]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/dialog.cpp
Use std::unique_ptr for managing memory
[libs/gltk.git] / source / dialog.cpp
index 2342e8483786b6ce5eba91f1a6c497290a70f7da..9f9fc20d15388f69ece201db0105265ddae7c74e 100644 (file)
@@ -6,28 +6,42 @@ using namespace std;
 namespace Msp {
 namespace GLtk {
 
-Dialog::Dialog():
-       stale(false)
-{ }
-
 void Dialog::add_button(Button &button, int code)
 {
        add(button);
        button.signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &Dialog::response), code));
 }
 
+void Dialog::set_modal(bool m)
+{
+       if(m)
+       {
+               set_focus();
+               if(state&FOCUS)
+                       signal_grab_pointer.emit();
+       }
+       else
+               signal_ungrab_pointer.emit();
+}
+
 void Dialog::button_release(int x, int y, unsigned button)
 {
        Panel::button_release(x, y, button);
-       if(stale)
-               delete this;
+       check_stale();
 }
 
-void Dialog::key_release(unsigned key, unsigned mod)
+bool Dialog::key_release(unsigned key, unsigned mod)
 {
-       Panel::key_release(key, mod);
-       if(stale)
-               delete this;
+       bool result = Panel::key_release(key, mod);
+       check_stale();
+       return result;
+}
+
+bool Dialog::navigate(Navigation nav)
+{
+       bool result = Panel::navigate(nav);
+       check_stale();
+       return result;
 }
 
 void Dialog::response(int code)
@@ -37,6 +51,12 @@ void Dialog::response(int code)
        stale = true;
 }
 
+void Dialog::check_stale()
+{
+       if(stale)
+               delete this;
+}
+
 
 Dialog::Loader::Loader(Dialog &d, WidgetMap &wm):
        DerivedObjectLoader<Dialog, Panel::Loader>(d, wm)
@@ -46,7 +66,7 @@ Dialog::Loader::Loader(Dialog &d, WidgetMap &wm):
 
 void Dialog::Loader::action_button(const string &n, int c)
 {
-       RefPtr<Button> btn = new Button();
+       unique_ptr<Button> btn = make_unique<Button>();
        load_sub(*btn);
        obj.add_button(*btn.get(), c);
        last_widget = wdg_map[n] = btn.release();