Ejemplo n.º 1
0
        internal static CGSize TranslateWindowSizeToCocoaWindowSize(CreateParams cp, CGSize size)
        {
            /* From XplatUIX11
             * If this is a form with no window manager, X is handling all the border and caption painting
             * so remove that from the area (since the area we set of the window here is the part of the window
             * we're painting in only)
             */
            Form form = cp.control as Form;

            if (form != null && (form.window_manager == null || cp.IsSet(WindowExStyles.WS_EX_TOOLWINDOW)))
            {
                Hwnd.Borders borders = Hwnd.GetBorders(cp, null);
                CGSize       qsize   = size;

                qsize.Width  -= borders.left + borders.right;
                qsize.Height -= borders.top + borders.bottom;

                size = qsize;
            }

            if (size.Height == 0)
            {
                size.Height = 1;
            }
            if (size.Width == 0)
            {
                size.Width = 1;
            }
            return(size);
        }
Ejemplo n.º 2
0
 public void Remove(Hwnd hwnd)
 {
     if (!hwnd.expose_pending && !hwnd.nc_expose_pending)
     {
         hwnds.Remove(hwnd);
     }
 }
Ejemplo n.º 3
0
        private void WaitForHwndMessage(Hwnd hwnd, Msg message)
        {
            MSG msg = new MSG();

            bool done = false;

            do
            {
                if (GetMessage(null, ref msg, IntPtr.Zero, 0, 0))
                {
                    if ((Msg)msg.message == Msg.WM_QUIT)
                    {
                        PostQuitMessage(0);
                        done = true;
                    }
                    else
                    {
                        if (msg.hwnd == hwnd.Handle)
                        {
                            if ((Msg)msg.message == message)
                            {
                                break;
                            }
                            else if ((Msg)msg.message == Msg.WM_DESTROY)
                            {
                                done = true;
                            }
                        }

                        TranslateMessage(ref msg);
                        DispatchMessage(ref msg);
                    }
                }
            } while (!done);
        }
Ejemplo n.º 4
0
 public Hwnd()
 {
     x                  = 0;
     y                  = 0;
     width              = 0;
     height             = 0;
     visible            = false;
     menu               = null;
     border_style       = FormBorderStyle.None;
     client_window      = IntPtr.Zero;
     whole_window       = IntPtr.Zero;
     cursor             = IntPtr.Zero;
     handle             = IntPtr.Zero;
     parent             = null;
     invalid_list       = new ArrayList();
     expose_pending     = false;
     nc_expose_pending  = false;
     enabled            = true;
     reparented         = false;
     client_rectangle   = Rectangle_.Empty;
     marshal_free_list  = new ArrayList(2);
     opacity            = 0xffffffff;
     fixed_size         = false;
     drawing_stack      = new Stack();
     children           = new ArrayList();
     resizing_or_moving = false;
     whacky_wm          = false;
     topmost            = false;
 }
Ejemplo n.º 5
0
        private void SendParentNotify(IntPtr child, Msg cause, int x, int y)
        {
            Hwnd hwnd;

            if (child == IntPtr.Zero)
            {
                return;
            }

            hwnd = Hwnd.GetObjectFromWindow(child);

            if (hwnd == null)
            {
                return;
            }
            if (hwnd.Handle == IntPtr.Zero)
            {
                return;
            }
            if (ExStyleSet((int)hwnd.initial_ex_style, WindowExStyles.WS_EX_NOPARENTNOTIFY))
            {
                return;
            }
            if (hwnd.Parent == null)
            {
                return;
            }

            if (hwnd.Parent.Handle == IntPtr.Zero)
            {
                return;
            }

            if (cause == Msg.WM_CREATE || cause == Msg.WM_DESTROY)
            {
                SendMessage(hwnd.Parent.Handle, Msg.WM_PARENTNOTIFY, Control.MakeParam((int)cause, 0), child);
            }
            else
            {
                SendMessage(hwnd.Parent.Handle, Msg.WM_PARENTNOTIFY, Control.MakeParam((int)cause, 0), Control.MakeParam(x, y));
            }

            SendParentNotify(hwnd.Parent.Handle, cause, x, y);
        }
Ejemplo n.º 6
0
        internal static CGRect TranslateClientRectangleToQuartzClientRectangle(Hwnd hwnd, Control ctrl)
        {
            /* From XplatUIX11
             * If this is a form with no window manager, X is handling all the border and caption painting
             * so remove that from the area (since the area we set of the window here is the part of the window
             * we're painting in only)
             */
            var          crect = hwnd.ClientRect;
            CGRect       rect  = new CGRect(crect.X, crect.Y, crect.Width, crect.Height);
            Form         form  = ctrl as Form;
            CreateParams cp    = null;

            if (form != null)
            {
                cp = form.GetCreateParams();
            }

            if (form != null && (form.window_manager == null || cp.IsSet(WindowExStyles.WS_EX_TOOLWINDOW)))
            {
                Hwnd.Borders borders = Hwnd.GetBorders(cp, null);
                CGRect       qrect   = rect;

                qrect.Y      -= borders.top;
                qrect.X      -= borders.left;
                qrect.Width  += borders.left + borders.right;
                qrect.Height += borders.top + borders.bottom;

                rect = qrect;
            }

            if (rect.Width < 1 || rect.Height < 1)
            {
                rect.Width  = 1;
                rect.Height = 1;
                rect.X      = -5;
                rect.Y      = -5;
            }

            return(rect);
        }
