diff options
author | George Hazan <george.hazan@gmail.com> | 2013-07-21 10:37:30 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-07-21 10:37:30 +0000 |
commit | a971c497d5c86f11df8a048e3e9eb88691966169 (patch) | |
tree | 2570d81ccc8302aac31b3aaa299627679eeb367e /plugins | |
parent | 25bbf4a64df769564aa3b177712dfd21d910edab (diff) |
- BUTTONSETSENDONDOWN functionality moved to the core;
- custom button click processing removed from clist_nicer;
- control id assignment removed and replaced with the search by HWND
git-svn-id: http://svn.miranda-ng.org/main/trunk@5440 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Clist_modern/src/m_api/m_skinbutton.h | 2 | ||||
-rw-r--r-- | plugins/Clist_modern/src/modern_tbbutton.cpp | 79 | ||||
-rw-r--r-- | plugins/Clist_nicer/src/CLCButton.cpp | 96 | ||||
-rw-r--r-- | plugins/Clist_nicer/src/Include/clc.h | 3 | ||||
-rw-r--r-- | plugins/Clist_nicer/src/clui.cpp | 4 | ||||
-rw-r--r-- | plugins/Clist_nicer/src/viewmodes.cpp | 2 |
6 files changed, 74 insertions, 112 deletions
diff --git a/plugins/Clist_modern/src/m_api/m_skinbutton.h b/plugins/Clist_modern/src/m_api/m_skinbutton.h index 43a3167ce3..1ca5c38e6d 100644 --- a/plugins/Clist_modern/src/m_api/m_skinbutton.h +++ b/plugins/Clist_modern/src/m_api/m_skinbutton.h @@ -7,8 +7,6 @@ #define BUTTONSETID WM_USER+55
#define BUTTONDRAWINPARENT WM_USER+56
#define BUTTONSETMARGINS WM_USER+57
-#define BUTTONSETSENDONDOWN WM_USER+58
-
#define SBF_ALIGN_TL_RIGHT 1
#define SBF_ALIGN_TL_HCENTER 2
diff --git a/plugins/Clist_modern/src/modern_tbbutton.cpp b/plugins/Clist_modern/src/modern_tbbutton.cpp index a82696884e..9d55684139 100644 --- a/plugins/Clist_modern/src/modern_tbbutton.cpp +++ b/plugins/Clist_modern/src/modern_tbbutton.cpp @@ -19,18 +19,15 @@ void CustomizeToolbar(HWND); struct TBBUTTONDATA : public MButtonCtrl
{
char *szButtonID; // button id
- BOOL fSendOnDown; // send event on button pushed
- BOOL fHotMark; // button is hot marked (e.g. current state)
- BOOL fFocused;
+ bool bHotMark; // button is hot marked (e.g. current state)
+ bool bFocused;
int nFontID; // internal font ID
- HANDLE ttbID; // control ID
TCHAR szText[128]; // text on the button
RECT rcMargins; // margins of inner content
- HANDLE hIcolibHandle; // handle of icon in iconlib
+ HANDLE hIcolibHandle; // handle of icon in iconlib
- XPTHANDLE hThemeButton;
- XPTHANDLE hThemeToolbar;
+ XPTHANDLE hThemeButton, hThemeToolbar;
};
static CRITICAL_SECTION csTips;
@@ -109,7 +106,7 @@ static void PaintWorker(TBBUTTONDATA *bct, HDC hdcPaint , POINT *pOffset) bct->szButtonID, // ID
b2str(bct->stateId == PBS_HOT), // Hovered
b2str(bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE), // Pressed
- b2str(bct->fFocused)); // Focused
+ b2str(bct->bFocused)); // Focused
SkinDrawGlyph(hdcMem,&rcClient,&rcClient,szRequest);
}
@@ -154,7 +151,7 @@ static void PaintWorker(TBBUTTONDATA *bct, HDC hdcPaint , POINT *pOffset) FillRect(hdcMem, &rcClient, hbr);
DeleteObject(hbr);
}
- if (bct->stateId == PBS_HOT || bct->fFocused) {
+ if (bct->stateId == PBS_HOT || bct->bFocused) {
if (bct->bIsPushed)
DrawEdge(hdcMem,&rcClient, EDGE_ETCHED,BF_RECT|BF_SOFT);
else
@@ -234,16 +231,16 @@ static void PaintWorker(TBBUTTONDATA *bct, HDC hdcPaint , POINT *pOffset) static LRESULT CALLBACK ToolbarButtonProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- TBBUTTONDATA *bct = (TBBUTTONDATA *) GetWindowLongPtr(hwndDlg, 0);
+ TBBUTTONDATA *bct = (TBBUTTONDATA*)GetWindowLongPtr(hwndDlg, 0);
+
switch (msg) {
case WM_DESTROY:
xpt_FreeThemeForWindow(hwndDlg);
WindowList_Remove(hButtonWindowList, hwndDlg);
- break; // DONT! fall thru
+ break;
case WM_SETTEXT:
- lstrcpyn(bct->szText, (TCHAR *)lParam, SIZEOF(bct->szText)-1);
- bct->szText[SIZEOF(bct->szText)-1] = '\0';
+ _tcsncpy_s(bct->szText, SIZEOF(bct->szText), (TCHAR*)lParam, _TRUNCATE);
break;
case WM_SETFONT:
@@ -252,10 +249,6 @@ static LRESULT CALLBACK ToolbarButtonProc(HWND hwndDlg, UINT msg, WPARAM wParam bct->nFontID = (int)lParam - 1;
break;
- case BUTTONSETSENDONDOWN:
- bct->fSendOnDown = (BOOL)lParam;
- break;
-
case BUTTONSETMARGINS:
if (lParam) bct->rcMargins = *(RECT*)lParam;
else {
@@ -270,7 +263,7 @@ static LRESULT CALLBACK ToolbarButtonProc(HWND hwndDlg, UINT msg, WPARAM wParam case BUTTONDRAWINPARENT:
if (IsWindowVisible(hwndDlg))
- PaintWorker(bct, (HDC) wParam, (POINT*) lParam);
+ PaintWorker(bct, (HDC)wParam, (POINT*)lParam);
break;
case WM_NCPAINT:
@@ -301,15 +294,15 @@ static LRESULT CALLBACK ToolbarButtonProc(HWND hwndDlg, UINT msg, WPARAM wParam RECT rcClient;
GetClientRect(bct->hwnd, &rcClient);
if ( !PtInRect(&rcClient, ptMouse)) {
- bct->fHotMark = FALSE;
+ bct->bHotMark = false;
ReleaseCapture();
}
else {
if (bct->stateId != PBS_DISABLED && bct->stateId != PBS_PRESSED) {
bct->stateId = PBS_PRESSED;
- bct->fHotMark = TRUE;
+ bct->bHotMark = true;
InvalidateParentRect(bct->hwnd, NULL, TRUE);
- if (bct->fSendOnDown) {
+ if (bct->bSendOnDown) {
SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM) hwndDlg);
bct->stateId = PBS_NORMAL;
InvalidateParentRect(bct->hwnd, NULL, TRUE);
@@ -321,14 +314,14 @@ static LRESULT CALLBACK ToolbarButtonProc(HWND hwndDlg, UINT msg, WPARAM wParam return 0;
case WM_LBUTTONUP:
- if ( GetCapture() == bct->hwnd ) {
+ if (GetCapture() == bct->hwnd) {
POINT ptMouse = UNPACK_POINT(lParam);
RECT rcClient;
GetClientRect(bct->hwnd, &rcClient);
if ( !PtInRect(&rcClient, ptMouse)) {
- bct->fHotMark = FALSE;
+ bct->bHotMark = false;
ReleaseCapture();
break;
}
@@ -341,44 +334,45 @@ static LRESULT CALLBACK ToolbarButtonProc(HWND hwndDlg, UINT msg, WPARAM wParam bct->stateId = PBS_HOT;
InvalidateParentRect(bct->hwnd, NULL, TRUE);
}
- if ( !bct->fSendOnDown) {
- bct->fHotMark = FALSE;
+ if ( !bct->bSendOnDown) {
+ bct->bHotMark = false;
SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
}
}
- else bct->fHotMark = FALSE;
+ else bct->bHotMark = false;
return 0;
case WM_MOUSEMOVE:
{
- RECT rc;
- POINT pt;
BOOL bPressed = (wParam & MK_LBUTTON) != 0;
- if ( bPressed && !bct->fHotMark )
+ if (bPressed && !bct->bHotMark)
break;
+
+ RECT rc;
+ POINT pt;
GetWindowRect(hwndDlg, &rc);
GetCursorPos(&pt);
BOOL inClient = PtInRect(&rc, pt);
- if ( inClient ) {
- SetCapture( bct->hwnd );
- if ( bct->stateId == PBS_NORMAL ) {
+ if (inClient) {
+ SetCapture(bct->hwnd);
+ if (bct->stateId == PBS_NORMAL) {
bct->stateId = PBS_HOT;
InvalidateParentRect(bct->hwnd, NULL, TRUE);
}
}
- if ( !inClient && bct->stateId == PBS_PRESSED ) {
+ if (!inClient && bct->stateId == PBS_PRESSED) {
bct->stateId = PBS_HOT;
InvalidateParentRect(bct->hwnd, NULL, TRUE);
}
- else if ( inClient && bct->stateId == PBS_HOT && bPressed ) {
- if ( bct->fHotMark ) {
+ else if (inClient && bct->stateId == PBS_HOT && bPressed) {
+ if (bct->bHotMark) {
bct->stateId = PBS_PRESSED;
InvalidateParentRect(bct->hwnd, NULL, TRUE);
}
}
else if ( !inClient && !bPressed) {
- bct->fHotMark = FALSE;
+ bct->bHotMark = false;
ReleaseCapture();
}
}
@@ -401,6 +395,16 @@ static LRESULT CALLBACK ToolbarButtonProc(HWND hwndDlg, UINT msg, WPARAM wParam InvalidateRect(bct->hwnd, NULL, TRUE);
return 0;
+ case WM_SETFOCUS: // set keyboard focus and redraw
+ bct->bFocused = true;
+ InvalidateParentRect(bct->hwnd, NULL, TRUE);
+ break;
+
+ case WM_KILLFOCUS: // kill focus and redraw
+ bct->bFocused = false;
+ InvalidateParentRect(bct->hwnd, NULL, TRUE);
+ break;
+
case WM_ERASEBKGND:
return 1;
@@ -459,9 +463,8 @@ void CustomizeButton(HANDLE ttbid, HWND hWnd, LPARAM lParam) MakeButtonSkinned(hWnd);
- TBBUTTONDATA* p = (TBBUTTONDATA*)GetWindowLongPtr(hWnd, 0);
+ TBBUTTONDATA *p = (TBBUTTONDATA*)GetWindowLongPtr(hWnd, 0);
p->szButtonID = "Toolbar.MissingID";
- p->ttbID = ttbid;
SendMessage(hWnd, MBM_UPDATETRANSPARENTFLAG, 0, 2);
}
diff --git a/plugins/Clist_nicer/src/CLCButton.cpp b/plugins/Clist_nicer/src/CLCButton.cpp index 9024f08c5a..e766f8b095 100644 --- a/plugins/Clist_nicer/src/CLCButton.cpp +++ b/plugins/Clist_nicer/src/CLCButton.cpp @@ -23,8 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct
{
- int ctrlid;
- char *pszButtonID, *pszButtonDn, *pszButtonName;
+ int ctrlid;
+ char *pszButtonID, *pszButtonDn, *pszButtonName;
int isPush, isVis, isAction;
HANDLE hButton;
HWND hwndButton;
@@ -67,8 +67,7 @@ static int getButtonIndex(HANDLE hButton) static void InitDefaultButtons()
{
for (int i=0; i < SIZEOF(BTNS); i++ ) {
- TTBButton tbb = { 0 };
- tbb.cbSize = sizeof(tbb);
+ TTBButton tbb = { sizeof(tbb) };
g_index = i;
if (BTNS[i].pszButtonID) {
@@ -110,6 +109,15 @@ HWND ClcGetButtonWindow(int ctrlid) return NULL;
}
+int ClcGetButtonId(HWND hwnd)
+{
+ for (int i=0; i < SIZEOF(BTNS); i++)
+ if (BTNS[i].hwndButton == hwnd)
+ return BTNS[i].ctrlid;
+
+ return 0;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
struct MButtonExtension : public MButtonCtrl
@@ -118,8 +126,7 @@ struct MButtonExtension : public MButtonCtrl TCHAR szText[128];
SIZE sLabel;
HIMAGELIST hIml;
- int iIcon, iCtrlID;
- BOOL bSendOnDown;
+ int iIcon;
ButtonItem *buttonItem;
LONG lastGlyphMetrics[4];
};
@@ -362,7 +369,7 @@ static void PaintWorker(MButtonExtension *ctl, HDC hdcPaint) static LRESULT CALLBACK TSButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- MButtonExtension *bct = (MButtonExtension*) GetWindowLongPtr(hwnd, 0);
+ MButtonExtension *bct = (MButtonExtension*)GetWindowLongPtr(hwnd, 0);
switch (msg) {
case WM_DESTROY:
@@ -371,22 +378,12 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR break;
case WM_SETTEXT:
- lstrcpyn(bct->szText, (TCHAR *)lParam, 127);
- bct->szText[127] = 0;
- break;
-
- case WM_SYSKEYUP:
- if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == tolower((int) wParam)) {
- if ( !bct->bSendOnDown)
- SendMessage(pcli->hwndContactList, WM_COMMAND, MAKELONG(bct->iCtrlID, BN_CLICKED), (LPARAM) hwnd);
- return 0;
- }
+ _tcsncpy_s(bct->szText, SIZEOF(bct->szText), (TCHAR*)lParam, _TRUNCATE);
break;
case BM_GETIMAGE:
if (wParam == IMAGE_ICON)
return (LRESULT)(bct->hIconPrivate ? bct->hIconPrivate : bct->hIcon);
-
break;
case BM_SETIMAGE:
@@ -414,7 +411,8 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR ImageList_RemoveAll(hImageList);
ImageList_Destroy(hImageList);
bct->hIcon = 0;
- } else {
+ }
+ else {
bct->hIcon = (HICON) lParam;
bct->hIconPrivate = 0;
}
@@ -452,37 +450,6 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR bct->buttonItem = (ButtonItem *)lParam;
break;
- case BUTTONSETASMENUACTION:
- bct->bSendOnDown = wParam ? TRUE : FALSE;
- break;
-
- case WM_LBUTTONDOWN:
- if (!bct->iCtrlID) break;
- if (bct->stateId != PBS_DISABLED && bct->stateId != PBS_PRESSED) {
- bct->stateId = PBS_PRESSED;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- if (bct->bSendOnDown) {
- SendMessage( GetParent(hwnd), WM_COMMAND, MAKELONG(bct->iCtrlID, BN_CLICKED), (LPARAM) hwnd);
- bct->stateId = PBS_NORMAL;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- }
- return 1;
-
- case WM_LBUTTONUP:
- if (!bct->iCtrlID) break;
- if (bct->bIsPushBtn)
- bct->bIsPushed = !bct->bIsPushed;
-
- if (bct->stateId != PBS_DISABLED) {
- // don't change states if disabled
- bct->stateId = PBS_HOT;
- InvalidateRect(bct->hwnd, NULL, TRUE);
- }
- if ( !bct->bSendOnDown)
- SendMessage( GetParent(hwnd), WM_COMMAND, MAKELONG(bct->iCtrlID, BN_CLICKED), (LPARAM) hwnd);
- return 1;
-
case WM_NCHITTEST:
switch( SendMessage(pcli->hwndContactList, WM_NCHITTEST, wParam, lParam)) {
case HTLEFT: case HTRIGHT: case HTBOTTOM: case HTTOP:
@@ -493,16 +460,14 @@ static LRESULT CALLBACK TSButtonWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR return mir_callNextSubclass(hwnd, TSButtonWndProc, msg, wParam, lParam);
}
-static void SetButtonAsCustom(HWND hWnd)
-{
- SendMessage(hWnd, BUTTONSETCUSTOMPAINT, sizeof(MButtonExtension), (LPARAM)PaintWorker);
- mir_subclassWindow(hWnd, TSButtonWndProc);
-}
-
static LRESULT CALLBACK ToolbarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- if (msg == WM_COMMAND && HIWORD(wParam) == BN_CLICKED)
- SendMessage(pcli->hwndContactList, msg, wParam, lParam);
+ // standard buttons are processed in the main window
+ if (msg == WM_COMMAND && HIWORD(wParam) == BN_CLICKED) {
+ int iCtrlId = ClcGetButtonId((HWND)lParam);
+ if (iCtrlId)
+ SendMessage(pcli->hwndContactList, msg, MAKELONG(iCtrlId, BN_CLICKED), lParam);
+ }
return mir_callNextSubclass(hwnd, ToolbarWndProc, msg, wParam, lParam);
}
@@ -516,27 +481,24 @@ static void CustomizeToolbar(HANDLE hButton, HWND hWnd, LPARAM) return;
}
- SetButtonAsCustom(hWnd);
+ SendMessage(hWnd, BUTTONSETCUSTOMPAINT, sizeof(MButtonExtension), (LPARAM)PaintWorker);
+ mir_subclassWindow(hWnd, TSButtonWndProc);
MButtonExtension *bct = (MButtonExtension*) GetWindowLongPtr(hWnd, 0);
int idx = getButtonIndex(hButton);
if (idx != -1) { // adding built-in button
BTNS[idx].hwndButton = hWnd;
- bct->iCtrlID = BTNS[idx].ctrlid;
if (BTNS[idx].isAction)
- bct->bSendOnDown = TRUE;
+ bct->bSendOnDown = true;
if ( !BTNS[idx].isPush)
- bct->bIsPushBtn = TRUE;
+ bct->bIsPushBtn = true;
}
}
void CustomizeButton(HWND hWnd, bool bIsSkinned, bool bIsThemed, bool bIsFlat)
{
- SetButtonAsCustom(hWnd);
-
- MButtonExtension *bct = (MButtonExtension*) GetWindowLongPtr(hWnd, 0);
- if (bct)
- bct->iCtrlID = GetDlgCtrlID(hWnd);
+ SendMessage(hWnd, BUTTONSETCUSTOMPAINT, sizeof(MButtonExtension), (LPARAM)PaintWorker);
+ mir_subclassWindow(hWnd, TSButtonWndProc);
SendMessage(hWnd, BUTTONSETSKINNED, bIsSkinned, 0);
SendMessage(hWnd, BUTTONSETASTHEMEDBTN, bIsThemed, 0);
diff --git a/plugins/Clist_nicer/src/Include/clc.h b/plugins/Clist_nicer/src/Include/clc.h index e28143eeec..9fe24eb181 100644 --- a/plugins/Clist_nicer/src/Include/clc.h +++ b/plugins/Clist_nicer/src/Include/clc.h @@ -461,8 +461,7 @@ int Docking_IsDocked(WPARAM wParam, LPARAM lParam); #define BUTTONSETIMLICON (WM_USER+20)
#define BUTTONSETSKINNED (WM_USER+21)
-#define BUTTONSETASMENUACTION (WM_USER+22)
-#define BUTTONSETBTNITEM (WM_USER+23)
+#define BUTTONSETBTNITEM (WM_USER+22)
// Menus
diff --git a/plugins/Clist_nicer/src/clui.cpp b/plugins/Clist_nicer/src/clui.cpp index 1c6f4e2839..75166d6429 100644 --- a/plugins/Clist_nicer/src/clui.cpp +++ b/plugins/Clist_nicer/src/clui.cpp @@ -315,14 +315,14 @@ void CreateButtonBar(HWND hWnd) CustomizeButton(hTbMenu, false, false, false);
SetWindowText(hTbMenu, TranslateT("Menu"));
SendMessage(hTbMenu, BM_SETIMAGE, IMAGE_ICON, (LPARAM) LoadSkinnedIcon(SKINICON_OTHER_MAINMENU));
- SendMessage(hTbMenu, BUTTONSETASMENUACTION, 1, 0);
+ SendMessage(hTbMenu, BUTTONSETSENDONDOWN, TRUE, 0);
SendMessage(hTbMenu, BUTTONADDTOOLTIP, (WPARAM) TranslateT("Open main menu"), BATF_TCHAR);
hTbGlobalStatus = CreateWindowEx(0, MIRANDABUTTONCLASS, _T(""), BS_PUSHBUTTON | WS_CHILD | WS_TABSTOP, 0, 0, 20, 20, hWnd, (HMENU) IDC_TBGLOBALSTATUS, g_hInst, NULL);
CustomizeButton(hTbGlobalStatus, false, false, false);
SetWindowText(hTbGlobalStatus, TranslateT("Offline"));
SendMessage(hTbGlobalStatus, BM_SETIMAGE, IMAGE_ICON, (LPARAM) LoadSkinnedIcon(SKINICON_STATUS_OFFLINE));
- SendMessage(hTbGlobalStatus, BUTTONSETASMENUACTION, 1, 0);
+ SendMessage(hTbGlobalStatus, BUTTONSETSENDONDOWN, TRUE, 0);
SendMessage(hTbGlobalStatus, BUTTONADDTOOLTIP, (WPARAM) TranslateT("Set status modes"), BATF_TCHAR);
}
diff --git a/plugins/Clist_nicer/src/viewmodes.cpp b/plugins/Clist_nicer/src/viewmodes.cpp index 47ac3f043a..831407e081 100644 --- a/plugins/Clist_nicer/src/viewmodes.cpp +++ b/plugins/Clist_nicer/src/viewmodes.cpp @@ -861,7 +861,7 @@ LRESULT CALLBACK ViewModeFrameWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM hwnd, (HMENU) IDC_SELECTMODE, g_hInst, NULL);
CustomizeButton(hwndSelector, false, false, false);
SendMessage(hwndSelector, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Select a view mode"), BATF_UNICODE);
- SendMessage(hwndSelector, BUTTONSETASMENUACTION, 1, 0);
+ SendMessage(hwndSelector, BUTTONSETSENDONDOWN, TRUE, 0);
HWND hwndButton = CreateWindowEx(0, MIRANDABUTTONCLASS, _T(""), BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP, 0, 0, 20, 20,
hwnd, (HMENU) IDC_CONFIGUREMODES, g_hInst, NULL);
|