2 * this file is part of evince, a gnome document viewer
4 * Copyright (C) 2010 Carlos Garcia Campos <carlosgc@gnome.org>
6 * Evince is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Evince is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include <glib/gi18n.h>
25 #include "ev-loading-window.h"
32 struct _EvLoadingWindow {
33 GtkWindow base_instance;
43 struct _EvLoadingWindowClass {
44 GtkWindowClass base_class;
47 G_DEFINE_TYPE (EvLoadingWindow, ev_loading_window, GTK_TYPE_WINDOW)
50 ev_loading_window_set_property (GObject *object,
55 EvLoadingWindow *window = EV_LOADING_WINDOW (object);
59 window->parent = g_value_get_object (value);
62 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
67 ev_loading_window_init (EvLoadingWindow *window)
69 GtkWindow *gtk_window = GTK_WINDOW (window);
70 GtkWidget *widget = GTK_WIDGET (window);
76 const gchar *loading_text = _("Loading…");
77 const gchar *fg_color_name = "info_fg_color";
78 const gchar *bg_color_name = "info_bg_color";
80 hbox = gtk_hbox_new (FALSE, 12);
82 spinner = gtk_spinner_new ();
83 gtk_spinner_start (GTK_SPINNER (spinner));
84 gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
85 gtk_widget_show (spinner);
87 label = gtk_label_new (loading_text);
88 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
89 gtk_widget_show (label);
91 gtk_container_add (GTK_CONTAINER (window), hbox);
92 gtk_widget_show (hbox);
94 gtk_widget_set_app_paintable (widget, TRUE);
96 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
98 gtk_window_set_type_hint (gtk_window, GDK_WINDOW_TYPE_HINT_NOTIFICATION);
99 gtk_window_set_accept_focus (gtk_window, FALSE);
100 gtk_window_set_decorated (gtk_window, FALSE);
101 gtk_window_set_resizable (gtk_window, FALSE);
103 style = gtk_widget_get_style (widget);
104 if (!gtk_style_lookup_color (style, fg_color_name, &fg) ||
105 !gtk_style_lookup_color (style, bg_color_name, &bg)) {
117 if (!gdk_color_equal (&bg, &style->bg[GTK_STATE_NORMAL]))
118 gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &bg);
119 if (!gdk_color_equal (&fg, &style->fg[GTK_STATE_NORMAL]))
120 gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, &fg);
124 ev_loading_window_constructor (GType type,
125 guint n_construct_properties,
126 GObjectConstructParam *construct_params)
129 EvLoadingWindow *window;
130 GtkWindow *gtk_window;
132 object = G_OBJECT_CLASS (ev_loading_window_parent_class)->constructor (type,
133 n_construct_properties,
135 window = EV_LOADING_WINDOW (object);
136 gtk_window = GTK_WINDOW (window);
138 gtk_window_set_transient_for (gtk_window, window->parent);
139 gtk_window_set_destroy_with_parent (gtk_window, TRUE);
145 _cairo_rounded_rectangle (cairo_t *cr,
150 cairo_move_to (cr, radius, 0);
151 cairo_line_to (cr, width - radius, 0);
157 cairo_line_to (cr, width, height - radius);
163 cairo_line_to (cr, radius, height);
168 cairo_line_to (cr, 0, radius);
176 ev_loading_window_size_allocate (GtkWidget *widget,
177 GtkAllocation *allocation)
179 EvLoadingWindow *window = EV_LOADING_WINDOW (widget);
184 GTK_WIDGET_CLASS (ev_loading_window_parent_class)->size_allocate (widget, allocation);
186 if (allocation->width == window->width && allocation->height == window->height)
189 window->width = allocation->width;
190 window->height = allocation->height;
192 mask = gdk_pixmap_new (NULL, window->width, window->height, 1);
193 cr = gdk_cairo_create (GDK_DRAWABLE (mask));
196 cairo_rectangle (cr, 0, 0, window->width, window->height);
197 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
201 cairo_set_source_rgb (cr, 1., 1., 1.);
202 r = MIN (window->width, window->height) / 2.;
203 _cairo_rounded_rectangle (cr, window->width, window->height, r);
208 gtk_widget_shape_combine_mask (widget, mask, 0, 0);
209 g_object_unref (mask);
213 ev_loading_window_hide (GtkWidget *widget)
215 EvLoadingWindow *window = EV_LOADING_WINDOW (widget);
217 window->x = window->y = 0;
219 GTK_WIDGET_CLASS (ev_loading_window_parent_class)->hide (widget);
223 ev_loading_window_class_init (EvLoadingWindowClass *klass)
225 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
226 GtkWidgetClass *gtk_widget_class = GTK_WIDGET_CLASS (klass);
228 g_object_class->constructor = ev_loading_window_constructor;
229 g_object_class->set_property = ev_loading_window_set_property;
231 gtk_widget_class->size_allocate = ev_loading_window_size_allocate;
232 gtk_widget_class->hide = ev_loading_window_hide;
234 g_object_class_install_property (g_object_class,
236 g_param_spec_object ("parent",
241 G_PARAM_CONSTRUCT_ONLY));
246 ev_loading_window_new (GtkWindow *parent)
250 g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
252 window = g_object_new (EV_TYPE_LOADING_WINDOW,
259 ev_loading_window_get_size (EvLoadingWindow *window,
263 if (width) *width = window->width;
264 if (height) *height = window->height;
268 ev_loading_window_move (EvLoadingWindow *window,
272 if (x == window->x && y == window->y)
277 gtk_window_move (GTK_WINDOW (window), x, y);