Ejemplo n.º 7
0
        internal static bool RegisterDropTarget(IntPtr Window)
        {
            Hwnd   hwnd;
            IntPtr drop_target;
            uint   result;

            hwnd = Hwnd.ObjectFromWindow(Window);
            if (hwnd == null)
            {
                return(false);
            }

            drop_target = ComIDropTarget.GetUnmanaged(Window);
            hwnd.marshal_free_list.Add(drop_target);
            result = Win32RegisterDragDrop(Window, drop_target);

            if (result != S_OK)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
		internal static Rectangle TranslateClientRectangleToXClientRectangle (Hwnd hwnd, Control ctrl)
		{
			/* 
			 * If this is a form with no window manager, X is handling all the border and caption painting
			 * so remove that from the area (since the area we set of the window here is the part of the window 
			 * we're painting in only)
			 */
			Rectangle rect = hwnd.ClientRect;
			Form form = ctrl as Form;
			CreateParams cp = null;

			if (form != null)
				cp = form.GetCreateParams ();

			if (form != null && (form.window_manager == null && !cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
				Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
				Rectangle xrect = rect;

				xrect.Y -= borders.top;
				xrect.X -= borders.left;
				xrect.Width += borders.left + borders.right;
				xrect.Height += borders.top + borders.bottom;

				rect = xrect;
			}
			
			if (rect.Width < 1 || rect.Height < 1) {
				rect.Width = 1;
				rect.Height = 1;
				rect.X = -5;
				rect.Y = -5;
			}
			
			return rect;
		}
Ejemplo n.º 9
0
		internal override IntPtr CreateWindow(CreateParams cp) {
			IntPtr	WindowHandle;
			IntPtr	ParentHandle;
			Hwnd	hwnd;

			hwnd = new Hwnd();

			ParentHandle=cp.Parent;

			if ((ParentHandle==IntPtr.Zero) && (cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
				// We need to use our foster parent window until this poor child gets it's parent assigned
				ParentHandle = GetFosterParent();
			}

			if ( ((cp.Style & (int)(WindowStyles.WS_CHILD | WindowStyles.WS_POPUP))==0) && ((cp.ExStyle & (int)WindowExStyles.WS_EX_APPWINDOW) == 0)) {
				// If we want to be hidden from the taskbar we need to be 'owned' by 
				// something not on the taskbar. FosterParent is just that
				ParentHandle = GetFosterParent();
			}

			Point location;
			if (cp.HasWindowManager) {
				location = Hwnd.GetNextStackedFormLocation (cp, Hwnd.ObjectFromHandle (cp.Parent));
			} else {
				location = new Point (cp.X, cp.Y);
			}

			string class_name = RegisterWindowClass (cp.ClassStyle);
			HwndCreating = hwnd;

			// We cannot actually send the WS_EX_MDICHILD flag to Windows because we
			// are faking MDI, not uses Windows' version.
			if ((cp.WindowExStyle & WindowExStyles.WS_EX_MDICHILD) == WindowExStyles.WS_EX_MDICHILD)
				cp.WindowExStyle ^= WindowExStyles.WS_EX_MDICHILD;
				
			WindowHandle = Win32CreateWindow (cp.WindowExStyle, class_name, cp.Caption, cp.WindowStyle, location.X, location.Y, cp.Width, cp.Height, ParentHandle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

			HwndCreating = null;

			if (WindowHandle==IntPtr.Zero) {
				int error = Marshal.GetLastWin32Error ();

				Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window, class '"+cp.ClassName+"'", 0);
			}

			hwnd.ClientWindow = WindowHandle;
			hwnd.Mapped = true;
			Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (uint)ThemeEngine.Current.DefaultControlBackColor.ToArgb());

			return WindowHandle;
		}
Ejemplo n.º 10
0
		internal void SetDisplay(IntPtr display_handle)
		{
			if (display_handle != IntPtr.Zero) {
				Hwnd	hwnd;

				if ((DisplayHandle != IntPtr.Zero) && (FosterParent != IntPtr.Zero)) {
					hwnd = Hwnd.ObjectFromHandle(FosterParent);
					XDestroyWindow(DisplayHandle, FosterParent);
					hwnd.Dispose();
				}

				if (DisplayHandle != IntPtr.Zero) {
					XCloseDisplay(DisplayHandle);
				}

				DisplayHandle=display_handle;

				// We need to tell System.Drawing our DisplayHandle. FromHdcInternal has
				// been hacked to do this for us.
				Graphics.FromHdcInternal (DisplayHandle);

				// query for the render extension so
				// we can ignore the spurious
				// BadPicture errors that are
				// generated by cairo/render.
				XQueryExtension (DisplayHandle, "RENDER",
						 ref render_major_opcode, ref render_first_event, ref render_first_error);

				// Debugging support
				if (Environment.GetEnvironmentVariable ("MONO_XSYNC") != null) {
					XSynchronize(DisplayHandle, true);
				}

				if (Environment.GetEnvironmentVariable ("MONO_XEXCEPTIONS") != null) {
					ErrorExceptions = true;
				}

				// Generic X11 setup
				ScreenNo = XDefaultScreen(DisplayHandle);
				RootWindow = XRootWindow(DisplayHandle, ScreenNo);
				DefaultColormap = XDefaultColormap(DisplayHandle, ScreenNo);

				// Create the foster parent
				// it is important that border_width is kept in synch with the other XCreateWindow calls
				FosterParent=XCreateSimpleWindow(DisplayHandle, RootWindow, 0, 0, 1, 1, 0, UIntPtr.Zero, UIntPtr.Zero);
				if (FosterParent==IntPtr.Zero) {
					Console.WriteLine("XplatUIX11 Constructor failed to create FosterParent");
				}

				DebugHelper.WriteLine ("FosterParent created 0x{0:x}", FosterParent.ToInt32());

				hwnd = new Hwnd();
				hwnd.Queue = ThreadQueue(Thread.CurrentThread);
				hwnd.WholeWindow = FosterParent;
				hwnd.ClientWindow = FosterParent;

				// Create a HWND for RootWIndow as well, so our queue doesn't eat the events
				hwnd = new Hwnd();
				hwnd.Queue = ThreadQueue(Thread.CurrentThread);
				hwnd.whole_window = RootWindow;
				hwnd.ClientWindow = RootWindow;

				// For sleeping on the X11 socket
				listen = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
				IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 0);
				listen.Bind(ep);
				listen.Listen(1);

				// To wake up when a timer is ready
				network_buffer = new byte[10];

				wake = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
				wake.Connect(listen.LocalEndPoint);

				// Make this non-blocking, so it doesn't
				// deadlock if too many wakes are sent
				// before the wake_receive end is polled
				wake.Blocking = false;

				wake_receive = listen.Accept();

				#if __MonoCS__
				pollfds = new Pollfd [2];
				pollfds [0] = new Pollfd ();
				pollfds [0].fd = XConnectionNumber (DisplayHandle);
				pollfds [0].events = PollEvents.POLLIN;

				pollfds [1] = new Pollfd ();
				pollfds [1].fd = wake_receive.Handle.ToInt32 ();
				pollfds [1].events = PollEvents.POLLIN;
				#endif

				Keyboard = new X11Keyboard(DisplayHandle, FosterParent);
				Dnd = new X11Dnd (DisplayHandle, Keyboard);

				DoubleClickInterval = 500;

				HoverState.Interval = 500;
				HoverState.Timer = new Timer();
				HoverState.Timer.Enabled = false;
				HoverState.Timer.Interval = HoverState.Interval;
				HoverState.Timer.Tick += new EventHandler(MouseHover);
				HoverState.Size = new Size(4, 4);
				HoverState.X = -1;
				HoverState.Y = -1;

				ActiveWindow = IntPtr.Zero;
				FocusWindow = IntPtr.Zero;
				ModalWindows = new Stack(3);

				MouseState = MouseButtons.None;
				mouse_position = new Point(0, 0);

				Caret.Timer = new Timer();
				Caret.Timer.Interval = 500;		// FIXME - where should this number come from?
				Caret.Timer.Tick += new EventHandler(CaretCallback);

				SetupAtoms();

				// Grab atom changes off the root window to catch certain WM events
				XSelectInput(DisplayHandle, RootWindow, new IntPtr ((int) (EventMask.PropertyChangeMask | Keyboard.KeyEventMask)));

				// Handle any upcoming errors
				ErrorHandler = new XErrorHandler(HandleError);
				XSetErrorHandler(ErrorHandler);
			} else {
				throw new ArgumentNullException("Display", "Could not open display (X-Server required. Check your DISPLAY environment variable)");
			}
		}
Ejemplo n.º 11
0
		void ProcessGraphicsExpose (Hwnd hwnd)
		{
			XEvent xevent = new XEvent ();
			IntPtr handle = Hwnd.HandleFromObject (hwnd);
			EventPredicate predicate = GraphicsExposePredicate;

			for (;;) {
				XIfEvent (Display, ref xevent, predicate, handle);
				if (xevent.type != XEventName.GraphicsExpose)
					break;

				AddExpose (hwnd, xevent.ExposeEvent.window == hwnd.ClientWindow, xevent.GraphicsExposeEvent.x, xevent.GraphicsExposeEvent.y,
						xevent.GraphicsExposeEvent.width, xevent.GraphicsExposeEvent.height);

				if (xevent.GraphicsExposeEvent.count == 0)
					break;
			}
		}
Ejemplo n.º 12
0
		void WaitForHwndMessage (Hwnd hwnd, Msg message, bool process) {
			MSG msg = new MSG ();
			XEventQueue queue;

			queue = ThreadQueue(Thread.CurrentThread);

			queue.DispatchIdle = false;

			bool done = false;
			string key = hwnd.Handle + ":" + message;
			if (!messageHold.ContainsKey (key))	
				messageHold.Add (key, 1);
			else
				messageHold[key] = ((int)messageHold[key]) + 1;
			
					
			do {

				DebugHelper.WriteLine  ("Waiting for message " + message + " on hwnd " + String.Format("0x{0:x}", hwnd.Handle.ToInt32 ()));
				DebugHelper.Indent ();
				
				if (PeekMessage(queue, ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)) {
					if ((Msg)msg.message == Msg.WM_QUIT) {
						PostQuitMessage (0);
						done = true;
					}
					else {
						
						DebugHelper.WriteLine  ("PeekMessage got " + msg);
						
						if (msg.hwnd == hwnd.Handle) {
							if ((Msg)msg.message == message) {
								if (process) {
									TranslateMessage (ref msg);
									DispatchMessage (ref msg);
								}
								break;
							}
							else if ((Msg)msg.message == Msg.WM_DESTROY)
								done = true;
						}

						TranslateMessage (ref msg);
						DispatchMessage (ref msg);
					}
				}
				
				done = !messageHold.ContainsKey (key) || ((int)messageHold[key] < 1) || done;
			} while (!done);
						
			messageHold.Remove (key);

			DebugHelper.Unindent ();
			DebugHelper.WriteLine  ("Finished waiting for " + key);			

			queue.DispatchIdle = true;

		}
Ejemplo n.º 13
0
        public static Point_ GetNextStackedFormLocation(CreateParams cp, Hwnd parent_hwnd)
        {
            if (cp.control == null)
            {
                return(Point_.Empty);
            }

            int        X = cp.X;
            int        Y = cp.Y;
            Point_     previous, next;
            Rectangle_ within;

            if (parent_hwnd != null)
            {
                Control parent = cp.control.Parent;
                previous = parent_hwnd.previous_child_startup_location;
                if (parent_hwnd.client_rectangle == Rectangle_.Empty && parent != null)
                {
                    within = parent.ClientRectangle;
                }
                else
                {
                    within = parent_hwnd.client_rectangle;
                }
            }
            else
            {
                previous = Hwnd.previous_main_startup_location;
                within   = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
            }

            if (previous.X == int.MinValue || previous.Y == int.MinValue)
            {
                next = Point_.Empty;
            }
            else
            {
                next = new Point_(previous.X + 22, previous.Y + 22);
            }

            if (!within.Contains(next.X * 3, next.Y * 3))
            {
                next = Point_.Empty;
            }

            if (next == Point_.Empty && cp.Parent == IntPtr.Zero)
            {
                next = new Point_(22, 22);
            }

            if (parent_hwnd != null)
            {
                parent_hwnd.previous_child_startup_location = next;
            }
            else
            {
                Hwnd.previous_main_startup_location = next;
            }

            if (X == int.MinValue && Y == int.MinValue)
            {
                X = next.X;
                Y = next.Y;
            }

            return(new Point_(X, Y));
        }
Ejemplo n.º 14
0
		void SetWMStyles(Hwnd hwnd, CreateParams cp) {
			MotifWmHints		mwmHints;
			MotifFunctions		functions;
			MotifDecorations	decorations;
			int[]			atoms;
			int			atom_count;
			Rectangle		client_rect;
			Form			form;
			IntPtr			window_type;
			bool			hide_from_taskbar;
			IntPtr			transient_for_parent;
			
			// Windows we manage ourselves don't need WM window styles.
			if (cp.HasWindowManager && !cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW)) {
				return;
			}

			atoms = new int[8];
			mwmHints = new MotifWmHints();
			functions = 0;
			decorations = 0;
			window_type = _NET_WM_WINDOW_TYPE_NORMAL;
			transient_for_parent = IntPtr.Zero;

			mwmHints.flags = (IntPtr)(MotifFlags.Functions | MotifFlags.Decorations);
			mwmHints.functions = (IntPtr)0;
			mwmHints.decorations = (IntPtr)0;

			form = cp.control as Form;

			if (ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
				/* tool windows get no window manager
				   decorations.
				*/

				/* just because the window doesn't get any decorations doesn't
				   mean we should disable the functions.  for instance, without
				   MotifFunctions.Maximize, changing the windowstate to Maximized
				   is ignored by metacity. */
				functions |= MotifFunctions.Move | MotifFunctions.Resize | MotifFunctions.Minimize | MotifFunctions.Maximize;
			} else if (form != null && form.FormBorderStyle == FormBorderStyle.None) {
				/* allow borderless window to be maximized */
				functions |= MotifFunctions.All | MotifFunctions.Resize;
			} else {
				if (StyleSet (cp.Style, WindowStyles.WS_CAPTION)) {
					functions |= MotifFunctions.Move;
					decorations |= MotifDecorations.Title | MotifDecorations.Menu;
				}

				if (StyleSet (cp.Style, WindowStyles.WS_THICKFRAME)) {
					functions |= MotifFunctions.Move | MotifFunctions.Resize;
					decorations |= MotifDecorations.Border | MotifDecorations.ResizeH;
				}

				if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZEBOX)) {
					functions |= MotifFunctions.Minimize;
					decorations |= MotifDecorations.Minimize;
				}

				if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZEBOX)) {
					functions |= MotifFunctions.Maximize;
					decorations |= MotifDecorations.Maximize;
				}

				if (StyleSet (cp.Style, WindowStyles.WS_SIZEBOX)) {
					functions |= MotifFunctions.Resize;
					decorations |= MotifDecorations.ResizeH;
				}

				if (ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_DLGMODALFRAME)) {
					decorations |= MotifDecorations.Border;
				}

				if (StyleSet (cp.Style, WindowStyles.WS_BORDER)) {
					decorations |= MotifDecorations.Border;
				}
			
				if (StyleSet (cp.Style, WindowStyles.WS_DLGFRAME)) {
					decorations |= MotifDecorations.Border;
				}

				if (StyleSet (cp.Style, WindowStyles.WS_SYSMENU)) {
					functions |= MotifFunctions.Close;
				}
				else {
					functions &= ~(MotifFunctions.Maximize | MotifFunctions.Minimize | MotifFunctions.Close);
					decorations &= ~(MotifDecorations.Menu | MotifDecorations.Maximize | MotifDecorations.Minimize);
					if (cp.Caption == "") {
						functions &= ~MotifFunctions.Move;
						decorations &= ~(MotifDecorations.Title | MotifDecorations.ResizeH);
					}
				}
			}

			if ((functions & MotifFunctions.Resize) == 0) {
				hwnd.fixed_size = true;
				Rectangle fixed_rectangle = new Rectangle (cp.X, cp.Y, cp.Width, cp.Height);
				SetWindowMinMax(hwnd.Handle, fixed_rectangle, fixed_rectangle.Size, fixed_rectangle.Size, cp);
			} else {
				hwnd.fixed_size = false;
			}

			mwmHints.functions = (IntPtr)functions;
			mwmHints.decorations = (IntPtr)decorations;

			DriverDebug ("SetWMStyles ({0}, {1}) functions = {2}, decorations = {3}", hwnd, cp, functions, decorations);

			if (cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW)) {
				// needed! map toolwindows to _NET_WM_WINDOW_TYPE_UTILITY to make newer metacity versions happy
				// and get those windows in front of their parents
				window_type = _NET_WM_WINDOW_TYPE_UTILITY;
			} else {
				window_type = _NET_WM_WINDOW_TYPE_NORMAL;
			}
			
			if (!cp.IsSet (WindowExStyles.WS_EX_APPWINDOW)) {
				hide_from_taskbar = true;
			} else if (cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW) &&  form != null && form.Parent != null && !form.ShowInTaskbar) {
				hide_from_taskbar = true;
			} else {
				hide_from_taskbar = false;
			}

			if (ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
				if (form != null && !hwnd.reparented) {
					if (form.Owner != null && form.Owner.Handle != IntPtr.Zero) {
						Hwnd owner_hwnd = Hwnd.ObjectFromHandle (form.Owner.Handle);
						if (owner_hwnd != null)
							transient_for_parent = owner_hwnd.whole_window;
					}
				}
			} 
			if (StyleSet (cp.Style, WindowStyles.WS_POPUP) && (hwnd.parent != null) && (hwnd.parent.whole_window != IntPtr.Zero)) {
				transient_for_parent = hwnd.parent.whole_window;
			}
			
			FormWindowState current_state = GetWindowState (hwnd.Handle);
			if (current_state == (FormWindowState)(-1))
				current_state = FormWindowState.Normal;

			client_rect = TranslateClientRectangleToXClientRectangle (hwnd);

			lock (XlibLock) {
				atom_count = 0;

				atoms [0] = window_type.ToInt32 ();
				XChangeProperty (DisplayHandle, hwnd.whole_window, _NET_WM_WINDOW_TYPE, (IntPtr)Atom.XA_ATOM, 32, PropertyMode.Replace, atoms, 1);

				XChangeProperty(DisplayHandle, hwnd.whole_window, _MOTIF_WM_HINTS, _MOTIF_WM_HINTS, 32, PropertyMode.Replace, ref mwmHints, 5);

				if (transient_for_parent != IntPtr.Zero) {
					XSetTransientForHint (DisplayHandle, hwnd.whole_window, transient_for_parent);
				}

				MoveResizeWindow(DisplayHandle, hwnd.client_window, client_rect.X, client_rect.Y, client_rect.Width, client_rect.Height);

				if (hide_from_taskbar) {
					/* this line keeps the window from showing up in gnome's taskbar */
					atoms[atom_count++] = _NET_WM_STATE_SKIP_TASKBAR.ToInt32();
				}
				/* we need to add these atoms in the
				 * event we're maximized, since we're
				 * replacing the existing
				 * _NET_WM_STATE here.  If we don't
				 * add them, future calls to
				 * GetWindowState will return Normal
				 * for a window which is maximized. */
				if (current_state == FormWindowState.Maximized) {
					atoms[atom_count++] = _NET_WM_STATE_MAXIMIZED_HORZ.ToInt32();
					atoms[atom_count++] = _NET_WM_STATE_MAXIMIZED_VERT.ToInt32();
				}
				
				if (form != null && form.Modal) {
					atoms[atom_count++] = _NET_WM_STATE_MODAL.ToInt32 ();
				}
				
				XChangeProperty(DisplayHandle, hwnd.whole_window, _NET_WM_STATE, (IntPtr)Atom.XA_ATOM, 32, PropertyMode.Replace, atoms, atom_count);

				atom_count = 0;
				IntPtr[] atom_ptrs = new IntPtr[2];
				atom_ptrs[atom_count++] = WM_DELETE_WINDOW;
				if (ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_CONTEXTHELP)) {
					atom_ptrs[atom_count++] = _NET_WM_CONTEXT_HELP;
				}

				XSetWMProtocols(DisplayHandle, hwnd.whole_window, atom_ptrs, atom_count);
			}
		}
