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