DropDownList.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
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 }
00198
00199
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_