File: basic_from_buffer.cc

package info (click to toggle)
libglademm2.4 2.6.7-6
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 2,744 kB
  • sloc: sh: 9,112; cpp: 704; makefile: 199; perl: 108; xml: 71
file content (133 lines) | stat: -rw-r--r-- 4,599 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <libglademm/xml.h>
#include <gtkmm.h>
#include <iostream>

const gchar buffer[] =
  "<?xml version=\"1.0\" standalone=\"no\"?> <!--*- mode: xml -*-->"
  "<!DOCTYPE glade-interface SYSTEM \"http://glade.gnome.org/glade-2.0.dtd\">"
  ""
  "<glade-interface>"
  ""
  "<widget class=\"GtkDialog\" id=\"DialogBasic\">"
  "  <property name=\"title\" translatable=\"yes\">basic libglademm example</property>"
  "  <property name=\"type\">GTK_WINDOW_TOPLEVEL</property>"
  "  <property name=\"window_position\">GTK_WIN_POS_NONE</property>"
  "  <property name=\"modal\">False</property>"
  "  <property name=\"resizable\">True</property>"
  "  <property name=\"destroy_with_parent\">False</property>"
  "  <property name=\"has_separator\">True</property>"
  ""
  "  <child internal-child=\"vbox\">"
  "    <widget class=\"GtkVBox\" id=\"dialog-vbox2\">"
  "      <property name=\"border_width\">2</property>"
  "      <property name=\"visible\">True</property>"
  "      <property name=\"homogeneous\">False</property>"
  "      <property name=\"spacing\">0</property>"
  ""
  "      <child internal-child=\"action_area\">"
  "        <widget class=\"GtkHButtonBox\" id=\"dialog-action_area2\">"
  "          <property name=\"border_width\">5</property>"
  "          <property name=\"visible\">True</property>"
  "          <property name=\"layout_style\">GTK_BUTTONBOX_END</property>"
  "          <property name=\"spacing\">10</property>"
  ""
  "          <child>"
  "            <widget class=\"GtkButton\" id=\"quit_button\">"
  "              <property name=\"visible\">True</property>"
  "              <property name=\"can_default\">True</property>"
  "              <property name=\"can_focus\">True</property>"
  "              <property name=\"label\">gtk-quit</property>"
  "              <property name=\"use_stock\">True</property>"
  "              <property name=\"relief\">GTK_RELIEF_NORMAL</property>"
  "              <property name=\"response_id\">0</property>"
  "            </widget>"
  "          </child>"
  "        </widget>"
  "        <packing>"
  "          <property name=\"padding\">0</property>"
  "          <property name=\"expand\">False</property>"
  "          <property name=\"fill\">True</property>"
  "          <property name=\"pack_type\">GTK_PACK_END</property>"
  "        </packing>"
  "      </child>"
  ""
  "      <child>"
  "        <widget class=\"GtkLabel\" id=\"label1\">"
  "          <property name=\"visible\">True</property>"
  "          <property name=\"label\" translatable=\"yes\">This is a basic libglademm example</property>"
  "          <property name=\"use_underline\">False</property>"
  "          <property name=\"use_markup\">False</property>"
  "          <property name=\"justify\">GTK_JUSTIFY_LEFT</property>"
  "          <property name=\"wrap\">False</property>"
  "          <property name=\"selectable\">False</property>"
  "          <property name=\"xalign\">0.5</property>"
  "          <property name=\"yalign\">0.5</property>"
  "          <property name=\"xpad\">0</property>"
  "          <property name=\"ypad\">0</property>"
  "        </widget>"
  "        <packing>"
  "          <property name=\"padding\">0</property>"
  "          <property name=\"expand\">False</property>"
  "          <property name=\"fill\">False</property>"
  "        </packing>"
  "      </child>"
  "    </widget>"
  "  </child>"
  "</widget>"
  ""
  "</glade-interface>";


Gtk::Dialog* pDialog = 0;

void on_button_clicked()
{
  if(pDialog)
    pDialog->hide(); //hide() will cause main::run() to end.
}

int main (int argc, char **argv)
{
  Gtk::Main kit(argc, argv);

  //Load the Glade file and instiate its widgets:
  Glib::RefPtr<Gnome::Glade::Xml> refXml;
#ifdef GLIBMM_EXCEPTIONS_ENABLED
  try
  {
    refXml = Gnome::Glade::Xml::create_from_buffer(buffer, sizeof(buffer));
  }
  catch(const Gnome::Glade::XmlError& ex)
  {
    std::cerr << ex.what() << std::endl;
    return 1;
  }
#else
  std::auto_ptr<Gnome::Glade::XmlError> error;
  refXml = Gnome::Glade::Xml::create_from_buffer(buffer, sizeof(buffer), "", "", error);
  if(error.get())
  {
    std::cerr << error->what() << std::endl;
    return 1;
  }
#endif

  //Get the Glade-instantiated Dialog:
  
  refXml->get_widget("DialogBasic", pDialog);
  if(pDialog)
  {
    //Get the Glade-instantiated Button, and connect a signal handler:
    Gtk::Button* pButton = 0;
    refXml->get_widget("quit_button", pButton);
    if(pButton)
    {
      pButton->signal_clicked().connect( sigc::ptr_fun(on_button_clicked) );
    }

    kit.run(*pDialog);
  }

  return 0;
}