private Point ConvertClientPointToScreen (IntPtr handle, Point point) {
			Point converted_point = new Point ();
			Carbon.Rect window_bounds = new Carbon.Rect ();
			Carbon.CGPoint native_point = new Carbon.CGPoint ();

			GetWindowBounds (HIViewGetWindow (handle), 32, ref window_bounds);
			
			native_point.x = point.X;
			native_point.y = point.Y;

			HIViewConvertPoint (ref native_point, handle, IntPtr.Zero);

			converted_point.X = (int)(native_point.x + window_bounds.left);
			converted_point.Y = (int)(native_point.y + window_bounds.top);

			return converted_point;
		}
Example #2
0
		public HIRect (int x, int y, int w, int h) {
			this.origin = new CGPoint (x, y);
			this.size = new CGSize (w, h);
		}
		private Point ConvertScreenPointToClient (IntPtr handle, Point point) {
			Point converted_point = new Point ();
			Carbon.Rect window_bounds = new Carbon.Rect ();
			Carbon.CGPoint native_point = new Carbon.CGPoint ();

			GetWindowBounds (HIViewGetWindow (handle), 32, ref window_bounds);
			
			native_point.x = (point.X - window_bounds.left);
			native_point.y = (point.Y - window_bounds.top);

			HIViewConvertPoint (ref native_point, IntPtr.Zero, handle);

			converted_point.X = (int)native_point.x;
			converted_point.Y = (int)native_point.y;

			return converted_point;
		}
Example #4
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;
		}
Example #5
0
 public HIRect(int x, int y, int w, int h)
 {
     this.origin = new CGPoint(x, y);
     this.size   = new CGSize(w, h);
 }
Example #6
0
		internal static extern int HIViewGetSubviewHit (IntPtr content_view, ref CGPoint point, bool tval, ref IntPtr hit_view);
Example #7
0
		internal static extern int HIViewConvertPoint (ref CGPoint point, IntPtr source_view, IntPtr target_view);
        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);
        }
 internal static extern int HIViewGetSubviewHit(IntPtr content_view, ref CGPoint point, bool tval, ref IntPtr hit_view);
 internal static extern int HIViewConvertPoint(ref CGPoint point, IntPtr source_view, IntPtr target_view);