//=========================================================================== LRESULT CALLBACK Toolbar_WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static UINT msgs[] = { BB_RECONFIGURE, BB_TASKSUPDATE, BB_SETTOOLBARLABEL, BB_BROADCAST, BB_DESKTOPINFO, BB_REDRAWGUI, 0 }; switch (message) { //==================== case WM_CREATE: DisableInputMethod(hwnd); TBInfo.hwnd = Toolbar_hwnd = hwnd; MessageManager_AddMessages (hwnd, msgs); MakeSticky(hwnd); Toolbar_UpdatePosition(); break; //==================== case WM_DESTROY: RemoveSticky(hwnd); MessageManager_RemoveMessages (hwnd, msgs); SetDesktopMargin(Toolbar_hwnd, 0, 0); if (Toolbar_hFont) DeleteObject(Toolbar_hFont), Toolbar_hFont = NULL; TBInfo.hwnd = Toolbar_hwnd = NULL; break; //==================== case BB_RECONFIGURE: tbreconfig: Toolbar_UpdatePosition(); Toolbar_ShowMenu(false); InvalidateRect(hwnd, NULL, FALSE); break; //==================== case BB_REDRAWGUI: if (wParam & BBRG_TOOLBAR) { Toolbar_force_button_pressed = 0 != (wParam & BBRG_PRESSED); Toolbar_UpdatePosition(); InvalidateRect(hwnd, NULL, FALSE); } break; //==================== case BB_TASKSUPDATE: showlabel: Toolbar_setlabel(); InvalidateRect(hwnd, NULL, FALSE); break; case BB_DESKTOPINFO: Toolbar_setlabel(); InvalidateRect(hwnd, NULL, FALSE); break; //==================== case WM_ACTIVATEAPP: if (wParam) SetOnTop(hwnd); break; //==================== case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); PaintToolbar(hdc, &ps.rcPaint); EndPaint(hwnd, &ps); break; } //==================== case BB_SETTOOLBARLABEL: SetTimer(hwnd, TOOLBAR_SETLABEL_TIMER, 2000, (TIMERPROC)NULL); Toolbar_ShowingExternalLabel = true; strcpy_max(Toolbar_CurrentWindow, (LPCTSTR)lParam, sizeof(Toolbar_CurrentWindow)/sizeof(TCHAR)); InvalidateRect(hwnd, NULL, FALSE); break; //==================== case WM_TIMER: if (wParam == TOOLBAR_AUTOHIDE_TIMER) { if (TBInfo.autoHide) { if (check_mouse(hwnd) || (TBInfo.bbsb_hwnd && check_mouse(TBInfo.bbsb_hwnd))) break; Toolbar_AutoHide(true); } KillTimer(hwnd, wParam); break; } if (wParam == TOOLBAR_UPDATE_TIMER) { Toolbar_setclock(); InvalidateRect(hwnd, NULL, FALSE); break; } KillTimer(hwnd, wParam); if (wParam == TOOLBAR_SETLABEL_TIMER) { Toolbar_ShowingExternalLabel = false; goto showlabel; } break; //==================== /* case WM_DROPFILES: drop_style((HDROP)wParam); break; */ //==================== case WM_LBUTTONDOWN: if (wParam & MK_CONTROL) { // Allow window to move if control key is being held down, UpdateWindow(hwnd); SendMessage(hwnd, WM_SYSCOMMAND, 0xf012, 0); break; } goto left_mouse; case WM_LBUTTONDBLCLK: if (wParam & MK_CONTROL) { // double click moves the window back to the default position Toolbar_set_pos(); break; } goto left_mouse; case WM_MOUSEMOVE: if (TBInfo.autohidden) { // bring back from autohide SetTimer(hwnd, TOOLBAR_AUTOHIDE_TIMER, 250, NULL); Toolbar_AutoHide(false); break; } goto left_mouse; case WM_LBUTTONUP: left_mouse: { POINT MouseEventPoint; MouseEventPoint.x = (short)LOWORD(lParam); MouseEventPoint.y = (short)HIWORD(lParam); if (HandleCapture(hwnd, message, MouseEventPoint)) break; for (int i=0; i<5; i++) if (CheckButton( hwnd, message, MouseEventPoint, &Toolbar_Button[i].r, &Toolbar_Button[i].pressed, Toolbar_button_event, i )) goto _break; if (message == WM_LBUTTONDOWN) SetActiveWindow(hwnd); } _break: break; //==================== // show menus case WM_RBUTTONUP: { int x = (short)LOWORD(lParam); if (x < tbClockW) PostMessage(BBhwnd, BB_MENU, BB_MENU_TASKS, 0); else if (x >= TBInfo.width - tbClockW) PostMessage(BBhwnd, BB_MENU, BB_MENU_ROOT, 0); else Toolbar_ShowMenu(true); break; } //==================== case WM_MBUTTONUP: // Is shift key held down? if (wParam & MK_SHIFT) PostMessage(BBhwnd, BB_TOGGLEPLUGINS, 0, 0); else PostMessage(BBhwnd, BB_TOGGLETRAY, 0, 0); break; //==================== // If moved, snap window to screen edges... case WM_WINDOWPOSCHANGING: if (Toolbar_moving) SnapWindowToEdge((WINDOWPOS*)lParam, 0, SNAP_FULLSCREEN); break; case WM_ENTERSIZEMOVE: Toolbar_moving = true; break; case WM_EXITSIZEMOVE: Toolbar_moving = false; break; //==================== case BB_BROADCAST: if (0 == _tmemcmp((LPTSTR)lParam, _T("@Toolbar"), 8)) { const TCHAR *argument = (LPTSTR)lParam; const struct cfgmenu *p_menu, *p_item; const void *v = exec_internal_broam(argument, tb_main, &p_menu, &p_item); if (v) goto tbreconfig; break; } if (!_tcsicmp((LPCTSTR)lParam, _T("@BBShowPlugins"))) { Toolbar_hidden = false; Toolbar_UpdatePosition(); break; } if (!_tcsicmp((LPCTSTR)lParam, _T("@BBHidePlugins"))) { if (Settings_toolbarPluginToggle) { Toolbar_hidden = true; Toolbar_UpdatePosition(); } break; } break; case WM_CLOSE: break; default: return DefWindowProc(hwnd,message,wParam,lParam); //==================== } return 0; }
void Toolbar_UpdatePosition() { Settings_toolbarAlpha = Settings_toolbarAlphaEnabled ? Settings_toolbarAlphaValue : 255; // Another Toolbar has set the info: if (NULL == Toolbar_hwnd && TBInfo.hwnd) return; intptr_t place = get_string_index(Settings_toolbarPlacement, placement_strings); if (-1 == place) place = PLACEMENT_BOTTOM_CENTER; // --- toolbar metrics ---------------------- int labelH, buttonH; if (Settings_newMetrics || (mStyle.ToolbarLabel.validated & VALID_MARGIN)) { HFONT hf = CreateStyleFont(&mStyle.Toolbar); int lfh = get_fontheight(hf); DeleteObject(hf); if (mStyle.ToolbarLabel.validated & VALID_MARGIN) labelH = lfh + 2 * mStyle.ToolbarLabel.marginWidth; else labelH = (int)imax(10, lfh) + 2*2; } else { labelH = (int)imax(8, mStyle.Toolbar.FontHeight) + 2; } labelH |= 1; if (mStyle.ToolbarButton.validated & VALID_MARGIN) { buttonH = 9 + 2 * mStyle.ToolbarButton.marginWidth; } else { buttonH = labelH - 2; } tbMargin = mStyle.Toolbar.marginWidth; tbButtonWH = buttonH; tbLabelH = labelH; int tbheight = (int)imax(labelH, buttonH) + 2 * (mStyle.Toolbar.borderWidth + mStyle.Toolbar.marginWidth); int tbwidth = (int)imax (300, ScreenWidth * Settings_toolbarWidthPercent / 100); // ------------------------------------------ //int ScreenWidth = GetSystemMetrics(SM_CXSCREEN); //int ScreenHeight = GetSystemMetrics(SM_CYSCREEN); TBInfo.placement = (int)place; TBInfo.widthPercent = Settings_toolbarWidthPercent; TBInfo.height = tbheight; TBInfo.width = tbwidth; TBInfo.ypos = (place<3) ? 0 : ScreenHeight - TBInfo.height; TBInfo.xpos = (place%3) * (ScreenWidth - TBInfo.width) / 2; TBInfo.onTop = Settings_toolbarOnTop; TBInfo.autoHide = Settings_toolbarAutoHide; TBInfo.pluginToggle = Settings_toolbarPluginToggle; TBInfo.autohidden = TBInfo.autoHide; TBInfo.alphaValue = Settings_toolbarAlphaValue; TBInfo.transparency = Settings_toolbarAlphaEnabled; TBInfo.disabled = false == Settings_toolbarEnabled; TBInfo.hidden = false == Settings_toolbarEnabled; if (Toolbar_hwnd) { int d = TBInfo.height - 1; Toolbar_HideY = TBInfo.ypos + (place < 3 ? -d : d); SetDesktopMargin( Toolbar_hwnd, place < 3 ? BB_DM_TOP : BB_DM_BOTTOM, TBInfo.autoHide || Toolbar_hidden ? 0 : TBInfo.height + (TBInfo.onTop ? 0 : 4) ); tbClockW = 0; Toolbar_setlabel(); Toolbar_setclock(); if (Toolbar_hFont) DeleteObject(Toolbar_hFont), Toolbar_hFont = NULL; Toolbar_set_pos(); } }
void Toolbar_UpdatePosition(void) { int ScreenWidth; int ScreenHeight; int labelH, buttonH, tbheight, tbwidth, labelBorder; int place, fontH; HFONT hf; struct toolbar_setting *tbs = &Settings_toolbar; // Another Toolbar has set the info: if (NULL == Toolbar_hwnd && TBInfo.hwnd) return; ScreenWidth = GetSystemMetrics(SM_CXSCREEN); ScreenHeight = GetSystemMetrics(SM_CYSCREEN); place = get_string_index(tbs->placement, placement_strings); if (-1 == place) place = PLACEMENT_BOTTOM_CENTER; // --- toolbar metrics ---------------------- hf = CreateStyleFont(&mStyle.Toolbar); fontH = get_fontheight(hf); DeleteObject(hf); // xxx old behaviour xxx if (false == mStyle.is_070 && 0 == (mStyle.ToolbarLabel.validated & V_MAR)) fontH = mStyle.Toolbar.FontHeight-2; //xxxxxxxxxxxxxxxxxxxxxx labelBorder = imax(mStyle.ToolbarLabel.borderWidth, imax(mStyle.ToolbarWindowLabel.borderWidth, mStyle.ToolbarClock.borderWidth)); labelH = (fontH|1) + 2*(mStyle.ToolbarLabel.marginWidth/*+labelBorder*/); buttonH = labelH + 2*(mStyle.ToolbarButton.marginWidth-mStyle.ToolbarLabel.marginWidth); tbMargin = mStyle.Toolbar.marginWidth; tbButtonWH = buttonH; tbLabelH = labelH; tbLabelIndent = imax(2+labelBorder, (labelH-fontH)/2); tbheight = imax(labelH, buttonH) + 2*(mStyle.Toolbar.borderWidth + mStyle.Toolbar.marginWidth); tbwidth = imax (300, ScreenWidth * tbs->widthPercent / 100); // ------------------------------------------ TBInfo.placement = place; TBInfo.widthPercent = tbs->widthPercent; TBInfo.height = tbheight; TBInfo.width = tbwidth; TBInfo.ypos = (place<3) ? 0 : ScreenHeight - TBInfo.height; TBInfo.xpos = (place%3) * (ScreenWidth - TBInfo.width) / 2; TBInfo.onTop = tbs->onTop; TBInfo.autoHide = tbs->autoHide; TBInfo.pluginToggle = tbs->pluginToggle; TBInfo.autohidden = TBInfo.autoHide; TBInfo.alphaValue = (BYTE)tbs->alphaValue; TBInfo.transparency = tbs->alphaEnabled; TBInfo.disabled = false == tbs->enabled; TBInfo.hidden = false == tbs->enabled; if (Toolbar_hwnd) { int d = TBInfo.height - 1; Toolbar_HideY = TBInfo.ypos + (place < 3 ? -d : d); SetDesktopMargin( Toolbar_hwnd, place < 3 ? BB_DM_TOP : BB_DM_BOTTOM, TBInfo.autoHide || Toolbar_hidden ? 0 : TBInfo.height); tbClockW = 0; Toolbar_setlabel(); Toolbar_setclock(); if (Toolbar_hFont) DeleteObject(Toolbar_hFont), Toolbar_hFont = NULL; Toolbar_set_pos(); } }