blob: ed235e8a495ebb8bdabc5b8b24c5f6a3312eb9f9 [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? */
Dimitrie O. Paunf8514f52002-10-21 18:22:51 +000080 BOOL bUnicode; /* Unicode flag */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000081 INT iMoveItem; /* index of tracked item. (Tracking mode) */
82 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
83 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
84 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
Dimitrie O. Paunf8514f52002-10-21 18:22:51 +000085 INT iHotItem; /* index of hot item (cursor is over this item) */
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +000086 INT iMargin; /* width of the margin that surrounds a bitmap */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000087
Francois Gouget93416cd2005-03-23 13:15:18 +000088 HIMAGELIST himl; /* handle to an image list (may be 0) */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000089 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
Phil Krylov682dd702005-08-29 12:17:42 +000090 INT *order; /* array of item IDs indexed by order */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000091 BOOL bRectsValid; /* validity flag for bounding rectangles */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000092} HEADER_INFO;
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000093
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000094
Dimitrie O. Paund6645402002-10-22 00:41:45 +000095#define VERT_BORDER 3
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000096#define DIVIDER_WIDTH 10
Mikołaj Zalewski84c31892006-04-17 17:09:56 +020097#define HDN_UNICODE_OFFSET 20
98#define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000099
Robert Shearmancdb263e2004-08-25 17:33:01 +0000100#define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000101
Frank Richter564872c2005-07-25 11:09:09 +0000102static const WCHAR themeClass[] = {'H','e','a','d','e','r',0};
103
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000104
Uwe Bonnes018c6542000-10-19 22:26:17 +0000105inline static LRESULT
106HEADER_IndexToOrder (HWND hwnd, INT iItem)
107{
108 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Bill Medland69f18272002-07-16 01:14:46 +0000109 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
Uwe Bonnes018c6542000-10-19 22:26:17 +0000110 return lpItem->iOrder;
111}
112
113
Vincent Béron9a624912002-05-31 23:06:46 +0000114static INT
Uwe Bonnes018c6542000-10-19 22:26:17 +0000115HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
116{
117 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000118 INT iorder = (INT)wParam;
Vincent Béron9a624912002-05-31 23:06:46 +0000119
Phil Krylov682dd702005-08-29 12:17:42 +0000120 if ((iorder <0) || iorder >= infoPtr->uNumItem)
Uwe Bonnes018c6542000-10-19 22:26:17 +0000121 return iorder;
Phil Krylov682dd702005-08-29 12:17:42 +0000122 return infoPtr->order[iorder];
Uwe Bonnes018c6542000-10-19 22:26:17 +0000123}
124
Martin Fuchs33bdf532000-04-28 14:46:36 +0000125static void
126HEADER_SetItemBounds (HWND hwnd)
127{
128 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
129 HEADER_ITEM *phdi;
130 RECT rect;
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000131 unsigned int i;
132 int x;
Martin Fuchs33bdf532000-04-28 14:46:36 +0000133
134 infoPtr->bRectsValid = TRUE;
135
136 if (infoPtr->uNumItem == 0)
137 return;
138
139 GetClientRect (hwnd, &rect);
140
141 x = rect.left;
142 for (i = 0; i < infoPtr->uNumItem; i++) {
Uwe Bonnes018c6542000-10-19 22:26:17 +0000143 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
Martin Fuchs33bdf532000-04-28 14:46:36 +0000144 phdi->rect.top = rect.top;
145 phdi->rect.bottom = rect.bottom;
146 phdi->rect.left = x;
Mike McCormack7c1db502001-09-17 20:25:52 +0000147 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
Martin Fuchs33bdf532000-04-28 14:46:36 +0000148 x = phdi->rect.right;
149 }
150}
151
152static LRESULT
153HEADER_Size (HWND hwnd, WPARAM wParam)
154{
155 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
156
157 infoPtr->bRectsValid = FALSE;
158
159 return 0;
160}
161
162
Alexandre Julliarda3960291999-02-26 11:11:13 +0000163static INT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000164HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000165{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000166 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000167 HEADER_ITEM *phdi = &infoPtr->items[iItem];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000168 RECT r;
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000169 INT oldBkMode, cxEdge = GetSystemMetrics(SM_CXEDGE);
Frank Richter564872c2005-07-25 11:09:09 +0000170 HTHEME theme = GetWindowTheme (hwnd);
Phil Krylov1b9fc2a2006-01-10 19:58:24 +0100171 NMCUSTOMDRAW nmcd;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000172
Duane Clarkf7301572002-03-11 01:08:29 +0000173 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode);
Eric Kohl4718b6d2000-12-13 01:52:23 +0000174
Martin Fuchs33bdf532000-04-28 14:46:36 +0000175 if (!infoPtr->bRectsValid)
176 HEADER_SetItemBounds(hwnd);
Vincent Béron9a624912002-05-31 23:06:46 +0000177
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000178 r = phdi->rect;
179 if (r.right - r.left == 0)
180 return phdi->rect.right;
181
Frank Richter564872c2005-07-25 11:09:09 +0000182 if (theme != NULL) {
183 int state = (phdi->bDown) ? HIS_PRESSED :
184 (bHotTrack ? HIS_HOT : HIS_NORMAL);
185 DrawThemeBackground (theme, hdc, HP_HEADERITEM, state,
186 &r, NULL);
187 GetThemeBackgroundContentRect (theme, hdc, HP_HEADERITEM, state,
188 &r, &r);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000189 }
Frank Richter564872c2005-07-25 11:09:09 +0000190 else {
191 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) {
192 if (phdi->bDown) {
193 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
194 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
195 }
196 else
197 DrawEdge (hdc, &r, EDGE_RAISED,
198 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
199 }
200 else
201 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
202 }
203 if (phdi->bDown) {
204 r.left += 2;
205 r.top += 2;
206 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000207
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000208 r.left -= cxEdge;
209 r.right += cxEdge;
210
Phil Krylov1b9fc2a2006-01-10 19:58:24 +0100211 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
212 SetTextColor (hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
213 SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
214
215 nmcd.hdr.hwndFrom = hwnd;
216 nmcd.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
217 nmcd.hdr.code = NM_CUSTOMDRAW;
218 nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM | CDDS_ITEMPOSTERASE;
219 nmcd.hdc = hdc;
220 nmcd.dwItemSpec = iItem;
221 nmcd.rc = r;
222 nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0;
223 nmcd.lItemlParam = phdi->lParam;
224
225 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd);
226
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000227 if (phdi->fmt & HDF_OWNERDRAW) {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000228 DRAWITEMSTRUCT dis;
Vitaliy Margolen4f403ed2005-06-30 18:11:19 +0000229
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000230 dis.CtlType = ODT_HEADER;
Robert Shearmancdb263e2004-08-25 17:33:01 +0000231 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000232 dis.itemID = iItem;
233 dis.itemAction = ODA_DRAWENTIRE;
234 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
Eric Kohlcad17ff1999-03-12 17:42:50 +0000235 dis.hwndItem = hwnd;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000236 dis.hDC = hdc;
237 dis.rcItem = r;
238 dis.itemData = phdi->lParam;
Gerard Patel66226d82001-04-04 00:09:05 +0000239 oldBkMode = SetBkMode(hdc, TRANSPARENT);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +0000240 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM,
Eric Kohlcad17ff1999-03-12 17:42:50 +0000241 (WPARAM)dis.CtlID, (LPARAM)&dis);
Gerard Patel66226d82001-04-04 00:09:05 +0000242 if (oldBkMode != TRANSPARENT)
243 SetBkMode(hdc, oldBkMode);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000244 }
245 else {
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000246 UINT rw, rh, /* width and height of r */
247 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
248 /* cnt,txt,img,bmp */
249 UINT cx, tx, ix, bx,
250 cw, tw, iw, bw;
251 BITMAP bmp;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000252
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000253 cw = tw = iw = bw = 0;
254 rw = r.right - r.left;
255 rh = r.bottom - r.top;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000256
Phil Krylov1b9fc2a2006-01-10 19:58:24 +0100257 if (theme == NULL) {
258 HBRUSH hbr = CreateSolidBrush(GetBkColor(hdc));
259 RECT rcBackground = r;
260
261 rcBackground.right -= cxEdge;
262 FillRect(hdc, &rcBackground, hbr);
263 DeleteObject(hbr);
264 }
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000265 if (phdi->fmt & HDF_STRING) {
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +0000266 RECT textRect;
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +0000267
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000268 DrawTextW (hdc, phdi->pszText, -1,
269 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
270 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
271 }
Maxime Bellengéf28afa12005-02-23 12:41:43 +0000272
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000273 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
274 iw = infoPtr->himl->cx + 2 * infoPtr->iMargin;
275 x = &ix;
276 w = &iw;
277 }
278
279 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
280 GetObjectW (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
281 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
282 if (!iw) {
283 x = &bx;
284 w = &bw;
Maxime Bellengéf28afa12005-02-23 12:41:43 +0000285 }
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000286 }
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +0000287
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000288 if (bw || iw)
289 cw += *w;
290
291 /* align cx using the unclipped cw */
292 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
293 cx = r.left;
294 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
295 cx = r.left + rw / 2 - cw / 2;
296 else /* HDF_RIGHT */
297 cx = r.right - cw;
298
299 /* clip cx & cw */
300 if (cx < r.left)
301 cx = r.left;
302 if (cx + cw > r.right)
303 cw = r.right - cx;
304
305 tx = cx + infoPtr->iMargin;
306 /* since cw might have changed we have to recalculate tw */
307 tw = cw - infoPtr->iMargin * 2;
308
309 if (iw || bw) {
310 tw -= *w;
311 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
312 /* put pic behind text */
313 *x = cx + tw + infoPtr->iMargin * 3;
314 } else {
315 *x = cx + infoPtr->iMargin;
316 /* move text behind pic */
317 tx += *w;
318 }
319 }
320
321 if (iw && bw) {
322 /* since we're done with the layout we can
323 now calculate the position of bmp which
324 has no influence on alignment and layout
325 because of img */
326 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
327 bx = cx - bw + infoPtr->iMargin;
328 else
329 bx = cx + cw + infoPtr->iMargin;
330 }
331
332 if (iw || bw) {
333 HDC hClipDC = GetDC(hwnd);
334 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
335 SelectClipRgn(hClipDC, hClipRgn);
336
337 if (bw) {
338 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
339 SelectObject (hdcBitmap, phdi->hbm);
340 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
341 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
342 DeleteDC (hdcBitmap);
343 }
344
345 if (iw) {
346 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
347 ix, r.top + ((INT)rh - infoPtr->himl->cy) / 2,
348 infoPtr->himl->cx, infoPtr->himl->cy, CLR_DEFAULT, CLR_DEFAULT, 0);
349 }
350
351 DeleteObject(hClipRgn);
Filip Navara52cf1852005-07-26 18:25:46 +0000352 ReleaseDC(hwnd, hClipDC);
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000353 }
354
355 if (((phdi->fmt & HDF_STRING)
Martin Fuchs33bdf532000-04-28 14:46:36 +0000356 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
357 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
358 && (phdi->pszText)) {
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000359 oldBkMode = SetBkMode(hdc, TRANSPARENT);
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000360 r.left = tx;
361 r.right = tx + tw;
Martin Fuchsfe7d46a2002-10-18 00:20:04 +0000362 DrawTextW (hdc, phdi->pszText, -1,
Felix Nawothnige9e6f132005-05-14 11:03:17 +0000363 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
Martin Fuchsfe7d46a2002-10-18 00:20:04 +0000364 if (oldBkMode != TRANSPARENT)
365 SetBkMode(hdc, oldBkMode);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000366 }
Uwe Bonnes018c6542000-10-19 22:26:17 +0000367 }/*Ownerdrawn*/
Eric Kohlcad17ff1999-03-12 17:42:50 +0000368
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000369 return phdi->rect.right;
370}
371
372
Vincent Béron9a624912002-05-31 23:06:46 +0000373static void
Eric Kohlcad17ff1999-03-12 17:42:50 +0000374HEADER_Refresh (HWND hwnd, HDC hdc)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000375{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000376 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000377 HFONT hFont, hOldFont;
378 RECT rect;
379 HBRUSH hbrBk;
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000380 UINT i;
381 INT x;
Frank Richter564872c2005-07-25 11:09:09 +0000382 HTHEME theme = GetWindowTheme (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000383
384 /* get rect for the bar, adjusted for the border */
Eric Kohlcad17ff1999-03-12 17:42:50 +0000385 GetClientRect (hwnd, &rect);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000386
Alexandre Julliarda3960291999-02-26 11:11:13 +0000387 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
388 hOldFont = SelectObject (hdc, hFont);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000389
390 /* draw Background */
Frank Richter564872c2005-07-25 11:09:09 +0000391 if (theme == NULL) {
392 hbrBk = GetSysColorBrush(COLOR_3DFACE);
393 FillRect(hdc, &rect, hbrBk);
394 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000395
396 x = rect.left;
Phil Krylov030dbe2d2005-08-25 19:18:14 +0000397 for (i = 0; x <= rect.right && i < infoPtr->uNumItem; i++) {
Frank Richter564872c2005-07-25 11:09:09 +0000398 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i),
399 infoPtr->iHotItem == i);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000400 }
401
402 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
403 rect.left = x;
Frank Richter564872c2005-07-25 11:09:09 +0000404 if (theme != NULL) {
405 DrawThemeBackground (theme, hdc, HP_HEADERITEM, HIS_NORMAL, &rect,
406 NULL);
407 }
408 else {
409 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS)
410 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
411 else
412 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
413 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000414 }
415
Alexandre Julliarda3960291999-02-26 11:11:13 +0000416 SelectObject (hdc, hOldFont);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000417}
418
419
420static void
Eric Kohlcad17ff1999-03-12 17:42:50 +0000421HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000422{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000423 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000424 HFONT hFont, hOldFont;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000425
Alexandre Julliarda3960291999-02-26 11:11:13 +0000426 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
427 hOldFont = SelectObject (hdc, hFont);
Frank Richter07f86902005-08-03 11:45:19 +0000428 HEADER_DrawItem (hwnd, hdc, iItem, infoPtr->iHotItem == iItem);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000429 SelectObject (hdc, hOldFont);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000430}
431
432
433static void
Eric Kohlcad17ff1999-03-12 17:42:50 +0000434HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000435{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000436 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000437 RECT rect, rcTest;
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000438 UINT iCount;
439 INT width;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000440 BOOL bNoWidth;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000441
Eric Kohlcad17ff1999-03-12 17:42:50 +0000442 GetClientRect (hwnd, &rect);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000443
444 *pFlags = 0;
445 bNoWidth = FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000446 if (PtInRect (&rect, *lpPt))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000447 {
448 if (infoPtr->uNumItem == 0) {
449 *pFlags |= HHT_NOWHERE;
450 *pItem = 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000451 TRACE("NOWHERE\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000452 return;
453 }
454 else {
455 /* somewhere inside */
456 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
457 rect = infoPtr->items[iCount].rect;
458 width = rect.right - rect.left;
459 if (width == 0) {
460 bNoWidth = TRUE;
461 continue;
462 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000463 if (PtInRect (&rect, *lpPt)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000464 if (width <= 2 * DIVIDER_WIDTH) {
465 *pFlags |= HHT_ONHEADER;
466 *pItem = iCount;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000467 TRACE("ON HEADER %d\n", iCount);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000468 return;
469 }
470 if (iCount > 0) {
471 rcTest = rect;
472 rcTest.right = rcTest.left + DIVIDER_WIDTH;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000473 if (PtInRect (&rcTest, *lpPt)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000474 if (bNoWidth) {
475 *pFlags |= HHT_ONDIVOPEN;
476 *pItem = iCount - 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000477 TRACE("ON DIVOPEN %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000478 return;
479 }
480 else {
481 *pFlags |= HHT_ONDIVIDER;
482 *pItem = iCount - 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000483 TRACE("ON DIVIDER %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000484 return;
485 }
486 }
487 }
488 rcTest = rect;
489 rcTest.left = rcTest.right - DIVIDER_WIDTH;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000490 if (PtInRect (&rcTest, *lpPt)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000491 *pFlags |= HHT_ONDIVIDER;
492 *pItem = iCount;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000493 TRACE("ON DIVIDER %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000494 return;
495 }
496
497 *pFlags |= HHT_ONHEADER;
498 *pItem = iCount;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000499 TRACE("ON HEADER %d\n", iCount);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000500 return;
501 }
502 }
503
504 /* check for last divider part (on nowhere) */
505 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
506 rect.left = rect.right;
507 rect.right += DIVIDER_WIDTH;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000508 if (PtInRect (&rect, *lpPt)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000509 if (bNoWidth) {
510 *pFlags |= HHT_ONDIVOPEN;
511 *pItem = infoPtr->uNumItem - 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000512 TRACE("ON DIVOPEN %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000513 return;
514 }
515 else {
516 *pFlags |= HHT_ONDIVIDER;
517 *pItem = infoPtr->uNumItem-1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000518 TRACE("ON DIVIDER %d\n", *pItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000519 return;
520 }
521 }
522
523 *pFlags |= HHT_NOWHERE;
524 *pItem = 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000525 TRACE("NOWHERE\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000526 return;
527 }
528 }
529 else {
530 if (lpPt->x < rect.left) {
Alexandre Julliarda099a551999-06-12 15:45:58 +0000531 TRACE("TO LEFT\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000532 *pFlags |= HHT_TOLEFT;
533 }
534 else if (lpPt->x > rect.right) {
Thuy Nguyen30eaa591999-10-13 13:47:36 +0000535 TRACE("TO RIGHT\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000536 *pFlags |= HHT_TORIGHT;
537 }
538
539 if (lpPt->y < rect.top) {
Alexandre Julliarda099a551999-06-12 15:45:58 +0000540 TRACE("ABOVE\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000541 *pFlags |= HHT_ABOVE;
542 }
543 else if (lpPt->y > rect.bottom) {
Alexandre Julliarda099a551999-06-12 15:45:58 +0000544 TRACE("BELOW\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000545 *pFlags |= HHT_BELOW;
546 }
547 }
548
549 *pItem = 1;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000550 TRACE("flags=0x%X\n", *pFlags);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000551 return;
552}
553
554
555static void
Eric Kohlcad17ff1999-03-12 17:42:50 +0000556HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000557{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000558 RECT rect;
559 HPEN hOldPen;
560 INT oldRop;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000561
Eric Kohlcad17ff1999-03-12 17:42:50 +0000562 GetClientRect (hwnd, &rect);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000563
Alexandre Julliarda3960291999-02-26 11:11:13 +0000564 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
565 oldRop = SetROP2 (hdc, R2_XORPEN);
566 MoveToEx (hdc, x, rect.top, NULL);
567 LineTo (hdc, x, rect.bottom);
568 SetROP2 (hdc, oldRop);
569 SelectObject (hdc, hOldPen);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000570}
571
Mikołaj Zalewski84c31892006-04-17 17:09:56 +0200572static UINT HEADER_NotifyCodeWtoA(UINT code)
573{
574 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
575 if (code >= HDN_LAST && code <= HDN_FIRST_UNICODE)
576 return code + HDN_UNICODE_OFFSET;
577 else
578 return code;
579}
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000580
Alexandre Julliarda3960291999-02-26 11:11:13 +0000581static BOOL
Eric Kohlcad17ff1999-03-12 17:42:50 +0000582HEADER_SendSimpleNotify (HWND hwnd, UINT code)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000583{
Uwe Bonnes018c6542000-10-19 22:26:17 +0000584 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000585 NMHDR nmhdr;
586
Eric Kohlcad17ff1999-03-12 17:42:50 +0000587 nmhdr.hwndFrom = hwnd;
Robert Shearmancdb263e2004-08-25 17:33:01 +0000588 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000589 nmhdr.code = code;
590
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +0000591 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000592 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000593}
594
Aric Stewart3054b762000-06-11 20:39:14 +0000595static BOOL
Mikołaj Zalewski84c31892006-04-17 17:09:56 +0200596HEADER_SendHeaderNotifyT (HWND hwnd, UINT code, INT iItem, INT mask)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000597{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000598 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000599 NMHEADERA nmhdr;
600 HDITEMA nmitem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000601
Eric Kohlcad17ff1999-03-12 17:42:50 +0000602 nmhdr.hdr.hwndFrom = hwnd;
Robert Shearmancdb263e2004-08-25 17:33:01 +0000603 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Mikołaj Zalewski84c31892006-04-17 17:09:56 +0200604 nmhdr.hdr.code = (infoPtr->nNotifyFormat == NFR_UNICODE ? code : HEADER_NotifyCodeWtoA(code));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000605 nmhdr.iItem = iItem;
606 nmhdr.iButton = 0;
607 nmhdr.pitem = &nmitem;
Ulrich Czekallaf235a7b2000-11-25 01:25:46 +0000608 nmitem.mask = mask;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000609 nmitem.cxy = infoPtr->items[iItem].cxy;
610 nmitem.hbm = infoPtr->items[iItem].hbm;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000611 nmitem.pszText = NULL;
612 nmitem.cchTextMax = 0;
Marcus Meissner73458b01998-12-26 12:54:29 +0000613/* nmitem.pszText = infoPtr->items[iItem].pszText; */
614/* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000615 nmitem.fmt = infoPtr->items[iItem].fmt;
616 nmitem.lParam = infoPtr->items[iItem].lParam;
617 nmitem.iOrder = infoPtr->items[iItem].iOrder;
618 nmitem.iImage = infoPtr->items[iItem].iImage;
619
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +0000620 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
Raphael Junqueirae3d53b42005-11-15 16:54:41 +0000621 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
622}
623
624/**
625 * Send Disp Info notification.
626 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
627 * (so we handle the two cases only doing a specific cast for pszText).
628 *
629 * @param hwnd : hwnd header container handler
630 * @param mask : notification mask (usually HDI_TEXT or HDI_IMAGE)
631 * @param pDispInfo : NMHDDISPINFO structure (can be unicode or ansi)
632 * @param isW : TRUE if dispinfo is Unicode
633 */
634static BOOL
635HEADER_SendHeaderDispInfoNotify(HWND hwnd, INT iItem, INT mask, LPHDITEMW phdi, HEADER_ITEM* lpItem, BOOL isW)
636{
637 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
638 BOOL ret;
639 BOOL convertToAnsi = FALSE;
640 BOOL convertToUnicode = FALSE;
641 BOOL isUnicodeNotify = FALSE;
642 NMHDDISPINFOW dispInfo;
643
644 if (mask & HDI_TEXT)
645 {
646 convertToAnsi = (isW && infoPtr->nNotifyFormat == NFR_ANSI);
647 convertToUnicode = (!isW && infoPtr->nNotifyFormat == NFR_UNICODE);
648 }
649 isUnicodeNotify = (isW && !convertToAnsi);
650
651 memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
652 dispInfo.hdr.hwndFrom = hwnd;
653 dispInfo.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
654 if (isUnicodeNotify || convertToUnicode)
655 {
656 dispInfo.hdr.code = HDN_GETDISPINFOW;
657 }
658 else
659 {
660 dispInfo.hdr.code = HDN_GETDISPINFOA;
661 }
662 dispInfo.iItem = iItem;
663 dispInfo.mask = mask;
664 /*
665 dispInfo.pszText = Alloc(sizeof(WCHAR) * 260);
666 dispInfo.cchTextMax = 260;
667 */
668 ret = (BOOL) SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
669 (WPARAM) dispInfo.hdr.idFrom,
670 (LPARAM) &dispInfo);
671
672 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
673 dispInfo.mask,
674 (isUnicodeNotify ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
675 (void*) dispInfo.lParam);
676
677 if (dispInfo.mask & HDI_DI_SETITEM)
678 {
679 if (dispInfo.mask & HDI_IMAGE)
680 {
681 lpItem->iImage = dispInfo.iImage;
682 }
683 if (dispInfo.mask & HDI_TEXT)
684 {
685 if (isUnicodeNotify || convertToUnicode)
686 Str_SetPtrW(&lpItem->pszText, (LPCWSTR)dispInfo.pszText);
687 else /*if (convertToAnsi || !isW)*/
688 Str_SetPtrAtoW(&lpItem->pszText, (LPCSTR)dispInfo.pszText);
689 }
690
691 FIXME("NMHDDISPINFO returns with flags HDI_DI_SETITEM\n");
692 }
693
694 if (NULL != phdi)
695 {
696 if ((phdi->mask & mask) & HDI_IMAGE)
697 {
698 phdi->iImage = dispInfo.iImage;
699 }
700 if ((phdi->mask & mask) & HDI_TEXT)
701 {
702 if (isUnicodeNotify)
703 Str_GetPtrW ((LPCWSTR)dispInfo.pszText, phdi->pszText, phdi->cchTextMax);
704 else if (convertToUnicode)
705 Str_GetPtrWtoA ((LPCWSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
706 else /*if (!isW) */
707 Str_GetPtrA ((LPCSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
708 }
709 }
710 return ret;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000711}
712
713
Alexandre Julliarda3960291999-02-26 11:11:13 +0000714static BOOL
Eric Kohlcad17ff1999-03-12 17:42:50 +0000715HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000716{
Uwe Bonnes018c6542000-10-19 22:26:17 +0000717 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000718 NMHEADERA nmhdr;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000719
Eric Kohlcad17ff1999-03-12 17:42:50 +0000720 nmhdr.hdr.hwndFrom = hwnd;
Robert Shearmancdb263e2004-08-25 17:33:01 +0000721 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000722 nmhdr.hdr.code = code;
723 nmhdr.iItem = iItem;
724 nmhdr.iButton = 0;
725 nmhdr.pitem = NULL;
726
Uwe Bonnes018c6542000-10-19 22:26:17 +0000727 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
Eric Kohlcad17ff1999-03-12 17:42:50 +0000728 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000729}
730
731
732static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000733HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000734{
Alexandre Julliarda099a551999-06-12 15:45:58 +0000735 FIXME("empty stub!\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000736 return 0;
737}
738
739
740static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000741HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000742{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000743 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000744 INT iItem = (INT)wParam;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000745
Alexandre Julliarda099a551999-06-12 15:45:58 +0000746 TRACE("[iItem=%d]\n", iItem);
Vincent Béron9a624912002-05-31 23:06:46 +0000747
Alexandre Julliarda3960291999-02-26 11:11:13 +0000748 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000749 return FALSE;
750
751 if (infoPtr->uNumItem == 1) {
Alexandre Julliarda099a551999-06-12 15:45:58 +0000752 TRACE("Simple delete!\n");
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000753 if (infoPtr->items[0].pszText)
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000754 Free (infoPtr->items[0].pszText);
755 Free (infoPtr->items);
Phil Krylov682dd702005-08-29 12:17:42 +0000756 Free(infoPtr->order);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000757 infoPtr->items = 0;
Phil Krylov682dd702005-08-29 12:17:42 +0000758 infoPtr->order = 0;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000759 infoPtr->uNumItem = 0;
760 }
761 else {
762 HEADER_ITEM *oldItems = infoPtr->items;
Bill Medland69f18272002-07-16 01:14:46 +0000763 INT i;
764 INT iOrder;
Alexandre Julliarda099a551999-06-12 15:45:58 +0000765 TRACE("Complex delete! [iItem=%d]\n", iItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000766
Phil Krylov682dd702005-08-29 12:17:42 +0000767 for (i = 0; i < infoPtr->uNumItem; i++)
768 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 +0000769 if (infoPtr->items[iItem].pszText)
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000770 Free (infoPtr->items[iItem].pszText);
Bill Medland69f18272002-07-16 01:14:46 +0000771 iOrder = infoPtr->items[iItem].iOrder;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000772
773 infoPtr->uNumItem--;
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000774 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000775 /* pre delete copy */
776 if (iItem > 0) {
777 memcpy (&infoPtr->items[0], &oldItems[0],
778 iItem * sizeof(HEADER_ITEM));
779 }
780
781 /* post delete copy */
782 if (iItem < infoPtr->uNumItem) {
783 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
784 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
785 }
786
Bill Medland69f18272002-07-16 01:14:46 +0000787 /* Correct the orders */
Phil Krylov682dd702005-08-29 12:17:42 +0000788 if (iOrder < infoPtr->uNumItem)
Bill Medland69f18272002-07-16 01:14:46 +0000789 {
Phil Krylov682dd702005-08-29 12:17:42 +0000790 memmove(&infoPtr->order[iOrder], &infoPtr->order[iOrder + 1],
791 (infoPtr->uNumItem - iOrder) * sizeof(INT));
792 for (i = 0; i < infoPtr->uNumItem; i++)
793 {
794 if (infoPtr->order[i] > iItem)
795 infoPtr->order[i]--;
796 if (i >= iOrder)
797 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
798 }
Bill Medland69f18272002-07-16 01:14:46 +0000799 }
Phil Krylov682dd702005-08-29 12:17:42 +0000800
801 for (i = 0; i < infoPtr->uNumItem; i++)
802 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 +0000803 Free (oldItems);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000804 }
805
Eric Kohlcad17ff1999-03-12 17:42:50 +0000806 HEADER_SetItemBounds (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000807
Chris Morgan3cbc1682000-06-04 01:34:31 +0000808 InvalidateRect(hwnd, NULL, FALSE);
Vincent Béron9a624912002-05-31 23:06:46 +0000809
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000810 return TRUE;
811}
812
813
814static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000815HEADER_GetImageList (HWND hwnd)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000816{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000817 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000818
819 return (LRESULT)infoPtr->himl;
820}
821
822
823static LRESULT
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000824HEADER_GetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000825{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000826 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000827 HEADER_ITEM *lpItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000828
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000829 if (!phdi)
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000830 return FALSE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000831
Alexandre Julliarda099a551999-06-12 15:45:58 +0000832 TRACE("[nItem=%d]\n", nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000833
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000834 if (phdi->mask == 0)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000835 return TRUE;
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000836 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
Vitaliy Margolendef2bb62005-11-17 11:06:18 +0000837 return FALSE;
838
839 lpItem = &infoPtr->items[nItem];
Evan Deaublc8483212005-01-10 14:25:30 +0000840
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000841 if (phdi->mask & HDI_BITMAP)
Evan Deaublc8483212005-01-10 14:25:30 +0000842 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000843
844 if (phdi->mask & HDI_FORMAT)
Evan Deaublc8483212005-01-10 14:25:30 +0000845 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000846
847 if (phdi->mask & HDI_WIDTH)
Evan Deaublc8483212005-01-10 14:25:30 +0000848 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000849
850 if (phdi->mask & HDI_LPARAM)
Evan Deaublc8483212005-01-10 14:25:30 +0000851 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000852
Raphael Junqueirae3d53b42005-11-15 16:54:41 +0000853 if (phdi->mask & HDI_IMAGE)
854 {
855 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
856 if (lpItem->iImage == I_IMAGECALLBACK)
857 {
858 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, phdi, lpItem, bUnicode);
859 }
860 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000861
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000862 if (phdi->mask & HDI_ORDER)
Evan Deaublc8483212005-01-10 14:25:30 +0000863 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000864
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000865 if (phdi->mask & HDI_TEXT)
866 {
Raphael Junqueirae3d53b42005-11-15 16:54:41 +0000867 if (lpItem == NULL) *phdi->pszText = 0; /* null pointer check */
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000868 else if (lpItem->pszText == LPSTR_TEXTCALLBACKW) /* covers == TEXTCALLBACKA too */
Raphael Junqueirae3d53b42005-11-15 16:54:41 +0000869 {
870 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, phdi, lpItem, bUnicode);
871 }
Vitaliy Margolenc2584302005-10-29 11:08:20 +0000872 else
873 {
874 if (bUnicode)
875 Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
876 else
877 Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
878 }
Evan Deaublc8483212005-01-10 14:25:30 +0000879 }
Eric Kohl8d2933d1998-11-22 18:12:12 +0000880
881 return TRUE;
882}
883
884
Patrik Stridvall896889f1999-05-08 12:50:36 +0000885inline static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000886HEADER_GetItemCount (HWND hwnd)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000887{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000888 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Eric Kohl8d2933d1998-11-22 18:12:12 +0000889 return infoPtr->uNumItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000890}
891
892
893static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000894HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000895{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000896 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000897 INT iItem = (INT)wParam;
898 LPRECT lpRect = (LPRECT)lParam;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000899
Alexandre Julliarda3960291999-02-26 11:11:13 +0000900 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000901 return FALSE;
902
903 lpRect->left = infoPtr->items[iItem].rect.left;
904 lpRect->right = infoPtr->items[iItem].rect.right;
905 lpRect->top = infoPtr->items[iItem].rect.top;
906 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
907
908 return TRUE;
909}
910
911
Vincent Béron9a624912002-05-31 23:06:46 +0000912static LRESULT
Uwe Bonnes018c6542000-10-19 22:26:17 +0000913HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
914{
Uwe Bonnes018c6542000-10-19 22:26:17 +0000915 LPINT order = (LPINT) lParam;
916 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Eric Kohl8d2933d1998-11-22 18:12:12 +0000917
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000918 if ((unsigned int)wParam <infoPtr->uNumItem)
Uwe Bonnes018c6542000-10-19 22:26:17 +0000919 return FALSE;
Phil Krylov682dd702005-08-29 12:17:42 +0000920
921 memcpy(order, infoPtr->order, infoPtr->uNumItem * sizeof(INT));
Uwe Bonnes018c6542000-10-19 22:26:17 +0000922 return TRUE;
923}
924
Vincent Béron9a624912002-05-31 23:06:46 +0000925static LRESULT
Uwe Bonnes018c6542000-10-19 22:26:17 +0000926HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
927{
928 int i;
929 LPINT order = (LPINT) lParam;
930 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
931 HEADER_ITEM *lpItem;
932
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000933 if ((unsigned int)wParam <infoPtr->uNumItem)
Uwe Bonnes018c6542000-10-19 22:26:17 +0000934 return FALSE;
Phil Krylov682dd702005-08-29 12:17:42 +0000935 memcpy(infoPtr->order, order, infoPtr->uNumItem * sizeof(INT));
Uwe Bonnes018c6542000-10-19 22:26:17 +0000936 for (i=0; i<(int)wParam; i++)
937 {
Bill Medland69f18272002-07-16 01:14:46 +0000938 lpItem = &infoPtr->items[*order++];
Uwe Bonnes018c6542000-10-19 22:26:17 +0000939 lpItem->iOrder=i;
940 }
941 infoPtr->bRectsValid=0;
942 InvalidateRect(hwnd, NULL, FALSE);
943 return TRUE;
944}
Eric Kohl8d2933d1998-11-22 18:12:12 +0000945
Patrik Stridvall896889f1999-05-08 12:50:36 +0000946inline static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000947HEADER_GetUnicodeFormat (HWND hwnd)
Eric Kohl8d2933d1998-11-22 18:12:12 +0000948{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000949 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Eric Kohl8d2933d1998-11-22 18:12:12 +0000950 return infoPtr->bUnicode;
951}
952
953
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000954static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +0000955HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000956{
957 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
958
Eric Kohlcad17ff1999-03-12 17:42:50 +0000959 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000960
Vitaliy Margolen4cf764f2004-09-13 18:05:02 +0000961 if (phti->flags == HHT_NOWHERE)
Aric Stewart7d6e9a12000-05-05 18:22:44 +0000962 return -1;
Vitaliy Margolen4cf764f2004-09-13 18:05:02 +0000963 else
964 return phti->iItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000965}
966
967
968static LRESULT
Vitaliy Margolen89a49182005-10-28 10:40:27 +0000969HEADER_InsertItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000970{
Eric Kohlcad17ff1999-03-12 17:42:50 +0000971 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000972 HEADER_ITEM *lpItem;
Vitaliy Margolen89a49182005-10-28 10:40:27 +0000973 INT iOrder;
Hans Leidekker411fc5f2004-09-02 23:00:53 +0000974 UINT i;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000975
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000976 if ((phdi == NULL) || (nItem < 0))
977 return -1;
978
979 if (nItem > infoPtr->uNumItem)
980 nItem = infoPtr->uNumItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000981
Robert Shearmanf644c782003-05-22 03:34:54 +0000982 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
Ge van Geldorpc00ded52005-09-18 12:29:35 +0000983 if (iOrder < 0)
984 iOrder = 0;
985 else if (infoPtr->uNumItem < iOrder)
986 iOrder = infoPtr->uNumItem;
Robert Shearmanf644c782003-05-22 03:34:54 +0000987
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000988 if (infoPtr->uNumItem == 0) {
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000989 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
Phil Krylov682dd702005-08-29 12:17:42 +0000990 infoPtr->order = Alloc(sizeof(INT));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000991 infoPtr->uNumItem++;
992 }
993 else {
994 HEADER_ITEM *oldItems = infoPtr->items;
Phil Krylov682dd702005-08-29 12:17:42 +0000995 INT *oldOrder = infoPtr->order;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000996
997 infoPtr->uNumItem++;
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000998 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
Luc Tourangeau4d6df2c1999-03-12 17:31:08 +0000999 if (nItem == 0) {
1000 memcpy (&infoPtr->items[1], &oldItems[0],
1001 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001002 }
Luc Tourangeau4d6df2c1999-03-12 17:31:08 +00001003 else
1004 {
1005 /* pre insert copy */
1006 if (nItem > 0) {
1007 memcpy (&infoPtr->items[0], &oldItems[0],
1008 nItem * sizeof(HEADER_ITEM));
1009 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001010
Luc Tourangeau4d6df2c1999-03-12 17:31:08 +00001011 /* post insert copy */
1012 if (nItem < infoPtr->uNumItem - 1) {
1013 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
Huw D M Davies25539761999-12-04 03:59:33 +00001014 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
Luc Tourangeau4d6df2c1999-03-12 17:31:08 +00001015 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001016 }
Vincent Béron9a624912002-05-31 23:06:46 +00001017
Phil Krylov682dd702005-08-29 12:17:42 +00001018 infoPtr->order = Alloc(sizeof(INT) * infoPtr->uNumItem);
1019 memcpy(infoPtr->order, oldOrder, iOrder * sizeof(INT));
1020 infoPtr->order[iOrder] = nItem;
1021 memcpy(&infoPtr->order[iOrder + 1], &oldOrder[iOrder],
1022 (infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
1023
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001024 Free (oldItems);
Phil Krylov682dd702005-08-29 12:17:42 +00001025 Free(oldOrder);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001026 }
1027
Phil Krylov682dd702005-08-29 12:17:42 +00001028 for (i = 0; i < infoPtr->uNumItem; i++)
Robert Shearmanf644c782003-05-22 03:34:54 +00001029 {
Phil Krylov682dd702005-08-29 12:17:42 +00001030 if (i != iOrder && infoPtr->order[i] >= nItem)
1031 infoPtr->order[i]++;
1032 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
Robert Shearmanf644c782003-05-22 03:34:54 +00001033 }
1034
Bill Medland69f18272002-07-16 01:14:46 +00001035 lpItem = &infoPtr->items[nItem];
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001036 lpItem->bDown = FALSE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001037
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001038 if (phdi->mask & HDI_WIDTH)
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001039 lpItem->cxy = phdi->cxy;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001040
Eric Kohl8d2933d1998-11-22 18:12:12 +00001041 if (phdi->mask & HDI_FORMAT)
1042 lpItem->fmt = phdi->fmt;
1043
1044 if (lpItem->fmt == 0)
1045 lpItem->fmt = HDF_LEFT;
1046
1047 if (phdi->mask & HDI_BITMAP)
1048 lpItem->hbm = phdi->hbm;
1049
1050 if (phdi->mask & HDI_LPARAM)
1051 lpItem->lParam = phdi->lParam;
1052
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001053 if (phdi->mask & HDI_IMAGE)
1054 {
1055 if (phdi->iImage != I_IMAGECALLBACK)
1056 {
1057 lpItem->iImage = phdi->iImage;
1058 }
1059 else
1060 {
1061 lpItem->iImage = phdi->iImage;
1062 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1063 }
1064 }
Eric Kohl8d2933d1998-11-22 18:12:12 +00001065
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001066 if (phdi->mask & HDI_TEXT)
Robert Shearmanf644c782003-05-22 03:34:54 +00001067 {
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001068 if (!phdi->pszText) phdi->pszText = '\0'; /* null pointer check */
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001069 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001070 {
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001071 if (bUnicode)
1072 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1073 else
1074 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001075 }
1076 else
1077 {
1078 lpItem->pszText = phdi->pszText;
1079 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1080 }
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001081 lpItem->fmt |= HDF_STRING;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001082 }
1083
Robert Shearmanf644c782003-05-22 03:34:54 +00001084 lpItem->iOrder = iOrder;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001085
Eric Kohlcad17ff1999-03-12 17:42:50 +00001086 HEADER_SetItemBounds (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001087
Chris Morgan3cbc1682000-06-04 01:34:31 +00001088 InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001089
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001090 return nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001091}
1092
1093
1094static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001095HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001096{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001097 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001098 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1099
Eric Kohlcad17ff1999-03-12 17:42:50 +00001100 lpLayout->pwpos->hwnd = hwnd;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001101 lpLayout->pwpos->hwndInsertAfter = 0;
1102 lpLayout->pwpos->x = lpLayout->prc->left;
1103 lpLayout->pwpos->y = lpLayout->prc->top;
1104 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001105 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_HIDDEN)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001106 lpLayout->pwpos->cy = 0;
Martin Fuchs33bdf532000-04-28 14:46:36 +00001107 else {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001108 lpLayout->pwpos->cy = infoPtr->nHeight;
Martin Fuchs33bdf532000-04-28 14:46:36 +00001109 lpLayout->prc->top += infoPtr->nHeight;
1110 }
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00001111 lpLayout->pwpos->flags = SWP_NOZORDER;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001112
Alexandre Julliarda099a551999-06-12 15:45:58 +00001113 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001114 lpLayout->pwpos->x, lpLayout->pwpos->y,
1115 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1116
Martin Fuchs33bdf532000-04-28 14:46:36 +00001117 infoPtr->bRectsValid = FALSE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001118
1119 return TRUE;
1120}
1121
1122
1123static LRESULT
Eric Kohl4718b6d2000-12-13 01:52:23 +00001124HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001125{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001126 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001127 HIMAGELIST himlOld;
1128
Frank Richter9e570912005-08-30 10:07:17 +00001129 TRACE("(himl %p)\n", himl);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001130 himlOld = infoPtr->himl;
Eric Kohl4718b6d2000-12-13 01:52:23 +00001131 infoPtr->himl = himl;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001132
1133 /* FIXME: Refresh needed??? */
1134
1135 return (LRESULT)himlOld;
1136}
1137
1138
1139static LRESULT
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +00001140HEADER_GetBitmapMargin(HWND hwnd)
1141{
1142 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1143
1144 return infoPtr->iMargin;
1145}
1146
1147static LRESULT
1148HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1149{
1150 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1151 INT oldMargin = infoPtr->iMargin;
1152
1153 infoPtr->iMargin = (INT)wParam;
1154
1155 return oldMargin;
1156}
1157
1158static LRESULT
Vitaliy Margolen05905cc2005-10-27 10:19:29 +00001159HEADER_SetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001160{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001161 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001162 HEADER_ITEM *lpItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001163
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001164 if (phdi == NULL)
1165 return FALSE;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001166 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001167 return FALSE;
1168
Alexandre Julliarda099a551999-06-12 15:45:58 +00001169 TRACE("[nItem=%d]\n", nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001170
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001171 if (HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001172 return FALSE;
1173
Bill Medland69f18272002-07-16 01:14:46 +00001174 lpItem = &infoPtr->items[nItem];
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001175 if (phdi->mask & HDI_BITMAP)
1176 lpItem->hbm = phdi->hbm;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001177
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001178 if (phdi->mask & HDI_FORMAT)
1179 lpItem->fmt = phdi->fmt;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001180
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001181 if (phdi->mask & HDI_LPARAM)
1182 lpItem->lParam = phdi->lParam;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001183
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001184 if (phdi->mask & HDI_WIDTH)
1185 lpItem->cxy = phdi->cxy;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001186
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001187 if (phdi->mask & HDI_IMAGE)
1188 {
1189 if (phdi->iImage != I_IMAGECALLBACK)
1190 {
1191 lpItem->iImage = phdi->iImage;
1192 }
1193 else
1194 {
1195 lpItem->iImage = phdi->iImage;
1196 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1197 }
1198 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001199
Vitaliy Margolen05905cc2005-10-27 10:19:29 +00001200 if (phdi->mask & HDI_TEXT)
1201 {
1202 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
1203 {
1204 if (lpItem->pszText)
1205 {
1206 Free(lpItem->pszText);
1207 lpItem->pszText = NULL;
1208 }
1209 if (phdi->pszText)
1210 {
1211 if (bUnicode)
1212 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1213 else
1214 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
1215 }
1216 }
Raphael Junqueirae3d53b42005-11-15 16:54:41 +00001217 else
1218 {
1219 lpItem->pszText = phdi->pszText;
1220 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1221 }
Vitaliy Margolen05905cc2005-10-27 10:19:29 +00001222 }
1223
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001224 if (phdi->mask & HDI_ORDER)
Uwe Bonnes018c6542000-10-19 22:26:17 +00001225 {
Phil Krylov682dd702005-08-29 12:17:42 +00001226 INT i, nMin, nMax;
1227
1228 if (lpItem->iOrder < phdi->iOrder)
1229 {
1230 memmove(&infoPtr->order[lpItem->iOrder],
1231 &infoPtr->order[lpItem->iOrder + 1],
1232 (phdi->iOrder - lpItem->iOrder) * sizeof(INT));
1233 }
1234 if (phdi->iOrder < lpItem->iOrder)
1235 {
1236 memmove(&infoPtr->order[phdi->iOrder + 1],
1237 &infoPtr->order[phdi->iOrder],
1238 (lpItem->iOrder - phdi->iOrder) * sizeof(INT));
1239 }
1240 infoPtr->order[phdi->iOrder] = nItem;
1241 nMin = min(lpItem->iOrder, phdi->iOrder);
1242 nMax = max(lpItem->iOrder, phdi->iOrder);
1243 for (i = nMin; i <= nMax; i++)
1244 {
1245 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1246 }
Uwe Bonnes018c6542000-10-19 22:26:17 +00001247 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001248
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001249 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001250
Eric Kohlcad17ff1999-03-12 17:42:50 +00001251 HEADER_SetItemBounds (hwnd);
Chris Morgan3cbc1682000-06-04 01:34:31 +00001252
1253 InvalidateRect(hwnd, NULL, FALSE);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001254
1255 return TRUE;
1256}
1257
Patrik Stridvall896889f1999-05-08 12:50:36 +00001258inline static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001259HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
Eric Kohl8d2933d1998-11-22 18:12:12 +00001260{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001261 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001262 BOOL bTemp = infoPtr->bUnicode;
Eric Kohl8d2933d1998-11-22 18:12:12 +00001263
Alexandre Julliarda3960291999-02-26 11:11:13 +00001264 infoPtr->bUnicode = (BOOL)wParam;
Eric Kohl8d2933d1998-11-22 18:12:12 +00001265
1266 return bTemp;
1267}
1268
1269
1270static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001271HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001272{
1273 HEADER_INFO *infoPtr;
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001274 TEXTMETRICW tm;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001275 HFONT hOldFont;
1276 HDC hdc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001277
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001278 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001279 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001280
Dimitrie O. Paunc5940432003-11-20 22:04:13 +00001281 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001282 infoPtr->uNumItem = 0;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001283 infoPtr->hFont = 0;
1284 infoPtr->items = 0;
Phil Krylov682dd702005-08-29 12:17:42 +00001285 infoPtr->order = 0;
Martin Fuchs33bdf532000-04-28 14:46:36 +00001286 infoPtr->bRectsValid = FALSE;
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001287 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1288 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1289 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001290 infoPtr->bPressed = FALSE;
1291 infoPtr->bTracking = FALSE;
1292 infoPtr->iMoveItem = 0;
1293 infoPtr->himl = 0;
1294 infoPtr->iHotItem = -1;
Eric Kohlcad17ff1999-03-12 17:42:50 +00001295 infoPtr->bUnicode = IsWindowUnicode (hwnd);
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +00001296 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
Eric Kohl40f29ee2000-11-25 03:07:01 +00001297 infoPtr->nNotifyFormat =
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001298 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001299
Alexandre Julliarda3960291999-02-26 11:11:13 +00001300 hdc = GetDC (0);
1301 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001302 GetTextMetricsW (hdc, &tm);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001303 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001304 SelectObject (hdc, hOldFont);
1305 ReleaseDC (0, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001306
Frank Richterd219a542005-07-27 15:16:09 +00001307 OpenThemeData(hwnd, themeClass);
Frank Richter564872c2005-07-25 11:09:09 +00001308
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001309 return 0;
1310}
1311
1312
1313static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001314HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001315{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001316 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001317 HEADER_ITEM *lpItem;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001318 INT nItem;
Frank Richter564872c2005-07-25 11:09:09 +00001319 HTHEME theme;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001320
1321 if (infoPtr->items) {
Bill Medland69f18272002-07-16 01:14:46 +00001322 lpItem = infoPtr->items;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001323 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001324 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001325 Free (lpItem->pszText);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001326 }
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001327 Free (infoPtr->items);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001328 }
1329
Phil Krylov682dd702005-08-29 12:17:42 +00001330 if (infoPtr->order)
1331 Free(infoPtr->order);
1332
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001333 if (infoPtr->himl)
1334 ImageList_Destroy (infoPtr->himl);
1335
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001336 SetWindowLongPtrW (hwnd, 0, 0);
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001337 Free (infoPtr);
Frank Richter564872c2005-07-25 11:09:09 +00001338
1339 theme = GetWindowTheme(hwnd);
1340 CloseThemeData(theme);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001341 return 0;
1342}
1343
1344
Patrik Stridvall896889f1999-05-08 12:50:36 +00001345static inline LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001346HEADER_GetFont (HWND hwnd)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001347{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001348 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001349
1350 return (LRESULT)infoPtr->hFont;
1351}
1352
1353
1354static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001355HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001356{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001357 POINT pt;
1358 UINT flags;
1359 INT nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001360
Vincent Béron9a624912002-05-31 23:06:46 +00001361 pt.x = (INT)LOWORD(lParam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001362 pt.y = (INT)HIWORD(lParam);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001363 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001364
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001365 if ((GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001366 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMDBLCLICKW, nItem,0);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001367 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001368 HEADER_SendHeaderNotifyT (hwnd, HDN_DIVIDERDBLCLICKW, nItem,0);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001369
1370 return 0;
1371}
1372
1373
1374static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001375HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001376{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001377 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001378 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001379 POINT pt;
1380 UINT flags;
1381 INT nItem;
1382 HDC hdc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001383
Vincent Béron9a624912002-05-31 23:06:46 +00001384 pt.x = (INT)LOWORD(lParam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001385 pt.y = (INT)HIWORD(lParam);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001386 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001387
Eric Kohlcad17ff1999-03-12 17:42:50 +00001388 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1389 SetCapture (hwnd);
Vincent Béron9a624912002-05-31 23:06:46 +00001390 infoPtr->bCaptured = TRUE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001391 infoPtr->bPressed = TRUE;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001392 infoPtr->iMoveItem = nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001393
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001394 infoPtr->items[nItem].bDown = TRUE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001395
1396 /* Send WM_CUSTOMDRAW */
Eric Kohlcad17ff1999-03-12 17:42:50 +00001397 hdc = GetDC (hwnd);
1398 HEADER_RefreshItem (hwnd, hdc, nItem);
1399 ReleaseDC (hwnd, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001400
Alexandre Julliarda099a551999-06-12 15:45:58 +00001401 TRACE("Pressed item %d!\n", nItem);
Vincent Béron9a624912002-05-31 23:06:46 +00001402 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001403 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001404 if (!(HEADER_SendHeaderNotifyT (hwnd, HDN_BEGINTRACKW, nItem,0))) {
Eric Kohlcad17ff1999-03-12 17:42:50 +00001405 SetCapture (hwnd);
Vincent Béron9a624912002-05-31 23:06:46 +00001406 infoPtr->bCaptured = TRUE;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001407 infoPtr->bTracking = TRUE;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001408 infoPtr->iMoveItem = nItem;
1409 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1410 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001411
Eric Kohlcad17ff1999-03-12 17:42:50 +00001412 if (!(dwStyle & HDS_FULLDRAG)) {
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001413 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
Eric Kohlcad17ff1999-03-12 17:42:50 +00001414 hdc = GetDC (hwnd);
1415 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1416 ReleaseDC (hwnd, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001417 }
1418
Alexandre Julliarda099a551999-06-12 15:45:58 +00001419 TRACE("Begin tracking item %d!\n", nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001420 }
1421 }
1422
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001423 return 0;
1424}
1425
1426
1427static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001428HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001429{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001430 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001431 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001432 POINT pt;
1433 UINT flags;
1434 INT nItem, nWidth;
1435 HDC hdc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001436
Alexandre Julliard9d615962003-09-17 04:28:28 +00001437 pt.x = (INT)(SHORT)LOWORD(lParam);
1438 pt.y = (INT)(SHORT)HIWORD(lParam);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001439 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001440
1441 if (infoPtr->bPressed) {
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001442 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001443 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
Eric Kohlcad17ff1999-03-12 17:42:50 +00001444 hdc = GetDC (hwnd);
1445 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1446 ReleaseDC (hwnd, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001447
Eric Kohlcad17ff1999-03-12 17:42:50 +00001448 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001449 }
Uwe Bonnes018c6542000-10-19 22:26:17 +00001450 else if (flags == HHT_ONHEADER)
1451 {
1452 HEADER_ITEM *lpItem;
1453 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1454 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1455
1456 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1457 infoPtr->iMoveItem,oldindex,nItem,newindex);
Bill Medland69f18272002-07-16 01:14:46 +00001458 lpItem= &infoPtr->items[nItem];
Uwe Bonnes018c6542000-10-19 22:26:17 +00001459 lpItem->iOrder=oldindex;
1460
Bill Medland69f18272002-07-16 01:14:46 +00001461 lpItem= &infoPtr->items[infoPtr->iMoveItem];
Uwe Bonnes018c6542000-10-19 22:26:17 +00001462 lpItem->iOrder = newindex;
1463
Phil Krylov682dd702005-08-29 12:17:42 +00001464 infoPtr->order[oldindex] = nItem;
1465 infoPtr->order[newindex] = infoPtr->iMoveItem;
1466
Uwe Bonnes018c6542000-10-19 22:26:17 +00001467 infoPtr->bRectsValid = FALSE;
1468 InvalidateRect(hwnd, NULL, FALSE);
1469 /* FIXME: Should some WM_NOTIFY be sent */
Vincent Béron9a624912002-05-31 23:06:46 +00001470 }
Uwe Bonnes018c6542000-10-19 22:26:17 +00001471
Alexandre Julliarda099a551999-06-12 15:45:58 +00001472 TRACE("Released item %d!\n", infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001473 infoPtr->bPressed = FALSE;
1474 }
1475 else if (infoPtr->bTracking) {
Alexandre Julliarda099a551999-06-12 15:45:58 +00001476 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001477 infoPtr->bTracking = FALSE;
1478
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001479 HEADER_SendHeaderNotifyT (hwnd, HDN_ENDTRACKW, infoPtr->iMoveItem,HDI_WIDTH);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001480
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001481 if (!(dwStyle & HDS_FULLDRAG)) {
Eric Kohlcad17ff1999-03-12 17:42:50 +00001482 hdc = GetDC (hwnd);
1483 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
Aric Stewart3054b762000-06-11 20:39:14 +00001484 ReleaseDC (hwnd, hdc);
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001485 }
1486
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001487 if (HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH))
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001488 {
1489 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1490 }
1491 else {
1492 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1493 if (nWidth < 0)
1494 nWidth = 0;
1495 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1496 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001497
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001498 HEADER_SetItemBounds (hwnd);
1499 InvalidateRect(hwnd, NULL, TRUE);
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001500 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001501 }
1502
1503 if (infoPtr->bCaptured) {
1504 infoPtr->bCaptured = FALSE;
1505 ReleaseCapture ();
Eric Kohlcad17ff1999-03-12 17:42:50 +00001506 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001507 }
1508
1509 return 0;
1510}
1511
1512
1513static LRESULT
Eric Kohl40f29ee2000-11-25 03:07:01 +00001514HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1515{
1516 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1517
1518 switch (lParam)
1519 {
1520 case NF_QUERY:
1521 return infoPtr->nNotifyFormat;
1522
1523 case NF_REQUERY:
1524 infoPtr->nNotifyFormat =
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001525 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
Eric Kohl40f29ee2000-11-25 03:07:01 +00001526 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1527 return infoPtr->nNotifyFormat;
1528 }
1529
1530 return 0;
1531}
1532
1533
1534static LRESULT
Frank Richter07f86902005-08-03 11:45:19 +00001535HEADER_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
1536{
1537 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1538 /* Reset hot-tracked item when mouse leaves control. */
1539 INT oldHotItem = infoPtr->iHotItem;
1540 HDC hdc = GetDC (hwnd);
1541
1542 infoPtr->iHotItem = -1;
1543 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1544 ReleaseDC (hwnd, hdc);
1545
1546 return 0;
1547}
1548
1549
1550static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001551HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001552{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001553 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001554 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001555 POINT pt;
1556 UINT flags;
1557 INT nItem, nWidth;
1558 HDC hdc;
Frank Richter07f86902005-08-03 11:45:19 +00001559 /* With theming, hottracking is always enabled */
1560 BOOL hotTrackEnabled =
1561 ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK))
1562 || (GetWindowTheme (hwnd) != NULL);
1563 INT oldHotItem = infoPtr->iHotItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001564
Alexandre Julliard9d615962003-09-17 04:28:28 +00001565 pt.x = (INT)(SHORT)LOWORD(lParam);
1566 pt.y = (INT)(SHORT)HIWORD(lParam);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001567 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001568
Frank Richter07f86902005-08-03 11:45:19 +00001569 if (hotTrackEnabled) {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001570 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001571 infoPtr->iHotItem = nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001572 else
1573 infoPtr->iHotItem = -1;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001574 }
1575
1576 if (infoPtr->bCaptured) {
1577 if (infoPtr->bPressed) {
Frank Richter07f86902005-08-03 11:45:19 +00001578 BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001579 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001580 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1581 else
1582 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
Frank Richter07f86902005-08-03 11:45:19 +00001583 if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
1584 hdc = GetDC (hwnd);
1585 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1586 ReleaseDC (hwnd, hdc);
1587 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001588
Alexandre Julliarda099a551999-06-12 15:45:58 +00001589 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001590 }
1591 else if (infoPtr->bTracking) {
Eric Kohlcad17ff1999-03-12 17:42:50 +00001592 if (dwStyle & HDS_FULLDRAG) {
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001593 if (!HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH))
Ulrich Czekallaf235a7b2000-11-25 01:25:46 +00001594 {
Aric Stewart3054b762000-06-11 20:39:14 +00001595 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1596 if (nWidth < 0)
1597 nWidth = 0;
1598 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001599 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH);
Ulrich Czekallaf235a7b2000-11-25 01:25:46 +00001600 }
Eric Kohlcad17ff1999-03-12 17:42:50 +00001601 HEADER_SetItemBounds (hwnd);
Mikołaj Zalewskic63f5f02006-04-12 17:50:33 +02001602 InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001603 }
1604 else {
Eric Kohlcad17ff1999-03-12 17:42:50 +00001605 hdc = GetDC (hwnd);
1606 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001607 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1608 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1609 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
Vincent Béron9a624912002-05-31 23:06:46 +00001610 infoPtr->items[infoPtr->iMoveItem].cxy =
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001611 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
Eric Kohlcad17ff1999-03-12 17:42:50 +00001612 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1613 ReleaseDC (hwnd, hdc);
Mikołaj Zalewski84c31892006-04-17 17:09:56 +02001614 HEADER_SendHeaderNotifyT (hwnd, HDN_TRACKW, infoPtr->iMoveItem, HDI_WIDTH);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001615 }
1616
Alexandre Julliarda099a551999-06-12 15:45:58 +00001617 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001618 }
1619 }
1620
Frank Richter07f86902005-08-03 11:45:19 +00001621 if (hotTrackEnabled) {
1622 TRACKMOUSEEVENT tme;
1623 if (oldHotItem != infoPtr->iHotItem) {
1624 hdc = GetDC (hwnd);
1625 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1626 if (infoPtr->iHotItem != -1) HEADER_RefreshItem (hwnd, hdc, infoPtr->iHotItem);
1627 ReleaseDC (hwnd, hdc);
1628 }
1629 tme.cbSize = sizeof( tme );
1630 tme.dwFlags = TME_LEAVE;
1631 tme.hwndTrack = hwnd;
1632 TrackMouseEvent( &tme );
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001633 }
1634
1635 return 0;
1636}
1637
1638
1639static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001640HEADER_Paint (HWND hwnd, WPARAM wParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001641{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001642 HDC hdc;
1643 PAINTSTRUCT ps;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001644
Eric Kohlcad17ff1999-03-12 17:42:50 +00001645 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1646 HEADER_Refresh (hwnd, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001647 if(!wParam)
Eric Kohlcad17ff1999-03-12 17:42:50 +00001648 EndPaint (hwnd, &ps);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001649 return 0;
1650}
1651
1652
1653static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001654HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001655{
Pascal Lessardce527de2000-02-29 22:04:00 +00001656 BOOL bRet;
1657 POINT pt;
1658
1659 pt.x = LOWORD(lParam);
1660 pt.y = HIWORD(lParam);
1661
1662 /* Send a Notify message */
1663 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1664
1665 /* Change to screen coordinate for WM_CONTEXTMENU */
1666 ClientToScreen(hwnd, &pt);
1667
1668 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001669 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
Vincent Béron9a624912002-05-31 23:06:46 +00001670
Pascal Lessardce527de2000-02-29 22:04:00 +00001671 return bRet;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001672}
1673
1674
1675static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001676HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001677{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001678 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001679 POINT pt;
1680 UINT flags;
1681 INT nItem;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001682
Alexandre Julliarda099a551999-06-12 15:45:58 +00001683 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001684
Alexandre Julliarda3960291999-02-26 11:11:13 +00001685 GetCursorPos (&pt);
Eric Kohlcad17ff1999-03-12 17:42:50 +00001686 ScreenToClient (hwnd, &pt);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001687
Eric Kohlcad17ff1999-03-12 17:42:50 +00001688 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001689
1690 if (flags == HHT_ONDIVIDER)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001691 SetCursor (infoPtr->hcurDivider);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001692 else if (flags == HHT_ONDIVOPEN)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001693 SetCursor (infoPtr->hcurDivopen);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001694 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00001695 SetCursor (infoPtr->hcurArrow);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001696
1697 return 0;
1698}
1699
1700
1701static LRESULT
Eric Kohlcad17ff1999-03-12 17:42:50 +00001702HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001703{
Eric Kohlcad17ff1999-03-12 17:42:50 +00001704 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001705 TEXTMETRICW tm;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001706 HFONT hFont, hOldFont;
1707 HDC hdc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001708
Alexandre Julliarda3960291999-02-26 11:11:13 +00001709 infoPtr->hFont = (HFONT)wParam;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001710
Alexandre Julliarda3960291999-02-26 11:11:13 +00001711 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001712
Alexandre Julliarda3960291999-02-26 11:11:13 +00001713 hdc = GetDC (0);
1714 hOldFont = SelectObject (hdc, hFont);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001715 GetTextMetricsW (hdc, &tm);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001716 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001717 SelectObject (hdc, hOldFont);
1718 ReleaseDC (0, hdc);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001719
Martin Fuchs33bdf532000-04-28 14:46:36 +00001720 infoPtr->bRectsValid = FALSE;
Vincent Béron9a624912002-05-31 23:06:46 +00001721
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001722 if (lParam) {
Chris Morgan3cbc1682000-06-04 01:34:31 +00001723 InvalidateRect(hwnd, NULL, FALSE);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001724 }
1725
1726 return 0;
1727}
1728
Frank Richter564872c2005-07-25 11:09:09 +00001729/* Update the theme handle after a theme change */
1730static LRESULT HEADER_ThemeChanged(HWND hwnd)
1731{
1732 HTHEME theme = GetWindowTheme(hwnd);
1733 CloseThemeData(theme);
1734 OpenThemeData(hwnd, themeClass);
1735 InvalidateRect(hwnd, NULL, FALSE);
1736 return 0;
1737}
1738
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001739
Patrik Stridvall26ffb3c1999-07-31 14:41:43 +00001740static LRESULT WINAPI
Alexandre Julliarda3960291999-02-26 11:11:13 +00001741HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001742{
Michael Stefaniuc353529b2002-10-23 22:19:10 +00001743 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
Gerard Patela1b2fc22000-05-10 01:34:53 +00001744 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001745 return DefWindowProcW (hwnd, msg, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001746 switch (msg) {
Eric Kohl40f29ee2000-11-25 03:07:01 +00001747/* case HDM_CLEARFILTER: */
1748
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001749 case HDM_CREATEDRAGIMAGE:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001750 return HEADER_CreateDragImage (hwnd, wParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001751
1752 case HDM_DELETEITEM:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001753 return HEADER_DeleteItem (hwnd, wParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001754
Eric Kohl40f29ee2000-11-25 03:07:01 +00001755/* case HDM_EDITFILTER: */
1756
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +00001757 case HDM_GETBITMAPMARGIN:
1758 return HEADER_GetBitmapMargin(hwnd);
Eric Kohl40f29ee2000-11-25 03:07:01 +00001759
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001760 case HDM_GETIMAGELIST:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001761 return HEADER_GetImageList (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001762
Alexandre Julliarda3960291999-02-26 11:11:13 +00001763 case HDM_GETITEMA:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001764 case HDM_GETITEMW:
Vitaliy Margolenc2584302005-10-29 11:08:20 +00001765 return HEADER_GetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001766
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001767 case HDM_GETITEMCOUNT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001768 return HEADER_GetItemCount (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001769
1770 case HDM_GETITEMRECT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001771 return HEADER_GetItemRect (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001772
Vincent Béron9a624912002-05-31 23:06:46 +00001773 case HDM_GETORDERARRAY:
Uwe Bonnes018c6542000-10-19 22:26:17 +00001774 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1775
Eric Kohl8d2933d1998-11-22 18:12:12 +00001776 case HDM_GETUNICODEFORMAT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001777 return HEADER_GetUnicodeFormat (hwnd);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001778
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001779 case HDM_HITTEST:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001780 return HEADER_HitTest (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001781
Alexandre Julliarda3960291999-02-26 11:11:13 +00001782 case HDM_INSERTITEMA:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001783 case HDM_INSERTITEMW:
Vitaliy Margolen89a49182005-10-28 10:40:27 +00001784 return HEADER_InsertItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001785
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001786 case HDM_LAYOUT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001787 return HEADER_Layout (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001788
Eric Kohl40f29ee2000-11-25 03:07:01 +00001789 case HDM_ORDERTOINDEX:
1790 return HEADER_OrderToIndex(hwnd, wParam);
1791
Maxime Bellengé5b99b3d2003-10-14 20:13:42 +00001792 case HDM_SETBITMAPMARGIN:
1793 return HEADER_SetBitmapMargin(hwnd, wParam);
Eric Kohl40f29ee2000-11-25 03:07:01 +00001794
1795/* case HDM_SETFILTERCHANGETIMEOUT: */
1796
1797/* case HDM_SETHOTDIVIDER: */
1798
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001799 case HDM_SETIMAGELIST:
Eric Kohl4718b6d2000-12-13 01:52:23 +00001800 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001801
Alexandre Julliarda3960291999-02-26 11:11:13 +00001802 case HDM_SETITEMA:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001803 case HDM_SETITEMW:
Vitaliy Margolen05905cc2005-10-27 10:19:29 +00001804 return HEADER_SetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001805
Eric Kohl40f29ee2000-11-25 03:07:01 +00001806 case HDM_SETORDERARRAY:
1807 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1808
Eric Kohl8d2933d1998-11-22 18:12:12 +00001809 case HDM_SETUNICODEFORMAT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001810 return HEADER_SetUnicodeFormat (hwnd, wParam);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00001811
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001812 case WM_CREATE:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001813 return HEADER_Create (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001814
1815 case WM_DESTROY:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001816 return HEADER_Destroy (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001817
1818 case WM_ERASEBKGND:
1819 return 1;
1820
1821 case WM_GETDLGCODE:
1822 return DLGC_WANTTAB | DLGC_WANTARROWS;
1823
1824 case WM_GETFONT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001825 return HEADER_GetFont (hwnd);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001826
1827 case WM_LBUTTONDBLCLK:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001828 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001829
1830 case WM_LBUTTONDOWN:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001831 return HEADER_LButtonDown (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001832
1833 case WM_LBUTTONUP:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001834 return HEADER_LButtonUp (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001835
Frank Richter07f86902005-08-03 11:45:19 +00001836 case WM_MOUSELEAVE:
1837 return HEADER_MouseLeave (hwnd, wParam, lParam);
1838
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001839 case WM_MOUSEMOVE:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001840 return HEADER_MouseMove (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001841
Eric Kohl40f29ee2000-11-25 03:07:01 +00001842 case WM_NOTIFYFORMAT:
1843 return HEADER_NotifyFormat (hwnd, wParam, lParam);
Eric Kohl8d2933d1998-11-22 18:12:12 +00001844
Martin Fuchs33bdf532000-04-28 14:46:36 +00001845 case WM_SIZE:
1846 return HEADER_Size (hwnd, wParam);
Vincent Béron9a624912002-05-31 23:06:46 +00001847
Frank Richter564872c2005-07-25 11:09:09 +00001848 case WM_THEMECHANGED:
1849 return HEADER_ThemeChanged (hwnd);
1850
Michael Kaufmanne9310da2005-11-08 12:52:35 +00001851 case WM_PRINTCLIENT:
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001852 case WM_PAINT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001853 return HEADER_Paint (hwnd, wParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001854
1855 case WM_RBUTTONUP:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001856 return HEADER_RButtonUp (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001857
1858 case WM_SETCURSOR:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001859 return HEADER_SetCursor (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001860
1861 case WM_SETFONT:
Eric Kohlcad17ff1999-03-12 17:42:50 +00001862 return HEADER_SetFont (hwnd, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001863
1864 default:
Bill Medland69f18272002-07-16 01:14:46 +00001865 if ((msg >= WM_USER) && (msg < WM_APP))
Alexandre Julliarda099a551999-06-12 15:45:58 +00001866 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001867 msg, wParam, lParam );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001868 return DefWindowProcA (hwnd, msg, wParam, lParam);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001869 }
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001870}
1871
1872
Eric Kohl9d8e8641998-10-24 10:49:27 +00001873VOID
Patrik Stridvall9e61c1c1999-06-12 08:27:49 +00001874HEADER_Register (void)
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001875{
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001876 WNDCLASSW wndClass;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001877
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001878 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001879 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
Robert Shearman8d28e032004-11-06 03:49:03 +00001880 wndClass.lpfnWndProc = HEADER_WindowProc;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001881 wndClass.cbClsExtra = 0;
1882 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001883 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1884 wndClass.lpszClassName = WC_HEADERW;
Vincent Béron9a624912002-05-31 23:06:46 +00001885
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001886 RegisterClassW (&wndClass);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001887}
1888
Eric Kohl9d8e8641998-10-24 10:49:27 +00001889
1890VOID
Patrik Stridvall9e61c1c1999-06-12 08:27:49 +00001891HEADER_Unregister (void)
Eric Kohl9d8e8641998-10-24 10:49:27 +00001892{
Dimitrie O. Paun4904c8b2005-03-23 10:23:06 +00001893 UnregisterClassW (WC_HEADERW, NULL);
Eric Kohl9d8e8641998-10-24 10:49:27 +00001894}