TabWnd.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00029 #ifndef _GG_TabWnd_h_
00030 #define _GG_TabWnd_h_
00031
00032 #include <GG/Button.h>
00033
00034
00035 namespace GG {
00036
00037 class TabBar;
00038 class WndEvent;
00039
00042 class GG_API TabWnd : public Wnd
00043 {
00044 public:
00046
00049 typedef boost::signal<void (std::size_t)> WndChangedSignalType;
00051
00053
00054 TabWnd(X x, Y y, X w, Y h, const boost::shared_ptr<Font>& font, Clr color, Clr text_color = CLR_BLACK,
00055 TabBarStyle style = TAB_BAR_ATTACHED, Flags<WndFlag> flags = INTERACTIVE);
00056 ~TabWnd();
00058
00060 virtual Pt MinUsableSize() const;
00061
00063 bool Empty() const;
00064
00066 std::size_t NumWnds() const;
00067
00069 Wnd* CurrentWnd() const;
00070
00074 std::size_t CurrentWndIndex() const;
00076
00078 virtual void Render();
00079
00083 std::size_t AddWnd(Wnd* wnd, const std::string& name);
00084
00089 void InsertWnd(std::size_t index, Wnd* wnd, const std::string& name);
00090
00093 Wnd* RemoveWnd(const std::string& name);
00094
00097 void SetCurrentWnd(std::size_t index);
00099
00100 mutable WndChangedSignalType WndChangedSignal;
00101
00104 static const std::size_t NO_WND;
00105
00106 protected:
00108 TabWnd();
00109
00110
00112 const TabBar* GetTabBar() const;
00113 const std::vector<std::pair<Wnd*, std::string> >& Wnds() const;
00115
00116 private:
00117 void TabChanged(std::size_t tab_index, bool signal);
00118
00119 TabBar* m_tab_bar;
00120 std::vector<std::pair<Wnd*, std::string> > m_wnds;
00121 Wnd* m_current_wnd;
00122
00123 friend class boost::serialization::access;
00124 template <class Archive>
00125 void serialize(Archive& ar, const unsigned int version);
00126 };
00127
00128
00134 class GG_API TabBar : public Control
00135 {
00136 public:
00138
00141 typedef boost::signal<void (std::size_t)> TabChangedSignalType;
00143
00145
00146 TabBar(X x, Y y, X w, const boost::shared_ptr<Font>& font, Clr color, Clr text_color = CLR_BLACK,
00147 TabBarStyle style = TAB_BAR_ATTACHED, Flags<WndFlag> flags = INTERACTIVE);
00149
00151 virtual Pt MinUsableSize() const;
00152
00154 bool Empty() const;
00155
00157 std::size_t NumTabs() const;
00158
00162 std::size_t CurrentTabIndex() const;
00163
00165 Clr TextColor() const;
00167
00169 virtual void SizeMove(const Pt& ul, const Pt& lr);
00170 virtual void Render();
00171
00175 std::size_t AddTab(const std::string& name);
00176
00181 void InsertTab(std::size_t index, const std::string& name);
00182
00185 void RemoveTab(const std::string& name);
00186
00189 void SetCurrentTab(std::size_t index);
00191
00192 mutable TabChangedSignalType TabChangedSignal;
00193
00196 static const std::size_t NO_TAB;
00197
00199 static const X BUTTON_WIDTH;
00200
00201 protected:
00203 TabBar();
00204
00205
00207 const Button* LeftButton() const;
00208 const Button* RightButton() const;
00210
00212 virtual bool EventFilter(Wnd* w, const WndEvent& event);
00213
00216 void RaiseCurrentTabButton();
00218
00219 private:
00220 virtual void DistinguishCurrentTab(const std::vector<StateButton*>& tab_buttons);
00221
00222 void TabChanged(std::size_t index, bool signal);
00223 void LeftClicked();
00224 void RightClicked();
00225 void BringTabIntoView(std::size_t index);
00226
00227 RadioButtonGroup* m_tabs;
00228 std::vector<StateButton*> m_tab_buttons;
00229 boost::shared_ptr<Font> m_font;
00230 Button* m_left_button;
00231 Button* m_right_button;
00232 Layout* m_left_right_button_layout;
00233 Flags<TextFormat> m_format;
00234 Clr m_text_color;
00235 TabBarStyle m_style;
00236 std::size_t m_first_tab_shown;
00237
00238 friend class boost::serialization::access;
00239 template <class Archive>
00240 void serialize(Archive& ar, const unsigned int version);
00241 };
00242
00243 }
00244
00245
00246 template <class Archive>
00247 void GG::TabWnd::serialize(Archive& ar, const unsigned int version)
00248 {
00249 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Wnd)
00250 & BOOST_SERIALIZATION_NVP(m_tab_bar)
00251 & BOOST_SERIALIZATION_NVP(m_wnds)
00252 & BOOST_SERIALIZATION_NVP(m_current_wnd);
00253 }
00254
00255 template <class Archive>
00256 void GG::TabBar::serialize(Archive& ar, const unsigned int version)
00257 {
00258 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Control)
00259 & BOOST_SERIALIZATION_NVP(m_tabs)
00260 & BOOST_SERIALIZATION_NVP(m_tab_buttons)
00261 & BOOST_SERIALIZATION_NVP(m_font)
00262 & BOOST_SERIALIZATION_NVP(m_left_button)
00263 & BOOST_SERIALIZATION_NVP(m_right_button)
00264 & BOOST_SERIALIZATION_NVP(m_left_right_button_layout)
00265 & BOOST_SERIALIZATION_NVP(m_format)
00266 & BOOST_SERIALIZATION_NVP(m_text_color)
00267 & BOOST_SERIALIZATION_NVP(m_style)
00268 & BOOST_SERIALIZATION_NVP(m_first_tab_shown);
00269 }
00270
00271 #endif