dialogbase.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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/dialogbase.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 12/03/01 5:09p $*
  29. * *
  30. * $Revision:: 19 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __DIALOG_BASE_H
  39. #define __DIALOG_BASE_H
  40. #include "vector.h"
  41. #include "vector3.h"
  42. #include "rect.h"
  43. #include "refcount.h"
  44. #include "bittype.h"
  45. #include "widestring.h"
  46. #include "controladvisesink.h"
  47. #include "win.h"
  48. #include "notify.h"
  49. ////////////////////////////////////////////////////////////////
  50. // Forward declarations
  51. ////////////////////////////////////////////////////////////////
  52. class DialogControlClass;
  53. class MenuDialogClass;
  54. class PopupDialogClass;
  55. class ChildDialogClass;
  56. class DialogBaseClass;
  57. class DialogTransitionClass;
  58. ////////////////////////////////////////////////////////////////
  59. // Usefull Macros
  60. ////////////////////////////////////////////////////////////////
  61. #define START_DIALOG(class_name) \
  62. { class_name *dialog = new class_name; \
  63. dialog->Start_Dialog (); \
  64. REF_PTR_RELEASE (dialog); }
  65. ////////////////////////////////////////////////////////////////
  66. // Typedefs
  67. ////////////////////////////////////////////////////////////////
  68. typedef bool (CALLBACK *DEFAULT_DLG_CMD_HANDLER) (DialogBaseClass *dialog, int ctrl_id, int mesage_id, DWORD param);
  69. class DialogEvent :
  70. public TypedEventPtr<DialogEvent, DialogBaseClass>
  71. {
  72. public:
  73. typedef enum
  74. {
  75. STARTED = 1,
  76. DESTROY,
  77. ACTIVATED,
  78. DEACTIVATED,
  79. } EventID;
  80. //! Retrieve event
  81. inline EventID GetEventID(void) const
  82. {return mEvent;}
  83. DialogEvent(EventID event, DialogBaseClass* dialog) :
  84. TypedEventPtr<DialogEvent, DialogBaseClass>(dialog),
  85. mEvent(event)
  86. {}
  87. private:
  88. EventID mEvent;
  89. };
  90. ////////////////////////////////////////////////////////////////
  91. //
  92. // DialogBaseClass
  93. //
  94. // These dialogs are analagous to Windows dialogs. They are
  95. // initialized from an RC file, however the dialog template is
  96. // only parsed - the window isn't actually created.
  97. //
  98. ////////////////////////////////////////////////////////////////
  99. class DialogBaseClass : public RefCountClass, public ControlAdviseSinkClass,
  100. public Notifier<DialogEvent>
  101. {
  102. public:
  103. ////////////////////////////////////////////////////////////////
  104. // Public friends
  105. ////////////////////////////////////////////////////////////////
  106. friend class DialogMgrClass;
  107. ////////////////////////////////////////////////////////////////
  108. // Public constructors/destructors
  109. ////////////////////////////////////////////////////////////////
  110. DialogBaseClass (int res_id);
  111. virtual ~DialogBaseClass (void);
  112. ////////////////////////////////////////////////////////////////
  113. // Public methods
  114. ////////////////////////////////////////////////////////////////
  115. //
  116. // RTTI
  117. //
  118. virtual MenuDialogClass * As_MenuDialogClass (void) { return NULL; }
  119. virtual PopupDialogClass * As_PopupDialogClass (void) { return NULL; }
  120. virtual ChildDialogClass * As_ChildDialogClass (void) { return NULL; }
  121. int Get_Dlg_ID(void) const {return DialogResID;}
  122. //
  123. // Display methods
  124. //
  125. virtual void Render (void);
  126. void Show (bool onoff) { IsVisible = onoff; }
  127. bool Is_Visible (void) const { return IsVisible; }
  128. void Set_Dirty(bool onoff=true);
  129. //
  130. // Position control
  131. //
  132. const RectClass & Get_Rect (void) const { return Rect; }
  133. void Set_Rect (const RectClass &rect);
  134. //
  135. // Flow control
  136. //
  137. virtual void Start_Dialog (void);
  138. virtual void End_Dialog (void);
  139. virtual bool Is_Running (void) { return IsRunning; }
  140. //
  141. // Control access
  142. //
  143. DialogControlClass * Get_Dlg_Item (int id) const;
  144. DialogControlClass * Find_Control (const Vector2 &mouse_pos);
  145. void Add_Control (DialogControlClass *control);
  146. void Remove_Control (DialogControlClass *control);
  147. DialogControlClass * Find_Next_Control (DialogControlClass *control, int direction = 1);
  148. DialogControlClass * Find_Next_Group_Control (DialogControlClass *control, int direction = 1);
  149. int Get_Control_Count (void) const { return ControlList.Count (); }
  150. DialogControlClass * Get_Control (int index) const { return ControlList[index]; }
  151. //
  152. // Control enable state access
  153. //
  154. void Enable_Dlg_Item (int id, bool onoff);
  155. bool Is_Dlg_Item_Enabled (int id);
  156. //
  157. // Control text access
  158. //
  159. const WCHAR * Get_Dlg_Item_Text (int id) const;
  160. void Set_Dlg_Item_Text (int id, const WCHAR *text);
  161. int Get_Dlg_Item_Int (int id) const;
  162. void Set_Dlg_Item_Int (int id, int value);
  163. float Get_Dlg_Item_Float (int id) const;
  164. void Set_Dlg_Item_Float (int id, float value);
  165. //
  166. // Control "check" access
  167. //
  168. void Check_Dlg_Button (int id, bool onoff);
  169. bool Is_Dlg_Button_Checked (int id) const;
  170. //
  171. // Child dialog access
  172. //
  173. void Add_Child_Dialog (ChildDialogClass *child);
  174. void Remove_Child_Dialog (ChildDialogClass *child);
  175. //
  176. // Title access
  177. //
  178. void Get_Title (WideStringClass *title) { *title = Title; }
  179. void Set_Title (const WCHAR *title) { Title = title; }
  180. //
  181. // Activation access
  182. //
  183. virtual bool Is_Active (void);
  184. virtual bool Wants_Activation (void) { return true; }
  185. //
  186. // Transition control
  187. //
  188. virtual DialogTransitionClass * Get_Transition_In (DialogBaseClass *prev_dlg) { return NULL; }
  189. virtual DialogTransitionClass * Get_Transition_Out (DialogBaseClass *next_dlg) { return NULL; }
  190. virtual void Set_Controls_Hidden (bool onoff) { AreControlsHidden = onoff; }
  191. virtual bool Are_Controls_Hidden (void) const { return AreControlsHidden; }
  192. //
  193. // Notifications
  194. //
  195. virtual void On_Command (int ctrl_id, int mesage_id, DWORD param);
  196. //
  197. // Default processing support
  198. //
  199. static void Set_Default_Command_Handler (DEFAULT_DLG_CMD_HANDLER ptr) { DefaultCmdHandler = ptr; }
  200. static DEFAULT_DLG_CMD_HANDLER Get_Default_Command_Handler (void) { return DefaultCmdHandler; }
  201. DECLARE_NOTIFIER(DialogEvent)
  202. protected:
  203. ////////////////////////////////////////////////////////////////
  204. // Protected typedefs
  205. ////////////////////////////////////////////////////////////////
  206. typedef DynamicVectorClass<DialogControlClass *> CONTROL_LIST;
  207. typedef DynamicVectorClass<ChildDialogClass *> DIALOG_LIST;
  208. ////////////////////////////////////////////////////////////////
  209. // Protected methods
  210. ////////////////////////////////////////////////////////////////
  211. virtual void On_Init_Dialog (void);
  212. virtual void On_Destroy (void) {}
  213. virtual void On_Activate (bool onoff);
  214. virtual bool On_Key_Down (uint32 key_id, uint32 key_data);
  215. virtual void On_Unicode_Char(uint16 unicode);
  216. virtual void On_Mouse_Wheel (int direction);
  217. virtual bool On_Key_Up (uint32 key_id);
  218. virtual void On_Frame_Update (void);
  219. virtual void On_Periodic (void) {}
  220. void Free_Controls (void);
  221. void Update_Mouse_State (void);
  222. int Find_Focus_Control (void);
  223. int Find_Control_Index (DialogControlClass *control);
  224. void Send_Mouse_Input (DialogControlClass *control, const Vector2 &mouse_pos);
  225. void Build_Control_List (CONTROL_LIST &list);
  226. void Set_Default_Focus (void);
  227. ////////////////////////////////////////////////////////////////
  228. // Protected member data
  229. ////////////////////////////////////////////////////////////////
  230. WideStringClass Title;
  231. RectClass Rect;
  232. int DialogResID;
  233. CONTROL_LIST ControlList;
  234. DIALOG_LIST ChildDialogList;
  235. DialogControlClass * LastFocusControl;
  236. bool IsVisible;
  237. bool AreControlsHidden;
  238. bool IsRunning;
  239. int LastMouseClickTime;
  240. static DEFAULT_DLG_CMD_HANDLER DefaultCmdHandler;
  241. };
  242. #endif //__DIALOG_BASE_H