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.

222 lines
5.3 KiB

  1. // SystemGroup.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "snapin.h"
  5. #include "SystemGroup.h"
  6. #include "EventManager.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CSystemGroup
  14. IMPLEMENT_SERIAL(CSystemGroup, CHMObject, 1)
  15. CSystemGroup::CSystemGroup()
  16. {
  17. EnableAutomation();
  18. // To keep the application running as long as an OLE automation
  19. // object is active, the constructor calls AfxOleLockApp.
  20. AfxOleLockApp();
  21. m_nState = HMS_NORMAL;
  22. // create the GUID
  23. GUID ChildGuid;
  24. CoCreateGuid(&ChildGuid);
  25. OLECHAR szGuid[GUID_CCH];
  26. ::StringFromGUID2(ChildGuid, szGuid, GUID_CCH);
  27. CString sGuid = OLE2CT(szGuid);
  28. SetGuid(sGuid);
  29. }
  30. CSystemGroup::~CSystemGroup()
  31. {
  32. // To terminate the application when all objects created with
  33. // with OLE automation, the destructor calls AfxOleUnlockApp.
  34. AfxOleUnlockApp();
  35. }
  36. int CSystemGroup::AddShortcut(CHMObject* pObject)
  37. {
  38. TRACEX(_T("CSystemGroup::AddShortcut\n"));
  39. TRACEARGn(pObject);
  40. if( ! GfxCheckObjPtr(pObject,CHMObject) )
  41. {
  42. TRACE(_T("FAILED : pObject is not a valid pointer.\n"));
  43. return -1;
  44. }
  45. pObject->SetScopePane(GetScopePane());
  46. int iIndex = (int)m_Shortcuts.Add(pObject);
  47. for( int i = 0; i < GetScopeItemCount(); i++ )
  48. {
  49. CScopePaneItem* pItem = pObject->CreateScopeItem();
  50. if( ! pItem->Create(m_pPane,GetScopeItem(i)) )
  51. {
  52. ASSERT(FALSE);
  53. delete pItem;
  54. return -1;
  55. }
  56. if( pObject->GetScopeItemCount() )
  57. {
  58. pItem->SetDisplayNames(pObject->GetScopeItem(0)->GetDisplayNames());
  59. }
  60. else
  61. {
  62. pItem->SetDisplayName(0,pObject->GetName());
  63. }
  64. pItem->SetIconIndex(pObject->GetState());
  65. pItem->SetOpenIconIndex(pObject->GetState());
  66. if( GfxCheckObjPtr(pItem,CHMScopeItem) )
  67. {
  68. ((CHMScopeItem*)pItem)->SetObjectPtr(pObject);
  69. }
  70. int iIndex = GetScopeItem(i)->AddChild(pItem);
  71. pItem->InsertItem(iIndex);
  72. pObject->AddScopeItem(pItem);
  73. }
  74. EvtGetEventManager()->AddSystemShortcutAssociation(GetGuid(),pObject->GetSystemName());
  75. return iIndex;
  76. }
  77. void CSystemGroup::RemoveShortcut(CHMObject* pObject)
  78. {
  79. TRACEX(_T("CSystemGroup::RemoveShortcut\n"));
  80. TRACEARGn(pObject);
  81. if( ! pObject )
  82. {
  83. return;
  84. }
  85. EvtGetEventManager()->RemoveSystemShortcutAssociation(GetGuid(),pObject->GetSystemName());
  86. for( int i = 0; i < m_Shortcuts.GetSize(); i++ )
  87. {
  88. if( m_Shortcuts[i] == pObject )
  89. {
  90. for( int j = pObject->GetScopeItemCount()-1; j >= 0; j-- )
  91. {
  92. CScopePaneItem* pChildItem = pObject->GetScopeItem(j);
  93. if( pChildItem )
  94. {
  95. CHMScopeItem* pParentItem = (CHMScopeItem*)pChildItem->GetParent();
  96. if( pParentItem && pParentItem->GetObjectPtr() == this )
  97. {
  98. pObject->RemoveScopeItem(j);
  99. pParentItem->DestroyChild(pChildItem);
  100. }
  101. }
  102. }
  103. m_Shortcuts.RemoveAt(i);
  104. return;
  105. }
  106. }
  107. }
  108. void CSystemGroup::OnFinalRelease()
  109. {
  110. // When the last reference for an automation object is released
  111. // OnFinalRelease is called. The base class will automatically
  112. // deletes the object. Add additional cleanup required for your
  113. // object before calling the base class.
  114. CHMObject::OnFinalRelease();
  115. }
  116. BEGIN_MESSAGE_MAP(CSystemGroup, CHMObject)
  117. //{{AFX_MSG_MAP(CSystemGroup)
  118. // NOTE - the ClassWizard will add and remove mapping macros here.
  119. //}}AFX_MSG_MAP
  120. END_MESSAGE_MAP()
  121. BEGIN_DISPATCH_MAP(CSystemGroup, CHMObject)
  122. //{{AFX_DISPATCH_MAP(CSystemGroup)
  123. // NOTE - the ClassWizard will add and remove mapping macros here.
  124. //}}AFX_DISPATCH_MAP
  125. END_DISPATCH_MAP()
  126. // Note: we add support for IID_ISystemGroup to support typesafe binding
  127. // from VBA. This IID must match the GUID that is attached to the
  128. // dispinterface in the .ODL file.
  129. // {D9BF4F9D-F673-11D2-BDC4-0000F87A3912}
  130. static const IID IID_ISystemGroup =
  131. { 0xd9bf4f9d, 0xf673, 0x11d2, { 0xbd, 0xc4, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  132. BEGIN_INTERFACE_MAP(CSystemGroup, CHMObject)
  133. INTERFACE_PART(CSystemGroup, IID_ISystemGroup, Dispatch)
  134. END_INTERFACE_MAP()
  135. // {D9BF4F9E-F673-11D2-BDC4-0000F87A3912}
  136. IMPLEMENT_OLECREATE_EX(CSystemGroup, "SnapIn.SystemGroup", 0xd9bf4f9e, 0xf673, 0x11d2, 0xbd, 0xc4, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12)
  137. BOOL CSystemGroup::CSystemGroupFactory::UpdateRegistry(BOOL bRegister)
  138. {
  139. if (bRegister)
  140. return AfxOleRegisterServerClass(m_clsid, m_lpszProgID, m_lpszProgID, m_lpszProgID, OAT_DISPATCH_OBJECT);
  141. else
  142. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  143. }
  144. /////////////////////////////////////////////////////////////////////////////
  145. // CSystemGroup message handlers
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CAllSystemsGroup
  148. IMPLEMENT_SERIAL(CAllSystemsGroup, CSystemGroup, 1)
  149. CAllSystemsGroup::CAllSystemsGroup()
  150. {
  151. EnableAutomation();
  152. // To keep the application running as long as an OLE automation
  153. // object is active, the constructor calls AfxOleLockApp.
  154. AfxOleLockApp();
  155. m_nState = HMS_NORMAL;
  156. // create the GUID
  157. GUID ChildGuid;
  158. CoCreateGuid(&ChildGuid);
  159. OLECHAR szGuid[GUID_CCH];
  160. ::StringFromGUID2(ChildGuid, szGuid, GUID_CCH);
  161. CString sGuid = OLE2CT(szGuid);
  162. SetGuid(sGuid);
  163. }
  164. CAllSystemsGroup::~CAllSystemsGroup()
  165. {
  166. // To terminate the application when all objects created with
  167. // with OLE automation, the destructor calls AfxOleUnlockApp.
  168. AfxOleUnlockApp();
  169. }