MainFrm.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. // MainFrm.cpp : implementation of the MainFrame class
  5. //
  6. #include "stdafx.h"
  7. #include "EditorMFC.h"
  8. #include "MainFrm.h"
  9. /////////////////////////////////////////////////////////////////////////////
  10. // MainFrame
  11. IMPLEMENT_DYNAMIC(MainFrame, CFrameWnd)
  12. BEGIN_MESSAGE_MAP(MainFrame, CFrameWnd)
  13. //{{AFX_MSG_MAP(MainFrame)
  14. ON_WM_CREATE()
  15. ON_WM_SETFOCUS()
  16. ON_WM_CLOSE()
  17. //}}AFX_MSG_MAP
  18. END_MESSAGE_MAP()
  19. static UINT indicators[] =
  20. {
  21. ID_SEPARATOR, // status line indicator
  22. ID_INDICATOR_CAPS,
  23. ID_INDICATOR_NUM,
  24. ID_INDICATOR_SCRL,
  25. };
  26. /////////////////////////////////////////////////////////////////////////////
  27. // MainFrame construction/destruction
  28. MainFrame::MainFrame()
  29. {
  30. }
  31. MainFrame::~MainFrame()
  32. {
  33. }
  34. int MainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  35. {
  36. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  37. return -1;
  38. // create a view to occupy the client area of the frame
  39. if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW | WS_VSCROLL | WS_HSCROLL,
  40. CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
  41. {
  42. TRACE0("Failed to create view window\n");
  43. return -1;
  44. }
  45. /*
  46. if (!m_wndToolBar.CreateEx(this) ||
  47. !m_wndToolBar.LoadToolBar(IDR_EDITOR_MENU))
  48. {
  49. TRACE0("Failed to create toolbar\n");
  50. return -1; // fail to create
  51. }
  52. */
  53. if (!m_wndDlgBar.Create(this, IDR_EDITOR_MENU,
  54. CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
  55. {
  56. TRACE0("Failed to create dialogbar\n");
  57. return -1; // fail to create
  58. }
  59. /* mh: rebars don't seem to be supported under win95 */
  60. #if 0
  61. if (!m_wndReBar.Create(this) ||
  62. /*!m_wndReBar.AddBar(&m_wndToolBar) ||*/
  63. !m_wndReBar.AddBar(&m_wndDlgBar))
  64. {
  65. TRACE0("Failed to create rebar\n");
  66. return -1; // fail to create
  67. }
  68. #endif
  69. if (!m_wndStatusBar.Create(this) ||
  70. !m_wndStatusBar.SetIndicators(indicators,
  71. sizeof(indicators)/sizeof(UINT)))
  72. {
  73. TRACE0("Failed to create status bar\n");
  74. return -1; // fail to create
  75. }
  76. /*
  77. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  78. CBRS_TOOLTIPS | CBRS_FLYBY);
  79. */
  80. return 0;
  81. }
  82. BOOL MainFrame::PreCreateWindow(CREATESTRUCT& cs)
  83. {
  84. if( !CFrameWnd::PreCreateWindow(cs) )
  85. return FALSE;
  86. // cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  87. cs.lpszClass = AfxRegisterWndClass(0);
  88. cs.cx = GetSystemMetrics( SM_CXFULLSCREEN );;
  89. cs.cy = GetSystemMetrics( SM_CYFULLSCREEN );;
  90. cs.x = 0;
  91. cs.y = 0;
  92. return TRUE;
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. // MainFrame diagnostics
  96. #ifdef _DEBUG
  97. void MainFrame::AssertValid() const
  98. {
  99. CFrameWnd::AssertValid();
  100. }
  101. void MainFrame::Dump(CDumpContext& dc) const
  102. {
  103. CFrameWnd::Dump(dc);
  104. }
  105. #endif //_DEBUG
  106. /////////////////////////////////////////////////////////////////////////////
  107. // MainFrame message handlers
  108. void MainFrame::OnSetFocus(CWnd* pOldWnd)
  109. {
  110. // forward focus to the view window
  111. if (m_wndView.m_hWnd) {
  112. m_wndView.SetFocus();
  113. }
  114. }
  115. BOOL MainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
  116. {
  117. // let the view have first crack at the command
  118. if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  119. return TRUE;
  120. // otherwise, do default handling
  121. return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  122. }
  123. LRESULT MainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  124. {
  125. if ( message == WM_MOVE )
  126. {
  127. POINT tmp;
  128. tmp.x = LOWORD(lParam) + 30;
  129. tmp.y = HIWORD(lParam) + 30;
  130. EditorInterface::instance()->ScreenToClient( &tmp );
  131. LPARAM lNewParam = tmp.y << 16 | tmp.x;
  132. EditorInterface::instance()->SendMessage( WM_MOVE, wParam, lNewParam );
  133. }
  134. return CFrameWnd::WindowProc(message, wParam, lParam);
  135. }
  136. void MainFrame::OnClose()
  137. {
  138. int res = IDNO;
  139. if (EditorInterface::instance() && EditorInterface::instance()->ThisIsInitialized()
  140. && EditorData::instance) {
  141. res = EditorInterface::instance()->PromptAndSaveIfNecessary();
  142. }
  143. if (IDCANCEL != res) {
  144. if (EditorInterface::instance()) {
  145. EditorInterface::instance()->SetBusyMode();
  146. }
  147. gos_TerminateApplication();
  148. PostQuitMessage(0);
  149. if (EditorInterface::instance()) {
  150. EditorInterface::instance()->UnsetBusyMode();
  151. }
  152. }
  153. }