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

对话框与窗口

开发平台:

Visual C++

  1. // TabbedViewView.cpp : implementation of the CTabbedViewView class
  2. //
  3. // This file is a part of the XTREME TOOLKIT 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 
  7. // BE RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED 
  8. // WRITTEN CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS 
  11. // OUTLINED IN THE XTREME TOOLKIT LICENSE AGREEMENT.  CODEJOCK SOFTWARE 
  12. // GRANTS TO YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE 
  13. // THIS SOFTWARE ON A SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. //////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "TabbedView.h"
  22. #include "TabbedViewDoc.h"
  23. #include "TabbedViewView.h"
  24. #include "TabTreeClass.h"
  25. #include "TabTreeFile.h"
  26. #include "TabTreeResource.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CTabbedViewView
  34. IMPLEMENT_DYNCREATE(CTabbedViewView, CXTTabView)
  35. BEGIN_MESSAGE_MAP(CTabbedViewView, CXTTabView)
  36. //{{AFX_MSG_MAP(CTabbedViewView)
  37. ON_WM_CREATE()
  38. ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  39. ON_WM_RBUTTONDOWN()
  40. ON_WM_CANCELMODE()
  41.     ON_COMMAND(ID_TAB_ACTIVATE, OnTabActivate)
  42. ON_COMMAND(ID_TAB_CLOSE, OnTabClose)
  43. ON_COMMAND(ID_TAB_SAVE, OnTabSave)
  44. ON_COMMAND(ID_TAB_SAVE_AS, OnTabSaveAs)
  45. ON_COMMAND(ID_TAB_PRINT, OnTabPrint)
  46. ON_COMMAND(ID_TAB_PRINT_PREVIEW, OnTabPrintPreview)
  47. ON_WM_TIMER()
  48. ON_WM_MOUSEMOVE()
  49. ON_WM_DROPFILES()
  50. //}}AFX_MSG_MAP
  51. ON_COMMAND(XT_IDC_TAB_CLOSE, OnCloseTab)
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CTabbedViewView construction/destruction
  55. CTabbedViewView::CTabbedViewView()
  56. {
  57. // TODO: add construction code here
  58. m_iHitTest = -1;
  59.     m_nIDEvent = 20;
  60. m_bXPBorder = true;
  61. }
  62. CTabbedViewView::~CTabbedViewView()
  63. {
  64. }
  65. BOOL CTabbedViewView::PreCreateWindow(CREATESTRUCT& cs)
  66. {
  67. // TODO: Modify the Window class or styles here by modifying
  68. //  the CREATESTRUCT cs
  69. return CXTTabView::PreCreateWindow(cs);
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CTabbedViewView diagnostics
  73. #ifdef _DEBUG
  74. void CTabbedViewView::AssertValid() const
  75. {
  76. CXTTabView::AssertValid();
  77. }
  78. void CTabbedViewView::Dump(CDumpContext& dc) const
  79. {
  80. CXTTabView::Dump(dc);
  81. }
  82. CTabbedViewDoc* CTabbedViewView::GetDocument() // non-debug version is inline
  83. {
  84. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTabbedViewDoc)));
  85. return (CTabbedViewDoc*)m_pDocument;
  86. }
  87. #endif //_DEBUG
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CTabbedViewView message handlers
  90. int CTabbedViewView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  91. {
  92. if (CXTTabView::OnCreate(lpCreateStruct) == -1)
  93. return -1;
  94. // Register as a drop target
  95. m_dropTarget.Register(this);
  96. DragAcceptFiles();
  97. // Create the image list used by the tab control.
  98. if (!m_imageList.Create( IDB_IMAGELIST, 16, 1, RGB( 0x00,0x80,0x80 )))
  99. {
  100. TRACE0("Failed to create image list.n");
  101. return -1;
  102. }
  103. // Create the edit control for the edit tab.
  104. if (!m_editTab.Create(WS_CHILD|WS_VISIBLE,
  105. CRect(0,0,0,0), this, IDC_EDIT_TAB))
  106. {
  107. TRACE0("Failed to create edit control.n");
  108. return -1;
  109. }
  110. // Create the tree control for the file tab
  111. if (!m_treeTabFile.Create(WS_CHILD|WS_VISIBLE,
  112. CRect(0,0,0,0), this, IDC_TREE_TAB_FILE))
  113. {
  114. TRACE0("Failed to create tree control.n");
  115. return -1;
  116. }
  117. // Create the tree control for the class tab
  118. if (!m_treeTabClass.Create(WS_CHILD|WS_VISIBLE,
  119. CRect(0,0,0,0), this, IDC_TREE_TAB_CLASS))
  120. {
  121. TRACE0("Failed to create tree control.n");
  122. return -1;
  123. }
  124. // Create the tree control for the resource tab
  125. if (!m_treeTabResource.Create(WS_CHILD|WS_VISIBLE,
  126. CRect(0,0,0,0), this, IDC_TREE_TAB_RESOURCE))
  127. {
  128. TRACE0("Failed to create tree control.n");
  129. return -1;
  130. }
  131. // Insert the edit control into the tabbed view.
  132. AddControl(_T("Edit Control"), &m_editTab);
  133. // Insert the tree controls into the tabbed view.
  134. AddControl(_T("File Tree"),     &m_treeTabFile);
  135. AddControl(_T("Class Tree"),    &m_treeTabClass);
  136. AddControl(_T("Resource Tree"), &m_treeTabResource);
  137. // Set the tab controls image list.
  138. GetTabCtrl().SetImageList(&m_imageList);
  139. // TODO: uncomment this line if you want the tabs to appear on bottom. 
  140. //ModifyTabStyle(NULL, TCS_BOTTOM);
  141. // Set the active view to the second tab.
  142. SetActiveView(1);
  143. UpdateTabBorders();
  144.     SetTabIcon(3, AfxGetApp()->LoadIcon(IDR_MDITABTYPE));
  145. return 0;
  146. }
  147. void CTabbedViewView::SetTabIcon(int iTab, int iImage)
  148. {
  149. TC_ITEM tci;
  150. tci.mask = TCIF_IMAGE;
  151. GetTabCtrl().GetItem(iTab, &tci);
  152. tci.iImage = iImage;
  153. GetTabCtrl().SetItem(iTab, &tci);
  154. }
  155. void CTabbedViewView::SetTabIcon(int iTab, HICON hIcon)
  156. {
  157.     CImageList* pImageList = GetTabCtrl().GetImageList();
  158.     SetTabIcon(iTab, pImageList->Add(hIcon));
  159. }
  160. void CTabbedViewView::OnSelChanging()
  161. {
  162. CXTTabView::OnSelChanging();
  163. // TODO: Add your code to handle tab selection.
  164. }
  165. void CTabbedViewView::OnSelChange()
  166. {
  167. CXTTabView::OnSelChange();
  168. // TODO: Add your code to handle tab selection.
  169. }
  170. void CTabbedViewView::OnInitialUpdate() 
  171. {
  172. CXTTabView::OnInitialUpdate();
  173. // TODO: Add your specialized code here and/or call the base class
  174. }
  175. void CTabbedViewView::OnFileOpen() 
  176. {
  177. // TODO: Add your command handler code here
  178. }
  179. void CTabbedViewView::OnRButtonDown(UINT /*nFlags*/, CPoint point) 
  180. {
  181. // Get the tab index based upon the cursor position.
  182. m_iHitTest = GetTabFromPoint(point);
  183. if (m_iHitTest == -1)
  184. return;
  185. CMenu popupMenu;
  186. VERIFY(popupMenu.CreatePopupMenu());
  187.     popupMenu.AppendMenu(MF_STRING, ID_TAB_ACTIVATE, _T("Active View Tab"));
  188. popupMenu.AppendMenu(MF_SEPARATOR);
  189. popupMenu.AppendMenu(MF_STRING, ID_TAB_CLOSE, _T("&Close"));
  190. popupMenu.AppendMenu(MF_STRING, ID_TAB_SAVE, _T("&SavetCtrl+S"));
  191. popupMenu.AppendMenu(MF_STRING, ID_TAB_SAVE_AS, _T("Save &As..."));
  192. popupMenu.AppendMenu(MF_SEPARATOR);
  193. popupMenu.AppendMenu(MF_STRING, ID_TAB_PRINT, _T("&PrinttCtrl+P"));
  194. popupMenu.AppendMenu(MF_STRING, ID_TAB_PRINT_PREVIEW, _T("Print Pre&view"));
  195.     ::SetMenuDefaultItem(popupMenu.m_hMenu, 0, TRUE);
  196. CPoint pt = point;
  197. ClientToScreen(&pt);
  198. popupMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
  199. pt.x, pt.y, this);
  200. popupMenu.DestroyMenu();
  201. }
  202. void CTabbedViewView::OnCancelMode() 
  203. {
  204. CXTTabView::OnCancelMode();
  205. // TODO: Add your message handler code here
  206. }
  207. void CTabbedViewView::OnTabActivate()
  208. {
  209. // TRACE0("CTabbedViewView::OnTabActivate()n");
  210. SetActiveView(m_iHitTest);
  211. }
  212. void CTabbedViewView::OnTabClose()
  213. {
  214. // TRACE0("CTabbedViewView::OnTabClose()n");
  215. if (GetTabCtrl().GetItemCount() == 1)
  216. {
  217. AfxMessageBox( IDS_CANNOTDEL );
  218. }
  219. else
  220. {
  221. DeleteView(m_iHitTest);
  222. }
  223. }
  224. void CTabbedViewView::OnTabSave()
  225. {
  226. // TRACE0("CTabbedViewView::OnTabSave()n");
  227. GetView(m_iHitTest)->SendMessage(WM_COMMAND, ID_FILE_SAVE);
  228. }
  229. void CTabbedViewView::OnTabSaveAs()
  230. {
  231. // TRACE0("CTabbedViewView::OnTabSaveAs()n");
  232. GetView(m_iHitTest)->SendMessage(WM_COMMAND, ID_FILE_SAVE_AS);
  233. }
  234. void CTabbedViewView::OnTabPrint()
  235. {
  236. // TRACE0("CTabbedViewView::OnTabPrint()n");
  237. GetView(m_iHitTest)->SendMessage(WM_COMMAND, ID_FILE_PRINT);
  238. }
  239. void CTabbedViewView::OnTabPrintPreview()
  240. {
  241. // TRACE0("CTabbedViewView::OnTabPrintPreview()n");
  242. GetView(m_iHitTest)->SendMessage(WM_COMMAND, ID_FILE_PRINT_PREVIEW);
  243. }
  244. void CTabbedViewView::OnTimer(UINT_PTR nIDEvent) 
  245. {
  246.     if (m_nIDEvent == nIDEvent)
  247.     {
  248.         CPoint point;
  249.         ::GetCursorPos(&point);
  250.         ScreenToClient(&point);
  251.         if (m_point == point)
  252.         {
  253.             CTabCtrl& tabCtrl = GetTabCtrl();
  254.             CRect rcItem;
  255.             int iItem;
  256. for (iItem = 0; iItem < tabCtrl.GetItemCount(); ++iItem )
  257.             {
  258.                 tabCtrl.GetItemRect(iItem, &rcItem);
  259.                 if (rcItem.PtInRect(m_point) && tabCtrl.GetCurSel() != iItem)
  260.                 {
  261.                     SetActiveView(iItem);
  262.                     break;
  263.                 }
  264.             }
  265.         }
  266.         
  267.         KillTimer(m_nIDEvent);
  268.     }
  269.     else
  270.     {
  271.         CXTTabView::OnTimer(nIDEvent);
  272.     }
  273. }
  274. void CTabbedViewView::OnMouseMove(UINT nFlags, CPoint point) 
  275. {
  276. CXTTabView::OnMouseMove(nFlags, point);
  277.     m_point = point;
  278.     SetTimer(m_nIDEvent, 2500, NULL);    
  279. }
  280. void CTabbedViewView::UpdateTabBorders()
  281. {
  282. BOOL bIsOfficeTheme = XTThemeManager()->GetTheme() != xtThemeDefault;
  283. DWORD dwAdd    = bIsOfficeTheme ? 0 : WS_EX_CLIENTEDGE;
  284. DWORD dwRemove = bIsOfficeTheme ? WS_EX_CLIENTEDGE : 0;
  285. if (::IsWindow(m_editTab.m_hWnd)) {
  286. m_editTab.ModifyStyleEx(dwRemove, dwAdd);
  287. }
  288. if (::IsWindow(m_treeTabFile.m_hWnd)) {
  289. m_treeTabFile.ModifyStyleEx(dwRemove, dwAdd);
  290. }
  291. if (::IsWindow(m_treeTabClass.m_hWnd)) {
  292. m_treeTabClass.ModifyStyleEx(dwRemove, dwAdd);
  293. }
  294. if (::IsWindow(m_treeTabResource.m_hWnd)) {
  295. m_treeTabResource.ModifyStyleEx(dwRemove, dwAdd);
  296. }
  297. CRect r;
  298. GetWindowRect(&r);
  299. SetWindowPos(NULL, 0,0,r.Width()+1,r.Height(),
  300. SWP_FRAMECHANGED|SWP_NOMOVE);
  301. SetWindowPos(NULL, 0,0,r.Width(),r.Height(),
  302. SWP_FRAMECHANGED|SWP_NOMOVE);
  303. }
  304. void CTabbedViewView::OnCloseTab()
  305. {
  306. if (GetTabCtrl().GetItemCount() == 1)
  307. {
  308. AfxMessageBox( IDS_CANNOTDEL );
  309. }
  310. else
  311. {
  312. DeleteView(GetTabCtrl().GetCurSel());
  313. }
  314. }
  315. DROPEFFECT CTabbedViewView::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point) 
  316. {
  317.     ::GetCursorPos(&point);
  318.     ScreenToClient(&point);
  319. CTabCtrl& tabCtrl = GetTabCtrl();
  320. CRect rcItem;
  321. for (int iItem = 0; iItem < tabCtrl.GetItemCount(); ++iItem )
  322.     {
  323. tabCtrl.GetItemRect(iItem, &rcItem);
  324. if (rcItem.PtInRect(point) && tabCtrl.GetCurSel() != iItem)
  325.         {
  326. SetActiveView(iItem);
  327. break;
  328. }
  329. }
  330.     return CXTTabView::OnDragOver(pDataObject, dwKeyState, point);
  331. }
  332. void CTabbedViewView::OnDropFiles(HDROP hDropInfo) 
  333. {
  334.     CPoint point;
  335.     ::GetCursorPos(&point);
  336.     ScreenToClient(&point);
  337. CTabCtrl& tabCtrl = GetTabCtrl();
  338. CRect rcItem;
  339. for (int iItem = 0; iItem < tabCtrl.GetItemCount(); ++iItem )
  340.     {
  341. tabCtrl.GetItemRect(iItem, &rcItem);
  342. if (rcItem.PtInRect(point))
  343.         {
  344. SetActiveView(iItem);
  345.             CWnd* pView = GetView(iItem);
  346.             if (pView && ::IsWindow(pView->m_hWnd))
  347.     pView->PostMessage(WM_DROPFILES, (WPARAM)hDropInfo, 0L);
  348. break;
  349. }
  350. }
  351. CXTTabView::OnDropFiles(hDropInfo);
  352. }