aboutsummaryrefslogtreecommitdiff
path: root/src/prefs_ui.h
blob: f0eadeb68300ac21b1f1b8ced9f784afea1c4198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
 * Copyright (C) 1999-2006 Hiroyuki Yamamoto
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __PREFS_UI_H__
#define __PREFS_UI_H__

#include <glib.h>
#include <gtk/gtkwidget.h>
#include <gtk/gtksignal.h>
#include <gtk/gtklabel.h>
#include <gtk/gtknotebook.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkvbox.h>
#include <stdio.h>

typedef struct _PrefsDialog	PrefsDialog;
typedef struct _PrefsUIData	PrefsUIData;

#include "prefs.h"
#include "gtkutils.h"

#define VSPACING		10
#define VSPACING_NARROW		4
#define VSPACING_NARROW_2	2
#define VBOX_BORDER		12
#define DEFAULT_ENTRY_WIDTH	80

struct _PrefsUIData
{
	gchar *name;
	GtkWidget **widget;
	DataSetFunc data_set_func;
	WidgetSetFunc widget_set_func;
};

struct _PrefsDialog 
{
	GtkWidget *window;
	GtkWidget *notebook;

	GtkWidget *confirm_area;
	GtkWidget *ok_btn;
	GtkWidget *cancel_btn;
	GtkWidget *apply_btn;
};

#define SET_NOTEBOOK_LABEL(notebook, str, page_num) \
{ \
	GtkWidget *label; \
 \
	label = gtk_label_new (str); \
	gtk_widget_show (label); \
	gtk_notebook_set_tab_label \
		(GTK_NOTEBOOK (notebook), \
		 gtk_notebook_get_nth_page \
			(GTK_NOTEBOOK (notebook), page_num), \
		 label); \
}

#define APPEND_SUB_NOTEBOOK(notebook, vbox, str) \
{ \
	GtkWidget *label; \
 \
	label = gtk_label_new(str); \
	gtk_widget_show(label); \
	vbox = gtk_vbox_new(FALSE, VSPACING); \
	gtk_widget_show(vbox); \
	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, label); \
	gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER); \
}

#define PACK_CHECK_BUTTON(box, chkbtn, label) \
{ \
	chkbtn = gtk_check_button_new_with_label(label); \
	gtk_widget_show(chkbtn); \
	gtk_box_pack_start(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \
}

#define PACK_END_CHECK_BUTTON(box, chkbtn, label) \
{ \
	chkbtn = gtk_check_button_new_with_label(label); \
	gtk_widget_show(chkbtn); \
	gtk_box_pack_end(GTK_BOX(box), chkbtn, FALSE, TRUE, 0); \
}

#define PACK_FRAME(box, frame, label) \
{ \
	frame = gtk_frame_new(label); \
	gtk_widget_show(frame); \
	gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0); \
	gtk_frame_set_label_align(GTK_FRAME(frame), 0.01, 0.5); \
}

#define PACK_FRAME_WITH_CHECK_BUTTON(box, frame, chkbtn, label) \
{ \
	chkbtn = gtk_check_button_new_with_label(label); \
	gtk_widget_show(chkbtn); \
	PACK_FRAME(box, frame, NULL); \
	gtk_frame_set_label_widget(GTK_FRAME(frame), chkbtn); \
}

#define PACK_SMALL_LABEL(box, label, str) \
{ \
	label = gtk_label_new(str); \
	gtk_widget_show(label); \
	gtk_box_pack_start(GTK_BOX(box), label, FALSE, TRUE, 0); \
	gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); \
	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); \
	gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); \
	gtkut_widget_set_small_font_size(label); \
}

#define PACK_VSPACER(box, vbox, spacing) \
{ \
	vbox = gtk_vbox_new(FALSE, 0); \
	gtk_widget_show(vbox); \
	gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, TRUE, spacing); \
}

#define SET_TOGGLE_SENSITIVITY(togglewid, targetwid) \
{ \
	gtk_widget_set_sensitive(targetwid, FALSE); \
	g_signal_connect(G_OBJECT(togglewid), "toggled", \
			 G_CALLBACK(prefs_button_toggled), targetwid); \
}

#define SET_TOGGLE_SENSITIVITY_REV(togglewid, targetwid) \
{ \
	gtk_widget_set_sensitive(targetwid, TRUE); \
	g_signal_connect(G_OBJECT(togglewid), "toggled", \
			 G_CALLBACK(prefs_button_toggled_rev), targetwid); \
}

void prefs_dialog_create	(PrefsDialog	*dialog);
void prefs_dialog_destroy	(PrefsDialog	*dialog);

void prefs_button_toggled	(GtkToggleButton	*toggle_btn,
				 GtkWidget		*widget);
void prefs_button_toggled_rev	(GtkToggleButton	*toggle_btn,
				 GtkWidget		*widget);

void prefs_register_ui		(PrefParam	*param,
				 PrefsUIData	*ui_data);

void prefs_set_dialog		(PrefParam	*param);
void prefs_set_data_from_dialog	(PrefParam	*param);
void prefs_set_dialog_to_default(PrefParam	*param);

void prefs_set_data_from_entry	(PrefParam	*pparam);
void prefs_set_entry		(PrefParam	*pparam);
void prefs_set_data_from_text	(PrefParam	*pparam);
void prefs_set_text		(PrefParam	*pparam);
void prefs_set_data_from_toggle	(PrefParam	*pparam);
void prefs_set_toggle		(PrefParam	*pparam);
void prefs_set_data_from_spinbtn(PrefParam	*pparam);
void prefs_set_spinbtn		(PrefParam	*pparam);
void prefs_set_data_from_fontbtn(PrefParam	*pparam);
void prefs_set_fontbtn		(PrefParam	*pparam);
void prefs_set_data_from_optmenu(PrefParam	*pparam);
void prefs_set_optmenu		(PrefParam	*pparam);

#endif /* __PREFS_UI_H__ */