diff options
Diffstat (limited to 'plugins/TabSRMM/src/TSButton.cpp')
-rw-r--r-- | plugins/TabSRMM/src/TSButton.cpp | 697 |
1 files changed, 233 insertions, 464 deletions
diff --git a/plugins/TabSRMM/src/TSButton.cpp b/plugins/TabSRMM/src/TSButton.cpp index da368c2fd7..22b4da3127 100644 --- a/plugins/TabSRMM/src/TSButton.cpp +++ b/plugins/TabSRMM/src/TSButton.cpp @@ -39,9 +39,6 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
// External theme methods and properties
-
-static CRITICAL_SECTION csTips;
-static HWND hwndToolTips = NULL;
static BLENDFUNCTION bf_buttonglyph;
static HDC hdc_buttonglyph = 0;
static HBITMAP hbm_buttonglyph, hbm_buttonglyph_old;
@@ -50,60 +47,6 @@ static HBITMAP hbm_buttonglyph, hbm_buttonglyph_old; #define BUTTON_POLLID 100
#define BUTTON_POLLDELAY 50
-#define MGPROC(x) GetProcAddress(themeAPIHandle,x)
-
-int TSAPI UnloadTSButtonModule()
-{
- DeleteCriticalSection(&csTips);
- if (hdc_buttonglyph) {
- SelectObject(hdc_buttonglyph, hbm_buttonglyph_old);
- DeleteObject(hbm_buttonglyph);
- DeleteDC(hdc_buttonglyph);
- }
- return 0;
-}
-
-int TSAPI LoadTSButtonModule(void)
-{
- WNDCLASSEX wc;
-
- ZeroMemory(&wc, sizeof(wc));
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = _T("TSButtonClass");
- wc.lpfnWndProc = TSButtonWndProc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.cbWndExtra = sizeof(MButtonCtrl*);
- wc.hbrBackground = 0;
- wc.style = CS_GLOBALCLASS | CS_PARENTDC;
- RegisterClassEx(&wc);
- InitializeCriticalSection(&csTips);
- return 0;
-}
-
-static void TSAPI DestroyTheme(MButtonCtrl *ctl)
-{
- if (M.isVSAPIState()) {
- if (ctl->hThemeButton) {
- CMimAPI::m_pfnCloseThemeData(ctl->hThemeButton);
- ctl->hThemeButton = NULL;
- }
- if (ctl->hThemeToolbar) {
- CMimAPI::m_pfnCloseThemeData(ctl->hThemeToolbar);
- ctl->hThemeToolbar = NULL;
- }
- }
-}
-
-static void TSAPI LoadTheme(MButtonCtrl *ctl)
-{
- if (M.isVSAPIState()) {
- DestroyTheme(ctl);
- ctl->hThemeButton = CMimAPI::m_pfnOpenThemeData(ctl->hwnd, L"BUTTON");
- ctl->hThemeToolbar = (M.isAero() || IsWinVerVistaPlus()) ? CMimAPI::m_pfnOpenThemeData(ctl->hwnd, L"MENU") : CMimAPI::m_pfnOpenThemeData(ctl->hwnd, L"TOOLBAR");
- ctl->bThemed = TRUE;
- }
-}
-
int TSAPI TBStateConvert2Flat(int state)
{
switch (state) {
@@ -121,6 +64,22 @@ int TSAPI TBStateConvert2Flat(int state) return TS_NORMAL;
}
+int TSAPI RBStateConvert2Flat(int state)
+{
+ switch (state) {
+ case PBS_NORMAL:
+ return 1;
+ case PBS_HOT:
+ return 2;
+ case PBS_PRESSED:
+ return 3;
+ case PBS_DISABLED:
+ return 1;
+ case PBS_DEFAULTED:
+ return 1;
+ }
+ return 1;
+}
/**
* convert button state (hot, pressed, normal) to REBAR part state ids
@@ -129,24 +88,8 @@ int TSAPI TBStateConvert2Flat(int state) *
* @return int: state item id
*/
-int TSAPI RBStateConvert2Flat(int state)
-{
- switch (state) {
- case PBS_NORMAL:
- return 1;
- case PBS_HOT:
- return 2;
- case PBS_PRESSED:
- return 3;
- case PBS_DISABLED:
- return 1;
- case PBS_DEFAULTED:
- return 1;
- }
- return 1;
-}
-static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint)
+static void PaintWorker(TSButtonCtrl *ctl, HDC hdcPaint)
{
if (hdc_buttonglyph == 0) {
hdc_buttonglyph = CreateCompatibleDC(hdcPaint);
@@ -157,113 +100,78 @@ static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint) bf_buttonglyph.BlendOp = AC_SRC_OVER;
bf_buttonglyph.AlphaFormat = 0;
}
- if (hdcPaint) {
- HDC hdcMem;
- HBITMAP hbmMem, hOld;
- RECT rcClient;
- RECT rcContent;
- bool fAero = M.isAero();
- bool fVSThemed = (!CSkin::m_skinEnabled && M.isVSThemed());
- HANDLE hbp = 0;
-
- TWindowData *dat = (TWindowData*)GetWindowLongPtr(GetParent(ctl->hwnd), GWLP_USERDATA);
- GetClientRect(ctl->hwnd, const_cast<RECT *>(&rcClient));
- CopyRect(&rcContent, &rcClient);
-
- if (CMimAPI::m_haveBufferedPaint)
- hbp = CMimAPI::m_pfnBeginBufferedPaint(hdcPaint, &rcContent, BPBF_TOPDOWNDIB, NULL, &hdcMem);
- else {
- hdcMem = CreateCompatibleDC(hdcPaint);
- hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
- hOld = (HBITMAP)SelectObject(hdcMem, hbmMem);
- }
+
+ if (hdcPaint == NULL)
+ return;
+
+ HDC hdcMem;
+ HBITMAP hbmMem, hOld;
+ HANDLE hbp = 0;
+ bool bAero = M.isAero();
+
+ TWindowData *dat = (TWindowData*)GetWindowLongPtr(GetParent(ctl->hwnd), GWLP_USERDATA);
+
+ RECT rcClient, rcContent;
+ GetClientRect(ctl->hwnd, const_cast<RECT *>(&rcClient));
+ CopyRect(&rcContent, &rcClient);
+
+ if (CMimAPI::m_haveBufferedPaint)
+ hbp = CMimAPI::m_pfnBeginBufferedPaint(hdcPaint, &rcContent, BPBF_TOPDOWNDIB, NULL, &hdcMem);
+ else {
+ hdcMem = CreateCompatibleDC(hdcPaint);
+ hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
+ hOld = (HBITMAP)SelectObject(hdcMem, hbmMem);
+ }
- CSkin::FillBack(hdcMem, &rcContent);
+ CSkin::FillBack(hdcMem, &rcContent);
- if (ctl->pushBtn && ctl->pbState)
- ctl->stateId = PBS_PRESSED;
+ if (ctl->bIsPushBtn && ctl->bIsPushed)
+ ctl->stateId = PBS_PRESSED;
- if (ctl->flatBtn) {
- if (ctl->pContainer && CSkin::m_skinEnabled) {
- CSkinItem *item, *realItem = 0;
- if (ctl->bTitleButton)
- item = &SkinItems[ctl->stateId == PBS_NORMAL ? ID_EXTBKTITLEBUTTON : (ctl->stateId == PBS_HOT ? ID_EXTBKTITLEBUTTONMOUSEOVER : ID_EXTBKTITLEBUTTONPRESSED)];
- else {
- item = &SkinItems[(ctl->stateId == PBS_NORMAL || ctl->stateId == PBS_DISABLED) ? ID_EXTBKBUTTONSNPRESSED : (ctl->stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : ID_EXTBKBUTTONSPRESSED)];
- realItem = item;
- }
- CSkin::SkinDrawBG(ctl->hwnd, ctl->pContainer->hwnd, ctl->pContainer, &rcContent, hdcMem);
- if (!item->IGNORED) {
- RECT rc1 = rcClient;
- rc1.left += item->MARGIN_LEFT;
- rc1.right -= item->MARGIN_RIGHT;
- rc1.top += item->MARGIN_TOP;
- rc1.bottom -= item->MARGIN_BOTTOM;
- CSkin::DrawItem(hdcMem, &rc1, item);
- } else
- goto flat_themed;
- } else {
+ if (ctl->bIsFlat) {
+ if (ctl->pContainer && CSkin::m_skinEnabled) {
+ CSkinItem *item, *realItem = 0;
+ if (ctl->bTitleButton)
+ item = &SkinItems[ctl->stateId == PBS_NORMAL ? ID_EXTBKTITLEBUTTON : (ctl->stateId == PBS_HOT ? ID_EXTBKTITLEBUTTONMOUSEOVER : ID_EXTBKTITLEBUTTONPRESSED)];
+ else {
+ item = &SkinItems[(ctl->stateId == PBS_NORMAL || ctl->stateId == PBS_DISABLED) ? ID_EXTBKBUTTONSNPRESSED : (ctl->stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : ID_EXTBKBUTTONSPRESSED)];
+ realItem = item;
+ }
+ CSkin::SkinDrawBG(ctl->hwnd, ctl->pContainer->hwnd, ctl->pContainer, &rcContent, hdcMem);
+ if (!item->IGNORED) {
+ RECT rc1 = rcClient;
+ rc1.left += item->MARGIN_LEFT;
+ rc1.right -= item->MARGIN_RIGHT;
+ rc1.top += item->MARGIN_TOP;
+ rc1.bottom -= item->MARGIN_BOTTOM;
+ CSkin::DrawItem(hdcMem, &rc1, item);
+ }
+ else goto flat_themed;
+ }
+ else {
flat_themed:
- int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
-
- if (ctl->bToolbarButton) {
- if (dat) {
- RECT rcWin;
- GetWindowRect(ctl->hwnd, &rcWin);
- POINT pt;
- pt.x = rcWin.left;
- ScreenToClient(dat->hwnd, &pt);
- BitBlt(hdcMem, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
- dat->pContainer->cachedToolbarDC, pt.x, 1, SRCCOPY);
- }
- }
- if (ctl->hThemeToolbar && ctl->bThemed && 1 == dat->pContainer->bTBRenderingMode) {
- if (fAero || PluginConfig.m_WinVerMajor >= 6)
- CMimAPI::m_pfnDrawThemeBackground(ctl->hThemeToolbar, hdcMem, 8, RBStateConvert2Flat(state), &rcClient, &rcClient);
- else
- CMimAPI::m_pfnDrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rcClient, &rcClient);
- } else {
- CSkin::m_switchBarItem->setAlphaFormat(AC_SRC_ALPHA, state == PBS_HOT ? 220 : 180);
- if (state == PBS_HOT || state == PBS_PRESSED) {
- if (state == PBS_PRESSED) {
- RECT rc = rcClient;
- InflateRect(&rc, -1, -1);
- HBRUSH bBack = CreateSolidBrush(PluginConfig.m_tbBackgroundLow ? PluginConfig.m_tbBackgroundLow : GetSysColor(COLOR_3DDKSHADOW));
- FillRect(hdcMem, &rc, bBack);
- DeleteObject(bBack);
- }
- CSkin::m_switchBarItem->Render(hdcMem, &rcClient, true);
- }
+ int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->bIsDefault ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
+
+ if (ctl->bToolbarButton) {
+ if (dat) {
+ RECT rcWin;
+ GetWindowRect(ctl->hwnd, &rcWin);
+ POINT pt;
+ pt.x = rcWin.left;
+ ScreenToClient(dat->hwnd, &pt);
+ BitBlt(hdcMem, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
+ dat->pContainer->cachedToolbarDC, pt.x, 1, SRCCOPY);
}
}
- } else {
- if (ctl->pContainer && CSkin::m_skinEnabled) {
- CSkinItem *item, *realItem = 0;
- if (ctl->bTitleButton)
- item = &SkinItems[ctl->stateId == PBS_NORMAL ? ID_EXTBKTITLEBUTTON : (ctl->stateId == PBS_HOT ? ID_EXTBKTITLEBUTTONMOUSEOVER : ID_EXTBKTITLEBUTTONPRESSED)];
- else {
- item = &SkinItems[(ctl->stateId == PBS_NORMAL || ctl->stateId == PBS_DISABLED) ? ID_EXTBKBUTTONSNPRESSED : (ctl->stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : ID_EXTBKBUTTONSPRESSED)];
- realItem = item;
- }
- CSkin::SkinDrawBG(ctl->hwnd, ctl->pContainer->hwnd, ctl->pContainer, &rcClient, hdcMem);
- if (!item->IGNORED) {
- RECT rc1 = rcClient;
- rc1.left += item->MARGIN_LEFT;
- rc1.right -= item->MARGIN_RIGHT;
- rc1.top += item->MARGIN_TOP;
- rc1.bottom -= item->MARGIN_BOTTOM;
- CSkin::DrawItem(hdcMem, &rc1, item);
- } else
- goto nonflat_themed;
- } else {
-nonflat_themed:
- int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
-
- if (ctl->hThemeButton && ctl->bThemed && 0 == PluginConfig.m_fillColor) {
- CMimAPI::m_pfnDrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, &rcClient, &rcClient);
- CMimAPI::m_pfnGetThemeBackgroundContentRect(ctl->hThemeToolbar, hdcMem, BP_PUSHBUTTON, PBS_NORMAL, &rcClient, &rcContent);
- } else {
- CSkin::m_switchBarItem->setAlphaFormat(AC_SRC_ALPHA, state == PBS_NORMAL ? 140 : 240);
+ if (ctl->hThemeToolbar && ctl->bIsThemed && 1 == dat->pContainer->bTBRenderingMode) {
+ if (bAero || PluginConfig.m_WinVerMajor >= 6)
+ CMimAPI::m_pfnDrawThemeBackground(ctl->hThemeToolbar, hdcMem, 8, RBStateConvert2Flat(state), &rcClient, &rcClient);
+ else
+ CMimAPI::m_pfnDrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rcClient, &rcClient);
+ }
+ else {
+ CSkin::m_switchBarItem->setAlphaFormat(AC_SRC_ALPHA, state == PBS_HOT ? 220 : 180);
+ if (state == PBS_HOT || state == PBS_PRESSED) {
if (state == PBS_PRESSED) {
RECT rc = rcClient;
InflateRect(&rc, -1, -1);
@@ -273,199 +181,151 @@ nonflat_themed: }
CSkin::m_switchBarItem->Render(hdcMem, &rcClient, true);
}
-
- // Draw focus rectangle if button has focus
- if (ctl->focus) {
- RECT focusRect = rcClient;
- InflateRect(&focusRect, -3, -3);
- DrawFocusRect(hdcMem, &focusRect);
- }
}
}
-
- /*
- * render content
- */
- if (ctl->arrow) {
- rcContent.top += 2;
- rcContent.bottom -= 2;
- rcContent.left = rcClient.right - 12;
- rcContent.right = rcContent.left;
-
- DrawIconEx(hdcMem, rcClient.right - 15, (rcClient.bottom - rcClient.top) / 2 - (PluginConfig.m_smcyicon / 2),
- PluginConfig.g_buttonBarIcons[ICON_DEFAULT_PULLDOWN], 16, 16, 0, 0, DI_NORMAL);
+ }
+ else {
+ if (ctl->pContainer && CSkin::m_skinEnabled) {
+ CSkinItem *item, *realItem = 0;
+ if (ctl->bTitleButton)
+ item = &SkinItems[ctl->stateId == PBS_NORMAL ? ID_EXTBKTITLEBUTTON : (ctl->stateId == PBS_HOT ? ID_EXTBKTITLEBUTTONMOUSEOVER : ID_EXTBKTITLEBUTTONPRESSED)];
+ else {
+ item = &SkinItems[(ctl->stateId == PBS_NORMAL || ctl->stateId == PBS_DISABLED) ? ID_EXTBKBUTTONSNPRESSED : (ctl->stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : ID_EXTBKBUTTONSPRESSED)];
+ realItem = item;
+ }
+ CSkin::SkinDrawBG(ctl->hwnd, ctl->pContainer->hwnd, ctl->pContainer, &rcClient, hdcMem);
+ if (!item->IGNORED) {
+ RECT rc1 = rcClient;
+ rc1.left += item->MARGIN_LEFT;
+ rc1.right -= item->MARGIN_RIGHT;
+ rc1.top += item->MARGIN_TOP;
+ rc1.bottom -= item->MARGIN_BOTTOM;
+ CSkin::DrawItem(hdcMem, &rc1, item);
+ } else
+ goto nonflat_themed;
}
+ else {
+nonflat_themed:
+ int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->bIsDefault ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
- if (ctl->hIcon || ctl->hIconPrivate) {
- int ix = (rcClient.right - rcClient.left) / 2 - 8;
- int iy = (rcClient.bottom - rcClient.top) / 2 - 8;
- HICON hIconNew = ctl->hIconPrivate != 0 ? ctl->hIconPrivate : ctl->hIcon;
-
- if (ctl->stateId == PBS_PRESSED) {
- ix++;
- iy++;
+ if (ctl->hThemeButton && ctl->bIsThemed && 0 == PluginConfig.m_fillColor) {
+ CMimAPI::m_pfnDrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, &rcClient, &rcClient);
+ CMimAPI::m_pfnGetThemeBackgroundContentRect(ctl->hThemeToolbar, hdcMem, BP_PUSHBUTTON, PBS_NORMAL, &rcClient, &rcContent);
}
-
- if (ctl->arrow)
- ix -= 4;
-
- if (ctl->dimmed && PluginConfig.m_IdleDetect)
- CSkin::DrawDimmedIcon(hdcMem, ix, iy, PluginConfig.m_smcxicon, PluginConfig.m_smcyicon, hIconNew, 180);
else {
- if (ctl->stateId != PBS_DISABLED || CMimAPI::m_MyAlphaBlend == 0) {
- DrawIconEx(hdcMem, ix, iy, hIconNew, 16, 16, 0, 0, DI_NORMAL);
- if (ctl->overlay)
- DrawIconEx(hdcMem, ix, iy, ctl->overlay, 16, 16, 0, 0, DI_NORMAL);
+ CSkin::m_switchBarItem->setAlphaFormat(AC_SRC_ALPHA, state == PBS_NORMAL ? 140 : 240);
+ if (state == PBS_PRESSED) {
+ RECT rc = rcClient;
+ InflateRect(&rc, -1, -1);
+ HBRUSH bBack = CreateSolidBrush(PluginConfig.m_tbBackgroundLow ? PluginConfig.m_tbBackgroundLow : GetSysColor(COLOR_3DDKSHADOW));
+ FillRect(hdcMem, &rc, bBack);
+ DeleteObject(bBack);
}
- else {
- BitBlt(hdc_buttonglyph, 0, 0, 16, 16, hdcMem, ix, iy, SRCCOPY);
- DrawIconEx(hdc_buttonglyph, 0, 0, hIconNew, 16, 16, 0, 0, DI_NORMAL);
- if (ctl->overlay)
- DrawIconEx(hdc_buttonglyph, 0, 0, ctl->overlay, 16, 16, 0, 0, DI_NORMAL);
- CMimAPI::m_MyAlphaBlend(hdcMem, ix, iy, PluginConfig.m_smcxicon, PluginConfig.m_smcyicon, hdc_buttonglyph, 0, 0, 16, 16, bf_buttonglyph);
- }
- }
- } else if (GetWindowTextLength(ctl->hwnd)) {
- // Draw the text and optinally the arrow
- TCHAR szText[MAX_PATH];
- SIZE sz;
- RECT rcText;
- HFONT hOldFont;
-
- CopyRect(&rcText, &rcClient);
- GetWindowText(ctl->hwnd, szText, MAX_PATH - 1);
- SetBkMode(hdcMem, TRANSPARENT);
- hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
- if (ctl->pContainer && CSkin::m_skinEnabled)
- SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd) ? CSkin::m_DefaultFontColor : GetSysColor(COLOR_GRAYTEXT));
- else {
- if (PluginConfig.m_genericTxtColor)
- SetTextColor(hdcMem, PluginConfig.m_genericTxtColor);
- else
- SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_GRAYTEXT));
+ CSkin::m_switchBarItem->Render(hdcMem, &rcClient, true);
}
- GetTextExtentPoint32(hdcMem, szText, lstrlen(szText), &sz);
- if (ctl->cHot) {
- SIZE szHot;
- GetTextExtentPoint32A(hdcMem, "&", 1, &szHot);
- sz.cx -= szHot.cx;
+ // Draw focus rectangle if button has focus
+ if (ctl->focus) {
+ RECT focusRect = rcClient;
+ InflateRect(&focusRect, -3, -3);
+ DrawFocusRect(hdcMem, &focusRect);
}
- if (ctl->arrow)
- DrawState(hdcMem, NULL, NULL, (LPARAM)ctl->arrow, 0, rcClient.right - rcClient.left - 5 - PluginConfig.m_smcxicon + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), (rcClient.bottom - rcClient.top) / 2 - PluginConfig.m_smcyicon / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), PluginConfig.m_smcxicon, PluginConfig.m_smcyicon, IsWindowEnabled(ctl->hwnd) ? DST_ICON : DST_ICON | DSS_DISABLED);
- SelectObject(hdcMem, ctl->hFont);
- DrawState(hdcMem, NULL, NULL, (LPARAM)szText, lstrlen(szText), (rcText.right - rcText.left - sz.cx) / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), ctl->hThemeButton ? (rcText.bottom - rcText.top - sz.cy) / 2 : (rcText.bottom - rcText.top - sz.cy) / 2 - (ctl->stateId == PBS_PRESSED ? 0 : 1), sz.cx, sz.cy, IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED);
- SelectObject(hdcMem, hOldFont);
- }
- if (hbp)
- CMimAPI::m_pfnEndBufferedPaint(hbp, TRUE);
- else {
- BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY);
- SelectObject(hdcMem, hOld);
- DeleteObject(hbmMem);
- DeleteDC(hdcMem);
}
+ }
+ /*
+ * render content
+ */
+ if (ctl->arrow) {
+ rcContent.top += 2;
+ rcContent.bottom -= 2;
+ rcContent.left = rcClient.right - 12;
+ rcContent.right = rcContent.left;
+
+ DrawIconEx(hdcMem, rcClient.right - 15, (rcClient.bottom - rcClient.top) / 2 - (PluginConfig.m_smcyicon / 2),
+ PluginConfig.g_buttonBarIcons[ICON_DEFAULT_PULLDOWN], 16, 16, 0, 0, DI_NORMAL);
}
-}
-static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- MButtonCtrl* bct = (MButtonCtrl*)GetWindowLongPtr(hwndDlg, 0);
- switch (msg) {
- case WM_NCCREATE:
- SetWindowLongPtr(hwndDlg, GWL_STYLE, GetWindowLongPtr(hwndDlg, GWL_STYLE) | BS_OWNERDRAW);
- bct = (MButtonCtrl*)mir_alloc(sizeof(MButtonCtrl));
- if (bct == NULL)
- return FALSE;
- {
- char *p = (char*)bct ;
- _DebugTraceA("MButtonCtrl allocated: crashes at %lp", p + offsetof(MButtonCtrl, cHot));
- }
- ZeroMemory(bct, sizeof(MButtonCtrl));
- bct->hwnd = hwndDlg;
- bct->stateId = PBS_NORMAL;
- bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
- LoadTheme(bct);
- SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)bct);
- if (((CREATESTRUCT *)lParam)->lpszName)
- SetWindowText(hwndDlg, ((CREATESTRUCT *)lParam)->lpszName);
- return TRUE;
+ if (ctl->hIcon || ctl->hIconPrivate) {
+ int ix = (rcClient.right - rcClient.left) / 2 - 8;
+ int iy = (rcClient.bottom - rcClient.top) / 2 - 8;
+ HICON hIconNew = ctl->hIconPrivate != 0 ? ctl->hIconPrivate : ctl->hIcon;
- case WM_DESTROY:
- if (bct) {
- mir_cslock lck(csTips);
- if (hwndToolTips) {
- TOOLINFO ti = { sizeof(ti) };
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT_PTR)bct->hwnd;
- if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti))
- SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
-
- if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0) {
- DestroyWindow(hwndToolTips);
- hwndToolTips = NULL;
- }
- }
- if (bct->hIconPrivate)
- DestroyIcon(bct->hIconPrivate);
- DestroyTheme(bct);
+ if (ctl->stateId == PBS_PRESSED) {
+ ix++;
+ iy++;
}
- break; // DONT! fall thru
- case WM_NCDESTROY:
- mir_free(bct);
- SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)NULL);
- break;
+ if (ctl->arrow)
+ ix -= 4;
- case WM_SETTEXT:
- bct->cHot = 0;
- if ((TCHAR*)lParam) {
- TCHAR *tmp = (TCHAR*)lParam;
- while (*tmp) {
- if (*tmp == (TCHAR)'&' && *(tmp + 1)) {
- bct->cHot = _totlower(*(tmp + 1));
- break;
- }
- tmp++;
+ if (ctl->bDimmed && PluginConfig.m_IdleDetect)
+ CSkin::DrawDimmedIcon(hdcMem, ix, iy, PluginConfig.m_smcxicon, PluginConfig.m_smcyicon, hIconNew, 180);
+ else {
+ if (ctl->stateId != PBS_DISABLED || CMimAPI::m_MyAlphaBlend == 0) {
+ DrawIconEx(hdcMem, ix, iy, hIconNew, 16, 16, 0, 0, DI_NORMAL);
+ if (ctl->overlay)
+ DrawIconEx(hdcMem, ix, iy, ctl->overlay, 16, 16, 0, 0, DI_NORMAL);
}
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
-
- case WM_KEYUP:
- if (bct->stateId != PBS_DISABLED && wParam == VK_SPACE && !(GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_SHIFT) & 0x8000)) {
- if (bct->pushBtn) {
- if (bct->pbState) bct->pbState = 0;
- else bct->pbState = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
+ else {
+ BitBlt(hdc_buttonglyph, 0, 0, 16, 16, hdcMem, ix, iy, SRCCOPY);
+ DrawIconEx(hdc_buttonglyph, 0, 0, hIconNew, 16, 16, 0, 0, DI_NORMAL);
+ if (ctl->overlay)
+ DrawIconEx(hdc_buttonglyph, 0, 0, ctl->overlay, 16, 16, 0, 0, DI_NORMAL);
+ CMimAPI::m_MyAlphaBlend(hdcMem, ix, iy, PluginConfig.m_smcxicon, PluginConfig.m_smcyicon, hdc_buttonglyph, 0, 0, 16, 16, bf_buttonglyph);
}
- SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
- return 0;
}
- break;
+ }
+ else if (GetWindowTextLength(ctl->hwnd)) {
+ // Draw the text and optinally the arrow
+ RECT rcText;
+ CopyRect(&rcText, &rcClient);
+
+ TCHAR szText[MAX_PATH];
+ GetWindowText(ctl->hwnd, szText, MAX_PATH - 1);
+ SetBkMode(hdcMem, TRANSPARENT);
+ HFONT hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
+ if (ctl->pContainer && CSkin::m_skinEnabled)
+ SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd) ? CSkin::m_DefaultFontColor : GetSysColor(COLOR_GRAYTEXT));
+ else {
+ if (PluginConfig.m_genericTxtColor)
+ SetTextColor(hdcMem, PluginConfig.m_genericTxtColor);
+ else
+ SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_GRAYTEXT));
+ }
- case WM_SYSKEYUP:
- if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == tolower((int)wParam)) {
- if (bct->pushBtn) {
- if (bct->pbState) bct->pbState = 0;
- else bct->pbState = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
- return 0;
+ SIZE sz;
+ GetTextExtentPoint32(hdcMem, szText, lstrlen(szText), &sz);
+ if (ctl->cHot) {
+ SIZE szHot;
+ GetTextExtentPoint32A(hdcMem, "&", 1, &szHot);
+ sz.cx -= szHot.cx;
}
- break;
+ if (ctl->arrow)
+ DrawState(hdcMem, NULL, NULL, (LPARAM)ctl->arrow, 0, rcClient.right - rcClient.left - 5 - PluginConfig.m_smcxicon + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), (rcClient.bottom - rcClient.top) / 2 - PluginConfig.m_smcyicon / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), PluginConfig.m_smcxicon, PluginConfig.m_smcyicon, IsWindowEnabled(ctl->hwnd) ? DST_ICON : DST_ICON | DSS_DISABLED);
+ SelectObject(hdcMem, ctl->hFont);
+ DrawState(hdcMem, NULL, NULL, (LPARAM)szText, lstrlen(szText), (rcText.right - rcText.left - sz.cx) / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), ctl->hThemeButton ? (rcText.bottom - rcText.top - sz.cy) / 2 : (rcText.bottom - rcText.top - sz.cy) / 2 - (ctl->stateId == PBS_PRESSED ? 0 : 1), sz.cx, sz.cy, IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED);
+ SelectObject(hdcMem, hOldFont);
+ }
- case WM_THEMECHANGED: // themed changed, reload theme object
- if (bct->bThemed)
- LoadTheme(bct);
- InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
- break;
+ if (hbp)
+ CMimAPI::m_pfnEndBufferedPaint(hbp, TRUE);
+ else {
+ BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY);
+ SelectObject(hdcMem, hOld);
+ DeleteObject(hbmMem);
+ DeleteDC(hdcMem);
+ }
+}
- case WM_SETFONT: // remember the font so we can use it later
- bct->hFont = (HFONT)wParam; // maybe we should redraw?
+static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ TSButtonCtrl *bct = (TSButtonCtrl*)GetWindowLongPtr(hwndDlg, 0);
+ switch (msg) {
+ case WM_DESTROY:
+ if (bct)
+ if (bct->hIconPrivate)
+ DestroyIcon(bct->hIconPrivate);
break;
case WM_NCPAINT:
@@ -496,14 +356,14 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, BITMAP bm;
GetObject(ii.hbmColor, sizeof(bm), &bm);
if (bm.bmWidth != PluginConfig.m_smcxicon || bm.bmHeight != PluginConfig.m_smcyicon) {
- HIMAGELIST hImageList;
- hImageList = ImageList_Create(PluginConfig.m_smcxicon, PluginConfig.m_smcyicon, PluginConfig.m_bIsXP ? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0);
+ HIMAGELIST hImageList = ImageList_Create(PluginConfig.m_smcxicon, PluginConfig.m_smcyicon, PluginConfig.m_bIsXP ? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0);
ImageList_AddIcon(hImageList, (HICON)lParam);
bct->hIconPrivate = ImageList_GetIcon(hImageList, 0, ILD_NORMAL);
ImageList_RemoveAll(hImageList);
ImageList_Destroy(hImageList);
bct->hIcon = 0;
- } else {
+ }
+ else {
bct->hIcon = (HICON)lParam;
bct->hIconPrivate = 0;
}
@@ -520,53 +380,15 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, bct->hIcon = bct->hIconPrivate = NULL;
InvalidateRect(bct->hwnd, NULL, TRUE);
}
- break;
-
- case BM_SETCHECK:
- if (!bct->pushBtn) break;
- if (wParam == BST_CHECKED) {
- bct->pbState = 1;
- bct->stateId = PBS_PRESSED;
- }
- else if (wParam == BST_UNCHECKED) {
- bct->pbState = 0;
- bct->stateId = PBS_NORMAL;
- }
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
-
- case BM_GETCHECK:
- if (bct->pushBtn)
- return bct->pbState ? BST_CHECKED : BST_UNCHECKED;
-
return 0;
case BUTTONSETARROW: // turn arrow on/off
bct->arrow = (HICON)wParam;
InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
-
- case BUTTONSETDEFAULT:
- bct->defbutton = (wParam != 0);
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
-
- case BUTTONSETASPUSHBTN:
- bct->pushBtn = (wParam != 0);
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
-
- case BUTTONSETASFLATBTN:
- bct->flatBtn = (wParam != 0);
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
-
- case BUTTONSETASTHEMEDBTN:
- bct->bThemed = (wParam != 0);
- break;
+ return 0;
case BUTTONSETASDIMMED:
- bct->dimmed = (wParam != 0);
+ bct->bDimmed = (wParam != 0);
break;
case BUTTONSETCONTAINER:
@@ -586,7 +408,7 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, return bct->stateId;
case BUTTONSETASTOOLBARBUTTON:
- bct->bToolbarButton = wParam;
+ bct->bToolbarButton = (wParam != 0);
break;
case BUTTONSETASSIDEBARBUTTON:
@@ -597,49 +419,6 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, bct->overlay = (HICON)wParam;
break;
- case BUTTONADDTOOLTIP:
- if (wParam) {
- mir_cslock lck(csTips);
- if (!hwndToolTips)
- hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
-
- TOOLINFO ti = { sizeof(ti) };
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT_PTR)bct->hwnd;
- if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti))
- SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
-
- ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
- ti.uId = (UINT_PTR)bct->hwnd;
- ti.lpszText = (TCHAR*)wParam;
- SendMessage(hwndToolTips, TTM_ADDTOOL, 0, (LPARAM)&ti);
- SendMessage(hwndToolTips, TTM_SETMAXTIPWIDTH, 0, 300);
- }
- break;
-
- case WM_SETFOCUS: // set keybord focus and redraw
- bct->focus = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
-
- case WM_KILLFOCUS: // kill focus and redraw
- bct->focus = 0;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
-
- case WM_ENABLE: // windows tells us to enable/disable
- bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
-
- case WM_MOUSELEAVE: // faked by the WM_TIMER
- if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
- bct->stateId = PBS_NORMAL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
-
case WM_CONTEXTMENU:
if (bct->sitem)
bct->sitem->invokeContextMenu();
@@ -672,49 +451,23 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, }
}
InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- else if (bct->stateId != PBS_DISABLED) {
- bct->stateId = PBS_PRESSED;
- InvalidateRect(bct->hwnd, NULL, TRUE);
+ return 0;
}
break;
- case WM_LBUTTONUP: {
- int showClick = 0;
-
+ case WM_LBUTTONUP:
if (bct->sitem) {
if (bct->sitem->testCloseButton() != -1) {
SendMessage(bct->sitem->getDat()->hwnd, WM_CLOSE, 1, 0);
return TRUE;
}
}
- if (bct->pushBtn) {
- if (bct->pbState) bct->pbState = 0;
- else bct->pbState = 1;
- }
- if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
- if (bct->stateId == PBS_PRESSED)
- showClick = 1;
- if (msg == WM_LBUTTONUP)
- bct->stateId = PBS_HOT;
- else
- bct->stateId = PBS_NORMAL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- if (showClick)
- SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
break;
- }
+
case WM_MOUSEMOVE:
- if (bct->stateId == PBS_NORMAL) {
- bct->stateId = PBS_HOT;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- else if (bct->arrow && bct->stateId == PBS_HOT)
+ if (bct->arrow && bct->stateId == PBS_HOT)
InvalidateRect(bct->hwnd, NULL, TRUE);
- // Call timer, used to start cheesy TrackMouseEvent faker
- SetTimer(hwndDlg, BUTTON_POLLID, BUTTON_POLLDELAY, NULL);
if (bct->sitem) {
if (bct->sitem->testCloseButton() != -1) {
if (bct->sitem->m_sideBar->getHoveredClose() != bct->sitem) {
@@ -728,6 +481,7 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, }
}
break;
+
case WM_TIMER: // use a timer to check if they have did a mouseout
if (wParam == BUTTON_POLLID) {
RECT rc;
@@ -743,10 +497,25 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, }
}
}
- break;
+ return 0;
+ }
- case WM_ERASEBKGND:
- return 1;
+ return mir_callNextSubclass(hwndDlg, TSButtonWndProc, msg, wParam, lParam);
+}
+
+int TSAPI UnloadTSButtonModule()
+{
+ if (hdc_buttonglyph) {
+ SelectObject(hdc_buttonglyph, hbm_buttonglyph_old);
+ DeleteObject(hbm_buttonglyph);
+ DeleteDC(hdc_buttonglyph);
}
- return DefWindowProc(hwndDlg, msg, wParam, lParam);
+ return 0;
+}
+
+void CustomizeButton(HWND hwndButton)
+{
+ SendMessage(hwndButton, BUTTONSETCUSTOMPAINT, sizeof(TSButtonCtrl), 0);
+
+ mir_subclassWindow(hwndButton, TSButtonWndProc);
}
|