treectrl.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 : wwui *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/treectrl.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 9/18/01 1:47p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __TREECTRL_H
  39. #define __TREECTRL_H
  40. #include "dialogcontrol.h"
  41. #include "vector.h"
  42. #include "render2dsentence.h"
  43. #include "scrollbarctrl.h"
  44. #include "listiconmgr.h"
  45. //////////////////////////////////////////////////////////////////////
  46. // Forward declarations
  47. //////////////////////////////////////////////////////////////////////
  48. class TreeItemClass;
  49. class TreeCtrlClass;
  50. //////////////////////////////////////////////////////////////////////
  51. // Typedefs
  52. //////////////////////////////////////////////////////////////////////
  53. typedef DynamicVectorClass<TreeItemClass *> TREE_ITEM_LIST;
  54. typedef int (CALLBACK *TREECTRL_SORT_CALLBACK) (TreeCtrlClass *tree_ctrl, TreeItemClass *item1, TreeItemClass *item2, uint32 user_param);
  55. //////////////////////////////////////////////////////////////////////
  56. //
  57. // TreeCtrlClass
  58. //
  59. //////////////////////////////////////////////////////////////////////
  60. class TreeCtrlClass : public DialogControlClass
  61. {
  62. public:
  63. ///////////////////////////////////////////////////////////////////
  64. // Public constants
  65. ///////////////////////////////////////////////////////////////////
  66. typedef enum
  67. {
  68. HIT_PLUS = 0,
  69. HIT_ICON,
  70. HIT_TEXT,
  71. } HITTYPE;
  72. static const char *ICON_FOLDER;
  73. static const char *ICON_FOLDER_OPEN;
  74. ///////////////////////////////////////////////////////////////////
  75. // Public constructors/destructors
  76. ///////////////////////////////////////////////////////////////////
  77. TreeCtrlClass (void);
  78. ~TreeCtrlClass (void);
  79. // RTTI.
  80. virtual TreeCtrlClass * As_TreeCtrlClass (void) { return this; }
  81. ///////////////////////////////////////////////////////////////////
  82. // Public methods
  83. ///////////////////////////////////////////////////////////////////
  84. //
  85. // Inherited
  86. //
  87. void Render (void);
  88. void On_VScroll (ScrollBarCtrlClass *, int, int new_position);
  89. //
  90. // Content control
  91. //
  92. TreeItemClass * Insert_Item (const WCHAR *name, const char *icon_name, const char *selected_icon_name, TreeItemClass *parent);
  93. void Delete_Item (TreeItemClass *item);
  94. void Delete_All_Items (void);
  95. void Select_Item (TreeItemClass *item);
  96. TreeItemClass * Get_Selected_Item (void);
  97. //
  98. // Sort support
  99. //
  100. void Sort_Children_Alphabetically (TreeItemClass *parent);
  101. void Sort_Children (TreeItemClass *parent, TREECTRL_SORT_CALLBACK sort_callback, uint32 user_param);
  102. //
  103. // Misc
  104. //
  105. TreeItemClass * Hit_Test (const Vector2 &mouse_pos, HITTYPE &type);
  106. void Ensure_Visible (TreeItemClass *tree_item);
  107. protected:
  108. ////////////////////////////////////////////////////////////////
  109. // Protected methods
  110. ////////////////////////////////////////////////////////////////
  111. void On_LButton_Down (const Vector2 &mouse_pos);
  112. void On_LButton_DblClk (const Vector2 &mouse_pos);
  113. void On_LButton_Up (const Vector2 &mouse_pos);
  114. void On_Mouse_Wheel (int direction);
  115. void On_Set_Cursor (const Vector2 &mouse_pos);
  116. void On_Set_Focus (void);
  117. void On_Kill_Focus (DialogControlClass *focus);
  118. bool On_Key_Down (uint32 key_id, uint32 key_data);
  119. void On_Create (void);
  120. void Update_Client_Rect (void);
  121. void On_Expanded (TreeItemClass *item);
  122. void Create_Control_Renderers (void);
  123. void Create_Text_Renderers (void);
  124. void Set_Scroll_Pos (int new_pos);
  125. void Update_Scroll_Bar_Visibility (void);
  126. int Count_Visible_Rows (void);
  127. int Count_Visible_Rows (TreeItemClass *item);
  128. TreeItemClass * Get_Prev_Sibling (TreeItemClass *item);
  129. TreeItemClass * Get_Next_Sibling (TreeItemClass *item);
  130. TreeItemClass * Find_Prev_Visible (TreeItemClass *item);
  131. TreeItemClass * Find_Next_Visible (TreeItemClass *item);
  132. TreeItemClass * Find_Top_Item (void);
  133. TreeItemClass * Find_Last_Visible_Item (void);
  134. bool Render_Item (TreeItemClass *item, float x_pos, float &y_pos, int &row_index, int level);
  135. static int __cdecl Sort_Callback (const void *elem1, const void *elem2);
  136. static int CALLBACK Alphabetic_Sort_Callback (TreeCtrlClass *tree_ctrl, TreeItemClass *item1, TreeItemClass *item2, uint32 user_param);
  137. ////////////////////////////////////////////////////////////////
  138. // Protected member data
  139. ////////////////////////////////////////////////////////////////
  140. Render2DClass HilightRenderer;
  141. Render2DSentenceClass TextRenderer;
  142. Render2DClass ControlRenderer;
  143. Render2DClass PlusRenderer;
  144. Render2DClass IconRenderer;
  145. TREE_ITEM_LIST ItemList;
  146. TreeItemClass * SelectedItem;
  147. ListIconMgrClass IconMgr;
  148. float RowHeight;
  149. int RowsPerPage;
  150. int ScrollPos;
  151. ScrollBarCtrlClass ScrollBarCtrl;
  152. bool IsScrollBarDisplayed;
  153. static TREECTRL_SORT_CALLBACK CurrentSortCallback;
  154. static TreeCtrlClass * CurrentSorter;
  155. static uint32 CurrentSortUserData;
  156. friend class TreeItemClass;
  157. };
  158. //////////////////////////////////////////////////////////////////////
  159. //
  160. // TreeItemClass
  161. //
  162. //////////////////////////////////////////////////////////////////////
  163. class TreeItemClass
  164. {
  165. public:
  166. ///////////////////////////////////////////////////////////////////
  167. // Public constructors/destructors
  168. ///////////////////////////////////////////////////////////////////
  169. TreeItemClass (TreeCtrlClass *ctrl) :
  170. TreeCtrl (ctrl),
  171. Parent (NULL),
  172. UserData (0),
  173. IsExpanded (false),
  174. NeedsChildren (false) {}
  175. virtual ~TreeItemClass (void) {}
  176. ///////////////////////////////////////////////////////////////////
  177. // Public methods
  178. ///////////////////////////////////////////////////////////////////
  179. //
  180. // Name access
  181. //
  182. void Set_Name (const WCHAR *name);
  183. const WCHAR * Get_Name (void) const { return Name; }
  184. //
  185. // Icon access
  186. //
  187. void Set_Icon (const char *texture_name);
  188. const char * Get_Icon (void) const { return IconName; }
  189. void Set_Selected_Icon (const char *texture_name);
  190. const char * Get_Selected_Icon (void) const { return SelectedIconName; }
  191. //
  192. // User data access
  193. //
  194. void Set_User_Data (uint32 data) { UserData = data; }
  195. uint32 Get_User_Data (void) const { return UserData; }
  196. //
  197. // Selection control
  198. //
  199. void Select (void) { TreeCtrl->Select_Item (this); }
  200. bool Is_Selected (void) { return (TreeCtrl->Get_Selected_Item () == this); }
  201. //
  202. // Expanded access
  203. //
  204. void Expand (bool onoff);
  205. bool Is_Expanded (void) const { return IsExpanded; }
  206. //
  207. // Child access
  208. //
  209. void Add_Child (TreeItemClass *child) { ChildList.Add (child); NeedsChildren = false; }
  210. void Remove_Child (int index) { ChildList.Delete (index); }
  211. void Remove_Child (TreeItemClass *child);
  212. bool Needs_Children (void) const { return NeedsChildren; }
  213. void Set_Needs_Children (bool onoff);
  214. int Get_Child_Count (void) const { return ChildList.Count (); }
  215. TreeItemClass * Get_Child (int index) { return ChildList[index]; }
  216. TREE_ITEM_LIST & Get_Child_List (void) { return ChildList; }
  217. TreeItemClass * Get_Last_Child (void);
  218. //
  219. // Parent access
  220. //
  221. TreeItemClass * Get_Prev_Child (TreeItemClass *child);
  222. TreeItemClass * Get_Next_Child (TreeItemClass *child);
  223. void Set_Parent (TreeItemClass *parent) { Parent = parent; }
  224. TreeItemClass * Get_Parent (void) const { return Parent; }
  225. //
  226. // Indent access
  227. //
  228. int Get_Indent_Level (void);
  229. protected:
  230. ////////////////////////////////////////////////////////////////
  231. // Protected methods
  232. ////////////////////////////////////////////////////////////////
  233. ////////////////////////////////////////////////////////////////
  234. // Protected member data
  235. ////////////////////////////////////////////////////////////////
  236. TreeCtrlClass * TreeCtrl;
  237. TreeItemClass * Parent;
  238. WideStringClass Name;
  239. StringClass IconName;
  240. StringClass SelectedIconName;
  241. uint32 UserData;
  242. TREE_ITEM_LIST ChildList;
  243. bool IsExpanded;
  244. bool NeedsChildren;
  245. };
  246. #endif //__TREECTRL_H