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

对话框与窗口

开发平台:

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 "CustomThemes.h"
  22. #include "MainFrm.h"
  23. #include "CustomControls.h"
  24. #include "Themes.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMainFrame
  32. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  33. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  34. ON_WM_CREATE()
  35. ON_COMMAND_RANGE(ID_SCROLL_ITEM1, ID_MULTICOLUMN_COLUMN2, OnScrollItem)
  36. ON_COMMAND_RANGE(ID_BUTTON32799, ID_BUTTON32818, OnScrollItem)
  37. ON_COMMAND_RANGE(ID_BACK, ID_VIEWS, OnScrollItem)
  38. ON_UPDATE_COMMAND_UI_RANGE(ID_THEME_DEFAULT, ID_THEME_RIBBON, OnUpdateTheme)
  39. ON_COMMAND_RANGE(ID_THEME_DEFAULT, ID_THEME_RIBBON, OnSwitchTheme)
  40. ON_COMMAND(ID_THEME_CUSTOM, OnThemeCustom)
  41. ON_COMMAND(ID_VIEW_OFFICE2007FRAME, OnViewOffice2007Frame)
  42. ON_UPDATE_COMMAND_UI(ID_VIEW_OFFICE2007FRAME, OnUpdateViewOffice2007Frame)
  43. ON_COMMAND(ID_VIEW_TEXTBELOWICONS, OnTextBelow)
  44. ON_UPDATE_COMMAND_UI(ID_VIEW_TEXTBELOWICONS, OnUpdateTextBelow)
  45. ON_COMMAND(ID_VIEW_RIGHTTOLEFT, OnOptionsRighttoleft)
  46. ON_UPDATE_COMMAND_UI(ID_VIEW_RIGHTTOLEFT, OnUpdateOptionsRighttoleft)
  47. ON_COMMAND_EX(ID_VIEW_MESSAGE_BAR, CFrameWnd::OnBarCheck)
  48. ON_UPDATE_COMMAND_UI(ID_VIEW_MESSAGE_BAR, CFrameWnd::OnUpdateControlBarMenu)
  49. ON_WM_CLOSE()
  50. ON_COMMAND_RANGE(ID_SAVEAS_XML, ID_SAVEAS_BINARY, OnSaveAs)
  51. ON_UPDATE_COMMAND_UI_RANGE(ID_SAVEAS_XML, ID_SAVEAS_BINARY, OnUpdateSaveAs)
  52. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  53. ON_XTP_EXECUTE(ID_EDIT_STATE, OnEditState)
  54. ON_UPDATE_COMMAND_UI(ID_EDIT_STATE, OnUpdateEditState)
  55. ON_XTP_EXECUTE(ID_FILE_NEW, OnFileNew)
  56. ON_XTP_CREATECONTROL()
  57. ON_XTP_CREATECOMMANDBAR()
  58. ON_XTP_EXECUTE_RANGE(ID_TASKPANEL_NEWDOCUMENT, ID_TASKPANEL_SEARCH, OnTaskPanelCaption)
  59. ON_UPDATE_COMMAND_UI_RANGE(ID_TASKPANEL_NEWDOCUMENT, ID_TASKPANEL_SEARCH, OnUpdateTaskPanelCaption)
  60. ON_MESSAGE(WM_XTP_CONTROLRBUTTONUP, OnControlRButtonUp)
  61. ON_XTP_EXECUTE(ID_COMBO_DATE, OnComboDate)
  62. ON_UPDATE_COMMAND_UI(ID_COMBO_DATE, OnUpdateComboDate)
  63. END_MESSAGE_MAP()
  64. static UINT indicators[] =
  65. {
  66. ID_SEPARATOR,           // status line indicator
  67. ID_INDICATOR_CAPS,
  68. ID_INDICATOR_NUM,
  69. ID_INDICATOR_SCRL,
  70. };
  71. static UINT uHideCmds[] =
  72. {
  73. ID_FILE_CLOSE,
  74. ID_FILE_SAVE_AS,
  75. ID_FILE_PRINT_PREVIEW,
  76. ID_FILE_PRINT_SETUP,
  77. ID_WINDOW_CASCADE,
  78. ID_WINDOW_TILE_HORZ,
  79. ID_WINDOW_ARRANGE,
  80. ID_SCROLL_ITEM21,
  81. ID_SCROLL_ITEM22,
  82. ID_SCROLL_ITEM23,
  83. ID_SCROLL_ITEM24,
  84. ID_SCROLL_ITEM25,
  85. ID_SCROLL_ITEM26
  86. };
  87. LPCTSTR lpszProfileName = _T("CommandBars_ver13");
  88. #define IDR_COLORTEXT_POPUP 1000
  89. #define IDR_COLORBACK_POPUP 1001
  90. // CMainFrame construction/destruction
  91. CMainFrame::CMainFrame()
  92. {
  93. m_nState = 0;
  94. m_nIDSaveAs = ID_SAVEAS_XML;
  95. m_dt = COleDateTime::GetCurrentTime();
  96. m_nCurrentTheme = ID_THEME_OFFICE_XP;
  97. m_bOffice2007Frame = 2;
  98. }
  99. CMainFrame::~CMainFrame()
  100. {
  101. }
  102. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  103. {
  104. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  105. return -1;
  106. if (!m_wndStatusBar.Create(this) ||
  107. !m_wndStatusBar.SetIndicators(indicators,
  108. sizeof(indicators)/sizeof(UINT)))
  109. {
  110. TRACE0("Failed to create status barn");
  111. return -1;      // fail to create
  112. }
  113. // Initialize command bars.  Command bars must be created and initialized
  114. // after all standard MFC control bars have been created.
  115. if (!InitCommandBars())
  116. return -1;
  117. // Set the default theme to Office XP.
  118. CXTPPaintManager::SetTheme(xtpThemeOfficeXP);
  119. // Get a pointer to the command bars object.
  120. CXTPCommandBars* pCommandBars = GetCommandBars();
  121. // create the menubar.
  122. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_CUSTOMTYPE);
  123. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage);
  124. // create the standard toolbar.
  125. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  126. if (!pStandardBar || !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  127. {
  128. TRACE0("Failed to create toolbarn");
  129. return -1;
  130. }
  131. // create the left docked toolbar.
  132. CXTPToolBar* pLeftBar = (CXTPToolBar*)pCommandBars->Add(_T("Left Bar"), xtpBarLeft);
  133. if (!pLeftBar || !pLeftBar->LoadToolBar(IDR_LEFT))
  134. {
  135. TRACE0("Failed to create toolbarn");
  136. return -1;
  137. }
  138. // create the combo box toolbar.
  139. CXTPToolBar* pComboBoxBar = (CXTPToolBar*)pCommandBars->Add(_T("ComboBox Bar"), xtpBarBottom);
  140. if (!pComboBoxBar || !pComboBoxBar->LoadToolBar(IDR_COMBOBOX_BAR))
  141. {
  142. TRACE0("Failed to create toolbarn");
  143. return -1;
  144. }
  145. // create the theme toolbar.
  146. CXTPToolBar* pThemeBar = (CXTPToolBar*)pCommandBars->Add(_T("Theme Bar"), xtpBarTop);
  147. if (!pThemeBar || !pThemeBar->LoadToolBar(IDR_SWITCH))
  148. {
  149. TRACE0("Failed to create toolbarn");
  150. return -1;
  151. }
  152. // create the custom toolbar.
  153. CXTPToolBar* pCustomBar = (CXTPToolBar*)pCommandBars->Add(_T("Custom Bar"), xtpBarTop);
  154. if (!pCustomBar || !pCustomBar->LoadToolBar(IDR_CUSTOM))
  155. {
  156. TRACE0("Failed to create toolbarn");
  157. return -1;
  158. }
  159. // Dock to the right of...
  160. DockRightOf(pCustomBar, pStandardBar);
  161. // create the 24 bit icon toolbar.
  162. CXTPToolBar* p24BitIconBar = (CXTPToolBar*)pCommandBars->Add(_T("26bit Icons Bar"), xtpBarTop);
  163. if (!p24BitIconBar || !p24BitIconBar->LoadToolBar(IDR_EXPLORER_BAR))
  164. {
  165. TRACE0("Failed to create toolbarn");
  166. return -1;
  167. }
  168. // Dock to the right of...
  169. DockRightOf(p24BitIconBar, pThemeBar);
  170. CXTPDialogBar* pBar = (CXTPDialogBar*)pCommandBars->Add(_T("Task Panel"), xtpBarRight, RUNTIME_CLASS(CXTPDialogBar));
  171. pBar->SetBarID(200);
  172. pBar->EnableDocking(xtpFlagAlignAny|xtpFlagFloating|xtpFlagStretched);
  173. pBar->SetCaption(_T("&New Document"));
  174. pBar->ModifyStyle(0, WS_CLIPCHILDREN|WS_CLIPSIBLINGS);
  175. m_wndTaskPanel.Create(pBar);
  176. pBar->SetChild(&m_wndTaskPanel);
  177. pBar->SetCaptionPopup(IDR_MENU_TASKPANEL);
  178. m_wndTaskPanel.SetTheme(XTPPaintManager()->BaseTheme());
  179. pCommandBars->GetCommandBarsOptions()->animationType = xtpAnimateWindowsDefault;
  180. pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  181. CXTPControlWindowList::m_bShowRadioButtons = TRUE;
  182. pCommandBars->GetContextMenus()->Add(IDR_CONTEXT_MENU);
  183. pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME);
  184. // Load the saved toolbar layout.
  185. LoadCommandBars(lpszProfileName);
  186. if (!m_wndMessageBar.Create(GetCommandBars()))
  187. return -1;
  188. m_wndMessageBar.AddButton(SC_CLOSE, NULL, _T("Close Message Bar"));
  189. m_wndMessageBar.AddButton(XTP_ID_CUSTOMIZE, _T("Options..."));
  190. m_wndMessageBar.SetMessage(_T("Security Warning. Certain content has been disabled"));
  191. m_wndMessageBar.ShowWindow(SW_HIDE);
  192. // Initialize intelligent menus.
  193. pCommandBars->GetCommandBarsOptions()->bAlwaysShowFullMenus = FALSE;
  194. pCommandBars->HideCommands(uHideCmds, _countof(uHideCmds));
  195. // Toggle floating by double click
  196. pCommandBars->GetCommandBarsOptions()->bDblClickFloat = TRUE;
  197. pCommandBars->GetToolTipContext()->SetStyle(xtpToolTipOffice);
  198. // Change size of popup icons.
  199. // pCommandBars->GetCommandBarsOptions()->szPopupIcons = CSize(20, 20);
  200. m_wndClient.Attach(this);
  201. return 0;
  202. }
  203. void CMainFrame::DockRightOf(CXTPToolBar* pBarToDock, CXTPToolBar* pBarOnLeft)
  204. {
  205. RecalcLayout(TRUE);
  206. CXTPWindowRect rcBar(pBarOnLeft);
  207. rcBar.OffsetRect(rcBar.Width(), 0);
  208. GetCommandBars()->DockCommandBar(pBarToDock, rcBar, pBarOnLeft->GetDockBar());
  209. }
  210. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  211. {
  212. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  213. return FALSE;
  214. cs.lpszClass = _T("XTPMainFrame");
  215. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  216. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  217. return TRUE;
  218. }
  219. // CMainFrame diagnostics
  220. #ifdef _DEBUG
  221. void CMainFrame::AssertValid() const
  222. {
  223. CMDIFrameWnd::AssertValid();
  224. }
  225. void CMainFrame::Dump(CDumpContext& dc) const
  226. {
  227. CMDIFrameWnd::Dump(dc);
  228. }
  229. #endif //_DEBUG
  230. // CMainFrame message handlers
  231. void CMainFrame::SetCustomTheme(CXTPPaintManager* pTheme)
  232. {
  233. CXTPPaintManager::SetCustomTheme(pTheme);
  234. if ((pTheme->BaseTheme() == xtpThemeOffice2007 || pTheme->BaseTheme() == xtpThemeRibbon) &&
  235. (m_bOffice2007Frame == 2 || m_bOffice2007Frame == 1))
  236. {
  237. EnableOffice2007Frame(GetCommandBars());
  238. }
  239. else
  240. {
  241. EnableOffice2007Frame(0);
  242. }
  243. m_wndTaskPanel.SetTheme(XTPPaintManager()->BaseTheme());
  244. GetCommandBars()->RedrawCommandBars();
  245. }
  246. void CMainFrame::OnThemeCustom()
  247. {
  248. }
  249. void CMainFrame::OnUpdateTheme(CCmdUI* pCmdUI)
  250. {
  251. pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrentTheme ? TRUE : FALSE);
  252. }
  253. void CMainFrame::OnSwitchTheme(UINT nTheme)
  254. {
  255. switch (nTheme)
  256. {
  257. case ID_THEME_DEFAULT: SetCustomTheme(new CXTPDefaultTheme()); break;
  258. case ID_THEME_OFFICE_XP: SetCustomTheme(new CXTPOfficeTheme()); break;
  259. case ID_THEME_OFFICE_2003: SetCustomTheme(new CXTPOffice2003Theme()); break;
  260. case ID_THEME_WINDOWS_XP: SetCustomTheme(new CXTPNativeXPTheme()); break;
  261. case ID_THEME_RIBBON: SetCustomTheme(new CXTPRibbonTheme()); break;
  262. case ID_THEME_OFFICE2007: SetCustomTheme(new CXTPOffice2007Theme()); break;
  263. case ID_THEME_VISUALSTUDIO2008: SetCustomTheme(new CXTPVisualStudio2008Theme()); break;
  264. case ID_THEME_MAC: SetCustomTheme(new CCustomMacTheme()); break;
  265. case ID_THEME_GRAY: SetCustomTheme(new CCustomGrayTheme()); break;
  266. case ID_THEME_ICY: SetCustomTheme(new CCustomIcyTheme()); break;
  267. case ID_THEME_GRAD: SetCustomTheme(new CCustomGradientTheme()); break;
  268. case ID_THEME_BEVEL: SetCustomTheme(new CCustomBevelTheme()); break;
  269. case ID_THEME_FANCY: SetCustomTheme(new CCustomFancyTheme()); break;
  270. case ID_THEME_ACD: SetCustomTheme(new CCustomBackgroundTheme()); break;
  271. }
  272. m_nCurrentTheme = nTheme;
  273. }
  274. void CMainFrame::OnViewOffice2007Frame()
  275. {
  276. m_bOffice2007Frame = m_bOffice2007Frame + 1;
  277. if (m_bOffice2007Frame == 3) m_bOffice2007Frame = 0;
  278. OnSwitchTheme(m_nCurrentTheme);
  279. }
  280. void CMainFrame::OnUpdateViewOffice2007Frame(CCmdUI* pCmdUI)
  281. {
  282. if (m_nCurrentTheme == ID_THEME_RIBBON || m_nCurrentTheme == ID_THEME_OFFICE2007)
  283. {
  284. pCmdUI->Enable(TRUE);
  285. pCmdUI->SetCheck(m_bOffice2007Frame);
  286. }
  287. else
  288. {
  289. pCmdUI->Enable(FALSE);
  290. }
  291. }
  292. void CMainFrame::OnScrollItem(UINT)
  293. {
  294. // TODO: Add your command handler code here
  295. }
  296. BOOL GetAppDataFolder(CString& strAppDataFolder)
  297. {
  298. OSVERSIONINFO versionInfo = { sizeof(OSVERSIONINFO) };
  299. if (!(GetVersionEx(&versionInfo) && versionInfo.dwPlatformId >= VER_PLATFORM_WIN32_NT && versionInfo.dwMajorVersion >= 5))
  300. return FALSE;
  301. LPITEMIDLIST pidlAppData = NULL;
  302. IMalloc * pMalloc = NULL;
  303. BOOL bResult = FALSE;
  304. HRESULT hr = SHGetMalloc(&pMalloc);
  305. if (SUCCEEDED(hr))
  306. {
  307. TCHAR   szPath[MAX_PATH];
  308. if (SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidlAppData) == NOERROR )
  309. {
  310. if (SHGetPathFromIDList( pidlAppData, szPath))
  311. {
  312. strAppDataFolder = szPath;
  313. bResult = TRUE;
  314. }
  315. }
  316. pMalloc->Free(pidlAppData);
  317. pMalloc->Release();
  318. }
  319. return TRUE;
  320. }
  321. void CMainFrame::OnClose()
  322. {
  323. CString strAppDataFolder;
  324. if (GetAppDataFolder(strAppDataFolder))
  325. {
  326. CreateDirectory(strAppDataFolder + _T("\") + AfxGetApp()->m_pszAppName, NULL);
  327. // Set customization path as "Documents and SettingsuserApplication DataCustomThemesCommandBars_ver6"
  328. GetCommandBars()->SetCustomizationDataFileName(strAppDataFolder + _T("\") + AfxGetApp()->m_pszAppName + _T("\") + lpszProfileName);
  329. }
  330. SaveCommandBars(lpszProfileName);
  331. CMDIFrameWnd::OnClose();
  332. }
  333. void CMainFrame::OnCustomize()
  334. {
  335. CXTPCustomizeSheet cs(GetCommandBars());
  336. CXTPCustomizeKeyboardPage pageKeyboard(&cs);
  337. pageKeyboard.AddCategories(IDR_CUSTOMTYPE);
  338. cs.AddPage(&pageKeyboard);
  339. CXTPCustomizeMenusPage pageMenus(&cs);
  340. cs.AddPage(&pageMenus);
  341. CXTPCustomizeOptionsPage pageOptions(&cs);
  342. cs.AddPage(&pageOptions);
  343. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  344. pCommands->AddCategories(IDR_CUSTOMTYPE);
  345. pCommands->GetControls(_T("File"))->Add(xtpControlButton, ID_FILE_OPEN, _T(""), 1);
  346. pCommands->AddToolbarCategory(_T("Themes"), IDR_SWITCH);
  347. pCommands->InsertAllCommandsCategory();
  348. pCommands->InsertBuiltInMenus(IDR_CUSTOMTYPE);
  349. pCommands->InsertNewMenuCategory();
  350. CXTPControls* pControls = pCommands->GetControls(_T("Test"));
  351. ASSERT(pControls);
  352. pControls->Add(xtpControlButton, ID_FILE_NEW);
  353. pControls->Add(xtpControlPopup, ID_TOOLS_HEX);
  354. pControls->Add(xtpControlButtonPopup, ID_TOOLS_HEX);
  355. pControls->Add(xtpControlSplitButtonPopup, ID_TOOLS_HEX);
  356. CXTPControl* pControlState = GetCommandBars()->FindControl(xtpControlComboBox, ID_EDIT_STATE, FALSE, TRUE);
  357. if (pControlState) pControls->AddClone(pControlState, 4);
  358. CXTPControl* pControlNew = GetCommandBars()->FindControl(xtpControlEdit, ID_FILE_NEW, FALSE, TRUE);
  359. if (pControlNew) pControls->AddClone(pControlNew, 6);
  360. cs.DoModal();
  361. }
  362. int CMainFrame::OnCreateCommandBar(LPCREATEBARSTRUCT lpCreatePopup)
  363. {
  364. if (lpCreatePopup->bTearOffBar && (lpCreatePopup->nID == IDR_COLORTEXT_POPUP || lpCreatePopup->nID == IDR_COLORBACK_POPUP))
  365. {
  366. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreatePopup->pCommandBar);
  367. ASSERT(pToolBar);
  368. // Prevent docking.
  369. pToolBar->EnableDocking(xtpFlagFloating);
  370. // Prevent customization
  371. pToolBar->EnableCustomization(FALSE);
  372. return TRUE;
  373. }
  374. return FALSE;
  375. }
  376. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  377. {
  378. if (lpCreateControl->bToolBar == FALSE)
  379. {
  380. if (lpCreateControl->controlType == xtpControlPopup && lpCreateControl->strCaption == _T("&Open..."))
  381. {
  382. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  383. lpCreateControl->nID = ID_FILE_OPEN;
  384. return TRUE;
  385. }
  386. if (lpCreateControl->controlType == xtpControlButton && lpCreateControl->nID == ID_TOOLS_HEX)
  387. {
  388. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  389. return TRUE;
  390. }
  391. if (lpCreateControl->nID == ID_MULTICOLUMN_COLUMN1 || lpCreateControl->nID == ID_MULTICOLUMN_COLUMN2)
  392. {
  393. lpCreateControl->pControl = new CXTPControlLabel();
  394. lpCreateControl->pControl->SetItemDefault(TRUE);
  395. lpCreateControl->pControl->SetStyle(xtpButtonCaption);
  396. return TRUE;
  397. }
  398. if (lpCreateControl->controlType == xtpControlButton && lpCreateControl->nID == ID_EDIT_FIND)
  399. {
  400. CXTPControlComboBox* pComboFind = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
  401. pComboFind->SetDropDownListStyle();
  402. pComboFind->SetEditHint(_T("Click to find string"));
  403. pComboFind->AddString(_T("Line1"));
  404. pComboFind->AddString(_T("Line2"));
  405. pComboFind->AddString(_T("Line3"));
  406. pComboFind->SetWidth(150);
  407. pComboFind->SetCaption(_T("Find"));
  408. pComboFind->SetStyle(xtpComboLabel);
  409. lpCreateControl->pControl = pComboFind;
  410. return TRUE;
  411. }
  412. if (lpCreateControl->nID == ID_PARA_INDENT)
  413. {
  414. CXTPControlEdit* pControl = new CXTPControlEdit();
  415. pControl->SetWidth(133);
  416. pControl->ShowSpinButtons();
  417. lpCreateControl->pControl = pControl;
  418. return TRUE;
  419. }
  420. }
  421. else
  422. {
  423. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
  424. if (!pToolBar)
  425. return FALSE;
  426. if (lpCreateControl->nID == ID_FILE_PRINT_EX && pToolBar->GetBarID() == IDR_LEFT)
  427. {
  428. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  429. lpCreateControl->buttonStyle = xtpButtonIconAndCaption;
  430. return TRUE;
  431. }
  432. if (lpCreateControl->nID == IDR_MENU_POPUP && pToolBar->GetBarID() == IDR_LEFT)
  433. {
  434. lpCreateControl->controlType = xtpControlPopup;
  435. lpCreateControl->buttonStyle = xtpButtonIconAndCaption;
  436. return TRUE;
  437. }
  438. if (lpCreateControl->nID == ID_TOOLS_HEX && pToolBar->GetBarID() == IDR_MAINFRAME)
  439. {
  440. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  441. return TRUE;
  442. }
  443. if (lpCreateControl->nID == ID_FILE_NEW && pToolBar->GetBarID() == IDR_COMBOBOX_BAR)
  444. {
  445. lpCreateControl->controlType = xtpControlEdit;
  446. return TRUE;
  447. }
  448. if (lpCreateControl->nID == ID_THEME_CUSTOM)
  449. {
  450. lpCreateControl->buttonStyle = xtpButtonIconAndCaption;
  451. lpCreateControl->controlType = xtpControlPopup;
  452. return TRUE;
  453. }
  454. if (lpCreateControl->nID == ID_VIEW_OFFICE2007FRAME)
  455. {
  456. lpCreateControl->controlType = xtpControlCheckBox;
  457. return TRUE;
  458. }
  459. if (pToolBar->GetBarID() == IDR_SWITCH && (lpCreateControl->nID >= ID_THEME_DEFAULT && lpCreateControl->nID <= ID_THEME_RIBBON))
  460. {
  461. lpCreateControl->buttonStyle = xtpButtonCaption;
  462. return TRUE;
  463. }
  464. if (lpCreateControl->nID == ID_EDIT_FIND && pToolBar->GetBarID() == IDR_COMBOBOX_BAR)
  465. {
  466. CXTPControlComboBox* pComboFind = new CXTPControlComboBox(GetCommandBars());
  467. pComboFind->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
  468. //pComboFind->SetListIconId(ID_FILE_NEW);
  469. pComboFind->SetDropDownListStyle();
  470. pComboFind->SetEditHint(_T("Click to find string"));
  471. pComboFind->AddString(_T("Line1"));
  472. pComboFind->AddString(_T("Line2"));
  473. pComboFind->AddString(_T("Line3"));
  474. pComboFind->SetWidth(150);
  475. pComboFind->SetStyle(xtpButtonIconAndCaption);
  476. lpCreateControl->pControl = pComboFind;
  477. return TRUE;
  478. }
  479. if (lpCreateControl->nID == ID_COMBO_MASKED)
  480. {
  481. CXTPControlComboBox* pComboMasked = (CXTPControlComboBox*)CControlComboBoxEx::CreateObject();
  482. //pComboMasked->GetCommandBar()->SetCommandBars(GetCommandBars()); // Require to find Site.
  483. //pComboMasked->ModifyListBoxStyle(0, LBS_OWNERDRAWFIXED | LBS_HASSTRINGS);
  484. pComboMasked->SetDropDownListStyle();
  485. pComboMasked->AddString(_T("12:00:20:30"));
  486. pComboMasked->AddString(_T("11:03:12:30"));
  487. pComboMasked->AddString(_T("00:00:12:30"));
  488. pComboMasked->AddString(_T("10:00:30:30"));
  489. pComboMasked->SetWidth(130);
  490. pComboMasked->SetStyle(xtpComboLabel);
  491. pComboMasked->SetFlags(xtpFlagManualUpdate);
  492. lpCreateControl->pControl = pComboMasked;
  493. return TRUE;
  494. }
  495. if (lpCreateControl->nID == ID_COMBO_OWNERDRAW)
  496. {
  497. CXTPControlComboBox* pComboCustomDraw = new CControlComboBoxCustomDraw(GetCommandBars());
  498. pComboCustomDraw->SetDropDownListStyle();
  499. pComboCustomDraw->SetWidth(130);
  500. pComboCustomDraw->SetDropDownWidth(230);
  501. pComboCustomDraw->SetStyle(xtpComboLabel);
  502. lpCreateControl->pControl = pComboCustomDraw;
  503. return TRUE;
  504. }
  505. if (lpCreateControl->nID == ID_COMBO_POPUP)
  506. {
  507. CXTPControlComboBox* pComboPopup = (CXTPControlComboBox*)CControlComboBoxPopup::CreateObject();
  508. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  509. CMenu menu;
  510. menu.LoadMenu(IDR_MENU_SAVEAS);
  511. pPopupBar->LoadMenu(menu.GetSubMenu(0));
  512. pComboPopup->SetCommandBar(pPopupBar);
  513. pPopupBar->InternalRelease();
  514. pComboPopup->SetWidth(130);
  515. pComboPopup->SetStyle(xtpComboLabel);
  516. pComboPopup->SetFlags(xtpFlagManualUpdate);
  517. lpCreateControl->pControl = pComboPopup;
  518. return TRUE;
  519. }
  520. if (lpCreateControl->nID == ID_COMBO_DATE)
  521. {
  522. CXTPControlComboBox* pCombo = new CControlComboBoxDatePicker();
  523. pCombo->SetWidth(100);
  524. lpCreateControl->pControl = pCombo;
  525. return TRUE;
  526. }
  527. if (lpCreateControl->nID == ID_EDIT_STATE && pToolBar->GetBarID() == IDR_COMBOBOX_BAR)
  528. {
  529. CXTPControlComboBox* pComboState = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
  530. pComboState->AddString(_T("Debug"));
  531. pComboState->AddString(_T("Release"));
  532. pComboState->AddString(_T("Configuration Manager"));
  533. pComboState->SetDropDownWidth(150);
  534. lpCreateControl->pControl = pComboState;
  535. return TRUE;
  536. }
  537. if (lpCreateControl->nID == ID_COMBO_DISABLED && pToolBar->GetBarID() == IDR_COMBOBOX_BAR)
  538. {
  539. CXTPControlComboBox* pComboDisable = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
  540. pComboDisable->SetStyle(xtpComboLabel);
  541. lpCreateControl->pControl = pComboDisable;
  542. return TRUE;
  543. }
  544. if (lpCreateControl->nID == ID_BUTTONLINE && pToolBar->GetBarID() == IDR_CUSTOM)
  545. {
  546. CXTPControlPopup* pButtonLine = CXTPControlPopup::CreateControlPopup(xtpControlButtonPopup);
  547. pButtonLine->SetFlags(xtpFlagManualUpdate);
  548. CXTPPopupBar* pLineBar = (CXTPPopupBar*)CXTPPopupToolBar::CreateObject();
  549. pLineBar->GetControls()->Add(new CControlButtonLine(0.25), 0, _T(""), -1, FALSE);
  550. pLineBar->GetControls()->Add(new CControlButtonLine(0.5), 0, _T(""), -1, FALSE);
  551. pLineBar->GetControls()->Add(new CControlButtonLine(0.75), 0, _T(""), -1, FALSE);
  552. pLineBar->GetControls()->Add(new CControlButtonLine(1), 0, _T(""), -1, FALSE);
  553. pLineBar->GetControls()->Add(new CControlButtonLine(1.5), 0, _T(""), -1, FALSE);
  554. pLineBar->GetControls()->Add(new CControlButtonLine(2.25), 0, _T(""), -1, FALSE);
  555. pLineBar->GetControls()->Add(new CControlButtonLine(3), 0, _T(""), -1, FALSE);
  556. pLineBar->GetControls()->Add(new CControlButtonLine(4.5), 0, _T(""), -1, FALSE);
  557. pLineBar->GetControls()->Add(new CControlButtonLine(6), 0, _T(""), -1, FALSE);
  558. pButtonLine->SetCommandBar(pLineBar);
  559. pLineBar->InternalRelease();
  560. lpCreateControl->pControl = pButtonLine;
  561. return TRUE;
  562. }
  563. if (lpCreateControl->nID == ID_BUTTONSTYLE && pToolBar->GetBarID() == IDR_CUSTOM)
  564. {
  565. CXTPControlPopup* pButtonStyle = CXTPControlPopup::CreateControlPopup(xtpControlButtonPopup);
  566. pButtonStyle->SetFlags(xtpFlagManualUpdate);
  567. CXTPPopupBar* pStyleBar = (CXTPPopupBar*)CXTPPopupToolBar::CreateObject();
  568. pStyleBar->GetControls()->Add(new CControlButtonStyle(0), 0, _T(""), -1, FALSE);
  569. pStyleBar->GetControls()->Add(new CControlButtonStyle(1), 0, _T(""), -1, FALSE);
  570. pStyleBar->GetControls()->Add(new CControlButtonStyle(2), 0, _T(""), -1, FALSE);
  571. pStyleBar->GetControls()->Add(new CControlButtonStyle(3), 0, _T(""), -1, FALSE);
  572. pStyleBar->GetControls()->Add(new CControlButtonStyle(4), 0, _T(""), -1, FALSE);
  573. pStyleBar->GetControls()->Add(new CControlButtonStyle(5), 0, _T(""), -1, FALSE);
  574. pButtonStyle->SetCommandBar(pStyleBar);
  575. pStyleBar->InternalRelease();
  576. lpCreateControl->pControl = pButtonStyle;
  577. return TRUE;
  578. }
  579. if (lpCreateControl->nID == ID_BUTTONARROW && pToolBar->GetBarID() == IDR_CUSTOM)
  580. {
  581. CXTPControlPopup* pButtonArrow = CXTPControlPopup::CreateControlPopup(xtpControlButtonPopup);
  582. pButtonArrow->SetFlags(xtpFlagManualUpdate);
  583. CXTPPopupBar* pArrowBar = (CXTPPopupBar*)CXTPPopupToolBar::CreateObject();
  584. pArrowBar->GetControls()->Add(new CControlButtonArrow(1), 0, _T(""), -1, FALSE);
  585. pArrowBar->GetControls()->Add(new CControlButtonArrow(2), 0, _T(""), -1, FALSE);
  586. pArrowBar->GetControls()->Add(new CControlButtonArrow(3), 0, _T(""), -1, FALSE);
  587. pArrowBar->GetControls()->Add(new CControlButtonArrow(4), 0, _T(""), -1, FALSE);
  588. CXTPControlButton* pOther =
  589. (CXTPControlButton*)pArrowBar->GetControls()->Add(new CControlButtonArrow(0), 0, _T(""), -1, FALSE);
  590. pOther->SetCaption(_T("Other Arrow..."));
  591. pOther->SetBeginGroup(TRUE);
  592. pOther->SetStyle(xtpButtonCaption);
  593. pButtonArrow->SetCommandBar(pArrowBar);
  594. pArrowBar->InternalRelease();
  595. lpCreateControl->pControl = pButtonArrow;
  596. return TRUE;
  597. }
  598. if (lpCreateControl->nID == ID_BUTTON_TEXT && pToolBar->GetBarID() == IDR_CUSTOM)
  599. {
  600. CXTPControlPopupColor* pPopupColor = new CXTPControlPopupColor();
  601. CXTPPopupBar* pColorBar = (CXTPPopupBar*)CXTPPopupToolBar::CreateObject();
  602. CXTPControlButtonColor* pButtonAutomatic = (CXTPControlButtonColor*)pColorBar->GetControls()->Add(new CXTPControlButtonColor(), ID_TEXT_AUTO);
  603. pButtonAutomatic->SetColor(GetSysColor(COLOR_BTNTEXT));
  604. pColorBar->GetControls()->Add(new CXTPControlColorSelector(), ID_SELECTOR_TEXT);
  605. pColorBar->GetControls()->Add(new CXTPControlButtonColor(), ID_TEXT_MORE);
  606. pPopupColor->SetCommandBar(pColorBar);
  607. pColorBar->InternalRelease();
  608. pColorBar->SetTearOffPopup(_T("Text Color"), IDR_COLORTEXT_POPUP, 0);
  609. pColorBar->EnableCustomization(FALSE);
  610. lpCreateControl->pControl = pPopupColor;
  611. return TRUE;
  612. }
  613. if (lpCreateControl->nID == ID_BUTTON_BACK && pToolBar->GetBarID() == IDR_CUSTOM)
  614. {
  615. CXTPControlPopupColor* pPopupColorBack = new CXTPControlPopupColor();
  616. CXTPPopupBar* pColorBar = (CXTPPopupBar*)CXTPPopupToolBar::CreateObject();
  617. CXTPControlButtonColor* pButtonAutomatic = (CXTPControlButtonColor*)pColorBar->GetControls()->Add(new CXTPControlButtonColor(), ID_BACK_NONE);
  618. pButtonAutomatic->SetColor(GetSysColor(COLOR_WINDOW));
  619. pColorBar->GetControls()->Add(new CXTPControlColorSelector(), ID_SELECTOR_BACK);
  620. pColorBar->GetControls()->Add(new CXTPControlButtonColor(), ID_BACK_MORE);
  621. pPopupColorBack->SetCommandBar(pColorBar);
  622. pColorBar->InternalRelease();
  623. pColorBar->SetTearOffPopup(_T("Back Color"), IDR_COLORBACK_POPUP, 0);
  624. pColorBar->EnableCustomization(FALSE);
  625. lpCreateControl->pControl = pPopupColorBack;
  626. return TRUE;
  627. }
  628. }
  629. return FALSE;
  630. }
  631. void CMainFrame::OnEditState(NMHDR* pNMHDR, LRESULT* pResult)
  632. {
  633. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  634. CXTPControlComboBox* pControl = (CXTPControlComboBox*)tagNMCONTROL->pControl;
  635. if (pControl->GetType() == xtpControlComboBox)
  636. {
  637. int nState = pControl->GetCurSel();
  638. if (nState != 2)
  639. {
  640. m_nState = nState;
  641. }
  642. else
  643. {
  644. MessageBox(_T("Configuration Manager"));
  645. pControl->SetCurSel(m_nState);
  646. }
  647. *pResult = TRUE; // Handled
  648. }
  649. }
  650. void CMainFrame::OnUpdateEditState(CCmdUI* pCmdUI)
  651. {
  652. CXTPControlComboBox* pStateCombo = DYNAMIC_DOWNCAST(CXTPControlComboBox, CXTPControl::FromUI(pCmdUI));
  653. if (pStateCombo && !pStateCombo->HasFocus())
  654. {
  655. pStateCombo->SetCurSel(m_nState);
  656. }
  657. pCmdUI->Enable(TRUE);
  658. }
  659. void CMainFrame::OnFileNew(NMHDR* pNMHDR, LRESULT* pResult)
  660. {
  661. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  662. CXTPControlComboBox* pControl = (CXTPControlComboBox*)tagNMCONTROL->pControl;
  663. if (pControl->GetType() == xtpControlEdit)
  664. {
  665. CString str = ((CXTPControlEdit*)pControl)->GetEditText();
  666. CDocument* pDocument = ((CCustomThemesApp*)AfxGetApp())->m_pDocTemplate->OpenDocumentFile(NULL);
  667. if (pDocument != NULL && str.GetLength() > 0)
  668. {
  669. pDocument->SetTitle(str);
  670. }
  671. *pResult = TRUE; // Handled
  672. }
  673. }
  674. BOOL CMainFrame::OnTaskPanelCaption(UINT /*nID*/, NMHDR* pNMHDR, LRESULT* /*pResult*/)
  675. {
  676. CXTPControl* pControl = ((NMXTPCONTROL*)pNMHDR)->pControl;
  677. CXTPDialogBar* pBar = DYNAMIC_DOWNCAST(CXTPDialogBar, GetCommandBars()->GetToolBar(200));
  678. ASSERT(pBar);
  679. pBar->SetCaption(pControl->GetCaption());
  680. return 1;
  681. }
  682. void CMainFrame::OnUpdateTaskPanelCaption(CCmdUI* pCmdUI)
  683. {
  684. pCmdUI->Enable(TRUE);
  685. CXTPDialogBar* pBar = DYNAMIC_DOWNCAST(CXTPDialogBar, GetCommandBars()->GetToolBar(200));
  686. ASSERT(pBar);
  687. CXTPControl* pControl = CXTPControl::FromUI(pCmdUI);
  688. if (pControl)
  689. {
  690. pCmdUI->SetCheck(pControl->GetCaption() == pBar->GetCaption()? TRUE: FALSE);
  691. }
  692. }
  693. void CMainFrame::OnTextBelow()
  694. {
  695. GetCommandBars()->GetCommandBarsOptions()->bShowTextBelowIcons =
  696. !GetCommandBars()->GetCommandBarsOptions()->bShowTextBelowIcons;
  697. // or
  698. // GetCommandBars()->GetAt(1)->ShowTextBelowIcons(TRUE);
  699. GetCommandBars()->RedrawCommandBars();
  700. }
  701. void CMainFrame::OnUpdateTextBelow(CCmdUI* pCmdUI)
  702. {
  703. pCmdUI->SetCheck(GetCommandBars()->GetCommandBarsOptions()->bShowTextBelowIcons);
  704. }
  705. void CMainFrame::OnSaveAs(UINT nID)
  706. {
  707. m_nIDSaveAs = nID;
  708. }
  709. void CMainFrame::OnUpdateSaveAs(CCmdUI* pCmdUI)
  710. {
  711. pCmdUI->SetCheck(pCmdUI->m_nID == m_nIDSaveAs? TRUE: FALSE);
  712. }
  713. LRESULT CMainFrame::OnControlRButtonUp(WPARAM, LPARAM lParam)
  714. {
  715. CXTPControl* pControl = (CXTPControl*)lParam;
  716. UNUSED_ALWAYS(pControl);
  717. return FALSE;
  718. }
  719. void CMainFrame::OnOptionsRighttoleft() 
  720. {
  721. if (GetExStyle() & WS_EX_LAYOUTRTL)
  722. {
  723. GetCommandBars()->SetLayoutRTL(FALSE);
  724. ModifyStyleEx(WS_EX_LAYOUTRTL, 0);
  725. }
  726. else
  727. {
  728. GetCommandBars()->SetLayoutRTL(TRUE);
  729. ModifyStyleEx(0, WS_EX_LAYOUTRTL);
  730. }
  731. }
  732. void CMainFrame::OnUpdateOptionsRighttoleft(CCmdUI* pCmdUI) 
  733. {
  734. if (XTPSystemVersion()->IsLayoutRTLSupported())
  735. {
  736. pCmdUI->SetCheck(GetExStyle() & WS_EX_LAYOUTRTL ? TRUE : FALSE);
  737. }
  738. else
  739. {
  740. pCmdUI->Enable(FALSE);
  741. }
  742. }
  743. void CMainFrame::OnComboDate(NMHDR* pNMHDR, LRESULT* pResult)
  744. {
  745. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  746. CControlComboBoxDatePicker* pControl = DYNAMIC_DOWNCAST(CControlComboBoxDatePicker, tagNMCONTROL->pControl);
  747. if (pControl)
  748. {
  749. m_dt = pControl->GetDate();
  750. }
  751. }
  752. void CMainFrame::OnUpdateComboDate(CCmdUI* pCmdUI)
  753. {
  754. CControlComboBoxDatePicker* pControl = DYNAMIC_DOWNCAST(CControlComboBoxDatePicker, CXTPControl::FromUI(pCmdUI));
  755. if (pControl)
  756. {
  757. pControl->SetDate(m_dt);
  758. }
  759. pCmdUI->Enable(TRUE);
  760. }