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