]> 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 3e09783dcb5eb36350d4c4158b9139ae33ed7fd0..9f9fc20d15388f69ece201db0105265ddae7c74e 100644 (file)
@@ -1,40 +1,47 @@
-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2010  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include "button.h"
 #include "dialog.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GLtk {
 
-Dialog::Dialog(const Resources &r):
-       Widget(r),
-       Panel(r),
-       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)
@@ -44,5 +51,26 @@ 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)
+{
+       add("action_button", &Loader::action_button);
+}
+
+void Dialog::Loader::action_button(const string &n, int c)
+{
+       unique_ptr<Button> btn = make_unique<Button>();
+       load_sub(*btn);
+       obj.add_button(*btn.get(), c);
+       last_widget = wdg_map[n] = btn.release();
+}
+
 } // namespace GLtk
 } // namespace Msp