File: main.cc

package info (click to toggle)
gtkmm3.0 3.24.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,712 kB
  • sloc: xml: 121,333; cpp: 8,571; sh: 4,301; makefile: 265; perl: 236
file content (56 lines) | stat: -rw-r--r-- 1,209 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
#include <gtkmm.h>
#include <iostream>

Glib::RefPtr<Gtk::Application> app;

//This is _not_ a good example of coding with gtkmm.
class Dlg : public sigc::trackable
{
  public:
    Dlg()
    {
      dlg_ = new Gtk::Dialog("Test Dialog");
      Gtk::Button *btn = Gtk::make_managed<Gtk::Button>("ClickMe");
      btn->signal_clicked().connect(sigc::mem_fun(*this, &Dlg::on_button_clicked));
      dlg_->get_content_area()->pack_start(*btn);
      dlg_->add_button("_OK", Gtk::RESPONSE_OK);
      dlg_->signal_response().connect(sigc::mem_fun(*this, &Dlg::on_response));
      dlg_->show_all();
    }

    ~Dlg()
    {
      delete dlg_;
    }

    void on_button_clicked()
    {
      std::cout << "button clicked" << std::endl;
    }

    void on_response(int id)
   {
      if (id == Gtk::RESPONSE_OK || id == Gtk::RESPONSE_DELETE_EVENT)
        quit();
    }

    void quit() {
      delete this; //This is _not_ a good example of coding with gtkmm.
      app->quit();
    }

  private:
    Gtk::Dialog *dlg_;
};

int main (int argc, char **argv)
{
  app = Gtk::Application::create(argc, argv);

  new Dlg(); //Not a Gtk::Dialog - it creates one in its constructor.

  app->hold();
  return app->run();
}