开发者

DragDetect (IntPtr, Point) from user32.dll eqivalent in mono?

Does anybody know managed code for the mentioned p/invoke call to use i开发者_Python百科t with mono? Is there a linux lib that provides similar functionality as the user32.dll on windows does?


I'm not sure if there is a direct equivalent for DragDirect call for x11\GTK, but you can have the same functionality with Gdk.Pointer.Grab and Gdk.Pointer.Ungrab methods. Capture the mouse pointer whenever you need then track mouse movement and release once user hits Escape or releases the mouse or mouse is 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>

more details on mouse pointer handling in GTK here: The Mouse Pointer

hope this helps, regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