Ejemplo n.º 15
0
		private void WaitForHwndMessage (Hwnd hwnd, Msg message) {
			MSG msg = new MSG ();

			bool done = false;
			do {
				if (GetMessage(null, ref msg, IntPtr.Zero, 0, 0)) {
					if ((Msg)msg.message == Msg.WM_QUIT) {
						PostQuitMessage (0);
						done = true;
					}
					else {
						if (msg.hwnd == hwnd.Handle) {
							if ((Msg)msg.message == message)
								break;
							else if ((Msg)msg.message == Msg.WM_DESTROY)
								done = true;
						}

						TranslateMessage (ref msg);
						DispatchMessage (ref msg);
					}
				}
			} while (!done);
		}
Ejemplo n.º 16
0
		internal void AddExpose (Hwnd hwnd, bool client, Carbon.HIRect rect) {
			AddExpose (hwnd, client, (int) rect.origin.x, (int) rect.origin.y, (int) rect.size.width, (int) rect.size.height);
		}
Ejemplo n.º 17
0
		public void SetAllowDrop (Hwnd hwnd, bool allow)
		{
			int[] atoms;

			if (hwnd.allow_drop == allow)
				return;

			atoms = new int[XdndVersion.Length];
			for (int i = 0; i < XdndVersion.Length; i++) {
				atoms[i] = XdndVersion[i].ToInt32();
			}

			XplatUIX11.XChangeProperty (display, hwnd.whole_window, XdndAware,
					(IntPtr) Atom.XA_ATOM, 32,
					PropertyMode.Replace, atoms, allow ? 1 : 0);
			hwnd.allow_drop = allow;
		}
