/[james]/archive/guilib/dialog_gtk.c
ViewVC logotype

Annotation of /archive/guilib/dialog_gtk.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (hide annotations) (download) (as text)
Mon Feb 10 22:56:40 2003 UTC (21 years, 8 months ago) by james
File MIME type: text/x-csrc
File size: 6308 byte(s)
Initial import.

1 james 16 /*
2     * dialog_gtk.c -- dialog creation, GTK
3     */
4    
5     #include "gui.h"
6    
7     /****************************************************************************************/
8     /* Dialog creation functions */
9     /****************************************************************************************/
10    
11     #define DIALOG_ICON_CHUNK 10
12    
13     static gui_window_id dialog_id = -1;
14     static GtkWidget *dialog;
15     static GtkWidget *table;
16     static unsigned int table_rows;
17    
18    
19     /*
20     * gui_start_dialog -- start creating a dialogue window
21     *
22     * => title -- window title
23     *
24     * <= nothing
25     */
26    
27     void gui_start_dialog(char *title, unsigned int width,
28     bool close, const char *help)
29     {
30     assert(dialog_id == -1);
31    
32     #ifdef DEBUG
33     printf("gui_start_dialog: title = '%s'\n", title);
34     fflush(stdout);
35     #endif
36    
37     dialog_id = gui_get_free_window_id();
38    
39     table = gtk_table_new(1, 2, FALSE);
40     dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
41    
42     gtk_window_set_title(GTK_WINDOW (dialog), title);
43     gtk_container_add(GTK_CONTAINER (dialog), table);
44    
45     gui_window_list[dialog_id].title = title;
46     gui_window_list[dialog_id].help = help;
47    
48     table_rows = 0;
49     }
50    
51    
52     /*
53     * gui_create_dialog -- finish creating and open a dialogue window
54     *
55     * => nothing
56     *
57     * <= window id
58     */
59    
60     gui_window_id gui_create_dialog()
61     {
62     gui_window_id id = dialog_id;
63    
64     assert(dialog_id != -1);
65    
66     gui_window_list[dialog_id].used = DIALOG;
67     gui_window_list[dialog_id].handle = dialog;
68     gui_window_list[dialog_id].close_fn = gui_remove_window;
69     gui_window_list[dialog_id].redraw_fn = NULL;
70     gui_window_list[dialog_id].click_fn = NULL;
71     gui_window_list[dialog_id].resize_fn = NULL;
72     gui_window_list[dialog_id].key_fn = NULL;
73     gui_window_list[dialog_id].input_fn = NULL;
74     gui_window_list[dialog_id].menu_fn = NULL;
75     gui_window_list[dialog_id].width = 0;
76     gui_window_list[dialog_id].height = 0;
77     gui_window_list[dialog_id].menu = NULL;
78    
79     gtk_widget_show(table);
80     gtk_widget_show(dialog);
81    
82     dialog_id = -1;
83    
84     #ifdef DEBUG
85     printf("gui_create_dialog: id = 0x%x, handle = 0x%x\n", dialog_id,
86     (unsigned int) dialog);
87     fflush(stdout);
88     #endif
89    
90     return id;
91     }
92    
93    
94     /*
95     * gui_create_label -- create a text label
96     *
97     * => text -- label text
98     *
99     * <= nothing
100     */
101    
102     void gui_create_label(char *text, const char *help)
103     {
104     GtkWidget *label;
105    
106     assert(dialog_id != -1);
107    
108     #ifdef DEBUG
109     printf("gui_create_label: text = '%s'\n", text);
110     fflush(stdout);
111     #endif
112    
113     label = gtk_label_new(text);
114     gtk_widget_show(label);
115    
116     gtk_table_resize(table, ++table_rows, 2);
117     gtk_table_attach(table, label, 0, 2, table_rows - 1, table_rows,
118     GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
119     }
120    
121    
122     /*
123     * gui_create_text_box -- create a labelled writeable text box
124     *
125     * => text -- label text
126     * mask -- entry mask (eg. '0-9' etc)
127     *
128     * <= gadget id
129     * 0 if an error occurred
130     */
131    
132     gui_gadget_id gui_create_text_box(char *text, const char *mask, const char *help)
133     {
134     GtkWidget *label;
135     GtkWidget *entry;
136    
137     assert(dialog_id != -1);
138    
139     #ifdef DEBUG
140     printf("gui_create_text_box: text = '%s', mask = '%s'\n", text, mask);
141     fflush(stdout);
142     #endif
143    
144     label = gtk_label_new(text);
145     entry = gtk_entry_new();
146    
147     gtk_label_set_justify(label, GTK_JUSTIFY_RIGHT);
148    
149     gtk_table_resize(table, ++table_rows, 2);
150     gtk_table_attach(table, label, 0, 1, table_rows - 1, table_rows,
151     GTK_EXPAND | GTK_FILL, 0, 0, 0);
152     gtk_table_attach(table, entry, 1, 2, table_rows - 1, table_rows,
153     GTK_EXPAND | GTK_FILL, 0, 0, 0);
154    
155     gtk_widget_show(label);
156     gtk_widget_show(entry);
157    
158     return entry;
159     }
160    
161    
162     /*
163     * gui_create_text_box -- create a labelled display text box
164     *
165     * => text -- label text
166     * value -- display text
167     *
168     * <= gadget id
169     * 0 if an error occurred
170     */
171    
172     gui_gadget_id gui_create_display_box(char *text, char *value, const char *help)
173     {
174     GtkWidget *label;
175     GtkWidget *display;
176    
177     assert(dialog_id != -1);
178    
179     #ifdef DEBUG
180     printf("gui_create_display_box: text = '%s', value = '%s'\n", text, value);
181     fflush(stdout);
182     #endif
183    
184     label = gtk_label_new(text);
185     display = gtk_label_new(value);
186    
187     gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_RIGHT);
188     gtk_label_set_justify(GTK_LABEL(display), GTK_JUSTIFY_LEFT);
189    
190     gtk_table_resize(GTK_TABLE(table), ++table_rows, 2);
191     gtk_table_attach(GTK_TABLE(table), label, 0, 1, table_rows - 1, table_rows,
192     GTK_EXPAND | GTK_FILL, 0, 0, 0);
193     gtk_table_attach(GTK_TABLE(table), display, 1, 2, table_rows - 1, table_rows,
194     GTK_EXPAND | GTK_FILL, 0, 0, 0);
195    
196     gtk_widget_show(label);
197     gtk_widget_show(display);
198    
199     return display;
200     }
201    
202    
203     /*
204     * gui_create_button -- create an action button
205     *
206     * => text -- button text
207     * click_fn -- function called when button is clicked
208     *
209     * <= nothing
210     */
211    
212     void gui_create_button(char *text, void (*click_fn)(), const char *help)
213     {
214     /* unsigned const int border = (dialog_x == dialog_block->extent.x1 ? 8 : 0);
215     *
216     * assert(dialog_id != -1);
217     *
218     * #ifdef DEBUG
219     * printf("gui_create_button: text = '%s'\n", text);
220     * fflush(stdout);
221     * #endif
222     *
223     * ensure_dialog_space();
224     *
225     * if (dialog_x == dialog_block->extent.x1) dialog_y += 84;
226     *
227     * dialog_block->icons[dialog_icons].extent.x0 = dialog_x - 140 - border * 2;
228     * dialog_block->icons[dialog_icons].extent.y0 = -(dialog_y - 16 + border);
229     * dialog_block->icons[dialog_icons].extent.x1 = dialog_x - 8;
230     * dialog_block->icons[dialog_icons].extent.y1 = -(dialog_y - 68 - border);
231     * dialog_block->icons[dialog_icons].flags = wimp_ICON_TEXT | wimp_ICON_HCENTRED |
232     * wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_BORDER | wimp_ICON_FILLED |
233     * wimp_BUTTON_CLICK << wimp_ICON_BUTTON_TYPE_SHIFT |
234     * wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT |
235     * wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT;
236     * dialog_block->icons[dialog_icons].data.indirected_text.text = text;
237     * dialog_block->icons[dialog_icons].data.indirected_text.validation =
238     * (dialog_x == dialog_block->extent.x1 ? "r6,3" : "r5,3");
239     *
240     * dialog_icon[dialog_icons].type = ICON_ACTION;
241     * dialog_icon[dialog_icons].click_fn = click_fn;
242     * dialog_icon[dialog_icons].help = help;
243     *
244     * dialog_icons++;
245     * dialog_x -= 140 + border * 2;
246     */
247     }

  ViewVC Help
Powered by ViewVC 1.1.26