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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * Note that TREEVIEW_INFO * and HTREEITEM are the same thing.
26 * Note2: If item's text == LPSTR_TEXTCALLBACKA we allocate buffer
27 * of size TEXT_CALLBACK_SIZE in DoSetItem.
28 * We use callbackMask to keep track of fields to be updated.
31 * missing notifications: TVN_GETINFOTIP, TVN_KEYDOWN,
34 * missing styles: TVS_FULLROWSELECT, TVS_INFOTIP, TVS_RTLREADING,
36 * missing item styles: TVIS_EXPANDPARTIAL, TVIS_EX_FLAT,
39 * Make the insertion mark look right.
40 * Scroll (instead of repaint) as much as possible.
45 WINE_DEFAULT_DEBUG_CHANNEL(treeview
);
47 /* internal structures */
48 typedef struct tagTREEVIEW_INFO
51 HWND hwndNotify
; /* Owner window to send notifications to */
56 UINT uNumItems
; /* number of valid TREEVIEW_ITEMs */
57 INT cdmode
; /* last custom draw setting */
58 UINT uScrollTime
; /* max. time for scrolling in milliseconds */
59 BOOL bRedraw
; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
61 UINT uItemHeight
; /* item height */
64 LONG clientWidth
; /* width of control window */
65 LONG clientHeight
; /* height of control window */
67 LONG treeWidth
; /* width of visible tree items */
68 LONG treeHeight
; /* height of visible tree items */
70 UINT uIndent
; /* indentation in pixels */
71 HTREEITEM selectedItem
; /* handle to selected item or 0 if none */
72 HTREEITEM hotItem
; /* handle currently under cursor, 0 if none */
73 HTREEITEM focusedItem
; /* item that was under the cursor when WM_LBUTTONDOWN was received */
74 HTREEITEM editItem
; /* item being edited with builtin edit box */
76 HTREEITEM firstVisible
; /* handle to first visible item */
78 HTREEITEM dropItem
; /* handle to item selected by drag cursor */
79 HTREEITEM insertMarkItem
; /* item after which insertion mark is placed */
80 BOOL insertBeforeorAfter
; /* flag used by TVM_SETINSERTMARK */
81 HIMAGELIST dragList
; /* Bitmap of dragged item */
87 COLORREF clrInsertMark
;
92 HFONT hBoldUnderlineFont
;
97 WNDPROC wpEditOrig
; /* orig window proc for subclassing edit */
98 BOOL bIgnoreEditKillFocus
;
101 BOOL bNtfUnicode
; /* TRUE if should send NOTIFY with W */
102 HIMAGELIST himlNormal
;
103 int normalImageHeight
;
104 int normalImageWidth
;
105 HIMAGELIST himlState
;
106 int stateImageHeight
;
110 DWORD lastKeyPressTimestamp
;
112 INT nSearchParamLength
;
113 WCHAR szSearchParam
[ MAX_PATH
];
116 typedef struct _TREEITEM
/* HTREEITEM is a _TREEINFO *. */
118 HTREEITEM parent
; /* handle to parent or 0 if at root */
119 HTREEITEM nextSibling
; /* handle to next item in list, 0 if last */
120 HTREEITEM firstChild
; /* handle to first child or 0 if no child */
132 int iIntegral
; /* item height multiplier (1 is normal) */
133 int iLevel
; /* indentation level:0=root level */
135 HTREEITEM prevSibling
; /* handle to prev item in list, 0 if first */
141 LONG textWidth
; /* horizontal text extent for pszText */
142 LONG visibleOrder
; /* visible ordering, 0 is first visible item */
143 const TREEVIEW_INFO
*infoPtr
; /* tree data this item belongs to */
146 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
147 #define KEY_DELAY 450
149 /* bitflags for infoPtr->uInternalStatus */
151 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
152 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
153 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
154 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
155 #define TV_RDRAG 0x10 /* ditto Rbutton */
156 #define TV_RDRAGGING 0x20
158 /* bitflags for infoPtr->timer */
160 #define TV_EDIT_TIMER 2
161 #define TV_EDIT_TIMER_SET 2
163 #define TEXT_CALLBACK_SIZE 260
165 #define TREEVIEW_LEFT_MARGIN 8
167 #define MINIMUM_INDENT 19
169 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
171 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
172 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
173 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
175 #define GETLINECOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrGrayText : (x))
176 #define GETBKCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindow : (x))
177 #define GETTXTCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindowText : (x))
178 #define GETINSCOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrBtnText : (x))
180 static const WCHAR themeClass
[] = { 'T','r','e','e','v','i','e','w',0 };
183 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
186 static VOID
TREEVIEW_Invalidate(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
188 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
189 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
190 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
191 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
192 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
193 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
195 /* Random Utilities *****************************************************/
196 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
198 /* Returns the treeview private data if hwnd is a treeview.
199 * Otherwise returns an undefined value. */
200 static inline TREEVIEW_INFO
*
201 TREEVIEW_GetInfoPtr(HWND hwnd
)
203 return (TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
206 /* Don't call this. Nothing wants an item index. */
208 TREEVIEW_GetItemIndex(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
210 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
213 /* Checks if item has changed and needs to be redrawn */
214 static inline BOOL
item_changed (const TREEVIEW_ITEM
*tiOld
, const TREEVIEW_ITEM
*tiNew
,
215 const TVITEMEXW
*tvChange
)
217 /* Number of children has changed */
218 if ((tvChange
->mask
& TVIF_CHILDREN
) && (tiOld
->cChildren
!= tiNew
->cChildren
))
221 /* Image has changed and it's not a callback */
222 if ((tvChange
->mask
& TVIF_IMAGE
) && (tiOld
->iImage
!= tiNew
->iImage
) &&
223 tiNew
->iImage
!= I_IMAGECALLBACK
)
226 /* Selected image has changed and it's not a callback */
227 if ((tvChange
->mask
& TVIF_SELECTEDIMAGE
) && (tiOld
->iSelectedImage
!= tiNew
->iSelectedImage
) &&
228 tiNew
->iSelectedImage
!= I_IMAGECALLBACK
)
231 if ((tvChange
->mask
& TVIF_EXPANDEDIMAGE
) && (tiOld
->iExpandedImage
!= tiNew
->iExpandedImage
) &&
232 tiNew
->iExpandedImage
!= I_IMAGECALLBACK
)
235 /* Text has changed and it's not a callback */
236 if ((tvChange
->mask
& TVIF_TEXT
) && (tiOld
->pszText
!= tiNew
->pszText
) &&
237 tiNew
->pszText
!= LPSTR_TEXTCALLBACKW
)
240 /* Indent has changed */
241 if ((tvChange
->mask
& TVIF_INTEGRAL
) && (tiOld
->iIntegral
!= tiNew
->iIntegral
))
244 /* Item state has changed */
245 if ((tvChange
->mask
& TVIF_STATE
) && ((tiOld
->state
^ tiNew
->state
) & tvChange
->stateMask
))
251 /***************************************************************************
252 * This method checks that handle is an item for this tree.
255 TREEVIEW_ValidItem(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
257 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
259 TRACE("invalid item %p\n", handle
);
267 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
271 GetObjectW(hOrigFont
, sizeof(font
), &font
);
272 font
.lfWeight
= FW_BOLD
;
273 return CreateFontIndirectW(&font
);
277 TREEVIEW_CreateUnderlineFont(HFONT hOrigFont
)
281 GetObjectW(hOrigFont
, sizeof(font
), &font
);
282 font
.lfUnderline
= TRUE
;
283 return CreateFontIndirectW(&font
);
287 TREEVIEW_CreateBoldUnderlineFont(HFONT hfont
)
291 GetObjectW(hfont
, sizeof(font
), &font
);
292 font
.lfWeight
= FW_BOLD
;
293 font
.lfUnderline
= TRUE
;
294 return CreateFontIndirectW(&font
);
298 TREEVIEW_FontForItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
300 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
301 return item
->state
& TVIS_BOLD
? infoPtr
->hBoldUnderlineFont
: infoPtr
->hUnderlineFont
;
302 if (item
->state
& TVIS_BOLD
)
303 return infoPtr
->hBoldFont
;
304 return infoPtr
->hFont
;
307 /* for trace/debugging purposes only */
309 TREEVIEW_ItemName(const TREEVIEW_ITEM
*item
)
311 if (item
== NULL
) return "<null item>";
312 if (item
->pszText
== LPSTR_TEXTCALLBACKW
) return "<callback>";
313 if (item
->pszText
== NULL
) return "<null>";
314 return debugstr_w(item
->pszText
);
317 /* An item is not a child of itself. */
319 TREEVIEW_IsChildOf(const TREEVIEW_ITEM
*parent
, const TREEVIEW_ITEM
*child
)
323 child
= child
->parent
;
324 if (child
== parent
) return TRUE
;
325 } while (child
!= NULL
);
331 /* Tree Traversal *******************************************************/
333 /***************************************************************************
334 * This method returns the last expanded sibling or child child item
337 static TREEVIEW_ITEM
*
338 TREEVIEW_GetLastListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
340 if (!item
) return NULL
;
342 while (item
->lastChild
)
344 if (item
->state
& TVIS_EXPANDED
)
345 item
= item
->lastChild
;
350 if (item
== infoPtr
->root
)
356 /***************************************************************************
357 * This method returns the previous non-hidden item in the list not
358 * considering the tree hierarchy.
360 static TREEVIEW_ITEM
*
361 TREEVIEW_GetPrevListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
363 if (tvItem
->prevSibling
)
365 /* This item has a prevSibling, get the last item in the sibling's tree. */
366 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
368 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
369 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
375 /* this item does not have a prevSibling, get the parent */
376 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
381 /***************************************************************************
382 * This method returns the next physical item in the treeview not
383 * considering the tree hierarchy.
385 static TREEVIEW_ITEM
*
386 TREEVIEW_GetNextListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
389 * If this item has children and is expanded, return the first child
391 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
393 return tvItem
->firstChild
;
398 * try to get the sibling
400 if (tvItem
->nextSibling
)
401 return tvItem
->nextSibling
;
404 * Otherwise, get the parent's sibling.
406 while (tvItem
->parent
)
408 tvItem
= tvItem
->parent
;
410 if (tvItem
->nextSibling
)
411 return tvItem
->nextSibling
;
417 /***************************************************************************
418 * This method returns the nth item starting at the given item. It returns
419 * the last item (or first) we we run out of items.
421 * Will scroll backward if count is <0.
422 * forward if count is >0.
424 static TREEVIEW_ITEM
*
425 TREEVIEW_GetListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
428 TREEVIEW_ITEM
*(*next_item
)(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
429 TREEVIEW_ITEM
*previousItem
;
431 assert(item
!= NULL
);
435 next_item
= TREEVIEW_GetNextListItem
;
440 next_item
= TREEVIEW_GetPrevListItem
;
448 item
= next_item(infoPtr
, item
);
450 } while (--count
&& item
!= NULL
);
453 return item
? item
: previousItem
;
456 /* Notifications ************************************************************/
458 static INT
get_notifycode(const TREEVIEW_INFO
*infoPtr
, INT code
)
460 if (!infoPtr
->bNtfUnicode
) {
462 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
463 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
464 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
465 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
466 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
467 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
468 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
469 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
470 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
471 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
472 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
473 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
480 TREEVIEW_SendRealNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, NMHDR
*hdr
)
482 TRACE("code=%d, hdr=%p\n", code
, hdr
);
484 hdr
->hwndFrom
= infoPtr
->hwnd
;
485 hdr
->idFrom
= GetWindowLongPtrW(infoPtr
->hwnd
, GWLP_ID
);
486 hdr
->code
= get_notifycode(infoPtr
, code
);
488 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, hdr
->idFrom
, (LPARAM
)hdr
);
492 TREEVIEW_SendSimpleNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
)
495 return TREEVIEW_SendRealNotify(infoPtr
, code
, &hdr
);
499 TREEVIEW_TVItemFromItem(const TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMW
*tvItem
, TREEVIEW_ITEM
*item
)
502 tvItem
->hItem
= item
;
503 tvItem
->state
= item
->state
;
504 tvItem
->stateMask
= 0;
505 tvItem
->iImage
= item
->iImage
;
506 tvItem
->iSelectedImage
= item
->iSelectedImage
;
507 tvItem
->cChildren
= item
->cChildren
;
508 tvItem
->lParam
= item
->lParam
;
512 if (!infoPtr
->bNtfUnicode
)
514 tvItem
->cchTextMax
= WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0, NULL
, NULL
);
515 tvItem
->pszText
= Alloc (tvItem
->cchTextMax
);
516 WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, 0, 0 );
520 tvItem
->cchTextMax
= item
->cchTextMax
;
521 tvItem
->pszText
= item
->pszText
;
526 tvItem
->cchTextMax
= 0;
527 tvItem
->pszText
= NULL
;
532 TREEVIEW_SendTreeviewNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
533 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
538 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
539 code
, action
, oldItem
, newItem
);
541 memset(&nmhdr
, 0, sizeof(NMTREEVIEWW
));
542 nmhdr
.action
= action
;
545 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
548 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
553 ret
= TREEVIEW_SendRealNotify(infoPtr
, code
, &nmhdr
.hdr
);
554 if (!infoPtr
->bNtfUnicode
)
556 Free(nmhdr
.itemOld
.pszText
);
557 Free(nmhdr
.itemNew
.pszText
);
563 TREEVIEW_SendTreeviewDnDNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
,
564 HTREEITEM dragItem
, POINT pt
)
568 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
571 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
572 nmhdr
.itemNew
.hItem
= dragItem
;
573 nmhdr
.itemNew
.state
= dragItem
->state
;
574 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
576 nmhdr
.ptDrag
.x
= pt
.x
;
577 nmhdr
.ptDrag
.y
= pt
.y
;
579 return TREEVIEW_SendRealNotify(infoPtr
, code
, &nmhdr
.hdr
);
584 TREEVIEW_SendCustomDrawNotify(const TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
587 NMTVCUSTOMDRAW nmcdhdr
;
590 TRACE("drawstage:%x hdc:%p\n", dwDrawStage
, hdc
);
592 nmcd
= &nmcdhdr
.nmcd
;
593 nmcd
->dwDrawStage
= dwDrawStage
;
596 nmcd
->dwItemSpec
= 0;
597 nmcd
->uItemState
= 0;
598 nmcd
->lItemlParam
= 0;
599 nmcdhdr
.clrText
= infoPtr
->clrText
;
600 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
603 return TREEVIEW_SendRealNotify(infoPtr
, NM_CUSTOMDRAW
, &nmcdhdr
.nmcd
.hdr
);
606 /* FIXME: need to find out when the flags in uItemState need to be set */
609 TREEVIEW_SendCustomDrawItemNotify(const TREEVIEW_INFO
*infoPtr
, HDC hdc
,
610 TREEVIEW_ITEM
*item
, UINT uItemDrawState
,
611 NMTVCUSTOMDRAW
*nmcdhdr
)
615 DWORD_PTR dwItemSpec
;
618 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
619 dwItemSpec
= (DWORD_PTR
)item
;
621 if (item
->state
& TVIS_SELECTED
)
622 uItemState
|= CDIS_SELECTED
;
623 if (item
== infoPtr
->selectedItem
)
624 uItemState
|= CDIS_FOCUS
;
625 if (item
== infoPtr
->hotItem
)
626 uItemState
|= CDIS_HOT
;
628 nmcd
= &nmcdhdr
->nmcd
;
629 nmcd
->dwDrawStage
= dwDrawStage
;
631 nmcd
->rc
= item
->rect
;
632 nmcd
->dwItemSpec
= dwItemSpec
;
633 nmcd
->uItemState
= uItemState
;
634 nmcd
->lItemlParam
= item
->lParam
;
635 nmcdhdr
->iLevel
= item
->iLevel
;
637 TRACE("drawstage:%x hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
638 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
639 nmcd
->uItemState
, nmcd
->lItemlParam
);
641 return TREEVIEW_SendRealNotify(infoPtr
, NM_CUSTOMDRAW
, &nmcdhdr
->nmcd
.hdr
);
645 TREEVIEW_BeginLabelEditNotify(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
650 TREEVIEW_TVItemFromItem(infoPtr
, TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
,
651 &tvdi
.item
, editItem
);
653 ret
= TREEVIEW_SendRealNotify(infoPtr
, TVN_BEGINLABELEDITW
, &tvdi
.hdr
);
655 if (!infoPtr
->bNtfUnicode
)
656 Free(tvdi
.item
.pszText
);
662 TREEVIEW_UpdateDispInfo(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
665 NMTVDISPINFOEXW callback
;
667 TRACE("mask=0x%x, callbackmask=0x%x\n", mask
, item
->callbackMask
);
668 mask
&= item
->callbackMask
;
670 if (mask
== 0) return;
672 /* 'state' always contains valid value, as well as 'lParam'.
673 * All other parameters are uninitialized.
675 callback
.item
.pszText
= item
->pszText
;
676 callback
.item
.cchTextMax
= item
->cchTextMax
;
677 callback
.item
.mask
= mask
;
678 callback
.item
.hItem
= item
;
679 callback
.item
.state
= item
->state
;
680 callback
.item
.lParam
= item
->lParam
;
682 /* If text is changed we need to recalculate textWidth */
683 if (mask
& TVIF_TEXT
)
686 TREEVIEW_SendRealNotify(infoPtr
, TVN_GETDISPINFOW
, &callback
.hdr
);
687 TRACE("resulting code 0x%08x\n", callback
.hdr
.code
);
689 /* It may have changed due to a call to SetItem. */
690 mask
&= item
->callbackMask
;
692 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= item
->pszText
)
694 /* Instead of copying text into our buffer user specified his own */
695 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
698 int len
= MultiByteToWideChar( CP_ACP
, 0,
699 (LPSTR
)callback
.item
.pszText
, -1,
701 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
702 newText
= ReAlloc(item
->pszText
, buflen
);
704 TRACE("returned str %s, len=%d, buflen=%d\n",
705 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
709 item
->pszText
= newText
;
710 MultiByteToWideChar( CP_ACP
, 0,
711 (LPSTR
)callback
.item
.pszText
, -1,
712 item
->pszText
, buflen
/sizeof(WCHAR
));
713 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
715 /* If ReAlloc fails we have nothing to do, but keep original text */
718 int len
= max(lstrlenW(callback
.item
.pszText
) + 1,
720 LPWSTR newText
= ReAlloc(item
->pszText
, len
);
722 TRACE("returned wstr %s, len=%d\n",
723 debugstr_w(callback
.item
.pszText
), len
);
727 item
->pszText
= newText
;
728 strcpyW(item
->pszText
, callback
.item
.pszText
);
729 item
->cchTextMax
= len
;
731 /* If ReAlloc fails we have nothing to do, but keep original text */
734 else if (mask
& TVIF_TEXT
) {
735 /* User put text into our buffer, that is ok unless A string */
736 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
739 int len
= MultiByteToWideChar( CP_ACP
, 0,
740 (LPSTR
)callback
.item
.pszText
, -1,
742 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
743 newText
= Alloc(buflen
);
745 TRACE("same buffer str %s, len=%d, buflen=%d\n",
746 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
750 LPWSTR oldText
= item
->pszText
;
751 item
->pszText
= newText
;
752 MultiByteToWideChar( CP_ACP
, 0,
753 (LPSTR
)callback
.item
.pszText
, -1,
754 item
->pszText
, buflen
/sizeof(WCHAR
));
755 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
761 if (mask
& TVIF_IMAGE
)
762 item
->iImage
= callback
.item
.iImage
;
764 if (mask
& TVIF_SELECTEDIMAGE
)
765 item
->iSelectedImage
= callback
.item
.iSelectedImage
;
767 if (mask
& TVIF_EXPANDEDIMAGE
)
768 item
->iExpandedImage
= callback
.item
.iExpandedImage
;
770 if (mask
& TVIF_CHILDREN
)
771 item
->cChildren
= callback
.item
.cChildren
;
773 if (callback
.item
.mask
& TVIF_STATE
)
775 item
->state
&= ~callback
.item
.stateMask
;
776 item
->state
|= (callback
.item
.state
& callback
.item
.stateMask
);
779 /* These members are now permanently set. */
780 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
781 item
->callbackMask
&= ~callback
.item
.mask
;
784 /***************************************************************************
785 * This function uses cChildren field to decide whether the item has
787 * Note: if this returns TRUE, the child items may not actually exist,
788 * they could be virtual.
790 * Just use item->firstChild to check for physical children.
793 TREEVIEW_HasChildren(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
795 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_CHILDREN
);
797 return item
->cChildren
> 0;
800 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
804 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
806 if (nCommand
!= NF_REQUERY
) return 0;
808 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
809 TRACE("format=%d\n", format
);
811 /* Invalid format returned by NF_QUERY defaults to ANSI*/
812 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
)
815 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
820 /* Item Position ********************************************************/
822 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
824 TREEVIEW_ComputeItemInternalMetrics(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
826 /* has TVS_LINESATROOT and (TVS_HASLINES|TVS_HASBUTTONS) */
827 BOOL lar
= ((infoPtr
->dwStyle
& (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
830 item
->linesOffset
= infoPtr
->uIndent
* (lar
? item
->iLevel
: item
->iLevel
- 1)
832 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
833 item
->imageOffset
= item
->stateOffset
834 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
835 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
839 TREEVIEW_ComputeTextWidth(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
845 /* DRAW's OM docker creates items like this */
846 if (item
->pszText
== NULL
)
858 hdc
= GetDC(infoPtr
->hwnd
);
859 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
862 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
863 item
->textWidth
= sz
.cx
;
867 SelectObject(hdc
, hOldFont
);
873 TREEVIEW_ComputeItemRect(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
875 item
->rect
.top
= infoPtr
->uItemHeight
*
876 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
878 item
->rect
.bottom
= item
->rect
.top
879 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
882 item
->rect
.right
= infoPtr
->clientWidth
;
885 /* We know that only items after start need their order updated. */
887 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
894 start
= infoPtr
->root
->firstChild
;
898 order
= start
->visibleOrder
;
900 for (item
= start
; item
!= NULL
;
901 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
903 if (!ISVISIBLE(item
) && order
> 0)
904 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
905 item
->visibleOrder
= order
;
906 order
+= item
->iIntegral
;
909 infoPtr
->maxVisibleOrder
= order
;
911 for (item
= start
; item
!= NULL
;
912 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
914 TREEVIEW_ComputeItemRect(infoPtr
, item
);
919 /* Update metrics of all items in selected subtree.
920 * root must be expanded
923 TREEVIEW_UpdateSubTree(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
925 TREEVIEW_ITEM
*sibling
;
929 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
932 root
->state
&= ~TVIS_EXPANDED
;
933 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
934 root
->state
|= TVIS_EXPANDED
;
936 hdc
= GetDC(infoPtr
->hwnd
);
937 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
939 for (; root
!= sibling
;
940 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
942 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
944 if (root
->callbackMask
& TVIF_TEXT
)
945 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
947 if (root
->textWidth
== 0)
949 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
950 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
954 SelectObject(hdc
, hOldFont
);
955 ReleaseDC(infoPtr
->hwnd
, hdc
);
958 /* Item Allocation **********************************************************/
960 static TREEVIEW_ITEM
*
961 TREEVIEW_AllocateItem(const TREEVIEW_INFO
*infoPtr
)
963 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
968 /* I_IMAGENONE would make more sense but this is neither what is
969 * documented (MSDN doesn't specify) nor what Windows actually does
970 * (it sets it to zero)... and I can so imagine an application using
971 * inc/dec to toggle the images. */
973 newItem
->iSelectedImage
= 0;
974 newItem
->iExpandedImage
= (WORD
)I_IMAGENONE
;
975 newItem
->infoPtr
= infoPtr
;
977 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
986 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
987 * free item->pszText. */
989 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
991 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
992 if (infoPtr
->selectedItem
== item
)
993 infoPtr
->selectedItem
= NULL
;
994 if (infoPtr
->hotItem
== item
)
995 infoPtr
->hotItem
= NULL
;
996 if (infoPtr
->focusedItem
== item
)
997 infoPtr
->focusedItem
= NULL
;
998 if (infoPtr
->firstVisible
== item
)
999 infoPtr
->firstVisible
= NULL
;
1000 if (infoPtr
->dropItem
== item
)
1001 infoPtr
->dropItem
= NULL
;
1002 if (infoPtr
->insertMarkItem
== item
)
1003 infoPtr
->insertMarkItem
= NULL
;
1008 /* Item Insertion *******************************************************/
1010 /***************************************************************************
1011 * This method inserts newItem before sibling as a child of parent.
1012 * sibling can be NULL, but only if parent has no children.
1015 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1016 TREEVIEW_ITEM
*parent
)
1018 assert(parent
!= NULL
);
1020 if (sibling
!= NULL
)
1022 assert(sibling
->parent
== parent
);
1024 if (sibling
->prevSibling
!= NULL
)
1025 sibling
->prevSibling
->nextSibling
= newItem
;
1027 newItem
->prevSibling
= sibling
->prevSibling
;
1028 sibling
->prevSibling
= newItem
;
1031 newItem
->prevSibling
= NULL
;
1033 newItem
->nextSibling
= sibling
;
1035 if (parent
->firstChild
== sibling
)
1036 parent
->firstChild
= newItem
;
1038 if (parent
->lastChild
== NULL
)
1039 parent
->lastChild
= newItem
;
1042 /***************************************************************************
1043 * This method inserts newItem after sibling as a child of parent.
1044 * sibling can be NULL, but only if parent has no children.
1047 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1048 TREEVIEW_ITEM
*parent
)
1050 assert(parent
!= NULL
);
1052 if (sibling
!= NULL
)
1054 assert(sibling
->parent
== parent
);
1056 if (sibling
->nextSibling
!= NULL
)
1057 sibling
->nextSibling
->prevSibling
= newItem
;
1059 newItem
->nextSibling
= sibling
->nextSibling
;
1060 sibling
->nextSibling
= newItem
;
1063 newItem
->nextSibling
= NULL
;
1065 newItem
->prevSibling
= sibling
;
1067 if (parent
->lastChild
== sibling
)
1068 parent
->lastChild
= newItem
;
1070 if (parent
->firstChild
== NULL
)
1071 parent
->firstChild
= newItem
;
1075 TREEVIEW_DoSetItemT(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
1076 const TVITEMEXW
*tvItem
, BOOL isW
)
1078 UINT callbackClear
= 0;
1079 UINT callbackSet
= 0;
1081 TRACE("item %p\n", item
);
1082 /* Do this first in case it fails. */
1083 if (tvItem
->mask
& TVIF_TEXT
)
1085 item
->textWidth
= 0; /* force width recalculation */
1086 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKW
&& tvItem
->pszText
!= NULL
) /* covers != TEXTCALLBACKA too, and undocumented: pszText of NULL also means TEXTCALLBACK */
1091 len
= lstrlenW(tvItem
->pszText
) + 1;
1093 len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1, NULL
, 0);
1095 newText
= ReAlloc(item
->pszText
, len
* sizeof(WCHAR
));
1097 if (newText
== NULL
) return FALSE
;
1099 callbackClear
|= TVIF_TEXT
;
1101 item
->pszText
= newText
;
1102 item
->cchTextMax
= len
;
1104 lstrcpynW(item
->pszText
, tvItem
->pszText
, len
);
1106 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1,
1107 item
->pszText
, len
);
1109 TRACE("setting text %s, item %p\n", debugstr_w(item
->pszText
), item
);
1113 callbackSet
|= TVIF_TEXT
;
1115 item
->pszText
= ReAlloc(item
->pszText
,
1116 TEXT_CALLBACK_SIZE
* sizeof(WCHAR
));
1117 item
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1118 TRACE("setting callback, item %p\n", item
);
1122 if (tvItem
->mask
& TVIF_CHILDREN
)
1124 item
->cChildren
= tvItem
->cChildren
;
1126 if (item
->cChildren
== I_CHILDRENCALLBACK
)
1127 callbackSet
|= TVIF_CHILDREN
;
1129 callbackClear
|= TVIF_CHILDREN
;
1132 if (tvItem
->mask
& TVIF_IMAGE
)
1134 item
->iImage
= tvItem
->iImage
;
1136 if (item
->iImage
== I_IMAGECALLBACK
)
1137 callbackSet
|= TVIF_IMAGE
;
1139 callbackClear
|= TVIF_IMAGE
;
1142 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1144 item
->iSelectedImage
= tvItem
->iSelectedImage
;
1146 if (item
->iSelectedImage
== I_IMAGECALLBACK
)
1147 callbackSet
|= TVIF_SELECTEDIMAGE
;
1149 callbackClear
|= TVIF_SELECTEDIMAGE
;
1152 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
1154 item
->iExpandedImage
= tvItem
->iExpandedImage
;
1156 if (item
->iExpandedImage
== I_IMAGECALLBACK
)
1157 callbackSet
|= TVIF_EXPANDEDIMAGE
;
1159 callbackClear
|= TVIF_EXPANDEDIMAGE
;
1162 if (tvItem
->mask
& TVIF_PARAM
)
1163 item
->lParam
= tvItem
->lParam
;
1165 /* If the application sets TVIF_INTEGRAL without
1166 * supplying a TVITEMEX structure, it's toast. */
1167 if (tvItem
->mask
& TVIF_INTEGRAL
)
1168 item
->iIntegral
= tvItem
->iIntegral
;
1170 if (tvItem
->mask
& TVIF_STATE
)
1172 TRACE("prevstate,state,mask:%x,%x,%x\n", item
->state
, tvItem
->state
,
1174 item
->state
&= ~tvItem
->stateMask
;
1175 item
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1178 if (tvItem
->mask
& TVIF_STATEEX
)
1180 FIXME("New extended state: %x\n", tvItem
->uStateEx
);
1183 item
->callbackMask
|= callbackSet
;
1184 item
->callbackMask
&= ~callbackClear
;
1189 /* Note that the new item is pre-zeroed. */
1191 TREEVIEW_InsertItemT(TREEVIEW_INFO
*infoPtr
, const TVINSERTSTRUCTW
*ptdi
, BOOL isW
)
1193 const TVITEMEXW
*tvItem
= &ptdi
->u
.itemex
;
1194 HTREEITEM insertAfter
;
1195 TREEVIEW_ITEM
*newItem
, *parentItem
;
1196 BOOL bTextUpdated
= FALSE
;
1198 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1200 parentItem
= infoPtr
->root
;
1204 parentItem
= ptdi
->hParent
;
1206 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1208 WARN("invalid parent %p\n", parentItem
);
1213 insertAfter
= ptdi
->hInsertAfter
;
1215 /* Validate this now for convenience. */
1216 switch ((DWORD_PTR
)insertAfter
)
1218 case (DWORD_PTR
)TVI_FIRST
:
1219 case (DWORD_PTR
)TVI_LAST
:
1220 case (DWORD_PTR
)TVI_SORT
:
1224 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1225 insertAfter
->parent
!= parentItem
)
1227 WARN("invalid insert after %p\n", insertAfter
);
1228 insertAfter
= TVI_LAST
;
1232 TRACE("parent %p position %p: %s\n", parentItem
, insertAfter
,
1233 (tvItem
->mask
& TVIF_TEXT
)
1234 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKW
) ? "<callback>"
1235 : (isW
? debugstr_w(tvItem
->pszText
) : debugstr_a((LPSTR
)tvItem
->pszText
)))
1238 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1239 if (newItem
== NULL
)
1242 newItem
->parent
= parentItem
;
1243 newItem
->iIntegral
= 1;
1244 newItem
->visibleOrder
= -1;
1246 if (!TREEVIEW_DoSetItemT(infoPtr
, newItem
, tvItem
, isW
))
1249 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1251 infoPtr
->uNumItems
++;
1253 switch ((DWORD_PTR
)insertAfter
)
1255 case (DWORD_PTR
)TVI_FIRST
:
1257 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1258 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1259 if (infoPtr
->firstVisible
== originalFirst
)
1260 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1264 case (DWORD_PTR
)TVI_LAST
:
1265 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1268 /* hInsertAfter names a specific item we want to insert after */
1270 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1273 case (DWORD_PTR
)TVI_SORT
:
1275 TREEVIEW_ITEM
*aChild
;
1276 TREEVIEW_ITEM
*previousChild
= NULL
;
1277 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1278 BOOL bItemInserted
= FALSE
;
1280 aChild
= parentItem
->firstChild
;
1282 bTextUpdated
= TRUE
;
1283 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1285 /* Iterate the parent children to see where we fit in */
1286 while (aChild
!= NULL
)
1290 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1291 comp
= lstrcmpW(newItem
->pszText
, aChild
->pszText
);
1293 if (comp
< 0) /* we are smaller than the current one */
1295 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1296 if (infoPtr
->firstVisible
== originalFirst
&&
1297 aChild
== originalFirst
)
1298 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1299 bItemInserted
= TRUE
;
1302 else if (comp
> 0) /* we are bigger than the current one */
1304 previousChild
= aChild
;
1306 /* This will help us to exit if there is no more sibling */
1307 aChild
= (aChild
->nextSibling
== 0)
1309 : aChild
->nextSibling
;
1311 /* Look at the next item */
1317 * An item with this name is already existing, therefore,
1318 * we add after the one we found
1320 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1321 bItemInserted
= TRUE
;
1327 * we reach the end of the child list and the item has not
1328 * yet been inserted, therefore, insert it after the last child.
1330 if ((!bItemInserted
) && (aChild
== NULL
))
1331 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1338 TRACE("new item %p; parent %p, mask %x\n", newItem
,
1339 newItem
->parent
, tvItem
->mask
);
1341 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1343 if (newItem
->parent
->cChildren
== 0)
1344 newItem
->parent
->cChildren
= 1;
1346 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1348 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1349 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1352 if (infoPtr
->firstVisible
== NULL
)
1353 infoPtr
->firstVisible
= newItem
;
1355 TREEVIEW_VerifyTree(infoPtr
);
1357 if (!infoPtr
->bRedraw
) return (LRESULT
)newItem
;
1359 if (parentItem
== infoPtr
->root
||
1360 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1362 TREEVIEW_ITEM
*item
;
1363 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1365 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1366 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1369 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1371 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1372 TREEVIEW_UpdateScrollBars(infoPtr
);
1374 * if the item was inserted in a visible part of the tree,
1375 * invalidate it, as well as those after it
1377 for (item
= newItem
;
1379 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1380 TREEVIEW_Invalidate(infoPtr
, item
);
1384 /* refresh treeview if newItem is the first item inserted under parentItem */
1385 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1387 /* parent got '+' - update it */
1388 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1392 return (LRESULT
)newItem
;
1395 /* Item Deletion ************************************************************/
1397 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
1400 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*parentItem
)
1402 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1404 while (kill
!= NULL
)
1406 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1408 TREEVIEW_RemoveItem(infoPtr
, kill
);
1413 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1414 assert(parentItem
->firstChild
== NULL
);
1415 assert(parentItem
->lastChild
== NULL
);
1419 TREEVIEW_UnlinkItem(const TREEVIEW_ITEM
*item
)
1421 TREEVIEW_ITEM
*parentItem
= item
->parent
;
1423 assert(item
!= NULL
);
1424 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1426 if (parentItem
->firstChild
== item
)
1427 parentItem
->firstChild
= item
->nextSibling
;
1429 if (parentItem
->lastChild
== item
)
1430 parentItem
->lastChild
= item
->prevSibling
;
1432 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1433 && parentItem
->cChildren
> 0)
1434 parentItem
->cChildren
= 0;
1436 if (item
->prevSibling
)
1437 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1439 if (item
->nextSibling
)
1440 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1444 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1446 TRACE("%p, (%s)\n", item
, TREEVIEW_ItemName(item
));
1448 if (item
->firstChild
)
1449 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
1451 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1452 TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
1454 TREEVIEW_UnlinkItem(item
);
1456 infoPtr
->uNumItems
--;
1458 if (item
->pszText
!= LPSTR_TEXTCALLBACKW
)
1459 Free(item
->pszText
);
1461 TREEVIEW_FreeItem(infoPtr
, item
);
1465 /* Empty out the tree. */
1467 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1469 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1471 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1475 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
)
1477 TREEVIEW_ITEM
*newSelection
= NULL
;
1478 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1479 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1480 BOOL visible
= FALSE
;
1482 if (item
== TVI_ROOT
|| !item
)
1484 TRACE("TVI_ROOT\n");
1485 parent
= infoPtr
->root
;
1486 newSelection
= NULL
;
1488 TREEVIEW_RemoveTree(infoPtr
);
1492 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1495 TRACE("%p (%s)\n", item
, TREEVIEW_ItemName(item
));
1496 parent
= item
->parent
;
1498 if (ISVISIBLE(item
))
1500 prev
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
1504 if (infoPtr
->selectedItem
!= NULL
1505 && (item
== infoPtr
->selectedItem
1506 || TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
)))
1508 if (item
->nextSibling
)
1509 newSelection
= item
->nextSibling
;
1510 else if (item
->parent
!= infoPtr
->root
)
1511 newSelection
= item
->parent
;
1513 newSelection
= item
->prevSibling
;
1514 TRACE("newSelection = %p\n", newSelection
);
1517 if (infoPtr
->firstVisible
== item
)
1519 if (item
->nextSibling
)
1520 newFirstVisible
= item
->nextSibling
;
1521 else if (item
->prevSibling
)
1522 newFirstVisible
= item
->prevSibling
;
1523 else if (item
->parent
!= infoPtr
->root
)
1524 newFirstVisible
= item
->parent
;
1525 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1528 newFirstVisible
= infoPtr
->firstVisible
;
1530 TREEVIEW_RemoveItem(infoPtr
, item
);
1533 /* Don't change if somebody else already has (infoPtr->selectedItem is cleared by FreeItem). */
1534 if (!infoPtr
->selectedItem
&& newSelection
)
1536 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1537 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1540 /* Validate insertMark dropItem.
1541 * hotItem ??? - used for comparison only.
1543 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1544 infoPtr
->insertMarkItem
= 0;
1546 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1547 infoPtr
->dropItem
= 0;
1549 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1550 newFirstVisible
= infoPtr
->root
->firstChild
;
1552 TREEVIEW_VerifyTree(infoPtr
);
1554 if (!infoPtr
->bRedraw
) return TRUE
;
1558 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1559 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1560 TREEVIEW_UpdateScrollBars(infoPtr
);
1561 TREEVIEW_Invalidate(infoPtr
, NULL
);
1563 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1565 /* parent lost '+/-' - update it */
1566 TREEVIEW_Invalidate(infoPtr
, parent
);
1573 /* Get/Set Messages *********************************************************/
1575 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
)
1577 infoPtr
->bRedraw
= wParam
!= 0;
1579 if (infoPtr
->bRedraw
)
1581 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1582 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1583 TREEVIEW_UpdateScrollBars(infoPtr
);
1584 TREEVIEW_Invalidate(infoPtr
, NULL
);
1590 TREEVIEW_GetIndent(const TREEVIEW_INFO
*infoPtr
)
1593 return infoPtr
->uIndent
;
1597 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1601 if (newIndent
< MINIMUM_INDENT
)
1602 newIndent
= MINIMUM_INDENT
;
1604 if (infoPtr
->uIndent
!= newIndent
)
1606 infoPtr
->uIndent
= newIndent
;
1607 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1608 TREEVIEW_UpdateScrollBars(infoPtr
);
1609 TREEVIEW_Invalidate(infoPtr
, NULL
);
1617 TREEVIEW_GetToolTips(const TREEVIEW_INFO
*infoPtr
)
1620 return (LRESULT
)infoPtr
->hwndToolTip
;
1624 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1629 prevToolTip
= infoPtr
->hwndToolTip
;
1630 infoPtr
->hwndToolTip
= hwndTT
;
1632 return (LRESULT
)prevToolTip
;
1636 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO
*infoPtr
, BOOL fUnicode
)
1638 BOOL rc
= infoPtr
->bNtfUnicode
;
1639 infoPtr
->bNtfUnicode
= fUnicode
;
1644 TREEVIEW_GetUnicodeFormat(const TREEVIEW_INFO
*infoPtr
)
1646 return infoPtr
->bNtfUnicode
;
1650 TREEVIEW_GetScrollTime(const TREEVIEW_INFO
*infoPtr
)
1652 return infoPtr
->uScrollTime
;
1656 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1658 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1660 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1662 return uOldScrollTime
;
1667 TREEVIEW_GetImageList(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1674 return (LRESULT
)infoPtr
->himlNormal
;
1677 return (LRESULT
)infoPtr
->himlState
;
1684 #define TVHEIGHT_MIN 16
1685 #define TVHEIGHT_FONT_ADJUST 3 /* 2 for focus border + 1 for margin some apps assume */
1687 /* Compute the natural height for items. */
1689 TREEVIEW_NaturalHeight(const TREEVIEW_INFO
*infoPtr
)
1693 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1696 /* Height is the maximum of:
1697 * 16 (a hack because our fonts are tiny), and
1698 * The text height + border & margin, and
1699 * The size of the normal image list
1701 GetTextMetricsW(hdc
, &tm
);
1702 SelectObject(hdc
, hOldFont
);
1705 height
= TVHEIGHT_MIN
;
1706 if (height
< tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
)
1707 height
= tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
;
1708 if (height
< infoPtr
->normalImageHeight
)
1709 height
= infoPtr
->normalImageHeight
;
1711 /* Round down, unless we support odd ("non even") heights. */
1712 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1719 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, UINT type
, HIMAGELIST himlNew
)
1721 HIMAGELIST himlOld
= 0;
1722 int oldWidth
= infoPtr
->normalImageWidth
;
1723 int oldHeight
= infoPtr
->normalImageHeight
;
1725 TRACE("%u,%p\n", type
, himlNew
);
1730 himlOld
= infoPtr
->himlNormal
;
1731 infoPtr
->himlNormal
= himlNew
;
1734 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1735 &infoPtr
->normalImageHeight
);
1738 infoPtr
->normalImageWidth
= 0;
1739 infoPtr
->normalImageHeight
= 0;
1745 himlOld
= infoPtr
->himlState
;
1746 infoPtr
->himlState
= himlNew
;
1749 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1750 &infoPtr
->stateImageHeight
);
1753 infoPtr
->stateImageWidth
= 0;
1754 infoPtr
->stateImageHeight
= 0;
1760 ERR("unknown imagelist type %u\n", type
);
1763 if (oldWidth
!= infoPtr
->normalImageWidth
||
1764 oldHeight
!= infoPtr
->normalImageHeight
)
1766 BOOL bRecalcVisible
= FALSE
;
1768 if (oldHeight
!= infoPtr
->normalImageHeight
&&
1769 !infoPtr
->bHeightSet
)
1771 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1772 bRecalcVisible
= TRUE
;
1775 if (infoPtr
->normalImageWidth
> MINIMUM_INDENT
&&
1776 infoPtr
->normalImageWidth
!= infoPtr
->uIndent
)
1778 infoPtr
->uIndent
= infoPtr
->normalImageWidth
;
1779 bRecalcVisible
= TRUE
;
1783 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1785 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1786 TREEVIEW_UpdateScrollBars(infoPtr
);
1789 TREEVIEW_Invalidate(infoPtr
, NULL
);
1791 return (LRESULT
)himlOld
;
1795 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1797 INT prevHeight
= infoPtr
->uItemHeight
;
1799 TRACE("new=%d, old=%d\n", newHeight
, prevHeight
);
1800 if (newHeight
== -1)
1802 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1803 infoPtr
->bHeightSet
= FALSE
;
1807 if (newHeight
== 0) newHeight
= 1;
1808 infoPtr
->uItemHeight
= newHeight
;
1809 infoPtr
->bHeightSet
= TRUE
;
1812 /* Round down, unless we support odd ("non even") heights. */
1813 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
) && infoPtr
->uItemHeight
!= 1)
1815 infoPtr
->uItemHeight
&= ~1;
1816 TRACE("after rounding=%d\n", infoPtr
->uItemHeight
);
1819 if (infoPtr
->uItemHeight
!= prevHeight
)
1821 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1822 TREEVIEW_UpdateScrollBars(infoPtr
);
1823 TREEVIEW_Invalidate(infoPtr
, NULL
);
1830 TREEVIEW_GetItemHeight(const TREEVIEW_INFO
*infoPtr
)
1833 return infoPtr
->uItemHeight
;
1838 TREEVIEW_GetFont(const TREEVIEW_INFO
*infoPtr
)
1840 TRACE("%p\n", infoPtr
->hFont
);
1841 return (LRESULT
)infoPtr
->hFont
;
1846 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1850 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1856 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1858 UINT uHeight
= infoPtr
->uItemHeight
;
1860 TRACE("%p %i\n", hFont
, bRedraw
);
1862 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
1864 DeleteObject(infoPtr
->hBoldFont
);
1865 DeleteObject(infoPtr
->hUnderlineFont
);
1866 DeleteObject(infoPtr
->hBoldUnderlineFont
);
1867 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1868 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
1869 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
1871 if (!infoPtr
->bHeightSet
)
1872 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1874 if (uHeight
!= infoPtr
->uItemHeight
)
1875 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1877 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1879 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1880 TREEVIEW_UpdateScrollBars(infoPtr
);
1883 TREEVIEW_Invalidate(infoPtr
, NULL
);
1890 TREEVIEW_GetLineColor(const TREEVIEW_INFO
*infoPtr
)
1893 return (LRESULT
)infoPtr
->clrLine
;
1897 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1899 COLORREF prevColor
= infoPtr
->clrLine
;
1902 infoPtr
->clrLine
= color
;
1903 return (LRESULT
)prevColor
;
1908 TREEVIEW_GetTextColor(const TREEVIEW_INFO
*infoPtr
)
1911 return (LRESULT
)infoPtr
->clrText
;
1915 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1917 COLORREF prevColor
= infoPtr
->clrText
;
1920 infoPtr
->clrText
= color
;
1922 if (infoPtr
->clrText
!= prevColor
)
1923 TREEVIEW_Invalidate(infoPtr
, NULL
);
1925 return (LRESULT
)prevColor
;
1930 TREEVIEW_GetBkColor(const TREEVIEW_INFO
*infoPtr
)
1933 return (LRESULT
)infoPtr
->clrBk
;
1937 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1939 COLORREF prevColor
= infoPtr
->clrBk
;
1942 infoPtr
->clrBk
= newColor
;
1944 if (newColor
!= prevColor
)
1945 TREEVIEW_Invalidate(infoPtr
, NULL
);
1947 return (LRESULT
)prevColor
;
1952 TREEVIEW_GetInsertMarkColor(const TREEVIEW_INFO
*infoPtr
)
1955 return (LRESULT
)infoPtr
->clrInsertMark
;
1959 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1961 COLORREF prevColor
= infoPtr
->clrInsertMark
;
1963 TRACE("%x\n", color
);
1964 infoPtr
->clrInsertMark
= color
;
1966 return (LRESULT
)prevColor
;
1971 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
1973 TRACE("%d %p\n", wParam
, item
);
1975 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1978 infoPtr
->insertBeforeorAfter
= wParam
;
1979 infoPtr
->insertMarkItem
= item
;
1981 TREEVIEW_Invalidate(infoPtr
, NULL
);
1987 /************************************************************************
1988 * Some serious braindamage here. lParam is a pointer to both the
1989 * input HTREEITEM and the output RECT.
1992 TREEVIEW_GetItemRect(const TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
1994 TREEVIEW_ITEM
*item
;
1995 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
2003 if (!TREEVIEW_ValidItem(infoPtr
, item
) || !ISVISIBLE(item
))
2007 * If wParam is TRUE return the text size otherwise return
2008 * the whole item size
2012 /* Windows does not send TVN_GETDISPINFO here. */
2014 lpRect
->top
= item
->rect
.top
;
2015 lpRect
->bottom
= item
->rect
.bottom
;
2017 lpRect
->left
= item
->textOffset
;
2018 if (!item
->textWidth
)
2019 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2021 lpRect
->right
= item
->textOffset
+ item
->textWidth
+ 4;
2025 *lpRect
= item
->rect
;
2028 TRACE("%s [%s]\n", fTextRect
? "text" : "item", wine_dbgstr_rect(lpRect
));
2033 static inline LRESULT
2034 TREEVIEW_GetVisibleCount(const TREEVIEW_INFO
*infoPtr
)
2036 /* Surprise! This does not take integral height into account. */
2037 TRACE("client=%d, item=%d\n", infoPtr
->clientHeight
, infoPtr
->uItemHeight
);
2038 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2043 TREEVIEW_GetItemT(const TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2045 TREEVIEW_ITEM
*item
= tvItem
->hItem
;
2047 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2049 if (!item
) return FALSE
;
2051 TRACE("got item from different tree %p, called from %p\n", item
->infoPtr
, infoPtr
);
2052 infoPtr
= item
->infoPtr
;
2053 if (!TREEVIEW_ValidItem(infoPtr
, item
)) return FALSE
;
2056 TREEVIEW_UpdateDispInfo(infoPtr
, item
, tvItem
->mask
);
2058 if (tvItem
->mask
& TVIF_CHILDREN
)
2060 if (item
->cChildren
==I_CHILDRENCALLBACK
)
2061 FIXME("I_CHILDRENCALLBACK not supported\n");
2062 tvItem
->cChildren
= item
->cChildren
;
2065 if (tvItem
->mask
& TVIF_HANDLE
)
2066 tvItem
->hItem
= item
;
2068 if (tvItem
->mask
& TVIF_IMAGE
)
2069 tvItem
->iImage
= item
->iImage
;
2071 if (tvItem
->mask
& TVIF_INTEGRAL
)
2072 tvItem
->iIntegral
= item
->iIntegral
;
2074 /* undocumented: (mask & TVIF_PARAM) ignored and lParam is always set */
2075 tvItem
->lParam
= item
->lParam
;
2077 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2078 tvItem
->iSelectedImage
= item
->iSelectedImage
;
2080 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
2081 tvItem
->iExpandedImage
= item
->iExpandedImage
;
2083 /* undocumented: stateMask and (state & TVIF_STATE) ignored, so state is always set */
2084 tvItem
->state
= item
->state
;
2086 if (tvItem
->mask
& TVIF_TEXT
)
2088 if (item
->pszText
== NULL
)
2090 if (tvItem
->cchTextMax
> 0)
2091 tvItem
->pszText
[0] = '\0';
2095 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2097 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2098 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2102 lstrcpynW(tvItem
->pszText
, item
->pszText
, tvItem
->cchTextMax
);
2107 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2109 tvItem
->pszText
= (LPWSTR
)LPSTR_TEXTCALLBACKA
;
2110 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2114 WideCharToMultiByte(CP_ACP
, 0, item
->pszText
, -1,
2115 (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, NULL
, NULL
);
2120 if (tvItem
->mask
& TVIF_STATEEX
)
2122 FIXME("Extended item state not supported, returning 0.\n");
2123 tvItem
->uStateEx
= 0;
2126 TRACE("item <%p>, txt %p, img %d, mask %x\n",
2127 item
, tvItem
->pszText
, tvItem
->iImage
, tvItem
->mask
);
2132 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2133 * which is wrong. */
2135 TREEVIEW_SetItemT(TREEVIEW_INFO
*infoPtr
, const TVITEMEXW
*tvItem
, BOOL isW
)
2137 TREEVIEW_ITEM
*item
;
2138 TREEVIEW_ITEM originalItem
;
2140 item
= tvItem
->hItem
;
2142 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr
, item
),
2145 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2148 /* store the original item values */
2149 originalItem
= *item
;
2151 if (!TREEVIEW_DoSetItemT(infoPtr
, item
, tvItem
, isW
))
2154 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2155 if ((tvItem
->mask
& TVIF_TEXT
2156 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2159 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_TEXT
);
2160 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2163 if (tvItem
->mask
!= 0 && ISVISIBLE(item
))
2165 /* The refresh updates everything, but we can't wait until then. */
2166 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
2168 /* if any of the item's values changed and it's not a callback, redraw the item */
2169 if (item_changed(&originalItem
, item
, tvItem
))
2171 if (tvItem
->mask
& TVIF_INTEGRAL
)
2173 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
2174 TREEVIEW_UpdateScrollBars(infoPtr
);
2176 TREEVIEW_Invalidate(infoPtr
, NULL
);
2180 TREEVIEW_UpdateScrollBars(infoPtr
);
2181 TREEVIEW_Invalidate(infoPtr
, item
);
2190 TREEVIEW_GetItemState(const TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, UINT mask
)
2194 if (!item
|| !TREEVIEW_ValidItem(infoPtr
, item
))
2197 return (item
->state
& mask
);
2201 TREEVIEW_GetNextItem(const TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM item
)
2203 TREEVIEW_ITEM
*retval
;
2207 /* handle all the global data here */
2210 case TVGN_CHILD
: /* Special case: child of 0 is root */
2215 retval
= infoPtr
->root
->firstChild
;
2219 retval
= infoPtr
->selectedItem
;
2222 case TVGN_FIRSTVISIBLE
:
2223 retval
= infoPtr
->firstVisible
;
2226 case TVGN_DROPHILITE
:
2227 retval
= infoPtr
->dropItem
;
2230 case TVGN_LASTVISIBLE
:
2231 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2237 TRACE("flags:%x, returns %p\n", which
, retval
);
2238 return (LRESULT
)retval
;
2241 if (item
== TVI_ROOT
) item
= infoPtr
->root
;
2243 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2249 retval
= item
->nextSibling
;
2252 retval
= item
->prevSibling
;
2255 retval
= (item
->parent
!= infoPtr
->root
) ? item
->parent
: NULL
;
2258 retval
= item
->firstChild
;
2260 case TVGN_NEXTVISIBLE
:
2261 retval
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2263 case TVGN_PREVIOUSVISIBLE
:
2264 retval
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
2267 TRACE("Unknown msg %x,item %p\n", which
, item
);
2271 TRACE("flags:%x, item %p;returns %p\n", which
, item
, retval
);
2272 return (LRESULT
)retval
;
2277 TREEVIEW_GetCount(const TREEVIEW_INFO
*infoPtr
)
2279 TRACE(" %d\n", infoPtr
->uNumItems
);
2280 return (LRESULT
)infoPtr
->uNumItems
;
2284 TREEVIEW_ToggleItemState(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2286 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2288 static const unsigned int state_table
[] = { 0, 2, 1 };
2292 state
= STATEIMAGEINDEX(item
->state
);
2293 TRACE("state:%x\n", state
);
2294 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2297 state
= state_table
[state
];
2299 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2301 TRACE("state:%x\n", state
);
2302 TREEVIEW_Invalidate(infoPtr
, item
);
2307 /* Painting *************************************************************/
2309 /* Draw the lines and expand button for an item. Also draws one section
2310 * of the line from item's parent to item's parent's next sibling. */
2312 TREEVIEW_DrawItemLines(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const TREEVIEW_ITEM
*item
)
2314 LONG centerx
, centery
;
2315 BOOL lar
= ((infoPtr
->dwStyle
2316 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2319 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2321 if (!lar
&& item
->iLevel
== 0)
2324 hbr
= CreateSolidBrush(clrBk
);
2325 hbrOld
= SelectObject(hdc
, hbr
);
2327 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2328 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2330 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2332 HPEN hOldPen
, hNewPen
;
2336 /* Get a dotted grey pen */
2337 lb
.lbStyle
= BS_SOLID
;
2338 lb
.lbColor
= GETLINECOLOR(infoPtr
->clrLine
);
2339 hNewPen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, NULL
);
2340 hOldPen
= SelectObject(hdc
, hNewPen
);
2342 /* Make sure the center is on a dot (using +2 instead
2343 * of +1 gives us pixel-by-pixel compat with native) */
2344 centery
= (centery
+ 2) & ~1;
2346 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2347 LineTo(hdc
, centerx
- 1, centery
);
2349 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2351 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2352 LineTo(hdc
, centerx
, centery
);
2355 if (item
->nextSibling
)
2357 MoveToEx(hdc
, centerx
, centery
, NULL
);
2358 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2361 /* Draw the line from our parent to its next sibling. */
2362 parent
= item
->parent
;
2363 while (parent
!= infoPtr
->root
)
2365 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2367 if (parent
->nextSibling
2368 /* skip top-levels unless TVS_LINESATROOT */
2369 && parent
->stateOffset
> parent
->linesOffset
)
2371 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2372 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2375 parent
= parent
->parent
;
2378 SelectObject(hdc
, hOldPen
);
2379 DeleteObject(hNewPen
);
2383 * Display the (+/-) signs
2386 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2388 if (item
->cChildren
)
2390 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
2393 RECT glyphRect
= item
->rect
;
2394 glyphRect
.left
= item
->linesOffset
;
2395 glyphRect
.right
= item
->stateOffset
;
2396 DrawThemeBackground (theme
, hdc
, TVP_GLYPH
,
2397 (item
->state
& TVIS_EXPANDED
) ? GLPS_OPENED
: GLPS_CLOSED
,
2402 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2403 LONG width
= item
->stateOffset
- item
->linesOffset
;
2404 LONG rectsize
= min(height
, width
) / 4;
2405 /* plussize = ceil(rectsize * 3/4) */
2406 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2408 HPEN new_pen
= CreatePen(PS_SOLID
, 0, GETLINECOLOR(infoPtr
->clrLine
));
2409 HPEN old_pen
= SelectObject(hdc
, new_pen
);
2411 Rectangle(hdc
, centerx
- rectsize
- 1, centery
- rectsize
- 1,
2412 centerx
+ rectsize
+ 2, centery
+ rectsize
+ 2);
2414 SelectObject(hdc
, old_pen
);
2415 DeleteObject(new_pen
);
2417 /* draw +/- signs with current text color */
2418 new_pen
= CreatePen(PS_SOLID
, 0, GETTXTCOLOR(infoPtr
->clrText
));
2419 old_pen
= SelectObject(hdc
, new_pen
);
2421 if (height
< 18 || width
< 18)
2423 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2424 LineTo(hdc
, centerx
+ plussize
, centery
);
2426 if (!(item
->state
& TVIS_EXPANDED
) ||
2427 (item
->state
& TVIS_EXPANDPARTIAL
))
2429 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2430 LineTo(hdc
, centerx
, centery
+ plussize
);
2435 Rectangle(hdc
, centerx
- plussize
+ 1, centery
- 1,
2436 centerx
+ plussize
, centery
+ 2);
2438 if (!(item
->state
& TVIS_EXPANDED
) ||
2439 (item
->state
& TVIS_EXPANDPARTIAL
))
2441 Rectangle(hdc
, centerx
- 1, centery
- plussize
+ 1,
2442 centerx
+ 2, centery
+ plussize
);
2443 SetPixel(hdc
, centerx
- 1, centery
, clrBk
);
2444 SetPixel(hdc
, centerx
+ 1, centery
, clrBk
);
2448 SelectObject(hdc
, old_pen
);
2449 DeleteObject(new_pen
);
2453 SelectObject(hdc
, hbrOld
);
2458 TREEVIEW_DrawItem(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*item
)
2462 COLORREF oldTextColor
, oldTextBkColor
;
2464 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2465 NMTVCUSTOMDRAW nmcdhdr
;
2467 TREEVIEW_UpdateDispInfo(infoPtr
, item
, CALLBACK_MASK_ALL
);
2469 /* - If item is drop target or it is selected and window is in focus -
2470 * use blue background (COLOR_HIGHLIGHT).
2471 * - If item is selected, window is not in focus, but it has style
2472 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2473 * - Otherwise - use background color
2475 if ((item
->state
& TVIS_DROPHILITED
) || ((item
== infoPtr
->focusedItem
) && !(item
->state
& TVIS_SELECTED
)) ||
2476 ((item
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
|| item
== infoPtr
->focusedItem
) &&
2477 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2479 if ((item
->state
& TVIS_DROPHILITED
) || inFocus
)
2481 nmcdhdr
.clrTextBk
= comctl32_color
.clrHighlight
;
2482 nmcdhdr
.clrText
= comctl32_color
.clrHighlightText
;
2486 nmcdhdr
.clrTextBk
= comctl32_color
.clrBtnFace
;
2487 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2492 nmcdhdr
.clrTextBk
= GETBKCOLOR(infoPtr
->clrBk
);
2493 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
2494 nmcdhdr
.clrText
= comctl32_color
.clrHighlight
;
2496 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2499 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
2501 /* The custom draw handler can query the text rectangle,
2503 /* should already be known, set to 0 when changed */
2504 if (!item
->textWidth
)
2505 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2509 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2511 cditem
= TREEVIEW_SendCustomDrawItemNotify
2512 (infoPtr
, hdc
, item
, CDDS_ITEMPREPAINT
, &nmcdhdr
);
2513 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2515 if (cditem
& CDRF_SKIPDEFAULT
)
2517 SelectObject(hdc
, hOldFont
);
2522 if (cditem
& CDRF_NEWFONT
)
2523 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2525 TREEVIEW_DrawItemLines(infoPtr
, hdc
, item
);
2527 /* Set colors. Custom draw handler can change these so we do this after it. */
2528 oldTextColor
= SetTextColor(hdc
, nmcdhdr
.clrText
);
2529 oldTextBkColor
= SetBkColor(hdc
, nmcdhdr
.clrTextBk
);
2531 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2534 * Display the images associated with this item
2539 /* State images are displayed to the left of the Normal image
2540 * image number is in state; zero should be `display no image'.
2542 imageIndex
= STATEIMAGEINDEX(item
->state
);
2544 if (infoPtr
->himlState
&& imageIndex
)
2546 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2548 centery
- infoPtr
->stateImageHeight
/ 2,
2552 /* Now, draw the normal image; can be either selected,
2553 * non-selected or expanded image.
2556 if ((item
->state
& TVIS_SELECTED
) && (item
->iSelectedImage
>= 0))
2558 /* The item is currently selected */
2559 imageIndex
= item
->iSelectedImage
;
2561 else if ((item
->state
& TVIS_EXPANDED
) && (item
->iExpandedImage
!= (WORD
)I_IMAGENONE
))
2563 /* The item is currently not selected but expanded */
2564 imageIndex
= item
->iExpandedImage
;
2568 /* The item is not selected and not expanded */
2569 imageIndex
= item
->iImage
;
2572 if (infoPtr
->himlNormal
)
2574 UINT style
= item
->state
& TVIS_CUT
? ILD_SELECTED
: ILD_NORMAL
;
2576 style
|= item
->state
& TVIS_OVERLAYMASK
;
2578 ImageList_DrawEx(infoPtr
->himlNormal
, imageIndex
, hdc
,
2579 item
->imageOffset
, centery
- infoPtr
->normalImageHeight
/ 2,
2580 0, 0, infoPtr
->clrBk
, item
->state
& TVIS_CUT
? GETBKCOLOR(infoPtr
->clrBk
) : CLR_DEFAULT
,
2587 * Display the text associated with this item
2590 /* Don't paint item's text if it's being edited */
2591 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= item
))
2599 rcText
.top
= item
->rect
.top
;
2600 rcText
.bottom
= item
->rect
.bottom
;
2601 rcText
.left
= item
->textOffset
;
2602 rcText
.right
= rcText
.left
+ item
->textWidth
+ 4;
2604 TRACE("drawing text %s at (%s)\n",
2605 debugstr_w(item
->pszText
), wine_dbgstr_rect(&rcText
));
2608 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
2610 align
= SetTextAlign(hdc
, TA_LEFT
| TA_TOP
);
2611 ExtTextOutW(hdc
, rcText
.left
+ 2, (rcText
.top
+ rcText
.bottom
- sz
.cy
) / 2,
2612 ETO_CLIPPED
| ETO_OPAQUE
,
2615 lstrlenW(item
->pszText
),
2617 SetTextAlign(hdc
, align
);
2619 /* Draw focus box around the selected item */
2620 if ((item
== infoPtr
->selectedItem
) && inFocus
)
2622 DrawFocusRect(hdc
,&rcText
);
2627 /* Draw insertion mark if necessary */
2629 if (infoPtr
->insertMarkItem
)
2630 TRACE("item:%d,mark:%p\n",
2631 TREEVIEW_GetItemIndex(infoPtr
, item
),
2632 infoPtr
->insertMarkItem
);
2634 if (item
== infoPtr
->insertMarkItem
)
2636 HPEN hNewPen
, hOldPen
;
2640 hNewPen
= CreatePen(PS_SOLID
, 2, GETINSCOLOR(infoPtr
->clrInsertMark
));
2641 hOldPen
= SelectObject(hdc
, hNewPen
);
2643 if (infoPtr
->insertBeforeorAfter
)
2644 offset
= item
->rect
.bottom
- 1;
2646 offset
= item
->rect
.top
+ 1;
2648 left
= item
->textOffset
- 2;
2649 right
= item
->textOffset
+ item
->textWidth
+ 2;
2651 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2652 LineTo(hdc
, left
, offset
+ 4);
2654 MoveToEx(hdc
, left
, offset
, NULL
);
2655 LineTo(hdc
, right
+ 1, offset
);
2657 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2658 LineTo(hdc
, right
, offset
- 4);
2660 SelectObject(hdc
, hOldPen
);
2661 DeleteObject(hNewPen
);
2664 /* Restore the hdc state */
2665 SetTextColor(hdc
, oldTextColor
);
2666 SetBkColor(hdc
, oldTextBkColor
);
2667 SelectObject(hdc
, hOldFont
);
2669 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2671 cditem
= TREEVIEW_SendCustomDrawItemNotify
2672 (infoPtr
, hdc
, item
, CDDS_ITEMPOSTPAINT
, &nmcdhdr
);
2673 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2677 /* Computes treeHeight and treeWidth and updates the scroll bars.
2680 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2682 TREEVIEW_ITEM
*item
;
2683 HWND hwnd
= infoPtr
->hwnd
;
2687 LONG scrollX
= infoPtr
->scrollX
;
2689 infoPtr
->treeWidth
= 0;
2690 infoPtr
->treeHeight
= 0;
2692 /* We iterate through all visible items in order to get the tree height
2694 item
= infoPtr
->root
->firstChild
;
2696 while (item
!= NULL
)
2698 if (ISVISIBLE(item
))
2700 /* actually we draw text at textOffset + 2 */
2701 if (2+item
->textOffset
+item
->textWidth
> infoPtr
->treeWidth
)
2702 infoPtr
->treeWidth
= item
->textOffset
+item
->textWidth
+2;
2704 /* This is scroll-adjusted, but we fix this below. */
2705 infoPtr
->treeHeight
= item
->rect
.bottom
;
2708 item
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2711 /* Fix the scroll adjusted treeHeight and treeWidth. */
2712 if (infoPtr
->root
->firstChild
)
2713 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2715 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2717 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2719 /* Adding one scroll bar may take up enough space that it forces us
2720 * to add the other as well. */
2721 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2725 if (infoPtr
->treeWidth
2726 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2729 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
|| infoPtr
->scrollX
> 0)
2732 if (!vert
&& horz
&& infoPtr
->treeHeight
2733 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2736 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2738 si
.cbSize
= sizeof(SCROLLINFO
);
2739 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2744 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2745 if ( si
.nPage
&& NULL
!= infoPtr
->firstVisible
)
2747 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2748 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2750 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2752 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2753 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2754 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2758 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2759 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2760 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2765 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2766 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2767 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2772 si
.nPage
= infoPtr
->clientWidth
;
2773 si
.nPos
= infoPtr
->scrollX
;
2774 si
.nMax
= infoPtr
->treeWidth
- 1;
2776 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2778 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2782 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2783 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2784 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2786 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2787 TREEVIEW_HScroll(infoPtr
,
2788 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2792 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2793 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2794 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2797 if (infoPtr
->scrollX
!= 0)
2799 TREEVIEW_HScroll(infoPtr
,
2800 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2805 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2809 TREEVIEW_FillBkgnd(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2812 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2814 hBrush
= CreateSolidBrush(clrBk
);
2815 FillRect(hdc
, rc
, hBrush
);
2816 DeleteObject(hBrush
);
2819 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2821 TREEVIEW_EraseBackground(const TREEVIEW_INFO
*infoPtr
, HDC hdc
)
2825 TRACE("%p\n", infoPtr
);
2827 GetClientRect(infoPtr
->hwnd
, &rect
);
2828 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rect
);
2834 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2836 HWND hwnd
= infoPtr
->hwnd
;
2838 TREEVIEW_ITEM
*item
;
2840 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2842 TRACE("empty window\n");
2846 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2849 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2851 ReleaseDC(hwnd
, hdc
);
2855 for (item
= infoPtr
->root
->firstChild
;
2857 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
2859 if (ISVISIBLE(item
))
2861 /* Avoid unneeded calculations */
2862 if (item
->rect
.top
> rect
.bottom
)
2864 if (item
->rect
.bottom
< rect
.top
)
2867 TREEVIEW_DrawItem(infoPtr
, hdc
, item
);
2872 // FIXME: This is correct, but is causes and infinite loop of WM_PAINT
2873 // messages, resulting in continuous painting of the scroll bar in reactos.
2874 // Comment out until the real bug is found
2877 TREEVIEW_UpdateScrollBars(infoPtr
);
2880 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2882 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2886 TREEVIEW_InvalidateItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2888 if (item
) InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2892 TREEVIEW_Invalidate(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2895 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2897 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2901 TREEVIEW_InitCheckboxes(TREEVIEW_INFO
*infoPtr
)
2904 HBITMAP hbm
, hbmOld
;
2908 infoPtr
->himlState
= ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
2910 hdcScreen
= GetDC(0);
2912 hdc
= CreateCompatibleDC(hdcScreen
);
2913 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
2914 hbmOld
= SelectObject(hdc
, hbm
);
2916 SetRect(&rc
, 0, 0, 48, 16);
2917 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
2919 SetRect(&rc
, 18, 2, 30, 14);
2920 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2921 DFCS_BUTTONCHECK
|DFCS_FLAT
);
2923 SetRect(&rc
, 34, 2, 46, 14);
2924 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2925 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
2927 SelectObject(hdc
, hbmOld
);
2928 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
2929 comctl32_color
.clrWindow
);
2930 TRACE("checkbox index %d\n", nIndex
);
2934 ReleaseDC(0, hdcScreen
);
2936 infoPtr
->stateImageWidth
= 16;
2937 infoPtr
->stateImageHeight
= 16;
2941 TREEVIEW_ResetImageStateIndex(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2943 TREEVIEW_ITEM
*child
= item
->firstChild
;
2945 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2946 item
->state
|= INDEXTOSTATEIMAGEMASK(1);
2950 TREEVIEW_ITEM
*next
= child
->nextSibling
;
2951 TREEVIEW_ResetImageStateIndex(infoPtr
, child
);
2957 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, HDC hdc_ref
)
2963 TRACE("(%p %p)\n", infoPtr
, hdc_ref
);
2965 if ((infoPtr
->dwStyle
& TVS_CHECKBOXES
) && !infoPtr
->himlState
)
2967 TREEVIEW_InitCheckboxes(infoPtr
);
2968 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
2970 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
2971 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
2972 TREEVIEW_UpdateScrollBars(infoPtr
);
2973 TREEVIEW_Invalidate(infoPtr
, NULL
);
2979 GetClientRect(infoPtr
->hwnd
, &rc
);
2980 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
2984 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
2987 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
2990 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
2991 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
2994 EndPaint(infoPtr
->hwnd
, &ps
);
3000 TREEVIEW_PrintClient(TREEVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
3002 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
3004 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwnd
))
3007 if (options
& PRF_ERASEBKGND
)
3008 TREEVIEW_EraseBackground(infoPtr
, hdc
);
3010 if (options
& PRF_CLIENT
)
3013 GetClientRect(infoPtr
->hwnd
, &rc
);
3014 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
3020 /* Sorting **************************************************************/
3022 /***************************************************************************
3023 * Forward the DPA local callback to the treeview owner callback
3026 TREEVIEW_CallBackCompare(const TREEVIEW_ITEM
*first
, const TREEVIEW_ITEM
*second
,
3027 const TVSORTCB
*pCallBackSort
)
3029 /* Forward the call to the client-defined callback */
3030 return pCallBackSort
->lpfnCompare(first
->lParam
,
3032 pCallBackSort
->lParam
);
3035 /***************************************************************************
3036 * Treeview native sort routine: sort on item text.
3039 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
3040 const TREEVIEW_INFO
*infoPtr
)
3042 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
3043 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
3045 if(first
->pszText
&& second
->pszText
)
3046 return lstrcmpiW(first
->pszText
, second
->pszText
);
3047 else if(first
->pszText
)
3049 else if(second
->pszText
)
3055 /* Returns the number of physical children belonging to item. */
3057 TREEVIEW_CountChildren(const TREEVIEW_ITEM
*item
)
3062 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
3068 /* Returns a DPA containing a pointer to each physical child of item in
3069 * sibling order. If item has no children, an empty DPA is returned. */
3071 TREEVIEW_BuildChildDPA(const TREEVIEW_ITEM
*item
)
3075 HDPA list
= DPA_Create(8);
3076 if (list
== 0) return NULL
;
3078 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
3080 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
3090 /***************************************************************************
3091 * Setup the treeview structure with regards of the sort method
3092 * and sort the children of the TV item specified in lParam
3093 * fRecurse: currently unused. Should be zero.
3094 * parent: if pSort!=NULL, should equal pSort->hParent.
3095 * otherwise, item which child items are to be sorted.
3096 * pSort: sort method info. if NULL, sort on item text.
3097 * if non-NULL, sort on item's lParam content, and let the
3098 * application decide what that means. See also TVM_SORTCHILDRENCB.
3102 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, HTREEITEM parent
,
3106 PFNDPACOMPARE pfnCompare
;
3109 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
3110 if (parent
== TVI_ROOT
|| parent
== NULL
)
3111 parent
= infoPtr
->root
;
3113 /* Check for a valid handle to the parent item */
3114 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
3116 ERR("invalid item hParent=%p\n", parent
);
3122 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
3123 lpCompare
= (LPARAM
)pSort
;
3127 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
3128 lpCompare
= (LPARAM
)infoPtr
;
3131 cChildren
= TREEVIEW_CountChildren(parent
);
3133 /* Make sure there is something to sort */
3136 /* TREEVIEW_ITEM rechaining */
3139 HTREEITEM nextItem
= 0;
3140 HTREEITEM prevItem
= 0;
3142 HDPA sortList
= TREEVIEW_BuildChildDPA(parent
);
3144 if (sortList
== NULL
)
3147 /* let DPA sort the list */
3148 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
3150 /* The order of DPA entries has been changed, so fixup the
3151 * nextSibling and prevSibling pointers. */
3153 item
= DPA_GetPtr(sortList
, count
++);
3154 while ((nextItem
= DPA_GetPtr(sortList
, count
++)) != NULL
)
3156 /* link the two current item together */
3157 item
->nextSibling
= nextItem
;
3158 nextItem
->prevSibling
= item
;
3160 if (prevItem
== NULL
)
3162 /* this is the first item, update the parent */
3163 parent
->firstChild
= item
;
3164 item
->prevSibling
= NULL
;
3168 /* fix the back chaining */
3169 item
->prevSibling
= prevItem
;
3172 /* get ready for the next one */
3177 /* the last item is pointed to by item and never has a sibling */
3178 item
->nextSibling
= NULL
;
3179 parent
->lastChild
= item
;
3181 DPA_Destroy(sortList
);
3183 TREEVIEW_VerifyTree(infoPtr
);
3185 if (parent
->state
& TVIS_EXPANDED
)
3187 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3189 if (parent
== infoPtr
->root
)
3190 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3192 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3194 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3196 TREEVIEW_ITEM
*item
;
3198 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3199 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3201 if (item
->visibleOrder
== visOrder
)
3205 if (!item
) item
= parent
->firstChild
;
3206 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3209 TREEVIEW_Invalidate(infoPtr
, NULL
);
3218 /***************************************************************************
3219 * Setup the treeview structure with regards of the sort method
3220 * and sort the children of the TV item specified in lParam
3223 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, LPTVSORTCB pSort
)
3225 return TREEVIEW_Sort(infoPtr
, pSort
->hParent
, pSort
);
3229 /***************************************************************************
3230 * Sort the children of the TV item specified in lParam.
3233 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3235 return TREEVIEW_Sort(infoPtr
, (HTREEITEM
)lParam
, NULL
);
3239 /* Expansion/Collapse ***************************************************/
3242 TREEVIEW_SendExpanding(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3245 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3246 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3247 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3252 TREEVIEW_SendExpanded(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3255 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3256 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3257 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3262 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3263 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3265 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3266 BOOL bRemoveChildren
, BOOL bUser
)
3268 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3269 BOOL bSetSelection
, bSetFirstVisible
;
3271 LONG scrollDist
= 0;
3272 TREEVIEW_ITEM
*nextItem
= NULL
, *tmpItem
;
3275 TRACE("TVE_COLLAPSE %p %s\n", item
, TREEVIEW_ItemName(item
));
3277 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3281 TREEVIEW_SendExpanding(infoPtr
, item
, action
);
3283 if (item
->firstChild
== NULL
)
3286 wasExpanded
= (item
->state
& TVIS_EXPANDED
) != 0;
3287 item
->state
&= ~TVIS_EXPANDED
;
3289 if (wasExpanded
&& bUser
)
3290 TREEVIEW_SendExpanded(infoPtr
, item
, action
);
3292 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3293 && TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
));
3295 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3296 && TREEVIEW_IsChildOf(item
, infoPtr
->firstVisible
));
3301 if (tmpItem
->nextSibling
)
3303 nextItem
= tmpItem
->nextSibling
;
3306 tmpItem
= tmpItem
->parent
;
3310 scrollDist
= nextItem
->rect
.top
;
3312 if (bRemoveChildren
)
3314 INT old_cChildren
= item
->cChildren
;
3315 TRACE("TVE_COLLAPSERESET\n");
3316 item
->state
&= ~TVIS_EXPANDEDONCE
;
3317 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
3318 item
->cChildren
= old_cChildren
;
3323 if (item
->firstChild
)
3325 TREEVIEW_ITEM
*i
, *sibling
;
3327 sibling
= TREEVIEW_GetNextListItem(infoPtr
, item
);
3329 for (i
= item
->firstChild
; i
!= sibling
;
3330 i
= TREEVIEW_GetNextListItem(infoPtr
, i
))
3332 i
->visibleOrder
= -1;
3336 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3339 scrollDist
= -(scrollDist
- nextItem
->rect
.top
);
3343 /* Don't call DoSelectItem, it sends notifications. */
3344 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3345 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3346 item
->state
|= TVIS_SELECTED
;
3347 infoPtr
->selectedItem
= item
;
3350 TREEVIEW_UpdateScrollBars(infoPtr
);
3352 scrollRect
.left
= 0;
3353 scrollRect
.right
= infoPtr
->clientWidth
;
3354 scrollRect
.bottom
= infoPtr
->clientHeight
;
3358 scrollRect
.top
= nextItem
->rect
.top
;
3360 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, &scrollRect
,
3361 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3362 TREEVIEW_Invalidate(infoPtr
, item
);
3364 scrollRect
.top
= item
->rect
.top
;
3365 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, TRUE
);
3368 TREEVIEW_SetFirstVisible(infoPtr
,
3369 bSetFirstVisible
? item
: infoPtr
->firstVisible
,
3376 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3377 BOOL partial
, BOOL user
)
3380 LONG orgNextTop
= 0;
3382 TREEVIEW_ITEM
*nextItem
, *tmpItem
;
3383 BOOL sendsNotifications
;
3385 TRACE("(%p, %p, partial=%d, %d)\n", infoPtr
, item
, partial
, user
);
3387 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3390 tmpItem
= item
; nextItem
= NULL
;
3393 if (tmpItem
->nextSibling
)
3395 nextItem
= tmpItem
->nextSibling
;
3398 tmpItem
= tmpItem
->parent
;
3402 orgNextTop
= nextItem
->rect
.top
;
3404 TRACE("TVE_EXPAND %p %s\n", item
, TREEVIEW_ItemName(item
));
3406 sendsNotifications
= user
|| ((item
->cChildren
!= 0) &&
3407 !(item
->state
& TVIS_EXPANDEDONCE
));
3408 if (sendsNotifications
)
3410 if (!TREEVIEW_SendExpanding(infoPtr
, item
, TVE_EXPAND
))
3412 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3416 if (!item
->firstChild
)
3419 item
->state
|= TVIS_EXPANDED
;
3422 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3424 if (ISVISIBLE(item
))
3426 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3427 TREEVIEW_UpdateSubTree(infoPtr
, item
);
3428 TREEVIEW_UpdateScrollBars(infoPtr
);
3430 scrollRect
.left
= 0;
3431 scrollRect
.bottom
= infoPtr
->treeHeight
;
3432 scrollRect
.right
= infoPtr
->clientWidth
;
3435 scrollDist
= nextItem
->rect
.top
- orgNextTop
;
3436 scrollRect
.top
= orgNextTop
;
3438 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3439 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3440 TREEVIEW_Invalidate (infoPtr
, item
);
3442 scrollRect
.top
= item
->rect
.top
;
3443 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, FALSE
);
3446 /* Scroll up so that as many children as possible are visible.
3447 * This fails when expanding causes an HScroll bar to appear, but we
3448 * don't know that yet, so the last item is obscured. */
3449 if (item
->firstChild
!= NULL
)
3451 int nChildren
= item
->lastChild
->visibleOrder
3452 - item
->firstChild
->visibleOrder
+ 1;
3454 int visible_pos
= item
->visibleOrder
3455 - infoPtr
->firstVisible
->visibleOrder
;
3457 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3459 if (visible_pos
> 0 && nChildren
> rows_below
)
3461 int scroll
= nChildren
- rows_below
;
3463 if (scroll
> visible_pos
)
3464 scroll
= visible_pos
;
3468 TREEVIEW_ITEM
*newFirstVisible
3469 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3473 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3479 if (sendsNotifications
) {
3480 TREEVIEW_SendExpanded(infoPtr
, item
, TVE_EXPAND
);
3481 item
->state
|= TVIS_EXPANDEDONCE
;
3487 /* Handler for TVS_SINGLEEXPAND behaviour. Used on response
3488 to mouse messages and TVM_SELECTITEM.
3490 selection - previously selected item, used to collapse a part of a tree
3491 item - new selected item
3493 static void TREEVIEW_SingleExpand(TREEVIEW_INFO
*infoPtr
,
3494 HTREEITEM selection
, HTREEITEM item
)
3496 TREEVIEW_ITEM
*prev
, *curr
;
3498 if ((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) == 0 || infoPtr
->hwndEdit
|| !item
) return;
3500 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
3503 * Close the previous item and its ancestors as long as they are not
3504 * ancestors of the current item
3506 for (prev
= selection
; prev
&& TREEVIEW_ValidItem(infoPtr
, prev
); prev
= prev
->parent
)
3508 for (curr
= item
; curr
&& TREEVIEW_ValidItem(infoPtr
, curr
); curr
= curr
->parent
)
3513 TREEVIEW_Collapse(infoPtr
, prev
, FALSE
, TRUE
);
3518 * Expand the current item
3520 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3524 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, BOOL user
)
3526 TRACE("item=%p, user=%d\n", item
, user
);
3528 if (item
->state
& TVIS_EXPANDED
)
3529 return TREEVIEW_Collapse(infoPtr
, item
, FALSE
, user
);
3531 return TREEVIEW_Expand(infoPtr
, item
, FALSE
, user
);
3535 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3537 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3539 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3541 if (TREEVIEW_HasChildren(infoPtr
, item
))
3542 TREEVIEW_ExpandAll(infoPtr
, item
);
3546 /* Note:If the specified item is the child of a collapsed parent item,
3547 the parent's list of child items is (recursively) expanded to reveal the
3548 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3549 know if it also applies here.
3553 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM item
)
3555 if (!TREEVIEW_ValidItem(infoPtr
, item
))
3558 TRACE("For (%s) item:%d, flags 0x%x, state:%d\n",
3559 TREEVIEW_ItemName(item
), TREEVIEW_GetItemIndex(infoPtr
, item
),
3562 switch (flag
& TVE_TOGGLE
)
3565 return TREEVIEW_Collapse(infoPtr
, item
, flag
& TVE_COLLAPSERESET
,
3569 return TREEVIEW_Expand(infoPtr
, item
, flag
& TVE_EXPANDPARTIAL
,
3573 return TREEVIEW_Toggle(infoPtr
, item
, FALSE
);
3580 /* Hit-Testing **********************************************************/
3582 static TREEVIEW_ITEM
*
3583 TREEVIEW_HitTestPoint(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3585 TREEVIEW_ITEM
*item
;
3588 if (!infoPtr
->firstVisible
)
3591 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3593 for (item
= infoPtr
->firstVisible
; item
!= NULL
;
3594 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3596 if (row
>= item
->visibleOrder
3597 && row
< item
->visibleOrder
+ item
->iIntegral
)
3605 TREEVIEW_HitTest(const TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3607 TREEVIEW_ITEM
*item
;
3613 GetClientRect(infoPtr
->hwnd
, &rect
);
3620 status
|= TVHT_TOLEFT
;
3622 else if (x
> rect
.right
)
3624 status
|= TVHT_TORIGHT
;
3629 status
|= TVHT_ABOVE
;
3631 else if (y
> rect
.bottom
)
3633 status
|= TVHT_BELOW
;
3638 lpht
->flags
= status
;
3642 item
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3645 lpht
->flags
= TVHT_NOWHERE
;
3649 if (x
>= item
->textOffset
+ item
->textWidth
)
3651 lpht
->flags
= TVHT_ONITEMRIGHT
;
3653 else if (x
>= item
->textOffset
)
3655 lpht
->flags
= TVHT_ONITEMLABEL
;
3657 else if (x
>= item
->imageOffset
)
3659 lpht
->flags
= TVHT_ONITEMICON
;
3661 else if (x
>= item
->stateOffset
)
3663 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3665 else if (x
>= item
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3667 lpht
->flags
= TVHT_ONITEMBUTTON
;
3671 lpht
->flags
= TVHT_ONITEMINDENT
;
3675 TRACE("(%d,%d):result %x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3677 return (LRESULT
)item
;
3680 /* Item Label Editing ***************************************************/
3683 TREEVIEW_GetEditControl(const TREEVIEW_INFO
*infoPtr
)
3685 return (LRESULT
)infoPtr
->hwndEdit
;
3688 static LRESULT CALLBACK
3689 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3691 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3692 BOOL bCancel
= FALSE
;
3698 TRACE("WM_PAINT start\n");
3699 rc
= CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3701 TRACE("WM_PAINT done\n");
3705 if (infoPtr
->bIgnoreEditKillFocus
)
3711 WNDPROC editProc
= infoPtr
->wpEditOrig
;
3712 infoPtr
->wpEditOrig
= 0;
3713 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
3714 return CallWindowProcW(editProc
, hwnd
, uMsg
, wParam
, lParam
);
3718 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3721 if (wParam
== VK_ESCAPE
)
3726 else if (wParam
== VK_RETURN
)
3733 return CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3736 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3737 /* eg. Using a messagebox */
3739 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3740 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3741 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3747 /* should handle edit control messages here */
3750 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3752 TRACE("code=%x, id=%x, handle=%lx\n", HIWORD(wParam
), LOWORD(wParam
), lParam
);
3754 switch (HIWORD(wParam
))
3759 * Adjust the edit window size
3762 TREEVIEW_ITEM
*editItem
= infoPtr
->editItem
;
3763 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3765 HFONT hFont
, hOldFont
= 0;
3767 TRACE("edit=%p\n", infoPtr
->hwndEdit
);
3769 if (!IsWindow(infoPtr
->hwndEdit
) || !hdc
) return FALSE
;
3771 infoPtr
->bLabelChanged
= TRUE
;
3773 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
3775 /* Select font to get the right dimension of the string */
3776 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3780 hOldFont
= SelectObject(hdc
, hFont
);
3783 if (GetTextExtentPoint32W(hdc
, buffer
, strlenW(buffer
), &sz
))
3785 TEXTMETRICW textMetric
;
3787 /* Add Extra spacing for the next character */
3788 GetTextMetricsW(hdc
, &textMetric
);
3789 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3791 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3793 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3795 SetWindowPos(infoPtr
->hwndEdit
,
3800 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3801 SWP_NOMOVE
| SWP_DRAWFRAME
);
3806 SelectObject(hdc
, hOldFont
);
3809 ReleaseDC(infoPtr
->hwnd
, hdc
);
3813 /* apparently we should respect passed handle value */
3814 if (infoPtr
->hwndEdit
!= (HWND
)lParam
) return FALSE
;
3816 TREEVIEW_EndEditLabelNow(infoPtr
, FALSE
);
3820 return SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3827 TREEVIEW_EditLabel(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3829 HWND hwnd
= infoPtr
->hwnd
;
3832 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
);
3835 TEXTMETRICW textMetric
;
3837 TRACE("%p %p\n", hwnd
, hItem
);
3838 if (!(infoPtr
->dwStyle
& TVS_EDITLABELS
))
3841 if (!TREEVIEW_ValidItem(infoPtr
, hItem
))
3844 if (infoPtr
->hwndEdit
)
3845 return infoPtr
->hwndEdit
;
3847 infoPtr
->bLabelChanged
= FALSE
;
3849 /* make edit item visible */
3850 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3852 TREEVIEW_UpdateDispInfo(infoPtr
, hItem
, TVIF_TEXT
);
3855 /* Select the font to get appropriate metric dimensions */
3856 if (infoPtr
->hFont
!= 0)
3858 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3861 /* Get string length in pixels */
3863 GetTextExtentPoint32W(hdc
, hItem
->pszText
, strlenW(hItem
->pszText
),
3866 GetTextExtentPoint32A(hdc
, "", 0, &sz
);
3868 /* Add Extra spacing for the next character */
3869 GetTextMetricsW(hdc
, &textMetric
);
3870 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3872 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3873 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- hItem
->textOffset
+ 2);
3875 if (infoPtr
->hFont
!= 0)
3877 SelectObject(hdc
, hOldFont
);
3880 ReleaseDC(hwnd
, hdc
);
3882 infoPtr
->editItem
= hItem
;
3884 hwndEdit
= CreateWindowExW(WS_EX_LEFT
,
3887 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3888 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3889 ES_LEFT
, hItem
->textOffset
- 2,
3890 hItem
->rect
.top
- 1, sz
.cx
+ 3,
3891 hItem
->rect
.bottom
-
3892 hItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3893 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3895 infoPtr
->hwndEdit
= hwndEdit
;
3897 /* Get a 2D border. */
3898 SetWindowLongW(hwndEdit
, GWL_EXSTYLE
,
3899 GetWindowLongW(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3900 SetWindowLongW(hwndEdit
, GWL_STYLE
,
3901 GetWindowLongW(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3903 SendMessageW(hwndEdit
, WM_SETFONT
,
3904 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, hItem
), FALSE
);
3906 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
,
3908 TREEVIEW_Edit_SubclassProc
);
3910 SetWindowTextW(hwndEdit
, hItem
->pszText
);
3912 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, hItem
))
3914 DestroyWindow(hwndEdit
);
3915 infoPtr
->hwndEdit
= 0;
3916 infoPtr
->editItem
= NULL
;
3921 SendMessageW(hwndEdit
, EM_SETSEL
, 0, -1);
3922 ShowWindow(hwndEdit
, SW_SHOW
);
3929 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3931 TREEVIEW_ITEM
*editedItem
= infoPtr
->editItem
;
3934 WCHAR tmpText
[1024] = { '\0' };
3935 WCHAR
*newText
= tmpText
;
3938 if (!IsWindow(infoPtr
->hwndEdit
)) return FALSE
;
3941 tvdi
.item
.hItem
= editedItem
;
3942 tvdi
.item
.state
= editedItem
->state
;
3943 tvdi
.item
.lParam
= editedItem
->lParam
;
3947 if (!infoPtr
->bNtfUnicode
)
3948 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, (LPSTR
)tmpText
, 1023);
3950 iLength
= GetWindowTextW(infoPtr
->hwndEdit
, tmpText
, 1023);
3952 if (iLength
>= 1023)
3954 ERR("Insufficient space to retrieve new item label\n");
3957 tvdi
.item
.mask
= TVIF_TEXT
;
3958 tvdi
.item
.pszText
= tmpText
;
3959 tvdi
.item
.cchTextMax
= iLength
+ 1;
3963 tvdi
.item
.pszText
= NULL
;
3964 tvdi
.item
.cchTextMax
= 0;
3967 bCommit
= TREEVIEW_SendRealNotify(infoPtr
, TVN_ENDLABELEDITW
, &tvdi
.hdr
);
3969 if (!bCancel
&& bCommit
) /* Apply the changes */
3971 if (!infoPtr
->bNtfUnicode
)
3973 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, NULL
, 0 );
3974 newText
= Alloc(len
* sizeof(WCHAR
));
3975 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, newText
, len
);
3979 if (strcmpW(newText
, editedItem
->pszText
) != 0)
3981 WCHAR
*ptr
= ReAlloc(editedItem
->pszText
, sizeof(WCHAR
)*(iLength
+ 1));
3984 ERR("OutOfMemory, cannot allocate space for label\n");
3985 if(newText
!= tmpText
) Free(newText
);
3986 DestroyWindow(infoPtr
->hwndEdit
);
3987 infoPtr
->hwndEdit
= 0;
3988 infoPtr
->editItem
= NULL
;
3993 editedItem
->pszText
= ptr
;
3994 editedItem
->cchTextMax
= iLength
+ 1;
3995 strcpyW(editedItem
->pszText
, newText
);
3996 TREEVIEW_ComputeTextWidth(infoPtr
, editedItem
, 0);
3999 if(newText
!= tmpText
) Free(newText
);
4002 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
4003 DestroyWindow(infoPtr
->hwndEdit
);
4004 infoPtr
->hwndEdit
= 0;
4005 infoPtr
->editItem
= NULL
;
4010 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4012 if (wParam
!= TV_EDIT_TIMER
)
4014 ERR("got unknown timer\n");
4018 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4019 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
4021 TREEVIEW_EditLabel(infoPtr
, infoPtr
->selectedItem
);
4027 /* Mouse Tracking/Drag **************************************************/
4029 /***************************************************************************
4030 * This is quite unusual piece of code, but that's how it's implemented in
4034 TREEVIEW_TrackMouse(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
4036 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
4037 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
4041 r
.top
= pt
.y
- cyDrag
;
4042 r
.left
= pt
.x
- cxDrag
;
4043 r
.bottom
= pt
.y
+ cyDrag
;
4044 r
.right
= pt
.x
+ cxDrag
;
4046 SetCapture(infoPtr
->hwnd
);
4050 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
4052 if (msg
.message
== WM_MOUSEMOVE
)
4054 pt
.x
= (short)LOWORD(msg
.lParam
);
4055 pt
.y
= (short)HIWORD(msg
.lParam
);
4056 if (PtInRect(&r
, pt
))
4064 else if (msg
.message
>= WM_LBUTTONDOWN
&&
4065 msg
.message
<= WM_RBUTTONDBLCLK
)
4070 DispatchMessageW(&msg
);
4073 if (GetCapture() != infoPtr
->hwnd
)
4083 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4085 TREEVIEW_ITEM
*item
;
4089 SetFocus(infoPtr
->hwnd
);
4091 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4093 /* If there is pending 'edit label' event - kill it now */
4094 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4097 hit
.pt
.x
= (short)LOWORD(lParam
);
4098 hit
.pt
.y
= (short)HIWORD(lParam
);
4100 item
= (TREEVIEW_ITEM
*)TREEVIEW_HitTest(infoPtr
, &hit
);
4103 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, item
));
4105 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
4109 case TVHT_ONITEMRIGHT
:
4110 /* FIXME: we should not have sent NM_DBLCLK in this case. */
4113 case TVHT_ONITEMINDENT
:
4114 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
4120 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
4121 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
4123 while (item
->iLevel
> level
)
4125 item
= item
->parent
;
4131 case TVHT_ONITEMLABEL
:
4132 case TVHT_ONITEMICON
:
4133 case TVHT_ONITEMBUTTON
:
4134 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4137 case TVHT_ONITEMSTATEICON
:
4138 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4139 TREEVIEW_ToggleItemState(infoPtr
, item
);
4141 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4150 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4152 HWND hwnd
= infoPtr
->hwnd
;
4154 BOOL bTrack
, bDoLabelEdit
;
4156 /* If Edit control is active - kill it and return.
4157 * The best way to do it is to set focus to itself.
4158 * Edit control subclassed procedure will automatically call
4161 if (infoPtr
->hwndEdit
)
4167 ht
.pt
.x
= (short)LOWORD(lParam
);
4168 ht
.pt
.y
= (short)HIWORD(lParam
);
4170 TREEVIEW_HitTest(infoPtr
, &ht
);
4171 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
4173 /* update focusedItem and redraw both items */
4174 if(ht
.hItem
&& (ht
.flags
& TVHT_ONITEM
))
4176 infoPtr
->focusedItem
= ht
.hItem
;
4177 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4178 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4181 bTrack
= (ht
.flags
& TVHT_ONITEM
)
4182 && !(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
);
4185 * If the style allows editing and the node is already selected
4186 * and the click occurred on the item label...
4188 bDoLabelEdit
= (infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
4189 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
);
4191 /* Send NM_CLICK right away */
4193 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4196 if (ht
.flags
& TVHT_ONITEMBUTTON
)
4198 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
4202 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
4203 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4205 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
4206 infoPtr
->dropItem
= ht
.hItem
;
4208 /* clean up focusedItem as we dragged and won't select this item */
4209 if(infoPtr
->focusedItem
)
4211 /* refresh the item that was focused */
4212 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4213 infoPtr
->focusedItem
= NULL
;
4215 /* refresh the selected item to return the filled background */
4216 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4223 if (bTrack
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4228 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4229 KillTimer(hwnd
, TV_EDIT_TIMER
);
4231 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
4232 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
4234 else if (ht
.flags
& (TVHT_ONITEMICON
|TVHT_ONITEMLABEL
)) /* select the item if the hit was inside of the icon or text */
4236 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4238 /* Select the current item */
4239 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4240 TREEVIEW_SingleExpand(infoPtr
, selection
, ht
.hItem
);
4242 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4244 /* TVS_CHECKBOXES requires us to toggle the current state */
4245 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4246 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4256 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4260 if (infoPtr
->hwndEdit
)
4262 SetFocus(infoPtr
->hwnd
);
4266 ht
.pt
.x
= (short)LOWORD(lParam
);
4267 ht
.pt
.y
= (short)HIWORD(lParam
);
4269 TREEVIEW_HitTest(infoPtr
, &ht
);
4271 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4275 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4276 infoPtr
->dropItem
= ht
.hItem
;
4281 SetFocus(infoPtr
->hwnd
);
4282 if(!TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
))
4284 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
4285 SendMessageW(infoPtr
->hwndNotify
, WM_CONTEXTMENU
,
4286 (WPARAM
)infoPtr
->hwnd
, (LPARAM
)GetMessagePos());
4294 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4296 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4300 HBITMAP hbmp
, hOldbmp
;
4307 if (!(infoPtr
->himlNormal
))
4310 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4313 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4315 hwtop
= GetDesktopWindow();
4316 htopdc
= GetDC(hwtop
);
4317 hdc
= CreateCompatibleDC(htopdc
);
4319 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4321 if (dragItem
->pszText
)
4322 GetTextExtentPoint32W(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
),
4325 GetTextExtentPoint32A(hdc
, "", 0, &size
);
4327 TRACE("%d %d %s\n", size
.cx
, size
.cy
, debugstr_w(dragItem
->pszText
));
4328 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4329 hOldbmp
= SelectObject(hdc
, hbmp
);
4331 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4336 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4337 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4341 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4342 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4345 /* draw item text */
4347 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4349 if (dragItem
->pszText
)
4350 DrawTextW(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
), &rc
,
4353 SelectObject(hdc
, hOldFont
);
4354 SelectObject(hdc
, hOldbmp
);
4356 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4360 ReleaseDC(hwtop
, htopdc
);
4362 return (LRESULT
)infoPtr
->dragList
;
4365 /* Selection ************************************************************/
4368 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4371 TREEVIEW_ITEM
*prevSelect
;
4373 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4375 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4376 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4377 newSelect
? newSelect
->state
: 0);
4379 /* reset and redraw focusedItem if focusedItem was set so we don't */
4380 /* have to worry about the previously focused item when we set a new one */
4381 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4382 infoPtr
->focusedItem
= NULL
;
4386 case TVGN_CARET
|TVSI_NOSINGLEEXPAND
:
4387 FIXME("TVSI_NOSINGLEEXPAND specified.\n");
4390 prevSelect
= infoPtr
->selectedItem
;
4392 if (prevSelect
== newSelect
) {
4393 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4397 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4400 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4406 prevSelect
->state
&= ~TVIS_SELECTED
;
4408 newSelect
->state
|= TVIS_SELECTED
;
4410 infoPtr
->selectedItem
= newSelect
;
4412 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4414 TREEVIEW_InvalidateItem(infoPtr
, prevSelect
);
4415 TREEVIEW_InvalidateItem(infoPtr
, newSelect
);
4417 TREEVIEW_SendTreeviewNotify(infoPtr
,
4420 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4425 case TVGN_DROPHILITE
:
4426 prevSelect
= infoPtr
->dropItem
;
4429 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4431 infoPtr
->dropItem
= newSelect
;
4434 newSelect
->state
|= TVIS_DROPHILITED
;
4436 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4437 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4440 case TVGN_FIRSTVISIBLE
:
4441 if (newSelect
!= NULL
)
4443 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4444 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4445 TREEVIEW_Invalidate(infoPtr
, NULL
);
4450 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4454 /* FIXME: handle NM_KILLFOCUS etc */
4456 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4458 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4460 if (item
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4463 if (item
== infoPtr
->selectedItem
)
4466 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4468 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4471 TREEVIEW_SingleExpand(infoPtr
, selection
, item
);
4476 /*************************************************************************
4477 * TREEVIEW_ProcessLetterKeys
4479 * Processes keyboard messages generated by pressing the letter keys
4481 * What this does is perform a case insensitive search from the
4482 * current position with the following quirks:
4483 * - If two chars or more are pressed in quick succession we search
4484 * for the corresponding string (e.g. 'abc').
4485 * - If there is a delay we wipe away the current search string and
4486 * restart with just that char.
4487 * - If the user keeps pressing the same character, whether slowly or
4488 * fast, so that the search string is entirely composed of this
4489 * character ('aaaaa' for instance), then we search for first item
4490 * that starting with that character.
4491 * - If the user types the above character in quick succession, then
4492 * we must also search for the corresponding string ('aaaaa'), and
4493 * go to that string if there is a match.
4501 * - The current implementation has a list of characters it will
4502 * accept and it ignores everything else. In particular it will
4503 * ignore accentuated characters which seems to match what
4504 * Windows does. But I'm not sure it makes sense to follow
4506 * - We don't sound a beep when the search fails.
4507 * - The search should start from the focused item, not from the selected
4508 * item. One reason for this is to allow for multiple selections in trees.
4509 * But currently infoPtr->focusedItem does not seem very usable.
4513 * TREEVIEW_ProcessLetterKeys
4515 static INT
TREEVIEW_ProcessLetterKeys(TREEVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
4518 HTREEITEM endidx
,idx
;
4520 WCHAR buffer
[MAX_PATH
];
4521 DWORD timestamp
,elapsed
;
4523 /* simple parameter checking */
4524 if (!charCode
|| !keyData
) return 0;
4526 /* only allow the valid WM_CHARs through */
4527 if (!isalnum(charCode
) &&
4528 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4529 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4530 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4531 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4532 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4533 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4534 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4535 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4536 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4539 /* compute how much time elapsed since last keypress */
4540 timestamp
= GetTickCount();
4541 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4542 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4544 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4547 /* update the search parameters */
4548 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4549 if (elapsed
< KEY_DELAY
) {
4550 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
) / sizeof(WCHAR
)) {
4551 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4553 if (infoPtr
->charCode
!= charCode
) {
4554 infoPtr
->charCode
=charCode
=0;
4557 infoPtr
->charCode
=charCode
;
4558 infoPtr
->szSearchParam
[0]=charCode
;
4559 infoPtr
->nSearchParamLength
=1;
4560 /* Redundant with the 1 char string */
4564 /* and search from the current position */
4566 if (infoPtr
->selectedItem
!= NULL
) {
4567 endidx
=infoPtr
->selectedItem
;
4568 /* if looking for single character match,
4569 * then we must always move forward
4571 if (infoPtr
->nSearchParamLength
== 1)
4572 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4577 idx
=infoPtr
->root
->firstChild
;
4580 /* At the end point, sort out wrapping */
4583 /* If endidx is null, stop at the last item (ie top to bottom) */
4587 /* Otherwise, start again at the very beginning */
4588 idx
=infoPtr
->root
->firstChild
;
4590 /* But if we are stopping on the first child, end now! */
4591 if (idx
== endidx
) break;
4595 ZeroMemory(&item
, sizeof(item
));
4596 item
.mask
= TVIF_TEXT
;
4598 item
.pszText
= buffer
;
4599 item
.cchTextMax
= sizeof(buffer
);
4600 TREEVIEW_GetItemT( infoPtr
, &item
, TRUE
);
4602 /* check for a match */
4603 if (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4606 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4607 (nItem
!= infoPtr
->selectedItem
) &&
4608 (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4609 /* This would work but we must keep looking for a longer match */
4612 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4613 } while (idx
!= endidx
);
4615 if (nItem
!= NULL
) {
4616 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4617 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4624 /* Scrolling ************************************************************/
4627 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4630 BOOL hasFirstVisible
= infoPtr
->firstVisible
!= NULL
;
4631 HTREEITEM newFirstVisible
= NULL
;
4632 int visible_pos
= -1;
4634 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4637 if (!ISVISIBLE(item
))
4639 /* Expand parents as necessary. */
4642 /* see if we are trying to ensure that root is visible */
4643 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4644 parent
= item
->parent
;
4646 parent
= item
; /* this item is the topmost item */
4648 while (parent
!= infoPtr
->root
)
4650 if (!(parent
->state
& TVIS_EXPANDED
))
4651 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, TRUE
);
4653 parent
= parent
->parent
;
4657 viscount
= TREEVIEW_GetVisibleCount(infoPtr
);
4659 TRACE("%p (%s) %d - %d viscount(%d)\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4660 hasFirstVisible
? infoPtr
->firstVisible
->visibleOrder
: -1, viscount
);
4662 if (hasFirstVisible
)
4663 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4665 if (visible_pos
< 0)
4667 /* item is before the start of the list: put it at the top. */
4668 newFirstVisible
= item
;
4670 else if (visible_pos
>= viscount
4671 /* Sometimes, before we are displayed, GVC is 0, causing us to
4672 * spuriously scroll up. */
4673 && visible_pos
> 0 && !(infoPtr
->dwStyle
& TVS_NOSCROLL
) )
4675 /* item is past the end of the list. */
4676 int scroll
= visible_pos
- viscount
;
4678 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4684 /* Scroll window so item's text is visible as much as possible */
4685 /* Calculation of amount of extra space is taken from EditLabel code */
4687 TEXTMETRICW textMetric
;
4688 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4690 x
= item
->textWidth
;
4692 GetTextMetricsW(hdc
, &textMetric
);
4693 ReleaseDC(infoPtr
->hwnd
, hdc
);
4695 x
+= (textMetric
.tmMaxCharWidth
* 2);
4696 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4698 if (item
->textOffset
< 0)
4699 pos
= item
->textOffset
;
4700 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4702 if (x
> infoPtr
->clientWidth
)
4703 pos
= item
->textOffset
;
4705 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4710 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4713 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4715 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4724 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4725 TREEVIEW_ITEM
*newFirstVisible
,
4726 BOOL bUpdateScrollPos
)
4730 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4732 if (newFirstVisible
!= NULL
)
4734 /* Prevent an empty gap from appearing at the bottom... */
4735 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4736 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4740 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4743 /* ... unless we just don't have enough items. */
4744 if (newFirstVisible
== NULL
)
4745 newFirstVisible
= infoPtr
->root
->firstChild
;
4749 if (infoPtr
->firstVisible
!= newFirstVisible
)
4751 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4753 infoPtr
->firstVisible
= newFirstVisible
;
4754 TREEVIEW_Invalidate(infoPtr
, NULL
);
4758 TREEVIEW_ITEM
*item
;
4759 int scroll
= infoPtr
->uItemHeight
*
4760 (infoPtr
->firstVisible
->visibleOrder
4761 - newFirstVisible
->visibleOrder
);
4763 infoPtr
->firstVisible
= newFirstVisible
;
4765 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4766 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4768 item
->rect
.top
+= scroll
;
4769 item
->rect
.bottom
+= scroll
;
4772 if (bUpdateScrollPos
)
4773 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4774 newFirstVisible
->visibleOrder
, TRUE
);
4776 ScrollWindowEx(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
, NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
4781 /************************************************************************
4782 * VScroll is always in units of visible items. i.e. we always have a
4783 * visible item aligned to the top of the control. (Unless we have no
4787 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4789 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4790 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4792 int nScrollCode
= LOWORD(wParam
);
4794 TRACE("wp %lx\n", wParam
);
4796 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4799 if (!oldFirstVisible
)
4801 assert(infoPtr
->root
->firstChild
== NULL
);
4805 switch (nScrollCode
)
4808 newFirstVisible
= infoPtr
->root
->firstChild
;
4812 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4816 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4820 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4824 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4825 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4829 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4830 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4834 case SB_THUMBPOSITION
:
4835 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4836 infoPtr
->root
->firstChild
,
4837 (LONG
)(SHORT
)HIWORD(wParam
));
4844 if (newFirstVisible
!= NULL
)
4846 if (newFirstVisible
!= oldFirstVisible
)
4847 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4848 nScrollCode
!= SB_THUMBTRACK
);
4849 else if (nScrollCode
== SB_THUMBPOSITION
)
4850 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4851 newFirstVisible
->visibleOrder
, TRUE
);
4858 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4861 int scrollX
= infoPtr
->scrollX
;
4862 int nScrollCode
= LOWORD(wParam
);
4864 TRACE("wp %lx\n", wParam
);
4866 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4869 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4870 /* shall never occur */
4877 switch (nScrollCode
)
4880 scrollX
-= infoPtr
->uItemHeight
;
4883 scrollX
+= infoPtr
->uItemHeight
;
4886 scrollX
-= infoPtr
->clientWidth
;
4889 scrollX
+= infoPtr
->clientWidth
;
4893 case SB_THUMBPOSITION
:
4894 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4901 if (scrollX
> maxWidth
)
4903 else if (scrollX
< 0)
4907 if (scrollX
!= infoPtr
->scrollX
)
4909 TREEVIEW_ITEM
*item
;
4910 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4912 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4913 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4915 item
->linesOffset
+= scroll_pixels
;
4916 item
->stateOffset
+= scroll_pixels
;
4917 item
->imageOffset
+= scroll_pixels
;
4918 item
->textOffset
+= scroll_pixels
;
4921 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4922 infoPtr
->scrollX
= scrollX
;
4923 UpdateWindow(infoPtr
->hwnd
);
4926 if (nScrollCode
!= SB_THUMBTRACK
)
4927 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
4933 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4936 UINT pulScrollLines
= 3;
4938 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4939 return DefWindowProcW(infoPtr
->hwnd
, WM_MOUSEWHEEL
, wParam
, lParam
);
4941 if (infoPtr
->firstVisible
== NULL
)
4944 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
4946 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4947 /* if scrolling changes direction, ignore left overs */
4948 if ((wheelDelta
< 0 && infoPtr
->wheelRemainder
< 0) ||
4949 (wheelDelta
> 0 && infoPtr
->wheelRemainder
> 0))
4950 infoPtr
->wheelRemainder
+= wheelDelta
;
4952 infoPtr
->wheelRemainder
= wheelDelta
;
4954 if (infoPtr
->wheelRemainder
&& pulScrollLines
)
4960 lineScroll
= pulScrollLines
* (float)infoPtr
->wheelRemainder
/ WHEEL_DELTA
;
4961 infoPtr
->wheelRemainder
-= WHEEL_DELTA
* lineScroll
/ (int)pulScrollLines
;
4963 newDy
= infoPtr
->firstVisible
->visibleOrder
- lineScroll
;
4964 maxDy
= infoPtr
->maxVisibleOrder
;
4972 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
4977 /* Create/Destroy *******************************************************/
4980 TREEVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
4983 TREEVIEW_INFO
*infoPtr
;
4986 TRACE("wnd %p, style %x\n", hwnd
, GetWindowLongW(hwnd
, GWL_STYLE
));
4988 infoPtr
= Alloc(sizeof(TREEVIEW_INFO
));
4990 if (infoPtr
== NULL
)
4992 ERR("could not allocate info memory!\n");
4996 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
4998 infoPtr
->hwnd
= hwnd
;
4999 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5001 infoPtr
->uNumItems
= 0;
5002 infoPtr
->cdmode
= 0;
5003 infoPtr
->uScrollTime
= 300; /* milliseconds */
5004 infoPtr
->bRedraw
= TRUE
;
5006 GetClientRect(hwnd
, &rcClient
);
5008 /* No scroll bars yet. */
5009 infoPtr
->clientWidth
= rcClient
.right
;
5010 infoPtr
->clientHeight
= rcClient
.bottom
;
5011 infoPtr
->uInternalStatus
= 0;
5013 infoPtr
->treeWidth
= 0;
5014 infoPtr
->treeHeight
= 0;
5016 infoPtr
->uIndent
= MINIMUM_INDENT
;
5017 infoPtr
->selectedItem
= NULL
;
5018 infoPtr
->focusedItem
= NULL
;
5019 infoPtr
->hotItem
= NULL
;
5020 infoPtr
->editItem
= NULL
;
5021 infoPtr
->firstVisible
= NULL
;
5022 infoPtr
->maxVisibleOrder
= 0;
5023 infoPtr
->dropItem
= NULL
;
5024 infoPtr
->insertMarkItem
= NULL
;
5025 infoPtr
->insertBeforeorAfter
= 0;
5028 infoPtr
->scrollX
= 0;
5029 infoPtr
->wheelRemainder
= 0;
5031 infoPtr
->clrBk
= CLR_NONE
; /* use system color */
5032 infoPtr
->clrText
= CLR_NONE
; /* use system color */
5033 infoPtr
->clrLine
= CLR_DEFAULT
;
5034 infoPtr
->clrInsertMark
= CLR_DEFAULT
;
5038 infoPtr
->hwndEdit
= NULL
;
5039 infoPtr
->wpEditOrig
= NULL
;
5040 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
5041 infoPtr
->bLabelChanged
= FALSE
;
5043 infoPtr
->himlNormal
= NULL
;
5044 infoPtr
->himlState
= NULL
;
5045 infoPtr
->normalImageWidth
= 0;
5046 infoPtr
->normalImageHeight
= 0;
5047 infoPtr
->stateImageWidth
= 0;
5048 infoPtr
->stateImageHeight
= 0;
5050 infoPtr
->items
= DPA_Create(16);
5052 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
5053 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW(&lf
);
5054 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
5055 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
5056 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
5057 infoPtr
->hcurHand
= LoadCursorW(NULL
, (LPWSTR
)IDC_HAND
);
5059 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
5061 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
5062 infoPtr
->root
->state
= TVIS_EXPANDED
;
5063 infoPtr
->root
->iLevel
= -1;
5064 infoPtr
->root
->visibleOrder
= -1;
5066 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5067 infoPtr
->hwndToolTip
= 0;
5069 /* Determine what type of notify should be issued (sets infoPtr->bNtfUnicode) */
5070 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
5072 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
5073 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
5074 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
5077 /* Make sure actual scrollbar state is consistent with uInternalStatus */
5078 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
5079 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
5081 OpenThemeData (hwnd
, themeClass
);
5088 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
5092 /* free item data */
5093 TREEVIEW_RemoveTree(infoPtr
);
5094 /* root isn't freed with other items */
5095 TREEVIEW_FreeItem(infoPtr
, infoPtr
->root
);
5096 DPA_Destroy(infoPtr
->items
);
5098 /* tool tip is automatically destroyed: we are its owner */
5100 /* Restore original wndproc */
5101 if (infoPtr
->hwndEdit
)
5102 SetWindowLongPtrW(infoPtr
->hwndEdit
, GWLP_WNDPROC
,
5103 (DWORD_PTR
)infoPtr
->wpEditOrig
);
5105 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
5107 /* Deassociate treeview from the window before doing anything drastic. */
5108 SetWindowLongPtrW(infoPtr
->hwnd
, 0, 0);
5110 DeleteObject(infoPtr
->hDefaultFont
);
5111 DeleteObject(infoPtr
->hBoldFont
);
5112 DeleteObject(infoPtr
->hUnderlineFont
);
5113 DeleteObject(infoPtr
->hBoldUnderlineFont
);
5119 /* Miscellaneous Messages ***********************************************/
5122 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
5130 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
5131 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
5132 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
5133 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
5134 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
5135 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
5136 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
5137 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
5138 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
5142 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
5144 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
5146 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
5148 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
5154 /************************************************************************
5157 * VK_UP Move selection to the previous non-hidden item.
5158 * VK_DOWN Move selection to the next non-hidden item.
5159 * VK_HOME Move selection to the first item.
5160 * VK_END Move selection to the last item.
5161 * VK_LEFT If expanded then collapse, otherwise move to parent.
5162 * VK_RIGHT If collapsed then expand, otherwise move to first child.
5164 * VK_SUBTRACT Collapse.
5165 * VK_MULTIPLY Expand all.
5166 * VK_PRIOR Move up GetVisibleCount items.
5167 * VK_NEXT Move down GetVisibleCount items.
5168 * VK_BACK Move to parent.
5169 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
5172 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
5174 /* If it is non-NULL and different, it will be selected and visible. */
5175 TREEVIEW_ITEM
*newSelection
= NULL
;
5176 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
5177 NMTVKEYDOWN nmkeydown
;
5179 TRACE("%lx\n", wParam
);
5181 nmkeydown
.wVKey
= wParam
;
5182 nmkeydown
.flags
= 0;
5183 TREEVIEW_SendRealNotify(infoPtr
, TVN_KEYDOWN
, &nmkeydown
.hdr
);
5185 if (prevItem
== NULL
)
5188 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
5189 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
5194 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
5196 newSelection
= infoPtr
->root
->firstChild
;
5200 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
5204 TREEVIEW_SendSimpleNotify(infoPtr
, NM_RETURN
);
5208 newSelection
= infoPtr
->root
->firstChild
;
5212 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
5216 if (prevItem
->state
& TVIS_EXPANDED
)
5218 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5220 else if (prevItem
->parent
!= infoPtr
->root
)
5222 newSelection
= prevItem
->parent
;
5227 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
5229 if (!(prevItem
->state
& TVIS_EXPANDED
))
5230 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5233 newSelection
= prevItem
->firstChild
;
5240 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5244 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5248 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5253 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5254 -TREEVIEW_GetVisibleCount(infoPtr
));
5259 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5260 TREEVIEW_GetVisibleCount(infoPtr
));
5264 newSelection
= prevItem
->parent
;
5265 if (newSelection
== infoPtr
->root
)
5266 newSelection
= NULL
;
5270 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5271 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5275 if (newSelection
&& newSelection
!= prevItem
)
5277 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5280 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5288 TREEVIEW_MouseLeave (TREEVIEW_INFO
* infoPtr
)
5290 /* remove hot effect from item */
5291 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5292 infoPtr
->hotItem
= NULL
;
5298 TREEVIEW_MouseMove (TREEVIEW_INFO
* infoPtr
, LPARAM lParam
)
5301 TRACKMOUSEEVENT trackinfo
;
5302 TREEVIEW_ITEM
* item
;
5304 if (!(infoPtr
->dwStyle
& TVS_TRACKSELECT
)) return 0;
5306 /* fill in the TRACKMOUSEEVENT struct */
5307 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5308 trackinfo
.dwFlags
= TME_QUERY
;
5309 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5311 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5312 _TrackMouseEvent(&trackinfo
);
5314 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5315 if(!(trackinfo
.dwFlags
& TME_LEAVE
))
5317 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5318 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5319 /* do it as fast as possible, minimal systimer latency will be used */
5320 trackinfo
.dwHoverTime
= 1;
5322 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5323 /* and can properly deactivate the hot item */
5324 _TrackMouseEvent(&trackinfo
);
5327 pt
.x
= (short)LOWORD(lParam
);
5328 pt
.y
= (short)HIWORD(lParam
);
5330 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5332 if (item
!= infoPtr
->hotItem
)
5334 /* redraw old hot item */
5335 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5336 infoPtr
->hotItem
= item
;
5337 /* redraw new hot item */
5338 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5344 /* Draw themed border */
5345 static BOOL
TREEVIEW_NCPaint (const TREEVIEW_INFO
*infoPtr
, HRGN region
, LPARAM lParam
)
5347 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5351 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
5352 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
5355 return DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)region
, lParam
);
5357 GetWindowRect(infoPtr
->hwnd
, &r
);
5359 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
5360 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
5361 if (region
!= (HRGN
)1)
5362 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
5363 OffsetRect(&r
, -r
.left
, -r
.top
);
5365 dc
= GetDCEx(infoPtr
->hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
5366 OffsetRect(&r
, -r
.left
, -r
.top
);
5368 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
5369 DrawThemeParentBackground(infoPtr
->hwnd
, dc
, &r
);
5370 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
5371 ReleaseDC(infoPtr
->hwnd
, dc
);
5373 /* Call default proc to get the scrollbars etc. painted */
5374 DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
5380 TREEVIEW_Notify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5382 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5384 if (lpnmh
->code
== PGN_CALCSIZE
) {
5385 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5387 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5388 lppgc
->iWidth
= infoPtr
->treeWidth
;
5389 TRACE("got PGN_CALCSIZE, returning horz size = %d, client=%d\n",
5390 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5393 lppgc
->iHeight
= infoPtr
->treeHeight
;
5394 TRACE("got PGN_CALCSIZE, returning vert size = %d, client=%d\n",
5395 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5399 return DefWindowProcW(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5403 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5405 if (wParam
== SIZE_RESTORED
)
5407 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5408 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5410 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5411 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5412 TREEVIEW_UpdateScrollBars(infoPtr
);
5416 FIXME("WM_SIZE flag %lx %lx not handled\n", wParam
, lParam
);
5419 TREEVIEW_Invalidate(infoPtr
, NULL
);
5424 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5426 TRACE("(%lx %lx)\n", wParam
, lParam
);
5428 if (wParam
== GWL_STYLE
)
5430 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5432 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_CHECKBOXES
)
5434 if (dwNewStyle
& TVS_CHECKBOXES
)
5436 TREEVIEW_InitCheckboxes(infoPtr
);
5437 TRACE("checkboxes enabled\n");
5439 /* set all items to state image index 1 */
5440 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
5444 FIXME("tried to disable checkboxes\n");
5448 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5450 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5452 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5453 TRACE("tooltips enabled\n");
5457 DestroyWindow(infoPtr
->hwndToolTip
);
5458 infoPtr
->hwndToolTip
= 0;
5459 TRACE("tooltips disabled\n");
5463 infoPtr
->dwStyle
= dwNewStyle
;
5466 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
5467 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5468 TREEVIEW_UpdateScrollBars(infoPtr
);
5469 TREEVIEW_Invalidate(infoPtr
, NULL
);
5475 TREEVIEW_SetCursor(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5478 TREEVIEW_ITEM
* item
;
5482 ScreenToClient(infoPtr
->hwnd
, &pt
);
5484 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5486 memset(&nmmouse
, 0, sizeof(nmmouse
));
5489 nmmouse
.dwItemSpec
= (DWORD_PTR
)item
;
5490 nmmouse
.dwItemData
= item
->lParam
;
5494 nmmouse
.dwHitInfo
= lParam
;
5495 if (TREEVIEW_SendRealNotify(infoPtr
, NM_SETCURSOR
, &nmmouse
.hdr
))
5498 if (item
&& (infoPtr
->dwStyle
& TVS_TRACKSELECT
))
5500 SetCursor(infoPtr
->hcurHand
);
5504 return DefWindowProcW(infoPtr
->hwnd
, WM_SETCURSOR
, wParam
, lParam
);
5508 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5512 if (!infoPtr
->selectedItem
)
5514 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5518 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5519 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5524 TREEVIEW_KillFocus(const TREEVIEW_INFO
*infoPtr
)
5528 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5529 UpdateWindow(infoPtr
->hwnd
);
5530 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5534 /* update theme after a WM_THEMECHANGED message */
5535 static LRESULT
TREEVIEW_ThemeChanged(const TREEVIEW_INFO
*infoPtr
)
5537 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5538 CloseThemeData (theme
);
5539 OpenThemeData (infoPtr
->hwnd
, themeClass
);
5544 static LRESULT WINAPI
5545 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5547 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5549 TRACE("hwnd %p msg %04x wp=%08lx lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5551 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5554 if (uMsg
== WM_CREATE
)
5555 TREEVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
5562 case TVM_CREATEDRAGIMAGE
:
5563 return TREEVIEW_CreateDragImage(infoPtr
, lParam
);
5565 case TVM_DELETEITEM
:
5566 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5568 case TVM_EDITLABELA
:
5569 case TVM_EDITLABELW
:
5570 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5572 case TVM_ENDEDITLABELNOW
:
5573 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5575 case TVM_ENSUREVISIBLE
:
5576 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5579 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5581 case TVM_GETBKCOLOR
:
5582 return TREEVIEW_GetBkColor(infoPtr
);
5585 return TREEVIEW_GetCount(infoPtr
);
5587 case TVM_GETEDITCONTROL
:
5588 return TREEVIEW_GetEditControl(infoPtr
);
5590 case TVM_GETIMAGELIST
:
5591 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5594 return TREEVIEW_GetIndent(infoPtr
);
5596 case TVM_GETINSERTMARKCOLOR
:
5597 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5599 case TVM_GETISEARCHSTRINGA
:
5600 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5603 case TVM_GETISEARCHSTRINGW
:
5604 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5609 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5610 uMsg
== TVM_GETITEMW
);
5611 case TVM_GETITEMHEIGHT
:
5612 return TREEVIEW_GetItemHeight(infoPtr
);
5614 case TVM_GETITEMRECT
:
5615 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5617 case TVM_GETITEMSTATE
:
5618 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5620 case TVM_GETLINECOLOR
:
5621 return TREEVIEW_GetLineColor(infoPtr
);
5623 case TVM_GETNEXTITEM
:
5624 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5626 case TVM_GETSCROLLTIME
:
5627 return TREEVIEW_GetScrollTime(infoPtr
);
5629 case TVM_GETTEXTCOLOR
:
5630 return TREEVIEW_GetTextColor(infoPtr
);
5632 case TVM_GETTOOLTIPS
:
5633 return TREEVIEW_GetToolTips(infoPtr
);
5635 case TVM_GETUNICODEFORMAT
:
5636 return TREEVIEW_GetUnicodeFormat(infoPtr
);
5638 case TVM_GETVISIBLECOUNT
:
5639 return TREEVIEW_GetVisibleCount(infoPtr
);
5642 return TREEVIEW_HitTest(infoPtr
, (LPTVHITTESTINFO
)lParam
);
5644 case TVM_INSERTITEMA
:
5645 case TVM_INSERTITEMW
:
5646 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
,
5647 uMsg
== TVM_INSERTITEMW
);
5648 case TVM_SELECTITEM
:
5649 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5651 case TVM_SETBKCOLOR
:
5652 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5654 case TVM_SETIMAGELIST
:
5655 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5658 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5660 case TVM_SETINSERTMARK
:
5661 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5663 case TVM_SETINSERTMARKCOLOR
:
5664 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5668 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5669 uMsg
== TVM_SETITEMW
);
5670 case TVM_SETLINECOLOR
:
5671 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5673 case TVM_SETITEMHEIGHT
:
5674 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5676 case TVM_SETSCROLLTIME
:
5677 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5679 case TVM_SETTEXTCOLOR
:
5680 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5682 case TVM_SETTOOLTIPS
:
5683 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5685 case TVM_SETUNICODEFORMAT
:
5686 return TREEVIEW_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
5688 case TVM_SORTCHILDREN
:
5689 return TREEVIEW_SortChildren(infoPtr
, lParam
);
5691 case TVM_SORTCHILDRENCB
:
5692 return TREEVIEW_SortChildrenCB(infoPtr
, (LPTVSORTCB
)lParam
);
5695 return TREEVIEW_ProcessLetterKeys(infoPtr
, wParam
, lParam
);
5698 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5701 return TREEVIEW_Destroy(infoPtr
);
5706 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5709 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5712 return TREEVIEW_GetFont(infoPtr
);
5715 return TREEVIEW_HScroll(infoPtr
, wParam
);
5718 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5721 return TREEVIEW_KillFocus(infoPtr
);
5723 case WM_LBUTTONDBLCLK
:
5724 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5726 case WM_LBUTTONDOWN
:
5727 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5729 /* WM_MBUTTONDOWN */
5732 return TREEVIEW_MouseLeave(infoPtr
);
5735 return TREEVIEW_MouseMove(infoPtr
, lParam
);
5737 case WM_NCLBUTTONDOWN
:
5738 if (infoPtr
->hwndEdit
)
5739 SetFocus(infoPtr
->hwnd
);
5743 return TREEVIEW_NCPaint (infoPtr
, (HRGN
)wParam
, lParam
);
5746 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5748 case WM_NOTIFYFORMAT
:
5749 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5751 case WM_PRINTCLIENT
:
5752 return TREEVIEW_PrintClient(infoPtr
, (HDC
)wParam
, lParam
);
5755 return TREEVIEW_Paint(infoPtr
, (HDC
)wParam
);
5757 case WM_RBUTTONDOWN
:
5758 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5761 return TREEVIEW_SetCursor(infoPtr
, wParam
, lParam
);
5764 return TREEVIEW_SetFocus(infoPtr
);
5767 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5770 return TREEVIEW_SetRedraw(infoPtr
, wParam
);
5773 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5775 case WM_STYLECHANGED
:
5776 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5778 case WM_SYSCOLORCHANGE
:
5779 COMCTL32_RefreshSysColors();
5785 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5787 case WM_THEMECHANGED
:
5788 return TREEVIEW_ThemeChanged (infoPtr
);
5791 return TREEVIEW_VScroll(infoPtr
, wParam
);
5793 /* WM_WININICHANGE */
5796 return TREEVIEW_MouseWheel(infoPtr
, wParam
, lParam
);
5799 TRACE("drawItem\n");
5803 /* This mostly catches MFC and Delphi messages. :( */
5804 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
5805 TRACE("Unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
5807 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
5812 /* Class Registration ***************************************************/
5815 TREEVIEW_Register(void)
5821 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
5822 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5823 wndClass
.lpfnWndProc
= TREEVIEW_WindowProc
;
5824 wndClass
.cbClsExtra
= 0;
5825 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5827 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
5828 wndClass
.hbrBackground
= 0;
5829 wndClass
.lpszClassName
= WC_TREEVIEWW
;
5831 RegisterClassW(&wndClass
);
5836 TREEVIEW_Unregister(void)
5838 UnregisterClassW(WC_TREEVIEWW
, NULL
);
5842 /* Tree Verification ****************************************************/
5845 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
);
5847 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5848 const TREEVIEW_ITEM
*item
)
5850 assert(infoPtr
!= NULL
);
5851 assert(item
!= NULL
);
5853 /* both NULL, or both non-null */
5854 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5856 assert(item
->firstChild
!= item
);
5857 assert(item
->lastChild
!= item
);
5859 if (item
->firstChild
)
5861 assert(item
->firstChild
->parent
== item
);
5862 assert(item
->firstChild
->prevSibling
== NULL
);
5865 if (item
->lastChild
)
5867 assert(item
->lastChild
->parent
== item
);
5868 assert(item
->lastChild
->nextSibling
== NULL
);
5871 assert(item
->nextSibling
!= item
);
5872 if (item
->nextSibling
)
5874 assert(item
->nextSibling
->parent
== item
->parent
);
5875 assert(item
->nextSibling
->prevSibling
== item
);
5878 assert(item
->prevSibling
!= item
);
5879 if (item
->prevSibling
)
5881 assert(item
->prevSibling
->parent
== item
->parent
);
5882 assert(item
->prevSibling
->nextSibling
== item
);
5887 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5889 assert(item
!= NULL
);
5891 assert(item
->parent
!= NULL
);
5892 assert(item
->parent
!= item
);
5893 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5895 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5897 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5899 TREEVIEW_VerifyChildren(infoPtr
, item
);
5903 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5905 const TREEVIEW_ITEM
*child
;
5906 assert(item
!= NULL
);
5908 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5909 TREEVIEW_VerifyItem(infoPtr
, child
);
5913 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5915 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5917 assert(root
!= NULL
);
5918 assert(root
->iLevel
== -1);
5919 assert(root
->parent
== NULL
);
5920 assert(root
->prevSibling
== NULL
);
5922 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
5924 TREEVIEW_VerifyChildren(infoPtr
, root
);
5928 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
5930 if (!TRACE_ON(treeview
)) return;
5932 assert(infoPtr
!= NULL
);
5933 TREEVIEW_VerifyRoot(infoPtr
);