Пример #1
0
        internal static bool HandleEvent(IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg)
        {
            Control         control;
            DataObject      data;
            DragEventArgs   drag_event;
            DragDropEffects allowed;
            QDPoint         point   = new QDPoint();
            UInt32          actions = 0;
            IntPtr          dragref = IntPtr.Zero;
            Hwnd            hwnd    = Hwnd.ObjectFromHandle(handle);

            if (hwnd == null || hwnd.Handle != handle)
            {
                return(false);
            }

            GetEventParameter(eventref, kEventParamDragRef, typeDragRef, IntPtr.Zero, (uint)Marshal.SizeOf(typeof(IntPtr)), IntPtr.Zero, ref dragref);
            XplatUICarbon.GetGlobalMouse(ref point);
            GetDragAllowableActions(dragref, ref actions);
            control    = Control.FromHandle(hwnd.Handle);
            allowed    = DragActionsToEffects(actions);
            data       = DragToDataObject(dragref);
            drag_event = new DragEventArgs(data, 0, point.x, point.y, allowed, DragDropEffects.None);

            switch (kind)
            {
            case ControlHandler.kEventControlDragEnter:
            {
                bool accept = control.AllowDrop;
                SetEventParameter(eventref, ControlHandler.kEventParamControlLikesDrag, ControlHandler.typeBoolean, (uint)Marshal.SizeOf(typeof(bool)), ref accept);

                control.DndEnter(drag_event);
                effects = drag_event.Effect;
                return(false);
            }

            case ControlHandler.kEventControlDragWithin:
                control.DndOver(drag_event);
                effects = drag_event.Effect;
                break;

            case ControlHandler.kEventControlDragLeave:
                control.DndLeave(drag_event);
                break;

            case ControlHandler.kEventControlDragReceive:
                control.DndDrop(drag_event);
                break;
            }
            return(true);
        }
Пример #2
0
		internal static bool HandleEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
			Control control;
			DataObject data;
			DragEventArgs drag_event;
			DragDropEffects allowed;
			QDPoint point = new QDPoint ();
			UInt32 actions = 0;
			IntPtr dragref = IntPtr.Zero;
			Hwnd hwnd = Hwnd.ObjectFromHandle (handle);

			if (hwnd == null || hwnd.Handle != handle)
				return false;

			GetEventParameter (eventref, kEventParamDragRef, typeDragRef, IntPtr.Zero, (uint) Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref dragref);
			XplatUICarbon.GetGlobalMouse (ref point);
			GetDragAllowableActions (dragref, ref actions);
			control = Control.FromHandle (hwnd.Handle);
			allowed = DragActionsToEffects (actions);
			data = DragToDataObject (dragref);
			drag_event = new DragEventArgs (data, 0, point.x, point.y, allowed, DragDropEffects.None);
				
			switch (kind) {
				case ControlHandler.kEventControlDragEnter: {
					bool accept = control.AllowDrop;
					SetEventParameter (eventref, ControlHandler.kEventParamControlLikesDrag, ControlHandler.typeBoolean, (uint)Marshal.SizeOf (typeof (bool)), ref accept);

					control.DndEnter (drag_event);
					effects = drag_event.Effect;
					return false;
				}
				case ControlHandler.kEventControlDragWithin:
					control.DndOver (drag_event);
					effects = drag_event.Effect;
					break;
				case ControlHandler.kEventControlDragLeave:
					control.DndLeave (drag_event);
					break;
				case ControlHandler.kEventControlDragReceive:
					control.DndDrop (drag_event);
					break;
			}
			return true;
		}
