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