EditorPropSheet.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. // EditorPropSheetClass.cpp : implementation file
  19. //
  20. #include "StdAfx.h"
  21. #include "leveledit.h"
  22. #include "EditorPropSheet.H"
  23. #include "Utils.H"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Local constants
  31. /////////////////////////////////////////////////////////////////////////////
  32. static const int BORDER_BUTTON_X = 6;
  33. static const int BORDER_BUTTON_Y = 6;
  34. static const int BORDER_TAB_X = 6;
  35. static const int BORDER_TAB_Y = 6;
  36. /////////////////////////////////////////////////////////////////////////////
  37. //
  38. // EditorPropSheetClass
  39. //
  40. /////////////////////////////////////////////////////////////////////////////
  41. EditorPropSheetClass::EditorPropSheetClass (void)
  42. : m_iCurrentTab (0),
  43. m_IsReadOnly (false),
  44. CDialog(EditorPropSheetClass::IDD, ::AfxGetMainWnd ())
  45. {
  46. //{{AFX_DATA_INIT(EditorPropSheetClass)
  47. // NOTE: the ClassWizard will add member initialization here
  48. //}}AFX_DATA_INIT
  49. return ;
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. //
  53. // ~EditorPropSheetClass
  54. //
  55. /////////////////////////////////////////////////////////////////////////////
  56. EditorPropSheetClass::~EditorPropSheetClass (void)
  57. {
  58. m_TabList.Delete_All ();
  59. return ;
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. //
  63. // DoDataExchange
  64. //
  65. /////////////////////////////////////////////////////////////////////////////
  66. void
  67. EditorPropSheetClass::DoDataExchange (CDataExchange* pDX)
  68. {
  69. CDialog::DoDataExchange(pDX);
  70. //{{AFX_DATA_MAP(EditorPropSheetClass)
  71. DDX_Control(pDX, IDC_TABCTRL, m_TabCtrl);
  72. //}}AFX_DATA_MAP
  73. return ;
  74. }
  75. BEGIN_MESSAGE_MAP(EditorPropSheetClass, CDialog)
  76. //{{AFX_MSG_MAP(EditorPropSheetClass)
  77. ON_WM_SIZE()
  78. ON_NOTIFY(TCN_SELCHANGE, IDC_TABCTRL, OnSelchangeTabCtrl)
  79. ON_BN_CLICKED(IDC_OK, OnOk)
  80. //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82. /////////////////////////////////////////////////////////////////////////////
  83. // EditorPropSheetClass diagnostics
  84. #ifdef _DEBUG
  85. void EditorPropSheetClass::AssertValid() const
  86. {
  87. CDialog::AssertValid();
  88. }
  89. void EditorPropSheetClass::Dump(CDumpContext& dc) const
  90. {
  91. CDialog::Dump(dc);
  92. }
  93. #endif //_DEBUG
  94. /////////////////////////////////////////////////////////////////////////////
  95. //
  96. // Reposition_Buttons
  97. //
  98. /////////////////////////////////////////////////////////////////////////////
  99. void
  100. EditorPropSheetClass::Reposition_Buttons (int cx, int cy)
  101. {
  102. //
  103. // Get the dimensions of the buttons
  104. //
  105. CRect button_rect;
  106. ::GetWindowRect (::GetDlgItem (m_hWnd, IDCANCEL), &button_rect);
  107. ScreenToClient (&button_rect);
  108. //
  109. // Reposition the OK and Cancel buttons
  110. //
  111. ::SetWindowPos (::GetDlgItem (m_hWnd, IDCANCEL),
  112. NULL,
  113. (cx - button_rect.Width ()) - BORDER_BUTTON_X,
  114. (cy - button_rect.Height ()) - BORDER_BUTTON_Y,
  115. 0,
  116. 0,
  117. SWP_NOZORDER | SWP_NOSIZE);
  118. ::SetWindowPos (::GetDlgItem (m_hWnd, IDC_OK),
  119. NULL,
  120. (cx - (button_rect.Width () << 1)) - (BORDER_BUTTON_X * 2),
  121. (cy - button_rect.Height ()) - BORDER_BUTTON_Y,
  122. 0,
  123. 0,
  124. SWP_NOZORDER | SWP_NOSIZE);
  125. return ;
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. //
  129. // OnSize
  130. //
  131. /////////////////////////////////////////////////////////////////////////////
  132. void
  133. EditorPropSheetClass::OnSize
  134. (
  135. UINT nType,
  136. int cx,
  137. int cy
  138. )
  139. {
  140. // Allow the base class to process this message
  141. CDialog::OnSize (nType, cx, cy);
  142. if (::IsWindow (m_TabCtrl) && (cx > 0) && (cy > 0)) {
  143. //
  144. // Get the dimensions of the buttons
  145. //
  146. CRect button_rect;
  147. ::GetWindowRect (::GetDlgItem (m_hWnd, IDCANCEL), &button_rect);
  148. ScreenToClient (&button_rect);
  149. //
  150. // Move the buttons so they continue to be in the lower right corner
  151. //
  152. Reposition_Buttons (cx, cy);
  153. //
  154. // Shrink the bounds by BORDER_TAB_X (to give a little border)
  155. //
  156. cx -= BORDER_TAB_X * 2;
  157. cy -= (BORDER_TAB_Y * 2) + (button_rect.Height () + BORDER_BUTTON_Y);
  158. // Resize the tab control to fill the entire contents of the client area
  159. m_TabCtrl.SetWindowPos (NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE);
  160. // Get the display rectangle of the tab control
  161. CRect rect;
  162. m_TabCtrl.GetWindowRect (&rect);
  163. m_TabCtrl.AdjustRect (FALSE, &rect);
  164. // Convert the display rectangle from screen to client coords
  165. ScreenToClient (&rect);
  166. // Loop through all the tabs in the property sheet
  167. for (int tab = 0;
  168. tab < m_TabList.Count ();
  169. tab ++) {
  170. // Get a pointer to this tab
  171. DockableFormClass *ptab = m_TabList[tab];
  172. if (ptab != NULL) {
  173. // Resize this tab
  174. ptab->SetWindowPos (NULL, rect.left, rect.top, rect.Width (), rect.Height (), SWP_NOZORDER);
  175. }
  176. }
  177. }
  178. return ;
  179. }
  180. /////////////////////////////////////////////////////////////////////////////
  181. //
  182. // OnSelchangeTabCtrl
  183. //
  184. /////////////////////////////////////////////////////////////////////////////
  185. void
  186. EditorPropSheetClass::OnSelchangeTabCtrl
  187. (
  188. NMHDR* pNMHDR,
  189. LRESULT* pResult
  190. )
  191. {
  192. // Which tab is selected?
  193. int newtab = m_TabCtrl.GetCurSel ();
  194. // Is this a new tab?
  195. if (m_iCurrentTab != newtab) {
  196. // Is the old tab valid?
  197. if (m_TabList[m_iCurrentTab] != NULL) {
  198. // Hide the contents of the old tab
  199. m_TabList[m_iCurrentTab]->ShowWindow (SW_HIDE);
  200. }
  201. // Is the new tab valid?
  202. if (m_TabList[newtab] != NULL) {
  203. // Show the contents of the new tab
  204. m_TabList[newtab]->ShowWindow (SW_SHOW);
  205. }
  206. // Remember what our new current tab is
  207. m_iCurrentTab = newtab;
  208. }
  209. (*pResult) = 0;
  210. return ;
  211. }
  212. /////////////////////////////////////////////////////////////////////////////
  213. //
  214. // OnInitDialog
  215. //
  216. /////////////////////////////////////////////////////////////////////////////
  217. BOOL
  218. EditorPropSheetClass::OnInitDialog (void)
  219. {
  220. // Allow the base class to process this message
  221. CDialog::OnInitDialog ();
  222. // Move the tab control so it starts at 2, 2
  223. m_TabCtrl.SetWindowPos (NULL, BORDER_TAB_X, BORDER_TAB_Y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  224. // Loop through all the tabs in our list
  225. int cx = 0;
  226. int cy = 0;
  227. for (int tab = 0;
  228. tab < m_TabList.Count ();
  229. tab ++) {
  230. // Get a pointer to this tab
  231. DockableFormClass *ptab = m_TabList[tab];
  232. // Was the tab pointer valid?
  233. ASSERT (ptab != NULL);
  234. if (ptab != NULL) {
  235. // Create the window associated with this tab
  236. ptab->Create (this, 100 + tab);
  237. // Hide the tab if it isn't the first one
  238. ptab->ShowWindow ((tab == 0) ? SW_SHOW : SW_HIDE);
  239. // Get the name of this tab from its form
  240. CString tab_name;
  241. ptab->GetWindowText (tab_name);
  242. // Determine if we need to stretch our cx and cy
  243. CRect rect = ptab->Get_Form_Rect ();
  244. cx = (rect.Width () > cx) ? rect.Width () : cx;
  245. cy = (rect.Height () > cy) ? rect.Height() : cy;
  246. ptab->SetWindowPos (NULL, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER);
  247. // Now insert a tab into the tab control for this form
  248. TC_ITEM tabInfo = { 0 };
  249. tabInfo.mask = TCIF_TEXT;
  250. tabInfo.pszText = (LPTSTR)(LPCTSTR)tab_name;
  251. m_TabCtrl.InsertItem (tab, &tabInfo);
  252. }
  253. }
  254. m_TabList[0]->SetFocus ();
  255. if ((cx > 0) && (cy > 0)) {
  256. // Get the display rectangle of the tab control
  257. CRect rect (0, 0, cx, cy);
  258. m_TabCtrl.AdjustRect (TRUE, &rect);
  259. CRect button_rect;
  260. ::GetWindowRect (::GetDlgItem (m_hWnd, IDCANCEL), &button_rect);
  261. ScreenToClient (&button_rect);
  262. // Find a rectangle large enough to hold the tab control
  263. ::AdjustWindowRectEx (&rect, ::GetWindowLong (m_hWnd, GWL_STYLE), FALSE, ::GetWindowLong (m_hWnd, GWL_EXSTYLE));
  264. rect.bottom += button_rect.Height () + BORDER_BUTTON_Y;
  265. rect.InflateRect (BORDER_TAB_X, BORDER_TAB_Y);
  266. // Resize the dialog to be large enough to hold the tab control
  267. SetWindowPos (NULL, 0, 0, rect.Width (), rect.Height (), SWP_NOZORDER | SWP_NOMOVE);
  268. }
  269. if (m_IsReadOnly) {
  270. ::ShowWindow (::GetDlgItem (m_hWnd, IDC_OK), SW_HIDE);
  271. SetDlgItemText (IDCANCEL, "Close");
  272. }
  273. return FALSE;
  274. }
  275. /////////////////////////////////////////////////////////////////////////////
  276. //
  277. // OnCommand
  278. //
  279. /////////////////////////////////////////////////////////////////////////////
  280. BOOL
  281. EditorPropSheetClass::OnCommand
  282. (
  283. WPARAM wParam,
  284. LPARAM lParam
  285. )
  286. {
  287. // Did the user hit the enter button?
  288. if (LOWORD (wParam) == IDOK) {
  289. m_TabList[m_iCurrentTab]->SendMessage (WM_COMMAND, wParam, lParam);
  290. return TRUE;
  291. }
  292. // Allow the base class to process this message
  293. return CDialog::OnCommand(wParam, lParam);
  294. }
  295. /////////////////////////////////////////////////////////////////////////////
  296. //
  297. // OnOk
  298. //
  299. /////////////////////////////////////////////////////////////////////////////
  300. void
  301. EditorPropSheetClass::OnOk (void)
  302. {
  303. if (Apply_Changes ()) {
  304. EndDialog (IDOK);
  305. }
  306. return ;
  307. }
  308. /////////////////////////////////////////////////////////////////////////////
  309. //
  310. // Apply_Changes
  311. //
  312. /////////////////////////////////////////////////////////////////////////////
  313. bool
  314. EditorPropSheetClass::Apply_Changes (void)
  315. {
  316. bool is_valid = true;
  317. for (int index = 0; index < m_TabList.Count (); index ++) {
  318. DockableFormClass *tab = m_TabList[index];
  319. ASSERT (tab != NULL);
  320. if (tab != NULL) {
  321. //
  322. // Have the tab apply its changes
  323. //
  324. is_valid &= tab->Apply_Changes ();
  325. }
  326. }
  327. return is_valid;
  328. }
  329. /////////////////////////////////////////////////////////////////////////////
  330. //
  331. // OnCancel
  332. //
  333. /////////////////////////////////////////////////////////////////////////////
  334. void
  335. EditorPropSheetClass::OnCancel (void)
  336. {
  337. for (int tab = 0;
  338. tab < m_TabList.Count ();
  339. tab ++) {
  340. // Get a pointer to this tab
  341. DockableFormClass *ptab = m_TabList[tab];
  342. // Was the tab pointer valid?
  343. ASSERT (ptab != NULL);
  344. if (ptab != NULL) {
  345. // Have the tab discard its changes
  346. ptab->Discard_Changes ();
  347. }
  348. }
  349. CDialog::OnCancel ();
  350. return ;
  351. }