static void realize(IntPtr self) { GdkRectangle allocation; gtk_widget_get_allocation(self, out allocation); gtk_widget_set_realized(self, true); GdkWindowAttr attributes = new GdkWindowAttr(); attributes.x = allocation.x; attributes.y = allocation.y; attributes.width = allocation.width; attributes.height = allocation.height; attributes.window_type = GdkWindowType.GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events(self) | GdkEventMask.GDK_BUTTON_MOTION_MASK | GdkEventMask.GDK_BUTTON_PRESS_MASK | GdkEventMask.GDK_BUTTON_RELEASE_MASK | GdkEventMask.GDK_EXPOSURE_MASK | GdkEventMask.GDK_ENTER_NOTIFY_MASK | GdkEventMask.GDK_LEAVE_NOTIFY_MASK; attributes.visual = gtk_widget_get_visual(self); attributes.wclass = GdkWindowWindowClass.GDK_INPUT_OUTPUT; GdkWindowAttributesType attributes_mask = GdkWindowAttributesType.GDK_WA_X | GdkWindowAttributesType.GDK_WA_Y | GdkWindowAttributesType.GDK_WA_VISUAL; IntPtr window = gdk_window_new(gtk_widget_get_parent_window(self), ref attributes, attributes_mask); gtk_widget_set_window(self, window); gtk_widget_register_window(self, window); }
static extern IntPtr gdk_window_new (IntPtr gdk_parent, ref GdkWindowAttr gdk_window_attributes, int attributes_mask);
internal override IntPtr CreateWindow (CreateParams cp) { GdkWindowAttr gdk_window_attributes; GdkWindowAttributesType attributes_mask = 0; Hwnd hwnd; int X; int Y; int Width; int Height; IntPtr GdkParentHandle; IntPtr GdkWholeWindow; IntPtr GdkClientWindow; Rectangle ClientRect; GdkWindowType gdk_window_type; hwnd = new Hwnd (); gdk_window_attributes = new GdkWindowAttr (); X = cp.X; Y = cp.Y; Width = cp.Width; Height = cp.Height; if (Width < 1) Width = 1; if (Height < 1) Height = 1; gdk_window_type = GdkWindowType.GDK_WINDOW_CHILD; if (cp.Parent != IntPtr.Zero) { GdkParentHandle = gdk_window_lookup (Hwnd.ObjectFromHandle (cp.Parent).client_window); } else { if ((cp.Style & (int)WindowStyles.WS_CHILD) != 0) { // We need to use our foster parent window until this poor child gets it's parent assigned GdkParentHandle = GdkFosterParent; } else if ((cp.Style & (int)WindowStyles.WS_POPUP) != 0) { GdkParentHandle = GdkRootWindow; } else { // Default position on screen, if window manager doesn't place us somewhere else if (X < 1) X = 50; if (Y < 1) Y = 50; GdkParentHandle = GdkRootWindow; } } // ValueMask = SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity; // Attributes.bit_gravity = Gravity.NorthWestGravity; // Attributes.win_gravity = Gravity.NorthWestGravity; // FIXME: does gdk need that ? // Save what's under the toolwindow if ((cp.ExStyle & (int)WindowStyles.WS_EX_TOOLWINDOW) != 0) { // Attributes.save_under = true; // ValueMask |= SetWindowValuemask.SaveUnder; } // If we're a popup without caption we override the WM if ((cp.Style & ((int)WindowStyles.WS_POPUP)) != 0) { if ((cp.Style & (int)WindowStyles.WS_CAPTION) == 0) { gdk_window_attributes.override_redirect = true; attributes_mask |= GdkWindowAttributesType.GDK_WA_NOREDIR; } } hwnd.x = X; hwnd.y = Y; hwnd.width = Width; hwnd.height = Height; hwnd.parent = Hwnd.ObjectFromHandle (cp.Parent); if ((cp.Style & ((int)WindowStyles.WS_DISABLED)) != 0) { hwnd.enabled = false; } ClientRect = hwnd.ClientRect; GdkClientWindow = IntPtr.Zero; gdk_window_attributes.x = X; gdk_window_attributes.y = Y; gdk_window_attributes.width = Width; gdk_window_attributes.height = Height; gdk_window_attributes.window_type = gdk_window_type; attributes_mask |= GdkWindowAttributesType.GDK_WA_X | GdkWindowAttributesType.GDK_WA_Y; gdk_window_attributes.wclass = GdkWindowClass.GDK_INPUT_OUTPUT; lock (XlibLock) { GdkWholeWindow = gdk_window_new (GdkParentHandle, ref gdk_window_attributes, (int)attributes_mask); if (GdkWholeWindow != IntPtr.Zero) { attributes_mask &= ~GdkWindowAttributesType.GDK_WA_NOREDIR; if (GdkCustomVisual != IntPtr.Zero && GdkCustomColormap != IntPtr.Zero) { attributes_mask |= GdkWindowAttributesType.GDK_WA_COLORMAP | GdkWindowAttributesType.GDK_WA_VISUAL; gdk_window_attributes.colormap = GdkCustomColormap; gdk_window_attributes.visual = GdkCustomVisual; } gdk_window_attributes.x = ClientRect.X; gdk_window_attributes.y = ClientRect.Y; gdk_window_attributes.width = ClientRect.Width; gdk_window_attributes.height = ClientRect.Height; GdkClientWindow = gdk_window_new (GdkWholeWindow, ref gdk_window_attributes, (int)attributes_mask); } } if ((GdkWholeWindow == IntPtr.Zero) || (GdkClientWindow == IntPtr.Zero)) { throw new Exception ("Could not create X11 Gdk windows"); } hwnd.WholeWindow = gdk_x11_drawable_get_xid (GdkWholeWindow); hwnd.ClientWindow = gdk_x11_drawable_get_xid (GdkClientWindow); #if DriverDebug Console.WriteLine("Created window {0:X} / {1:X} parent {2:X}", ClientWindow.ToInt32(), WholeWindow.ToInt32(), hwnd.parent != null ? hwnd.parent.Handle.ToInt32() : 0); #endif lock (XlibLock) { gdk_window_set_events (GdkWholeWindow, (int)GdkSelectInputMask); gdk_window_set_events (GdkClientWindow, (int)GdkSelectInputMask); if ((cp.Style & (int)WindowStyles.WS_VISIBLE) != 0) { gdk_window_show (GdkWholeWindow); gdk_window_show (GdkClientWindow); hwnd.visible = true; } } SetWMStyles (hwnd, cp); if ((cp.Style & (int)WindowStyles.WS_MINIMIZE) != 0) { SetWindowState (hwnd.Handle, FormWindowState.Minimized); } else if ((cp.Style & (int)WindowStyles.WS_MAXIMIZE) != 0) { 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); return hwnd.Handle; }