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.

423 lines
12 KiB

  1. #ifndef __NmAppletImpl_h__
  2. #define __NmAppletImpl_h__
  3. #define DECLARE_NMAPPLET_CAPS(dwCaps)\
  4. static DWORD _GetNmAppletCaps()\
  5. {\
  6. return dwCaps;\
  7. }
  8. #define DECLARE_NMAPPLET_FILE_OPEN_FILTER(idStringResourceFilter, idStringResourceExt) \
  9. static HRESULT _GetNmAppletFileOpenFilter( LPTSTR szFilter, int cchMaxFilter, LPTSTR szExtension, int cchMaxExtension )\
  10. { HRESULT hr = S_OK;\
  11. DBGENTRY(_GetNmAppletFileOpenFilter);\
  12. if( SUCCEEDED( hr = NmCtlLoadString( idStringResourceFilter, szFilter, cchMaxFilter ) ) )\
  13. {\
  14. hr = NmCtlLoadString( idStringResourceExt, szExtension, cchMaxExtension );\
  15. }\
  16. DBGEXIT_HR(_GetNmAppletFileOpenFilter,hr);\
  17. return hr;\
  18. }
  19. template <class T>
  20. class ATL_NO_VTABLE INmAppletImpl
  21. {
  22. // YOU MUST ONLY PUT DATA MEMBERS OR HELPER FNS AT THE END OF THE CLASS
  23. // THE VTABLE FOR INmAgendaItemView MUST BE AT THE BEGINNING OF THE CLASS!!!!
  24. public:
  25. INmAppletImpl( void )
  26. : m_bInsertFileMenuIntoEditGroup( false )
  27. {
  28. DBGENTRY(INmAppletImpl::INmAppletImpl);
  29. DBGEXIT(INmAppletImpl::INmAppletImpl);
  30. }
  31. ~INmAppletImpl( void )
  32. {
  33. DBGENTRY(INmAppletImpl::~INmAppletImpl);
  34. DBGEXIT(INmAppletImpl::~INmAppletImpl);
  35. }
  36. public:
  37. // IUnknown
  38. //
  39. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObject) = 0;
  40. _ATL_DEBUG_ADDREF_RELEASE_IMPL(INmAppletImpl)
  41. // The INmApplet Interface...
  42. STDMETHOD(get_NmAppletCaps)( OUT DWORD* pdwCaps )
  43. {
  44. DBGENTRY(INmAppletImpl::get_NmAppletCaps)
  45. HRESULT hr = S_OK;
  46. ASSERT( pdwCaps != NULL );
  47. *pdwCaps = T::_GetNmAppletCaps();
  48. DBGEXIT_HR(INmAppletImpl::get_NmAppletCaps ,hr)
  49. return hr;
  50. }
  51. STDMETHOD(SaveDialog)( /*[in, out, retval]*/ LPTSTR lpszFile, /*[in]*/ DWORD dwFlags, /*[out]*/ LPWORD pnFileOffset )
  52. {
  53. DBGENTRY(INmAppletImpl::SaveDialog)
  54. HRESULT hr = S_OK;
  55. T* pT = static_cast<T*>(this);
  56. TCHAR szFilter[MAX_PATH];
  57. TCHAR szDefExt[MAX_PATH];
  58. if( SUCCEEDED ( hr = T::_GetNmAppletFileOpenFilter( szFilter, CCHMAX( szFilter ), szDefExt, CCHMAX( szDefExt ) ) ) )
  59. {
  60. ConvertSzCh(szFilter);
  61. OPENFILENAME ofn;
  62. ClearStruct( &ofn );
  63. ofn.lStructSize = sizeof( OPENFILENAME );
  64. ofn.hwndOwner = pT->m_hWnd;
  65. ofn.lpstrFilter = szFilter;
  66. ofn.lpstrFile = lpszFile;
  67. ofn.nMaxFile = MAX_PATH;
  68. ofn.lpstrDefExt = szDefExt;
  69. ofn.Flags = dwFlags;
  70. if( !GetSaveFileName( &ofn ) )
  71. {
  72. hr = E_FAIL;
  73. }
  74. else
  75. {
  76. *pnFileOffset = ofn.nFileOffset;
  77. }
  78. }
  79. DBGEXIT_HR(INmAppletImpl::SaveDialog,hr)
  80. return hr;
  81. }
  82. STDMETHOD(OpenDialog)()
  83. {
  84. DBGENTRY(INmAppletImpl::OpenDialog)
  85. HRESULT hr = E_NOTIMPL;
  86. DBGEXIT_HR(INmAppletImpl::OpenDialog,hr)
  87. return hr;
  88. }
  89. STDMETHOD(GetIconBitmaps)( IN int cxBitmap, IN int cyBitmap,
  90. OUT int* pcStates,
  91. OUT HBITMAP** pphBitmapIcon,
  92. OUT HBITMAP** pphBitmapIconHot,
  93. OUT HBITMAP** pphBitmapIconDisabled
  94. )
  95. {
  96. DBGENTRY(INmAppletImpl::GetIconBitmaps)
  97. HRESULT hr = E_NOTIMPL;
  98. DBGEXIT_HR(INmAppletImpl::GetIconBitmaps,hr)
  99. return hr;
  100. }
  101. STDMETHOD(GetIconLabel)( OUT BSTR* pLabel )
  102. {
  103. DBGENTRY(INmAppletImpl::GetIconLabel)
  104. HRESULT hr = E_NOTIMPL;
  105. DBGEXIT_HR(INmAppletImpl::GetIconLabel,hr)
  106. return hr;
  107. }
  108. STDMETHOD(OnContainerActivating)( IN BOOL bAppActivating )
  109. {
  110. DBGENTRY(INmAppletImpl::OnContainerActivating)
  111. HRESULT hr = S_OK;
  112. DBGEXIT_HR(INmAppletImpl::OnContainerActivating,hr)
  113. return hr;
  114. }
  115. STDMETHOD(SetFocus)()
  116. {
  117. DBGENTRY(INmAppletImpl::SetFocus)
  118. HRESULT hr = S_OK;
  119. DBGEXIT_HR(INmAppletImpl::SetFocus,hr)
  120. return hr;
  121. }
  122. STDMETHOD(SetClientSite)( IN INmAppletClientSite* pClientSite )
  123. {
  124. DBGENTRY(INmAppletImpl::SetClientSite);
  125. HRESULT hr = S_OK;
  126. m_spContianerAppletSite = pClientSite;
  127. DBGEXIT_HR(INmAppletImpl::SetClientSite,hr);
  128. return hr;
  129. }
  130. STDMETHOD(ShiftFocus)( IN HWND hWndCur, BOOL bForward )
  131. {
  132. DBGENTRY(INmAppletImpl::ShiftFocus);
  133. HRESULT hr = S_OK;
  134. DBGEXIT_HR(INmAppletImpl::ShiftFocus,hr);
  135. return hr;
  136. }
  137. STDMETHOD(IsChild)( IN HWND hWnd )
  138. {
  139. DBGENTRY(INmAppletImpl::IsChild);
  140. HRESULT hr = S_FALSE;
  141. DBGEXIT_HR(INmAppletImpl::IsChild,hr);
  142. return hr;
  143. }
  144. STDMETHOD(QueryEndSession)( OUT BOOL* pbCancelTermination )
  145. {
  146. DBGENTRY(INmAppletImpl::QueryEndSession);
  147. HRESULT hr = S_OK;
  148. if( pbCancelTermination )
  149. {
  150. *pbCancelTermination = FALSE;
  151. }
  152. else
  153. {
  154. hr = E_POINTER;
  155. }
  156. DBGEXIT_HR(INmAppletImpl::QueryEndSession,hr);
  157. return hr;
  158. }
  159. STDMETHOD(OnMenuSelect)( IN DWORD wParam, IN DWORD lParam )
  160. {
  161. DBGENTRY(INmAppletImpl::OnMenuSelect);
  162. HRESULT hr = S_OK;
  163. DBGEXIT_HR(INmAppletImpl::OnMenuSelect,hr);
  164. return hr;
  165. }
  166. STDMETHOD(OnCommand)( IN DWORD wParam, IN DWORD lParam )
  167. {
  168. DBGENTRY(INmAppletImpl::OnCommand);
  169. HRESULT hr = S_OK;
  170. DBGEXIT_HR(INmAppletImpl::OnCommand,hr);
  171. return hr;
  172. }
  173. STDMETHOD(OnGetMinMax)( IN DWORD lParam )
  174. {
  175. DBGENTRY(INmAppletImpl::OnGetMinMax);
  176. HRESULT hr = S_OK;
  177. DBGEXIT_HR(INmAppletImpl::OnGetMinMax,hr);
  178. return hr;
  179. }
  180. static DWORD _GetNmAppletCaps() { return 0; }
  181. protected:
  182. // PUT data members here
  183. bool m_bInsertFileMenuIntoEditGroup;
  184. CComPtr<INmAppletClientSite> m_spContianerAppletSite;
  185. };
  186. static HRESULT _MoveMenuToSharedMenu( HMENU hMenu, HMENU hMenuShared, int MenuBarIndex, int InsertionIndex )
  187. {
  188. DBGENTRY(MoveMenuToSharedMenu);
  189. HRESULT hr = S_OK;
  190. if( IsMenu( hMenu ) && IsMenu( hMenuShared ) )
  191. {
  192. TCHAR szMenuItem[ MAX_PATH ] = TEXT("");
  193. int cbMenuItem = 0;
  194. MENUITEMINFO mii;
  195. ClearStruct( &mii );
  196. mii.cbSize = sizeof(MENUITEMINFO);
  197. mii.fMask = MIIM_DATA | MIIM_SUBMENU | MIIM_TYPE;
  198. mii.fType = MFT_STRING;
  199. cbMenuItem = GetMenuString( hMenu, MenuBarIndex, szMenuItem, MAX_PATH, MF_BYPOSITION );
  200. if( 0 != cbMenuItem )
  201. {
  202. mii.cch = 1 + cbMenuItem;
  203. mii.dwTypeData = szMenuItem;
  204. mii.hSubMenu = GetSubMenu( hMenu, MenuBarIndex );
  205. RemoveMenu( hMenu, MenuBarIndex, MF_BYPOSITION );
  206. if( 0 == InsertMenuItem( hMenuShared, InsertionIndex, TRUE, &mii ) )
  207. {
  208. ERROR_OUT(("InsertMenuItem failed"));
  209. hr = HRESULT_FROM_WIN32(GetLastError());
  210. }
  211. }
  212. else
  213. {
  214. ERROR_OUT(("GetMenuString failed"));
  215. hr = E_FAIL;
  216. }
  217. }
  218. else
  219. {
  220. ERROR_OUT(("Passed a bad menu handle"));
  221. hr = E_HANDLE;
  222. }
  223. DBGEXIT_HR( MoveMenuToSharedMenu, hr );
  224. return hr;
  225. }
  226. inline STDMETHODIMP NmApplet_UIActivate(LONG iVerb,
  227. const RECT* prcPosRect,
  228. CComControlBase* pThis,
  229. HMENU* phMenuShared,
  230. DWORD dwMenuResourceID,
  231. int nEditGroupMenuBarItems,
  232. int nObjectGroupMenuBarItems,
  233. int nHelpGroupMenuBarItems
  234. )
  235. {
  236. DBGENTRY(Applet_UIActivate);
  237. HRESULT hr = S_OK;
  238. bool bPreviouslyActiveUI = pThis->m_bUIActive;
  239. // CComControlBase::InPlaceActivawe may change the state of m_bUIActive
  240. // which would indicate that we are UI activating for the first time...
  241. hr = pThis->InPlaceActivate( iVerb, NULL );
  242. if( SUCCEEDED( hr ) && (!bPreviouslyActiveUI) && pThis->m_bUIActive )
  243. {
  244. OLEINPLACEFRAMEINFO frameInfo;
  245. RECT rcPos, rcClip;
  246. CComPtr<IOleInPlaceFrame> spInPlaceFrame;
  247. CComPtr<IOleInPlaceUIWindow> spInPlaceUIWindow;
  248. ClearStruct(&frameInfo);
  249. frameInfo.cb = sizeof(OLEINPLACEFRAMEINFO);
  250. CComPtr<IOleInPlaceObject> pIPO;
  251. pThis->ControlQueryInterface(IID_IOleInPlaceObject, (void**)&pIPO);
  252. _ASSERTE(pIPO != NULL);
  253. if (prcPosRect != NULL)
  254. {
  255. pIPO->SetObjectRects(prcPosRect, prcPosRect);
  256. }
  257. if( pThis->m_spInPlaceSite )
  258. {
  259. hr = pThis->m_spInPlaceSite->GetWindowContext(&spInPlaceFrame, &spInPlaceUIWindow, &rcPos, &rcClip, &frameInfo);
  260. if( spInPlaceFrame )
  261. {
  262. // Create the shared menu...
  263. *phMenuShared = ::CreateMenu();
  264. if( NULL != *phMenuShared )
  265. {
  266. OLEMENUGROUPWIDTHS mgw;
  267. ClearStruct( &mgw );
  268. if( SUCCEEDED( hr = spInPlaceFrame->InsertMenus(*phMenuShared, &mgw) ) )
  269. {
  270. HMENU hMenu = LoadMenu( _Module.GetModuleInstance(), MAKEINTRESOURCE( dwMenuResourceID ) );
  271. if( hMenu )
  272. {
  273. int InsertionIndex, i;
  274. // Edit Group
  275. InsertionIndex = mgw.width[0];
  276. for( i = 0; i < nEditGroupMenuBarItems; i++ )
  277. {
  278. _MoveMenuToSharedMenu( hMenu, *phMenuShared, 0, InsertionIndex + i );
  279. }
  280. mgw.width[1] = nEditGroupMenuBarItems;
  281. // Object Group
  282. InsertionIndex = mgw.width[0] + mgw.width[1] + mgw.width[2];
  283. for( i = 0; i < nObjectGroupMenuBarItems; i++ )
  284. {
  285. _MoveMenuToSharedMenu( hMenu, *phMenuShared, 0, InsertionIndex + i );
  286. }
  287. mgw.width[3] = nObjectGroupMenuBarItems; // Object Group
  288. // Help Group
  289. InsertionIndex = mgw.width[0] + mgw.width[1] + mgw.width[2] + mgw.width[3] + mgw.width[4];
  290. for( i = 0; i < nHelpGroupMenuBarItems; i++ )
  291. {
  292. _MoveMenuToSharedMenu( hMenu, *phMenuShared, 0, InsertionIndex + i );
  293. }
  294. mgw.width[5] = nHelpGroupMenuBarItems; // Help Group
  295. HOLEMENU hOLEMENU = OleCreateMenuDescriptor( *phMenuShared, &mgw );
  296. if( hOLEMENU )
  297. {
  298. hr = spInPlaceFrame->SetMenu( *phMenuShared, hOLEMENU, pThis->m_hWndCD );
  299. }
  300. else
  301. {
  302. hr = E_OUTOFMEMORY;
  303. }
  304. DestroyMenu(hMenu);
  305. }
  306. else
  307. {
  308. hr = HRESULT_FROM_WIN32(GetLastError());
  309. }
  310. }
  311. else
  312. {
  313. DestroyMenu( *phMenuShared );
  314. *phMenuShared = NULL;
  315. }
  316. }
  317. else
  318. {
  319. hr = HRESULT_FROM_WIN32(GetLastError());
  320. ERROR_OUT(("Could not create menu..."));
  321. }
  322. }
  323. }
  324. else
  325. {
  326. hr = E_UNEXPECTED;
  327. }
  328. }
  329. DBGEXIT_HR(Applet_UIActivate,hr);
  330. return hr;
  331. }
  332. #endif // __NmAppletImpl_h__