I am trying to make sustom modal dialog with glade. For this I use "dialog box" from "toplevels", set transient_for_window and modal variables properly. Then I put widgets to table all packed into dialog-vbox. And this works OK, as expected.
But, when I need more complex GUI, like I need now, and pack into dialog-vbox scrolledwindow> viewport> aspectframe> table> and then place widgets in table this dialog becomes no more modal! After some playing I conclude that it is obvious that problems with modality starts with scrolledwindow.
Is it allowed to put such complex GUI in dialog? If yes - why my dialog lost modality with gtkscrollwindow, if no, how people do such tasks? In my case I'm trying to make modal dialog which can be connected to different projects (say reusable).
GUI:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="dialog1">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<object class="GtkViewport" id="viewport1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">10</property>
<property name="n_columns">2</property>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
<property name="invisible_char_set">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button1</action-widget>
<action-widget response="0">button2</action-widget>
</action-widgets>
</object>
</interface>
C:
int dlgmodal(GtkWidget *mainwindow, char* fmw)
{
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "external0.glade", NULL);
dialog1 = GTK_DIALOG(gtk_builder_get_object(builder, "dialog1"));
entry1 = GTK_WIDGET(gtk_builder_get_object(builder, "entry1"));
gtk_builder_connect_signals(builder, NULL);
g_object_unref(G_OBJECT(builder));
gtk_entry_set_text(GTK_ENTRY(entry1), fmw);
gtk_window_set_modal(GTK_WINDOW(GTK_DIALOG(dialog1)), TRUE);
gtk_window_set_transient_for(GTK_WINDOW(GTK_DIALOG(dialog1)), GTK_WINDOW(mainwindow));
//
int x, y;
gdk_window_get_origin(GDK_WINDOW(GTK_WIDGET(mainwindow)->window), &x, &y);
gtk_window_move(GTK_WINDOW(dialog1), x+8, y);
//
int dlgresponse;
dlgresponse = gtk_dialog_run(GTK_DIALOG(dialog1));
gtk_widget_destroy(GTK_WIDGET(GTK_DIALOG(dialog1)));
return dlgresponse;
}