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;
44 struct _EvLoadingWindowClass {
45 GtkWindowClass base_class;
48 G_DEFINE_TYPE (EvLoadingWindow, ev_loading_window, GTK_TYPE_WINDOW)
51 ev_loading_window_set_property (GObject *object,
56 EvLoadingWindow *window = EV_LOADING_WINDOW (object);
60 window->parent = g_value_get_object (value);
63 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
68 ev_loading_window_init (EvLoadingWindow *window)
70 GtkWindow *gtk_window = GTK_WINDOW (window);
71 GtkWidget *widget = GTK_WIDGET (window);
74 GtkStyleContext *context;
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 window->spinner = gtk_spinner_new ();
83 gtk_box_pack_start (GTK_BOX (hbox), window->spinner, FALSE, FALSE, 0);
84 gtk_widget_show (window->spinner);
86 label = gtk_label_new (loading_text);
87 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
88 gtk_widget_show (label);
90 gtk_container_add (GTK_CONTAINER (window), hbox);
91 gtk_widget_show (hbox);
93 gtk_widget_set_app_paintable (widget, TRUE);
95 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
97 gtk_window_set_type_hint (gtk_window, GDK_WINDOW_TYPE_HINT_NOTIFICATION);
98 gtk_window_set_accept_focus (gtk_window, FALSE);
99 gtk_window_set_decorated (gtk_window, FALSE);
100 gtk_window_set_resizable (gtk_window, FALSE);
102 context = gtk_widget_get_style_context (widget);
103 if (!gtk_style_context_lookup_color (context, fg_color_name, &fg) ||
104 !gtk_style_context_lookup_color (context, bg_color_name, &bg)) {
116 gtk_widget_override_background_color (widget, GTK_STATE_NORMAL, &bg);
117 gtk_widget_override_color (widget, GTK_STATE_NORMAL, &fg);
121 ev_loading_window_constructor (GType type,
122 guint n_construct_properties,
123 GObjectConstructParam *construct_params)
126 EvLoadingWindow *window;
127 GtkWindow *gtk_window;
129 object = G_OBJECT_CLASS (ev_loading_window_parent_class)->constructor (type,
130 n_construct_properties,
132 window = EV_LOADING_WINDOW (object);
133 gtk_window = GTK_WINDOW (window);
135 gtk_window_set_transient_for (gtk_window, window->parent);
136 gtk_window_set_destroy_with_parent (gtk_window, TRUE);
142 _cairo_rounded_rectangle (cairo_t *cr,
147 cairo_move_to (cr, radius, 0);
148 cairo_line_to (cr, width - radius, 0);
154 cairo_line_to (cr, width, height - radius);
160 cairo_line_to (cr, radius, height);
165 cairo_line_to (cr, 0, radius);
173 ev_loading_window_size_allocate (GtkWidget *widget,
174 GtkAllocation *allocation)
176 EvLoadingWindow *window = EV_LOADING_WINDOW (widget);
177 cairo_surface_t *surface;
178 cairo_region_t *shape;
182 GTK_WIDGET_CLASS (ev_loading_window_parent_class)->size_allocate (widget, allocation);
184 if (allocation->width == window->width && allocation->height == window->height)
187 window->width = allocation->width;
188 window->height = allocation->height;
190 surface = cairo_image_surface_create (CAIRO_FORMAT_A8,
193 cr = cairo_create (surface);
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 shape = gdk_cairo_region_create_from_surface (surface);
209 cairo_surface_destroy (surface);
211 gtk_widget_shape_combine_region (widget, shape);
212 cairo_region_destroy (shape);
216 ev_loading_window_hide (GtkWidget *widget)
218 EvLoadingWindow *window = EV_LOADING_WINDOW (widget);
220 window->x = window->y = 0;
222 gtk_spinner_stop (GTK_SPINNER (window->spinner));
224 GTK_WIDGET_CLASS (ev_loading_window_parent_class)->hide (widget);
228 ev_loading_window_show (GtkWidget *widget)
230 EvLoadingWindow *window = EV_LOADING_WINDOW (widget);
232 gtk_spinner_start (GTK_SPINNER (window->spinner));
234 GTK_WIDGET_CLASS (ev_loading_window_parent_class)->show (widget);
238 ev_loading_window_class_init (EvLoadingWindowClass *klass)
240 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
241 GtkWidgetClass *gtk_widget_class = GTK_WIDGET_CLASS (klass);
243 g_object_class->constructor = ev_loading_window_constructor;
244 g_object_class->set_property = ev_loading_window_set_property;
246 gtk_widget_class->size_allocate = ev_loading_window_size_allocate;
247 gtk_widget_class->show = ev_loading_window_show;
248 gtk_widget_class->hide = ev_loading_window_hide;
250 g_object_class_install_property (g_object_class,
252 g_param_spec_object ("parent",
257 G_PARAM_CONSTRUCT_ONLY));
262 ev_loading_window_new (GtkWindow *parent)
266 g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
268 window = g_object_new (EV_TYPE_LOADING_WINDOW,
269 "type", GTK_WINDOW_POPUP,
276 ev_loading_window_get_size (EvLoadingWindow *window,
280 if (width) *width = window->width;
281 if (height) *height = window->height;
285 ev_loading_window_move (EvLoadingWindow *window,
289 if (x == window->x && y == window->y)
294 gtk_window_move (GTK_WINDOW (window), x, y);