3 * Copyright 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de>
4 * Copyright 1998,1999 Alex Priem <alexp@sci.kun.nl>
5 * Copyright 1999 Sylvain St-Germain
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Note that TREEVIEW_INFO * and HTREEITEM are the same thing.
23 * Note2: All items always! have valid (allocated) pszText field.
24 * If item's text == LPSTR_TEXTCALLBACKA we allocate buffer
25 * of size TEXT_CALLBACK_SIZE in DoSetItem.
26 * We use callbackMask to keep track of fields to be updated.
29 * missing notifications: NM_SETCURSOR, TVN_GETINFOTIP, TVN_KEYDOWN,
30 * TVN_SETDISPINFO, TVN_SINGLEEXPAND
32 * missing styles: TVS_FULLROWSELECT, TVS_INFOTIP, TVS_NOSCROLL,
33 * TVS_RTLREADING, TVS_TRACKSELECT
35 * missing item styles: TVIS_CUT, TVIS_EXPANDPARTIAL
37 * Make the insertion mark look right.
38 * Scroll (instead of repaint) as much as possible.
51 #include "wine/debug.h"
53 /* internal structures */
55 typedef struct _TREEITEM /* HTREEITEM is a _TREEINFO *. */
66 int iIntegral; /* item height multiplier (1 is normal) */
67 int iLevel; /* indentation level:0=root level */
68 HTREEITEM parent; /* handle to parent or 0 if at root */
69 HTREEITEM firstChild; /* handle to first child or 0 if no child */
71 HTREEITEM prevSibling; /* handle to prev item in list, 0 if first */
72 HTREEITEM nextSibling; /* handle to next item in list, 0 if last */
78 LONG textWidth; /* horizontal text extent for pszText */
79 LONG visibleOrder; /* visible ordering, 0 is first visible item */
83 typedef struct tagTREEVIEW_INFO
86 HWND hwndNotify; /* Owner window to send notifications to */
91 UINT uNumItems; /* number of valid TREEVIEW_ITEMs */
92 INT cdmode; /* last custom draw setting */
93 UINT uScrollTime; /* max. time for scrolling in milliseconds */
94 BOOL bRedraw; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
96 UINT uItemHeight; /* item height */
99 LONG clientWidth; /* width of control window */
100 LONG clientHeight; /* height of control window */
102 LONG treeWidth; /* width of visible tree items */
103 LONG treeHeight; /* height of visible tree items */
105 UINT uIndent; /* indentation in pixels */
106 HTREEITEM selectedItem; /* handle to selected item or 0 if none */
107 HTREEITEM hotItem; /* handle currently under cursor, 0 if none */
108 HTREEITEM focusedItem; /* item that was under the cursor when WM_LBUTTONDOWN was received */
110 HTREEITEM firstVisible; /* handle to first visible item */
111 LONG maxVisibleOrder;
112 HTREEITEM dropItem; /* handle to item selected by drag cursor */
113 HTREEITEM insertMarkItem; /* item after which insertion mark is placed */
114 BOOL insertBeforeorAfter; /* flag used by TVM_SETINSERTMARK */
115 HIMAGELIST dragList; /* Bitmap of dragged item */
120 COLORREF clrInsertMark;
126 WNDPROC wpEditOrig; /* orig window proc for subclassing edit */
127 BOOL bIgnoreEditKillFocus;
130 BOOL bNtfUnicode; /* TRUE if should send NOTIFY with W */
131 BOOL bUnicode; /* set by CCM_SETUNICODEFORMAT */
132 HIMAGELIST himlNormal;
133 int normalImageHeight;
134 int normalImageWidth;
135 HIMAGELIST himlState;
136 int stateImageHeight;
140 DWORD lastKeyPressTimestamp; /* Added */
141 WPARAM charCode; /* Added */
142 INT nSearchParamLength; /* Added */
143 CHAR szSearchParam[ MAX_PATH ]; /* Added */
147 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
148 #define KEY_DELAY 450
150 /* bitflags for infoPtr->uInternalStatus */
152 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
153 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
154 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
155 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
156 #define TV_RDRAG 0x10 /* dito Rbutton */
157 #define TV_RDRAGGING 0x20
159 /* bitflags for infoPtr->timer */
161 #define TV_EDIT_TIMER 2
162 #define TV_EDIT_TIMER_SET 2
165 VOID TREEVIEW_Register (VOID);
166 VOID TREEVIEW_Unregister (VOID);
169 WINE_DEFAULT_DEBUG_CHANNEL(treeview);
172 #define TEXT_CALLBACK_SIZE 260
174 #define TREEVIEW_LEFT_MARGIN 8
176 #define MINIMUM_INDENT 19
178 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
180 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
181 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
182 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
185 typedef VOID (*TREEVIEW_ItemEnumFunc)(TREEVIEW_INFO *, TREEVIEW_ITEM *,LPVOID);
188 static VOID TREEVIEW_Invalidate(TREEVIEW_INFO *, TREEVIEW_ITEM *);
190 static LRESULT TREEVIEW_DoSelectItem(TREEVIEW_INFO *, INT, HTREEITEM, INT);
191 static VOID TREEVIEW_SetFirstVisible(TREEVIEW_INFO *, TREEVIEW_ITEM *, BOOL);
192 static LRESULT TREEVIEW_EnsureVisible(TREEVIEW_INFO *, HTREEITEM, BOOL);
193 static LRESULT TREEVIEW_RButtonUp(TREEVIEW_INFO *, LPPOINT);
194 static LRESULT TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel);
195 static VOID TREEVIEW_UpdateScrollBars(TREEVIEW_INFO *infoPtr);
196 static LRESULT TREEVIEW_HScroll(TREEVIEW_INFO *, WPARAM);
197 static INT TREEVIEW_NotifyFormat (TREEVIEW_INFO *infoPtr, HWND wParam, UINT lParam);
200 /* Random Utilities *****************************************************/
204 TREEVIEW_VerifyTree(TREEVIEW_INFO *infoPtr)
209 /* The definition is at the end of the file. */
210 static void TREEVIEW_VerifyTree(TREEVIEW_INFO *infoPtr);
213 /* Returns the treeview private data if hwnd is a treeview.
214 * Otherwise returns an undefined value. */
215 static TREEVIEW_INFO *
216 TREEVIEW_GetInfoPtr(HWND hwnd)
218 return (TREEVIEW_INFO *)GetWindowLongA(hwnd, 0);
221 /* Don't call this. Nothing wants an item index. */
223 TREEVIEW_GetItemIndex(TREEVIEW_INFO *infoPtr, HTREEITEM handle)
225 assert(infoPtr != NULL);
227 return DPA_GetPtrIndex(infoPtr->items, handle);
230 /***************************************************************************
231 * This method checks that handle is an item for this tree.
234 TREEVIEW_ValidItem(TREEVIEW_INFO *infoPtr, HTREEITEM handle)
236 if (TREEVIEW_GetItemIndex(infoPtr, handle) == -1)
238 TRACE("invalid item %p\n", handle);
246 TREEVIEW_CreateBoldFont(HFONT hOrigFont)
250 GetObjectA(hOrigFont, sizeof(font), &font);
251 font.lfWeight = FW_BOLD;
252 return CreateFontIndirectA(&font);
256 TREEVIEW_FontForItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
258 return (item->state & TVIS_BOLD) ? infoPtr->hBoldFont : infoPtr->hFont;
261 /* for trace/debugging purposes only */
263 TREEVIEW_ItemName(TREEVIEW_ITEM *item)
265 if (item == NULL) return "<null item>";
266 if (item->pszText == LPSTR_TEXTCALLBACKA) return "<callback>";
267 if (item->pszText == NULL) return "<null>";
268 return item->pszText;
271 /* An item is not a child of itself. */
273 TREEVIEW_IsChildOf(TREEVIEW_ITEM *parent, TREEVIEW_ITEM *child)
277 child = child->parent;
278 if (child == parent) return TRUE;
279 } while (child != NULL);
285 /* Tree Traversal *******************************************************/
287 /***************************************************************************
288 * This method returns the last expanded sibling or child child item
291 static TREEVIEW_ITEM *
292 TREEVIEW_GetLastListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
297 while (wineItem->lastChild)
299 if (wineItem->state & TVIS_EXPANDED)
300 wineItem = wineItem->lastChild;
305 if (wineItem == infoPtr->root)
311 /***************************************************************************
312 * This method returns the previous non-hidden item in the list not
313 * considering the tree hierarchy.
315 static TREEVIEW_ITEM *
316 TREEVIEW_GetPrevListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *tvItem)
318 if (tvItem->prevSibling)
320 /* This item has a prevSibling, get the last item in the sibling's tree. */
321 TREEVIEW_ITEM *upItem = tvItem->prevSibling;
323 if ((upItem->state & TVIS_EXPANDED) && upItem->lastChild != NULL)
324 return TREEVIEW_GetLastListItem(infoPtr, upItem->lastChild);
330 /* this item does not have a prevSibling, get the parent */
331 return (tvItem->parent != infoPtr->root) ? tvItem->parent : NULL;
336 /***************************************************************************
337 * This method returns the next physical item in the treeview not
338 * considering the tree hierarchy.
340 static TREEVIEW_ITEM *
341 TREEVIEW_GetNextListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *tvItem)
343 assert(tvItem != NULL);
346 * If this item has children and is expanded, return the first child
348 if ((tvItem->state & TVIS_EXPANDED) && tvItem->firstChild != NULL)
350 return tvItem->firstChild;
355 * try to get the sibling
357 if (tvItem->nextSibling)
358 return tvItem->nextSibling;
361 * Otherwise, get the parent's sibling.
363 while (tvItem->parent)
365 tvItem = tvItem->parent;
367 if (tvItem->nextSibling)
368 return tvItem->nextSibling;
374 /***************************************************************************
375 * This method returns the nth item starting at the given item. It returns
376 * the last item (or first) we we run out of items.
378 * Will scroll backward if count is <0.
379 * forward if count is >0.
381 static TREEVIEW_ITEM *
382 TREEVIEW_GetListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
385 TREEVIEW_ITEM *(*next_item)(TREEVIEW_INFO *, TREEVIEW_ITEM *);
386 TREEVIEW_ITEM *previousItem;
388 assert(wineItem != NULL);
392 next_item = TREEVIEW_GetNextListItem;
397 next_item = TREEVIEW_GetPrevListItem;
404 previousItem = wineItem;
405 wineItem = next_item(infoPtr, wineItem);
407 } while (--count && wineItem != NULL);
410 return wineItem ? wineItem : previousItem;
413 /* Notifications ************************************************************/
415 static INT get_notifycode(TREEVIEW_INFO *infoPtr, INT code)
417 if (!infoPtr->bNtfUnicode) {
419 case TVN_SELCHANGINGW: return TVN_SELCHANGINGA;
420 case TVN_SELCHANGEDW: return TVN_SELCHANGEDA;
421 case TVN_GETDISPINFOW: return TVN_GETDISPINFOA;
422 case TVN_SETDISPINFOW: return TVN_SETDISPINFOA;
423 case TVN_ITEMEXPANDINGW: return TVN_ITEMEXPANDINGA;
424 case TVN_ITEMEXPANDEDW: return TVN_ITEMEXPANDEDA;
425 case TVN_BEGINDRAGW: return TVN_BEGINDRAGA;
426 case TVN_BEGINRDRAGW: return TVN_BEGINRDRAGA;
427 case TVN_DELETEITEMW: return TVN_DELETEITEMA;
428 case TVN_BEGINLABELEDITW: return TVN_BEGINLABELEDITA;
429 case TVN_ENDLABELEDITW: return TVN_ENDLABELEDITA;
430 case TVN_GETINFOTIPW: return TVN_GETINFOTIPA;
437 TREEVIEW_SendRealNotify(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
439 TRACE("wParam=%d, lParam=%ld\n", wParam, lParam);
440 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
444 TREEVIEW_SendSimpleNotify(TREEVIEW_INFO *infoPtr, UINT code)
447 HWND hwnd = infoPtr->hwnd;
450 nmhdr.hwndFrom = hwnd;
451 nmhdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
452 nmhdr.code = get_notifycode(infoPtr, code);
454 return (BOOL)TREEVIEW_SendRealNotify(infoPtr,
455 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
459 TREEVIEW_TVItemFromItem(TREEVIEW_INFO *infoPtr, UINT mask, TVITEMA *tvItem, TREEVIEW_ITEM *item)
462 tvItem->hItem = item;
463 tvItem->state = item->state;
464 tvItem->stateMask = 0;
465 tvItem->iImage = item->iImage;
466 tvItem->cchTextMax = item->cchTextMax;
467 tvItem->iImage = item->iImage;
468 tvItem->iSelectedImage = item->iSelectedImage;
469 tvItem->cChildren = item->cChildren;
470 tvItem->lParam = item->lParam;
472 /* **** **** **** **** WARNING **** **** **** **** */
473 /* This control stores all the data in A format */
474 /* we will convert it to W if the notify format */
476 /* **** **** **** **** WARNING **** **** **** **** */
477 if (infoPtr->bNtfUnicode) {
478 INT len = MultiByteToWideChar( CP_ACP, 0, item->pszText, -1, NULL, 0 );
480 tvItem->pszText = (LPSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
481 MultiByteToWideChar( CP_ACP, 0, item->pszText, -1, (LPWSTR)tvItem->pszText, len*sizeof(WCHAR) );
485 tvItem->pszText = item->pszText;
489 TREEVIEW_SendTreeviewNotify(TREEVIEW_INFO *infoPtr, UINT code, UINT action,
490 UINT mask, HTREEITEM oldItem, HTREEITEM newItem)
492 HWND hwnd = infoPtr->hwnd;
496 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
497 code, action, oldItem, newItem);
499 ZeroMemory(&nmhdr, sizeof(NMTREEVIEWA));
501 nmhdr.hdr.hwndFrom = hwnd;
502 nmhdr.hdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
503 nmhdr.hdr.code = get_notifycode(infoPtr, code);
504 nmhdr.action = action;
507 TREEVIEW_TVItemFromItem(infoPtr, mask, &nmhdr.itemOld, oldItem);
510 TREEVIEW_TVItemFromItem(infoPtr, mask, &nmhdr.itemNew, newItem);
515 ret = (BOOL)TREEVIEW_SendRealNotify(infoPtr,
516 (WPARAM)GetWindowLongA(hwnd, GWL_ID),
518 if (infoPtr->bNtfUnicode) {
519 COMCTL32_Free(nmhdr.itemOld.pszText);
520 COMCTL32_Free(nmhdr.itemNew.pszText);
526 TREEVIEW_SendTreeviewDnDNotify(TREEVIEW_INFO *infoPtr, UINT code,
527 HTREEITEM dragItem, POINT pt)
529 HWND hwnd = infoPtr->hwnd;
532 TRACE("code:%d dragitem:%p\n", code, dragItem);
534 nmhdr.hdr.hwndFrom = hwnd;
535 nmhdr.hdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
536 nmhdr.hdr.code = get_notifycode(infoPtr, code);
538 nmhdr.itemNew.mask = TVIF_STATE | TVIF_PARAM | TVIF_HANDLE;
539 nmhdr.itemNew.hItem = dragItem;
540 nmhdr.itemNew.state = dragItem->state;
541 nmhdr.itemNew.lParam = dragItem->lParam;
543 nmhdr.ptDrag.x = pt.x;
544 nmhdr.ptDrag.y = pt.y;
546 return (BOOL)TREEVIEW_SendRealNotify(infoPtr,
547 (WPARAM)GetWindowLongA(hwnd, GWL_ID),
553 TREEVIEW_SendCustomDrawNotify(TREEVIEW_INFO *infoPtr, DWORD dwDrawStage,
556 HWND hwnd = infoPtr->hwnd;
557 NMTVCUSTOMDRAW nmcdhdr;
560 TRACE("drawstage:%lx hdc:%p\n", dwDrawStage, hdc);
562 nmcd = &nmcdhdr.nmcd;
563 nmcd->hdr.hwndFrom = hwnd;
564 nmcd->hdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
565 nmcd->hdr.code = NM_CUSTOMDRAW;
566 nmcd->dwDrawStage = dwDrawStage;
569 nmcd->dwItemSpec = 0;
570 nmcd->uItemState = 0;
571 nmcd->lItemlParam = 0;
572 nmcdhdr.clrText = infoPtr->clrText;
573 nmcdhdr.clrTextBk = infoPtr->clrBk;
576 return (BOOL)TREEVIEW_SendRealNotify(infoPtr,
577 (WPARAM)GetWindowLongA(hwnd, GWL_ID),
583 /* FIXME: need to find out when the flags in uItemState need to be set */
586 TREEVIEW_SendCustomDrawItemNotify(TREEVIEW_INFO *infoPtr, HDC hdc,
587 TREEVIEW_ITEM *wineItem, UINT uItemDrawState)
589 HWND hwnd = infoPtr->hwnd;
590 NMTVCUSTOMDRAW nmcdhdr;
592 DWORD dwDrawStage, dwItemSpec;
596 dwDrawStage = CDDS_ITEM | uItemDrawState;
597 dwItemSpec = (DWORD)wineItem;
599 if (wineItem->state & TVIS_SELECTED)
600 uItemState |= CDIS_SELECTED;
601 if (wineItem == infoPtr->selectedItem)
602 uItemState |= CDIS_FOCUS;
603 if (wineItem == infoPtr->hotItem)
604 uItemState |= CDIS_HOT;
606 nmcd = &nmcdhdr.nmcd;
607 nmcd->hdr.hwndFrom = hwnd;
608 nmcd->hdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
609 nmcd->hdr.code = NM_CUSTOMDRAW;
610 nmcd->dwDrawStage = dwDrawStage;
612 nmcd->rc = wineItem->rect;
613 nmcd->dwItemSpec = dwItemSpec;
614 nmcd->uItemState = uItemState;
615 nmcd->lItemlParam = wineItem->lParam;
616 nmcdhdr.clrText = infoPtr->clrText;
617 nmcdhdr.clrTextBk = infoPtr->clrBk;
618 nmcdhdr.iLevel = wineItem->iLevel;
620 TRACE("drawstage:%lx hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
621 nmcd->dwDrawStage, nmcd->hdc, nmcd->dwItemSpec,
622 nmcd->uItemState, nmcd->lItemlParam);
624 retval = TREEVIEW_SendRealNotify(infoPtr,
625 (WPARAM)GetWindowLongA(hwnd, GWL_ID),
628 infoPtr->clrText = nmcdhdr.clrText;
629 infoPtr->clrBk = nmcdhdr.clrTextBk;
634 TREEVIEW_BeginLabelEditNotify(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *editItem)
636 HWND hwnd = infoPtr->hwnd;
637 LPSTR allocated = NULL;
641 tvdi.hdr.hwndFrom = hwnd;
642 tvdi.hdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
643 tvdi.hdr.code = get_notifycode(infoPtr, TVN_BEGINLABELEDITW);
645 tvdi.item.mask = TVIF_HANDLE | TVIF_STATE | TVIF_PARAM | TVIF_TEXT;
646 tvdi.item.hItem = editItem;
647 tvdi.item.state = editItem->state;
648 tvdi.item.lParam = editItem->lParam;
649 if (infoPtr->bNtfUnicode) {
650 INT len = MultiByteToWideChar( CP_ACP, 0, editItem->pszText, -1, NULL, 0 );
652 tvdi.item.pszText = allocated = (LPSTR)COMCTL32_Alloc (len*sizeof(WCHAR));
653 MultiByteToWideChar( CP_ACP, 0, editItem->pszText, -1, (LPWSTR)tvdi.item.pszText, len*sizeof(WCHAR) );
654 tvdi.item.cchTextMax = len*sizeof(WCHAR);
657 tvdi.item.pszText = editItem->pszText; /* ??? */
658 tvdi.item.cchTextMax = editItem->cchTextMax; /* ??? */
662 tvdi.item.pszText = editItem->pszText;
663 tvdi.item.cchTextMax = editItem->cchTextMax;
666 ret = (BOOL)TREEVIEW_SendRealNotify(infoPtr,
670 COMCTL32_Free(allocated);
675 TREEVIEW_UpdateDispInfo(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
678 NMTVDISPINFOA callback;
679 HWND hwnd = infoPtr->hwnd;
681 mask &= wineItem->callbackMask;
683 if (mask == 0) return;
685 callback.hdr.hwndFrom = hwnd;
686 callback.hdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
687 callback.hdr.code = get_notifycode(infoPtr, TVN_GETDISPINFOW);
689 /* 'state' always contains valid value, as well as 'lParam'.
690 * All other parameters are uninitialized.
692 callback.item.pszText = wineItem->pszText;
693 callback.item.cchTextMax = wineItem->cchTextMax;
694 callback.item.mask = mask;
695 callback.item.hItem = wineItem;
696 callback.item.state = wineItem->state;
697 callback.item.lParam = wineItem->lParam;
699 /* If text is changed we need to recalculate textWidth */
700 if (mask & TVIF_TEXT)
701 wineItem->textWidth = 0;
703 TREEVIEW_SendRealNotify(infoPtr,
704 (WPARAM)callback.hdr.idFrom, (LPARAM)&callback);
706 /* It may have changed due to a call to SetItem. */
707 mask &= wineItem->callbackMask;
709 if ((mask & TVIF_TEXT) && callback.item.pszText != wineItem->pszText)
711 /* Instead of copying text into our buffer user specified its own */
712 if (infoPtr->bNtfUnicode) {
715 int len = WideCharToMultiByte( CP_ACP, 0,
716 (LPWSTR)callback.item.pszText, -1,
717 NULL, 0, NULL, NULL );
718 buflen = max((len+1)*sizeof(WCHAR), TEXT_CALLBACK_SIZE);
719 newText = (LPWSTR)COMCTL32_ReAlloc(wineItem->pszText, buflen);
721 TRACE("returned wstr %s, len=%d, buflen=%d\n",
722 debugstr_w((LPWSTR)callback.item.pszText), len, buflen);
726 wineItem->pszText = (LPSTR)newText;
727 WideCharToMultiByte( CP_ACP, 0,
728 (LPWSTR)callback.item.pszText, -1,
729 wineItem->pszText, buflen,
731 wineItem->cchTextMax = buflen;
733 /* If ReAlloc fails we have nothing to do, but keep original text */
736 int len = max(lstrlenA(callback.item.pszText) + 1,
738 LPSTR newText = COMCTL32_ReAlloc(wineItem->pszText, len);
740 TRACE("returned str %s, len=%d\n",
741 debugstr_a(callback.item.pszText), len);
745 wineItem->pszText = newText;
746 strcpy(wineItem->pszText, callback.item.pszText);
747 wineItem->cchTextMax = len;
749 /* If ReAlloc fails we have nothing to do, but keep original text */
752 else if (mask & TVIF_TEXT) {
753 /* User put text into our buffer, that is ok unless W string */
754 if (infoPtr->bNtfUnicode) {
756 LPSTR oldText = NULL;
758 int len = WideCharToMultiByte( CP_ACP, 0,
759 (LPWSTR)callback.item.pszText, -1,
760 NULL, 0, NULL, NULL );
761 buflen = max((len+1)*sizeof(WCHAR), TEXT_CALLBACK_SIZE);
762 newText = (LPWSTR)COMCTL32_Alloc(buflen);
764 TRACE("same buffer wstr %s, len=%d, buflen=%d\n",
765 debugstr_w((LPWSTR)callback.item.pszText), len, buflen);
769 oldText = wineItem->pszText;
770 wineItem->pszText = (LPSTR)newText;
771 WideCharToMultiByte( CP_ACP, 0,
772 (LPWSTR)callback.item.pszText, -1,
773 wineItem->pszText, buflen, NULL, NULL );
774 wineItem->cchTextMax = buflen;
776 COMCTL32_Free(oldText);
781 if (mask & TVIF_IMAGE)
782 wineItem->iImage = callback.item.iImage;
784 if (mask & TVIF_SELECTEDIMAGE)
785 wineItem->iSelectedImage = callback.item.iSelectedImage;
787 if (mask & TVIF_CHILDREN)
788 wineItem->cChildren = callback.item.cChildren;
790 /* These members are now permanently set. */
791 if (callback.item.mask & TVIF_DI_SETITEM)
792 wineItem->callbackMask &= ~callback.item.mask;
795 /***************************************************************************
796 * This function uses cChildren field to decide whether the item has
798 * Note: if this returns TRUE, the child items may not actually exist,
799 * they could be virtual.
801 * Just use wineItem->firstChild to check for physical children.
804 TREEVIEW_HasChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
806 TREEVIEW_UpdateDispInfo(infoPtr, wineItem, TVIF_CHILDREN);
808 return wineItem->cChildren > 0;
812 /* Item Position ********************************************************/
814 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
816 TREEVIEW_ComputeItemInternalMetrics(TREEVIEW_INFO *infoPtr,
819 /* Same effect, different optimisation. */
821 BOOL lar = ((infoPtr->dwStyle & TVS_LINESATROOT)
822 && (infoPtr->dwStyle & (TVS_HASLINES|TVS_HASBUTTONS)));
824 BOOL lar = ((infoPtr->dwStyle
825 & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS))
829 item->linesOffset = infoPtr->uIndent * (item->iLevel + lar - 1)
831 item->stateOffset = item->linesOffset + infoPtr->uIndent;
832 item->imageOffset = item->stateOffset
833 + (STATEIMAGEINDEX(item->state) ? infoPtr->stateImageWidth : 0);
834 item->textOffset = item->imageOffset + infoPtr->normalImageWidth;
838 TREEVIEW_ComputeTextWidth(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item, HDC hDC)
844 /* DRAW's OM docker creates items like this */
845 if (item->pszText == NULL)
851 if (item->textWidth != 0 && !(item->callbackMask & TVIF_TEXT))
860 hdc = GetDC(infoPtr->hwnd);
861 hOldFont = SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, item));
864 GetTextExtentPoint32A(hdc, item->pszText, strlen(item->pszText), &sz);
865 item->textWidth = sz.cx;
869 SelectObject(hdc, hOldFont);
875 TREEVIEW_ComputeItemRect(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
877 item->rect.top = infoPtr->uItemHeight *
878 (item->visibleOrder - infoPtr->firstVisible->visibleOrder);
880 item->rect.bottom = item->rect.top
881 + infoPtr->uItemHeight * item->iIntegral - 1;
884 item->rect.right = infoPtr->clientWidth;
887 /* We know that only items after start need their order updated. */
889 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *start)
896 start = infoPtr->root->firstChild;
900 order = start->visibleOrder;
902 for (item = start; item != NULL;
903 item = TREEVIEW_GetNextListItem(infoPtr, item))
905 item->visibleOrder = order;
906 order += item->iIntegral;
909 infoPtr->maxVisibleOrder = order;
911 for (item = start; item != NULL;
912 item = TREEVIEW_GetNextListItem(infoPtr, item))
914 TREEVIEW_ComputeItemRect(infoPtr, item);
919 /* Update metrics of all items in selected subtree.
920 * root must be expanded
923 TREEVIEW_UpdateSubTree(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *root)
925 TREEVIEW_ITEM *sibling;
929 if (!root->firstChild || !(root->state & TVIS_EXPANDED))
932 root->state &= ~TVIS_EXPANDED;
933 sibling = TREEVIEW_GetNextListItem(infoPtr, root);
934 root->state |= TVIS_EXPANDED;
936 hdc = GetDC(infoPtr->hwnd);
937 hOldFont = SelectObject(hdc, infoPtr->hFont);
939 for (; root != sibling;
940 root = TREEVIEW_GetNextListItem(infoPtr, root))
942 TREEVIEW_ComputeItemInternalMetrics(infoPtr, root);
944 if (root->callbackMask & TVIF_TEXT)
945 TREEVIEW_UpdateDispInfo(infoPtr, root, TVIF_TEXT);
947 if (root->textWidth == 0)
949 SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, root));
950 TREEVIEW_ComputeTextWidth(infoPtr, root, hdc);
954 SelectObject(hdc, hOldFont);
955 ReleaseDC(infoPtr->hwnd, hdc);
958 /* Item Allocation **********************************************************/
960 static TREEVIEW_ITEM *
961 TREEVIEW_AllocateItem(TREEVIEW_INFO *infoPtr)
963 TREEVIEW_ITEM *newItem = COMCTL32_Alloc(sizeof(TREEVIEW_ITEM));
968 if (DPA_InsertPtr(infoPtr->items, INT_MAX, newItem) == -1)
970 COMCTL32_Free(newItem);
977 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
978 * free item->pszText. */
980 TREEVIEW_FreeItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
982 DPA_DeletePtr(infoPtr->items, DPA_GetPtrIndex(infoPtr->items, item));
984 if (infoPtr->selectedItem == item)
985 infoPtr->selectedItem = NULL;
989 /* Item Insertion *******************************************************/
991 /***************************************************************************
992 * This method inserts newItem before sibling as a child of parent.
993 * sibling can be NULL, but only if parent has no children.
996 TREEVIEW_InsertBefore(TREEVIEW_ITEM *newItem, TREEVIEW_ITEM *sibling,
997 TREEVIEW_ITEM *parent)
999 assert(newItem != NULL);
1000 assert(parent != NULL);
1002 if (sibling != NULL)
1004 assert(sibling->parent == parent);
1006 if (sibling->prevSibling != NULL)
1007 sibling->prevSibling->nextSibling = newItem;
1009 newItem->prevSibling = sibling->prevSibling;
1010 sibling->prevSibling = newItem;
1013 newItem->prevSibling = NULL;
1015 newItem->nextSibling = sibling;
1017 if (parent->firstChild == sibling)
1018 parent->firstChild = newItem;
1020 if (parent->lastChild == NULL)
1021 parent->lastChild = newItem;
1024 /***************************************************************************
1025 * This method inserts newItem after sibling as a child of parent.
1026 * sibling can be NULL, but only if parent has no children.
1029 TREEVIEW_InsertAfter(TREEVIEW_ITEM *newItem, TREEVIEW_ITEM *sibling,
1030 TREEVIEW_ITEM *parent)
1032 assert(newItem != NULL);
1033 assert(parent != NULL);
1035 if (sibling != NULL)
1037 assert(sibling->parent == parent);
1039 if (sibling->nextSibling != NULL)
1040 sibling->nextSibling->prevSibling = newItem;
1042 newItem->nextSibling = sibling->nextSibling;
1043 sibling->nextSibling = newItem;
1046 newItem->nextSibling = NULL;
1048 newItem->prevSibling = sibling;
1050 if (parent->lastChild == sibling)
1051 parent->lastChild = newItem;
1053 if (parent->firstChild == NULL)
1054 parent->firstChild = newItem;
1058 TREEVIEW_DoSetItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
1059 const TVITEMEXA *tvItem)
1061 UINT callbackClear = 0;
1062 UINT callbackSet = 0;
1064 /* Do this first in case it fails. */
1065 if (tvItem->mask & TVIF_TEXT)
1067 wineItem->textWidth = 0; /* force width recalculation */
1068 if (tvItem->pszText != LPSTR_TEXTCALLBACKA)
1070 int len = lstrlenA(tvItem->pszText) + 1;
1071 LPSTR newText = COMCTL32_ReAlloc(wineItem->pszText, len);
1073 if (newText == NULL) return FALSE;
1075 callbackClear |= TVIF_TEXT;
1077 wineItem->pszText = newText;
1078 wineItem->cchTextMax = len;
1079 lstrcpynA(wineItem->pszText, tvItem->pszText, len);
1080 TRACE("setting text %s, item %p\n",
1081 debugstr_a(wineItem->pszText), wineItem);
1085 callbackSet |= TVIF_TEXT;
1087 wineItem->pszText = COMCTL32_ReAlloc(wineItem->pszText,
1088 TEXT_CALLBACK_SIZE);
1089 wineItem->cchTextMax = TEXT_CALLBACK_SIZE;
1090 TRACE("setting callback, item %p\n",
1095 if (tvItem->mask & TVIF_CHILDREN)
1097 wineItem->cChildren = tvItem->cChildren;
1099 if (wineItem->cChildren == I_CHILDRENCALLBACK)
1100 callbackSet |= TVIF_CHILDREN;
1102 callbackClear |= TVIF_CHILDREN;
1105 if (tvItem->mask & TVIF_IMAGE)
1107 wineItem->iImage = tvItem->iImage;
1109 if (wineItem->iImage == I_IMAGECALLBACK)
1110 callbackSet |= TVIF_IMAGE;
1112 callbackClear |= TVIF_IMAGE;
1115 if (tvItem->mask & TVIF_SELECTEDIMAGE)
1117 wineItem->iSelectedImage = tvItem->iSelectedImage;
1119 if (wineItem->iSelectedImage == I_IMAGECALLBACK)
1120 callbackSet |= TVIF_SELECTEDIMAGE;
1122 callbackClear |= TVIF_SELECTEDIMAGE;
1125 if (tvItem->mask & TVIF_PARAM)
1126 wineItem->lParam = tvItem->lParam;
1128 /* If the application sets TVIF_INTEGRAL without
1129 * supplying a TVITEMEX structure, it's toast. */
1130 if (tvItem->mask & TVIF_INTEGRAL)
1131 wineItem->iIntegral = tvItem->iIntegral;
1133 if (tvItem->mask & TVIF_STATE)
1135 TRACE("prevstate,state,mask:%x,%x,%x\n", wineItem->state, tvItem->state,
1137 wineItem->state &= ~tvItem->stateMask;
1138 wineItem->state |= (tvItem->state & tvItem->stateMask);
1141 wineItem->callbackMask |= callbackSet;
1142 wineItem->callbackMask &= ~callbackClear;
1147 /* Note that the new item is pre-zeroed. */
1149 TREEVIEW_InsertItemA(TREEVIEW_INFO *infoPtr, LPARAM lParam)
1151 const TVINSERTSTRUCTA *ptdi = (LPTVINSERTSTRUCTA) lParam;
1152 const TVITEMEXA *tvItem = &ptdi->DUMMYUNIONNAME.itemex;
1153 HTREEITEM insertAfter;
1154 TREEVIEW_ITEM *newItem, *parentItem;
1155 BOOL bTextUpdated = FALSE;
1157 if (ptdi->hParent == TVI_ROOT || ptdi->hParent == 0)
1159 parentItem = infoPtr->root;
1163 parentItem = ptdi->hParent;
1165 if (!TREEVIEW_ValidItem(infoPtr, parentItem))
1167 WARN("invalid parent %p\n", parentItem);
1168 return (LRESULT)(HTREEITEM)NULL;
1172 insertAfter = ptdi->hInsertAfter;
1174 /* Validate this now for convenience. */
1175 switch ((DWORD)insertAfter)
1177 case (DWORD)TVI_FIRST:
1178 case (DWORD)TVI_LAST:
1179 case (DWORD)TVI_SORT:
1183 if (!TREEVIEW_ValidItem(infoPtr, insertAfter) ||
1184 insertAfter->parent != parentItem)
1186 WARN("invalid insert after %p\n", insertAfter);
1187 insertAfter = TVI_LAST;
1191 TRACE("parent %p position %p: '%s'\n", parentItem, insertAfter,
1192 (tvItem->mask & TVIF_TEXT)
1193 ? ((tvItem->pszText == LPSTR_TEXTCALLBACKA) ? "<callback>"
1197 newItem = TREEVIEW_AllocateItem(infoPtr);
1198 if (newItem == NULL)
1199 return (LRESULT)(HTREEITEM)NULL;
1201 newItem->parent = parentItem;
1202 newItem->iIntegral = 1;
1204 if (!TREEVIEW_DoSetItem(infoPtr, newItem, tvItem))
1205 return (LRESULT)(HTREEITEM)NULL;
1207 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1209 infoPtr->uNumItems++;
1211 switch ((DWORD)insertAfter)
1213 case (DWORD)TVI_FIRST:
1214 TREEVIEW_InsertBefore(newItem, parentItem->firstChild, parentItem);
1215 if (infoPtr->firstVisible == parentItem->firstChild)
1216 TREEVIEW_SetFirstVisible(infoPtr, newItem, TRUE);
1219 case (DWORD)TVI_LAST:
1220 TREEVIEW_InsertAfter(newItem, parentItem->lastChild, parentItem);
1223 /* hInsertAfter names a specific item we want to insert after */
1225 TREEVIEW_InsertAfter(newItem, insertAfter, insertAfter->parent);
1228 case (DWORD)TVI_SORT:
1230 TREEVIEW_ITEM *aChild;
1231 TREEVIEW_ITEM *previousChild = NULL;
1232 BOOL bItemInserted = FALSE;
1234 aChild = parentItem->firstChild;
1236 bTextUpdated = TRUE;
1237 TREEVIEW_UpdateDispInfo(infoPtr, newItem, TVIF_TEXT);
1239 /* Iterate the parent children to see where we fit in */
1240 while (aChild != NULL)
1244 TREEVIEW_UpdateDispInfo(infoPtr, aChild, TVIF_TEXT);
1245 comp = lstrcmpA(newItem->pszText, aChild->pszText);
1247 if (comp < 0) /* we are smaller than the current one */
1249 TREEVIEW_InsertBefore(newItem, aChild, parentItem);
1250 bItemInserted = TRUE;
1253 else if (comp > 0) /* we are bigger than the current one */
1255 previousChild = aChild;
1257 /* This will help us to exit if there is no more sibling */
1258 aChild = (aChild->nextSibling == 0)
1260 : aChild->nextSibling;
1262 /* Look at the next item */
1268 * An item with this name is already existing, therefore,
1269 * we add after the one we found
1271 TREEVIEW_InsertAfter(newItem, aChild, parentItem);
1272 bItemInserted = TRUE;
1278 * we reach the end of the child list and the item has not
1279 * yet been inserted, therefore, insert it after the last child.
1281 if ((!bItemInserted) && (aChild == NULL))
1282 TREEVIEW_InsertAfter(newItem, previousChild, parentItem);
1289 TRACE("new item %p; parent %p, mask %x\n", newItem,
1290 newItem->parent, tvItem->mask);
1292 newItem->iLevel = newItem->parent->iLevel + 1;
1294 if (newItem->parent->cChildren == 0)
1295 newItem->parent->cChildren = 1;
1297 if (infoPtr->dwStyle & TVS_CHECKBOXES)
1299 if (STATEIMAGEINDEX(newItem->state) == 0)
1300 newItem->state |= INDEXTOSTATEIMAGEMASK(1);
1303 if (infoPtr->firstVisible == NULL)
1304 infoPtr->firstVisible = newItem;
1306 TREEVIEW_VerifyTree(infoPtr);
1308 if (parentItem == infoPtr->root ||
1309 (ISVISIBLE(parentItem) && parentItem->state & TVIS_EXPANDED))
1311 TREEVIEW_ITEM *item;
1312 TREEVIEW_ITEM *prev = TREEVIEW_GetPrevListItem(infoPtr, newItem);
1314 TREEVIEW_RecalculateVisibleOrder(infoPtr, prev);
1315 TREEVIEW_ComputeItemInternalMetrics(infoPtr, newItem);
1318 TREEVIEW_UpdateDispInfo(infoPtr, newItem, TVIF_TEXT);
1320 TREEVIEW_ComputeTextWidth(infoPtr, newItem, 0);
1321 TREEVIEW_UpdateScrollBars(infoPtr);
1323 * if the item was inserted in a visible part of the tree,
1324 * invalidate it, as well as those after it
1326 for (item = newItem;
1328 item = TREEVIEW_GetNextListItem(infoPtr, item))
1329 TREEVIEW_Invalidate(infoPtr, item);
1333 newItem->visibleOrder = -1;
1335 /* refresh treeview if newItem is the first item inserted under parentItem */
1336 if (ISVISIBLE(parentItem) && newItem->prevSibling == newItem->nextSibling)
1338 /* parent got '+' - update it */
1339 TREEVIEW_Invalidate(infoPtr, parentItem);
1343 return (LRESULT)newItem;
1348 TREEVIEW_InsertItemW(TREEVIEW_INFO *infoPtr, LPARAM lParam)
1350 TVINSERTSTRUCTW *tvisW;
1351 TVINSERTSTRUCTA tvisA;
1354 tvisW = (LPTVINSERTSTRUCTW) lParam;
1356 tvisA.hParent = tvisW->hParent;
1357 tvisA.hInsertAfter = tvisW->hInsertAfter;
1359 tvisA.DUMMYUNIONNAME.item.mask = tvisW->DUMMYUNIONNAME.item.mask;
1360 tvisA.DUMMYUNIONNAME.item.hItem = tvisW->DUMMYUNIONNAME.item.hItem;
1361 tvisA.DUMMYUNIONNAME.item.state = tvisW->DUMMYUNIONNAME.item.state;
1362 tvisA.DUMMYUNIONNAME.item.stateMask = tvisW->DUMMYUNIONNAME.item.stateMask;
1363 tvisA.DUMMYUNIONNAME.item.cchTextMax =
1364 tvisW->DUMMYUNIONNAME.item.cchTextMax;
1366 if (tvisW->DUMMYUNIONNAME.item.pszText)
1368 if (tvisW->DUMMYUNIONNAME.item.pszText != LPSTR_TEXTCALLBACKW)
1370 int len = WideCharToMultiByte( CP_ACP, 0, tvisW->DUMMYUNIONNAME.item.pszText, -1,
1371 NULL, 0, NULL, NULL );
1372 tvisA.DUMMYUNIONNAME.item.pszText = COMCTL32_Alloc(len);
1373 WideCharToMultiByte( CP_ACP, 0, tvisW->DUMMYUNIONNAME.item.pszText, -1,
1374 tvisA.DUMMYUNIONNAME.item.pszText, len, NULL, NULL );
1378 tvisA.DUMMYUNIONNAME.item.pszText = LPSTR_TEXTCALLBACKA;
1379 tvisA.DUMMYUNIONNAME.item.cchTextMax = 0;
1383 tvisA.DUMMYUNIONNAME.item.iImage = tvisW->DUMMYUNIONNAME.item.iImage;
1384 tvisA.DUMMYUNIONNAME.item.iSelectedImage =
1385 tvisW->DUMMYUNIONNAME.item.iSelectedImage;
1386 tvisA.DUMMYUNIONNAME.item.cChildren = tvisW->DUMMYUNIONNAME.item.cChildren;
1387 tvisA.DUMMYUNIONNAME.item.lParam = tvisW->DUMMYUNIONNAME.item.lParam;
1389 lRes = TREEVIEW_InsertItemA(infoPtr, (LPARAM)&tvisA);
1391 if (tvisA.DUMMYUNIONNAME.item.pszText != LPSTR_TEXTCALLBACKA)
1393 COMCTL32_Free(tvisA.DUMMYUNIONNAME.item.pszText);
1401 /* Item Deletion ************************************************************/
1403 TREEVIEW_RemoveItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem);
1406 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *parentItem)
1408 TREEVIEW_ITEM *kill = parentItem->firstChild;
1410 while (kill != NULL)
1412 TREEVIEW_ITEM *next = kill->nextSibling;
1414 TREEVIEW_RemoveItem(infoPtr, kill);
1419 assert(parentItem->cChildren <= 0); /* I_CHILDRENCALLBACK or 0 */
1420 assert(parentItem->firstChild == NULL);
1421 assert(parentItem->lastChild == NULL);
1425 TREEVIEW_UnlinkItem(TREEVIEW_ITEM *item)
1427 TREEVIEW_ITEM *parentItem = item->parent;
1429 assert(item != NULL);
1430 assert(item->parent != NULL); /* i.e. it must not be the root */
1432 if (parentItem->firstChild == item)
1433 parentItem->firstChild = item->nextSibling;
1435 if (parentItem->lastChild == item)
1436 parentItem->lastChild = item->prevSibling;
1438 if (parentItem->firstChild == NULL && parentItem->lastChild == NULL
1439 && parentItem->cChildren > 0)
1440 parentItem->cChildren = 0;
1442 if (item->prevSibling)
1443 item->prevSibling->nextSibling = item->nextSibling;
1445 if (item->nextSibling)
1446 item->nextSibling->prevSibling = item->prevSibling;
1450 TREEVIEW_RemoveItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
1452 TRACE("%p, (%s)\n", wineItem, TREEVIEW_ItemName(wineItem));
1454 TREEVIEW_SendTreeviewNotify(infoPtr, TVN_DELETEITEMW, TVC_UNKNOWN,
1455 TVIF_HANDLE | TVIF_PARAM, wineItem, 0);
1457 if (wineItem->firstChild)
1458 TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
1460 TREEVIEW_UnlinkItem(wineItem);
1462 infoPtr->uNumItems--;
1464 if (wineItem->pszText != LPSTR_TEXTCALLBACKA)
1465 COMCTL32_Free(wineItem->pszText);
1467 TREEVIEW_FreeItem(infoPtr, wineItem);
1471 /* Empty out the tree. */
1473 TREEVIEW_RemoveTree(TREEVIEW_INFO *infoPtr)
1475 TREEVIEW_RemoveAllChildren(infoPtr, infoPtr->root);
1477 assert(infoPtr->uNumItems == 0); /* root isn't counted in uNumItems */
1481 TREEVIEW_DeleteItem(TREEVIEW_INFO *infoPtr, HTREEITEM wineItem)
1483 TREEVIEW_ITEM *oldSelection = infoPtr->selectedItem;
1484 TREEVIEW_ITEM *newSelection = oldSelection;
1485 TREEVIEW_ITEM *newFirstVisible = NULL;
1486 TREEVIEW_ITEM *parent, *prev = NULL;
1487 BOOL visible = FALSE;
1489 if (wineItem == TVI_ROOT)
1491 TRACE("TVI_ROOT\n");
1492 parent = infoPtr->root;
1493 newSelection = NULL;
1495 TREEVIEW_RemoveTree(infoPtr);
1499 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
1502 TRACE("%p (%s)\n", wineItem, TREEVIEW_ItemName(wineItem));
1503 parent = wineItem->parent;
1505 if (ISVISIBLE(wineItem))
1507 prev = TREEVIEW_GetPrevListItem(infoPtr, wineItem);
1511 if (infoPtr->selectedItem != NULL
1512 && (wineItem == infoPtr->selectedItem
1513 || TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem)))
1515 if (wineItem->nextSibling)
1516 newSelection = wineItem->nextSibling;
1517 else if (wineItem->parent != infoPtr->root)
1518 newSelection = wineItem->parent;
1521 if (infoPtr->firstVisible == wineItem)
1523 if (wineItem->nextSibling)
1524 newFirstVisible = wineItem->nextSibling;
1525 else if (wineItem->prevSibling)
1526 newFirstVisible = wineItem->prevSibling;
1527 else if (wineItem->parent != infoPtr->root)
1528 newFirstVisible = wineItem->parent;
1531 newFirstVisible = infoPtr->firstVisible;
1533 TREEVIEW_RemoveItem(infoPtr, wineItem);
1536 /* Don't change if somebody else already has. */
1537 if (oldSelection == infoPtr->selectedItem)
1539 if (TREEVIEW_ValidItem(infoPtr, newSelection))
1540 TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, newSelection, TVC_UNKNOWN);
1542 infoPtr->selectedItem = 0;
1545 /* Validate insertMark dropItem.
1546 * hotItem ??? - used for comparison only.
1548 if (!TREEVIEW_ValidItem(infoPtr, infoPtr->insertMarkItem))
1549 infoPtr->insertMarkItem = 0;
1551 if (!TREEVIEW_ValidItem(infoPtr, infoPtr->dropItem))
1552 infoPtr->dropItem = 0;
1554 if (!TREEVIEW_ValidItem(infoPtr, newFirstVisible))
1555 newFirstVisible = infoPtr->root->firstChild;
1557 TREEVIEW_VerifyTree(infoPtr);
1562 TREEVIEW_RecalculateVisibleOrder(infoPtr, prev);
1563 TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
1564 TREEVIEW_UpdateScrollBars(infoPtr);
1565 TREEVIEW_Invalidate(infoPtr, NULL);
1567 else if (ISVISIBLE(parent) && !TREEVIEW_HasChildren(infoPtr, parent))
1569 /* parent lost '+/-' - update it */
1570 TREEVIEW_Invalidate(infoPtr, parent);
1577 /* Get/Set Messages *********************************************************/
1579 TREEVIEW_SetRedraw(TREEVIEW_INFO* infoPtr, WPARAM wParam, LPARAM lParam)
1582 infoPtr->bRedraw = TRUE;
1584 infoPtr->bRedraw = FALSE;
1590 TREEVIEW_GetIndent(TREEVIEW_INFO *infoPtr)
1593 return infoPtr->uIndent;
1597 TREEVIEW_SetIndent(TREEVIEW_INFO *infoPtr, UINT newIndent)
1601 if (newIndent < MINIMUM_INDENT)
1602 newIndent = MINIMUM_INDENT;
1604 if (infoPtr->uIndent != newIndent)
1606 infoPtr->uIndent = newIndent;
1607 TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
1608 TREEVIEW_UpdateScrollBars(infoPtr);
1609 TREEVIEW_Invalidate(infoPtr, NULL);
1617 TREEVIEW_GetToolTips(TREEVIEW_INFO *infoPtr)
1620 return (LRESULT)infoPtr->hwndToolTip;
1624 TREEVIEW_SetToolTips(TREEVIEW_INFO *infoPtr, HWND hwndTT)
1629 prevToolTip = infoPtr->hwndToolTip;
1630 infoPtr->hwndToolTip = hwndTT;
1632 return (LRESULT)prevToolTip;
1637 TREEVIEW_GetScrollTime(TREEVIEW_INFO *infoPtr)
1639 return infoPtr->uScrollTime;
1643 TREEVIEW_SetScrollTime(TREEVIEW_INFO *infoPtr, UINT uScrollTime)
1645 UINT uOldScrollTime = infoPtr->uScrollTime;
1647 infoPtr->uScrollTime = min(uScrollTime, 100);
1649 return uOldScrollTime;
1654 TREEVIEW_GetImageList(TREEVIEW_INFO *infoPtr, WPARAM wParam)
1660 case (WPARAM)TVSIL_NORMAL:
1661 return (LRESULT)infoPtr->himlNormal;
1663 case (WPARAM)TVSIL_STATE:
1664 return (LRESULT)infoPtr->himlState;
1672 TREEVIEW_SetImageList(TREEVIEW_INFO *infoPtr, WPARAM wParam, HIMAGELIST himlNew)
1674 HIMAGELIST himlOld = 0;
1675 int oldWidth = infoPtr->normalImageWidth;
1676 int oldHeight = infoPtr->normalImageHeight;
1679 TRACE("%x,%p\n", wParam, himlNew);
1683 case (WPARAM)TVSIL_NORMAL:
1684 himlOld = infoPtr->himlNormal;
1685 infoPtr->himlNormal = himlNew;
1687 if (himlNew != NULL)
1688 ImageList_GetIconSize(himlNew, &infoPtr->normalImageWidth,
1689 &infoPtr->normalImageHeight);
1692 infoPtr->normalImageWidth = 0;
1693 infoPtr->normalImageHeight = 0;
1698 case (WPARAM)TVSIL_STATE:
1699 himlOld = infoPtr->himlState;
1700 infoPtr->himlState = himlNew;
1702 if (himlNew != NULL)
1703 ImageList_GetIconSize(himlNew, &infoPtr->stateImageWidth,
1704 &infoPtr->stateImageHeight);
1707 infoPtr->stateImageWidth = 0;
1708 infoPtr->stateImageHeight = 0;
1714 if (oldWidth != infoPtr->normalImageWidth ||
1715 oldHeight != infoPtr->normalImageHeight)
1717 TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
1718 TREEVIEW_UpdateScrollBars(infoPtr);
1721 TREEVIEW_Invalidate(infoPtr, NULL);
1723 return (LRESULT)himlOld;
1726 /* Compute the natural height (based on the font size) for items. */
1728 TREEVIEW_NaturalHeight(TREEVIEW_INFO *infoPtr)
1732 HFONT hOldFont = SelectObject(hdc, infoPtr->hFont);
1734 GetTextMetricsA(hdc, &tm);
1736 SelectObject(hdc, hOldFont);
1739 /* The 16 is a hack because our fonts are tiny. */
1740 /* add 2 for the focus border and 1 more for margin some apps assume */
1741 return max(16, tm.tmHeight + tm.tmExternalLeading + 3);
1745 TREEVIEW_SetItemHeight(TREEVIEW_INFO *infoPtr, INT newHeight)
1747 INT prevHeight = infoPtr->uItemHeight;
1749 TRACE("%d \n", newHeight);
1750 if (newHeight == -1)
1752 infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
1753 infoPtr->bHeightSet = FALSE;
1757 infoPtr->uItemHeight = newHeight;
1758 infoPtr->bHeightSet = TRUE;
1761 /* Round down, unless we support odd ("non even") heights. */
1762 if (!(infoPtr->dwStyle) & TVS_NONEVENHEIGHT)
1763 infoPtr->uItemHeight &= ~1;
1765 if (infoPtr->uItemHeight != prevHeight)
1767 TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
1768 TREEVIEW_UpdateScrollBars(infoPtr);
1769 TREEVIEW_Invalidate(infoPtr, NULL);
1776 TREEVIEW_GetItemHeight(TREEVIEW_INFO *infoPtr)
1779 return infoPtr->uItemHeight;
1784 TREEVIEW_GetFont(TREEVIEW_INFO *infoPtr)
1786 TRACE("%p\n", infoPtr->hFont);
1787 return (LRESULT)infoPtr->hFont;
1792 TREEVIEW_ResetTextWidth(LPVOID pItem, DWORD unused)
1796 ((TREEVIEW_ITEM *)pItem)->textWidth = 0;
1802 TREEVIEW_SetFont(TREEVIEW_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
1804 UINT uHeight = infoPtr->uItemHeight;
1806 TRACE("%p %i\n", hFont, bRedraw);
1808 infoPtr->hFont = hFont ? hFont : GetStockObject(SYSTEM_FONT);
1810 DeleteObject(infoPtr->hBoldFont);
1811 infoPtr->hBoldFont = TREEVIEW_CreateBoldFont(infoPtr->hFont);
1813 if (!infoPtr->bHeightSet)
1814 infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
1816 if (uHeight != infoPtr->uItemHeight)
1817 TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
1819 DPA_EnumCallback(infoPtr->items, TREEVIEW_ResetTextWidth, 0);
1821 TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
1822 TREEVIEW_UpdateScrollBars(infoPtr);
1825 TREEVIEW_Invalidate(infoPtr, NULL);
1832 TREEVIEW_GetLineColor(TREEVIEW_INFO *infoPtr)
1835 return (LRESULT)infoPtr->clrLine;
1839 TREEVIEW_SetLineColor(TREEVIEW_INFO *infoPtr, COLORREF color)
1841 COLORREF prevColor = infoPtr->clrLine;
1844 infoPtr->clrLine = color;
1845 return (LRESULT)prevColor;
1850 TREEVIEW_GetTextColor(TREEVIEW_INFO *infoPtr)
1853 return (LRESULT)infoPtr->clrText;
1857 TREEVIEW_SetTextColor(TREEVIEW_INFO *infoPtr, COLORREF color)
1859 COLORREF prevColor = infoPtr->clrText;
1862 infoPtr->clrText = color;
1864 if (infoPtr->clrText != prevColor)
1865 TREEVIEW_Invalidate(infoPtr, NULL);
1867 return (LRESULT)prevColor;
1872 TREEVIEW_GetBkColor(TREEVIEW_INFO *infoPtr)
1875 return (LRESULT)infoPtr->clrBk;
1879 TREEVIEW_SetBkColor(TREEVIEW_INFO *infoPtr, COLORREF newColor)
1881 COLORREF prevColor = infoPtr->clrBk;
1884 infoPtr->clrBk = newColor;
1886 if (newColor != prevColor)
1887 TREEVIEW_Invalidate(infoPtr, NULL);
1889 return (LRESULT)prevColor;
1894 TREEVIEW_GetInsertMarkColor(TREEVIEW_INFO *infoPtr)
1897 return (LRESULT)infoPtr->clrInsertMark;
1901 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO *infoPtr, COLORREF color)
1903 COLORREF prevColor = infoPtr->clrInsertMark;
1905 TRACE("%lx\n", color);
1906 infoPtr->clrInsertMark = color;
1908 return (LRESULT)prevColor;
1913 TREEVIEW_SetInsertMark(TREEVIEW_INFO *infoPtr, BOOL wParam, HTREEITEM item)
1915 TRACE("%d %p\n", wParam, item);
1917 if (!TREEVIEW_ValidItem(infoPtr, item))
1920 infoPtr->insertBeforeorAfter = wParam;
1921 infoPtr->insertMarkItem = item;
1923 TREEVIEW_Invalidate(infoPtr, NULL);
1929 /************************************************************************
1930 * Some serious braindamage here. lParam is a pointer to both the
1931 * input HTREEITEM and the output RECT.
1934 TREEVIEW_GetItemRect(TREEVIEW_INFO *infoPtr, BOOL fTextRect, LPRECT lpRect)
1936 TREEVIEW_ITEM *wineItem;
1937 const HTREEITEM *pItem = (HTREEITEM *)lpRect;
1941 * validate parameters
1947 if (!TREEVIEW_ValidItem(infoPtr, wineItem) || !ISVISIBLE(wineItem))
1951 * If wParam is TRUE return the text size otherwise return
1952 * the whole item size
1956 /* Windows does not send TVN_GETDISPINFO here. */
1958 lpRect->top = wineItem->rect.top;
1959 lpRect->bottom = wineItem->rect.bottom;
1961 lpRect->left = wineItem->textOffset;
1962 lpRect->right = wineItem->textOffset + wineItem->textWidth;
1966 *lpRect = wineItem->rect;
1969 TRACE("%s [L:%d R:%d T:%d B:%d]\n", fTextRect ? "text" : "item",
1970 lpRect->left, lpRect->right, lpRect->top, lpRect->bottom);
1975 static inline LRESULT
1976 TREEVIEW_GetVisibleCount(TREEVIEW_INFO *infoPtr)
1978 /* Suprise! This does not take integral height into account. */
1979 return infoPtr->clientHeight / infoPtr->uItemHeight;
1984 TREEVIEW_GetItemA(TREEVIEW_INFO *infoPtr, LPTVITEMEXA tvItem)
1986 TREEVIEW_ITEM *wineItem;
1988 wineItem = tvItem->hItem;
1989 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
1992 TREEVIEW_UpdateDispInfo(infoPtr, wineItem, tvItem->mask);
1994 if (tvItem->mask & TVIF_CHILDREN)
1995 tvItem->cChildren = wineItem->cChildren;
1997 if (tvItem->mask & TVIF_HANDLE)
1998 tvItem->hItem = wineItem;
2000 if (tvItem->mask & TVIF_IMAGE)
2001 tvItem->iImage = wineItem->iImage;
2003 if (tvItem->mask & TVIF_INTEGRAL)
2004 tvItem->iIntegral = wineItem->iIntegral;
2006 /* undocumented: windows ignores TVIF_PARAM and
2007 * * always sets lParam
2009 tvItem->lParam = wineItem->lParam;
2011 if (tvItem->mask & TVIF_SELECTEDIMAGE)
2012 tvItem->iSelectedImage = wineItem->iSelectedImage;
2014 if (tvItem->mask & TVIF_STATE)
2015 tvItem->state = wineItem->state & tvItem->stateMask;
2017 if (tvItem->mask & TVIF_TEXT)
2018 lstrcpynA(tvItem->pszText, wineItem->pszText, tvItem->cchTextMax);
2020 TRACE("item <%p>, txt %p, img %p, mask %x\n",
2021 wineItem, tvItem->pszText, &tvItem->iImage, tvItem->mask);
2026 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2027 * which is wrong. */
2029 TREEVIEW_SetItemA(TREEVIEW_INFO *infoPtr, LPTVITEMEXA tvItem)
2031 TREEVIEW_ITEM *wineItem;
2032 TREEVIEW_ITEM originalItem;
2034 wineItem = tvItem->hItem;
2036 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr, wineItem),
2039 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
2042 if (!TREEVIEW_DoSetItem(infoPtr, wineItem, tvItem))
2045 /* store the orignal item values */
2046 originalItem = *wineItem;
2048 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2049 if ((tvItem->mask & TVIF_TEXT
2050 || (tvItem->mask & TVIF_STATE && tvItem->stateMask & TVIS_BOLD))
2051 && ISVISIBLE(wineItem))
2053 TREEVIEW_UpdateDispInfo(infoPtr, wineItem, TVIF_TEXT);
2054 TREEVIEW_ComputeTextWidth(infoPtr, wineItem, 0);
2057 if (tvItem->mask != 0 && ISVISIBLE(wineItem))
2059 /* The refresh updates everything, but we can't wait until then. */
2060 TREEVIEW_ComputeItemInternalMetrics(infoPtr, wineItem);
2062 /* if any of the items values changed, redraw the item */
2063 if(memcmp(&originalItem, wineItem, sizeof(TREEVIEW_ITEM)))
2065 if (tvItem->mask & TVIF_INTEGRAL)
2067 TREEVIEW_RecalculateVisibleOrder(infoPtr, wineItem);
2068 TREEVIEW_UpdateScrollBars(infoPtr);
2070 TREEVIEW_Invalidate(infoPtr, NULL);
2074 TREEVIEW_UpdateScrollBars(infoPtr);
2075 TREEVIEW_Invalidate(infoPtr, wineItem);
2084 TREEVIEW_GetItemW(TREEVIEW_INFO *infoPtr, LPTVITEMEXW tvItem)
2086 TREEVIEW_ITEM *wineItem;
2088 iItem = (INT)tvItem->hItem;
2090 wineItem = tvItem->hItem;
2091 if(!TREEVIEW_ValidItem (infoPtr, wineItem))
2094 TREEVIEW_UpdateDispInfo(infoPtr, wineItem, tvItem->mask);
2096 if (tvItem->mask & TVIF_CHILDREN) {
2097 if (TVIF_CHILDREN==I_CHILDRENCALLBACK)
2098 FIXME("I_CHILDRENCALLBACK not supported\n");
2099 tvItem->cChildren = wineItem->cChildren;
2102 if (tvItem->mask & TVIF_HANDLE) {
2103 tvItem->hItem = wineItem;
2105 if (tvItem->mask & TVIF_IMAGE) {
2106 tvItem->iImage = wineItem->iImage;
2108 if (tvItem->mask & TVIF_INTEGRAL) {
2109 tvItem->iIntegral = wineItem->iIntegral;
2111 /* undocumented: windows ignores TVIF_PARAM and
2112 * always sets lParam */
2113 tvItem->lParam = wineItem->lParam;
2114 if (tvItem->mask & TVIF_SELECTEDIMAGE) {
2115 tvItem->iSelectedImage = wineItem->iSelectedImage;
2117 if (tvItem->mask & TVIF_STATE) {
2118 tvItem->state = wineItem->state & tvItem->stateMask;
2121 if (tvItem->mask & TVIF_TEXT) {
2122 if (wineItem->pszText == LPSTR_TEXTCALLBACKA) {
2123 tvItem->pszText = LPSTR_TEXTCALLBACKW;
2124 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2126 else if (wineItem->pszText) {
2127 TRACE("orig str %s at %p\n",
2128 debugstr_a(wineItem->pszText), wineItem->pszText);
2129 MultiByteToWideChar(CP_ACP, 0, wineItem->pszText,
2130 -1 , tvItem->pszText, tvItem->cchTextMax);
2134 TRACE("item %d<%p>, txt %p<%s>, img %p, action %x\n",
2135 iItem, tvItem, tvItem->pszText, debugstr_w(tvItem->pszText),
2136 &tvItem->iImage, tvItem->mask);
2141 TREEVIEW_SetItemW(TREEVIEW_INFO *infoPtr, LPTVITEMEXW tvItem)
2147 tvItemA.mask = tvItem->mask;
2148 tvItemA.hItem = tvItem->hItem;
2149 tvItemA.state = tvItem->state;
2150 tvItemA.stateMask = tvItem->stateMask;
2151 if (tvItem->mask & TVIF_TEXT) {
2152 len = WideCharToMultiByte(CP_ACP, 0, tvItem->pszText, -1,
2153 NULL ,0 , NULL,NULL);
2156 tvItemA.pszText = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
2157 len = WideCharToMultiByte(CP_ACP, 0, tvItem->pszText, -1,
2158 tvItemA.pszText ,len*sizeof(WCHAR),
2162 tvItemA.pszText = NULL;
2164 tvItemA.cchTextMax = tvItem->cchTextMax;
2165 tvItemA.iImage = tvItem->iImage;
2166 tvItemA.iSelectedImage = tvItem->iSelectedImage;
2167 tvItemA.cChildren = tvItem->cChildren;
2168 tvItemA.lParam = tvItem->lParam;
2169 tvItemA.iIntegral = tvItem->iIntegral;
2171 rc = TREEVIEW_SetItemA(infoPtr,&tvItemA);
2172 HeapFree(GetProcessHeap(),0,tvItemA.pszText);
2177 TREEVIEW_GetItemState(TREEVIEW_INFO *infoPtr, HTREEITEM wineItem, UINT mask)
2181 if (!wineItem || !TREEVIEW_ValidItem(infoPtr, wineItem))
2184 return (wineItem->state & mask);
2188 TREEVIEW_GetNextItem(TREEVIEW_INFO *infoPtr, UINT which, HTREEITEM wineItem)
2190 TREEVIEW_ITEM *retval;
2194 /* handle all the global data here */
2197 case TVGN_CHILD: /* Special case: child of 0 is root */
2202 retval = infoPtr->root->firstChild;
2206 retval = infoPtr->selectedItem;
2209 case TVGN_FIRSTVISIBLE:
2210 retval = infoPtr->firstVisible;
2213 case TVGN_DROPHILITE:
2214 retval = infoPtr->dropItem;
2217 case TVGN_LASTVISIBLE:
2218 retval = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
2224 TRACE("flags:%x, returns %p\n", which, retval);
2225 return (LRESULT)retval;
2228 if (wineItem == TVI_ROOT) wineItem = infoPtr->root;
2230 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
2236 retval = wineItem->nextSibling;
2239 retval = wineItem->prevSibling;
2242 retval = (wineItem->parent != infoPtr->root) ? wineItem->parent : NULL;
2245 retval = wineItem->firstChild;
2247 case TVGN_NEXTVISIBLE:
2248 retval = TREEVIEW_GetNextListItem(infoPtr, wineItem);
2250 case TVGN_PREVIOUSVISIBLE:
2251 retval = TREEVIEW_GetPrevListItem(infoPtr, wineItem);
2254 TRACE("Unknown msg %x,item %p\n", which, wineItem);
2258 TRACE("flags:%x, item %p;returns %p\n", which, wineItem, retval);
2259 return (LRESULT)retval;
2264 TREEVIEW_GetCount(TREEVIEW_INFO *infoPtr)
2266 TRACE(" %d\n", infoPtr->uNumItems);
2267 return (LRESULT)infoPtr->uNumItems;
2271 TREEVIEW_ToggleItemState(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
2273 if (infoPtr->dwStyle & TVS_CHECKBOXES)
2275 static const unsigned int state_table[] = { 0, 2, 1 };
2279 state = STATEIMAGEINDEX(item->state);
2280 TRACE("state:%x\n", state);
2281 item->state &= ~TVIS_STATEIMAGEMASK;
2284 state = state_table[state];
2286 item->state |= INDEXTOSTATEIMAGEMASK(state);
2288 TRACE("state:%x\n", state);
2289 TREEVIEW_Invalidate(infoPtr, item);
2294 /* Painting *************************************************************/
2296 /* Draw the lines and expand button for an item. Also draws one section
2297 * of the line from item's parent to item's parent's next sibling. */
2299 TREEVIEW_DrawItemLines(TREEVIEW_INFO *infoPtr, HDC hdc, TREEVIEW_ITEM *item)
2301 LONG centerx, centery;
2302 BOOL lar = ((infoPtr->dwStyle
2303 & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS))
2306 if (!lar && item->iLevel == 0)
2309 centerx = (item->linesOffset + item->stateOffset) / 2;
2310 centery = (item->rect.top + item->rect.bottom) / 2;
2312 if (infoPtr->dwStyle & TVS_HASLINES)
2314 HPEN hOldPen, hNewPen;
2318 * Get a dotted grey pen
2320 hNewPen = CreatePen(PS_ALTERNATE, 0, infoPtr->clrLine);
2321 hOldPen = SelectObject(hdc, hNewPen);
2323 MoveToEx(hdc, item->stateOffset, centery, NULL);
2324 LineTo(hdc, centerx - 1, centery);
2326 if (item->prevSibling || item->parent != infoPtr->root)
2328 MoveToEx(hdc, centerx, item->rect.top, NULL);
2329 LineTo(hdc, centerx, centery);
2332 if (item->nextSibling)
2334 MoveToEx(hdc, centerx, centery, NULL);
2335 LineTo(hdc, centerx, item->rect.bottom + 1);
2338 /* Draw the line from our parent to its next sibling. */
2339 parent = item->parent;
2340 while (parent != infoPtr->root)
2342 int pcenterx = (parent->linesOffset + parent->stateOffset) / 2;
2344 if (parent->nextSibling
2345 /* skip top-levels unless TVS_LINESATROOT */
2346 && parent->stateOffset > parent->linesOffset)
2348 MoveToEx(hdc, pcenterx, item->rect.top, NULL);
2349 LineTo(hdc, pcenterx, item->rect.bottom + 1);
2352 parent = parent->parent;
2355 SelectObject(hdc, hOldPen);
2356 DeleteObject(hNewPen);
2360 * Display the (+/-) signs
2363 if (infoPtr->dwStyle & TVS_HASBUTTONS)
2365 if (item->cChildren)
2367 LONG height = item->rect.bottom - item->rect.top;
2368 LONG width = item->stateOffset - item->linesOffset;
2369 LONG rectsize = min(height, width) / 4;
2370 /* plussize = ceil(rectsize * 3/4) */
2371 LONG plussize = (rectsize + 1) * 3 / 4;
2373 HPEN hNewPen = CreatePen(PS_SOLID, 0, infoPtr->clrLine);
2374 HPEN hOldPen = SelectObject(hdc, hNewPen);
2375 HBRUSH hbr = CreateSolidBrush(infoPtr->clrBk);
2376 HBRUSH hbrOld = SelectObject(hdc, hbr);
2378 Rectangle(hdc, centerx - rectsize, centery - rectsize,
2379 centerx + rectsize + 1, centery + rectsize + 1);
2381 SelectObject(hdc, hbrOld);
2384 SelectObject(hdc, hOldPen);
2385 DeleteObject(hNewPen);
2387 MoveToEx(hdc, centerx - plussize + 1, centery, NULL);
2388 LineTo(hdc, centerx + plussize, centery);
2390 if (!(item->state & TVIS_EXPANDED))
2392 MoveToEx(hdc, centerx, centery - plussize + 1, NULL);
2393 LineTo(hdc, centerx, centery + plussize);
2400 TREEVIEW_DrawItem(TREEVIEW_INFO *infoPtr, HDC hdc, TREEVIEW_ITEM *wineItem)
2406 hOldFont = SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, wineItem));
2408 TREEVIEW_UpdateDispInfo(infoPtr, wineItem, CALLBACK_MASK_ALL);
2410 /* The custom draw handler can query the text rectangle,
2412 TREEVIEW_ComputeTextWidth(infoPtr, wineItem, hdc);
2416 if (infoPtr->cdmode & CDRF_NOTIFYITEMDRAW)
2418 cditem = TREEVIEW_SendCustomDrawItemNotify
2419 (infoPtr, hdc, wineItem, CDDS_ITEMPREPAINT);
2420 TRACE("prepaint:cditem-app returns 0x%x\n", cditem);
2422 if (cditem & CDRF_SKIPDEFAULT)
2424 SelectObject(hdc, hOldFont);
2429 if (cditem & CDRF_NEWFONT)
2430 TREEVIEW_ComputeTextWidth(infoPtr, wineItem, hdc);
2432 TREEVIEW_DrawItemLines(infoPtr, hdc, wineItem);
2434 centery = (wineItem->rect.top + wineItem->rect.bottom) / 2;
2437 * Display the images associated with this item
2442 /* State images are displayed to the left of the Normal image
2443 * image number is in state; zero should be `display no image'.
2445 imageIndex = STATEIMAGEINDEX(wineItem->state);
2447 if (infoPtr->himlState && imageIndex)
2449 ImageList_Draw(infoPtr->himlState, imageIndex, hdc,
2450 wineItem->stateOffset,
2451 centery - infoPtr->stateImageHeight / 2,
2455 /* Now, draw the normal image; can be either selected or
2456 * non-selected image.
2459 if ((wineItem->state & TVIS_SELECTED) && (wineItem->iSelectedImage))
2461 /* The item is currently selected */
2462 imageIndex = wineItem->iSelectedImage;
2466 /* The item is not selected */
2467 imageIndex = wineItem->iImage;
2470 if (infoPtr->himlNormal)
2472 int ovlIdx = wineItem->state & TVIS_OVERLAYMASK;
2474 ImageList_Draw(infoPtr->himlNormal, imageIndex, hdc,
2475 wineItem->imageOffset,
2476 centery - infoPtr->normalImageHeight / 2,
2477 ILD_NORMAL | ovlIdx);
2483 * Display the text associated with this item
2486 /* Don't paint item's text if it's being edited */
2487 if (!infoPtr->hwndEdit || (infoPtr->selectedItem != wineItem))
2489 if (wineItem->pszText)
2491 COLORREF oldTextColor = 0;
2494 BOOL inFocus = (GetFocus() == infoPtr->hwnd);
2497 oldBkMode = SetBkMode(hdc, TRANSPARENT);
2499 /* - If item is drop target or it is selected and window is in focus -
2500 * use blue background (COLOR_HIGHLIGHT).
2501 * - If item is selected, window is not in focus, but it has style
2502 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2503 * - Otherwise - don't fill background
2505 if ((wineItem->state & TVIS_DROPHILITED) || ((wineItem == infoPtr->focusedItem) && !(wineItem->state & TVIS_SELECTED)) ||
2506 ((wineItem->state & TVIS_SELECTED) && (!infoPtr->focusedItem) &&
2507 (inFocus || (infoPtr->dwStyle & TVS_SHOWSELALWAYS))))
2509 if ((wineItem->state & TVIS_DROPHILITED) || inFocus)
2511 hbrBk = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
2513 SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
2517 hbrBk = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
2519 if (infoPtr->clrText == -1)
2521 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
2523 oldTextColor = SetTextColor(hdc, infoPtr->clrText);
2528 if (infoPtr->clrText == -1)
2530 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
2532 oldTextColor = SetTextColor(hdc, infoPtr->clrText);
2535 rcText.top = wineItem->rect.top;
2536 rcText.bottom = wineItem->rect.bottom;
2537 rcText.left = wineItem->textOffset;
2538 rcText.right = rcText.left + wineItem->textWidth + 4;
2542 FillRect(hdc, &rcText, hbrBk);
2543 DeleteObject(hbrBk);
2546 /* Draw the box around the selected item */
2547 if ((wineItem == infoPtr->selectedItem) && inFocus)
2549 DrawFocusRect(hdc,&rcText);
2552 InflateRect(&rcText, -2, -1); /* allow for the focus rect */
2554 TRACE("drawing text %s at (%d,%d)-(%d,%d)\n",
2555 debugstr_a(wineItem->pszText),
2556 rcText.left, rcText.top, rcText.right, rcText.bottom);
2561 lstrlenA(wineItem->pszText),
2563 DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
2565 /* Restore the hdc state */
2566 SetTextColor(hdc, oldTextColor);
2568 if (oldBkMode != TRANSPARENT)
2569 SetBkMode(hdc, oldBkMode);
2573 /* Draw insertion mark if necessary */
2575 if (infoPtr->insertMarkItem)
2576 TRACE("item:%d,mark:%d\n",
2577 TREEVIEW_GetItemIndex(infoPtr, wineItem),
2578 (int)infoPtr->insertMarkItem);
2580 if (wineItem == infoPtr->insertMarkItem)
2582 HPEN hNewPen, hOldPen;
2586 hNewPen = CreatePen(PS_SOLID, 2, infoPtr->clrInsertMark);
2587 hOldPen = SelectObject(hdc, hNewPen);
2589 if (infoPtr->insertBeforeorAfter)
2590 offset = wineItem->rect.bottom - 1;
2592 offset = wineItem->rect.top + 1;
2594 left = wineItem->textOffset - 2;
2595 right = wineItem->textOffset + wineItem->textWidth + 2;
2597 MoveToEx(hdc, left, offset - 3, NULL);
2598 LineTo(hdc, left, offset + 4);
2600 MoveToEx(hdc, left, offset, NULL);
2601 LineTo(hdc, right + 1, offset);
2603 MoveToEx(hdc, right, offset + 3, NULL);
2604 LineTo(hdc, right, offset - 4);
2606 SelectObject(hdc, hOldPen);
2607 DeleteObject(hNewPen);
2610 if (cditem & CDRF_NOTIFYPOSTPAINT)
2612 cditem = TREEVIEW_SendCustomDrawItemNotify
2613 (infoPtr, hdc, wineItem, CDDS_ITEMPOSTPAINT);
2614 TRACE("postpaint:cditem-app returns 0x%x\n", cditem);
2617 SelectObject(hdc, hOldFont);
2620 /* Computes treeHeight and treeWidth and updates the scroll bars.
2623 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO *infoPtr)
2625 TREEVIEW_ITEM *wineItem;
2626 HWND hwnd = infoPtr->hwnd;
2630 LONG scrollX = infoPtr->scrollX;
2632 infoPtr->treeWidth = 0;
2633 infoPtr->treeHeight = 0;
2635 /* We iterate through all visible items in order to get the tree height
2637 wineItem = infoPtr->root->firstChild;
2639 while (wineItem != NULL)
2641 if (ISVISIBLE(wineItem))
2643 /* actually we draw text at textOffset + 2 */
2644 if (2+wineItem->textOffset+wineItem->textWidth > infoPtr->treeWidth)
2645 infoPtr->treeWidth = wineItem->textOffset+wineItem->textWidth+2;
2647 /* This is scroll-adjusted, but we fix this below. */
2648 infoPtr->treeHeight = wineItem->rect.bottom;
2651 wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem);
2654 /* Fix the scroll adjusted treeHeight and treeWidth. */
2655 if (infoPtr->root->firstChild)
2656 infoPtr->treeHeight -= infoPtr->root->firstChild->rect.top;
2658 infoPtr->treeWidth += infoPtr->scrollX;
2660 if (infoPtr->dwStyle & TVS_NOSCROLL) return;
2662 /* Adding one scroll bar may take up enough space that it forces us
2663 * to add the other as well. */
2664 if (infoPtr->treeHeight > infoPtr->clientHeight)
2668 if (infoPtr->treeWidth
2669 > infoPtr->clientWidth - GetSystemMetrics(SM_CXVSCROLL))
2672 else if (infoPtr->treeWidth > infoPtr->clientWidth)
2675 if (!vert && horz && infoPtr->treeHeight
2676 > infoPtr->clientHeight - GetSystemMetrics(SM_CYVSCROLL))
2679 if (horz && (infoPtr->dwStyle & TVS_NOHSCROLL)) horz = FALSE;
2681 si.cbSize = sizeof(SCROLLINFO);
2682 si.fMask = SIF_POS|SIF_RANGE|SIF_PAGE;
2687 si.nPage = TREEVIEW_GetVisibleCount(infoPtr);
2688 si.nPos = infoPtr->firstVisible->visibleOrder;
2689 si.nMax = infoPtr->maxVisibleOrder - 1;
2691 SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
2693 if (!(infoPtr->uInternalStatus & TV_VSCROLL))
2694 ShowScrollBar(hwnd, SB_VERT, TRUE);
2695 infoPtr->uInternalStatus |= TV_VSCROLL;
2699 if (infoPtr->uInternalStatus & TV_VSCROLL)
2700 ShowScrollBar(hwnd, SB_VERT, FALSE);
2701 infoPtr->uInternalStatus &= ~TV_VSCROLL;
2706 si.nPage = infoPtr->clientWidth;
2707 si.nPos = infoPtr->scrollX;
2708 si.nMax = infoPtr->treeWidth - 1;
2710 if (si.nPos > si.nMax - max( si.nPage-1, 0 ))
2712 si.nPos = si.nMax - max( si.nPage-1, 0 );
2716 if (!(infoPtr->uInternalStatus & TV_HSCROLL))
2717 ShowScrollBar(hwnd, SB_HORZ, TRUE);
2718 infoPtr->uInternalStatus |= TV_HSCROLL;
2720 SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
2724 if (infoPtr->uInternalStatus & TV_HSCROLL)
2725 ShowScrollBar(hwnd, SB_HORZ, FALSE);
2726 infoPtr->uInternalStatus &= ~TV_HSCROLL;
2731 if (infoPtr->scrollX != scrollX)
2733 TREEVIEW_HScroll(infoPtr,
2734 MAKEWPARAM(SB_THUMBPOSITION, scrollX));
2738 infoPtr->uInternalStatus &= ~TV_HSCROLL;
2741 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2743 TREEVIEW_EraseBackground(TREEVIEW_INFO *infoPtr, HDC hDC)
2745 HBRUSH hBrush = CreateSolidBrush(infoPtr->clrBk);
2748 GetClientRect(infoPtr->hwnd, &rect);
2749 FillRect(hDC, &rect, hBrush);
2750 DeleteObject(hBrush);
2756 TREEVIEW_Refresh(TREEVIEW_INFO *infoPtr, HDC hdc, RECT *rc)
2758 HWND hwnd = infoPtr->hwnd;
2760 TREEVIEW_ITEM *wineItem;
2762 if (infoPtr->clientHeight == 0 || infoPtr->clientWidth == 0)
2764 TRACE("empty window\n");
2768 infoPtr->cdmode = TREEVIEW_SendCustomDrawNotify(infoPtr, CDDS_PREPAINT,
2771 if (infoPtr->cdmode == CDRF_SKIPDEFAULT)
2773 ReleaseDC(hwnd, hdc);
2777 for (wineItem = infoPtr->root->firstChild;
2779 wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem))
2781 if (ISVISIBLE(wineItem))
2783 /* Avoid unneeded calculations */
2784 if (wineItem->rect.top > rect.bottom)
2786 if (wineItem->rect.bottom < rect.top)
2789 TREEVIEW_DrawItem(infoPtr, hdc, wineItem);
2793 TREEVIEW_UpdateScrollBars(infoPtr);
2795 if (infoPtr->cdmode & CDRF_NOTIFYPOSTPAINT)
2797 TREEVIEW_SendCustomDrawNotify(infoPtr, CDDS_POSTPAINT, hdc, rect);
2801 TREEVIEW_Invalidate(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
2804 InvalidateRect(infoPtr->hwnd, &item->rect, TRUE);
2806 InvalidateRect(infoPtr->hwnd, NULL, TRUE);
2810 TREEVIEW_Paint(TREEVIEW_INFO *infoPtr, WPARAM wParam)
2821 if (!GetUpdateRect(infoPtr->hwnd, &rc, TRUE))
2825 hbitmap = GetCurrentObject(hdc, OBJ_BITMAP);
2826 if (!hbitmap) return 0;
2827 GetObjectA(hbitmap, sizeof(BITMAP), &bitmap);
2828 rc.left = 0; rc.top = 0;
2829 rc.right = bitmap.bmWidth;
2830 rc.bottom = bitmap.bmHeight;
2831 TREEVIEW_EraseBackground(infoPtr, (HDC)wParam);
2836 hdc = BeginPaint(infoPtr->hwnd, &ps);
2840 if(infoPtr->bRedraw) /* WM_SETREDRAW sets bRedraw */
2841 TREEVIEW_Refresh(infoPtr, hdc, &rc);
2844 EndPaint(infoPtr->hwnd, &ps);
2850 /* Sorting **************************************************************/
2852 /***************************************************************************
2853 * Forward the DPA local callback to the treeview owner callback
2856 TREEVIEW_CallBackCompare(TREEVIEW_ITEM *first, TREEVIEW_ITEM *second, LPTVSORTCB pCallBackSort)
2858 /* Forward the call to the client-defined callback */
2859 return pCallBackSort->lpfnCompare(first->lParam,
2861 pCallBackSort->lParam);
2864 /***************************************************************************
2865 * Treeview native sort routine: sort on item text.
2868 TREEVIEW_SortOnName(TREEVIEW_ITEM *first, TREEVIEW_ITEM *second,
2869 TREEVIEW_INFO *infoPtr)
2871 TREEVIEW_UpdateDispInfo(infoPtr, first, TVIF_TEXT);
2872 TREEVIEW_UpdateDispInfo(infoPtr, second, TVIF_TEXT);
2874 return strcasecmp(first->pszText, second->pszText);
2877 /* Returns the number of physical children belonging to item. */
2879 TREEVIEW_CountChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
2884 for (hti = item->firstChild; hti != NULL; hti = hti->nextSibling)
2890 /* Returns a DPA containing a pointer to each physical child of item in
2891 * sibling order. If item has no children, an empty DPA is returned. */
2893 TREEVIEW_BuildChildDPA(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
2895 HTREEITEM child = item->firstChild;
2897 HDPA list = DPA_Create(8);
2898 if (list == 0) return NULL;
2900 for (child = item->firstChild; child != NULL; child = child->nextSibling)
2902 if (DPA_InsertPtr(list, INT_MAX, child) == -1)
2912 /***************************************************************************
2913 * Setup the treeview structure with regards of the sort method
2914 * and sort the children of the TV item specified in lParam
2915 * fRecurse: currently unused. Should be zero.
2916 * parent: if pSort!=NULL, should equal pSort->hParent.
2917 * otherwise, item which child items are to be sorted.
2918 * pSort: sort method info. if NULL, sort on item text.
2919 * if non-NULL, sort on item's lParam content, and let the
2920 * application decide what that means. See also TVM_SORTCHILDRENCB.
2924 TREEVIEW_Sort(TREEVIEW_INFO *infoPtr, BOOL fRecurse, HTREEITEM parent,
2928 PFNDPACOMPARE pfnCompare;
2931 /* undocumented feature: TVI_ROOT means `sort the whole tree' */
2932 if (parent == TVI_ROOT)
2933 parent = infoPtr->root;
2935 /* Check for a valid handle to the parent item */
2936 if (!TREEVIEW_ValidItem(infoPtr, parent))
2938 ERR("invalid item hParent=%x\n", (INT)parent);
2944 pfnCompare = (PFNDPACOMPARE)TREEVIEW_CallBackCompare;
2945 lpCompare = (LPARAM)pSort;
2949 pfnCompare = (PFNDPACOMPARE)TREEVIEW_SortOnName;
2950 lpCompare = (LPARAM)infoPtr;
2953 cChildren = TREEVIEW_CountChildren(infoPtr, parent);
2955 /* Make sure there is something to sort */
2958 /* TREEVIEW_ITEM rechaining */
2961 HTREEITEM nextItem = 0;
2962 HTREEITEM prevItem = 0;
2964 HDPA sortList = TREEVIEW_BuildChildDPA(infoPtr, parent);
2966 if (sortList == NULL)
2969 /* let DPA sort the list */
2970 DPA_Sort(sortList, pfnCompare, lpCompare);
2972 /* The order of DPA entries has been changed, so fixup the
2973 * nextSibling and prevSibling pointers. */
2975 item = (HTREEITEM)DPA_GetPtr(sortList, count++);
2976 while ((nextItem = (HTREEITEM)DPA_GetPtr(sortList, count++)) != NULL)
2978 /* link the two current item toghether */
2979 item->nextSibling = nextItem;
2980 nextItem->prevSibling = item;
2982 if (prevItem == NULL)
2984 /* this is the first item, update the parent */
2985 parent->firstChild = item;
2986 item->prevSibling = NULL;
2990 /* fix the back chaining */
2991 item->prevSibling = prevItem;
2994 /* get ready for the next one */
2999 /* the last item is pointed to by item and never has a sibling */
3000 item->nextSibling = NULL;
3001 parent->lastChild = item;
3003 DPA_Destroy(sortList);
3005 TREEVIEW_VerifyTree(infoPtr);
3007 if (parent->state & TVIS_EXPANDED)
3009 int visOrder = infoPtr->firstVisible->visibleOrder;
3011 if (parent == infoPtr->root)
3012 TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
3014 TREEVIEW_RecalculateVisibleOrder(infoPtr, parent);
3016 if (TREEVIEW_IsChildOf(parent, infoPtr->firstVisible))
3018 TREEVIEW_ITEM *item;
3020 for (item = infoPtr->root->firstChild; item != NULL;
3021 item = TREEVIEW_GetNextListItem(infoPtr, item))
3023 if (item->visibleOrder == visOrder)
3027 TREEVIEW_SetFirstVisible(infoPtr, item, FALSE);
3030 TREEVIEW_Invalidate(infoPtr, NULL);
3039 /***************************************************************************
3040 * Setup the treeview structure with regards of the sort method
3041 * and sort the children of the TV item specified in lParam
3044 TREEVIEW_SortChildrenCB(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPTVSORTCB pSort)
3046 return TREEVIEW_Sort(infoPtr, wParam, pSort->hParent, pSort);
3050 /***************************************************************************
3051 * Sort the children of the TV item specified in lParam.
3054 TREEVIEW_SortChildren(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3056 return TREEVIEW_Sort(infoPtr, (BOOL)wParam, (HTREEITEM)lParam, NULL);
3060 /* Expansion/Collapse ***************************************************/
3063 TREEVIEW_SendExpanding(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
3066 return !TREEVIEW_SendTreeviewNotify(infoPtr, TVN_ITEMEXPANDINGW, action,
3067 TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
3068 | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
3073 TREEVIEW_SendExpanded(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
3076 TREEVIEW_SendTreeviewNotify(infoPtr, TVN_ITEMEXPANDEDW, action,
3077 TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
3078 | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
3083 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3084 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3086 TREEVIEW_Collapse(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
3087 BOOL bRemoveChildren, BOOL bUser)
3089 UINT action = TVE_COLLAPSE | (bRemoveChildren ? TVE_COLLAPSERESET : 0);
3090 BOOL bSetSelection, bSetFirstVisible;
3092 TRACE("TVE_COLLAPSE %p %s\n", wineItem, TREEVIEW_ItemName(wineItem));
3094 if (!(wineItem->state & TVIS_EXPANDED) || wineItem->firstChild == NULL)
3098 TREEVIEW_SendExpanding(infoPtr, wineItem, action);
3100 wineItem->state &= ~TVIS_EXPANDED;
3103 TREEVIEW_SendExpanded(infoPtr, wineItem, action);
3105 bSetSelection = (infoPtr->selectedItem != NULL
3106 && TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem));
3108 bSetFirstVisible = (infoPtr->firstVisible != NULL
3109 && TREEVIEW_IsChildOf(wineItem, infoPtr->firstVisible));
3111 if (bRemoveChildren)
3113 TRACE("TVE_COLLAPSERESET\n");
3114 wineItem->state &= ~TVIS_EXPANDEDONCE;
3115 TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
3118 if (wineItem->firstChild)
3120 TREEVIEW_ITEM *item, *sibling;
3122 sibling = TREEVIEW_GetNextListItem(infoPtr, wineItem);
3124 for (item = wineItem->firstChild; item != sibling;
3125 item = TREEVIEW_GetNextListItem(infoPtr, item))
3127 item->visibleOrder = -1;
3131 TREEVIEW_RecalculateVisibleOrder(infoPtr, wineItem);
3133 TREEVIEW_SetFirstVisible(infoPtr, bSetFirstVisible ? wineItem
3134 : infoPtr->firstVisible, TRUE);
3138 /* Don't call DoSelectItem, it sends notifications. */
3139 if (TREEVIEW_ValidItem(infoPtr, infoPtr->selectedItem))
3140 infoPtr->selectedItem->state &= ~TVIS_SELECTED;
3141 wineItem->state |= TVIS_SELECTED;
3142 infoPtr->selectedItem = wineItem;
3144 TREEVIEW_EnsureVisible(infoPtr, wineItem, FALSE);
3147 TREEVIEW_UpdateScrollBars(infoPtr);
3148 TREEVIEW_Invalidate(infoPtr, NULL);
3154 TREEVIEW_Expand(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
3155 BOOL bExpandPartial, BOOL bUser)
3159 if (!TREEVIEW_HasChildren(infoPtr, wineItem)
3160 || wineItem->state & TVIS_EXPANDED)
3163 TRACE("TVE_EXPAND %p %s\n", wineItem, TREEVIEW_ItemName(wineItem));
3165 if (bUser || !(wineItem->state & TVIS_EXPANDEDONCE))
3167 if (!TREEVIEW_SendExpanding(infoPtr, wineItem, TVE_EXPAND))
3169 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3173 wineItem->state |= TVIS_EXPANDED;
3174 TREEVIEW_SendExpanded(infoPtr, wineItem, TVE_EXPAND);
3175 wineItem->state |= TVIS_EXPANDEDONCE;
3179 /* this item has already been expanded */
3180 wineItem->state |= TVIS_EXPANDED;
3184 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3186 TREEVIEW_RecalculateVisibleOrder(infoPtr, wineItem);
3187 TREEVIEW_UpdateSubTree(infoPtr, wineItem);
3188 TREEVIEW_UpdateScrollBars(infoPtr);
3190 /* Scroll up so that as many children as possible are visible.
3191 * This looses when expanding causes an HScroll bar to appear, but we
3192 * don't know that yet, so the last item is obscured. */
3193 if (wineItem->firstChild != NULL)
3195 int nChildren = wineItem->lastChild->visibleOrder
3196 - wineItem->firstChild->visibleOrder + 1;
3198 int visible_pos = wineItem->visibleOrder
3199 - infoPtr->firstVisible->visibleOrder;
3201 int rows_below = TREEVIEW_GetVisibleCount(infoPtr) - visible_pos - 1;
3203 if (visible_pos > 0 && nChildren > rows_below)
3205 int scroll = nChildren - rows_below;
3207 if (scroll > visible_pos)
3208 scroll = visible_pos;
3212 TREEVIEW_ITEM *newFirstVisible
3213 = TREEVIEW_GetListItem(infoPtr, infoPtr->firstVisible,
3217 TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
3222 TREEVIEW_Invalidate(infoPtr, NULL);
3228 TREEVIEW_Toggle(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem, BOOL bUser)
3232 if (wineItem->state & TVIS_EXPANDED)
3233 return TREEVIEW_Collapse(infoPtr, wineItem, FALSE, bUser);
3235 return TREEVIEW_Expand(infoPtr, wineItem, FALSE, bUser);
3239 TREEVIEW_ExpandAll(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
3241 TREEVIEW_Expand(infoPtr, item, FALSE, TRUE);
3243 for (item = item->firstChild; item != NULL; item = item->nextSibling)
3245 if (TREEVIEW_HasChildren(infoPtr, item))
3246 TREEVIEW_ExpandAll(infoPtr, item);
3250 /* Note:If the specified item is the child of a collapsed parent item,
3251 the parent's list of child items is (recursively) expanded to reveal the
3252 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3253 know if it also applies here.
3257 TREEVIEW_ExpandMsg(TREEVIEW_INFO *infoPtr, UINT flag, HTREEITEM wineItem)
3259 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
3262 TRACE("For (%s) item:%d, flags %x, state:%d\n",
3263 TREEVIEW_ItemName(wineItem), flag,
3264 TREEVIEW_GetItemIndex(infoPtr, wineItem), wineItem->state);
3266 switch (flag & TVE_TOGGLE)
3269 return TREEVIEW_Collapse(infoPtr, wineItem, flag & TVE_COLLAPSERESET,
3273 return TREEVIEW_Expand(infoPtr, wineItem, flag & TVE_EXPANDPARTIAL,
3277 return TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
3284 TRACE("Exiting, Item %p state is now %d...\n", wineItem, wineItem->state);
3288 /* Hit-Testing **********************************************************/
3290 static TREEVIEW_ITEM *
3291 TREEVIEW_HitTestPoint(TREEVIEW_INFO *infoPtr, POINT pt)
3293 TREEVIEW_ITEM *wineItem;
3296 if (!infoPtr->firstVisible)
3299 row = pt.y / infoPtr->uItemHeight + infoPtr->firstVisible->visibleOrder;
3301 for (wineItem = infoPtr->firstVisible; wineItem != NULL;
3302 wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem))
3304 if (row >= wineItem->visibleOrder
3305 && row < wineItem->visibleOrder + wineItem->iIntegral)
3313 TREEVIEW_HitTest(TREEVIEW_INFO *infoPtr, LPTVHITTESTINFO lpht)
3315 TREEVIEW_ITEM *wineItem;
3321 GetClientRect(infoPtr->hwnd, &rect);
3328 status |= TVHT_TOLEFT;
3330 else if (x > rect.right)
3332 status |= TVHT_TORIGHT;
3337 status |= TVHT_ABOVE;
3339 else if (y > rect.bottom)
3341 status |= TVHT_BELOW;
3346 lpht->flags = status;
3347 return (LRESULT)(HTREEITEM)NULL;
3350 wineItem = TREEVIEW_HitTestPoint(infoPtr, lpht->pt);
3353 lpht->flags = TVHT_NOWHERE;
3354 return (LRESULT)(HTREEITEM)NULL;
3357 if (x >= wineItem->textOffset + wineItem->textWidth)
3359 lpht->flags = TVHT_ONITEMRIGHT;
3361 else if (x >= wineItem->textOffset)
3363 lpht->flags = TVHT_ONITEMLABEL;
3365 else if (x >= wineItem->imageOffset)
3367 lpht->flags = TVHT_ONITEMICON;
3369 else if (x >= wineItem->stateOffset)
3371 lpht->flags = TVHT_ONITEMSTATEICON;
3373 else if (x >= wineItem->linesOffset && infoPtr->dwStyle & TVS_HASBUTTONS)
3375 lpht->flags = TVHT_ONITEMBUTTON;
3379 lpht->flags = TVHT_ONITEMINDENT;
3382 lpht->hItem = wineItem;
3383 TRACE("(%ld,%ld):result %x\n", lpht->pt.x, lpht->pt.y, lpht->flags);
3385 return (LRESULT)wineItem;
3388 /* Item Label Editing ***************************************************/
3391 TREEVIEW_GetEditControl(TREEVIEW_INFO *infoPtr)
3393 return (LRESULT)infoPtr->hwndEdit;
3396 static LRESULT CALLBACK
3397 TREEVIEW_Edit_SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3399 TREEVIEW_INFO *infoPtr;
3400 BOOL bCancel = FALSE;
3407 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
3409 TRACE("WM_PAINT start\n");
3410 rc = CallWindowProcA(infoPtr->wpEditOrig, hwnd, uMsg, wParam,
3412 TRACE("WM_PAINT done\n");
3418 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
3419 if (infoPtr->bIgnoreEditKillFocus)
3426 return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
3429 if (wParam == (WPARAM)VK_ESCAPE)
3434 else if (wParam == (WPARAM)VK_RETURN)
3442 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
3444 return CallWindowProcA(infoPtr->wpEditOrig, hwnd, uMsg, wParam,
3449 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3450 /* eg. Using a messagebox */
3452 infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
3453 infoPtr->bIgnoreEditKillFocus = TRUE;
3454 TREEVIEW_EndEditLabelNow(infoPtr, bCancel || !infoPtr->bLabelChanged);
3455 infoPtr->bIgnoreEditKillFocus = FALSE;
3461 /* should handle edit control messages here */
3464 TREEVIEW_Command(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3466 TRACE("%x %ld\n", wParam, lParam);
3468 switch (HIWORD(wParam))
3473 * Adjust the edit window size
3476 TREEVIEW_ITEM *editItem = infoPtr->selectedItem;
3477 HDC hdc = GetDC(infoPtr->hwndEdit);
3480 HFONT hFont, hOldFont = 0;
3482 infoPtr->bLabelChanged = TRUE;
3484 len = GetWindowTextA(infoPtr->hwndEdit, buffer, sizeof(buffer));
3486 /* Select font to get the right dimension of the string */
3487 hFont = (HFONT)SendMessageA(infoPtr->hwndEdit, WM_GETFONT, 0, 0);
3490 hOldFont = SelectObject(hdc, hFont);
3493 if (GetTextExtentPoint32A(hdc, buffer, strlen(buffer), &sz))
3495 TEXTMETRICA textMetric;
3497 /* Add Extra spacing for the next character */
3498 GetTextMetricsA(hdc, &textMetric);
3499 sz.cx += (textMetric.tmMaxCharWidth * 2);
3501 sz.cx = max(sz.cx, textMetric.tmMaxCharWidth * 3);
3503 infoPtr->clientWidth - editItem->textOffset + 2);
3505 SetWindowPos(infoPtr->hwndEdit,
3510 editItem->rect.bottom - editItem->rect.top + 3,
3511 SWP_NOMOVE | SWP_DRAWFRAME);
3516 SelectObject(hdc, hOldFont);
3519 ReleaseDC(infoPtr->hwnd, hdc);
3524 return SendMessageA(GetParent(infoPtr->hwnd), WM_COMMAND, wParam, lParam);
3531 TREEVIEW_EditLabelA(TREEVIEW_INFO *infoPtr, HTREEITEM hItem)
3533 HWND hwnd = infoPtr->hwnd;
3536 TREEVIEW_ITEM *editItem = hItem;
3537 HINSTANCE hinst = (HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE);
3540 TEXTMETRICA textMetric;
3542 TRACE("%x %p\n", (unsigned)hwnd, hItem);
3543 if (!TREEVIEW_ValidItem(infoPtr, editItem))
3546 if (infoPtr->hwndEdit)
3547 return infoPtr->hwndEdit;
3549 infoPtr->bLabelChanged = FALSE;
3551 /* Make sure that edit item is selected */
3552 TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, hItem, TVC_UNKNOWN);
3553 TREEVIEW_EnsureVisible(infoPtr, hItem, TRUE);
3555 TREEVIEW_UpdateDispInfo(infoPtr, editItem, TVIF_TEXT);
3558 /* Select the font to get appropriate metric dimensions */
3559 if (infoPtr->hFont != 0)
3561 hOldFont = SelectObject(hdc, infoPtr->hFont);
3564 /* Get string length in pixels */
3565 GetTextExtentPoint32A(hdc, editItem->pszText, strlen(editItem->pszText),
3568 /* Add Extra spacing for the next character */
3569 GetTextMetricsA(hdc, &textMetric);
3570 sz.cx += (textMetric.tmMaxCharWidth * 2);
3572 sz.cx = max(sz.cx, textMetric.tmMaxCharWidth * 3);
3573 sz.cx = min(sz.cx, infoPtr->clientWidth - editItem->textOffset + 2);
3575 if (infoPtr->hFont != 0)
3577 SelectObject(hdc, hOldFont);
3580 ReleaseDC(hwnd, hdc);
3581 hwndEdit = CreateWindowExA(WS_EX_LEFT,
3584 WS_CHILD | WS_BORDER | ES_AUTOHSCROLL |
3585 WS_CLIPSIBLINGS | ES_WANTRETURN |
3586 ES_LEFT, editItem->textOffset - 2,
3587 editItem->rect.top - 1, sz.cx + 3,
3588 editItem->rect.bottom -
3589 editItem->rect.top + 3, hwnd, 0, hinst, 0);
3590 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3592 infoPtr->hwndEdit = hwndEdit;
3594 /* Get a 2D border. */
3595 SetWindowLongA(hwndEdit, GWL_EXSTYLE,
3596 GetWindowLongA(hwndEdit, GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
3597 SetWindowLongA(hwndEdit, GWL_STYLE,
3598 GetWindowLongA(hwndEdit, GWL_STYLE) | WS_BORDER);
3600 SendMessageA(hwndEdit, WM_SETFONT,
3601 (WPARAM)TREEVIEW_FontForItem(infoPtr, editItem), FALSE);
3603 infoPtr->wpEditOrig = (WNDPROC)SetWindowLongA(hwndEdit, GWL_WNDPROC,
3605 TREEVIEW_Edit_SubclassProc);
3607 if (TREEVIEW_BeginLabelEditNotify(infoPtr, editItem))
3609 DestroyWindow(hwndEdit);
3610 infoPtr->hwndEdit = 0;
3614 infoPtr->selectedItem = hItem;
3615 SetWindowTextA(hwndEdit, editItem->pszText);
3617 SendMessageA(hwndEdit, EM_SETSEL, 0, -1);
3618 ShowWindow(hwndEdit, SW_SHOW);
3625 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel)
3627 HWND hwnd = infoPtr->hwnd;
3628 TREEVIEW_ITEM *editedItem = infoPtr->selectedItem;
3631 char tmpText[1024] = { '\0' };
3634 if (!infoPtr->hwndEdit)
3637 tvdi.hdr.hwndFrom = hwnd;
3638 tvdi.hdr.idFrom = GetWindowLongA(hwnd, GWL_ID);
3639 tvdi.hdr.code = get_notifycode(infoPtr, TVN_ENDLABELEDITW);
3641 tvdi.item.hItem = editedItem;
3642 tvdi.item.state = editedItem->state;
3643 tvdi.item.lParam = editedItem->lParam;
3647 iLength = GetWindowTextA(infoPtr->hwndEdit, tmpText, 1023);
3649 if (iLength >= 1023)
3651 ERR("Insufficient space to retrieve new item label\n");
3654 tvdi.item.pszText = tmpText;
3655 tvdi.item.cchTextMax = iLength + 1;
3659 tvdi.item.pszText = NULL;
3660 tvdi.item.cchTextMax = 0;
3663 bCommit = (BOOL)TREEVIEW_SendRealNotify(infoPtr,
3664 (WPARAM)tvdi.hdr.idFrom, (LPARAM)&tvdi);
3666 if (!bCancel && bCommit) /* Apply the changes */
3668 if (strcmp(tmpText, editedItem->pszText) != 0)
3670 if (NULL == COMCTL32_ReAlloc(editedItem->pszText, iLength + 1))
3672 ERR("OutOfMemory, cannot allocate space for label\n");
3673 DestroyWindow(infoPtr->hwndEdit);
3674 infoPtr->hwndEdit = 0;
3679 editedItem->cchTextMax = iLength + 1;
3680 lstrcpyA(editedItem->pszText, tmpText);
3685 ShowWindow(infoPtr->hwndEdit, SW_HIDE);
3686 DestroyWindow(infoPtr->hwndEdit);
3687 infoPtr->hwndEdit = 0;
3692 TREEVIEW_HandleTimer(TREEVIEW_INFO *infoPtr, WPARAM wParam)
3694 if (wParam != TV_EDIT_TIMER)
3696 ERR("got unknown timer\n");
3700 KillTimer(infoPtr->hwnd, TV_EDIT_TIMER);
3701 infoPtr->Timer &= ~TV_EDIT_TIMER_SET;
3703 TREEVIEW_EditLabelA(infoPtr, infoPtr->selectedItem);
3709 /* Mouse Tracking/Drag **************************************************/
3711 /***************************************************************************
3712 * This is quite unusual piece of code, but that's how it's implemented in
3716 TREEVIEW_TrackMouse(TREEVIEW_INFO *infoPtr, POINT pt)
3718 INT cxDrag = GetSystemMetrics(SM_CXDRAG);
3719 INT cyDrag = GetSystemMetrics(SM_CYDRAG);
3723 r.top = pt.y - cyDrag;
3724 r.left = pt.x - cxDrag;
3725 r.bottom = pt.y + cyDrag;
3726 r.right = pt.x + cxDrag;
3728 SetCapture(infoPtr->hwnd);
3732 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD))
3734 if (msg.message == WM_MOUSEMOVE)
3736 pt.x = SLOWORD(msg.lParam);
3737 pt.y = SHIWORD(msg.lParam);
3738 if (PtInRect(&r, pt))
3746 else if (msg.message >= WM_LBUTTONDOWN &&
3747 msg.message <= WM_RBUTTONDBLCLK)
3749 if (msg.message == WM_RBUTTONUP)
3750 TREEVIEW_RButtonUp(infoPtr, &pt);
3754 DispatchMessageA(&msg);
3757 if (GetCapture() != infoPtr->hwnd)
3767 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO *infoPtr, LPARAM lParam)
3769 TREEVIEW_ITEM *wineItem;
3773 SetFocus(infoPtr->hwnd);
3775 if (infoPtr->Timer & TV_EDIT_TIMER_SET)
3777 /* If there is pending 'edit label' event - kill it now */
3778 KillTimer(infoPtr->hwnd, TV_EDIT_TIMER);
3781 hit.pt.x = SLOWORD(lParam);
3782 hit.pt.y = SHIWORD(lParam);
3784 wineItem = (TREEVIEW_ITEM *)TREEVIEW_HitTest(infoPtr, &hit);
3787 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr, wineItem));
3789 if (TREEVIEW_SendSimpleNotify(infoPtr, NM_DBLCLK) == FALSE)
3793 case TVHT_ONITEMRIGHT:
3794 /* FIXME: we should not have sent NM_DBLCLK in this case. */
3797 case TVHT_ONITEMINDENT:
3798 if (!(infoPtr->dwStyle & TVS_HASLINES))
3804 int level = hit.pt.x / infoPtr->uIndent;
3805 if (!(infoPtr->dwStyle & TVS_LINESATROOT)) level++;
3807 while (wineItem->iLevel > level)
3809 wineItem = wineItem->parent;
3815 case TVHT_ONITEMLABEL:
3816 case TVHT_ONITEMICON:
3817 case TVHT_ONITEMBUTTON:
3818 TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
3821 case TVHT_ONITEMSTATEICON:
3822 if (infoPtr->dwStyle & TVS_CHECKBOXES)
3823 TREEVIEW_ToggleItemState(infoPtr, wineItem);
3825 TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
3834 TREEVIEW_LButtonDown(TREEVIEW_INFO *infoPtr, LPARAM lParam)
3836 HWND hwnd = infoPtr->hwnd;
3841 /* If Edit control is active - kill it and return.
3842 * The best way to do it is to set focus to itself.
3843 * Edit control subclassed procedure will automatically call
3846 if (infoPtr->hwndEdit)
3852 ht.pt.x = SLOWORD(lParam);
3853 ht.pt.y = SHIWORD(lParam);
3855 TREEVIEW_HitTest(infoPtr, &ht);
3856 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr, ht.hItem));
3858 /* update focusedItem and redraw both items */
3859 if(ht.hItem && (ht.flags & TVHT_ONITEM))
3861 infoPtr->focusedItem = ht.hItem;
3862 InvalidateRect(hwnd, &(((HTREEITEM)(ht.hItem))->rect), TRUE);
3864 if(infoPtr->selectedItem)
3865 InvalidateRect(hwnd, &(infoPtr->selectedItem->rect), TRUE);
3868 bTrack = (ht.flags & TVHT_ONITEM)
3869 && !(infoPtr->dwStyle & TVS_DISABLEDRAGDROP);
3871 /* Send NM_CLICK right away */
3873 if (TREEVIEW_SendSimpleNotify(infoPtr, NM_CLICK))
3876 if (ht.flags & TVHT_ONITEMBUTTON)
3878 TREEVIEW_Toggle(infoPtr, ht.hItem, TRUE);
3882 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
3883 if (TREEVIEW_TrackMouse(infoPtr, ht.pt))
3885 TREEVIEW_SendTreeviewDnDNotify(infoPtr, TVN_BEGINDRAGW, ht.hItem, ht.pt);
3886 infoPtr->dropItem = ht.hItem;
3888 /* clean up focusedItem as we dragged and won't select this item */
3889 if(infoPtr->focusedItem)
3891 /* refresh the item that was focused */
3892 tempItem = infoPtr->focusedItem;
3893 infoPtr->focusedItem = 0;
3894 InvalidateRect(infoPtr->hwnd, &tempItem->rect, TRUE);
3896 /* refresh the selected item to return the filled background */
3897 InvalidateRect(infoPtr->hwnd, &(infoPtr->selectedItem->rect), TRUE);
3904 if (TREEVIEW_SendSimpleNotify(infoPtr, NM_CLICK))
3908 * If the style allows editing and the node is already selected
3909 * and the click occurred on the item label...
3911 if ((infoPtr->dwStyle & TVS_EDITLABELS) &&
3912 (ht.flags & TVHT_ONITEMLABEL) && (infoPtr->selectedItem == ht.hItem))
3914 if (infoPtr->Timer & TV_EDIT_TIMER_SET)
3915 KillTimer(hwnd, TV_EDIT_TIMER);
3917 SetTimer(hwnd, TV_EDIT_TIMER, GetDoubleClickTime(), 0);
3918 infoPtr->Timer |= TV_EDIT_TIMER_SET;
3920 else if (ht.flags & TVHT_ONITEM) /* select the item if the hit was inside of the icon or text */
3923 * if we are TVS_SINGLEEXPAND then we want this single click to
3924 * do a bunch of things.
3926 if((infoPtr->dwStyle & TVS_SINGLEEXPAND) &&
3927 (infoPtr->hwndEdit == 0))
3929 TREEVIEW_ITEM *SelItem;
3932 * Send the notification
3934 TREEVIEW_SendTreeviewNotify(infoPtr, TVN_SINGLEEXPAND, TVC_UNKNOWN, TVIF_HANDLE | TVIF_PARAM, ht.hItem, 0);
3937 * Close the previous selection all the way to the root
3938 * as long as the new selection is not a child
3940 if((infoPtr->selectedItem)
3941 && (infoPtr->selectedItem != ht.hItem))
3943 BOOL closeit = TRUE;
3946 /* determine if the hitItem is a child of the currently selected item */
3947 while(closeit && SelItem && TREEVIEW_ValidItem(infoPtr, SelItem) && (SelItem != infoPtr->root))
3949 closeit = (SelItem != infoPtr->selectedItem);
3950 SelItem = SelItem->parent;
3955 if(TREEVIEW_ValidItem(infoPtr, infoPtr->selectedItem))
3956 SelItem = infoPtr->selectedItem;
3958 while(SelItem && (SelItem != ht.hItem) && TREEVIEW_ValidItem(infoPtr, SelItem) && (SelItem != infoPtr->root))
3960 TREEVIEW_Collapse(infoPtr, SelItem, FALSE, FALSE);
3961 SelItem = SelItem->parent;
3967 * Expand the current item
3969 TREEVIEW_Expand(infoPtr, ht.hItem, TVE_TOGGLE, FALSE);
3972 /* Select the current item */
3973 TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, ht.hItem, TVC_BYMOUSE);
3975 else if (ht.flags & TVHT_ONITEMSTATEICON)
3977 /* TVS_CHECKBOXES requires us to toggle the current state */
3978 if (infoPtr->dwStyle & TVS_CHECKBOXES)
3979 TREEVIEW_ToggleItemState(infoPtr, ht.hItem);
3989 TREEVIEW_RButtonDown(TREEVIEW_INFO *infoPtr, LPARAM lParam)
3993 if (infoPtr->hwndEdit)
3995 SetFocus(infoPtr->hwnd);
3999 ht.pt.x = SLOWORD(lParam);
4000 ht.pt.y = SHIWORD(lParam);
4002 TREEVIEW_HitTest(infoPtr, &ht);
4004 if (TREEVIEW_TrackMouse(infoPtr, ht.pt))
4008 TREEVIEW_SendTreeviewDnDNotify(infoPtr, TVN_BEGINRDRAGW, ht.hItem, ht.pt);
4009 infoPtr->dropItem = ht.hItem;
4014 SetFocus(infoPtr->hwnd);
4015 TREEVIEW_SendSimpleNotify(infoPtr, NM_RCLICK);
4022 TREEVIEW_RButtonUp(TREEVIEW_INFO *infoPtr, LPPOINT pPt)
4029 TREEVIEW_CreateDragImage(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4031 TREEVIEW_ITEM *dragItem = (HTREEITEM)lParam;
4035 HBITMAP hbmp, hOldbmp;
4042 if (!(infoPtr->himlNormal))
4045 if (!dragItem || !TREEVIEW_ValidItem(infoPtr, dragItem))
4048 TREEVIEW_UpdateDispInfo(infoPtr, dragItem, TVIF_TEXT);
4050 hwtop = GetDesktopWindow();
4051 htopdc = GetDC(hwtop);
4052 hdc = CreateCompatibleDC(htopdc);
4054 hOldFont = SelectObject(hdc, infoPtr->hFont);
4055 GetTextExtentPoint32A(hdc, dragItem->pszText, lstrlenA(dragItem->pszText),
4057 TRACE("%ld %ld %s %d\n", size.cx, size.cy, dragItem->pszText,
4058 lstrlenA(dragItem->pszText));
4059 hbmp = CreateCompatibleBitmap(htopdc, size.cx, size.cy);
4060 hOldbmp = SelectObject(hdc, hbmp);
4062 ImageList_GetIconSize(infoPtr->himlNormal, &cx, &cy);
4067 infoPtr->dragList = ImageList_Create(size.cx, size.cy, ILC_COLOR, 10, 10);
4068 ImageList_Draw(infoPtr->himlNormal, dragItem->iImage, hdc, 0, 0,
4072 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4073 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4076 /* draw item text */
4078 SetRect(&rc, cx, 0, size.cx, size.cy);
4079 DrawTextA(hdc, dragItem->pszText, lstrlenA(dragItem->pszText), &rc,
4081 SelectObject(hdc, hOldFont);
4082 SelectObject(hdc, hOldbmp);
4084 ImageList_Add(infoPtr->dragList, hbmp, 0);
4088 ReleaseDC(hwtop, htopdc);
4090 return (LRESULT)infoPtr->dragList;
4093 /* Selection ************************************************************/
4096 TREEVIEW_DoSelectItem(TREEVIEW_INFO *infoPtr, INT action, HTREEITEM newSelect,
4099 TREEVIEW_ITEM *prevSelect;
4102 assert(newSelect == NULL || TREEVIEW_ValidItem(infoPtr, newSelect));
4104 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4105 newSelect, TREEVIEW_ItemName(newSelect), action, cause,
4106 newSelect ? newSelect->state : 0);
4108 /* reset and redraw focusedItem if focusedItem was set so we don't */
4109 /* have to worry about the previously focused item when we set a new one */
4110 if(infoPtr->focusedItem)
4112 rcFocused = (infoPtr->focusedItem)->rect;
4113 infoPtr->focusedItem = 0;
4114 InvalidateRect(infoPtr->hwnd, &rcFocused, TRUE);
4120 prevSelect = infoPtr->selectedItem;
4122 if (prevSelect == newSelect)
4125 if (TREEVIEW_SendTreeviewNotify(infoPtr,
4128 TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
4134 prevSelect->state &= ~TVIS_SELECTED;
4136 newSelect->state |= TVIS_SELECTED;
4138 infoPtr->selectedItem = newSelect;
4140 TREEVIEW_EnsureVisible(infoPtr, infoPtr->selectedItem, FALSE);
4142 TREEVIEW_SendTreeviewNotify(infoPtr,
4145 TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
4148 TREEVIEW_Invalidate(infoPtr, prevSelect);
4149 TREEVIEW_Invalidate(infoPtr, newSelect);
4152 case TVGN_DROPHILITE:
4153 prevSelect = infoPtr->dropItem;
4156 prevSelect->state &= ~TVIS_DROPHILITED;
4158 infoPtr->dropItem = newSelect;
4161 newSelect->state |= TVIS_DROPHILITED;
4163 TREEVIEW_Invalidate(infoPtr, prevSelect);
4164 TREEVIEW_Invalidate(infoPtr, newSelect);
4167 case TVGN_FIRSTVISIBLE:
4168 TREEVIEW_EnsureVisible(infoPtr, newSelect, FALSE);
4169 TREEVIEW_SetFirstVisible(infoPtr, newSelect, TRUE);
4170 TREEVIEW_Invalidate(infoPtr, NULL);
4174 TRACE("Leaving state %d\n", newSelect ? newSelect->state : 0);
4178 /* FIXME: handle NM_KILLFOCUS etc */
4180 TREEVIEW_SelectItem(TREEVIEW_INFO *infoPtr, INT wParam, HTREEITEM item)
4182 if (item != NULL && !TREEVIEW_ValidItem(infoPtr, item))
4185 TRACE("%p (%s) %d\n", item, TREEVIEW_ItemName(item), wParam);
4187 if (!TREEVIEW_DoSelectItem(infoPtr, wParam, item, TVC_UNKNOWN))
4193 /*************************************************************************
4194 * TREEVIEW_ProcessLetterKeys
4196 * Processes keyboard messages generated by pressing the letter keys
4198 * What this does is perform a case insensitive search from the
4199 * current position with the following quirks:
4200 * - If two chars or more are pressed in quick succession we search
4201 * for the corresponding string (e.g. 'abc').
4202 * - If there is a delay we wipe away the current search string and
4203 * restart with just that char.
4204 * - If the user keeps pressing the same character, whether slowly or
4205 * fast, so that the search string is entirely composed of this
4206 * character ('aaaaa' for instance), then we search for first item
4207 * that starting with that character.
4208 * - If the user types the above character in quick succession, then
4209 * we must also search for the corresponding string ('aaaaa'), and
4210 * go to that string if there is a match.
4218 * - The current implementation has a list of characters it will
4219 * accept and it ignores averything else. In particular it will
4220 * ignore accentuated characters which seems to match what
4221 * Windows does. But I'm not sure it makes sense to follow
4223 * - We don't sound a beep when the search fails.
4224 * - The search should start from the focused item, not from the selected
4225 * item. One reason for this is to allow for multiple selections in trees.
4226 * But currently infoPtr->focusedItem does not seem very usable.
4230 * TREEVIEW_ProcessLetterKeys
4232 static INT TREEVIEW_ProcessLetterKeys(
4233 HWND hwnd, /* handle to the window */
4234 WPARAM charCode, /* the character code, the actual character */
4235 LPARAM keyData /* key data */
4238 TREEVIEW_INFO *infoPtr;
4240 HTREEITEM endidx,idx;
4242 CHAR buffer[MAX_PATH];
4243 DWORD timestamp,elapsed;
4245 /* simple parameter checking */
4246 if (!hwnd || !charCode || !keyData)
4249 infoPtr=(TREEVIEW_INFO*)GetWindowLongA(hwnd, 0);
4253 /* only allow the valid WM_CHARs through */
4254 if (!isalnum(charCode) &&
4255 charCode != '.' && charCode != '`' && charCode != '!' &&
4256 charCode != '@' && charCode != '#' && charCode != '$' &&
4257 charCode != '%' && charCode != '^' && charCode != '&' &&
4258 charCode != '*' && charCode != '(' && charCode != ')' &&
4259 charCode != '-' && charCode != '_' && charCode != '+' &&
4260 charCode != '=' && charCode != '\\'&& charCode != ']' &&
4261 charCode != '}' && charCode != '[' && charCode != '{' &&
4262 charCode != '/' && charCode != '?' && charCode != '>' &&
4263 charCode != '<' && charCode != ',' && charCode != '~')
4266 /* compute how much time elapsed since last keypress */
4267 timestamp = GetTickCount();
4268 if (timestamp > infoPtr->lastKeyPressTimestamp) {
4269 elapsed=timestamp-infoPtr->lastKeyPressTimestamp;
4271 elapsed=infoPtr->lastKeyPressTimestamp-timestamp;
4274 /* update the search parameters */
4275 infoPtr->lastKeyPressTimestamp=timestamp;
4276 if (elapsed < KEY_DELAY) {
4277 if (infoPtr->nSearchParamLength < sizeof(infoPtr->szSearchParam)) {
4278 infoPtr->szSearchParam[infoPtr->nSearchParamLength++]=charCode;
4280 if (infoPtr->charCode != charCode) {
4281 infoPtr->charCode=charCode=0;
4284 infoPtr->charCode=charCode;
4285 infoPtr->szSearchParam[0]=charCode;
4286 infoPtr->nSearchParamLength=1;
4287 /* Redundant with the 1 char string */
4291 /* and search from the current position */
4293 if (infoPtr->selectedItem != NULL) {
4294 endidx=infoPtr->selectedItem;
4295 /* if looking for single character match,
4296 * then we must always move forward
4298 if (infoPtr->nSearchParamLength == 1)
4299 idx=TREEVIEW_GetNextListItem(infoPtr,endidx);
4304 idx=infoPtr->root->firstChild;
4310 idx=infoPtr->root->firstChild;
4314 ZeroMemory(&item, sizeof(item));
4315 item.mask = TVIF_TEXT;
4317 item.pszText = buffer;
4318 item.cchTextMax = sizeof(buffer);
4319 TREEVIEW_GetItemA( infoPtr, &item );
4321 /* check for a match */
4322 if (strncasecmp(item.pszText,infoPtr->szSearchParam,infoPtr->nSearchParamLength) == 0) {
4325 } else if ( (charCode != 0) && (nItem == NULL) &&
4326 (nItem != infoPtr->selectedItem) &&
4327 (strncasecmp(item.pszText,infoPtr->szSearchParam,1) == 0) ) {
4328 /* This would work but we must keep looking for a longer match */
4331 idx=TREEVIEW_GetNextListItem(infoPtr,idx);
4332 } while (idx != endidx);
4334 if (nItem != NULL) {
4335 if (TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, nItem, TVC_BYKEYBOARD)) {
4336 TREEVIEW_EnsureVisible(infoPtr, nItem, FALSE);
4343 /* Scrolling ************************************************************/
4346 TREEVIEW_EnsureVisible(TREEVIEW_INFO *infoPtr, HTREEITEM item, BOOL bHScroll)
4348 HTREEITEM newFirstVisible = NULL;
4351 if (!TREEVIEW_ValidItem(infoPtr, item))
4354 if (!ISVISIBLE(item))
4356 /* Expand parents as necessary. */
4359 /* see if we are trying to ensure that root is vislble */
4360 if((item != infoPtr->root) && TREEVIEW_ValidItem(infoPtr, item))
4361 parent = item->parent;
4363 parent = item; /* this item is the topmost item */
4365 while (parent != infoPtr->root)
4367 if (!(parent->state & TVIS_EXPANDED))
4368 TREEVIEW_Expand(infoPtr, parent, FALSE, FALSE);
4370 parent = parent->parent;
4374 TRACE("%p (%s) %ld - %ld\n", item, TREEVIEW_ItemName(item), item->visibleOrder,
4375 infoPtr->firstVisible->visibleOrder);
4377 visible_pos = item->visibleOrder - infoPtr->firstVisible->visibleOrder;
4379 if (visible_pos < 0)
4381 /* item is before the start of the list: put it at the top. */
4382 newFirstVisible = item;
4384 else if (visible_pos >= TREEVIEW_GetVisibleCount(infoPtr)
4385 /* Sometimes, before we are displayed, GVC is 0, causing us to
4386 * spuriously scroll up. */
4389 /* item is past the end of the list. */
4390 int scroll = visible_pos - TREEVIEW_GetVisibleCount(infoPtr);
4392 newFirstVisible = TREEVIEW_GetListItem(infoPtr, infoPtr->firstVisible,
4398 /* Scroll window so item's text is visible as much as possible */
4399 /* Calculation of amount of extra space is taken from EditLabel code */
4401 TEXTMETRICA textMetric;
4402 HDC hdc = GetWindowDC(infoPtr->hwnd);
4404 x = item->textWidth;
4406 GetTextMetricsA(hdc, &textMetric);
4407 ReleaseDC(infoPtr->hwnd, hdc);
4409 x += (textMetric.tmMaxCharWidth * 2);
4410 x = max(x, textMetric.tmMaxCharWidth * 3);
4412 if (item->textOffset < 0)
4413 pos = item->textOffset;
4414 else if (item->textOffset + x > infoPtr->clientWidth)
4416 if (x > infoPtr->clientWidth)
4417 pos = item->textOffset;
4419 pos = item->textOffset + x - infoPtr->clientWidth;
4424 TREEVIEW_HScroll(infoPtr, MAKEWPARAM(SB_THUMBPOSITION, infoPtr->scrollX + pos));
4427 if (newFirstVisible != NULL && newFirstVisible != infoPtr->firstVisible)
4429 TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
4438 TREEVIEW_SetFirstVisible(TREEVIEW_INFO *infoPtr,
4439 TREEVIEW_ITEM *newFirstVisible,
4440 BOOL bUpdateScrollPos)
4444 TRACE("%p: %s\n", newFirstVisible, TREEVIEW_ItemName(newFirstVisible));
4446 if (newFirstVisible != NULL)
4448 /* Prevent an empty gap from appearing at the bottom... */
4449 gap_size = TREEVIEW_GetVisibleCount(infoPtr)
4450 - infoPtr->maxVisibleOrder + newFirstVisible->visibleOrder;
4454 newFirstVisible = TREEVIEW_GetListItem(infoPtr, newFirstVisible,
4457 /* ... unless we just don't have enough items. */
4458 if (newFirstVisible == NULL)
4459 newFirstVisible = infoPtr->root->firstChild;
4463 if (infoPtr->firstVisible != newFirstVisible)
4465 if (infoPtr->firstVisible == NULL || newFirstVisible == NULL)
4467 infoPtr->firstVisible = newFirstVisible;
4468 TREEVIEW_Invalidate(infoPtr, NULL);
4472 TREEVIEW_ITEM *item;
4473 int scroll = infoPtr->uItemHeight *
4474 (infoPtr->firstVisible->visibleOrder
4475 - newFirstVisible->visibleOrder);
4477 infoPtr->firstVisible = newFirstVisible;
4479 for (item = infoPtr->root->firstChild; item != NULL;
4480 item = TREEVIEW_GetNextListItem(infoPtr, item))
4482 item->rect.top += scroll;
4483 item->rect.bottom += scroll;
4486 if (bUpdateScrollPos)
4487 SetScrollPos(infoPtr->hwnd, SB_VERT,
4488 newFirstVisible->visibleOrder, TRUE);
4490 ScrollWindow(infoPtr->hwnd, 0, scroll, NULL, NULL);
4491 UpdateWindow(infoPtr->hwnd);
4496 /************************************************************************
4497 * VScroll is always in units of visible items. i.e. we always have a
4498 * visible item aligned to the top of the control. (Unless we have no
4502 TREEVIEW_VScroll(TREEVIEW_INFO *infoPtr, WPARAM wParam)
4504 TREEVIEW_ITEM *oldFirstVisible = infoPtr->firstVisible;
4505 TREEVIEW_ITEM *newFirstVisible = NULL;
4507 int nScrollCode = LOWORD(wParam);
4509 TRACE("wp %x\n", wParam);
4511 if (!(infoPtr->uInternalStatus & TV_VSCROLL))
4514 if (infoPtr->hwndEdit)
4515 SetFocus(infoPtr->hwnd);
4517 if (!oldFirstVisible)
4519 assert(infoPtr->root->firstChild == NULL);
4523 switch (nScrollCode)
4526 newFirstVisible = infoPtr->root->firstChild;
4530 newFirstVisible = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
4534 newFirstVisible = TREEVIEW_GetPrevListItem(infoPtr, oldFirstVisible);
4538 newFirstVisible = TREEVIEW_GetNextListItem(infoPtr, oldFirstVisible);
4542 newFirstVisible = TREEVIEW_GetListItem(infoPtr, oldFirstVisible,
4543 -max(1, TREEVIEW_GetVisibleCount(infoPtr)));
4547 newFirstVisible = TREEVIEW_GetListItem(infoPtr, oldFirstVisible,
4548 max(1, TREEVIEW_GetVisibleCount(infoPtr)));
4552 case SB_THUMBPOSITION:
4553 newFirstVisible = TREEVIEW_GetListItem(infoPtr,
4554 infoPtr->root->firstChild,
4555 (LONG)(SHORT)HIWORD(wParam));
4562 if (newFirstVisible != NULL)
4564 if (newFirstVisible != oldFirstVisible)
4565 TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible,
4566 nScrollCode != SB_THUMBTRACK);
4567 else if (nScrollCode == SB_THUMBPOSITION)
4568 SetScrollPos(infoPtr->hwnd, SB_VERT,
4569 newFirstVisible->visibleOrder, TRUE);
4576 TREEVIEW_HScroll(TREEVIEW_INFO *infoPtr, WPARAM wParam)
4579 int scrollX = infoPtr->scrollX;
4580 int nScrollCode = LOWORD(wParam);
4582 TRACE("wp %x\n", wParam);
4584 if (!(infoPtr->uInternalStatus & TV_HSCROLL))
4587 if (infoPtr->hwndEdit)
4588 SetFocus(infoPtr->hwnd);
4590 maxWidth = infoPtr->treeWidth - infoPtr->clientWidth;
4591 /* shall never occur */
4598 switch (nScrollCode)
4601 scrollX -= infoPtr->uItemHeight;
4604 scrollX += infoPtr->uItemHeight;
4607 scrollX -= infoPtr->clientWidth;
4610 scrollX += infoPtr->clientWidth;
4614 case SB_THUMBPOSITION:
4615 scrollX = (int)(SHORT)HIWORD(wParam);
4622 if (scrollX > maxWidth)
4624 else if (scrollX < 0)
4628 if (scrollX != infoPtr->scrollX)
4630 TREEVIEW_ITEM *item;
4631 LONG scroll_pixels = infoPtr->scrollX - scrollX;
4633 for (item = infoPtr->root->firstChild; item != NULL;
4634 item = TREEVIEW_GetNextListItem(infoPtr, item))
4636 item->linesOffset += scroll_pixels;
4637 item->stateOffset += scroll_pixels;
4638 item->imageOffset += scroll_pixels;
4639 item->textOffset += scroll_pixels;
4642 ScrollWindow(infoPtr->hwnd, scroll_pixels, 0, NULL, NULL);
4643 infoPtr->scrollX = scrollX;
4644 UpdateWindow(infoPtr->hwnd);
4647 if (nScrollCode != SB_THUMBTRACK)
4648 SetScrollPos(infoPtr->hwnd, SB_HORZ, scrollX, TRUE);
4654 TREEVIEW_MouseWheel(TREEVIEW_INFO *infoPtr, WPARAM wParam)
4657 UINT pulScrollLines = 3;
4659 if (infoPtr->firstVisible == NULL)
4662 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, &pulScrollLines, 0);
4664 gcWheelDelta = -(short)HIWORD(wParam);
4665 pulScrollLines *= (gcWheelDelta / WHEEL_DELTA);
4667 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
4669 int newDy = infoPtr->firstVisible->visibleOrder + pulScrollLines;
4670 int maxDy = infoPtr->maxVisibleOrder;
4678 TREEVIEW_VScroll(infoPtr, MAKEWPARAM(SB_THUMBPOSITION, newDy));
4683 /* Create/Destroy *******************************************************/
4686 TREEVIEW_Create(HWND hwnd)
4689 TREEVIEW_INFO *infoPtr;
4691 TRACE("wnd %p, style %lx\n", hwnd, GetWindowLongA(hwnd, GWL_STYLE));
4693 infoPtr = (TREEVIEW_INFO *)COMCTL32_Alloc(sizeof(TREEVIEW_INFO));
4695 if (infoPtr == NULL)
4697 ERR("could not allocate info memory!\n");
4701 SetWindowLongA(hwnd, 0, (DWORD)infoPtr);
4703 infoPtr->hwnd = hwnd;
4704 infoPtr->dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
4705 infoPtr->uInternalStatus = 0;
4707 infoPtr->uNumItems = 0;
4708 infoPtr->cdmode = 0;
4709 infoPtr->uScrollTime = 300; /* milliseconds */
4710 infoPtr->bRedraw = TRUE;
4712 GetClientRect(hwnd, &rcClient);
4714 /* No scroll bars yet. */
4715 infoPtr->clientWidth = rcClient.right;
4716 infoPtr->clientHeight = rcClient.bottom;
4718 infoPtr->treeWidth = 0;
4719 infoPtr->treeHeight = 0;
4721 infoPtr->uIndent = 19;
4722 infoPtr->selectedItem = 0;
4723 infoPtr->focusedItem = 0;
4725 infoPtr->firstVisible = 0;
4726 infoPtr->maxVisibleOrder = 0;
4727 infoPtr->dropItem = 0;
4728 infoPtr->insertMarkItem = 0;
4729 infoPtr->insertBeforeorAfter = 0;
4732 infoPtr->scrollX = 0;
4734 infoPtr->clrBk = GetSysColor(COLOR_WINDOW);
4735 infoPtr->clrText = -1; /* use system color */
4736 infoPtr->clrLine = RGB(128, 128, 128);
4737 infoPtr->clrInsertMark = GetSysColor(COLOR_BTNTEXT);
4741 infoPtr->hwndEdit = 0;
4742 infoPtr->wpEditOrig = NULL;
4743 infoPtr->bIgnoreEditKillFocus = FALSE;
4744 infoPtr->bLabelChanged = FALSE;
4746 infoPtr->himlNormal = NULL;
4747 infoPtr->himlState = NULL;
4748 infoPtr->normalImageWidth = 0;
4749 infoPtr->normalImageHeight = 0;
4750 infoPtr->stateImageWidth = 0;
4751 infoPtr->stateImageHeight = 0;
4753 infoPtr->items = DPA_Create(16);
4755 infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);
4756 infoPtr->hBoldFont = TREEVIEW_CreateBoldFont(infoPtr->hFont);
4758 infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
4760 infoPtr->root = TREEVIEW_AllocateItem(infoPtr);
4761 infoPtr->root->state = TVIS_EXPANDED;
4762 infoPtr->root->iLevel = -1;
4763 infoPtr->root->visibleOrder = -1;
4765 infoPtr->hwndNotify = GetParent(hwnd);
4767 infoPtr->bTransparent = ( GetWindowLongA( hwnd, GWL_STYLE) & TBSTYLE_FLAT);
4770 infoPtr->hwndToolTip = 0;
4772 infoPtr->bUnicode = IsWindowUnicode (hwnd);
4774 /* Determine what type of notify should be issued */
4775 /* sets infoPtr->bNtfUnicode */
4776 TREEVIEW_NotifyFormat(infoPtr, infoPtr->hwndNotify, NF_REQUERY);
4778 if (!(infoPtr->dwStyle & TVS_NOTOOLTIPS))
4779 infoPtr->hwndToolTip = COMCTL32_CreateToolTip(hwnd);
4781 if (infoPtr->dwStyle & TVS_CHECKBOXES)
4784 HBITMAP hbm, hbmOld;
4788 infoPtr->himlState =
4789 ImageList_Create(16, 16, ILC_COLOR | ILC_MASK, 3, 0);
4791 hdc = CreateCompatibleDC(0);
4792 hbm = CreateCompatibleBitmap(hdc, 48, 16);
4793 hbmOld = SelectObject(hdc, hbm);
4795 rc.left = 0; rc.top = 0;
4796 rc.right = 48; rc.bottom = 16;
4797 FillRect(hdc, &rc, (HBRUSH)(COLOR_WINDOW+1));
4799 rc.left = 18; rc.top = 2;
4800 rc.right = 30; rc.bottom = 14;
4801 DrawFrameControl(hdc, &rc, DFC_BUTTON,
4802 DFCS_BUTTONCHECK|DFCS_FLAT);
4804 rc.left = 34; rc.right = 46;
4805 DrawFrameControl(hdc, &rc, DFC_BUTTON,
4806 DFCS_BUTTONCHECK|DFCS_FLAT|DFCS_CHECKED);
4808 nIndex = ImageList_AddMasked(infoPtr->himlState, hbm,
4809 GetSysColor(COLOR_WINDOW));
4810 TRACE("chckbox index %d\n", nIndex);
4811 SelectObject(hdc, hbmOld);
4815 infoPtr->stateImageWidth = 16;
4816 infoPtr->stateImageHeight = 16;
4823 TREEVIEW_Destroy(TREEVIEW_INFO *infoPtr)
4827 TREEVIEW_RemoveTree(infoPtr);
4829 /* tool tip is automatically destroyed: we are its owner */
4831 /* Restore original wndproc */
4832 if (infoPtr->hwndEdit)
4833 SetWindowLongA(infoPtr->hwndEdit, GWL_WNDPROC,
4834 (LONG)infoPtr->wpEditOrig);
4836 /* Deassociate treeview from the window before doing anything drastic. */
4837 SetWindowLongA(infoPtr->hwnd, 0, (LONG)NULL);
4839 DeleteObject(infoPtr->hBoldFont);
4840 COMCTL32_Free(infoPtr);
4845 /* Miscellaneous Messages ***********************************************/
4848 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO *infoPtr, WPARAM key)
4856 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
4857 SCROLL_ENTRY(SB_VERT, SB_PAGEUP), /* VK_PRIOR */
4858 SCROLL_ENTRY(SB_VERT, SB_PAGEDOWN), /* VK_NEXT */
4859 SCROLL_ENTRY(SB_VERT, SB_BOTTOM), /* VK_END */
4860 SCROLL_ENTRY(SB_VERT, SB_TOP), /* VK_HOME */
4861 SCROLL_ENTRY(SB_HORZ, SB_LINEUP), /* VK_LEFT */
4862 SCROLL_ENTRY(SB_VERT, SB_LINEUP), /* VK_UP */
4863 SCROLL_ENTRY(SB_HORZ, SB_LINEDOWN), /* VK_RIGHT */
4864 SCROLL_ENTRY(SB_VERT, SB_LINEDOWN) /* VK_DOWN */
4868 if (key >= VK_PRIOR && key <= VK_DOWN)
4870 unsigned char code = scroll[key - VK_PRIOR].code;
4872 (((code & (1 << 7)) == (SB_HORZ << 7))
4874 : TREEVIEW_VScroll)(infoPtr, code & 0x7F);
4880 /************************************************************************
4883 * VK_UP Move selection to the previous non-hidden item.
4884 * VK_DOWN Move selection to the next non-hidden item.
4885 * VK_HOME Move selection to the first item.
4886 * VK_END Move selection to the last item.
4887 * VK_LEFT If expanded then collapse, otherwise move to parent.
4888 * VK_RIGHT If collapsed then expand, otherwise move to first child.
4890 * VK_SUBTRACT Collapse.
4891 * VK_MULTIPLY Expand all.
4892 * VK_PRIOR Move up GetVisibleCount items.
4893 * VK_NEXT Move down GetVisibleCount items.
4894 * VK_BACK Move to parent.
4895 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
4898 TREEVIEW_KeyDown(TREEVIEW_INFO *infoPtr, WPARAM wParam)
4900 /* If it is non-NULL and different, it will be selected and visible. */
4901 TREEVIEW_ITEM *newSelection = NULL;
4903 TREEVIEW_ITEM *prevItem = infoPtr->selectedItem;
4905 TRACE("%x\n", wParam);
4907 if (prevItem == NULL)
4910 if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
4911 return TREEVIEW_ScrollKeyDown(infoPtr, wParam);
4916 newSelection = TREEVIEW_GetPrevListItem(infoPtr, prevItem);
4918 newSelection = infoPtr->root->firstChild;
4922 newSelection = TREEVIEW_GetNextListItem(infoPtr, prevItem);
4926 newSelection = infoPtr->root->firstChild;
4930 newSelection = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
4934 if (prevItem->state & TVIS_EXPANDED)
4936 TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
4938 else if (prevItem->parent != infoPtr->root)
4940 newSelection = prevItem->parent;
4945 if (TREEVIEW_HasChildren(infoPtr, prevItem))
4947 if (!(prevItem->state & TVIS_EXPANDED))
4948 TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
4951 newSelection = prevItem->firstChild;
4958 TREEVIEW_ExpandAll(infoPtr, prevItem);
4962 if (!(prevItem->state & TVIS_EXPANDED))
4963 TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
4967 if (prevItem->state & TVIS_EXPANDED)
4968 TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
4973 = TREEVIEW_GetListItem(infoPtr, prevItem,
4974 -TREEVIEW_GetVisibleCount(infoPtr));
4979 = TREEVIEW_GetListItem(infoPtr, prevItem,
4980 TREEVIEW_GetVisibleCount(infoPtr));
4984 newSelection = prevItem->parent;
4985 if (newSelection == infoPtr->root)
4986 newSelection = NULL;
4990 if (infoPtr->dwStyle & TVS_CHECKBOXES)
4991 TREEVIEW_ToggleItemState(infoPtr, prevItem);
4995 if (newSelection && newSelection != prevItem)
4997 if (TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, newSelection,
5000 TREEVIEW_EnsureVisible(infoPtr, newSelection, FALSE);
5008 TREEVIEW_Notify(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5010 LPNMHDR lpnmh = (LPNMHDR)lParam;
5012 if (lpnmh->code == PGN_CALCSIZE) {
5013 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5015 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5016 lppgc->iWidth = infoPtr->treeWidth;
5017 TRACE("got PGN_CALCSIZE, returning horz size = %ld, client=%ld\n",
5018 infoPtr->treeWidth, infoPtr->clientWidth);
5021 lppgc->iHeight = infoPtr->treeHeight;
5022 TRACE("got PGN_CALCSIZE, returning vert size = %ld, client=%ld\n",
5023 infoPtr->treeHeight, infoPtr->clientHeight);
5027 return DefWindowProcA(infoPtr->hwnd, WM_NOTIFY, wParam, lParam);
5030 static INT TREEVIEW_NotifyFormat (TREEVIEW_INFO *infoPtr, HWND hwndFrom, UINT nCommand)
5034 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom, nCommand);
5036 if (nCommand != NF_REQUERY) return 0;
5038 format = SendMessageW(hwndFrom, WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwnd, NF_QUERY);
5039 TRACE("format=%d\n", format);
5041 if (format != NFR_ANSI && format != NFR_UNICODE) return 0;
5043 infoPtr->bNtfUnicode = (format == NFR_UNICODE);
5049 TREEVIEW_Size(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5051 if (wParam == SIZE_RESTORED)
5053 infoPtr->clientWidth = SLOWORD(lParam);
5054 infoPtr->clientHeight = SHIWORD(lParam);
5056 TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
5057 TREEVIEW_SetFirstVisible(infoPtr, infoPtr->firstVisible, TRUE);
5058 TREEVIEW_UpdateScrollBars(infoPtr);
5062 FIXME("WM_SIZE flag %x %lx not handled\n", wParam, lParam);
5065 TREEVIEW_Invalidate(infoPtr, NULL);
5070 TREEVIEW_StyleChanged(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5072 TRACE("(%x %lx)\n", wParam, lParam);
5074 if (wParam == GWL_STYLE)
5076 DWORD dwNewStyle = ((LPSTYLESTRUCT)lParam)->styleNew;
5078 /* we have to take special care about tooltips */
5079 if ((infoPtr->dwStyle ^ dwNewStyle) & TVS_NOTOOLTIPS)
5081 if (infoPtr->dwStyle & TVS_NOTOOLTIPS)
5083 infoPtr->hwndToolTip = COMCTL32_CreateToolTip(infoPtr->hwnd);
5088 DestroyWindow(infoPtr->hwndToolTip);
5089 infoPtr->hwndToolTip = 0;
5093 infoPtr->dwStyle = dwNewStyle;
5096 TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
5097 TREEVIEW_UpdateScrollBars(infoPtr);
5098 TREEVIEW_Invalidate(infoPtr, NULL);
5104 TREEVIEW_SetFocus(TREEVIEW_INFO *infoPtr)
5108 if (!infoPtr->selectedItem)
5110 TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, infoPtr->firstVisible,
5114 TREEVIEW_SendSimpleNotify(infoPtr, NM_SETFOCUS);
5115 TREEVIEW_Invalidate(infoPtr, infoPtr->selectedItem);
5120 TREEVIEW_KillFocus(TREEVIEW_INFO *infoPtr)
5124 TREEVIEW_SendSimpleNotify(infoPtr, NM_KILLFOCUS);
5125 TREEVIEW_Invalidate(infoPtr, infoPtr->selectedItem);
5130 static LRESULT WINAPI
5131 TREEVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5133 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
5134 if (infoPtr) TREEVIEW_VerifyTree(infoPtr);
5137 if (uMsg == WM_CREATE)
5138 TREEVIEW_Create(hwnd);
5145 case TVM_CREATEDRAGIMAGE:
5146 return TREEVIEW_CreateDragImage(infoPtr, wParam, lParam);
5148 case TVM_DELETEITEM:
5149 return TREEVIEW_DeleteItem(infoPtr, (HTREEITEM)lParam);
5151 case TVM_EDITLABELA:
5152 return (LRESULT)TREEVIEW_EditLabelA(infoPtr, (HTREEITEM)lParam);
5154 case TVM_EDITLABELW:
5155 FIXME("Unimplemented msg TVM_EDITLABELW\n");
5158 case TVM_ENDEDITLABELNOW:
5159 return TREEVIEW_EndEditLabelNow(infoPtr, (BOOL)wParam);
5161 case TVM_ENSUREVISIBLE:
5162 return TREEVIEW_EnsureVisible(infoPtr, (HTREEITEM)lParam, TRUE);
5165 return TREEVIEW_ExpandMsg(infoPtr, (UINT)wParam, (HTREEITEM)lParam);
5167 case TVM_GETBKCOLOR:
5168 return TREEVIEW_GetBkColor(infoPtr);
5171 return TREEVIEW_GetCount(infoPtr);
5173 case TVM_GETEDITCONTROL:
5174 return TREEVIEW_GetEditControl(infoPtr);
5176 case TVM_GETIMAGELIST:
5177 return TREEVIEW_GetImageList(infoPtr, wParam);
5180 return TREEVIEW_GetIndent(infoPtr);
5182 case TVM_GETINSERTMARKCOLOR:
5183 return TREEVIEW_GetInsertMarkColor(infoPtr);
5185 case TVM_GETISEARCHSTRINGA:
5186 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5189 case TVM_GETISEARCHSTRINGW:
5190 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5194 return TREEVIEW_GetItemA(infoPtr, (LPTVITEMEXA)lParam);
5197 return TREEVIEW_GetItemW(infoPtr, (LPTVITEMEXW)lParam);
5199 case TVM_GETITEMHEIGHT:
5200 return TREEVIEW_GetItemHeight(infoPtr);
5202 case TVM_GETITEMRECT:
5203 return TREEVIEW_GetItemRect(infoPtr, (BOOL)wParam, (LPRECT)lParam);
5205 case TVM_GETITEMSTATE:
5206 return TREEVIEW_GetItemState(infoPtr, (HTREEITEM)wParam, (UINT)lParam);
5208 case TVM_GETLINECOLOR:
5209 return TREEVIEW_GetLineColor(infoPtr);
5211 case TVM_GETNEXTITEM:
5212 return TREEVIEW_GetNextItem(infoPtr, (UINT)wParam, (HTREEITEM)lParam);
5214 case TVM_GETSCROLLTIME:
5215 return TREEVIEW_GetScrollTime(infoPtr);
5217 case TVM_GETTEXTCOLOR:
5218 return TREEVIEW_GetTextColor(infoPtr);
5220 case TVM_GETTOOLTIPS:
5221 return TREEVIEW_GetToolTips(infoPtr);
5223 case TVM_GETUNICODEFORMAT:
5224 FIXME("Unimplemented msg TVM_GETUNICODEFORMAT\n");
5227 case TVM_GETVISIBLECOUNT:
5228 return TREEVIEW_GetVisibleCount(infoPtr);
5231 return TREEVIEW_HitTest(infoPtr, (LPTVHITTESTINFO)lParam);
5233 case TVM_INSERTITEMA:
5234 return TREEVIEW_InsertItemA(infoPtr, lParam);
5236 case TVM_INSERTITEMW:
5237 return TREEVIEW_InsertItemW(infoPtr, lParam);
5239 case TVM_SELECTITEM:
5240 return TREEVIEW_SelectItem(infoPtr, (INT)wParam, (HTREEITEM)lParam);
5242 case TVM_SETBKCOLOR:
5243 return TREEVIEW_SetBkColor(infoPtr, (COLORREF)lParam);
5245 case TVM_SETIMAGELIST:
5246 return TREEVIEW_SetImageList(infoPtr, wParam, (HIMAGELIST)lParam);
5249 return TREEVIEW_SetIndent(infoPtr, (UINT)wParam);
5251 case TVM_SETINSERTMARK:
5252 return TREEVIEW_SetInsertMark(infoPtr, (BOOL)wParam, (HTREEITEM)lParam);
5254 case TVM_SETINSERTMARKCOLOR:
5255 return TREEVIEW_SetInsertMarkColor(infoPtr, (COLORREF)lParam);
5258 return TREEVIEW_SetItemA(infoPtr, (LPTVITEMEXA)lParam);
5261 return TREEVIEW_SetItemW(infoPtr, (LPTVITEMEXW)lParam);
5264 case TVM_SETLINECOLOR:
5265 return TREEVIEW_SetLineColor(infoPtr, (COLORREF)lParam);
5267 case TVM_SETITEMHEIGHT:
5268 return TREEVIEW_SetItemHeight(infoPtr, (INT)(SHORT)wParam);
5270 case TVM_SETSCROLLTIME:
5271 return TREEVIEW_SetScrollTime(infoPtr, (UINT)wParam);
5273 case TVM_SETTEXTCOLOR:
5274 return TREEVIEW_SetTextColor(infoPtr, (COLORREF)lParam);
5276 case TVM_SETTOOLTIPS:
5277 return TREEVIEW_SetToolTips(infoPtr, (HWND)wParam);
5279 case TVM_SETUNICODEFORMAT:
5280 FIXME("Unimplemented msg TVM_SETUNICODEFORMAT\n");
5283 case TVM_SORTCHILDREN:
5284 return TREEVIEW_SortChildren(infoPtr, wParam, lParam);
5286 case TVM_SORTCHILDRENCB:
5287 return TREEVIEW_SortChildrenCB(infoPtr, wParam, (LPTVSORTCB)lParam);
5290 return TREEVIEW_ProcessLetterKeys( hwnd, wParam, lParam );
5293 return TREEVIEW_Command(infoPtr, wParam, lParam);
5296 return TREEVIEW_Destroy(infoPtr);
5301 return TREEVIEW_EraseBackground(infoPtr, (HDC)wParam);
5304 return DLGC_WANTARROWS | DLGC_WANTCHARS;
5307 return TREEVIEW_GetFont(infoPtr);
5310 return TREEVIEW_HScroll(infoPtr, wParam);
5313 return TREEVIEW_KeyDown(infoPtr, wParam);
5316 return TREEVIEW_KillFocus(infoPtr);
5318 case WM_LBUTTONDBLCLK:
5319 return TREEVIEW_LButtonDoubleClick(infoPtr, lParam);
5321 case WM_LBUTTONDOWN:
5322 return TREEVIEW_LButtonDown(infoPtr, lParam);
5324 /* WM_MBUTTONDOWN */
5329 return TREEVIEW_Notify(infoPtr, wParam, lParam);
5331 case WM_NOTIFYFORMAT:
5332 return TREEVIEW_NotifyFormat(infoPtr, (HWND)wParam, (UINT)lParam);
5335 return TREEVIEW_Paint(infoPtr, wParam);
5337 /* WM_PRINTCLIENT */
5339 case WM_RBUTTONDOWN:
5340 return TREEVIEW_RButtonDown(infoPtr, lParam);
5343 return TREEVIEW_SetFocus(infoPtr);
5346 return TREEVIEW_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
5349 return TREEVIEW_SetRedraw(infoPtr, wParam, lParam);
5352 return TREEVIEW_Size(infoPtr, wParam, lParam);
5354 case WM_STYLECHANGED:
5355 return TREEVIEW_StyleChanged(infoPtr, wParam, lParam);
5357 /* WM_SYSCOLORCHANGE */
5362 return TREEVIEW_HandleTimer(infoPtr, wParam);
5365 return TREEVIEW_VScroll(infoPtr, wParam);
5367 /* WM_WININICHANGE */
5370 if (wParam & (MK_SHIFT | MK_CONTROL))
5372 return TREEVIEW_MouseWheel(infoPtr, wParam);
5375 TRACE("drawItem\n");
5379 /* This mostly catches MFC and Delphi messages. :( */
5380 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
5381 TRACE("Unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
5383 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
5389 /* Class Registration ***************************************************/
5392 TREEVIEW_Register(void)
5398 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
5399 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5400 wndClass.lpfnWndProc = (WNDPROC)TREEVIEW_WindowProc;
5401 wndClass.cbClsExtra = 0;
5402 wndClass.cbWndExtra = sizeof(TREEVIEW_INFO *);
5404 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
5405 wndClass.hbrBackground = 0;
5406 wndClass.lpszClassName = WC_TREEVIEWA;
5408 RegisterClassA(&wndClass);
5413 TREEVIEW_Unregister(void)
5415 UnregisterClassA(WC_TREEVIEWA, NULL);
5419 /* Tree Verification ****************************************************/
5423 TREEVIEW_VerifyChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item);
5425 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO *infoPtr,
5426 TREEVIEW_ITEM *item)
5428 assert(infoPtr != NULL);
5429 assert(item != NULL);
5431 /* both NULL, or both non-null */
5432 assert((item->firstChild == NULL) == (item->lastChild == NULL));
5434 assert(item->firstChild != item);
5435 assert(item->lastChild != item);
5437 if (item->firstChild)
5439 assert(item->firstChild->parent == item);
5440 assert(item->firstChild->prevSibling == NULL);
5443 if (item->lastChild)
5445 assert(item->lastChild->parent == item);
5446 assert(item->lastChild->nextSibling == NULL);
5449 assert(item->nextSibling != item);
5450 if (item->nextSibling)
5452 assert(item->nextSibling->parent == item->parent);
5453 assert(item->nextSibling->prevSibling == item);
5456 assert(item->prevSibling != item);
5457 if (item->prevSibling)
5459 assert(item->prevSibling->parent == item->parent);
5460 assert(item->prevSibling->nextSibling == item);
5465 TREEVIEW_VerifyItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
5467 assert(item != NULL);
5469 assert(item->parent != NULL);
5470 assert(item->parent != item);
5471 assert(item->iLevel == item->parent->iLevel + 1);
5473 assert(DPA_GetPtrIndex(infoPtr->items, item) != -1);
5475 TREEVIEW_VerifyItemCommon(infoPtr, item);
5477 TREEVIEW_VerifyChildren(infoPtr, item);
5481 TREEVIEW_VerifyChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
5483 TREEVIEW_ITEM *child;
5484 assert(item != NULL);
5486 for (child = item->firstChild; child != NULL; child = child->nextSibling)
5487 TREEVIEW_VerifyItem(infoPtr, child);
5491 TREEVIEW_VerifyRoot(TREEVIEW_INFO *infoPtr)
5493 TREEVIEW_ITEM *root = infoPtr->root;
5495 assert(root != NULL);
5496 assert(root->iLevel == -1);
5497 assert(root->parent == NULL);
5498 assert(root->prevSibling == NULL);
5500 TREEVIEW_VerifyItemCommon(infoPtr, root);
5502 TREEVIEW_VerifyChildren(infoPtr, root);
5506 TREEVIEW_VerifyTree(TREEVIEW_INFO *infoPtr)
5508 assert(infoPtr != NULL);
5510 TREEVIEW_VerifyRoot(infoPtr);