15032
|
1 /*
|
15058
|
2 * @file gtkscrollbook.c GTK+ Scrolling notebook widget
|
15032
|
3 * @ingroup gtkui
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25
|
|
26 #include "gtkscrollbook.h"
|
|
27
|
|
28
|
|
29 static void gtk_gaim_scroll_book_init (GtkGaimScrollBook *scroll_book);
|
|
30 static void gtk_gaim_scroll_book_class_init (GtkGaimScrollBookClass *klass);
|
15178
|
31 static void gtk_gaim_scroll_book_forall (GtkContainer *c,
|
|
32 gboolean include_internals,
|
|
33 GtkCallback callback,
|
|
34 gpointer user_data);
|
15032
|
35
|
|
36 GType
|
|
37 gtk_gaim_scroll_book_get_type (void)
|
|
38 {
|
|
39 static GType scroll_book_type = 0;
|
|
40
|
|
41 if (!scroll_book_type)
|
|
42 {
|
|
43 static const GTypeInfo scroll_book_info =
|
|
44 {
|
|
45 sizeof (GtkGaimScrollBookClass),
|
|
46 NULL, /* base_init */
|
|
47 NULL, /* base_finalize */
|
|
48 (GClassInitFunc) gtk_gaim_scroll_book_class_init,
|
|
49 NULL, /* class_finalize */
|
|
50 NULL, /* class_data */
|
|
51 sizeof (GtkGaimScrollBook),
|
|
52 0,
|
|
53 (GInstanceInitFunc) gtk_gaim_scroll_book_init,
|
|
54 NULL /* value_table */
|
|
55 };
|
|
56
|
|
57 scroll_book_type = g_type_register_static(GTK_TYPE_VBOX,
|
|
58 "GtkGaimScrollBook",
|
|
59 &scroll_book_info,
|
|
60 0);
|
|
61 }
|
|
62
|
|
63 return scroll_book_type;
|
|
64 }
|
|
65
|
|
66 static void
|
|
67 scroll_left_cb(GtkGaimScrollBook *scroll_book)
|
|
68 {
|
|
69 int index;
|
|
70 index = gtk_notebook_get_current_page(GTK_NOTEBOOK(scroll_book->notebook));
|
|
71
|
|
72 if (index > 0)
|
|
73 gtk_notebook_set_current_page(GTK_NOTEBOOK(scroll_book->notebook), index - 1);
|
|
74 }
|
|
75
|
|
76 static void
|
|
77 scroll_right_cb(GtkGaimScrollBook *scroll_book)
|
|
78 {
|
|
79 int index, count;
|
|
80 index = gtk_notebook_get_current_page(GTK_NOTEBOOK(scroll_book->notebook));
|
|
81 #if GTK_CHECK_VERSION(2,2,0)
|
|
82 count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook));
|
|
83 #else
|
|
84 count = g_list_length(GTK_NOTEBOOK(scroll_book->notebook)->children);
|
|
85 #endif
|
|
86
|
|
87 if (index + 1 < count)
|
|
88 gtk_notebook_set_current_page(GTK_NOTEBOOK(scroll_book->notebook), index + 1);
|
|
89 }
|
|
90
|
|
91 static void
|
|
92 refresh_scroll_box(GtkGaimScrollBook *scroll_book, int index, int count)
|
|
93 {
|
|
94 char *label;
|
15052
|
95 gtk_widget_show_all(GTK_WIDGET(scroll_book));
|
15032
|
96 if (count <= 1)
|
|
97 gtk_widget_hide(GTK_WIDGET(scroll_book->hbox));
|
|
98 else
|
|
99 gtk_widget_show_all(GTK_WIDGET(scroll_book->hbox));
|
|
100
|
|
101
|
|
102 label = g_strdup_printf("<span size='smaller' weight='bold'>(%d/%d)</span>", index+1, count);
|
|
103 gtk_label_set_markup(GTK_LABEL(scroll_book->label), label);
|
|
104 g_free(label);
|
|
105
|
|
106 if (index == 0)
|
|
107 gtk_widget_set_sensitive(scroll_book->left_arrow, FALSE);
|
|
108 else
|
|
109 gtk_widget_set_sensitive(scroll_book->left_arrow, TRUE);
|
|
110
|
|
111
|
|
112 if (index +1== count)
|
|
113 gtk_widget_set_sensitive(scroll_book->right_arrow, FALSE);
|
|
114 else
|
|
115 gtk_widget_set_sensitive(scroll_book->right_arrow, TRUE);
|
|
116 }
|
|
117
|
|
118
|
|
119 static void
|
15057
|
120 page_count_change_cb(GtkGaimScrollBook *scroll_book)
|
15032
|
121 {
|
15181
|
122 int count;
|
15032
|
123 int index = gtk_notebook_get_current_page(GTK_NOTEBOOK(scroll_book->notebook));
|
|
124 #if GTK_CHECK_VERSION(2,2,0)
|
15181
|
125 count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook));
|
15032
|
126 #else
|
|
127 count = g_list_length(GTK_NOTEBOOK(scroll_book->notebook)->children);
|
|
128 #endif
|
|
129 refresh_scroll_box(scroll_book, index, count);
|
|
130
|
|
131 }
|
|
132
|
|
133 static void
|
|
134 switch_page_cb(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, GtkGaimScrollBook *scroll_book)
|
|
135 {
|
|
136 #if GTK_CHECK_VERSION(2,2,0)
|
|
137 int count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook));
|
|
138 #else
|
|
139 count = g_list_length(GTK_NOTEBOOK(scroll_book->notebook)->children);
|
|
140 #endif
|
|
141 refresh_scroll_box(scroll_book, page_num, count);
|
|
142 }
|
|
143
|
|
144 static void
|
|
145 gtk_gaim_scroll_book_add(GtkContainer *container, GtkWidget *widget)
|
|
146 {
|
|
147 gtk_widget_show(widget);
|
|
148 gtk_notebook_append_page(GTK_NOTEBOOK(GTK_GAIM_SCROLL_BOOK(container)->notebook), widget, NULL);
|
15181
|
149 page_count_change_cb(GTK_GAIM_SCROLL_BOOK(container));
|
15032
|
150 }
|
|
151
|
|
152 static void
|
15178
|
153 gtk_gaim_scroll_book_forall(GtkContainer *container,
|
|
154 gboolean include_internals,
|
|
155 GtkCallback callback,
|
|
156 gpointer callback_data)
|
|
157 {
|
|
158 GtkGaimScrollBook *scroll_book = GTK_GAIM_SCROLL_BOOK(container);
|
15181
|
159 if (include_internals)
|
15178
|
160 (*callback)(scroll_book->hbox, callback_data);
|
|
161 (*callback)(scroll_book->notebook, callback_data);
|
|
162 }
|
|
163
|
|
164 static void
|
15032
|
165 gtk_gaim_scroll_book_class_init (GtkGaimScrollBookClass *klass)
|
|
166 {
|
|
167 GtkContainerClass *container_class = (GtkContainerClass*)klass;
|
|
168
|
|
169 container_class->add = gtk_gaim_scroll_book_add;
|
15178
|
170 container_class->forall = gtk_gaim_scroll_book_forall;
|
15032
|
171
|
|
172 }
|
|
173
|
|
174 static void
|
|
175 gtk_gaim_scroll_book_init (GtkGaimScrollBook *scroll_book)
|
|
176 {
|
|
177 GtkWidget *eb;
|
|
178
|
|
179 scroll_book->hbox = gtk_hbox_new(FALSE, 0);
|
|
180
|
|
181 eb = gtk_event_box_new();
|
|
182 gtk_box_pack_end(GTK_BOX(scroll_book->hbox), eb, FALSE, FALSE, 0);
|
|
183 scroll_book->right_arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
|
|
184 gtk_container_add(GTK_CONTAINER(eb), scroll_book->right_arrow);
|
|
185 g_signal_connect_swapped(G_OBJECT(eb), "button-press-event", G_CALLBACK(scroll_right_cb), scroll_book);
|
|
186
|
|
187 scroll_book->label = gtk_label_new(NULL);
|
|
188 gtk_box_pack_end(GTK_BOX(scroll_book->hbox), scroll_book->label, FALSE, FALSE, 0);
|
|
189
|
|
190 eb = gtk_event_box_new();
|
|
191 gtk_box_pack_end(GTK_BOX(scroll_book->hbox), eb, FALSE, FALSE, 0);
|
|
192 scroll_book->left_arrow = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_NONE);
|
|
193 gtk_container_add(GTK_CONTAINER(eb), scroll_book->left_arrow);
|
|
194 g_signal_connect_swapped(G_OBJECT(eb), "button-press-event", G_CALLBACK(scroll_left_cb), scroll_book);
|
|
195
|
|
196 gtk_box_pack_start(GTK_BOX(scroll_book), scroll_book->hbox, FALSE, FALSE, 0);
|
|
197
|
|
198 scroll_book->notebook = gtk_notebook_new();
|
|
199 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(scroll_book->notebook), FALSE);
|
|
200 gtk_notebook_set_show_border(GTK_NOTEBOOK(scroll_book->notebook), FALSE);
|
|
201
|
|
202 gtk_box_pack_start(GTK_BOX(scroll_book), scroll_book->notebook, TRUE, TRUE, 0);
|
|
203
|
15128
|
204 g_signal_connect_swapped(G_OBJECT(scroll_book->notebook), "remove", G_CALLBACK(page_count_change_cb), scroll_book);
|
15032
|
205 g_signal_connect(G_OBJECT(scroll_book->notebook), "switch-page", G_CALLBACK(switch_page_cb), scroll_book);
|
15181
|
206 gtk_widget_show_all(scroll_book->hbox);
|
|
207 gtk_widget_show_all(scroll_book->notebook);
|
15032
|
208 }
|
|
209
|
|
210
|
|
211
|
|
212 GtkWidget *
|
|
213 gtk_gaim_scroll_book_new()
|
|
214 {
|
|
215 return g_object_new(GTK_GAIM_TYPE_SCROLL_BOOK, NULL);
|
|
216 }
|