Ejemplo n.º 18
0
		internal void AddExpose (Hwnd hwnd, bool client, Rectangle rect) {
			AddExpose (hwnd, client, (int) rect.X, (int) rect.Y, (int) rect.Width, (int) rect.Height);
		}
Ejemplo n.º 19
0
		internal override IntPtr CreateWindow(CreateParams cp) {
			Hwnd hwnd;
			Hwnd parent_hwnd = null;
			int X;
			int Y;
			int Width;
			int Height;
			IntPtr ParentHandle;
			IntPtr WindowHandle;
			IntPtr WholeWindow;
			IntPtr ClientWindow;
			IntPtr WholeWindowTracking;
			IntPtr ClientWindowTracking;

			hwnd = new Hwnd ();

			X = cp.X;
			Y = cp.Y;
			Width = cp.Width;
			Height = cp.Height;
			ParentHandle = IntPtr.Zero;
			WindowHandle = IntPtr.Zero;
			WholeWindow = IntPtr.Zero;
			ClientWindow = IntPtr.Zero;
			WholeWindowTracking = IntPtr.Zero;
			ClientWindowTracking = IntPtr.Zero;

			if (Width < 1) Width = 1;	
			if (Height < 1) Height = 1;	

			if (cp.Parent != IntPtr.Zero) {
				parent_hwnd = Hwnd.ObjectFromHandle (cp.Parent);
				ParentHandle = parent_hwnd.client_window;
			} else {
				if (StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
					HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
				}
			}

			Point next;
			if (cp.control is Form) {
				next = Hwnd.GetNextStackedFormLocation (cp, parent_hwnd);
				X = next.X;
				Y = next.Y;
			}

			hwnd.x = X;
			hwnd.y = Y;
			hwnd.width = Width;
			hwnd.height = Height;
			hwnd.Parent = Hwnd.ObjectFromHandle (cp.Parent);
			hwnd.initial_style = cp.WindowStyle;
			hwnd.initial_ex_style = cp.WindowExStyle;
			hwnd.visible = false;

			if (StyleSet (cp.Style, WindowStyles.WS_DISABLED)) {
				hwnd.enabled = false;
			}

			ClientWindow = IntPtr.Zero;

			Size QWindowSize = TranslateWindowSizeToQuartzWindowSize (cp);
			Rectangle QClientRect = TranslateClientRectangleToQuartzClientRectangle (hwnd, cp.control);

			SetHwndStyles(hwnd, cp);
/* FIXME */
			if (ParentHandle == IntPtr.Zero) {
				IntPtr WindowView = IntPtr.Zero;
				IntPtr GrowBox = IntPtr.Zero;
				Carbon.WindowClass windowklass = Carbon.WindowClass.kOverlayWindowClass;
				Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
				if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZEBOX)) {
					attributes |= Carbon.WindowAttributes.kWindowCollapseBoxAttribute;
				}
				if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZEBOX)) {
					attributes |= Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowHorizontalZoomAttribute | Carbon.WindowAttributes.kWindowVerticalZoomAttribute;
				}
				if (StyleSet (cp.Style, WindowStyles.WS_SYSMENU)) {
					attributes |= Carbon.WindowAttributes.kWindowCloseBoxAttribute;
				}
				if (StyleSet (cp.Style, WindowStyles.WS_CAPTION)) {
					windowklass = Carbon.WindowClass.kDocumentWindowClass;
				}
				if (hwnd.border_style == FormBorderStyle.FixedToolWindow) {
					windowklass = Carbon.WindowClass.kUtilityWindowClass;
				} else if (hwnd.border_style == FormBorderStyle.SizableToolWindow) {
					attributes |= Carbon.WindowAttributes.kWindowResizableAttribute;
					windowklass = Carbon.WindowClass.kUtilityWindowClass;
				}
				if (windowklass == Carbon.WindowClass.kOverlayWindowClass) {
					attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
				}
				attributes |= Carbon.WindowAttributes.kWindowLiveResizeAttribute;

				Carbon.Rect rect = new Carbon.Rect ();
				if (StyleSet (cp.Style, WindowStyles.WS_POPUP)) {
					SetRect (ref rect, (short)X, (short)(Y), (short)(X + QWindowSize.Width), (short)(Y + QWindowSize.Height));
				} else {
					SetRect (ref rect, (short)X, (short)(Y + MenuBarHeight), (short)(X + QWindowSize.Width), (short)(Y + MenuBarHeight + QWindowSize.Height));
				}

				CreateNewWindow (windowklass, attributes, ref rect, ref WindowHandle);

				Carbon.EventHandler.InstallWindowHandler (WindowHandle);
				HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref WindowView);
				HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 7), ref GrowBox);
				HIGrowBoxViewSetTransparent (GrowBox, true);
				SetAutomaticControlDragTrackingEnabledForWindow (WindowHandle, true);
				ParentHandle = WindowView;
			}

			HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref WholeWindow);
			HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref ClientWindow);

			Carbon.EventHandler.InstallControlHandler (WholeWindow);
			Carbon.EventHandler.InstallControlHandler (ClientWindow);

			// Enable embedding on controls
			HIViewChangeFeatures (WholeWindow, 1<<1, 0);
			HIViewChangeFeatures (ClientWindow, 1<<1, 0);

			HIViewNewTrackingArea (WholeWindow, IntPtr.Zero, (UInt64)WholeWindow, ref WholeWindowTracking);
			HIViewNewTrackingArea (ClientWindow, IntPtr.Zero, (UInt64)ClientWindow, ref ClientWindowTracking);
			Carbon.HIRect WholeRect;
			if (WindowHandle != IntPtr.Zero) {
				WholeRect = new Carbon.HIRect (0, 0, QWindowSize.Width, QWindowSize.Height);
			} else {
				WholeRect = new Carbon.HIRect (X, Y, QWindowSize.Width, QWindowSize.Height);
			}
			Carbon.HIRect ClientRect = new Carbon.HIRect (QClientRect.X, QClientRect.Y, QClientRect.Width, QClientRect.Height);
			HIViewSetFrame (WholeWindow, ref WholeRect);
			HIViewSetFrame (ClientWindow, ref ClientRect);

			HIViewAddSubview (ParentHandle, WholeWindow);
			HIViewAddSubview (WholeWindow, ClientWindow);

			hwnd.WholeWindow = WholeWindow;
			hwnd.ClientWindow = ClientWindow;

			if (WindowHandle != IntPtr.Zero) {
				WindowMapping [hwnd.Handle] = WindowHandle;
				HandleMapping [WindowHandle] = hwnd.Handle;
				if (hwnd.border_style == FormBorderStyle.FixedToolWindow || hwnd.border_style == FormBorderStyle.SizableToolWindow) {
					UtilityWindows.Add (WindowHandle);
				}
			}

			// Allow dnd on controls
			Dnd.SetAllowDrop (hwnd, true);

			Text (hwnd.Handle, cp.Caption);
			
			SendMessage (hwnd.Handle, Msg.WM_CREATE, (IntPtr)1, IntPtr.Zero /* XXX unused */);
			SendParentNotify (hwnd.Handle, Msg.WM_CREATE, int.MaxValue, int.MaxValue);

			if (StyleSet (cp.Style, WindowStyles.WS_VISIBLE)) {
				if (WindowHandle != IntPtr.Zero) {
					if (Control.FromHandle(hwnd.Handle) is Form) {
						Form f = Control.FromHandle(hwnd.Handle) as Form;
						if (f.WindowState == FormWindowState.Normal) {
							SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
						}
					}
					ShowWindow (WindowHandle);
					WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
				}
				HIViewSetVisible (WholeWindow, true);
				HIViewSetVisible (ClientWindow, true);
				hwnd.visible = true;
				if (!(Control.FromHandle(hwnd.Handle) is Form)) {
					SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
				}
			}

			if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZE)) {
				SetWindowState(hwnd.Handle, FormWindowState.Minimized);
			} else if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZE)) {
				SetWindowState(hwnd.Handle, FormWindowState.Maximized);
			}

			return hwnd.Handle;
		}
