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.

256 lines
9.4 KiB

  1. #ifndef _DESKHOST_H_
  2. #define _DESKHOST_H_
  3. #include <exdisp.h>
  4. #include <mshtml.h>
  5. #include "dpa.h"
  6. #include "../startmnu.h"
  7. #include <cowsite.h>
  8. #define WC_DV2 TEXT("DV2ControlHost")
  9. // These are in WM_APP range because IsDialogMessage uses
  10. // the WM_USER range and we used to use IsDialogMessage to get our focus
  11. // management right.
  12. #define DHM_DISMISS (WM_APP+0)
  13. #define DesktopHost_Dismiss(hwnd) SendMessage(hwnd, DHM_DISMISS, 0, 0)
  14. EXTERN_C HBITMAP CreateMirroredBitmap(HBITMAP hbm);
  15. class CPopupMenu
  16. {
  17. CPopupMenu() : _cRef(1) { }
  18. ~CPopupMenu();
  19. public:
  20. friend HRESULT CPopupMenu_CreateInstance(IShellMenu *psm,
  21. IUnknown *punkSite,
  22. HWND hwnd,
  23. CPopupMenu **ppmOut);
  24. void AddRef() { _cRef++; }
  25. void Release() { if (--_cRef == 0) delete this; }
  26. BOOL IsSame(IShellMenu *psm)
  27. {
  28. return SHIsSameObject(_psm, psm);
  29. }
  30. // Wrapped method calls
  31. HRESULT Invalidate()
  32. { return _psm->InvalidateItem(NULL, SMINV_REFRESH); }
  33. HRESULT TranslateMenuMessage(MSG *pmsg, LRESULT *plRet)
  34. { return _pmb->TranslateMenuMessage(pmsg, plRet); }
  35. HRESULT OnSelect(DWORD dwSelectType)
  36. { return _pmp->OnSelect(dwSelectType); }
  37. HRESULT IsMenuMessage(MSG *pmsg)
  38. { return _pmb->IsMenuMessage(pmsg); }
  39. HRESULT Popup(RECT *prcExclude, DWORD dwFlags);
  40. private:
  41. HRESULT Initialize(IShellMenu *psm, IUnknown *punkSite, HWND hwnd);
  42. private:
  43. LONG _cRef;
  44. IMenuPopup * _pmp;
  45. IMenuBand * _pmb;
  46. IShellMenu * _psm;
  47. };
  48. class CDesktopHost
  49. : public CUnknown
  50. , public IMenuPopup
  51. , public IMenuBand
  52. , public ITrayPriv2
  53. , public IServiceProvider
  54. , public IOleCommandTarget
  55. , public CObjectWithSite
  56. {
  57. friend class CDeskHostShellMenuCallback;
  58. private:
  59. enum {
  60. IDT_MENUCHANGESEL = 1,
  61. };
  62. enum {
  63. NEWAPP_OFFER_COUNT = 3, // offer up to 3 times
  64. };
  65. private:
  66. HWND _hwnd; // window handle
  67. HTHEME _hTheme;
  68. HWND _hwndChildFocus; // which child last had focus?
  69. IMenuPopup * _pmpTracking; // The popup menu we are tracking
  70. IMenuBand * _pmbTracking; // The menuband we are tracking
  71. LPARAM _itemTracking; // The item that owns the current popup menu
  72. HWND _hwndTracking; // The child window that owns _itemTracking
  73. LPARAM _itemAltTracking; // The item the user has hot-tracked to while viewing a different item's popup menu
  74. HWND _hwndAltTracking; // The child window that owns _itemAltTracking
  75. CPopupMenu * _ppmPrograms; // Cached Programs menu
  76. CPopupMenu * _ppmTracking; // The one that is currently popped up
  77. HWND _hwndNewHandler; // Which window knows which apps are new?
  78. RECT _rcDesired; // The layout gets to specify a desired size
  79. RECT _rcActual; // And then the components can request additional resizing
  80. int _iOfferNewApps; // number of times we should suggest to the
  81. // user that they look at the app that was installed
  82. UINT _wmDragCancel; // user dragged an item off of a submenu
  83. BOOL _fOfferedNewApps; // did we offer new apps this time?
  84. BOOL _fOpen; // Is the menu open for business?
  85. BOOL _fMenuBlocked; // Is menu mode temporarily blocked?
  86. BOOL _fMouseEntered; // Is the mouse inside our window?
  87. BOOL _fAutoCascade; // Should we auto-open on hover?
  88. BOOL _fClipped; // Did we have to pitch some items to fit on screen?
  89. BOOL _fWarnedClipped; // Has the user been warned that it's been clipped?
  90. BOOL _fDismissOnlyPopup; // Are we only dismissing the popup?
  91. HWND _hwndLastMouse; // HWND that received last mousemove message
  92. LPARAM _lParamLastMouse; // LPARAM of last mousemove message
  93. HWND _hwndClipBalloon; // HWND of "you've been clipped!" balloon tip
  94. IFadeTask * _ptFader; // For cool selection fading
  95. SIZE _sizWindowPrev; // previous size of window when we popped up
  96. STARTPANELMETRICS _spm; // start panel metrics
  97. HBITMAP _hbmCachedSnapshot; // This bitmap reflects the current look of the start menu, ready to show!
  98. public:
  99. // *** IUnknown ***
  100. STDMETHODIMP QueryInterface(REFIID riid, void** ppvObj);
  101. STDMETHODIMP_(ULONG) AddRef(void) { return CUnknown::AddRef(); }
  102. STDMETHODIMP_(ULONG) Release(void) { return CUnknown::Release(); }
  103. // *** IOleWindow methods ***
  104. STDMETHODIMP GetWindow(HWND * phwnd) { *phwnd = _hwnd; return S_OK; }
  105. STDMETHODIMP ContextSensitiveHelp(BOOL bEnterMode) { return E_NOTIMPL; }
  106. // *** IDeskBar methods ***
  107. STDMETHODIMP SetClient(IUnknown* punk) { return E_NOTIMPL; };
  108. STDMETHODIMP GetClient(IUnknown** ppunkClient) { return E_NOTIMPL; }
  109. STDMETHODIMP OnPosRectChangeDB (LPRECT prc) { return E_NOTIMPL; }
  110. // *** IMenuPopup methods ***
  111. STDMETHODIMP Popup(POINTL *ppt, RECTL *prcExclude, DWORD dwFlags);
  112. STDMETHODIMP OnSelect(DWORD dwSelectType);
  113. STDMETHODIMP SetSubMenu(IMenuPopup* pmp, BOOL fSet) { return E_NOTIMPL; }
  114. // *** IMenuBand methods ***
  115. STDMETHODIMP IsMenuMessage(MSG *pmsg);
  116. STDMETHODIMP TranslateMenuMessage(MSG *pmsg, LRESULT *plres);
  117. // *** ITrayPriv methods ***
  118. STDMETHODIMP ExecItem(IShellFolder *psf, LPCITEMIDLIST pidl) { return E_NOTIMPL; }
  119. STDMETHODIMP GetFindCM(HMENU hmenu, UINT idFirst, UINT idLast, IContextMenu **ppcmFind) { return E_NOTIMPL; }
  120. STDMETHODIMP GetStaticStartMenu(HMENU* phmenu) { return E_NOTIMPL; }
  121. // *** ITrayPriv2 methods ***
  122. STDMETHODIMP ModifySMInfo(IN LPSMDATA psmd, IN OUT SMINFO *psminfo);
  123. // *** IServiceProvider ***
  124. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppvObj);
  125. // *** IOleCommandTarget ***
  126. STDMETHODIMP QueryStatus(const GUID * pguidCmdGroup,
  127. ULONG cCmds, OLECMD rgCmds[], OLECMDTEXT *pcmdtext);
  128. STDMETHODIMP Exec(const GUID * pguidCmdGroup,
  129. DWORD nCmdID, DWORD nCmdexecopt,
  130. VARIANTARG *pvarargIn, VARIANTARG *pvarargOut);
  131. // *** IObjectWithSite ***
  132. STDMETHODIMP SetSite(IUnknown *punkSite);
  133. public:
  134. HRESULT Initialize();
  135. HRESULT Build();
  136. private:
  137. HWND _Create();
  138. HRESULT _Popup(POINT *ppt, RECT *prcExclude, DWORD dwFlags);
  139. private:
  140. ~CDesktopHost();
  141. static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  142. // Window Messages
  143. void OnCreate(HWND hwnd);
  144. void OnDestroy();
  145. void OnPaint(HDC hdc, BOOL bBackground);
  146. void OnSetFocus(HWND hwndLose);
  147. void OnContextMenu(LPARAM lParam);
  148. void _OnDismiss(BOOL bDestroy);
  149. void _OnMenuChangeSel();
  150. LRESULT OnHaveNewItems(NMHDR *pnm);
  151. LRESULT OnCommandInvoked(NMHDR *pnm);
  152. LRESULT OnFilterOptions(NMHDR *pnm);
  153. LRESULT OnTrackShellMenu(NMHDR *pnm);
  154. void OnSeenNewItems();
  155. LRESULT OnNeedRepaint();
  156. HRESULT TranslatePopupMenuMessage(MSG *pmsg, LRESULT *plres);
  157. // Other helpers
  158. BOOL Register();
  159. void LoadPanelMetrics();
  160. void LoadResourceInt(UINT ids, LONG *pl);
  161. BOOL AddWin32Controls();
  162. BOOL _TryShowBuffered();
  163. void _DismissTrackShellMenu();
  164. void _CleanupTrackShellMenu(); // release + UI-related goo
  165. void _DismissMenuPopup();
  166. BOOL _IsDialogMessage(MSG *pmsg);
  167. BOOL _DlgNavigateArrow(HWND hwndStart, MSG *pmsg);
  168. BOOL _DlgNavigateChar(HWND hwndStart, MSG *pmsg);
  169. HWND _FindNextDlgChar(HWND hwndStart, SMNDIALOGMESSAGE *pnmdm, UINT snmdm);
  170. void _EnableKeyboardCues();
  171. void _MaybeOfferNewApps();
  172. BOOL _ShouldIgnoreFocusChange(HWND hwndFocusRecipient);
  173. void _FilterMouseMove(MSG *pmsg, HWND hwndTarget);
  174. void _FilterMouseLeave(MSG *pmsg, HWND hwndTarget);
  175. void _FilterMouseHover(MSG *pmsg, HWND hwndTarget);
  176. void _RemoveSelection();
  177. void _SubclassTrackShellMenu(IShellMenu *psm);
  178. HRESULT _MenuMouseFilter(LPSMDATA psmd, BOOL fRemove, LPMSG pmsg);
  179. typedef HWND (WINAPI *GETNEXTDLGITEM)(HWND, HWND, BOOL);
  180. HWND _DlgFindItem(HWND hwndStart, SMNDIALOGMESSAGE *pnmdm, UINT smndm,
  181. GETNEXTDLGITEM GetNextDlgItem, UINT fl);
  182. LRESULT _FindChildItem(HWND hwnd, SMNDIALOGMESSAGE *pnmdm, UINT smndm);
  183. void _ReadPaneSizeFromTheme(SMPANEDATA *psmpd);
  184. void _ComputeActualSize(MONITORINFO *pminfo, LPCRECT prcExclude);
  185. void _ChoosePopupPosition(POINT *ppt, LPCRECT prcExclude, LPRECT prcWindow);
  186. void _ReapplyRegion();
  187. void _SaveChildFocus();
  188. HWND _RestoreChildFocus();
  189. void _MaybeShowClipBalloon();
  190. void _DestroyClipBalloon();
  191. };
  192. #endif