Beispiel #1
0
        private void CalculateBounds(SecondDisplayProcess proc)
        {
            _thumbnail = LiveThumbnail.FromHandle(proc.Handle, this.Handle);

            Size size;

            if (_thumbnail != null && _thumbnail.IsValid && _thumbnail.SafeGetSize(out size))
            {
                this.Height = Math.Min(size.Height, ThumbnailConstants.MaxHeight) + panelTitle.Top * 2 + ThumbnailConstants.ThumbPadding * 2;
                this.Width  = Math.Min(size.Width, ThumbnailConstants.MaxWidth) + panelTitle.Left * 2 + ThumbnailConstants.ThumbPadding * 2;

                using (GraphicsPath gp = RoundedRectangle.Create(this.ClientRectangle, 5))
                {
                    Region   hrgn = new System.Drawing.Region(gp);
                    Graphics g    = Graphics.FromHwnd(this.Handle);
                    Native.SetWindowRgn(this.Handle, hrgn.GetHrgn(g), true);
                }
            }
            else
            {
                this.Height = 51;
                this.Width  = panelTitle.Left * 2 + CalculateWidth(proc.Title.Clamp(Constants.MaxProgramNameLength));

                using (GraphicsPath gp = new GraphicsPath())
                {
                    gp.AddRectangle(this.ClientRectangle);
                    Region   hrgn = new System.Drawing.Region(gp);
                    Graphics g    = Graphics.FromHwnd(this.Handle);
                    Native.SetWindowRgn(this.Handle, hrgn.GetHrgn(g), true);
                }
            }
        }
Beispiel #2
0
        public static void DrawDragOutline(Region region)
        {
            if (region == null)
                return;

            // Get hold of the DC for the desktop
            IntPtr hDC = User32.GetDC(IntPtr.Zero);

            // Define the area we are allowed to draw into
            IntPtr hRegion = region.GetHrgn(Graphics.FromHdc(hDC));
            Gdi32.SelectClipRgn(hDC, hRegion);

            Win32.RECT rectBox = new Win32.RECT();

            // Get the smallest rectangle that encloses region
            Gdi32.GetClipBox(hDC, ref rectBox);

            IntPtr brushHandler = GetHalfToneBrush();

            // Select brush into the device context
            IntPtr oldHandle = Gdi32.SelectObject(hDC, brushHandler);

            // Blit to screen using provided pattern brush and invert with existing screen contents
            Gdi32.PatBlt(hDC,
                rectBox.left,
                rectBox.top,
                rectBox.right - rectBox.left,
                rectBox.bottom - rectBox.top,
                (uint)Win32.RasterOperations.PATINVERT);

            // Put old handle back again
            Gdi32.SelectObject(hDC, oldHandle);

            // Reset the clipping region
            Gdi32.SelectClipRgn(hDC, IntPtr.Zero);

            Gdi32.DeleteObject(hRegion);

            // Must remember to release the HDC resource!
            User32.ReleaseDC(IntPtr.Zero, hDC);
        }
 private void cBAreo_CheckStateChanged(object sender, EventArgs e)
 {
     Areo.AreoParams parameter;
     switch (cBAreo.CheckState)
     {
     case CheckState.Checked:
     cBAreo.Text = "窗体背景Areo效果";
     parameter = new Areo.AreoParams();
     parameter.Flags = Areo.AreoParams.ENABLE;       //开启Areo效果
     parameter.Enable = true;                        //开启Areo效果
     parameter.AreoRegion = IntPtr.Zero;             //区域为整个窗体背景区
     Areo.AreoWindow(this.Handle, parameter);        //将整个窗体背景设置为Areo效果
     break;
     case CheckState.Indeterminate:
     cBAreo.Text = "窗体区域Areo效果";
     ClearAreoWindow();                              //清除原有Areo效果
     using (Graphics G = CreateGraphics())
     {
     parameter = new Areo.AreoParams();
     //开启Areo效果和区域Areo效果
     parameter.Flags = Areo.AreoParams.ENABLE | Areo.AreoParams.REGION;
     parameter.Enable = true;                    //开启Areo效果
     Rectangle rect = this.ClientRectangle;
     rect.Inflate(-rect.Width / 4, -rect.Height / 4);
     regionAreo = new Region(rect);              //获取窗体中心区域
     parameter.AreoRegion = regionAreo.GetHrgn(G);//设置Areo区域
     Areo.AreoWindow(this.Handle, parameter);    //将窗体中心区域设置成Areo效果
     }
     break;
     case CheckState.Unchecked:
     cBAreo.Text = "窗体无Areo效果";
     ClearAreoWindow();
     break;
     default:
     break;
     }
     this.Invalidate();
 }
Beispiel #4
0
		internal override Region GetClipRegion(IntPtr hwnd) {
			Region region;

			region = new Region();

			Win32GetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)));

			return region;
		}
Beispiel #5
0
        public IntPtr NCPaint(IntPtr region)
        {
            IntPtr hDC = GetWindowDC(this.Handle);
            if (hDC != IntPtr.Zero)
            {
                Graphics grTemp = Graphics.FromHdc(hDC);

                int ScrollBarWidth = SystemInformation.VerticalScrollBarWidth;
                int ScrollBarHeight = SystemInformation.HorizontalScrollBarHeight;

                WINDOWINFO wi = new WINDOWINFO();
                wi.cbSize = (uint)Marshal.SizeOf(wi);

                //得到当前控件的窗口信息
                GetWindowInfo(Handle, ref wi);

                wi.rcClient.Right--;
                wi.rcClient.Bottom--;


                //获得当前控件的区域
                Region UpdateRegion = new Region(new Rectangle(wi.rcWindow.Top, wi.rcWindow.Left, wi.rcWindow.Right - wi.rcWindow.Left, wi.rcWindow.Bottom - wi.rcWindow.Top));

                //获得客户区以外的区域
                UpdateRegion.Exclude(new Rectangle(wi.rcClient.Top, wi.rcClient.Left, wi.rcClient.Right - wi.rcClient.Left, wi.rcClient.Bottom - wi.rcClient.Top));

                //if (IsHScrollVisible && IsVScrollVisible)
                //{
                //    UpdateRegion.Exclude(Rectangle.FromLTRB
                //            (wi.rcClient.Right + 2, wi.rcClient.Bottom + 2,
                //            wi.rcWindow.Right, wi.rcWindow.Bottom));
                //}

                //得到当前区域的句柄
                IntPtr hRgn = UpdateRegion.GetHrgn(grTemp);

                //For Painting we need to zero offset the Rectangles.
                Rectangle WindowRect = new Rectangle(wi.rcWindow.Top, wi.rcWindow.Left, wi.rcWindow.Right - wi.rcWindow.Left, wi.rcWindow.Bottom - wi.rcWindow.Top);

                Point offset = Point.Empty - (Size)WindowRect.Location;

                WindowRect.Offset(offset);

                Rectangle ClientRect = WindowRect;

                ClientRect.Inflate(-1, -1);

                //Fill the BorderArea
                Region PaintRegion = new Region(WindowRect);
                PaintRegion.Exclude(ClientRect);
                grTemp.FillRegion(SystemBrushes.Control, PaintRegion);

                //Adjust ClientRect for Drawing Border.
                ClientRect.Inflate(1, 1);
                ClientRect.Width--;
                ClientRect.Height--;

                //Draw Outer Raised Border
                //ControlPaint.DrawBorder3D(grTemp, WindowRect, Border3DStyle.Raised,
                //Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);
                WindowRect.Width--;
                WindowRect.Height--;
                grTemp.DrawRectangle(_borderPen, WindowRect);

                //Draw Inner Sunken Border
                //ControlPaint.DrawBorder3D(grTemp, ClientRect, Border3DStyle.Sunken,
                //Border3DSide.Bottom | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);

                ReleaseDC(Handle, hDC);

                grTemp.Dispose();

                return hRgn;

            }
            return region;

        }
        public HitTestCode HitTestBackground(Graphics g, Rectangle backgroundRectangle, Region region, Point pt, HitTestOptions options) {
            if (g == null) {
                throw new ArgumentNullException("g");
            }

            IntPtr hRgn = region.GetHrgn(g);

            return HitTestBackground(g, backgroundRectangle, hRgn, pt, options);
        }