Ejemplo n.º 20
0
		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;

				}
			}
		}
Ejemplo n.º 21
0
		public Hwnd() {
			x = 0;
			y = 0;
			width = 0;
			height = 0;
			visible = false;
			menu = null;
			border_style = FormBorderStyle.None;
			client_window = IntPtr.Zero;
			whole_window = IntPtr.Zero;
			cursor = IntPtr.Zero;
			handle = IntPtr.Zero;
			parent = null;
			invalid_list = new ArrayList();
			expose_pending = false;
			nc_expose_pending = false;
			enabled = true;
			reparented = false;
			client_rectangle = Rectangle.Empty;
			marshal_free_list = new ArrayList(2);
			opacity = 0xffffffff;
			fixed_size = false;
			drawing_stack = new Stack ();
			children = new ArrayList ();
			resizing_or_moving = false;
			whacky_wm = false;
			topmost = false;
		}
Ejemplo n.º 22
0
		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) {
					if (!hwnd.nc_expose_pending) {
						hwnd.Queue.Paint.Enqueue(hwnd);
					}
					hwnd.expose_pending = true;
				}
			} else {
				hwnd.AddNcInvalidArea (x, y, width, height);
				
				if (!hwnd.nc_expose_pending) {
					if (!hwnd.expose_pending) {
						hwnd.Queue.Paint.Enqueue(hwnd);
					}
					hwnd.nc_expose_pending = true;
				}
			}
		}
Ejemplo n.º 23
0
 private void SetHwndStyles(Hwnd hwnd, CreateParams cp)
 {
     DeriveStyles(cp.Style, cp.ExStyle, out hwnd.border_style, out hwnd.border_static, out hwnd.title_style, out hwnd.caption_height, out hwnd.tool_caption_height);
 }
Ejemplo n.º 24
0
		internal void PerformNCCalc(Hwnd hwnd) {
			XplatUIWin32.NCCALCSIZE_PARAMS  ncp;
			IntPtr ptr;
			Rectangle rect;

			rect = new Rectangle (0, 0, hwnd.Width, hwnd.Height);

			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);


			rect = new Rectangle(ncp.rgrc1.left, ncp.rgrc1.top, ncp.rgrc1.right - ncp.rgrc1.left, ncp.rgrc1.bottom - ncp.rgrc1.top);
			hwnd.ClientRect = rect;

			rect = TranslateClientRectangleToQuartzClientRectangle (hwnd);

			if (hwnd.visible) {
				Carbon.HIRect r = new Carbon.HIRect (rect.X, rect.Y, rect.Width, rect.Height);
				HIViewSetFrame (hwnd.client_window, ref r);
			}
	
			AddExpose (hwnd, false, 0, 0, hwnd.Width, hwnd.Height);
		}
Ejemplo n.º 25
0
		void SetHwndStyles(Hwnd hwnd, CreateParams cp) {
			DeriveStyles(cp.Style, cp.ExStyle, out hwnd.border_style, out hwnd.border_static, out hwnd.title_style, out hwnd.caption_height, out hwnd.tool_caption_height);
		}
Ejemplo n.º 26
0
 internal static CGRect TranslateClientRectangleToQuartzClientRectangle(Hwnd hwnd)
 {
     return(TranslateClientRectangleToQuartzClientRectangle(hwnd, Control.FromHandle(hwnd.Handle)));
 }
Ejemplo n.º 27
0
		void SetIcon(Hwnd hwnd, Icon icon)
		{
			if (icon == null) {
				// XXX

				// This really needs to do whatever it
				// takes to remove the window manager
				// menu, not just delete the ICON
				// property.  This will cause metacity
				// to use the "no icon set" icon, and
				// we'll still have an icon.
				XDeleteProperty (DisplayHandle, hwnd.whole_window, _NET_WM_ICON);
			}
			else {
				Bitmap		bitmap;
				int		size;
				IntPtr[]	data;
				int		index;

				bitmap = icon.ToBitmap();
				index = 0;
				size = bitmap.Width * bitmap.Height + 2;
				data = new IntPtr[size];

				data[index++] = (IntPtr)bitmap.Width;
				data[index++] = (IntPtr)bitmap.Height;

				for (int y = 0; y < bitmap.Height; y++) {
					for (int x = 0; x < bitmap.Width; x++) {
						data[index++] = (IntPtr)bitmap.GetPixel (x, y).ToArgb ();
					}
				}

				XChangeProperty (DisplayHandle, hwnd.whole_window,
						 _NET_WM_ICON, (IntPtr)Atom.XA_CARDINAL, 32,
						 PropertyMode.Replace, data, size);
			}
		}
