diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-11 15:51:11 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-11 15:51:11 +0000 |
commit | 3b8d44fb4646951be55b3777cbe30d3280867067 (patch) | |
tree | 8efa68247b8478dff4856415f06c15babf7136a7 /plugins/TopToolBar | |
parent | a051932068d3d2b76dac5afb279310505c2e70f0 (diff) |
- antiflicker effect for TTB resizing (thx to FYR for writing it)
- TTB visual part extracted to the separate module
git-svn-id: http://svn.miranda-ng.org/main/trunk@904 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TopToolBar')
-rw-r--r-- | plugins/TopToolBar/TopToolBar.vcxproj | 1 | ||||
-rw-r--r-- | plugins/TopToolBar/TopToolBar.vcxproj.filters | 3 | ||||
-rw-r--r-- | plugins/TopToolBar/common.h | 8 | ||||
-rw-r--r-- | plugins/TopToolBar/toolbar.cpp | 398 | ||||
-rw-r--r-- | plugins/TopToolBar/toolbarwnd.cpp | 329 | ||||
-rw-r--r-- | plugins/TopToolBar/ttbopt.cpp | 13 |
6 files changed, 424 insertions, 328 deletions
diff --git a/plugins/TopToolBar/TopToolBar.vcxproj b/plugins/TopToolBar/TopToolBar.vcxproj index 978fc4bfcc..312bf92d2c 100644 --- a/plugins/TopToolBar/TopToolBar.vcxproj +++ b/plugins/TopToolBar/TopToolBar.vcxproj @@ -271,6 +271,7 @@ <PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="toolbar.cpp" />
+ <ClCompile Include="toolbarwnd.cpp" />
<ClCompile Include="topbutton.cpp" />
<ClCompile Include="ttbopt.cpp" />
</ItemGroup>
diff --git a/plugins/TopToolBar/TopToolBar.vcxproj.filters b/plugins/TopToolBar/TopToolBar.vcxproj.filters index fca64531d0..500784079b 100644 --- a/plugins/TopToolBar/TopToolBar.vcxproj.filters +++ b/plugins/TopToolBar/TopToolBar.vcxproj.filters @@ -90,5 +90,8 @@ <ClCompile Include="topbutton.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="toolbarwnd.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file diff --git a/plugins/TopToolBar/common.h b/plugins/TopToolBar/common.h index 23c0bcb2f0..5a189df73b 100644 --- a/plugins/TopToolBar/common.h +++ b/plugins/TopToolBar/common.h @@ -93,12 +93,12 @@ char __inline *AS(char *str, const char *setting, char *addstr); TopButtonInt* CreateButton(TTBButton* but);
-int ttbOptionsChanged();
+int LoadBackgroundOptions();
int ArrangeButtons();
#define DEFBUTTWIDTH 20
-#define DEFBUTTHEIGHT 16
+#define DEFBUTTHEIGHT 20
#define DEFBUTTGAP 1
#define SEPWIDTH 3
@@ -106,12 +106,12 @@ int ArrangeButtons(); extern TTBCtrl* g_ctrl;
extern LIST<TopButtonInt> Buttons;
-extern bool bStopArrange;
extern HINSTANCE hInst;
extern HBITMAP hBmpBackground, hBmpSeparator;
extern CRITICAL_SECTION csButtonsHook;
extern pfnCustomProc g_CustomProc;
extern LPARAM g_CustomProcParam;
+extern HANDLE hTTBModuleLoaded, hTTBInitButtons;
void AddToOptions(TopButtonInt* b);
void RemoveFromOptions(int id);
@@ -128,6 +128,8 @@ char *AS(char *str, const char *setting, char *addstr) #define TTB_LAUNCHSERVICE "TTB/LaunchService"
+TopButtonInt* idtopos(int id, int* pPos=NULL);
+
INT_PTR TTBAddButton(WPARAM, LPARAM);
INT_PTR TTBRemoveButton(WPARAM, LPARAM);
diff --git a/plugins/TopToolBar/toolbar.cpp b/plugins/TopToolBar/toolbar.cpp index a40804efd8..70d3f02daa 100644 --- a/plugins/TopToolBar/toolbar.cpp +++ b/plugins/TopToolBar/toolbar.cpp @@ -7,20 +7,15 @@ pfnCustomProc g_CustomProc = NULL; LPARAM g_CustomProcParam = 0;
TTBCtrl *g_ctrl = NULL;
+INT_PTR OnEventFire(WPARAM wParam, LPARAM lParam);
+
HWND hwndContactList = 0;
-bool bStopArrange, bEventFired = false;
int nextButtonId = 200;
-static HANDLE hTTBModuleLoaded, hTTBInitButtons;
-static TCHAR pluginname[] = _T("TopToolBar");
+HANDLE hTTBModuleLoaded, hTTBInitButtons;
static WNDPROC buttonWndProc;
-//------------ options -------------
-COLORREF bkColour;
-HBITMAP hBmpBackground, hBmpSeparator;
-int backgroundBmpUse;
-
CRITICAL_SECTION csButtonsHook;
int sortfunc(const TopButtonInt* a, const TopButtonInt* b)
@@ -37,7 +32,7 @@ static void SetAllBitmaps() Buttons[i]->SetBitmap();
}
-static TopButtonInt* idtopos(int id, int* pPos=NULL)
+TopButtonInt* idtopos(int id, int* pPos)
{
for ( int i = 0; i < Buttons.getCount(); i++)
if (Buttons[i]->id == id) {
@@ -139,32 +134,6 @@ int SaveAllButtonsOptions() return 0;
}
-int ttbOptionsChanged()
-{
- //load options
- bkColour = DBGetContactSettingDword(NULL, TTB_OPTDIR, "BkColour", TTBDEFAULT_BKCOLOUR);
- if (hBmpBackground) {
- DeleteObject(hBmpBackground);
- hBmpBackground = NULL;
- }
-
- if (DBGetContactSettingByte(NULL, TTB_OPTDIR, "UseBitmap", TTBDEFAULT_USEBITMAP)) {
- DBVARIANT dbv;
- if (!DBGetContactSetting(NULL, TTB_OPTDIR, "BkBitmap", &dbv)) {
- hBmpBackground = (HBITMAP)CallService(MS_UTILS_LOADBITMAP, 0, (LPARAM)dbv.pszVal);
- DBFreeVariant(&dbv);
- }
- }
- backgroundBmpUse = DBGetContactSettingWord(NULL, TTB_OPTDIR, "BkBmpUse", TTBDEFAULT_BKBMPUSE);
-
- RECT rc;
- GetClientRect(g_ctrl->hWnd, &rc);
- InvalidateRect(g_ctrl->hWnd, &rc, TRUE);
- UpdateWindow(g_ctrl->hWnd);
-
- return 0;
-}
-
INT_PTR TTBRemoveButton(WPARAM wParam, LPARAM lParam)
{
mir_cslock lck(csButtonsHook);
@@ -310,56 +279,84 @@ INT_PTR TTBAddButton(WPARAM wParam, LPARAM lParam) int ArrangeButtons()
{
- if (bStopArrange == TRUE)
- return 0;
-
mir_cslock lck(csButtonsHook);
- RECT winrc;
- GetClientRect(g_ctrl->hWnd, &winrc);
- winrc.left = winrc.right-winrc.left;
- if (winrc.left == 0)
- return 0;
- int newheight;
-
- bStopArrange = true;
- int ypos = 1;
- 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);
+ RECT rcClient;
+ GetClientRect(g_ctrl->hWnd, &rcClient);
+ int nBarSize = rcClient.right - rcClient.left;
+ if (nBarSize == 0)
+ return g_ctrl->nButtonHeight;
- int uFlags;
+ g_ctrl->nLineCount = 0;
- for (int i = 0; i < Buttons.getCount(); i++) {
- TopButtonInt *b = Buttons[i];
+ int i, ypos = 1, xpos = g_ctrl->nButtonSpace, nextX = 0, y = 0;
+ int newheight = g_ctrl->nButtonHeight+1;
- // not visible - hide and skip
- if ( !(b->dwFlags & TTBBF_VISIBLE)) {
+ LIST<TopButtonInt> tmpList = Buttons;
+ for (i=tmpList.getCount()-1; i >= 0; i--) {
+ TopButtonInt *b = tmpList[i];
+ if (b->hwnd == NULL || !(b->dwFlags & TTBBF_VISIBLE)) {
ShowWindow(b->hwnd, SW_HIDE);
- continue;
+ tmpList.remove(i);
}
+ }
+
+ if (tmpList.getCount() == 0)
+ return g_ctrl->nButtonHeight;
+
+ HDWP hdwp = BeginDeferWindowPos(tmpList.getCount());
+
+ bool bWasButttonBefore;
+ int nUsedWidth, iFirstButtonId = 0, iLastButtonId = 0;
+
+ do
+ {
+ g_ctrl->nLineCount++;
+ bWasButttonBefore = false;
+ nUsedWidth = 0;
+
+ for (i=iFirstButtonId; i < tmpList.getCount(); i++) {
+ TopButtonInt *b = tmpList[i];
- if ( b->isSep())
- uFlags = SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW;
- else
- uFlags = SWP_NOZORDER | SWP_SHOWWINDOW;
-
- // check, if need to move to next line
- 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);
+ int width = (b->isSep()) ? SEPWIDTH+2 : g_ctrl->nButtonWidth + ((bWasButttonBefore) ? g_ctrl->nButtonSpace : 0);
+ if (nUsedWidth + width > nBarSize)
+ break;
+
+ nUsedWidth += width;
+ iLastButtonId = i+1;
+ bWasButttonBefore = !b->isSep();
}
- SetWindowPos(b->hwnd, 0, xpos, ypos, g_ctrl->nButtonWidth, g_ctrl->nButtonHeight, uFlags);
- InvalidateRect(b->hwnd, NULL, TRUE);
+ int nFreeSpace = nBarSize - nUsedWidth;
+
+ for (i=iFirstButtonId; i < iLastButtonId; i++) {
+ TopButtonInt *b = tmpList[i];
+
+ hdwp = DeferWindowPos(hdwp, b->hwnd, NULL, nextX, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
+ if ( b->isSep())
+ nextX += SEPWIDTH+2;
+ else
+ nextX += g_ctrl->nButtonWidth + g_ctrl->nButtonSpace;
+ }
- xpos += (b->isSep()) ? SEPWIDTH+2 : g_ctrl->nButtonWidth+g_ctrl->nButtonSpace;
+ if (iFirstButtonId == iLastButtonId)
+ break;
+ iFirstButtonId = iLastButtonId;
+ y += g_ctrl->nButtonHeight + g_ctrl->nButtonSpace;
+ nextX = 0;
+ if (g_ctrl->bSingleLine)
+ break;
}
- bStopArrange = false;
- return 1;
+ while (iFirstButtonId < tmpList.getCount() && y >= 0 && (g_ctrl->bAutoSize || (y + g_ctrl->nButtonHeight <= rcClient.bottom - rcClient.top)));
+
+ for (i=iFirstButtonId; i < tmpList.getCount(); i++)
+ hdwp = DeferWindowPos(hdwp, tmpList[i]->hwnd, NULL, nextX, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_HIDEWINDOW);
+
+ if (hdwp)
+ EndDeferWindowPos(hdwp);
+
+ return (g_ctrl->nButtonHeight + g_ctrl->nButtonSpace)*g_ctrl->nLineCount - g_ctrl->nButtonSpace;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -532,247 +529,6 @@ INT_PTR TTBSetOptions(WPARAM wParam, LPARAM lParam) return retval;
}
-/////////////////////////////////////////////////////////////////////////////////////////
-// Toolbar window procedure
-
-static void PaintToolbar(HWND hwnd)
-{
- InvalidateRect(hwnd, 0, FALSE);
-
- PAINTSTRUCT paintst;
- HDC hdc = BeginPaint(hwnd, &paintst);
- RECT *rcPaint = &paintst.rcPaint;
-
- RECT clRect;
- GetClientRect(hwnd, &clRect);
- if (rcPaint == NULL) rcPaint = &clRect;
-
- int yScroll = 0;
- int y = -yScroll;
-
- HDC hdcMem = CreateCompatibleDC(hdc);
- HBITMAP hBmpOsb = CreateBitmap(clRect.right, clRect.bottom, 1, GetDeviceCaps(hdc, BITSPIXEL), NULL);
- HBITMAP hOldBmp = (HBITMAP)SelectObject(hdcMem, hBmpOsb);
- SetBkMode(hdcMem, TRANSPARENT);
-
- HBRUSH hBrush = CreateSolidBrush(bkColour);
- HBRUSH hoBrush = (HBRUSH)SelectObject(hdcMem, hBrush);
- FillRect(hdcMem, rcPaint, hBrush);
- SelectObject(hdcMem, hoBrush);
- DeleteObject(hBrush);
- if (hBmpBackground) {
- BITMAP bmp;
- HDC hdcBmp;
- int x, y;
- int maxx, maxy;
- int destw, desth;
-
- GetObject(hBmpBackground, sizeof(bmp), &bmp);
- hdcBmp = CreateCompatibleDC(hdcMem);
- 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;
- switch(backgroundBmpUse & CLBM_TYPE) {
- case CLB_STRETCH:
- if (backgroundBmpUse&CLBF_PROPORTIONAL) {
- if (clRect.right*bmp.bmHeight<clRect.bottom*bmp.bmWidth) {
- desth = clRect.bottom;
- destw = desth*bmp.bmWidth/bmp.bmHeight;
- }
- else {
- destw = clRect.right;
- desth = destw*bmp.bmHeight/bmp.bmWidth;
- }
- }
- else {
- destw = clRect.right;
- desth = clRect.bottom;
- }
- break;
- case CLB_STRETCHH:
- if (backgroundBmpUse&CLBF_PROPORTIONAL) {
- destw = clRect.right;
- desth = destw*bmp.bmHeight/bmp.bmWidth;
- if (backgroundBmpUse & CLBF_TILEVTOROWHEIGHT)
- desth = g_ctrl->nButtonHeight+2;
- }
- else {
- destw = clRect.right;
- desth = bmp.bmHeight;
- }
- break;
- case CLB_STRETCHV:
- if (backgroundBmpUse&CLBF_PROPORTIONAL) {
- desth = clRect.bottom;
- destw = desth*bmp.bmWidth/bmp.bmHeight;
- }
- else {
- destw = bmp.bmWidth;
- desth = clRect.bottom;
- }
- break;
- default: //clb_topleft
- destw = bmp.bmWidth;
- desth = bmp.bmHeight;
- if (backgroundBmpUse&CLBF_TILEVTOROWHEIGHT)
- desth = g_ctrl->nButtonHeight+2;
- break;
- }
-
- for (; y < maxy; y += desth) {
- if (y < rcPaint->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);
- 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:
- g_ctrl->hWnd = hwnd;
- return FALSE;
-
- case WM_MOVE:
- return 0;
-
- case WM_WINDOWPOSCHANGING:
- case WM_SIZE:
- ArrangeButtons();
- return 0;
-
- case WM_NCPAINT:
- case WM_PAINT:
- PaintToolbar(hwnd);
- return 0;
-
- case WM_LBUTTONDOWN:
- if (DBGetContactSettingByte(NULL, "CLUI", "ClientAreaDrag", 0)) {
- POINT pt;
- GetCursorPos(&pt);
- return SendMessage(GetParent(hwnd), WM_SYSCOMMAND, SC_MOVE|HTCAPTION, MAKELPARAM(pt.x, pt.y));
- }
- return 0;
-
- case WM_COMMAND:
- switch (HIWORD(wParam)) {
- case BN_CLICKED:
- case BN_DOUBLECLICKED:
- {
- 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;
-
- if (b->dwFlags & TTBBF_ASPUSHBUTTON)
- b->bPushed = !b->bPushed;
-
- if (b->bPushed) { //Dn -> Up
- 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->pszService != NULL)
- CallService(b->pszService, b->wParamDown, b->lParamDown);
- }
-
- 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));
-
- g_ctrl->fnWindowProc = pCustom->fnWindowProc;
- SetWindowLongPtr(hwnd, 0, (LONG_PTR)g_ctrl);
- }
- break;
-
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return(TRUE);
-}
-
-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*);
- wndclass.hInstance = hInst;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
- wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);//NULL;//(HBRUSH)(COLOR_3DFACE+1);
- wndclass.lpszClassName = pluginname;
- RegisterClass(&wndclass);
-
- g_ctrl->pButtonList = (SortedList*)&Buttons;
- g_ctrl->hWnd = CreateWindow(pluginname, _T("Toolbar"),
- WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
- 0, 0, 0, 0, parent, NULL, hInst, NULL);
- SetWindowLongPtr(g_ctrl->hWnd, 0, (LPARAM)g_ctrl);
-
- // if we're working in skinned clist, receive the standard buttons & customizations
- if (g_CustomProc && g_ctrl->hWnd)
- g_CustomProc(TTB_WINDOW_HANDLE, g_ctrl->hWnd, g_CustomProcParam);
-
- // if there's no customized frames, create our own
- if (g_ctrl->hFrame == NULL) {
- CLISTFrame Frame = { 0 };
- Frame.cbSize = sizeof(Frame);
- Frame.tname = _T("Toolbar");
- Frame.hWnd = g_ctrl->hWnd;
- Frame.align = alTop;
- Frame.Flags = F_VISIBLE | F_NOBORDER | F_LOCKED | F_TCHAR;
- Frame.height = 18;
- g_ctrl->hFrame = (HANDLE)CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&Frame, 0);
- }
-
- // receive all buttons
- NotifyEventHooks(hTTBInitButtons, 0, 0);
- NotifyEventHooks(hTTBModuleLoaded, 0, 0);
-
- ttbOptionsChanged();
-
- bEventFired = true;
- return 0;
-}
-
int OnIconChange(WPARAM wParam, LPARAM lParam)
{
ReloadIcons();
@@ -782,7 +538,7 @@ int OnIconChange(WPARAM wParam, LPARAM lParam) static int OnBGChange(WPARAM wParam, LPARAM lParam)
{
- ttbOptionsChanged();
+ LoadBackgroundOptions();
return 0;
}
@@ -805,7 +561,6 @@ int OnModulesLoad(WPARAM wParam, LPARAM lParam) LoadAllSeparators();
LoadAllLButs();
- bStopArrange = FALSE;
ArrangeButtons();
HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);//anonymous event
@@ -838,9 +593,16 @@ static LRESULT CALLBACK TTBButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LP int LoadToolbarModule()
{
g_ctrl = (TTBCtrl*)mir_calloc( sizeof(TTBCtrl));
+ g_ctrl->nButtonHeight = db_get_dw(0, TTB_OPTDIR, "BUTTHEIGHT", DEFBUTTHEIGHT);
+ g_ctrl->nButtonWidth = db_get_dw(0, TTB_OPTDIR, "BUTTWIDTH", DEFBUTTWIDTH);
+ g_ctrl->nButtonSpace = db_get_dw(0, TTB_OPTDIR, "BUTTGAP", DEFBUTTGAP);
+ g_ctrl->nLastHeight = db_get_dw(0, TTB_OPTDIR, "LastHeight", DEFBUTTHEIGHT);
+
+ g_ctrl->bFlatButtons = db_get_b(0, TTB_OPTDIR, "UseFlatButton", true);
+ g_ctrl->bSingleLine = db_get_b(0, TTB_OPTDIR, "SingleLine", true);
+ g_ctrl->bAutoSize = db_get_b(0, TTB_OPTDIR, "AutoSize", true);
InitializeCriticalSection(&csButtonsHook);
- bStopArrange = TRUE;
hBmpSeparator = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_SEP));
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoad);
@@ -875,10 +637,6 @@ int LoadToolbarModule() wc.hbrBackground = 0;
wc.style = CS_GLOBALCLASS;
RegisterClassEx(&wc);
-
- 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;
}
diff --git a/plugins/TopToolBar/toolbarwnd.cpp b/plugins/TopToolBar/toolbarwnd.cpp new file mode 100644 index 0000000000..52eff7deac --- /dev/null +++ b/plugins/TopToolBar/toolbarwnd.cpp @@ -0,0 +1,329 @@ +
+#include "common.h"
+
+COLORREF bkColour;
+HBITMAP hBmpBackground, hBmpSeparator;
+int backgroundBmpUse;
+
+static TCHAR pluginname[] = _T("TopToolBar");
+
+#define TTB_REPOSBUTTONS (WM_USER+10)
+#define TTB_UPDATEFRAMEVISIBILITY (WM_USER+11)
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Toolbar window procedure
+
+static void PaintToolbar(HWND hwnd)
+{
+ InvalidateRect(hwnd, 0, FALSE);
+
+ PAINTSTRUCT paintst;
+ HDC hdc = BeginPaint(hwnd, &paintst);
+ RECT *rcPaint = &paintst.rcPaint;
+
+ RECT clRect;
+ GetClientRect(hwnd, &clRect);
+ if (rcPaint == NULL) rcPaint = &clRect;
+
+ int yScroll = 0;
+ int y = -yScroll;
+
+ HDC hdcMem = CreateCompatibleDC(hdc);
+ HBITMAP hBmpOsb = CreateBitmap(clRect.right, clRect.bottom, 1, GetDeviceCaps(hdc, BITSPIXEL), NULL);
+ HBITMAP hOldBmp = (HBITMAP)SelectObject(hdcMem, hBmpOsb);
+ SetBkMode(hdcMem, TRANSPARENT);
+
+ HBRUSH hBrush = CreateSolidBrush(bkColour);
+ HBRUSH hoBrush = (HBRUSH)SelectObject(hdcMem, hBrush);
+ FillRect(hdcMem, rcPaint, hBrush);
+ SelectObject(hdcMem, hoBrush);
+ DeleteObject(hBrush);
+ if (hBmpBackground) {
+ BITMAP bmp;
+ GetObject(hBmpBackground, sizeof(bmp), &bmp);
+
+ HDC hdcBmp = CreateCompatibleDC(hdcMem);
+ SelectObject(hdcBmp, hBmpBackground);
+ int y = backgroundBmpUse & CLBF_SCROLL ? -yScroll : 0;
+ int maxx = backgroundBmpUse & CLBF_TILEH ? clRect.right : 1;
+ int maxy = backgroundBmpUse & CLBF_TILEV ? maxy = rcPaint->bottom : y+1;
+
+ int destw, desth;
+ switch(backgroundBmpUse & CLBM_TYPE) {
+ case CLB_STRETCH:
+ if (backgroundBmpUse&CLBF_PROPORTIONAL) {
+ if (clRect.right * bmp.bmHeight < clRect.bottom * bmp.bmWidth) {
+ desth = clRect.bottom;
+ destw = desth * bmp.bmWidth/bmp.bmHeight;
+ }
+ else {
+ destw = clRect.right;
+ desth = destw * bmp.bmHeight/bmp.bmWidth;
+ }
+ }
+ else {
+ destw = clRect.right;
+ desth = clRect.bottom;
+ }
+ break;
+ case CLB_STRETCHH:
+ if (backgroundBmpUse & CLBF_PROPORTIONAL) {
+ destw = clRect.right;
+ desth = destw * bmp.bmHeight/bmp.bmWidth;
+ if (backgroundBmpUse & CLBF_TILEVTOROWHEIGHT)
+ desth = g_ctrl->nButtonHeight+2;
+ }
+ else {
+ destw = clRect.right;
+ desth = bmp.bmHeight;
+ }
+ break;
+ case CLB_STRETCHV:
+ if (backgroundBmpUse & CLBF_PROPORTIONAL) {
+ desth = clRect.bottom;
+ destw = desth*bmp.bmWidth/bmp.bmHeight;
+ }
+ else {
+ destw = bmp.bmWidth;
+ desth = clRect.bottom;
+ }
+ break;
+ default: //clb_topleft
+ destw = bmp.bmWidth;
+ desth = bmp.bmHeight;
+ if (backgroundBmpUse & CLBF_TILEVTOROWHEIGHT)
+ desth = g_ctrl->nButtonHeight+2;
+ break;
+ }
+
+ for (; y < maxy; y += desth) {
+ if (y < rcPaint->top - desth)
+ continue;
+
+ for (int 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);
+ SelectObject(hdcMem, hOldBmp);
+ DeleteDC(hdcMem);
+ DeleteObject(hBmpOsb);
+
+ paintst.fErase = FALSE;
+ EndPaint(hwnd, &paintst);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ static bool supressRepos = false;
+
+ if (g_ctrl->fnWindowProc != NULL)
+ if ( g_ctrl->fnWindowProc(hwnd, msg, wParam, lParam))
+ return g_ctrl->lResult;
+
+ switch(msg) {
+ case WM_CREATE:
+ g_ctrl->hWnd = hwnd;
+ PostMessage(hwnd, TTB_UPDATEFRAMEVISIBILITY, 1, 0);
+ return FALSE;
+
+ case WM_MOVE:
+ return 0;
+
+ case WM_WINDOWPOSCHANGING:
+ case WM_SIZE:
+ if (g_ctrl->nLastHeight != HIWORD(lParam)) {
+ db_set_dw(0, TTB_OPTDIR, "LastHeight", g_ctrl->nLastHeight = HIWORD(lParam));
+ ArrangeButtons();
+ }
+ if (supressRepos) {
+ supressRepos = false;
+ break;
+ }
+ // fall through
+
+ case TTB_REPOSBUTTONS:
+ if (g_ctrl->hWnd == hwnd) {
+ int iHeight = ArrangeButtons();
+ if ( g_ctrl->bAutoSize) {
+ RECT rcClient;
+ GetClientRect(g_ctrl->hWnd, &rcClient);
+ if (rcClient.bottom - rcClient.top != iHeight && iHeight) {
+ supressRepos = true;
+ PostMessage(hwnd, TTB_UPDATEFRAMEVISIBILITY, -1, 0);
+ }
+ }
+ return 0;
+ }
+ break;
+
+ case WM_NCPAINT:
+ case WM_PAINT:
+ PaintToolbar(hwnd);
+ return 0;
+
+ case WM_LBUTTONDOWN:
+ if (DBGetContactSettingByte(NULL, "CLUI", "ClientAreaDrag", 0)) {
+ POINT pt;
+ GetCursorPos(&pt);
+ return SendMessage(GetParent(hwnd), WM_SYSCOMMAND, SC_MOVE|HTCAPTION, MAKELPARAM(pt.x, pt.y));
+ }
+ return 0;
+
+ case WM_COMMAND:
+ switch (HIWORD(wParam)) {
+ case BN_CLICKED:
+ case BN_DOUBLECLICKED:
+ {
+ 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;
+
+ if (b->dwFlags & TTBBF_ASPUSHBUTTON)
+ b->bPushed = !b->bPushed;
+
+ if (b->bPushed) { //Dn -> Up
+ 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->pszService != NULL)
+ CallService(b->pszService, b->wParamDown, b->lParamDown);
+ }
+
+ b->SetBitmap();
+ }
+ }
+ break;
+ }
+ break;
+
+ case TTB_UPDATEFRAMEVISIBILITY:
+ {
+ BOOL vis=(BOOL)wParam;
+ BOOL curvis = IsWindowVisible(hwnd);
+ bool bResize = false;
+ int Height = ArrangeButtons();
+
+ if (g_ctrl->bAutoSize) {
+ INT_PTR frameopt = CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT, g_ctrl->hFrame), 0);
+ if (Height != frameopt) {
+ CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT, g_ctrl->hFrame), Height);
+ bResize = TRUE;
+ }
+ }
+
+ if ((curvis != vis || bResize) && vis != -1) {
+ INT_PTR frameopt = CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS, MAKEWPARAM(FO_FLAGS, g_ctrl->hFrame), 0);
+ frameopt &= ~F_VISIBLE;
+ frameopt |= vis ? F_VISIBLE : 0;
+ CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_FLAGS, g_ctrl->hFrame), frameopt);
+ }
+ }
+ 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));
+
+ g_ctrl->fnWindowProc = pCustom->fnWindowProc;
+ SetWindowLongPtr(hwnd, 0, (LONG_PTR)g_ctrl);
+ }
+ break;
+
+ default:
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+ }
+ return(TRUE);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+INT_PTR OnEventFire(WPARAM wParam, LPARAM lParam)
+{
+ CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0);
+
+ 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*);
+ wndclass.hInstance = hInst;
+ wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
+ wndclass.lpszClassName = pluginname;
+ RegisterClass(&wndclass);
+
+ g_ctrl->pButtonList = (SortedList*)&Buttons;
+ g_ctrl->hWnd = CreateWindow(pluginname, _T("Toolbar"),
+ WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ 0, 0, 0, g_ctrl->nLastHeight, parent, NULL, hInst, NULL);
+ SetWindowLongPtr(g_ctrl->hWnd, 0, (LPARAM)g_ctrl);
+
+ LoadBackgroundOptions();
+
+ // if we're working in skinned clist, receive the standard buttons & customizations
+ if (g_CustomProc && g_ctrl->hWnd)
+ g_CustomProc(TTB_WINDOW_HANDLE, g_ctrl->hWnd, g_CustomProcParam);
+
+ // if there's no customized frames, create our own
+ if (g_ctrl->hFrame == NULL) {
+ CLISTFrame Frame = { 0 };
+ Frame.cbSize = sizeof(Frame);
+ Frame.tname = _T("Toolbar");
+ Frame.hWnd = g_ctrl->hWnd;
+ Frame.align = alTop;
+ Frame.Flags = F_VISIBLE | F_NOBORDER | F_LOCKED | F_TCHAR;
+ Frame.height = g_ctrl->nLastHeight;
+ g_ctrl->hFrame = (HANDLE)CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&Frame, 0);
+ }
+
+ // receive all buttons
+ NotifyEventHooks(hTTBInitButtons, 0, 0);
+ NotifyEventHooks(hTTBModuleLoaded, 0, 0);
+
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+int LoadBackgroundOptions()
+{
+ //load options
+ bkColour = DBGetContactSettingDword(NULL, TTB_OPTDIR, "BkColour", TTBDEFAULT_BKCOLOUR);
+ if (hBmpBackground) {
+ DeleteObject(hBmpBackground);
+ hBmpBackground = NULL;
+ }
+
+ if (DBGetContactSettingByte(NULL, TTB_OPTDIR, "UseBitmap", TTBDEFAULT_USEBITMAP)) {
+ DBVARIANT dbv;
+ if (!DBGetContactSetting(NULL, TTB_OPTDIR, "BkBitmap", &dbv)) {
+ hBmpBackground = (HBITMAP)CallService(MS_UTILS_LOADBITMAP, 0, (LPARAM)dbv.pszVal);
+ DBFreeVariant(&dbv);
+ }
+ }
+ backgroundBmpUse = DBGetContactSettingWord(NULL, TTB_OPTDIR, "BkBmpUse", TTBDEFAULT_BKBMPUSE);
+
+ RECT rc;
+ GetClientRect(g_ctrl->hWnd, &rc);
+ InvalidateRect(g_ctrl->hWnd, &rc, TRUE);
+ UpdateWindow(g_ctrl->hWnd);
+
+ return 0;
+}
diff --git a/plugins/TopToolBar/ttbopt.cpp b/plugins/TopToolBar/ttbopt.cpp index 5fd2edef80..a63554f436 100644 --- a/plugins/TopToolBar/ttbopt.cpp +++ b/plugins/TopToolBar/ttbopt.cpp @@ -194,7 +194,8 @@ static INT_PTR CALLBACK ButOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR 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));
+
+ CheckDlgButton(hwndDlg, IDC_USEFLAT, g_ctrl->bFlatButtons);
BuildTree(hwndDlg);
EnableWindow(GetDlgItem(hwndDlg, IDC_ENAME), FALSE);
@@ -361,10 +362,12 @@ static INT_PTR CALLBACK ButOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR 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));
+ g_ctrl->bFlatButtons = (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USEFLAT);
+
+ db_set_dw(0, TTB_OPTDIR, "BUTTHEIGHT", g_ctrl->nButtonHeight);
+ db_set_dw(0, TTB_OPTDIR, "BUTTWIDTH", g_ctrl->nButtonWidth);
+ db_set_dw(0, TTB_OPTDIR, "BUTTGAP", g_ctrl->nButtonSpace);
+ db_set_b(0, TTB_OPTDIR, "UseFlatButton", g_ctrl->bFlatButtons);
SaveTree(hwndDlg);
RecreateWindows();
|