1 ///////////////////////////////////////// 2 // 3 // OpenLieroX 4 // 5 // code under LGPL, based on JasonBs work, 6 // enhanced by Dark Charlie and Albert Zeyer 7 // 8 // 9 ///////////////////////////////////////// 10 11 12 // Combo box 13 // Created 3/9/02 14 // Jason Boettcher 15 16 17 #ifndef __CCOMBOBOX_H__DEPRECATED_GUI__ 18 #define __CCOMBOBOX_H__DEPRECATED_GUI__ 19 20 #include <list> 21 22 #include "StringUtils.h" 23 #include "InputEvents.h" 24 #include "DeprecatedGUI/CScrollbar.h" 25 #include "DynDraw.h" 26 27 namespace DeprecatedGUI { 28 29 // Combo box events 30 enum { 31 CMB_NONE=-1, 32 CMB_CHANGED 33 }; 34 35 // Combobox messages 36 enum { 37 CBS_ADDITEM, 38 CBS_ADDSITEM, 39 CBM_GETCOUNT, 40 CBM_GETCURINDEX, 41 CBS_GETCURSINDEX, 42 CBM_GETCURITEM, 43 CBS_GETCURNAME, 44 CBM_CLEAR, 45 CBM_SETCURSEL, 46 CBS_SETCURSINDEX, 47 CBM_SETCURINDEX, 48 CBM_ISDROPPED, 49 CBM_SETSORTED, 50 CBM_SETUNIQUE 51 }; 52 53 // Sorting directions 54 enum { 55 SORT_DESC = -1, 56 SORT_NONE = 0, 57 SORT_ASC = 1 58 }; 59 60 61 // Item structure 62 struct cb_item_t { 63 std::string sIndex; 64 std::string sName; 65 SmartPointer<DynDrawIntf> tImage; 66 int iTag; 67 }; 68 69 70 71 class CCombobox : public CWidget { 72 public: 73 // Constructor CCombobox()74 CCombobox() { 75 iSelected = 0; 76 bGotScrollbar = false; 77 bDropped = false; 78 bArrowDown = false; 79 bLastDropped = false; 80 iDropTime = AbsTime(); 81 iNow = AbsTime(); 82 bCanSearch = true; 83 iKeySelectedItem = -1; 84 iSortDirection = SORT_NONE; 85 bUnique = false; 86 bFingerDragged = false; 87 iFingerDraggedPos = 0; 88 iType = wid_Combobox; 89 } 90 91 92 private: 93 // Attributes 94 95 // Items 96 std::list<cb_item_t> tItems; 97 int iSelected; 98 bool bGotScrollbar; 99 bool bDropped; 100 bool bArrowDown; 101 bool bLastDropped; 102 bool bFingerDragged; 103 int iFingerDraggedPos; 104 AbsTime iDropTime; 105 AbsTime iNow; 106 int iKeySelectedItem; 107 108 // Stuff 109 bool bCanSearch; 110 int iSortDirection; 111 bool bUnique; 112 113 // Scrollbar 114 CScrollbar cScrollbar; 115 116 private: 117 cb_item_t* getItemRW(int index); 118 void Sort(bool ascending); 119 void Unique(); 120 std::list<cb_item_t>::iterator lowerBound(const cb_item_t& item, int *index, bool *equal); 121 std::list<cb_item_t>::iterator upperBound(const cb_item_t& item, int *index, bool *equal); 122 123 public: 124 // Methods 125 126 void Create(); 127 void Destroy(); 128 129 //These events return an event id, otherwise they return -1 130 int MouseOver(mouse_t *tMouse); 131 int MouseUp(mouse_t *tMouse, int nDown); 132 int MouseDown(mouse_t *tMouse, int nDown); 133 int MouseWheelDown(mouse_t *tMouse); 134 int MouseWheelUp(mouse_t *tMouse); KeyUp(UnicodeChar c,int keysym,const ModifiersState & modstate)135 int KeyUp(UnicodeChar c, int keysym, const ModifiersState& modstate) { bCanSearch = true; return CMB_NONE; } 136 int KeyDown(UnicodeChar c, int keysym, const ModifiersState& modstate); 137 138 void Draw(SDL_Surface * bmpDest); 139 140 DWORD SendMessage(int iMsg, DWORD Param1, DWORD Param2); 141 DWORD SendMessage(int iMsg, const std::string& sStr, DWORD Param); 142 DWORD SendMessage(int iMsg, std::string *sStr, DWORD Param); 143 144 void clear(); 145 int addItem(const std::string& sindex, const std::string& name, const SmartPointer<DynDrawIntf>& img = NULL, int tag = 0); 146 int addItem(int index, const std::string& sindex, const std::string& name, const SmartPointer<DynDrawIntf>& img = NULL, int tag = 0); getItems()147 const std::list<cb_item_t>& getItems() { return tItems; } 148 const cb_item_t* getItem(int index) const; 149 int getItemIndex(const cb_item_t* item); 150 int getItemsCount(); 151 const cb_item_t* getItem(const std::string& name) const; 152 const cb_item_t* getSIndexItem(const std::string& sIndex) const; 153 int getIndexBySIndex(const std::string& szName); 154 int getIndexByName(const std::string& szName); 155 void setCurItem(int index); 156 void setCurItem(const cb_item_t* item); 157 void setCurSIndexItem(const std::string& szString); 158 void setCurItemByName(const std::string& szString); 159 bool selectNext(); 160 bool selectPrev(); 161 int findItem(UnicodeChar startLetter); 162 void setImage(const SmartPointer<DynDrawIntf>& img, int ItemIndex); 163 int getSelectedIndex(); 164 const cb_item_t* getSelectedItem(); getDropped()165 bool getDropped() { return bDropped; } 166 void setSorted(int sort_direction); 167 int getSorted(); 168 void setUnique(bool _u); 169 bool getUnique(); 170 int getItemHeight(); 171 int getItemHeightExpanded(); 172 173 const cb_item_t* getLastItem(); 174 }; 175 176 } // namespace DeprecatedGUI 177 178 #endif // __CCOMBOBOX_H__DEPRECATED_GUI__ 179