Ejemplo n.º 28
0
		void UnmapWindow(Hwnd hwnd, WindowType windows) {
			if (hwnd.mapped) {
				Form f = null;
				if (Control.FromHandle(hwnd.Handle) is Form) {
					f = Control.FromHandle(hwnd.Handle) as Form;
					if (f.WindowState == FormWindowState.Normal) {
						f.waiting_showwindow = true;
						SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, IntPtr.Zero, IntPtr.Zero);
					}
				}

				// it's possible that our Hwnd is no
				// longer valid after making that
				// SendMessage call, so check here.
				// FIXME: it is likely wrong, as it has already sent WM_SHOWWINDOW
				if (hwnd.zombie)
					return;

				if ((windows & WindowType.Client) != 0) {
					XUnmapWindow(DisplayHandle, hwnd.client_window);
				}
				if ((windows & WindowType.Whole) != 0) {
					XUnmapWindow(DisplayHandle, hwnd.whole_window);
				}

				hwnd.mapped = false;

				if (f != null) {
					if (f.waiting_showwindow) {
						WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
						CreateParams cp = f.GetCreateParams();
						if (!ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_MDICHILD) &&
						    !StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
							WaitForHwndMessage (hwnd, Msg.WM_ACTIVATE, true);
						}
					}
				}
			}
		}
Ejemplo n.º 29
0
		void WaitForHwndMessage (Hwnd hwnd, Msg message) {
			WaitForHwndMessage (hwnd, message, false);

		}
Ejemplo n.º 30
0
		void PerformNCCalc(Hwnd hwnd) {
			XplatUIWin32.NCCALCSIZE_PARAMS	ncp;
			IntPtr				ptr;
			Rectangle			rect;

			rect = new Rectangle (0, 0, hwnd.Width, hwnd.Height);

			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);


			rect = new Rectangle(ncp.rgrc1.left, ncp.rgrc1.top, ncp.rgrc1.right - ncp.rgrc1.left, ncp.rgrc1.bottom - ncp.rgrc1.top);
			hwnd.ClientRect = rect;
		
			rect = TranslateClientRectangleToXClientRectangle (hwnd);

			if (hwnd.visible) {
				MoveResizeWindow (DisplayHandle, hwnd.client_window, rect.X, rect.Y, rect.Width, rect.Height);
			}

			AddExpose (hwnd, hwnd.WholeWindow == hwnd.ClientWindow, 0, 0, hwnd.Width, hwnd.Height);
		}
Ejemplo n.º 31
0
		void MapWindow(Hwnd hwnd, WindowType windows) {
			if (!hwnd.mapped) {
				Form f = Control.FromHandle(hwnd.Handle) as Form;
				if (f != null) {
					if (f.WindowState == FormWindowState.Normal) {
						f.waiting_showwindow = true;
						SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
					}
				}

				// it's possible that our Hwnd is no
				// longer valid after making that
				// SendMessage call, so check here.
				if (hwnd.zombie)
					return;

				if (hwnd.topmost) {
					// Most window managers will respect the _NET_WM_STATE property.
					// If not, use XMapRaised to map the window at the top level as
					// a last ditch effort.
					if ((windows & WindowType.Whole) != 0) {
						XMapRaised(DisplayHandle, hwnd.whole_window);
					}
					if ((windows & WindowType.Client) != 0) {
						XMapRaised(DisplayHandle, hwnd.client_window);
					}
				} else {
					if ((windows & WindowType.Whole) != 0) {
						XMapWindow(DisplayHandle, hwnd.whole_window);
					}
					if ((windows & WindowType.Client) != 0) {
						XMapWindow(DisplayHandle, hwnd.client_window);
					}
				}

				hwnd.mapped = true;

				if (f != null) {
					if (f.waiting_showwindow) {
						WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
						CreateParams cp = f.GetCreateParams();
						if (!ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_MDICHILD) &&
						    !StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
							WaitForHwndMessage (hwnd, Msg.WM_ACTIVATE, true);
						}
					}
				}
			}
		}
Ejemplo n.º 32
0
 public static IntPtr HandleFromObject(Hwnd obj)
 {
     return(obj.handle);
 }
Ejemplo n.º 33
0
		void CleanupCachedWindows (Hwnd hwnd)
		{
			if (ActiveWindow == hwnd.Handle) {
				SendMessage(hwnd.client_window, Msg.WM_ACTIVATE, (IntPtr)WindowActiveFlags.WA_INACTIVE, IntPtr.Zero);
				ActiveWindow = IntPtr.Zero;
			}

			if (FocusWindow == hwnd.Handle) {
				SendMessage(hwnd.client_window, Msg.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);
				FocusWindow = IntPtr.Zero;
			}

			if (Grab.Hwnd == hwnd.Handle) {
				Grab.Hwnd = IntPtr.Zero;
				Grab.Confined = false;
			}

			DestroyCaret (hwnd.Handle);
		}
