Leaked source code of windows server 2003
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.

390 lines
8.4 KiB

  1. #include "Precomp.h"
  2. #include "Resource.h"
  3. #include "confroom.h"
  4. #include "ias.h"
  5. #include "NmEnum.h"
  6. #include "SDKInternal.h"
  7. #include "NmConference.h"
  8. #include "NmChannel.h"
  9. #include "NmChannelAppShare.h"
  10. #include "NmSharableApp.h"
  11. #include "SDKWindow.h"
  12. CNmChannelAppShareObj::CNmChannelAppShareObj()
  13. {
  14. DBGENTRY(CNmChannelAppShareObj::CNmChannelAppShareObj);
  15. DBGEXIT(CNmChannelAppShareObj::CNmChannelAppShareObj);
  16. }
  17. CNmChannelAppShareObj::~CNmChannelAppShareObj()
  18. {
  19. DBGENTRY(CNmChannelAppShareObj::~CNmChannelAppShareObj);
  20. for(int j = 0; j < m_ArySharableApps.GetSize(); ++j)
  21. {
  22. m_ArySharableApps[j]->Release();
  23. }
  24. m_ArySharableApps.RemoveAll();
  25. DBGEXIT(CNmChannelAppShareObj::~CNmChannelAppShareObj);
  26. }
  27. //static
  28. HRESULT CNmChannelAppShareObj::CreateInstance(CNmConferenceObj* pConfObj, INmChannel** ppChannel)
  29. {
  30. DBGENTRY(CNmChannelAppShareObj::CreateInstance);
  31. HRESULT hr = S_OK;
  32. typedef CNmChannel<CNmChannelAppShareObj, &IID_INmChannelAppShare, NMCH_SHARE> channel_type;
  33. channel_type* p = NULL;
  34. p = new CComObject<channel_type>(NULL);
  35. if (p != NULL)
  36. {
  37. if(ppChannel)
  38. {
  39. p->SetVoid(NULL);
  40. hr = p->QueryInterface(IID_INmChannel, reinterpret_cast<void**>(ppChannel));
  41. if(SUCCEEDED(hr))
  42. {
  43. // We don't have to RefCount this because our lifetime is
  44. // contained in the CConf's lifetime
  45. p->m_pConfObj = pConfObj;
  46. }
  47. if(FAILED(hr))
  48. {
  49. *ppChannel = NULL;
  50. }
  51. }
  52. else
  53. {
  54. hr = E_POINTER;
  55. }
  56. }
  57. else
  58. {
  59. hr = E_OUTOFMEMORY;
  60. }
  61. if(FAILED(hr))
  62. {
  63. delete p;
  64. }
  65. DBGEXIT_HR(CNmChannelAppShareObj::CreateInstance,hr);
  66. return hr;
  67. }
  68. ///////////////////////////////////////////////////////////////////////////////////
  69. // INmChannelAppShare methods
  70. ///////////////////////////////////////////////////////////////////////////////////
  71. STDMETHODIMP CNmChannelAppShareObj::GetState(NM_SHARE_STATE *puState)
  72. {
  73. DBGENTRY(CNmChannelAppShareObj::GetState);
  74. HRESULT hr = E_UNEXPECTED;
  75. INmMember* pMember = GetConfObj()->GetLocalSDKMember();
  76. if(pMember)
  77. {
  78. hr = pMember->GetShareState(puState);
  79. }
  80. DBGEXIT_HR(CNmChannelAppShareObj::GetState,hr);
  81. return hr;
  82. }
  83. STDMETHODIMP CNmChannelAppShareObj::SetState(NM_SHARE_STATE uState)
  84. {
  85. DWORD uf;
  86. HRESULT hr = S_OK;
  87. if (!(S_OK == IsActive()))
  88. return E_FAIL;
  89. if(!GetConfObj() || !GetConfObj()->GetLocalSDKMember())
  90. {
  91. return E_UNEXPECTED;
  92. }
  93. if(NM_SHARE_UNKNOWN)
  94. {
  95. return E_FAIL;
  96. }
  97. else
  98. {
  99. if(NM_SHARE_WORKING_ALONE == uState)
  100. {
  101. return ::AllowControl(false);
  102. }
  103. if(NM_SHARE_COLLABORATING == uState)
  104. {
  105. return ::AllowControl(true);
  106. }
  107. if(NM_SHARE_IN_CONTROL == uState)
  108. {
  109. NM_SHARE_STATE uCurrentState;
  110. if(SUCCEEDED(hr = GetState(&uCurrentState)))
  111. {
  112. if(NM_SHARE_COLLABORATING == uCurrentState)
  113. {
  114. // Yank control from the person that is controlling you
  115. return ::RevokeControl(0);
  116. }
  117. }
  118. else
  119. {
  120. return hr;
  121. }
  122. return ::AllowControl(true);
  123. }
  124. }
  125. return E_UNEXPECTED;
  126. }
  127. //static
  128. HRESULT CNmChannelAppShareObj::GetSharableAppName(HWND hWnd, LPTSTR sz, UINT cchMax)
  129. {
  130. HRESULT hr = S_OK;
  131. ASSERT(sz);
  132. ::GetWindowText(hWnd, sz, cchMax);
  133. return hr;
  134. }
  135. static INmSharableApp* _SharableAppAryHasThisHWND(CSimpleArray<INmSharableApp*>& ArySharableApps, HWND hWnd)
  136. {
  137. for(int i = 0; i < ArySharableApps.GetSize(); ++i)
  138. {
  139. HWND h;
  140. if(SUCCEEDED(ArySharableApps[i]->GetHwnd(&h)))
  141. {
  142. if(hWnd == h) return ArySharableApps[i];
  143. }
  144. }
  145. return NULL;
  146. }
  147. STDMETHODIMP CNmChannelAppShareObj::EnumSharableApp(IEnumNmSharableApp **ppEnum)
  148. {
  149. DBGENTRY(CNmChannelAppShareObj::EnumSharableApp);
  150. HRESULT hr = E_UNEXPECTED;
  151. IAS_HWND_ARRAY* pAry;
  152. hr = ::GetShareableApps(&pAry);
  153. if(SUCCEEDED(hr))
  154. {
  155. for(UINT i = 0; i < pAry->cEntries; ++i)
  156. {
  157. HWND hWnd = pAry->aEntries[i].hwnd;
  158. TCHAR szName[MAX_PATH];
  159. if(!_SharableAppAryHasThisHWND(m_ArySharableApps, hWnd))
  160. {
  161. hr = GetSharableAppName(hWnd, szName, CCHMAX(szName));
  162. if(FAILED(hr)) goto end;
  163. INmSharableApp* pApp;
  164. hr = CNmSharableAppObj::CreateInstance(hWnd, szName, &pApp);
  165. if(SUCCEEDED(hr))
  166. {
  167. m_ArySharableApps.Add(pApp);
  168. }
  169. }
  170. }
  171. hr = CreateEnumFromSimpleAryOfInterface<IEnumNmSharableApp, INmSharableApp>(m_ArySharableApps, ppEnum);
  172. FreeShareableApps(pAry);
  173. }
  174. end:
  175. DBGEXIT_HR(CNmChannelAppShareObj::EnumSharableApp,hr);
  176. return hr;
  177. }
  178. ///////////////////////////////////////////////////////////////////////////////
  179. // IInternalChannelObj methods
  180. ///////////////////////////////////////////////////////////////////////////////
  181. STDMETHODIMP CNmChannelAppShareObj::GetInternalINmChannel(INmChannel** ppChannel)
  182. {
  183. DBGENTRY(CNmChannelAppShareObj::GetInternalINmChannel);
  184. HRESULT hr = S_OK;
  185. if(ppChannel)
  186. {
  187. hr = GetUnknown()->QueryInterface(IID_INmChannel, reinterpret_cast<void**>(ppChannel));
  188. }
  189. else
  190. {
  191. hr = E_POINTER;
  192. }
  193. DBGEXIT_HR(CNmChannelAppShareObj::GetInternalINmChannel,hr);
  194. return hr;
  195. }
  196. HRESULT CNmChannelAppShareObj::ChannelRemoved()
  197. {
  198. HRESULT hr = S_OK;
  199. RemoveMembers();
  200. CNmConferenceObj* pConfObj = GetConfObj();
  201. if(pConfObj)
  202. {
  203. hr = pConfObj->Fire_ChannelChanged(NM_CHANNEL_REMOVED, com_cast<INmChannel>(GetUnknown()));
  204. }
  205. else
  206. {
  207. ERROR_OUT(("ChannelRemoved, but no ConfObject"));
  208. hr = E_UNEXPECTED;
  209. }
  210. return hr;
  211. }
  212. // interface INmChannelAppShareNotify methods
  213. STDMETHODIMP CNmChannelAppShareObj::StateChanged(NM_SHAPP_STATE uState,INmSharableApp *pApp)
  214. {
  215. if(pApp)
  216. {
  217. HWND hWnd;
  218. if(SUCCEEDED(pApp->GetHwnd(&hWnd)))
  219. {
  220. INmSharableApp* pExistingApp = _SharableAppAryHasThisHWND(m_ArySharableApps, hWnd);
  221. if(!pExistingApp)
  222. {
  223. pExistingApp = pApp;
  224. pExistingApp->AddRef();
  225. m_ArySharableApps.Add(pExistingApp);
  226. }
  227. Fire_StateChanged(uState, pExistingApp);
  228. }
  229. }
  230. return S_OK;
  231. }
  232. ///////////////////////////////////////////////////////////////////////////////
  233. // Helpers
  234. ///////////////////////////////////////////////////////////////////////////////
  235. HRESULT CNmChannelAppShareObj::Fire_MemberChanged(NM_MEMBER_NOTIFY uNotify, INmMember *pMember)
  236. {
  237. DBGENTRY(CNmChannelAppShareObj::Fire_MemberChanged);
  238. HRESULT hr = S_OK;
  239. /////////////////////////////////////////////////////
  240. // INmChannelNotify
  241. /////////////////////////////////////////////////////
  242. IConnectionPointImpl<CNmChannelAppShareObj, &IID_INmChannelNotify, CComDynamicUnkArray>* pCP = this;
  243. for(int i = 0; i < pCP->m_vec.GetSize(); ++i )
  244. {
  245. INmChannelNotify* pNotify = reinterpret_cast<INmChannelNotify*>(pCP->m_vec.GetAt(i));
  246. if(pNotify)
  247. {
  248. pNotify->MemberChanged(uNotify, pMember);
  249. }
  250. }
  251. /////////////////////////////////////////////////////
  252. // INmChannelNotify2
  253. /////////////////////////////////////////////////////
  254. IConnectionPointImpl<CNmChannelAppShareObj, &IID_INmChannelAppShareNotify, CComDynamicUnkArray>* pCP2 = this;
  255. for(i = 0; i < pCP2->m_vec.GetSize(); ++i )
  256. {
  257. INmChannelAppShareNotify* pNotify2 = reinterpret_cast<INmChannelAppShareNotify*>(pCP2->m_vec.GetAt(i));
  258. if(pNotify2)
  259. {
  260. pNotify2->MemberChanged(uNotify, pMember);
  261. }
  262. }
  263. DBGEXIT_HR(CNmChannelAppShareObj::Fire_MemberChanged,hr)
  264. return hr;
  265. }
  266. extern bool g_bSDKPostNotifications;
  267. HRESULT CNmChannelAppShareObj::Fire_StateChanged(NM_SHAPP_STATE uNotify, INmSharableApp *pApp)
  268. {
  269. DBGENTRY(CNmChannelAppShareObj::Fire_StateChanged);
  270. HRESULT hr = S_OK;
  271. if(!g_bSDKPostNotifications)
  272. {
  273. /////////////////////////////////////////////////////
  274. // INmChannelAppShareNotify
  275. /////////////////////////////////////////////////////
  276. IConnectionPointImpl<CNmChannelAppShareObj, &IID_INmChannelAppShareNotify, CComDynamicUnkArray>* pCP2 = this;
  277. for(int i = 0; i < pCP2->m_vec.GetSize(); ++i )
  278. {
  279. INmChannelAppShareNotify* pNotify2 = reinterpret_cast<INmChannelAppShareNotify*>(pCP2->m_vec.GetAt(i));
  280. if(pNotify2)
  281. {
  282. pNotify2->StateChanged(uNotify, pApp);
  283. }
  284. }
  285. }
  286. else
  287. {
  288. CSDKWindow::PostStateChanged(this, uNotify, pApp);
  289. }
  290. DBGEXIT_HR(CNmChannelAppShareObj::Fire_StateChanged,hr)
  291. return hr;
  292. }
  293. HRESULT CNmChannelAppShareObj::_IsActive()
  294. {
  295. DBGENTRY(CNmChannelAppShareObj::_IsActive);
  296. return GetbActive() ? S_OK : S_FALSE;
  297. }
  298. HRESULT CNmChannelAppShareObj::_SetActive(BOOL bActive)
  299. {
  300. if (GetbActive() == bActive)
  301. return S_FALSE;
  302. return E_FAIL;
  303. }