1 /*
2  * PROJECT:     PAINT for ReactOS
3  * LICENSE:     LGPL
4  * FILE:        base/applications/mspaint/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     HPEN oldPen;
19     HBRUSH oldBrush;
20     int i, a, b;
21 
22     PAINTSTRUCT ps;
23     HDC hDC = BeginPaint(&ps);
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(paletteModel.GetBgColor()));
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(paletteModel.GetFgColor()));
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(paletteModel.GetColor(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     EndPaint(&ps);
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         paletteModel.SetFgColor(paletteModel.GetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14));
65     return 0;
66 }
67 
68 LRESULT CPaletteWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
69 {
70     if (GET_X_LPARAM(lParam) >= 31)
71         paletteModel.SetBgColor(paletteModel.GetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14));
72     return 0;
73 }
74 
75 LRESULT CPaletteWindow::OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
76 {
77     if (GET_X_LPARAM(lParam) >= 31)
78         if (ChooseColor(&choosecolor))
79         {
80             paletteModel.SetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14,
81                 choosecolor.rgbResult);
82             paletteModel.SetFgColor(choosecolor.rgbResult);
83         }
84     return 0;
85 }
86 
87 LRESULT CPaletteWindow::OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
88 {
89     if (GET_X_LPARAM(lParam) >= 31)
90         if (ChooseColor(&choosecolor))
91         {
92             paletteModel.SetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14,
93                 choosecolor.rgbResult);
94             paletteModel.SetBgColor(choosecolor.rgbResult);
95         }
96     return 0;
97 }
98 
99 LRESULT CPaletteWindow::OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
100 {
101     InvalidateRect(NULL, FALSE);
102     return 0;
103 }
104 
105 LRESULT CPaletteWindow::OnPaletteModelPaletteChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
106 {
107     InvalidateRect(NULL, FALSE);
108     return 0;
109 }
110