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