]> 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 void Dialog::add_button(Button &button, int code)
10 {
11         add(button);
12         connect_button(button, code);
13 }
14
15 void Dialog::add_button(unique_ptr<Button> button, int code)
16 {
17         Button &b = *button;
18         add(move(button));
19         connect_button(b, code);
20 }
21
22 Button &Dialog::add_button(const string &text, int code)
23 {
24         Button &b = add_new<Button>(text);
25         connect_button(b, code);
26         return b;
27 }
28
29 void Dialog::set_modal(bool m)
30 {
31         if(m)
32         {
33                 set_focus();
34                 if(state&FOCUS)
35                         signal_grab_pointer.emit();
36         }
37         else
38                 signal_ungrab_pointer.emit();
39 }
40
41 void Dialog::connect_button(Button &button, int code)
42 {
43         button.signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &Dialog::response), code));
44 }
45
46 void Dialog::response(int code)
47 {
48         on_response(code);
49         signal_response.emit(code);
50         set_visible(false);
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         unique_ptr<Button> btn = make_unique<Button>();
63         load_sub(*btn);
64         Widget *wdg = btn.get();
65         obj.add_button(move(btn), c);
66         last_widget = wdg_map[n] = wdg;
67 }
68
69 } // namespace GLtk
70 } // namespace Msp