summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/colorchooser.cpp415
1 files changed, 205 insertions, 210 deletions
diff --git a/src/mir_app/src/colorchooser.cpp b/src/mir_app/src/colorchooser.cpp
index d719826d43..f414bec570 100644
--- a/src/mir_app/src/colorchooser.cpp
+++ b/src/mir_app/src/colorchooser.cpp
@@ -24,261 +24,256 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "chat.h"
-struct COLORCHOOSER
+class CColorChooserDlg : public CDlgBase
{
- MODULEINFO *pModule;
- int xPosition, yPosition;
- HWND hWndTarget, hWndChooser;
- BOOL bForeground;
- GCSessionInfoBase *si;
-};
+ CCtrlBase m_text;
-static int CalculateCoordinatesToButton(COLORCHOOSER * pCC, POINT pt)
-{
- int iSquareRoot = (int)sqrt(static_cast<float>(pCC->pModule->nColorCount));
- int nCols = iSquareRoot * iSquareRoot < pCC->pModule->nColorCount ? iSquareRoot + 1 : iSquareRoot;
+ GCSessionInfoBase *m_si;
+ MODULEINFO *m_pModule;
- int col = pt.x / 25;
- int row = (pt.y - 20) / 20;
- int pos = nCols * row + col;
+ int m_xPosition, m_yPosition;
+ int iCurrentHotTrack, iRows, iColumns;
+ HWND m_hwndTarget, m_hwndChooser, hwndPreviousActiveWindow;
+ BOOL m_bForeground, bChoosing;
- if (pt.y < 20 && pos >= pCC->pModule->nColorCount)
- pos = -1;
+ int CalculateCoordinatesToButton(POINT pt)
+ {
+ int iSquareRoot = (int)sqrt(static_cast<float>(m_pModule->nColorCount));
+ int nCols = iSquareRoot * iSquareRoot < m_pModule->nColorCount ? iSquareRoot + 1 : iSquareRoot;
- return pos;
-}
+ int col = pt.x / 25;
+ int row = (pt.y - 20) / 20;
+ int pos = nCols * row + col;
-static RECT CalculateButtonToCoordinates(COLORCHOOSER * pCC, int buttonPosition)
-{
- int iSquareRoot = (int)sqrt(static_cast<float>(pCC->pModule->nColorCount));
- int nCols = iSquareRoot * iSquareRoot < pCC->pModule->nColorCount ? iSquareRoot + 1 : iSquareRoot;
+ if (pt.y < 20 && pos >= m_pModule->nColorCount)
+ pos = -1;
- int row = buttonPosition / nCols;
- int col = buttonPosition % nCols;
+ return pos;
+ }
- RECT pt;
- pt.left = col * 25 + 1;
- pt.top = row * 20 + 20;
- pt.right = pt.left + 25 - 1;
- pt.bottom = pt.top + 20;
+ RECT CalculateButtonToCoordinates(int buttonPosition)
+ {
+ int iSquareRoot = (int)sqrt(static_cast<float>(m_pModule->nColorCount));
+ int nCols = iSquareRoot * iSquareRoot < m_pModule->nColorCount ? iSquareRoot + 1 : iSquareRoot;
- return pt;
-}
+ int row = buttonPosition / nCols;
+ int col = buttonPosition % nCols;
-static INT_PTR CALLBACK DlgProcColorToolWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- static COLORCHOOSER* pCC = NULL;
- static int iCurrentHotTrack;
- static BOOL bChoosing;
- static int iRows;
- static int iColumns;
- static HWND hPreviousActiveWindow;
+ RECT pt;
+ pt.left = col * 25 + 1;
+ pt.top = row * 20 + 20;
+ pt.right = pt.left + 25 - 1;
+ pt.bottom = pt.top + 20;
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- {
- pCC = (COLORCHOOSER*) lParam;
+ return pt;
+ }
- iCurrentHotTrack = -2;
- bChoosing = FALSE;
+public:
+ CColorChooserDlg(SESSION_INFO *si, BOOL bFG, HWND hwndDlg, HWND hwndTarget, HWND hwndChooser) :
+ CDlgBase(g_hInst, IDD_COLORCHOOSER),
+ m_text(this, IDC_COLORTEXT),
+ iCurrentHotTrack(-2),
+ bChoosing(false)
+ {
+ RECT rc;
+ GetWindowRect(hwndChooser, &rc);
+
+ m_hwndParent = hwndDlg;
+ m_hwndTarget = hwndTarget;
+ m_pModule = chatApi.MM_FindModule(si->pszModule);
+ m_xPosition = rc.left + 3;
+ m_yPosition = IsWindowVisible(hwndChooser) ? rc.top - 1 : rc.top + 20;
+ m_bForeground = bFG;
+ m_hwndChooser = hwndChooser;
+ m_si = si;
+ }
- int iSquareRoot = (int)sqrt(static_cast<float>(pCC->pModule->nColorCount));
+ virtual void OnInitDialog() override
+ {
+ int iSquareRoot = (int)sqrt(static_cast<float>(m_pModule->nColorCount));
- iColumns = iSquareRoot * iSquareRoot == pCC->pModule->nColorCount ? iSquareRoot : iSquareRoot + 1;
- iRows = iSquareRoot;
+ iColumns = iSquareRoot * iSquareRoot == m_pModule->nColorCount ? iSquareRoot : iSquareRoot + 1;
+ iRows = iSquareRoot;
- RECT rc;
- rc.top = rc.left = 100;
- rc.right = 100 + iColumns * 25 + 1;
- rc.bottom = iRows * 20 + 100 + 20;
+ RECT rc;
+ rc.top = rc.left = 100;
+ rc.right = 100 + iColumns * 25 + 1;
+ rc.bottom = iRows * 20 + 100 + 20;
- AdjustWindowRectEx(&rc, GetWindowLongPtr(hwndDlg, GWL_STYLE), FALSE, GetWindowLongPtr(hwndDlg, GWL_EXSTYLE));
+ AdjustWindowRectEx(&rc, GetWindowLongPtr(m_hwnd, GWL_STYLE), FALSE, GetWindowLongPtr(m_hwnd, GWL_EXSTYLE));
- int width = rc.right - rc.left;
- int height = rc.bottom - rc.top;
+ int width = rc.right - rc.left;
+ int height = rc.bottom - rc.top;
- pCC->yPosition -= height;
+ m_yPosition -= height;
- SetDlgItemText(hwndDlg, IDC_COLORTEXT, pCC->bForeground ? TranslateT("Text color") : TranslateT("Background color"));
- SetWindowPos(GetDlgItem(hwndDlg, IDC_COLORTEXT), NULL, 0, 0, width, 20, 0);
- SetWindowPos(hwndDlg, NULL, pCC->xPosition, pCC->yPosition, width, height, SWP_SHOWWINDOW);
- }
- break;
-
- case WM_CTLCOLOREDIT:
- case WM_CTLCOLORSTATIC:
- if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_COLORTEXT)) {
- SetTextColor((HDC)wParam, RGB(60, 60, 150));
- SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
- return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
- }
- break;
+ m_text.SetText(m_bForeground ? TranslateT("Text color") : TranslateT("Background color"));
+ SetWindowPos(m_text.GetHwnd(), NULL, 0, 0, width, 20, 0);
+ SetWindowPos(m_hwnd, NULL, m_xPosition, m_yPosition, width, height, SWP_SHOWWINDOW);
+ }
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- if (iCurrentHotTrack >= 0)
- PostMessage(hwndDlg, WM_LBUTTONUP, 0, 0);
+ virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override
+ {
+ switch (msg) {
+ case WM_CTLCOLOREDIT:
+ case WM_CTLCOLORSTATIC:
+ if ((HWND)lParam == m_text.GetHwnd()) {
+ SetTextColor((HDC)wParam, RGB(60, 60, 150));
+ SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
+ return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
+ }
break;
- case IDCANCEL:
- DestroyWindow(hwndDlg);
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ if (iCurrentHotTrack >= 0)
+ PostMessage(m_hwnd, WM_LBUTTONUP, 0, 0);
+ break;
+ case IDCANCEL:
+ DestroyWindow(m_hwnd);
+ break;
+ }
break;
- }
- break;
-
- case WM_LBUTTONUP:
- if (iCurrentHotTrack >= 0 && iCurrentHotTrack < pCC->pModule->nColorCount && pCC->hWndTarget != NULL) {
- CHARFORMAT2 cf;
- cf.cbSize = sizeof(CHARFORMAT2);
- cf.dwMask = 0;
- cf.dwEffects = 0;
-
- HWND hWindow = GetParent(pCC->hWndTarget);
- int ctrlId = GetDlgCtrlID(pCC->hWndChooser);
-
- if (pCC->bForeground) {
- pCC->si->bFGSet = TRUE;
- pCC->si->iFG = iCurrentHotTrack;
- if (IsDlgButtonChecked(hWindow, ctrlId)) {
- cf.dwMask = CFM_COLOR;
- cf.crTextColor = pCC->pModule->crColors[iCurrentHotTrack];
- SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
+
+ case WM_LBUTTONUP:
+ if (iCurrentHotTrack >= 0 && iCurrentHotTrack < m_pModule->nColorCount && m_hwndTarget != NULL) {
+ CHARFORMAT2 cf;
+ cf.cbSize = sizeof(CHARFORMAT2);
+ cf.dwMask = 0;
+ cf.dwEffects = 0;
+
+ HWND hWindow = GetParent(m_hwndTarget);
+ int ctrlId = GetDlgCtrlID(m_hwndChooser);
+
+ if (m_bForeground) {
+ m_si->bFGSet = TRUE;
+ m_si->iFG = iCurrentHotTrack;
+ if (IsDlgButtonChecked(hWindow, ctrlId)) {
+ cf.dwMask = CFM_COLOR;
+ cf.crTextColor = m_pModule->crColors[iCurrentHotTrack];
+ SendMessage(m_hwndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
+ }
}
- }
- else {
- pCC->si->bBGSet = TRUE;
- pCC->si->iBG = iCurrentHotTrack;
- if (IsDlgButtonChecked(hWindow, ctrlId)) {
- cf.dwMask = CFM_BACKCOLOR;
- cf.crBackColor = pCC->pModule->crColors[iCurrentHotTrack];
- SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
+ else {
+ m_si->bBGSet = TRUE;
+ m_si->iBG = iCurrentHotTrack;
+ if (IsDlgButtonChecked(hWindow, ctrlId)) {
+ cf.dwMask = CFM_BACKCOLOR;
+ cf.crBackColor = m_pModule->crColors[iCurrentHotTrack];
+ SendMessage(m_hwndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
+ }
}
}
- }
- PostMessage(hwndDlg, WM_CLOSE, 0, 0);
- break;
-
- case WM_ACTIVATE:
- if (wParam == WA_INACTIVE)
- PostMessage(hwndDlg, WM_CLOSE, 0, 0);
- else if ((wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE))
- hPreviousActiveWindow = (HWND)lParam;
- break;
-
- case WM_MOUSEMOVE:
- {
- HDC hdc = GetDC(hwndDlg);
- POINT pt;
- RECT rect;
- int but;
-
- pt.x = LOWORD(lParam);
- pt.y = HIWORD(lParam);
-
- if (iCurrentHotTrack == -2)
- return 0; // prevent focussing when not drawn yet!
-
- but = CalculateCoordinatesToButton(pCC, pt);
-
- // weird stuff
- if (but != iCurrentHotTrack) {
- if (iCurrentHotTrack >= 0) {
- rect = CalculateButtonToCoordinates(pCC, iCurrentHotTrack);
- DrawFocusRect(hdc, &rect);
- iCurrentHotTrack = -1;
- }
- iCurrentHotTrack = but;
+ Close();
+ break;
+
+ case WM_ACTIVATE:
+ if (wParam == WA_INACTIVE)
+ Close();
+ else if ((wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE))
+ hwndPreviousActiveWindow = (HWND)lParam;
+ break;
- if (iCurrentHotTrack >= 0) {
- rect = CalculateButtonToCoordinates(pCC, iCurrentHotTrack);
- DrawFocusRect(hdc, &rect);
+ case WM_MOUSEMOVE:
+ {
+ HDC hdc = GetDC(m_hwnd);
+ POINT pt;
+ RECT rect;
+ int but;
+
+ pt.x = LOWORD(lParam);
+ pt.y = HIWORD(lParam);
+
+ if (iCurrentHotTrack == -2)
+ return 0; // prevent focussing when not drawn yet!
+
+ but = CalculateCoordinatesToButton(pt);
+
+ // weird stuff
+ if (but != iCurrentHotTrack) {
+ if (iCurrentHotTrack >= 0) {
+ rect = CalculateButtonToCoordinates(iCurrentHotTrack);
+ DrawFocusRect(hdc, &rect);
+ iCurrentHotTrack = -1;
+ }
+ iCurrentHotTrack = but;
+
+ if (iCurrentHotTrack >= 0) {
+ rect = CalculateButtonToCoordinates(iCurrentHotTrack);
+ DrawFocusRect(hdc, &rect);
+ }
}
+ ReleaseDC(m_hwnd, hdc);
}
- ReleaseDC(hwndDlg, hdc);
- }
- break;
+ break;
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- int iThisRow = 1;
- int iThisColumn = 0;
+ case WM_PAINT:
+ {
+ PAINTSTRUCT ps;
+ int iThisRow = 1;
+ int iThisColumn = 0;
- RECT rc;
- GetClientRect(hwndDlg, &rc);
- rc.top += 20;
+ RECT rc;
+ GetClientRect(m_hwnd, &rc);
+ rc.top += 20;
- HDC hdc = BeginPaint(hwndDlg, &ps);
+ HDC hdc = BeginPaint(m_hwnd, &ps);
- // fill background
- FillRect(hdc, &rc, GetSysColorBrush(COLOR_WINDOW));
+ // fill background
+ FillRect(hdc, &rc, GetSysColorBrush(COLOR_WINDOW));
- for (int i=0; i < pCC->pModule->nColorCount; i++) {
- // decide place to draw the color block in the window
- iThisColumn ++;
- if (iThisColumn > iColumns) {
- iThisColumn = 1;
- iThisRow++;
- }
+ for (int i = 0; i < m_pModule->nColorCount; i++) {
+ // decide place to draw the color block in the window
+ iThisColumn++;
+ if (iThisColumn > iColumns) {
+ iThisColumn = 1;
+ iThisRow++;
+ }
- if (pCC->bForeground && pCC->si->bFGSet && pCC->si->iFG == i || !pCC->bForeground && pCC->si->bBGSet && pCC->si->iBG == i) {
- rc.top = (iThisRow - 1) * 20 + 1 + 20 ;
- rc.left = (iThisColumn - 1) * 25 + 1 + 1 ;
- rc.bottom = iThisRow * 20 - 1 + 20 ;
- rc.right = iThisColumn * 25 - 1 ;
+ if (m_bForeground && m_si->bFGSet && m_si->iFG == i || !m_bForeground && m_si->bBGSet && m_si->iBG == i) {
+ rc.top = (iThisRow - 1) * 20 + 1 + 20;
+ rc.left = (iThisColumn - 1) * 25 + 1 + 1;
+ rc.bottom = iThisRow * 20 - 1 + 20;
+ rc.right = iThisColumn * 25 - 1;
- DrawEdge(hdc, &rc, EDGE_RAISED, BF_TOP | BF_LEFT | BF_RIGHT | BF_BOTTOM);
- }
+ DrawEdge(hdc, &rc, EDGE_RAISED, BF_TOP | BF_LEFT | BF_RIGHT | BF_BOTTOM);
+ }
- rc.top = (iThisRow - 1) * 20 + 3 + 20 ;
- rc.left = (iThisColumn - 1) * 25 + 3 + 1 ;
- rc.bottom = iThisRow * 20 - 3 + 20 ;
- rc.right = iThisColumn * 25 - 3 ;
+ rc.top = (iThisRow - 1) * 20 + 3 + 20;
+ rc.left = (iThisColumn - 1) * 25 + 3 + 1;
+ rc.bottom = iThisRow * 20 - 3 + 20;
+ rc.right = iThisColumn * 25 - 3;
- FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
+ FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
- HBRUSH hbr = CreateSolidBrush(pCC->pModule->crColors[i]);
+ HBRUSH hbr = CreateSolidBrush(m_pModule->crColors[i]);
- rc.top = (iThisRow - 1) * 20 + 4 + 20;
- rc.left = (iThisColumn - 1) * 25 + 4 + 1;
- rc.bottom = iThisRow * 20 - 4 + 20;
- rc.right = iThisColumn * 25 - 4;
+ rc.top = (iThisRow - 1) * 20 + 4 + 20;
+ rc.left = (iThisColumn - 1) * 25 + 4 + 1;
+ rc.bottom = iThisRow * 20 - 4 + 20;
+ rc.right = iThisColumn * 25 - 4;
- FillRect(hdc, &rc, hbr);
- DeleteObject(hbr);
- }
+ FillRect(hdc, &rc, hbr);
+ DeleteObject(hbr);
+ }
- EndPaint(hwndDlg, &ps);
- iCurrentHotTrack = -1;
+ EndPaint(m_hwnd, &ps);
+ iCurrentHotTrack = -1;
+ }
+ break;
}
- break;
-
- case WM_CLOSE:
- SetFocus(pCC->hWndTarget);
- DestroyWindow(hwndDlg);
- break;
-
- case WM_DESTROY:
- mir_free(pCC);
- return TRUE;
+ return CDlgBase::DlgProc(msg, wParam, lParam);
}
- return FALSE;
-}
+ virtual void OnClose() override
+ {
+ SetFocus(m_hwndTarget);
+ }
+};
void ColorChooser(SESSION_INFO *si, BOOL bFG, HWND hwndDlg, HWND hwndTarget, HWND hwndChooser)
{
- RECT rc;
- GetWindowRect(hwndChooser, &rc);
-
- COLORCHOOSER *pCC = (COLORCHOOSER *)mir_alloc(sizeof(COLORCHOOSER));
- pCC->hWndTarget = hwndTarget;
- pCC->pModule = chatApi.MM_FindModule(si->pszModule);
- pCC->xPosition = rc.left + 3;
- pCC->yPosition = IsWindowVisible(hwndChooser) ? rc.top - 1 : rc.top + 20;
- pCC->bForeground = bFG;
- pCC->hWndChooser = hwndChooser;
- pCC->si = si;
- CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_COLORCHOOSER), hwndDlg, DlgProcColorToolWindow, (LPARAM)pCC);
+ CColorChooserDlg *pDialog = new CColorChooserDlg(si, bFG, hwndDlg, hwndTarget, hwndChooser);
+ pDialog->Show();
}