15032
|
1 /*
|
|
2 * @file gtkscrollbook.c GTK+ Status Selection Widget
|
|
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);
|
|
31
|
|
32 GType
|
|
33 gtk_gaim_scroll_book_get_type (void)
|
|
34 {
|
|
35 static GType scroll_book_type = 0;
|
|
36
|
|
37 if (!scroll_book_type)
|
|
38 {
|
|
39 static const GTypeInfo scroll_book_info =
|
|
40 {
|
|
41 sizeof (GtkGaimScrollBookClass),
|
|
42 NULL, /* base_init */
|
|
43 NULL, /* base_finalize */
|
|
44 (GClassInitFunc) gtk_gaim_scroll_book_class_init,
|
|
45 NULL, /* class_finalize */
|
|
46 NULL, /* class_data */
|
|
47 sizeof (GtkGaimScrollBook),
|
|
48 0,
|
|
49 (GInstanceInitFunc) gtk_gaim_scroll_book_init,
|
|
50 NULL /* value_table */
|
|
51 };
|
|
52
|
|
53 scroll_book_type = g_type_register_static(GTK_TYPE_VBOX,
|
|
54 "GtkGaimScrollBook",
|
|
55 &scroll_book_info,
|
|
56 0);
|
|
57 }
|
|
58
|
|
59 return scroll_book_type;
|
|
60 }
|
|
61
|
|
62 static void
|
|
63 scroll_left_cb(GtkGaimScrollBook *scroll_book)
|
|
64 {
|
|
65 int index;
|
|
66 index = gtk_notebook_get_current_page(GTK_NOTEBOOK(scroll_book->notebook));
|
|
67
|
|
68 if (index > 0)
|
|
69 gtk_notebook_set_current_page(GTK_NOTEBOOK(scroll_book->notebook), index - 1);
|
|
70 }
|
|
71
|
|
72 static void
|
|
73 scroll_right_cb(GtkGaimScrollBook *scroll_book)
|
|
74 {
|
|
75 int index, count;
|
|
76 index = gtk_notebook_get_current_page(GTK_NOTEBOOK(scroll_book->notebook));
|
|
77 #if GTK_CHECK_VERSION(2,2,0)
|
|
78 count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook));
|
|
79 #else
|
|
80 count = g_list_length(GTK_NOTEBOOK(scroll_book->notebook)->children);
|
|
81 #endif
|
|
82
|
|
83 if (index + 1 < count)
|
|
84 gtk_notebook_set_current_page(GTK_NOTEBOOK(scroll_book->notebook), index + 1);
|
|
85 }
|
|
86
|
|
87 static void
|
|
88 refresh_scroll_box(GtkGaimScrollBook *scroll_book, int index, int count)
|
|
89 {
|
|
90 char *label;
|
|
91
|
|
92 gtk_widget_show_all(scroll_book);
|
|
93 if (count <= 1)
|
|
94 gtk_widget_hide(GTK_WIDGET(scroll_book->hbox));
|
|
95 else
|
|
96 gtk_widget_show_all(GTK_WIDGET(scroll_book->hbox));
|
|
97
|
|
98
|
|
99 label = g_strdup_printf("<span size='smaller' weight='bold'>(%d/%d)</span>", index+1, count);
|
|
100 gtk_label_set_markup(GTK_LABEL(scroll_book->label), label);
|
|
101 g_free(label);
|
|
102
|
|
103 if (index == 0)
|
|
104 gtk_widget_set_sensitive(scroll_book->left_arrow, FALSE);
|
|
105 else
|
|
106 gtk_widget_set_sensitive(scroll_book->left_arrow, TRUE);
|
|
107
|
|
108
|
|
109 if (index +1== count)
|
|
110 gtk_widget_set_sensitive(scroll_book->right_arrow, FALSE);
|
|
111 else
|
|
112 gtk_widget_set_sensitive(scroll_book->right_arrow, TRUE);
|
|
113 }
|
|
114
|
|
115
|
|
116 static void
|
|
117 page_count_change_cb(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, GtkGaimScrollBook *scroll_book)
|
|
118 {
|
|
119 int index = gtk_notebook_get_current_page(GTK_NOTEBOOK(scroll_book->notebook));
|
|
120 #if GTK_CHECK_VERSION(2,2,0)
|
|
121 int count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook));
|
|
122 #else
|
|
123 count = g_list_length(GTK_NOTEBOOK(scroll_book->notebook)->children);
|
|
124 #endif
|
|
125 refresh_scroll_box(scroll_book, index, count);
|
|
126
|
|
127 }
|
|
128
|
|
129 static void
|
|
130 switch_page_cb(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, GtkGaimScrollBook *scroll_book)
|
|
131 {
|
|
132 #if GTK_CHECK_VERSION(2,2,0)
|
|
133 int count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook));
|
|
134 #else
|
|
135 count = g_list_length(GTK_NOTEBOOK(scroll_book->notebook)->children);
|
|
136 #endif
|
|
137 refresh_scroll_box(scroll_book, page_num, count);
|
|
138 }
|
|
139
|
|
140 static void
|
|
141 gtk_gaim_scroll_book_add(GtkContainer *container, GtkWidget *widget)
|
|
142 {
|
|
143 gtk_widget_show(widget);
|
|
144 gtk_notebook_append_page(GTK_NOTEBOOK(GTK_GAIM_SCROLL_BOOK(container)->notebook), widget, NULL);
|
|
145 }
|
|
146
|
|
147 static void
|
|
148 gtk_gaim_scroll_book_class_init (GtkGaimScrollBookClass *klass)
|
|
149 {
|
|
150 GtkContainerClass *container_class = (GtkContainerClass*)klass;
|
|
151
|
|
152 container_class->add = gtk_gaim_scroll_book_add;
|
|
153
|
|
154 }
|
|
155
|
|
156 static void
|
|
157 gtk_gaim_scroll_book_init (GtkGaimScrollBook *scroll_book)
|
|
158 {
|
|
159 GtkWidget *eb;
|
|
160
|
|
161 scroll_book->hbox = gtk_hbox_new(FALSE, 0);
|
|
162
|
|
163 eb = gtk_event_box_new();
|
|
164 gtk_box_pack_end(GTK_BOX(scroll_book->hbox), eb, FALSE, FALSE, 0);
|
|
165 scroll_book->right_arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
|
|
166 gtk_container_add(GTK_CONTAINER(eb), scroll_book->right_arrow);
|
|
167 g_signal_connect_swapped(G_OBJECT(eb), "button-press-event", G_CALLBACK(scroll_right_cb), scroll_book);
|
|
168
|
|
169 scroll_book->label = gtk_label_new(NULL);
|
|
170 gtk_box_pack_end(GTK_BOX(scroll_book->hbox), scroll_book->label, FALSE, FALSE, 0);
|
|
171
|
|
172 eb = gtk_event_box_new();
|
|
173 gtk_box_pack_end(GTK_BOX(scroll_book->hbox), eb, FALSE, FALSE, 0);
|
|
174 scroll_book->left_arrow = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_NONE);
|
|
175 gtk_container_add(GTK_CONTAINER(eb), scroll_book->left_arrow);
|
|
176 g_signal_connect_swapped(G_OBJECT(eb), "button-press-event", G_CALLBACK(scroll_left_cb), scroll_book);
|
|
177
|
|
178 gtk_box_pack_start(GTK_BOX(scroll_book), scroll_book->hbox, FALSE, FALSE, 0);
|
|
179
|
|
180 scroll_book->notebook = gtk_notebook_new();
|
|
181 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(scroll_book->notebook), FALSE);
|
|
182 gtk_notebook_set_show_border(GTK_NOTEBOOK(scroll_book->notebook), FALSE);
|
|
183
|
|
184 gtk_box_pack_start(GTK_BOX(scroll_book), scroll_book->notebook, TRUE, TRUE, 0);
|
|
185
|
|
186 g_signal_connect(G_OBJECT(scroll_book->notebook), "page-added", G_CALLBACK(page_count_change_cb), scroll_book);
|
|
187 g_signal_connect(G_OBJECT(scroll_book->notebook), "page-removed", G_CALLBACK(page_count_change_cb), scroll_book);
|
|
188 g_signal_connect(G_OBJECT(scroll_book->notebook), "switch-page", G_CALLBACK(switch_page_cb), scroll_book);
|
|
189 gtk_widget_hide(scroll_book->hbox);
|
|
190 }
|
|
191
|
|
192
|
|
193
|
|
194 GtkWidget *
|
|
195 gtk_gaim_scroll_book_new()
|
|
196 {
|
|
197 return g_object_new(GTK_GAIM_TYPE_SCROLL_BOOK, NULL);
|
|
198 }
|