mainfrm.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:13k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // mainfrm.cpp : implementation of the CMainFrame class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "drawcli.h"
  22. #include "mainfrm.h"
  23. #include "SplitFrm.h"
  24. #include "DrawVw.h"
  25. #include "DrawDoc.h"
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char BASED_CODE THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMainFrame
  32. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  33. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  34. //{{AFX_MSG_MAP(CMainFrame)
  35. ON_WM_CREATE()
  36. ON_WM_DESTROY()
  37. ON_COMMAND(ID_PROPERTIES, OnProperties)
  38. //}}AFX_MSG_MAP
  39. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  40. ON_MESSAGE(XTPWM_PROPERTYGRID_NOTIFY, OnGridNotify)
  41. ON_WM_CLOSE()
  42. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  43. ON_MESSAGE(WM_XTP_PRETRANSLATEMOUSEMSG, OnTabbarMouseMsg)
  44. END_MESSAGE_MAP()
  45. static UINT BASED_CODE indicators[] =
  46. {
  47. ID_SEPARATOR,           // status line indicator
  48. ID_INDICATOR_CAPS,
  49. ID_INDICATOR_NUM,
  50. ID_INDICATOR_SCRL,
  51. };
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CMainFrame construction/destruction
  54. CMainFrame::CMainFrame()
  55. {
  56. m_pView = 0;
  57. m_bInUpdate = FALSE;
  58. }
  59. CMainFrame::~CMainFrame()
  60. {
  61. }
  62. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  63. {
  64. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  65. return -1;
  66. XTThemeManager()->SetTheme(xtThemeOffice2003);
  67. if (!m_wndStatusBar.Create(this) ||
  68. !m_wndStatusBar.SetIndicators(indicators,
  69.   sizeof(indicators)/sizeof(UINT)))
  70. {
  71. TRACE0("Failed to create status barn");
  72. return -1;      // fail to create
  73. }
  74. if (!InitCommandBars())
  75. return -1;
  76. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  77. CXTPCommandBars* pCommandBars = GetCommandBars();
  78. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_DRAWCLTYPE);
  79. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage);
  80. CXTPToolBar* pCommandBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  81. if (!pCommandBar ||
  82. !pCommandBar->LoadToolBar(IDR_MAINFRAME))
  83. {
  84. TRACE0("Failed to create toolbarn");
  85. return -1;
  86. }
  87. CXTPToolBar* pOrderBar = (CXTPToolBar*)pCommandBars->Add(_T("Order"), xtpBarBottom);
  88. if (!pOrderBar ||
  89. !pOrderBar->LoadToolBar(IDR_TOOLBAR_ORDER))
  90. {
  91. TRACE0("Failed to create toolbarn");
  92. return -1;
  93. }
  94. for (int i = 0; i < pOrderBar->GetControls()->GetCount(); i++)
  95. pOrderBar->GetControl(i)->SetStyle(xtpButtonIconAndCaption);
  96. pOrderBar->GetControls()->CreateOriginalControls();
  97. VERIFY(m_MTIClientWnd.Attach(this));
  98. XTPImageManager()->SetIcons(IDR_COLORS);
  99. CXTPOffice2003Theme::LoadModernToolbarIcons(IDR_MAINFRAME);
  100. CXTPOffice2003Theme::LoadModernToolbarIcons(IDR_TOOLBAR_ORDER);
  101. GetDockingPaneManager()->InstallDockingPanes(this);
  102. GetDockingPaneManager()->SetTheme(xtpPaneThemeOffice2003);
  103. int nID = 1;
  104. CXTPDockingPane* pPropertyPane = GetDockingPaneManager()->CreatePane(nID, CRect(0, 0,200, 120), xtpPaneDockRight);
  105. pPropertyPane->SetTitle(_T("Properties"));
  106. GetDockingPaneManager()->SetIcons(IDB_PANEICONS, &nID, 1);
  107. XTPPaintManager()->RefreshMetrics();
  108. // Load the previous state for command bars.
  109. LoadCommandBars(_T("CommandBars"));
  110. return 0;
  111. }
  112. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  113. {
  114. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  115. return FALSE;
  116. cs.lpszClass = _T("XTPMainFrame");
  117. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  118. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  119. return TRUE;
  120. }
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CMainFrame diagnostics
  123. #ifdef _DEBUG
  124. void CMainFrame::AssertValid() const
  125. {
  126. CMDIFrameWnd::AssertValid();
  127. }
  128. void CMainFrame::Dump(CDumpContext& dc) const
  129. {
  130. CMDIFrameWnd::Dump(dc);
  131. }
  132. #endif //_DEBUG
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CMainFrame message handlers
  135. void CMainFrame::OnDestroy()
  136. {
  137. CMDIFrameWnd::OnDestroy();
  138. m_MTIClientWnd.Detach();
  139. }
  140. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  141. {
  142. if (wParam == XTP_DPN_SHOWWINDOW)
  143. {
  144. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  145. if (!pPane->IsValid())
  146. {
  147. ASSERT (pPane->GetID() == 1);
  148. if (!m_panePropertyGrid.m_hWnd)
  149. {
  150. m_panePropertyGrid.Create(_T("STATIC"), NULL, WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, 0);
  151. }
  152. pPane->Attach(&m_panePropertyGrid);
  153. }
  154. return TRUE;
  155. }
  156. return FALSE;
  157. }
  158. void CMainFrame::OnProperties()
  159. {
  160. GetDockingPaneManager()->ShowPane(1);
  161. }
  162. void CMainFrame::UpdatePropertyGridContent(CDrawView* /*pView*/)
  163. {
  164. CXTPPropertyGrid& wndPropertyGrid = GetPropertyGrid(this);
  165. if (!wndPropertyGrid.m_hWnd) return;
  166. if (m_bInUpdate)
  167. return;
  168. m_bInUpdate = TRUE;
  169. wndPropertyGrid.BeginUpdate(m_stateExpanding);
  170. CFrameWnd* pFrame = MDIGetActive();
  171. if (!pFrame)
  172. {
  173. m_pView = NULL;
  174. wndPropertyGrid.EndUpdate(m_stateExpanding);
  175. m_bInUpdate = FALSE;
  176. return;
  177. }
  178. CDrawView* pView = DYNAMIC_DOWNCAST(CDrawView, pFrame->GetActiveView());
  179. m_pView = pView;
  180. if (!pView)
  181. {
  182. wndPropertyGrid.EndUpdate(m_stateExpanding);
  183. m_bInUpdate = FALSE;
  184. return;
  185. }
  186. CDrawObjList* pObjects = &pView->m_selection;
  187. CXTPPropertyGridItem* pCategoryObjects = wndPropertyGrid.AddCategory(ID_CATEGORY_OBJECTS);
  188. CXTPPropertyGridItem* pItemObjectsCount = pCategoryObjects->AddChildItem(new CXTPPropertyGridItemNumber(_T("Objects Count"), (long)pView->GetDocument()->GetObjects()->GetCount()));
  189. pItemObjectsCount->SetReadOnly(TRUE);
  190. pCategoryObjects->Expand();
  191. CXTPPropertyGridItem* pCategorySelected = wndPropertyGrid.AddCategory(ID_CATEGORY_SELECTED);
  192. CXTPPropertyGridItem* pItemSelectedCount =  pCategorySelected->AddChildItem(new CXTPPropertyGridItemNumber(_T("Selected Count"), (long)pObjects->GetCount()));
  193. pItemSelectedCount->SetReadOnly(TRUE);
  194. if (pObjects->GetCount() > 0)
  195. {
  196. CDrawObj* pSelected = pObjects->GetHead();
  197. pCategorySelected->AddChildItem(new CXTPPropertyGridItemColor(ID_ITEM_LINECOLOR, pSelected->m_logpen.lopnColor));
  198. pCategorySelected->AddChildItem(new CXTPPropertyGridItemColor(ID_ITEM_FILLCOLOR, pSelected->m_logbrush.lbColor));
  199. if (pObjects->GetCount() == 1)
  200. {
  201. pCategorySelected->AddChildItem(new CXTPPropertyGridItemBool(ID_ITEM_SOLID, pSelected->m_bBrush));
  202. int nPenSize = pSelected->m_bPen ? pSelected->m_logpen.lopnWidth.x : 0;
  203. pCategorySelected->AddChildItem(new CXTPPropertyGridItemNumber(ID_ITEM_PENSIZE, nPenSize));
  204. }
  205. }
  206. pCategorySelected->Expand();
  207. if (pView->GetDocument()->m_pSummInfo)
  208. {
  209. CXTPPropertyGridItem* pCategorySummary = wndPropertyGrid.AddCategory(ID_CATEGORY_SUMMARY);
  210. pCategorySummary->AddChildItem(new CXTPPropertyGridItem(ID_ITEM_AUTHOR,
  211. pView->GetDocument()->m_pSummInfo->GetAuthor()));
  212. pCategorySummary->AddChildItem(new CXTPPropertyGridItem(ID_ITEM_TITLE,
  213. pView->GetDocument()->m_pSummInfo->GetTitle()));
  214. pCategorySummary->AddChildItem(new CXTPPropertyGridItem(ID_ITEM_SUBJECT,
  215. pView->GetDocument()->m_pSummInfo->GetSubject()));
  216. CXTPPropertyGridItem* pItemCreated =  pCategorySummary->AddChildItem(new CXTPPropertyGridItem(_T("Created"),
  217. pView->GetDocument()->m_pSummInfo->GetCreateDate()));
  218. pItemCreated->SetReadOnly(TRUE);
  219. pCategorySummary->Expand();
  220. }
  221. if (pObjects->GetCount() > 0)
  222. {
  223. wndPropertyGrid.GetVerbs()->Add(_T("Shape Properties"), 1);
  224. wndPropertyGrid.GetVerbs()->Add(_T("Paper Color"), 2);
  225. }
  226. wndPropertyGrid.EndUpdate(m_stateExpanding);
  227. m_bInUpdate = FALSE;
  228. }
  229. LRESULT CMainFrame::OnGridNotify(WPARAM wParam, LPARAM lParam)
  230. {
  231. if (wParam == XTP_PGN_VERB_CLICK)
  232. {
  233. CXTPPropertyGridVerb* pVerb = (CXTPPropertyGridVerb*)lParam;
  234. if (pVerb->GetID() == 1) OnCommand(ID_EDIT_PROPERTIES, 0);
  235. if (pVerb->GetID() == 2) OnCommand(ID_VIEW_PAPERCOLOR, 0);
  236. return TRUE;
  237. }
  238. if (wParam == XTP_PGN_ITEMVALUE_CHANGED && m_pView)
  239. {
  240. CXTPPropertyGridItem* pItem = (CXTPPropertyGridItem*)lParam;
  241. switch (pItem->GetID())
  242. {
  243. case ID_ITEM_AUTHOR: m_pView->GetDocument()->m_pSummInfo->SetAuthor(pItem->GetValue()); break;
  244. case ID_ITEM_SUBJECT: m_pView->GetDocument()->m_pSummInfo->SetSubject(pItem->GetValue()); break;
  245. case ID_ITEM_TITLE: m_pView->GetDocument()->m_pSummInfo->SetTitle(pItem->GetValue()); break;
  246. case ID_ITEM_PENSIZE:
  247. {
  248. CDrawObj* pSelected = m_pView->m_selection.GetHead();
  249. int nPenSize = min(100, ((CXTPPropertyGridItemNumber*)pItem)->GetNumber());
  250. if (nPenSize > 0)
  251. {
  252. pSelected->m_logpen.lopnWidth.x = nPenSize;
  253. pSelected->m_logpen.lopnWidth.y = nPenSize;
  254. }
  255. pSelected->Invalidate();
  256. pSelected->m_pDocument->SetModifiedFlag();
  257. }
  258. break;
  259. case ID_ITEM_SOLID:
  260. {
  261. CDrawObj* pSelected = m_pView->m_selection.GetHead();
  262. BOOL bSolid = min(100, ((CXTPPropertyGridItemBool*)pItem)->GetBool());
  263. pSelected->m_bBrush = bSolid;
  264. pSelected->Invalidate();
  265. pSelected->m_pDocument->SetModifiedFlag();
  266. }
  267. break;
  268. case ID_ITEM_LINECOLOR:
  269. {
  270. COLORREF color = ((CXTPPropertyGridItemColor*)pItem)->GetColor();
  271. POSITION pos = m_pView->m_selection.GetHeadPosition();
  272. while (pos != NULL)
  273. {
  274. CDrawObj* pObj = m_pView->m_selection.GetNext(pos);
  275. pObj->SetLineColor(color);
  276. }
  277. }
  278. break;
  279. case ID_ITEM_FILLCOLOR:
  280. {
  281. COLORREF color = ((CXTPPropertyGridItemColor*)pItem)->GetColor();
  282. POSITION pos = m_pView->m_selection.GetHeadPosition();
  283. while (pos != NULL)
  284. {
  285. CDrawObj* pObj = m_pView->m_selection.GetNext(pos);
  286. pObj->SetFillColor(color);
  287. }
  288. }
  289. break;
  290. default:
  291. TRACE(_T("Value Changed. Caption = %s, ID = %i, Value = %sn"), pItem->GetCaption(), pItem->GetID(), pItem->GetValue());
  292. }
  293. }
  294. return 0;
  295. }
  296. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
  297. {
  298. return CMDIFrameWnd::OnCreateClient(lpcs, pContext);
  299. }
  300. LRESULT CMainFrame::OnTabbarMouseMsg(WPARAM wParam,LPARAM lParam)
  301. {
  302. if (wParam != WM_RBUTTONDOWN)
  303. return FALSE;
  304. CPoint point = CPoint((DWORD)lParam);
  305. CXTPTabManagerItem* pItem =  m_MTIClientWnd.HitTest(point);
  306. if (pItem)
  307. {
  308. CWnd* pFrame = CWnd::FromHandle(pItem->GetHandle());
  309. MDIActivate(pFrame);
  310. m_MTIClientWnd.Refresh();
  311. CMenu menu;
  312. VERIFY(menu.LoadMenu(IDR_POPUP_TABS));
  313. CMenu* pPopup = menu.GetSubMenu(0);
  314. m_MTIClientWnd.WorkspaceToScreen(&point);
  315. CXTPCommandBars::TrackPopupMenu(pPopup, 0, point.x, point.y, this);
  316. m_MTIClientWnd.Refresh();
  317. return TRUE;
  318. }
  319. return FALSE;
  320. }
  321. void CMainFrame::OnClose()
  322. {
  323. SendMessageToDescendants(WM_CANCELMODE, 0, 0, TRUE, TRUE);
  324. // Save the current state for command bars.
  325. SaveCommandBars(_T("CommandBars"));
  326. // TODO: Add your message handler code here and/or call default
  327. CMDIFrameWnd::OnClose();
  328. }
  329. void CMainFrame::OnCustomize()
  330. {
  331. // get a pointer to the command bars object.
  332. CXTPCommandBars* pCommandBars = GetCommandBars();
  333. if (pCommandBars == NULL)
  334. return;
  335. // instanciate the customize dialog
  336. CXTPCustomizeSheet dlg(pCommandBars);
  337. // add the options page to the customize dialog.
  338. CXTPCustomizeOptionsPage pageOptions(&dlg);
  339. dlg.AddPage(&pageOptions);
  340. // add the commands page to the customize dialog.
  341. CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
  342. pPageCommands->AddCategories(IDR_DRAWCLTYPE);
  343. // initialize the commands page page.
  344. pPageCommands->InsertAllCommandsCategory();
  345. pPageCommands->InsertBuiltInMenus(IDR_DRAWCLTYPE);
  346. pPageCommands->InsertNewMenuCategory();
  347. // display the customize dialog.
  348. dlg.DoModal();
  349. }
  350. void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
  351. {
  352. // Toggle CommandBars
  353. GetCommandBars()->OnSetPreviewMode(bPreview);
  354. // Toggle Docking Panes.
  355. m_paneManager.OnSetPreviewMode(bPreview);
  356. // Toggle Tab Client
  357. m_MTIClientWnd.ShowWorkspace(!bPreview);
  358. CMDIFrameWnd::OnSetPreviewMode(bPreview, pState);
  359. }