Statistics
| Revision:

root / src / prefs_display_items.c @ 3063

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