1 /* 2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client 3 * Copyright (C) 1999-2017 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 #ifndef __PREFS_UI_H__ 21 #define __PREFS_UI_H__ 22 23 #include <glib.h> 24 #include <gtk/gtkwidget.h> 25 #include <gtk/gtksignal.h> 26 #include <gtk/gtklabel.h> 27 #include <gtk/gtknotebook.h> 28 #include <gtk/gtkcheckbutton.h> 29 #include <gtk/gtkframe.h> 30 #include <gtk/gtkvbox.h> 31 #include <stdio.h> 32 33 typedef struct _PrefsDialog PrefsDialog; 34 typedef struct _PrefsUIData PrefsUIData; 35 36 #include "prefs.h" 37 #include "gtkutils.h" 38 39 #define VSPACING 10 40 #define VSPACING_NARROW 4 41 #define VSPACING_NARROW_2 2 42 #define VBOX_BORDER 12 43 #define DEFAULT_ENTRY_WIDTH 80 44 45 struct _PrefsUIData 46 { 47 gchar *name; 48 GtkWidget **widget; 49 DataSetFunc data_set_func; 50 WidgetSetFunc widget_set_func; 51 }; 52 53 struct _PrefsDialog 54 { 55 GtkWidget *window; 56 GtkWidget *notebook; 57 58 GtkWidget *confirm_area; 59 GtkWidget *ok_btn; 60 GtkWidget *cancel_btn; 61 GtkWidget *apply_btn; 62 }; 63 64 #define SET_NOTEBOOK_LABEL(notebook, str, page_num) \ 65 { \ 66 GtkWidget *label; \ 67 \ 68 label = gtk_label_new (str); \ 69 gtk_widget_show (label); \ 70 gtk_notebook_set_tab_label \ 71 (GTK_NOTEBOOK (notebook), \ 72 gtk_notebook_get_nth_page \ 73 (GTK_NOTEBOOK (notebook), page_num), \ 74 label); \ 75 } 76 77 #define APPEND_SUB_NOTEBOOK(notebook, vbox, str) \ 78 { \ 79 GtkWidget *label; \ 80 \ 81 label = gtk_label_new(str); \ 82 gtk_widget_show(label); \ 83 vbox = gtk_vbox_new(FALSE, VSPACING); \ 84 gtk_widget_show(vbox); \ 85 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, label); \ 86 gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER); \ 87 } 88 89 #define PACK_CHECK_BUTTON(box, chkbtn, label) \ 90 { \ 91 chkbtn = gtk_check_button_new_with_label(label); \ 92 gtk_widget_show(chkbtn); \ 93 gtk_box_pack_start(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \ 94 } 95 96 #define PACK_END_CHECK_BUTTON(box, chkbtn, label) \ 97 { \ 98 chkbtn = gtk_check_button_new_with_label(label); \ 99 gtk_widget_show(chkbtn); \ 100 gtk_box_pack_end(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \ 101 } 102 103 #define PACK_FRAME(box, frame, label) \ 104 { \ 105 frame = gtk_frame_new(label); \ 106 gtk_widget_show(frame); \ 107 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0); \ 108 gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5); \ 109 } 110 111 #define PACK_FRAME_WITH_CHECK_BUTTON(box, frame, chkbtn, label) \ 112 { \ 113 chkbtn = gtk_check_button_new_with_label(label); \ 114 gtk_widget_show(chkbtn); \ 115 PACK_FRAME(box, frame, NULL); \ 116 gtk_frame_set_label_widget(GTK_FRAME(frame), chkbtn); \ 117 } 118 119 #define PACK_SMALL_LABEL(box, label, str) \ 120 { \ 121 label = gtk_label_new(str); \ 122 gtk_widget_show(label); \ 123 gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0); \ 124 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); \ 125 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); \ 126 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); \ 127 gtkut_widget_set_small_font_size(label); \ 128 } 129 130 #define PACK_VSPACER(box, vbox, spacing) \ 131 { \ 132 vbox = gtk_vbox_new(FALSE, 0); \ 133 gtk_widget_show(vbox); \ 134 gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, TRUE, spacing); \ 135 } 136 137 #define SET_TOGGLE_SENSITIVITY(togglewid, targetwid) \ 138 { \ 139 gtk_widget_set_sensitive(targetwid, FALSE); \ 140 g_signal_connect(G_OBJECT(togglewid), "toggled", \ 141 G_CALLBACK(prefs_button_toggled), targetwid); \ 142 } 143 144 #define SET_TOGGLE_SENSITIVITY_REV(togglewid, targetwid) \ 145 { \ 146 gtk_widget_set_sensitive(targetwid, TRUE); \ 147 g_signal_connect(G_OBJECT(togglewid), "toggled", \ 148 G_CALLBACK(prefs_button_toggled_rev), targetwid); \ 149 } 150 151 void prefs_dialog_create (PrefsDialog *dialog); 152 void prefs_dialog_destroy (PrefsDialog *dialog); 153 154 void prefs_button_toggled (GtkToggleButton *toggle_btn, 155 GtkWidget *widget); 156 void prefs_button_toggled_rev (GtkToggleButton *toggle_btn, 157 GtkWidget *widget); 158 159 void prefs_register_ui (PrefParam *param, 160 PrefsUIData *ui_data); 161 162 void prefs_set_dialog (PrefParam *param); 163 void prefs_set_data_from_dialog (PrefParam *param); 164 void prefs_set_dialog_to_default(PrefParam *param); 165 166 void prefs_set_data_from_entry (PrefParam *pparam); 167 void prefs_set_entry (PrefParam *pparam); 168 void prefs_set_data_from_text (PrefParam *pparam); 169 void prefs_set_text (PrefParam *pparam); 170 void prefs_set_data_from_toggle (PrefParam *pparam); 171 void prefs_set_toggle (PrefParam *pparam); 172 void prefs_set_data_from_spinbtn(PrefParam *pparam); 173 void prefs_set_spinbtn (PrefParam *pparam); 174 void prefs_set_data_from_fontbtn(PrefParam *pparam); 175 void prefs_set_fontbtn (PrefParam *pparam); 176 void prefs_set_data_from_optmenu(PrefParam *pparam); 177 void prefs_set_optmenu (PrefParam *pparam); 178 179 gchar *prefs_get_escaped_str_from_text (GtkWidget *widget); 180 void prefs_set_escaped_str_to_text (GtkWidget *widget, 181 const gchar *str); 182 183 #endif /* __PREFS_UI_H__ */ 184