2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the
14 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
15 * Boston, MA 02111-1307, USA.
17 * Authors: Cody Russell <crussell@canonical.com>
18 * Alexander Larsson <alexl@redhat.com>
21 #include "gtkoffscreenwindow.h"
24 G_DEFINE_TYPE (GtkOffscreenWindow, gtk_offscreen_window, GTK_TYPE_WINDOW);
27 gtk_offscreen_window_size_request (GtkWidget *widget,
28 GtkRequisition *requisition)
30 GtkBin *bin = GTK_BIN (widget);
32 gint default_width, default_height;
34 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
36 requisition->width = border_width * 2;
37 requisition->height = border_width * 2;
39 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
41 GtkRequisition child_req;
43 gtk_widget_size_request (bin->child, &child_req);
45 requisition->width += child_req.width;
46 requisition->height += child_req.height;
49 gtk_window_get_default_size (GTK_WINDOW (widget),
50 &default_width, &default_height);
51 if (default_width > 0)
52 requisition->width = default_width;
54 if (default_height > 0)
55 requisition->height = default_height;
59 gtk_offscreen_window_size_allocate (GtkWidget *widget,
60 GtkAllocation *allocation)
62 GtkBin *bin = GTK_BIN (widget);
65 widget->allocation = *allocation;
67 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
69 if (GTK_WIDGET_REALIZED (widget))
70 gdk_window_move_resize (widget->window,
76 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
78 GtkAllocation child_alloc;
80 child_alloc.x = border_width;
81 child_alloc.y = border_width;
82 child_alloc.width = allocation->width - 2 * border_width;
83 child_alloc.height = allocation->height - 2 * border_width;
85 gtk_widget_size_allocate (bin->child, &child_alloc);
88 gtk_widget_queue_draw (widget);
92 gtk_offscreen_window_realize (GtkWidget *widget)
95 GdkWindowAttr attributes;
99 bin = GTK_BIN (widget);
101 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
103 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
105 attributes.x = widget->allocation.x;
106 attributes.y = widget->allocation.y;
107 attributes.width = widget->allocation.width;
108 attributes.height = widget->allocation.height;
109 attributes.window_type = GDK_WINDOW_OFFSCREEN;
110 attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
111 attributes.visual = gtk_widget_get_visual (widget);
112 attributes.colormap = gtk_widget_get_colormap (widget);
113 attributes.wclass = GDK_INPUT_OUTPUT;
115 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
117 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
118 &attributes, attributes_mask);
119 gdk_window_set_user_data (widget->window, widget);
122 gtk_widget_set_parent_window (bin->child, widget->window);
124 widget->style = gtk_style_attach (widget->style, widget->window);
126 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
130 gtk_offscreen_window_resize (GtkWidget *widget)
132 GtkAllocation allocation = { 0, 0 };
133 GtkRequisition requisition;
135 gtk_widget_size_request (widget, &requisition);
137 allocation.width = requisition.width;
138 allocation.height = requisition.height;
139 gtk_widget_size_allocate (widget, &allocation);
143 move_focus (GtkWidget *widget,
144 GtkDirectionType dir)
146 gtk_widget_child_focus (widget, dir);
148 if (!GTK_CONTAINER (widget)->focus_child)
149 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
153 gtk_offscreen_window_show (GtkWidget *widget)
155 gboolean need_resize;
156 GtkContainer *container;
158 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
160 container = GTK_CONTAINER (widget);
161 need_resize = container->need_resize || !GTK_WIDGET_REALIZED (widget);
162 container->need_resize = FALSE;
165 gtk_offscreen_window_resize (widget);
167 gtk_widget_map (widget);
169 /* Try to make sure that we have some focused widget */
170 if (!gtk_window_get_focus (GTK_WINDOW (widget)))
171 move_focus (widget, GTK_DIR_TAB_FORWARD);
175 gtk_offscreen_window_hide (GtkWidget *widget)
177 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
178 gtk_widget_unmap (widget);
182 gtk_offscreen_window_check_resize (GtkContainer *container)
184 GtkWidget *widget = GTK_WIDGET (container);
186 if (GTK_WIDGET_VISIBLE (widget))
187 gtk_offscreen_window_resize (widget);
191 gtk_offscreen_window_class_init (GtkOffscreenWindowClass *class)
193 GtkWidgetClass *widget_class;
194 GtkContainerClass *container_class;
196 widget_class = GTK_WIDGET_CLASS (class);
197 container_class = GTK_CONTAINER_CLASS (class);
199 widget_class->realize = gtk_offscreen_window_realize;
200 widget_class->show = gtk_offscreen_window_show;
201 widget_class->hide = gtk_offscreen_window_hide;
202 widget_class->size_request = gtk_offscreen_window_size_request;
203 widget_class->size_allocate = gtk_offscreen_window_size_allocate;
205 container_class->check_resize = gtk_offscreen_window_check_resize;
209 gtk_offscreen_window_init (GtkOffscreenWindow *window)
214 gtk_offscreen_window_new (void)
216 return g_object_new (gtk_offscreen_window_get_type (), NULL);
220 #define __GTK_OFFSCREEN_WINDOW_C__
221 #include "gtkaliasdef.c"