]> git.tdb.fi Git - libs/gltk.git/blob - source/dialog.cpp
Rework how widget ownership works in Container
[libs/gltk.git] / source / dialog.cpp
1 #include "button.h"
2 #include "dialog.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GLtk {
8
9 Dialog::Dialog():
10         stale(false)
11 { }
12
13 void Dialog::add_button(Button &button, int code)
14 {
15         add(button);
16         button.signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &Dialog::response), code));
17 }
18
19 void Dialog::button_release(int x, int y, unsigned button)
20 {
21         Panel::button_release(x, y, button);
22         if(stale)
23                 delete this;
24 }
25
26 bool Dialog::key_release(unsigned key, unsigned mod)
27 {
28         bool result = Panel::key_release(key, mod);
29         if(stale)
30                 delete this;
31         return result;
32 }
33
34 void Dialog::response(int code)
35 {
36         on_response(code);
37         signal_response.emit(code);
38         stale = true;
39 }
40
41
42 Dialog::Loader::Loader(Dialog &d, WidgetMap &wm):
43         DerivedObjectLoader<Dialog, Panel::Loader>(d, wm)
44 {
45         add("action_button", &Loader::action_button);
46 }
47
48 void Dialog::Loader::action_button(const string &n, int c)
49 {
50         RefPtr<Button> btn = new Button();
51         load_sub(*btn);
52         obj.add_button(*btn.get(), c);
53         last_widget = wdg_map[n] = btn.release();
54 }
55
56 } // namespace GLtk
57 } // namespace Msp