]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/dialog.cpp
Refactor Dialog to separate the autodeletion functionality
[libs/gltk.git] / source / dialog.cpp
index 5eea60964ec3d694ff94b001cc8a7702473824d8..5e5e390e7cadadf91d3e5af4e978d4e3f333dc33 100644 (file)
@@ -1,47 +1,49 @@
-/* $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::button_release(int x, int y, unsigned button)
-{
-       Panel::button_release(x, y, button);
-       if(stale)
-               delete this;
-}
-
-void Dialog::key_release(unsigned key, unsigned mod)
+void Dialog::set_modal(bool m)
 {
-       Panel::key_release(key, mod);
-       if(stale)
-               delete this;
+       if(m)
+       {
+               set_focus();
+               if(state&FOCUS)
+                       signal_grab_pointer.emit();
+       }
+       else
+               signal_ungrab_pointer.emit();
 }
 
 void Dialog::response(int code)
 {
        on_response(code);
        signal_response.emit(code);
-       stale=true;
+       set_visible(false);
+}
+
+
+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