Sun, 22 Jul 2007 08:14:16 +0000
revert 'no visible tabs when only one conversation' as it proved unpopular. Made tabs only fill the entire width of the notebook when there's only one tab to avoid http://pidgin.im/~deryni/that_just_looks_dumb.png
| 15094 | 1 | /* |
| 15120 | 2 | * @file gtkscrollbook.c GTK+ Scrolling notebook widget |
|
16254
eeb2bba4dc94
Rename the Doxygen group from gtkui to pidgin.
Richard Laager <rlaager@pidgin.im>
parents:
15931
diff
changeset
|
3 | * @ingroup pidgin |
| 15094 | 4 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
5 | * pidgin |
| 15094 | 6 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
7 | * Pidgin is the legal property of its developers, whose names are too numerous |
| 15094 | 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 | ||
| 15577 | 29 | static void pidgin_scroll_book_init (PidginScrollBook *scroll_book); |
| 30 | static void pidgin_scroll_book_class_init (PidginScrollBookClass *klass); | |
| 31 | static void pidgin_scroll_book_forall (GtkContainer *c, | |
| 15240 | 32 | gboolean include_internals, |
| 33 | GtkCallback callback, | |
| 34 | gpointer user_data); | |
| 15094 | 35 | |
| 36 | GType | |
| 15577 | 37 | pidgin_scroll_book_get_type (void) |
| 15094 | 38 | { |
| 39 | static GType scroll_book_type = 0; | |
| 40 | ||
| 41 | if (!scroll_book_type) | |
| 42 | { | |
| 43 | static const GTypeInfo scroll_book_info = | |
| 44 | { | |
| 15577 | 45 | sizeof (PidginScrollBookClass), |
| 15094 | 46 | NULL, /* base_init */ |
| 47 | NULL, /* base_finalize */ | |
| 15577 | 48 | (GClassInitFunc) pidgin_scroll_book_class_init, |
| 15094 | 49 | NULL, /* class_finalize */ |
| 50 | NULL, /* class_data */ | |
| 15577 | 51 | sizeof (PidginScrollBook), |
| 15094 | 52 | 0, |
| 15577 | 53 | (GInstanceInitFunc) pidgin_scroll_book_init, |
| 15094 | 54 | NULL /* value_table */ |
| 55 | }; | |
| 56 | ||
| 57 | scroll_book_type = g_type_register_static(GTK_TYPE_VBOX, | |
| 15577 | 58 | "PidginScrollBook", |
| 15094 | 59 | &scroll_book_info, |
| 60 | 0); | |
| 61 | } | |
| 62 | ||
| 63 | return scroll_book_type; | |
| 64 | } | |
| 65 | ||
| 66 | static void | |
| 15577 | 67 | scroll_left_cb(PidginScrollBook *scroll_book) |
| 15094 | 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 | |
| 15577 | 77 | scroll_right_cb(PidginScrollBook *scroll_book) |
| 15094 | 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 | |
| 15577 | 92 | refresh_scroll_box(PidginScrollBook *scroll_book, int index, int count) |
| 15094 | 93 | { |
| 94 | char *label; | |
|
15114
4224e5db3ee4
[gaim-migrate @ 17836]
Mark Doliner <markdoliner@pidgin.im>
parents:
15094
diff
changeset
|
95 | gtk_widget_show_all(GTK_WIDGET(scroll_book)); |
| 15094 | 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 | |
| 15577 | 120 | page_count_change_cb(PidginScrollBook *scroll_book) |
| 15094 | 121 | { |
| 15243 | 122 | int count; |
| 15094 | 123 | int index = gtk_notebook_get_current_page(GTK_NOTEBOOK(scroll_book->notebook)); |
| 124 | #if GTK_CHECK_VERSION(2,2,0) | |
| 15243 | 125 | count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook)); |
| 15094 | 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 | |
| 15577 | 134 | switch_page_cb(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, PidginScrollBook *scroll_book) |
| 15094 | 135 | { |
|
15320
c4eea0409712
[gaim-migrate @ 18048]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15246
diff
changeset
|
136 | int count; |
| 15094 | 137 | #if GTK_CHECK_VERSION(2,2,0) |
|
15320
c4eea0409712
[gaim-migrate @ 18048]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15246
diff
changeset
|
138 | count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(scroll_book->notebook)); |
| 15094 | 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 | |
| 15577 | 146 | pidgin_scroll_book_add(GtkContainer *container, GtkWidget *widget) |
| 15094 | 147 | { |
| 148 | gtk_widget_show(widget); | |
| 15577 | 149 | gtk_notebook_append_page(GTK_NOTEBOOK(PIDGIN_SCROLL_BOOK(container)->notebook), widget, NULL); |
| 150 | page_count_change_cb(PIDGIN_SCROLL_BOOK(container)); | |
| 15094 | 151 | } |
| 152 | ||
| 153 | static void | |
| 15577 | 154 | pidgin_scroll_book_forall(GtkContainer *container, |
| 15240 | 155 | gboolean include_internals, |
| 156 | GtkCallback callback, | |
| 157 | gpointer callback_data) | |
| 158 | { | |
| 15577 | 159 | PidginScrollBook *scroll_book = PIDGIN_SCROLL_BOOK(container); |
| 15243 | 160 | if (include_internals) |
| 15240 | 161 | (*callback)(scroll_book->hbox, callback_data); |
| 162 | (*callback)(scroll_book->notebook, callback_data); | |
| 163 | } | |
| 164 | ||
| 165 | static void | |
| 15577 | 166 | pidgin_scroll_book_class_init (PidginScrollBookClass *klass) |
| 15094 | 167 | { |
| 168 | GtkContainerClass *container_class = (GtkContainerClass*)klass; | |
| 169 | ||
| 15577 | 170 | container_class->add = pidgin_scroll_book_add; |
| 171 | container_class->forall = pidgin_scroll_book_forall; | |
| 15094 | 172 | |
| 173 | } | |
| 174 | ||
| 175 | static void | |
| 15577 | 176 | pidgin_scroll_book_init (PidginScrollBook *scroll_book) |
| 15094 | 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 | ||
|
15190
4ce2829864f0
[gaim-migrate @ 17914]
Mark Doliner <markdoliner@pidgin.im>
parents:
15120
diff
changeset
|
205 | g_signal_connect_swapped(G_OBJECT(scroll_book->notebook), "remove", G_CALLBACK(page_count_change_cb), scroll_book); |
| 15094 | 206 | g_signal_connect(G_OBJECT(scroll_book->notebook), "switch-page", G_CALLBACK(switch_page_cb), scroll_book); |
| 15243 | 207 | gtk_widget_show_all(scroll_book->notebook); |
| 15094 | 208 | } |
| 209 | ||
| 210 | ||
| 211 | ||
| 212 | GtkWidget * | |
| 15577 | 213 | pidgin_scroll_book_new() |
| 15094 | 214 | { |
| 15577 | 215 | return g_object_new(PIDGIN_TYPE_SCROLL_BOOK, NULL); |
| 15094 | 216 | } |