Пример #3
0
        public bool ProcessEvent(IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg)
        {
            QDPoint qdpoint       = new QDPoint();
            CGPoint point         = new CGPoint();
            Rect    window_bounds = new Rect();
            IntPtr  view_handle   = IntPtr.Zero;
            IntPtr  window_handle = IntPtr.Zero;
            bool    client        = true;
            ushort  button        = 0;
            Hwnd    hwnd;

            GetEventParameter(eventref, kEventParamMouseLocation, typeQDPoint, IntPtr.Zero, (uint)Marshal.SizeOf(typeof(QDPoint)), IntPtr.Zero, ref qdpoint);
            GetEventParameter(eventref, kEventParamMouseButton, typeMouseButton, IntPtr.Zero, (uint)Marshal.SizeOf(typeof(ushort)), IntPtr.Zero, ref button);

            if (button == 1 && ((Driver.ModifierKeys & Keys.Control) != 0))
            {
                button = 2;
            }

            point.x = qdpoint.x;
            point.y = qdpoint.y;

            if (FindWindow(qdpoint, ref window_handle) == 5)
            {
                return(true);
            }

            GetWindowBounds(handle, 33, ref window_bounds);
            HIViewFindByID(HIViewGetRoot(handle), new HIViewID(EventHandler.kEventClassWindow, 1), ref window_handle);

            point.x -= window_bounds.left;
            point.y -= window_bounds.top;

            HIViewGetSubviewHit(window_handle, ref point, true, ref view_handle);
            HIViewConvertPoint(ref point, window_handle, view_handle);

            hwnd = Hwnd.ObjectFromHandle(view_handle);

            if (hwnd != null)
            {
                client = (hwnd.ClientWindow == view_handle ? true : false);
            }

            if (XplatUICarbon.Grab.Hwnd != IntPtr.Zero)
            {
                hwnd   = Hwnd.ObjectFromHandle(XplatUICarbon.Grab.Hwnd);
                client = true;
            }
            if (hwnd == null)
            {
                return(true);
            }

            if (client)
            {
                qdpoint.x = (short)point.x;
                qdpoint.y = (short)point.y;

                Driver.ScreenToClient(hwnd.Handle, ref qdpoint);
            }
            else
            {
                point.x = qdpoint.x;
                point.y = qdpoint.y;
            }

            msg.hwnd   = hwnd.Handle;
            msg.lParam = (IntPtr)((ushort)point.y << 16 | (ushort)point.x);

            switch (kind)
            {
            case kEventMouseDown:
                UpdateMouseState(button, true);
                msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE) + ((button - 1) * 3) + 1;
                msg.wParam  = Driver.GetMousewParam(0);
                if (ClickPending.Pending && (((DateTime.Now.Ticks - ClickPending.Time) < DoubleClickInterval) && (msg.hwnd == ClickPending.Hwnd) && (msg.wParam == ClickPending.wParam) && (msg.lParam == ClickPending.lParam) && (msg.message == ClickPending.Message)))
                {
                    msg.message          = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE) + ((button - 1) * 3) + 3;
                    ClickPending.Pending = false;
                }
                else
                {
                    ClickPending.Pending = true;
                    ClickPending.Hwnd    = msg.hwnd;
                    ClickPending.Message = msg.message;
                    ClickPending.wParam  = msg.wParam;
                    ClickPending.lParam  = msg.lParam;
                    ClickPending.Time    = DateTime.Now.Ticks;
                }
                break;

            case kEventMouseUp:
                UpdateMouseState(button, false);
                msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE) + ((button - 1) * 3) + 2;
                msg.wParam  = Driver.GetMousewParam(0);
                break;

            case kEventMouseDragged:
            case kEventMouseMoved:
                if (XplatUICarbon.Grab.Hwnd == IntPtr.Zero)
                {
                    IntPtr ht = IntPtr.Zero;
                    if (client)
                    {
                        ht = (IntPtr)HitTest.HTCLIENT;
                        NativeWindow.WndProc(msg.hwnd, Msg.WM_SETCURSOR, msg.hwnd, (IntPtr)HitTest.HTCLIENT);
                    }
                    else
                    {
                        ht = (IntPtr)NativeWindow.WndProc(hwnd.client_window, Msg.WM_NCHITTEST, IntPtr.Zero, msg.lParam).ToInt32();
                        NativeWindow.WndProc(hwnd.client_window, Msg.WM_SETCURSOR, msg.hwnd, ht);
                    }
                }
                msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE);
                msg.wParam  = Driver.GetMousewParam(0);
                break;

            case kEventMouseWheelMoved:
            case kEventMouseScroll:
                UInt16 axis  = 0;
                Int32  delta = 0;

                GetEventParameter(eventref, kEventParamMouseWheelAxis, typeMouseWheelAxis, IntPtr.Zero, (uint)Marshal.SizeOf(typeof(UInt16)), IntPtr.Zero, ref axis);
                GetEventParameter(eventref, kEventParamMouseWheelDelta, typeLongInteger, IntPtr.Zero, (uint)Marshal.SizeOf(typeof(Int32)), IntPtr.Zero, ref delta);

                if (axis == kEventMouseWheelAxisY)
                {
                    msg.hwnd    = XplatUICarbon.FocusWindow;
                    msg.message = Msg.WM_MOUSEWHEEL;
                    msg.wParam  = Driver.GetMousewParam(delta * 40);
                    return(true);
                }
                break;

            default:
                return(false);
            }
            Driver.mouse_position.X = (int)point.x;
            Driver.mouse_position.Y = (int)point.y;
            return(true);
        }
Пример #4
0
 internal static extern short FindWindow(QDPoint point, ref IntPtr handle);
Пример #5
0
 static extern int GetEventParameter(IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref QDPoint data);
		internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
			Carbon.QDPoint pt = new Carbon.QDPoint ();
			GetGlobalMouse (ref pt);
			x = pt.x;
			y = pt.y;
		}
