-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddressBarHostBand.cpp
342 lines (291 loc) · 7.94 KB
/
AddressBarHostBand.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
* AddressBarHostBand.cpp: Implements the host rebar band for the address bar toolbar.
*
* For the address bar implementation proper, see AddressBar.cpp.
*
* As usual, the window itself is created in the SetSite method.
*
* ================================================================================================
* ---- IMPORTANT FUNCTIONS ----
*
* - SetSite: Installs the toolbar.
* - GetBandInfo: Provides important metadata about the toolbar.
*/
#include "stdafx.h"
#include "framework.h"
#include "resource.h"
#include "ClassicExplorer_i.h"
#include "dllmain.h"
#include <commoncontrols.h>
#include "AddressBarHostBand.h"
static char GetAddressAccelerator()
{
WCHAR szBuffer[64];
// Load "Address" string from resources.
if (!LoadStringW(
_AtlBaseModule.GetResourceInstance(),
IDS_ADDRESSBANDLABEL,
szBuffer,
_countof(szBuffer)
))
{
return L'\0';
}
for (int i = 0; i < _countof(szBuffer); i++)
{
if (szBuffer[i] == L'\0')
break;
if (szBuffer[i - 1] == L'&')
return (char)szBuffer[i];
}
return L'\0';
}
//================================================================================================================
// implement IDeskBand:
//
/*
* GetBandInfo: This is queried by the Shell and must return relevant information about
* the Desk Band.
*/
STDMETHODIMP AddressBarHostBand::GetBandInfo(DWORD dwBandId, DWORD dwViewMode, DESKBANDINFO *pDbi)
{
RECT rc;
SendMessage(m_addressBar.GetToolbar(), TB_GETITEMRECT, 0, (LPARAM)&rc);
int minSize = rc.right;
if (pDbi)
{
if (pDbi->dwMask & DBIM_MINSIZE)
{
RECT rcComboBox;
GetWindowRect(m_addressBar.m_comboBox, &rcComboBox);
pDbi->ptMinSize.x = 150;
pDbi->ptMinSize.y = rcComboBox.bottom - rcComboBox.top;
}
if (pDbi->dwMask & DBIM_MAXSIZE)
{
pDbi->ptMaxSize.x = 0; // 0 = ignored
pDbi->ptMaxSize.y = -1; // -1 = unlimited
}
if (pDbi->dwMask & DBIM_INTEGRAL)
{
// Should not be sizeable.
pDbi->ptIntegral.x = 0;
pDbi->ptIntegral.y = 1;
}
if (pDbi->dwMask & DBIM_ACTUAL)
{
pDbi->ptActual.x = rc.right;
pDbi->ptActual.y = rc.bottom;
}
if (pDbi->dwMask & DBIM_TITLE)
{
// Load "Address" string from resources.
if (!LoadStringW(
_AtlBaseModule.GetResourceInstance(),
IDS_ADDRESSBANDLABEL,
pDbi->wszTitle,
_countof(pDbi->wszTitle)
))
{
return HRESULT_FROM_WIN32(GetLastError());
}
}
if (pDbi->dwMask & DBIM_BKCOLOR)
{
// use default:
pDbi->dwMask &= ~DBIM_BKCOLOR;
}
}
return S_OK;
}
//================================================================================================================
// implement IOleWindow:
//
STDMETHODIMP AddressBarHostBand::GetWindow(HWND *hWnd)
{
if (!hWnd)
{
return E_INVALIDARG;
}
*hWnd = m_addressBar.GetToolbar();
return S_OK;
}
STDMETHODIMP AddressBarHostBand::ContextSensitiveHelp(BOOL fEnterMode)
{
return S_OK;
}
//================================================================================================================
// implement IDockingWindow:
//
STDMETHODIMP AddressBarHostBand::CloseDW(unsigned long dwReserved)
{
return ShowDW(FALSE);
}
STDMETHODIMP AddressBarHostBand::ResizeBorderDW(const RECT *pRcBorder, IUnknown *pUnkToolbarSite, BOOL fReserved)
{
return E_NOTIMPL;
}
STDMETHODIMP AddressBarHostBand::ShowDW(BOOL fShow)
{
ShowWindow(m_addressBar.GetToolbar(), fShow ? SW_SHOW : SW_HIDE);
return S_OK;
}
//================================================================================================================
// implement IObjectWithSite:
//
/*
* SetSite: Responsible for installation or removal of the toolbar band from a location provided
* by the Shell.
*
* This function is additionally responsible for obtaining the shell control APIs and creating
* the actual toolbar control window.
*/
STDMETHODIMP AddressBarHostBand::SetSite(IUnknown *pUnkSite)
{
IObjectWithSiteImpl<AddressBarHostBand>::SetSite(pUnkSite);
if (m_addressBar.IsWindow())
{
m_addressBar.DestroyWindow();
}
// If pUnkSite is not NULL, then the site is being set.
// Otherwise, the site is being removed.
if (pUnkSite) // hook:
{
if (FAILED(pUnkSite->QueryInterface(IID_IInputObjectSite, (void **)&m_pSite)))
{
return E_FAIL;
}
HWND hWndParent = NULL;
CComQIPtr<IOleWindow> pOleWindow = pUnkSite;
if (pOleWindow)
pOleWindow->GetWindow(&hWndParent);
if (!IsWindow(hWndParent))
{
return E_FAIL;
}
m_parentWindow = GetAncestor(hWndParent, GA_ROOT);
// Create the toolbar window proper:
m_addressBar.Create(hWndParent, NULL, NULL, WS_CHILD);
//m_addressBar.CreateBand(hWndParent);
if (!m_addressBar.IsWindow())
{
return E_FAIL;
}
CComQIPtr<IServiceProvider> pProvider = pUnkSite;
if (pProvider)
{
CComPtr<IShellBrowser> pShellBrowser;
pProvider->QueryService(SID_SShellBrowser, IID_IShellBrowser, (void **)&pShellBrowser);
pProvider->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (void **)&m_pWebBrowser);
if (m_pWebBrowser)
{
if (m_dwEventCookie == 0xFEFEFEFE)
{
DispEventAdvise(m_pWebBrowser, &DIID_DWebBrowserEvents2);
}
}
m_addressBar.SetBrowsers(pShellBrowser, m_pWebBrowser);
m_addressBar.InitComboBox();
}
}
else // unhook:
{
m_pSite = NULL;
m_parentWindow = NULL;
}
return S_OK;
}
//================================================================================================================
// handle DWebBrowserEvents2:
//
STDMETHODIMP AddressBarHostBand::OnNavigateComplete(IDispatch *pDisp, VARIANT *url)
{
m_addressBar.HandleNavigate();
return S_OK;
}
/**
* OnQuit: Called when the user attempts to quit the Shell browser.
*
* This detaches the event listener we installed in order to listen for navigation
* events.
*
* Copied from Open-Shell implementation here:
* https://github.com/Open-Shell/Open-Shell-Menu/blob/master/Src/ClassicExplorer/ExplorerBand.cpp#L2280-L2285
*/
STDMETHODIMP AddressBarHostBand::OnQuit()
{
if (m_pWebBrowser && m_dwEventCookie != 0xFEFEFEFE)
{
return DispEventUnadvise(m_pWebBrowser, &DIID_DWebBrowserEvents2);
}
return S_OK;
}
//================================================================================================================
// implement IInputObject:
//
STDMETHODIMP AddressBarHostBand::HasFocusIO()
{
if (
GetFocus() == m_addressBar.m_comboBoxEditCtl ||
::SendMessage(m_addressBar.m_comboBox, CB_GETDROPPEDSTATE, 0, 0)
)
{
return S_OK;
}
else
{
return S_FALSE;
}
}
STDMETHODIMP AddressBarHostBand::TranslateAcceleratorIO(MSG *pMsg)
{
switch (pMsg->message)
{
case WM_SYSCHAR:
{
char szInput[2] = "\0";
szInput[0] = (char)pMsg->wParam;
char szAccelerator[2] = "\0";
szAccelerator[0] = GetAddressAccelerator();
if (lstrcmpiA(szInput, szAccelerator) == 0)
{
//MessageBoxW(NULL, L"FUCK", L"KILL YOURSELF", MB_OK);
::SetFocus(m_addressBar.m_comboBoxEditCtl);
return S_OK;
}
}
break;
}
/*if (pMsg->hwnd == m_addressBar.m_comboBoxEditCtl)
{
switch (pMsg->message)
{
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_SYSCOMMAND:
case WM_SYSDEADCHAR:
case WM_SYSCHAR:
return S_FALSE;
}
TranslateMessage(pMsg);
DispatchMessageW(pMsg);
return S_OK;
}*/
return S_FALSE;
}
STDMETHODIMP AddressBarHostBand::UIActivateIO(BOOL fActivate, MSG *pMsg)
{
if (fActivate)
{
m_pSite->OnFocusChangeIS((IDeskBand *)this, fActivate);
::SetFocus(m_addressBar.m_comboBoxEditCtl);
}
return S_OK;
}
//================================================================================================================
// implement IInputObjectSite:
//
STDMETHODIMP AddressBarHostBand::OnFocusChangeIS(IUnknown *pUnkObj, BOOL fSetFocus)
{
return E_NOTIMPL;
}