]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add Widget::focusable flag
authorMikko Rasa <tdb@tdb.fi>
Sun, 28 Feb 2010 10:32:54 +0000 (10:32 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sun, 28 Feb 2010 10:32:54 +0000 (10:32 +0000)
Propagate focus requests through Panels
Add getters for input focus

source/indicator.cpp
source/label.cpp
source/panel.cpp
source/panel.h
source/table.cpp
source/widget.cpp
source/widget.h

index 2debf35d01ee02d973f1170d6c98ad4fbe914e57..7f4ac4b87a88d807abada60336826c65dc58644f 100644 (file)
@@ -13,6 +13,7 @@ namespace GLtk {
 Indicator::Indicator(const Resources &r):
        Widget(r)
 {
+       focusable=false;
        update_style();
 }
 
index ae821a81f0f6330dc42ac6c3f15ce18ac85d21d9..2353385c1174c44f78b129a45b3c550eec79206b 100644 (file)
@@ -18,6 +18,7 @@ Label::Label(const Resources &r, const string &t):
        Widget(r),
        text(style)
 {
+       focusable=false;
        update_style();
        set_text(t);
 }
index 14e9b6ea8cc3dbf97b9c57f4f673df53870bacc2..4d7e1a9df3d0aa814aa225c9dc47038d58fc3f68 100644 (file)
@@ -47,6 +47,17 @@ void Panel::raise(Widget &wdg)
        throw InvalidState("That Widget is not in this Panel");
 }
 
+Widget *Panel::get_final_input_focus() const
+{
+       if(Panel *panel=dynamic_cast<Panel *>(input_focus))
+       {
+               Widget *focus=panel->get_final_input_focus();
+               if(focus)
+                       return focus;
+       }
+       return input_focus;
+}
+
 void Panel::button_press(int x, int y, unsigned btn)
 {
        if(pointer_grabbed)
@@ -59,7 +70,8 @@ void Panel::button_press(int x, int y, unsigned btn)
                if(Widget *wdg=get_child_at(x, y))
                {
                        set_pointer_focus(wdg);
-                       set_input_focus(wdg);
+                       if(wdg->is_focusable())
+                               set_input_focus(wdg);
                }
                Container::button_press(x, y, btn);
        }
@@ -224,7 +236,10 @@ void Panel::Child::visibility_changed(bool v)
 
 void Panel::Child::request_focus()
 {
-       static_cast<Panel &>(container).set_input_focus(widget);
+       Panel &panel=static_cast<Panel &>(container);
+       panel.set_input_focus(widget);
+       if(panel.parent && panel.visible)
+               panel.set_focus();
 }
 
 void Panel::Child::grab_pointer()
index 8a5d1286ab97024a3abf102643a2b344fd2eb655..1082447bc58fdddaf77f660d5876e326a5a82616 100644 (file)
@@ -58,6 +58,8 @@ public:
        Panel(const Resources &);
 
        void raise(Widget &);
+       Widget *get_input_focus() const { return input_focus; }
+       Widget *get_final_input_focus() const;
 
        virtual void button_press(int, int, unsigned);
        virtual void button_release(int, int, unsigned);
index 7f334a0e6825041fb24df917a06be91bc3a2e405..7f0ae796f9c7077599990ee1fd563fe64bec0b29 100644 (file)
@@ -23,6 +23,7 @@ Table::Table(const Resources &r):
        data(1),
        col_w(1)
 {
+       focusable=false;
        update_style();
 }
 
index 8c59c07fe1e9d4b877907499fb6e70c8cee55a4c..04c272a136242cea7b14e9adf1988da22fc9cf09 100644 (file)
@@ -23,6 +23,7 @@ Widget::Widget(const Resources &r):
        style(0),
        state(NORMAL),
        visible(true),
+       focusable(true),
        parent(0)
 { }
 
@@ -73,6 +74,11 @@ void Widget::set_visible(bool v)
        signal_visibility_changed.emit(visible);
 }
 
+void Widget::set_focusable(bool f)
+{
+       focusable=f;
+}
+
 void Widget::set_focus()
 {
        if(!parent)
index 69adf9ca52b0fce6b0aaa64fc703badaafbe61fb..2fdc68c34c778e34f4ebf72ba237921eeb2f54fb 100644 (file)
@@ -53,6 +53,7 @@ protected:
        const Style *style;
        State state;
        bool visible;
+       bool focusable;
        Container *parent;
        std::string tooltip;
 
@@ -78,6 +79,8 @@ public:
 
        void set_visible(bool);
        bool is_visible() const { return visible; }
+       void set_focusable(bool);
+       bool is_focusable() const { return focusable; }
        void set_focus();
 
        void render() const;