GenericProperties.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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: GenericProperties.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: GenericProperties.cpp
  36. //
  37. // Created: Colin Day, August 2001
  38. //
  39. // Desc: Properties dialog for generic windows
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  44. #include <stdlib.h>
  45. #include <assert.h>
  46. #include <windows.h>
  47. #include <commctrl.h>
  48. #include <stdio.h>
  49. // USER INCLUDES //////////////////////////////////////////////////////////////
  50. #include "Common/Debug.h"
  51. #include "Common/FunctionLexicon.h"
  52. #include "GUIEdit.h"
  53. #include "Properties.h"
  54. #include "Resource.h"
  55. #include "EditWindow.h"
  56. // DEFINES ////////////////////////////////////////////////////////////////////
  57. // PRIVATE TYPES //////////////////////////////////////////////////////////////
  58. ///////////////////////////////////////////////////////////////////////////////
  59. // PRIVATE DATA ///////////////////////////////////////////////////////////////
  60. ///////////////////////////////////////////////////////////////////////////////
  61. // PUBLIC DATA ////////////////////////////////////////////////////////////////
  62. // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
  63. ///////////////////////////////////////////////////////////////////////////////
  64. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  65. ///////////////////////////////////////////////////////////////////////////////
  66. // genericPropertiesCallback ==================================================
  67. /** Dialog callback for properties */
  68. //=============================================================================
  69. static LRESULT CALLBACK genericPropertiesCallback( HWND hWndDialog,
  70. UINT message,
  71. WPARAM wParam,
  72. LPARAM lParam )
  73. {
  74. Int returnCode;
  75. //
  76. // handle any common messages between all property dialogs cause they
  77. // are designed to have controls doing the same functionality
  78. // and names
  79. //
  80. if( HandleCommonDialogMessages( hWndDialog, message,
  81. wParam, lParam, &returnCode ) == TRUE )
  82. return returnCode;
  83. switch( message )
  84. {
  85. // ------------------------------------------------------------------------
  86. case WM_DRAWITEM:
  87. {
  88. UINT controlID = (UINT)wParam; // control identifier
  89. LPDRAWITEMSTRUCT drawItem = (LPDRAWITEMSTRUCT)lParam; // item drawing
  90. RGBColorInt *color = GetControlColor( controlID );
  91. // we only care about color button controls
  92. if( color )
  93. {
  94. HBRUSH hBrushNew, hBrushOld;
  95. RECT rect;
  96. HWND hWndControl = GetDlgItem( hWndDialog, controlID );
  97. // if this control is disabled just let windows handle drawing
  98. if( IsWindowEnabled( hWndControl ) == FALSE )
  99. return FALSE;
  100. // Get the area we have to draw in
  101. GetClientRect( hWndControl, &rect );
  102. // create a new brush and select it into DC
  103. hBrushNew = CreateSolidBrush (RGB ((BYTE)color->red,
  104. (BYTE)color->green,
  105. (BYTE)color->blue));
  106. hBrushOld = (HBRUSH)SelectObject( drawItem->hDC, hBrushNew );
  107. // draw the rectangle
  108. Rectangle( drawItem->hDC, rect.left, rect.top, rect.right, rect.bottom );
  109. // put the old brush back and delete the new one
  110. SelectObject( drawItem->hDC, hBrushOld );
  111. DeleteObject( hBrushNew );
  112. // validate this new area
  113. ValidateRect( hWndControl, NULL );
  114. // we have taken care of it
  115. return TRUE;
  116. } // end if
  117. return FALSE;
  118. } // end draw item
  119. // ------------------------------------------------------------------------
  120. case WM_COMMAND:
  121. {
  122. // Int notifyCode = HIWORD( wParam ); // notification code
  123. Int controlID = LOWORD( wParam ); // control ID
  124. HWND hWndControl = (HWND)lParam; // control window handle
  125. switch( controlID )
  126. {
  127. // --------------------------------------------------------------------
  128. case BUTTON_ENABLED_COLOR:
  129. case BUTTON_ENABLED_BORDER_COLOR:
  130. case BUTTON_DISABLED_COLOR:
  131. case BUTTON_DISABLED_BORDER_COLOR:
  132. case BUTTON_HILITE_COLOR:
  133. case BUTTON_HILITE_BORDER_COLOR:
  134. {
  135. RGBColorInt *currColor = GetControlColor( controlID );
  136. // bring up color selector for this color control at the mouse
  137. if( currColor )
  138. {
  139. RGBColorInt *newColor;
  140. POINT mouse;
  141. GetCursorPos( &mouse );
  142. newColor = SelectColor( currColor->red, currColor->green,
  143. currColor->blue, currColor->alpha,
  144. mouse.x, mouse.y );
  145. if( newColor )
  146. {
  147. Color newGameColor = GameMakeColor( newColor->red,
  148. newColor->green,
  149. newColor->blue,
  150. newColor->alpha );
  151. SetControlColor( controlID, newGameColor );
  152. InvalidateRect( hWndControl, NULL, TRUE );
  153. } // end if
  154. } // end if
  155. break;
  156. } // end color buttons
  157. // --------------------------------------------------------------------
  158. case IDOK:
  159. {
  160. GameWindow *window = TheEditor->getPropertyTarget();
  161. // sanity
  162. if( window )
  163. {
  164. const Image *image;
  165. RGBColorInt *rgbColor;
  166. Color color;
  167. // save the common properties
  168. if( SaveCommonDialogProperties( hWndDialog, window ) == FALSE )
  169. break;
  170. // save callbacks
  171. SaveCallbacks( window, hWndDialog );
  172. // save the enabled colors/images
  173. image = ComboBoxSelectionToImage( GetDlgItem( hWndDialog, COMBO_ENABLED_IMAGE ) );
  174. window->winSetEnabledImage( 0, image );
  175. rgbColor = GetControlColor( BUTTON_ENABLED_COLOR );
  176. color = GameMakeColor( rgbColor->red, rgbColor->green, rgbColor->blue, rgbColor->alpha );
  177. window->winSetEnabledColor( 0, color );
  178. rgbColor = GetControlColor( BUTTON_ENABLED_BORDER_COLOR );
  179. color = GameMakeColor( rgbColor->red, rgbColor->green, rgbColor->blue, rgbColor->alpha );
  180. window->winSetEnabledBorderColor( 0, color );
  181. // save the disabled colors/images
  182. image = ComboBoxSelectionToImage( GetDlgItem( hWndDialog, COMBO_DISABLED_IMAGE ) );
  183. window->winSetDisabledImage( 0, image );
  184. rgbColor = GetControlColor( BUTTON_DISABLED_COLOR );
  185. color = GameMakeColor( rgbColor->red, rgbColor->green, rgbColor->blue, rgbColor->alpha );
  186. window->winSetDisabledColor( 0, color );
  187. rgbColor = GetControlColor( BUTTON_DISABLED_BORDER_COLOR );
  188. color = GameMakeColor( rgbColor->red, rgbColor->green, rgbColor->blue, rgbColor->alpha );
  189. window->winSetDisabledBorderColor( 0, color );
  190. // save the hilite colors/images
  191. image = ComboBoxSelectionToImage( GetDlgItem( hWndDialog, COMBO_HILITE_IMAGE ) );
  192. window->winSetHiliteImage( 0, image );
  193. rgbColor = GetControlColor( BUTTON_HILITE_COLOR );
  194. color = GameMakeColor( rgbColor->red, rgbColor->green, rgbColor->blue, rgbColor->alpha );
  195. window->winSetHiliteColor( 0, color );
  196. rgbColor = GetControlColor( BUTTON_HILITE_BORDER_COLOR );
  197. color = GameMakeColor( rgbColor->red, rgbColor->green, rgbColor->blue, rgbColor->alpha );
  198. window->winSetHiliteBorderColor( 0, color );
  199. } // end if
  200. DestroyWindow( hWndDialog );
  201. break;
  202. } // end OK
  203. // --------------------------------------------------------------------
  204. case IDCANCEL:
  205. {
  206. DestroyWindow( hWndDialog );
  207. break;
  208. } // end cancel
  209. } // end switch( LOWORD( wParam ) )
  210. return 0;
  211. } // end of WM_COMMAND
  212. // ------------------------------------------------------------------------
  213. case WM_CLOSE:
  214. {
  215. DestroyWindow( hWndDialog );
  216. return 0;
  217. } // end close
  218. // ------------------------------------------------------------------------
  219. default:
  220. return 0;
  221. } // end of switch
  222. } // end genericPropertiesCallback
  223. // InitCallbackCombos =========================================================
  224. /** load the callbacks combo boxes with the functions that the user cal
  225. * select to attach to this window */
  226. //=============================================================================
  227. void InitCallbackCombos( HWND dialog, GameWindow *window )
  228. {
  229. HWND combo;
  230. FunctionLexicon::TableEntry *entry;
  231. GameWindowEditData *editData = NULL;
  232. AsciiString name;
  233. // get edit data from window
  234. if( window )
  235. editData = window->winGetEditData();
  236. // load the system combo ----------------------------------------------------
  237. combo = GetDlgItem( dialog, COMBO_SYSTEM );
  238. entry = TheFunctionLexicon->getTable( FunctionLexicon::TABLE_GAME_WIN_SYSTEM );
  239. while( entry && entry ->key != NAMEKEY_INVALID )
  240. {
  241. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)entry->name );
  242. entry++;
  243. } // end while
  244. SendMessage( combo, CB_INSERTSTRING, 0, (LPARAM)GUIEDIT_NONE_STRING );
  245. // select the current function of the window in the combo if present
  246. name.clear();
  247. if( editData )
  248. name = editData->systemCallbackString;
  249. if( name.isEmpty() )
  250. name = GUIEDIT_NONE_STRING;
  251. SendMessage( combo, CB_SELECTSTRING, -1, (LPARAM)name.str() );
  252. // load the input combo -----------------------------------------------------
  253. combo = GetDlgItem( dialog, COMBO_INPUT );
  254. entry = TheFunctionLexicon->getTable( FunctionLexicon::TABLE_GAME_WIN_INPUT );
  255. while( entry && entry ->key != NAMEKEY_INVALID )
  256. {
  257. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)entry->name );
  258. entry++;
  259. } // end while
  260. SendMessage( combo, CB_INSERTSTRING, 0, (LPARAM)GUIEDIT_NONE_STRING );
  261. // select the current function of the window in the combo if present
  262. name.clear();
  263. if( editData )
  264. name = editData->inputCallbackString;
  265. if( name.isEmpty() )
  266. name = GUIEDIT_NONE_STRING;
  267. SendMessage( combo, CB_SELECTSTRING, -1, (LPARAM)name.str() );
  268. // load the tooltip combo ---------------------------------------------------
  269. combo = GetDlgItem( dialog, COMBO_TOOLTIP );
  270. entry = TheFunctionLexicon->getTable( FunctionLexicon::TABLE_GAME_WIN_TOOLTIP );
  271. while( entry && entry ->key != NAMEKEY_INVALID )
  272. {
  273. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)entry->name );
  274. entry++;
  275. } // end while
  276. SendMessage( combo, CB_INSERTSTRING, 0, (LPARAM)GUIEDIT_NONE_STRING );
  277. // select the current function of the window in the combo if present
  278. name.clear();
  279. if( editData )
  280. name = editData->tooltipCallbackString;
  281. if( name.isEmpty() )
  282. name = GUIEDIT_NONE_STRING;
  283. SendMessage( combo, CB_SELECTSTRING, -1, (LPARAM)name.str() );
  284. // load the draw combo ------------------------------------------------------
  285. combo = GetDlgItem( dialog, COMBO_DRAW );
  286. entry = TheFunctionLexicon->getTable( FunctionLexicon::TABLE_GAME_WIN_DRAW );
  287. while( entry && entry ->key != NAMEKEY_INVALID )
  288. {
  289. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)entry->name );
  290. entry++;
  291. } // end while
  292. entry = TheFunctionLexicon->getTable( FunctionLexicon::TABLE_GAME_WIN_DEVICEDRAW );
  293. while( entry && entry ->key != NAMEKEY_INVALID )
  294. {
  295. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)entry->name );
  296. entry++;
  297. } // end while
  298. SendMessage( combo, CB_INSERTSTRING, 0, (LPARAM)GUIEDIT_NONE_STRING );
  299. // select the current function of the window in the combo if present
  300. name.clear();
  301. if( editData )
  302. name = editData->drawCallbackString;
  303. if( name.isEmpty() )
  304. name = GUIEDIT_NONE_STRING;
  305. SendMessage( combo, CB_SELECTSTRING, -1, (LPARAM)name.str() );
  306. //=================================================================================================
  307. // callbacks for the layout itself
  308. //=================================================================================================
  309. // init combo
  310. combo = GetDlgItem( dialog, COMBO_INIT );
  311. entry = TheFunctionLexicon->getTable( FunctionLexicon::TABLE_WIN_LAYOUT_INIT );
  312. while( entry && entry->key != NAMEKEY_INVALID )
  313. {
  314. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)entry->name );
  315. entry++;
  316. }
  317. entry = TheFunctionLexicon->getTable( FunctionLexicon::TABLE_WIN_LAYOUT_DEVICEINIT );
  318. while( entry && entry->key != NAMEKEY_INVALID )
  319. {
  320. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)entry->name );
  321. entry++;
  322. }
  323. SendMessage( combo, CB_INSERTSTRING, 0, (LPARAM)GUIEDIT_NONE_STRING );
  324. name = TheEditor->getLayoutInit();
  325. SendMessage( combo, CB_SELECTSTRING, -1, (LPARAM)name.str() );
  326. // update combo
  327. combo = GetDlgItem( dialog, COMBO_UPDATE );
  328. entry = TheFunctionLexicon->getTable( FunctionLexicon::TABLE_WIN_LAYOUT_UPDATE );
  329. while( entry && entry->key != NAMEKEY_INVALID )
  330. {
  331. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)entry->name );
  332. entry++;
  333. }
  334. SendMessage( combo, CB_INSERTSTRING, 0, (LPARAM)GUIEDIT_NONE_STRING );
  335. name = TheEditor->getLayoutUpdate();
  336. SendMessage( combo, CB_SELECTSTRING, -1, (LPARAM)name.str() );
  337. // shutdown combo
  338. combo = GetDlgItem( dialog, COMBO_SHUTDOWN );
  339. entry = TheFunctionLexicon->getTable( FunctionLexicon::TABLE_WIN_LAYOUT_SHUTDOWN );
  340. while( entry && entry->key != NAMEKEY_INVALID )
  341. {
  342. SendMessage( combo, CB_ADDSTRING, 0, (LPARAM)entry->name );
  343. entry++;
  344. }
  345. SendMessage( combo, CB_INSERTSTRING, 0, (LPARAM)GUIEDIT_NONE_STRING );
  346. name = TheEditor->getLayoutShutdown();
  347. SendMessage( combo, CB_SELECTSTRING, -1, (LPARAM)name.str() );
  348. } // end InitCallbackCombos
  349. ///////////////////////////////////////////////////////////////////////////////
  350. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  351. ///////////////////////////////////////////////////////////////////////////////
  352. // InitUserWinPropertiesDialog ================================================
  353. /** Initialize the generic properties dialog for windows */
  354. //=============================================================================
  355. HWND InitUserWinPropertiesDialog( GameWindow *window )
  356. {
  357. HWND dialog;
  358. // create the dialog box
  359. dialog = CreateDialog( TheEditor->getInstance(),
  360. (LPCTSTR)GENERIC_PROPERTIES_DIALOG,
  361. TheEditor->getWindowHandle(),
  362. (DLGPROC)genericPropertiesCallback );
  363. if( dialog == NULL )
  364. return NULL;
  365. // do the common initialization
  366. CommonDialogInitialize( window, dialog );
  367. //
  368. // initialize the dialog with values from the window
  369. //
  370. // fill out the image combo boxes
  371. LoadImageListComboBox( GetDlgItem( dialog, COMBO_ENABLED_IMAGE ) );
  372. LoadImageListComboBox( GetDlgItem( dialog, COMBO_DISABLED_IMAGE ) );
  373. LoadImageListComboBox( GetDlgItem( dialog, COMBO_HILITE_IMAGE ) );
  374. // select any images in the combo boxes
  375. const Image *image;
  376. image = window->winGetEnabledImage( 0 );
  377. if( image )
  378. SendDlgItemMessage( dialog, COMBO_ENABLED_IMAGE, CB_SELECTSTRING,
  379. -1, (LPARAM)image->getName().str() );
  380. image = window->winGetDisabledImage( 0 );
  381. if( image )
  382. SendDlgItemMessage( dialog, COMBO_DISABLED_IMAGE, CB_SELECTSTRING,
  383. -1, (LPARAM)image->getName().str() );
  384. image = window->winGetHiliteImage( 0 );
  385. if( image )
  386. SendDlgItemMessage( dialog, COMBO_HILITE_IMAGE, CB_SELECTSTRING,
  387. -1, (LPARAM)image->getName().str() );
  388. // initialize the color buttons
  389. SetControlColor( BUTTON_ENABLED_COLOR, window->winGetEnabledColor( 0 ) );
  390. SetControlColor( BUTTON_ENABLED_BORDER_COLOR, window->winGetEnabledBorderColor( 0 ) );
  391. SetControlColor( BUTTON_DISABLED_COLOR, window->winGetDisabledColor( 0 ) );
  392. SetControlColor( BUTTON_DISABLED_BORDER_COLOR, window->winGetDisabledBorderColor( 0 ) );
  393. SetControlColor( BUTTON_HILITE_COLOR, window->winGetHiliteColor( 0 ) );
  394. SetControlColor( BUTTON_HILITE_BORDER_COLOR, window->winGetHiliteBorderColor( 0 ) );
  395. // load the combo boxes with the callbacks the user can use
  396. InitCallbackCombos( dialog, window );
  397. return dialog;
  398. } // end InitUserWinPropertiesDialog