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

对话框与窗口

开发平台:

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 "ToolBox.h"
  22. #include "MainFrm.h"
  23. #include "ToolBoxView.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CMainFrame
  31. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  32. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  33. //{{AFX_MSG_MAP(CMainFrame)
  34. ON_WM_CREATE()
  35. ON_MESSAGE(XTPWM_TASKPANEL_NOTIFY, OnTaskPanelNotify)
  36. ON_WM_CLOSE()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. static UINT indicators[] =
  40. {
  41. ID_SEPARATOR,           // status line indicator
  42. ID_INDICATOR_CAPS,
  43. ID_INDICATOR_NUM,
  44. ID_INDICATOR_SCRL,
  45. };
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CMainFrame construction/destruction
  48. CMainFrame::CMainFrame()
  49. {
  50. // get path of executable
  51. TCHAR szBuff[_MAX_PATH];
  52. VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuff, _MAX_PATH));
  53. LPTSTR lpszExt = _tcsrchr(szBuff, '.');
  54. lstrcpy(lpszExt, _T(".xml"));
  55. m_strIniFileName = szBuff;
  56. }
  57. CMainFrame::~CMainFrame()
  58. {
  59. }
  60. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  61. {
  62. if (CFrameWnd::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(xtpThemeOfficeXP);
  74. CXTPCommandBars* pCommandBars = GetCommandBars();
  75. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  76. pMenuBar->SetFlags(xtpFlagIgnoreSetMenuMessage);
  77. CXTPToolBar* pStandardBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  78. if (!pStandardBar ||
  79. !pStandardBar->LoadToolBar(IDR_MAINFRAME))
  80. {
  81. TRACE0("Failed to create toolbarn");
  82. return -1;
  83. }
  84. CXTPPropExchangeXMLNode px(TRUE, 0, _T("Settings"));
  85. if (px.LoadFromFile(m_strIniFileName))
  86. {
  87. CXTPPropExchangeSection pxTaskPanel(px.GetSection(_T("TaskPanel")));
  88. m_wndTaskPanel.GetGroups()->DoPropExchange(&pxTaskPanel);
  89. CXTPPropExchangeSection pxCommandBars(px.GetSection(_T("CommandBars")));
  90. GetCommandBars()->DoPropExchange(&pxCommandBars, NULL);
  91. }
  92. else
  93. {
  94. ResetToolboxItems();
  95. }
  96. return 0;
  97. }
  98. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  99. {
  100. if( !CFrameWnd::PreCreateWindow(cs) )
  101. return FALSE;
  102. cs.lpszClass = _T("XTPMainFrame");
  103. CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
  104. CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
  105. // TODO: Modify the Window class or styles here by modifying
  106. //  the CREATESTRUCT cs
  107. cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
  108. cs.dwExStyle |= WS_EX_CONTROLPARENT;
  109. cs.cx = 690;
  110. cs.cy = 500;
  111. return TRUE;
  112. }
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CMainFrame diagnostics
  115. #ifdef _DEBUG
  116. void CMainFrame::AssertValid() const
  117. {
  118. CFrameWnd::AssertValid();
  119. }
  120. void CMainFrame::Dump(CDumpContext& dc) const
  121. {
  122. CFrameWnd::Dump(dc);
  123. }
  124. #endif //_DEBUG
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CMainFrame message handlers
  127. CXTPTaskPanelGroup* CMainFrame::CreateToolboxGroup(UINT nID)
  128. {
  129. CXTPTaskPanelGroup* pFolder = m_wndTaskPanel.AddGroup(nID);
  130. CXTPTaskPanelGroupItem* pPointer = pFolder->AddLinkItem(ID_TOOLBOXITEM_POINTER, 0);
  131. pPointer->SetItemSelected(TRUE);
  132. pPointer->AllowDrag(FALSE);
  133. pPointer->AllowDrop(FALSE);
  134. pFolder->SetIconIndex(IDR_MAINFRAME);
  135. return pFolder;
  136. }
  137. void CMainFrame::ResetToolboxItems()
  138. {
  139. m_wndTaskPanel.GetGroups()->Clear(FALSE);
  140. CXTPTaskPanelGroup* pFolderPropertyPanes = CreateToolboxGroup(ID_TOOLBOXFOLDER_PROPERTYPANES);
  141. CXTPTaskPanelGroup* pFolderData = CreateToolboxGroup(ID_TOOLBOXFOLDER_DATA);
  142. pFolderData->AddLinkItem(ID_TOOLBOXITEM_DATASET                 ,26);
  143. pFolderData->AddLinkItem(ID_TOOLBOXITEM_OLEDBDATAADAPTER        ,27);
  144. pFolderData->AddLinkItem(ID_TOOLBOXITEM_OLEDBCONNECTION         ,28);
  145. pFolderData->AddLinkItem(ID_TOOLBOXITEM_OLEDBCOMMAND            ,29);
  146. pFolderData->AddLinkItem(ID_TOOLBOXITEM_SQLDATAADAPTER          ,30);
  147. pFolderData->AddLinkItem(ID_TOOLBOXITEM_SQLCONNECTION           ,31);
  148. pFolderData->AddLinkItem(ID_TOOLBOXITEM_SQLCOMMAND              ,32);
  149. pFolderData->AddLinkItem(ID_TOOLBOXITEM_DATAVIEW                ,33);
  150. CXTPTaskPanelGroup* pFolderComponents = CreateToolboxGroup(ID_TOOLBOXFOLDER_COMPONENTS);
  151. pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_FILESYSTEMWATCHER     ,34);
  152. pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_EVENTLOG              ,35);
  153. pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_DIRECTORYENTRY        ,36);
  154. pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_DIRECTORYSEARCHER     ,37);
  155. pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_MESSAGEQUEUE          ,38);
  156. pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_PERFORMANCECOUNTER    ,39);
  157. pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_PROCESS               ,40);
  158. pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_SERVICECONTROLLER     ,41);
  159. pFolderComponents->AddLinkItem(ID_TOOLBOXITEM_TIMER                 ,42);
  160. CXTPTaskPanelGroup* pFolderWindowsForms = CreateToolboxGroup(ID_TOOLBOXFOLDER_WINDOWSFORMS);
  161. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_BUTTON,             1);
  162. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_CHECK_BOX,              2);
  163. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_EDIT_CONTROL,           3);
  164. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_COMBO_BOX,              4);
  165. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_LIST_BOX,               5);
  166. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_GROUP_BOX,              6);
  167. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_RADIO_BUTTON,           7);
  168. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_STATIC_TEXT,            8);
  169. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_PICTURE_CONTROL,        9);
  170. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_HORIZONTAL_SCROLL_BAR,  10);
  171. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_VERTICAL_SCROLL_BAR,    11);
  172. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_SLIDER_CONTROL,     12);
  173. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_SPIN_CONTROL,           13);
  174. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_PROGRESS_CONTROL,       14);
  175. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_HOT_KEY,                15);
  176. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_LIST_CONTROL,           16);
  177. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_TREE_CONTROL,           17);
  178. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_TAB_CONTROL,            18);
  179. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_ANIMATION_CONTROL,      19);
  180. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_RICH_EDIT_CONTROL,      20);
  181. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_DATE_TIME_PICKER,       21);
  182. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_MONTH_CALENDAR_CONTROL,22);
  183. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_IP_ADDRESS_CONTROL, 23);
  184. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_EXTENDED_COMBO_BOX, 24);
  185. pFolderWindowsForms->AddLinkItem(ID_TOOLBOXITEM_CUSTOM_CONTROL,     25);
  186. CreateToolboxGroup(ID_TOOLBOXFOLDER_CLIPBOARDRING);
  187. CreateToolboxGroup(ID_TOOLBOXFOLDER_GENERAL);
  188. pFolderPropertyPanes->SetExpanded(TRUE);
  189. }
  190. BOOL CMainFrame::CreateTaskPanel()
  191. {
  192. if (!m_wndTaskPanel.Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_TABSTOP, CRect(0, 0, 0, 0), &m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0)))
  193. return FALSE;
  194. m_wndTaskPanel.SetOwner(this);
  195. m_wndTaskPanel.GetImageManager()->SetIcons(IDB_TOOLBOXICONS, 0, 0, CSize(16, 16));
  196. m_wndTaskPanel.SetBehaviour(xtpTaskPanelBehaviourToolbox);
  197. m_wndTaskPanel.SetTheme(xtpTaskPanelThemeToolbox);
  198. m_wndTaskPanel.SetSelectItemOnFocus(TRUE);
  199. m_wndTaskPanel.AllowDrag(TRUE);
  200. m_wndSplitter.SetColumnInfo(0, 210, 0);
  201. return TRUE;
  202. }
  203. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
  204. {
  205. m_wndSplitter.CreateStatic(this, 1, 2);
  206. m_wndSplitter.ModifyStyleEx(0, WS_EX_CONTROLPARENT);
  207. m_wndSplitter.CreateView(0, 1, pContext->m_pNewViewClass, CSize(300, 0), pContext);
  208. SetActiveView((CView*)m_wndSplitter.GetDlgItem(m_wndSplitter.IdFromRowCol(0, 1)));
  209. if (!CreateTaskPanel())
  210. return FALSE;
  211. return TRUE;
  212. }
  213. BOOL CMainFrame::IsToggleButtons()
  214. {
  215. return ((CToolBoxView*)GetActiveView())->m_wndPageLookAndBehaviour.m_bToggleButtons;
  216. }
  217. LRESULT CMainFrame::OnTaskPanelNotify(WPARAM wParam, LPARAM lParam)
  218. {
  219. switch(wParam)
  220. {
  221. case XTP_TPN_CLICK:
  222. {
  223. CXTPTaskPanelGroupItem* pItem = (CXTPTaskPanelGroupItem*)lParam;
  224. TRACE(_T("Click Event: pItem.Caption = %s, pItem.ID = %in"), pItem->GetCaption(), pItem->GetID());
  225. if (IsToggleButtons())
  226. {
  227. pItem->SetItemSelected(!pItem->IsItemSelected());
  228. }
  229. }
  230. break;
  231. case XTP_TPN_RCLICK:
  232. OnTaskPanelRButtonDown((CXTPTaskPanelItem*)lParam);
  233. return TRUE;
  234. }
  235. return 0;
  236. }
  237. void CMainFrame::OnRenameTaskPanelItem(CXTPTaskPanelItem* pItem)
  238. {
  239. CXTPTaskPanelGroup* pGroup = pItem->GetItemGroup();
  240. if (pGroup->GetItemLayout() == xtpTaskItemLayoutImages)
  241. pGroup->SetItemLayout(xtpTaskItemLayoutDefault);
  242. if (pGroup->GetItemLayout() == xtpTaskItemLayoutImages)
  243. return;
  244. m_wndTaskPanel.RenameItem(pItem);
  245. }
  246. void CMainFrame::OnTaskPanelRButtonDown(CXTPTaskPanelItem* pItem)
  247. {
  248. CPoint pt;
  249. GetCursorPos(&pt);
  250. CXTPTaskPanelGroup* pGroup = pItem->GetItemGroup();
  251. if (pItem->GetID() == ID_TOOLBOXITEM_POINTER)
  252. {
  253. pItem = pGroup;
  254. pt = pGroup->GetCaptionRect().CenterPoint();
  255. pt.Offset(0, -m_wndTaskPanel.GetScrollOffset());
  256. m_wndTaskPanel.ClientToScreen(&pt);
  257. }
  258. BOOL bGroup = pItem->GetType() == xtpTaskItemTypeGroup;
  259. ASSERT(pGroup);
  260. CMenu menu;
  261. menu.LoadMenu(IDR_POPUP_TOOLBOX);
  262. CMenu* pMenuPopup = menu.GetSubMenu(bGroup? 1: 0);
  263. if (pGroup->GetItemLayout() != xtpTaskItemLayoutImages)
  264. pMenuPopup->CheckMenuItem(ID_TOOLBOX_LISTVIEW, MF_CHECKED|MF_BYCOMMAND);
  265. CXTPTaskPanelItems* pItems = pItem->GetParentItems();
  266. if (pItem->GetIndex() == 0)
  267. pMenuPopup->EnableMenuItem(ID_TOOLBOX_MOVEUP, MF_DISABLED|MF_BYCOMMAND);
  268. if (pItem->GetIndex() == pItems->GetCount() - 1)
  269. pMenuPopup->EnableMenuItem(ID_TOOLBOX_MOVEDOWN, MF_DISABLED|MF_BYCOMMAND);
  270. if (!::IsClipboardFormatAvailable(CXTPTaskPanel::GetClipboardFormat()))
  271. pMenuPopup->EnableMenuItem(ID_EDIT_PASTE, MF_DISABLED|MF_BYCOMMAND);
  272. int nReturn = CXTPCommandBars::TrackPopupMenu(pMenuPopup, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_NONOTIFY, pt.x, pt.y, this);
  273. switch (nReturn)
  274. {
  275. case ID_TOOLBOX_RENAME:
  276. OnRenameTaskPanelItem(pItem);
  277. break;
  278. case ID_TOOLBOX_ADDTAB:
  279. {
  280. CXTPTaskPanelGroup* pGroup = CreateToolboxGroup(0);
  281. m_wndTaskPanel.RenameItem(pGroup);
  282. }
  283. break;
  284. case ID_TOOLBOX_LISTVIEW:
  285. pGroup->SetItemLayout(pGroup->GetItemLayout() == xtpTaskItemLayoutImages?
  286. xtpTaskItemLayoutDefault: xtpTaskItemLayoutImages);
  287. break;
  288. case ID_TOOLBOX_MOVEDOWN:
  289. case ID_TOOLBOX_MOVEUP:
  290. {
  291. CXTPTaskPanelItems* pItems = pItem->GetParentItems();
  292. pItems->Move(pItem, pItem->GetIndex() + (nReturn == ID_TOOLBOX_MOVEDOWN? +1: -1));
  293. }
  294. break;
  295. case ID_EDIT_COPY:
  296. pItem->CopyToClipboard();
  297. break;
  298. case ID_EDIT_PASTE:
  299. {
  300. CXTPTaskPanelItem* pItem = CXTPTaskPanelItem::PasteFromClipboard();
  301. if (pItem)
  302. {
  303. CXTPTaskPanelItems* pItems = pGroup->GetItems();
  304. pItems->InsertAt(pItems->GetCount(), pItem);
  305. }
  306. }
  307. break;
  308. case ID_EDIT_CUT:
  309. pItem->CopyToClipboard();
  310. case ID_TOOLBOX_DELETE:
  311. pItem->Remove();
  312. break;
  313. }
  314. }
  315. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
  316. {
  317. if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F2 && GetFocus() == &m_wndTaskPanel)
  318. {
  319. CXTPTaskPanelItem* pItem = m_wndTaskPanel.GetFocusedItem();
  320. if (pItem)
  321. {
  322. OnRenameTaskPanelItem(pItem);
  323. return TRUE;
  324. }
  325. }
  326. if (CXTPFrameWnd::PreTranslateMessage(pMsg))
  327. return TRUE;
  328. return PreTranslateInput(pMsg);
  329. }
  330. void CMainFrame::OnClose()
  331. {
  332. CXTPPropExchangeXMLNode px(FALSE, 0, _T("Settings"));
  333. if (px.OnBeforeExchange()) 
  334. {
  335. CXTPPropExchangeSection pxTaskPanel(px.GetSection(_T("TaskPanel")));
  336. m_wndTaskPanel.GetGroups()->DoPropExchange(&pxTaskPanel);
  337. CXTPPropExchangeSection pxCommandBars(px.GetSection(_T("CommandBars")));
  338. GetCommandBars()->DoPropExchange(&pxCommandBars);
  339. px.SaveToFile(m_strIniFileName);
  340. }
  341. CFrameWnd::OnClose();
  342. }