DragDetect (IntPtr, Point) of user32.dll, equivalent in mono?

Does anyone know the managed code for the above p / invoke call to use it with mono? Is there a linux lib that provides similar functionality as user32.dll on windows?

+3
source share
1 answer

I'm not sure if there is a direct equivalent for calling DragDirect for x11 \ GTK, but you can have the same functions with Gdk.Pointer.Graband methods Gdk.Pointer.Ungrab. Capture the mouse pointer whenever you need, and then track the movement of the mouse and release it after the user hit. Escape or mouse or mouse releases out of the drag rectangle.

Below is a small example:

public partial class MainWindow : Gtk.Window
{
    public MainWindow () : base(Gtk.WindowType.Toplevel)
    {
        Build ();
    }

    protected void OnDeleteEvent (object sender, DeleteEventArgs a)
    {
        Application.Quit ();
        a.RetVal = true;
    }

    protected virtual void OnWidgetEvent (object o, Gtk.WidgetEventArgs args)
    {   
        if (args.Event is Gdk.EventMotion && args.Event.Type==Gdk.EventType.MotionNotify)
        {
            Gdk.EventMotion eventMotion = (Gdk.EventMotion)args.Event; 
            Console.WriteLine("mouse move {0} {1}", eventMotion.X, eventMotion.Y);
        }
        else if (args.Event is Gdk.EventKey && args.Event.Type==Gdk.EventType.KeyPress)
        {
            Gdk.EventKey eventKey = (Gdk.EventKey)args.Event;
            if (eventKey.Key==Gdk.Key.Escape)
            {
                Console.WriteLine("mouse pointer ungrab");
                Gtk.Grab.Remove(this);
                Gdk.Pointer.Ungrab(Gtk.Global.CurrentEventTime);
            }
        }
    }

    protected virtual void OnButton1WidgetEvent (object o, Gtk.WidgetEventArgs args)
    {
        if (args.Event is Gdk.EventButton && args.Event.Type==Gdk.EventType.ButtonPress)
        {
            Console.WriteLine("mouse pointer grab");
            Gdk.Pointer.Grab(this.GdkWindow, true,
                Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.PointerMotionMask | Gdk.EventMask.EnterNotifyMask | Gdk.EventMask.LeaveNotifyMask, 
                null, null, Gtk.Global.CurrentEventTime); 
            Gtk.Grab.Add (this);
        }
    }
}

MainWindow UI declaration:

  <widget class="Gtk.Window" id="MainWindow" design-size="400 300">
    <property name="MemberName" />
    <property name="Title" translatable="yes">MainWindow</property>
    <property name="WindowPosition">CenterOnParent</property>
    <signal name="DeleteEvent" handler="OnDeleteEvent" />
    <signal name="WidgetEvent" handler="OnWidgetEvent" />
    <child>
      <widget class="Gtk.Fixed" id="fixed1">
        <property name="MemberName" />
        <property name="HasWindow">False</property>
        <child>
          <widget class="Gtk.Button" id="button1">
            <property name="MemberName" />
            <property name="CanFocus">True</property>
            <property name="Type">TextOnly</property>
            <property name="Label" translatable="yes">GtkButton</property>
            <property name="UseUnderline">True</property>
            <signal name="WidgetEvent" handler="OnButton1WidgetEvent" />
          </widget>
          <packing>
            <property name="X">165</property>
            <property name="Y">125</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>

GTK :

, ,

+1

Source: https://habr.com/ru/post/1793656/


All Articles