GG
|
00001 // -*- C++ -*- 00002 /* GG is a GUI for SDL and OpenGL. 00003 Copyright (C) 2003-2008 T. Zachary Laine 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public License 00007 as published by the Free Software Foundation; either version 2.1 00008 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00018 02111-1307 USA 00019 00020 If you do not wish to comply with the terms of the LGPL please 00021 contact the author as other terms are available for a fee. 00022 00023 Zach Laine 00024 whatwasthataddress@gmail.com */ 00025 00031 #ifndef _GG_DropDownList_h_ 00032 #define _GG_DropDownList_h_ 00033 00034 #include <GG/ListBox.h> 00035 00036 00037 namespace GG { 00038 00052 class GG_API DropDownList : public Control 00053 { 00054 public: 00056 typedef ListBox::Row Row; 00057 00058 typedef ListBox::iterator iterator; 00059 typedef ListBox::const_iterator const_iterator; 00060 typedef ListBox::reverse_iterator reverse_iterator; 00061 typedef ListBox::const_reverse_iterator const_reverse_iterator; 00062 00064 typedef boost::signal<void (iterator)> SelChangedSignalType; 00065 00066 00068 00069 DropDownList(X x, Y y, X w, Y h, Y drop_ht, Clr color, Flags<WndFlag> flags = INTERACTIVE); 00070 00071 ~DropDownList(); 00072 00073 00075 iterator CurrentItem() const; 00076 std::size_t CurrentItemIndex() const; 00077 00078 std::size_t IteratorToIndex(iterator it) const; 00079 iterator IndexToIterator(std::size_t n) const; 00080 00081 bool Empty() const; 00082 const_iterator begin() const; 00083 const_iterator end() const; 00084 const_reverse_iterator 00085 rbegin() const; 00086 const_reverse_iterator 00087 rend() const; 00088 const Row& GetRow(std::size_t n) const; 00089 bool Selected(iterator it) const; 00090 bool Selected(std::size_t n) const; 00091 Clr InteriorColor() const; 00092 00093 Y DropHeight() const; 00094 00096 Flags<ListBoxStyle> Style() const; 00097 00098 std::size_t NumRows() const; 00099 std::size_t NumCols() const; 00100 00104 std::size_t SortCol() const; 00105 00106 X ColWidth(std::size_t n) const; 00107 Alignment ColAlignment(std::size_t n) const; 00108 Alignment RowAlignment(iterator it) const; 00109 00110 virtual Pt ClientUpperLeft() const; 00111 virtual Pt ClientLowerRight() const; 00112 00113 mutable SelChangedSignalType SelChangedSignal; 00114 00115 00117 virtual void Render(); 00118 00119 virtual void SizeMove(const Pt& ul, const Pt& lr); 00120 00121 virtual void SetColor(Clr c); 00122 00127 iterator Insert(Row* row, iterator it); 00128 00133 iterator Insert(Row* row); 00134 00135 Row* Erase(iterator it); 00136 void Clear(); 00137 iterator begin(); 00138 iterator end(); 00139 reverse_iterator 00140 rbegin(); 00141 reverse_iterator 00142 rend(); 00143 Row& GetRow(std::size_t n); 00144 00145 void Select(iterator it); 00146 void Select(std::size_t n); 00147 00148 void SetInteriorColor(Clr c); 00149 void SetDropHeight(Y h); 00150 00152 void SetStyle(Flags<ListBoxStyle> s); 00153 00154 void SetNumCols(std::size_t n); 00155 void SetSortCol(std::size_t n); 00156 void SetColWidth(std::size_t n, X w); 00157 00162 void LockColWidths(); 00163 00166 void UnLockColWidths(); 00167 00168 void SetColAlignment(std::size_t n, Alignment align); 00169 void SetRowAlignment(iterator it, Alignment align); 00170 00171 virtual void DefineAttributes(WndEditor* editor); 00173 00174 protected: 00176 DropDownList(); 00177 00178 00180 virtual void LClick(const Pt& pt, Flags<ModKey> mod_keys); 00181 virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys); 00182 00183 ListBox* LB(); 00184 00185 00186 private: 00187 void SelectImpl(iterator it, bool signal); 00188 00189 iterator m_current_item; 00190 ListBox* m_LB; 00191 00192 friend class boost::serialization::access; 00193 template <class Archive> 00194 void serialize(Archive& ar, const unsigned int version); 00195 }; 00196 00197 } // namespace GG 00198 00199 // template implementations 00200 template <class Archive> 00201 void GG::DropDownList::serialize(Archive& ar, const unsigned int version) 00202 { 00203 std::size_t current_item; 00204 if (Archive::is_saving::value) 00205 current_item = std::distance(m_LB->begin(), m_current_item); 00206 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Control) 00207 & BOOST_SERIALIZATION_NVP(current_item) 00208 & BOOST_SERIALIZATION_NVP(m_LB); 00209 if (Archive::is_loading::value) 00210 m_current_item = boost::next(m_LB->begin(), current_item); 00211 } 00212 00213 #endif // _GG_DropDownList_h_