From 6d10b27399e46e952ded3d5a8bc4645ccffb2c34 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 9 Jul 2012 09:02:16 +0000 Subject: - customizeable TopToolbar - restored Clist Modern toolbar painter git-svn-id: http://svn.miranda-ng.org/main/trunk@876 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Clist_modern/modern_cluiframes.cpp | 2 - plugins/Clist_modern/modern_tbbutton.cpp | 44 +++--- plugins/Clist_modern/modern_toolbar.cpp | 183 ++++++++++++++++++++++- plugins/ExternalAPI/m_toptoolbar.h | 46 ++++++ plugins/TopToolBar/common.h | 8 +- plugins/TopToolBar/toolbar.cpp | 231 +++++++++++++++-------------- plugins/TopToolBar/topbutton.cpp | 23 +-- plugins/TopToolBar/ttbopt.cpp | 20 +-- 8 files changed, 396 insertions(+), 161 deletions(-) (limited to 'plugins') diff --git a/plugins/Clist_modern/modern_cluiframes.cpp b/plugins/Clist_modern/modern_cluiframes.cpp index 2df4d35889..5af86e7bde 100644 --- a/plugins/Clist_modern/modern_cluiframes.cpp +++ b/plugins/Clist_modern/modern_cluiframes.cpp @@ -2675,8 +2675,6 @@ int CLUIFramesOnClistResize(WPARAM wParam,LPARAM lParam) } GetWindowRect(pcli->hwndContactList,&mainRect); mainHeight = mainRect.bottom-mainRect.top; - //if (mainHeight < minHeight) - // DebugBreak(); } GetClientRect(pcli->hwndContactList,&nRect); //$$$ Fixed borders diff --git a/plugins/Clist_modern/modern_tbbutton.cpp b/plugins/Clist_modern/modern_tbbutton.cpp index fc17b0921f..dadf53637a 100644 --- a/plugins/Clist_modern/modern_tbbutton.cpp +++ b/plugins/Clist_modern/modern_tbbutton.cpp @@ -15,7 +15,6 @@ #define b2str(a) ((a) ? "True" : "False") void CustomizeToolbar(HWND); -int Modern_InitButtons(WPARAM, LPARAM); struct TBBUTTONDATA : public MButtonCtrl { @@ -77,27 +76,24 @@ static int TBStateConvert2Flat(int state) return TS_NORMAL; } -static void PaintWorker(TBBUTTONDATA *lpSBData, HDC hdcPaint , POINT * pOffset) +static void PaintWorker(TBBUTTONDATA *lpSBData, HDC hdcPaint , POINT *pOffset) { - HDC hdcMem; - HBITMAP hbmMem; - RECT rcClient; - int width; - int height; - HBITMAP hbmOld = NULL; - HFONT hOldFont = NULL; - BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; POINT offset = {0}; - if (pOffset) offset = *pOffset; + if (pOffset) + offset = *pOffset; - if ( !hdcPaint) return; //early exit + if ( !hdcPaint) + return; //early exit + RECT rcClient; GetClientRect(lpSBData->hwnd, &rcClient); - width = rcClient.right - rcClient.left; - height = rcClient.bottom - rcClient.top; + int width = rcClient.right - rcClient.left; + int height = rcClient.bottom - rcClient.top; - hdcMem = pOffset?hdcPaint:CreateCompatibleDC(hdcPaint); - hOldFont = (HFONT)SelectObject(hdcMem, lpSBData->hFont); + HBITMAP hbmMem; + HBITMAP hbmOld = NULL; + HDC hdcMem = pOffset ? hdcPaint : CreateCompatibleDC(hdcPaint); + HFONT hOldFont = (HFONT)SelectObject(hdcMem, lpSBData->hFont); if ( !pOffset) { hbmMem = ske_CreateDIB32(width, height); hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMem); @@ -107,7 +103,7 @@ static void PaintWorker(TBBUTTONDATA *lpSBData, HDC hdcPaint , POINT * pOffset) if ( !g_CluiData.fDisableSkinEngine) { char szRequest[128]; /* painting */ - mir_snprintf(szRequest,SIZEOF(szRequest),"Button,ID = %s,Hovered = %s,Pressed = %s,Focused = %s", + mir_snprintf(szRequest,SIZEOF(szRequest),"Button,ID=%s,Hovered=%s,Pressed=%s,Focused=%s", lpSBData->szButtonID, // ID b2str(lpSBData->stateId == PBS_HOT), // Hovered b2str(lpSBData->stateId == PBS_PRESSED || lpSBData->bIsPushed == TRUE), // Pressed @@ -312,21 +308,17 @@ static LRESULT CALLBACK ToolbarButtonProc(HWND hwndDlg, UINT msg, WPARAM wParam RECT rcClient; GetClientRect( lpSBData->hwnd, &rcClient ); - - if ( !PtInRect( &rcClient, ptMouse )) - { + if ( !PtInRect( &rcClient, ptMouse )) { lpSBData->fHotMark = FALSE; ReleaseCapture(); break; } - if (lpSBData->stateId != PBS_DISABLED && lpSBData->stateId != PBS_PRESSED) - { + if (lpSBData->stateId != PBS_DISABLED && lpSBData->stateId != PBS_PRESSED) { lpSBData->stateId = PBS_PRESSED; lpSBData->fHotMark = TRUE; InvalidateParentRect(lpSBData->hwnd, NULL, TRUE); - if (lpSBData->fSendOnDown) - { + if (lpSBData->fSendOnDown) { SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg); lpSBData->stateId = PBS_NORMAL; InvalidateParentRect(lpSBData->hwnd, NULL, TRUE); @@ -510,7 +502,7 @@ static LRESULT CALLBACK ToolbarButtonProc(HWND hwndDlg, UINT msg, WPARAM wParam static void CustomizeButton(HANDLE ttbid, HWND hWnd, LPARAM lParam) { if (ttbid == (HANDLE)-1) { - //CustomizeToolbar(hWnd); + CustomizeToolbar(hWnd); return; } @@ -521,6 +513,7 @@ static void CustomizeButton(HANDLE ttbid, HWND hWnd, LPARAM lParam) SendMessage(hWnd, BUTTONSETCUSTOM, 0, (LPARAM)&Custom); TBBUTTONDATA* p = (TBBUTTONDATA*)GetWindowLongPtr(hWnd, 0); + sprintf(p->szButtonID, "Toolbar.%p", p->hwnd); p->nFontID = -1; p->hThemeButton = xpt_AddThemeHandle(p->hwnd, L"BUTTON"); p->hThemeToolbar = xpt_AddThemeHandle(p->hwnd, L"TOOLBAR"); @@ -531,7 +524,6 @@ static void CustomizeButton(HANDLE ttbid, HWND hWnd, LPARAM lParam) int Buttons_ModuleLoaded(WPARAM wParam, LPARAM lParam) { - HookEvent(ME_TTB_INITBUTTONS, Modern_InitButtons); TopToolbar_SetCustomProc(CustomizeButton, 0); return 0; } diff --git a/plugins/Clist_modern/modern_toolbar.cpp b/plugins/Clist_modern/modern_toolbar.cpp index 59f30db249..606dc1122a 100644 --- a/plugins/Clist_modern/modern_toolbar.cpp +++ b/plugins/Clist_modern/modern_toolbar.cpp @@ -49,7 +49,7 @@ static BTNS[] = { "Minimize","Minimize", "CList/ShowHide", "Minimize", NULL, 180 , IDI_RESETVIEW, IDI_RESETVIEW, FALSE } }; -int Modern_InitButtons(WPARAM, LPARAM) +static int Modern_InitButtons(WPARAM, LPARAM) { TTBButton tbb = { 0 }; tbb.cbSize = sizeof(tbb); @@ -81,6 +81,186 @@ int Modern_InitButtons(WPARAM, LPARAM) /////////////////////////////////////////////////////////////////////////////// +#define MTBM_LAYEREDPAINT (WM_USER+20) + +struct ModernToolbarCtrl : public TTBCtrl +{ + XPTHANDLE mtbXPTheme; + BOOL fAutoSize; + int nLineCount; + WORD wLastHeight; + BOOL fSingleLine; +}; + +struct MTB_BUTTONINFO +{ + HWND hWindow; +}; + +struct +{ + HBITMAP mtb_hBmpBackground; + COLORREF mtb_bkColour; + WORD mtb_backgroundBmpUse; + BOOL mtb_useWinColors; +} +static tbdat = { 0 }; + +COLORREF sttGetColor(char * module, char * color, COLORREF defColor); + +static int ehhToolBarBackgroundSettingsChanged(WPARAM wParam, LPARAM lParam) +{ + if ( tbdat.mtb_hBmpBackground) { + DeleteObject(tbdat.mtb_hBmpBackground); + tbdat.mtb_hBmpBackground = NULL; + } + if (g_CluiData.fDisableSkinEngine) { + DBVARIANT dbv; + tbdat.mtb_bkColour = sttGetColor("ToolBar","BkColour",CLCDEFAULT_BKCOLOUR); + if ( db_get_b(NULL,"ToolBar","UseBitmap",CLCDEFAULT_USEBITMAP)) { + if ( !db_get_s(NULL, "ToolBar", "BkBitmap", &dbv, DBVT_TCHAR)) { + tbdat.mtb_hBmpBackground = (HBITMAP)CallService(MS_UTILS_LOADBITMAP,0,(LPARAM)dbv.ptszVal); + db_free(&dbv); + } + } + tbdat.mtb_useWinColors = db_get_b(NULL, "ToolBar", "UseWinColours", CLCDEFAULT_USEWINDOWSCOLOURS); + tbdat.mtb_backgroundBmpUse = db_get_b(NULL, "ToolBar", "BkBmpUse", CLCDEFAULT_BKBMPUSE); + } + PostMessage(pcli->hwndContactList,WM_SIZE,0,0); + return 0; +} + +static BOOL sttDrawToolBarBackground(HWND hwnd, HDC hdc, RECT * rect, ModernToolbarCtrl* pMTBInfo) +{ + BOOL bFloat = (GetParent(hwnd)!=pcli->hwndContactList); + if (g_CluiData.fDisableSkinEngine || !g_CluiData.fLayered || bFloat) + { + RECT rc; + HBRUSH hbr; + + if (rect) + rc=*rect; + else + GetClientRect(hwnd,&rc); + + if ( !(tbdat.mtb_backgroundBmpUse && tbdat.mtb_hBmpBackground) && tbdat.mtb_useWinColors) + { + if (xpt_IsThemed(pMTBInfo->mtbXPTheme)) + xpt_DrawTheme(pMTBInfo->mtbXPTheme,pMTBInfo->hWnd, hdc, 0, 0, &rc, &rc); + else { + hbr = GetSysColorBrush(COLOR_3DFACE); + FillRect(hdc, &rc, hbr); + } + } + else if (!tbdat.mtb_hBmpBackground && !tbdat.mtb_useWinColors) + { + hbr = CreateSolidBrush(tbdat.mtb_bkColour); + FillRect(hdc, &rc, hbr); + DeleteObject(hbr); + } + else DrawBackGround(hwnd, hdc, tbdat.mtb_hBmpBackground, tbdat.mtb_bkColour, tbdat.mtb_backgroundBmpUse); + } + return TRUE; +} + +static void sttDrawNonLayeredSkinedBar(HWND hwnd, HDC hdc) +{ + RECT rc = {0}; + GetClientRect(hwnd, &rc); + rc.right++; + rc.bottom++; + HDC hdc2 = CreateCompatibleDC(hdc); + HBITMAP hbmp = ske_CreateDIB32(rc.right, rc.bottom); + HBITMAP hbmpo = (HBITMAP)SelectObject(hdc2, hbmp); + if (GetParent(hwnd) != pcli->hwndContactList) { + HBRUSH br = GetSysColorBrush(COLOR_3DFACE); + FillRect(hdc2, &rc, br); + } + else ske_BltBackImage(hwnd, hdc2, &rc); + + SendMessage(hwnd, MTBM_LAYEREDPAINT, (WPARAM)hdc2, 0); + BitBlt(hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc2, rc.left, rc.top, SRCCOPY); + SelectObject(hdc2, hbmpo); + DeleteObject(hbmp); + mod_DeleteDC(hdc2); + + SelectObject(hdc, (HFONT)GetStockObject(DEFAULT_GUI_FONT)); + ValidateRect(hwnd, NULL); +} + +static LRESULT CALLBACK toolbarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + ModernToolbarCtrl* pMTBInfo = (ModernToolbarCtrl*)GetWindowLongPtr(hwnd, 0); + + switch( msg ) { + case WM_ERASEBKGND: + pMTBInfo->lResult = (g_CluiData.fDisableSkinEngine) ? sttDrawToolBarBackground(hwnd, (HDC)wParam, NULL, pMTBInfo) : 0; + return 1; + + case WM_NCPAINT: + case WM_PAINT: + { + PAINTSTRUCT ps; + BOOL bFloat = (GetParent(hwnd) != pcli->hwndContactList); + if (g_CluiData.fDisableSkinEngine|| !g_CluiData.fLayered || bFloat ) { + BeginPaint(hwnd,&ps); + if ((!g_CluiData.fLayered || bFloat) && !g_CluiData.fDisableSkinEngine) + sttDrawNonLayeredSkinedBar(hwnd, ps.hdc); + else + sttDrawToolBarBackground(hwnd, ps.hdc, &ps.rcPaint, pMTBInfo); + EndPaint(hwnd,&ps); + } + } + pMTBInfo->lResult = DefWindowProc(hwnd, msg, wParam, lParam); + return 1; + + case MTBM_LAYEREDPAINT: + { + int i; + RECT MyRect={0}; + HDC hDC=(HDC)wParam; + GetWindowRect(hwnd,&MyRect); + + RECT rcClient; + GetClientRect(hwnd, &rcClient); + SkinDrawGlyph(hDC, &rcClient, &rcClient, "Bar,ID=ToolBar,Part=Background"); + + for (i=0; i < pMTBInfo->pButtonList->realCount; i++) { + RECT childRect; + POINT Offset; + TTBCtrlButton* mtbi = (TTBCtrlButton*)pMTBInfo->pButtonList->items[i]; + GetWindowRect(mtbi->hWindow, &childRect); + Offset.x = childRect.left - MyRect.left;; + Offset.y = childRect.top - MyRect.top; + SendMessage(mtbi->hWindow, BUTTONDRAWINPARENT, (WPARAM)hDC, (LPARAM)&Offset); + } + return 1; + } + } + + return 0; +} + +void CustomizeToolbar(HWND hwnd) +{ + TTBCtrlCustomize custData = { sizeof(ModernToolbarCtrl), toolbarWndProc, NULL }; + SendMessage(hwnd, TTB_SETCUSTOM, 0, (LPARAM)&custData); + + ModernToolbarCtrl* pMTBInfo = (ModernToolbarCtrl*)GetWindowLongPtr(hwnd, 0); + pMTBInfo->nLineCount = 1; + pMTBInfo->mtbXPTheme = xpt_AddThemeHandle(hwnd, L"TOOLBAR"); +} + +static int Toolbar_ModulesLoaded(WPARAM, LPARAM) +{ + CallService(MS_BACKGROUNDCONFIG_REGISTER, (WPARAM)"ToolBar Background/ToolBar",0); + HookEvent(ME_BACKGROUNDCONFIG_CHANGED, ehhToolBarBackgroundSettingsChanged); + HookEvent(ME_TTB_INITBUTTONS, Modern_InitButtons); + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// + #define TTB_OPTDIR "TopToolBar" #if defined(WIN64) @@ -113,5 +293,6 @@ HRESULT ToolbarLoadModule() CallService(MS_UTILS_OPENURL, 0, (LPARAM)szUrl); } + HookEvent(ME_SYSTEM_MODULESLOADED, Toolbar_ModulesLoaded); return S_OK; } diff --git a/plugins/ExternalAPI/m_toptoolbar.h b/plugins/ExternalAPI/m_toptoolbar.h index 5ef3a20352..ed79f8818e 100644 --- a/plugins/ExternalAPI/m_toptoolbar.h +++ b/plugins/ExternalAPI/m_toptoolbar.h @@ -134,10 +134,56 @@ returns: always returns 0. #define TTB_WINDOW_HANDLE ((HANDLE)-1) +// this procedure is executed on each button on toolbar +// and on a toolbar itself with hTTButton == TTB_WINDOW_HANDLE +// hTTButton = button handle +// hwndBtn = button window handle +// userInfo = lParam passed into TopToolbar_SetCustomProc + typedef void (__cdecl *pfnCustomProc)(HANDLE hTTButton, HWND hwndBtn, LPARAM userInfo); __forceinline void TopToolbar_SetCustomProc(pfnCustomProc pFunc, LPARAM lParam) { CallService("TopToolBar/SetCustomProc", (WPARAM)pFunc, lParam); } +/////////////////////////////////////////////////////////////////////////////// +// Toolbar internal structures + +typedef void (__cdecl *pfnTTBPainterFunc)(struct TTBCtrl*, HDC); + +struct TTBCtrlButton +{ + HWND hWindow; +}; + +struct TTBCtrl +{ + HWND hWnd; + HANDLE hFrame; + int nButtonWidth; + int nButtonHeight; + int nButtonSpace; + BOOL bFlatButtons; + + SortedList* pButtonList; + + LRESULT lResult; // custom window proc result + WNDPROC fnWindowProc; // custom window proc + pfnTTBPainterFunc fnPainter; // custom button painter +}; + +struct TTBCtrlCustomize +{ + size_t cbLen; // total length of the internal data structure + WNDPROC fnWindowProc; // subclassed windows procedure for the custom button + pfnTTBPainterFunc fnPainter; // custom button painter +}; + +// Sets the custom painting procedure for a toolbar +// wParam = not used +// lParam = TTBCtrlCustomize* +// Usage: SendMessage(hwndToolbar, TTB_SETCUSTOM, 0, (LPARAM)&CustomData); +// Only works on TopToolbars +#define TTB_SETCUSTOM (WM_USER+1) + #endif diff --git a/plugins/TopToolBar/common.h b/plugins/TopToolBar/common.h index 1e14548c0e..82060ac458 100644 --- a/plugins/TopToolBar/common.h +++ b/plugins/TopToolBar/common.h @@ -101,13 +101,15 @@ int ArrangeButtons(); #define SEPWIDTH 3 +extern TTBCtrl* g_ctrl; + extern LIST Buttons; -extern bool StopArrange; -extern HWND hwndTopToolBar; +extern bool bStopArrange; extern HINSTANCE hInst; extern HBITMAP hBmpBackground, hBmpSeparator; -extern int BUTTWIDTH, BUTTHEIGHT, BUTTGAP; extern CRITICAL_SECTION csButtonsHook; +extern pfnCustomProc g_CustomProc; +extern LPARAM g_CustomProcParam; void AddToOptions(TopButtonInt* b); void RemoveFromOptions(int id); diff --git a/plugins/TopToolBar/toolbar.cpp b/plugins/TopToolBar/toolbar.cpp index e51d99f259..28a197fd56 100644 --- a/plugins/TopToolBar/toolbar.cpp +++ b/plugins/TopToolBar/toolbar.cpp @@ -5,18 +5,15 @@ pfnCustomProc g_CustomProc = NULL; LPARAM g_CustomProcParam = 0; +TTBCtrl *g_ctrl = NULL; HWND hwndContactList = 0; -HWND hwndTopToolBar = 0; -bool StopArrange; - -int BUTTWIDTH; -int BUTTHEIGHT; -int BUTTGAP; +bool bStopArrange, bEventFired = false; int nextButtonId = 200; static HANDLE hTTBModuleLoaded, hTTBInitButtons; +static TCHAR pluginname[] = _T("TopToolBar"); //------------ options ------------- COLORREF bkColour; @@ -24,7 +21,6 @@ HBITMAP hBmpBackground, hBmpSeparator; int backgroundBmpUse; CRITICAL_SECTION csButtonsHook; -static int hFrameTopWindow = -1; int sortfunc(const TopButtonInt* a, const TopButtonInt* b) { @@ -161,9 +157,9 @@ int ttbOptionsChanged() backgroundBmpUse = DBGetContactSettingWord(NULL, TTB_OPTDIR, "BkBmpUse", TTBDEFAULT_BKBMPUSE); RECT rc; - GetClientRect(hwndTopToolBar, &rc); - InvalidateRect(hwndTopToolBar, &rc, TRUE); - UpdateWindow(hwndTopToolBar); + GetClientRect(g_ctrl->hWnd, &rc); + InvalidateRect(g_ctrl->hWnd, &rc, TRUE); + UpdateWindow(g_ctrl->hWnd); return 0; } @@ -299,12 +295,6 @@ INT_PTR TTBAddButton(WPARAM wParam, LPARAM lParam) if (wParam == 0) return -1; - if (hwndContactList == 0) - hwndContactList = (HWND)CallService(MS_CLUI_GETHWND, 0, 0); - //oops clui even now not loaded...sorry no buttons available - if (hwndContactList == 0) - return -1; - TopButtonInt* b; { mir_cslock lck(csButtonsHook); @@ -329,23 +319,23 @@ INT_PTR TTBAddButton(WPARAM wParam, LPARAM lParam) int ArrangeButtons() { - if (StopArrange == TRUE) + if (bStopArrange == TRUE) return 0; mir_cslock lck(csButtonsHook); RECT winrc; - GetClientRect(hwndTopToolBar, &winrc); + GetClientRect(g_ctrl->hWnd, &winrc); winrc.left = winrc.right-winrc.left; if (winrc.left == 0) return 0; int newheight; - StopArrange = true; + bStopArrange = true; int ypos = 1; - int xpos = BUTTGAP; - newheight = BUTTHEIGHT+1; - CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT, hFrameTopWindow), BUTTHEIGHT+2); + int xpos = g_ctrl->nButtonSpace; + newheight = g_ctrl->nButtonHeight+1; + CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT, g_ctrl->hFrame), g_ctrl->nButtonHeight+2); int uFlags; @@ -364,20 +354,20 @@ int ArrangeButtons() uFlags = SWP_NOZORDER | SWP_SHOWWINDOW; // check, if need to move to next line - if (xpos+BUTTWIDTH+BUTTGAP > winrc.left) { - xpos = BUTTGAP; - ypos += BUTTHEIGHT+2; - newheight = ypos+BUTTHEIGHT+1; - CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT, hFrameTopWindow), newheight); + if (xpos+g_ctrl->nButtonWidth+g_ctrl->nButtonSpace > winrc.left) { + xpos = g_ctrl->nButtonSpace; + ypos += g_ctrl->nButtonHeight+2; + newheight = ypos+g_ctrl->nButtonHeight+1; + CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT, g_ctrl->hFrame), newheight); } - SetWindowPos(b->hwnd, 0, xpos, ypos, BUTTWIDTH, BUTTHEIGHT, uFlags); + SetWindowPos(b->hwnd, 0, xpos, ypos, g_ctrl->nButtonWidth, g_ctrl->nButtonHeight, uFlags); InvalidateRect(b->hwnd, NULL, TRUE); - xpos += (b->isSep()) ? SEPWIDTH+2 : BUTTWIDTH+BUTTGAP; + xpos += (b->isSep()) ? SEPWIDTH+2 : g_ctrl->nButtonWidth+g_ctrl->nButtonSpace; } - StopArrange = false; + bStopArrange = false; return 1; } @@ -564,17 +554,12 @@ INT_PTR TTBSetOptions(WPARAM wParam, LPARAM lParam) ///////////////////////////////////////////////////////////////////////////////////////// // Toolbar window procedure -static void PaintToolbar(HWND hwnd) +static void PaintToolbar(TTBCtrl *ttb, HDC hdc) { - InvalidateRect(hwnd, 0, FALSE); - - PAINTSTRUCT paintst; - HDC hdc = BeginPaint(hwnd, &paintst); - RECT *rcPaint = &paintst.rcPaint; + InvalidateRect(ttb->hWnd, 0, FALSE); RECT clRect; - GetClientRect(hwnd, &clRect); - if (rcPaint == NULL) rcPaint = &clRect; + GetClientRect(ttb->hWnd, &clRect); int yScroll = 0; int y = -yScroll; @@ -588,7 +573,7 @@ static void PaintToolbar(HWND hwnd) hBrush = CreateSolidBrush(bkColour); hoBrush = (HBRUSH)SelectObject(hdcMem, hBrush); - FillRect(hdcMem, rcPaint, hBrush); + FillRect(hdcMem, &clRect, hBrush); SelectObject(hdcMem, hoBrush); DeleteObject(hBrush); if (hBmpBackground) { @@ -603,7 +588,7 @@ static void PaintToolbar(HWND hwnd) SelectObject(hdcBmp, hBmpBackground); y = backgroundBmpUse & CLBF_SCROLL ? -yScroll : 0; maxx = backgroundBmpUse & CLBF_TILEH ? clRect.right : 1; - maxy = backgroundBmpUse & CLBF_TILEV ? maxy = rcPaint->bottom : y+1; + maxy = backgroundBmpUse & CLBF_TILEV ? maxy = clRect.bottom : y+1; switch(backgroundBmpUse & CLBM_TYPE) { case CLB_STRETCH: if (backgroundBmpUse&CLBF_PROPORTIONAL) { @@ -626,7 +611,7 @@ static void PaintToolbar(HWND hwnd) destw = clRect.right; desth = destw*bmp.bmHeight/bmp.bmWidth; if (backgroundBmpUse & CLBF_TILEVTOROWHEIGHT) - desth = BUTTHEIGHT+2; + desth = g_ctrl->nButtonHeight+2; } else { destw = clRect.right; @@ -647,30 +632,32 @@ static void PaintToolbar(HWND hwnd) destw = bmp.bmWidth; desth = bmp.bmHeight; if (backgroundBmpUse&CLBF_TILEVTOROWHEIGHT) - desth = BUTTHEIGHT+2; + desth = g_ctrl->nButtonHeight+2; break; } for (; y < maxy; y += desth) { - if (y < rcPaint->top - desth) continue; + if (y < clRect.top - desth) continue; for (x = 0; x < maxx; x += destw) StretchBlt(hdcMem, x, y, destw, desth, hdcBmp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); } DeleteDC(hdcBmp); } - BitBlt(hdc, rcPaint->left, rcPaint->top, rcPaint->right-rcPaint->left, rcPaint->bottom-rcPaint->top, hdcMem, rcPaint->left, rcPaint->top, SRCCOPY); + BitBlt(hdc, clRect.left, clRect.top, clRect.right-clRect.left, clRect.bottom-clRect.top, hdcMem, clRect.left, clRect.top, SRCCOPY); SelectObject(hdcMem, hOldBmp); DeleteDC(hdcMem); DeleteObject(hBmpOsb); - paintst.fErase = FALSE; - EndPaint(hwnd, &paintst); } LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { + if (g_ctrl->fnWindowProc != NULL) + if ( g_ctrl->fnWindowProc(hwnd, msg, wParam, lParam)) + return g_ctrl->lResult; + switch(msg) { case WM_CREATE: - hwndTopToolBar = hwnd; + g_ctrl->hWnd = hwnd; return FALSE; case WM_MOVE: @@ -682,7 +669,14 @@ LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara return 0; case WM_PAINT: - PaintToolbar(hwnd); + { + PAINTSTRUCT ps; + HDC hdcPaint = BeginPaint(hwnd, &ps); + if (hdcPaint) { + g_ctrl->fnPainter(g_ctrl, hdcPaint); + EndPaint(hwnd, &ps); + } + } return 0; case WM_LBUTTONDOWN: @@ -697,35 +691,56 @@ LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara return 0; case WM_COMMAND: - if ((HIWORD(wParam) == STN_CLICKED || HIWORD(wParam) == STN_DBLCLK)) { - int id = GetWindowLongPtr((HWND)lParam, GWLP_USERDATA); - if (id != 0) { - mir_cslock lck(csButtonsHook); - TopButtonInt* b = idtopos(id); - if (b == NULL || b->isSep()) - return 0; - - // flag inversion inside condition coz we uses Up -> Down for non-push buttons - // condition and inversion can be moved to main condition end - if (b->bPushed) { //Dn -> Up - - if (b->dwFlags & TTBBF_ASPUSHBUTTON) - b->bPushed = !b->bPushed; - - if (!(b->dwFlags & TTBBF_ISLBUTTON)) // must be always true + switch (HIWORD(wParam)) { + case STN_CLICKED: + case STN_DBLCLK: + { + int id = GetWindowLongPtr((HWND)lParam, GWLP_USERDATA); + if (id != 0) { + mir_cslock lck(csButtonsHook); + TopButtonInt* b = idtopos(id); + if (b == NULL || b->isSep()) + return 0; + + // flag inversion inside condition coz we uses Up -> Down for non-push buttons + // condition and inversion can be moved to main condition end + if (b->bPushed) { //Dn -> Up + + if (b->dwFlags & TTBBF_ASPUSHBUTTON) + b->bPushed = !b->bPushed; + + if (!(b->dwFlags & TTBBF_ISLBUTTON)) // must be always true + if (b->pszService != NULL) + CallService(b->pszService, b->wParamUp, b->lParamUp); + } + else { //Up -> Dn + if (b->dwFlags & TTBBF_ASPUSHBUTTON) + b->bPushed = !b->bPushed; + if (b->pszService != NULL) - CallService(b->pszService, b->wParamUp, b->lParamUp); - } - else { //Up -> Dn - if (b->dwFlags & TTBBF_ASPUSHBUTTON) - b->bPushed = !b->bPushed; + CallService(b->pszService, b->wParamDown, b->lParamDown); + } - if (b->pszService != NULL) - CallService(b->pszService, b->wParamDown, b->lParamDown); + b->SetBitmap(); } - - b->SetBitmap(); } + break; + } + break; + + case TTB_SETCUSTOM: + { + TTBCtrlCustomize *pCustom = (TTBCtrlCustomize*)lParam; + if (pCustom == NULL || g_ctrl->fnWindowProc) + break; + + g_ctrl = (TTBCtrl*)mir_realloc(g_ctrl, pCustom->cbLen); + if (pCustom->cbLen > sizeof(TTBCtrl)) + memset(g_ctrl+1, 0, pCustom->cbLen - sizeof(TTBCtrl)); + if (pCustom->fnPainter) + g_ctrl->fnPainter = pCustom->fnPainter; + g_ctrl->fnWindowProc = pCustom->fnWindowProc; + SetWindowLongPtr(hwnd, 0, (LONG_PTR)g_ctrl); } break; @@ -735,10 +750,15 @@ LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara return(TRUE); } -static TCHAR pluginname[] = _T("TopToolBar"); - -int addTopToolBarWindow(HWND parent) +static INT_PTR OnEventFire(WPARAM wParam, LPARAM lParam) { + CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0); + bStopArrange = FALSE; + + HWND parent = (HWND)CallService(MS_CLUI_GETHWND, 0, 0); + if (parent == NULL) // no clist, no buttons + return -1; + WNDCLASS wndclass = { 0 }; wndclass.lpfnWndProc = TopToolBarProc; wndclass.cbWndExtra = sizeof(void*); @@ -748,39 +768,33 @@ int addTopToolBarWindow(HWND parent) wndclass.lpszClassName = pluginname; RegisterClass(&wndclass); - HWND pluginwind = CreateWindow(pluginname, pluginname, + g_ctrl->pButtonList = (SortedList*)&Buttons; + g_ctrl->fnPainter = PaintToolbar; + g_ctrl->hWnd = CreateWindow(pluginname, pluginname, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 0, 0, parent, NULL, hInst, NULL); + SetWindowLongPtr(g_ctrl->hWnd, 0, (LPARAM)g_ctrl); + + ttbOptionsChanged(); + + // if we're working in skinned clist, receive the standard buttons & customizations + NotifyEventHooks(hTTBInitButtons, 0, 0); + if (g_CustomProc && g_ctrl->hWnd) + g_CustomProc(TTB_WINDOW_HANDLE, g_ctrl->hWnd, g_CustomProcParam); + + // receive all another buttons + NotifyEventHooks(hTTBModuleLoaded, 0, 0); CLISTFrame Frame = { 0 }; Frame.cbSize = sizeof(Frame); Frame.tname = pluginname; - Frame.hWnd = pluginwind; + Frame.hWnd = g_ctrl->hWnd; Frame.align = alTop; Frame.Flags = F_VISIBLE | F_NOBORDER | F_LOCKED | F_TCHAR; Frame.height = 18; - return (int)CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&Frame, 0); -} - -static INT_PTR OnEventFire(WPARAM wParam, LPARAM lParam) -{ - CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0); - StopArrange = FALSE; - NotifyEventHooks(hTTBInitButtons, 0, 0); - NotifyEventHooks(hTTBModuleLoaded, 0, 0); - - if (g_CustomProc) { - mir_cslock lck(csButtonsHook); - - if (hwndTopToolBar) - g_CustomProc(TTB_WINDOW_HANDLE, hwndTopToolBar, g_CustomProcParam); - - for (int i=0; i < Buttons.getCount(); i++) { - TopButtonInt* p = Buttons[i]; - g_CustomProc((HANDLE)p->id, p->hwnd, g_CustomProcParam); - } - } + g_ctrl->hFrame = (HANDLE)CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&Frame, 0); + bEventFired = true; return 0; } @@ -813,13 +827,10 @@ int OnModulesLoad(WPARAM wParam, LPARAM lParam) return 0; } - hwndContactList = (HWND)CallService(MS_CLUI_GETHWND, 0, 0); - - hFrameTopWindow = addTopToolBarWindow(hwndContactList); LoadAllSeparators(); LoadAllLButs(); - StopArrange = FALSE; + bStopArrange = FALSE; ArrangeButtons(); HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);//anonymous event @@ -831,8 +842,6 @@ int OnModulesLoad(WPARAM wParam, LPARAM lParam) sprintf(buf, "TopToolBar Background/%s", TTB_OPTDIR); CallService(MS_BACKGROUNDCONFIG_REGISTER, (WPARAM)buf, 0); } - - ttbOptionsChanged(); return 0; } @@ -840,8 +849,10 @@ int OnModulesLoad(WPARAM wParam, LPARAM lParam) int LoadToolbarModule() { + g_ctrl = (TTBCtrl*)mir_calloc( sizeof(TTBCtrl)); + InitializeCriticalSection(&csButtonsHook); - StopArrange = TRUE; + bStopArrange = TRUE; hBmpSeparator = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_SEP)); HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoad); @@ -866,9 +877,9 @@ int LoadToolbarModule() CreateServiceFunction("TopToolBar/SetCustomProc", TTBSetCustomProc); CreateServiceFunction("TTB_ONSTARTUPFIRE", OnEventFire); - BUTTHEIGHT = DBGetContactSettingByte(0, TTB_OPTDIR, "BUTTHEIGHT", DEFBUTTHEIGHT); - BUTTWIDTH = DBGetContactSettingByte(0, TTB_OPTDIR, "BUTTWIDTH", DEFBUTTWIDTH); - BUTTGAP = DBGetContactSettingByte(0, TTB_OPTDIR, "BUTTGAP", DEFBUTTGAP); + g_ctrl->nButtonHeight = db_get_b(0, TTB_OPTDIR, "BUTTHEIGHT", DEFBUTTHEIGHT); + g_ctrl->nButtonWidth = db_get_b(0, TTB_OPTDIR, "BUTTWIDTH", DEFBUTTWIDTH); + g_ctrl->nButtonSpace = db_get_b(0, TTB_OPTDIR, "BUTTGAP", DEFBUTTGAP); return 0; } @@ -885,5 +896,7 @@ int UnloadToolbarModule() for (int i=0; i < Buttons.getCount(); i++) delete Buttons[i]; Buttons.destroy(); + + mir_free(g_ctrl); return 0; } diff --git a/plugins/TopToolBar/topbutton.cpp b/plugins/TopToolBar/topbutton.cpp index 651686feea..9a1cbe0200 100644 --- a/plugins/TopToolBar/topbutton.cpp +++ b/plugins/TopToolBar/topbutton.cpp @@ -23,25 +23,25 @@ TopButtonInt::~TopButtonInt() DWORD TopButtonInt::CheckFlags(DWORD Flags) { int res = 0; - if (BitChanged(TTBBF_DISABLED)) { - dwFlags^=TTBBF_DISABLED; + if ( BitChanged(TTBBF_DISABLED)) { + dwFlags ^= TTBBF_DISABLED; EnableWindow(hwnd,(dwFlags & TTBBF_DISABLED)?FALSE:TRUE); } - if (BitChanged(TTBBF_ASPUSHBUTTON)) { + if ( BitChanged(TTBBF_ASPUSHBUTTON)) { dwFlags ^= TTBBF_ASPUSHBUTTON; SendMessage(hwnd, BUTTONSETASPUSHBTN, (dwFlags & TTBBF_ASPUSHBUTTON)?1:0, 0); } - if (BitChanged(TTBBF_SHOWTOOLTIP)) { + if ( BitChanged(TTBBF_SHOWTOOLTIP)) { dwFlags ^= TTBBF_SHOWTOOLTIP; SendMessage(hwnd,BUTTONADDTOOLTIP, (WPARAM)((dwFlags & TTBBF_SHOWTOOLTIP)?tooltip:L""),BATF_UNICODE); } // next settings changing visual side, requires additional actions - if (BitChanged(TTBBF_VISIBLE)) { + if ( BitChanged(TTBBF_VISIBLE)) { dwFlags ^= TTBBF_VISIBLE; res |= TTBBF_VISIBLE; } - if (BitChanged(TTBBF_PUSHED)) { + if ( BitChanged(TTBBF_PUSHED)) { dwFlags ^= TTBBF_PUSHED; res |= TTBBF_PUSHED; bPushed = (dwFlags & TTBBF_PUSHED) ? TRUE : FALSE; @@ -52,7 +52,10 @@ DWORD TopButtonInt::CheckFlags(DWORD Flags) void TopButtonInt::CreateWnd() { if ( !(dwFlags & TTBBF_ISSEPARATOR)) { - hwnd = CreateWindow(MIRANDABUTTONCLASS, _T(""), BS_PUSHBUTTON|WS_CHILD|WS_TABSTOP|SS_NOTIFY, 0, 0, BUTTWIDTH, BUTTHEIGHT, hwndTopToolBar, NULL, hInst, 0); + hwnd = CreateWindow(MIRANDABUTTONCLASS, _T(""), BS_PUSHBUTTON|WS_CHILD|WS_TABSTOP|SS_NOTIFY, 0, 0, g_ctrl->nButtonWidth, g_ctrl->nButtonHeight, g_ctrl->hWnd, NULL, hInst, 0); + + if (g_CustomProc) + g_CustomProc((HANDLE)id, hwnd, g_CustomProcParam); if (dwFlags & TTBBF_ASPUSHBUTTON) SendMessage(hwnd, BUTTONSETASPUSHBTN, 1, 0); @@ -60,11 +63,11 @@ void TopButtonInt::CreateWnd() if (DBGetContactSettingByte(0, TTB_OPTDIR, "UseFlatButton", 1)) SendMessage(hwnd, BUTTONSETASFLATBTN, TRUE, 0); - EnableWindow(hwnd,(dwFlags & TTBBF_DISABLED)?FALSE:TRUE); + EnableWindow(hwnd,(dwFlags & TTBBF_DISABLED)?FALSE:TRUE); } - // maybe SEPWIDTH, not BUTTWIDTH? + // maybe SEPWIDTH, not g_ctrl->nButtonWidth? else - hwnd = CreateWindow( _T("STATIC"), _T(""), WS_CHILD|SS_NOTIFY, 0, 0, BUTTWIDTH, BUTTHEIGHT, hwndTopToolBar, NULL, hInst, 0); + hwnd = CreateWindow( _T("STATIC"), _T(""), WS_CHILD|SS_NOTIFY, 0, 0, g_ctrl->nButtonWidth, g_ctrl->nButtonHeight, g_ctrl->hWnd, NULL, hInst, 0); SetWindowLongPtr(hwnd, GWLP_USERDATA, id); SetBitmap(); diff --git a/plugins/TopToolBar/ttbopt.cpp b/plugins/TopToolBar/ttbopt.cpp index e410f71dfa..2662a44eef 100644 --- a/plugins/TopToolBar/ttbopt.cpp +++ b/plugins/TopToolBar/ttbopt.cpp @@ -191,9 +191,9 @@ static INT_PTR CALLBACK ButOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR SetWindowLongPtr(hTree, GWL_STYLE, GetWindowLongPtr(hTree, GWL_STYLE)|TVS_NOHSCROLL); - SetDlgItemInt(hwndDlg, IDC_BUTTHEIGHT, BUTTHEIGHT, FALSE); - SetDlgItemInt(hwndDlg, IDC_BUTTWIDTH, BUTTWIDTH, FALSE); - SetDlgItemInt(hwndDlg, IDC_BUTTGAP, BUTTGAP, FALSE); + SetDlgItemInt(hwndDlg, IDC_BUTTHEIGHT, g_ctrl->nButtonHeight, FALSE); + SetDlgItemInt(hwndDlg, IDC_BUTTWIDTH, g_ctrl->nButtonWidth, FALSE); + SetDlgItemInt(hwndDlg, IDC_BUTTGAP, g_ctrl->nButtonSpace, FALSE); CheckDlgButton(hwndDlg, IDC_USEFLAT, DBGetContactSettingByte(0, TTB_OPTDIR, "UseFlatButton", 1)); BuildTree(hwndDlg); @@ -360,13 +360,13 @@ static INT_PTR CALLBACK ButOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: - BUTTHEIGHT = GetDlgItemInt(hwndDlg, IDC_BUTTHEIGHT, NULL, FALSE); - BUTTWIDTH = GetDlgItemInt(hwndDlg, IDC_BUTTWIDTH, NULL, FALSE); - BUTTGAP = GetDlgItemInt(hwndDlg, IDC_BUTTGAP, NULL, FALSE); - DBWriteContactSettingByte(0, TTB_OPTDIR, "BUTTHEIGHT", BUTTHEIGHT); - DBWriteContactSettingByte(0, TTB_OPTDIR, "BUTTWIDTH", BUTTWIDTH); - DBWriteContactSettingByte(0, TTB_OPTDIR, "BUTTGAP", BUTTGAP); - DBWriteContactSettingByte(0, TTB_OPTDIR, "UseFlatButton", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USEFLAT)); + g_ctrl->nButtonHeight = GetDlgItemInt(hwndDlg, IDC_BUTTHEIGHT, NULL, FALSE); + g_ctrl->nButtonWidth = GetDlgItemInt(hwndDlg, IDC_BUTTWIDTH, NULL, FALSE); + g_ctrl->nButtonSpace = GetDlgItemInt(hwndDlg, IDC_BUTTGAP, NULL, FALSE); + db_set_b(0, TTB_OPTDIR, "BUTTHEIGHT", g_ctrl->nButtonHeight); + db_set_b(0, TTB_OPTDIR, "BUTTWIDTH", g_ctrl->nButtonWidth); + db_set_b(0, TTB_OPTDIR, "BUTTGAP", g_ctrl->nButtonSpace); + db_set_b(0, TTB_OPTDIR, "UseFlatButton", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USEFLAT)); SaveTree(hwndDlg); RecreateWindows(); -- cgit v1.2.3