From: Mikko Rasa Date: Sun, 28 Feb 2010 10:32:54 +0000 (+0000) Subject: Add Widget::focusable flag X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=75a16eae9eb2714f8112d46fa5b8f7908b6d2487;p=libs%2Fgltk.git Add Widget::focusable flag Propagate focus requests through Panels Add getters for input focus --- diff --git a/source/indicator.cpp b/source/indicator.cpp index 2debf35..7f4ac4b 100644 --- a/source/indicator.cpp +++ b/source/indicator.cpp @@ -13,6 +13,7 @@ namespace GLtk { Indicator::Indicator(const Resources &r): Widget(r) { + focusable=false; update_style(); } diff --git a/source/label.cpp b/source/label.cpp index ae821a8..2353385 100644 --- a/source/label.cpp +++ b/source/label.cpp @@ -18,6 +18,7 @@ Label::Label(const Resources &r, const string &t): Widget(r), text(style) { + focusable=false; update_style(); set_text(t); } diff --git a/source/panel.cpp b/source/panel.cpp index 14e9b6e..4d7e1a9 100644 --- a/source/panel.cpp +++ b/source/panel.cpp @@ -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(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(container).set_input_focus(widget); + Panel &panel=static_cast(container); + panel.set_input_focus(widget); + if(panel.parent && panel.visible) + panel.set_focus(); } void Panel::Child::grab_pointer() diff --git a/source/panel.h b/source/panel.h index 8a5d128..1082447 100644 --- a/source/panel.h +++ b/source/panel.h @@ -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); diff --git a/source/table.cpp b/source/table.cpp index 7f334a0..7f0ae79 100644 --- a/source/table.cpp +++ b/source/table.cpp @@ -23,6 +23,7 @@ Table::Table(const Resources &r): data(1), col_w(1) { + focusable=false; update_style(); } diff --git a/source/widget.cpp b/source/widget.cpp index 8c59c07..04c272a 100644 --- a/source/widget.cpp +++ b/source/widget.cpp @@ -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) diff --git a/source/widget.h b/source/widget.h index 69adf9c..2fdc68c 100644 --- a/source/widget.h +++ b/source/widget.h @@ -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;