Corrected the changelog format.
[doldaconnect.git] / common / makegdesc
CommitLineData
d3372da9 1#!/usr/bin/perl
2
4dda7bfa
FT
3use Getopt::Long;
4use IO::File;
5
6GetOptions(\%args, "h=s") || exit 1;
7
d3372da9 8$tempvar = 0;
9
10sub printwidgets
11{
12 my($widget, $sl, $p, $sig, $cb, $data, $pf, $cpf, $mod, $key, @delayedlines);
13 $sl = $_[1];
14 $p = " " . (" " x $sl);
15 $cpf = $_[2];
16 @delayedlines = ();
17 foreach $widget (@{$_[0]})
18 {
19 if($widget->{"type"} eq "wnd")
20 {
21 print "${p}stack[$sl] = gtk_window_new(GTK_WINDOW_TOPLEVEL);\n";
22 if($options{"hasaccels"}) {
23 print "${p}gtk_window_add_accel_group(GTK_WINDOW(stack[$sl]), accel_group);\n";
24 }
25 if($widget->{"title"}) {
26 print "${p}gtk_window_set_title(GTK_WINDOW(stack[$sl]), \"" . $widget->{"title"} . "\");\n";
27 }
28 $pf = sub
29 {
30 my($widget, $p, $sl) = @_;
31 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
32 }
4e3cd270 33 } elsif($widget->{"type"} eq "assistant") {
34 print "${p}stack[$sl] = gtk_assistant_new();\n";
4b4f9fc7 35 if(defined($widget->{"title"})) {
36 print "${p}gtk_window_set_title(GTK_WINDOW(stack[$sl]), \"" . $widget->{"title"} . "\");\n";
37 }
4e3cd270 38 $pf = sub
39 {
40 my($widget, $p, $sl) = @_;
41 print "${p}gtk_assistant_append_page(GTK_ASSISTANT(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
42 if(defined($widget->{"title"})) {
43 print "${p}gtk_assistant_set_page_title(GTK_ASSISTANT(stack[" . ($sl - 1) . "]), stack[" . $sl . "], _(\"" . $widget->{"title"} . "\"));\n";
44 }
45 if(defined($widget->{"ptype"})) {
46 print "${p}gtk_assistant_set_page_type(GTK_ASSISTANT(stack[" . ($sl - 1) . "]), stack[" . $sl . "], GTK_ASSISTANT_PAGE_" . $widget->{"ptype"} . ");\n";
47 }
48 if(defined($widget->{"cmpl"})) {
ca2d6377 49 print "${p}gtk_assistant_set_page_complete(GTK_ASSISTANT(stack[" . ($sl - 1) . "]), stack[" . $sl . "], " . $widget->{"cmpl"} . ");\n";
4e3cd270 50 }
51 }
d3372da9 52 } elsif($widget->{"type"} =~ /[hv]box/) {
53 print "${p}stack[$sl] = gtk_" . $widget->{"type"} . "_new(";
54 print $widget->{"homo"}?"TRUE, ":"FALSE, ";
55 print $widget->{"spacing"} || "0";
56 print ");\n";
57 $pf = sub
58 {
59 my($widget, $p, $sl) = @_;
60 print "${p}gtk_box_pack_start(GTK_BOX(stack[" . ($sl - 1) . "]), stack[$sl], ";
61 print (($widget->{"expand"} || $widget->{"parent"}->{"dexpand"})?"TRUE, ":"FALSE, ");
62 print (($widget->{"fill"} || $widget->{"parent"}->{"dfill"})?"TRUE, ":"FALSE, ");
63 print $widget->{"pad"} || "0";
64 print ");\n";
65 }
99dd2b9f
FT
66 } elsif($widget->{"type"} =~ /([hv])btnbox/) {
67 print "${p}stack[$sl] = gtk_" . $1 . "button_box_new();\n";
68 if(defined($widget->{"layout"})) {
69 print "${p}gtk_button_box_set_layout(GTK_BUTTON_BOX(stack[$sl]), GTK_BUTTONBOX_" . $widget->{"layout"} . ");\n";
70 }
71 $pf = sub
72 {
73 my($widget, $p, $sl) = @_;
74 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
75 }
d3372da9 76 } elsif($widget->{"type"} eq "table") {
77 print "${p}stack[$sl] = gtk_table_new(" . $widget->{"rows"} . ", " . $widget->{"cols"};
78 print ", " . (($widget->{"homo"} eq "TRUE")?"TRUE":"FALSE");
79 print ");\n";
80 $pf = sub
81 {
82 my($widget, $p, $sl) = @_;
83 print "${p}gtk_table_attach(GTK_TABLE(stack[" . ($sl - 1) . "]), stack[$sl]";
84 print ", " . $widget->{"tx"};
85 print ", " . ($widget->{"tx"} + (defined($widget->{"tw"})?$widget->{"tw"}:1));
86 print ", " . $widget->{"ty"};
87 print ", " . ($widget->{"ty"} + (defined($widget->{"th"})?$widget->{"th"}:1));
88 if($widget->{"fill"} eq "y") {
89 $widget->{"fillx"} = "y";
90 $widget->{"filly"} = "y";
91 }
92 if($widget->{"shrink"} eq "y") {
93 $widget->{"shrinkx"} = "y";
94 $widget->{"shrinky"} = "y";
95 }
96 if($widget->{"expand"} eq "y") {
97 $widget->{"expandx"} = "y";
98 $widget->{"expandy"} = "y";
99 }
100 print ", 0";
101 print " | GTK_FILL" if $widget->{"fillx"} eq "y";
102 print " | GTK_SHRINK" if $widget->{"shrinkx"} eq "y";
103 print " | GTK_EXPAND" if $widget->{"expandx"} eq "y";
104 print ", 0";
105 print " | GTK_FILL" if $widget->{"filly"} eq "y";
106 print " | GTK_SHRINK" if $widget->{"shrinky"} eq "y";
107 print " | GTK_EXPAND" if $widget->{"expandy"} eq "y";
108 print ", " . (defined($widget->{"padx"})?$widget->{"padx"}:"0");
109 print ", " . (defined($widget->{"pady"})?$widget->{"pady"}:"0");
110 print ");\n";
111 }
112 } elsif($widget->{"type"} eq "btn") {
113 $widget->{"label"} || die("Can't have button without label\n");
114 print "${p}stack[$sl] = gtk_button_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
115 } elsif($widget->{"type"} eq "chk") {
116 $widget->{"label"} || die("Can't have check button without label\n");
117 print "${p}stack[$sl] = gtk_check_button_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
9b081644 118 } elsif($widget->{"type"} eq "radio") {
119 $widget->{"label"} || die("Can't have check button without label\n");
120 if(defined($widget->{"group"})) {
121 print "${p}stack[$sl] = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(" . $options{"prefix"} . $widget->{"group"} . "), _(\"" . $widget->{"label"} . "\"));\n";
122 } else {
123 print "${p}stack[$sl] = gtk_radio_button_new_with_mnemonic(NULL, _(\"" . $widget->{"label"} . "\"));\n";
124 }
d3372da9 125 } elsif($widget->{"type"} eq "sbtn") {
126 $widget->{"stock"} || die("Can't have button without stock\n");
127 print "${p}stack[$sl] = gtk_button_new_from_stock(GTK_STOCK_" . $widget->{"stock"} . ");\n";
128 } elsif($widget->{"type"} eq "simg") {
129 $widget->{"stock"} || die("Can't have image without stock\n");
130 $widget->{"size"} || die("Can't have image without size\n");
131 print "${p}stack[$sl] = gtk_image_new_from_stock(GTK_STOCK_" . $widget->{"stock"} . ", GTK_ICON_SIZE_" . $widget->{"size"} . ");\n";
a46a6c26
FT
132 } elsif($widget->{"type"} eq "xpmimg") {
133 $widget->{"data"} || die("Can't have XPM image without data\n");
134 print "${p}stack[$sl] = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_xpm_data((const char **)" . $widget->{"data"} . "));\n";
d3372da9 135 } elsif($widget->{"type"} eq "lbl") {
55c6add0 136 $widget->{"label"} || $widget->{"markup"} || die("Can't have label without label\n");
137 if($widget->{"label"}) {
138 print "${p}stack[$sl] = gtk_label_new(_(\"" . $widget->{"label"} . "\"));\n";
139 } else {
140 print "${p}stack[$sl] = gtk_label_new(NULL);\n";
bf9a1919 141 print "${p}gtk_label_set_markup(GTK_LABEL(stack[$sl]), _(\"" . $widget->{"markup"} . "\"));\n";
55c6add0 142 }
8345a394 143 if($widget->{"wrap"} eq "y") {
144 print "${p}gtk_label_set_line_wrap(GTK_LABEL(stack[$sl]), TRUE);\n";
145 }
d3372da9 146 } elsif($widget->{"type"} eq "mlbl") {
147 $widget->{"label"} || die("Can't have label without label\n");
148 print "${p}stack[$sl] = gtk_label_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
149 if(defined($widget->{"mwidget"}))
150 {
151 if($widget->{"var"} ne "y") {
152 $widget->{"var"} = "l";
153 }
154 if(!defined($widget->{"name"})) {
155 $widget->{"name"} = "temp" . $tempvar++;
156 }
157 $str = "gtk_label_set_mnemonic_widget(GTK_LABEL(";
158 if($widget->{"var"} eq "y") {
159 $str .= $options{"prefix"};
160 }
161 $str .= $widget->{"name"};
162 $str .= "), " . $options{"prefix"} . $widget->{"mwidget"} . ");";
163 push @delayedlines, ($str);
164 }
165 } elsif($widget->{"type"} eq "text") {
166 print "${p}stack[$sl] = gtk_entry_new();\n";
167 if($widget->{"default"}) {
168 print "${p}gtk_entry_set_text(GTK_ENTRY(stack[$sl]), \"" . $widget->{"default"} . "\");\n";
169 }
170 } elsif($widget->{"type"} eq "menubar") {
171 print "${p}stack[$sl] = gtk_menu_bar_new();\n";
172 $pf = sub
173 {
174 my($widget, $p, $sl) = @_;
175 print "${p}gtk_menu_shell_append(GTK_MENU_SHELL(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
176 }
177 } elsif($widget->{"type"} eq "menuitem") {
178 print "${p}stack[$sl] = gtk_menu_item_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
179 $pf = sub
180 {
181 my($widget, $p, $sl) = @_;
182 print "${p}gtk_menu_item_set_submenu(GTK_MENU_ITEM(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
183 }
184 } elsif($widget->{"type"} eq "smenuitem") {
185 print "${p}stack[$sl] = gtk_image_menu_item_new_from_stock(GTK_STOCK_" . $widget->{"stock"} . ", accel_group);\n";
186 $pf = sub
187 {
188 my($widget, $p, $sl) = @_;
189 print "${p}gtk_menu_item_set_submenu(GTK_MENU_ITEM(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
190 }
191 } elsif($widget->{"type"} eq "menusep") {
192 print "${p}stack[$sl] = gtk_separator_menu_item_new();\n";
193 } elsif($widget->{"type"} eq "menu") {
194 print "${p}stack[$sl] = gtk_menu_new();\n";
195 if($options{"hasaccels"}) {
196 print "${p}gtk_menu_set_accel_group(GTK_MENU(stack[$sl]), accel_group);\n";
197 }
198 $pf = sub
199 {
200 my($widget, $p, $sl) = @_;
201 print "${p}gtk_menu_shell_append(GTK_MENU_SHELL(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
202 };
203 $widget->{"noshow"} = 1;
204 } elsif($widget->{"type"} =~ /^[hv]paned$/) {
205 print "${p}stack[$sl] = gtk_" . $widget->{"type"} . "_new();\n";
206 $widget->{"cur"} = 1;
207 $pf = sub
208 {
209 my($widget, $p, $sl) = @_;
210 print "${p}gtk_paned_pack" . ($widget->{"parent"}->{"cur"}) . "(GTK_PANED(stack[" . ($sl - 1) . "]), stack[$sl]";
211 print ", " . ((index($widget->{"parent"}->{"resize"}, $widget->{"parent"}->{"cur"}) < 0)?"FALSE":"TRUE");
212 print ", " . ((index($widget->{"parent"}->{"shrink"}, $widget->{"parent"}->{"cur"}) < 0)?"FALSE":"TRUE");
213 print ");\n";
214 $widget->{"parent"}->{"cur"}++;
215 }
216 } elsif($widget->{"type"} eq "notebook") {
217 print "${p}stack[$sl] = gtk_notebook_new();\n";
bf565de3 218 if(defined($widget->{"pos"})) {
f44e64ee 219 print "${p}gtk_notebook_set_tab_pos(GTK_NOTEBOOK(stack[$sl]), GTK_POS_" . $widget->{"pos"} . ");\n";
bf565de3 220 }
d3372da9 221 $pf = sub
222 {
223 my($widget, $p, $sl) = @_;
224 print "${p}gtk_notebook_append_page(GTK_NOTEBOOK(stack[" . ($sl - 1) . "]), stack[$sl]";
225 print ", gtk_label_new_with_mnemonic(_(\"" . $widget->{"nblabel"} . "\"))";
226 print ");\n";
227 }
228 } elsif($widget->{"type"} eq "sw") {
229 print "${p}stack[$sl] = gtk_scrolled_window_new(NULL, NULL);\n";
230 $pf = sub
231 {
232 my($widget, $p, $sl) = @_;
233 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
234 }
235 } elsif($widget->{"type"} eq "frame") {
236 print "${p}stack[$sl] = gtk_frame_new(_(\"" . $widget->{"label"} . "\"));\n";
237 $pf = sub
238 {
239 my($widget, $p, $sl) = @_;
240 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
241 }
242 } elsif($widget->{"type"} eq "exp") {
243 print "${p}stack[$sl] = gtk_expander_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
244 $pf = sub
245 {
246 my($widget, $p, $sl) = @_;
247 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
248 }
9b081644 249 } elsif($widget->{"type"} eq "align") {
250 print "${p}stack[$sl] = gtk_alignment_new(";
251 if(defined($widget->{"xa"})) {
252 print $widget->{"xa"};
253 } else {
254 print "0.5";
255 }
b699c67f 256 print ", ";
9b081644 257 if(defined($widget->{"ya"})) {
258 print $widget->{"ya"};
259 } else {
260 print "0.5";
261 }
b699c67f 262 print ", ";
9b081644 263 if(defined($widget->{"xs"})) {
264 print $widget->{"xs"};
265 } else {
266 print "1.0";
267 }
b699c67f 268 print ", ";
9b081644 269 if(defined($widget->{"ys"})) {
270 print $widget->{"ys"};
271 } else {
272 print "1.0";
273 }
274 print ");\n";
275 $pf = sub
276 {
277 my($widget, $p, $sl) = @_;
278 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
279 }
d3372da9 280 } elsif($widget->{"type"} eq "treeview") {
281 print "${p}stack[$sl] = gtk_tree_view_new();\n";
282 if(defined($widget->{"hvis"})) {
283 print "${p}gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(stack[$sl]), " . $widget->{"hvis"} . ");\n";
284 }
285 if(defined($widget->{"rules"})) {
286 print "${p}gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(stack[$sl]), " . $widget->{"rules"} . ");\n";
287 }
288 if(defined($widget->{"searchcol"})) {
289 print "${p}gtk_tree_view_set_search_column(GTK_TREE_VIEW(stack[$sl]), " . $widget->{"searchcol"} . ");\n";
290 print "${p}gtk_tree_view_set_enable_search(GTK_TREE_VIEW(stack[$sl]), TRUE);\n";
291 }
292 $pf = sub
293 {
294 my($widget, $p, $sl) = @_;
295 print "${p}gtk_tree_view_append_column(GTK_TREE_VIEW(stack[" . ($sl - 1) . "]), column);\n";
296 if($widget->{"expander"} eq "y") {
297 print "${p}gtk_tree_view_set_expander_column(GTK_TREE_VIEW(stack[" . ($sl - 1) . "]), column);\n";
298 }
299 }
300 } elsif($widget->{"type"} eq "tvcol") {
301 if(!defined($widget->{"subwidgets"}))
302 {
303 print "${p}column = gtk_tree_view_column_new_with_attributes(";
304 print "_(\"" . $widget->{"title"} . "\")";
305 print ", gtk_cell_renderer_text_new()";
306 if(defined($widget->{"text"})) {
307 print ", \"text\", " . $widget->{"text"};
308 }
309 print ", NULL);\n";
310 } else {
311 print "${p}column = gtk_tree_view_column_new();\n";
312 print "${p}gtk_tree_view_column_set_title(column, _(\"" . $widget->{"title"} . "\"));\n";
313 }
314 if(defined($widget->{"sortcol"})) {
315 print "${p}gtk_tree_view_column_set_sort_column_id(column, " . $widget->{"sortcol"} . ");\n";
316 }
317 if(defined($widget->{"resizable"})) {
318 print "${p}gtk_tree_view_column_set_resizable(column, " . $widget->{"resizable"} . ");\n";
319 }
320 $widget->{"noshow"} = 1;
321 $pf = sub
322 {
323 }
324 } elsif($widget->{"type"} eq "textrend") {
325 print "${p}renderer = gtk_cell_renderer_text_new();\n";
326 print "${p}gtk_tree_view_column_pack_start(column, renderer, " . (defined($widget->{"expand"})?$widget->{"expand"}:"TRUE") . ");\n";
327 if(defined($widget->{"text"})) {
328 print "${p}gtk_tree_view_column_add_attribute(column, renderer, \"text\", " . $widget->{"text"} . ");\n";
329 }
330 if(defined($widget->{"func"})) {
331 print "${p}gtk_tree_view_column_set_cell_data_func(column, renderer, " . $widget->{"func"} . ", " . ($widget->{"funcdata"} || "NULL") . ", NULL);\n";
332 }
333 $widget->{"noshow"} = 1;
dbdb91fa
FT
334 } elsif($widget->{"type"} eq "progrend") {
335 print "${p}renderer = gtk_cell_renderer_progress_new();\n";
336 print "${p}gtk_tree_view_column_pack_start(column, renderer, " . (defined($widget->{"expand"})?$widget->{"expand"}:"FALSE") . ");\n";
337 if(defined($widget->{"value"})) {
338 print "${p}gtk_tree_view_column_add_attribute(column, renderer, \"value\", " . $widget->{"value"} . ");\n";
339 }
340 if(defined($widget->{"func"})) {
341 print "${p}gtk_tree_view_column_set_cell_data_func(column, renderer, " . $widget->{"func"} . ", " . ($widget->{"funcdata"} || "NULL") . ", NULL);\n";
342 }
343 $widget->{"noshow"} = 1;
d3372da9 344 } elsif($widget->{"type"} eq "custrend") {
345 print "${p}renderer = GTK_CELL_RENDERER(" . $widget->{"newfunc"} . "());\n";
346 print "${p}gtk_tree_view_column_pack_start(column, renderer, " . (defined($widget->{"expand"})?$widget->{"expand"}:"FALSE") . ");\n";
347 foreach $attr (keys %{$widget})
348 {
349 if($attr =~ /attr\((\S+)\)/)
350 {
351 print "${p}gtk_tree_view_column_add_attribute(column, renderer, \"" . $1 . "\", " . $widget->{$attr} . ");\n";
352 }
353 }
354 $widget->{"noshow"} = 1;
355 } elsif($widget->{"type"} eq "pixbufrend") {
356 print "${p}renderer = gtk_cell_renderer_pixbuf_new();\n";
357 print "${p}gtk_tree_view_column_pack_start(column, renderer, FALSE);\n";
358 if(defined($widget->{"stock_id"})) {
359 print "${p}gtk_tree_view_column_add_attribute(column, renderer, \"stock_id\", " . $widget->{"stock_id"} . ");\n";
360 }
361 $widget->{"noshow"} = 1;
362 } elsif($widget->{"type"} eq "textview") {
363 print "${p}stack[$sl] = gtk_text_view_new();\n";
364 if(defined($widget->{"editable"})) {
365 print "${p}gtk_text_view_set_editable(GTK_TEXT_VIEW(stack[$sl]), " . $widget->{"editable"} . ");\n";
366 }
b37ddeb6 367 } elsif($widget->{"type"} eq "pbar") {
368 print "${p}stack[$sl] = gtk_progress_bar_new();\n";
d3372da9 369 } elsif($widget->{"type"} eq "hr") {
370 print "${p}stack[$sl] = gtk_hseparator_new();\n";
371 } elsif($widget->{"type"} eq "sbar") {
372 print "${p}stack[$sl] = gtk_statusbar_new();\n";
373 if($widget->{"grip"} eq "n") {
374 print "${p}gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(stack[$sl]), FALSE);\n";
375 }
79138dda 376 } elsif($widget->{"type"} eq "filechooser") {
377 print "${p}stack[$sl] = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_" . (defined($widget->{"action"})?$widget->{"action"}:"OPEN") . ");\n";
d3372da9 378 } else {
379 print STDERR "Unknown widget: " . $widget->{"type"} ."\n";
380 }
381 if($widget->{"sensitive"}) {
382 print "${p}gtk_widget_set_sensitive(stack[$sl], " . $widget->{"sensitive"} . ");\n";
383 }
55c6add0 384 if($widget->{"rqsz"} =~ /(\d+)x(\d+)/) {
385 print "${p}gtk_widget_set_size_request(stack[$sl], $1, $2);\n";
386 }
387 if($widget->{"align"} =~ /([\d\.]+):([\d\.]+)/) {
388 print "${p}gtk_misc_set_alignment(GTK_MISC(stack[$sl]), $1, $2);\n";
389 }
bf9a1919 390 if($widget->{"wpad"} =~ /([\d\.]+):([\d\.]+)/) {
391 print "${p}gtk_misc_set_padding(GTK_MISC(stack[$sl]), $1, $2);\n";
392 }
d3372da9 393 if($widget->{"var"} eq "y") {
394 print $p . $options{"prefix"} . $widget->{"name"} . " = stack[$sl];\n";
395 }
396 if($widget->{"var"} eq "l") {
397 print $p . "GtkWidget *" . $widget->{"name"} . " = stack[$sl];\n";
398 }
399 if($widget->{"sig"})
400 {
401 while($widget->{"sig"} =~ /\G([\w_]+),?/g) {
402 print "${p}g_signal_connect(G_OBJECT(stack[$sl]), \"$1\", G_CALLBACK(cb_" . $options{"prefix"} . $widget->{"name"} . "_" . $1 . "), (gpointer)NULL);\n";
403 }
404 }
405 if($widget->{"accel"})
406 {
407 $mod = "";
408 while($widget->{"accel"} =~ /\G(\w+)\+/gc)
409 {
410 $mod .= " | " if($mod);
411 $mod = $mod . "GDK_" . $1 . "_MASK";
412 }
413 $mod || ($mod = "0");
414 $widget->{"accel"} =~ /\G(\w+)/g;
415 $key = $1;
416 print "${p}gtk_widget_add_accelerator(stack[$sl], \"activate\", accel_group, GDK_$key, $mod, GTK_ACCEL_VISIBLE);\n";
417 }
418 foreach $attr (keys %{$widget})
419 {
420 if($attr =~ /^sig\((\S+)\)/)
421 {
422 $sig = $1;
423 if($widget->{$attr} =~ /([^,]*),(.*)/)
424 {
425 $cb = $1;
426 $data = $2;
427 } else {
428 $cb = $widget->{$attr};
429 $data = "NULL";
430 }
34f4de8b 431 print "${p}g_signal_connect(G_OBJECT(stack[$sl]), \"$sig\", G_CALLBACK($cb), (gpointer)$data);\n";
d3372da9 432 }
433 }
434 if($widget->{"subwidgets"})
435 {
436 print "$p\n";
437 printwidgets($widget->{"subwidgets"}, $sl + 1, $pf);
438 }
439 if($sl > 0)
440 {
441 &$cpf($widget, $p, $sl);
442 if(!$widget->{"noshow"}) {
443 print "${p}gtk_widget_show(stack[$sl]);\n";
444 }
445 }
446 print "$p\n";
447 }
448 foreach $line (@delayedlines)
449 {
450 print $p . $line . "\n";
451 }
452}
453
4dda7bfa
FT
454sub printheader
455{
456 my($widget, $handle);
457 $handle = $_[1];
458 foreach $widget (@{$_[0]})
459 {
460 if($widget->{"var"})
461 {
462 $handle->print("extern GtkWidget *" . $options{"prefix"} . $widget->{"name"} .";\n");
463 }
464 printheader($widget->{"subwidgets"}, $handle) if($widget->{"subwidgets"});
465 }
466}
467
d3372da9 468sub printvars
469{
470 my($widget);
471 foreach $widget (@{$_[0]})
472 {
473 if($widget->{"var"})
474 {
475 print "GtkWidget *" . $options{"prefix"} . $widget->{"name"} .";\n";
476 }
477 printvars($widget->{"subwidgets"}) if($widget->{"subwidgets"});
478 }
479}
480
481sub dequote
482{
483 my($text);
484 ($text) = @_;
485 $text =~ s/([^\\]|^)\"/$1/g;
486 $text =~ s/\\(.)/$1/g;
487 return $text;
488}
489
490$rootwidgets = [];
491@estack = ($rootwidgets);
492@wstack = ();
493$curwidget = 0;
494$maxstack = 1;
495
496while(<>)
497{
498 chomp;
499 s/(^|\s+)\#.*$//;
500 s/^\s*//;
501 if(/^;\s*(\w+)\s*:\s*(\w.*)/)
502 {
503 $options{$1} = $2;
504 } elsif(/^([:\$])\s*(\w+)/g) {
505 $curwidget = {"type" => $2};
506 push @{$estack[0]}, $curwidget;
507 if((scalar @wstack) > 0) {
508 $curwidget->{"parent"} = $wstack[0];
509 }
510 if($1 eq ":")
511 {
512 unshift @estack, ($curwidget->{"subwidgets"} = []);
513 unshift @wstack, $curwidget;
514 }
515 $maxstack = (scalar @estack) if((scalar @estack) > $maxstack);
516 while(/\G\s*(\S+)\s*:\s*((\w+|\"([^\\\"]+|\\.)*([^\\]|)\"|\\.)+)/g)
517 {
518 $curwidget->{$1} = dequote($2);
519 }
520 } elsif(/^%\s*(\S+)\s*:\s*((\w+|\"([^\\\"]+|\\.)*([^\\]|)\"|\\.)+)/) {
521 $curwidget || die("No current widget\n");
522 $curwidget->{$1} = dequote($2);
523 } elsif(/^end/) {
524 shift @estack;
525 shift @wstack;
526 $curwidget = $wstack[0] if((scalar @wstack) > 0);
527 } elsif(!$_) {
528 } else {
529 print STDERR "Invalid construct: $_\n";
530 }
531}
532
4dda7bfa
FT
533if($args{"h"})
534{
535 $hfile = IO::File->new($args{"h"}, "w") || die;
1627115d 536 $hfile->print("GtkWidget *create_" . $options{"prefix"} . "wnd(void);\n");
4dda7bfa
FT
537 printheader $rootwidgets, $hfile;
538 $hfile->close();
539}
540
d3372da9 541printvars $rootwidgets;
542print "\n";
543print "GtkWidget *create_" . $options{"prefix"} . "wnd(void)\n";
544print "{\n";
545print " GtkWidget *stack[$maxstack];\n";
546print " GtkAccelGroup *accel_group;\n" if $options{"hasaccels"};
547print " GtkTreeViewColumn *column;\n" if $options{"hascolumns"};
548print " GtkCellRenderer *renderer;\n" if $options{"hasrenderers"};
549print " \n";
550print " accel_group = gtk_accel_group_new();\n" if $options{"hasaccels"};
551printwidgets $rootwidgets, 0;
552print " return(stack[0]);\n";
553print "}\n";