4 * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 class CStartMenuSite
:
24 public CComCoClass
<CStartMenuSite
>,
25 public CComObjectRootEx
<CComMultiThreadModelNoCS
>,
26 public IServiceProvider
,
28 public IOleCommandTarget
,
31 CComPtr
<ITrayWindow
> m_Tray
;
38 virtual ~CStartMenuSite() {}
40 /*******************************************************************/
42 virtual HRESULT STDMETHODCALLTYPE
QueryService(
43 IN REFGUID guidService
,
47 if (IsEqualGUID(guidService
, SID_SMenuPopup
))
49 return QueryInterface(riid
, ppvObject
);
55 /*******************************************************************/
57 virtual HRESULT STDMETHODCALLTYPE
GetWindow(
60 TRACE("ITrayPriv::GetWindow\n");
62 *phwnd
= m_Tray
->GetHWND();
69 virtual HRESULT STDMETHODCALLTYPE
ContextSensitiveHelp(
72 TRACE("ITrayPriv::ContextSensitiveHelp\n");
76 virtual HRESULT STDMETHODCALLTYPE
Execute(
77 IN IShellFolder
*pShellFolder
,
78 IN LPCITEMIDLIST pidl
)
80 HRESULT ret
= S_FALSE
;
82 TRACE("ITrayPriv::Execute\n");
84 ret
= SHInvokeDefaultCommand(m_Tray
->GetHWND(), pShellFolder
, pidl
);
89 virtual HRESULT STDMETHODCALLTYPE
Unknown(
95 TRACE("ITrayPriv::Unknown(0x%p,0x%p,0x%p,0x%p)\n", Unknown1
, Unknown2
, Unknown3
, Unknown4
);
100 ShowUndockMenuItem(VOID
)
102 TRACE("ShowUndockMenuItem() not implemented!\n");
103 /* FIXME: How do we detect this?! */
108 ShowSynchronizeMenuItem(VOID
)
110 TRACE("ShowSynchronizeMenuItem() not implemented!\n");
111 /* FIXME: How do we detect this?! */
115 virtual HRESULT STDMETHODCALLTYPE
AppendMenu(
118 HMENU hMenu
, hSettingsMenu
;
121 UINT uLastItemsCount
= 5; /* 5 menu items below the last separator */
124 TRACE("ITrayPriv::AppendMenu\n");
126 hMenu
= LoadPopupMenu(hExplorerInstance
, MAKEINTRESOURCEW(IDM_STARTMENU
));
131 /* Remove menu items that don't apply */
133 dwLogoff
= SHRestricted(REST_STARTMENULOGOFF
);
134 bWantLogoff
= (dwLogoff
== 2 ||
135 SHRestricted(REST_FORCESTARTMENULOGOFF
) ||
136 GetExplorerRegValueSet(HKEY_CURRENT_USER
,
138 L
"StartMenuLogoff"));
141 if (!GetExplorerRegValueSet(HKEY_CURRENT_USER
,
143 L
"StartMenuFavorites"))
151 if (SHRestricted(REST_NORECENTDOCSMENU
))
159 hSettingsMenu
= FindSubMenu(hMenu
,
162 if (hSettingsMenu
!= NULL
)
164 if (SHRestricted(REST_NOSETFOLDERS
))
167 if (SHRestricted(REST_NOCONTROLPANEL
))
169 DeleteMenu(hSettingsMenu
,
173 /* Delete the separator below it */
174 DeleteMenu(hSettingsMenu
,
179 /* Network Connections */
180 if (SHRestricted(REST_NONETWORKCONNECTIONS
))
182 DeleteMenu(hSettingsMenu
,
183 IDM_NETWORKCONNECTIONS
,
187 /* Printers and Faxes */
188 DeleteMenu(hSettingsMenu
,
189 IDM_PRINTERSANDFAXES
,
194 if (GetSystemMetrics(SM_REMOTECONTROL
) == 0 ||
195 SHRestricted(REST_NOSECURITY
))
197 DeleteMenu(hSettingsMenu
,
202 if (GetMenuItemCount(hSettingsMenu
) == 0)
211 /* FIXME: Enable after implementing */
212 /* if (SHRestricted(REST_NOFIND)) */
222 if (SHRestricted(REST_NORUN
))
230 if (!ShowSynchronizeMenuItem())
239 if (dwLogoff
!= 1 && bWantLogoff
)
241 /* FIXME: We need a more sophisticated way to determine whether to show
242 or hide it, it might be hidden in too many cases!!! */
244 /* Update Log Off menu item */
245 if (!GetCurrentLoggedOnUserName(szUser
, _countof(szUser
)))
247 szUser
[0] = _T('\0');
250 if (!FormatMenuString(hMenu
,
255 /* We couldn't update the menu item, delete it... */
271 if (GetSystemMetrics(SM_REMOTECONTROL
) == 0)
279 /* Undock computer */
280 if (!ShowUndockMenuItem())
289 if (SHRestricted(REST_NOCLOSE
))
297 if (uLastItemsCount
== 0)
299 /* Remove the separator at the end of the menu */
301 IDM_LASTSTARTMENU_SEPARATOR
,
308 /*******************************************************************/
310 virtual HRESULT STDMETHODCALLTYPE
QueryStatus(
311 IN
const GUID
*pguidCmdGroup OPTIONAL
,
313 IN OUT OLECMD
*prgCmds
,
314 IN OUT OLECMDTEXT
*pCmdText OPTIONAL
)
319 virtual HRESULT STDMETHODCALLTYPE
Exec(
320 IN
const GUID
*pguidCmdGroup OPTIONAL
,
322 IN DWORD nCmdExecOpt
,
323 IN VARIANTARG
*pvaIn OPTIONAL
,
324 IN VARIANTARG
*pvaOut OPTIONAL
)
329 /*******************************************************************/
331 virtual HRESULT STDMETHODCALLTYPE
SetClient(IUnknown
*punkClient
)
336 virtual HRESULT STDMETHODCALLTYPE
GetClient(IUnknown
** ppunkClient
)
341 virtual HRESULT STDMETHODCALLTYPE
OnPosRectChangeDB(RECT
*prc
)
346 virtual HRESULT STDMETHODCALLTYPE
Popup(POINTL
*ppt
, RECTL
*prcExclude
, MP_POPUPFLAGS dwFlags
)
351 virtual HRESULT STDMETHODCALLTYPE
OnSelect(DWORD dwSelectType
)
356 virtual HRESULT STDMETHODCALLTYPE
SetSubMenu(IMenuPopup
*pmp
, BOOL fSet
)
360 return Tray_OnStartMenuDismissed(m_Tray
);
366 /*******************************************************************/
368 HRESULT
Initialize(IN ITrayWindow
*tray
)
374 DECLARE_NOT_AGGREGATABLE(CStartMenuSite
)
376 DECLARE_PROTECT_FINAL_CONSTRUCT()
377 BEGIN_COM_MAP(CStartMenuSite
)
378 COM_INTERFACE_ENTRY_IID(IID_IServiceProvider
, IServiceProvider
)
379 COM_INTERFACE_ENTRY_IID(IID_ITrayPriv
, ITrayPriv
)
380 COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget
, IOleCommandTarget
)
381 COM_INTERFACE_ENTRY_IID(IID_IMenuPopup
, IMenuPopup
)
382 COM_INTERFACE_ENTRY_IID(IID_IOleWindow
, IOleWindow
)
386 HRESULT
CreateStartMenuSite(IN OUT ITrayWindow
*Tray
, const IID
& riid
, PVOID
* ppv
)
388 return ShellObjectCreatorInit
<CStartMenuSite
>(Tray
, riid
, ppv
);