Beispiel #7
0
		public bool GetMessage (object queue_id, ref MSG msg, IntPtr handle, int wFilterMin, int wFilterMax)
		{
			X11ThreadQueue queue = (X11ThreadQueue)queue_id;
			XEvent xevent;
			bool client;
			bool got_xevent = false;

			X11Hwnd hwnd;

		ProcessNextMessage:
			do {
				got_xevent = queue.Dequeue (out xevent);

				if (!got_xevent) {
#if spew
					Console.WriteLine (">");
					Console.Out.Flush ();
#endif
					break;
				}

#if spew
				Console.Write ("-");
				Console.Out.Flush ();
#endif

				hwnd = (X11Hwnd)Hwnd.GetObjectFromWindow (xevent.AnyEvent.window);

				// Handle messages for windows that are already or are about to be destroyed.

				// we need a special block for this because unless we remove the hwnd from the paint
				// queue it will always stay there (since we don't handle the expose), and we'll
				// effectively loop infinitely trying to repaint a non-existant window.
				if (hwnd != null && hwnd.zombie && xevent.type == XEventName.Expose) {
					hwnd.PendingExpose = hwnd.PendingNCExpose = false;
					goto ProcessNextMessage;
				}

				// We need to make sure we only allow DestroyNotify events through for zombie
				// hwnds, since much of the event handling code makes requests using the hwnd's
				// ClientWindow, and that'll result in BadWindow errors if there's some lag
				// between the XDestroyWindow call and the DestroyNotify event.
				if (hwnd == null || hwnd.zombie) {
#if DriverDebug || DriverDebugDestroy
					Console.WriteLine("GetMessage(): Got message {0} for non-existent or already destroyed window {1:X}",
							  xevent.type, xevent.AnyEvent.window.ToInt32());
#endif
					goto ProcessNextMessage;
				}

				client = hwnd.ClientWindow == xevent.AnyEvent.window;

				msg.hwnd = hwnd.Handle;

				switch (xevent.type) {
				case XEventName.KeyPress:
					Keyboard.KeyEvent (FocusWindow.Handle, xevent, ref msg);
					return true;

				case XEventName.KeyRelease:
					Keyboard.KeyEvent (FocusWindow.Handle, xevent, ref msg);
					return true;

				case XEventName.ButtonPress: {
					switch(xevent.ButtonEvent.button) {
					case 1:
						MouseState |= MouseButtons.Left;
						if (client) {
							msg.message = Msg.WM_LBUTTONDOWN;
						} else {
							msg.message = Msg.WM_NCLBUTTONDOWN;
							hwnd.MenuToScreen (ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
						}
						// TODO: For WM_NCLBUTTONDOWN wParam specifies a hit-test value not the virtual keys down
						msg.wParam=GetMousewParam(0);
						break;

					case 2:
						MouseState |= MouseButtons.Middle;
						if (client) {
							msg.message = Msg.WM_MBUTTONDOWN;
						} else {
							msg.message = Msg.WM_NCMBUTTONDOWN;
							hwnd.MenuToScreen (ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
						}
						msg.wParam=GetMousewParam(0);
						break;

					case 3:
						MouseState |= MouseButtons.Right;
						if (client) {
							msg.message = Msg.WM_RBUTTONDOWN;
						} else {
							msg.message = Msg.WM_NCRBUTTONDOWN;
							hwnd.MenuToScreen (ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
						}
						msg.wParam=GetMousewParam(0);
						break;

					case 4:
						msg.hwnd = FocusWindow.Handle;
						msg.message=Msg.WM_MOUSEWHEEL;
						msg.wParam=GetMousewParam(120);
						break;

					case 5:
						msg.hwnd = FocusWindow.Handle;
						msg.message=Msg.WM_MOUSEWHEEL;
						msg.wParam=GetMousewParam(-120);
						break;
					}

					msg.lParam=(IntPtr) (xevent.ButtonEvent.y << 16 | xevent.ButtonEvent.x);
					MousePosition.X = xevent.ButtonEvent.x;
					MousePosition.Y = xevent.ButtonEvent.y;

					if (!hwnd.Enabled) {
						RedirectMsgToEnabledAncestor (hwnd, msg, xevent.AnyEvent.window,
									      ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
					}

					if (Grab.Hwnd != IntPtr.Zero)
						msg.hwnd = Grab.Hwnd;

					if (ClickPending.Pending &&
					    ((((long)xevent.ButtonEvent.time - ClickPending.Time) < DoubleClickInterval) &&
					     (msg.wParam == ClickPending.wParam) &&
					     (msg.lParam == ClickPending.lParam) &&
					     (msg.message == ClickPending.Message))) {
						// Looks like a genuine double click, clicked twice on the same spot with the same keys
						switch(xevent.ButtonEvent.button) {
						case 1:
							msg.message = client ? Msg.WM_LBUTTONDBLCLK : Msg.WM_NCLBUTTONDBLCLK;
							break;

						case 2:
							msg.message = client ? Msg.WM_MBUTTONDBLCLK : Msg.WM_NCMBUTTONDBLCLK;
							break;

						case 3:
							msg.message = client ? Msg.WM_RBUTTONDBLCLK : Msg.WM_NCRBUTTONDBLCLK;
							break;
						}

						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 = (long)xevent.ButtonEvent.time;
					}

					if (msg.message == Msg.WM_LBUTTONDOWN || msg.message == Msg.WM_MBUTTONDOWN || msg.message == Msg.WM_RBUTTONDOWN) {
						hwnd.SendParentNotify (msg.message, MousePosition.X, MousePosition.Y);

						// Win32 splurts MouseMove events all over the place, regardless of whether the mouse is actually moving or
						// not, especially after mousedown and mouseup. To support apps relying on mousemove events between and after 
						// mouse clicks to repaint or whatever, we generate a mousemove event here. *sigh*
						XEvent motionEvent = new XEvent ();
						motionEvent.type = XEventName.MotionNotify;
						motionEvent.MotionEvent.display = display;
						motionEvent.MotionEvent.window = xevent.ButtonEvent.window;
						motionEvent.MotionEvent.x = xevent.ButtonEvent.x;
						motionEvent.MotionEvent.y = xevent.ButtonEvent.y;
						hwnd.Queue.Enqueue (motionEvent);
					}

					return true;
				}

				case XEventName.ButtonRelease:
					switch(xevent.ButtonEvent.button) {
					case 1:
						if (client) {
							msg.message = Msg.WM_LBUTTONUP;
						} else {
							msg.message = Msg.WM_NCLBUTTONUP;
							hwnd.MenuToScreen (ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
						}
						MouseState &= ~MouseButtons.Left;
						msg.wParam=GetMousewParam(0);
						break;

					case 2:
						if (client) {
							msg.message = Msg.WM_MBUTTONUP;
						} else {
							msg.message = Msg.WM_NCMBUTTONUP;
							hwnd.MenuToScreen (ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
						}
						MouseState &= ~MouseButtons.Middle;
						msg.wParam=GetMousewParam(0);
						break;

					case 3:
						if (client) {
							msg.message = Msg.WM_RBUTTONUP;
						} else {
							msg.message = Msg.WM_NCRBUTTONUP;
							hwnd.MenuToScreen (ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
						}
						MouseState &= ~MouseButtons.Right;
						msg.wParam=GetMousewParam(0);
						break;

					case 4:
						goto ProcessNextMessage;

					case 5:
						goto ProcessNextMessage;
					}

					if (!hwnd.Enabled) {
						RedirectMsgToEnabledAncestor (hwnd, msg, xevent.AnyEvent.window,
									      ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
					}

					if (Grab.Hwnd != IntPtr.Zero)
						msg.hwnd = Grab.Hwnd;

					msg.lParam=(IntPtr) (xevent.ButtonEvent.y << 16 | xevent.ButtonEvent.x);
					MousePosition.X = xevent.ButtonEvent.x;
					MousePosition.Y = xevent.ButtonEvent.y;

						// Win32 splurts MouseMove events all over the place, regardless of whether the mouse is actually moving or
						// not, especially after mousedown and mouseup. To support apps relying on mousemove events between and after 
						// mouse clicks to repaint or whatever, we generate a mousemove event here. *sigh*
					if (msg.message == Msg.WM_LBUTTONUP || msg.message == Msg.WM_MBUTTONUP || msg.message == Msg.WM_RBUTTONUP) {
						XEvent motionEvent = new XEvent ();
						motionEvent.type = XEventName.MotionNotify;
						motionEvent.MotionEvent.display = display;
						motionEvent.MotionEvent.window = xevent.ButtonEvent.window;
						motionEvent.MotionEvent.x = xevent.ButtonEvent.x;
						motionEvent.MotionEvent.y = xevent.ButtonEvent.y;
						hwnd.Queue.Enqueue (motionEvent);
					}
					return true;

				case XEventName.MotionNotify:
					/* XXX move the compression stuff here */

					if (client) {
#if DriverDebugExtra
						Console.WriteLine("GetMessage(): Window {0:X} MotionNotify x={1} y={2}",
								  client ? hwnd.ClientWindow.ToInt32() : hwnd.WholeWindow.ToInt32(),
								  xevent.MotionEvent.x, xevent.MotionEvent.y);
#endif

						if (Grab.Hwnd != IntPtr.Zero)
							msg.hwnd = Grab.Hwnd;
						else
							NativeWindow.WndProc(msg.hwnd, Msg.WM_SETCURSOR, msg.hwnd, (IntPtr)HitTest.HTCLIENT);

						msg.message = Msg.WM_MOUSEMOVE;
						msg.wParam = GetMousewParam(0);
						msg.lParam = (IntPtr) (xevent.MotionEvent.y << 16 | xevent.MotionEvent.x & 0xFFFF);

						if (!hwnd.Enabled) {
							RedirectMsgToEnabledAncestor (hwnd, msg, xevent.AnyEvent.window,
										      ref xevent.MotionEvent.x, ref xevent.MotionEvent.y);
						}

						MousePosition.X = xevent.MotionEvent.x;
						MousePosition.Y = xevent.MotionEvent.y;

						if ((HoverState.Timer.Enabled) &&
						    (((MousePosition.X + HoverState.Size.Width) < HoverState.X) ||
						     ((MousePosition.X - HoverState.Size.Width) > HoverState.X) ||
						     ((MousePosition.Y + HoverState.Size.Height) < HoverState.Y) ||
						     ((MousePosition.Y - HoverState.Size.Height) > HoverState.Y))) {

							HoverState.Timer.Stop();
							HoverState.Timer.Start();
							HoverState.X = MousePosition.X;
							HoverState.Y = MousePosition.Y;
						}
					}
					else {
						HitTest	ht;
						IntPtr dummy;
						int screen_x;
						int screen_y;

						#if DriverDebugExtra
						Console.WriteLine("GetMessage(): non-client area {0:X} MotionNotify x={1} y={2}",
								  client ? hwnd.ClientWindow.ToInt32() : hwnd.WholeWindow.ToInt32(),
								  xevent.MotionEvent.x, xevent.MotionEvent.y);
						#endif
						msg.message = Msg.WM_NCMOUSEMOVE;

						if (!hwnd.Enabled) {
							RedirectMsgToEnabledAncestor (hwnd, msg, xevent.AnyEvent.window,
										      ref xevent.MotionEvent.x, ref xevent.MotionEvent.y);
						}

						// The hit test is sent in screen coordinates
						Xlib.XTranslateCoordinates (display, xevent.AnyEvent.window, RootWindow.Handle,
									    xevent.MotionEvent.x, xevent.MotionEvent.y,
									    out screen_x, out screen_y, out dummy);

						msg.lParam = (IntPtr) (screen_y << 16 | screen_x & 0xFFFF);
						ht = (HitTest)NativeWindow.WndProc (hwnd.ClientWindow, Msg.WM_NCHITTEST,
										    IntPtr.Zero, msg.lParam).ToInt32 ();
						NativeWindow.WndProc(hwnd.ClientWindow, Msg.WM_SETCURSOR, msg.hwnd, (IntPtr)ht);

						MousePosition.X = xevent.MotionEvent.x;
						MousePosition.Y = xevent.MotionEvent.y;
					}

					return true;

				case XEventName.EnterNotify:
					if (!hwnd.Enabled)
						goto ProcessNextMessage;

					if (xevent.CrossingEvent.mode != NotifyMode.NotifyNormal)
						goto ProcessNextMessage;

					msg.message = Msg.WM_MOUSE_ENTER;
					HoverState.X = xevent.CrossingEvent.x;
					HoverState.Y = xevent.CrossingEvent.y;
					HoverState.Timer.Enabled = true;
					HoverState.Window = xevent.CrossingEvent.window;

					return true;

				case XEventName.LeaveNotify:
					if (!hwnd.Enabled)
						goto ProcessNextMessage;

					if ((xevent.CrossingEvent.mode != NotifyMode.NotifyNormal) ||
					    (xevent.CrossingEvent.window != hwnd.ClientWindow))
						goto ProcessNextMessage;

					msg.message=Msg.WM_MOUSELEAVE;
					HoverState.Timer.Enabled = false;
					HoverState.Window = IntPtr.Zero;

					return true;

				case XEventName.ReparentNotify:
					if (hwnd.parent == null) {	// Toplevel
						if ((xevent.ReparentEvent.parent != IntPtr.Zero) && (xevent.ReparentEvent.window == hwnd.WholeWindow)) {
							// We need to adjust x/y
							// This sucks ass, part 2
							// Every WM does the reparenting of toplevel windows different, so there's
							// no standard way of getting our adjustment considering frames/decorations
							// The code below is needed for metacity. KDE doesn't works just fine without this
							int	dummy_int;
							IntPtr	dummy_ptr;
							int	new_x;
							int	new_y;
							int	frame_left;
							int	frame_top;

							hwnd.Reparented = true;

							Xlib.XGetGeometry(display, XGetParent(hwnd.WholeWindow),
									  out dummy_ptr, out new_x, out new_y,
									  out dummy_int, out dummy_int, out dummy_int, out dummy_int);
							hwnd.FrameExtents(out frame_left, out frame_top);
							if ((frame_left != 0) && (frame_top != 0) && (new_x != frame_left) && (new_y != frame_top)) {
								hwnd.x = new_x;
								hwnd.y = new_y;
								hwnd.whacky_wm = true;
							}

							if (hwnd.opacity != 0xffffffff) {
								IntPtr opacity;

								opacity = (IntPtr)(Int32)hwnd.opacity;
								Xlib.XChangeProperty (display, XGetParent(hwnd.WholeWindow),
										      Atoms._NET_WM_WINDOW_OPACITY, Atoms.XA_CARDINAL, 32,
										      PropertyMode.Replace, ref opacity, 1);
							}
							SendMessage(msg.hwnd, Msg.WM_WINDOWPOSCHANGED, msg.wParam, msg.lParam);
							goto ProcessNextMessage;
						} else {
							hwnd.Reparented = false;
							goto ProcessNextMessage;
						}
					}
					goto ProcessNextMessage;

				case XEventName.ConfigureNotify:
					hwnd.HandleConfigureNotify (xevent);
					goto ProcessNextMessage;

				case XEventName.MapNotify: {
					if (client && (xevent.ConfigureEvent.xevent == xevent.ConfigureEvent.window)) { // Ignore events for children (SubstructureNotify) and client areas
						hwnd.Mapped = true;
						msg.message = Msg.WM_SHOWWINDOW;
						msg.wParam = (IntPtr) 1;
						// XXX we're missing the lParam..
						break;
					}
					goto ProcessNextMessage;
				}

				case XEventName.UnmapNotify: {
					if (client && (xevent.ConfigureEvent.xevent == xevent.ConfigureEvent.window)) { // Ignore events for children (SubstructureNotify) and client areas
						hwnd.Mapped = false;
						msg.message = Msg.WM_SHOWWINDOW;
						msg.wParam = (IntPtr) 0;
						// XXX we're missing the lParam..
						break;
					}
					goto ProcessNextMessage;
				}

				case XEventName.FocusIn:
					// We received focus. We use X11 focus only to know if the app window does or does not have focus
					// We do not track the actual focussed window via it. Instead, this is done via FocusWindow internally
					// Receiving focus means we've gotten activated and therefore we need to let the actual FocusWindow know 
					// about it having focus again
					if (xevent.FocusChangeEvent.detail != NotifyDetail.NotifyNonlinear)
						goto ProcessNextMessage;

					if (FocusWindow == null) {
						Control c = Control.FromHandle (hwnd.ClientWindow);
						if (c == null)
							goto ProcessNextMessage;
						Form form = c.FindForm ();
						if (form == null)
							goto ProcessNextMessage;
						X11Hwnd new_active = (X11Hwnd)Hwnd.ObjectFromHandle (form.Handle);
						if (ActiveWindow != new_active) {
							ActiveWindow = new_active;
							SendMessage (ActiveWindow.Handle, Msg.WM_ACTIVATE, (IntPtr) WindowActiveFlags.WA_ACTIVE, IntPtr.Zero);
						}
						goto ProcessNextMessage;
					}
					Keyboard.FocusIn(FocusWindow.Handle);
					SendMessage(FocusWindow.Handle, Msg.WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
					goto ProcessNextMessage;

				case XEventName.FocusOut:
					// Se the comment for our FocusIn handler
					if (xevent.FocusChangeEvent.detail != NotifyDetail.NotifyNonlinear)
						goto ProcessNextMessage;

					if (FocusWindow == null)
						goto ProcessNextMessage;

					Keyboard.FocusOut(FocusWindow.Handle);

					while (Keyboard.ResetKeyState(FocusWindow.Handle, ref msg))
						SendMessage(FocusWindow.Handle, msg.message, msg.wParam, msg.lParam);

					SendMessage(FocusWindow.Handle, Msg.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);
					goto ProcessNextMessage;

				case XEventName.Expose:
					if (!hwnd.Mapped) {
						hwnd.PendingExpose = hwnd.PendingNCExpose = false;
						continue;
					}

					msg.hwnd = hwnd.Handle;

					if (client) {
#if DriverDebugExtra
						Console.WriteLine("GetMessage(): Window {0:X} Exposed area {1},{2} {3}x{4}",
								  hwnd.client_window.ToInt32(),
								  xevent.ExposeEvent.x, xevent.ExposeEvent.y,
								  xevent.ExposeEvent.width, xevent.ExposeEvent.height);
#endif
						msg.message = Msg.WM_PAINT;
					}
					else {
						Graphics g;

						switch (hwnd.border_style) {
						case FormBorderStyle.Fixed3D:
							g = Graphics.FromHwnd(hwnd.WholeWindow);
							ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height),
										  Border3DStyle.Sunken);
							g.Dispose();
							break;

						case FormBorderStyle.FixedSingle:
							g = Graphics.FromHwnd(hwnd.WholeWindow);
							ControlPaint.DrawBorder(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height),
										Color.Black, ButtonBorderStyle.Solid);
							g.Dispose();
						break;
						}
#if DriverDebugExtra
						Console.WriteLine("GetMessage(): Window {0:X} Exposed non-client area {1},{2} {3}x{4}",
								  hwnd.ClientWindow.ToInt32(),
								  xevent.ExposeEvent.x, xevent.ExposeEvent.y,
								  xevent.ExposeEvent.width, xevent.ExposeEvent.height);
#endif

						Rectangle rect = new Rectangle (xevent.ExposeEvent.x, xevent.ExposeEvent.y,
										xevent.ExposeEvent.width, xevent.ExposeEvent.height);
						Region region = new Region (rect);
						IntPtr hrgn = region.GetHrgn (null); // Graphics object isn't needed
						msg.message = Msg.WM_NCPAINT;
						msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
						msg.refobject = region;
					}

					return true;
						
				case XEventName.DestroyNotify:

					// This is a bit tricky, we don't receive our own DestroyNotify, we only get those for our children
					hwnd = (X11Hwnd)Hwnd.ObjectFromHandle(xevent.DestroyWindowEvent.window);

					// We may get multiple for the same window, act only one the first (when Hwnd still knows about it)
					if ((hwnd != null) && (hwnd.ClientWindow == xevent.DestroyWindowEvent.window)) {
						CleanupCachedWindows (hwnd);

						#if DriverDebugDestroy
						Console.WriteLine("Received X11 Destroy Notification for {0}", XplatUI.Window(hwnd.ClientWindow));
						#endif

						msg.hwnd = hwnd.ClientWindow;
						msg.message=Msg.WM_DESTROY;
						hwnd.Dispose();
					}
					else
						goto ProcessNextMessage;

					return true;

				case XEventName.ClientMessage:
					if (Dnd.HandleClientMessage (ref xevent))
						goto ProcessNextMessage;

					if (xevent.ClientMessageEvent.message_type == Atoms.AsyncAtom) {
						XplatUIDriverSupport.ExecuteClientMessage((GCHandle)xevent.ClientMessageEvent.ptr1);
						goto ProcessNextMessage;
					}

					if (xevent.ClientMessageEvent.message_type == HoverState.Atom) {
						msg.message = Msg.WM_MOUSEHOVER;
						msg.wParam = GetMousewParam(0);
						msg.lParam = (IntPtr) (xevent.ClientMessageEvent.ptr1);
						return true;
					}

					if (xevent.ClientMessageEvent.message_type == Atoms.PostAtom) {
						msg.hwnd = xevent.ClientMessageEvent.ptr1;
						msg.message = (Msg) xevent.ClientMessageEvent.ptr2.ToInt32 ();
						msg.wParam = xevent.ClientMessageEvent.ptr3;
						msg.lParam = xevent.ClientMessageEvent.ptr4;

						// if we posted a WM_QUIT message, make sure we return
						// false here as well.
						if (msg.message == (Msg)Msg.WM_QUIT)
							return false;
						else
							return true;
					}

					if (xevent.ClientMessageEvent.message_type == Atoms._XEMBED) {
#if DriverDebugXEmbed
						Console.WriteLine("GOT EMBED MESSAGE {0:X}, detail {1:X}",
								  xevent.ClientMessageEvent.ptr2.ToInt32(), xevent.ClientMessageEvent.ptr3.ToInt32());
#endif

						if (xevent.ClientMessageEvent.ptr2.ToInt32() == (int)XEmbedMessage.EmbeddedNotify) {
							XSizeHints hints = new XSizeHints();
							IntPtr dummy;

							Xlib.XGetWMNormalHints (display, hwnd.WholeWindow, ref hints, out dummy);

							hwnd.width = hints.max_width;
							hwnd.height = hints.max_height;
							hwnd.ClientRect = Rectangle.Empty;
							SendMessage(msg.hwnd, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
						}
					}

					if (xevent.ClientMessageEvent.message_type == Atoms.WM_PROTOCOLS) {
						if (xevent.ClientMessageEvent.ptr1 == Atoms.WM_DELETE_WINDOW) {
							msg.message = Msg.WM_CLOSE;
							return true;
						}

						// We should not get this, but I'll leave the code in case we need it in the future
						if (xevent.ClientMessageEvent.ptr1 == Atoms.WM_TAKE_FOCUS) {
							goto ProcessNextMessage;
						}
					}

					goto ProcessNextMessage;

				case XEventName.PropertyNotify:
					// The Hwnd's themselves handle this
					hwnd.PropertyChanged (xevent);
					goto ProcessNextMessage;
				}
			} while (true);

			msg.hwnd= IntPtr.Zero;
			msg.message = Msg.WM_ENTERIDLE;
			return true;
		}
        /// <devdoc>
        ///     Creates a WindowsRegion from a System.Drawing.Region. 
        /// </devdoc>
        public static WindowsRegion FromRegion( Region region, Graphics g ){
            if (region.IsInfinite(g)){
                // An infinite region would cover the entire device region which is the same as
                // not having a clipping region. Observe that this is not the same as having an
                // empty region, which when clipping to it has the effect of excluding the entire
                // device region.
                // To remove the clip region from a dc the SelectClipRgn() function needs to be
                // called with a null region ptr - that's why we use the empty constructor here.
                // GDI+ will return IntPtr.Zero for Region.GetHrgn(Graphics) when the region is
                // Infinite.
                return new WindowsRegion();
            }

            return WindowsRegion.FromHregion(region.GetHrgn(g), true);
        }
Beispiel #9
0
		protected void SetWindowRegion(Size winSize)
		{
			// Style specific handling
			if (_style == VisualStyle.IDE)
			{
				int shadowHeight = _position[(int)_style, (int)PI.ShadowHeight];
				int shadowWidth = _position[(int)_style, (int)PI.ShadowWidth];

				// Create a new region object
				using (Region drawRegion = new Region())
				{
				// Can draw anywhere
				drawRegion.MakeInfinite();

				// Remove the area above the right hand shadow
				drawRegion.Xor(new Rectangle(winSize.Width - shadowWidth, 0, shadowWidth, shadowHeight));

				// When drawing upwards from a vertical menu we need to allow a connection between the
				// MenuControl selection box and the PopupMenu shadow
				if (!((_direction == Direction.Vertical) && !_excludeTop))
				{
					// Remove the area left of the bottom shadow
					drawRegion.Xor(new Rectangle(0, winSize.Height - shadowHeight, shadowWidth, shadowHeight));
				}

				// Define a region to prevent drawing over exposed corners of shadows
				using(Graphics g = Graphics.FromHwnd(this.Handle))
					WindowsAPI.SetWindowRgn(this.Handle, drawRegion.GetHrgn(g), false);
			}
			}
		}
            public void Update(bool timerCaused)
            {
                ErrorProvider.IconRegion region = this.provider.Region;
                Size size = region.Size;
                this.windowBounds = Rectangle.Empty;
                for (int i = 0; i < this.items.Count; i++)
                {
                    Rectangle iconBounds = ((ErrorProvider.ControlItem) this.items[i]).GetIconBounds(size);
                    if (this.windowBounds.IsEmpty)
                    {
                        this.windowBounds = iconBounds;
                    }
                    else
                    {
                        this.windowBounds = Rectangle.Union(this.windowBounds, iconBounds);
                    }
                }
                Region wrapper = new Region(new Rectangle(0, 0, 0, 0));
                IntPtr zero = IntPtr.Zero;
                try
                {
                    for (int j = 0; j < this.items.Count; j++)
                    {
                        ErrorProvider.ControlItem item2 = (ErrorProvider.ControlItem) this.items[j];
                        Rectangle rectangle2 = item2.GetIconBounds(size);
                        rectangle2.X -= this.windowBounds.X;
                        rectangle2.Y -= this.windowBounds.Y;
                        bool flag = true;
                        if (!item2.ToolTipShown)
                        {
                            switch (this.provider.BlinkStyle)
                            {
                                case ErrorBlinkStyle.BlinkIfDifferentError:
                                    flag = (item2.BlinkPhase == 0) || ((item2.BlinkPhase > 0) && ((item2.BlinkPhase & 1) == (j & 1)));
                                    break;

                                case ErrorBlinkStyle.AlwaysBlink:
                                    flag = ((j & 1) == 0) == this.provider.showIcon;
                                    break;
                            }
                        }
                        if (flag)
                        {
                            region.Region.Translate(rectangle2.X, rectangle2.Y);
                            wrapper.Union(region.Region);
                            region.Region.Translate(-rectangle2.X, -rectangle2.Y);
                        }
                        if (this.tipWindow != null)
                        {
                            System.Windows.Forms.NativeMethods.TOOLINFO_T toolinfo_t;
                            toolinfo_t = new System.Windows.Forms.NativeMethods.TOOLINFO_T {
                                cbSize = Marshal.SizeOf(toolinfo_t),
                                hwnd = base.Handle,
                                uId = item2.Id,
                                lpszText = item2.Error,
                                rect = System.Windows.Forms.NativeMethods.RECT.FromXYWH(rectangle2.X, rectangle2.Y, rectangle2.Width, rectangle2.Height),
                                uFlags = 0x10
                            };
                            if (this.provider.RightToLeft)
                            {
                                toolinfo_t.uFlags |= 4;
                            }
                            System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this.tipWindow, this.tipWindow.Handle), System.Windows.Forms.NativeMethods.TTM_SETTOOLINFO, 0, toolinfo_t);
                        }
                        if (timerCaused && (item2.BlinkPhase > 0))
                        {
                            item2.BlinkPhase--;
                        }
                    }
                    if (timerCaused)
                    {
                        this.provider.showIcon = !this.provider.showIcon;
                    }
                    DeviceContext context = null;
                    using (context = DeviceContext.FromHwnd(base.Handle))
                    {
                        this.CreateMirrorDC(context.Hdc, this.windowBounds.Width);
                        Graphics g = Graphics.FromHdcInternal(this.mirrordc.Hdc);
                        try
                        {
                            zero = wrapper.GetHrgn(g);
                            System.Internal.HandleCollector.Add(zero, System.Windows.Forms.NativeMethods.CommonHandles.GDI);
                        }
                        finally
                        {
                            g.Dispose();
                            this.RestoreMirrorDC();
                        }
                        if (System.Windows.Forms.UnsafeNativeMethods.SetWindowRgn(new HandleRef(this, base.Handle), new HandleRef(wrapper, zero), true) != 0)
                        {
                            zero = IntPtr.Zero;
                        }
                    }
                }
                finally
                {
                    wrapper.Dispose();
                    if (zero != IntPtr.Zero)
                    {
                        System.Windows.Forms.SafeNativeMethods.DeleteObject(new HandleRef(null, zero));
                    }
                }
                System.Windows.Forms.SafeNativeMethods.SetWindowPos(new HandleRef(this, base.Handle), System.Windows.Forms.NativeMethods.HWND_TOP, this.windowBounds.X, this.windowBounds.Y, this.windowBounds.Width, this.windowBounds.Height, 0x10);
                System.Windows.Forms.SafeNativeMethods.InvalidateRect(new HandleRef(this, base.Handle), (System.Windows.Forms.NativeMethods.COMRECT) null, false);
            }
		public void GetHrgn_Infinite_MakeEmpty ()
		{
			Region r = new Region ();
			Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
			Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
			Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");

			r.MakeEmpty ();
			Assert.IsTrue (r.IsEmpty (graphic), "Empty");
			Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
			IntPtr h = r.GetHrgn (graphic);
			Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");
#if NET_2_0
			r.ReleaseHrgn (h);
#endif
		}
Beispiel #12
0
        private void NCPaint()
        {
            if (this.Parent == null)
                return;
            if (this.Width <= 0 || this.Height <= 0)
                return;

            IntPtr windowDC = NativeMethods.GetDCEx(this.Handle,
                             IntPtr.Zero, NativeMethods.DCX_CACHE |
                             NativeMethods.DCX_WINDOW |
                             NativeMethods.DCX_CLIPSIBLINGS |
                             NativeMethods.DCX_LOCKWINDOWUPDATE);

            if (windowDC.Equals(IntPtr.Zero))
                return;

            using (Bitmap bm = new Bitmap(this.Width, this.Height,
                System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
            {

                using (Graphics g = Graphics.FromImage(bm))
                {

                    Rectangle borderRect = new Rectangle(0, 0,
                        Width - 1, Height - 1);

                    using (Pen borderPen = new Pen(this.borderColor, 1))
                    {
                        borderPen.Alignment = PenAlignment.Inset;
                        g.DrawRectangle(borderPen, borderRect);
                    }

                    // Create and Apply a Clip Region to the WindowDC
                    using (Region Rgn = new Region(new
                        Rectangle(0, 0, Width, Height)))
                    {
                        Rgn.Exclude(new Rectangle(1, 1, Width - 2, Height - 2));
                        IntPtr hRgn = Rgn.GetHrgn(g);
                        if (!hRgn.Equals(IntPtr.Zero))
                            NativeMethods.SelectClipRgn(windowDC, hRgn);

                        IntPtr bmDC = g.GetHdc();
                        IntPtr hBmp = bm.GetHbitmap();
                        IntPtr oldDC = NativeMethods.SelectObject(bmDC,
                            hBmp);
                        NativeMethods.BitBlt(windowDC, 0, 0, bm.Width,
                            bm.Height, bmDC, 0, 0, NativeMethods.SRCCOPY);

                        NativeMethods.SelectClipRgn(windowDC, IntPtr.Zero);
                        NativeMethods.DeleteObject(hRgn);

                        g.ReleaseHdc(bmDC);
                        NativeMethods.SelectObject(oldDC, hBmp);
                        NativeMethods.DeleteObject(hBmp);
                        bm.Dispose();
                    }
                }
            }

            NativeMethods.ReleaseDC(this.Handle, windowDC);

        }
Beispiel #13
0
        private IntPtr GetHRegion()
        {
            //Define a Clip Region to pass back to WM_NCPAINTs wParam.
            //Must be in Screen Coordinates.
            IntPtr hRgn;
            Rectangle winRect = this.Parent.RectangleToScreen(this.Bounds);
            Rectangle clientRect =
                this.RectangleToScreen(this.ClientRectangle);

            Region updateRegion = new Region(winRect);
            updateRegion.Complement(clientRect);

            using (Graphics g = this.CreateGraphics())
                hRgn = updateRegion.GetHrgn(g);
            updateRegion.Dispose();
            return hRgn;
        }
Beispiel #14
0
        protected void InvalidateNonClient(Rectangle invalidRect,
                                           bool excludeClientArea)
        {
            if (!IsDisposed && !Disposing && IsHandleCreated)
            {
                if (invalidRect.IsEmpty)
                {
                    Padding realWindowBorders = RealWindowBorders;
                    Rectangle realWindowRectangle = RealWindowRectangle;

                    invalidRect = new Rectangle(-realWindowBorders.Left,
                                                -realWindowBorders.Top,
                                                realWindowRectangle.Width,
                                                realWindowRectangle.Height);
                }

                using (Region invalidRegion = new Region(invalidRect))
                {
                    if (excludeClientArea)
                        invalidRegion.Exclude(ClientRectangle);

                    using (Graphics g = Graphics.FromHwnd(Handle))
                    {
                        IntPtr hRgn = invalidRegion.GetHrgn(g);

                        PI.RedrawWindow(Handle, IntPtr.Zero, hRgn,
                                        (uint)(PI.RDW_FRAME | PI.RDW_UPDATENOW | PI.RDW_INVALIDATE));

                        PI.DeleteObject(hRgn);
                    }
                }
            }
        }
Beispiel #15
0
		internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
			IntPtr		hdc;
			IntPtr		pen;
			IntPtr		oldpen;
			POINT		pt;

			pt = new POINT();
			pt.x = 0;
			pt.y = 0;
			Win32ClientToScreen(handle, ref pt);

			// If we want the standard hatch pattern we would
			// need to create a brush

			// Grab a pen
			pen = Win32CreatePen(PenStyle.PS_SOLID, line_width, IntPtr.Zero);

			hdc = Win32GetDC(IntPtr.Zero);
			Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
			oldpen = Win32SelectObject(hdc, pen);

			Control c = Control.FromHandle (handle);
			if (c != null) {
				RECT window_rect;
				Win32GetWindowRect (c.Handle, out window_rect);
				Region r = new Region (new Rectangle(window_rect.left, window_rect.top, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top));
				Win32ExtSelectClipRgn(hdc, r.GetHrgn (Graphics.FromHdc (hdc)), (int) ClipCombineMode.RGN_AND);
			}

			Win32MoveToEx(hdc, pt.x + rect.Left, pt.y + rect.Top, IntPtr.Zero);
			if ((rect.Width > 0) && (rect.Height > 0)) {
				Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
				Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Bottom);
				Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
				Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Top);
			} else {
				if (rect.Width > 0) {
					Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
				} else {
					Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
				}
			}

			Win32SelectObject(hdc, oldpen);
			Win32DeleteObject(pen);
			if (c != null)
				Win32ExtSelectClipRgn(hdc, IntPtr.Zero, (int) ClipCombineMode.RGN_COPY);

			Win32ReleaseDC(IntPtr.Zero, hdc);
		}
Beispiel #16
0
 public static void CreateRegion(IntPtr hWnd, int radius, RoundStyle roundStyle, bool redraw)
 {
     Win32.Struct.RECT lpRect = new Win32.Struct.RECT();
     Win32.NativeMethods.GetWindowRect(hWnd, ref lpRect);
     Rectangle rect = new Rectangle(System.Drawing.Point.Empty, lpRect.Size);
     if (roundStyle != RoundStyle.None)
     {
         using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, radius, roundStyle, true))
         {
             using (Region region = new Region(path))
             {
                 path.Widen(Pens.White);
                 region.Union(path);
                 IntPtr windowDC = Win32.NativeMethods.GetWindowDC(hWnd);
                 try
                 {
                     using (Graphics graphics = Graphics.FromHdc(windowDC))
                     {
                         Win32.NativeMethods.SetWindowRgn(hWnd, region.GetHrgn(graphics), redraw);
                     }
                 }
                 finally
                 {
                     Win32.NativeMethods.ReleaseDC(hWnd, windowDC);
                 }
             }
             return;
         }
     }
     IntPtr hRgn = Win32.NativeMethods.CreateRectRgn(0, 0, rect.Width, rect.Height);
     Win32.NativeMethods.SetWindowRgn(hWnd, hRgn, redraw);
 }
Beispiel #17
0
        /// <summary>
        /// Redraws the non client area.
        /// </summary>
        /// <param name="invalidateBuffer">if set to <c>true</c> the buffer is invalidated.</param>
        /// <returns>true if the original painting should be suppressed otherwise false.</returns>
        private bool NcPaint(bool invalidateBuffer)
        {
            if (!IsProcessNcArea)
                return false;
            bool result = false;

            IntPtr hdc = (IntPtr)0;
            Graphics g = null;
            Region region = null;
            IntPtr hrgn = (IntPtr)0;

            try
            {
                // no drawing needed
                if (_parentForm.MdiParent != null && _parentForm.WindowState == FormWindowState.Maximized)
                {
                    _currentCacheSize = Size.Empty;
                    return false;
                }

                // prepare image bounds
                Size borderSize = FormExtenders.GetBorderSize(_parentForm);
                int captionHeight = FormExtenders.GetCaptionHeight(_parentForm);

                RECT rectScreen = new RECT();
                Win32Api.GetWindowRect(_parentForm.Handle, ref rectScreen);

                Rectangle rectBounds = rectScreen.ToRectangle();
                rectBounds.Offset(-rectBounds.X, -rectBounds.Y);

                // prepare clipping
                Rectangle rectClip = rectBounds;
                region = new Region(rectClip);
                rectClip.Inflate(-borderSize.Width, -borderSize.Height);
                rectClip.Y += captionHeight;
                rectClip.Height -= captionHeight;

                // create graphics handle
                hdc = Win32Api.GetDCEx(_parentForm.Handle, (IntPtr)0,
                    (DCXFlags.DCX_CACHE | DCXFlags.DCX_CLIPSIBLINGS | DCXFlags.DCX_WINDOW));
                g = Graphics.FromHdc(hdc);

                // Apply clipping
                region.Exclude(rectClip);
                hrgn = region.GetHrgn(g);
                Win32Api.SelectClipRgn(hdc, hrgn);

                // create new buffered graphics if needed
                if (_bufferGraphics == null || _currentCacheSize != rectBounds.Size)
                {
                    if (_bufferGraphics != null)
                        _bufferGraphics.Dispose();

                    _bufferGraphics = _bufferContext.Allocate(g, new Rectangle(0, 0,
                                rectBounds.Width, rectBounds.Height));
                    _currentCacheSize = rectBounds.Size;
                    invalidateBuffer = true;
                }

                if (invalidateBuffer)
                {
                    // Create painting meta data for form
                    SkinningFormPaintData paintData = new SkinningFormPaintData(_bufferGraphics.Graphics, rectBounds)
                    {
                        Borders = borderSize,
                        CaptionHeight = captionHeight,
                        Active = _formIsActive,
                        HasMenu = FormExtenders.HasMenu(_parentForm),
                        IconSize = SystemInformation.SmallIconSize,
                        IsSmallCaption =
                            captionHeight ==
                            SystemInformation.ToolWindowCaptionHeight,
                        Text = _parentForm.Text
                    };

                    // create painting meta data for caption buttons
                    if (_captionButtons.Count > 0)
                    {
                        paintData.CaptionButtons = new CaptionButtonPaintData[_captionButtons.Count];
                        for (int i = 0; i < _captionButtons.Count; i++)
                        {
                            CaptionButton button = _captionButtons[i];
                            CaptionButtonPaintData buttonData = new CaptionButtonPaintData(_bufferGraphics.Graphics, button.Bounds)
                            {
                                Pressed = button.Pressed,
                                Hovered = button.Hovered,
                                Enabled = button.Enabled,
                                HitTest = button.HitTest
                            };
                            paintData.CaptionButtons[i] = buttonData;
                        }
                    }

                    // paint
                    result = _manager.CurrentSkin.OnNcPaint(_parentForm, paintData);
                }

                // render buffered graphics 
                if (_bufferGraphics != null)
                    _bufferGraphics.Render(g);
            }
            catch (Exception)
            {// error drawing
                result = false;
            }

            // cleanup data
            if (hdc != (IntPtr)0)
            {
                Win32Api.SelectClipRgn(hdc, (IntPtr)0);
                Win32Api.ReleaseDC(_parentForm.Handle, hdc);
            }
            if (region != null && hrgn != (IntPtr)0)
                region.ReleaseHrgn(hrgn);

            if (region != null)
                region.Dispose();

            if (g != null)
                g.Dispose();

            return result;
        }
Beispiel #18
0
 /// <summary>
 /// Swap the swapchain's next buffer with the front buffer.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="sourceRectangle">The source rectangle.</param>
 /// <param name="destinationRectangle">The destination rectangle.</param>
 /// <param name="windowOverride">The window override.</param>
 /// <param name="region">The region.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT IDirect3DDevice9Ex::PresentEx([In] const void* pSourceRect,[In] const void* pDestRect,[In] HWND hDestWindowOverride,[In] const RGNDATA* pDirtyRegion,[In] unsigned int dwFlags)</unmanaged>
 public void PresentEx(Present flags, Rectangle sourceRectangle, Rectangle destinationRectangle, IntPtr windowOverride, Region region)
 {
     unsafe
     {
         var graphics = Graphics.FromHwnd(windowOverride);
         var regionPtr = region.GetHrgn(graphics);
         graphics.Dispose();
         PresentEx(new IntPtr(&sourceRectangle), new IntPtr(&destinationRectangle), windowOverride, regionPtr, (int)flags);
     }            
 }
Beispiel #19
0
            /// <include file='doc\ErrorProvider.uex' path='docs/doc[@for="ErrorProvider.ErrorWindow.Update"]/*' />
            /// <devdoc>
            ///     Move and size the error window, compute and set the window region,
            ///     set the tooltip rectangles and descriptions.  This basically brings
            ///     the error window up to date with the internal data structures.
            /// </devdoc>
            public void Update(bool timerCaused) {
                IconRegion iconRegion = provider.Region;
                Size size = iconRegion.Size;
                windowBounds = Rectangle.Empty;
                for (int i = 0; i < items.Count; i++) {
                    ControlItem item = (ControlItem)items[i];
                    Rectangle iconBounds = item.GetIconBounds(size);
                    if (windowBounds.IsEmpty)
                        windowBounds = iconBounds;
                    else
                        windowBounds = Rectangle.Union(windowBounds, iconBounds);
                }

                Region windowRegion =  new Region(new Rectangle(0, 0, 0, 0));
                IntPtr windowRegionHandle = IntPtr.Zero;
                try {
                    for (int i = 0; i < items.Count; i++) {
                        ControlItem item = (ControlItem)items[i];
                        Rectangle iconBounds = item.GetIconBounds(size);
                        iconBounds.X -= windowBounds.X;
                        iconBounds.Y -= windowBounds.Y;

                        bool showIcon = true;
                        if (!item.ToolTipShown) {
                            switch (provider.BlinkStyle) {
                                case ErrorBlinkStyle.NeverBlink:
                                    // always show icon
                                    break;

                                case ErrorBlinkStyle.BlinkIfDifferentError:
                                    showIcon = (item.BlinkPhase == 0) || (item.BlinkPhase > 0 && (item.BlinkPhase & 1) == (i & 1));
                                    break;

                                case ErrorBlinkStyle.AlwaysBlink:
                                    showIcon = ((i & 1) == 0) == provider.showIcon;
                                    break;
                            }
                        }

                        if (showIcon)
                        {
                            iconRegion.Region.Translate(iconBounds.X, iconBounds.Y);
                            windowRegion.Union(iconRegion.Region);
                            iconRegion.Region.Translate(-iconBounds.X, -iconBounds.Y);
                        }

                        if (tipWindow != null) {
                            NativeMethods.TOOLINFO_T toolInfo = new NativeMethods.TOOLINFO_T();
                            toolInfo.cbSize = Marshal.SizeOf(toolInfo);
                            toolInfo.hwnd = Handle;
                            toolInfo.uId = item.Id;
                            toolInfo.lpszText = item.Error;
                            toolInfo.rect = NativeMethods.RECT.FromXYWH(iconBounds.X, iconBounds.Y, iconBounds.Width, iconBounds.Height);
                            toolInfo.uFlags = NativeMethods.TTF_SUBCLASS;
                            if (provider.RightToLeft) {
                                toolInfo.uFlags |= NativeMethods.TTF_RTLREADING;
                            }
                            UnsafeNativeMethods.SendMessage(new HandleRef(tipWindow, tipWindow.Handle), NativeMethods.TTM_SETTOOLINFO, 0, toolInfo);
                        }

                        if (timerCaused && item.BlinkPhase > 0) {
                            item.BlinkPhase--;
                        }
                    }
                    if (timerCaused) {
                        provider.showIcon = !provider.showIcon;
                    }


                    DeviceContext dc = null;
                    dc = DeviceContext.FromHwnd(this.Handle);
                    try {
                        CreateMirrorDC(dc.Hdc, windowBounds.Width);
                        
                        Graphics graphics = Graphics.FromHdcInternal(mirrordc.Hdc);
                        try {
                            windowRegionHandle = windowRegion.GetHrgn(graphics);
                            System.Internal.HandleCollector.Add(windowRegionHandle, NativeMethods.CommonHandles.GDI);
                        }
                        finally {
                            graphics.Dispose();
                            RestoreMirrorDC();
                        }
                        
                        if (UnsafeNativeMethods.SetWindowRgn(new HandleRef(this, Handle), new HandleRef(windowRegion, windowRegionHandle), true) != 0) {
                            //The HWnd owns the region.
                            windowRegionHandle = IntPtr.Zero;
                        }
                    }
                    
                    finally {
                        if (dc != null) {
                            dc.Dispose();
                        }
                    }

                }
                finally {
                    windowRegion.Dispose();
                    if (windowRegionHandle != IntPtr.Zero) {
                        SafeNativeMethods.DeleteObject(new HandleRef(null, windowRegionHandle));
                    }
                }

                SafeNativeMethods.SetWindowPos(new HandleRef(this, Handle), NativeMethods.HWND_TOP, windowBounds.X, windowBounds.Y,
                                     windowBounds.Width, windowBounds.Height, NativeMethods.SWP_NOACTIVATE);
                SafeNativeMethods.InvalidateRect(new HandleRef(this, Handle), null, false);
            }
		private void AddExpose (Hwnd hwnd, bool client, int x, int y, int width, int height) {
			// Don't waste time
			if ((hwnd == null) || (x > hwnd.Width) || (y > hwnd.Height) || ((x + width) < 0) || ((y + height) < 0)) {
				return;
			}

			// Keep the invalid area as small as needed
			if ((x + width) > hwnd.width) {
				width = hwnd.width - x;
			}

			if ((y + height) > hwnd.height) {
				height = hwnd.height - y;
			}

			if (client) {
				hwnd.AddInvalidArea(x, y, width, height);
				if (!hwnd.expose_pending && hwnd.visible) {
					MSG msg = new MSG ();
					msg.message = Msg.WM_PAINT;
					msg.hwnd = hwnd.Handle;
					EnqueueMessage (msg);
					hwnd.expose_pending = true;
				}
			} else {
				hwnd.AddNcInvalidArea (x, y, width, height);
				if (!hwnd.nc_expose_pending && hwnd.visible) {
					MSG msg = new MSG ();
					Region rgn = new Region (hwnd.Invalid);
					IntPtr hrgn = rgn.GetHrgn (null); // Graphics object isn't needed
					msg.message = Msg.WM_NCPAINT;
					msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
					msg.refobject = rgn;
					msg.hwnd = hwnd.Handle;
					EnqueueMessage (msg);
					hwnd.nc_expose_pending = true;

				}
			}
		}
Beispiel #21
0
		public void GetHrgn_Empty_MakeInfinite ()
		{
			Region r = new Region (new GraphicsPath ());
			Assert.IsTrue (r.IsEmpty (graphic), "Empty");
			Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
			IntPtr h = r.GetHrgn (graphic);
			Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");

			r.MakeInfinite ();
			Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
			Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
			Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
			r.ReleaseHrgn (h);
		}
        private NativeMethods.RECT[] CreateScrollableRegion(Rectangle scroll) 
        {
            if (this.cachedScrollableRegion != null) 
            {
                return this.cachedScrollableRegion;
            }

            using (Region region = new Region(scroll))
            {
                IntPtr handle = IntPtr.Zero;
                using (Graphics graphics = CreateGraphicsInternal())
                {
                    handle = region.GetHrgn(graphics);
                }
                if (handle != IntPtr.Zero)
                {
                    this.cachedScrollableRegion = UnsafeNativeMethods.GetRectsFromRegion(handle);

                    // SECREVIEW : This assert is safe since we created the native region.
                    //
                    IntSecurity.ObjectFromWin32Handle.Assert();
                    try
                    {
                        region.ReleaseHrgn(handle);
                    }
                    finally
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
            return this.cachedScrollableRegion;
        }
Beispiel #23
0
		public void GetHrgn_TwiceFromSameRegionInstance ()
		{
			Region r = new Region (new GraphicsPath ());
			IntPtr h1 = r.GetHrgn (graphic);
			IntPtr h2 = r.GetHrgn (graphic);
			Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
			r.ReleaseHrgn (h1);
			r.ReleaseHrgn (h2);
		}
Beispiel #24
0
        /// <summary>
        /// Retrieves an array of rectangles that approximates a region, and computes the
        /// pixel area of it. This method is necessary to work around some bugs in .NET
        /// and to increase performance for the way in which we typically use this data.
        /// </summary>
        /// <param name="region">The Region to retrieve data from.</param>
        /// <param name="scans">An array of Rectangle to put the scans into.</param>
        /// <param name="area">An integer to write the computed area of the region into.</param>
        /// <remarks>
        /// Note to implementors: Simple implementations may simple call region.GetRegionScans()
        /// and process the data for the 'out' variables.</remarks>
        public static void GetRegionScans(Region region, out Rectangle[] scans, out int area)
        {
            using (NullGraphics nullGraphics = new NullGraphics())
            {
                IntPtr hRgn = IntPtr.Zero;

                try
                {
                    hRgn = region.GetHrgn(nullGraphics.Graphics);
                    GetRegionScans(hRgn, out scans, out area);
                }

                finally
                {
                    if (hRgn != IntPtr.Zero)
                    {
                        SafeNativeMethods.DeleteObject(hRgn);
                        hRgn = IntPtr.Zero;
                    }
                }
            }

            GC.KeepAlive(region);
        }
Beispiel #25
0
		public void GetHrgn_FromHrgn ()
		{
			Region r1 = new Region (new GraphicsPath ());
			IntPtr h1 = r1.GetHrgn (graphic);
			Assert.IsFalse (h1 == IntPtr.Zero, "Handle_1!=0");

			Region r2 = Region.FromHrgn (h1);
			IntPtr h2 = r2.GetHrgn (graphic);
			Assert.IsFalse (h2 == IntPtr.Zero, "Handle_2!=0");
			Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
			r1.ReleaseHrgn (h1);
			r2.ReleaseHrgn (h2);
		}
Beispiel #26
0
 public void SetRegion(System.Drawing.Graphics graphics, System.Drawing.Region region)
 {
     hRgnBlur = region.GetHrgn(graphics);
     dwFlags |= DWM_BLURBEHIND_Mask.DWM_BB_BLURREGION;
 }
Beispiel #27
0
		public void ReleaseHrng ()
		{
			Region r = new Region (new GraphicsPath ());
			IntPtr ptr = r.GetHrgn (graphic);
			Assert.IsFalse (IntPtr.Zero == ptr, "ptr");
			r.ReleaseHrgn (ptr);
		}
Beispiel #28
0
		internal override bool GetMessage(Object queue_id, ref MSG msg, IntPtr handle, int wFilterMin, int wFilterMax)
		{
			XEvent	xevent;
			bool	client;
			Hwnd	hwnd;

			ProcessNextMessage:

			if (((XEventQueue)queue_id).Count > 0) {
				xevent = (XEvent) ((XEventQueue)queue_id).Dequeue ();
			} else {
				UpdateMessageQueue ((XEventQueue)queue_id);

				if (((XEventQueue)queue_id).Count > 0) {
					xevent = (XEvent) ((XEventQueue)queue_id).Dequeue ();
				} else if (((XEventQueue)queue_id).Paint.Count > 0) {
					xevent = ((XEventQueue)queue_id).Paint.Dequeue();
				} else {
					msg.hwnd= IntPtr.Zero;
					msg.message = Msg.WM_ENTERIDLE;
					return true;
				}
			}

			hwnd = Hwnd.GetObjectFromWindow(xevent.AnyEvent.window);

#if DriverDebugDestroy			
			if (hwnd != null)
				if (hwnd.zombie)
					Console.WriteLine ( "GetMessage zombie, got Event: " + xevent.ToString () + " for 0x{0:x}", hwnd.Handle.ToInt32());
				else	
					Console.WriteLine ( "GetMessage, got Event: " + xevent.ToString () + " for 0x{0:x}", hwnd.Handle.ToInt32());
#endif
			// Handle messages for windows that are already or are about to be destroyed.

			// we need a special block for this because unless we remove the hwnd from the paint
			// queue it will always stay there (since we don't handle the expose), and we'll
			// effectively loop infinitely trying to repaint a non-existant window.
			if (hwnd != null && hwnd.zombie && xevent.type == XEventName.Expose) {
				hwnd.expose_pending = hwnd.nc_expose_pending = false;
				hwnd.Queue.Paint.Remove (hwnd);
				goto ProcessNextMessage;
			}

			// We need to make sure we only allow DestroyNotify events through for zombie
			// hwnds, since much of the event handling code makes requests using the hwnd's
			// client_window, and that'll result in BadWindow errors if there's some lag
			// between the XDestroyWindow call and the DestroyNotify event.
			if (hwnd == null || hwnd.zombie && xevent.AnyEvent.type != XEventName.ClientMessage) {
				DriverDebug("GetMessage(): Got message {0} for non-existent or already destroyed window {1:X}", xevent.type, xevent.AnyEvent.window.ToInt32());
				goto ProcessNextMessage;
			}


			// If we get here, that means the window is no more but there are Client Messages
			// to be processed, probably a Posted message (for instance, an WM_ACTIVATE message) 
			// We don't want anything else to run but the ClientMessage block, so reset all hwnd
			// properties that might cause other processing to occur.
			if (hwnd.zombie) {
				hwnd.resizing_or_moving = false;
			}

			if (hwnd.client_window == xevent.AnyEvent.window) {
				client = true;
				//Console.WriteLine("Client message {1}, sending to window {0:X}", msg.hwnd.ToInt32(), xevent.type);
			} else {
				client = false;
				//Console.WriteLine("Non-Client message, sending to window {0:X}", msg.hwnd.ToInt32());
			}

			msg.hwnd = hwnd.Handle;

			// Windows sends WM_ENTERSIZEMOVE when a form resize/move operation starts and WM_EXITSIZEMOVE 
			// when it is done. The problem in X11 is that there is no concept of start-end of a moving/sizing.
			// Configure events ("this window has resized/moved") are sent for each step of the resize. We send a
			// WM_ENTERSIZEMOVE when we get the first Configure event. The problem is the WM_EXITSIZEMOVE.
			// 
			//  - There is no way for us to know which is the last Configure event. We can't traverse the events 
			//    queue, because the next configure event might not be pending yet.
			//  - We can't get ButtonPress/Release events for the window decorations, because they are not part 
			//    of the window(s) we manage.
			//  - We can't rely on the mouse state to change to "up" before the last Configure event. It doesn't.
			// 
			// We are almost 100% guaranteed to get another event (e.g Expose or other), but we can't know for sure 
			// which, so we have here to check if the mouse buttons state is "up" and send the WM_EXITSIZEMOVE
			//
			if (hwnd.resizing_or_moving) {
				int root_x, root_y, win_x, win_y, keys_buttons;
				IntPtr  root, child;
				XQueryPointer (DisplayHandle, hwnd.Handle, out root, out child, out root_x, out root_y, 
					       out win_x, out win_y, out keys_buttons);
				if ((keys_buttons & (int)MouseKeyMasks.Button1Mask) == 0 &&
				    (keys_buttons & (int)MouseKeyMasks.Button2Mask) == 0 &&
				    (keys_buttons & (int)MouseKeyMasks.Button3Mask) == 0) {
					hwnd.resizing_or_moving = false;
					SendMessage (hwnd.Handle, Msg.WM_EXITSIZEMOVE, IntPtr.Zero, IntPtr.Zero);
				}
			}

			//
			// If you add a new event to this switch make sure to add it in
			// UpdateMessage also unless it is not coming through the X event system.
			//
			switch(xevent.type) {
				case XEventName.KeyPress: {
					Keyboard.KeyEvent (FocusWindow, xevent, ref msg);

					// F1 key special case - WM_HELP sending
					if (msg.wParam == (IntPtr)VirtualKeys.VK_F1 || msg.wParam == (IntPtr)VirtualKeys.VK_HELP) {
						// Send wM_HELP and then return it as a keypress message in
						// case it needs to be preproccessed.
						HELPINFO helpInfo = new HELPINFO ();
						GetCursorPos (IntPtr.Zero, out helpInfo.MousePos.x, out helpInfo.MousePos.y);
						IntPtr helpInfoPtr = Marshal.AllocHGlobal (Marshal.SizeOf (helpInfo));
						Marshal.StructureToPtr (helpInfo, helpInfoPtr, true);
						NativeWindow.WndProc (FocusWindow, Msg.WM_HELP, IntPtr.Zero, helpInfoPtr);
						Marshal.FreeHGlobal (helpInfoPtr);
					}
					break;
				}

				case XEventName.KeyRelease: {
					Keyboard.KeyEvent (FocusWindow, xevent, ref msg);
					break;
				}

				case XEventName.ButtonPress: {
					switch(xevent.ButtonEvent.button) {
						case 1: {
							MouseState |= MouseButtons.Left;
							if (client) {
								msg.message = Msg.WM_LBUTTONDOWN;
								msg.wParam = GetMousewParam (0);
							} else {
								msg.message = Msg.WM_NCLBUTTONDOWN;
								msg.wParam = (IntPtr) NCHitTest (hwnd, xevent.MotionEvent.x, xevent.MotionEvent.y);
								MenuToScreen (xevent.AnyEvent.window, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							break;
						}

						case 2: {
							MouseState |= MouseButtons.Middle;
							if (client) {
								msg.message = Msg.WM_MBUTTONDOWN;
								msg.wParam = GetMousewParam (0);
							} else {
								msg.message = Msg.WM_NCMBUTTONDOWN;
								msg.wParam = (IntPtr) NCHitTest (hwnd, xevent.MotionEvent.x, xevent.MotionEvent.y);
								MenuToScreen (xevent.AnyEvent.window, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							break;
						}

						case 3: {
							MouseState |= MouseButtons.Right;
							if (client) {
								msg.message = Msg.WM_RBUTTONDOWN;
								msg.wParam = GetMousewParam (0);
							} else {
								msg.message = Msg.WM_NCRBUTTONDOWN;
								msg.wParam = (IntPtr) NCHitTest (hwnd, xevent.MotionEvent.x, xevent.MotionEvent.y);
								MenuToScreen (xevent.AnyEvent.window, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							break;
						}

						case 4: {
							msg.hwnd = FocusWindow;
							msg.message=Msg.WM_MOUSEWHEEL;
							msg.wParam=GetMousewParam(120);
							break;
						}

						case 5: {
							msg.hwnd = FocusWindow;
							msg.message=Msg.WM_MOUSEWHEEL;
							msg.wParam=GetMousewParam(-120);
							break;
						}

					}

					msg.lParam=(IntPtr) (xevent.ButtonEvent.y << 16 | xevent.ButtonEvent.x);
					mouse_position.X = xevent.ButtonEvent.x;
					mouse_position.Y = xevent.ButtonEvent.y;

					if (!hwnd.Enabled) {
						IntPtr dummy;

						msg.hwnd = hwnd.EnabledHwnd;
						XTranslateCoordinates(DisplayHandle, xevent.AnyEvent.window, Hwnd.ObjectFromHandle(msg.hwnd).ClientWindow, xevent.ButtonEvent.x, xevent.ButtonEvent.y, out xevent.ButtonEvent.x, out xevent.ButtonEvent.y, out dummy);
						msg.lParam = (IntPtr)(mouse_position.Y << 16 | mouse_position.X);
					}

					if (Grab.Hwnd != IntPtr.Zero) {
						msg.hwnd = Grab.Hwnd;
					}

					if (ClickPending.Pending && ((((long)xevent.ButtonEvent.time - ClickPending.Time) < DoubleClickInterval) && (msg.wParam == ClickPending.wParam) && (msg.lParam == ClickPending.lParam) && (msg.message == ClickPending.Message))) {
						// Looks like a genuine double click, clicked twice on the same spot with the same keys
						switch(xevent.ButtonEvent.button) {
							case 1: {
								msg.message = client ? Msg.WM_LBUTTONDBLCLK : Msg.WM_NCLBUTTONDBLCLK;
								break;
							}

							case 2: {
								msg.message = client ? Msg.WM_MBUTTONDBLCLK : Msg.WM_NCMBUTTONDBLCLK;
								break;
							}

							case 3: {
								msg.message = client ? Msg.WM_RBUTTONDBLCLK : Msg.WM_NCRBUTTONDBLCLK;
								break;
							}
						}
						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 = (long)xevent.ButtonEvent.time;
					}
					
					if (msg.message == Msg.WM_LBUTTONDOWN || msg.message == Msg.WM_MBUTTONDOWN || msg.message == Msg.WM_RBUTTONDOWN) {
						SendParentNotify(msg.hwnd, msg.message, mouse_position.X, mouse_position.Y);
					}
					
					break;
				}

				case XEventName.ButtonRelease: {
					switch(xevent.ButtonEvent.button) {
						case 1: {
							if (client) {
								msg.message = Msg.WM_LBUTTONUP;
							} else {
								msg.message = Msg.WM_NCLBUTTONUP;
								msg.wParam = (IntPtr) NCHitTest (hwnd, xevent.MotionEvent.x, xevent.MotionEvent.y);
								MenuToScreen (xevent.AnyEvent.window, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							MouseState &= ~MouseButtons.Left;
							msg.wParam = GetMousewParam (0);
							break;
						}

						case 2: {
							if (client) {
								msg.message = Msg.WM_MBUTTONUP;
							} else {
								msg.message = Msg.WM_NCMBUTTONUP;
								msg.wParam = (IntPtr) NCHitTest (hwnd, xevent.MotionEvent.x, xevent.MotionEvent.y);
								MenuToScreen (xevent.AnyEvent.window, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							MouseState &= ~MouseButtons.Middle;
							msg.wParam = GetMousewParam (0);
							break;
						}

						case 3: {
							if (client) {
								msg.message = Msg.WM_RBUTTONUP;
							} else {
								msg.message = Msg.WM_NCRBUTTONUP;
								msg.wParam = (IntPtr) NCHitTest (hwnd, xevent.MotionEvent.x, xevent.MotionEvent.y);
								MenuToScreen (xevent.AnyEvent.window, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							MouseState &= ~MouseButtons.Right;
							msg.wParam = GetMousewParam (0);
							break;
						}

						case 4: {
							goto ProcessNextMessage;
						}

						case 5: {
							goto ProcessNextMessage;
						}
					}

					if (!hwnd.Enabled) {
						IntPtr dummy;

						msg.hwnd = hwnd.EnabledHwnd;
						XTranslateCoordinates(DisplayHandle, xevent.AnyEvent.window, Hwnd.ObjectFromHandle(msg.hwnd).ClientWindow, xevent.ButtonEvent.x, xevent.ButtonEvent.y, out xevent.ButtonEvent.x, out xevent.ButtonEvent.y, out dummy);
						msg.lParam = (IntPtr)(mouse_position.Y << 16 | mouse_position.X);
					}

					if (Grab.Hwnd != IntPtr.Zero) {
						msg.hwnd = Grab.Hwnd;
					}

					msg.lParam=(IntPtr) (xevent.ButtonEvent.y << 16 | xevent.ButtonEvent.x);
					mouse_position.X = xevent.ButtonEvent.x;
					mouse_position.Y = xevent.ButtonEvent.y;

					// Win32 splurts MouseMove events all over the place, regardless of whether the mouse is actually moving or
					// not, especially after mousedown and mouseup. To support apps relying on mousemove events between and after 
					// mouse clicks to repaint or whatever, we generate a mousemove event here. *sigh*
					if (msg.message == Msg.WM_LBUTTONUP || msg.message == Msg.WM_MBUTTONUP || msg.message == Msg.WM_RBUTTONUP) {
						XEvent motionEvent = new XEvent ();
						motionEvent.type = XEventName.MotionNotify;
						motionEvent.MotionEvent.display = DisplayHandle;
						motionEvent.MotionEvent.window = xevent.ButtonEvent.window;
						motionEvent.MotionEvent.x = xevent.ButtonEvent.x;
						motionEvent.MotionEvent.y = xevent.ButtonEvent.y;
						hwnd.Queue.EnqueueLocked (motionEvent);
					}
					break;
				}

				case XEventName.MotionNotify: {
					if (client) {
						DriverDebug("GetMessage(): Window {0:X} MotionNotify x={1} y={2}",
							    client ? hwnd.client_window.ToInt32() : hwnd.whole_window.ToInt32(),
							    xevent.MotionEvent.x, xevent.MotionEvent.y);

						if (Grab.Hwnd != IntPtr.Zero) {
							msg.hwnd = Grab.Hwnd;
						} else {
							if (hwnd.Enabled) {
								NativeWindow.WndProc(msg.hwnd, Msg.WM_SETCURSOR, msg.hwnd, (IntPtr)HitTest.HTCLIENT);
							}
						}

						if (xevent.MotionEvent.is_hint != 0)
						{
							IntPtr root, child;
							int mask;
							XQueryPointer (DisplayHandle, xevent.AnyEvent.window,
											out root, out child,
											out xevent.MotionEvent.x_root, 
											out xevent.MotionEvent.y_root,
											out xevent.MotionEvent.x,      
											out xevent.MotionEvent.y, out mask);
						}

						msg.message = Msg.WM_MOUSEMOVE;
						msg.wParam = GetMousewParam(0);
						msg.lParam = (IntPtr) (xevent.MotionEvent.y << 16 | xevent.MotionEvent.x & 0xFFFF);

						if (!hwnd.Enabled) {
							IntPtr dummy;

							msg.hwnd = hwnd.EnabledHwnd;
							XTranslateCoordinates(DisplayHandle, xevent.AnyEvent.window, Hwnd.ObjectFromHandle(msg.hwnd).ClientWindow, xevent.MotionEvent.x, xevent.MotionEvent.y, out xevent.MotionEvent.x, out xevent.MotionEvent.y, out dummy);
							msg.lParam = (IntPtr)(mouse_position.Y << 16 | mouse_position.X);
						}

						mouse_position.X = xevent.MotionEvent.x;
						mouse_position.Y = xevent.MotionEvent.y;

						if ((HoverState.Timer.Enabled) &&
						    (((mouse_position.X + HoverState.Size.Width) < HoverState.X) ||
						    ((mouse_position.X - HoverState.Size.Width) > HoverState.X) ||
						    ((mouse_position.Y + HoverState.Size.Height) < HoverState.Y) ||
						    ((mouse_position.Y - HoverState.Size.Height) > HoverState.Y))) {
							HoverState.Timer.Stop();
							HoverState.Timer.Start();
							HoverState.X = mouse_position.X;
							HoverState.Y = mouse_position.Y;
						}

						break;
					} else {
						HitTest	ht;
						IntPtr dummy;

						DriverDebug("GetMessage(): non-client area {0:X} MotionNotify x={1} y={2}",
							    client ? hwnd.client_window.ToInt32() : hwnd.whole_window.ToInt32(),
							    xevent.MotionEvent.x, xevent.MotionEvent.y);
						msg.message = Msg.WM_NCMOUSEMOVE;

						if (!hwnd.Enabled) {
							msg.hwnd = hwnd.EnabledHwnd;
							XTranslateCoordinates(DisplayHandle, xevent.AnyEvent.window, Hwnd.ObjectFromHandle(msg.hwnd).ClientWindow, xevent.MotionEvent.x, xevent.MotionEvent.y, out xevent.MotionEvent.x, out xevent.MotionEvent.y, out dummy);
							msg.lParam = (IntPtr)(mouse_position.Y << 16 | mouse_position.X);
						}

						ht = NCHitTest (hwnd, xevent.MotionEvent.x, xevent.MotionEvent.y);
						NativeWindow.WndProc(hwnd.client_window, Msg.WM_SETCURSOR, msg.hwnd, (IntPtr)ht);

						mouse_position.X = xevent.MotionEvent.x;
						mouse_position.Y = xevent.MotionEvent.y;
					}

					break;
				}

				case XEventName.EnterNotify: {
					if (!hwnd.Enabled) {
						goto ProcessNextMessage;
					}
					if (xevent.CrossingEvent.mode == NotifyMode.NotifyGrab || xevent.AnyEvent.window != hwnd.client_window) {
						goto ProcessNextMessage;
					}
					if (xevent.CrossingEvent.mode == NotifyMode.NotifyUngrab) { // Pseudo motion caused by grabbing
						if (LastPointerWindow == xevent.AnyEvent.window)
							goto ProcessNextMessage;

						if (LastPointerWindow != IntPtr.Zero) {
							Point enter_loc = new Point (xevent.ButtonEvent.x, xevent.ButtonEvent.y);

							// We need this due to EnterNotify being fired on all the parent controls
							// of the Control being grabbed, and obviously in that scenario we are not
							// actuallty entering them
							Control ctrl = Control.FromHandle (hwnd.client_window);
							foreach (Control child_control in ctrl.Controls.GetAllControls ())
								if (child_control.Bounds.Contains (enter_loc))
									goto ProcessNextMessage;

							// A MouseLeave/LeaveNotify event is sent to the previous window
							// until the mouse is ungrabbed, not when actually leaving its bounds
							int x = xevent.CrossingEvent.x_root;
							int y = xevent.CrossingEvent.y_root;
							ScreenToClient (LastPointerWindow, ref x, ref y);

							XEvent leaveEvent = new XEvent ();
							leaveEvent.type = XEventName.LeaveNotify;
							leaveEvent.CrossingEvent.display = DisplayHandle;
							leaveEvent.CrossingEvent.window = LastPointerWindow;
							leaveEvent.CrossingEvent.x = x;
							leaveEvent.CrossingEvent.y = y;
							leaveEvent.CrossingEvent.mode = NotifyMode.NotifyNormal;
							Hwnd last_pointer_hwnd = Hwnd.ObjectFromHandle (LastPointerWindow);
							last_pointer_hwnd.Queue.EnqueueLocked (leaveEvent);
						}
					}

					LastPointerWindow = xevent.AnyEvent.window;

					msg.message = Msg.WM_MOUSE_ENTER;
					HoverState.X = xevent.CrossingEvent.x;
					HoverState.Y = xevent.CrossingEvent.y;
					HoverState.Timer.Enabled = true;
					HoverState.Window = xevent.CrossingEvent.window;

					// Win32 sends a WM_MOUSEMOVE after mouse enter
					XEvent motionEvent = new XEvent ();
					motionEvent.type = XEventName.MotionNotify;
					motionEvent.MotionEvent.display = DisplayHandle;
					motionEvent.MotionEvent.window = xevent.ButtonEvent.window;
					motionEvent.MotionEvent.x = xevent.ButtonEvent.x;
					motionEvent.MotionEvent.y = xevent.ButtonEvent.y;
					hwnd.Queue.EnqueueLocked (motionEvent);
					break;
				}

				case XEventName.LeaveNotify: {
					if (xevent.CrossingEvent.mode == NotifyMode.NotifyUngrab) {
						WindowUngrabbed (hwnd.Handle);
						goto ProcessNextMessage;
					}
					if (!hwnd.Enabled) {
						goto ProcessNextMessage;
					}
					if ((xevent.CrossingEvent.mode != NotifyMode.NotifyNormal) || (xevent.CrossingEvent.window != hwnd.client_window)) {
						goto ProcessNextMessage;
					}
					// If a grab is taking place, ignore it - we handle it in EnterNotify
					if (Grab.Hwnd != IntPtr.Zero)
						goto ProcessNextMessage;

					// Reset the cursor explicitly on X11.
					// X11 remembers the last set cursor for the window and in cases where 
					// the control won't get a WM_SETCURSOR	X11 will restore the last 
					// known cursor, which we don't want.
					// 
					SetCursor (hwnd.client_window, IntPtr.Zero);

					msg.message=Msg.WM_MOUSELEAVE;
					HoverState.Timer.Enabled = false;
					HoverState.Window = IntPtr.Zero;
					break;
				}

				#if later
				case XEventName.CreateNotify: {
					if (client && (xevent.ConfigureEvent.xevent == xevent.ConfigureEvent.window)) {
						msg.message = WM_CREATE;
						// Set up CreateStruct
					} else {
						goto ProcessNextMessage;
					}
					break;
				}
				#endif


				case XEventName.ReparentNotify: {
					if (hwnd.parent == null) {	// Toplevel
						if ((xevent.ReparentEvent.parent != IntPtr.Zero) && (xevent.ReparentEvent.window == hwnd.whole_window)) {
							hwnd.Reparented = true;

							// The location given by the event is not reliable between different wm's, 
							// so use an alternative way of getting it.
							Point location = GetTopLevelWindowLocation (hwnd);
							hwnd.X = location.X;
							hwnd.Y = location.Y;

							if (hwnd.opacity != 0xffffffff) {
								IntPtr opacity;

								opacity = (IntPtr)(Int32)hwnd.opacity;
								XChangeProperty(DisplayHandle, XGetParent(hwnd.whole_window), _NET_WM_WINDOW_OPACITY, (IntPtr)Atom.XA_CARDINAL, 32, PropertyMode.Replace, ref opacity, 1);
							}
							SendMessage(msg.hwnd, Msg.WM_WINDOWPOSCHANGED, msg.wParam, msg.lParam);
							goto ProcessNextMessage;
						} else {
							hwnd.Reparented = false;
							goto ProcessNextMessage;
						}
					}
					goto ProcessNextMessage;
				}

				case XEventName.ConfigureNotify: {
					if (!client && (xevent.ConfigureEvent.xevent == xevent.ConfigureEvent.window)) {	// Ignore events for children (SubstructureNotify) and client areas
						DriverDebug("GetMessage(): Window {0:X} ConfigureNotify x={1} y={2} width={3} height={4}",
							    hwnd.client_window.ToInt32(), xevent.ConfigureEvent.x,
							    xevent.ConfigureEvent.y, xevent.ConfigureEvent.width, xevent.ConfigureEvent.height);

						lock (hwnd.configure_lock) {
							Form form = Control.FromHandle (hwnd.client_window) as Form;
							if (form != null && !hwnd.resizing_or_moving) {
								if (hwnd.x != form.Bounds.X || hwnd.y != form.Bounds.Y) {
									SendMessage (form.Handle, Msg.WM_SYSCOMMAND, (IntPtr)SystemCommands.SC_MOVE, IntPtr.Zero);
									hwnd.resizing_or_moving = true;
								} else if (hwnd.width != form.Bounds.Width || hwnd.height != form.Bounds.Height) {
									SendMessage (form.Handle, Msg.WM_SYSCOMMAND, (IntPtr)SystemCommands.SC_SIZE, IntPtr.Zero);
									hwnd.resizing_or_moving = true;
								}
								if (hwnd.resizing_or_moving)
									SendMessage (form.Handle, Msg.WM_ENTERSIZEMOVE, IntPtr.Zero, IntPtr.Zero);
							}
	
							SendMessage(msg.hwnd, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
							hwnd.configure_pending = false;
	
							// We need to adjust our client window to track the resize of whole_window
							if (hwnd.whole_window != hwnd.client_window)
								PerformNCCalc(hwnd);
						}
					}
					goto ProcessNextMessage;
				}

				case XEventName.FocusIn: {
					// We received focus. We use X11 focus only to know if the app window does or does not have focus
					// We do not track the actual focussed window via it. Instead, this is done via FocusWindow internally
					// Receiving focus means we've gotten activated and therefore we need to let the actual FocusWindow know 
					// about it having focus again
					if (xevent.FocusChangeEvent.detail != NotifyDetail.NotifyNonlinear) {
						goto ProcessNextMessage;
					}

					
					if (FocusWindow == IntPtr.Zero) {
						Control c = Control.FromHandle (hwnd.client_window);

						if (c == null)
							goto ProcessNextMessage;						
						Form form = c.FindForm ();
						if (form == null)
							goto ProcessNextMessage;
					
						if (ActiveWindow != form.Handle) {
							ActiveWindow = form.Handle;
							SendMessage (ActiveWindow, Msg.WM_ACTIVATE, (IntPtr) WindowActiveFlags.WA_ACTIVE, IntPtr.Zero);
						}
						goto ProcessNextMessage;
					}
					Keyboard.FocusIn (FocusWindow);
					SendMessage(FocusWindow, Msg.WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
					goto ProcessNextMessage;
				}

				case XEventName.FocusOut: {
					// Se the comment for our FocusIn handler
					if (xevent.FocusChangeEvent.detail != NotifyDetail.NotifyNonlinear) {
						goto ProcessNextMessage;
					}

					while (Keyboard.ResetKeyState(FocusWindow, ref msg)) {
						SendMessage(FocusWindow, msg.message, msg.wParam, msg.lParam);
					}

					Keyboard.FocusOut(hwnd.client_window);
					SendMessage(FocusWindow, Msg.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);
					goto ProcessNextMessage;
				}

				// We are already firing WM_SHOWWINDOW messages in the proper places, but I'm leaving this code
				// in case we break a scenario not taken into account in the tests
				case XEventName.MapNotify: {
					/*if (client && (xevent.ConfigureEvent.xevent == xevent.ConfigureEvent.window)) {	// Ignore events for children (SubstructureNotify) and client areas
						hwnd.mapped = true;
						msg.message = Msg.WM_SHOWWINDOW;
						msg.wParam = (IntPtr) 1;
						// XXX we're missing the lParam..
						break;
					}*/
					goto ProcessNextMessage;
				}

				case XEventName.UnmapNotify: {
					/*if (client && (xevent.ConfigureEvent.xevent == xevent.ConfigureEvent.window)) {	// Ignore events for children (SubstructureNotify) and client areas
						hwnd.mapped = false;
						msg.message = Msg.WM_SHOWWINDOW;
						msg.wParam = (IntPtr) 0;
						// XXX we're missing the lParam..
						break;
					}*/
					goto ProcessNextMessage;
				}

				case XEventName.Expose: {
					if (!hwnd.Mapped) {
						if (client) {
							hwnd.expose_pending = false;
						} else {
							hwnd.nc_expose_pending = false;
						}
						goto ProcessNextMessage;
					}

					if (client) {
						if (!hwnd.expose_pending) {
							goto ProcessNextMessage;
						}
					} else {
						if (!hwnd.nc_expose_pending) {
							goto ProcessNextMessage;
						}

						switch (hwnd.border_style) {
							case FormBorderStyle.Fixed3D: {
								Graphics g;

								g = Graphics.FromHwnd(hwnd.whole_window);
								if (hwnd.border_static)
									ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height), Border3DStyle.SunkenOuter);
								else
									ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height), Border3DStyle.Sunken);
								g.Dispose();
								break;
							}

							case FormBorderStyle.FixedSingle: {
								Graphics g;

								g = Graphics.FromHwnd(hwnd.whole_window);
								ControlPaint.DrawBorder(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height), Color.Black, ButtonBorderStyle.Solid);
								g.Dispose();
								break;
							}
						}
						DriverDebug("GetMessage(): Window {0:X} Exposed non-client area {1},{2} {3}x{4}",
							    hwnd.client_window.ToInt32(), xevent.ExposeEvent.x, xevent.ExposeEvent.y,
							    xevent.ExposeEvent.width, xevent.ExposeEvent.height);

						Rectangle rect = new Rectangle (xevent.ExposeEvent.x, xevent.ExposeEvent.y, xevent.ExposeEvent.width, xevent.ExposeEvent.height);
						Region region = new Region (rect);
						IntPtr hrgn = region.GetHrgn (null); // Graphics object isn't needed
						msg.message = Msg.WM_NCPAINT;
						msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
						msg.refobject = region;
						break;
					}
					DriverDebug("GetMessage(): Window {0:X} Exposed area {1},{2} {3}x{4}",
						    hwnd.client_window.ToInt32(), xevent.ExposeEvent.x, xevent.ExposeEvent.y,
						    xevent.ExposeEvent.width, xevent.ExposeEvent.height);
					if (Caret.Visible == true) {
						Caret.Paused = true;
						HideCaret();
					}

					if (Caret.Visible == true) {
						ShowCaret();
						Caret.Paused = false;
					}
					msg.message = Msg.WM_PAINT;
					break;
				}

				case XEventName.DestroyNotify: {

					// This is a bit tricky, we don't receive our own DestroyNotify, we only get those for our children
					hwnd = Hwnd.ObjectFromHandle(xevent.DestroyWindowEvent.window);

					// We may get multiple for the same window, act only one the first (when Hwnd still knows about it)
					if ((hwnd != null) && (hwnd.client_window == xevent.DestroyWindowEvent.window)) {
						CleanupCachedWindows (hwnd);

						DriverDebug("Received X11 Destroy Notification for {0}", XplatUI.Window(hwnd.client_window));

						msg.hwnd = hwnd.client_window;
						msg.message=Msg.WM_DESTROY;
						hwnd.Dispose();
					} else {
						goto ProcessNextMessage;
					}

					break;
				}

				case XEventName.ClientMessage: {
					if (Dnd.HandleClientMessage (ref xevent)) {
						goto ProcessNextMessage;
					}

					if (xevent.ClientMessageEvent.message_type == AsyncAtom) {
						XplatUIDriverSupport.ExecuteClientMessage((GCHandle)xevent.ClientMessageEvent.ptr1);
						goto ProcessNextMessage;
					}

					if (xevent.ClientMessageEvent.message_type == HoverState.Atom) {
						msg.message = Msg.WM_MOUSEHOVER;
						msg.wParam = GetMousewParam(0);
						msg.lParam = (IntPtr) (xevent.ClientMessageEvent.ptr1);
						return true;
					}

					if (xevent.ClientMessageEvent.message_type == (IntPtr)PostAtom) {						
						DebugHelper.Indent ();
						DebugHelper.WriteLine (String.Format ("Posted message:" + (Msg) xevent.ClientMessageEvent.ptr2.ToInt32 () + " for 0x{0:x}", xevent.ClientMessageEvent.ptr1.ToInt32 ()));
						DebugHelper.Unindent ();
						msg.hwnd = xevent.ClientMessageEvent.ptr1;
						msg.message = (Msg) xevent.ClientMessageEvent.ptr2.ToInt32 ();
						msg.wParam = xevent.ClientMessageEvent.ptr3;
						msg.lParam = xevent.ClientMessageEvent.ptr4;
						if (msg.message == (Msg)Msg.WM_QUIT)
							return false;
						else
							return true;
					}

					if  (xevent.ClientMessageEvent.message_type == _XEMBED) {
#if DriverDebugXEmbed
						Console.WriteLine("GOT EMBED MESSAGE {0:X}, detail {1:X}", xevent.ClientMessageEvent.ptr2.ToInt32(), xevent.ClientMessageEvent.ptr3.ToInt32());
#endif

						if (xevent.ClientMessageEvent.ptr2.ToInt32() == (int)XEmbedMessage.EmbeddedNotify) {
							XSizeHints hints = new XSizeHints();
							IntPtr dummy;

							XGetWMNormalHints(DisplayHandle, hwnd.whole_window, ref hints, out dummy);

							hwnd.width = hints.max_width;
							hwnd.height = hints.max_height;
							hwnd.ClientRect = Rectangle.Empty;
							SendMessage(msg.hwnd, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
						}
					}

					if  (xevent.ClientMessageEvent.message_type == WM_PROTOCOLS) {
						if (xevent.ClientMessageEvent.ptr1 == WM_DELETE_WINDOW) {
							SendMessage (msg.hwnd, Msg.WM_SYSCOMMAND, (IntPtr)SystemCommands.SC_CLOSE, IntPtr.Zero);
							msg.message = Msg.WM_CLOSE;
							return true;
						}

						// We should not get this, but I'll leave the code in case we need it in the future
						if (xevent.ClientMessageEvent.ptr1 == WM_TAKE_FOCUS) {
							goto ProcessNextMessage;
						}
					}
					goto ProcessNextMessage;
				}

				default: {
					goto ProcessNextMessage;
				}
			}

			return true;
		}
Beispiel #29
0
        public void NCPaint(ref Message m)
        {
            //IntPtr hDC = GetWindowDC(this.Handle);
            IntPtr hDC = GetDCEx(Handle, m.WParam, DCX_WINDOW | DCX_LOCKWINDOWUPDATE | DCX_UNDOCUMENTED);

            if (hDC != IntPtr.Zero)
            {
                Graphics grTemp = Graphics.FromHdc(hDC);

                int ScrollBarWidth = SystemInformation.VerticalScrollBarWidth;
                int ScrollBarHeight = SystemInformation.HorizontalScrollBarHeight;

                //Bounds is unreliable as it often reports the incorrect
                //location, especially when part of the window is OffScreen.
                //So we'll use GetWindowInfo as it returns all the info we need.
                WINDOWINFO wi = new WINDOWINFO();
                wi.cbSize = (uint) Marshal.SizeOf(wi);
                GetWindowInfo(Handle, ref wi);
                //Console.WriteLine(wi.rcWindow.ToRectangle().Width);

                wi.rcClient.Right--;
                wi.rcClient.Bottom--;

                //Define a Clip Region to pass back to WM_NCPAINTs wParam.
                //Must be in Screen Coordinates, which is what GetWindowInfo returns.
                Region updateRegion = new Region(wi.rcWindow.ToRectangle());
                updateRegion.Exclude(wi.rcClient.ToRectangle());

                if (this.HScroll && this.VScroll)
                    updateRegion.Exclude(Rectangle.FromLTRB
                        (wi.rcClient.Right + 1, wi.rcClient.Bottom + 1,
                        wi.rcWindow.Right, wi.rcWindow.Bottom));

                //For Painting we need to zero offset the Rectangles.
                Rectangle windowRect = wi.rcWindow.ToRectangle();

                Bitmap bmp = new Bitmap(windowRect.Width, windowRect.Height);
                Graphics gr = Graphics.FromImage(bmp);
                gr.Clear(Color.Black);

                Bitmap bmMask = new Bitmap(bmp.Width, bmp.Height);
                Graphics gMask = Graphics.FromImage(bmMask);
                gMask.Clear(Color.White);

                Point offset = Point.Empty - (Size) windowRect.Location;

                windowRect.Offset(offset);

                Rectangle clientRect = windowRect;

                clientRect.Inflate(-marginSize, -marginSize);
                clientRect.Width -= 1;
                clientRect.Height -= 1;

                //Fill the BorderArea
                Region paintRegion = new Region(windowRect);
                paintRegion.Exclude(clientRect);
                //					gr.FillRegion(Brushes.Green, PaintRegion);
                gMask.FillRegion(Brushes.Black, paintRegion);

                //Fill the Area between the scrollbars
                if (this.HScroll && this.VScroll)
                {
                    Rectangle scrollRect = new Rectangle(clientRect.Right - ScrollBarWidth,
                        clientRect.Bottom - ScrollBarHeight, ScrollBarWidth + 2, ScrollBarHeight + 2);
                    scrollRect.Offset(-1, -1);
                    gr.FillRectangle(SystemBrushes.Control, scrollRect);
                    gMask.FillRectangle(Brushes.Black, scrollRect);
                }

                //Adjust ClientRect for Drawing Border.
                clientRect.Inflate(2, 2);
                clientRect.Width -= 1;
                clientRect.Height -= 1;

                gr.DrawRectangle(SystemPens.ControlDark, clientRect);
                clientRect.Inflate(-1, -1);
                gr.DrawRectangle(new Pen(SystemColors.Window), clientRect);

                //Draw offscreen bitmap to Control
                //If Parent form has WS_EX_LAYERED then use
                //Interop to blit mask then image to screen
                //m.wParam will always be 1 in this case.
                if (m.WParam == (IntPtr) 1)
                {
                    Blit(bmMask, hDC, SRCAND);
                    Blit(bmp, hDC, SRCPAINT);
                }
                    //...otherwise draw image straight to control
                else
                {
                    bmp.MakeTransparent(Color.Black);
                    grTemp.DrawImage(bmp, windowRect);
                }

                //Clean Up
                gMask.Dispose();
                bmMask.Dispose();

                gr.Dispose();
                bmp.Dispose();

                //Return hRegion
            //				if ( m.WParam != (IntPtr) 1 )
            //					DeleteObject(m.WParam);

                m.WParam = updateRegion.GetHrgn(grTemp);

                ReleaseDC(Handle, hDC);
                grTemp.Dispose();
            }
        }
Beispiel #30
0
		internal override void SetClipRegion(IntPtr hwnd, Region region) {
			if (region == null)
				Win32SetWindowRgn (hwnd, IntPtr.Zero, true);
			else
				Win32SetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)), true);
		}
Beispiel #31
0
		internal override bool GetMessage (ref MSG msg, IntPtr handle, int wFilterMin, int wFilterMax)
		{
			XEvent	xevent;
			bool	client;
			Hwnd	hwnd;
			
			ProcessNextMessage:
			
			if (MessageQueue.Count > 0) {
				xevent = (XEvent) MessageQueue.Dequeue ();
			} else {
				UpdateMessageQueue ();
				
				if (MessageQueue.Count > 0) {
					xevent = (XEvent) MessageQueue.Dequeue ();
				} else {
					if (!PostQuitState) {
						msg.hwnd = IntPtr.Zero;
						msg.message = Msg.WM_ENTERIDLE;
						return true;
					}
					
					// We reset ourselves so GetMessage can be called again
					PostQuitState = false;
					
					return false;
				}
			}
			
			// FIXME - handle filtering
			
			hwnd = Hwnd.GetObjectFromWindow (xevent.AnyEvent.window);
			
			// Handle messages for windows that are already or are about to be destroyed
			if (hwnd == null) {
				#if DriverDebug
					Console.WriteLine("GetMessage(): Got message {0} for non-existent or already destroyed window {1:X}", xevent.type, xevent.AnyEvent.window.ToInt32());
				#endif
				goto ProcessNextMessage;
			}
			
			if (hwnd.client_window == xevent.AnyEvent.window) {
				client = true;
				//Console.WriteLine("Client message, sending to window {0:X}", msg.hwnd.ToInt32());
			} else {
				client = false;
				//Console.WriteLine("Non-Client message, sending to window {0:X}", msg.hwnd.ToInt32());
			}
			
			msg.hwnd = hwnd.Handle;
			
			//
			// If you add a new event to this switch make sure to add it in
			// UpdateMessage also unless it is not coming through the X event system.
			//
			switch (xevent.type) {
			case XEventName.KeyPress: {
					Keyboard.KeyEvent (FocusWindow, xevent, ref msg);
					break;
				}
				
			case XEventName.KeyRelease: {
					Keyboard.KeyEvent (FocusWindow, xevent, ref msg);
					break;
				}
				
			case XEventName.ButtonPress: {
					switch (xevent.ButtonEvent.button) {
					case 1: {
							MouseState |= MouseButtons.Left;
							if (client) {
								msg.message = Msg.WM_LBUTTONDOWN;
							} else {
								msg.message = Msg.WM_NCLBUTTONDOWN;
								WholeToScreen (msg.hwnd, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							// TODO: For WM_NCLBUTTONDOWN wParam specifies a hit-test value not the virtual keys down
							msg.wParam = GetMousewParam (0);
							break;
						}
						
					case 2: {
							MouseState |= MouseButtons.Middle;
							if (client) {
								msg.message = Msg.WM_MBUTTONDOWN;
							} else {
								msg.message = Msg.WM_NCMBUTTONDOWN;
								WholeToScreen (msg.hwnd, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							msg.wParam = GetMousewParam (0);
							break;
						}
						
					case 3: {
							MouseState |= MouseButtons.Right;
							if (client) {
								msg.message = Msg.WM_RBUTTONDOWN;
							} else {
								msg.message = Msg.WM_NCRBUTTONDOWN;
								WholeToScreen (msg.hwnd, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							msg.wParam = GetMousewParam (0);
							break;
						}
						
					case 4: {
							msg.message = Msg.WM_MOUSEWHEEL;
							msg.wParam = GetMousewParam (120);
							break;
						}
						
					case 5: {
							msg.message = Msg.WM_MOUSEWHEEL;
							msg.wParam = GetMousewParam (-120);
							break;
						}
						
					}
					
					msg.lParam = (IntPtr) (xevent.ButtonEvent.y << 16 | xevent.ButtonEvent.x);
					MousePosition.X = xevent.ButtonEvent.x;
					MousePosition.Y = xevent.ButtonEvent.y;
					
					if (!hwnd.Enabled) {
						IntPtr dummy;
						
						msg.hwnd = hwnd.EnabledHwnd;
						XTranslateCoordinates (DisplayHandle, xevent.AnyEvent.window, Hwnd.ObjectFromHandle (msg.hwnd).ClientWindow, xevent.ButtonEvent.x, xevent.ButtonEvent.y, out xevent.ButtonEvent.x, out xevent.ButtonEvent.y, out dummy);
						msg.lParam = (IntPtr)(MousePosition.Y << 16 | MousePosition.X);
					}
					
					if (Grab.Hwnd != IntPtr.Zero) {
						msg.hwnd = Grab.Hwnd;
					}
					
					if (!ClickPending.Pending) {
						ClickPending.Pending = true;
						ClickPending.Hwnd = msg.hwnd;
						ClickPending.Message = msg.message;
						ClickPending.wParam = msg.wParam;
						ClickPending.lParam = msg.lParam;
						ClickPending.Time = (long)xevent.ButtonEvent.time;
					} else {
						if ((((long)xevent.ButtonEvent.time - ClickPending.Time) < DoubleClickInterval) && (msg.wParam == ClickPending.wParam) && (msg.lParam == ClickPending.lParam) && (msg.message == ClickPending.Message)) {
							// Looks like a genuine double click, clicked twice on the same spot with the same keys
							switch (xevent.ButtonEvent.button) {
							case 1: {
									msg.message = client ? Msg.WM_LBUTTONDBLCLK : Msg.WM_NCLBUTTONDBLCLK;
									break;
								}
								
							case 2: {
									msg.message = client ? Msg.WM_MBUTTONDBLCLK : Msg.WM_NCMBUTTONDBLCLK;
									break;
								}
								
							case 3: {
									msg.message = client ? Msg.WM_RBUTTONDBLCLK : Msg.WM_NCRBUTTONDBLCLK;
									break;
								}
							}
						}
						ClickPending.Pending = false;
					}
					
					break;
				}
				
			case XEventName.ButtonRelease: {
					Dnd.HandleButtonRelease (ref xevent);
					switch (xevent.ButtonEvent.button) {
					case 1: {
							if (client) {
								msg.message = Msg.WM_LBUTTONUP;
							} else {
								msg.message = Msg.WM_NCLBUTTONUP;
								WholeToScreen (msg.hwnd, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							msg.wParam = GetMousewParam (0);
							MouseState &= ~MouseButtons.Left;
							break;
						}
						
					case 2: {
							if (client) {
								msg.message = Msg.WM_MBUTTONUP;
							} else {
								msg.message = Msg.WM_NCMBUTTONUP;
								WholeToScreen (msg.hwnd, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							msg.wParam = GetMousewParam (0);
							MouseState &= ~MouseButtons.Middle;
							break;
						}
						
					case 3: {
							if (client) {
								msg.message = Msg.WM_RBUTTONUP;
							} else {
								msg.message = Msg.WM_NCRBUTTONUP;
								WholeToScreen (msg.hwnd, ref xevent.ButtonEvent.x, ref xevent.ButtonEvent.y);
							}
							msg.wParam = GetMousewParam (0);
							MouseState &= ~MouseButtons.Right;
							break;
						}
						
					case 4: {
							goto ProcessNextMessage;
						}
						
					case 5: {
							goto ProcessNextMessage;
						}
					}
					
					if (!hwnd.Enabled) {
						IntPtr dummy;
						
						msg.hwnd = hwnd.EnabledHwnd;
						XTranslateCoordinates (DisplayHandle, xevent.AnyEvent.window, Hwnd.ObjectFromHandle (msg.hwnd).ClientWindow, xevent.ButtonEvent.x, xevent.ButtonEvent.y, out xevent.ButtonEvent.x, out xevent.ButtonEvent.y, out dummy);
						msg.lParam = (IntPtr)(MousePosition.Y << 16 | MousePosition.X);
					}
					
					if (Grab.Hwnd != IntPtr.Zero) {
						msg.hwnd = Grab.Hwnd;
					}
					
					msg.lParam = (IntPtr) (xevent.ButtonEvent.y << 16 | xevent.ButtonEvent.x);
					MousePosition.X = xevent.ButtonEvent.x;
					MousePosition.Y = xevent.ButtonEvent.y;
					break;
				}
				
			case XEventName.MotionNotify: {
					if (client) {
						#if DriverDebugExtra
							Console.WriteLine("GetMessage(): Window {0:X} MotionNotify x={1} y={2}", client ? hwnd.client_window.ToInt32() : hwnd.whole_window.ToInt32(), xevent.MotionEvent.x, xevent.MotionEvent.y);
						#endif
						
						if (Dnd.HandleMotionNotify (ref xevent))
							goto ProcessNextMessage;
						if (Grab.Hwnd != IntPtr.Zero) {
							msg.hwnd = Grab.Hwnd;
						} else {
							NativeWindow.WndProc (msg.hwnd, Msg.WM_SETCURSOR, msg.hwnd, (IntPtr)HitTest.HTCLIENT);
						}
						
						msg.message = Msg.WM_MOUSEMOVE;
						msg.wParam = GetMousewParam (0);
						msg.lParam = (IntPtr) (xevent.MotionEvent.y << 16 | xevent.MotionEvent.x & 0xFFFF);
						
						if (!hwnd.Enabled) {
							IntPtr dummy;
							
							msg.hwnd = hwnd.EnabledHwnd;
							XTranslateCoordinates (DisplayHandle, xevent.AnyEvent.window, Hwnd.ObjectFromHandle (msg.hwnd).ClientWindow, xevent.MotionEvent.x, xevent.MotionEvent.y, out xevent.MotionEvent.x, out xevent.MotionEvent.y, out dummy);
							msg.lParam = (IntPtr)(MousePosition.Y << 16 | MousePosition.X);
						}
						
						HoverState.X = MousePosition.X = xevent.MotionEvent.x;
						HoverState.Y = MousePosition.Y = xevent.MotionEvent.y;
						
						break;
					} else {
						#if DriverDebugExtra
							Console.WriteLine("GetMessage(): non-client area {0:X} MotionNotify x={1} y={2}", client ? hwnd.client_window.ToInt32() : hwnd.whole_window.ToInt32(), xevent.MotionEvent.x, xevent.MotionEvent.y);
						#endif
						msg.message = Msg.WM_NCMOUSEMOVE;
						msg.lParam = (IntPtr) (xevent.MotionEvent.y << 16 | xevent.MotionEvent.x & 0xFFFF);
						
						if (!hwnd.Enabled) {
							IntPtr dummy;
							
							msg.hwnd = hwnd.EnabledHwnd;
							XTranslateCoordinates (DisplayHandle, xevent.AnyEvent.window, Hwnd.ObjectFromHandle (msg.hwnd).ClientWindow, xevent.MotionEvent.x, xevent.MotionEvent.y, out xevent.MotionEvent.x, out xevent.MotionEvent.y, out dummy);
							msg.lParam = (IntPtr)(MousePosition.Y << 16 | MousePosition.X);
						}
						
						#if notyet
							// Not sure we need this...
							HitTest	ht;
							ht = NativeWindow.WndProc(hwnd.client_window, Msg.WM_NCHITTEST, IntPtr.Zero, msg.lParam);
						#endif
						
						MousePosition.X = xevent.MotionEvent.x;
						MousePosition.Y = xevent.MotionEvent.y;
					}
					
					break;
				}
				
			case XEventName.EnterNotify: {
					if (!hwnd.Enabled) {
						goto ProcessNextMessage;
					}
					if (xevent.CrossingEvent.mode != NotifyMode.NotifyNormal) {
						goto ProcessNextMessage;
					}
					msg.message = Msg.WM_MOUSE_ENTER;
					HoverState.Timer.Enabled = true;
					HoverState.Window = xevent.CrossingEvent.window;
					break;
				}
				
			case XEventName.LeaveNotify: {
					if (!hwnd.Enabled) {
						goto ProcessNextMessage;
					}
					if (xevent.CrossingEvent.mode != NotifyMode.NotifyNormal) {
						goto ProcessNextMessage;
					}
					msg.message = Msg.WM_MOUSELEAVE;
					HoverState.Timer.Enabled = false;
					HoverState.Window = IntPtr.Zero;
					break;
				}
				
				#if later
				case XEventName.CreateNotify: {
					if (client && (xevent.ConfigureEvent.xevent == xevent.ConfigureEvent.window)) {
						msg.message = WM_CREATE;
						// Set up CreateStruct
					} else {
						goto ProcessNextMessage;
					}
					break;
				}
				#endif
				
				
			case XEventName.ReparentNotify: {
					if (hwnd.parent == null) {	// Toplevel
						if (xevent.ReparentEvent.parent != IntPtr.Zero) {
							// We need to adjust x/y
							int	dummy_int;
							
							hwnd.Reparented = true;
							
							gdk_window_get_geometry (gdk_window_lookup (hwnd.whole_window), out hwnd.x, out hwnd.y, out dummy_int, out dummy_int, out dummy_int);
							msg.message = Msg.WM_WINDOWPOSCHANGED;
							if (hwnd.opacity != 0xffffffff) {
								uint opacity;
								
								opacity = hwnd.opacity;
								XChangeProperty (DisplayHandle, XGetParent (hwnd.whole_window), NetAtoms [(int)NA._NET_WM_WINDOW_OPACITY], Atom.XA_CARDINAL, 32, PropertyMode.Replace, ref opacity, 1);
							}
						} else {
							hwnd.Reparented = false;
							goto ProcessNextMessage;
						}
					}
					break;
				}
				
			case XEventName.ConfigureNotify: {
					if (!client && (xevent.ConfigureEvent.xevent == xevent.ConfigureEvent.window)) {	// Ignore events for children (SubstructureNotify) and client areas
						XplatUIWin32.NCCALCSIZE_PARAMS	ncp;
						IntPtr				ptr;
						Rectangle			rect;
						
						#if DriverDebugExtra
							Console.WriteLine("GetMessage(): Window {0:X} ConfigureNotify x={1} y={2} width={3} height={4}", hwnd.client_window.ToInt32(), xevent.ConfigureEvent.x, xevent.ConfigureEvent.y, xevent.ConfigureEvent.width, xevent.ConfigureEvent.height);
						#endif
						msg.message = Msg.WM_WINDOWPOSCHANGED;
						hwnd.configure_pending = false;
						
						// We need to adjust our client window to track the resize of whole_window
						rect = hwnd.DefaultClientRect;
						
						ncp = new XplatUIWin32.NCCALCSIZE_PARAMS ();
						ptr = Marshal.AllocHGlobal (Marshal.SizeOf (ncp));
						
						ncp.rgrc1.left = rect.Left;
						ncp.rgrc1.top = rect.Top;
						ncp.rgrc1.right = rect.Right;
						ncp.rgrc1.bottom = rect.Bottom;
						
						Marshal.StructureToPtr (ncp, ptr, true);
						NativeWindow.WndProc (hwnd.client_window, Msg.WM_NCCALCSIZE, (IntPtr)1, ptr);
						ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure (ptr, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
						Marshal.FreeHGlobal (ptr);
						
						// FIXME - debug this with Menus, need to set hwnd.ClientRect
						
						rect = new Rectangle (ncp.rgrc1.left, ncp.rgrc1.top, ncp.rgrc1.right - ncp.rgrc1.left, ncp.rgrc1.bottom - ncp.rgrc1.top);
						//Console.WriteLine("CreateOffscreenbuffer...");
//						CreateOffscreenBuffer (ref hwnd.client_offscreen, rect.Width, rect.Height);
						
						XMoveResizeWindow (DisplayHandle, hwnd.client_window, rect.X, rect.Y, rect.Width, rect.Height);
					} else {
						goto ProcessNextMessage;
					}
					
					msg.lParam = IntPtr.Zero;		// FIXME - Generate LPWINDOWPOS structure and pass on
					break;
				}
				
			case XEventName.FocusIn: {
					if (!hwnd.Enabled) {
						goto ProcessNextMessage;
					}
					msg.message = Msg.WM_SETFOCUS;
					msg.wParam = IntPtr.Zero;
					break;
				}
				
			case XEventName.FocusOut: {
					if (!hwnd.Enabled) {
						goto ProcessNextMessage;
					}
					msg.message = Msg.WM_KILLFOCUS;
					msg.wParam = IntPtr.Zero;
					break;
				}
				
			case XEventName.Expose: {
					if (PostQuitState) {
						goto ProcessNextMessage;
					}
					
					
					if (client) {
						if (!hwnd.expose_pending) {
							goto ProcessNextMessage;
						}
					} else {
						if (!hwnd.nc_expose_pending) {
							goto ProcessNextMessage;
						}
						
						switch (hwnd.border_style) {
						case FormBorderStyle.Fixed3D: {
								Graphics g;
								
								g = Graphics.FromHwnd (hwnd.whole_window);
								ControlPaint.DrawBorder3D (g, new Rectangle (0, 0, hwnd.Width, hwnd.Height));
								g.Dispose ();
								break;
							}
							
						case FormBorderStyle.FixedSingle: {
								Graphics g;
								
								g = Graphics.FromHwnd (hwnd.whole_window);
								ControlPaint.DrawBorder (g, new Rectangle (0, 0, hwnd.Width, hwnd.Height), Color.Black, ButtonBorderStyle.Solid);
								g.Dispose ();
								break;
							}
						}
						#if DriverDebugExtra
							Console.WriteLine("GetMessage(): Window {0:X} Exposed non-client area {1},{2} {3}x{4}", hwnd.client_window.ToInt32(), xevent.ExposeEvent.x, xevent.ExposeEvent.y, xevent.ExposeEvent.width, xevent.ExposeEvent.height);
						#endif
						
						Rectangle rect = new Rectangle (xevent.ExposeEvent.x, xevent.ExposeEvent.y, xevent.ExposeEvent.width, xevent.ExposeEvent.height);
						Region region = new Region (rect);
						IntPtr hrgn = region.GetHrgn (null); // Graphics object isn't needed
						msg.message = Msg.WM_NCPAINT;
						msg.wParam = hrgn;
						hwnd.nc_expose_pending = false;
						break;
					}
					#if DriverDebugExtra
						Console.WriteLine("GetMessage(): Window {0:X} Exposed area {1},{2} {3}x{4}", hwnd.client_window.ToInt32(), xevent.ExposeEvent.x, xevent.ExposeEvent.y, xevent.ExposeEvent.width, xevent.ExposeEvent.height);
					#endif
					if (Caret.Visible == 1) {
						Caret.Paused = true;
						HideCaret ();
					}
					
					if (Caret.Visible == 1) {
						ShowCaret ();
						Caret.Paused = false;
					}
					msg.message = Msg.WM_PAINT;
					break;
				}
				
			case XEventName.DestroyNotify: {
					
					// This is a bit tricky, we don't receive our own DestroyNotify, we only get those for our children
					hwnd = Hwnd.ObjectFromHandle (xevent.DestroyWindowEvent.window);
					
					// We may get multiple for the same window, act only one the first (when Hwnd still knows about it)
					if (hwnd.client_window == xevent.DestroyWindowEvent.window) {
						msg.hwnd = hwnd.client_window;
						msg.message = Msg.WM_DESTROY;
						hwnd.Dispose ();
						
						#if DriverDebug
							Console.WriteLine("Got DestroyNotify on Window {0:X}", msg.hwnd.ToInt32());
						#endif
					} else {
						goto ProcessNextMessage;
					}
					
					break;
				}
				
			case XEventName.ClientMessage: {
					if (Dnd.HandleClientMessage (ref xevent)) {
						goto ProcessNextMessage;
					}
					
					if (xevent.ClientMessageEvent.message_type == (IntPtr)AsyncAtom) {
						XplatUIDriverSupport.ExecuteClientMessage ((GCHandle)xevent.ClientMessageEvent.ptr1);
						break;
					}
					
					if (xevent.ClientMessageEvent.message_type == (IntPtr)HoverState.Atom) {
						msg.message = Msg.WM_MOUSEHOVER;
						msg.wParam = GetMousewParam (0);
						msg.lParam = (IntPtr) (xevent.ClientMessageEvent.ptr1);
						break;
					}
					
					if (xevent.ClientMessageEvent.message_type == (IntPtr)PostAtom) {
						msg.hwnd = xevent.ClientMessageEvent.ptr1;
						msg.message = (Msg) xevent.ClientMessageEvent.ptr2.ToInt32 ();
						msg.wParam = xevent.ClientMessageEvent.ptr3;
						msg.lParam = xevent.ClientMessageEvent.ptr4;
						break;
					}
					
					#if dontcare
					if  (xevent.ClientMessageEvent.message_type == (IntPtr)NetAtoms[(int)NA._XEMBED]) {
						Console.WriteLine("GOT EMBED MESSAGE {0:X}", xevent.ClientMessageEvent.ptr2.ToInt32());
						break;
					}
					#endif
					
					if  (xevent.ClientMessageEvent.message_type == (IntPtr)NetAtoms [(int)NA.WM_PROTOCOLS]) {
						if (xevent.ClientMessageEvent.ptr1 == (IntPtr)NetAtoms [(int)NA.WM_DELETE_WINDOW]) {
							msg.message = Msg.WM_CLOSE;
							Graphics.FromHdcInternal (IntPtr.Zero);
							break;
						}
						
						// We should not get this, but I'll leave the code in case we need it in the future
						if (xevent.ClientMessageEvent.ptr1 == (IntPtr)NetAtoms [(int)NA.WM_TAKE_FOCUS]) {
							goto ProcessNextMessage;
						}
					}
					break;
				}
				
			case XEventName.TimerNotify: {
					xevent.TimerNotifyEvent.handler (this, EventArgs.Empty);
					break;
				}
				
			default: {
					goto ProcessNextMessage;
				}
			}
			
			return true;
		}
Beispiel #32
0
 public void SetRegion(System.Drawing.Graphics graphics, System.Drawing.Region region)
 {
     hRgnBlur = region.GetHrgn(graphics);
     dwFlags |= DWM_BB.BlurRegion;
 }
 public static WindowsRegion FromRegion(Region region, Graphics g)
 {
     if (region.IsInfinite(g))
     {
         return new WindowsRegion();
     }
     return FromHregion(region.GetHrgn(g), true);
 }