Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

382 lines
9.8 KiB

  1. // HMTabViewCtl.cpp : Implementation of the CHMTabViewCtrl ActiveX Control class.
  2. #include "stdafx.h"
  3. #include "HMTabView.h"
  4. #include "HMTabViewCtl.h"
  5. #include "HMTabViewPpg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. IMPLEMENT_DYNCREATE(CHMTabViewCtrl, COleControl)
  12. /////////////////////////////////////////////////////////////////////////////
  13. // Message map
  14. BEGIN_MESSAGE_MAP(CHMTabViewCtrl, COleControl)
  15. //{{AFX_MSG_MAP(CHMTabViewCtrl)
  16. ON_WM_CREATE()
  17. ON_WM_SIZE()
  18. //}}AFX_MSG_MAP
  19. ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  20. END_MESSAGE_MAP()
  21. /////////////////////////////////////////////////////////////////////////////
  22. // Dispatch map
  23. BEGIN_DISPATCH_MAP(CHMTabViewCtrl, COleControl)
  24. //{{AFX_DISPATCH_MAP(CHMTabViewCtrl)
  25. DISP_FUNCTION(CHMTabViewCtrl, "InsertItem", InsertItem, VT_BOOL, VTS_I4 VTS_I4 VTS_BSTR VTS_I4 VTS_I4)
  26. DISP_FUNCTION(CHMTabViewCtrl, "DeleteItem", DeleteItem, VT_BOOL, VTS_I4)
  27. DISP_FUNCTION(CHMTabViewCtrl, "DeleteAllItems", DeleteAllItems, VT_BOOL, VTS_NONE)
  28. DISP_FUNCTION(CHMTabViewCtrl, "CreateControl", CreateControl, VT_BOOL, VTS_I4 VTS_BSTR)
  29. DISP_FUNCTION(CHMTabViewCtrl, "GetControl", GetControl, VT_UNKNOWN, VTS_I4)
  30. //}}AFX_DISPATCH_MAP
  31. DISP_FUNCTION_ID(CHMTabViewCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
  32. END_DISPATCH_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Event map
  35. BEGIN_EVENT_MAP(CHMTabViewCtrl, COleControl)
  36. //{{AFX_EVENT_MAP(CHMTabViewCtrl)
  37. // NOTE - ClassWizard will add and remove event map entries
  38. // DO NOT EDIT what you see in these blocks of generated code !
  39. //}}AFX_EVENT_MAP
  40. END_EVENT_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // Property pages
  43. // TODO: Add more property pages as needed. Remember to increase the count!
  44. BEGIN_PROPPAGEIDS(CHMTabViewCtrl, 1)
  45. PROPPAGEID(CHMTabViewPropPage::guid)
  46. END_PROPPAGEIDS(CHMTabViewCtrl)
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Initialize class factory and guid
  49. IMPLEMENT_OLECREATE_EX(CHMTabViewCtrl, "HMTABVIEW.HMTabViewCtrl.1",
  50. 0x4fffc38c, 0x2f1e, 0x11d3, 0xbe, 0x10, 0, 0, 0xf8, 0x7a, 0x39, 0x12)
  51. /////////////////////////////////////////////////////////////////////////////
  52. // Type library ID and version
  53. IMPLEMENT_OLETYPELIB(CHMTabViewCtrl, _tlid, _wVerMajor, _wVerMinor)
  54. /////////////////////////////////////////////////////////////////////////////
  55. // Interface IDs
  56. const IID BASED_CODE IID_DHMTabView =
  57. { 0x4fffc38a, 0x2f1e, 0x11d3, { 0xbe, 0x10, 0, 0, 0xf8, 0x7a, 0x39, 0x12 } };
  58. const IID BASED_CODE IID_DHMTabViewEvents =
  59. { 0x4fffc38b, 0x2f1e, 0x11d3, { 0xbe, 0x10, 0, 0, 0xf8, 0x7a, 0x39, 0x12 } };
  60. /////////////////////////////////////////////////////////////////////////////
  61. // Control type information
  62. static const DWORD BASED_CODE _dwHMTabViewOleMisc =
  63. OLEMISC_ACTIVATEWHENVISIBLE |
  64. OLEMISC_SETCLIENTSITEFIRST |
  65. OLEMISC_INSIDEOUT |
  66. OLEMISC_CANTLINKINSIDE |
  67. OLEMISC_RECOMPOSEONRESIZE;
  68. IMPLEMENT_OLECTLTYPE(CHMTabViewCtrl, IDS_HMTABVIEW, _dwHMTabViewOleMisc)
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CHMTabViewCtrl::CHMTabViewCtrlFactory::UpdateRegistry -
  71. // Adds or removes system registry entries for CHMTabViewCtrl
  72. BOOL CHMTabViewCtrl::CHMTabViewCtrlFactory::UpdateRegistry(BOOL bRegister)
  73. {
  74. // TODO: Verify that your control follows apartment-model threading rules.
  75. // Refer to MFC TechNote 64 for more information.
  76. // If your control does not conform to the apartment-model rules, then
  77. // you must modify the code below, changing the 6th parameter from
  78. // afxRegApartmentThreading to 0.
  79. if (bRegister)
  80. return AfxOleRegisterControlClass(
  81. AfxGetInstanceHandle(),
  82. m_clsid,
  83. m_lpszProgID,
  84. IDS_HMTABVIEW,
  85. IDB_HMTABVIEW,
  86. afxRegApartmentThreading,
  87. _dwHMTabViewOleMisc,
  88. _tlid,
  89. _wVerMajor,
  90. _wVerMinor);
  91. else
  92. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. // Licensing strings
  96. static const TCHAR BASED_CODE _szLicFileName[] = _T("HMTabView.lic");
  97. static const WCHAR BASED_CODE _szLicString[] =
  98. L"Copyright (c) 1999 Microsoft";
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CHMTabViewCtrl::CHMTabViewCtrlFactory::VerifyUserLicense -
  101. // Checks for existence of a user license
  102. BOOL CHMTabViewCtrl::CHMTabViewCtrlFactory::VerifyUserLicense()
  103. {
  104. return AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName,
  105. _szLicString);
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CHMTabViewCtrl::CHMTabViewCtrlFactory::GetLicenseKey -
  109. // Returns a runtime licensing key
  110. BOOL CHMTabViewCtrl::CHMTabViewCtrlFactory::GetLicenseKey(DWORD dwReserved,
  111. BSTR FAR* pbstrKey)
  112. {
  113. if (pbstrKey == NULL)
  114. return FALSE;
  115. *pbstrKey = SysAllocString(_szLicString);
  116. return (*pbstrKey != NULL);
  117. }
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CHMTabViewCtrl::CHMTabViewCtrl - Constructor
  120. CHMTabViewCtrl::CHMTabViewCtrl()
  121. {
  122. InitializeIIDs(&IID_DHMTabView, &IID_DHMTabViewEvents);
  123. // TODO: Initialize your control's instance data here.
  124. }
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CHMTabViewCtrl::~CHMTabViewCtrl - Destructor
  127. CHMTabViewCtrl::~CHMTabViewCtrl()
  128. {
  129. // TODO: Cleanup your control's instance data here.
  130. }
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CHMTabViewCtrl::OnDraw - Drawing function
  133. void CHMTabViewCtrl::OnDraw(
  134. CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  135. {
  136. pdc->FillSolidRect(rcBounds, GetSysColor(COLOR_3DFACE));
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CHMTabViewCtrl::DoPropExchange - Persistence support
  140. void CHMTabViewCtrl::DoPropExchange(CPropExchange* pPX)
  141. {
  142. ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  143. COleControl::DoPropExchange(pPX);
  144. // TODO: Call PX_ functions for each persistent custom property.
  145. }
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CHMTabViewCtrl::OnResetState - Reset control to default state
  148. void CHMTabViewCtrl::OnResetState()
  149. {
  150. COleControl::OnResetState(); // Resets defaults found in DoPropExchange
  151. // TODO: Reset any other control state here.
  152. }
  153. /////////////////////////////////////////////////////////////////////////////
  154. // CHMTabViewCtrl::AboutBox - Display an "About" box to the user
  155. void CHMTabViewCtrl::AboutBox()
  156. {
  157. CDialog dlgAbout(IDD_ABOUTBOX_HMTABVIEW);
  158. dlgAbout.DoModal();
  159. }
  160. /////////////////////////////////////////////////////////////////////////////
  161. // Operations
  162. void CHMTabViewCtrl::OnSelChangeTabs(int iItem)
  163. {
  164. CCtrlWnd* pWnd = NULL;
  165. for( int i = 0; i < m_Controls.GetSize(); i++ )
  166. {
  167. if( i == iItem )
  168. {
  169. pWnd = m_Controls[i];
  170. }
  171. else
  172. {
  173. m_Controls[i]->ShowWindow(SW_HIDE);
  174. }
  175. }
  176. if( pWnd )
  177. {
  178. pWnd->ShowWindow(SW_SHOW);
  179. pWnd->Invalidate(TRUE);
  180. pWnd->UpdateWindow();
  181. }
  182. }
  183. /////////////////////////////////////////////////////////////////////////////
  184. // CHMTabViewCtrl message handlers
  185. int CHMTabViewCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
  186. {
  187. if (COleControl::OnCreate(lpCreateStruct) == -1)
  188. return -1;
  189. m_TabCtrl.Create( TCS_TABS | TCS_FLATBUTTONS | WS_CHILD | WS_VISIBLE, CRect(0,0,10,10), this, 0x1006);
  190. // init position for the window
  191. int cx=-1;
  192. int cy=-1;
  193. GetControlSize(&cx,&cy);
  194. m_TabCtrl.SetWindowPos(NULL,0,0,cx,cy-2,SWP_NOZORDER|SWP_SHOWWINDOW);
  195. return 0;
  196. }
  197. void CHMTabViewCtrl::OnSize(UINT nType, int cx, int cy)
  198. {
  199. COleControl::OnSize(nType, cx, cy);
  200. if( GetSafeHwnd() )
  201. {
  202. CRect rcControl;
  203. GetClientRect(rcControl);
  204. m_TabCtrl.SetWindowPos(NULL,0,0,rcControl.Width(),rcControl.Height()-2,SWP_NOZORDER|SWP_SHOWWINDOW);
  205. CRect rcDisplay;
  206. m_TabCtrl.GetWindowRect(rcDisplay);
  207. ScreenToClient(rcDisplay);
  208. m_TabCtrl.AdjustRect(FALSE,rcDisplay);
  209. rcDisplay.top += 4;
  210. rcDisplay.bottom -= 8;
  211. for( int i = 0; i < m_Controls.GetSize(); i++ )
  212. {
  213. m_Controls[i]->SetWindowPos(NULL,rcDisplay.left,rcDisplay.top,rcDisplay.Width(),rcDisplay.Height(),SWP_NOZORDER);
  214. if( m_TabCtrl.GetCurSel() != i )
  215. {
  216. m_Controls[i]->ShowWindow(SW_HIDE);
  217. }
  218. }
  219. }
  220. }
  221. BOOL CHMTabViewCtrl::InsertItem(long lMask, long lItem, LPCTSTR lpszItem, long lImage, long lParam)
  222. {
  223. CCtrlWnd* pCtrlWnd = new CCtrlWnd;
  224. if( ! pCtrlWnd->Create(NULL,NULL,WS_CHILD,CRect(0,0,10,10),&m_TabCtrl,500+lItem) )
  225. {
  226. delete pCtrlWnd;
  227. return FALSE;
  228. }
  229. m_Controls.InsertAt(lItem,pCtrlWnd);
  230. CRect rcDisplay;
  231. GetClientRect(rcDisplay);
  232. m_TabCtrl.AdjustRect(FALSE,rcDisplay);
  233. pCtrlWnd->SetWindowPos(NULL,rcDisplay.left,rcDisplay.top,rcDisplay.Width(),rcDisplay.Height(),SWP_NOZORDER);
  234. if( lItem == 0 )
  235. {
  236. pCtrlWnd->ShowWindow(SW_SHOW);
  237. }
  238. else
  239. {
  240. pCtrlWnd->ShowWindow(SW_HIDE);
  241. m_Controls[0]->Invalidate();
  242. m_Controls[0]->UpdateWindow();
  243. }
  244. return m_TabCtrl.InsertItem(lMask,lItem,lpszItem,lImage,lParam);
  245. }
  246. BOOL CHMTabViewCtrl::DeleteItem(long lItem)
  247. {
  248. if( lItem >= m_Controls.GetSize() || lItem < 0 )
  249. {
  250. return FALSE;
  251. }
  252. m_Controls[lItem]->DestroyWindow();
  253. m_Controls.RemoveAt(lItem);
  254. return m_TabCtrl.DeleteItem(lItem);
  255. }
  256. BOOL CHMTabViewCtrl::DeleteAllItems()
  257. {
  258. for( int i = 0; i < m_Controls.GetSize(); i++ )
  259. {
  260. m_Controls[i]->DestroyWindow();
  261. }
  262. return m_TabCtrl.DeleteAllItems();
  263. }
  264. BOOL CHMTabViewCtrl::CreateControl(long lItem, LPCTSTR lpszControlID)
  265. {
  266. if( lItem >= m_Controls.GetSize() || lItem < 0 )
  267. {
  268. return FALSE;
  269. }
  270. CCtrlWnd* pCtrlWnd = m_Controls[lItem];
  271. if( pCtrlWnd == NULL )
  272. {
  273. return FALSE;
  274. }
  275. BOOL bResult = pCtrlWnd->CreateControl(lpszControlID);
  276. pCtrlWnd->ShowWindow(SW_SHOW);
  277. pCtrlWnd->Invalidate();
  278. pCtrlWnd->UpdateWindow();
  279. return bResult;
  280. }
  281. LPUNKNOWN CHMTabViewCtrl::GetControl(long lItem)
  282. {
  283. if( lItem >= m_Controls.GetSize() || lItem < 0 )
  284. {
  285. return NULL;
  286. }
  287. return m_Controls[lItem]->GetControlIUnknown();
  288. }