Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

791 lines
26 KiB

  1. //******************************************************************
  2. // layout.cpp
  3. //
  4. // This file contains the code that lays out the CTrapEventDialog.
  5. // This is neccessary when the edit/view button changes the
  6. // dialog form its small (main) view to the extended view.
  7. //
  8. // Author: Larry A. French
  9. //
  10. // History:
  11. // 20-Febuary-96 Wrote it
  12. //
  13. //
  14. // Copyright (C) 1996 Microsoft Corporation. All rights reserved.
  15. //******************************************************************
  16. #include "stdafx.h"
  17. #include "layout.h"
  18. #include "trapdlg.h"
  19. #include "trapreg.h"
  20. #include "globals.h"
  21. #define CX_MARGIN 10
  22. #define CY_MARGIN 10
  23. #define CY_LEADING 3
  24. #define CY_DIALOG_FONT 8
  25. class CDlgMetrics
  26. {
  27. public:
  28. CDlgMetrics(CEventTrapDlg* pdlg);
  29. CSize m_sizeMargin;
  30. CSize m_sizeAddButton;
  31. CSize m_sizeRemoveButton;
  32. CSize m_sizeFindButton;
  33. CSize m_sizeOKButton;
  34. int m_cyLeading;
  35. CSize m_sizeLabel0;
  36. CSize m_sizeLabel1;
  37. CSize m_sizeLabel2;
  38. CSize m_sizeConfigTypeBox;
  39. CSize m_sizeConfigCustomButton;
  40. CSize m_sizeConfigDefaultButton;
  41. };
  42. //*****************************************************************
  43. // CDlgMetrics::CDlgMetrics
  44. //
  45. // Construct an object containing the metrics for the CEventTrapDlg
  46. //
  47. // Parameters:
  48. // CEventTrapDlg* pdlg
  49. // Pointer to an instance of the main event trap dialog.
  50. // This pointer is used to access members, such as buttons
  51. // and so on so that they can be measured.
  52. //
  53. // Returns:
  54. // The members of this class are valid on return.
  55. //
  56. //*****************************************************************
  57. CDlgMetrics::CDlgMetrics(CEventTrapDlg* pdlg)
  58. {
  59. m_sizeMargin.cx = CX_MARGIN;
  60. m_sizeMargin.cy = CY_MARGIN;
  61. m_cyLeading = CY_LEADING;
  62. CRect rc;
  63. pdlg->m_btnAdd.GetWindowRect(&rc);
  64. pdlg->ScreenToClient(&rc);
  65. m_sizeAddButton = rc.Size();
  66. pdlg->m_btnFind.GetWindowRect(&rc);
  67. pdlg->ScreenToClient(&rc);
  68. m_sizeFindButton = rc.Size();
  69. pdlg->m_btnRemove.GetWindowRect(&rc);
  70. pdlg->ScreenToClient(&rc);
  71. m_sizeRemoveButton = rc.Size();
  72. pdlg->m_statLabel0.GetWindowRect(&rc);
  73. pdlg->ScreenToClient(&rc);
  74. m_sizeLabel0 = rc.Size();
  75. pdlg->m_statLabel1.GetWindowRect(&rc);
  76. pdlg->ScreenToClient(&rc);
  77. m_sizeLabel1 = rc.Size();
  78. pdlg->m_statLabel2.GetWindowRect(&rc);
  79. pdlg->ScreenToClient(&rc);
  80. m_sizeLabel2 = rc.Size();
  81. pdlg->m_btnOK.GetWindowRect(&rc);
  82. pdlg->ScreenToClient(&rc);
  83. m_sizeOKButton = rc.Size();
  84. if (g_reg.m_bShowConfigTypeBox) {
  85. pdlg->m_btnConfigTypeBox.GetWindowRect(&rc);
  86. pdlg->ScreenToClient(&rc);
  87. m_sizeConfigTypeBox = rc.Size();
  88. pdlg->m_btnConfigTypeCustom.GetWindowRect(&rc);
  89. pdlg->ScreenToClient(&rc);
  90. m_sizeConfigCustomButton = rc.Size();
  91. pdlg->m_btnConfigTypeDefault.GetWindowRect(&rc);
  92. pdlg->ScreenToClient(&rc);
  93. m_sizeConfigDefaultButton = rc.Size();
  94. }
  95. else {
  96. // If the "Configuration type box will not be shown, then the size of the
  97. // box and the radio buttons in it are all zero.
  98. pdlg->m_btnConfigTypeBox.GetWindowRect(&rc);
  99. m_sizeConfigTypeBox.cx = 0;
  100. m_sizeConfigTypeBox.cy = 0;
  101. m_sizeConfigCustomButton.cx = 0;
  102. m_sizeConfigCustomButton.cy = 0;
  103. m_sizeConfigDefaultButton.cx = 0;
  104. m_sizeConfigDefaultButton.cy = 0;
  105. }
  106. }
  107. //////////////////////////////////////////////////////////////////////
  108. // CLASS: CMainLayout
  109. //
  110. // This class computes the position of various items for the main (small)
  111. // view of the dialog. The metrics for each of these items is made
  112. // available through public data members.
  113. /////////////////////////////////////////////////////////////////////
  114. class CMainLayout
  115. {
  116. public:
  117. void Create(CDlgMetrics& metrics, CRect& rc);
  118. CRect m_rc;
  119. CRect m_rcLabel0;
  120. CRect m_rcOKButton;
  121. CRect m_rcCancelButton;
  122. CRect m_rcApplyButton;
  123. CRect m_rcPropertiesButton;
  124. CRect m_rcSettingsButton;
  125. CRect m_rcExportButton;
  126. CRect m_rcViewButton;
  127. CRect m_rcListView;
  128. CRect m_rcConfigTypeBox;
  129. CRect m_rcConfigCustomButton;
  130. CRect m_rcConfigDefaultButton;
  131. };
  132. //*****************************************************************
  133. // CMainLayout::Create
  134. //
  135. // Construct the layout for the main part of the dialog. This is
  136. // the part where the add event stuff is hidden.
  137. //
  138. // Note: The caller is responsible for making sure that the
  139. // specified rectangle is large enough so that the display
  140. // still looks good. For example, it doesn't make sense to shrink
  141. // the listview to a zero size or even negative size.
  142. //
  143. // Parameters:
  144. // CDlgMetrics& metrics
  145. // The dialog metrics containing the size of the things
  146. // that appear on the dialog and so on.
  147. //
  148. // CRect& rc
  149. // The rectangle where the main part of the dialog will be
  150. // drawn.
  151. //
  152. // Returns:
  153. // The members of this class are valid on return.
  154. //
  155. //*****************************************************************
  156. void CMainLayout::Create(CDlgMetrics& metrics, CRect& rc)
  157. {
  158. m_rc = rc;
  159. // The rectangle for this layout may actually extend beyond the size
  160. // of the dialog window. This can occur when the user shrinks the dialog
  161. // to a size smaller than the minimum for this layout.
  162. //
  163. // Things that are drawn outside of the dialog are clipped.
  164. //
  165. // Set the rectangle for the "Configuration Type" groupbox
  166. m_rcConfigTypeBox.left = rc.left + metrics.m_sizeMargin.cx;
  167. m_rcConfigTypeBox.top = rc.top + metrics.m_sizeMargin.cy;
  168. m_rcConfigTypeBox.right = rc.right - (metrics.m_sizeOKButton.cx + 2 * metrics.m_sizeMargin.cx);
  169. m_rcConfigTypeBox.bottom = m_rcConfigTypeBox.top + metrics.m_sizeConfigTypeBox.cy;
  170. // Set the rectangle for the "Custom" radio button within the "Configuration Type" groupbox
  171. // We place it right in the middle between the top and the bottom of the groupbox.
  172. m_rcConfigCustomButton.left = m_rcConfigTypeBox.left + metrics.m_sizeMargin.cx;
  173. m_rcConfigCustomButton.top = m_rcConfigTypeBox.top +
  174. (metrics.m_sizeConfigTypeBox.cy/2 - metrics.m_sizeConfigCustomButton.cy/2) + CY_DIALOG_FONT/2;
  175. m_rcConfigCustomButton.right = m_rcConfigCustomButton.left + metrics.m_sizeConfigCustomButton.cx;
  176. m_rcConfigCustomButton.bottom = m_rcConfigCustomButton.top + metrics.m_sizeConfigCustomButton.cy;
  177. // Set the rectangle for the "Default" radio button within the "Configuration Type" groupbox
  178. m_rcConfigDefaultButton.left = m_rcConfigCustomButton.right + metrics.m_sizeMargin.cx;
  179. m_rcConfigDefaultButton.top = m_rcConfigCustomButton.top;
  180. m_rcConfigDefaultButton.right = m_rcConfigDefaultButton.left + metrics.m_sizeConfigDefaultButton.cx;
  181. m_rcConfigDefaultButton.bottom = m_rcConfigCustomButton.bottom;
  182. m_rcLabel0.left = m_rcConfigTypeBox.left;
  183. m_rcLabel0.top = m_rcConfigTypeBox.bottom;
  184. if (metrics.m_sizeConfigTypeBox.cy != 0) {
  185. // If the configuration type groupbox is present, then the event list
  186. // should be placed one margin height below it.
  187. m_rcLabel0.top += metrics.m_sizeMargin.cy;
  188. }
  189. m_rcLabel0.right = m_rcLabel0.left + metrics.m_sizeLabel0.cx;
  190. m_rcLabel0.bottom = m_rcLabel0.top + metrics.m_sizeLabel0.cy;
  191. // Set the position of the top events listview.
  192. m_rcListView.left = m_rcConfigTypeBox.left;
  193. m_rcListView.top = m_rcLabel0.bottom + metrics.m_sizeMargin.cy;
  194. m_rcListView.right = m_rcConfigTypeBox.right;
  195. m_rcListView.bottom = rc.bottom - metrics.m_sizeMargin.cy;
  196. // Set the position of the OK button
  197. m_rcOKButton.left = m_rcListView.right + metrics.m_sizeMargin.cx;
  198. m_rcOKButton.top = m_rcConfigTypeBox.top;
  199. if (metrics.m_sizeConfigTypeBox.cy != 0) {
  200. // If the configuration type groupbox is present, then the OK button should be
  201. // moved down by half the dialog font height so that it lines up with the
  202. // top of the groupbox's rectangle instead of the top of the group box's title.
  203. m_rcOKButton.top += CY_DIALOG_FONT / 2;
  204. }
  205. m_rcOKButton.right = m_rcOKButton.left + metrics.m_sizeOKButton.cx;
  206. m_rcOKButton.bottom = m_rcOKButton.top + metrics.m_sizeOKButton.cy;
  207. // Compute the vertical distance between buttons.
  208. int cyDelta = m_rcOKButton.Height() + metrics.m_sizeMargin.cy / 2;
  209. // Set the position of the Cancel button
  210. m_rcCancelButton = m_rcOKButton;
  211. m_rcCancelButton.OffsetRect(0, cyDelta);
  212. // Set the position of the Apply button
  213. m_rcApplyButton = m_rcCancelButton;
  214. m_rcApplyButton.OffsetRect(0, cyDelta);
  215. // Set the position of the settings button
  216. m_rcSettingsButton = m_rcApplyButton;
  217. m_rcSettingsButton.OffsetRect(0, cyDelta);
  218. // Set the position of the properties button
  219. m_rcPropertiesButton = m_rcSettingsButton;
  220. m_rcPropertiesButton.OffsetRect(0, cyDelta);
  221. // Set the position of the export button
  222. m_rcExportButton = m_rcPropertiesButton;
  223. m_rcExportButton.OffsetRect(0, cyDelta);
  224. // Set the position of the view button
  225. m_rcViewButton = m_rcExportButton;
  226. m_rcViewButton.OffsetRect(0, cyDelta);
  227. }
  228. //////////////////////////////////////////////////////////////////////
  229. // CLASS: CExtendedLayout
  230. //
  231. // This class computes the position of various items for the extended
  232. // view of the dialog. The metrics for each of these items is made
  233. // available through public data members.
  234. /////////////////////////////////////////////////////////////////////
  235. class CExtendedLayout
  236. {
  237. public:
  238. void Create(CDlgMetrics& metrics, CRect& rc);
  239. CRect m_rc;
  240. CRect m_rcTreeView;
  241. CRect m_rcListView;
  242. CRect m_rcFindButton;
  243. CRect m_rcAddButton;
  244. CRect m_rcRemoveButton;
  245. CRect m_rcLabel1;
  246. CRect m_rcLabel2;
  247. private:
  248. };
  249. //*****************************************************************
  250. // CExtendedLayout::Create
  251. //
  252. // Construct the layout for the extended part of the dialog. This is
  253. // the part where the add event stuff is shown.
  254. //
  255. // Note: The caller is responsible for making sure that the
  256. // specified rectangle is large enough so that the display
  257. // still looks good. For example, it doesn't make sense to shrink
  258. // the listview to a zero size or even negative size.
  259. //
  260. // Parameters:
  261. // CDlgMetrics& metrics
  262. // The dialog metrics containing the size of the things
  263. // that appear on the dialog and so on.
  264. //
  265. // CRect& rc
  266. // The rectangle where the main part of the dialog will be
  267. // drawn.
  268. //
  269. // Returns:
  270. // The members of this class are valid on return.
  271. //
  272. //*****************************************************************
  273. void CExtendedLayout::Create(CDlgMetrics& metrics, CRect& rc)
  274. {
  275. m_rc = rc;
  276. CRect rcTemp;
  277. // Calculate the combined width of the treeview and listview.
  278. // We subtract 3 * CX_MARGIN because there is a margin on
  279. // the left and right and another margin to separate the right
  280. // side of the list view from the button.
  281. int cxViews = rc.Width() - (2*metrics.m_sizeMargin.cx);
  282. int cxTreeView = cxViews * 2 / 5;
  283. int cxListView = cxViews - cxTreeView;
  284. // Set the location of the add button. This should be aligned with
  285. // the left side of the listview and one margin height below the
  286. // top of the given rectangle.
  287. m_rcAddButton.left = m_rc.left + metrics.m_sizeMargin.cx/2 + cxTreeView - metrics.m_sizeAddButton.cx;
  288. m_rcAddButton.top = m_rc.top + metrics.m_cyLeading;
  289. m_rcAddButton.right = m_rcAddButton.left + metrics.m_sizeAddButton.cx;
  290. m_rcAddButton.bottom = m_rcAddButton.top + metrics.m_sizeAddButton.cy;
  291. // Set the location of the remove button. This should be aligned with the
  292. // top of the "Add" button and one margin size to the right of the add button.
  293. m_rcRemoveButton.left = m_rcAddButton.right + metrics.m_sizeMargin.cx;
  294. m_rcRemoveButton.top = m_rcAddButton.top;
  295. m_rcRemoveButton.right = m_rcRemoveButton.left + metrics.m_sizeRemoveButton.cx;
  296. m_rcRemoveButton.bottom = m_rcRemoveButton.top + metrics.m_sizeRemoveButton.cy;
  297. // Set the location of label1. This is the label at the top-left
  298. // of the tree control
  299. m_rcLabel1.left = m_rc.left + metrics.m_sizeMargin.cx;
  300. m_rcLabel1.top = m_rcRemoveButton.bottom + metrics.m_cyLeading + metrics.m_sizeMargin.cy;
  301. m_rcLabel1.right = m_rcLabel1.left + metrics.m_sizeLabel1.cx;
  302. m_rcLabel1.bottom = m_rcLabel1.top + metrics.m_sizeLabel1.cy;
  303. // Set the location of label2. This is at the top-left of the list box.
  304. m_rcLabel2.left = m_rcLabel1.left + cxTreeView;
  305. m_rcLabel2.top = m_rcLabel1.top;
  306. m_rcLabel2.right = m_rcLabel2.left + metrics.m_sizeLabel2.cx;
  307. m_rcLabel2.bottom = m_rcLabel2.top + metrics.m_sizeLabel2.cy;
  308. // Set the location of the tree view. This is one margin size from
  309. // the left of m_rc and one margin size below the labels. The width
  310. // has been calulated above. There is also a margin reserved on the
  311. // bottom.
  312. m_rcTreeView.left = m_rc.left + metrics.m_sizeMargin.cx;
  313. m_rcTreeView.top = m_rcLabel2.bottom + 1; // + metrics.m_sizeMargin.cy;
  314. m_rcTreeView.right = m_rcTreeView.left + cxTreeView;
  315. m_rcTreeView.bottom = m_rc.bottom - metrics.m_sizeMargin.cy;
  316. // Set the location of the list view. This is the same height as the
  317. // tree view and aligned so that its left side is adjacent to the
  318. // right side of the treeview. Its width has been calculated above.
  319. m_rcListView.left = m_rcTreeView.right - 1;
  320. m_rcListView.top = m_rcTreeView.top;
  321. m_rcListView.right = m_rcListView.left + cxListView;
  322. m_rcListView.bottom = m_rcTreeView.bottom;
  323. // Set the location of the find button so that it is aligned with the top of the
  324. // list view and so that its right side is one margin widh from m_rc.right.
  325. m_rcFindButton.left = m_rc.right - metrics.m_sizeFindButton.cx - metrics.m_sizeMargin.cx;
  326. m_rcFindButton.top = m_rcAddButton.top;
  327. m_rcFindButton.right = m_rcFindButton.left + metrics.m_sizeFindButton.cx;
  328. m_rcFindButton.bottom = m_rcFindButton.top + metrics.m_sizeFindButton.cy;
  329. }
  330. //************************************************************************
  331. // CLayout::CLayout
  332. //
  333. // Constructor for CLayout. This class is used to layout the items on
  334. // the CEventTrapDialog when it is changed from the large extended view to
  335. // the small main view. This class also handles resizing the CEventTrapDialog.
  336. //
  337. // Parameters:
  338. // None.
  339. //
  340. // Returns:
  341. // Nothing.
  342. //************************************************************************
  343. CLayout::CLayout()
  344. {
  345. m_pdlg = NULL;
  346. }
  347. //************************************************************************
  348. // CLayout::Initialize
  349. //
  350. // Take a snapshot of various initial attributes of the dialog and its
  351. // items. These attributes are used later to constrain the size of the
  352. // dialog and so on.
  353. //
  354. // This makes it possible to set certain characteristics of the dialog
  355. // in the resource editor so that they do not need to be hard-coded here.
  356. //
  357. // Parameters:
  358. // CEventTrapDlg* pdlg
  359. // Pointer to the dialog that needs to be laid out, resized
  360. // and so on.
  361. //
  362. // Returns:
  363. // Nothing.
  364. //
  365. //***********************************************************************
  366. void CLayout::Initialize(CEventTrapDlg* pdlg)
  367. {
  368. ASSERT(m_pdlg == NULL);
  369. m_pdlg = pdlg;
  370. // Dialog layout stuff
  371. CRect rcWindow;
  372. pdlg->GetWindowRect(&rcWindow);
  373. CRect rcClient;
  374. pdlg->GetClientRect(&rcClient);
  375. CRect rcEventList;
  376. pdlg->m_lcEvents.GetWindowRect(&rcEventList);
  377. pdlg->ScreenToClient(&rcEventList);
  378. m_sizeMainViewInitial.cx = rcClient.right;
  379. m_sizeMainViewInitial.cy = rcEventList.bottom + CY_MARGIN;
  380. m_sizeExtendedViewInitial.cx = rcClient.right;
  381. m_sizeExtendedViewInitial.cy = rcClient.bottom;
  382. m_cyMainView = 0;
  383. m_cyExtendedView = 0;
  384. }
  385. //*************************************************************************
  386. // CLayout::ResizeMainLayout
  387. //
  388. // This method resizes and repositions the dialog components that appear
  389. // int the small dialog layout.
  390. //
  391. // Parameters:
  392. // CMainLayout& layoutMain
  393. // The layout information for the small (main) layout.
  394. //
  395. // Returns:
  396. // Nothing.
  397. //
  398. //*************************************************************************
  399. void CLayout::ResizeMainLayout(CMainLayout& layoutMain)
  400. {
  401. m_pdlg->m_btnConfigTypeBox.MoveWindow(&layoutMain.m_rcConfigTypeBox, TRUE);
  402. m_pdlg->m_btnConfigTypeCustom.MoveWindow(&layoutMain.m_rcConfigCustomButton, TRUE);
  403. m_pdlg->m_btnConfigTypeDefault.MoveWindow(&layoutMain.m_rcConfigDefaultButton, TRUE);
  404. m_pdlg->m_btnOK.MoveWindow(&layoutMain.m_rcOKButton, TRUE);
  405. m_pdlg->m_btnCancel.MoveWindow(&layoutMain.m_rcCancelButton, TRUE);
  406. m_pdlg->m_btnApply.MoveWindow(&layoutMain.m_rcApplyButton, TRUE);
  407. m_pdlg->m_btnProps.MoveWindow(&layoutMain.m_rcPropertiesButton, TRUE);
  408. m_pdlg->m_btnSettings.MoveWindow(&layoutMain.m_rcSettingsButton, TRUE);
  409. m_pdlg->m_btnExport.MoveWindow(&layoutMain.m_rcExportButton, TRUE);
  410. m_pdlg->m_btnView.MoveWindow(&layoutMain.m_rcViewButton, TRUE);
  411. m_pdlg->m_lcEvents.MoveWindow(&layoutMain.m_rcListView, TRUE);
  412. }
  413. //*************************************************************************
  414. // CLayout::ResizeExtendedLayout
  415. //
  416. // This method resizes and repositions the dialog components that appear
  417. // int the large (extended) dialog layout.
  418. //
  419. // Parameters:
  420. // CExtendedLayout& layoutExtended
  421. // The layout information for the large (extended) layout.
  422. //
  423. // Returns:
  424. // Nothing.
  425. //
  426. //*************************************************************************
  427. void CLayout::ResizeExtendedLayout(CExtendedLayout& layoutExtended)
  428. {
  429. m_pdlg->m_btnAdd.MoveWindow(&layoutExtended.m_rcAddButton, TRUE);
  430. m_pdlg->m_btnRemove.MoveWindow(&layoutExtended.m_rcRemoveButton, TRUE);
  431. m_pdlg->m_btnFind.MoveWindow(&layoutExtended.m_rcFindButton, TRUE);
  432. m_pdlg->m_statLabel1.MoveWindow(&layoutExtended.m_rcLabel1, TRUE);
  433. m_pdlg->m_statLabel2.MoveWindow(&layoutExtended.m_rcLabel2, TRUE);
  434. m_pdlg->m_tcSource.MoveWindow(&layoutExtended.m_rcTreeView, TRUE);
  435. m_pdlg->m_lcSource.MoveWindow(&layoutExtended.m_rcListView, TRUE);
  436. }
  437. //*************************************************************************
  438. // CLayout::LayoutAndRedraw
  439. //
  440. // This lays out the size and position of each component on the dialog and
  441. // then redraws the dialog according to the new layout.
  442. //
  443. // Parameters:
  444. // BOOL bExtendedView
  445. // TRUE if the layout should be for the large (extended) view of
  446. // the dialog, FALSE if the layout should be for the small (main)
  447. // view of the dialog.
  448. //
  449. // int cx
  450. // The desired width of the dialog in screen units.
  451. //
  452. // int cy
  453. // The desired height of the dialog in screen units.
  454. //
  455. // Returns:
  456. // Nothing.
  457. //
  458. //*************************************************************************
  459. void CLayout::LayoutAndRedraw(BOOL bExtendedView, int cx, int cy)
  460. {
  461. // If the user sizes the window smaller than its original size, then
  462. // the window will begin to obscure what is already there rather than
  463. // try to make things smaller. This avoids the problems that would
  464. // occur if buttons and other controls overlapped each other.
  465. BOOL bLayoutWidth = TRUE;
  466. BOOL bLayoutHeight = TRUE;
  467. if (bExtendedView) {
  468. // Limit the minimum size of the extended view
  469. if (cx < m_sizeExtendedViewInitial.cx) {
  470. cx = m_sizeExtendedViewInitial.cx;
  471. bLayoutWidth = FALSE;
  472. }
  473. if (cy < m_sizeExtendedViewInitial.cy) {
  474. cy = m_sizeExtendedViewInitial.cy;
  475. bLayoutHeight = FALSE;
  476. }
  477. m_cyExtendedView = cy;
  478. }
  479. else {
  480. // Limit the minimum size for the small (main) view
  481. if (cx < m_sizeMainViewInitial.cx) {
  482. cx = m_sizeMainViewInitial.cx;
  483. bLayoutWidth = FALSE;
  484. }
  485. if (cy < m_sizeMainViewInitial.cy) {
  486. cy = m_sizeMainViewInitial.cy;
  487. bLayoutHeight = FALSE;
  488. }
  489. m_cyMainView = cy;
  490. }
  491. CDlgMetrics metrics(m_pdlg);
  492. CMainLayout layoutMain;
  493. CExtendedLayout layoutExtended;
  494. CRect rcMain;
  495. CRect rcExtended;
  496. int cyMain = cy;
  497. if (bExtendedView) {
  498. // For the extended view, half the space if given to the components that
  499. // appear on the small (main) layout, and the extended components get
  500. // half the space. Thus, the dialog is split horizontally at the half-way
  501. // point for the extended view.
  502. cyMain = cy / 2;
  503. rcMain.SetRect(0, 0, cx, cy / 2);
  504. layoutMain.Create(metrics, rcMain);
  505. ResizeMainLayout(layoutMain);
  506. // The extended component rectangle's top is at the half-way point. The bottom
  507. // is at the bottom of the dialog.
  508. rcExtended.SetRect(0, cy / 2, cx, cy);
  509. layoutExtended.Create(metrics, rcExtended);
  510. ResizeExtendedLayout(layoutExtended);
  511. }
  512. else {
  513. // For the small (main) view, use the entire dialog.
  514. rcMain.SetRect(0, 0, cx, cy);
  515. layoutMain.Create(metrics, rcMain);
  516. ResizeMainLayout(layoutMain);
  517. }
  518. // Redraw the entire client area to fix things up since much
  519. // of the stuff in the client has moved around.
  520. CRect rcClient;
  521. m_pdlg->GetClientRect(&rcClient);
  522. m_pdlg->InvalidateRect(&rcClient);
  523. }
  524. //**************************************************************
  525. // CLayout::LayoutView
  526. //
  527. // This method lays out the position and size of the CEventTrap
  528. // dialog and the items that appear on it.
  529. //
  530. // Parameters:
  531. // BOOL bExtendedView
  532. // TRUE if this is a request to layout the extended (large)
  533. // view of the dialog. FALSE if this is a request to layout
  534. // the small (main) view of the dialog.
  535. //
  536. // Returns:
  537. // Nothing.
  538. //**************************************************************
  539. void CLayout::LayoutView(BOOL bExtendedView)
  540. {
  541. CRect rcWindow;
  542. m_pdlg->GetWindowRect(&rcWindow);
  543. CRect rcClient;
  544. m_pdlg->GetClientRect(&rcClient);
  545. m_pdlg->ClientToScreen(&rcClient);
  546. // cx and cy are the width and height of the dialog in client units
  547. // respectively. The code below will calculate new values for cx and
  548. // cy to reflect the change from extended view to small (main) view
  549. // or vice-versa.
  550. int cx = rcClient.Width();
  551. int cy = rcClient.Height();
  552. int cxInitial = cx;
  553. int cyInitial = cy;
  554. // Compute the margins that intervene between the client
  555. // rectangle and window rectangle.
  556. int cxLeftMargin = rcClient.left - rcWindow.left;
  557. int cyTopMargin = rcClient.top - rcWindow.top;
  558. int cxRightMargin = rcWindow.right - rcClient.right;
  559. int cyBottomMargin = rcWindow.bottom - rcClient.bottom;
  560. CRect rc;
  561. m_pdlg->GetClientRect(&rc);
  562. if (bExtendedView) {
  563. // Control comes here if we are changing from the small main view
  564. // to the larger extended view. This causes the dialog to flip
  565. // back to the previous size of the extended view. However this
  566. // is constrained to a minimum of the original dialog size.
  567. // Save the current height of the main view so that we can flip
  568. // back to it later. Assume that the new height will be the
  569. // height of the extended view when it was flipped the last time.
  570. m_cyMainView = cy;
  571. cy = m_cyExtendedView;
  572. // Constrain the height so that the mimimum height is what it
  573. // the initial height was for the extended view.
  574. if (cx < m_sizeExtendedViewInitial.cx) {
  575. cx = m_sizeExtendedViewInitial.cx;
  576. }
  577. if (cy < m_sizeExtendedViewInitial.cy) {
  578. cy = m_sizeExtendedViewInitial.cy;
  579. }
  580. // The extended view should never be smaller than the main view.
  581. // This check is necessary when the user resizes the window and
  582. // then flips the view.
  583. if (cy < m_cyMainView) {
  584. cy = m_cyMainView;
  585. }
  586. rc.SetRect(0, 0, cx, cy);
  587. // Check to see if the size changed, if not then do nothing.
  588. // Otherwise, resize the window.
  589. if ((cxInitial != cx) || (cyInitial != cy)) {
  590. m_pdlg->ClientToScreen(&rc);
  591. rc.left -= cxLeftMargin;
  592. rc.top -= cyTopMargin;
  593. rc.right += cxRightMargin;
  594. rc.bottom += cyBottomMargin;
  595. m_pdlg->MoveWindow(&rc, TRUE);
  596. }
  597. else {
  598. LayoutAndRedraw(bExtendedView, cx, cy);
  599. }
  600. }
  601. // The main view should never be taller than the extended view. This may
  602. // check is necessary if the user resized the window and then flipped to the
  603. // other view.
  604. if (m_cyMainView > m_cyExtendedView) {
  605. m_cyMainView = m_cyExtendedView;
  606. }
  607. // Show or hide the items in the extended portion of the dialog.
  608. ShowExtendedView(bExtendedView);
  609. if (!bExtendedView) {
  610. // This used to be an extended view, now we need to
  611. // go back to just the main view.
  612. // Save the current extended view height and then flip back to the
  613. // previously saved main (small) view height.
  614. m_cyExtendedView = cy;
  615. cy = m_cyMainView;
  616. // Constrain the size to be at least as large as the initial size for
  617. // the main (small) view.
  618. if (cx < m_sizeMainViewInitial.cx) {
  619. cx = m_sizeMainViewInitial.cx;
  620. }
  621. if (cy < m_sizeMainViewInitial.cy) {
  622. cy = m_sizeMainViewInitial.cy;
  623. }
  624. // Resize the dialog only if the computed size is different
  625. // from the current size. Moving the window to resize it will automatically
  626. // cause it to be layed out correctly.
  627. if ((cxInitial != cx) || (cyInitial != cy)) {
  628. rc.SetRect(0, 0, cx, cy);
  629. m_pdlg->ClientToScreen(&rc);
  630. rc.left -= cxLeftMargin;
  631. rc.top -= cyTopMargin;
  632. rc.right += cxRightMargin;
  633. rc.bottom += cyBottomMargin;
  634. m_pdlg->MoveWindow(&rc, TRUE);
  635. }
  636. else {
  637. LayoutAndRedraw(bExtendedView, cx, cy);
  638. }
  639. }
  640. }
  641. //**************************************************************
  642. // CLayout::ShowExtendedView
  643. //
  644. // This method shows or hides the dialog items that make up the
  645. // extended portion of the dialog.
  646. //
  647. // Parameters:
  648. // BOOL bShowExtendedItems
  649. // TRUE if the extended items should be shown, false if
  650. // they should be hidden.
  651. //
  652. // Returns:
  653. // Nothing.
  654. //**************************************************************
  655. void CLayout::ShowExtendedView(BOOL bShowExtendedItems)
  656. {
  657. m_pdlg->m_btnRemove.ShowWindow(bShowExtendedItems);
  658. m_pdlg->m_btnAdd.ShowWindow(bShowExtendedItems);
  659. m_pdlg->m_btnFind.ShowWindow(bShowExtendedItems);
  660. m_pdlg->m_lcSource.ShowWindow(bShowExtendedItems);
  661. m_pdlg->m_tcSource.ShowWindow(bShowExtendedItems);
  662. m_pdlg->m_statLabel1.ShowWindow(bShowExtendedItems);
  663. m_pdlg->m_statLabel2.ShowWindow(bShowExtendedItems);
  664. }