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
6 * Copyright 2002 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Note that TREEVIEW_INFO * and HTREEITEM are the same thing.
24 * Note2: All items always! have valid (allocated) pszText field.
25 * If item's text == LPSTR_TEXTCALLBACKA we allocate buffer
26 * of size TEXT_CALLBACK_SIZE in DoSetItem.
27 * We use callbackMask to keep track of fields to be updated.
30 * missing notifications: NM_SETCURSOR, TVN_GETINFOTIP, TVN_KEYDOWN,
31 * TVN_SETDISPINFO, TVN_SINGLEEXPAND
33 * missing styles: TVS_FULLROWSELECT, TVS_INFOTIP, TVS_NOSCROLL,
34 * TVS_RTLREADING, TVS_TRACKSELECT
36 * missing item styles: TVIS_CUT, TVIS_EXPANDPARTIAL
38 * Make the insertion mark look right.
39 * Scroll (instead of repaint) as much as possible.
43 #include "wine/port.h"
52 #define NONAMELESSUNION
53 #define NONAMELESSSTRUCT
61 #include "wine/unicode.h"
62 #include "wine/debug.h"
64 /* internal structures */
66 typedef struct _TREEITEM /* HTREEITEM is a _TREEINFO *. */
77 int iIntegral; /* item height multiplier (1 is normal) */
78 int iLevel; /* indentation level:0=root level */
79 HTREEITEM parent; /* handle to parent or 0 if at root */
80 HTREEITEM firstChild; /* handle to first child or 0 if no child */
82 HTREEITEM prevSibling; /* handle to prev item in list, 0 if first */
83 HTREEITEM nextSibling; /* handle to next item in list, 0 if last */
89 LONG textWidth; /* horizontal text extent for pszText */
90 LONG visibleOrder; /* visible ordering, 0 is first visible item */
94 typedef struct tagTREEVIEW_INFO
97 HWND hwndNotify; /* Owner window to send notifications to */
100 UINT uInternalStatus;
102 UINT uNumItems; /* number of valid TREEVIEW_ITEMs */
103 INT cdmode; /* last custom draw setting */
104 UINT uScrollTime; /* max. time for scrolling in milliseconds */
105 BOOL bRedraw; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
107 UINT uItemHeight; /* item height */
110 LONG clientWidth; /* width of control window */
111 LONG clientHeight; /* height of control window */
113 LONG treeWidth; /* width of visible tree items */
114 LONG treeHeight; /* height of visible tree items */
116 UINT uIndent; /* indentation in pixels */
117 HTREEITEM selectedItem; /* handle to selected item or 0 if none */
118 HTREEITEM hotItem; /* handle currently under cursor, 0 if none */
119 HTREEITEM focusedItem; /* item that was under the cursor when WM_LBUTTONDOWN was received */
121 HTREEITEM firstVisible; /* handle to first visible item */
122 LONG maxVisibleOrder;
123 HTREEITEM dropItem; /* handle to item selected by drag cursor */
124 HTREEITEM insertMarkItem; /* item after which insertion mark is placed */
125 BOOL insertBeforeorAfter; /* flag used by TVM_SETINSERTMARK */
126 HIMAGELIST dragList; /* Bitmap of dragged item */
131 COLORREF clrInsertMark;
137 WNDPROC wpEditOrig; /* orig window proc for subclassing edit */
138 BOOL bIgnoreEditKillFocus;
141 BOOL bNtfUnicode; /* TRUE if should send NOTIFY with W */
142 HIMAGELIST himlNormal;
143 int normalImageHeight;
144 int normalImageWidth;
145 HIMAGELIST himlState;
146 int stateImageHeight;
150 DWORD lastKeyPressTimestamp; /* Added */
151 WPARAM charCode; /* Added */
152 INT nSearchParamLength; /* Added */
153 WCHAR szSearchParam[ MAX_PATH ]; /* Added */
157 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
158 #define KEY_DELAY 450
160 /* bitflags for infoPtr->uInternalStatus */
162 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
163 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
164 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
165 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
166 #define TV_RDRAG 0x10 /* dito Rbutton */
167 #define TV_RDRAGGING 0x20
169 /* bitflags for infoPtr->timer */
171 #define TV_EDIT_TIMER 2
172 #define TV_EDIT_TIMER_SET 2
175 VOID TREEVIEW_Register (VOID);
176 VOID TREEVIEW_Unregister (VOID);
179 WINE_DEFAULT_DEBUG_CHANNEL(treeview);
182 #define TEXT_CALLBACK_SIZE 260
184 #define TREEVIEW_LEFT_MARGIN 8
186 #define MINIMUM_INDENT 19
188 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
190 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
191 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
192 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
195 typedef VOID (*TREEVIEW_ItemEnumFunc)(TREEVIEW_INFO *, TREEVIEW_ITEM *,LPVOID);
198 static VOID TREEVIEW_Invalidate(TREEVIEW_INFO *, TREEVIEW_ITEM *);
200 static LRESULT TREEVIEW_DoSelectItem(TREEVIEW_INFO *, INT, HTREEITEM, INT);
201 static VOID TREEVIEW_SetFirstVisible(TREEVIEW_INFO *, TREEVIEW_ITEM *, BOOL);
202 static LRESULT TREEVIEW_EnsureVisible(TREEVIEW_INFO *, HTREEITEM, BOOL);
203 static LRESULT TREEVIEW_RButtonUp(TREEVIEW_INFO *, LPPOINT);
204 static LRESULT TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel);
205 static VOID TREEVIEW_UpdateScrollBars(TREEVIEW_INFO *infoPtr);
206 static LRESULT TREEVIEW_HScroll(TREEVIEW_INFO *, WPARAM);
207 static INT TREEVIEW_NotifyFormat (TREEVIEW_INFO *infoPtr, HWND wParam, UINT lParam);
210 /* Random Utilities *****************************************************/
214 TREEVIEW_VerifyTree(TREEVIEW_INFO *infoPtr)
219 /* The definition is at the end of the file. */
220 static void TREEVIEW_VerifyTree(TREEVIEW_INFO *infoPtr);
223 /* Returns the treeview private data if hwnd is a treeview.
224 * Otherwise returns an undefined value. */
225 static TREEVIEW_INFO *
226 TREEVIEW_GetInfoPtr(HWND hwnd)
228 return (TREEVIEW_INFO *)GetWindowLongW(hwnd, 0);
231 /* Don't call this. Nothing wants an item index. */
233 TREEVIEW_GetItemIndex(TREEVIEW_INFO *infoPtr, HTREEITEM handle)
235 assert(infoPtr != NULL);
237 return DPA_GetPtrIndex(infoPtr->items, handle);
240 /***************************************************************************
241 * This method checks that handle is an item for this tree.
244 TREEVIEW_ValidItem(TREEVIEW_INFO *infoPtr, HTREEITEM handle)
246 if (TREEVIEW_GetItemIndex(infoPtr, handle) == -1)
248 TRACE("invalid item %p\n", handle);
256 TREEVIEW_CreateBoldFont(HFONT hOrigFont)
260 GetObjectA(hOrigFont, sizeof(font), &font);
261 font.lfWeight = FW_BOLD;
262 return CreateFontIndirectA(&font);
266 TREEVIEW_FontForItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
268 return (item->state & TVIS_BOLD) ? infoPtr->hBoldFont : infoPtr->hFont;
271 /* for trace/debugging purposes only */
273 TREEVIEW_ItemName(TREEVIEW_ITEM *item)
275 if (item == NULL) return "<null item>";
276 if (item->pszText == LPSTR_TEXTCALLBACKW) return "<callback>";
277 if (item->pszText == NULL) return "<null>";
278 return debugstr_w(item->pszText);
281 /* An item is not a child of itself. */
283 TREEVIEW_IsChildOf(TREEVIEW_ITEM *parent, TREEVIEW_ITEM *child)
287 child = child->parent;
288 if (child == parent) return TRUE;
289 } while (child != NULL);
295 /* Tree Traversal *******************************************************/
297 /***************************************************************************
298 * This method returns the last expanded sibling or child child item
301 static TREEVIEW_ITEM *
302 TREEVIEW_GetLastListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
307 while (wineItem->lastChild)
309 if (wineItem->state & TVIS_EXPANDED)
310 wineItem = wineItem->lastChild;
315 if (wineItem == infoPtr->root)
321 /***************************************************************************
322 * This method returns the previous non-hidden item in the list not
323 * considering the tree hierarchy.
325 static TREEVIEW_ITEM *
326 TREEVIEW_GetPrevListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *tvItem)
328 if (tvItem->prevSibling)
330 /* This item has a prevSibling, get the last item in the sibling's tree. */
331 TREEVIEW_ITEM *upItem = tvItem->prevSibling;
333 if ((upItem->state & TVIS_EXPANDED) && upItem->lastChild != NULL)
334 return TREEVIEW_GetLastListItem(infoPtr, upItem->lastChild);
340 /* this item does not have a prevSibling, get the parent */
341 return (tvItem->parent != infoPtr->root) ? tvItem->parent : NULL;
346 /***************************************************************************
347 * This method returns the next physical item in the treeview not
348 * considering the tree hierarchy.
350 static TREEVIEW_ITEM *
351 TREEVIEW_GetNextListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *tvItem)
353 assert(tvItem != NULL);
356 * If this item has children and is expanded, return the first child
358 if ((tvItem->state & TVIS_EXPANDED) && tvItem->firstChild != NULL)
360 return tvItem->firstChild;
365 * try to get the sibling
367 if (tvItem->nextSibling)
368 return tvItem->nextSibling;
371 * Otherwise, get the parent's sibling.
373 while (tvItem->parent)
375 tvItem = tvItem->parent;
377 if (tvItem->nextSibling)
378 return tvItem->nextSibling;
384 /***************************************************************************
385 * This method returns the nth item starting at the given item. It returns
386 * the last item (or first) we we run out of items.
388 * Will scroll backward if count is <0.
389 * forward if count is >0.
391 static TREEVIEW_ITEM *
392 TREEVIEW_GetListItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
395 TREEVIEW_ITEM *(*next_item)(TREEVIEW_INFO *, TREEVIEW_ITEM *);
396 TREEVIEW_ITEM *previousItem;
398 assert(wineItem != NULL);
402 next_item = TREEVIEW_GetNextListItem;
407 next_item = TREEVIEW_GetPrevListItem;
414 previousItem = wineItem;
415 wineItem = next_item(infoPtr, wineItem);
417 } while (--count && wineItem != NULL);
420 return wineItem ? wineItem : previousItem;
423 /* Notifications ************************************************************/
425 static INT get_notifycode(TREEVIEW_INFO *infoPtr, INT code)
427 if (!infoPtr->bNtfUnicode) {
429 case TVN_SELCHANGINGW: return TVN_SELCHANGINGA;
430 case TVN_SELCHANGEDW: return TVN_SELCHANGEDA;
431 case TVN_GETDISPINFOW: return TVN_GETDISPINFOA;
432 case TVN_SETDISPINFOW: return TVN_SETDISPINFOA;
433 case TVN_ITEMEXPANDINGW: return TVN_ITEMEXPANDINGA;
434 case TVN_ITEMEXPANDEDW: return TVN_ITEMEXPANDEDA;
435 case TVN_BEGINDRAGW: return TVN_BEGINDRAGA;
436 case TVN_BEGINRDRAGW: return TVN_BEGINRDRAGA;
437 case TVN_DELETEITEMW: return TVN_DELETEITEMA;
438 case TVN_BEGINLABELEDITW: return TVN_BEGINLABELEDITA;
439 case TVN_ENDLABELEDITW: return TVN_ENDLABELEDITA;
440 case TVN_GETINFOTIPW: return TVN_GETINFOTIPA;
447 TREEVIEW_SendRealNotify(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
449 TRACE("wParam=%d, lParam=%ld\n", wParam, lParam);
450 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, wParam, lParam);
454 TREEVIEW_SendSimpleNotify(TREEVIEW_INFO *infoPtr, UINT code)
457 HWND hwnd = infoPtr->hwnd;
460 nmhdr.hwndFrom = hwnd;
461 nmhdr.idFrom = GetWindowLongW(hwnd, GWL_ID);
462 nmhdr.code = get_notifycode(infoPtr, code);
464 return (BOOL)TREEVIEW_SendRealNotify(infoPtr,
465 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
469 TREEVIEW_TVItemFromItem(TREEVIEW_INFO *infoPtr, UINT mask, TVITEMW *tvItem, TREEVIEW_ITEM *item)
472 tvItem->hItem = item;
473 tvItem->state = item->state;
474 tvItem->stateMask = 0;
475 tvItem->iImage = item->iImage;
476 tvItem->iImage = item->iImage;
477 tvItem->iSelectedImage = item->iSelectedImage;
478 tvItem->cChildren = item->cChildren;
479 tvItem->lParam = item->lParam;
483 if (!infoPtr->bNtfUnicode)
485 tvItem->cchTextMax = WideCharToMultiByte( CP_ACP, 0, item->pszText, -1, NULL, 0, NULL, NULL );
486 tvItem->pszText = Alloc (tvItem->cchTextMax);
487 WideCharToMultiByte( CP_ACP, 0, item->pszText, -1, (LPSTR)tvItem->pszText, tvItem->cchTextMax, 0, 0 );
491 tvItem->cchTextMax = item->cchTextMax;
492 tvItem->pszText = item->pszText;
497 tvItem->cchTextMax = 0;
498 tvItem->pszText = NULL;
503 TREEVIEW_SendTreeviewNotify(TREEVIEW_INFO *infoPtr, UINT code, UINT action,
504 UINT mask, HTREEITEM oldItem, HTREEITEM newItem)
506 HWND hwnd = infoPtr->hwnd;
510 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
511 code, action, oldItem, newItem);
513 ZeroMemory(&nmhdr, sizeof(NMTREEVIEWA));
515 nmhdr.hdr.hwndFrom = hwnd;
516 nmhdr.hdr.idFrom = GetWindowLongW(hwnd, GWL_ID);
517 nmhdr.hdr.code = get_notifycode(infoPtr, code);
518 nmhdr.action = action;
521 TREEVIEW_TVItemFromItem(infoPtr, mask, &nmhdr.itemOld, oldItem);
524 TREEVIEW_TVItemFromItem(infoPtr, mask, &nmhdr.itemNew, newItem);
529 ret = (BOOL)TREEVIEW_SendRealNotify(infoPtr,
530 (WPARAM)nmhdr.hdr.idFrom,
532 if (!infoPtr->bNtfUnicode)
534 Free(nmhdr.itemOld.pszText);
535 Free(nmhdr.itemNew.pszText);
541 TREEVIEW_SendTreeviewDnDNotify(TREEVIEW_INFO *infoPtr, UINT code,
542 HTREEITEM dragItem, POINT pt)
544 HWND hwnd = infoPtr->hwnd;
547 TRACE("code:%d dragitem:%p\n", code, dragItem);
549 nmhdr.hdr.hwndFrom = hwnd;
550 nmhdr.hdr.idFrom = GetWindowLongW(hwnd, GWL_ID);
551 nmhdr.hdr.code = get_notifycode(infoPtr, code);
553 nmhdr.itemNew.mask = TVIF_STATE | TVIF_PARAM | TVIF_HANDLE;
554 nmhdr.itemNew.hItem = dragItem;
555 nmhdr.itemNew.state = dragItem->state;
556 nmhdr.itemNew.lParam = dragItem->lParam;
558 nmhdr.ptDrag.x = pt.x;
559 nmhdr.ptDrag.y = pt.y;
561 return (BOOL)TREEVIEW_SendRealNotify(infoPtr,
562 (WPARAM)nmhdr.hdr.idFrom,
568 TREEVIEW_SendCustomDrawNotify(TREEVIEW_INFO *infoPtr, DWORD dwDrawStage,
571 HWND hwnd = infoPtr->hwnd;
572 NMTVCUSTOMDRAW nmcdhdr;
575 TRACE("drawstage:%lx hdc:%p\n", dwDrawStage, hdc);
577 nmcd = &nmcdhdr.nmcd;
578 nmcd->hdr.hwndFrom = hwnd;
579 nmcd->hdr.idFrom = GetWindowLongW(hwnd, GWL_ID);
580 nmcd->hdr.code = NM_CUSTOMDRAW;
581 nmcd->dwDrawStage = dwDrawStage;
584 nmcd->dwItemSpec = 0;
585 nmcd->uItemState = 0;
586 nmcd->lItemlParam = 0;
587 nmcdhdr.clrText = infoPtr->clrText;
588 nmcdhdr.clrTextBk = infoPtr->clrBk;
591 return (BOOL)TREEVIEW_SendRealNotify(infoPtr,
592 (WPARAM)nmcd->hdr.idFrom,
598 /* FIXME: need to find out when the flags in uItemState need to be set */
601 TREEVIEW_SendCustomDrawItemNotify(TREEVIEW_INFO *infoPtr, HDC hdc,
602 TREEVIEW_ITEM *wineItem, UINT uItemDrawState)
604 HWND hwnd = infoPtr->hwnd;
605 NMTVCUSTOMDRAW nmcdhdr;
607 DWORD dwDrawStage, dwItemSpec;
611 dwDrawStage = CDDS_ITEM | uItemDrawState;
612 dwItemSpec = (DWORD)wineItem;
614 if (wineItem->state & TVIS_SELECTED)
615 uItemState |= CDIS_SELECTED;
616 if (wineItem == infoPtr->selectedItem)
617 uItemState |= CDIS_FOCUS;
618 if (wineItem == infoPtr->hotItem)
619 uItemState |= CDIS_HOT;
621 nmcd = &nmcdhdr.nmcd;
622 nmcd->hdr.hwndFrom = hwnd;
623 nmcd->hdr.idFrom = GetWindowLongW(hwnd, GWL_ID);
624 nmcd->hdr.code = NM_CUSTOMDRAW;
625 nmcd->dwDrawStage = dwDrawStage;
627 nmcd->rc = wineItem->rect;
628 nmcd->dwItemSpec = dwItemSpec;
629 nmcd->uItemState = uItemState;
630 nmcd->lItemlParam = wineItem->lParam;
631 nmcdhdr.clrText = infoPtr->clrText;
632 nmcdhdr.clrTextBk = infoPtr->clrBk;
633 nmcdhdr.iLevel = wineItem->iLevel;
635 TRACE("drawstage:%lx hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
636 nmcd->dwDrawStage, nmcd->hdc, nmcd->dwItemSpec,
637 nmcd->uItemState, nmcd->lItemlParam);
639 retval = TREEVIEW_SendRealNotify(infoPtr,
640 (WPARAM)nmcd->hdr.idFrom,
643 infoPtr->clrText = nmcdhdr.clrText;
644 infoPtr->clrBk = nmcdhdr.clrTextBk;
649 TREEVIEW_BeginLabelEditNotify(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *editItem)
651 HWND hwnd = infoPtr->hwnd;
655 tvdi.hdr.hwndFrom = hwnd;
656 tvdi.hdr.idFrom = GetWindowLongW(hwnd, GWL_ID);
657 tvdi.hdr.code = get_notifycode(infoPtr, TVN_BEGINLABELEDITW);
659 TREEVIEW_TVItemFromItem(infoPtr, TVIF_HANDLE | TVIF_STATE | TVIF_PARAM | TVIF_TEXT,
660 &tvdi.item, editItem);
662 ret = (BOOL)TREEVIEW_SendRealNotify(infoPtr, tvdi.hdr.idFrom, (LPARAM)&tvdi);
664 if (!infoPtr->bNtfUnicode)
665 Free(tvdi.item.pszText);
671 TREEVIEW_UpdateDispInfo(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
674 NMTVDISPINFOW callback;
675 HWND hwnd = infoPtr->hwnd;
677 TRACE("mask %x callbackMask %x\n", mask, wineItem->callbackMask);
678 mask &= wineItem->callbackMask;
680 if (mask == 0) return;
682 callback.hdr.hwndFrom = hwnd;
683 callback.hdr.idFrom = GetWindowLongW(hwnd, GWL_ID);
684 callback.hdr.code = get_notifycode(infoPtr, TVN_GETDISPINFOW);
686 /* 'state' always contains valid value, as well as 'lParam'.
687 * All other parameters are uninitialized.
689 callback.item.pszText = wineItem->pszText;
690 callback.item.cchTextMax = wineItem->cchTextMax;
691 callback.item.mask = mask;
692 callback.item.hItem = wineItem;
693 callback.item.state = wineItem->state;
694 callback.item.lParam = wineItem->lParam;
696 /* If text is changed we need to recalculate textWidth */
697 if (mask & TVIF_TEXT)
698 wineItem->textWidth = 0;
700 TREEVIEW_SendRealNotify(infoPtr,
701 (WPARAM)callback.hdr.idFrom, (LPARAM)&callback);
703 /* It may have changed due to a call to SetItem. */
704 mask &= wineItem->callbackMask;
706 if ((mask & TVIF_TEXT) && callback.item.pszText != wineItem->pszText)
708 /* Instead of copying text into our buffer user specified its own */
709 if (!infoPtr->bNtfUnicode) {
712 int len = MultiByteToWideChar( CP_ACP, 0,
713 (LPSTR)callback.item.pszText, -1,
715 buflen = max((len)*sizeof(WCHAR), TEXT_CALLBACK_SIZE);
716 newText = (LPWSTR)ReAlloc(wineItem->pszText, buflen);
718 TRACE("returned str %s, len=%d, buflen=%d\n",
719 debugstr_a((LPSTR)callback.item.pszText), len, buflen);
723 wineItem->pszText = newText;
724 MultiByteToWideChar( CP_ACP, 0,
725 (LPSTR)callback.item.pszText, -1,
726 wineItem->pszText, buflen);
727 wineItem->cchTextMax = buflen;
729 /* If ReAlloc fails we have nothing to do, but keep original text */
732 int len = max(lstrlenW(callback.item.pszText) + 1,
734 LPWSTR newText = ReAlloc(wineItem->pszText, len);
736 TRACE("returned wstr %s, len=%d\n",
737 debugstr_w(callback.item.pszText), len);
741 wineItem->pszText = newText;
742 strcpyW(wineItem->pszText, callback.item.pszText);
743 wineItem->cchTextMax = len;
745 /* If ReAlloc fails we have nothing to do, but keep original text */
748 else if (mask & TVIF_TEXT) {
749 /* User put text into our buffer, that is ok unless A string */
750 if (!infoPtr->bNtfUnicode) {
752 LPWSTR oldText = NULL;
754 int len = MultiByteToWideChar( CP_ACP, 0,
755 (LPSTR)callback.item.pszText, -1,
757 buflen = max((len)*sizeof(WCHAR), TEXT_CALLBACK_SIZE);
758 newText = (LPWSTR)Alloc(buflen);
760 TRACE("same buffer str %s, len=%d, buflen=%d\n",
761 debugstr_a((LPSTR)callback.item.pszText), len, buflen);
765 oldText = wineItem->pszText;
766 wineItem->pszText = newText;
767 MultiByteToWideChar( CP_ACP, 0,
768 (LPSTR)callback.item.pszText, -1,
769 wineItem->pszText, buflen);
770 wineItem->cchTextMax = buflen;
777 if (mask & TVIF_IMAGE)
778 wineItem->iImage = callback.item.iImage;
780 if (mask & TVIF_SELECTEDIMAGE)
781 wineItem->iSelectedImage = callback.item.iSelectedImage;
783 if (mask & TVIF_CHILDREN)
784 wineItem->cChildren = callback.item.cChildren;
786 /* These members are now permanently set. */
787 if (callback.item.mask & TVIF_DI_SETITEM)
788 wineItem->callbackMask &= ~callback.item.mask;
791 /***************************************************************************
792 * This function uses cChildren field to decide whether the item has
794 * Note: if this returns TRUE, the child items may not actually exist,
795 * they could be virtual.
797 * Just use wineItem->firstChild to check for physical children.
800 TREEVIEW_HasChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
802 TREEVIEW_UpdateDispInfo(infoPtr, wineItem, TVIF_CHILDREN);
804 return wineItem->cChildren > 0;
808 /* Item Position ********************************************************/
810 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
812 TREEVIEW_ComputeItemInternalMetrics(TREEVIEW_INFO *infoPtr,
815 /* Same effect, different optimisation. */
817 BOOL lar = ((infoPtr->dwStyle & TVS_LINESATROOT)
818 && (infoPtr->dwStyle & (TVS_HASLINES|TVS_HASBUTTONS)));
820 BOOL lar = ((infoPtr->dwStyle
821 & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS))
825 item->linesOffset = infoPtr->uIndent * (item->iLevel + lar - 1)
827 item->stateOffset = item->linesOffset + infoPtr->uIndent;
828 item->imageOffset = item->stateOffset
829 + (STATEIMAGEINDEX(item->state) ? infoPtr->stateImageWidth : 0);
830 item->textOffset = item->imageOffset + infoPtr->normalImageWidth;
834 TREEVIEW_ComputeTextWidth(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item, HDC hDC)
840 /* DRAW's OM docker creates items like this */
841 if (item->pszText == NULL)
853 hdc = GetDC(infoPtr->hwnd);
854 hOldFont = SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, item));
857 GetTextExtentPoint32W(hdc, item->pszText, strlenW(item->pszText), &sz);
858 item->textWidth = sz.cx;
862 SelectObject(hdc, hOldFont);
868 TREEVIEW_ComputeItemRect(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
870 item->rect.top = infoPtr->uItemHeight *
871 (item->visibleOrder - infoPtr->firstVisible->visibleOrder);
873 item->rect.bottom = item->rect.top
874 + infoPtr->uItemHeight * item->iIntegral - 1;
877 item->rect.right = infoPtr->clientWidth;
880 /* We know that only items after start need their order updated. */
882 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *start)
889 start = infoPtr->root->firstChild;
893 order = start->visibleOrder;
895 for (item = start; item != NULL;
896 item = TREEVIEW_GetNextListItem(infoPtr, item))
898 item->visibleOrder = order;
899 order += item->iIntegral;
902 infoPtr->maxVisibleOrder = order;
904 for (item = start; item != NULL;
905 item = TREEVIEW_GetNextListItem(infoPtr, item))
907 TREEVIEW_ComputeItemRect(infoPtr, item);
912 /* Update metrics of all items in selected subtree.
913 * root must be expanded
916 TREEVIEW_UpdateSubTree(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *root)
918 TREEVIEW_ITEM *sibling;
922 if (!root->firstChild || !(root->state & TVIS_EXPANDED))
925 root->state &= ~TVIS_EXPANDED;
926 sibling = TREEVIEW_GetNextListItem(infoPtr, root);
927 root->state |= TVIS_EXPANDED;
929 hdc = GetDC(infoPtr->hwnd);
930 hOldFont = SelectObject(hdc, infoPtr->hFont);
932 for (; root != sibling;
933 root = TREEVIEW_GetNextListItem(infoPtr, root))
935 TREEVIEW_ComputeItemInternalMetrics(infoPtr, root);
937 if (root->callbackMask & TVIF_TEXT)
938 TREEVIEW_UpdateDispInfo(infoPtr, root, TVIF_TEXT);
940 if (root->textWidth == 0)
942 SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, root));
943 TREEVIEW_ComputeTextWidth(infoPtr, root, hdc);
947 SelectObject(hdc, hOldFont);
948 ReleaseDC(infoPtr->hwnd, hdc);
951 /* Item Allocation **********************************************************/
953 static TREEVIEW_ITEM *
954 TREEVIEW_AllocateItem(TREEVIEW_INFO *infoPtr)
956 TREEVIEW_ITEM *newItem = Alloc(sizeof(TREEVIEW_ITEM));
961 if (DPA_InsertPtr(infoPtr->items, INT_MAX, newItem) == -1)
970 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
971 * free item->pszText. */
973 TREEVIEW_FreeItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
975 DPA_DeletePtr(infoPtr->items, DPA_GetPtrIndex(infoPtr->items, item));
977 if (infoPtr->selectedItem == item)
978 infoPtr->selectedItem = NULL;
979 if (infoPtr->hotItem == item)
980 infoPtr->hotItem = NULL;
981 if (infoPtr->focusedItem == item)
982 infoPtr->focusedItem = NULL;
983 if (infoPtr->firstVisible == item)
984 infoPtr->firstVisible = NULL;
985 if (infoPtr->dropItem == item)
986 infoPtr->dropItem = NULL;
987 if (infoPtr->insertMarkItem == item)
988 infoPtr->insertMarkItem = NULL;
992 /* Item Insertion *******************************************************/
994 /***************************************************************************
995 * This method inserts newItem before sibling as a child of parent.
996 * sibling can be NULL, but only if parent has no children.
999 TREEVIEW_InsertBefore(TREEVIEW_ITEM *newItem, TREEVIEW_ITEM *sibling,
1000 TREEVIEW_ITEM *parent)
1002 assert(newItem != NULL);
1003 assert(parent != NULL);
1005 if (sibling != NULL)
1007 assert(sibling->parent == parent);
1009 if (sibling->prevSibling != NULL)
1010 sibling->prevSibling->nextSibling = newItem;
1012 newItem->prevSibling = sibling->prevSibling;
1013 sibling->prevSibling = newItem;
1016 newItem->prevSibling = NULL;
1018 newItem->nextSibling = sibling;
1020 if (parent->firstChild == sibling)
1021 parent->firstChild = newItem;
1023 if (parent->lastChild == NULL)
1024 parent->lastChild = newItem;
1027 /***************************************************************************
1028 * This method inserts newItem after sibling as a child of parent.
1029 * sibling can be NULL, but only if parent has no children.
1032 TREEVIEW_InsertAfter(TREEVIEW_ITEM *newItem, TREEVIEW_ITEM *sibling,
1033 TREEVIEW_ITEM *parent)
1035 assert(newItem != NULL);
1036 assert(parent != NULL);
1038 if (sibling != NULL)
1040 assert(sibling->parent == parent);
1042 if (sibling->nextSibling != NULL)
1043 sibling->nextSibling->prevSibling = newItem;
1045 newItem->nextSibling = sibling->nextSibling;
1046 sibling->nextSibling = newItem;
1049 newItem->nextSibling = NULL;
1051 newItem->prevSibling = sibling;
1053 if (parent->lastChild == sibling)
1054 parent->lastChild = newItem;
1056 if (parent->firstChild == NULL)
1057 parent->firstChild = newItem;
1061 TREEVIEW_DoSetItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
1062 const TVITEMEXW *tvItem)
1064 UINT callbackClear = 0;
1065 UINT callbackSet = 0;
1067 TRACE("item %p\n", wineItem);
1068 /* Do this first in case it fails. */
1069 if (tvItem->mask & TVIF_TEXT)
1071 wineItem->textWidth = 0; /* force width recalculation */
1072 if (tvItem->pszText != LPSTR_TEXTCALLBACKW)
1074 int len = lstrlenW(tvItem->pszText) + 1;
1075 LPWSTR newText = ReAlloc(wineItem->pszText,
1076 len * sizeof(WCHAR));
1078 if (newText == NULL) return FALSE;
1080 callbackClear |= TVIF_TEXT;
1082 wineItem->pszText = newText;
1083 wineItem->cchTextMax = len;
1084 lstrcpynW(wineItem->pszText, tvItem->pszText, len);
1085 TRACE("setting text %s, item %p\n",
1086 debugstr_w(wineItem->pszText), wineItem);
1090 callbackSet |= TVIF_TEXT;
1092 wineItem->pszText = ReAlloc(wineItem->pszText,
1093 TEXT_CALLBACK_SIZE * sizeof(WCHAR));
1094 wineItem->cchTextMax = TEXT_CALLBACK_SIZE;
1095 TRACE("setting callback, item %p\n",
1100 if (tvItem->mask & TVIF_CHILDREN)
1102 wineItem->cChildren = tvItem->cChildren;
1104 if (wineItem->cChildren == I_CHILDRENCALLBACK)
1105 callbackSet |= TVIF_CHILDREN;
1107 callbackClear |= TVIF_CHILDREN;
1110 if (tvItem->mask & TVIF_IMAGE)
1112 wineItem->iImage = tvItem->iImage;
1114 if (wineItem->iImage == I_IMAGECALLBACK)
1115 callbackSet |= TVIF_IMAGE;
1117 callbackClear |= TVIF_IMAGE;
1120 if (tvItem->mask & TVIF_SELECTEDIMAGE)
1122 wineItem->iSelectedImage = tvItem->iSelectedImage;
1124 if (wineItem->iSelectedImage == I_IMAGECALLBACK)
1125 callbackSet |= TVIF_SELECTEDIMAGE;
1127 callbackClear |= TVIF_SELECTEDIMAGE;
1130 if (tvItem->mask & TVIF_PARAM)
1131 wineItem->lParam = tvItem->lParam;
1133 /* If the application sets TVIF_INTEGRAL without
1134 * supplying a TVITEMEX structure, it's toast. */
1135 if (tvItem->mask & TVIF_INTEGRAL)
1136 wineItem->iIntegral = tvItem->iIntegral;
1138 if (tvItem->mask & TVIF_STATE)
1140 TRACE("prevstate,state,mask:%x,%x,%x\n", wineItem->state, tvItem->state,
1142 wineItem->state &= ~tvItem->stateMask;
1143 wineItem->state |= (tvItem->state & tvItem->stateMask);
1146 wineItem->callbackMask |= callbackSet;
1147 wineItem->callbackMask &= ~callbackClear;
1152 /* Note that the new item is pre-zeroed. */
1154 TREEVIEW_InsertItemW(TREEVIEW_INFO *infoPtr, LPARAM lParam)
1156 const TVINSERTSTRUCTW *ptdi = (LPTVINSERTSTRUCTW) lParam;
1157 const TVITEMEXW *tvItem = &ptdi->DUMMYUNIONNAME.itemex;
1158 HTREEITEM insertAfter;
1159 TREEVIEW_ITEM *newItem, *parentItem;
1160 BOOL bTextUpdated = FALSE;
1162 if (ptdi->hParent == TVI_ROOT || ptdi->hParent == 0)
1164 parentItem = infoPtr->root;
1168 parentItem = ptdi->hParent;
1170 if (!TREEVIEW_ValidItem(infoPtr, parentItem))
1172 WARN("invalid parent %p\n", parentItem);
1173 return (LRESULT)(HTREEITEM)NULL;
1177 insertAfter = ptdi->hInsertAfter;
1179 /* Validate this now for convenience. */
1180 switch ((DWORD)insertAfter)
1182 case (DWORD)TVI_FIRST:
1183 case (DWORD)TVI_LAST:
1184 case (DWORD)TVI_SORT:
1188 if (!TREEVIEW_ValidItem(infoPtr, insertAfter) ||
1189 insertAfter->parent != parentItem)
1191 WARN("invalid insert after %p\n", insertAfter);
1192 insertAfter = TVI_LAST;
1196 TRACE("parent %p position %p: %s\n", parentItem, insertAfter,
1197 (tvItem->mask & TVIF_TEXT)
1198 ? ((tvItem->pszText == LPSTR_TEXTCALLBACKW) ? "<callback>"
1199 : debugstr_w(tvItem->pszText))
1202 newItem = TREEVIEW_AllocateItem(infoPtr);
1203 if (newItem == NULL)
1204 return (LRESULT)(HTREEITEM)NULL;
1206 newItem->parent = parentItem;
1207 newItem->iIntegral = 1;
1209 if (!TREEVIEW_DoSetItem(infoPtr, newItem, tvItem))
1210 return (LRESULT)(HTREEITEM)NULL;
1212 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1214 infoPtr->uNumItems++;
1216 switch ((DWORD)insertAfter)
1218 case (DWORD)TVI_FIRST:
1220 TREEVIEW_ITEM *originalFirst = parentItem->firstChild;
1221 TREEVIEW_InsertBefore(newItem, parentItem->firstChild, parentItem);
1222 if (infoPtr->firstVisible == originalFirst)
1223 TREEVIEW_SetFirstVisible(infoPtr, newItem, TRUE);
1227 case (DWORD)TVI_LAST:
1228 TREEVIEW_InsertAfter(newItem, parentItem->lastChild, parentItem);
1231 /* hInsertAfter names a specific item we want to insert after */
1233 TREEVIEW_InsertAfter(newItem, insertAfter, insertAfter->parent);
1236 case (DWORD)TVI_SORT:
1238 TREEVIEW_ITEM *aChild;
1239 TREEVIEW_ITEM *previousChild = NULL;
1240 BOOL bItemInserted = FALSE;
1242 aChild = parentItem->firstChild;
1244 bTextUpdated = TRUE;
1245 TREEVIEW_UpdateDispInfo(infoPtr, newItem, TVIF_TEXT);
1247 /* Iterate the parent children to see where we fit in */
1248 while (aChild != NULL)
1252 TREEVIEW_UpdateDispInfo(infoPtr, aChild, TVIF_TEXT);
1253 comp = lstrcmpW(newItem->pszText, aChild->pszText);
1255 if (comp < 0) /* we are smaller than the current one */
1257 TREEVIEW_InsertBefore(newItem, aChild, parentItem);
1258 bItemInserted = TRUE;
1261 else if (comp > 0) /* we are bigger than the current one */
1263 previousChild = aChild;
1265 /* This will help us to exit if there is no more sibling */
1266 aChild = (aChild->nextSibling == 0)
1268 : aChild->nextSibling;
1270 /* Look at the next item */
1276 * An item with this name is already existing, therefore,
1277 * we add after the one we found
1279 TREEVIEW_InsertAfter(newItem, aChild, parentItem);
1280 bItemInserted = TRUE;
1286 * we reach the end of the child list and the item has not
1287 * yet been inserted, therefore, insert it after the last child.
1289 if ((!bItemInserted) && (aChild == NULL))
1290 TREEVIEW_InsertAfter(newItem, previousChild, parentItem);
1297 TRACE("new item %p; parent %p, mask %x\n", newItem,
1298 newItem->parent, tvItem->mask);
1300 newItem->iLevel = newItem->parent->iLevel + 1;
1302 if (newItem->parent->cChildren == 0)
1303 newItem->parent->cChildren = 1;
1305 if (infoPtr->dwStyle & TVS_CHECKBOXES)
1307 if (STATEIMAGEINDEX(newItem->state) == 0)
1308 newItem->state |= INDEXTOSTATEIMAGEMASK(1);
1311 if (infoPtr->firstVisible == NULL)
1312 infoPtr->firstVisible = newItem;
1314 TREEVIEW_VerifyTree(infoPtr);
1316 if (parentItem == infoPtr->root ||
1317 (ISVISIBLE(parentItem) && parentItem->state & TVIS_EXPANDED))
1319 TREEVIEW_ITEM *item;
1320 TREEVIEW_ITEM *prev = TREEVIEW_GetPrevListItem(infoPtr, newItem);
1322 TREEVIEW_RecalculateVisibleOrder(infoPtr, prev);
1323 TREEVIEW_ComputeItemInternalMetrics(infoPtr, newItem);
1326 TREEVIEW_UpdateDispInfo(infoPtr, newItem, TVIF_TEXT);
1328 TREEVIEW_ComputeTextWidth(infoPtr, newItem, 0);
1329 TREEVIEW_UpdateScrollBars(infoPtr);
1331 * if the item was inserted in a visible part of the tree,
1332 * invalidate it, as well as those after it
1334 for (item = newItem;
1336 item = TREEVIEW_GetNextListItem(infoPtr, item))
1337 TREEVIEW_Invalidate(infoPtr, item);
1341 newItem->visibleOrder = -1;
1343 /* refresh treeview if newItem is the first item inserted under parentItem */
1344 if (ISVISIBLE(parentItem) && newItem->prevSibling == newItem->nextSibling)
1346 /* parent got '+' - update it */
1347 TREEVIEW_Invalidate(infoPtr, parentItem);
1351 return (LRESULT)newItem;
1356 TREEVIEW_InsertItemA(TREEVIEW_INFO *infoPtr, LPARAM lParam)
1358 TVINSERTSTRUCTW tvisW;
1359 TVINSERTSTRUCTA *tvisA;
1362 tvisA = (LPTVINSERTSTRUCTA) lParam;
1364 tvisW.hParent = tvisA->hParent;
1365 tvisW.hInsertAfter = tvisA->hInsertAfter;
1367 tvisW.DUMMYUNIONNAME.item.mask = tvisA->DUMMYUNIONNAME.item.mask;
1368 tvisW.DUMMYUNIONNAME.item.hItem = tvisA->DUMMYUNIONNAME.item.hItem;
1369 tvisW.DUMMYUNIONNAME.item.state = tvisA->DUMMYUNIONNAME.item.state;
1370 tvisW.DUMMYUNIONNAME.item.stateMask = tvisA->DUMMYUNIONNAME.item.stateMask;
1371 tvisW.DUMMYUNIONNAME.item.cchTextMax =
1372 tvisA->DUMMYUNIONNAME.item.cchTextMax;
1374 if ((tvisA->DUMMYUNIONNAME.item.pszText) &&
1375 (tvisA->DUMMYUNIONNAME.item.mask & TVIF_TEXT))
1378 if (tvisA->DUMMYUNIONNAME.item.pszText != LPSTR_TEXTCALLBACKA)
1380 int len = MultiByteToWideChar( CP_ACP, 0, tvisA->DUMMYUNIONNAME.item.pszText, -1,
1382 tvisW.DUMMYUNIONNAME.item.pszText = Alloc(len * sizeof(WCHAR));
1383 MultiByteToWideChar( CP_ACP, 0, tvisA->DUMMYUNIONNAME.item.pszText, -1,
1384 tvisW.DUMMYUNIONNAME.item.pszText, len );
1388 tvisW.DUMMYUNIONNAME.item.pszText = LPSTR_TEXTCALLBACKW;
1389 tvisW.DUMMYUNIONNAME.item.cchTextMax = 0;
1393 tvisW.DUMMYUNIONNAME.item.iImage = tvisA->DUMMYUNIONNAME.item.iImage;
1394 tvisW.DUMMYUNIONNAME.item.iSelectedImage =
1395 tvisA->DUMMYUNIONNAME.item.iSelectedImage;
1396 tvisW.DUMMYUNIONNAME.item.cChildren = tvisA->DUMMYUNIONNAME.item.cChildren;
1397 tvisW.DUMMYUNIONNAME.item.lParam = tvisA->DUMMYUNIONNAME.item.lParam;
1399 lRes = TREEVIEW_InsertItemW(infoPtr, (LPARAM)&tvisW);
1401 if (tvisW.DUMMYUNIONNAME.item.pszText && tvisW.DUMMYUNIONNAME.item.pszText != LPSTR_TEXTCALLBACKW)
1403 Free(tvisW.DUMMYUNIONNAME.item.pszText);
1410 /* Item Deletion ************************************************************/
1412 TREEVIEW_RemoveItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem);
1415 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *parentItem)
1417 TREEVIEW_ITEM *kill = parentItem->firstChild;
1419 while (kill != NULL)
1421 TREEVIEW_ITEM *next = kill->nextSibling;
1423 TREEVIEW_RemoveItem(infoPtr, kill);
1428 assert(parentItem->cChildren <= 0); /* I_CHILDRENCALLBACK or 0 */
1429 assert(parentItem->firstChild == NULL);
1430 assert(parentItem->lastChild == NULL);
1434 TREEVIEW_UnlinkItem(TREEVIEW_ITEM *item)
1436 TREEVIEW_ITEM *parentItem = item->parent;
1438 assert(item != NULL);
1439 assert(item->parent != NULL); /* i.e. it must not be the root */
1441 if (parentItem->firstChild == item)
1442 parentItem->firstChild = item->nextSibling;
1444 if (parentItem->lastChild == item)
1445 parentItem->lastChild = item->prevSibling;
1447 if (parentItem->firstChild == NULL && parentItem->lastChild == NULL
1448 && parentItem->cChildren > 0)
1449 parentItem->cChildren = 0;
1451 if (item->prevSibling)
1452 item->prevSibling->nextSibling = item->nextSibling;
1454 if (item->nextSibling)
1455 item->nextSibling->prevSibling = item->prevSibling;
1459 TREEVIEW_RemoveItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
1461 TRACE("%p, (%s)\n", wineItem, TREEVIEW_ItemName(wineItem));
1463 TREEVIEW_SendTreeviewNotify(infoPtr, TVN_DELETEITEMW, TVC_UNKNOWN,
1464 TVIF_HANDLE | TVIF_PARAM, wineItem, 0);
1466 if (wineItem->firstChild)
1467 TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
1469 TREEVIEW_UnlinkItem(wineItem);
1471 infoPtr->uNumItems--;
1473 if (wineItem->pszText && wineItem->pszText != LPSTR_TEXTCALLBACKW)
1474 Free(wineItem->pszText);
1476 TREEVIEW_FreeItem(infoPtr, wineItem);
1480 /* Empty out the tree. */
1482 TREEVIEW_RemoveTree(TREEVIEW_INFO *infoPtr)
1484 TREEVIEW_RemoveAllChildren(infoPtr, infoPtr->root);
1486 assert(infoPtr->uNumItems == 0); /* root isn't counted in uNumItems */
1490 TREEVIEW_DeleteItem(TREEVIEW_INFO *infoPtr, HTREEITEM wineItem)
1492 TREEVIEW_ITEM *oldSelection = infoPtr->selectedItem;
1493 TREEVIEW_ITEM *newSelection = oldSelection;
1494 TREEVIEW_ITEM *newFirstVisible = NULL;
1495 TREEVIEW_ITEM *parent, *prev = NULL;
1496 BOOL visible = FALSE;
1498 if (wineItem == TVI_ROOT)
1500 TRACE("TVI_ROOT\n");
1501 parent = infoPtr->root;
1502 newSelection = NULL;
1504 TREEVIEW_RemoveTree(infoPtr);
1508 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
1511 TRACE("%p (%s)\n", wineItem, TREEVIEW_ItemName(wineItem));
1512 parent = wineItem->parent;
1514 if (ISVISIBLE(wineItem))
1516 prev = TREEVIEW_GetPrevListItem(infoPtr, wineItem);
1520 if (infoPtr->selectedItem != NULL
1521 && (wineItem == infoPtr->selectedItem
1522 || TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem)))
1524 if (wineItem->nextSibling)
1525 newSelection = wineItem->nextSibling;
1526 else if (wineItem->parent != infoPtr->root)
1527 newSelection = wineItem->parent;
1530 if (infoPtr->firstVisible == wineItem)
1532 if (wineItem->nextSibling)
1533 newFirstVisible = wineItem->nextSibling;
1534 else if (wineItem->prevSibling)
1535 newFirstVisible = wineItem->prevSibling;
1536 else if (wineItem->parent != infoPtr->root)
1537 newFirstVisible = wineItem->parent;
1538 TREEVIEW_SetFirstVisible(infoPtr, NULL, TRUE);
1541 newFirstVisible = infoPtr->firstVisible;
1543 TREEVIEW_RemoveItem(infoPtr, wineItem);
1546 /* Don't change if somebody else already has. */
1547 if (oldSelection == infoPtr->selectedItem)
1549 if (TREEVIEW_ValidItem(infoPtr, newSelection))
1550 TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, newSelection, TVC_UNKNOWN);
1552 infoPtr->selectedItem = 0;
1555 /* Validate insertMark dropItem.
1556 * hotItem ??? - used for comparison only.
1558 if (!TREEVIEW_ValidItem(infoPtr, infoPtr->insertMarkItem))
1559 infoPtr->insertMarkItem = 0;
1561 if (!TREEVIEW_ValidItem(infoPtr, infoPtr->dropItem))
1562 infoPtr->dropItem = 0;
1564 if (!TREEVIEW_ValidItem(infoPtr, newFirstVisible))
1565 newFirstVisible = infoPtr->root->firstChild;
1567 TREEVIEW_VerifyTree(infoPtr);
1572 TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
1573 TREEVIEW_RecalculateVisibleOrder(infoPtr, prev);
1574 TREEVIEW_UpdateScrollBars(infoPtr);
1575 TREEVIEW_Invalidate(infoPtr, NULL);
1577 else if (ISVISIBLE(parent) && !TREEVIEW_HasChildren(infoPtr, parent))
1579 /* parent lost '+/-' - update it */
1580 TREEVIEW_Invalidate(infoPtr, parent);
1587 /* Get/Set Messages *********************************************************/
1589 TREEVIEW_SetRedraw(TREEVIEW_INFO* infoPtr, WPARAM wParam, LPARAM lParam)
1592 infoPtr->bRedraw = TRUE;
1594 infoPtr->bRedraw = FALSE;
1600 TREEVIEW_GetIndent(TREEVIEW_INFO *infoPtr)
1603 return infoPtr->uIndent;
1607 TREEVIEW_SetIndent(TREEVIEW_INFO *infoPtr, UINT newIndent)
1611 if (newIndent < MINIMUM_INDENT)
1612 newIndent = MINIMUM_INDENT;
1614 if (infoPtr->uIndent != newIndent)
1616 infoPtr->uIndent = newIndent;
1617 TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
1618 TREEVIEW_UpdateScrollBars(infoPtr);
1619 TREEVIEW_Invalidate(infoPtr, NULL);
1627 TREEVIEW_GetToolTips(TREEVIEW_INFO *infoPtr)
1630 return (LRESULT)infoPtr->hwndToolTip;
1634 TREEVIEW_SetToolTips(TREEVIEW_INFO *infoPtr, HWND hwndTT)
1639 prevToolTip = infoPtr->hwndToolTip;
1640 infoPtr->hwndToolTip = hwndTT;
1642 return (LRESULT)prevToolTip;
1646 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO *infoPtr, BOOL fUnicode)
1648 BOOL rc = infoPtr->bNtfUnicode;
1649 infoPtr->bNtfUnicode = fUnicode;
1654 TREEVIEW_GetUnicodeFormat(TREEVIEW_INFO *infoPtr)
1656 return infoPtr->bNtfUnicode;
1660 TREEVIEW_GetScrollTime(TREEVIEW_INFO *infoPtr)
1662 return infoPtr->uScrollTime;
1666 TREEVIEW_SetScrollTime(TREEVIEW_INFO *infoPtr, UINT uScrollTime)
1668 UINT uOldScrollTime = infoPtr->uScrollTime;
1670 infoPtr->uScrollTime = min(uScrollTime, 100);
1672 return uOldScrollTime;
1677 TREEVIEW_GetImageList(TREEVIEW_INFO *infoPtr, WPARAM wParam)
1683 case (WPARAM)TVSIL_NORMAL:
1684 return (LRESULT)infoPtr->himlNormal;
1686 case (WPARAM)TVSIL_STATE:
1687 return (LRESULT)infoPtr->himlState;
1695 TREEVIEW_SetImageList(TREEVIEW_INFO *infoPtr, WPARAM wParam, HIMAGELIST himlNew)
1697 HIMAGELIST himlOld = 0;
1698 int oldWidth = infoPtr->normalImageWidth;
1699 int oldHeight = infoPtr->normalImageHeight;
1702 TRACE("%x,%p\n", wParam, himlNew);
1706 case (WPARAM)TVSIL_NORMAL:
1707 himlOld = infoPtr->himlNormal;
1708 infoPtr->himlNormal = himlNew;
1710 if (himlNew != NULL)
1711 ImageList_GetIconSize(himlNew, &infoPtr->normalImageWidth,
1712 &infoPtr->normalImageHeight);
1715 infoPtr->normalImageWidth = 0;
1716 infoPtr->normalImageHeight = 0;
1721 case (WPARAM)TVSIL_STATE:
1722 himlOld = infoPtr->himlState;
1723 infoPtr->himlState = himlNew;
1725 if (himlNew != NULL)
1726 ImageList_GetIconSize(himlNew, &infoPtr->stateImageWidth,
1727 &infoPtr->stateImageHeight);
1730 infoPtr->stateImageWidth = 0;
1731 infoPtr->stateImageHeight = 0;
1737 if (oldWidth != infoPtr->normalImageWidth ||
1738 oldHeight != infoPtr->normalImageHeight)
1740 TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
1741 TREEVIEW_UpdateScrollBars(infoPtr);
1744 TREEVIEW_Invalidate(infoPtr, NULL);
1746 return (LRESULT)himlOld;
1749 /* Compute the natural height (based on the font size) for items. */
1751 TREEVIEW_NaturalHeight(TREEVIEW_INFO *infoPtr)
1755 HFONT hOldFont = SelectObject(hdc, infoPtr->hFont);
1757 GetTextMetricsW(hdc, &tm);
1759 SelectObject(hdc, hOldFont);
1762 /* The 16 is a hack because our fonts are tiny. */
1763 /* add 2 for the focus border and 1 more for margin some apps assume */
1764 return max(16, tm.tmHeight + tm.tmExternalLeading + 3);
1768 TREEVIEW_SetItemHeight(TREEVIEW_INFO *infoPtr, INT newHeight)
1770 INT prevHeight = infoPtr->uItemHeight;
1772 TRACE("%d \n", newHeight);
1773 if (newHeight == -1)
1775 infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
1776 infoPtr->bHeightSet = FALSE;
1780 infoPtr->uItemHeight = newHeight;
1781 infoPtr->bHeightSet = TRUE;
1784 /* Round down, unless we support odd ("non even") heights. */
1785 if (!(infoPtr->dwStyle) & TVS_NONEVENHEIGHT)
1786 infoPtr->uItemHeight &= ~1;
1788 if (infoPtr->uItemHeight != prevHeight)
1790 TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
1791 TREEVIEW_UpdateScrollBars(infoPtr);
1792 TREEVIEW_Invalidate(infoPtr, NULL);
1799 TREEVIEW_GetItemHeight(TREEVIEW_INFO *infoPtr)
1802 return infoPtr->uItemHeight;
1807 TREEVIEW_GetFont(TREEVIEW_INFO *infoPtr)
1809 TRACE("%p\n", infoPtr->hFont);
1810 return (LRESULT)infoPtr->hFont;
1815 TREEVIEW_ResetTextWidth(LPVOID pItem, LPVOID unused)
1819 ((TREEVIEW_ITEM *)pItem)->textWidth = 0;
1825 TREEVIEW_SetFont(TREEVIEW_INFO *infoPtr, HFONT hFont, BOOL bRedraw)
1827 UINT uHeight = infoPtr->uItemHeight;
1829 TRACE("%p %i\n", hFont, bRedraw);
1831 infoPtr->hFont = hFont ? hFont : GetStockObject(SYSTEM_FONT);
1833 DeleteObject(infoPtr->hBoldFont);
1834 infoPtr->hBoldFont = TREEVIEW_CreateBoldFont(infoPtr->hFont);
1836 if (!infoPtr->bHeightSet)
1837 infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
1839 if (uHeight != infoPtr->uItemHeight)
1840 TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
1842 DPA_EnumCallback(infoPtr->items, TREEVIEW_ResetTextWidth, 0);
1844 TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
1845 TREEVIEW_UpdateScrollBars(infoPtr);
1848 TREEVIEW_Invalidate(infoPtr, NULL);
1855 TREEVIEW_GetLineColor(TREEVIEW_INFO *infoPtr)
1858 return (LRESULT)infoPtr->clrLine;
1862 TREEVIEW_SetLineColor(TREEVIEW_INFO *infoPtr, COLORREF color)
1864 COLORREF prevColor = infoPtr->clrLine;
1867 infoPtr->clrLine = color;
1868 return (LRESULT)prevColor;
1873 TREEVIEW_GetTextColor(TREEVIEW_INFO *infoPtr)
1876 return (LRESULT)infoPtr->clrText;
1880 TREEVIEW_SetTextColor(TREEVIEW_INFO *infoPtr, COLORREF color)
1882 COLORREF prevColor = infoPtr->clrText;
1885 infoPtr->clrText = color;
1887 if (infoPtr->clrText != prevColor)
1888 TREEVIEW_Invalidate(infoPtr, NULL);
1890 return (LRESULT)prevColor;
1895 TREEVIEW_GetBkColor(TREEVIEW_INFO *infoPtr)
1898 return (LRESULT)infoPtr->clrBk;
1902 TREEVIEW_SetBkColor(TREEVIEW_INFO *infoPtr, COLORREF newColor)
1904 COLORREF prevColor = infoPtr->clrBk;
1907 infoPtr->clrBk = newColor;
1909 if (newColor != prevColor)
1910 TREEVIEW_Invalidate(infoPtr, NULL);
1912 return (LRESULT)prevColor;
1917 TREEVIEW_GetInsertMarkColor(TREEVIEW_INFO *infoPtr)
1920 return (LRESULT)infoPtr->clrInsertMark;
1924 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO *infoPtr, COLORREF color)
1926 COLORREF prevColor = infoPtr->clrInsertMark;
1928 TRACE("%lx\n", color);
1929 infoPtr->clrInsertMark = color;
1931 return (LRESULT)prevColor;
1936 TREEVIEW_SetInsertMark(TREEVIEW_INFO *infoPtr, BOOL wParam, HTREEITEM item)
1938 TRACE("%d %p\n", wParam, item);
1940 if (!TREEVIEW_ValidItem(infoPtr, item))
1943 infoPtr->insertBeforeorAfter = wParam;
1944 infoPtr->insertMarkItem = item;
1946 TREEVIEW_Invalidate(infoPtr, NULL);
1952 /************************************************************************
1953 * Some serious braindamage here. lParam is a pointer to both the
1954 * input HTREEITEM and the output RECT.
1957 TREEVIEW_GetItemRect(TREEVIEW_INFO *infoPtr, BOOL fTextRect, LPRECT lpRect)
1959 TREEVIEW_ITEM *wineItem;
1960 const HTREEITEM *pItem = (HTREEITEM *)lpRect;
1964 * validate parameters
1970 if (!TREEVIEW_ValidItem(infoPtr, wineItem) || !ISVISIBLE(wineItem))
1974 * If wParam is TRUE return the text size otherwise return
1975 * the whole item size
1979 /* Windows does not send TVN_GETDISPINFO here. */
1981 lpRect->top = wineItem->rect.top;
1982 lpRect->bottom = wineItem->rect.bottom;
1984 lpRect->left = wineItem->textOffset;
1985 lpRect->right = wineItem->textOffset + wineItem->textWidth;
1989 *lpRect = wineItem->rect;
1992 TRACE("%s [L:%ld R:%ld T:%ld B:%ld]\n", fTextRect ? "text" : "item",
1993 lpRect->left, lpRect->right, lpRect->top, lpRect->bottom);
1998 static inline LRESULT
1999 TREEVIEW_GetVisibleCount(TREEVIEW_INFO *infoPtr)
2001 /* Suprise! This does not take integral height into account. */
2002 return infoPtr->clientHeight / infoPtr->uItemHeight;
2007 TREEVIEW_GetItemT(TREEVIEW_INFO *infoPtr, LPTVITEMEXW tvItem, BOOL isW)
2009 TREEVIEW_ITEM *wineItem;
2011 wineItem = tvItem->hItem;
2012 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
2015 TREEVIEW_UpdateDispInfo(infoPtr, wineItem, tvItem->mask);
2017 if (tvItem->mask & TVIF_CHILDREN)
2019 if (TVIF_CHILDREN==I_CHILDRENCALLBACK)
2020 FIXME("I_CHILDRENCALLBACK not supported\n");
2021 tvItem->cChildren = wineItem->cChildren;
2024 if (tvItem->mask & TVIF_HANDLE)
2025 tvItem->hItem = wineItem;
2027 if (tvItem->mask & TVIF_IMAGE)
2028 tvItem->iImage = wineItem->iImage;
2030 if (tvItem->mask & TVIF_INTEGRAL)
2031 tvItem->iIntegral = wineItem->iIntegral;
2033 /* undocumented: windows ignores TVIF_PARAM and
2034 * * always sets lParam
2036 tvItem->lParam = wineItem->lParam;
2038 if (tvItem->mask & TVIF_SELECTEDIMAGE)
2039 tvItem->iSelectedImage = wineItem->iSelectedImage;
2041 if (tvItem->mask & TVIF_STATE)
2042 /* Careful here - Windows ignores the stateMask when you get the state
2043 That contradicts the documentation, but makes more common sense, masking
2044 retrieval in this way seems overkill */
2045 tvItem->state = wineItem->state;
2047 if (tvItem->mask & TVIF_TEXT)
2051 if (wineItem->pszText == LPSTR_TEXTCALLBACKW)
2053 tvItem->pszText = LPSTR_TEXTCALLBACKW;
2054 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2058 lstrcpynW(tvItem->pszText, wineItem->pszText, tvItem->cchTextMax);
2063 if (wineItem->pszText == LPSTR_TEXTCALLBACKW)
2065 tvItem->pszText = (LPWSTR)LPSTR_TEXTCALLBACKA;
2066 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2070 WideCharToMultiByte(CP_ACP, 0, wineItem->pszText, -1,
2071 (LPSTR)tvItem->pszText, tvItem->cchTextMax, NULL, NULL);
2075 TRACE("item <%p>, txt %p, img %p, mask %x\n",
2076 wineItem, tvItem->pszText, &tvItem->iImage, tvItem->mask);
2081 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2082 * which is wrong. */
2084 TREEVIEW_SetItemW(TREEVIEW_INFO *infoPtr, LPTVITEMEXW tvItem)
2086 TREEVIEW_ITEM *wineItem;
2087 TREEVIEW_ITEM originalItem;
2089 wineItem = tvItem->hItem;
2091 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr, wineItem),
2094 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
2097 /* store the orignal item values */
2098 originalItem = *wineItem;
2100 if (!TREEVIEW_DoSetItem(infoPtr, wineItem, tvItem))
2103 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2104 if ((tvItem->mask & TVIF_TEXT
2105 || (tvItem->mask & TVIF_STATE && tvItem->stateMask & TVIS_BOLD))
2106 && ISVISIBLE(wineItem))
2108 TREEVIEW_UpdateDispInfo(infoPtr, wineItem, TVIF_TEXT);
2109 TREEVIEW_ComputeTextWidth(infoPtr, wineItem, 0);
2112 if (tvItem->mask != 0 && ISVISIBLE(wineItem))
2114 /* The refresh updates everything, but we can't wait until then. */
2115 TREEVIEW_ComputeItemInternalMetrics(infoPtr, wineItem);
2117 /* if any of the items values changed, redraw the item */
2118 if(memcmp(&originalItem, wineItem, sizeof(TREEVIEW_ITEM)) ||
2119 (tvItem->stateMask & TVIS_BOLD))
2121 if (tvItem->mask & TVIF_INTEGRAL)
2123 TREEVIEW_RecalculateVisibleOrder(infoPtr, wineItem);
2124 TREEVIEW_UpdateScrollBars(infoPtr);
2126 TREEVIEW_Invalidate(infoPtr, NULL);
2130 TREEVIEW_UpdateScrollBars(infoPtr);
2131 TREEVIEW_Invalidate(infoPtr, wineItem);
2140 TREEVIEW_SetItemA(TREEVIEW_INFO *infoPtr, LPTVITEMEXA tvItem)
2146 tvItemW.mask = tvItem->mask;
2147 tvItemW.hItem = tvItem->hItem;
2148 tvItemW.state = tvItem->state;
2149 tvItemW.stateMask = tvItem->stateMask;
2150 tvItemW.cchTextMax = 0;
2151 tvItemW.pszText = 0;
2153 if (tvItem->mask & TVIF_TEXT)
2155 if(tvItem->pszText && tvItem->pszText != LPSTR_TEXTCALLBACKA)
2157 len = MultiByteToWideChar(CP_ACP, 0, tvItem->pszText, -1,
2161 tvItemW.pszText = Alloc(len*sizeof(WCHAR));
2162 MultiByteToWideChar(CP_ACP, 0, tvItem->pszText, -1,
2163 tvItemW.pszText ,len);
2164 tvItemW.cchTextMax = len;
2167 else if(tvItem->pszText == LPSTR_TEXTCALLBACKA)
2168 tvItemW.pszText = LPSTR_TEXTCALLBACKW;
2171 tvItemW.iImage = tvItem->iImage;
2172 tvItemW.iSelectedImage = tvItem->iSelectedImage;
2173 tvItemW.cChildren = tvItem->cChildren;
2174 tvItemW.lParam = tvItem->lParam;
2175 tvItemW.iIntegral = tvItem->iIntegral;
2177 rc = TREEVIEW_SetItemW(infoPtr,&tvItemW);
2178 if(tvItemW.pszText && tvItemW.pszText != LPSTR_TEXTCALLBACKW)
2179 Free(tvItemW.pszText);
2184 TREEVIEW_GetItemState(TREEVIEW_INFO *infoPtr, HTREEITEM wineItem, UINT mask)
2188 if (!wineItem || !TREEVIEW_ValidItem(infoPtr, wineItem))
2191 return (wineItem->state & mask);
2195 TREEVIEW_GetNextItem(TREEVIEW_INFO *infoPtr, UINT which, HTREEITEM wineItem)
2197 TREEVIEW_ITEM *retval;
2201 /* handle all the global data here */
2204 case TVGN_CHILD: /* Special case: child of 0 is root */
2209 retval = infoPtr->root->firstChild;
2213 retval = infoPtr->selectedItem;
2216 case TVGN_FIRSTVISIBLE:
2217 retval = infoPtr->firstVisible;
2220 case TVGN_DROPHILITE:
2221 retval = infoPtr->dropItem;
2224 case TVGN_LASTVISIBLE:
2225 retval = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
2231 TRACE("flags:%x, returns %p\n", which, retval);
2232 return (LRESULT)retval;
2235 if (wineItem == TVI_ROOT) wineItem = infoPtr->root;
2237 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
2243 retval = wineItem->nextSibling;
2246 retval = wineItem->prevSibling;
2249 retval = (wineItem->parent != infoPtr->root) ? wineItem->parent : NULL;
2252 retval = wineItem->firstChild;
2254 case TVGN_NEXTVISIBLE:
2255 retval = TREEVIEW_GetNextListItem(infoPtr, wineItem);
2257 case TVGN_PREVIOUSVISIBLE:
2258 retval = TREEVIEW_GetPrevListItem(infoPtr, wineItem);
2261 TRACE("Unknown msg %x,item %p\n", which, wineItem);
2265 TRACE("flags:%x, item %p;returns %p\n", which, wineItem, retval);
2266 return (LRESULT)retval;
2271 TREEVIEW_GetCount(TREEVIEW_INFO *infoPtr)
2273 TRACE(" %d\n", infoPtr->uNumItems);
2274 return (LRESULT)infoPtr->uNumItems;
2278 TREEVIEW_ToggleItemState(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
2280 if (infoPtr->dwStyle & TVS_CHECKBOXES)
2282 static const unsigned int state_table[] = { 0, 2, 1 };
2286 state = STATEIMAGEINDEX(item->state);
2287 TRACE("state:%x\n", state);
2288 item->state &= ~TVIS_STATEIMAGEMASK;
2291 state = state_table[state];
2293 item->state |= INDEXTOSTATEIMAGEMASK(state);
2295 TRACE("state:%x\n", state);
2296 TREEVIEW_Invalidate(infoPtr, item);
2301 /* Painting *************************************************************/
2303 /* Draw the lines and expand button for an item. Also draws one section
2304 * of the line from item's parent to item's parent's next sibling. */
2306 TREEVIEW_DrawItemLines(TREEVIEW_INFO *infoPtr, HDC hdc, TREEVIEW_ITEM *item)
2308 LONG centerx, centery;
2309 BOOL lar = ((infoPtr->dwStyle
2310 & (TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS))
2313 if (!lar && item->iLevel == 0)
2316 centerx = (item->linesOffset + item->stateOffset) / 2;
2317 centery = (item->rect.top + item->rect.bottom) / 2;
2319 if (infoPtr->dwStyle & TVS_HASLINES)
2321 HPEN hOldPen, hNewPen;
2325 * Get a dotted grey pen
2327 hNewPen = CreatePen(PS_ALTERNATE, 0, infoPtr->clrLine);
2328 hOldPen = SelectObject(hdc, hNewPen);
2330 MoveToEx(hdc, item->stateOffset, centery, NULL);
2331 LineTo(hdc, centerx - 1, centery);
2333 if (item->prevSibling || item->parent != infoPtr->root)
2335 MoveToEx(hdc, centerx, item->rect.top, NULL);
2336 LineTo(hdc, centerx, centery);
2339 if (item->nextSibling)
2341 MoveToEx(hdc, centerx, centery, NULL);
2342 LineTo(hdc, centerx, item->rect.bottom + 1);
2345 /* Draw the line from our parent to its next sibling. */
2346 parent = item->parent;
2347 while (parent != infoPtr->root)
2349 int pcenterx = (parent->linesOffset + parent->stateOffset) / 2;
2351 if (parent->nextSibling
2352 /* skip top-levels unless TVS_LINESATROOT */
2353 && parent->stateOffset > parent->linesOffset)
2355 MoveToEx(hdc, pcenterx, item->rect.top, NULL);
2356 LineTo(hdc, pcenterx, item->rect.bottom + 1);
2359 parent = parent->parent;
2362 SelectObject(hdc, hOldPen);
2363 DeleteObject(hNewPen);
2367 * Display the (+/-) signs
2370 if (infoPtr->dwStyle & TVS_HASBUTTONS)
2372 if (item->cChildren)
2374 LONG height = item->rect.bottom - item->rect.top;
2375 LONG width = item->stateOffset - item->linesOffset;
2376 LONG rectsize = min(height, width) / 4;
2377 /* plussize = ceil(rectsize * 3/4) */
2378 LONG plussize = (rectsize + 1) * 3 / 4;
2380 HPEN hNewPen = CreatePen(PS_SOLID, 0, infoPtr->clrLine);
2381 HPEN hOldPen = SelectObject(hdc, hNewPen);
2382 HBRUSH hbr = CreateSolidBrush(infoPtr->clrBk);
2383 HBRUSH hbrOld = SelectObject(hdc, hbr);
2385 Rectangle(hdc, centerx - rectsize, centery - rectsize,
2386 centerx + rectsize + 1, centery + rectsize + 1);
2388 SelectObject(hdc, hbrOld);
2391 SelectObject(hdc, hOldPen);
2392 DeleteObject(hNewPen);
2394 MoveToEx(hdc, centerx - plussize + 1, centery, NULL);
2395 LineTo(hdc, centerx + plussize, centery);
2397 if (!(item->state & TVIS_EXPANDED))
2399 MoveToEx(hdc, centerx, centery - plussize + 1, NULL);
2400 LineTo(hdc, centerx, centery + plussize);
2407 TREEVIEW_DrawItem(TREEVIEW_INFO *infoPtr, HDC hdc, TREEVIEW_ITEM *wineItem)
2413 hOldFont = SelectObject(hdc, TREEVIEW_FontForItem(infoPtr, wineItem));
2415 TREEVIEW_UpdateDispInfo(infoPtr, wineItem, CALLBACK_MASK_ALL);
2417 /* The custom draw handler can query the text rectangle,
2419 TREEVIEW_ComputeTextWidth(infoPtr, wineItem, hdc);
2423 if (infoPtr->cdmode & CDRF_NOTIFYITEMDRAW)
2425 cditem = TREEVIEW_SendCustomDrawItemNotify
2426 (infoPtr, hdc, wineItem, CDDS_ITEMPREPAINT);
2427 TRACE("prepaint:cditem-app returns 0x%x\n", cditem);
2429 if (cditem & CDRF_SKIPDEFAULT)
2431 SelectObject(hdc, hOldFont);
2436 if (cditem & CDRF_NEWFONT)
2437 TREEVIEW_ComputeTextWidth(infoPtr, wineItem, hdc);
2439 TREEVIEW_DrawItemLines(infoPtr, hdc, wineItem);
2441 centery = (wineItem->rect.top + wineItem->rect.bottom) / 2;
2444 * Display the images associated with this item
2449 /* State images are displayed to the left of the Normal image
2450 * image number is in state; zero should be `display no image'.
2452 imageIndex = STATEIMAGEINDEX(wineItem->state);
2454 if (infoPtr->himlState && imageIndex)
2456 ImageList_Draw(infoPtr->himlState, imageIndex, hdc,
2457 wineItem->stateOffset,
2458 centery - infoPtr->stateImageHeight / 2,
2462 /* Now, draw the normal image; can be either selected or
2463 * non-selected image.
2466 if ((wineItem->state & TVIS_SELECTED) && (wineItem->iSelectedImage))
2468 /* The item is currently selected */
2469 imageIndex = wineItem->iSelectedImage;
2473 /* The item is not selected */
2474 imageIndex = wineItem->iImage;
2477 if (infoPtr->himlNormal)
2479 int ovlIdx = wineItem->state & TVIS_OVERLAYMASK;
2481 ImageList_Draw(infoPtr->himlNormal, imageIndex, hdc,
2482 wineItem->imageOffset,
2483 centery - infoPtr->normalImageHeight / 2,
2484 ILD_NORMAL | ovlIdx);
2490 * Display the text associated with this item
2493 /* Don't paint item's text if it's being edited */
2494 if (!infoPtr->hwndEdit || (infoPtr->selectedItem != wineItem))
2496 if (wineItem->pszText)
2498 COLORREF oldTextColor = 0;
2501 BOOL inFocus = (GetFocus() == infoPtr->hwnd);
2504 oldBkMode = SetBkMode(hdc, TRANSPARENT);
2506 /* - If item is drop target or it is selected and window is in focus -
2507 * use blue background (COLOR_HIGHLIGHT).
2508 * - If item is selected, window is not in focus, but it has style
2509 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2510 * - Otherwise - don't fill background
2512 if ((wineItem->state & TVIS_DROPHILITED) || ((wineItem == infoPtr->focusedItem) && !(wineItem->state & TVIS_SELECTED)) ||
2513 ((wineItem->state & TVIS_SELECTED) && (!infoPtr->focusedItem) &&
2514 (inFocus || (infoPtr->dwStyle & TVS_SHOWSELALWAYS))))
2516 if ((wineItem->state & TVIS_DROPHILITED) || inFocus)
2518 hbrBk = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
2520 SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
2524 hbrBk = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
2526 if (infoPtr->clrText == -1)
2528 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
2530 oldTextColor = SetTextColor(hdc, infoPtr->clrText);
2535 if (infoPtr->clrText == -1)
2537 SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
2539 oldTextColor = SetTextColor(hdc, infoPtr->clrText);
2542 rcText.top = wineItem->rect.top;
2543 rcText.bottom = wineItem->rect.bottom;
2544 rcText.left = wineItem->textOffset;
2545 rcText.right = rcText.left + wineItem->textWidth + 4;
2549 FillRect(hdc, &rcText, hbrBk);
2550 DeleteObject(hbrBk);
2553 /* Draw the box around the selected item */
2554 if ((wineItem == infoPtr->selectedItem) && inFocus)
2556 DrawFocusRect(hdc,&rcText);
2559 InflateRect(&rcText, -2, -1); /* allow for the focus rect */
2561 TRACE("drawing text %s at (%ld,%ld)-(%ld,%ld)\n",
2562 debugstr_w(wineItem->pszText),
2563 rcText.left, rcText.top, rcText.right, rcText.bottom);
2568 lstrlenW(wineItem->pszText),
2570 DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
2572 /* Restore the hdc state */
2573 SetTextColor(hdc, oldTextColor);
2575 if (oldBkMode != TRANSPARENT)
2576 SetBkMode(hdc, oldBkMode);
2580 /* Draw insertion mark if necessary */
2582 if (infoPtr->insertMarkItem)
2583 TRACE("item:%d,mark:%d\n",
2584 TREEVIEW_GetItemIndex(infoPtr, wineItem),
2585 (int)infoPtr->insertMarkItem);
2587 if (wineItem == infoPtr->insertMarkItem)
2589 HPEN hNewPen, hOldPen;
2593 hNewPen = CreatePen(PS_SOLID, 2, infoPtr->clrInsertMark);
2594 hOldPen = SelectObject(hdc, hNewPen);
2596 if (infoPtr->insertBeforeorAfter)
2597 offset = wineItem->rect.bottom - 1;
2599 offset = wineItem->rect.top + 1;
2601 left = wineItem->textOffset - 2;
2602 right = wineItem->textOffset + wineItem->textWidth + 2;
2604 MoveToEx(hdc, left, offset - 3, NULL);
2605 LineTo(hdc, left, offset + 4);
2607 MoveToEx(hdc, left, offset, NULL);
2608 LineTo(hdc, right + 1, offset);
2610 MoveToEx(hdc, right, offset + 3, NULL);
2611 LineTo(hdc, right, offset - 4);
2613 SelectObject(hdc, hOldPen);
2614 DeleteObject(hNewPen);
2617 if (cditem & CDRF_NOTIFYPOSTPAINT)
2619 cditem = TREEVIEW_SendCustomDrawItemNotify
2620 (infoPtr, hdc, wineItem, CDDS_ITEMPOSTPAINT);
2621 TRACE("postpaint:cditem-app returns 0x%x\n", cditem);
2624 SelectObject(hdc, hOldFont);
2627 /* Computes treeHeight and treeWidth and updates the scroll bars.
2630 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO *infoPtr)
2632 TREEVIEW_ITEM *wineItem;
2633 HWND hwnd = infoPtr->hwnd;
2637 LONG scrollX = infoPtr->scrollX;
2639 infoPtr->treeWidth = 0;
2640 infoPtr->treeHeight = 0;
2642 /* We iterate through all visible items in order to get the tree height
2644 wineItem = infoPtr->root->firstChild;
2646 while (wineItem != NULL)
2648 if (ISVISIBLE(wineItem))
2650 /* actually we draw text at textOffset + 2 */
2651 if (2+wineItem->textOffset+wineItem->textWidth > infoPtr->treeWidth)
2652 infoPtr->treeWidth = wineItem->textOffset+wineItem->textWidth+2;
2654 /* This is scroll-adjusted, but we fix this below. */
2655 infoPtr->treeHeight = wineItem->rect.bottom;
2658 wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem);
2661 /* Fix the scroll adjusted treeHeight and treeWidth. */
2662 if (infoPtr->root->firstChild)
2663 infoPtr->treeHeight -= infoPtr->root->firstChild->rect.top;
2665 infoPtr->treeWidth += infoPtr->scrollX;
2667 if (infoPtr->dwStyle & TVS_NOSCROLL) return;
2669 /* Adding one scroll bar may take up enough space that it forces us
2670 * to add the other as well. */
2671 if (infoPtr->treeHeight > infoPtr->clientHeight)
2675 if (infoPtr->treeWidth
2676 > infoPtr->clientWidth - GetSystemMetrics(SM_CXVSCROLL))
2679 else if (infoPtr->treeWidth > infoPtr->clientWidth)
2682 if (!vert && horz && infoPtr->treeHeight
2683 > infoPtr->clientHeight - GetSystemMetrics(SM_CYVSCROLL))
2686 if (horz && (infoPtr->dwStyle & TVS_NOHSCROLL)) horz = FALSE;
2688 si.cbSize = sizeof(SCROLLINFO);
2689 si.fMask = SIF_POS|SIF_RANGE|SIF_PAGE;
2694 si.nPage = TREEVIEW_GetVisibleCount(infoPtr);
2697 si.nPos = infoPtr->firstVisible->visibleOrder;
2698 si.nMax = infoPtr->maxVisibleOrder - 1;
2700 SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
2702 if (!(infoPtr->uInternalStatus & TV_VSCROLL))
2703 ShowScrollBar(hwnd, SB_VERT, TRUE);
2704 infoPtr->uInternalStatus |= TV_VSCROLL;
2708 if (infoPtr->uInternalStatus & TV_VSCROLL)
2709 ShowScrollBar(hwnd, SB_VERT, FALSE);
2710 infoPtr->uInternalStatus &= ~TV_VSCROLL;
2715 if (infoPtr->uInternalStatus & TV_VSCROLL)
2716 ShowScrollBar(hwnd, SB_VERT, FALSE);
2717 infoPtr->uInternalStatus &= ~TV_VSCROLL;
2722 si.nPage = infoPtr->clientWidth;
2723 si.nPos = infoPtr->scrollX;
2724 si.nMax = infoPtr->treeWidth - 1;
2726 if (si.nPos > si.nMax - max( si.nPage-1, 0 ))
2728 si.nPos = si.nMax - max( si.nPage-1, 0 );
2732 if (!(infoPtr->uInternalStatus & TV_HSCROLL))
2733 ShowScrollBar(hwnd, SB_HORZ, TRUE);
2734 infoPtr->uInternalStatus |= TV_HSCROLL;
2736 SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
2740 if (infoPtr->uInternalStatus & TV_HSCROLL)
2741 ShowScrollBar(hwnd, SB_HORZ, FALSE);
2742 infoPtr->uInternalStatus &= ~TV_HSCROLL;
2747 if (infoPtr->scrollX != scrollX)
2749 TREEVIEW_HScroll(infoPtr,
2750 MAKEWPARAM(SB_THUMBPOSITION, scrollX));
2754 infoPtr->uInternalStatus &= ~TV_HSCROLL;
2757 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2759 TREEVIEW_EraseBackground(TREEVIEW_INFO *infoPtr, HDC hDC)
2761 HBRUSH hBrush = CreateSolidBrush(infoPtr->clrBk);
2764 GetClientRect(infoPtr->hwnd, &rect);
2765 FillRect(hDC, &rect, hBrush);
2766 DeleteObject(hBrush);
2772 TREEVIEW_Refresh(TREEVIEW_INFO *infoPtr, HDC hdc, RECT *rc)
2774 HWND hwnd = infoPtr->hwnd;
2776 TREEVIEW_ITEM *wineItem;
2778 if (infoPtr->clientHeight == 0 || infoPtr->clientWidth == 0)
2780 TRACE("empty window\n");
2784 infoPtr->cdmode = TREEVIEW_SendCustomDrawNotify(infoPtr, CDDS_PREPAINT,
2787 if (infoPtr->cdmode == CDRF_SKIPDEFAULT)
2789 ReleaseDC(hwnd, hdc);
2793 for (wineItem = infoPtr->root->firstChild;
2795 wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem))
2797 if (ISVISIBLE(wineItem))
2799 /* Avoid unneeded calculations */
2800 if (wineItem->rect.top > rect.bottom)
2802 if (wineItem->rect.bottom < rect.top)
2805 TREEVIEW_DrawItem(infoPtr, hdc, wineItem);
2809 TREEVIEW_UpdateScrollBars(infoPtr);
2811 if (infoPtr->cdmode & CDRF_NOTIFYPOSTPAINT)
2813 TREEVIEW_SendCustomDrawNotify(infoPtr, CDDS_POSTPAINT, hdc, rect);
2817 TREEVIEW_Invalidate(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
2820 InvalidateRect(infoPtr->hwnd, &item->rect, TRUE);
2822 InvalidateRect(infoPtr->hwnd, NULL, TRUE);
2826 TREEVIEW_Paint(TREEVIEW_INFO *infoPtr, WPARAM wParam)
2837 if (!GetUpdateRect(infoPtr->hwnd, &rc, TRUE))
2841 hbitmap = GetCurrentObject(hdc, OBJ_BITMAP);
2842 if (!hbitmap) return 0;
2843 GetObjectA(hbitmap, sizeof(BITMAP), &bitmap);
2844 rc.left = 0; rc.top = 0;
2845 rc.right = bitmap.bmWidth;
2846 rc.bottom = bitmap.bmHeight;
2847 TREEVIEW_EraseBackground(infoPtr, (HDC)wParam);
2852 hdc = BeginPaint(infoPtr->hwnd, &ps);
2856 if(infoPtr->bRedraw) /* WM_SETREDRAW sets bRedraw */
2857 TREEVIEW_Refresh(infoPtr, hdc, &rc);
2860 EndPaint(infoPtr->hwnd, &ps);
2866 /* Sorting **************************************************************/
2868 /***************************************************************************
2869 * Forward the DPA local callback to the treeview owner callback
2872 TREEVIEW_CallBackCompare(TREEVIEW_ITEM *first, TREEVIEW_ITEM *second, LPTVSORTCB pCallBackSort)
2874 /* Forward the call to the client-defined callback */
2875 return pCallBackSort->lpfnCompare(first->lParam,
2877 pCallBackSort->lParam);
2880 /***************************************************************************
2881 * Treeview native sort routine: sort on item text.
2884 TREEVIEW_SortOnName(TREEVIEW_ITEM *first, TREEVIEW_ITEM *second,
2885 TREEVIEW_INFO *infoPtr)
2887 TREEVIEW_UpdateDispInfo(infoPtr, first, TVIF_TEXT);
2888 TREEVIEW_UpdateDispInfo(infoPtr, second, TVIF_TEXT);
2890 if(first->pszText && second->pszText)
2891 return lstrcmpiW(first->pszText, second->pszText);
2892 else if(first->pszText)
2894 else if(second->pszText)
2900 /* Returns the number of physical children belonging to item. */
2902 TREEVIEW_CountChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
2907 for (hti = item->firstChild; hti != NULL; hti = hti->nextSibling)
2913 /* Returns a DPA containing a pointer to each physical child of item in
2914 * sibling order. If item has no children, an empty DPA is returned. */
2916 TREEVIEW_BuildChildDPA(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
2918 HTREEITEM child = item->firstChild;
2920 HDPA list = DPA_Create(8);
2921 if (list == 0) return NULL;
2923 for (child = item->firstChild; child != NULL; child = child->nextSibling)
2925 if (DPA_InsertPtr(list, INT_MAX, child) == -1)
2935 /***************************************************************************
2936 * Setup the treeview structure with regards of the sort method
2937 * and sort the children of the TV item specified in lParam
2938 * fRecurse: currently unused. Should be zero.
2939 * parent: if pSort!=NULL, should equal pSort->hParent.
2940 * otherwise, item which child items are to be sorted.
2941 * pSort: sort method info. if NULL, sort on item text.
2942 * if non-NULL, sort on item's lParam content, and let the
2943 * application decide what that means. See also TVM_SORTCHILDRENCB.
2947 TREEVIEW_Sort(TREEVIEW_INFO *infoPtr, BOOL fRecurse, HTREEITEM parent,
2951 PFNDPACOMPARE pfnCompare;
2954 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
2955 if (parent == TVI_ROOT || parent == NULL)
2956 parent = infoPtr->root;
2958 /* Check for a valid handle to the parent item */
2959 if (!TREEVIEW_ValidItem(infoPtr, parent))
2961 ERR("invalid item hParent=%x\n", (INT)parent);
2967 pfnCompare = (PFNDPACOMPARE)TREEVIEW_CallBackCompare;
2968 lpCompare = (LPARAM)pSort;
2972 pfnCompare = (PFNDPACOMPARE)TREEVIEW_SortOnName;
2973 lpCompare = (LPARAM)infoPtr;
2976 cChildren = TREEVIEW_CountChildren(infoPtr, parent);
2978 /* Make sure there is something to sort */
2981 /* TREEVIEW_ITEM rechaining */
2984 HTREEITEM nextItem = 0;
2985 HTREEITEM prevItem = 0;
2987 HDPA sortList = TREEVIEW_BuildChildDPA(infoPtr, parent);
2989 if (sortList == NULL)
2992 /* let DPA sort the list */
2993 DPA_Sort(sortList, pfnCompare, lpCompare);
2995 /* The order of DPA entries has been changed, so fixup the
2996 * nextSibling and prevSibling pointers. */
2998 item = (HTREEITEM)DPA_GetPtr(sortList, count++);
2999 while ((nextItem = (HTREEITEM)DPA_GetPtr(sortList, count++)) != NULL)
3001 /* link the two current item toghether */
3002 item->nextSibling = nextItem;
3003 nextItem->prevSibling = item;
3005 if (prevItem == NULL)
3007 /* this is the first item, update the parent */
3008 parent->firstChild = item;
3009 item->prevSibling = NULL;
3013 /* fix the back chaining */
3014 item->prevSibling = prevItem;
3017 /* get ready for the next one */
3022 /* the last item is pointed to by item and never has a sibling */
3023 item->nextSibling = NULL;
3024 parent->lastChild = item;
3026 DPA_Destroy(sortList);
3028 TREEVIEW_VerifyTree(infoPtr);
3030 if (parent->state & TVIS_EXPANDED)
3032 int visOrder = infoPtr->firstVisible->visibleOrder;
3034 if (parent == infoPtr->root)
3035 TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
3037 TREEVIEW_RecalculateVisibleOrder(infoPtr, parent);
3039 if (TREEVIEW_IsChildOf(parent, infoPtr->firstVisible))
3041 TREEVIEW_ITEM *item;
3043 for (item = infoPtr->root->firstChild; item != NULL;
3044 item = TREEVIEW_GetNextListItem(infoPtr, item))
3046 if (item->visibleOrder == visOrder)
3050 if (!item) item = parent->firstChild;
3051 TREEVIEW_SetFirstVisible(infoPtr, item, FALSE);
3054 TREEVIEW_Invalidate(infoPtr, NULL);
3063 /***************************************************************************
3064 * Setup the treeview structure with regards of the sort method
3065 * and sort the children of the TV item specified in lParam
3068 TREEVIEW_SortChildrenCB(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPTVSORTCB pSort)
3070 return TREEVIEW_Sort(infoPtr, wParam, pSort->hParent, pSort);
3074 /***************************************************************************
3075 * Sort the children of the TV item specified in lParam.
3078 TREEVIEW_SortChildren(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3080 return TREEVIEW_Sort(infoPtr, (BOOL)wParam, (HTREEITEM)lParam, NULL);
3084 /* Expansion/Collapse ***************************************************/
3087 TREEVIEW_SendExpanding(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
3090 return !TREEVIEW_SendTreeviewNotify(infoPtr, TVN_ITEMEXPANDINGW, action,
3091 TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
3092 | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
3097 TREEVIEW_SendExpanded(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
3100 TREEVIEW_SendTreeviewNotify(infoPtr, TVN_ITEMEXPANDEDW, action,
3101 TVIF_HANDLE | TVIF_STATE | TVIF_PARAM
3102 | TVIF_IMAGE | TVIF_SELECTEDIMAGE,
3107 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3108 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3110 TREEVIEW_Collapse(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
3111 BOOL bRemoveChildren, BOOL bUser)
3113 UINT action = TVE_COLLAPSE | (bRemoveChildren ? TVE_COLLAPSERESET : 0);
3114 BOOL bSetSelection, bSetFirstVisible;
3116 TRACE("TVE_COLLAPSE %p %s\n", wineItem, TREEVIEW_ItemName(wineItem));
3118 if (!(wineItem->state & TVIS_EXPANDED))
3121 if (bUser || !(wineItem->state & TVIS_EXPANDEDONCE))
3122 TREEVIEW_SendExpanding(infoPtr, wineItem, action);
3124 if (wineItem->firstChild == NULL)
3127 wineItem->state &= ~TVIS_EXPANDED;
3129 if (bUser || !(wineItem->state & TVIS_EXPANDEDONCE))
3130 TREEVIEW_SendExpanded(infoPtr, wineItem, action);
3132 bSetSelection = (infoPtr->selectedItem != NULL
3133 && TREEVIEW_IsChildOf(wineItem, infoPtr->selectedItem));
3135 bSetFirstVisible = (infoPtr->firstVisible != NULL
3136 && TREEVIEW_IsChildOf(wineItem, infoPtr->firstVisible));
3138 if (bRemoveChildren)
3140 INT old_cChildren = wineItem->cChildren;
3141 TRACE("TVE_COLLAPSERESET\n");
3142 wineItem->state &= ~TVIS_EXPANDEDONCE;
3143 TREEVIEW_RemoveAllChildren(infoPtr, wineItem);
3144 wineItem->cChildren = old_cChildren;
3147 if (wineItem->firstChild)
3149 TREEVIEW_ITEM *item, *sibling;
3151 sibling = TREEVIEW_GetNextListItem(infoPtr, wineItem);
3153 for (item = wineItem->firstChild; item != sibling;
3154 item = TREEVIEW_GetNextListItem(infoPtr, item))
3156 item->visibleOrder = -1;
3160 TREEVIEW_RecalculateVisibleOrder(infoPtr, wineItem);
3162 TREEVIEW_SetFirstVisible(infoPtr, bSetFirstVisible ? wineItem
3163 : infoPtr->firstVisible, TRUE);
3167 /* Don't call DoSelectItem, it sends notifications. */
3168 if (TREEVIEW_ValidItem(infoPtr, infoPtr->selectedItem))
3169 infoPtr->selectedItem->state &= ~TVIS_SELECTED;
3170 wineItem->state |= TVIS_SELECTED;
3171 infoPtr->selectedItem = wineItem;
3173 TREEVIEW_EnsureVisible(infoPtr, wineItem, FALSE);
3176 TREEVIEW_UpdateScrollBars(infoPtr);
3177 TREEVIEW_Invalidate(infoPtr, NULL);
3183 TREEVIEW_Expand(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem,
3184 BOOL bExpandPartial, BOOL bUser)
3188 if (wineItem->state & TVIS_EXPANDED)
3191 TRACE("TVE_EXPAND %p %s\n", wineItem, TREEVIEW_ItemName(wineItem));
3193 if (bUser || ((wineItem->cChildren != 0) &&
3194 !(wineItem->state & TVIS_EXPANDEDONCE)))
3196 if (!TREEVIEW_SendExpanding(infoPtr, wineItem, TVE_EXPAND))
3198 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3202 if (!wineItem->firstChild)
3205 wineItem->state |= TVIS_EXPANDED;
3206 TREEVIEW_SendExpanded(infoPtr, wineItem, TVE_EXPAND);
3207 wineItem->state |= TVIS_EXPANDEDONCE;
3211 if (!wineItem->firstChild)
3214 /* this item has already been expanded */
3215 wineItem->state |= TVIS_EXPANDED;
3219 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3221 TREEVIEW_RecalculateVisibleOrder(infoPtr, wineItem);
3222 TREEVIEW_UpdateSubTree(infoPtr, wineItem);
3223 TREEVIEW_UpdateScrollBars(infoPtr);
3225 /* Scroll up so that as many children as possible are visible.
3226 * This looses when expanding causes an HScroll bar to appear, but we
3227 * don't know that yet, so the last item is obscured. */
3228 if (wineItem->firstChild != NULL)
3230 int nChildren = wineItem->lastChild->visibleOrder
3231 - wineItem->firstChild->visibleOrder + 1;
3233 int visible_pos = wineItem->visibleOrder
3234 - infoPtr->firstVisible->visibleOrder;
3236 int rows_below = TREEVIEW_GetVisibleCount(infoPtr) - visible_pos - 1;
3238 if (visible_pos > 0 && nChildren > rows_below)
3240 int scroll = nChildren - rows_below;
3242 if (scroll > visible_pos)
3243 scroll = visible_pos;
3247 TREEVIEW_ITEM *newFirstVisible
3248 = TREEVIEW_GetListItem(infoPtr, infoPtr->firstVisible,
3252 TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
3257 TREEVIEW_Invalidate(infoPtr, NULL);
3263 TREEVIEW_Toggle(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem, BOOL bUser)
3267 if (wineItem->state & TVIS_EXPANDED)
3268 return TREEVIEW_Collapse(infoPtr, wineItem, FALSE, bUser);
3270 return TREEVIEW_Expand(infoPtr, wineItem, FALSE, bUser);
3274 TREEVIEW_ExpandAll(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
3276 TREEVIEW_Expand(infoPtr, item, FALSE, TRUE);
3278 for (item = item->firstChild; item != NULL; item = item->nextSibling)
3280 if (TREEVIEW_HasChildren(infoPtr, item))
3281 TREEVIEW_ExpandAll(infoPtr, item);
3285 /* Note:If the specified item is the child of a collapsed parent item,
3286 the parent's list of child items is (recursively) expanded to reveal the
3287 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3288 know if it also applies here.
3292 TREEVIEW_ExpandMsg(TREEVIEW_INFO *infoPtr, UINT flag, HTREEITEM wineItem)
3294 if (!TREEVIEW_ValidItem(infoPtr, wineItem))
3297 TRACE("For (%s) item:%d, flags %x, state:%d\n",
3298 TREEVIEW_ItemName(wineItem), flag,
3299 TREEVIEW_GetItemIndex(infoPtr, wineItem), wineItem->state);
3301 switch (flag & TVE_TOGGLE)
3304 return TREEVIEW_Collapse(infoPtr, wineItem, flag & TVE_COLLAPSERESET,
3308 return TREEVIEW_Expand(infoPtr, wineItem, flag & TVE_EXPANDPARTIAL,
3312 return TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
3319 TRACE("Exiting, Item %p state is now %d...\n", wineItem, wineItem->state);
3323 /* Hit-Testing **********************************************************/
3325 static TREEVIEW_ITEM *
3326 TREEVIEW_HitTestPoint(TREEVIEW_INFO *infoPtr, POINT pt)
3328 TREEVIEW_ITEM *wineItem;
3331 if (!infoPtr->firstVisible)
3334 row = pt.y / infoPtr->uItemHeight + infoPtr->firstVisible->visibleOrder;
3336 for (wineItem = infoPtr->firstVisible; wineItem != NULL;
3337 wineItem = TREEVIEW_GetNextListItem(infoPtr, wineItem))
3339 if (row >= wineItem->visibleOrder
3340 && row < wineItem->visibleOrder + wineItem->iIntegral)
3348 TREEVIEW_HitTest(TREEVIEW_INFO *infoPtr, LPTVHITTESTINFO lpht)
3350 TREEVIEW_ITEM *wineItem;
3356 GetClientRect(infoPtr->hwnd, &rect);
3363 status |= TVHT_TOLEFT;
3365 else if (x > rect.right)
3367 status |= TVHT_TORIGHT;
3372 status |= TVHT_ABOVE;
3374 else if (y > rect.bottom)
3376 status |= TVHT_BELOW;
3381 lpht->flags = status;
3382 return (LRESULT)(HTREEITEM)NULL;
3385 wineItem = TREEVIEW_HitTestPoint(infoPtr, lpht->pt);
3388 lpht->flags = TVHT_NOWHERE;
3389 return (LRESULT)(HTREEITEM)NULL;
3392 if (x >= wineItem->textOffset + wineItem->textWidth)
3394 lpht->flags = TVHT_ONITEMRIGHT;
3396 else if (x >= wineItem->textOffset)
3398 lpht->flags = TVHT_ONITEMLABEL;
3400 else if (x >= wineItem->imageOffset)
3402 lpht->flags = TVHT_ONITEMICON;
3404 else if (x >= wineItem->stateOffset)
3406 lpht->flags = TVHT_ONITEMSTATEICON;
3408 else if (x >= wineItem->linesOffset && infoPtr->dwStyle & TVS_HASBUTTONS)
3410 lpht->flags = TVHT_ONITEMBUTTON;
3414 lpht->flags = TVHT_ONITEMINDENT;
3417 lpht->hItem = wineItem;
3418 TRACE("(%ld,%ld):result %x\n", lpht->pt.x, lpht->pt.y, lpht->flags);
3420 return (LRESULT)wineItem;
3423 /* Item Label Editing ***************************************************/
3426 TREEVIEW_GetEditControl(TREEVIEW_INFO *infoPtr)
3428 return (LRESULT)infoPtr->hwndEdit;
3431 static LRESULT CALLBACK
3432 TREEVIEW_Edit_SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3434 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(GetParent(hwnd));
3435 BOOL bCancel = FALSE;
3441 TRACE("WM_PAINT start\n");
3442 rc = CallWindowProcW(infoPtr->wpEditOrig, hwnd, uMsg, wParam,
3444 TRACE("WM_PAINT done\n");
3448 if (infoPtr->bIgnoreEditKillFocus)
3453 return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
3456 if (wParam == (WPARAM)VK_ESCAPE)
3461 else if (wParam == (WPARAM)VK_RETURN)
3468 return CallWindowProcW(infoPtr->wpEditOrig, hwnd, uMsg, wParam, lParam);
3471 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3472 /* eg. Using a messagebox */
3474 infoPtr->bIgnoreEditKillFocus = TRUE;
3475 TREEVIEW_EndEditLabelNow(infoPtr, bCancel || !infoPtr->bLabelChanged);
3476 infoPtr->bIgnoreEditKillFocus = FALSE;
3482 /* should handle edit control messages here */
3485 TREEVIEW_Command(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
3487 TRACE("%x %ld\n", wParam, lParam);
3489 switch (HIWORD(wParam))
3494 * Adjust the edit window size
3497 TREEVIEW_ITEM *editItem = infoPtr->selectedItem;
3498 HDC hdc = GetDC(infoPtr->hwndEdit);
3501 HFONT hFont, hOldFont = 0;
3503 infoPtr->bLabelChanged = TRUE;
3505 len = GetWindowTextW(infoPtr->hwndEdit, buffer, sizeof(buffer));
3507 /* Select font to get the right dimension of the string */
3508 hFont = (HFONT)SendMessageW(infoPtr->hwndEdit, WM_GETFONT, 0, 0);
3512 hOldFont = SelectObject(hdc, hFont);
3515 if (GetTextExtentPoint32W(hdc, buffer, strlenW(buffer), &sz))
3517 TEXTMETRICW textMetric;
3519 /* Add Extra spacing for the next character */
3520 GetTextMetricsW(hdc, &textMetric);
3521 sz.cx += (textMetric.tmMaxCharWidth * 2);
3523 sz.cx = max(sz.cx, textMetric.tmMaxCharWidth * 3);
3525 infoPtr->clientWidth - editItem->textOffset + 2);
3527 SetWindowPos(infoPtr->hwndEdit,
3532 editItem->rect.bottom - editItem->rect.top + 3,
3533 SWP_NOMOVE | SWP_DRAWFRAME);
3538 SelectObject(hdc, hOldFont);
3541 ReleaseDC(infoPtr->hwnd, hdc);
3546 return SendMessageW(infoPtr->hwndNotify, WM_COMMAND, wParam, lParam);
3553 TREEVIEW_EditLabel(TREEVIEW_INFO *infoPtr, HTREEITEM hItem)
3555 HWND hwnd = infoPtr->hwnd;
3558 TREEVIEW_ITEM *editItem = hItem;
3559 HINSTANCE hinst = (HINSTANCE)GetWindowLongW(hwnd, GWL_HINSTANCE);
3562 TEXTMETRICW textMetric;
3563 WCHAR EditW[] = {'E','d','i','t',0};
3565 TRACE("%x %p\n", (unsigned)hwnd, hItem);
3566 if (!TREEVIEW_ValidItem(infoPtr, editItem))
3569 if (infoPtr->hwndEdit)
3570 return infoPtr->hwndEdit;
3572 infoPtr->bLabelChanged = FALSE;
3574 /* Make sure that edit item is selected */
3575 TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, hItem, TVC_UNKNOWN);
3576 TREEVIEW_EnsureVisible(infoPtr, hItem, TRUE);
3578 TREEVIEW_UpdateDispInfo(infoPtr, editItem, TVIF_TEXT);
3581 /* Select the font to get appropriate metric dimensions */
3582 if (infoPtr->hFont != 0)
3584 hOldFont = SelectObject(hdc, infoPtr->hFont);
3587 /* Get string length in pixels */
3588 GetTextExtentPoint32W(hdc, editItem->pszText, strlenW(editItem->pszText),
3591 /* Add Extra spacing for the next character */
3592 GetTextMetricsW(hdc, &textMetric);
3593 sz.cx += (textMetric.tmMaxCharWidth * 2);
3595 sz.cx = max(sz.cx, textMetric.tmMaxCharWidth * 3);
3596 sz.cx = min(sz.cx, infoPtr->clientWidth - editItem->textOffset + 2);
3598 if (infoPtr->hFont != 0)
3600 SelectObject(hdc, hOldFont);
3603 ReleaseDC(hwnd, hdc);
3604 hwndEdit = CreateWindowExW(WS_EX_LEFT,
3607 WS_CHILD | WS_BORDER | ES_AUTOHSCROLL |
3608 WS_CLIPSIBLINGS | ES_WANTRETURN |
3609 ES_LEFT, editItem->textOffset - 2,
3610 editItem->rect.top - 1, sz.cx + 3,
3611 editItem->rect.bottom -
3612 editItem->rect.top + 3, hwnd, 0, hinst, 0);
3613 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3615 infoPtr->hwndEdit = hwndEdit;
3617 /* Get a 2D border. */
3618 SetWindowLongW(hwndEdit, GWL_EXSTYLE,
3619 GetWindowLongW(hwndEdit, GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
3620 SetWindowLongW(hwndEdit, GWL_STYLE,
3621 GetWindowLongW(hwndEdit, GWL_STYLE) | WS_BORDER);
3623 SendMessageW(hwndEdit, WM_SETFONT,
3624 (WPARAM)TREEVIEW_FontForItem(infoPtr, editItem), FALSE);
3626 infoPtr->wpEditOrig = (WNDPROC)SetWindowLongW(hwndEdit, GWL_WNDPROC,
3628 TREEVIEW_Edit_SubclassProc);
3630 if (TREEVIEW_BeginLabelEditNotify(infoPtr, editItem))
3632 DestroyWindow(hwndEdit);
3633 infoPtr->hwndEdit = 0;
3637 infoPtr->selectedItem = hItem;
3638 SetWindowTextW(hwndEdit, editItem->pszText);
3640 SendMessageW(hwndEdit, EM_SETSEL, 0, -1);
3641 ShowWindow(hwndEdit, SW_SHOW);
3648 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO *infoPtr, BOOL bCancel)
3650 HWND hwnd = infoPtr->hwnd;
3651 TREEVIEW_ITEM *editedItem = infoPtr->selectedItem;
3654 WCHAR tmpText[1024] = { '\0' };
3655 WCHAR *newText = tmpText;
3658 if (!infoPtr->hwndEdit)
3661 tvdi.hdr.hwndFrom = hwnd;
3662 tvdi.hdr.idFrom = GetWindowLongW(hwnd, GWL_ID);
3663 tvdi.hdr.code = get_notifycode(infoPtr, TVN_ENDLABELEDITW);
3665 tvdi.item.hItem = editedItem;
3666 tvdi.item.state = editedItem->state;
3667 tvdi.item.lParam = editedItem->lParam;
3671 if (!infoPtr->bNtfUnicode)
3672 iLength = GetWindowTextA(infoPtr->hwndEdit, (LPSTR)tmpText, 1023);
3674 iLength = GetWindowTextW(infoPtr->hwndEdit, tmpText, 1023);
3676 if (iLength >= 1023)
3678 ERR("Insufficient space to retrieve new item label\n");
3681 tvdi.item.mask = TVIF_TEXT;
3682 tvdi.item.pszText = tmpText;
3683 tvdi.item.cchTextMax = iLength + 1;
3687 tvdi.item.pszText = NULL;
3688 tvdi.item.cchTextMax = 0;
3691 bCommit = (BOOL)TREEVIEW_SendRealNotify(infoPtr,
3692 (WPARAM)tvdi.hdr.idFrom, (LPARAM)&tvdi);
3694 if (!bCancel && bCommit) /* Apply the changes */
3696 if (!infoPtr->bNtfUnicode)
3698 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)tmpText, -1, NULL, 0 );
3699 newText = Alloc(len * sizeof(WCHAR));
3700 MultiByteToWideChar( CP_ACP, 0, (LPSTR)tmpText, -1, newText, len );
3704 if (strcmpW(newText, editedItem->pszText) != 0)
3706 if (NULL == ReAlloc(editedItem->pszText, iLength + 1))
3708 ERR("OutOfMemory, cannot allocate space for label\n");
3709 DestroyWindow(infoPtr->hwndEdit);
3710 infoPtr->hwndEdit = 0;
3715 editedItem->cchTextMax = iLength + 1;
3716 strcpyW(editedItem->pszText, newText);
3719 if(newText != tmpText) Free(newText);
3722 ShowWindow(infoPtr->hwndEdit, SW_HIDE);
3723 DestroyWindow(infoPtr->hwndEdit);
3724 infoPtr->hwndEdit = 0;
3729 TREEVIEW_HandleTimer(TREEVIEW_INFO *infoPtr, WPARAM wParam)
3731 if (wParam != TV_EDIT_TIMER)
3733 ERR("got unknown timer\n");
3737 KillTimer(infoPtr->hwnd, TV_EDIT_TIMER);
3738 infoPtr->Timer &= ~TV_EDIT_TIMER_SET;
3740 TREEVIEW_EditLabel(infoPtr, infoPtr->selectedItem);
3746 /* Mouse Tracking/Drag **************************************************/
3748 /***************************************************************************
3749 * This is quite unusual piece of code, but that's how it's implemented in
3753 TREEVIEW_TrackMouse(TREEVIEW_INFO *infoPtr, POINT pt)
3755 INT cxDrag = GetSystemMetrics(SM_CXDRAG);
3756 INT cyDrag = GetSystemMetrics(SM_CYDRAG);
3760 r.top = pt.y - cyDrag;
3761 r.left = pt.x - cxDrag;
3762 r.bottom = pt.y + cyDrag;
3763 r.right = pt.x + cxDrag;
3765 SetCapture(infoPtr->hwnd);
3769 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE | PM_NOYIELD))
3771 if (msg.message == WM_MOUSEMOVE)
3773 pt.x = (short)LOWORD(msg.lParam);
3774 pt.y = (short)HIWORD(msg.lParam);
3775 if (PtInRect(&r, pt))
3783 else if (msg.message >= WM_LBUTTONDOWN &&
3784 msg.message <= WM_RBUTTONDBLCLK)
3786 if (msg.message == WM_RBUTTONUP)
3787 TREEVIEW_RButtonUp(infoPtr, &pt);
3791 DispatchMessageA(&msg);
3794 if (GetCapture() != infoPtr->hwnd)
3804 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO *infoPtr, LPARAM lParam)
3806 TREEVIEW_ITEM *wineItem;
3810 SetFocus(infoPtr->hwnd);
3812 if (infoPtr->Timer & TV_EDIT_TIMER_SET)
3814 /* If there is pending 'edit label' event - kill it now */
3815 KillTimer(infoPtr->hwnd, TV_EDIT_TIMER);
3818 hit.pt.x = (short)LOWORD(lParam);
3819 hit.pt.y = (short)HIWORD(lParam);
3821 wineItem = (TREEVIEW_ITEM *)TREEVIEW_HitTest(infoPtr, &hit);
3824 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr, wineItem));
3826 if (TREEVIEW_SendSimpleNotify(infoPtr, NM_DBLCLK) == FALSE)
3830 case TVHT_ONITEMRIGHT:
3831 /* FIXME: we should not have sent NM_DBLCLK in this case. */
3834 case TVHT_ONITEMINDENT:
3835 if (!(infoPtr->dwStyle & TVS_HASLINES))
3841 int level = hit.pt.x / infoPtr->uIndent;
3842 if (!(infoPtr->dwStyle & TVS_LINESATROOT)) level++;
3844 while (wineItem->iLevel > level)
3846 wineItem = wineItem->parent;
3852 case TVHT_ONITEMLABEL:
3853 case TVHT_ONITEMICON:
3854 case TVHT_ONITEMBUTTON:
3855 TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
3858 case TVHT_ONITEMSTATEICON:
3859 if (infoPtr->dwStyle & TVS_CHECKBOXES)
3860 TREEVIEW_ToggleItemState(infoPtr, wineItem);
3862 TREEVIEW_Toggle(infoPtr, wineItem, TRUE);
3871 TREEVIEW_LButtonDown(TREEVIEW_INFO *infoPtr, LPARAM lParam)
3873 HWND hwnd = infoPtr->hwnd;
3878 /* If Edit control is active - kill it and return.
3879 * The best way to do it is to set focus to itself.
3880 * Edit control subclassed procedure will automatically call
3883 if (infoPtr->hwndEdit)
3889 ht.pt.x = (short)LOWORD(lParam);
3890 ht.pt.y = (short)HIWORD(lParam);
3892 TREEVIEW_HitTest(infoPtr, &ht);
3893 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr, ht.hItem));
3895 /* update focusedItem and redraw both items */
3896 if(ht.hItem && (ht.flags & TVHT_ONITEM))
3898 infoPtr->focusedItem = ht.hItem;
3899 InvalidateRect(hwnd, &(((HTREEITEM)(ht.hItem))->rect), TRUE);
3901 if(infoPtr->selectedItem)
3902 InvalidateRect(hwnd, &(infoPtr->selectedItem->rect), TRUE);
3905 bTrack = (ht.flags & TVHT_ONITEM)
3906 && !(infoPtr->dwStyle & TVS_DISABLEDRAGDROP);
3908 /* Send NM_CLICK right away */
3910 if (TREEVIEW_SendSimpleNotify(infoPtr, NM_CLICK))
3913 if (ht.flags & TVHT_ONITEMBUTTON)
3915 TREEVIEW_Toggle(infoPtr, ht.hItem, TRUE);
3919 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
3920 if (TREEVIEW_TrackMouse(infoPtr, ht.pt))
3922 TREEVIEW_SendTreeviewDnDNotify(infoPtr, TVN_BEGINDRAGW, ht.hItem, ht.pt);
3923 infoPtr->dropItem = ht.hItem;
3925 /* clean up focusedItem as we dragged and won't select this item */
3926 if(infoPtr->focusedItem)
3928 /* refresh the item that was focused */
3929 tempItem = infoPtr->focusedItem;
3930 infoPtr->focusedItem = 0;
3931 InvalidateRect(infoPtr->hwnd, &tempItem->rect, TRUE);
3933 /* refresh the selected item to return the filled background */
3934 InvalidateRect(infoPtr->hwnd, &(infoPtr->selectedItem->rect), TRUE);
3941 if (bTrack && TREEVIEW_SendSimpleNotify(infoPtr, NM_CLICK))
3945 * If the style allows editing and the node is already selected
3946 * and the click occurred on the item label...
3948 if ((infoPtr->dwStyle & TVS_EDITLABELS) &&
3949 (ht.flags & TVHT_ONITEMLABEL) && (infoPtr->selectedItem == ht.hItem))
3951 if (infoPtr->Timer & TV_EDIT_TIMER_SET)
3952 KillTimer(hwnd, TV_EDIT_TIMER);
3954 SetTimer(hwnd, TV_EDIT_TIMER, GetDoubleClickTime(), 0);
3955 infoPtr->Timer |= TV_EDIT_TIMER_SET;
3957 else if (ht.flags & (TVHT_ONITEMICON|TVHT_ONITEMLABEL)) /* select the item if the hit was inside of the icon or text */
3960 * if we are TVS_SINGLEEXPAND then we want this single click to
3961 * do a bunch of things.
3963 if((infoPtr->dwStyle & TVS_SINGLEEXPAND) &&
3964 (infoPtr->hwndEdit == 0))
3966 TREEVIEW_ITEM *SelItem;
3969 * Send the notification
3971 TREEVIEW_SendTreeviewNotify(infoPtr, TVN_SINGLEEXPAND, TVC_UNKNOWN, TVIF_HANDLE | TVIF_PARAM, ht.hItem, 0);
3974 * Close the previous selection all the way to the root
3975 * as long as the new selection is not a child
3977 if((infoPtr->selectedItem)
3978 && (infoPtr->selectedItem != ht.hItem))
3980 BOOL closeit = TRUE;
3983 /* determine if the hitItem is a child of the currently selected item */
3984 while(closeit && SelItem && TREEVIEW_ValidItem(infoPtr, SelItem) && (SelItem != infoPtr->root))
3986 closeit = (SelItem != infoPtr->selectedItem);
3987 SelItem = SelItem->parent;
3992 if(TREEVIEW_ValidItem(infoPtr, infoPtr->selectedItem))
3993 SelItem = infoPtr->selectedItem;
3995 while(SelItem && (SelItem != ht.hItem) && TREEVIEW_ValidItem(infoPtr, SelItem) && (SelItem != infoPtr->root))
3997 TREEVIEW_Collapse(infoPtr, SelItem, FALSE, FALSE);
3998 SelItem = SelItem->parent;
4004 * Expand the current item
4006 TREEVIEW_Expand(infoPtr, ht.hItem, TVE_TOGGLE, FALSE);
4009 /* Select the current item */
4010 TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, ht.hItem, TVC_BYMOUSE);
4012 else if (ht.flags & TVHT_ONITEMSTATEICON)
4014 /* TVS_CHECKBOXES requires us to toggle the current state */
4015 if (infoPtr->dwStyle & TVS_CHECKBOXES)
4016 TREEVIEW_ToggleItemState(infoPtr, ht.hItem);
4026 TREEVIEW_RButtonDown(TREEVIEW_INFO *infoPtr, LPARAM lParam)
4030 if (infoPtr->hwndEdit)
4032 SetFocus(infoPtr->hwnd);
4036 ht.pt.x = (short)LOWORD(lParam);
4037 ht.pt.y = (short)HIWORD(lParam);
4039 TREEVIEW_HitTest(infoPtr, &ht);
4041 if (TREEVIEW_TrackMouse(infoPtr, ht.pt))
4045 TREEVIEW_SendTreeviewDnDNotify(infoPtr, TVN_BEGINRDRAGW, ht.hItem, ht.pt);
4046 infoPtr->dropItem = ht.hItem;
4051 SetFocus(infoPtr->hwnd);
4052 TREEVIEW_SendSimpleNotify(infoPtr, NM_RCLICK);
4059 TREEVIEW_RButtonUp(TREEVIEW_INFO *infoPtr, LPPOINT pPt)
4066 TREEVIEW_CreateDragImage(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
4068 TREEVIEW_ITEM *dragItem = (HTREEITEM)lParam;
4072 HBITMAP hbmp, hOldbmp;
4079 if (!(infoPtr->himlNormal))
4082 if (!dragItem || !TREEVIEW_ValidItem(infoPtr, dragItem))
4085 TREEVIEW_UpdateDispInfo(infoPtr, dragItem, TVIF_TEXT);
4087 hwtop = GetDesktopWindow();
4088 htopdc = GetDC(hwtop);
4089 hdc = CreateCompatibleDC(htopdc);
4091 hOldFont = SelectObject(hdc, infoPtr->hFont);
4092 GetTextExtentPoint32W(hdc, dragItem->pszText, strlenW(dragItem->pszText),
4094 TRACE("%ld %ld %s %d\n", size.cx, size.cy, debugstr_w(dragItem->pszText),
4095 strlenW(dragItem->pszText));
4096 hbmp = CreateCompatibleBitmap(htopdc, size.cx, size.cy);
4097 hOldbmp = SelectObject(hdc, hbmp);
4099 ImageList_GetIconSize(infoPtr->himlNormal, &cx, &cy);
4104 infoPtr->dragList = ImageList_Create(size.cx, size.cy, ILC_COLOR, 10, 10);
4105 ImageList_Draw(infoPtr->himlNormal, dragItem->iImage, hdc, 0, 0,
4109 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4110 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4113 /* draw item text */
4115 SetRect(&rc, cx, 0, size.cx, size.cy);
4116 DrawTextW(hdc, dragItem->pszText, strlenW(dragItem->pszText), &rc,
4118 SelectObject(hdc, hOldFont);
4119 SelectObject(hdc, hOldbmp);
4121 ImageList_Add(infoPtr->dragList, hbmp, 0);
4125 ReleaseDC(hwtop, htopdc);
4127 return (LRESULT)infoPtr->dragList;
4130 /* Selection ************************************************************/
4133 TREEVIEW_DoSelectItem(TREEVIEW_INFO *infoPtr, INT action, HTREEITEM newSelect,
4136 TREEVIEW_ITEM *prevSelect;
4139 assert(newSelect == NULL || TREEVIEW_ValidItem(infoPtr, newSelect));
4141 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4142 newSelect, TREEVIEW_ItemName(newSelect), action, cause,
4143 newSelect ? newSelect->state : 0);
4145 /* reset and redraw focusedItem if focusedItem was set so we don't */
4146 /* have to worry about the previously focused item when we set a new one */
4147 if(infoPtr->focusedItem)
4149 rcFocused = (infoPtr->focusedItem)->rect;
4150 infoPtr->focusedItem = 0;
4151 InvalidateRect(infoPtr->hwnd, &rcFocused, TRUE);
4157 prevSelect = infoPtr->selectedItem;
4159 if (prevSelect == newSelect)
4162 if (TREEVIEW_SendTreeviewNotify(infoPtr,
4165 TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
4171 prevSelect->state &= ~TVIS_SELECTED;
4173 newSelect->state |= TVIS_SELECTED;
4175 infoPtr->selectedItem = newSelect;
4177 TREEVIEW_EnsureVisible(infoPtr, infoPtr->selectedItem, FALSE);
4179 TREEVIEW_SendTreeviewNotify(infoPtr,
4182 TVIF_HANDLE | TVIF_STATE | TVIF_PARAM,
4185 TREEVIEW_Invalidate(infoPtr, prevSelect);
4186 TREEVIEW_Invalidate(infoPtr, newSelect);
4189 case TVGN_DROPHILITE:
4190 prevSelect = infoPtr->dropItem;
4193 prevSelect->state &= ~TVIS_DROPHILITED;
4195 infoPtr->dropItem = newSelect;
4198 newSelect->state |= TVIS_DROPHILITED;
4200 TREEVIEW_Invalidate(infoPtr, prevSelect);
4201 TREEVIEW_Invalidate(infoPtr, newSelect);
4204 case TVGN_FIRSTVISIBLE:
4205 TREEVIEW_EnsureVisible(infoPtr, newSelect, FALSE);
4206 TREEVIEW_SetFirstVisible(infoPtr, newSelect, TRUE);
4207 TREEVIEW_Invalidate(infoPtr, NULL);
4211 TRACE("Leaving state %d\n", newSelect ? newSelect->state : 0);
4215 /* FIXME: handle NM_KILLFOCUS etc */
4217 TREEVIEW_SelectItem(TREEVIEW_INFO *infoPtr, INT wParam, HTREEITEM item)
4219 if (item != NULL && !TREEVIEW_ValidItem(infoPtr, item))
4222 TRACE("%p (%s) %d\n", item, TREEVIEW_ItemName(item), wParam);
4224 if (!TREEVIEW_DoSelectItem(infoPtr, wParam, item, TVC_UNKNOWN))
4230 /*************************************************************************
4231 * TREEVIEW_ProcessLetterKeys
4233 * Processes keyboard messages generated by pressing the letter keys
4235 * What this does is perform a case insensitive search from the
4236 * current position with the following quirks:
4237 * - If two chars or more are pressed in quick succession we search
4238 * for the corresponding string (e.g. 'abc').
4239 * - If there is a delay we wipe away the current search string and
4240 * restart with just that char.
4241 * - If the user keeps pressing the same character, whether slowly or
4242 * fast, so that the search string is entirely composed of this
4243 * character ('aaaaa' for instance), then we search for first item
4244 * that starting with that character.
4245 * - If the user types the above character in quick succession, then
4246 * we must also search for the corresponding string ('aaaaa'), and
4247 * go to that string if there is a match.
4255 * - The current implementation has a list of characters it will
4256 * accept and it ignores averything else. In particular it will
4257 * ignore accentuated characters which seems to match what
4258 * Windows does. But I'm not sure it makes sense to follow
4260 * - We don't sound a beep when the search fails.
4261 * - The search should start from the focused item, not from the selected
4262 * item. One reason for this is to allow for multiple selections in trees.
4263 * But currently infoPtr->focusedItem does not seem very usable.
4267 * TREEVIEW_ProcessLetterKeys
4269 static INT TREEVIEW_ProcessLetterKeys(
4270 HWND hwnd, /* handle to the window */
4271 WPARAM charCode, /* the character code, the actual character */
4272 LPARAM keyData /* key data */
4275 TREEVIEW_INFO *infoPtr;
4277 HTREEITEM endidx,idx;
4279 WCHAR buffer[MAX_PATH];
4280 DWORD timestamp,elapsed;
4282 /* simple parameter checking */
4283 if (!hwnd || !charCode || !keyData)
4286 infoPtr=(TREEVIEW_INFO*)GetWindowLongW(hwnd, 0);
4290 /* only allow the valid WM_CHARs through */
4291 if (!isalnum(charCode) &&
4292 charCode != '.' && charCode != '`' && charCode != '!' &&
4293 charCode != '@' && charCode != '#' && charCode != '$' &&
4294 charCode != '%' && charCode != '^' && charCode != '&' &&
4295 charCode != '*' && charCode != '(' && charCode != ')' &&
4296 charCode != '-' && charCode != '_' && charCode != '+' &&
4297 charCode != '=' && charCode != '\\'&& charCode != ']' &&
4298 charCode != '}' && charCode != '[' && charCode != '{' &&
4299 charCode != '/' && charCode != '?' && charCode != '>' &&
4300 charCode != '<' && charCode != ',' && charCode != '~')
4303 /* compute how much time elapsed since last keypress */
4304 timestamp = GetTickCount();
4305 if (timestamp > infoPtr->lastKeyPressTimestamp) {
4306 elapsed=timestamp-infoPtr->lastKeyPressTimestamp;
4308 elapsed=infoPtr->lastKeyPressTimestamp-timestamp;
4311 /* update the search parameters */
4312 infoPtr->lastKeyPressTimestamp=timestamp;
4313 if (elapsed < KEY_DELAY) {
4314 if (infoPtr->nSearchParamLength < sizeof(infoPtr->szSearchParam) / sizeof(WCHAR)) {
4315 infoPtr->szSearchParam[infoPtr->nSearchParamLength++]=charCode;
4317 if (infoPtr->charCode != charCode) {
4318 infoPtr->charCode=charCode=0;
4321 infoPtr->charCode=charCode;
4322 infoPtr->szSearchParam[0]=charCode;
4323 infoPtr->nSearchParamLength=1;
4324 /* Redundant with the 1 char string */
4328 /* and search from the current position */
4330 if (infoPtr->selectedItem != NULL) {
4331 endidx=infoPtr->selectedItem;
4332 /* if looking for single character match,
4333 * then we must always move forward
4335 if (infoPtr->nSearchParamLength == 1)
4336 idx=TREEVIEW_GetNextListItem(infoPtr,endidx);
4341 idx=infoPtr->root->firstChild;
4347 idx=infoPtr->root->firstChild;
4351 ZeroMemory(&item, sizeof(item));
4352 item.mask = TVIF_TEXT;
4354 item.pszText = buffer;
4355 item.cchTextMax = sizeof(buffer);
4356 TREEVIEW_GetItemT( infoPtr, &item, TRUE );
4358 /* check for a match */
4359 if (strncmpiW(item.pszText,infoPtr->szSearchParam,infoPtr->nSearchParamLength) == 0) {
4362 } else if ( (charCode != 0) && (nItem == NULL) &&
4363 (nItem != infoPtr->selectedItem) &&
4364 (strncmpiW(item.pszText,infoPtr->szSearchParam,1) == 0) ) {
4365 /* This would work but we must keep looking for a longer match */
4368 idx=TREEVIEW_GetNextListItem(infoPtr,idx);
4369 } while (idx != endidx);
4371 if (nItem != NULL) {
4372 if (TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, nItem, TVC_BYKEYBOARD)) {
4373 TREEVIEW_EnsureVisible(infoPtr, nItem, FALSE);
4380 /* Scrolling ************************************************************/
4383 TREEVIEW_EnsureVisible(TREEVIEW_INFO *infoPtr, HTREEITEM item, BOOL bHScroll)
4386 BOOL hasFirstVisible = infoPtr->firstVisible != NULL;
4387 HTREEITEM newFirstVisible = NULL;
4388 int visible_pos = -1;
4390 if (!TREEVIEW_ValidItem(infoPtr, item))
4393 if (!ISVISIBLE(item))
4395 /* Expand parents as necessary. */
4398 /* see if we are trying to ensure that root is vislble */
4399 if((item != infoPtr->root) && TREEVIEW_ValidItem(infoPtr, item))
4400 parent = item->parent;
4402 parent = item; /* this item is the topmost item */
4404 while (parent != infoPtr->root)
4406 if (!(parent->state & TVIS_EXPANDED))
4407 TREEVIEW_Expand(infoPtr, parent, FALSE, FALSE);
4409 parent = parent->parent;
4413 viscount = TREEVIEW_GetVisibleCount(infoPtr);
4415 TRACE("%p (%s) %ld - %ld viscount(%d)\n", item, TREEVIEW_ItemName(item), item->visibleOrder,
4416 hasFirstVisible ? infoPtr->firstVisible->visibleOrder : -1, viscount);
4418 if (hasFirstVisible)
4419 visible_pos = item->visibleOrder - infoPtr->firstVisible->visibleOrder;
4421 if (visible_pos < 0)
4423 /* item is before the start of the list: put it at the top. */
4424 newFirstVisible = item;
4426 else if (visible_pos >= viscount
4427 /* Sometimes, before we are displayed, GVC is 0, causing us to
4428 * spuriously scroll up. */
4431 /* item is past the end of the list. */
4432 int scroll = visible_pos - viscount;
4434 newFirstVisible = TREEVIEW_GetListItem(infoPtr, infoPtr->firstVisible,
4440 /* Scroll window so item's text is visible as much as possible */
4441 /* Calculation of amount of extra space is taken from EditLabel code */
4443 TEXTMETRICW textMetric;
4444 HDC hdc = GetWindowDC(infoPtr->hwnd);
4446 x = item->textWidth;
4448 GetTextMetricsW(hdc, &textMetric);
4449 ReleaseDC(infoPtr->hwnd, hdc);
4451 x += (textMetric.tmMaxCharWidth * 2);
4452 x = max(x, textMetric.tmMaxCharWidth * 3);
4454 if (item->textOffset < 0)
4455 pos = item->textOffset;
4456 else if (item->textOffset + x > infoPtr->clientWidth)
4458 if (x > infoPtr->clientWidth)
4459 pos = item->textOffset;
4461 pos = item->textOffset + x - infoPtr->clientWidth;
4466 TREEVIEW_HScroll(infoPtr, MAKEWPARAM(SB_THUMBPOSITION, infoPtr->scrollX + pos));
4469 if (newFirstVisible != NULL && newFirstVisible != infoPtr->firstVisible)
4471 TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
4480 TREEVIEW_SetFirstVisible(TREEVIEW_INFO *infoPtr,
4481 TREEVIEW_ITEM *newFirstVisible,
4482 BOOL bUpdateScrollPos)
4486 TRACE("%p: %s\n", newFirstVisible, TREEVIEW_ItemName(newFirstVisible));
4488 if (newFirstVisible != NULL)
4490 /* Prevent an empty gap from appearing at the bottom... */
4491 gap_size = TREEVIEW_GetVisibleCount(infoPtr)
4492 - infoPtr->maxVisibleOrder + newFirstVisible->visibleOrder;
4496 newFirstVisible = TREEVIEW_GetListItem(infoPtr, newFirstVisible,
4499 /* ... unless we just don't have enough items. */
4500 if (newFirstVisible == NULL)
4501 newFirstVisible = infoPtr->root->firstChild;
4505 if (infoPtr->firstVisible != newFirstVisible)
4507 if (infoPtr->firstVisible == NULL || newFirstVisible == NULL)
4509 infoPtr->firstVisible = newFirstVisible;
4510 TREEVIEW_Invalidate(infoPtr, NULL);
4514 TREEVIEW_ITEM *item;
4515 int scroll = infoPtr->uItemHeight *
4516 (infoPtr->firstVisible->visibleOrder
4517 - newFirstVisible->visibleOrder);
4519 infoPtr->firstVisible = newFirstVisible;
4521 for (item = infoPtr->root->firstChild; item != NULL;
4522 item = TREEVIEW_GetNextListItem(infoPtr, item))
4524 item->rect.top += scroll;
4525 item->rect.bottom += scroll;
4528 if (bUpdateScrollPos)
4529 SetScrollPos(infoPtr->hwnd, SB_VERT,
4530 newFirstVisible->visibleOrder, TRUE);
4532 ScrollWindow(infoPtr->hwnd, 0, scroll, NULL, NULL);
4533 UpdateWindow(infoPtr->hwnd);
4538 /************************************************************************
4539 * VScroll is always in units of visible items. i.e. we always have a
4540 * visible item aligned to the top of the control. (Unless we have no
4544 TREEVIEW_VScroll(TREEVIEW_INFO *infoPtr, WPARAM wParam)
4546 TREEVIEW_ITEM *oldFirstVisible = infoPtr->firstVisible;
4547 TREEVIEW_ITEM *newFirstVisible = NULL;
4549 int nScrollCode = LOWORD(wParam);
4551 TRACE("wp %x\n", wParam);
4553 if (!(infoPtr->uInternalStatus & TV_VSCROLL))
4556 if (infoPtr->hwndEdit)
4557 SetFocus(infoPtr->hwnd);
4559 if (!oldFirstVisible)
4561 assert(infoPtr->root->firstChild == NULL);
4565 switch (nScrollCode)
4568 newFirstVisible = infoPtr->root->firstChild;
4572 newFirstVisible = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
4576 newFirstVisible = TREEVIEW_GetPrevListItem(infoPtr, oldFirstVisible);
4580 newFirstVisible = TREEVIEW_GetNextListItem(infoPtr, oldFirstVisible);
4584 newFirstVisible = TREEVIEW_GetListItem(infoPtr, oldFirstVisible,
4585 -max(1, TREEVIEW_GetVisibleCount(infoPtr)));
4589 newFirstVisible = TREEVIEW_GetListItem(infoPtr, oldFirstVisible,
4590 max(1, TREEVIEW_GetVisibleCount(infoPtr)));
4594 case SB_THUMBPOSITION:
4595 newFirstVisible = TREEVIEW_GetListItem(infoPtr,
4596 infoPtr->root->firstChild,
4597 (LONG)(SHORT)HIWORD(wParam));
4604 if (newFirstVisible != NULL)
4606 if (newFirstVisible != oldFirstVisible)
4607 TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible,
4608 nScrollCode != SB_THUMBTRACK);
4609 else if (nScrollCode == SB_THUMBPOSITION)
4610 SetScrollPos(infoPtr->hwnd, SB_VERT,
4611 newFirstVisible->visibleOrder, TRUE);
4618 TREEVIEW_HScroll(TREEVIEW_INFO *infoPtr, WPARAM wParam)
4621 int scrollX = infoPtr->scrollX;
4622 int nScrollCode = LOWORD(wParam);
4624 TRACE("wp %x\n", wParam);
4626 if (!(infoPtr->uInternalStatus & TV_HSCROLL))
4629 if (infoPtr->hwndEdit)
4630 SetFocus(infoPtr->hwnd);
4632 maxWidth = infoPtr->treeWidth - infoPtr->clientWidth;
4633 /* shall never occur */
4640 switch (nScrollCode)
4643 scrollX -= infoPtr->uItemHeight;
4646 scrollX += infoPtr->uItemHeight;
4649 scrollX -= infoPtr->clientWidth;
4652 scrollX += infoPtr->clientWidth;
4656 case SB_THUMBPOSITION:
4657 scrollX = (int)(SHORT)HIWORD(wParam);
4664 if (scrollX > maxWidth)
4666 else if (scrollX < 0)
4670 if (scrollX != infoPtr->scrollX)
4672 TREEVIEW_ITEM *item;
4673 LONG scroll_pixels = infoPtr->scrollX - scrollX;
4675 for (item = infoPtr->root->firstChild; item != NULL;
4676 item = TREEVIEW_GetNextListItem(infoPtr, item))
4678 item->linesOffset += scroll_pixels;
4679 item->stateOffset += scroll_pixels;
4680 item->imageOffset += scroll_pixels;
4681 item->textOffset += scroll_pixels;
4684 ScrollWindow(infoPtr->hwnd, scroll_pixels, 0, NULL, NULL);
4685 infoPtr->scrollX = scrollX;
4686 UpdateWindow(infoPtr->hwnd);
4689 if (nScrollCode != SB_THUMBTRACK)
4690 SetScrollPos(infoPtr->hwnd, SB_HORZ, scrollX, TRUE);
4696 TREEVIEW_MouseWheel(TREEVIEW_INFO *infoPtr, WPARAM wParam)
4699 UINT pulScrollLines = 3;
4701 if (infoPtr->firstVisible == NULL)
4704 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, &pulScrollLines, 0);
4706 gcWheelDelta = -(short)HIWORD(wParam);
4707 pulScrollLines *= (gcWheelDelta / WHEEL_DELTA);
4709 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
4711 int newDy = infoPtr->firstVisible->visibleOrder + pulScrollLines;
4712 int maxDy = infoPtr->maxVisibleOrder;
4720 TREEVIEW_VScroll(infoPtr, MAKEWPARAM(SB_THUMBPOSITION, newDy));
4725 /* Create/Destroy *******************************************************/
4728 TREEVIEW_Create(HWND hwnd, const CREATESTRUCTW *lpcs)
4731 TREEVIEW_INFO *infoPtr;
4733 TRACE("wnd %p, style %lx\n", hwnd, GetWindowLongW(hwnd, GWL_STYLE));
4735 infoPtr = (TREEVIEW_INFO *)Alloc(sizeof(TREEVIEW_INFO));
4737 if (infoPtr == NULL)
4739 ERR("could not allocate info memory!\n");
4743 SetWindowLongW(hwnd, 0, (DWORD)infoPtr);
4745 infoPtr->hwnd = hwnd;
4746 infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
4747 infoPtr->uInternalStatus = 0;
4749 infoPtr->uNumItems = 0;
4750 infoPtr->cdmode = 0;
4751 infoPtr->uScrollTime = 300; /* milliseconds */
4752 infoPtr->bRedraw = TRUE;
4754 GetClientRect(hwnd, &rcClient);
4756 /* No scroll bars yet. */
4757 infoPtr->clientWidth = rcClient.right;
4758 infoPtr->clientHeight = rcClient.bottom;
4760 infoPtr->treeWidth = 0;
4761 infoPtr->treeHeight = 0;
4763 infoPtr->uIndent = 19;
4764 infoPtr->selectedItem = 0;
4765 infoPtr->focusedItem = 0;
4767 infoPtr->firstVisible = 0;
4768 infoPtr->maxVisibleOrder = 0;
4769 infoPtr->dropItem = 0;
4770 infoPtr->insertMarkItem = 0;
4771 infoPtr->insertBeforeorAfter = 0;
4774 infoPtr->scrollX = 0;
4776 infoPtr->clrBk = GetSysColor(COLOR_WINDOW);
4777 infoPtr->clrText = -1; /* use system color */
4778 infoPtr->clrLine = RGB(128, 128, 128);
4779 infoPtr->clrInsertMark = GetSysColor(COLOR_BTNTEXT);
4783 infoPtr->hwndEdit = 0;
4784 infoPtr->wpEditOrig = NULL;
4785 infoPtr->bIgnoreEditKillFocus = FALSE;
4786 infoPtr->bLabelChanged = FALSE;
4788 infoPtr->himlNormal = NULL;
4789 infoPtr->himlState = NULL;
4790 infoPtr->normalImageWidth = 0;
4791 infoPtr->normalImageHeight = 0;
4792 infoPtr->stateImageWidth = 0;
4793 infoPtr->stateImageHeight = 0;
4795 infoPtr->items = DPA_Create(16);
4797 infoPtr->hFont = GetStockObject(DEFAULT_GUI_FONT);
4798 infoPtr->hBoldFont = TREEVIEW_CreateBoldFont(infoPtr->hFont);
4800 infoPtr->uItemHeight = TREEVIEW_NaturalHeight(infoPtr);
4802 infoPtr->root = TREEVIEW_AllocateItem(infoPtr);
4803 infoPtr->root->state = TVIS_EXPANDED;
4804 infoPtr->root->iLevel = -1;
4805 infoPtr->root->visibleOrder = -1;
4807 infoPtr->hwndNotify = lpcs->hwndParent;
4809 infoPtr->bTransparent = ( GetWindowLongW( hwnd, GWL_STYLE) & TBSTYLE_FLAT);
4812 infoPtr->hwndToolTip = 0;
4814 infoPtr->bNtfUnicode = IsWindowUnicode (hwnd);
4816 /* Determine what type of notify should be issued */
4817 /* sets infoPtr->bNtfUnicode */
4818 TREEVIEW_NotifyFormat(infoPtr, infoPtr->hwndNotify, NF_REQUERY);
4820 if (!(infoPtr->dwStyle & TVS_NOTOOLTIPS))
4821 infoPtr->hwndToolTip = COMCTL32_CreateToolTip(hwnd);
4823 if (infoPtr->dwStyle & TVS_CHECKBOXES)
4826 HBITMAP hbm, hbmOld;
4830 infoPtr->himlState =
4831 ImageList_Create(16, 16, ILC_COLOR | ILC_MASK, 3, 0);
4833 hdcScreen = CreateDCA("DISPLAY", NULL, NULL, NULL);
4835 /* Create a coloured bitmap compatible with the screen depth
4836 because checkboxes are not black&white */
4837 hdc = CreateCompatibleDC(hdcScreen);
4838 hbm = CreateCompatibleBitmap(hdcScreen, 48, 16);
4839 hbmOld = SelectObject(hdc, hbm);
4841 rc.left = 0; rc.top = 0;
4842 rc.right = 48; rc.bottom = 16;
4843 FillRect(hdc, &rc, (HBRUSH)(COLOR_WINDOW+1));
4845 rc.left = 18; rc.top = 2;
4846 rc.right = 30; rc.bottom = 14;
4847 DrawFrameControl(hdc, &rc, DFC_BUTTON,
4848 DFCS_BUTTONCHECK|DFCS_FLAT);
4850 rc.left = 34; rc.right = 46;
4851 DrawFrameControl(hdc, &rc, DFC_BUTTON,
4852 DFCS_BUTTONCHECK|DFCS_FLAT|DFCS_CHECKED);
4854 SelectObject(hdc, hbmOld);
4855 nIndex = ImageList_AddMasked(infoPtr->himlState, hbm,
4856 GetSysColor(COLOR_WINDOW));
4857 TRACE("checkbox index %d\n", nIndex);
4861 DeleteDC(hdcScreen);
4863 infoPtr->stateImageWidth = 16;
4864 infoPtr->stateImageHeight = 16;
4871 TREEVIEW_Destroy(TREEVIEW_INFO *infoPtr)
4875 TREEVIEW_RemoveTree(infoPtr);
4877 /* tool tip is automatically destroyed: we are its owner */
4879 /* Restore original wndproc */
4880 if (infoPtr->hwndEdit)
4881 SetWindowLongW(infoPtr->hwndEdit, GWL_WNDPROC,
4882 (LONG)infoPtr->wpEditOrig);
4884 /* Deassociate treeview from the window before doing anything drastic. */
4885 SetWindowLongW(infoPtr->hwnd, 0, (LONG)NULL);
4887 DeleteObject(infoPtr->hBoldFont);
4893 /* Miscellaneous Messages ***********************************************/
4896 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO *infoPtr, WPARAM key)
4904 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
4905 SCROLL_ENTRY(SB_VERT, SB_PAGEUP), /* VK_PRIOR */
4906 SCROLL_ENTRY(SB_VERT, SB_PAGEDOWN), /* VK_NEXT */
4907 SCROLL_ENTRY(SB_VERT, SB_BOTTOM), /* VK_END */
4908 SCROLL_ENTRY(SB_VERT, SB_TOP), /* VK_HOME */
4909 SCROLL_ENTRY(SB_HORZ, SB_LINEUP), /* VK_LEFT */
4910 SCROLL_ENTRY(SB_VERT, SB_LINEUP), /* VK_UP */
4911 SCROLL_ENTRY(SB_HORZ, SB_LINEDOWN), /* VK_RIGHT */
4912 SCROLL_ENTRY(SB_VERT, SB_LINEDOWN) /* VK_DOWN */
4916 if (key >= VK_PRIOR && key <= VK_DOWN)
4918 unsigned char code = scroll[key - VK_PRIOR].code;
4920 (((code & (1 << 7)) == (SB_HORZ << 7))
4922 : TREEVIEW_VScroll)(infoPtr, code & 0x7F);
4928 /************************************************************************
4931 * VK_UP Move selection to the previous non-hidden item.
4932 * VK_DOWN Move selection to the next non-hidden item.
4933 * VK_HOME Move selection to the first item.
4934 * VK_END Move selection to the last item.
4935 * VK_LEFT If expanded then collapse, otherwise move to parent.
4936 * VK_RIGHT If collapsed then expand, otherwise move to first child.
4938 * VK_SUBTRACT Collapse.
4939 * VK_MULTIPLY Expand all.
4940 * VK_PRIOR Move up GetVisibleCount items.
4941 * VK_NEXT Move down GetVisibleCount items.
4942 * VK_BACK Move to parent.
4943 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
4946 TREEVIEW_KeyDown(TREEVIEW_INFO *infoPtr, WPARAM wParam)
4948 /* If it is non-NULL and different, it will be selected and visible. */
4949 TREEVIEW_ITEM *newSelection = NULL;
4951 TREEVIEW_ITEM *prevItem = infoPtr->selectedItem;
4953 TRACE("%x\n", wParam);
4955 if (prevItem == NULL)
4958 if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
4959 return TREEVIEW_ScrollKeyDown(infoPtr, wParam);
4964 newSelection = TREEVIEW_GetPrevListItem(infoPtr, prevItem);
4966 newSelection = infoPtr->root->firstChild;
4970 newSelection = TREEVIEW_GetNextListItem(infoPtr, prevItem);
4974 newSelection = infoPtr->root->firstChild;
4978 newSelection = TREEVIEW_GetLastListItem(infoPtr, infoPtr->root);
4982 if (prevItem->state & TVIS_EXPANDED)
4984 TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
4986 else if (prevItem->parent != infoPtr->root)
4988 newSelection = prevItem->parent;
4993 if (TREEVIEW_HasChildren(infoPtr, prevItem))
4995 if (!(prevItem->state & TVIS_EXPANDED))
4996 TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
4999 newSelection = prevItem->firstChild;
5006 TREEVIEW_ExpandAll(infoPtr, prevItem);
5010 if (!(prevItem->state & TVIS_EXPANDED))
5011 TREEVIEW_Expand(infoPtr, prevItem, FALSE, TRUE);
5015 if (prevItem->state & TVIS_EXPANDED)
5016 TREEVIEW_Collapse(infoPtr, prevItem, FALSE, TRUE);
5021 = TREEVIEW_GetListItem(infoPtr, prevItem,
5022 -TREEVIEW_GetVisibleCount(infoPtr));
5027 = TREEVIEW_GetListItem(infoPtr, prevItem,
5028 TREEVIEW_GetVisibleCount(infoPtr));
5032 newSelection = prevItem->parent;
5033 if (newSelection == infoPtr->root)
5034 newSelection = NULL;
5038 if (infoPtr->dwStyle & TVS_CHECKBOXES)
5039 TREEVIEW_ToggleItemState(infoPtr, prevItem);
5043 if (newSelection && newSelection != prevItem)
5045 if (TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, newSelection,
5048 TREEVIEW_EnsureVisible(infoPtr, newSelection, FALSE);
5056 TREEVIEW_Notify(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5058 LPNMHDR lpnmh = (LPNMHDR)lParam;
5060 if (lpnmh->code == PGN_CALCSIZE) {
5061 LPNMPGCALCSIZE lppgc = (LPNMPGCALCSIZE)lParam;
5063 if (lppgc->dwFlag == PGF_CALCWIDTH) {
5064 lppgc->iWidth = infoPtr->treeWidth;
5065 TRACE("got PGN_CALCSIZE, returning horz size = %ld, client=%ld\n",
5066 infoPtr->treeWidth, infoPtr->clientWidth);
5069 lppgc->iHeight = infoPtr->treeHeight;
5070 TRACE("got PGN_CALCSIZE, returning vert size = %ld, client=%ld\n",
5071 infoPtr->treeHeight, infoPtr->clientHeight);
5075 return DefWindowProcA(infoPtr->hwnd, WM_NOTIFY, wParam, lParam);
5078 static INT TREEVIEW_NotifyFormat (TREEVIEW_INFO *infoPtr, HWND hwndFrom, UINT nCommand)
5082 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom, nCommand);
5084 if (nCommand != NF_REQUERY) return 0;
5086 format = SendMessageW(hwndFrom, WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwnd, NF_QUERY);
5087 TRACE("format=%d\n", format);
5089 if (format != NFR_ANSI && format != NFR_UNICODE) return 0;
5091 infoPtr->bNtfUnicode = (format == NFR_UNICODE);
5097 TREEVIEW_Size(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5099 if (wParam == SIZE_RESTORED)
5101 infoPtr->clientWidth = (short)LOWORD(lParam);
5102 infoPtr->clientHeight = (short)HIWORD(lParam);
5104 TREEVIEW_RecalculateVisibleOrder(infoPtr, NULL);
5105 TREEVIEW_SetFirstVisible(infoPtr, infoPtr->firstVisible, TRUE);
5106 TREEVIEW_UpdateScrollBars(infoPtr);
5110 FIXME("WM_SIZE flag %x %lx not handled\n", wParam, lParam);
5113 TREEVIEW_Invalidate(infoPtr, NULL);
5118 TREEVIEW_StyleChanged(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
5120 TRACE("(%x %lx)\n", wParam, lParam);
5122 if (wParam == GWL_STYLE)
5124 DWORD dwNewStyle = ((LPSTYLESTRUCT)lParam)->styleNew;
5126 /* we have to take special care about tooltips */
5127 if ((infoPtr->dwStyle ^ dwNewStyle) & TVS_NOTOOLTIPS)
5129 if (infoPtr->dwStyle & TVS_NOTOOLTIPS)
5131 infoPtr->hwndToolTip = COMCTL32_CreateToolTip(infoPtr->hwnd);
5136 DestroyWindow(infoPtr->hwndToolTip);
5137 infoPtr->hwndToolTip = 0;
5141 infoPtr->dwStyle = dwNewStyle;
5144 TREEVIEW_UpdateSubTree(infoPtr, infoPtr->root);
5145 TREEVIEW_UpdateScrollBars(infoPtr);
5146 TREEVIEW_Invalidate(infoPtr, NULL);
5152 TREEVIEW_SetFocus(TREEVIEW_INFO *infoPtr)
5156 if (!infoPtr->selectedItem)
5158 TREEVIEW_DoSelectItem(infoPtr, TVGN_CARET, infoPtr->firstVisible,
5162 TREEVIEW_SendSimpleNotify(infoPtr, NM_SETFOCUS);
5163 TREEVIEW_Invalidate(infoPtr, infoPtr->selectedItem);
5168 TREEVIEW_KillFocus(TREEVIEW_INFO *infoPtr)
5172 TREEVIEW_SendSimpleNotify(infoPtr, NM_KILLFOCUS);
5173 TREEVIEW_Invalidate(infoPtr, infoPtr->selectedItem);
5178 static LRESULT WINAPI
5179 TREEVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
5181 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(hwnd);
5183 TRACE("hwnd %p msg %04x wp=%08x lp=%08lx\n", hwnd, uMsg, wParam, lParam);
5185 if (infoPtr) TREEVIEW_VerifyTree(infoPtr);
5188 if (uMsg == WM_CREATE)
5189 TREEVIEW_Create(hwnd, (LPCREATESTRUCTW)lParam);
5196 case TVM_CREATEDRAGIMAGE:
5197 return TREEVIEW_CreateDragImage(infoPtr, wParam, lParam);
5199 case TVM_DELETEITEM:
5200 return TREEVIEW_DeleteItem(infoPtr, (HTREEITEM)lParam);
5202 case TVM_EDITLABELA:
5203 return (LRESULT)TREEVIEW_EditLabel(infoPtr, (HTREEITEM)lParam);
5205 case TVM_EDITLABELW:
5206 return (LRESULT)TREEVIEW_EditLabel(infoPtr, (HTREEITEM)lParam);
5208 case TVM_ENDEDITLABELNOW:
5209 return TREEVIEW_EndEditLabelNow(infoPtr, (BOOL)wParam);
5211 case TVM_ENSUREVISIBLE:
5212 return TREEVIEW_EnsureVisible(infoPtr, (HTREEITEM)lParam, TRUE);
5215 return TREEVIEW_ExpandMsg(infoPtr, (UINT)wParam, (HTREEITEM)lParam);
5217 case TVM_GETBKCOLOR:
5218 return TREEVIEW_GetBkColor(infoPtr);
5221 return TREEVIEW_GetCount(infoPtr);
5223 case TVM_GETEDITCONTROL:
5224 return TREEVIEW_GetEditControl(infoPtr);
5226 case TVM_GETIMAGELIST:
5227 return TREEVIEW_GetImageList(infoPtr, wParam);
5230 return TREEVIEW_GetIndent(infoPtr);
5232 case TVM_GETINSERTMARKCOLOR:
5233 return TREEVIEW_GetInsertMarkColor(infoPtr);
5235 case TVM_GETISEARCHSTRINGA:
5236 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5239 case TVM_GETISEARCHSTRINGW:
5240 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5244 return TREEVIEW_GetItemT(infoPtr, (LPTVITEMEXW)lParam, FALSE);
5247 return TREEVIEW_GetItemT(infoPtr, (LPTVITEMEXW)lParam, TRUE);
5249 case TVM_GETITEMHEIGHT:
5250 return TREEVIEW_GetItemHeight(infoPtr);
5252 case TVM_GETITEMRECT:
5253 return TREEVIEW_GetItemRect(infoPtr, (BOOL)wParam, (LPRECT)lParam);
5255 case TVM_GETITEMSTATE:
5256 return TREEVIEW_GetItemState(infoPtr, (HTREEITEM)wParam, (UINT)lParam);
5258 case TVM_GETLINECOLOR:
5259 return TREEVIEW_GetLineColor(infoPtr);
5261 case TVM_GETNEXTITEM:
5262 return TREEVIEW_GetNextItem(infoPtr, (UINT)wParam, (HTREEITEM)lParam);
5264 case TVM_GETSCROLLTIME:
5265 return TREEVIEW_GetScrollTime(infoPtr);
5267 case TVM_GETTEXTCOLOR:
5268 return TREEVIEW_GetTextColor(infoPtr);
5270 case TVM_GETTOOLTIPS:
5271 return TREEVIEW_GetToolTips(infoPtr);
5273 case TVM_GETUNICODEFORMAT:
5274 return TREEVIEW_GetUnicodeFormat(infoPtr);
5276 case TVM_GETVISIBLECOUNT:
5277 return TREEVIEW_GetVisibleCount(infoPtr);
5280 return TREEVIEW_HitTest(infoPtr, (LPTVHITTESTINFO)lParam);
5282 case TVM_INSERTITEMA:
5283 return TREEVIEW_InsertItemA(infoPtr, lParam);
5285 case TVM_INSERTITEMW:
5286 return TREEVIEW_InsertItemW(infoPtr, lParam);
5288 case TVM_SELECTITEM:
5289 return TREEVIEW_SelectItem(infoPtr, (INT)wParam, (HTREEITEM)lParam);
5291 case TVM_SETBKCOLOR:
5292 return TREEVIEW_SetBkColor(infoPtr, (COLORREF)lParam);
5294 case TVM_SETIMAGELIST:
5295 return TREEVIEW_SetImageList(infoPtr, wParam, (HIMAGELIST)lParam);
5298 return TREEVIEW_SetIndent(infoPtr, (UINT)wParam);
5300 case TVM_SETINSERTMARK:
5301 return TREEVIEW_SetInsertMark(infoPtr, (BOOL)wParam, (HTREEITEM)lParam);
5303 case TVM_SETINSERTMARKCOLOR:
5304 return TREEVIEW_SetInsertMarkColor(infoPtr, (COLORREF)lParam);
5307 return TREEVIEW_SetItemA(infoPtr, (LPTVITEMEXA)lParam);
5310 return TREEVIEW_SetItemW(infoPtr, (LPTVITEMEXW)lParam);
5312 case TVM_SETLINECOLOR:
5313 return TREEVIEW_SetLineColor(infoPtr, (COLORREF)lParam);
5315 case TVM_SETITEMHEIGHT:
5316 return TREEVIEW_SetItemHeight(infoPtr, (INT)(SHORT)wParam);
5318 case TVM_SETSCROLLTIME:
5319 return TREEVIEW_SetScrollTime(infoPtr, (UINT)wParam);
5321 case TVM_SETTEXTCOLOR:
5322 return TREEVIEW_SetTextColor(infoPtr, (COLORREF)lParam);
5324 case TVM_SETTOOLTIPS:
5325 return TREEVIEW_SetToolTips(infoPtr, (HWND)wParam);
5327 case TVM_SETUNICODEFORMAT:
5328 return TREEVIEW_SetUnicodeFormat(infoPtr, (BOOL)wParam);
5330 case TVM_SORTCHILDREN:
5331 return TREEVIEW_SortChildren(infoPtr, wParam, lParam);
5333 case TVM_SORTCHILDRENCB:
5334 return TREEVIEW_SortChildrenCB(infoPtr, wParam, (LPTVSORTCB)lParam);
5337 return TREEVIEW_ProcessLetterKeys( hwnd, wParam, lParam );
5340 return TREEVIEW_Command(infoPtr, wParam, lParam);
5343 return TREEVIEW_Destroy(infoPtr);
5348 return TREEVIEW_EraseBackground(infoPtr, (HDC)wParam);
5351 return DLGC_WANTARROWS | DLGC_WANTCHARS;
5354 return TREEVIEW_GetFont(infoPtr);
5357 return TREEVIEW_HScroll(infoPtr, wParam);
5360 return TREEVIEW_KeyDown(infoPtr, wParam);
5363 return TREEVIEW_KillFocus(infoPtr);
5365 case WM_LBUTTONDBLCLK:
5366 return TREEVIEW_LButtonDoubleClick(infoPtr, lParam);
5368 case WM_LBUTTONDOWN:
5369 return TREEVIEW_LButtonDown(infoPtr, lParam);
5371 /* WM_MBUTTONDOWN */
5376 return TREEVIEW_Notify(infoPtr, wParam, lParam);
5378 case WM_NOTIFYFORMAT:
5379 return TREEVIEW_NotifyFormat(infoPtr, (HWND)wParam, (UINT)lParam);
5382 return TREEVIEW_Paint(infoPtr, wParam);
5384 /* WM_PRINTCLIENT */
5386 case WM_RBUTTONDOWN:
5387 return TREEVIEW_RButtonDown(infoPtr, lParam);
5390 return TREEVIEW_SetFocus(infoPtr);
5393 return TREEVIEW_SetFont(infoPtr, (HFONT)wParam, (BOOL)lParam);
5396 return TREEVIEW_SetRedraw(infoPtr, wParam, lParam);
5399 return TREEVIEW_Size(infoPtr, wParam, lParam);
5401 case WM_STYLECHANGED:
5402 return TREEVIEW_StyleChanged(infoPtr, wParam, lParam);
5404 /* WM_SYSCOLORCHANGE */
5409 return TREEVIEW_HandleTimer(infoPtr, wParam);
5412 return TREEVIEW_VScroll(infoPtr, wParam);
5414 /* WM_WININICHANGE */
5417 if (wParam & (MK_SHIFT | MK_CONTROL))
5419 return TREEVIEW_MouseWheel(infoPtr, wParam);
5422 TRACE("drawItem\n");
5426 /* This mostly catches MFC and Delphi messages. :( */
5427 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
5428 TRACE("Unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
5430 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
5436 /* Class Registration ***************************************************/
5439 TREEVIEW_Register(void)
5445 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
5446 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
5447 wndClass.lpfnWndProc = (WNDPROC)TREEVIEW_WindowProc;
5448 wndClass.cbClsExtra = 0;
5449 wndClass.cbWndExtra = sizeof(TREEVIEW_INFO *);
5451 wndClass.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
5452 wndClass.hbrBackground = 0;
5453 wndClass.lpszClassName = WC_TREEVIEWA;
5455 RegisterClassA(&wndClass);
5460 TREEVIEW_Unregister(void)
5462 UnregisterClassA(WC_TREEVIEWA, NULL);
5466 /* Tree Verification ****************************************************/
5470 TREEVIEW_VerifyChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item);
5472 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO *infoPtr,
5473 TREEVIEW_ITEM *item)
5475 assert(infoPtr != NULL);
5476 assert(item != NULL);
5478 /* both NULL, or both non-null */
5479 assert((item->firstChild == NULL) == (item->lastChild == NULL));
5481 assert(item->firstChild != item);
5482 assert(item->lastChild != item);
5484 if (item->firstChild)
5486 assert(item->firstChild->parent == item);
5487 assert(item->firstChild->prevSibling == NULL);
5490 if (item->lastChild)
5492 assert(item->lastChild->parent == item);
5493 assert(item->lastChild->nextSibling == NULL);
5496 assert(item->nextSibling != item);
5497 if (item->nextSibling)
5499 assert(item->nextSibling->parent == item->parent);
5500 assert(item->nextSibling->prevSibling == item);
5503 assert(item->prevSibling != item);
5504 if (item->prevSibling)
5506 assert(item->prevSibling->parent == item->parent);
5507 assert(item->prevSibling->nextSibling == item);
5512 TREEVIEW_VerifyItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
5514 assert(item != NULL);
5516 assert(item->parent != NULL);
5517 assert(item->parent != item);
5518 assert(item->iLevel == item->parent->iLevel + 1);
5520 assert(DPA_GetPtrIndex(infoPtr->items, item) != -1);
5522 TREEVIEW_VerifyItemCommon(infoPtr, item);
5524 TREEVIEW_VerifyChildren(infoPtr, item);
5528 TREEVIEW_VerifyChildren(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
5530 TREEVIEW_ITEM *child;
5531 assert(item != NULL);
5533 for (child = item->firstChild; child != NULL; child = child->nextSibling)
5534 TREEVIEW_VerifyItem(infoPtr, child);
5538 TREEVIEW_VerifyRoot(TREEVIEW_INFO *infoPtr)
5540 TREEVIEW_ITEM *root = infoPtr->root;
5542 assert(root != NULL);
5543 assert(root->iLevel == -1);
5544 assert(root->parent == NULL);
5545 assert(root->prevSibling == NULL);
5547 TREEVIEW_VerifyItemCommon(infoPtr, root);
5549 TREEVIEW_VerifyChildren(infoPtr, root);
5553 TREEVIEW_VerifyTree(TREEVIEW_INFO *infoPtr)
5555 assert(infoPtr != NULL);
5557 TREEVIEW_VerifyRoot(infoPtr);