blob: 9f856cf8abef8692c19056169ebb4d19e7c50000 [file] [log] [blame]
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001/*
2 * Header control
3 *
4 * Copyright 1998 Eric Kohl
Eric Kohldbbc2242000-11-09 20:26:34 +00005 * Copyright 2000 Eric Kohl for CodeWeavers
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +00006 * Copyright 2003 Maxime Bellenge
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00007 *
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00008 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000022 * TODO:
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000023 * - Imagelist support (partially).
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000024 * - Callback items (under construction).
Alexandre Julliarda845b881998-06-01 10:44:35 +000025 * - Hottrack support (partially).
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000026 * - Custom draw support (including Notifications).
27 * - Drag and Drop support (including Notifications).
Eric Kohl40f29ee2000-11-25 03:07:01 +000028 * - New messages.
29 * - Use notification format
Bill Medland69f18272002-07-16 01:14:46 +000030 * - Correct the order maintenance code to preserve valid order
Alexandre Julliarda845b881998-06-01 10:44:35 +000031 *
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000032 */
33
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000034#include <stdarg.h>
Jeff Garzikc3e1f721999-02-19 15:42:11 +000035#include <string.h>
36
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000037#include "windef.h"
Marcus Meissner3480e4a1999-03-16 10:53:11 +000038#include "winbase.h"
Alexandre Julliardc7e7df82000-08-14 14:41:19 +000039#include "wine/unicode.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000040#include "wingdi.h"
41#include "winuser.h"
42#include "winnls.h"
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000043#include "commctrl.h"
Eric Kohldbbc2242000-11-09 20:26:34 +000044#include "comctl32.h"
Uwe Bonnes018c6542000-10-19 22:26:17 +000045#include "imagelist.h"
Frank Richter564872c2005-07-25 11:09:09 +000046#include "tmschema.h"
47#include "uxtheme.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000048#include "wine/debug.h"
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000049
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000050WINE_DEFAULT_DEBUG_CHANNEL(header);
Alexandre Julliard70c9e092000-08-09 00:41:17 +000051
Vincent Béron9a624912002-05-31 23:06:46 +000052typedef struct
Alexandre Julliard70c9e092000-08-09 00:41:17 +000053{
54 INT cxy;
55 HBITMAP hbm;
56 LPWSTR pszText;
57 INT fmt;
58 LPARAM lParam;
59 INT iImage;
60 INT iOrder; /* see documentation of HD_ITEM */
61
62 BOOL bDown; /* is item pressed? (used for drawing) */
63 RECT rect; /* bounding rectangle of the item */
64} HEADER_ITEM;
65
66
67typedef struct
68{
Dimitrie O. Paunf8514f52002-10-21 18:22:51 +000069 HWND hwndNotify; /* Owner window to send notifications to */
Eric Kohl40f29ee2000-11-25 03:07:01 +000070 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
Dimitrie O. Paunf8514f52002-10-21 18:22:51 +000071 UINT uNumItem; /* number of items (columns) */
72 INT nHeight; /* height of the header (pixels) */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000073 HFONT hFont; /* handle to the current font */
74 HCURSOR hcurArrow; /* handle to the arrow cursor */
75 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
76 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
77 BOOL bCaptured; /* Is the mouse captured? */
Dimitrie O. Paunf8514f52002-10-21 18:22:51 +000078 BOOL bPressed; /* Is a header item pressed (down)? */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000079 BOOL bTracking; /* Is in tracking mode? */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000080 INT iMoveItem; /* index of tracked item. (Tracking mode) */
81 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
82 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
83 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
Dimitrie O. Paunf8514f52002-10-21 18:22:51 +000084 INT iHotItem; /* index of hot item (cursor is over this item) */
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +000085 INT iMargin; /* width of the margin that surrounds a bitmap */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000086
Francois Gouget93416cd2005-03-23 13:15:18 +000087 HIMAGELIST himl; /* handle to an image list (may be 0) */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000088 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
Phil Krylov682dd702005-08-29 12:17:42 +000089 INT *order; /* array of item IDs indexed by order */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000090 BOOL bRectsValid; /* validity flag for bounding rectangles */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000091} HEADER_INFO;
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000092
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000093
Dimitrie O. Paund6645402002-10-22 00:41:45 +000094#define VERT_BORDER 3
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000095#define DIVIDER_WIDTH 10
Mikołaj Zalewski84c31892006-04-17 17:09:56 +020096#define HDN_UNICODE_OFFSET 20
97#define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000098
Robert Shearmancdb263e2004-08-25 17:33:01 +000099#define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000100
Frank Richter564872c2005-07-25 11:09:09 +0000101static const WCHAR themeClass[] = {'H','e','a','d','e','r',0};
102
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000103
Uwe Bonnes018c6542000-10-19 22:26:17 +0000104inline static LRESULT
105HEADER_IndexToOrder (HWND hwnd, INT iItem)
106{
107 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Bill Medland69f18272002-07-16 01:14:46 +0000108 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
Uwe Bonnes018c6542000-10-19 22:26:17 +0000109 return lpItem->iOrder;
110}
111
112
Vincent Béron9a624912002-05-31 23:06:46 +0000113static INT
Uwe Bonnes018c6542000-10-19 22:26:17 +0000114HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
115{
116 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000117 INT iorder = (INT)wParam;
Vincent Béron9a624912002-05-31 23:06:46 +0000118
Phil Krylov682dd702005-08-29 12:17:42 +0000119 if ((iorder <0) || iorder >= infoPtr->uNumItem)
Uwe Bonnes018c6542000-10-19 22:26:17 +0000120 return iorder;
Phil Krylov682dd702005-08-29 12:17:42 +0000121 return infoPtr->order[iorder];
Uwe Bonnes018c6542000-10-19 22:26:17 +0000122}
123
Martin Fuchs33bdf532000-04-28 14:46:36 +0000124static void
125HEADER_SetItemBounds (HWND hwnd)
126{
127 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
128 HEADER_ITEM *phdi;
129 RECT rect;
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000130 unsigned int i;
131 int x;
Martin Fuchs33bdf532000-04-28 14:46:36 +0000132
133 infoPtr->bRectsValid = TRUE;
134
135 if (infoPtr->uNumItem == 0)
136 return;
137
138 GetClientRect (hwnd, &rect);
139
140 x = rect.left;
141 for (i = 0; i < infoPtr->uNumItem; i++) {
Uwe Bonnes018c6542000-10-19 22:26:17 +0000142 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
Martin Fuchs33bdf532000-04-28 14:46:36 +0000143 phdi->rect.top = rect.top;
144 phdi->rect.bottom = rect.bottom;
145 phdi->rect.left = x;
Mike McCormack7c1db502001-09-17 20:25:52 +0000146 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
Martin Fuchs33bdf532000-04-28 14:46:36 +0000147 x = phdi->rect.right;
148 }
149}
150
151static LRESULT
152HEADER_Size (HWND hwnd, WPARAM wParam)
153{
154 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
155
156 infoPtr->bRectsValid = FALSE;
157
158 return 0;
159}
160
161
Alexandre Julliarda3960291999-02-26 11:11:13 +0000162static INT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000163HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000164{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000165 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000166 HEADER_ITEM *phdi = &infoPtr->items[iItem];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000167 RECT r;
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000168 INT oldBkMode, cxEdge = GetSystemMetrics(SM_CXEDGE);
Frank Richter564872c2005-07-25 11:09:09 +0000169 HTHEME theme = GetWindowTheme (hwnd);
Phil Krylov1b9fc2a2006-01-10 19:58:24 +0100170 NMCUSTOMDRAW nmcd;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000171
Mikołaj Zalewskia49da0b2006-04-18 19:45:29 +0200172 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, (infoPtr->nNotifyFormat == NFR_UNICODE));
Eric Kohl4718b6d2000-12-13 01:52:23 +0000173
Martin Fuchs33bdf532000-04-28 14:46:36 +0000174 if (!infoPtr->bRectsValid)
175 HEADER_SetItemBounds(hwnd);
Vincent Béron9a624912002-05-31 23:06:46 +0000176
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000177 r = phdi->rect;
178 if (r.right - r.left == 0)
179 return phdi->rect.right;
180
Frank Richter564872c2005-07-25 11:09:09 +0000181 if (theme != NULL) {
182 int state = (phdi->bDown) ? HIS_PRESSED :
183 (bHotTrack ? HIS_HOT : HIS_NORMAL);
184 DrawThemeBackground (theme, hdc, HP_HEADERITEM, state,
185 &r, NULL);
186 GetThemeBackgroundContentRect (theme, hdc, HP_HEADERITEM, state,
187 &r, &r);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000188 }
Frank Richter564872c2005-07-25 11:09:09 +0000189 else {
190 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) {
191 if (phdi->bDown) {
192 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
193 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
194 }
195 else
196 DrawEdge (hdc, &r, EDGE_RAISED,
197 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
198 }
199 else
200 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
201 }
202 if (phdi->bDown) {
203 r.left += 2;
204 r.top += 2;
205 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000206
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000207 r.left -= cxEdge;
208 r.right += cxEdge;
209
Phil Krylov1b9fc2a2006-01-10 19:58:24 +0100210 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
211 SetTextColor (hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
212 SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
213
214 nmcd.hdr.hwndFrom = hwnd;
215 nmcd.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
216 nmcd.hdr.code = NM_CUSTOMDRAW;
217 nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM | CDDS_ITEMPOSTERASE;
218 nmcd.hdc = hdc;
219 nmcd.dwItemSpec = iItem;
220 nmcd.rc = r;
221 nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0;
222 nmcd.lItemlParam = phdi->lParam;
223
224 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd);
225
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000226 if (phdi->fmt & HDF_OWNERDRAW) {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000227 DRAWITEMSTRUCT dis;
Vitaliy Margolen4f403ed2005-06-30 18:11:19 +0000228
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000229 dis.CtlType = ODT_HEADER;
Robert Shearmancdb263e2004-08-25 17:33:01 +0000230 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000231 dis.itemID = iItem;
232 dis.itemAction = ODA_DRAWENTIRE;
233 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
Eric Kohlcad17ff1999-03-12 17:42:50 +0000234 dis.hwndItem = hwnd;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000235 dis.hDC = hdc;
236 dis.rcItem = r;
237 dis.itemData = phdi->lParam;
Gerard Patel66226d82001-04-04 00:09:05 +0000238 oldBkMode = SetBkMode(hdc, TRANSPARENT);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +0000239 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM,
Eric Kohlcad17ff1999-03-12 17:42:50 +0000240 (WPARAM)dis.CtlID, (LPARAM)&dis);
Gerard Patel66226d82001-04-04 00:09:05 +0000241 if (oldBkMode != TRANSPARENT)
242 SetBkMode(hdc, oldBkMode);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000243 }
244 else {
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000245 UINT rw, rh, /* width and height of r */
246 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
247 /* cnt,txt,img,bmp */
248 UINT cx, tx, ix, bx,
249 cw, tw, iw, bw;
250 BITMAP bmp;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000251
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000252 cw = tw = iw = bw = 0;
253 rw = r.right - r.left;
254 rh = r.bottom - r.top;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000255
Phil Krylov1b9fc2a2006-01-10 19:58:24 +0100256 if (theme == NULL) {
257 HBRUSH hbr = CreateSolidBrush(GetBkColor(hdc));
258 RECT rcBackground = r;
259
260 rcBackground.right -= cxEdge;
261 FillRect(hdc, &rcBackground, hbr);
262 DeleteObject(hbr);
263 }
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000264 if (phdi->fmt & HDF_STRING) {
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +0000265 RECT textRect;
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +0000266
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000267 DrawTextW (hdc, phdi->pszText, -1,
268 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
269 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
270 }
Maxime Bellengéf28afa12005-02-23 12:41:43 +0000271
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000272 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
273 iw = infoPtr->himl->cx + 2 * infoPtr->iMargin;
274 x = &ix;
275 w = &iw;
276 }
277
278 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
279 GetObjectW (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
280 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
281 if (!iw) {
282 x = &bx;
283 w = &bw;
Maxime Bellengéf28afa12005-02-23 12:41:43 +0000284 }
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000285 }
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +0000286
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000287 if (bw || iw)
288 cw += *w;
289
290 /* align cx using the unclipped cw */
291 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
292 cx = r.left;
293 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
294 cx = r.left + rw / 2 - cw / 2;
295 else /* HDF_RIGHT */
296 cx = r.right - cw;
297
298 /* clip cx & cw */
299 if (cx < r.left)
300 cx = r.left;
301 if (cx + cw > r.right)
302 cw = r.right - cx;
303
304 tx = cx + infoPtr->iMargin;
305 /* since cw might have changed we have to recalculate tw */
306 tw = cw - infoPtr->iMargin * 2;
307
308 if (iw || bw) {
309 tw -= *w;
310 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
311 /* put pic behind text */
312 *x = cx + tw + infoPtr->iMargin * 3;
313 } else {
314 *x = cx + infoPtr->iMargin;
315 /* move text behind pic */
316 tx += *w;
317 }
318 }
319
320 if (iw && bw) {
321 /* since we're done with the layout we can
322 now calculate the position of bmp which
323 has no influence on alignment and layout
324 because of img */
325 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
326 bx = cx - bw + infoPtr->iMargin;
327 else
328 bx = cx + cw + infoPtr->iMargin;
329 }
330
331 if (iw || bw) {
332 HDC hClipDC = GetDC(hwnd);
333 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
334 SelectClipRgn(hClipDC, hClipRgn);
335
336 if (bw) {
337 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
338 SelectObject (hdcBitmap, phdi->hbm);
339 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
340 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
341 DeleteDC (hdcBitmap);
342 }
343
344 if (iw) {
345 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
346 ix, r.top + ((INT)rh - infoPtr->himl->cy) / 2,
347 infoPtr->himl->cx, infoPtr->himl->cy, CLR_DEFAULT, CLR_DEFAULT, 0);
348 }
349
350 DeleteObject(hClipRgn);
Filip Navara52cf1852005-07-26 18:25:46 +0000351 ReleaseDC(hwnd, hClipDC);
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000352 }
353
354 if (((phdi->fmt & HDF_STRING)
Martin Fuchs33bdf532000-04-28 14:46:36 +0000355 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
356 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
357 && (phdi->pszText)) {
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000358 oldBkMode = SetBkMode(hdc, TRANSPARENT);
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000359 r.left = tx;
360 r.right = tx + tw;
Martin Fuchsfe7d46a2002-10-18 00:20:04 +0000361 DrawTextW (hdc, phdi->pszText, -1,
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000362 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
Martin Fuchsfe7d46a2002-10-18 00:20:04 +0000363 if (oldBkMode != TRANSPARENT)
364 SetBkMode(hdc, oldBkMode);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000365 }
Uwe Bonnes018c6542000-10-19 22:26:17 +0000366 }/*Ownerdrawn*/
Eric Kohlcad17ff1999-03-12 17:42:50 +0000367
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000368 return phdi->rect.right;
369}
370
371
Vincent Béron9a624912002-05-31 23:06:46 +0000372static void
Eric Kohlcad17ff1999-03-12 17:42:50 +0000373HEADER_Refresh (HWND hwnd, HDC hdc)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000374{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000375 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000376 HFONT hFont, hOldFont;
377 RECT rect;
378 HBRUSH hbrBk;
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000379 UINT i;
380 INT x;
Frank Richter564872c2005-07-25 11:09:09 +0000381 HTHEME theme = GetWindowTheme (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000382
383 /* get rect for the bar, adjusted for the border */
Eric Kohlcad17ff1999-03-12 17:42:50 +0000384 GetClientRect (hwnd, &rect);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000385
Alexandre Julliarda3960291999-02-26 11:11:13 +0000386 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
387 hOldFont = SelectObject (hdc, hFont);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000388
389 /* draw Background */
Frank Richter564872c2005-07-25 11:09:09 +0000390 if (theme == NULL) {
391 hbrBk = GetSysColorBrush(COLOR_3DFACE);
392 FillRect(hdc, &rect, hbrBk);
393 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000394
395 x = rect.left;
Phil Krylov030dbe2d2005-08-25 19:18:14 +0000396 for (i = 0; x <= rect.right && i < infoPtr->uNumItem; i++) {
Frank Richter564872c2005-07-25 11:09:09 +0000397 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i),
398 infoPtr->iHotItem == i);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000399 }
400
401 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
402 rect.left = x;
Frank Richter564872c2005-07-25 11:09:09 +0000403 if (theme != NULL) {
404 DrawThemeBackground (theme, hdc, HP_HEADERITEM, HIS_NORMAL, &rect,
405 NULL);
406 }
407 else {
408 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS)
409 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
410 else
411 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
412 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000413 }
414
Alexandre Julliarda3960291999-02-26 11:11:13 +0000415 SelectObject (hdc, hOldFont);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000416}
417
418
419static void
Eric Kohlcad17ff1999-03-12 17:42:50 +0000420HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000421{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000422 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000423 HFONT hFont, hOldFont;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000424
Alexandre Julliarda3960291999-02-26 11:11:13 +0000425 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
426 hOldFont = SelectObject (hdc, hFont);
Frank Richter07f86902005-08-03 11:45:19 +0000427 HEADER_DrawItem (hwnd, hdc, iItem, infoPtr->iHotItem == iItem);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000428 SelectObject (hdc, hOldFont);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000429}
430
431
432static void
Eric Kohlcad17ff1999-03-12 17:42:50 +0000433HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000434{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000435 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000436 RECT rect, rcTest;
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000437 UINT iCount;
438 INT width;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000439 BOOL bNoWidth;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000440
Eric Kohlcad17ff1999-03-12 17:42:50 +0000441 GetClientRect (hwnd, &rect);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000442
443 *pFlags = 0;
444 bNoWidth = FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000445 if (PtInRect (&rect, *lpPt))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000446 {
447 if (infoPtr->uNumItem == 0) {
448 *pFlags |= HHT_NOWHERE;
449 *pItem = 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000450 TRACE("NOWHERE\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000451 return;
452 }
453 else {
454 /* somewhere inside */
455 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
456 rect = infoPtr->items[iCount].rect;
457 width = rect.right - rect.left;
458 if (width == 0) {
459 bNoWidth = TRUE;
460 continue;
461 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000462 if (PtInRect (&rect, *lpPt)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000463 if (width <= 2 * DIVIDER_WIDTH) {
464 *pFlags |= HHT_ONHEADER;
465 *pItem = iCount;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000466 TRACE("ON HEADER %d\n", iCount);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000467 return;
468 }
469 if (iCount > 0) {
470 rcTest = rect;
471 rcTest.right = rcTest.left + DIVIDER_WIDTH;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000472 if (PtInRect (&rcTest, *lpPt)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000473 if (bNoWidth) {
474 *pFlags |= HHT_ONDIVOPEN;
475 *pItem = iCount - 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000476 TRACE("ON DIVOPEN %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000477 return;
478 }
479 else {
480 *pFlags |= HHT_ONDIVIDER;
481 *pItem = iCount - 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000482 TRACE("ON DIVIDER %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000483 return;
484 }
485 }
486 }
487 rcTest = rect;
488 rcTest.left = rcTest.right - DIVIDER_WIDTH;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000489 if (PtInRect (&rcTest, *lpPt)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000490 *pFlags |= HHT_ONDIVIDER;
491 *pItem = iCount;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000492 TRACE("ON DIVIDER %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000493 return;
494 }
495
496 *pFlags |= HHT_ONHEADER;
497 *pItem = iCount;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000498 TRACE("ON HEADER %d\n", iCount);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000499 return;
500 }
501 }
502
503 /* check for last divider part (on nowhere) */
504 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
505 rect.left = rect.right;
506 rect.right += DIVIDER_WIDTH;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000507 if (PtInRect (&rect, *lpPt)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000508 if (bNoWidth) {
509 *pFlags |= HHT_ONDIVOPEN;
510 *pItem = infoPtr->uNumItem - 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000511 TRACE("ON DIVOPEN %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000512 return;
513 }
514 else {
515 *pFlags |= HHT_ONDIVIDER;
516 *pItem = infoPtr->uNumItem-1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000517 TRACE("ON DIVIDER %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000518 return;
519 }
520 }
521
522 *pFlags |= HHT_NOWHERE;
523 *pItem = 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000524 TRACE("NOWHERE\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000525 return;
526 }
527 }
528 else {
529 if (lpPt->x < rect.left) {
Alexandre Julliarda099a551999-06-12 15:45:58 +0000530 TRACE("TO LEFT\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000531 *pFlags |= HHT_TOLEFT;
532 }
533 else if (lpPt->x > rect.right) {
Thuy Nguyen30eaa591999-10-13 13:47:36 +0000534 TRACE("TO RIGHT\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000535 *pFlags |= HHT_TORIGHT;
536 }
537
538 if (lpPt->y < rect.top) {
Alexandre Julliarda099a551999-06-12 15:45:58 +0000539 TRACE("ABOVE\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000540 *pFlags |= HHT_ABOVE;
541 }
542 else if (lpPt->y > rect.bottom) {
Alexandre Julliarda099a551999-06-12 15:45:58 +0000543 TRACE("BELOW\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000544 *pFlags |= HHT_BELOW;
545 }
546 }
547
548 *pItem = 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000549 TRACE("flags=0x%X\n", *pFlags);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000550 return;
551}
552
553
554static void
Eric Kohlcad17ff1999-03-12 17:42:50 +0000555HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000556{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000557 RECT rect;
558 HPEN hOldPen;
559 INT oldRop;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000560
Eric Kohlcad17ff1999-03-12 17:42:50 +0000561 GetClientRect (hwnd, &rect);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000562
Alexandre Julliarda3960291999-02-26 11:11:13 +0000563 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
564 oldRop = SetROP2 (hdc, R2_XORPEN);
565 MoveToEx (hdc, x, rect.top, NULL);
566 LineTo (hdc, x, rect.bottom);
567 SetROP2 (hdc, oldRop);
568 SelectObject (hdc, hOldPen);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000569}
570
Mikołaj Zalewski84c31892006-04-17 17:09:56 +0200571static UINT HEADER_NotifyCodeWtoA(UINT code)
572{
573 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
574 if (code >= HDN_LAST && code <= HDN_FIRST_UNICODE)
575 return code + HDN_UNICODE_OFFSET;
576 else
577 return code;
578}
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000579
Alexandre Julliarda3960291999-02-26 11:11:13 +0000580static BOOL
Eric Kohlcad17ff1999-03-12 17:42:50 +0000581HEADER_SendSimpleNotify (HWND hwnd, UINT code)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000582{
Uwe Bonnes018c6542000-10-19 22:26:17 +0000583 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000584 NMHDR nmhdr;
585
Eric Kohlcad17ff1999-03-12 17:42:50 +0000586 nmhdr.hwndFrom = hwnd;
Robert Shearmancdb263e2004-08-25 17:33:01 +0000587 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000588 nmhdr.code = code;
589
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +0000590 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000591 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000592}
593
Aric Stewart3054b762000-06-11 20:39:14 +0000594static BOOL
Mikołaj Zalewski84c31892006-04-17 17:09:56 +0200595HEADER_SendHeaderNotifyT (HWND hwnd, UINT code, INT iItem, INT mask)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000596{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000597 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000598 NMHEADERA nmhdr;
599 HDITEMA nmitem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000600
Eric Kohlcad17ff1999-03-12 17:42:50 +0000601 nmhdr.hdr.hwndFrom = hwnd;
Robert Shearmancdb263e2004-08-25 17:33:01 +0000602 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Mikołaj Zalewski84c31892006-04-17 17:09:56 +0200603 nmhdr.hdr.code = (infoPtr->nNotifyFormat == NFR_UNICODE ? code : HEADER_NotifyCodeWtoA(code));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000604 nmhdr.iItem = iItem;
605 nmhdr.iButton = 0;
606 nmhdr.pitem = &nmitem;
Ulrich Czekallaf235a7b2000-11-25 01:25:46 +0000607 nmitem.mask = mask;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000608 nmitem.cxy = infoPtr->items[iItem].cxy;
609 nmitem.hbm = infoPtr->items[iItem].hbm;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000610 nmitem.pszText = NULL;
611 nmitem.cchTextMax = 0;
Marcus Meissner73458b01998-12-26 12:54:29 +0000612/* nmitem.pszText = infoPtr->items[iItem].pszText; */
613/* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000614 nmitem.fmt = infoPtr->items[iItem].fmt;
615 nmitem.lParam = infoPtr->items[iItem].lParam;
616 nmitem.iOrder = infoPtr->items[iItem].iOrder;
617 nmitem.iImage = infoPtr->items[iItem].iImage;
618
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +0000619 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
Raphael Junqueirae3d53b42005-11-15 16:54:41 +0000620 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
621}
622
623/**
624 * Send Disp Info notification.
625 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
626 * (so we handle the two cases only doing a specific cast for pszText).
627 *
628 * @param hwnd : hwnd header container handler
629 * @param mask : notification mask (usually HDI_TEXT or HDI_IMAGE)
630 * @param pDispInfo : NMHDDISPINFO structure (can be unicode or ansi)
631 * @param isW : TRUE if dispinfo is Unicode
632 */
633static BOOL
634HEADER_SendHeaderDispInfoNotify(HWND hwnd, INT iItem, INT mask, LPHDITEMW phdi, HEADER_ITEM* lpItem, BOOL isW)
635{
636 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
637 BOOL ret;
638 BOOL convertToAnsi = FALSE;
639 BOOL convertToUnicode = FALSE;
640 BOOL isUnicodeNotify = FALSE;
641 NMHDDISPINFOW dispInfo;
642
643 if (mask & HDI_TEXT)
644 {
645 convertToAnsi = (isW && infoPtr->nNotifyFormat == NFR_ANSI);
646 convertToUnicode = (!isW && infoPtr->nNotifyFormat == NFR_UNICODE);
647 }
648 isUnicodeNotify = (isW && !convertToAnsi);
649
650 memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
651 dispInfo.hdr.hwndFrom = hwnd;
652 dispInfo.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
653 if (isUnicodeNotify || convertToUnicode)
654 {
655 dispInfo.hdr.code = HDN_GETDISPINFOW;
656 }
657 else
658 {
659 dispInfo.hdr.code = HDN_GETDISPINFOA;
660 }
661 dispInfo.iItem = iItem;
662 dispInfo.mask = mask;
663 /*
664 dispInfo.pszText = Alloc(sizeof(WCHAR) * 260);
665 dispInfo.cchTextMax = 260;
666 */
667 ret = (BOOL) SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
668 (WPARAM) dispInfo.hdr.idFrom,
669 (LPARAM) &dispInfo);
670
671 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
672 dispInfo.mask,
673 (isUnicodeNotify ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
674 (void*) dispInfo.lParam);
675
676 if (dispInfo.mask & HDI_DI_SETITEM)
677 {
678 if (dispInfo.mask & HDI_IMAGE)
679 {
680 lpItem->iImage = dispInfo.iImage;
681 }
682 if (dispInfo.mask & HDI_TEXT)
683 {
684 if (isUnicodeNotify || convertToUnicode)
685 Str_SetPtrW(&lpItem->pszText, (LPCWSTR)dispInfo.pszText);
686 else /*if (convertToAnsi || !isW)*/
687 Str_SetPtrAtoW(&lpItem->pszText, (LPCSTR)dispInfo.pszText);
688 }
689
690 FIXME("NMHDDISPINFO returns with flags HDI_DI_SETITEM\n");
691 }
692
693 if (NULL != phdi)
694 {
695 if ((phdi->mask & mask) & HDI_IMAGE)
696 {
697 phdi->iImage = dispInfo.iImage;
698 }
699 if ((phdi->mask & mask) & HDI_TEXT)
700 {
701 if (isUnicodeNotify)
702 Str_GetPtrW ((LPCWSTR)dispInfo.pszText, phdi->pszText, phdi->cchTextMax);
703 else if (convertToUnicode)
704 Str_GetPtrWtoA ((LPCWSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
705 else /*if (!isW) */
706 Str_GetPtrA ((LPCSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
707 }
708 }
709 return ret;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000710}
711
712
Alexandre Julliarda3960291999-02-26 11:11:13 +0000713static BOOL
Eric Kohlcad17ff1999-03-12 17:42:50 +0000714HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000715{
Uwe Bonnes018c6542000-10-19 22:26:17 +0000716 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000717 NMHEADERA nmhdr;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000718
Eric Kohlcad17ff1999-03-12 17:42:50 +0000719 nmhdr.hdr.hwndFrom = hwnd;
Robert Shearmancdb263e2004-08-25 17:33:01 +0000720 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000721 nmhdr.hdr.code = code;
722 nmhdr.iItem = iItem;
723 nmhdr.iButton = 0;
724 nmhdr.pitem = NULL;
725
Uwe Bonnes018c6542000-10-19 22:26:17 +0000726 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
Eric Kohlcad17ff1999-03-12 17:42:50 +0000727 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000728}
729
730
731static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000732HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000733{
Alexandre Julliarda099a551999-06-12 15:45:58 +0000734 FIXME("empty stub!\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000735 return 0;
736}
737
738
739static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000740HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000741{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000742 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000743 INT iItem = (INT)wParam;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000744
Alexandre Julliarda099a551999-06-12 15:45:58 +0000745 TRACE("[iItem=%d]\n", iItem);
Vincent Béron9a624912002-05-31 23:06:46 +0000746
Alexandre Julliarda3960291999-02-26 11:11:13 +0000747 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000748 return FALSE;
749
750 if (infoPtr->uNumItem == 1) {
Alexandre Julliarda099a551999-06-12 15:45:58 +0000751 TRACE("Simple delete!\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000752 if (infoPtr->items[0].pszText)
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000753 Free (infoPtr->items[0].pszText);
754 Free (infoPtr->items);
Phil Krylov682dd702005-08-29 12:17:42 +0000755 Free(infoPtr->order);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000756 infoPtr->items = 0;
Phil Krylov682dd702005-08-29 12:17:42 +0000757 infoPtr->order = 0;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000758 infoPtr->uNumItem = 0;
759 }
760 else {
761 HEADER_ITEM *oldItems = infoPtr->items;
Bill Medland69f18272002-07-16 01:14:46 +0000762 INT i;
763 INT iOrder;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000764 TRACE("Complex delete! [iItem=%d]\n", iItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000765
Phil Krylov682dd702005-08-29 12:17:42 +0000766 for (i = 0; i < infoPtr->uNumItem; i++)
767 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000768 if (infoPtr->items[iItem].pszText)
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000769 Free (infoPtr->items[iItem].pszText);
Bill Medland69f18272002-07-16 01:14:46 +0000770 iOrder = infoPtr->items[iItem].iOrder;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000771
772 infoPtr->uNumItem--;
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000773 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000774 /* pre delete copy */
775 if (iItem > 0) {
776 memcpy (&infoPtr->items[0], &oldItems[0],
777 iItem * sizeof(HEADER_ITEM));
778 }
779
780 /* post delete copy */
781 if (iItem < infoPtr->uNumItem) {
782 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
783 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
784 }
785
Bill Medland69f18272002-07-16 01:14:46 +0000786 /* Correct the orders */
Phil Krylov682dd702005-08-29 12:17:42 +0000787 if (iOrder < infoPtr->uNumItem)
Bill Medland69f18272002-07-16 01:14:46 +0000788 {
Phil Krylov682dd702005-08-29 12:17:42 +0000789 memmove(&infoPtr->order[iOrder], &infoPtr->order[iOrder + 1],
790 (infoPtr->uNumItem - iOrder) * sizeof(INT));
791 for (i = 0; i < infoPtr->uNumItem; i++)
792 {
793 if (infoPtr->order[i] > iItem)
794 infoPtr->order[i]--;
795 if (i >= iOrder)
796 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
797 }
Bill Medland69f18272002-07-16 01:14:46 +0000798 }
Phil Krylov682dd702005-08-29 12:17:42 +0000799
800 for (i = 0; i < infoPtr->uNumItem; i++)
801 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000802 Free (oldItems);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000803 }
804
Eric Kohlcad17ff1999-03-12 17:42:50 +0000805 HEADER_SetItemBounds (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000806
Chris Morgan3cbc1682000-06-04 01:34:31 +0000807 InvalidateRect(hwnd, NULL, FALSE);
Vincent Béron9a624912002-05-31 23:06:46 +0000808
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000809 return TRUE;
810}
811
812
813static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000814HEADER_GetImageList (HWND hwnd)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000815{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000816 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000817
818 return (LRESULT)infoPtr->himl;
819}
820
821
822static LRESULT
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000823HEADER_GetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000824{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000825 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000826 HEADER_ITEM *lpItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000827
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000828 if (!phdi)
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000829 return FALSE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000830
Alexandre Julliarda099a551999-06-12 15:45:58 +0000831 TRACE("[nItem=%d]\n", nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000832
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000833 if (phdi->mask == 0)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000834 return TRUE;
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000835 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
Vitaliy Margolendef2bb62005-11-17 11:06:18 +0000836 return FALSE;
837
838 lpItem = &infoPtr->items[nItem];
Evan Deaublc8483212005-01-10 14:25:30 +0000839
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000840 if (phdi->mask & HDI_BITMAP)
Evan Deaublc8483212005-01-10 14:25:30 +0000841 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000842
843 if (phdi->mask & HDI_FORMAT)
Evan Deaublc8483212005-01-10 14:25:30 +0000844 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000845
846 if (phdi->mask & HDI_WIDTH)
Evan Deaublc8483212005-01-10 14:25:30 +0000847 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000848
849 if (phdi->mask & HDI_LPARAM)
Evan Deaublc8483212005-01-10 14:25:30 +0000850 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000851
Raphael Junqueirae3d53b42005-11-15 16:54:41 +0000852 if (phdi->mask & HDI_IMAGE)
853 {
854 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
855 if (lpItem->iImage == I_IMAGECALLBACK)
856 {
857 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, phdi, lpItem, bUnicode);
858 }
859 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000860
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000861 if (phdi->mask & HDI_ORDER)
Evan Deaublc8483212005-01-10 14:25:30 +0000862 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000863
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000864 if (phdi->mask & HDI_TEXT)
865 {
Raphael Junqueirae3d53b42005-11-15 16:54:41 +0000866 if (lpItem == NULL) *phdi->pszText = 0; /* null pointer check */
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000867 else if (lpItem->pszText == LPSTR_TEXTCALLBACKW) /* covers == TEXTCALLBACKA too */
Raphael Junqueirae3d53b42005-11-15 16:54:41 +0000868 {
869 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, phdi, lpItem, bUnicode);
870 }
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000871 else
872 {
873 if (bUnicode)
874 Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
875 else
876 Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
877 }
Evan Deaublc8483212005-01-10 14:25:30 +0000878 }
Eric Kohl8d2933d1998-11-22 18:12:12 +0000879
880 return TRUE;
881}
882
883
Patrik Stridvall896889f1999-05-08 12:50:36 +0000884inline static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000885HEADER_GetItemCount (HWND hwnd)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000886{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000887 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Eric Kohl8d2933d1998-11-22 18:12:12 +0000888 return infoPtr->uNumItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000889}
890
891
892static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000893HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000894{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000895 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000896 INT iItem = (INT)wParam;
897 LPRECT lpRect = (LPRECT)lParam;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000898
Alexandre Julliarda3960291999-02-26 11:11:13 +0000899 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000900 return FALSE;
901
902 lpRect->left = infoPtr->items[iItem].rect.left;
903 lpRect->right = infoPtr->items[iItem].rect.right;
904 lpRect->top = infoPtr->items[iItem].rect.top;
905 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
906
907 return TRUE;
908}
909
910
Vincent Béron9a624912002-05-31 23:06:46 +0000911static LRESULT
Uwe Bonnes018c6542000-10-19 22:26:17 +0000912HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
913{
Uwe Bonnes018c6542000-10-19 22:26:17 +0000914 LPINT order = (LPINT) lParam;
915 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Eric Kohl8d2933d1998-11-22 18:12:12 +0000916
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000917 if ((unsigned int)wParam <infoPtr->uNumItem)
Uwe Bonnes018c6542000-10-19 22:26:17 +0000918 return FALSE;
Phil Krylov682dd702005-08-29 12:17:42 +0000919
920 memcpy(order, infoPtr->order, infoPtr->uNumItem * sizeof(INT));
Uwe Bonnes018c6542000-10-19 22:26:17 +0000921 return TRUE;
922}
923
Vincent Béron9a624912002-05-31 23:06:46 +0000924static LRESULT
Uwe Bonnes018c6542000-10-19 22:26:17 +0000925HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
926{
927 int i;
928 LPINT order = (LPINT) lParam;
929 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
930 HEADER_ITEM *lpItem;
931
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000932 if ((unsigned int)wParam <infoPtr->uNumItem)
Uwe Bonnes018c6542000-10-19 22:26:17 +0000933 return FALSE;
Phil Krylov682dd702005-08-29 12:17:42 +0000934 memcpy(infoPtr->order, order, infoPtr->uNumItem * sizeof(INT));
Uwe Bonnes018c6542000-10-19 22:26:17 +0000935 for (i=0; i<(int)wParam; i++)
936 {
Bill Medland69f18272002-07-16 01:14:46 +0000937 lpItem = &infoPtr->items[*order++];
Uwe Bonnes018c6542000-10-19 22:26:17 +0000938 lpItem->iOrder=i;
939 }
940 infoPtr->bRectsValid=0;
941 InvalidateRect(hwnd, NULL, FALSE);
942 return TRUE;
943}
Eric Kohl8d2933d1998-11-22 18:12:12 +0000944
Patrik Stridvall896889f1999-05-08 12:50:36 +0000945inline static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000946HEADER_GetUnicodeFormat (HWND hwnd)
Eric Kohl8d2933d1998-11-22 18:12:12 +0000947{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000948 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Mikołaj Zalewski7a7f80e2006-04-18 19:44:09 +0200949 return (infoPtr->nNotifyFormat == NFR_UNICODE);
Eric Kohl8d2933d1998-11-22 18:12:12 +0000950}
951
952
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000953static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000954HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000955{
956 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
957
Eric Kohlcad17ff1999-03-12 17:42:50 +0000958 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000959
Vitaliy Margolen4cf764f2004-09-13 18:05:02 +0000960 if (phti->flags == HHT_NOWHERE)
Aric Stewart7d6e9a12000-05-05 18:22:44 +0000961 return -1;
Vitaliy Margolen4cf764f2004-09-13 18:05:02 +0000962 else
963 return phti->iItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000964}
965
966
967static LRESULT
Vitaliy Margolen89a49182005-10-28 10:40:27 +0000968HEADER_InsertItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000969{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000970 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000971 HEADER_ITEM *lpItem;
Vitaliy Margolen89a49182005-10-28 10:40:27 +0000972 INT iOrder;
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000973 UINT i;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000974
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000975 if ((phdi == NULL) || (nItem < 0))
976 return -1;
977
978 if (nItem > infoPtr->uNumItem)
979 nItem = infoPtr->uNumItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000980
Robert Shearmanf644c782003-05-22 03:34:54 +0000981 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
Ge van Geldorpc00ded52005-09-18 12:29:35 +0000982 if (iOrder < 0)
983 iOrder = 0;
984 else if (infoPtr->uNumItem < iOrder)
985 iOrder = infoPtr->uNumItem;
Robert Shearmanf644c782003-05-22 03:34:54 +0000986
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000987 if (infoPtr->uNumItem == 0) {
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000988 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
Phil Krylov682dd702005-08-29 12:17:42 +0000989 infoPtr->order = Alloc(sizeof(INT));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000990 infoPtr->uNumItem++;
991 }
992 else {
993 HEADER_ITEM *oldItems = infoPtr->items;
Phil Krylov682dd702005-08-29 12:17:42 +0000994 INT *oldOrder = infoPtr->order;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000995
996 infoPtr->uNumItem++;
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000997 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
Luc Tourangeau4d6df2c1999-03-12 17:31:08 +0000998 if (nItem == 0) {
999 memcpy (&infoPtr->items[1], &oldItems[0],
1000 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001001 }
Luc Tourangeau4d6df2c1999-03-12 17:31:08 +00001002 else
1003 {
1004 /* pre insert copy */
1005 if (nItem > 0) {
1006 memcpy (&infoPtr->items[0], &oldItems[0],
1007 nItem * sizeof(HEADER_ITEM));
1008 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001009
Luc Tourangeau4d6df2c1999-03-12 17:31:08 +00001010 /* post insert copy */
1011 if (nItem < infoPtr->uNumItem - 1) {
1012 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
Huw D M Davies25539761999-12-04 03:59:33 +00001013 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
Luc Tourangeau4d6df2c1999-03-12 17:31:08 +00001014 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001015 }
Vincent Béron9a624912002-05-31 23:06:46 +00001016
Phil Krylov682dd702005-08-29 12:17:42 +00001017 infoPtr->order = Alloc(sizeof(INT) * infoPtr->uNumItem);
1018 memcpy(infoPtr->order, oldOrder, iOrder * sizeof(INT));
1019 infoPtr->order[iOrder] = nItem;
1020 memcpy(&infoPtr->order[iOrder + 1], &oldOrder[iOrder],
1021 (infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
1022
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001023 Free (oldItems);
Phil Krylov682dd702005-08-29 12:17:42 +00001024 Free(oldOrder);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001025 }
1026
Phil Krylov682dd702005-08-29 12:17:42 +00001027 for (i = 0; i < infoPtr->uNumItem; i++)
Robert Shearmanf644c782003-05-22 03:34:54 +00001028 {
Phil Krylov682dd702005-08-29 12:17:42 +00001029 if (i != iOrder && infoPtr->order[i] >= nItem)
1030 infoPtr->order[i]++;
1031 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
Robert Shearmanf644c782003-05-22 03:34:54 +00001032 }
1033
Bill Medland69f18272002-07-16 01:14:46 +00001034 lpItem = &infoPtr->items[nItem];
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001035 lpItem->bDown = FALSE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001036
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001037 if (phdi->mask & HDI_WIDTH)
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001038 lpItem->cxy = phdi->cxy;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001039
Eric Kohl8d2933d1998-11-22 18:12:12 +00001040 if (phdi->mask & HDI_FORMAT)
1041 lpItem->fmt = phdi->fmt;
1042
1043 if (lpItem->fmt == 0)
1044 lpItem->fmt = HDF_LEFT;
1045
1046 if (phdi->mask & HDI_BITMAP)
1047 lpItem->hbm = phdi->hbm;
1048
1049 if (phdi->mask & HDI_LPARAM)
1050 lpItem->lParam = phdi->lParam;
1051
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001052 if (phdi->mask & HDI_IMAGE)
1053 {
1054 if (phdi->iImage != I_IMAGECALLBACK)
1055 {
1056 lpItem->iImage = phdi->iImage;
1057 }
1058 else
1059 {
1060 lpItem->iImage = phdi->iImage;
1061 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1062 }
1063 }
Eric Kohl8d2933d1998-11-22 18:12:12 +00001064
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001065 if (phdi->mask & HDI_TEXT)
Robert Shearmanf644c782003-05-22 03:34:54 +00001066 {
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001067 if (!phdi->pszText) phdi->pszText = '\0'; /* null pointer check */
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001068 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001069 {
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001070 if (bUnicode)
1071 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1072 else
1073 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001074 }
1075 else
1076 {
1077 lpItem->pszText = phdi->pszText;
1078 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1079 }
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001080 lpItem->fmt |= HDF_STRING;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001081 }
1082
Robert Shearmanf644c782003-05-22 03:34:54 +00001083 lpItem->iOrder = iOrder;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001084
Eric Kohlcad17ff1999-03-12 17:42:50 +00001085 HEADER_SetItemBounds (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001086
Chris Morgan3cbc1682000-06-04 01:34:31 +00001087 InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001088
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001089 return nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001090}
1091
1092
1093static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001094HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001095{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001096 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001097 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1098
Eric Kohlcad17ff1999-03-12 17:42:50 +00001099 lpLayout->pwpos->hwnd = hwnd;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001100 lpLayout->pwpos->hwndInsertAfter = 0;
1101 lpLayout->pwpos->x = lpLayout->prc->left;
1102 lpLayout->pwpos->y = lpLayout->prc->top;
1103 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001104 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_HIDDEN)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001105 lpLayout->pwpos->cy = 0;
Martin Fuchs33bdf532000-04-28 14:46:36 +00001106 else {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001107 lpLayout->pwpos->cy = infoPtr->nHeight;
Martin Fuchs33bdf532000-04-28 14:46:36 +00001108 lpLayout->prc->top += infoPtr->nHeight;
1109 }
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00001110 lpLayout->pwpos->flags = SWP_NOZORDER;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001111
Alexandre Julliarda099a551999-06-12 15:45:58 +00001112 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001113 lpLayout->pwpos->x, lpLayout->pwpos->y,
1114 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1115
Martin Fuchs33bdf532000-04-28 14:46:36 +00001116 infoPtr->bRectsValid = FALSE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001117
1118 return TRUE;
1119}
1120
1121
1122static LRESULT
Eric Kohl4718b6d2000-12-13 01:52:23 +00001123HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001124{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001125 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001126 HIMAGELIST himlOld;
1127
Frank Richter9e570912005-08-30 10:07:17 +00001128 TRACE("(himl %p)\n", himl);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001129 himlOld = infoPtr->himl;
Eric Kohl4718b6d2000-12-13 01:52:23 +00001130 infoPtr->himl = himl;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001131
1132 /* FIXME: Refresh needed??? */
1133
1134 return (LRESULT)himlOld;
1135}
1136
1137
1138static LRESULT
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +00001139HEADER_GetBitmapMargin(HWND hwnd)
1140{
1141 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1142
1143 return infoPtr->iMargin;
1144}
1145
1146static LRESULT
1147HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1148{
1149 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1150 INT oldMargin = infoPtr->iMargin;
1151
1152 infoPtr->iMargin = (INT)wParam;
1153
1154 return oldMargin;
1155}
1156
1157static LRESULT
Vitaliy Margolen05905cc2005-10-27 10:19:29 +00001158HEADER_SetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001159{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001160 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001161 HEADER_ITEM *lpItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001162
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001163 if (phdi == NULL)
1164 return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001165 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001166 return FALSE;
1167
Alexandre Julliarda099a551999-06-12 15:45:58 +00001168 TRACE("[nItem=%d]\n", nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001169
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001170 if (HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001171 return FALSE;
1172
Bill Medland69f18272002-07-16 01:14:46 +00001173 lpItem = &infoPtr->items[nItem];
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001174 if (phdi->mask & HDI_BITMAP)
1175 lpItem->hbm = phdi->hbm;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001176
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001177 if (phdi->mask & HDI_FORMAT)
1178 lpItem->fmt = phdi->fmt;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001179
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001180 if (phdi->mask & HDI_LPARAM)
1181 lpItem->lParam = phdi->lParam;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001182
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001183 if (phdi->mask & HDI_WIDTH)
1184 lpItem->cxy = phdi->cxy;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001185
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001186 if (phdi->mask & HDI_IMAGE)
1187 {
1188 if (phdi->iImage != I_IMAGECALLBACK)
1189 {
1190 lpItem->iImage = phdi->iImage;
1191 }
1192 else
1193 {
1194 lpItem->iImage = phdi->iImage;
1195 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1196 }
1197 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001198
Vitaliy Margolen05905cc2005-10-27 10:19:29 +00001199 if (phdi->mask & HDI_TEXT)
1200 {
1201 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
1202 {
1203 if (lpItem->pszText)
1204 {
1205 Free(lpItem->pszText);
1206 lpItem->pszText = NULL;
1207 }
1208 if (phdi->pszText)
1209 {
1210 if (bUnicode)
1211 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1212 else
1213 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
1214 }
1215 }
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001216 else
1217 {
1218 lpItem->pszText = phdi->pszText;
1219 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1220 }
Vitaliy Margolen05905cc2005-10-27 10:19:29 +00001221 }
1222
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001223 if (phdi->mask & HDI_ORDER)
Uwe Bonnes018c6542000-10-19 22:26:17 +00001224 {
Phil Krylov682dd702005-08-29 12:17:42 +00001225 INT i, nMin, nMax;
1226
1227 if (lpItem->iOrder < phdi->iOrder)
1228 {
1229 memmove(&infoPtr->order[lpItem->iOrder],
1230 &infoPtr->order[lpItem->iOrder + 1],
1231 (phdi->iOrder - lpItem->iOrder) * sizeof(INT));
1232 }
1233 if (phdi->iOrder < lpItem->iOrder)
1234 {
1235 memmove(&infoPtr->order[phdi->iOrder + 1],
1236 &infoPtr->order[phdi->iOrder],
1237 (lpItem->iOrder - phdi->iOrder) * sizeof(INT));
1238 }
1239 infoPtr->order[phdi->iOrder] = nItem;
1240 nMin = min(lpItem->iOrder, phdi->iOrder);
1241 nMax = max(lpItem->iOrder, phdi->iOrder);
1242 for (i = nMin; i <= nMax; i++)
1243 {
1244 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1245 }
Uwe Bonnes018c6542000-10-19 22:26:17 +00001246 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001247
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001248 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001249
Eric Kohlcad17ff1999-03-12 17:42:50 +00001250 HEADER_SetItemBounds (hwnd);
Chris Morgan3cbc1682000-06-04 01:34:31 +00001251
1252 InvalidateRect(hwnd, NULL, FALSE);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001253
1254 return TRUE;
1255}
1256
Patrik Stridvall896889f1999-05-08 12:50:36 +00001257inline static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001258HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
Eric Kohl8d2933d1998-11-22 18:12:12 +00001259{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001260 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Mikołaj Zalewski7a7f80e2006-04-18 19:44:09 +02001261 BOOL bTemp = (infoPtr->nNotifyFormat == NFR_UNICODE);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001262
Mikołaj Zalewski7a7f80e2006-04-18 19:44:09 +02001263 infoPtr->nNotifyFormat = ((BOOL)wParam ? NFR_UNICODE : NFR_ANSI);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001264
1265 return bTemp;
1266}
1267
1268
1269static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001270HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001271{
1272 HEADER_INFO *infoPtr;
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001273 TEXTMETRICW tm;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001274 HFONT hOldFont;
1275 HDC hdc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001276
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001277 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001278 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001279
Dimitrie O. Paunc5940432003-11-20 22:04:13 +00001280 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001281 infoPtr->uNumItem = 0;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001282 infoPtr->hFont = 0;
1283 infoPtr->items = 0;
Phil Krylov682dd702005-08-29 12:17:42 +00001284 infoPtr->order = 0;
Martin Fuchs33bdf532000-04-28 14:46:36 +00001285 infoPtr->bRectsValid = FALSE;
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001286 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1287 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1288 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001289 infoPtr->bPressed = FALSE;
1290 infoPtr->bTracking = FALSE;
1291 infoPtr->iMoveItem = 0;
1292 infoPtr->himl = 0;
1293 infoPtr->iHotItem = -1;
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +00001294 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
Eric Kohl40f29ee2000-11-25 03:07:01 +00001295 infoPtr->nNotifyFormat =
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001296 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001297
Alexandre Julliarda3960291999-02-26 11:11:13 +00001298 hdc = GetDC (0);
1299 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001300 GetTextMetricsW (hdc, &tm);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001301 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001302 SelectObject (hdc, hOldFont);
1303 ReleaseDC (0, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001304
Frank Richterd219a542005-07-27 15:16:09 +00001305 OpenThemeData(hwnd, themeClass);
Frank Richter564872c2005-07-25 11:09:09 +00001306
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001307 return 0;
1308}
1309
1310
1311static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001312HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001313{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001314 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001315 HEADER_ITEM *lpItem;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001316 INT nItem;
Frank Richter564872c2005-07-25 11:09:09 +00001317 HTHEME theme;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001318
1319 if (infoPtr->items) {
Bill Medland69f18272002-07-16 01:14:46 +00001320 lpItem = infoPtr->items;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001321 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001322 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001323 Free (lpItem->pszText);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001324 }
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001325 Free (infoPtr->items);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001326 }
1327
Phil Krylov682dd702005-08-29 12:17:42 +00001328 if (infoPtr->order)
1329 Free(infoPtr->order);
1330
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001331 if (infoPtr->himl)
1332 ImageList_Destroy (infoPtr->himl);
1333
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001334 SetWindowLongPtrW (hwnd, 0, 0);
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001335 Free (infoPtr);
Frank Richter564872c2005-07-25 11:09:09 +00001336
1337 theme = GetWindowTheme(hwnd);
1338 CloseThemeData(theme);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001339 return 0;
1340}
1341
1342
Patrik Stridvall896889f1999-05-08 12:50:36 +00001343static inline LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001344HEADER_GetFont (HWND hwnd)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001345{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001346 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001347
1348 return (LRESULT)infoPtr->hFont;
1349}
1350
1351
1352static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001353HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001354{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001355 POINT pt;
1356 UINT flags;
1357 INT nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001358
Vincent Béron9a624912002-05-31 23:06:46 +00001359 pt.x = (INT)LOWORD(lParam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001360 pt.y = (INT)HIWORD(lParam);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001361 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001362
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001363 if ((GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001364 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMDBLCLICKW, nItem,0);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001365 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001366 HEADER_SendHeaderNotifyT (hwnd, HDN_DIVIDERDBLCLICKW, nItem,0);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001367
1368 return 0;
1369}
1370
1371
1372static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001373HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001374{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001375 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001376 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001377 POINT pt;
1378 UINT flags;
1379 INT nItem;
1380 HDC hdc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001381
Vincent Béron9a624912002-05-31 23:06:46 +00001382 pt.x = (INT)LOWORD(lParam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001383 pt.y = (INT)HIWORD(lParam);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001384 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001385
Eric Kohlcad17ff1999-03-12 17:42:50 +00001386 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1387 SetCapture (hwnd);
Vincent Béron9a624912002-05-31 23:06:46 +00001388 infoPtr->bCaptured = TRUE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001389 infoPtr->bPressed = TRUE;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001390 infoPtr->iMoveItem = nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001391
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001392 infoPtr->items[nItem].bDown = TRUE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001393
1394 /* Send WM_CUSTOMDRAW */
Eric Kohlcad17ff1999-03-12 17:42:50 +00001395 hdc = GetDC (hwnd);
1396 HEADER_RefreshItem (hwnd, hdc, nItem);
1397 ReleaseDC (hwnd, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001398
Alexandre Julliarda099a551999-06-12 15:45:58 +00001399 TRACE("Pressed item %d!\n", nItem);
Vincent Béron9a624912002-05-31 23:06:46 +00001400 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001401 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001402 if (!(HEADER_SendHeaderNotifyT (hwnd, HDN_BEGINTRACKW, nItem,0))) {
Eric Kohlcad17ff1999-03-12 17:42:50 +00001403 SetCapture (hwnd);
Vincent Béron9a624912002-05-31 23:06:46 +00001404 infoPtr->bCaptured = TRUE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001405 infoPtr->bTracking = TRUE;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001406 infoPtr->iMoveItem = nItem;
1407 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1408 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001409
Eric Kohlcad17ff1999-03-12 17:42:50 +00001410 if (!(dwStyle & HDS_FULLDRAG)) {
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001411 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
Eric Kohlcad17ff1999-03-12 17:42:50 +00001412 hdc = GetDC (hwnd);
1413 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1414 ReleaseDC (hwnd, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001415 }
1416
Alexandre Julliarda099a551999-06-12 15:45:58 +00001417 TRACE("Begin tracking item %d!\n", nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001418 }
1419 }
1420
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001421 return 0;
1422}
1423
1424
1425static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001426HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001427{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001428 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001429 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001430 POINT pt;
1431 UINT flags;
1432 INT nItem, nWidth;
1433 HDC hdc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001434
Alexandre Julliard9d615962003-09-17 04:28:28 +00001435 pt.x = (INT)(SHORT)LOWORD(lParam);
1436 pt.y = (INT)(SHORT)HIWORD(lParam);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001437 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001438
1439 if (infoPtr->bPressed) {
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001440 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001441 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
Eric Kohlcad17ff1999-03-12 17:42:50 +00001442 hdc = GetDC (hwnd);
1443 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1444 ReleaseDC (hwnd, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001445
Eric Kohlcad17ff1999-03-12 17:42:50 +00001446 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001447 }
Uwe Bonnes018c6542000-10-19 22:26:17 +00001448 else if (flags == HHT_ONHEADER)
1449 {
1450 HEADER_ITEM *lpItem;
1451 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1452 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1453
1454 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1455 infoPtr->iMoveItem,oldindex,nItem,newindex);
Bill Medland69f18272002-07-16 01:14:46 +00001456 lpItem= &infoPtr->items[nItem];
Uwe Bonnes018c6542000-10-19 22:26:17 +00001457 lpItem->iOrder=oldindex;
1458
Bill Medland69f18272002-07-16 01:14:46 +00001459 lpItem= &infoPtr->items[infoPtr->iMoveItem];
Uwe Bonnes018c6542000-10-19 22:26:17 +00001460 lpItem->iOrder = newindex;
1461
Phil Krylov682dd702005-08-29 12:17:42 +00001462 infoPtr->order[oldindex] = nItem;
1463 infoPtr->order[newindex] = infoPtr->iMoveItem;
1464
Uwe Bonnes018c6542000-10-19 22:26:17 +00001465 infoPtr->bRectsValid = FALSE;
1466 InvalidateRect(hwnd, NULL, FALSE);
1467 /* FIXME: Should some WM_NOTIFY be sent */
Vincent Béron9a624912002-05-31 23:06:46 +00001468 }
Uwe Bonnes018c6542000-10-19 22:26:17 +00001469
Alexandre Julliarda099a551999-06-12 15:45:58 +00001470 TRACE("Released item %d!\n", infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001471 infoPtr->bPressed = FALSE;
1472 }
1473 else if (infoPtr->bTracking) {
Alexandre Julliarda099a551999-06-12 15:45:58 +00001474 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001475 infoPtr->bTracking = FALSE;
1476
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001477 HEADER_SendHeaderNotifyT (hwnd, HDN_ENDTRACKW, infoPtr->iMoveItem,HDI_WIDTH);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001478
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001479 if (!(dwStyle & HDS_FULLDRAG)) {
Eric Kohlcad17ff1999-03-12 17:42:50 +00001480 hdc = GetDC (hwnd);
1481 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
Aric Stewart3054b762000-06-11 20:39:14 +00001482 ReleaseDC (hwnd, hdc);
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001483 }
1484
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001485 if (HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH))
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001486 {
1487 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1488 }
1489 else {
1490 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1491 if (nWidth < 0)
1492 nWidth = 0;
1493 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1494 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001495
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001496 HEADER_SetItemBounds (hwnd);
1497 InvalidateRect(hwnd, NULL, TRUE);
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001498 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001499 }
1500
1501 if (infoPtr->bCaptured) {
1502 infoPtr->bCaptured = FALSE;
1503 ReleaseCapture ();
Eric Kohlcad17ff1999-03-12 17:42:50 +00001504 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001505 }
1506
1507 return 0;
1508}
1509
1510
1511static LRESULT
Eric Kohl40f29ee2000-11-25 03:07:01 +00001512HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1513{
1514 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1515
1516 switch (lParam)
1517 {
1518 case NF_QUERY:
1519 return infoPtr->nNotifyFormat;
1520
1521 case NF_REQUERY:
1522 infoPtr->nNotifyFormat =
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001523 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
Eric Kohl40f29ee2000-11-25 03:07:01 +00001524 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1525 return infoPtr->nNotifyFormat;
1526 }
1527
1528 return 0;
1529}
1530
1531
1532static LRESULT
Frank Richter07f86902005-08-03 11:45:19 +00001533HEADER_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
1534{
1535 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1536 /* Reset hot-tracked item when mouse leaves control. */
1537 INT oldHotItem = infoPtr->iHotItem;
1538 HDC hdc = GetDC (hwnd);
1539
1540 infoPtr->iHotItem = -1;
1541 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1542 ReleaseDC (hwnd, hdc);
1543
1544 return 0;
1545}
1546
1547
1548static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001549HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001550{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001551 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001552 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001553 POINT pt;
1554 UINT flags;
1555 INT nItem, nWidth;
1556 HDC hdc;
Frank Richter07f86902005-08-03 11:45:19 +00001557 /* With theming, hottracking is always enabled */
1558 BOOL hotTrackEnabled =
1559 ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK))
1560 || (GetWindowTheme (hwnd) != NULL);
1561 INT oldHotItem = infoPtr->iHotItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001562
Alexandre Julliard9d615962003-09-17 04:28:28 +00001563 pt.x = (INT)(SHORT)LOWORD(lParam);
1564 pt.y = (INT)(SHORT)HIWORD(lParam);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001565 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001566
Frank Richter07f86902005-08-03 11:45:19 +00001567 if (hotTrackEnabled) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001568 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001569 infoPtr->iHotItem = nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001570 else
1571 infoPtr->iHotItem = -1;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001572 }
1573
1574 if (infoPtr->bCaptured) {
1575 if (infoPtr->bPressed) {
Frank Richter07f86902005-08-03 11:45:19 +00001576 BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001577 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001578 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1579 else
1580 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
Frank Richter07f86902005-08-03 11:45:19 +00001581 if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
1582 hdc = GetDC (hwnd);
1583 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1584 ReleaseDC (hwnd, hdc);
1585 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001586
Alexandre Julliarda099a551999-06-12 15:45:58 +00001587 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001588 }
1589 else if (infoPtr->bTracking) {
Eric Kohlcad17ff1999-03-12 17:42:50 +00001590 if (dwStyle & HDS_FULLDRAG) {
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001591 if (!HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH))
Ulrich Czekallaf235a7b2000-11-25 01:25:46 +00001592 {
Aric Stewart3054b762000-06-11 20:39:14 +00001593 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1594 if (nWidth < 0)
1595 nWidth = 0;
1596 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001597 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH);
Ulrich Czekallaf235a7b2000-11-25 01:25:46 +00001598 }
Eric Kohlcad17ff1999-03-12 17:42:50 +00001599 HEADER_SetItemBounds (hwnd);
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001600 InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001601 }
1602 else {
Eric Kohlcad17ff1999-03-12 17:42:50 +00001603 hdc = GetDC (hwnd);
1604 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001605 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1606 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1607 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
Vincent Béron9a624912002-05-31 23:06:46 +00001608 infoPtr->items[infoPtr->iMoveItem].cxy =
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001609 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
Eric Kohlcad17ff1999-03-12 17:42:50 +00001610 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1611 ReleaseDC (hwnd, hdc);
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001612 HEADER_SendHeaderNotifyT (hwnd, HDN_TRACKW, infoPtr->iMoveItem, HDI_WIDTH);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001613 }
1614
Alexandre Julliarda099a551999-06-12 15:45:58 +00001615 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001616 }
1617 }
1618
Frank Richter07f86902005-08-03 11:45:19 +00001619 if (hotTrackEnabled) {
1620 TRACKMOUSEEVENT tme;
1621 if (oldHotItem != infoPtr->iHotItem) {
1622 hdc = GetDC (hwnd);
1623 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1624 if (infoPtr->iHotItem != -1) HEADER_RefreshItem (hwnd, hdc, infoPtr->iHotItem);
1625 ReleaseDC (hwnd, hdc);
1626 }
1627 tme.cbSize = sizeof( tme );
1628 tme.dwFlags = TME_LEAVE;
1629 tme.hwndTrack = hwnd;
1630 TrackMouseEvent( &tme );
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001631 }
1632
1633 return 0;
1634}
1635
1636
1637static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001638HEADER_Paint (HWND hwnd, WPARAM wParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001639{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001640 HDC hdc;
1641 PAINTSTRUCT ps;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001642
Eric Kohlcad17ff1999-03-12 17:42:50 +00001643 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1644 HEADER_Refresh (hwnd, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001645 if(!wParam)
Eric Kohlcad17ff1999-03-12 17:42:50 +00001646 EndPaint (hwnd, &ps);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001647 return 0;
1648}
1649
1650
1651static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001652HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001653{
Pascal Lessardce527de2000-02-29 22:04:00 +00001654 BOOL bRet;
1655 POINT pt;
1656
1657 pt.x = LOWORD(lParam);
1658 pt.y = HIWORD(lParam);
1659
1660 /* Send a Notify message */
1661 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1662
1663 /* Change to screen coordinate for WM_CONTEXTMENU */
1664 ClientToScreen(hwnd, &pt);
1665
1666 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001667 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
Vincent Béron9a624912002-05-31 23:06:46 +00001668
Pascal Lessardce527de2000-02-29 22:04:00 +00001669 return bRet;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001670}
1671
1672
1673static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001674HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001675{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001676 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001677 POINT pt;
1678 UINT flags;
1679 INT nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001680
Alexandre Julliarda099a551999-06-12 15:45:58 +00001681 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001682
Alexandre Julliarda3960291999-02-26 11:11:13 +00001683 GetCursorPos (&pt);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001684 ScreenToClient (hwnd, &pt);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001685
Eric Kohlcad17ff1999-03-12 17:42:50 +00001686 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001687
1688 if (flags == HHT_ONDIVIDER)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001689 SetCursor (infoPtr->hcurDivider);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001690 else if (flags == HHT_ONDIVOPEN)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001691 SetCursor (infoPtr->hcurDivopen);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001692 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001693 SetCursor (infoPtr->hcurArrow);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001694
1695 return 0;
1696}
1697
1698
1699static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001700HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001701{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001702 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001703 TEXTMETRICW tm;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001704 HFONT hFont, hOldFont;
1705 HDC hdc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001706
Alexandre Julliarda3960291999-02-26 11:11:13 +00001707 infoPtr->hFont = (HFONT)wParam;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001708
Alexandre Julliarda3960291999-02-26 11:11:13 +00001709 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001710
Alexandre Julliarda3960291999-02-26 11:11:13 +00001711 hdc = GetDC (0);
1712 hOldFont = SelectObject (hdc, hFont);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001713 GetTextMetricsW (hdc, &tm);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001714 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001715 SelectObject (hdc, hOldFont);
1716 ReleaseDC (0, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001717
Martin Fuchs33bdf532000-04-28 14:46:36 +00001718 infoPtr->bRectsValid = FALSE;
Vincent Béron9a624912002-05-31 23:06:46 +00001719
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001720 if (lParam) {
Chris Morgan3cbc1682000-06-04 01:34:31 +00001721 InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001722 }
1723
1724 return 0;
1725}
1726
Frank Richter564872c2005-07-25 11:09:09 +00001727/* Update the theme handle after a theme change */
1728static LRESULT HEADER_ThemeChanged(HWND hwnd)
1729{
1730 HTHEME theme = GetWindowTheme(hwnd);
1731 CloseThemeData(theme);
1732 OpenThemeData(hwnd, themeClass);
1733 InvalidateRect(hwnd, NULL, FALSE);
1734 return 0;
1735}
1736
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001737
Patrik Stridvall26ffb3c1999-07-31 14:41:43 +00001738static LRESULT WINAPI
Alexandre Julliarda3960291999-02-26 11:11:13 +00001739HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001740{
Michael Stefaniuc353529b2002-10-23 22:19:10 +00001741 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
Gerard Patela1b2fc22000-05-10 01:34:53 +00001742 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001743 return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001744 switch (msg) {
Eric Kohl40f29ee2000-11-25 03:07:01 +00001745/* case HDM_CLEARFILTER: */
1746
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001747 case HDM_CREATEDRAGIMAGE:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001748 return HEADER_CreateDragImage (hwnd, wParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001749
1750 case HDM_DELETEITEM:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001751 return HEADER_DeleteItem (hwnd, wParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001752
Eric Kohl40f29ee2000-11-25 03:07:01 +00001753/* case HDM_EDITFILTER: */
1754
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +00001755 case HDM_GETBITMAPMARGIN:
1756 return HEADER_GetBitmapMargin(hwnd);
Eric Kohl40f29ee2000-11-25 03:07:01 +00001757
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001758 case HDM_GETIMAGELIST:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001759 return HEADER_GetImageList (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001760
Alexandre Julliarda3960291999-02-26 11:11:13 +00001761 case HDM_GETITEMA:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001762 case HDM_GETITEMW:
Vitaliy Margolenc2584302005-10-29 11:08:20 +00001763 return HEADER_GetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001764
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001765 case HDM_GETITEMCOUNT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001766 return HEADER_GetItemCount (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001767
1768 case HDM_GETITEMRECT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001769 return HEADER_GetItemRect (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001770
Vincent Béron9a624912002-05-31 23:06:46 +00001771 case HDM_GETORDERARRAY:
Uwe Bonnes018c6542000-10-19 22:26:17 +00001772 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1773
Eric Kohl8d2933d1998-11-22 18:12:12 +00001774 case HDM_GETUNICODEFORMAT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001775 return HEADER_GetUnicodeFormat (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001776
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001777 case HDM_HITTEST:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001778 return HEADER_HitTest (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001779
Alexandre Julliarda3960291999-02-26 11:11:13 +00001780 case HDM_INSERTITEMA:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001781 case HDM_INSERTITEMW:
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001782 return HEADER_InsertItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001783
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001784 case HDM_LAYOUT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001785 return HEADER_Layout (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001786
Eric Kohl40f29ee2000-11-25 03:07:01 +00001787 case HDM_ORDERTOINDEX:
1788 return HEADER_OrderToIndex(hwnd, wParam);
1789
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +00001790 case HDM_SETBITMAPMARGIN:
1791 return HEADER_SetBitmapMargin(hwnd, wParam);
Eric Kohl40f29ee2000-11-25 03:07:01 +00001792
1793/* case HDM_SETFILTERCHANGETIMEOUT: */
1794
1795/* case HDM_SETHOTDIVIDER: */
1796
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001797 case HDM_SETIMAGELIST:
Eric Kohl4718b6d2000-12-13 01:52:23 +00001798 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001799
Alexandre Julliarda3960291999-02-26 11:11:13 +00001800 case HDM_SETITEMA:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001801 case HDM_SETITEMW:
Vitaliy Margolen05905cc2005-10-27 10:19:29 +00001802 return HEADER_SetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001803
Eric Kohl40f29ee2000-11-25 03:07:01 +00001804 case HDM_SETORDERARRAY:
1805 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1806
Eric Kohl8d2933d1998-11-22 18:12:12 +00001807 case HDM_SETUNICODEFORMAT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001808 return HEADER_SetUnicodeFormat (hwnd, wParam);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001809
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001810 case WM_CREATE:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001811 return HEADER_Create (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001812
1813 case WM_DESTROY:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001814 return HEADER_Destroy (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001815
1816 case WM_ERASEBKGND:
1817 return 1;
1818
1819 case WM_GETDLGCODE:
1820 return DLGC_WANTTAB | DLGC_WANTARROWS;
1821
1822 case WM_GETFONT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001823 return HEADER_GetFont (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001824
1825 case WM_LBUTTONDBLCLK:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001826 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001827
1828 case WM_LBUTTONDOWN:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001829 return HEADER_LButtonDown (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001830
1831 case WM_LBUTTONUP:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001832 return HEADER_LButtonUp (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001833
Frank Richter07f86902005-08-03 11:45:19 +00001834 case WM_MOUSELEAVE:
1835 return HEADER_MouseLeave (hwnd, wParam, lParam);
1836
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001837 case WM_MOUSEMOVE:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001838 return HEADER_MouseMove (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001839
Eric Kohl40f29ee2000-11-25 03:07:01 +00001840 case WM_NOTIFYFORMAT:
1841 return HEADER_NotifyFormat (hwnd, wParam, lParam);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001842
Martin Fuchs33bdf532000-04-28 14:46:36 +00001843 case WM_SIZE:
1844 return HEADER_Size (hwnd, wParam);
Vincent Béron9a624912002-05-31 23:06:46 +00001845
Frank Richter564872c2005-07-25 11:09:09 +00001846 case WM_THEMECHANGED:
1847 return HEADER_ThemeChanged (hwnd);
1848
Michael Kaufmanne9310da2005-11-08 12:52:35 +00001849 case WM_PRINTCLIENT:
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001850 case WM_PAINT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001851 return HEADER_Paint (hwnd, wParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001852
1853 case WM_RBUTTONUP:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001854 return HEADER_RButtonUp (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001855
1856 case WM_SETCURSOR:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001857 return HEADER_SetCursor (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001858
1859 case WM_SETFONT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001860 return HEADER_SetFont (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001861
1862 default:
Bill Medland69f18272002-07-16 01:14:46 +00001863 if ((msg >= WM_USER) && (msg < WM_APP))
Alexandre Julliarda099a551999-06-12 15:45:58 +00001864 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001865 msg, wParam, lParam );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001866 return DefWindowProcA (hwnd, msg, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001867 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001868}
1869
1870
Eric Kohl9d8e8641998-10-24 10:49:27 +00001871VOID
Patrik Stridvall9e61c1c1999-06-12 08:27:49 +00001872HEADER_Register (void)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001873{
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001874 WNDCLASSW wndClass;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001875
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001876 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001877 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
Robert Shearman8d28e032004-11-06 03:49:03 +00001878 wndClass.lpfnWndProc = HEADER_WindowProc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001879 wndClass.cbClsExtra = 0;
1880 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001881 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1882 wndClass.lpszClassName = WC_HEADERW;
Vincent Béron9a624912002-05-31 23:06:46 +00001883
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001884 RegisterClassW (&wndClass);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001885}
1886
Eric Kohl9d8e8641998-10-24 10:49:27 +00001887
1888VOID
Patrik Stridvall9e61c1c1999-06-12 08:27:49 +00001889HEADER_Unregister (void)
Eric Kohl9d8e8641998-10-24 10:49:27 +00001890{
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001891 UnregisterClassW (WC_HEADERW, NULL);
Eric Kohl9d8e8641998-10-24 10:49:27 +00001892}