| 1 | /* $Id: header.c,v 1.7 1999-06-30 15:52:16 cbratschi Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Header control
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1998 Eric Kohl
|
|---|
| 6 | * Copyright 1999 Achim Hasenmueller
|
|---|
| 7 | * Copyright 1999 Christoph Bratschi
|
|---|
| 8 | *
|
|---|
| 9 | * TODO:
|
|---|
| 10 | * - Imagelist support (partially).
|
|---|
| 11 | * - Callback items (under construction).
|
|---|
| 12 | * - Order list support.
|
|---|
| 13 | * - Control specific cursors (over dividers).
|
|---|
| 14 | * - Hottrack support (partially).
|
|---|
| 15 | * - Custom draw support (including Notifications).
|
|---|
| 16 | * - Drag and Drop support (including Notifications).
|
|---|
| 17 | * - Unicode support.
|
|---|
| 18 | *
|
|---|
| 19 | * FIXME:
|
|---|
| 20 | * - Replace DrawText32A by DrawTextEx32A(...|DT_ENDELLIPSIS) in
|
|---|
| 21 | * HEADER_DrawItem.
|
|---|
| 22 | * - Little flaw when drawing a bitmap on the right side of the text.
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| 25 | #include <string.h>
|
|---|
| 26 |
|
|---|
| 27 | #include "winbase.h"
|
|---|
| 28 | #include "commctrl.h"
|
|---|
| 29 | #include "header.h"
|
|---|
| 30 | #include "comctl32.h"
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | #define __HDM_LAYOUT_HACK__
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | #define VERT_BORDER 4
|
|---|
| 37 | #define DIVIDER_WIDTH 10
|
|---|
| 38 |
|
|---|
| 39 | #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongA(hwnd,0))
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | static INT
|
|---|
| 43 | HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
|
|---|
| 44 | {
|
|---|
| 45 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 46 | HEADER_ITEM *phdi = &infoPtr->items[iItem];
|
|---|
| 47 | RECT r;
|
|---|
| 48 | INT oldBkMode;
|
|---|
| 49 |
|
|---|
| 50 | r = phdi->rect;
|
|---|
| 51 | if (r.right - r.left == 0)
|
|---|
| 52 | return phdi->rect.right;
|
|---|
| 53 |
|
|---|
| 54 | if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
|
|---|
| 55 | if (phdi->bDown) {
|
|---|
| 56 | DrawEdge (hdc, &r, BDR_RAISEDOUTER,
|
|---|
| 57 | BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
|
|---|
| 58 | r.left += 2;
|
|---|
| 59 | r.top += 2;
|
|---|
| 60 | }
|
|---|
| 61 | else
|
|---|
| 62 | DrawEdge (hdc, &r, EDGE_RAISED,
|
|---|
| 63 | BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
|
|---|
| 64 | }
|
|---|
| 65 | else
|
|---|
| 66 | DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
|
|---|
| 67 |
|
|---|
| 68 | if (phdi->fmt & HDF_OWNERDRAW) {
|
|---|
| 69 | DRAWITEMSTRUCT dis;
|
|---|
| 70 | dis.CtlType = ODT_HEADER;
|
|---|
| 71 | dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
|
|---|
| 72 | dis.itemID = iItem;
|
|---|
| 73 | dis.itemAction = ODA_DRAWENTIRE;
|
|---|
| 74 | dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
|
|---|
| 75 | dis.hwndItem = hwnd;
|
|---|
| 76 | dis.hDC = hdc;
|
|---|
| 77 | dis.rcItem = r;
|
|---|
| 78 | dis.itemData = phdi->lParam;
|
|---|
| 79 | SendMessageA (GetParent (hwnd), WM_DRAWITEM,
|
|---|
| 80 | (WPARAM)dis.CtlID, (LPARAM)&dis);
|
|---|
| 81 | }
|
|---|
| 82 | else {
|
|---|
| 83 | UINT uTextJustify = DT_LEFT;
|
|---|
| 84 |
|
|---|
| 85 | if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
|
|---|
| 86 | uTextJustify = DT_CENTER;
|
|---|
| 87 | else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
|
|---|
| 88 | uTextJustify = DT_RIGHT;
|
|---|
| 89 |
|
|---|
| 90 | if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
|
|---|
| 91 | BITMAP bmp;
|
|---|
| 92 | HDC hdcBitmap;
|
|---|
| 93 | INT yD, yS, cx, cy, rx, ry;
|
|---|
| 94 |
|
|---|
| 95 | GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
|
|---|
| 96 |
|
|---|
| 97 | ry = r.bottom - r.top;
|
|---|
| 98 | rx = r.right - r.left;
|
|---|
| 99 |
|
|---|
| 100 | if (ry >= bmp.bmHeight) {
|
|---|
| 101 | cy = bmp.bmHeight;
|
|---|
| 102 | yD = r.top + (ry - bmp.bmHeight) / 2;
|
|---|
| 103 | yS = 0;
|
|---|
| 104 | }
|
|---|
| 105 | else {
|
|---|
| 106 | cy = ry;
|
|---|
| 107 | yD = r.top;
|
|---|
| 108 | yS = (bmp.bmHeight - ry) / 2;
|
|---|
| 109 |
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | if (rx >= bmp.bmWidth + 6) {
|
|---|
| 113 | cx = bmp.bmWidth;
|
|---|
| 114 | }
|
|---|
| 115 | else {
|
|---|
| 116 | cx = rx - 6;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | hdcBitmap = CreateCompatibleDC (hdc);
|
|---|
| 120 | SelectObject (hdcBitmap, phdi->hbm);
|
|---|
| 121 | BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
|
|---|
| 122 | DeleteDC (hdcBitmap);
|
|---|
| 123 |
|
|---|
| 124 | r.left += (bmp.bmWidth + 3);
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | if ((phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
|
|---|
| 129 | BITMAP bmp;
|
|---|
| 130 | HDC hdcBitmap;
|
|---|
| 131 | INT xD, yD, yS, cx, cy, rx, ry, tx;
|
|---|
| 132 | RECT textRect;
|
|---|
| 133 |
|
|---|
| 134 | GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
|
|---|
| 135 |
|
|---|
| 136 | textRect = r;
|
|---|
| 137 | DrawTextW (hdc, phdi->pszText, lstrlenW (phdi->pszText),
|
|---|
| 138 | &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
|
|---|
| 139 | tx = textRect.right - textRect.left;
|
|---|
| 140 | ry = r.bottom - r.top;
|
|---|
| 141 | rx = r.right - r.left;
|
|---|
| 142 |
|
|---|
| 143 | if (ry >= bmp.bmHeight) {
|
|---|
| 144 | cy = bmp.bmHeight;
|
|---|
| 145 | yD = r.top + (ry - bmp.bmHeight) / 2;
|
|---|
| 146 | yS = 0;
|
|---|
| 147 | }
|
|---|
| 148 | else {
|
|---|
| 149 | cy = ry;
|
|---|
| 150 | yD = r.top;
|
|---|
| 151 | yS = (bmp.bmHeight - ry) / 2;
|
|---|
| 152 |
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | if (r.left + tx + bmp.bmWidth + 9 <= r.right) {
|
|---|
| 156 | cx = bmp.bmWidth;
|
|---|
| 157 | xD = r.left + tx + 6;
|
|---|
| 158 | }
|
|---|
| 159 | else {
|
|---|
| 160 | if (rx >= bmp.bmWidth + 6) {
|
|---|
| 161 | cx = bmp.bmWidth;
|
|---|
| 162 | xD = r.right - bmp.bmWidth - 3;
|
|---|
| 163 | r.right = xD - 3;
|
|---|
| 164 | }
|
|---|
| 165 | else {
|
|---|
| 166 | cx = rx - 3;
|
|---|
| 167 | xD = r.left;
|
|---|
| 168 | r.right = r.left;
|
|---|
| 169 | }
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | hdcBitmap = CreateCompatibleDC (hdc);
|
|---|
| 173 | SelectObject (hdcBitmap, phdi->hbm);
|
|---|
| 174 | BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
|
|---|
| 175 | DeleteDC (hdcBitmap);
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | if (phdi->fmt & HDF_IMAGE) {
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 | /* ImageList_Draw (infoPtr->himl, phdi->iImage,...); */
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | if ((phdi->fmt & HDF_STRING) && (phdi->pszText)) {
|
|---|
| 185 | oldBkMode = SetBkMode(hdc, TRANSPARENT);
|
|---|
| 186 | r.left += 3;
|
|---|
| 187 | r.right -= 3;
|
|---|
| 188 | SetTextColor (hdc, bHotTrack ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
|
|---|
| 189 | DrawTextW (hdc, phdi->pszText, lstrlenW (phdi->pszText),
|
|---|
| 190 | &r, uTextJustify|DT_VCENTER|DT_SINGLELINE);
|
|---|
| 191 | if (oldBkMode != TRANSPARENT)
|
|---|
| 192 | SetBkMode(hdc, oldBkMode);
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | return phdi->rect.right;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 | static void
|
|---|
| 201 | HEADER_Refresh (HWND hwnd, HDC hdc)
|
|---|
| 202 | {
|
|---|
| 203 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 204 | HFONT hFont, hOldFont;
|
|---|
| 205 | RECT rect;
|
|---|
| 206 | HBRUSH hbrBk;
|
|---|
| 207 | INT i, x;
|
|---|
| 208 |
|
|---|
| 209 | /* get rect for the bar, adjusted for the border */
|
|---|
| 210 | GetClientRect (hwnd, &rect);
|
|---|
| 211 |
|
|---|
| 212 | hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
|
|---|
| 213 | hOldFont = SelectObject (hdc, hFont);
|
|---|
| 214 |
|
|---|
| 215 | /* draw Background */
|
|---|
| 216 | hbrBk = GetSysColorBrush(COLOR_3DFACE);
|
|---|
| 217 | FillRect(hdc, &rect, hbrBk);
|
|---|
| 218 |
|
|---|
| 219 | x = rect.left;
|
|---|
| 220 | for (i = 0; i < infoPtr->uNumItem; i++) {
|
|---|
| 221 | x = HEADER_DrawItem (hwnd, hdc, i, FALSE);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
|
|---|
| 225 | rect.left = x;
|
|---|
| 226 | if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
|
|---|
| 227 | DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
|
|---|
| 228 | else
|
|---|
| 229 | DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | SelectObject (hdc, hOldFont);
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 | static void
|
|---|
| 237 | HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
|
|---|
| 238 | {
|
|---|
| 239 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 240 | HFONT hFont, hOldFont;
|
|---|
| 241 |
|
|---|
| 242 | hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
|
|---|
| 243 | hOldFont = SelectObject (hdc, hFont);
|
|---|
| 244 | HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
|
|---|
| 245 | SelectObject (hdc, hOldFont);
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 | static void
|
|---|
| 250 | HEADER_SetItemBounds (HWND hwnd)
|
|---|
| 251 | {
|
|---|
| 252 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 253 | HEADER_ITEM *phdi;
|
|---|
| 254 | RECT rect;
|
|---|
| 255 | int i, x;
|
|---|
| 256 |
|
|---|
| 257 | if (infoPtr->uNumItem == 0)
|
|---|
| 258 | return;
|
|---|
| 259 |
|
|---|
| 260 | GetClientRect (hwnd, &rect);
|
|---|
| 261 |
|
|---|
| 262 | x = rect.left;
|
|---|
| 263 | for (i = 0; i < infoPtr->uNumItem; i++) {
|
|---|
| 264 | phdi = &infoPtr->items[i];
|
|---|
| 265 | phdi->rect.top = rect.top;
|
|---|
| 266 | phdi->rect.bottom = rect.bottom;
|
|---|
| 267 | phdi->rect.left = x;
|
|---|
| 268 | phdi->rect.right = phdi->rect.left + phdi->cxy;
|
|---|
| 269 | x = phdi->rect.right;
|
|---|
| 270 | }
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 | static void
|
|---|
| 275 | HEADER_ForceItemBounds (HWND hwnd, INT cy)
|
|---|
| 276 | {
|
|---|
| 277 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 278 | HEADER_ITEM *phdi;
|
|---|
| 279 | int i, x;
|
|---|
| 280 |
|
|---|
| 281 | if (infoPtr->uNumItem == 0)
|
|---|
| 282 | return;
|
|---|
| 283 |
|
|---|
| 284 | x = 0;
|
|---|
| 285 | for (i = 0; i < infoPtr->uNumItem; i++) {
|
|---|
| 286 | phdi = &infoPtr->items[i];
|
|---|
| 287 | phdi->rect.top = 0;
|
|---|
| 288 | phdi->rect.bottom = cy;
|
|---|
| 289 | phdi->rect.left = x;
|
|---|
| 290 | phdi->rect.right = phdi->rect.left + phdi->cxy;
|
|---|
| 291 | x = phdi->rect.right;
|
|---|
| 292 | }
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 | static void
|
|---|
| 297 | HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
|
|---|
| 298 | {
|
|---|
| 299 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 300 | RECT rect, rcTest;
|
|---|
| 301 | INT iCount, width;
|
|---|
| 302 | BOOL bNoWidth;
|
|---|
| 303 |
|
|---|
| 304 | GetClientRect (hwnd, &rect);
|
|---|
| 305 |
|
|---|
| 306 | *pFlags = 0;
|
|---|
| 307 | bNoWidth = FALSE;
|
|---|
| 308 | if (PtInRect (&rect, *lpPt))
|
|---|
| 309 | {
|
|---|
| 310 | if (infoPtr->uNumItem == 0) {
|
|---|
| 311 | *pFlags |= HHT_NOWHERE;
|
|---|
| 312 | *pItem = 1;
|
|---|
| 313 | // TRACE (header, "NOWHERE\n");
|
|---|
| 314 | return;
|
|---|
| 315 | }
|
|---|
| 316 | else {
|
|---|
| 317 | /* somewhere inside */
|
|---|
| 318 | for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
|
|---|
| 319 | rect = infoPtr->items[iCount].rect;
|
|---|
| 320 | width = rect.right - rect.left;
|
|---|
| 321 | if (width == 0) {
|
|---|
| 322 | bNoWidth = TRUE;
|
|---|
| 323 | continue;
|
|---|
| 324 | }
|
|---|
| 325 | if (PtInRect (&rect, *lpPt)) {
|
|---|
| 326 | if (width <= 2 * DIVIDER_WIDTH) {
|
|---|
| 327 | *pFlags |= HHT_ONHEADER;
|
|---|
| 328 | *pItem = iCount;
|
|---|
| 329 | // TRACE (header, "ON HEADER %d\n", iCount);
|
|---|
| 330 | return;
|
|---|
| 331 | }
|
|---|
| 332 | if (iCount > 0) {
|
|---|
| 333 | rcTest = rect;
|
|---|
| 334 | rcTest.right = rcTest.left + DIVIDER_WIDTH;
|
|---|
| 335 | if (PtInRect (&rcTest, *lpPt)) {
|
|---|
| 336 | if (bNoWidth) {
|
|---|
| 337 | *pFlags |= HHT_ONDIVOPEN;
|
|---|
| 338 | *pItem = iCount - 1;
|
|---|
| 339 | // TRACE (header, "ON DIVOPEN %d\n", *pItem);
|
|---|
| 340 | return;
|
|---|
| 341 | }
|
|---|
| 342 | else {
|
|---|
| 343 | *pFlags |= HHT_ONDIVIDER;
|
|---|
| 344 | *pItem = iCount - 1;
|
|---|
| 345 | // TRACE (header, "ON DIVIDER %d\n", *pItem);
|
|---|
| 346 | return;
|
|---|
| 347 | }
|
|---|
| 348 | }
|
|---|
| 349 | }
|
|---|
| 350 | rcTest = rect;
|
|---|
| 351 | rcTest.left = rcTest.right - DIVIDER_WIDTH;
|
|---|
| 352 | if (PtInRect (&rcTest, *lpPt)) {
|
|---|
| 353 | *pFlags |= HHT_ONDIVIDER;
|
|---|
| 354 | *pItem = iCount;
|
|---|
| 355 | // TRACE (header, "ON DIVIDER %d\n", *pItem);
|
|---|
| 356 | return;
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | *pFlags |= HHT_ONHEADER;
|
|---|
| 360 | *pItem = iCount;
|
|---|
| 361 | // TRACE (header, "ON HEADER %d\n", iCount);
|
|---|
| 362 | return;
|
|---|
| 363 | }
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | /* check for last divider part (on nowhere) */
|
|---|
| 367 | rect = infoPtr->items[infoPtr->uNumItem-1].rect;
|
|---|
| 368 | rect.left = rect.right;
|
|---|
| 369 | rect.right += DIVIDER_WIDTH;
|
|---|
| 370 | if (PtInRect (&rect, *lpPt)) {
|
|---|
| 371 | if (bNoWidth) {
|
|---|
| 372 | *pFlags |= HHT_ONDIVOPEN;
|
|---|
| 373 | *pItem = infoPtr->uNumItem - 1;
|
|---|
| 374 | // TRACE (header, "ON DIVOPEN %d\n", *pItem);
|
|---|
| 375 | return;
|
|---|
| 376 | }
|
|---|
| 377 | else {
|
|---|
| 378 | *pFlags |= HHT_ONDIVIDER;
|
|---|
| 379 | *pItem = infoPtr->uNumItem-1;
|
|---|
| 380 | // TRACE (header, "ON DIVIDER %d\n", *pItem);
|
|---|
| 381 | return;
|
|---|
| 382 | }
|
|---|
| 383 | }
|
|---|
| 384 |
|
|---|
| 385 | *pFlags |= HHT_NOWHERE;
|
|---|
| 386 | *pItem = 1;
|
|---|
| 387 | // TRACE (header, "NOWHERE\n");
|
|---|
| 388 | return;
|
|---|
| 389 | }
|
|---|
| 390 | }
|
|---|
| 391 | else {
|
|---|
| 392 | if (lpPt->x < rect.left) {
|
|---|
| 393 | // TRACE (header, "TO LEFT\n");
|
|---|
| 394 | *pFlags |= HHT_TOLEFT;
|
|---|
| 395 | }
|
|---|
| 396 | else if (lpPt->x > rect.right) {
|
|---|
| 397 | // TRACE (header, "TO LEFT\n");
|
|---|
| 398 | *pFlags |= HHT_TORIGHT;
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | if (lpPt->y < rect.top) {
|
|---|
| 402 | // TRACE (header, "ABOVE\n");
|
|---|
| 403 | *pFlags |= HHT_ABOVE;
|
|---|
| 404 | }
|
|---|
| 405 | else if (lpPt->y > rect.bottom) {
|
|---|
| 406 | // TRACE (header, "BELOW\n");
|
|---|
| 407 | *pFlags |= HHT_BELOW;
|
|---|
| 408 | }
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 | *pItem = 1;
|
|---|
| 412 | // TRACE (header, "flags=0x%X\n", *pFlags);
|
|---|
| 413 | return;
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 | static void
|
|---|
| 418 | HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
|
|---|
| 419 | {
|
|---|
| 420 | RECT rect;
|
|---|
| 421 | HPEN hOldPen;
|
|---|
| 422 | INT oldRop;
|
|---|
| 423 |
|
|---|
| 424 | GetClientRect (hwnd, &rect);
|
|---|
| 425 |
|
|---|
| 426 | hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
|
|---|
| 427 | oldRop = SetROP2 (hdc, R2_XORPEN);
|
|---|
| 428 | MoveToEx (hdc, x, rect.top, NULL);
|
|---|
| 429 | LineTo (hdc, x, rect.bottom);
|
|---|
| 430 | SetROP2 (hdc, oldRop);
|
|---|
| 431 | SelectObject (hdc, hOldPen);
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 | static BOOL
|
|---|
| 436 | HEADER_SendSimpleNotify (HWND hwnd, UINT code)
|
|---|
| 437 | {
|
|---|
| 438 | NMHDR nmhdr;
|
|---|
| 439 |
|
|---|
| 440 | nmhdr.hwndFrom = hwnd;
|
|---|
| 441 | nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
|
|---|
| 442 | nmhdr.code = code;
|
|---|
| 443 |
|
|---|
| 444 | return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
|
|---|
| 445 | (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 | static BOOL
|
|---|
| 450 | HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem)
|
|---|
| 451 | {
|
|---|
| 452 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 453 | NMHEADERA nmhdr;
|
|---|
| 454 | HDITEMA nmitem;
|
|---|
| 455 |
|
|---|
| 456 | nmhdr.hdr.hwndFrom = hwnd;
|
|---|
| 457 | nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
|
|---|
| 458 | nmhdr.hdr.code = code;
|
|---|
| 459 | nmhdr.iItem = iItem;
|
|---|
| 460 | nmhdr.iButton = 0;
|
|---|
| 461 | nmhdr.pitem = &nmitem;
|
|---|
| 462 | nmitem.mask = 0;
|
|---|
| 463 | nmitem.cxy = infoPtr->items[iItem].cxy;
|
|---|
| 464 | nmitem.hbm = infoPtr->items[iItem].hbm;
|
|---|
| 465 | nmitem.pszText = NULL;
|
|---|
| 466 | nmitem.cchTextMax = 0;
|
|---|
| 467 | /* nmitem.pszText = infoPtr->items[iItem].pszText; */
|
|---|
| 468 | /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
|
|---|
| 469 | nmitem.fmt = infoPtr->items[iItem].fmt;
|
|---|
| 470 | nmitem.lParam = infoPtr->items[iItem].lParam;
|
|---|
| 471 | nmitem.iOrder = infoPtr->items[iItem].iOrder;
|
|---|
| 472 | nmitem.iImage = infoPtr->items[iItem].iImage;
|
|---|
| 473 |
|
|---|
| 474 | return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
|
|---|
| 475 | (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 | static BOOL
|
|---|
| 480 | HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
|
|---|
| 481 | {
|
|---|
| 482 | NMHEADERA nmhdr;
|
|---|
| 483 |
|
|---|
| 484 | nmhdr.hdr.hwndFrom = hwnd;
|
|---|
| 485 | nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
|
|---|
| 486 | nmhdr.hdr.code = code;
|
|---|
| 487 | nmhdr.iItem = iItem;
|
|---|
| 488 | nmhdr.iButton = 0;
|
|---|
| 489 | nmhdr.pitem = NULL;
|
|---|
| 490 |
|
|---|
| 491 | return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
|
|---|
| 492 | (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 | static LRESULT
|
|---|
| 497 | HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
|
|---|
| 498 | {
|
|---|
| 499 | // FIXME (header, "empty stub!\n");
|
|---|
| 500 | return 0;
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 | static LRESULT
|
|---|
| 505 | HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
|
|---|
| 506 | {
|
|---|
| 507 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
|
|---|
| 508 | INT iItem = (INT)wParam;
|
|---|
| 509 | HDC hdc;
|
|---|
| 510 |
|
|---|
| 511 | // TRACE(header, "[iItem=%d]\n", iItem);
|
|---|
| 512 |
|
|---|
| 513 | if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
|
|---|
| 514 | return FALSE;
|
|---|
| 515 |
|
|---|
| 516 | if (infoPtr->uNumItem == 1) {
|
|---|
| 517 | // TRACE(header, "Simple delete!\n");
|
|---|
| 518 | if (infoPtr->items[0].pszText)
|
|---|
| 519 | COMCTL32_Free (infoPtr->items[0].pszText);
|
|---|
| 520 | COMCTL32_Free (infoPtr->items);
|
|---|
| 521 | infoPtr->items = 0;
|
|---|
| 522 | infoPtr->uNumItem = 0;
|
|---|
| 523 | }
|
|---|
| 524 | else {
|
|---|
| 525 | HEADER_ITEM *oldItems = infoPtr->items;
|
|---|
| 526 | // TRACE(header, "Complex delete! [iItem=%d]\n", iItem);
|
|---|
| 527 |
|
|---|
| 528 | if (infoPtr->items[iItem].pszText)
|
|---|
| 529 | COMCTL32_Free (infoPtr->items[iItem].pszText);
|
|---|
| 530 |
|
|---|
| 531 | infoPtr->uNumItem--;
|
|---|
| 532 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
|
|---|
| 533 | /* pre delete copy */
|
|---|
| 534 | if (iItem > 0) {
|
|---|
| 535 | memcpy (&infoPtr->items[0], &oldItems[0],
|
|---|
| 536 | iItem * sizeof(HEADER_ITEM));
|
|---|
| 537 | }
|
|---|
| 538 |
|
|---|
| 539 | /* post delete copy */
|
|---|
| 540 | if (iItem < infoPtr->uNumItem) {
|
|---|
| 541 | memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
|
|---|
| 542 | (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 | COMCTL32_Free (oldItems);
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | HEADER_SetItemBounds (hwnd);
|
|---|
| 549 |
|
|---|
| 550 | hdc = GetDC (hwnd);
|
|---|
| 551 | HEADER_Refresh (hwnd, hdc);
|
|---|
| 552 | ReleaseDC (hwnd, hdc);
|
|---|
| 553 |
|
|---|
| 554 | return TRUE;
|
|---|
| 555 | }
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 | static LRESULT
|
|---|
| 559 | HEADER_GetImageList (HWND hwnd)
|
|---|
| 560 | {
|
|---|
| 561 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 562 |
|
|---|
| 563 | return (LRESULT)infoPtr->himl;
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 | static LRESULT
|
|---|
| 568 | HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 569 | {
|
|---|
| 570 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 571 | HDITEMA *phdi = (HDITEMA*)lParam;
|
|---|
| 572 | INT nItem = (INT)wParam;
|
|---|
| 573 | HEADER_ITEM *lpItem;
|
|---|
| 574 |
|
|---|
| 575 | if (!phdi)
|
|---|
| 576 | return FALSE;
|
|---|
| 577 | if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
|
|---|
| 578 | return FALSE;
|
|---|
| 579 |
|
|---|
| 580 | // TRACE (header, "[nItem=%d]\n", nItem);
|
|---|
| 581 |
|
|---|
| 582 | if (phdi->mask == 0)
|
|---|
| 583 | return TRUE;
|
|---|
| 584 |
|
|---|
| 585 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
|---|
| 586 | if (phdi->mask & HDI_BITMAP)
|
|---|
| 587 | phdi->hbm = lpItem->hbm;
|
|---|
| 588 |
|
|---|
| 589 | if (phdi->mask & HDI_FORMAT)
|
|---|
| 590 | phdi->fmt = lpItem->fmt;
|
|---|
| 591 |
|
|---|
| 592 | if (phdi->mask & HDI_WIDTH)
|
|---|
| 593 | phdi->cxy = lpItem->cxy;
|
|---|
| 594 |
|
|---|
| 595 | if (phdi->mask & HDI_LPARAM)
|
|---|
| 596 | phdi->lParam = lpItem->lParam;
|
|---|
| 597 |
|
|---|
| 598 | if (phdi->mask & HDI_TEXT) {
|
|---|
| 599 | if (lpItem->pszText != LPSTR_TEXTCALLBACKW)
|
|---|
| 600 | lstrcpynWtoA (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
|
|---|
| 601 | else
|
|---|
| 602 | phdi->pszText = LPSTR_TEXTCALLBACKA;
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | if (phdi->mask & HDI_IMAGE)
|
|---|
| 606 | phdi->iImage = lpItem->iImage;
|
|---|
| 607 |
|
|---|
| 608 | if (phdi->mask & HDI_ORDER)
|
|---|
| 609 | phdi->iOrder = lpItem->iOrder;
|
|---|
| 610 |
|
|---|
| 611 | return TRUE;
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 | static LRESULT
|
|---|
| 616 | HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 617 | {
|
|---|
| 618 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 619 | HDITEMW *phdi = (HDITEMW*)lParam;
|
|---|
| 620 | INT nItem = (INT)wParam;
|
|---|
| 621 | HEADER_ITEM *lpItem;
|
|---|
| 622 |
|
|---|
| 623 | if (!phdi)
|
|---|
| 624 | return FALSE;
|
|---|
| 625 | if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
|
|---|
| 626 | return FALSE;
|
|---|
| 627 |
|
|---|
| 628 | // TRACE (header, "[nItem=%d]\n", nItem);
|
|---|
| 629 |
|
|---|
| 630 | if (phdi->mask == 0)
|
|---|
| 631 | return TRUE;
|
|---|
| 632 |
|
|---|
| 633 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
|---|
| 634 | if (phdi->mask & HDI_BITMAP)
|
|---|
| 635 | phdi->hbm = lpItem->hbm;
|
|---|
| 636 |
|
|---|
| 637 | if (phdi->mask & HDI_FORMAT)
|
|---|
| 638 | phdi->fmt = lpItem->fmt;
|
|---|
| 639 |
|
|---|
| 640 | if (phdi->mask & HDI_WIDTH)
|
|---|
| 641 | phdi->cxy = lpItem->cxy;
|
|---|
| 642 |
|
|---|
| 643 | if (phdi->mask & HDI_LPARAM)
|
|---|
| 644 | phdi->lParam = lpItem->lParam;
|
|---|
| 645 |
|
|---|
| 646 | if (phdi->mask & HDI_TEXT) {
|
|---|
| 647 | if (lpItem->pszText != LPSTR_TEXTCALLBACKW)
|
|---|
| 648 | lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
|
|---|
| 649 | else
|
|---|
| 650 | phdi->pszText = LPSTR_TEXTCALLBACKW;
|
|---|
| 651 | }
|
|---|
| 652 |
|
|---|
| 653 | if (phdi->mask & HDI_IMAGE)
|
|---|
| 654 | phdi->iImage = lpItem->iImage;
|
|---|
| 655 |
|
|---|
| 656 | if (phdi->mask & HDI_ORDER)
|
|---|
| 657 | phdi->iOrder = lpItem->iOrder;
|
|---|
| 658 |
|
|---|
| 659 | return TRUE;
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 | static LRESULT
|
|---|
| 664 | HEADER_GetItemCount (HWND hwnd)
|
|---|
| 665 | {
|
|---|
| 666 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 667 | return infoPtr->uNumItem;
|
|---|
| 668 | }
|
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 | static LRESULT
|
|---|
| 672 | HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 673 | {
|
|---|
| 674 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 675 | INT iItem = (INT)wParam;
|
|---|
| 676 | LPRECT lpRect = (LPRECT)lParam;
|
|---|
| 677 |
|
|---|
| 678 | if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
|
|---|
| 679 | return FALSE;
|
|---|
| 680 |
|
|---|
| 681 | lpRect->left = infoPtr->items[iItem].rect.left;
|
|---|
| 682 | lpRect->right = infoPtr->items[iItem].rect.right;
|
|---|
| 683 | lpRect->top = infoPtr->items[iItem].rect.top;
|
|---|
| 684 | lpRect->bottom = infoPtr->items[iItem].rect.bottom;
|
|---|
| 685 |
|
|---|
| 686 | return TRUE;
|
|---|
| 687 | }
|
|---|
| 688 |
|
|---|
| 689 |
|
|---|
| 690 | /* << HEADER_GetOrderArray >> */
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 | static LRESULT
|
|---|
| 694 | HEADER_GetUnicodeFormat (HWND hwnd)
|
|---|
| 695 | {
|
|---|
| 696 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 697 | return infoPtr->bUnicode;
|
|---|
| 698 | }
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 | static LRESULT
|
|---|
| 702 | HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 703 | {
|
|---|
| 704 | LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
|
|---|
| 705 |
|
|---|
| 706 | HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
|
|---|
| 707 |
|
|---|
| 708 | return phti->flags;
|
|---|
| 709 | }
|
|---|
| 710 |
|
|---|
| 711 |
|
|---|
| 712 | static LRESULT
|
|---|
| 713 | HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 714 | {
|
|---|
| 715 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 716 | HDITEMA *phdi = (HDITEMA*)lParam;
|
|---|
| 717 | INT nItem = (INT)wParam;
|
|---|
| 718 | HEADER_ITEM *lpItem;
|
|---|
| 719 | HDC hdc;
|
|---|
| 720 | INT len;
|
|---|
| 721 |
|
|---|
| 722 | if ((phdi == NULL) || (nItem < 0))
|
|---|
| 723 | return -1;
|
|---|
| 724 |
|
|---|
| 725 | if (nItem > infoPtr->uNumItem)
|
|---|
| 726 | nItem = infoPtr->uNumItem;
|
|---|
| 727 |
|
|---|
| 728 | if (infoPtr->uNumItem == 0) {
|
|---|
| 729 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
|
|---|
| 730 | infoPtr->uNumItem++;
|
|---|
| 731 | }
|
|---|
| 732 | else {
|
|---|
| 733 | HEADER_ITEM *oldItems = infoPtr->items;
|
|---|
| 734 |
|
|---|
| 735 | infoPtr->uNumItem++;
|
|---|
| 736 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
|
|---|
| 737 | if (nItem == 0) {
|
|---|
| 738 | memcpy (&infoPtr->items[1], &oldItems[0],
|
|---|
| 739 | (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
|
|---|
| 740 | }
|
|---|
| 741 | else
|
|---|
| 742 | {
|
|---|
| 743 | /* pre insert copy */
|
|---|
| 744 | if (nItem > 0) {
|
|---|
| 745 | memcpy (&infoPtr->items[0], &oldItems[0],
|
|---|
| 746 | nItem * sizeof(HEADER_ITEM));
|
|---|
| 747 | }
|
|---|
| 748 |
|
|---|
| 749 | /* post insert copy */
|
|---|
| 750 | if (nItem < infoPtr->uNumItem - 1) {
|
|---|
| 751 | memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
|
|---|
| 752 | (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
|
|---|
| 753 | }
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | COMCTL32_Free (oldItems);
|
|---|
| 757 | }
|
|---|
| 758 |
|
|---|
| 759 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
|---|
| 760 | lpItem->bDown = FALSE;
|
|---|
| 761 |
|
|---|
| 762 | if (phdi->mask & HDI_WIDTH)
|
|---|
| 763 | lpItem->cxy = phdi->cxy;
|
|---|
| 764 |
|
|---|
| 765 | if (phdi->mask & HDI_TEXT) {
|
|---|
| 766 | if (!phdi->pszText) /* null pointer check */
|
|---|
| 767 | phdi->pszText = "";
|
|---|
| 768 | if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
|
|---|
| 769 | len = lstrlenA (phdi->pszText);
|
|---|
| 770 | lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
|
|---|
| 771 | lstrcpyAtoW (lpItem->pszText, phdi->pszText);
|
|---|
| 772 | }
|
|---|
| 773 | else
|
|---|
| 774 | lpItem->pszText = LPSTR_TEXTCALLBACKW;
|
|---|
| 775 | }
|
|---|
| 776 |
|
|---|
| 777 | if (phdi->mask & HDI_FORMAT)
|
|---|
| 778 | lpItem->fmt = phdi->fmt;
|
|---|
| 779 |
|
|---|
| 780 | if (lpItem->fmt == 0)
|
|---|
| 781 | lpItem->fmt = HDF_LEFT;
|
|---|
| 782 |
|
|---|
| 783 | if (phdi->mask & HDI_BITMAP)
|
|---|
| 784 | lpItem->hbm = phdi->hbm;
|
|---|
| 785 |
|
|---|
| 786 | if (phdi->mask & HDI_LPARAM)
|
|---|
| 787 | lpItem->lParam = phdi->lParam;
|
|---|
| 788 |
|
|---|
| 789 | if (phdi->mask & HDI_IMAGE)
|
|---|
| 790 | lpItem->iImage = phdi->iImage;
|
|---|
| 791 |
|
|---|
| 792 | if (phdi->mask & HDI_ORDER)
|
|---|
| 793 | lpItem->iOrder = phdi->iOrder;
|
|---|
| 794 |
|
|---|
| 795 | HEADER_SetItemBounds (hwnd);
|
|---|
| 796 |
|
|---|
| 797 | hdc = GetDC (hwnd);
|
|---|
| 798 | HEADER_Refresh (hwnd, hdc);
|
|---|
| 799 | ReleaseDC (hwnd, hdc);
|
|---|
| 800 |
|
|---|
| 801 | return nItem;
|
|---|
| 802 | }
|
|---|
| 803 |
|
|---|
| 804 |
|
|---|
| 805 | static LRESULT
|
|---|
| 806 | HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 807 | {
|
|---|
| 808 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 809 | HDITEMW *phdi = (HDITEMW*)lParam;
|
|---|
| 810 | INT nItem = (INT)wParam;
|
|---|
| 811 | HEADER_ITEM *lpItem;
|
|---|
| 812 | HDC hdc;
|
|---|
| 813 | INT len;
|
|---|
| 814 |
|
|---|
| 815 | if ((phdi == NULL) || (nItem < 0))
|
|---|
| 816 | return -1;
|
|---|
| 817 |
|
|---|
| 818 | if (nItem > infoPtr->uNumItem)
|
|---|
| 819 | nItem = infoPtr->uNumItem;
|
|---|
| 820 |
|
|---|
| 821 | if (infoPtr->uNumItem == 0) {
|
|---|
| 822 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
|
|---|
| 823 | infoPtr->uNumItem++;
|
|---|
| 824 | }
|
|---|
| 825 | else {
|
|---|
| 826 | HEADER_ITEM *oldItems = infoPtr->items;
|
|---|
| 827 |
|
|---|
| 828 | infoPtr->uNumItem++;
|
|---|
| 829 | infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
|
|---|
| 830 | /* pre insert copy */
|
|---|
| 831 | if (nItem > 0) {
|
|---|
| 832 | memcpy (&infoPtr->items[0], &oldItems[0],
|
|---|
| 833 | nItem * sizeof(HEADER_ITEM));
|
|---|
| 834 | }
|
|---|
| 835 |
|
|---|
| 836 | /* post insert copy */
|
|---|
| 837 | if (nItem < infoPtr->uNumItem - 1) {
|
|---|
| 838 | memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
|
|---|
| 839 | (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
|
|---|
| 840 | }
|
|---|
| 841 |
|
|---|
| 842 | COMCTL32_Free (oldItems);
|
|---|
| 843 | }
|
|---|
| 844 |
|
|---|
| 845 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
|---|
| 846 | lpItem->bDown = FALSE;
|
|---|
| 847 |
|
|---|
| 848 | if (phdi->mask & HDI_WIDTH)
|
|---|
| 849 | lpItem->cxy = phdi->cxy;
|
|---|
| 850 |
|
|---|
| 851 | if (phdi->mask & HDI_TEXT) {
|
|---|
| 852 | WCHAR wide_null_char = 0;
|
|---|
| 853 | if (!phdi->pszText) /* null pointer check */
|
|---|
| 854 | phdi->pszText = &wide_null_char;
|
|---|
| 855 | if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
|
|---|
| 856 | len = lstrlenW (phdi->pszText);
|
|---|
| 857 | lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
|
|---|
| 858 | lstrcpyW (lpItem->pszText, phdi->pszText);
|
|---|
| 859 | }
|
|---|
| 860 | else
|
|---|
| 861 | lpItem->pszText = LPSTR_TEXTCALLBACKW;
|
|---|
| 862 | }
|
|---|
| 863 |
|
|---|
| 864 | if (phdi->mask & HDI_FORMAT)
|
|---|
| 865 | lpItem->fmt = phdi->fmt;
|
|---|
| 866 |
|
|---|
| 867 | if (lpItem->fmt == 0)
|
|---|
| 868 | lpItem->fmt = HDF_LEFT;
|
|---|
| 869 |
|
|---|
| 870 | if (phdi->mask & HDI_BITMAP)
|
|---|
| 871 | lpItem->hbm = phdi->hbm;
|
|---|
| 872 |
|
|---|
| 873 | if (phdi->mask & HDI_LPARAM)
|
|---|
| 874 | lpItem->lParam = phdi->lParam;
|
|---|
| 875 |
|
|---|
| 876 | if (phdi->mask & HDI_IMAGE)
|
|---|
| 877 | lpItem->iImage = phdi->iImage;
|
|---|
| 878 |
|
|---|
| 879 | if (phdi->mask & HDI_ORDER)
|
|---|
| 880 | lpItem->iOrder = phdi->iOrder;
|
|---|
| 881 |
|
|---|
| 882 | HEADER_SetItemBounds (hwnd);
|
|---|
| 883 |
|
|---|
| 884 | hdc = GetDC (hwnd);
|
|---|
| 885 | HEADER_Refresh (hwnd, hdc);
|
|---|
| 886 | ReleaseDC (hwnd, hdc);
|
|---|
| 887 |
|
|---|
| 888 | return nItem;
|
|---|
| 889 | }
|
|---|
| 890 |
|
|---|
| 891 |
|
|---|
| 892 | static LRESULT
|
|---|
| 893 | HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 894 | {
|
|---|
| 895 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 896 | LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
|
|---|
| 897 |
|
|---|
| 898 | lpLayout->pwpos->hwnd = hwnd;
|
|---|
| 899 | lpLayout->pwpos->hwndInsertAfter = 0;
|
|---|
| 900 | lpLayout->pwpos->x = lpLayout->prc->left;
|
|---|
| 901 | lpLayout->pwpos->y = lpLayout->prc->top;
|
|---|
| 902 | lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
|
|---|
| 903 | if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
|
|---|
| 904 | lpLayout->pwpos->cy = 0;
|
|---|
| 905 | else
|
|---|
| 906 | lpLayout->pwpos->cy = infoPtr->nHeight;
|
|---|
| 907 | lpLayout->pwpos->flags = SWP_NOZORDER;
|
|---|
| 908 |
|
|---|
| 909 | // TRACE (header, "Layout x=%d y=%d cx=%d cy=%d\n",
|
|---|
| 910 | // lpLayout->pwpos->x, lpLayout->pwpos->y,
|
|---|
| 911 | // lpLayout->pwpos->cx, lpLayout->pwpos->cy);
|
|---|
| 912 |
|
|---|
| 913 | HEADER_ForceItemBounds (hwnd, lpLayout->pwpos->cy);
|
|---|
| 914 |
|
|---|
| 915 | /* hack */
|
|---|
| 916 | #ifdef __HDM_LAYOUT_HACK__
|
|---|
| 917 | MoveWindow (lpLayout->pwpos->hwnd, lpLayout->pwpos->x, lpLayout->pwpos->y,
|
|---|
| 918 | lpLayout->pwpos->cx, lpLayout->pwpos->cy, TRUE);
|
|---|
| 919 | #endif
|
|---|
| 920 |
|
|---|
| 921 | return TRUE;
|
|---|
| 922 | }
|
|---|
| 923 |
|
|---|
| 924 |
|
|---|
| 925 | static LRESULT
|
|---|
| 926 | HEADER_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 927 | {
|
|---|
| 928 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 929 | HIMAGELIST himlOld;
|
|---|
| 930 |
|
|---|
| 931 | himlOld = infoPtr->himl;
|
|---|
| 932 | infoPtr->himl = (HIMAGELIST)lParam;
|
|---|
| 933 |
|
|---|
| 934 | /* FIXME: Refresh needed??? */
|
|---|
| 935 |
|
|---|
| 936 | return (LRESULT)himlOld;
|
|---|
| 937 | }
|
|---|
| 938 |
|
|---|
| 939 |
|
|---|
| 940 | static LRESULT
|
|---|
| 941 | HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|---|
| 942 | {
|
|---|
| 943 | HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
|
|---|
| 944 | HDITEMA *phdi = (HDITEMA*)lParam;
|
|---|
| 945 | INT nItem = (INT)wParam;
|
|---|
| 946 | HEADER_ITEM *lpItem;
|
|---|
| 947 | HDC hdc;
|
|---|
| 948 |
|
|---|
| 949 | if (phdi == NULL)
|
|---|
| 950 | return FALSE;
|
|---|
| 951 | if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
|
|---|
| 952 | return FALSE;
|
|---|
| 953 |
|
|---|
| 954 | // TRACE (header, "[nItem=%d]\n", nItem);
|
|---|
| 955 |
|
|---|
| 956 | if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem))
|
|---|
| 957 | return FALSE;
|
|---|
| 958 |
|
|---|
| 959 | lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
|
|---|
| 960 | if (phdi->mask & HDI_BITMAP)
|
|---|
| 961 | lpItem->hbm = phdi->hbm;
|
|---|
| 962 |
|
|---|
| 963 | if (phdi->mask & HDI_FORMAT)
|
|---|
| 964 | lpItem->fmt = phdi->fmt;
|
|---|
| 965 |
|
|---|
| 966 | if (phdi->mask & HDI_LPARAM)
|
|---|
| 967 | lpItem->lParam = phdi->lParam;
|
|---|
| 968 |
|
|---|
| 969 | if (phdi->mask & HDI_TEXT) {
|
|---|
| 970 | if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
|
|---|
| 971 | if (lpItem->pszText) {
|
|---|
| 972 | COMCTL32_Free (lpItem->pszText);
|
|---|
| 973 | lpItem->pszText = NULL;
|
|---|
| 974 | }
|
|---|
| 975 | if (phdi->pszText) {
|
|---|
| 976 | INT len = lstrlenA (phdi->pszText);
|
|---|
| 977 | lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
|
|---|
| 978 | lstrcpyAtoW (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 |
|
|---|