1 | /* $Id: treeview.cpp,v 1.15 2000-06-22 19:02:04 cbratschi Exp $ */
|
---|
2 | /* Treeview control
|
---|
3 | *
|
---|
4 | * Copyright 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de>
|
---|
5 | * Copyright 1998,1999 Alex Priem <alexp@sci.kun.nl>
|
---|
6 | * Copyright 1999 Sylvain St-Germain
|
---|
7 | * Copyright 1999 Achim Hasenmueller
|
---|
8 | * Copyright 1999-2000 Christoph Bratschi (cbratschi@datacomm.ch)
|
---|
9 | *
|
---|
10 | * Note that TREEVIEW_INFO * and HTREEITEM are the same thing.
|
---|
11 | *
|
---|
12 | *
|
---|
13 | * Status: complete (many things untested)
|
---|
14 | * Version: 5.80
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | Most identical with:
|
---|
19 | - Corel 20000212 level
|
---|
20 | - (WINE 991212 level)
|
---|
21 | */
|
---|
22 |
|
---|
23 | /* CB: todo/bugs
|
---|
24 | - startup: missing WM_SIZE messages -> i.e. wrong info tip calculation
|
---|
25 | - bug in SetScrollInfo/ShowScrollBar: WM_SIZE and WM_NCPAINT problems (i.e. RegEdit)
|
---|
26 | - VK_LEFT in WinHlp32 displays expanded icon
|
---|
27 | - expand not finished
|
---|
28 | - WM_ENABLE: draw disabled control
|
---|
29 | - AMD cpuid: text not drawn (> treeview.cpp,v 1.13 2000/05/10 19:50:33)
|
---|
30 | t1: GDI32: SetBkColor to FFFFFF
|
---|
31 | t1: GDI32: GetTextMetricsA returned 1
|
---|
32 | t1: GDI32: SetTextAlign
|
---|
33 | -->
|
---|
34 | t1: GDI32: RestoreDC
|
---|
35 | t1: SendInternalMessageA WM_NOTIFY for 68000003 65 1312e4
|
---|
36 | t1: USER32: GetDlgCtrlID
|
---|
37 |
|
---|
38 | missing lines at -->:
|
---|
39 | t1: GDI32: GetTextExtentPoint32A 10001a1 Processor Speed Test 20 returned 1 (93,14)
|
---|
40 | t1: GDI32: ExtTextOutA 10001a1 Processor Speed Test
|
---|
41 | t1: GDI32: GetTextAlign
|
---|
42 | t1: GDI32: GetTextExtentPoint32A 10001a1 454 Mhz 7 returned 1 (37,14)
|
---|
43 | t1: GDI32: ExtTextOutA 10001a1 454 Mhz
|
---|
44 | t1: GDI32: GetTextAlign
|
---|
45 |
|
---|
46 | don't know why it fails
|
---|
47 | */
|
---|
48 |
|
---|
49 | #include <assert.h>
|
---|
50 | #include <stdlib.h>
|
---|
51 | #include <string.h>
|
---|
52 | #include <math.h>
|
---|
53 | #include <limits.h>
|
---|
54 | #include "winbase.h"
|
---|
55 | #include "wingdi.h"
|
---|
56 | #include "winnls.h"
|
---|
57 | #include "commctrl.h"
|
---|
58 | #include "comctl32.h"
|
---|
59 | #include "ccbase.h"
|
---|
60 | #include "treeview.h"
|
---|
61 |
|
---|
62 | /* ffs should be in <string.h>. */
|
---|
63 |
|
---|
64 | //#define NDEBUG
|
---|
65 | #define NDEBUG_TEXT
|
---|
66 |
|
---|
67 | #define TEXT_CALLBACK_SIZE 260
|
---|
68 |
|
---|
69 | #define TREEVIEW_LEFT_MARGIN 8
|
---|
70 |
|
---|
71 | #define MINIMUM_INDENT 19
|
---|
72 |
|
---|
73 | #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
|
---|
74 |
|
---|
75 | #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
|
---|
76 | #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
|
---|
77 |
|
---|
78 | typedef VOID (*TREEVIEW_ItemEnumFunc)(TREEVIEW_INFO *, TREEVIEW_ITEM *,LPVOID);
|
---|
79 |
|
---|
80 | static BOOL TREEVIEW_UnqueueRefresh(TREEVIEW_INFO *,BOOL calc,BOOL refresh);
|
---|
81 | static void TREEVIEW_QueueRefresh(TREEVIEW_INFO *);
|
---|
82 | static void TREEVIEW_Refresh(TREEVIEW_INFO *infoPtr);
|
---|
83 | static void TREEVIEW_RefreshItem(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item,DWORD changed);
|
---|
84 |
|
---|
85 | static VOID TREEVIEW_HideInfoTip(TREEVIEW_INFO *infoPtr);
|
---|
86 | static LRESULT TREEVIEW_DoSelectItem(TREEVIEW_INFO *, INT, HTREEITEM, INT);
|
---|
87 | static LRESULT TREEVIEW_EnsureVisible(TREEVIEW_INFO *, HTREEITEM);
|
---|
88 | static LRESULT TREEVIEW_RButtonUp(TREEVIEW_INFO *, LPPOINT);
|
---|
89 | static LRESULT TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel);
|
---|
90 | static VOID TREEVIEW_UpdateScrollBars(TREEVIEW_INFO *infoPtr, BOOL);
|
---|
91 | static VOID TREEVIEW_CheckInfoTip(TREEVIEW_INFO *infoPtr);
|
---|
92 | static VOID TREEVIEW_ISearch(TREEVIEW_INFO *infoPtr,CHAR ch);
|
---|
93 |
|
---|
94 | /* Random Utilities *****************************************************/
|
---|
95 |
|
---|
96 | #ifdef NDEBUG
|
---|
97 | static inline void
|
---|
98 | TREEVIEW_VerifyTree(TREEVIEW_INFO *infoPtr)
|
---|
99 | {
|
---|
100 | (void)infoPtr;
|
---|
101 | }
|
---|
102 |
|
---|
103 | #else
|
---|
104 | /* The definition is at the end of the file. */
|
---|
105 | static void TREEVIEW_VerifyTree(TREEVIEW_INFO *infoPtr);
|
---|
106 | #ifndef NDEBUG_TEXT
|
---|
107 | static void TREEVIEW_WriteVerify(CHAR *text)
|
---|
108 | {
|
---|
109 | dprintf((text));
|
---|
110 | }
|
---|
111 | #else
|
---|
112 | static inline void TREEVIEW_WriteVerify(CHAR * text) {}
|
---|
113 | #endif
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | /* Returns the treeview private data if hwnd is a treeview.
|
---|
117 | * Otherwise returns an undefined value. */
|
---|
118 | #define TREEVIEW_GetInfoPtr(hwnd) ((TREEVIEW_INFO *)getInfoPtr(hwnd))
|
---|
119 |
|
---|
120 | /* Don't call this. Nothing wants an item index. */
|
---|
121 | static inline int
|
---|
122 | TREEVIEW_GetItemIndex(TREEVIEW_INFO *infoPtr, HTREEITEM handle)
|
---|
123 | {
|
---|
124 | assert(infoPtr != NULL);
|
---|
125 |
|
---|
126 | return DPA_GetPtrIndex(infoPtr->items,handle);
|
---|
127 | }
|
---|
128 |
|
---|
129 | /***************************************************************************
|
---|
130 | * This method checks that handle is an item for this tree.
|
---|
131 | */
|
---|
132 | static BOOL
|
---|
133 | TREEVIEW_ValidItem(TREEVIEW_INFO *infoPtr,HTREEITEM handle)
|
---|
134 | {
|
---|
135 | if (TREEVIEW_GetItemIndex(infoPtr, handle) == -1)
|
---|
136 | {
|
---|
137 | //TRACE("invalid item %p\n", handle);
|
---|
138 | return FALSE;
|
---|
139 | }
|
---|
140 | else
|
---|
141 | return TRUE;
|
---|
142 | }
|
---|
143 |
|
---|
144 | static HFONT
|
---|
145 | TREEVIEW_CreateBoldFont(HFONT hOrigFont)
|
---|
146 | {
|
---|
147 | LOGFONTA font;
|
---|
148 |
|
---|
149 | GetObjectA(hOrigFont, sizeof(font), &font);
|
---|
150 | font.lfWeight = FW_BOLD;
|
---|
151 |
|
---|
152 | return CreateFontIndirectA(&font);
|
---|
153 | }
|
---|
154 |
|
---|
155 | static inline HFONT
|
---|
156 | TREEVIEW_FontForItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
|
---|
157 | {
|
---|
158 | return (item->state & TVIS_BOLD) ? infoPtr->hBoldFont : infoPtr->hFont;
|
---|
159 | }
|
---|
160 |
|
---|
161 | /* for trace/debugging purposes only */
|
---|
162 | static const WCHAR *
|
---|
163 | TREEVIEW_ItemName(TREEVIEW_ITEM *item)
|
---|
164 | {
|
---|
165 | if (item == NULL) return (WCHAR*)L"<null item>";
|
---|
166 | if (item->pszText == LPSTR_TEXTCALLBACKW) return (WCHAR*)L"<callback>";
|
---|
167 | if (item->pszText == NULL) return (WCHAR*)L"<null>";
|
---|
168 | /* It would be nice to check item->callbackMask & TVIF_TEXT here,
|
---|
169 | * and indicate that this is a callback string, but there is nowhere
|
---|
170 | * to put that indication. (Or we could be clever, and put it before
|
---|
171 | * pszText, but that is just too hacky.) */
|
---|
172 | return item->pszText;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /* An item is not a child of itself. */
|
---|
176 | static BOOL
|
---|
177 | TREEVIEW_IsChildOf(TREEVIEW_ITEM *parent, TREEVIEW_ITEM *child)
|
---|
178 | {
|
---|
179 | do
|
---|
180 | {
|
---|
181 | child = child->parent;
|
---|
182 | if (child == parent) return TRUE;
|
---|
183 | } while (child != NULL);
|
---|
184 |
|
---|
185 | return FALSE;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /* Tree Traversal *******************************************************/
|
---|
189 |
|
---|
190 | /***************************************************************************
|
---|
191 | * This method returns the last expanded sibling or child child item
|
---|
192 | * of a tree node
|
---|
193 | */
|
---|
194 | static TREEVIEW_ITEM *
|
---|
195 | TREEVIEW_GetLastListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
|
---|
196 | {
|
---|
197 | /*
|
---|
198 | * Get this item's last sibling
|
---|
199 | */
|
---|
200 | while (wineItem->nextSibling)
|
---|
201 | wineItem = wineItem->nextSibling;
|
---|
202 |
|
---|
203 | /*
|
---|
204 | * If the last sibling has expanded children, restart.
|
---|
205 | */
|
---|
206 | if ((wineItem->state & TVIS_EXPANDED) && wineItem->firstChild != NULL)
|
---|
207 | {
|
---|
208 | return TREEVIEW_GetLastListItem(infoPtr, wineItem->firstChild);
|
---|
209 | }
|
---|
210 |
|
---|
211 | return wineItem;
|
---|
212 | }
|
---|
213 |
|
---|
214 | /***************************************************************************
|
---|
215 | * This method returns the previous non-hidden item in the list not
|
---|
216 | * considering the tree hierarchy.
|
---|
217 | */
|
---|
218 | static TREEVIEW_ITEM *
|
---|
219 | TREEVIEW_GetPrevListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *tvItem)
|
---|
220 | {
|
---|
221 | if (tvItem->prevSibling)
|
---|
222 | {
|
---|
223 | /*
|
---|
224 | * This item has a prevSibling, get the last item. Since
|
---|
225 | * GetLastListItem first looks at siblings, we must feed it with the
|
---|
226 | * first child.
|
---|
227 | */
|
---|
228 | TREEVIEW_ITEM *upItem = tvItem->prevSibling;
|
---|
229 |
|
---|
230 | if ((upItem->state & TVIS_EXPANDED) && upItem->firstChild != NULL)
|
---|
231 | return TREEVIEW_GetLastListItem(infoPtr, upItem->firstChild);
|
---|
232 | else
|
---|
233 | return upItem;
|
---|
234 | }
|
---|
235 | else
|
---|
236 | {
|
---|
237 | /*
|
---|
238 | * this item does not have a prevSibling, get the parent
|
---|
239 | */
|
---|
240 | return (tvItem->parent != infoPtr->root) ? tvItem->parent : NULL;
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | /***************************************************************************
|
---|
246 | * This method returns the next physical item in the treeview not
|
---|
247 | * considering the tree hierarchy.
|
---|
248 | */
|
---|
249 | static TREEVIEW_ITEM *
|
---|
250 | TREEVIEW_GetNextListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *tvItem)
|
---|
251 | {
|
---|
252 | assert(infoPtr != NULL);
|
---|
253 | assert(tvItem != NULL);
|
---|
254 |
|
---|
255 | /*
|
---|
256 | * If this item has children and is expanded, return the first child
|
---|
257 | */
|
---|
258 | if ((tvItem->state & TVIS_EXPANDED) && tvItem->firstChild != NULL)
|
---|
259 | {
|
---|
260 | return tvItem->firstChild;
|
---|
261 | }
|
---|
262 |
|
---|
263 |
|
---|
264 | /*
|
---|
265 | * try to get the sibling
|
---|
266 | */
|
---|
267 | if (tvItem->nextSibling)
|
---|
268 | return tvItem->nextSibling;
|
---|
269 |
|
---|
270 | /*
|
---|
271 | * Otherwise, get the parent's sibling.
|
---|
272 | */
|
---|
273 | while (tvItem->parent)
|
---|
274 | {
|
---|
275 | tvItem = tvItem->parent;
|
---|
276 |
|
---|
277 | if (tvItem->nextSibling)
|
---|
278 | return tvItem->nextSibling;
|
---|
279 | }
|
---|
280 |
|
---|
281 | return NULL;
|
---|
282 | }
|
---|
283 |
|
---|
284 | /***************************************************************************
|
---|
285 | * This method returns the nth item starting at the given item. It returns
|
---|
286 | * the last item (or first) we we run out of items.
|
---|
287 | *
|
---|
288 | * Will scroll backward if count is <0.
|
---|
289 | * forward if count is >0.
|
---|
290 | */
|
---|
291 | static TREEVIEW_ITEM *
|
---|
292 | TREEVIEW_GetListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
|
---|
293 | LONG count)
|
---|
294 | {
|
---|
295 | TREEVIEW_ITEM *(*next_item)(TREEVIEW_INFO *, TREEVIEW_ITEM *);
|
---|
296 | TREEVIEW_ITEM *previousItem;
|
---|
297 |
|
---|
298 | assert(wineItem != NULL);
|
---|
299 |
|
---|
300 | if (count > 0)
|
---|
301 | {
|
---|
302 | next_item = TREEVIEW_GetNextListItem;
|
---|
303 | }
|
---|
304 | else if (count < 0)
|
---|
305 | {
|
---|
306 | count = -count;
|
---|
307 | next_item = TREEVIEW_GetPrevListItem;
|
---|
308 | }
|
---|
309 | else
|
---|
310 | return wineItem;
|
---|
311 |
|
---|
312 | do
|
---|
313 | {
|
---|
314 | previousItem = wineItem;
|
---|
315 | wineItem = next_item(infoPtr, wineItem);
|
---|
316 |
|
---|
317 | } while (--count && wineItem != NULL);
|
---|
318 |
|
---|
319 |
|
---|
320 | return wineItem ? wineItem : previousItem;
|
---|
321 | }
|
---|
322 |
|
---|
323 | static VOID
|
---|
324 | TREEVIEW_ForEachDisplayed(TREEVIEW_INFO *infoPtr,TREEVIEW_ItemEnumFunc func,LPVOID data)
|
---|
325 | {
|
---|
326 | TREEVIEW_ITEM *item;
|
---|
327 |
|
---|
328 | for (item = infoPtr->root->firstChild; item != NULL;
|
---|
329 | item = TREEVIEW_GetNextListItem(infoPtr, item))
|
---|
330 | {
|
---|
331 | func(infoPtr, item, data);
|
---|
332 | }
|
---|
333 | }
|
---|
334 |
|
---|
335 | /* Notifications */
|
---|
336 |
|
---|
337 | static VOID
|
---|
338 | TREEVIEW_TVItemFromItem(UINT mask,TVITEMW *tvItem,TREEVIEW_ITEM *item)
|
---|
339 | {
|
---|
340 | tvItem->mask = mask;
|
---|
341 | tvItem->hItem = item;
|
---|
342 | tvItem->state = item->state;
|
---|
343 | tvItem->stateMask = 0;
|
---|
344 | tvItem->iImage = item->iImage;
|
---|
345 | tvItem->pszText = item->pszText;
|
---|
346 | tvItem->cchTextMax = item->cchTextMax;
|
---|
347 | tvItem->iImage = item->iImage;
|
---|
348 | tvItem->iSelectedImage = item->iSelectedImage;
|
---|
349 | tvItem->cChildren = item->cChildren;
|
---|
350 | tvItem->lParam = item->lParam;
|
---|
351 | }
|
---|
352 |
|
---|
353 | static BOOL TREEVIEW_SendTreeviewNotify(TREEVIEW_INFO *infoPtr,UINT code,UINT action,UINT mask,HTREEITEM oldItem,HTREEITEM newItem)
|
---|
354 | {
|
---|
355 | NMTREEVIEWW nmhdr;
|
---|
356 | CHAR *oldText = NULL,*newText = NULL;
|
---|
357 | BOOL rc;
|
---|
358 |
|
---|
359 | ZeroMemory(&nmhdr,sizeof(NMTREEVIEWW));
|
---|
360 |
|
---|
361 | nmhdr.action = action;
|
---|
362 | if (oldItem)
|
---|
363 | {
|
---|
364 | TREEVIEW_TVItemFromItem(mask, &nmhdr.itemOld, oldItem);
|
---|
365 | if (!isUnicodeNotify(&infoPtr->header))
|
---|
366 | {
|
---|
367 | if (!oldItem->pszText || (oldItem->pszText == LPSTR_TEXTCALLBACKW)) nmhdr.itemOld.pszText = NULL; else
|
---|
368 | {
|
---|
369 | INT len = lstrlenW(oldItem->pszText)+1;
|
---|
370 |
|
---|
371 | oldText = (CHAR*)COMCTL32_Alloc(len);
|
---|
372 | lstrcpyWtoA(oldText,oldItem->pszText);
|
---|
373 | nmhdr.itemOld.pszText = (WCHAR*)oldText;
|
---|
374 | nmhdr.itemOld.cchTextMax = len;
|
---|
375 | }
|
---|
376 | }
|
---|
377 | }
|
---|
378 |
|
---|
379 | if (newItem)
|
---|
380 | {
|
---|
381 | TREEVIEW_TVItemFromItem(mask, &nmhdr.itemNew, newItem);
|
---|
382 | if (!isUnicodeNotify(&infoPtr->header))
|
---|
383 | {
|
---|
384 | if (!newItem->pszText || (newItem->pszText == LPSTR_TEXTCALLBACKW)) nmhdr.itemNew.pszText = NULL; else
|
---|
385 | {
|
---|
386 | INT len = lstrlenW(newItem->pszText)+1;
|
---|
387 |
|
---|
388 | newText = (CHAR*)COMCTL32_Alloc(len);
|
---|
389 | lstrcpyWtoA(newText,newItem->pszText);
|
---|
390 | nmhdr.itemNew.pszText = (WCHAR*)newText;
|
---|
391 | nmhdr.itemNew.cchTextMax = len;
|
---|
392 | }
|
---|
393 | }
|
---|
394 | }
|
---|
395 |
|
---|
396 | nmhdr.ptDrag.x = 0;
|
---|
397 | nmhdr.ptDrag.y = 0;
|
---|
398 |
|
---|
399 | rc = (BOOL)sendNotify(infoPtr->hwnd,code,&nmhdr.hdr);
|
---|
400 |
|
---|
401 | if (oldText) COMCTL32_Free(oldText);
|
---|
402 | if (newText) COMCTL32_Free(newText);
|
---|
403 |
|
---|
404 | return rc;
|
---|
405 | }
|
---|
406 |
|
---|
407 | static BOOL
|
---|
408 | TREEVIEW_SendTreeviewDnDNotify (TREEVIEW_INFO *infoPtr,UINT code,HTREEITEM dragItem,POINT pt)
|
---|
409 | {
|
---|
410 | NMTREEVIEWA nmhdr;
|
---|
411 |
|
---|
412 | nmhdr.action = 0;
|
---|
413 | nmhdr.itemNew.mask = TVIF_STATE | TVIF_PARAM | TVIF_HANDLE;
|
---|
414 | nmhdr.itemNew.hItem = dragItem;
|
---|
415 | nmhdr.itemNew.state = dragItem->state;
|
---|
416 | nmhdr.itemNew.lParam = dragItem->lParam;
|
---|
417 |
|
---|
418 | nmhdr.ptDrag.x = pt.x;
|
---|
419 | nmhdr.ptDrag.y = pt.y;
|
---|
420 |
|
---|
421 | return (BOOL)sendNotify(infoPtr->hwnd,code,&nmhdr.hdr);
|
---|
422 | }
|
---|
423 |
|
---|
424 | static BOOL
|
---|
425 | TREEVIEW_SendCustomDrawNotify(TREEVIEW_INFO *infoPtr,DWORD dwDrawStage,HDC hdc,RECT rc)
|
---|
426 | {
|
---|
427 | NMTVCUSTOMDRAW nmcdhdr;
|
---|
428 | LPNMCUSTOMDRAW nmcd;
|
---|
429 |
|
---|
430 | nmcd = &nmcdhdr.nmcd;
|
---|
431 | nmcd->dwDrawStage = dwDrawStage;
|
---|
432 | nmcd->hdc = hdc;
|
---|
433 | nmcd->rc = rc;
|
---|
434 | nmcd->dwItemSpec = 0;
|
---|
435 | nmcd->uItemState = 0;
|
---|
436 | nmcd->lItemlParam = 0;
|
---|
437 | nmcdhdr.clrText = infoPtr->clrText;
|
---|
438 | nmcdhdr.clrTextBk = infoPtr->clrBk;
|
---|
439 | nmcdhdr.iLevel = 0;
|
---|
440 |
|
---|
441 | return (BOOL)sendNotify(infoPtr->hwnd,NM_CUSTOMDRAW,&nmcdhdr.nmcd.hdr);
|
---|
442 | }
|
---|
443 |
|
---|
444 | /* FIXME: need to find out when the flags in uItemState need to be set */
|
---|
445 | static BOOL
|
---|
446 | TREEVIEW_SendCustomDrawItemNotify(TREEVIEW_INFO *infoPtr,HDC hdc,TREEVIEW_ITEM *wineItem,UINT uItemDrawState)
|
---|
447 | {
|
---|
448 | NMTVCUSTOMDRAW nmcdhdr;
|
---|
449 | LPNMCUSTOMDRAW nmcd;
|
---|
450 | DWORD dwDrawStage,dwItemSpec;
|
---|
451 | UINT uItemState;
|
---|
452 | INT retval;
|
---|
453 |
|
---|
454 | dwDrawStage = CDDS_ITEM | uItemDrawState;
|
---|
455 | dwItemSpec = (DWORD)wineItem;
|
---|
456 | uItemState = 0;
|
---|
457 | if (wineItem == infoPtr->selectedItem)
|
---|
458 | {
|
---|
459 | uItemState |= CDIS_SELECTED;
|
---|
460 | if (GetFocus() == infoPtr->hwnd) uItemState |= CDIS_FOCUS;
|
---|
461 | }
|
---|
462 | if (wineItem == infoPtr->focusItem)
|
---|
463 | uItemState |= CDIS_FOCUS;
|
---|
464 | if (wineItem == infoPtr->hotItem)
|
---|
465 | uItemState |= CDIS_HOT;
|
---|
466 |
|
---|
467 | nmcd = &nmcdhdr.nmcd;
|
---|
468 | nmcd->dwDrawStage = dwDrawStage;
|
---|
469 | nmcd->hdc = hdc;
|
---|
470 | nmcd->rc = wineItem->rect;
|
---|
471 | nmcd->dwItemSpec = dwItemSpec;
|
---|
472 | nmcd->uItemState = uItemState;
|
---|
473 | nmcd->lItemlParam = wineItem->lParam;
|
---|
474 | nmcdhdr.clrText = infoPtr->clrText;
|
---|
475 | nmcdhdr.clrTextBk = infoPtr->clrBk;
|
---|
476 | nmcdhdr.iLevel = wineItem->iLevel;
|
---|
477 |
|
---|
478 | retval = sendNotify(infoPtr->hwnd,NM_CUSTOMDRAW,&nmcdhdr.nmcd.hdr);
|
---|
479 |
|
---|
480 | infoPtr->clrText = nmcdhdr.clrText;
|
---|
481 | infoPtr->clrBk = nmcdhdr.clrTextBk;
|
---|
482 |
|
---|
483 | return (BOOL)retval;
|
---|
484 | }
|
---|
485 |
|
---|
486 | static void
|
---|
487 | TREEVIEW_GetDispInfo(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *wineItem,NMTVDISPINFOW* info,UINT mask)
|
---|
488 | {
|
---|
489 | info->item.mask = mask;
|
---|
490 | info->item.hItem = wineItem;
|
---|
491 | info->item.state = wineItem->state;
|
---|
492 | info->item.stateMask = 0;
|
---|
493 | info->item.lParam = wineItem->lParam;
|
---|
494 |
|
---|
495 | sendNotify(infoPtr->hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_GETDISPINFOW:TVN_GETDISPINFOA,&info->hdr);
|
---|
496 | }
|
---|
497 |
|
---|
498 | static void
|
---|
499 | TREEVIEW_UpdateDispInfo(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *wineItem,UINT mask)
|
---|
500 | {
|
---|
501 | NMTVDISPINFOW callback;
|
---|
502 |
|
---|
503 | mask &= wineItem->callbackMask;
|
---|
504 |
|
---|
505 | if (mask == 0) return;
|
---|
506 |
|
---|
507 | if ((mask & TVIF_TEXT) /*&& (wineItem->cchTextMax < TEXT_CALLBACK_SIZE)*/)
|
---|
508 | {
|
---|
509 | wineItem->pszText = (WCHAR*)COMCTL32_ReAlloc(wineItem->pszText,TEXT_CALLBACK_SIZE*sizeof(WCHAR));
|
---|
510 | wineItem->cchTextMax = TEXT_CALLBACK_SIZE;
|
---|
511 | }
|
---|
512 |
|
---|
513 | callback.item.pszText = wineItem->pszText;
|
---|
514 | callback.item.cchTextMax = wineItem->cchTextMax;
|
---|
515 | callback.item.iImage = wineItem->iImage;
|
---|
516 | callback.item.iSelectedImage = wineItem->iSelectedImage;
|
---|
517 | callback.item.cChildren = wineItem->cChildren;
|
---|
518 |
|
---|
519 | TREEVIEW_GetDispInfo(infoPtr,wineItem,&callback,mask);
|
---|
520 |
|
---|
521 | /* It may have changed due to a call to SetItem. */
|
---|
522 | mask &= wineItem->callbackMask;
|
---|
523 |
|
---|
524 | if (mask & TVIF_TEXT)
|
---|
525 | {
|
---|
526 | if (callback.item.pszText != wineItem->pszText)
|
---|
527 | {
|
---|
528 | INT len = MAX((isUnicodeNotify(&infoPtr->header) ? lstrlenW(callback.item.pszText):lstrlenA((CHAR*)callback.item.pszText))+1,TEXT_CALLBACK_SIZE);
|
---|
529 |
|
---|
530 | wineItem->pszText = (WCHAR*)COMCTL32_ReAlloc(wineItem->pszText,len*sizeof(WCHAR));
|
---|
531 | if (isUnicodeNotify(&infoPtr->header))
|
---|
532 | lstrcpyW(wineItem->pszText,callback.item.pszText);
|
---|
533 | else
|
---|
534 | lstrcpyAtoW(wineItem->pszText,(CHAR*)callback.item.pszText);
|
---|
535 | wineItem->cchTextMax = len;
|
---|
536 | } else if (!isUnicodeNotify(&infoPtr->header))
|
---|
537 | {
|
---|
538 | WCHAR *newText;
|
---|
539 | INT len = MAX(lstrlenA((CHAR*)callback.item.pszText)+1,TEXT_CALLBACK_SIZE);
|
---|
540 |
|
---|
541 | newText = (WCHAR*)COMCTL32_Alloc(len*sizeof(WCHAR));
|
---|
542 | lstrcpyAtoW(newText,(LPSTR)callback.item.pszText);
|
---|
543 | COMCTL32_Free(wineItem->pszText);
|
---|
544 | wineItem->pszText = newText;
|
---|
545 | wineItem->cchTextMax = len;
|
---|
546 | }
|
---|
547 | }
|
---|
548 |
|
---|
549 | if (mask & TVIF_IMAGE)
|
---|
550 | wineItem->iImage = callback.item.iImage;
|
---|
551 |
|
---|
552 | if (mask & TVIF_SELECTEDIMAGE)
|
---|
553 | wineItem->iSelectedImage = callback.item.iSelectedImage;
|
---|
554 |
|
---|
555 | if (mask & TVIF_CHILDREN)
|
---|
556 | wineItem->cChildren = callback.item.cChildren;
|
---|
557 |
|
---|
558 | /* These members are now permanently set. */
|
---|
559 | if (callback.item.mask & TVIF_DI_SETITEM)
|
---|
560 | wineItem->callbackMask &= ~callback.item.mask;
|
---|
561 | }
|
---|
562 |
|
---|
563 | static VOID TREEVIEW_SendKeyDownNotify(TREEVIEW_INFO *infoPtr,UINT code,WORD wVKey)
|
---|
564 | {
|
---|
565 | NMTVKEYDOWN nmkdhdr;
|
---|
566 |
|
---|
567 | nmkdhdr.wVKey = wVKey;
|
---|
568 | nmkdhdr.flags = 0;
|
---|
569 |
|
---|
570 | sendNotify(infoPtr->hwnd,code,&nmkdhdr.hdr);
|
---|
571 | }
|
---|
572 |
|
---|
573 | /***************************************************************************
|
---|
574 | * This function uses cChildren field to decide whether the item has
|
---|
575 | * children or not.
|
---|
576 | * Note: if this returns TRUE, the child items may not actually exist,
|
---|
577 | * they could be virtual.
|
---|
578 | *
|
---|
579 | * Just use wineItem->firstChild to check for physical children.
|
---|
580 | */
|
---|
581 | static INT
|
---|
582 | TREEVIEW_HasChildren(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *wineItem)
|
---|
583 | {
|
---|
584 | TREEVIEW_UpdateDispInfo(infoPtr, wineItem, TVIF_CHILDREN);
|
---|
585 |
|
---|
586 | return wineItem->cChildren > 0;
|
---|
587 | }
|
---|
588 |
|
---|
589 | /* Item Position ********************************************************/
|
---|
590 |
|
---|
591 | static VOID
|
---|
592 | TREEVIEW_ComputeTextWidth(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item,HDC hDC,BOOL useFont)
|
---|
593 | {
|
---|
594 | HDC hdc;
|
---|
595 | HFONT hOldFont;
|
---|
596 | RECT rect;
|
---|
597 |
|
---|
598 | /* DRAW's OM docker creates items like this */
|
---|
599 | if (item->pszText == NULL)
|
---|
600 | {
|
---|
601 | item->textWidth = 0;
|
---|
602 | return;
|
---|
603 | }
|
---|
604 |
|
---|
605 | hdc = hDC ? hDC:GetDC(infoPtr->hwnd);
|
---|
606 | if (!hDC || !useFont) hOldFont = SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, item));
|
---|
607 |
|
---|
608 | SetRectEmpty(&rect);
|
---|
609 | DrawTextW (hdc,item->pszText,lstrlenW(item->pszText),&rect,DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_CALCRECT | DT_NOPREFIX);
|
---|
610 | item->textWidth = rect.right-rect.left;
|
---|
611 | item->textHeight = rect.bottom-rect.top;
|
---|
612 | item->rect.right = item->textOffset+item->textWidth+4;
|
---|
613 |
|
---|
614 | if (!hDC || !useFont) SelectObject(hdc, hOldFont);
|
---|
615 | if (!hDC) ReleaseDC(infoPtr->hwnd,hdc);
|
---|
616 | }
|
---|
617 |
|
---|
618 | static INT CALLBACK
|
---|
619 | TREEVIEW_ResetItemOrderVisible(LPVOID pItem, DWORD unused)
|
---|
620 | {
|
---|
621 | TREEVIEW_ITEM *item = (TREEVIEW_ITEM *)pItem;
|
---|
622 | (void)unused;
|
---|
623 |
|
---|
624 | item->displayOrder = -1;
|
---|
625 | item->displayed = FALSE;
|
---|
626 | item->inclient = FALSE;
|
---|
627 |
|
---|
628 | return 1;
|
---|
629 | }
|
---|
630 |
|
---|
631 | static VOID TREEVIEW_CalcItem(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item,HDC hdc)
|
---|
632 | {
|
---|
633 | TREEVIEW_UpdateDispInfo(infoPtr,item,TVIF_TEXT);
|
---|
634 | TREEVIEW_ComputeTextWidth(infoPtr,item,hdc,FALSE);
|
---|
635 | item->calculated = TRUE;
|
---|
636 | }
|
---|
637 |
|
---|
638 | static BOOL TREEVIEW_CalcItems(TREEVIEW_INFO *infoPtr)
|
---|
639 | {
|
---|
640 | TREEVIEW_ITEM *item;
|
---|
641 | int order = 0;
|
---|
642 | BOOL lar = ((infoPtr->dwStyle & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS)) > TVS_LINESATROOT);
|
---|
643 | HDC hdc = 0;
|
---|
644 | INT maxXScroll,maxYScroll;
|
---|
645 | INT xDiff,yDiff;
|
---|
646 | BOOL changedLeftTop = FALSE;
|
---|
647 | RECT rc;
|
---|
648 |
|
---|
649 | TREEVIEW_HideInfoTip(infoPtr);
|
---|
650 |
|
---|
651 | // 1) reset
|
---|
652 | infoPtr->treeWidth = 0;
|
---|
653 | infoPtr->treeHeight = 0;
|
---|
654 | GetClientRect(infoPtr->hwnd,&rc);
|
---|
655 | infoPtr->clientWidth = rc.right;
|
---|
656 | infoPtr->clientHeight = rc.bottom;
|
---|
657 | DPA_EnumCallback(infoPtr->items,TREEVIEW_ResetItemOrderVisible,(LPARAM)NULL);
|
---|
658 |
|
---|
659 | // 2) get order and tree height
|
---|
660 | infoPtr->firstVisible = NULL;
|
---|
661 | for (item = infoPtr->root->firstChild;item != NULL;item = TREEVIEW_GetNextListItem(infoPtr, item))
|
---|
662 | {
|
---|
663 | INT itemW;
|
---|
664 |
|
---|
665 | item->displayOrder = order;
|
---|
666 |
|
---|
667 | if ((infoPtr->uInternalStatus & TV_CALCALL) || !item->calculated)
|
---|
668 | {
|
---|
669 | if (!hdc) hdc = GetDC(infoPtr->hwnd);
|
---|
670 | TREEVIEW_CalcItem(infoPtr,item,hdc);
|
---|
671 | }
|
---|
672 |
|
---|
673 | //set internal metrics
|
---|
674 | item->linesOffset = infoPtr->uIndent * (item->iLevel + lar - 1) - infoPtr->lefttop.x;
|
---|
675 | item->stateOffset = item->linesOffset + infoPtr->uIndent;
|
---|
676 | item->imageOffset = item->stateOffset + (STATEIMAGEINDEX(item->state) ? infoPtr->stateImageWidth : 0);
|
---|
677 | item->textOffset = item->imageOffset + infoPtr->normalImageWidth;
|
---|
678 |
|
---|
679 | //set item rect
|
---|
680 | item->rect.top = infoPtr->uItemHeight*item->displayOrder-infoPtr->lefttop.y;
|
---|
681 | item->rect.bottom = item->rect.top+infoPtr->uItemHeight*item->iIntegral;
|
---|
682 | item->rect.left = item->stateOffset;
|
---|
683 | item->rect.right = item->textOffset+item->textWidth+4;
|
---|
684 | item->displayed = TRUE;
|
---|
685 | item->inclient = (((item->rect.top >= 0) || (item->rect.bottom >= 0)) && (item->rect.top < infoPtr->clientHeight));
|
---|
686 | if (!infoPtr->firstVisible && item->inclient) infoPtr->firstVisible = item;
|
---|
687 |
|
---|
688 | itemW = item->textOffset+item->textWidth+4+infoPtr->lefttop.x;
|
---|
689 | if (itemW > infoPtr->treeWidth)
|
---|
690 | infoPtr->treeWidth = itemW;
|
---|
691 |
|
---|
692 | infoPtr->treeHeight += item->rect.bottom-item->rect.top;
|
---|
693 |
|
---|
694 | order += item->iIntegral;
|
---|
695 | }
|
---|
696 | infoPtr->maxDisplayOrder = order;
|
---|
697 |
|
---|
698 | if (hdc) ReleaseDC(infoPtr->hwnd,hdc);
|
---|
699 | infoPtr->uInternalStatus &= ~TV_CALCALL;
|
---|
700 |
|
---|
701 | // 3) check lefttop
|
---|
702 | yDiff = xDiff = 0;
|
---|
703 |
|
---|
704 | maxYScroll = infoPtr->treeHeight-infoPtr->clientHeight;
|
---|
705 | if (maxYScroll < 0) maxYScroll = 0;
|
---|
706 | if (infoPtr->lefttop.y > maxYScroll)
|
---|
707 | {
|
---|
708 | INT mod = maxYScroll % infoPtr->uItemHeight;
|
---|
709 |
|
---|
710 | if (mod > 0) maxYScroll += infoPtr->uItemHeight-mod;
|
---|
711 | yDiff = infoPtr->lefttop.y-maxYScroll;
|
---|
712 | infoPtr->lefttop.y = maxYScroll;
|
---|
713 | }
|
---|
714 |
|
---|
715 | maxXScroll = infoPtr->treeWidth-infoPtr->clientWidth;
|
---|
716 | if (maxXScroll < 0) maxXScroll = 0;
|
---|
717 | if (infoPtr->lefttop.x > maxXScroll)
|
---|
718 | {
|
---|
719 | xDiff = infoPtr->lefttop.x-maxXScroll;
|
---|
720 | infoPtr->lefttop.x = maxXScroll;
|
---|
721 | }
|
---|
722 |
|
---|
723 | changedLeftTop = xDiff || yDiff;
|
---|
724 | if (changedLeftTop)
|
---|
725 | {
|
---|
726 | //update visible flag and position
|
---|
727 | infoPtr->firstVisible = NULL;
|
---|
728 | for (item = infoPtr->root->firstChild;item != NULL;item = TREEVIEW_GetNextListItem(infoPtr, item))
|
---|
729 | {
|
---|
730 | item->rect.top += yDiff;
|
---|
731 | item->rect.bottom += yDiff;
|
---|
732 | item->rect.left += xDiff;
|
---|
733 | item->rect.right += xDiff;
|
---|
734 | item->inclient = (((item->rect.top >= 0) || (item->rect.bottom >= 0)) && (item->rect.top < infoPtr->clientHeight));
|
---|
735 | if (!infoPtr->firstVisible && item->inclient) infoPtr->firstVisible = item;
|
---|
736 | item->linesOffset += xDiff;
|
---|
737 | item->stateOffset += xDiff;
|
---|
738 | item->imageOffset += xDiff;
|
---|
739 | item->textOffset += xDiff;
|
---|
740 | }
|
---|
741 | }
|
---|
742 |
|
---|
743 | // 4) set scrollbars
|
---|
744 | if (!(infoPtr->dwStyle & TVS_NOSCROLL) && (infoPtr->clientHeight > 0) && (infoPtr->clientWidth > 0))
|
---|
745 | {
|
---|
746 | if (infoPtr->treeHeight > infoPtr->clientHeight)
|
---|
747 | {
|
---|
748 | SCROLLINFO info;
|
---|
749 | INT visH = ((INT)(infoPtr->clientHeight/infoPtr->uItemHeight))*infoPtr->uItemHeight;
|
---|
750 |
|
---|
751 | info.cbSize = sizeof(info);
|
---|
752 | info.nMin = 0;
|
---|
753 | info.nMax = infoPtr->treeHeight-1;
|
---|
754 | info.nPos = infoPtr->lefttop.y;
|
---|
755 | info.nPage = visH;
|
---|
756 | info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
|
---|
757 | infoPtr->uInternalStatus |= TV_VSCROLL;
|
---|
758 | SetScrollInfo(infoPtr->hwnd,SB_VERT,&info,TRUE);
|
---|
759 | } else
|
---|
760 | {
|
---|
761 | if (infoPtr->uInternalStatus & TV_VSCROLL)
|
---|
762 | ShowScrollBar(infoPtr->hwnd,SB_VERT,FALSE);
|
---|
763 | infoPtr->uInternalStatus &= ~TV_VSCROLL;
|
---|
764 | }
|
---|
765 | if (!(infoPtr->dwStyle & TVS_NOHSCROLL) && (infoPtr->treeWidth > infoPtr->clientWidth))
|
---|
766 | {
|
---|
767 | SCROLLINFO info;
|
---|
768 |
|
---|
769 | info.cbSize = sizeof(info);
|
---|
770 | info.nMin = 0;
|
---|
771 | info.nMax = infoPtr->treeWidth-1;
|
---|
772 | info.nPos = infoPtr->lefttop.x;
|
---|
773 | info.nPage = MAX(infoPtr->clientWidth,1);
|
---|
774 | info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE;
|
---|
775 | infoPtr->uInternalStatus |= TV_HSCROLL;
|
---|
776 | SetScrollInfo(infoPtr->hwnd,SB_HORZ,&info,TRUE);
|
---|
777 | } else
|
---|
778 | {
|
---|
779 | if (infoPtr->uInternalStatus & TV_HSCROLL)
|
---|
780 | ShowScrollBar(infoPtr->hwnd,SB_HORZ,FALSE);
|
---|
781 | infoPtr->uInternalStatus &= ~TV_HSCROLL;
|
---|
782 | }
|
---|
783 | } else
|
---|
784 | {
|
---|
785 | if (infoPtr->uInternalStatus & (TV_VSCROLL | TV_HSCROLL))
|
---|
786 | ShowScrollBar(infoPtr->hwnd,SB_BOTH,FALSE);
|
---|
787 | infoPtr->uInternalStatus &= ~(TV_VSCROLL | TV_HSCROLL);
|
---|
788 | }
|
---|
789 |
|
---|
790 | infoPtr->dwStyle = GetWindowLongA(infoPtr->hwnd,GWL_STYLE);
|
---|
791 |
|
---|
792 | return changedLeftTop;
|
---|
793 | }
|
---|
794 |
|
---|
795 | static VOID TREEVIEW_MoveItems(TREEVIEW_INFO *infoPtr,INT xScroll,INT yScroll)
|
---|
796 | {
|
---|
797 | TREEVIEW_ITEM *item;
|
---|
798 |
|
---|
799 | infoPtr->firstVisible = NULL;
|
---|
800 | for (item = infoPtr->root->firstChild;item;item = TREEVIEW_GetNextListItem(infoPtr,item))
|
---|
801 | {
|
---|
802 | item->rect.top += yScroll;
|
---|
803 | item->rect.bottom += yScroll;
|
---|
804 | item->rect.left += xScroll;
|
---|
805 | item->rect.right += xScroll;
|
---|
806 | item->inclient = (((item->rect.top >= 0) || (item->rect.bottom >= 0)) && (item->rect.top < infoPtr->clientHeight));
|
---|
807 | if (!infoPtr->firstVisible && item->inclient) infoPtr->firstVisible = item;
|
---|
808 |
|
---|
809 | //set internal metrics
|
---|
810 | item->linesOffset += xScroll;
|
---|
811 | item->stateOffset += xScroll;
|
---|
812 | item->imageOffset += xScroll;
|
---|
813 | item->textOffset += xScroll;
|
---|
814 | }
|
---|
815 | }
|
---|
816 |
|
---|
817 | /* Item Allocation **********************************************************/
|
---|
818 |
|
---|
819 | static TREEVIEW_ITEM *
|
---|
820 | TREEVIEW_AllocateItem(TREEVIEW_INFO *infoPtr)
|
---|
821 | {
|
---|
822 | TREEVIEW_ITEM *newItem = (TREEVIEW_ITEM*)COMCTL32_Alloc(sizeof(TREEVIEW_ITEM));
|
---|
823 |
|
---|
824 | if (!newItem)
|
---|
825 | return NULL;
|
---|
826 |
|
---|
827 | ZeroMemory(newItem,sizeof(TREEVIEW_ITEM));
|
---|
828 | if (DPA_InsertPtr(infoPtr->items, INT_MAX, newItem) == -1)
|
---|
829 | {
|
---|
830 | COMCTL32_Free(newItem);
|
---|
831 | return NULL;
|
---|
832 | }
|
---|
833 |
|
---|
834 | return newItem;
|
---|
835 | }
|
---|
836 |
|
---|
837 | /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
|
---|
838 | * free item->pszText. */
|
---|
839 | static void
|
---|
840 | TREEVIEW_FreeItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
|
---|
841 | {
|
---|
842 | DPA_DeletePtr(infoPtr->items, DPA_GetPtrIndex(infoPtr->items, item));
|
---|
843 | COMCTL32_Free(item);
|
---|
844 | }
|
---|
845 |
|
---|
846 |
|
---|
847 | /* Item Insertion *******************************************************/
|
---|
848 |
|
---|
849 | /***************************************************************************
|
---|
850 | * This method inserts newItem before sibling as a child of parent.
|
---|
851 | * sibling can be NULL, but only if parent has no children.
|
---|
852 | */
|
---|
853 | static void
|
---|
854 | TREEVIEW_InsertBefore(TREEVIEW_ITEM *newItem, TREEVIEW_ITEM *sibling,
|
---|
855 | TREEVIEW_ITEM *parent)
|
---|
856 | {
|
---|
857 | assert(newItem != NULL);
|
---|
858 | assert(parent != NULL);
|
---|
859 |
|
---|
860 | if (sibling != NULL)
|
---|
861 | {
|
---|
862 | assert(sibling->parent == parent);
|
---|
863 |
|
---|
864 | if (sibling->prevSibling != NULL)
|
---|
865 | sibling->prevSibling->nextSibling = newItem;
|
---|
866 |
|
---|
867 | newItem->prevSibling = sibling->prevSibling;
|
---|
868 | sibling->prevSibling = newItem;
|
---|
869 | }
|
---|
870 |
|
---|
871 | newItem->nextSibling = sibling;
|
---|
872 |
|
---|
873 | if (parent->firstChild == sibling)
|
---|
874 | {
|
---|
875 | newItem->nextSibling = parent->firstChild;
|
---|
876 | parent->firstChild = newItem;
|
---|
877 | }
|
---|
878 |
|
---|
879 | if (parent->lastChild == NULL)
|
---|
880 | parent->lastChild = newItem;
|
---|
881 | }
|
---|
882 |
|
---|
883 | /***************************************************************************
|
---|
884 | * This method inserts newItem after sibling as a child of parent.
|
---|
885 | * sibling can be NULL, but only if parent has no children.
|
---|
886 | */
|
---|
887 | static void
|
---|
888 | TREEVIEW_InsertAfter(TREEVIEW_ITEM *newItem, TREEVIEW_ITEM *sibling,
|
---|
889 | TREEVIEW_ITEM *parent)
|
---|
890 | {
|
---|
891 | assert(newItem != NULL);
|
---|
892 | assert(parent != NULL);
|
---|
893 |
|
---|
894 | if (sibling != NULL)
|
---|
895 | {
|
---|
896 | assert(sibling->parent == parent);
|
---|
897 |
|
---|
898 | if (sibling->nextSibling != NULL)
|
---|
899 | sibling->nextSibling->prevSibling = newItem;
|
---|
900 |
|
---|
901 | newItem->nextSibling = sibling->nextSibling;
|
---|
902 | sibling->nextSibling = newItem;
|
---|
903 | }
|
---|
904 |
|
---|
905 | newItem->prevSibling = sibling;
|
---|
906 |
|
---|
907 | if (parent->lastChild == sibling)
|
---|
908 | {
|
---|
909 | newItem->prevSibling = parent->lastChild;
|
---|
910 | parent->lastChild = newItem;
|
---|
911 | }
|
---|
912 |
|
---|
913 | if (parent->firstChild == NULL)
|
---|
914 | parent->firstChild = newItem;
|
---|
915 | }
|
---|
916 |
|
---|
917 | static BOOL
|
---|
918 | TREEVIEW_DoSetItem(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *wineItem,const TVITEMEXW *tvItem,BOOL unicode,DWORD *changed = NULL)
|
---|
919 | {
|
---|
920 | UINT callbackClear = 0;
|
---|
921 | UINT callbackSet = 0;
|
---|
922 |
|
---|
923 | if (changed) *changed = 0;
|
---|
924 |
|
---|
925 | /* Do this first in case it fails. */
|
---|
926 |
|
---|
927 | if (tvItem->mask & TVIF_TEXT)
|
---|
928 | {
|
---|
929 | /*
|
---|
930 | * Setup the item text stuff here since it's required by the Sort method
|
---|
931 | * when the insertion are ordered
|
---|
932 | */
|
---|
933 | if (unicode)
|
---|
934 | {
|
---|
935 | if (tvItem->pszText != LPSTR_TEXTCALLBACKW)
|
---|
936 | {
|
---|
937 | INT len = lstrlenW(tvItem->pszText)+1;
|
---|
938 |
|
---|
939 | callbackClear |= TVIF_TEXT;
|
---|
940 |
|
---|
941 | if (changed && ((wineItem->callbackMask & LVIF_TEXT) || (lstrcmpW(wineItem->pszText,tvItem->pszText) != 0))) *changed |= TVIF_TEXT;
|
---|
942 | if (len > wineItem->cchTextMax)
|
---|
943 | {
|
---|
944 | LPWSTR newText = (WCHAR*)COMCTL32_ReAlloc(wineItem->pszText,len*sizeof(WCHAR));
|
---|
945 | if (newText == NULL) return FALSE;
|
---|
946 |
|
---|
947 | wineItem->pszText = newText;
|
---|
948 | wineItem->cchTextMax = len;
|
---|
949 | }
|
---|
950 | lstrcpyW (wineItem->pszText,tvItem->pszText);
|
---|
951 | } else
|
---|
952 | {
|
---|
953 | callbackSet |= TVIF_TEXT;
|
---|
954 |
|
---|
955 | wineItem->pszText = (WCHAR*)COMCTL32_ReAlloc(wineItem->pszText,TEXT_CALLBACK_SIZE*sizeof(WCHAR));
|
---|
956 | wineItem->cchTextMax = TEXT_CALLBACK_SIZE;
|
---|
957 | if (changed) *changed |= TVIF_TEXT;
|
---|
958 | }
|
---|
959 | } else
|
---|
960 | {
|
---|
961 | if ((LPSTR)tvItem->pszText != LPSTR_TEXTCALLBACKA)
|
---|
962 | {
|
---|
963 | INT len = lstrlenA((LPSTR)tvItem->pszText)+1;
|
---|
964 |
|
---|
965 | callbackClear |= TVIF_TEXT;
|
---|
966 |
|
---|
967 | if (changed && ((wineItem->callbackMask & LVIF_TEXT) || (lstrcmpAtoW((CHAR*)tvItem->pszText,wineItem->pszText) != 0))) *changed |= TVIF_TEXT;
|
---|
968 | if (len > wineItem->cchTextMax)
|
---|
969 | {
|
---|
970 | LPWSTR newText = (WCHAR*)COMCTL32_ReAlloc(wineItem->pszText,len*sizeof(WCHAR));
|
---|
971 | if (newText == NULL) return FALSE;
|
---|
972 |
|
---|
973 | wineItem->pszText = newText;
|
---|
974 | wineItem->cchTextMax = len;
|
---|
975 | }
|
---|
976 | lstrcpyAtoW (wineItem->pszText,(LPSTR)tvItem->pszText);
|
---|
977 | } else
|
---|
978 | {
|
---|
979 | callbackSet |= TVIF_TEXT;
|
---|
980 |
|
---|
981 | wineItem->pszText = (WCHAR*)COMCTL32_ReAlloc(wineItem->pszText,TEXT_CALLBACK_SIZE*sizeof(WCHAR));
|
---|
982 | wineItem->cchTextMax = TEXT_CALLBACK_SIZE;
|
---|
983 | if (changed) *changed |= TVIF_TEXT;
|
---|
984 | }
|
---|
985 | }
|
---|
986 | }
|
---|
987 |
|
---|
988 | if (tvItem->mask & TVIF_CHILDREN)
|
---|
989 | {
|
---|
990 | if (changed && (wineItem->cChildren != tvItem->cChildren)) *changed |= TVIF_CHILDREN;
|
---|
991 | wineItem->cChildren = tvItem->cChildren;
|
---|
992 |
|
---|
993 | if (wineItem->cChildren == I_CHILDRENCALLBACK)
|
---|
994 | callbackSet |= TVIF_CHILDREN;
|
---|
995 | else
|
---|
996 | callbackClear |= TVIF_CHILDREN;
|
---|
997 | }
|
---|
998 |
|
---|
999 | if (tvItem->mask & TVIF_IMAGE)
|
---|
1000 | {
|
---|
1001 | if (changed && (wineItem->iImage != tvItem->iImage)) *changed |= TVIF_IMAGE;
|
---|
1002 | wineItem->iImage = tvItem->iImage;
|
---|
1003 |
|
---|
1004 | if (wineItem->iImage == I_IMAGECALLBACK)
|
---|
1005 | callbackSet |= TVIF_IMAGE;
|
---|
1006 | else
|
---|
1007 | callbackClear |= TVIF_IMAGE;
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | if (tvItem->mask & TVIF_SELECTEDIMAGE)
|
---|
1011 | {
|
---|
1012 | if (changed && (wineItem->iSelectedImage != tvItem->iSelectedImage)) *changed |= TVIF_SELECTEDIMAGE;
|
---|
1013 | wineItem->iSelectedImage = tvItem->iSelectedImage;
|
---|
1014 |
|
---|
1015 | if (wineItem->iImage == I_IMAGECALLBACK)
|
---|
1016 | callbackSet |= TVIF_SELECTEDIMAGE;
|
---|
1017 | else
|
---|
1018 | callbackClear |= TVIF_SELECTEDIMAGE;
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | if (tvItem->mask & TVIF_PARAM)
|
---|
1022 | {
|
---|
1023 | if (changed && (wineItem->lParam != tvItem->lParam)) *changed |= TVIF_PARAM;
|
---|
1024 | wineItem->lParam = tvItem->lParam;
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | /* If the application sets TVIF_INTEGRAL without
|
---|
1028 | * supplying a TVITEMEX structure, it's toast. */
|
---|
1029 | if (tvItem->mask & TVIF_INTEGRAL)
|
---|
1030 | {
|
---|
1031 | if (changed && (wineItem->iIntegral != tvItem->iIntegral)) *changed |= TVIF_INTEGRAL;
|
---|
1032 | wineItem->iIntegral = tvItem->iIntegral;
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | if (tvItem->mask & TVIF_STATE)
|
---|
1036 | {
|
---|
1037 | DWORD oldState = wineItem->state;
|
---|
1038 |
|
---|
1039 | wineItem->state &= ~tvItem->stateMask;
|
---|
1040 | wineItem->state |= (tvItem->state & tvItem->stateMask);
|
---|
1041 | if (changed && (wineItem->state != oldState)) *changed |= TVIF_STATE;
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | wineItem->callbackMask |= callbackSet;
|
---|
1045 | wineItem->callbackMask &= ~callbackClear;
|
---|
1046 |
|
---|
1047 | return TRUE;
|
---|
1048 | }
|
---|
1049 |
|
---|
1050 | /* Note that the new item is pre-zeroed. */
|
---|
1051 | static LRESULT
|
---|
1052 | TREEVIEW_InsertItem(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam,BOOL unicode)
|
---|
1053 | {
|
---|
1054 | TVINSERTSTRUCTW *ptdi = (LPTVINSERTSTRUCTW)lParam;
|
---|
1055 | TVITEMEXW *tvItem;
|
---|
1056 | HTREEITEM insertAfter;
|
---|
1057 | INT x;
|
---|
1058 | TREEVIEW_ITEM *newItem, *parentItem;
|
---|
1059 |
|
---|
1060 | if (!ptdi) return NULL;
|
---|
1061 | tvItem = &ptdi->itemex;
|
---|
1062 |
|
---|
1063 | if (infoPtr->hwndEdit) SetFocus(infoPtr->hwnd);
|
---|
1064 |
|
---|
1065 | if ((ptdi->hParent == TVI_ROOT) || (ptdi->hParent == 0))
|
---|
1066 | {
|
---|
1067 | parentItem = infoPtr->root;
|
---|
1068 | } else
|
---|
1069 | {
|
---|
1070 | parentItem = ptdi->hParent;
|
---|
1071 |
|
---|
1072 | if (!TREEVIEW_ValidItem(infoPtr,parentItem))
|
---|
1073 | {
|
---|
1074 | //dprintf(("invalid parent %p\n",parentItem));
|
---|
1075 |
|
---|
1076 | return (LRESULT)(HTREEITEM)NULL;
|
---|
1077 | }
|
---|
1078 | }
|
---|
1079 |
|
---|
1080 | insertAfter = ptdi->hInsertAfter;
|
---|
1081 |
|
---|
1082 | /* Validate this now for convenience. */
|
---|
1083 | if ((insertAfter != TVI_FIRST) && (insertAfter != TVI_LAST) && (insertAfter != TVI_SORT))
|
---|
1084 | {
|
---|
1085 | if (!TREEVIEW_ValidItem(infoPtr,insertAfter))
|
---|
1086 | {
|
---|
1087 | //dprintf(("invalid insert after %p\n",insertAfter));
|
---|
1088 | insertAfter = TVI_LAST;
|
---|
1089 | } else if (parentItem != insertAfter->parent)
|
---|
1090 | {
|
---|
1091 | //dprintf(("invalid insert after parent %p %p %p",insertAfter,insertAfter->parent,parentItem));
|
---|
1092 | //CB: Verified with AMD cpuid 2.04 (there are other strange things...)
|
---|
1093 | insertAfter = parentItem->lastChild;
|
---|
1094 | }
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | //TRACE("parent %p position %p: %s\n", parentItem, insertAfter,
|
---|
1098 | // (tvItem->mask & TVIF_TEXT)
|
---|
1099 | // ? ((tvItem->pszText == LPSTR_TEXTCALLBACKA) ? "<callback>"
|
---|
1100 | // : tvItem->pszText)
|
---|
1101 | // : "<no label>");
|
---|
1102 |
|
---|
1103 | newItem = TREEVIEW_AllocateItem(infoPtr);
|
---|
1104 | if (newItem == NULL)
|
---|
1105 | return (LRESULT)(HTREEITEM)NULL;
|
---|
1106 |
|
---|
1107 | newItem->parent = parentItem;
|
---|
1108 | newItem->iIntegral = 1;
|
---|
1109 |
|
---|
1110 | if (!TREEVIEW_DoSetItem(infoPtr,newItem,tvItem,unicode))
|
---|
1111 | return (LRESULT)(HTREEITEM)NULL;
|
---|
1112 |
|
---|
1113 | /* After this point, nothing can fail. (Except for TVI_SORT.) */
|
---|
1114 |
|
---|
1115 | infoPtr->uNumItems++;
|
---|
1116 |
|
---|
1117 | if (insertAfter == TVI_FIRST)
|
---|
1118 | {
|
---|
1119 | TREEVIEW_InsertBefore(newItem, parentItem->firstChild, parentItem);
|
---|
1120 | } else if (insertAfter == TVI_LAST)
|
---|
1121 | {
|
---|
1122 | TREEVIEW_InsertAfter(newItem, parentItem->lastChild, parentItem);
|
---|
1123 | } else if (insertAfter == TVI_SORT)
|
---|
1124 | {
|
---|
1125 | TREEVIEW_ITEM *aChild;
|
---|
1126 | TREEVIEW_ITEM *previousChild = NULL;
|
---|
1127 | BOOL bItemInserted = FALSE;
|
---|
1128 |
|
---|
1129 | aChild = parentItem->firstChild;
|
---|
1130 |
|
---|
1131 | TREEVIEW_UpdateDispInfo(infoPtr, newItem, TVIF_TEXT);
|
---|
1132 |
|
---|
1133 | /* Iterate the parent children to see where we fit in */
|
---|
1134 | while (aChild)
|
---|
1135 | {
|
---|
1136 | INT comp;
|
---|
1137 |
|
---|
1138 | TREEVIEW_UpdateDispInfo(infoPtr,aChild,TVIF_TEXT);
|
---|
1139 | comp = lstrcmpW(newItem->pszText,aChild->pszText);
|
---|
1140 |
|
---|
1141 | if (comp < 0) /* we are smaller than the current one */
|
---|
1142 | {
|
---|
1143 | TREEVIEW_InsertBefore(newItem, aChild, parentItem);
|
---|
1144 | bItemInserted = TRUE;
|
---|
1145 | break;
|
---|
1146 | }
|
---|
1147 | else if (comp > 0) /* we are bigger than the current one */
|
---|
1148 | {
|
---|
1149 | previousChild = aChild;
|
---|
1150 | aChild = (aChild->nextSibling == 0) /* This will help us to exit */
|
---|
1151 | ? NULL /* if there is no more sibling */
|
---|
1152 | : aChild->nextSibling;
|
---|
1153 |
|
---|
1154 | /* Look at the next item */
|
---|
1155 | continue;
|
---|
1156 | }
|
---|
1157 | else if (comp == 0)
|
---|
1158 | {
|
---|
1159 | /*
|
---|
1160 | * An item with this name is already existing, therefore,
|
---|
1161 | * we add after the one we found
|
---|
1162 | */
|
---|
1163 | TREEVIEW_InsertAfter(newItem, aChild, parentItem);
|
---|
1164 | bItemInserted = TRUE;
|
---|
1165 | break;
|
---|
1166 | }
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | /*
|
---|
1170 | * we reach the end of the child list and the item as not
|
---|
1171 | * yet been inserted, therefore, insert it after the last child.
|
---|
1172 | */
|
---|
1173 | if ((!bItemInserted) && (aChild == NULL))
|
---|
1174 | TREEVIEW_InsertAfter(newItem, previousChild, parentItem);
|
---|
1175 | } else
|
---|
1176 | {
|
---|
1177 | /* hInsertAfter names a specific item we want to insert after */
|
---|
1178 | TREEVIEW_InsertAfter(newItem,insertAfter,parentItem);
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | //TRACE("new item %p; parent %p, mask %x\n", newItem,
|
---|
1182 | // newItem->parent, tvItem->mask);
|
---|
1183 |
|
---|
1184 | newItem->iLevel = newItem->parent->iLevel + 1;
|
---|
1185 |
|
---|
1186 | if (newItem->parent->cChildren == 0)
|
---|
1187 | newItem->parent->cChildren = 1;
|
---|
1188 |
|
---|
1189 | if (infoPtr->dwStyle & TVS_CHECKBOXES)
|
---|
1190 | {
|
---|
1191 | if (STATEIMAGEINDEX(newItem->state) == 0)
|
---|
1192 | newItem->state |= INDEXTOSTATEIMAGEMASK(1);
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | TREEVIEW_VerifyTree(infoPtr);
|
---|
1196 |
|
---|
1197 | newItem->calculated = FALSE;
|
---|
1198 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
1199 |
|
---|
1200 | return (LRESULT)newItem;
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | /* Item Deletion ************************************************************/
|
---|
1204 | static void
|
---|
1205 | TREEVIEW_RemoveItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem);
|
---|
1206 |
|
---|
1207 | static void
|
---|
1208 | TREEVIEW_RemoveAllChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *parentItem)
|
---|
1209 | {
|
---|
1210 | TREEVIEW_ITEM *kill = parentItem->firstChild;
|
---|
1211 |
|
---|
1212 | while (kill != NULL)
|
---|
1213 | {
|
---|
1214 | TREEVIEW_ITEM *next = kill->nextSibling;
|
---|
1215 |
|
---|
1216 | TREEVIEW_RemoveItem(infoPtr, kill);
|
---|
1217 |
|
---|
1218 | kill = next;
|
---|
1219 | }
|
---|
1220 |
|
---|
1221 | assert(parentItem->cChildren <= 0); /* I_CHILDRENCALLBACK or 0 */
|
---|
1222 | assert(parentItem->firstChild == NULL);
|
---|
1223 | assert(parentItem->lastChild == NULL);
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | static void
|
---|
1227 | TREEVIEW_UnlinkItem(TREEVIEW_ITEM *item)
|
---|
1228 | {
|
---|
1229 | TREEVIEW_ITEM *parentItem = item->parent;
|
---|
1230 |
|
---|
1231 | assert(item != NULL);
|
---|
1232 | assert(item->parent != NULL); /* i.e. it must not be the root */
|
---|
1233 |
|
---|
1234 | if (parentItem->firstChild == item)
|
---|
1235 | parentItem->firstChild = item->nextSibling;
|
---|
1236 |
|
---|
1237 | if (parentItem->lastChild == item)
|
---|
1238 | parentItem->lastChild = item->prevSibling;
|
---|
1239 |
|
---|
1240 | if (parentItem->firstChild == NULL && parentItem->lastChild == NULL
|
---|
1241 | && parentItem->cChildren > 0)
|
---|
1242 | parentItem->cChildren = 0;
|
---|
1243 |
|
---|
1244 | if (item->prevSibling)
|
---|
1245 | item->prevSibling->nextSibling = item->nextSibling;
|
---|
1246 |
|
---|
1247 | if (item->nextSibling)
|
---|
1248 | item->nextSibling->prevSibling = item->prevSibling;
|
---|
1249 | }
|
---|
1250 |
|
---|
1251 | static void
|
---|
1252 | TREEVIEW_RemoveItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
|
---|
1253 | {
|
---|
1254 | TREEVIEW_ITEM *newFirstVisible;
|
---|
1255 |
|
---|
1256 | //TRACE("%p, (%s)\n", wineItem, TREEVIEW_ItemName(wineItem));
|
---|
1257 |
|
---|
1258 | TREEVIEW_SendTreeviewNotify(infoPtr,isUnicodeNotify(&infoPtr->header) ? TVN_DELETEITEMW:TVN_DELETEITEMA,TVIF_HANDLE | TVIF_PARAM,0,wineItem,0);
|
---|
1259 |
|
---|
1260 | if (wineItem->firstChild)
|
---|
1261 | TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
|
---|
1262 |
|
---|
1263 | /* Selection is handled in TREEVIEW_DeleteItem. */
|
---|
1264 |
|
---|
1265 | if (infoPtr->insertMarkItem == wineItem)
|
---|
1266 | infoPtr->insertMarkItem = NULL;
|
---|
1267 |
|
---|
1268 | /* XXX focusItem, hotItem, dropItem */
|
---|
1269 |
|
---|
1270 | TREEVIEW_UnlinkItem(wineItem);
|
---|
1271 |
|
---|
1272 | infoPtr->uNumItems--;
|
---|
1273 |
|
---|
1274 | if (wineItem->pszText != LPSTR_TEXTCALLBACKW)
|
---|
1275 | COMCTL32_Free(wineItem->pszText);
|
---|
1276 |
|
---|
1277 | TREEVIEW_FreeItem(infoPtr, wineItem);
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 |
|
---|
1281 | /* Empty out the tree. */
|
---|
1282 | static void
|
---|
1283 | TREEVIEW_RemoveTree(TREEVIEW_INFO *infoPtr)
|
---|
1284 | {
|
---|
1285 | TREEVIEW_RemoveAllChildren(infoPtr, infoPtr->root);
|
---|
1286 |
|
---|
1287 | assert(infoPtr->uNumItems == 0); /* root isn't counted in uNumItems */
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | static LRESULT
|
---|
1291 | TREEVIEW_DeleteItem(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1292 | {
|
---|
1293 | TREEVIEW_ITEM *oldSelection = infoPtr->selectedItem;
|
---|
1294 | TREEVIEW_ITEM *newSelection = NULL;
|
---|
1295 |
|
---|
1296 | if (lParam == (LPARAM)TVI_ROOT)
|
---|
1297 | {
|
---|
1298 | newSelection = NULL;
|
---|
1299 | TREEVIEW_RemoveTree(infoPtr);
|
---|
1300 | }
|
---|
1301 | else
|
---|
1302 | {
|
---|
1303 | TREEVIEW_ITEM *wineItem = (TREEVIEW_ITEM *)lParam;
|
---|
1304 |
|
---|
1305 | if (!TREEVIEW_ValidItem(infoPtr, wineItem))
|
---|
1306 | return FALSE;
|
---|
1307 |
|
---|
1308 | //TRACE("%p (%s)\n", wineItem, TREEVIEW_ItemName(wineItem));
|
---|
1309 |
|
---|
1310 | if (infoPtr->selectedItem != NULL
|
---|
1311 | && (wineItem == infoPtr->selectedItem
|
---|
1312 | || TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem)))
|
---|
1313 | {
|
---|
1314 | if (wineItem->nextSibling)
|
---|
1315 | newSelection = wineItem->nextSibling;
|
---|
1316 | else if (wineItem->parent != infoPtr->root)
|
---|
1317 | newSelection = wineItem->parent;
|
---|
1318 | }
|
---|
1319 |
|
---|
1320 | TREEVIEW_RemoveItem(infoPtr, wineItem);
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 | /* Don't change if somebody else already has. */
|
---|
1324 | if (oldSelection == infoPtr->selectedItem
|
---|
1325 | && TREEVIEW_ValidItem(infoPtr, newSelection))
|
---|
1326 | {
|
---|
1327 | TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, newSelection, TVC_UNKNOWN);
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | TREEVIEW_VerifyTree(infoPtr);
|
---|
1331 |
|
---|
1332 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
1333 |
|
---|
1334 | return TRUE;
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | /* Get/Set Messages *********************************************************/
|
---|
1338 |
|
---|
1339 | static LRESULT
|
---|
1340 | TREEVIEW_GetIndent(TREEVIEW_INFO *infoPtr)
|
---|
1341 | {
|
---|
1342 | return infoPtr->uIndent;
|
---|
1343 | }
|
---|
1344 |
|
---|
1345 | static LRESULT
|
---|
1346 | TREEVIEW_SetIndent(TREEVIEW_INFO *infoPtr, WPARAM wParam)
|
---|
1347 | {
|
---|
1348 | INT newIndent;
|
---|
1349 |
|
---|
1350 | newIndent = (INT)wParam;
|
---|
1351 | if (newIndent < MINIMUM_INDENT)
|
---|
1352 | newIndent = MINIMUM_INDENT;
|
---|
1353 |
|
---|
1354 | if (infoPtr->uIndent != newIndent)
|
---|
1355 | {
|
---|
1356 | infoPtr->uIndent = newIndent;
|
---|
1357 |
|
---|
1358 | infoPtr->uInternalStatus |= TV_CALCALL;
|
---|
1359 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | return 0;
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 | static LRESULT
|
---|
1366 | TREEVIEW_GetToolTips(TREEVIEW_INFO *infoPtr)
|
---|
1367 | {
|
---|
1368 | return infoPtr->hwndToolTip;
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | static LRESULT
|
---|
1372 | TREEVIEW_SetToolTips(TREEVIEW_INFO *infoPtr, WPARAM wParam)
|
---|
1373 | {
|
---|
1374 | HWND prevToolTip;
|
---|
1375 |
|
---|
1376 | prevToolTip = infoPtr->hwndToolTip;
|
---|
1377 | infoPtr->hwndToolTip = (HWND)wParam;
|
---|
1378 |
|
---|
1379 | return prevToolTip;
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | static LRESULT
|
---|
1383 | TREEVIEW_GetScrollTime(TREEVIEW_INFO *infoPtr)
|
---|
1384 | {
|
---|
1385 | return infoPtr->uScrollTime;
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | static LRESULT
|
---|
1389 | TREEVIEW_SetScrollTime(TREEVIEW_INFO *infoPtr, UINT uScrollTime)
|
---|
1390 | {
|
---|
1391 | UINT uOldScrollTime = infoPtr->uScrollTime;
|
---|
1392 |
|
---|
1393 | infoPtr->uScrollTime = min(uScrollTime, 100);
|
---|
1394 |
|
---|
1395 | return uOldScrollTime;
|
---|
1396 | }
|
---|
1397 |
|
---|
1398 |
|
---|
1399 | static LRESULT
|
---|
1400 | TREEVIEW_GetImageList(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1401 | {
|
---|
1402 | switch (wParam)
|
---|
1403 | {
|
---|
1404 | case (WPARAM)TVSIL_NORMAL:
|
---|
1405 | return (LRESULT)infoPtr->himlNormal;
|
---|
1406 |
|
---|
1407 | case (WPARAM)TVSIL_STATE:
|
---|
1408 | return (LRESULT)infoPtr->himlState;
|
---|
1409 |
|
---|
1410 | default:
|
---|
1411 | return 0;
|
---|
1412 | }
|
---|
1413 | }
|
---|
1414 |
|
---|
1415 | static LRESULT
|
---|
1416 | TREEVIEW_SetImageList(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1417 | {
|
---|
1418 | HIMAGELIST himlNew = (HIMAGELIST)lParam;
|
---|
1419 | HIMAGELIST himlOld = 0;
|
---|
1420 |
|
---|
1421 | switch (wParam)
|
---|
1422 | {
|
---|
1423 | case (WPARAM)TVSIL_NORMAL:
|
---|
1424 | himlOld = infoPtr->himlNormal;
|
---|
1425 | infoPtr->himlNormal = himlNew;
|
---|
1426 |
|
---|
1427 | if (himlNew != NULL)
|
---|
1428 | ImageList_GetIconSize(himlNew, &infoPtr->normalImageWidth,
|
---|
1429 | &infoPtr->normalImageHeight);
|
---|
1430 | else
|
---|
1431 | {
|
---|
1432 | infoPtr->normalImageWidth = 0;
|
---|
1433 | infoPtr->normalImageHeight = 0;
|
---|
1434 | }
|
---|
1435 |
|
---|
1436 | break;
|
---|
1437 |
|
---|
1438 | case (WPARAM)TVSIL_STATE:
|
---|
1439 | himlOld = infoPtr->himlState;
|
---|
1440 | infoPtr->himlState = himlNew;
|
---|
1441 |
|
---|
1442 | if (himlNew != NULL)
|
---|
1443 | ImageList_GetIconSize(himlNew, &infoPtr->stateImageWidth,
|
---|
1444 | &infoPtr->stateImageHeight);
|
---|
1445 | else
|
---|
1446 | {
|
---|
1447 | infoPtr->stateImageWidth = 0;
|
---|
1448 | infoPtr->stateImageHeight = 0;
|
---|
1449 | }
|
---|
1450 |
|
---|
1451 | break;
|
---|
1452 | }
|
---|
1453 |
|
---|
1454 | infoPtr->uInternalStatus |= TV_CALCALL;
|
---|
1455 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
1456 |
|
---|
1457 | return (LRESULT)himlOld;
|
---|
1458 | }
|
---|
1459 |
|
---|
1460 | /* Compute the natural height (based on the font size) for items. */
|
---|
1461 | static UINT
|
---|
1462 | TREEVIEW_NaturalHeight(TREEVIEW_INFO *infoPtr)
|
---|
1463 | {
|
---|
1464 | TEXTMETRICA tm;
|
---|
1465 | HDC hdc = GetDC(infoPtr->hwnd);
|
---|
1466 | HFONT hOldFont = SelectObject(hdc, infoPtr->hFont);
|
---|
1467 | INT height;
|
---|
1468 |
|
---|
1469 | GetTextMetricsA(hdc, &tm);
|
---|
1470 |
|
---|
1471 | SelectObject(hdc, hOldFont);
|
---|
1472 | ReleaseDC(infoPtr->hwnd, hdc);
|
---|
1473 |
|
---|
1474 | /* The 16 is a hack because our fonts are tiny. */
|
---|
1475 | height = MAX(16, tm.tmHeight + tm.tmExternalLeading);
|
---|
1476 | if (!(infoPtr->dwStyle & TVS_NONEVENHEIGHT))
|
---|
1477 | if (height & 0x1) height++; //important for PS_DOT pen!
|
---|
1478 |
|
---|
1479 | return height;
|
---|
1480 | }
|
---|
1481 |
|
---|
1482 | static LRESULT
|
---|
1483 | TREEVIEW_SetItemHeight(TREEVIEW_INFO *infoPtr, WPARAM wParam)
|
---|
1484 | {
|
---|
1485 | INT prevHeight = infoPtr->uItemHeight;
|
---|
1486 |
|
---|
1487 | if (wParam == (WPARAM)(SHORT)-1)
|
---|
1488 | {
|
---|
1489 | infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
|
---|
1490 | infoPtr->bHeightSet = FALSE;
|
---|
1491 | }
|
---|
1492 | else
|
---|
1493 | {
|
---|
1494 | infoPtr->uItemHeight = wParam;
|
---|
1495 | infoPtr->bHeightSet = TRUE;
|
---|
1496 | }
|
---|
1497 |
|
---|
1498 | if (!(infoPtr->dwStyle & TVS_NONEVENHEIGHT))
|
---|
1499 | if (infoPtr->uItemHeight & 0x1) infoPtr->uItemHeight++;
|
---|
1500 |
|
---|
1501 | if (infoPtr->uItemHeight != prevHeight)
|
---|
1502 | {
|
---|
1503 | infoPtr->uInternalStatus |= TV_CALCALL;
|
---|
1504 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
1505 | }
|
---|
1506 |
|
---|
1507 | return prevHeight;
|
---|
1508 | }
|
---|
1509 |
|
---|
1510 | static LRESULT
|
---|
1511 | TREEVIEW_GetItemHeight(TREEVIEW_INFO *infoPtr)
|
---|
1512 | {
|
---|
1513 | return infoPtr->uItemHeight;
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 |
|
---|
1517 | static LRESULT
|
---|
1518 | TREEVIEW_GetFont(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1519 | {
|
---|
1520 | return infoPtr->hFont;
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | static LRESULT
|
---|
1524 | TREEVIEW_SetFont(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1525 | {
|
---|
1526 | infoPtr->hFont = wParam ? (HFONT)wParam : GetStockObject(SYSTEM_FONT);
|
---|
1527 |
|
---|
1528 | DeleteObject(infoPtr->hBoldFont);
|
---|
1529 | infoPtr->hBoldFont = TREEVIEW_CreateBoldFont(infoPtr->hFont);
|
---|
1530 |
|
---|
1531 | if (!infoPtr->bHeightSet)
|
---|
1532 | infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
|
---|
1533 |
|
---|
1534 | SendMessageA(infoPtr->hwndToolTip,WM_SETFONT,infoPtr->hFont,1);
|
---|
1535 | infoPtr->uInternalStatus |= TV_CALCALL;
|
---|
1536 | TREEVIEW_CalcItems(infoPtr);
|
---|
1537 |
|
---|
1538 | if (lParam)
|
---|
1539 | {
|
---|
1540 | TREEVIEW_UnqueueRefresh(infoPtr,FALSE,FALSE);
|
---|
1541 | TREEVIEW_Refresh(infoPtr);
|
---|
1542 | }
|
---|
1543 |
|
---|
1544 | return 0;
|
---|
1545 | }
|
---|
1546 |
|
---|
1547 |
|
---|
1548 | static LRESULT
|
---|
1549 | TREEVIEW_GetLineColor(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1550 | {
|
---|
1551 | return (LRESULT)infoPtr->clrLine;
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 | static LRESULT
|
---|
1555 | TREEVIEW_SetLineColor(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1556 | {
|
---|
1557 | COLORREF prevColor = infoPtr->clrLine;
|
---|
1558 |
|
---|
1559 | infoPtr->clrLine = (COLORREF)lParam;
|
---|
1560 |
|
---|
1561 | return (LRESULT)prevColor;
|
---|
1562 | }
|
---|
1563 |
|
---|
1564 |
|
---|
1565 | static LRESULT
|
---|
1566 | TREEVIEW_GetTextColor(TREEVIEW_INFO *infoPtr)
|
---|
1567 | {
|
---|
1568 | return (LRESULT)infoPtr->clrText;
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 | static LRESULT
|
---|
1572 | TREEVIEW_SetTextColor(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1573 | {
|
---|
1574 | COLORREF prevColor = infoPtr->clrText;
|
---|
1575 |
|
---|
1576 | infoPtr->clrText = (COLORREF)lParam;
|
---|
1577 |
|
---|
1578 | if (infoPtr->clrText != prevColor)
|
---|
1579 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
1580 |
|
---|
1581 | return (LRESULT)prevColor;
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 |
|
---|
1585 | static LRESULT
|
---|
1586 | TREEVIEW_GetBkColor(TREEVIEW_INFO *infoPtr)
|
---|
1587 | {
|
---|
1588 | return (LRESULT)infoPtr->clrBk;
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 | static LRESULT
|
---|
1592 | TREEVIEW_SetBkColor(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1593 | {
|
---|
1594 | COLORREF prevColor = infoPtr->clrBk;
|
---|
1595 |
|
---|
1596 | infoPtr->clrBk = (COLORREF)lParam;
|
---|
1597 |
|
---|
1598 | if (infoPtr->clrBk != prevColor)
|
---|
1599 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
1600 |
|
---|
1601 | return (LRESULT)prevColor;
|
---|
1602 | }
|
---|
1603 |
|
---|
1604 |
|
---|
1605 | static LRESULT
|
---|
1606 | TREEVIEW_GetInsertMarkColor(TREEVIEW_INFO *infoPtr, WPARAM wParam,
|
---|
1607 | LPARAM lParam)
|
---|
1608 | {
|
---|
1609 | return (LRESULT)infoPtr->clrInsertMark;
|
---|
1610 | }
|
---|
1611 |
|
---|
1612 | static LRESULT
|
---|
1613 | TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO *infoPtr, WPARAM wParam,
|
---|
1614 | LPARAM lParam)
|
---|
1615 | {
|
---|
1616 | COLORREF prevColor = infoPtr->clrInsertMark;
|
---|
1617 |
|
---|
1618 | infoPtr->clrInsertMark = (COLORREF)lParam;
|
---|
1619 |
|
---|
1620 | return (LRESULT)prevColor;
|
---|
1621 | }
|
---|
1622 |
|
---|
1623 |
|
---|
1624 | static LRESULT
|
---|
1625 | TREEVIEW_SetInsertMark(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1626 | {
|
---|
1627 | if (!TREEVIEW_ValidItem(infoPtr, (HTREEITEM)lParam))
|
---|
1628 | return 0;
|
---|
1629 |
|
---|
1630 | infoPtr->insertBeforeorAfter = (BOOL)wParam;
|
---|
1631 | infoPtr->insertMarkItem = (HTREEITEM)lParam;
|
---|
1632 |
|
---|
1633 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
1634 |
|
---|
1635 | return 1;
|
---|
1636 | }
|
---|
1637 |
|
---|
1638 | /************************************************************************
|
---|
1639 | * Some serious braindamage here. lParam is a pointer to both the
|
---|
1640 | * input HTREEITEM and the output RECT.
|
---|
1641 | */
|
---|
1642 | static LRESULT
|
---|
1643 | TREEVIEW_GetItemRect(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1644 | {
|
---|
1645 | TREEVIEW_ITEM *wineItem;
|
---|
1646 | const HTREEITEM *pItem = (HTREEITEM *)lParam;
|
---|
1647 | LPRECT lpRect = (LPRECT)lParam;
|
---|
1648 |
|
---|
1649 | /*
|
---|
1650 | * validate parameters
|
---|
1651 | */
|
---|
1652 | if ((pItem == NULL) || (lpRect == NULL))
|
---|
1653 | return FALSE;
|
---|
1654 |
|
---|
1655 | TREEVIEW_UnqueueRefresh(infoPtr,TRUE,TRUE);
|
---|
1656 |
|
---|
1657 | wineItem = *pItem;
|
---|
1658 | if (!TREEVIEW_ValidItem(infoPtr, *pItem) || !wineItem->displayed)
|
---|
1659 | return FALSE;
|
---|
1660 |
|
---|
1661 | if (!wineItem->calculated)
|
---|
1662 | TREEVIEW_CalcItem(infoPtr,wineItem,(HDC)0);
|
---|
1663 |
|
---|
1664 | /*
|
---|
1665 | * If wParam is TRUE return the text size otherwise return
|
---|
1666 | * the whole item size
|
---|
1667 | */
|
---|
1668 | if (wParam)
|
---|
1669 | {
|
---|
1670 | /* Windows does not send TVN_GETDISPINFO here. */
|
---|
1671 |
|
---|
1672 | lpRect->top = wineItem->rect.top;
|
---|
1673 | lpRect->bottom = wineItem->rect.bottom;
|
---|
1674 |
|
---|
1675 | lpRect->left = wineItem->textOffset;
|
---|
1676 | lpRect->right = wineItem->textOffset+wineItem->textWidth+4;
|
---|
1677 | }
|
---|
1678 | else
|
---|
1679 | {
|
---|
1680 | *lpRect = wineItem->rect;
|
---|
1681 | }
|
---|
1682 |
|
---|
1683 | return TRUE;
|
---|
1684 | }
|
---|
1685 |
|
---|
1686 | static inline LRESULT
|
---|
1687 | TREEVIEW_GetVisibleCount(TREEVIEW_INFO *infoPtr)
|
---|
1688 | {
|
---|
1689 | /* Suprise! This does not take integral height into account. */
|
---|
1690 | return infoPtr->clientHeight / infoPtr->uItemHeight;
|
---|
1691 | }
|
---|
1692 |
|
---|
1693 | static LRESULT
|
---|
1694 | TREEVIEW_GetItem(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam,BOOL unicode)
|
---|
1695 | {
|
---|
1696 | LPTVITEMEXW tvItem;
|
---|
1697 | TREEVIEW_ITEM *wineItem;
|
---|
1698 |
|
---|
1699 | tvItem = (LPTVITEMEXW)lParam;
|
---|
1700 |
|
---|
1701 | wineItem = tvItem->hItem;
|
---|
1702 |
|
---|
1703 | if (!TREEVIEW_ValidItem(infoPtr, wineItem))
|
---|
1704 | return FALSE;
|
---|
1705 |
|
---|
1706 | TREEVIEW_UpdateDispInfo(infoPtr, wineItem, tvItem->mask);
|
---|
1707 |
|
---|
1708 | if (tvItem->mask & TVIF_CHILDREN)
|
---|
1709 | tvItem->cChildren = wineItem->cChildren;
|
---|
1710 |
|
---|
1711 | if (tvItem->mask & TVIF_HANDLE)
|
---|
1712 | tvItem->hItem = wineItem;
|
---|
1713 |
|
---|
1714 | if (tvItem->mask & TVIF_IMAGE)
|
---|
1715 | tvItem->iImage = wineItem->iImage;
|
---|
1716 |
|
---|
1717 | if (tvItem->mask & TVIF_INTEGRAL)
|
---|
1718 | tvItem->iIntegral = wineItem->iIntegral;
|
---|
1719 |
|
---|
1720 | /* undocumented: windows ignores TVIF_PARAM and
|
---|
1721 | * * always sets lParam
|
---|
1722 | */
|
---|
1723 | tvItem->lParam = wineItem->lParam;
|
---|
1724 |
|
---|
1725 | if (tvItem->mask & TVIF_SELECTEDIMAGE)
|
---|
1726 | tvItem->iSelectedImage = wineItem->iSelectedImage;
|
---|
1727 |
|
---|
1728 | if (tvItem->mask & TVIF_STATE)
|
---|
1729 | tvItem->state = wineItem->state & tvItem->stateMask;
|
---|
1730 |
|
---|
1731 | if (tvItem->mask & TVIF_TEXT)
|
---|
1732 | {
|
---|
1733 | if (unicode)
|
---|
1734 | lstrcpynW(tvItem->pszText,wineItem->pszText,tvItem->cchTextMax);
|
---|
1735 | else
|
---|
1736 | lstrcpynWtoA((CHAR*)tvItem->pszText,wineItem->pszText,tvItem->cchTextMax);
|
---|
1737 | }
|
---|
1738 |
|
---|
1739 | return TRUE;
|
---|
1740 | }
|
---|
1741 |
|
---|
1742 | /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
|
---|
1743 | * which is wrong. */
|
---|
1744 | static LRESULT
|
---|
1745 | TREEVIEW_SetItem(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam,BOOL unicode)
|
---|
1746 | {
|
---|
1747 | TREEVIEW_ITEM *wineItem;
|
---|
1748 | TVITEMEXW *tvItem;
|
---|
1749 | DWORD changed = 0;
|
---|
1750 |
|
---|
1751 | if (infoPtr->hwndEdit) SetFocus(infoPtr->hwnd);
|
---|
1752 |
|
---|
1753 | tvItem = (LPTVITEMEXW)lParam;
|
---|
1754 | wineItem = tvItem->hItem;
|
---|
1755 |
|
---|
1756 | if (!TREEVIEW_ValidItem(infoPtr, wineItem))
|
---|
1757 | return FALSE;
|
---|
1758 |
|
---|
1759 | if (!TREEVIEW_DoSetItem(infoPtr,wineItem,tvItem,unicode,&changed))
|
---|
1760 | return FALSE;
|
---|
1761 |
|
---|
1762 | /* If the text or TVIS_BOLD was changed, and it is displayed, recalculate. */
|
---|
1763 | if (((changed & TVIF_TEXT) || ((tvItem->mask & TVIF_STATE) && (tvItem->stateMask & TVIS_BOLD))) && wineItem->displayed)
|
---|
1764 | {
|
---|
1765 | TREEVIEW_ComputeTextWidth(infoPtr,wineItem,0,FALSE);
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 | if (changed & (TVIF_INTEGRAL | TVIF_CHILDREN))
|
---|
1769 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
1770 | else
|
---|
1771 | TREEVIEW_RefreshItem(infoPtr,wineItem,changed);
|
---|
1772 |
|
---|
1773 | return TRUE;
|
---|
1774 | }
|
---|
1775 |
|
---|
1776 | static LRESULT
|
---|
1777 | TREEVIEW_GetItemState(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1778 | {
|
---|
1779 | TREEVIEW_ITEM *wineItem = (HTREEITEM)wParam;
|
---|
1780 |
|
---|
1781 | if (!wineItem || !TREEVIEW_ValidItem(infoPtr, wineItem))
|
---|
1782 | return 0;
|
---|
1783 |
|
---|
1784 | return (wineItem->state & lParam);
|
---|
1785 | }
|
---|
1786 |
|
---|
1787 | static LRESULT
|
---|
1788 | TREEVIEW_GetNextItem(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1789 | {
|
---|
1790 | TREEVIEW_ITEM *wineItem;
|
---|
1791 | TREEVIEW_ITEM *retval;
|
---|
1792 | WPARAM which;
|
---|
1793 |
|
---|
1794 | which = (INT)wParam;
|
---|
1795 | wineItem = (TREEVIEW_ITEM *)lParam;
|
---|
1796 | retval = 0;
|
---|
1797 |
|
---|
1798 | /* handle all the global data here */
|
---|
1799 | switch (which)
|
---|
1800 | {
|
---|
1801 | case TVGN_CHILD: /* Special case: child of 0 is root */
|
---|
1802 | if (wineItem)
|
---|
1803 | break;
|
---|
1804 | /* fall through */
|
---|
1805 | case TVGN_ROOT:
|
---|
1806 | retval = infoPtr->root->firstChild;
|
---|
1807 | break;
|
---|
1808 |
|
---|
1809 | case TVGN_CARET:
|
---|
1810 | retval = infoPtr->selectedItem;
|
---|
1811 | break;
|
---|
1812 |
|
---|
1813 | case TVGN_FIRSTVISIBLE:
|
---|
1814 | TREEVIEW_UnqueueRefresh(infoPtr,TRUE,TRUE);
|
---|
1815 | retval = infoPtr->firstVisible;
|
---|
1816 | break;
|
---|
1817 |
|
---|
1818 | case TVGN_DROPHILITE:
|
---|
1819 | retval = infoPtr->dropItem;
|
---|
1820 | break;
|
---|
1821 | }
|
---|
1822 |
|
---|
1823 | if (retval)
|
---|
1824 | {
|
---|
1825 | //TRACE("flags:%x, returns %p\n", which, retval);
|
---|
1826 | return (LRESULT)retval;
|
---|
1827 | }
|
---|
1828 |
|
---|
1829 | if (!TREEVIEW_ValidItem(infoPtr, wineItem))
|
---|
1830 | return FALSE;
|
---|
1831 |
|
---|
1832 | switch (which)
|
---|
1833 | {
|
---|
1834 | case TVGN_NEXT:
|
---|
1835 | retval = wineItem->nextSibling;
|
---|
1836 | break;
|
---|
1837 |
|
---|
1838 | case TVGN_PREVIOUS:
|
---|
1839 | retval = wineItem->prevSibling;
|
---|
1840 | break;
|
---|
1841 |
|
---|
1842 | case TVGN_PARENT:
|
---|
1843 | retval = (wineItem->parent != infoPtr->root) ? wineItem->parent : NULL;
|
---|
1844 | break;
|
---|
1845 |
|
---|
1846 | case TVGN_CHILD:
|
---|
1847 | retval = wineItem->firstChild;
|
---|
1848 | break;
|
---|
1849 |
|
---|
1850 | case TVGN_LASTVISIBLE:
|
---|
1851 | retval = TREEVIEW_GetLastListItem(infoPtr, wineItem);
|
---|
1852 | break;
|
---|
1853 |
|
---|
1854 | case TVGN_NEXTVISIBLE:
|
---|
1855 | retval = TREEVIEW_GetNextListItem(infoPtr, wineItem);
|
---|
1856 | break;
|
---|
1857 |
|
---|
1858 | case TVGN_PREVIOUSVISIBLE:
|
---|
1859 | retval = TREEVIEW_GetPrevListItem(infoPtr, wineItem);
|
---|
1860 | break;
|
---|
1861 |
|
---|
1862 | default:
|
---|
1863 | //TRACE("Unknown msg %x,item %p\n", which, wineItem);
|
---|
1864 | break;
|
---|
1865 | }
|
---|
1866 |
|
---|
1867 | //TRACE("flags:%x, item %p;returns %p\n", which, wineItem, retval);
|
---|
1868 | return (LRESULT)retval;
|
---|
1869 | }
|
---|
1870 |
|
---|
1871 |
|
---|
1872 | static LRESULT
|
---|
1873 | TREEVIEW_GetCount(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
1874 | {
|
---|
1875 | return (LRESULT)infoPtr->uNumItems;
|
---|
1876 | }
|
---|
1877 |
|
---|
1878 | static VOID
|
---|
1879 | TREEVIEW_ToggleItemState(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
|
---|
1880 | {
|
---|
1881 | if (infoPtr->dwStyle & TVS_CHECKBOXES)
|
---|
1882 | {
|
---|
1883 | static const unsigned int state_table[] = { 0, 2, 1 };
|
---|
1884 |
|
---|
1885 | unsigned int state;
|
---|
1886 |
|
---|
1887 | state = STATEIMAGEINDEX(item->state);
|
---|
1888 | //TRACE("state:%x\n", state);
|
---|
1889 | item->state &= ~TVIS_STATEIMAGEMASK;
|
---|
1890 |
|
---|
1891 | if (state < 3)
|
---|
1892 | state = state_table[state];
|
---|
1893 |
|
---|
1894 | item->state |= INDEXTOSTATEIMAGEMASK(state);
|
---|
1895 |
|
---|
1896 | //TRACE("state:%x\n", state);
|
---|
1897 | TREEVIEW_RefreshItem(infoPtr,item,TVIF_IMAGE);
|
---|
1898 | }
|
---|
1899 | }
|
---|
1900 |
|
---|
1901 |
|
---|
1902 | /* Painting *************************************************************/
|
---|
1903 |
|
---|
1904 | /* Draw the lines and expand button for an item. Also draws one section
|
---|
1905 | * of the line from item's parent to item's parent's next sibling. */
|
---|
1906 | static void
|
---|
1907 | TREEVIEW_DrawItemLines(TREEVIEW_INFO *infoPtr, HDC hdc, TREEVIEW_ITEM *item)
|
---|
1908 | {
|
---|
1909 | LONG centerx, centery;
|
---|
1910 | BOOL lar = ((infoPtr->dwStyle
|
---|
1911 | & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS))
|
---|
1912 | > TVS_LINESATROOT);
|
---|
1913 |
|
---|
1914 | if (!lar && item->iLevel == 0)
|
---|
1915 | return;
|
---|
1916 |
|
---|
1917 | centerx = (item->linesOffset + item->stateOffset) / 2;
|
---|
1918 | centery = (item->rect.top + item->rect.bottom) / 2;
|
---|
1919 |
|
---|
1920 | if (infoPtr->dwStyle & TVS_HASLINES)
|
---|
1921 | {
|
---|
1922 | HPEN hOldPen, hNewPen;
|
---|
1923 | HTREEITEM parent;
|
---|
1924 |
|
---|
1925 | /*
|
---|
1926 | * Get a dotted grey pen
|
---|
1927 | */
|
---|
1928 | hNewPen = CreatePen(PS_DOT, 0, infoPtr->clrLine);
|
---|
1929 | hOldPen = SelectObject(hdc, hNewPen);
|
---|
1930 |
|
---|
1931 | MoveToEx(hdc, item->stateOffset, centery, NULL);
|
---|
1932 | LineTo(hdc, centerx - 1, centery);
|
---|
1933 |
|
---|
1934 | if (item->prevSibling || item->parent != infoPtr->root)
|
---|
1935 | {
|
---|
1936 | MoveToEx(hdc, centerx, item->rect.top, NULL);
|
---|
1937 | LineTo(hdc, centerx, centery);
|
---|
1938 | }
|
---|
1939 |
|
---|
1940 | if (item->nextSibling)
|
---|
1941 | {
|
---|
1942 | MoveToEx(hdc, centerx, centery, NULL);
|
---|
1943 | LineTo(hdc, centerx, item->rect.bottom + 1);
|
---|
1944 | }
|
---|
1945 |
|
---|
1946 | /* Draw the line from our parent to its next sibling. */
|
---|
1947 | parent = item->parent;
|
---|
1948 | while (parent != infoPtr->root)
|
---|
1949 | {
|
---|
1950 | int pcenterx = (parent->linesOffset + parent->stateOffset) / 2;
|
---|
1951 |
|
---|
1952 | if (parent->nextSibling
|
---|
1953 | /* skip top-levels unless TVS_LINESATROOT */
|
---|
1954 | && parent->stateOffset > parent->linesOffset)
|
---|
1955 | {
|
---|
1956 | MoveToEx(hdc, pcenterx, item->rect.top, NULL);
|
---|
1957 | LineTo(hdc, pcenterx, item->rect.bottom + 1);
|
---|
1958 | }
|
---|
1959 |
|
---|
1960 | parent = parent->parent;
|
---|
1961 | }
|
---|
1962 |
|
---|
1963 | SelectObject(hdc, hOldPen);
|
---|
1964 | DeleteObject(hNewPen);
|
---|
1965 | }
|
---|
1966 |
|
---|
1967 | /*
|
---|
1968 | * Display the (+/-) signs
|
---|
1969 | */
|
---|
1970 |
|
---|
1971 | if (infoPtr->dwStyle & TVS_HASBUTTONS)
|
---|
1972 | {
|
---|
1973 | if (item->cChildren)
|
---|
1974 | {
|
---|
1975 | LONG height = item->rect.bottom - item->rect.top;
|
---|
1976 | LONG width = item->stateOffset - item->linesOffset;
|
---|
1977 | LONG rectsize = MIN(height, width) / 4;
|
---|
1978 | /* plussize = ceil(rectsize * 3/4) */
|
---|
1979 | LONG plussize = (rectsize + 1) * 3 / 4;
|
---|
1980 |
|
---|
1981 | HPEN hNewPen = CreatePen(PS_SOLID, 0, infoPtr->clrLine);
|
---|
1982 | HPEN hOldPen = SelectObject(hdc, hNewPen);
|
---|
1983 |
|
---|
1984 | Rectangle(hdc, centerx - rectsize, centery - rectsize,
|
---|
1985 | centerx + rectsize + 1, centery + rectsize + 1);
|
---|
1986 |
|
---|
1987 | SelectObject(hdc, hOldPen);
|
---|
1988 | DeleteObject(hNewPen);
|
---|
1989 |
|
---|
1990 | MoveToEx(hdc, centerx - plussize + 1, centery, NULL);
|
---|
1991 | LineTo(hdc, centerx + plussize, centery);
|
---|
1992 |
|
---|
1993 | if (!(item->state & TVIS_EXPANDED))
|
---|
1994 | {
|
---|
1995 | MoveToEx(hdc, centerx, centery - plussize + 1, NULL);
|
---|
1996 | LineTo(hdc, centerx, centery + plussize);
|
---|
1997 | }
|
---|
1998 | }
|
---|
1999 | }
|
---|
2000 | }
|
---|
2001 |
|
---|
2002 | static VOID TREEVIEW_DrawHottrackLine(HDC hdc,TREEVIEW_ITEM *item)
|
---|
2003 | {
|
---|
2004 | HPEN hPen,hOldPen;
|
---|
2005 | INT rop;
|
---|
2006 |
|
---|
2007 | if (!item->inclient) return;
|
---|
2008 |
|
---|
2009 | rop = SetROP2(hdc,R2_XORPEN);
|
---|
2010 | hPen = CreatePen(PS_SOLID,2,RGB(0,0,0));
|
---|
2011 | hOldPen = SelectObject(hdc,hPen);
|
---|
2012 |
|
---|
2013 | MoveToEx(hdc,item->textOffset,item->rect.bottom-1,NULL);
|
---|
2014 | LineTo(hdc,item->textOffset+item->textWidth,item->rect.bottom-1);
|
---|
2015 |
|
---|
2016 | DeleteObject(hPen);
|
---|
2017 | SelectObject(hdc,hOldPen);
|
---|
2018 | SetROP2(hdc,rop);
|
---|
2019 | }
|
---|
2020 |
|
---|
2021 | static void
|
---|
2022 | TREEVIEW_DrawItem(TREEVIEW_INFO *infoPtr, HDC hdc, TREEVIEW_ITEM *wineItem)
|
---|
2023 | {
|
---|
2024 | INT cditem;
|
---|
2025 | HFONT hOldFont;
|
---|
2026 | int centery;
|
---|
2027 |
|
---|
2028 | if (!wineItem->calculated) TREEVIEW_CalcItem(infoPtr,wineItem,hdc);
|
---|
2029 |
|
---|
2030 | hOldFont = SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, wineItem));
|
---|
2031 |
|
---|
2032 | TREEVIEW_UpdateDispInfo(infoPtr, wineItem, CALLBACK_MASK_ALL);
|
---|
2033 |
|
---|
2034 | /* The custom draw handler can query the text rectangle,
|
---|
2035 | * so get ready. */
|
---|
2036 | TREEVIEW_ComputeTextWidth(infoPtr,wineItem,hdc,TRUE);
|
---|
2037 |
|
---|
2038 | cditem = 0;
|
---|
2039 |
|
---|
2040 | if (infoPtr->cdmode & CDRF_NOTIFYITEMDRAW)
|
---|
2041 | {
|
---|
2042 | cditem = TREEVIEW_SendCustomDrawItemNotify(infoPtr, hdc, wineItem, CDDS_ITEMPREPAINT);
|
---|
2043 |
|
---|
2044 | if (cditem & CDRF_SKIPDEFAULT)
|
---|
2045 | {
|
---|
2046 | SelectObject(hdc, hOldFont);
|
---|
2047 | return;
|
---|
2048 | }
|
---|
2049 | }
|
---|
2050 |
|
---|
2051 | if (cditem & CDRF_NEWFONT)
|
---|
2052 | TREEVIEW_ComputeTextWidth(infoPtr,wineItem,hdc,TRUE);
|
---|
2053 |
|
---|
2054 | TREEVIEW_DrawItemLines(infoPtr, hdc, wineItem);
|
---|
2055 |
|
---|
2056 | centery = (wineItem->rect.top + wineItem->rect.bottom) / 2;
|
---|
2057 |
|
---|
2058 | /*
|
---|
2059 | * Display the images associated with this item
|
---|
2060 | */
|
---|
2061 | {
|
---|
2062 | INT imageIndex;
|
---|
2063 |
|
---|
2064 | /* State images are displayed to the left of the Normal image
|
---|
2065 | * image number is in state; zero should be `display no image'.
|
---|
2066 | */
|
---|
2067 | imageIndex = STATEIMAGEINDEX(wineItem->state);
|
---|
2068 |
|
---|
2069 | if (infoPtr->himlState && imageIndex)
|
---|
2070 | {
|
---|
2071 | ImageList_Draw(infoPtr->himlState, imageIndex - 1, hdc,
|
---|
2072 | wineItem->stateOffset,
|
---|
2073 | centery - infoPtr->stateImageHeight / 2,
|
---|
2074 | ILD_NORMAL);
|
---|
2075 | }
|
---|
2076 |
|
---|
2077 | /* Now, draw the normal image; can be either selected or
|
---|
2078 | * non-selected image.
|
---|
2079 | */
|
---|
2080 |
|
---|
2081 | if ((wineItem->state & TVIS_SELECTED) && wineItem->iSelectedImage)
|
---|
2082 | {
|
---|
2083 | /* The item is curently selected */
|
---|
2084 | imageIndex = wineItem->iSelectedImage;
|
---|
2085 | }
|
---|
2086 | else
|
---|
2087 | {
|
---|
2088 | /* The item is not selected */
|
---|
2089 | imageIndex = wineItem->iImage;
|
---|
2090 | }
|
---|
2091 |
|
---|
2092 | if (infoPtr->himlNormal && (imageIndex != I_IMAGENONE))
|
---|
2093 | {
|
---|
2094 | int ovlIdx = wineItem->state & TVIS_OVERLAYMASK;
|
---|
2095 |
|
---|
2096 | ImageList_Draw(infoPtr->himlNormal, imageIndex, hdc,
|
---|
2097 | wineItem->imageOffset,
|
---|
2098 | centery - infoPtr->normalImageHeight / 2,
|
---|
2099 | ILD_NORMAL | ovlIdx);
|
---|
2100 | }
|
---|
2101 | }
|
---|
2102 |
|
---|
2103 |
|
---|
2104 | /*
|
---|
2105 | * Display the text associated with this item
|
---|
2106 | */
|
---|
2107 |
|
---|
2108 | /* Don't paint item's text if it's being edited */
|
---|
2109 | if (!infoPtr->hwndEdit)
|
---|
2110 | {
|
---|
2111 | if (wineItem->pszText && (wineItem->pszText[0] != 0))
|
---|
2112 | {
|
---|
2113 | COLORREF oldTextColor = 0;
|
---|
2114 | INT oldBkMode;
|
---|
2115 | HBRUSH hbrBk = 0;
|
---|
2116 | BOOL inFocus = (GetFocus() == infoPtr->hwnd);
|
---|
2117 | RECT rcText;
|
---|
2118 |
|
---|
2119 | oldBkMode = SetBkMode(hdc, TRANSPARENT);
|
---|
2120 |
|
---|
2121 | /* - If item is drop target or it is selected and window is in focus -
|
---|
2122 | * use blue background (COLOR_HIGHLIGHT).
|
---|
2123 | * - If item is selected, window is not in focus, but it has style
|
---|
2124 | * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
|
---|
2125 | * - Otherwise - don't fill background
|
---|
2126 | */
|
---|
2127 | if ((wineItem->state & TVIS_DROPHILITED) ||
|
---|
2128 | ((wineItem->state & TVIS_SELECTED) &&
|
---|
2129 | (inFocus || (infoPtr->dwStyle & TVS_SHOWSELALWAYS))))
|
---|
2130 | {
|
---|
2131 | if ((wineItem->state & TVIS_DROPHILITED) || inFocus)
|
---|
2132 | {
|
---|
2133 | hbrBk = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
|
---|
2134 | oldTextColor =
|
---|
2135 | SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
|
---|
2136 | }
|
---|
2137 | else
|
---|
2138 | {
|
---|
2139 | hbrBk = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
|
---|
2140 |
|
---|
2141 | if (infoPtr->clrText == -1)
|
---|
2142 | oldTextColor =
|
---|
2143 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
2144 | else
|
---|
2145 | oldTextColor = SetTextColor(hdc, infoPtr->clrText);
|
---|
2146 | }
|
---|
2147 | }
|
---|
2148 | else
|
---|
2149 | {
|
---|
2150 | if (infoPtr->clrText == -1)
|
---|
2151 | oldTextColor =
|
---|
2152 | SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
---|
2153 | else
|
---|
2154 | oldTextColor = SetTextColor(hdc, infoPtr->clrText);
|
---|
2155 | }
|
---|
2156 |
|
---|
2157 | rcText.top = wineItem->rect.top;
|
---|
2158 | rcText.bottom = wineItem->rect.bottom;
|
---|
2159 | rcText.left = wineItem->textOffset;
|
---|
2160 | rcText.right = rcText.left + wineItem->textWidth + 4;
|
---|
2161 |
|
---|
2162 | if (hbrBk)
|
---|
2163 | {
|
---|
2164 | FillRect(hdc, &rcText, hbrBk);
|
---|
2165 | DeleteObject(hbrBk);
|
---|
2166 | }
|
---|
2167 |
|
---|
2168 | /* Draw the box arround the selected item */
|
---|
2169 | if ((wineItem->state & TVIS_SELECTED) && inFocus)
|
---|
2170 | {
|
---|
2171 | HPEN hNewPen = CreatePen(PS_DOT, 0,
|
---|
2172 | GetSysColor(COLOR_WINDOWTEXT));
|
---|
2173 | HPEN hOldPen = SelectObject(hdc, hNewPen);
|
---|
2174 | INT rop = SetROP2(hdc, R2_XORPEN);
|
---|
2175 | POINT points[5];
|
---|
2176 |
|
---|
2177 | points[4].x = points[0].x = rcText.left;
|
---|
2178 | points[4].y = points[0].y = rcText.top;
|
---|
2179 | points[1].x = rcText.right - 1;
|
---|
2180 | points[1].y = rcText.top;
|
---|
2181 | points[2].x = rcText.right - 1;
|
---|
2182 | points[2].y = rcText.bottom - 1;
|
---|
2183 | points[3].x = rcText.left;
|
---|
2184 | points[3].y = rcText.bottom - 1;
|
---|
2185 |
|
---|
2186 | Polyline(hdc, points, 5);
|
---|
2187 |
|
---|
2188 | SetROP2(hdc, rop);
|
---|
2189 | SelectObject(hdc, hOldPen);
|
---|
2190 | DeleteObject(hNewPen);
|
---|
2191 | }
|
---|
2192 |
|
---|
2193 | rcText.left += 2;
|
---|
2194 | rcText.right -= 2;
|
---|
2195 |
|
---|
2196 | /* Draw it */
|
---|
2197 | DrawTextW(hdc,
|
---|
2198 | wineItem->pszText,
|
---|
2199 | lstrlenW(wineItem->pszText),
|
---|
2200 | &rcText,
|
---|
2201 | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
|
---|
2202 |
|
---|
2203 | /* Restore the hdc state */
|
---|
2204 | SetTextColor(hdc, oldTextColor);
|
---|
2205 |
|
---|
2206 | if (oldBkMode != TRANSPARENT)
|
---|
2207 | SetBkMode(hdc, oldBkMode);
|
---|
2208 | }
|
---|
2209 | }
|
---|
2210 |
|
---|
2211 | /* Draw insertion mark if necessary */
|
---|
2212 |
|
---|
2213 | if (wineItem == infoPtr->insertMarkItem)
|
---|
2214 | {
|
---|
2215 | HPEN hNewPen, hOldPen;
|
---|
2216 | int offset;
|
---|
2217 | int left, right;
|
---|
2218 |
|
---|
2219 | hNewPen = CreatePen(PS_SOLID, 2, infoPtr->clrInsertMark);
|
---|
2220 | hOldPen = SelectObject(hdc, hNewPen);
|
---|
2221 |
|
---|
2222 | if (infoPtr->insertBeforeorAfter)
|
---|
2223 | offset = wineItem->rect.bottom - 1;
|
---|
2224 | else
|
---|
2225 | offset = wineItem->rect.top + 1;
|
---|
2226 |
|
---|
2227 | left = wineItem->textOffset - 2;
|
---|
2228 | right = wineItem->textOffset + wineItem->textWidth + 2;
|
---|
2229 |
|
---|
2230 | MoveToEx(hdc, left, offset - 3, NULL);
|
---|
2231 | LineTo(hdc, left, offset + 4);
|
---|
2232 |
|
---|
2233 | MoveToEx(hdc, left, offset, NULL);
|
---|
2234 | LineTo(hdc, right + 1, offset);
|
---|
2235 |
|
---|
2236 | MoveToEx(hdc, right, offset + 3, NULL);
|
---|
2237 | LineTo(hdc, right, offset - 4);
|
---|
2238 |
|
---|
2239 | SelectObject(hdc, hOldPen);
|
---|
2240 | DeleteObject(hNewPen);
|
---|
2241 | }
|
---|
2242 |
|
---|
2243 | //draw hot item if necessary
|
---|
2244 | if (wineItem == infoPtr->hotItem)
|
---|
2245 | TREEVIEW_DrawHottrackLine(hdc,wineItem);
|
---|
2246 |
|
---|
2247 | if (cditem & CDRF_NOTIFYPOSTPAINT)
|
---|
2248 | {
|
---|
2249 | cditem = TREEVIEW_SendCustomDrawItemNotify(infoPtr, hdc, wineItem, CDDS_ITEMPOSTPAINT);
|
---|
2250 | }
|
---|
2251 |
|
---|
2252 | SelectObject(hdc, hOldFont);
|
---|
2253 | }
|
---|
2254 |
|
---|
2255 | static void TREEVIEW_QueueRefresh(TREEVIEW_INFO *infoPtr)
|
---|
2256 | {
|
---|
2257 | if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
|
---|
2258 | KillTimer(infoPtr->hwnd,TV_REFRESH_TIMER);
|
---|
2259 |
|
---|
2260 | if (infoPtr->uInternalStatus & TV_NOREDRAW)
|
---|
2261 | {
|
---|
2262 | infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
|
---|
2263 |
|
---|
2264 | return;
|
---|
2265 | }
|
---|
2266 |
|
---|
2267 | SetTimer(infoPtr->hwnd,TV_REFRESH_TIMER,TV_REFRESH_DELAY,0);
|
---|
2268 | infoPtr->Timer |= TV_REFRESH_TIMER_SET;
|
---|
2269 | }
|
---|
2270 |
|
---|
2271 | static BOOL TREEVIEW_UnqueueRefresh(TREEVIEW_INFO *infoPtr,BOOL calc,BOOL refresh)
|
---|
2272 | {
|
---|
2273 | if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
|
---|
2274 | {
|
---|
2275 | KillTimer(infoPtr->hwnd,TV_REFRESH_TIMER);
|
---|
2276 | infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
|
---|
2277 |
|
---|
2278 | if (calc) TREEVIEW_CalcItems(infoPtr);
|
---|
2279 | if (refresh)
|
---|
2280 | {
|
---|
2281 | TREEVIEW_Refresh(infoPtr);
|
---|
2282 | UpdateWindow(infoPtr->hwnd);
|
---|
2283 | }
|
---|
2284 |
|
---|
2285 | return TRUE;
|
---|
2286 | }
|
---|
2287 |
|
---|
2288 | return FALSE;
|
---|
2289 | }
|
---|
2290 |
|
---|
2291 | static void
|
---|
2292 | TREEVIEW_Draw(TREEVIEW_INFO *infoPtr,HDC hdc,RECT *updateRect)
|
---|
2293 | {
|
---|
2294 | RECT rect;
|
---|
2295 | TREEVIEW_ITEM *item;
|
---|
2296 | INT iItem;
|
---|
2297 |
|
---|
2298 | TREEVIEW_UnqueueRefresh(infoPtr,TRUE,FALSE);
|
---|
2299 |
|
---|
2300 | GetClientRect(infoPtr->hwnd,&rect);
|
---|
2301 | if ((rect.left == rect.right) || (rect.top == rect.bottom)) return;
|
---|
2302 |
|
---|
2303 | infoPtr->cdmode = TREEVIEW_SendCustomDrawNotify(infoPtr,CDDS_PREPAINT,hdc,rect);
|
---|
2304 |
|
---|
2305 | if (infoPtr->cdmode == CDRF_SKIPDEFAULT) return;
|
---|
2306 |
|
---|
2307 | /* We iterate through all visible items in order */
|
---|
2308 | item = infoPtr->firstVisible;
|
---|
2309 |
|
---|
2310 | while ((item != NULL) && item->inclient)
|
---|
2311 | {
|
---|
2312 | RECT itemRect = item->rect;
|
---|
2313 |
|
---|
2314 | if (!item->calculated) TREEVIEW_CalcItem(infoPtr,item,hdc);
|
---|
2315 | if (updateRect && IntersectRect(NULL,&itemRect,updateRect))
|
---|
2316 | TREEVIEW_DrawItem(infoPtr,hdc,item);
|
---|
2317 | else
|
---|
2318 | {
|
---|
2319 | if (updateRect && (item->rect.top >= updateRect->bottom)) break;
|
---|
2320 | itemRect.left = 0;
|
---|
2321 | if (updateRect && IntersectRect(NULL,&itemRect,updateRect))
|
---|
2322 | TREEVIEW_DrawItemLines(infoPtr,hdc,item);
|
---|
2323 | }
|
---|
2324 | item = TREEVIEW_GetNextListItem(infoPtr,item);
|
---|
2325 | }
|
---|
2326 |
|
---|
2327 | if (infoPtr->cdmode & CDRF_NOTIFYPOSTPAINT)
|
---|
2328 | infoPtr->cdmode = TREEVIEW_SendCustomDrawNotify(infoPtr, CDDS_POSTPAINT, hdc, rect);
|
---|
2329 | }
|
---|
2330 |
|
---|
2331 | static void TREEVIEW_Refresh(TREEVIEW_INFO *infoPtr)
|
---|
2332 | {
|
---|
2333 | TREEVIEW_UnqueueRefresh(infoPtr,TRUE,FALSE);
|
---|
2334 |
|
---|
2335 | InvalidateRect(infoPtr->hwnd,NULL,TRUE);
|
---|
2336 | }
|
---|
2337 |
|
---|
2338 | static void TREEVIEW_RefreshItem(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item,DWORD changed)
|
---|
2339 | {
|
---|
2340 | if (item && item->inclient)
|
---|
2341 | {
|
---|
2342 | RECT rect = item->rect;
|
---|
2343 |
|
---|
2344 | //left
|
---|
2345 | if (changed & TVIF_STATE) rect.left = item->stateOffset;
|
---|
2346 | else if (changed & (TVIF_IMAGE | TVIF_SELECTEDIMAGE)) rect.left = item->imageOffset;
|
---|
2347 | else if (changed & TVIF_TEXT) rect.left = item->textOffset;
|
---|
2348 |
|
---|
2349 | //right
|
---|
2350 | if (changed & TVIF_TEXT);
|
---|
2351 | else if (changed & (TVIF_IMAGE | TVIF_SELECTEDIMAGE)) rect.right = item->imageOffset-infoPtr->normalImageWidth;
|
---|
2352 | else if (changed & TVIF_STATE) rect.right = item->stateOffset-infoPtr->stateImageWidth;
|
---|
2353 |
|
---|
2354 | InvalidateRect(infoPtr->hwnd,&rect,TRUE);
|
---|
2355 | }
|
---|
2356 | }
|
---|
2357 |
|
---|
2358 | static LRESULT
|
---|
2359 | TREEVIEW_Paint(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
2360 | {
|
---|
2361 | HDC hdc = (HDC)wParam;
|
---|
2362 |
|
---|
2363 | if (!hdc)
|
---|
2364 | {
|
---|
2365 | PAINTSTRUCT ps;
|
---|
2366 |
|
---|
2367 | hdc = BeginPaint(infoPtr->hwnd,&ps);
|
---|
2368 | TREEVIEW_Draw(infoPtr,hdc,&ps.rcPaint);
|
---|
2369 | EndPaint(infoPtr->hwnd,&ps);
|
---|
2370 | } else
|
---|
2371 | TREEVIEW_Draw(infoPtr,hdc,NULL);
|
---|
2372 |
|
---|
2373 | return 0;
|
---|
2374 | }
|
---|
2375 |
|
---|
2376 | /* Sorting **************************************************************/
|
---|
2377 |
|
---|
2378 | /***************************************************************************
|
---|
2379 | * Forward the DPA local callback to the treeview owner callback
|
---|
2380 | */
|
---|
2381 | static INT WINAPI
|
---|
2382 | TREEVIEW_CallBackCompare(LPVOID pvFirst, LPVOID pvSecond, LPARAM callback)
|
---|
2383 | {
|
---|
2384 | LPTVSORTCB pCallBackSort = (LPTVSORTCB)callback;
|
---|
2385 |
|
---|
2386 | TREEVIEW_ITEM *first = (TREEVIEW_ITEM *)pvFirst;
|
---|
2387 | TREEVIEW_ITEM *second = (TREEVIEW_ITEM *)pvSecond;
|
---|
2388 |
|
---|
2389 | /* Forward the call to the client-defined callback */
|
---|
2390 | return pCallBackSort->lpfnCompare(first->lParam,
|
---|
2391 | second->lParam,
|
---|
2392 | pCallBackSort->lParam);
|
---|
2393 | }
|
---|
2394 |
|
---|
2395 | /***************************************************************************
|
---|
2396 | * Treeview native sort routine: sort on item text.
|
---|
2397 | */
|
---|
2398 | static INT WINAPI
|
---|
2399 | TREEVIEW_SortOnName(LPVOID pvFirst, LPVOID pvSecond, LPARAM tvInfoPtr)
|
---|
2400 | {
|
---|
2401 | TREEVIEW_INFO *infoPtr = (TREEVIEW_INFO *)tvInfoPtr;
|
---|
2402 |
|
---|
2403 | TREEVIEW_ITEM *first = (TREEVIEW_ITEM *)pvFirst;
|
---|
2404 | TREEVIEW_ITEM *second = (TREEVIEW_ITEM *)pvSecond;
|
---|
2405 |
|
---|
2406 | TREEVIEW_UpdateDispInfo(infoPtr, first, TVIF_TEXT);
|
---|
2407 | TREEVIEW_UpdateDispInfo(infoPtr, second, TVIF_TEXT);
|
---|
2408 |
|
---|
2409 | return lstrcmpiW(first->pszText, second->pszText);
|
---|
2410 | }
|
---|
2411 |
|
---|
2412 | /* Returns the number of physical children belonging to item. */
|
---|
2413 | static INT
|
---|
2414 | TREEVIEW_CountChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
|
---|
2415 | {
|
---|
2416 | INT cChildren = 0;
|
---|
2417 | HTREEITEM hti;
|
---|
2418 |
|
---|
2419 | for (hti = item->firstChild; hti != NULL; hti = hti->nextSibling)
|
---|
2420 | cChildren++;
|
---|
2421 |
|
---|
2422 | return cChildren;
|
---|
2423 | }
|
---|
2424 |
|
---|
2425 | /* Returns a DPA containing a pointer to each physical child of item in
|
---|
2426 | * sibling order. If item has no children, an empty DPA is returned. */
|
---|
2427 | static HDPA
|
---|
2428 | TREEVIEW_BuildChildDPA(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
|
---|
2429 | {
|
---|
2430 | HTREEITEM child = item->firstChild;
|
---|
2431 |
|
---|
2432 | HDPA list = DPA_Create(8);
|
---|
2433 | if (list == 0) return NULL;
|
---|
2434 |
|
---|
2435 | for (child = item->firstChild; child != NULL; child = child->nextSibling)
|
---|
2436 | {
|
---|
2437 | if (DPA_InsertPtr(list, INT_MAX, child) == -1)
|
---|
2438 | {
|
---|
2439 | DPA_Destroy(list);
|
---|
2440 | return NULL;
|
---|
2441 | }
|
---|
2442 | }
|
---|
2443 |
|
---|
2444 | return list;
|
---|
2445 | }
|
---|
2446 |
|
---|
2447 | /***************************************************************************
|
---|
2448 | * Setup the treeview structure with regards of the sort method
|
---|
2449 | * and sort the children of the TV item specified in lParam
|
---|
2450 | * fRecurse: currently unused. Should be zero.
|
---|
2451 | * parent: if pSort!=NULL, should equal pSort->hParent.
|
---|
2452 | * otherwise, item which child items are to be sorted.
|
---|
2453 | * pSort: sort method info. if NULL, sort on item text.
|
---|
2454 | * if non-NULL, sort on item's lParam content, and let the
|
---|
2455 | * application decide what that means. See also TVM_SORTCHILDRENCB.
|
---|
2456 | */
|
---|
2457 |
|
---|
2458 | static LRESULT
|
---|
2459 | TREEVIEW_Sort(TREEVIEW_INFO *infoPtr, BOOL fRecurse, HTREEITEM parent,
|
---|
2460 | LPTVSORTCB pSort)
|
---|
2461 | {
|
---|
2462 | INT cChildren;
|
---|
2463 | PFNDPACOMPARE pfnCompare;
|
---|
2464 | LPARAM lpCompare;
|
---|
2465 | BOOL root = FALSE;
|
---|
2466 |
|
---|
2467 | /* undocumented feature: TVI_ROOT means `sort the whole tree' */
|
---|
2468 | if ((parent == TVI_ROOT) || (parent == 0))
|
---|
2469 | {
|
---|
2470 | root = TRUE;
|
---|
2471 | parent = infoPtr->root;
|
---|
2472 | }
|
---|
2473 |
|
---|
2474 | /* Check for a valid handle to the parent item */
|
---|
2475 | if (!TREEVIEW_ValidItem(infoPtr, parent))
|
---|
2476 | {
|
---|
2477 | //ERR("invalid item hParent=%x\n", (INT)parent);
|
---|
2478 | return FALSE;
|
---|
2479 | }
|
---|
2480 |
|
---|
2481 | if (pSort)
|
---|
2482 | {
|
---|
2483 | pfnCompare = TREEVIEW_CallBackCompare;
|
---|
2484 | lpCompare = (LPARAM)pSort;
|
---|
2485 | }
|
---|
2486 | else
|
---|
2487 | {
|
---|
2488 | pfnCompare = TREEVIEW_SortOnName;
|
---|
2489 | lpCompare = (LPARAM)infoPtr;
|
---|
2490 | }
|
---|
2491 |
|
---|
2492 | cChildren = TREEVIEW_CountChildren(infoPtr,parent);
|
---|
2493 |
|
---|
2494 | /* Make sure there is something to sort */
|
---|
2495 | if (cChildren > 1)
|
---|
2496 | {
|
---|
2497 | /* TREEVIEW_ITEM rechaining */
|
---|
2498 | INT count = 0;
|
---|
2499 | HTREEITEM item = 0;
|
---|
2500 | HTREEITEM nextItem = 0;
|
---|
2501 | HTREEITEM prevItem = 0;
|
---|
2502 |
|
---|
2503 | HDPA sortList = TREEVIEW_BuildChildDPA(infoPtr, parent);
|
---|
2504 |
|
---|
2505 | if (sortList == NULL)
|
---|
2506 | return FALSE;
|
---|
2507 |
|
---|
2508 | /* let DPA sort the list */
|
---|
2509 | DPA_Sort(sortList, pfnCompare, lpCompare);
|
---|
2510 |
|
---|
2511 | /* The order of DPA entries has been changed, so fixup the
|
---|
2512 | * nextSibling and prevSibling pointers. */
|
---|
2513 |
|
---|
2514 | item = (HTREEITEM)DPA_GetPtr(sortList, count++);
|
---|
2515 | while ((nextItem = (HTREEITEM)DPA_GetPtr(sortList, count++)) != NULL)
|
---|
2516 | {
|
---|
2517 | /* link the two current item toghether */
|
---|
2518 | item->nextSibling = nextItem;
|
---|
2519 | nextItem->prevSibling = item;
|
---|
2520 |
|
---|
2521 | if (prevItem == NULL)
|
---|
2522 | {
|
---|
2523 | /* this is the first item, update the parent */
|
---|
2524 | parent->firstChild = item;
|
---|
2525 | item->prevSibling = NULL;
|
---|
2526 | }
|
---|
2527 | else
|
---|
2528 | {
|
---|
2529 | /* fix the back chaining */
|
---|
2530 | item->prevSibling = prevItem;
|
---|
2531 | }
|
---|
2532 |
|
---|
2533 | /* get ready for the next one */
|
---|
2534 | prevItem = item;
|
---|
2535 | item = nextItem;
|
---|
2536 | }
|
---|
2537 |
|
---|
2538 | /* the last item is pointed to by item and never has a sibling */
|
---|
2539 | item->nextSibling = NULL;
|
---|
2540 | parent->lastChild = item;
|
---|
2541 |
|
---|
2542 | DPA_Destroy(sortList);
|
---|
2543 |
|
---|
2544 | TREEVIEW_VerifyTree(infoPtr);
|
---|
2545 |
|
---|
2546 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
2547 |
|
---|
2548 | return TRUE;
|
---|
2549 | }
|
---|
2550 | return FALSE;
|
---|
2551 | }
|
---|
2552 |
|
---|
2553 | /***************************************************************************
|
---|
2554 | * Setup the treeview structure with regards of the sort method
|
---|
2555 | * and sort the children of the TV item specified in lParam
|
---|
2556 | */
|
---|
2557 | static LRESULT
|
---|
2558 | TREEVIEW_SortChildrenCB(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
2559 | {
|
---|
2560 | LPTVSORTCB pSort = (LPTVSORTCB)lParam;
|
---|
2561 |
|
---|
2562 | return TREEVIEW_Sort(infoPtr, wParam, pSort->hParent, pSort);
|
---|
2563 | }
|
---|
2564 |
|
---|
2565 |
|
---|
2566 | /***************************************************************************
|
---|
2567 | * Sort the children of the TV item specified in lParam.
|
---|
2568 | */
|
---|
2569 | static LRESULT
|
---|
2570 | TREEVIEW_SortChildren(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
2571 | {
|
---|
2572 | return TREEVIEW_Sort(infoPtr, (BOOL)wParam, (HTREEITEM)lParam, NULL);
|
---|
2573 | }
|
---|
2574 |
|
---|
2575 |
|
---|
2576 | /* Expansion/Collapse ***************************************************/
|
---|
2577 |
|
---|
2578 | static BOOL
|
---|
2579 | TREEVIEW_SendExpanding(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
|
---|
2580 | UINT action)
|
---|
2581 | {
|
---|
2582 | return !TREEVIEW_SendTreeviewNotify(infoPtr,isUnicodeNotify(&infoPtr->header) ? TVN_ITEMEXPANDINGW:TVN_ITEMEXPANDINGA, action,
|
---|
2583 | TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
|
---|
2584 | | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
|
---|
2585 | 0, wineItem);
|
---|
2586 | }
|
---|
2587 |
|
---|
2588 | static VOID
|
---|
2589 | TREEVIEW_SendExpanded(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
|
---|
2590 | UINT action)
|
---|
2591 | {
|
---|
2592 | TREEVIEW_SendTreeviewNotify(infoPtr,isUnicodeNotify(&infoPtr->header) ? TVN_ITEMEXPANDEDW:TVN_ITEMEXPANDEDA, action,
|
---|
2593 | TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
|
---|
2594 | | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
|
---|
2595 | 0, wineItem);
|
---|
2596 | }
|
---|
2597 |
|
---|
2598 |
|
---|
2599 | /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
|
---|
2600 | * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
|
---|
2601 | static BOOL
|
---|
2602 | TREEVIEW_Collapse(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
|
---|
2603 | BOOL bRemoveChildren, BOOL bUser)
|
---|
2604 | {
|
---|
2605 | UINT action = TVE_COLLAPSE | (bRemoveChildren ? TVE_COLLAPSERESET : 0);
|
---|
2606 | BOOL bSetSelection, bSetFirstVisible;
|
---|
2607 |
|
---|
2608 | //TRACE("TVE_COLLAPSE %p %s\n", wineItem, TREEVIEW_ItemName(wineItem));
|
---|
2609 |
|
---|
2610 | if (!(wineItem->state & TVIS_EXPANDED) || wineItem->firstChild == NULL)
|
---|
2611 | return FALSE;
|
---|
2612 |
|
---|
2613 | if (bUser)
|
---|
2614 | TREEVIEW_SendExpanding(infoPtr, wineItem, action);
|
---|
2615 |
|
---|
2616 | wineItem->state &= ~TVIS_EXPANDED;
|
---|
2617 |
|
---|
2618 | if (bUser)
|
---|
2619 | TREEVIEW_SendExpanded(infoPtr, wineItem, action);
|
---|
2620 |
|
---|
2621 | bSetSelection = (infoPtr->selectedItem != NULL
|
---|
2622 | && TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem));
|
---|
2623 |
|
---|
2624 | if (TREEVIEW_IsChildOf(wineItem,infoPtr->firstVisible))
|
---|
2625 | {
|
---|
2626 | infoPtr->lefttop.y += wineItem->rect.top;
|
---|
2627 | }
|
---|
2628 |
|
---|
2629 | if (bRemoveChildren)
|
---|
2630 | {
|
---|
2631 | //TRACE("TVE_COLLAPSERESET\n");
|
---|
2632 | wineItem->state &= ~TVIS_EXPANDEDONCE;
|
---|
2633 | TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
|
---|
2634 | }
|
---|
2635 |
|
---|
2636 | //update window
|
---|
2637 | //CB: todo: optimize!
|
---|
2638 | TREEVIEW_UnqueueRefresh(infoPtr,FALSE,FALSE);
|
---|
2639 | //CB: todo: precalc expanded items here
|
---|
2640 | TREEVIEW_CalcItems(infoPtr);
|
---|
2641 | TREEVIEW_Refresh(infoPtr);
|
---|
2642 |
|
---|
2643 | if (bSetSelection)
|
---|
2644 | {
|
---|
2645 | /* Don't call DoSelectItem, it sends notifications. */
|
---|
2646 | if (infoPtr->selectedItem)
|
---|
2647 | infoPtr->selectedItem->state &= ~TVIS_SELECTED;
|
---|
2648 | wineItem->state |= TVIS_SELECTED;
|
---|
2649 | infoPtr->selectedItem = wineItem;
|
---|
2650 |
|
---|
2651 | TREEVIEW_EnsureVisible(infoPtr, wineItem);
|
---|
2652 | }
|
---|
2653 |
|
---|
2654 | return TRUE;
|
---|
2655 | }
|
---|
2656 |
|
---|
2657 | static BOOL
|
---|
2658 | TREEVIEW_Expand(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
|
---|
2659 | BOOL bExpandPartial, BOOL bUser)
|
---|
2660 | {
|
---|
2661 | //TRACE("TVE_EXPAND\n");
|
---|
2662 |
|
---|
2663 | if (!TREEVIEW_HasChildren(infoPtr, wineItem)
|
---|
2664 | || (wineItem->state & TVIS_EXPANDED))
|
---|
2665 | return FALSE;
|
---|
2666 |
|
---|
2667 | //TRACE(" is not expanded...\n");
|
---|
2668 |
|
---|
2669 | if (bUser || !(wineItem->state & TVIS_EXPANDEDONCE))
|
---|
2670 | {
|
---|
2671 | //TRACE(" and has never been expanded...\n");
|
---|
2672 |
|
---|
2673 | if (bExpandPartial)
|
---|
2674 | {
|
---|
2675 | return FALSE; //CB: how does this work??? (only display one level? nonsense in MSDN docu)
|
---|
2676 | wineItem->state ^=TVIS_EXPANDED;
|
---|
2677 | wineItem->state |=TVIS_EXPANDEDONCE;
|
---|
2678 | }
|
---|
2679 |
|
---|
2680 | wineItem->state |= TVIS_EXPANDED;
|
---|
2681 | //TRACE(" TVN_ITEMEXPANDING sent...\n");
|
---|
2682 |
|
---|
2683 | if (!TREEVIEW_SendExpanding(infoPtr, wineItem, TVE_EXPAND))
|
---|
2684 | {
|
---|
2685 | //TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
|
---|
2686 | return FALSE;
|
---|
2687 | }
|
---|
2688 |
|
---|
2689 | wineItem->state |= TVIS_EXPANDEDONCE;
|
---|
2690 |
|
---|
2691 | TREEVIEW_SendExpanded(infoPtr, wineItem, TVE_EXPAND);
|
---|
2692 |
|
---|
2693 | //TRACE(" TVN_ITEMEXPANDED sent...\n");
|
---|
2694 | }
|
---|
2695 | else
|
---|
2696 | {
|
---|
2697 | /* this item has already been expanded */
|
---|
2698 | wineItem->state |= TVIS_EXPANDED;
|
---|
2699 | }
|
---|
2700 |
|
---|
2701 | //if (bExpandPartial)
|
---|
2702 | // FIXME("TVE_EXPANDPARTIAL not implemented\n");
|
---|
2703 |
|
---|
2704 | //update window
|
---|
2705 | //CB: todo: optimize!
|
---|
2706 | TREEVIEW_UnqueueRefresh(infoPtr,TRUE,FALSE);
|
---|
2707 |
|
---|
2708 | /* Scroll up so that as many children as possible are visible.
|
---|
2709 | * This looses when expanding causes an HScroll bar to appear, but we
|
---|
2710 | * don't know that yet, so the last item is obscured. */
|
---|
2711 | if (wineItem->firstChild && wineItem->inclient && (infoPtr->firstVisible != wineItem) && (wineItem->lastChild->rect.bottom > infoPtr->clientHeight))
|
---|
2712 | {
|
---|
2713 | INT childrenH = wineItem->lastChild->rect.bottom-wineItem->firstChild->rect.top;
|
---|
2714 | INT itemH = wineItem->rect.bottom-wineItem->rect.top;
|
---|
2715 | INT clientH = ((INT)(infoPtr->clientHeight/infoPtr->uItemHeight))*infoPtr->uItemHeight;
|
---|
2716 |
|
---|
2717 | if (itemH+childrenH > clientH)
|
---|
2718 | {
|
---|
2719 | infoPtr->lefttop.y += wineItem->rect.top;
|
---|
2720 | } else
|
---|
2721 | {
|
---|
2722 | INT diff = wineItem->lastChild->rect.bottom-clientH;
|
---|
2723 |
|
---|
2724 | infoPtr->lefttop.y += diff;
|
---|
2725 | }
|
---|
2726 | }
|
---|
2727 |
|
---|
2728 | TREEVIEW_CalcItems(infoPtr);
|
---|
2729 | TREEVIEW_Refresh(infoPtr);
|
---|
2730 | //CB: todo: check cx and cy to fit ranges!
|
---|
2731 |
|
---|
2732 | return TRUE;
|
---|
2733 | }
|
---|
2734 |
|
---|
2735 | static BOOL
|
---|
2736 | TREEVIEW_Toggle(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem, BOOL bUser)
|
---|
2737 | {
|
---|
2738 | if (wineItem->state & TVIS_EXPANDED)
|
---|
2739 | return TREEVIEW_Collapse(infoPtr, wineItem, FALSE, bUser);
|
---|
2740 | else
|
---|
2741 | return TREEVIEW_Expand(infoPtr, wineItem, FALSE, bUser);
|
---|
2742 | }
|
---|
2743 |
|
---|
2744 | static VOID
|
---|
2745 | TREEVIEW_ExpandAll(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
|
---|
2746 | {
|
---|
2747 | TREEVIEW_Expand(infoPtr, item, FALSE, TRUE);
|
---|
2748 |
|
---|
2749 | for (item = item->firstChild; item != NULL; item = item->nextSibling)
|
---|
2750 | {
|
---|
2751 | if (TREEVIEW_HasChildren(infoPtr, item))
|
---|
2752 | TREEVIEW_ExpandAll(infoPtr, item);
|
---|
2753 | }
|
---|
2754 | }
|
---|
2755 |
|
---|
2756 | /* Note:If the specified item is the child of a collapsed parent item,
|
---|
2757 | the parent's list of child items is (recursively) expanded to reveal the
|
---|
2758 | specified item. This is mentioned for TREEVIEW_SelectItem; don't
|
---|
2759 | know if it also applies here.
|
---|
2760 | */
|
---|
2761 |
|
---|
2762 | static LRESULT
|
---|
2763 | TREEVIEW_ExpandMsg(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
2764 | {
|
---|
2765 | TREEVIEW_ITEM *wineItem = (HTREEITEM)lParam;
|
---|
2766 | UINT flag = wParam;
|
---|
2767 |
|
---|
2768 | if (!TREEVIEW_ValidItem(infoPtr, wineItem))
|
---|
2769 | return 0;
|
---|
2770 |
|
---|
2771 | switch (flag & TVE_TOGGLE)
|
---|
2772 | {
|
---|
2773 | case TVE_COLLAPSE:
|
---|
2774 | return TREEVIEW_Collapse(infoPtr, wineItem, flag & TVE_COLLAPSERESET,
|
---|
2775 | FALSE);
|
---|
2776 |
|
---|
2777 | case TVE_EXPAND:
|
---|
2778 | return TREEVIEW_Expand(infoPtr, wineItem, flag & TVE_EXPANDPARTIAL,
|
---|
2779 | FALSE);
|
---|
2780 |
|
---|
2781 | case TVE_TOGGLE:
|
---|
2782 | return TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
|
---|
2783 |
|
---|
2784 | default:
|
---|
2785 | return 0;
|
---|
2786 | }
|
---|
2787 |
|
---|
2788 | }
|
---|
2789 |
|
---|
2790 | /* Hit-Testing **********************************************************/
|
---|
2791 |
|
---|
2792 | static TREEVIEW_ITEM *
|
---|
2793 | TREEVIEW_HitTestPoint(TREEVIEW_INFO *infoPtr,POINT pt)
|
---|
2794 | {
|
---|
2795 | TREEVIEW_ITEM *wineItem;
|
---|
2796 |
|
---|
2797 | if (!infoPtr->firstVisible)
|
---|
2798 | return NULL;
|
---|
2799 |
|
---|
2800 | wineItem = infoPtr->firstVisible;
|
---|
2801 |
|
---|
2802 | while (wineItem && (pt.y > wineItem->rect.bottom))
|
---|
2803 | wineItem = TREEVIEW_GetNextListItem(infoPtr,wineItem);
|
---|
2804 |
|
---|
2805 | return wineItem;
|
---|
2806 | }
|
---|
2807 |
|
---|
2808 | static LRESULT
|
---|
2809 | TREEVIEW_HitTest(TREEVIEW_INFO *infoPtr,LPTVHITTESTINFO lpht,BOOL ignoreClientRect)
|
---|
2810 | {
|
---|
2811 | TREEVIEW_ITEM *wineItem;
|
---|
2812 | RECT rect;
|
---|
2813 | UINT status, x, y;
|
---|
2814 |
|
---|
2815 | if (!lpht) return 0;
|
---|
2816 |
|
---|
2817 | status = 0;
|
---|
2818 | x = lpht->pt.x;
|
---|
2819 | y = lpht->pt.y;
|
---|
2820 | lpht->hItem = 0;
|
---|
2821 |
|
---|
2822 | if (!ignoreClientRect)
|
---|
2823 | {
|
---|
2824 | GetClientRect(infoPtr->hwnd,&rect);
|
---|
2825 |
|
---|
2826 | if (x < rect.left) status |= TVHT_TOLEFT;
|
---|
2827 | else if (x > rect.right) status |= TVHT_TORIGHT;
|
---|
2828 | if (y < rect.top) status |= TVHT_ABOVE;
|
---|
2829 | else if (y > rect.bottom) status |= TVHT_BELOW;
|
---|
2830 |
|
---|
2831 | if (status)
|
---|
2832 | {
|
---|
2833 | lpht->flags = status;
|
---|
2834 | return (LRESULT)(HTREEITEM)NULL;
|
---|
2835 | }
|
---|
2836 | }
|
---|
2837 |
|
---|
2838 | wineItem = TREEVIEW_HitTestPoint(infoPtr,lpht->pt);
|
---|
2839 | if (!wineItem)
|
---|
2840 | {
|
---|
2841 | lpht->flags = TVHT_NOWHERE;
|
---|
2842 | return (LRESULT)(HTREEITEM)NULL;
|
---|
2843 | }
|
---|
2844 |
|
---|
2845 | if (!wineItem->calculated)
|
---|
2846 | TREEVIEW_CalcItem(infoPtr,wineItem,0);
|
---|
2847 |
|
---|
2848 | if (x >= wineItem->textOffset + wineItem->textWidth)
|
---|
2849 | {
|
---|
2850 | lpht->flags = TVHT_ONITEMRIGHT;
|
---|
2851 | }
|
---|
2852 | else if (x >= wineItem->textOffset)
|
---|
2853 | {
|
---|
2854 | lpht->flags = TVHT_ONITEMLABEL;
|
---|
2855 | }
|
---|
2856 | else if (x >= wineItem->imageOffset)
|
---|
2857 | {
|
---|
2858 | lpht->flags = TVHT_ONITEMICON;
|
---|
2859 | }
|
---|
2860 | else if (x >= wineItem->stateOffset)
|
---|
2861 | {
|
---|
2862 | lpht->flags = TVHT_ONITEMSTATEICON;
|
---|
2863 | }
|
---|
2864 | else if ((x >= wineItem->linesOffset) && (infoPtr->dwStyle & TVS_HASBUTTONS))
|
---|
2865 | {
|
---|
2866 | lpht->flags = TVHT_ONITEMBUTTON;
|
---|
2867 | }
|
---|
2868 | else
|
---|
2869 | {
|
---|
2870 | lpht->flags = TVHT_ONITEMINDENT;
|
---|
2871 | }
|
---|
2872 |
|
---|
2873 | lpht->hItem = wineItem;
|
---|
2874 | //TRACE("(%ld,%ld):result %x\n", lpht->pt.x, lpht->pt.y, lpht->flags);
|
---|
2875 |
|
---|
2876 | return (LRESULT)wineItem;
|
---|
2877 | }
|
---|
2878 |
|
---|
2879 | /* Item Label Editing ***************************************************/
|
---|
2880 |
|
---|
2881 | static LRESULT
|
---|
2882 | TREEVIEW_GetEditControl(TREEVIEW_INFO *infoPtr)
|
---|
2883 | {
|
---|
2884 | return infoPtr->hwndEdit;
|
---|
2885 | }
|
---|
2886 |
|
---|
2887 | static LRESULT CALLBACK
|
---|
2888 | TREEVIEW_Edit_SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
2889 | {
|
---|
2890 | TREEVIEW_INFO *infoPtr;
|
---|
2891 | BOOL bCancel = FALSE;
|
---|
2892 |
|
---|
2893 | switch (uMsg)
|
---|
2894 | {
|
---|
2895 | case WM_PAINT:
|
---|
2896 | {
|
---|
2897 | LRESULT rc;
|
---|
2898 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
|
---|
2899 |
|
---|
2900 | //TRACE("WM_PAINT start\n");
|
---|
2901 | rc = CallWindowProcA(infoPtr->wpEditOrig, hwnd, uMsg, wParam,
|
---|
2902 | lParam);
|
---|
2903 | //TRACE("WM_PAINT done\n");
|
---|
2904 | return rc;
|
---|
2905 | }
|
---|
2906 |
|
---|
2907 | case WM_KILLFOCUS:
|
---|
2908 | {
|
---|
2909 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
|
---|
2910 | if (infoPtr->bIgnoreEditKillFocus)
|
---|
2911 | return TRUE;
|
---|
2912 |
|
---|
2913 | break;
|
---|
2914 | }
|
---|
2915 |
|
---|
2916 | case WM_GETDLGCODE:
|
---|
2917 | return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
|
---|
2918 |
|
---|
2919 | case WM_KEYDOWN:
|
---|
2920 | if (wParam == (WPARAM)VK_ESCAPE)
|
---|
2921 | {
|
---|
2922 | bCancel = TRUE;
|
---|
2923 | break;
|
---|
2924 | }
|
---|
2925 | else if (wParam == (WPARAM)VK_RETURN)
|
---|
2926 | {
|
---|
2927 | break;
|
---|
2928 | }
|
---|
2929 |
|
---|
2930 | /* fall through */
|
---|
2931 | default:
|
---|
2932 | {
|
---|
2933 | TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
|
---|
2934 |
|
---|
2935 | //@@@PH 1999/11/05 method called with freed infoPtr memory object
|
---|
2936 | if (infoPtr != NULL)
|
---|
2937 | return CallWindowProcA(infoPtr->wpEditOrig, hwnd, uMsg, wParam, lParam);
|
---|
2938 | else
|
---|
2939 | break;
|
---|
2940 | }
|
---|
2941 | }
|
---|
2942 |
|
---|
2943 | /* Processing TVN_ENDLABELEDIT message could kill the focus */
|
---|
2944 | /* eg. Using a messagebox */
|
---|
2945 |
|
---|
2946 | infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
|
---|
2947 | infoPtr->bIgnoreEditKillFocus = TRUE;
|
---|
2948 | TREEVIEW_EndEditLabelNow(infoPtr, bCancel || !infoPtr->bLabelChanged);
|
---|
2949 | infoPtr->bIgnoreEditKillFocus = FALSE;
|
---|
2950 |
|
---|
2951 | return 0;
|
---|
2952 | }
|
---|
2953 |
|
---|
2954 |
|
---|
2955 | /* should handle edit control messages here */
|
---|
2956 |
|
---|
2957 | static LRESULT
|
---|
2958 | TREEVIEW_Command(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
2959 | {
|
---|
2960 | //TRACE("%x %ld\n", wParam, lParam);
|
---|
2961 |
|
---|
2962 | switch (HIWORD(wParam))
|
---|
2963 | {
|
---|
2964 | case EN_UPDATE:
|
---|
2965 | {
|
---|
2966 | /*
|
---|
2967 | * Adjust the edit window size
|
---|
2968 | */
|
---|
2969 | char buffer[1024];
|
---|
2970 | TREEVIEW_ITEM *editItem = infoPtr->selectedItem;
|
---|
2971 | HDC hdc = GetDC(infoPtr->hwndEdit);
|
---|
2972 | SIZE sz;
|
---|
2973 | int len;
|
---|
2974 | HFONT hFont, hOldFont = 0;
|
---|
2975 |
|
---|
2976 | infoPtr->bLabelChanged = TRUE;
|
---|
2977 |
|
---|
2978 | len = GetWindowTextA(infoPtr->hwndEdit, buffer, sizeof(buffer));
|
---|
2979 |
|
---|
2980 | /* Select font to get the right dimension of the string */
|
---|
2981 | hFont = SendMessageA(infoPtr->hwndEdit, WM_GETFONT, 0, 0);
|
---|
2982 | if (hFont != 0)
|
---|
2983 | {
|
---|
2984 | hOldFont = SelectObject(hdc, hFont);
|
---|
2985 | }
|
---|
2986 |
|
---|
2987 | if (GetTextExtentPoint32A(hdc, buffer, strlen(buffer), &sz))
|
---|
2988 | {
|
---|
2989 | TEXTMETRICA textMetric;
|
---|
2990 |
|
---|
2991 | /* Add Extra spacing for the next character */
|
---|
2992 | GetTextMetricsA(hdc, &textMetric);
|
---|
2993 | sz.cx += (textMetric.tmMaxCharWidth * 2);
|
---|
2994 |
|
---|
2995 | sz.cx = MAX(sz.cx, textMetric.tmMaxCharWidth * 3);
|
---|
2996 | sz.cx = MIN(sz.cx,
|
---|
2997 | infoPtr->clientWidth - editItem->textOffset + 2);
|
---|
2998 |
|
---|
2999 | SetWindowPos(infoPtr->hwndEdit,
|
---|
3000 | HWND_TOP,
|
---|
3001 | 0,
|
---|
3002 | 0,
|
---|
3003 | sz.cx,
|
---|
3004 | editItem->rect.bottom - editItem->rect.top + 3,
|
---|
3005 | SWP_NOMOVE | SWP_DRAWFRAME);
|
---|
3006 | }
|
---|
3007 |
|
---|
3008 | if (hFont != 0)
|
---|
3009 | {
|
---|
3010 | SelectObject(hdc, hOldFont);
|
---|
3011 | }
|
---|
3012 |
|
---|
3013 | ReleaseDC(infoPtr->hwnd, hdc);
|
---|
3014 | break;
|
---|
3015 | }
|
---|
3016 |
|
---|
3017 | default:
|
---|
3018 | return SendMessageA(GetParent(infoPtr->hwnd), WM_COMMAND, wParam, lParam);
|
---|
3019 | }
|
---|
3020 |
|
---|
3021 | return 0;
|
---|
3022 | }
|
---|
3023 |
|
---|
3024 | HWND TREEVIEW_EditLabel(TREEVIEW_INFO *infoPtr,HTREEITEM hItem,BOOL unicode)
|
---|
3025 | {
|
---|
3026 | SIZE sz;
|
---|
3027 | TREEVIEW_ITEM *editItem = hItem;
|
---|
3028 | HINSTANCE hinst = GetWindowLongA(infoPtr->hwnd,GWL_HINSTANCE);
|
---|
3029 | HDC hdc;
|
---|
3030 | HFONT hOldFont = 0;
|
---|
3031 | TEXTMETRICA textMetric;
|
---|
3032 | CHAR* textA = NULL;
|
---|
3033 | NMTVDISPINFOW tvdi;
|
---|
3034 |
|
---|
3035 | if (!TREEVIEW_ValidItem(infoPtr, editItem))
|
---|
3036 | return (HWND)NULL;
|
---|
3037 |
|
---|
3038 | if(infoPtr->hwndEdit)
|
---|
3039 | return infoPtr->hwndEdit;
|
---|
3040 |
|
---|
3041 | infoPtr->bLabelChanged = FALSE;
|
---|
3042 |
|
---|
3043 | /* Make shure that edit item is selected */
|
---|
3044 |
|
---|
3045 | TREEVIEW_DoSelectItem ( infoPtr, TVGN_CARET, hItem, TVC_UNKNOWN);
|
---|
3046 |
|
---|
3047 | TREEVIEW_UpdateDispInfo(infoPtr, editItem, TVIF_TEXT);
|
---|
3048 |
|
---|
3049 | hdc = GetDC(infoPtr->hwnd);
|
---|
3050 | /* Select the font to get appropriate metric dimensions */
|
---|
3051 | if(infoPtr->hFont != 0)
|
---|
3052 | {
|
---|
3053 | hOldFont = SelectObject(hdc, infoPtr->hFont);
|
---|
3054 | }
|
---|
3055 |
|
---|
3056 | /*Get String Lenght in pixels */
|
---|
3057 | GetTextExtentPoint32W(hdc,editItem->pszText,lstrlenW(editItem->pszText),&sz);
|
---|
3058 |
|
---|
3059 | /*Add Extra spacing for the next character */
|
---|
3060 | GetTextMetricsA(hdc, &textMetric);
|
---|
3061 | sz.cx += (textMetric.tmMaxCharWidth * 2);
|
---|
3062 |
|
---|
3063 | sz.cx = MAX(sz.cx, textMetric.tmMaxCharWidth * 3);
|
---|
3064 | sz.cx = MIN(sz.cx, infoPtr->clientWidth - editItem->textOffset + 2);
|
---|
3065 |
|
---|
3066 | if(infoPtr->hFont != 0)
|
---|
3067 | {
|
---|
3068 | SelectObject(hdc, hOldFont);
|
---|
3069 | }
|
---|
3070 |
|
---|
3071 | ReleaseDC(infoPtr->hwnd, hdc);
|
---|
3072 | infoPtr->hwndEdit = CreateWindowExA (
|
---|
3073 | WS_EX_LEFT,
|
---|
3074 | "EDIT",
|
---|
3075 | 0,
|
---|
3076 | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL | WS_CLIPSIBLINGS |
|
---|
3077 | ES_WANTRETURN | ES_LEFT,
|
---|
3078 | editItem->textOffset - 2, editItem->rect.top - 1,
|
---|
3079 | sz.cx+3, editItem->rect.bottom - editItem->rect.top + 3,
|
---|
3080 | infoPtr->hwnd,
|
---|
3081 | 0,hinst,0); /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0);*/
|
---|
3082 |
|
---|
3083 | /* Get a 2D border. */
|
---|
3084 | SetWindowLongA(infoPtr->hwndEdit, GWL_EXSTYLE,GetWindowLongA(infoPtr->hwndEdit, GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
|
---|
3085 | SetWindowLongA(infoPtr->hwndEdit, GWL_STYLE,GetWindowLongA(infoPtr->hwndEdit, GWL_STYLE) | WS_BORDER);
|
---|
3086 |
|
---|
3087 | SendMessageA(infoPtr->hwndEdit, WM_SETFONT, TREEVIEW_FontForItem(infoPtr, editItem),FALSE);
|
---|
3088 |
|
---|
3089 | infoPtr->wpEditOrig = (WNDPROC)SetWindowLongA (infoPtr->hwndEdit,GWL_WNDPROC,(DWORD)TREEVIEW_Edit_SubclassProc);
|
---|
3090 |
|
---|
3091 | tvdi.item.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
|
---|
3092 | tvdi.item.hItem = editItem;
|
---|
3093 | tvdi.item.state = editItem->state;
|
---|
3094 | tvdi.item.lParam = editItem->lParam;
|
---|
3095 | if (isUnicodeNotify(&infoPtr->header))
|
---|
3096 | {
|
---|
3097 | tvdi.item.pszText = editItem->pszText;
|
---|
3098 | } else
|
---|
3099 | {
|
---|
3100 | textA = HEAP_strdupWtoA(GetProcessHeap(),0,editItem->pszText);
|
---|
3101 | tvdi.item.pszText = (LPWSTR)textA;
|
---|
3102 | }
|
---|
3103 |
|
---|
3104 | if (sendNotify(infoPtr->hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_BEGINLABELEDITW:TVN_BEGINLABELEDITA,&tvdi.hdr))
|
---|
3105 | {
|
---|
3106 | DestroyWindow(infoPtr->hwndEdit);
|
---|
3107 | infoPtr->hwndEdit = 0;
|
---|
3108 | if (textA) HeapFree(GetProcessHeap(),0,textA);
|
---|
3109 |
|
---|
3110 | return (HWND)0;
|
---|
3111 | }
|
---|
3112 | if (textA) HeapFree(GetProcessHeap(),0,textA);
|
---|
3113 |
|
---|
3114 | infoPtr->selectedItem = hItem;
|
---|
3115 | SetWindowTextW(infoPtr->hwndEdit,editItem->pszText);
|
---|
3116 | SetFocus(infoPtr->hwndEdit);
|
---|
3117 | SendMessageA(infoPtr->hwndEdit, EM_SETSEL, 0, -1);
|
---|
3118 | ShowWindow(infoPtr->hwndEdit, SW_SHOW);
|
---|
3119 |
|
---|
3120 | return infoPtr->hwndEdit;
|
---|
3121 | }
|
---|
3122 |
|
---|
3123 |
|
---|
3124 | static LRESULT
|
---|
3125 | TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr,BOOL bCancel)
|
---|
3126 | {
|
---|
3127 | TREEVIEW_ITEM *editedItem = infoPtr->selectedItem;
|
---|
3128 | NMTVDISPINFOW tvdi;
|
---|
3129 | DWORD dwStyle = GetWindowLongA(infoPtr->hwnd,GWL_STYLE);
|
---|
3130 | BOOL bCommit;
|
---|
3131 | WCHAR *textW = NULL;
|
---|
3132 | CHAR *textA = NULL;
|
---|
3133 | int iLength = 0;
|
---|
3134 |
|
---|
3135 | if (!infoPtr->hwndEdit)
|
---|
3136 | return FALSE;
|
---|
3137 |
|
---|
3138 | tvdi.item.mask = 0;
|
---|
3139 | tvdi.item.hItem = editedItem;
|
---|
3140 | tvdi.item.state = editedItem->state;
|
---|
3141 | tvdi.item.lParam = editedItem->lParam;
|
---|
3142 |
|
---|
3143 | if (!bCancel)
|
---|
3144 | {
|
---|
3145 | textW = (WCHAR*)COMCTL32_Alloc(1024*sizeof(WCHAR));
|
---|
3146 | iLength = GetWindowTextW(infoPtr->hwndEdit,textW,1023);
|
---|
3147 |
|
---|
3148 | if (isUnicodeNotify(&infoPtr->header)) tvdi.item.pszText = textW; else
|
---|
3149 | {
|
---|
3150 | INT len = iLength+1;
|
---|
3151 |
|
---|
3152 | textA = (CHAR*)COMCTL32_Alloc(1024*sizeof(CHAR));
|
---|
3153 | lstrcpynWtoA(textA,textW,len);
|
---|
3154 | tvdi.item.pszText = (WCHAR*)textA;
|
---|
3155 | }
|
---|
3156 | tvdi.item.cchTextMax = iLength + 1;
|
---|
3157 | } else
|
---|
3158 | {
|
---|
3159 | tvdi.item.pszText = NULL;
|
---|
3160 | tvdi.item.cchTextMax = 0;
|
---|
3161 | }
|
---|
3162 |
|
---|
3163 | bCommit = (BOOL)sendNotify(infoPtr->hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_ENDLABELEDITW:TVN_ENDLABELEDITA,&tvdi.hdr);
|
---|
3164 |
|
---|
3165 | if (!bCancel && bCommit) /* Apply the changes */
|
---|
3166 | {
|
---|
3167 | BOOL mustFree = FALSE;
|
---|
3168 |
|
---|
3169 | if (!isUnicodeNotify(&infoPtr->header))
|
---|
3170 | lstrcpynAtoW(textW,textA,iLength+1);
|
---|
3171 |
|
---|
3172 | if (lstrcmpW(textW,editedItem->pszText) != 0)
|
---|
3173 | {
|
---|
3174 | if (editedItem->callbackMask & TVIF_TEXT)
|
---|
3175 | {
|
---|
3176 | NMTVDISPINFOW tvdi;
|
---|
3177 | BOOL retval;
|
---|
3178 |
|
---|
3179 | tvdi.item.mask = TVIF_TEXT;
|
---|
3180 | tvdi.item.hItem = editedItem;
|
---|
3181 | tvdi.item.state = editedItem->state;
|
---|
3182 | tvdi.item.lParam = editedItem->lParam;
|
---|
3183 | if (isUnicodeNotify(&infoPtr->header))
|
---|
3184 | {
|
---|
3185 | tvdi.item.pszText = textW;
|
---|
3186 | tvdi.item.cchTextMax = lstrlenW(textW)+1;
|
---|
3187 | } else
|
---|
3188 | {
|
---|
3189 | tvdi.item.pszText = (LPWSTR)textA;
|
---|
3190 | tvdi.item.cchTextMax = lstrlenA(textA)+1;
|
---|
3191 | }
|
---|
3192 |
|
---|
3193 | retval = (BOOL)sendNotify(infoPtr->hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_SETDISPINFOW:TVN_SETDISPINFOA,&tvdi.hdr);
|
---|
3194 | } else
|
---|
3195 | {
|
---|
3196 | if (!COMCTL32_ReAlloc(editedItem->pszText,(iLength+1)*sizeof(WCHAR)))
|
---|
3197 | {
|
---|
3198 | //ERR("OutOfMemory, cannot allocate space for label");
|
---|
3199 | DestroyWindow(infoPtr->hwndEdit);
|
---|
3200 | infoPtr->hwndEdit = 0;
|
---|
3201 | if (textA) COMCTL32_Free(textA);
|
---|
3202 | if (textW) COMCTL32_Free(textW);
|
---|
3203 |
|
---|
3204 | return FALSE;
|
---|
3205 | } else
|
---|
3206 | {
|
---|
3207 | editedItem->cchTextMax = iLength + 1;
|
---|
3208 | lstrcpyW(editedItem->pszText,textW);
|
---|
3209 | }
|
---|
3210 | }
|
---|
3211 | }
|
---|
3212 | }
|
---|
3213 |
|
---|
3214 | ShowWindow(infoPtr->hwndEdit, SW_HIDE);
|
---|
3215 | DestroyWindow(infoPtr->hwndEdit);
|
---|
3216 | infoPtr->hwndEdit = 0;
|
---|
3217 | if (textA) COMCTL32_Free(textA);
|
---|
3218 | if (textW) COMCTL32_Free(textW);
|
---|
3219 |
|
---|
3220 | editedItem->calculated = FALSE;
|
---|
3221 | TREEVIEW_RefreshItem(infoPtr,editedItem,0);
|
---|
3222 |
|
---|
3223 | return TRUE;
|
---|
3224 | }
|
---|
3225 |
|
---|
3226 | static LRESULT
|
---|
3227 | TREEVIEW_HandleTimer (TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
3228 | {
|
---|
3229 | switch (wParam)
|
---|
3230 | {
|
---|
3231 | case TV_REFRESH_TIMER:
|
---|
3232 | KillTimer(infoPtr->hwnd,TV_REFRESH_TIMER);
|
---|
3233 | infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
|
---|
3234 | TREEVIEW_CalcItems(infoPtr);
|
---|
3235 | TREEVIEW_Refresh(infoPtr);
|
---|
3236 | return 0;
|
---|
3237 |
|
---|
3238 | case TV_EDIT_TIMER:
|
---|
3239 | KillTimer(infoPtr->hwnd,TV_EDIT_TIMER);
|
---|
3240 | infoPtr->Timer &= ~TV_EDIT_TIMER_SET;
|
---|
3241 | TREEVIEW_EditLabel(infoPtr,infoPtr->selectedItem,TRUE);
|
---|
3242 | return 0;
|
---|
3243 |
|
---|
3244 | case TV_INFOTIP_TIMER:
|
---|
3245 | TREEVIEW_CheckInfoTip(infoPtr);
|
---|
3246 | return 0;
|
---|
3247 | }
|
---|
3248 |
|
---|
3249 | return 1;
|
---|
3250 | }
|
---|
3251 |
|
---|
3252 | /* Mouse Tracking/Drag **************************************************/
|
---|
3253 |
|
---|
3254 | /***************************************************************************
|
---|
3255 | * This is quite unusual piece of code, but that's how it's implemented in
|
---|
3256 | * Windows.
|
---|
3257 | */
|
---|
3258 | static LRESULT
|
---|
3259 | TREEVIEW_TrackMouse(TREEVIEW_INFO *infoPtr, POINT pt)
|
---|
3260 | {
|
---|
3261 | INT cxDrag = GetSystemMetrics(SM_CXDRAG);
|
---|
3262 | INT cyDrag = GetSystemMetrics(SM_CYDRAG);
|
---|
3263 | RECT r;
|
---|
3264 | MSG msg;
|
---|
3265 |
|
---|
3266 | r.top = pt.y - cyDrag;
|
---|
3267 | r.left = pt.x - cxDrag;
|
---|
3268 | r.bottom = pt.y + cyDrag;
|
---|
3269 | r.right = pt.x + cxDrag;
|
---|
3270 |
|
---|
3271 | SetCapture(infoPtr->hwnd);
|
---|
3272 |
|
---|
3273 | while (1)
|
---|
3274 | {
|
---|
3275 | if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD))
|
---|
3276 | {
|
---|
3277 | if (msg.message == WM_MOUSEMOVE)
|
---|
3278 | {
|
---|
3279 | pt.x = (INT)LOWORD(msg.lParam);
|
---|
3280 | pt.y = (INT)HIWORD(msg.lParam);
|
---|
3281 | if (PtInRect(&r, pt))
|
---|
3282 | continue;
|
---|
3283 | else
|
---|
3284 | {
|
---|
3285 | ReleaseCapture();
|
---|
3286 | return 1;
|
---|
3287 | }
|
---|
3288 | }
|
---|
3289 | else if (msg.message >= WM_LBUTTONDOWN &&
|
---|
3290 | msg.message <= WM_RBUTTONDBLCLK)
|
---|
3291 | {
|
---|
3292 | if (msg.message == WM_RBUTTONUP)
|
---|
3293 | TREEVIEW_RButtonUp(infoPtr, &pt);
|
---|
3294 | break;
|
---|
3295 | }
|
---|
3296 |
|
---|
3297 | DispatchMessageA(&msg);
|
---|
3298 | }
|
---|
3299 |
|
---|
3300 | if (GetCapture() != infoPtr->hwnd)
|
---|
3301 | return 0;
|
---|
3302 | }
|
---|
3303 |
|
---|
3304 | ReleaseCapture();
|
---|
3305 | return 0;
|
---|
3306 | }
|
---|
3307 |
|
---|
3308 | static LRESULT
|
---|
3309 | TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
3310 | {
|
---|
3311 | TREEVIEW_ITEM *wineItem;
|
---|
3312 | TV_HITTESTINFO hit;
|
---|
3313 |
|
---|
3314 | hit.pt.x = (INT)LOWORD(lParam);
|
---|
3315 | hit.pt.y = (INT)HIWORD(lParam);
|
---|
3316 | SetFocus (infoPtr->hwnd);
|
---|
3317 |
|
---|
3318 | if (infoPtr->Timer & TV_EDIT_TIMER_SET)
|
---|
3319 | {
|
---|
3320 | /* If there is pending 'edit label' event - kill it now */
|
---|
3321 | KillTimer(infoPtr->hwnd,TV_EDIT_TIMER);
|
---|
3322 | }
|
---|
3323 |
|
---|
3324 | wineItem = (TREEVIEW_ITEM *)TREEVIEW_HitTest(infoPtr,&hit,FALSE);
|
---|
3325 | if (!wineItem)
|
---|
3326 | return 0;
|
---|
3327 |
|
---|
3328 | //MSDN documentation says: stop on non zero. but this isn't true in this case
|
---|
3329 | if (!sendNotify(infoPtr->hwnd,NM_DBLCLK))
|
---|
3330 | { /* FIXME! */
|
---|
3331 | switch (hit.flags)
|
---|
3332 | {
|
---|
3333 | case TVHT_ONITEMRIGHT:
|
---|
3334 | /* FIXME: we should not have send NM_DBLCLK in this case. */
|
---|
3335 | break;
|
---|
3336 |
|
---|
3337 | case TVHT_ONITEMINDENT:
|
---|
3338 | if (!(infoPtr->dwStyle & TVS_HASLINES))
|
---|
3339 | {
|
---|
3340 | break;
|
---|
3341 | } else
|
---|
3342 | {
|
---|
3343 | int level = hit.pt.x / infoPtr->uIndent;
|
---|
3344 |
|
---|
3345 | if (!(infoPtr->dwStyle & TVS_LINESATROOT)) level++;
|
---|
3346 |
|
---|
3347 | while (wineItem->iLevel > level)
|
---|
3348 | {
|
---|
3349 | wineItem = wineItem->parent;
|
---|
3350 | }
|
---|
3351 |
|
---|
3352 | /* fall through */
|
---|
3353 | }
|
---|
3354 |
|
---|
3355 | case TVHT_ONITEMLABEL:
|
---|
3356 | case TVHT_ONITEMICON:
|
---|
3357 | case TVHT_ONITEMSTATEICON:
|
---|
3358 | case TVHT_ONITEMBUTTON:
|
---|
3359 | TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
|
---|
3360 | break;
|
---|
3361 | }
|
---|
3362 | }
|
---|
3363 |
|
---|
3364 | return TRUE;
|
---|
3365 | }
|
---|
3366 |
|
---|
3367 | static LRESULT
|
---|
3368 | TREEVIEW_LButtonDown(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
3369 | {
|
---|
3370 | TVHITTESTINFO ht;
|
---|
3371 | BOOL bTrack;
|
---|
3372 |
|
---|
3373 | /* If Edit control is active - kill it and return.
|
---|
3374 | * The best way to do it is to set focus to itself.
|
---|
3375 | * Edit control subclassed procedure will automatically call
|
---|
3376 | * EndEditLabelNow.
|
---|
3377 | */
|
---|
3378 | if (infoPtr->hwndEdit)
|
---|
3379 | {
|
---|
3380 | SetFocus(infoPtr->hwnd);
|
---|
3381 | return 0;
|
---|
3382 | }
|
---|
3383 |
|
---|
3384 | ht.pt.x = (INT)LOWORD(lParam);
|
---|
3385 | ht.pt.y = (INT)HIWORD(lParam);
|
---|
3386 |
|
---|
3387 | TREEVIEW_HitTest(infoPtr,&ht,FALSE);
|
---|
3388 |
|
---|
3389 | bTrack = (ht.flags & TVHT_ONITEM) && !(infoPtr->dwStyle & TVS_DISABLEDRAGDROP);
|
---|
3390 |
|
---|
3391 | /* Send NM_CLICK right away */
|
---|
3392 | if (!bTrack)
|
---|
3393 | if (sendNotify(infoPtr->hwnd,NM_CLICK))
|
---|
3394 | goto setfocus;
|
---|
3395 |
|
---|
3396 | if (ht.flags & TVHT_ONITEMBUTTON)
|
---|
3397 | {
|
---|
3398 | TREEVIEW_Toggle(infoPtr,ht.hItem,TRUE);
|
---|
3399 | goto setfocus;
|
---|
3400 | } else if (bTrack)
|
---|
3401 | {
|
---|
3402 | if (TREEVIEW_TrackMouse(infoPtr,ht.pt))
|
---|
3403 | {
|
---|
3404 | TREEVIEW_SendTreeviewDnDNotify(infoPtr,isUnicodeNotify(&infoPtr->header) ? TVN_BEGINDRAGW:TVN_BEGINDRAGA, ht.hItem, ht.pt);
|
---|
3405 | infoPtr->dropItem = ht.hItem;
|
---|
3406 | return 0;
|
---|
3407 | }
|
---|
3408 | }
|
---|
3409 |
|
---|
3410 | if (sendNotify(infoPtr->hwnd,NM_CLICK))
|
---|
3411 | goto setfocus;
|
---|
3412 |
|
---|
3413 | /*
|
---|
3414 | * If the style allow editing and the node is already selected
|
---|
3415 | * and the click occured on the item label...
|
---|
3416 | */
|
---|
3417 | if ((infoPtr->dwStyle & TVS_EDITLABELS) && (ht.flags & TVHT_ONITEMLABEL) && (infoPtr->selectedItem == ht.hItem))
|
---|
3418 | {
|
---|
3419 | if (infoPtr->Timer & TV_EDIT_TIMER_SET)
|
---|
3420 | KillTimer(infoPtr->hwnd,TV_EDIT_TIMER);
|
---|
3421 |
|
---|
3422 | SetTimer(infoPtr->hwnd,TV_EDIT_TIMER,GetDoubleClickTime(),0);
|
---|
3423 | infoPtr->Timer |= TV_EDIT_TIMER_SET;
|
---|
3424 | } else if (ht.flags & (TVHT_ONITEMLABEL | TVHT_ONITEMICON))
|
---|
3425 | {
|
---|
3426 | TREEVIEW_DoSelectItem(infoPtr,TVGN_CARET,ht.hItem,TVC_BYMOUSE);
|
---|
3427 | } else if (ht.flags & TVHT_ONITEMSTATEICON)
|
---|
3428 | {
|
---|
3429 | if (infoPtr->dwStyle & TVS_CHECKBOXES)
|
---|
3430 | {
|
---|
3431 | /* TVS_CHECKBOXES requires us to toggle the current state */
|
---|
3432 | if (infoPtr->dwStyle & TVS_CHECKBOXES)
|
---|
3433 | TREEVIEW_ToggleItemState(infoPtr,ht.hItem);
|
---|
3434 | }
|
---|
3435 | }
|
---|
3436 |
|
---|
3437 | setfocus:
|
---|
3438 | SetFocus(infoPtr->hwnd);
|
---|
3439 |
|
---|
3440 | return 0;
|
---|
3441 | }
|
---|
3442 |
|
---|
3443 | static LRESULT
|
---|
3444 | TREEVIEW_RButtonDown(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
3445 | {
|
---|
3446 | TVHITTESTINFO ht;
|
---|
3447 |
|
---|
3448 | if (infoPtr->hwndEdit)
|
---|
3449 | {
|
---|
3450 | SetFocus(infoPtr->hwnd);
|
---|
3451 | return 0;
|
---|
3452 | }
|
---|
3453 |
|
---|
3454 | ht.pt.x = (INT)LOWORD(lParam);
|
---|
3455 | ht.pt.y = (INT)HIWORD(lParam);
|
---|
3456 |
|
---|
3457 | TREEVIEW_HitTest(infoPtr,&ht,FALSE);
|
---|
3458 |
|
---|
3459 | if (TREEVIEW_TrackMouse(infoPtr,ht.pt))
|
---|
3460 | {
|
---|
3461 | if (ht.hItem)
|
---|
3462 | {
|
---|
3463 | TREEVIEW_SendTreeviewDnDNotify(infoPtr,isUnicodeNotify(&infoPtr->header) ? TVN_BEGINRDRAGW:TVN_BEGINDRAGA, ht.hItem, ht.pt);
|
---|
3464 | infoPtr->dropItem = ht.hItem;
|
---|
3465 | }
|
---|
3466 | }
|
---|
3467 | else
|
---|
3468 | {
|
---|
3469 | SetFocus(infoPtr->hwnd);
|
---|
3470 | sendNotify(infoPtr->hwnd,NM_RCLICK);
|
---|
3471 | }
|
---|
3472 |
|
---|
3473 | return 0;
|
---|
3474 | }
|
---|
3475 |
|
---|
3476 | static LRESULT
|
---|
3477 | TREEVIEW_RButtonUp(TREEVIEW_INFO *infoPtr, LPPOINT pPt)
|
---|
3478 | {
|
---|
3479 | POINT pt = *pPt;
|
---|
3480 |
|
---|
3481 | /* Change to screen coordinate for WM_CONTEXTMENU */
|
---|
3482 | ClientToScreen(infoPtr->hwnd, &pt);
|
---|
3483 |
|
---|
3484 | /* Send the WM_CONTEXTMENU on a right click */
|
---|
3485 | SendMessageA( infoPtr->hwnd, WM_CONTEXTMENU, (WPARAM)infoPtr->hwnd, MAKELPARAM(pt.x, pt.y));
|
---|
3486 | return 0;
|
---|
3487 | }
|
---|
3488 |
|
---|
3489 | static LRESULT TREEVIEW_CreateDragImage (TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
3490 | {
|
---|
3491 | TREEVIEW_ITEM *dragItem;
|
---|
3492 | INT cx,cy;
|
---|
3493 | HDC hdc,htopdc;
|
---|
3494 | HWND hwtop;
|
---|
3495 | HBITMAP hbmp,hOldbmp;
|
---|
3496 | SIZE size;
|
---|
3497 | RECT rc;
|
---|
3498 | HFONT hOldFont;
|
---|
3499 |
|
---|
3500 | if (!(infoPtr->himlNormal)) return 0;
|
---|
3501 | if (!dragItem || !TREEVIEW_ValidItem(infoPtr, dragItem))
|
---|
3502 | return 0;
|
---|
3503 |
|
---|
3504 | TREEVIEW_UpdateDispInfo(infoPtr, dragItem, TVIF_TEXT);
|
---|
3505 |
|
---|
3506 | hwtop = GetDesktopWindow();
|
---|
3507 | htopdc = GetDC(hwtop);
|
---|
3508 | hdc = CreateCompatibleDC(htopdc);
|
---|
3509 |
|
---|
3510 | hOldFont = SelectObject (hdc, infoPtr->hFont);
|
---|
3511 | GetTextExtentPoint32W (hdc, dragItem->pszText, lstrlenW (dragItem->pszText), &size);
|
---|
3512 |
|
---|
3513 | hbmp = CreateCompatibleBitmap (htopdc, size.cx, size.cy);
|
---|
3514 | hOldbmp = SelectObject (hdc, hbmp);
|
---|
3515 |
|
---|
3516 | ImageList_GetIconSize (infoPtr->himlNormal, &cx, &cy);
|
---|
3517 | size.cx += cx;
|
---|
3518 | if (cy > size.cy) size.cy = cy;
|
---|
3519 |
|
---|
3520 | infoPtr->dragList = ImageList_Create (size.cx, size.cy, ILC_COLOR, 10, 10);
|
---|
3521 | ImageList_Draw (infoPtr->himlNormal, dragItem->iImage, hdc, 0, 0, ILD_NORMAL);
|
---|
3522 |
|
---|
3523 | /*
|
---|
3524 | ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
|
---|
3525 | ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
|
---|
3526 | */
|
---|
3527 |
|
---|
3528 | /* draw item text */
|
---|
3529 |
|
---|
3530 | SetRect (&rc, cx, 0, size.cx,size.cy);
|
---|
3531 | DrawTextW (hdc, dragItem->pszText, lstrlenW(dragItem->pszText), &rc, DT_LEFT);
|
---|
3532 | SelectObject (hdc, hOldFont);
|
---|
3533 | SelectObject (hdc, hOldbmp);
|
---|
3534 |
|
---|
3535 | ImageList_Add (infoPtr->dragList, hbmp, 0);
|
---|
3536 |
|
---|
3537 | DeleteDC (hdc);
|
---|
3538 | DeleteObject (hbmp);
|
---|
3539 | ReleaseDC (hwtop, htopdc);
|
---|
3540 |
|
---|
3541 | return (LRESULT)infoPtr->dragList;
|
---|
3542 | }
|
---|
3543 |
|
---|
3544 | /* Selection ************************************************************/
|
---|
3545 |
|
---|
3546 | static LRESULT
|
---|
3547 | TREEVIEW_DoSelectItem(TREEVIEW_INFO *infoPtr, INT action, HTREEITEM newSelect,
|
---|
3548 | INT cause)
|
---|
3549 | {
|
---|
3550 | TREEVIEW_ITEM *prevSelect;
|
---|
3551 | BOOL refreshPrev = FALSE,refreshNew = FALSE;
|
---|
3552 |
|
---|
3553 | assert(newSelect == NULL || TREEVIEW_ValidItem(infoPtr, newSelect));
|
---|
3554 |
|
---|
3555 | //TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
|
---|
3556 | // newSelect, TREEVIEW_ItemName(newSelect), action, cause,
|
---|
3557 | // newSelect ? newSelect->state : 0);
|
---|
3558 |
|
---|
3559 | if (newSelect && newSelect->parent)
|
---|
3560 | {
|
---|
3561 | TREEVIEW_ITEM *parent = newSelect->parent;
|
---|
3562 |
|
---|
3563 | /*
|
---|
3564 | * If the item has a collapse parent expand the parent so he
|
---|
3565 | * can expose the item
|
---|
3566 | */
|
---|
3567 | while (parent && !(parent->state & TVIS_EXPANDED))
|
---|
3568 | {
|
---|
3569 | TREEVIEW_Expand(infoPtr,parent,FALSE,FALSE);
|
---|
3570 | parent = parent->parent;
|
---|
3571 | }
|
---|
3572 | }
|
---|
3573 |
|
---|
3574 |
|
---|
3575 | switch (action)
|
---|
3576 | {
|
---|
3577 | case TVGN_CARET:
|
---|
3578 | prevSelect = infoPtr->selectedItem;
|
---|
3579 |
|
---|
3580 | if (prevSelect == newSelect)
|
---|
3581 | return FALSE;
|
---|
3582 |
|
---|
3583 | if (TREEVIEW_SendTreeviewNotify(infoPtr,
|
---|
3584 | isUnicodeNotify(&infoPtr->header) ? TVN_SELCHANGINGW:TVN_SELCHANGINGA,
|
---|
3585 | cause,
|
---|
3586 | TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
|
---|
3587 | prevSelect,
|
---|
3588 | newSelect))
|
---|
3589 | return FALSE; /* FIXME: OK? */
|
---|
3590 |
|
---|
3591 | if (prevSelect)
|
---|
3592 | {
|
---|
3593 | refreshPrev = prevSelect->state & TVIS_SELECTED;
|
---|
3594 | prevSelect->state &= ~TVIS_SELECTED;
|
---|
3595 | }
|
---|
3596 |
|
---|
3597 | if (newSelect)
|
---|
3598 | {
|
---|
3599 | refreshNew = !(newSelect->state & TVIS_SELECTED);
|
---|
3600 | newSelect->state |= TVIS_SELECTED;
|
---|
3601 | }
|
---|
3602 |
|
---|
3603 | infoPtr->selectedItem = newSelect;
|
---|
3604 |
|
---|
3605 | if ((cause == TVC_BYMOUSE) && (infoPtr->dwStyle & TVS_SINGLEEXPAND))
|
---|
3606 | {
|
---|
3607 | BOOL control = GetKeyState(VK_CONTROL) & 0x8000;
|
---|
3608 | UINT rc = TREEVIEW_SendTreeviewNotify(infoPtr,TVN_SINGLEEXPAND,0,TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,prevSelect,newSelect);
|
---|
3609 |
|
---|
3610 | if (!(rc & TVNRET_SKIPOLD) && !control && (prevSelect->state & TVIS_EXPANDED))
|
---|
3611 | TREEVIEW_Collapse(infoPtr,prevSelect,FALSE,FALSE);
|
---|
3612 | if (!(rc & TVNRET_SKIPNEW) && TREEVIEW_HasChildren(infoPtr,newSelect))
|
---|
3613 | TREEVIEW_Toggle(infoPtr,newSelect,FALSE);
|
---|
3614 | }
|
---|
3615 |
|
---|
3616 | TREEVIEW_UnqueueRefresh(infoPtr,TRUE,TRUE);
|
---|
3617 | TREEVIEW_EnsureVisible(infoPtr,infoPtr->selectedItem);
|
---|
3618 | if (infoPtr->dwStyle & TVS_FULLROWSELECT)
|
---|
3619 | {
|
---|
3620 | TREEVIEW_ITEM *item;
|
---|
3621 |
|
---|
3622 | //deselect last selected row
|
---|
3623 | if (prevSelect)
|
---|
3624 | {
|
---|
3625 | if (refreshPrev) TREEVIEW_RefreshItem(infoPtr,prevSelect,TVIF_IMAGE | TVIF_TEXT);
|
---|
3626 | if (prevSelect->prevSibling)
|
---|
3627 | {
|
---|
3628 | item = prevSelect->prevSibling;
|
---|
3629 | while (item)
|
---|
3630 | {
|
---|
3631 | if (item->state & TVIS_SELECTED)
|
---|
3632 | {
|
---|
3633 | item->state &= ~TVIS_SELECTED;
|
---|
3634 | TREEVIEW_RefreshItem(infoPtr,item,TVIF_IMAGE | TVIF_TEXT);
|
---|
3635 | }
|
---|
3636 | item = item->prevSibling;
|
---|
3637 | }
|
---|
3638 | }
|
---|
3639 | if (prevSelect->nextSibling)
|
---|
3640 | {
|
---|
3641 | item = prevSelect->nextSibling;
|
---|
3642 | while (item)
|
---|
3643 | {
|
---|
3644 | if (item->state & TVIS_SELECTED)
|
---|
3645 | {
|
---|
3646 | item->state &= ~TVIS_SELECTED;
|
---|
3647 | TREEVIEW_RefreshItem(infoPtr,item,TVIF_IMAGE | TVIF_TEXT);
|
---|
3648 | }
|
---|
3649 | item = item->nextSibling;
|
---|
3650 | }
|
---|
3651 | }
|
---|
3652 | }
|
---|
3653 |
|
---|
3654 | //select new row
|
---|
3655 | if (newSelect)
|
---|
3656 | {
|
---|
3657 | if (refreshNew) TREEVIEW_RefreshItem(infoPtr,newSelect,TVIF_IMAGE | TVIF_TEXT);
|
---|
3658 | if (newSelect->prevSibling)
|
---|
3659 | {
|
---|
3660 | item = newSelect->prevSibling;
|
---|
3661 | while (item)
|
---|
3662 | {
|
---|
3663 | if (!(item->state & TVIS_SELECTED))
|
---|
3664 | {
|
---|
3665 | item->state |= TVIS_SELECTED;
|
---|
3666 | TREEVIEW_RefreshItem(infoPtr,item,TVIF_IMAGE | TVIF_TEXT);
|
---|
3667 | }
|
---|
3668 | item = item->prevSibling;
|
---|
3669 | }
|
---|
3670 | }
|
---|
3671 | if (newSelect->nextSibling)
|
---|
3672 | {
|
---|
3673 | item = newSelect->nextSibling;
|
---|
3674 | while (item)
|
---|
3675 | {
|
---|
3676 | if (!(item->state & TVIS_SELECTED))
|
---|
3677 | {
|
---|
3678 | item->state |= TVIS_SELECTED;
|
---|
3679 | TREEVIEW_RefreshItem(infoPtr,item,TVIF_IMAGE | TVIF_TEXT);
|
---|
3680 | }
|
---|
3681 | item = item->nextSibling;
|
---|
3682 | }
|
---|
3683 | }
|
---|
3684 | }
|
---|
3685 | } else
|
---|
3686 | {
|
---|
3687 | if (refreshPrev) TREEVIEW_RefreshItem(infoPtr,prevSelect,TVIF_IMAGE | TVIF_TEXT);
|
---|
3688 | if (refreshNew) TREEVIEW_RefreshItem(infoPtr,newSelect,TVIF_IMAGE | TVIF_TEXT);
|
---|
3689 | }
|
---|
3690 |
|
---|
3691 | TREEVIEW_SendTreeviewNotify(infoPtr,
|
---|
3692 | isUnicodeNotify(&infoPtr->header) ? TVN_SELCHANGEDW:TVN_SELCHANGEDA,
|
---|
3693 | cause,
|
---|
3694 | TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
|
---|
3695 | prevSelect,
|
---|
3696 | newSelect);
|
---|
3697 | break;
|
---|
3698 |
|
---|
3699 | case TVGN_DROPHILITE:
|
---|
3700 | prevSelect = infoPtr->dropItem;
|
---|
3701 |
|
---|
3702 | if (prevSelect)
|
---|
3703 | {
|
---|
3704 | refreshPrev = prevSelect->state & TVIS_DROPHILITED;
|
---|
3705 | prevSelect->state &= ~TVIS_DROPHILITED;
|
---|
3706 | }
|
---|
3707 |
|
---|
3708 | infoPtr->dropItem = newSelect;
|
---|
3709 |
|
---|
3710 | if (newSelect)
|
---|
3711 | {
|
---|
3712 | refreshNew = !(newSelect->state & TVIS_DROPHILITED);
|
---|
3713 | newSelect->state |= TVIS_DROPHILITED;
|
---|
3714 | }
|
---|
3715 |
|
---|
3716 | TREEVIEW_UnqueueRefresh(infoPtr,TRUE,TRUE);
|
---|
3717 | if (refreshPrev) TREEVIEW_RefreshItem(infoPtr,prevSelect,TVIF_IMAGE | TVIF_TEXT);
|
---|
3718 | if (refreshNew) TREEVIEW_RefreshItem(infoPtr,newSelect,TVIF_IMAGE | TVIF_TEXT);
|
---|
3719 |
|
---|
3720 | break;
|
---|
3721 |
|
---|
3722 | case TVGN_FIRSTVISIBLE:
|
---|
3723 | {
|
---|
3724 | TREEVIEW_ITEM *firstVis;
|
---|
3725 | INT scrollY;
|
---|
3726 |
|
---|
3727 | if (!infoPtr->firstVisible) return FALSE;
|
---|
3728 |
|
---|
3729 | firstVis = infoPtr->firstVisible;
|
---|
3730 |
|
---|
3731 | if (newSelect->rect.top < 0)
|
---|
3732 | scrollY = newSelect->rect.top;
|
---|
3733 | else
|
---|
3734 | {
|
---|
3735 | scrollY = MIN(newSelect->rect.top,(infoPtr->treeHeight-infoPtr->clientHeight)-infoPtr->lefttop.y);
|
---|
3736 | scrollY -= scrollY % infoPtr->uItemHeight;
|
---|
3737 | }
|
---|
3738 |
|
---|
3739 | if (scrollY != 0)
|
---|
3740 | {
|
---|
3741 | infoPtr->lefttop.y += scrollY;
|
---|
3742 | if (!TREEVIEW_UnqueueRefresh(infoPtr,TRUE,TRUE))
|
---|
3743 | TREEVIEW_CalcItems(infoPtr);
|
---|
3744 |
|
---|
3745 | ScrollWindowEx(infoPtr->hwnd,0,-scrollY,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
|
---|
3746 | }
|
---|
3747 |
|
---|
3748 | break;
|
---|
3749 | }
|
---|
3750 | }
|
---|
3751 |
|
---|
3752 | //TRACE("Leaving state %d\n", newSelect ? newSelect->state : 0);
|
---|
3753 | return TRUE;
|
---|
3754 | }
|
---|
3755 |
|
---|
3756 | /* FIXME: handle NM_KILLFOCUS etc */
|
---|
3757 | static LRESULT
|
---|
3758 | TREEVIEW_SelectItem(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
3759 | {
|
---|
3760 | HTREEITEM item = (HTREEITEM)lParam;
|
---|
3761 |
|
---|
3762 | if (item != NULL && !TREEVIEW_ValidItem(infoPtr, item))
|
---|
3763 | return FALSE;
|
---|
3764 |
|
---|
3765 | //TRACE("%p (%s) %d\n", item, TREEVIEW_ItemName(item), (int)wParam);
|
---|
3766 |
|
---|
3767 | if (!TREEVIEW_DoSelectItem(infoPtr, wParam, item, TVC_UNKNOWN))
|
---|
3768 | return FALSE;
|
---|
3769 |
|
---|
3770 | return TRUE;
|
---|
3771 | }
|
---|
3772 |
|
---|
3773 | /* Scrolling ************************************************************/
|
---|
3774 |
|
---|
3775 | static LRESULT TREEVIEW_EnsureVisible(TREEVIEW_INFO *infoPtr,HTREEITEM item)
|
---|
3776 | {
|
---|
3777 | RECT rect;
|
---|
3778 | INT scrollY;
|
---|
3779 |
|
---|
3780 | if (!item) return FALSE;
|
---|
3781 |
|
---|
3782 | if (!TREEVIEW_ValidItem(infoPtr,item))
|
---|
3783 | return FALSE;
|
---|
3784 |
|
---|
3785 | if (item && item->parent)
|
---|
3786 | {
|
---|
3787 | TREEVIEW_ITEM *parent = item->parent;
|
---|
3788 |
|
---|
3789 | while (parent && !(parent->state & TVIS_EXPANDED))
|
---|
3790 | {
|
---|
3791 | TREEVIEW_Expand(infoPtr,parent,FALSE,FALSE);
|
---|
3792 | parent = parent->parent;
|
---|
3793 | }
|
---|
3794 | }
|
---|
3795 |
|
---|
3796 | TREEVIEW_UnqueueRefresh(infoPtr,TRUE,TRUE);
|
---|
3797 | GetClientRect(infoPtr->hwnd,&rect);
|
---|
3798 | if (item->rect.top < 0)
|
---|
3799 | scrollY = item->rect.top;
|
---|
3800 | else if (item->rect.bottom > rect.bottom)
|
---|
3801 | {
|
---|
3802 | INT mod;
|
---|
3803 |
|
---|
3804 | scrollY = item->rect.bottom-rect.bottom;
|
---|
3805 | mod = scrollY % infoPtr->uItemHeight;
|
---|
3806 | if (mod) scrollY += infoPtr->uItemHeight-mod;
|
---|
3807 | } else return FALSE;
|
---|
3808 |
|
---|
3809 | if (scrollY != 0)
|
---|
3810 | {
|
---|
3811 | infoPtr->lefttop.y += scrollY;
|
---|
3812 | TREEVIEW_CalcItems(infoPtr);
|
---|
3813 | ScrollWindowEx(infoPtr->hwnd,0,-scrollY,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
|
---|
3814 |
|
---|
3815 | return TRUE;
|
---|
3816 | }
|
---|
3817 |
|
---|
3818 | return FALSE;
|
---|
3819 | }
|
---|
3820 |
|
---|
3821 | static LRESULT
|
---|
3822 | TREEVIEW_VScroll(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
3823 | {
|
---|
3824 | INT newY,mod;
|
---|
3825 | INT maxY = infoPtr->treeHeight-infoPtr->clientHeight;
|
---|
3826 |
|
---|
3827 | if (!(infoPtr->uInternalStatus & TV_VSCROLL)) return FALSE;
|
---|
3828 |
|
---|
3829 | mod = maxY % infoPtr->uItemHeight;
|
---|
3830 | if (mod > 0) maxY += infoPtr->uItemHeight-mod;
|
---|
3831 |
|
---|
3832 | switch (LOWORD (wParam))
|
---|
3833 | {
|
---|
3834 | case SB_LINEUP:
|
---|
3835 | newY = infoPtr->lefttop.y-infoPtr->uItemHeight;
|
---|
3836 | if (newY < 0) newY = 0;
|
---|
3837 | break;
|
---|
3838 |
|
---|
3839 | case SB_LINEDOWN:
|
---|
3840 | newY = infoPtr->lefttop.y+infoPtr->uItemHeight;
|
---|
3841 | if (newY > maxY) newY = maxY;
|
---|
3842 | break;
|
---|
3843 |
|
---|
3844 | case SB_PAGEUP:
|
---|
3845 | newY = infoPtr->lefttop.y-MAX(((INT)(infoPtr->clientHeight/infoPtr->uItemHeight))*infoPtr->uItemHeight,infoPtr->uItemHeight);
|
---|
3846 | if (newY < 0) newY = 0;
|
---|
3847 | break;
|
---|
3848 |
|
---|
3849 | case SB_PAGEDOWN:
|
---|
3850 | newY = infoPtr->lefttop.y+MAX(((INT)(infoPtr->clientHeight/infoPtr->uItemHeight))*infoPtr->uItemHeight,infoPtr->uItemHeight);
|
---|
3851 | if (newY > maxY) newY = maxY;
|
---|
3852 | break;
|
---|
3853 |
|
---|
3854 | case SB_THUMBTRACK:
|
---|
3855 | newY = HIWORD(wParam);
|
---|
3856 | mod = newY % infoPtr->uItemHeight;
|
---|
3857 | if (mod > 0) newY -= mod;
|
---|
3858 | break;
|
---|
3859 |
|
---|
3860 | default:
|
---|
3861 | return FALSE;
|
---|
3862 | }
|
---|
3863 |
|
---|
3864 | if (newY != infoPtr->lefttop.y)
|
---|
3865 | {
|
---|
3866 | INT scrollY = infoPtr->lefttop.y-newY;
|
---|
3867 | SCROLLINFO info;
|
---|
3868 |
|
---|
3869 | TREEVIEW_HideInfoTip(infoPtr);
|
---|
3870 | infoPtr->lefttop.y = newY;
|
---|
3871 | if (!TREEVIEW_UnqueueRefresh(infoPtr,TRUE,TRUE))
|
---|
3872 | TREEVIEW_MoveItems(infoPtr,0,scrollY);
|
---|
3873 |
|
---|
3874 | info.cbSize = sizeof(info);
|
---|
3875 | info.nPos = infoPtr->lefttop.y;
|
---|
3876 | info.fMask = SIF_POS;
|
---|
3877 | SetScrollInfo(infoPtr->hwnd,SB_VERT,&info,TRUE);
|
---|
3878 |
|
---|
3879 | ScrollWindowEx(infoPtr->hwnd,0,scrollY,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
|
---|
3880 |
|
---|
3881 | return TRUE;
|
---|
3882 | }
|
---|
3883 |
|
---|
3884 | return FALSE;
|
---|
3885 | }
|
---|
3886 |
|
---|
3887 | static LRESULT
|
---|
3888 | TREEVIEW_HScroll(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
3889 | {
|
---|
3890 | int maxWidth;
|
---|
3891 | int lastPos = infoPtr->lefttop.x;
|
---|
3892 | SCROLLINFO info;
|
---|
3893 |
|
---|
3894 | if (!(infoPtr->uInternalStatus & TV_HSCROLL)) return FALSE;
|
---|
3895 |
|
---|
3896 | switch (LOWORD (wParam))
|
---|
3897 | {
|
---|
3898 | case SB_LINEUP:
|
---|
3899 | if (!infoPtr->lefttop.x) return FALSE;
|
---|
3900 | infoPtr->lefttop.x -= infoPtr->uItemHeight;
|
---|
3901 | if (infoPtr->lefttop.x < 0) infoPtr->lefttop.x = 0;
|
---|
3902 | break;
|
---|
3903 |
|
---|
3904 | case SB_LINEDOWN:
|
---|
3905 | maxWidth = infoPtr->treeWidth-infoPtr->clientWidth;
|
---|
3906 | if (maxWidth <= 0) return FALSE;
|
---|
3907 | if (infoPtr->lefttop.x == maxWidth) return FALSE;
|
---|
3908 | infoPtr->lefttop.x += infoPtr->uItemHeight; /*FIXME */
|
---|
3909 | if (infoPtr->lefttop.x > maxWidth)
|
---|
3910 | infoPtr->lefttop.x = maxWidth;
|
---|
3911 | break;
|
---|
3912 |
|
---|
3913 | case SB_PAGEUP:
|
---|
3914 | if (!infoPtr->lefttop.x) return FALSE;
|
---|
3915 | infoPtr->lefttop.x -= infoPtr->clientWidth;
|
---|
3916 | if (infoPtr->lefttop.x < 0) infoPtr->lefttop.x = 0;
|
---|
3917 | break;
|
---|
3918 |
|
---|
3919 | case SB_PAGEDOWN:
|
---|
3920 | maxWidth = infoPtr->treeWidth-infoPtr->clientWidth;
|
---|
3921 | if (maxWidth <= 0) return FALSE;
|
---|
3922 | if (infoPtr->lefttop.x == maxWidth) return FALSE;
|
---|
3923 | infoPtr->lefttop.x += infoPtr->clientWidth;
|
---|
3924 | if (infoPtr->lefttop.x > maxWidth)
|
---|
3925 | infoPtr->lefttop.x = maxWidth;
|
---|
3926 | break;
|
---|
3927 |
|
---|
3928 | case SB_THUMBTRACK:
|
---|
3929 | maxWidth = infoPtr->treeWidth-infoPtr->clientWidth;
|
---|
3930 | if (maxWidth <= 0) return FALSE;
|
---|
3931 | infoPtr->lefttop.x = HIWORD(wParam);
|
---|
3932 | if (infoPtr->lefttop.x < 0) infoPtr->lefttop.x = 0;
|
---|
3933 | if (infoPtr->lefttop.x > maxWidth) infoPtr->lefttop.x = maxWidth;
|
---|
3934 | break;
|
---|
3935 |
|
---|
3936 | default:
|
---|
3937 | return FALSE;
|
---|
3938 | }
|
---|
3939 |
|
---|
3940 | if (lastPos != infoPtr->lefttop.x)
|
---|
3941 | {
|
---|
3942 | TREEVIEW_HideInfoTip(infoPtr);
|
---|
3943 | if (!TREEVIEW_UnqueueRefresh(infoPtr,TRUE,TRUE))
|
---|
3944 | TREEVIEW_MoveItems(infoPtr,lastPos-infoPtr->lefttop.x,0);
|
---|
3945 |
|
---|
3946 | info.cbSize = sizeof(info);
|
---|
3947 | info.nPos = infoPtr->lefttop.x;
|
---|
3948 | info.fMask = SIF_POS;
|
---|
3949 | SetScrollInfo(infoPtr->hwnd,SB_HORZ,&info,TRUE);
|
---|
3950 |
|
---|
3951 | ScrollWindowEx(infoPtr->hwnd,lastPos-infoPtr->lefttop.x,0,NULL,NULL,0,NULL,SW_INVALIDATE | SW_SCROLLCHILDREN | (infoPtr->uScrollTime << 16));
|
---|
3952 |
|
---|
3953 | return TRUE;
|
---|
3954 | }
|
---|
3955 |
|
---|
3956 | return FALSE;
|
---|
3957 | }
|
---|
3958 |
|
---|
3959 | static LRESULT
|
---|
3960 | TREEVIEW_MouseWheel(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
3961 | {
|
---|
3962 | short gcWheelDelta;
|
---|
3963 | UINT pulScrollLines = 3;
|
---|
3964 |
|
---|
3965 | if (infoPtr->firstVisible == NULL)
|
---|
3966 | return TRUE;
|
---|
3967 |
|
---|
3968 | SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, &pulScrollLines, 0);
|
---|
3969 |
|
---|
3970 | gcWheelDelta = -(short)HIWORD(wParam);
|
---|
3971 | pulScrollLines *= (gcWheelDelta / WHEEL_DELTA);
|
---|
3972 |
|
---|
3973 | if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
|
---|
3974 | {
|
---|
3975 | int wheelDy = pulScrollLines * infoPtr->uItemHeight;
|
---|
3976 | int newDy = infoPtr->lefttop.y + wheelDy;
|
---|
3977 | int maxDy = infoPtr->treeHeight-infoPtr->clientHeight;
|
---|
3978 |
|
---|
3979 | if (newDy > maxDy) newDy = maxDy;
|
---|
3980 |
|
---|
3981 | if (newDy < 0) newDy = 0;
|
---|
3982 |
|
---|
3983 | TREEVIEW_VScroll(infoPtr, MAKEWPARAM(SB_THUMBTRACK, newDy), 0);
|
---|
3984 | }
|
---|
3985 | return TRUE;
|
---|
3986 | }
|
---|
3987 |
|
---|
3988 | /* Create/Destroy *******************************************************/
|
---|
3989 |
|
---|
3990 | static LRESULT
|
---|
3991 | TREEVIEW_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
|
---|
3992 | {
|
---|
3993 | LPCREATESTRUCTA lpcs = (LPCREATESTRUCTA)lParam;
|
---|
3994 | TREEVIEW_INFO *infoPtr;
|
---|
3995 | RECT rcClient;
|
---|
3996 |
|
---|
3997 | /* allocate memory for info structure */
|
---|
3998 | infoPtr = (TREEVIEW_INFO*)initControl(hwnd,sizeof(TREEVIEW_INFO));
|
---|
3999 |
|
---|
4000 | if (!infoPtr) return 0;
|
---|
4001 |
|
---|
4002 | /* set default settings */
|
---|
4003 | infoPtr->hwnd = hwnd;
|
---|
4004 | infoPtr->dwStyle = lpcs->style;
|
---|
4005 | infoPtr->uInternalStatus = TV_CALCALL;
|
---|
4006 | infoPtr->Timer = 0;
|
---|
4007 | infoPtr->uNumItems = 0;
|
---|
4008 | infoPtr->cdmode = 0;
|
---|
4009 | infoPtr->uScrollTime = 300; /* milliseconds */
|
---|
4010 |
|
---|
4011 | GetClientRect(hwnd,&rcClient);
|
---|
4012 |
|
---|
4013 | /* No scroll bars yet. */
|
---|
4014 | infoPtr->clientWidth = rcClient.right;
|
---|
4015 | infoPtr->clientHeight = rcClient.bottom;
|
---|
4016 |
|
---|
4017 | infoPtr->treeWidth = 0;
|
---|
4018 | infoPtr->treeHeight = 0;
|
---|
4019 |
|
---|
4020 | infoPtr->uIndent = 19;
|
---|
4021 | infoPtr->selectedItem = 0;
|
---|
4022 | infoPtr->firstVisible = 0;
|
---|
4023 | infoPtr->maxDisplayOrder = 0;
|
---|
4024 | infoPtr->dropItem = 0;
|
---|
4025 | infoPtr->insertMarkItem = 0;
|
---|
4026 | infoPtr->insertBeforeorAfter = 0;
|
---|
4027 |
|
---|
4028 | infoPtr->clrBk = GetSysColor(COLOR_WINDOW);
|
---|
4029 | infoPtr->clrText = -1; /* use system color */
|
---|
4030 | infoPtr->clrLine = RGB(128, 128, 128);
|
---|
4031 | infoPtr->clrInsertMark = GetSysColor(COLOR_BTNTEXT);
|
---|
4032 |
|
---|
4033 | infoPtr->lefttop.y = 0;
|
---|
4034 | infoPtr->lefttop.x = 0;
|
---|
4035 |
|
---|
4036 | infoPtr->hwndEdit = 0;
|
---|
4037 | infoPtr->wpEditOrig = NULL;
|
---|
4038 | infoPtr->bIgnoreEditKillFocus = FALSE;
|
---|
4039 | infoPtr->bLabelChanged = FALSE;
|
---|
4040 |
|
---|
4041 | infoPtr->himlNormal = NULL;
|
---|
4042 | infoPtr->himlState = NULL;
|
---|
4043 | infoPtr->normalImageWidth = 0;
|
---|
4044 | infoPtr->normalImageHeight = 0;
|
---|
4045 | infoPtr->stateImageWidth = 0;
|
---|
4046 | infoPtr->stateImageHeight = 0;
|
---|
4047 |
|
---|
4048 | infoPtr->items = DPA_Create(16);
|
---|
4049 |
|
---|
4050 | infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);
|
---|
4051 | infoPtr->hBoldFont = TREEVIEW_CreateBoldFont(infoPtr->hFont);
|
---|
4052 |
|
---|
4053 | infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
|
---|
4054 |
|
---|
4055 | infoPtr->root = TREEVIEW_AllocateItem(infoPtr);
|
---|
4056 | infoPtr->root->state = TVIS_EXPANDED;
|
---|
4057 | infoPtr->root->iLevel = -1;
|
---|
4058 | infoPtr->root->displayOrder = -1;
|
---|
4059 |
|
---|
4060 | infoPtr->pszISearch = NULL;
|
---|
4061 | infoPtr->uISearchLen = 0;
|
---|
4062 |
|
---|
4063 | infoPtr->tipItem = 0;
|
---|
4064 | infoPtr->hwndToolTip = 0;
|
---|
4065 | if (!(infoPtr->dwStyle & TVS_NOTOOLTIPS))
|
---|
4066 | {
|
---|
4067 | infoPtr->hwndToolTip = createToolTip(hwnd,TTF_TRACK | TTF_ABSOLUTE | TTF_TRANSPARENT,TRUE);
|
---|
4068 | SendMessageA(infoPtr->hwndToolTip,WM_SETFONT,infoPtr->hFont,0);
|
---|
4069 | }
|
---|
4070 |
|
---|
4071 | if (infoPtr->dwStyle & TVS_CHECKBOXES)
|
---|
4072 | {
|
---|
4073 | HBITMAP hbmLoad;
|
---|
4074 | int nIndex;
|
---|
4075 |
|
---|
4076 | infoPtr->himlState = ImageList_Create (16, 16,ILC_COLOR | ILC_MASK, 15, 1);
|
---|
4077 |
|
---|
4078 | //MSDN docu says: uses DrawFrameControl but never believe what they write
|
---|
4079 | hbmLoad = LoadBitmapA (COMCTL32_hModule, MAKEINTRESOURCEA(IDT_CHECK));
|
---|
4080 | nIndex = ImageList_AddMasked (infoPtr->himlState, hbmLoad, CLR_DEFAULT);
|
---|
4081 | DeleteObject (hbmLoad);
|
---|
4082 |
|
---|
4083 | infoPtr->stateImageWidth = 16;
|
---|
4084 | infoPtr->stateImageHeight = 16;
|
---|
4085 | }
|
---|
4086 |
|
---|
4087 | return 0;
|
---|
4088 | }
|
---|
4089 |
|
---|
4090 | static LRESULT
|
---|
4091 | TREEVIEW_Destroy(TREEVIEW_INFO *infoPtr)
|
---|
4092 | {
|
---|
4093 | TREEVIEW_RemoveTree(infoPtr);
|
---|
4094 |
|
---|
4095 | /* tool tip is automatically destroyed: we are its owner */
|
---|
4096 |
|
---|
4097 | /* Restore original windproc. */
|
---|
4098 | if (infoPtr->hwndEdit)
|
---|
4099 | SetWindowLongA(infoPtr->hwndEdit, GWL_WNDPROC,(LONG)infoPtr->wpEditOrig);
|
---|
4100 |
|
---|
4101 | if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
|
---|
4102 | KillTimer(infoPtr->hwnd, TV_REFRESH_TIMER);
|
---|
4103 |
|
---|
4104 | DeleteObject(infoPtr->hBoldFont);
|
---|
4105 | COMCTL32_Free(infoPtr->pszISearch);
|
---|
4106 | doneControl(infoPtr->hwnd);
|
---|
4107 |
|
---|
4108 | return 0;
|
---|
4109 | }
|
---|
4110 |
|
---|
4111 | /* Miscellaneous Messages ***********************************************/
|
---|
4112 |
|
---|
4113 | static LRESULT
|
---|
4114 | TREEVIEW_ScrollKeyDown(TREEVIEW_INFO *infoPtr, WPARAM key)
|
---|
4115 | {
|
---|
4116 | static const struct
|
---|
4117 | {
|
---|
4118 | unsigned char code;
|
---|
4119 | }
|
---|
4120 | scroll[] =
|
---|
4121 | {
|
---|
4122 | #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
|
---|
4123 | SCROLL_ENTRY(SB_VERT, SB_PAGEUP), /* VK_PRIOR */
|
---|
4124 | SCROLL_ENTRY(SB_VERT, SB_PAGEDOWN), /* VK_NEXT */
|
---|
4125 | SCROLL_ENTRY(SB_VERT, SB_BOTTOM), /* VK_END */
|
---|
4126 | SCROLL_ENTRY(SB_VERT, SB_TOP), /* VK_HOME */
|
---|
4127 | SCROLL_ENTRY(SB_HORZ, SB_LINEUP), /* VK_LEFT */
|
---|
4128 | SCROLL_ENTRY(SB_VERT, SB_LINEUP), /* VK_UP */
|
---|
4129 | SCROLL_ENTRY(SB_HORZ, SB_LINEDOWN), /* VK_RIGHT */
|
---|
4130 | SCROLL_ENTRY(SB_VERT, SB_LINEDOWN) /* VK_DOWN */
|
---|
4131 | #undef SCROLL_ENTRY
|
---|
4132 | };
|
---|
4133 |
|
---|
4134 | if (key >= VK_PRIOR && key <= VK_DOWN)
|
---|
4135 | {
|
---|
4136 | unsigned char code = scroll[key - VK_PRIOR].code;
|
---|
4137 |
|
---|
4138 | (((code & (1 << 7)) == (SB_HORZ << 7))
|
---|
4139 | ? TREEVIEW_HScroll
|
---|
4140 | : TREEVIEW_VScroll)(infoPtr, code & 0x7F, 0);
|
---|
4141 | }
|
---|
4142 |
|
---|
4143 | return 0;
|
---|
4144 | }
|
---|
4145 |
|
---|
4146 | /************************************************************************
|
---|
4147 | * TREEVIEW_KeyDown
|
---|
4148 | *
|
---|
4149 | * VK_UP Move selection to the previous non-hidden item.
|
---|
4150 | * VK_DOWN Move selection to the next non-hidden item.
|
---|
4151 | * VK_HOME Move selection to the first item.
|
---|
4152 | * VK_END Move selection to the last item.
|
---|
4153 | * VK_LEFT If expanded then collapse, otherwise move to parent.
|
---|
4154 | * VK_RIGHT If collapsed then expand, otherwise move to first child.
|
---|
4155 | * VK_ADD Expand.
|
---|
4156 | * VK_SUBTRACT Collapse.
|
---|
4157 | * VK_MULTIPLY Expand all.
|
---|
4158 | * VK_PRIOR Move up GetVisibleCount items.
|
---|
4159 | * VK_NEXT Move down GetVisibleCount items.
|
---|
4160 | * VK_BACK Move to parent.
|
---|
4161 | * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
|
---|
4162 | */
|
---|
4163 | static LRESULT
|
---|
4164 | TREEVIEW_KeyDown(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
4165 | {
|
---|
4166 | /* If it is non-NULL and different, it will be selected and visible. */
|
---|
4167 | TREEVIEW_ITEM *newSelection = NULL;
|
---|
4168 | TREEVIEW_ITEM *prevItem = infoPtr->selectedItem;
|
---|
4169 |
|
---|
4170 | TREEVIEW_SendKeyDownNotify(infoPtr,TVN_KEYDOWN,wParam);
|
---|
4171 |
|
---|
4172 | //TRACE("%x %lx\n", wParam, lParam);
|
---|
4173 |
|
---|
4174 | if (prevItem == NULL)
|
---|
4175 | return FALSE;
|
---|
4176 |
|
---|
4177 | if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
|
---|
4178 | return TREEVIEW_ScrollKeyDown(infoPtr, wParam);
|
---|
4179 |
|
---|
4180 | switch (wParam)
|
---|
4181 | {
|
---|
4182 | case VK_UP:
|
---|
4183 | newSelection = TREEVIEW_GetPrevListItem(infoPtr, prevItem);
|
---|
4184 | if (!newSelection)
|
---|
4185 | newSelection = infoPtr->root->firstChild;
|
---|
4186 | break;
|
---|
4187 |
|
---|
4188 | case VK_DOWN:
|
---|
4189 | newSelection = TREEVIEW_GetNextListItem(infoPtr, prevItem);
|
---|
4190 | break;
|
---|
4191 |
|
---|
4192 | case VK_HOME:
|
---|
4193 | newSelection = infoPtr->root->firstChild;
|
---|
4194 | break;
|
---|
4195 |
|
---|
4196 | case VK_END:
|
---|
4197 | newSelection = TREEVIEW_GetLastListItem(infoPtr,
|
---|
4198 | infoPtr->root->lastChild);
|
---|
4199 | break;
|
---|
4200 |
|
---|
4201 | case VK_LEFT:
|
---|
4202 | if (prevItem->state & TVIS_EXPANDED)
|
---|
4203 | {
|
---|
4204 | TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
|
---|
4205 | }
|
---|
4206 | else if (prevItem->parent != infoPtr->root)
|
---|
4207 | {
|
---|
4208 | newSelection = prevItem->parent;
|
---|
4209 | }
|
---|
4210 | break;
|
---|
4211 |
|
---|
4212 | case VK_RIGHT:
|
---|
4213 | if (TREEVIEW_HasChildren(infoPtr, prevItem))
|
---|
4214 | {
|
---|
4215 | if (!(prevItem->state & TVIS_EXPANDED))
|
---|
4216 | TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
|
---|
4217 | else
|
---|
4218 | {
|
---|
4219 | newSelection = prevItem->firstChild;
|
---|
4220 | }
|
---|
4221 | }
|
---|
4222 |
|
---|
4223 | break;
|
---|
4224 |
|
---|
4225 | case VK_MULTIPLY:
|
---|
4226 | TREEVIEW_ExpandAll(infoPtr, prevItem);
|
---|
4227 | break;
|
---|
4228 |
|
---|
4229 | case VK_ADD:
|
---|
4230 | if (!(prevItem->state & TVIS_EXPANDED))
|
---|
4231 | TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
|
---|
4232 | break;
|
---|
4233 |
|
---|
4234 | case VK_SUBTRACT:
|
---|
4235 | if (prevItem->state & TVIS_EXPANDED)
|
---|
4236 | TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
|
---|
4237 | break;
|
---|
4238 |
|
---|
4239 | case VK_PRIOR:
|
---|
4240 | newSelection
|
---|
4241 | = TREEVIEW_GetListItem(infoPtr, prevItem,
|
---|
4242 | -TREEVIEW_GetVisibleCount(infoPtr));
|
---|
4243 | break;
|
---|
4244 |
|
---|
4245 | case VK_NEXT:
|
---|
4246 | newSelection
|
---|
4247 | = TREEVIEW_GetListItem(infoPtr, prevItem,
|
---|
4248 | TREEVIEW_GetVisibleCount(infoPtr));
|
---|
4249 | break;
|
---|
4250 |
|
---|
4251 | case VK_RETURN:
|
---|
4252 | sendNotify(infoPtr->hwnd,NM_RETURN);
|
---|
4253 | break;
|
---|
4254 |
|
---|
4255 | case VK_BACK:
|
---|
4256 | newSelection = prevItem->parent;
|
---|
4257 | if (newSelection == infoPtr->root)
|
---|
4258 | newSelection = NULL;
|
---|
4259 | break;
|
---|
4260 |
|
---|
4261 | case VK_SPACE:
|
---|
4262 | if (infoPtr->dwStyle & TVS_CHECKBOXES)
|
---|
4263 | TREEVIEW_ToggleItemState(infoPtr, prevItem);
|
---|
4264 | break;
|
---|
4265 | }
|
---|
4266 |
|
---|
4267 | if (newSelection && newSelection != prevItem)
|
---|
4268 | {
|
---|
4269 | if (TREEVIEW_DoSelectItem(infoPtr,TVGN_CARET,newSelection,TVC_BYKEYBOARD))
|
---|
4270 | {
|
---|
4271 | TREEVIEW_EnsureVisible(infoPtr, newSelection);
|
---|
4272 | }
|
---|
4273 | }
|
---|
4274 |
|
---|
4275 | return FALSE;
|
---|
4276 | }
|
---|
4277 |
|
---|
4278 | static LRESULT
|
---|
4279 | TREEVIEW_Size(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
4280 | {
|
---|
4281 | if (wParam == SIZE_RESTORED)
|
---|
4282 | {
|
---|
4283 | infoPtr->clientWidth = LOWORD(lParam);
|
---|
4284 | infoPtr->clientHeight = HIWORD(lParam);
|
---|
4285 | if (TREEVIEW_CalcItems(infoPtr))
|
---|
4286 | TREEVIEW_Refresh(infoPtr);
|
---|
4287 | }
|
---|
4288 |
|
---|
4289 | return 0;
|
---|
4290 | }
|
---|
4291 |
|
---|
4292 | static LRESULT
|
---|
4293 | TREEVIEW_StyleChanged(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
4294 | {
|
---|
4295 | //TRACE("(%x %lx)\n", wParam, lParam);
|
---|
4296 |
|
---|
4297 | if (wParam == GWL_STYLE)
|
---|
4298 | infoPtr->dwStyle = ((LPSTYLESTRUCT)lParam)->styleNew;
|
---|
4299 |
|
---|
4300 | if (infoPtr->hwndEdit) SetFocus(infoPtr->hwnd);
|
---|
4301 |
|
---|
4302 | infoPtr->uInternalStatus |= TV_CALCALL;
|
---|
4303 | TREEVIEW_QueueRefresh(infoPtr);
|
---|
4304 |
|
---|
4305 | return 0;
|
---|
4306 | }
|
---|
4307 |
|
---|
4308 | static LRESULT
|
---|
4309 | TREEVIEW_SetFocus(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
4310 | {
|
---|
4311 | sendNotify(infoPtr->hwnd,NM_SETFOCUS);
|
---|
4312 |
|
---|
4313 | if (!(infoPtr->dwStyle & TVS_SHOWSELALWAYS))
|
---|
4314 | {
|
---|
4315 | if (infoPtr->selectedItem)
|
---|
4316 | TREEVIEW_RefreshItem(infoPtr,infoPtr->selectedItem,TVIF_IMAGE | TVIF_TEXT);
|
---|
4317 | else if (infoPtr->firstVisible)
|
---|
4318 | TREEVIEW_DoSelectItem(infoPtr,TVGN_CARET,infoPtr->firstVisible,TVC_UNKNOWN);
|
---|
4319 | }
|
---|
4320 |
|
---|
4321 | return 0;
|
---|
4322 | }
|
---|
4323 |
|
---|
4324 | static LRESULT
|
---|
4325 | TREEVIEW_KillFocus(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
4326 | {
|
---|
4327 | sendNotify(infoPtr->hwnd,NM_KILLFOCUS);
|
---|
4328 |
|
---|
4329 | if (!(infoPtr->dwStyle & TVS_SHOWSELALWAYS) && infoPtr->selectedItem)
|
---|
4330 | TREEVIEW_RefreshItem(infoPtr,infoPtr->selectedItem,TVIF_IMAGE | TVIF_TEXT);
|
---|
4331 |
|
---|
4332 | return 0;
|
---|
4333 | }
|
---|
4334 |
|
---|
4335 | static LRESULT TREEVIEW_RButtonDoubleClick(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
4336 | {
|
---|
4337 | sendNotify(infoPtr->hwnd,NM_RDBLCLK);
|
---|
4338 |
|
---|
4339 | return DefWindowProcA(infoPtr->hwnd,WM_RBUTTONDBLCLK,wParam,lParam);
|
---|
4340 | }
|
---|
4341 |
|
---|
4342 |
|
---|
4343 | HTREEITEM TREEVIEW_GetInfoTipItem(TREEVIEW_INFO *infoPtr,POINT pt)
|
---|
4344 | {
|
---|
4345 | TVHITTESTINFO ht;
|
---|
4346 |
|
---|
4347 | ht.pt = pt;
|
---|
4348 | TREEVIEW_HitTest(infoPtr,&ht,FALSE);
|
---|
4349 |
|
---|
4350 | if (ht.hItem && (ht.flags & TVHT_ONITEM))
|
---|
4351 | {
|
---|
4352 | TREEVIEW_ITEM *item = ht.hItem;
|
---|
4353 |
|
---|
4354 | if (item->inclient && ((item->textOffset < 0) || (item->textOffset+item->textWidth > infoPtr->clientWidth)))
|
---|
4355 | return ht.hItem;
|
---|
4356 | }
|
---|
4357 |
|
---|
4358 | //check tool rect -> no flickering on tip frame
|
---|
4359 | if (infoPtr->tipItem)
|
---|
4360 | {
|
---|
4361 | POINT pt2 = pt;
|
---|
4362 | RECT rect;
|
---|
4363 |
|
---|
4364 | GetWindowRect(infoPtr->hwndToolTip,&rect);
|
---|
4365 | ClientToScreen(infoPtr->hwnd,&pt2);
|
---|
4366 | return PtInRect(&rect,pt2) ? infoPtr->tipItem:0;
|
---|
4367 | }
|
---|
4368 |
|
---|
4369 | return 0;
|
---|
4370 | }
|
---|
4371 |
|
---|
4372 | VOID TREEVIEW_ShowInfoTip(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item)
|
---|
4373 | {
|
---|
4374 | LPWSTR text;
|
---|
4375 | BOOL mustFree = FALSE;
|
---|
4376 | TTTOOLINFOW ti;
|
---|
4377 | POINT pt;
|
---|
4378 |
|
---|
4379 | if (infoPtr->dwStyle & TVS_INFOTIP)
|
---|
4380 | {
|
---|
4381 | NMTVGETINFOTIPW tvgit;
|
---|
4382 | WCHAR* buf = (WCHAR*)COMCTL32_Alloc(isUnicodeNotify(&infoPtr->header) ? INFOTIPSIZE*sizeof(WCHAR):INFOTIPSIZE*sizeof(CHAR));
|
---|
4383 |
|
---|
4384 | tvgit.pszText = buf;
|
---|
4385 | tvgit.cchTextMax = INFOTIPSIZE;
|
---|
4386 | tvgit.hItem = item;
|
---|
4387 | tvgit.lParam = item->lParam;
|
---|
4388 |
|
---|
4389 | sendNotify(infoPtr->hwnd,isUnicodeNotify(&infoPtr->header) ? TVN_GETINFOTIPW:TVN_GETINFOTIPA,&tvgit.hdr);
|
---|
4390 | if (isUnicodeNotify(&infoPtr->header))
|
---|
4391 | {
|
---|
4392 | if (buf != tvgit.pszText) COMCTL32_Free(buf); else mustFree = TRUE;
|
---|
4393 | text = tvgit.pszText;
|
---|
4394 | } else
|
---|
4395 | {
|
---|
4396 | text = (WCHAR*)COMCTL32_Alloc(tvgit.cchTextMax*sizeof(WCHAR));
|
---|
4397 | mustFree = TRUE;
|
---|
4398 | lstrcpyAtoW(text,(LPSTR)tvgit.pszText);
|
---|
4399 | COMCTL32_Free(buf);
|
---|
4400 | }
|
---|
4401 | } else
|
---|
4402 | {
|
---|
4403 | TREEVIEW_UpdateDispInfo(infoPtr,item,TVIF_TEXT);
|
---|
4404 | text = item->pszText;
|
---|
4405 | }
|
---|
4406 |
|
---|
4407 | infoPtr->tipItem = item;
|
---|
4408 | SetTimer(infoPtr->hwnd,TV_INFOTIP_TIMER,TV_INFOTIP_DELAY,0);
|
---|
4409 | infoPtr->Timer |= TV_INFOTIP_TIMER_SET;
|
---|
4410 |
|
---|
4411 | ti.cbSize = sizeof(ti);
|
---|
4412 | ti.uId = 0;
|
---|
4413 | ti.hwnd = infoPtr->hwnd;
|
---|
4414 | ti.hinst = 0;
|
---|
4415 | ti.lpszText = text;
|
---|
4416 | SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)FALSE,(LPARAM)&ti);
|
---|
4417 | pt.x = item->textOffset;
|
---|
4418 | pt.y = item->rect.top;
|
---|
4419 | ClientToScreen(infoPtr->hwnd,&pt);
|
---|
4420 | SendMessageA(infoPtr->hwndToolTip,TTM_TRACKPOSITION,0,(LPARAM)MAKELPARAM(pt.x,pt.y));
|
---|
4421 | SendMessageA(infoPtr->hwndToolTip,TTM_UPDATETIPTEXTW,0,(LPARAM)&ti);
|
---|
4422 | SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)TRUE,(LPARAM)&ti);
|
---|
4423 |
|
---|
4424 | if (mustFree) COMCTL32_Free(text);
|
---|
4425 | }
|
---|
4426 |
|
---|
4427 | VOID TREEVIEW_HideInfoTip(TREEVIEW_INFO *infoPtr)
|
---|
4428 | {
|
---|
4429 | if (infoPtr->tipItem)
|
---|
4430 | {
|
---|
4431 | TTTOOLINFOA ti;
|
---|
4432 |
|
---|
4433 | infoPtr->tipItem = 0;
|
---|
4434 | KillTimer(infoPtr->hwnd,TV_INFOTIP_TIMER);
|
---|
4435 | infoPtr->Timer &= ~TV_INFOTIP_TIMER_SET;
|
---|
4436 |
|
---|
4437 | ti.cbSize = sizeof(TTTOOLINFOA);
|
---|
4438 | ti.uId = 0;
|
---|
4439 | ti.hwnd = (UINT)infoPtr->hwnd;
|
---|
4440 |
|
---|
4441 | SendMessageA(infoPtr->hwndToolTip,TTM_TRACKACTIVATE,(WPARAM)FALSE,(LPARAM)&ti);
|
---|
4442 | }
|
---|
4443 | }
|
---|
4444 |
|
---|
4445 | static VOID TREEVIEW_CheckInfoTip(TREEVIEW_INFO *infoPtr)
|
---|
4446 | {
|
---|
4447 | HTREEITEM hItem;
|
---|
4448 | POINT pt;
|
---|
4449 |
|
---|
4450 | GetCursorPos(&pt);
|
---|
4451 | ScreenToClient(infoPtr->hwnd,&pt);
|
---|
4452 | hItem = TREEVIEW_GetInfoTipItem(infoPtr,pt);
|
---|
4453 |
|
---|
4454 | if (hItem != infoPtr->tipItem)
|
---|
4455 | TREEVIEW_HideInfoTip(infoPtr);
|
---|
4456 | }
|
---|
4457 |
|
---|
4458 | HTREEITEM TREEVIEW_GetHottrackItem(TREEVIEW_INFO *infoPtr,POINT pt)
|
---|
4459 | {
|
---|
4460 | TVHITTESTINFO ht;
|
---|
4461 |
|
---|
4462 | ht.pt = pt;
|
---|
4463 | TREEVIEW_HitTest(infoPtr,&ht,FALSE);
|
---|
4464 |
|
---|
4465 | return (ht.hItem && (ht.flags & TVHT_ONITEM)) ? ht.hItem:0;
|
---|
4466 | }
|
---|
4467 |
|
---|
4468 | static LRESULT TREEVIEW_MouseMove(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
4469 | {
|
---|
4470 | POINT pt;
|
---|
4471 |
|
---|
4472 | pt.x = (INT)LOWORD(lParam);
|
---|
4473 | pt.y = (INT)HIWORD(lParam);
|
---|
4474 |
|
---|
4475 | if (infoPtr->hwndToolTip)
|
---|
4476 | {
|
---|
4477 | HTREEITEM hItem = TREEVIEW_GetInfoTipItem(infoPtr,pt);
|
---|
4478 |
|
---|
4479 | if (infoPtr->tipItem != hItem)
|
---|
4480 | {
|
---|
4481 | if (hItem)
|
---|
4482 | {
|
---|
4483 | TREEVIEW_ITEM *item = hItem;
|
---|
4484 |
|
---|
4485 | TREEVIEW_ShowInfoTip(infoPtr,item);
|
---|
4486 | } else TREEVIEW_HideInfoTip(infoPtr);
|
---|
4487 | }
|
---|
4488 | }
|
---|
4489 |
|
---|
4490 | if (infoPtr->dwStyle & TVS_TRACKSELECT)
|
---|
4491 | {
|
---|
4492 | HTREEITEM hItem = TREEVIEW_GetHottrackItem(infoPtr,pt);
|
---|
4493 |
|
---|
4494 | if (infoPtr->hotItem != hItem)
|
---|
4495 | {
|
---|
4496 | TREEVIEW_ITEM *item;
|
---|
4497 | HDC hdc = 0;
|
---|
4498 |
|
---|
4499 | item = infoPtr->hotItem;
|
---|
4500 | if (TREEVIEW_ValidItem(infoPtr,infoPtr->hotItem))
|
---|
4501 | {
|
---|
4502 | if (!hdc) hdc = GetDC(infoPtr->hwnd);
|
---|
4503 | TREEVIEW_DrawHottrackLine(hdc,item);
|
---|
4504 | }
|
---|
4505 | if (hItem)
|
---|
4506 | {
|
---|
4507 | item = hItem;
|
---|
4508 | if (item)
|
---|
4509 | {
|
---|
4510 | if (!hdc) hdc = GetDC(infoPtr->hwnd);
|
---|
4511 | TREEVIEW_DrawHottrackLine(hdc,item);
|
---|
4512 | }
|
---|
4513 | }
|
---|
4514 | if (hdc) ReleaseDC(infoPtr->hwnd,hdc);
|
---|
4515 | }
|
---|
4516 | }
|
---|
4517 |
|
---|
4518 | return 0;
|
---|
4519 | }
|
---|
4520 |
|
---|
4521 | static LRESULT TREEVIEW_SetRedraw(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
4522 | {
|
---|
4523 | if (wParam)
|
---|
4524 | {
|
---|
4525 | if (!(infoPtr->uInternalStatus & TV_NOREDRAW)) return 0;
|
---|
4526 | infoPtr->uInternalStatus &= ~TV_NOREDRAW;
|
---|
4527 | TREEVIEW_CalcItems(infoPtr);
|
---|
4528 | TREEVIEW_Refresh(infoPtr);
|
---|
4529 | } else
|
---|
4530 | {
|
---|
4531 | infoPtr->uInternalStatus |= TV_NOREDRAW;
|
---|
4532 | }
|
---|
4533 |
|
---|
4534 | return 0;
|
---|
4535 | }
|
---|
4536 |
|
---|
4537 | static LRESULT
|
---|
4538 | TREEVIEW_SysColorChange(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
4539 | {
|
---|
4540 | TREEVIEW_Refresh(infoPtr);
|
---|
4541 |
|
---|
4542 | return DefWindowProcA(infoPtr->hwnd,WM_SYSCOLORCHANGE,wParam,lParam);
|
---|
4543 | }
|
---|
4544 |
|
---|
4545 | static LRESULT TREEVIEW_Enable(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
4546 | {
|
---|
4547 | TREEVIEW_Refresh(infoPtr);
|
---|
4548 |
|
---|
4549 | return DefWindowProcA(infoPtr->hwnd,WM_ENABLE,wParam,lParam);
|
---|
4550 | }
|
---|
4551 |
|
---|
4552 | static LRESULT
|
---|
4553 | TREEVIEW_EraseBackground(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
|
---|
4554 | {
|
---|
4555 | HBRUSH hBrush = CreateSolidBrush (infoPtr->clrBk);
|
---|
4556 | RECT rect;
|
---|
4557 |
|
---|
4558 | GetClientRect (infoPtr->hwnd, &rect);
|
---|
4559 | FillRect ((HDC)wParam, &rect, hBrush);
|
---|
4560 | DeleteObject (hBrush);
|
---|
4561 |
|
---|
4562 | return TRUE;
|
---|
4563 | }
|
---|
4564 |
|
---|
4565 | static LRESULT TREEVIEW_GetDlgCode(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
4566 | {
|
---|
4567 | return DLGC_WANTARROWS | DLGC_WANTCHARS;
|
---|
4568 | }
|
---|
4569 |
|
---|
4570 |
|
---|
4571 | static LRESULT TREEVIEW_Char(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
4572 | {
|
---|
4573 | CHAR ch = (CHAR)wParam;
|
---|
4574 |
|
---|
4575 | TREEVIEW_ISearch(infoPtr,ch);
|
---|
4576 |
|
---|
4577 | return 0;
|
---|
4578 | }
|
---|
4579 |
|
---|
4580 | static BOOL TREEVIEW_Compare(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item,LPWSTR text,INT textlen,BOOL *matchLast)
|
---|
4581 | {
|
---|
4582 | BOOL res;
|
---|
4583 | INT itemlen;
|
---|
4584 |
|
---|
4585 | TREEVIEW_UpdateDispInfo(infoPtr,item,TVIF_TEXT);
|
---|
4586 |
|
---|
4587 | itemlen = lstrlenW(item->pszText);
|
---|
4588 | if (itemlen < textlen)
|
---|
4589 | {
|
---|
4590 | res = FALSE;
|
---|
4591 | } else
|
---|
4592 | {
|
---|
4593 | res = (lstrcmpniW(item->pszText,text,textlen) == 0);
|
---|
4594 | }
|
---|
4595 | if (!res && matchLast)
|
---|
4596 | {
|
---|
4597 | textlen--;
|
---|
4598 | if ((textlen > 0) && (itemlen >= textlen))
|
---|
4599 | *matchLast = (lstrcmpniW(item->pszText,text,textlen) == 0);
|
---|
4600 | else
|
---|
4601 | *matchLast = FALSE;
|
---|
4602 | }
|
---|
4603 |
|
---|
4604 | return res;
|
---|
4605 | }
|
---|
4606 |
|
---|
4607 | static TREEVIEW_ITEM* TREEVIEW_Search(TREEVIEW_INFO *infoPtr,TREEVIEW_ITEM *item,LPWSTR text,INT textlen,TREEVIEW_ITEM **nearest)
|
---|
4608 | {
|
---|
4609 | TREEVIEW_ITEM *start;
|
---|
4610 | BOOL bMatchLast;
|
---|
4611 |
|
---|
4612 | start = item;
|
---|
4613 | if (nearest) *nearest = NULL;
|
---|
4614 |
|
---|
4615 | //search start to end
|
---|
4616 | while (item)
|
---|
4617 | {
|
---|
4618 | if (nearest)
|
---|
4619 | {
|
---|
4620 | if (TREEVIEW_Compare(infoPtr,item,text,textlen,(!*nearest) ? &bMatchLast:NULL))
|
---|
4621 | return item;
|
---|
4622 | else if (!*nearest && bMatchLast)
|
---|
4623 | *nearest = item;
|
---|
4624 | } else
|
---|
4625 | {
|
---|
4626 | if (TREEVIEW_Compare(infoPtr,item,text,textlen,NULL))
|
---|
4627 | return item;
|
---|
4628 | }
|
---|
4629 | item = TREEVIEW_GetNextListItem(infoPtr,item);
|
---|
4630 | }
|
---|
4631 |
|
---|
4632 | item = infoPtr->root;
|
---|
4633 |
|
---|
4634 | //search first to start
|
---|
4635 | while (item != start)
|
---|
4636 | {
|
---|
4637 | if (nearest)
|
---|
4638 | {
|
---|
4639 | if (TREEVIEW_Compare(infoPtr,item,text,textlen,(!*nearest) ? &bMatchLast:NULL))
|
---|
4640 | return item;
|
---|
4641 | else if (!*nearest && bMatchLast)
|
---|
4642 | *nearest = item;
|
---|
4643 | } else
|
---|
4644 | {
|
---|
4645 | if (TREEVIEW_Compare(infoPtr,item,text,textlen,NULL))
|
---|
4646 | return item;
|
---|
4647 | }
|
---|
4648 | item = TREEVIEW_GetNextListItem(infoPtr,item);
|
---|
4649 | }
|
---|
4650 |
|
---|
4651 | return NULL;
|
---|
4652 | }
|
---|
4653 |
|
---|
4654 | //NOTE: sister function in listview control -> sync changes
|
---|
4655 |
|
---|
4656 | static VOID TREEVIEW_ISearch(TREEVIEW_INFO *infoPtr,CHAR ch)
|
---|
4657 | {
|
---|
4658 | LPWSTR newString;
|
---|
4659 | INT len;
|
---|
4660 | CHAR ch2[2];
|
---|
4661 | TREEVIEW_ITEM *item,*nearest = NULL;
|
---|
4662 | DWORD dwISearchTime;
|
---|
4663 | BOOL checkNearest = TRUE;
|
---|
4664 |
|
---|
4665 | //check timer
|
---|
4666 | dwISearchTime = GetTickCount();
|
---|
4667 | if ((infoPtr->uISearchLen > 0) && (TICKDIFF(infoPtr->dwISearchTime,dwISearchTime) > TV_ISEARCH_DELAY))
|
---|
4668 | {
|
---|
4669 | COMCTL32_Free(infoPtr->pszISearch);
|
---|
4670 | infoPtr->pszISearch = NULL;
|
---|
4671 | infoPtr->uISearchLen = 0;
|
---|
4672 | }
|
---|
4673 |
|
---|
4674 | //prepare new search string
|
---|
4675 | len = infoPtr->uISearchLen+1;
|
---|
4676 | newString = (WCHAR*)COMCTL32_Alloc((len+1)*sizeof(WCHAR));
|
---|
4677 |
|
---|
4678 | if (infoPtr->uISearchLen > 0) lstrcpyW(newString,infoPtr->pszISearch);
|
---|
4679 |
|
---|
4680 | ch2[0] = ch;
|
---|
4681 | ch2[1] = 0;
|
---|
4682 | lstrcpyAtoW((LPWSTR)&newString[len-1],(LPSTR)&ch2);
|
---|
4683 | for (INT x = 1;x < len;x++)
|
---|
4684 | {
|
---|
4685 | if (newString[0] != newString[x])
|
---|
4686 | {
|
---|
4687 | checkNearest = FALSE;
|
---|
4688 | break;
|
---|
4689 | }
|
---|
4690 | }
|
---|
4691 |
|
---|
4692 | //search
|
---|
4693 |
|
---|
4694 | //start with selected item or root
|
---|
4695 | if (infoPtr->selectedItem)
|
---|
4696 | {
|
---|
4697 | item = infoPtr->selectedItem;
|
---|
4698 |
|
---|
4699 | //check if new string is valid for old selection
|
---|
4700 | if (TREEVIEW_Compare(infoPtr,item,newString,len,NULL))
|
---|
4701 | goto ISearchDone;
|
---|
4702 |
|
---|
4703 | //no match, continue with next item
|
---|
4704 | item = TREEVIEW_GetNextListItem(infoPtr,item);
|
---|
4705 | if (!item) item = infoPtr->root;
|
---|
4706 | } else item = infoPtr->root;
|
---|
4707 |
|
---|
4708 | //scan
|
---|
4709 | item = TREEVIEW_Search(infoPtr,item,newString,len,checkNearest ? &nearest:NULL);
|
---|
4710 |
|
---|
4711 | if (!item && nearest)
|
---|
4712 | {
|
---|
4713 | TREEVIEW_SelectItem(infoPtr,(WPARAM)TVGN_CARET,(LPARAM)nearest);
|
---|
4714 | TREEVIEW_EnsureVisible(infoPtr,nearest);
|
---|
4715 | infoPtr->dwISearchTime = GetTickCount();
|
---|
4716 |
|
---|
4717 | COMCTL32_Free(newString);
|
---|
4718 | return;
|
---|
4719 | }
|
---|
4720 |
|
---|
4721 | ISearchDone:
|
---|
4722 | //done
|
---|
4723 | if (item)
|
---|
4724 | {
|
---|
4725 | COMCTL32_Free(infoPtr->pszISearch);
|
---|
4726 | infoPtr->pszISearch = newString;
|
---|
4727 | infoPtr->uISearchLen = len;
|
---|
4728 | TREEVIEW_SelectItem(infoPtr,(WPARAM)TVGN_CARET,(LPARAM)item);
|
---|
4729 | TREEVIEW_EnsureVisible(infoPtr,item);
|
---|
4730 | infoPtr->dwISearchTime = GetTickCount();
|
---|
4731 | } else
|
---|
4732 | {
|
---|
4733 | COMCTL32_Free(newString);
|
---|
4734 | MessageBeep(0xFFFFFFFF);
|
---|
4735 | }
|
---|
4736 | }
|
---|
4737 |
|
---|
4738 | static LRESULT TREEVIEW_GetISearchString(TREEVIEW_INFO *infoPtr,LPWSTR lpsz,BOOL unicode)
|
---|
4739 | {
|
---|
4740 | if (infoPtr->uISearchLen == 0) return 0;
|
---|
4741 |
|
---|
4742 | if (unicode)
|
---|
4743 | lstrcpyW(lpsz,infoPtr->pszISearch);
|
---|
4744 | else
|
---|
4745 | lstrcpyWtoA((LPSTR)lpsz,infoPtr->pszISearch);
|
---|
4746 |
|
---|
4747 | return infoPtr->uISearchLen;
|
---|
4748 | }
|
---|
4749 |
|
---|
4750 | static LRESULT TREEVIEW_SetCursor(TREEVIEW_INFO *infoPtr,WPARAM wParam,LPARAM lParam)
|
---|
4751 | {
|
---|
4752 | sendNotify(infoPtr->hwnd,NM_SETCURSOR); //CB: todo: result
|
---|
4753 |
|
---|
4754 | return DefWindowProcA(infoPtr->hwnd,WM_SETCURSOR,wParam,lParam);
|
---|
4755 | }
|
---|
4756 |
|
---|
4757 | static LRESULT TREEVIEW_NCCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
4758 | {
|
---|
4759 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE),oldStyle = dwStyle;
|
---|
4760 |
|
---|
4761 | dwStyle &= ~(WS_HSCROLL | WS_VSCROLL);
|
---|
4762 | if (dwStyle != oldStyle) SetWindowLongA(hwnd,GWL_STYLE,dwStyle);
|
---|
4763 |
|
---|
4764 | return DefWindowProcA(hwnd,WM_NCCREATE,wParam,lParam);
|
---|
4765 | }
|
---|
4766 |
|
---|
4767 | static LRESULT WINAPI
|
---|
4768 | TREEVIEW_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
---|
4769 | {
|
---|
4770 | TREEVIEW_INFO *infoPtr;
|
---|
4771 |
|
---|
4772 | if (uMsg == WM_NCCREATE)
|
---|
4773 | {
|
---|
4774 | return TREEVIEW_NCCreate(hwnd,wParam,lParam);
|
---|
4775 | } else if (uMsg == WM_CREATE)
|
---|
4776 | {
|
---|
4777 | return TREEVIEW_Create(hwnd, wParam, lParam);
|
---|
4778 | }
|
---|
4779 |
|
---|
4780 | infoPtr = TREEVIEW_GetInfoPtr(hwnd);
|
---|
4781 | if (infoPtr) TREEVIEW_VerifyTree(infoPtr); else goto def;
|
---|
4782 |
|
---|
4783 | switch (uMsg)
|
---|
4784 | {
|
---|
4785 | case TVM_INSERTITEMA:
|
---|
4786 | return TREEVIEW_InsertItem(infoPtr,wParam,lParam,FALSE);
|
---|
4787 |
|
---|
4788 | case TVM_INSERTITEMW:
|
---|
4789 | return TREEVIEW_InsertItem(infoPtr,wParam,lParam,TRUE);
|
---|
4790 |
|
---|
4791 | case TVM_DELETEITEM:
|
---|
4792 | return TREEVIEW_DeleteItem(infoPtr,wParam,lParam);
|
---|
4793 |
|
---|
4794 | case TVM_EXPAND:
|
---|
4795 | return TREEVIEW_ExpandMsg(infoPtr,wParam,lParam);
|
---|
4796 |
|
---|
4797 | case TVM_GETITEMRECT:
|
---|
4798 | return TREEVIEW_GetItemRect(infoPtr,wParam,lParam);
|
---|
4799 |
|
---|
4800 | case TVM_GETCOUNT:
|
---|
4801 | return TREEVIEW_GetCount(infoPtr,wParam,lParam);
|
---|
4802 |
|
---|
4803 | case TVM_GETINDENT:
|
---|
4804 | return TREEVIEW_GetIndent(infoPtr);
|
---|
4805 |
|
---|
4806 | case TVM_SETINDENT:
|
---|
4807 | return TREEVIEW_SetIndent(infoPtr,wParam);
|
---|
4808 |
|
---|
4809 | case TVM_GETIMAGELIST:
|
---|
4810 | return TREEVIEW_GetImageList(infoPtr,wParam,lParam);
|
---|
4811 |
|
---|
4812 | case TVM_SETIMAGELIST:
|
---|
4813 | return TREEVIEW_SetImageList (infoPtr, wParam, lParam);
|
---|
4814 |
|
---|
4815 | case TVM_GETNEXTITEM:
|
---|
4816 | return TREEVIEW_GetNextItem (infoPtr, wParam, lParam);
|
---|
4817 |
|
---|
4818 | case TVM_SELECTITEM:
|
---|
4819 | return TREEVIEW_SelectItem (infoPtr, wParam, lParam);
|
---|
4820 |
|
---|
4821 | case TVM_GETITEMA:
|
---|
4822 | return TREEVIEW_GetItem(infoPtr,wParam,lParam,FALSE);
|
---|
4823 |
|
---|
4824 | case TVM_GETITEMW:
|
---|
4825 | return TREEVIEW_GetItem(infoPtr,wParam,lParam,TRUE);
|
---|
4826 |
|
---|
4827 | case TVM_SETITEMA:
|
---|
4828 | return TREEVIEW_SetItem(infoPtr,wParam,lParam,FALSE);
|
---|
4829 |
|
---|
4830 | case TVM_SETITEMW:
|
---|
4831 | return TREEVIEW_SetItem(infoPtr,wParam,lParam,TRUE);
|
---|
4832 |
|
---|
4833 | case TVM_EDITLABELA:
|
---|
4834 | return TREEVIEW_EditLabel(infoPtr,(HTREEITEM)lParam,FALSE);
|
---|
4835 |
|
---|
4836 | case TVM_EDITLABELW:
|
---|
4837 | return TREEVIEW_EditLabel(infoPtr,(HTREEITEM)lParam,TRUE);
|
---|
4838 |
|
---|
4839 | case TVM_GETEDITCONTROL:
|
---|
4840 | return TREEVIEW_GetEditControl (infoPtr);
|
---|
4841 |
|
---|
4842 | case TVM_GETVISIBLECOUNT:
|
---|
4843 | return TREEVIEW_GetVisibleCount (infoPtr);
|
---|
4844 |
|
---|
4845 | case TVM_HITTEST:
|
---|
4846 | return TREEVIEW_HitTest(infoPtr,(LPTVHITTESTINFO)lParam,FALSE);
|
---|
4847 |
|
---|
4848 | case TVM_CREATEDRAGIMAGE:
|
---|
4849 | return TREEVIEW_CreateDragImage (infoPtr, wParam, lParam);
|
---|
4850 |
|
---|
4851 | case TVM_SORTCHILDREN:
|
---|
4852 | return TREEVIEW_SortChildren(infoPtr, wParam, lParam);
|
---|
4853 |
|
---|
4854 | case TVM_ENSUREVISIBLE:
|
---|
4855 | return TREEVIEW_EnsureVisible(infoPtr,(HTREEITEM)lParam);
|
---|
4856 |
|
---|
4857 | case TVM_SORTCHILDRENCB:
|
---|
4858 | return TREEVIEW_SortChildrenCB(infoPtr, wParam, lParam);
|
---|
4859 |
|
---|
4860 | case TVM_ENDEDITLABELNOW:
|
---|
4861 | return TREEVIEW_EndEditLabelNow (infoPtr,(BOOL)wParam);
|
---|
4862 |
|
---|
4863 | case TVM_GETISEARCHSTRINGA:
|
---|
4864 | return TREEVIEW_GetISearchString(infoPtr,(LPWSTR)lParam,FALSE);
|
---|
4865 |
|
---|
4866 | case TVM_GETISEARCHSTRINGW:
|
---|
4867 | return TREEVIEW_GetISearchString(infoPtr,(LPWSTR)lParam,TRUE);
|
---|
4868 |
|
---|
4869 | case TVM_GETTOOLTIPS:
|
---|
4870 | return TREEVIEW_GetToolTips (infoPtr);
|
---|
4871 |
|
---|
4872 | case TVM_SETTOOLTIPS:
|
---|
4873 | return TREEVIEW_SetToolTips (infoPtr, wParam);
|
---|
4874 |
|
---|
4875 | case TVM_SETINSERTMARK:
|
---|
4876 | return TREEVIEW_SetInsertMark (infoPtr,wParam, lParam);
|
---|
4877 |
|
---|
4878 | case TVM_SETITEMHEIGHT:
|
---|
4879 | return TREEVIEW_SetItemHeight (infoPtr, wParam);
|
---|
4880 |
|
---|
4881 | case TVM_GETITEMHEIGHT:
|
---|
4882 | return TREEVIEW_GetItemHeight (infoPtr);
|
---|
4883 |
|
---|
4884 | case TVM_SETBKCOLOR:
|
---|
4885 | return TREEVIEW_SetBkColor (infoPtr, wParam, lParam);
|
---|
4886 |
|
---|
4887 | case TVM_SETTEXTCOLOR:
|
---|
4888 | return TREEVIEW_SetTextColor (infoPtr, wParam, lParam);
|
---|
4889 |
|
---|
4890 | case TVM_GETBKCOLOR:
|
---|
4891 | return TREEVIEW_GetBkColor (infoPtr);
|
---|
4892 |
|
---|
4893 | case TVM_GETTEXTCOLOR:
|
---|
4894 | return TREEVIEW_GetTextColor (infoPtr);
|
---|
4895 |
|
---|
4896 | case TVM_SETSCROLLTIME:
|
---|
4897 | return TREEVIEW_SetScrollTime (infoPtr, (UINT)wParam);
|
---|
4898 |
|
---|
4899 | case TVM_GETSCROLLTIME:
|
---|
4900 | return TREEVIEW_GetScrollTime (infoPtr);
|
---|
4901 |
|
---|
4902 | case TVM_GETITEMSTATE:
|
---|
4903 | return TREEVIEW_GetItemState (infoPtr,wParam, lParam);
|
---|
4904 |
|
---|
4905 | case TVM_GETLINECOLOR:
|
---|
4906 | return TREEVIEW_GetLineColor (infoPtr,wParam, lParam);
|
---|
4907 |
|
---|
4908 | case TVM_SETLINECOLOR:
|
---|
4909 | return TREEVIEW_SetLineColor (infoPtr,wParam, lParam);
|
---|
4910 |
|
---|
4911 | case TVM_SETINSERTMARKCOLOR:
|
---|
4912 | return TREEVIEW_SetInsertMarkColor (infoPtr,wParam, lParam);
|
---|
4913 |
|
---|
4914 | case TVM_GETINSERTMARKCOLOR:
|
---|
4915 | return TREEVIEW_GetInsertMarkColor (infoPtr,wParam, lParam);
|
---|
4916 |
|
---|
4917 | case WM_COMMAND:
|
---|
4918 | return TREEVIEW_Command (infoPtr, wParam, lParam);
|
---|
4919 |
|
---|
4920 | case WM_DESTROY:
|
---|
4921 | return TREEVIEW_Destroy (infoPtr);
|
---|
4922 |
|
---|
4923 | case WM_ENABLE:
|
---|
4924 | return TREEVIEW_Enable(infoPtr,wParam,lParam);
|
---|
4925 |
|
---|
4926 | case WM_ERASEBKGND:
|
---|
4927 | return TREEVIEW_EraseBackground (infoPtr, wParam, lParam);
|
---|
4928 |
|
---|
4929 | case WM_GETDLGCODE:
|
---|
4930 | return TREEVIEW_GetDlgCode(infoPtr,wParam,lParam);
|
---|
4931 |
|
---|
4932 | case WM_PAINT:
|
---|
4933 | return TREEVIEW_Paint (infoPtr, wParam, lParam);
|
---|
4934 |
|
---|
4935 | case WM_GETFONT:
|
---|
4936 | return TREEVIEW_GetFont (infoPtr, wParam, lParam);
|
---|
4937 |
|
---|
4938 | case WM_SETFONT:
|
---|
4939 | return TREEVIEW_SetFont (infoPtr, wParam, lParam);
|
---|
4940 |
|
---|
4941 | case WM_KEYDOWN:
|
---|
4942 | return TREEVIEW_KeyDown (infoPtr, wParam, lParam);
|
---|
4943 |
|
---|
4944 | case WM_CHAR:
|
---|
4945 | return TREEVIEW_Char(infoPtr,wParam,lParam);
|
---|
4946 |
|
---|
4947 | case WM_SETFOCUS:
|
---|
4948 | return TREEVIEW_SetFocus (infoPtr, wParam, lParam);
|
---|
4949 |
|
---|
4950 | case WM_KILLFOCUS:
|
---|
4951 | return TREEVIEW_KillFocus (infoPtr, wParam, lParam);
|
---|
4952 |
|
---|
4953 | case WM_MOUSEMOVE:
|
---|
4954 | return TREEVIEW_MouseMove(infoPtr,wParam,lParam);
|
---|
4955 |
|
---|
4956 | case WM_LBUTTONDOWN:
|
---|
4957 | return TREEVIEW_LButtonDown (infoPtr, wParam, lParam);
|
---|
4958 |
|
---|
4959 | case WM_LBUTTONDBLCLK:
|
---|
4960 | return TREEVIEW_LButtonDoubleClick (infoPtr, wParam, lParam);
|
---|
4961 |
|
---|
4962 | case WM_RBUTTONDOWN:
|
---|
4963 | return TREEVIEW_RButtonDown (infoPtr, wParam, lParam);
|
---|
4964 |
|
---|
4965 | case WM_RBUTTONDBLCLK:
|
---|
4966 | return TREEVIEW_RButtonDoubleClick(infoPtr,wParam,lParam);
|
---|
4967 |
|
---|
4968 | case WM_STYLECHANGED:
|
---|
4969 | return TREEVIEW_StyleChanged (infoPtr, wParam, lParam);
|
---|
4970 |
|
---|
4971 | case WM_SYSCOLORCHANGE:
|
---|
4972 | return TREEVIEW_SysColorChange(infoPtr,wParam,lParam);
|
---|
4973 |
|
---|
4974 | case WM_SETCURSOR:
|
---|
4975 | return TREEVIEW_SetCursor(infoPtr,wParam,lParam);
|
---|
4976 |
|
---|
4977 | case WM_SETREDRAW:
|
---|
4978 | return TREEVIEW_SetRedraw(infoPtr,wParam,lParam);
|
---|
4979 |
|
---|
4980 | case WM_TIMER:
|
---|
4981 | return TREEVIEW_HandleTimer (infoPtr, wParam, lParam);
|
---|
4982 |
|
---|
4983 | case WM_SIZE:
|
---|
4984 | return TREEVIEW_Size (infoPtr, wParam,lParam);
|
---|
4985 |
|
---|
4986 | case WM_HSCROLL:
|
---|
4987 | return TREEVIEW_HScroll (infoPtr, wParam, lParam);
|
---|
4988 |
|
---|
4989 | case WM_VSCROLL:
|
---|
4990 | return TREEVIEW_VScroll (infoPtr, wParam, lParam);
|
---|
4991 |
|
---|
4992 | case WM_MOUSEWHEEL:
|
---|
4993 | return TREEVIEW_MouseWheel (infoPtr, wParam, lParam);
|
---|
4994 |
|
---|
4995 | case WM_DRAWITEM:
|
---|
4996 | //printf ("drawItem\n");
|
---|
4997 | return DefWindowProcA (hwnd, uMsg, wParam, lParam);
|
---|
4998 |
|
---|
4999 | default:
|
---|
5000 | def:
|
---|
5001 | return defComCtl32ProcA(hwnd,uMsg,wParam,lParam);
|
---|
5002 | }
|
---|
5003 | return 0;
|
---|
5004 | }
|
---|
5005 |
|
---|
5006 | /* Tree Verification ****************************************************/
|
---|
5007 |
|
---|
5008 | #ifndef NDEBUG
|
---|
5009 | static inline void
|
---|
5010 | TREEVIEW_VerifyChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item);
|
---|
5011 |
|
---|
5012 | static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO *infoPtr,
|
---|
5013 | TREEVIEW_ITEM *item)
|
---|
5014 | {
|
---|
5015 | TREEVIEW_WriteVerify("TV: checking infoPtr");
|
---|
5016 | assert(infoPtr != NULL);
|
---|
5017 | TREEVIEW_WriteVerify("TV: checking item");
|
---|
5018 | assert(item != NULL);
|
---|
5019 |
|
---|
5020 | /* both NULL, or both non-null */
|
---|
5021 | TREEVIEW_WriteVerify("TV: checking firstChild,lastChild");
|
---|
5022 | assert((item->firstChild == NULL) == (item->lastChild == NULL));
|
---|
5023 |
|
---|
5024 | TREEVIEW_WriteVerify("TV: checking firstChild,lastChild != item");
|
---|
5025 | assert(item->firstChild != item);
|
---|
5026 | assert(item->lastChild != item);
|
---|
5027 |
|
---|
5028 | TREEVIEW_WriteVerify("TV: checking firstChild");
|
---|
5029 | if (item->firstChild)
|
---|
5030 | {
|
---|
5031 | assert(item->firstChild->parent == item);
|
---|
5032 | assert(item->firstChild->prevSibling == NULL);
|
---|
5033 | }
|
---|
5034 |
|
---|
5035 | TREEVIEW_WriteVerify("TV: checking lastChild");
|
---|
5036 | if (item->lastChild)
|
---|
5037 | {
|
---|
5038 | TREEVIEW_WriteVerify("TV: checking lastChild->parent");
|
---|
5039 | assert(item->lastChild->parent == item);
|
---|
5040 | TREEVIEW_WriteVerify("TV: checking lastChild->nextSibling");
|
---|
5041 | assert(item->lastChild->nextSibling == NULL);
|
---|
5042 | }
|
---|
5043 |
|
---|
5044 | TREEVIEW_WriteVerify("TV: checking nextSibling");
|
---|
5045 | assert(item->nextSibling != item);
|
---|
5046 | if (item->nextSibling)
|
---|
5047 | {
|
---|
5048 | assert(item->nextSibling->parent == item->parent);
|
---|
5049 | assert(item->nextSibling->prevSibling == item);
|
---|
5050 | }
|
---|
5051 |
|
---|
5052 | TREEVIEW_WriteVerify("TV: checking prevSibling");
|
---|
5053 | assert(item->prevSibling != item);
|
---|
5054 | if (item->prevSibling)
|
---|
5055 | {
|
---|
5056 | assert(item->prevSibling->parent == item->parent);
|
---|
5057 | assert(item->prevSibling->nextSibling == item);
|
---|
5058 | }
|
---|
5059 | }
|
---|
5060 |
|
---|
5061 | static inline void
|
---|
5062 | TREEVIEW_VerifyItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
|
---|
5063 | {
|
---|
5064 | TREEVIEW_WriteVerify("TV: checking item");
|
---|
5065 | assert(item != NULL);
|
---|
5066 |
|
---|
5067 | TREEVIEW_WriteVerify("TV: checking parent, iLevel");
|
---|
5068 | assert(item->parent != NULL);
|
---|
5069 | assert(item->parent != item);
|
---|
5070 | assert(item->iLevel == item->parent->iLevel + 1);
|
---|
5071 |
|
---|
5072 | TREEVIEW_WriteVerify("TV: checking PtrIndex");
|
---|
5073 | assert(DPA_GetPtrIndex(infoPtr->items, item) != -1);
|
---|
5074 |
|
---|
5075 | TREEVIEW_VerifyItemCommon(infoPtr, item);
|
---|
5076 |
|
---|
5077 | TREEVIEW_VerifyChildren(infoPtr, item);
|
---|
5078 | }
|
---|
5079 |
|
---|
5080 | static inline void
|
---|
5081 | TREEVIEW_VerifyChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
|
---|
5082 | {
|
---|
5083 | TREEVIEW_ITEM *child;
|
---|
5084 | assert(item != NULL);
|
---|
5085 |
|
---|
5086 | for (child = item->firstChild; child != NULL; child = child->nextSibling)
|
---|
5087 | TREEVIEW_VerifyItem(infoPtr, child);
|
---|
5088 | }
|
---|
5089 |
|
---|
5090 | static inline void
|
---|
5091 | TREEVIEW_VerifyRoot(TREEVIEW_INFO *infoPtr)
|
---|
5092 | {
|
---|
5093 | TREEVIEW_ITEM *root = infoPtr->root;
|
---|
5094 |
|
---|
5095 | TREEVIEW_WriteVerify("TV: checking root");
|
---|
5096 | assert(root != NULL);
|
---|
5097 | TREEVIEW_WriteVerify("TV: checking iLevel");
|
---|
5098 | assert(root->iLevel == -1);
|
---|
5099 | TREEVIEW_WriteVerify("TV: checking parent");
|
---|
5100 | assert(root->parent == NULL);
|
---|
5101 | TREEVIEW_WriteVerify("TV: checking prevSibling");
|
---|
5102 | assert(root->prevSibling == NULL);
|
---|
5103 |
|
---|
5104 | TREEVIEW_VerifyItemCommon(infoPtr, root);
|
---|
5105 |
|
---|
5106 | TREEVIEW_VerifyChildren(infoPtr, root);
|
---|
5107 | }
|
---|
5108 |
|
---|
5109 | static void
|
---|
5110 | TREEVIEW_VerifyTree(TREEVIEW_INFO *infoPtr)
|
---|
5111 | {
|
---|
5112 | TREEVIEW_WriteVerify("TV: checking infoPtr");
|
---|
5113 | assert(infoPtr != NULL);
|
---|
5114 |
|
---|
5115 | TREEVIEW_VerifyRoot(infoPtr);
|
---|
5116 | }
|
---|
5117 | #endif
|
---|
5118 |
|
---|
5119 | /* Class Registration ***************************************************/
|
---|
5120 |
|
---|
5121 | VOID TREEVIEW_Register (VOID)
|
---|
5122 | {
|
---|
5123 | WNDCLASSA wndClass;
|
---|
5124 |
|
---|
5125 | ZeroMemory (&wndClass, sizeof(WNDCLASSA));
|
---|
5126 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
|
---|
5127 | wndClass.lpfnWndProc = (WNDPROC)TREEVIEW_WindowProc;
|
---|
5128 | wndClass.cbClsExtra = 0;
|
---|
5129 | wndClass.cbWndExtra = sizeof(TREEVIEW_INFO *);
|
---|
5130 | wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
|
---|
5131 | wndClass.hbrBackground = 0;
|
---|
5132 | wndClass.lpszClassName = WC_TREEVIEWA;
|
---|
5133 |
|
---|
5134 | RegisterClassA (&wndClass);
|
---|
5135 | }
|
---|
5136 |
|
---|
5137 |
|
---|
5138 | VOID TREEVIEW_Unregister (VOID)
|
---|
5139 | {
|
---|
5140 | UnregisterClassA (WC_TREEVIEWA, (HINSTANCE)NULL);
|
---|
5141 | }
|
---|