#include "Toolbar.h"
const char szToolbarName[] = "BBToolbar";
extern BImage *pBImage;
extern Toolbar *pToolbar;
extern Systembar *pSystembar;
extern Settings *pSettings;
extern Workspaces *pWorkspaces;
extern MenuMaker *pMenuMaker;
Toolbar::Toolbar(HINSTANCE hInstance)
{
WNDCLASS wc;
hToolbarInstance = hInstance;
hBlackboxWnd = GetBBWnd();
cachedBackground = CreateCompatibleDC(NULL);
cachedToolbarButton = CreateCompatibleDC(NULL);
cachedToolbarButtonPressed = CreateCompatibleDC(NULL);
cachedBitmapsExist = false;
cachedToolbarWindowLabel = CreateCompatibleDC(NULL);
SetRectEmpty(¤tWindowLabelRect);
ButtonPressed1 = ButtonPressed2 = ButtonPressed3 = ButtonPressed4 = false;
FirstUpdate = true;
ShowingExternalLabel = false;
saveWidthOnRestart = false;
ToolbarPosInProgress = false;
GetSettings();
ZeroMemory(&wc,sizeof(wc));
wc.lpfnWndProc = ToolbarWndProc;
wc.hInstance = hToolbarInstance;
wc.lpszClassName = szToolbarName;
if (!RegisterClass(&wc))
{
MessageBox(0, "Error registering window class", szToolbarName, MB_OK | MB_ICONERROR | MB_TOPMOST);
Log("Toolbar: Error registering window class", NULL);
return;
}
hToolbarWnd = CreateWindowEx(
WS_EX_TOOLWINDOW,
szToolbarName,
NULL,
WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
ToolbarX, ToolbarY,
ToolbarWidth, ToolbarHeight,
NULL,
NULL,
hToolbarInstance,
NULL);
if (!hToolbarWnd)
{
UnregisterClass(szToolbarName, hToolbarInstance);
MessageBox(0, "Error creating window", szToolbarName, MB_OK | MB_ICONERROR | MB_TOPMOST);
Log("Toolbar: Error creating window", NULL);
return;
}
int msgs[] = { BB_DESKTOPINFO, BB_RECONFIGURE, BB_TOGGLETOOLBAR, BB_SETTOOLBARLABEL, 0 };
SendMessage(hBlackboxWnd, BB_REGISTERMESSAGE, (WPARAM)hToolbarWnd, (LPARAM)msgs);
SetTransparency(hToolbarWnd, pSettings->toolbarTransparencyAlpha);
MakeSticky(hToolbarWnd);
SetClassLongPtr(hToolbarWnd, GCL_STYLE, CS_DBLCLKS | GetClassLongPtr(hToolbarWnd, GCL_STYLE));
DragAcceptFiles(hToolbarWnd, true);
ShowWindow(hToolbarWnd, pSettings->toolbarHidden ? SW_HIDE : SW_SHOWNOACTIVATE);
if (pSettings->toolbarOnTop) SetWindowPos(hToolbarWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)&origDesktopArea, SPIF_SENDCHANGE);
UpdateDesktopArea();
int UpdateInterval = 250;
if (!SetTimer(hToolbarWnd, TOOLBAR_UPDATE_TIMER, UpdateInterval, (TIMERPROC)NULL))
{
MessageBox(0, "Error creating update timer", szToolbarName, MB_OK | MB_ICONERROR | MB_TOPMOST);
Log("Could not create Toolbar update timer", NULL);
return;
}
ToolbarAutoHiding = ToolbarAutoShowing = false;
ToolbarAutoHidden = false;
ToolbarAutoShown = true;
if (pSettings->toolbarAutoHide && !CheckIfMouseHover()) AutoHide();
}
Toolbar::~Toolbar()
{
KillTimer(hToolbarWnd, TOOLBAR_UPDATE_TIMER);
if (ToolbarAutoHiding || ToolbarAutoShowing) KillTimer(hToolbarWnd, TOOLBAR_AUTOHIDE_TIMER);
if (ShowingExternalLabel) KillTimer(hToolbarWnd, TOOLBAR_SETLABEL_TIMER);
SystemParametersInfo(SPI_SETWORKAREA, 0, (PVOID)&origDesktopArea, SPIF_SENDCHANGE);
int msgs[] = { BB_DESKTOPINFO, BB_RECONFIGURE, BB_TOGGLETOOLBAR, BB_SETTOOLBARLABEL, 0 };
SendMessage(hBlackboxWnd, BB_UNREGISTERMESSAGE, (WPARAM)hToolbarWnd, (LPARAM)msgs);
DestroyWindow(hToolbarWnd);
UnregisterClass(szToolbarName, hToolbarInstance);
DeleteDC(cachedToolbarWindowLabel);
DeleteDC(cachedToolbarButtonPressed);
DeleteDC(cachedToolbarButton);
DeleteDC(cachedBackground);
}
LRESULT CALLBACK ToolbarWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC buf = CreateCompatibleDC(NULL);
RECT r;
int updateRectWidth = ps.rcPaint.right - ps.rcPaint.left;
int updateRectHeight = ps.rcPaint.bottom - ps.rcPaint.top;
HBITMAP bufbmp = CreateCompatibleBitmap(hdc, pToolbar->ToolbarWidth, pToolbar->ToolbarHeight);
HBITMAP oldbuf = (HBITMAP)SelectObject(buf, bufbmp);
int tbLabelW;
int tbClockW;
SIZE size;
HDC fonthdc = CreateDC("DISPLAY", NULL, NULL, NULL);
HFONT tempfont = CreateFont(pSettings->ToolbarLabel->FontHeight, 0, 0, 0, pSettings->ToolbarLabel->FontWeight, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, pSettings->ToolbarLabel->Font);
HGDIOBJ oldtempfont = SelectObject(fonthdc, tempfont);
if (pWorkspaces) strcpy(pToolbar->ToolbarWorkspaceName, (LPSTR)pWorkspaces->deskNames[pWorkspaces->currentScreen].c_str());
GetTextExtentPoint32(fonthdc, pToolbar->ToolbarWorkspaceName, strlen(pToolbar->ToolbarWorkspaceName), &size);
tbLabelW = size.cx + 6 + pSettings->ToolbarLabel->borderWidth;
DeleteObject(SelectObject(fonthdc, oldtempfont));
tempfont = CreateFont(pSettings->ToolbarClock->FontHeight, 0, 0, 0, pSettings->ToolbarClock->FontWeight, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, pSettings->ToolbarClock->Font);
oldtempfont = SelectObject(fonthdc, tempfont);
GetTextExtentPoint32(fonthdc, pToolbar->CurrentTime, strlen(pToolbar->CurrentTime), &size);
tbClockW = size.cx + 12 + pSettings->ToolbarClock->borderWidth;
if (tbClockW > tbLabelW) { tbLabelW = tbClockW; }
else { tbClockW = tbLabelW; }
DeleteObject(SelectObject(fonthdc, oldtempfont));
DeleteDC(fonthdc);
pToolbar->ButtonWH = pToolbar->ToolbarHeight - (pSettings->Toolbar->borderWidth * 2) - 6;
int tbLabelX = pSettings->Toolbar->borderWidth + 1;
int tbLabelH = pToolbar->ToolbarHeight - (pSettings->Toolbar->borderWidth * 2) - 2;
int tbClockX = pToolbar->ToolbarWidth - tbClockW - 1 - pSettings->Toolbar->borderWidth;
int tbWinLabelX = tbLabelW + (2 * pToolbar->ButtonWH) + 10 + pSettings->Toolbar->borderWidth;
int tbWinLabelW = pToolbar->ToolbarWidth - tbLabelW - tbClockW - (4 * pToolbar->ButtonWH) - 20 - (pSettings->Toolbar->borderWidth * 2);
if (tbWinLabelW < 0) tbWinLabelW = 0;
pToolbar->ButtonX1 = tbLabelX + tbLabelW + 3;
pToolbar->ButtonX2 = pToolbar->ButtonX1 + pToolbar->ButtonWH + 3;
pToolbar->ButtonX3 = tbClockX - (2 * pToolbar->ButtonWH) - 6;
pToolbar->ButtonX4 = pToolbar->ButtonX3 + pToolbar->ButtonWH + 3;
pToolbar->ButtonY = pSettings->Toolbar->borderWidth + 3;
SetRect(&pToolbar->labelRect, tbLabelX, 1 + pSettings->Toolbar->borderWidth, tbLabelX + tbLabelW, 1 + pSettings->Toolbar->borderWidth + tbLabelH);
SetRect(&pToolbar->winlabelRect, tbWinLabelX, 1 + pSettings->Toolbar->borderWidth, tbWinLabelX + tbWinLabelW, 1 + pSettings->Toolbar->borderWidth + tbLabelH);
SetRect(&pToolbar->clockRect, tbClockX, 1 + pSettings->Toolbar->borderWidth, tbClockX + tbClockW, 1 + pSettings->Toolbar->borderWidth + tbLabelH);
if (!pToolbar->cachedBitmapsExist)
{
HBITMAP tempBitmap, oldBitmap;
tempBitmap = CreateCompatibleBitmap(hdc, pToolbar->ToolbarWidth, pToolbar->ToolbarHeight);
oldBitmap = (HBITMAP)SelectObject(pToolbar->cachedBackground, tempBitmap);
DeleteObject(oldBitmap);
GetClientRect(hwnd, &r);
MakeGradient(pToolbar->cachedBackground, r, pSettings->Toolbar->type, pSettings->Toolbar->Color, pSettings->Toolbar->ColorTo, pSettings->Toolbar->interlaced, pSettings->Toolbar->bevelstyle, pSettings->Toolbar->bevelposition, pSettings->bevelWidth, pSettings->Toolbar->borderColor, pSettings->Toolbar->borderWidth);
if (!pSettings->ToolbarLabel->parentRelative)
{
MakeGradient(pToolbar->cachedBackground, pToolbar->labelRect, pSettings->ToolbarLabel->type, pSettings->ToolbarLabel->Color, pSettings->ToolbarLabel->ColorTo, pSettings->ToolbarLabel->interlaced, pSettings->ToolbarLabel->bevelstyle, pSettings->ToolbarLabel->bevelposition, pSettings->bevelWidth, pSettings->ToolbarLabel->borderColor, pSettings->ToolbarLabel->borderWidth);
}
if (!pSettings->ToolbarClock->parentRelative)
{
MakeGradient(pToolbar->cachedBackground, pToolbar->clockRect, pSettings->ToolbarClock->type, pSettings->ToolbarClock->Color, pSettings->ToolbarClock->ColorTo, pSettings->ToolbarClock->interlaced, pSettings->ToolbarClock->bevelstyle, pSettings->ToolbarClock->bevelposition, pSettings->bevelWidth, pSettings->ToolbarClock->borderColor, pSettings->ToolbarClock->borderWidth);
}
DeleteObject(tempBitmap);
if (!pSettings->ToolbarButton->parentRelative)
{
tempBitmap = CreateCompatibleBitmap(hdc, pToolbar->ButtonWH, pToolbar->ButtonWH);
oldBitmap = (HBITMAP)SelectObject(pToolbar->cachedToolbarButton, tempBitmap);
DeleteObject(oldBitmap);
r.left = 0; r.top = 0; r.right = pToolbar->ButtonWH; r.bottom = pToolbar->ButtonWH;
MakeGradient(pToolbar->cachedToolbarButton, r, pSettings->ToolbarButton->type, pSettings->ToolbarButton->Color, pSettings->ToolbarButton->ColorTo, pSettings->ToolbarButton->interlaced, pSettings->ToolbarButton->bevelstyle, pSettings->ToolbarButton->bevelposition, pSettings->bevelWidth, pSettings->ToolbarButton->borderColor, pSettings->ToolbarButton->borderWidth);
DeleteObject(tempBitmap);
}
if (!pSettings->ToolbarButton->parentRelative)
{
BitBlt(pToolbar->cachedBackground, pToolbar->ButtonX1, pToolbar->ButtonY, pToolbar->ButtonWH, pToolbar->ButtonWH, pToolbar->cachedToolbarButton, 0, 0, SRCCOPY);
BitBlt(pToolbar->cachedBackground, pToolbar->ButtonX2, pToolbar->ButtonY, pToolbar->ButtonWH, pToolbar->ButtonWH, pToolbar->cachedToolbarButton, 0, 0, SRCCOPY);
BitBlt(pToolbar->cachedBackground, pToolbar->ButtonX3, pToolbar->ButtonY, pToolbar->ButtonWH, pToolbar->ButtonWH, pToolbar->cachedToolbarButton, 0, 0, SRCCOPY);
BitBlt(pToolbar->cachedBackground, pToolbar->ButtonX4, pToolbar->ButtonY, pToolbar->ButtonWH, pToolbar->ButtonWH, pToolbar->cachedToolbarButton, 0, 0, SRCCOPY);
}
pToolbar->cachedBitmapsExist = true;
}
BitBlt(buf, ps.rcPaint.left, ps.rcPaint.top, updateRectWidth, updateRectHeight, pToolbar->cachedBackground, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);
if (pSettings->taskbarOnToolbar && pSystembar)
{
if (tbWinLabelW > (pSystembar->WinEnumeratorCount*16))
{
pSystembar->DrawTaskbar(buf, 0, pToolbar->winlabelRect);
}
}
else pToolbar->DrawWindowLabel(buf, pToolbar->winlabelRect);
if (!pSettings->ToolbarButtonPressed->parentRelative && (pToolbar->ButtonPressed1 || pToolbar->ButtonPressed2 || pToolbar->ButtonPressed3 || pToolbar->ButtonPressed4))
{
HDC src = CreateCompatibleDC(NULL);
HBITMAP srcbmp = CreateCompatibleBitmap(hdc, pToolbar->ButtonWH, pToolbar->ButtonWH);
HBITMAP oldsrc = (HBITMAP)SelectObject(src, srcbmp);
r.left = 0; r.top = 0; r.right = pToolbar->ButtonWH; r.bottom = pToolbar->ButtonWH;
MakeGradient(src, r, pSettings->ToolbarButtonPressed->type, pSettings->ToolbarButtonPressed->Color, pSettings->ToolbarButtonPressed->ColorTo, pSettings->ToolbarButtonPressed->interlaced, pSettings->ToolbarButtonPressed->bevelstyle, pSettings->ToolbarButtonPressed->bevelposition, pSettings->bevelWidth, pSettings->ToolbarButtonPressed->borderColor, pSettings->ToolbarButtonPressed->borderWidth);
if (pToolbar->ButtonPressed1) BitBlt(buf, pToolbar->ButtonX1, pToolbar->ButtonY, pToolbar->ButtonWH, pToolbar->ButtonWH, src, 0, 0, SRCCOPY);
if (pToolbar->ButtonPressed2) BitBlt(buf, pToolbar->ButtonX2, pToolbar->ButtonY, pToolbar->ButtonWH, pToolbar->ButtonWH, src, 0, 0, SRCCOPY);
if (pToolbar->ButtonPressed3) BitBlt(buf, pToolbar->ButtonX3, pToolbar->ButtonY, pToolbar->ButtonWH, pToolbar->ButtonWH, src, 0, 0, SRCCOPY);
if (pToolbar->ButtonPressed4) BitBlt(buf, pToolbar->ButtonX4, pToolbar->ButtonY, pToolbar->ButtonWH, pToolbar->ButtonWH, src, 0, 0, SRCCOPY);
SelectObject(src, oldsrc);
DeleteDC(src);
DeleteObject(srcbmp);
DeleteObject(oldsrc);
}
unsigned int format;
HFONT font = CreateFont(pSettings->ToolbarLabel->FontHeight, 0, 0, 0, pSettings->ToolbarLabel->FontWeight, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, pSettings->ToolbarLabel->Font);
HGDIOBJ oldfont = SelectObject(buf, font);
SetBkMode(buf, TRANSPARENT);
format = pSettings->ToolbarLabel->Justify | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE | DT_WORD_ELLIPSIS;
CopyRect(&r, &pToolbar->labelRect);
r.left = r.left + 3;
r.right = r.right - 3;
DrawTextWithShadow(buf, pToolbar->ToolbarWorkspaceName, r, format, pSettings->ToolbarLabel->TextColor, pSettings->toolbarLabelShadowColor, pSettings->ToolbarLabel->FontShadow);
DeleteObject(SelectObject(buf, oldfont));
font = CreateFont(pSettings->ToolbarClock->FontHeight, 0, 0, 0, pSettings->ToolbarClock->FontWeight, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, pSettings->ToolbarClock->Font);
oldfont = SelectObject(buf, font);
SetBkMode(buf, TRANSPARENT);
format = pSettings->ToolbarClock->Justify | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE | DT_WORD_ELLIPSIS;
SetTextColor(buf, pSettings->ToolbarClock->TextColor);
CopyRect(&r, &pToolbar->clockRect);
r.left = r.left + 3;
r.right = r.right - 3;
DrawTextWithShadow(buf, pToolbar->CurrentTime, r, format, pSettings->ToolbarClock->TextColor, pSettings->toolbarClockShadowColor, pSettings->ToolbarClock->FontShadow);
DeleteObject(SelectObject(buf, oldfont));
HPEN activePen, inactivePen, oldPen;
activePen = CreatePen(PS_SOLID, 1, pSettings->ToolbarButtonPressed->PicColor);
inactivePen = CreatePen(PS_SOLID, 1, pSettings->ToolbarButton->PicColor);
oldPen = (HPEN) SelectObject(buf, inactivePen);
int xcenter;
int xoffset = pToolbar->ButtonWH/2;
int ycenter = pToolbar->ToolbarHeight/2;
xcenter = pToolbar->ButtonX1 + xoffset;
if (pToolbar->ButtonPressed1) SelectObject(buf, activePen);
pToolbar->DrawArrowBackward(buf, xcenter, ycenter);
if (pToolbar->ButtonPressed1) SelectObject(buf, inactivePen);
xcenter = pToolbar->ButtonX2 + xoffset;
if (pToolbar->ButtonPressed2) SelectObject(buf, activePen);
pToolbar->DrawArrowForward(buf, xcenter, ycenter);
if (pToolbar->ButtonPressed2) SelectObject(buf, inactivePen);
xcenter = pToolbar->ButtonX3 + xoffset;
if (pToolbar->ButtonPressed3) SelectObject(buf, activePen);
pToolbar->DrawArrowBackward(buf, xcenter, ycenter);
if (pToolbar->ButtonPressed3) SelectObject(buf, inactivePen);
xcenter = pToolbar->ButtonX4 + xoffset;
if (pToolbar->ButtonPressed4) SelectObject(buf, activePen);
pToolbar->DrawArrowForward(buf, xcenter, ycenter);
if (pToolbar->ButtonPressed4) SelectObject(buf, inactivePen);
SelectObject(buf, oldPen);
DeleteObject(inactivePen);
DeleteObject(activePen);
BitBlt(hdc, 0, 0, pToolbar->ToolbarWidth, pToolbar->ToolbarHeight, buf, 0, 0, SRCCOPY);
SelectObject(buf, oldbuf);
DeleteDC(buf);
DeleteObject(bufbmp);
DeleteObject(oldbuf);
EndPaint(hwnd, &ps);
return 0;
}
break;
case BB_SETTOOLBARLABEL:
{
int timeout;
if (wParam) timeout = (int)wParam;
else timeout = 2000;
if (pToolbar->ShowingExternalLabel) KillTimer(pToolbar->hToolbarWnd, TOOLBAR_SETLABEL_TIMER);
pToolbar->ShowingExternalLabel = true;
strcpy(pToolbar->CurrentWindow, (LPCSTR)lParam);
if (!SetTimer(pToolbar->hToolbarWnd, TOOLBAR_SETLABEL_TIMER, timeout, (TIMERPROC)NULL))
{
MessageBox(0, "Error creating setlabel timer", szToolbarName, MB_OK | MB_ICONERROR | MB_TOPMOST);
Log("Could not create Toolbar setlabel timer", NULL);
return 0;
}
if (pSettings->taskbarOnToolbar && pSystembar) InvalidateRect(pSystembar->hSystembarWnd, NULL, false);
else InvalidateRect(pToolbar->hToolbarWnd, &pToolbar->winlabelRect, false);
}
break;
case WM_TIMER:
{
if (wParam == TOOLBAR_AUTOHIDE_TIMER)
{
if (pToolbar->ToolbarAutoShowing)
{
if (pToolbar->ToolbarAutoCurrentPos == pToolbar->ToolbarAutoShowTarget)
{
KillTimer(pToolbar->hToolbarWnd, TOOLBAR_AUTOHIDE_TIMER);
pToolbar->ToolbarAutoShown = true;
pToolbar->ToolbarAutoShowing = false;
if (!SetTimer(pToolbar->hToolbarWnd, TOOLBAR_MOUSEHOVER_TIMER, 100, (TIMERPROC)NULL))
{
MessageBox(GetBBWnd(), "Error creating mousehover timer", szToolbarName, MB_OK | MB_ICONERROR | MB_TOPMOST);
Log("Could not create Toolbar mousehover timer", NULL);
}
}
else
{
if (IsInString(pSettings->toolbarPlacement, "Bottom"))
{
pToolbar->ToolbarAutoCurrentPos--;
MoveWindow(pToolbar->hToolbarWnd, pToolbar->ToolbarX, pToolbar->ToolbarAutoCurrentPos, pToolbar->ToolbarWidth, pToolbar->ToolbarHeight, true);
if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar"))
{
if (pSystembar) MoveWindow(pSystembar->hSystembarWnd, pSystembar->SystembarX, (pToolbar->ToolbarAutoCurrentPos - pSystembar->SystembarHeight), pSystembar->SystembarWidth, pSystembar->SystembarHeight, true);
}
}
else
{
pToolbar->ToolbarAutoCurrentPos++;
MoveWindow(pToolbar->hToolbarWnd, pToolbar->ToolbarX, pToolbar->ToolbarAutoCurrentPos, pToolbar->ToolbarWidth, pToolbar->ToolbarHeight, true);
if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar"))
{
if (pSystembar) MoveWindow(pSystembar->hSystembarWnd, pSystembar->SystembarX, (pToolbar->ToolbarAutoCurrentPos + pToolbar->ToolbarHeight), pSystembar->SystembarWidth, pSystembar->SystembarHeight, true);
}
}
}
}
else if (pToolbar->ToolbarAutoHiding)
{
if (pToolbar->ToolbarAutoCurrentPos == pToolbar->ToolbarAutoHideTarget)
{
KillTimer(pToolbar->hToolbarWnd, TOOLBAR_AUTOHIDE_TIMER);
pToolbar->ToolbarAutoHidden = true;
pToolbar->ToolbarAutoHiding = false;
SetTransparency(pToolbar->hToolbarWnd, 1);
}
else
{
if (IsInString(pSettings->toolbarPlacement, "Bottom"))
{
pToolbar->ToolbarAutoCurrentPos++;
MoveWindow(pToolbar->hToolbarWnd, pToolbar->ToolbarX, pToolbar->ToolbarAutoCurrentPos, pToolbar->ToolbarWidth, pToolbar->ToolbarHeight, true);
if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar"))
{
if (pSystembar) MoveWindow(pSystembar->hSystembarWnd, pSystembar->SystembarX, (pToolbar->ToolbarAutoCurrentPos - pSystembar->SystembarHeight), pSystembar->SystembarWidth, pSystembar->SystembarHeight, true);
}
}
else
{
pToolbar->ToolbarAutoCurrentPos--;
MoveWindow(pToolbar->hToolbarWnd, pToolbar->ToolbarX, pToolbar->ToolbarAutoCurrentPos, pToolbar->ToolbarWidth, pToolbar->ToolbarHeight, true);
if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar"))
{
if (pSystembar) MoveWindow(pSystembar->hSystembarWnd, pSystembar->SystembarX, (pToolbar->ToolbarAutoCurrentPos + pToolbar->ToolbarHeight), pSystembar->SystembarWidth, pSystembar->SystembarHeight, true);
}
}
}
}
return 0;
}
if (wParam == TOOLBAR_MOUSEHOVER_TIMER)
{
if (!pToolbar->CheckIfMouseHover())
{
KillTimer(pToolbar->hToolbarWnd, TOOLBAR_MOUSEHOVER_TIMER);
pToolbar->AutoHide();
}
return 0;
}
if (wParam == TOOLBAR_SETLABEL_TIMER)
{
KillTimer(pToolbar->hToolbarWnd, TOOLBAR_SETLABEL_TIMER);
pToolbar->ShowingExternalLabel = false;
}
bool UpdateToolbar = false;
bool UpdateSystembar = false;
if (pToolbar->FirstUpdate)
{
SendMessage(pToolbar->hBlackboxWnd, BB_LISTDESKTOPS, (WPARAM)pToolbar->hToolbarWnd, 0);
UpdateToolbar = true;
pToolbar->FirstUpdate = false;
}
if (!pToolbar->ShowingExternalLabel)
{
HWND currentwnd = GetForegroundWindow();
if (currentwnd)
{
GetWindowText(currentwnd, pToolbar->temp, MAX_LINE_LENGTH);
if (_stricmp(pToolbar->CurrentWindow, pToolbar->temp))
{
if (pSettings->taskbarOnToolbar && pSystembar) UpdateSystembar = true;
else UpdateToolbar = true;
}
strcpy(pToolbar->CurrentWindow, pToolbar->temp);
}
}
time_t systemTime;
struct tm *localTime;
char *currentTime=(char*)malloc(MAX_LINE_LENGTH);
int currentMinute;
time(&systemTime);
localTime = localtime(&systemTime);
currentMinute = localTime->tm_min;
if (currentMinute != pToolbar->DisplayedMinute || UpdateToolbar)
{
strftime(currentTime, MAX_LINE_LENGTH, pSettings->strftimeFormat, localTime);
strcpy(pToolbar->CurrentTime, currentTime);
pToolbar->DisplayedMinute = currentMinute;
UpdateToolbar = true;
}
free(currentTime);
if (UpdateToolbar)
{
if (pSettings->taskbarOnToolbar && pSystembar) pSystembar->cachedTaskButtonsExist = false;
pToolbar->cachedBitmapsExist = false;
InvalidateRect(pToolbar->hToolbarWnd, NULL, false);
}
if (UpdateSystembar) InvalidateRect(pSystembar->hSystembarWnd, NULL, false);
return 0;
}
break;
case WM_DROPFILES:
{
static TCHAR filename[MAX_LINE_LENGTH];
DragQueryFile((HDROP)wParam, 0, filename, sizeof(filename));
if (PathIsDirectory(filename))
{
MessageBox(0, "Trying to fool me, eh?\n...drag'n'drop a style file instead!", "xoblite", MB_OK | MB_TOPMOST);
DragFinish((HDROP)wParam);
return 0;
}
else
{
if (strlen(ReadString(filename, "menu.frame", "")))
{
SendMessage(pToolbar->hBlackboxWnd, BB_SETSTYLE, 0, (LPARAM)filename);
DragFinish((HDROP)wParam);
return 0;
}
else
{
MessageBox(0, "Trying to fool me, eh?\n...drag'n'drop a style file instead!", "xoblite", MB_OK | MB_TOPMOST);
DragFinish((HDROP)wParam);
return 0;
}
}
}
break;
case BB_RECONFIGURE:
{
SetRectEmpty(&pToolbar->currentWindowLabelRect);
pToolbar->UpdatePosition();
}
break;
case BB_TOGGLETOOLBAR:
{
if (!pSettings->toolbarHidden) pSettings->toolbarHidden = true;
else pSettings->toolbarHidden = false;
if (pSettings->toolbarHidden && !stricmp(pSettings->systembarPlacement, "DockedToToolbar"))
{
if (!pSettings->systembarHidden) PostMessage(GetBBWnd(), BB_TOGGLESYSTEMBAR, 0, 0);
}
WriteBool(pSettings->extrcFile, "xoblite.toolbar.hidden:", pSettings->toolbarHidden);
if (!pSettings->toolbarHidden) pToolbar->UpdatePosition();
ShowWindow(pToolbar->hToolbarWnd, pSettings->toolbarHidden ? SW_HIDE : SW_SHOWNOACTIVATE);
}
break;
case WM_CLOSE:
return 0;
case WM_DISPLAYCHANGE:
{
if (pSettings->toolbarHidden) break;
pToolbar->UpdatePosition();
}
break;
case WM_EXITSIZEMOVE:
{
if (pToolbar->ToolbarPosInProgress)
{
pToolbar->ToolbarPosInProgress = false;
RECT r;
GetWindowRect(pToolbar->hToolbarWnd, &r);
pToolbar->ToolbarX = r.left;
pToolbar->ToolbarY = r.top;
sprintf(pSettings->toolbarPlacement, "Manual x%d y%d", pToolbar->ToolbarX, pToolbar->ToolbarY);
pToolbar->UpdatePosition();
}
return 0;
}
case WM_NCHITTEST:
{
if ((GetAsyncKeyState(VK_CONTROL) & 0x8000))
{
if (pSettings->toolbarAutoHide)
{
KillTimer(pToolbar->hToolbarWnd, TOOLBAR_AUTOHIDE_TIMER);
pSettings->toolbarAutoHide = false;
WriteBool(bbrcPath(), "session.screen0.toolbar.autoHide:", pSettings->toolbarAutoHide);
pToolbar->ToolbarAutoHiding = pToolbar->ToolbarAutoShowing = false;
pToolbar->ToolbarAutoHidden = false;
pToolbar->ToolbarAutoShown = true;
}
pToolbar->ToolbarPosInProgress = true;
return HTCAPTION;
}
return HTCLIENT;
}
break;
case WM_LBUTTONDBLCLK:
{
POINT mousepos;
GetCursorPos(&mousepos);
int relX = mousepos.x - pToolbar->ToolbarX;
if (relX <= pToolbar->labelRect.right) BBExecute(GetDesktopWindow(), NULL, pSettings->preferredEditor, bbrcPath(), NULL, SW_SHOWNORMAL, false);
else if (relX >= pToolbar->clockRect.left) BBExecute(GetDesktopWindow(), NULL, "control.exe", "timedate.cpl", NULL, SW_SHOWNORMAL, false);
}
break;
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_XBUTTONDOWN:
case WM_XBUTTONUP:
{
if (pSettings->taskbarOnToolbar && pSystembar)
{
if (pSystembar->MouseButtonOnTaskbar(hwnd, message, wParam, lParam))
{
return DefWindowProc(hwnd, message, wParam, lParam);
}
}
if (message == WM_LBUTTONDOWN)
{
TRACKMOUSEEVENT track;
ZeroMemory(&track,sizeof(track));
track.cbSize = sizeof(track);
track.dwFlags = TME_LEAVE;
track.dwHoverTime = HOVER_DEFAULT;
track.hwndTrack = pToolbar->hToolbarWnd;
_TrackMouseEvent(&track);
pToolbar->ClickMouse(LOWORD(lParam), HIWORD(lParam));
}
else if (message == WM_LBUTTONUP)
{
if (pToolbar->ButtonPressed1) SendMessage(pToolbar->hBlackboxWnd, BB_WORKSPACE, 0, 0);
else if (pToolbar->ButtonPressed2) SendMessage(pToolbar->hBlackboxWnd, BB_WORKSPACE, 1, 0);
else if (pToolbar->ButtonPressed3)
{
if (GetAsyncKeyState(VK_MENU) & 0x8000)
SendMessage(pToolbar->hBlackboxWnd, BB_WORKSPACE, 8, 0);
else
SendMessage(pToolbar->hBlackboxWnd, BB_WORKSPACE, 8, 1);
}
else if (pToolbar->ButtonPressed4)
{
if (GetAsyncKeyState(VK_MENU) & 0x8000)
SendMessage(pToolbar->hBlackboxWnd, BB_WORKSPACE, 9, 0);
else
SendMessage(pToolbar->hBlackboxWnd, BB_WORKSPACE, 9, 1);
}
pToolbar->ButtonPressed1 = pToolbar->ButtonPressed2 = pToolbar->ButtonPressed3 = pToolbar->ButtonPressed4 = false;
InvalidateRect(pToolbar->hToolbarWnd, NULL, false);
}
else if (message == WM_RBUTTONUP)
{
if (GetAsyncKeyState(VK_MENU) & 0x8000) SendMessage(GetBBWnd(), BB_MENU, 0, 0);
else if (GetAsyncKeyState(VK_SHIFT) & 0x8000) SendMessage(GetBBWnd(), BB_MENU, 1, 0);
else SendMessage(GetBBWnd(), BB_MENU, 2, 0);
}
else if (message == WM_MBUTTONUP)
{
if (GetAsyncKeyState(VK_MENU) & 0x8000) PostMessage(GetBBWnd(), BB_TOGGLESLIT, 0, 0);
else if (GetAsyncKeyState(VK_SHIFT) & 0x8000) PostMessage(GetBBWnd(), BB_TOGGLEPLUGINS, 0, 0);
else if (GetAsyncKeyState(VK_CONTROL) & 0x8000) PostMessage(GetBBWnd(), BB_TOGGLEPLUGINS, 0, 0);
else if (!stricmp(pSettings->systembarPlacement, "DockedToSlit")) PostMessage(GetBBWnd(), BB_TOGGLESLIT, 0, 0);
else PostMessage(GetBBWnd(), BB_TOGGLESYSTEMBAR, 0, 0);
}
else if (message == WM_XBUTTONDOWN)
{
if (HIWORD(wParam) == XBUTTON1)
{
if (pSettings->taskbarOnToolbar)
{
if (GetAsyncKeyState(VK_MENU) & 0x8000) pSystembar->RestoreAllWindows();
else pSystembar->MinimizeAllWindows();
}
else BBExecute(GetDesktopWindow(), NULL, "control.exe", "desk.cpl,,3", NULL, SW_SHOWNORMAL, false);
}
else if (HIWORD(wParam) == XBUTTON2)
{
if (pSettings->taskbarOnToolbar) pSystembar->RestoreAllWindows();
else BBExecute(GetDesktopWindow(), NULL, "control.exe", "mmsys.cpl", NULL, SW_SHOWNORMAL, false);
}
}
}
break;
case WM_MOUSEWHEEL:
{
if (!(GetAsyncKeyState(VK_CONTROL) & 0x8000)) break;
bool sizechanged = false;
if (GET_WHEEL_DELTA_WPARAM(wParam) < 0)
{
if (pSettings->toolbarWidthPercent > 30)
{
sizechanged = true;
pSettings->toolbarWidthPercent--;
}
}
else
{
if (pSettings->toolbarWidthPercent < 100)
{
sizechanged = true;
pSettings->toolbarWidthPercent++;
}
}
if (sizechanged)
{
pToolbar->GetSettings();
pToolbar->cachedBitmapsExist = false;
if (pSettings->taskbarOnToolbar && pSystembar) pSystembar->cachedTaskButtonsExist = false;
InvalidateRect(pToolbar->hToolbarWnd, NULL, false);
MoveWindow(pToolbar->hToolbarWnd, pToolbar->ToolbarX, pToolbar->ToolbarY, pToolbar->ToolbarWidth, pToolbar->ToolbarHeight, true);
if (pSettings->toolbarOnTop) SetWindowPos(pToolbar->hToolbarWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
else SetWindowPos(pToolbar->hToolbarWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar") && pSystembar) pSystembar->UpdatePosition();
pToolbar->saveWidthOnRestart = true;
}
}
break;
case WM_MOUSEMOVE:
{
if (pSettings->toolbarAutoHide) pToolbar->AutoShow();
}
break;
case WM_MOUSELEAVE:
case WM_NCMOUSELEAVE:
{
pToolbar->ButtonPressed1 = pToolbar->ButtonPressed2 = pToolbar->ButtonPressed3 = pToolbar->ButtonPressed4 = false;
InvalidateRect(pToolbar->hToolbarWnd, NULL, false);
}
break;
case WM_WINDOWPOSCHANGING:
{
if (!pSettings->toolbarAutoHide && (pSettings->toolbarPlacement[0] == 'M') && pSettings->toolbarSnapToEdges)
{
if (pToolbar)
{
if (IsWindowVisible(hwnd)) SnapWindowToEdge((WINDOWPOS*)lParam, pSettings->edgeSnapThreshold, true);
}
}
}
return 0;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
void Toolbar::DrawWindowLabel(HDC hdc, RECT r)
{
RECT wlRect, wlTextRect;
CopyRect(&wlRect, &r);
CopyRect(&wlTextRect, &wlRect);
if (!EqualRect(¤tWindowLabelRect, &wlRect))
{
CopyRect(¤tWindowLabelRect, &wlRect);
currentWindowLabelWidth = wlRect.right - wlRect.left;
currentWindowLabelHeight = wlRect.bottom - wlRect.top;
if (!pSettings->ToolbarWindowLabel->parentRelative)
{
HBITMAP tempBitmap = CreateCompatibleBitmap(hdc, currentWindowLabelWidth, currentWindowLabelHeight);
HBITMAP oldBitmap = (HBITMAP)SelectObject(cachedToolbarWindowLabel, tempBitmap);
DeleteObject(oldBitmap);
r.left = 0; r.top = 0; r.right = currentWindowLabelWidth; r.bottom = currentWindowLabelHeight;
MakeGradient(cachedToolbarWindowLabel, r, pSettings->ToolbarWindowLabel->type, pSettings->ToolbarWindowLabel->Color, pSettings->ToolbarWindowLabel->ColorTo, pSettings->ToolbarWindowLabel->interlaced, pSettings->ToolbarWindowLabel->bevelstyle, pSettings->ToolbarWindowLabel->bevelposition, pSettings->bevelWidth, pSettings->ToolbarWindowLabel->borderColor, pSettings->ToolbarWindowLabel->borderWidth);
DeleteObject(tempBitmap);
}
}
if (!pSettings->ToolbarWindowLabel->parentRelative)
{
BitBlt(hdc, wlRect.left, wlRect.top, currentWindowLabelWidth, currentWindowLabelHeight, cachedToolbarWindowLabel, 0, 0, SRCCOPY);
}
HFONT font = CreateFont(pSettings->ToolbarWindowLabel->FontHeight, 0, 0, 0, pSettings->ToolbarWindowLabel->FontWeight, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, pSettings->ToolbarWindowLabel->Font);
HGDIOBJ oldfont = SelectObject(hdc, font);
SetBkMode(hdc, TRANSPARENT);
unsigned int format = pSettings->ToolbarWindowLabel->Justify | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE | DT_WORD_ELLIPSIS;
if (!pSettings->taskbarOnToolbar)
{
wlTextRect.left = wlTextRect.left + 3;
if (pSettings->writeProtection && pSettings->checkingForUpdates) wlTextRect.right = wlTextRect.right - 22;
else if (pSettings->writeProtection) wlTextRect.right = wlTextRect.right - 13;
else if (pSettings->checkingForUpdates) wlTextRect.right = wlTextRect.right - 14;
else wlTextRect.right = wlTextRect.right - 3;
}
else
{
wlTextRect.left = wlTextRect.left + 7;
if (pSettings->writeProtection && pSettings->checkingForUpdates) wlTextRect.right = wlTextRect.right - 29;
else if (pSettings->writeProtection) wlTextRect.right = wlTextRect.right - 20;
else if (pSettings->checkingForUpdates) wlTextRect.right = wlTextRect.right - 21;
else wlTextRect.right = wlTextRect.right - 7;
}
DrawTextWithShadow(hdc, pToolbar->CurrentWindow, wlTextRect, format, pSettings->ToolbarWindowLabel->TextColor, pSettings->toolbarWindowLabelShadowColor, pSettings->ToolbarWindowLabel->FontShadow);
DeleteObject(SelectObject(hdc, oldfont));
if (pSettings->writeProtection)
{
int lockIconX, lockIconY;
if (!pSettings->taskbarOnToolbar) lockIconX = wlRect.right - 4;
else lockIconX = wlRect.right - 7;
lockIconY = (wlRect.bottom - wlRect.top)/2;
HPEN protectPen = CreatePen(PS_SOLID, 1, pSettings->toolbarWindowLabelShadowColor);
HPEN oldPen = (HPEN) SelectObject(hdc, protectPen);
MoveToEx(hdc, lockIconX - 5, pSettings->Toolbar->borderWidth + lockIconY-2, NULL);
LineTo(hdc, lockIconX - 2, pSettings->Toolbar->borderWidth + lockIconY-2);
MoveToEx(hdc, lockIconX - 6, pSettings->Toolbar->borderWidth + lockIconY-1, NULL);
LineTo(hdc, lockIconX - 6, pSettings->Toolbar->borderWidth + lockIconY+1);
MoveToEx(hdc, lockIconX - 2, pSettings->Toolbar->borderWidth + lockIconY-1, NULL);
LineTo(hdc, lockIconX - 2, pSettings->Toolbar->borderWidth + lockIconY+1);
MoveToEx(hdc, lockIconX - 7, pSettings->Toolbar->borderWidth + lockIconY+1, NULL);
LineTo(hdc, lockIconX, pSettings->Toolbar->borderWidth + lockIconY+1);
MoveToEx(hdc, lockIconX - 7, pSettings->Toolbar->borderWidth + lockIconY+2, NULL);
LineTo(hdc, lockIconX, pSettings->Toolbar->borderWidth + lockIconY+2);
MoveToEx(hdc, lockIconX - 7, pSettings->Toolbar->borderWidth + lockIconY+3, NULL);
LineTo(hdc, lockIconX, pSettings->Toolbar->borderWidth + lockIconY+3);
MoveToEx(hdc, lockIconX - 7, pSettings->Toolbar->borderWidth + lockIconY+4, NULL);
LineTo(hdc, lockIconX, pSettings->Toolbar->borderWidth + lockIconY+4);
SelectObject(hdc, oldPen);
DeleteObject(protectPen);
}
if (pSettings->checkingForUpdates)
{
int checkIconX, checkIconY;
if (pSettings->writeProtection)
{
if (!pSettings->taskbarOnToolbar) checkIconX = wlRect.right - 13;
else checkIconX = wlRect.right - 16;
}
else
{
if (!pSettings->taskbarOnToolbar) checkIconX = wlRect.right - 5;
else checkIconX = wlRect.right - 8;
}
checkIconY = (wlRect.bottom - wlRect.top)/2;
HPEN checkPen = CreatePen(PS_SOLID, 1, pSettings->toolbarWindowLabelShadowColor);
HPEN oldPen = (HPEN) SelectObject(hdc, checkPen);
MoveToEx(hdc, checkIconX - 5, pSettings->Toolbar->borderWidth + checkIconY-2, NULL);
LineTo(hdc, checkIconX - 1, pSettings->Toolbar->borderWidth + checkIconY-2);
MoveToEx(hdc, checkIconX - 1, pSettings->Toolbar->borderWidth + checkIconY-1, NULL);
LineTo(hdc, checkIconX - 1, pSettings->Toolbar->borderWidth + checkIconY+2);
MoveToEx(hdc, checkIconX - 6, pSettings->Toolbar->borderWidth + checkIconY-1, NULL);
LineTo(hdc, checkIconX - 6, pSettings->Toolbar->borderWidth + checkIconY);
MoveToEx(hdc, checkIconX, pSettings->Toolbar->borderWidth + checkIconY, NULL);
LineTo(hdc, checkIconX - 3, pSettings->Toolbar->borderWidth + checkIconY);
MoveToEx(hdc, checkIconX - 5, pSettings->Toolbar->borderWidth + checkIconY+4, NULL);
LineTo(hdc, checkIconX - 1, pSettings->Toolbar->borderWidth + checkIconY+4);
MoveToEx(hdc, checkIconX - 6, pSettings->Toolbar->borderWidth + checkIconY+3, NULL);
LineTo(hdc, checkIconX - 6, pSettings->Toolbar->borderWidth + checkIconY);
MoveToEx(hdc, checkIconX - 1, pSettings->Toolbar->borderWidth + checkIconY+3, NULL);
LineTo(hdc, checkIconX - 1, pSettings->Toolbar->borderWidth + checkIconY+2);
MoveToEx(hdc, checkIconX - 7, pSettings->Toolbar->borderWidth + checkIconY+2, NULL);
LineTo(hdc, checkIconX - 4, pSettings->Toolbar->borderWidth + checkIconY+2);
SelectObject(hdc, oldPen);
DeleteObject(checkPen);
}
}
void Toolbar::DrawArrowBackward(HDC hdc, int xcenter, int ycenter)
{
if (!pSettings->alternativeBullets)
{
MoveToEx(hdc, xcenter-1, ycenter, NULL);
LineTo(hdc, xcenter-1, ycenter+1);
MoveToEx(hdc, xcenter, ycenter-1, NULL);
LineTo(hdc, xcenter, ycenter+2);
MoveToEx(hdc, xcenter+1, ycenter-2, NULL);
LineTo(hdc, xcenter+1, ycenter+3);
}
else
{
MoveToEx(hdc, xcenter+1, ycenter-1, NULL);
LineTo(hdc, xcenter+3, ycenter-1);
MoveToEx(hdc, xcenter-1, ycenter, NULL);
LineTo(hdc, xcenter+3, ycenter);
MoveToEx(hdc, xcenter+1, ycenter+1, NULL);
LineTo(hdc, xcenter+3, ycenter+1);
}
}
void Toolbar::DrawArrowForward(HDC hdc, int xcenter, int ycenter)
{
if (!pSettings->alternativeBullets)
{
MoveToEx(hdc, xcenter-1, ycenter-2, NULL);
LineTo(hdc, xcenter-1, ycenter+3);
MoveToEx(hdc, xcenter, ycenter-1, NULL);
LineTo(hdc, xcenter, ycenter+2);
MoveToEx(hdc, xcenter+1, ycenter, NULL);
LineTo(hdc, xcenter+1, ycenter+1);
}
else
{
MoveToEx(hdc, xcenter-1, ycenter-1, NULL);
LineTo(hdc, xcenter+1, ycenter-1);
MoveToEx(hdc, xcenter-1, ycenter, NULL);
LineTo(hdc, xcenter+3, ycenter);
MoveToEx(hdc, xcenter-1, ycenter+1, NULL);
LineTo(hdc, xcenter+1, ycenter+1);
}
}
void Toolbar::GetSettings()
{
ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
ToolbarWidth = (ScreenWidth * pSettings->toolbarWidthPercent) / 100;
int borderPadding = 0;
if (pSettings->ToolbarLabel->borderWidth > borderPadding) borderPadding = pSettings->ToolbarLabel->borderWidth;
if (pSettings->ToolbarWindowLabel->borderWidth > borderPadding) borderPadding = pSettings->ToolbarWindowLabel->borderWidth;
if (pSettings->ToolbarClock->borderWidth > borderPadding) borderPadding = pSettings->ToolbarClock->borderWidth;
if (pSettings->ToolbarButton->borderWidth > borderPadding) borderPadding = pSettings->ToolbarButton->borderWidth;
int fontPadding = pSettings->Toolbar->FontHeight;
if (pSettings->ToolbarLabel->FontHeight > fontPadding) fontPadding = pSettings->ToolbarLabel->FontHeight;
if (pSettings->ToolbarWindowLabel->FontHeight > fontPadding) fontPadding = pSettings->ToolbarWindowLabel->FontHeight;
if (pSettings->ToolbarClock->FontHeight > fontPadding) fontPadding = pSettings->ToolbarClock->FontHeight;
if (fontPadding > 12) fontPadding -= 12;
else fontPadding = 0;
ToolbarHeight = 15 + (borderPadding*2) + fontPadding;
if (pSettings->taskbarOnToolbar && (ToolbarHeight < 17)) ToolbarHeight = 17;
ToolbarHeight += (pSettings->Toolbar->borderWidth * 2);
if (pSettings->toolbarPlacement[0] == 'M')
{
char tempPlacement[MAX_LINE_LENGTH];
strcpy(tempPlacement, pSettings->toolbarPlacement);
char token1[MAX_LINE_LENGTH], token2[MAX_LINE_LENGTH], token3[MAX_LINE_LENGTH];
LPSTR tokens[2];
tokens[0] = token1;
tokens[1] = token2;
token1[0] = token2[0] = token3[0] = '\0';
BBTokenize (tempPlacement, tokens, 2, token3);
ToolbarX = atoi(&token2[1]);
ToolbarY = atoi(&token3[1]);
int xmax = ScreenWidth - ToolbarWidth;
int ymax = ScreenHeight - ToolbarHeight;
if (ToolbarX < 0) ToolbarX = 0;
if (ToolbarY < 0) ToolbarY = 0;
if (ToolbarX > xmax) ToolbarX = xmax;
if (ToolbarY > ymax) ToolbarY = ymax;
return;
}
if (!stricmp(pSettings->toolbarPlacement, "TopLeft"))
{
ToolbarX = 0;
ToolbarY = 0;
if (!pSettings->systembarHidden && !stricmp(pSettings->systembarPlacement, "DockedToToolbar")) ToolbarAutoHideTarget = 0 - ToolbarHeight;
else ToolbarAutoHideTarget = 1 - ToolbarHeight;
ToolbarAutoShowTarget = 0;
}
else if (!stricmp(pSettings->toolbarPlacement, "TopCenter"))
{
ToolbarX = (ScreenWidth - ToolbarWidth) / 2;
ToolbarY = 0;
if (!pSettings->systembarHidden && !stricmp(pSettings->systembarPlacement, "DockedToToolbar")) ToolbarAutoHideTarget = 0 - ToolbarHeight;
else ToolbarAutoHideTarget = 1 - ToolbarHeight;
ToolbarAutoShowTarget = 0;
}
else if (!stricmp(pSettings->toolbarPlacement, "TopRight"))
{
ToolbarX = ScreenWidth - ToolbarWidth;
ToolbarY = 0;
if (!pSettings->systembarHidden && !stricmp(pSettings->systembarPlacement, "DockedToToolbar")) ToolbarAutoHideTarget = 0 - ToolbarHeight;
else ToolbarAutoHideTarget = 1 - ToolbarHeight;
ToolbarAutoShowTarget = 0;
}
else if (!stricmp(pSettings->toolbarPlacement, "BottomLeft"))
{
ToolbarX = 0;
ToolbarY = ScreenHeight - ToolbarHeight;
if (!pSettings->systembarHidden && !stricmp(pSettings->systembarPlacement, "DockedToToolbar")) ToolbarAutoHideTarget = ScreenHeight;
else ToolbarAutoHideTarget = ScreenHeight - 1;
ToolbarAutoShowTarget = ScreenHeight - ToolbarHeight;
}
else if (!stricmp(pSettings->toolbarPlacement, "BottomCenter"))
{
ToolbarX = (ScreenWidth - ToolbarWidth) / 2;
ToolbarY = ScreenHeight - ToolbarHeight;
if (!pSettings->systembarHidden && !stricmp(pSettings->systembarPlacement, "DockedToToolbar")) ToolbarAutoHideTarget = ScreenHeight;
else ToolbarAutoHideTarget = ScreenHeight - 1;
ToolbarAutoShowTarget = ScreenHeight - ToolbarHeight;
}
else if (!stricmp(pSettings->toolbarPlacement, "BottomRight"))
{
ToolbarX = ScreenWidth - ToolbarWidth;
ToolbarY = ScreenHeight - ToolbarHeight;
if (!pSettings->systembarHidden && !stricmp(pSettings->systembarPlacement, "DockedToToolbar")) ToolbarAutoHideTarget = ScreenHeight;
else ToolbarAutoHideTarget = ScreenHeight - 1;
ToolbarAutoShowTarget = ScreenHeight - ToolbarHeight;
}
else ToolbarY = ScreenHeight - ToolbarHeight;
}
void Toolbar::UpdatePosition()
{
pToolbar->GetSettings();
MoveWindow(hToolbarWnd, ToolbarX, ToolbarY, ToolbarWidth, ToolbarHeight, true);
cachedBitmapsExist = false;
if (pSettings->taskbarOnToolbar && pSystembar) pSystembar->cachedTaskButtonsExist = false;
else SetRectEmpty(&pToolbar->currentWindowLabelRect);
InvalidateRect(hToolbarWnd, NULL, false);
if (pSettings->toolbarOnTop) SetWindowPos(hToolbarWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
else SetWindowPos(hToolbarWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
SetTransparency(hToolbarWnd, pSettings->toolbarTransparencyAlpha);
UpdateDesktopArea();
if (pSettings->toolbarAutoHide)
{
ToolbarAutoHiding = ToolbarAutoShowing = false;
ToolbarAutoHidden = false;
ToolbarAutoShown = true;
if (!CheckIfMouseHover()) AutoHide();
}
WriteString(bbrcPath(), "session.screen0.toolbar.placement:", pSettings->toolbarPlacement);
if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar")) pSystembar->UpdatePosition();
}
void Toolbar::UpdateDesktopArea()
{
RECT r;
if (pSettings->fullMaximization)
{
r.left = 0;
r.right = ScreenWidth;
r.top = 0;
r.bottom = ScreenHeight;
}
else if (pSettings->desktopAreaNotDefined)
{
r.left = 0;
r.right = ScreenWidth;
if (ToolbarY == 0)
{
r.top = ToolbarHeight + 5;
r.bottom = ScreenHeight;
}
else
{
r.top = 0;
r.bottom = ScreenHeight - ToolbarHeight - 5;
}
}
else
{
r.left = pSettings->desktopArea.left;
r.top = pSettings->desktopArea.top;
r.right = ScreenWidth - pSettings->desktopArea.right;
r.bottom = ScreenHeight - pSettings->desktopArea.bottom;
}
SystemParametersInfo(SPI_SETWORKAREA, 0, (PVOID)&r, SPIF_SENDCHANGE);
SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)&r, SPIF_SENDCHANGE);
}
void Toolbar::ClickMouse(int mouseX, int mouseY)
{
if (mouseY >= 3 && mouseY <= (ToolbarHeight - 3))
{
if (mouseX >= ButtonX1 && mouseX <= (ButtonX1 + ButtonWH))
{
ButtonPressed1 = true;
InvalidateRect(hToolbarWnd, NULL, false);
return;
}
else if (mouseX >= ButtonX2 && mouseX <= (ButtonX2 + ButtonWH))
{
ButtonPressed2 = true;
InvalidateRect(hToolbarWnd, NULL, false);
return;
}
else if (mouseX >= ButtonX3 && mouseX <= (ButtonX3 + ButtonWH))
{
ButtonPressed3 = true;
InvalidateRect(hToolbarWnd, NULL, false);
return;
}
else if (mouseX >= ButtonX4 && mouseX <= (ButtonX4 + ButtonWH))
{
ButtonPressed4 = true;
InvalidateRect(hToolbarWnd, NULL, false);
return;
}
else if (pMenuMaker) pMenuMaker->Hide();
}
else if (pMenuMaker) pMenuMaker->Hide();
}
void Toolbar::ToggleAlwaysOnTop()
{
if (!pSettings->toolbarOnTop)
{
pSettings->toolbarOnTop = true;
SetWindowPos(hToolbarWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
}
else
{
pSettings->toolbarOnTop = false;
SetWindowPos(hToolbarWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
}
WriteBool(bbrcPath(), "session.screen0.toolbar.onTop:", pSettings->toolbarOnTop);
}
bool Toolbar::CheckIfMouseHover()
{
POINT mousepos;
GetCursorPos(&mousepos);
if (mousepos.x >= ToolbarX && mousepos.x <= (ToolbarX + ToolbarWidth))
{
if (mousepos.y >= ToolbarY && mousepos.y <= (ToolbarY + ToolbarHeight)) return true;
}
return false;
}
void Toolbar::AutoShow()
{
if (pSettings->toolbarAutoHide && !ToolbarAutoShowing && !ToolbarAutoShown)
{
if (ToolbarAutoHiding)
{
KillTimer(hToolbarWnd, TOOLBAR_AUTOHIDE_TIMER);
ToolbarAutoHiding = false;
}
if (IsInString(pSettings->toolbarPlacement, "Bottom"))
{
if (!pSettings->systembarHidden && !stricmp(pSettings->systembarPlacement, "DockedToToolbar")) ToolbarAutoCurrentPos = ScreenHeight;
else ToolbarAutoCurrentPos = ScreenHeight - 1;
}
else
{
if (!pSettings->systembarHidden && !stricmp(pSettings->systembarPlacement, "DockedToToolbar")) ToolbarAutoCurrentPos = 0 - ToolbarHeight;
else ToolbarAutoCurrentPos = 1 - ToolbarHeight;
}
ToolbarAutoHidden = false;
ToolbarAutoShowing = true;
SetTransparency(hToolbarWnd, pSettings->toolbarTransparencyAlpha);
if (!SetTimer(hToolbarWnd, TOOLBAR_AUTOHIDE_TIMER, pSettings->autohideSpeed, (TIMERPROC)NULL))
{
MessageBox(GetBBWnd(), "Error creating autohide timer", szToolbarName, MB_OK | MB_ICONERROR | MB_TOPMOST);
Log("Could not create Toolbar autohide timer", NULL);
}
}
}
void Toolbar::AutoHide()
{
if (pSettings->toolbarAutoHide && !ToolbarAutoHiding && !ToolbarAutoHidden)
{
if (ToolbarAutoShowing)
{
KillTimer(hToolbarWnd, TOOLBAR_AUTOHIDE_TIMER);
ToolbarAutoShowing = false;
}
ToolbarAutoCurrentPos = ToolbarY;
ToolbarAutoShown = false;
ToolbarAutoHiding = true;
if (!SetTimer(hToolbarWnd, TOOLBAR_AUTOHIDE_TIMER, pSettings->autohideSpeed, (TIMERPROC)NULL))
{
MessageBox(GetBBWnd(), "Error creating autohide timer", szToolbarName, MB_OK | MB_ICONERROR | MB_TOPMOST);
Log("Could not create Toolbar autohide timer", NULL);
}
}
}
syntax highlighting by