Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-loading-message.c
Go to the documentation of this file.
1 /* ev-loading-message.c
2  * this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2010, 2012 Carlos Garcia Campos <carlosgc@gnome.org>
5  *
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.
10  *
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.
15  *
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.
19  */
20 
21 #include "config.h"
22 #include "ev-loading-message.h"
23 
24 #include <string.h>
25 #include <glib/gi18n.h>
26 
28  GtkBox base_instance;
29 
30  GtkWidget *spinner;
31 };
32 
34  GtkBoxClass base_class;
35 };
36 
37 G_DEFINE_TYPE (EvLoadingMessage, ev_loading_message, GTK_TYPE_BOX)
38 
39 static void
41 {
42  GtkWidget *label;
43 
44  gtk_container_set_border_width (GTK_CONTAINER (message), 10);
45 
46  message->spinner = gtk_spinner_new ();
47  gtk_box_pack_start (GTK_BOX (message), message->spinner, FALSE, FALSE, 0);
48  gtk_widget_show (message->spinner);
49 
50  label = gtk_label_new (_("Loading…"));
51  gtk_box_pack_start (GTK_BOX (message), label, FALSE, FALSE, 0);
52  gtk_widget_show (label);
53 }
54 
55 static void
56 get_widget_padding (GtkWidget *widget,
57  GtkBorder *padding)
58 {
59  GtkStyleContext *context;
60  GtkStateFlags state;
61 
62  context = gtk_widget_get_style_context (widget);
63  state = gtk_style_context_get_state (context);
64  gtk_style_context_get_padding (context, state, padding);
65 }
66 
67 static void
69  GtkAllocation *allocation)
70 {
71  GtkAllocation child_allocation;
72  GtkBorder padding;
73 
74  get_widget_padding (widget, &padding);
75  child_allocation.y = allocation->x + padding.left;
76  child_allocation.x = allocation->y + padding.top;
77  child_allocation.width = MAX (1, allocation->width - (padding.left + padding.right));
78  child_allocation.height = MAX (1, allocation->height - (padding.top + padding.bottom));
79 
80  GTK_WIDGET_CLASS (ev_loading_message_parent_class)->size_allocate (widget, &child_allocation);
81  gtk_widget_set_allocation (widget, allocation);
82 }
83 
84 static void
86  gint *minimum_size,
87  gint *natural_size)
88 {
89  GtkBorder padding;
90 
91  GTK_WIDGET_CLASS (ev_loading_message_parent_class)->get_preferred_width (widget, minimum_size, natural_size);
92 
93  get_widget_padding (widget, &padding);
94  *minimum_size += padding.left + padding.right;
95  *natural_size += padding.left + padding.right;
96 }
97 
98 static void
100  gint *minimum_size,
101  gint *natural_size)
102 {
103  GtkBorder padding;
104 
105  GTK_WIDGET_CLASS (ev_loading_message_parent_class)->get_preferred_height (widget, minimum_size, natural_size);
106 
107  get_widget_padding (widget, &padding);
108  *minimum_size += padding.top + padding.bottom;
109  *natural_size += padding.top + padding.bottom;
110 }
111 
112 static gboolean
113 ev_loading_message_draw (GtkWidget *widget,
114  cairo_t *cr)
115 {
116  GtkStyleContext *context;
117  gint width, height;
118 
119  context = gtk_widget_get_style_context (widget);
120  width = gtk_widget_get_allocated_width (widget);
121  height = gtk_widget_get_allocated_height (widget);
122 
123  gtk_render_background (context, cr, 0, 0, width, height);
124  gtk_render_frame (context, cr, 0, 0, width, height);
125 
126  GTK_WIDGET_CLASS (ev_loading_message_parent_class)->draw (widget, cr);
127 
128  return TRUE;
129 }
130 
131 static void
132 ev_loading_message_hide (GtkWidget *widget)
133 {
134  EvLoadingMessage *message = EV_LOADING_MESSAGE (widget);
135 
136  gtk_spinner_stop (GTK_SPINNER (message->spinner));
137 
138  GTK_WIDGET_CLASS (ev_loading_message_parent_class)->hide (widget);
139 }
140 
141 static void
142 ev_loading_message_show (GtkWidget *widget)
143 {
144  EvLoadingMessage *message = EV_LOADING_MESSAGE (widget);
145 
146  gtk_spinner_start (GTK_SPINNER (message->spinner));
147 
148  GTK_WIDGET_CLASS (ev_loading_message_parent_class)->show (widget);
149 }
150 
151 static void
153 {
154  GtkWidgetClass *gtk_widget_class = GTK_WIDGET_CLASS (klass);
155 
156  gtk_widget_class->size_allocate = ev_loading_message_size_allocate;
157  gtk_widget_class->get_preferred_width = ev_loading_message_get_preferred_width;
158  gtk_widget_class->get_preferred_height = ev_loading_message_get_preferred_height;
159  gtk_widget_class->draw = ev_loading_message_draw;
160  gtk_widget_class->show = ev_loading_message_show;
161  gtk_widget_class->hide = ev_loading_message_hide;
162 }
163 
164 /* Public methods */
165 GtkWidget *
167 {
168  GtkWidget *message;
169 
170  message = g_object_new (EV_TYPE_LOADING_MESSAGE,
171  "orientation", GTK_ORIENTATION_HORIZONTAL,
172  "spacing", 12,
173  NULL);
174  return message;
175 }
176