Gtk,自定义模态对话框

时间:2012-01-29 22:57:00

标签: gtk

我正在尝试使用glade进行可持续模态对话。 为此,我使用“toplevels”中的“对话框”,正确设置transient_for_window和模态变量。然后我将小部件放到table中,所有打包到dialog-vbox中。 这正常,正如预期的那样。

但是,当我需要更复杂的GUI时,就像我现在需要的那样,并打包到dialog-vbox scrolledwindow>视> aspectframe>表>然后将小部件放在表格中,此对话框不再是模态的!经过一段时间的演奏后,我得出结论,很明显,模态问题始于滚动窗口。

是否允许在对话框中放置如此​​复杂的GUI?如果是 - 为什么我的对话框失去了gtkscrollwindow的模态,如果没有,人们如何做这样的任务?在我的情况下,我正在尝试进行模态对话,可以连接到不同的项目(比如可重复使用)。

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;
}

0 个答案:

没有答案