]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/root.cpp
Minor style fixes
[libs/gltk.git] / source / root.cpp
index 89db305ea5bd291e7cfc9823c7a5a2964a837ec6..de2472797199108870d8b045679d53019ad815a8 100644 (file)
@@ -15,33 +15,41 @@ Root::Root(const Resources &r, Graphics::Window &window):
        mouse(new Input::Mouse(window)),
        own_input(true)
 {
-       set_geometry(Geometry(0, 0, window.get_width(), window.get_height()));
-
-       init();
+       init(&window);
 }
 
-Root::Root(const Resources &r, Input::Keyboard *k, Input::Mouse *m):
+Root::Root(const Resources &r, Graphics::Window *window, Input::Keyboard *k, Input::Mouse *m):
        resources(r),
        keyboard(k),
        mouse(m),
        own_input(false)
 {
-       init();
+       init(window);
 }
 
-void Root::init()
+void Root::init(Graphics::Window *window)
 {
+       if(window)
+               set_geometry(Geometry(0, 0, window->get_width(), window->get_height()));
+
        lbl_tooltip = 0;
        tooltip_target = 0;
 
        update_style();
 
-       mouse->signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
-       mouse->signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
-       mouse->signal_axis_motion.connect(sigc::mem_fun(this, &Root::axis_motion_event));
-       keyboard->signal_button_press.connect(sigc::mem_fun(this, &Root::key_press_event));
-       keyboard->signal_button_release.connect(sigc::mem_fun(this, &Root::key_release_event));
-       keyboard->signal_character.connect(sigc::mem_fun(this, &Root::character_event));
+       if(mouse)
+       {
+               mouse->signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
+               mouse->signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
+               mouse->signal_axis_motion.connect(sigc::mem_fun(this, &Root::axis_motion_event));
+       }
+
+       if(keyboard)
+       {
+               keyboard->signal_button_press.connect(sigc::mem_fun(this, &Root::key_press_event));
+               keyboard->signal_button_release.connect(sigc::mem_fun(this, &Root::key_release_event));
+               keyboard->signal_character.connect(sigc::mem_fun(this, &Root::character_event));
+       }
 }
 
 Root::~Root()
@@ -109,27 +117,41 @@ void Root::render() const
        Widget::render(renderer);
 }
 
-void Root::button_press_event(unsigned btn)
+bool Root::button_press_event(unsigned btn)
 {
        if(visible)
        {
+               Widget *old_focus = pointer_focus;
+
                int x, y;
                get_pointer(x, y);
                button_press(x, y, btn);
+
+               if(pointer_focus || old_focus)
+                       return true;
        }
+
+       return false;
 }
 
-void Root::button_release_event(unsigned btn)
+bool Root::button_release_event(unsigned btn)
 {
        if(visible)
        {
+               Widget *old_focus = pointer_focus;
+
                int x, y;
                get_pointer(x, y);
                button_release(x, y, btn);
+
+               if(pointer_focus || old_focus)
+                       return true;
        }
+
+       return false;
 }
 
-void Root::axis_motion_event(unsigned, float, float)
+bool Root::axis_motion_event(unsigned, float, float)
 {
        if(visible)
        {
@@ -149,26 +171,58 @@ void Root::axis_motion_event(unsigned, float, float)
                                lbl_tooltip->set_visible(false);
                        tooltip_target = 0;
                }
+
+               if(pointer_focus)
+                       return true;
        }
+
+       return false;
 }
 
-void Root::key_press_event(unsigned key)
+bool Root::key_press_event(unsigned key)
 {
        // XXX Modifiers
        if(visible)
+       {
+               Widget *old_focus = input_focus;
+
                key_press(key, 0);
+
+               if(input_focus || old_focus)
+                       return true;
+       }
+
+       return false;
 }
 
-void Root::key_release_event(unsigned key)
+bool Root::key_release_event(unsigned key)
 {
        if(visible)
+       {
+               Widget *old_focus = input_focus;
+
                key_release(key, 0);
+
+               if(input_focus || old_focus)
+                       return true;
+       }
+
+       return false;
 }
 
-void Root::character_event(StringCodec::unichar ch)
+bool Root::character_event(StringCodec::unichar ch)
 {
        if(visible)
+       {
+               Widget *old_focus = input_focus;
+
                character(ch);
+
+               if(input_focus || old_focus)
+                       return true;
+       }
+
+       return false;
 }
 
 void Root::get_pointer(int &x, int &y)
@@ -177,5 +231,11 @@ void Root::get_pointer(int &x, int &y)
        y = (mouse->get_axis_value(1)*0.5+0.5)*geom.h;
 }
 
+void Root::on_child_added(Widget &wdg)
+{
+       if(&wdg!=lbl_tooltip)
+               Panel::on_child_added(wdg);
+}
+
 } // namespace GLtk
 } // namespace Msp