]> git.tdb.fi Git - libs/gltk.git/blob - source/dialog.cpp
Add a set_modal function for Dialog
[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         if(stale)
35                 delete this;
36 }
37
38 bool Dialog::key_release(unsigned key, unsigned mod)
39 {
40         bool result = Panel::key_release(key, mod);
41         if(stale)
42                 delete this;
43         return result;
44 }
45
46 void Dialog::response(int code)
47 {
48         on_response(code);
49         signal_response.emit(code);
50         stale = true;
51 }
52
53
54 Dialog::Loader::Loader(Dialog &d, WidgetMap &wm):
55         DerivedObjectLoader<Dialog, Panel::Loader>(d, wm)
56 {
57         add("action_button", &Loader::action_button);
58 }
59
60 void Dialog::Loader::action_button(const string &n, int c)
61 {
62         RefPtr<Button> btn = new Button();
63         load_sub(*btn);
64         obj.add_button(*btn.get(), c);
65         last_widget = wdg_map[n] = btn.release();
66 }
67
68 } // namespace GLtk
69 } // namespace Msp