Пример #7
0
		public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
			QDPoint qdpoint = new QDPoint ();
			CGPoint point = new CGPoint ();
			Rect window_bounds = new Rect ();
			IntPtr view_handle = IntPtr.Zero;
			IntPtr window_handle = IntPtr.Zero;
			bool client = true;
			ushort button = 0;
			Hwnd hwnd;

			GetEventParameter (eventref, kEventParamMouseLocation, typeQDPoint, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref qdpoint);
			GetEventParameter (eventref, kEventParamMouseButton, typeMouseButton, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (ushort)), IntPtr.Zero, ref button);
			
			if (button == 1 && ((Driver.ModifierKeys & Keys.Control) != 0))
				button = 2;

			point.x = qdpoint.x;
			point.y = qdpoint.y;

			if (FindWindow (qdpoint, ref window_handle) == 5)
				return true;

			GetWindowBounds (handle, 33, ref window_bounds);
			HIViewFindByID (HIViewGetRoot (handle), new HIViewID (EventHandler.kEventClassWindow, 1), ref window_handle);

			point.x -= window_bounds.left;
			point.y -= window_bounds.top;

			HIViewGetSubviewHit (window_handle, ref point, true, ref view_handle);
			HIViewConvertPoint (ref point, window_handle, view_handle);

			hwnd = Hwnd.ObjectFromHandle (view_handle);

			if (hwnd != null)
				client = (hwnd.ClientWindow == view_handle ? true : false);

			if (XplatUICarbon.Grab.Hwnd != IntPtr.Zero) {
				hwnd = Hwnd.ObjectFromHandle (XplatUICarbon.Grab.Hwnd); 
				client = true;
			}
			if (hwnd == null)
				return true;
			
			if (client) {
				qdpoint.x = (short) point.x;
				qdpoint.y = (short) point.y;

				Driver.ScreenToClient (hwnd.Handle, ref qdpoint);
			} else {
				point.x = qdpoint.x;
				point.y = qdpoint.y;
			}

			msg.hwnd = hwnd.Handle;
			msg.lParam = (IntPtr) ((ushort) point.y << 16 | (ushort) point.x);

			switch (kind) {
				case kEventMouseDown:
					UpdateMouseState (button, true);
					msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE) + ((button - 1) * 3) + 1;
					msg.wParam = Driver.GetMousewParam (0);
					if (ClickPending.Pending && (((DateTime.Now.Ticks - ClickPending.Time) < DoubleClickInterval) && (msg.hwnd == ClickPending.Hwnd) && (msg.wParam == ClickPending.wParam) && (msg.lParam == ClickPending.lParam) && (msg.message == ClickPending.Message))) {
						msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE) + ((button - 1) * 3) + 3;
						ClickPending.Pending = false;
					} else {
						ClickPending.Pending = true;
						ClickPending.Hwnd = msg.hwnd;
						ClickPending.Message = msg.message;
						ClickPending.wParam = msg.wParam;
						ClickPending.lParam = msg.lParam;
						ClickPending.Time = DateTime.Now.Ticks;
					}
					break;
				case kEventMouseUp:
					UpdateMouseState (button, false);
					msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE) + ((button - 1) * 3) + 2;
					msg.wParam = Driver.GetMousewParam (0);
					break;
				case kEventMouseDragged:
				case kEventMouseMoved:
					if (XplatUICarbon.Grab.Hwnd == IntPtr.Zero) {
						IntPtr ht = IntPtr.Zero;
						if (client) {
							ht = (IntPtr) HitTest.HTCLIENT;
							NativeWindow.WndProc(msg.hwnd, Msg.WM_SETCURSOR, msg.hwnd, (IntPtr)HitTest.HTCLIENT);
						} else {
	                                                ht = (IntPtr) NativeWindow.WndProc (hwnd.client_window, Msg.WM_NCHITTEST, IntPtr.Zero, msg.lParam).ToInt32 ();
							NativeWindow.WndProc(hwnd.client_window, Msg.WM_SETCURSOR, msg.hwnd, ht);
						}
					}
					msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE);
					msg.wParam = Driver.GetMousewParam (0);
					break;
				case kEventMouseWheelMoved:
				case kEventMouseScroll:
					UInt16 axis = 0;
					Int32 delta = 0;

					GetEventParameter (eventref, kEventParamMouseWheelAxis, typeMouseWheelAxis, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (UInt16)), IntPtr.Zero, ref axis);
					GetEventParameter (eventref, kEventParamMouseWheelDelta, typeLongInteger, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (Int32)), IntPtr.Zero, ref delta);

					if (axis == kEventMouseWheelAxisY) {
						msg.hwnd = XplatUICarbon.FocusWindow;
						msg.message = Msg.WM_MOUSEWHEEL;
						msg.wParam = Driver.GetMousewParam (delta*40);
						return true;
					}
					break;
				default:
					return false;
			}
			Driver.mouse_position.X = (int) point.x;
			Driver.mouse_position.Y = (int) point.y;
			return true;
		}
Пример #8
0
		internal static extern short FindWindow (QDPoint point, ref IntPtr handle);
Пример #9
0
		static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref QDPoint data);