7 my($widget, $sl, $p, $sig, $cb, $data, $pf, $cpf, $mod, $key, @delayedlines);
9 $p = " " . (" " x $sl);
12 foreach $widget (@{$_[0]})
14 if($widget->{"type"} eq "wnd")
16 print "${p}stack[$sl] = gtk_window_new(GTK_WINDOW_TOPLEVEL);\n";
17 if($options{"hasaccels"}) {
18 print "${p}gtk_window_add_accel_group(GTK_WINDOW(stack[$sl]), accel_group);\n";
20 if($widget->{"title"}) {
21 print "${p}gtk_window_set_title(GTK_WINDOW(stack[$sl]), \"" . $widget->{"title"} . "\");\n";
25 my($widget, $p, $sl) = @_;
26 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
28 } elsif($widget->{"type"} =~ /[hv]box/) {
29 print "${p}stack[$sl] = gtk_" . $widget->{"type"} . "_new(";
30 print $widget->{"homo"}?"TRUE, ":"FALSE, ";
31 print $widget->{"spacing"} || "0";
35 my($widget, $p, $sl) = @_;
36 print "${p}gtk_box_pack_start(GTK_BOX(stack[" . ($sl - 1) . "]), stack[$sl], ";
37 print (($widget->{"expand"} || $widget->{"parent"}->{"dexpand"})?"TRUE, ":"FALSE, ");
38 print (($widget->{"fill"} || $widget->{"parent"}->{"dfill"})?"TRUE, ":"FALSE, ");
39 print $widget->{"pad"} || "0";
42 } elsif($widget->{"type"} eq "table") {
43 print "${p}stack[$sl] = gtk_table_new(" . $widget->{"rows"} . ", " . $widget->{"cols"};
44 print ", " . (($widget->{"homo"} eq "TRUE")?"TRUE":"FALSE");
48 my($widget, $p, $sl) = @_;
49 print "${p}gtk_table_attach(GTK_TABLE(stack[" . ($sl - 1) . "]), stack[$sl]";
50 print ", " . $widget->{"tx"};
51 print ", " . ($widget->{"tx"} + (defined($widget->{"tw"})?$widget->{"tw"}:1));
52 print ", " . $widget->{"ty"};
53 print ", " . ($widget->{"ty"} + (defined($widget->{"th"})?$widget->{"th"}:1));
54 if($widget->{"fill"} eq "y") {
55 $widget->{"fillx"} = "y";
56 $widget->{"filly"} = "y";
58 if($widget->{"shrink"} eq "y") {
59 $widget->{"shrinkx"} = "y";
60 $widget->{"shrinky"} = "y";
62 if($widget->{"expand"} eq "y") {
63 $widget->{"expandx"} = "y";
64 $widget->{"expandy"} = "y";
67 print " | GTK_FILL" if $widget->{"fillx"} eq "y";
68 print " | GTK_SHRINK" if $widget->{"shrinkx"} eq "y";
69 print " | GTK_EXPAND" if $widget->{"expandx"} eq "y";
71 print " | GTK_FILL" if $widget->{"filly"} eq "y";
72 print " | GTK_SHRINK" if $widget->{"shrinky"} eq "y";
73 print " | GTK_EXPAND" if $widget->{"expandy"} eq "y";
74 print ", " . (defined($widget->{"padx"})?$widget->{"padx"}:"0");
75 print ", " . (defined($widget->{"pady"})?$widget->{"pady"}:"0");
78 } elsif($widget->{"type"} eq "btn") {
79 $widget->{"label"} || die("Can't have button without label\n");
80 print "${p}stack[$sl] = gtk_button_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
81 } elsif($widget->{"type"} eq "chk") {
82 $widget->{"label"} || die("Can't have check button without label\n");
83 print "${p}stack[$sl] = gtk_check_button_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
84 } elsif($widget->{"type"} eq "sbtn") {
85 $widget->{"stock"} || die("Can't have button without stock\n");
86 print "${p}stack[$sl] = gtk_button_new_from_stock(GTK_STOCK_" . $widget->{"stock"} . ");\n";
87 } elsif($widget->{"type"} eq "simg") {
88 $widget->{"stock"} || die("Can't have image without stock\n");
89 $widget->{"size"} || die("Can't have image without size\n");
90 print "${p}stack[$sl] = gtk_image_new_from_stock(GTK_STOCK_" . $widget->{"stock"} . ", GTK_ICON_SIZE_" . $widget->{"size"} . ");\n";
91 } elsif($widget->{"type"} eq "lbl") {
92 $widget->{"label"} || die("Can't have label without label\n");
93 print "${p}stack[$sl] = gtk_label_new(_(\"" . $widget->{"label"} . "\"));\n";
94 } elsif($widget->{"type"} eq "mlbl") {
95 $widget->{"label"} || die("Can't have label without label\n");
96 print "${p}stack[$sl] = gtk_label_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
97 if(defined($widget->{"mwidget"}))
99 if($widget->{"var"} ne "y") {
100 $widget->{"var"} = "l";
102 if(!defined($widget->{"name"})) {
103 $widget->{"name"} = "temp" . $tempvar++;
105 $str = "gtk_label_set_mnemonic_widget(GTK_LABEL(";
106 if($widget->{"var"} eq "y") {
107 $str .= $options{"prefix"};
109 $str .= $widget->{"name"};
110 $str .= "), " . $options{"prefix"} . $widget->{"mwidget"} . ");";
111 push @delayedlines, ($str);
113 } elsif($widget->{"type"} eq "text") {
114 print "${p}stack[$sl] = gtk_entry_new();\n";
115 if($widget->{"default"}) {
116 print "${p}gtk_entry_set_text(GTK_ENTRY(stack[$sl]), \"" . $widget->{"default"} . "\");\n";
118 } elsif($widget->{"type"} eq "menubar") {
119 print "${p}stack[$sl] = gtk_menu_bar_new();\n";
122 my($widget, $p, $sl) = @_;
123 print "${p}gtk_menu_shell_append(GTK_MENU_SHELL(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
125 } elsif($widget->{"type"} eq "menuitem") {
126 print "${p}stack[$sl] = gtk_menu_item_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
129 my($widget, $p, $sl) = @_;
130 print "${p}gtk_menu_item_set_submenu(GTK_MENU_ITEM(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
132 } elsif($widget->{"type"} eq "smenuitem") {
133 print "${p}stack[$sl] = gtk_image_menu_item_new_from_stock(GTK_STOCK_" . $widget->{"stock"} . ", accel_group);\n";
136 my($widget, $p, $sl) = @_;
137 print "${p}gtk_menu_item_set_submenu(GTK_MENU_ITEM(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
139 } elsif($widget->{"type"} eq "menusep") {
140 print "${p}stack[$sl] = gtk_separator_menu_item_new();\n";
141 } elsif($widget->{"type"} eq "menu") {
142 print "${p}stack[$sl] = gtk_menu_new();\n";
143 if($options{"hasaccels"}) {
144 print "${p}gtk_menu_set_accel_group(GTK_MENU(stack[$sl]), accel_group);\n";
148 my($widget, $p, $sl) = @_;
149 print "${p}gtk_menu_shell_append(GTK_MENU_SHELL(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
151 $widget->{"noshow"} = 1;
152 } elsif($widget->{"type"} =~ /^[hv]paned$/) {
153 print "${p}stack[$sl] = gtk_" . $widget->{"type"} . "_new();\n";
154 $widget->{"cur"} = 1;
157 my($widget, $p, $sl) = @_;
158 print "${p}gtk_paned_pack" . ($widget->{"parent"}->{"cur"}) . "(GTK_PANED(stack[" . ($sl - 1) . "]), stack[$sl]";
159 print ", " . ((index($widget->{"parent"}->{"resize"}, $widget->{"parent"}->{"cur"}) < 0)?"FALSE":"TRUE");
160 print ", " . ((index($widget->{"parent"}->{"shrink"}, $widget->{"parent"}->{"cur"}) < 0)?"FALSE":"TRUE");
162 $widget->{"parent"}->{"cur"}++;
164 } elsif($widget->{"type"} eq "notebook") {
165 print "${p}stack[$sl] = gtk_notebook_new();\n";
168 my($widget, $p, $sl) = @_;
169 print "${p}gtk_notebook_append_page(GTK_NOTEBOOK(stack[" . ($sl - 1) . "]), stack[$sl]";
170 print ", gtk_label_new_with_mnemonic(_(\"" . $widget->{"nblabel"} . "\"))";
173 } elsif($widget->{"type"} eq "sw") {
174 print "${p}stack[$sl] = gtk_scrolled_window_new(NULL, NULL);\n";
177 my($widget, $p, $sl) = @_;
178 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
180 } elsif($widget->{"type"} eq "frame") {
181 print "${p}stack[$sl] = gtk_frame_new(_(\"" . $widget->{"label"} . "\"));\n";
184 my($widget, $p, $sl) = @_;
185 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
187 } elsif($widget->{"type"} eq "exp") {
188 print "${p}stack[$sl] = gtk_expander_new_with_mnemonic(_(\"" . $widget->{"label"} . "\"));\n";
191 my($widget, $p, $sl) = @_;
192 print "${p}gtk_container_add(GTK_CONTAINER(stack[" . ($sl - 1) . "]), stack[$sl]);\n";
194 } elsif($widget->{"type"} eq "treeview") {
195 print "${p}stack[$sl] = gtk_tree_view_new();\n";
196 if(defined($widget->{"hvis"})) {
197 print "${p}gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(stack[$sl]), " . $widget->{"hvis"} . ");\n";
199 if(defined($widget->{"rules"})) {
200 print "${p}gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(stack[$sl]), " . $widget->{"rules"} . ");\n";
202 if(defined($widget->{"searchcol"})) {
203 print "${p}gtk_tree_view_set_search_column(GTK_TREE_VIEW(stack[$sl]), " . $widget->{"searchcol"} . ");\n";
204 print "${p}gtk_tree_view_set_enable_search(GTK_TREE_VIEW(stack[$sl]), TRUE);\n";
208 my($widget, $p, $sl) = @_;
209 print "${p}gtk_tree_view_append_column(GTK_TREE_VIEW(stack[" . ($sl - 1) . "]), column);\n";
210 if($widget->{"expander"} eq "y") {
211 print "${p}gtk_tree_view_set_expander_column(GTK_TREE_VIEW(stack[" . ($sl - 1) . "]), column);\n";
214 } elsif($widget->{"type"} eq "tvcol") {
215 if(!defined($widget->{"subwidgets"}))
217 print "${p}column = gtk_tree_view_column_new_with_attributes(";
218 print "_(\"" . $widget->{"title"} . "\")";
219 print ", gtk_cell_renderer_text_new()";
220 if(defined($widget->{"text"})) {
221 print ", \"text\", " . $widget->{"text"};
225 print "${p}column = gtk_tree_view_column_new();\n";
226 print "${p}gtk_tree_view_column_set_title(column, _(\"" . $widget->{"title"} . "\"));\n";
228 if(defined($widget->{"sortcol"})) {
229 print "${p}gtk_tree_view_column_set_sort_column_id(column, " . $widget->{"sortcol"} . ");\n";
231 if(defined($widget->{"resizable"})) {
232 print "${p}gtk_tree_view_column_set_resizable(column, " . $widget->{"resizable"} . ");\n";
234 $widget->{"noshow"} = 1;
238 } elsif($widget->{"type"} eq "textrend") {
239 print "${p}renderer = gtk_cell_renderer_text_new();\n";
240 print "${p}gtk_tree_view_column_pack_start(column, renderer, " . (defined($widget->{"expand"})?$widget->{"expand"}:"TRUE") . ");\n";
241 if(defined($widget->{"text"})) {
242 print "${p}gtk_tree_view_column_add_attribute(column, renderer, \"text\", " . $widget->{"text"} . ");\n";
244 if(defined($widget->{"func"})) {
245 print "${p}gtk_tree_view_column_set_cell_data_func(column, renderer, " . $widget->{"func"} . ", " . ($widget->{"funcdata"} || "NULL") . ", NULL);\n";
247 $widget->{"noshow"} = 1;
248 } elsif($widget->{"type"} eq "custrend") {
249 print "${p}renderer = GTK_CELL_RENDERER(" . $widget->{"newfunc"} . "());\n";
250 print "${p}gtk_tree_view_column_pack_start(column, renderer, " . (defined($widget->{"expand"})?$widget->{"expand"}:"FALSE") . ");\n";
251 foreach $attr (keys %{$widget})
253 if($attr =~ /attr\((\S+)\)/)
255 print "${p}gtk_tree_view_column_add_attribute(column, renderer, \"" . $1 . "\", " . $widget->{$attr} . ");\n";
258 $widget->{"noshow"} = 1;
259 } elsif($widget->{"type"} eq "pixbufrend") {
260 print "${p}renderer = gtk_cell_renderer_pixbuf_new();\n";
261 print "${p}gtk_tree_view_column_pack_start(column, renderer, FALSE);\n";
262 if(defined($widget->{"stock_id"})) {
263 print "${p}gtk_tree_view_column_add_attribute(column, renderer, \"stock_id\", " . $widget->{"stock_id"} . ");\n";
265 $widget->{"noshow"} = 1;
266 } elsif($widget->{"type"} eq "textview") {
267 print "${p}stack[$sl] = gtk_text_view_new();\n";
268 if(defined($widget->{"editable"})) {
269 print "${p}gtk_text_view_set_editable(GTK_TEXT_VIEW(stack[$sl]), " . $widget->{"editable"} . ");\n";
271 } elsif($widget->{"type"} eq "hr") {
272 print "${p}stack[$sl] = gtk_hseparator_new();\n";
273 } elsif($widget->{"type"} eq "sbar") {
274 print "${p}stack[$sl] = gtk_statusbar_new();\n";
275 if($widget->{"grip"} eq "n") {
276 print "${p}gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(stack[$sl]), FALSE);\n";
279 print STDERR "Unknown widget: " . $widget->{"type"} ."\n";
281 if($widget->{"sensitive"}) {
282 print "${p}gtk_widget_set_sensitive(stack[$sl], " . $widget->{"sensitive"} . ");\n";
284 if($widget->{"var"} eq "y") {
285 print $p . $options{"prefix"} . $widget->{"name"} . " = stack[$sl];\n";
287 if($widget->{"var"} eq "l") {
288 print $p . "GtkWidget *" . $widget->{"name"} . " = stack[$sl];\n";
292 while($widget->{"sig"} =~ /\G([\w_]+),?/g) {
293 print "${p}g_signal_connect(G_OBJECT(stack[$sl]), \"$1\", G_CALLBACK(cb_" . $options{"prefix"} . $widget->{"name"} . "_" . $1 . "), (gpointer)NULL);\n";
296 if($widget->{"accel"})
299 while($widget->{"accel"} =~ /\G(\w+)\+/gc)
301 $mod .= " | " if($mod);
302 $mod = $mod . "GDK_" . $1 . "_MASK";
304 $mod || ($mod = "0");
305 $widget->{"accel"} =~ /\G(\w+)/g;
307 print "${p}gtk_widget_add_accelerator(stack[$sl], \"activate\", accel_group, GDK_$key, $mod, GTK_ACCEL_VISIBLE);\n";
309 foreach $attr (keys %{$widget})
311 if($attr =~ /^sig\((\S+)\)/)
314 if($widget->{$attr} =~ /([^,]*),(.*)/)
319 $cb = $widget->{$attr};
322 print "${p}g_signal_connect(G_OBJECT(stack[$sl]), \"$1\", G_CALLBACK($cb), (gpointer)$data);\n";
325 if($widget->{"subwidgets"})
328 printwidgets($widget->{"subwidgets"}, $sl + 1, $pf);
332 &$cpf($widget, $p, $sl);
333 if(!$widget->{"noshow"}) {
334 print "${p}gtk_widget_show(stack[$sl]);\n";
339 foreach $line (@delayedlines)
341 print $p . $line . "\n";
348 foreach $widget (@{$_[0]})
352 print "GtkWidget *" . $options{"prefix"} . $widget->{"name"} .";\n";
354 printvars($widget->{"subwidgets"}) if($widget->{"subwidgets"});
362 $text =~ s/([^\\]|^)\"/$1/g;
363 $text =~ s/\\(.)/$1/g;
368 @estack = ($rootwidgets);
378 if(/^;\s*(\w+)\s*:\s*(\w.*)/)
381 } elsif(/^([:\$])\s*(\w+)/g) {
382 $curwidget = {"type" => $2};
383 push @{$estack[0]}, $curwidget;
384 if((scalar @wstack) > 0) {
385 $curwidget->{"parent"} = $wstack[0];
389 unshift @estack, ($curwidget->{"subwidgets"} = []);
390 unshift @wstack, $curwidget;
392 $maxstack = (scalar @estack) if((scalar @estack) > $maxstack);
393 while(/\G\s*(\S+)\s*:\s*((\w+|\"([^\\\"]+|\\.)*([^\\]|)\"|\\.)+)/g)
395 $curwidget->{$1} = dequote($2);
397 } elsif(/^%\s*(\S+)\s*:\s*((\w+|\"([^\\\"]+|\\.)*([^\\]|)\"|\\.)+)/) {
398 $curwidget || die("No current widget\n");
399 $curwidget->{$1} = dequote($2);
403 $curwidget = $wstack[0] if((scalar @wstack) > 0);
406 print STDERR "Invalid construct: $_\n";
410 printvars $rootwidgets;
412 print "GtkWidget *create_" . $options{"prefix"} . "wnd(void)\n";
414 print " GtkWidget *stack[$maxstack];\n";
415 print " GtkAccelGroup *accel_group;\n" if $options{"hasaccels"};
416 print " GtkTreeViewColumn *column;\n" if $options{"hascolumns"};
417 print " GtkCellRenderer *renderer;\n" if $options{"hasrenderers"};
419 print " accel_group = gtk_accel_group_new();\n" if $options{"hasaccels"};
420 printwidgets $rootwidgets, 0;
421 print " return(stack[0]);\n";