15033
|
1 /*
|
15059
|
2 * @file gtkscrollbook.c GTK+ Scrolling notebook widget
|
15033
|
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);
|
15179
|
31 static void gtk_gaim_scroll_book_forall (GtkContainer *c,
|
|
32 gboolean include_internals,
|
|
33 GtkCallback callback,
|
|
34 gpointer user_data);
|
15033
|
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;
|
15053
|
95 gtk_widget_show_all(GTK_WIDGET(scroll_book));
|
15033
|
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
|
15058
|
120 page_count_change_cb(GtkGaimScrollBook *scroll_book)
|
15033
|
121 {
|
15182
|
122 int count;
|
15033
|
123 int index = gtk_notebook_get_current_page(GTK_NOTEBOOK(scroll_book->notebook));
|
|
124 #if GTK_CHECK_VERSION(2,2,0)
|
15182
|
125 count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook));
|
15033
|
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 {
|
15259
|
136 int count;
|
15033
|
137 #if GTK_CHECK_VERSION(2,2,0)
|
15259
|
138 count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook));
|
15033
|
139 #else
|
|
140 count = g_list_length(GTK_NOTEBOOK(scroll_book->notebook)->children);
|
|
141 #endif
|
|
142 refresh_scroll_box(scroll_book, page_num, count);
|
|
143 }
|
|
144
|
|
145 static void
|
|
146 gtk_gaim_scroll_book_add(GtkContainer *container, GtkWidget *widget)
|
|
147 {
|
|
148 gtk_widget_show(widget);
|
|
149 gtk_notebook_append_page(GTK_NOTEBOOK(GTK_GAIM_SCROLL_BOOK(container)->notebook), widget, NULL);
|
15182
|
150 page_count_change_cb(GTK_GAIM_SCROLL_BOOK(container));
|
15033
|
151 }
|
|
152
|
|
153 static void
|
15179
|
154 gtk_gaim_scroll_book_forall(GtkContainer *container,
|
|
155 gboolean include_internals,
|
|
156 GtkCallback callback,
|
|
157 gpointer callback_data)
|
|
158 {
|
|
159 GtkGaimScrollBook *scroll_book = GTK_GAIM_SCROLL_BOOK(container);
|
15182
|
160 if (include_internals)
|
15179
|
161 (*callback)(scroll_book->hbox, callback_data);
|
|
162 (*callback)(scroll_book->notebook, callback_data);
|
|
163 }
|
|
164
|
|
165 static void
|
15033
|
166 gtk_gaim_scroll_book_class_init (GtkGaimScrollBookClass *klass)
|
|
167 {
|
|
168 GtkContainerClass *container_class = (GtkContainerClass*)klass;
|
|
169
|
|
170 container_class->add = gtk_gaim_scroll_book_add;
|
15179
|
171 container_class->forall = gtk_gaim_scroll_book_forall;
|
15033
|
172
|
|
173 }
|
|
174
|
|
175 static void
|
|
176 gtk_gaim_scroll_book_init (GtkGaimScrollBook *scroll_book)
|
|
177 {
|
|
178 GtkWidget *eb;
|
|
179
|
|
180 scroll_book->hbox = gtk_hbox_new(FALSE, 0);
|
|
181
|
|
182 eb = gtk_event_box_new();
|
|
183 gtk_box_pack_end(GTK_BOX(scroll_book->hbox), eb, FALSE, FALSE, 0);
|
|
184 scroll_book->right_arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
|
|
185 gtk_container_add(GTK_CONTAINER(eb), scroll_book->right_arrow);
|
|
186 g_signal_connect_swapped(G_OBJECT(eb), "button-press-event", G_CALLBACK(scroll_right_cb), scroll_book);
|
|
187
|
|
188 scroll_book->label = gtk_label_new(NULL);
|
|
189 gtk_box_pack_end(GTK_BOX(scroll_book->hbox), scroll_book->label, FALSE, FALSE, 0);
|
|
190
|
|
191 eb = gtk_event_box_new();
|
|
192 gtk_box_pack_end(GTK_BOX(scroll_book->hbox), eb, FALSE, FALSE, 0);
|
|
193 scroll_book->left_arrow = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_NONE);
|
|
194 gtk_container_add(GTK_CONTAINER(eb), scroll_book->left_arrow);
|
|
195 g_signal_connect_swapped(G_OBJECT(eb), "button-press-event", G_CALLBACK(scroll_left_cb), scroll_book);
|
|
196
|
|
197 gtk_box_pack_start(GTK_BOX(scroll_book), scroll_book->hbox, FALSE, FALSE, 0);
|
|
198
|
|
199 scroll_book->notebook = gtk_notebook_new();
|
|
200 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(scroll_book->notebook), FALSE);
|
|
201 gtk_notebook_set_show_border(GTK_NOTEBOOK(scroll_book->notebook), FALSE);
|
|
202
|
|
203 gtk_box_pack_start(GTK_BOX(scroll_book), scroll_book->notebook, TRUE, TRUE, 0);
|
|
204
|
15129
|
205 g_signal_connect_swapped(G_OBJECT(scroll_book->notebook), "remove", G_CALLBACK(page_count_change_cb), scroll_book);
|
15033
|
206 g_signal_connect(G_OBJECT(scroll_book->notebook), "switch-page", G_CALLBACK(switch_page_cb), scroll_book);
|
15182
|
207 gtk_widget_show_all(scroll_book->notebook);
|
15033
|
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 }
|