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
24 * Note that TREEVIEW_INFO * and HTREEITEM are the same thing.
26 * Note2: All items always! have valid (allocated) pszText field.
27 * If item's text == LPSTR_TEXTCALLBACKA we allocate buffer
28 * of size TEXT_CALLBACK_SIZE in DoSetItem.
29 * We use callbackMask to keep track of fields to be updated.
32 * missing notifications: NM_SETCURSOR, TVN_GETINFOTIP, TVN_KEYDOWN,
33 * TVN_SETDISPINFO, TVN_SINGLEEXPAND
35 * missing styles: TVS_FULLROWSELECT, TVS_INFOTIP, TVS_RTLREADING,
37 * missing item styles: TVIS_CUT, TVIS_EXPANDPARTIAL
39 * Make the insertion mark look right.
40 * Scroll (instead of repaint) as much as possible.
44 #include "wine/port.h"
53 #define NONAMELESSUNION
54 #define NONAMELESSSTRUCT
64 #include "wine/unicode.h"
65 #include "wine/debug.h"
67 /* internal structures */
69 typedef struct _TREEITEM
/* HTREEITEM is a _TREEINFO *. */
80 int iIntegral
; /* item height multiplier (1 is normal) */
81 int iLevel
; /* indentation level:0=root level */
82 HTREEITEM parent
; /* handle to parent or 0 if at root */
83 HTREEITEM firstChild
; /* handle to first child or 0 if no child */
85 HTREEITEM prevSibling
; /* handle to prev item in list, 0 if first */
86 HTREEITEM nextSibling
; /* handle to next item in list, 0 if last */
92 LONG textWidth
; /* horizontal text extent for pszText */
93 LONG visibleOrder
; /* visible ordering, 0 is first visible item */
97 typedef struct tagTREEVIEW_INFO
100 HWND hwndNotify
; /* Owner window to send notifications to */
103 UINT uInternalStatus
;
105 UINT uNumItems
; /* number of valid TREEVIEW_ITEMs */
106 INT cdmode
; /* last custom draw setting */
107 UINT uScrollTime
; /* max. time for scrolling in milliseconds */
108 BOOL bRedraw
; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
110 UINT uItemHeight
; /* item height */
113 LONG clientWidth
; /* width of control window */
114 LONG clientHeight
; /* height of control window */
116 LONG treeWidth
; /* width of visible tree items */
117 LONG treeHeight
; /* height of visible tree items */
119 UINT uIndent
; /* indentation in pixels */
120 HTREEITEM selectedItem
; /* handle to selected item or 0 if none */
121 HTREEITEM hotItem
; /* handle currently under cursor, 0 if none */
122 HTREEITEM focusedItem
; /* item that was under the cursor when WM_LBUTTONDOWN was received */
124 HTREEITEM firstVisible
; /* handle to first visible item */
125 LONG maxVisibleOrder
;
126 HTREEITEM dropItem
; /* handle to item selected by drag cursor */
127 HTREEITEM insertMarkItem
; /* item after which insertion mark is placed */
128 BOOL insertBeforeorAfter
; /* flag used by TVM_SETINSERTMARK */
129 HIMAGELIST dragList
; /* Bitmap of dragged item */
134 COLORREF clrInsertMark
;
138 HFONT hUnderlineFont
;
143 WNDPROC wpEditOrig
; /* orig window proc for subclassing edit */
144 BOOL bIgnoreEditKillFocus
;
147 BOOL bNtfUnicode
; /* TRUE if should send NOTIFY with W */
148 HIMAGELIST himlNormal
;
149 int normalImageHeight
;
150 int normalImageWidth
;
151 HIMAGELIST himlState
;
152 int stateImageHeight
;
156 DWORD lastKeyPressTimestamp
; /* Added */
157 WPARAM charCode
; /* Added */
158 INT nSearchParamLength
; /* Added */
159 WCHAR szSearchParam
[ MAX_PATH
]; /* Added */
163 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
164 #define KEY_DELAY 450
166 /* bitflags for infoPtr->uInternalStatus */
168 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
169 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
170 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
171 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
172 #define TV_RDRAG 0x10 /* dito Rbutton */
173 #define TV_RDRAGGING 0x20
175 /* bitflags for infoPtr->timer */
177 #define TV_EDIT_TIMER 2
178 #define TV_EDIT_TIMER_SET 2
181 VOID
TREEVIEW_Register (VOID
);
182 VOID
TREEVIEW_Unregister (VOID
);
185 WINE_DEFAULT_DEBUG_CHANNEL(treeview
);
188 #define TEXT_CALLBACK_SIZE 260
190 #define TREEVIEW_LEFT_MARGIN 8
192 #define MINIMUM_INDENT 19
194 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
196 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
197 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
198 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
201 static const WCHAR themeClass
[] = { 'T','r','e','e','v','i','e','w',0 };
204 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
207 static VOID
TREEVIEW_Invalidate(TREEVIEW_INFO
*, TREEVIEW_ITEM
*);
209 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
210 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
211 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
212 static LRESULT
TREEVIEW_RButtonUp(TREEVIEW_INFO
*, LPPOINT
);
213 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
214 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
215 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
216 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND wParam
, UINT lParam
);
219 /* Random Utilities *****************************************************/
223 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
228 /* The definition is at the end of the file. */
229 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
232 /* Returns the treeview private data if hwnd is a treeview.
233 * Otherwise returns an undefined value. */
234 static TREEVIEW_INFO
*
235 TREEVIEW_GetInfoPtr(HWND hwnd
)
237 return (TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
240 /* Don't call this. Nothing wants an item index. */
242 TREEVIEW_GetItemIndex(TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
244 assert(infoPtr
!= NULL
);
246 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
249 /* Checks if item has changed and needs to be redrawn */
250 static inline BOOL
item_changed (TREEVIEW_ITEM
*tiOld
, TREEVIEW_ITEM
*tiNew
, LPTVITEMEXW tvChange
)
252 /* Number of children has changed */
253 if ((tvChange
->mask
& TVIF_CHILDREN
) && (tiOld
->cChildren
!= tiNew
->cChildren
))
256 /* Image has changed and it's not a callback */
257 if ((tvChange
->mask
& TVIF_IMAGE
) && (tiOld
->iImage
!= tiNew
->iImage
) &&
258 tiNew
->iImage
!= I_IMAGECALLBACK
)
261 /* Selected image has changed and it's not a callback */
262 if ((tvChange
->mask
& TVIF_SELECTEDIMAGE
) && (tiOld
->iSelectedImage
!= tiNew
->iSelectedImage
) &&
263 tiNew
->iSelectedImage
!= I_IMAGECALLBACK
)
266 /* Text has changed and it's not a callback */
267 if ((tvChange
->mask
& TVIF_TEXT
) && (tiOld
->pszText
!= tiNew
->pszText
) &&
268 tiNew
->pszText
!= LPSTR_TEXTCALLBACKW
)
271 /* Indent has changed */
272 if ((tvChange
->mask
& TVIF_INTEGRAL
) && (tiOld
->iIntegral
!= tiNew
->iIntegral
))
275 /* Item state has changed */
276 if ((tvChange
->mask
& TVIF_STATE
) && ((tiOld
->state
^ tiNew
->state
) & tvChange
->stateMask
))
282 /***************************************************************************
283 * This method checks that handle is an item for this tree.
286 TREEVIEW_ValidItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
288 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
290 TRACE("invalid item %p\n", handle
);
298 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
302 GetObjectW(hOrigFont
, sizeof(font
), &font
);
303 font
.lfWeight
= FW_BOLD
;
304 return CreateFontIndirectW(&font
);
308 TREEVIEW_CreateUnderlineFont(HFONT hOrigFont
)
312 GetObjectW(hOrigFont
, sizeof(font
), &font
);
313 font
.lfUnderline
= TRUE
;
314 return CreateFontIndirectW(&font
);
318 TREEVIEW_FontForItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
320 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
321 return infoPtr
->hUnderlineFont
;
322 if (item
->state
& TVIS_BOLD
)
323 return infoPtr
->hBoldFont
;
324 return infoPtr
->hFont
;
327 /* for trace/debugging purposes only */
329 TREEVIEW_ItemName(TREEVIEW_ITEM
*item
)
331 if (item
== NULL
) return "<null item>";
332 if (item
->pszText
== LPSTR_TEXTCALLBACKW
) return "<callback>";
333 if (item
->pszText
== NULL
) return "<null>";
334 return debugstr_w(item
->pszText
);
337 /* An item is not a child of itself. */
339 TREEVIEW_IsChildOf(TREEVIEW_ITEM
*parent
, TREEVIEW_ITEM
*child
)
343 child
= child
->parent
;
344 if (child
== parent
) return TRUE
;
345 } while (child
!= NULL
);
351 /* Tree Traversal *******************************************************/
353 /***************************************************************************
354 * This method returns the last expanded sibling or child child item
357 static TREEVIEW_ITEM
*
358 TREEVIEW_GetLastListItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
363 while (wineItem
->lastChild
)
365 if (wineItem
->state
& TVIS_EXPANDED
)
366 wineItem
= wineItem
->lastChild
;
371 if (wineItem
== infoPtr
->root
)
377 /***************************************************************************
378 * This method returns the previous non-hidden item in the list not
379 * considering the tree hierarchy.
381 static TREEVIEW_ITEM
*
382 TREEVIEW_GetPrevListItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*tvItem
)
384 if (tvItem
->prevSibling
)
386 /* This item has a prevSibling, get the last item in the sibling's tree. */
387 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
389 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
390 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
396 /* this item does not have a prevSibling, get the parent */
397 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
402 /***************************************************************************
403 * This method returns the next physical item in the treeview not
404 * considering the tree hierarchy.
406 static TREEVIEW_ITEM
*
407 TREEVIEW_GetNextListItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*tvItem
)
409 assert(tvItem
!= NULL
);
412 * If this item has children and is expanded, return the first child
414 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
416 return tvItem
->firstChild
;
421 * try to get the sibling
423 if (tvItem
->nextSibling
)
424 return tvItem
->nextSibling
;
427 * Otherwise, get the parent's sibling.
429 while (tvItem
->parent
)
431 tvItem
= tvItem
->parent
;
433 if (tvItem
->nextSibling
)
434 return tvItem
->nextSibling
;
440 /***************************************************************************
441 * This method returns the nth item starting at the given item. It returns
442 * the last item (or first) we we run out of items.
444 * Will scroll backward if count is <0.
445 * forward if count is >0.
447 static TREEVIEW_ITEM
*
448 TREEVIEW_GetListItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
451 TREEVIEW_ITEM
*(*next_item
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*);
452 TREEVIEW_ITEM
*previousItem
;
454 assert(wineItem
!= NULL
);
458 next_item
= TREEVIEW_GetNextListItem
;
463 next_item
= TREEVIEW_GetPrevListItem
;
470 previousItem
= wineItem
;
471 wineItem
= next_item(infoPtr
, wineItem
);
473 } while (--count
&& wineItem
!= NULL
);
476 return wineItem
? wineItem
: previousItem
;
479 /* Notifications ************************************************************/
481 static INT
get_notifycode(TREEVIEW_INFO
*infoPtr
, INT code
)
483 if (!infoPtr
->bNtfUnicode
) {
485 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
486 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
487 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
488 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
489 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
490 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
491 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
492 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
493 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
494 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
495 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
496 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
503 TREEVIEW_SendRealNotify(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
505 TRACE("wParam=%d, lParam=%ld\n", wParam
, lParam
);
506 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, wParam
, lParam
);
510 TREEVIEW_SendSimpleNotify(TREEVIEW_INFO
*infoPtr
, UINT code
)
513 HWND hwnd
= infoPtr
->hwnd
;
516 nmhdr
.hwndFrom
= hwnd
;
517 nmhdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
518 nmhdr
.code
= get_notifycode(infoPtr
, code
);
520 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
521 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
525 TREEVIEW_TVItemFromItem(TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMW
*tvItem
, TREEVIEW_ITEM
*item
)
528 tvItem
->hItem
= item
;
529 tvItem
->state
= item
->state
;
530 tvItem
->stateMask
= 0;
531 tvItem
->iImage
= item
->iImage
;
532 tvItem
->iSelectedImage
= item
->iSelectedImage
;
533 tvItem
->cChildren
= item
->cChildren
;
534 tvItem
->lParam
= item
->lParam
;
538 if (!infoPtr
->bNtfUnicode
)
540 tvItem
->cchTextMax
= WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0, NULL
, NULL
);
541 tvItem
->pszText
= Alloc (tvItem
->cchTextMax
);
542 WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, 0, 0 );
546 tvItem
->cchTextMax
= item
->cchTextMax
;
547 tvItem
->pszText
= item
->pszText
;
552 tvItem
->cchTextMax
= 0;
553 tvItem
->pszText
= NULL
;
558 TREEVIEW_SendTreeviewNotify(TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
559 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
561 HWND hwnd
= infoPtr
->hwnd
;
565 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
566 code
, action
, oldItem
, newItem
);
568 ZeroMemory(&nmhdr
, sizeof(NMTREEVIEWW
));
570 nmhdr
.hdr
.hwndFrom
= hwnd
;
571 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
572 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
573 nmhdr
.action
= action
;
576 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
579 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
584 ret
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
585 (WPARAM
)nmhdr
.hdr
.idFrom
,
587 if (!infoPtr
->bNtfUnicode
)
589 Free(nmhdr
.itemOld
.pszText
);
590 Free(nmhdr
.itemNew
.pszText
);
596 TREEVIEW_SendTreeviewDnDNotify(TREEVIEW_INFO
*infoPtr
, UINT code
,
597 HTREEITEM dragItem
, POINT pt
)
599 HWND hwnd
= infoPtr
->hwnd
;
602 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
604 nmhdr
.hdr
.hwndFrom
= hwnd
;
605 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
606 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
608 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
609 nmhdr
.itemNew
.hItem
= dragItem
;
610 nmhdr
.itemNew
.state
= dragItem
->state
;
611 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
613 nmhdr
.ptDrag
.x
= pt
.x
;
614 nmhdr
.ptDrag
.y
= pt
.y
;
616 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
617 (WPARAM
)nmhdr
.hdr
.idFrom
,
623 TREEVIEW_SendCustomDrawNotify(TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
626 HWND hwnd
= infoPtr
->hwnd
;
627 NMTVCUSTOMDRAW nmcdhdr
;
630 TRACE("drawstage:%lx hdc:%p\n", dwDrawStage
, hdc
);
632 nmcd
= &nmcdhdr
.nmcd
;
633 nmcd
->hdr
.hwndFrom
= hwnd
;
634 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
635 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
636 nmcd
->dwDrawStage
= dwDrawStage
;
639 nmcd
->dwItemSpec
= 0;
640 nmcd
->uItemState
= 0;
641 nmcd
->lItemlParam
= 0;
642 nmcdhdr
.clrText
= infoPtr
->clrText
;
643 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
646 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
647 (WPARAM
)nmcd
->hdr
.idFrom
,
653 /* FIXME: need to find out when the flags in uItemState need to be set */
656 TREEVIEW_SendCustomDrawItemNotify(TREEVIEW_INFO
*infoPtr
, HDC hdc
,
657 TREEVIEW_ITEM
*wineItem
, UINT uItemDrawState
,
658 NMTVCUSTOMDRAW
*nmcdhdr
)
660 HWND hwnd
= infoPtr
->hwnd
;
663 DWORD_PTR dwItemSpec
;
667 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
668 dwItemSpec
= (DWORD_PTR
)wineItem
;
670 if (wineItem
->state
& TVIS_SELECTED
)
671 uItemState
|= CDIS_SELECTED
;
672 if (wineItem
== infoPtr
->selectedItem
)
673 uItemState
|= CDIS_FOCUS
;
674 if (wineItem
== infoPtr
->hotItem
)
675 uItemState
|= CDIS_HOT
;
677 nmcd
= &nmcdhdr
->nmcd
;
678 nmcd
->hdr
.hwndFrom
= hwnd
;
679 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
680 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
681 nmcd
->dwDrawStage
= dwDrawStage
;
683 nmcd
->rc
= wineItem
->rect
;
684 nmcd
->dwItemSpec
= dwItemSpec
;
685 nmcd
->uItemState
= uItemState
;
686 nmcd
->lItemlParam
= wineItem
->lParam
;
687 nmcdhdr
->iLevel
= wineItem
->iLevel
;
689 TRACE("drawstage:%lx hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
690 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
691 nmcd
->uItemState
, nmcd
->lItemlParam
);
693 retval
= TREEVIEW_SendRealNotify(infoPtr
,
694 (WPARAM
)nmcd
->hdr
.idFrom
,
701 TREEVIEW_BeginLabelEditNotify(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
703 HWND hwnd
= infoPtr
->hwnd
;
707 tvdi
.hdr
.hwndFrom
= hwnd
;
708 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
709 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_BEGINLABELEDITW
);
711 TREEVIEW_TVItemFromItem(infoPtr
, TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
,
712 &tvdi
.item
, editItem
);
714 ret
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, tvdi
.hdr
.idFrom
, (LPARAM
)&tvdi
);
716 if (!infoPtr
->bNtfUnicode
)
717 Free(tvdi
.item
.pszText
);
723 TREEVIEW_UpdateDispInfo(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
726 NMTVDISPINFOW callback
;
727 HWND hwnd
= infoPtr
->hwnd
;
729 TRACE("mask %x callbackMask %x\n", mask
, wineItem
->callbackMask
);
730 mask
&= wineItem
->callbackMask
;
732 if (mask
== 0) return;
734 callback
.hdr
.hwndFrom
= hwnd
;
735 callback
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
736 callback
.hdr
.code
= get_notifycode(infoPtr
, TVN_GETDISPINFOW
);
738 /* 'state' always contains valid value, as well as 'lParam'.
739 * All other parameters are uninitialized.
741 callback
.item
.pszText
= wineItem
->pszText
;
742 callback
.item
.cchTextMax
= wineItem
->cchTextMax
;
743 callback
.item
.mask
= mask
;
744 callback
.item
.hItem
= wineItem
;
745 callback
.item
.state
= wineItem
->state
;
746 callback
.item
.lParam
= wineItem
->lParam
;
748 /* If text is changed we need to recalculate textWidth */
749 if (mask
& TVIF_TEXT
)
750 wineItem
->textWidth
= 0;
752 TREEVIEW_SendRealNotify(infoPtr
,
753 (WPARAM
)callback
.hdr
.idFrom
, (LPARAM
)&callback
);
755 /* It may have changed due to a call to SetItem. */
756 mask
&= wineItem
->callbackMask
;
758 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= wineItem
->pszText
)
760 /* Instead of copying text into our buffer user specified its own */
761 if (!infoPtr
->bNtfUnicode
) {
764 int len
= MultiByteToWideChar( CP_ACP
, 0,
765 (LPSTR
)callback
.item
.pszText
, -1,
767 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
768 newText
= (LPWSTR
)ReAlloc(wineItem
->pszText
, buflen
);
770 TRACE("returned str %s, len=%d, buflen=%d\n",
771 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
775 wineItem
->pszText
= newText
;
776 MultiByteToWideChar( CP_ACP
, 0,
777 (LPSTR
)callback
.item
.pszText
, -1,
778 wineItem
->pszText
, buflen
/sizeof(WCHAR
));
779 wineItem
->cchTextMax
= buflen
/sizeof(WCHAR
);
781 /* If ReAlloc fails we have nothing to do, but keep original text */
784 int len
= max(lstrlenW(callback
.item
.pszText
) + 1,
786 LPWSTR newText
= ReAlloc(wineItem
->pszText
, len
);
788 TRACE("returned wstr %s, len=%d\n",
789 debugstr_w(callback
.item
.pszText
), len
);
793 wineItem
->pszText
= newText
;
794 strcpyW(wineItem
->pszText
, callback
.item
.pszText
);
795 wineItem
->cchTextMax
= len
;
797 /* If ReAlloc fails we have nothing to do, but keep original text */
800 else if (mask
& TVIF_TEXT
) {
801 /* User put text into our buffer, that is ok unless A string */
802 if (!infoPtr
->bNtfUnicode
) {
804 LPWSTR oldText
= NULL
;
806 int len
= MultiByteToWideChar( CP_ACP
, 0,
807 (LPSTR
)callback
.item
.pszText
, -1,
809 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
810 newText
= (LPWSTR
)Alloc(buflen
);
812 TRACE("same buffer str %s, len=%d, buflen=%d\n",
813 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
817 oldText
= wineItem
->pszText
;
818 wineItem
->pszText
= newText
;
819 MultiByteToWideChar( CP_ACP
, 0,
820 (LPSTR
)callback
.item
.pszText
, -1,
821 wineItem
->pszText
, buflen
/sizeof(WCHAR
));
822 wineItem
->cchTextMax
= buflen
/sizeof(WCHAR
);
829 if (mask
& TVIF_IMAGE
)
830 wineItem
->iImage
= callback
.item
.iImage
;
832 if (mask
& TVIF_SELECTEDIMAGE
)
833 wineItem
->iSelectedImage
= callback
.item
.iSelectedImage
;
835 if (mask
& TVIF_CHILDREN
)
836 wineItem
->cChildren
= callback
.item
.cChildren
;
838 /* These members are now permanently set. */
839 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
840 wineItem
->callbackMask
&= ~callback
.item
.mask
;
843 /***************************************************************************
844 * This function uses cChildren field to decide whether the item has
846 * Note: if this returns TRUE, the child items may not actually exist,
847 * they could be virtual.
849 * Just use wineItem->firstChild to check for physical children.
852 TREEVIEW_HasChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
854 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, TVIF_CHILDREN
);
856 return wineItem
->cChildren
> 0;
860 /* Item Position ********************************************************/
862 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
864 TREEVIEW_ComputeItemInternalMetrics(TREEVIEW_INFO
*infoPtr
,
867 /* Same effect, different optimisation. */
869 BOOL lar
= ((infoPtr
->dwStyle
& TVS_LINESATROOT
)
870 && (infoPtr
->dwStyle
& (TVS_HASLINES
|TVS_HASBUTTONS
)));
872 BOOL lar
= ((infoPtr
->dwStyle
873 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
877 item
->linesOffset
= infoPtr
->uIndent
* (item
->iLevel
+ lar
- 1)
879 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
880 item
->imageOffset
= item
->stateOffset
881 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
882 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
886 TREEVIEW_ComputeTextWidth(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
892 /* DRAW's OM docker creates items like this */
893 if (item
->pszText
== NULL
)
905 hdc
= GetDC(infoPtr
->hwnd
);
906 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
909 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
910 item
->textWidth
= sz
.cx
;
914 SelectObject(hdc
, hOldFont
);
920 TREEVIEW_ComputeItemRect(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
922 item
->rect
.top
= infoPtr
->uItemHeight
*
923 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
925 item
->rect
.bottom
= item
->rect
.top
926 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
929 item
->rect
.right
= infoPtr
->clientWidth
;
932 /* We know that only items after start need their order updated. */
934 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
941 start
= infoPtr
->root
->firstChild
;
945 order
= start
->visibleOrder
;
947 for (item
= start
; item
!= NULL
;
948 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
950 item
->visibleOrder
= order
;
951 order
+= item
->iIntegral
;
954 infoPtr
->maxVisibleOrder
= order
;
956 for (item
= start
; item
!= NULL
;
957 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
959 TREEVIEW_ComputeItemRect(infoPtr
, item
);
964 /* Update metrics of all items in selected subtree.
965 * root must be expanded
968 TREEVIEW_UpdateSubTree(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
970 TREEVIEW_ITEM
*sibling
;
974 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
977 root
->state
&= ~TVIS_EXPANDED
;
978 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
979 root
->state
|= TVIS_EXPANDED
;
981 hdc
= GetDC(infoPtr
->hwnd
);
982 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
984 for (; root
!= sibling
;
985 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
987 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
989 if (root
->callbackMask
& TVIF_TEXT
)
990 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
992 if (root
->textWidth
== 0)
994 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
995 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
999 SelectObject(hdc
, hOldFont
);
1000 ReleaseDC(infoPtr
->hwnd
, hdc
);
1003 /* Item Allocation **********************************************************/
1005 static TREEVIEW_ITEM
*
1006 TREEVIEW_AllocateItem(TREEVIEW_INFO
*infoPtr
)
1008 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
1013 newItem
->iImage
= -1;
1014 newItem
->iSelectedImage
= -1;
1016 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
1025 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
1026 * free item->pszText. */
1028 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1030 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
1032 if (infoPtr
->selectedItem
== item
)
1033 infoPtr
->selectedItem
= NULL
;
1034 if (infoPtr
->hotItem
== item
)
1035 infoPtr
->hotItem
= NULL
;
1036 if (infoPtr
->focusedItem
== item
)
1037 infoPtr
->focusedItem
= NULL
;
1038 if (infoPtr
->firstVisible
== item
)
1039 infoPtr
->firstVisible
= NULL
;
1040 if (infoPtr
->dropItem
== item
)
1041 infoPtr
->dropItem
= NULL
;
1042 if (infoPtr
->insertMarkItem
== item
)
1043 infoPtr
->insertMarkItem
= NULL
;
1047 /* Item Insertion *******************************************************/
1049 /***************************************************************************
1050 * This method inserts newItem before sibling as a child of parent.
1051 * sibling can be NULL, but only if parent has no children.
1054 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1055 TREEVIEW_ITEM
*parent
)
1057 assert(newItem
!= NULL
);
1058 assert(parent
!= NULL
);
1060 if (sibling
!= NULL
)
1062 assert(sibling
->parent
== parent
);
1064 if (sibling
->prevSibling
!= NULL
)
1065 sibling
->prevSibling
->nextSibling
= newItem
;
1067 newItem
->prevSibling
= sibling
->prevSibling
;
1068 sibling
->prevSibling
= newItem
;
1071 newItem
->prevSibling
= NULL
;
1073 newItem
->nextSibling
= sibling
;
1075 if (parent
->firstChild
== sibling
)
1076 parent
->firstChild
= newItem
;
1078 if (parent
->lastChild
== NULL
)
1079 parent
->lastChild
= newItem
;
1082 /***************************************************************************
1083 * This method inserts newItem after sibling as a child of parent.
1084 * sibling can be NULL, but only if parent has no children.
1087 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1088 TREEVIEW_ITEM
*parent
)
1090 assert(newItem
!= NULL
);
1091 assert(parent
!= NULL
);
1093 if (sibling
!= NULL
)
1095 assert(sibling
->parent
== parent
);
1097 if (sibling
->nextSibling
!= NULL
)
1098 sibling
->nextSibling
->prevSibling
= newItem
;
1100 newItem
->nextSibling
= sibling
->nextSibling
;
1101 sibling
->nextSibling
= newItem
;
1104 newItem
->nextSibling
= NULL
;
1106 newItem
->prevSibling
= sibling
;
1108 if (parent
->lastChild
== sibling
)
1109 parent
->lastChild
= newItem
;
1111 if (parent
->firstChild
== NULL
)
1112 parent
->firstChild
= newItem
;
1116 TREEVIEW_DoSetItemT(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
1117 const TVITEMEXW
*tvItem
, BOOL isW
)
1119 UINT callbackClear
= 0;
1120 UINT callbackSet
= 0;
1122 TRACE("item %p\n", wineItem
);
1123 /* Do this first in case it fails. */
1124 if (tvItem
->mask
& TVIF_TEXT
)
1126 wineItem
->textWidth
= 0; /* force width recalculation */
1127 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers != TEXTCALLBACKA too */
1132 len
= lstrlenW(tvItem
->pszText
) + 1;
1134 len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1, NULL
, 0);
1136 newText
= ReAlloc(wineItem
->pszText
, len
* sizeof(WCHAR
));
1138 if (newText
== NULL
) return FALSE
;
1140 callbackClear
|= TVIF_TEXT
;
1142 wineItem
->pszText
= newText
;
1143 wineItem
->cchTextMax
= len
;
1145 lstrcpynW(wineItem
->pszText
, tvItem
->pszText
, len
);
1147 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1,
1148 wineItem
->pszText
, len
);
1150 TRACE("setting text %s, item %p\n", debugstr_w(wineItem
->pszText
), wineItem
);
1154 callbackSet
|= TVIF_TEXT
;
1156 wineItem
->pszText
= ReAlloc(wineItem
->pszText
,
1157 TEXT_CALLBACK_SIZE
* sizeof(WCHAR
));
1158 wineItem
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1159 TRACE("setting callback, item %p\n", wineItem
);
1163 if (tvItem
->mask
& TVIF_CHILDREN
)
1165 wineItem
->cChildren
= tvItem
->cChildren
;
1167 if (wineItem
->cChildren
== I_CHILDRENCALLBACK
)
1168 callbackSet
|= TVIF_CHILDREN
;
1170 callbackClear
|= TVIF_CHILDREN
;
1173 if (tvItem
->mask
& TVIF_IMAGE
)
1175 wineItem
->iImage
= tvItem
->iImage
;
1177 if (wineItem
->iImage
== I_IMAGECALLBACK
)
1178 callbackSet
|= TVIF_IMAGE
;
1180 callbackClear
|= TVIF_IMAGE
;
1183 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1185 wineItem
->iSelectedImage
= tvItem
->iSelectedImage
;
1187 if (wineItem
->iSelectedImage
== I_IMAGECALLBACK
)
1188 callbackSet
|= TVIF_SELECTEDIMAGE
;
1190 callbackClear
|= TVIF_SELECTEDIMAGE
;
1193 if (tvItem
->mask
& TVIF_PARAM
)
1194 wineItem
->lParam
= tvItem
->lParam
;
1196 /* If the application sets TVIF_INTEGRAL without
1197 * supplying a TVITEMEX structure, it's toast. */
1198 if (tvItem
->mask
& TVIF_INTEGRAL
)
1199 wineItem
->iIntegral
= tvItem
->iIntegral
;
1201 if (tvItem
->mask
& TVIF_STATE
)
1203 TRACE("prevstate,state,mask:%x,%x,%x\n", wineItem
->state
, tvItem
->state
,
1205 wineItem
->state
&= ~tvItem
->stateMask
;
1206 wineItem
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1209 wineItem
->callbackMask
|= callbackSet
;
1210 wineItem
->callbackMask
&= ~callbackClear
;
1215 /* Note that the new item is pre-zeroed. */
1217 TREEVIEW_InsertItemT(TREEVIEW_INFO
*infoPtr
, const TVINSERTSTRUCTW
*ptdi
, BOOL isW
)
1219 const TVITEMEXW
*tvItem
= &ptdi
->u
.itemex
;
1220 HTREEITEM insertAfter
;
1221 TREEVIEW_ITEM
*newItem
, *parentItem
;
1222 BOOL bTextUpdated
= FALSE
;
1224 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1226 parentItem
= infoPtr
->root
;
1230 parentItem
= ptdi
->hParent
;
1232 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1234 WARN("invalid parent %p\n", parentItem
);
1235 return (LRESULT
)(HTREEITEM
)NULL
;
1239 insertAfter
= ptdi
->hInsertAfter
;
1241 /* Validate this now for convenience. */
1242 switch ((DWORD_PTR
)insertAfter
)
1244 case (DWORD_PTR
)TVI_FIRST
:
1245 case (DWORD_PTR
)TVI_LAST
:
1246 case (DWORD_PTR
)TVI_SORT
:
1250 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1251 insertAfter
->parent
!= parentItem
)
1253 WARN("invalid insert after %p\n", insertAfter
);
1254 insertAfter
= TVI_LAST
;
1258 TRACE("parent %p position %p: %s\n", parentItem
, insertAfter
,
1259 (tvItem
->mask
& TVIF_TEXT
)
1260 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKW
) ? "<callback>"
1261 : (isW
? debugstr_w(tvItem
->pszText
) : debugstr_a((LPSTR
)tvItem
->pszText
)))
1264 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1265 if (newItem
== NULL
)
1266 return (LRESULT
)(HTREEITEM
)NULL
;
1268 newItem
->parent
= parentItem
;
1269 newItem
->iIntegral
= 1;
1271 if (!TREEVIEW_DoSetItemT(infoPtr
, newItem
, tvItem
, isW
))
1272 return (LRESULT
)(HTREEITEM
)NULL
;
1274 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1276 infoPtr
->uNumItems
++;
1278 switch ((DWORD_PTR
)insertAfter
)
1280 case (DWORD_PTR
)TVI_FIRST
:
1282 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1283 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1284 if (infoPtr
->firstVisible
== originalFirst
)
1285 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1289 case (DWORD_PTR
)TVI_LAST
:
1290 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1293 /* hInsertAfter names a specific item we want to insert after */
1295 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1298 case (DWORD_PTR
)TVI_SORT
:
1300 TREEVIEW_ITEM
*aChild
;
1301 TREEVIEW_ITEM
*previousChild
= NULL
;
1302 BOOL bItemInserted
= FALSE
;
1304 aChild
= parentItem
->firstChild
;
1306 bTextUpdated
= TRUE
;
1307 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1309 /* Iterate the parent children to see where we fit in */
1310 while (aChild
!= NULL
)
1314 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1315 comp
= lstrcmpW(newItem
->pszText
, aChild
->pszText
);
1317 if (comp
< 0) /* we are smaller than the current one */
1319 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1320 bItemInserted
= TRUE
;
1323 else if (comp
> 0) /* we are bigger than the current one */
1325 previousChild
= aChild
;
1327 /* This will help us to exit if there is no more sibling */
1328 aChild
= (aChild
->nextSibling
== 0)
1330 : aChild
->nextSibling
;
1332 /* Look at the next item */
1338 * An item with this name is already existing, therefore,
1339 * we add after the one we found
1341 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1342 bItemInserted
= TRUE
;
1348 * we reach the end of the child list and the item has not
1349 * yet been inserted, therefore, insert it after the last child.
1351 if ((!bItemInserted
) && (aChild
== NULL
))
1352 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1359 TRACE("new item %p; parent %p, mask %x\n", newItem
,
1360 newItem
->parent
, tvItem
->mask
);
1362 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1364 if (newItem
->parent
->cChildren
== 0)
1365 newItem
->parent
->cChildren
= 1;
1367 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1369 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1370 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1373 if (infoPtr
->firstVisible
== NULL
)
1374 infoPtr
->firstVisible
= newItem
;
1376 TREEVIEW_VerifyTree(infoPtr
);
1378 if (parentItem
== infoPtr
->root
||
1379 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1381 TREEVIEW_ITEM
*item
;
1382 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1384 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1385 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1388 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1390 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1391 TREEVIEW_UpdateScrollBars(infoPtr
);
1393 * if the item was inserted in a visible part of the tree,
1394 * invalidate it, as well as those after it
1396 for (item
= newItem
;
1398 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1399 TREEVIEW_Invalidate(infoPtr
, item
);
1403 newItem
->visibleOrder
= -1;
1405 /* refresh treeview if newItem is the first item inserted under parentItem */
1406 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1408 /* parent got '+' - update it */
1409 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1413 return (LRESULT
)newItem
;
1416 /* Item Deletion ************************************************************/
1418 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
);
1421 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*parentItem
)
1423 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1425 while (kill
!= NULL
)
1427 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1429 TREEVIEW_RemoveItem(infoPtr
, kill
);
1434 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1435 assert(parentItem
->firstChild
== NULL
);
1436 assert(parentItem
->lastChild
== NULL
);
1440 TREEVIEW_UnlinkItem(TREEVIEW_ITEM
*item
)
1442 TREEVIEW_ITEM
*parentItem
= item
->parent
;
1444 assert(item
!= NULL
);
1445 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1447 if (parentItem
->firstChild
== item
)
1448 parentItem
->firstChild
= item
->nextSibling
;
1450 if (parentItem
->lastChild
== item
)
1451 parentItem
->lastChild
= item
->prevSibling
;
1453 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1454 && parentItem
->cChildren
> 0)
1455 parentItem
->cChildren
= 0;
1457 if (item
->prevSibling
)
1458 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1460 if (item
->nextSibling
)
1461 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1465 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
1467 TRACE("%p, (%s)\n", wineItem
, TREEVIEW_ItemName(wineItem
));
1469 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1470 TVIF_HANDLE
| TVIF_PARAM
, wineItem
, 0);
1472 if (wineItem
->firstChild
)
1473 TREEVIEW_RemoveAllChildren(infoPtr
, wineItem
);
1475 TREEVIEW_UnlinkItem(wineItem
);
1477 infoPtr
->uNumItems
--;
1479 if (wineItem
->pszText
&& wineItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
1480 Free(wineItem
->pszText
);
1482 TREEVIEW_FreeItem(infoPtr
, wineItem
);
1486 /* Empty out the tree. */
1488 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1490 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1492 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1496 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM wineItem
)
1498 TREEVIEW_ITEM
*newSelection
= NULL
;
1499 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1500 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1501 BOOL visible
= FALSE
;
1503 if (wineItem
== TVI_ROOT
)
1505 TRACE("TVI_ROOT\n");
1506 parent
= infoPtr
->root
;
1507 newSelection
= NULL
;
1509 TREEVIEW_RemoveTree(infoPtr
);
1513 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
1516 TRACE("%p (%s)\n", wineItem
, TREEVIEW_ItemName(wineItem
));
1517 parent
= wineItem
->parent
;
1519 if (ISVISIBLE(wineItem
))
1521 prev
= TREEVIEW_GetPrevListItem(infoPtr
, wineItem
);
1525 if (infoPtr
->selectedItem
!= NULL
1526 && (wineItem
== infoPtr
->selectedItem
1527 || TREEVIEW_IsChildOf(wineItem
, infoPtr
->selectedItem
)))
1529 if (wineItem
->nextSibling
)
1530 newSelection
= wineItem
->nextSibling
;
1531 else if (wineItem
->parent
!= infoPtr
->root
)
1532 newSelection
= wineItem
->parent
;
1534 newSelection
= wineItem
->prevSibling
;
1535 TRACE("newSelection = %p\n", newSelection
);
1538 if (infoPtr
->firstVisible
== wineItem
)
1540 if (wineItem
->nextSibling
)
1541 newFirstVisible
= wineItem
->nextSibling
;
1542 else if (wineItem
->prevSibling
)
1543 newFirstVisible
= wineItem
->prevSibling
;
1544 else if (wineItem
->parent
!= infoPtr
->root
)
1545 newFirstVisible
= wineItem
->parent
;
1546 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1549 newFirstVisible
= infoPtr
->firstVisible
;
1551 TREEVIEW_RemoveItem(infoPtr
, wineItem
);
1554 /* Don't change if somebody else already has (infoPtr->selectedItem is cleared by FreeItem). */
1555 if (!infoPtr
->selectedItem
&& newSelection
)
1557 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1558 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1561 /* Validate insertMark dropItem.
1562 * hotItem ??? - used for comparison only.
1564 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1565 infoPtr
->insertMarkItem
= 0;
1567 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1568 infoPtr
->dropItem
= 0;
1570 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1571 newFirstVisible
= infoPtr
->root
->firstChild
;
1573 TREEVIEW_VerifyTree(infoPtr
);
1578 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1579 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1580 TREEVIEW_UpdateScrollBars(infoPtr
);
1581 TREEVIEW_Invalidate(infoPtr
, NULL
);
1583 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1585 /* parent lost '+/-' - update it */
1586 TREEVIEW_Invalidate(infoPtr
, parent
);
1593 /* Get/Set Messages *********************************************************/
1595 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
, LPARAM lParam
)
1598 infoPtr
->bRedraw
= TRUE
;
1600 infoPtr
->bRedraw
= FALSE
;
1606 TREEVIEW_GetIndent(TREEVIEW_INFO
*infoPtr
)
1609 return infoPtr
->uIndent
;
1613 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1617 if (newIndent
< MINIMUM_INDENT
)
1618 newIndent
= MINIMUM_INDENT
;
1620 if (infoPtr
->uIndent
!= newIndent
)
1622 infoPtr
->uIndent
= newIndent
;
1623 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1624 TREEVIEW_UpdateScrollBars(infoPtr
);
1625 TREEVIEW_Invalidate(infoPtr
, NULL
);
1633 TREEVIEW_GetToolTips(TREEVIEW_INFO
*infoPtr
)
1636 return (LRESULT
)infoPtr
->hwndToolTip
;
1640 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1645 prevToolTip
= infoPtr
->hwndToolTip
;
1646 infoPtr
->hwndToolTip
= hwndTT
;
1648 return (LRESULT
)prevToolTip
;
1652 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO
*infoPtr
, BOOL fUnicode
)
1654 BOOL rc
= infoPtr
->bNtfUnicode
;
1655 infoPtr
->bNtfUnicode
= fUnicode
;
1660 TREEVIEW_GetUnicodeFormat(TREEVIEW_INFO
*infoPtr
)
1662 return infoPtr
->bNtfUnicode
;
1666 TREEVIEW_GetScrollTime(TREEVIEW_INFO
*infoPtr
)
1668 return infoPtr
->uScrollTime
;
1672 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1674 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1676 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1678 return uOldScrollTime
;
1683 TREEVIEW_GetImageList(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1689 case (WPARAM
)TVSIL_NORMAL
:
1690 return (LRESULT
)infoPtr
->himlNormal
;
1692 case (WPARAM
)TVSIL_STATE
:
1693 return (LRESULT
)infoPtr
->himlState
;
1700 #define TVHEIGHT_MIN 16
1701 #define TVHEIGHT_FONT_ADJUST 3 /* 2 for focus border + 1 for margin some apps assume */
1703 /* Compute the natural height for items. */
1705 TREEVIEW_NaturalHeight(TREEVIEW_INFO
*infoPtr
)
1709 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1712 /* Height is the maximum of:
1713 * 16 (a hack because our fonts are tiny), and
1714 * The text height + border & margin, and
1715 * The size of the normal image list
1717 GetTextMetricsW(hdc
, &tm
);
1718 SelectObject(hdc
, hOldFont
);
1721 height
= TVHEIGHT_MIN
;
1722 if (height
< tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
)
1723 height
= tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
;
1724 if (height
< infoPtr
->normalImageHeight
)
1725 height
= infoPtr
->normalImageHeight
;
1730 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himlNew
)
1732 HIMAGELIST himlOld
= 0;
1733 int oldWidth
= infoPtr
->normalImageWidth
;
1734 int oldHeight
= infoPtr
->normalImageHeight
;
1737 TRACE("%x,%p\n", wParam
, himlNew
);
1741 case (WPARAM
)TVSIL_NORMAL
:
1742 himlOld
= infoPtr
->himlNormal
;
1743 infoPtr
->himlNormal
= himlNew
;
1745 if (himlNew
!= NULL
)
1746 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1747 &infoPtr
->normalImageHeight
);
1750 infoPtr
->normalImageWidth
= 0;
1751 infoPtr
->normalImageHeight
= 0;
1756 case (WPARAM
)TVSIL_STATE
:
1757 himlOld
= infoPtr
->himlState
;
1758 infoPtr
->himlState
= himlNew
;
1760 if (himlNew
!= NULL
)
1761 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1762 &infoPtr
->stateImageHeight
);
1765 infoPtr
->stateImageWidth
= 0;
1766 infoPtr
->stateImageHeight
= 0;
1772 if (oldWidth
!= infoPtr
->normalImageWidth
||
1773 oldHeight
!= infoPtr
->normalImageHeight
)
1775 BOOL bRecalcVisible
= FALSE
;
1777 if (oldHeight
!= infoPtr
->normalImageHeight
&&
1778 !infoPtr
->bHeightSet
)
1780 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1781 bRecalcVisible
= TRUE
;
1784 if (infoPtr
->normalImageWidth
> MINIMUM_INDENT
&&
1785 infoPtr
->normalImageWidth
!= infoPtr
->uIndent
)
1787 infoPtr
->uIndent
= infoPtr
->normalImageWidth
;
1788 bRecalcVisible
= TRUE
;
1792 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1794 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1795 TREEVIEW_UpdateScrollBars(infoPtr
);
1798 TREEVIEW_Invalidate(infoPtr
, NULL
);
1800 return (LRESULT
)himlOld
;
1804 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1806 INT prevHeight
= infoPtr
->uItemHeight
;
1808 TRACE("%d\n", newHeight
);
1809 if (newHeight
== -1)
1811 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1812 infoPtr
->bHeightSet
= FALSE
;
1816 infoPtr
->uItemHeight
= newHeight
;
1817 infoPtr
->bHeightSet
= TRUE
;
1820 /* Round down, unless we support odd ("non even") heights. */
1821 if (!(infoPtr
->dwStyle
) & TVS_NONEVENHEIGHT
)
1822 infoPtr
->uItemHeight
&= ~1;
1824 if (infoPtr
->uItemHeight
!= prevHeight
)
1826 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1827 TREEVIEW_UpdateScrollBars(infoPtr
);
1828 TREEVIEW_Invalidate(infoPtr
, NULL
);
1835 TREEVIEW_GetItemHeight(TREEVIEW_INFO
*infoPtr
)
1838 return infoPtr
->uItemHeight
;
1843 TREEVIEW_GetFont(TREEVIEW_INFO
*infoPtr
)
1845 TRACE("%p\n", infoPtr
->hFont
);
1846 return (LRESULT
)infoPtr
->hFont
;
1851 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1855 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1861 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1863 UINT uHeight
= infoPtr
->uItemHeight
;
1865 TRACE("%p %i\n", hFont
, bRedraw
);
1867 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
1869 DeleteObject(infoPtr
->hBoldFont
);
1870 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1871 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
1873 if (!infoPtr
->bHeightSet
)
1874 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1876 if (uHeight
!= infoPtr
->uItemHeight
)
1877 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1879 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1881 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1882 TREEVIEW_UpdateScrollBars(infoPtr
);
1885 TREEVIEW_Invalidate(infoPtr
, NULL
);
1892 TREEVIEW_GetLineColor(TREEVIEW_INFO
*infoPtr
)
1895 return (LRESULT
)infoPtr
->clrLine
;
1899 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1901 COLORREF prevColor
= infoPtr
->clrLine
;
1904 infoPtr
->clrLine
= color
;
1905 return (LRESULT
)prevColor
;
1910 TREEVIEW_GetTextColor(TREEVIEW_INFO
*infoPtr
)
1913 return (LRESULT
)infoPtr
->clrText
;
1917 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1919 COLORREF prevColor
= infoPtr
->clrText
;
1922 infoPtr
->clrText
= color
;
1924 if (infoPtr
->clrText
!= prevColor
)
1925 TREEVIEW_Invalidate(infoPtr
, NULL
);
1927 return (LRESULT
)prevColor
;
1932 TREEVIEW_GetBkColor(TREEVIEW_INFO
*infoPtr
)
1935 return (LRESULT
)infoPtr
->clrBk
;
1939 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1941 COLORREF prevColor
= infoPtr
->clrBk
;
1944 infoPtr
->clrBk
= newColor
;
1946 if (newColor
!= prevColor
)
1947 TREEVIEW_Invalidate(infoPtr
, NULL
);
1949 return (LRESULT
)prevColor
;
1954 TREEVIEW_GetInsertMarkColor(TREEVIEW_INFO
*infoPtr
)
1957 return (LRESULT
)infoPtr
->clrInsertMark
;
1961 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1963 COLORREF prevColor
= infoPtr
->clrInsertMark
;
1965 TRACE("%lx\n", color
);
1966 infoPtr
->clrInsertMark
= color
;
1968 return (LRESULT
)prevColor
;
1973 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
1975 TRACE("%d %p\n", wParam
, item
);
1977 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1980 infoPtr
->insertBeforeorAfter
= wParam
;
1981 infoPtr
->insertMarkItem
= item
;
1983 TREEVIEW_Invalidate(infoPtr
, NULL
);
1989 /************************************************************************
1990 * Some serious braindamage here. lParam is a pointer to both the
1991 * input HTREEITEM and the output RECT.
1994 TREEVIEW_GetItemRect(TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
1996 TREEVIEW_ITEM
*wineItem
;
1997 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
2001 * validate parameters
2007 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
) || !ISVISIBLE(wineItem
))
2011 * If wParam is TRUE return the text size otherwise return
2012 * the whole item size
2016 /* Windows does not send TVN_GETDISPINFO here. */
2018 lpRect
->top
= wineItem
->rect
.top
;
2019 lpRect
->bottom
= wineItem
->rect
.bottom
;
2021 lpRect
->left
= wineItem
->textOffset
;
2022 lpRect
->right
= wineItem
->textOffset
+ wineItem
->textWidth
;
2026 *lpRect
= wineItem
->rect
;
2029 TRACE("%s [L:%ld R:%ld T:%ld B:%ld]\n", fTextRect
? "text" : "item",
2030 lpRect
->left
, lpRect
->right
, lpRect
->top
, lpRect
->bottom
);
2035 static inline LRESULT
2036 TREEVIEW_GetVisibleCount(TREEVIEW_INFO
*infoPtr
)
2038 /* Suprise! This does not take integral height into account. */
2039 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2044 TREEVIEW_GetItemT(TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2046 TREEVIEW_ITEM
*wineItem
;
2048 wineItem
= tvItem
->hItem
;
2049 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2052 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, tvItem
->mask
);
2054 if (tvItem
->mask
& TVIF_CHILDREN
)
2056 if (wineItem
->cChildren
==I_CHILDRENCALLBACK
)
2057 FIXME("I_CHILDRENCALLBACK not supported\n");
2058 tvItem
->cChildren
= wineItem
->cChildren
;
2061 if (tvItem
->mask
& TVIF_HANDLE
)
2062 tvItem
->hItem
= wineItem
;
2064 if (tvItem
->mask
& TVIF_IMAGE
)
2065 tvItem
->iImage
= wineItem
->iImage
;
2067 if (tvItem
->mask
& TVIF_INTEGRAL
)
2068 tvItem
->iIntegral
= wineItem
->iIntegral
;
2070 /* undocumented: windows ignores TVIF_PARAM and
2071 * * always sets lParam
2073 tvItem
->lParam
= wineItem
->lParam
;
2075 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2076 tvItem
->iSelectedImage
= wineItem
->iSelectedImage
;
2078 if (tvItem
->mask
& TVIF_STATE
)
2079 /* Careful here - Windows ignores the stateMask when you get the state
2080 That contradicts the documentation, but makes more common sense, masking
2081 retrieval in this way seems overkill */
2082 tvItem
->state
= wineItem
->state
;
2084 if (tvItem
->mask
& TVIF_TEXT
)
2088 if (wineItem
->pszText
== LPSTR_TEXTCALLBACKW
)
2090 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2091 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2095 lstrcpynW(tvItem
->pszText
, wineItem
->pszText
, tvItem
->cchTextMax
);
2100 if (wineItem
->pszText
== LPSTR_TEXTCALLBACKW
)
2102 tvItem
->pszText
= (LPWSTR
)LPSTR_TEXTCALLBACKA
;
2103 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2107 WideCharToMultiByte(CP_ACP
, 0, wineItem
->pszText
, -1,
2108 (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, NULL
, NULL
);
2112 TRACE("item <%p>, txt %p, img %p, mask %x\n",
2113 wineItem
, tvItem
->pszText
, &tvItem
->iImage
, tvItem
->mask
);
2118 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2119 * which is wrong. */
2121 TREEVIEW_SetItemT(TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2123 TREEVIEW_ITEM
*wineItem
;
2124 TREEVIEW_ITEM originalItem
;
2126 wineItem
= tvItem
->hItem
;
2128 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr
, wineItem
),
2131 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2134 /* store the orignal item values */
2135 originalItem
= *wineItem
;
2137 if (!TREEVIEW_DoSetItemT(infoPtr
, wineItem
, tvItem
, isW
))
2140 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2141 if ((tvItem
->mask
& TVIF_TEXT
2142 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2143 && ISVISIBLE(wineItem
))
2145 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, TVIF_TEXT
);
2146 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, 0);
2149 if (tvItem
->mask
!= 0 && ISVISIBLE(wineItem
))
2151 /* The refresh updates everything, but we can't wait until then. */
2152 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, wineItem
);
2154 /* if any of the item's values changed and it's not a callback, redraw the item */
2155 if (item_changed(&originalItem
, wineItem
, tvItem
))
2157 if (tvItem
->mask
& TVIF_INTEGRAL
)
2159 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
2160 TREEVIEW_UpdateScrollBars(infoPtr
);
2162 TREEVIEW_Invalidate(infoPtr
, NULL
);
2166 TREEVIEW_UpdateScrollBars(infoPtr
);
2167 TREEVIEW_Invalidate(infoPtr
, wineItem
);
2176 TREEVIEW_GetItemState(TREEVIEW_INFO
*infoPtr
, HTREEITEM wineItem
, UINT mask
)
2180 if (!wineItem
|| !TREEVIEW_ValidItem(infoPtr
, wineItem
))
2183 return (wineItem
->state
& mask
);
2187 TREEVIEW_GetNextItem(TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM wineItem
)
2189 TREEVIEW_ITEM
*retval
;
2193 /* handle all the global data here */
2196 case TVGN_CHILD
: /* Special case: child of 0 is root */
2201 retval
= infoPtr
->root
->firstChild
;
2205 retval
= infoPtr
->selectedItem
;
2208 case TVGN_FIRSTVISIBLE
:
2209 retval
= infoPtr
->firstVisible
;
2212 case TVGN_DROPHILITE
:
2213 retval
= infoPtr
->dropItem
;
2216 case TVGN_LASTVISIBLE
:
2217 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2223 TRACE("flags:%x, returns %p\n", which
, retval
);
2224 return (LRESULT
)retval
;
2227 if (wineItem
== TVI_ROOT
) wineItem
= infoPtr
->root
;
2229 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2235 retval
= wineItem
->nextSibling
;
2238 retval
= wineItem
->prevSibling
;
2241 retval
= (wineItem
->parent
!= infoPtr
->root
) ? wineItem
->parent
: NULL
;
2244 retval
= wineItem
->firstChild
;
2246 case TVGN_NEXTVISIBLE
:
2247 retval
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
2249 case TVGN_PREVIOUSVISIBLE
:
2250 retval
= TREEVIEW_GetPrevListItem(infoPtr
, wineItem
);
2253 TRACE("Unknown msg %x,item %p\n", which
, wineItem
);
2257 TRACE("flags:%x, item %p;returns %p\n", which
, wineItem
, retval
);
2258 return (LRESULT
)retval
;
2263 TREEVIEW_GetCount(TREEVIEW_INFO
*infoPtr
)
2265 TRACE(" %d\n", infoPtr
->uNumItems
);
2266 return (LRESULT
)infoPtr
->uNumItems
;
2270 TREEVIEW_ToggleItemState(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2272 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2274 static const unsigned int state_table
[] = { 0, 2, 1 };
2278 state
= STATEIMAGEINDEX(item
->state
);
2279 TRACE("state:%x\n", state
);
2280 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2283 state
= state_table
[state
];
2285 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2287 TRACE("state:%x\n", state
);
2288 TREEVIEW_Invalidate(infoPtr
, item
);
2293 /* Painting *************************************************************/
2295 /* Draw the lines and expand button for an item. Also draws one section
2296 * of the line from item's parent to item's parent's next sibling. */
2298 TREEVIEW_DrawItemLines(TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*item
)
2300 LONG centerx
, centery
;
2301 BOOL lar
= ((infoPtr
->dwStyle
2302 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2306 if (!lar
&& item
->iLevel
== 0)
2309 hbr
= CreateSolidBrush(infoPtr
->clrBk
);
2310 hbrOld
= SelectObject(hdc
, hbr
);
2312 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2313 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2315 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2317 HPEN hOldPen
, hNewPen
;
2321 * Get a dotted grey pen
2323 hNewPen
= CreatePen(PS_ALTERNATE
, 0, infoPtr
->clrLine
);
2324 hOldPen
= SelectObject(hdc
, hNewPen
);
2326 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2327 LineTo(hdc
, centerx
- 1, centery
);
2329 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2331 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2332 LineTo(hdc
, centerx
, centery
);
2335 if (item
->nextSibling
)
2337 MoveToEx(hdc
, centerx
, centery
, NULL
);
2338 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2341 /* Draw the line from our parent to its next sibling. */
2342 parent
= item
->parent
;
2343 while (parent
!= infoPtr
->root
)
2345 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2347 if (parent
->nextSibling
2348 /* skip top-levels unless TVS_LINESATROOT */
2349 && parent
->stateOffset
> parent
->linesOffset
)
2351 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2352 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2355 parent
= parent
->parent
;
2358 SelectObject(hdc
, hOldPen
);
2359 DeleteObject(hNewPen
);
2363 * Display the (+/-) signs
2366 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2368 if (item
->cChildren
)
2370 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
2373 RECT glyphRect
= item
->rect
;
2374 glyphRect
.left
= item
->linesOffset
;
2375 glyphRect
.right
= item
->stateOffset
;
2376 DrawThemeBackground (theme
, hdc
, TVP_GLYPH
,
2377 (item
->state
& TVIS_EXPANDED
) ? GLPS_OPENED
: GLPS_CLOSED
,
2382 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2383 LONG width
= item
->stateOffset
- item
->linesOffset
;
2384 LONG rectsize
= min(height
, width
) / 4;
2385 /* plussize = ceil(rectsize * 3/4) */
2386 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2388 HPEN hNewPen
= CreatePen(PS_SOLID
, 0, infoPtr
->clrLine
);
2389 HPEN hOldPen
= SelectObject(hdc
, hNewPen
);
2391 Rectangle(hdc
, centerx
- rectsize
- 1, centery
- rectsize
- 1,
2392 centerx
+ rectsize
+ 2, centery
+ rectsize
+ 2);
2394 SelectObject(hdc
, hOldPen
);
2395 DeleteObject(hNewPen
);
2397 if (height
< 18 || width
< 18)
2399 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2400 LineTo(hdc
, centerx
+ plussize
, centery
);
2402 if (!(item
->state
& TVIS_EXPANDED
))
2404 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2405 LineTo(hdc
, centerx
, centery
+ plussize
);
2410 Rectangle(hdc
, centerx
- plussize
+ 1, centery
- 1,
2411 centerx
+ plussize
, centery
+ 2);
2413 if (!(item
->state
& TVIS_EXPANDED
))
2415 Rectangle(hdc
, centerx
- 1, centery
- plussize
+ 1,
2416 centerx
+ 2, centery
+ plussize
);
2417 SetPixel(hdc
, centerx
- 1, centery
, infoPtr
->clrBk
);
2418 SetPixel(hdc
, centerx
+ 1, centery
, infoPtr
->clrBk
);
2424 SelectObject(hdc
, hbrOld
);
2429 TREEVIEW_DrawItem(TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*wineItem
)
2433 COLORREF oldTextColor
, oldTextBkColor
;
2435 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2436 NMTVCUSTOMDRAW nmcdhdr
;
2438 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, CALLBACK_MASK_ALL
);
2440 /* - If item is drop target or it is selected and window is in focus -
2441 * use blue background (COLOR_HIGHLIGHT).
2442 * - If item is selected, window is not in focus, but it has style
2443 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2444 * - Otherwise - use background color
2446 if ((wineItem
->state
& TVIS_DROPHILITED
) || ((wineItem
== infoPtr
->focusedItem
) && !(wineItem
->state
& TVIS_SELECTED
)) ||
2447 ((wineItem
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
) &&
2448 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2450 if ((wineItem
->state
& TVIS_DROPHILITED
) || inFocus
)
2452 nmcdhdr
.clrTextBk
= GetSysColor(COLOR_HIGHLIGHT
);
2453 nmcdhdr
.clrText
= GetSysColor(COLOR_HIGHLIGHTTEXT
);
2457 nmcdhdr
.clrTextBk
= GetSysColor(COLOR_BTNFACE
);
2458 if (infoPtr
->clrText
== -1)
2459 nmcdhdr
.clrText
= GetSysColor(COLOR_WINDOWTEXT
);
2461 nmcdhdr
.clrText
= infoPtr
->clrText
;
2466 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
2467 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (wineItem
== infoPtr
->hotItem
))
2468 nmcdhdr
.clrText
= comctl32_color
.clrHighlight
;
2469 else if (infoPtr
->clrText
== -1)
2470 nmcdhdr
.clrText
= GetSysColor(COLOR_WINDOWTEXT
);
2472 nmcdhdr
.clrText
= infoPtr
->clrText
;
2475 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, wineItem
));
2477 /* The custom draw handler can query the text rectangle,
2479 /* should already be known, set to 0 when changed */
2480 if (!wineItem
->textWidth
)
2481 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, hdc
);
2485 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2487 cditem
= TREEVIEW_SendCustomDrawItemNotify
2488 (infoPtr
, hdc
, wineItem
, CDDS_ITEMPREPAINT
, &nmcdhdr
);
2489 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2491 if (cditem
& CDRF_SKIPDEFAULT
)
2493 SelectObject(hdc
, hOldFont
);
2498 if (cditem
& CDRF_NEWFONT
)
2499 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, hdc
);
2501 TREEVIEW_DrawItemLines(infoPtr
, hdc
, wineItem
);
2503 /* Set colors. Custom draw handler can change these so we do this after it. */
2504 oldTextColor
= SetTextColor(hdc
, nmcdhdr
.clrText
);
2505 oldTextBkColor
= SetBkColor(hdc
, nmcdhdr
.clrTextBk
);
2507 centery
= (wineItem
->rect
.top
+ wineItem
->rect
.bottom
) / 2;
2510 * Display the images associated with this item
2515 /* State images are displayed to the left of the Normal image
2516 * image number is in state; zero should be `display no image'.
2518 imageIndex
= STATEIMAGEINDEX(wineItem
->state
);
2520 if (infoPtr
->himlState
&& imageIndex
)
2522 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2523 wineItem
->stateOffset
,
2524 centery
- infoPtr
->stateImageHeight
/ 2,
2528 /* Now, draw the normal image; can be either selected or
2529 * non-selected image.
2532 if ((wineItem
->state
& TVIS_SELECTED
) && (wineItem
->iSelectedImage
>= 0))
2534 /* The item is currently selected */
2535 imageIndex
= wineItem
->iSelectedImage
;
2539 /* The item is not selected */
2540 imageIndex
= wineItem
->iImage
;
2543 if (infoPtr
->himlNormal
)
2545 int ovlIdx
= wineItem
->state
& TVIS_OVERLAYMASK
;
2547 ImageList_Draw(infoPtr
->himlNormal
, imageIndex
, hdc
,
2548 wineItem
->imageOffset
,
2549 centery
- infoPtr
->normalImageHeight
/ 2,
2550 ILD_NORMAL
| ovlIdx
);
2556 * Display the text associated with this item
2559 /* Don't paint item's text if it's being edited */
2560 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= wineItem
))
2562 if (wineItem
->pszText
)
2566 rcText
.top
= wineItem
->rect
.top
;
2567 rcText
.bottom
= wineItem
->rect
.bottom
;
2568 rcText
.left
= wineItem
->textOffset
;
2569 rcText
.right
= rcText
.left
+ wineItem
->textWidth
+ 4;
2571 TRACE("drawing text %s at (%ld,%ld)-(%ld,%ld)\n",
2572 debugstr_w(wineItem
->pszText
),
2573 rcText
.left
, rcText
.top
, rcText
.right
, rcText
.bottom
);
2576 ExtTextOutW(hdc
, rcText
.left
+ 2, rcText
.top
+ 1,
2577 ETO_CLIPPED
| ETO_OPAQUE
,
2580 lstrlenW(wineItem
->pszText
),
2583 /* Draw the box around the selected item */
2584 if ((wineItem
== infoPtr
->selectedItem
) && inFocus
)
2586 DrawFocusRect(hdc
,&rcText
);
2592 /* Draw insertion mark if necessary */
2594 if (infoPtr
->insertMarkItem
)
2595 TRACE("item:%d,mark:%p\n",
2596 TREEVIEW_GetItemIndex(infoPtr
, wineItem
),
2597 infoPtr
->insertMarkItem
);
2599 if (wineItem
== infoPtr
->insertMarkItem
)
2601 HPEN hNewPen
, hOldPen
;
2605 hNewPen
= CreatePen(PS_SOLID
, 2, infoPtr
->clrInsertMark
);
2606 hOldPen
= SelectObject(hdc
, hNewPen
);
2608 if (infoPtr
->insertBeforeorAfter
)
2609 offset
= wineItem
->rect
.bottom
- 1;
2611 offset
= wineItem
->rect
.top
+ 1;
2613 left
= wineItem
->textOffset
- 2;
2614 right
= wineItem
->textOffset
+ wineItem
->textWidth
+ 2;
2616 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2617 LineTo(hdc
, left
, offset
+ 4);
2619 MoveToEx(hdc
, left
, offset
, NULL
);
2620 LineTo(hdc
, right
+ 1, offset
);
2622 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2623 LineTo(hdc
, right
, offset
- 4);
2625 SelectObject(hdc
, hOldPen
);
2626 DeleteObject(hNewPen
);
2629 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2631 cditem
= TREEVIEW_SendCustomDrawItemNotify
2632 (infoPtr
, hdc
, wineItem
, CDDS_ITEMPOSTPAINT
, &nmcdhdr
);
2633 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2636 /* Restore the hdc state */
2637 SetTextColor(hdc
, oldTextColor
);
2638 SetBkColor(hdc
, oldTextBkColor
);
2639 SelectObject(hdc
, hOldFont
);
2642 /* Computes treeHeight and treeWidth and updates the scroll bars.
2645 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2647 TREEVIEW_ITEM
*wineItem
;
2648 HWND hwnd
= infoPtr
->hwnd
;
2652 LONG scrollX
= infoPtr
->scrollX
;
2654 infoPtr
->treeWidth
= 0;
2655 infoPtr
->treeHeight
= 0;
2657 /* We iterate through all visible items in order to get the tree height
2659 wineItem
= infoPtr
->root
->firstChild
;
2661 while (wineItem
!= NULL
)
2663 if (ISVISIBLE(wineItem
))
2665 /* actually we draw text at textOffset + 2 */
2666 if (2+wineItem
->textOffset
+wineItem
->textWidth
> infoPtr
->treeWidth
)
2667 infoPtr
->treeWidth
= wineItem
->textOffset
+wineItem
->textWidth
+2;
2669 /* This is scroll-adjusted, but we fix this below. */
2670 infoPtr
->treeHeight
= wineItem
->rect
.bottom
;
2673 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
2676 /* Fix the scroll adjusted treeHeight and treeWidth. */
2677 if (infoPtr
->root
->firstChild
)
2678 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2680 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2682 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2684 /* Adding one scroll bar may take up enough space that it forces us
2685 * to add the other as well. */
2686 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2690 if (infoPtr
->treeWidth
2691 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2694 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
)
2697 if (!vert
&& horz
&& infoPtr
->treeHeight
2698 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2701 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2703 si
.cbSize
= sizeof(SCROLLINFO
);
2704 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2709 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2710 if ( si
.nPage
&& NULL
!= infoPtr
->firstVisible
)
2712 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2713 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2715 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2717 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2718 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2719 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2723 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2724 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2725 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2730 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2731 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2732 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2737 si
.nPage
= infoPtr
->clientWidth
;
2738 si
.nPos
= infoPtr
->scrollX
;
2739 si
.nMax
= infoPtr
->treeWidth
- 1;
2741 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2743 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2747 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2748 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2749 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2751 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2755 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2756 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2757 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2762 if (infoPtr
->scrollX
!= scrollX
)
2764 TREEVIEW_HScroll(infoPtr
,
2765 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2769 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2772 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2774 TREEVIEW_EraseBackground(TREEVIEW_INFO
*infoPtr
, HDC hDC
)
2776 HBRUSH hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
2779 GetClientRect(infoPtr
->hwnd
, &rect
);
2780 FillRect(hDC
, &rect
, hBrush
);
2781 DeleteObject(hBrush
);
2787 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, RECT
*rc
)
2789 HWND hwnd
= infoPtr
->hwnd
;
2791 TREEVIEW_ITEM
*wineItem
;
2793 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2795 TRACE("empty window\n");
2799 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2802 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2804 ReleaseDC(hwnd
, hdc
);
2808 for (wineItem
= infoPtr
->root
->firstChild
;
2810 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
))
2812 if (ISVISIBLE(wineItem
))
2814 /* Avoid unneeded calculations */
2815 if (wineItem
->rect
.top
> rect
.bottom
)
2817 if (wineItem
->rect
.bottom
< rect
.top
)
2820 TREEVIEW_DrawItem(infoPtr
, hdc
, wineItem
);
2824 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2826 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2830 TREEVIEW_Invalidate(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2833 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2835 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2839 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
2850 GetClientRect(infoPtr
->hwnd
, &rc
);
2851 TREEVIEW_EraseBackground(infoPtr
, hdc
);
2855 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
2859 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
2860 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
2863 EndPaint(infoPtr
->hwnd
, &ps
);
2869 /* Sorting **************************************************************/
2871 /***************************************************************************
2872 * Forward the DPA local callback to the treeview owner callback
2875 TREEVIEW_CallBackCompare(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
, LPTVSORTCB pCallBackSort
)
2877 /* Forward the call to the client-defined callback */
2878 return pCallBackSort
->lpfnCompare(first
->lParam
,
2880 pCallBackSort
->lParam
);
2883 /***************************************************************************
2884 * Treeview native sort routine: sort on item text.
2887 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
2888 TREEVIEW_INFO
*infoPtr
)
2890 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
2891 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
2893 if(first
->pszText
&& second
->pszText
)
2894 return lstrcmpiW(first
->pszText
, second
->pszText
);
2895 else if(first
->pszText
)
2897 else if(second
->pszText
)
2903 /* Returns the number of physical children belonging to item. */
2905 TREEVIEW_CountChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2910 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
2916 /* Returns a DPA containing a pointer to each physical child of item in
2917 * sibling order. If item has no children, an empty DPA is returned. */
2919 TREEVIEW_BuildChildDPA(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2921 HTREEITEM child
= item
->firstChild
;
2923 HDPA list
= DPA_Create(8);
2924 if (list
== 0) return NULL
;
2926 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
2928 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
2938 /***************************************************************************
2939 * Setup the treeview structure with regards of the sort method
2940 * and sort the children of the TV item specified in lParam
2941 * fRecurse: currently unused. Should be zero.
2942 * parent: if pSort!=NULL, should equal pSort->hParent.
2943 * otherwise, item which child items are to be sorted.
2944 * pSort: sort method info. if NULL, sort on item text.
2945 * if non-NULL, sort on item's lParam content, and let the
2946 * application decide what that means. See also TVM_SORTCHILDRENCB.
2950 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, BOOL fRecurse
, HTREEITEM parent
,
2954 PFNDPACOMPARE pfnCompare
;
2957 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
2958 if (parent
== TVI_ROOT
|| parent
== NULL
)
2959 parent
= infoPtr
->root
;
2961 /* Check for a valid handle to the parent item */
2962 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
2964 ERR("invalid item hParent=%p\n", parent
);
2970 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
2971 lpCompare
= (LPARAM
)pSort
;
2975 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
2976 lpCompare
= (LPARAM
)infoPtr
;
2979 cChildren
= TREEVIEW_CountChildren(infoPtr
, parent
);
2981 /* Make sure there is something to sort */
2984 /* TREEVIEW_ITEM rechaining */
2987 HTREEITEM nextItem
= 0;
2988 HTREEITEM prevItem
= 0;
2990 HDPA sortList
= TREEVIEW_BuildChildDPA(infoPtr
, parent
);
2992 if (sortList
== NULL
)
2995 /* let DPA sort the list */
2996 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
2998 /* The order of DPA entries has been changed, so fixup the
2999 * nextSibling and prevSibling pointers. */
3001 item
= (HTREEITEM
)DPA_GetPtr(sortList
, count
++);
3002 while ((nextItem
= (HTREEITEM
)DPA_GetPtr(sortList
, count
++)) != NULL
)
3004 /* link the two current item toghether */
3005 item
->nextSibling
= nextItem
;
3006 nextItem
->prevSibling
= item
;
3008 if (prevItem
== NULL
)
3010 /* this is the first item, update the parent */
3011 parent
->firstChild
= item
;
3012 item
->prevSibling
= NULL
;
3016 /* fix the back chaining */
3017 item
->prevSibling
= prevItem
;
3020 /* get ready for the next one */
3025 /* the last item is pointed to by item and never has a sibling */
3026 item
->nextSibling
= NULL
;
3027 parent
->lastChild
= item
;
3029 DPA_Destroy(sortList
);
3031 TREEVIEW_VerifyTree(infoPtr
);
3033 if (parent
->state
& TVIS_EXPANDED
)
3035 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3037 if (parent
== infoPtr
->root
)
3038 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3040 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3042 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3044 TREEVIEW_ITEM
*item
;
3046 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3047 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3049 if (item
->visibleOrder
== visOrder
)
3053 if (!item
) item
= parent
->firstChild
;
3054 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3057 TREEVIEW_Invalidate(infoPtr
, NULL
);
3066 /***************************************************************************
3067 * Setup the treeview structure with regards of the sort method
3068 * and sort the children of the TV item specified in lParam
3071 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPTVSORTCB pSort
)
3073 return TREEVIEW_Sort(infoPtr
, wParam
, pSort
->hParent
, pSort
);
3077 /***************************************************************************
3078 * Sort the children of the TV item specified in lParam.
3081 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3083 return TREEVIEW_Sort(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
, NULL
);
3087 /* Expansion/Collapse ***************************************************/
3090 TREEVIEW_SendExpanding(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3093 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3094 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3095 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3100 TREEVIEW_SendExpanded(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3103 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3104 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3105 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3110 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3111 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3113 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3114 BOOL bRemoveChildren
, BOOL bUser
)
3116 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3117 BOOL bSetSelection
, bSetFirstVisible
;
3119 LONG scrollDist
= 0;
3120 TREEVIEW_ITEM
*nextItem
= NULL
, *tmpItem
;
3122 TRACE("TVE_COLLAPSE %p %s\n", wineItem
, TREEVIEW_ItemName(wineItem
));
3124 if (!(wineItem
->state
& TVIS_EXPANDED
))
3127 if (bUser
|| !(wineItem
->state
& TVIS_EXPANDEDONCE
))
3128 TREEVIEW_SendExpanding(infoPtr
, wineItem
, action
);
3130 if (wineItem
->firstChild
== NULL
)
3133 wineItem
->state
&= ~TVIS_EXPANDED
;
3135 if (bUser
|| !(wineItem
->state
& TVIS_EXPANDEDONCE
))
3136 TREEVIEW_SendExpanded(infoPtr
, wineItem
, action
);
3138 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3139 && TREEVIEW_IsChildOf(wineItem
, infoPtr
->selectedItem
));
3141 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3142 && TREEVIEW_IsChildOf(wineItem
, infoPtr
->firstVisible
));
3147 if (tmpItem
->nextSibling
)
3149 nextItem
= tmpItem
->nextSibling
;
3152 tmpItem
= tmpItem
->parent
;
3156 scrollDist
= nextItem
->rect
.top
;
3158 if (bRemoveChildren
)
3160 INT old_cChildren
= wineItem
->cChildren
;
3161 TRACE("TVE_COLLAPSERESET\n");
3162 wineItem
->state
&= ~TVIS_EXPANDEDONCE
;
3163 TREEVIEW_RemoveAllChildren(infoPtr
, wineItem
);
3164 wineItem
->cChildren
= old_cChildren
;
3167 if (wineItem
->firstChild
)
3169 TREEVIEW_ITEM
*item
, *sibling
;
3171 sibling
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
3173 for (item
= wineItem
->firstChild
; item
!= sibling
;
3174 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3176 item
->visibleOrder
= -1;
3180 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
3183 scrollDist
= -(scrollDist
- nextItem
->rect
.top
);
3187 /* Don't call DoSelectItem, it sends notifications. */
3188 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3189 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3190 wineItem
->state
|= TVIS_SELECTED
;
3191 infoPtr
->selectedItem
= wineItem
;
3194 TREEVIEW_UpdateScrollBars(infoPtr
);
3196 scrollRect
.left
= 0;
3197 scrollRect
.right
= infoPtr
->clientWidth
;
3198 scrollRect
.bottom
= infoPtr
->clientHeight
;
3202 scrollRect
.top
= nextItem
->rect
.top
;
3204 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3205 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3206 TREEVIEW_Invalidate(infoPtr
, wineItem
);
3208 scrollRect
.top
= wineItem
->rect
.top
;
3209 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, TRUE
);
3212 TREEVIEW_SetFirstVisible(infoPtr
,
3213 bSetFirstVisible
? wineItem
: infoPtr
->firstVisible
,
3220 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3221 BOOL bExpandPartial
, BOOL bUser
)
3224 LONG orgNextTop
= 0;
3226 TREEVIEW_ITEM
*nextItem
, *tmpItem
;
3230 if (wineItem
->state
& TVIS_EXPANDED
)
3233 tmpItem
= wineItem
; nextItem
= NULL
;
3236 if (tmpItem
->nextSibling
)
3238 nextItem
= tmpItem
->nextSibling
;
3241 tmpItem
= tmpItem
->parent
;
3245 orgNextTop
= nextItem
->rect
.top
;
3247 TRACE("TVE_EXPAND %p %s\n", wineItem
, TREEVIEW_ItemName(wineItem
));
3249 if (bUser
|| ((wineItem
->cChildren
!= 0) &&
3250 !(wineItem
->state
& TVIS_EXPANDEDONCE
)))
3252 if (!TREEVIEW_SendExpanding(infoPtr
, wineItem
, TVE_EXPAND
))
3254 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3258 if (!wineItem
->firstChild
)
3261 wineItem
->state
|= TVIS_EXPANDED
;
3262 TREEVIEW_SendExpanded(infoPtr
, wineItem
, TVE_EXPAND
);
3263 wineItem
->state
|= TVIS_EXPANDEDONCE
;
3267 if (!wineItem
->firstChild
)
3270 /* this item has already been expanded */
3271 wineItem
->state
|= TVIS_EXPANDED
;
3275 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3277 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
3278 TREEVIEW_UpdateSubTree(infoPtr
, wineItem
);
3279 TREEVIEW_UpdateScrollBars(infoPtr
);
3281 scrollRect
.left
= 0;
3282 scrollRect
.bottom
= infoPtr
->treeHeight
;
3283 scrollRect
.right
= infoPtr
->clientWidth
;
3286 scrollDist
= nextItem
->rect
.top
- orgNextTop
;
3287 scrollRect
.top
= orgNextTop
;
3289 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3290 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3291 TREEVIEW_Invalidate (infoPtr
, wineItem
);
3293 scrollRect
.top
= wineItem
->rect
.top
;
3294 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, FALSE
);
3297 /* Scroll up so that as many children as possible are visible.
3298 * This fails when expanding causes an HScroll bar to appear, but we
3299 * don't know that yet, so the last item is obscured. */
3300 if (wineItem
->firstChild
!= NULL
)
3302 int nChildren
= wineItem
->lastChild
->visibleOrder
3303 - wineItem
->firstChild
->visibleOrder
+ 1;
3305 int visible_pos
= wineItem
->visibleOrder
3306 - infoPtr
->firstVisible
->visibleOrder
;
3308 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3310 if (visible_pos
> 0 && nChildren
> rows_below
)
3312 int scroll
= nChildren
- rows_below
;
3314 if (scroll
> visible_pos
)
3315 scroll
= visible_pos
;
3319 TREEVIEW_ITEM
*newFirstVisible
3320 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3324 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3328 TREEVIEW_UpdateScrollBars(infoPtr
);
3334 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
, BOOL bUser
)
3338 if (wineItem
->state
& TVIS_EXPANDED
)
3339 return TREEVIEW_Collapse(infoPtr
, wineItem
, FALSE
, bUser
);
3341 return TREEVIEW_Expand(infoPtr
, wineItem
, FALSE
, bUser
);
3345 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3347 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3349 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3351 if (TREEVIEW_HasChildren(infoPtr
, item
))
3352 TREEVIEW_ExpandAll(infoPtr
, item
);
3356 /* Note:If the specified item is the child of a collapsed parent item,
3357 the parent's list of child items is (recursively) expanded to reveal the
3358 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3359 know if it also applies here.
3363 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM wineItem
)
3365 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
3368 TRACE("For (%s) item:%d, flags %x, state:%d\n",
3369 TREEVIEW_ItemName(wineItem
), flag
,
3370 TREEVIEW_GetItemIndex(infoPtr
, wineItem
), wineItem
->state
);
3372 switch (flag
& TVE_TOGGLE
)
3375 return TREEVIEW_Collapse(infoPtr
, wineItem
, flag
& TVE_COLLAPSERESET
,
3379 return TREEVIEW_Expand(infoPtr
, wineItem
, flag
& TVE_EXPANDPARTIAL
,
3383 return TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3390 TRACE("Exiting, Item %p state is now %d...\n", wineItem
, wineItem
->state
);
3394 /* Hit-Testing **********************************************************/
3396 static TREEVIEW_ITEM
*
3397 TREEVIEW_HitTestPoint(TREEVIEW_INFO
*infoPtr
, POINT pt
)
3399 TREEVIEW_ITEM
*wineItem
;
3402 if (!infoPtr
->firstVisible
)
3405 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3407 for (wineItem
= infoPtr
->firstVisible
; wineItem
!= NULL
;
3408 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
))
3410 if (row
>= wineItem
->visibleOrder
3411 && row
< wineItem
->visibleOrder
+ wineItem
->iIntegral
)
3419 TREEVIEW_HitTest(TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3421 TREEVIEW_ITEM
*wineItem
;
3427 GetClientRect(infoPtr
->hwnd
, &rect
);
3434 status
|= TVHT_TOLEFT
;
3436 else if (x
> rect
.right
)
3438 status
|= TVHT_TORIGHT
;
3443 status
|= TVHT_ABOVE
;
3445 else if (y
> rect
.bottom
)
3447 status
|= TVHT_BELOW
;
3452 lpht
->flags
= status
;
3453 return (LRESULT
)(HTREEITEM
)NULL
;
3456 wineItem
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3459 lpht
->flags
= TVHT_NOWHERE
;
3460 return (LRESULT
)(HTREEITEM
)NULL
;
3463 if (x
>= wineItem
->textOffset
+ wineItem
->textWidth
)
3465 lpht
->flags
= TVHT_ONITEMRIGHT
;
3467 else if (x
>= wineItem
->textOffset
)
3469 lpht
->flags
= TVHT_ONITEMLABEL
;
3471 else if (x
>= wineItem
->imageOffset
)
3473 lpht
->flags
= TVHT_ONITEMICON
;
3475 else if (x
>= wineItem
->stateOffset
)
3477 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3479 else if (x
>= wineItem
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3481 lpht
->flags
= TVHT_ONITEMBUTTON
;
3485 lpht
->flags
= TVHT_ONITEMINDENT
;
3488 lpht
->hItem
= wineItem
;
3489 TRACE("(%ld,%ld):result %x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3491 return (LRESULT
)wineItem
;
3494 /* Item Label Editing ***************************************************/
3497 TREEVIEW_GetEditControl(TREEVIEW_INFO
*infoPtr
)
3499 return (LRESULT
)infoPtr
->hwndEdit
;
3502 static LRESULT CALLBACK
3503 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3505 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3506 BOOL bCancel
= FALSE
;
3512 TRACE("WM_PAINT start\n");
3513 rc
= CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3515 TRACE("WM_PAINT done\n");
3519 if (infoPtr
->bIgnoreEditKillFocus
)
3524 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3527 if (wParam
== (WPARAM
)VK_ESCAPE
)
3532 else if (wParam
== (WPARAM
)VK_RETURN
)
3539 return CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3542 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3543 /* eg. Using a messagebox */
3545 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3546 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3547 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3553 /* should handle edit control messages here */
3556 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3558 TRACE("%x %ld\n", wParam
, lParam
);
3560 switch (HIWORD(wParam
))
3565 * Adjust the edit window size
3568 TREEVIEW_ITEM
*editItem
= infoPtr
->selectedItem
;
3569 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3572 HFONT hFont
, hOldFont
= 0;
3574 infoPtr
->bLabelChanged
= TRUE
;
3576 len
= GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
));
3578 /* Select font to get the right dimension of the string */
3579 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3583 hOldFont
= SelectObject(hdc
, hFont
);
3586 if (GetTextExtentPoint32W(hdc
, buffer
, strlenW(buffer
), &sz
))
3588 TEXTMETRICW textMetric
;
3590 /* Add Extra spacing for the next character */
3591 GetTextMetricsW(hdc
, &textMetric
);
3592 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3594 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3596 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3598 SetWindowPos(infoPtr
->hwndEdit
,
3603 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3604 SWP_NOMOVE
| SWP_DRAWFRAME
);
3609 SelectObject(hdc
, hOldFont
);
3612 ReleaseDC(infoPtr
->hwnd
, hdc
);
3617 return SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3624 TREEVIEW_EditLabel(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3626 HWND hwnd
= infoPtr
->hwnd
;
3629 TREEVIEW_ITEM
*editItem
= hItem
;
3630 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
);
3633 TEXTMETRICW textMetric
;
3634 static const WCHAR EditW
[] = {'E','d','i','t',0};
3636 TRACE("%p %p\n", hwnd
, hItem
);
3637 if (!TREEVIEW_ValidItem(infoPtr
, editItem
))
3640 if (infoPtr
->hwndEdit
)
3641 return infoPtr
->hwndEdit
;
3643 infoPtr
->bLabelChanged
= FALSE
;
3645 /* Make sure that edit item is selected */
3646 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, hItem
, TVC_UNKNOWN
);
3647 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3649 TREEVIEW_UpdateDispInfo(infoPtr
, editItem
, TVIF_TEXT
);
3652 /* Select the font to get appropriate metric dimensions */
3653 if (infoPtr
->hFont
!= 0)
3655 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3658 /* Get string length in pixels */
3659 GetTextExtentPoint32W(hdc
, editItem
->pszText
, strlenW(editItem
->pszText
),
3662 /* Add Extra spacing for the next character */
3663 GetTextMetricsW(hdc
, &textMetric
);
3664 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3666 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3667 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3669 if (infoPtr
->hFont
!= 0)
3671 SelectObject(hdc
, hOldFont
);
3674 ReleaseDC(hwnd
, hdc
);
3675 hwndEdit
= CreateWindowExW(WS_EX_LEFT
,
3678 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3679 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3680 ES_LEFT
, editItem
->textOffset
- 2,
3681 editItem
->rect
.top
- 1, sz
.cx
+ 3,
3682 editItem
->rect
.bottom
-
3683 editItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3684 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3686 infoPtr
->hwndEdit
= hwndEdit
;
3688 /* Get a 2D border. */
3689 SetWindowLongW(hwndEdit
, GWL_EXSTYLE
,
3690 GetWindowLongW(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3691 SetWindowLongW(hwndEdit
, GWL_STYLE
,
3692 GetWindowLongW(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3694 SendMessageW(hwndEdit
, WM_SETFONT
,
3695 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, editItem
), FALSE
);
3697 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
,
3699 TREEVIEW_Edit_SubclassProc
);
3701 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, editItem
))
3703 DestroyWindow(hwndEdit
);
3704 infoPtr
->hwndEdit
= 0;
3708 infoPtr
->selectedItem
= hItem
;
3709 SetWindowTextW(hwndEdit
, editItem
->pszText
);
3711 SendMessageW(hwndEdit
, EM_SETSEL
, 0, -1);
3712 ShowWindow(hwndEdit
, SW_SHOW
);
3719 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3721 HWND hwnd
= infoPtr
->hwnd
;
3722 TREEVIEW_ITEM
*editedItem
= infoPtr
->selectedItem
;
3725 WCHAR tmpText
[1024] = { '\0' };
3726 WCHAR
*newText
= tmpText
;
3729 if (!infoPtr
->hwndEdit
)
3732 tvdi
.hdr
.hwndFrom
= hwnd
;
3733 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
3734 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_ENDLABELEDITW
);
3736 tvdi
.item
.hItem
= editedItem
;
3737 tvdi
.item
.state
= editedItem
->state
;
3738 tvdi
.item
.lParam
= editedItem
->lParam
;
3742 if (!infoPtr
->bNtfUnicode
)
3743 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, (LPSTR
)tmpText
, 1023);
3745 iLength
= GetWindowTextW(infoPtr
->hwndEdit
, tmpText
, 1023);
3747 if (iLength
>= 1023)
3749 ERR("Insufficient space to retrieve new item label\n");
3752 tvdi
.item
.mask
= TVIF_TEXT
;
3753 tvdi
.item
.pszText
= tmpText
;
3754 tvdi
.item
.cchTextMax
= iLength
+ 1;
3758 tvdi
.item
.pszText
= NULL
;
3759 tvdi
.item
.cchTextMax
= 0;
3762 bCommit
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
3763 (WPARAM
)tvdi
.hdr
.idFrom
, (LPARAM
)&tvdi
);
3765 if (!bCancel
&& bCommit
) /* Apply the changes */
3767 if (!infoPtr
->bNtfUnicode
)
3769 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, NULL
, 0 );
3770 newText
= Alloc(len
* sizeof(WCHAR
));
3771 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, newText
, len
);
3775 if (strcmpW(newText
, editedItem
->pszText
) != 0)
3777 if (NULL
== ReAlloc(editedItem
->pszText
, iLength
+ 1))
3779 ERR("OutOfMemory, cannot allocate space for label\n");
3780 DestroyWindow(infoPtr
->hwndEdit
);
3781 infoPtr
->hwndEdit
= 0;
3786 editedItem
->cchTextMax
= iLength
+ 1;
3787 strcpyW(editedItem
->pszText
, newText
);
3790 if(newText
!= tmpText
) Free(newText
);
3793 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
3794 DestroyWindow(infoPtr
->hwndEdit
);
3795 infoPtr
->hwndEdit
= 0;
3800 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
3802 if (wParam
!= TV_EDIT_TIMER
)
3804 ERR("got unknown timer\n");
3808 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
3809 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
3811 TREEVIEW_EditLabel(infoPtr
, infoPtr
->selectedItem
);
3817 /* Mouse Tracking/Drag **************************************************/
3819 /***************************************************************************
3820 * This is quite unusual piece of code, but that's how it's implemented in
3824 TREEVIEW_TrackMouse(TREEVIEW_INFO
*infoPtr
, POINT pt
)
3826 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
3827 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
3831 r
.top
= pt
.y
- cyDrag
;
3832 r
.left
= pt
.x
- cxDrag
;
3833 r
.bottom
= pt
.y
+ cyDrag
;
3834 r
.right
= pt
.x
+ cxDrag
;
3836 SetCapture(infoPtr
->hwnd
);
3840 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
3842 if (msg
.message
== WM_MOUSEMOVE
)
3844 pt
.x
= (short)LOWORD(msg
.lParam
);
3845 pt
.y
= (short)HIWORD(msg
.lParam
);
3846 if (PtInRect(&r
, pt
))
3854 else if (msg
.message
>= WM_LBUTTONDOWN
&&
3855 msg
.message
<= WM_RBUTTONDBLCLK
)
3857 if (msg
.message
== WM_RBUTTONUP
)
3858 TREEVIEW_RButtonUp(infoPtr
, &pt
);
3862 DispatchMessageW(&msg
);
3865 if (GetCapture() != infoPtr
->hwnd
)
3875 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3877 TREEVIEW_ITEM
*wineItem
;
3881 SetFocus(infoPtr
->hwnd
);
3883 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
3885 /* If there is pending 'edit label' event - kill it now */
3886 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
3889 hit
.pt
.x
= (short)LOWORD(lParam
);
3890 hit
.pt
.y
= (short)HIWORD(lParam
);
3892 wineItem
= (TREEVIEW_ITEM
*)TREEVIEW_HitTest(infoPtr
, &hit
);
3895 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, wineItem
));
3897 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
3901 case TVHT_ONITEMRIGHT
:
3902 /* FIXME: we should not have sent NM_DBLCLK in this case. */
3905 case TVHT_ONITEMINDENT
:
3906 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
3912 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
3913 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
3915 while (wineItem
->iLevel
> level
)
3917 wineItem
= wineItem
->parent
;
3923 case TVHT_ONITEMLABEL
:
3924 case TVHT_ONITEMICON
:
3925 case TVHT_ONITEMBUTTON
:
3926 TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3929 case TVHT_ONITEMSTATEICON
:
3930 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
3931 TREEVIEW_ToggleItemState(infoPtr
, wineItem
);
3933 TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3942 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3944 HWND hwnd
= infoPtr
->hwnd
;
3946 BOOL bTrack
, bDoLabelEdit
;
3949 /* If Edit control is active - kill it and return.
3950 * The best way to do it is to set focus to itself.
3951 * Edit control subclassed procedure will automatically call
3954 if (infoPtr
->hwndEdit
)
3960 ht
.pt
.x
= (short)LOWORD(lParam
);
3961 ht
.pt
.y
= (short)HIWORD(lParam
);
3963 TREEVIEW_HitTest(infoPtr
, &ht
);
3964 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
3966 /* update focusedItem and redraw both items */
3967 if(ht
.hItem
&& (ht
.flags
& TVHT_ONITEM
))
3969 infoPtr
->focusedItem
= ht
.hItem
;
3970 InvalidateRect(hwnd
, &(((HTREEITEM
)(ht
.hItem
))->rect
), TRUE
);
3972 if(infoPtr
->selectedItem
)
3973 InvalidateRect(hwnd
, &(infoPtr
->selectedItem
->rect
), TRUE
);
3976 bTrack
= (ht
.flags
& TVHT_ONITEM
)
3977 && !(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
);
3980 * If the style allows editing and the node is already selected
3981 * and the click occurred on the item label...
3983 bDoLabelEdit
= (infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
3984 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
);
3986 /* Send NM_CLICK right away */
3988 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
3991 if (ht
.flags
& TVHT_ONITEMBUTTON
)
3993 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
3997 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
3998 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4000 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
4001 infoPtr
->dropItem
= ht
.hItem
;
4003 /* clean up focusedItem as we dragged and won't select this item */
4004 if(infoPtr
->focusedItem
)
4006 /* refresh the item that was focused */
4007 tempItem
= infoPtr
->focusedItem
;
4008 infoPtr
->focusedItem
= 0;
4009 InvalidateRect(infoPtr
->hwnd
, &tempItem
->rect
, TRUE
);
4011 /* refresh the selected item to return the filled background */
4012 InvalidateRect(infoPtr
->hwnd
, &(infoPtr
->selectedItem
->rect
), TRUE
);
4019 if (bTrack
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4024 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4025 KillTimer(hwnd
, TV_EDIT_TIMER
);
4027 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
4028 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
4030 else if (ht
.flags
& (TVHT_ONITEMICON
|TVHT_ONITEMLABEL
)) /* select the item if the hit was inside of the icon or text */
4033 * if we are TVS_SINGLEEXPAND then we want this single click to
4034 * do a bunch of things.
4036 if((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) &&
4037 (infoPtr
->hwndEdit
== 0))
4039 TREEVIEW_ITEM
*SelItem
;
4042 * Send the notification
4044 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, ht
.hItem
, 0);
4047 * Close the previous selection all the way to the root
4048 * as long as the new selection is not a child
4050 if((infoPtr
->selectedItem
)
4051 && (infoPtr
->selectedItem
!= ht
.hItem
))
4053 BOOL closeit
= TRUE
;
4056 /* determine if the hitItem is a child of the currently selected item */
4057 while(closeit
&& SelItem
&& TREEVIEW_ValidItem(infoPtr
, SelItem
) && (SelItem
!= infoPtr
->root
))
4059 closeit
= (SelItem
!= infoPtr
->selectedItem
);
4060 SelItem
= SelItem
->parent
;
4065 if(TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
4066 SelItem
= infoPtr
->selectedItem
;
4068 while(SelItem
&& (SelItem
!= ht
.hItem
) && TREEVIEW_ValidItem(infoPtr
, SelItem
) && (SelItem
!= infoPtr
->root
))
4070 TREEVIEW_Collapse(infoPtr
, SelItem
, FALSE
, FALSE
);
4071 SelItem
= SelItem
->parent
;
4077 * Expand the current item
4079 TREEVIEW_Expand(infoPtr
, ht
.hItem
, TVE_TOGGLE
, FALSE
);
4082 /* Select the current item */
4083 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4085 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4087 /* TVS_CHECKBOXES requires us to toggle the current state */
4088 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4089 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4099 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4103 if (infoPtr
->hwndEdit
)
4105 SetFocus(infoPtr
->hwnd
);
4109 ht
.pt
.x
= (short)LOWORD(lParam
);
4110 ht
.pt
.y
= (short)HIWORD(lParam
);
4112 TREEVIEW_HitTest(infoPtr
, &ht
);
4114 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4118 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4119 infoPtr
->dropItem
= ht
.hItem
;
4124 SetFocus(infoPtr
->hwnd
);
4125 TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
);
4132 TREEVIEW_RButtonUp(TREEVIEW_INFO
*infoPtr
, LPPOINT pPt
)
4139 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4141 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4145 HBITMAP hbmp
, hOldbmp
;
4152 if (!(infoPtr
->himlNormal
))
4155 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4158 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4160 hwtop
= GetDesktopWindow();
4161 htopdc
= GetDC(hwtop
);
4162 hdc
= CreateCompatibleDC(htopdc
);
4164 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4165 GetTextExtentPoint32W(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
),
4167 TRACE("%ld %ld %s %d\n", size
.cx
, size
.cy
, debugstr_w(dragItem
->pszText
),
4168 strlenW(dragItem
->pszText
));
4169 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4170 hOldbmp
= SelectObject(hdc
, hbmp
);
4172 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4177 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4178 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4182 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4183 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4186 /* draw item text */
4188 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4189 DrawTextW(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
), &rc
,
4191 SelectObject(hdc
, hOldFont
);
4192 SelectObject(hdc
, hOldbmp
);
4194 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4198 ReleaseDC(hwtop
, htopdc
);
4200 return (LRESULT
)infoPtr
->dragList
;
4203 /* Selection ************************************************************/
4206 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4209 TREEVIEW_ITEM
*prevSelect
;
4212 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4214 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4215 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4216 newSelect
? newSelect
->state
: 0);
4218 /* reset and redraw focusedItem if focusedItem was set so we don't */
4219 /* have to worry about the previously focused item when we set a new one */
4220 if(infoPtr
->focusedItem
)
4222 rcFocused
= (infoPtr
->focusedItem
)->rect
;
4223 infoPtr
->focusedItem
= 0;
4224 InvalidateRect(infoPtr
->hwnd
, &rcFocused
, TRUE
);
4230 prevSelect
= infoPtr
->selectedItem
;
4232 if (prevSelect
== newSelect
) {
4233 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4237 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4240 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4246 prevSelect
->state
&= ~TVIS_SELECTED
;
4248 newSelect
->state
|= TVIS_SELECTED
;
4250 infoPtr
->selectedItem
= newSelect
;
4252 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4255 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4257 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4259 TREEVIEW_SendTreeviewNotify(infoPtr
,
4262 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4267 case TVGN_DROPHILITE
:
4268 prevSelect
= infoPtr
->dropItem
;
4271 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4273 infoPtr
->dropItem
= newSelect
;
4276 newSelect
->state
|= TVIS_DROPHILITED
;
4278 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4279 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4282 case TVGN_FIRSTVISIBLE
:
4283 if (newSelect
!= NULL
)
4285 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4286 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4287 TREEVIEW_Invalidate(infoPtr
, NULL
);
4292 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4296 /* FIXME: handle NM_KILLFOCUS etc */
4298 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4300 if (item
!= NULL
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4303 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4305 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4311 /*************************************************************************
4312 * TREEVIEW_ProcessLetterKeys
4314 * Processes keyboard messages generated by pressing the letter keys
4316 * What this does is perform a case insensitive search from the
4317 * current position with the following quirks:
4318 * - If two chars or more are pressed in quick succession we search
4319 * for the corresponding string (e.g. 'abc').
4320 * - If there is a delay we wipe away the current search string and
4321 * restart with just that char.
4322 * - If the user keeps pressing the same character, whether slowly or
4323 * fast, so that the search string is entirely composed of this
4324 * character ('aaaaa' for instance), then we search for first item
4325 * that starting with that character.
4326 * - If the user types the above character in quick succession, then
4327 * we must also search for the corresponding string ('aaaaa'), and
4328 * go to that string if there is a match.
4336 * - The current implementation has a list of characters it will
4337 * accept and it ignores averything else. In particular it will
4338 * ignore accentuated characters which seems to match what
4339 * Windows does. But I'm not sure it makes sense to follow
4341 * - We don't sound a beep when the search fails.
4342 * - The search should start from the focused item, not from the selected
4343 * item. One reason for this is to allow for multiple selections in trees.
4344 * But currently infoPtr->focusedItem does not seem very usable.
4348 * TREEVIEW_ProcessLetterKeys
4350 static INT
TREEVIEW_ProcessLetterKeys(
4351 HWND hwnd
, /* handle to the window */
4352 WPARAM charCode
, /* the character code, the actual character */
4353 LPARAM keyData
/* key data */
4356 TREEVIEW_INFO
*infoPtr
;
4358 HTREEITEM endidx
,idx
;
4360 WCHAR buffer
[MAX_PATH
];
4361 DWORD timestamp
,elapsed
;
4363 /* simple parameter checking */
4364 if (!hwnd
|| !charCode
|| !keyData
)
4367 infoPtr
=(TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
4371 /* only allow the valid WM_CHARs through */
4372 if (!isalnum(charCode
) &&
4373 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4374 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4375 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4376 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4377 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4378 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4379 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4380 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4381 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4384 /* compute how much time elapsed since last keypress */
4385 timestamp
= GetTickCount();
4386 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4387 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4389 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4392 /* update the search parameters */
4393 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4394 if (elapsed
< KEY_DELAY
) {
4395 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
) / sizeof(WCHAR
)) {
4396 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4398 if (infoPtr
->charCode
!= charCode
) {
4399 infoPtr
->charCode
=charCode
=0;
4402 infoPtr
->charCode
=charCode
;
4403 infoPtr
->szSearchParam
[0]=charCode
;
4404 infoPtr
->nSearchParamLength
=1;
4405 /* Redundant with the 1 char string */
4409 /* and search from the current position */
4411 if (infoPtr
->selectedItem
!= NULL
) {
4412 endidx
=infoPtr
->selectedItem
;
4413 /* if looking for single character match,
4414 * then we must always move forward
4416 if (infoPtr
->nSearchParamLength
== 1)
4417 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4422 idx
=infoPtr
->root
->firstChild
;
4425 /* At the end point, sort out wrapping */
4428 /* If endidx is null, stop at the last item (ie top to bottom) */
4432 /* Otherwise, start again at the very beginning */
4433 idx
=infoPtr
->root
->firstChild
;
4435 /* But if we are stopping on the first child, end now! */
4436 if (idx
== endidx
) break;
4440 ZeroMemory(&item
, sizeof(item
));
4441 item
.mask
= TVIF_TEXT
;
4443 item
.pszText
= buffer
;
4444 item
.cchTextMax
= sizeof(buffer
);
4445 TREEVIEW_GetItemT( infoPtr
, &item
, TRUE
);
4447 /* check for a match */
4448 if (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4451 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4452 (nItem
!= infoPtr
->selectedItem
) &&
4453 (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4454 /* This would work but we must keep looking for a longer match */
4457 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4458 } while (idx
!= endidx
);
4460 if (nItem
!= NULL
) {
4461 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4462 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4469 /* Scrolling ************************************************************/
4472 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4475 BOOL hasFirstVisible
= infoPtr
->firstVisible
!= NULL
;
4476 HTREEITEM newFirstVisible
= NULL
;
4477 int visible_pos
= -1;
4479 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4482 if (!ISVISIBLE(item
))
4484 /* Expand parents as necessary. */
4487 /* see if we are trying to ensure that root is vislble */
4488 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4489 parent
= item
->parent
;
4491 parent
= item
; /* this item is the topmost item */
4493 while (parent
!= infoPtr
->root
)
4495 if (!(parent
->state
& TVIS_EXPANDED
))
4496 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, FALSE
);
4498 parent
= parent
->parent
;
4502 viscount
= TREEVIEW_GetVisibleCount(infoPtr
);
4504 TRACE("%p (%s) %ld - %ld viscount(%d)\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4505 hasFirstVisible
? infoPtr
->firstVisible
->visibleOrder
: -1, viscount
);
4507 if (hasFirstVisible
)
4508 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4510 if (visible_pos
< 0)
4512 /* item is before the start of the list: put it at the top. */
4513 newFirstVisible
= item
;
4515 else if (visible_pos
>= viscount
4516 /* Sometimes, before we are displayed, GVC is 0, causing us to
4517 * spuriously scroll up. */
4518 && visible_pos
> 0 && !(infoPtr
->dwStyle
& TVS_NOSCROLL
) )
4520 /* item is past the end of the list. */
4521 int scroll
= visible_pos
- viscount
;
4523 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4529 /* Scroll window so item's text is visible as much as possible */
4530 /* Calculation of amount of extra space is taken from EditLabel code */
4532 TEXTMETRICW textMetric
;
4533 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4535 x
= item
->textWidth
;
4537 GetTextMetricsW(hdc
, &textMetric
);
4538 ReleaseDC(infoPtr
->hwnd
, hdc
);
4540 x
+= (textMetric
.tmMaxCharWidth
* 2);
4541 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4543 if (item
->textOffset
< 0)
4544 pos
= item
->textOffset
;
4545 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4547 if (x
> infoPtr
->clientWidth
)
4548 pos
= item
->textOffset
;
4550 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4555 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4558 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4560 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4569 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4570 TREEVIEW_ITEM
*newFirstVisible
,
4571 BOOL bUpdateScrollPos
)
4575 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4577 if (newFirstVisible
!= NULL
)
4579 /* Prevent an empty gap from appearing at the bottom... */
4580 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4581 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4585 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4588 /* ... unless we just don't have enough items. */
4589 if (newFirstVisible
== NULL
)
4590 newFirstVisible
= infoPtr
->root
->firstChild
;
4594 if (infoPtr
->firstVisible
!= newFirstVisible
)
4596 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4598 infoPtr
->firstVisible
= newFirstVisible
;
4599 TREEVIEW_Invalidate(infoPtr
, NULL
);
4603 TREEVIEW_ITEM
*item
;
4604 int scroll
= infoPtr
->uItemHeight
*
4605 (infoPtr
->firstVisible
->visibleOrder
4606 - newFirstVisible
->visibleOrder
);
4608 infoPtr
->firstVisible
= newFirstVisible
;
4610 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4611 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4613 item
->rect
.top
+= scroll
;
4614 item
->rect
.bottom
+= scroll
;
4617 if (bUpdateScrollPos
)
4618 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4619 newFirstVisible
->visibleOrder
, TRUE
);
4621 ScrollWindowEx(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
, NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
4626 /************************************************************************
4627 * VScroll is always in units of visible items. i.e. we always have a
4628 * visible item aligned to the top of the control. (Unless we have no
4632 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4634 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4635 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4637 int nScrollCode
= LOWORD(wParam
);
4639 TRACE("wp %x\n", wParam
);
4641 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4644 if (infoPtr
->hwndEdit
)
4645 SetFocus(infoPtr
->hwnd
);
4647 if (!oldFirstVisible
)
4649 assert(infoPtr
->root
->firstChild
== NULL
);
4653 switch (nScrollCode
)
4656 newFirstVisible
= infoPtr
->root
->firstChild
;
4660 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4664 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4668 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4672 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4673 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4677 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4678 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4682 case SB_THUMBPOSITION
:
4683 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4684 infoPtr
->root
->firstChild
,
4685 (LONG
)(SHORT
)HIWORD(wParam
));
4692 if (newFirstVisible
!= NULL
)
4694 if (newFirstVisible
!= oldFirstVisible
)
4695 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4696 nScrollCode
!= SB_THUMBTRACK
);
4697 else if (nScrollCode
== SB_THUMBPOSITION
)
4698 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4699 newFirstVisible
->visibleOrder
, TRUE
);
4706 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4709 int scrollX
= infoPtr
->scrollX
;
4710 int nScrollCode
= LOWORD(wParam
);
4712 TRACE("wp %x\n", wParam
);
4714 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4717 if (infoPtr
->hwndEdit
)
4718 SetFocus(infoPtr
->hwnd
);
4720 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4721 /* shall never occur */
4728 switch (nScrollCode
)
4731 scrollX
-= infoPtr
->uItemHeight
;
4734 scrollX
+= infoPtr
->uItemHeight
;
4737 scrollX
-= infoPtr
->clientWidth
;
4740 scrollX
+= infoPtr
->clientWidth
;
4744 case SB_THUMBPOSITION
:
4745 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4752 if (scrollX
> maxWidth
)
4754 else if (scrollX
< 0)
4758 if (scrollX
!= infoPtr
->scrollX
)
4760 TREEVIEW_ITEM
*item
;
4761 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4763 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4764 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4766 item
->linesOffset
+= scroll_pixels
;
4767 item
->stateOffset
+= scroll_pixels
;
4768 item
->imageOffset
+= scroll_pixels
;
4769 item
->textOffset
+= scroll_pixels
;
4772 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4773 infoPtr
->scrollX
= scrollX
;
4774 UpdateWindow(infoPtr
->hwnd
);
4777 if (nScrollCode
!= SB_THUMBTRACK
)
4778 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
4784 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4787 UINT pulScrollLines
= 3;
4789 if (infoPtr
->firstVisible
== NULL
)
4792 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
4794 gcWheelDelta
= -(short)HIWORD(wParam
);
4795 pulScrollLines
*= (gcWheelDelta
/ WHEEL_DELTA
);
4797 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
4799 int newDy
= infoPtr
->firstVisible
->visibleOrder
+ pulScrollLines
;
4800 int maxDy
= infoPtr
->maxVisibleOrder
;
4808 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
4813 /* Create/Destroy *******************************************************/
4816 TREEVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
4818 static const WCHAR szDisplayW
[] = { 'D','I','S','P','L','A','Y','\0' };
4820 TREEVIEW_INFO
*infoPtr
;
4823 TRACE("wnd %p, style %lx\n", hwnd
, GetWindowLongW(hwnd
, GWL_STYLE
));
4825 infoPtr
= (TREEVIEW_INFO
*)Alloc(sizeof(TREEVIEW_INFO
));
4827 if (infoPtr
== NULL
)
4829 ERR("could not allocate info memory!\n");
4833 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
4835 infoPtr
->hwnd
= hwnd
;
4836 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
4838 infoPtr
->uNumItems
= 0;
4839 infoPtr
->cdmode
= 0;
4840 infoPtr
->uScrollTime
= 300; /* milliseconds */
4841 infoPtr
->bRedraw
= TRUE
;
4843 GetClientRect(hwnd
, &rcClient
);
4845 /* No scroll bars yet. */
4846 infoPtr
->clientWidth
= rcClient
.right
;
4847 infoPtr
->clientHeight
= rcClient
.bottom
;
4848 infoPtr
->uInternalStatus
= 0;
4850 infoPtr
->treeWidth
= 0;
4851 infoPtr
->treeHeight
= 0;
4853 infoPtr
->uIndent
= MINIMUM_INDENT
;
4854 infoPtr
->selectedItem
= 0;
4855 infoPtr
->focusedItem
= 0;
4856 infoPtr
->hotItem
= 0;
4857 infoPtr
->firstVisible
= 0;
4858 infoPtr
->maxVisibleOrder
= 0;
4859 infoPtr
->dropItem
= 0;
4860 infoPtr
->insertMarkItem
= 0;
4861 infoPtr
->insertBeforeorAfter
= 0;
4864 infoPtr
->scrollX
= 0;
4866 infoPtr
->clrBk
= GetSysColor(COLOR_WINDOW
);
4867 infoPtr
->clrText
= -1; /* use system color */
4868 infoPtr
->clrLine
= RGB(128, 128, 128);
4869 infoPtr
->clrInsertMark
= GetSysColor(COLOR_BTNTEXT
);
4873 infoPtr
->hwndEdit
= 0;
4874 infoPtr
->wpEditOrig
= NULL
;
4875 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
4876 infoPtr
->bLabelChanged
= FALSE
;
4878 infoPtr
->himlNormal
= NULL
;
4879 infoPtr
->himlState
= NULL
;
4880 infoPtr
->normalImageWidth
= 0;
4881 infoPtr
->normalImageHeight
= 0;
4882 infoPtr
->stateImageWidth
= 0;
4883 infoPtr
->stateImageHeight
= 0;
4885 infoPtr
->items
= DPA_Create(16);
4887 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
4888 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW(&lf
);
4889 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
4890 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
4891 infoPtr
->hcurHand
= LoadCursorW(NULL
, (LPWSTR
)IDC_HAND
);
4893 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
4895 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
4896 infoPtr
->root
->state
= TVIS_EXPANDED
;
4897 infoPtr
->root
->iLevel
= -1;
4898 infoPtr
->root
->visibleOrder
= -1;
4900 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
4902 infoPtr
->bTransparent
= ( GetWindowLongW( hwnd
, GWL_STYLE
) & TBSTYLE_FLAT
);
4905 infoPtr
->hwndToolTip
= 0;
4907 infoPtr
->bNtfUnicode
= IsWindowUnicode (hwnd
);
4909 /* Determine what type of notify should be issued */
4910 /* sets infoPtr->bNtfUnicode */
4911 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
4913 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
4914 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(hwnd
);
4916 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4919 HBITMAP hbm
, hbmOld
;
4923 infoPtr
->himlState
=
4924 ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
4926 hdcScreen
= CreateDCW(szDisplayW
, NULL
, NULL
, NULL
);
4928 /* Create a coloured bitmap compatible with the screen depth
4929 because checkboxes are not black&white */
4930 hdc
= CreateCompatibleDC(hdcScreen
);
4931 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
4932 hbmOld
= SelectObject(hdc
, hbm
);
4934 rc
.left
= 0; rc
.top
= 0;
4935 rc
.right
= 48; rc
.bottom
= 16;
4936 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
4938 rc
.left
= 18; rc
.top
= 2;
4939 rc
.right
= 30; rc
.bottom
= 14;
4940 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4941 DFCS_BUTTONCHECK
|DFCS_FLAT
);
4943 rc
.left
= 34; rc
.right
= 46;
4944 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4945 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
4947 SelectObject(hdc
, hbmOld
);
4948 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
4949 GetSysColor(COLOR_WINDOW
));
4950 TRACE("checkbox index %d\n", nIndex
);
4954 DeleteDC(hdcScreen
);
4956 infoPtr
->stateImageWidth
= 16;
4957 infoPtr
->stateImageHeight
= 16;
4960 /* Make sure actual scrollbar state is consistent with uInternalStatus */
4961 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
4962 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
4964 OpenThemeData (hwnd
, themeClass
);
4971 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
4975 TREEVIEW_RemoveTree(infoPtr
);
4977 /* tool tip is automatically destroyed: we are its owner */
4979 /* Restore original wndproc */
4980 if (infoPtr
->hwndEdit
)
4981 SetWindowLongPtrW(infoPtr
->hwndEdit
, GWLP_WNDPROC
,
4982 (DWORD_PTR
)infoPtr
->wpEditOrig
);
4984 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
4986 /* Deassociate treeview from the window before doing anything drastic. */
4987 SetWindowLongPtrW(infoPtr
->hwnd
, 0, (DWORD_PTR
)NULL
);
4990 DeleteObject(infoPtr
->hDefaultFont
);
4991 DeleteObject(infoPtr
->hBoldFont
);
4992 DeleteObject(infoPtr
->hUnderlineFont
);
4998 /* Miscellaneous Messages ***********************************************/
5001 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
5009 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
5010 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
5011 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
5012 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
5013 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
5014 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
5015 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
5016 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
5017 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
5021 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
5023 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
5025 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
5027 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
5033 /************************************************************************
5036 * VK_UP Move selection to the previous non-hidden item.
5037 * VK_DOWN Move selection to the next non-hidden item.
5038 * VK_HOME Move selection to the first item.
5039 * VK_END Move selection to the last item.
5040 * VK_LEFT If expanded then collapse, otherwise move to parent.
5041 * VK_RIGHT If collapsed then expand, otherwise move to first child.
5043 * VK_SUBTRACT Collapse.
5044 * VK_MULTIPLY Expand all.
5045 * VK_PRIOR Move up GetVisibleCount items.
5046 * VK_NEXT Move down GetVisibleCount items.
5047 * VK_BACK Move to parent.
5048 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
5051 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
5053 /* If it is non-NULL and different, it will be selected and visible. */
5054 TREEVIEW_ITEM
*newSelection
= NULL
;
5056 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
5058 TRACE("%x\n", wParam
);
5060 if (prevItem
== NULL
)
5063 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
5064 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
5069 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
5071 newSelection
= infoPtr
->root
->firstChild
;
5075 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
5079 newSelection
= infoPtr
->root
->firstChild
;
5083 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
5087 if (prevItem
->state
& TVIS_EXPANDED
)
5089 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5091 else if (prevItem
->parent
!= infoPtr
->root
)
5093 newSelection
= prevItem
->parent
;
5098 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
5100 if (!(prevItem
->state
& TVIS_EXPANDED
))
5101 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5104 newSelection
= prevItem
->firstChild
;
5111 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5115 if (!(prevItem
->state
& TVIS_EXPANDED
))
5116 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5120 if (prevItem
->state
& TVIS_EXPANDED
)
5121 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5126 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5127 -TREEVIEW_GetVisibleCount(infoPtr
));
5132 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5133 TREEVIEW_GetVisibleCount(infoPtr
));
5137 newSelection
= prevItem
->parent
;
5138 if (newSelection
== infoPtr
->root
)
5139 newSelection
= NULL
;
5143 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5144 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5148 if (newSelection
&& newSelection
!= prevItem
)
5150 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5153 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5161 TREEVIEW_MouseLeave (TREEVIEW_INFO
* infoPtr
)
5163 if (infoPtr
->hotItem
)
5165 /* remove hot effect from item */
5166 InvalidateRect(infoPtr
->hwnd
, &infoPtr
->hotItem
->rect
, TRUE
);
5167 infoPtr
->hotItem
= NULL
;
5173 TREEVIEW_MouseMove (TREEVIEW_INFO
* infoPtr
, WPARAM wParam
, LPARAM lParam
)
5176 TRACKMOUSEEVENT trackinfo
;
5177 TREEVIEW_ITEM
* item
;
5179 /* fill in the TRACKMOUSEEVENT struct */
5180 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5181 trackinfo
.dwFlags
= TME_QUERY
;
5182 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5183 trackinfo
.dwHoverTime
= HOVER_DEFAULT
;
5185 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5186 _TrackMouseEvent(&trackinfo
);
5188 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5189 if(!(trackinfo
.dwFlags
& TME_LEAVE
))
5191 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5193 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5194 /* and can properly deactivate the hot item */
5195 _TrackMouseEvent(&trackinfo
);
5198 pt
.x
= (INT
)LOWORD(lParam
);
5199 pt
.y
= (INT
)HIWORD(lParam
);
5201 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5203 if (item
!= infoPtr
->hotItem
)
5205 /* redraw old hot item */
5206 if (infoPtr
->hotItem
)
5207 InvalidateRect(infoPtr
->hwnd
, &infoPtr
->hotItem
->rect
, TRUE
);
5208 infoPtr
->hotItem
= item
;
5209 /* redraw new hot item */
5210 if (infoPtr
->hotItem
)
5211 InvalidateRect(infoPtr
->hwnd
, &infoPtr
->hotItem
->rect
, TRUE
);
5217 /* Draw themed border */
5218 static BOOL
nc_paint (TREEVIEW_INFO
*infoPtr
, HRGN region
)
5220 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5224 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
5225 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
5227 if (!theme
) return FALSE
;
5229 GetWindowRect(infoPtr
->hwnd
, &r
);
5231 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
5232 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
5233 if (region
!= (HRGN
)1)
5234 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
5235 OffsetRect(&r
, -r
.left
, -r
.top
);
5237 dc
= GetDCEx(infoPtr
->hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
5238 OffsetRect(&r
, -r
.left
, -r
.top
);
5240 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
5241 DrawThemeParentBackground(infoPtr
->hwnd
, dc
, &r
);
5242 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
5243 ReleaseDC(infoPtr
->hwnd
, dc
);
5245 /* Call default proc to get the scrollbars etc. painted */
5246 DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
5252 TREEVIEW_Notify(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5254 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5256 if (lpnmh
->code
== PGN_CALCSIZE
) {
5257 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5259 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5260 lppgc
->iWidth
= infoPtr
->treeWidth
;
5261 TRACE("got PGN_CALCSIZE, returning horz size = %ld, client=%ld\n",
5262 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5265 lppgc
->iHeight
= infoPtr
->treeHeight
;
5266 TRACE("got PGN_CALCSIZE, returning vert size = %ld, client=%ld\n",
5267 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5271 return DefWindowProcW(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5274 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
5278 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
5280 if (nCommand
!= NF_REQUERY
) return 0;
5282 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
5283 TRACE("format=%d\n", format
);
5285 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
) return 0;
5287 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
5293 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5295 if (wParam
== SIZE_RESTORED
)
5297 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5298 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5300 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5301 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5302 TREEVIEW_UpdateScrollBars(infoPtr
);
5306 FIXME("WM_SIZE flag %x %lx not handled\n", wParam
, lParam
);
5309 TREEVIEW_Invalidate(infoPtr
, NULL
);
5314 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5316 TRACE("(%x %lx)\n", wParam
, lParam
);
5318 if (wParam
== GWL_STYLE
)
5320 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5322 /* we have to take special care about tooltips */
5323 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5325 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5327 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5332 DestroyWindow(infoPtr
->hwndToolTip
);
5333 infoPtr
->hwndToolTip
= 0;
5337 infoPtr
->dwStyle
= dwNewStyle
;
5340 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5341 TREEVIEW_UpdateScrollBars(infoPtr
);
5342 TREEVIEW_Invalidate(infoPtr
, NULL
);
5348 TREEVIEW_SetCursor(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5351 TREEVIEW_ITEM
* item
;
5354 ScreenToClient(infoPtr
->hwnd
, &pt
);
5356 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5358 /* FIXME: send NM_SETCURSOR */
5360 if (item
&& (infoPtr
->dwStyle
& TVS_TRACKSELECT
))
5362 SetCursor(infoPtr
->hcurHand
);
5366 return DefWindowProcW(infoPtr
->hwnd
, WM_SETCURSOR
, wParam
, lParam
);
5370 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5374 if (!infoPtr
->selectedItem
)
5376 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5380 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5381 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5386 TREEVIEW_KillFocus(TREEVIEW_INFO
*infoPtr
)
5390 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5391 UpdateWindow(infoPtr
->hwnd
);
5392 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5396 /* update theme after a WM_THEMECHANGED message */
5397 static LRESULT
theme_changed (TREEVIEW_INFO
* infoPtr
)
5399 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5400 CloseThemeData (theme
);
5401 OpenThemeData (infoPtr
->hwnd
, themeClass
);
5406 static LRESULT WINAPI
5407 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5409 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5411 TRACE("hwnd %p msg %04x wp=%08x lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5413 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5416 if (uMsg
== WM_CREATE
)
5417 TREEVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
5424 case TVM_CREATEDRAGIMAGE
:
5425 return TREEVIEW_CreateDragImage(infoPtr
, wParam
, lParam
);
5427 case TVM_DELETEITEM
:
5428 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5430 case TVM_EDITLABELA
:
5431 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5433 case TVM_EDITLABELW
:
5434 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5436 case TVM_ENDEDITLABELNOW
:
5437 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5439 case TVM_ENSUREVISIBLE
:
5440 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5443 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5445 case TVM_GETBKCOLOR
:
5446 return TREEVIEW_GetBkColor(infoPtr
);
5449 return TREEVIEW_GetCount(infoPtr
);
5451 case TVM_GETEDITCONTROL
:
5452 return TREEVIEW_GetEditControl(infoPtr
);
5454 case TVM_GETIMAGELIST
:
5455 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5458 return TREEVIEW_GetIndent(infoPtr
);
5460 case TVM_GETINSERTMARKCOLOR
:
5461 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5463 case TVM_GETISEARCHSTRINGA
:
5464 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5467 case TVM_GETISEARCHSTRINGW
:
5468 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5472 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
, FALSE
);
5475 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
, TRUE
);
5477 case TVM_GETITEMHEIGHT
:
5478 return TREEVIEW_GetItemHeight(infoPtr
);
5480 case TVM_GETITEMRECT
:
5481 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5483 case TVM_GETITEMSTATE
:
5484 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5486 case TVM_GETLINECOLOR
:
5487 return TREEVIEW_GetLineColor(infoPtr
);
5489 case TVM_GETNEXTITEM
:
5490 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5492 case TVM_GETSCROLLTIME
:
5493 return TREEVIEW_GetScrollTime(infoPtr
);
5495 case TVM_GETTEXTCOLOR
:
5496 return TREEVIEW_GetTextColor(infoPtr
);
5498 case TVM_GETTOOLTIPS
:
5499 return TREEVIEW_GetToolTips(infoPtr
);
5501 case TVM_GETUNICODEFORMAT
:
5502 return TREEVIEW_GetUnicodeFormat(infoPtr
);
5504 case TVM_GETVISIBLECOUNT
:
5505 return TREEVIEW_GetVisibleCount(infoPtr
);
5508 return TREEVIEW_HitTest(infoPtr
, (LPTVHITTESTINFO
)lParam
);
5510 case TVM_INSERTITEMA
:
5511 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
, FALSE
);
5513 case TVM_INSERTITEMW
:
5514 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
, TRUE
);
5516 case TVM_SELECTITEM
:
5517 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5519 case TVM_SETBKCOLOR
:
5520 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5522 case TVM_SETIMAGELIST
:
5523 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5526 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5528 case TVM_SETINSERTMARK
:
5529 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5531 case TVM_SETINSERTMARKCOLOR
:
5532 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5535 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
, FALSE
);
5538 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
, TRUE
);
5540 case TVM_SETLINECOLOR
:
5541 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5543 case TVM_SETITEMHEIGHT
:
5544 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5546 case TVM_SETSCROLLTIME
:
5547 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5549 case TVM_SETTEXTCOLOR
:
5550 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5552 case TVM_SETTOOLTIPS
:
5553 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5555 case TVM_SETUNICODEFORMAT
:
5556 return TREEVIEW_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
5558 case TVM_SORTCHILDREN
:
5559 return TREEVIEW_SortChildren(infoPtr
, wParam
, lParam
);
5561 case TVM_SORTCHILDRENCB
:
5562 return TREEVIEW_SortChildrenCB(infoPtr
, wParam
, (LPTVSORTCB
)lParam
);
5565 return TREEVIEW_ProcessLetterKeys( hwnd
, wParam
, lParam
);
5568 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5571 return TREEVIEW_Destroy(infoPtr
);
5576 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5579 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5582 return TREEVIEW_GetFont(infoPtr
);
5585 return TREEVIEW_HScroll(infoPtr
, wParam
);
5588 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5591 return TREEVIEW_KillFocus(infoPtr
);
5593 case WM_LBUTTONDBLCLK
:
5594 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5596 case WM_LBUTTONDOWN
:
5597 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5599 /* WM_MBUTTONDOWN */
5602 return TREEVIEW_MouseLeave(infoPtr
);
5605 if (infoPtr
->dwStyle
& TVS_TRACKSELECT
)
5606 return TREEVIEW_MouseMove(infoPtr
, wParam
, lParam
);
5611 if (nc_paint (infoPtr
, (HRGN
)wParam
))
5616 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5618 case WM_NOTIFYFORMAT
:
5619 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5621 case WM_PRINTCLIENT
:
5623 return TREEVIEW_Paint(infoPtr
, wParam
);
5625 case WM_RBUTTONDOWN
:
5626 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5629 return TREEVIEW_SetCursor(infoPtr
, wParam
, lParam
);
5632 return TREEVIEW_SetFocus(infoPtr
);
5635 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5638 return TREEVIEW_SetRedraw(infoPtr
, wParam
, lParam
);
5641 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5643 case WM_STYLECHANGED
:
5644 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5646 /* WM_SYSCOLORCHANGE */
5651 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5653 case WM_THEMECHANGED
:
5654 return theme_changed (infoPtr
);
5657 return TREEVIEW_VScroll(infoPtr
, wParam
);
5659 /* WM_WININICHANGE */
5662 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
5664 return TREEVIEW_MouseWheel(infoPtr
, wParam
);
5667 TRACE("drawItem\n");
5671 /* This mostly catches MFC and Delphi messages. :( */
5672 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
5673 TRACE("Unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
5675 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
5680 /* Class Registration ***************************************************/
5683 TREEVIEW_Register(void)
5689 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
5690 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5691 wndClass
.lpfnWndProc
= TREEVIEW_WindowProc
;
5692 wndClass
.cbClsExtra
= 0;
5693 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5695 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
5696 wndClass
.hbrBackground
= 0;
5697 wndClass
.lpszClassName
= WC_TREEVIEWW
;
5699 RegisterClassW(&wndClass
);
5704 TREEVIEW_Unregister(void)
5706 UnregisterClassW(WC_TREEVIEWW
, NULL
);
5710 /* Tree Verification ****************************************************/
5714 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
5716 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5717 TREEVIEW_ITEM
*item
)
5719 assert(infoPtr
!= NULL
);
5720 assert(item
!= NULL
);
5722 /* both NULL, or both non-null */
5723 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5725 assert(item
->firstChild
!= item
);
5726 assert(item
->lastChild
!= item
);
5728 if (item
->firstChild
)
5730 assert(item
->firstChild
->parent
== item
);
5731 assert(item
->firstChild
->prevSibling
== NULL
);
5734 if (item
->lastChild
)
5736 assert(item
->lastChild
->parent
== item
);
5737 assert(item
->lastChild
->nextSibling
== NULL
);
5740 assert(item
->nextSibling
!= item
);
5741 if (item
->nextSibling
)
5743 assert(item
->nextSibling
->parent
== item
->parent
);
5744 assert(item
->nextSibling
->prevSibling
== item
);
5747 assert(item
->prevSibling
!= item
);
5748 if (item
->prevSibling
)
5750 assert(item
->prevSibling
->parent
== item
->parent
);
5751 assert(item
->prevSibling
->nextSibling
== item
);
5756 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
5758 assert(item
!= NULL
);
5760 assert(item
->parent
!= NULL
);
5761 assert(item
->parent
!= item
);
5762 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5764 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5766 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5768 TREEVIEW_VerifyChildren(infoPtr
, item
);
5772 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
5774 TREEVIEW_ITEM
*child
;
5775 assert(item
!= NULL
);
5777 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5778 TREEVIEW_VerifyItem(infoPtr
, child
);
5782 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5784 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5786 assert(root
!= NULL
);
5787 assert(root
->iLevel
== -1);
5788 assert(root
->parent
== NULL
);
5789 assert(root
->prevSibling
== NULL
);
5791 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
5793 TREEVIEW_VerifyChildren(infoPtr
, root
);
5797 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
5799 assert(infoPtr
!= NULL
);
5801 TREEVIEW_VerifyRoot(infoPtr
);