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