Ejemplo n.º 34
0
        internal override IntPtr CreateWindow(CreateParams cp)
        {
            Hwnd     hwnd;
            Hwnd     parent_hwnd = null;
            int      X;
            int      Y;
            int      Width;
            int      Height;
            IntPtr   ParentHandle;
            NSWindow window;
            NSView   WholeWindow;
            NSView   ClientWindow;
            IntPtr   WholeWindowTracking;
            IntPtr   ClientWindowTracking;

            hwnd = new Hwnd();

            X                    = cp.X;
            Y                    = cp.Y;
            Width                = cp.Width;
            Height               = cp.Height;
            ParentHandle         = IntPtr.Zero;
            window               = null;
            WholeWindow          = null;
            ClientWindow         = null;
            WholeWindowTracking  = IntPtr.Zero;
            ClientWindowTracking = IntPtr.Zero;

            if (Width < 1)
            {
                Width = 1;
            }
            if (Height < 1)
            {
                Height = 1;
            }

            if (cp.Parent != IntPtr.Zero)
            {
                parent_hwnd  = Hwnd.ObjectFromHandle(cp.Parent);
                ParentHandle = parent_hwnd.client_window;
            }
            else
            {
                if (StyleSet(cp.Style, WindowStyles.WS_CHILD))
                {
                    // HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
                    Console.WriteLine("CreateWindow WS_CHILD not implemented");
                }
            }

            Point next;

            if (cp.control is Form)
            {
                next = Hwnd.GetNextStackedFormLocation(cp, parent_hwnd);
                X    = next.X;
                Y    = next.Y;
            }

            hwnd.x                = X;
            hwnd.y                = Y;
            hwnd.width            = Width;
            hwnd.height           = Height;
            hwnd.Parent           = Hwnd.ObjectFromHandle(cp.Parent);
            hwnd.initial_style    = cp.WindowStyle;
            hwnd.initial_ex_style = cp.WindowExStyle;
            hwnd.visible          = false;

            if (StyleSet(cp.Style, WindowStyles.WS_DISABLED))
            {
                hwnd.enabled = false;
            }

            ClientWindow = null;

            CGSize QWindowSize = TranslateWindowSizeToQuartzWindowSize(cp);
            CGRect QClientRect = TranslateClientRectangleToQuartzClientRectangle(hwnd, cp.control);

            SetHwndStyles(hwnd, cp);
            /* FIXME */
            if (ParentHandle == IntPtr.Zero)
            {
                NSWindowStyle style      = 0;
                IntPtr        WindowView = IntPtr.Zero;
                IntPtr        GrowBox    = IntPtr.Zero;

                // Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
                if (StyleSet(cp.Style, WindowStyles.WS_MINIMIZEBOX))
                {
                    style |= NSWindowStyle.Miniaturizable;
                }

                if (StyleSet(cp.Style, WindowStyles.WS_MAXIMIZEBOX))
                {
                    style |= NSWindowStyle.Resizable;
                }

                if (StyleSet(cp.Style, WindowStyles.WS_SYSMENU))
                {
                    style |= NSWindowStyle.Closable;
                }

                if (StyleSet(cp.Style, WindowStyles.WS_CAPTION))
                {
                    style |= NSWindowStyle.Titled;
                }


                if (hwnd.border_style == FormBorderStyle.FixedToolWindow)
                {
                    style |= NSWindowStyle.Utility;
                }
                else if (hwnd.border_style == FormBorderStyle.SizableToolWindow)
                {
                    style |= NSWindowStyle.Resizable;
                }

                CGRect rect = StyleSet(cp.Style, WindowStyles.WS_POPUP)
                                        ? new CGRect((short)X, (short)(Y), (short)(X + QWindowSize.Width), (short)(Y + QWindowSize.Height))
                                        : new CGRect((short)X, (short)(Y + MenuBarHeight), (short)(X + QWindowSize.Width), (short)(Y + MenuBarHeight + QWindowSize.Height));

                window = new NSWindow(rect, style, NSBackingStore.Buffered, false);

#if false
                Carbon.EventHandler.InstallWindowHandler(window);
                HIViewFindByID(HIViewGetRoot(window), new Carbon.HIViewID(Carbon.EventHandler.kEventClassWindow, 1), ref WindowView);
                HIViewFindByID(HIViewGetRoot(window), new Carbon.HIViewID(Carbon.EventHandler.kEventClassWindow, 7), ref GrowBox);
                HIGrowBoxViewSetTransparent(GrowBox, true);
                SetAutomaticControlDragTrackingEnabledForWindow(window, true);
                ParentHandle = WindowView;
#endif
            }

#if false
            HIObjectCreate(__CFStringMakeConstantString("com.novell.mwfview"), 0, ref WholeWindow);
            HIObjectCreate(__CFStringMakeConstantString("com.novell.mwfview"), 0, ref ClientWindow);

            Carbon.EventHandler.InstallControlHandler(WholeWindow);
            Carbon.EventHandler.InstallControlHandler(ClientWindow);

            // Enable embedding on controls
            HIViewChangeFeatures(WholeWindow, 1 << 1, 0);
            HIViewChangeFeatures(ClientWindow, 1 << 1, 0);

            HIViewNewTrackingArea(WholeWindow, IntPtr.Zero, (UInt64)WholeWindow, ref WholeWindowTracking);
            HIViewNewTrackingArea(ClientWindow, IntPtr.Zero, (UInt64)ClientWindow, ref ClientWindowTracking);
            Carbon.HIRect WholeRect;
            if (window != IntPtr.Zero)
            {
                WholeRect = new Carbon.HIRect(0, 0, QWindowSize.Width, QWindowSize.Height);
            }
            else
            {
                WholeRect = new Carbon.HIRect(X, Y, QWindowSize.Width, QWindowSize.Height);
            }
            Carbon.HIRect ClientRect = new Carbon.HIRect(QClientRect.X, QClientRect.Y, QClientRect.Width, QClientRect.Height);
            HIViewSetFrame(WholeWindow, ref WholeRect);
            HIViewSetFrame(ClientWindow, ref ClientRect);

            HIViewAddSubview(ParentHandle, WholeWindow);
            HIViewAddSubview(WholeWindow, ClientWindow);

            hwnd.WholeWindow  = WholeWindow;
            hwnd.ClientWindow = ClientWindow;
#endif
            CGRect WholeRect;
            if (window != null)
            {
                WholeRect = new CGRect(0, 0, QWindowSize.Width, QWindowSize.Height);
            }
            else
            {
                WholeRect = new CGRect(X, Y, QWindowSize.Width, QWindowSize.Height);
            }

            CGRect ClientRect = new CGRect(QClientRect.X, QClientRect.Y, QClientRect.Width, QClientRect.Height);
            WholeWindow  = new NSView(WholeRect);
            ClientWindow = new NSView(ClientRect);

            window.ContentView.AddSubview(WholeWindow);
            window.ContentView.AddSubview(ClientWindow);

            hwnd.WholeWindow  = WholeWindow.Handle;
            hwnd.ClientWindow = ClientWindow.Handle;

            if (window != null)
            {
                WindowMapping [hwnd.Handle] = window;
                HandleMapping [window]      = hwnd.Handle;
                if (hwnd.border_style == FormBorderStyle.FixedToolWindow || hwnd.border_style == FormBorderStyle.SizableToolWindow)
                {
                    UtilityWindows.Add(window);
                }
            }

#if false
            // Allow dnd on controls
            Dnd.SetAllowDrop(hwnd, true);
#endif
            window.Title = cp.Caption;

            SendMessage(hwnd.Handle, Msg.WM_CREATE, (IntPtr)1, IntPtr.Zero /* XXX unused */);
            SendParentNotify(hwnd.Handle, Msg.WM_CREATE, int.MaxValue, int.MaxValue);

            if (StyleSet(cp.Style, WindowStyles.WS_VISIBLE))
            {
                if (window != null)
                {
                    if (Control.FromHandle(hwnd.Handle) is Form)
                    {
                        Form f = Control.FromHandle(hwnd.Handle) as Form;
                        if (f.WindowState == FormWindowState.Normal)
                        {
                            SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
                        }
                    }
                    window.OrderFront(window);
                    WaitForHwndMessage(hwnd, Msg.WM_SHOWWINDOW);
                }
#if false
                HIViewSetVisible(WholeWindow, true);
                HIViewSetVisible(ClientWindow, true);
                hwnd.visible = true;
#endif
                if (!(Control.FromHandle(hwnd.Handle) is Form))
                {
                    SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
                }
            }

            if (StyleSet(cp.Style, WindowStyles.WS_MINIMIZE))
            {
                window.Miniaturize(window);
            }
            else if (StyleSet(cp.Style, WindowStyles.WS_MAXIMIZE))
            {
                // TODO
            }

            return(hwnd.Handle);
        }
