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
00048 typedef boost::signal<void (int)> WndChangedSignalType;
00050
00052 typedef WndChangedSignalType::slot_type WndChangedSlotType;
00053
00054
00056
00057 TabWnd(int x, int y, int w, int h, const boost::shared_ptr<Font>& font, Clr color, Clr text_color = CLR_BLACK,
00058 TabBarStyle style = TAB_BAR_ATTACHED, Flags<WndFlag> flags = CLICKABLE | DRAGABLE);
00059 ~TabWnd();
00061
00063 virtual Pt MinUsableSize() const;
00064
00066 Wnd* CurrentWnd() const;
00067
00071 int CurrentWndIndex() const;
00073
00075 virtual void Render();
00076
00080 int AddWnd(Wnd* wnd, const std::string& name);
00081
00086 void InsertWnd(int index, Wnd* wnd, const std::string& name);
00087
00090 Wnd* RemoveWnd(const std::string& name);
00091
00094 void SetCurrentWnd(int index);
00096
00097 mutable WndChangedSignalType WndChangedSignal;
00098
00100 static const int NO_WND;
00101
00102 protected:
00104 TabWnd();
00105
00106
00108 const TabBar* GetTabBar() const;
00109 const std::vector<std::pair<Wnd*, std::string> >& Wnds() const;
00111
00112 private:
00113 void TabChanged(int tab_index);
00114
00115 TabBar* m_tab_bar;
00116 std::vector<std::pair<Wnd*, std::string> > m_wnds;
00117 Wnd* m_current_wnd;
00118
00119 friend class boost::serialization::access;
00120 template <class Archive>
00121 void serialize(Archive& ar, const unsigned int version);
00122 };
00123
00124
00128 class GG_API TabBar : public Control
00129 {
00130 public:
00132
00134 typedef boost::signal<void (int)> TabChangedSignalType;
00136
00138 typedef TabChangedSignalType::slot_type TabChangedSlotType;
00139
00140
00142
00143 TabBar(int x, int y, int w, const boost::shared_ptr<Font>& font, Clr color, Clr text_color = CLR_BLACK,
00144 TabBarStyle style = TAB_BAR_ATTACHED, Flags<WndFlag> flags = CLICKABLE);
00146
00148 virtual Pt MinUsableSize() const;
00149
00153 int CurrentTabIndex() const;
00155
00157 virtual void SizeMove(const Pt& ul, const Pt& lr);
00158 virtual void Render();
00159
00163 int AddTab(const std::string& name);
00164
00168 void InsertTab(int index, const std::string& name);
00169
00172 void RemoveTab(const std::string& name);
00173
00176 void SetCurrentTab(int index);
00178
00179 mutable TabChangedSignalType TabChangedSignal;
00180
00182 static const int NO_TAB;
00183
00185 static const int BUTTON_WIDTH;
00186
00187 protected:
00189 TabBar();
00190
00191
00193 const Button* LeftButton() const;
00194 const Button* RightButton() const;
00196
00198 virtual bool EventFilter(Wnd* w, const WndEvent& event);
00200
00201 private:
00202 virtual void DistinguishCurrentTab(const std::vector<StateButton*>& tab_buttons);
00203
00204 void TabChanged(int index);
00205 void LeftClicked();
00206 void RightClicked();
00207 void BringTabIntoView(int index);
00208
00209 RadioButtonGroup* m_tabs;
00210 std::vector<StateButton*> m_tab_buttons;
00211 boost::shared_ptr<Font> m_font;
00212 Button* m_left_button;
00213 Button* m_right_button;
00214 Layout* m_left_right_button_layout;
00215 Flags<TextFormat> m_format;
00216 Clr m_text_color;
00217 TabBarStyle m_style;
00218 int m_first_tab_shown;
00219
00220 friend class boost::serialization::access;
00221 template <class Archive>
00222 void serialize(Archive& ar, const unsigned int version);
00223 };
00224
00225 }
00226
00227
00228 template <class Archive>
00229 void GG::TabWnd::serialize(Archive& ar, const unsigned int version)
00230 {
00231 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Wnd)
00232 & BOOST_SERIALIZATION_NVP(m_tab_bar)
00233 & BOOST_SERIALIZATION_NVP(m_wnds)
00234 & BOOST_SERIALIZATION_NVP(m_current_wnd);
00235 }
00236
00237 template <class Archive>
00238 void GG::TabBar::serialize(Archive& ar, const unsigned int version)
00239 {
00240 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Control)
00241 & BOOST_SERIALIZATION_NVP(m_tabs)
00242 & BOOST_SERIALIZATION_NVP(m_tab_buttons)
00243 & BOOST_SERIALIZATION_NVP(m_font)
00244 & BOOST_SERIALIZATION_NVP(m_left_button)
00245 & BOOST_SERIALIZATION_NVP(m_right_button)
00246 & BOOST_SERIALIZATION_NVP(m_left_right_button_layout)
00247 & BOOST_SERIALIZATION_NVP(m_format)
00248 & BOOST_SERIALIZATION_NVP(m_text_color)
00249 & BOOST_SERIALIZATION_NVP(m_style)
00250 & BOOST_SERIALIZATION_NVP(m_first_tab_shown);
00251 }
00252
00253 #endif