xoblite™ / Blackbox for Windows bb5 | RC6 preview | 0.25.2.14
http://xoblite.net/
Dock.cpp File Reference
#include "Dock.h"

Functions

LRESULT CALLBACK DockWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 

Variables

const char szDockName [] = "BBSlit"
 
DockpDock
 
BImagepBImage
 
SettingspSettings
 
MenuCommonpMenuCommon
 
PluginManagerpPluginManager
 
TaskbarpTaskbar
 
int dockMessageSubscription [] = { BB_TOGGLEDOCK, BB_RECONFIGURE, 0 }
 

Function Documentation

◆ DockWndProc()

LRESULT CALLBACK DockWndProc ( HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam )
134{
135 switch (message)
136 {
137 //====================
138
139 case WM_PAINT:
140 {
141 PAINTSTRUCT ps;
142 HDC hdc = BeginPaint(pDock->hDockWnd, &ps);
143
144 // If we have not yet created a cached background, let's do that...
145 if (!pDock->cachedBackgroundExists)
146 {
147
148 HBITMAP tempBitmap = CreateCompatibleBitmap(hdc, pDock->DockWidth, pDock->DockHeight);
149 DeleteObject(SelectObject(pDock->cachedBackground, tempBitmap));
150
151 // Draw dock background... (nb. as per the current style+settings if the dock is not empty, highly transparent black with white --- tag if the dock is empty)
152 RECT r;
153 GetClientRect(hwnd, &r);
154 if (pDock->DockPlugins.size() > 0)
155 {
156 if (pSettings->Dock->type == B_IMAGEFROMFILE) DrawImageIntoRect(pDock->cachedBackground, r, pSettings->Dock, false, true);
157 else MakeGradientSuper(pDock->cachedBackground, r, pSettings->Dock->type, pSettings->Dock->Color1, pSettings->Dock->Color2, pSettings->Dock->Color3, pSettings->Dock->Color4, pSettings->Dock->Color5, pSettings->Dock->Color6, pSettings->Dock->Color7, pSettings->Dock->Color8, pSettings->Dock->interlaced, pSettings->Dock->bevelstyle, pSettings->Dock->bevelposition, pSettings->bevelWidth, pSettings->Dock->borderColor, pSettings->Dock->borderWidth);
158
159 if (!pSettings->DockBorder->parentRelative && (pSettings->Dock->borderWidth > 0))
160 {
161 CreateBorderSuper(pDock->cachedBackground, r, pSettings->DockBorder->type, pSettings->DockBorder->Color1, pSettings->DockBorder->Color2, pSettings->DockBorder->Color3, pSettings->DockBorder->Color4, pSettings->DockBorder->Color5, pSettings->DockBorder->Color6, pSettings->DockBorder->Color7, pSettings->DockBorder->Color8, pSettings->Dock->borderWidth);
162 }
163 }
164 else
165 {
166 MakeGradientSuper(pDock->cachedBackground, r, B_SOLID, 0x000000, 0, 0, 0, 0, 0, 0, 0, false, BEVEL_FLAT, 0, 0, 0, 0);
167 HFONT font = CreateFont(pSettings->Dock->FontHeight, 0, 0, 0, pSettings->Dock->FontWeight, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, pSettings->Dock->Font);
168 HGDIOBJ oldfont = SelectObject(pDock->cachedBackground, font);
169 SetBkMode(pDock->cachedBackground, TRANSPARENT);
170 DrawTextWithEffects(pDock->cachedBackground, r, "---", DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE | DT_WORD_ELLIPSIS, 0xffffff, false, 0, false, 0, 0, 0);
171 DeleteObject(SelectObject(pDock->cachedBackground, oldfont));
172 }
173
174 DeleteObject(tempBitmap);
175
176 // Set the "cached background created" indicator...
177 pDock->cachedBackgroundExists = true;
178 }
179
180 // Copy the cached background into the dock window HDC...
181 BitBlt(hdc, ps.rcPaint.left, ps.rcPaint.top, (ps.rcPaint.right - ps.rcPaint.left), (ps.rcPaint.bottom - ps.rcPaint.top), pDock->cachedBackground, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);
182
183 EndPaint(pDock->hDockWnd, &ps);
184 }
185 break;
186
187 //====================
188
189 case WM_CLOSE:
190 return 0;
191
192 //====================
193
194 case BB_RECONFIGURE:
195 {
196 // NOTE: When only need to do this if the dock is *empty*, since any docked plugins
197 // will send SLIT_UPDATE which will in turn invalidate the parent dock window...
198 if (pDock->DockPlugins.size() == 0) pDock->UpdateDockWindow();
199 }
200 break;
201
202 //====================
203
204 case WM_DISPLAYCHANGE:
205 {
206 // Update the dock's position if the screen resolution changes...
207 pDock->UpdatePosition();
208 }
209 break;
210
211 case WM_SETTINGCHANGE:
212 {
213 // Update the dock's position if the work area changes...
214 // (e.g. if the Explorer taskbar is moved to another screen edge)
215 if (wParam == SPI_SETWORKAREA) pDock->UpdatePosition();
216 return 0;
217 }
218
219 //====================
220
221 case DOCK_ADD: // -> A plugin is being docked... (added to the dock)
222 {
223 if (IsWindow((HWND)lParam))
224 {
225 dockPluginItem plugin;
226 plugin.hwndPlugin = (HWND)lParam;
227 pDock->DockPlugins.push_back(plugin);
228
229 SetWindowLongPtr((HWND)lParam, GWL_STYLE, (GetWindowLongPtr((HWND)lParam, GWL_STYLE) & ~WS_POPUP) | WS_CHILD);
230 SetParent((HWND)lParam, pDock->hDockWnd);
231 }
232
233 pDock->UpdateDockWindow();
234 }
235 break;
236
237 //====================
238
239 case DOCK_REMOVE: // -> A plugin is being undocked... (removed from the dock)
240 {
241 vector<dockPluginItem>::iterator dockPlugin;
242
243 for (dockPlugin = pDock->DockPlugins.begin(); dockPlugin != pDock->DockPlugins.end(); dockPlugin++)
244 {
245 if (dockPlugin->hwndPlugin == (HWND)lParam)
246 {
247 if (IsWindow((HWND)lParam))
248 {
249 SetWindowLongPtr((HWND)lParam, GWL_STYLE, (GetWindowLongPtr((HWND)lParam, GWL_STYLE) & ~WS_CHILD) | WS_POPUP);
250 SetParent((HWND)lParam, NULL);
251 }
252
253 pDock->DockPlugins.erase(dockPlugin);
254
255 break;
256 }
257 }
258
259 pDock->UpdateDockWindow();
260 }
261 break;
262
263 //====================
264
265 case DOCK_UPDATE: // -> Update the dock window...
266 {
267 pDock->UpdateDockWindow();
268 }
269 break;
270
271 //====================
272
273 case BB_TOGGLEDOCK: // -> Toggle the dock shown/hidden...
274 {
275 if (!pSettings->dockHidden) pSettings->dockHidden = true;
276 else pSettings->dockHidden = false;
277 pDock->UpdateDockWindow();
279 WriteBool(pSettings->xobrcFile, "xoblite.dock.hidden:", pSettings->dockHidden);
280 }
281 break;
282
283 //====================
284
285 case WM_NCHITTEST:
286 {
287 POINT p;
288 GetCursorPos(&p);
289 RECT r;
290 GetWindowRect(pDock->hDockWnd, &r);
291 pDock->DockX = r.left;
292 pDock->DockY = r.top;
293
294 p.x = p.x - pDock->DockX;
295 p.y = p.y - pDock->DockY;
296
297 // Allow mouse drag manual positioning if we're not hovering over
298 // a child (plugin) window, and the control key is being held down...
299 if (ChildWindowFromPoint(pDock->hDockWnd, p) == pDock->hDockWnd)
300 {
301 if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
302 {
303 pDock->positioningInProgress = true;
304 return HTCAPTION;
305 }
306 }
307
308 return HTCLIENT;
309 }
310
311 //====================
312
313 case WM_LBUTTONUP:
314 {
315 if (pMenuCommon) pMenuCommon->Hide();
316 return 0;
317 }
318
319 case WM_LBUTTONDOWN: {} break;
320
321 //====================
322
323 case WM_RBUTTONUP:
324 case WM_NCRBUTTONUP:
325 {
326 if (GetAsyncKeyState(VK_CONTROL) & 0x8000) SendMessage(GetBBWnd(), BB_MENU, 0, 0); // Ctrl+RightClick -> Main menu
327 else if (GetAsyncKeyState(VK_MENU) & 0x8000) SendMessage(GetBBWnd(), BB_MENU, 0, 0); // Alt+RightClick -> Main menu
328 else SendMessage(GetBBWnd(), BB_MENU, 2, 0); // RightClick without modifiers -> Configuration menu
329 return 0;
330 }
331
332 case WM_RBUTTONDOWN:
333 case WM_NCRBUTTONDOWN: {} break;
334
335 //====================
336
337 case WM_MBUTTONUP:
338 case WM_NCMBUTTONUP:
339 {
340 if (GetAsyncKeyState(VK_CONTROL) & 0x8000) PostMessage(GetBBWnd(), BB_TOGGLEPLUGINS, 0, 0); // Ctrl+MidClick -> Toggle plugins
341 else if (GetAsyncKeyState(VK_MENU) & 0x8000) PostMessage(GetBBWnd(), BB_TOGGLEPLUGINS, 0, 0); // Alt+MidClick -> Toggle plugins
342 else PostMessage(GetBBWnd(), BB_TOGGLETOOLBAR, 0, 0); // MidClick without modifiers -> Toggle toolbar
343 }
344 break;
345
346 case WM_MBUTTONDOWN:
347 case WM_NCMBUTTONDOWN: {} break;
348
349 //====================
350
351 case WM_XBUTTONDOWN:
352 {
353 if (HIWORD(wParam) == XBUTTON1) // X1 Click without modifiers -> Toggle dock orientation (horizontal/vertical)
354 {
355 if (pSettings->dockVertical) pSettings->dockVertical = false;
356 else pSettings->dockVertical = true;
357 pDock->UpdateDockWindow();
358 WriteBool(pSettings->xobrcFile, "xoblite.dock.vertical:", pSettings->dockVertical);
359 }
360 }
361 break;
362
363 //====================
364
365 case WM_MOUSEWHEEL:
366 case WM_MOUSEHWHEEL:
367 {
368 // Forward any mousewheel messages to the
369 // child plugin window beneath the mouse cursor...
370 POINT p;
371 GetCursorPos(&p);
372 p.x = p.x - pDock->DockX;
373 p.y = p.y - pDock->DockY;
374 HWND pluginWnd = ChildWindowFromPoint(pDock->hDockWnd, p);
375 if ((pluginWnd != NULL) && (pluginWnd != pDock->hDockWnd)) PostMessage(pluginWnd, message, (WPARAM)wParam, (LPARAM)lParam);
376 }
377 break;
378
379 //====================
380
381 case WM_DROPFILES:
382 {
383 return ParseDropFiles(hwnd, wParam); // -> Common handling of drag'n'drop events for all core UI elements
384 }
385 break;
386
387 //====================
388
389 case WM_WINDOWPOSCHANGING:
390 {
391 if (pDock->positioningInProgress)
392 {
393 // Snap window to screen edges when in manual positioning mode?
394 if ((pSettings->DockPlacement.placement == PLACEMENT_MANUAL) && pSettings->dockSnapToEdges)
395 {
396 if (IsWindowVisible(hwnd)) SnapWindowToEdge((WINDOWPOS*)lParam, pSettings->edgeSnapThreshold, true);
397 }
398 }
399 return 0;
400 }
401
402 //====================
403
404 case WM_EXITSIZEMOVE:
405 {
406 if (pDock->positioningInProgress)
407 {
408 pDock->positioningInProgress = false;
409
410 RECT r;
411 GetWindowRect(pDock->hDockWnd, &r);
412 pSettings->DockPlacement.placement = PLACEMENT_MANUAL;
413 pSettings->DockPlacement.rcx = pDock->DockX = r.left;
414 pSettings->DockPlacement.rcy = pDock->DockY = r.top;
415
416 pSettings->WritePlacement(&pSettings->DockPlacement);
417 }
418
419 return 0;
420 }
421
422 //====================
423
424 case WM_TIMER:
425 {
426 if (wParam == DOCK_RECONFIGURE_LOCK_TIMER)
427 {
428 pDock->ReconfigureLock(false);
429 return 0;
430 }
431 }
432 break;
433
434 //====================
435
436 default:
437 return DefWindowProc(hwnd,message,wParam,lParam);
438
439 //====================
440 }
441 return 0;
442}
int ParseDropFiles(HWND hwnd, WPARAM wParam)
Definition BBApi.cpp:3381
void WriteBool(LPCSTR fp, LPCSTR keyword, bool value)
Definition BBApi.cpp:3131
void DrawImageIntoRect(HDC hdc, RECT r, StyleItem *styleItem, bool useAlpha, bool drawBorder)
Definition BBApi.cpp:2333
void MakeGradientSuper(HDC hdc, RECT rect, int type, COLORREF color1, COLORREF color2, COLORREF color3, COLORREF color4, COLORREF color5, COLORREF color6, COLORREF color7, COLORREF color8, bool bInterlaced, int bevelStyle, int bevelPosition, int bevelWidth, COLORREF borderColour, int borderWidth)
Definition BBApi.cpp:2127
MenuCommon * pMenuCommon
Definition Blackbox.cpp:41
void SnapWindowToEdge(WINDOWPOS *pwPos, int nDist, bool bUseScreenSize)
Definition BBApi.cpp:1970
void CreateBorderSuper(HDC hdc, RECT rect, int type, COLORREF color1, COLORREF color2, COLORREF color3, COLORREF color4, COLORREF color5, COLORREF color6, COLORREF color7, COLORREF color8, int borderWidth)
Definition BBApi.cpp:2250
void DrawTextWithEffects(HDC hdc, RECT r, LPSTR text, unsigned int format, COLORREF textColor, bool outline, COLORREF outlineColor, bool shadow, COLORREF shadowColor, int shadowX, int shadowY)
Definition BBApi.cpp:3519
Settings * pSettings
Definition Blackbox.cpp:46
HWND GetBBWnd()
Definition BBApi.cpp:128
#define DOCK_ADD
Definition BBApi.h:251
#define B_SOLID
Definition BBApi.h:80
#define DOCK_UPDATE
Definition BBApi.h:253
#define BB_TOGGLEPLUGINS
Definition BBApi.h:167
#define BB_MENU
Definition BBApi.h:160
#define BB_RECONFIGURE
Definition BBApi.h:147
#define BEVEL_FLAT
Definition BBApi.h:105
#define DOCK_REMOVE
Definition BBApi.h:252
#define B_IMAGEFROMFILE
Definition BBApi.h:83
#define BB_TOGGLEDOCK
Definition BBApi.h:170
#define BB_TOGGLETOOLBAR
Definition BBApi.h:171
Dock * pDock
Definition Blackbox.cpp:38
#define DOCK_RECONFIGURE_LOCK_TIMER
Definition Dock.h:52
#define PLACEMENT_MANUAL
Definition Settings.h:67
void PlaySoundFX(int sound)
Definition Sounds.cpp:40
@ SFX_TOGGLE_ELEMENT
Definition Sounds.h:48
Definition Dock.h:57
HWND hwndPlugin
Definition Dock.h:58

Variable Documentation

◆ szDockName

const char szDockName[] = "BBSlit"

◆ pDock

Dock* pDock
extern

◆ pBImage

BImage* pBImage
extern

◆ pSettings

Settings* pSettings
extern

◆ pMenuCommon

MenuCommon* pMenuCommon
extern

◆ pPluginManager

PluginManager* pPluginManager
extern

◆ pTaskbar

Taskbar* pTaskbar
extern

◆ dockMessageSubscription

int dockMessageSubscription[] = { BB_TOGGLEDOCK, BB_RECONFIGURE, 0 }