]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/dialog.cpp
Improve Dialog staleness checks
[libs/gltk.git] / source / dialog.cpp
index 5eea60964ec3d694ff94b001cc8a7702473824d8..a264fbe87ce753de12b4b7c89ba76d5a849f2fa9 100644 (file)
@@ -1,19 +1,12 @@
-/* $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),
+Dialog::Dialog():
        stale(false)
 { }
 
@@ -23,25 +16,64 @@ void Dialog::add_button(Button &button, int code)
        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)
 {
        on_response(code);
        signal_response.emit(code);
-       stale=true;
+       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)
+{
+       RefPtr<Button> btn = new Button();
+       load_sub(*btn);
+       obj.add_button(*btn.get(), c);
+       last_widget = wdg_map[n] = btn.release();
 }
 
 } // namespace GLtk