summaryrefslogtreecommitdiff
path: root/src/modules/button
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-06-13 17:26:45 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-06-13 17:26:45 +0000
commit5e686292c537275c8ea1399f311c082d905e8a63 (patch)
tree88a4f3921ff70323775f3329c8820a0fe947d74f /src/modules/button
parent90c154b4be566ec4a804217d0f1e50fb1e259b72 (diff)
code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@398 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/button')
-rw-r--r--src/modules/button/button.cpp445
1 files changed, 227 insertions, 218 deletions
diff --git a/src/modules/button/button.cpp b/src/modules/button/button.cpp
index 66aafc243c..1c6bd79980 100644
--- a/src/modules/button/button.cpp
+++ b/src/modules/button/button.cpp
@@ -24,77 +24,42 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <initguid.h>
#include <oleacc.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;
- HTHEME hThemeButton;
- HTHEME hThemeToolbar;
- char cHot;
- int flatBtn;
- HWND hwndToolTips;
+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;
+ HBITMAP hBitmap;
+ int pushBtn;
+ int pbState;
+ HTHEME hThemeButton;
+ HTHEME hThemeToolbar;
+ TCHAR cHot;
+ int flatBtn;
+ HWND hwndToolTips;
IAccPropServices* pAccPropServices;
-} MButtonCtrl;
-
+};
-static CRITICAL_SECTION csTips;
-static SortedList lToolTips;
-static BOOL bModuleInitialized = FALSE;
-
-typedef struct
+struct TTooltips
{
DWORD ThreadId;
HWND hwnd;
-} TTooltips;
-
-int LoadButtonModule(void)
-{
- WNDCLASSEX wc = {0};
+};
- if ( bModuleInitialized ) return 0;
- bModuleInitialized = TRUE;
-
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = MIRANDABUTTONCLASS;
- wc.lpfnWndProc = MButtonWndProc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.cbWndExtra = sizeof(MButtonCtrl*);
- wc.hbrBackground = 0;
- wc.style = CS_GLOBALCLASS;
- RegisterClassEx(&wc);
-
- InitializeCriticalSection(&csTips);
- lToolTips.increment = 1;
- lToolTips.sortFunc = NumericKeySort;
- return 0;
-}
-
-void UnloadButtonModule()
-{
- if ( !bModuleInitialized ) return;
- EnterCriticalSection(&csTips);
- List_Destroy(&lToolTips);
- LeaveCriticalSection(&csTips);
- DeleteCriticalSection(&csTips);
-}
+static LIST<TTooltips> lToolTips(1, (LIST<TTooltips>::FTSortFunc)NumericKeySort);
+static CRITICAL_SECTION csTips;
+static BOOL bModuleInitialized = FALSE;
// Used for our own cheap TrackMouseEvent
#define BUTTON_POLLID 100
#define BUTTON_POLLDELAY 50
-static void DestroyTheme(MButtonCtrl *ctl) {
+static void DestroyTheme(MButtonCtrl *ctl)
+{
if (closeThemeData) {
if (ctl->hThemeButton) {
closeThemeData(ctl->hThemeButton);
@@ -124,6 +89,7 @@ static void SetHwndPropInt(MButtonCtrl* bct, DWORD idObject, DWORD idChild, MSAA
var.lVal = val;
bct->pAccPropServices->SetHwndProp(bct->hwnd, idObject, idChild, idProp, var);
}
+
static int TBStateConvert2Flat(int state)
{
switch(state) {
@@ -140,149 +106,155 @@ static int TBStateConvert2Flat(int state)
#define DFCS_HOT 0x1000
#endif
+///////////////////////////////////////////////////////////////////////////////
+// Button painter
+
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 = ( 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) {
- int state = IsWindowEnabled(ctl->hwnd)?(ctl->stateId==PBS_NORMAL&&ctl->defbutton?PBS_DEFAULTED:ctl->stateId):PBS_DISABLED;
- if (isThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
- drawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient);
- }
- drawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rcClient, &rcClient);
- }
- else {
- HBRUSH hbr;
+ if (!hdcPaint)
+ return;
- if (ctl->stateId==PBS_PRESSED||ctl->stateId==PBS_HOT)
- hbr = GetSysColorBrush(COLOR_3DLIGHT);
- else {
- HWND hwndParent = GetParent(ctl->hwnd);
- HDC dc = GetDC(hwndParent);
- HBRUSH oldBrush = (HBRUSH)GetCurrentObject( dc, OBJ_BRUSH );
- hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent);
- SelectObject(dc,oldBrush);
- ReleaseDC(hwndParent,dc);
- }
- if (hbr) {
- FillRect(hdcMem, &rcClient, hbr);
- DeleteObject(hbr);
- }
- if (ctl->stateId==PBS_HOT||ctl->focus) {
- if (ctl->pbState)
- DrawEdge(hdcMem,&rcClient, EDGE_ETCHED,BF_RECT|BF_SOFT);
- else DrawEdge(hdcMem,&rcClient, BDR_RAISEDOUTER,BF_RECT|BF_SOFT|BF_FLAT);
- }
- else if (ctl->stateId==PBS_PRESSED)
- DrawEdge(hdcMem, &rcClient, BDR_SUNKENOUTER,BF_RECT|BF_SOFT);
+ 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 = ( 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) {
+ int state = IsWindowEnabled(ctl->hwnd)?(ctl->stateId == PBS_NORMAL&&ctl->defbutton?PBS_DEFAULTED:ctl->stateId):PBS_DISABLED;
+ if (isThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
+ drawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient);
}
+ drawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rcClient, &rcClient);
}
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 (isThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
- drawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient);
- }
- drawThemeBackground(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);
- }
+ HBRUSH hbr;
- // Draw focus rectangle if button has focus
- if (ctl->focus) {
- RECT focusRect = rcClient;
- InflateRect(&focusRect, -3, -3);
- DrawFocusRect(hdcMem, &focusRect);
+ if (ctl->stateId == PBS_PRESSED||ctl->stateId == PBS_HOT)
+ hbr = GetSysColorBrush(COLOR_3DLIGHT);
+ else {
+ HWND hwndParent = GetParent(ctl->hwnd);
+ HDC dc = GetDC(hwndParent);
+ HBRUSH oldBrush = (HBRUSH)GetCurrentObject( dc, OBJ_BRUSH );
+ hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent);
+ SelectObject(dc,oldBrush);
+ ReleaseDC(hwndParent,dc);
}
- }
-
- // 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++;
+ if (hbr) {
+ FillRect(hdcMem, &rcClient, hbr);
+ DeleteObject(hbr);
}
- {
- 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);
+ if (ctl->stateId == PBS_HOT||ctl->focus) {
+ if (ctl->pbState)
+ DrawEdge(hdcMem,&rcClient, EDGE_ETCHED,BF_RECT|BF_SOFT);
+ else DrawEdge(hdcMem,&rcClient, BDR_RAISEDOUTER,BF_RECT|BF_SOFT|BF_FLAT);
}
+ else if (ctl->stateId == PBS_PRESSED)
+ DrawEdge(hdcMem, &rcClient, BDR_SUNKENOUTER,BF_RECT|BF_SOFT);
}
- 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++;
+ }
+ 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 (isThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
+ drawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient);
}
- DrawState(hdcMem,NULL,NULL,(LPARAM)ctl->hBitmap,0,ix,iy,bminfo.bmWidth,bminfo.bmHeight,IsWindowEnabled(ctl->hwnd)?DST_BITMAP:DST_BITMAP|DSS_DISABLED);
+ drawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, &rcClient, &rcClient);
}
- else if (GetWindowTextLength(ctl->hwnd)) {
- // Draw the text and optinally the arrow
- TCHAR szText[MAX_PATH];
- SIZE sz;
- RECT rcText;
- HFONT hOldFont;
-
- CopyRect(&rcText, &rcClient);
- GetWindowText(ctl->hwnd, szText, SIZEOF(szText));
- SetBkMode(hdcMem, TRANSPARENT);
- 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);
- if (ctl->cHot) {
- SIZE szHot;
-
- GetTextExtentPoint32 (hdcMem, _T("&"), 1, &szHot);
- sz.cx -= szHot.cx;
- }
- if (ctl->arrow) {
- DrawState(hdcMem,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(hdcMem, ctl->hFont);
- DrawState(hdcMem,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);
- SelectObject(hdcMem, hOldFont);
+ 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);
}
- BitBlt(hdcPaint, 0, 0, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top, hdcMem, 0, 0, SRCCOPY);
- SelectObject(hdcMem, hOld);
- DeleteObject(hbmMem);
- DeleteDC(hdcMem);
+ // 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) {
+ 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++;
+ }
+ {
+ 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);
+ }
+ }
+ 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);
}
+ else if (GetWindowTextLength(ctl->hwnd)) {
+ // Draw the text and optinally the arrow
+ TCHAR szText[MAX_PATH];
+ SIZE sz;
+ RECT rcText;
+ HFONT hOldFont;
+
+ CopyRect(&rcText, &rcClient);
+ GetWindowText(ctl->hwnd, szText, SIZEOF(szText));
+ SetBkMode(hdcMem, TRANSPARENT);
+ 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);
+ if (ctl->cHot) {
+ SIZE szHot;
+
+ GetTextExtentPoint32 (hdcMem, _T("&"), 1, &szHot);
+ sz.cx -= szHot.cx;
+ }
+ if (ctl->arrow) {
+ DrawState(hdcMem,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(hdcMem, ctl->hFont);
+ DrawState(hdcMem,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);
+ 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);
}
+///////////////////////////////////////////////////////////////////////////////
+// Button's window procedure
+
static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
MButtonCtrl* bct = (MButtonCtrl *)GetWindowLongPtr(hwndDlg, 0);
@@ -290,14 +262,12 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
case WM_NCCREATE:
SetWindowLongPtr(hwndDlg, GWL_STYLE, GetWindowLongPtr(hwndDlg, GWL_STYLE) | BS_OWNERDRAW);
bct = ( MButtonCtrl* )mir_calloc(sizeof(MButtonCtrl));
- if (bct==NULL) return FALSE;
+ if (bct == NULL) return FALSE;
bct->hwnd = hwndDlg;
bct->stateId = PBS_NORMAL;
bct->hFont = ( HFONT )GetStockObject(DEFAULT_GUI_FONT);
LoadTheme(bct);
- if (SUCCEEDED(CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER,
- IID_IAccPropServices, (void**)&bct->pAccPropServices)))
- {
+ if (SUCCEEDED(CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, IID_IAccPropServices, (void**)&bct->pAccPropServices))) {
// Annotating the Role of this object to be PushButton
SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_PUSHBUTTON);
}
@@ -326,16 +296,16 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
int idx;
TTooltips tt;
tt.ThreadId = GetCurrentThreadId();
-
- EnterCriticalSection(&csTips);
- if ( List_GetIndex( &lToolTips, &tt, &idx ) ) {
- mir_free( lToolTips.items[idx] );
- List_Remove( &lToolTips, idx );
- DestroyWindow( bct->hwndToolTips );
+
+ EnterCriticalSection(&csTips);
+ if (( idx = lToolTips.getIndex(&tt)) != -1) {
+ mir_free( lToolTips[idx] );
+ lToolTips.remove(idx);
+ DestroyWindow(bct->hwndToolTips);
}
- LeaveCriticalSection(&csTips);
-
- bct->hwndToolTips = NULL;
+ LeaveCriticalSection(&csTips);
+
+ bct->hwndToolTips = NULL;
}
}
if (bct->arrow) IconLib_ReleaseIcon(bct->arrow, 0);
@@ -352,7 +322,7 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
if ( lParam != 0 ) {
TCHAR *tmp = ( TCHAR* )lParam;
while (*tmp) {
- if (*tmp=='&' && *(tmp+1)) {
+ if (*tmp == '&' && *(tmp+1)) {
bct->cHot = _tolower(*(tmp+1));
break;
}
@@ -363,7 +333,7 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
break;
case WM_KEYUP:
- if (bct->stateId!=PBS_DISABLED && wParam == VK_SPACE) {
+ if (bct->stateId != PBS_DISABLED && wParam == VK_SPACE) {
if (bct->pushBtn) {
if (bct->pbState) {
bct->pbState = 0;
@@ -381,7 +351,7 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
break;
case WM_SYSKEYUP:
- if (bct->stateId!=PBS_DISABLED && bct->cHot && bct->cHot == tolower((int)wParam)) {
+ if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == tolower((int)wParam)) {
if (bct->pushBtn) {
if (bct->pbState) {
bct->pbState = 0;
@@ -412,9 +382,7 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
case WM_PAINT:
{
PAINTSTRUCT ps;
- HDC hdcPaint;
-
- hdcPaint = BeginPaint(hwndDlg, &ps);
+ HDC hdcPaint = BeginPaint(hwndDlg, &ps);
if (hdcPaint) {
PaintWorker(bct, hdcPaint);
EndPaint(hwndDlg, &ps);
@@ -443,15 +411,16 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
if (bct->hIcon) return (LRESULT)bct->hIcon;
else if (bct->hBitmap) return (LRESULT)bct->hBitmap;
else return 0;
+
case BM_SETCHECK:
if (!bct->pushBtn) break;
if (wParam == BST_CHECKED) {
bct->pbState = 1;
- bct->stateId = PBS_PRESSED;
+ bct->stateId = PBS_PRESSED;
}
else if (wParam == BST_UNCHECKED) {
bct->pbState = 0;
- bct->stateId = PBS_NORMAL;
+ bct->stateId = PBS_NORMAL;
}
InvalidateRect(bct->hwnd, NULL, TRUE);
break;
@@ -476,18 +445,22 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
}
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 ) {
TOOLINFO ti = {0};
@@ -495,18 +468,18 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
int idx;
TTooltips tt;
tt.ThreadId = GetCurrentThreadId();
-
- EnterCriticalSection(&csTips);
- if ( List_GetIndex( &lToolTips, &tt, &idx )) {
- bct->hwndToolTips = ((TTooltips*)lToolTips.items[idx])->hwnd;
- } else {
+
+ EnterCriticalSection(&csTips);
+ if (( idx = lToolTips.getIndex(&tt)) != -1)
+ bct->hwndToolTips = lToolTips[idx]->hwnd;
+ else {
TTooltips *ptt = ( TTooltips* )mir_alloc( sizeof(TTooltips) );
ptt->ThreadId = tt.ThreadId;
ptt->hwnd = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), TTS_ALWAYSTIP, 0, 0, 0, 0, NULL, NULL, hMirandaInst, NULL);
- List_Insert( &lToolTips, ptt, idx );
+ lToolTips.insert(ptt, idx);
bct->hwndToolTips = ptt->hwnd;
}
- LeaveCriticalSection(&csTips);
+ LeaveCriticalSection(&csTips);
}
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_IDISHWND;
@@ -556,14 +529,14 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
break;
case WM_MOUSELEAVE: // faked by the WM_TIMER
- if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
+ 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
+ if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
bct->stateId = PBS_PRESSED;
InvalidateRect(bct->hwnd, NULL, TRUE);
}
@@ -576,10 +549,10 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
if (bct->pbState) bct->pbState = 0;
else bct->pbState = 1;
}
- if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
- if (bct->stateId==PBS_PRESSED)
+ if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
+ if (bct->stateId == PBS_PRESSED)
showClick = 1;
- if (msg==WM_LBUTTONUP) bct->stateId = PBS_HOT;
+ if (msg == WM_LBUTTONUP) bct->stateId = PBS_HOT;
else bct->stateId = PBS_NORMAL;
InvalidateRect(bct->hwnd, NULL, TRUE);
}
@@ -612,3 +585,39 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
}
return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
+
+///////////////////////////////////////////////////////////////////////////////
+// Module load
+
+int LoadButtonModule(void)
+{
+ WNDCLASSEX wc = {0};
+
+ if ( bModuleInitialized ) return 0;
+ bModuleInitialized = TRUE;
+
+ wc.cbSize = sizeof(wc);
+ wc.lpszClassName = MIRANDABUTTONCLASS;
+ wc.lpfnWndProc = MButtonWndProc;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.cbWndExtra = sizeof(MButtonCtrl*);
+ wc.hbrBackground = 0;
+ wc.style = CS_GLOBALCLASS;
+ RegisterClassEx(&wc);
+
+ InitializeCriticalSection(&csTips);
+ return 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Module unload
+
+void UnloadButtonModule()
+{
+ if ( bModuleInitialized ) {
+ EnterCriticalSection(&csTips);
+ lToolTips.destroy();
+ LeaveCriticalSection(&csTips);
+ DeleteCriticalSection(&csTips);
+ }
+}