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

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "GallerySample.h"
  5. #include "MainFrm.h"
  6. #include "GalleryItems.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_DYNCREATE(CMainFrame, CFrameWnd)
  15. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  16. //{{AFX_MSG_MAP(CMainFrame)
  17. ON_WM_CREATE()
  18. ON_WM_CLOSE()
  19. ON_COMMAND(ID_STYLES_CHANGE, OnStylesChange)
  20. ON_COMMAND(ID_VIEW_ANIMATE, OnViewAnimate)
  21. ON_UPDATE_COMMAND_UI(ID_VIEW_ANIMATE, OnUpdateViewAnimate)
  22. //}}AFX_MSG_MAP
  23. ON_XTP_CREATECONTROL()
  24. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  25. ON_XTP_EXECUTE(ID_GALLERY_SHAPES, OnGalleryShapes)
  26. ON_UPDATE_COMMAND_UI(ID_GALLERY_SHAPES, OnUpdateGalleryShapes)
  27. ON_XTP_EXECUTE(ID_GALLERY_STYLES, OnGalleryStyles)
  28. ON_UPDATE_COMMAND_UI(ID_GALLERY_STYLES, OnUpdateGalleryStyles)
  29. ON_XTP_EXECUTE(ID_GALLERY_STYLESET, OnGalleryStyleSet)
  30. ON_UPDATE_COMMAND_UI(ID_GALLERY_STYLESET, OnUpdateGalleryStyleSet)
  31. ON_XTP_EXECUTE(ID_GALLERY_COLORS, OnGalleryThemeColors)
  32. ON_UPDATE_COMMAND_UI(ID_GALLERY_COLORS, OnUpdateGalleryThemeColors)
  33. ON_XTP_EXECUTE(ID_GALLERY_TABLE, OnGalleryTable)
  34. ON_UPDATE_COMMAND_UI(ID_GALLERY_TABLE, OnUpdateGalleryTable)
  35. ON_XTP_EXECUTE(ID_GALLERY_FONTS, OnGalleryThemeFonts)
  36. ON_UPDATE_COMMAND_UI(ID_GALLERY_FONTS, OnUpdateGalleryThemeFonts)
  37. ON_COMMAND_RANGE(ID_VIEW_THEME_OFFICE2000, ID_VIEW_THEME_RIBBON, OnViewTheme)
  38. ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_THEME_OFFICE2000, ID_VIEW_THEME_RIBBON, OnUpdateViewTheme)
  39. ON_NOTIFY(XTP_GN_PREVIEWSTART, ID_GALLERY_STYLES, OnStylesPreviewStart)
  40. ON_NOTIFY(XTP_GN_PREVIEWCANCEL, ID_GALLERY_STYLES, OnStylesPreviewCancel)
  41. ON_NOTIFY(XTP_GN_PREVIEWAPPLY, ID_GALLERY_STYLES, OnStylesPreviewApply)
  42. ON_NOTIFY(XTP_GN_PREVIEWCHANGE, ID_GALLERY_STYLES, OnStylesPreviewChange)
  43. END_MESSAGE_MAP()
  44. static UINT indicators[] =
  45. {
  46. ID_SEPARATOR,           // status line indicator
  47. ID_INDICATOR_CAPS,
  48. ID_INDICATOR_NUM,
  49. ID_INDICATOR_SCRL,
  50. };
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CMainFrame construction/destruction
  53. CMainFrame::CMainFrame()
  54. {
  55. m_pItemsShapes = 0;
  56. m_pItemsStyles = 0;
  57. m_pItemsStyleSet = 0;
  58. m_pItemsThemeColors = 0;
  59. m_pItemsThemeFonts = 0;
  60. m_pItemsTable = 0;
  61. m_pItemsFontTextColor = 0;
  62. m_pItemsFontBackColor = 0;
  63. m_pItemsFontFace = 0;
  64. m_pItemsFontSize = 0;
  65. TCHAR szStylesPath[_MAX_PATH];
  66. VERIFY(::GetModuleFileName(
  67. AfxGetApp()->m_hInstance, szStylesPath, _MAX_PATH));
  68. CString csStylesPath(szStylesPath);
  69. int nIndex  = csStylesPath.ReverseFind(_T('\'));
  70. if (nIndex > 0) {
  71. csStylesPath = csStylesPath.Left(nIndex);
  72. }
  73. else {
  74. csStylesPath.Empty();
  75. }
  76. XTPOffice2007Images()->SetHandle(csStylesPath + _T("\Styles\Office2007Blue.dll"));
  77. }
  78. CMainFrame::~CMainFrame()
  79. {
  80. }
  81. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  82. {
  83. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  84. return -1;
  85. if (!m_wndStatusBar.Create(this) ||
  86. !m_wndStatusBar.SetIndicators(indicators,
  87. sizeof(indicators)/sizeof(UINT)))
  88. {
  89. TRACE0("Failed to create status barn");
  90. return -1;      // fail to create
  91. }
  92. if (!InitCommandBars())
  93. return -1;
  94. m_wndStatusBar.SetCommandBars(GetCommandBars());
  95. CreateGalleries();
  96. CXTPCommandBars* pCommandBars = GetCommandBars();
  97. pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  98. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  99. if (!pStandardBar ||
  100. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  101. {
  102. TRACE0("Failed to create toolbarn");
  103. return -1;
  104. }
  105. CXTPToolBar* pFormatBar = (CXTPToolBar*)pCommandBars->Add(_T("Format"), xtpBarTop);
  106. if (!pFormatBar ||
  107. !pFormatBar->LoadToolBar(IDR_TOOLBAR_FORMAT))
  108. {
  109. TRACE0("Failed to create toolbarn");
  110. return -1;
  111. }
  112. DockRightOf(pFormatBar, pStandardBar);
  113. CXTPToolBar* pStylesBar = (CXTPToolBar*)pCommandBars->Add(_T("Styles"), xtpBarTop);
  114. if (!pStylesBar || 
  115. !pStylesBar->LoadToolBar(IDR_TOOLBAR_STYLES))
  116. {
  117. TRACE0("Failed to create toolbarn");
  118. return -1;
  119. }
  120. pStylesBar->SetIconSize(CSize(16, 16));
  121. DockRightOf(pStylesBar, pFormatBar);
  122. CXTPToolBar* pShapesBar = (CXTPToolBar*)pCommandBars->Add(_T("Shapes"), xtpBarLeft);
  123. if (!pShapesBar)
  124. {
  125. TRACE0("Failed to create toolbarn");
  126. return -1;
  127. }
  128. pShapesBar->SetBarID(100);
  129. CXTPControlGallery* pControlGalleryShapes4 = new CXTPControlGallery();
  130. pControlGalleryShapes4->SetControlSize(CSize(120, 200));
  131. pControlGalleryShapes4->SetResizable();
  132. pControlGalleryShapes4->ShowBorders(TRUE);
  133. pControlGalleryShapes4->SetItems(m_pItemsShapes);
  134. pShapesBar->GetControls()->Add(pControlGalleryShapes4, ID_GALLERY_SHAPES);
  135. pShapesBar->GetControls()->CreateOriginalControls();
  136. pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME, IDR_MAINFRAME_LARGE);
  137. pCommandBars->SetTheme(xtpThemeRibbon);
  138. EnableOffice2007Frame(GetCommandBars());
  139. pCommandBars->GetPaintManager()->m_bEnableAnimation = TRUE;
  140. LoadCommandBars(_T("CommandBars2"));
  141. return 0;
  142. }
  143. void CMainFrame::CreateGalleries()
  144. {
  145. m_pItemsShapes = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_SHAPES);
  146. m_pItemsShapes->GetImageManager()->SetIcons(ID_GALLERY_SHAPES, 0, 0, CSize(20, 20));
  147. CXTPControlGalleryItem* pItem = m_pItemsShapes->AddLabel(0);
  148. pItem->SetCaption(_T("Lines"));
  149. int nShape;
  150. for (nShape = 0; nShape < 12; nShape++)
  151. m_pItemsShapes->AddItem(nShape, nShape);
  152. pItem = m_pItemsShapes->AddLabel(0);
  153. pItem->SetCaption(_T("Basic Shapes"));
  154. for (; nShape < 12 + 32; nShape++)
  155. m_pItemsShapes->AddItem(nShape, nShape);
  156. pItem = m_pItemsShapes->AddLabel(0);
  157. pItem->SetCaption(_T("Block Arrows"));
  158. for (; nShape < 12 + 32 + 27; nShape++)
  159. m_pItemsShapes->AddItem(nShape, nShape);
  160. pItem = m_pItemsShapes->AddLabel(0);
  161. pItem->SetCaption(_T("Flowchart"));
  162. for (; nShape < 12 + 32 + 27 + 28; nShape++)
  163. m_pItemsShapes->AddItem(nShape, nShape);
  164. pItem = m_pItemsShapes->AddLabel(0);
  165. pItem->SetCaption(_T("Callouts"));
  166. for (; nShape < 12 + 32 + 27 + 28 + 20; nShape++)
  167. m_pItemsShapes->AddItem(nShape, nShape);
  168. pItem = m_pItemsShapes->AddLabel(0);
  169. pItem->SetCaption(_T("Stars and Banners"));
  170. for (; nShape < 12 + 32 + 27 + 28 + 20 + 16; nShape++)
  171. m_pItemsShapes->AddItem(nShape, nShape);
  172. m_nShape = -1;
  173. m_nStyle = 0;
  174. m_pItemsStyles = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_STYLES);
  175. m_pItemsStyles->GetImageManager()->SetMaskColor(0xFF00FF);
  176. m_pItemsStyles->GetImageManager()->SetIcons(ID_GALLERY_STYLES, 0, 0, CSize(64, 48));
  177. m_pItemsStyles->GetImageManager()->SetMaskColor(COLORREF_NULL); // Default TopLeft Pixel.
  178. m_pItemsStyles->SetItemSize(CSize(72, 56));
  179. for (int nStyle = 0; nStyle < 16; nStyle++)
  180. m_pItemsStyles->AddItem(nStyle, nStyle);
  181. m_nStyleSet = 0;
  182. m_pItemsStyleSet = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_STYLESET);
  183. m_pItemsStyleSet->SetItemSize(CSize(0, 22));
  184. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(0, _T("Classic")));
  185. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(1, _T("Default")));
  186. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(2, _T("Distinctive")));
  187. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(3, _T("Elegant")));
  188. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(4, _T("Fancy")));
  189. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(5, _T("Formal")));
  190. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(6, _T("Manuscript")));
  191. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(7, _T("Modern")));
  192. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(8, _T("Simple")));
  193. m_pItemsStyleSet->AddItem(new CGalleryItemStyleSet(9, _T("Traditional")));
  194. m_nThemeColors = 0;
  195. m_pItemsThemeColors = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_COLORS);
  196. m_pItemsThemeColors->SetItemSize(CSize(0, 20));
  197. pItem = m_pItemsThemeColors->AddLabel(0);
  198. pItem->SetCaption(_T("Built-In"));
  199. m_pItemsThemeColors->AddItem(new CGalleryItemThemeColors(0, _T("Office")));
  200. m_pItemsThemeColors->AddItem(new CGalleryItemThemeColors(1, _T("Grayscale")));
  201. m_pItemsThemeColors->AddItem(new CGalleryItemThemeColors(2, _T("Apex")));
  202. m_pItemsThemeColors->AddItem(new CGalleryItemThemeColors(3, _T("Aspect")));
  203. m_pItemsThemeColors->AddItem(new CGalleryItemThemeColors(4, _T("Civic")));
  204. m_pItemsThemeColors->AddItem(new CGalleryItemThemeColors(5, _T("Concourse")));
  205. m_pItemsThemeColors->AddItem(new CGalleryItemThemeColors(6, _T("Currency")));
  206. m_pItemsThemeColors->AddItem(new CGalleryItemThemeColors(7, _T("Deluxe")));
  207. m_nThemeFonts = 0;
  208. m_pItemsThemeFonts = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_FONTS);
  209. m_pItemsThemeFonts->SetItemSize(CSize(0, 60));
  210. pItem = m_pItemsThemeFonts->AddLabel(0);
  211. pItem->SetCaption(_T("Built-In"));
  212. m_pItemsThemeFonts->AddItem(new CGalleryItemThemeFonts(0, _T("Office")));
  213. m_pItemsThemeFonts->AddItem(new CGalleryItemThemeFonts(1, _T("Apex")));
  214. m_pItemsThemeFonts->AddItem(new CGalleryItemThemeFonts(2, _T("Aspect")));
  215. m_pItemsThemeFonts->AddItem(new CGalleryItemThemeFonts(3, _T("Civic")));
  216. m_pItemsThemeFonts->AddItem(new CGalleryItemThemeFonts(4, _T("Concourse")));
  217. m_pItemsThemeFonts->AddItem(new CGalleryItemThemeFonts(5, _T("Currency")));
  218. m_pItemsThemeFonts->AddItem(new CGalleryItemThemeFonts(6, _T("Deluxe")));
  219. m_pItemsThemeFonts->AddItem(new CGalleryItemThemeFonts(7, _T("Equity")));
  220. m_pItemsTable = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_TABLE);
  221. m_pItemsTable->ClipItems(FALSE); //Redraw all Items if selection changed
  222. m_pItemsTable->SetItemSize(CSize(19, 19));
  223. pItem = m_pItemsTable->AddItem(new CGalleryItemTableLabel());
  224. int nItem;
  225. for (nItem = 0; nItem < 10 * 8; nItem++)
  226. m_pItemsTable->AddItem(new CGalleryItemTable(nItem));
  227. m_pItemsFontTextColor = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_FONTTEXTCOLOR);
  228. m_pItemsFontTextColor->SetItemSize(CSize(17, 17));
  229. pItem = m_pItemsFontTextColor->AddLabel(0);
  230. pItem->SetCaption(_T("Theme Colors"));
  231. CGalleryItemFontColor::AddThemeColors(m_pItemsFontTextColor, 0);
  232. pItem = m_pItemsFontTextColor->AddLabel(0);
  233. pItem->SetCaption(_T("Standard Colors"));
  234. CGalleryItemFontColor::AddStandardColors(m_pItemsFontTextColor);
  235. m_pItemsFontBackColor = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_FONTBACKCOLOR);
  236. m_pItemsFontBackColor->SetItemSize(CSize(30, 30));
  237. CGalleryItemFontColor::AddStandardBackColors(m_pItemsFontBackColor);
  238. m_pItemsFontFace = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_FONTFACE);
  239. m_pItemsFontFace->SetItemSize(CSize(0, 26));
  240. CGalleryItemFontFace::AddFontItems(m_pItemsFontFace);
  241. m_pItemsFontSize = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_FONTSIZE);
  242. m_pItemsFontSize->SetItemSize(CSize(0, 17));
  243. m_pItemsFontSize->AddItem(_T("8"));
  244. m_pItemsFontSize->AddItem(_T("9"));
  245. m_pItemsFontSize->AddItem(_T("10"));
  246. m_pItemsFontSize->AddItem(_T("11"));
  247. m_pItemsFontSize->AddItem(_T("12"));
  248. m_pItemsFontSize->AddItem(_T("14"));
  249. m_pItemsFontSize->AddItem(_T("16"));
  250. m_pItemsFontSize->AddItem(_T("18"));
  251. m_pItemsFontSize->AddItem(_T("20"));
  252. m_pItemsFontSize->AddItem(_T("22"));
  253. m_pItemsFontSize->AddItem(_T("24"));
  254. m_pItemsFontSize->AddItem(_T("26"));
  255. m_pItemsFontSize->AddItem(_T("28"));
  256. m_pItemsFontSize->AddItem(_T("36"));
  257. m_pItemsFontSize->AddItem(_T("48"));
  258. m_pItemsFontSize->AddItem(_T("72"));
  259. m_pItemsUndo = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_EDIT_UNDO);
  260. m_pItemsUndo->SetItemSize(CSize(0, 21));
  261. m_pItemsUndo->ClipItems(FALSE);
  262. }
  263. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  264. {
  265. if( !CFrameWnd::PreCreateWindow(cs) )
  266. return FALSE;
  267. cs.lpszClass = _T("XTPMainFrame");
  268. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  269. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  270. return TRUE;
  271. }
  272. /////////////////////////////////////////////////////////////////////////////
  273. // CMainFrame diagnostics
  274. #ifdef _DEBUG
  275. void CMainFrame::AssertValid() const
  276. {
  277. CFrameWnd::AssertValid();
  278. }
  279. void CMainFrame::Dump(CDumpContext& dc) const
  280. {
  281. CFrameWnd::Dump(dc);
  282. }
  283. #endif //_DEBUG
  284. /////////////////////////////////////////////////////////////////////////////
  285. // CMainFrame message handlers
  286. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  287. {
  288. if (lpCreateControl->nID == ID_STYLES_CHANGE)
  289. {
  290. lpCreateControl->controlType =  xtpControlButtonPopup;
  291. lpCreateControl->buttonStyle = xtpButtonIconAndCaptionBelow;
  292. return TRUE;
  293. }
  294. if (lpCreateControl->bToolBar && lpCreateControl->pCommandBar->GetBarID() == IDR_MAINFRAME)
  295. {
  296. lpCreateControl->buttonStyle = xtpButtonIconAndCaptionBelow;
  297. return TRUE;
  298. }
  299. if (lpCreateControl->nID == ID_GALLERY_STYLESET)
  300. {
  301. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  302. pControlGallery->SetControlSize(CSize(200, 22 * 7 + 2));
  303. pControlGallery->SetResizable();
  304. pControlGallery->ShowLabels(TRUE);
  305. pControlGallery->SetItems(m_pItemsStyleSet);
  306. lpCreateControl->pControl = pControlGallery;
  307. return TRUE;
  308. }
  309. if (lpCreateControl->nID == ID_GALLERY_COLORS)
  310. {
  311. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  312. pControlGallery->SetControlSize(CSize(200, 20 * 9 + 2));
  313. pControlGallery->SetResizable();
  314. pControlGallery->ShowLabels(TRUE);
  315. pControlGallery->SetItems(m_pItemsThemeColors);
  316. lpCreateControl->pControl = pControlGallery;
  317. return TRUE;
  318. }
  319. if (lpCreateControl->nID == ID_GALLERY_TABLE)
  320. {
  321. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  322. pControlGallery->SetControlSize(CSize(190, 175));
  323. pControlGallery->ShowLabels(TRUE);
  324. pControlGallery->ShowScrollBar(FALSE);
  325. pControlGallery->SetItems(m_pItemsTable);
  326. lpCreateControl->pControl = pControlGallery;
  327. return TRUE;
  328. }
  329. if (lpCreateControl->nID == ID_EDIT_FONT)
  330. {
  331. CXTPControlComboBox* pComboFont = new CXTPControlComboBox();
  332. pComboFont->SetDropDownListStyle();
  333. pComboFont->EnableAutoComplete();
  334. pComboFont->SetWidth(145);
  335. CXTPPopupBar* pPopupBar = CXTPControlComboBoxGalleryPopupBar::CreateComboBoxGalleryPopupBar(GetCommandBars());
  336. pComboFont->SetCommandBar(pPopupBar);
  337. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  338. pControlGallery->SetControlSize(CSize(290, 508));
  339. pControlGallery->SetResizable(FALSE, TRUE);
  340. pControlGallery->ShowLabels(TRUE);
  341. pControlGallery->SetItems(m_pItemsFontFace);
  342. pPopupBar->GetControls()->Add(pControlGallery, ID_GALLERY_FONTFACE);
  343. pPopupBar->InternalRelease();
  344. lpCreateControl->pControl = pComboFont;
  345. return TRUE;
  346. }
  347. if (lpCreateControl->nID == ID_EDIT_SIZE)
  348. {
  349. CXTPControlComboBox* pComboFont = new CXTPControlComboBox();
  350. pComboFont->SetDropDownListStyle();
  351. pComboFont->SetWidth(45);
  352. CXTPPopupBar* pPopupBar = CXTPControlComboBoxGalleryPopupBar::CreateComboBoxGalleryPopupBar(GetCommandBars());
  353. pComboFont->SetCommandBar(pPopupBar);
  354. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  355. pControlGallery->SetControlSize(CSize(42, 16 * 17));
  356. pControlGallery->SetResizable(FALSE, TRUE);
  357. pControlGallery->SetItems(m_pItemsFontSize);
  358. pPopupBar->GetControls()->Add(pControlGallery, ID_GALLERY_FONTSIZE);
  359. pPopupBar->InternalRelease();
  360. lpCreateControl->pControl = pComboFont;
  361. return TRUE;
  362. }
  363. if (lpCreateControl->nID == ID_EDIT_UNDO)
  364. {
  365. CXTPControlPopup* pControlUndo = CXTPControlPopup::CreateControlPopup(xtpControlSplitButtonPopup);
  366. pControlUndo->SetID(ID_EDIT_UNDO);
  367. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  368. pPopupBar->SetShowGripper(FALSE);
  369. pControlUndo->SetCommandBar(pPopupBar);
  370. CXTPControlGallery* pControlGallery = new CControlGalleryUndo();
  371. pControlGallery->SetItems(m_pItemsUndo);
  372. pControlGallery->SetWidth(120);
  373. pPopupBar->GetControls()->Add(pControlGallery, ID_EDIT_UNDO);
  374. CXTPControlStatic* pControlListBoxInfo = (CXTPControlStatic*)pPopupBar->GetControls()->Add(new CXTPControlStatic(), ID_EDIT_UNDO);
  375. pControlListBoxInfo->SetWidth(120);
  376. pControlListBoxInfo->SetFlags(xtpFlagSkipFocus);
  377. pPopupBar->InternalRelease();
  378. lpCreateControl->pControl = pControlUndo;
  379. return TRUE;
  380. }
  381. if (lpCreateControl->nID == ID_FORMAT_BOLD)
  382. {
  383. CXTPControlButton* pControl = new CXTPControlButton();
  384. pControl ->SetFlags(xtpFlagWrapRow);
  385. lpCreateControl->pControl = pControl;
  386. return TRUE;
  387. }
  388. if (lpCreateControl->nID == ID_VIEW_ANIMATE)
  389. {
  390. CXTPControlButton* pControl = new CXTPControlCheckBox();
  391. pControl ->SetFlags(xtpFlagRightAlign);
  392. lpCreateControl->pControl = pControl;
  393. return TRUE;
  394. }
  395. if (lpCreateControl->nID == ID_FORMAT_BACKCOLOR)
  396. {
  397. CXTPControlPopupColor* pPopupColor = new CXTPControlPopupColor();
  398. CXTPPopupBar* pColorBar = (CXTPPopupBar*)CXTPPopupBar::CreatePopupBar(GetCommandBars());
  399. CMenu menu;
  400. menu.LoadMenu(ID_GALLERY_FONTBACKCOLOR);
  401. pColorBar->LoadMenu(menu.GetSubMenu(0));
  402. pPopupColor->SetCommandBar(pColorBar);
  403. pColorBar->EnableCustomization(FALSE);
  404. pColorBar->InternalRelease();
  405. pPopupColor->SetFlags(xtpFlagWrapRow);
  406. lpCreateControl->pControl = pPopupColor;
  407. return TRUE;
  408. }
  409. if (lpCreateControl->nID == ID_FORMAT_FONTCOLOR)
  410. {
  411. CXTPControlPopupColor* pPopupColor = new CXTPControlPopupColor();
  412. CXTPPopupBar* pColorBar = (CXTPPopupBar*)CXTPPopupBar::CreatePopupBar(GetCommandBars());
  413. CMenu menu;
  414. menu.LoadMenu(ID_GALLERY_FONTTEXTCOLOR);
  415. pColorBar->LoadMenu(menu.GetSubMenu(0));
  416. pPopupColor->SetCommandBar(pColorBar);
  417. pColorBar->EnableCustomization(FALSE);
  418. pColorBar->InternalRelease();
  419. lpCreateControl->pControl = pPopupColor;
  420. return TRUE;
  421. }
  422. if (lpCreateControl->nID == ID_GALLERY_FONTTEXTCOLOR)
  423. {
  424. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  425. pControlGallery->SetControlSize(CSize(171, 145));
  426. pControlGallery->ShowLabels(TRUE);
  427. pControlGallery->ShowScrollBar(FALSE);
  428. pControlGallery->SetItems(m_pItemsFontTextColor);
  429. lpCreateControl->pControl = pControlGallery;
  430. return TRUE;
  431. }
  432. if (lpCreateControl->nID == ID_GALLERY_FONTBACKCOLOR)
  433. {
  434. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  435. pControlGallery->SetControlSize(CSize(30 * 5, 30 * 3 + 2));
  436. pControlGallery->ShowScrollBar(FALSE);
  437. pControlGallery->SetItems(m_pItemsFontBackColor);
  438. lpCreateControl->pControl = pControlGallery;
  439. return TRUE;
  440. }
  441. if (lpCreateControl->nID == ID_GALLERY_FONTS)
  442. {
  443. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  444. pControlGallery->SetControlSize(CSize(250, 60 * 5 + 2 + 20));
  445. pControlGallery->SetResizable();
  446. pControlGallery->ShowLabels(TRUE);
  447. pControlGallery->SetItems(m_pItemsThemeFonts);
  448. lpCreateControl->pControl = pControlGallery;
  449. return TRUE;
  450. }
  451. if (lpCreateControl->nID == ID_GALLERY_STYLES)
  452. {
  453. if (lpCreateControl->bToolBar)
  454. {
  455. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  456. pControlGallery->SetControlSize(CSize(235, 60));
  457. pControlGallery->SetResizable();
  458. pControlGallery->SetItemsMargin(0, 1, 0, 1);
  459. pControlGallery->ShowLabels(FALSE);
  460. pControlGallery->ShowBorders(TRUE);
  461. pControlGallery->SetItems(m_pItemsStyles);
  462. CMenu menu;
  463. menu.LoadMenu(ID_STYLES_QUICKSTYLES);
  464. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  465. pPopupBar->LoadMenu(menu.GetSubMenu(0));
  466. pControlGallery->SetCommandBar(pPopupBar);
  467. pPopupBar->InternalRelease();
  468. lpCreateControl->pControl = pControlGallery;
  469. }
  470. else
  471. {
  472. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  473. pControlGallery->SetResizable();
  474. pControlGallery->SetControlSize(CSize(235 + 72, 56 * 3));
  475. pControlGallery->SetItems(m_pItemsStyles);
  476. lpCreateControl->pControl = pControlGallery;
  477. }
  478. return TRUE;
  479. }
  480. if (lpCreateControl->nID == ID_GALLERY_SHAPES)
  481. {
  482. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  483. pControlGallery->SetControlSize(CSize(200, 200));
  484. pControlGallery->SetResizable();
  485. pControlGallery->ShowLabels(TRUE);
  486. pControlGallery->SetItems(m_pItemsShapes);
  487. lpCreateControl->pControl = pControlGallery;
  488. return TRUE;
  489. }
  490. return FALSE;
  491. }
  492. void CMainFrame::OnCustomize()
  493. {
  494. CXTPCustomizeSheet cs(GetCommandBars());
  495. CXTPCustomizeOptionsPage pageOptions(&cs);
  496. cs.AddPage(&pageOptions);
  497. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  498. pCommands->AddCategories(IDR_MAINFRAME);
  499. pCommands->InsertAllCommandsCategory();
  500. pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  501. pCommands->InsertNewMenuCategory();
  502. cs.DoModal();
  503. }
  504. void CMainFrame::OnViewTheme(UINT nTheme)
  505. {
  506. EnableOffice2007Frame(NULL);
  507. BOOL bEnableAnimation = GetCommandBars()->GetPaintManager()->m_bEnableAnimation;
  508. GetCommandBars()->SetTheme((XTPPaintTheme)(nTheme - ID_VIEW_THEME_OFFICE2000));
  509. GetCommandBars()->GetPaintManager()->m_bEnableAnimation = bEnableAnimation;
  510. if (nTheme >= ID_VIEW_THEME_OFFICE2007)
  511. {
  512. EnableOffice2007Frame(GetCommandBars());
  513. }
  514. GetCommandBars()->RedrawCommandBars();
  515. }
  516. void CMainFrame::OnUpdateViewTheme(CCmdUI* pCmdUI)
  517. {
  518. pCmdUI->SetCheck((int)pCmdUI->m_nID == GetCommandBars()->GetPaintManager()->GetCurrentTheme() + ID_VIEW_THEME_OFFICE2000 ? TRUE : FALSE);
  519. }
  520. void CMainFrame::OnClose()
  521. {
  522. SaveCommandBars(_T("CommandBars2"));
  523. CFrameWnd::OnClose();
  524. }
  525. void CMainFrame::OnGalleryShapes(NMHDR* pNMHDR, LRESULT* pResult)
  526. {
  527. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  528. CXTPControlGallery* pGallery = DYNAMIC_DOWNCAST(CXTPControlGallery, tagNMCONTROL->pControl);
  529. if (pGallery)
  530. {
  531. CXTPControlGalleryItem* pItem = pGallery->GetItem(pGallery->GetSelectedItem());
  532. if (pItem)
  533. {
  534. m_nShape = pItem->GetID();
  535. }
  536. *pResult = TRUE; // Handled
  537. }
  538. }
  539. void CMainFrame::OnUpdateGalleryShapes(CCmdUI* pCmdUI)
  540. {
  541. CXTPControlGallery* pGallery =  DYNAMIC_DOWNCAST(CXTPControlGallery, CXTPControl::FromUI(pCmdUI));
  542. if (pGallery)
  543. {
  544. pGallery->SetCheckedItem(m_nShape);
  545. }
  546. pCmdUI->Enable(TRUE);
  547. }
  548. void CMainFrame::OnGalleryStyles(NMHDR* pNMHDR, LRESULT* pResult)
  549. {
  550. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  551. CXTPControlGallery* pGallery = DYNAMIC_DOWNCAST(CXTPControlGallery, tagNMCONTROL->pControl);
  552. if (pGallery)
  553. {
  554. CXTPControlGalleryItem* pItem = pGallery->GetItem(pGallery->GetSelectedItem());
  555. if (pItem)
  556. {
  557. m_nStyle = pItem->GetID();
  558. }
  559. *pResult = TRUE; // Handled
  560. }
  561. }
  562. void CMainFrame::OnUpdateGalleryStyles(CCmdUI* pCmdUI)
  563. {
  564. CXTPControlGallery* pGallery =  DYNAMIC_DOWNCAST(CXTPControlGallery, CXTPControl::FromUI(pCmdUI));
  565. if (pGallery)
  566. {
  567. pGallery->SetCheckedItem(m_nStyle);
  568. }
  569. pCmdUI->Enable(TRUE);
  570. }
  571. void CMainFrame::OnGalleryStyleSet(NMHDR* pNMHDR, LRESULT* pResult)
  572. {
  573. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  574. CXTPControlGallery* pGallery = DYNAMIC_DOWNCAST(CXTPControlGallery, tagNMCONTROL->pControl);
  575. if (pGallery)
  576. {
  577. CXTPControlGalleryItem* pItem = pGallery->GetItem(pGallery->GetSelectedItem());
  578. if (pItem)
  579. {
  580. m_nStyleSet = pItem->GetID();
  581. }
  582. *pResult = TRUE; // Handled
  583. }
  584. }
  585. void CMainFrame::OnUpdateGalleryStyleSet(CCmdUI* pCmdUI)
  586. {
  587. CXTPControlGallery* pGallery =  DYNAMIC_DOWNCAST(CXTPControlGallery, CXTPControl::FromUI(pCmdUI));
  588. if (pGallery)
  589. {
  590. pGallery->SetCheckedItem(m_nStyleSet);
  591. }
  592. pCmdUI->Enable(TRUE);
  593. }
  594. void CMainFrame::OnGalleryThemeColors(NMHDR* pNMHDR, LRESULT* pResult)
  595. {
  596. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  597. CXTPControlGallery* pGallery = DYNAMIC_DOWNCAST(CXTPControlGallery, tagNMCONTROL->pControl);
  598. if (pGallery)
  599. {
  600. CXTPControlGalleryItem* pItem = pGallery->GetItem(pGallery->GetSelectedItem());
  601. if (pItem)
  602. {
  603. m_nThemeColors = pItem->GetID();
  604. m_pItemsFontTextColor->RemoveAll();
  605. pItem = m_pItemsFontTextColor->AddLabel(0);
  606. pItem->SetCaption(_T("Theme Colors"));
  607. CGalleryItemFontColor::AddThemeColors(m_pItemsFontTextColor, m_nThemeColors);
  608. pItem = m_pItemsFontTextColor->AddLabel(0);
  609. pItem->SetCaption(_T("Standard Colors"));
  610. CGalleryItemFontColor::AddStandardColors(m_pItemsFontTextColor);
  611. }
  612. *pResult = TRUE; // Handled
  613. }
  614. }
  615. void CMainFrame::OnUpdateGalleryThemeColors(CCmdUI* pCmdUI)
  616. {
  617. CXTPControlGallery* pGallery =  DYNAMIC_DOWNCAST(CXTPControlGallery, CXTPControl::FromUI(pCmdUI));
  618. if (pGallery)
  619. {
  620. pGallery->SetCheckedItem(m_nThemeColors);
  621. }
  622. pCmdUI->Enable(TRUE);
  623. }
  624. void CMainFrame::OnGalleryThemeFonts(NMHDR* pNMHDR, LRESULT* pResult)
  625. {
  626. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  627. CXTPControlGallery* pGallery = DYNAMIC_DOWNCAST(CXTPControlGallery, tagNMCONTROL->pControl);
  628. if (pGallery)
  629. {
  630. CXTPControlGalleryItem* pItem = pGallery->GetItem(pGallery->GetSelectedItem());
  631. if (pItem)
  632. {
  633. m_nThemeFonts = pItem->GetID();
  634. }
  635. *pResult = TRUE; // Handled
  636. }
  637. }
  638. void CMainFrame::OnUpdateGalleryThemeFonts(CCmdUI* pCmdUI)
  639. {
  640. CXTPControlGallery* pGallery =  DYNAMIC_DOWNCAST(CXTPControlGallery, CXTPControl::FromUI(pCmdUI));
  641. if (pGallery)
  642. {
  643. pGallery->SetCheckedItem(m_nThemeFonts);
  644. }
  645. pCmdUI->Enable(TRUE);
  646. }
  647. void CMainFrame::OnStylesChange() 
  648. {
  649. // TODO: Add your command handler code here
  650. }
  651. void CMainFrame::OnGalleryTable(NMHDR* pNMHDR, LRESULT* pResult)
  652. {
  653. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  654. CXTPControlGallery* pGallery = DYNAMIC_DOWNCAST(CXTPControlGallery, tagNMCONTROL->pControl);
  655. if (pGallery)
  656. {
  657. CXTPControlGalleryItem* pItem = pGallery->GetItem(pGallery->GetSelectedItem());
  658. if (pItem)
  659. {
  660. }
  661. *pResult = TRUE; // Handled
  662. }
  663. }
  664. void CMainFrame::OnUpdateGalleryTable(CCmdUI* pCmdUI)
  665. {
  666. pCmdUI->Enable(TRUE);
  667. }
  668. void CMainFrame::OnViewAnimate() 
  669. {
  670. GetCommandBars()->GetPaintManager()->m_bEnableAnimation ^= 1;
  671. }
  672. void CMainFrame::OnUpdateViewAnimate(CCmdUI* pCmdUI) 
  673. {
  674. pCmdUI->SetCheck(GetCommandBars()->GetPaintManager()->m_bEnableAnimation);
  675. }
  676. void CMainFrame::OnStylesPreviewStart(NMHDR* /*pHdr*/, LRESULT* /*presult*/)
  677. {
  678. TRACE(_T("nOnStylesPreviewStartn"));
  679. }
  680. void CMainFrame::OnStylesPreviewCancel(NMHDR* /*pHdr*/, LRESULT* /*presult*/)
  681. {
  682. TRACE(_T("OnStylesPreviewCanceln"));
  683. }
  684. void CMainFrame::OnStylesPreviewApply(NMHDR* /*pHdr*/, LRESULT* /*presult*/)
  685. {
  686. TRACE(_T("OnStylesPreviewApplyn"));
  687. }
  688. void CMainFrame::OnStylesPreviewChange(NMHDR* pHdr, LRESULT* /*presult*/)
  689. {
  690. NMXTPCONTROL* pNM = (NMXTPCONTROL*)pHdr;
  691. if (pNM->pControl->GetType() == xtpControlGallery)
  692. {
  693. CXTPControlGallery* pGallery = (CXTPControlGallery*)pNM->pControl;
  694. int nSelected = (pGallery->IsItemSelected() ? pGallery->GetSelectedItem() : -1);
  695. TRACE(_T("OnStylesPreviewChange, %in"), nSelected);
  696. }
  697. }