xref: /reactos/base/shell/explorer/startmnu.cpp (revision 84344399)
1 /*
2  * ReactOS Explorer
3  *
4  * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include "precomp.h"
22 
23 HRESULT
24 UpdateStartMenu(IN OUT IMenuPopup *pMenuPopup,
25                 IN HBITMAP hbmBanner  OPTIONAL,
26                 IN BOOL bSmallIcons,
27                 IN BOOL bRefresh)
28 {
29     CComPtr<IBanneredBar> pbb;
30     HRESULT hRet;
31 
32     hRet = pMenuPopup->QueryInterface(IID_PPV_ARG(IBanneredBar, &pbb));
33     if (SUCCEEDED(hRet))
34     {
35         hRet = pbb->SetBitmap(hbmBanner);
36 
37         /* Update the icon size */
38         hRet = pbb->SetIconSize(bSmallIcons ? BMICON_SMALL : BMICON_LARGE);
39     }
40 
41     if (bRefresh)
42     {
43         FIXME("Refresh the Start menu with communicating with SHELL32\n");
44     }
45 
46     return hRet;
47 }
48 
49 IMenuPopup*
50 CreateStartMenu(IN ITrayWindow *Tray,
51                 OUT IMenuBand **ppMenuBand,
52                 IN HBITMAP hbmBanner OPTIONAL,
53                 IN BOOL bSmallIcons)
54 {
55     HRESULT hr;
56     CComPtr<IMenuPopup> pMp;
57     CComPtr<IUnknown> pSms;
58     CComPtr<IMenuBand> pMb;
59     CComPtr<IInitializeObject> pIo;
60     CComPtr<IUnknown> pUnk;
61     CComPtr<IBandSite> pBs;
62     DWORD dwBandId = 0;
63 
64     hr = CStartMenuSite_CreateInstance(Tray, IID_PPV_ARG(IUnknown, &pSms));
65     if (FAILED_UNEXPECTEDLY(hr))
66         return NULL;
67 
68     hr = _CStartMenu_CreateInstance(IID_PPV_ARG(IMenuPopup, &pMp));
69     if (FAILED_UNEXPECTEDLY(hr))
70         return NULL;
71 
72     /* Set the menu site so we can handle messages */
73     hr = IUnknown_SetSite(pMp, pSms);
74     if (FAILED_UNEXPECTEDLY(hr))
75         return NULL;
76 
77     /* Initialize the menu object */
78     hr = pMp->QueryInterface(IID_PPV_ARG(IInitializeObject, &pIo));
79     if (SUCCEEDED(hr))
80         hr = pIo->Initialize();
81     else
82         hr = S_OK;
83 
84     /* Everything is initialized now. Let's get the IMenuBand interface. */
85     if (FAILED_UNEXPECTEDLY(hr))
86         return NULL;
87 
88     hr = pMp->GetClient(&pUnk);
89     if (FAILED_UNEXPECTEDLY(hr))
90         return NULL;
91 
92     hr = pUnk->QueryInterface(IID_PPV_ARG(IBandSite, &pBs));
93     if (FAILED_UNEXPECTEDLY(hr))
94         return NULL;
95 
96     /* Finally we have the IBandSite interface, there's only one
97        band in it that apparently provides the IMenuBand interface */
98     hr = pBs->EnumBands(0, &dwBandId);
99     if (FAILED_UNEXPECTEDLY(hr))
100         return NULL;
101 
102     hr = pBs->GetBandObject(dwBandId, IID_PPV_ARG(IMenuBand, &pMb));
103     if (FAILED_UNEXPECTEDLY(hr))
104         return NULL;
105 
106     UpdateStartMenu(pMp, hbmBanner, bSmallIcons, FALSE);
107 
108     *ppMenuBand = pMb.Detach();
109 
110     return pMp.Detach();
111 }
112