diff options
Diffstat (limited to 'src/prefs_display_items.c')
| -rw-r--r-- | src/prefs_display_items.c | 623 |
1 files changed, 623 insertions, 0 deletions
diff --git a/src/prefs_display_items.c b/src/prefs_display_items.c new file mode 100644 index 0000000..bd554e3 --- /dev/null +++ b/src/prefs_display_items.c | |||
| @@ -0,0 +1,623 @@ | |||
| 1 | /* | ||
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client | ||
| 3 | * Copyright (C) 1999-2015 Hiroyuki Yamamoto | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #ifdef HAVE_CONFIG_H | ||
| 21 | # include "config.h" | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #include "defs.h" | ||
| 25 | |||
| 26 | #include <glib.h> | ||
| 27 | #include <glib/gi18n.h> | ||
| 28 | #include <gdk/gdkkeysyms.h> | ||
| 29 | #include <gtk/gtk.h> | ||
| 30 | |||
| 31 | #include "prefs.h" | ||
| 32 | #include "prefs_ui.h" | ||
| 33 | #include "prefs_common.h" | ||
| 34 | #include "prefs_display_items.h" | ||
| 35 | #include "manage_window.h" | ||
| 36 | #include "mainwindow.h" | ||
| 37 | #include "gtkutils.h" | ||
| 38 | #include "utils.h" | ||
| 39 | |||
| 40 | #define SCROLLED_WINDOW_WIDTH 180 | ||
| 41 | #define SCROLLED_WINDOW_HEIGHT 210 | ||
| 42 | |||
| 43 | static void prefs_display_items_set_sensitive(PrefsDisplayItemsDialog *dialog); | ||
| 44 | |||
| 45 | /* callback functions */ | ||
| 46 | static void prefs_display_items_add (GtkWidget *widget, | ||
| 47 | gpointer data); | ||
| 48 | static void prefs_display_items_remove (GtkWidget *widget, | ||
| 49 | gpointer data); | ||
| 50 | |||
| 51 | static void prefs_display_items_up (GtkWidget *widget, | ||
| 52 | gpointer data); | ||
| 53 | static void prefs_display_items_down (GtkWidget *widget, | ||
| 54 | gpointer data); | ||
| 55 | |||
| 56 | static void prefs_display_items_default (GtkWidget *widget, | ||
| 57 | gpointer data); | ||
| 58 | |||
| 59 | static void prefs_display_items_ok (GtkWidget *widget, | ||
| 60 | gpointer data); | ||
| 61 | static void prefs_display_items_cancel (GtkWidget *widget, | ||
| 62 | gpointer data); | ||
| 63 | |||
| 64 | static void prefs_display_items_shown_select_row(GtkWidget *widget, | ||
| 65 | gint row, | ||
| 66 | gint column, | ||
| 67 | GdkEventButton *event, | ||
| 68 | gpointer data); | ||
| 69 | static void prefs_display_items_shown_row_move (GtkWidget *widget, | ||
| 70 | gint row, | ||
| 71 | gint column, | ||
| 72 | gpointer data); | ||
| 73 | |||
| 74 | static gint prefs_display_items_delete_event (GtkWidget *widget, | ||
| 75 | GdkEventAny *event, | ||
| 76 | gpointer data); | ||
| 77 | static gboolean prefs_display_items_key_pressed (GtkWidget *widget, | ||
| 78 | GdkEventKey *event, | ||
| 79 | gpointer data); | ||
| 80 | |||
| 81 | PrefsDisplayItemsDialog *prefs_display_items_dialog_create(void) | ||
| 82 | { | ||
| 83 | PrefsDisplayItemsDialog *dialog; | ||
| 84 | |||
| 85 | GtkWidget *window; | ||
| 86 | GtkWidget *vbox; | ||
| 87 | |||
| 88 | GtkWidget *label_hbox; | ||
| 89 | GtkWidget *label; | ||
| 90 | |||
| 91 | GtkWidget *vbox1; | ||
| 92 | |||
| 93 | GtkWidget *hbox1; | ||
| 94 | GtkWidget *clist_hbox; | ||
| 95 | GtkWidget *scrolledwin; | ||
| 96 | GtkWidget *stock_clist; | ||
| 97 | GtkWidget *shown_clist; | ||
| 98 | |||
| 99 | GtkWidget *btn_vbox; | ||
| 100 | GtkWidget *btn_vbox1; | ||
| 101 | GtkWidget *add_btn; | ||
| 102 | GtkWidget *remove_btn; | ||
| 103 | GtkWidget *up_btn; | ||
| 104 | GtkWidget *down_btn; | ||
| 105 | |||
| 106 | GtkWidget *btn_hbox; | ||
| 107 | GtkWidget *default_btn; | ||
| 108 | GtkWidget *confirm_area; | ||
| 109 | GtkWidget *ok_btn; | ||
| 110 | GtkWidget *cancel_btn; | ||
| 111 | |||
| 112 | gchar *title[1]; | ||
| 113 | |||
| 114 | dialog = g_new0(PrefsDisplayItemsDialog, 1); | ||
| 115 | |||
| 116 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
| 117 | gtk_container_set_border_width(GTK_CONTAINER(window), 8); | ||
| 118 | gtk_window_set_position(GTK_WINDOW(window), | ||
| 119 | GTK_WIN_POS_CENTER_ON_PARENT); | ||
| 120 | gtk_window_set_modal(GTK_WINDOW(window), TRUE); | ||
| 121 | gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); | ||
| 122 | gtk_window_set_title(GTK_WINDOW(window), _("Display items setting")); | ||
| 123 | g_signal_connect(G_OBJECT(window), "delete_event", | ||
| 124 | G_CALLBACK(prefs_display_items_delete_event), dialog); | ||
| 125 | g_signal_connect(G_OBJECT(window), "key_press_event", | ||
| 126 | G_CALLBACK(prefs_display_items_key_pressed), dialog); | ||
| 127 | |||
| 128 | vbox = gtk_vbox_new(FALSE, 6); | ||
| 129 | gtk_widget_show(vbox); | ||
| 130 | gtk_container_add(GTK_CONTAINER(window), vbox); | ||
| 131 | |||
| 132 | label_hbox = gtk_hbox_new(FALSE, 0); | ||
| 133 | gtk_widget_show(label_hbox); | ||
| 134 | gtk_box_pack_start(GTK_BOX(vbox), label_hbox, FALSE, FALSE, 4); | ||
| 135 | |||
| 136 | label = gtk_label_new(""); | ||
| 137 | gtk_widget_show(label); | ||
| 138 | gtk_box_pack_start(GTK_BOX(label_hbox), label, FALSE, FALSE, 4); | ||
| 139 | gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | ||
| 140 | |||
| 141 | vbox1 = gtk_vbox_new(FALSE, VSPACING); | ||
| 142 | gtk_widget_show(vbox1); | ||
| 143 | gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0); | ||
| 144 | gtk_container_set_border_width(GTK_CONTAINER(vbox1), 2); | ||
| 145 | |||
| 146 | hbox1 = gtk_hbox_new(FALSE, 8); | ||
| 147 | gtk_widget_show(hbox1); | ||
| 148 | gtk_box_pack_start(GTK_BOX(vbox1), hbox1, FALSE, TRUE, 0); | ||
| 149 | |||
| 150 | clist_hbox = gtk_hbox_new(FALSE, 8); | ||
| 151 | gtk_widget_show(clist_hbox); | ||
| 152 | gtk_box_pack_start(GTK_BOX(hbox1), clist_hbox, TRUE, TRUE, 0); | ||
| 153 | |||
| 154 | scrolledwin = gtk_scrolled_window_new(NULL, NULL); | ||
| 155 | gtk_widget_set_size_request | ||
| 156 | (scrolledwin, | ||
| 157 | SCROLLED_WINDOW_WIDTH * gtkut_get_dpi_multiplier(), | ||
| 158 | SCROLLED_WINDOW_HEIGHT * gtkut_get_dpi_multiplier()); | ||
| 159 | gtk_widget_show(scrolledwin); | ||
| 160 | gtk_box_pack_start(GTK_BOX(clist_hbox), scrolledwin, TRUE, TRUE, 0); | ||
| 161 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 162 | GTK_POLICY_AUTOMATIC, | ||
| 163 | GTK_POLICY_AUTOMATIC); | ||
| 164 | |||
| 165 | title[0] = _("Available items"); | ||
| 166 | stock_clist = gtk_clist_new_with_titles(1, title); | ||
| 167 | gtk_widget_show(stock_clist); | ||
| 168 | gtk_container_add(GTK_CONTAINER(scrolledwin), stock_clist); | ||
| 169 | gtk_clist_set_selection_mode(GTK_CLIST(stock_clist), | ||
| 170 | GTK_SELECTION_BROWSE); | ||
| 171 | GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(stock_clist)->column[0].button, | ||
| 172 | GTK_CAN_FOCUS); | ||
| 173 | gtkut_clist_set_redraw(GTK_CLIST(stock_clist)); | ||
| 174 | |||
| 175 | /* add/remove button */ | ||
| 176 | btn_vbox = gtk_vbox_new(FALSE, 0); | ||
| 177 | gtk_widget_show(btn_vbox); | ||
| 178 | gtk_box_pack_start(GTK_BOX(hbox1), btn_vbox, FALSE, FALSE, 0); | ||
| 179 | |||
| 180 | btn_vbox1 = gtk_vbox_new(FALSE, 8); | ||
| 181 | gtk_widget_show(btn_vbox1); | ||
| 182 | gtk_box_pack_start(GTK_BOX(btn_vbox), btn_vbox1, TRUE, FALSE, 0); | ||
| 183 | |||
| 184 | add_btn = gtk_button_new_with_label(_(" -> ")); | ||
| 185 | gtk_widget_show(add_btn); | ||
| 186 | gtk_box_pack_start(GTK_BOX(btn_vbox1), add_btn, FALSE, FALSE, 0); | ||
| 187 | |||
| 188 | remove_btn = gtk_button_new_with_label(_(" <- ")); | ||
| 189 | gtk_widget_show(remove_btn); | ||
| 190 | gtk_box_pack_start(GTK_BOX(btn_vbox1), remove_btn, FALSE, FALSE, 0); | ||
| 191 | |||
| 192 | g_signal_connect(G_OBJECT(add_btn), "clicked", | ||
| 193 | G_CALLBACK(prefs_display_items_add), dialog); | ||
| 194 | g_signal_connect(G_OBJECT(remove_btn), "clicked", | ||
| 195 | G_CALLBACK(prefs_display_items_remove), dialog); | ||
| 196 | |||
| 197 | clist_hbox = gtk_hbox_new(FALSE, 8); | ||
| 198 | gtk_widget_show(clist_hbox); | ||
| 199 | gtk_box_pack_start(GTK_BOX(hbox1), clist_hbox, TRUE, TRUE, 0); | ||
| 200 | |||
| 201 | scrolledwin = gtk_scrolled_window_new(NULL, NULL); | ||
| 202 | gtk_widget_set_size_request | ||
| 203 | (scrolledwin, | ||
| 204 | SCROLLED_WINDOW_WIDTH * gtkut_get_dpi_multiplier(), | ||
| 205 | SCROLLED_WINDOW_HEIGHT * gtkut_get_dpi_multiplier()); | ||
| 206 | gtk_widget_show(scrolledwin); | ||
| 207 | gtk_box_pack_start(GTK_BOX(clist_hbox), scrolledwin, TRUE, TRUE, 0); | ||
| 208 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 209 | GTK_POLICY_AUTOMATIC, | ||
| 210 | GTK_POLICY_AUTOMATIC); | ||
| 211 | |||
| 212 | title[0] = _("Displayed items"); | ||
| 213 | shown_clist = gtk_clist_new_with_titles(1, title); | ||
| 214 | gtk_widget_show(shown_clist); | ||
| 215 | gtk_container_add(GTK_CONTAINER(scrolledwin), shown_clist); | ||
| 216 | gtk_clist_set_selection_mode(GTK_CLIST(shown_clist), | ||
| 217 | GTK_SELECTION_BROWSE); | ||
| 218 | #if 0 | ||
| 219 | gtk_clist_set_reorderable(GTK_CLIST(shown_clist), TRUE); | ||
| 220 | gtk_clist_set_use_drag_icons(GTK_CLIST(shown_clist), FALSE); | ||
| 221 | #endif | ||
| 222 | GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(shown_clist)->column[0].button, | ||
| 223 | GTK_CAN_FOCUS); | ||
| 224 | gtkut_clist_set_redraw(GTK_CLIST(shown_clist)); | ||
| 225 | |||
| 226 | g_signal_connect(G_OBJECT(shown_clist), "select-row", | ||
| 227 | G_CALLBACK(prefs_display_items_shown_select_row), | ||
| 228 | dialog); | ||
| 229 | g_signal_connect_after(G_OBJECT(shown_clist), "row-move", | ||
| 230 | G_CALLBACK(prefs_display_items_shown_row_move), | ||
| 231 | dialog); | ||
| 232 | |||
| 233 | /* up/down button */ | ||
| 234 | btn_vbox = gtk_vbox_new(FALSE, 0); | ||
| 235 | gtk_widget_show(btn_vbox); | ||
| 236 | gtk_box_pack_start(GTK_BOX(hbox1), btn_vbox, FALSE, FALSE, 0); | ||
| 237 | |||
| 238 | btn_vbox1 = gtk_vbox_new(FALSE, 8); | ||
| 239 | gtk_widget_show(btn_vbox1); | ||
| 240 | gtk_box_pack_start(GTK_BOX(btn_vbox), btn_vbox1, TRUE, FALSE, 0); | ||
| 241 | |||
| 242 | up_btn = gtk_button_new_with_label(_("Up")); | ||
| 243 | gtk_widget_show(up_btn); | ||
| 244 | gtk_box_pack_start(GTK_BOX(btn_vbox1), up_btn, FALSE, FALSE, 0); | ||
| 245 | |||
| 246 | down_btn = gtk_button_new_with_label(_("Down")); | ||
| 247 | gtk_widget_show(down_btn); | ||
| 248 | gtk_box_pack_start(GTK_BOX(btn_vbox1), down_btn, FALSE, FALSE, 0); | ||
| 249 | |||
| 250 | g_signal_connect(G_OBJECT(up_btn), "clicked", | ||
| 251 | G_CALLBACK(prefs_display_items_up), dialog); | ||
| 252 | g_signal_connect(G_OBJECT(down_btn), "clicked", | ||
| 253 | G_CALLBACK(prefs_display_items_down), dialog); | ||
| 254 | |||
| 255 | btn_hbox = gtk_hbox_new(FALSE, 8); | ||
| 256 | gtk_widget_show(btn_hbox); | ||
| 257 | gtk_box_pack_end(GTK_BOX(vbox), btn_hbox, FALSE, FALSE, 0); | ||
| 258 | |||
| 259 | btn_vbox = gtk_vbox_new(FALSE, 0); | ||
| 260 | gtk_widget_show(btn_vbox); | ||
| 261 | gtk_box_pack_start(GTK_BOX(btn_hbox), btn_vbox, FALSE, FALSE, 0); | ||
| 262 | |||
| 263 | default_btn = gtk_button_new_with_label(_(" Revert to default ")); | ||
| 264 | gtk_widget_show(default_btn); | ||
| 265 | gtk_box_pack_start(GTK_BOX(btn_vbox), default_btn, TRUE, FALSE, 0); | ||
| 266 | |||
| 267 | g_signal_connect(G_OBJECT(default_btn), "clicked", | ||
| 268 | G_CALLBACK(prefs_display_items_default), dialog); | ||
| 269 | |||
| 270 | gtkut_stock_button_set_create(&confirm_area, &ok_btn, GTK_STOCK_OK, | ||
| 271 | &cancel_btn, GTK_STOCK_CANCEL, | ||
| 272 | NULL, NULL); | ||
| 273 | gtk_widget_show(confirm_area); | ||
| 274 | gtk_box_pack_end(GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0); | ||
| 275 | gtk_widget_grab_default(ok_btn); | ||
| 276 | |||
| 277 | g_signal_connect(G_OBJECT(ok_btn), "clicked", | ||
| 278 | G_CALLBACK(prefs_display_items_ok), dialog); | ||
| 279 | g_signal_connect(G_OBJECT(cancel_btn), "clicked", | ||
| 280 | G_CALLBACK(prefs_display_items_cancel), dialog); | ||
| 281 | |||
| 282 | dialog->window = window; | ||
| 283 | dialog->label = label; | ||
| 284 | dialog->stock_clist = stock_clist; | ||
| 285 | dialog->shown_clist = shown_clist; | ||
| 286 | dialog->add_btn = add_btn; | ||
| 287 | dialog->remove_btn = remove_btn; | ||
| 288 | dialog->up_btn = up_btn; | ||
| 289 | dialog->down_btn = down_btn; | ||
| 290 | dialog->confirm_area = confirm_area; | ||
| 291 | dialog->ok_btn = ok_btn; | ||
| 292 | dialog->cancel_btn = cancel_btn; | ||
| 293 | |||
| 294 | gtkut_box_set_reverse_order(GTK_BOX(dialog->confirm_area), | ||
| 295 | !prefs_common.comply_gnome_hig); | ||
| 296 | manage_window_set_transient(GTK_WINDOW(dialog->window)); | ||
| 297 | gtk_widget_grab_focus(dialog->ok_btn); | ||
| 298 | |||
| 299 | dialog->finished = FALSE; | ||
| 300 | dialog->cancelled = FALSE; | ||
| 301 | |||
| 302 | return dialog; | ||
| 303 | } | ||
| 304 | |||
| 305 | void prefs_display_items_dialog_destroy(PrefsDisplayItemsDialog *dialog) | ||
| 306 | { | ||
| 307 | if (!dialog) | ||
| 308 | return; | ||
| 309 | |||
| 310 | if (dialog->available_items) | ||
| 311 | g_list_free(dialog->available_items); | ||
| 312 | if (dialog->visible_items) | ||
| 313 | g_list_free(dialog->visible_items); | ||
| 314 | gtk_widget_destroy(dialog->window); | ||
| 315 | g_free(dialog); | ||
| 316 | } | ||
| 317 | |||
| 318 | static void prefs_display_items_update_available | ||
| 319 | (PrefsDisplayItemsDialog *dialog) | ||
| 320 | { | ||
| 321 | GtkCList *stock_clist = GTK_CLIST(dialog->stock_clist); | ||
| 322 | GList *cur; | ||
| 323 | |||
| 324 | g_return_if_fail(dialog->available_items != NULL); | ||
| 325 | |||
| 326 | gtk_clist_clear(stock_clist); | ||
| 327 | |||
| 328 | for (cur = dialog->available_items; cur != NULL; cur = cur->next) { | ||
| 329 | PrefsDisplayItem *item = cur->data; | ||
| 330 | gint row; | ||
| 331 | gchar *name; | ||
| 332 | |||
| 333 | if (item->allow_multiple || item->in_use == FALSE) { | ||
| 334 | name = gettext(item->label); | ||
| 335 | row = gtk_clist_append(stock_clist, (gchar **)&name); | ||
| 336 | gtk_clist_set_row_data(stock_clist, row, item); | ||
| 337 | } | ||
| 338 | } | ||
| 339 | } | ||
| 340 | |||
| 341 | static PrefsDisplayItem *prefs_display_items_get_item_from_id | ||
| 342 | (PrefsDisplayItemsDialog *dialog, gint id) | ||
| 343 | { | ||
| 344 | gint i; | ||
| 345 | |||
| 346 | for (i = 0; dialog->all_items[i].id != -1; i++) { | ||
| 347 | if (id == dialog->all_items[i].id) | ||
| 348 | return (PrefsDisplayItem *)&dialog->all_items[i]; | ||
| 349 | } | ||
| 350 | |||
| 351 | return NULL; | ||
| 352 | } | ||
| 353 | |||
| 354 | void prefs_display_items_dialog_set_available(PrefsDisplayItemsDialog *dialog, | ||
| 355 | PrefsDisplayItem *all_items, | ||
| 356 | const gint *ids) | ||
| 357 | { | ||
| 358 | gint i; | ||
| 359 | GList *list = NULL; | ||
| 360 | |||
| 361 | dialog->all_items = all_items; | ||
| 362 | for (i = 0; ids[i] != -1; i++) { | ||
| 363 | PrefsDisplayItem *item; | ||
| 364 | |||
| 365 | item = prefs_display_items_get_item_from_id(dialog, ids[i]); | ||
| 366 | if (item) | ||
| 367 | list = g_list_append(list, item); | ||
| 368 | } | ||
| 369 | dialog->available_items = list; | ||
| 370 | prefs_display_items_update_available(dialog); | ||
| 371 | } | ||
| 372 | |||
| 373 | void prefs_display_items_dialog_set_default_visible | ||
| 374 | (PrefsDisplayItemsDialog *dialog, | ||
| 375 | const gint *ids) | ||
| 376 | { | ||
| 377 | dialog->default_visible_ids = ids; | ||
| 378 | } | ||
| 379 | |||
| 380 | void prefs_display_items_dialog_set_visible(PrefsDisplayItemsDialog *dialog, | ||
| 381 | const gint *ids) | ||
| 382 | { | ||
| 383 | GtkCList *shown_clist = GTK_CLIST(dialog->shown_clist); | ||
| 384 | GList *cur; | ||
| 385 | PrefsDisplayItem *item; | ||
| 386 | gint i; | ||
| 387 | gint row; | ||
| 388 | gchar *name; | ||
| 389 | |||
| 390 | g_return_if_fail(dialog->available_items != NULL); | ||
| 391 | |||
| 392 | if (!ids) | ||
| 393 | ids = dialog->default_visible_ids; | ||
| 394 | g_return_if_fail(ids != NULL); | ||
| 395 | |||
| 396 | gtk_clist_clear(shown_clist); | ||
| 397 | |||
| 398 | if (dialog->visible_items) { | ||
| 399 | g_list_free(dialog->visible_items); | ||
| 400 | dialog->visible_items = NULL; | ||
| 401 | } | ||
| 402 | |||
| 403 | for (cur = dialog->available_items; cur != NULL; cur = cur->next) { | ||
| 404 | item = cur->data; | ||
| 405 | item->in_use = FALSE; | ||
| 406 | } | ||
| 407 | |||
| 408 | for (i = 0; ids[i] != -1; i++) { | ||
| 409 | gint id = ids[i]; | ||
| 410 | |||
| 411 | item = prefs_display_items_get_item_from_id(dialog, id); | ||
| 412 | |||
| 413 | g_return_if_fail(item != NULL); | ||
| 414 | g_return_if_fail(item->allow_multiple || item->in_use == FALSE); | ||
| 415 | |||
| 416 | item->in_use = TRUE; | ||
| 417 | |||
| 418 | name = gettext(item->label); | ||
| 419 | row = gtk_clist_append(shown_clist, (gchar **)&name); | ||
| 420 | gtk_clist_set_row_data(shown_clist, row, item); | ||
| 421 | } | ||
| 422 | |||
| 423 | name = "--------"; | ||
| 424 | row = gtk_clist_append(shown_clist, (gchar **)&name); | ||
| 425 | gtk_widget_ensure_style(GTK_WIDGET(shown_clist)); | ||
| 426 | gtk_clist_set_foreground | ||
| 427 | (shown_clist, row, | ||
| 428 | >K_WIDGET(shown_clist)->style->text[GTK_STATE_INSENSITIVE]); | ||
| 429 | |||
| 430 | prefs_display_items_update_available(dialog); | ||
| 431 | prefs_display_items_set_sensitive(dialog); | ||
| 432 | gtk_clist_moveto(shown_clist, 0, 0, 0, 0); | ||
| 433 | } | ||
| 434 | |||
| 435 | static void prefs_display_items_set_sensitive(PrefsDisplayItemsDialog *dialog) | ||
| 436 | { | ||
| 437 | GtkCList *clist = GTK_CLIST(dialog->shown_clist); | ||
| 438 | gint row; | ||
| 439 | |||
| 440 | if (!clist->selection) return; | ||
| 441 | |||
| 442 | row = GPOINTER_TO_INT(clist->selection->data); | ||
| 443 | |||
| 444 | if (gtk_clist_get_row_data(clist, row)) | ||
| 445 | gtk_widget_set_sensitive(dialog->remove_btn, TRUE); | ||
| 446 | else | ||
| 447 | gtk_widget_set_sensitive(dialog->remove_btn, FALSE); | ||
| 448 | |||
| 449 | if (row > 0 && row < clist->rows - 1) | ||
| 450 | gtk_widget_set_sensitive(dialog->up_btn, TRUE); | ||
| 451 | else | ||
| 452 | gtk_widget_set_sensitive(dialog->up_btn, FALSE); | ||
| 453 | |||
| 454 | if (row >= 0 && row < clist->rows - 2) | ||
| 455 | gtk_widget_set_sensitive(dialog->down_btn, TRUE); | ||
| 456 | else | ||
| 457 | gtk_widget_set_sensitive(dialog->down_btn, FALSE); | ||
| 458 | |||
| 459 | if (gtk_clist_row_is_visible(clist, row) != GTK_VISIBILITY_FULL) | ||
| 460 | gtk_clist_moveto(clist, row, 0, 0.5, 0); | ||
| 461 | } | ||
| 462 | |||
| 463 | static void prefs_display_items_add(GtkWidget *widget, gpointer data) | ||
| 464 | { | ||
| 465 | PrefsDisplayItemsDialog *dialog = data; | ||
| 466 | GtkCList *stock_clist = GTK_CLIST(dialog->stock_clist); | ||
| 467 | GtkCList *shown_clist = GTK_CLIST(dialog->shown_clist); | ||
| 468 | PrefsDisplayItem *item; | ||
| 469 | gint row; | ||
| 470 | gchar *name; | ||
| 471 | |||
| 472 | if (!stock_clist->selection) return; | ||
| 473 | |||
| 474 | row = GPOINTER_TO_INT(stock_clist->selection->data); | ||
| 475 | item = (PrefsDisplayItem *)gtk_clist_get_row_data(stock_clist, row); | ||
| 476 | if (!item->allow_multiple) { | ||
| 477 | gtk_clist_remove(stock_clist, row); | ||
| 478 | if (stock_clist->rows == row) | ||
| 479 | gtk_clist_select_row(stock_clist, row - 1, -1); | ||
| 480 | } | ||
| 481 | |||
| 482 | if (!shown_clist->selection) | ||
| 483 | row = 0; | ||
| 484 | else | ||
| 485 | row = GPOINTER_TO_INT(shown_clist->selection->data); | ||
| 486 | |||
| 487 | item->in_use = TRUE; | ||
| 488 | |||
| 489 | name = gettext(item->label); | ||
| 490 | row = gtk_clist_insert(shown_clist, row, (gchar **)&name); | ||
| 491 | gtk_clist_set_row_data(shown_clist, row, item); | ||
| 492 | |||
| 493 | prefs_display_items_set_sensitive(dialog); | ||
| 494 | } | ||
| 495 | |||
| 496 | static void prefs_display_items_remove(GtkWidget *widget, gpointer data) | ||
| 497 | { | ||
| 498 | PrefsDisplayItemsDialog *dialog = data; | ||
| 499 | GtkCList *shown_clist = GTK_CLIST(dialog->shown_clist); | ||
| 500 | PrefsDisplayItem *item; | ||
| 501 | gint row; | ||
| 502 | |||
| 503 | if (!shown_clist->selection) return; | ||
| 504 | |||
| 505 | row = GPOINTER_TO_INT(shown_clist->selection->data); | ||
| 506 | item = (PrefsDisplayItem *)gtk_clist_get_row_data(shown_clist, row); | ||
| 507 | if (!item) | ||
| 508 | return; | ||
| 509 | gtk_clist_remove(shown_clist, row); | ||
| 510 | if (shown_clist->rows == row) | ||
| 511 | gtk_clist_select_row(shown_clist, row - 1, -1); | ||
| 512 | |||
| 513 | if (!item->allow_multiple) { | ||
| 514 | item->in_use = FALSE; | ||
| 515 | prefs_display_items_update_available(dialog); | ||
| 516 | } | ||
| 517 | |||
| 518 | prefs_display_items_set_sensitive(dialog); | ||
| 519 | } | ||
| 520 | |||
| 521 | static void prefs_display_items_up(GtkWidget *widget, gpointer data) | ||
| 522 | { | ||
| 523 | PrefsDisplayItemsDialog *dialog = data; | ||
| 524 | GtkCList *shown_clist = GTK_CLIST(dialog->shown_clist); | ||
| 525 | gint row; | ||
| 526 | |||
| 527 | if (!shown_clist->selection) return; | ||
| 528 | |||
| 529 | row = GPOINTER_TO_INT(shown_clist->selection->data); | ||
| 530 | if (row > 0 && row < shown_clist->rows - 1) | ||
| 531 | gtk_clist_row_move(shown_clist, row, row - 1); | ||
| 532 | } | ||
| 533 | |||
| 534 | static void prefs_display_items_down(GtkWidget *widget, gpointer data) | ||
| 535 | { | ||
| 536 | PrefsDisplayItemsDialog *dialog = data; | ||
| 537 | GtkCList *shown_clist = GTK_CLIST(dialog->shown_clist); | ||
| 538 | gint row; | ||
| 539 | |||
| 540 | if (!shown_clist->selection) return; | ||
| 541 | |||
| 542 | row = GPOINTER_TO_INT(shown_clist->selection->data); | ||
| 543 | if (row >= 0 && row < shown_clist->rows - 2) | ||
| 544 | gtk_clist_row_move(shown_clist, row, row + 1); | ||
| 545 | } | ||
| 546 | |||
| 547 | static void prefs_display_items_default(GtkWidget *widget, gpointer data) | ||
| 548 | { | ||
| 549 | PrefsDisplayItemsDialog *dialog = data; | ||
| 550 | |||
| 551 | prefs_display_items_dialog_set_visible(dialog, NULL); | ||
| 552 | } | ||
| 553 | |||
| 554 | static void prefs_display_items_ok(GtkWidget *widget, gpointer data) | ||
| 555 | { | ||
| 556 | PrefsDisplayItemsDialog *dialog = data; | ||
| 557 | GtkCList *shown_clist = GTK_CLIST(dialog->shown_clist); | ||
| 558 | GList *list = NULL; | ||
| 559 | PrefsDisplayItem *item; | ||
| 560 | gint row; | ||
| 561 | |||
| 562 | for (row = 0; row < shown_clist->rows; row++) { | ||
| 563 | item = gtk_clist_get_row_data(shown_clist, row); | ||
| 564 | if (item) | ||
| 565 | list = g_list_append(list, item); | ||
| 566 | } | ||
| 567 | |||
| 568 | dialog->visible_items = list; | ||
| 569 | dialog->finished = TRUE; | ||
| 570 | } | ||
| 571 | |||
| 572 | static void prefs_display_items_cancel(GtkWidget *widget, gpointer data) | ||
| 573 | { | ||
| 574 | PrefsDisplayItemsDialog *dialog = data; | ||
| 575 | |||
| 576 | dialog->finished = TRUE; | ||
| 577 | dialog->cancelled = TRUE; | ||
| 578 | } | ||
| 579 | |||
| 580 | static void prefs_display_items_shown_select_row(GtkWidget *widget, | ||
| 581 | gint row, | ||
| 582 | gint column, | ||
| 583 | GdkEventButton *event, | ||
| 584 | gpointer data) | ||
| 585 | { | ||
| 586 | PrefsDisplayItemsDialog *dialog = data; | ||
| 587 | |||
| 588 | prefs_display_items_set_sensitive(dialog); | ||
| 589 | } | ||
| 590 | |||
| 591 | static void prefs_display_items_shown_row_move (GtkWidget *widget, | ||
| 592 | gint row, | ||
| 593 | gint column, | ||
| 594 | gpointer data) | ||
| 595 | { | ||
| 596 | PrefsDisplayItemsDialog *dialog = data; | ||
| 597 | |||
| 598 | prefs_display_items_set_sensitive(dialog); | ||
| 599 | } | ||
| 600 | |||
| 601 | static gint prefs_display_items_delete_event(GtkWidget *widget, | ||
| 602 | GdkEventAny *event, | ||
| 603 | gpointer data) | ||
| 604 | { | ||
| 605 | PrefsDisplayItemsDialog *dialog = data; | ||
| 606 | |||
| 607 | dialog->finished = TRUE; | ||
| 608 | dialog->cancelled = TRUE; | ||
| 609 | return TRUE; | ||
| 610 | } | ||
| 611 | |||
| 612 | static gboolean prefs_display_items_key_pressed(GtkWidget *widget, | ||
| 613 | GdkEventKey *event, | ||
| 614 | gpointer data) | ||
| 615 | { | ||
| 616 | PrefsDisplayItemsDialog *dialog = data; | ||
| 617 | |||
| 618 | if (event && event->keyval == GDK_Escape) { | ||
| 619 | dialog->finished = TRUE; | ||
| 620 | dialog->cancelled = TRUE; | ||
| 621 | } | ||
| 622 | return FALSE; | ||
| 623 | } | ||
