[GDI32]
[reactos.git] / rosapps / templates / imagesoft / custcombo.c
1 #include <precomp.h>
2
3
4 LRESULT WINAPI
5 FlatComboProc(HWND hwnd,
6 UINT msg,
7 WPARAM wParam,
8 LPARAM lParam)
9 {
10 HDC hdc;
11 PAINTSTRUCT ps;
12 RECT rect, rect2;
13 POINT pt;
14
15 WNDPROC OldComboProc = (WNDPROC)GetWindowLong(hwnd, GWL_USERDATA);
16
17 static BOOL fMouseDown = FALSE;
18 static BOOL fButtonDown = FALSE;
19
20 switch(msg)
21 {
22 case WM_PAINT:
23 {
24 if(wParam == 0) hdc = BeginPaint(hwnd, &ps);
25 else hdc = (HDC)wParam;
26
27 /* mask off the borders and draw ComboBox normally */
28 GetClientRect(hwnd, &rect);
29
30 InflateRect(&rect,
31 -GetSystemMetrics(SM_CXEDGE)*2,
32 -GetSystemMetrics(SM_CYEDGE)*2);
33
34 rect.right -= GetSystemMetrics(SM_CXVSCROLL);
35
36 IntersectClipRect(hdc,
37 rect.left,
38 rect.top,
39 rect.right,
40 rect.bottom);
41
42 /* Draw the ComboBox */
43 CallWindowProc(OldComboProc,
44 hwnd,
45 msg,
46 (WPARAM)hdc,
47 lParam);
48
49 /* Now mask off inside and draw the borders */
50 SelectClipRgn(hdc,
51 NULL);
52 rect.right += GetSystemMetrics(SM_CXVSCROLL);
53
54 ExcludeClipRect(hdc,
55 rect.left,
56 rect.top,
57 rect.right,
58 rect.bottom);
59
60 /* draw borders */
61 GetClientRect(hwnd,
62 &rect2);
63 FillRect(hdc,
64 &rect2,
65 //CreateSolidBrush(RGB(0,0,0)));
66 GetSysColorBrush(COLOR_3DFACE));
67
68 /* now draw the button */
69 SelectClipRgn(hdc,
70 NULL);
71 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
72
73 if(fButtonDown)
74 {
75 HBRUSH oldBrush;
76 HPEN oldPen;
77 POINT pt[3];
78
79 FillRect(hdc, &rect, CreateSolidBrush(RGB(182,189,210)));
80 rect.top -= 1;
81 rect.bottom += 1;
82 FrameRect(hdc, &rect, GetStockBrush(WHITE_BRUSH));
83
84 pt[0].x = rect.right - ((GetSystemMetrics(SM_CXVSCROLL) / 2) + 2);
85 pt[0].y = rect.bottom / 2;
86 pt[1].x = pt[0].x + 4;
87 pt[1].y = pt[0].y;
88 pt[2].x = pt[1].x - 2;
89 pt[2].y = pt[1].y + 2;
90
91 oldPen = (HPEN) SelectObject(hdc, GetStockPen(WHITE_PEN));
92 oldBrush = (HBRUSH) SelectObject(hdc, GetStockBrush(WHITE_BRUSH));
93 Polygon(hdc, pt, 3);
94
95 SelectObject(hdc, oldPen);
96 SelectObject(hdc, oldBrush);
97 }
98 else
99 {
100 HBRUSH oldBrush;
101 POINT pt[3];
102
103 FillRect(hdc, &rect, GetSysColorBrush(COLOR_3DFACE));
104 rect.top -= 1;
105 rect.bottom += 1;
106 FrameRect(hdc, &rect, GetStockBrush(WHITE_BRUSH));
107
108 pt[0].x = rect.right - ((GetSystemMetrics(SM_CXVSCROLL) / 2) + 2);
109 pt[0].y = rect.bottom / 2;
110 pt[1].x = pt[0].x + 4;
111 pt[1].y = pt[0].y;
112 pt[2].x = pt[1].x - 2;
113 pt[2].y = pt[1].y + 2;
114
115 oldBrush = (HBRUSH) SelectObject(hdc, GetStockBrush(BLACK_BRUSH));
116 Polygon(hdc, pt, 3);
117
118 SelectObject(hdc, oldBrush);
119 }
120
121
122 if(wParam == 0)
123 EndPaint(hwnd, &ps);
124
125 return 0;
126 }
127
128 /* check if mouse is within drop-arrow area, toggle
129 * a flag to say if the mouse is up/down. Then invalidate
130 * the window so it redraws to show the changes. */
131 case WM_LBUTTONDBLCLK:
132 case WM_LBUTTONDOWN:
133 {
134
135 pt.x = (short)LOWORD(lParam);
136 pt.y = (short)HIWORD(lParam);
137
138 GetClientRect(hwnd, &rect);
139
140 InflateRect(&rect,
141 -GetSystemMetrics(SM_CXEDGE),
142 -GetSystemMetrics(SM_CYEDGE));
143 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
144
145 if(PtInRect(&rect, pt))
146 {
147 /* we *should* call SetCapture, but the ComboBox does it for us */
148 fMouseDown = TRUE;
149 fButtonDown = TRUE;
150 InvalidateRect(hwnd, 0, 0);
151 }
152 }
153 break;
154
155 /* mouse has moved. Check to see if it is in/out of the drop-arrow */
156 case WM_MOUSEMOVE:
157 {
158
159 pt.x = (short)LOWORD(lParam);
160 pt.y = (short)HIWORD(lParam);
161
162 if(fMouseDown && (wParam & MK_LBUTTON))
163 {
164 GetClientRect(hwnd, &rect);
165
166 InflateRect(&rect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE));
167 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
168
169 if(fButtonDown != PtInRect(&rect, pt))
170 {
171 fButtonDown = PtInRect(&rect, pt);
172 InvalidateRect(hwnd, 0, 0);
173 }
174 }
175 }
176 break;
177
178 case WM_LBUTTONUP:
179 {
180
181 if(fMouseDown)
182 {
183 /* No need to call ReleaseCapture, the ComboBox does it for us */
184 fMouseDown = FALSE;
185 fButtonDown = FALSE;
186 InvalidateRect(hwnd, 0, 0);
187 }
188 }
189 break;
190 }
191
192 return CallWindowProc(OldComboProc,
193 hwnd,
194 msg,
195 wParam,
196 lParam);
197 }
198
199 VOID MakeFlatCombo(HWND hwndCombo)
200 {
201 LONG OldComboProc;
202
203 /* Remember old window procedure */
204 OldComboProc = GetWindowLongPtr(hwndCombo, GWL_WNDPROC);
205 SetWindowLongPtr(hwndCombo,
206 GWL_USERDATA,
207 OldComboProc);
208
209 /* Perform the subclass */
210 SetWindowLongPtr(hwndCombo,
211 GWL_WNDPROC,
212 (LONG_PTR)FlatComboProc);
213 }