* Sync with recent trunk (r52637).
[reactos.git] / base / applications / mspaint / palette.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/paint/palette.c
5 * PURPOSE: Window procedure of the palette window
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include <windows.h>
12 #include "globalvar.h"
13
14 /* FUNCTIONS ********************************************************/
15
16 LRESULT CALLBACK
17 PalWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
18 {
19 switch (message)
20 {
21 case WM_PAINT:
22 {
23 RECT rc = { 0, 0, 31, 32 };
24 HDC hDC = GetDC(hwnd);
25 HPEN oldPen;
26 HBRUSH oldBrush;
27 int i, a, b;
28
29 DefWindowProc(hwnd, message, wParam, lParam);
30
31 for(b = 2; b < 30; b++)
32 for(a = 2; a < 29; a++)
33 if ((a + b) % 2 == 1)
34 SetPixel(hDC, a, b, GetSysColor(COLOR_BTNHILIGHT));
35
36 DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
37 DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_TOPLEFT | BF_BOTTOMRIGHT);
38 SetRect(&rc, 11, 12, 26, 27);
39 DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
40 oldPen = SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
41 oldBrush = SelectObject(hDC, CreateSolidBrush(bgColor));
42 Rectangle(hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1);
43 DeleteObject(SelectObject(hDC, oldBrush));
44 SetRect(&rc, 4, 5, 19, 20);
45 DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
46 oldBrush = SelectObject(hDC, CreateSolidBrush(fgColor));
47 Rectangle(hDC, rc.left + 2, rc.top + 2, rc.right - 1, rc.bottom - 1);
48 DeleteObject(SelectObject(hDC, oldBrush));
49 DeleteObject(SelectObject(hDC, oldPen));
50
51 for(i = 0; i < 28; i++)
52 {
53 SetRect(&rc, 31 + (i % 14) * 16,
54 0 + (i / 14) * 16, 16 + 31 + (i % 14) * 16, 16 + 0 + (i / 14) * 16);
55 DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
56 DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_RECT);
57 oldPen = SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
58 oldBrush = SelectObject(hDC, CreateSolidBrush(palColors[i]));
59 Rectangle(hDC, rc.left + 2, rc.top + 2, rc.right - 1, rc.bottom - 1);
60 DeleteObject(SelectObject(hDC, oldBrush));
61 DeleteObject(SelectObject(hDC, oldPen));
62 }
63 ReleaseDC(hwnd, hDC);
64 break;
65 }
66 case WM_LBUTTONDOWN:
67 if (LOWORD(lParam) >= 31)
68 {
69 fgColor = palColors[(LOWORD(lParam) - 31) / 16 + (HIWORD(lParam) / 16) * 14];
70 SendMessage(hwnd, WM_PAINT, 0, 0);
71 }
72 break;
73 case WM_RBUTTONDOWN:
74 if (LOWORD(lParam) >= 31)
75 {
76 bgColor = palColors[(LOWORD(lParam) - 31) / 16 + (HIWORD(lParam) / 16) * 14];
77 SendMessage(hwnd, WM_PAINT, 0, 0);
78 }
79 break;
80 case WM_LBUTTONDBLCLK:
81 if (LOWORD(lParam) >= 31)
82 if (ChooseColor(&choosecolor))
83 {
84 palColors[(LOWORD(lParam) - 31) / 16 + (HIWORD(lParam) / 16) * 14] =
85 choosecolor.rgbResult;
86 fgColor = choosecolor.rgbResult;
87 SendMessage(hwnd, WM_PAINT, 0, 0);
88 }
89 break;
90 case WM_RBUTTONDBLCLK:
91 if (LOWORD(lParam) >= 31)
92 if (ChooseColor(&choosecolor))
93 {
94 palColors[(LOWORD(lParam) - 31) / 16 + (HIWORD(lParam) / 16) * 14] =
95 choosecolor.rgbResult;
96 bgColor = choosecolor.rgbResult;
97 SendMessage(hwnd, WM_PAINT, 0, 0);
98 }
99 break;
100
101 default:
102 return DefWindowProc(hwnd, message, wParam, lParam);
103 }
104
105 return 0;
106 }