listctrl.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/listctrl.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 10/26/01 4:10p $*
  29. * *
  30. * $Revision:: 19 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __LIST_CTRL_H
  39. #define __LIST_CTRL_H
  40. #include "dialogcontrol.h"
  41. #include "vector3.h"
  42. #include "vector.h"
  43. #include "render2d.h"
  44. #include "bittype.h"
  45. #include "scrollbarctrl.h"
  46. #include "render2dsentence.h"
  47. #include "listiconmgr.h"
  48. ////////////////////////////////////////////////////////////////
  49. // Forward declarations
  50. ////////////////////////////////////////////////////////////////
  51. class ListColumnClass;
  52. class ListCtrlClass;
  53. class ListRowClass;
  54. class TextureClass;
  55. ////////////////////////////////////////////////////////////////
  56. // Typedefs
  57. ////////////////////////////////////////////////////////////////
  58. typedef int (CALLBACK *LISTCTRL_SORT_CALLBACK) (ListCtrlClass *list_ctrl, int item_index1, int item_index2, uint32 user_param);
  59. ////////////////////////////////////////////////////////////////
  60. //
  61. // ListCtrlClass
  62. //
  63. ////////////////////////////////////////////////////////////////
  64. class ListCtrlClass : public DialogControlClass
  65. {
  66. public:
  67. ////////////////////////////////////////////////////////////////
  68. // Public constants
  69. ////////////////////////////////////////////////////////////////
  70. typedef enum
  71. {
  72. SORT_NONE = 0,
  73. SORT_ASCENDING,
  74. SORT_DESCENDING
  75. } SORT_TYPE;
  76. ////////////////////////////////////////////////////////////////
  77. // Public constructors/destructors
  78. ////////////////////////////////////////////////////////////////
  79. ListCtrlClass (void);
  80. virtual ~ListCtrlClass (void);
  81. ////////////////////////////////////////////////////////////////
  82. // Public methods
  83. ////////////////////////////////////////////////////////////////
  84. // RTTI
  85. virtual ListCtrlClass * As_ListCtrlClass (void) { return this; }
  86. //
  87. // From DialogControlClass
  88. //
  89. void Render (void);
  90. void Set_Tabstop(float stop);
  91. //
  92. // Column support
  93. //
  94. void Auto_Size_Columns (float col_spacing = 2.0F);
  95. void Auto_Size_Columns_Include_Contents (float col_spacing = 2.0F);
  96. void Add_Column (const WCHAR *column_name, float width, const Vector3 &color);
  97. void Set_Column_Color (int col_index, const Vector3 &color);
  98. bool Remove_Column (int col_index);
  99. void Delete_All_Columns (void);
  100. int Get_Column_Count(void) const;
  101. //
  102. // Content control
  103. //
  104. int Find_Entry(int col_index, const WCHAR* text);
  105. int Insert_Entry (int index, const WCHAR *text);
  106. bool Set_Entry_Text (int index, int col_index, const WCHAR *text);
  107. bool Set_Entry_Int (int index, int col_index, int value);
  108. bool Set_Entry_Color (int index, int col_index, const Vector3 &color);
  109. bool Set_Entry_Data (int index, int col_index, uint32 user_data);
  110. bool Select_Entry (int index, bool onoff);
  111. uint32 Get_Entry_Data (int index, int col_index);
  112. const WCHAR * Get_Entry_Text (int index, int col_index);
  113. bool Is_Entry_Selected (int index);
  114. bool Delete_Entry (int index);
  115. void Delete_All_Entries (void);
  116. int Get_Entry_Count (void) const;
  117. //
  118. // Row height support
  119. //
  120. void Set_Min_Row_Height (int height);
  121. int Get_Min_Row_Height (void) const { return MinRowHeight; }
  122. //
  123. // Icon support
  124. //
  125. void Add_Icon (int index, int col_index, const char *texture_name);
  126. void Reset_Icons (int index, int col_index);
  127. void Set_Icon_Size (float width, float height);
  128. //
  129. // Selection support
  130. //
  131. int Get_Curr_Sel (void) const { return CurrSel; }
  132. void Set_Curr_Sel (int new_sel);
  133. void Allow_Selection(bool onoff) {IsSelectionAllowed = onoff;}
  134. void Allow_NoSelection(bool onoff) {IsNoSelectionAllowed = onoff;}
  135. void Allow_Multiple_Selection (bool onoff) { IsMultipleSelection = onoff; }
  136. int Get_First_Selected (void) const;
  137. int Get_Next_Selected (int index) const;
  138. void Select_All (bool select = true);
  139. bool Toggle_Entry_Selection (int index);
  140. //
  141. // Sort support
  142. //
  143. void Sort (LISTCTRL_SORT_CALLBACK sort_callback, uint32 user_param);
  144. void Set_Sort_Designator (int col_index, SORT_TYPE type);
  145. void Sort_Alphabetically (int col_index, SORT_TYPE type);
  146. //
  147. // Scroll support
  148. //
  149. void Scroll_To_End (void);
  150. //
  151. // Advise-sink callbacks
  152. //
  153. void On_VScroll (ScrollBarCtrlClass *scrollbar, int ctrl_id, int new_position);
  154. void On_VScroll_Page (ScrollBarCtrlClass *scrollbar, int ctrl_id, int direction);
  155. protected:
  156. ////////////////////////////////////////////////////////////////
  157. // Protected methods
  158. ////////////////////////////////////////////////////////////////
  159. void Set_Sel (int new_sel, bool notify);
  160. void On_LButton_Down (const Vector2 &mouse_pos);
  161. void On_LButton_DblClk (const Vector2 &mouse_pos);
  162. void On_LButton_Up (const Vector2 &mouse_pos);
  163. void On_Mouse_Move (const Vector2 &mouse_pos);
  164. void On_Mouse_Wheel (int direction);
  165. void On_Set_Cursor (const Vector2 &mouse_pos);
  166. void On_Set_Focus (void);
  167. void On_Kill_Focus (DialogControlClass *focus);
  168. bool On_Key_Down (uint32 key_id, uint32 key_data);
  169. void On_Create (void);
  170. void On_Destroy (void);
  171. void Update_Client_Rect (void);
  172. void Create_Control_Renderer (void);
  173. void Create_Text_Renderers (void);
  174. int Entry_From_Pos (const Vector2 &mouse_pos);
  175. int Col_From_Pos (const Vector2 &mouse_pos);
  176. void Get_Entry_Rect (int index, RectClass &rect);
  177. void Update_Scroll_Pos (void);
  178. void Update_Scroll_Bar_Visibility (void);
  179. void Update_Row_Height (int row_index);
  180. void Quick_Sort (int start_index, int end_index, LISTCTRL_SORT_CALLBACK sort_callback, uint32 user_param);
  181. int Find_Last_Page_Top_Entry (void);
  182. void Scroll_Page (int direction);
  183. int Find_End_Of_Page (void);
  184. int Find_Top_Of_Page (int bottom_index);
  185. void Render_Entry (const RectClass &rect, int col_index, int row_index);
  186. static int CALLBACK Default_Sort_Callback (ListCtrlClass *list_ctrl, int item_index1, int item_index2, uint32 user_param);
  187. ////////////////////////////////////////////////////////////////
  188. // Protected constants
  189. ////////////////////////////////////////////////////////////////
  190. enum
  191. {
  192. NORMAL = 0,
  193. DISABLED,
  194. STATE_MAX
  195. };
  196. ////////////////////////////////////////////////////////////////
  197. // Protected typedefs
  198. ////////////////////////////////////////////////////////////////
  199. typedef DynamicVectorClass<ListColumnClass *> COL_LIST;
  200. typedef DynamicVectorClass<ListRowClass *> ROW_LIST;
  201. ////////////////////////////////////////////////////////////////
  202. // Protected member data
  203. ////////////////////////////////////////////////////////////////
  204. Render2DClass HilightRenderer;
  205. Render2DClass ControlRenderer;
  206. Render2DClass UnderlineRenderer;
  207. Render2DSentenceClass HeaderRenderer;
  208. Render2DSentenceClass TextRenderer;
  209. ListIconMgrClass IconMgr;
  210. int RowBorderHeight;
  211. int ScrollPos;
  212. int CurrSel;
  213. int CurrState;
  214. int LastPageTopEntryIndex;
  215. ScrollBarCtrlClass ScrollBarCtrl;
  216. bool IsScrollBarDisplayed;
  217. bool IsSelectionAllowed;
  218. bool IsNoSelectionAllowed;
  219. bool IsMultipleSelection;
  220. int SortColumn;
  221. SORT_TYPE SortType;
  222. float PulsePercent;
  223. float PulseDirection;
  224. float MinRowHeight;
  225. RectClass TextRect;
  226. RectClass HeaderRect;
  227. COL_LIST ColList;
  228. ROW_LIST RowInfoList;
  229. };
  230. ////////////////////////////////////////////////////////////////
  231. //
  232. // ListEntryClass
  233. //
  234. ////////////////////////////////////////////////////////////////
  235. class ListEntryClass
  236. {
  237. public:
  238. ////////////////////////////////////////////////////////////////
  239. // Public constructors/destructors
  240. ////////////////////////////////////////////////////////////////
  241. ListEntryClass (void) :
  242. Name (L""),
  243. Color (1, 1, 1),
  244. UserData (0) {}
  245. ListEntryClass (const WCHAR *name) :
  246. Name (name),
  247. Color (1, 1, 1),
  248. UserData (0) {}
  249. ~ListEntryClass (void) { Reset_Icons (); }
  250. ////////////////////////////////////////////////////////////////
  251. // Public methods
  252. ////////////////////////////////////////////////////////////////
  253. //
  254. // Name access
  255. //
  256. const WCHAR * Get_Name (void) const { return Name; }
  257. void Set_Name (const WCHAR *name) { Name = name; }
  258. //
  259. // Color access
  260. //
  261. const Vector3 & Get_Color (void) const { return Color; }
  262. void Set_Color (const Vector3 &color) { Color = color; }
  263. //
  264. // User data access
  265. //
  266. uint32 Get_User_Data (void) const { return UserData; }
  267. void Set_User_Data (uint32 user_data) { UserData = user_data; }
  268. //
  269. // Icon support
  270. //
  271. int Get_Icon_Count (void) const { return IconList.Count (); }
  272. const char * Get_Icon (int index) { return IconList[index]; }
  273. void Add_Icon (const char *name) { IconList.Add (name); }
  274. void Reset_Icons (void) { IconList.Delete_All (); }
  275. private:
  276. ////////////////////////////////////////////////////////////////
  277. // Private member data
  278. ////////////////////////////////////////////////////////////////
  279. WideStringClass Name;
  280. Vector3 Color;
  281. uint32 UserData;
  282. DynamicVectorClass<StringClass> IconList;
  283. };
  284. ////////////////////////////////////////////////////////////////
  285. //
  286. // ListColumnClass
  287. //
  288. ////////////////////////////////////////////////////////////////
  289. class ListColumnClass
  290. {
  291. public:
  292. ////////////////////////////////////////////////////////////////
  293. // Public constructors/destructors
  294. ////////////////////////////////////////////////////////////////
  295. ListColumnClass (void) :
  296. Width (0) { Reset_Contents (); }
  297. ~ListColumnClass (void) { Free_Data (); }
  298. ////////////////////////////////////////////////////////////////
  299. // Public operators
  300. ////////////////////////////////////////////////////////////////
  301. bool operator== (const ListColumnClass &src) const { return false; }
  302. bool operator!= (const ListColumnClass &src) const { return true; }
  303. ////////////////////////////////////////////////////////////////
  304. // Public methods
  305. ////////////////////////////////////////////////////////////////
  306. //
  307. // Name access
  308. //
  309. const WCHAR * Get_Name (void) const { return Header.Get_Name (); }
  310. void Set_Name (const WCHAR *name) { Header.Set_Name (name); }
  311. //
  312. // Width access
  313. //
  314. float Get_Width (void) const { return Width; }
  315. void Set_Width (float width) { Width = width; }
  316. //
  317. // Color access
  318. //
  319. const Vector3 & Get_Color (void) const { return Header.Get_Color (); }
  320. void Set_Color (const Vector3 &color) { Header.Set_Color (color); }
  321. //
  322. // Entry access
  323. //
  324. void Move_Entry (int old_index, int new_index);
  325. void Swap_Entries (int index1, int index2);
  326. int Insert_Entry (int index, const WCHAR *entry_name);
  327. int Get_Entry_Count (void) const { return EntryList.Count (); }
  328. bool Delete_Entry (int index);
  329. void Delete_All_Entries (void);
  330. void Set_Entry_Text (int index, const WCHAR *text) { EntryList[index]->Set_Name (text); }
  331. const WCHAR * Get_Entry_Text (int index) const { return EntryList[index]->Get_Name (); }
  332. void Set_Entry_Color (int index, const Vector3 &color) { EntryList[index]->Set_Color (color); }
  333. const Vector3 & Get_Entry_Color (int index) const { return EntryList[index]->Get_Color (); }
  334. void Set_Entry_Data (int index, uint32 data) { EntryList[index]->Set_User_Data (data); }
  335. uint32 Get_Entry_Data (int index) const { return EntryList[index]->Get_User_Data (); }
  336. int Get_Icon_Count (int index) const { return EntryList[index]->Get_Icon_Count (); }
  337. const char * Get_Icon (int index, int icon_index) { return EntryList[index]->Get_Icon (icon_index); }
  338. void Add_Icon (int index, const char *name) { EntryList[index]->Add_Icon (name); }
  339. void Reset_Icons (int index) { EntryList[index]->Reset_Icons (); }
  340. //
  341. // Cleanup
  342. //
  343. void Reset_Contents (void);
  344. private:
  345. ////////////////////////////////////////////////////////////////
  346. // Private methods
  347. ////////////////////////////////////////////////////////////////
  348. void Free_Data (void);
  349. ////////////////////////////////////////////////////////////////
  350. // Private data types
  351. ////////////////////////////////////////////////////////////////
  352. typedef DynamicVectorClass<ListEntryClass *> ENTRY_LIST;
  353. ////////////////////////////////////////////////////////////////
  354. // Private member data
  355. ////////////////////////////////////////////////////////////////
  356. ListEntryClass Header;
  357. ENTRY_LIST EntryList;
  358. float Width;
  359. };
  360. ////////////////////////////////////////////////////////////////
  361. //
  362. // ListRowClass
  363. //
  364. ////////////////////////////////////////////////////////////////
  365. class ListRowClass
  366. {
  367. public:
  368. ////////////////////////////////////////////////////////////////
  369. // Public constructors/destructors
  370. ////////////////////////////////////////////////////////////////
  371. ListRowClass (void) :
  372. Height (0),
  373. IsSelected (false) { }
  374. ~ListRowClass (void) { }
  375. ////////////////////////////////////////////////////////////////
  376. // Public operators
  377. ////////////////////////////////////////////////////////////////
  378. bool operator== (const ListRowClass &src) const { return false; }
  379. bool operator!= (const ListRowClass &src) const { return true; }
  380. ////////////////////////////////////////////////////////////////
  381. // Public methods
  382. ////////////////////////////////////////////////////////////////
  383. //
  384. // Height access
  385. //
  386. float Get_Height (void) const { return Height; }
  387. void Set_Height (float height) { Height = height; }
  388. //
  389. // Selection access
  390. //
  391. bool Is_Selected (void) const { return IsSelected; }
  392. void Select (bool onoff) { IsSelected = onoff; }
  393. private:
  394. ////////////////////////////////////////////////////////////////
  395. // Private member data
  396. ////////////////////////////////////////////////////////////////
  397. float Height;
  398. bool IsSelected;
  399. };
  400. #endif //__LIST_CTRL_H