summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-06-08 20:53:44 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-06-08 20:53:44 +0000
commitd0ffabed30e05f6dc56e2e5231637f333bc16003 (patch)
treee60b3117ac38932b085df745edf969262a6d836b
parent164424ac47e2be37daa5e4346cc29a865042027e (diff)
toptoolbar -> c++
git-svn-id: http://svn.miranda-ng.org/main/trunk@363 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/TopToolBar/BkgrCfg.h4
-rw-r--r--plugins/TopToolBar/CLCButton.c624
-rw-r--r--plugins/TopToolBar/CLCButton.cpp625
-rw-r--r--plugins/TopToolBar/InternalButtons.c436
-rw-r--r--plugins/TopToolBar/InternalButtons.cpp312
-rw-r--r--plugins/TopToolBar/TopToolBar.vcxproj68
-rw-r--r--plugins/TopToolBar/TopToolBar.vcxproj.filters49
-rw-r--r--plugins/TopToolBar/_button.c515
-rw-r--r--plugins/TopToolBar/_button.cpp522
-rw-r--r--plugins/TopToolBar/button.cpp (renamed from plugins/TopToolBar/button.c)534
-rw-r--r--plugins/TopToolBar/buttonopt.c340
-rw-r--r--plugins/TopToolBar/buttonopt.cpp323
-rw-r--r--plugins/TopToolBar/common.h70
-rw-r--r--plugins/TopToolBar/launchbt.c211
-rw-r--r--plugins/TopToolBar/launchbt.cpp218
-rw-r--r--plugins/TopToolBar/main.c1515
-rw-r--r--plugins/TopToolBar/main.cpp1156
-rw-r--r--plugins/TopToolBar/main.rc188
-rw-r--r--plugins/TopToolBar/separators.c111
-rw-r--r--plugins/TopToolBar/separators.cpp98
-rw-r--r--plugins/TopToolBar/ttbopt.c970
-rw-r--r--plugins/TopToolBar/ttbopt.cpp822
22 files changed, 4523 insertions, 5188 deletions
diff --git a/plugins/TopToolBar/BkgrCfg.h b/plugins/TopToolBar/BkgrCfg.h
index a47b53a603..4533267fcb 100644
--- a/plugins/TopToolBar/BkgrCfg.h
+++ b/plugins/TopToolBar/BkgrCfg.h
@@ -2,8 +2,8 @@
// Register of plugin's user
//
// wParam = (WPARAM)szSetting - string that describes a user
-// format: Category/ModuleName,
-// eg: "Contact list background/CLUI",
+// format: Category/ModuleName,
+// eg: "Contact list background/CLUI",
// "Status bar background/StatusBar"
// lParam = (LPARAM)dwFlags
//
diff --git a/plugins/TopToolBar/CLCButton.c b/plugins/TopToolBar/CLCButton.c
deleted file mode 100644
index 597bb67cc2..0000000000
--- a/plugins/TopToolBar/CLCButton.c
+++ /dev/null
@@ -1,624 +0,0 @@
-/*
-Miranda IM
-Copyright (C) 2002 Robert Rainwater
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include "common.h"
-
-// TODO:
-// - Support for bitmap buttons (simple call to DrawIconEx())
-extern HINSTANCE hInst;
-LONG g_cxsmIcon, g_cysmIcon;
-
-static LRESULT CALLBACK TSButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-
-typedef struct {
- HWND hwnd;
- int stateId; // button state
- int focus; // has focus (1 or 0)
- HFONT hFont; // font
- HICON arrow; // uses down arrow
- int defbutton; // default button
- HICON hIcon, hIconPrivate;
- HBITMAP hBitmap;
- int pushBtn;
- int pbState;
- HANDLE hThemeButton;
- HANDLE hThemeToolbar;
- BOOL bThemed;
- char cHot;
- int flatBtn;
- char szText[128];
- SIZE sLabel;
- HIMAGELIST hIml;
- int iIcon;
-} MButtonCtrl;
-
-// External theme methods and properties
-static HMODULE themeAPIHandle = NULL; // handle to uxtheme.dll
-static HANDLE (WINAPI *MyOpenThemeData)(HWND, LPCWSTR);
-static HRESULT (WINAPI *MyCloseThemeData)(HANDLE);
-static BOOL (WINAPI *MyIsThemeBackgroundPartiallyTransparent)(HANDLE, int,
- int);
-static HRESULT (WINAPI *MyDrawThemeParentBackground)(HWND, HDC, RECT *);
-static HRESULT (WINAPI *MyDrawThemeBackground)(HANDLE, HDC, int, int,
- const RECT *, const RECT *);
-static HRESULT (WINAPI *MyDrawThemeText)(HANDLE, HDC, int, int, LPCWSTR, int,
- DWORD, DWORD, const RECT *);
-
-static CRITICAL_SECTION csTips;
-static HWND hwndToolTips = NULL;
-
-int UnloadTSButtonModule(WPARAM wParam, LPARAM lParam)
-{
- DeleteCriticalSection(&csTips);
- return 0;
-}
-
-int LoadCLCButtonModule(void)
-{
- WNDCLASSEXA wc;
-
- g_cxsmIcon=GetSystemMetrics(SM_CXSMICON);
- g_cysmIcon=GetSystemMetrics(SM_CYSMICON);
-
- ZeroMemory(&wc, sizeof(wc));
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = "CLCButtonClass";
- wc.lpfnWndProc = TSButtonWndProc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.cbWndExtra = sizeof(MButtonCtrl *);
- wc.hbrBackground = 0;
- wc.style = CS_GLOBALCLASS;
- RegisterClassExA(&wc);
- InitializeCriticalSection(&csTips);
- return 0;
-}
-
-// Used for our own cheap TrackMouseEvent
-#define BUTTON_POLLID 100
-#define BUTTON_POLLDELAY 50
-
-#define MGPROC(x) GetProcAddress(themeAPIHandle,x)
-static int ThemeSupport()
-{
- if (IsWinVerXPPlus()) {
- if (!themeAPIHandle) {
- themeAPIHandle = GetModuleHandleA("uxtheme");
- if (themeAPIHandle) {
- MyOpenThemeData = (HANDLE(WINAPI *)(HWND, LPCWSTR))MGPROC("OpenThemeData");
- MyCloseThemeData = (HRESULT(WINAPI *)(HANDLE))MGPROC("CloseThemeData");
- MyIsThemeBackgroundPartiallyTransparent = (BOOL(WINAPI *)(HANDLE, int, int))MGPROC("IsThemeBackgroundPartiallyTransparent");
- MyDrawThemeParentBackground = (HRESULT(WINAPI *)(HWND, HDC, RECT *))MGPROC("DrawThemeParentBackground");
- MyDrawThemeBackground = (HRESULT(WINAPI *)(HANDLE, HDC, int, int, const RECT *, const RECT *))MGPROC("DrawThemeBackground");
- MyDrawThemeText = (HRESULT(WINAPI *)(HANDLE, HDC, int, int, LPCWSTR, int, DWORD, DWORD, const RECT *))MGPROC("DrawThemeText");
- }
- }
- // Make sure all of these methods are valid (i would hope either all or none work)
- if (MyOpenThemeData && MyCloseThemeData && MyIsThemeBackgroundPartiallyTransparent && MyDrawThemeParentBackground && MyDrawThemeBackground && MyDrawThemeText) {
- return 1;
- }
- }
- return 0;
-}
-
-static void DestroyTheme(MButtonCtrl *ctl)
-{
- if (ThemeSupport()) {
- if (ctl->hThemeButton) {
- MyCloseThemeData(ctl->hThemeButton);
- ctl->hThemeButton = NULL;
- }
- if (ctl->hThemeToolbar) {
- MyCloseThemeData(ctl->hThemeToolbar);
- ctl->hThemeToolbar = NULL;
- }
- }
-}
-
-static void LoadTheme(MButtonCtrl *ctl)
-{
- if (ThemeSupport()) {
- DestroyTheme(ctl);
- ctl->hThemeButton = MyOpenThemeData(ctl->hwnd, L"BUTTON");
- ctl->hThemeToolbar = MyOpenThemeData(ctl->hwnd, L"TOOLBAR");
- ctl->bThemed = TRUE;
- }
-}
-
-static TBStateConvert2Flat(int state)
-{
- switch (state) {
- case PBS_NORMAL:
- return TS_NORMAL;
- case PBS_HOT:
- return TS_HOT;
- case PBS_PRESSED:
- return TS_PRESSED;
- case PBS_DISABLED:
- return TS_DISABLED;
- case PBS_DEFAULTED:
- return TS_NORMAL;
- }
- return TS_NORMAL;
-}
-
-static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint)
-{
- if (hdcPaint) {
- HDC hdcMem;
- HBITMAP hbmMem;
- HDC hOld;
- RECT rcClient;
- HFONT hOldFont = 0;
-
- GetClientRect(ctl->hwnd, &rcClient);
- hdcMem = CreateCompatibleDC(hdcPaint);
- hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
- hOld = SelectObject(hdcMem, hbmMem);
-
- // If its a push button, check to see if it should stay pressed
- if (ctl->pushBtn && ctl->pbState)
- ctl->stateId = PBS_PRESSED;
-
- // Draw the flat button
- if (ctl->flatBtn) {
- if (ctl->hThemeToolbar && ctl->bThemed) {
- RECT rc = rcClient;
- int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
- if (MyIsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
- MyDrawThemeParentBackground(ctl->hwnd, hdcMem, &rc);
- }
- MyDrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rc, &rc);
- } else {
- HBRUSH hbr;
- RECT rc = rcClient;
-
- if (ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT)
- hbr = GetSysColorBrush(COLOR_3DFACE);
- else {
- HDC dc;
- HWND hwndParent;
-
- hwndParent = GetParent(ctl->hwnd);
- dc = GetDC(hwndParent);
- hbr = (HBRUSH) SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM) dc, (LPARAM) hwndParent);
- ReleaseDC(hwndParent, dc);
- }
- if (hbr) {
- FillRect(hdcMem, &rc, hbr);
- DeleteObject(hbr);
- }
- if (ctl->stateId == PBS_HOT || ctl->focus) {
- if (ctl->pbState)
- DrawEdge(hdcMem, &rc, EDGE_ETCHED, BF_RECT | BF_SOFT);
- else
- DrawEdge(hdcMem, &rc, BDR_RAISEDOUTER, BF_RECT | BF_SOFT);
- } else if (ctl->stateId == PBS_PRESSED)
- DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT | BF_SOFT);
- }
- } else {
- // Draw background/border
- if (ctl->hThemeButton && ctl->bThemed) {
- int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
- if (MyIsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
- MyDrawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient);
- }
- MyDrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, &rcClient, &rcClient);
- } else {
- UINT uState = DFCS_BUTTONPUSH | ((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0) | ((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0);
- if (ctl->defbutton && ctl->stateId == PBS_NORMAL)
- uState |= DLGC_DEFPUSHBUTTON;
- DrawFrameControl(hdcMem, &rcClient, DFC_BUTTON, uState);
- }
-
- // Draw focus rectangle if button has focus
- if (ctl->focus) {
- RECT focusRect = rcClient;
- InflateRect(&focusRect, -3, -3);
- DrawFocusRect(hdcMem, &focusRect);
- }
- }
-
- // If we have an icon or a bitmap, ignore text and only draw the image on the button
- if (ctl->hIcon || ctl->hIconPrivate || ctl->iIcon) {
- int ix = (rcClient.right - rcClient.left) / 2 - (g_cxsmIcon / 2);
- int iy = (rcClient.bottom - rcClient.top) / 2 - (g_cxsmIcon / 2);
- HICON hIconNew = ctl->hIconPrivate != 0 ? ctl->hIconPrivate : ctl->hIcon;
- if (lstrlenA(ctl->szText) == 0) {
- if (ctl->iIcon)
- ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, g_cxsmIcon, g_cysmIcon, CLR_NONE, CLR_NONE, ILD_NORMAL);
- else
- DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
- ctl->sLabel.cx = ctl->sLabel.cy = 0;
- } else {
- hOldFont = SelectObject(hdcMem, ctl->hFont);
- GetTextExtentPoint32A(hdcMem, ctl->szText, lstrlenA(ctl->szText), &ctl->sLabel);
- ix = (rcClient.right - rcClient.left) / 2 - ((g_cxsmIcon + ctl->sLabel.cx + 4) / 2);
- if (ctl->iIcon)
- ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, g_cxsmIcon, g_cysmIcon, CLR_NONE, CLR_NONE, ILD_NORMAL);
- else
- DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
- ctl->sLabel.cx += (g_cxsmIcon + 4);
- }
- } else if (ctl->hBitmap) {
- BITMAP bminfo;
- int ix, iy;
-
- GetObject(ctl->hBitmap, sizeof(bminfo), &bminfo);
- ix = (rcClient.right - rcClient.left) / 2 - (bminfo.bmWidth / 2);
- iy = (rcClient.bottom - rcClient.top) / 2 - (bminfo.bmHeight / 2);
- if (ctl->stateId == PBS_PRESSED) {
- ix++;
- iy++;
- }
- DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->hBitmap, 0, ix, iy, bminfo.bmWidth, bminfo.bmHeight, IsWindowEnabled(ctl->hwnd) ? DST_BITMAP : DST_BITMAP | DSS_DISABLED);
- }
- if (GetWindowTextLengthA(ctl->hwnd)) {
- // Draw the text and optinally the arrow
- RECT rcText;
-
- CopyRect(&rcText, &rcClient);
- SetBkMode(hdcMem, TRANSPARENT);
- // XP w/themes doesn't used the glossy disabled text. Is it always using COLOR_GRAYTEXT? Seems so.
- SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_GRAYTEXT));
- if (ctl->arrow)
- DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->arrow, 0, rcClient.right - rcClient.left - 5 - g_cxsmIcon + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), (rcClient.bottom - rcClient.top) / 2 - g_cysmIcon / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON : DST_ICON | DSS_DISABLED);
- SelectObject(hdcMem, ctl->hFont);
- DrawStateA(hdcMem, NULL, NULL, (LPARAM) ctl->szText, 0, (rcText.right - rcText.left - ctl->sLabel.cx) / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0) + g_cxsmIcon + 4, ctl->hThemeButton ? (rcText.bottom - rcText.top - ctl->sLabel.cy) / 2 + 1 : (rcText.bottom - rcText.top - ctl->sLabel.cy) / 2 + (ctl->stateId == PBS_PRESSED ? 1 : 0), ctl->sLabel.cx, ctl->sLabel.cy, IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED);
- }
- if (hOldFont)
- SelectObject(hdcMem, hOldFont);
- BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY);
- SelectObject(hdcMem, hOld);
- DeleteObject(hbmMem);
- DeleteDC(hdcMem);
- }
-}
-
-static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- MButtonCtrl *bct = (MButtonCtrl *) GetWindowLong(hwndDlg, 0);
- switch (msg) {
- case WM_NCCREATE:
- {
- SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLong(hwndDlg, GWL_STYLE) | BS_OWNERDRAW);
- bct = malloc(sizeof(MButtonCtrl));
- if (bct == NULL)
- return FALSE;
- bct->hwnd = hwndDlg;
- bct->stateId = PBS_NORMAL;
- bct->focus = 0;
- bct->hFont = GetStockObject(DEFAULT_GUI_FONT);
- bct->arrow = NULL;
- bct->defbutton = 0;
- bct->hIcon = bct->hIconPrivate = 0;
- bct->iIcon = 0;
- bct->hIml = 0;
- bct->hBitmap = NULL;
- bct->pushBtn = 0;
- bct->pbState = 0;
- bct->hThemeButton = NULL;
- bct->hThemeToolbar = NULL;
- bct->cHot = 0;
- bct->flatBtn = 0;
- bct->bThemed = FALSE;
- LoadTheme(bct);
- SetWindowLong(hwndDlg, 0, (LONG) bct);
- if (((CREATESTRUCTA *) lParam)->lpszName)
- SetWindowTextA(hwndDlg, ((CREATESTRUCTA *) lParam)->lpszName);
- return TRUE;
- }
- case WM_DESTROY:
- {
- if (bct) {
- EnterCriticalSection(&csTips);
- if (hwndToolTips) {
- TOOLINFO ti;
-
- ZeroMemory(&ti, sizeof(ti));
- ti.cbSize = sizeof(ti);
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT) 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);
- LeaveCriticalSection(&csTips);
- DestroyTheme(bct);
- free(bct);
- }
- SetWindowLong(hwndDlg, 0, (LONG) NULL);
- break; // DONT! fall thru
- }
- case WM_SETTEXT:
- {
- bct->cHot = 0;
- if ((char*) lParam) {
- char *tmp = (char *) lParam;
- while (*tmp) {
- if (*tmp == '&' && *(tmp + 1)) {
- bct->cHot = tolower(*(tmp + 1));
- break;
- }
- tmp++;
- }
- InvalidateRect(bct->hwnd, NULL, TRUE);
- strncpy(bct->szText, (char*) lParam, 127);
- bct->szText[127] = 0;
- }
- break;
- }
- 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;
- }
- break;
- case WM_THEMECHANGED:
- {
- // themed changed, reload theme object
- if (bct->bThemed)
- LoadTheme(bct);
- InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
- break;
- }
- case WM_SETFONT:
- // remember the font so we can use it later
- {
- bct->hFont = (HFONT) wParam; // maybe we should redraw?
- break;
- }
- case WM_NCPAINT:
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdcPaint;
-
- hdcPaint = BeginPaint(hwndDlg, &ps);
- if (hdcPaint) {
- PaintWorker(bct, hdcPaint);
- EndPaint(hwndDlg, &ps);
- }
- break;
- }
- case BM_SETIMAGE:
- bct->hIml = 0;
- bct->iIcon = 0;
- if (wParam == IMAGE_ICON) {
- ICONINFO ii;
- BITMAP bm;
-
- if (bct->hIconPrivate)
- DestroyIcon(bct->hIconPrivate);
-
- GetIconInfo((HICON) lParam, &ii);
- GetObject(ii.hbmColor, sizeof(bm), &bm);
- if (bm.bmWidth > g_cxsmIcon || bm.bmHeight > g_cysmIcon) {
- HIMAGELIST hImageList;
- hImageList = ImageList_Create(g_cxsmIcon, g_cysmIcon, IsWinVerXPPlus() ? 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 {
- bct->hIcon = (HICON) lParam;
- bct->hIconPrivate = 0;
- }
-
- DeleteObject(ii.hbmMask);
- DeleteObject(ii.hbmColor);
- bct->hBitmap = NULL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- } else if (wParam == IMAGE_BITMAP) {
- bct->hBitmap = (HBITMAP) lParam;
- if (bct->hIconPrivate)
- DestroyIcon(bct->hIconPrivate);
- bct->hIcon = bct->hIconPrivate = NULL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
- case BM_SETPRIVATEICON:
- bct->hIml = 0;
- bct->iIcon = 0; {
- if (bct->hIconPrivate)
- DestroyIcon(bct->hIconPrivate);
- bct->hIconPrivate = DuplicateIcon(hInst, (HICON) lParam);
- bct->hIcon = 0;
- break;
- }
- case BM_SETIMLICON:
- {
- if (bct->hIconPrivate)
- DestroyIcon(bct->hIconPrivate);
- bct->hIml = (HIMAGELIST) wParam;
- bct->iIcon = (int) lParam;
- bct->hIcon = bct->hIconPrivate = 0;
- 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
- if (wParam) {
- //if (!bct->arrow) bct->arrow = (HICON) LoadImage(g_hInst, MAKEINTRESOURCE(IDI_MINIMIZE), IMAGE_ICON, g_cxsmIcon, g_cysmIcon, 0);
- } else {
- if (bct->arrow) {
- DestroyIcon(bct->arrow);
- bct->arrow = NULL;
- }
- }
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETDEFAULT:
- bct->defbutton = wParam ? 1 : 0;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETASPUSHBTN:
- bct->pushBtn = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETASFLATBTN:
- bct->flatBtn = lParam == 0 ? 1 : 0;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETASFLATBTN + 10:
- bct->bThemed = lParam ? TRUE : FALSE;
- break;
- case BUTTONADDTOOLTIP:
- {
- TOOLINFOA ti;
-
- if (!(char*) wParam)
- break;
- EnterCriticalSection(&csTips);
- if (!hwndToolTips) {
- hwndToolTips = CreateWindowExA(WS_EX_TOPMOST, TOOLTIPS_CLASSA, "", WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
- }
- ZeroMemory(&ti, sizeof(ti));
- ti.cbSize = sizeof(ti);
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT) 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) bct->hwnd;
- ti.lpszText = (char*) wParam;
- SendMessageA(hwndToolTips, TTM_ADDTOOLA, 0, (LPARAM) &ti);
- LeaveCriticalSection(&csTips);
- 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_WINDOWPOSCHANGED:
- 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_LBUTTONDOWN:
- {
- if (bct->stateId != PBS_DISABLED) {
- // don't change states if disabled
- bct->stateId = PBS_PRESSED;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
- }
- case WM_LBUTTONUP:
- {
- 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 (msg == WM_LBUTTONUP)
- bct->stateId = PBS_HOT;
- else
- bct->stateId = PBS_NORMAL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- // Tell your daddy you got clicked.
- 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);
- }
- // Call timer, used to start cheesy TrackMouseEvent faker
- SetTimer(hwndDlg, BUTTON_POLLID, BUTTON_POLLDELAY, NULL);
- break;
- case WM_TIMER:
- // use a timer to check if they have did a mouseout
- {
- if (wParam == BUTTON_POLLID) {
- RECT rc;
- POINT pt;
- GetWindowRect(hwndDlg, &rc);
- GetCursorPos(&pt);
- if (!PtInRect(&rc, pt)) {
- // mouse must be gone, trigger mouse leave
- PostMessage(hwndDlg, WM_MOUSELEAVE, 0, 0L);
- KillTimer(hwndDlg, BUTTON_POLLID);
- }
- }
- break;
- }
- case WM_ERASEBKGND:
- return 1;
- }
- return DefWindowProc(hwndDlg, msg, wParam, lParam);
-}
diff --git a/plugins/TopToolBar/CLCButton.cpp b/plugins/TopToolBar/CLCButton.cpp
new file mode 100644
index 0000000000..c2b197f7dc
--- /dev/null
+++ b/plugins/TopToolBar/CLCButton.cpp
@@ -0,0 +1,625 @@
+/*
+Miranda IM
+Copyright (C) 2002 Robert Rainwater
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "common.h"
+
+// TODO:
+// - Support for bitmap buttons (simple call to DrawIconEx())
+extern HINSTANCE hInst;
+LONG g_cxsmIcon, g_cysmIcon;
+
+static LRESULT CALLBACK TSButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+
+struct MButtonCtrl
+{
+ HWND hwnd;
+ int stateId; // button state
+ int focus; // has focus (1 or 0)
+ HFONT hFont; // font
+ HICON arrow; // uses down arrow
+ int defbutton; // default button
+ HICON hIcon, hIconPrivate;
+ HBITMAP hBitmap;
+ int pushBtn;
+ int pbState;
+ HANDLE hThemeButton;
+ HANDLE hThemeToolbar;
+ BOOL bThemed;
+ char cHot;
+ int flatBtn;
+ char szText[128];
+ SIZE sLabel;
+ HIMAGELIST hIml;
+ int iIcon;
+};
+
+// External theme methods and properties
+static HMODULE themeAPIHandle = NULL; // handle to uxtheme.dll
+static HANDLE (WINAPI *MyOpenThemeData)(HWND, LPCWSTR);
+static HRESULT (WINAPI *MyCloseThemeData)(HANDLE);
+static BOOL (WINAPI *MyIsThemeBackgroundPartiallyTransparent)(HANDLE, int,
+ int);
+static HRESULT (WINAPI *MyDrawThemeParentBackground)(HWND, HDC, RECT *);
+static HRESULT (WINAPI *MyDrawThemeBackground)(HANDLE, HDC, int, int,
+ const RECT *, const RECT *);
+static HRESULT (WINAPI *MyDrawThemeText)(HANDLE, HDC, int, int, LPCWSTR, int,
+ DWORD, DWORD, const RECT *);
+
+static CRITICAL_SECTION csTips;
+static HWND hwndToolTips = NULL;
+
+// Used for our own cheap TrackMouseEvent
+#define BUTTON_POLLID 100
+#define BUTTON_POLLDELAY 50
+
+#define MGPROC(x) GetProcAddress(themeAPIHandle, x)
+static int ThemeSupport()
+{
+ if (IsWinVerXPPlus()) {
+ if (!themeAPIHandle) {
+ themeAPIHandle = GetModuleHandleA("uxtheme");
+ if (themeAPIHandle) {
+ MyOpenThemeData = (HANDLE(WINAPI *)(HWND, LPCWSTR))MGPROC("OpenThemeData");
+ MyCloseThemeData = (HRESULT(WINAPI *)(HANDLE))MGPROC("CloseThemeData");
+ MyIsThemeBackgroundPartiallyTransparent = (BOOL(WINAPI *)(HANDLE, int, int))MGPROC("IsThemeBackgroundPartiallyTransparent");
+ MyDrawThemeParentBackground = (HRESULT(WINAPI *)(HWND, HDC, RECT *))MGPROC("DrawThemeParentBackground");
+ MyDrawThemeBackground = (HRESULT(WINAPI *)(HANDLE, HDC, int, int, const RECT *, const RECT *))MGPROC("DrawThemeBackground");
+ MyDrawThemeText = (HRESULT(WINAPI *)(HANDLE, HDC, int, int, LPCWSTR, int, DWORD, DWORD, const RECT *))MGPROC("DrawThemeText");
+ }
+ }
+ // Make sure all of these methods are valid (i would hope either all or none work)
+ if (MyOpenThemeData && MyCloseThemeData && MyIsThemeBackgroundPartiallyTransparent && MyDrawThemeParentBackground && MyDrawThemeBackground && MyDrawThemeText)
+ return 1;
+ }
+ return 0;
+}
+
+static void DestroyTheme(MButtonCtrl *ctl)
+{
+ if (ThemeSupport()) {
+ if (ctl->hThemeButton) {
+ MyCloseThemeData(ctl->hThemeButton);
+ ctl->hThemeButton = NULL;
+ }
+ if (ctl->hThemeToolbar) {
+ MyCloseThemeData(ctl->hThemeToolbar);
+ ctl->hThemeToolbar = NULL;
+ }
+ }
+}
+
+static void LoadTheme(MButtonCtrl *ctl)
+{
+ if (ThemeSupport()) {
+ DestroyTheme(ctl);
+ ctl->hThemeButton = MyOpenThemeData(ctl->hwnd, L"BUTTON");
+ ctl->hThemeToolbar = MyOpenThemeData(ctl->hwnd, L"TOOLBAR");
+ ctl->bThemed = TRUE;
+ }
+}
+
+static int TBStateConvert2Flat(int state)
+{
+ switch (state) {
+ case PBS_NORMAL: return TS_NORMAL;
+ case PBS_HOT: return TS_HOT;
+ case PBS_PRESSED: return TS_PRESSED;
+ case PBS_DISABLED: return TS_DISABLED;
+ case PBS_DEFAULTED: return TS_NORMAL;
+ }
+ return TS_NORMAL;
+}
+
+static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint)
+{
+ if (hdcPaint == NULL)
+ return;
+
+ HFONT hOldFont = NULL;
+ RECT rcClient;
+ GetClientRect(ctl->hwnd, &rcClient);
+ HDC hdcMem = CreateCompatibleDC(hdcPaint);
+ HBITMAP hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
+ HDC hOld = (HDC)SelectObject(hdcMem, hbmMem);
+
+ // If its a push button, check to see if it should stay pressed
+ if (ctl->pushBtn && ctl->pbState)
+ ctl->stateId = PBS_PRESSED;
+
+ // Draw the flat button
+ if (ctl->flatBtn) {
+ if (ctl->hThemeToolbar && ctl->bThemed) {
+ RECT rc = rcClient;
+ int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
+ if (MyIsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state)))
+ MyDrawThemeParentBackground(ctl->hwnd, hdcMem, &rc);
+
+ MyDrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rc, &rc);
+ }
+ else {
+ HBRUSH hbr;
+ RECT rc = rcClient;
+
+ if (ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT)
+ hbr = GetSysColorBrush(COLOR_3DFACE);
+ else {
+ HWND hwndParent = GetParent(ctl->hwnd);
+ HDC dc = GetDC(hwndParent);
+ hbr = (HBRUSH) SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM) dc, (LPARAM) hwndParent);
+ ReleaseDC(hwndParent, dc);
+ }
+ if (hbr) {
+ FillRect(hdcMem, &rc, hbr);
+ DeleteObject(hbr);
+ }
+ if (ctl->stateId == PBS_HOT || ctl->focus) {
+ if (ctl->pbState)
+ DrawEdge(hdcMem, &rc, EDGE_ETCHED, BF_RECT | BF_SOFT);
+ else
+ DrawEdge(hdcMem, &rc, BDR_RAISEDOUTER, BF_RECT | BF_SOFT);
+ }
+ else if (ctl->stateId == PBS_PRESSED)
+ DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT | BF_SOFT);
+ }
+ }
+ else {
+ // Draw background/border
+ if (ctl->hThemeButton && ctl->bThemed) {
+ int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
+ if (MyIsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
+ MyDrawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient);
+ }
+ MyDrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, &rcClient, &rcClient);
+ }
+ else {
+ UINT uState = DFCS_BUTTONPUSH | ((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0) | ((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0);
+ if (ctl->defbutton && ctl->stateId == PBS_NORMAL)
+ uState |= DLGC_DEFPUSHBUTTON;
+ DrawFrameControl(hdcMem, &rcClient, DFC_BUTTON, uState);
+ }
+
+ // Draw focus rectangle if button has focus
+ if (ctl->focus) {
+ RECT focusRect = rcClient;
+ InflateRect(&focusRect, -3, -3);
+ DrawFocusRect(hdcMem, &focusRect);
+ }
+ }
+
+ // If we have an icon or a bitmap, ignore text and only draw the image on the button
+ if (ctl->hIcon || ctl->hIconPrivate || ctl->iIcon) {
+ int ix = (rcClient.right - rcClient.left) / 2 - (g_cxsmIcon / 2);
+ int iy = (rcClient.bottom - rcClient.top) / 2 - (g_cxsmIcon / 2);
+ HICON hIconNew = ctl->hIconPrivate != 0 ? ctl->hIconPrivate : ctl->hIcon;
+ if (lstrlenA(ctl->szText) == 0) {
+ if (ctl->iIcon)
+ ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, g_cxsmIcon, g_cysmIcon, CLR_NONE, CLR_NONE, ILD_NORMAL);
+ else
+ DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
+ ctl->sLabel.cx = ctl->sLabel.cy = 0;
+ }
+ else {
+ hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
+ GetTextExtentPoint32A(hdcMem, ctl->szText, lstrlenA(ctl->szText), &ctl->sLabel);
+ ix = (rcClient.right - rcClient.left) / 2 - ((g_cxsmIcon + ctl->sLabel.cx + 4) / 2);
+ if (ctl->iIcon)
+ ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, g_cxsmIcon, g_cysmIcon, CLR_NONE, CLR_NONE, ILD_NORMAL);
+ else
+ DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
+ ctl->sLabel.cx += (g_cxsmIcon + 4);
+ }
+ }
+ else if (ctl->hBitmap) {
+ BITMAP bminfo;
+ int ix, iy;
+
+ GetObject(ctl->hBitmap, sizeof(bminfo), &bminfo);
+ ix = (rcClient.right - rcClient.left) / 2 - (bminfo.bmWidth / 2);
+ iy = (rcClient.bottom - rcClient.top) / 2 - (bminfo.bmHeight / 2);
+ if (ctl->stateId == PBS_PRESSED) {
+ ix++;
+ iy++;
+ }
+ DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->hBitmap, 0, ix, iy, bminfo.bmWidth, bminfo.bmHeight, IsWindowEnabled(ctl->hwnd) ? DST_BITMAP : DST_BITMAP | DSS_DISABLED);
+ }
+
+ if (GetWindowTextLengthA(ctl->hwnd)) {
+ // Draw the text and optinally the arrow
+ RECT rcText;
+
+ CopyRect(&rcText, &rcClient);
+ SetBkMode(hdcMem, TRANSPARENT);
+ // XP w/themes doesn't used the glossy disabled text. Is it always using COLOR_GRAYTEXT? Seems so.
+ SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_GRAYTEXT));
+ if (ctl->arrow)
+ DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->arrow, 0, rcClient.right - rcClient.left - 5 - g_cxsmIcon + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), (rcClient.bottom - rcClient.top) / 2 - g_cysmIcon / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON : DST_ICON | DSS_DISABLED);
+ SelectObject(hdcMem, ctl->hFont);
+ DrawStateA(hdcMem, NULL, NULL, (LPARAM) ctl->szText, 0, (rcText.right - rcText.left - ctl->sLabel.cx) / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0) + g_cxsmIcon + 4, ctl->hThemeButton ? (rcText.bottom - rcText.top - ctl->sLabel.cy) / 2 + 1 : (rcText.bottom - rcText.top - ctl->sLabel.cy) / 2 + (ctl->stateId == PBS_PRESSED ? 1 : 0), ctl->sLabel.cx, ctl->sLabel.cy, IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED);
+ }
+
+ if (hOldFont)
+ SelectObject(hdcMem, hOldFont);
+
+ BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY);
+ SelectObject(hdcMem, hOld);
+ DeleteObject(hbmMem);
+ DeleteDC(hdcMem);
+}
+
+static LRESULT CALLBACK TSButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ MButtonCtrl *bct = (MButtonCtrl *) GetWindowLongPtr(hwndDlg, 0);
+ switch (msg) {
+ case WM_NCCREATE:
+ SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLongPtr(hwndDlg, GWL_STYLE) | BS_OWNERDRAW);
+ bct = ( MButtonCtrl* )malloc(sizeof(MButtonCtrl));
+ if (bct == NULL)
+ return FALSE;
+
+ bct->hwnd = hwndDlg;
+ bct->stateId = PBS_NORMAL;
+ bct->focus = 0;
+ bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+ bct->arrow = NULL;
+ bct->defbutton = 0;
+ bct->hIcon = bct->hIconPrivate = 0;
+ bct->iIcon = 0;
+ bct->hIml = 0;
+ bct->hBitmap = NULL;
+ bct->pushBtn = 0;
+ bct->pbState = 0;
+ bct->hThemeButton = NULL;
+ bct->hThemeToolbar = NULL;
+ bct->cHot = 0;
+ bct->flatBtn = 0;
+ bct->bThemed = FALSE;
+ LoadTheme(bct);
+ SetWindowLong(hwndDlg, 0, (LONG) bct);
+ if (((CREATESTRUCTA *) lParam)->lpszName)
+ SetWindowTextA(hwndDlg, ((CREATESTRUCTA *) lParam)->lpszName);
+ return TRUE;
+
+ case WM_SETTEXT:
+ bct->cHot = 0;
+ if ((char*) lParam) {
+ char *tmp = (char *) lParam;
+ while (*tmp) {
+ if (*tmp == '&' && *(tmp + 1)) {
+ bct->cHot = tolower(*(tmp + 1));
+ break;
+ }
+ tmp++;
+ }
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ strncpy(bct->szText, (char*) lParam, 127);
+ bct->szText[127] = 0;
+ }
+ break;
+
+ 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;
+ }
+ break;
+
+ case WM_THEMECHANGED:
+ // themed changed, reload theme object
+ if (bct->bThemed)
+ LoadTheme(bct);
+ InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
+ break;
+
+ case WM_SETFONT:
+ // remember the font so we can use it later
+ bct->hFont = (HFONT) wParam; // maybe we should redraw?
+ break;
+
+ case WM_NCPAINT:
+ case WM_PAINT:
+ {
+ PAINTSTRUCT ps;
+ HDC hdcPaint;
+
+ hdcPaint = BeginPaint(hwndDlg, &ps);
+ if (hdcPaint) {
+ PaintWorker(bct, hdcPaint);
+ EndPaint(hwndDlg, &ps);
+ }
+ }
+ break;
+
+ case BM_SETIMAGE:
+ bct->hIml = 0;
+ bct->iIcon = 0;
+ if (wParam == IMAGE_ICON) {
+ if (bct->hIconPrivate)
+ DestroyIcon(bct->hIconPrivate);
+
+ ICONINFO ii;
+ GetIconInfo((HICON) lParam, &ii);
+
+ BITMAP bm;
+ GetObject(ii.hbmColor, sizeof(bm), &bm);
+ if (bm.bmWidth > g_cxsmIcon || bm.bmHeight > g_cysmIcon) {
+ HIMAGELIST hImageList;
+ hImageList = ImageList_Create(g_cxsmIcon, g_cysmIcon, IsWinVerXPPlus() ? 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 {
+ bct->hIcon = (HICON) lParam;
+ bct->hIconPrivate = 0;
+ }
+
+ DeleteObject(ii.hbmMask);
+ DeleteObject(ii.hbmColor);
+ bct->hBitmap = NULL;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ }
+ else if (wParam == IMAGE_BITMAP) {
+ bct->hBitmap = (HBITMAP) lParam;
+ if (bct->hIconPrivate)
+ DestroyIcon(bct->hIconPrivate);
+ bct->hIcon = bct->hIconPrivate = NULL;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ }
+ break;
+
+ case BM_SETPRIVATEICON:
+ bct->hIml = 0;
+ bct->iIcon = 0;
+ if (bct->hIconPrivate)
+ DestroyIcon(bct->hIconPrivate);
+ bct->hIconPrivate = DuplicateIcon(hInst, (HICON) lParam);
+ bct->hIcon = 0;
+ break;
+
+ case BM_SETIMLICON:
+ if (bct->hIconPrivate)
+ DestroyIcon(bct->hIconPrivate);
+ bct->hIml = (HIMAGELIST) wParam;
+ bct->iIcon = (int) lParam;
+ bct->hIcon = bct->hIconPrivate = 0;
+ 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
+ if (wParam) {
+ //if (!bct->arrow) bct->arrow = (HICON) LoadImage(g_hInst, MAKEINTRESOURCE(IDI_MINIMIZE), IMAGE_ICON, g_cxsmIcon, g_cysmIcon, 0);
+ }
+ else {
+ if (bct->arrow) {
+ DestroyIcon(bct->arrow);
+ bct->arrow = NULL;
+ }
+ }
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETDEFAULT:
+ bct->defbutton = wParam ? 1 : 0;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETASPUSHBTN:
+ bct->pushBtn = 1;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETASFLATBTN:
+ bct->flatBtn = lParam == 0 ? 1 : 0;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETASFLATBTN + 10:
+ bct->bThemed = lParam ? TRUE : FALSE;
+ break;
+
+ case BUTTONADDTOOLTIP:
+ if (wParam) {
+ EnterCriticalSection(&csTips);
+ if (!hwndToolTips)
+ hwndToolTips = CreateWindowExA(WS_EX_TOPMOST, TOOLTIPS_CLASSA, "", WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
+
+ TOOLINFOA ti = { 0 };
+ ti.cbSize = sizeof(ti);
+ ti.uFlags = TTF_IDISHWND;
+ ti.hwnd = bct->hwnd;
+ ti.uId = (UINT) 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) bct->hwnd;
+ ti.lpszText = (char*) wParam;
+ SendMessageA(hwndToolTips, TTM_ADDTOOLA, 0, (LPARAM) &ti);
+ LeaveCriticalSection(&csTips);
+ }
+ 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_WINDOWPOSCHANGED:
+ 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_LBUTTONDOWN:
+ if (bct->stateId != PBS_DISABLED) {
+ // don't change states if disabled
+ bct->stateId = PBS_PRESSED;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ }
+ break;
+
+ case WM_LBUTTONUP:
+ 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 (msg == WM_LBUTTONUP)
+ bct->stateId = PBS_HOT;
+ else
+ bct->stateId = PBS_NORMAL;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ }
+ // Tell your daddy you got clicked.
+ 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);
+ }
+
+ // Call timer, used to start cheesy TrackMouseEvent faker
+ SetTimer(hwndDlg, BUTTON_POLLID, BUTTON_POLLDELAY, NULL);
+ break;
+ case WM_TIMER:
+ // use a timer to check if they have did a mouseout
+ if (wParam == BUTTON_POLLID) {
+ RECT rc;
+ POINT pt;
+ GetWindowRect(hwndDlg, &rc);
+ GetCursorPos(&pt);
+ if (!PtInRect(&rc, pt)) {
+ // mouse must be gone, trigger mouse leave
+ PostMessage(hwndDlg, WM_MOUSELEAVE, 0, 0L);
+ KillTimer(hwndDlg, BUTTON_POLLID);
+ }
+ }
+ break;
+
+ case WM_ERASEBKGND:
+ return 1;
+
+ case WM_DESTROY:
+ if (bct) {
+ EnterCriticalSection(&csTips);
+ if (hwndToolTips) {
+ TOOLINFO ti = { 0 };
+ ti.cbSize = sizeof(ti);
+ ti.uFlags = TTF_IDISHWND;
+ ti.hwnd = bct->hwnd;
+ ti.uId = (UINT) 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);
+ LeaveCriticalSection(&csTips);
+ DestroyTheme(bct);
+ free(bct);
+ }
+ SetWindowLong(hwndDlg, 0, (LONG) NULL);
+ break; // DONT! fall thru
+ }
+
+ return DefWindowProc(hwndDlg, msg, wParam, lParam);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+int LoadCLCButtonModule(void)
+{
+ g_cxsmIcon = GetSystemMetrics(SM_CXSMICON);
+ g_cysmIcon = GetSystemMetrics(SM_CYSMICON);
+
+ WNDCLASSEXA wc = { 0 };
+ wc.cbSize = sizeof(wc);
+ wc.lpszClassName = "CLCButtonClass";
+ wc.lpfnWndProc = TSButtonWndProc;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.cbWndExtra = sizeof(MButtonCtrl *);
+ wc.hbrBackground = 0;
+ wc.style = CS_GLOBALCLASS;
+ RegisterClassExA(&wc);
+ InitializeCriticalSection(&csTips);
+ return 0;
+}
+
+int UnloadTSButtonModule(WPARAM wParam, LPARAM lParam)
+{
+ DeleteCriticalSection(&csTips);
+ return 0;
+}
diff --git a/plugins/TopToolBar/InternalButtons.c b/plugins/TopToolBar/InternalButtons.c
deleted file mode 100644
index 320e8e1d59..0000000000
--- a/plugins/TopToolBar/InternalButtons.c
+++ /dev/null
@@ -1,436 +0,0 @@
-
-#include "common.h"
-#pragma hdrstop
-
-#define TTBI_GROUPSHOWHIDE "TTBInternal/GroupShowHide"
-#define TTBI_SOUNDSONOFF "TTBInternal/SoundsOnOFF"
-#define TTBI_OPTIONSBUTT "TTBInternal/OptionsBUTT"
-#define TTBI_MAINMENUBUTT "TTBInternal/MainMenuBUTT"
-#define TTBI_MINIMIZEBUTT "TTBInternal/MinimizeBUTT"
-#define TTBI_FINDADDBUTT "TTBInternal/FindAddBUTT"
-
-int LoadInternalButtons();
-int UnLoadInternalButtons();
-extern HINSTANCE hInst;
-
-HANDLE hSettingChangedHook;
-
-static HBITMAP OnlineUp,OnlineDn,GroupsUp,GroupsDn,SoundsUp;
-static HBITMAP SoundsDn,hbOptUp,hbOptDn,testsearch;
-static HBITMAP MainMenuUp,MainMenuDn;
-static HBITMAP MinimizeUp,MinimizeDn;
-static HBITMAP FindUserUp,FindUserDn;
-
-static int ShowOnline,ShowGroups,SoundsEnabled;
-static HANDLE hOnlineBut,hGroupBut,hSoundsBut,hOptionsBut,hMainMenuBut;
-static HANDLE hMinimizeBut;
-static HANDLE hFindUsers;
-
-static HANDLE OnSettingChg;
-
-static HWND hwndContactTree;
-
-int OnSettingChanging(WPARAM wParam,LPARAM lParam)
-{
- if (wParam!=0){return(0);};
- {
- DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING *)lParam;
- if (dbcws==NULL){return(0);};
-
- if (!strcmp(dbcws->szModule,"CList"))
- {
-
- if (!strcmp(dbcws->szSetting,"HideOffline"))
- {
- int val=dbcws->value.bVal;
-
- //OutputDebugStr("==>TopToolBar HideOffline set it\r\n");
-
- CallService(MS_TTB_SETBUTTONSTATE,(WPARAM)hOnlineBut,(LPARAM)(val)?TTBST_PUSHED:TTBST_RELEASED);
-
- CallService(MS_TTB_SETBUTTONOPTIONS,MAKEWPARAM(TTBO_TIPNAME,hOnlineBut),
- (LPARAM)((!val)?Translate("Hide Offline Users"):Translate("Show All Users")));
-
- return(0);
- };
-
- if (!strcmp(dbcws->szSetting,"UseGroups"))
- {
- int val=dbcws->value.bVal;
- //int val=GetWindowLong(hwndContactTree,GWL_STYLE)&CLS_USEGROUPS;
-
- CallService(MS_TTB_SETBUTTONSTATE,(WPARAM)hGroupBut,(LPARAM)((val)?TTBST_PUSHED:TTBST_RELEASED));
-
- return(0);
- };
- };
- if (!strcmp(dbcws->szModule,"Skin"))
- {
- if (!strcmp(dbcws->szSetting,"UseSound"))
- {
- int val=dbcws->value.bVal;
-
- CallService(MS_TTB_SETBUTTONSTATE,(WPARAM)hSoundsBut,(LPARAM)(val)?TTBST_PUSHED:TTBST_RELEASED);
-
- return(0);
- };
-
- };
- }
- return(0);
-};
-INT_PTR TTBInternalFindAddButt(WPARAM wParam,LPARAM lParam)
-{
- //Sleep(100);
-
- CallService("FindAdd/FindAddCommand",0,0);
- CallService(MS_TTB_SETBUTTONSTATE,(WPARAM)hFindUsers,TTBST_RELEASED);
- return(0);
-};
-
-
-INT_PTR TTBInternalMinimizeButt(WPARAM wParam,LPARAM lParam)
-{
- Sleep(30);
- CallService(MS_TTB_SETBUTTONSTATE,(WPARAM)hMinimizeBut,TTBST_RELEASED);
- Sleep(30);
- CallService(MS_CLIST_SHOWHIDE,0,0);
- return(0);
-};
-
-INT_PTR TTBInternalMainMenuButt(WPARAM wParam,LPARAM lParam)
-{
- POINT pt;
- //CallService("Options/OptionsCommand",0,0);
- HMENU hMenu=(HMENU)CallService(MS_CLIST_MENUGETMAIN,0,0);
-// hMenu=(HMENU)CallService(MS_CLIST_MENUGETSTATUS,0,0);
-
- GetCursorPos(&pt);
- TrackPopupMenu(hMenu,TPM_TOPALIGN|TPM_LEFTALIGN|TPM_RIGHTBUTTON,pt.x,pt.y,0,(HWND)CallService(MS_CLUI_GETHWND,0,0),NULL);
-
- Sleep(100);
- CallService(MS_TTB_SETBUTTONSTATE,(WPARAM)hMainMenuBut,TTBST_RELEASED);
- return(0);
-};
-
-INT_PTR TTBInternalOptionsButt(WPARAM wParam,LPARAM lParam)
-{
- CallService("Options/OptionsCommand",0,0);
- Sleep(100);
- CallService(MS_TTB_SETBUTTONSTATE,(WPARAM)hOptionsBut,TTBST_RELEASED);
- return(0);
-};
-INT_PTR TTBInternalGroupShowHide(WPARAM wParam,LPARAM lParam)
-{
- int newVal=!(GetWindowLong(hwndContactTree,GWL_STYLE)&CLS_USEGROUPS);
- DBWriteContactSettingByte(NULL,"CList","UseGroups",(BYTE)newVal);
- SendMessage(hwndContactTree,CLM_SETUSEGROUPS,newVal,0);
-
- /*
- CallService(MS_TTB_SETBUTTONOPTIONS,MAKEWPARAM(TTBO_TIPNAME,hGroupBut),
- (!newVal)?Translate("Show Groups"):Translate("Hide Groups"));
- */
- return(0);
-};
-//DBGetContactSettingByte(NULL,"Skin","UseSound",1)
-
-INT_PTR TTBInternalSoundsOnOff(WPARAM wParam,LPARAM lParam)
-{
- int newVal=!(DBGetContactSettingByte(NULL,"Skin","UseSound",1));
- DBWriteContactSettingByte(NULL,"Skin","UseSound",(BYTE)newVal);
- CallService(MS_TTB_SETBUTTONOPTIONS,MAKEWPARAM(TTBO_TIPNAME,hSoundsBut),
- (LPARAM)((newVal)?Translate("Disable Sounds"):Translate("Enable Sounds")));
- return(0);
-};
-int UnLoadInternalButtons()
-{
- if (hSettingChangedHook){UnhookEvent(hSettingChangedHook);};
- return(0);
-};
-
-boolean framesexists=FALSE;
-int windhandle;
-
-LRESULT CALLBACK TestProczzz(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch(msg) {
- case WM_CREATE:
- SetTimer(hwnd,0,100,0);
- return 0;
- case WM_TIMER:
- InvalidateRect(hwnd,NULL,TRUE);
- RedrawWindow(hwnd,NULL,NULL,0);
- break;
- case WM_PAINT:
- {
- PAINTSTRUCT lp;
- HDC hdc;
- hdc=BeginPaint(hwnd,&lp);
- if (hdc)
- {
- char buf[255];
- wsprintf((LPSTR)&buf,"%d",GetTickCount());
- TextOut(hdc,4,4,(LPCTSTR)&buf,strlen(buf));
- EndPaint(hwnd,&lp);
- }
- return(0);
- }
-
- }
-
-
- return(DefWindowProc(hwnd, msg, wParam, lParam));
-};
-
-boolean first=TRUE;
-char pluginname[]="SimpleClassName";
-
-INT_PTR test(WPARAM wParam,LPARAM lParam)
-{
-if (first)
-{
- WNDCLASS wndclass;
- int r;
-
- wndclass.style = 0;
- wndclass.lpfnWndProc = TestProczzz;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInst;
- wndclass.hIcon = NULL;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
- wndclass.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);//NULL;//(HBRUSH)(COLOR_3DFACE+1);
- wndclass.lpszMenuName = NULL;
- wndclass.lpszClassName = pluginname;
- r=RegisterClass(&wndclass);
- first=FALSE;
-};
-
-if (framesexists)
-{
- CallService(MS_CLIST_FRAMES_REMOVEFRAME,(WPARAM)windhandle,0);
- windhandle=0;
- framesexists=FALSE;
-}else
-{
- CLISTFrame Frame;
- //int font;
-
- HWND pluginwind;
- pluginwind=CreateWindow(pluginname,pluginname,
- WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,
- 0,0,0,0,(HWND)CallService(MS_CLUI_GETHWND,0,0),NULL,hInst,NULL);
-
- //font=SendMessage(parent,WM_GETFONT,0,0);
- //SendMessage(pluginwind,WM_SETFONT,font,0);
-
- //
- memset(&Frame,0,sizeof(Frame));
- Frame.name=(char *)malloc(255);
- memset(Frame.name,0,255);
- memcpy(Frame.name,pluginname,sizeof(pluginname));
- Frame.cbSize=sizeof(Frame);
- Frame.hWnd=pluginwind;
- Frame.align=alTop;
- Frame.Flags=F_VISIBLE;
- Frame.height=18;
-
- windhandle=CallService(MS_CLIST_FRAMES_ADDFRAME,(WPARAM)&Frame,0);
- framesexists=TRUE;
- //free(Frame.name);
-};
-return(0);
-};
-
-int LoadInternalButtons(HWND hwnd)
-{
- TTBButtonV2 ttb;
-
- hwndContactTree=hwnd;
- hSettingChangedHook=0;
- CreateServiceFunction(TTBI_GROUPSHOWHIDE,TTBInternalGroupShowHide);
- CreateServiceFunction(TTBI_SOUNDSONOFF,TTBInternalSoundsOnOff);
-
- CreateServiceFunction(TTBI_OPTIONSBUTT,TTBInternalOptionsButt);
- CreateServiceFunction(TTBI_MAINMENUBUTT,TTBInternalMainMenuButt);
-
- CreateServiceFunction(TTBI_MINIMIZEBUTT,TTBInternalMinimizeButt);
- CreateServiceFunction(TTBI_FINDADDBUTT,TTBInternalFindAddButt);
-
- CreateServiceFunction("TEST1",test);
-
-
- //ShowOnline=(GetWindowLong(hwndContactTree,GWL_STYLE)&CLS_HIDEOFFLINE);
- ShowOnline=DBGetContactSettingByte(NULL,"CList","HideOffline",0);
- //ShowGroups=(GetWindowLong(hwndContactTree,GWL_STYLE)&CLS_USEGROUPS);
- ShowGroups=DBGetContactSettingByte(NULL,"CList","UseGroups",2);
- SoundsEnabled=DBGetContactSettingByte(NULL,"Skin","UseSound",1);
-
-/*
- OnlineDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_ONLINEDN));
- OnlineUp=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_ONLINEUP));
-
- hbOptUp=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_CPANELUP));
- hbOptDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_CPANELDN));
-
- MainMenuUp=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_MENUUP));
- MainMenuDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_MENUDN));
- //MainMenuDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_SEP));
-
- MinimizeUp=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_MINIMIZEUP));
- MinimizeDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_MINIMIZEDN));
-
- FindUserUp=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_FINDUSERUP));
- FindUserDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_FINDUSERDN));
-
-
- //OnlineDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_TESTBITMAP));
- //OnlineUp=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_TESTBITMAP));
-// testsearch=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_SEARCHTEST));
-
- GroupsDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_GROUPDN));
- GroupsUp=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_GROUPUP));
- SoundsDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_SOUNDSDN));
- SoundsUp=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_SOUNDSUP));
-*/
- //hbOptions=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_OPTIONS));
-
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- //ttb.hbBitmapDown=OnlineDn;
- //ttb.hbBitmapUp=OnlineUp;
- ttb.hIconUp=LoadImage(hInst,MAKEINTRESOURCE(IDI_SHOWONLINEUP),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
- ttb.hIconDn=LoadImage(hInst,MAKEINTRESOURCE(IDI_SHOWONLINEDN),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
-
-
-
- ttb.dwFlags=(ShowOnline?TTBBF_PUSHED:0)|TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
- ttb.pszServiceDown=MS_CLIST_SETHIDEOFFLINE;
- ttb.pszServiceUp=MS_CLIST_SETHIDEOFFLINE;
- //ttb.lParam=0;
- ttb.wParamUp=-1;
- ttb.wParamDown=-1;
- ttb.name="Show only Online Users";
- hOnlineBut=(HANDLE)TTBAddButton(&ttb,0);
-
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- //ttb.hbBitmapDown=GroupsDn;
- //ttb.hbBitmapUp=GroupsUp;
-
- ttb.hIconUp=LoadImage(hInst,MAKEINTRESOURCE(IDI_GROUPSUP),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
- ttb.hIconDn=LoadImage(hInst,MAKEINTRESOURCE(IDI_GROUPSDN),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
-
- ttb.dwFlags=(ShowGroups?TTBBF_PUSHED:0)|TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
- ttb.pszServiceDown=TTBI_GROUPSHOWHIDE;
- ttb.pszServiceUp=TTBI_GROUPSHOWHIDE;
- ttb.name="Groups On/Off";
- hGroupBut=(HANDLE)TTBAddButton(&ttb,0);
-
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- //ttb.hbBitmapDown=SoundsDn;
- //ttb.hbBitmapUp=SoundsUp;
- ttb.hIconUp=LoadImage(hInst,MAKEINTRESOURCE(IDI_SOUNDUP),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
- ttb.hIconDn=LoadImage(hInst,MAKEINTRESOURCE(IDI_SOUNDDN),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
-
- ttb.dwFlags=(SoundsEnabled?TTBBF_PUSHED:0)|TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
- ttb.pszServiceDown=TTBI_SOUNDSONOFF;
- ttb.pszServiceUp=TTBI_SOUNDSONOFF;
- ttb.name="Sounds Enable/Disable";
- hSoundsBut=(HANDLE)TTBAddButton(&ttb,0);
-/*
- memset(&ttb,0,sizeof(ttb));
- ttb.hbBitmapDown=hbOptions;
- ttb.hbBitmapUp=hbOptions;
- ttb.dwFlags=TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP|TTBBF_DRAWBORDER;
- ttb.pszServiceDown="Options/OptionsCommand";
- ttb.pszServiceUp="Options/OptionsCommand";
- ttb.lParam=0;
- ttb.wParam=0;
-// hOptionsBut=TTBAddButton(&ttb,0);
-*/
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- //ttb.hbBitmapDown=hbOptDn;
- //ttb.hbBitmapUp=hbOptUp;
- ttb.hIconUp=LoadImage(hInst,MAKEINTRESOURCE(IDI_OPTIONSUP),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
- ttb.hIconDn=LoadImage(hInst,MAKEINTRESOURCE(IDI_OPTIONSDN),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
-
- ttb.dwFlags=TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
- ttb.pszServiceDown=TTBI_OPTIONSBUTT;
- ttb.pszServiceUp=TTBI_OPTIONSBUTT;
- ttb.name="Show Options Page";
- hOptionsBut=(HANDLE)TTBAddButton(&ttb,0);
-
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- //ttb.hbBitmapDown=MinimizeDn;
- //ttb.hbBitmapUp=MinimizeUp;
- ttb.hIconUp=LoadImage(hInst,MAKEINTRESOURCE(IDI_MINIMIZEUP),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
- ttb.hIconDn=LoadImage(hInst,MAKEINTRESOURCE(IDI_MINIMIZEDN),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
-
- ttb.dwFlags=TTBBF_VISIBLE;
- ttb.pszServiceDown=TTBI_MINIMIZEBUTT;
- ttb.pszServiceUp=TTBI_MINIMIZEBUTT;
- ttb.name="Minimize Button";
- hMinimizeBut=(HANDLE)TTBAddButton(&ttb,0);
-
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- //ttb.hbBitmapDown=FindUserDn;
- //ttb.hbBitmapUp=FindUserUp;
- ttb.hIconUp=LoadImage(hInst,MAKEINTRESOURCE(IDI_FINDADDUP),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
- ttb.hIconDn=LoadImage(hInst,MAKEINTRESOURCE(IDI_FINDADDDN),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
-
- ttb.dwFlags=TTBBF_VISIBLE;
- ttb.pszServiceDown=TTBI_FINDADDBUTT;
- ttb.pszServiceUp=TTBI_FINDADDBUTT;
- ttb.name="Find/Add Contacts";
- hFindUsers=(HANDLE)TTBAddButton(&ttb,0);
-
-
-
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- //ttb.hbBitmapUp=MainMenuUp;
- //ttb.hbBitmapDown=MainMenuDn;
- ttb.hIconUp=LoadImage(hInst,MAKEINTRESOURCE(IDI_MIRANDAUP),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
- ttb.hIconDn=LoadImage(hInst,MAKEINTRESOURCE(IDI_MIRANDADN),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
-
- ttb.dwFlags=TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
- ttb.pszServiceDown=TTBI_MAINMENUBUTT;
- ttb.pszServiceUp=TTBI_MAINMENUBUTT;
- ttb.name="Show Main Menu";
- hMainMenuBut=(HANDLE)TTBAddButton(&ttb,0);
-
-
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- //ttb.hbBitmapUp=MainMenuUp;
- //ttb.hbBitmapDown=MainMenuDn;
- ttb.dwFlags=TTBBF_VISIBLE;
- ttb.pszServiceDown="TEST1";
- ttb.pszServiceUp="TEST1";
- ttb.name="Test";
- //TTBAddButton(&ttb,0);
-
- CallService(MS_TTB_SETBUTTONOPTIONS,MAKEWPARAM(TTBO_TIPNAME,hOnlineBut),
- (LPARAM)((ShowOnline)?Translate("Hide Offline Users"):Translate("Show All Users")));
-
- CallService(MS_TTB_SETBUTTONOPTIONS,MAKEWPARAM(TTBO_TIPNAME,hGroupBut),
- (LPARAM)((ShowGroups)?Translate("Hide Groups"):Translate("Show Groups")));
-
- CallService(MS_TTB_SETBUTTONOPTIONS,MAKEWPARAM(TTBO_TIPNAME,hSoundsBut),
- (LPARAM)((SoundsEnabled)?Translate("Disable Sounds"):Translate("Enable Sounds")));
-
- CallService(MS_TTB_SETBUTTONOPTIONS,MAKEWPARAM(TTBO_TIPNAME,hOptionsBut),
- (LPARAM)Translate("Show Options"));
-
- //OutputDebugStr("==>TopToolBar setted Hook for ME_DB_CONTACT_SETTINGCHANGED\r\n");
- //hSettingChangedHook=HookEvent(ME_DB_CONTACT_SETTINGCHANGED,OnSettingChanging);
- //OutputDebugStr("==>TopToolBar setted Hook for ME_DB_CONTACT_SETTINGCHANGED Done\r\n");
-
- return(0);
-
-}; \ No newline at end of file
diff --git a/plugins/TopToolBar/InternalButtons.cpp b/plugins/TopToolBar/InternalButtons.cpp
new file mode 100644
index 0000000000..d377053ee1
--- /dev/null
+++ b/plugins/TopToolBar/InternalButtons.cpp
@@ -0,0 +1,312 @@
+
+#include "common.h"
+#pragma hdrstop
+
+#define TTBI_GROUPSHOWHIDE "TTBInternal/GroupShowHide"
+#define TTBI_SOUNDSONOFF "TTBInternal/SoundsOnOFF"
+#define TTBI_OPTIONSBUTT "TTBInternal/OptionsBUTT"
+#define TTBI_MAINMENUBUTT "TTBInternal/MainMenuBUTT"
+#define TTBI_MINIMIZEBUTT "TTBInternal/MinimizeBUTT"
+#define TTBI_FINDADDBUTT "TTBInternal/FindAddBUTT"
+
+int LoadInternalButtons( HWND );
+int UnLoadInternalButtons();
+extern HINSTANCE hInst;
+
+HANDLE hSettingChangedHook;
+
+static HBITMAP OnlineUp, OnlineDn, GroupsUp, GroupsDn, SoundsUp;
+static HBITMAP SoundsDn, hbOptUp, hbOptDn, testsearch;
+static HBITMAP MainMenuUp, MainMenuDn;
+static HBITMAP MinimizeUp, MinimizeDn;
+static HBITMAP FindUserUp, FindUserDn;
+
+static int ShowOnline, ShowGroups, SoundsEnabled;
+static HANDLE hOnlineBut, hGroupBut, hSoundsBut, hOptionsBut, hMainMenuBut;
+static HANDLE hMinimizeBut;
+static HANDLE hFindUsers;
+
+static HANDLE OnSettingChg;
+
+static HWND hwndContactTree;
+
+int OnSettingChanging(WPARAM wParam, LPARAM lParam)
+{
+ if (wParam != 0)
+ return 0;
+
+ DBCONTACTWRITESETTING *dbcws = (DBCONTACTWRITESETTING *)lParam;
+ if (dbcws == NULL)
+ return 0;
+
+ if ( !strcmp(dbcws->szModule, "CList")) {
+ if ( !strcmp(dbcws->szSetting, "HideOffline")) {
+ int val = dbcws->value.bVal;
+
+ CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hOnlineBut, (LPARAM)(val)?TTBST_PUSHED:TTBST_RELEASED);
+
+ CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hOnlineBut),
+ (LPARAM)((!val)?Translate("Hide Offline Users"):Translate("Show All Users")));
+
+ return 0;
+ }
+
+ if (!strcmp(dbcws->szSetting, "UseGroups")) {
+ int val = dbcws->value.bVal;
+ CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hGroupBut, (LPARAM)((val)?TTBST_PUSHED:TTBST_RELEASED));
+ return 0;
+ }
+ }
+
+ if (!strcmp(dbcws->szModule, "Skin")) {
+ if (!strcmp(dbcws->szSetting, "UseSound")) {
+ int val = dbcws->value.bVal;
+ CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hSoundsBut, (LPARAM)(val)?TTBST_PUSHED:TTBST_RELEASED);
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
+INT_PTR TTBInternalFindAddButt(WPARAM wParam, LPARAM lParam)
+{
+ CallService("FindAdd/FindAddCommand", 0, 0);
+ CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hFindUsers, TTBST_RELEASED);
+ return 0;
+}
+
+INT_PTR TTBInternalMinimizeButt(WPARAM wParam, LPARAM lParam)
+{
+ Sleep(30);
+ CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hMinimizeBut, TTBST_RELEASED);
+ Sleep(30);
+ CallService(MS_CLIST_SHOWHIDE, 0, 0);
+ return 0;
+}
+
+INT_PTR TTBInternalMainMenuButt(WPARAM wParam, LPARAM lParam)
+{
+ HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUGETMAIN, 0, 0);
+
+ POINT pt;
+ GetCursorPos(&pt);
+ TrackPopupMenu(hMenu, TPM_TOPALIGN|TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, 0, (HWND)CallService(MS_CLUI_GETHWND, 0, 0), NULL);
+
+ Sleep(100);
+ CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hMainMenuBut, TTBST_RELEASED);
+ return 0;
+}
+
+INT_PTR TTBInternalOptionsButt(WPARAM wParam, LPARAM lParam)
+{
+ CallService("Options/OptionsCommand", 0, 0);
+ Sleep(100);
+ CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hOptionsBut, TTBST_RELEASED);
+ return 0;
+}
+
+INT_PTR TTBInternalGroupShowHide(WPARAM wParam, LPARAM lParam)
+{
+ int newVal = !(GetWindowLongPtr(hwndContactTree, GWL_STYLE)&CLS_USEGROUPS);
+ DBWriteContactSettingByte(NULL, "CList", "UseGroups", (BYTE)newVal);
+ SendMessage(hwndContactTree, CLM_SETUSEGROUPS, newVal, 0);
+ return 0;
+}
+
+INT_PTR TTBInternalSoundsOnOff(WPARAM wParam, LPARAM lParam)
+{
+ int newVal = !(DBGetContactSettingByte(NULL, "Skin", "UseSound", 1));
+ DBWriteContactSettingByte(NULL, "Skin", "UseSound", (BYTE)newVal);
+ CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hSoundsBut),
+ (LPARAM)((newVal)?Translate("Disable Sounds"):Translate("Enable Sounds")));
+ return 0;
+}
+
+int UnLoadInternalButtons()
+{
+ if (hSettingChangedHook){UnhookEvent(hSettingChangedHook);}
+ return 0;
+}
+
+bool framesexists = FALSE;
+int windhandle;
+
+LRESULT CALLBACK TestProczzz(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg) {
+ case WM_CREATE:
+ SetTimer(hwnd, 0, 100, 0);
+ return 0;
+
+ case WM_TIMER:
+ InvalidateRect(hwnd, NULL, TRUE);
+ RedrawWindow(hwnd, NULL, NULL, 0);
+ break;
+
+ case WM_PAINT:
+ {
+ PAINTSTRUCT lp;
+ HDC hdc = BeginPaint(hwnd, &lp);
+ if (hdc) {
+ char buf[255];
+ wsprintf(buf, "%d", GetTickCount());
+ TextOutA(hdc, 4, 4, buf, strlen(buf));
+ EndPaint(hwnd, &lp);
+ }
+ return 0;
+ }
+ }
+
+ return(DefWindowProc(hwnd, msg, wParam, lParam));
+}
+
+bool first = TRUE;
+char pluginname[] = "SimpleClassName";
+
+INT_PTR test(WPARAM wParam, LPARAM lParam)
+{
+ if (first) {
+ WNDCLASS wndclass = { 0 };
+ wndclass.lpfnWndProc = TestProczzz;
+ wndclass.hInstance = hInst;
+ wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
+ wndclass.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);//NULL;//(HBRUSH)(COLOR_3DFACE+1);
+ wndclass.lpszClassName = pluginname;
+ RegisterClass(&wndclass);
+ first = FALSE;
+ }
+
+ if (framesexists) {
+ CallService(MS_CLIST_FRAMES_REMOVEFRAME, (WPARAM)windhandle, 0);
+ windhandle = 0;
+ framesexists = FALSE;
+ }
+ else {
+ HWND pluginwind = CreateWindow(pluginname, pluginname,
+ WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,
+ 0, 0, 0, 0, (HWND)CallService(MS_CLUI_GETHWND, 0, 0), NULL, hInst, NULL);
+
+ CLISTFrame Frame = { 0 };
+ Frame.name = (char *)malloc(255);
+ memset(Frame.name, 0, 255);
+ memcpy(Frame.name, pluginname, sizeof(pluginname));
+ Frame.cbSize = sizeof(Frame);
+ Frame.hWnd = pluginwind;
+ Frame.align = alTop;
+ Frame.Flags = F_VISIBLE;
+ Frame.height = 18;
+
+ windhandle = CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&Frame, 0);
+ framesexists = TRUE;
+ }
+ return 0;
+}
+
+int LoadInternalButtons(HWND hwnd)
+{
+ hwndContactTree = hwnd;
+ hSettingChangedHook = 0;
+ CreateServiceFunction(TTBI_GROUPSHOWHIDE, TTBInternalGroupShowHide);
+ CreateServiceFunction(TTBI_SOUNDSONOFF, TTBInternalSoundsOnOff);
+
+ CreateServiceFunction(TTBI_OPTIONSBUTT, TTBInternalOptionsButt);
+ CreateServiceFunction(TTBI_MAINMENUBUTT, TTBInternalMainMenuButt);
+
+ CreateServiceFunction(TTBI_MINIMIZEBUTT, TTBInternalMinimizeButt);
+ CreateServiceFunction(TTBI_FINDADDBUTT, TTBInternalFindAddButt);
+
+ CreateServiceFunction("TEST1", test);
+
+ ShowOnline = DBGetContactSettingByte(NULL, "CList", "HideOffline", 0);
+ ShowGroups = DBGetContactSettingByte(NULL, "CList", "UseGroups", 2);
+ SoundsEnabled = DBGetContactSettingByte(NULL, "Skin", "UseSound", 1);
+
+ TTBButtonV2 ttb = { 0 };
+ ttb.cbSize = sizeof(ttb);
+ ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_SHOWONLINEUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_SHOWONLINEDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.dwFlags = (ShowOnline?TTBBF_PUSHED:0)|TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
+ ttb.pszServiceDown = MS_CLIST_SETHIDEOFFLINE;
+ ttb.pszServiceUp = MS_CLIST_SETHIDEOFFLINE;
+ ttb.wParamUp = -1;
+ ttb.wParamDown = -1;
+ ttb.name = "Show only Online Users";
+ hOnlineBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);
+
+ memset(&ttb, 0, sizeof(ttb));
+ ttb.cbSize = sizeof(ttb);
+ ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_GROUPSUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_GROUPSDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.dwFlags = (ShowGroups?TTBBF_PUSHED:0)|TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
+ ttb.pszServiceDown = TTBI_GROUPSHOWHIDE;
+ ttb.pszServiceUp = TTBI_GROUPSHOWHIDE;
+ ttb.name = "Groups On/Off";
+ hGroupBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);
+
+ memset(&ttb, 0, sizeof(ttb));
+ ttb.cbSize = sizeof(ttb);
+ ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_SOUNDUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_SOUNDDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+
+ ttb.dwFlags = (SoundsEnabled?TTBBF_PUSHED:0)|TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
+ ttb.pszServiceDown = TTBI_SOUNDSONOFF;
+ ttb.pszServiceUp = TTBI_SOUNDSONOFF;
+ ttb.name = "Sounds Enable/Disable";
+ hSoundsBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);
+
+ memset(&ttb, 0, sizeof(ttb));
+ ttb.cbSize = sizeof(ttb);
+ ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_OPTIONSUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_OPTIONSDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.dwFlags = TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
+ ttb.pszServiceDown = TTBI_OPTIONSBUTT;
+ ttb.pszServiceUp = TTBI_OPTIONSBUTT;
+ ttb.name = "Show Options Page";
+ hOptionsBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);
+
+ memset(&ttb, 0, sizeof(ttb));
+ ttb.cbSize = sizeof(ttb);
+ ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MINIMIZEUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MINIMIZEDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+
+ ttb.dwFlags = TTBBF_VISIBLE;
+ ttb.pszServiceDown = TTBI_MINIMIZEBUTT;
+ ttb.pszServiceUp = TTBI_MINIMIZEBUTT;
+ ttb.name = "Minimize Button";
+ hMinimizeBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);
+
+ memset(&ttb, 0, sizeof(ttb));
+ ttb.cbSize = sizeof(ttb);
+ ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_FINDADDUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_FINDADDDN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.dwFlags = TTBBF_VISIBLE;
+ ttb.pszServiceDown = TTBI_FINDADDBUTT;
+ ttb.pszServiceUp = TTBI_FINDADDBUTT;
+ ttb.name = "Find/Add Contacts";
+ hFindUsers = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);
+
+ memset(&ttb, 0, sizeof(ttb));
+ ttb.cbSize = sizeof(ttb);
+ ttb.hIconUp = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MIRANDAUP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MIRANDADN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+ ttb.dwFlags = TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
+ ttb.pszServiceDown = TTBI_MAINMENUBUTT;
+ ttb.pszServiceUp = TTBI_MAINMENUBUTT;
+ ttb.name = "Show Main Menu";
+ hMainMenuBut = (HANDLE)TTBAddButton((WPARAM)&ttb, 0);
+
+ CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hOnlineBut),
+ (LPARAM)((ShowOnline)?Translate("Hide Offline Users"):Translate("Show All Users")));
+
+ CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hGroupBut),
+ (LPARAM)((ShowGroups)?Translate("Hide Groups"):Translate("Show Groups")));
+
+ CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hSoundsBut),
+ (LPARAM)((SoundsEnabled)?Translate("Disable Sounds"):Translate("Enable Sounds")));
+
+ CallService(MS_TTB_SETBUTTONOPTIONS, MAKEWPARAM(TTBO_TIPNAME, hOptionsBut),
+ (LPARAM)Translate("Show Options"));
+
+ return 0;
+}
diff --git a/plugins/TopToolBar/TopToolBar.vcxproj b/plugins/TopToolBar/TopToolBar.vcxproj
index 0609a5725d..4987149c7e 100644
--- a/plugins/TopToolBar/TopToolBar.vcxproj
+++ b/plugins/TopToolBar/TopToolBar.vcxproj
@@ -49,19 +49,15 @@
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
@@ -98,6 +94,8 @@
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -133,6 +131,8 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -170,6 +170,8 @@
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -209,6 +211,8 @@
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -229,53 +233,8 @@
</Bscmake>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="button.c">
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <ClCompile Include="CLCButton.c">
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <ClCompile Include="InternalButtons.c">
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <ClCompile Include="launchbt.c">
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <ClCompile Include="main.c">
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <ClCompile Include="separators.c">
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- <ClCompile Include="ttbopt.c">
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
<ClInclude Include="BkgrCfg.h" />
<ClInclude Include="common.h" />
- <ClInclude Include="m_toptoolbar.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
@@ -329,6 +288,17 @@
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="button.cpp" />
+ <ClCompile Include="CLCButton.cpp" />
+ <ClCompile Include="InternalButtons.cpp" />
+ <ClCompile Include="launchbt.cpp" />
+ <ClCompile Include="main.cpp">
+ <PrecompiledHeader>Create</PrecompiledHeader>
+ </ClCompile>
+ <ClCompile Include="separators.cpp" />
+ <ClCompile Include="ttbopt.cpp" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
diff --git a/plugins/TopToolBar/TopToolBar.vcxproj.filters b/plugins/TopToolBar/TopToolBar.vcxproj.filters
index f70b2e4a25..9066e55109 100644
--- a/plugins/TopToolBar/TopToolBar.vcxproj.filters
+++ b/plugins/TopToolBar/TopToolBar.vcxproj.filters
@@ -15,38 +15,12 @@
</Filter>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="button.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="CLCButton.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="InternalButtons.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="launchbt.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="main.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="separators.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="ttbopt.c">
- <Filter>Source Files</Filter>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
<ClInclude Include="BkgrCfg.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="common.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="m_toptoolbar.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -181,4 +155,27 @@
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="CLCButton.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="InternalButtons.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="launchbt.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="separators.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="ttbopt.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="button.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
</Project> \ No newline at end of file
diff --git a/plugins/TopToolBar/_button.c b/plugins/TopToolBar/_button.c
deleted file mode 100644
index 6998efb409..0000000000
--- a/plugins/TopToolBar/_button.c
+++ /dev/null
@@ -1,515 +0,0 @@
-/*
-Miranda IM
-Copyright (C) 2002 Robert Rainwater
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-#include "common.h"
-
-// TODO:
-// - Support for bitmap buttons (simple call to DrawIconEx())
-
-static LRESULT CALLBACK MButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-
-typedef struct {
- HWND hwnd;
- int stateId; // button state
- int focus; // has focus (1 or 0)
- HFONT hFont; // font
- HICON arrow; // uses down arrow
- int defbutton; // default button
- HICON hIcon;
- HBITMAP hBitmap;
- int pushBtn;
- int pbState;
- HANDLE hThemeButton;
- HANDLE hThemeToolbar;
- char cHot;
- int flatBtn;
-} MButtonCtrl;
-
-
-// External theme methods and properties
-static HMODULE themeAPIHandle = NULL; // handle to uxtheme.dll
-static HANDLE (WINAPI *MyOpenThemeData)(HWND,LPCWSTR);
-static HRESULT (WINAPI *MyCloseThemeData)(HANDLE);
-static BOOL (WINAPI *MyIsThemeBackgroundPartiallyTransparent)(HANDLE,int,int);
-static HRESULT (WINAPI *MyDrawThemeParentBackground)(HWND,HDC,RECT *);
-static HRESULT (WINAPI *MyDrawThemeBackground)(HANDLE,HDC,int,int,const RECT *,const RECT *);
-static HRESULT (WINAPI *MyDrawThemeText)(HANDLE,HDC,int,int,LPCWSTR,int,DWORD,DWORD,const RECT *);
-
-static CRITICAL_SECTION csTips;
-static HWND hwndToolTips = NULL;
-
-int UnloadButtonModule(WPARAM wParam, LPARAM lParam) {
- DeleteCriticalSection(&csTips);
- return 0;
-}
-
-int LoadButtonModule(void) {
- WNDCLASSEX wc;
-
- ZeroMemory(&wc, sizeof(wc));
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = MYMIRANDABUTTONCLASS;
- wc.lpfnWndProc = MButtonWndProc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.cbWndExtra = sizeof(MButtonCtrl*);
- wc.hbrBackground = 0;
- wc.style = CS_GLOBALCLASS;
- RegisterClassEx(&wc);
- InitializeCriticalSection(&csTips);
- HookEvent(ME_SYSTEM_SHUTDOWN, UnloadButtonModule);
- return 0;
-}
-
-// Used for our own cheap TrackMouseEvent
-#define BUTTON_POLLID 100
-#define BUTTON_POLLDELAY 50
-
-#define MGPROC(x) GetProcAddress(themeAPIHandle,x)
-static int ThemeSupport() {
- if (IsWinVerXPPlus()) {
- if (!themeAPIHandle) {
- themeAPIHandle = GetModuleHandle("uxtheme");
- if (themeAPIHandle) {
- MyOpenThemeData = (HANDLE (WINAPI *)(HWND,LPCWSTR))MGPROC("OpenThemeData");
- MyCloseThemeData = (HRESULT (WINAPI *)(HANDLE))MGPROC("CloseThemeData");
- MyIsThemeBackgroundPartiallyTransparent = (BOOL (WINAPI *)(HANDLE,int,int))MGPROC("IsThemeBackgroundPartiallyTransparent");
- MyDrawThemeParentBackground = (HRESULT (WINAPI *)(HWND,HDC,RECT *))MGPROC("DrawThemeParentBackground");
- MyDrawThemeBackground = (HRESULT (WINAPI *)(HANDLE,HDC,int,int,const RECT *,const RECT *))MGPROC("DrawThemeBackground");
- MyDrawThemeText = (HRESULT (WINAPI *)(HANDLE,HDC,int,int,LPCWSTR,int,DWORD,DWORD,const RECT *))MGPROC("DrawThemeText");
- }
- }
- // Make sure all of these methods are valid (i would hope either all or none work)
- if (MyOpenThemeData
- &&MyCloseThemeData
- &&MyIsThemeBackgroundPartiallyTransparent
- &&MyDrawThemeParentBackground
- &&MyDrawThemeBackground
- &&MyDrawThemeText) {
- return 1;
- }
- }
- return 0;
-}
-
-static void DestroyTheme(MButtonCtrl *ctl) {
- if (ThemeSupport()) {
- if (ctl->hThemeButton) {
- MyCloseThemeData(ctl->hThemeButton);
- ctl->hThemeButton = NULL;
- }
- if (ctl->hThemeToolbar) {
- MyCloseThemeData(ctl->hThemeToolbar);
- ctl->hThemeToolbar = NULL;
- }
- }
-}
-
-static void LoadTheme(MButtonCtrl *ctl) {
- if (ThemeSupport()) {
- DestroyTheme(ctl);
- ctl->hThemeButton = MyOpenThemeData(ctl->hwnd,L"BUTTON");
- ctl->hThemeToolbar = MyOpenThemeData(ctl->hwnd,L"TOOLBAR");
- }
-}
-
-static TBStateConvert2Flat(int state) {
- switch(state) {
- case PBS_NORMAL: return TS_NORMAL;
- case PBS_HOT: return TS_HOT;
- case PBS_PRESSED: return TS_PRESSED;
- case PBS_DISABLED: return TS_DISABLED;
- case PBS_DEFAULTED: return TS_NORMAL;
- }
- return TS_NORMAL;
-}
-
-static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint) {
- if (hdcPaint) {
- RECT rcClient;
- GetClientRect(ctl->hwnd, &rcClient);
-
- // If its a push button, check to see if it should stay pressed
- if (ctl->pushBtn && ctl->pbState) ctl->stateId = PBS_PRESSED;
-
- // Draw the flat button
- if (ctl->flatBtn) {
- if (ctl->hThemeToolbar) {
- int state = IsWindowEnabled(ctl->hwnd)?(ctl->stateId==PBS_NORMAL&&ctl->defbutton?PBS_DEFAULTED:ctl->stateId):PBS_DISABLED;
- if (MyIsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
- MyDrawThemeParentBackground(ctl->hwnd, hdcPaint, &rcClient);
- }
- MyDrawThemeBackground(ctl->hThemeToolbar, hdcPaint, TP_BUTTON, TBStateConvert2Flat(state), &rcClient, &rcClient);
- }
- else {
- HBRUSH hbr;
-
- if (ctl->stateId==PBS_PRESSED||ctl->stateId==PBS_HOT)
- hbr = GetSysColorBrush(COLOR_3DLIGHT);
- else {
- HDC dc;
- HWND hwndParent;
-
- hwndParent = GetParent(ctl->hwnd);
- dc=GetDC(hwndParent);
- hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent);
- ReleaseDC(hwndParent,dc);
- }
- if (hbr) {
- FillRect(hdcPaint, &rcClient, hbr);
- DeleteObject(hbr);
- }
- if (ctl->stateId==PBS_HOT||ctl->focus) {
- if (ctl->pbState)
- DrawEdge(hdcPaint,&rcClient, EDGE_ETCHED,BF_RECT|BF_SOFT);
- else DrawEdge(hdcPaint,&rcClient, BDR_RAISEDOUTER,BF_RECT|BF_SOFT|BF_FLAT);
- }
- else if (ctl->stateId==PBS_PRESSED)
- DrawEdge(hdcPaint, &rcClient, BDR_SUNKENOUTER,BF_RECT|BF_SOFT);
- }
- }
- else {
- // Draw background/border
- if (ctl->hThemeButton) {
- int state = IsWindowEnabled(ctl->hwnd)?(ctl->stateId==PBS_NORMAL&&ctl->defbutton?PBS_DEFAULTED:ctl->stateId):PBS_DISABLED;
- if (MyIsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
- MyDrawThemeParentBackground(ctl->hwnd, hdcPaint, &rcClient);
- }
- MyDrawThemeBackground(ctl->hThemeButton, hdcPaint, BP_PUSHBUTTON, state, &rcClient, &rcClient);
- }
- else {
- UINT uState = DFCS_BUTTONPUSH|((ctl->stateId==PBS_HOT)?DFCS_HOT:0)|((ctl->stateId == PBS_PRESSED)?DFCS_PUSHED:0);
- if (ctl->defbutton&&ctl->stateId==PBS_NORMAL) uState |= DLGC_DEFPUSHBUTTON;
- DrawFrameControl(hdcPaint, &rcClient, DFC_BUTTON, uState);
- }
-
- // Draw focus rectangle if button has focus
- if (ctl->focus) {
- RECT focusRect = rcClient;
- InflateRect(&focusRect, -3, -3);
- DrawFocusRect(hdcPaint, &focusRect);
- }
- }
-
- // If we have an icon or a bitmap, ignore text and only draw the image on the button
- if (ctl->hIcon) {
- int ix = (rcClient.right-rcClient.left)/2 - (GetSystemMetrics(SM_CXSMICON)/2);
- int iy = (rcClient.bottom-rcClient.top)/2 - (GetSystemMetrics(SM_CYSMICON)/2);
- if (ctl->stateId == PBS_PRESSED) {
- ix++;
- iy++;
- }
- DrawState(hdcPaint,NULL,NULL,(LPARAM)ctl->hIcon,0,ix,iy,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),IsWindowEnabled(ctl->hwnd)?DST_ICON:DST_ICON|DSS_DISABLED);
- }
- else if (ctl->hBitmap) {
- BITMAP bminfo;
- int ix,iy;
-
- GetObject(ctl->hBitmap, sizeof(bminfo), &bminfo);
- ix = (rcClient.right-rcClient.left)/2 - (bminfo.bmWidth/2);
- iy = (rcClient.bottom-rcClient.top)/2 - (bminfo.bmHeight/2);
- if (ctl->stateId == PBS_PRESSED) {
- ix++;
- iy++;
- }
- DrawState(hdcPaint,NULL,NULL,(LPARAM)ctl->hBitmap,0,ix,iy,bminfo.bmWidth,bminfo.bmHeight,IsWindowEnabled(ctl->hwnd)?DST_BITMAP:DST_BITMAP|DSS_DISABLED);
- }
- else if (GetWindowTextLength(ctl->hwnd)) {
- // Draw the text and optinally the arrow
- char szText[MAX_PATH];
- SIZE sz;
- RECT rcText;
-
- CopyRect(&rcText, &rcClient);
- GetWindowText(ctl->hwnd, szText, sizeof(szText));
- SetBkMode(hdcPaint, TRANSPARENT);
- SelectObject(hdcPaint, ctl->hFont);
- // XP w/themes doesn't used the glossy disabled text. Is it always using COLOR_GRAYTEXT? Seems so.
- SetTextColor(hdcPaint, IsWindowEnabled(ctl->hwnd)||!ctl->hThemeButton?GetSysColor(COLOR_BTNTEXT):GetSysColor(COLOR_GRAYTEXT));
- GetTextExtentPoint32(hdcPaint, szText, lstrlen(szText), &sz);
- if (ctl->cHot) {
- SIZE szHot;
-
- GetTextExtentPoint32(hdcPaint, "&", 1, &szHot);
- sz.cx -= szHot.cx;
- }
- if (ctl->arrow) {
- DrawState(hdcPaint,NULL,NULL,(LPARAM)ctl->arrow,0,rcClient.right-rcClient.left-5-GetSystemMetrics(SM_CXSMICON)+(!ctl->hThemeButton&&ctl->stateId==PBS_PRESSED?1:0),(rcClient.bottom-rcClient.top)/2-GetSystemMetrics(SM_CYSMICON)/2+(!ctl->hThemeButton&&ctl->stateId==PBS_PRESSED?1:0),GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),IsWindowEnabled(ctl->hwnd)?DST_ICON:DST_ICON|DSS_DISABLED);
- }
- SelectObject(hdcPaint, ctl->hFont);
- DrawState(hdcPaint,NULL,NULL,(LPARAM)szText,0,(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);
- }
- }
-}
-
-static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
- MButtonCtrl* bct = (MButtonCtrl *)GetWindowLong(hwndDlg, 0);
- switch(msg) {
- case WM_NCCREATE:
- {
- SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLong(hwndDlg, GWL_STYLE)|BS_OWNERDRAW);
- bct = malloc(sizeof(MButtonCtrl));
- if (bct==NULL) return FALSE;
- bct->hwnd = hwndDlg;
- bct->stateId = PBS_NORMAL;
- bct->focus = 0;
- bct->hFont = GetStockObject(DEFAULT_GUI_FONT);
- bct->arrow = NULL;
- bct->defbutton = 0;
- bct->hIcon = NULL;
- bct->hBitmap = NULL;
- bct->pushBtn = 0;
- bct->pbState = 0;
- bct->hThemeButton = NULL;
- bct->hThemeToolbar = NULL;
- bct->cHot = 0;
- bct->flatBtn = 0;
- LoadTheme(bct);
- SetWindowLong(hwndDlg, 0, (LONG)bct);
- if (((CREATESTRUCT *)lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *)lParam)->lpszName);
- return TRUE;
- }
- case WM_DESTROY:
- {
- if (bct) {
- EnterCriticalSection(&csTips);
- if (hwndToolTips) {
- TOOLINFO ti;
-
- ZeroMemory(&ti, sizeof(ti));
- ti.cbSize = sizeof(ti);
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT)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;
- }
- }
- LeaveCriticalSection(&csTips);
- DestroyTheme(bct);
- free(bct);
- }
- SetWindowLong(hwndDlg,0,(LONG)NULL);
- break; // DONT! fall thru
- }
- case WM_SETTEXT:
- {
- bct->cHot = 0;
- if ((char*)lParam) {
- char *tmp = (char*)lParam;
- while (*tmp) {
- if (*tmp=='&' && *(tmp+1)) {
- bct->cHot = tolower(*(tmp+1));
- break;
- }
- tmp++;
- }
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
- }
- 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;
- }
- break;
- case WM_THEMECHANGED: {
- // themed changed, reload theme object
- LoadTheme(bct);
- InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
- break;
- }
- case WM_SETFONT: // remember the font so we can use it later
- {
- bct->hFont = (HFONT)wParam; // maybe we should redraw?
- break;
- }
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdcPaint;
-
- hdcPaint = BeginPaint(hwndDlg, &ps);
- if (hdcPaint) {
- PaintWorker(bct, hdcPaint);
- EndPaint(hwndDlg, &ps);
- }
- break;
- }
- case BM_SETIMAGE:
- if (wParam == IMAGE_ICON) {
- bct->hIcon = (HICON)lParam;
- bct->hBitmap = NULL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- else if (wParam == IMAGE_BITMAP) {
- bct->hBitmap = (HBITMAP)lParam;
- bct->hIcon = 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
- if (wParam) {
- //if (!bct->arrow)
- //bct->arrow = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_DOWNARROW),IMAGE_ICON,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0);
- }
- else {
- if (bct->arrow) {
- DestroyIcon(bct->arrow);
- bct->arrow = NULL;
- }
- }
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETDEFAULT:
- bct->defbutton = wParam?1:0;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETASPUSHBTN:
- bct->pushBtn = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETASFLATBTN:
- bct->flatBtn = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONADDTOOLTIP:
- {
- TOOLINFO ti;
-
- if (!(char*)wParam) break;
- EnterCriticalSection(&csTips);
- if (!hwndToolTips) {
- hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, "", WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
- }
- ZeroMemory(&ti, sizeof(ti));
- ti.cbSize = sizeof(ti);
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT)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)bct->hwnd;
- ti.lpszText=(char*)wParam;
- SendMessage(hwndToolTips,TTM_ADDTOOL,0,(LPARAM)&ti);
- LeaveCriticalSection(&csTips);
- 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_WINDOWPOSCHANGED:
- 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_LBUTTONDOWN:
- {
- if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
- bct->stateId = PBS_PRESSED;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
- }
- case WM_LBUTTONUP:
- {
- 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 (msg==WM_LBUTTONUP) bct->stateId = PBS_HOT;
- else bct->stateId = PBS_NORMAL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- // Tell your daddy you got clicked.
- 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);
- }
- // Call timer, used to start cheesy TrackMouseEvent faker
- SetTimer(hwndDlg,BUTTON_POLLID,BUTTON_POLLDELAY,NULL);
- break;
- case WM_TIMER: // use a timer to check if they have did a mouseout
- {
- if (wParam==BUTTON_POLLID) {
- RECT rc;
- POINT pt;
- GetWindowRect(hwndDlg,&rc);
- GetCursorPos(&pt);
- if(!PtInRect(&rc,pt)) { // mouse must be gone, trigger mouse leave
- PostMessage(hwndDlg,WM_MOUSELEAVE,0,0L);
- KillTimer(hwndDlg,BUTTON_POLLID);
- }
- }
- break;
- }
- case WM_ERASEBKGND:
- return 1;
- }
- return DefWindowProc(hwndDlg, msg, wParam, lParam);
-}
diff --git a/plugins/TopToolBar/_button.cpp b/plugins/TopToolBar/_button.cpp
new file mode 100644
index 0000000000..e1c1a31584
--- /dev/null
+++ b/plugins/TopToolBar/_button.cpp
@@ -0,0 +1,522 @@
+/*
+Miranda IM
+Copyright (C) 2002 Robert Rainwater
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+#include "common.h"
+
+// TODO:
+// - Support for bitmap buttons (simple call to DrawIconEx())
+
+static LRESULT CALLBACK MButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+
+typedef struct {
+ HWND hwnd;
+ int stateId; // button state
+ int focus; // has focus (1 or 0)
+ HFONT hFont; // font
+ HICON arrow; // uses down arrow
+ int defbutton; // default button
+ HICON hIcon;
+ HBITMAP hBitmap;
+ int pushBtn;
+ int pbState;
+ HANDLE hThemeButton;
+ HANDLE hThemeToolbar;
+ char cHot;
+ int flatBtn;
+} MButtonCtrl;
+
+
+// External theme methods and properties
+static HMODULE themeAPIHandle = NULL; // handle to uxtheme.dll
+static HANDLE (WINAPI *MyOpenThemeData)(HWND, LPCWSTR);
+static HRESULT (WINAPI *MyCloseThemeData)(HANDLE);
+static BOOL (WINAPI *MyIsThemeBackgroundPartiallyTransparent)(HANDLE, int, int);
+static HRESULT (WINAPI *MyDrawThemeParentBackground)(HWND, HDC, RECT *);
+static HRESULT (WINAPI *MyDrawThemeBackground)(HANDLE, HDC, int, int, const RECT *, const RECT *);
+static HRESULT (WINAPI *MyDrawThemeText)(HANDLE, HDC, int, int, LPCWSTR, int, DWORD, DWORD, const RECT *);
+
+static CRITICAL_SECTION csTips;
+static HWND hwndToolTips = NULL;
+
+int UnloadButtonModule(WPARAM wParam, LPARAM lParam)
+{
+ DeleteCriticalSection(&csTips);
+ return 0;
+}
+
+int LoadButtonModule(void)
+{
+ WNDCLASSEX wc = { 0 };
+ wc.cbSize = sizeof(wc);
+ wc.lpszClassName = MYMIRANDABUTTONCLASS;
+ wc.lpfnWndProc = MButtonWndProc;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.cbWndExtra = sizeof(MButtonCtrl*);
+ wc.hbrBackground = 0;
+ wc.style = CS_GLOBALCLASS;
+ RegisterClassEx(&wc);
+ InitializeCriticalSection(&csTips);
+ HookEvent(ME_SYSTEM_SHUTDOWN, UnloadButtonModule);
+ return 0;
+}
+
+// Used for our own cheap TrackMouseEvent
+#define BUTTON_POLLID 100
+#define BUTTON_POLLDELAY 50
+
+#define MGPROC(x) GetProcAddress(themeAPIHandle, x)
+static int ThemeSupport() {
+ if (IsWinVerXPPlus()) {
+ if (!themeAPIHandle) {
+ themeAPIHandle = GetModuleHandle("uxtheme");
+ if (themeAPIHandle) {
+ MyOpenThemeData = (HANDLE (WINAPI *)(HWND, LPCWSTR))MGPROC("OpenThemeData");
+ MyCloseThemeData = (HRESULT (WINAPI *)(HANDLE))MGPROC("CloseThemeData");
+ MyIsThemeBackgroundPartiallyTransparent = (BOOL (WINAPI *)(HANDLE, int, int))MGPROC("IsThemeBackgroundPartiallyTransparent");
+ MyDrawThemeParentBackground = (HRESULT (WINAPI *)(HWND, HDC, RECT *))MGPROC("DrawThemeParentBackground");
+ MyDrawThemeBackground = (HRESULT (WINAPI *)(HANDLE, HDC, int, int, const RECT *, const RECT *))MGPROC("DrawThemeBackground");
+ MyDrawThemeText = (HRESULT (WINAPI *)(HANDLE, HDC, int, int, LPCWSTR, int, DWORD, DWORD, const RECT *))MGPROC("DrawThemeText");
+ }
+ }
+ // Make sure all of these methods are valid (i would hope either all or none work)
+ if (MyOpenThemeData
+ &&MyCloseThemeData
+ &&MyIsThemeBackgroundPartiallyTransparent
+ &&MyDrawThemeParentBackground
+ &&MyDrawThemeBackground
+ &&MyDrawThemeText) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void DestroyTheme(MButtonCtrl *ctl)
+{
+ if (ThemeSupport()) {
+ if (ctl->hThemeButton) {
+ MyCloseThemeData(ctl->hThemeButton);
+ ctl->hThemeButton = NULL;
+ }
+ if (ctl->hThemeToolbar) {
+ MyCloseThemeData(ctl->hThemeToolbar);
+ ctl->hThemeToolbar = NULL;
+ }
+ }
+}
+
+static void LoadTheme(MButtonCtrl *ctl)
+{
+ if (ThemeSupport()) {
+ DestroyTheme(ctl);
+ ctl->hThemeButton = MyOpenThemeData(ctl->hwnd, L"BUTTON");
+ ctl->hThemeToolbar = MyOpenThemeData(ctl->hwnd, L"TOOLBAR");
+ }
+}
+
+static int TBStateConvert2Flat(int state)
+{
+ switch(state) {
+ case PBS_NORMAL: return TS_NORMAL;
+ case PBS_HOT: return TS_HOT;
+ case PBS_PRESSED: return TS_PRESSED;
+ case PBS_DISABLED: return TS_DISABLED;
+ case PBS_DEFAULTED: return TS_NORMAL;
+ }
+ return TS_NORMAL;
+}
+
+static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint)
+{
+ if (hdcPaint) {
+ RECT rcClient;
+ GetClientRect(ctl->hwnd, &rcClient);
+
+ // If its a push button, check to see if it should stay pressed
+ if (ctl->pushBtn && ctl->pbState) ctl->stateId = PBS_PRESSED;
+
+ // Draw the flat button
+ if (ctl->flatBtn) {
+ if (ctl->hThemeToolbar) {
+ int state = IsWindowEnabled(ctl->hwnd)?(ctl->stateId == PBS_NORMAL&&ctl->defbutton?PBS_DEFAULTED:ctl->stateId):PBS_DISABLED;
+ if (MyIsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
+ MyDrawThemeParentBackground(ctl->hwnd, hdcPaint, &rcClient);
+ }
+ MyDrawThemeBackground(ctl->hThemeToolbar, hdcPaint, TP_BUTTON, TBStateConvert2Flat(state), &rcClient, &rcClient);
+ }
+ else {
+ HBRUSH hbr;
+
+ if (ctl->stateId == PBS_PRESSED||ctl->stateId == PBS_HOT)
+ hbr = GetSysColorBrush(COLOR_3DLIGHT);
+ else {
+ HDC dc;
+ HWND hwndParent;
+
+ hwndParent = GetParent(ctl->hwnd);
+ dc = GetDC(hwndParent);
+ hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent);
+ ReleaseDC(hwndParent, dc);
+ }
+ if (hbr) {
+ FillRect(hdcPaint, &rcClient, hbr);
+ DeleteObject(hbr);
+ }
+ if (ctl->stateId == PBS_HOT||ctl->focus) {
+ if (ctl->pbState)
+ DrawEdge(hdcPaint, &rcClient, EDGE_ETCHED, BF_RECT|BF_SOFT);
+ else DrawEdge(hdcPaint, &rcClient, BDR_RAISEDOUTER, BF_RECT|BF_SOFT|BF_FLAT);
+ }
+ else if (ctl->stateId == PBS_PRESSED)
+ DrawEdge(hdcPaint, &rcClient, BDR_SUNKENOUTER, BF_RECT|BF_SOFT);
+ }
+ }
+ else {
+ // Draw background/border
+ if (ctl->hThemeButton) {
+ int state = IsWindowEnabled(ctl->hwnd)?(ctl->stateId == PBS_NORMAL&&ctl->defbutton?PBS_DEFAULTED:ctl->stateId):PBS_DISABLED;
+ if (MyIsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
+ MyDrawThemeParentBackground(ctl->hwnd, hdcPaint, &rcClient);
+ }
+ MyDrawThemeBackground(ctl->hThemeButton, hdcPaint, BP_PUSHBUTTON, state, &rcClient, &rcClient);
+ }
+ else {
+ UINT uState = DFCS_BUTTONPUSH|((ctl->stateId == PBS_HOT)?DFCS_HOT:0)|((ctl->stateId == PBS_PRESSED)?DFCS_PUSHED:0);
+ if (ctl->defbutton&&ctl->stateId == PBS_NORMAL) uState |= DLGC_DEFPUSHBUTTON;
+ DrawFrameControl(hdcPaint, &rcClient, DFC_BUTTON, uState);
+ }
+
+ // Draw focus rectangle if button has focus
+ if (ctl->focus) {
+ RECT focusRect = rcClient;
+ InflateRect(&focusRect, -3, -3);
+ DrawFocusRect(hdcPaint, &focusRect);
+ }
+ }
+
+ // If we have an icon or a bitmap, ignore text and only draw the image on the button
+ if (ctl->hIcon) {
+ int ix = (rcClient.right-rcClient.left)/2 - (GetSystemMetrics(SM_CXSMICON)/2);
+ int iy = (rcClient.bottom-rcClient.top)/2 - (GetSystemMetrics(SM_CYSMICON)/2);
+ if (ctl->stateId == PBS_PRESSED) {
+ ix++;
+ iy++;
+ }
+ DrawState(hdcPaint, NULL, NULL, (LPARAM)ctl->hIcon, 0, ix, iy, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), IsWindowEnabled(ctl->hwnd)?DST_ICON:DST_ICON|DSS_DISABLED);
+ }
+ else if (ctl->hBitmap) {
+ BITMAP bminfo;
+ int ix, iy;
+
+ GetObject(ctl->hBitmap, sizeof(bminfo), &bminfo);
+ ix = (rcClient.right-rcClient.left)/2 - (bminfo.bmWidth/2);
+ iy = (rcClient.bottom-rcClient.top)/2 - (bminfo.bmHeight/2);
+ if (ctl->stateId == PBS_PRESSED) {
+ ix++;
+ iy++;
+ }
+ DrawState(hdcPaint, NULL, NULL, (LPARAM)ctl->hBitmap, 0, ix, iy, bminfo.bmWidth, bminfo.bmHeight, IsWindowEnabled(ctl->hwnd)?DST_BITMAP:DST_BITMAP|DSS_DISABLED);
+ }
+ else if (GetWindowTextLength(ctl->hwnd)) {
+ // Draw the text and optinally the arrow
+ char szText[MAX_PATH];
+ SIZE sz;
+ RECT rcText;
+
+ CopyRect(&rcText, &rcClient);
+ GetWindowText(ctl->hwnd, szText, sizeof(szText));
+ SetBkMode(hdcPaint, TRANSPARENT);
+ SelectObject(hdcPaint, ctl->hFont);
+ // XP w/themes doesn't used the glossy disabled text. Is it always using COLOR_GRAYTEXT? Seems so.
+ SetTextColor(hdcPaint, IsWindowEnabled(ctl->hwnd)||!ctl->hThemeButton?GetSysColor(COLOR_BTNTEXT):GetSysColor(COLOR_GRAYTEXT));
+ GetTextExtentPoint32(hdcPaint, szText, lstrlen(szText), &sz);
+ if (ctl->cHot) {
+ SIZE szHot;
+
+ GetTextExtentPoint32(hdcPaint, "&", 1, &szHot);
+ sz.cx -= szHot.cx;
+ }
+ if (ctl->arrow) {
+ DrawState(hdcPaint, NULL, NULL, (LPARAM)ctl->arrow, 0, rcClient.right-rcClient.left-5-GetSystemMetrics(SM_CXSMICON)+(!ctl->hThemeButton&&ctl->stateId == PBS_PRESSED?1:0), (rcClient.bottom-rcClient.top)/2-GetSystemMetrics(SM_CYSMICON)/2+(!ctl->hThemeButton&&ctl->stateId == PBS_PRESSED?1:0), GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), IsWindowEnabled(ctl->hwnd)?DST_ICON:DST_ICON|DSS_DISABLED);
+ }
+ SelectObject(hdcPaint, ctl->hFont);
+ DrawState(hdcPaint, NULL, NULL, (LPARAM)szText, 0, (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);
+ }
+ }
+}
+
+static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ MButtonCtrl* bct = (MButtonCtrl *)GetWindowLongPtr(hwndDlg, 0);
+ switch(msg) {
+ case WM_NCCREATE:
+ SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLongPtr(hwndDlg, GWL_STYLE)|BS_OWNERDRAW);
+ bct = ( MButtonCtrl* )malloc(sizeof(MButtonCtrl));
+ if (bct == NULL)
+ return FALSE;
+
+ bct->hwnd = hwndDlg;
+ bct->stateId = PBS_NORMAL;
+ bct->focus = 0;
+ bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+ bct->arrow = NULL;
+ bct->defbutton = 0;
+ bct->hIcon = NULL;
+ bct->hBitmap = NULL;
+ bct->pushBtn = 0;
+ bct->pbState = 0;
+ bct->hThemeButton = NULL;
+ bct->hThemeToolbar = NULL;
+ bct->cHot = 0;
+ bct->flatBtn = 0;
+ LoadTheme(bct);
+ SetWindowLong(hwndDlg, 0, (LONG)bct);
+ if (((CREATESTRUCT *)lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *)lParam)->lpszName);
+ return TRUE;
+
+ case WM_DESTROY:
+ if (bct) {
+ EnterCriticalSection(&csTips);
+ if (hwndToolTips) {
+ TOOLINFO ti;
+
+ ZeroMemory(&ti, sizeof(ti));
+ ti.cbSize = sizeof(ti);
+ ti.uFlags = TTF_IDISHWND;
+ ti.hwnd = bct->hwnd;
+ ti.uId = (UINT)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;
+ }
+ }
+ LeaveCriticalSection(&csTips);
+ DestroyTheme(bct);
+ free(bct);
+ }
+ SetWindowLong(hwndDlg, 0, (LONG)NULL);
+ break; // DONT! fall thru
+
+ case WM_SETTEXT:
+ bct->cHot = 0;
+ if ((char*)lParam) {
+ char *tmp = (char*)lParam;
+ while (*tmp) {
+ if (*tmp == '&' && *(tmp+1)) {
+ bct->cHot = tolower(*(tmp+1));
+ break;
+ }
+ tmp++;
+ }
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ }
+ break;
+
+ 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;
+ }
+ break;
+
+ case WM_THEMECHANGED:
+ // themed changed, reload theme object
+ LoadTheme(bct);
+ InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
+ break;
+
+ case WM_SETFONT: // remember the font so we can use it later
+ bct->hFont = (HFONT)wParam; // maybe we should redraw?
+ break;
+
+ case WM_PAINT:
+ {
+ PAINTSTRUCT ps;
+ HDC hdcPaint = BeginPaint(hwndDlg, &ps);
+ if (hdcPaint) {
+ PaintWorker(bct, hdcPaint);
+ EndPaint(hwndDlg, &ps);
+ }
+ }
+ break;
+
+ case BM_SETIMAGE:
+ if (wParam == IMAGE_ICON) {
+ bct->hIcon = (HICON)lParam;
+ bct->hBitmap = NULL;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ }
+ else if (wParam == IMAGE_BITMAP) {
+ bct->hBitmap = (HBITMAP)lParam;
+ bct->hIcon = 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
+ if (wParam) {
+ //if (!bct->arrow)
+ //bct->arrow = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_DOWNARROW), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);
+ }
+ else {
+ if (bct->arrow) {
+ DestroyIcon(bct->arrow);
+ bct->arrow = NULL;
+ }
+ }
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETDEFAULT:
+ bct->defbutton = wParam?1:0;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETASPUSHBTN:
+ bct->pushBtn = 1;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETASFLATBTN:
+ bct->flatBtn = 1;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONADDTOOLTIP:
+ if (wParam) {
+ EnterCriticalSection(&csTips);
+ if (!hwndToolTips)
+ hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, "", WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
+
+ TOOLINFO ti = { 0 };
+ ti.cbSize = sizeof(ti);
+ ti.uFlags = TTF_IDISHWND;
+ ti.hwnd = bct->hwnd;
+ ti.uId = (UINT)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)bct->hwnd;
+ ti.lpszText = (char*)wParam;
+ SendMessage(hwndToolTips, TTM_ADDTOOL, 0, (LPARAM)&ti);
+ LeaveCriticalSection(&csTips);
+ }
+ 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_WINDOWPOSCHANGED:
+ 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_LBUTTONDOWN:
+ if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
+ bct->stateId = PBS_PRESSED;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ }
+ break;
+
+ case WM_LBUTTONUP:
+ 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 (msg == WM_LBUTTONUP) bct->stateId = PBS_HOT;
+ else bct->stateId = PBS_NORMAL;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ }
+ // Tell your daddy you got clicked.
+ 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);
+ }
+ // Call timer, used to start cheesy TrackMouseEvent faker
+ SetTimer(hwndDlg, BUTTON_POLLID, BUTTON_POLLDELAY, NULL);
+ break;
+
+ case WM_TIMER: // use a timer to check if they have did a mouseout
+ if (wParam == BUTTON_POLLID) {
+ RECT rc;
+ POINT pt;
+ GetWindowRect(hwndDlg, &rc);
+ GetCursorPos(&pt);
+ if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave
+ PostMessage(hwndDlg, WM_MOUSELEAVE, 0, 0L);
+ KillTimer(hwndDlg, BUTTON_POLLID);
+ }
+ }
+ break;
+
+ case WM_ERASEBKGND:
+ return 1;
+ }
+ return DefWindowProc(hwndDlg, msg, wParam, lParam);
+}
diff --git a/plugins/TopToolBar/button.c b/plugins/TopToolBar/button.cpp
index a8ed3d0270..ab6662e6ef 100644
--- a/plugins/TopToolBar/button.c
+++ b/plugins/TopToolBar/button.cpp
@@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// TODO:
// - Support for bitmap buttons (simple call to DrawIconEx())
-static LRESULT CALLBACK MButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-
typedef struct {
HWND hwnd;
int stateId; // button state
@@ -53,34 +51,13 @@ static HRESULT (WINAPI *MyDrawThemeText)(HANDLE,HDC,int,int,LPCWSTR,int,DWORD,D
static CRITICAL_SECTION csTips;
static HWND hwndToolTips = NULL;
-int UnloadButtonModule(WPARAM wParam, LPARAM lParam) {
- DeleteCriticalSection(&csTips);
- return 0;
-}
-
-int LoadButtonModule(void) {
- WNDCLASSEX wc;
-
- ZeroMemory(&wc, sizeof(wc));
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = MYMIRANDABUTTONCLASS;
- wc.lpfnWndProc = MButtonWndProc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.cbWndExtra = sizeof(MButtonCtrl*);
- wc.hbrBackground = 0;
- wc.style = CS_GLOBALCLASS;
- RegisterClassEx(&wc);
- InitializeCriticalSection(&csTips);
- HookEvent(ME_SYSTEM_SHUTDOWN, UnloadButtonModule);
- return 0;
-}
-
// Used for our own cheap TrackMouseEvent
#define BUTTON_POLLID 100
#define BUTTON_POLLDELAY 50
#define MGPROC(x) GetProcAddress(themeAPIHandle,x)
-static int ThemeSupport() {
+static int ThemeSupport()
+{
if (IsWinVerXPPlus()) {
if (!themeAPIHandle) {
themeAPIHandle = GetModuleHandle("uxtheme");
@@ -94,19 +71,15 @@ static int ThemeSupport() {
}
}
// Make sure all of these methods are valid (i would hope either all or none work)
- if (MyOpenThemeData
- &&MyCloseThemeData
- &&MyIsThemeBackgroundPartiallyTransparent
- &&MyDrawThemeParentBackground
- &&MyDrawThemeBackground
- &&MyDrawThemeText) {
+ if (MyOpenThemeData && MyCloseThemeData && MyIsThemeBackgroundPartiallyTransparent &&
+ MyDrawThemeParentBackground && MyDrawThemeBackground && MyDrawThemeText)
return 1;
- }
}
return 0;
}
-static void DestroyTheme(MButtonCtrl *ctl) {
+static void DestroyTheme(MButtonCtrl *ctl)
+{
if (ThemeSupport()) {
if (ctl->hThemeButton) {
MyCloseThemeData(ctl->hThemeButton);
@@ -119,7 +92,8 @@ static void DestroyTheme(MButtonCtrl *ctl) {
}
}
-static void LoadTheme(MButtonCtrl *ctl) {
+static void LoadTheme(MButtonCtrl *ctl)
+{
if (ThemeSupport()) {
DestroyTheme(ctl);
ctl->hThemeButton = MyOpenThemeData(ctl->hwnd,L"BUTTON");
@@ -127,7 +101,8 @@ static void LoadTheme(MButtonCtrl *ctl) {
}
}
-static int TBStateConvert2Flat(int state) {
+static int TBStateConvert2Flat(int state)
+{
switch(state) {
case PBS_NORMAL: return TS_NORMAL;
case PBS_HOT: return TS_HOT;
@@ -138,17 +113,15 @@ static int TBStateConvert2Flat(int state) {
return TS_NORMAL;
}
-static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint) {
+static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint)
+{
if (hdcPaint) {
- HDC hdcMem;
- HBITMAP hbmMem;
- HDC hOld;
RECT rcClient;
-
GetClientRect(ctl->hwnd, &rcClient);
- hdcMem = CreateCompatibleDC(hdcPaint);
- hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top);
- hOld = SelectObject(hdcMem, hbmMem);
+
+ HDC hdcMem = (HDC)CreateCompatibleDC(hdcPaint);
+ HBITMAP hbmMem = (HBITMAP)CreateCompatibleBitmap(hdcPaint, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top);
+ HDC hOld = (HDC)SelectObject(hdcMem, hbmMem);
// If its a push button, check to see if it should stay pressed
if (ctl->pushBtn && ctl->pbState) ctl->stateId = PBS_PRESSED;
@@ -220,18 +193,14 @@ static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint) {
ix++;
iy++;
}
- {
- HIMAGELIST hImageList;
- HICON hIconNew;
-
- hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), IsWinVerXPPlus()? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0);
- ImageList_AddIcon(hImageList, ctl->hIcon);
- hIconNew = ImageList_GetIcon(hImageList, 0, ILD_NORMAL);
- DrawState(hdcMem,NULL,NULL,(LPARAM)hIconNew,0,ix,iy,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),IsWindowEnabled(ctl->hwnd)?DST_ICON|DSS_NORMAL:DST_ICON|DSS_DISABLED);
- ImageList_RemoveAll(hImageList);
- ImageList_Destroy(hImageList);
- DestroyIcon(hIconNew);
- }
+
+ HIMAGELIST hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), IsWinVerXPPlus()? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0);
+ ImageList_AddIcon(hImageList, ctl->hIcon);
+ HICON hIconNew = ImageList_GetIcon(hImageList, 0, ILD_NORMAL);
+ DrawState(hdcMem,NULL,NULL,(LPARAM)hIconNew,0,ix,iy,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),IsWindowEnabled(ctl->hwnd)?DST_ICON|DSS_NORMAL:DST_ICON|DSS_DISABLED);
+ ImageList_RemoveAll(hImageList);
+ ImageList_Destroy(hImageList);
+ DestroyIcon(hIconNew);
}
else if (ctl->hBitmap) {
BITMAP bminfo;
@@ -251,12 +220,11 @@ static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint) {
char szText[MAX_PATH];
SIZE sz;
RECT rcText;
- HFONT hOldFont;
-
CopyRect(&rcText, &rcClient);
+
GetWindowText(ctl->hwnd, szText, sizeof(szText));
SetBkMode(hdcMem, TRANSPARENT);
- hOldFont = SelectObject(hdcMem, ctl->hFont);
+ HFONT hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
// XP w/themes doesn't used the glossy disabled text. Is it always using COLOR_GRAYTEXT? Seems so.
SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd)||!ctl->hThemeButton?GetSysColor(COLOR_BTNTEXT):GetSysColor(COLOR_GRAYTEXT));
GetTextExtentPoint32(hdcMem, szText, lstrlen(szText), &sz);
@@ -277,104 +245,77 @@ static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint) {
SelectObject(hdcMem, hOld);
DeleteObject(hbmMem);
DeleteDC(hdcMem);
-
}
}
-static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
+static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
MButtonCtrl* bct = (MButtonCtrl *)GetWindowLong(hwndDlg, 0);
switch(msg) {
case WM_NCCREATE:
- {
- SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLong(hwndDlg, GWL_STYLE)|BS_OWNERDRAW);
- bct = malloc(sizeof(MButtonCtrl));
- if (bct==NULL) return FALSE;
- bct->hwnd = hwndDlg;
- bct->stateId = PBS_NORMAL;
- bct->focus = 0;
- bct->hFont = GetStockObject(DEFAULT_GUI_FONT);
- bct->arrow = NULL;
- bct->defbutton = 0;
- bct->hIcon = NULL;
- bct->hBitmap = NULL;
- bct->pushBtn = 0;
- bct->pbState = 0;
- bct->hThemeButton = NULL;
- bct->hThemeToolbar = NULL;
- bct->cHot = 0;
- bct->flatBtn = 0;
- LoadTheme(bct);
- SetWindowLong(hwndDlg, 0, (LONG)bct);
- if (((CREATESTRUCT *)lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *)lParam)->lpszName);
- return TRUE;
- }
- case WM_DESTROY:
- {
- if (bct) {
- EnterCriticalSection(&csTips);
- if (hwndToolTips) {
- TOOLINFO ti;
-
- ZeroMemory(&ti, sizeof(ti));
- ti.cbSize = sizeof(ti);
- ti.uFlags = TTF_IDISHWND;
- ti.hwnd = bct->hwnd;
- ti.uId = (UINT)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;
- }
+ SetWindowLong(hwndDlg, GWL_STYLE, GetWindowLong(hwndDlg, GWL_STYLE)|BS_OWNERDRAW);
+ bct = (MButtonCtrl*)malloc(sizeof(MButtonCtrl));
+ if (bct == NULL)
+ return FALSE;
+
+ bct->hwnd = hwndDlg;
+ bct->stateId = PBS_NORMAL;
+ bct->focus = 0;
+ bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+ bct->arrow = NULL;
+ bct->defbutton = 0;
+ bct->hIcon = NULL;
+ bct->hBitmap = NULL;
+ bct->pushBtn = 0;
+ bct->pbState = 0;
+ bct->hThemeButton = NULL;
+ bct->hThemeToolbar = NULL;
+ bct->cHot = 0;
+ bct->flatBtn = 0;
+ LoadTheme(bct);
+ SetWindowLong(hwndDlg, 0, (LONG)bct);
+ if (((CREATESTRUCT *)lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *)lParam)->lpszName);
+ return TRUE;
+
+ case WM_SETTEXT:
+ bct->cHot = 0;
+ if ((char*)lParam) {
+ char *tmp = (char*)lParam;
+ while (*tmp) {
+ if (*tmp=='&' && *(tmp+1)) {
+ bct->cHot = tolower(*(tmp+1));
+ break;
}
- LeaveCriticalSection(&csTips);
- DestroyTheme(bct);
- free(bct);
+ tmp++;
}
- SetWindowLong(hwndDlg,0,(LONG)NULL);
- break; // DONT! fall thru
+ InvalidateRect(bct->hwnd, NULL, TRUE);
}
- case WM_SETTEXT:
- {
- bct->cHot = 0;
- if ((char*)lParam) {
- char *tmp = (char*)lParam;
- while (*tmp) {
- if (*tmp=='&' && *(tmp+1)) {
- bct->cHot = tolower(*(tmp+1));
- break;
- }
- tmp++;
- }
+ break;
+
+ 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);
}
- break;
- }
- 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;
- }
- break;
- case WM_THEMECHANGED: {
- // themed changed, reload theme object
- LoadTheme(bct);
- InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
- break;
- }
- case WM_SETFONT: // remember the font so we can use it later
- {
- bct->hFont = (HFONT)wParam; // maybe we should redraw?
- break;
+ SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
+ return 0;
}
- case WM_NCPAINT:
- case WM_PAINT:
+ break;
+
+ case WM_THEMECHANGED:
+ // themed changed, reload theme object
+ LoadTheme(bct);
+ InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
+ break;
+
+ case WM_SETFONT: // remember the font so we can use it later
+ bct->hFont = (HFONT)wParam; // maybe we should redraw?
+ break;
+
+ case WM_NCPAINT:
+ case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdcPaint;
@@ -384,158 +325,211 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
PaintWorker(bct, hdcPaint);
EndPaint(hwndDlg, &ps);
}
- break;
}
- case BM_SETIMAGE:
- if (wParam == IMAGE_ICON) {
- bct->hIcon = (HICON)lParam;
- bct->hBitmap = NULL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- else if (wParam == IMAGE_BITMAP) {
- bct->hBitmap = (HBITMAP)lParam;
- bct->hIcon = 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;
- }
+ break;
+
+ case BM_SETIMAGE:
+ if (wParam == IMAGE_ICON) {
+ bct->hIcon = (HICON)lParam;
+ bct->hBitmap = NULL;
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
- if (wParam) {
+ }
+ else if (wParam == IMAGE_BITMAP) {
+ bct->hBitmap = (HBITMAP)lParam;
+ bct->hIcon = 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
+ if (wParam) {
// if (!bct->arrow)
// bct->arrow = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_DOWNARROW),IMAGE_ICON,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0);
+ }
+ else {
+ if (bct->arrow) {
+ DestroyIcon(bct->arrow);
+ bct->arrow = NULL;
}
- else {
- if (bct->arrow) {
- DestroyIcon(bct->arrow);
- bct->arrow = NULL;
- }
- }
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETDEFAULT:
- bct->defbutton = wParam?1:0;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETASPUSHBTN:
- bct->pushBtn = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONSETASFLATBTN:
- bct->flatBtn = 1;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- break;
- case BUTTONADDTOOLTIP:
- {
- TOOLINFO ti;
+ }
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETDEFAULT:
+ bct->defbutton = wParam?1:0;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETASPUSHBTN:
+ bct->pushBtn = 1;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case BUTTONSETASFLATBTN:
+ bct->flatBtn = 1;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
+ break;
- if (!(char*)wParam) break;
- EnterCriticalSection(&csTips);
- if (!hwndToolTips) {
+ case BUTTONADDTOOLTIP:
+ if (wParam) {
+ EnterCriticalSection(&csTips);
+ if (!hwndToolTips)
hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, "", WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
- }
- ZeroMemory(&ti, sizeof(ti));
+
+ TOOLINFO ti = { 0 };
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_IDISHWND;
ti.hwnd = bct->hwnd;
ti.uId = (UINT)bct->hwnd;
- if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) {
+ if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti))
SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
- }
+
ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
ti.uId = (UINT)bct->hwnd;
ti.lpszText=(char*)wParam;
SendMessage(hwndToolTips,TTM_ADDTOOL,0,(LPARAM)&ti);
- LeaveCriticalSection(&csTips);
- break;
+ LeaveCriticalSection(&csTips);
}
- 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_WINDOWPOSCHANGED:
+ 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_WINDOWPOSCHANGED:
+ 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_ENABLE: // windows tells us to enable/disable
- {
- bct->stateId = wParam?PBS_NORMAL:PBS_DISABLED;
+ }
+ break;
+
+ case WM_LBUTTONDOWN:
+ if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
+ bct->stateId = PBS_PRESSED;
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;
+ break;
+
+ case WM_LBUTTONUP:
+ if (bct->pushBtn) {
+ if (bct->pbState) bct->pbState = 0;
+ else bct->pbState = 1;
}
- case WM_LBUTTONDOWN:
- {
- if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
- bct->stateId = PBS_PRESSED;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- break;
+ if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
+ if (msg==WM_LBUTTONUP) bct->stateId = PBS_HOT;
+ else bct->stateId = PBS_NORMAL;
+ InvalidateRect(bct->hwnd, NULL, TRUE);
}
- case WM_LBUTTONUP:
- {
- 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 (msg==WM_LBUTTONUP) bct->stateId = PBS_HOT;
- else bct->stateId = PBS_NORMAL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
+ // Tell your daddy you got clicked.
+ 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);
+ }
+ // Call timer, used to start cheesy TrackMouseEvent faker
+ SetTimer(hwndDlg,BUTTON_POLLID,BUTTON_POLLDELAY,NULL);
+ break;
+
+ case WM_TIMER: // use a timer to check if they have did a mouseout
+ if (wParam==BUTTON_POLLID) {
+ RECT rc;
+ POINT pt;
+ GetWindowRect(hwndDlg,&rc);
+ GetCursorPos(&pt);
+ if(!PtInRect(&rc,pt)) { // mouse must be gone, trigger mouse leave
+ PostMessage(hwndDlg,WM_MOUSELEAVE,0,0L);
+ KillTimer(hwndDlg,BUTTON_POLLID);
}
- // Tell your daddy you got clicked.
- 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);
+ break;
+
+ case WM_ERASEBKGND:
+ return 1;
+
+ case WM_DESTROY:
+ if (bct) {
+ EnterCriticalSection(&csTips);
+ if (hwndToolTips) {
+ TOOLINFO ti = { 0 };
+ ti.cbSize = sizeof(ti);
+ ti.uFlags = TTF_IDISHWND;
+ ti.hwnd = bct->hwnd;
+ ti.uId = (UINT)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;
+ }
}
- // Call timer, used to start cheesy TrackMouseEvent faker
- SetTimer(hwndDlg,BUTTON_POLLID,BUTTON_POLLDELAY,NULL);
- break;
- case WM_TIMER: // use a timer to check if they have did a mouseout
- {
- if (wParam==BUTTON_POLLID) {
- RECT rc;
- POINT pt;
- GetWindowRect(hwndDlg,&rc);
- GetCursorPos(&pt);
- if(!PtInRect(&rc,pt)) { // mouse must be gone, trigger mouse leave
- PostMessage(hwndDlg,WM_MOUSELEAVE,0,0L);
- KillTimer(hwndDlg,BUTTON_POLLID);
- }
- }
- break;
+ LeaveCriticalSection(&csTips);
+ DestroyTheme(bct);
+ free(bct);
}
- case WM_ERASEBKGND:
- return 1;
+ SetWindowLong(hwndDlg,0,(LONG)NULL);
+ break; // DONT! fall thru
}
return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
+
+int UnloadButtonModule(WPARAM wParam, LPARAM lParam)
+{
+ DeleteCriticalSection(&csTips);
+ return 0;
+}
+
+int LoadButtonModule(void)
+{
+ WNDCLASSEX wc;
+
+ ZeroMemory(&wc, sizeof(wc));
+ wc.cbSize = sizeof(wc);
+ wc.lpszClassName = MYMIRANDABUTTONCLASS;
+ wc.lpfnWndProc = MButtonWndProc;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.cbWndExtra = sizeof(MButtonCtrl*);
+ wc.hbrBackground = 0;
+ wc.style = CS_GLOBALCLASS;
+ RegisterClassEx(&wc);
+ InitializeCriticalSection(&csTips);
+ HookEvent(ME_SYSTEM_SHUTDOWN, UnloadButtonModule);
+ return 0;
+}
diff --git a/plugins/TopToolBar/buttonopt.c b/plugins/TopToolBar/buttonopt.c
deleted file mode 100644
index b1d8275953..0000000000
--- a/plugins/TopToolBar/buttonopt.c
+++ /dev/null
@@ -1,340 +0,0 @@
-#include "common.h"
-#pragma hdrstop
-
-extern HINSTANCE hInst;
-
-char *DBGetString(HANDLE hContact,const char *szModule,const char *szSetting)
-{
- char *str=NULL;
- DBVARIANT dbv;
- DBGetContactSetting(hContact,szModule,szSetting,&dbv);
- if(dbv.type==DBVT_ASCIIZ)
- str=strdup(dbv.pszVal);
- DBFreeVariant(&dbv);
- return str;
-}
-
-
-
-
-struct OrderData {
- int dragging;
- HTREEITEM hDragItem;
-};
-
-
-
-int CheckButtonOrder()
-{
- boolean protochanged=FALSE;
- int StoredButCount;
- int i,count;
- int v;
- char buf[10];
- char buf2[10];
-
- //curproto=0;
- //curproto[1]='22';
-
- StoredButCount=DBGetContactSettingByte(0,TTB_OPTDIR,"ButCount",-1);
- if (StoredButCount==-1){protochanged=TRUE;};
- if (protochanged)
- {
- //reseting all settings;
-
- CallService(MS_PROTO_ENUMPROTOCOLS,(WPARAM)&count,(LPARAM)&protos);
-
- v=0;
- for(i=0;i<count;i++) {
- if(protos[i]->type!=PROTOTYPE_PROTOCOL || CallProtoService(protos[i]->szName,PS_GETCAPS,PFLAGNUM_2,0)==0) continue;
- itoa(v,&buf,10);
- DBWriteContactSettingString(0,"Protocols",&buf,protos[i]->szName);
-
- itoa(OFFSET_VISIBLE+v,&buf,10);//save default visible status
- DBWriteContactSettingByte(0,"Protocols",&buf,1);
-
- v++;
- };
- DBWriteContactSettingByte(0,TTB_OPTDIR,"ButCount",v);
- return(1);
- }
- else
- {
- return(0);
- };
-
-
-
-};
-
-
-
-static BOOL CALLBACK ProtocolOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{ struct ProtocolOrderData *dat;
-
- dat=(struct ProtocolOrderData*)GetWindowLong(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),GWL_USERDATA);
-
- switch (msg)
- {
- case WM_INITDIALOG: {
- PROTOCOLDESCRIPTOR **protos;
- TVINSERTSTRUCT tvis;
- ProtocolData *PD;
- char szName[64];
- char *szSTName;
- char buf[10];
- int i,count;
-
- dat=(struct ProtocolOrderData*)malloc(sizeof(struct ProtocolOrderData));
- SetWindowLong(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),GWL_USERDATA,(LONG)dat);
- dat->dragging=0;
-
- SetWindowLong(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY),GWL_STYLE,GetWindowLong(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY),GWL_STYLE)|TVS_NOHSCROLL);
- SetWindowLong(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),GWL_STYLE,GetWindowLong(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),GWL_STYLE)|TVS_NOHSCROLL);
-
- { HIMAGELIST himlCheckBoxes;
- himlCheckBoxes=ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_COLOR4|ILC_MASK,2,2);
- ImageList_AddIcon(himlCheckBoxes,LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_NOTICK)));
- ImageList_AddIcon(himlCheckBoxes,LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_TICK)));
- TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY),himlCheckBoxes,TVSIL_NORMAL);
- //
- TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),himlCheckBoxes,TVSIL_NORMAL);
-
- }
-
- tvis.hParent=NULL;
- tvis.hInsertAfter=TVI_LAST;
- tvis.item.mask=TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
-
- CheckProtocolOrder();
-
- count=DBGetContactSettingByte(0,"Protocols","ProtoCount",-1);
- if (count==-1){return(FALSE);};
-
- for(i=0;i<count;i++) {
- //if(protos[i]->type!=PROTOTYPE_PROTOCOL || CallProtoService(protos[i]->szName,PS_GETCAPS,PFLAGNUM_2,0)==0) continue;
- itoa(i,&buf,10);
- szSTName=DBGetString(0,"Protocols",&buf);
- if (szSTName==NULL){continue;};
-
- CallProtoService(szSTName,PS_GETNAME,sizeof(szName),(LPARAM)szName);
- PD=(ProtocolData*)malloc(sizeof(ProtocolData));
-
-
- PD->RealName=szSTName;
-
- itoa(OFFSET_VISIBLE+i,&buf,10);
- PD->show=DBGetContactSettingByte(0,"Protocols",&buf,1);
-
- itoa(OFFSET_PROTOPOS+i,&buf,10);
- PD->protopos=DBGetContactSettingByte(0,"Protocols",&buf,-1);
-
- tvis.item.lParam=(LPARAM)PD;
- tvis.item.pszText=Translate(szName);
- tvis.item.iImage=tvis.item.iSelectedImage=PD->show;
- TreeView_InsertItem(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&tvis);
- tvis.item.iImage=tvis.item.iSelectedImage=PD->show;
- TreeView_InsertItem(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY),&tvis);
-
- //free(szSTName);
- }
- return TRUE;
- }
- case WM_NOTIFY:
- switch(((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code)
- {
- case PSN_APPLY:
- {
- TVITEM tvi;
- PROTOCOLDESCRIPTOR **protos;
- int count;
- char idstr[33];
- char buf[10];
-
- /*
- tvi.hItem=TreeView_GetRoot(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY));
- tvi.cchTextMax=32;
- tvi.mask=TVIF_TEXT|TVIF_IMAGE|TVIF_PARAM|TVIF_HANDLE;
- tvi.pszText=&idstr;
- //count=0;
- while(tvi.hItem!=NULL) {
- itoa(OFFSET_VISIBLE+count,&buf,10);
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY),&tvi);
- DBWriteContactSettingByte(NULL,"Protocols",&buf,(byte)tvi.iImage);
- tvi.hItem=TreeView_GetNextSibling(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY),tvi.hItem);
- //count++;
- }
- */
- tvi.hItem=TreeView_GetRoot(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER));
- tvi.cchTextMax=32;
- tvi.mask=TVIF_TEXT|TVIF_PARAM|TVIF_HANDLE;
- tvi.pszText=&idstr;
- //CallService(MS_PROTO_ENUMPROTOCOLS,(WPARAM)&count,(LPARAM)&protos);
- //count--;
- count=0;
-
- while(tvi.hItem!=NULL) {
- itoa(count,buf,10);
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&tvi);
- DBWriteContactSettingString(NULL,"Protocols",&buf,((ProtocolData *)tvi.lParam)->RealName);
-
- itoa(OFFSET_PROTOPOS+count,&buf,10);//save pos in protos
- DBWriteContactSettingByte(0,"Protocols",&buf,((ProtocolData *)tvi.lParam)->protopos);
-
- itoa(OFFSET_VISIBLE+count,&buf,10);//save pos in protos
- DBWriteContactSettingByte(0,"Protocols",&buf,((ProtocolData *)tvi.lParam)->show);
-
- tvi.hItem=TreeView_GetNextSibling(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),tvi.hItem);
-
- count++;
- }
- CluiProtocolStatusChanged(0,0);
- }
- }
- break;
- /*
- case IDC_PROTOCOLORDER: //IDC_PROTOCOLVISIBILITY:
- if(((LPNMHDR)lParam)->code==NM_CLICK) {
- TVHITTESTINFO hti;
- hti.pt.x=(short)LOWORD(GetMessagePos());
- hti.pt.y=(short)HIWORD(GetMessagePos());
- ScreenToClient(((LPNMHDR)lParam)->hwndFrom,&hti.pt);
- if(TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom,&hti))
- if(hti.flags&TVHT_ONITEMICON) {
- TVITEM tvi;
- tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
- tvi.hItem=hti.hItem;
- TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom,&tvi);
- tvi.iImage=tvi.iSelectedImage=!tvi.iImage;
- ((ProtocolData *)tvi.lParam)->show=tvi.iImage;
- TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom,&tvi);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- ShowWindow(GetDlgItem(hwndDlg,IDC_PROTOCOLORDERWARNING),SW_SHOW);
- }
- }
- break;
- */
- case IDC_PROTOCOLORDER:
- switch (((LPNMHDR)lParam)->code) {
- case TVN_BEGINDRAG:
- SetCapture(hwndDlg);
- dat->dragging=1;
- dat->hDragItem=((LPNMTREEVIEW)lParam)->itemNew.hItem;
- TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),dat->hDragItem);
- //ShowWindow(GetDlgItem(hwndDlg,IDC_PROTOCOLORDERWARNING),SW_SHOW);
- break;
- case NM_CLICK:
- {
-
- TVHITTESTINFO hti;
- hti.pt.x=(short)LOWORD(GetMessagePos());
- hti.pt.y=(short)HIWORD(GetMessagePos());
- ScreenToClient(((LPNMHDR)lParam)->hwndFrom,&hti.pt);
- if(TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom,&hti))
- if(hti.flags&TVHT_ONITEMICON) {
- TVITEM tvi;
- tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
- tvi.hItem=hti.hItem;
- TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom,&tvi);
- tvi.iImage=tvi.iSelectedImage=!tvi.iImage;
- ((ProtocolData *)tvi.lParam)->show=tvi.iImage;
- TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom,&tvi);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
-
- //all changes take effect in runtime
- //ShowWindow(GetDlgItem(hwndDlg,IDC_PROTOCOLORDERWARNING),SW_SHOW);
- }
-
-
-
- };
- }
- break;
- }
- break;
- case WM_MOUSEMOVE:
- if(!dat->dragging) break;
- { TVHITTESTINFO hti;
- hti.pt.x=(short)LOWORD(lParam);
- hti.pt.y=(short)HIWORD(lParam);
- ClientToScreen(hwndDlg,&hti.pt);
- ScreenToClient(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&hti.pt);
- TreeView_HitTest(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&hti);
- if(hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
- hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER))/2;
- TreeView_HitTest(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&hti);
- TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),hti.hItem,1);
- }
- else {
- if(hti.flags&TVHT_ABOVE) SendDlgItemMessage(hwndDlg,IDC_PROTOCOLORDER,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0);
- if(hti.flags&TVHT_BELOW) SendDlgItemMessage(hwndDlg,IDC_PROTOCOLORDER,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0);
- TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),NULL,0);
- }
- }
- break;
- case WM_LBUTTONUP:
- if(!dat->dragging) break;
- TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),NULL,0);
- dat->dragging=0;
- ReleaseCapture();
- { TVHITTESTINFO hti;
- TVITEM tvi;
- hti.pt.x=(short)LOWORD(lParam);
- hti.pt.y=(short)HIWORD(lParam);
- ClientToScreen(hwndDlg,&hti.pt);
- ScreenToClient(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&hti.pt);
- hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER))/2;
- TreeView_HitTest(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&hti);
- if(dat->hDragItem==hti.hItem) break;
- tvi.mask=TVIF_HANDLE|TVIF_PARAM;
- tvi.hItem=hti.hItem;
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&tvi);
- if(hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
- TVINSERTSTRUCT tvis;
- char name[128];
- tvis.item.mask=TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
- tvis.item.stateMask=0xFFFFFFFF;
- tvis.item.pszText=name;
- tvis.item.cchTextMax=sizeof(name);
- tvis.item.hItem=dat->hDragItem;
- //
- tvis.item.iImage=tvis.item.iSelectedImage=((ProtocolData *)tvi.lParam)->show;
-
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&tvis.item);
-
-
- TreeView_DeleteItem(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),dat->hDragItem);
- tvis.hParent=NULL;
- tvis.hInsertAfter=hti.hItem;
- TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),TreeView_InsertItem(GetDlgItem(hwndDlg,IDC_PROTOCOLORDER),&tvis));
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- }
- break;
- }
- return FALSE;
-}
-
-static int ProtocolOrderInit(WPARAM wParam,LPARAM lParam) {
- OPTIONSDIALOGPAGE odp;
-
- ZeroMemory(&odp,sizeof(odp));
- odp.cbSize=sizeof(odp);
- odp.position=-1000000000;
- odp.hInstance=hInst;//GetModuleHandle(NULL);
- odp.pszTemplate=MAKEINTRESOURCE(IDD_OPT_PROTOCOLORDER);
- odp.pszGroup=Translate("Contact List");
- odp.pszTitle=Translate("Protocols");
- odp.pfnDlgProc=ProtocolOrderOpts;
- odp.flags=ODPF_BOLDGROUPS|ODPF_EXPERTONLY;
- CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&odp);
-
- return 0;
-}
-
-int LoadProtocolOrderModule(void) {
- HookEvent(ME_OPT_INITIALISE,ProtocolOrderInit);
- return 0;
-} \ No newline at end of file
diff --git a/plugins/TopToolBar/buttonopt.cpp b/plugins/TopToolBar/buttonopt.cpp
new file mode 100644
index 0000000000..99f7c0f9de
--- /dev/null
+++ b/plugins/TopToolBar/buttonopt.cpp
@@ -0,0 +1,323 @@
+#include "common.h"
+
+#define OFFSET_PROTOPOS 200
+#define OFFSET_VISIBLE 400
+
+extern HINSTANCE hInst;
+
+struct OrderData {
+ int dragging;
+ HTREEITEM hDragItem;
+};
+
+char *MyDbGetString(HANDLE hContact, const char *szModule, const char *szSetting)
+{
+ char *str = NULL;
+ DBVARIANT dbv;
+ DBGetContactSetting(hContact, szModule, szSetting, &dbv);
+ if (dbv.type == DBVT_ASCIIZ)
+ str = strdup(dbv.pszVal);
+ DBFreeVariant(&dbv);
+ return str;
+}
+
+int CheckButtonOrder()
+{
+ bool protochanged = FALSE;
+ char buf[10];
+ char buf2[10];
+
+ int StoredButCount = DBGetContactSettingByte(0, TTB_OPTDIR, "ButCount", -1);
+ if (StoredButCount == -1)
+ protochanged = TRUE;
+ if (protochanged) {
+ //reseting all settings;
+ PROTOCOLDESCRIPTOR **protos;
+ int count;
+ CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&count, (LPARAM)&protos);
+
+ int v = 0;
+ for (int i = 0;i<count;i++) {
+ if (protos[i]->type != PROTOTYPE_PROTOCOL || CallProtoService(protos[i]->szName, PS_GETCAPS, PFLAGNUM_2, 0) == 0) continue;
+ itoa(v, buf, 10);
+ DBWriteContactSettingString(0, "Protocols", buf, protos[i]->szName);
+
+ itoa(OFFSET_VISIBLE+v, buf, 10);//save default visible status
+ DBWriteContactSettingByte(0, "Protocols", buf, 1);
+ v++;
+ }
+
+ DBWriteContactSettingByte(0, TTB_OPTDIR, "ButCount", v);
+ return 1;
+ }
+
+ return 0;
+}
+
+static BOOL CALLBACK ProtocolOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ ProtocolOrderData *dat = (ProtocolOrderData*)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), GWL_USERDATA);
+
+ switch (msg) {
+ case WM_INITDIALOG: {
+ PROTOCOLDESCRIPTOR **protos;
+ TVINSERTSTRUCT tvis;
+ ProtocolData *PD;
+ char szName[64];
+ char *szSTName;
+ char buf[10];
+ int i, count;
+
+ dat = (struct ProtocolOrderData*)malloc(sizeof(struct ProtocolOrderData));
+ SetWindowLong(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), GWL_USERDATA, (LONG)dat);
+ dat->dragging = 0;
+
+ SetWindowLong(GetDlgItem(hwndDlg, IDC_PROTOCOLVISIBILITY), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PROTOCOLVISIBILITY), GWL_STYLE)|TVS_NOHSCROLL);
+ SetWindowLong(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), GWL_STYLE)|TVS_NOHSCROLL);
+
+ { HIMAGELIST himlCheckBoxes;
+ himlCheckBoxes = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR4|ILC_MASK, 2, 2);
+ ImageList_AddIcon(himlCheckBoxes, LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_NOTICK)));
+ ImageList_AddIcon(himlCheckBoxes, LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TICK)));
+ TreeView_SetImageList(GetDlgItem(hwndDlg, IDC_PROTOCOLVISIBILITY), himlCheckBoxes, TVSIL_NORMAL);
+ //
+ TreeView_SetImageList(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), himlCheckBoxes, TVSIL_NORMAL);
+
+ }
+
+ tvis.hParent = NULL;
+ tvis.hInsertAfter = TVI_LAST;
+ tvis.item.mask = TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+
+ CheckProtocolOrder();
+
+ count = DBGetContactSettingByte(0, "Protocols", "ProtoCount", -1);
+ if (count == -1){return(FALSE);}
+
+ for (i = 0;i<count;i++) {
+ //if (protos[i]->type != PROTOTYPE_PROTOCOL || CallProtoService(protos[i]->szName, PS_GETCAPS, PFLAGNUM_2, 0) == 0) continue;
+ itoa(i, &buf, 10);
+ szSTName = MyDbGetString(0, "Protocols", &buf);
+ if (szSTName == NULL){continue;}
+
+ CallProtoService(szSTName, PS_GETNAME, sizeof(szName), (LPARAM)szName);
+ PD = (ProtocolData*)malloc(sizeof(ProtocolData));
+
+
+ PD->RealName = szSTName;
+
+ itoa(OFFSET_VISIBLE+i, buf, 10);
+ PD->show = DBGetContactSettingByte(0, "Protocols", buf, 1);
+
+ itoa(OFFSET_PROTOPOS+i, buf, 10);
+ PD->protopos = DBGetContactSettingByte(0, "Protocols", buf, -1);
+
+ tvis.item.lParam = (LPARAM)PD;
+ tvis.item.pszText = Translate(szName);
+ tvis.item.iImage = tvis.item.iSelectedImage = PD->show;
+ TreeView_InsertItem(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &tvis);
+ tvis.item.iImage = tvis.item.iSelectedImage = PD->show;
+ TreeView_InsertItem(GetDlgItem(hwndDlg, IDC_PROTOCOLVISIBILITY), &tvis);
+
+ //free(szSTName);
+ }
+ return TRUE;
+ }
+ case WM_NOTIFY:
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ switch (((LPNMHDR)lParam)->code)
+ {
+ case PSN_APPLY:
+ {
+ TVITEM tvi;
+ PROTOCOLDESCRIPTOR **protos;
+ int count;
+ char idstr[33];
+ char buf[10];
+
+ /*
+ tvi.hItem = TreeView_GetRoot(GetDlgItem(hwndDlg, IDC_PROTOCOLVISIBILITY));
+ tvi.cchTextMax = 32;
+ tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_PARAM|TVIF_HANDLE;
+ tvi.pszText = &idstr;
+ //count = 0;
+ while(tvi.hItem != NULL) {
+ itoa(OFFSET_VISIBLE+count, &buf, 10);
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_PROTOCOLVISIBILITY), &tvi);
+ DBWriteContactSettingByte(NULL, "Protocols", &buf, (byte)tvi.iImage);
+ tvi.hItem = TreeView_GetNextSibling(GetDlgItem(hwndDlg, IDC_PROTOCOLVISIBILITY), tvi.hItem);
+ //count++;
+ }
+ */
+ tvi.hItem = TreeView_GetRoot(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER));
+ tvi.cchTextMax = 32;
+ tvi.mask = TVIF_TEXT|TVIF_PARAM|TVIF_HANDLE;
+ tvi.pszText = &idstr;
+ //CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&count, (LPARAM)&protos);
+ //count--;
+ count = 0;
+
+ while(tvi.hItem != NULL) {
+ itoa(count, buf, 10);
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &tvi);
+ DBWriteContactSettingString(NULL, "Protocols", &buf, ((ProtocolData *)tvi.lParam)->RealName);
+
+ itoa(OFFSET_PROTOPOS+count, &buf, 10);//save pos in protos
+ DBWriteContactSettingByte(0, "Protocols", &buf, ((ProtocolData *)tvi.lParam)->protopos);
+
+ itoa(OFFSET_VISIBLE+count, &buf, 10);//save pos in protos
+ DBWriteContactSettingByte(0, "Protocols", &buf, ((ProtocolData *)tvi.lParam)->show);
+
+ tvi.hItem = TreeView_GetNextSibling(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), tvi.hItem);
+
+ count++;
+ }
+ CluiProtocolStatusChanged(0, 0);
+ }
+ }
+ break;
+ /*
+ case IDC_PROTOCOLORDER: //IDC_PROTOCOLVISIBILITY:
+ if (((LPNMHDR)lParam)->code == NM_CLICK) {
+ TVHITTESTINFO hti;
+ hti.pt.x = (short)LOWORD(GetMessagePos());
+ hti.pt.y = (short)HIWORD(GetMessagePos());
+ ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
+ if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti))
+ if (hti.flags&TVHT_ONITEMICON) {
+ TVITEM tvi;
+ tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+ tvi.hItem = hti.hItem;
+ TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
+ tvi.iImage = tvi.iSelectedImage = !tvi.iImage;
+ ((ProtocolData *)tvi.lParam)->show = tvi.iImage;
+ TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_PROTOCOLORDERWARNING), SW_SHOW);
+ }
+ }
+ break;
+ */
+ case IDC_PROTOCOLORDER:
+ switch (((LPNMHDR)lParam)->code) {
+ case TVN_BEGINDRAG:
+ SetCapture(hwndDlg);
+ dat->dragging = 1;
+ dat->hDragItem = ((LPNMTREEVIEW)lParam)->itemNew.hItem;
+ TreeView_SelectItem(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), dat->hDragItem);
+ //ShowWindow(GetDlgItem(hwndDlg, IDC_PROTOCOLORDERWARNING), SW_SHOW);
+ break;
+ case NM_CLICK:
+ {
+
+ TVHITTESTINFO hti;
+ hti.pt.x = (short)LOWORD(GetMessagePos());
+ hti.pt.y = (short)HIWORD(GetMessagePos());
+ ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
+ if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti))
+ if (hti.flags&TVHT_ONITEMICON) {
+ TVITEM tvi;
+ tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+ tvi.hItem = hti.hItem;
+ TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
+ tvi.iImage = tvi.iSelectedImage = !tvi.iImage;
+ ((ProtocolData *)tvi.lParam)->show = tvi.iImage;
+ TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+
+ //all changes take effect in runtime
+ //ShowWindow(GetDlgItem(hwndDlg, IDC_PROTOCOLORDERWARNING), SW_SHOW);
+ }
+
+
+
+ }
+ }
+ break;
+ }
+ break;
+ case WM_MOUSEMOVE:
+ if (!dat->dragging) break;
+ { TVHITTESTINFO hti;
+ hti.pt.x = (short)LOWORD(lParam);
+ hti.pt.y = (short)HIWORD(lParam);
+ ClientToScreen(hwndDlg, &hti.pt);
+ ScreenToClient(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &hti.pt);
+ TreeView_HitTest(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &hti);
+ if (hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
+ hti.pt.y -= TreeView_GetItemHeight(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER))/2;
+ TreeView_HitTest(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &hti);
+ TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), hti.hItem, 1);
+ }
+ else {
+ if (hti.flags&TVHT_ABOVE) SendDlgItemMessage(hwndDlg, IDC_PROTOCOLORDER, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
+ if (hti.flags&TVHT_BELOW) SendDlgItemMessage(hwndDlg, IDC_PROTOCOLORDER, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
+ TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), NULL, 0);
+ }
+ }
+ break;
+ case WM_LBUTTONUP:
+ if (!dat->dragging) break;
+ TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), NULL, 0);
+ dat->dragging = 0;
+ ReleaseCapture();
+ { TVHITTESTINFO hti;
+ TVITEM tvi;
+ hti.pt.x = (short)LOWORD(lParam);
+ hti.pt.y = (short)HIWORD(lParam);
+ ClientToScreen(hwndDlg, &hti.pt);
+ ScreenToClient(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &hti.pt);
+ hti.pt.y -= TreeView_GetItemHeight(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER))/2;
+ TreeView_HitTest(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &hti);
+ if (dat->hDragItem == hti.hItem) break;
+ tvi.mask = TVIF_HANDLE|TVIF_PARAM;
+ tvi.hItem = hti.hItem;
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &tvi);
+ if (hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
+ TVINSERTSTRUCT tvis;
+ char name[128];
+ tvis.item.mask = TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+ tvis.item.stateMask = 0xFFFFFFFF;
+ tvis.item.pszText = name;
+ tvis.item.cchTextMax = sizeof(name);
+ tvis.item.hItem = dat->hDragItem;
+ //
+ tvis.item.iImage = tvis.item.iSelectedImage = ((ProtocolData *)tvi.lParam)->show;
+
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &tvis.item);
+
+
+ TreeView_DeleteItem(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), dat->hDragItem);
+ tvis.hParent = NULL;
+ tvis.hInsertAfter = hti.hItem;
+ TreeView_SelectItem(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), TreeView_InsertItem(GetDlgItem(hwndDlg, IDC_PROTOCOLORDER), &tvis));
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+static int ProtocolOrderInit(WPARAM wParam, LPARAM lParam) {
+ OPTIONSDIALOGPAGE odp;
+
+ ZeroMemory(&odp, sizeof(odp));
+ odp.cbSize = sizeof(odp);
+ odp.position = -1000000000;
+ odp.hInstance = hInst;//GetModuleHandle(NULL);
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_OPT_PROTOCOLORDER);
+ odp.pszGroup = Translate("Contact List");
+ odp.pszTitle = Translate("Protocols");
+ odp.pfnDlgProc = ProtocolOrderOpts;
+ odp.flags = ODPF_BOLDGROUPS|ODPF_EXPERTONLY;
+ CallService(MS_OPT_ADDPAGE, wParam, (LPARAM)&odp);
+
+ return 0;
+}
+
+int LoadProtocolOrderModule(void) {
+ HookEvent(ME_OPT_INITIALISE, ProtocolOrderInit);
+ return 0;
+} \ No newline at end of file
diff --git a/plugins/TopToolBar/common.h b/plugins/TopToolBar/common.h
index 3150ca3a23..92d715701b 100644
--- a/plugins/TopToolBar/common.h
+++ b/plugins/TopToolBar/common.h
@@ -25,6 +25,8 @@
#include "m_langpack.h"
#include "m_options.h"
#include "resource.h"
+#include "m_protocols.h"
+#include "m_protosvc.h"
#include "m_toptoolbar.h"
#include "m_button.h"
#include "m_icolib.h"
@@ -38,9 +40,9 @@
#define TTBDEFAULT_USEBITMAP 0
#define TTBDEFAULT_SELBKCOLOUR GetSysColor(COLOR_HIGHLIGHT)
-int TTBOptInit(WPARAM wParam,LPARAM lParam);
+int TTBOptInit(WPARAM wParam, LPARAM lParam);
//append string
-char __inline *AS(char *str,const char *setting,char *addstr);
+char __inline *AS(char *str, const char *setting, char *addstr);
int ttbOptionsChanged();
@@ -53,13 +55,13 @@ typedef struct {
int id;
BOOL bPushed;
int dwFlags;
- int x,y;
- HBITMAP hbBitmapUp,hbBitmapDown;
- HBITMAP hbDefBitmapUp,hbDefBitmapDown;
- HBITMAP hbWBordBitmapUp,hbWBordBitmapDown;
- HICON hIconUp,hIconDn;
+ int x, y;
+ HBITMAP hbBitmapUp, hbBitmapDown;
+ HBITMAP hbDefBitmapUp, hbDefBitmapDown;
+ HBITMAP hbWBordBitmapUp, hbWBordBitmapDown;
+ HICON hIconUp, hIconDn;
- char *pszServiceUp,*pszServiceDown;
+ char *pszServiceUp, *pszServiceDown;
char *tooltip;
char *name;
@@ -88,34 +90,31 @@ typedef struct tagSortData {
typedef struct tagButtonOptData {
char *name;
int pos;
- boolean show;
+ bool show;
} ButtonOptData;
-boolean OptionsOpened;
-HWND OptionshWnd;
+extern bool OptionsOpened;
+extern HWND OptionshWnd;
+
int OptionsPageRebuild();
void lockbut();
void ulockbut();
-//return - 0 success, -1 on error
+//return - 0 success, -1 on error
#define TTB_ADDSEPARATOR "TTB/AddSeparator"
//wparam sepid
#define TTB_REMOVESEPARATOR "TTB/RemoveSeparator"
//append string
-char *AS(char *str,const char *setting,char *addstr)
+char *AS(char *str, const char *setting, char *addstr)
{
- if(str!=NULL) {
- strcpy(str,setting);
- strcat(str,addstr);
+ if (str != NULL) {
+ strcpy(str, setting);
+ strcat(str, addstr);
}
return str;
-};
-
-
-char *DBGetString(HANDLE hContact,const char *szModule,const char *szSetting);
-
+}
#define TTB_LAUNCHSERVICE "TTB/LaunchSerice"
//wparam -id
@@ -130,16 +129,37 @@ char *DBGetString(HANDLE hContact,const char *szModule,const char *szSetting);
#define TTB_REMOVELBUTTON "TTB/RemoveLButton"
#define MYMIRANDABUTTONCLASS "MyMIRANDABUTTONCLASS"
+int LoadInternalButtons( HWND );
+int UnLoadInternalButtons( void );
+int LoadButtonModule( void );
+
+int SetAllBitmaps( void );
+int SaveAllLButs( void );
+int SaveAllButtonsOptions( void );
+int SaveAllSeparators( void );
int InitLBut();
int UnInitLBut();
+void lockbut();
+void ulockbut();
+int applyuserbitmaps( int );
+
+INT_PTR TTBAddButton(WPARAM, LPARAM);
+INT_PTR TTBRemoveButton(WPARAM, LPARAM);
+INT_PTR DeleteLBut(WPARAM, LPARAM);
+INT_PTR ModifyLButton(WPARAM, LPARAM);
+INT_PTR GetLButton(WPARAM, LPARAM);
+
+INT_PTR InsertLBut(int id);
+
typedef struct
{
-int hframe;
-char *lpath;
-char *name;
-}LBUTOPT;
+ int hframe;
+ char *lpath;
+ char *name;
+}
+ LBUTOPT;
int LoadCLCButtonModule(void);
#define BM_SETPRIVATEICON (WM_USER + 6)
diff --git a/plugins/TopToolBar/launchbt.c b/plugins/TopToolBar/launchbt.c
deleted file mode 100644
index cffce36be0..0000000000
--- a/plugins/TopToolBar/launchbt.c
+++ /dev/null
@@ -1,211 +0,0 @@
-#include "common.h"
-#pragma hdrstop
-
-extern HINSTANCE hInst;
-#define MAXLBUTS 32
-
-LBUTOPT LBUTS[MAXLBUTS];
-static int LButCnt=0;
-
-extern char *AS(char *str,const char *setting,char *addstr);
-//wparam i;
-INT_PTR LaunchService(WPARAM wParam,LPARAM lParam)
-{
- PROCESS_INFORMATION pi;
- STARTUPINFO si={0};
- si.cb=sizeof(si);
- if ((lParam<0)||(lParam>=MAXLBUTS)){return(-1);};
-
- if(CreateProcess(NULL,LBUTS[lParam].lpath,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) {
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- }
- Sleep(20);
-CallService(MS_TTB_SETBUTTONSTATE,LBUTS[lParam].hframe,TTBST_RELEASED);
-return(0);
-};
-
-//wparam -id
-//lparam &LBTOPT
-INT_PTR GetLButton(WPARAM wParam,LPARAM lParam)
-{
- LBUTOPT *lbo=lParam;
- if ((wParam<0)||(wParam>=MAXLBUTS)){return(-1);};
- if (lbo==NULL){return(-1);};
- if (LBUTS[wParam].hframe==0){return(-1);};
- *lbo=LBUTS[wParam];
-
- return(0);
-};
-//wparam -id
-//lparam &LBTOPT
-INT_PTR ModifyLButton(WPARAM wParam,LPARAM lParam)
-{
- LBUTOPT *lbo=lParam;
- if ((wParam<0)||(wParam>=LButCnt)){return(-1);};
- if (lbo==NULL){return(-1);};
-
- if (LBUTS[wParam].hframe==0){return(-1);};
- DeleteLBut(wParam,0);
- if (LBUTS[wParam].lpath!=NULL){free(LBUTS[wParam].lpath);};
- if (LBUTS[wParam].name!=NULL){free(LBUTS[wParam].name);};
- LBUTS[wParam].name=NULL;
- LBUTS[wParam].lpath=NULL;
-
-
- if (lbo->name!=NULL){LBUTS[wParam].name=_strdup(lbo->name);};
- if (lbo->lpath!=NULL){LBUTS[wParam].lpath=_strdup(lbo->lpath);};
-
- LBUTS[wParam].hframe=InsertLBut(wParam);
- SaveAllLButs();
- return(0);
-};
-
-int InsertLBut(int id)
-{
- TTBButton ttb;
-
- HBITMAP DefLUp;
- HBITMAP DefLDn;
-
- DefLDn=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_LAUNCHDN));
- DefLUp=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_LAUNCHUP));
- //itoa(SeparatorCnt++,buf,10);
-
- //wsprintf(buf,"%s %d",Translate("Separator"),id);
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- ttb.hbBitmapDown=DefLDn;
- ttb.hbBitmapUp=DefLUp;
- ttb.dwFlags=TTBBF_VISIBLE|TTBBF_ISLBUTTON;
- ttb.pszServiceDown=TTB_LAUNCHSERVICE;
- //ttb.pszServiceUp=TTB_LAUNCHSERVICE;
- ttb.lParamDown=id;
- ttb.name=LBUTS[id].name;
- LButCnt++;
- return(TTBAddButton(&ttb,0));
-};
-INT_PTR DeleteLBut(WPARAM id,LPARAM lParam)
-{
- if (LBUTS[id].hframe!=0)
- {
- TTBRemoveButton(LBUTS[id].hframe,0);
- LBUTS[id].hframe=0;
- if (LBUTS[id].name!=NULL){free(LBUTS[id].name);};
- if (LBUTS[id].lpath!=NULL){free(LBUTS[id].lpath);};
- LBUTS[id].name=NULL;
- LBUTS[id].lpath=NULL;
-
- LButCnt--;
- };
- return(0);
-};
-
-int LoadAllLButs()
-{
- char buf[255];
- char buf1[10];
- char fixname[255];
- int id,i;
-// char *oldtb;
-
- //must be locked
- memset(buf,0,sizeof(buf));
-
- memset(LBUTS,0,sizeof(LBUTS));
- for (i=0;i<MAXLBUTS;i++)
- {
- memset(buf1,0,sizeof(buf1));
- itoa(i,buf1,10);
- AS(fixname,"LBUT",buf1);
- id=DBGetContactSettingWord(0,TTB_OPTDIR,AS(buf,fixname,""),-1);
- if (id!=-1)
- {
- LBUTS[i].name=DBGetString(0,TTB_OPTDIR,AS(buf,fixname,"_name"));
- LBUTS[i].lpath=DBGetString(0,TTB_OPTDIR,AS(buf,fixname,"_lpath"));
- if (LBUTS[i].lpath==NULL){LBUTS[i].lpath=_strdup("Execute Path");};
- LBUTS[i].hframe=0;
- LBUTS[i].hframe=InsertLBut(i);
- };
- };
- return(0);
-
-};
-
-
-int SaveAllLButs()
-{
- char buf[255];
- char buf1[10];
- char fixname[255];
- int i;
-
- //must be locked
- memset(buf,0,sizeof(buf));
-
- for (i=0;i<MAXLBUTS;i++)
- {
- itoa(i,buf1,10);
- if (LBUTS[i].hframe!=0)
- {
- AS(fixname,"LBUT",buf1);
- DBWriteContactSettingWord(0,TTB_OPTDIR,AS(buf,fixname,""),i);
- DBWriteContactSettingString(0,TTB_OPTDIR,AS(buf,fixname,"_name"),LBUTS[i].name);
- DBWriteContactSettingString(0,TTB_OPTDIR,AS(buf,fixname,"_lpath"),LBUTS[i].lpath);
- }
- else
- {
- AS(fixname,"LBUT",buf1);
- DBWriteContactSettingWord(0,TTB_OPTDIR,AS(buf,fixname,""),-1);
- DBDeleteContactSetting(0,TTB_OPTDIR,AS(buf,fixname,""));
- DBDeleteContactSetting(0,TTB_OPTDIR,AS(buf,fixname,"_lpath"));
- DBDeleteContactSetting(0,TTB_OPTDIR,AS(buf,fixname,"_name"));
- };
- };
- return(0);
-
-};
-
-
-//return 0 on success,-1 on error
-INT_PTR InsertNewFreeLBut(WPARAM wParam,LPARAM lParam)
-{
- char buf[256];
- if (LButCnt<MAXLBUTS)
- {
- int i;
- for (i=0;i<MAXLBUTS;i++)
- {
- if (LBUTS[i].hframe==0)
- {
- wsprintf(buf,"%s %d",Translate("Default"),i);
- LBUTS[i].name=_strdup(buf);
- LBUTS[i].lpath=_strdup("Execute Path");
- LBUTS[i].hframe=InsertLBut(i);
- SaveAllLButs();
- return(0);
- };
- };
- };
-
- return(-1);
-};
-
-int InitLBut()
-{
- CreateServiceFunction(TTB_LAUNCHSERVICE,LaunchService);
- CreateServiceFunction(TTB_ADDLBUTTON,InsertNewFreeLBut);
- CreateServiceFunction(TTB_REMOVELBUTTON,DeleteLBut);
- CreateServiceFunction(TTB_MODIFYLBUTTON,ModifyLButton);
- CreateServiceFunction(TTB_GETLBUTTON,GetLButton);
-
-
-
- LoadAllLButs();
- return(0);
-};
-int UnInitLBut()
-{
- SaveAllLButs();
- return(0);
-}; \ No newline at end of file
diff --git a/plugins/TopToolBar/launchbt.cpp b/plugins/TopToolBar/launchbt.cpp
new file mode 100644
index 0000000000..a5becaeba7
--- /dev/null
+++ b/plugins/TopToolBar/launchbt.cpp
@@ -0,0 +1,218 @@
+#include "common.h"
+#pragma hdrstop
+
+extern HINSTANCE hInst;
+#define MAXLBUTS 32
+
+LBUTOPT LBUTS[MAXLBUTS];
+static int LButCnt = 0;
+
+extern char *AS(char *str, const char *setting, char *addstr);
+
+//wparam -id
+INT_PTR LaunchService(WPARAM wParam, LPARAM lParam)
+{
+ PROCESS_INFORMATION pi;
+ STARTUPINFO si = {0};
+ si.cb = sizeof(si);
+ if ( lParam < 0 || lParam >= MAXLBUTS )
+ return -1;
+
+ if ( CreateProcess(NULL, LBUTS[lParam].lpath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
+ CloseHandle(pi.hProcess);
+ CloseHandle(pi.hThread);
+ }
+ Sleep(20);
+ CallService(MS_TTB_SETBUTTONSTATE, LBUTS[lParam].hframe, TTBST_RELEASED);
+ return 0;
+}
+
+//wparam -id
+//lparam &LBTOPT
+INT_PTR GetLButton(WPARAM wParam, LPARAM lParam)
+{
+ if ( wParam < 0 || wParam >= MAXLBUTS )
+ return -1;
+
+ LBUTOPT *lbo = ( LBUTOPT* )lParam;
+ if (lbo == NULL)
+ return -1;
+
+ if (LBUTS[wParam].hframe == 0)
+ return -1;
+
+ *lbo = LBUTS[wParam];
+ return 0;
+}
+
+//wparam -id
+//lparam &LBTOPT
+INT_PTR ModifyLButton(WPARAM wParam, LPARAM lParam)
+{
+ if ( wParam < 0 || wParam >= LButCnt )
+ return -1;
+
+ LBUTOPT *lbo = ( LBUTOPT* )lParam;
+ if (lbo == NULL)
+ return -1;
+
+ if (LBUTS[wParam].hframe == 0)
+ return -1;
+
+ DeleteLBut(wParam, 0);
+ if (LBUTS[wParam].lpath != NULL){free(LBUTS[wParam].lpath);}
+ if (LBUTS[wParam].name != NULL){free(LBUTS[wParam].name);}
+ LBUTS[wParam].name = NULL;
+ LBUTS[wParam].lpath = NULL;
+
+ if (lbo->name != NULL)
+ LBUTS[wParam].name = _strdup(lbo->name);
+ if (lbo->lpath != NULL)
+ LBUTS[wParam].lpath = _strdup(lbo->lpath);
+
+ LBUTS[wParam].hframe = InsertLBut(wParam);
+ SaveAllLButs();
+ return 0;
+}
+
+int InsertLBut(int id)
+{
+ HBITMAP DefLUp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_LAUNCHDN));
+ HBITMAP DefLDn = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_LAUNCHUP));
+
+ TTBButton ttb = { 0 };
+ ttb.cbSize = sizeof(ttb);
+ ttb.hbBitmapDown = DefLDn;
+ ttb.hbBitmapUp = DefLUp;
+ ttb.dwFlags = TTBBF_VISIBLE|TTBBF_ISLBUTTON;
+ ttb.pszServiceDown = TTB_LAUNCHSERVICE;
+ ttb.lParamDown = id;
+ ttb.name = LBUTS[id].name;
+ LButCnt++;
+ return TTBAddButton(( WPARAM )&ttb, 0);
+}
+
+INT_PTR DeleteLBut(WPARAM id, LPARAM lParam)
+{
+ if (LBUTS[id].hframe != 0)
+ {
+ TTBRemoveButton(LBUTS[id].hframe, 0);
+ LBUTS[id].hframe = 0;
+ if (LBUTS[id].name != NULL){free(LBUTS[id].name);}
+ if (LBUTS[id].lpath != NULL){free(LBUTS[id].lpath);}
+ LBUTS[id].name = NULL;
+ LBUTS[id].lpath = NULL;
+
+ LButCnt--;
+ }
+ return 0;
+}
+
+int LoadAllLButs()
+{
+ char buf[255];
+ char buf1[10];
+ char fixname[255];
+ int id, i;
+// char *oldtb;
+
+ //must be locked
+ memset(buf, 0, sizeof(buf));
+
+ memset(LBUTS, 0, sizeof(LBUTS));
+ for (i = 0;i<MAXLBUTS;i++)
+ {
+ memset(buf1, 0, sizeof(buf1));
+ itoa(i, buf1, 10);
+ AS(fixname, "LBUT", buf1);
+ id = DBGetContactSettingWord(0, TTB_OPTDIR, AS(buf, fixname, ""), -1);
+ if (id != -1)
+ {
+ LBUTS[i].name = DBGetString(0, TTB_OPTDIR, AS(buf, fixname, "_name"));
+ LBUTS[i].lpath = DBGetString(0, TTB_OPTDIR, AS(buf, fixname, "_lpath"));
+ if (LBUTS[i].lpath == NULL){LBUTS[i].lpath = _strdup("Execute Path");}
+ LBUTS[i].hframe = 0;
+ LBUTS[i].hframe = InsertLBut(i);
+ }
+ }
+ return 0;
+
+}
+
+
+int SaveAllLButs()
+{
+ char buf[255];
+ char buf1[10];
+ char fixname[255];
+ int i;
+
+ //must be locked
+ memset(buf, 0, sizeof(buf));
+
+ for (i = 0;i<MAXLBUTS;i++)
+ {
+ itoa(i, buf1, 10);
+ if (LBUTS[i].hframe != 0)
+ {
+ AS(fixname, "LBUT", buf1);
+ DBWriteContactSettingWord(0, TTB_OPTDIR, AS(buf, fixname, ""), i);
+ DBWriteContactSettingString(0, TTB_OPTDIR, AS(buf, fixname, "_name"), LBUTS[i].name);
+ DBWriteContactSettingString(0, TTB_OPTDIR, AS(buf, fixname, "_lpath"), LBUTS[i].lpath);
+ }
+ else
+ {
+ AS(fixname, "LBUT", buf1);
+ DBWriteContactSettingWord(0, TTB_OPTDIR, AS(buf, fixname, ""), -1);
+ DBDeleteContactSetting(0, TTB_OPTDIR, AS(buf, fixname, ""));
+ DBDeleteContactSetting(0, TTB_OPTDIR, AS(buf, fixname, "_lpath"));
+ DBDeleteContactSetting(0, TTB_OPTDIR, AS(buf, fixname, "_name"));
+ }
+ }
+ return 0;
+
+}
+
+
+//return 0 on success, -1 on error
+INT_PTR InsertNewFreeLBut(WPARAM wParam, LPARAM lParam)
+{
+ char buf[256];
+ if (LButCnt<MAXLBUTS)
+ {
+ int i;
+ for (i = 0;i<MAXLBUTS;i++)
+ {
+ if (LBUTS[i].hframe == 0)
+ {
+ wsprintf(buf, "%s %d", Translate("Default"), i);
+ LBUTS[i].name = _strdup(buf);
+ LBUTS[i].lpath = _strdup("Execute Path");
+ LBUTS[i].hframe = InsertLBut(i);
+ SaveAllLButs();
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+int InitLBut()
+{
+ CreateServiceFunction(TTB_LAUNCHSERVICE, LaunchService);
+ CreateServiceFunction(TTB_ADDLBUTTON, InsertNewFreeLBut);
+ CreateServiceFunction(TTB_REMOVELBUTTON, DeleteLBut);
+ CreateServiceFunction(TTB_MODIFYLBUTTON, ModifyLButton);
+ CreateServiceFunction(TTB_GETLBUTTON, GetLButton);
+
+
+
+ LoadAllLButs();
+ return 0;
+}
+int UnInitLBut()
+{
+ SaveAllLButs();
+ return 0;
+}
diff --git a/plugins/TopToolBar/main.c b/plugins/TopToolBar/main.c
deleted file mode 100644
index a3637b00b1..0000000000
--- a/plugins/TopToolBar/main.c
+++ /dev/null
@@ -1,1515 +0,0 @@
-
-#include "common.h"
-#pragma hdrstop
-
-HINSTANCE hInst;
-PLUGINLINK *pluginLink;
-struct MM_INTERFACE mmi;
-HANDLE hModulesLoaded,hOptInit;
-HANDLE hHookTTBModuleLoaded;
-int hLangpack;
-
-HWND hwndContactList=0;
-HWND hwndTopToolBar=0;
-boolean StopArrange;
-
-int BUTTWIDTH=20;
-int BUTTHEIGHT=16;
-boolean UseIcoLib=FALSE;
-
-extern int LoadAllSeparators();
-extern int SaveAllSeparators();
-extern INT_PTR InsertNewFreeSeparator(WPARAM wParam,LPARAM lParam);
-extern INT_PTR DeleteSeparator(WPARAM id,LPARAM lParam);
-
-#define MIID_TTB {0xf593c752, 0x51d8, 0x4d46, {0xba, 0x27, 0x37, 0x57, 0x79, 0x53, 0xf5, 0x5c}}
-
-PLUGININFOEX pluginInfo={
- sizeof(PLUGININFOEX),
- "TopToolbar",
- PLUGIN_MAKE_VERSION(0,7,3,1),
- "ToptoolBar adds buttons in top frame for fast access.This plugin uses MultiWindow or CList_MW plugin.("__DATE__" "__TIME__")",
- "Bethoven",
- "Bethoven@mailgate.ru",
- "© 2003-2008 Bethoven",
- "http://www.miranda-im.org/",
- UNICODE_AWARE,
- 0, //doesn't replace anything built-in
- MIID_TTB
-};
-
-
-
-
-int nextButtonId=200;
-int nButtonsCount=0;
-int lastxpos=1;
-int lastypos=1;
-
-
-
-
-//==============options
-COLORREF bkColour;
-HBITMAP hBmpBackground;
-int backgroundBmpUse;
-
-
-static CRITICAL_SECTION csButtonsHook;
-
-static int hFrameTopWindow=-1;
-
-
-TopButtonInt Buttons[MAX_BUTTONS];
-SortData arrangedbuts[MAX_BUTTONS];
-
-
-
-
-
-
-
-int SetButtBitmap(int pos);
-
-void lockbut()
-{
- EnterCriticalSection(&csButtonsHook);
-}
-
-void ulockbut()
-{
- LeaveCriticalSection(&csButtonsHook);
-}
-
-
-
-static int RemoveItemFromList(int pos,TopButtonInt (*lpButtons)[],int *ButtonsItemCount)
-{
- memcpy(&((*lpButtons)[pos]),&((*lpButtons)[pos+1]),sizeof(TopButtonInt)*(*ButtonsItemCount-pos-1));
- (*ButtonsItemCount)--;
- //(*lpButtons)=(TopButtonInt*)realloc((*lpButtons),sizeof(TopButtonInt)*(*ButtonsItemCount));
- return 0;
-}
-
-
-int idtopos(int id)
-{
- int i;
-
- for (i=0;i<nButtonsCount;i++)
- {
- if (Buttons[i].id==id){return(i);};
- };
- return(-1);
-};
-
-
-int DBSaveButtonSettings(int butpos)
-{
- char buf[255];
- DWORD oldv;
-// char *oldtb;
-
- //must be locked
- memset(buf,0,sizeof(buf));
-
-
-
- DBWriteContactSettingWord(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_Position"),Buttons[butpos].arrangedpos);
-
- oldv=Buttons[butpos].dwFlags&(TTBBF_VISIBLE);
- DBWriteContactSettingDword(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_Visible"),oldv);
-
- //Buttons[butpos].UserDefinedbmDown=DBGetString(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_BmpDown"));
- DBWriteContactSettingString(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_BmpDown"),"");
- DBWriteContactSettingString(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_BmpUp"),"");
-
- if (Buttons[butpos].UserDefinedbmDown!=NULL)
- {
- DBWriteContactSettingString(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_BmpDown"),Buttons[butpos].UserDefinedbmDown);
- };
- if (Buttons[butpos].UserDefinedbmUp!=NULL){DBWriteContactSettingString(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_BmpUp"),Buttons[butpos].UserDefinedbmUp);};
-
-
- return 0;
-}
-
-int SaveAllButtonsOptions()
-{
- int i;
- lockbut();
- for (i=0;i<nButtonsCount;i++)
- {
- DBSaveButtonSettings(i);
- };
-
- ulockbut();
-
- return(0);
-};
-int DBLoadButtonSettings(int butpos)
-{
- char buf[255];
- DWORD oldv;
-// char *oldtb;
-
- //must be locked
- memset(buf,0,sizeof(buf));
- //DBWriteContactSettingString(0,CLUIFrameModule,strcat("Name",sadd),Frames[Frameid].name);
-
- //boolean
- Buttons[butpos].arrangedpos=DBGetContactSettingWord(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_Position"),MAX_BUTTONS);
- oldv=Buttons[butpos].dwFlags&(TTBBF_VISIBLE);
- Buttons[butpos].dwFlags=Buttons[butpos].dwFlags&(~TTBBF_VISIBLE);
- if (
- DBGetContactSettingDword(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_Visible"),oldv)>0
- )
- {
- Buttons[butpos].dwFlags|=(TTBBF_VISIBLE);
- };
- Buttons[butpos].UserDefinedbmDown=DBGetString(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_BmpDown"));
- if ((Buttons[butpos].UserDefinedbmDown!=NULL)&&strlen(Buttons[butpos].UserDefinedbmDown)==0){free(Buttons[butpos].UserDefinedbmDown);Buttons[butpos].UserDefinedbmDown=NULL;};
-
- Buttons[butpos].UserDefinedbmUp=DBGetString(0,TTB_OPTDIR,AS(buf,Buttons[butpos].name,"_BmpUp"));
- if ((Buttons[butpos].UserDefinedbmUp!=NULL)&&strlen(Buttons[butpos].UserDefinedbmUp)==0){free(Buttons[butpos].UserDefinedbmUp);Buttons[butpos].UserDefinedbmUp=NULL;};
- return 0;
-}
-
-
-int ttbOptionsChanged()
-{
-
- //load options
- if(TRUE) {
- DBVARIANT dbv;
- bkColour=DBGetContactSettingDword(NULL,TTB_OPTDIR,"BkColour",TTBDEFAULT_BKCOLOUR);
- if(hBmpBackground) {DeleteObject(hBmpBackground); hBmpBackground=NULL;}
- if(DBGetContactSettingByte(NULL,TTB_OPTDIR,"UseBitmap",TTBDEFAULT_USEBITMAP)) {
- 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(hwndTopToolBar,&rc);
- InvalidateRect(hwndTopToolBar,&rc,TRUE);
- UpdateWindow(hwndTopToolBar);
- }
- ArrangeButtons();
- SetAllBitmaps();
- SaveAllSeparators();
- SaveAllButtonsOptions();
-
- return(0);
-};
-
-INT_PTR TTBRemoveButton(WPARAM wParam,LPARAM lParam)
-{
- int pos;
-
- lockbut();
- pos=idtopos(wParam);
- if (pos<0||pos>=nButtonsCount){ulockbut();return(-1);};
-
- DestroyWindow(Buttons[pos].hwnd);
- if (Buttons[pos].pszServiceDown!=NULL) free(Buttons[pos].pszServiceDown);
- if (Buttons[pos].pszServiceUp!=NULL) free(Buttons[pos].pszServiceUp);
- RemoveItemFromList(pos,&Buttons,&nButtonsCount);
- ArrangeButtons();
- ulockbut();
- OptionsPageRebuild();
- return(0);
-
-};
-static HBITMAP DrawBorderForBitmap(HBITMAP hb,BOOL up)
-{
- HBITMAP Border,workbmp;
- HDC workdc,destdc,srcdc;
-
- Border=LoadBitmap(hInst,MAKEINTRESOURCE(up?IDB_BORDERUP:IDB_BORDERDN));
- workdc=GetDC(hwndContactList);
- destdc=CreateCompatibleDC(workdc);
- srcdc=CreateCompatibleDC(workdc);
-
- workbmp=CreateBitmap(BUTTWIDTH,BUTTHEIGHT,1,GetDeviceCaps(workdc,BITSPIXEL),NULL);
- SelectObject(destdc,workbmp);
-
- SelectObject(srcdc,Border);
-
- BitBlt(destdc,0,0,BUTTWIDTH,BUTTHEIGHT,srcdc,0,0,SRCCOPY);
- SelectObject(srcdc,hb);
- BitBlt(destdc,1,1,BUTTWIDTH-4,BUTTHEIGHT-4,srcdc,0,0,SRCCOPY);
-
-
-
- DeleteDC(destdc);
- DeleteDC(srcdc);
- ReleaseDC(hwndContactList,workdc);
- return(workbmp);
-};
-
-static int UpdateToolTip(int bpos)
-{
- {
- TOOLINFO ti;
-
- ZeroMemory(&ti,sizeof(ti));
- ti.cbSize=sizeof(ti);
- ti.lpszText=Buttons[bpos].tooltip;
- ti.hinst=hInst;
- ti.uFlags=TTF_IDISHWND|TTF_SUBCLASS ;
- ti.uId=(UINT_PTR)Buttons[bpos].hwnd;
- return(SendMessage(Buttons[bpos].hwndTip,TTM_UPDATETIPTEXT ,0,(LPARAM)&ti));
- }
-
-};
-
-boolean nameexists(const char *name)
-{
- //must be locked
- int i;
-
- for (i=0;i<nButtonsCount;i++)
- {
- if (strcmp(Buttons[i].name,name)==0){return(TRUE);};
- };
- return(FALSE);
-
-
-};
-
-HICON LoadIconFromLibrary(char *SectName,char *Name,char *Description,HICON hIcon,boolean RegisterIt,boolean *RegistredOk)
-{
- SKINICONDESC sid={0};
- int retval;
-
- //if (hIcon==NULL) return hIcon;
- if(RegistredOk) *RegistredOk=FALSE;
-
- if (Name!=NULL&&strlen(Name)!=0)
- {
- char iconame[256];
-
- _snprintf(iconame,sizeof(iconame),"toptoolbar_%s",Name);
- if(ServiceExists(MS_SKIN2_ADDICON))
- {
-
- if (RegisterIt)
- {
-
- memset(&sid,0,sizeof(sid));
- sid.cbSize = sizeof(sid);
- sid.pszSection = Translate(SectName);
- sid.pszName=iconame;
- sid.pszDefaultFile=NULL;
- sid.pszDescription=Description;
- sid.hDefaultIcon=hIcon;
-
- retval=CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);
-
- if(RegistredOk) *RegistredOk=TRUE;
- };
- return ((HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)iconame));
- }
- };
-
- return hIcon;
-}
-
-
-INT_PTR TTBAddButton(WPARAM wParam,LPARAM lParam)
-{
- int i,retval;
- TTBButtonV2 but;
- {
- char readbuf[256];
- sprintf(readbuf,"(%08x)Try Adding TTB Button: wparam:%x\r\n",wParam,wParam);
- //OutputDebugStringMy(readbuf);
- }
-
- if (wParam==0){return(-1);};
- if (hwndContactList==0){hwndContactList=(HWND)CallService(MS_CLUI_GETHWND,0,0);};
- if (hwndContactList==0)
- {
- //oops clui even now not loaded...sorry no buttons available
- return(-1);
- }
- lockbut();
- if (nButtonsCount==MAX_BUTTONS){return(-1);};
-
-
- i=nButtonsCount;
- memset(&but,0,sizeof(but));
-
- //but=*((TTBButton*)wParam);
- if (((TTBButton*)wParam)->cbSize==sizeof(TTBButton))
- {
- //(TTBButton)but=*((TTBButton*)wParam);
- memcpy(&but,(void *)wParam,sizeof(TTBButton));
- }
- if (((TTBButton*)wParam)->cbSize==sizeof(TTBButtonV2))
- {
- memcpy(&but,(void *)wParam,sizeof(TTBButtonV2));
- }
-
- if ( (but.name==NULL) || nameexists(but.name)){return(-1);};
-
- Buttons[i].id=nextButtonId++;
- Buttons[i].hbBitmapDown=but.hbBitmapDown;
- Buttons[i].hbBitmapUp=but.hbBitmapUp;
- Buttons[i].hbDefBitmapDown=but.hbBitmapDown;
- Buttons[i].hbDefBitmapUp =but.hbBitmapUp;
-
- if(but.pszServiceDown!=NULL) Buttons[i].pszServiceDown=strdup(but.pszServiceDown);
- if(but.pszServiceUp!=NULL) Buttons[i].pszServiceUp=strdup(but.pszServiceUp);
- Buttons[i].name=strdup(but.name);
-
- Buttons[i].dwFlags=but.dwFlags;
-
- if (Buttons[i].dwFlags&TTBBF_DRAWBORDER)
- {
- Buttons[i].hbWBordBitmapDown=DrawBorderForBitmap(Buttons[i].hbBitmapDown,FALSE);
- Buttons[i].hbWBordBitmapUp=DrawBorderForBitmap(Buttons[i].hbBitmapUp,TRUE);
- };
-
- Buttons[i].wParamUp=but.wParamUp;
- Buttons[i].lParamUp=but.lParamUp;
- Buttons[i].wParamDown=but.wParamDown;
- Buttons[i].lParamDown=but.lParamDown;
-
- Buttons[i].dwFlags=but.dwFlags;
-
- Buttons[i].bPushed=(but.dwFlags&TTBBF_PUSHED)?TRUE:FALSE;
-
- CreateOneWindow(i);
-
- Buttons[i].hIconUp =but.hIconUp ;
- Buttons[i].hIconDn =but.hIconDn ;
-
-
- if (UseIcoLib&&(!(Buttons[i].dwFlags&TTBBF_ISSEPARATOR)))
- {
- char buf[256];
- sprintf(buf,"%s_up",Buttons[i].name);
- Buttons[i].hIconUp=LoadIconFromLibrary("TopToolBar",buf,buf,but.hIconDn,TRUE,NULL);
- sprintf(buf,"%s_dn",Buttons[i].name);
- Buttons[i].hIconDn=LoadIconFromLibrary("TopToolBar",buf,buf,but.hIconUp,TRUE,NULL);
-
- }
-
-
- //WS_EX_TRANSPARENT
- //SetWindowLong(Buttons[i].hwnd,GWL_EXSTYLE,WS_EX_TRANSPARENT);
-
-
- Buttons[i].hwndTip
- =CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
- WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
- CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT,
- hwndTopToolBar, NULL, hInst,
- NULL);
-
-SetWindowPos(Buttons[i].hwndTip, HWND_TOPMOST,0, 0, 0, 0,
- SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
- {
- TOOLINFO ti;
- int res;
-
- ZeroMemory(&ti,sizeof(ti));
- ti.cbSize=sizeof(ti);
- ti.lpszText="";
- ti.hinst=hInst;
- ti.uFlags=TTF_IDISHWND|TTF_SUBCLASS ;
- ti.uId=(UINT_PTR)Buttons[i].hwnd;
- res=SendMessage(Buttons[i].hwndTip,TTM_ADDTOOL,0,(LPARAM)&ti);
- }
-
- SendMessage(Buttons[i].hwndTip,TTM_ACTIVATE,(WPARAM)(Buttons[i].dwFlags&TTBBF_SHOWTOOLTIP)?TRUE:FALSE,0);
-
- SetWindowLong(Buttons[i].hwnd,GWLP_USERDATA,Buttons[i].id);
-
- //lastxpos+=BUTTWIDTH+2;
-
- {
- //char readbuf[256];
- //sprintf(readbuf,"(%08x)Adding TTB Button:%s (%08x) id(%d),current buttons count %d\r\n",wParam,Buttons[i].name,Buttons[i].dwFlags,Buttons[i].id,nButtonsCount);
- //OutputDebugStringMy(readbuf);
- }
-
-
- nButtonsCount++;
-
- retval=Buttons[i].id;
- DBLoadButtonSettings(i);
- applyuserbitmaps(i);
-
- SetButtBitmap(i);
- ulockbut();
- ArrangeButtons();
- OptionsPageRebuild();
-
- {
- //char readbuf[256];
- //sprintf(readbuf,"(%08x)Added TTB Button:%s (%08x) id(%d),current buttons count %d, All Done\r\n",wParam,Buttons[i].name,Buttons[i].dwFlags,Buttons[i].id,nButtonsCount);
- //OutputDebugStringMy(readbuf);
- }
-
- return(retval);
-};
-
-/*
-//wparam=*TTBButton;
-int TTBAddButton(WPARAM wParam,LPARAM lParam)
-{
- int i,retval;
- TTBButton but;
-
- if (wParam==NULL){return(-1);};
- if (hwndContactList==0){hwndContactList=CallService(MS_CLUI_GETHWND,0,0);};
- if (hwndContactList==0)
- {
- //oops clui even now not loaded...sorry no buttons available
- return(-1);
- }
- lockbut();
- if (nButtonsCount==MAX_BUTTONS){return(-1);};
-
-
- i=nButtonsCount;
- but=*((TTBButton*)wParam);
- if (but.cbSize!=sizeof(but)){return(-1);};
- if ( (but.name==NULL) || nameexists(but.name)){return(-1);};
-
- Buttons[i].id=nextButtonId++;
- Buttons[i].hbBitmapDown=but.hbBitmapDown;
- Buttons[i].hbBitmapUp=but.hbBitmapUp;
- Buttons[i].hbDefBitmapDown=but.hbBitmapDown;
- Buttons[i].hbDefBitmapUp =but.hbBitmapUp;
-
- if(but.pszServiceDown!=NULL) Buttons[i].pszServiceDown=strdup(but.pszServiceDown);
- if(but.pszServiceUp!=NULL) Buttons[i].pszServiceUp=strdup(but.pszServiceUp);
- Buttons[i].name=strdup(but.name);
-
- Buttons[i].dwFlags=but.dwFlags;
-
- if (Buttons[i].dwFlags&TTBBF_DRAWBORDER)
- {
- Buttons[i].hbWBordBitmapDown=DrawBorderForBitmap(Buttons[i].hbBitmapDown,FALSE);
- Buttons[i].hbWBordBitmapUp=DrawBorderForBitmap(Buttons[i].hbBitmapUp,TRUE);
- };
-
- Buttons[i].wParamUp=but.wParamUp;
- Buttons[i].lParamUp=but.lParamUp;
- Buttons[i].wParamDown=but.wParamDown;
- Buttons[i].lParamDown=but.lParamDown;
-
- Buttons[i].dwFlags=but.dwFlags;
-
- Buttons[i].bPushed=(but.dwFlags&TTBBF_PUSHED)?TRUE:FALSE;
-
- CreateOneWindow(i);
-
- if (UseIcoLib&&(!(Buttons[i].dwFlags&TTBBF_ISSEPARATOR)))
- {
- char buf[256];
- sprintf(buf,"%s_up",Buttons[i].name);
- Buttons[i].hIconUp=LoadIconFromLibrary("TopToolBar",buf,buf,NULL,TRUE,NULL);
- sprintf(buf,"%s_dn",Buttons[i].name);
- Buttons[i].hIconDn=LoadIconFromLibrary("TopToolBar",buf,buf,NULL,TRUE,NULL);
-
- }
-
-
- //WS_EX_TRANSPARENT
- //SetWindowLong(Buttons[i].hwnd,GWL_EXSTYLE,WS_EX_TRANSPARENT);
-
-
- Buttons[i].hwndTip
- =CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
- WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
- CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT,
- hwndTopToolBar, NULL, hInst,
- NULL);
-
-SetWindowPos(Buttons[i].hwndTip, HWND_TOPMOST,0, 0, 0, 0,
- SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
- {
- TOOLINFO ti;
- int res;
-
- ZeroMemory(&ti,sizeof(ti));
- ti.cbSize=sizeof(ti);
- ti.lpszText="";
- ti.hinst=hInst;
- ti.uFlags=TTF_IDISHWND|TTF_SUBCLASS ;
- ti.uId=Buttons[i].hwnd;
- res=SendMessage(Buttons[i].hwndTip,TTM_ADDTOOL,0,&ti);
- }
-
- SendMessage(Buttons[i].hwndTip,TTM_ACTIVATE,(WPARAM)(Buttons[i].dwFlags&TTBBF_SHOWTOOLTIP)?TRUE:FALSE,0);
-
- SetWindowLong(Buttons[i].hwnd,GWL_USERDATA,Buttons[i].id);
-
- //lastxpos+=BUTTWIDTH+2;
-
-
- nButtonsCount++;
-
- retval=Buttons[i].id;
- DBLoadButtonSettings(i);
- applyuserbitmaps(i);
-
- SetButtBitmap(i);
- ulockbut();
- ArrangeButtons();
- OptionsPageRebuild();
- return(retval);
-};
-
-*/
-
-int sortfunc(const void *a,const void *b)
-{
- SortData *sd1,*sd2;
- sd1=a;
- sd2=b;
- if (sd1->arrangeval > sd2->arrangeval){return(1);};
- if (sd1->arrangeval < sd2->arrangeval){return(-1);};
- /*if (sd1->arrangeval = sd2->arrangeval)*/{return(0);};
-
-};
-boolean isSep(int i)
-{
- if (Buttons[i].dwFlags&TTBBF_ISSEPARATOR){return(TRUE);}
- return(FALSE);
-};
-int getbutw(i)
-{
- RECT rc;
- GetWindowRect(Buttons[i].hwnd,&rc);
- return(rc.right-rc.left);
-};
-
-int MakeSortArr(boolean vis)
-{
- int i;
- int v;
- v=0;
- memset(&arrangedbuts,0,sizeof(arrangedbuts));
- for (i=0;i<nButtonsCount;i++)
- {
- if (vis)
- {
- if (!(Buttons[i].dwFlags&TTBBF_VISIBLE)){continue;};
- };
- arrangedbuts[v].arrangeval=Buttons[i].arrangedpos;
- arrangedbuts[v].oldpos=i;
- v++;
- };
- if (v>0)
- {
- qsort(&(arrangedbuts[0]),v,sizeof(SortData),sortfunc);
- };
- return(v);
-
-};
-
-int CreateOneWindow(int ButtonPos)
-{
- if (DBGetContactSettingByte(0,TTB_OPTDIR,"UseMirandaButtonClass",UseMirandaButtonClassDefaultValue)&& !(Buttons[ButtonPos].dwFlags&TTBBF_ISSEPARATOR))
- {
- Buttons[ButtonPos].hwnd=CreateWindow(MYMIRANDABUTTONCLASS,"",BS_PUSHBUTTON|WS_CHILD|WS_TABSTOP|SS_NOTIFY,0,0,BUTTWIDTH,BUTTHEIGHT,hwndTopToolBar,NULL,hInst,0);
- //"CLCButtonClass"
- //SS_NOTIFY|
- //MYMIRANDABUTTONCLASS
- }else
- {
- Buttons[ButtonPos].hwnd=CreateWindow("STATIC","",WS_CHILD|SS_NOTIFY,
- 0,0,BUTTWIDTH,BUTTHEIGHT,hwndTopToolBar,NULL,hInst,0);
- };
- SetWindowLong(Buttons[ButtonPos].hwnd,GWLP_USERDATA,Buttons[ButtonPos].id);
- if (DBGetContactSettingByte(0,TTB_OPTDIR,"UseFlatButton",1))
- SendMessage(Buttons[ButtonPos].hwnd,BUTTONSETASFLATBTN,0,0);
-
- return(0);
-
-}
-int RecreateWindows()
-{
- int i;
- lockbut();
- for (i=0;i<nButtonsCount;i++)
- {
- if (Buttons[i].hwnd)
- {
- //SendMessage(Buttons[i].hwnd,STM_SETIMAGE,IMAGE_BITMAP,NULL);
- //SendMessage(Buttons[i].hwnd,BM_SETIMAGE,IMAGE_BITMAP,NULL);
-
- DestroyWindow(Buttons[i].hwnd);
- Buttons[i].hwnd=NULL;
- CreateOneWindow(i);
- }
- }
-
- ulockbut();
- SetAllBitmaps();
- return (0);
-};
-
-int ArrangeButtons()
-{
- int i,totwidth,visbut;
- RECT winrc;
- int newheight,cnt,perline;
- int v;
-
- if (StopArrange==TRUE) return(0);
-
- BUTTHEIGHT=DBGetContactSettingByte(0,TTB_OPTDIR,"BUTTHEIGHT",16);
- BUTTWIDTH=DBGetContactSettingByte(0,TTB_OPTDIR,"BUTTWIDTH",20);
-
-
-
- lockbut();
- lastxpos=1;
-
- {
- //sorting stuff
-
- v=MakeSortArr(TRUE);
- if (v>0)
- {
- for (i=0;i<nButtonsCount;i++)
- {
- //SetWindowPos(Buttons[i].hwnd,0,i*(-BUTTWIDTH),-BUTTWIDTH,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW);
-
-
- if (!(Buttons[i].dwFlags&TTBBF_VISIBLE)){
- ShowWindow(Buttons[i].hwnd,SW_HIDE);};
-
- };
- GetClientRect(hwndTopToolBar,&winrc);
- winrc.left=winrc.right-winrc.left;
- winrc.top=winrc.bottom-winrc.top;
-
- totwidth=1;
- visbut=0;
- for (i=0;i<v;i++)
- {
- if (!(Buttons[arrangedbuts[i].oldpos].dwFlags&TTBBF_VISIBLE)) continue;
- totwidth+=BUTTWIDTH+1;
- visbut++;
- };
- //if need wraping
- if (winrc.left==0){return(0);};
- {
-
- perline=winrc.left/(BUTTWIDTH+1);
- if (perline==0){perline=1;};
-
- cnt=(visbut)/perline;
- if (cnt*perline<visbut){cnt++;};
- newheight=1+((cnt))*(BUTTHEIGHT+2);
- //if (newheight!=winrc.top)
- {
- //CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_HEIGHT,hFrameTopWindow),newheight);
- };
- };
-
- lastypos=1;
- lastxpos=1;
- newheight=BUTTHEIGHT+1;
- CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_HEIGHT,hFrameTopWindow),BUTTHEIGHT+2);
- for (i=0;i<v;i++)
- {
- int w1,w2,x;
- //Buttons[arrangedbuts[i].oldpos].arrangedpos=i;
- if (!(Buttons[arrangedbuts[i].oldpos].dwFlags&TTBBF_VISIBLE)){
- ShowWindow(Buttons[arrangedbuts[i].oldpos].hwnd,SW_HIDE);continue;};
-
-
-// TTBBF_ISSEPARATOR
- x=SWP_NOZORDER|SWP_SHOWWINDOW;
- if (Buttons[arrangedbuts[i].oldpos].dwFlags&TTBBF_ISSEPARATOR) {x=SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW;};
- SetWindowPos(Buttons[arrangedbuts[i].oldpos].hwnd,0,lastxpos,lastypos,BUTTWIDTH,BUTTHEIGHT,x);
- InvalidateRect(Buttons[arrangedbuts[i].oldpos].hwnd,NULL,TRUE);
- //RedrawWindow(Buttons[arrangedbuts[i].oldpos].hwnd,NULL,NULL,RDW_UPDATENOW|RDW_ALLCHILDREN|RDW_ERASE|RDW_INVALIDATE);
- //UpdateWindow(Buttons[arrangedbuts[i].oldpos].hwnd);
-
- //lastxpos+=BUTTWIDTH+1;
- if (i==v-1){break;};
- if (!(Buttons[arrangedbuts[i+1].oldpos].dwFlags&TTBBF_VISIBLE)){continue;};
-
- w1=getbutw(arrangedbuts[i+1].oldpos);
- w2=getbutw(arrangedbuts[i].oldpos);
- if ( (lastxpos+(+w1+w2+1)>winrc.left))
- {
- lastxpos=1;
- lastypos+=BUTTHEIGHT+2;
- if (Buttons[arrangedbuts[i+1].oldpos].dwFlags&TTBBF_VISIBLE)
- {
- CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_HEIGHT,hFrameTopWindow),lastypos+BUTTHEIGHT+1);
- newheight=lastypos+BUTTHEIGHT+1;
- };
- }
- else
- {
- lastxpos+=(isSep(arrangedbuts[i].oldpos))?(SEPWIDTH+2):(BUTTWIDTH+1);
- if (isSep(arrangedbuts[i+1].oldpos))
- {
- lastxpos+=1;
- };
-
-
-
- };
-
- };
- };
-
- }
- v=MakeSortArr(FALSE);
- ulockbut();
-
- //RedrawWindow(hwndTopToolBar,NULL,NULL,RDW_UPDATENOW|RDW_ALLCHILDREN|RDW_ERASE|RDW_INVALIDATE);
- //UpdateWindow(hwndTopToolBar);
- if (newheight!=winrc.top)
- {
- //SendMessage(GetParent(hwndTopToolBar),WM_SIZE,0,0);
- };
-
- return (1);
-
-};
-
-
-int applyuserbitmaps(int pos)
-{
-int t=IMAGE_BITMAP;
- Buttons[pos].hbBitmapDown=Buttons[pos].hbDefBitmapDown;
-Buttons[pos].hbBitmapUp=Buttons[pos].hbDefBitmapUp;
-if (Buttons[pos].UserDefinedbmDown!=NULL)
-{
- if (strstr(Buttons[pos].UserDefinedbmDown,".ico")) {t=IMAGE_ICON;};
- Buttons[pos].hbBitmapDown=LoadImage(0,Buttons[pos].UserDefinedbmDown,t,0,0,LR_LOADFROMFILE);
- //Buttons[pos].hbBitmapDown=CopyImage(Buttons[pos].hbBitmapDown,t,0,0,LR_CREATEDIBSECTION);
-};
-
-if (Buttons[pos].UserDefinedbmUp!=NULL)
-{
- if (strstr(Buttons[pos].UserDefinedbmUp,".ico")) {t=IMAGE_ICON;};
- Buttons[pos].hbBitmapUp=LoadImage(0,Buttons[pos].UserDefinedbmUp,t,0,0,LR_LOADFROMFILE);
-};
-
-
-return(0);
-};
-
-int SetAllBitmaps()
-{
- int i;
-
- lockbut();
- for (i=0;i<nButtonsCount;i++)
- {
- applyuserbitmaps(i);
- SetButtBitmap(i);
- };
- ulockbut();
- return(0);
-};
-int SetButtBitmap(int pos)
-{
-int t=IMAGE_BITMAP;
-char *curname;
-int curstyle;
-
-
-
-
-curname=(Buttons[pos].bPushed)?(Buttons[pos].UserDefinedbmDown):(Buttons[pos].UserDefinedbmUp);
-
-curstyle=GetWindowLong(Buttons[pos].hwnd,GWL_STYLE);
-curstyle&=(~SS_BITMAP);
-curstyle&=(~SS_ICON);
-
-/*
-if (UseIcoLib&&DBGetContactSettingByte(0,TTB_OPTDIR,"UseMirandaButtonClass",0)&& !(Buttons[pos].dwFlags&TTBBF_ISSEPARATOR))
-{
-
- //SendMessage(Buttons[pos].hwnd,BM_SETIMAGE,IMAGE_ICON,(Buttons[pos].bPushed)?(Buttons[pos].hIconDn):(Buttons[pos].hIconUp));
- return 0;
-}
-*/
-
-if (!UseIcoLib||(Buttons[pos].dwFlags&TTBBF_ISSEPARATOR))
-{
- if (curname!=NULL)
- {
- if (strstr(curname,".ico")) {t=IMAGE_ICON;};
-
- (t==IMAGE_ICON||UseIcoLib)?(curstyle|=SS_ICON):(curstyle|=SS_BITMAP);
- SetWindowLong(Buttons[pos].hwnd,GWL_STYLE,curstyle);
- }else
- {
- SetWindowLong(Buttons[pos].hwnd,GWL_STYLE,curstyle|(Buttons[pos].hbBitmapDown==NULL?SS_ICON:SS_BITMAP));
- }
-} else
-{
- if (GetWindowLong(Buttons[pos].hwnd,GWL_STYLE)&SS_ICON)
- {
- SetWindowLong(Buttons[pos].hwnd,GWL_STYLE,curstyle|SS_ICON);
- }
-}
-
-
-
-if (!UseIcoLib||(Buttons[pos].dwFlags&TTBBF_ISSEPARATOR))
-{
- if(!(Buttons[pos].dwFlags&TTBBF_DRAWBORDER))
- {
- if (Buttons[pos].hbBitmapDown==NULL)
- {
- t=IMAGE_ICON;
- SendMessage(Buttons[pos].hwnd,STM_SETIMAGE,t,(LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hIconDn):(Buttons[pos].hIconUp)));
- SendMessage(Buttons[pos].hwnd,BM_SETIMAGE,t,(LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hIconDn):(Buttons[pos].hIconUp)));
- }else
- {
- SendMessage(Buttons[pos].hwnd,STM_SETIMAGE,t,(LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hbBitmapDown):(Buttons[pos].hbBitmapUp)));
- SendMessage(Buttons[pos].hwnd,BM_SETIMAGE,t,(LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hbBitmapDown):(Buttons[pos].hbBitmapUp)));
- }
-
-
- }
- else
- {
- SendMessage(Buttons[pos].hwnd,STM_SETIMAGE,t,(LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hbWBordBitmapDown):(Buttons[pos].hbWBordBitmapUp)));
- }
-}else
-{
- SendMessage(Buttons[pos].hwnd,BM_SETIMAGE,IMAGE_ICON,(LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hIconDn):(Buttons[pos].hIconUp)));
-}
-
-return(0);
-};
-
-//wparam=hTTBButton
-//lparam=state
-INT_PTR TTBSetState(WPARAM wParam,LPARAM lParam)
-{
- int pos;
-
- lockbut();
- pos=idtopos(wParam);
- if (pos<0||pos>=nButtonsCount){ulockbut();;return(-1);};
-
- Buttons[pos].bPushed=(lParam&TTBST_PUSHED)?TRUE:FALSE;
- Buttons[pos].bPushed=(lParam&TTBST_RELEASED)?FALSE:TRUE;
- SetButtBitmap(pos);
- ulockbut();
- return(0);
-};
-
-//wparam=hTTBButton
-//lparam=0
-//return=state
-INT_PTR TTBGetState(WPARAM wParam,LPARAM lParam)
-{
- int pos,retval;
-
- lockbut();
- pos=idtopos(wParam);
- if (pos<0||pos>=nButtonsCount){ulockbut();return(-1);};
-
- retval=(Buttons[pos].bPushed==TRUE)?TTBST_PUSHED:TTBST_RELEASED;
- ulockbut();
- return(retval);
-};
-
-INT_PTR TTBGetOptions(WPARAM wParam,LPARAM lParam)
-{
- int pos,retval;
-
- lockbut();
- pos=idtopos(HIWORD(wParam));
- if (pos<0||pos>=nButtonsCount){ulockbut();return(-1);};
-
- switch(LOWORD(wParam))
- {
- case TTBO_FLAGS:
-
- retval=Buttons[pos].dwFlags&(!TTBBF_PUSHED);
- if (Buttons[pos].bPushed){retval|=TTBBF_PUSHED;};
- break;
-
- case TTBO_POS:
- retval=(int)pos;
- break;
-
- case TTBO_TIPNAME:
- retval=(int)Buttons[pos].tooltip;
- break;
-
- case TTBO_ALLDATA:
- {
-
- lpTTBButton lpTTB=lParam;
-
- if (lParam==0){break;};
- if (lpTTB->cbSize!=sizeof(TTBButton)){break;};
- lpTTB->dwFlags=Buttons[pos].dwFlags&(!TTBBF_PUSHED);
- if (Buttons[pos].bPushed){lpTTB->dwFlags|=TTBBF_PUSHED;};
-
- lpTTB->hbBitmapDown=Buttons[pos].hbBitmapDown;
- lpTTB->hbBitmapUp=Buttons[pos].hbBitmapUp;
- lpTTB->lParamUp=Buttons[pos].lParamUp;
- lpTTB->wParamUp=Buttons[pos].wParamUp;
- lpTTB->lParamDown=Buttons[pos].lParamDown;
- lpTTB->wParamDown=Buttons[pos].wParamDown;
-
- lpTTB->pszServiceDown=_strdup(Buttons[pos].pszServiceDown);
- lpTTB->pszServiceUp=_strdup(Buttons[pos].pszServiceUp);
-
- retval=lpTTB;
- break;
- }
-
- default:
- retval=-1;
- break;
- }
-
-
- ulockbut();
- return(retval);
-
-};
-
-
-INT_PTR TTBSetOptions(WPARAM wParam,LPARAM lParam)
-{
- int pos,retval;
-
- lockbut();
- pos=idtopos(HIWORD(wParam));
- if (pos<0||pos>=nButtonsCount){ulockbut();return(-1);};
-
- switch(LOWORD(wParam))
- {
- case TTBO_FLAGS:
- //retval=Buttons[i].dwFlags;
- if (Buttons[pos].dwFlags==lParam){break;};
- Buttons[pos].dwFlags=lParam;
- Buttons[pos].bPushed=(Buttons[pos].dwFlags&TTBBF_PUSHED)?TRUE:FALSE;
- if (Buttons[pos].dwFlags&TTBBF_DRAWBORDER)
- {
- Buttons[pos].hbWBordBitmapDown=DrawBorderForBitmap(Buttons[pos].hbBitmapDown,FALSE);
- Buttons[pos].hbWBordBitmapUp=DrawBorderForBitmap(Buttons[pos].hbBitmapUp,TRUE);
- };
-
- SetButtBitmap(pos);
- SendMessage(Buttons[pos].hwndTip,TTM_ACTIVATE,(WPARAM)(Buttons[pos].dwFlags&TTBBF_SHOWTOOLTIP)?TRUE:FALSE,0);
- retval=1;
- break;
-
- case TTBO_POS:
- {
- TopButtonInt tempttb;
-
- if (lParam<0||lParam>=nButtonsCount){break;};
- tempttb=Buttons[lParam];
- Buttons[lParam]=Buttons[pos];
- Buttons[pos]=tempttb;
-
- ArrangeButtons();
-
- retval=(int)1;
- break;
- }
-
- case TTBO_TIPNAME:
- if (lParam==0){break;};
- if (Buttons[pos].tooltip!=NULL){free(Buttons[pos].tooltip);};
- Buttons[pos].tooltip=_strdup((LPCSTR)lParam);
- UpdateToolTip(pos);
- retval=1;
- break;
-
- case TTBO_ALLDATA:
- {
-
- lpTTBButton lpTTB=lParam;
-
- if (lParam==0){break;};
- if (lpTTB->cbSize!=sizeof(TTBButton)){break;};
- Buttons[pos].dwFlags=lpTTB->dwFlags;
- Buttons[pos].hbBitmapDown=lpTTB->hbBitmapDown;
- Buttons[pos].hbBitmapUp=lpTTB->hbBitmapUp;
- Buttons[pos].lParamUp=lpTTB->lParamUp;
- Buttons[pos].wParamUp=lpTTB->wParamUp;
- Buttons[pos].lParamDown=lpTTB->lParamDown;
- Buttons[pos].wParamDown=lpTTB->wParamDown;
-
- if (Buttons[pos].pszServiceDown!=NULL){free(Buttons[pos].pszServiceDown);};
- if (Buttons[pos].pszServiceUp!=NULL){free(Buttons[pos].pszServiceUp);};
-
- Buttons[pos].pszServiceDown=_strdup(lpTTB->pszServiceDown);
- Buttons[pos].pszServiceUp=_strdup(lpTTB->pszServiceUp);
-
- if (Buttons[pos].dwFlags&TTBBF_DRAWBORDER)
- {
- Buttons[pos].hbWBordBitmapDown=DrawBorderForBitmap(Buttons[pos].hbBitmapDown,FALSE);
- Buttons[pos].hbWBordBitmapUp=DrawBorderForBitmap(Buttons[pos].hbBitmapUp,TRUE);
- };
-
-
- Buttons[pos].bPushed=(Buttons[pos].dwFlags&TTBBF_PUSHED)?TRUE:FALSE;
- SendMessage(Buttons[pos].hwndTip,TTM_ACTIVATE,(WPARAM)(Buttons[pos].dwFlags&TTBBF_SHOWTOOLTIP)?TRUE:FALSE,0);
- ArrangeButtons();
- retval=1;
- break;
- }
-
- default:
- retval=-1;
- break;
- }
-
-
- ulockbut();
- return(retval);
-
-};
-
-
-BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
-{
- hInst=hinstDLL;
- return TRUE;
-}
-
-LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch(msg)
- {
- case WM_CREATE:
- {
- {
- hwndTopToolBar=hwnd;
- }
-
- return(FALSE);
- };
-
- case WM_MOVE:
- {
- //RedrawWindow(hwnd,NULL,NULL,RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
- return(0);
- };
-
- case WM_WINDOWPOSCHANGING:
- case WM_SIZE:
- {
- ArrangeButtons();
-
- //RedrawWindow(hwnd,NULL,NULL,RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
- return(0);
- };
-
- //InvalidateRect(hwnd,NULL,TRUE);
- //ArrangeButtons();
- case WM_PAINT:
- {
- HDC hdcMem,hdc;
- RECT clRect,*rcPaint;
- int yScroll=0;
- int y;
- PAINTSTRUCT paintst;
- HBITMAP hBmpOsb,hOldBmp;
- DWORD style=GetWindowLong(hwnd,GWL_STYLE);
- int grey=0;
- HBRUSH hBrushAlternateGrey=NULL;
-
- InvalidateRect(hwnd,0,FALSE);
-
- hdc=BeginPaint(hwnd,&paintst);
- rcPaint=&(paintst.rcPaint);
-
- GetClientRect(hwnd,&clRect);
- if(rcPaint==NULL) rcPaint=&clRect;
- y=-yScroll;
- hdcMem=CreateCompatibleDC(hdc);
- hBmpOsb=CreateBitmap(clRect.right,clRect.bottom,1,GetDeviceCaps(hdc,BITSPIXEL),NULL);
- hOldBmp=SelectObject(hdcMem,hBmpOsb);
- SetBkMode(hdcMem,TRANSPARENT);
- { HBRUSH hBrush,hoBrush;
-
- hBrush=CreateSolidBrush(bkColour);
- 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=BUTTHEIGHT+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=BUTTHEIGHT+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);
-
-
- return(0);
- };
- case WM_LBUTTONDOWN:
- {
- if (DBGetContactSettingByte(NULL,"CLUI","ClientAreaDrag",0)) {
- POINT pt;
- //pt=nm->pt;
- GetCursorPos(&pt);
- return SendMessage(GetParent(hwnd), WM_SYSCOMMAND, SC_MOVE|HTCAPTION,MAKELPARAM(pt.x,pt.y));
- }
- return(0);
- };
- case WM_NOTIFY:
- {
- int id=wParam;
- LPNMHDR lpnm=(LPNMHDR)lParam;
- switch(lpnm->code)
- {
- case 1:{;};
- };
-
- return(0);
- };
- case WM_COMMAND:
- {
- if ((HIWORD(wParam)==STN_CLICKED|| HIWORD(wParam)==STN_DBLCLK))
- {
- int id=GetWindowLong((HWND)lParam,GWLP_USERDATA);
- int pos;
-
- if (id==0){break;};
- lockbut();
- pos=idtopos(id);
- if(isSep(pos)){ulockbut();return(0);};
- if (Buttons[pos].bPushed)
- {//Dn -> Up
- Buttons[pos].bPushed=!Buttons[pos].bPushed;
- SetButtBitmap(pos);
-
- if(Buttons[pos].pszServiceUp!=NULL) CallService(Buttons[pos].pszServiceUp,Buttons[pos].wParamUp,Buttons[pos].lParamUp);
- }
- else
- {//Up -> Dn
- Buttons[pos].bPushed=!Buttons[pos].bPushed;
- SetButtBitmap(pos);
-
- if(Buttons[pos].pszServiceDown!=NULL) CallService(Buttons[pos].pszServiceDown,Buttons[pos].wParamDown,Buttons[pos].lParamDown);
- };
- ulockbut();
- };
- break;
- };
-
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
-
- };
- return(TRUE);
-};
-
-int addTopToolBarWindow(HWND parent)
-{
- WNDCLASS wndclass;
-
- CLISTFrame Frame;
- int retval;
- HWND pluginwind;
- char pluginname[]="TopToolBar";
-
- wndclass.style = 0;
- wndclass.lpfnWndProc = TopToolBarProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInst;
- wndclass.hIcon = NULL;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
- wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);//NULL;//(HBRUSH)(COLOR_3DFACE+1);
- wndclass.lpszMenuName = NULL;
- wndclass.lpszClassName = pluginname;
- RegisterClass(&wndclass);
- pluginwind=CreateWindow(pluginname,pluginname,
- WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,
- 0,0,0,0,parent,NULL,hInst,NULL);
-
- //font=SendMessage(parent,WM_GETFONT,0,0);
- //SendMessage(pluginwind,WM_SETFONT,font,0);
- ttbOptionsChanged();
- //
- memset(&Frame,0,sizeof(Frame));
- Frame.name=(char *)malloc(255);
- memset(Frame.name,0,255);
- memcpy(Frame.name,pluginname,sizeof(pluginname));
- Frame.cbSize=sizeof(Frame);
- Frame.hWnd=pluginwind;
- Frame.align=alTop;
- Frame.Flags=F_VISIBLE|F_NOBORDER|F_LOCKED;
- Frame.height=18;
-
- retval=CallService(MS_CLIST_FRAMES_ADDFRAME,(WPARAM)&Frame,0);
- free(Frame.name);
-
-
- return(retval);
-
-
-};
-
-VOID CALLBACK TimerProc(
- HWND hwnd, // handle to window
- UINT uMsg, // WM_TIMER message
- UINT_PTR idEvent, // timer identifier
- DWORD dwTime // current system time
-)
-{
- KillTimer(0,idEvent);
- NotifyEventHooks(hHookTTBModuleLoaded, 0,0);
-
-
-};
-
-static INT_PTR OnEventFire(WPARAM wParam,LPARAM lParam) {
- CallService(MS_SYSTEM_REMOVEWAIT,wParam,0);
- StopArrange=FALSE;
- NotifyEventHooks(hHookTTBModuleLoaded, 0,0);
- return(0);
-};
-
-int OnIconChange(WPARAM wParam,LPARAM lParam) {
-int i;
- lockbut();
- for (i=0;i<nButtonsCount;i++)
- {
- char buf[256];
- sprintf(buf,"%s_up",Buttons[i].name);
- Buttons[i].hIconUp=LoadIconFromLibrary("TopToolBar",buf,buf,Buttons[i].hIconUp,FALSE,NULL);
- sprintf(buf,"%s_dn",Buttons[i].name);
- Buttons[i].hIconDn=LoadIconFromLibrary("TopToolBar",buf,buf,Buttons[i].hIconDn,FALSE,NULL);
- };
- ulockbut();
- RecreateWindows();
- SetAllBitmaps();
- ArrangeButtons();
- return(0);
-};
-
-static int OnBGChange(WPARAM wParam,LPARAM lParam) {
-
-ttbOptionsChanged();
-return(0);
-};
-
-
-static int OnmodulesLoad(WPARAM wParam,LPARAM lParam) {
-
- int ex=0;
-
- hwndContactList=(HWND)CallService(MS_CLUI_GETHWND,0,0);
-
- if (!ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) {
- MessageBox(0,"Frames Services not found - plugin disabled.You need MultiWindow plugin.","TopToolBar",0);
- return(0);
- ex=1;
- }
- if (!ServiceExists(MS_CLUI_GETHWNDTREE)) {
- MessageBox(0,"MS_CLUI_GETHWNDTREE Service not found - plugin disabled","TopToolBar",0);
- return(0);
- ex=1;
- }
-
- if (ex==1)
- {
- //destroy hook ???
- return(0);
- }
- OptionsOpened=FALSE;
- CreateServiceFunction(MS_TTB_ADDBUTTON,TTBAddButton);
- CreateServiceFunction(MS_TTB_REMOVEBUTTON,TTBRemoveButton);
-
- CreateServiceFunction(MS_TTB_SETBUTTONSTATE,TTBSetState);
- CreateServiceFunction(MS_TTB_GETBUTTONSTATE,TTBGetState);
-
- CreateServiceFunction(MS_TTB_GETBUTTONOPTIONS,TTBGetOptions);
- CreateServiceFunction(MS_TTB_SETBUTTONOPTIONS,TTBSetOptions);
- CreateServiceFunction(TTB_ADDSEPARATOR,InsertNewFreeSeparator);
- CreateServiceFunction(TTB_REMOVESEPARATOR,DeleteSeparator);
-
-
- CreateServiceFunction("TTB_ONSTARTUPFIRE",OnEventFire);
- UseIcoLib=DBGetContactSettingByte(0,TTB_OPTDIR,"UseIcoLib",UseIcoLibDefaultValue);
- if (UseIcoLib)
- {
- HookEvent(ME_SKIN2_ICONSCHANGED,OnIconChange);
- }
-
-
- hFrameTopWindow = addTopToolBarWindow(hwndContactList);
- LoadInternalButtons(CallService(MS_CLUI_GETHWNDTREE,0,0));
- SaveAllButtonsOptions();
-
- LoadAllSeparators();
- InitLBut();
-
- StopArrange=FALSE;
- ArrangeButtons();
-
- //SetTimer(0,GetTickCount(),1,&TimerProc);
- {
- HANDLE hEvent=CreateEvent(NULL,TRUE,TRUE,NULL);//anonymous event
- if (hEvent!=0)
- {
- CallService(MS_SYSTEM_WAITONHANDLE,(WPARAM)hEvent,(LPARAM)"TTB_ONSTARTUPFIRE");
- };
- };
-
- if (ServiceExists(MS_BACKGROUNDCONFIG_REGISTER))
- {
- char buf[256];
- sprintf(buf,"TopToolBar Background/%s",TTB_OPTDIR);
- CallService(MS_BACKGROUNDCONFIG_REGISTER,(WPARAM)buf,0);
- HookEvent(ME_BACKGROUNDCONFIG_CHANGED,OnBGChange);
- };
-
-
- return(0);
-};
-
-static const MUUID interfaces[] = {MIID_TTB, MIID_LAST};
-
-__declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
-{
- return interfaces;
-}
-
-__declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
-{
- return &pluginInfo;
-}
-
-int __declspec(dllexport) Load(PLUGINLINK *link)
-{
- pluginLink=link;
- mir_getMMI( &mmi );
- mir_getLP(&pluginInfo);
-
- InitializeCriticalSection(&csButtonsHook);
- StopArrange=TRUE;
- LoadCLCButtonModule();
- LoadButtonModule();
-
-
- hModulesLoaded=HookEvent(ME_SYSTEM_MODULESLOADED,OnmodulesLoad);
- hOptInit=HookEvent(ME_OPT_INITIALISE,TTBOptInit);
-
-
-
- BUTTHEIGHT=DBGetContactSettingByte(0,TTB_OPTDIR,"BUTTHEIGHT",16);
- BUTTWIDTH=DBGetContactSettingByte(0,TTB_OPTDIR,"BUTTWIDTH",20);
- hHookTTBModuleLoaded = CreateHookableEvent(ME_TTB_MODULELOADED);
-
- return 0;
-}
-
-int __declspec(dllexport) Unload(void)
-{
- //if (hFrameTopWindow!=NULL){CallService(MS_CLIST_FRAMES_REMOVEFRAME,(WPARAM)hFrameTopWindow,(LPARAM)0);};
-
-
- SaveAllSeparators();
- UnInitLBut();
- UnLoadInternalButtons();
-
- DeleteCriticalSection(&csButtonsHook);
- //DestroyServiceFunction();
- UnhookEvent(hModulesLoaded);
- UnhookEvent(hOptInit);
-
- return 0;
-} \ No newline at end of file
diff --git a/plugins/TopToolBar/main.cpp b/plugins/TopToolBar/main.cpp
new file mode 100644
index 0000000000..c0008e239b
--- /dev/null
+++ b/plugins/TopToolBar/main.cpp
@@ -0,0 +1,1156 @@
+
+#include "common.h"
+#pragma hdrstop
+
+HINSTANCE hInst;
+PLUGINLINK *pluginLink;
+struct MM_INTERFACE mmi;
+HANDLE hModulesLoaded, hOptInit;
+HANDLE hHookTTBModuleLoaded;
+int hLangpack;
+
+HWND hwndContactList = 0;
+HWND hwndTopToolBar = 0;
+bool StopArrange;
+
+int BUTTWIDTH = 20;
+int BUTTHEIGHT = 16;
+bool UseIcoLib = false;
+
+extern int LoadAllSeparators();
+extern int SaveAllSeparators();
+extern INT_PTR InsertNewFreeSeparator(WPARAM wParam, LPARAM lParam);
+extern INT_PTR DeleteSeparator(WPARAM id, LPARAM lParam);
+
+#define MIID_TTB {0xf593c752, 0x51d8, 0x4d46, {0xba, 0x27, 0x37, 0x57, 0x79, 0x53, 0xf5, 0x5c}}
+
+int nextButtonId = 200;
+int nButtonsCount = 0;
+int lastxpos = 1;
+int lastypos = 1;
+
+// == == == == == == == options
+COLORREF bkColour;
+HBITMAP hBmpBackground;
+int backgroundBmpUse;
+
+static CRITICAL_SECTION csButtonsHook;
+static int hFrameTopWindow = -1;
+
+TopButtonInt Buttons[MAX_BUTTONS];
+SortData arrangedbuts[MAX_BUTTONS];
+
+int SetButtBitmap(int pos);
+
+int applyuserbitmaps(int pos)
+{
+ int t = IMAGE_BITMAP;
+ Buttons[pos].hbBitmapDown = Buttons[pos].hbDefBitmapDown;
+ Buttons[pos].hbBitmapUp = Buttons[pos].hbDefBitmapUp;
+ if (Buttons[pos].UserDefinedbmDown != NULL) {
+ if (strstr(Buttons[pos].UserDefinedbmDown, ".ico"))
+ t = IMAGE_ICON;
+ Buttons[pos].hbBitmapDown = ( HBITMAP )LoadImage(0, Buttons[pos].UserDefinedbmDown, t, 0, 0, LR_LOADFROMFILE);
+ }
+
+ if (Buttons[pos].UserDefinedbmUp != NULL) {
+ if (strstr(Buttons[pos].UserDefinedbmUp, ".ico"))
+ t = IMAGE_ICON;
+ Buttons[pos].hbBitmapUp = ( HBITMAP )LoadImage(0, Buttons[pos].UserDefinedbmUp, t, 0, 0, LR_LOADFROMFILE);
+ }
+
+ return 0;
+}
+
+int SetAllBitmaps()
+{
+ lockbut();
+ for (int i = 0; i < nButtonsCount; i++) {
+ applyuserbitmaps(i);
+ SetButtBitmap(i);
+ }
+ ulockbut();
+ return 0;
+}
+
+void lockbut()
+{
+ EnterCriticalSection(&csButtonsHook);
+}
+
+void ulockbut()
+{
+ LeaveCriticalSection(&csButtonsHook);
+}
+
+int idtopos(int id)
+{
+ for ( int i = 0;i<nButtonsCount;i++)
+ if (Buttons[i].id == id)
+ return i;
+
+ return -1;
+}
+
+int DBSaveButtonSettings(int butpos)
+{
+ char buf[255];
+ memset(buf, 0, sizeof(buf));
+
+ DBWriteContactSettingWord(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_Position"), Buttons[butpos].arrangedpos);
+
+ DWORD oldv = Buttons[butpos].dwFlags & TTBBF_VISIBLE;
+ DBWriteContactSettingDword(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_Visible"), oldv);
+
+ DBWriteContactSettingString(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_BmpDown"), "");
+ DBWriteContactSettingString(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_BmpUp"), "");
+
+ if (Buttons[butpos].UserDefinedbmDown != NULL)
+ DBWriteContactSettingString(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_BmpDown"), Buttons[butpos].UserDefinedbmDown);
+
+ if (Buttons[butpos].UserDefinedbmUp != NULL)
+ DBWriteContactSettingString(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_BmpUp"), Buttons[butpos].UserDefinedbmUp);
+
+ return 0;
+}
+
+int SaveAllButtonsOptions()
+{
+ lockbut();
+ for (int i = 0; i < nButtonsCount; i++)
+ DBSaveButtonSettings(i);
+
+ ulockbut();
+ return 0;
+}
+
+int DBLoadButtonSettings(int butpos)
+{
+ char buf[255];
+ memset(buf, 0, sizeof(buf));
+
+ //bool
+ Buttons[butpos].arrangedpos = DBGetContactSettingWord(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_Position"), MAX_BUTTONS);
+ DWORD oldv = Buttons[butpos].dwFlags & TTBBF_VISIBLE;
+ Buttons[butpos].dwFlags = Buttons[butpos].dwFlags & (~TTBBF_VISIBLE);
+ if ( DBGetContactSettingDword(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_Visible"), oldv) > 0 )
+ Buttons[butpos].dwFlags |= TTBBF_VISIBLE;
+
+ Buttons[butpos].UserDefinedbmDown = DBGetString(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_BmpDown"));
+ if ((Buttons[butpos].UserDefinedbmDown != NULL) && strlen(Buttons[butpos].UserDefinedbmDown) == 0) {
+ free(Buttons[butpos].UserDefinedbmDown);
+ Buttons[butpos].UserDefinedbmDown = NULL;
+ }
+
+ Buttons[butpos].UserDefinedbmUp = DBGetString(0, TTB_OPTDIR, AS(buf, Buttons[butpos].name, "_BmpUp"));
+ if ((Buttons[butpos].UserDefinedbmUp != NULL) && strlen(Buttons[butpos].UserDefinedbmUp) == 0) {
+ free(Buttons[butpos].UserDefinedbmUp);
+ Buttons[butpos].UserDefinedbmUp = NULL;
+ }
+ return 0;
+}
+
+int ttbOptionsChanged()
+{
+ //load options
+ if (TRUE) {
+ DBVARIANT dbv;
+ bkColour = DBGetContactSettingDword(NULL, TTB_OPTDIR, "BkColour", TTBDEFAULT_BKCOLOUR);
+ if (hBmpBackground) {DeleteObject(hBmpBackground); hBmpBackground = NULL;}
+ if (DBGetContactSettingByte(NULL, TTB_OPTDIR, "UseBitmap", TTBDEFAULT_USEBITMAP)) {
+ 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(hwndTopToolBar, &rc);
+ InvalidateRect(hwndTopToolBar, &rc, TRUE);
+ UpdateWindow(hwndTopToolBar);
+
+ ArrangeButtons();
+ SetAllBitmaps();
+ SaveAllSeparators();
+ SaveAllButtonsOptions();
+
+ return 0;
+}
+
+static int RemoveItemFromList(int pos, TopButtonInt *lpButtons, int *ButtonsItemCount)
+{
+ memcpy( &lpButtons[pos], &lpButtons[pos+1], sizeof(TopButtonInt)*(*ButtonsItemCount-pos-1));
+ *ButtonsItemCount--;
+ return 0;
+}
+
+INT_PTR TTBRemoveButton(WPARAM wParam, LPARAM lParam)
+{
+ int pos;
+
+ lockbut();
+ pos = idtopos(wParam);
+ if (pos<0||pos >= nButtonsCount){ulockbut();return -1;}
+
+ DestroyWindow(Buttons[pos].hwnd);
+ if (Buttons[pos].pszServiceDown != NULL)
+ free(Buttons[pos].pszServiceDown);
+ if (Buttons[pos].pszServiceUp != NULL)
+ free(Buttons[pos].pszServiceUp);
+ RemoveItemFromList(pos, Buttons, &nButtonsCount);
+ ArrangeButtons();
+ ulockbut();
+ OptionsPageRebuild();
+ return 0;
+
+}
+static HBITMAP DrawBorderForBitmap(HBITMAP hb, BOOL up)
+{
+ HBITMAP Border, workbmp;
+ HDC workdc, destdc, srcdc;
+
+ Border = LoadBitmap(hInst, MAKEINTRESOURCE(up?IDB_BORDERUP:IDB_BORDERDN));
+ workdc = GetDC(hwndContactList);
+ destdc = CreateCompatibleDC(workdc);
+ srcdc = CreateCompatibleDC(workdc);
+
+ workbmp = CreateBitmap(BUTTWIDTH, BUTTHEIGHT, 1, GetDeviceCaps(workdc, BITSPIXEL), NULL);
+ SelectObject(destdc, workbmp);
+
+ SelectObject(srcdc, Border);
+
+ BitBlt(destdc, 0, 0, BUTTWIDTH, BUTTHEIGHT, srcdc, 0, 0, SRCCOPY);
+ SelectObject(srcdc, hb);
+ BitBlt(destdc, 1, 1, BUTTWIDTH-4, BUTTHEIGHT-4, srcdc, 0, 0, SRCCOPY);
+
+ DeleteDC(destdc);
+ DeleteDC(srcdc);
+ ReleaseDC(hwndContactList, workdc);
+ return workbmp;
+}
+
+static int UpdateToolTip(int bpos)
+{
+ TOOLINFO ti = { 0 };
+ ti.cbSize = sizeof(ti);
+ ti.lpszText = Buttons[bpos].tooltip;
+ ti.hinst = hInst;
+ ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS ;
+ ti.uId = (UINT_PTR)Buttons[bpos].hwnd;
+ return SendMessage(Buttons[bpos].hwndTip, TTM_UPDATETIPTEXT , 0, (LPARAM)&ti);
+}
+
+bool nameexists(const char *name)
+{
+ for (int i = 0; i < nButtonsCount; i++)
+ if (strcmp(Buttons[i].name, name) == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
+HICON LoadIconFromLibrary(char *SectName, char *Name, char *Description, HICON hIcon, bool RegisterIt, bool *RegistredOk)
+{
+ if (RegistredOk)
+ *RegistredOk = FALSE;
+
+ if (Name != NULL && *Name != 0) {
+ char iconame[256];
+ _snprintf(iconame, sizeof(iconame), "toptoolbar_%s", Name);
+ if ( ServiceExists(MS_SKIN2_ADDICON)) {
+ if (RegisterIt) {
+ SKINICONDESC sid = {0};
+ sid.cbSize = sizeof(sid);
+ sid.pszSection = Translate(SectName);
+ sid.pszName = iconame;
+ sid.pszDefaultFile = NULL;
+ sid.pszDescription = Description;
+ sid.hDefaultIcon = hIcon;
+ CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);
+
+ if (RegistredOk)
+ *RegistredOk = TRUE;
+ }
+ return ((HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)iconame));
+ }
+ }
+
+ return hIcon;
+}
+
+int CreateOneWindow(int ButtonPos)
+{
+ if (DBGetContactSettingByte(0, TTB_OPTDIR, "UseMirandaButtonClass", UseMirandaButtonClassDefaultValue) && !(Buttons[ButtonPos].dwFlags & TTBBF_ISSEPARATOR))
+ Buttons[ButtonPos].hwnd = CreateWindow(MYMIRANDABUTTONCLASS, "", BS_PUSHBUTTON|WS_CHILD|WS_TABSTOP|SS_NOTIFY, 0, 0, BUTTWIDTH, BUTTHEIGHT, hwndTopToolBar, NULL, hInst, 0);
+ else
+ Buttons[ButtonPos].hwnd = CreateWindow("STATIC", "", WS_CHILD|SS_NOTIFY, 0, 0, BUTTWIDTH, BUTTHEIGHT, hwndTopToolBar, NULL, hInst, 0);
+
+ SetWindowLong(Buttons[ButtonPos].hwnd, GWLP_USERDATA, Buttons[ButtonPos].id);
+ if (DBGetContactSettingByte(0, TTB_OPTDIR, "UseFlatButton", 1))
+ SendMessage(Buttons[ButtonPos].hwnd, BUTTONSETASFLATBTN, 0, 0);
+
+ return 0;
+}
+
+INT_PTR TTBAddButton(WPARAM wParam, LPARAM lParam)
+{
+ int i, retval;
+ TTBButtonV2 but;
+
+ 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;
+
+ lockbut();
+ if (nButtonsCount == MAX_BUTTONS)
+ return -1;
+
+ i = nButtonsCount;
+ memset(&but, 0, sizeof(but));
+
+ if (((TTBButton*)wParam)->cbSize == sizeof(TTBButton))
+ memcpy(&but, (void*)wParam, sizeof(TTBButton));
+
+ if (((TTBButton*)wParam)->cbSize == sizeof(TTBButtonV2))
+ memcpy(&but, (void*)wParam, sizeof(TTBButtonV2));
+
+ if ( but.name == NULL|| nameexists(but.name)) {
+ ulockbut();
+ return -1;
+ }
+
+ Buttons[i].id = nextButtonId++;
+ Buttons[i].hbBitmapDown = but.hbBitmapDown;
+ Buttons[i].hbBitmapUp = but.hbBitmapUp;
+ Buttons[i].hbDefBitmapDown = but.hbBitmapDown;
+ Buttons[i].hbDefBitmapUp = but.hbBitmapUp;
+
+ if (but.pszServiceDown != NULL) Buttons[i].pszServiceDown = strdup(but.pszServiceDown);
+ if (but.pszServiceUp != NULL) Buttons[i].pszServiceUp = strdup(but.pszServiceUp);
+ Buttons[i].name = strdup(but.name);
+ Buttons[i].dwFlags = but.dwFlags;
+
+ if (Buttons[i].dwFlags & TTBBF_DRAWBORDER) {
+ Buttons[i].hbWBordBitmapDown = DrawBorderForBitmap(Buttons[i].hbBitmapDown, FALSE);
+ Buttons[i].hbWBordBitmapUp = DrawBorderForBitmap(Buttons[i].hbBitmapUp, TRUE);
+ }
+
+ Buttons[i].wParamUp = but.wParamUp;
+ Buttons[i].lParamUp = but.lParamUp;
+ Buttons[i].wParamDown = but.wParamDown;
+ Buttons[i].lParamDown = but.lParamDown;
+
+ Buttons[i].dwFlags = but.dwFlags;
+
+ Buttons[i].bPushed = (but.dwFlags&TTBBF_PUSHED)?TRUE:FALSE;
+
+ CreateOneWindow(i);
+
+ Buttons[i].hIconUp = but.hIconUp ;
+ Buttons[i].hIconDn = but.hIconDn ;
+
+ if (UseIcoLib && (!(Buttons[i].dwFlags & TTBBF_ISSEPARATOR))) {
+ char buf[256];
+ sprintf(buf, "%s_up", Buttons[i].name);
+ Buttons[i].hIconUp = LoadIconFromLibrary("TopToolBar", buf, buf, but.hIconDn, TRUE, NULL);
+ sprintf(buf, "%s_dn", Buttons[i].name);
+ Buttons[i].hIconDn = LoadIconFromLibrary("TopToolBar", buf, buf, but.hIconUp, TRUE, NULL);
+ }
+
+ Buttons[i].hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
+ WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ hwndTopToolBar, NULL, hInst,
+ NULL);
+
+ SetWindowPos(Buttons[i].hwndTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+
+ TOOLINFO ti = { 0 };
+ ti.cbSize = sizeof(ti);
+ ti.lpszText = "";
+ ti.hinst = hInst;
+ ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS ;
+ ti.uId = (UINT_PTR)Buttons[i].hwnd;
+ SendMessage(Buttons[i].hwndTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
+
+ SendMessage(Buttons[i].hwndTip, TTM_ACTIVATE, (WPARAM)(Buttons[i].dwFlags&TTBBF_SHOWTOOLTIP)?TRUE:FALSE, 0);
+
+ SetWindowLong(Buttons[i].hwnd, GWLP_USERDATA, Buttons[i].id);
+
+ nButtonsCount++;
+
+ retval = Buttons[i].id;
+ DBLoadButtonSettings(i);
+ applyuserbitmaps(i);
+
+ SetButtBitmap(i);
+ ulockbut();
+ ArrangeButtons();
+ OptionsPageRebuild();
+ return retval;
+}
+
+int sortfunc(const void *a, const void *b)
+{
+ SortData *sd1 = ( SortData* )a, *sd2 = ( SortData* )b;
+
+ if (sd1->arrangeval > sd2->arrangeval)
+ return 1;
+ if (sd1->arrangeval < sd2->arrangeval)
+ return -1;
+ return 0;
+}
+
+bool isSep(int i)
+{
+ if (Buttons[i].dwFlags & TTBBF_ISSEPARATOR)
+ return TRUE;
+ return FALSE;
+}
+
+int getbutw(int i)
+{
+ RECT rc;
+ GetWindowRect(Buttons[i].hwnd, &rc);
+ return rc.right-rc.left;
+}
+
+int MakeSortArr(bool vis)
+{
+ int v = 0;
+ memset(&arrangedbuts, 0, sizeof(arrangedbuts));
+
+ for (int i = 0; i < nButtonsCount; i++) {
+ if (vis && !(Buttons[i].dwFlags & TTBBF_VISIBLE))
+ continue;
+
+ arrangedbuts[v].arrangeval = Buttons[i].arrangedpos;
+ arrangedbuts[v].oldpos = i;
+ v++;
+ }
+
+ if ( v > 0 )
+ qsort( arrangedbuts, v, sizeof(SortData), sortfunc);
+
+ return v;
+}
+
+int RecreateWindows()
+{
+ lockbut();
+ for (int i = 0; i < nButtonsCount; i++) {
+ if (Buttons[i].hwnd) {
+ DestroyWindow(Buttons[i].hwnd);
+ Buttons[i].hwnd = NULL;
+ CreateOneWindow(i);
+ }
+ }
+
+ ulockbut();
+ SetAllBitmaps();
+ return (0);
+}
+
+int ArrangeButtons()
+{
+ int i;
+ int newheight, cnt, perline;
+
+ if (StopArrange == TRUE)
+ return 0;
+
+ BUTTHEIGHT = DBGetContactSettingByte(0, TTB_OPTDIR, "BUTTHEIGHT", 16);
+ BUTTWIDTH = DBGetContactSettingByte(0, TTB_OPTDIR, "BUTTWIDTH", 20);
+
+ lockbut();
+ lastxpos = 1;
+
+ int v = MakeSortArr(TRUE);
+ if ( v > 0) {
+ for (i = 0; i < nButtonsCount; i++)
+ if ( !(Buttons[i].dwFlags & TTBBF_VISIBLE))
+ ShowWindow(Buttons[i].hwnd, SW_HIDE);
+
+ RECT winrc;
+ GetClientRect(hwndTopToolBar, &winrc);
+ winrc.left = winrc.right-winrc.left;
+ winrc.top = winrc.bottom-winrc.top;
+
+ int totwidth = 1;
+ int visbut = 0;
+ for (i = 0;i<v;i++)
+ {
+ if (!(Buttons[arrangedbuts[i].oldpos].dwFlags&TTBBF_VISIBLE)) continue;
+ totwidth+= BUTTWIDTH+1;
+ visbut++;
+ }
+
+ if (winrc.left == 0)
+ return 0;
+
+ perline = winrc.left/(BUTTWIDTH+1);
+ if (perline == 0)
+ perline = 1;
+
+ cnt = (visbut)/perline;
+ if (cnt*perline < visbut)
+ cnt++;
+ newheight = 1+((cnt))*(BUTTHEIGHT+2);
+
+ lastypos = 1;
+ lastxpos = 1;
+ newheight = BUTTHEIGHT+1;
+ CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT, hFrameTopWindow), BUTTHEIGHT+2);
+ for (i = 0; i < v; i++) {
+ int w1, w2, x;
+ if (!(Buttons[arrangedbuts[i].oldpos].dwFlags & TTBBF_VISIBLE)){
+ ShowWindow(Buttons[arrangedbuts[i].oldpos].hwnd, SW_HIDE);continue;}
+
+ // TTBBF_ISSEPARATOR
+ x = SWP_NOZORDER | SWP_SHOWWINDOW;
+ if ( Buttons[arrangedbuts[i].oldpos].dwFlags & TTBBF_ISSEPARATOR)
+ x = SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW;
+
+ SetWindowPos(Buttons[arrangedbuts[i].oldpos].hwnd, 0, lastxpos, lastypos, BUTTWIDTH, BUTTHEIGHT, x);
+ InvalidateRect(Buttons[arrangedbuts[i].oldpos].hwnd, NULL, TRUE);
+
+ //lastxpos += BUTTWIDTH+1;
+ if (i == v-1)
+ break;
+ if ( !(Buttons[arrangedbuts[i+1].oldpos].dwFlags & TTBBF_VISIBLE))
+ continue;
+
+ w1 = getbutw(arrangedbuts[i+1].oldpos);
+ w2 = getbutw(arrangedbuts[i].oldpos);
+ if ( (lastxpos+(+w1+w2+1)>winrc.left)) {
+ lastxpos = 1;
+ lastypos += BUTTHEIGHT+2;
+ if (Buttons[arrangedbuts[i+1].oldpos].dwFlags & TTBBF_VISIBLE) {
+ CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT, hFrameTopWindow), lastypos+BUTTHEIGHT+1);
+ newheight = lastypos+BUTTHEIGHT+1;
+ }
+ }
+ else {
+ lastxpos += (isSep(arrangedbuts[i].oldpos)) ? SEPWIDTH+2 : BUTTWIDTH+1;
+ if ( isSep(arrangedbuts[i+1].oldpos))
+ lastxpos++;
+ }
+ }
+ }
+
+ v = MakeSortArr(FALSE);
+ ulockbut();
+ return 1;
+}
+
+int SetButtBitmap(int pos)
+{
+ int t = IMAGE_BITMAP;
+ char *curname = (Buttons[pos].bPushed)?(Buttons[pos].UserDefinedbmDown):(Buttons[pos].UserDefinedbmUp);
+
+ int curstyle = GetWindowLongPtr(Buttons[pos].hwnd, GWL_STYLE);
+ curstyle &= (~SS_BITMAP);
+ curstyle &= (~SS_ICON);
+
+ if (!UseIcoLib||(Buttons[pos].dwFlags&TTBBF_ISSEPARATOR)) {
+ if (curname != NULL) {
+ if (strstr(curname, ".ico"))
+ t = IMAGE_ICON;
+
+ curstyle |= (t == IMAGE_ICON || UseIcoLib) ? SS_ICON : SS_BITMAP;
+ SetWindowLong(Buttons[pos].hwnd, GWL_STYLE, curstyle);
+ }
+ else SetWindowLong(Buttons[pos].hwnd, GWL_STYLE, curstyle|(Buttons[pos].hbBitmapDown == NULL?SS_ICON:SS_BITMAP));
+ }
+ else if (GetWindowLongPtr(Buttons[pos].hwnd, GWL_STYLE)&SS_ICON)
+ SetWindowLong(Buttons[pos].hwnd, GWL_STYLE, curstyle|SS_ICON);
+
+ if ( !UseIcoLib||(Buttons[pos].dwFlags & TTBBF_ISSEPARATOR)) {
+ if (!(Buttons[pos].dwFlags & TTBBF_DRAWBORDER)) {
+ if (Buttons[pos].hbBitmapDown == NULL) {
+ t = IMAGE_ICON;
+ SendMessage(Buttons[pos].hwnd, STM_SETIMAGE, t, (LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hIconDn):(Buttons[pos].hIconUp)));
+ SendMessage(Buttons[pos].hwnd, BM_SETIMAGE, t, (LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hIconDn):(Buttons[pos].hIconUp)));
+ }
+ else {
+ SendMessage(Buttons[pos].hwnd, STM_SETIMAGE, t, (LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hbBitmapDown):(Buttons[pos].hbBitmapUp)));
+ SendMessage(Buttons[pos].hwnd, BM_SETIMAGE, t, (LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hbBitmapDown):(Buttons[pos].hbBitmapUp)));
+ }
+ }
+ else SendMessage(Buttons[pos].hwnd, STM_SETIMAGE, t, (LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hbWBordBitmapDown):(Buttons[pos].hbWBordBitmapUp)));
+ }
+ else SendMessage(Buttons[pos].hwnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)((Buttons[pos].bPushed)?(Buttons[pos].hIconDn):(Buttons[pos].hIconUp)));
+
+ return 0;
+}
+
+//wparam = hTTBButton
+//lparam = state
+INT_PTR TTBSetState(WPARAM wParam, LPARAM lParam)
+{
+ lockbut();
+ int pos = idtopos(wParam);
+ if (pos<0||pos >= nButtonsCount){ulockbut();;return -1;}
+
+ Buttons[pos].bPushed = (lParam&TTBST_PUSHED)?TRUE:FALSE;
+ Buttons[pos].bPushed = (lParam&TTBST_RELEASED)?FALSE:TRUE;
+ SetButtBitmap(pos);
+ ulockbut();
+ return 0;
+}
+
+//wparam = hTTBButton
+//lparam = 0
+//return = state
+INT_PTR TTBGetState(WPARAM wParam, LPARAM lParam)
+{
+ lockbut();
+ int pos = idtopos(wParam);
+ if (pos < 0 || pos >= nButtonsCount) {
+ ulockbut();
+ return -1;
+ }
+
+ int retval = (Buttons[pos].bPushed == TRUE) ? TTBST_PUSHED : TTBST_RELEASED;
+ ulockbut();
+ return retval;
+}
+
+INT_PTR TTBGetOptions(WPARAM wParam, LPARAM lParam)
+{
+ int retval;
+
+ lockbut();
+ int pos = idtopos(HIWORD(wParam));
+ if (pos < 0 || pos >= nButtonsCount) {
+ ulockbut();
+ return -1;
+ }
+
+ switch(LOWORD(wParam)) {
+ case TTBO_FLAGS:
+
+ retval = Buttons[pos].dwFlags&(!TTBBF_PUSHED);
+ if (Buttons[pos].bPushed){retval |= TTBBF_PUSHED;}
+ break;
+
+ case TTBO_POS:
+ retval = (int)pos;
+ break;
+
+ case TTBO_TIPNAME:
+ retval = (int)Buttons[pos].tooltip;
+ break;
+
+ case TTBO_ALLDATA:
+ if (lParam) {
+ lpTTBButton lpTTB = (lpTTBButton)lParam;
+ if (lpTTB->cbSize != sizeof(TTBButton))
+ break;
+
+ lpTTB->dwFlags = Buttons[pos].dwFlags & (!TTBBF_PUSHED);
+ if (Buttons[pos].bPushed)
+ lpTTB->dwFlags |= TTBBF_PUSHED;
+
+ lpTTB->hbBitmapDown = Buttons[pos].hbBitmapDown;
+ lpTTB->hbBitmapUp = Buttons[pos].hbBitmapUp;
+ lpTTB->lParamUp = Buttons[pos].lParamUp;
+ lpTTB->wParamUp = Buttons[pos].wParamUp;
+ lpTTB->lParamDown = Buttons[pos].lParamDown;
+ lpTTB->wParamDown = Buttons[pos].wParamDown;
+
+ lpTTB->pszServiceDown = _strdup(Buttons[pos].pszServiceDown);
+ lpTTB->pszServiceUp = _strdup(Buttons[pos].pszServiceUp);
+
+ retval = ( INT_PTR )lpTTB;
+ break;
+ }
+
+ default:
+ retval = -1;
+ break;
+ }
+
+ ulockbut();
+ return retval;
+}
+
+
+INT_PTR TTBSetOptions(WPARAM wParam, LPARAM lParam)
+{
+ int pos, retval;
+
+ lockbut();
+ pos = idtopos(HIWORD(wParam));
+ if (pos<0||pos >= nButtonsCount){ulockbut();return -1;}
+
+ switch(LOWORD(wParam)) {
+ case TTBO_FLAGS:
+ if (Buttons[pos].dwFlags == lParam)
+ break;
+
+ Buttons[pos].dwFlags = lParam;
+ Buttons[pos].bPushed = (Buttons[pos].dwFlags & TTBBF_PUSHED) ? TRUE : FALSE;
+ if (Buttons[pos].dwFlags & TTBBF_DRAWBORDER) {
+ Buttons[pos].hbWBordBitmapDown = DrawBorderForBitmap(Buttons[pos].hbBitmapDown, FALSE);
+ Buttons[pos].hbWBordBitmapUp = DrawBorderForBitmap(Buttons[pos].hbBitmapUp, TRUE);
+ }
+
+ SetButtBitmap(pos);
+ SendMessage(Buttons[pos].hwndTip, TTM_ACTIVATE, (WPARAM)(Buttons[pos].dwFlags & TTBBF_SHOWTOOLTIP) ? TRUE : FALSE, 0);
+ retval = 1;
+ break;
+
+ case TTBO_POS:
+ if (lParam<0||lParam >= nButtonsCount)
+ break;
+ else {
+ TopButtonInt tempttb = Buttons[lParam];
+ Buttons[lParam] = Buttons[pos];
+ Buttons[pos] = tempttb;
+
+ ArrangeButtons();
+ retval = 1;
+ }
+ break;
+
+ case TTBO_TIPNAME:
+ if (lParam == 0)
+ break;
+ if (Buttons[pos].tooltip != NULL)
+ free(Buttons[pos].tooltip);
+ Buttons[pos].tooltip = _strdup((LPCSTR)lParam);
+ UpdateToolTip(pos);
+ retval = 1;
+ break;
+
+ case TTBO_ALLDATA:
+ if (lParam) {
+ lpTTBButton lpTTB = (lpTTBButton)lParam;
+
+ if (lpTTB->cbSize != sizeof(TTBButton)){break;}
+ Buttons[pos].dwFlags = lpTTB->dwFlags;
+ Buttons[pos].hbBitmapDown = lpTTB->hbBitmapDown;
+ Buttons[pos].hbBitmapUp = lpTTB->hbBitmapUp;
+ Buttons[pos].lParamUp = lpTTB->lParamUp;
+ Buttons[pos].wParamUp = lpTTB->wParamUp;
+ Buttons[pos].lParamDown = lpTTB->lParamDown;
+ Buttons[pos].wParamDown = lpTTB->wParamDown;
+
+ if (Buttons[pos].pszServiceDown != NULL)
+ free(Buttons[pos].pszServiceDown);
+ if (Buttons[pos].pszServiceUp != NULL)
+ free(Buttons[pos].pszServiceUp);
+
+ Buttons[pos].pszServiceDown = _strdup(lpTTB->pszServiceDown);
+ Buttons[pos].pszServiceUp = _strdup(lpTTB->pszServiceUp);
+
+ if (Buttons[pos].dwFlags & TTBBF_DRAWBORDER) {
+ Buttons[pos].hbWBordBitmapDown = DrawBorderForBitmap(Buttons[pos].hbBitmapDown, FALSE);
+ Buttons[pos].hbWBordBitmapUp = DrawBorderForBitmap(Buttons[pos].hbBitmapUp, TRUE);
+ }
+
+ Buttons[pos].bPushed = (Buttons[pos].dwFlags&TTBBF_PUSHED)?TRUE:FALSE;
+ SendMessage(Buttons[pos].hwndTip, TTM_ACTIVATE, (WPARAM)(Buttons[pos].dwFlags&TTBBF_SHOWTOOLTIP)?TRUE:FALSE, 0);
+ ArrangeButtons();
+ retval = 1;
+ }
+ break;
+
+ default:
+ retval = -1;
+ break;
+ }
+
+ ulockbut();
+ return retval;
+}
+
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+ hInst = hinstDLL;
+ return TRUE;
+}
+
+LRESULT CALLBACK TopToolBarProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg) {
+ case WM_CREATE:
+ hwndTopToolBar = hwnd;
+ return FALSE;
+
+ case WM_MOVE:
+ //RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
+ return 0;
+
+ case WM_WINDOWPOSCHANGING:
+ case WM_SIZE:
+ ArrangeButtons();
+ //RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN);
+ return 0;
+
+ //InvalidateRect(hwnd, NULL, TRUE);
+ //ArrangeButtons();
+ case WM_PAINT:
+ {
+ HDC hdcMem, hdc;
+ RECT clRect, *rcPaint;
+ int yScroll = 0;
+ int y;
+ PAINTSTRUCT paintst;
+ HBITMAP hBmpOsb, hOldBmp;
+ DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE);
+ int grey = 0;
+ HBRUSH hBrushAlternateGrey = NULL;
+
+ InvalidateRect(hwnd, 0, FALSE);
+
+ hdc = BeginPaint(hwnd, &paintst);
+ rcPaint = &(paintst.rcPaint);
+
+ GetClientRect(hwnd, &clRect);
+ if (rcPaint == NULL) rcPaint = &clRect;
+ y = -yScroll;
+ hdcMem = CreateCompatibleDC(hdc);
+ hBmpOsb = CreateBitmap(clRect.right, clRect.bottom, 1, GetDeviceCaps(hdc, BITSPIXEL), NULL);
+ hOldBmp = (HBITMAP)SelectObject(hdcMem, hBmpOsb);
+ SetBkMode(hdcMem, TRANSPARENT);
+
+ HBRUSH hBrush, hoBrush;
+
+ hBrush = CreateSolidBrush(bkColour);
+ 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 = BUTTHEIGHT+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 = BUTTHEIGHT+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);
+ 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_NOTIFY:
+ return 0;
+
+ case WM_COMMAND:
+ if ((HIWORD(wParam) == STN_CLICKED|| HIWORD(wParam) == STN_DBLCLK)) {
+ int id = GetWindowLongPtr((HWND)lParam, GWLP_USERDATA);
+ if (id != 0) {
+ lockbut();
+ int pos = idtopos(id);
+ if (isSep(pos)) {
+ ulockbut();
+ return 0;
+ }
+
+ if (Buttons[pos].bPushed) {
+ //Dn -> Up
+ Buttons[pos].bPushed = !Buttons[pos].bPushed;
+ SetButtBitmap(pos);
+
+ if (Buttons[pos].pszServiceUp != NULL)
+ CallService(Buttons[pos].pszServiceUp, Buttons[pos].wParamUp, Buttons[pos].lParamUp);
+ }
+ else {
+ //Up -> Dn
+ Buttons[pos].bPushed = !Buttons[pos].bPushed;
+ SetButtBitmap(pos);
+
+ if (Buttons[pos].pszServiceDown != NULL)
+ CallService(Buttons[pos].pszServiceDown, Buttons[pos].wParamDown, Buttons[pos].lParamDown);
+ }
+ ulockbut();
+ }
+ }
+ break;
+
+ default:
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+ }
+ return(TRUE);
+}
+
+int addTopToolBarWindow(HWND parent)
+{
+ char pluginname[] = "TopToolBar";
+
+ WNDCLASS wndclass;
+ wndclass.style = 0;
+ wndclass.lpfnWndProc = TopToolBarProc;
+ wndclass.cbClsExtra = 0;
+ wndclass.cbWndExtra = 0;
+ wndclass.hInstance = hInst;
+ wndclass.hIcon = NULL;
+ wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
+ wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);//NULL;//(HBRUSH)(COLOR_3DFACE+1);
+ wndclass.lpszMenuName = NULL;
+ wndclass.lpszClassName = pluginname;
+ RegisterClass(&wndclass);
+ HWND pluginwind = CreateWindow(pluginname, pluginname,
+ WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ 0, 0, 0, 0, parent, NULL, hInst, NULL);
+
+ ttbOptionsChanged();
+
+ CLISTFrame Frame = { 0 };
+ Frame.name = (char *)malloc(255);
+ memset(Frame.name, 0, 255);
+ memcpy(Frame.name, pluginname, sizeof(pluginname));
+ Frame.cbSize = sizeof(Frame);
+ Frame.hWnd = pluginwind;
+ Frame.align = alTop;
+ Frame.Flags = F_VISIBLE|F_NOBORDER|F_LOCKED;
+ Frame.height = 18;
+
+ int retval = CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&Frame, 0);
+ free(Frame.name);
+ return retval;
+}
+
+VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
+{
+ KillTimer(0, idEvent);
+ NotifyEventHooks(hHookTTBModuleLoaded, 0, 0);
+}
+
+static INT_PTR OnEventFire(WPARAM wParam, LPARAM lParam)
+{
+ CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0);
+ StopArrange = FALSE;
+ NotifyEventHooks(hHookTTBModuleLoaded, 0, 0);
+ return 0;
+}
+
+int OnIconChange(WPARAM wParam, LPARAM lParam)
+{
+ lockbut();
+ for (int i = 0; i < nButtonsCount; i++) {
+ char buf[256];
+ sprintf(buf, "%s_up", Buttons[i].name);
+ Buttons[i].hIconUp = LoadIconFromLibrary("TopToolBar", buf, buf, Buttons[i].hIconUp, FALSE, NULL);
+ sprintf(buf, "%s_dn", Buttons[i].name);
+ Buttons[i].hIconDn = LoadIconFromLibrary("TopToolBar", buf, buf, Buttons[i].hIconDn, FALSE, NULL);
+ }
+ ulockbut();
+ RecreateWindows();
+ SetAllBitmaps();
+ ArrangeButtons();
+ return 0;
+}
+
+static int OnBGChange(WPARAM wParam, LPARAM lParam)
+{
+ ttbOptionsChanged();
+ return 0;
+}
+
+static int OnmodulesLoad(WPARAM wParam, LPARAM lParam)
+{
+ int ex = 0;
+
+ hwndContactList = (HWND)CallService(MS_CLUI_GETHWND, 0, 0);
+
+ if (!ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) {
+ MessageBox(0, "Frames Services not found - plugin disabled.You need MultiWindow plugin.", "TopToolBar", 0);
+ return 0;
+ ex = 1;
+ }
+ if (!ServiceExists(MS_CLUI_GETHWNDTREE)) {
+ MessageBox(0, "MS_CLUI_GETHWNDTREE Service not found - plugin disabled", "TopToolBar", 0);
+ return 0;
+ ex = 1;
+ }
+
+ if (ex == 1)
+ return 0;
+
+ OptionsOpened = false;
+ CreateServiceFunction(MS_TTB_ADDBUTTON, TTBAddButton);
+ CreateServiceFunction(MS_TTB_REMOVEBUTTON, TTBRemoveButton);
+
+ CreateServiceFunction(MS_TTB_SETBUTTONSTATE, TTBSetState);
+ CreateServiceFunction(MS_TTB_GETBUTTONSTATE, TTBGetState);
+
+ CreateServiceFunction(MS_TTB_GETBUTTONOPTIONS, TTBGetOptions);
+ CreateServiceFunction(MS_TTB_SETBUTTONOPTIONS, TTBSetOptions);
+ CreateServiceFunction(TTB_ADDSEPARATOR, InsertNewFreeSeparator);
+ CreateServiceFunction(TTB_REMOVESEPARATOR, DeleteSeparator);
+
+ CreateServiceFunction("TTB_ONSTARTUPFIRE", OnEventFire);
+ UseIcoLib = DBGetContactSettingByte(0, TTB_OPTDIR, "UseIcoLib", UseIcoLibDefaultValue);
+ if (UseIcoLib)
+ HookEvent(ME_SKIN2_ICONSCHANGED, OnIconChange);
+
+ hFrameTopWindow = addTopToolBarWindow(hwndContactList);
+ LoadInternalButtons(( HWND )CallService(MS_CLUI_GETHWNDTREE, 0, 0));
+ SaveAllButtonsOptions();
+
+ LoadAllSeparators();
+ InitLBut();
+
+ StopArrange = FALSE;
+ ArrangeButtons();
+
+ HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);//anonymous event
+ if (hEvent != 0)
+ CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hEvent, (LPARAM)"TTB_ONSTARTUPFIRE");
+
+ if ( ServiceExists(MS_BACKGROUNDCONFIG_REGISTER)) {
+ char buf[256];
+ sprintf(buf, "TopToolBar Background/%s", TTB_OPTDIR);
+ CallService(MS_BACKGROUNDCONFIG_REGISTER, (WPARAM)buf, 0);
+ HookEvent(ME_BACKGROUNDCONFIG_CHANGED, OnBGChange);
+ }
+
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static const MUUID interfaces[] = {MIID_TTB, MIID_LAST};
+
+__declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
+{
+ return interfaces;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+PLUGININFOEX pluginInfo =
+{
+ sizeof(PLUGININFOEX),
+ "TopToolbar",
+ PLUGIN_MAKE_VERSION(0, 7, 3, 1),
+ "ToptoolBar adds buttons in top frame for fast access.This plugin uses MultiWindow or CList_MW plugin.("__DATE__" "__TIME__")",
+ "Bethoven",
+ "Bethoven@mailgate.ru",
+ "© 2003-2008 Bethoven",
+ "http://www.miranda-im.org/",
+ UNICODE_AWARE,
+ 0, //doesn't replace anything built-in
+ MIID_TTB
+};
+
+__declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ return &pluginInfo;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+int __declspec(dllexport) Load(PLUGINLINK *link)
+{
+ pluginLink = link;
+ mir_getMMI( &mmi );
+ mir_getLP(&pluginInfo);
+
+ InitializeCriticalSection(&csButtonsHook);
+ StopArrange = TRUE;
+ LoadCLCButtonModule();
+ LoadButtonModule();
+
+ hModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, OnmodulesLoad);
+ hOptInit = HookEvent(ME_OPT_INITIALISE, TTBOptInit);
+
+ BUTTHEIGHT = DBGetContactSettingByte(0, TTB_OPTDIR, "BUTTHEIGHT", 16);
+ BUTTWIDTH = DBGetContactSettingByte(0, TTB_OPTDIR, "BUTTWIDTH", 20);
+ hHookTTBModuleLoaded = CreateHookableEvent(ME_TTB_MODULELOADED);
+ return 0;
+}
+
+int __declspec(dllexport) Unload(void)
+{
+ SaveAllSeparators();
+ UnInitLBut();
+ UnLoadInternalButtons();
+
+ DeleteCriticalSection(&csButtonsHook);
+ UnhookEvent(hModulesLoaded);
+ UnhookEvent(hOptInit);
+ return 0;
+} \ No newline at end of file
diff --git a/plugins/TopToolBar/main.rc b/plugins/TopToolBar/main.rc
index 235447ddba..45da6ef577 100644
--- a/plugins/TopToolBar/main.rc
+++ b/plugins/TopToolBar/main.rc
@@ -17,7 +17,7 @@
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
#ifdef _WIN32
-LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#pragma code_page(1251)
#endif //_WIN32
@@ -26,40 +26,40 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
// Dialog
//
-IDD_OPT_BUTORDER DIALOGEX 0, 0, 300, 231
+IDD_OPT_BUTORDER DIALOGEX 0, 0, 300, 231
STYLE DS_SETFONT | WS_CHILD
-FONT 8, "MS Sans Serif", 0, 0, 0x1
+FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
- GROUPBOX "Buttons Order && Visibility",IDC_STATIC,10,0,150,180
- CONTROL "Tree1",IDC_BUTTONORDERTREE,"SysTreeView32",TVS_NOTOOLTIPS | WS_BORDER | WS_TABSTOP,20,25,132,100
- LTEXT "Buttons order:",IDC_STATIC,20,15,132,8
- CONTROL 268,IDC_BMPUP,"Static",SS_BITMAP | SS_NOTIFY,60,130,13,10
- CONTROL 268,IDC_BMPDN,"Static",SS_BITMAP | SS_NOTIFY,115,130,13,10,WS_EX_TRANSPARENT
- LTEXT "Up:",IDC_STATIC1,35,130,12,8
- LTEXT "Down:",IDC_STATIC2,85,130,22,8
- PUSHBUTTON "Default",IDC_DEFAULT,55,146,50,14
- LTEXT "Click on images to select new bitmaps.",IDC_STATIC3,15,165,140,8
- PUSHBUTTON "Add Separator",IDC_ADDSEP,175,15,55,14
- PUSHBUTTON "Del Separator",IDC_REMOVESEP,235,15,55,14
- PUSHBUTTON "Add Launch",IDC_ADDLBUTTON,180,60,100,14
- PUSHBUTTON "Del Launch",IDC_DELLBUTTON,180,81,100,14
- EDITTEXT IDC_ENAME,195,100,85,14,ES_AUTOHSCROLL
- LTEXT "Name: ",IDC_LBUTTONNAME,170,100,24,8
- EDITTEXT IDC_EPATH,195,121,85,14,ES_AUTOHSCROLL
- LTEXT "Path:",IDC_LBUTTONPATH,170,121,18,8
- PUSHBUTTON "Set",IDC_LBUTTONSET,205,140,50,14
- EDITTEXT IDC_IMGDIR,65,190,205,14,ES_AUTOHSCROLL | ES_READONLY
- GROUPBOX "Separator Button",IDC_STATIC,165,0,130,40
- GROUPBOX "Launch Button",IDC_STATIC,165,45,130,115
- PUSHBUTTON "...",IDC_OPENIMGDIR,275,190,14,14
- CONTROL "Image Directory:",IDC_STATIC,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,5,190,55,10
- LTEXT "Button Height:",IDC_STATIC,11,210,46,8
- EDITTEXT IDC_BUTTHEIGHT,65,207,24,14,ES_AUTOHSCROLL
- LTEXT "Button Width: ",IDC_STATIC,99,210,46,8
- EDITTEXT IDC_BUTTWIDTH,147,208,24,14,ES_AUTOHSCROLL
- CONTROL "Use Miranda Button Class",IDC_USEMIRANDABUTTON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,185,210,97,10
- CONTROL "Use Flat Mode",IDC_USEFLAT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,220,62,10
- CONTROL "Use IcoLib (need restart!)",IDC_USEICOLIB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,165,95,10
+ GROUPBOX "Buttons Order && Visibility", IDC_STATIC, 10, 0, 150, 180
+ CONTROL "Tree1", IDC_BUTTONORDERTREE, "SysTreeView32", TVS_NOTOOLTIPS | WS_BORDER | WS_TABSTOP, 20, 25, 132, 100
+ LTEXT "Buttons order:", IDC_STATIC, 20, 15, 132, 8
+ CONTROL 268, IDC_BMPUP, "Static", SS_BITMAP | SS_NOTIFY, 60, 130, 13, 10
+ CONTROL 268, IDC_BMPDN, "Static", SS_BITMAP | SS_NOTIFY, 115, 130, 13, 10, WS_EX_TRANSPARENT
+ LTEXT "Up:", IDC_STATIC1, 35, 130, 12, 8
+ LTEXT "Down:", IDC_STATIC2, 85, 130, 22, 8
+ PUSHBUTTON "Default", IDC_DEFAULT, 55, 146, 50, 14
+ LTEXT "Click on images to select new bitmaps.", IDC_STATIC3, 15, 165, 140, 8
+ PUSHBUTTON "Add Separator", IDC_ADDSEP, 175, 15, 55, 14
+ PUSHBUTTON "Del Separator", IDC_REMOVESEP, 235, 15, 55, 14
+ PUSHBUTTON "Add Launch", IDC_ADDLBUTTON, 180, 60, 100, 14
+ PUSHBUTTON "Del Launch", IDC_DELLBUTTON, 180, 81, 100, 14
+ EDITTEXT IDC_ENAME, 195, 100, 85, 14, ES_AUTOHSCROLL
+ LTEXT "Name: ", IDC_LBUTTONNAME, 170, 100, 24, 8
+ EDITTEXT IDC_EPATH, 195, 121, 85, 14, ES_AUTOHSCROLL
+ LTEXT "Path:", IDC_LBUTTONPATH, 170, 121, 18, 8
+ PUSHBUTTON "Set", IDC_LBUTTONSET, 205, 140, 50, 14
+ EDITTEXT IDC_IMGDIR, 65, 190, 205, 14, ES_AUTOHSCROLL | ES_READONLY
+ GROUPBOX "Separator Button", IDC_STATIC, 165, 0, 130, 40
+ GROUPBOX "Launch Button", IDC_STATIC, 165, 45, 130, 115
+ PUSHBUTTON "...", IDC_OPENIMGDIR, 275, 190, 14, 14
+ CONTROL "Image Directory:", IDC_STATIC, "Static", SS_LEFTNOWORDWRAP | WS_GROUP, 5, 190, 55, 10
+ LTEXT "Button Height:", IDC_STATIC, 11, 210, 46, 8
+ EDITTEXT IDC_BUTTHEIGHT, 65, 207, 24, 14, ES_AUTOHSCROLL
+ LTEXT "Button Width: ", IDC_STATIC, 99, 210, 46, 8
+ EDITTEXT IDC_BUTTWIDTH, 147, 208, 24, 14, ES_AUTOHSCROLL
+ CONTROL "Use Miranda Button Class", IDC_USEMIRANDABUTTON, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 185, 210, 97, 10
+ CONTROL "Use Flat Mode", IDC_USEFLAT, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 201, 220, 62, 10
+ CONTROL "Use IcoLib (need restart!)", IDC_USEICOLIB, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 170, 165, 95, 10
END
@@ -71,18 +71,18 @@ END
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
- IDD_OPT_BUTORDER, DIALOG
+ IDD_OPT_BUTORDER, DIALOG
BEGIN
- VERTGUIDE, 8
- VERTGUIDE, 140
- VERTGUIDE, 158
- VERTGUIDE, 290
- VERTGUIDE, 297
- BOTTOMMARGIN, 229
- HORZGUIDE, 17
- HORZGUIDE, 38
- HORZGUIDE, 133
- HORZGUIDE, 138
+ VERTGUIDE, 8
+ VERTGUIDE, 140
+ VERTGUIDE, 158
+ VERTGUIDE, 290
+ VERTGUIDE, 297
+ BOTTOMMARGIN, 229
+ HORZGUIDE, 17
+ HORZGUIDE, 38
+ HORZGUIDE, 133
+ HORZGUIDE, 138
END
END
#endif // APSTUDIO_INVOKED
@@ -96,7 +96,7 @@ END
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
#ifdef _WIN32
-LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
+LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32
@@ -105,12 +105,12 @@ LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
// Dialog
//
-IDD_FRAMEPLUG2 DIALOG 0, 0, 211, 11
+IDD_FRAMEPLUG2 DIALOG 0, 0, 211, 11
STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN
-FONT 8, "MS Sans Serif"
+FONT 8, "MS Sans Serif"
BEGIN
- CONTROL 262,IDC_P2ONLINEBUTT,"Static",SS_BITMAP | SS_NOTIFY | NOT WS_VISIBLE,55,0,13,10
- CONTROL 269,IDC_P2GROUPBUTT,"Static",SS_BITMAP | SS_NOTIFY | NOT WS_VISIBLE,70,0,13,10
+ CONTROL 262, IDC_P2ONLINEBUTT, "Static", SS_BITMAP | SS_NOTIFY | NOT WS_VISIBLE, 55, 0, 13, 10
+ CONTROL 269, IDC_P2GROUPBUTT, "Static", SS_BITMAP | SS_NOTIFY | NOT WS_VISIBLE, 70, 0, 13, 10
END
@@ -122,10 +122,10 @@ END
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
- IDD_FRAMEPLUG2, DIALOG
+ IDD_FRAMEPLUG2, DIALOG
BEGIN
- RIGHTMARGIN, 197
- BOTTOMMARGIN, 10
+ RIGHTMARGIN, 197
+ BOTTOMMARGIN, 10
END
END
#endif // APSTUDIO_INVOKED
@@ -194,8 +194,8 @@ IDI_MIRANDADN ICON "icos\\Show Main Menu_DN.ico"
//
VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,7,3,1
- PRODUCTVERSION 0,7,3,1
+ FILEVERSION 0, 7, 3, 1
+ PRODUCTVERSION 0, 7, 3, 1
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -210,18 +210,18 @@ BEGIN
BEGIN
BLOCK "041904b0"
BEGIN
- VALUE "FileDescription", "ToptoolBar adds buttons in top frame for fast access."
- VALUE "FileVersion", "0.7.3.1"
- VALUE "InternalName", "TopToolBar"
- VALUE "LegalCopyright", "© 2003-2008 Bethoven"
- VALUE "OriginalFilename", "TopToolbar.dll"
- VALUE "ProductName", "TopToolBar"
- VALUE "ProductVersion", "0.7.3.1"
+ VALUE "FileDescription", "ToptoolBar adds buttons in top frame for fast access."
+ VALUE "FileVersion", "0.7.3.1"
+ VALUE "InternalName", "TopToolBar"
+ VALUE "LegalCopyright", "© 2003-2008 Bethoven"
+ VALUE "OriginalFilename", "TopToolbar.dll"
+ VALUE "ProductName", "TopToolBar"
+ VALUE "ProductVersion", "0.7.3.1"
END
END
BLOCK "VarFileInfo"
BEGIN
- VALUE "Translation", 0x419, 1200
+ VALUE "Translation", 0x419, 1200
END
END
@@ -234,7 +234,7 @@ END
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
#ifdef _WIN32
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#pragma code_page(1252)
#endif //_WIN32
@@ -256,7 +256,7 @@ IDI_TICK ICON "icos\\notick1.ico"
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENC)
#ifdef _WIN32
-LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_CAN
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_CAN
#pragma code_page(1252)
#endif //_WIN32
@@ -265,25 +265,25 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_CAN
// Dialog
//
-IDD_OPT_TTBBKG DIALOGEX 0, 0, 235, 132
+IDD_OPT_TTBBKG DIALOGEX 0, 0, 235, 132
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE
EXSTYLE WS_EX_CONTROLPARENT
-FONT 8, "MS Shell Dlg", 0, 0, 0x1
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
- GROUPBOX "TopToolBar Background",IDC_STATIC,4,4,227,124
- LTEXT "Background colour:",IDC_STATIC,12,20,72,8,NOT WS_GROUP
- CONTROL "",IDC_BKGCOLOUR,"ColourPicker",WS_TABSTOP,84,19,32,10
- LTEXT "Selection colour:",IDC_STATIC,12,36,72,8,NOT WS_VISIBLE
- CONTROL "",IDC_SELCOLOUR,"ColourPicker",NOT WS_VISIBLE | WS_TABSTOP,84,35,32,10
- CONTROL "Use background bitmap",IDC_BITMAP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,53,161,10
- EDITTEXT IDC_FILENAME,22,67,184,12,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_BROWSE,208,67,15,11
- CONTROL "Stretch to width",IDC_STRETCHH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,22,84,100,10
- CONTROL "Stretch to height",IDC_STRETCHV,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,122,84,101,10
- CONTROL "Tile horizontally",IDC_TILEH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,22,97,100,10
- CONTROL "Tile vertically",IDC_TILEV,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,122,97,101,10
- CONTROL "Scroll with text",IDC_SCROLL,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,22,110,100,10
- CONTROL "Stretch proportionally",IDC_PROPORTIONAL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,122,110,101,10
+ GROUPBOX "TopToolBar Background", IDC_STATIC, 4, 4, 227, 124
+ LTEXT "Background colour:", IDC_STATIC, 12, 20, 72, 8, NOT WS_GROUP
+ CONTROL "", IDC_BKGCOLOUR, "ColourPicker", WS_TABSTOP, 84, 19, 32, 10
+ LTEXT "Selection colour:", IDC_STATIC, 12, 36, 72, 8, NOT WS_VISIBLE
+ CONTROL "", IDC_SELCOLOUR, "ColourPicker", NOT WS_VISIBLE | WS_TABSTOP, 84, 35, 32, 10
+ CONTROL "Use background bitmap", IDC_BITMAP, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 12, 53, 161, 10
+ EDITTEXT IDC_FILENAME, 22, 67, 184, 12, ES_AUTOHSCROLL
+ PUSHBUTTON "...", IDC_BROWSE, 208, 67, 15, 11
+ CONTROL "Stretch to width", IDC_STRETCHH, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 22, 84, 100, 10
+ CONTROL "Stretch to height", IDC_STRETCHV, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 122, 84, 101, 10
+ CONTROL "Tile horizontally", IDC_TILEH, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 22, 97, 100, 10
+ CONTROL "Tile vertically", IDC_TILEV, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 122, 97, 101, 10
+ CONTROL "Scroll with text", IDC_SCROLL, "Button", BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP, 22, 110, 100, 10
+ CONTROL "Stretch proportionally", IDC_PROPORTIONAL, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 122, 110, 101, 10
END
@@ -295,21 +295,21 @@ END
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
- IDD_OPT_TTBBKG, DIALOG
+ IDD_OPT_TTBBKG, DIALOG
BEGIN
- LEFTMARGIN, 4
- RIGHTMARGIN, 231
- VERTGUIDE, 12
- VERTGUIDE, 22
- VERTGUIDE, 122
- TOPMARGIN, 4
- BOTTOMMARGIN, 128
- HORZGUIDE, 24
- HORZGUIDE, 40
- HORZGUIDE, 73
- HORZGUIDE, 89
- HORZGUIDE, 102
- HORZGUIDE, 115
+ LEFTMARGIN, 4
+ RIGHTMARGIN, 231
+ VERTGUIDE, 12
+ VERTGUIDE, 22
+ VERTGUIDE, 122
+ TOPMARGIN, 4
+ BOTTOMMARGIN, 128
+ HORZGUIDE, 24
+ HORZGUIDE, 40
+ HORZGUIDE, 73
+ HORZGUIDE, 89
+ HORZGUIDE, 102
+ HORZGUIDE, 115
END
END
#endif // APSTUDIO_INVOKED
diff --git a/plugins/TopToolBar/separators.c b/plugins/TopToolBar/separators.c
deleted file mode 100644
index 3be5e056a3..0000000000
--- a/plugins/TopToolBar/separators.c
+++ /dev/null
@@ -1,111 +0,0 @@
-
-#include "common.h"
-#pragma hdrstop
-
-extern HINSTANCE hInst;
-#define MAXSEPS 32
-int Separators[MAXSEPS];
-
-static int SeparatorCnt=0;
-
-int InsertSeparator(int id)
-{
- TTBButton ttb;
- char buf[255];
-
- HBITMAP Separator=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_SEP));
- //itoa(SeparatorCnt++,buf,10);
-
- wsprintf(buf,"%s %d",Translate("Separator"),id);
- memset(&ttb,0,sizeof(ttb));
- ttb.cbSize=sizeof(ttb);
- ttb.hbBitmapDown=Separator;
- ttb.hbBitmapUp=Separator;
- ttb.dwFlags=TTBBF_VISIBLE|TTBBF_ISSEPARATOR;
- ttb.pszServiceDown="";
- ttb.pszServiceUp="";
- ttb.lParamDown=id;
- ttb.name=buf;
- SeparatorCnt++;
- return(TTBAddButton(&ttb,0));
-};
-
-INT_PTR DeleteSeparator(WPARAM id,LPARAM lParam)
-{
- if ((id<0)||(id>=MAXSEPS))
- {
- MessageBoxA(0,"Wrong id","Error",0);
- return(0);
- };
-
- if (Separators[id]!=0)
- {
- TTBRemoveButton(Separators[id],0);
- Separators[id]=0;
- SeparatorCnt--;
- };
- SaveAllSeparators();
- return (1);
-};
-int LoadAllSeparators()
-{
- char buf[255];
- char buf1[10];
- int id,i;
-
- //must be locked
- memset(buf,0,sizeof(buf));
-
- memset(Separators,0,sizeof(Separators));
- for (i=0;i<MAXSEPS;i++)
- {
- memset(buf1,0,sizeof(buf1));
- _itoa(i,buf1,10);
- id=DBGetContactSettingWord(0,TTB_OPTDIR,AS(buf,"Sep",buf1),-1);
- if (id==i)
- {
- Separators[i]=InsertSeparator(i);
- };
- };
- return 0;
-};
-int SaveAllSeparators()
-{
- char buf[255];
- char buf1[10];
- int i;
- for (i=0;i<MAXSEPS;i++)
- {
- memset(buf1,0,sizeof(buf1));
- _itoa(i,buf1,10);
- if (Separators[i]!=0)
- {
- DBWriteContactSettingWord(0,TTB_OPTDIR,AS(buf,"Sep",buf1),i);
- }
- else
- {
- DBWriteContactSettingWord(0,TTB_OPTDIR,AS(buf,"Sep",buf1),-1);
- DBDeleteContactSetting(0,TTB_OPTDIR,AS(buf,"Sep",buf1));
- };
- };
- return 0;
-};
-//return 0 on success,-1 on error
-INT_PTR InsertNewFreeSeparator(WPARAM wParam,LPARAM lParam)
-{
- if (SeparatorCnt<MAXSEPS)
- {
- int i;
- for (i=0;i<MAXSEPS;i++)
- {
- if (Separators[i]==0)
- {
- Separators[i]=InsertSeparator(i);
- SaveAllSeparators();
- return(0);
- };
- };
- };
-
- return(-1);
-};
diff --git a/plugins/TopToolBar/separators.cpp b/plugins/TopToolBar/separators.cpp
new file mode 100644
index 0000000000..28cd67857e
--- /dev/null
+++ b/plugins/TopToolBar/separators.cpp
@@ -0,0 +1,98 @@
+
+#include "common.h"
+#pragma hdrstop
+
+extern HINSTANCE hInst;
+#define MAXSEPS 32
+int Separators[MAXSEPS];
+
+static int SeparatorCnt = 0;
+
+int InsertSeparator(int id)
+{
+ HBITMAP Separator = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_SEP));
+
+ char buf[255];
+ wsprintf(buf, "%s %d", Translate("Separator"), id);
+
+ TTBButton ttb = { 0 };
+ ttb.cbSize = sizeof(ttb);
+ ttb.hbBitmapDown = Separator;
+ ttb.hbBitmapUp = Separator;
+ ttb.dwFlags = TTBBF_VISIBLE | TTBBF_ISSEPARATOR;
+ ttb.pszServiceDown = "";
+ ttb.pszServiceUp = "";
+ ttb.lParamDown = id;
+ ttb.name = buf;
+ SeparatorCnt++;
+ return ( int )TTBAddButton((WPARAM)&ttb, 0);
+}
+
+INT_PTR DeleteSeparator(WPARAM id, LPARAM lParam)
+{
+ if ((id<0)||(id >= MAXSEPS)) {
+ MessageBoxA(0, "Wrong id", "Error", 0);
+ return 0;
+ }
+
+ if (Separators[id] != 0) {
+ TTBRemoveButton(Separators[id], 0);
+ Separators[id] = 0;
+ SeparatorCnt--;
+ }
+
+ SaveAllSeparators();
+ return 1;
+}
+
+int LoadAllSeparators()
+{
+ //must be locked
+ char buf[255];
+ memset(buf, 0, sizeof(buf));
+
+ memset(Separators, 0, sizeof(Separators));
+ for (int i = 0; i < MAXSEPS; i++) {
+ char buf1[10];
+ _itoa(i, buf1, 10);
+
+ int id = DBGetContactSettingWord(0, TTB_OPTDIR, AS(buf, "Sep", buf1), -1);
+ if (id == i)
+ Separators[i] = InsertSeparator(i);
+ }
+ return 0;
+}
+
+int SaveAllSeparators()
+{
+ char buf[255];
+ char buf1[10];
+
+ for (int i = 0; i < MAXSEPS; i++) {
+ memset(buf1, 0, sizeof(buf1));
+ _itoa(i, buf1, 10);
+ if (Separators[i] != 0)
+ DBWriteContactSettingWord(0, TTB_OPTDIR, AS(buf, "Sep", buf1), i);
+ else {
+ DBWriteContactSettingWord(0, TTB_OPTDIR, AS(buf, "Sep", buf1), -1);
+ DBDeleteContactSetting(0, TTB_OPTDIR, AS(buf, "Sep", buf1));
+ }
+ }
+ return 0;
+}
+
+//return 0 on success, -1 on error
+INT_PTR InsertNewFreeSeparator(WPARAM wParam, LPARAM lParam)
+{
+ if (SeparatorCnt < MAXSEPS) {
+ for (int i = 0; i < MAXSEPS; i++) {
+ if (Separators[i] == 0) {
+ Separators[i] = InsertSeparator(i);
+ SaveAllSeparators();
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
diff --git a/plugins/TopToolBar/ttbopt.c b/plugins/TopToolBar/ttbopt.c
deleted file mode 100644
index f202e7a6c0..0000000000
--- a/plugins/TopToolBar/ttbopt.c
+++ /dev/null
@@ -1,970 +0,0 @@
-#include "common.h"
-#include <shlobj.h>
-#pragma hdrstop
-
-static BOOL CALLBACK DlgProcTTBBkgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
-extern int ttbOptionsChanged();
-extern HINSTANCE hInst;
-
-extern TopButtonInt Buttons[MAX_BUTTONS];
-extern int nButtonsCount;
-
-extern SortData arrangedbuts[MAX_BUTTONS];
-
-extern void lockbut();
-extern void ulockbut();
-extern int applyuserbitmaps();
-
-struct OrderData {
- int dragging;
- HTREEITEM hDragItem;
-};
-
-char *SetEndSlash(char *str)
-{
- char *outs;
- if (str==NULL){return(NULL);};
- if (strlen(str)==0){return(NULL);};
- outs=str;
-
- if (str[strlen(str)-1]!='\\')
- {
- outs=(char*)malloc(strlen(str)+3);
- memset(outs,0,strlen(str)+3);
- strcat(outs,str);
- outs[strlen(str)]='\\';
- //free(str);
- };
- return(outs);
-};
-boolean FileExists(char *fname)
-{
- HANDLE h;
- WIN32_FIND_DATA wfd;
-
-
-
- /*
- h=CreateFile(fname,GENERIC_READ,
- FILE_SHARE_READ,
- NULL,OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- */
- memset(&wfd,0,sizeof(wfd));
- h=FindFirstFile(fname,&wfd);
-
- if (h==INVALID_HANDLE_VALUE) {
- return(FALSE);
- }
- else
- {
- FindClose(h);
- return(TRUE);
- };
-
-
-};
-
-
-char *ReplaceBadChar(char *str,char bad,char toreplace)
-{
- int i;
- for (i=0;i<strlen(str);i++)
- {
- if (str[i]==bad){str[i]=toreplace;};
- };
- return(str);
-};
-char *ReplaceAll(char *str)
-{
- ReplaceBadChar(str,'\\','_');
- ReplaceBadChar(str,'/','_');
- ReplaceBadChar(str,'"','_');
- ReplaceBadChar(str,'?','_');
- ReplaceBadChar(str,'|','_');
- ReplaceBadChar(str,'>','_');
- ReplaceBadChar(str,'<','_');
- ReplaceBadChar(str,':','_');
- ReplaceBadChar(str,'*','_');
-
- return(str);
-};
-
-void AssignBitmapsFromDir(char *dir)
-{
- char curnameUP[512],curnameDN[512];
- char ChangedName[512];
-
- int i;
-
- if (dir==NULL){return;};
- if (strlen(dir)==0){return;};
- dir=SetEndSlash(dir);
-lockbut();
- for(i=0;i<nButtonsCount;i++) {
- memset(curnameUP,0,512);
- memset(curnameDN,0,512);
-
- memset(ChangedName,0,512);
- strcpy(ChangedName,Buttons[i].name);
- ReplaceAll(ChangedName);
-
- wsprintf(curnameUP,"%s%s_UP.bmp",dir,ChangedName);
- wsprintf(curnameDN,"%s%s_DN.bmp",dir,ChangedName);
-
- if (FileExists(curnameUP)){
- if (Buttons[i].UserDefinedbmUp!=NULL){free(Buttons[i].UserDefinedbmUp);};
- Buttons[i].UserDefinedbmUp=_strdup(curnameUP);
- };
-
- if (FileExists(curnameDN)){
- if (Buttons[i].UserDefinedbmDown!=NULL){free(Buttons[i].UserDefinedbmDown);};
- Buttons[i].UserDefinedbmDown=_strdup(curnameDN);
- };
-
-
- wsprintf(curnameUP,"%s%s_UP.ico",dir,ChangedName);
- wsprintf(curnameDN,"%s%s_DN.ico",dir,ChangedName);
-
- if (FileExists(curnameUP)){
- if (Buttons[i].UserDefinedbmUp!=NULL){free(Buttons[i].UserDefinedbmUp);};
- Buttons[i].UserDefinedbmUp=_strdup(curnameUP);
- };
-
- if (FileExists(curnameDN)){
- if (Buttons[i].UserDefinedbmDown!=NULL){free(Buttons[i].UserDefinedbmDown);};
- Buttons[i].UserDefinedbmDown=_strdup(curnameDN);
- };
- //applyuserbitmaps(i);
-
- };
-
-ulockbut();
-SetAllBitmaps();
-SaveAllButtonsOptions();
-};
-
-void ApplyNewDir(HWND hwnd)
-{
- char buf[512];
- char *buf2;
- GetDlgItemText(hwnd,IDC_IMGDIR,buf,512);
- buf2=DBGetString(0,TTB_OPTDIR,"ImgDir");
- if ((buf2==NULL)||strcmp(buf,buf2))
- {
- DBWriteContactSettingString(0,TTB_OPTDIR,"ImgDir",buf);
- AssignBitmapsFromDir(buf);
-
- };
-
-
-};
-
-
-//call this when options opened and buttons added/removed
-int OptionsPageRebuild()
-{
-
- if (OptionsOpened)
- {
- //MessageBoxA(0,"TreeRebuild","log",0);
- BuildTree(OptionshWnd);
- };
- return 0;
-};
-int SaveTree(HWND hwndDlg)
-{
- TVITEM tvi;
- int count;
- char idstr[100];
- char *name;
- int pos;
-
- tvi.hItem=TreeView_GetRoot(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE));
- tvi.cchTextMax=99;
- tvi.mask=TVIF_TEXT|TVIF_PARAM|TVIF_HANDLE;
- tvi.pszText=(LPSTR)&idstr;
- //CallService(MS_PROTO_ENUMPROTOCOLS,(WPARAM)&count,(LPARAM)&protos);
- //count--;
- count=0;
- lockbut();
-
- while(tvi.hItem!=NULL) {
- //itoa(count,buf,10);
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvi);
- name=((ButtonOptData *)tvi.lParam)->name;
- pos=((ButtonOptData *)tvi.lParam)->pos;
- if (pos>=0&&pos<nButtonsCount)
- {
- Buttons[pos].dwFlags&=~(TTBBF_VISIBLE);
- Buttons[pos].dwFlags|=(((ButtonOptData *)tvi.lParam)->show==TRUE )?TTBBF_VISIBLE:0;
- Buttons[pos].arrangedpos=count;
- // int DBSaveButtonSettings(int butpos)
- };
-
-
- tvi.hItem=TreeView_GetNextSibling(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),tvi.hItem);
-
- count++;
- }
- ulockbut();
- ttbOptionsChanged();
- return (TRUE);
-};
-
-int BuildTree(HWND hwndDlg)
-{
- struct OrderData *dat;
- TVINSERTSTRUCT tvis;
- ButtonOptData *PD;
- int i;
-
- PostMessage(GetDlgItem(hwndDlg,IDC_BMPUP), STM_SETIMAGE,IMAGE_BITMAP,0);
- PostMessage(GetDlgItem(hwndDlg,IDC_BMPDN), STM_SETIMAGE,IMAGE_BITMAP,0);
-
- // LockWindowUpdate(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE));
- dat=(struct OrderData*)GetWindowLong(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),GWLP_USERDATA);
- tvis.hParent=NULL;
- tvis.hInsertAfter=TVI_LAST;
- tvis.item.mask=TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
- TreeView_DeleteAllItems(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE));
- //CheckBUTORDER();
-
-
- if (nButtonsCount==0){return(FALSE);};
-
- for(i=0;i<nButtonsCount;i++) {
- PD=(ButtonOptData*)malloc(sizeof(ButtonOptData));
-
- PD->name=Buttons[arrangedbuts[i].oldpos].name;
- PD->show=Buttons[arrangedbuts[i].oldpos].dwFlags&TTBBF_VISIBLE?TRUE:FALSE;
- PD->pos=arrangedbuts[i].oldpos;
- tvis.item.lParam=(LPARAM)PD;
- tvis.item.pszText=Translate(PD->name);
- tvis.item.iImage=tvis.item.iSelectedImage=PD->show;
- TreeView_InsertItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvis);
-
- tvis.item.iImage=tvis.item.iSelectedImage=PD->show;
- };
- // LockWindowUpdate(NULL);
- return (TRUE);
-};
-
-void SetImagesForCurrent (HWND hwndDlg,int curselect)
-{
-
- {
-
- int t=IMAGE_BITMAP;
- char *curname;
-
- PostMessage(GetDlgItem(hwndDlg,IDC_BMPUP), STM_SETIMAGE,t,0);
- PostMessage(GetDlgItem(hwndDlg,IDC_BMPDN), STM_SETIMAGE,t,0);
-
- curname=Buttons[curselect].UserDefinedbmUp;
- if (curname!=NULL)
- {
- int st;
- if (strstr(curname,".ico")) {t=IMAGE_ICON;};
- st=WS_CHILDWINDOW|SS_NOTIFY|WS_VISIBLE;(t==IMAGE_ICON)?(st|=SS_ICON):(st|=SS_BITMAP);
- SetWindowLong(GetDlgItem(hwndDlg,IDC_BMPUP),GWL_STYLE,st);
- }else
- {
- SetWindowLong(GetDlgItem(hwndDlg,IDC_BMPUP),GWL_STYLE,WS_CHILDWINDOW|WS_VISIBLE|SS_NOTIFY|(Buttons[curselect].hbBitmapDown==NULL?SS_ICON:SS_BITMAP));
- t=IMAGE_ICON;
- }
-
- PostMessage(GetDlgItem(hwndDlg,IDC_BMPUP), STM_SETIMAGE,t,(LPARAM)(Buttons[curselect].hbBitmapUp==NULL?Buttons[curselect].hIconUp:Buttons[curselect].hbBitmapUp));
-
- curname=Buttons[curselect].UserDefinedbmDown;
- if (curname!=NULL)
- {
- int st;
- if (strstr(curname,".ico")) {t=IMAGE_ICON;};
- st=WS_CHILDWINDOW|SS_NOTIFY|WS_VISIBLE;(t==IMAGE_ICON)?(st|=SS_ICON):(st|=SS_BITMAP);
- SetWindowLong(GetDlgItem(hwndDlg,IDC_BMPDN),GWL_STYLE,st);
- }else
- {
- SetWindowLong(GetDlgItem(hwndDlg,IDC_BMPDN),GWL_STYLE,WS_CHILDWINDOW|WS_VISIBLE|SS_NOTIFY|(Buttons[curselect].hbBitmapDown==NULL?SS_ICON:SS_BITMAP));
- t=IMAGE_ICON;
- }
-
- PostMessage(GetDlgItem(hwndDlg,IDC_BMPDN), STM_SETIMAGE,t,(LPARAM)(Buttons[curselect].hbBitmapDown==NULL?Buttons[curselect].hIconDn:Buttons[curselect].hbBitmapDown ));
- }
-}
-
-static BOOL CALLBACK ButOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{ struct OrderData *dat;
-
- dat=(struct OrderData*)GetWindowLong(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),GWLP_USERDATA);
-
- switch (msg)
- {
- case WM_INITDIALOG: {
-
-
- TranslateDialogDefault(hwndDlg);
- dat=(struct OrderData*)malloc(sizeof(struct OrderData));
- SetWindowLong(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),GWLP_USERDATA,(LONG)dat);
- dat->dragging=0;
-
- //SetWindowLong(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY),GWL_STYLE,GetWindowLong(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY),GWL_STYLE)|TVS_NOHSCROLL);
- SetWindowLong(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),GWL_STYLE,GetWindowLong(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),GWL_STYLE)|TVS_NOHSCROLL);
-
- { HIMAGELIST himlCheckBoxes;
- himlCheckBoxes=ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),ILC_COLOR4|ILC_MASK,2,2);
- ImageList_AddIcon(himlCheckBoxes,LoadIcon(hInst,MAKEINTRESOURCE(IDI_NOTICK)));
- ImageList_AddIcon(himlCheckBoxes,LoadIcon(hInst,MAKEINTRESOURCE(IDI_TICK)));
- //TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_PROTOCOLVISIBILITY),himlCheckBoxes,TVSIL_NORMAL);
- //
- TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),himlCheckBoxes,TVSIL_NORMAL);
-
- }
- PostMessage(GetDlgItem(hwndDlg,IDC_BMPUP), STM_SETIMAGE,IMAGE_BITMAP,0);
- PostMessage(GetDlgItem(hwndDlg,IDC_BMPDN), STM_SETIMAGE,IMAGE_BITMAP,0);
- SetDlgItemInt(hwndDlg,IDC_BUTTHEIGHT,DBGetContactSettingByte(0,TTB_OPTDIR,"BUTTHEIGHT",16),FALSE);
- SetDlgItemInt(hwndDlg,IDC_BUTTWIDTH,DBGetContactSettingByte(0,TTB_OPTDIR,"BUTTWIDTH",20),FALSE);
- CheckDlgButton(hwndDlg,IDC_USEMIRANDABUTTON,DBGetContactSettingByte(0,TTB_OPTDIR,"UseMirandaButtonClass",UseMirandaButtonClassDefaultValue));
- CheckDlgButton(hwndDlg,IDC_USEFLAT,DBGetContactSettingByte(0,TTB_OPTDIR,"UseFlatButton",1));
-
- if (!ServiceExists(MS_SKIN2_ADDICON))
- {
- EnableWindow(GetDlgItem(hwndDlg,IDC_USEICOLIB),FALSE);
- }
- CheckDlgButton(hwndDlg,IDC_USEICOLIB,ServiceExists(MS_SKIN2_ADDICON)&&DBGetContactSettingByte(0,TTB_OPTDIR,"UseIcoLib",UseIcoLibDefaultValue));
-
-
-
- BuildTree(hwndDlg);
- OptionsOpened=TRUE;
- EnableWindow(GetDlgItem(hwndDlg,IDC_ENAME),FALSE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_EPATH),FALSE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_DELLBUTTON),FALSE);
-
- SetDlgItemText(hwndDlg,IDC_IMGDIR,DBGetString(0,TTB_OPTDIR,"ImgDir"));
- SendMessage(hwndDlg,WM_COMMAND,0,0);
- OptionshWnd=hwndDlg;
- return TRUE;
- }
- case WM_COMMAND:
- {
- //if (IDC_BMPUP)
- ShowWindow(GetDlgItem(hwndDlg,IDC_BMPUP),IsDlgButtonChecked(hwndDlg,IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg,IDC_BMPDN),IsDlgButtonChecked(hwndDlg,IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg,IDC_DEFAULT),IsDlgButtonChecked(hwndDlg,IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
-
- ShowWindow(GetDlgItem(hwndDlg,IDC_STATIC1),IsDlgButtonChecked(hwndDlg,IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg,IDC_STATIC2),IsDlgButtonChecked(hwndDlg,IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
- ShowWindow(GetDlgItem(hwndDlg,IDC_STATIC3),IsDlgButtonChecked(hwndDlg,IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
-
- EnableWindow(GetDlgItem(hwndDlg,IDC_USEFLAT),IsDlgButtonChecked(hwndDlg,IDC_USEMIRANDABUTTON));
-
- if (HIWORD(wParam)==EN_CHANGE )
- {
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
- };
- if ((HIWORD(wParam)==BN_CLICKED|| HIWORD(wParam)==BN_DBLCLK))
- {
- int ctrlid=LOWORD(wParam);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
-
- if (ctrlid==IDC_OPENIMGDIR)
- {
- char buf[512];
- PCIDLIST_ABSOLUTE res;
-
- BROWSEINFO bi;
- memset(&bi,0,sizeof(bi));
- bi.hwndOwner=hwndDlg;
- bi.pszDisplayName=buf;
- bi.lpszTitle=Translate("Select Directory");
- bi.ulFlags=BIF_RETURNONLYFSDIRS;
- res=SHBrowseForFolder(&bi);
- if(res!=NULL)
- {
- if (SHGetPathFromIDList(res,buf)==TRUE)
- {
-
- SetDlgItemText(hwndDlg,IDC_IMGDIR,(LPCSTR)&buf);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- };
-
- };
-
- break;
- };
- if (ctrlid==IDC_LBUTTONSET)
- {
- int curselect;
- TVITEM tvi;
- tvi.hItem=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE));
- if (tvi.hItem==NULL){break;};
-
- tvi.mask=TVIF_PARAM;
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvi);
-
- curselect=((ButtonOptData *)tvi.lParam)->pos;
- if (Buttons[curselect].dwFlags&TTBBF_ISLBUTTON)
- {
- LBUTOPT lbo;
- char buf[256];
- memset(&lbo,0,sizeof(lbo));
-
-
- GetDlgItemText(hwndDlg,IDC_ENAME,buf,255);
- lbo.name=_strdup(buf);
-
- GetDlgItemText(hwndDlg,IDC_EPATH,buf,255);
- lbo.lpath=_strdup(buf);
-
- CallService(TTB_MODIFYLBUTTON,Buttons[curselect].lParamDown,(LPARAM)&lbo);
- free(lbo.name);
- free(lbo.lpath);
- };
-
- break;
- };
- if (ctrlid==IDC_ADDLBUTTON)
- {
- if (CallService(TTB_ADDLBUTTON,0,0)==0)
- {
- // BuildTree(hwndDlg);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
-
- };
- break;
- };
-
- if (ctrlid==IDC_DELLBUTTON)
- {
- int curselect;
- TVITEM tvi;
- tvi.hItem=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE));
- if (tvi.hItem==NULL){break;};
- tvi.mask=TVIF_PARAM;
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvi);
-
- curselect=((ButtonOptData *)tvi.lParam)->pos;
- if (Buttons[curselect].dwFlags&TTBBF_ISLBUTTON)
- {
- CallService(TTB_REMOVELBUTTON,Buttons[curselect].lParamDown,0);
- EnableWindow(GetDlgItem(hwndDlg,IDC_ENAME),FALSE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_EPATH),FALSE);
- BuildTree(hwndDlg);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
-
- };
-
-
- };
- if (ctrlid==IDC_ADDSEP)
- {
- if (CallService(TTB_ADDSEPARATOR,0,0)==0)
- {
- // BuildTree(hwndDlg);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- };
- break;
- };
- if (ctrlid==IDC_REMOVESEP)
- {
- int curselect;
- TVITEM tvi;
- memset(&tvi,0,sizeof(tvi));
- tvi.hItem=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE));
- if (tvi.hItem==NULL){break;};
-
- //MessageBoxA(0,"GetSelItem","log",0);
- tvi.mask=TVIF_PARAM;
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvi);
-
- if (tvi.lParam==0){break;};
- //MessageBoxA(0,"Getting curselect","log",0);
- //!!! in win98 cause crash ?
- if (IsBadCodePtr(tvi.lParam))
- {
- MessageBoxA(0,"Bad Code Ptr: tvi.lParam","log",0);
- break;
- };
- curselect=((ButtonOptData *)tvi.lParam)->pos;
-
- if ((curselect>=0)&&(curselect<nButtonsCount))
- {
- if (Buttons[curselect].dwFlags&TTBBF_ISSEPARATOR)
- {
- //wsprintf(buf,"curselect: %d/%d, lparamdown: %d",curselect,nButtonsCount,Buttons[curselect].lParamDown);
- //MessageBoxA(0,buf,"log",0);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- //MessageBoxA(0,"CallService(TTB_REMOVESEPARATOR","log",0);
- CallService(TTB_REMOVESEPARATOR,Buttons[curselect].lParamDown,0);
-
-
- //MessageBoxA(0,"Remove OK","log",0);
- };
- }
-
- break;
- };
- if (ctrlid==IDC_DEFAULT)
- {
- int curselect;
- TVITEM tvi;
-
- tvi.hItem=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE));
- if (tvi.hItem==NULL){break;};
-
- tvi.mask=TVIF_PARAM;
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvi);
-
- curselect=((ButtonOptData *)tvi.lParam)->pos;
- lockbut();
-
- if (Buttons[curselect].UserDefinedbmUp!=NULL){free(Buttons[curselect].UserDefinedbmUp);};
- if (Buttons[curselect].UserDefinedbmDown!=NULL){free(Buttons[curselect].UserDefinedbmDown);};
- Buttons[curselect].UserDefinedbmUp=NULL;
- Buttons[curselect].UserDefinedbmDown=NULL;
- applyuserbitmaps(curselect);
- SetImagesForCurrent(hwndDlg,curselect);
- //PostMessage(GetDlgItem(hwndDlg,IDC_BMPUP), STM_SETIMAGE,IMAGE_BITMAP,Buttons[curselect].hbBitmapUp);
- //PostMessage(GetDlgItem(hwndDlg,IDC_BMPDN), STM_SETIMAGE,IMAGE_BITMAP,Buttons[curselect].hbBitmapDown);
-
- ulockbut();
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- };
- };
-
- if ((HIWORD(wParam)==STN_CLICKED|| HIWORD(wParam)==STN_DBLCLK))
- {
- int ctrlid=LOWORD(wParam);
- if (ctrlid==IDC_BMPUP||ctrlid==IDC_BMPDN)
- {
-
-
- char filename[MAX_PATH];
- OPENFILENAME ofn={0};
- char filter[512],*pfilter;
- int curselect;
- TVITEM tvi;
-
- tvi.hItem=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE));
- if (tvi.hItem==NULL){break;};
- tvi.mask=TVIF_PARAM;
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvi);
-
- if (tvi.lParam==0){break;};
- curselect=((ButtonOptData *)tvi.lParam)->pos;
-
-
- filename[0]=0;
- memset(&ofn,0,sizeof(ofn));
- ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.hwndOwner = hwndDlg;
- ofn.hInstance = NULL;
- strcpy(filter,Translate("Bitmap/Icon files"));
- //sprintf(filter,"Bitmap/Icon files \0 *.bmp;*.ico \0\0" );
-
- strcat(filter," (*.bmp;*.ico)");
-
- pfilter=filter+strlen(filter)+1;
- strcpy(pfilter,"*.bmp;*.ico");
- pfilter=pfilter+strlen(pfilter)+1;
-
- strcpy(pfilter,Translate("All Files"));
- strcat(pfilter,"(*)");
- pfilter=pfilter+strlen(pfilter)+1;
- strcpy(pfilter,"*");
-
-
- pfilter=pfilter+strlen(pfilter)+1;
- *pfilter='\0';
-
- ofn.lpstrFilter = filter;
- ofn.lpstrFile = filename;
- ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
- ofn.nMaxFile = sizeof(filename);
- ofn.nMaxFileTitle = MAX_PATH;
- ofn.lpstrDefExt = "bmp";
- ofn.lpstrTitle=(ctrlid==IDC_BMPUP)?Translate("Select Up Bitmap"):Translate("Select Down Bitmap");
- if(GetOpenFileName(&ofn)) {
- lockbut();
- if (ctrlid==IDC_BMPUP){
- if (Buttons[curselect].UserDefinedbmUp!=NULL){free(Buttons[curselect].UserDefinedbmUp);};
- Buttons[curselect].UserDefinedbmUp=_strdup(ofn.lpstrFile);
- };
- if (ctrlid==IDC_BMPDN){
- if (Buttons[curselect].UserDefinedbmDown!=NULL){free(Buttons[curselect].UserDefinedbmDown);};
- Buttons[curselect].UserDefinedbmDown=_strdup(ofn.lpstrFile);
- };
- applyuserbitmaps(curselect);
- SetImagesForCurrent(hwndDlg,curselect);
-
- ulockbut();
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- };
- };
- };
- break;
- }
-
-
-
-
-
-
-
-
-
-
- case WM_NOTIFY:
- switch(((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code)
- {
- case PSN_APPLY:
- {
-
- DBWriteContactSettingByte(0,TTB_OPTDIR,"BUTTHEIGHT",GetDlgItemInt(hwndDlg,IDC_BUTTHEIGHT,FALSE,FALSE));
- DBWriteContactSettingByte(0,TTB_OPTDIR,"BUTTWIDTH",GetDlgItemInt(hwndDlg,IDC_BUTTWIDTH,FALSE,FALSE));
- DBWriteContactSettingByte(0,TTB_OPTDIR,"UseMirandaButtonClass",(BYTE)IsDlgButtonChecked(hwndDlg,IDC_USEMIRANDABUTTON));
- DBWriteContactSettingByte(0,TTB_OPTDIR,"UseFlatButton",(BYTE)IsDlgButtonChecked(hwndDlg,IDC_USEFLAT));
-
- DBWriteContactSettingByte(0,TTB_OPTDIR,"UseIcoLib",(BYTE)IsDlgButtonChecked(hwndDlg,IDC_USEICOLIB));
-
-
- SaveTree(hwndDlg);
- ApplyNewDir(hwndDlg);
- RecreateWindows();
- ArrangeButtons();
-
- }
- }
- break;
- case IDC_BUTTONORDERTREE:
- switch (((LPNMHDR)lParam)->code) {
- case TVN_BEGINDRAG:
- SetCapture(hwndDlg);
- dat->dragging=1;
- dat->hDragItem=((LPNMTREEVIEW)lParam)->itemNew.hItem;
- TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),dat->hDragItem);
- //ShowWindow(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREEWARNING),SW_SHOW);
- break;
-
- case NM_CLICK:
- {
- TVHITTESTINFO hti;
- hti.pt.x=(short)LOWORD(GetMessagePos());
- hti.pt.y=(short)HIWORD(GetMessagePos());
- ScreenToClient(((LPNMHDR)lParam)->hwndFrom,&hti.pt);
- if(TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom,&hti))
- {
- if(hti.flags&TVHT_ONITEMICON) {
- TVITEM tvi;
- tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
- tvi.hItem=hti.hItem;
- TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom,&tvi);
- tvi.iImage=tvi.iSelectedImage=!tvi.iImage;
- ((ButtonOptData *)tvi.lParam)->show=tvi.iImage;
- TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom,&tvi);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
-
- //all changes take effect in runtime
- //ShowWindow(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREEWARNING),SW_SHOW);
- }
-
-
- };
- }
- break;
- case TVN_SELCHANGED:
-
- {
-
- if(1/*TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom,&hti)*/)
- if (1/*hti.flags&TVHT_ONITEMLABEL*/)
- {
- TVITEM tvi;
- HTREEITEM hti;
-
- hti=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE));
- if (hti==NULL){break;};
- tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
- tvi.hItem=hti;
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvi);
-
-
- lockbut();
- EnableWindow(GetDlgItem(hwndDlg,IDC_BMPUP),FALSE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_BMPDN),FALSE);
-
- SetImagesForCurrent(hwndDlg,((ButtonOptData *)tvi.lParam)->pos);
- //PostMessage(GetDlgItem(hwndDlg,IDC_BMPUP), STM_SETIMAGE,IMAGE_BITMAP,Buttons[((ButtonOptData *)tvi.lParam)->pos].hbBitmapUp);
- //PostMessage(GetDlgItem(hwndDlg,IDC_BMPDN), STM_SETIMAGE,IMAGE_BITMAP,Buttons[((ButtonOptData *)tvi.lParam)->pos].hbBitmapDown);
-
- EnableWindow(GetDlgItem(hwndDlg,IDC_REMOVESEP),FALSE);
- if (Buttons[((ButtonOptData *)tvi.lParam)->pos].dwFlags&TTBBF_ISSEPARATOR)
- {
-
- EnableWindow(GetDlgItem(hwndDlg,IDC_REMOVESEP),TRUE);
- }else
- {
- EnableWindow(GetDlgItem(hwndDlg,IDC_BMPUP),TRUE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_BMPDN),TRUE);
-
- };
- EnableWindow(GetDlgItem(hwndDlg,IDC_ENAME),FALSE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_EPATH),FALSE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_DELLBUTTON),FALSE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_LBUTTONSET),FALSE);
- {SetDlgItemText(hwndDlg,IDC_ENAME,"");}
- {SetDlgItemText(hwndDlg,IDC_EPATH,"");}
-
-
- if (Buttons[((ButtonOptData *)tvi.lParam)->pos].dwFlags&TTBBF_ISLBUTTON)
- {
- LBUTOPT lbo;
-
- memset(&lbo,0,sizeof(lbo));
- CallService(TTB_GETLBUTTON,Buttons[((ButtonOptData *)tvi.lParam)->pos].lParamDown,(LPARAM)&lbo);
- if (lbo.hframe!=0)
- {
- EnableWindow(GetDlgItem(hwndDlg,IDC_ENAME),TRUE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_EPATH),TRUE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_DELLBUTTON),TRUE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_LBUTTONSET),TRUE);
-
- if (lbo.name!=NULL){SetDlgItemText(hwndDlg,IDC_ENAME,lbo.name);};
- if (lbo.lpath!=NULL){SetDlgItemText(hwndDlg,IDC_EPATH,lbo.lpath);};
- };
-
-
- };
-
- ulockbut();
- };
-
-
-
- };
-
-
-
- }
- break;
- }
- break;
- case WM_MOUSEMOVE:
- if(!dat->dragging) break;
- { TVHITTESTINFO hti;
- hti.pt.x=(short)LOWORD(lParam);
- hti.pt.y=(short)HIWORD(lParam);
- ClientToScreen(hwndDlg,&hti.pt);
- ScreenToClient(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&hti.pt);
- TreeView_HitTest(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&hti);
- if(hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
- hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE))/2;
- TreeView_HitTest(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&hti);
- TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),hti.hItem,1);
- }
- else {
- if(hti.flags&TVHT_ABOVE) SendDlgItemMessage(hwndDlg,IDC_BUTTONORDERTREE,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0);
- if(hti.flags&TVHT_BELOW) SendDlgItemMessage(hwndDlg,IDC_BUTTONORDERTREE,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0);
- TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),NULL,0);
- }
-
- }
- break;
- case WM_DESTROY:
- {
- OptionsOpened=FALSE;
- return(0);
- };
-
- case WM_LBUTTONUP:
- if(!dat->dragging) break;
- TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),NULL,0);
- dat->dragging=0;
- ReleaseCapture();
- { TVHITTESTINFO hti;
- TVITEM tvi;
- hti.pt.x=(short)LOWORD(lParam);
- hti.pt.y=(short)HIWORD(lParam);
- ClientToScreen(hwndDlg,&hti.pt);
- ScreenToClient(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&hti.pt);
- hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE))/2;
- TreeView_HitTest(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&hti);
- if(dat->hDragItem==hti.hItem) break;
- tvi.mask=TVIF_HANDLE|TVIF_PARAM;
- tvi.hItem=hti.hItem;
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvi);
- if(hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
- TVINSERTSTRUCT tvis;
- char name[128];
- tvis.item.mask=TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
- tvis.item.stateMask=0xFFFFFFFF;
- tvis.item.pszText=name;
- tvis.item.cchTextMax=sizeof(name);
- tvis.item.hItem=dat->hDragItem;
- //
- tvis.item.iImage=tvis.item.iSelectedImage=((ButtonOptData *)tvi.lParam)->show;
-
- TreeView_GetItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvis.item);
-
-
- TreeView_DeleteItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),dat->hDragItem);
- tvis.hParent=NULL;
- tvis.hInsertAfter=hti.hItem;
- TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),TreeView_InsertItem(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREE),&tvis));
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- SaveTree(hwndDlg);
- }
- }
- break;
- }
- return FALSE;
-}
-
-
-
-int TTBOptInit(WPARAM wParam,LPARAM lParam)
-{
- OPTIONSDIALOGPAGE odp;
-
- ZeroMemory(&odp,sizeof(odp));
- odp.cbSize=sizeof(odp);
- odp.position=0;
- odp.hInstance=hInst;
- odp.pszGroup=Translate("TopToolBar");
-
- if (ServiceExists(MS_BACKGROUNDCONFIG_REGISTER))
- {
-
- }else
- {
- odp.pszTemplate=MAKEINTRESOURCE(IDD_OPT_TTBBKG);
- odp.pszTitle=Translate("TTBBackground");
- odp.pfnDlgProc=DlgProcTTBBkgOpts;
- odp.flags=ODPF_BOLDGROUPS;
- CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&odp);
- };
-
- ZeroMemory(&odp,sizeof(odp));
- odp.cbSize=sizeof(odp);
- odp.position=-1000000000;
- odp.hInstance=hInst;//GetModuleHandle(NULL);
- odp.pszTemplate=MAKEINTRESOURCE(IDD_OPT_BUTORDER);
- odp.pszGroup=Translate("TopToolBar");
- odp.pszTitle=Translate("Buttons");
- odp.pfnDlgProc=ButOrderOpts;
- odp.flags=ODPF_BOLDGROUPS|ODPF_EXPERTONLY;
- CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&odp);
-
- return 0;
-}
-
-static BOOL CALLBACK DlgProcTTBBkgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg)
- {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- CheckDlgButton(hwndDlg,IDC_BITMAP,DBGetContactSettingByte(NULL,TTB_OPTDIR,"UseBitmap",TTBDEFAULT_USEBITMAP)?BST_CHECKED:BST_UNCHECKED);
- SendMessage(hwndDlg,WM_USER+10,0,0);
- SendDlgItemMessage(hwndDlg,IDC_BKGCOLOUR,CPM_SETDEFAULTCOLOUR,0,TTBDEFAULT_BKCOLOUR);
- SendDlgItemMessage(hwndDlg,IDC_BKGCOLOUR,CPM_SETCOLOUR,0,DBGetContactSettingDword(NULL,TTB_OPTDIR,"BkColour",TTBDEFAULT_BKCOLOUR));
- SendDlgItemMessage(hwndDlg,IDC_SELCOLOUR,CPM_SETDEFAULTCOLOUR,0,TTBDEFAULT_SELBKCOLOUR);
- SendDlgItemMessage(hwndDlg,IDC_SELCOLOUR,CPM_SETCOLOUR,0,DBGetContactSettingDword(NULL,TTB_OPTDIR,"SelBkColour",TTBDEFAULT_SELBKCOLOUR));
- { DBVARIANT dbv;
- if(!DBGetContactSetting(NULL,TTB_OPTDIR,"BkBitmap",&dbv)) {
- SetDlgItemText(hwndDlg,IDC_FILENAME,dbv.pszVal);
- DBFreeVariant(&dbv);
-
- }
- }
- { WORD bmpUse=DBGetContactSettingWord(NULL,TTB_OPTDIR,"BkBmpUse",TTBDEFAULT_BKBMPUSE);
- CheckDlgButton(hwndDlg,IDC_STRETCHH,bmpUse&CLB_STRETCHH?BST_CHECKED:BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_STRETCHV,bmpUse&CLB_STRETCHV?BST_CHECKED:BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_TILEH,bmpUse&CLBF_TILEH?BST_CHECKED:BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_TILEV,bmpUse&CLBF_TILEV?BST_CHECKED:BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_SCROLL,bmpUse&CLBF_SCROLL?BST_CHECKED:BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_PROPORTIONAL,bmpUse&CLBF_PROPORTIONAL?BST_CHECKED:BST_UNCHECKED);
- }
- { HRESULT (STDAPICALLTYPE *MySHAutoComplete)(HWND,DWORD);
- MySHAutoComplete=(HRESULT (STDAPICALLTYPE*)(HWND,DWORD))GetProcAddress(GetModuleHandle("shlwapi"),"SHAutoComplete");
- if(MySHAutoComplete) MySHAutoComplete(GetDlgItem(hwndDlg,IDC_FILENAME),1);
- }
- return TRUE;
- case WM_USER+10:
- EnableWindow(GetDlgItem(hwndDlg,IDC_FILENAME),IsDlgButtonChecked(hwndDlg,IDC_BITMAP));
- EnableWindow(GetDlgItem(hwndDlg,IDC_BROWSE),IsDlgButtonChecked(hwndDlg,IDC_BITMAP));
- EnableWindow(GetDlgItem(hwndDlg,IDC_STRETCHH),IsDlgButtonChecked(hwndDlg,IDC_BITMAP));
- EnableWindow(GetDlgItem(hwndDlg,IDC_STRETCHV),IsDlgButtonChecked(hwndDlg,IDC_BITMAP));
- EnableWindow(GetDlgItem(hwndDlg,IDC_TILEH),IsDlgButtonChecked(hwndDlg,IDC_BITMAP));
- EnableWindow(GetDlgItem(hwndDlg,IDC_TILEV),IsDlgButtonChecked(hwndDlg,IDC_BITMAP));
- EnableWindow(GetDlgItem(hwndDlg,IDC_SCROLL),IsDlgButtonChecked(hwndDlg,IDC_BITMAP));
- EnableWindow(GetDlgItem(hwndDlg,IDC_PROPORTIONAL),IsDlgButtonChecked(hwndDlg,IDC_BITMAP));
- break;
- case WM_COMMAND:
- if(LOWORD(wParam)==IDC_BROWSE) {
- char str[MAX_PATH];
- OPENFILENAME ofn={0};
- char filter[512];
-
- GetDlgItemText(hwndDlg,IDC_FILENAME,str,sizeof(str));
- ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.hwndOwner = hwndDlg;
- ofn.hInstance = NULL;
- CallService(MS_UTILS_GETBITMAPFILTERSTRINGS,sizeof(filter),(LPARAM)filter);
- ofn.lpstrFilter = filter;
- ofn.lpstrFile = str;
- ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
- ofn.nMaxFile = sizeof(str);
- ofn.nMaxFileTitle = MAX_PATH;
- ofn.lpstrDefExt = "bmp";
- if(!GetOpenFileName(&ofn)) break;
- SetDlgItemText(hwndDlg,IDC_FILENAME,str);
- }
- else if(LOWORD(wParam)==IDC_FILENAME && HIWORD(wParam)!=EN_CHANGE) break;
- if(LOWORD(wParam)==IDC_BITMAP) SendMessage(hwndDlg,WM_USER+10,0,0);
- if(LOWORD(wParam)==IDC_FILENAME && (HIWORD(wParam)!=EN_CHANGE || (HWND)lParam!=GetFocus())) return 0;
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
- case WM_NOTIFY:
- switch(((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code)
- {
- case PSN_APPLY:
- DBWriteContactSettingByte(NULL,TTB_OPTDIR,"UseBitmap",(BYTE)IsDlgButtonChecked(hwndDlg,IDC_BITMAP));
- { COLORREF col;
- col=SendDlgItemMessage(hwndDlg,IDC_BKGCOLOUR,CPM_GETCOLOUR,0,0);
- if(col==TTBDEFAULT_BKCOLOUR) DBDeleteContactSetting(NULL,TTB_OPTDIR,"BkColour");
- else DBWriteContactSettingDword(NULL,TTB_OPTDIR,"BkColour",col);
- col=SendDlgItemMessage(hwndDlg,IDC_SELCOLOUR,CPM_GETCOLOUR,0,0);
- if(col==TTBDEFAULT_SELBKCOLOUR) DBDeleteContactSetting(NULL,TTB_OPTDIR,"SelBkColour");
- else DBWriteContactSettingDword(NULL,TTB_OPTDIR,"SelBkColour",col);
- }
- { char str[MAX_PATH];
- GetDlgItemText(hwndDlg,IDC_FILENAME,str,sizeof(str));
- DBWriteContactSettingString(NULL,TTB_OPTDIR,"BkBitmap",str);
- }
- { WORD flags=0;
- if(IsDlgButtonChecked(hwndDlg,IDC_STRETCHH)) flags|=CLB_STRETCHH;
- if(IsDlgButtonChecked(hwndDlg,IDC_STRETCHV)) flags|=CLB_STRETCHV;
- if(IsDlgButtonChecked(hwndDlg,IDC_TILEH)) flags|=CLBF_TILEH;
- if(IsDlgButtonChecked(hwndDlg,IDC_TILEV)) flags|=CLBF_TILEV;
- if(IsDlgButtonChecked(hwndDlg,IDC_SCROLL)) flags|=CLBF_SCROLL;
- if(IsDlgButtonChecked(hwndDlg,IDC_PROPORTIONAL)) flags|=CLBF_PROPORTIONAL;
- DBWriteContactSettingWord(NULL,TTB_OPTDIR,"BkBmpUse",flags);
- }
-
- ttbOptionsChanged();
- return TRUE;
- }
- break;
- }
- break;
- }
- return FALSE;
-}
diff --git a/plugins/TopToolBar/ttbopt.cpp b/plugins/TopToolBar/ttbopt.cpp
new file mode 100644
index 0000000000..f4bddc8f6b
--- /dev/null
+++ b/plugins/TopToolBar/ttbopt.cpp
@@ -0,0 +1,822 @@
+#include "common.h"
+#include <shlobj.h>
+#pragma hdrstop
+
+static BOOL CALLBACK DlgProcTTBBkgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
+extern int ttbOptionsChanged();
+extern HINSTANCE hInst;
+
+extern TopButtonInt Buttons[MAX_BUTTONS];
+extern int nButtonsCount;
+
+extern SortData arrangedbuts[MAX_BUTTONS];
+
+bool OptionsOpened = false;
+HWND OptionshWnd = 0;
+
+struct OrderData
+{
+ int dragging;
+ HTREEITEM hDragItem;
+};
+
+char *SetEndSlash(char *str)
+{
+ if (str == NULL || *str == 0)
+ return NULL;
+
+ char *outs = str;
+ if (str[strlen(str)-1] != '\\') {
+ outs = (char*)malloc(strlen(str)+3);
+ memset(outs, 0, strlen(str)+3);
+ strcat(outs, str);
+ outs[strlen(str)] = '\\';
+ }
+ return outs;
+}
+
+bool FileExists(char *fname)
+{
+ WIN32_FIND_DATA wfd = { 0 };
+ HANDLE h = FindFirstFile(fname, &wfd);
+ if (h == INVALID_HANDLE_VALUE)
+ return FALSE;
+
+ FindClose(h);
+ return TRUE;
+}
+
+char *ReplaceBadChar(char *str, char bad, char toreplace)
+{
+ for (int i = 0; i < strlen(str); i++)
+ if (str[i] == bad)
+ str[i] = toreplace;
+
+ return str;
+}
+
+char *ReplaceAll(char *str)
+{
+ ReplaceBadChar(str, '\\', '_');
+ ReplaceBadChar(str, '/', '_');
+ ReplaceBadChar(str, '"', '_');
+ ReplaceBadChar(str, '?', '_');
+ ReplaceBadChar(str, '|', '_');
+ ReplaceBadChar(str, '>', '_');
+ ReplaceBadChar(str, '<', '_');
+ ReplaceBadChar(str, ':', '_');
+ ReplaceBadChar(str, '*', '_');
+ return str;
+}
+
+void AssignBitmapsFromDir(char *dir)
+{
+ if (dir == NULL || *dir == 0 )
+ return;
+
+ dir = SetEndSlash(dir);
+ lockbut();
+ for (int i = 0; i < nButtonsCount; i++) {
+ char curnameUP[512], curnameDN[512], ChangedName[512];
+ strcpy(ChangedName, Buttons[i].name);
+ ReplaceAll(ChangedName);
+
+ wsprintf(curnameUP, "%s%s_UP.bmp", dir, ChangedName);
+ wsprintf(curnameDN, "%s%s_DN.bmp", dir, ChangedName);
+
+ if ( FileExists(curnameUP)) {
+ if (Buttons[i].UserDefinedbmUp != NULL){free(Buttons[i].UserDefinedbmUp);}
+ Buttons[i].UserDefinedbmUp = _strdup(curnameUP);
+ }
+
+ if ( FileExists(curnameDN)) {
+ if (Buttons[i].UserDefinedbmDown != NULL){free(Buttons[i].UserDefinedbmDown);}
+ Buttons[i].UserDefinedbmDown = _strdup(curnameDN);
+ }
+
+ wsprintf(curnameUP, "%s%s_UP.ico", dir, ChangedName);
+ wsprintf(curnameDN, "%s%s_DN.ico", dir, ChangedName);
+
+ if ( FileExists(curnameUP)) {
+ if (Buttons[i].UserDefinedbmUp != NULL){free(Buttons[i].UserDefinedbmUp);}
+ Buttons[i].UserDefinedbmUp = _strdup(curnameUP);
+ }
+
+ if ( FileExists(curnameDN)) {
+ if (Buttons[i].UserDefinedbmDown != NULL){free(Buttons[i].UserDefinedbmDown);}
+ Buttons[i].UserDefinedbmDown = _strdup(curnameDN);
+ }
+ }
+
+ ulockbut();
+ SetAllBitmaps();
+ SaveAllButtonsOptions();
+}
+
+void ApplyNewDir(HWND hwnd)
+{
+ char buf[512];
+ char *buf2;
+ GetDlgItemText(hwnd, IDC_IMGDIR, buf, 512);
+ buf2 = DBGetString(0, TTB_OPTDIR, "ImgDir");
+ if ( buf2 == NULL || strcmp(buf, buf2)) {
+ DBWriteContactSettingString(0, TTB_OPTDIR, "ImgDir", buf);
+ AssignBitmapsFromDir(buf);
+ }
+}
+
+int BuildTree(HWND hwndDlg)
+{
+ PostMessage(GetDlgItem(hwndDlg, IDC_BMPUP), STM_SETIMAGE, IMAGE_BITMAP, 0);
+ PostMessage(GetDlgItem(hwndDlg, IDC_BMPDN), STM_SETIMAGE, IMAGE_BITMAP, 0);
+
+ OrderData *dat = (struct OrderData*)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), GWLP_USERDATA);
+
+ TVINSERTSTRUCT tvis;
+ tvis.hParent = NULL;
+ tvis.hInsertAfter = TVI_LAST;
+ tvis.item.mask = TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+ TreeView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE));
+
+ if (nButtonsCount == 0)
+ return FALSE;
+
+ for (int i = 0; i < nButtonsCount; i++) {
+ ButtonOptData *PD = (ButtonOptData*)malloc(sizeof(ButtonOptData));
+
+ PD->name = Buttons[arrangedbuts[i].oldpos].name;
+ PD->show = Buttons[arrangedbuts[i].oldpos].dwFlags&TTBBF_VISIBLE?TRUE:FALSE;
+ PD->pos = arrangedbuts[i].oldpos;
+ tvis.item.lParam = (LPARAM)PD;
+ tvis.item.pszText = Translate(PD->name);
+ tvis.item.iImage = tvis.item.iSelectedImage = PD->show;
+ TreeView_InsertItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvis);
+
+ tvis.item.iImage = tvis.item.iSelectedImage = PD->show;
+ }
+
+ return (TRUE);
+}
+
+//call this when options opened and buttons added/removed
+int OptionsPageRebuild()
+{
+ if (OptionsOpened)
+ BuildTree(OptionshWnd);
+
+ return 0;
+}
+
+int SaveTree(HWND hwndDlg)
+{
+ TCHAR idstr[100];
+ TVITEM tvi;
+ tvi.hItem = TreeView_GetRoot(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE));
+ tvi.cchTextMax = 99;
+ tvi.mask = TVIF_TEXT|TVIF_PARAM|TVIF_HANDLE;
+ tvi.pszText = idstr;
+
+ int count = 0;
+ lockbut();
+
+ while(tvi.hItem != NULL) {
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvi);
+ char* name = ((ButtonOptData *)tvi.lParam)->name;
+ int pos = ((ButtonOptData *)tvi.lParam)->pos;
+ if (pos >= 0 && pos < nButtonsCount) {
+ Buttons[pos].dwFlags &= ~(TTBBF_VISIBLE);
+ Buttons[pos].dwFlags |= (((ButtonOptData *)tvi.lParam)->show == TRUE ) ? TTBBF_VISIBLE : 0;
+ Buttons[pos].arrangedpos = count;
+ }
+
+ tvi.hItem = TreeView_GetNextSibling(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), tvi.hItem);
+ count++;
+ }
+
+ ulockbut();
+ ttbOptionsChanged();
+ return (TRUE);
+}
+
+void SetImagesForCurrent (HWND hwndDlg, int curselect)
+{
+ int t = IMAGE_BITMAP;
+
+ PostMessage(GetDlgItem(hwndDlg, IDC_BMPUP), STM_SETIMAGE, t, 0);
+ PostMessage(GetDlgItem(hwndDlg, IDC_BMPDN), STM_SETIMAGE, t, 0);
+
+ char *curname = Buttons[curselect].UserDefinedbmUp;
+ if (curname != NULL) {
+ if (strstr(curname, ".ico"))
+ t = IMAGE_ICON;
+ int st = WS_CHILDWINDOW | SS_NOTIFY | WS_VISIBLE;
+ st |= (t == IMAGE_ICON) ? SS_ICON : SS_BITMAP;
+ SetWindowLong(GetDlgItem(hwndDlg, IDC_BMPUP), GWL_STYLE, st);
+ }
+ else {
+ SetWindowLong(GetDlgItem(hwndDlg, IDC_BMPUP), GWL_STYLE, WS_CHILDWINDOW|WS_VISIBLE|SS_NOTIFY|(Buttons[curselect].hbBitmapDown == NULL?SS_ICON:SS_BITMAP));
+ t = IMAGE_ICON;
+ }
+
+ PostMessage(GetDlgItem(hwndDlg, IDC_BMPUP), STM_SETIMAGE, t, (Buttons[curselect].hbBitmapUp == NULL) ? (LPARAM)Buttons[curselect].hIconUp : (LPARAM)Buttons[curselect].hbBitmapUp);
+
+ curname = Buttons[curselect].UserDefinedbmDown;
+ if (curname != NULL) {
+ if (strstr(curname, ".ico"))
+ t = IMAGE_ICON;
+ int st = WS_CHILDWINDOW | SS_NOTIFY | WS_VISIBLE;
+ st |= (t == IMAGE_ICON) ? SS_ICON : SS_BITMAP;
+ SetWindowLong(GetDlgItem(hwndDlg, IDC_BMPDN), GWL_STYLE, st);
+ }
+ else {
+ SetWindowLong(GetDlgItem(hwndDlg, IDC_BMPDN), GWL_STYLE, WS_CHILDWINDOW|WS_VISIBLE|SS_NOTIFY|(Buttons[curselect].hbBitmapDown == NULL?SS_ICON:SS_BITMAP));
+ t = IMAGE_ICON;
+ }
+
+ PostMessage(GetDlgItem(hwndDlg, IDC_BMPDN), STM_SETIMAGE, t, (Buttons[curselect].hbBitmapDown == NULL) ? (LPARAM)Buttons[curselect].hIconDn : (LPARAM)Buttons[curselect].hbBitmapDown);
+}
+
+static BOOL CALLBACK ButOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ struct OrderData *dat = (struct OrderData*)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), GWLP_USERDATA);
+
+ switch (msg) {
+ case WM_INITDIALOG:
+ {
+ TranslateDialogDefault(hwndDlg);
+ dat = (struct OrderData*)malloc(sizeof(struct OrderData));
+ SetWindowLong(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), GWLP_USERDATA, (LONG)dat);
+ dat->dragging = 0;
+
+ SetWindowLong(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), GWL_STYLE)|TVS_NOHSCROLL);
+ {
+ HIMAGELIST himlCheckBoxes;
+ himlCheckBoxes = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR4|ILC_MASK, 2, 2);
+ ImageList_AddIcon(himlCheckBoxes, LoadIcon(hInst, MAKEINTRESOURCE(IDI_NOTICK)));
+ ImageList_AddIcon(himlCheckBoxes, LoadIcon(hInst, MAKEINTRESOURCE(IDI_TICK)));
+ TreeView_SetImageList(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), himlCheckBoxes, TVSIL_NORMAL);
+ }
+
+ PostMessage(GetDlgItem(hwndDlg, IDC_BMPUP), STM_SETIMAGE, IMAGE_BITMAP, 0);
+ PostMessage(GetDlgItem(hwndDlg, IDC_BMPDN), STM_SETIMAGE, IMAGE_BITMAP, 0);
+ SetDlgItemInt(hwndDlg, IDC_BUTTHEIGHT, DBGetContactSettingByte(0, TTB_OPTDIR, "BUTTHEIGHT", 16), FALSE);
+ SetDlgItemInt(hwndDlg, IDC_BUTTWIDTH, DBGetContactSettingByte(0, TTB_OPTDIR, "BUTTWIDTH", 20), FALSE);
+ CheckDlgButton(hwndDlg, IDC_USEMIRANDABUTTON, DBGetContactSettingByte(0, TTB_OPTDIR, "UseMirandaButtonClass", UseMirandaButtonClassDefaultValue));
+ CheckDlgButton(hwndDlg, IDC_USEFLAT, DBGetContactSettingByte(0, TTB_OPTDIR, "UseFlatButton", 1));
+
+ if ( !ServiceExists(MS_SKIN2_ADDICON))
+ EnableWindow(GetDlgItem(hwndDlg, IDC_USEICOLIB), FALSE);
+
+ CheckDlgButton(hwndDlg, IDC_USEICOLIB, ServiceExists(MS_SKIN2_ADDICON)&&DBGetContactSettingByte(0, TTB_OPTDIR, "UseIcoLib", UseIcoLibDefaultValue));
+
+ BuildTree(hwndDlg);
+ OptionsOpened = true;
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ENAME), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_EPATH), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_DELLBUTTON), FALSE);
+
+ SetDlgItemText(hwndDlg, IDC_IMGDIR, DBGetString(0, TTB_OPTDIR, "ImgDir"));
+ SendMessage(hwndDlg, WM_COMMAND, 0, 0);
+ OptionshWnd = hwndDlg;
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ ShowWindow(GetDlgItem(hwndDlg, IDC_BMPUP), IsDlgButtonChecked(hwndDlg, IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_BMPDN), IsDlgButtonChecked(hwndDlg, IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_DEFAULT), IsDlgButtonChecked(hwndDlg, IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
+
+ ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC1), IsDlgButtonChecked(hwndDlg, IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC2), IsDlgButtonChecked(hwndDlg, IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC3), IsDlgButtonChecked(hwndDlg, IDC_USEICOLIB)?SW_HIDE:SW_SHOW);
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_USEFLAT), IsDlgButtonChecked(hwndDlg, IDC_USEMIRANDABUTTON));
+
+ if (HIWORD(wParam) == EN_CHANGE ) {
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+ }
+
+ if ((HIWORD(wParam) == BN_CLICKED|| HIWORD(wParam) == BN_DBLCLK)) {
+ int ctrlid = LOWORD(wParam);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+
+ if (ctrlid == IDC_OPENIMGDIR) {
+ char buf[512];
+ PCIDLIST_ABSOLUTE res;
+
+ BROWSEINFO bi;
+ memset(&bi, 0, sizeof(bi));
+ bi.hwndOwner = hwndDlg;
+ bi.pszDisplayName = buf;
+ bi.lpszTitle = Translate("Select Directory");
+ bi.ulFlags = BIF_RETURNONLYFSDIRS;
+ res = SHBrowseForFolder(&bi);
+ if (res != NULL) {
+ if (SHGetPathFromIDList(res, buf) == TRUE) {
+ SetDlgItemText(hwndDlg, IDC_IMGDIR, (LPCSTR)&buf);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ }
+ break;
+ }
+
+ if (ctrlid == IDC_LBUTTONSET) {
+ int curselect;
+ TVITEM tvi;
+ tvi.hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE));
+ if (tvi.hItem == NULL){break;}
+
+ tvi.mask = TVIF_PARAM;
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvi);
+
+ curselect = ((ButtonOptData *)tvi.lParam)->pos;
+ if (Buttons[curselect].dwFlags & TTBBF_ISLBUTTON) {
+ LBUTOPT lbo = { 0 };
+ char buf[256];
+ GetDlgItemText(hwndDlg, IDC_ENAME, buf, 255);
+ lbo.name = _strdup(buf);
+
+ GetDlgItemText(hwndDlg, IDC_EPATH, buf, 255);
+ lbo.lpath = _strdup(buf);
+
+ CallService(TTB_MODIFYLBUTTON, Buttons[curselect].lParamDown, (LPARAM)&lbo);
+ free(lbo.name);
+ free(lbo.lpath);
+ }
+ break;
+ }
+
+ if (ctrlid == IDC_ADDLBUTTON) {
+ if (CallService(TTB_ADDLBUTTON, 0, 0) == 0) {
+ // BuildTree(hwndDlg);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ break;
+ }
+
+ if (ctrlid == IDC_DELLBUTTON) {
+ int curselect;
+ TVITEM tvi;
+ tvi.hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE));
+ if (tvi.hItem == NULL)
+ break;
+
+ tvi.mask = TVIF_PARAM;
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvi);
+
+ curselect = ((ButtonOptData *)tvi.lParam)->pos;
+ if (Buttons[curselect].dwFlags & TTBBF_ISLBUTTON) {
+ CallService(TTB_REMOVELBUTTON, Buttons[curselect].lParamDown, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ENAME), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_EPATH), FALSE);
+ BuildTree(hwndDlg);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ }
+
+ if (ctrlid == IDC_ADDSEP) {
+ if (CallService(TTB_ADDSEPARATOR, 0, 0) == 0) {
+ // BuildTree(hwndDlg);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ break;
+ }
+
+ if (ctrlid == IDC_REMOVESEP) {
+ TVITEM tvi;
+ memset(&tvi, 0, sizeof(tvi));
+ tvi.hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE));
+ if (tvi.hItem == NULL){break;}
+
+ //MessageBoxA(0, "GetSelItem", "log", 0);
+ tvi.mask = TVIF_PARAM;
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvi);
+
+ if (tvi.lParam == 0)
+ break;
+
+ if ( IsBadCodePtr(( FARPROC )tvi.lParam)) {
+ MessageBoxA(0, "Bad Code Ptr: tvi.lParam", "log", 0);
+ break;
+ }
+
+ int curselect = ((ButtonOptData *)tvi.lParam)->pos;
+ if ( curselect >= 0 && curselect < nButtonsCount ) {
+ if (Buttons[curselect].dwFlags&TTBBF_ISSEPARATOR) {
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ CallService(TTB_REMOVESEPARATOR, Buttons[curselect].lParamDown, 0);
+ }
+ }
+ break;
+ }
+
+ if (ctrlid == IDC_DEFAULT) {
+ TVITEM tvi;
+ tvi.hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE));
+ if (tvi.hItem == NULL)
+ break;
+
+ tvi.mask = TVIF_PARAM;
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvi);
+
+ int curselect = ((ButtonOptData *)tvi.lParam)->pos;
+ lockbut();
+
+ if (Buttons[curselect].UserDefinedbmUp != NULL) free(Buttons[curselect].UserDefinedbmUp);
+ if (Buttons[curselect].UserDefinedbmDown != NULL) free(Buttons[curselect].UserDefinedbmDown);
+ Buttons[curselect].UserDefinedbmUp = NULL;
+ Buttons[curselect].UserDefinedbmDown = NULL;
+ applyuserbitmaps(curselect);
+ SetImagesForCurrent(hwndDlg, curselect);
+
+ ulockbut();
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ }
+
+ if ((HIWORD(wParam) == STN_CLICKED|| HIWORD(wParam) == STN_DBLCLK)) {
+ int ctrlid = LOWORD(wParam);
+ if (ctrlid == IDC_BMPUP||ctrlid == IDC_BMPDN) {
+ TVITEM tvi;
+ tvi.hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE));
+ if (tvi.hItem == NULL)
+ break;
+
+ tvi.mask = TVIF_PARAM;
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvi);
+ if (tvi.lParam == 0)
+ break;
+
+ int curselect = ((ButtonOptData *)tvi.lParam)->pos;
+
+ TCHAR filename[MAX_PATH], filter[512];
+ filename[0] = 0;
+ _tcscpy(filter, TranslateT("Bitmap/Icon files"));
+ _tcscat(filter, _T(" (*.bmp;*.ico)"));
+
+ TCHAR *pfilter = filter+_tcslen(filter)+1;
+ _tcscpy(pfilter, _T("*.bmp;*.ico"));
+ pfilter += _tcslen(pfilter)+1;
+
+ _tcscpy(pfilter, TranslateT("All Files"));
+ _tcscat(pfilter, _T("(*)"));
+ pfilter = pfilter + _tcslen(pfilter)+1;
+
+ _tcscpy(pfilter, _T("*"));
+ pfilter = pfilter + _tcslen(pfilter)+1;
+ *pfilter = '\0';
+
+ OPENFILENAME ofn = {0};
+ ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+ ofn.hwndOwner = hwndDlg;
+ ofn.hInstance = NULL;
+ ofn.lpstrFilter = filter;
+ ofn.lpstrFile = filename;
+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
+ ofn.nMaxFile = sizeof(filename);
+ ofn.nMaxFileTitle = MAX_PATH;
+ ofn.lpstrDefExt = "bmp";
+ ofn.lpstrTitle = (ctrlid == IDC_BMPUP)?Translate("Select Up Bitmap"):Translate("Select Down Bitmap");
+ if (GetOpenFileName(&ofn)) {
+ lockbut();
+ if (ctrlid == IDC_BMPUP){
+ if (Buttons[curselect].UserDefinedbmUp != NULL){free(Buttons[curselect].UserDefinedbmUp);}
+ Buttons[curselect].UserDefinedbmUp = _strdup(ofn.lpstrFile);
+ }
+ if (ctrlid == IDC_BMPDN){
+ if (Buttons[curselect].UserDefinedbmDown != NULL){free(Buttons[curselect].UserDefinedbmDown);}
+ Buttons[curselect].UserDefinedbmDown = _strdup(ofn.lpstrFile);
+ }
+ applyuserbitmaps(curselect);
+ SetImagesForCurrent(hwndDlg, curselect);
+
+ ulockbut();
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ }
+ }
+ break;
+
+ case WM_NOTIFY:
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_APPLY:
+ DBWriteContactSettingByte(0, TTB_OPTDIR, "BUTTHEIGHT", GetDlgItemInt(hwndDlg, IDC_BUTTHEIGHT, FALSE, FALSE));
+ DBWriteContactSettingByte(0, TTB_OPTDIR, "BUTTWIDTH", GetDlgItemInt(hwndDlg, IDC_BUTTWIDTH, FALSE, FALSE));
+ DBWriteContactSettingByte(0, TTB_OPTDIR, "UseMirandaButtonClass", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USEMIRANDABUTTON));
+ DBWriteContactSettingByte(0, TTB_OPTDIR, "UseFlatButton", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USEFLAT));
+
+ DBWriteContactSettingByte(0, TTB_OPTDIR, "UseIcoLib", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USEICOLIB));
+
+
+ SaveTree(hwndDlg);
+ ApplyNewDir(hwndDlg);
+ RecreateWindows();
+ ArrangeButtons();
+ }
+ break;
+
+ case IDC_BUTTONORDERTREE:
+ switch (((LPNMHDR)lParam)->code) {
+ case TVN_BEGINDRAG:
+ SetCapture(hwndDlg);
+ dat->dragging = 1;
+ dat->hDragItem = ((LPNMTREEVIEW)lParam)->itemNew.hItem;
+ TreeView_SelectItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), dat->hDragItem);
+ break;
+
+ case NM_CLICK:
+ {
+ TVHITTESTINFO hti;
+ hti.pt.x = (short)LOWORD(GetMessagePos());
+ hti.pt.y = (short)HIWORD(GetMessagePos());
+ ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
+ if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) {
+ if (hti.flags&TVHT_ONITEMICON) {
+ TVITEM tvi;
+ tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
+ tvi.hItem = hti.hItem;
+ TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
+ tvi.iImage = tvi.iSelectedImage = !tvi.iImage;
+ ((ButtonOptData *)tvi.lParam)->show = tvi.iImage;
+ TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ }
+ }
+ break;
+
+ case TVN_SELCHANGED:
+ {
+ TVITEM tvi;
+ HTREEITEM hti;
+
+ hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE));
+ if (hti == NULL){break;}
+ tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
+ tvi.hItem = hti;
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvi);
+
+
+ lockbut();
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BMPUP), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BMPDN), FALSE);
+
+ SetImagesForCurrent(hwndDlg, ((ButtonOptData *)tvi.lParam)->pos);
+ //PostMessage(GetDlgItem(hwndDlg, IDC_BMPUP), STM_SETIMAGE, IMAGE_BITMAP, Buttons[((ButtonOptData *)tvi.lParam)->pos].hbBitmapUp);
+ //PostMessage(GetDlgItem(hwndDlg, IDC_BMPDN), STM_SETIMAGE, IMAGE_BITMAP, Buttons[((ButtonOptData *)tvi.lParam)->pos].hbBitmapDown);
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVESEP), FALSE);
+ if (Buttons[((ButtonOptData *)tvi.lParam)->pos].dwFlags&TTBBF_ISSEPARATOR)
+ EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVESEP), TRUE);
+ else {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BMPUP), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BMPDN), TRUE);
+ }
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ENAME), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_EPATH), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_DELLBUTTON), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_LBUTTONSET), FALSE);
+ {SetDlgItemText(hwndDlg, IDC_ENAME, "");}
+ {SetDlgItemText(hwndDlg, IDC_EPATH, "");}
+
+ if (Buttons[((ButtonOptData *)tvi.lParam)->pos].dwFlags & TTBBF_ISLBUTTON) {
+ LBUTOPT lbo = { 0 };
+ CallService(TTB_GETLBUTTON, Buttons[((ButtonOptData *)tvi.lParam)->pos].lParamDown, (LPARAM)&lbo);
+ if (lbo.hframe != 0) {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ENAME), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_EPATH), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_DELLBUTTON), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_LBUTTONSET), TRUE);
+
+ if (lbo.name != NULL){SetDlgItemText(hwndDlg, IDC_ENAME, lbo.name);}
+ if (lbo.lpath != NULL){SetDlgItemText(hwndDlg, IDC_EPATH, lbo.lpath);}
+ }
+ }
+
+ ulockbut();
+ }
+ }
+ break;
+ }
+ break;
+
+ case WM_MOUSEMOVE:
+ if (dat->dragging) {
+ TVHITTESTINFO hti;
+ hti.pt.x = (short)LOWORD(lParam);
+ hti.pt.y = (short)HIWORD(lParam);
+ ClientToScreen(hwndDlg, &hti.pt);
+ ScreenToClient(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &hti.pt);
+ TreeView_HitTest(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &hti);
+ if (hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
+ hti.pt.y -= TreeView_GetItemHeight(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE))/2;
+ TreeView_HitTest(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &hti);
+ TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), hti.hItem, 1);
+ }
+ else {
+ if (hti.flags&TVHT_ABOVE) SendDlgItemMessage(hwndDlg, IDC_BUTTONORDERTREE, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
+ if (hti.flags&TVHT_BELOW) SendDlgItemMessage(hwndDlg, IDC_BUTTONORDERTREE, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
+ TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), NULL, 0);
+ }
+ }
+ break;
+
+ case WM_DESTROY:
+ OptionsOpened = false;
+ return 0;
+
+ case WM_LBUTTONUP:
+ if (dat->dragging) {
+ TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), NULL, 0);
+ dat->dragging = 0;
+ ReleaseCapture();
+
+ TVHITTESTINFO hti;
+ TVITEM tvi;
+ hti.pt.x = (short)LOWORD(lParam);
+ hti.pt.y = (short)HIWORD(lParam);
+ ClientToScreen(hwndDlg, &hti.pt);
+ ScreenToClient(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &hti.pt);
+ hti.pt.y -= TreeView_GetItemHeight(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE))/2;
+ TreeView_HitTest(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &hti);
+ if (dat->hDragItem == hti.hItem) break;
+ tvi.mask = TVIF_HANDLE|TVIF_PARAM;
+ tvi.hItem = hti.hItem;
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvi);
+ if (hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
+ TVINSERTSTRUCT tvis;
+ char name[128];
+ tvis.item.mask = TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+ tvis.item.stateMask = 0xFFFFFFFF;
+ tvis.item.pszText = name;
+ tvis.item.cchTextMax = sizeof(name);
+ tvis.item.hItem = dat->hDragItem;
+ //
+ tvis.item.iImage = tvis.item.iSelectedImage = ((ButtonOptData *)tvi.lParam)->show;
+
+ TreeView_GetItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvis.item);
+
+ TreeView_DeleteItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), dat->hDragItem);
+ tvis.hParent = NULL;
+ tvis.hInsertAfter = hti.hItem;
+ TreeView_SelectItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), TreeView_InsertItem(GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE), &tvis));
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ SaveTree(hwndDlg);
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+int TTBOptInit(WPARAM wParam, LPARAM lParam)
+{
+ OPTIONSDIALOGPAGE odp = { 0 };
+ odp.cbSize = sizeof(odp);
+ odp.position = 0;
+ odp.hInstance = hInst;
+ odp.pszGroup = Translate("TopToolBar");
+
+ if ( !ServiceExists(MS_BACKGROUNDCONFIG_REGISTER)) {
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_OPT_TTBBKG);
+ odp.pszTitle = Translate("TTBBackground");
+ odp.pfnDlgProc = DlgProcTTBBkgOpts;
+ odp.flags = ODPF_BOLDGROUPS;
+ CallService(MS_OPT_ADDPAGE, wParam, (LPARAM)&odp);
+ }
+
+ ZeroMemory(&odp, sizeof(odp));
+ odp.cbSize = sizeof(odp);
+ odp.position = -1000000000;
+ odp.hInstance = hInst;//GetModuleHandle(NULL);
+ odp.pszTemplate = MAKEINTRESOURCE(IDD_OPT_BUTORDER);
+ odp.pszGroup = Translate("TopToolBar");
+ odp.pszTitle = Translate("Buttons");
+ odp.pfnDlgProc = ButOrderOpts;
+ odp.flags = ODPF_BOLDGROUPS|ODPF_EXPERTONLY;
+ CallService(MS_OPT_ADDPAGE, wParam, (LPARAM)&odp);
+ return 0;
+}
+
+static BOOL CALLBACK DlgProcTTBBkgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ CheckDlgButton(hwndDlg, IDC_BITMAP, DBGetContactSettingByte(NULL, TTB_OPTDIR, "UseBitmap", TTBDEFAULT_USEBITMAP)?BST_CHECKED:BST_UNCHECKED);
+ SendMessage(hwndDlg, WM_USER+10, 0, 0);
+ SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_SETDEFAULTCOLOUR, 0, TTBDEFAULT_BKCOLOUR);
+ SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_SETCOLOUR, 0, DBGetContactSettingDword(NULL, TTB_OPTDIR, "BkColour", TTBDEFAULT_BKCOLOUR));
+ SendDlgItemMessage(hwndDlg, IDC_SELCOLOUR, CPM_SETDEFAULTCOLOUR, 0, TTBDEFAULT_SELBKCOLOUR);
+ SendDlgItemMessage(hwndDlg, IDC_SELCOLOUR, CPM_SETCOLOUR, 0, DBGetContactSettingDword(NULL, TTB_OPTDIR, "SelBkColour", TTBDEFAULT_SELBKCOLOUR));
+ {
+ DBVARIANT dbv;
+ if (!DBGetContactSetting(NULL, TTB_OPTDIR, "BkBitmap", &dbv)) {
+ SetDlgItemText(hwndDlg, IDC_FILENAME, dbv.pszVal);
+ DBFreeVariant(&dbv);
+ }
+ }
+ {
+ WORD bmpUse = DBGetContactSettingWord(NULL, TTB_OPTDIR, "BkBmpUse", TTBDEFAULT_BKBMPUSE);
+ CheckDlgButton(hwndDlg, IDC_STRETCHH, bmpUse&CLB_STRETCHH?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_STRETCHV, bmpUse&CLB_STRETCHV?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_TILEH, bmpUse&CLBF_TILEH?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_TILEV, bmpUse&CLBF_TILEV?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_SCROLL, bmpUse&CLBF_SCROLL?BST_CHECKED:BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_PROPORTIONAL, bmpUse&CLBF_PROPORTIONAL?BST_CHECKED:BST_UNCHECKED);
+ }
+ {
+ HRESULT (STDAPICALLTYPE *MySHAutoComplete)(HWND, DWORD);
+ MySHAutoComplete = (HRESULT (STDAPICALLTYPE*)(HWND, DWORD))GetProcAddress(GetModuleHandle("shlwapi"), "SHAutoComplete");
+ if (MySHAutoComplete) MySHAutoComplete(GetDlgItem(hwndDlg, IDC_FILENAME), 1);
+ }
+ return TRUE;
+
+ case WM_USER+10:
+ EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), IsDlgButtonChecked(hwndDlg, IDC_BITMAP));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BROWSE), IsDlgButtonChecked(hwndDlg, IDC_BITMAP));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_STRETCHH), IsDlgButtonChecked(hwndDlg, IDC_BITMAP));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_STRETCHV), IsDlgButtonChecked(hwndDlg, IDC_BITMAP));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_TILEH), IsDlgButtonChecked(hwndDlg, IDC_BITMAP));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_TILEV), IsDlgButtonChecked(hwndDlg, IDC_BITMAP));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_SCROLL), IsDlgButtonChecked(hwndDlg, IDC_BITMAP));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_PROPORTIONAL), IsDlgButtonChecked(hwndDlg, IDC_BITMAP));
+ break;
+
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDC_BROWSE) {
+ TCHAR str[MAX_PATH];
+ OPENFILENAME ofn = {0};
+ TCHAR filter[512];
+
+ GetDlgItemText(hwndDlg, IDC_FILENAME, str, sizeof(str));
+ ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+ ofn.hwndOwner = hwndDlg;
+ ofn.hInstance = NULL;
+ CallService(MS_UTILS_GETBITMAPFILTERSTRINGST, SIZEOF(filter), (LPARAM)filter);
+ ofn.lpstrFilter = filter;
+ ofn.lpstrFile = str;
+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
+ ofn.nMaxFile = sizeof(str);
+ ofn.nMaxFileTitle = MAX_PATH;
+ ofn.lpstrDefExt = "bmp";
+ if (!GetOpenFileName(&ofn))
+ break;
+
+ SetDlgItemText(hwndDlg, IDC_FILENAME, str);
+ }
+ else if (LOWORD(wParam) == IDC_FILENAME && HIWORD(wParam) != EN_CHANGE)
+ break;
+
+ if (LOWORD(wParam) == IDC_BITMAP) SendMessage(hwndDlg, WM_USER+10, 0, 0);
+ if (LOWORD(wParam) == IDC_FILENAME && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0;
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+
+ case WM_NOTIFY:
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_APPLY:
+ DBWriteContactSettingByte(NULL, TTB_OPTDIR, "UseBitmap", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_BITMAP));
+ {
+ COLORREF col = SendDlgItemMessage(hwndDlg, IDC_BKGCOLOUR, CPM_GETCOLOUR, 0, 0);
+ if (col == TTBDEFAULT_BKCOLOUR)
+ DBDeleteContactSetting(NULL, TTB_OPTDIR, "BkColour");
+ else
+ DBWriteContactSettingDword(NULL, TTB_OPTDIR, "BkColour", col);
+ col = SendDlgItemMessage(hwndDlg, IDC_SELCOLOUR, CPM_GETCOLOUR, 0, 0);
+ if (col == TTBDEFAULT_SELBKCOLOUR)
+ DBDeleteContactSetting(NULL, TTB_OPTDIR, "SelBkColour");
+ else
+ DBWriteContactSettingDword(NULL, TTB_OPTDIR, "SelBkColour", col);
+ }
+ {
+ TCHAR str[MAX_PATH];
+ GetDlgItemText(hwndDlg, IDC_FILENAME, str, SIZEOF(str));
+ DBWriteContactSettingString(NULL, TTB_OPTDIR, "BkBitmap", str);
+ }
+ {
+ WORD flags = 0;
+ if (IsDlgButtonChecked(hwndDlg, IDC_STRETCHH)) flags |= CLB_STRETCHH;
+ if (IsDlgButtonChecked(hwndDlg, IDC_STRETCHV)) flags |= CLB_STRETCHV;
+ if (IsDlgButtonChecked(hwndDlg, IDC_TILEH)) flags |= CLBF_TILEH;
+ if (IsDlgButtonChecked(hwndDlg, IDC_TILEV)) flags |= CLBF_TILEV;
+ if (IsDlgButtonChecked(hwndDlg, IDC_SCROLL)) flags |= CLBF_SCROLL;
+ if (IsDlgButtonChecked(hwndDlg, IDC_PROPORTIONAL)) flags |= CLBF_PROPORTIONAL;
+ DBWriteContactSettingWord(NULL, TTB_OPTDIR, "BkBmpUse", flags);
+ }
+
+ ttbOptionsChanged();
+ return TRUE;
+ }
+ break;
+ }
+ break;
+ }
+ return FALSE;
+}