1 | /*
|
---|
2 | * Header control
|
---|
3 | *
|
---|
4 | * Copyright 1998 Eric Kohl
|
---|
5 | * Copyright 1999 Achim Hasenmueller
|
---|
6 | *
|
---|
7 | * TODO:
|
---|
8 | * - Imagelist support (partially).
|
---|
9 | * - Callback items (under construction).
|
---|
10 | * - Order list support.
|
---|
11 | * - Control specific cursors (over dividers).
|
---|
12 | * - Hottrack support (partially).
|
---|
13 | * - Custom draw support (including Notifications).
|
---|
14 | * - Drag and Drop support (including Notifications).
|
---|
15 | * - Unicode support.
|
---|
16 | *
|
---|
17 | * FIXME:
|
---|
18 | * - Replace DrawText32A by DrawTextEx32A(...|DT_ENDELLIPSIS) in
|
---|
19 | * HEADER_DrawItem.
|
---|
20 | * - Little flaw when drawing a bitmap on the right side of the text.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include <string.h>
|
---|
24 |
|
---|
25 | #include "winbase.h"
|
---|
26 | #include "commctrl.h"
|
---|
27 | #include "header.h"
|
---|
28 | #include "comctl32.h"
|
---|
29 |
|
---|
30 |
|
---|
31 | #define __HDM_LAYOUT_HACK__
|
---|
32 |
|
---|
33 |
|
---|
34 | #define VERT_BORDER 4
|
---|
35 | #define DIVIDER_WIDTH 10
|
---|
36 |
|
---|
37 | #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongA(hwnd,0))
|
---|
38 |
|
---|
39 |
|
---|
40 | static INT
|
---|
41 | HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
|
---|
42 | {
|
---|
43 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
44 | HEADER_ITEM *phdi = &infoPtr->items[iItem];
|
---|
45 | RECT r;
|
---|
46 | INT oldBkMode;
|
---|
47 |
|
---|
48 | r = phdi->rect;
|
---|
49 | if (r.right - r.left == 0)
|
---|
50 | return phdi->rect.right;
|
---|
51 |
|
---|
52 | if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
|
---|
53 | if (phdi->bDown) {
|
---|
54 | DrawEdge (hdc, &r, BDR_RAISEDOUTER,
|
---|
55 | BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
|
---|
56 | r.left += 2;
|
---|
57 | r.top += 2;
|
---|
58 | }
|
---|
59 | else
|
---|
60 | DrawEdge (hdc, &r, EDGE_RAISED,
|
---|
61 | BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
|
---|
62 | }
|
---|
63 | else
|
---|
64 | DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
|
---|
65 |
|
---|
66 | if (phdi->fmt & HDF_OWNERDRAW) {
|
---|
67 | DRAWITEMSTRUCT dis;
|
---|
68 | dis.CtlType = ODT_HEADER;
|
---|
69 | dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
|
---|
70 | dis.itemID = iItem;
|
---|
71 | dis.itemAction = ODA_DRAWENTIRE;
|
---|
72 | dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
|
---|
73 | dis.hwndItem = hwnd;
|
---|
74 | dis.hDC = hdc;
|
---|
75 | dis.rcItem = r;
|
---|
76 | dis.itemData = phdi->lParam;
|
---|
77 | SendMessageA (GetParent (hwnd), WM_DRAWITEM,
|
---|
78 | (WPARAM)dis.CtlID, (LPARAM)&dis);
|
---|
79 | }
|
---|
80 | else {
|
---|
81 | UINT uTextJustify = DT_LEFT;
|
---|
82 |
|
---|
83 | if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
|
---|
84 | uTextJustify = DT_CENTER;
|
---|
85 | else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
|
---|
86 | uTextJustify = DT_RIGHT;
|
---|
87 |
|
---|
88 | if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
|
---|
89 | BITMAP bmp;
|
---|
90 | HDC hdcBitmap;
|
---|
91 | INT yD, yS, cx, cy, rx, ry;
|
---|
92 |
|
---|
93 | GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
|
---|
94 |
|
---|
95 | ry = r.bottom - r.top;
|
---|
96 | rx = r.right - r.left;
|
---|
97 |
|
---|
98 | if (ry >= bmp.bmHeight) {
|
---|
99 | cy = bmp.bmHeight;
|
---|
100 | yD = r.top + (ry - bmp.bmHeight) / 2;
|
---|
101 | yS = 0;
|
---|
102 | }
|
---|
103 | else {
|
---|
104 | cy = ry;
|
---|
105 | yD = r.top;
|
---|
106 | yS = (bmp.bmHeight - ry) / 2;
|
---|
107 |
|
---|
108 | }
|
---|
109 |
|
---|
110 | if (rx >= bmp.bmWidth + 6) {
|
---|
111 | cx = bmp.bmWidth;
|
---|
112 | }
|
---|
113 | else {
|
---|
114 | cx = rx - 6;
|
---|
115 | }
|
---|
116 |
|
---|
117 | hdcBitmap = CreateCompatibleDC (hdc);
|
---|
118 | SelectObject (hdcBitmap, phdi->hbm);
|
---|
119 | BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
|
---|
120 | DeleteDC (hdcBitmap);
|
---|
121 |
|
---|
122 | r.left += (bmp.bmWidth + 3);
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | if ((phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
|
---|
127 | BITMAP bmp;
|
---|
128 | HDC hdcBitmap;
|
---|
129 | INT xD, yD, yS, cx, cy, rx, ry, tx;
|
---|
130 | RECT textRect;
|
---|
131 |
|
---|
132 | GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
|
---|
133 |
|
---|
134 | textRect = r;
|
---|
135 | DrawTextW (hdc, phdi->pszText, lstrlenW (phdi->pszText),
|
---|
136 | &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
|
---|
137 | tx = textRect.right - textRect.left;
|
---|
138 | ry = r.bottom - r.top;
|
---|
139 | rx = r.right - r.left;
|
---|
140 |
|
---|
141 | if (ry >= bmp.bmHeight) {
|
---|
142 | cy = bmp.bmHeight;
|
---|
143 | yD = r.top + (ry - bmp.bmHeight) / 2;
|
---|
144 | yS = 0;
|
---|
145 | }
|
---|
146 | else {
|
---|
147 | cy = ry;
|
---|
148 | yD = r.top;
|
---|
149 | yS = (bmp.bmHeight - ry) / 2;
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 | if (r.left + tx + bmp.bmWidth + 9 <= r.right) {
|
---|
154 | cx = bmp.bmWidth;
|
---|
155 | xD = r.left + tx + 6;
|
---|
156 | }
|
---|
157 | else {
|
---|
158 | if (rx >= bmp.bmWidth + 6) {
|
---|
159 | cx = bmp.bmWidth;
|
---|
160 | xD = r.right - bmp.bmWidth - 3;
|
---|
161 | r.right = xD - 3;
|
---|
162 | }
|
---|
163 | else {
|
---|
164 | cx = rx - 3;
|
---|
165 | xD = r.left;
|
---|
166 | r.right = r.left;
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | hdcBitmap = CreateCompatibleDC (hdc);
|
---|
171 | SelectObject (hdcBitmap, phdi->hbm);
|
---|
172 | BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
|
---|
173 | DeleteDC (hdcBitmap);
|
---|
174 | }
|
---|
175 |
|
---|
176 | if (phdi->fmt & HDF_IMAGE) {
|
---|
177 |
|
---|
178 |
|
---|
179 | /* ImageList_Draw (infoPtr->himl, phdi->iImage,...); */
|
---|
180 | }
|
---|
181 |
|
---|
182 | if ((phdi->fmt & HDF_STRING) && (phdi->pszText)) {
|
---|
183 | oldBkMode = SetBkMode(hdc, TRANSPARENT);
|
---|
184 | r.left += 3;
|
---|
185 | r.right -= 3;
|
---|
186 | SetTextColor (hdc, bHotTrack ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
|
---|
187 | DrawTextW (hdc, phdi->pszText, lstrlenW (phdi->pszText),
|
---|
188 | &r, uTextJustify|DT_VCENTER|DT_SINGLELINE);
|
---|
189 | if (oldBkMode != TRANSPARENT)
|
---|
190 | SetBkMode(hdc, oldBkMode);
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | return phdi->rect.right;
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | static void
|
---|
199 | HEADER_Refresh (HWND hwnd, HDC hdc)
|
---|
200 | {
|
---|
201 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
202 | HFONT hFont, hOldFont;
|
---|
203 | RECT rect;
|
---|
204 | HBRUSH hbrBk;
|
---|
205 | INT i, x;
|
---|
206 |
|
---|
207 | /* get rect for the bar, adjusted for the border */
|
---|
208 | GetClientRect (hwnd, &rect);
|
---|
209 |
|
---|
210 | hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
|
---|
211 | hOldFont = SelectObject (hdc, hFont);
|
---|
212 |
|
---|
213 | /* draw Background */
|
---|
214 | hbrBk = GetSysColorBrush(COLOR_3DFACE);
|
---|
215 | FillRect(hdc, &rect, hbrBk);
|
---|
216 |
|
---|
217 | x = rect.left;
|
---|
218 | for (i = 0; i < infoPtr->uNumItem; i++) {
|
---|
219 | x = HEADER_DrawItem (hwnd, hdc, i, FALSE);
|
---|
220 | }
|
---|
221 |
|
---|
222 | if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
|
---|
223 | rect.left = x;
|
---|
224 | if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
|
---|
225 | DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
|
---|
226 | else
|
---|
227 | DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
|
---|
228 | }
|
---|
229 |
|
---|
230 | SelectObject (hdc, hOldFont);
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | static void
|
---|
235 | HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
|
---|
236 | {
|
---|
237 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
238 | HFONT hFont, hOldFont;
|
---|
239 |
|
---|
240 | hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
|
---|
241 | hOldFont = SelectObject (hdc, hFont);
|
---|
242 | HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
|
---|
243 | SelectObject (hdc, hOldFont);
|
---|
244 | }
|
---|
245 |
|
---|
246 |
|
---|
247 | static void
|
---|
248 | HEADER_SetItemBounds (HWND hwnd)
|
---|
249 | {
|
---|
250 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
251 | HEADER_ITEM *phdi;
|
---|
252 | RECT rect;
|
---|
253 | int i, x;
|
---|
254 |
|
---|
255 | if (infoPtr->uNumItem == 0)
|
---|
256 | return;
|
---|
257 |
|
---|
258 | GetClientRect (hwnd, &rect);
|
---|
259 |
|
---|
260 | x = rect.left;
|
---|
261 | for (i = 0; i < infoPtr->uNumItem; i++) {
|
---|
262 | phdi = &infoPtr->items[i];
|
---|
263 | phdi->rect.top = rect.top;
|
---|
264 | phdi->rect.bottom = rect.bottom;
|
---|
265 | phdi->rect.left = x;
|
---|
266 | phdi->rect.right = phdi->rect.left + phdi->cxy;
|
---|
267 | x = phdi->rect.right;
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 |
|
---|
272 | static void
|
---|
273 | HEADER_ForceItemBounds (HWND hwnd, INT cy)
|
---|
274 | {
|
---|
275 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
276 | HEADER_ITEM *phdi;
|
---|
277 | int i, x;
|
---|
278 |
|
---|
279 | if (infoPtr->uNumItem == 0)
|
---|
280 | return;
|
---|
281 |
|
---|
282 | x = 0;
|
---|
283 | for (i = 0; i < infoPtr->uNumItem; i++) {
|
---|
284 | phdi = &infoPtr->items[i];
|
---|
285 | phdi->rect.top = 0;
|
---|
286 | phdi->rect.bottom = cy;
|
---|
287 | phdi->rect.left = x;
|
---|
288 | phdi->rect.right = phdi->rect.left + phdi->cxy;
|
---|
289 | x = phdi->rect.right;
|
---|
290 | }
|
---|
291 | }
|
---|
292 |
|
---|
293 |
|
---|
294 | static void
|
---|
295 | HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
|
---|
296 | {
|
---|
297 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
298 | RECT rect, rcTest;
|
---|
299 | INT iCount, width;
|
---|
300 | BOOL bNoWidth;
|
---|
301 |
|
---|
302 | GetClientRect (hwnd, &rect);
|
---|
303 |
|
---|
304 | *pFlags = 0;
|
---|
305 | bNoWidth = FALSE;
|
---|
306 | if (PtInRect (&rect, *lpPt))
|
---|
307 | {
|
---|
308 | if (infoPtr->uNumItem == 0) {
|
---|
309 | *pFlags |= HHT_NOWHERE;
|
---|
310 | *pItem = 1;
|
---|
311 | // TRACE (header, "NOWHERE\n");
|
---|
312 | return;
|
---|
313 | }
|
---|
314 | else {
|
---|
315 | /* somewhere inside */
|
---|
316 | for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
|
---|
317 | rect = infoPtr->items[iCount].rect;
|
---|
318 | width = rect.right - rect.left;
|
---|
319 | if (width == 0) {
|
---|
320 | bNoWidth = TRUE;
|
---|
321 | continue;
|
---|
322 | }
|
---|
323 | if (PtInRect (&rect, *lpPt)) {
|
---|
324 | if (width <= 2 * DIVIDER_WIDTH) {
|
---|
325 | *pFlags |= HHT_ONHEADER;
|
---|
326 | *pItem = iCount;
|
---|
327 | // TRACE (header, "ON HEADER %d\n", iCount);
|
---|
328 | return;
|
---|
329 | }
|
---|
330 | if (iCount > 0) {
|
---|
331 | rcTest = rect;
|
---|
332 | rcTest.right = rcTest.left + DIVIDER_WIDTH;
|
---|
333 | if (PtInRect (&rcTest, *lpPt)) {
|
---|
334 | if (bNoWidth) {
|
---|
335 | *pFlags |= HHT_ONDIVOPEN;
|
---|
336 | *pItem = iCount - 1;
|
---|
337 | // TRACE (header, "ON DIVOPEN %d\n", *pItem);
|
---|
338 | return;
|
---|
339 | }
|
---|
340 | else {
|
---|
341 | *pFlags |= HHT_ONDIVIDER;
|
---|
342 | *pItem = iCount - 1;
|
---|
343 | // TRACE (header, "ON DIVIDER %d\n", *pItem);
|
---|
344 | return;
|
---|
345 | }
|
---|
346 | }
|
---|
347 | }
|
---|
348 | rcTest = rect;
|
---|
349 | rcTest.left = rcTest.right - DIVIDER_WIDTH;
|
---|
350 | if (PtInRect (&rcTest, *lpPt)) {
|
---|
351 | *pFlags |= HHT_ONDIVIDER;
|
---|
352 | *pItem = iCount;
|
---|
353 | // TRACE (header, "ON DIVIDER %d\n", *pItem);
|
---|
354 | return;
|
---|
355 | }
|
---|
356 |
|
---|
357 | *pFlags |= HHT_ONHEADER;
|
---|
358 | *pItem = iCount;
|
---|
359 | // TRACE (header, "ON HEADER %d\n", iCount);
|
---|
360 | return;
|
---|
361 | }
|
---|
362 | }
|
---|
363 |
|
---|
364 | /* check for last divider part (on nowhere) */
|
---|
365 | rect = infoPtr->items[infoPtr->uNumItem-1].rect;
|
---|
366 | rect.left = rect.right;
|
---|
367 | rect.right += DIVIDER_WIDTH;
|
---|
368 | if (PtInRect (&rect, *lpPt)) {
|
---|
369 | if (bNoWidth) {
|
---|
370 | *pFlags |= HHT_ONDIVOPEN;
|
---|
371 | *pItem = infoPtr->uNumItem - 1;
|
---|
372 | // TRACE (header, "ON DIVOPEN %d\n", *pItem);
|
---|
373 | return;
|
---|
374 | }
|
---|
375 | else {
|
---|
376 | *pFlags |= HHT_ONDIVIDER;
|
---|
377 | *pItem = infoPtr->uNumItem-1;
|
---|
378 | // TRACE (header, "ON DIVIDER %d\n", *pItem);
|
---|
379 | return;
|
---|
380 | }
|
---|
381 | }
|
---|
382 |
|
---|
383 | *pFlags |= HHT_NOWHERE;
|
---|
384 | *pItem = 1;
|
---|
385 | // TRACE (header, "NOWHERE\n");
|
---|
386 | return;
|
---|
387 | }
|
---|
388 | }
|
---|
389 | else {
|
---|
390 | if (lpPt->x < rect.left) {
|
---|
391 | // TRACE (header, "TO LEFT\n");
|
---|
392 | *pFlags |= HHT_TOLEFT;
|
---|
393 | }
|
---|
394 | else if (lpPt->x > rect.right) {
|
---|
395 | // TRACE (header, "TO LEFT\n");
|
---|
396 | *pFlags |= HHT_TORIGHT;
|
---|
397 | }
|
---|
398 |
|
---|
399 | if (lpPt->y < rect.top) {
|
---|
400 | // TRACE (header, "ABOVE\n");
|
---|
401 | *pFlags |= HHT_ABOVE;
|
---|
402 | }
|
---|
403 | else if (lpPt->y > rect.bottom) {
|
---|
404 | // TRACE (header, "BELOW\n");
|
---|
405 | *pFlags |= HHT_BELOW;
|
---|
406 | }
|
---|
407 | }
|
---|
408 |
|
---|
409 | *pItem = 1;
|
---|
410 | // TRACE (header, "flags=0x%X\n", *pFlags);
|
---|
411 | return;
|
---|
412 | }
|
---|
413 |
|
---|
414 |
|
---|
415 | static void
|
---|
416 | HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
|
---|
417 | {
|
---|
418 | RECT rect;
|
---|
419 | HPEN hOldPen;
|
---|
420 | INT oldRop;
|
---|
421 |
|
---|
422 | GetClientRect (hwnd, &rect);
|
---|
423 |
|
---|
424 | hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
|
---|
425 | oldRop = SetROP2 (hdc, R2_XORPEN);
|
---|
426 | MoveToEx (hdc, x, rect.top, NULL);
|
---|
427 | LineTo (hdc, x, rect.bottom);
|
---|
428 | SetROP2 (hdc, oldRop);
|
---|
429 | SelectObject (hdc, hOldPen);
|
---|
430 | }
|
---|
431 |
|
---|
432 |
|
---|
433 | static BOOL
|
---|
434 | HEADER_SendSimpleNotify (HWND hwnd, UINT code)
|
---|
435 | {
|
---|
436 | NMHDR nmhdr;
|
---|
437 |
|
---|
438 | nmhdr.hwndFrom = hwnd;
|
---|
439 | nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
|
---|
440 | nmhdr.code = code;
|
---|
441 |
|
---|
442 | return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
|
---|
443 | (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
|
---|
444 | }
|
---|
445 |
|
---|
446 |
|
---|
447 | static BOOL
|
---|
448 | HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem)
|
---|
449 | {
|
---|
450 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
451 | NMHEADERA nmhdr;
|
---|
452 | HDITEMA nmitem;
|
---|
453 |
|
---|
454 | nmhdr.hdr.hwndFrom = hwnd;
|
---|
455 | nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
|
---|
456 | nmhdr.hdr.code = code;
|
---|
457 | nmhdr.iItem = iItem;
|
---|
458 | nmhdr.iButton = 0;
|
---|
459 | nmhdr.pitem = &nmitem;
|
---|
460 | nmitem.mask = 0;
|
---|
461 | nmitem.cxy = infoPtr->items[iItem].cxy;
|
---|
462 | nmitem.hbm = infoPtr->items[iItem].hbm;
|
---|
463 | nmitem.pszText = NULL;
|
---|
464 | nmitem.cchTextMax = 0;
|
---|
465 | /* nmitem.pszText = infoPtr->items[iItem].pszText; */
|
---|
466 | /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
|
---|
467 | nmitem.fmt = infoPtr->items[iItem].fmt;
|
---|
468 | nmitem.lParam = infoPtr->items[iItem].lParam;
|
---|
469 | nmitem.iOrder = infoPtr->items[iItem].iOrder;
|
---|
470 | nmitem.iImage = infoPtr->items[iItem].iImage;
|
---|
471 |
|
---|
472 | return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
|
---|
473 | (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
|
---|
474 | }
|
---|
475 |
|
---|
476 |
|
---|
477 | static BOOL
|
---|
478 | HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
|
---|
479 | {
|
---|
480 | NMHEADERA nmhdr;
|
---|
481 |
|
---|
482 | nmhdr.hdr.hwndFrom = hwnd;
|
---|
483 | nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
|
---|
484 | nmhdr.hdr.code = code;
|
---|
485 | nmhdr.iItem = iItem;
|
---|
486 | nmhdr.iButton = 0;
|
---|
487 | nmhdr.pitem = NULL;
|
---|
488 |
|
---|
489 | return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
|
---|
490 | (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
|
---|
491 | }
|
---|
492 |
|
---|
493 |
|
---|
494 | static LRESULT
|
---|
495 | HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
|
---|
496 | {
|
---|
497 | // FIXME (header, "empty stub!\n");
|
---|
498 | return 0;
|
---|
499 | }
|
---|
500 |
|
---|
501 |
|
---|
502 | static LRESULT
|
---|
503 | HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
|
---|
504 | {
|
---|
505 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
|
---|
506 | INT iItem = (INT)wParam;
|
---|
507 | HDC hdc;
|
---|
508 |
|
---|
509 | // TRACE(header, "[iItem=%d]\n", iItem);
|
---|
510 |
|
---|
511 | if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
|
---|
512 | return FALSE;
|
---|
513 |
|
---|
514 | if (infoPtr->uNumItem == 1) {
|
---|
515 | // TRACE(header, "Simple delete!\n");
|
---|
516 | if (infoPtr->items[0].pszText)
|
---|
517 | COMCTL32_Free (infoPtr->items[0].pszText);
|
---|
518 | COMCTL32_Free (infoPtr->items);
|
---|
519 | infoPtr->items = 0;
|
---|
520 | infoPtr->uNumItem = 0;
|
---|
521 | }
|
---|
522 | else {
|
---|
523 | HEADER_ITEM *oldItems = infoPtr->items;
|
---|
524 | // TRACE(header, "Complex delete! [iItem=%d]\n", iItem);
|
---|
525 |
|
---|
526 | if (infoPtr->items[iItem].pszText)
|
---|
527 | COMCTL32_Free (infoPtr->items[iItem].pszText);
|
---|
528 |
|
---|
529 | infoPtr->uNumItem--;
|
---|
530 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
|
---|
531 | /* pre delete copy */
|
---|
532 | if (iItem > 0) {
|
---|
533 | memcpy (&infoPtr->items[0], &oldItems[0],
|
---|
534 | iItem * sizeof(HEADER_ITEM));
|
---|
535 | }
|
---|
536 |
|
---|
537 | /* post delete copy */
|
---|
538 | if (iItem < infoPtr->uNumItem) {
|
---|
539 | memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
|
---|
540 | (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
|
---|
541 | }
|
---|
542 |
|
---|
543 | COMCTL32_Free (oldItems);
|
---|
544 | }
|
---|
545 |
|
---|
546 | HEADER_SetItemBounds (hwnd);
|
---|
547 |
|
---|
548 | hdc = GetDC (hwnd);
|
---|
549 | HEADER_Refresh (hwnd, hdc);
|
---|
550 | ReleaseDC (hwnd, hdc);
|
---|
551 |
|
---|
552 | return TRUE;
|
---|
553 | }
|
---|
554 |
|
---|
555 |
|
---|
556 | static LRESULT
|
---|
557 | HEADER_GetImageList (HWND hwnd)
|
---|
558 | {
|
---|
559 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
560 |
|
---|
561 | return (LRESULT)infoPtr->himl;
|
---|
562 | }
|
---|
563 |
|
---|
564 |
|
---|
565 | static LRESULT
|
---|
566 | HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
567 | {
|
---|
568 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
569 | HDITEMA *phdi = (HDITEMA*)lParam;
|
---|
570 | INT nItem = (INT)wParam;
|
---|
571 | HEADER_ITEM *lpItem;
|
---|
572 |
|
---|
573 | if (!phdi)
|
---|
574 | return FALSE;
|
---|
575 | if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
|
---|
576 | return FALSE;
|
---|
577 |
|
---|
578 | // TRACE (header, "[nItem=%d]\n", nItem);
|
---|
579 |
|
---|
580 | if (phdi->mask == 0)
|
---|
581 | return TRUE;
|
---|
582 |
|
---|
583 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
---|
584 | if (phdi->mask & HDI_BITMAP)
|
---|
585 | phdi->hbm = lpItem->hbm;
|
---|
586 |
|
---|
587 | if (phdi->mask & HDI_FORMAT)
|
---|
588 | phdi->fmt = lpItem->fmt;
|
---|
589 |
|
---|
590 | if (phdi->mask & HDI_WIDTH)
|
---|
591 | phdi->cxy = lpItem->cxy;
|
---|
592 |
|
---|
593 | if (phdi->mask & HDI_LPARAM)
|
---|
594 | phdi->lParam = lpItem->lParam;
|
---|
595 |
|
---|
596 | if (phdi->mask & HDI_TEXT) {
|
---|
597 | if (lpItem->pszText != LPSTR_TEXTCALLBACKW)
|
---|
598 | lstrcpynWtoA (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
|
---|
599 | else
|
---|
600 | phdi->pszText = LPSTR_TEXTCALLBACKA;
|
---|
601 | }
|
---|
602 |
|
---|
603 | if (phdi->mask & HDI_IMAGE)
|
---|
604 | phdi->iImage = lpItem->iImage;
|
---|
605 |
|
---|
606 | if (phdi->mask & HDI_ORDER)
|
---|
607 | phdi->iOrder = lpItem->iOrder;
|
---|
608 |
|
---|
609 | return TRUE;
|
---|
610 | }
|
---|
611 |
|
---|
612 |
|
---|
613 | static LRESULT
|
---|
614 | HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
615 | {
|
---|
616 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
617 | HDITEMW *phdi = (HDITEMW*)lParam;
|
---|
618 | INT nItem = (INT)wParam;
|
---|
619 | HEADER_ITEM *lpItem;
|
---|
620 |
|
---|
621 | if (!phdi)
|
---|
622 | return FALSE;
|
---|
623 | if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
|
---|
624 | return FALSE;
|
---|
625 |
|
---|
626 | // TRACE (header, "[nItem=%d]\n", nItem);
|
---|
627 |
|
---|
628 | if (phdi->mask == 0)
|
---|
629 | return TRUE;
|
---|
630 |
|
---|
631 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
---|
632 | if (phdi->mask & HDI_BITMAP)
|
---|
633 | phdi->hbm = lpItem->hbm;
|
---|
634 |
|
---|
635 | if (phdi->mask & HDI_FORMAT)
|
---|
636 | phdi->fmt = lpItem->fmt;
|
---|
637 |
|
---|
638 | if (phdi->mask & HDI_WIDTH)
|
---|
639 | phdi->cxy = lpItem->cxy;
|
---|
640 |
|
---|
641 | if (phdi->mask & HDI_LPARAM)
|
---|
642 | phdi->lParam = lpItem->lParam;
|
---|
643 |
|
---|
644 | if (phdi->mask & HDI_TEXT) {
|
---|
645 | if (lpItem->pszText != LPSTR_TEXTCALLBACKW)
|
---|
646 | lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
|
---|
647 | else
|
---|
648 | phdi->pszText = LPSTR_TEXTCALLBACKW;
|
---|
649 | }
|
---|
650 |
|
---|
651 | if (phdi->mask & HDI_IMAGE)
|
---|
652 | phdi->iImage = lpItem->iImage;
|
---|
653 |
|
---|
654 | if (phdi->mask & HDI_ORDER)
|
---|
655 | phdi->iOrder = lpItem->iOrder;
|
---|
656 |
|
---|
657 | return TRUE;
|
---|
658 | }
|
---|
659 |
|
---|
660 |
|
---|
661 | static LRESULT
|
---|
662 | HEADER_GetItemCount (HWND hwnd)
|
---|
663 | {
|
---|
664 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
665 | return infoPtr->uNumItem;
|
---|
666 | }
|
---|
667 |
|
---|
668 |
|
---|
669 | static LRESULT
|
---|
670 | HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
671 | {
|
---|
672 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
673 | INT iItem = (INT)wParam;
|
---|
674 | LPRECT lpRect = (LPRECT)lParam;
|
---|
675 |
|
---|
676 | if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
|
---|
677 | return FALSE;
|
---|
678 |
|
---|
679 | lpRect->left = infoPtr->items[iItem].rect.left;
|
---|
680 | lpRect->right = infoPtr->items[iItem].rect.right;
|
---|
681 | lpRect->top = infoPtr->items[iItem].rect.top;
|
---|
682 | lpRect->bottom = infoPtr->items[iItem].rect.bottom;
|
---|
683 |
|
---|
684 | return TRUE;
|
---|
685 | }
|
---|
686 |
|
---|
687 |
|
---|
688 | /* << HEADER_GetOrderArray >> */
|
---|
689 |
|
---|
690 |
|
---|
691 | static LRESULT
|
---|
692 | HEADER_GetUnicodeFormat (HWND hwnd)
|
---|
693 | {
|
---|
694 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
695 | return infoPtr->bUnicode;
|
---|
696 | }
|
---|
697 |
|
---|
698 |
|
---|
699 | static LRESULT
|
---|
700 | HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
701 | {
|
---|
702 | LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
|
---|
703 |
|
---|
704 | HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
|
---|
705 |
|
---|
706 | return phti->flags;
|
---|
707 | }
|
---|
708 |
|
---|
709 |
|
---|
710 | static LRESULT
|
---|
711 | HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
712 | {
|
---|
713 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
714 | HDITEMA *phdi = (HDITEMA*)lParam;
|
---|
715 | INT nItem = (INT)wParam;
|
---|
716 | HEADER_ITEM *lpItem;
|
---|
717 | HDC hdc;
|
---|
718 | INT len;
|
---|
719 |
|
---|
720 | if ((phdi == NULL) || (nItem < 0))
|
---|
721 | return -1;
|
---|
722 |
|
---|
723 | if (nItem > infoPtr->uNumItem)
|
---|
724 | nItem = infoPtr->uNumItem;
|
---|
725 |
|
---|
726 | if (infoPtr->uNumItem == 0) {
|
---|
727 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
|
---|
728 | infoPtr->uNumItem++;
|
---|
729 | }
|
---|
730 | else {
|
---|
731 | HEADER_ITEM *oldItems = infoPtr->items;
|
---|
732 |
|
---|
733 | infoPtr->uNumItem++;
|
---|
734 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
|
---|
735 | if (nItem == 0) {
|
---|
736 | memcpy (&infoPtr->items[1], &oldItems[0],
|
---|
737 | (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
|
---|
738 | }
|
---|
739 | else
|
---|
740 | {
|
---|
741 | /* pre insert copy */
|
---|
742 | if (nItem > 0) {
|
---|
743 | memcpy (&infoPtr->items[0], &oldItems[0],
|
---|
744 | nItem * sizeof(HEADER_ITEM));
|
---|
745 | }
|
---|
746 |
|
---|
747 | /* post insert copy */
|
---|
748 | if (nItem < infoPtr->uNumItem - 1) {
|
---|
749 | memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
|
---|
750 | (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
|
---|
751 | }
|
---|
752 | }
|
---|
753 |
|
---|
754 | COMCTL32_Free (oldItems);
|
---|
755 | }
|
---|
756 |
|
---|
757 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
---|
758 | lpItem->bDown = FALSE;
|
---|
759 |
|
---|
760 | if (phdi->mask & HDI_WIDTH)
|
---|
761 | lpItem->cxy = phdi->cxy;
|
---|
762 |
|
---|
763 | if (phdi->mask & HDI_TEXT) {
|
---|
764 | if (!phdi->pszText) /* null pointer check */
|
---|
765 | phdi->pszText = "";
|
---|
766 | if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
|
---|
767 | len = lstrlenA (phdi->pszText);
|
---|
768 | lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
|
---|
769 | lstrcpyAtoW (lpItem->pszText, phdi->pszText);
|
---|
770 | }
|
---|
771 | else
|
---|
772 | lpItem->pszText = LPSTR_TEXTCALLBACKW;
|
---|
773 | }
|
---|
774 |
|
---|
775 | if (phdi->mask & HDI_FORMAT)
|
---|
776 | lpItem->fmt = phdi->fmt;
|
---|
777 |
|
---|
778 | if (lpItem->fmt == 0)
|
---|
779 | lpItem->fmt = HDF_LEFT;
|
---|
780 |
|
---|
781 | if (phdi->mask & HDI_BITMAP)
|
---|
782 | lpItem->hbm = phdi->hbm;
|
---|
783 |
|
---|
784 | if (phdi->mask & HDI_LPARAM)
|
---|
785 | lpItem->lParam = phdi->lParam;
|
---|
786 |
|
---|
787 | if (phdi->mask & HDI_IMAGE)
|
---|
788 | lpItem->iImage = phdi->iImage;
|
---|
789 |
|
---|
790 | if (phdi->mask & HDI_ORDER)
|
---|
791 | lpItem->iOrder = phdi->iOrder;
|
---|
792 |
|
---|
793 | HEADER_SetItemBounds (hwnd);
|
---|
794 |
|
---|
795 | hdc = GetDC (hwnd);
|
---|
796 | HEADER_Refresh (hwnd, hdc);
|
---|
797 | ReleaseDC (hwnd, hdc);
|
---|
798 |
|
---|
799 | return nItem;
|
---|
800 | }
|
---|
801 |
|
---|
802 |
|
---|
803 | static LRESULT
|
---|
804 | HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
805 | {
|
---|
806 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
807 | HDITEMW *phdi = (HDITEMW*)lParam;
|
---|
808 | INT nItem = (INT)wParam;
|
---|
809 | HEADER_ITEM *lpItem;
|
---|
810 | HDC hdc;
|
---|
811 | INT len;
|
---|
812 |
|
---|
813 | if ((phdi == NULL) || (nItem < 0))
|
---|
814 | return -1;
|
---|
815 |
|
---|
816 | if (nItem > infoPtr->uNumItem)
|
---|
817 | nItem = infoPtr->uNumItem;
|
---|
818 |
|
---|
819 | if (infoPtr->uNumItem == 0) {
|
---|
820 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
|
---|
821 | infoPtr->uNumItem++;
|
---|
822 | }
|
---|
823 | else {
|
---|
824 | HEADER_ITEM *oldItems = infoPtr->items;
|
---|
825 |
|
---|
826 | infoPtr->uNumItem++;
|
---|
827 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
|
---|
828 | /* pre insert copy */
|
---|
829 | if (nItem > 0) {
|
---|
830 | memcpy (&infoPtr->items[0], &oldItems[0],
|
---|
831 | nItem * sizeof(HEADER_ITEM));
|
---|
832 | }
|
---|
833 |
|
---|
834 | /* post insert copy */
|
---|
835 | if (nItem < infoPtr->uNumItem - 1) {
|
---|
836 | memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
|
---|
837 | (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
|
---|
838 | }
|
---|
839 |
|
---|
840 | COMCTL32_Free (oldItems);
|
---|
841 | }
|
---|
842 |
|
---|
843 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
---|
844 | lpItem->bDown = FALSE;
|
---|
845 |
|
---|
846 | if (phdi->mask & HDI_WIDTH)
|
---|
847 | lpItem->cxy = phdi->cxy;
|
---|
848 |
|
---|
849 | if (phdi->mask & HDI_TEXT) {
|
---|
850 | WCHAR wide_null_char = 0;
|
---|
851 | if (!phdi->pszText) /* null pointer check */
|
---|
852 | phdi->pszText = &wide_null_char;
|
---|
853 | if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
|
---|
854 | len = lstrlenW (phdi->pszText);
|
---|
855 | lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
|
---|
856 | lstrcpyW (lpItem->pszText, phdi->pszText);
|
---|
857 | }
|
---|
858 | else
|
---|
859 | lpItem->pszText = LPSTR_TEXTCALLBACKW;
|
---|
860 | }
|
---|
861 |
|
---|
862 | if (phdi->mask & HDI_FORMAT)
|
---|
863 | lpItem->fmt = phdi->fmt;
|
---|
864 |
|
---|
865 | if (lpItem->fmt == 0)
|
---|
866 | lpItem->fmt = HDF_LEFT;
|
---|
867 |
|
---|
868 | if (phdi->mask & HDI_BITMAP)
|
---|
869 | lpItem->hbm = phdi->hbm;
|
---|
870 |
|
---|
871 | if (phdi->mask & HDI_LPARAM)
|
---|
872 | lpItem->lParam = phdi->lParam;
|
---|
873 |
|
---|
874 | if (phdi->mask & HDI_IMAGE)
|
---|
875 | lpItem->iImage = phdi->iImage;
|
---|
876 |
|
---|
877 | if (phdi->mask & HDI_ORDER)
|
---|
878 | lpItem->iOrder = phdi->iOrder;
|
---|
879 |
|
---|
880 | HEADER_SetItemBounds (hwnd);
|
---|
881 |
|
---|
882 | hdc = GetDC (hwnd);
|
---|
883 | HEADER_Refresh (hwnd, hdc);
|
---|
884 | ReleaseDC (hwnd, hdc);
|
---|
885 |
|
---|
886 | return nItem;
|
---|
887 | }
|
---|
888 |
|
---|
889 |
|
---|
890 | static LRESULT
|
---|
891 | HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
892 | {
|
---|
893 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
894 | LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
|
---|
895 |
|
---|
896 | lpLayout->pwpos->hwnd = hwnd;
|
---|
897 | lpLayout->pwpos->hwndInsertAfter = 0;
|
---|
898 | lpLayout->pwpos->x = lpLayout->prc->left;
|
---|
899 | lpLayout->pwpos->y = lpLayout->prc->top;
|
---|
900 | lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
|
---|
901 | if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
|
---|
902 | lpLayout->pwpos->cy = 0;
|
---|
903 | else
|
---|
904 | lpLayout->pwpos->cy = infoPtr->nHeight;
|
---|
905 | lpLayout->pwpos->flags = SWP_NOZORDER;
|
---|
906 |
|
---|
907 | // TRACE (header, "Layout x=%d y=%d cx=%d cy=%d\n",
|
---|
908 | // lpLayout->pwpos->x, lpLayout->pwpos->y,
|
---|
909 | // lpLayout->pwpos->cx, lpLayout->pwpos->cy);
|
---|
910 |
|
---|
911 | HEADER_ForceItemBounds (hwnd, lpLayout->pwpos->cy);
|
---|
912 |
|
---|
913 | /* hack */
|
---|
914 | #ifdef __HDM_LAYOUT_HACK__
|
---|
915 | MoveWindow (lpLayout->pwpos->hwnd, lpLayout->pwpos->x, lpLayout->pwpos->y,
|
---|
916 | lpLayout->pwpos->cx, lpLayout->pwpos->cy, TRUE);
|
---|
917 | #endif
|
---|
918 |
|
---|
919 | return TRUE;
|
---|
920 | }
|
---|
921 |
|
---|
922 |
|
---|
923 | static LRESULT
|
---|
924 | HEADER_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
925 | {
|
---|
926 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
927 | HIMAGELIST himlOld;
|
---|
928 |
|
---|
929 | himlOld = infoPtr->himl;
|
---|
930 | infoPtr->himl = (HIMAGELIST)lParam;
|
---|
931 |
|
---|
932 | /* FIXME: Refresh needed??? */
|
---|
933 |
|
---|
934 | return (LRESULT)himlOld;
|
---|
935 | }
|
---|
936 |
|
---|
937 |
|
---|
938 | static LRESULT
|
---|
939 | HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
940 | {
|
---|
941 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
942 | HDITEMA *phdi = (HDITEMA*)lParam;
|
---|
943 | INT nItem = (INT)wParam;
|
---|
944 | HEADER_ITEM *lpItem;
|
---|
945 | HDC hdc;
|
---|
946 |
|
---|
947 | if (phdi == NULL)
|
---|
948 | return FALSE;
|
---|
949 | if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
|
---|
950 | return FALSE;
|
---|
951 |
|
---|
952 | // TRACE (header, "[nItem=%d]\n", nItem);
|
---|
953 |
|
---|
954 | if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem))
|
---|
955 | return FALSE;
|
---|
956 |
|
---|
957 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
---|
958 | if (phdi->mask & HDI_BITMAP)
|
---|
959 | lpItem->hbm = phdi->hbm;
|
---|
960 |
|
---|
961 | if (phdi->mask & HDI_FORMAT)
|
---|
962 | lpItem->fmt = phdi->fmt;
|
---|
963 |
|
---|
964 | if (phdi->mask & HDI_LPARAM)
|
---|
965 | lpItem->lParam = phdi->lParam;
|
---|
966 |
|
---|
967 | if (phdi->mask & HDI_TEXT) {
|
---|
968 | if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
|
---|
969 | if (lpItem->pszText) {
|
---|
970 | COMCTL32_Free (lpItem->pszText);
|
---|
971 | lpItem->pszText = NULL;
|
---|
972 | }
|
---|
973 | if (phdi->pszText) {
|
---|
974 | INT len = lstrlenA (phdi->pszText);
|
---|
975 | lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
|
---|
976 | lstrcpyAtoW (lpItem->pszText, phdi->pszText);
|
---|
977 | }
|
---|
978 | }
|
---|
979 | else
|
---|
980 | lpItem->pszText = LPSTR_TEXTCALLBACKW;
|
---|
981 | }
|
---|
982 |
|
---|
983 | if (phdi->mask & HDI_WIDTH)
|
---|
984 | lpItem->cxy = phdi->cxy;
|
---|
985 |
|
---|
986 | if (phdi->mask & HDI_IMAGE)
|
---|
987 | lpItem->iImage = phdi->iImage;
|
---|
988 |
|
---|
989 | if (phdi->mask & HDI_ORDER)
|
---|
990 | lpItem->iOrder = phdi->iOrder;
|
---|
991 |
|
---|
992 | HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem);
|
---|
993 |
|
---|
994 | HEADER_SetItemBounds (hwnd);
|
---|
995 | hdc = GetDC (hwnd);
|
---|
996 | HEADER_Refresh (hwnd, hdc);
|
---|
997 | ReleaseDC (hwnd, hdc);
|
---|
998 |
|
---|
999 | return TRUE;
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 |
|
---|
1003 | static LRESULT
|
---|
1004 | HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1005 | {
|
---|
1006 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
1007 | HDITEMW *phdi = (HDITEMW*)lParam;
|
---|
1008 | INT nItem = (INT)wParam;
|
---|
1009 | HEADER_ITEM *lpItem;
|
---|
1010 | HDC hdc;
|
---|
1011 |
|
---|
1012 | if (phdi == NULL)
|
---|
1013 | return FALSE;
|
---|
1014 | if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
|
---|
1015 | return FALSE;
|
---|
1016 |
|
---|
1017 | // TRACE (header, "[nItem=%d]\n", nItem);
|
---|
1018 |
|
---|
1019 | if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem))
|
---|
1020 | return FALSE;
|
---|
1021 |
|
---|
1022 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
---|
1023 | if (phdi->mask & HDI_BITMAP)
|
---|
1024 | lpItem->hbm = phdi->hbm;
|
---|
1025 |
|
---|
1026 | if (phdi->mask & HDI_FORMAT)
|
---|
1027 | lpItem->fmt = phdi->fmt;
|
---|
1028 |
|
---|
1029 | if (phdi->mask & HDI_LPARAM)
|
---|
1030 | lpItem->lParam = phdi->lParam;
|
---|
1031 |
|
---|
1032 | if (phdi->mask & HDI_TEXT) {
|
---|
1033 | if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
|
---|
1034 | if (lpItem->pszText) {
|
---|
1035 | COMCTL32_Free (lpItem->pszText);
|
---|
1036 | lpItem->pszText = NULL;
|
---|
1037 | }
|
---|
1038 | if (phdi->pszText) {
|
---|
1039 | INT len = lstrlenW (phdi->pszText);
|
---|
1040 | lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
|
---|
1041 | lstrcpyW (lpItem->pszText, phdi->pszText);
|
---|
1042 | }
|
---|
1043 | }
|
---|
1044 | else
|
---|
1045 | lpItem->pszText = LPSTR_TEXTCALLBACKW;
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | if (phdi->mask & HDI_WIDTH)
|
---|
1049 | lpItem->cxy = phdi->cxy;
|
---|
1050 |
|
---|
1051 | if (phdi->mask & HDI_IMAGE)
|
---|
1052 | lpItem->iImage = phdi->iImage;
|
---|
1053 |
|
---|
1054 | if (phdi->mask & HDI_ORDER)
|
---|
1055 | lpItem->iOrder = phdi->iOrder;
|
---|
1056 |
|
---|
1057 | HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem);
|
---|
1058 |
|
---|
1059 | HEADER_SetItemBounds (hwnd);
|
---|
1060 | hdc = GetDC (hwnd);
|
---|
1061 | HEADER_Refresh (hwnd, hdc);
|
---|
1062 | ReleaseDC (hwnd, hdc);
|
---|
1063 |
|
---|
1064 | return TRUE;
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 |
|
---|
1068 | /* << HEADER_SetOrderArray >> */
|
---|
1069 |
|
---|
1070 |
|
---|
1071 | static LRESULT
|
---|
1072 | HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
|
---|
1073 | {
|
---|
1074 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
1075 | BOOL bTemp = infoPtr->bUnicode;
|
---|
1076 |
|
---|
1077 | infoPtr->bUnicode = (BOOL)wParam;
|
---|
1078 |
|
---|
1079 | return bTemp;
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 |
|
---|
1083 | static LRESULT
|
---|
1084 | HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1085 | {
|
---|
1086 | HEADER_INFO *infoPtr;
|
---|
1087 | TEXTMETRICA tm;
|
---|
1088 | HFONT hOldFont;
|
---|
1089 | HDC hdc;
|
---|
1090 |
|
---|
1091 | infoPtr = (HEADER_INFO *)COMCTL32_Alloc (sizeof(HEADER_INFO));
|
---|
1092 | SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
|
---|
1093 |
|
---|
1094 | infoPtr->uNumItem = 0;
|
---|
1095 | infoPtr->nHeight = 20;
|
---|
1096 | infoPtr->hFont = 0;
|
---|
1097 | infoPtr->items = 0;
|
---|
1098 | infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
|
---|
1099 | infoPtr->hcurDivider = LoadCursorA (0, IDC_SIZEWEA);
|
---|
1100 | infoPtr->hcurDivopen = LoadCursorA (0, IDC_SIZENSA);
|
---|
1101 | infoPtr->bPressed = FALSE;
|
---|
1102 | infoPtr->bTracking = FALSE;
|
---|
1103 | infoPtr->iMoveItem = 0;
|
---|
1104 | infoPtr->himl = 0;
|
---|
1105 | infoPtr->iHotItem = -1;
|
---|
1106 | infoPtr->bUnicode = IsWindowUnicode (hwnd);
|
---|
1107 |
|
---|
1108 | hdc = GetDC (0);
|
---|
1109 | hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
|
---|
1110 | GetTextMetricsA (hdc, &tm);
|
---|
1111 | infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
|
---|
1112 | SelectObject (hdc, hOldFont);
|
---|
1113 | ReleaseDC (0, hdc);
|
---|
1114 |
|
---|
1115 | return 0;
|
---|
1116 | }
|
---|
1117 |
|
---|
1118 |
|
---|
1119 | static LRESULT
|
---|
1120 | HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1121 | {
|
---|
1122 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
1123 | HEADER_ITEM *lpItem;
|
---|
1124 | INT nItem;
|
---|
1125 |
|
---|
1126 | if (infoPtr->items) {
|
---|
1127 | lpItem = (HEADER_ITEM*)infoPtr->items;
|
---|
1128 | for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
|
---|
1129 | if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
|
---|
1130 | COMCTL32_Free (lpItem->pszText);
|
---|
1131 | }
|
---|
1132 | COMCTL32_Free (infoPtr->items);
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | if (infoPtr->himl)
|
---|
1136 | ImageList_Destroy (infoPtr->himl);
|
---|
1137 |
|
---|
1138 | COMCTL32_Free (infoPtr);
|
---|
1139 |
|
---|
1140 | return 0;
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 |
|
---|
1144 | static LRESULT
|
---|
1145 | HEADER_GetFont (HWND hwnd)
|
---|
1146 | {
|
---|
1147 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
1148 |
|
---|
1149 | return (LRESULT)infoPtr->hFont;
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 |
|
---|
1153 | static LRESULT
|
---|
1154 | HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1155 | {
|
---|
1156 | POINT pt;
|
---|
1157 | UINT flags;
|
---|
1158 | INT nItem;
|
---|
1159 |
|
---|
1160 | pt.x = (INT)LOWORD(lParam);
|
---|
1161 | pt.y = (INT)HIWORD(lParam);
|
---|
1162 | HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
|
---|
1163 |
|
---|
1164 | if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
|
---|
1165 | HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem);
|
---|
1166 | else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
|
---|
1167 | HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem);
|
---|
1168 |
|
---|
1169 | return 0;
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 |
|
---|
1173 | static LRESULT
|
---|
1174 | HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1175 | {
|
---|
1176 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
1177 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
|
---|
1178 | POINT pt;
|
---|
1179 | UINT flags;
|
---|
1180 | INT nItem;
|
---|
1181 | HDC hdc;
|
---|
1182 |
|
---|
1183 | pt.x = (INT)LOWORD(lParam);
|
---|
1184 | pt.y = (INT)HIWORD(lParam);
|
---|
1185 | HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
|
---|
1186 |
|
---|
1187 | if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
|
---|
1188 | SetCapture (hwnd);
|
---|
1189 | infoPtr->bCaptured = TRUE;
|
---|
1190 | infoPtr->bPressed = TRUE;
|
---|
1191 | infoPtr->iMoveItem = nItem;
|
---|
1192 |
|
---|
1193 | infoPtr->items[nItem].bDown = TRUE;
|
---|
1194 |
|
---|
1195 | /* Send WM_CUSTOMDRAW */
|
---|
1196 | hdc = GetDC (hwnd);
|
---|
1197 | HEADER_RefreshItem (hwnd, hdc, nItem);
|
---|
1198 | ReleaseDC (hwnd, hdc);
|
---|
1199 |
|
---|
1200 | // TRACE (header, "Pressed item %d!\n", nItem);
|
---|
1201 | }
|
---|
1202 | else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
|
---|
1203 | if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem))) {
|
---|
1204 | SetCapture (hwnd);
|
---|
1205 | infoPtr->bCaptured = TRUE;
|
---|
1206 | infoPtr->bTracking = TRUE;
|
---|
1207 | infoPtr->iMoveItem = nItem;
|
---|
1208 | infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
|
---|
1209 | infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
|
---|
1210 |
|
---|
1211 | if (!(dwStyle & HDS_FULLDRAG)) {
|
---|
1212 | infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
|
---|
1213 | hdc = GetDC (hwnd);
|
---|
1214 | HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
|
---|
1215 | ReleaseDC (hwnd, hdc);
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | // TRACE (header, "Begin tracking item %d!\n", nItem);
|
---|
1219 | }
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | return 0;
|
---|
1223 | }
|
---|
1224 |
|
---|
1225 |
|
---|
1226 | static LRESULT
|
---|
1227 | HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1228 | {
|
---|
1229 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
1230 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
|
---|
1231 | POINT pt;
|
---|
1232 | UINT flags;
|
---|
1233 | INT nItem, nWidth;
|
---|
1234 | HDC hdc;
|
---|
1235 |
|
---|
1236 | pt.x = (INT)LOWORD(lParam);
|
---|
1237 | pt.y = (INT)HIWORD(lParam);
|
---|
1238 | HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
|
---|
1239 |
|
---|
1240 | if (infoPtr->bPressed) {
|
---|
1241 | if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
|
---|
1242 | infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
|
---|
1243 | hdc = GetDC (hwnd);
|
---|
1244 | HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
|
---|
1245 | ReleaseDC (hwnd, hdc);
|
---|
1246 |
|
---|
1247 | HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
|
---|
1248 | }
|
---|
1249 | // TRACE (header, "Released item %d!\n", infoPtr->iMoveItem);
|
---|
1250 | infoPtr->bPressed = FALSE;
|
---|
1251 | }
|
---|
1252 | else if (infoPtr->bTracking) {
|
---|
1253 | // TRACE (header, "End tracking item %d!\n", infoPtr->iMoveItem);
|
---|
1254 | infoPtr->bTracking = FALSE;
|
---|
1255 |
|
---|
1256 | HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem);
|
---|
1257 |
|
---|
1258 | if (!(dwStyle & HDS_FULLDRAG)) {
|
---|
1259 | hdc = GetDC (hwnd);
|
---|
1260 | HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
|
---|
1261 | ReleaseDC (hwnd, hdc);
|
---|
1262 | if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem))
|
---|
1263 | infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
|
---|
1264 | else {
|
---|
1265 | nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
|
---|
1266 | if (nWidth < 0)
|
---|
1267 | nWidth = 0;
|
---|
1268 | infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
|
---|
1269 | HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem);
|
---|
1270 | }
|
---|
1271 |
|
---|
1272 | HEADER_SetItemBounds (hwnd);
|
---|
1273 | hdc = GetDC (hwnd);
|
---|
1274 | HEADER_Refresh (hwnd, hdc);
|
---|
1275 | ReleaseDC (hwnd, hdc);
|
---|
1276 | }
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | if (infoPtr->bCaptured) {
|
---|
1280 | infoPtr->bCaptured = FALSE;
|
---|
1281 | ReleaseCapture ();
|
---|
1282 | HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 | return 0;
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 |
|
---|
1289 | static LRESULT
|
---|
1290 | HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1291 | {
|
---|
1292 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
1293 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
|
---|
1294 | POINT pt;
|
---|
1295 | UINT flags;
|
---|
1296 | INT nItem, nWidth;
|
---|
1297 | HDC hdc;
|
---|
1298 |
|
---|
1299 | pt.x = (INT)LOWORD(lParam);
|
---|
1300 | pt.y = (INT)HIWORD(lParam);
|
---|
1301 | HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
|
---|
1302 |
|
---|
1303 | if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
|
---|
1304 | if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
|
---|
1305 | infoPtr->iHotItem = nItem;
|
---|
1306 | else
|
---|
1307 | infoPtr->iHotItem = -1;
|
---|
1308 | hdc = GetDC (hwnd);
|
---|
1309 | HEADER_Refresh (hwnd, hdc);
|
---|
1310 | ReleaseDC (hwnd, hdc);
|
---|
1311 | }
|
---|
1312 |
|
---|
1313 | if (infoPtr->bCaptured) {
|
---|
1314 | if (infoPtr->bPressed) {
|
---|
1315 | if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
|
---|
1316 | infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
|
---|
1317 | else
|
---|
1318 | infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
|
---|
1319 | hdc = GetDC (hwnd);
|
---|
1320 | HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
|
---|
1321 | ReleaseDC (hwnd, hdc);
|
---|
1322 |
|
---|
1323 | // TRACE (header, "Moving pressed item %d!\n", infoPtr->iMoveItem);
|
---|
1324 | }
|
---|
1325 | else if (infoPtr->bTracking) {
|
---|
1326 | if (dwStyle & HDS_FULLDRAG) {
|
---|
1327 | if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem))
|
---|
1328 | infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
|
---|
1329 | else {
|
---|
1330 | nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
|
---|
1331 | if (nWidth < 0)
|
---|
1332 | nWidth = 0;
|
---|
1333 | infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
|
---|
1334 | HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA,
|
---|
1335 | infoPtr->iMoveItem);
|
---|
1336 | }
|
---|
1337 | HEADER_SetItemBounds (hwnd);
|
---|
1338 | hdc = GetDC (hwnd);
|
---|
1339 | HEADER_Refresh (hwnd, hdc);
|
---|
1340 | ReleaseDC (hwnd, hdc);
|
---|
1341 | }
|
---|
1342 | else {
|
---|
1343 | hdc = GetDC (hwnd);
|
---|
1344 | HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
|
---|
1345 | infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
|
---|
1346 | if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
|
---|
1347 | infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
|
---|
1348 | infoPtr->items[infoPtr->iMoveItem].cxy =
|
---|
1349 | infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
|
---|
1350 | HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
|
---|
1351 | ReleaseDC (hwnd, hdc);
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem);
|
---|
1355 | // TRACE (header, "Tracking item %d!\n", infoPtr->iMoveItem);
|
---|
1356 | }
|
---|
1357 | }
|
---|
1358 |
|
---|
1359 | if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
|
---|
1360 | // FIXME (header, "hot track support!\n");
|
---|
1361 | }
|
---|
1362 |
|
---|
1363 | return 0;
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 |
|
---|
1367 | static LRESULT
|
---|
1368 | HEADER_Paint (HWND hwnd, WPARAM wParam)
|
---|
1369 | {
|
---|
1370 | HDC hdc;
|
---|
1371 | PAINTSTRUCT ps;
|
---|
1372 |
|
---|
1373 | hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
|
---|
1374 | HEADER_Refresh (hwnd, hdc);
|
---|
1375 | if(!wParam)
|
---|
1376 | EndPaint (hwnd, &ps);
|
---|
1377 | return 0;
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 |
|
---|
1381 | static LRESULT
|
---|
1382 | HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1383 | {
|
---|
1384 | return HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 |
|
---|
1388 | static LRESULT
|
---|
1389 | HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1390 | {
|
---|
1391 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
1392 | POINT pt;
|
---|
1393 | UINT flags;
|
---|
1394 | INT nItem;
|
---|
1395 |
|
---|
1396 | // TRACE (header, "code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
|
---|
1397 |
|
---|
1398 | GetCursorPos (&pt);
|
---|
1399 | ScreenToClient (hwnd, &pt);
|
---|
1400 |
|
---|
1401 | HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
|
---|
1402 |
|
---|
1403 | if (flags == HHT_ONDIVIDER)
|
---|
1404 | SetCursor (infoPtr->hcurDivider);
|
---|
1405 | else if (flags == HHT_ONDIVOPEN)
|
---|
1406 | SetCursor (infoPtr->hcurDivopen);
|
---|
1407 | else
|
---|
1408 | SetCursor (infoPtr->hcurArrow);
|
---|
1409 |
|
---|
1410 | return 0;
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 |
|
---|
1414 | static LRESULT
|
---|
1415 | HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
1416 | {
|
---|
1417 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
---|
1418 | TEXTMETRICA tm;
|
---|
1419 | HFONT hFont, hOldFont;
|
---|
1420 | HDC hdc;
|
---|
1421 |
|
---|
1422 | infoPtr->hFont = (HFONT)wParam;
|
---|
1423 |
|
---|
1424 | hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
|
---|
1425 |
|
---|
1426 | hdc = GetDC (0);
|
---|
1427 | hOldFont = SelectObject (hdc, hFont);
|
---|
1428 | GetTextMetricsA (hdc, &tm);
|
---|
1429 | infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
|
---|
1430 | SelectObject (hdc, hOldFont);
|
---|
1431 | ReleaseDC (0, hdc);
|
---|
1432 |
|
---|
1433 | if (lParam) {
|
---|
1434 | HEADER_ForceItemBounds (hwnd, infoPtr->nHeight);
|
---|
1435 | hdc = GetDC (hwnd);
|
---|
1436 | HEADER_Refresh (hwnd, hdc);
|
---|
1437 | ReleaseDC (hwnd, hdc);
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | return 0;
|
---|
1441 | }
|
---|
1442 |
|
---|
1443 |
|
---|
1444 | LRESULT WINAPI
|
---|
1445 | HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
---|
1446 | {
|
---|
1447 | switch (msg) {
|
---|
1448 | case HDM_CREATEDRAGIMAGE:
|
---|
1449 | return HEADER_CreateDragImage (hwnd, wParam);
|
---|
1450 |
|
---|
1451 | case HDM_DELETEITEM:
|
---|
1452 | return HEADER_DeleteItem (hwnd, wParam);
|
---|
1453 |
|
---|
1454 | case HDM_GETIMAGELIST:
|
---|
1455 | return HEADER_GetImageList (hwnd);
|
---|
1456 |
|
---|
1457 | case HDM_GETITEMA:
|
---|
1458 | return HEADER_GetItemA (hwnd, wParam, lParam);
|
---|
1459 |
|
---|
1460 | case HDM_GETITEMW:
|
---|
1461 | return HEADER_GetItemW (hwnd, wParam, lParam);
|
---|
1462 |
|
---|
1463 | case HDM_GETITEMCOUNT:
|
---|
1464 | return HEADER_GetItemCount (hwnd);
|
---|
1465 |
|
---|
1466 | case HDM_GETITEMRECT:
|
---|
1467 | return HEADER_GetItemRect (hwnd, wParam, lParam);
|
---|
1468 |
|
---|
1469 | /* case HDM_GETORDERARRAY: */
|
---|
1470 |
|
---|
1471 | case HDM_GETUNICODEFORMAT:
|
---|
1472 | return HEADER_GetUnicodeFormat (hwnd);
|
---|
1473 |
|
---|
1474 | case HDM_HITTEST:
|
---|
1475 | return HEADER_HitTest (hwnd, wParam, lParam);
|
---|
1476 |
|
---|
1477 | case HDM_INSERTITEMA:
|
---|
1478 | return HEADER_InsertItemA (hwnd, wParam, lParam);
|
---|
1479 |
|
---|
1480 | case HDM_INSERTITEMW:
|
---|
1481 | return HEADER_InsertItemW (hwnd, wParam, lParam);
|
---|
1482 |
|
---|
1483 | case HDM_LAYOUT:
|
---|
1484 | return HEADER_Layout (hwnd, wParam, lParam);
|
---|
1485 |
|
---|
1486 | case HDM_SETIMAGELIST:
|
---|
1487 | return HEADER_SetImageList (hwnd, wParam, lParam);
|
---|
1488 |
|
---|
1489 | case HDM_SETITEMA:
|
---|
1490 | return HEADER_SetItemA (hwnd, wParam, lParam);
|
---|
1491 |
|
---|
1492 | case HDM_SETITEMW:
|
---|
1493 | return HEADER_SetItemW (hwnd, wParam, lParam);
|
---|
1494 |
|
---|
1495 | /* case HDM_SETORDERARRAY: */
|
---|
1496 |
|
---|
1497 | case HDM_SETUNICODEFORMAT:
|
---|
1498 | return HEADER_SetUnicodeFormat (hwnd, wParam);
|
---|
1499 |
|
---|
1500 |
|
---|
1501 | case WM_CREATE:
|
---|
1502 | return HEADER_Create (hwnd, wParam, lParam);
|
---|
1503 |
|
---|
1504 | case WM_DESTROY:
|
---|
1505 | return HEADER_Destroy (hwnd, wParam, lParam);
|
---|
1506 |
|
---|
1507 | case WM_ERASEBKGND:
|
---|
1508 | return 1;
|
---|
1509 |
|
---|
1510 | case WM_GETDLGCODE:
|
---|
1511 | return DLGC_WANTTAB | DLGC_WANTARROWS;
|
---|
1512 |
|
---|
1513 | case WM_GETFONT:
|
---|
1514 | return HEADER_GetFont (hwnd);
|
---|
1515 |
|
---|
1516 | case WM_LBUTTONDBLCLK:
|
---|
1517 | return HEADER_LButtonDblClk (hwnd, wParam, lParam);
|
---|
1518 |
|
---|
1519 | case WM_LBUTTONDOWN:
|
---|
1520 | return HEADER_LButtonDown (hwnd, wParam, lParam);
|
---|
1521 |
|
---|
1522 | case WM_LBUTTONUP:
|
---|
1523 | return HEADER_LButtonUp (hwnd, wParam, lParam);
|
---|
1524 |
|
---|
1525 | case WM_MOUSEMOVE:
|
---|
1526 | return HEADER_MouseMove (hwnd, wParam, lParam);
|
---|
1527 |
|
---|
1528 | /* case WM_NOTIFYFORMAT: */
|
---|
1529 |
|
---|
1530 | case WM_PAINT:
|
---|
1531 | return HEADER_Paint (hwnd, wParam);
|
---|
1532 |
|
---|
1533 | case WM_RBUTTONUP:
|
---|
1534 | return HEADER_RButtonUp (hwnd, wParam, lParam);
|
---|
1535 |
|
---|
1536 | case WM_SETCURSOR:
|
---|
1537 | return HEADER_SetCursor (hwnd, wParam, lParam);
|
---|
1538 |
|
---|
1539 | case WM_SETFONT:
|
---|
1540 | return HEADER_SetFont (hwnd, wParam, lParam);
|
---|
1541 |
|
---|
1542 | default:
|
---|
1543 | // if (msg >= WM_USER)
|
---|
1544 | // ERR (header, "unknown msg %04x wp=%04x lp=%08lx\n",
|
---|
1545 | // msg, wParam, lParam );
|
---|
1546 | return DefWindowProcA (hwnd, msg, wParam, lParam);
|
---|
1547 | }
|
---|
1548 | return 0;
|
---|
1549 | }
|
---|
1550 |
|
---|
1551 |
|
---|
1552 | VOID
|
---|
1553 | HEADER_Register (VOID)
|
---|
1554 | {
|
---|
1555 | WNDCLASSA wndClass;
|
---|
1556 |
|
---|
1557 | if (GlobalFindAtomA (WC_HEADERA)) return;
|
---|
1558 |
|
---|
1559 | ZeroMemory (&wndClass, sizeof(WNDCLASSA));
|
---|
1560 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
|
---|
1561 | wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
|
---|
1562 | wndClass.cbClsExtra = 0;
|
---|
1563 | wndClass.cbWndExtra = sizeof(HEADER_INFO *);
|
---|
1564 | wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
|
---|
1565 | wndClass.lpszClassName = WC_HEADERA;
|
---|
1566 |
|
---|
1567 | RegisterClassA (&wndClass);
|
---|
1568 | }
|
---|
1569 |
|
---|
1570 |
|
---|
1571 | VOID
|
---|
1572 | HEADER_Unregister (VOID)
|
---|
1573 | {
|
---|
1574 | if (GlobalFindAtomA (WC_HEADERA))
|
---|
1575 | UnregisterClassA (WC_HEADERA, (HINSTANCE)NULL);
|
---|
1576 | }
|
---|
1577 |
|
---|