]> git.tdb.fi Git - libs/gltk.git/blob - source/dialog.cpp
9f9fc20d15388f69ece201db0105265ddae7c74e
[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 void Dialog::add_button(Button &button, int code)
10 {
11         add(button);
12         button.signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &Dialog::response), code));
13 }
14
15 void Dialog::set_modal(bool m)
16 {
17         if(m)
18         {
19                 set_focus();
20                 if(state&FOCUS)
21                         signal_grab_pointer.emit();
22         }
23         else
24                 signal_ungrab_pointer.emit();
25 }
26
27 void Dialog::button_release(int x, int y, unsigned button)
28 {
29         Panel::button_release(x, y, button);
30         check_stale();
31 }
32
33 bool Dialog::key_release(unsigned key, unsigned mod)
34 {
35         bool result = Panel::key_release(key, mod);
36         check_stale();
37         return result;
38 }
39
40 bool Dialog::navigate(Navigation nav)
41 {
42         bool result = Panel::navigate(nav);
43         check_stale();
44         return result;
45 }
46
47 void Dialog::response(int code)
48 {
49         on_response(code);
50         signal_response.emit(code);
51         stale = true;
52 }
53
54 void Dialog::check_stale()
55 {
56         if(stale)
57                 delete this;
58 }
59
60
61 Dialog::Loader::Loader(Dialog &d, WidgetMap &wm):
62         DerivedObjectLoader<Dialog, Panel::Loader>(d, wm)
63 {
64         add("action_button", &Loader::action_button);
65 }
66
67 void Dialog::Loader::action_button(const string &n, int c)
68 {
69         unique_ptr<Button> btn = make_unique<Button>();
70         load_sub(*btn);
71         obj.add_button(*btn.get(), c);
72         last_widget = wdg_map[n] = btn.release();
73 }
74
75 } // namespace GLtk
76 } // namespace Msp