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

对话框与窗口

开发平台:

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 "GUI_OneNote.h"
  22. #include "MainFrm.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. #define IDC_BUTTON_AUTORUN 300
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CMainFrame
  31. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  32. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  33. //{{AFX_MSG_MAP(CMainFrame)
  34. ON_WM_CREATE()
  35. ON_WM_DESTROY()
  36. ON_WM_CLOSE()
  37. ON_COMMAND(ID_VIEW_TASKPANE, OnViewTaskPane)
  38. //}}AFX_MSG_MAP
  39. ON_XTP_CREATECONTROL()
  40. ON_XTP_CREATECOMMANDBAR()
  41. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  42. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  43. ON_MESSAGE(WM_XTP_PRETRANSLATEMOUSEMSG, OnTabbarMouseMsg)
  44. END_MESSAGE_MAP()
  45. static UINT indicators[] =
  46. {
  47. ID_SEPARATOR,           // status line indicator
  48. ID_INDICATOR_CAPS,
  49. ID_INDICATOR_NUM,
  50. ID_INDICATOR_SCRL,
  51. };
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CMainFrame construction/destruction
  54. CMainFrame::CMainFrame()
  55. {
  56. }
  57. CMainFrame::~CMainFrame()
  58. {
  59. }
  60. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  61. {
  62. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  63. return -1;
  64. if (!m_wndStatusBar.Create(this) ||
  65. !m_wndStatusBar.SetIndicators(indicators,
  66.   sizeof(indicators)/sizeof(UINT)))
  67. {
  68. TRACE0("Failed to create status barn");
  69. return -1;      // fail to create
  70. }
  71. if (!InitCommandBars())
  72. return -1;
  73. CXTPPaintManager::SetTheme(xtpThemeOffice2003);
  74. CXTPCommandBars* pCommandBars = GetCommandBars();
  75. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  76. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage|xtpFlagHideMDIButtons);
  77. XTPImageManager()->SetMaskColor(RGB(128, 0, 128));
  78. CXTPToolBar* pCommandBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  79. if (!pCommandBar ||
  80. !pCommandBar->LoadToolBar(IDR_MAINFRAME))
  81. {
  82. TRACE0("Failed to create toolbarn");
  83. return -1;
  84. }
  85. CXTPToolBar* pFormatBar = (CXTPToolBar*)pCommandBars->Add(_T("Formatting"), xtpBarTop);
  86. if (!pFormatBar ||
  87. !pFormatBar->LoadToolBar(IDR_FORMATBAR))
  88. {
  89. TRACE0("Failed to create toolbarn");
  90. return -1;
  91. }
  92. if (XTPImageManager()->IsAlphaIconsSupported())
  93. {
  94. XTPImageManager()->SetIcons(IDR_MAINFRAME, IDR_MAINFRAME_ALPHA, xtpImageNormal);
  95. XTPImageManager()->SetIcons(IDR_EXTENDED, IDR_EXTENDED_ALPHA, xtpImageNormal);
  96. XTPImageManager()->SetIcons(IDR_FORMATBAR, IDR_FORMATBAR_ALPHA, xtpImageNormal);
  97. XTPPaintManager()->GetIconsInfo()->bUseDisabledIcons = TRUE;
  98. else
  99. {
  100. CXTPOffice2003Theme::LoadModernToolbarIcons(IDR_MAINFRAME);
  101. CXTPOffice2003Theme::LoadModernToolbarIcons(IDR_EXTENDED);
  102. CXTPOffice2003Theme::LoadModernToolbarIcons(IDR_FORMATBAR);
  103. }
  104. XTPImageManager()->SetIcons(IDR_COMMONBAR);
  105. XTPImageManager()->SetIcons(IDR_COLORS);
  106. m_paneManager.InstallDockingPanes(this);
  107. m_paneManager.SetTheme(xtpPaneThemeOffice2003);
  108. // Create docking panes.
  109. m_paneManager.CreatePane(
  110. IDR_PANE_NEW, CRect(0, 0,200, 120), xtpPaneDockRight);
  111. CXTPDockingPane* pPaneSearch = m_paneManager.CreatePane(
  112. IDR_PANE_SEARCH, CRect(0, 0,200, 120), xtpPaneDockLeft);
  113. pPaneSearch->Hide();
  114. CXTPImageManagerIcon* pIcon = XTPImageManager()->GetImage(ID_FILE_NEW);
  115. ASSERT(pIcon);
  116. m_paneManager.SetIcon(IDR_PANE_NEW, pIcon->GetIcon());
  117. pIcon = XTPImageManager()->GetImage(ID_EDIT_FIND);
  118. ASSERT(pIcon);
  119. m_paneManager.SetIcon(IDR_PANE_SEARCH, pIcon->GetIcon());
  120. CXTPDockingPaneLayout layoutNormal(&m_paneManager);
  121. if (layoutNormal.Load(_T("NormalLayout")))
  122. {
  123. m_paneManager.SetLayout(&layoutNormal);
  124. }
  125. VERIFY(m_MTIClientWnd.Attach(this));
  126. m_MTIClientWnd.EnableToolTips();
  127. CXTPTabPaintManager* pTabPaintManager = new CXTPTabPaintManager();
  128. pTabPaintManager->SetAppearance(xtpTabAppearancePropertyPage2003);
  129. pTabPaintManager->m_bOneNoteColors = TRUE;
  130. pTabPaintManager->m_bHotTracking = TRUE;
  131. pTabPaintManager->m_bShowIcons = FALSE;
  132. pTabPaintManager->m_bBoldSelected = TRUE;
  133. pTabPaintManager->GetAppearanceSet()->m_rcHeaderMargin.SetRect(2, 6, 2, 0);
  134. pTabPaintManager->m_rcClientMargin.SetRect(2, 2, 2, 2);
  135. pTabPaintManager->m_rcButtonMargin.SetRect(4, 1, 4, 1);
  136. m_MTIClientWnd.SetPaintManager(pTabPaintManager);
  137. // Load the previous state for toolbars and menus.
  138. LoadCommandBars(_T("CommandBars"));
  139. return 0;
  140. }
  141. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  142. {
  143. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  144. return FALSE;
  145. cs.lpszClass = _T("XTPMainFrame");
  146. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  147. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  148. return TRUE;
  149. }
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CMainFrame diagnostics
  152. #ifdef _DEBUG
  153. void CMainFrame::AssertValid() const
  154. {
  155. CMDIFrameWnd::AssertValid();
  156. }
  157. void CMainFrame::Dump(CDumpContext& dc) const
  158. {
  159. CMDIFrameWnd::Dump(dc);
  160. }
  161. #endif //_DEBUG
  162. /////////////////////////////////////////////////////////////////////////////
  163. // CMainFrame message handlers
  164. void CMainFrame::OnViewTaskPane()
  165. {
  166. m_paneManager.ShowPane(IDR_PANE_NEW);
  167. }
  168. int CMainFrame::OnCreateCommandBar(LPCREATEBARSTRUCT lpCreatePopup)
  169. {
  170. if (lpCreatePopup->nID == ID_FORMAT_NOTEFLAGS_TODO ||
  171. (lpCreatePopup->bPopup && _tcscmp(lpCreatePopup->lpcstrCaption, _T("Note Flags")) == 0))
  172. {
  173. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  174. pPopupBar->SetTearOffPopup(_T("Note Flags"), 1000);
  175. lpCreatePopup->pCommandBar = pPopupBar;
  176. return TRUE;
  177. }
  178. return FALSE;
  179. }
  180. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  181. {
  182. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
  183. if (!pToolBar)
  184. return FALSE;
  185. if (lpCreateControl->nID == ID_HELP_QUESTION)
  186. {
  187. CXTPControlComboBox* pComboQuestion = new CXTPControlComboBox();
  188. pComboQuestion->SetDropDownListStyle();
  189. pComboQuestion->SetFlags(xtpFlagManualUpdate | xtpFlagRightAlign);
  190. pComboQuestion->SetWidth(150);
  191. pComboQuestion->SetID(ID_HELP_QUESTION);
  192. pComboQuestion->SetEditHint(pComboQuestion->GetCaption());
  193. lpCreateControl->pControl = pComboQuestion;
  194. return TRUE;
  195. }
  196. if (lpCreateControl->nID == ID_EDIT_FONT && pToolBar->GetBarID() == IDR_FORMATBAR)
  197. {
  198. CXTPControlComboBox* pComboFont = new CXTPControlFontComboBox();
  199. pComboFont->SetDropDownListStyle();
  200. lpCreateControl->pControl = pComboFont;
  201. return TRUE;
  202. }
  203. if (lpCreateControl->nID == ID_EDIT_SIZE && pToolBar->GetBarID() == IDR_FORMATBAR)
  204. {
  205. CXTPControlComboBox* pComboSize = new CXTPControlSizeComboBox();
  206. pComboSize->SetDropDownListStyle();
  207. lpCreateControl->pControl = pComboSize;
  208. return TRUE;
  209. }
  210. if (lpCreateControl->nID == ID_FORMAT_NOTEFLAGS_TODO && pToolBar->GetBarID() == IDR_MAINFRAME)
  211. {
  212. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  213. return TRUE;
  214. }
  215. if (lpCreateControl->nID == ID_FORMAT_FONTCOLOR && pToolBar->GetBarID() == IDR_FORMATBAR)
  216. {
  217. CXTPControlPopupColor* pPopupColor = new CXTPControlPopupColor();
  218. CXTPPopupBar* pColorBar = (CXTPPopupBar*)CXTPPopupToolBar::CreateObject();
  219. pColorBar->GetControls()->Add(new CXTPControlButtonColor(), XTP_IDS_AUTOMATIC);
  220. pColorBar->GetControls()->Add(new CXTPControlColorSelector(), ID_FORMAT_FONTCOLOR_SELECTOR);
  221. pPopupColor->SetCommandBar(pColorBar);
  222. pColorBar->EnableCustomization(FALSE);
  223. pColorBar->InternalRelease();
  224. lpCreateControl->pControl = pPopupColor;
  225. return TRUE;
  226. }
  227. if (lpCreateControl->nID == ID_FORMAT_HIGHLIGHT && pToolBar->GetBarID() == IDR_FORMATBAR)
  228. {
  229. CXTPControlPopupColor* pPopupColor = new CXTPControlPopupColor();
  230. CXTPPopupBar* pColorBar = (CXTPPopupBar*)CXTPPopupToolBar::CreateObject();
  231. pColorBar->GetControls()->Add(new CXTPControlButtonColor(), ID_FORMAT_HIGHLIGHT_NONE);
  232. pColorBar->GetControls()->Add(new CXTPControlColorSelector(), ID_FORMAT_HIGHLIGHT_SELECTOR);
  233. pPopupColor->SetCommandBar(pColorBar);
  234. pColorBar->EnableCustomization(FALSE);
  235. pColorBar->InternalRelease();
  236. lpCreateControl->pControl = pPopupColor;
  237. return TRUE;
  238. }
  239. return FALSE;
  240. }
  241. void CMainFrame::OnCustomize()
  242. {
  243. CXTPCustomizeSheet cs(GetCommandBars());
  244. CXTPCustomizeOptionsPage pageOptions(&cs);
  245. cs.AddPage(&pageOptions);
  246. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  247. pCommands->AddCategories(IDR_MAINFRAME);
  248. pCommands->GetControls(_T("File"))->Add(xtpControlButton, ID_FILE_OPEN, _T(""), 1);
  249. pCommands->InsertAllCommandsCategory();
  250. pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  251. pCommands->InsertNewMenuCategory();
  252. cs.DoModal();
  253. }
  254. void CMainFrame::CreateTaskPanel()
  255. {
  256. VERIFY(m_wndTaskPanel.Create(WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, CRect(0, 0, 0, 0), this, 0));
  257. m_wndTaskPanel.SetOwner(this);
  258. m_wndTaskPanel.SetTheme(xtpTaskPanelThemeOffice2003Plain);
  259. m_wndTaskPanel.SetExpandable(FALSE);
  260. m_wndTaskPanel.SetAnimation(xtpTaskPanelAnimationNo);
  261. CXTPTaskPanelGroupItem* pTextItem;
  262. CXTPTaskPanelGroup* pGroupNew = m_wndTaskPanel.AddGroup(ID_TASKGROUP_NEW);
  263. pGroupNew->GetInnerMargins().SetRect(0, 5, 0, 0);
  264. pGroupNew->AddLinkItem(ID_TASKITEM_BLANK, 0);
  265. pTextItem = pGroupNew->AddTextItem(_T("Add a new page to the current notebook. A new page is represented by a new tab at the end of the vertical series of tabs."));
  266. pTextItem->GetMargins().SetRect(20, 0, 0, 5);
  267. pGroupNew->AddLinkItem(ID_TASKITEM_SUBPAGE, 1);
  268. pTextItem = pGroupNew->AddTextItem(_T("Add a new page immediately following the current page and that shares the same title as the current page. A subpage is represented by a small tab to indicate that it is grouped with another page."));
  269. pTextItem->GetMargins().SetRect(20, 0, 0, 5);
  270. pGroupNew->AddLinkItem(ID_TASKITEM_SECTION, 2);
  271. pTextItem = pGroupNew->AddTextItem(_T("Create a section file in the current folder on your computer. Sections are represented by tabs across the top of the pages."));
  272. pTextItem->GetMargins().SetRect(20, 0, 0, 5);
  273. pGroupNew->AddLinkItem(ID_TASKITEM_QUICK, 3);
  274. pTextItem = pGroupNew->AddTextItem(_T("Open a small OneNote window where you can make notes that are automatically saved in the Quick notes section."));
  275. pTextItem->GetMargins().SetRect(20, 0, 0, 5);
  276. m_ilTaskIcons.Create(16, 16, ILC_COLOR24|ILC_MASK, 0, 1);
  277. CBitmap bmp;
  278. bmp.LoadBitmap(IDB_TASKPANEL_ICONS);
  279. m_ilTaskIcons.Add(&bmp, RGB(0, 0xFF, 0));
  280. m_wndTaskPanel.SetImageList(&m_ilTaskIcons);
  281. m_wndButtonAutoRun.Create(_T("Show at Startup"), WS_CHILD|BS_AUTOCHECKBOX|BS_NOTIFY   , CRect(0, 0, 300, 20), &m_wndTaskPanel, IDC_BUTTON_AUTORUN);
  282. m_wndButtonAutoRun.SetFont(XTPPaintManager()->GetRegularFont());
  283. CXTPTaskPanelGroupItem* pItemButton = pGroupNew->AddControlItem(m_wndButtonAutoRun);
  284. pItemButton->SetSize(CSize(0, 20));
  285. pItemButton->GetMargins().SetRect(0, 15, 0, 0);
  286. m_wndButtonAutoRun.SetItem(pItemButton);
  287. m_wndButtonAutoRun.SetCheck(1);
  288. }
  289. BEGIN_MESSAGE_MAP(CButtonEx, CButton)
  290. ON_WM_CTLCOLOR_REFLECT()
  291. ON_CONTROL_REFLECT(BN_CLICKED, OnAutoRun)
  292. END_MESSAGE_MAP()
  293. HBRUSH CButtonEx::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
  294. {
  295. if (m_pItem)
  296. {
  297. XTP_TASKPANEL_GROUPCOLORS* pColors = m_pItem->GetPaintManager()->GetGroupColors(m_pItem->GetItemGroup()->IsSpecialGroup());
  298. if (!m_brushBack.GetSafeHandle() || pColors->clrClient != m_clrBack)
  299. {
  300. m_brushBack.DeleteObject();
  301. m_brushBack.CreateSolidBrush(pColors->clrClient);
  302. m_clrBack = pColors->clrClient;
  303. }
  304. pDC->SetBkMode(TRANSPARENT);
  305. return m_brushBack;
  306. }
  307. return 0;
  308. }
  309. void CButtonEx::OnAutoRun()
  310. {
  311. TRACE(_T("AutoRun clickedn"));
  312. }
  313. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  314. {
  315. if (wParam == XTP_DPN_SHOWWINDOW)
  316. {
  317. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  318. if (!pPane->IsValid())
  319. {
  320. switch(pPane->GetID())
  321. {
  322. case IDR_PANE_NEW:
  323. if (!m_wndTaskPanel.m_hWnd)
  324. {
  325. CreateTaskPanel();
  326. }
  327. pPane->Attach(&m_wndTaskPanel);
  328. break;
  329. case IDR_PANE_SEARCH:
  330. if (!m_paneSeaarch.m_hWnd)
  331. {
  332. m_paneSeaarch.Create(_T("STATIC"), NULL, WS_CHILD, CRect(0, 0, 0, 0), this, 0);
  333. }
  334. pPane->Attach(&m_paneSeaarch);
  335. break;
  336. default:
  337. ASSERT(FALSE);
  338. }
  339. }
  340. return TRUE;
  341. }
  342. return FALSE;
  343. }
  344. void CMainFrame::OnDestroy()
  345. {
  346. m_MTIClientWnd.Detach();
  347. CMDIFrameWnd::OnDestroy();
  348. }
  349. void CMainFrame::OnClose()
  350. {
  351. CXTPDockingPaneLayout layoutNormal(&m_paneManager);
  352. m_paneManager.GetLayout(&layoutNormal);
  353. layoutNormal.Save(_T("NormalLayout"));
  354. // Save the current state for toolbars and menus.
  355. SaveCommandBars(_T("CommandBars"));
  356. CMDIFrameWnd::OnClose();
  357. }
  358. LRESULT CMainFrame::OnTabbarMouseMsg(WPARAM wParam,LPARAM lParam)
  359. {
  360. if (wParam != WM_RBUTTONDOWN)
  361. return FALSE;
  362. CPoint point = CPoint((DWORD)lParam);
  363. CXTPTabManagerItem* pItem =  m_MTIClientWnd.HitTest(point);
  364. if (pItem)
  365. {
  366. CWnd* pFrame = CWnd::FromHandle(pItem->GetHandle());
  367. MDIActivate(pFrame);
  368. m_MTIClientWnd.Refresh();
  369. CMenu menu;
  370. VERIFY(menu.LoadMenu(IDR_POPUP_TABS));
  371. CMenu* pPopup = menu.GetSubMenu(0);
  372. m_MTIClientWnd.WorkspaceToScreen(&point);
  373. CXTPCommandBars::TrackPopupMenu(pPopup, 0, point.x, point.y, this);
  374. m_MTIClientWnd.Refresh();
  375. return TRUE;
  376. }
  377. return FALSE;
  378. }
  379. void CMainFrame::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
  380. {
  381. // Toggle CommandBars
  382. GetCommandBars()->OnSetPreviewMode(bPreview);
  383. // Toggle Docking Panes.
  384. m_paneManager.OnSetPreviewMode(bPreview);
  385. // Toggle Tab Client
  386. m_MTIClientWnd.ShowWorkspace(!bPreview);
  387. CMDIFrameWnd::OnSetPreviewMode(bPreview, pState);
  388. }