Ejemplo n.º 35
0
		internal override IntPtr CreateWindow (CreateParams cp)
		{
			XSetWindowAttributes	Attributes;
			Hwnd			hwnd;
			Hwnd			parent_hwnd = null;
			int			X;
			int			Y;
			int			Width;
			int			Height;
			IntPtr			ParentHandle;
			IntPtr			WholeWindow;
			IntPtr			ClientWindow;
			SetWindowValuemask	ValueMask;
			int[]			atoms;

			hwnd = new Hwnd();

			Attributes = new XSetWindowAttributes();
			X = cp.X;
			Y = cp.Y;
			Width = cp.Width;
			Height = cp.Height;

			if (Width<1) Width=1;
			if (Height<1) Height=1;

			if (cp.Parent != IntPtr.Zero) {
				parent_hwnd = Hwnd.ObjectFromHandle(cp.Parent);
				ParentHandle = parent_hwnd.client_window;
			} else {
				if (StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
					// We need to use our foster parent window until this poor child gets it's parent assigned
					ParentHandle=FosterParent;
				} else {
					ParentHandle=RootWindow;
				}
			}

			// Set the default location location for forms.
			Point next;
			if (cp.control is Form) {
				next = Hwnd.GetNextStackedFormLocation (cp, parent_hwnd);
				X = next.X;
				Y = next.Y;
			}
			ValueMask = SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity;

			Attributes.bit_gravity = Gravity.NorthWestGravity;
			Attributes.win_gravity = Gravity.NorthWestGravity;

			// Save what's under the toolwindow
			if (ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
				Attributes.save_under = true;
				ValueMask |= SetWindowValuemask.SaveUnder;
			}


			// If we're a popup without caption we override the WM
			if (StyleSet (cp.Style, WindowStyles.WS_POPUP) && !StyleSet (cp.Style, WindowStyles.WS_CAPTION)) {
				Attributes.override_redirect = true;
				ValueMask |= SetWindowValuemask.OverrideRedirect;
			}

			hwnd.x = X;
			hwnd.y = Y;
			hwnd.width = Width;
			hwnd.height = Height;
			hwnd.parent = Hwnd.ObjectFromHandle(cp.Parent);
			hwnd.initial_style = cp.WindowStyle;
			hwnd.initial_ex_style = cp.WindowExStyle;

			if (StyleSet (cp.Style, WindowStyles.WS_DISABLED)) {
				hwnd.enabled = false;
			}

			ClientWindow = IntPtr.Zero;

			Size XWindowSize = TranslateWindowSizeToXWindowSize (cp);
			Rectangle XClientRect = TranslateClientRectangleToXClientRectangle (hwnd, cp.control);
				
			lock (XlibLock) {
				WholeWindow = XCreateWindow(DisplayHandle, ParentHandle, X, Y, XWindowSize.Width, XWindowSize.Height, 0, (int)CreateWindowArgs.CopyFromParent, (int)CreateWindowArgs.InputOutput, IntPtr.Zero, new UIntPtr ((uint)ValueMask), ref Attributes);
				if (WholeWindow != IntPtr.Zero) {
					ValueMask &= ~(SetWindowValuemask.OverrideRedirect | SetWindowValuemask.SaveUnder);

					if (CustomVisual != IntPtr.Zero && CustomColormap != IntPtr.Zero) {
						ValueMask = SetWindowValuemask.ColorMap;
						Attributes.colormap = CustomColormap;
					}
					ClientWindow = XCreateWindow(DisplayHandle, WholeWindow, XClientRect.X, XClientRect.Y, XClientRect.Width, XClientRect.Height, 0, (int)CreateWindowArgs.CopyFromParent, (int)CreateWindowArgs.InputOutput, CustomVisual, new UIntPtr ((uint)ValueMask), ref Attributes);
				}
			}

			if ((WholeWindow == IntPtr.Zero) || (ClientWindow == IntPtr.Zero)) {
				throw new Exception("Could not create X11 windows");
			}

			hwnd.Queue = ThreadQueue(Thread.CurrentThread);
			hwnd.WholeWindow = WholeWindow;
			hwnd.ClientWindow = ClientWindow;

			DriverDebug("Created window {0:X} / {1:X} parent {2:X}, Style {3}, ExStyle {4}", ClientWindow.ToInt32(), WholeWindow.ToInt32(), hwnd.parent != null ? hwnd.parent.Handle.ToInt32() : 0, (WindowStyles)cp.Style, (WindowExStyles)cp.ExStyle);
			
			if (!StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
				if ((X != unchecked((int)0x80000000)) && (Y != unchecked((int)0x80000000))) {
					XSizeHints	hints;

					hints = new XSizeHints();
					hints.x = X;
					hints.y = Y;
					hints.flags = (IntPtr)(XSizeHintsFlags.USPosition | XSizeHintsFlags.PPosition);
					XSetWMNormalHints(DisplayHandle, WholeWindow, ref hints);
				}
			}

			lock (XlibLock) {
				XSelectInput(DisplayHandle, hwnd.whole_window, new IntPtr ((int)(SelectInputMask | EventMask.StructureNotifyMask | EventMask.PropertyChangeMask | Keyboard.KeyEventMask)));
				if (hwnd.whole_window != hwnd.client_window)
					XSelectInput(DisplayHandle, hwnd.client_window, new IntPtr ((int)(SelectInputMask | EventMask.StructureNotifyMask | Keyboard.KeyEventMask)));
			}

			if (ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_TOPMOST))
				SetTopmost(hwnd.whole_window, true);

			SetWMStyles(hwnd, cp);
			
			// set the group leader
			XWMHints wm_hints = new XWMHints ();
			
			wm_hints.flags = (IntPtr)(XWMHintsFlags.InputHint | XWMHintsFlags.StateHint | XWMHintsFlags.WindowGroupHint);
			wm_hints.input = !StyleSet (cp.Style, WindowStyles.WS_DISABLED);
			wm_hints.initial_state = StyleSet (cp.Style, WindowStyles.WS_MINIMIZE) ? XInitialState.IconicState : XInitialState.NormalState;
			
			if (ParentHandle != RootWindow) {
				wm_hints.window_group = hwnd.whole_window;
			} else {
				wm_hints.window_group = ParentHandle;
			}
			
			lock (XlibLock) {
				XSetWMHints(DisplayHandle, hwnd.whole_window, ref wm_hints );
			}

			if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZE)) {
				SetWindowState(hwnd.Handle, FormWindowState.Minimized);
			} else if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZE)) {
				SetWindowState(hwnd.Handle, FormWindowState.Maximized);
			}

			// for now make all windows dnd enabled
			Dnd.SetAllowDrop (hwnd, true);

			// Set caption/window title
			Text(hwnd.Handle, cp.Caption);

			SendMessage (hwnd.Handle, Msg.WM_CREATE, (IntPtr)1, IntPtr.Zero /* XXX unused */);
			SendParentNotify (hwnd.Handle, Msg.WM_CREATE, int.MaxValue, int.MaxValue);

			if (StyleSet (cp.Style, WindowStyles.WS_VISIBLE)) {
				hwnd.visible = true;
				MapWindow(hwnd, WindowType.Both);
				if (!(Control.FromHandle(hwnd.Handle) is Form))
					SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
			}

			return hwnd.Handle;
		}
Ejemplo n.º 36
0
 internal override bool CalculateWindowRect(ref Rectangle ClientRect, CreateParams cp, Menu menu, out Rectangle WindowRect)
 {
     WindowRect = Hwnd.GetWindowRectangle(cp, menu, ClientRect);
     return(true);
 }
Ejemplo n.º 37
0
		HitTest NCHitTest (Hwnd hwnd, int x, int y)
		{
			// The hit test is sent in screen coordinates
			IntPtr dummy;
			int screen_x, screen_y;
			XTranslateCoordinates (DisplayHandle, hwnd.WholeWindow, RootWindow, x, y, out screen_x, out screen_y, out dummy);
			return (HitTest) NativeWindow.WndProc (hwnd.client_window, Msg.WM_NCHITTEST, IntPtr.Zero, 
							       (IntPtr) (screen_y << 16 | screen_x & 0xFFFF));
		}
Ejemplo n.º 38
0
			public void Enqueue (Hwnd hwnd) {
				hwnds.Add(hwnd);
			}
Ejemplo n.º 39
0
		internal static Rectangle TranslateClientRectangleToXClientRectangle (Hwnd hwnd)
		{
			return TranslateClientRectangleToXClientRectangle (hwnd, Control.FromHandle (hwnd.Handle));
		}
Ejemplo n.º 40
0
			public void Remove(Hwnd hwnd) {
				if (!hwnd.expose_pending && !hwnd.nc_expose_pending) {
					hwnds.Remove(hwnd);
				}
			}
Ejemplo n.º 41
0
		internal static Point GetTopLevelWindowLocation (Hwnd hwnd)
		{
			IntPtr dummy; 
			int x, y;
			Hwnd.Borders frame;

			XTranslateCoordinates (DisplayHandle, hwnd.whole_window, RootWindow, 0, 0, out x, out y, out dummy);
			frame = FrameExtents (hwnd.whole_window);

			x -= frame.left;
			y -= frame.top;
			
			return new Point (x, y);
		}
Ejemplo n.º 42
0
 public void Enqueue(Hwnd hwnd)
 {
     hwnds.Add(hwnd);
 }
Ejemplo n.º 43
0
Archivo: Dnd.cs Proyecto: nlhepler/mono
		public void SetAllowDrop (Hwnd hwnd, bool allow) {
			if (hwnd.allow_drop == allow)
				return;

			hwnd.allow_drop = allow;
			SetControlDragTrackingEnabled (hwnd.whole_window, true);
			SetControlDragTrackingEnabled (hwnd.client_window, true);
		}
Ejemplo n.º 44
0
		public static Point GetNextStackedFormLocation  (CreateParams cp, Hwnd parent_hwnd)
		{
			if (cp.control == null)
				return Point.Empty;
		
			int X = cp.X;
			int Y = cp.Y;
			Point previous, next;
			Rectangle within;

			if (parent_hwnd != null) {
				Control parent = cp.control.Parent;
				previous = parent_hwnd.previous_child_startup_location;
				if (parent_hwnd.client_rectangle == Rectangle.Empty && parent != null) {
					within = parent.ClientRectangle;
				} else {
					within = parent_hwnd.client_rectangle;
				}
			} else {
				previous = Hwnd.previous_main_startup_location;
				within = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
			}

			if (previous.X == int.MinValue || previous.Y == int.MinValue) {
				next = Point.Empty;
			} else {
				next = new Point (previous.X + 22, previous.Y + 22);
			}

			if (!within.Contains (next.X * 3, next.Y * 3)) {
				next = Point.Empty;
			}

			if (next == Point.Empty && cp.Parent == IntPtr.Zero) {
				next = new Point (22, 22);
			}

			if (parent_hwnd != null) {
				parent_hwnd.previous_child_startup_location = next;
			} else {
				Hwnd.previous_main_startup_location = next;
			}

			if (X == int.MinValue && Y == int.MinValue) {
				X = next.X;
				Y = next.Y;
			}
			
			return new Point (X, Y);
		}