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

对话框与窗口

开发平台:

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 "wordpad.h"
  22. #include "mainfrm.h"
  23. #include "wordpdoc.h"
  24. #include "wordpvw.h"
  25. #include "strings.h"
  26. #include "colorlis.h"
  27. #include "ControlSelector.h"
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char BASED_CODE THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CMainFrame
  34. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  35. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  36. //{{AFX_MSG_MAP(CMainFrame)
  37. ON_WM_CREATE()
  38. ON_WM_SYSCOLORCHANGE()
  39. ON_WM_SIZE()
  40. ON_WM_MOVE()
  41. ON_COMMAND(ID_HELP, OnHelpFinder)
  42. ON_WM_DROPFILES()
  43. ON_COMMAND(ID_CHAR_COLOR, OnCharColor)
  44. ON_COMMAND(ID_PEN_TOGGLE, OnPenToggle)
  45. ON_WM_FONTCHANGE()
  46. ON_WM_QUERYNEWPALETTE()
  47. ON_WM_PALETTECHANGED()
  48. ON_WM_DEVMODECHANGE()
  49. ON_COMMAND(ID_HELP_INDEX, OnHelpFinder)
  50. ON_WM_CLOSE()
  51. //}}AFX_MSG_MAP
  52. // Global help commands
  53. //  ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
  54. ON_COMMAND(ID_DEFAULT_HELP, OnHelpFinder)
  55. ON_UPDATE_COMMAND_UI(ID_VIEW_FORMATBAR, OnUpdateControlBarMenu)
  56. ON_UPDATE_COMMAND_UI(ID_VIEW_RULER, OnUpdateControlBarMenu)
  57. ON_MESSAGE(WPM_BARSTATE, OnBarState)
  58. ON_REGISTERED_MESSAGE(CWordPadApp::m_nOpenMsg, OnOpenMsg)
  59. ON_COMMAND_EX(ID_VIEW_STATUS_BAR, OnBarCheck)
  60. ON_COMMAND_EX(ID_VIEW_TOOLBAR, OnBarCheck)
  61. ON_COMMAND_EX(ID_VIEW_FORMATBAR, OnBarCheck)
  62. ON_COMMAND_EX(ID_VIEW_RULER, OnBarCheck)
  63. ON_XTP_CREATECONTROL()
  64. ON_XTP_CREATECOMMANDBAR()
  65. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  66. ON_COMMAND_RANGE(ID_BDR_OUTSIDE, ID_BDR_INSIDE_VERT, OnBorders)
  67. ON_UPDATE_COMMAND_UI_RANGE(ID_BDR_OUTSIDE, ID_BDR_INSIDE_VERT, OnUpdateBorders)
  68. ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
  69. ON_COMMAND_RANGE(ID_VIEW_THEME_OFFICE2000, ID_VIEW_THEME_OFFICE2007, OnViewTheme)
  70. END_MESSAGE_MAP()
  71. static UINT BASED_CODE indicators[] =
  72. {
  73. ID_SEPARATOR,           // status line indicator
  74. ID_INDICATOR_CAPS,
  75. ID_INDICATOR_NUM,
  76. ID_INDICATOR_SCRL,
  77. };
  78. #define IDR_COLORTEXT_POPUP 1000
  79. enum Borders {borderTop = 1, borderLeft = 2, borderRight = 4, borderBottom = 8, borderInsideVert = 16, borderInsideHorz = 32,
  80. borderOutside = borderBottom | borderTop | borderLeft | borderRight,
  81. borderInside = borderInsideVert | borderInsideHorz,
  82. borderAll = borderInside | borderOutside};
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CMainFrame construction/destruction
  85. CMainFrame::CMainFrame()
  86. {
  87. m_hIconDoc = theApp.LoadIcon(IDI_ICON_DOC);
  88. m_hIconText = theApp.LoadIcon(IDI_ICON_TEXT);
  89. m_hIconWrite = theApp.LoadIcon(IDI_ICON_WRITE);
  90. m_dwBorders = 0;
  91. }
  92. CMainFrame::~CMainFrame()
  93. {
  94. }
  95. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  96. {
  97. WNDCLASS wndcls;
  98. BOOL bRes = CFrameWnd::PreCreateWindow(cs);
  99. HINSTANCE hInst = AfxGetInstanceHandle();
  100. // see if the class already exists
  101. if (!::GetClassInfo(hInst, szWordPadClass, &wndcls))
  102. {
  103. // get default stuff
  104. ::GetClassInfo(hInst, cs.lpszClass, &wndcls);
  105. wndcls.style &= ~(CS_HREDRAW|CS_VREDRAW);
  106. // register a new class
  107. wndcls.lpszClassName = szWordPadClass;
  108. wndcls.hIcon = ::LoadIcon(hInst, MAKEINTRESOURCE(IDR_MAINFRAME));
  109. ASSERT(wndcls.hIcon != NULL);
  110. if (!AfxRegisterClass(&wndcls))
  111. AfxThrowResourceException();
  112. }
  113. cs.lpszClass = szWordPadClass;
  114. CRect rect = theApp.m_rectInitialFrame;
  115. if (rect.Width() > 0 && rect.Height() > 0)
  116. {
  117. // make sure window will be visible
  118. CDisplayIC dc;
  119. CRect rectDisplay(0, 0, dc.GetDeviceCaps(HORZRES),
  120. dc.GetDeviceCaps(VERTRES));
  121. if (rectDisplay.PtInRect(rect.TopLeft()) &&
  122. rectDisplay.PtInRect(rect.BottomRight()))
  123. {
  124. cs.x = rect.left;
  125. cs.y = rect.top;
  126. cs.cx = rect.Width();
  127. cs.cy = rect.Height();
  128. }
  129. }
  130. return bRes;
  131. }
  132. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  133. {
  134. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  135. return -1;
  136. if (!CreateStatusBar())
  137. return -1;
  138. if (!InitCommandBars())
  139. return -1;
  140. CXTPCommandBars* pCommandBars = GetCommandBars();
  141. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  142. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage);
  143. if (!CreateToolBars())
  144. return -1;
  145. EnableDocking(CBRS_ALIGN_ANY);
  146. if (!CreateRulerBar())
  147. return -1;
  148. CWnd* pView = GetDlgItem(AFX_IDW_PANE_FIRST);
  149. if (pView != NULL)
  150. {
  151. pView->SetWindowPos(&wndBottom, 0, 0, 0, 0,
  152. SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
  153. }
  154. pCommandBars->GetImageManager()->SetIcons(IDR_MAINFRAME1, IDB_TOOLBAR_ALPHA);
  155. pCommandBars->GetImageManager()->SetIcons(IDB_FORMATBAR, IDB_FORMATBAR_ALPHA);
  156. pCommandBars->GetToolTipContext()->SetStyle(xtpToolTipOffice);
  157. LoadCommandBars(_T("CommandBars2"));
  158. CXTPPaintManager::SetTheme(xtpThemeRibbon);
  159. EnableOffice2007Frame(GetCommandBars());
  160. return 0;
  161. }
  162. BOOL CMainFrame::CreateToolBars()
  163. {
  164. XTPImageManager()->SetMaskColor(RGB(0, 255, 0));
  165. CXTPCommandBars* pCommandBars = GetCommandBars();
  166. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  167. if (!pStandardBar ||
  168. !pStandardBar->LoadToolBar(IDR_MAINFRAME1))
  169. {
  170. TRACE0("Failed to create toolbarn");
  171. return FALSE;
  172. }
  173. CXTPToolBar* pFormatBar = (CXTPToolBar*)pCommandBars->Add(_T("Formating"), xtpBarTop);
  174. if (!pFormatBar ||
  175. !pFormatBar->LoadToolBar(IDB_FORMATBAR))
  176. {
  177. TRACE0("Failed to create toolbarn");
  178. return FALSE;
  179. }
  180. DockRightOf(pFormatBar, pStandardBar);
  181. // Create Context Menu
  182. CMenu menuText;
  183. menuText.LoadMenu(IDR_TEXT_POPUP);
  184. CMenu* pMenuPopup = menuText.GetSubMenu(0);
  185. menuText.RemoveMenu(0, MF_BYPOSITION);
  186. if (!GetSystemMetrics(SM_PENWINDOWS))
  187. {
  188. //delete pen specific stuff
  189. // remove Insert Keystrokes
  190. pMenuPopup->DeleteMenu(ID_PEN_LENS, MF_BYCOMMAND);
  191. int nIndex = pMenuPopup->GetMenuItemCount()-1; //index of last item
  192. // remove Edit Text...
  193. pMenuPopup->DeleteMenu(nIndex, MF_BYPOSITION);
  194. // remove separator
  195. pMenuPopup->DeleteMenu(nIndex-1, MF_BYPOSITION);
  196. }
  197. pCommandBars->GetContextMenus()->Add(IDR_TEXT_POPUP, _T("Context Menu"), pMenuPopup);
  198. return TRUE;
  199. }
  200. BOOL CMainFrame::CreateRulerBar()
  201. {
  202. if (!m_wndRulerBar.Create(this,
  203. WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_HIDE_INPLACE, ID_VIEW_RULER))
  204. {
  205. TRACE0("Failed to create rulern");
  206. return FALSE;      // fail to create
  207. }
  208. return TRUE;
  209. }
  210. BOOL CMainFrame::CreateStatusBar()
  211. {
  212. if (!m_wndStatusBar.Create(this) ||
  213. !m_wndStatusBar.SetIndicators(indicators,
  214. sizeof(indicators)/sizeof(UINT)))
  215. {
  216. TRACE0("Failed to create status barn");
  217. return FALSE;      // fail to create
  218. }
  219. return TRUE;
  220. }
  221. /////////////////////////////////////////////////////////////////////////////
  222. // CMainFrame Operations
  223. HICON CMainFrame::GetIcon(int nDocType)
  224. {
  225. switch (nDocType)
  226. {
  227. case RD_WINWORD6:
  228. case RD_WORDPAD:
  229. case RD_EMBEDDED:
  230. case RD_RICHTEXT:
  231. return m_hIconDoc;
  232. case RD_TEXT:
  233. case RD_OEMTEXT:
  234. return m_hIconText;
  235. case RD_WRITE:
  236. return m_hIconWrite;
  237. }
  238. return m_hIconDoc;
  239. }
  240. /////////////////////////////////////////////////////////////////////////////
  241. // CMainFrame diagnostics
  242. #ifdef _DEBUG
  243. void CMainFrame::AssertValid() const
  244. {
  245. CFrameWnd::AssertValid();
  246. }
  247. void CMainFrame::Dump(CDumpContext& dc) const
  248. {
  249. CFrameWnd::Dump(dc);
  250. }
  251. #endif //_DEBUG
  252. /////////////////////////////////////////////////////////////////////////////
  253. // CMainFrame message handlers
  254. void CMainFrame::OnFontChange()
  255. {
  256. //m_wndFormatBar.SendMessage(CWordPadApp::m_nPrinterChangedMsg);
  257. }
  258. void CMainFrame::OnDevModeChange(LPTSTR lpDeviceName)
  259. {
  260. theApp.NotifyPrinterChanged();
  261. CFrameWnd::OnDevModeChange(lpDeviceName); //sends message to descendants
  262. }
  263. void CMainFrame::OnSysColorChange()
  264. {
  265. CFrameWnd::OnSysColorChange();
  266. m_wndRulerBar.SendMessage(WM_SYSCOLORCHANGE);
  267. }
  268. void CMainFrame::ActivateFrame(int nCmdShow)
  269. {
  270. CFrameWnd::ActivateFrame(nCmdShow);
  271. // make sure and display the toolbar, ruler, etc while loading a document.
  272. OnIdleUpdateCmdUI();
  273. UpdateWindow();
  274. }
  275. void CMainFrame::OnSize(UINT nType, int cx, int cy)
  276. {
  277. CFrameWnd::OnSize(nType, cx, cy);
  278. theApp.m_bMaximized = (nType == SIZE_MAXIMIZED);
  279. if (nType == SIZE_RESTORED)
  280. GetWindowRect(theApp.m_rectInitialFrame);
  281. }
  282. LRESULT CMainFrame::OnBarState(WPARAM wParam, LPARAM lParam)
  283. {
  284. if (lParam == -1)
  285. return 0L;
  286. ASSERT(lParam != RD_EMBEDDED);
  287. if (wParam == 0)
  288. {
  289. //CDockState& ds = theApp.GetDockState(lParam);
  290. //ds.Clear(); // empty out the dock state
  291. //GetDockState(ds);
  292. }
  293. else
  294. {
  295. if (IsTextType((int)lParam))
  296. {
  297. // in text mode hide the ruler and format bar so that it is the default
  298. CWnd* pBar = GetControlBar(ID_VIEW_RULER);
  299. if (pBar != NULL)
  300. pBar->ShowWindow(SW_HIDE);
  301. }
  302. HICON hIcon = GetIcon((int)lParam);
  303. SendMessage(WM_SETICON, TRUE, (LPARAM)hIcon);
  304. //SetDockState(theApp.GetDockState(lParam));
  305. }
  306. return 0L;
  307. }
  308. void CMainFrame::OnMove(int x, int y)
  309. {
  310. CFrameWnd::OnMove(x, y);
  311. WINDOWPLACEMENT wp;
  312. wp.length = sizeof(wp);
  313. GetWindowPlacement(&wp);
  314. theApp.m_rectInitialFrame = wp.rcNormalPosition;
  315. CView* pView = GetActiveView();
  316. if (pView != NULL)
  317. pView->SendMessage(WM_MOVE);
  318. }
  319. LRESULT CMainFrame::OnOpenMsg(WPARAM, LPARAM lParam)
  320. {
  321. TCHAR szAtomName[256];
  322. szAtomName[0] = NULL;
  323. GlobalGetAtomName((ATOM)lParam, szAtomName, 256);
  324. CWordPadDoc* pDoc = (CWordPadDoc*)GetActiveDocument();
  325. if (szAtomName[0] != NULL && pDoc != NULL)
  326. {
  327. if (lstrcmpi(szAtomName, pDoc->GetPathName()) == 0)
  328. return TRUE;
  329. }
  330. return FALSE;
  331. }
  332. void CMainFrame::OnHelpFinder()
  333. {
  334. theApp.WinHelp(0, HELP_FINDER);
  335. }
  336. void CMainFrame::OnDropFiles(HDROP hDropInfo)
  337. {
  338. TCHAR szFileName[_MAX_PATH];
  339. ::DragQueryFile(hDropInfo, 0, szFileName, _MAX_PATH);
  340. ::DragFinish(hDropInfo);
  341. theApp.OpenDocumentFile(szFileName);
  342. }
  343. void CMainFrame::OnCharColor()
  344. {
  345. /*CColorMenu colorMenu;
  346. CRect rc;
  347. int index = m_wndFormatBar.CommandToIndex(ID_CHAR_COLOR);
  348. m_wndFormatBar.GetItemRect(index, &rc);
  349. m_wndFormatBar.ClientToScreen(rc);
  350. colorMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,rc.left,rc.bottom, this);*/
  351. }
  352. void CMainFrame::OnPenToggle()
  353. {
  354. }
  355. BOOL CMainFrame::OnQueryNewPalette()
  356. {
  357. CView* pView = GetActiveView();
  358. if (pView != NULL)
  359. return (BOOL)pView->SendMessage(WM_QUERYNEWPALETTE);
  360. return FALSE;
  361. }
  362. void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
  363. {
  364. CView* pView = GetActiveView();
  365. if (pView != NULL)
  366. pView->SendMessage(WM_PALETTECHANGED, (WPARAM)pFocusWnd->GetSafeHwnd());
  367. }
  368. int CMainFrame::OnCreateCommandBar(LPCREATEBARSTRUCT lpCreatePopup)
  369. {
  370. if (lpCreatePopup->bTearOffBar && lpCreatePopup->nID == IDR_COLORTEXT_POPUP)
  371. {
  372. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreatePopup->pCommandBar);
  373. ASSERT(pToolBar);
  374. // Prevent docking.
  375. pToolBar->EnableDocking(xtpFlagFloating);
  376. // Prevent customization
  377. pToolBar->EnableCustomization(FALSE);
  378. return TRUE;
  379. }
  380. return FALSE;
  381. }
  382. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  383. {
  384. CXTPToolBar* pToolBar = lpCreateControl->bToolBar? DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar): NULL;
  385. if (lpCreateControl->nID == ID_COMBO_FONT && pToolBar && pToolBar->GetBarID() == IDB_FORMATBAR)
  386. {
  387. CXTPControlComboBox* pComboFont = new CXTPControlFontComboBox();
  388. pComboFont->SetDropDownListStyle();
  389. lpCreateControl->pControl = pComboFont;
  390. return TRUE;
  391. }
  392. if (lpCreateControl->nID == ID_BDR_NONE && pToolBar)
  393. {
  394. CXTPControlPopup* pPopup = CXTPControlPopup::CreateControlPopup(xtpControlSplitButtonPopup);
  395. CXTPPopupToolBar* pPopupBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  396. pPopupBar->LoadToolBar(IDR_BORDERS);
  397. pPopupBar->SetWidth(23 * 5 + 6);
  398. pPopupBar->SetTearOffPopup(_T("Borders"), IDR_BORDERS, 23 * 5 + 6);
  399. pPopup->SetCommandBar(pPopupBar);
  400. pPopupBar->InternalRelease();
  401. lpCreateControl->pControl = pPopup;
  402. return TRUE;
  403. }
  404. if (lpCreateControl->nID == ID_COMBO_SIZE && pToolBar && pToolBar->GetBarID() == IDB_FORMATBAR)
  405. {
  406. CXTPControlComboBox* pComboSize = new CXTPControlSizeComboBox();
  407. pComboSize->SetDropDownListStyle();
  408. lpCreateControl->pControl = pComboSize;
  409. return TRUE;
  410. }
  411. if (lpCreateControl->nID == ID_BUTTON_TEXT && pToolBar && pToolBar->GetBarID() == IDB_FORMATBAR)
  412. {
  413. CXTPControlPopupColor* pPopupColor = new CXTPControlPopupColor();
  414. CXTPPopupBar* pColorBar = (CXTPPopupBar*)CXTPPopupToolBar::CreateObject();
  415. pColorBar->GetControls()->Add(new CXTPControlButtonColor(), XTP_IDS_AUTOMATIC);
  416. pColorBar->GetControls()->Add(new CXTPControlColorSelector(), ID_SELECTOR_TEXT);
  417. pColorBar->GetControls()->Add(new CXTPControlButtonColor(), XTP_IDS_MORE_COLORS);
  418. pPopupColor->SetCommandBar(pColorBar);
  419. pColorBar->SetTearOffPopup(_T("Text Color"), IDR_COLORTEXT_POPUP, 0);
  420. pColorBar->EnableCustomization(FALSE);
  421. pColorBar->InternalRelease();
  422. lpCreateControl->pControl = pPopupColor;
  423. return TRUE;
  424. }
  425. if (lpCreateControl->nID == ID_EDIT_UNDO && pToolBar)
  426. {
  427. CXTPControlPopup* pButtonUndo = CXTPControlPopup::CreateControlPopup(xtpControlSplitButtonPopup);
  428. CXTPPopupToolBar* pUndoBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  429. pUndoBar->EnableCustomization(FALSE);
  430. pUndoBar->SetBorders(CRect(2, 2, 2, 2));
  431. pUndoBar->DisableShadow();
  432. CXTPControlListBox* pControlListBox = (CXTPControlListBox*)pUndoBar->GetControls()->Add(new CXTPControlListBox(), ID_EDIT_UNDO);
  433. pControlListBox->SetWidth(140);
  434. pControlListBox->SetLinesMinMax(1, 6);
  435. pControlListBox->SetMultiplSel(TRUE);
  436. CXTPControlStatic* pControlListBoxInfo = (CXTPControlStatic*)pUndoBar->GetControls()->Add(new CXTPControlStatic(), ID_EDIT_UNDO);
  437. pControlListBoxInfo->SetWidth(140);
  438. pButtonUndo->SetCommandBar(pUndoBar);
  439. pUndoBar->InternalRelease();
  440. lpCreateControl->pControl = pButtonUndo;
  441. return TRUE;
  442. }
  443. if (lpCreateControl->nID == ID_INSERT_COLUMNS)
  444. {
  445. CXTPControlPopup* pButtonColumns = CXTPControlPopup::CreateControlPopup(xtpControlButtonPopup);
  446. pButtonColumns->SetFlags(xtpFlagManualUpdate);
  447. CXTPPopupToolBar* pColumnsBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  448. pColumnsBar->EnableCustomization(FALSE);
  449. pColumnsBar->SetBorders(CRect(2, 2, 2, 2));
  450. pColumnsBar->DisableShadow();
  451. pColumnsBar->GetControls()->Add(new CControlColumns(), ID_INSERT_COLUMNS);
  452. CXTPControlStatic* pControlColumnsInfo = (CXTPControlStatic*)pColumnsBar->GetControls()->Add(new CXTPControlStatic(), ID_INSERT_COLUMNS);
  453. pControlColumnsInfo->SetFlags(xtpFlagManualUpdate);
  454. pButtonColumns->SetCommandBar(pColumnsBar);
  455. pColumnsBar->InternalRelease();
  456. lpCreateControl->pControl = pButtonColumns;
  457. return TRUE;
  458. }
  459. if (lpCreateControl->nID == ID_INSERT_TABLE)
  460. {
  461. CXTPControlPopup* pButtonTable = CXTPControlPopup::CreateControlPopup(xtpControlButtonPopup);
  462. pButtonTable->SetFlags(xtpFlagManualUpdate);
  463. CXTPPopupToolBar* pTableBar = CXTPPopupToolBar::CreatePopupToolBar(GetCommandBars());
  464. pTableBar->EnableCustomization(FALSE);
  465. pTableBar->SetBorders(CRect(2, 2, 2, 2));
  466. pTableBar->DisableShadow();
  467. pTableBar->GetControls()->Add(new CControlTable(), ID_INSERT_TABLE);
  468. CXTPControlStatic* pControlTableInfo = (CXTPControlStatic*)pTableBar->GetControls()->Add(new CXTPControlStatic(), ID_INSERT_TABLE);
  469. pControlTableInfo->SetFlags(xtpFlagManualUpdate);
  470. pButtonTable->SetCommandBar(pTableBar);
  471. pTableBar->InternalRelease();
  472. lpCreateControl->pControl = pButtonTable;
  473. return TRUE;
  474. }
  475. return FALSE;
  476. }
  477. void CMainFrame::OnCustomize()
  478. {
  479. CXTPCustomizeSheet cs(GetCommandBars());
  480. CXTPCustomizeOptionsPage pageOptions(&cs);
  481. cs.AddPage(&pageOptions);
  482. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  483. pCommands->AddCategories(IDR_MAINFRAME);
  484. pCommands->GetControls(_T("File"))->Add(xtpControlButton, ID_FILE_OPEN, _T(""), 1);
  485. pCommands->InsertAllCommandsCategory();
  486. pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  487. pCommands->InsertNewMenuCategory();
  488. cs.DoModal();
  489. }
  490. void CMainFrame::OnClose()
  491. {
  492. SaveCommandBars(_T("CommandBars2"));
  493. CFrameWnd::OnClose();
  494. }
  495. void CMainFrame::SwitchBorders(DWORD dwState)
  496. {
  497. if (m_dwBorders & dwState) m_dwBorders &= ~dwState; else m_dwBorders |= dwState;
  498. }
  499. void CMainFrame::OnBorders(UINT nID)
  500. {
  501. switch (nID)
  502. {
  503. case ID_BDR_TOP: SwitchBorders(borderTop); break;
  504. case ID_BDR_LEFT: SwitchBorders(borderLeft); break;
  505. case ID_BDR_RIGHT: SwitchBorders(borderRight); break;
  506. case ID_BDR_BOTTOM: SwitchBorders(borderBottom); break;
  507. case ID_BDR_NONE: m_dwBorders = 0; break;
  508. case ID_BDR_OUTSIDE: SwitchBorders(borderOutside); break;
  509. case ID_BDR_ALL: SwitchBorders(borderAll); break;
  510. case ID_BDR_INSIDE_VERT: SwitchBorders(borderInsideVert); break;
  511. case ID_BDR_INSIDE_HORZ: SwitchBorders(borderInsideHorz); break;
  512. case ID_BDR_INSIDE: SwitchBorders(borderInside); break;
  513. }
  514. }
  515. void CMainFrame::OnUpdateBorders(CCmdUI* pCmdUI)
  516. {
  517. switch (pCmdUI->m_nID)
  518. {
  519. case ID_BDR_TOP: pCmdUI->SetCheck(m_dwBorders & borderTop? TRUE: FALSE); break;
  520. case ID_BDR_LEFT: pCmdUI->SetCheck(m_dwBorders & borderLeft? TRUE: FALSE); break;
  521. case ID_BDR_RIGHT: pCmdUI->SetCheck(m_dwBorders & borderRight? TRUE: FALSE); break;
  522. case ID_BDR_BOTTOM: pCmdUI->SetCheck(m_dwBorders & borderBottom? TRUE: FALSE); break;
  523. case ID_BDR_OUTSIDE : pCmdUI->SetCheck((m_dwBorders & borderOutside) == borderOutside? TRUE: FALSE); break;
  524. case ID_BDR_ALL : pCmdUI->SetCheck((m_dwBorders & borderAll) == borderAll? TRUE: FALSE); break;
  525. case ID_BDR_INSIDE_VERT: pCmdUI->SetCheck(m_dwBorders & borderInsideVert? TRUE: FALSE); break;
  526. case ID_BDR_INSIDE_HORZ: pCmdUI->SetCheck(m_dwBorders & borderInsideHorz? TRUE: FALSE); break;
  527. case ID_BDR_INSIDE: pCmdUI->SetCheck((m_dwBorders & borderInside) == borderInside? TRUE: FALSE); break;
  528. }
  529. }
  530. void CMainFrame::OnViewTheme(UINT nTheme)
  531. {
  532. switch (nTheme)
  533. {
  534. case ID_VIEW_THEME_OFFICE2000:
  535. EnableOffice2007Frame(NULL);
  536. XTPPaintManager()->SetTheme(xtpThemeOffice2000);
  537. break;
  538. case ID_VIEW_THEME_OFFICE2002:
  539. EnableOffice2007Frame(NULL);
  540. XTPPaintManager()->SetTheme(xtpThemeOfficeXP);
  541. break;
  542. case ID_VIEW_THEME_OFFICE2003:
  543. EnableOffice2007Frame(NULL);
  544. XTPPaintManager()->SetTheme(xtpThemeOffice2003);
  545. break;
  546. case ID_VIEW_THEME_OFFICE2007:
  547. XTPPaintManager()->SetTheme(xtpThemeRibbon);
  548. EnableOffice2007Frame(GetCommandBars());
  549. break;
  550. }
  551. GetCommandBars()->RedrawCommandBars();
  552. RedrawWindow(0, 0, RDW_ALLCHILDREN | RDW_INVALIDATE);
  553. }