1 #include "gtkoffscreenwindow.h"
4 G_DEFINE_TYPE (GtkOffscreenWindow, gtk_offscreen_window, GTK_TYPE_WINDOW);
7 gtk_offscreen_window_size_request (GtkWidget *widget,
8 GtkRequisition *requisition)
10 GtkBin *bin = GTK_BIN (widget);
12 gint default_width, default_height;
14 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
16 requisition->width = border_width * 2;
17 requisition->height = border_width * 2;
19 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
21 GtkRequisition child_req;
23 gtk_widget_size_request (bin->child, &child_req);
25 requisition->width += child_req.width;
26 requisition->height += child_req.height;
29 gtk_window_get_default_size (GTK_WINDOW (widget),
30 &default_width, &default_height);
31 if (default_width > 0)
32 requisition->width = default_width;
34 if (default_height > 0)
35 requisition->height = default_height;
39 gtk_offscreen_window_size_allocate (GtkWidget *widget,
40 GtkAllocation *allocation)
42 GtkBin *bin = GTK_BIN (widget);
45 widget->allocation = *allocation;
47 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
49 if (GTK_WIDGET_REALIZED (widget))
50 gdk_window_move_resize (widget->window,
56 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
58 GtkAllocation child_alloc;
60 child_alloc.x = border_width;
61 child_alloc.y = border_width;
62 child_alloc.width = allocation->width - 2 * border_width;
63 child_alloc.height = allocation->height - 2 * border_width;
65 gtk_widget_size_allocate (bin->child, &child_alloc);
68 gtk_widget_queue_draw (widget);
72 gtk_offscreen_window_realize (GtkWidget *widget)
75 GdkWindowAttr attributes;
79 bin = GTK_BIN (widget);
81 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
83 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
85 attributes.x = widget->allocation.x;
86 attributes.y = widget->allocation.y;
87 attributes.width = widget->allocation.width;
88 attributes.height = widget->allocation.height;
89 attributes.window_type = GDK_WINDOW_OFFSCREEN;
90 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
91 attributes.visual = gtk_widget_get_visual (widget);
92 attributes.colormap = gtk_widget_get_colormap (widget);
93 attributes.wclass = GDK_INPUT_OUTPUT;
95 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
97 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
98 &attributes, attributes_mask);
99 gdk_window_set_user_data (widget->window, widget);
102 gtk_widget_set_parent_window (bin->child, widget->window);
104 widget->style = gtk_style_attach (widget->style, widget->window);
106 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
110 gtk_offscreen_window_resize (GtkWidget *widget)
112 GtkAllocation allocation = { 0, 0 };
113 GtkRequisition requisition;
115 gtk_widget_size_request (widget, &requisition);
117 allocation.width = requisition.width;
118 allocation.height = requisition.height;
119 gtk_widget_size_allocate (widget, &allocation);
123 move_focus (GtkWidget *widget,
124 GtkDirectionType dir)
126 gtk_widget_child_focus (widget, dir);
128 if (!GTK_CONTAINER (widget)->focus_child)
129 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
133 gtk_offscreen_window_show (GtkWidget *widget)
135 gboolean need_resize;
136 GtkContainer *container;
138 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
140 container = GTK_CONTAINER (widget);
141 need_resize = container->need_resize || !GTK_WIDGET_REALIZED (widget);
142 container->need_resize = FALSE;
145 gtk_offscreen_window_resize (widget);
147 gtk_widget_map (widget);
149 /* Try to make sure that we have some focused widget */
150 if (!gtk_window_get_focus (GTK_WINDOW (widget)))
151 move_focus (widget, GTK_DIR_TAB_FORWARD);
155 gtk_offscreen_window_hide (GtkWidget *widget)
157 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
158 gtk_widget_unmap (widget);
162 gtk_offscreen_window_check_resize (GtkContainer *container)
164 GtkWidget *widget = GTK_WIDGET (container);
166 if (GTK_WIDGET_VISIBLE (widget))
167 gtk_offscreen_window_resize (widget);
171 gtk_offscreen_window_class_init (GtkOffscreenWindowClass *class)
173 GtkWidgetClass *widget_class;
174 GtkContainerClass *container_class;
176 widget_class = GTK_WIDGET_CLASS (class);
177 container_class = GTK_CONTAINER_CLASS (class);
179 widget_class->realize = gtk_offscreen_window_realize;
180 widget_class->show = gtk_offscreen_window_show;
181 widget_class->hide = gtk_offscreen_window_hide;
182 widget_class->size_request = gtk_offscreen_window_size_request;
183 widget_class->size_allocate = gtk_offscreen_window_size_allocate;
185 container_class->check_resize = gtk_offscreen_window_check_resize;
189 gtk_offscreen_window_init (GtkOffscreenWindow *bin)
194 gtk_offscreen_window_new (void)
196 return g_object_new (gtk_offscreen_window_get_type (), NULL);
200 #define __GTK_OFFSCREEN_WINDOW_C__
201 #include "gtkaliasdef.c"