1 #include "gtkoffscreenwindow.h"
3 G_DEFINE_TYPE (GtkOffscreenWindow, gtk_offscreen_window, GTK_TYPE_WINDOW);
6 gtk_offscreen_window_size_request (GtkWidget *widget,
7 GtkRequisition *requisition)
9 GtkBin *bin = GTK_BIN (widget);
11 gint default_width, default_height;
13 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
15 requisition->width = border_width * 2;
16 requisition->height = border_width * 2;
18 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
20 GtkRequisition child_req;
22 gtk_widget_size_request (bin->child, &child_req);
24 requisition->width += child_req.width;
25 requisition->height += child_req.height;
28 gtk_window_get_default_size (GTK_WINDOW (widget),
29 &default_width, &default_height);
30 if (default_width > 0)
31 requisition->width = default_width;
33 if (default_height > 0)
34 requisition->height = default_height;
38 gtk_offscreen_window_size_allocate (GtkWidget *widget,
39 GtkAllocation *allocation)
41 GtkBin *bin = GTK_BIN (widget);
44 widget->allocation = *allocation;
46 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
48 if (GTK_WIDGET_REALIZED (widget))
49 gdk_window_move_resize (widget->window,
55 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
57 GtkAllocation child_alloc;
59 child_alloc.x = border_width;
60 child_alloc.y = border_width;
61 child_alloc.width = allocation->width - 2 * border_width;
62 child_alloc.height = allocation->height - 2 * border_width;
64 gtk_widget_size_allocate (bin->child, &child_alloc);
67 gtk_widget_queue_draw (widget);
71 gtk_offscreen_window_realize (GtkWidget *widget)
74 GdkWindowAttr attributes;
78 bin = GTK_BIN (widget);
80 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
82 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
84 attributes.x = widget->allocation.x;
85 attributes.y = widget->allocation.y;
86 attributes.width = widget->allocation.width;
87 attributes.height = widget->allocation.height;
88 attributes.window_type = GDK_WINDOW_OFFSCREEN;
89 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
90 attributes.visual = gtk_widget_get_visual (widget);
91 attributes.colormap = gtk_widget_get_colormap (widget);
92 attributes.wclass = GDK_INPUT_OUTPUT;
94 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
96 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
97 &attributes, attributes_mask);
98 gdk_window_set_user_data (widget->window, widget);
101 gtk_widget_set_parent_window (bin->child, widget->window);
103 widget->style = gtk_style_attach (widget->style, widget->window);
105 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
109 gtk_offscreen_window_resize (GtkWidget *widget)
111 GtkAllocation allocation = { 0, 0 };
112 GtkRequisition requisition;
114 gtk_widget_size_request (widget, &requisition);
116 allocation.width = requisition.width;
117 allocation.height = requisition.height;
118 gtk_widget_size_allocate (widget, &allocation);
122 move_focus (GtkWidget *widget,
123 GtkDirectionType dir)
125 gtk_widget_child_focus (widget, dir);
127 if (!GTK_CONTAINER (widget)->focus_child)
128 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
132 gtk_offscreen_window_show (GtkWidget *widget)
134 gboolean need_resize;
135 GtkContainer *container;
137 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
139 container = GTK_CONTAINER (widget);
140 need_resize = container->need_resize || !GTK_WIDGET_REALIZED (widget);
141 container->need_resize = FALSE;
144 gtk_offscreen_window_resize (widget);
146 gtk_widget_map (widget);
148 /* Try to make sure that we have some focused widget */
149 if (!gtk_window_get_focus (GTK_WINDOW (widget)))
150 move_focus (widget, GTK_DIR_TAB_FORWARD);
154 gtk_offscreen_window_hide (GtkWidget *widget)
156 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
157 gtk_widget_unmap (widget);
161 gtk_offscreen_window_check_resize (GtkContainer *container)
163 GtkWidget *widget = GTK_WIDGET (container);
165 if (GTK_WIDGET_VISIBLE (widget))
166 gtk_offscreen_window_resize (widget);
170 gtk_offscreen_window_class_init (GtkOffscreenWindowClass *class)
172 GtkWidgetClass *widget_class;
173 GtkContainerClass *container_class;
175 widget_class = GTK_WIDGET_CLASS (class);
176 container_class = GTK_CONTAINER_CLASS (class);
178 widget_class->realize = gtk_offscreen_window_realize;
179 widget_class->show = gtk_offscreen_window_show;
180 widget_class->hide = gtk_offscreen_window_hide;
181 widget_class->size_request = gtk_offscreen_window_size_request;
182 widget_class->size_allocate = gtk_offscreen_window_size_allocate;
184 container_class->check_resize = gtk_offscreen_window_check_resize;
188 gtk_offscreen_window_init (GtkOffscreenWindow *bin)
193 gtk_offscreen_window_new (void)
195 return g_object_new (gtk_offscreen_window_get_type (), NULL);
199 #define __GTK_OFFSCREEN_WINDOW_C__
200 #include "gtkaliasdef.c"