Counter Strike : Global Offensive Source Code
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.

911 lines
24 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Implements the MDI child window. Each MDI child window contains one
  4. // or more views. If it contains more than one view, there is a splitter
  5. // seperating the views. All views in a given MDI child window reflect
  6. // a single document.
  7. //
  8. //===========================================================================//
  9. #include "stdafx.h"
  10. #include <oleauto.h>
  11. #include <oaidl.h>
  12. #if _MSC_VER < 1300
  13. #include <afxpriv.h>
  14. #else
  15. #define WM_INITIALUPDATE 0x0364 // (params unused) - sent to children
  16. #endif
  17. #include "hammer.h"
  18. #include "Options.h"
  19. #include "MainFrm.h"
  20. #include "ChildFrm.h"
  21. #include "MapDoc.h"
  22. #include "MapView2D.h"
  23. #include "MapViewLogical.h"
  24. #include "MapView3D.h"
  25. #include "GlobalFunctions.h"
  26. #include "materialdlg.h"
  27. // memdbgon must be the last include file in a .cpp file!!!
  28. #include "tier0/memdbgon.h"
  29. IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
  30. BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
  31. //{{AFX_MSG_MAP(CChildFrame)
  32. ON_WM_SETFOCUS()
  33. ON_WM_SIZE()
  34. ON_WM_CREATE()
  35. ON_WM_PAINT()
  36. ON_WM_CLOSE()
  37. ON_COMMAND(ID_VIEW_2DXY, OnView2dxy)
  38. ON_COMMAND(ID_VIEW_2DYZ, OnView2dyz)
  39. ON_COMMAND(ID_VIEW_2DXZ, OnView2dxz)
  40. ON_COMMAND(ID_VIEW_2DLOGICAL, OnViewLogical)
  41. ON_COMMAND(ID_VIEW_3DPOLYGON, OnView3dPolygon)
  42. ON_COMMAND(ID_VIEW_3DTEXTURED, OnView3dTextured)
  43. ON_COMMAND(ID_VIEW_3DTEXTURED_SHADED, OnView3dTexturedShaded)
  44. ON_COMMAND(ID_VIEW_LIGHTINGPREVIEW, OnView3dLightingPreview)
  45. ON_COMMAND(ID_VIEW_LIGHTINGPREVIEW_RAYTRACED, OnView3dLightingPreviewRayTraced)
  46. ON_COMMAND(ID_VIEW_3DLIGHTMAP_GRID, OnView3dLightmapGrid)
  47. ON_COMMAND(ID_VIEW_3DWIREFRAME, OnView3dWireframe)
  48. ON_COMMAND(ID_VIEW_3DSMOOTH, OnView3dSmooth)
  49. //ON_COMMAND(ID_VIEW_3DENGINE, OnView3dEngine)
  50. ON_COMMAND(ID_VIEW_AUTOSIZE4, OnViewAutosize4)
  51. ON_UPDATE_COMMAND_UI(ID_VIEW_AUTOSIZE4, OnUpdateViewAutosize4)
  52. ON_COMMAND(ID_VIEW_MAXIMIZEPANE, OnViewMaximizepane)
  53. ON_UPDATE_COMMAND_UI(ID_VIEW_MAXIMIZERESTOREACTIVEVIEW, OnUpdateViewMaximizepane)
  54. ON_COMMAND(ID_WINDOW_TOGGLE, OnWindowToggle)
  55. ON_COMMAND(ID_VIEW_MAXIMIZERESTOREACTIVEVIEW, OnViewMaximizepane)
  56. ON_WM_DESTROY()
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. static BOOL g_b4Views = TRUE;
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. // Input : b4Views -
  63. //-----------------------------------------------------------------------------
  64. void SetDefaultChildType(BOOL b4Views)
  65. {
  66. g_b4Views = b4Views;
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose: Constructor. Initializes data members.
  70. //-----------------------------------------------------------------------------
  71. CChildFrame::CChildFrame(void)
  72. {
  73. m_bReady = FALSE;
  74. bAutosize4 = TRUE;
  75. bFirstPaint = TRUE;
  76. bUsingSplitter = !g_b4Views ? FALSE : !Options.general.bIndependentwin;
  77. m_wndSplitter = NULL;
  78. m_bNeedsCentered = FALSE;
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Purpose:
  82. //-----------------------------------------------------------------------------
  83. CChildFrame::~CChildFrame(void)
  84. {
  85. if (m_wndSplitter != NULL)
  86. {
  87. m_wndSplitter->DestroyWindow();
  88. delete m_wndSplitter;
  89. }
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose:
  93. // Input : cs -
  94. // Output : Returns TRUE on success, FALSE on failure.
  95. //-----------------------------------------------------------------------------
  96. BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
  97. {
  98. //cs.style |= WS_MAXIMIZE;
  99. return(CMDIChildWnd::PreCreateWindow(cs));
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. // Input :
  104. // Output : CView *
  105. //-----------------------------------------------------------------------------
  106. CView * CChildFrame::GetActiveView()
  107. {
  108. // find active pane in splitter wnd and replace it there
  109. int iRow, iCol;
  110. CView *pCurrentView;
  111. if(bUsingSplitter)
  112. {
  113. m_wndSplitter->GetActivePane(&iRow, &iCol);
  114. // If no active view for the frame, return FALSE because this
  115. // function retrieves the current document from the active view.
  116. if ((pCurrentView= (CView*) m_wndSplitter->GetPane(iRow, iCol))==NULL)
  117. return NULL;
  118. }
  119. else
  120. {
  121. pCurrentView = CMDIChildWnd::GetActiveView();
  122. }
  123. return pCurrentView;
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. // Input : bSplitter -
  128. //-----------------------------------------------------------------------------
  129. void CChildFrame::SetSplitterMode(BOOL bSplitter)
  130. {
  131. if(bSplitter == bUsingSplitter)
  132. return; // already at this mode
  133. if(!bSplitter)
  134. {
  135. // delete the splitterwnd.. first, get the view that it is currently
  136. // using.
  137. CView * pActiveView = GetActiveView();
  138. CDocument* pDoc = pActiveView->GetDocument();
  139. BOOL bAutoDelete=pDoc->m_bAutoDelete;
  140. pDoc->m_bAutoDelete=FALSE;
  141. pActiveView->SetRedraw(FALSE);
  142. m_wndSplitter->SetRedraw(FALSE);
  143. pActiveView->SetParent(this);
  144. m_wndSplitter->DestroyWindow();
  145. delete m_wndSplitter;
  146. m_wndSplitter = NULL;
  147. pDoc->m_bAutoDelete = bAutoDelete;
  148. // redraw active view
  149. CRect r;
  150. GetClientRect(r);
  151. pActiveView->SetRedraw(TRUE);
  152. pActiveView->MoveWindow(0, 0, r.right, r.bottom, TRUE);
  153. }
  154. else
  155. {
  156. CView * pActiveView = GetActiveView();
  157. Assert(pActiveView);
  158. CMapDoc* pDoc = (CMapDoc*) pActiveView->GetDocument();
  159. BOOL bAutoDelete=pDoc->m_bAutoDelete;
  160. pDoc->m_bAutoDelete=FALSE;
  161. pActiveView->DestroyWindow();
  162. pDoc->m_bAutoDelete = bAutoDelete;
  163. // creating new four views.
  164. m_wndSplitter = new CMySplitterWnd;
  165. if(!m_wndSplitter->CreateStatic(this, 2, 2))
  166. {
  167. TRACE0("Failed to create split bar ");
  168. return; // failed to create
  169. }
  170. CRect r;
  171. GetClientRect(r);
  172. CSize sizeView(r.Width()/2 - 3, r.Height()/2 - 3);
  173. CCreateContext context;
  174. context.m_pNewViewClass = NULL;
  175. context.m_pCurrentDoc = pDoc;
  176. context.m_pNewDocTemplate = NULL;
  177. context.m_pLastView = NULL;
  178. context.m_pCurrentFrame = this;
  179. context.m_pNewViewClass = RUNTIME_CLASS(CMapView2D);
  180. m_wndSplitter->CreateView(0, 1, RUNTIME_CLASS(CMapView2D),
  181. sizeView, &context);
  182. m_wndSplitter->CreateView(1, 0, RUNTIME_CLASS(CMapView2D),
  183. sizeView, &context);
  184. m_wndSplitter->CreateView(1, 1, RUNTIME_CLASS(CMapView2D),
  185. sizeView, &context);
  186. context.m_pNewViewClass = RUNTIME_CLASS(CMapView3D);
  187. m_wndSplitter->CreateView(0, 0, context.m_pNewViewClass,
  188. sizeView, &context);
  189. }
  190. bUsingSplitter = bSplitter;
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Purpose: Replaces the current active view with a given view type.
  194. // Input : *pViewClass -
  195. // Output : CView
  196. //-----------------------------------------------------------------------------
  197. CView *CChildFrame::ReplaceView(CRuntimeClass *pViewClass)
  198. {
  199. //
  200. // Verify that there is an active view to replace.
  201. //
  202. CView *pCurrentView = GetActiveView();
  203. if (!pCurrentView)
  204. {
  205. return(NULL);
  206. }
  207. //
  208. // If we're already displaying this kind of view, no need to go
  209. // further.
  210. //
  211. if ((pCurrentView->IsKindOf(pViewClass)) == TRUE)
  212. {
  213. return(pCurrentView);
  214. }
  215. //
  216. // Get pointer to CDocument object so that it can be used in the
  217. // creation process of the new view. Set flag so that the document
  218. // will not be deleted when view is destroyed.
  219. //
  220. CMapDoc *pDoc = (CMapDoc *)pCurrentView->GetDocument();
  221. BOOL bAutoDelete = pDoc->m_bAutoDelete;
  222. pDoc->m_bAutoDelete=FALSE;
  223. int iRow = 0, iCol = 0;
  224. CRect rect;
  225. // Delete existing view
  226. if (bUsingSplitter)
  227. {
  228. pCurrentView->GetClientRect(rect);
  229. m_wndSplitter->GetActivePane(&iRow, &iCol);
  230. m_wndSplitter->DeleteView(iRow, iCol);
  231. }
  232. else
  233. {
  234. pCurrentView->DestroyWindow();
  235. }
  236. // Restore the autodelete flag.
  237. pDoc->m_bAutoDelete = bAutoDelete;
  238. // Create new view and redraw.
  239. CCreateContext context;
  240. context.m_pNewViewClass = pViewClass;
  241. context.m_pCurrentDoc = pDoc;
  242. context.m_pNewDocTemplate = NULL;
  243. context.m_pLastView = NULL;
  244. context.m_pCurrentFrame=this;
  245. CView *pNewView = NULL;
  246. if (bUsingSplitter)
  247. {
  248. if (m_wndSplitter->CreateView(iRow, iCol, pViewClass, rect.Size(), &context))
  249. {
  250. pNewView = (CView *)m_wndSplitter->GetPane(iRow, iCol);
  251. }
  252. }
  253. else
  254. {
  255. pNewView = (CView *)pViewClass->CreateObject();
  256. if (pNewView)
  257. {
  258. CRect r;
  259. GetClientRect(r);
  260. if (!pNewView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, r, this, AFX_IDW_PANE_FIRST, &context))
  261. {
  262. pNewView = NULL;
  263. }
  264. }
  265. }
  266. if (!pNewView)
  267. {
  268. TRACE0("Warning: couldn't create view for frame\n");
  269. return(NULL);
  270. }
  271. pNewView->SendMessage(WM_INITIALUPDATE, 0, 0);
  272. if (bUsingSplitter)
  273. {
  274. m_wndSplitter->RecalcLayout();
  275. }
  276. return(pNewView);
  277. }
  278. #ifdef _DEBUG
  279. //-----------------------------------------------------------------------------
  280. // Purpose:
  281. // Input :
  282. //-----------------------------------------------------------------------------
  283. void CChildFrame::AssertValid() const
  284. {
  285. CMDIChildWnd::AssertValid();
  286. }
  287. //-----------------------------------------------------------------------------
  288. // Purpose:
  289. // Input : dc -
  290. //-----------------------------------------------------------------------------
  291. void CChildFrame::Dump(CDumpContext& dc) const
  292. {
  293. CMDIChildWnd::Dump(dc);
  294. }
  295. #endif //_DEBUG
  296. //-----------------------------------------------------------------------------
  297. // Purpose: Stores layout information in the registry for use next session.
  298. //-----------------------------------------------------------------------------
  299. void CChildFrame::SaveOptions(void)
  300. {
  301. if (bUsingSplitter)
  302. {
  303. //
  304. // Save the draw type for each pane of the splitter.
  305. //
  306. for (int nRow = 0; nRow < 2; nRow++)
  307. {
  308. for (int nCol = 0; nCol < 2; nCol++)
  309. {
  310. CMapView *pView = dynamic_cast<CMapView*>(m_wndSplitter->GetPane(nRow, nCol));
  311. if (pView != NULL)
  312. {
  313. char szKey[30];
  314. sprintf(szKey, "DrawType%d,%d", nRow, nCol);
  315. APP()->WriteProfileInt("Splitter", szKey, pView->GetDrawType());
  316. }
  317. }
  318. }
  319. int nWidth, nHeight, nMin;
  320. m_wndSplitter->GetColumnInfo( 0, nWidth, nMin );
  321. m_wndSplitter->GetRowInfo( 0, nHeight, nMin );
  322. APP()->WriteProfileInt( "Splitter", "SplitterWidth", nWidth );
  323. APP()->WriteProfileInt( "Splitter", "SplitterHeight", nHeight );
  324. //
  325. // Save the window position, size, and minimized/maximized state.
  326. //
  327. WINDOWPLACEMENT wp;
  328. wp.length = sizeof(wp);
  329. GetWindowPlacement(&wp);
  330. char szPlacement[100];
  331. sprintf(szPlacement, "(%d %d) (%d %d) (%d %d %d %d) %d", wp.ptMaxPosition.x, wp.ptMaxPosition.y, wp.ptMinPosition.x, wp.ptMinPosition.y, wp.rcNormalPosition.bottom, wp.rcNormalPosition.left, wp.rcNormalPosition.right, wp.rcNormalPosition.top, wp.showCmd);
  332. APP()->WriteProfileString("Splitter", "WindowPlacement", szPlacement);
  333. }
  334. }
  335. //-----------------------------------------------------------------------------
  336. // Purpose: Calls ReplaceView with the appropriate runtime class information to
  337. // switch the active view to given view type.
  338. // Input : eViewType - 2d xy, xz, 3d textured, flat, etc.
  339. //-----------------------------------------------------------------------------
  340. void CChildFrame::SetViewType(DrawType_t eViewType)
  341. {
  342. CMapView *pNewView = NULL;
  343. switch (eViewType)
  344. {
  345. case VIEW2D_XY:
  346. case VIEW2D_XZ:
  347. case VIEW2D_YZ:
  348. pNewView = (CMapView2D *)ReplaceView(RUNTIME_CLASS(CMapView2D));
  349. break;
  350. case VIEW_LOGICAL:
  351. pNewView = (CMapViewLogical *)ReplaceView(RUNTIME_CLASS(CMapViewLogical));
  352. break;
  353. default:
  354. case VIEW3D_WIREFRAME:
  355. case VIEW3D_POLYGON:
  356. case VIEW3D_TEXTURED:
  357. case VIEW3D_TEXTURED_SHADED:
  358. case VIEW3D_LIGHTMAP_GRID:
  359. case VIEW3D_LIGHTING_PREVIEW2:
  360. case VIEW3D_LIGHTING_PREVIEW_RAYTRACED:
  361. case VIEW3D_SMOOTHING_GROUP:
  362. //case VIEW3D_ENGINE:
  363. pNewView = (CMapView3D *)ReplaceView(RUNTIME_CLASS(CMapView3D));
  364. break;
  365. }
  366. if (pNewView != NULL)
  367. {
  368. SetActiveView( dynamic_cast<CView*>(pNewView->GetViewWnd()) );
  369. pNewView->SetDrawType(eViewType);
  370. pNewView->UpdateView( MAPVIEW_UPDATE_OBJECTS );
  371. }
  372. }
  373. //-----------------------------------------------------------------------------
  374. // Purpose: Handles the ID_VIEW_2DXY command when the active view is a 3D view.
  375. //-----------------------------------------------------------------------------
  376. void CChildFrame::OnView2dxy(void)
  377. {
  378. SetViewType(VIEW2D_XY);
  379. }
  380. //-----------------------------------------------------------------------------
  381. // Purpose: Handles the ID_VIEW_2DYZ command when the active view is a 3D view.
  382. //-----------------------------------------------------------------------------
  383. void CChildFrame::OnView2dyz(void)
  384. {
  385. SetViewType(VIEW2D_YZ);
  386. }
  387. //-----------------------------------------------------------------------------
  388. // Purpose: Handles the ID_VIEW_2DXZ command when the active view is a 3D view.
  389. //-----------------------------------------------------------------------------
  390. void CChildFrame::OnView2dxz(void)
  391. {
  392. SetViewType(VIEW2D_XZ);
  393. }
  394. //-----------------------------------------------------------------------------
  395. // Purpose: Handles the ID_VIEW_2DLOGICAL command when the active view is a 3D view.
  396. //-----------------------------------------------------------------------------
  397. void CChildFrame::OnViewLogical(void)
  398. {
  399. SetViewType(VIEW_LOGICAL);
  400. }
  401. //-----------------------------------------------------------------------------
  402. // Purpose: Handles the ID_VIEW_3DWIREFRAME command when the active view is a 2D view.
  403. //-----------------------------------------------------------------------------
  404. void CChildFrame::OnView3dWireframe(void)
  405. {
  406. SetViewType(VIEW3D_WIREFRAME);
  407. }
  408. //-----------------------------------------------------------------------------
  409. // Purpose: Handles the ID_VIEW_3DPOLYGON command when the active view is a 2D view.
  410. //-----------------------------------------------------------------------------
  411. void CChildFrame::OnView3dPolygon(void)
  412. {
  413. SetViewType(VIEW3D_POLYGON);
  414. }
  415. //-----------------------------------------------------------------------------
  416. // Purpose: Handles the ID_VIEW_3DTEXTURED command when the active view is a 2D view.
  417. //-----------------------------------------------------------------------------
  418. void CChildFrame::OnView3dTextured(void)
  419. {
  420. SetViewType(VIEW3D_TEXTURED);
  421. }
  422. void CChildFrame::OnView3dTexturedShaded(void)
  423. {
  424. SetViewType(VIEW3D_TEXTURED_SHADED);
  425. }
  426. void CChildFrame::OnView3dLightingPreview(void)
  427. {
  428. SetViewType(VIEW3D_LIGHTING_PREVIEW2);
  429. }
  430. void CChildFrame::OnView3dLightingPreviewRayTraced(void)
  431. {
  432. SetViewType(VIEW3D_LIGHTING_PREVIEW_RAYTRACED);
  433. }
  434. //-----------------------------------------------------------------------------
  435. // Purpose: Handles the ID_VIEW_3DTEXTURED command when the active view is a 2D view.
  436. //-----------------------------------------------------------------------------
  437. void CChildFrame::OnView3dLightmapGrid(void)
  438. {
  439. SetViewType(VIEW3D_LIGHTMAP_GRID);
  440. }
  441. //-----------------------------------------------------------------------------
  442. // Purpose: Handles the ID_VIEW_3DSMOOTH command when the active view is a 3D view.
  443. //-----------------------------------------------------------------------------
  444. void CChildFrame::OnView3dSmooth(void)
  445. {
  446. SetViewType(VIEW3D_SMOOTHING_GROUP);
  447. }
  448. //-----------------------------------------------------------------------------
  449. // Purpose: Handles the ID_VIEW_3DENGINE command when the active view is a 2D view.
  450. //-----------------------------------------------------------------------------
  451. //void CChildFrame::OnView3dEngine(void)
  452. //{
  453. // SetViewType(VIEW3D_ENGINE);
  454. //}
  455. //-----------------------------------------------------------------------------
  456. // Purpose: Overloaded to handle the 2x2 splitter. If the splitter is enabled,
  457. // the splitter window is createed and one 3D view and three 2D views
  458. // are added to it.
  459. // Input : lpcs -
  460. // pContext -
  461. // Output : Returns TRUE on success, FALSE on failure.
  462. //-----------------------------------------------------------------------------
  463. BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext *pContext)
  464. {
  465. //
  466. // If we are using the splitter, create the splitter and 4 views.
  467. //
  468. if (bUsingSplitter)
  469. {
  470. m_wndSplitter = new CMySplitterWnd;
  471. Assert(m_wndSplitter != NULL);
  472. if (m_wndSplitter == NULL)
  473. {
  474. return(FALSE);
  475. }
  476. if (!m_wndSplitter->CreateStatic(this, 2, 2))
  477. {
  478. delete m_wndSplitter;
  479. m_wndSplitter = NULL;
  480. TRACE0("Failed to create split bar ");
  481. return(FALSE);
  482. }
  483. //
  484. // Calculate the size of each view within the splitter,
  485. //
  486. CRect r;
  487. GetClientRect(r);
  488. CSize sizeView((r.Width() / 2) - 3, (r.Height() / 2) - 3);
  489. //
  490. // Create the 4 views as they were when the user last closed the app.
  491. //
  492. DrawType_t eDrawType[2][2];
  493. eDrawType[0][0] = (DrawType_t)APP()->GetProfileInt("Splitter", "DrawType0,0", VIEW3D_WIREFRAME);
  494. eDrawType[0][1] = (DrawType_t)APP()->GetProfileInt("Splitter", "DrawType0,1", VIEW2D_XY);
  495. eDrawType[1][0] = (DrawType_t)APP()->GetProfileInt("Splitter", "DrawType1,0", VIEW2D_YZ);
  496. eDrawType[1][1] = (DrawType_t)APP()->GetProfileInt("Splitter", "DrawType1,1", VIEW2D_XZ);
  497. for (int nRow = 0; nRow < 2; nRow++)
  498. {
  499. for (int nCol = 0; nCol < 2; nCol++)
  500. {
  501. // These might be lying around in people's registry.
  502. if ((eDrawType[nRow][nCol] == VIEW3D_ENGINE) || (eDrawType[nRow][nCol] >= VIEW_TYPE_LAST))
  503. {
  504. eDrawType[nRow][nCol] = VIEW3D_TEXTURED;
  505. }
  506. switch (eDrawType[nRow][nCol])
  507. {
  508. case VIEW2D_XY:
  509. case VIEW2D_XZ:
  510. case VIEW2D_YZ:
  511. {
  512. m_wndSplitter->CreateView(nRow, nCol, RUNTIME_CLASS(CMapView2D), sizeView, pContext);
  513. break;
  514. }
  515. case VIEW_LOGICAL:
  516. {
  517. m_wndSplitter->CreateView(nRow, nCol, RUNTIME_CLASS(CMapViewLogical), sizeView, pContext);
  518. break;
  519. }
  520. case VIEW3D_WIREFRAME:
  521. case VIEW3D_POLYGON:
  522. case VIEW3D_TEXTURED:
  523. case VIEW3D_TEXTURED_SHADED:
  524. case VIEW3D_LIGHTMAP_GRID:
  525. case VIEW3D_LIGHTING_PREVIEW2:
  526. case VIEW3D_LIGHTING_PREVIEW_RAYTRACED:
  527. case VIEW3D_SMOOTHING_GROUP:
  528. {
  529. m_wndSplitter->CreateView(nRow, nCol, RUNTIME_CLASS(CMapView3D), sizeView, pContext);
  530. break;
  531. }
  532. }
  533. CMapView *pView = dynamic_cast<CMapView*>(m_wndSplitter->GetPane(nRow, nCol));
  534. if (pView != NULL)
  535. {
  536. pView->SetDrawType(eDrawType[nRow][nCol]);
  537. }
  538. }
  539. }
  540. int nWidth = APP()->GetProfileInt("Splitter", "SplitterWidth", -1);
  541. int nHeight = APP()->GetProfileInt("Splitter", "SplitterHeight", -1);
  542. if ( nWidth != -1 && nHeight != -1 )
  543. {
  544. m_wndSplitter->SetRowInfo( 0, nHeight, 0 );
  545. m_wndSplitter->SetColumnInfo( 0, nWidth, 0 );
  546. m_wndSplitter->RecalcLayout();
  547. }
  548. else
  549. {
  550. m_bNeedsCentered = TRUE;
  551. }
  552. m_bReady = TRUE;
  553. return TRUE;
  554. }
  555. //
  556. // No splitter, call default creation code.
  557. //
  558. return(CMDIChildWnd::OnCreateClient(lpcs, pContext));
  559. }
  560. //-----------------------------------------------------------------------------
  561. // Purpose:
  562. //-----------------------------------------------------------------------------
  563. void CChildFrame::CenterViews(void)
  564. {
  565. if (!bUsingSplitter || !m_bReady)
  566. {
  567. return;
  568. }
  569. WriteDebug("childfrm::centerviews");
  570. CRect r;
  571. GetClientRect(r);
  572. CSize sizeView(r.Width()/2 - 3, r.Height()/2 - 3);
  573. sizeView.cy = max(0, sizeView.cy);
  574. sizeView.cx = max(0, sizeView.cx);
  575. m_wndSplitter->SetRowInfo(0, sizeView.cy, 0);
  576. m_wndSplitter->SetRowInfo(1, sizeView.cy, 0);
  577. m_wndSplitter->SetColumnInfo(0, sizeView.cx, 0);
  578. m_wndSplitter->SetColumnInfo(1, sizeView.cx, 0);
  579. m_wndSplitter->RecalcLayout();
  580. WriteDebug("childfrm::centerviews done");
  581. }
  582. //-----------------------------------------------------------------------------
  583. // Purpose:
  584. //-----------------------------------------------------------------------------
  585. void CChildFrame::OnViewAutosize4(void)
  586. {
  587. if (!bUsingSplitter)
  588. {
  589. return;
  590. }
  591. if (0) // bAutosize4)
  592. {
  593. bAutosize4 = FALSE;
  594. }
  595. else
  596. {
  597. // resize 4 views
  598. CenterViews();
  599. }
  600. }
  601. //-----------------------------------------------------------------------------
  602. // Purpose:
  603. // Input : pCmdUI -
  604. //-----------------------------------------------------------------------------
  605. void CChildFrame::OnUpdateViewAutosize4(CCmdUI *pCmdUI)
  606. {
  607. }
  608. //-----------------------------------------------------------------------------
  609. // Purpose:
  610. // Input : nType -
  611. // cx -
  612. // cy -
  613. //-----------------------------------------------------------------------------
  614. void CChildFrame::OnSize(UINT nType, int cx, int cy)
  615. {
  616. CMDIChildWnd::OnSize(nType, cx, cy);
  617. }
  618. //-----------------------------------------------------------------------------
  619. // Purpose:
  620. // Input : lpCreateStruct -
  621. // Output : int
  622. //-----------------------------------------------------------------------------
  623. int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  624. {
  625. if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
  626. {
  627. return(-1);
  628. }
  629. //
  630. // The splitter gets its layout from the registry.
  631. //
  632. if ( bUsingSplitter && CHammer::IsNewDocumentVisible() )
  633. {
  634. CString str = APP()->GetProfileString("Splitter", "WindowPlacement", "");
  635. if (!str.IsEmpty())
  636. {
  637. WINDOWPLACEMENT wp;
  638. wp.length = sizeof(wp);
  639. wp.flags = 0;
  640. sscanf(str, "(%d %d) (%d %d) (%d %d %d %d) %d", &wp.ptMaxPosition.x, &wp.ptMaxPosition.y, &wp.ptMinPosition.x, &wp.ptMinPosition.y, &wp.rcNormalPosition.bottom, &wp.rcNormalPosition.left, &wp.rcNormalPosition.right, &wp.rcNormalPosition.top, &wp.showCmd);
  641. if (wp.showCmd == SW_SHOWMAXIMIZED)
  642. {
  643. PostMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  644. }
  645. else
  646. {
  647. SetWindowPlacement(&wp);
  648. }
  649. }
  650. }
  651. return(0);
  652. }
  653. //-----------------------------------------------------------------------------
  654. // Purpose:
  655. //-----------------------------------------------------------------------------
  656. void CChildFrame::OnPaint(void)
  657. {
  658. if (bFirstPaint)
  659. {
  660. ValidateRect(NULL);
  661. bFirstPaint = FALSE;
  662. if ( m_bNeedsCentered )
  663. {
  664. CenterViews();
  665. }
  666. Invalidate();
  667. return;
  668. }
  669. CPaintDC dc(this); // device context for painting
  670. }
  671. //-----------------------------------------------------------------------------
  672. // Purpose:
  673. // Input : *pWnd -
  674. //-----------------------------------------------------------------------------
  675. void CMySplitterWnd::ToggleMax(CWnd *pWnd)
  676. {
  677. int ir, ic;
  678. if(!pMaxPrev)
  679. {
  680. int dummy;
  681. // save current info
  682. GetRowInfo(0, sizePrev[1][0], dummy);
  683. GetRowInfo(1, sizePrev[1][1], dummy);
  684. GetColumnInfo(0, sizePrev[0][0], dummy);
  685. GetColumnInfo(1, sizePrev[0][1], dummy);
  686. }
  687. if(pWnd != pMaxPrev)
  688. {
  689. // maximize this one
  690. int iRow, iCol;
  691. CRect r;
  692. GetClientRect(r);
  693. VERIFY(IsChildPane(pWnd, &iRow, &iCol));
  694. for(ir = 0; ir < 2; ir++)
  695. {
  696. for(ic = 0; ic < 2; ic++)
  697. {
  698. SetRowInfo(ir, 0, 0);
  699. SetColumnInfo(ic, 0, 0);
  700. }
  701. }
  702. SetRowInfo(iRow, r.Height(), 5);
  703. SetColumnInfo(iCol, r.Width(), 5);
  704. pMaxPrev = pWnd;
  705. }
  706. else
  707. {
  708. // restore saved info
  709. SetRowInfo(0, sizePrev[1][0], 0);
  710. SetRowInfo(1, sizePrev[1][1], 0);
  711. SetColumnInfo(0, sizePrev[0][0], 0);
  712. SetColumnInfo(1, sizePrev[0][1], 0);
  713. pMaxPrev = NULL;
  714. }
  715. RecalcLayout();
  716. }
  717. //-----------------------------------------------------------------------------
  718. // Purpose:
  719. //-----------------------------------------------------------------------------
  720. void CChildFrame::OnViewMaximizepane(void)
  721. {
  722. if (!bUsingSplitter)
  723. {
  724. return;
  725. }
  726. // find current wndsplitter pane, & call ToggleMax() in
  727. // cmysplitterwnd.
  728. if (m_wndSplitter->GetActivePane())
  729. {
  730. m_wndSplitter->ToggleMax(m_wndSplitter->GetActivePane());
  731. }
  732. }
  733. //-----------------------------------------------------------------------------
  734. // Purpose:
  735. // Input : *pCmdUI -
  736. //-----------------------------------------------------------------------------
  737. void CChildFrame::OnUpdateViewMaximizepane(CCmdUI *pCmdUI)
  738. {
  739. pCmdUI->Enable();
  740. }
  741. //-----------------------------------------------------------------------------
  742. // Purpose:
  743. // Input :
  744. //-----------------------------------------------------------------------------
  745. void CChildFrame::OnWindowToggle(void)
  746. {
  747. // SetSplitterMode(!bUsingSplitter);
  748. }
  749. //-----------------------------------------------------------------------------
  750. // Purpose: Saves the splitter setup for next time.
  751. //-----------------------------------------------------------------------------
  752. void CChildFrame::OnClose(void)
  753. {
  754. SaveOptions();
  755. CFrameWnd::OnClose();
  756. }
  757. void CChildFrame::OnSetFocus( CWnd* pOldWnd )
  758. {
  759. CMDIChildWnd::OnSetFocus( pOldWnd );
  760. CMapDoc *pDoc = dynamic_cast<CMapDoc*>(GetActiveDocument());
  761. if ( pDoc )
  762. CMapDoc::SetActiveMapDoc( pDoc );
  763. }