summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2016-06-15 10:24:12 +0000
committerGeorge Hazan <george.hazan@gmail.com>2016-06-15 10:24:12 +0000
commitd7c8421febc417a767fe74afa3a4a22c9bc55b70 (patch)
tree4fe6ee1786b2fd4f83c6d0c1d5850d228a426faf /src
parent0a32217a1a246c5f05c7b492c2d34276ad95969f (diff)
fixes #1253 (ModernOpt: crash after plugin enable)
git-svn-id: http://svn.miranda-ng.org/main/trunk@16977 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/iconheader.cpp180
1 files changed, 91 insertions, 89 deletions
diff --git a/src/mir_app/src/iconheader.cpp b/src/mir_app/src/iconheader.cpp
index be9b55a6b8..48c1c97cb0 100644
--- a/src/mir_app/src/iconheader.cpp
+++ b/src/mir_app/src/iconheader.cpp
@@ -44,46 +44,44 @@ static BOOL IsVSMode()
#define ITC_BORDER_SIZE 3
-static LRESULT CALLBACK MIcoTabWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-
// structure is used for storing list of tab info
struct MIcoTabCtrl : public MZeroedObject
{
- MIcoTabCtrl(): pList(1) {}
+ MIcoTabCtrl() : pList(1) {}
- HWND hwnd;
- int nSelectedIdx, nHotIdx;
+ HWND hwnd;
+ int nSelectedIdx, nHotIdx;
LIST<MIcoTab> pList;
// UI info
- BOOL bMouseInside;
- RECT rc;
- int width, height;
- int itemWidth, itemHeight;
+ BOOL bMouseInside;
+ RECT rc;
+ int width, height;
+ int itemWidth, itemHeight;
//background bitmap
- HBITMAP hBkgBmp;
- HBITMAP hBkgOldBmp;
- HDC hBkgDC;
- SIZE BkgSize;
+ HBITMAP hBkgBmp;
+ HBITMAP hBkgOldBmp;
+ HDC hBkgDC;
+ SIZE BkgSize;
// control colors
- RGBQUAD rgbBkgTop, rgbBkgBottom;
- RGBQUAD rgbSelTop, rgbSelBottom;
- RGBQUAD rgbHotTop, rgbHotBottom;
- COLORREF clText;
- COLORREF clSelText, clSelBorder;
- COLORREF clHotText, clHotBorder;
+ RGBQUAD rgbBkgTop, rgbBkgBottom;
+ RGBQUAD rgbSelTop, rgbSelBottom;
+ RGBQUAD rgbHotTop, rgbHotBottom;
+ COLORREF clText;
+ COLORREF clSelText, clSelBorder;
+ COLORREF clHotText, clHotBorder;
// fonts
- HFONT hFont;
+ HFONT hFont;
};
typedef void (*ItemDestuctor)(void*);
static void MITListDestructor(void * adr)
{
- MIcoTab * mit = (MIcoTab *)adr;
+ MIcoTab *mit = (MIcoTab *)adr;
mir_free(mit->tcsName);
if (mit->hIcon && !(mit->flag&MITCF_SHAREDICON))
DestroyIcon(mit->hIcon);
@@ -92,63 +90,45 @@ static void MITListDestructor(void * adr)
void li_ListDestruct(LIST<MIcoTab> &pList, ItemDestuctor pItemDestructor)
{
- for (int i=0; i<pList.getCount(); i++) pItemDestructor(pList[i]);
+ for (int i = 0; i < pList.getCount(); i++) pItemDestructor(pList[i]);
pList.destroy();
}
-int LoadIcoTabsModule()
-{
- WNDCLASSEX wc;
-
- memset(&wc, 0, sizeof(wc));
- wc.cbSize = sizeof(wc);
- wc.lpszClassName = MIRANDAICOTABCLASS;
- wc.lpfnWndProc = MIcoTabWndProc;
-// wc.hCursor = LoadCursor(NULL, IDC_HAND);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.cbWndExtra = sizeof(MIcoTabCtrl*);
- wc.hbrBackground = 0; //GetStockObject(WHITE_BRUSH);
- wc.style = CS_GLOBALCLASS/*|CS_SAVEBITS*/;
- RegisterClassEx(&wc);
- return 0;
-}
-
static void MIcoTab_SetupColors(MIcoTabCtrl *dat)
{
- COLORREF cl;
-
- cl = GetSysColor(COLOR_WINDOW);
- dat->rgbBkgBottom.rgbRed = (dat->rgbBkgTop.rgbRed = GetRValue(cl)) * .95;
- dat->rgbBkgBottom.rgbGreen = (dat->rgbBkgTop.rgbGreen = GetGValue(cl)) * .95;
- dat->rgbBkgBottom.rgbBlue = (dat->rgbBkgTop.rgbBlue = GetBValue(cl)) * .95;
+ COLORREF cl = GetSysColor(COLOR_WINDOW);
+ dat->rgbBkgBottom.rgbRed = (dat->rgbBkgTop.rgbRed = GetRValue(cl)) * .95;
+ dat->rgbBkgBottom.rgbGreen = (dat->rgbBkgTop.rgbGreen = GetGValue(cl)) * .95;
+ dat->rgbBkgBottom.rgbBlue = (dat->rgbBkgTop.rgbBlue = GetBValue(cl)) * .95;
cl = GetSysColor(COLOR_HIGHLIGHT);
- dat->rgbSelTop.rgbRed = (dat->rgbSelBottom.rgbRed = GetRValue(cl)) * .75;
- dat->rgbSelTop.rgbGreen = (dat->rgbSelBottom.rgbGreen = GetGValue(cl)) * .75;
- dat->rgbSelTop.rgbBlue = (dat->rgbSelBottom.rgbBlue = GetBValue(cl)) * .75;
+ dat->rgbSelTop.rgbRed = (dat->rgbSelBottom.rgbRed = GetRValue(cl)) * .75;
+ dat->rgbSelTop.rgbGreen = (dat->rgbSelBottom.rgbGreen = GetGValue(cl)) * .75;
+ dat->rgbSelTop.rgbBlue = (dat->rgbSelBottom.rgbBlue = GetBValue(cl)) * .75;
- dat->rgbHotTop.rgbRed = (dat->rgbSelTop.rgbRed + 255) / 2;
- dat->rgbHotTop.rgbGreen = (dat->rgbSelTop.rgbGreen + 255) / 2;
- dat->rgbHotTop.rgbBlue = (dat->rgbSelTop.rgbBlue + 255) / 2;
+ dat->rgbHotTop.rgbRed = (dat->rgbSelTop.rgbRed + 255) / 2;
+ dat->rgbHotTop.rgbGreen = (dat->rgbSelTop.rgbGreen + 255) / 2;
+ dat->rgbHotTop.rgbBlue = (dat->rgbSelTop.rgbBlue + 255) / 2;
- dat->rgbHotBottom.rgbRed = (dat->rgbSelBottom.rgbRed + 255) / 2;
- dat->rgbHotBottom.rgbGreen = (dat->rgbSelBottom.rgbGreen + 255) / 2;
- dat->rgbHotBottom.rgbBlue = (dat->rgbSelBottom.rgbBlue + 255) / 2;
+ dat->rgbHotBottom.rgbRed = (dat->rgbSelBottom.rgbRed + 255) / 2;
+ dat->rgbHotBottom.rgbGreen = (dat->rgbSelBottom.rgbGreen + 255) / 2;
+ dat->rgbHotBottom.rgbBlue = (dat->rgbSelBottom.rgbBlue + 255) / 2;
- dat->clText = GetSysColor(COLOR_WINDOWTEXT);
- dat->clSelText = GetSysColor(COLOR_HIGHLIGHTTEXT);
- dat->clSelBorder = RGB(dat->rgbSelTop.rgbRed, dat->rgbSelTop.rgbGreen, dat->rgbSelTop.rgbBlue);
- dat->clHotBorder = RGB(dat->rgbHotTop.rgbRed, dat->rgbHotTop.rgbGreen, dat->rgbHotTop.rgbBlue);
+ dat->clText = GetSysColor(COLOR_WINDOWTEXT);
+ dat->clSelText = GetSysColor(COLOR_HIGHLIGHTTEXT);
+ dat->clSelBorder = RGB(dat->rgbSelTop.rgbRed, dat->rgbSelTop.rgbGreen, dat->rgbSelTop.rgbBlue);
+ dat->clHotBorder = RGB(dat->rgbHotTop.rgbRed, dat->rgbHotTop.rgbGreen, dat->rgbHotTop.rgbBlue);
- if (!dat->hFont) dat->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+ if (!dat->hFont)
+ dat->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
}
static void MIcoTab_FillRect(HDC hdc, int x, int y, int width, int height, COLORREF cl)
{
- int oldMode = SetBkMode(hdc, OPAQUE);
- COLORREF oldColor = SetBkColor(hdc, cl);
+ int oldMode = SetBkMode(hdc, OPAQUE);
+ COLORREF oldColor = SetBkColor(hdc, cl);
- RECT rc; SetRect(&rc, x, y, x+width, y+height);
+ RECT rc; SetRect(&rc, x, y, x + width, y + height);
ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, "", 0, 0);
SetBkMode(hdc, oldMode);
@@ -157,15 +137,17 @@ static void MIcoTab_FillRect(HDC hdc, int x, int y, int width, int height, COLOR
static void MIcoTab_DrawGradient(HDC hdc, int x, int y, int width, int height, RGBQUAD *rgb0, RGBQUAD *rgb1)
{
- int oldMode = SetBkMode(hdc, OPAQUE);
- COLORREF oldColor = SetBkColor(hdc, 0);
+ int oldMode = SetBkMode(hdc, OPAQUE);
+ COLORREF oldColor = SetBkColor(hdc, 0);
- RECT rc; SetRect(&rc, x, 0, x+width, 0);
- for (int i = y+height; --i >= y;) {
+ RECT rc;
+ SetRect(&rc, x, 0, x + width, 0);
+
+ for (int i = y + height; --i >= y;) {
COLORREF color = RGB(
- ((height-i-1)*rgb0->rgbRed + i*rgb1->rgbRed) / height,
- ((height-i-1)*rgb0->rgbGreen + i*rgb1->rgbGreen) / height,
- ((height-i-1)*rgb0->rgbBlue + i*rgb1->rgbBlue) / height);
+ ((height - i - 1)*rgb0->rgbRed + i*rgb1->rgbRed) / height,
+ ((height - i - 1)*rgb0->rgbGreen + i*rgb1->rgbGreen) / height,
+ ((height - i - 1)*rgb0->rgbBlue + i*rgb1->rgbBlue) / height);
rc.top = rc.bottom = i;
++rc.bottom;
SetBkColor(hdc, color);
@@ -179,9 +161,9 @@ static void MIcoTab_DrawGradient(HDC hdc, int x, int y, int width, int height, R
static void MIcoTab_DrawItem(HWND hwnd, HDC hdc, MIcoTabCtrl *dat, MIcoTab *tab, int i)
{
int iTopSpace = IsAeroMode() ? 0 : ITC_BORDER_SIZE;
- int itemX = ITC_BORDER_SIZE + dat->itemWidth * i;
- int iconTop = iTopSpace + 5;
- int textTop = iconTop + 32 + 3;
+ int itemX = ITC_BORDER_SIZE + dat->itemWidth * i;
+ int iconTop = iTopSpace + 5;
+ int textTop = iconTop + 32 + 3;
HFONT hFntSave = NULL;
@@ -207,7 +189,7 @@ static void MIcoTab_DrawItem(HWND hwnd, HDC hdc, MIcoTabCtrl *dat, MIcoTab *tab,
}
else {
MIcoTab_FillRect(hdc, itemX, ITC_BORDER_SIZE, dat->itemWidth, dat->itemHeight, dat->clSelBorder);
- MIcoTab_DrawGradient(hdc, itemX+1, ITC_BORDER_SIZE+1, dat->itemWidth-2, dat->itemHeight-2, &dat->rgbSelTop, &dat->rgbSelBottom);
+ MIcoTab_DrawGradient(hdc, itemX + 1, ITC_BORDER_SIZE + 1, dat->itemWidth - 2, dat->itemHeight - 2, &dat->rgbSelTop, &dat->rgbSelBottom);
}
SetTextColor(hdc, dat->clSelText);
}
@@ -225,7 +207,7 @@ static void MIcoTab_DrawItem(HWND hwnd, HDC hdc, MIcoTabCtrl *dat, MIcoTab *tab,
}
else {
MIcoTab_FillRect(hdc, itemX, ITC_BORDER_SIZE, dat->itemWidth, dat->itemHeight, dat->clHotBorder);
- MIcoTab_DrawGradient(hdc, itemX+1, ITC_BORDER_SIZE+1, dat->itemWidth-2, dat->itemHeight-2, &dat->rgbHotTop, &dat->rgbHotBottom);
+ MIcoTab_DrawGradient(hdc, itemX + 1, ITC_BORDER_SIZE + 1, dat->itemWidth - 2, dat->itemHeight - 2, &dat->rgbHotTop, &dat->rgbHotBottom);
}
SetTextColor(hdc, dat->clHotText);
}
@@ -233,23 +215,23 @@ static void MIcoTab_DrawItem(HWND hwnd, HDC hdc, MIcoTabCtrl *dat, MIcoTab *tab,
RECT textRect;
textRect.left = itemX;
- textRect.right = itemX+dat->itemWidth;
+ textRect.right = itemX + dat->itemWidth;
textRect.top = textTop;
- textRect.bottom = iconTop+dat->itemHeight;
- DrawIcon(hdc, itemX+dat->itemWidth/2-16, iconTop, tab->hIcon);
+ textRect.bottom = iconTop + dat->itemHeight;
+ DrawIcon(hdc, itemX + dat->itemWidth / 2 - 16, iconTop, tab->hIcon);
if (IsVSMode()) {
- DTTOPTS dto = {0};
+ DTTOPTS dto = { 0 };
dto.dwSize = sizeof(dto);
- dto.dwFlags = DTT_COMPOSITED|DTT_GLOWSIZE;
+ dto.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
dto.iGlowSize = 10;
HANDLE hTheme = OpenThemeData(hwnd, L"Window");
wchar_t *tcsNameW = mir_t2u(tab->tcsName);
- drawThemeTextEx(hTheme, hdc, WP_CAPTION, CS_ACTIVE, tcsNameW, -1, DT_VCENTER|DT_CENTER|DT_END_ELLIPSIS, &textRect, &dto);
+ drawThemeTextEx(hTheme, hdc, WP_CAPTION, CS_ACTIVE, tcsNameW, -1, DT_VCENTER | DT_CENTER | DT_END_ELLIPSIS, &textRect, &dto);
mir_free(tcsNameW);
CloseThemeData(hTheme);
}
- else DrawText(hdc, tab->tcsName, -1, &textRect, DT_VCENTER|DT_CENTER|DT_END_ELLIPSIS);
+ else DrawText(hdc, tab->tcsName, -1, &textRect, DT_VCENTER | DT_CENTER | DT_END_ELLIPSIS);
if (hFntSave)
DeleteObject(SelectObject(hdc, hFntSave));
@@ -290,8 +272,8 @@ static LRESULT MIcoTab_OnPaint(HWND hwndDlg, MIcoTabCtrl *mit)
else
MIcoTab_DrawGradient(tempDC, 0, 0, mit->width, mit->height, &mit->rgbBkgTop, &mit->rgbBkgBottom);
- MIcoTab_FillRect(tempDC, 0, mit->height-2, mit->width, 1, GetSysColor(COLOR_BTNSHADOW));
- MIcoTab_FillRect(tempDC, 0, mit->height-1, mit->width, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
+ MIcoTab_FillRect(tempDC, 0, mit->height - 2, mit->width, 1, GetSysColor(COLOR_BTNSHADOW));
+ MIcoTab_FillRect(tempDC, 0, mit->height - 1, mit->width, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
}
}
@@ -300,7 +282,7 @@ static LRESULT MIcoTab_OnPaint(HWND hwndDlg, MIcoTabCtrl *mit)
HFONT hOldFont = (HFONT)SelectObject(tempDC, hFont);
SetBkMode(tempDC, TRANSPARENT);
- for (int i=0; i<mit->pList.getCount(); i++) {
+ for (int i = 0; i < mit->pList.getCount(); i++) {
MIcoTab *tab = (MIcoTab *)mit->pList[i];
MIcoTab_DrawItem(hwndDlg, tempDC, mit, tab, i);
}
@@ -309,7 +291,7 @@ static LRESULT MIcoTab_OnPaint(HWND hwndDlg, MIcoTabCtrl *mit)
BitBlt(hdc, mit->rc.left, mit->rc.top, mit->width, mit->height, tempDC, 0, 0, SRCCOPY);
SelectObject(tempDC, hOldBmp);
DeleteObject(hBmp);
- SelectObject(tempDC,hOldFont);
+ SelectObject(tempDC, hOldFont);
DeleteDC(tempDC);
EndPaint(hwndDlg, &ps);
@@ -330,7 +312,9 @@ static LRESULT CALLBACK MIcoTabWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
MIcoTab_SetupColors(itc);
if (IsAeroMode()) {
- RECT rc; GetWindowRect(hwndDlg, &rc);
+ RECT rc;
+ GetWindowRect(hwndDlg, &rc);
+
MARGINS margins = { 0, 0, rc.bottom - rc.top, 0 };
dwmExtendFrameIntoClientArea(GetParent(hwndDlg), &margins);
}
@@ -368,9 +352,12 @@ static LRESULT CALLBACK MIcoTabWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
itc->bMouseInside = TRUE;
}
- itc->nHotIdx = (LOWORD(lParam) - ITC_BORDER_SIZE) / itc->itemWidth;
- if (itc->nHotIdx >= itc->pList.getCount())
- itc->nHotIdx = -1;
+ itc->nHotIdx = -1;
+ if (itc->itemWidth != 0) {
+ int idx = (LOWORD(lParam) - ITC_BORDER_SIZE) / itc->itemWidth;
+ if (idx >= itc->pList.getCount())
+ itc->nHotIdx = idx;
+ }
RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE);
return 0;
@@ -524,3 +511,18 @@ static LRESULT CALLBACK MIcoTabWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, L
}
return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+int LoadIcoTabsModule()
+{
+ WNDCLASSEX wc = {};
+ wc.cbSize = sizeof(wc);
+ wc.lpszClassName = MIRANDAICOTABCLASS;
+ wc.lpfnWndProc = MIcoTabWndProc;
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.cbWndExtra = sizeof(MIcoTabCtrl*);
+ wc.style = CS_GLOBALCLASS;
+ RegisterClassEx(&wc);
+ return 0;
+}