[MSPAINT_NEW] port to ATL (first batch of git commits)
[reactos.git] / reactos / base / applications / mspaint_new / palette.cpp
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/mspaint_new/palette.cpp
5 * PURPOSE: Window procedure of the palette window
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include "precomp.h"
12
13 /* FUNCTIONS ********************************************************/
14
15 LRESULT CPaletteWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
16 {
17 RECT rc = { 0, 0, 31, 32 };
18 HDC hDC = GetDC();
19 HPEN oldPen;
20 HBRUSH oldBrush;
21 int i, a, b;
22
23 DefWindowProc(WM_PAINT, wParam, lParam);
24
25 for(b = 2; b < 30; b++)
26 for(a = 2; a < 29; a++)
27 if ((a + b) % 2 == 1)
28 SetPixel(hDC, a, b, GetSysColor(COLOR_BTNHILIGHT));
29
30 DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
31 DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_TOPLEFT | BF_BOTTOMRIGHT);
32 SetRect(&rc, 11, 12, 26, 27);
33 DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
34 oldPen = (HPEN) SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
35 oldBrush = (HBRUSH) SelectObject(hDC, CreateSolidBrush(bgColor));
36 Rectangle(hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1);
37 DeleteObject(SelectObject(hDC, oldBrush));
38 SetRect(&rc, 4, 5, 19, 20);
39 DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
40 oldBrush = (HBRUSH) SelectObject(hDC, CreateSolidBrush(fgColor));
41 Rectangle(hDC, rc.left + 2, rc.top + 2, rc.right - 1, rc.bottom - 1);
42 DeleteObject(SelectObject(hDC, oldBrush));
43 DeleteObject(SelectObject(hDC, oldPen));
44
45 for(i = 0; i < 28; i++)
46 {
47 SetRect(&rc, 31 + (i % 14) * 16,
48 0 + (i / 14) * 16, 16 + 31 + (i % 14) * 16, 16 + 0 + (i / 14) * 16);
49 DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
50 DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_RECT);
51 oldPen = (HPEN) SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
52 oldBrush = (HBRUSH) SelectObject(hDC, CreateSolidBrush(palColors[i]));
53 Rectangle(hDC, rc.left + 2, rc.top + 2, rc.right - 1, rc.bottom - 1);
54 DeleteObject(SelectObject(hDC, oldBrush));
55 DeleteObject(SelectObject(hDC, oldPen));
56 }
57 ReleaseDC(hDC);
58 return 0;
59 }
60
61 LRESULT CPaletteWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
62 {
63 if (GET_X_LPARAM(lParam) >= 31)
64 {
65 fgColor = palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14];
66 InvalidateRect(NULL, FALSE);
67 if (activeTool == 10)
68 ForceRefreshSelectionContents();
69 }
70 return 0;
71 }
72
73 LRESULT CPaletteWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
74 {
75 if (GET_X_LPARAM(lParam) >= 31)
76 {
77 bgColor = palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14];
78 InvalidateRect(NULL, FALSE);
79 if (activeTool == 10)
80 ForceRefreshSelectionContents();
81 }
82 return 0;
83 }
84
85 LRESULT CPaletteWindow::OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
86 {
87 if (GET_X_LPARAM(lParam) >= 31)
88 if (ChooseColor(&choosecolor))
89 {
90 palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14] =
91 choosecolor.rgbResult;
92 fgColor = choosecolor.rgbResult;
93 InvalidateRect(NULL, FALSE);
94 if (activeTool == 10)
95 ForceRefreshSelectionContents();
96 }
97 return 0;
98 }
99
100 LRESULT CPaletteWindow::OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
101 {
102 if (GET_X_LPARAM(lParam) >= 31)
103 if (ChooseColor(&choosecolor))
104 {
105 palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14] =
106 choosecolor.rgbResult;
107 bgColor = choosecolor.rgbResult;
108 InvalidateRect(NULL, FALSE);
109 if (activeTool == 10)
110 ForceRefreshSelectionContents();
111 }
112 return 0;
113 }