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 "RibbonControls.h"
  5. #include "GalleryItems.h"
  6. #include "MainFrm.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. // NOTE - the ClassWizard will add and remove mapping macros here.
  18. //    DO NOT EDIT what you see in these blocks of generated code !
  19. ON_WM_CREATE()
  20. //}}AFX_MSG_MAP
  21. ON_XTP_CREATECONTROL()
  22. ON_COMMAND(ID_BUTTON_LARGETOGGLEBUTTON, OnToggleButton)
  23. ON_UPDATE_COMMAND_UI(ID_BUTTON_LARGETOGGLEBUTTON, OnUpdateToggleButton)
  24. ON_UPDATE_COMMAND_UI_RANGE(ID_BUTTON_LARGESIMPLEBUTTON, ID_BUTTON_SMALLSPLITPOPUPBUTTON, OnEnableButton)
  25. ON_UPDATE_COMMAND_UI_RANGE(ID_POPUP_OPTION1, ID_POPUP_OPTION3, OnEnableButton)
  26. ON_UPDATE_COMMAND_UI_RANGE(ID_EDITOR_EDIT, ID_EDITOR_COMBO, OnEnableButton)
  27. ON_UPDATE_COMMAND_UI_RANGE(ID_EDITOR_EXTENDEDEDIT, ID_EDITOR_EXTENDEDCOMBO, OnEnableButton)
  28. ON_UPDATE_COMMAND_UI_RANGE(ID_GALLERY_FONTFACE, ID_EDITOR_POPUP, OnEnableButton)
  29. ON_UPDATE_COMMAND_UI_RANGE(ID_GALLERY_STYLES, ID_GALLERY_TABLE, OnEnableButton)
  30. ON_UPDATE_COMMAND_UI(ID_GALLERY_COLOR, OnUpdateSelectorText)
  31. ON_XTP_EXECUTE(ID_GALLERY_COLOR, OnSelectorText)
  32. ON_UPDATE_COMMAND_UI(ID_GALLERY_UNDO, OnUpdateEditUndo)
  33. ON_XTP_EXECUTE(ID_GALLERY_UNDO, OnEditUndo)
  34. ON_COMMAND_RANGE(ID_BUTTON_CHECKBOX1, ID_BUTTON_CHECKBOX3, OnCheckbox)
  35. ON_COMMAND_RANGE(ID_BUTTON_RADIOBUTTON1, ID_BUTTON_RADIOBUTTON3, OnRadioButton)
  36. ON_UPDATE_COMMAND_UI_RANGE(ID_BUTTON_CHECKBOX1, ID_BUTTON_CHECKBOX3, OnUpdateCheckbox)
  37. ON_UPDATE_COMMAND_UI_RANGE(ID_BUTTON_RADIOBUTTON1, ID_BUTTON_RADIOBUTTON3, OnUpdateRadioButton)
  38. ON_COMMAND(ID_OPTIONS_RIGHTTOLEFT, OnOptionsRighttoleft)
  39. ON_UPDATE_COMMAND_UI(ID_OPTIONS_RIGHTTOLEFT, OnUpdateOptionsRighttoleft)
  40. ON_COMMAND_RANGE(ID_OPTIONS_STYLEBLUE, ID_OPTIONS_STYLEAQUA, OnOptionsStyle)
  41. ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_STYLEBLUE, ID_OPTIONS_STYLEAQUA, OnUpdateOptionsStyle)
  42. END_MESSAGE_MAP()
  43. static UINT indicators[] =
  44. {
  45. ID_SEPARATOR,           // status line indicator
  46. ID_INDICATOR_CAPS,
  47. ID_INDICATOR_NUM,
  48. ID_INDICATOR_SCRL,
  49. };
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CMainFrame construction/destruction
  52. CMainFrame::CMainFrame()
  53. {
  54. m_bCheckbox[0] = TRUE;
  55. m_bCheckbox[1] = FALSE;
  56. m_bCheckbox[2] = FALSE;
  57. m_nRadioButton = 1;
  58. m_bToggleButton = FALSE;
  59. m_nRibbonStyle = ID_OPTIONS_STYLEBLUE;
  60. m_clr = 0;
  61. }
  62. CMainFrame::~CMainFrame()
  63. {
  64. }
  65. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  66. {
  67. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  68. return -1;
  69. XTPPaintManager()->SetTheme(xtpThemeRibbon);
  70. if (!CreateStatusBar())
  71. return -1;
  72. if (!InitCommandBars())
  73. return -1;
  74. CXTPCommandBars* pCommandBars = GetCommandBars();
  75. m_wndStatusBar.SetCommandBars(pCommandBars);
  76. if (!CreateRibbonBar())
  77. {
  78. TRACE0("Failed to create ribbonn");
  79. return -1;
  80. }
  81. CXTPToolTipContext* pToolTipContext = GetCommandBars()->GetToolTipContext();
  82. pToolTipContext->SetStyle(xtpToolTipOffice2007);
  83. pToolTipContext->ShowTitleAndDescription();
  84. pToolTipContext->ShowImage(TRUE, 0);
  85. pToolTipContext->SetMargin(CRect(2, 2, 2, 2));
  86. pToolTipContext->SetMaxTipWidth(180);
  87. pToolTipContext->SetFont(pCommandBars->GetPaintManager()->GetIconFont());
  88. pToolTipContext->SetDelayTime(TTDT_INITIAL, 900);
  89. pCommandBars->GetCommandBarsOptions()->bShowKeyboardTips = TRUE;
  90. return 0;
  91. }
  92. BOOL CMainFrame::CreateStatusBar()
  93. {
  94. if (!m_wndStatusBar.Create(this))
  95. {
  96. TRACE0("Failed to create status barn");
  97. return FALSE;      // fail to create
  98. }
  99. m_wndStatusBar.AddIndicator(0);
  100. m_wndStatusBar.AddIndicator(ID_INDICATOR_CAPS);
  101. m_wndStatusBar.AddIndicator(ID_INDICATOR_NUM);
  102. m_wndStatusBar.AddIndicator(ID_INDICATOR_SCRL);
  103. return TRUE;
  104. }
  105. BOOL CMainFrame::CreateRibbonBar()
  106. {
  107. CXTPCommandBars* pCommandBars = GetCommandBars();
  108. CMenu menu;
  109. menu.Attach(::GetMenu(m_hWnd));
  110. SetMenu(NULL);
  111. CXTPRibbonBar* pRibbonBar = (CXTPRibbonBar*)pCommandBars->Add(_T("The Ribbon"), xtpBarTop, RUNTIME_CLASS(CXTPRibbonBar));
  112. if (!pRibbonBar)
  113. {
  114. return FALSE;
  115. }
  116. pRibbonBar->EnableDocking(0);
  117. CXTPControlPopup* pControlFile = (CXTPControlPopup*)pRibbonBar->AddSystemButton(ID_MENU_FILE);
  118. pControlFile->SetCommandBar(menu.GetSubMenu(0));
  119. pControlFile->GetCommandBar()->SetIconSize(CSize(32, 32));
  120. pCommandBars->GetImageManager()->SetIcons(ID_MENU_FILE);
  121. pControlFile->SetCaption(_T("&File"));
  122. pControlFile->SetIconId(IDB_GEAR);
  123. UINT uCommand = {IDB_GEAR};
  124. pCommandBars->GetImageManager()->SetIcons(IDB_GEAR, &uCommand, 1, CSize(0, 0), xtpImageNormal);
  125. CXTPRibbonTab* pTabHome = pRibbonBar->AddTab(ID_TAB_BUTTONS);
  126. // Large Buttons
  127. if (pTabHome)
  128. {
  129. CXTPControl* pControl;
  130. CXTPRibbonGroup* pGroup = pTabHome->AddGroup(ID_GROUP_LARGEBUTTONS);
  131. pGroup->ShowOptionButton();
  132. pControl = pGroup->Add(xtpControlButton, ID_BUTTON_LARGESIMPLEBUTTON);
  133. pControl->SetStyle(xtpButtonIconAndCaptionBelow);
  134. pControl = pGroup->Add(xtpControlButton, ID_BUTTON_LARGETOGGLEBUTTON);
  135. pControl->SetStyle(xtpButtonIconAndCaptionBelow);
  136. pControl = pGroup->Add(xtpControlButtonPopup, ID_BUTTON_LARGEPOPUPBUTTON);
  137. pControl->SetStyle(xtpButtonIconAndCaptionBelow);
  138. pControl = pGroup->Add(xtpControlSplitButtonPopup, ID_BUTTON_LARGESPLITPOPUPBUTTON);
  139. pControl->SetStyle(xtpButtonIconAndCaptionBelow);
  140. UINT nIDs[] = {ID_BUTTON_LARGESIMPLEBUTTON, ID_BUTTON_LARGEPOPUPBUTTON, ID_BUTTON_LARGESPLITPOPUPBUTTON, ID_BUTTON_LARGETOGGLEBUTTON};
  141. pCommandBars->GetImageManager()->SetIcons(ID_GROUP_LARGEBUTTONS, nIDs, 4, CSize(32, 32), xtpImageNormal);
  142. pCommandBars->GetImageManager()->SetIcons(ID_GROUP_SMALLBUTTONS, nIDs, 4, CSize(16, 16), xtpImageNormal);
  143. }
  144. // Small Buttons
  145. if (pTabHome)
  146. {
  147. CXTPControl* pControl;
  148. CXTPRibbonGroup* pGroup = pTabHome->AddGroup(ID_GROUP_SMALLBUTTONS);
  149. pControl = pGroup->Add(xtpControlButton, ID_BUTTON_SMALLSIMPLEBUTTON);
  150. pControl->SetStyle(xtpButtonIconAndCaption);
  151. pControl = pGroup->Add(xtpControlPopup, ID_BUTTON_SMALLPOPUPBUTTON);
  152. pControl->SetStyle(xtpButtonIconAndCaption);
  153. pControl = pGroup->Add(xtpControlSplitButtonPopup, ID_BUTTON_SMALLSPLITPOPUPBUTTON);
  154. pControl->SetStyle(xtpButtonIconAndCaption);
  155. pControl = pGroup->Add(xtpControlButton, ID_BUTTON_SMALLSIMPLEBUTTON);
  156. pControl->SetStyle(xtpButtonIcon);
  157. pControl = pGroup->Add(xtpControlPopup, ID_BUTTON_SMALLPOPUPBUTTON);
  158. pControl->SetStyle(xtpButtonIcon);
  159. pControl = pGroup->Add(xtpControlSplitButtonPopup, ID_BUTTON_SMALLSPLITPOPUPBUTTON);
  160. pControl->SetStyle(xtpButtonIcon);
  161. UINT nIDs[] = {ID_BUTTON_SMALLSIMPLEBUTTON, ID_BUTTON_SMALLPOPUPBUTTON, ID_BUTTON_SMALLSPLITPOPUPBUTTON};
  162. pCommandBars->GetImageManager()->SetIcons(ID_GROUP_SMALLBUTTONS, nIDs, 3, CSize(16, 16), xtpImageNormal);
  163. }
  164. // CheckBoxes and Radio Buttons
  165. if (pTabHome)
  166. {
  167. CXTPRibbonGroup* pGroup = pTabHome->AddGroup(ID_GROUP_CHECKBOXES);
  168. CXTPControl* pControl;
  169. pControl = pGroup->Add(xtpControlCheckBox, ID_BUTTON_CHECKBOX1);
  170. pControl = pGroup->Add(xtpControlCheckBox, ID_BUTTON_CHECKBOX2);
  171. pControl = pGroup->Add(xtpControlCheckBox, ID_BUTTON_CHECKBOX3);
  172. pControl = pGroup->Add(xtpControlRadioButton, ID_BUTTON_RADIOBUTTON1);
  173. pControl->SetBeginGroup(TRUE);
  174. pControl = pGroup->Add(xtpControlRadioButton, ID_BUTTON_RADIOBUTTON2);
  175. pControl = pGroup->Add(xtpControlRadioButton, ID_BUTTON_RADIOBUTTON3);
  176. }
  177. if (pTabHome)
  178. {
  179. CXTPRibbonGroup* pGroup = pTabHome->AddGroup(ID_GROUP_GROUP);
  180. pGroup->SetControlsGrouping(TRUE);
  181. pGroup->SetControlsCentering(TRUE);
  182. pGroup->LoadToolBar(IDR_MAINFRAME);
  183. }
  184. CXTPRibbonTab* pTabEditors = pRibbonBar->AddTab(ID_TAB_EDITORS);
  185. // Standard Editors
  186. if (pTabEditors)
  187. {
  188. CXTPRibbonGroup* pGroup = pTabEditors->AddGroup(ID_GROUP_STANDARDEDITORS);
  189. CXTPControlEdit* pControlEdit = (CXTPControlEdit*)pGroup->Add(xtpControlEdit, ID_EDITOR_EDIT);
  190. pControlEdit->SetEditText("Edit");
  191. //pControlEdit->ShowSpinButtons(TRUE);
  192. pControlEdit->SetWidth(150);
  193. pControlEdit->SetStyle(xtpButtonIcon);
  194. CXTPControlComboBox* pControlCombo = (CXTPControlComboBox*)pGroup->Add(xtpControlComboBox, ID_EDITOR_COMBO);
  195. pControlCombo->GetCommandBar()->SetCommandBars(pCommandBars);
  196. pControlCombo->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
  197. pControlCombo->SetWidth(150);
  198. pControlCombo->SetStyle(xtpButtonIcon);
  199. pControlCombo->SetDropDownListStyle();
  200. pControlCombo->SetEditText(_T("ComboBox"));
  201. pControlCombo->AddString(_T("Item 1"));
  202. pControlCombo->AddString(_T("Item 2"));
  203. pControlCombo = (CXTPControlComboBox*)pGroup->Add(xtpControlComboBox, ID_EDITOR_COMBO);
  204. pControlCombo->GetCommandBar()->SetCommandBars(pCommandBars);
  205. pControlCombo->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
  206. pControlCombo->SetWidth(150);
  207. pControlCombo->SetStyle(xtpButtonIcon);
  208. pControlCombo->AddString(_T("ComboBox"));
  209. pControlCombo->AddString(_T("Item 1"));
  210. pControlCombo->AddString(_T("Item 2"));
  211. pControlCombo->SetCurSel(0);
  212. }
  213. // Extended Editors
  214. if (pTabEditors)
  215. {
  216. CXTPRibbonGroup* pGroup = pTabEditors->AddGroup(ID_GROUP_EXTENDEDEDITORS);
  217. CXTPControlEdit* pControlEdit = (CXTPControlEdit*)pGroup->Add(xtpControlEdit, ID_EDITOR_EXTENDEDEDIT);
  218. pControlEdit->SetEditText("0");
  219. pControlEdit->ShowSpinButtons(TRUE);
  220. pControlEdit->SetWidth(150);
  221. pControlEdit->SetStyle(xtpButtonIconAndCaption);
  222. CXTPControlComboBox* pControlCombo = (CXTPControlComboBox*)pGroup->Add(xtpControlComboBox, ID_EDITOR_EXTENDEDCOMBO);
  223. pControlCombo->GetCommandBar()->SetCommandBars(pCommandBars);
  224. pControlCombo->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
  225. pControlCombo->SetWidth(150);
  226. pControlCombo->SetStyle(xtpButtonIconAndCaption);
  227. pControlCombo->SetDropDownListStyle();
  228. pControlCombo->SetEditText(_T("ComboBox"));
  229. pControlCombo->AddString(_T("Item 1"));
  230. pControlCombo->AddString(_T("Item 2"));
  231. pControlCombo = (CXTPControlComboBox*)pGroup->Add(xtpControlComboBox, ID_EDITOR_EXTENDEDCOMBO);
  232. pControlCombo->GetCommandBar()->SetCommandBars(pCommandBars);
  233. pControlCombo->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
  234. pControlCombo->SetWidth(150);
  235. pControlCombo->SetStyle(xtpButtonIconAndCaption);
  236. pControlCombo->AddString(_T("ComboBox"));
  237. pControlCombo->AddString(_T("Item 1"));
  238. pControlCombo->AddString(_T("Item 2"));
  239. pControlCombo->SetCurSel(0);
  240. UINT nIDs[] = {ID_EDITOR_EXTENDEDEDIT, ID_EDITOR_EXTENDEDCOMBO};
  241. pCommandBars->GetImageManager()->SetIcons(ID_GROUP_EXTENDEDEDITORS, nIDs, 2, CSize(16, 16), xtpImageNormal);
  242. }
  243. // Gallery Editors
  244. {
  245. CXTPRibbonGroup* pGroup = pTabEditors->AddGroup(ID_GROUP_GALLERY);
  246. CXTPControlGalleryItems* m_pItemsFontFace = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_FONTFACE);
  247. m_pItemsFontFace->SetItemSize(CSize(0, 26));
  248. CGalleryItemFontFace::AddFontItems(m_pItemsFontFace);
  249. CXTPControlComboBox* pComboFont = new CXTPControlComboBox();
  250. pGroup->Add(pComboFont, ID_GALLERY_FONTFACE);
  251. pComboFont->SetDropDownListStyle();
  252. pComboFont->EnableAutoComplete();
  253. pComboFont->SetWidth(150);
  254. CXTPPopupBar* pPopupBarGallery = CXTPControlComboBoxGalleryPopupBar::CreateComboBoxGalleryPopupBar(pCommandBars);
  255. pComboFont->SetCommandBar(pPopupBarGallery);
  256. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  257. pControlGallery->SetControlSize(CSize(290, 508));
  258. pControlGallery->SetResizable(FALSE, TRUE);
  259. pControlGallery->ShowLabels(TRUE);
  260. pControlGallery->SetItems(m_pItemsFontFace);
  261. pPopupBarGallery->GetControls()->Add(pControlGallery, ID_GALLERY_FONTFACE);
  262. pPopupBarGallery->InternalRelease();
  263. CXTPControlComboBox* pComboPopup = new CXTPControlComboBox();
  264. pComboPopup->SetWidth(150);
  265. pGroup->Add(pComboPopup, ID_EDITOR_POPUP);
  266. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(pCommandBars);
  267. pPopupBar->SetWidth(150);
  268. pComboPopup->SetCommandBar(pPopupBar);
  269. CMenu menu;
  270. menu.LoadMenu(IDR_MENU_OPTIONS);
  271. pPopupBar->LoadMenu(menu.GetSubMenu(0));
  272. pPopupBar->InternalRelease();
  273. }
  274. CXTPRibbonTab* pTabGallery = pRibbonBar->AddTab(ID_TAB_GALLERIES);
  275. // Create Gallery Items
  276. {
  277. m_pItemsStyles = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_STYLES);
  278. m_pItemsStyles->GetImageManager()->SetMaskColor(0xFF00FF);
  279. m_pItemsStyles->GetImageManager()->SetIcons(ID_GALLERY_STYLES, 0, 0, CSize(64, 48));
  280. m_pItemsStyles->GetImageManager()->SetMaskColor(COLORREF_NULL); // Default TopLeft Pixel.
  281. m_pItemsStyles->SetItemSize(CSize(72, 56));
  282. for (int nStyle = 0; nStyle < 16; nStyle++)
  283. m_pItemsStyles->AddItem(nStyle, nStyle);
  284. m_pItemsTable = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_TABLE);
  285. m_pItemsTable->ClipItems(FALSE); //Redraw all Items if selection changed
  286. m_pItemsTable->SetItemSize(CSize(19, 19));
  287. CXTPControlGalleryItem* pItem = m_pItemsTable->AddItem(new CGalleryItemTableLabel());
  288. int nItem;
  289. for (nItem = 0; nItem < 10 * 8; nItem++)
  290. m_pItemsTable->AddItem(new CGalleryItemTable(nItem));
  291. m_pItemsFontTextColor = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_COLOR);
  292. m_pItemsFontTextColor->SetItemSize(CSize(17, 17));
  293. pItem = m_pItemsFontTextColor->AddLabel(0);
  294. pItem->SetCaption(_T("Theme Colors"));
  295. CGalleryItemFontColor::AddThemeColors(m_pItemsFontTextColor, 0);
  296. pItem = m_pItemsFontTextColor->AddLabel(0);
  297. pItem->SetCaption(_T("Standard Colors"));
  298. CGalleryItemFontColor::AddStandardColors(m_pItemsFontTextColor);
  299. m_pItemsUndo = CXTPControlGalleryItems::CreateItems(GetCommandBars(), ID_GALLERY_UNDO);
  300. m_pItemsUndo->SetItemSize(CSize(0, 21));
  301. m_pItemsUndo->ClipItems(FALSE);
  302. }
  303. // Create Popup Gallery
  304. if (pTabGallery)
  305. {
  306. CXTPRibbonGroup* pGroup = pTabGallery->AddGroup(ID_GROUP_POPUP);
  307. pGroup->SetControlsCentering(TRUE);
  308. CXTPControlPopup* pControl = (CXTPControlPopup*)pGroup->Add(xtpControlButtonPopup, ID_GALLERY_STYLES);
  309. CMenu menu;
  310. menu.LoadMenu(ID_STYLES_QUICKSTYLES);
  311. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  312. pPopupBar->LoadMenu(menu.GetSubMenu(0));
  313. pControl->SetCommandBar(pPopupBar);
  314. pPopupBar->InternalRelease();
  315. pControl = (CXTPControlPopup*)pGroup->Add(xtpControlButtonPopup, ID_GALLERY_TABLE);
  316. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  317. pControlGallery->SetControlSize(CSize(190, 175));
  318. pControlGallery->ShowLabels(TRUE);
  319. pControlGallery->ShowScrollBar(FALSE);
  320. pControlGallery->SetItems(m_pItemsTable);
  321. pControl->GetCommandBar()->GetControls()->Add(pControlGallery);
  322. pControl = (CXTPControlPopup*)pGroup->Add(xtpControlButtonPopup, ID_GALLERY_COLOR);
  323. pControlGallery = new CXTPControlGallery();
  324. pControlGallery->SetControlSize(CSize(171, 145));
  325. pControlGallery->ShowLabels(TRUE);
  326. pControlGallery->ShowScrollBar(FALSE);
  327. pControlGallery->SetItems(m_pItemsFontTextColor);
  328. pControl->GetCommandBar()->GetControls()->Add(pControlGallery);
  329. CXTPControlPopup* pControlUndo = (CXTPControlPopup*)pGroup->Add(xtpControlSplitButtonPopup, ID_GALLERY_UNDO);
  330. pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  331. pPopupBar->SetShowGripper(FALSE);
  332. pControlUndo->SetCommandBar(pPopupBar);
  333. pControlGallery = new CControlGalleryUndo();
  334. pControlGallery->SetItems(m_pItemsUndo);
  335. pControlGallery->SetWidth(120);
  336. pControlGallery->ShowScrollBar(FALSE);
  337. pPopupBar->GetControls()->Add(pControlGallery, ID_GALLERY_UNDO);
  338. CXTPControlStatic* pControlListBoxInfo = (CXTPControlStatic*)pPopupBar->GetControls()->Add(new CXTPControlStatic(), ID_GALLERY_UNDO);
  339. pControlListBoxInfo->SetWidth(120);
  340. pControlListBoxInfo->SetFlags(xtpFlagSkipFocus);
  341. pPopupBar->InternalRelease();
  342. UINT nIDs[] = {ID_GALLERY_STYLES, ID_GALLERY_TABLE, ID_GALLERY_COLOR, ID_GALLERY_UNDO};
  343. pCommandBars->GetImageManager()->SetIcons(ID_GROUP_INLINE, nIDs, 4, CSize(32, 32), xtpImageNormal);
  344. }
  345. // Create Inline Gallery
  346. if (pTabGallery)
  347. {
  348. CXTPRibbonGroup* pGroup = pTabGallery->AddGroup(ID_GROUP_INLINE);
  349. pGroup->SetControlsCentering(TRUE);
  350. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  351. pControlGallery->SetControlSize(CSize(171 + 19, 60));
  352. pControlGallery->ShowLabels(FALSE);
  353. pControlGallery->ShowScrollBar(TRUE);
  354. pControlGallery->ShowBorders(TRUE);
  355. pControlGallery->SetItems(m_pItemsFontTextColor);
  356. pGroup->Add(pControlGallery, ID_GALLERY_STYLES);
  357. pControlGallery = new CXTPControlGallery();
  358. pControlGallery->SetBeginGroup(TRUE);
  359. pControlGallery->SetControlSize(CSize(235, 60));
  360. pControlGallery->SetResizable();
  361. pControlGallery->SetItemsMargin(0, 1, 0, 1);
  362. pControlGallery->ShowLabels(FALSE);
  363. pControlGallery->ShowBorders(TRUE);
  364. pControlGallery->SetItems(m_pItemsStyles);
  365. CMenu menu;
  366. menu.LoadMenu(ID_STYLES_QUICKSTYLES);
  367. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  368. pPopupBar->LoadMenu(menu.GetSubMenu(0));
  369. pControlGallery->SetCommandBar(pPopupBar);
  370. pPopupBar->InternalRelease();
  371. pGroup->Add(pControlGallery, ID_GALLERY_STYLES);
  372. }
  373. CXTPRibbonTab* pTabMisc = pRibbonBar->AddTab(ID_TAB_MISC);
  374. if (pTabMisc)
  375. {
  376. CXTPRibbonGroup* pGroup = pTabMisc->AddGroup(ID_GROUP_LABEL);
  377. pGroup->SetControlsCentering(TRUE);
  378. CXTPControl* pControl = pGroup->Add(xtpControlLabel, 0);
  379. pControl->SetCaption(_T("Label Text 1"));
  380. pControl->SetStyle(xtpButtonCaption);
  381. pControl = pGroup->Add(xtpControlLabel, 0);
  382. pControl->SetCaption(_T("Label Text 2"));
  383. pControl->SetStyle(xtpButtonCaption);
  384. pControl = pGroup->Add(xtpControlLabel, 0);
  385. pControl->SetCaption(_T("Label Text 3"));
  386. pControl->SetStyle(xtpButtonCaption);
  387. #ifdef _XTP_INCLUDE_MARKUP
  388. CXTPControlMarkupLabel* pLabel = new CXTPControlMarkupLabel();
  389. pGroup->Add(pLabel, 0);
  390. pLabel->SetBeginGroup(TRUE);
  391. pLabel->SetCaption(_T("<TextBlock TextAlignment='Center'><Underline>This is</Underline><LineBreak/><Bold>Markup</Bold> <Run Foreground='Red'>Label</Run><LineBreak/><Italic>Control</Italic></TextBlock>"));
  392. #endif
  393. }
  394. if (pTabMisc)
  395. {
  396. CXTPRibbonGroup* pGroup = pTabMisc->AddGroup(ID_GROUP_BITMAP);
  397. pGroup->SetControlsCentering(TRUE);
  398. CXTPControlBitmap* pLabel = new CXTPControlBitmap();
  399. pGroup->Add(pLabel, ID_BUTTON_BITMAP);
  400. UINT nIDs[] = {ID_BUTTON_BITMAP};
  401. pCommandBars->GetImageManager()->SetIcons(ID_BUTTON_BITMAP, nIDs, 1, CSize(0, 0), xtpImageNormal);
  402. }
  403. if (pTabMisc)
  404. {
  405. CXTPRibbonGroup* pGroup = pTabMisc->AddGroup(ID_GROUP_HYPERLINK);
  406. pGroup->SetControlsCentering(TRUE);
  407. CXTPControlHyperlink* pLabel = new CXTPControlHyperlink();
  408. pLabel->SetFlags(xtpFlagManualUpdate);
  409. pGroup->Add(pLabel, ID_BUTTON_URLLINK);
  410. pLabel = new CXTPControlHyperlink();
  411. pLabel->SetFlags(xtpFlagManualUpdate);
  412. pGroup->Add(pLabel, ID_BUTTON_EMAILLINK);
  413. }
  414. if (pTabMisc)
  415. {
  416. CXTPRibbonGroup* pGroup = pTabMisc->AddGroup(ID_GROUP_PROGRESS);
  417. pGroup->SetControlsCentering(TRUE);
  418. CXTPControlProgress* pControl = (CXTPControlProgress*)pGroup->Add(new CXTPControlProgress(), 0);
  419. pControl->SetPos(30);
  420. pControl->SetFlags(xtpFlagNoMovable | xtpFlagSkipFocus);
  421. }
  422. if (pTabMisc)
  423. {
  424. CXTPRibbonGroup* pGroup = pTabMisc->AddGroup(ID_GROUP_SCROLLBAR);
  425. pGroup->SetControlsCentering(TRUE);
  426. CXTPControlScrollBar* pControl = (CXTPControlScrollBar*)pGroup->Add(new CXTPControlScrollBar(), 0);
  427. pControl->SetFlags(xtpFlagNoMovable | xtpFlagSkipFocus);
  428. pControl->SetPos(30);
  429. pControl->SetWidth(100);
  430. }
  431. if (pTabMisc)
  432. {
  433. CXTPRibbonGroup* pGroup = pTabMisc->AddGroup(ID_GROUP_SLIDER);
  434. pGroup->SetControlsCentering(TRUE);
  435. CXTPControlScrollBar* pControl = (CXTPControlScrollBar*)pGroup->Add(new CXTPControlScrollBar(), 0);
  436. pControl->SetScrollBarStyle(xtpScrollStyleSlider);
  437. pControl->SetPos(30);
  438. pControl->SetFlags(xtpFlagNoMovable | xtpFlagSkipFocus);
  439. pControl->SetWidth(100);
  440. }
  441. // Options
  442. {
  443. CXTPControlPopup* pControlOptions = (CXTPControlPopup*)pRibbonBar->GetControls()->Add(xtpControlPopup, -1);
  444. pControlOptions->SetFlags(xtpFlagRightAlign);
  445. CMenu mnuOptions;
  446. mnuOptions.LoadMenu(IDR_MENU_OPTIONS);
  447. pControlOptions->SetCommandBar(mnuOptions.GetSubMenu(0));
  448. pControlOptions->SetCaption(_T("Options"));
  449. CXTPControl* pControlAbout = pRibbonBar->GetControls()->Add(xtpControlButton, ID_APP_ABOUT);
  450. pControlAbout->SetFlags(xtpFlagRightAlign);
  451. pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME);
  452. }
  453. // Quick Access
  454. {
  455. pRibbonBar->GetQuickAccessControls()->Add(xtpControlButton, ID_FILE_NEW);
  456. pRibbonBar->GetQuickAccessControls()->Add(xtpControlButton, ID_FILE_OPEN)->SetHideFlag(xtpHideCustomize, TRUE);
  457. pRibbonBar->GetQuickAccessControls()->Add(xtpControlButton, ID_FILE_SAVE);
  458. pRibbonBar->GetQuickAccessControls()->Add(xtpControlButton, ID_FILE_PRINT);
  459. pRibbonBar->GetQuickAccessControls()->CreateOriginalControls();
  460. }
  461. pRibbonBar->SetCloseable(FALSE);
  462. pRibbonBar->EnableFrameTheme();
  463. return TRUE;
  464. }
  465. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  466. {
  467. if( !CFrameWnd::PreCreateWindow(cs) )
  468. return FALSE;
  469. // TODO: Modify the Window class or styles here by modifying
  470. //  the CREATESTRUCT cs
  471. cs.cx = 730;
  472. cs.cy = 600;
  473. cs.lpszClass = _T("XTPMainFrame");
  474. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  475. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  476. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  477. return TRUE;
  478. }
  479. /////////////////////////////////////////////////////////////////////////////
  480. // CMainFrame diagnostics
  481. #ifdef _DEBUG
  482. void CMainFrame::AssertValid() const
  483. {
  484. CFrameWnd::AssertValid();
  485. }
  486. void CMainFrame::Dump(CDumpContext& dc) const
  487. {
  488. CFrameWnd::Dump(dc);
  489. }
  490. #endif //_DEBUG
  491. /////////////////////////////////////////////////////////////////////////////
  492. // CMainFrame message handlers
  493. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  494. {
  495. if (lpCreateControl->nID == ID_FILE_RECENTDOCUMENTS)
  496. {
  497. lpCreateControl->pControl = new CXTPRibbonControlSystemRecentFileList();
  498. return TRUE;
  499. }
  500. if (lpCreateControl->nID == ID_APP_EXIT || lpCreateControl->nID == ID_APP_OPTIONS)
  501. {
  502. lpCreateControl->pControl = new CXTPRibbonControlSystemPopupBarButton();
  503. return TRUE;
  504. }
  505. if (lpCreateControl->nID == ID_GALLERY_STYLES)
  506. {
  507. CXTPControlGallery* pControlGallery = new CXTPControlGallery();
  508. pControlGallery->SetResizable();
  509. pControlGallery->SetControlSize(CSize(235 + 72, 56 * 3));
  510. pControlGallery->SetItems(m_pItemsStyles);
  511. lpCreateControl->pControl = pControlGallery;
  512. return TRUE;
  513. }
  514. return FALSE;
  515. }
  516. void CMainFrame::OnEnableButton(CCmdUI* pCmdUI)
  517. {
  518. pCmdUI->Enable();
  519. }
  520. void CMainFrame::OnCheckbox(UINT nID)
  521. {
  522. m_bCheckbox[nID - ID_BUTTON_CHECKBOX1] ^= 1;
  523. }
  524. void CMainFrame::OnRadioButton(UINT nID)
  525. {
  526. m_nRadioButton = nID - ID_BUTTON_RADIOBUTTON1;
  527. }
  528. void CMainFrame::OnUpdateCheckbox(CCmdUI* pCmdUI)
  529. {
  530. pCmdUI->SetCheck(m_bCheckbox[(int)pCmdUI->m_nID - ID_BUTTON_CHECKBOX1]);
  531. }
  532. void CMainFrame::OnUpdateRadioButton(CCmdUI* pCmdUI)
  533. {
  534. pCmdUI->SetCheck((int)pCmdUI->m_nID - ID_BUTTON_RADIOBUTTON1 == m_nRadioButton);
  535. }
  536. void CMainFrame::OnToggleButton()
  537. {
  538. m_bToggleButton ^= 1;
  539. }
  540. void CMainFrame::OnUpdateToggleButton(CCmdUI* pCmdUI)
  541. {
  542. pCmdUI->SetCheck(m_bToggleButton);
  543. }
  544. void CMainFrame::OnOptionsRighttoleft() 
  545. {
  546. if (GetExStyle() & WS_EX_LAYOUTRTL)
  547. {
  548. GetCommandBars()->SetLayoutRTL(FALSE);
  549. ModifyStyleEx(WS_EX_LAYOUTRTL, 0);
  550. }
  551. else
  552. {
  553. GetCommandBars()->SetLayoutRTL(TRUE);
  554. ModifyStyleEx(0, WS_EX_LAYOUTRTL);
  555. }
  556. }
  557. void CMainFrame::OnUpdateOptionsRighttoleft(CCmdUI* pCmdUI) 
  558. {
  559. if (XTPSystemVersion()->IsLayoutRTLSupported())
  560. {
  561. pCmdUI->SetCheck(GetExStyle() & WS_EX_LAYOUTRTL ? TRUE : FALSE);
  562. }
  563. else
  564. {
  565. pCmdUI->Enable(FALSE);
  566. }
  567. }
  568. void CMainFrame::OnUpdateOptionsStyle(CCmdUI* pCmdUI)
  569. {
  570. pCmdUI->SetCheck(pCmdUI->m_nID == m_nRibbonStyle ? 1 : 0);
  571. }
  572. void CMainFrame::OnOptionsStyle(UINT nStyle)
  573. {
  574. HMODULE hModule = AfxGetInstanceHandle();
  575. LPCTSTR lpszIniFile = 0;
  576. switch (nStyle)
  577. {
  578. case ID_OPTIONS_STYLEBLUE: 
  579. lpszIniFile = _T("OFFICE2007BLUE.INI"); break;
  580. case ID_OPTIONS_STYLEBLACK: 
  581. lpszIniFile = _T("OFFICE2007BLACK.INI"); break;
  582. case ID_OPTIONS_STYLEAQUA: 
  583. lpszIniFile = _T("OFFICE2007AQUA.INI"); break;
  584. case ID_OPTIONS_STYLESILVER: 
  585. lpszIniFile = _T("OFFICE2007SILVER.INI"); break;
  586. }
  587. ((CXTPOffice2007Theme*)GetCommandBars()->GetPaintManager())->SetImageHandle(hModule, lpszIniFile);
  588. GetCommandBars()->GetImageManager()->RefreshAll();
  589. GetCommandBars()->RedrawCommandBars();
  590. SendMessage(WM_NCPAINT);
  591. RedrawWindow(0, 0, RDW_ALLCHILDREN|RDW_INVALIDATE);
  592. m_nRibbonStyle = nStyle;
  593. }
  594. void CMainFrame::OnUpdateEditUndo(CCmdUI* pCmd)
  595. {
  596. CXTPControlGallery* pControlUndo = DYNAMIC_DOWNCAST(CXTPControlGallery, CXTPControl::FromUI(pCmd));
  597. if (pControlUndo)
  598. {
  599. pCmd->Enable(TRUE);
  600. CXTPControlGalleryItems* pItems = pControlUndo->GetItems();
  601. pItems->RemoveAll();
  602. int nCount = RAND_S() % 20 + 3;
  603. for (int i = 0; i < nCount; i++)
  604. {
  605. CString str;
  606. str.Format(_T("Undo String %i"), i + 1);
  607. pItems->AddItem(new CGalleryItemUndo(str), i);
  608. }
  609. pControlUndo->OnSelectedItemChanged();
  610. pControlUndo->SetHeight(pItems->GetItemSize().cy * nCount + 2);
  611. }
  612. else
  613. {
  614. pCmd->Enable();
  615. }
  616. }
  617. void CMainFrame::OnEditUndo(NMHDR* pNMHDR, LRESULT* pResult)
  618. {
  619. CXTPControlGallery* pControlUndo = DYNAMIC_DOWNCAST(CXTPControlGallery, ((NMXTPCONTROL*)pNMHDR)->pControl);
  620. if (pControlUndo)
  621. {
  622. CString str;
  623. str.Format(_T("Undo last %i actions"), pControlUndo->GetSelectedItem() + 1);
  624. AfxMessageBox(str);
  625. }
  626. *pResult = 1; // Handled;
  627. }
  628. void CMainFrame::OnUpdateSelectorText(CCmdUI* pCmdUI)
  629. {
  630. CXTPControlGallery* pControl =  DYNAMIC_DOWNCAST(CXTPControlGallery, CXTPControl::FromUI(pCmdUI));
  631. if (pControl)
  632. {
  633. pControl->SetCheckedItem(m_clr);
  634. }
  635. pCmdUI->Enable(TRUE);
  636. }
  637. void CMainFrame::OnSelectorText(NMHDR* pNMHDR, LRESULT* pResult)
  638. {
  639. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  640. CXTPControlGallery* pControl = DYNAMIC_DOWNCAST(CXTPControlGallery, tagNMCONTROL->pControl);
  641. if (pControl)
  642. {
  643. CXTPControlGalleryItem* pItem = pControl->GetItem(pControl->GetSelectedItem());
  644. if (pItem)
  645. {
  646. m_clr = (COLORREF)pItem->GetID();
  647. }
  648. *pResult = TRUE; // Handled
  649. }
  650. *pResult = 1;
  651. }