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

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "SmartLayout.h"
  5. #include "MainFrm.h"
  6. #include "ControlSelector.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMainFrame
  14. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  15. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  16. //{{AFX_MSG_MAP(CMainFrame)
  17. ON_WM_CREATE()
  18. ON_WM_CLOSE()
  19. ON_COMMAND(ID_VIEW_THEME_OFFICE2003, OnViewThemeOffice2003)
  20. ON_COMMAND(ID_VIEW_THEME_OFFICE2000, OnViewThemeOffice2000)
  21. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICE2000, OnUpdateViewThemeOffice2000)
  22. ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICE2003, OnUpdateViewThemeOffice2003)
  23. //}}AFX_MSG_MAP
  24. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  25. ON_XTP_AFTERCREATECONTROL()
  26. ON_XTP_CREATECONTROL()
  27. END_MESSAGE_MAP()
  28. static UINT indicators[] =
  29. {
  30. ID_SEPARATOR,           // status line indicator
  31. ID_INDICATOR_CAPS,
  32. ID_INDICATOR_NUM,
  33. ID_INDICATOR_SCRL,
  34. };
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CMainFrame construction/destruction
  37. CMainFrame::CMainFrame()
  38. {
  39. // TODO: add member initialization code here
  40. }
  41. CMainFrame::~CMainFrame()
  42. {
  43. }
  44. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  45. {
  46. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  47. return -1;
  48. // Create Status bar.
  49. // Important: All control bars including the Status Bar
  50. // must be created before CommandBars....
  51. if (!m_wndStatusBar.Create(this) ||
  52. !m_wndStatusBar.SetIndicators(indicators,
  53. sizeof(indicators)/sizeof(UINT)))
  54. {
  55. TRACE0("Failed to create status barn");
  56. return -1;      // fail to create
  57. }
  58. // Initialize the command bars
  59. if (!InitCommandBars())
  60. return -1;
  61. // Get a pointer to the command bars object.
  62. CXTPCommandBars* pCommandBars = GetCommandBars();
  63. if(pCommandBars == NULL)
  64. {
  65. TRACE0("Failed to create command bars object.n");
  66. return -1;      // fail to create
  67. }
  68. // Add the menu bar
  69. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
  70. _T("Menu Bar"), IDR_MAINFRAME);
  71. if(pMenuBar == NULL)
  72. {
  73. TRACE0("Failed to create menu bar.n");
  74. return -1;      // fail to create
  75. }
  76. pMenuBar->SetFlags(xtpFlagAddMDISysPopup);
  77. // Create ToolBar
  78. CXTPToolBar* pToolBar = (CXTPToolBar*)
  79. pCommandBars->Add(_T("Standard"), xtpBarTop);
  80. if (!pToolBar || !pToolBar->LoadToolBar(IDR_STANDARDBAR))
  81. {
  82. TRACE0("Failed to create toolbarn");
  83. return -1;
  84. }
  85. pToolBar->EnableDocking(xtpFlagAlignAny | xtpFlagFloating | xtpFlagHideWrap | xtpFlagSmartLayout);
  86. // Create ToolBar
  87. CXTPToolBar* pFormatBar = (CXTPToolBar*)
  88. pCommandBars->Add(_T("Format"), xtpBarTop);
  89. if (!pFormatBar || !pFormatBar->LoadToolBar(IDR_FORMATBAR))
  90. {
  91. TRACE0("Failed to create toolbarn");
  92. return -1;
  93. }
  94. pFormatBar->EnableDocking(xtpFlagAlignAny | xtpFlagFloating | xtpFlagHideWrap | xtpFlagSmartLayout);
  95. pFormatBar->GetControls()->FindControl(ID_BDR_NONE)->SetHideFlags(xtpHideCustomize);
  96. pFormatBar->GetControls()->CreateOriginalControls();
  97. pCommandBars->GetImageManager()->SetIcons(IDB_LARGEICONS);
  98. UINT nCommands[] = {ID_EDIT_UNDO, ID_EDIT_REDO, ID_VIEW_MAP, ID_EDIT_COPY, ID_EDIT_CUT};
  99. pCommandBars->GetImageManager()->SetIcons(IDB_EDITUNDO, nCommands, _countof(nCommands), xtpImageNormal);
  100. UINT nCommands2[] = {ID_CHAR_BOLD, ID_CHAR_ITALIC, ID_CHAR_UNDERLINE, ID_BUTTON_TEXT, ID_PARA_LEFT, ID_PARA_CENTER, ID_PARA_RIGHT, ID_INSERT_BULLET, ID_FORMAT_FONT};
  101. pCommandBars->GetImageManager()->SetIcons(IDB_FORMATBARLARGE, nCommands2, _countof(nCommands2), xtpImageNormal);
  102. GetCommandBars()->GetImageManager()->RemoveIcon(ID_COMBO_FONT);
  103. GetCommandBars()->GetImageManager()->RemoveIcon(ID_COMBO_SIZE);
  104. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, AFX_IDW_PANE_FIRST);
  105. CXTPWindowRect rcBar(pToolBar);
  106. rcBar.OffsetRect(470, 0);
  107. GetCommandBars()->DockCommandBar(pFormatBar, rcBar, pToolBar->GetDockBar());
  108. // Set Office 2003 Theme
  109. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  110. pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME);
  111. pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  112. // Load the previous state for toolbars and menus.
  113. LoadCommandBars(_T("CommandBars"));
  114. return 0;
  115. }
  116. void CMainFrame::OnClose()
  117. {
  118. // Save the current state for toolbars and menus.
  119. SaveCommandBars(_T("CommandBars"));
  120. RecalcLayout();
  121. CMDIFrameWnd::OnClose();
  122. }
  123. void CMainFrame::OnCustomize()
  124. {
  125. // Get a pointer to the command bars object.
  126. CXTPCommandBars* pCommandBars = GetCommandBars();
  127. if(pCommandBars != NULL)
  128. {
  129. // Instanciate the customize dialog object.
  130. CXTPCustomizeSheet dlg(pCommandBars);
  131. // Add the keyboard page to the customize dialog.
  132. CXTPCustomizeKeyboardPage pageKeyboard(&dlg);
  133. dlg.AddPage(&pageKeyboard);
  134. pageKeyboard.AddCategories(IDR_SMARTLTYPE);
  135. // Add the options page to the customize dialog.
  136. CXTPCustomizeOptionsPage pageOptions(&dlg);
  137. dlg.AddPage(&pageOptions);
  138. // Add the commands page to the customize dialog.
  139. CXTPCustomizeCommandsPage* pCommands = dlg.GetCommandsPage();
  140. pCommands->AddCategories(IDR_SMARTLTYPE);
  141. // Use the command bar manager to initialize the
  142. // customize dialog.
  143. pCommands->InsertAllCommandsCategory();
  144. pCommands->InsertBuiltInMenus(IDR_SMARTLTYPE);
  145. pCommands->InsertNewMenuCategory();
  146. // Dispaly the dialog.
  147. dlg.DoModal();
  148. }
  149. }
  150. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  151. {
  152. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  153. return FALSE;
  154. cs.lpszClass = _T("XTPMainFrame");
  155. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  156. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  157. return TRUE;
  158. }
  159. /////////////////////////////////////////////////////////////////////////////
  160. // CMainFrame diagnostics
  161. #ifdef _DEBUG
  162. void CMainFrame::AssertValid() const
  163. {
  164. CMDIFrameWnd::AssertValid();
  165. }
  166. void CMainFrame::Dump(CDumpContext& dc) const
  167. {
  168. CMDIFrameWnd::Dump(dc);
  169. }
  170. #endif //_DEBUG
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CMainFrame message handlers
  173. void CMainFrame::OnAfterCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  174. {
  175. lpCreateControl;
  176. }
  177. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  178. {
  179. CXTPToolBar* pToolBar = lpCreateControl->bToolBar? DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar): NULL;
  180. if (lpCreateControl->nID == ID_COMBO_FONT && pToolBar && pToolBar->GetBarID() == IDR_FORMATBAR)
  181. {
  182. CXTPControlComboBox* pComboFont = new CXTPControlFontComboBox();
  183. pComboFont->SetDropDownListStyle();
  184. lpCreateControl->pControl = pComboFont;
  185. return TRUE;
  186. }
  187. if (lpCreateControl->nID == ID_BDR_NONE && pToolBar)
  188. {
  189. CXTPControlPopup* pPopup = CXTPControlPopup::CreateControlPopup(xtpControlSplitButtonPopup);
  190. CXTPPopupToolBar* pPopupBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  191. pPopupBar->LoadToolBar(IDR_BORDERS);
  192. pPopupBar->SetWidth(52 * 5 + 6);
  193. pPopupBar->SetTearOffPopup(_T("Borders"), IDR_BORDERS, 52 * 5 + 6);
  194. pPopup->SetCommandBar(pPopupBar);
  195. pPopupBar->InternalRelease();
  196. lpCreateControl->pControl = pPopup;
  197. return TRUE;
  198. }
  199. if (lpCreateControl->nID == ID_COMBO_SIZE && pToolBar && pToolBar->GetBarID() == IDR_FORMATBAR)
  200. {
  201. CXTPControlComboBox* pComboSize = new CXTPControlSizeComboBox();
  202. pComboSize->SetDropDownListStyle();
  203. pComboSize->SetWidth(80);
  204. lpCreateControl->pControl = pComboSize;
  205. return TRUE;
  206. }
  207. if (lpCreateControl->nID == ID_BUTTON_TEXT && pToolBar && pToolBar->GetBarID() == IDR_FORMATBAR)
  208. {
  209. CXTPControlPopupColor* pPopupColor = new CXTPControlPopupColor();
  210. CXTPPopupBar* pColorBar = (CXTPPopupBar*)CXTPPopupToolBar::CreateObject();
  211. CXTPControlButtonColor* pButtonAutomatic = (CXTPControlButtonColor*)pColorBar->GetControls()->Add(new CXTPControlButtonColor(), XTP_IDS_AUTOMATIC);
  212. pButtonAutomatic->SetColor(GetSysColor(COLOR_BTNTEXT));
  213. pColorBar->GetControls()->Add(new CXTPControlColorSelector(), ID_SELECTOR_TEXT);
  214. pColorBar->GetControls()->Add(new CXTPControlButtonColor(), XTP_IDS_MORE_COLORS);
  215. pPopupColor->SetCommandBar(pColorBar);
  216. pColorBar->SetTearOffPopup(_T("Text Color"), IDR_COLORTEXT_POPUP, 0);
  217. pColorBar->EnableCustomization(FALSE);
  218. pColorBar->InternalRelease();
  219. lpCreateControl->pControl = pPopupColor;
  220. return TRUE;
  221. }
  222. if (lpCreateControl->nID == ID_EDIT_UNDO && pToolBar)
  223. {
  224. CXTPControlPopup* pButtonUndo = CXTPControlPopup::CreateControlPopup(xtpControlSplitButtonPopup);
  225. CXTPPopupToolBar* pUndoBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  226. pUndoBar->EnableCustomization(FALSE);
  227. pUndoBar->SetBorders(CRect(2, 2, 2, 2));
  228. pUndoBar->DisableShadow();
  229. CXTPControlListBox* pControlListBox = (CXTPControlListBox*)pUndoBar->GetControls()->Add(new CXTPControlListBox(), ID_EDIT_UNDO);
  230. pControlListBox->SetWidth(140);
  231. pControlListBox->SetLinesMinMax(1, 6);
  232. pControlListBox->SetMultiplSel(TRUE);
  233. CXTPControlStatic* pControlListBoxInfo = (CXTPControlStatic*)pUndoBar->GetControls()->Add(new CXTPControlStatic(), ID_EDIT_UNDO);
  234. pControlListBoxInfo->SetWidth(140);
  235. pButtonUndo->SetCommandBar(pUndoBar);
  236. pUndoBar->InternalRelease();
  237. lpCreateControl->pControl = pButtonUndo;
  238. return TRUE;
  239. }
  240. if (lpCreateControl->nID == ID_INSERT_COLUMNS)
  241. {
  242. CXTPControlPopup* pButtonColumns = CXTPControlPopup::CreateControlPopup(xtpControlPopup);
  243. CXTPPopupToolBar* pColumnsBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  244. pColumnsBar->EnableCustomization(FALSE);
  245. pColumnsBar->SetBorders(CRect(2, 2, 2, 2));
  246. pColumnsBar->DisableShadow();
  247. pColumnsBar->GetControls()->Add(new CControlColumns(), ID_INSERT_COLUMNS);
  248. CXTPControlStatic* pControlColumnsInfo = (CXTPControlStatic*)pColumnsBar->GetControls()->Add(new CXTPControlStatic(), ID_INSERT_COLUMNS);
  249. pControlColumnsInfo->SetFlags(xtpFlagManualUpdate);
  250. pButtonColumns->SetCommandBar(pColumnsBar);
  251. pColumnsBar->InternalRelease();
  252. lpCreateControl->pControl = pButtonColumns;
  253. return TRUE;
  254. }
  255. if (lpCreateControl->nID == ID_INSERT_TABLE)
  256. {
  257. CXTPControlPopup* pButtonTable = CXTPControlPopup::CreateControlPopup(xtpControlPopup);
  258. CXTPPopupToolBar* pTableBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  259. pTableBar->EnableCustomization(FALSE);
  260. pTableBar->SetBorders(CRect(2, 2, 2, 2));
  261. pTableBar->DisableShadow();
  262. pTableBar->GetControls()->Add(new CControlTable(), ID_INSERT_TABLE);
  263. CXTPControlStatic* pControlTableInfo = (CXTPControlStatic*)pTableBar->GetControls()->Add(new CXTPControlStatic(), ID_INSERT_TABLE);
  264. pControlTableInfo->SetFlags(xtpFlagManualUpdate);
  265. pButtonTable->SetCommandBar(pTableBar);
  266. pTableBar->InternalRelease();
  267. lpCreateControl->pControl = pButtonTable;
  268. return TRUE;
  269. }
  270. return FALSE;
  271. }
  272. void CMainFrame::OnViewThemeOffice2003() 
  273. {
  274. XTPPaintManager()->SetTheme(xtpThemeOffice2003);
  275. GetCommandBars()->RedrawCommandBars();
  276. }
  277. void CMainFrame::OnViewThemeOffice2000() 
  278. {
  279. XTPPaintManager()->SetTheme(xtpThemeOffice2000);
  280. GetCommandBars()->RedrawCommandBars();
  281. }
  282. void CMainFrame::OnUpdateViewThemeOffice2000(CCmdUI* pCmdUI) 
  283. {
  284. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2000);
  285. }
  286. void CMainFrame::OnUpdateViewThemeOffice2003(CCmdUI* pCmdUI) 
  287. {
  288. pCmdUI->SetCheck(XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2003);
  289. }