CallbackEditor.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. ** Command & Conquer Generals(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. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: CallbackEditor.cpp ///////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: GUIEdit
  34. //
  35. // File name: CallbackEditor.cpp
  36. //
  37. // Created: Colin Day, Sepember 2001
  38. //
  39. // Desc: A handy dandy little dialog to just edit the callbacks for
  40. // user windows ... a super convient luxury at a bargain price!
  41. //
  42. //-----------------------------------------------------------------------------
  43. ///////////////////////////////////////////////////////////////////////////////
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. #include <windows.h>
  46. // USER INCLUDES //////////////////////////////////////////////////////////////
  47. #include "Common/Debug.h"
  48. #include "Common/FunctionLexicon.h"
  49. #include "GameClient/Gadget.h"
  50. #include "GameClient/GameWindowManager.h"
  51. #include "GUIEdit.h"
  52. #include "Resource.h"
  53. #include "Properties.h"
  54. // DEFINES ////////////////////////////////////////////////////////////////////
  55. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  56. ///////////////////////////////////////////////////////////////////////////////
  57. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  58. ///////////////////////////////////////////////////////////////////////////////
  59. static char *noNameWindowString = "Un-named Window";
  60. static GameWindow *currentWindow = NULL; ///< current window we're editing
  61. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  62. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  63. ///////////////////////////////////////////////////////////////////////////////
  64. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  65. ///////////////////////////////////////////////////////////////////////////////
  66. // SaveCallbacks ==============================================================
  67. /** save the current callbacks for the selected window */
  68. void SaveCallbacks( GameWindow *window, HWND dialog )
  69. {
  70. // sanity
  71. if( window == NULL || dialog == NULL )
  72. return;
  73. // get edit data for window
  74. GameWindowEditData *editData = window->winGetEditData();
  75. DEBUG_ASSERTCRASH( editData, ("No edit data for window saving callbacks!\n") );
  76. // get the currently selected item from each of the combos and save
  77. Int index;
  78. char buffer[ 256 ];
  79. // system
  80. index = SendDlgItemMessage( dialog, COMBO_SYSTEM, CB_GETCURSEL, 0, 0 );
  81. SendDlgItemMessage( dialog, COMBO_SYSTEM, CB_GETLBTEXT, index, (LPARAM)buffer );
  82. editData->systemCallbackString = buffer;
  83. // input
  84. index = SendDlgItemMessage( dialog, COMBO_INPUT, CB_GETCURSEL, 0, 0 );
  85. SendDlgItemMessage( dialog, COMBO_INPUT, CB_GETLBTEXT, index, (LPARAM)buffer );
  86. editData->inputCallbackString = buffer;
  87. // tooltip
  88. index = SendDlgItemMessage( dialog, COMBO_TOOLTIP, CB_GETCURSEL, 0, 0 );
  89. SendDlgItemMessage( dialog, COMBO_TOOLTIP, CB_GETLBTEXT, index, (LPARAM)buffer );
  90. editData->tooltipCallbackString = buffer;
  91. // draw
  92. index = SendDlgItemMessage( dialog, COMBO_DRAW, CB_GETCURSEL, 0, 0 );
  93. SendDlgItemMessage( dialog, COMBO_DRAW, CB_GETLBTEXT, index, (LPARAM)buffer );
  94. editData->drawCallbackString = buffer;
  95. // if there was a window we have a change
  96. if( window )
  97. TheEditor->setUnsaved( TRUE );
  98. } // end SaveCallbacks
  99. // setCurrentWindow ===========================================================
  100. /** Set the window passed in as the active window for editing */
  101. //=============================================================================
  102. static void setCurrentWindow( GameWindow *window, HWND dialog )
  103. {
  104. GameWindowEditData *editData = NULL;
  105. // get edit data from window if present
  106. if( window )
  107. editData = window->winGetEditData();
  108. // save window
  109. currentWindow = window;
  110. // sanity
  111. if( dialog == NULL )
  112. return;
  113. // enable the callback combo boxes
  114. EnableWindow( GetDlgItem( dialog, COMBO_SYSTEM ), TRUE );
  115. EnableWindow( GetDlgItem( dialog, COMBO_INPUT ), TRUE );
  116. EnableWindow( GetDlgItem( dialog, COMBO_TOOLTIP ), TRUE );
  117. EnableWindow( GetDlgItem( dialog, COMBO_DRAW ), TRUE );
  118. //
  119. // select the assigned callbacks, if no callback is assigned
  120. // in a slot then we select the "none string" for the combo box
  121. //
  122. AsciiString name;
  123. // system
  124. if( editData )
  125. name = editData->systemCallbackString;
  126. if( name.isEmpty() )
  127. name = GUIEDIT_NONE_STRING;
  128. SendDlgItemMessage( dialog, COMBO_SYSTEM,
  129. CB_SELECTSTRING, -1, (LPARAM)name.str() );
  130. // input
  131. name = NULL;
  132. if( editData )
  133. name = editData->inputCallbackString;
  134. if( name.isEmpty() )
  135. name = GUIEDIT_NONE_STRING;
  136. SendDlgItemMessage( dialog, COMBO_INPUT,
  137. CB_SELECTSTRING, -1, (LPARAM)name.str() );
  138. // tooltip
  139. name = NULL;
  140. if( editData )
  141. name = editData->tooltipCallbackString;
  142. if( name.isEmpty() )
  143. name = GUIEDIT_NONE_STRING;
  144. SendDlgItemMessage( dialog, COMBO_TOOLTIP,
  145. CB_SELECTSTRING, -1, (LPARAM)name.str() );
  146. // draw
  147. name = NULL;
  148. if( editData )
  149. name = editData->drawCallbackString;
  150. if( name.isEmpty() )
  151. name = GUIEDIT_NONE_STRING;
  152. SendDlgItemMessage( dialog, COMBO_DRAW,
  153. CB_SELECTSTRING, -1, (LPARAM)name.str() );
  154. //
  155. // set the name of the window in the static control above
  156. // the callback editor boxes
  157. //
  158. name = GUIEDIT_NONE_STRING;
  159. if( window )
  160. {
  161. WinInstanceData *instData = window->winGetInstanceData();
  162. if( !instData->m_decoratedNameString.isEmpty() )
  163. name = instData->m_decoratedNameString;
  164. else
  165. name = noNameWindowString;
  166. } // end if
  167. SetWindowText( GetDlgItem( dialog, STATIC_WINDOW ), name.str() );
  168. } // end setCurrentWindow
  169. // loadUserWindows ============================================================
  170. /** Given the window list passed in, load the list box passed with the
  171. * names of USER windows found in the hierarchy. */
  172. //=============================================================================
  173. static void loadUserWindows( HWND listbox, GameWindow *root )
  174. {
  175. // end recursion
  176. if( root == NULL )
  177. return;
  178. // is this a candidate
  179. if( TheEditor->windowIsGadget( root ) == FALSE )
  180. {
  181. WinInstanceData *instData = root->winGetInstanceData();
  182. Int index;
  183. AsciiString name;
  184. //
  185. // add name to the listbox, if there is no name we can only put
  186. // an unnamed label in there
  187. //
  188. if( !instData->m_decoratedNameString.isEmpty() )
  189. name = instData->m_decoratedNameString;
  190. else
  191. name = noNameWindowString;
  192. index = SendMessage( listbox, LB_ADDSTRING, 0, (LPARAM)name.str() );
  193. // add data pointer to the window at the index just added
  194. SendMessage( listbox, LB_SETITEMDATA, index, (LPARAM)root );
  195. // check the children
  196. loadUserWindows( listbox, root->winGetChild() );
  197. } // end if
  198. // check the rest of the list
  199. loadUserWindows( listbox, root->winGetNext() );
  200. } // end loadUserWindows
  201. //-------------------------------------------------------------------------------------------------
  202. /** save the layout callbacks */
  203. //-------------------------------------------------------------------------------------------------
  204. static void saveLayoutCallbacks( HWND dialog )
  205. {
  206. char buffer[ MAX_LAYOUT_FUNC_LEN ];
  207. Int sel;
  208. // layout init
  209. sel = SendDlgItemMessage( dialog, COMBO_INIT, CB_GETCURSEL, 0, 0 );
  210. SendDlgItemMessage( dialog, COMBO_INIT, CB_GETLBTEXT, sel, (LPARAM)buffer );
  211. TheEditor->setLayoutInit( AsciiString(buffer) );
  212. // layout update
  213. sel = SendDlgItemMessage( dialog, COMBO_UPDATE, CB_GETCURSEL, 0, 0 );
  214. SendDlgItemMessage( dialog, COMBO_UPDATE, CB_GETLBTEXT, sel, (LPARAM)buffer );
  215. TheEditor->setLayoutUpdate( AsciiString(buffer) );
  216. // layout shutdown
  217. sel = SendDlgItemMessage( dialog, COMBO_SHUTDOWN, CB_GETCURSEL, 0, 0 );
  218. SendDlgItemMessage( dialog, COMBO_SHUTDOWN, CB_GETLBTEXT, sel, (LPARAM)buffer );
  219. TheEditor->setLayoutShutdown( AsciiString(buffer) );
  220. } // end saveLayoutCallbacks
  221. ///////////////////////////////////////////////////////////////////////////////
  222. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  223. ///////////////////////////////////////////////////////////////////////////////
  224. // CallbackEditorDialogProc ===================================================
  225. /** Dialog procedure for grid settings dialog */
  226. //=============================================================================
  227. BOOL CALLBACK CallbackEditorDialogProc( HWND hWndDialog, UINT message,
  228. WPARAM wParam, LPARAM lParam )
  229. {
  230. switch( message )
  231. {
  232. // ------------------------------------------------------------------------
  233. case WM_INITDIALOG:
  234. {
  235. // load the combos with the callbacks
  236. InitCallbackCombos( hWndDialog, NULL );
  237. // select the none string at the top index in each combo
  238. SendDlgItemMessage( hWndDialog, COMBO_SYSTEM, CB_SETCURSEL, 0, 0 );
  239. SendDlgItemMessage( hWndDialog, COMBO_INPUT, CB_SETCURSEL, 0, 0 );
  240. SendDlgItemMessage( hWndDialog, COMBO_TOOLTIP, CB_SETCURSEL, 0, 0 );
  241. SendDlgItemMessage( hWndDialog, COMBO_DRAW, CB_SETCURSEL, 0, 0 );
  242. // load the listbox with all the USER windows in the edit window
  243. loadUserWindows( GetDlgItem( hWndDialog, LIST_WINDOWS ),
  244. TheWindowManager->winGetWindowList() );
  245. // no current window
  246. setCurrentWindow( NULL, hWndDialog );
  247. return TRUE;
  248. } // end init dialog
  249. // ------------------------------------------------------------------------
  250. case WM_COMMAND:
  251. {
  252. Int notifyCode = HIWORD( wParam ); // notification code
  253. // Int controlID = LOWORD( wParam ); // control ID
  254. HWND hWndControl = (HWND)lParam; // control window handle
  255. switch( LOWORD( wParam ) )
  256. {
  257. // --------------------------------------------------------------------
  258. case LIST_WINDOWS:
  259. {
  260. switch( notifyCode )
  261. {
  262. // ----------------------------------------------------------------
  263. case LBN_SELCHANGE:
  264. {
  265. Int selected;
  266. GameWindow *win;
  267. // get the current selection of the window list
  268. selected = SendMessage( hWndControl, LB_GETCURSEL, 0, 0 );
  269. // get the window of the selected listbox item
  270. win = (GameWindow *)SendMessage( hWndControl, LB_GETITEMDATA,
  271. selected, 0 );
  272. // sanity
  273. DEBUG_ASSERTCRASH( win, ("NULL window set in listbox item data") );
  274. // save the callbacks for the curent window selected
  275. SaveCallbacks( currentWindow, hWndDialog );
  276. // set the current window to the new selection
  277. setCurrentWindow( win, hWndDialog );
  278. break;
  279. } // end case selection change
  280. } // end switch
  281. break;
  282. } // end window listbox
  283. // --------------------------------------------------------------------
  284. case IDOK:
  285. {
  286. // save callbacks, set current window to empty and end dialog
  287. SaveCallbacks( currentWindow, hWndDialog );
  288. setCurrentWindow( NULL, hWndDialog );
  289. // save the layout callbacks
  290. saveLayoutCallbacks( hWndDialog );
  291. // end dialog
  292. EndDialog( hWndDialog, TRUE );
  293. break;
  294. } // end ok
  295. } // end switch( LOWORD( wParam ) )
  296. return 0;
  297. } // end of WM_COMMAND
  298. // ------------------------------------------------------------------------
  299. default:
  300. return 0;
  301. } // end of switch
  302. } // end CallbackEditorDialogProc