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 #include <wine/exception.h>
47 WINE_DEFAULT_DEBUG_CHANNEL(treeview
);
49 /* internal structures */
50 typedef struct tagTREEVIEW_INFO
53 HWND hwndNotify
; /* Owner window to send notifications to */
58 UINT uNumItems
; /* number of valid TREEVIEW_ITEMs */
59 INT cdmode
; /* last custom draw setting */
60 UINT uScrollTime
; /* max. time for scrolling in milliseconds */
61 BOOL bRedraw
; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
63 UINT uItemHeight
; /* item height */
66 LONG clientWidth
; /* width of control window */
67 LONG clientHeight
; /* height of control window */
69 LONG treeWidth
; /* width of visible tree items */
70 LONG treeHeight
; /* height of visible tree items */
72 UINT uIndent
; /* indentation in pixels */
73 HTREEITEM selectedItem
; /* handle to selected item or 0 if none */
74 HTREEITEM hotItem
; /* handle currently under cursor, 0 if none */
75 HTREEITEM focusedItem
; /* item that was under the cursor when WM_LBUTTONDOWN was received */
76 HTREEITEM editItem
; /* item being edited with builtin edit box */
78 HTREEITEM firstVisible
; /* handle to first visible item */
80 HTREEITEM dropItem
; /* handle to item selected by drag cursor */
81 HTREEITEM insertMarkItem
; /* item after which insertion mark is placed */
82 BOOL insertBeforeorAfter
; /* flag used by TVM_SETINSERTMARK */
83 HIMAGELIST dragList
; /* Bitmap of dragged item */
89 COLORREF clrInsertMark
;
94 HFONT hBoldUnderlineFont
;
99 WNDPROC wpEditOrig
; /* orig window proc for subclassing edit */
100 BOOL bIgnoreEditKillFocus
;
103 BOOL bNtfUnicode
; /* TRUE if should send NOTIFY with W */
104 HIMAGELIST himlNormal
;
105 int normalImageHeight
;
106 int normalImageWidth
;
107 HIMAGELIST himlState
;
108 int stateImageHeight
;
112 DWORD lastKeyPressTimestamp
;
114 INT nSearchParamLength
;
115 WCHAR szSearchParam
[ MAX_PATH
];
118 typedef struct _TREEITEM
/* HTREEITEM is a _TREEINFO *. */
120 HTREEITEM parent
; /* handle to parent or 0 if at root */
121 HTREEITEM nextSibling
; /* handle to next item in list, 0 if last */
122 HTREEITEM firstChild
; /* handle to first child or 0 if no child */
134 int iIntegral
; /* item height multiplier (1 is normal) */
135 int iLevel
; /* indentation level:0=root level */
137 HTREEITEM prevSibling
; /* handle to prev item in list, 0 if first */
143 LONG textWidth
; /* horizontal text extent for pszText */
144 LONG visibleOrder
; /* visible ordering, 0 is first visible item */
145 const TREEVIEW_INFO
*infoPtr
; /* tree data this item belongs to */
148 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
149 #define KEY_DELAY 450
151 /* bitflags for infoPtr->uInternalStatus */
153 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
154 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
155 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
156 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
157 #define TV_RDRAG 0x10 /* ditto Rbutton */
158 #define TV_RDRAGGING 0x20
160 /* bitflags for infoPtr->timer */
162 #define TV_EDIT_TIMER 2
163 #define TV_EDIT_TIMER_SET 2
165 #define TEXT_CALLBACK_SIZE 260
167 #define TREEVIEW_LEFT_MARGIN 8
169 #define MINIMUM_INDENT 19
171 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
173 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
174 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
175 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
177 #define GETLINECOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrGrayText : (x))
178 #define GETBKCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindow : (x))
179 #define GETTXTCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindowText : (x))
180 #define GETINSCOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrBtnText : (x))
182 static const WCHAR themeClass
[] = { 'T','r','e','e','v','i','e','w',0 };
185 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
188 static VOID
TREEVIEW_Invalidate(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
190 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
191 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
192 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
193 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
194 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
195 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
197 /* Random Utilities *****************************************************/
198 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
200 /* Returns the treeview private data if hwnd is a treeview.
201 * Otherwise returns an undefined value. */
202 static inline TREEVIEW_INFO
*
203 TREEVIEW_GetInfoPtr(HWND hwnd
)
205 return (TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
208 /* Don't call this. Nothing wants an item index. */
210 TREEVIEW_GetItemIndex(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
212 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
215 /* Checks if item has changed and needs to be redrawn */
216 static inline BOOL
item_changed (const TREEVIEW_ITEM
*tiOld
, const TREEVIEW_ITEM
*tiNew
,
217 const TVITEMEXW
*tvChange
)
219 /* Number of children has changed */
220 if ((tvChange
->mask
& TVIF_CHILDREN
) && (tiOld
->cChildren
!= tiNew
->cChildren
))
223 /* Image has changed and it's not a callback */
224 if ((tvChange
->mask
& TVIF_IMAGE
) && (tiOld
->iImage
!= tiNew
->iImage
) &&
225 tiNew
->iImage
!= I_IMAGECALLBACK
)
228 /* Selected image has changed and it's not a callback */
229 if ((tvChange
->mask
& TVIF_SELECTEDIMAGE
) && (tiOld
->iSelectedImage
!= tiNew
->iSelectedImage
) &&
230 tiNew
->iSelectedImage
!= I_IMAGECALLBACK
)
233 if ((tvChange
->mask
& TVIF_EXPANDEDIMAGE
) && (tiOld
->iExpandedImage
!= tiNew
->iExpandedImage
) &&
234 tiNew
->iExpandedImage
!= I_IMAGECALLBACK
)
237 /* Text has changed and it's not a callback */
238 if ((tvChange
->mask
& TVIF_TEXT
) && (tiOld
->pszText
!= tiNew
->pszText
) &&
239 tiNew
->pszText
!= LPSTR_TEXTCALLBACKW
)
242 /* Indent has changed */
243 if ((tvChange
->mask
& TVIF_INTEGRAL
) && (tiOld
->iIntegral
!= tiNew
->iIntegral
))
246 /* Item state has changed */
247 if ((tvChange
->mask
& TVIF_STATE
) && ((tiOld
->state
^ tiNew
->state
) & tvChange
->stateMask
))
253 /***************************************************************************
254 * This method checks that handle is an item for this tree.
257 TREEVIEW_ValidItem(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
259 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
261 TRACE("invalid item %p\n", handle
);
269 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
273 GetObjectW(hOrigFont
, sizeof(font
), &font
);
274 font
.lfWeight
= FW_BOLD
;
275 return CreateFontIndirectW(&font
);
279 TREEVIEW_CreateUnderlineFont(HFONT hOrigFont
)
283 GetObjectW(hOrigFont
, sizeof(font
), &font
);
284 font
.lfUnderline
= TRUE
;
285 return CreateFontIndirectW(&font
);
289 TREEVIEW_CreateBoldUnderlineFont(HFONT hfont
)
293 GetObjectW(hfont
, sizeof(font
), &font
);
294 font
.lfWeight
= FW_BOLD
;
295 font
.lfUnderline
= TRUE
;
296 return CreateFontIndirectW(&font
);
300 TREEVIEW_FontForItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
302 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
303 return item
->state
& TVIS_BOLD
? infoPtr
->hBoldUnderlineFont
: infoPtr
->hUnderlineFont
;
304 if (item
->state
& TVIS_BOLD
)
305 return infoPtr
->hBoldFont
;
306 return infoPtr
->hFont
;
309 /* for trace/debugging purposes only */
311 TREEVIEW_ItemName(const TREEVIEW_ITEM
*item
)
313 if (item
== NULL
) return "<null item>";
314 if (item
->pszText
== LPSTR_TEXTCALLBACKW
) return "<callback>";
315 if (item
->pszText
== NULL
) return "<null>";
316 return debugstr_w(item
->pszText
);
319 /* An item is not a child of itself. */
321 TREEVIEW_IsChildOf(const TREEVIEW_ITEM
*parent
, const TREEVIEW_ITEM
*child
)
325 child
= child
->parent
;
326 if (child
== parent
) return TRUE
;
327 } while (child
!= NULL
);
333 /* Tree Traversal *******************************************************/
335 /***************************************************************************
336 * This method returns the last expanded sibling or child child item
339 static TREEVIEW_ITEM
*
340 TREEVIEW_GetLastListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
342 if (!item
) return NULL
;
344 while (item
->lastChild
)
346 if (item
->state
& TVIS_EXPANDED
)
347 item
= item
->lastChild
;
352 if (item
== infoPtr
->root
)
358 /***************************************************************************
359 * This method returns the previous non-hidden item in the list not
360 * considering the tree hierarchy.
362 static TREEVIEW_ITEM
*
363 TREEVIEW_GetPrevListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
365 if (tvItem
->prevSibling
)
367 /* This item has a prevSibling, get the last item in the sibling's tree. */
368 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
370 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
371 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
377 /* this item does not have a prevSibling, get the parent */
378 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
383 /***************************************************************************
384 * This method returns the next physical item in the treeview not
385 * considering the tree hierarchy.
387 static TREEVIEW_ITEM
*
388 TREEVIEW_GetNextListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
391 * If this item has children and is expanded, return the first child
393 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
395 return tvItem
->firstChild
;
400 * try to get the sibling
402 if (tvItem
->nextSibling
)
403 return tvItem
->nextSibling
;
406 * Otherwise, get the parent's sibling.
408 while (tvItem
->parent
)
410 tvItem
= tvItem
->parent
;
412 if (tvItem
->nextSibling
)
413 return tvItem
->nextSibling
;
419 /***************************************************************************
420 * This method returns the nth item starting at the given item. It returns
421 * the last item (or first) we we run out of items.
423 * Will scroll backward if count is <0.
424 * forward if count is >0.
426 static TREEVIEW_ITEM
*
427 TREEVIEW_GetListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
430 TREEVIEW_ITEM
*(*next_item
)(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
431 TREEVIEW_ITEM
*previousItem
;
433 assert(item
!= NULL
);
437 next_item
= TREEVIEW_GetNextListItem
;
442 next_item
= TREEVIEW_GetPrevListItem
;
450 item
= next_item(infoPtr
, item
);
452 } while (--count
&& item
!= NULL
);
455 return item
? item
: previousItem
;
458 /* Notifications ************************************************************/
460 static INT
get_notifycode(const TREEVIEW_INFO
*infoPtr
, INT code
)
462 if (!infoPtr
->bNtfUnicode
) {
464 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
465 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
466 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
467 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
468 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
469 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
470 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
471 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
472 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
473 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
474 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
475 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
482 TREEVIEW_SendRealNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, NMHDR
*hdr
)
484 TRACE("code=%d, hdr=%p\n", code
, hdr
);
486 hdr
->hwndFrom
= infoPtr
->hwnd
;
487 hdr
->idFrom
= GetWindowLongPtrW(infoPtr
->hwnd
, GWLP_ID
);
488 hdr
->code
= get_notifycode(infoPtr
, code
);
490 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, hdr
->idFrom
, (LPARAM
)hdr
);
494 TREEVIEW_SendSimpleNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
)
497 return TREEVIEW_SendRealNotify(infoPtr
, code
, &hdr
);
501 TREEVIEW_TVItemFromItem(const TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMW
*tvItem
, TREEVIEW_ITEM
*item
)
504 tvItem
->hItem
= item
;
505 tvItem
->state
= item
->state
;
506 tvItem
->stateMask
= 0;
507 tvItem
->iImage
= item
->iImage
;
508 tvItem
->iSelectedImage
= item
->iSelectedImage
;
509 tvItem
->cChildren
= item
->cChildren
;
510 tvItem
->lParam
= item
->lParam
;
514 if (!infoPtr
->bNtfUnicode
)
516 tvItem
->cchTextMax
= WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0, NULL
, NULL
);
517 tvItem
->pszText
= Alloc (tvItem
->cchTextMax
);
518 WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, 0, 0 );
522 tvItem
->cchTextMax
= item
->cchTextMax
;
523 tvItem
->pszText
= item
->pszText
;
528 tvItem
->cchTextMax
= 0;
529 tvItem
->pszText
= NULL
;
534 TREEVIEW_SendTreeviewNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
535 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
540 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
541 code
, action
, oldItem
, newItem
);
543 memset(&nmhdr
, 0, sizeof(NMTREEVIEWW
));
544 nmhdr
.action
= action
;
547 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
550 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
555 ret
= TREEVIEW_SendRealNotify(infoPtr
, code
, &nmhdr
.hdr
);
556 if (!infoPtr
->bNtfUnicode
)
558 Free(nmhdr
.itemOld
.pszText
);
559 Free(nmhdr
.itemNew
.pszText
);
565 TREEVIEW_SendTreeviewDnDNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
,
566 HTREEITEM dragItem
, POINT pt
)
570 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
573 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
574 nmhdr
.itemNew
.hItem
= dragItem
;
575 nmhdr
.itemNew
.state
= dragItem
->state
;
576 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
578 nmhdr
.ptDrag
.x
= pt
.x
;
579 nmhdr
.ptDrag
.y
= pt
.y
;
581 return TREEVIEW_SendRealNotify(infoPtr
, code
, &nmhdr
.hdr
);
586 TREEVIEW_SendCustomDrawNotify(const TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
589 NMTVCUSTOMDRAW nmcdhdr
;
592 TRACE("drawstage:%x hdc:%p\n", dwDrawStage
, hdc
);
594 nmcd
= &nmcdhdr
.nmcd
;
595 nmcd
->dwDrawStage
= dwDrawStage
;
598 nmcd
->dwItemSpec
= 0;
599 nmcd
->uItemState
= 0;
600 nmcd
->lItemlParam
= 0;
601 nmcdhdr
.clrText
= infoPtr
->clrText
;
602 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
605 return TREEVIEW_SendRealNotify(infoPtr
, NM_CUSTOMDRAW
, &nmcdhdr
.nmcd
.hdr
);
608 /* FIXME: need to find out when the flags in uItemState need to be set */
611 TREEVIEW_SendCustomDrawItemNotify(const TREEVIEW_INFO
*infoPtr
, HDC hdc
,
612 TREEVIEW_ITEM
*item
, UINT uItemDrawState
,
613 NMTVCUSTOMDRAW
*nmcdhdr
)
617 DWORD_PTR dwItemSpec
;
620 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
621 dwItemSpec
= (DWORD_PTR
)item
;
623 if (item
->state
& TVIS_SELECTED
)
624 uItemState
|= CDIS_SELECTED
;
625 if (item
== infoPtr
->selectedItem
)
626 uItemState
|= CDIS_FOCUS
;
627 if (item
== infoPtr
->hotItem
)
628 uItemState
|= CDIS_HOT
;
630 nmcd
= &nmcdhdr
->nmcd
;
631 nmcd
->dwDrawStage
= dwDrawStage
;
633 nmcd
->rc
= item
->rect
;
634 nmcd
->dwItemSpec
= dwItemSpec
;
635 nmcd
->uItemState
= uItemState
;
636 nmcd
->lItemlParam
= item
->lParam
;
637 nmcdhdr
->iLevel
= item
->iLevel
;
639 TRACE("drawstage:%x hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
640 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
641 nmcd
->uItemState
, nmcd
->lItemlParam
);
643 return TREEVIEW_SendRealNotify(infoPtr
, NM_CUSTOMDRAW
, &nmcdhdr
->nmcd
.hdr
);
647 TREEVIEW_BeginLabelEditNotify(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
652 TREEVIEW_TVItemFromItem(infoPtr
, TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
,
653 &tvdi
.item
, editItem
);
655 ret
= TREEVIEW_SendRealNotify(infoPtr
, TVN_BEGINLABELEDITW
, &tvdi
.hdr
);
657 if (!infoPtr
->bNtfUnicode
)
658 Free(tvdi
.item
.pszText
);
664 TREEVIEW_UpdateDispInfo(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
667 NMTVDISPINFOEXW callback
;
669 TRACE("mask=0x%x, callbackmask=0x%x\n", mask
, item
->callbackMask
);
670 mask
&= item
->callbackMask
;
672 if (mask
== 0) return;
674 /* 'state' always contains valid value, as well as 'lParam'.
675 * All other parameters are uninitialized.
677 callback
.item
.pszText
= item
->pszText
;
678 callback
.item
.cchTextMax
= item
->cchTextMax
;
679 callback
.item
.mask
= mask
;
680 callback
.item
.hItem
= item
;
681 callback
.item
.state
= item
->state
;
682 callback
.item
.lParam
= item
->lParam
;
684 /* If text is changed we need to recalculate textWidth */
685 if (mask
& TVIF_TEXT
)
688 TREEVIEW_SendRealNotify(infoPtr
, TVN_GETDISPINFOW
, &callback
.hdr
);
689 TRACE("resulting code 0x%08x\n", callback
.hdr
.code
);
691 /* It may have changed due to a call to SetItem. */
692 mask
&= item
->callbackMask
;
694 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= item
->pszText
)
696 /* Instead of copying text into our buffer user specified his own */
697 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
700 int len
= MultiByteToWideChar( CP_ACP
, 0,
701 (LPSTR
)callback
.item
.pszText
, -1,
703 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
704 newText
= ReAlloc(item
->pszText
, buflen
);
706 TRACE("returned str %s, len=%d, buflen=%d\n",
707 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
711 item
->pszText
= newText
;
712 MultiByteToWideChar( CP_ACP
, 0,
713 (LPSTR
)callback
.item
.pszText
, -1,
714 item
->pszText
, buflen
/sizeof(WCHAR
));
715 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
717 /* If ReAlloc fails we have nothing to do, but keep original text */
720 int len
= max(lstrlenW(callback
.item
.pszText
) + 1,
722 LPWSTR newText
= ReAlloc(item
->pszText
, len
);
724 TRACE("returned wstr %s, len=%d\n",
725 debugstr_w(callback
.item
.pszText
), len
);
729 item
->pszText
= newText
;
730 strcpyW(item
->pszText
, callback
.item
.pszText
);
731 item
->cchTextMax
= len
;
733 /* If ReAlloc fails we have nothing to do, but keep original text */
736 else if (mask
& TVIF_TEXT
) {
737 /* User put text into our buffer, that is ok unless A string */
738 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
741 int len
= MultiByteToWideChar( CP_ACP
, 0,
742 (LPSTR
)callback
.item
.pszText
, -1,
744 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
745 newText
= Alloc(buflen
);
747 TRACE("same buffer str %s, len=%d, buflen=%d\n",
748 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
752 LPWSTR oldText
= item
->pszText
;
753 item
->pszText
= newText
;
754 MultiByteToWideChar( CP_ACP
, 0,
755 (LPSTR
)callback
.item
.pszText
, -1,
756 item
->pszText
, buflen
/sizeof(WCHAR
));
757 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
763 if (mask
& TVIF_IMAGE
)
764 item
->iImage
= callback
.item
.iImage
;
766 if (mask
& TVIF_SELECTEDIMAGE
)
767 item
->iSelectedImage
= callback
.item
.iSelectedImage
;
769 if (mask
& TVIF_EXPANDEDIMAGE
)
770 item
->iExpandedImage
= callback
.item
.iExpandedImage
;
772 if (mask
& TVIF_CHILDREN
)
773 item
->cChildren
= callback
.item
.cChildren
;
775 if (callback
.item
.mask
& TVIF_STATE
)
777 item
->state
&= ~callback
.item
.stateMask
;
778 item
->state
|= (callback
.item
.state
& callback
.item
.stateMask
);
781 /* These members are now permanently set. */
782 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
783 item
->callbackMask
&= ~callback
.item
.mask
;
786 /***************************************************************************
787 * This function uses cChildren field to decide whether the item has
789 * Note: if this returns TRUE, the child items may not actually exist,
790 * they could be virtual.
792 * Just use item->firstChild to check for physical children.
795 TREEVIEW_HasChildren(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
797 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_CHILDREN
);
799 return item
->cChildren
> 0;
802 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
806 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
808 if (nCommand
!= NF_REQUERY
) return 0;
810 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
811 TRACE("format=%d\n", format
);
813 /* Invalid format returned by NF_QUERY defaults to ANSI*/
814 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
)
817 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
822 /* Item Position ********************************************************/
824 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
826 TREEVIEW_ComputeItemInternalMetrics(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
828 /* has TVS_LINESATROOT and (TVS_HASLINES|TVS_HASBUTTONS) */
829 BOOL lar
= ((infoPtr
->dwStyle
& (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
832 item
->linesOffset
= infoPtr
->uIndent
* (lar
? item
->iLevel
: item
->iLevel
- 1)
834 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
835 item
->imageOffset
= item
->stateOffset
836 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
837 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
841 TREEVIEW_ComputeTextWidth(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
847 /* DRAW's OM docker creates items like this */
848 if (item
->pszText
== NULL
)
860 hdc
= GetDC(infoPtr
->hwnd
);
861 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
864 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
865 item
->textWidth
= sz
.cx
;
869 SelectObject(hdc
, hOldFont
);
875 TREEVIEW_ComputeItemRect(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
877 item
->rect
.top
= infoPtr
->uItemHeight
*
878 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
880 item
->rect
.bottom
= item
->rect
.top
881 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
884 item
->rect
.right
= infoPtr
->clientWidth
;
887 /* We know that only items after start need their order updated. */
889 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
896 start
= infoPtr
->root
->firstChild
;
900 order
= start
->visibleOrder
;
902 for (item
= start
; item
!= NULL
;
903 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
905 if (!ISVISIBLE(item
) && order
> 0)
906 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
907 item
->visibleOrder
= order
;
908 order
+= item
->iIntegral
;
911 infoPtr
->maxVisibleOrder
= order
;
913 for (item
= start
; item
!= NULL
;
914 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
916 TREEVIEW_ComputeItemRect(infoPtr
, item
);
921 /* Update metrics of all items in selected subtree.
922 * root must be expanded
925 TREEVIEW_UpdateSubTree(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
927 TREEVIEW_ITEM
*sibling
;
931 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
934 root
->state
&= ~TVIS_EXPANDED
;
935 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
936 root
->state
|= TVIS_EXPANDED
;
938 hdc
= GetDC(infoPtr
->hwnd
);
939 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
941 for (; root
!= sibling
;
942 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
944 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
946 if (root
->callbackMask
& TVIF_TEXT
)
947 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
949 if (root
->textWidth
== 0)
951 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
952 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
956 SelectObject(hdc
, hOldFont
);
957 ReleaseDC(infoPtr
->hwnd
, hdc
);
960 /* Item Allocation **********************************************************/
962 static TREEVIEW_ITEM
*
963 TREEVIEW_AllocateItem(const TREEVIEW_INFO
*infoPtr
)
965 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
970 /* I_IMAGENONE would make more sense but this is neither what is
971 * documented (MSDN doesn't specify) nor what Windows actually does
972 * (it sets it to zero)... and I can so imagine an application using
973 * inc/dec to toggle the images. */
975 newItem
->iSelectedImage
= 0;
976 newItem
->iExpandedImage
= (WORD
)I_IMAGENONE
;
977 newItem
->infoPtr
= infoPtr
;
979 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
988 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
989 * free item->pszText. */
991 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
993 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
994 if (infoPtr
->selectedItem
== item
)
995 infoPtr
->selectedItem
= NULL
;
996 if (infoPtr
->hotItem
== item
)
997 infoPtr
->hotItem
= NULL
;
998 if (infoPtr
->focusedItem
== item
)
999 infoPtr
->focusedItem
= NULL
;
1000 if (infoPtr
->firstVisible
== item
)
1001 infoPtr
->firstVisible
= NULL
;
1002 if (infoPtr
->dropItem
== item
)
1003 infoPtr
->dropItem
= NULL
;
1004 if (infoPtr
->insertMarkItem
== item
)
1005 infoPtr
->insertMarkItem
= NULL
;
1010 /* Item Insertion *******************************************************/
1012 /***************************************************************************
1013 * This method inserts newItem before sibling as a child of parent.
1014 * sibling can be NULL, but only if parent has no children.
1017 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1018 TREEVIEW_ITEM
*parent
)
1020 assert(parent
!= NULL
);
1022 if (sibling
!= NULL
)
1024 assert(sibling
->parent
== parent
);
1026 if (sibling
->prevSibling
!= NULL
)
1027 sibling
->prevSibling
->nextSibling
= newItem
;
1029 newItem
->prevSibling
= sibling
->prevSibling
;
1030 sibling
->prevSibling
= newItem
;
1033 newItem
->prevSibling
= NULL
;
1035 newItem
->nextSibling
= sibling
;
1037 if (parent
->firstChild
== sibling
)
1038 parent
->firstChild
= newItem
;
1040 if (parent
->lastChild
== NULL
)
1041 parent
->lastChild
= newItem
;
1044 /***************************************************************************
1045 * This method inserts newItem after sibling as a child of parent.
1046 * sibling can be NULL, but only if parent has no children.
1049 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1050 TREEVIEW_ITEM
*parent
)
1052 assert(parent
!= NULL
);
1054 if (sibling
!= NULL
)
1056 assert(sibling
->parent
== parent
);
1058 if (sibling
->nextSibling
!= NULL
)
1059 sibling
->nextSibling
->prevSibling
= newItem
;
1061 newItem
->nextSibling
= sibling
->nextSibling
;
1062 sibling
->nextSibling
= newItem
;
1065 newItem
->nextSibling
= NULL
;
1067 newItem
->prevSibling
= sibling
;
1069 if (parent
->lastChild
== sibling
)
1070 parent
->lastChild
= newItem
;
1072 if (parent
->firstChild
== NULL
)
1073 parent
->firstChild
= newItem
;
1077 TREEVIEW_DoSetItemT(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
1078 const TVITEMEXW
*tvItem
, BOOL isW
)
1080 UINT callbackClear
= 0;
1081 UINT callbackSet
= 0;
1083 TRACE("item %p\n", item
);
1084 /* Do this first in case it fails. */
1085 if (tvItem
->mask
& TVIF_TEXT
)
1087 item
->textWidth
= 0; /* force width recalculation */
1088 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKW
&& tvItem
->pszText
!= NULL
) /* covers != TEXTCALLBACKA too, and undocumented: pszText of NULL also means TEXTCALLBACK */
1093 len
= lstrlenW(tvItem
->pszText
) + 1;
1095 len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1, NULL
, 0);
1097 newText
= ReAlloc(item
->pszText
, len
* sizeof(WCHAR
));
1099 if (newText
== NULL
) return FALSE
;
1101 callbackClear
|= TVIF_TEXT
;
1103 item
->pszText
= newText
;
1104 item
->cchTextMax
= len
;
1106 lstrcpynW(item
->pszText
, tvItem
->pszText
, len
);
1108 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1,
1109 item
->pszText
, len
);
1111 TRACE("setting text %s, item %p\n", debugstr_w(item
->pszText
), item
);
1115 callbackSet
|= TVIF_TEXT
;
1117 item
->pszText
= ReAlloc(item
->pszText
,
1118 TEXT_CALLBACK_SIZE
* sizeof(WCHAR
));
1119 item
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1120 TRACE("setting callback, item %p\n", item
);
1124 if (tvItem
->mask
& TVIF_CHILDREN
)
1126 item
->cChildren
= tvItem
->cChildren
;
1128 if (item
->cChildren
== I_CHILDRENCALLBACK
)
1129 callbackSet
|= TVIF_CHILDREN
;
1131 callbackClear
|= TVIF_CHILDREN
;
1134 if (tvItem
->mask
& TVIF_IMAGE
)
1136 item
->iImage
= tvItem
->iImage
;
1138 if (item
->iImage
== I_IMAGECALLBACK
)
1139 callbackSet
|= TVIF_IMAGE
;
1141 callbackClear
|= TVIF_IMAGE
;
1144 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1146 item
->iSelectedImage
= tvItem
->iSelectedImage
;
1148 if (item
->iSelectedImage
== I_IMAGECALLBACK
)
1149 callbackSet
|= TVIF_SELECTEDIMAGE
;
1151 callbackClear
|= TVIF_SELECTEDIMAGE
;
1154 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
1156 item
->iExpandedImage
= tvItem
->iExpandedImage
;
1158 if (item
->iExpandedImage
== I_IMAGECALLBACK
)
1159 callbackSet
|= TVIF_EXPANDEDIMAGE
;
1161 callbackClear
|= TVIF_EXPANDEDIMAGE
;
1164 if (tvItem
->mask
& TVIF_PARAM
)
1165 item
->lParam
= tvItem
->lParam
;
1167 /* If the application sets TVIF_INTEGRAL without
1168 * supplying a TVITEMEX structure, it's toast. */
1169 if (tvItem
->mask
& TVIF_INTEGRAL
)
1170 item
->iIntegral
= tvItem
->iIntegral
;
1172 if (tvItem
->mask
& TVIF_STATE
)
1174 TRACE("prevstate,state,mask:%x,%x,%x\n", item
->state
, tvItem
->state
,
1176 item
->state
&= ~tvItem
->stateMask
;
1177 item
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1180 if (tvItem
->mask
& TVIF_STATEEX
)
1182 FIXME("New extended state: %x\n", tvItem
->uStateEx
);
1185 item
->callbackMask
|= callbackSet
;
1186 item
->callbackMask
&= ~callbackClear
;
1191 /* Note that the new item is pre-zeroed. */
1193 TREEVIEW_InsertItemT(TREEVIEW_INFO
*infoPtr
, const TVINSERTSTRUCTW
*ptdi
, BOOL isW
)
1195 const TVITEMEXW
*tvItem
= &ptdi
->u
.itemex
;
1196 HTREEITEM insertAfter
;
1197 TREEVIEW_ITEM
*newItem
, *parentItem
;
1198 BOOL bTextUpdated
= FALSE
;
1200 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1202 parentItem
= infoPtr
->root
;
1206 parentItem
= ptdi
->hParent
;
1208 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1210 WARN("invalid parent %p\n", parentItem
);
1215 insertAfter
= ptdi
->hInsertAfter
;
1217 /* Validate this now for convenience. */
1218 switch ((DWORD_PTR
)insertAfter
)
1220 case (DWORD_PTR
)TVI_FIRST
:
1221 case (DWORD_PTR
)TVI_LAST
:
1222 case (DWORD_PTR
)TVI_SORT
:
1226 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1227 insertAfter
->parent
!= parentItem
)
1229 WARN("invalid insert after %p\n", insertAfter
);
1230 insertAfter
= TVI_LAST
;
1234 TRACE("parent %p position %p: %s\n", parentItem
, insertAfter
,
1235 (tvItem
->mask
& TVIF_TEXT
)
1236 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKW
) ? "<callback>"
1237 : (isW
? debugstr_w(tvItem
->pszText
) : debugstr_a((LPSTR
)tvItem
->pszText
)))
1240 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1241 if (newItem
== NULL
)
1244 newItem
->parent
= parentItem
;
1245 newItem
->iIntegral
= 1;
1246 newItem
->visibleOrder
= -1;
1248 if (!TREEVIEW_DoSetItemT(infoPtr
, newItem
, tvItem
, isW
))
1251 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1253 infoPtr
->uNumItems
++;
1255 switch ((DWORD_PTR
)insertAfter
)
1257 case (DWORD_PTR
)TVI_FIRST
:
1259 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1260 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1261 if (infoPtr
->firstVisible
== originalFirst
)
1262 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1266 case (DWORD_PTR
)TVI_LAST
:
1267 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1270 /* hInsertAfter names a specific item we want to insert after */
1272 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1275 case (DWORD_PTR
)TVI_SORT
:
1277 TREEVIEW_ITEM
*aChild
;
1278 TREEVIEW_ITEM
*previousChild
= NULL
;
1279 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1280 BOOL bItemInserted
= FALSE
;
1282 aChild
= parentItem
->firstChild
;
1284 bTextUpdated
= TRUE
;
1285 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1287 /* Iterate the parent children to see where we fit in */
1288 while (aChild
!= NULL
)
1292 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1293 comp
= lstrcmpW(newItem
->pszText
, aChild
->pszText
);
1295 if (comp
< 0) /* we are smaller than the current one */
1297 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1298 if (infoPtr
->firstVisible
== originalFirst
&&
1299 aChild
== originalFirst
)
1300 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1301 bItemInserted
= TRUE
;
1304 else if (comp
> 0) /* we are bigger than the current one */
1306 previousChild
= aChild
;
1308 /* This will help us to exit if there is no more sibling */
1309 aChild
= (aChild
->nextSibling
== 0)
1311 : aChild
->nextSibling
;
1313 /* Look at the next item */
1319 * An item with this name is already existing, therefore,
1320 * we add after the one we found
1322 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1323 bItemInserted
= TRUE
;
1329 * we reach the end of the child list and the item has not
1330 * yet been inserted, therefore, insert it after the last child.
1332 if ((!bItemInserted
) && (aChild
== NULL
))
1333 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1340 TRACE("new item %p; parent %p, mask %x\n", newItem
,
1341 newItem
->parent
, tvItem
->mask
);
1343 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1345 if (newItem
->parent
->cChildren
== 0)
1346 newItem
->parent
->cChildren
= 1;
1348 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1350 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1351 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1354 if (infoPtr
->firstVisible
== NULL
)
1355 infoPtr
->firstVisible
= newItem
;
1357 TREEVIEW_VerifyTree(infoPtr
);
1359 if (!infoPtr
->bRedraw
) return (LRESULT
)newItem
;
1361 if (parentItem
== infoPtr
->root
||
1362 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1364 TREEVIEW_ITEM
*item
;
1365 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1367 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1368 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1371 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1373 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1374 TREEVIEW_UpdateScrollBars(infoPtr
);
1376 * if the item was inserted in a visible part of the tree,
1377 * invalidate it, as well as those after it
1379 for (item
= newItem
;
1381 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1382 TREEVIEW_Invalidate(infoPtr
, item
);
1386 /* refresh treeview if newItem is the first item inserted under parentItem */
1387 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1389 /* parent got '+' - update it */
1390 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1394 return (LRESULT
)newItem
;
1397 /* Item Deletion ************************************************************/
1399 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
1402 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*parentItem
)
1404 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1406 while (kill
!= NULL
)
1408 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1410 TREEVIEW_RemoveItem(infoPtr
, kill
);
1415 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1416 assert(parentItem
->firstChild
== NULL
);
1417 assert(parentItem
->lastChild
== NULL
);
1421 TREEVIEW_UnlinkItem(const TREEVIEW_ITEM
*item
)
1423 TREEVIEW_ITEM
*parentItem
= item
->parent
;
1425 assert(item
!= NULL
);
1426 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1428 if (parentItem
->firstChild
== item
)
1429 parentItem
->firstChild
= item
->nextSibling
;
1431 if (parentItem
->lastChild
== item
)
1432 parentItem
->lastChild
= item
->prevSibling
;
1434 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1435 && parentItem
->cChildren
> 0)
1436 parentItem
->cChildren
= 0;
1438 if (item
->prevSibling
)
1439 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1441 if (item
->nextSibling
)
1442 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1446 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1448 TRACE("%p, (%s)\n", item
, TREEVIEW_ItemName(item
));
1450 if (item
->firstChild
)
1451 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
1453 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1454 TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
1456 TREEVIEW_UnlinkItem(item
);
1458 infoPtr
->uNumItems
--;
1460 if (item
->pszText
!= LPSTR_TEXTCALLBACKW
)
1461 Free(item
->pszText
);
1463 TREEVIEW_FreeItem(infoPtr
, item
);
1467 /* Empty out the tree. */
1469 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1471 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1473 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1477 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
)
1479 TREEVIEW_ITEM
*newSelection
= NULL
;
1480 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1481 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1482 BOOL visible
= FALSE
;
1484 if (item
== TVI_ROOT
|| !item
)
1486 TRACE("TVI_ROOT\n");
1487 parent
= infoPtr
->root
;
1488 newSelection
= NULL
;
1490 TREEVIEW_RemoveTree(infoPtr
);
1494 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1497 TRACE("%p (%s)\n", item
, TREEVIEW_ItemName(item
));
1498 parent
= item
->parent
;
1500 if (ISVISIBLE(item
))
1502 prev
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
1506 if (infoPtr
->selectedItem
!= NULL
1507 && (item
== infoPtr
->selectedItem
1508 || TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
)))
1510 if (item
->nextSibling
)
1511 newSelection
= item
->nextSibling
;
1512 else if (item
->parent
!= infoPtr
->root
)
1513 newSelection
= item
->parent
;
1515 newSelection
= item
->prevSibling
;
1516 TRACE("newSelection = %p\n", newSelection
);
1519 if (infoPtr
->firstVisible
== item
)
1521 if (item
->nextSibling
)
1522 newFirstVisible
= item
->nextSibling
;
1523 else if (item
->prevSibling
)
1524 newFirstVisible
= item
->prevSibling
;
1525 else if (item
->parent
!= infoPtr
->root
)
1526 newFirstVisible
= item
->parent
;
1527 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1530 newFirstVisible
= infoPtr
->firstVisible
;
1532 TREEVIEW_RemoveItem(infoPtr
, item
);
1535 /* Don't change if somebody else already has (infoPtr->selectedItem is cleared by FreeItem). */
1536 if (!infoPtr
->selectedItem
&& newSelection
)
1538 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1539 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1542 /* Validate insertMark dropItem.
1543 * hotItem ??? - used for comparison only.
1545 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1546 infoPtr
->insertMarkItem
= 0;
1548 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1549 infoPtr
->dropItem
= 0;
1551 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1552 newFirstVisible
= infoPtr
->root
->firstChild
;
1554 TREEVIEW_VerifyTree(infoPtr
);
1556 if (!infoPtr
->bRedraw
) return TRUE
;
1560 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1561 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1562 TREEVIEW_UpdateScrollBars(infoPtr
);
1563 TREEVIEW_Invalidate(infoPtr
, NULL
);
1565 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1567 /* parent lost '+/-' - update it */
1568 TREEVIEW_Invalidate(infoPtr
, parent
);
1575 /* Get/Set Messages *********************************************************/
1577 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
)
1579 infoPtr
->bRedraw
= wParam
!= 0;
1581 if (infoPtr
->bRedraw
)
1583 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1584 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1585 TREEVIEW_UpdateScrollBars(infoPtr
);
1586 TREEVIEW_Invalidate(infoPtr
, NULL
);
1592 TREEVIEW_GetIndent(const TREEVIEW_INFO
*infoPtr
)
1595 return infoPtr
->uIndent
;
1599 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1603 if (newIndent
< MINIMUM_INDENT
)
1604 newIndent
= MINIMUM_INDENT
;
1606 if (infoPtr
->uIndent
!= newIndent
)
1608 infoPtr
->uIndent
= newIndent
;
1609 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1610 TREEVIEW_UpdateScrollBars(infoPtr
);
1611 TREEVIEW_Invalidate(infoPtr
, NULL
);
1619 TREEVIEW_GetToolTips(const TREEVIEW_INFO
*infoPtr
)
1622 return (LRESULT
)infoPtr
->hwndToolTip
;
1626 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1631 prevToolTip
= infoPtr
->hwndToolTip
;
1632 infoPtr
->hwndToolTip
= hwndTT
;
1634 return (LRESULT
)prevToolTip
;
1638 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO
*infoPtr
, BOOL fUnicode
)
1640 BOOL rc
= infoPtr
->bNtfUnicode
;
1641 infoPtr
->bNtfUnicode
= fUnicode
;
1646 TREEVIEW_GetUnicodeFormat(const TREEVIEW_INFO
*infoPtr
)
1648 return infoPtr
->bNtfUnicode
;
1652 TREEVIEW_GetScrollTime(const TREEVIEW_INFO
*infoPtr
)
1654 return infoPtr
->uScrollTime
;
1658 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1660 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1662 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1664 return uOldScrollTime
;
1669 TREEVIEW_GetImageList(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1676 return (LRESULT
)infoPtr
->himlNormal
;
1679 return (LRESULT
)infoPtr
->himlState
;
1686 #define TVHEIGHT_MIN 16
1687 #define TVHEIGHT_FONT_ADJUST 3 /* 2 for focus border + 1 for margin some apps assume */
1689 /* Compute the natural height for items. */
1691 TREEVIEW_NaturalHeight(const TREEVIEW_INFO
*infoPtr
)
1695 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1698 /* Height is the maximum of:
1699 * 16 (a hack because our fonts are tiny), and
1700 * The text height + border & margin, and
1701 * The size of the normal image list
1703 GetTextMetricsW(hdc
, &tm
);
1704 SelectObject(hdc
, hOldFont
);
1707 height
= TVHEIGHT_MIN
;
1708 if (height
< tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
)
1709 height
= tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
;
1710 if (height
< infoPtr
->normalImageHeight
)
1711 height
= infoPtr
->normalImageHeight
;
1713 /* Round down, unless we support odd ("non even") heights. */
1714 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1721 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, UINT type
, HIMAGELIST himlNew
)
1723 HIMAGELIST himlOld
= 0;
1724 int oldWidth
= infoPtr
->normalImageWidth
;
1725 int oldHeight
= infoPtr
->normalImageHeight
;
1727 TRACE("%u,%p\n", type
, himlNew
);
1732 himlOld
= infoPtr
->himlNormal
;
1733 infoPtr
->himlNormal
= himlNew
;
1736 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1737 &infoPtr
->normalImageHeight
);
1740 infoPtr
->normalImageWidth
= 0;
1741 infoPtr
->normalImageHeight
= 0;
1747 himlOld
= infoPtr
->himlState
;
1748 infoPtr
->himlState
= himlNew
;
1751 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1752 &infoPtr
->stateImageHeight
);
1755 infoPtr
->stateImageWidth
= 0;
1756 infoPtr
->stateImageHeight
= 0;
1762 ERR("unknown imagelist type %u\n", type
);
1765 if (oldWidth
!= infoPtr
->normalImageWidth
||
1766 oldHeight
!= infoPtr
->normalImageHeight
)
1768 BOOL bRecalcVisible
= FALSE
;
1770 if (oldHeight
!= infoPtr
->normalImageHeight
&&
1771 !infoPtr
->bHeightSet
)
1773 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1774 bRecalcVisible
= TRUE
;
1777 if (infoPtr
->normalImageWidth
> MINIMUM_INDENT
&&
1778 infoPtr
->normalImageWidth
!= infoPtr
->uIndent
)
1780 infoPtr
->uIndent
= infoPtr
->normalImageWidth
;
1781 bRecalcVisible
= TRUE
;
1785 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1787 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1788 TREEVIEW_UpdateScrollBars(infoPtr
);
1791 TREEVIEW_Invalidate(infoPtr
, NULL
);
1793 return (LRESULT
)himlOld
;
1797 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1799 INT prevHeight
= infoPtr
->uItemHeight
;
1801 TRACE("new=%d, old=%d\n", newHeight
, prevHeight
);
1802 if (newHeight
== -1)
1804 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1805 infoPtr
->bHeightSet
= FALSE
;
1809 if (newHeight
== 0) newHeight
= 1;
1810 infoPtr
->uItemHeight
= newHeight
;
1811 infoPtr
->bHeightSet
= TRUE
;
1814 /* Round down, unless we support odd ("non even") heights. */
1815 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
) && infoPtr
->uItemHeight
!= 1)
1817 infoPtr
->uItemHeight
&= ~1;
1818 TRACE("after rounding=%d\n", infoPtr
->uItemHeight
);
1821 if (infoPtr
->uItemHeight
!= prevHeight
)
1823 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1824 TREEVIEW_UpdateScrollBars(infoPtr
);
1825 TREEVIEW_Invalidate(infoPtr
, NULL
);
1832 TREEVIEW_GetItemHeight(const TREEVIEW_INFO
*infoPtr
)
1835 return infoPtr
->uItemHeight
;
1840 TREEVIEW_GetFont(const TREEVIEW_INFO
*infoPtr
)
1842 TRACE("%p\n", infoPtr
->hFont
);
1843 return (LRESULT
)infoPtr
->hFont
;
1848 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1852 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1858 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1860 UINT uHeight
= infoPtr
->uItemHeight
;
1862 TRACE("%p %i\n", hFont
, bRedraw
);
1864 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
1866 DeleteObject(infoPtr
->hBoldFont
);
1867 DeleteObject(infoPtr
->hUnderlineFont
);
1868 DeleteObject(infoPtr
->hBoldUnderlineFont
);
1869 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1870 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
1871 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
1873 if (!infoPtr
->bHeightSet
)
1874 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1876 if (uHeight
!= infoPtr
->uItemHeight
)
1877 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1879 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1881 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1882 TREEVIEW_UpdateScrollBars(infoPtr
);
1885 TREEVIEW_Invalidate(infoPtr
, NULL
);
1892 TREEVIEW_GetLineColor(const TREEVIEW_INFO
*infoPtr
)
1895 return (LRESULT
)infoPtr
->clrLine
;
1899 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1901 COLORREF prevColor
= infoPtr
->clrLine
;
1904 infoPtr
->clrLine
= color
;
1905 return (LRESULT
)prevColor
;
1910 TREEVIEW_GetTextColor(const TREEVIEW_INFO
*infoPtr
)
1913 return (LRESULT
)infoPtr
->clrText
;
1917 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1919 COLORREF prevColor
= infoPtr
->clrText
;
1922 infoPtr
->clrText
= color
;
1924 if (infoPtr
->clrText
!= prevColor
)
1925 TREEVIEW_Invalidate(infoPtr
, NULL
);
1927 return (LRESULT
)prevColor
;
1932 TREEVIEW_GetBkColor(const TREEVIEW_INFO
*infoPtr
)
1935 return (LRESULT
)infoPtr
->clrBk
;
1939 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1941 COLORREF prevColor
= infoPtr
->clrBk
;
1944 infoPtr
->clrBk
= newColor
;
1946 if (newColor
!= prevColor
)
1947 TREEVIEW_Invalidate(infoPtr
, NULL
);
1949 return (LRESULT
)prevColor
;
1954 TREEVIEW_GetInsertMarkColor(const TREEVIEW_INFO
*infoPtr
)
1957 return (LRESULT
)infoPtr
->clrInsertMark
;
1961 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1963 COLORREF prevColor
= infoPtr
->clrInsertMark
;
1965 TRACE("%x\n", color
);
1966 infoPtr
->clrInsertMark
= color
;
1968 return (LRESULT
)prevColor
;
1973 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
1975 TRACE("%d %p\n", wParam
, item
);
1977 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1980 infoPtr
->insertBeforeorAfter
= wParam
;
1981 infoPtr
->insertMarkItem
= item
;
1983 TREEVIEW_Invalidate(infoPtr
, NULL
);
1989 /************************************************************************
1990 * Some serious braindamage here. lParam is a pointer to both the
1991 * input HTREEITEM and the output RECT.
1994 TREEVIEW_GetItemRect(const TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
1996 TREEVIEW_ITEM
*item
;
1997 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
2005 if (!TREEVIEW_ValidItem(infoPtr
, item
) || !ISVISIBLE(item
))
2009 * If wParam is TRUE return the text size otherwise return
2010 * the whole item size
2014 /* Windows does not send TVN_GETDISPINFO here. */
2016 lpRect
->top
= item
->rect
.top
;
2017 lpRect
->bottom
= item
->rect
.bottom
;
2019 lpRect
->left
= item
->textOffset
;
2020 if (!item
->textWidth
)
2021 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2023 lpRect
->right
= item
->textOffset
+ item
->textWidth
+ 4;
2027 *lpRect
= item
->rect
;
2030 TRACE("%s [%s]\n", fTextRect
? "text" : "item", wine_dbgstr_rect(lpRect
));
2035 static inline LRESULT
2036 TREEVIEW_GetVisibleCount(const TREEVIEW_INFO
*infoPtr
)
2038 /* Surprise! This does not take integral height into account. */
2039 TRACE("client=%d, item=%d\n", infoPtr
->clientHeight
, infoPtr
->uItemHeight
);
2040 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2045 TREEVIEW_GetItemT(const TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2047 TREEVIEW_ITEM
*item
= tvItem
->hItem
;
2049 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2051 BOOL valid_item
= FALSE
;
2052 if (!item
) return FALSE
;
2056 infoPtr
= item
->infoPtr
;
2057 TRACE("got item from different tree %p, called from %p\n", item
->infoPtr
, infoPtr
);
2058 valid_item
= TREEVIEW_ValidItem(infoPtr
, item
);
2064 if (!valid_item
) return FALSE
;
2067 TREEVIEW_UpdateDispInfo(infoPtr
, item
, tvItem
->mask
);
2069 if (tvItem
->mask
& TVIF_CHILDREN
)
2071 if (item
->cChildren
==I_CHILDRENCALLBACK
)
2072 FIXME("I_CHILDRENCALLBACK not supported\n");
2073 tvItem
->cChildren
= item
->cChildren
;
2076 if (tvItem
->mask
& TVIF_HANDLE
)
2077 tvItem
->hItem
= item
;
2079 if (tvItem
->mask
& TVIF_IMAGE
)
2080 tvItem
->iImage
= item
->iImage
;
2082 if (tvItem
->mask
& TVIF_INTEGRAL
)
2083 tvItem
->iIntegral
= item
->iIntegral
;
2085 /* undocumented: (mask & TVIF_PARAM) ignored and lParam is always set */
2086 tvItem
->lParam
= item
->lParam
;
2088 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2089 tvItem
->iSelectedImage
= item
->iSelectedImage
;
2091 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
2092 tvItem
->iExpandedImage
= item
->iExpandedImage
;
2094 /* undocumented: stateMask and (state & TVIF_STATE) ignored, so state is always set */
2095 tvItem
->state
= item
->state
;
2097 if (tvItem
->mask
& TVIF_TEXT
)
2099 if (item
->pszText
== NULL
)
2101 if (tvItem
->cchTextMax
> 0)
2102 tvItem
->pszText
[0] = '\0';
2106 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2108 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2109 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2113 lstrcpynW(tvItem
->pszText
, item
->pszText
, tvItem
->cchTextMax
);
2118 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2120 tvItem
->pszText
= (LPWSTR
)LPSTR_TEXTCALLBACKA
;
2121 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2125 WideCharToMultiByte(CP_ACP
, 0, item
->pszText
, -1,
2126 (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, NULL
, NULL
);
2131 if (tvItem
->mask
& TVIF_STATEEX
)
2133 FIXME("Extended item state not supported, returning 0.\n");
2134 tvItem
->uStateEx
= 0;
2137 TRACE("item <%p>, txt %p, img %d, mask %x\n",
2138 item
, tvItem
->pszText
, tvItem
->iImage
, tvItem
->mask
);
2143 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2144 * which is wrong. */
2146 TREEVIEW_SetItemT(TREEVIEW_INFO
*infoPtr
, const TVITEMEXW
*tvItem
, BOOL isW
)
2148 TREEVIEW_ITEM
*item
;
2149 TREEVIEW_ITEM originalItem
;
2151 item
= tvItem
->hItem
;
2153 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr
, item
),
2156 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2159 /* store the original item values */
2160 originalItem
= *item
;
2162 if (!TREEVIEW_DoSetItemT(infoPtr
, item
, tvItem
, isW
))
2165 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2166 if ((tvItem
->mask
& TVIF_TEXT
2167 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2170 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_TEXT
);
2171 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2174 if (tvItem
->mask
!= 0 && ISVISIBLE(item
))
2176 /* The refresh updates everything, but we can't wait until then. */
2177 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
2179 /* if any of the item's values changed and it's not a callback, redraw the item */
2180 if (item_changed(&originalItem
, item
, tvItem
))
2182 if (tvItem
->mask
& TVIF_INTEGRAL
)
2184 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
2185 TREEVIEW_UpdateScrollBars(infoPtr
);
2187 TREEVIEW_Invalidate(infoPtr
, NULL
);
2191 TREEVIEW_UpdateScrollBars(infoPtr
);
2192 TREEVIEW_Invalidate(infoPtr
, item
);
2201 TREEVIEW_GetItemState(const TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, UINT mask
)
2205 if (!item
|| !TREEVIEW_ValidItem(infoPtr
, item
))
2208 return (item
->state
& mask
);
2212 TREEVIEW_GetNextItem(const TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM item
)
2214 TREEVIEW_ITEM
*retval
;
2218 /* handle all the global data here */
2221 case TVGN_CHILD
: /* Special case: child of 0 is root */
2226 retval
= infoPtr
->root
->firstChild
;
2230 retval
= infoPtr
->selectedItem
;
2233 case TVGN_FIRSTVISIBLE
:
2234 retval
= infoPtr
->firstVisible
;
2237 case TVGN_DROPHILITE
:
2238 retval
= infoPtr
->dropItem
;
2241 case TVGN_LASTVISIBLE
:
2242 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2248 TRACE("flags:%x, returns %p\n", which
, retval
);
2249 return (LRESULT
)retval
;
2252 if (item
== TVI_ROOT
) item
= infoPtr
->root
;
2254 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2260 retval
= item
->nextSibling
;
2263 retval
= item
->prevSibling
;
2266 retval
= (item
->parent
!= infoPtr
->root
) ? item
->parent
: NULL
;
2269 retval
= item
->firstChild
;
2271 case TVGN_NEXTVISIBLE
:
2272 retval
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2274 case TVGN_PREVIOUSVISIBLE
:
2275 retval
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
2278 TRACE("Unknown msg %x,item %p\n", which
, item
);
2282 TRACE("flags:%x, item %p;returns %p\n", which
, item
, retval
);
2283 return (LRESULT
)retval
;
2288 TREEVIEW_GetCount(const TREEVIEW_INFO
*infoPtr
)
2290 TRACE(" %d\n", infoPtr
->uNumItems
);
2291 return (LRESULT
)infoPtr
->uNumItems
;
2295 TREEVIEW_ToggleItemState(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2297 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2299 static const unsigned int state_table
[] = { 0, 2, 1 };
2303 state
= STATEIMAGEINDEX(item
->state
);
2304 TRACE("state:%x\n", state
);
2305 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2308 state
= state_table
[state
];
2310 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2312 TRACE("state:%x\n", state
);
2313 TREEVIEW_Invalidate(infoPtr
, item
);
2318 /* Painting *************************************************************/
2320 /* Draw the lines and expand button for an item. Also draws one section
2321 * of the line from item's parent to item's parent's next sibling. */
2323 TREEVIEW_DrawItemLines(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const TREEVIEW_ITEM
*item
)
2325 LONG centerx
, centery
;
2326 BOOL lar
= ((infoPtr
->dwStyle
2327 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2330 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2332 if (!lar
&& item
->iLevel
== 0)
2335 hbr
= CreateSolidBrush(clrBk
);
2336 hbrOld
= SelectObject(hdc
, hbr
);
2338 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2339 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2341 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2343 HPEN hOldPen
, hNewPen
;
2347 /* Get a dotted grey pen */
2348 lb
.lbStyle
= BS_SOLID
;
2349 lb
.lbColor
= GETLINECOLOR(infoPtr
->clrLine
);
2350 hNewPen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, NULL
);
2351 hOldPen
= SelectObject(hdc
, hNewPen
);
2353 /* Make sure the center is on a dot (using +2 instead
2354 * of +1 gives us pixel-by-pixel compat with native) */
2355 centery
= (centery
+ 2) & ~1;
2357 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2358 LineTo(hdc
, centerx
- 1, centery
);
2360 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2362 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2363 LineTo(hdc
, centerx
, centery
);
2366 if (item
->nextSibling
)
2368 MoveToEx(hdc
, centerx
, centery
, NULL
);
2369 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2372 /* Draw the line from our parent to its next sibling. */
2373 parent
= item
->parent
;
2374 while (parent
!= infoPtr
->root
)
2376 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2378 if (parent
->nextSibling
2379 /* skip top-levels unless TVS_LINESATROOT */
2380 && parent
->stateOffset
> parent
->linesOffset
)
2382 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2383 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2386 parent
= parent
->parent
;
2389 SelectObject(hdc
, hOldPen
);
2390 DeleteObject(hNewPen
);
2394 * Display the (+/-) signs
2397 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2399 if (item
->cChildren
)
2401 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
2404 RECT glyphRect
= item
->rect
;
2405 glyphRect
.left
= item
->linesOffset
;
2406 glyphRect
.right
= item
->stateOffset
;
2407 DrawThemeBackground (theme
, hdc
, TVP_GLYPH
,
2408 (item
->state
& TVIS_EXPANDED
) ? GLPS_OPENED
: GLPS_CLOSED
,
2413 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2414 LONG width
= item
->stateOffset
- item
->linesOffset
;
2415 LONG rectsize
= min(height
, width
) / 4;
2416 /* plussize = ceil(rectsize * 3/4) */
2417 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2419 HPEN new_pen
= CreatePen(PS_SOLID
, 0, GETLINECOLOR(infoPtr
->clrLine
));
2420 HPEN old_pen
= SelectObject(hdc
, new_pen
);
2422 Rectangle(hdc
, centerx
- rectsize
- 1, centery
- rectsize
- 1,
2423 centerx
+ rectsize
+ 2, centery
+ rectsize
+ 2);
2425 SelectObject(hdc
, old_pen
);
2426 DeleteObject(new_pen
);
2428 /* draw +/- signs with current text color */
2429 new_pen
= CreatePen(PS_SOLID
, 0, GETTXTCOLOR(infoPtr
->clrText
));
2430 old_pen
= SelectObject(hdc
, new_pen
);
2432 if (height
< 18 || width
< 18)
2434 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2435 LineTo(hdc
, centerx
+ plussize
, centery
);
2437 if (!(item
->state
& TVIS_EXPANDED
) ||
2438 (item
->state
& TVIS_EXPANDPARTIAL
))
2440 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2441 LineTo(hdc
, centerx
, centery
+ plussize
);
2446 Rectangle(hdc
, centerx
- plussize
+ 1, centery
- 1,
2447 centerx
+ plussize
, centery
+ 2);
2449 if (!(item
->state
& TVIS_EXPANDED
) ||
2450 (item
->state
& TVIS_EXPANDPARTIAL
))
2452 Rectangle(hdc
, centerx
- 1, centery
- plussize
+ 1,
2453 centerx
+ 2, centery
+ plussize
);
2454 SetPixel(hdc
, centerx
- 1, centery
, clrBk
);
2455 SetPixel(hdc
, centerx
+ 1, centery
, clrBk
);
2459 SelectObject(hdc
, old_pen
);
2460 DeleteObject(new_pen
);
2464 SelectObject(hdc
, hbrOld
);
2469 TREEVIEW_DrawItem(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*item
)
2473 COLORREF oldTextColor
, oldTextBkColor
;
2475 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2476 NMTVCUSTOMDRAW nmcdhdr
;
2478 TREEVIEW_UpdateDispInfo(infoPtr
, item
, CALLBACK_MASK_ALL
);
2480 /* - If item is drop target or it is selected and window is in focus -
2481 * use blue background (COLOR_HIGHLIGHT).
2482 * - If item is selected, window is not in focus, but it has style
2483 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2484 * - Otherwise - use background color
2486 if ((item
->state
& TVIS_DROPHILITED
) || ((item
== infoPtr
->focusedItem
) && !(item
->state
& TVIS_SELECTED
)) ||
2487 ((item
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
|| item
== infoPtr
->focusedItem
) &&
2488 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2490 if ((item
->state
& TVIS_DROPHILITED
) || inFocus
)
2492 nmcdhdr
.clrTextBk
= comctl32_color
.clrHighlight
;
2493 nmcdhdr
.clrText
= comctl32_color
.clrHighlightText
;
2497 nmcdhdr
.clrTextBk
= comctl32_color
.clrBtnFace
;
2498 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2503 nmcdhdr
.clrTextBk
= GETBKCOLOR(infoPtr
->clrBk
);
2504 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
2505 nmcdhdr
.clrText
= comctl32_color
.clrHighlight
;
2507 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2510 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
2512 /* The custom draw handler can query the text rectangle,
2514 /* should already be known, set to 0 when changed */
2515 if (!item
->textWidth
)
2516 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2520 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2522 cditem
= TREEVIEW_SendCustomDrawItemNotify
2523 (infoPtr
, hdc
, item
, CDDS_ITEMPREPAINT
, &nmcdhdr
);
2524 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2526 if (cditem
& CDRF_SKIPDEFAULT
)
2528 SelectObject(hdc
, hOldFont
);
2533 if (cditem
& CDRF_NEWFONT
)
2534 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2536 TREEVIEW_DrawItemLines(infoPtr
, hdc
, item
);
2538 /* Set colors. Custom draw handler can change these so we do this after it. */
2539 oldTextColor
= SetTextColor(hdc
, nmcdhdr
.clrText
);
2540 oldTextBkColor
= SetBkColor(hdc
, nmcdhdr
.clrTextBk
);
2542 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2545 * Display the images associated with this item
2550 /* State images are displayed to the left of the Normal image
2551 * image number is in state; zero should be `display no image'.
2553 imageIndex
= STATEIMAGEINDEX(item
->state
);
2555 if (infoPtr
->himlState
&& imageIndex
)
2557 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2559 centery
- infoPtr
->stateImageHeight
/ 2,
2563 /* Now, draw the normal image; can be either selected,
2564 * non-selected or expanded image.
2567 if ((item
->state
& TVIS_SELECTED
) && (item
->iSelectedImage
>= 0))
2569 /* The item is currently selected */
2570 imageIndex
= item
->iSelectedImage
;
2572 else if ((item
->state
& TVIS_EXPANDED
) && (item
->iExpandedImage
!= (WORD
)I_IMAGENONE
))
2574 /* The item is currently not selected but expanded */
2575 imageIndex
= item
->iExpandedImage
;
2579 /* The item is not selected and not expanded */
2580 imageIndex
= item
->iImage
;
2583 if (infoPtr
->himlNormal
)
2585 UINT style
= item
->state
& TVIS_CUT
? ILD_SELECTED
: ILD_NORMAL
;
2587 style
|= item
->state
& TVIS_OVERLAYMASK
;
2589 ImageList_DrawEx(infoPtr
->himlNormal
, imageIndex
, hdc
,
2590 item
->imageOffset
, centery
- infoPtr
->normalImageHeight
/ 2,
2591 0, 0, infoPtr
->clrBk
, item
->state
& TVIS_CUT
? GETBKCOLOR(infoPtr
->clrBk
) : CLR_DEFAULT
,
2598 * Display the text associated with this item
2601 /* Don't paint item's text if it's being edited */
2602 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= item
))
2610 rcText
.top
= item
->rect
.top
;
2611 rcText
.bottom
= item
->rect
.bottom
;
2612 rcText
.left
= item
->textOffset
;
2613 rcText
.right
= rcText
.left
+ item
->textWidth
+ 4;
2615 TRACE("drawing text %s at (%s)\n",
2616 debugstr_w(item
->pszText
), wine_dbgstr_rect(&rcText
));
2619 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
2621 align
= SetTextAlign(hdc
, TA_LEFT
| TA_TOP
);
2622 ExtTextOutW(hdc
, rcText
.left
+ 2, (rcText
.top
+ rcText
.bottom
- sz
.cy
) / 2,
2623 ETO_CLIPPED
| ETO_OPAQUE
,
2626 lstrlenW(item
->pszText
),
2628 SetTextAlign(hdc
, align
);
2630 /* Draw focus box around the selected item */
2631 if ((item
== infoPtr
->selectedItem
) && inFocus
)
2633 DrawFocusRect(hdc
,&rcText
);
2638 /* Draw insertion mark if necessary */
2640 if (infoPtr
->insertMarkItem
)
2641 TRACE("item:%d,mark:%p\n",
2642 TREEVIEW_GetItemIndex(infoPtr
, item
),
2643 infoPtr
->insertMarkItem
);
2645 if (item
== infoPtr
->insertMarkItem
)
2647 HPEN hNewPen
, hOldPen
;
2651 hNewPen
= CreatePen(PS_SOLID
, 2, GETINSCOLOR(infoPtr
->clrInsertMark
));
2652 hOldPen
= SelectObject(hdc
, hNewPen
);
2654 if (infoPtr
->insertBeforeorAfter
)
2655 offset
= item
->rect
.bottom
- 1;
2657 offset
= item
->rect
.top
+ 1;
2659 left
= item
->textOffset
- 2;
2660 right
= item
->textOffset
+ item
->textWidth
+ 2;
2662 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2663 LineTo(hdc
, left
, offset
+ 4);
2665 MoveToEx(hdc
, left
, offset
, NULL
);
2666 LineTo(hdc
, right
+ 1, offset
);
2668 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2669 LineTo(hdc
, right
, offset
- 4);
2671 SelectObject(hdc
, hOldPen
);
2672 DeleteObject(hNewPen
);
2675 /* Restore the hdc state */
2676 SetTextColor(hdc
, oldTextColor
);
2677 SetBkColor(hdc
, oldTextBkColor
);
2678 SelectObject(hdc
, hOldFont
);
2680 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2682 cditem
= TREEVIEW_SendCustomDrawItemNotify
2683 (infoPtr
, hdc
, item
, CDDS_ITEMPOSTPAINT
, &nmcdhdr
);
2684 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2688 /* Computes treeHeight and treeWidth and updates the scroll bars.
2691 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2693 TREEVIEW_ITEM
*item
;
2694 HWND hwnd
= infoPtr
->hwnd
;
2698 LONG scrollX
= infoPtr
->scrollX
;
2700 infoPtr
->treeWidth
= 0;
2701 infoPtr
->treeHeight
= 0;
2703 /* We iterate through all visible items in order to get the tree height
2705 item
= infoPtr
->root
->firstChild
;
2707 while (item
!= NULL
)
2709 if (ISVISIBLE(item
))
2711 /* actually we draw text at textOffset + 2 */
2712 if (2+item
->textOffset
+item
->textWidth
> infoPtr
->treeWidth
)
2713 infoPtr
->treeWidth
= item
->textOffset
+item
->textWidth
+2;
2715 /* This is scroll-adjusted, but we fix this below. */
2716 infoPtr
->treeHeight
= item
->rect
.bottom
;
2719 item
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2722 /* Fix the scroll adjusted treeHeight and treeWidth. */
2723 if (infoPtr
->root
->firstChild
)
2724 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2726 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2728 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2730 /* Adding one scroll bar may take up enough space that it forces us
2731 * to add the other as well. */
2732 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2736 if (infoPtr
->treeWidth
2737 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2740 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
|| infoPtr
->scrollX
> 0)
2743 if (!vert
&& horz
&& infoPtr
->treeHeight
2744 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2747 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2749 si
.cbSize
= sizeof(SCROLLINFO
);
2750 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2755 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2756 if ( si
.nPage
&& NULL
!= infoPtr
->firstVisible
)
2758 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2759 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2761 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2763 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2764 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2765 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2769 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2770 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2771 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2776 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2777 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2778 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2783 si
.nPage
= infoPtr
->clientWidth
;
2784 si
.nPos
= infoPtr
->scrollX
;
2785 si
.nMax
= infoPtr
->treeWidth
- 1;
2787 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2789 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2793 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2794 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2795 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2797 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2798 TREEVIEW_HScroll(infoPtr
,
2799 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2803 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2804 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2805 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2808 if (infoPtr
->scrollX
!= 0)
2810 TREEVIEW_HScroll(infoPtr
,
2811 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2816 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2820 TREEVIEW_FillBkgnd(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2823 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2825 hBrush
= CreateSolidBrush(clrBk
);
2826 FillRect(hdc
, rc
, hBrush
);
2827 DeleteObject(hBrush
);
2830 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2832 TREEVIEW_EraseBackground(const TREEVIEW_INFO
*infoPtr
, HDC hdc
)
2836 TRACE("%p\n", infoPtr
);
2838 GetClientRect(infoPtr
->hwnd
, &rect
);
2839 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rect
);
2845 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2847 HWND hwnd
= infoPtr
->hwnd
;
2849 TREEVIEW_ITEM
*item
;
2851 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2853 TRACE("empty window\n");
2857 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2860 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2862 ReleaseDC(hwnd
, hdc
);
2866 for (item
= infoPtr
->root
->firstChild
;
2868 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
2870 if (ISVISIBLE(item
))
2872 /* Avoid unneeded calculations */
2873 if (item
->rect
.top
> rect
.bottom
)
2875 if (item
->rect
.bottom
< rect
.top
)
2878 TREEVIEW_DrawItem(infoPtr
, hdc
, item
);
2883 // FIXME: This is correct, but is causes and infinite loop of WM_PAINT
2884 // messages, resulting in continuous painting of the scroll bar in reactos.
2885 // Comment out until the real bug is found. CORE-4912
2888 TREEVIEW_UpdateScrollBars(infoPtr
);
2891 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2893 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2897 TREEVIEW_InvalidateItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2899 if (item
) InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2903 TREEVIEW_Invalidate(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2906 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2908 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2912 TREEVIEW_InitCheckboxes(TREEVIEW_INFO
*infoPtr
)
2915 HBITMAP hbm
, hbmOld
;
2919 infoPtr
->himlState
= ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
2921 hdcScreen
= GetDC(0);
2923 hdc
= CreateCompatibleDC(hdcScreen
);
2924 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
2925 hbmOld
= SelectObject(hdc
, hbm
);
2927 SetRect(&rc
, 0, 0, 48, 16);
2928 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
2930 SetRect(&rc
, 18, 2, 30, 14);
2931 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2932 DFCS_BUTTONCHECK
|DFCS_FLAT
);
2934 SetRect(&rc
, 34, 2, 46, 14);
2935 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2936 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
2938 SelectObject(hdc
, hbmOld
);
2939 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
2940 comctl32_color
.clrWindow
);
2941 TRACE("checkbox index %d\n", nIndex
);
2945 ReleaseDC(0, hdcScreen
);
2947 infoPtr
->stateImageWidth
= 16;
2948 infoPtr
->stateImageHeight
= 16;
2952 TREEVIEW_ResetImageStateIndex(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2954 TREEVIEW_ITEM
*child
= item
->firstChild
;
2956 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2957 item
->state
|= INDEXTOSTATEIMAGEMASK(1);
2961 TREEVIEW_ITEM
*next
= child
->nextSibling
;
2962 TREEVIEW_ResetImageStateIndex(infoPtr
, child
);
2968 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, HDC hdc_ref
)
2974 TRACE("(%p %p)\n", infoPtr
, hdc_ref
);
2976 if ((infoPtr
->dwStyle
& TVS_CHECKBOXES
) && !infoPtr
->himlState
)
2978 TREEVIEW_InitCheckboxes(infoPtr
);
2979 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
2981 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
2982 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
2983 TREEVIEW_UpdateScrollBars(infoPtr
);
2984 TREEVIEW_Invalidate(infoPtr
, NULL
);
2990 GetClientRect(infoPtr
->hwnd
, &rc
);
2991 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
2995 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
2998 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
3001 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
3002 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
3005 EndPaint(infoPtr
->hwnd
, &ps
);
3011 TREEVIEW_PrintClient(TREEVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
3013 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
3015 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwnd
))
3018 if (options
& PRF_ERASEBKGND
)
3019 TREEVIEW_EraseBackground(infoPtr
, hdc
);
3021 if (options
& PRF_CLIENT
)
3024 GetClientRect(infoPtr
->hwnd
, &rc
);
3025 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
3031 /* Sorting **************************************************************/
3033 /***************************************************************************
3034 * Forward the DPA local callback to the treeview owner callback
3037 TREEVIEW_CallBackCompare(const TREEVIEW_ITEM
*first
, const TREEVIEW_ITEM
*second
,
3038 const TVSORTCB
*pCallBackSort
)
3040 /* Forward the call to the client-defined callback */
3041 return pCallBackSort
->lpfnCompare(first
->lParam
,
3043 pCallBackSort
->lParam
);
3046 /***************************************************************************
3047 * Treeview native sort routine: sort on item text.
3050 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
3051 const TREEVIEW_INFO
*infoPtr
)
3053 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
3054 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
3056 if(first
->pszText
&& second
->pszText
)
3057 return lstrcmpiW(first
->pszText
, second
->pszText
);
3058 else if(first
->pszText
)
3060 else if(second
->pszText
)
3066 /* Returns the number of physical children belonging to item. */
3068 TREEVIEW_CountChildren(const TREEVIEW_ITEM
*item
)
3073 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
3079 /* Returns a DPA containing a pointer to each physical child of item in
3080 * sibling order. If item has no children, an empty DPA is returned. */
3082 TREEVIEW_BuildChildDPA(const TREEVIEW_ITEM
*item
)
3086 HDPA list
= DPA_Create(8);
3087 if (list
== 0) return NULL
;
3089 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
3091 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
3101 /***************************************************************************
3102 * Setup the treeview structure with regards of the sort method
3103 * and sort the children of the TV item specified in lParam
3104 * fRecurse: currently unused. Should be zero.
3105 * parent: if pSort!=NULL, should equal pSort->hParent.
3106 * otherwise, item which child items are to be sorted.
3107 * pSort: sort method info. if NULL, sort on item text.
3108 * if non-NULL, sort on item's lParam content, and let the
3109 * application decide what that means. See also TVM_SORTCHILDRENCB.
3113 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, HTREEITEM parent
,
3117 PFNDPACOMPARE pfnCompare
;
3120 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
3121 if (parent
== TVI_ROOT
|| parent
== NULL
)
3122 parent
= infoPtr
->root
;
3124 /* Check for a valid handle to the parent item */
3125 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
3127 ERR("invalid item hParent=%p\n", parent
);
3133 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
3134 lpCompare
= (LPARAM
)pSort
;
3138 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
3139 lpCompare
= (LPARAM
)infoPtr
;
3142 cChildren
= TREEVIEW_CountChildren(parent
);
3144 /* Make sure there is something to sort */
3147 /* TREEVIEW_ITEM rechaining */
3150 HTREEITEM nextItem
= 0;
3151 HTREEITEM prevItem
= 0;
3153 HDPA sortList
= TREEVIEW_BuildChildDPA(parent
);
3155 if (sortList
== NULL
)
3158 /* let DPA sort the list */
3159 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
3161 /* The order of DPA entries has been changed, so fixup the
3162 * nextSibling and prevSibling pointers. */
3164 item
= DPA_GetPtr(sortList
, count
++);
3165 while ((nextItem
= DPA_GetPtr(sortList
, count
++)) != NULL
)
3167 /* link the two current item together */
3168 item
->nextSibling
= nextItem
;
3169 nextItem
->prevSibling
= item
;
3171 if (prevItem
== NULL
)
3173 /* this is the first item, update the parent */
3174 parent
->firstChild
= item
;
3175 item
->prevSibling
= NULL
;
3179 /* fix the back chaining */
3180 item
->prevSibling
= prevItem
;
3183 /* get ready for the next one */
3188 /* the last item is pointed to by item and never has a sibling */
3189 item
->nextSibling
= NULL
;
3190 parent
->lastChild
= item
;
3192 DPA_Destroy(sortList
);
3194 TREEVIEW_VerifyTree(infoPtr
);
3196 if (parent
->state
& TVIS_EXPANDED
)
3198 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3200 if (parent
== infoPtr
->root
)
3201 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3203 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3205 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3207 TREEVIEW_ITEM
*item
;
3209 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3210 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3212 if (item
->visibleOrder
== visOrder
)
3216 if (!item
) item
= parent
->firstChild
;
3217 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3220 TREEVIEW_Invalidate(infoPtr
, NULL
);
3229 /***************************************************************************
3230 * Setup the treeview structure with regards of the sort method
3231 * and sort the children of the TV item specified in lParam
3234 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, LPTVSORTCB pSort
)
3236 return TREEVIEW_Sort(infoPtr
, pSort
->hParent
, pSort
);
3240 /***************************************************************************
3241 * Sort the children of the TV item specified in lParam.
3244 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3246 return TREEVIEW_Sort(infoPtr
, (HTREEITEM
)lParam
, NULL
);
3250 /* Expansion/Collapse ***************************************************/
3253 TREEVIEW_SendExpanding(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3256 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3257 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3258 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3263 TREEVIEW_SendExpanded(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3266 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3267 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3268 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3273 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3274 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3276 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3277 BOOL bRemoveChildren
, BOOL bUser
)
3279 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3280 BOOL bSetSelection
, bSetFirstVisible
;
3282 LONG scrollDist
= 0;
3283 TREEVIEW_ITEM
*nextItem
= NULL
, *tmpItem
;
3286 TRACE("TVE_COLLAPSE %p %s\n", item
, TREEVIEW_ItemName(item
));
3288 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3292 TREEVIEW_SendExpanding(infoPtr
, item
, action
);
3294 if (item
->firstChild
== NULL
)
3297 wasExpanded
= (item
->state
& TVIS_EXPANDED
) != 0;
3298 item
->state
&= ~TVIS_EXPANDED
;
3300 if (wasExpanded
&& bUser
)
3301 TREEVIEW_SendExpanded(infoPtr
, item
, action
);
3303 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3304 && TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
));
3306 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3307 && TREEVIEW_IsChildOf(item
, infoPtr
->firstVisible
));
3312 if (tmpItem
->nextSibling
)
3314 nextItem
= tmpItem
->nextSibling
;
3317 tmpItem
= tmpItem
->parent
;
3321 scrollDist
= nextItem
->rect
.top
;
3323 if (bRemoveChildren
)
3325 INT old_cChildren
= item
->cChildren
;
3326 TRACE("TVE_COLLAPSERESET\n");
3327 item
->state
&= ~TVIS_EXPANDEDONCE
;
3328 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
3329 item
->cChildren
= old_cChildren
;
3334 if (item
->firstChild
)
3336 TREEVIEW_ITEM
*i
, *sibling
;
3338 sibling
= TREEVIEW_GetNextListItem(infoPtr
, item
);
3340 for (i
= item
->firstChild
; i
!= sibling
;
3341 i
= TREEVIEW_GetNextListItem(infoPtr
, i
))
3343 i
->visibleOrder
= -1;
3347 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3350 scrollDist
= -(scrollDist
- nextItem
->rect
.top
);
3354 /* Don't call DoSelectItem, it sends notifications. */
3355 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3356 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3357 item
->state
|= TVIS_SELECTED
;
3358 infoPtr
->selectedItem
= item
;
3361 TREEVIEW_UpdateScrollBars(infoPtr
);
3363 scrollRect
.left
= 0;
3364 scrollRect
.right
= infoPtr
->clientWidth
;
3365 scrollRect
.bottom
= infoPtr
->clientHeight
;
3369 scrollRect
.top
= nextItem
->rect
.top
;
3371 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, &scrollRect
,
3372 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3373 TREEVIEW_Invalidate(infoPtr
, item
);
3375 scrollRect
.top
= item
->rect
.top
;
3376 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, TRUE
);
3379 TREEVIEW_SetFirstVisible(infoPtr
,
3380 bSetFirstVisible
? item
: infoPtr
->firstVisible
,
3387 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3388 BOOL partial
, BOOL user
)
3391 LONG orgNextTop
= 0;
3393 TREEVIEW_ITEM
*nextItem
, *tmpItem
;
3394 BOOL sendsNotifications
;
3396 TRACE("(%p, %p, partial=%d, %d)\n", infoPtr
, item
, partial
, user
);
3398 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3401 tmpItem
= item
; nextItem
= NULL
;
3404 if (tmpItem
->nextSibling
)
3406 nextItem
= tmpItem
->nextSibling
;
3409 tmpItem
= tmpItem
->parent
;
3413 orgNextTop
= nextItem
->rect
.top
;
3415 TRACE("TVE_EXPAND %p %s\n", item
, TREEVIEW_ItemName(item
));
3417 sendsNotifications
= user
|| ((item
->cChildren
!= 0) &&
3418 !(item
->state
& TVIS_EXPANDEDONCE
));
3419 if (sendsNotifications
)
3421 if (!TREEVIEW_SendExpanding(infoPtr
, item
, TVE_EXPAND
))
3423 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3427 if (!item
->firstChild
)
3430 item
->state
|= TVIS_EXPANDED
;
3433 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3435 if (ISVISIBLE(item
))
3437 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3438 TREEVIEW_UpdateSubTree(infoPtr
, item
);
3439 TREEVIEW_UpdateScrollBars(infoPtr
);
3441 scrollRect
.left
= 0;
3442 scrollRect
.bottom
= infoPtr
->treeHeight
;
3443 scrollRect
.right
= infoPtr
->clientWidth
;
3446 scrollDist
= nextItem
->rect
.top
- orgNextTop
;
3447 scrollRect
.top
= orgNextTop
;
3449 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3450 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3451 TREEVIEW_Invalidate (infoPtr
, item
);
3453 scrollRect
.top
= item
->rect
.top
;
3454 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, FALSE
);
3457 /* Scroll up so that as many children as possible are visible.
3458 * This fails when expanding causes an HScroll bar to appear, but we
3459 * don't know that yet, so the last item is obscured. */
3460 if (item
->firstChild
!= NULL
)
3462 int nChildren
= item
->lastChild
->visibleOrder
3463 - item
->firstChild
->visibleOrder
+ 1;
3465 int visible_pos
= item
->visibleOrder
3466 - infoPtr
->firstVisible
->visibleOrder
;
3468 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3470 if (visible_pos
> 0 && nChildren
> rows_below
)
3472 int scroll
= nChildren
- rows_below
;
3474 if (scroll
> visible_pos
)
3475 scroll
= visible_pos
;
3479 TREEVIEW_ITEM
*newFirstVisible
3480 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3484 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3490 if (sendsNotifications
) {
3491 TREEVIEW_SendExpanded(infoPtr
, item
, TVE_EXPAND
);
3492 item
->state
|= TVIS_EXPANDEDONCE
;
3498 /* Handler for TVS_SINGLEEXPAND behaviour. Used on response
3499 to mouse messages and TVM_SELECTITEM.
3501 selection - previously selected item, used to collapse a part of a tree
3502 item - new selected item
3504 static void TREEVIEW_SingleExpand(TREEVIEW_INFO
*infoPtr
,
3505 HTREEITEM selection
, HTREEITEM item
)
3507 TREEVIEW_ITEM
*prev
, *curr
;
3509 if ((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) == 0 || infoPtr
->hwndEdit
|| !item
) return;
3511 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
3514 * Close the previous item and its ancestors as long as they are not
3515 * ancestors of the current item
3517 for (prev
= selection
; prev
&& TREEVIEW_ValidItem(infoPtr
, prev
); prev
= prev
->parent
)
3519 for (curr
= item
; curr
&& TREEVIEW_ValidItem(infoPtr
, curr
); curr
= curr
->parent
)
3524 TREEVIEW_Collapse(infoPtr
, prev
, FALSE
, TRUE
);
3529 * Expand the current item
3531 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3535 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, BOOL user
)
3537 TRACE("item=%p, user=%d\n", item
, user
);
3539 if (item
->state
& TVIS_EXPANDED
)
3540 return TREEVIEW_Collapse(infoPtr
, item
, FALSE
, user
);
3542 return TREEVIEW_Expand(infoPtr
, item
, FALSE
, user
);
3546 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3548 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3550 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3552 if (TREEVIEW_HasChildren(infoPtr
, item
))
3553 TREEVIEW_ExpandAll(infoPtr
, item
);
3557 /* Note:If the specified item is the child of a collapsed parent item,
3558 the parent's list of child items is (recursively) expanded to reveal the
3559 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3560 know if it also applies here.
3564 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM item
)
3566 if (!TREEVIEW_ValidItem(infoPtr
, item
))
3569 TRACE("For (%s) item:%d, flags 0x%x, state:%d\n",
3570 TREEVIEW_ItemName(item
), TREEVIEW_GetItemIndex(infoPtr
, item
),
3573 switch (flag
& TVE_TOGGLE
)
3576 return TREEVIEW_Collapse(infoPtr
, item
, flag
& TVE_COLLAPSERESET
,
3580 return TREEVIEW_Expand(infoPtr
, item
, flag
& TVE_EXPANDPARTIAL
,
3584 return TREEVIEW_Toggle(infoPtr
, item
, FALSE
);
3591 /* Hit-Testing **********************************************************/
3593 static TREEVIEW_ITEM
*
3594 TREEVIEW_HitTestPoint(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3596 TREEVIEW_ITEM
*item
;
3599 if (!infoPtr
->firstVisible
)
3602 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3604 for (item
= infoPtr
->firstVisible
; item
!= NULL
;
3605 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3607 if (row
>= item
->visibleOrder
3608 && row
< item
->visibleOrder
+ item
->iIntegral
)
3616 TREEVIEW_HitTest(const TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3618 TREEVIEW_ITEM
*item
;
3624 GetClientRect(infoPtr
->hwnd
, &rect
);
3631 status
|= TVHT_TOLEFT
;
3633 else if (x
> rect
.right
)
3635 status
|= TVHT_TORIGHT
;
3640 status
|= TVHT_ABOVE
;
3642 else if (y
> rect
.bottom
)
3644 status
|= TVHT_BELOW
;
3649 lpht
->flags
= status
;
3653 item
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3656 lpht
->flags
= TVHT_NOWHERE
;
3660 if (x
>= item
->textOffset
+ item
->textWidth
)
3662 lpht
->flags
= TVHT_ONITEMRIGHT
;
3664 else if (x
>= item
->textOffset
)
3666 lpht
->flags
= TVHT_ONITEMLABEL
;
3668 else if (x
>= item
->imageOffset
)
3670 lpht
->flags
= TVHT_ONITEMICON
;
3672 else if (x
>= item
->stateOffset
)
3674 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3676 else if (x
>= item
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3678 lpht
->flags
= TVHT_ONITEMBUTTON
;
3682 lpht
->flags
= TVHT_ONITEMINDENT
;
3686 TRACE("(%d,%d):result %x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3688 return (LRESULT
)item
;
3691 /* Item Label Editing ***************************************************/
3694 TREEVIEW_GetEditControl(const TREEVIEW_INFO
*infoPtr
)
3696 return (LRESULT
)infoPtr
->hwndEdit
;
3699 static LRESULT CALLBACK
3700 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3702 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3703 BOOL bCancel
= FALSE
;
3709 TRACE("WM_PAINT start\n");
3710 rc
= CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3712 TRACE("WM_PAINT done\n");
3716 if (infoPtr
->bIgnoreEditKillFocus
)
3722 WNDPROC editProc
= infoPtr
->wpEditOrig
;
3723 infoPtr
->wpEditOrig
= 0;
3724 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
3725 return CallWindowProcW(editProc
, hwnd
, uMsg
, wParam
, lParam
);
3729 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3732 if (wParam
== VK_ESCAPE
)
3737 else if (wParam
== VK_RETURN
)
3744 return CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3747 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3748 /* eg. Using a messagebox */
3750 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3751 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3752 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3758 /* should handle edit control messages here */
3761 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3763 TRACE("code=%x, id=%x, handle=%lx\n", HIWORD(wParam
), LOWORD(wParam
), lParam
);
3765 switch (HIWORD(wParam
))
3770 * Adjust the edit window size
3773 TREEVIEW_ITEM
*editItem
= infoPtr
->editItem
;
3774 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3776 HFONT hFont
, hOldFont
= 0;
3778 TRACE("edit=%p\n", infoPtr
->hwndEdit
);
3780 if (!IsWindow(infoPtr
->hwndEdit
) || !hdc
) return FALSE
;
3782 infoPtr
->bLabelChanged
= TRUE
;
3784 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
3786 /* Select font to get the right dimension of the string */
3787 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3791 hOldFont
= SelectObject(hdc
, hFont
);
3794 if (GetTextExtentPoint32W(hdc
, buffer
, strlenW(buffer
), &sz
))
3796 TEXTMETRICW textMetric
;
3798 /* Add Extra spacing for the next character */
3799 GetTextMetricsW(hdc
, &textMetric
);
3800 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3802 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3804 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3806 SetWindowPos(infoPtr
->hwndEdit
,
3811 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3812 SWP_NOMOVE
| SWP_DRAWFRAME
);
3817 SelectObject(hdc
, hOldFont
);
3820 ReleaseDC(infoPtr
->hwnd
, hdc
);
3824 /* apparently we should respect passed handle value */
3825 if (infoPtr
->hwndEdit
!= (HWND
)lParam
) return FALSE
;
3827 TREEVIEW_EndEditLabelNow(infoPtr
, FALSE
);
3831 return SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3838 TREEVIEW_EditLabel(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3840 HWND hwnd
= infoPtr
->hwnd
;
3843 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
);
3846 TEXTMETRICW textMetric
;
3848 TRACE("%p %p\n", hwnd
, hItem
);
3849 if (!(infoPtr
->dwStyle
& TVS_EDITLABELS
))
3852 if (!TREEVIEW_ValidItem(infoPtr
, hItem
))
3855 if (infoPtr
->hwndEdit
)
3856 return infoPtr
->hwndEdit
;
3858 infoPtr
->bLabelChanged
= FALSE
;
3860 /* make edit item visible */
3861 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3863 TREEVIEW_UpdateDispInfo(infoPtr
, hItem
, TVIF_TEXT
);
3866 /* Select the font to get appropriate metric dimensions */
3867 if (infoPtr
->hFont
!= 0)
3869 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3872 /* Get string length in pixels */
3874 GetTextExtentPoint32W(hdc
, hItem
->pszText
, strlenW(hItem
->pszText
),
3877 GetTextExtentPoint32A(hdc
, "", 0, &sz
);
3879 /* Add Extra spacing for the next character */
3880 GetTextMetricsW(hdc
, &textMetric
);
3881 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3883 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3884 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- hItem
->textOffset
+ 2);
3886 if (infoPtr
->hFont
!= 0)
3888 SelectObject(hdc
, hOldFont
);
3891 ReleaseDC(hwnd
, hdc
);
3893 infoPtr
->editItem
= hItem
;
3895 hwndEdit
= CreateWindowExW(WS_EX_LEFT
,
3898 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3899 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3900 ES_LEFT
, hItem
->textOffset
- 2,
3901 hItem
->rect
.top
- 1, sz
.cx
+ 3,
3902 hItem
->rect
.bottom
-
3903 hItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3904 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3906 infoPtr
->hwndEdit
= hwndEdit
;
3908 /* Get a 2D border. */
3909 SetWindowLongW(hwndEdit
, GWL_EXSTYLE
,
3910 GetWindowLongW(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3911 SetWindowLongW(hwndEdit
, GWL_STYLE
,
3912 GetWindowLongW(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3914 SendMessageW(hwndEdit
, WM_SETFONT
,
3915 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, hItem
), FALSE
);
3917 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
,
3919 TREEVIEW_Edit_SubclassProc
);
3921 SetWindowTextW(hwndEdit
, hItem
->pszText
);
3923 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, hItem
))
3925 DestroyWindow(hwndEdit
);
3926 infoPtr
->hwndEdit
= 0;
3927 infoPtr
->editItem
= NULL
;
3932 SendMessageW(hwndEdit
, EM_SETSEL
, 0, -1);
3933 ShowWindow(hwndEdit
, SW_SHOW
);
3940 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3942 TREEVIEW_ITEM
*editedItem
= infoPtr
->editItem
;
3945 WCHAR tmpText
[1024] = { '\0' };
3946 WCHAR
*newText
= tmpText
;
3949 if (!IsWindow(infoPtr
->hwndEdit
)) return FALSE
;
3952 tvdi
.item
.hItem
= editedItem
;
3953 tvdi
.item
.state
= editedItem
->state
;
3954 tvdi
.item
.lParam
= editedItem
->lParam
;
3958 if (!infoPtr
->bNtfUnicode
)
3959 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, (LPSTR
)tmpText
, 1023);
3961 iLength
= GetWindowTextW(infoPtr
->hwndEdit
, tmpText
, 1023);
3963 if (iLength
>= 1023)
3965 ERR("Insufficient space to retrieve new item label\n");
3968 tvdi
.item
.mask
= TVIF_TEXT
;
3969 tvdi
.item
.pszText
= tmpText
;
3970 tvdi
.item
.cchTextMax
= iLength
+ 1;
3974 tvdi
.item
.pszText
= NULL
;
3975 tvdi
.item
.cchTextMax
= 0;
3978 bCommit
= TREEVIEW_SendRealNotify(infoPtr
, TVN_ENDLABELEDITW
, &tvdi
.hdr
);
3980 if (!bCancel
&& bCommit
) /* Apply the changes */
3982 if (!infoPtr
->bNtfUnicode
)
3984 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, NULL
, 0 );
3985 newText
= Alloc(len
* sizeof(WCHAR
));
3986 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, newText
, len
);
3990 if (strcmpW(newText
, editedItem
->pszText
) != 0)
3992 WCHAR
*ptr
= ReAlloc(editedItem
->pszText
, sizeof(WCHAR
)*(iLength
+ 1));
3995 ERR("OutOfMemory, cannot allocate space for label\n");
3996 if(newText
!= tmpText
) Free(newText
);
3997 DestroyWindow(infoPtr
->hwndEdit
);
3998 infoPtr
->hwndEdit
= 0;
3999 infoPtr
->editItem
= NULL
;
4004 editedItem
->pszText
= ptr
;
4005 editedItem
->cchTextMax
= iLength
+ 1;
4006 strcpyW(editedItem
->pszText
, newText
);
4007 TREEVIEW_ComputeTextWidth(infoPtr
, editedItem
, 0);
4010 if(newText
!= tmpText
) Free(newText
);
4013 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
4014 DestroyWindow(infoPtr
->hwndEdit
);
4015 infoPtr
->hwndEdit
= 0;
4016 infoPtr
->editItem
= NULL
;
4021 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4023 if (wParam
!= TV_EDIT_TIMER
)
4025 ERR("got unknown timer\n");
4029 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4030 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
4032 TREEVIEW_EditLabel(infoPtr
, infoPtr
->selectedItem
);
4038 /* Mouse Tracking/Drag **************************************************/
4040 /***************************************************************************
4041 * This is quite unusual piece of code, but that's how it's implemented in
4045 TREEVIEW_TrackMouse(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
4047 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
4048 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
4052 r
.top
= pt
.y
- cyDrag
;
4053 r
.left
= pt
.x
- cxDrag
;
4054 r
.bottom
= pt
.y
+ cyDrag
;
4055 r
.right
= pt
.x
+ cxDrag
;
4057 SetCapture(infoPtr
->hwnd
);
4061 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
4063 if (msg
.message
== WM_MOUSEMOVE
)
4065 pt
.x
= (short)LOWORD(msg
.lParam
);
4066 pt
.y
= (short)HIWORD(msg
.lParam
);
4067 if (PtInRect(&r
, pt
))
4075 else if (msg
.message
>= WM_LBUTTONDOWN
&&
4076 msg
.message
<= WM_RBUTTONDBLCLK
)
4081 DispatchMessageW(&msg
);
4084 if (GetCapture() != infoPtr
->hwnd
)
4094 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4096 TREEVIEW_ITEM
*item
;
4100 SetFocus(infoPtr
->hwnd
);
4102 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4104 /* If there is pending 'edit label' event - kill it now */
4105 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4108 hit
.pt
.x
= (short)LOWORD(lParam
);
4109 hit
.pt
.y
= (short)HIWORD(lParam
);
4111 item
= (TREEVIEW_ITEM
*)TREEVIEW_HitTest(infoPtr
, &hit
);
4114 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, item
));
4116 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
4120 case TVHT_ONITEMRIGHT
:
4121 /* FIXME: we should not have sent NM_DBLCLK in this case. */
4124 case TVHT_ONITEMINDENT
:
4125 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
4131 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
4132 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
4134 while (item
->iLevel
> level
)
4136 item
= item
->parent
;
4142 case TVHT_ONITEMLABEL
:
4143 case TVHT_ONITEMICON
:
4144 case TVHT_ONITEMBUTTON
:
4145 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4148 case TVHT_ONITEMSTATEICON
:
4149 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4150 TREEVIEW_ToggleItemState(infoPtr
, item
);
4152 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4161 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4163 HWND hwnd
= infoPtr
->hwnd
;
4165 BOOL bTrack
, bDoLabelEdit
;
4167 /* If Edit control is active - kill it and return.
4168 * The best way to do it is to set focus to itself.
4169 * Edit control subclassed procedure will automatically call
4172 if (infoPtr
->hwndEdit
)
4178 ht
.pt
.x
= (short)LOWORD(lParam
);
4179 ht
.pt
.y
= (short)HIWORD(lParam
);
4181 TREEVIEW_HitTest(infoPtr
, &ht
);
4182 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
4184 /* update focusedItem and redraw both items */
4185 if(ht
.hItem
&& (ht
.flags
& TVHT_ONITEM
))
4187 infoPtr
->focusedItem
= ht
.hItem
;
4188 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4189 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4192 bTrack
= (ht
.flags
& TVHT_ONITEM
)
4193 && !(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
);
4196 * If the style allows editing and the node is already selected
4197 * and the click occurred on the item label...
4199 bDoLabelEdit
= (infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
4200 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
);
4202 /* Send NM_CLICK right away */
4204 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4207 if (ht
.flags
& TVHT_ONITEMBUTTON
)
4209 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
4213 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
4214 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4216 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
4217 infoPtr
->dropItem
= ht
.hItem
;
4219 /* clean up focusedItem as we dragged and won't select this item */
4220 if(infoPtr
->focusedItem
)
4222 /* refresh the item that was focused */
4223 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4224 infoPtr
->focusedItem
= NULL
;
4226 /* refresh the selected item to return the filled background */
4227 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4234 if (bTrack
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4239 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4240 KillTimer(hwnd
, TV_EDIT_TIMER
);
4242 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
4243 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
4245 else if (ht
.flags
& (TVHT_ONITEMICON
|TVHT_ONITEMLABEL
)) /* select the item if the hit was inside of the icon or text */
4247 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4249 /* Select the current item */
4250 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4251 TREEVIEW_SingleExpand(infoPtr
, selection
, ht
.hItem
);
4253 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4255 /* TVS_CHECKBOXES requires us to toggle the current state */
4256 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4257 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4267 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4271 if (infoPtr
->hwndEdit
)
4273 SetFocus(infoPtr
->hwnd
);
4277 ht
.pt
.x
= (short)LOWORD(lParam
);
4278 ht
.pt
.y
= (short)HIWORD(lParam
);
4280 TREEVIEW_HitTest(infoPtr
, &ht
);
4282 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4286 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4287 infoPtr
->dropItem
= ht
.hItem
;
4292 SetFocus(infoPtr
->hwnd
);
4293 if(!TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
))
4295 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
4296 SendMessageW(infoPtr
->hwndNotify
, WM_CONTEXTMENU
,
4297 (WPARAM
)infoPtr
->hwnd
, (LPARAM
)GetMessagePos());
4305 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4307 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4311 HBITMAP hbmp
, hOldbmp
;
4318 if (!(infoPtr
->himlNormal
))
4321 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4324 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4326 hwtop
= GetDesktopWindow();
4327 htopdc
= GetDC(hwtop
);
4328 hdc
= CreateCompatibleDC(htopdc
);
4330 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4332 if (dragItem
->pszText
)
4333 GetTextExtentPoint32W(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
),
4336 GetTextExtentPoint32A(hdc
, "", 0, &size
);
4338 TRACE("%d %d %s\n", size
.cx
, size
.cy
, debugstr_w(dragItem
->pszText
));
4339 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4340 hOldbmp
= SelectObject(hdc
, hbmp
);
4342 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4347 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4348 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4352 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4353 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4356 /* draw item text */
4358 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4360 if (dragItem
->pszText
)
4361 DrawTextW(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
), &rc
,
4364 SelectObject(hdc
, hOldFont
);
4365 SelectObject(hdc
, hOldbmp
);
4367 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4371 ReleaseDC(hwtop
, htopdc
);
4373 return (LRESULT
)infoPtr
->dragList
;
4376 /* Selection ************************************************************/
4379 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4382 TREEVIEW_ITEM
*prevSelect
;
4384 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4386 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4387 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4388 newSelect
? newSelect
->state
: 0);
4390 /* reset and redraw focusedItem if focusedItem was set so we don't */
4391 /* have to worry about the previously focused item when we set a new one */
4392 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4393 infoPtr
->focusedItem
= NULL
;
4397 case TVGN_CARET
|TVSI_NOSINGLEEXPAND
:
4398 FIXME("TVSI_NOSINGLEEXPAND specified.\n");
4401 prevSelect
= infoPtr
->selectedItem
;
4403 if (prevSelect
== newSelect
) {
4404 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4408 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4411 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4417 prevSelect
->state
&= ~TVIS_SELECTED
;
4419 newSelect
->state
|= TVIS_SELECTED
;
4421 infoPtr
->selectedItem
= newSelect
;
4423 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4425 TREEVIEW_InvalidateItem(infoPtr
, prevSelect
);
4426 TREEVIEW_InvalidateItem(infoPtr
, newSelect
);
4428 TREEVIEW_SendTreeviewNotify(infoPtr
,
4431 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4436 case TVGN_DROPHILITE
:
4437 prevSelect
= infoPtr
->dropItem
;
4440 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4442 infoPtr
->dropItem
= newSelect
;
4445 newSelect
->state
|= TVIS_DROPHILITED
;
4447 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4448 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4451 case TVGN_FIRSTVISIBLE
:
4452 if (newSelect
!= NULL
)
4454 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4455 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4456 TREEVIEW_Invalidate(infoPtr
, NULL
);
4461 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4465 /* FIXME: handle NM_KILLFOCUS etc */
4467 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4469 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4471 if (item
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4474 if (item
== infoPtr
->selectedItem
)
4477 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4479 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4482 TREEVIEW_SingleExpand(infoPtr
, selection
, item
);
4487 /*************************************************************************
4488 * TREEVIEW_ProcessLetterKeys
4490 * Processes keyboard messages generated by pressing the letter keys
4492 * What this does is perform a case insensitive search from the
4493 * current position with the following quirks:
4494 * - If two chars or more are pressed in quick succession we search
4495 * for the corresponding string (e.g. 'abc').
4496 * - If there is a delay we wipe away the current search string and
4497 * restart with just that char.
4498 * - If the user keeps pressing the same character, whether slowly or
4499 * fast, so that the search string is entirely composed of this
4500 * character ('aaaaa' for instance), then we search for first item
4501 * that starting with that character.
4502 * - If the user types the above character in quick succession, then
4503 * we must also search for the corresponding string ('aaaaa'), and
4504 * go to that string if there is a match.
4512 * - The current implementation has a list of characters it will
4513 * accept and it ignores everything else. In particular it will
4514 * ignore accentuated characters which seems to match what
4515 * Windows does. But I'm not sure it makes sense to follow
4517 * - We don't sound a beep when the search fails.
4518 * - The search should start from the focused item, not from the selected
4519 * item. One reason for this is to allow for multiple selections in trees.
4520 * But currently infoPtr->focusedItem does not seem very usable.
4524 * TREEVIEW_ProcessLetterKeys
4526 static INT
TREEVIEW_ProcessLetterKeys(TREEVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
4529 HTREEITEM endidx
,idx
;
4531 WCHAR buffer
[MAX_PATH
];
4532 DWORD timestamp
,elapsed
;
4534 /* simple parameter checking */
4535 if (!charCode
|| !keyData
) return 0;
4537 /* only allow the valid WM_CHARs through */
4538 if (!isalnum(charCode
) &&
4539 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4540 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4541 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4542 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4543 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4544 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4545 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4546 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4547 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4550 /* compute how much time elapsed since last keypress */
4551 timestamp
= GetTickCount();
4552 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4553 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4555 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4558 /* update the search parameters */
4559 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4560 if (elapsed
< KEY_DELAY
) {
4561 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
) / sizeof(WCHAR
)) {
4562 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4564 if (infoPtr
->charCode
!= charCode
) {
4565 infoPtr
->charCode
=charCode
=0;
4568 infoPtr
->charCode
=charCode
;
4569 infoPtr
->szSearchParam
[0]=charCode
;
4570 infoPtr
->nSearchParamLength
=1;
4571 /* Redundant with the 1 char string */
4575 /* and search from the current position */
4577 if (infoPtr
->selectedItem
!= NULL
) {
4578 endidx
=infoPtr
->selectedItem
;
4579 /* if looking for single character match,
4580 * then we must always move forward
4582 if (infoPtr
->nSearchParamLength
== 1)
4583 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4588 idx
=infoPtr
->root
->firstChild
;
4591 /* At the end point, sort out wrapping */
4594 /* If endidx is null, stop at the last item (ie top to bottom) */
4598 /* Otherwise, start again at the very beginning */
4599 idx
=infoPtr
->root
->firstChild
;
4601 /* But if we are stopping on the first child, end now! */
4602 if (idx
== endidx
) break;
4606 ZeroMemory(&item
, sizeof(item
));
4607 item
.mask
= TVIF_TEXT
;
4609 item
.pszText
= buffer
;
4610 item
.cchTextMax
= sizeof(buffer
);
4611 TREEVIEW_GetItemT( infoPtr
, &item
, TRUE
);
4613 /* check for a match */
4614 if (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4617 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4618 (nItem
!= infoPtr
->selectedItem
) &&
4619 (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4620 /* This would work but we must keep looking for a longer match */
4623 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4624 } while (idx
!= endidx
);
4626 if (nItem
!= NULL
) {
4627 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4628 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4635 /* Scrolling ************************************************************/
4638 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4641 BOOL hasFirstVisible
= infoPtr
->firstVisible
!= NULL
;
4642 HTREEITEM newFirstVisible
= NULL
;
4643 int visible_pos
= -1;
4645 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4648 if (!ISVISIBLE(item
))
4650 /* Expand parents as necessary. */
4653 /* see if we are trying to ensure that root is visible */
4654 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4655 parent
= item
->parent
;
4657 parent
= item
; /* this item is the topmost item */
4659 while (parent
!= infoPtr
->root
)
4661 if (!(parent
->state
& TVIS_EXPANDED
))
4662 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, TRUE
);
4664 parent
= parent
->parent
;
4668 viscount
= TREEVIEW_GetVisibleCount(infoPtr
);
4670 TRACE("%p (%s) %d - %d viscount(%d)\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4671 hasFirstVisible
? infoPtr
->firstVisible
->visibleOrder
: -1, viscount
);
4673 if (hasFirstVisible
)
4674 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4676 if (visible_pos
< 0)
4678 /* item is before the start of the list: put it at the top. */
4679 newFirstVisible
= item
;
4681 else if (visible_pos
>= viscount
4682 /* Sometimes, before we are displayed, GVC is 0, causing us to
4683 * spuriously scroll up. */
4684 && visible_pos
> 0 && !(infoPtr
->dwStyle
& TVS_NOSCROLL
) )
4686 /* item is past the end of the list. */
4687 int scroll
= visible_pos
- viscount
;
4689 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4695 /* Scroll window so item's text is visible as much as possible */
4696 /* Calculation of amount of extra space is taken from EditLabel code */
4698 TEXTMETRICW textMetric
;
4699 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4701 x
= item
->textWidth
;
4703 GetTextMetricsW(hdc
, &textMetric
);
4704 ReleaseDC(infoPtr
->hwnd
, hdc
);
4706 x
+= (textMetric
.tmMaxCharWidth
* 2);
4707 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4709 if (item
->textOffset
< 0)
4710 pos
= item
->textOffset
;
4711 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4713 if (x
> infoPtr
->clientWidth
)
4714 pos
= item
->textOffset
;
4716 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4721 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4724 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4726 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4735 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4736 TREEVIEW_ITEM
*newFirstVisible
,
4737 BOOL bUpdateScrollPos
)
4741 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4743 if (newFirstVisible
!= NULL
)
4745 /* Prevent an empty gap from appearing at the bottom... */
4746 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4747 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4751 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4754 /* ... unless we just don't have enough items. */
4755 if (newFirstVisible
== NULL
)
4756 newFirstVisible
= infoPtr
->root
->firstChild
;
4760 if (infoPtr
->firstVisible
!= newFirstVisible
)
4762 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4764 infoPtr
->firstVisible
= newFirstVisible
;
4765 TREEVIEW_Invalidate(infoPtr
, NULL
);
4769 TREEVIEW_ITEM
*item
;
4770 int scroll
= infoPtr
->uItemHeight
*
4771 (infoPtr
->firstVisible
->visibleOrder
4772 - newFirstVisible
->visibleOrder
);
4774 infoPtr
->firstVisible
= newFirstVisible
;
4776 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4777 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4779 item
->rect
.top
+= scroll
;
4780 item
->rect
.bottom
+= scroll
;
4783 if (bUpdateScrollPos
)
4784 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4785 newFirstVisible
->visibleOrder
, TRUE
);
4787 ScrollWindowEx(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
, NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
4792 /************************************************************************
4793 * VScroll is always in units of visible items. i.e. we always have a
4794 * visible item aligned to the top of the control. (Unless we have no
4798 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4800 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4801 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4803 int nScrollCode
= LOWORD(wParam
);
4805 TRACE("wp %lx\n", wParam
);
4807 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4810 if (!oldFirstVisible
)
4812 assert(infoPtr
->root
->firstChild
== NULL
);
4816 switch (nScrollCode
)
4819 newFirstVisible
= infoPtr
->root
->firstChild
;
4823 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4827 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4831 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4835 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4836 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4840 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4841 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4845 case SB_THUMBPOSITION
:
4846 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4847 infoPtr
->root
->firstChild
,
4848 (LONG
)(SHORT
)HIWORD(wParam
));
4855 if (newFirstVisible
!= NULL
)
4857 if (newFirstVisible
!= oldFirstVisible
)
4858 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4859 nScrollCode
!= SB_THUMBTRACK
);
4860 else if (nScrollCode
== SB_THUMBPOSITION
)
4861 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4862 newFirstVisible
->visibleOrder
, TRUE
);
4869 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4872 int scrollX
= infoPtr
->scrollX
;
4873 int nScrollCode
= LOWORD(wParam
);
4875 TRACE("wp %lx\n", wParam
);
4877 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4880 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4881 /* shall never occur */
4888 switch (nScrollCode
)
4891 scrollX
-= infoPtr
->uItemHeight
;
4894 scrollX
+= infoPtr
->uItemHeight
;
4897 scrollX
-= infoPtr
->clientWidth
;
4900 scrollX
+= infoPtr
->clientWidth
;
4904 case SB_THUMBPOSITION
:
4905 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4912 if (scrollX
> maxWidth
)
4914 else if (scrollX
< 0)
4918 if (scrollX
!= infoPtr
->scrollX
)
4920 TREEVIEW_ITEM
*item
;
4921 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4923 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4924 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4926 item
->linesOffset
+= scroll_pixels
;
4927 item
->stateOffset
+= scroll_pixels
;
4928 item
->imageOffset
+= scroll_pixels
;
4929 item
->textOffset
+= scroll_pixels
;
4932 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4933 infoPtr
->scrollX
= scrollX
;
4934 UpdateWindow(infoPtr
->hwnd
);
4937 if (nScrollCode
!= SB_THUMBTRACK
)
4938 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
4944 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4947 UINT pulScrollLines
= 3;
4949 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4950 return DefWindowProcW(infoPtr
->hwnd
, WM_MOUSEWHEEL
, wParam
, lParam
);
4952 if (infoPtr
->firstVisible
== NULL
)
4955 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
4957 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4958 /* if scrolling changes direction, ignore left overs */
4959 if ((wheelDelta
< 0 && infoPtr
->wheelRemainder
< 0) ||
4960 (wheelDelta
> 0 && infoPtr
->wheelRemainder
> 0))
4961 infoPtr
->wheelRemainder
+= wheelDelta
;
4963 infoPtr
->wheelRemainder
= wheelDelta
;
4965 if (infoPtr
->wheelRemainder
&& pulScrollLines
)
4971 lineScroll
= pulScrollLines
* (float)infoPtr
->wheelRemainder
/ WHEEL_DELTA
;
4972 infoPtr
->wheelRemainder
-= WHEEL_DELTA
* lineScroll
/ (int)pulScrollLines
;
4974 newDy
= infoPtr
->firstVisible
->visibleOrder
- lineScroll
;
4975 maxDy
= infoPtr
->maxVisibleOrder
;
4983 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
4988 /* Create/Destroy *******************************************************/
4991 TREEVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
4994 TREEVIEW_INFO
*infoPtr
;
4997 TRACE("wnd %p, style %x\n", hwnd
, GetWindowLongW(hwnd
, GWL_STYLE
));
4999 infoPtr
= Alloc(sizeof(TREEVIEW_INFO
));
5001 if (infoPtr
== NULL
)
5003 ERR("could not allocate info memory!\n");
5007 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
5009 infoPtr
->hwnd
= hwnd
;
5010 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5012 infoPtr
->uNumItems
= 0;
5013 infoPtr
->cdmode
= 0;
5014 infoPtr
->uScrollTime
= 300; /* milliseconds */
5015 infoPtr
->bRedraw
= TRUE
;
5017 GetClientRect(hwnd
, &rcClient
);
5019 /* No scroll bars yet. */
5020 infoPtr
->clientWidth
= rcClient
.right
;
5021 infoPtr
->clientHeight
= rcClient
.bottom
;
5022 infoPtr
->uInternalStatus
= 0;
5024 infoPtr
->treeWidth
= 0;
5025 infoPtr
->treeHeight
= 0;
5027 infoPtr
->uIndent
= MINIMUM_INDENT
;
5028 infoPtr
->selectedItem
= NULL
;
5029 infoPtr
->focusedItem
= NULL
;
5030 infoPtr
->hotItem
= NULL
;
5031 infoPtr
->editItem
= NULL
;
5032 infoPtr
->firstVisible
= NULL
;
5033 infoPtr
->maxVisibleOrder
= 0;
5034 infoPtr
->dropItem
= NULL
;
5035 infoPtr
->insertMarkItem
= NULL
;
5036 infoPtr
->insertBeforeorAfter
= 0;
5039 infoPtr
->scrollX
= 0;
5040 infoPtr
->wheelRemainder
= 0;
5042 infoPtr
->clrBk
= CLR_NONE
; /* use system color */
5043 infoPtr
->clrText
= CLR_NONE
; /* use system color */
5044 infoPtr
->clrLine
= CLR_DEFAULT
;
5045 infoPtr
->clrInsertMark
= CLR_DEFAULT
;
5049 infoPtr
->hwndEdit
= NULL
;
5050 infoPtr
->wpEditOrig
= NULL
;
5051 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
5052 infoPtr
->bLabelChanged
= FALSE
;
5054 infoPtr
->himlNormal
= NULL
;
5055 infoPtr
->himlState
= NULL
;
5056 infoPtr
->normalImageWidth
= 0;
5057 infoPtr
->normalImageHeight
= 0;
5058 infoPtr
->stateImageWidth
= 0;
5059 infoPtr
->stateImageHeight
= 0;
5061 infoPtr
->items
= DPA_Create(16);
5063 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
5064 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW(&lf
);
5065 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
5066 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
5067 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
5068 infoPtr
->hcurHand
= LoadCursorW(NULL
, (LPWSTR
)IDC_HAND
);
5070 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
5072 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
5073 infoPtr
->root
->state
= TVIS_EXPANDED
;
5074 infoPtr
->root
->iLevel
= -1;
5075 infoPtr
->root
->visibleOrder
= -1;
5077 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5078 infoPtr
->hwndToolTip
= 0;
5080 /* Determine what type of notify should be issued (sets infoPtr->bNtfUnicode) */
5081 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
5083 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
5084 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
5085 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
5088 /* Make sure actual scrollbar state is consistent with uInternalStatus */
5089 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
5090 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
5092 OpenThemeData (hwnd
, themeClass
);
5099 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
5103 /* free item data */
5104 TREEVIEW_RemoveTree(infoPtr
);
5105 /* root isn't freed with other items */
5106 TREEVIEW_FreeItem(infoPtr
, infoPtr
->root
);
5107 DPA_Destroy(infoPtr
->items
);
5109 /* tool tip is automatically destroyed: we are its owner */
5111 /* Restore original wndproc */
5112 if (infoPtr
->hwndEdit
)
5113 SetWindowLongPtrW(infoPtr
->hwndEdit
, GWLP_WNDPROC
,
5114 (DWORD_PTR
)infoPtr
->wpEditOrig
);
5116 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
5118 /* Deassociate treeview from the window before doing anything drastic. */
5119 SetWindowLongPtrW(infoPtr
->hwnd
, 0, 0);
5121 DeleteObject(infoPtr
->hDefaultFont
);
5122 DeleteObject(infoPtr
->hBoldFont
);
5123 DeleteObject(infoPtr
->hUnderlineFont
);
5124 DeleteObject(infoPtr
->hBoldUnderlineFont
);
5130 /* Miscellaneous Messages ***********************************************/
5133 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
5141 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
5142 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
5143 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
5144 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
5145 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
5146 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
5147 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
5148 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
5149 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
5153 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
5155 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
5157 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
5159 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
5165 /************************************************************************
5168 * VK_UP Move selection to the previous non-hidden item.
5169 * VK_DOWN Move selection to the next non-hidden item.
5170 * VK_HOME Move selection to the first item.
5171 * VK_END Move selection to the last item.
5172 * VK_LEFT If expanded then collapse, otherwise move to parent.
5173 * VK_RIGHT If collapsed then expand, otherwise move to first child.
5175 * VK_SUBTRACT Collapse.
5176 * VK_MULTIPLY Expand all.
5177 * VK_PRIOR Move up GetVisibleCount items.
5178 * VK_NEXT Move down GetVisibleCount items.
5179 * VK_BACK Move to parent.
5180 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
5183 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
5185 /* If it is non-NULL and different, it will be selected and visible. */
5186 TREEVIEW_ITEM
*newSelection
= NULL
;
5187 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
5188 NMTVKEYDOWN nmkeydown
;
5190 TRACE("%lx\n", wParam
);
5192 nmkeydown
.wVKey
= wParam
;
5193 nmkeydown
.flags
= 0;
5194 TREEVIEW_SendRealNotify(infoPtr
, TVN_KEYDOWN
, &nmkeydown
.hdr
);
5196 if (prevItem
== NULL
)
5199 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
5200 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
5205 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
5207 newSelection
= infoPtr
->root
->firstChild
;
5211 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
5215 TREEVIEW_SendSimpleNotify(infoPtr
, NM_RETURN
);
5219 newSelection
= infoPtr
->root
->firstChild
;
5223 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
5227 if (prevItem
->state
& TVIS_EXPANDED
)
5229 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5231 else if (prevItem
->parent
!= infoPtr
->root
)
5233 newSelection
= prevItem
->parent
;
5238 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
5240 if (!(prevItem
->state
& TVIS_EXPANDED
))
5241 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5244 newSelection
= prevItem
->firstChild
;
5251 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5255 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5259 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5264 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5265 -TREEVIEW_GetVisibleCount(infoPtr
));
5270 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5271 TREEVIEW_GetVisibleCount(infoPtr
));
5275 newSelection
= prevItem
->parent
;
5276 if (newSelection
== infoPtr
->root
)
5277 newSelection
= NULL
;
5281 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5282 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5286 if (newSelection
&& newSelection
!= prevItem
)
5288 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5291 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5299 TREEVIEW_MouseLeave (TREEVIEW_INFO
* infoPtr
)
5301 /* remove hot effect from item */
5302 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5303 infoPtr
->hotItem
= NULL
;
5309 TREEVIEW_MouseMove (TREEVIEW_INFO
* infoPtr
, LPARAM lParam
)
5312 TRACKMOUSEEVENT trackinfo
;
5313 TREEVIEW_ITEM
* item
;
5315 if (!(infoPtr
->dwStyle
& TVS_TRACKSELECT
)) return 0;
5317 /* fill in the TRACKMOUSEEVENT struct */
5318 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5319 trackinfo
.dwFlags
= TME_QUERY
;
5320 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5322 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5323 _TrackMouseEvent(&trackinfo
);
5325 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5326 if(!(trackinfo
.dwFlags
& TME_LEAVE
))
5328 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5329 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5330 /* do it as fast as possible, minimal systimer latency will be used */
5331 trackinfo
.dwHoverTime
= 1;
5333 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5334 /* and can properly deactivate the hot item */
5335 _TrackMouseEvent(&trackinfo
);
5338 pt
.x
= (short)LOWORD(lParam
);
5339 pt
.y
= (short)HIWORD(lParam
);
5341 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5343 if (item
!= infoPtr
->hotItem
)
5345 /* redraw old hot item */
5346 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5347 infoPtr
->hotItem
= item
;
5348 /* redraw new hot item */
5349 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5355 /* Draw themed border */
5356 static BOOL
TREEVIEW_NCPaint (const TREEVIEW_INFO
*infoPtr
, HRGN region
, LPARAM lParam
)
5358 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5362 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
5363 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
5366 return DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)region
, lParam
);
5368 GetWindowRect(infoPtr
->hwnd
, &r
);
5370 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
5371 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
5372 if (region
!= (HRGN
)1)
5373 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
5374 OffsetRect(&r
, -r
.left
, -r
.top
);
5376 dc
= GetDCEx(infoPtr
->hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
5377 OffsetRect(&r
, -r
.left
, -r
.top
);
5379 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
5380 DrawThemeParentBackground(infoPtr
->hwnd
, dc
, &r
);
5381 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
5382 ReleaseDC(infoPtr
->hwnd
, dc
);
5384 /* Call default proc to get the scrollbars etc. painted */
5385 DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
5391 TREEVIEW_Notify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5393 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5395 if (lpnmh
->code
== PGN_CALCSIZE
) {
5396 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5398 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5399 lppgc
->iWidth
= infoPtr
->treeWidth
;
5400 TRACE("got PGN_CALCSIZE, returning horz size = %d, client=%d\n",
5401 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5404 lppgc
->iHeight
= infoPtr
->treeHeight
;
5405 TRACE("got PGN_CALCSIZE, returning vert size = %d, client=%d\n",
5406 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5410 return DefWindowProcW(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5414 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5416 if (wParam
== SIZE_RESTORED
)
5418 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5419 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5421 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5422 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5423 TREEVIEW_UpdateScrollBars(infoPtr
);
5427 FIXME("WM_SIZE flag %lx %lx not handled\n", wParam
, lParam
);
5430 TREEVIEW_Invalidate(infoPtr
, NULL
);
5435 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5437 TRACE("(%lx %lx)\n", wParam
, lParam
);
5439 if (wParam
== GWL_STYLE
)
5441 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5443 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_CHECKBOXES
)
5445 if (dwNewStyle
& TVS_CHECKBOXES
)
5447 TREEVIEW_InitCheckboxes(infoPtr
);
5448 TRACE("checkboxes enabled\n");
5450 /* set all items to state image index 1 */
5451 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
5455 FIXME("tried to disable checkboxes\n");
5459 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5461 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5463 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5464 TRACE("tooltips enabled\n");
5468 DestroyWindow(infoPtr
->hwndToolTip
);
5469 infoPtr
->hwndToolTip
= 0;
5470 TRACE("tooltips disabled\n");
5474 infoPtr
->dwStyle
= dwNewStyle
;
5477 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
5478 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5479 TREEVIEW_UpdateScrollBars(infoPtr
);
5480 TREEVIEW_Invalidate(infoPtr
, NULL
);
5486 TREEVIEW_SetCursor(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5489 TREEVIEW_ITEM
* item
;
5493 ScreenToClient(infoPtr
->hwnd
, &pt
);
5495 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5497 memset(&nmmouse
, 0, sizeof(nmmouse
));
5500 nmmouse
.dwItemSpec
= (DWORD_PTR
)item
;
5501 nmmouse
.dwItemData
= item
->lParam
;
5505 nmmouse
.dwHitInfo
= lParam
;
5506 if (TREEVIEW_SendRealNotify(infoPtr
, NM_SETCURSOR
, &nmmouse
.hdr
))
5509 if (item
&& (infoPtr
->dwStyle
& TVS_TRACKSELECT
))
5511 SetCursor(infoPtr
->hcurHand
);
5515 return DefWindowProcW(infoPtr
->hwnd
, WM_SETCURSOR
, wParam
, lParam
);
5519 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5523 if (!infoPtr
->selectedItem
)
5525 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5529 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5530 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5535 TREEVIEW_KillFocus(const TREEVIEW_INFO
*infoPtr
)
5539 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5540 UpdateWindow(infoPtr
->hwnd
);
5541 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5545 /* update theme after a WM_THEMECHANGED message */
5546 static LRESULT
TREEVIEW_ThemeChanged(const TREEVIEW_INFO
*infoPtr
)
5548 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5549 CloseThemeData (theme
);
5550 OpenThemeData (infoPtr
->hwnd
, themeClass
);
5555 static LRESULT WINAPI
5556 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5558 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5560 TRACE("hwnd %p msg %04x wp=%08lx lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5562 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5565 if (uMsg
== WM_CREATE
)
5566 TREEVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
5573 case TVM_CREATEDRAGIMAGE
:
5574 return TREEVIEW_CreateDragImage(infoPtr
, lParam
);
5576 case TVM_DELETEITEM
:
5577 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5579 case TVM_EDITLABELA
:
5580 case TVM_EDITLABELW
:
5581 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5583 case TVM_ENDEDITLABELNOW
:
5584 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5586 case TVM_ENSUREVISIBLE
:
5587 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5590 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5592 case TVM_GETBKCOLOR
:
5593 return TREEVIEW_GetBkColor(infoPtr
);
5596 return TREEVIEW_GetCount(infoPtr
);
5598 case TVM_GETEDITCONTROL
:
5599 return TREEVIEW_GetEditControl(infoPtr
);
5601 case TVM_GETIMAGELIST
:
5602 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5605 return TREEVIEW_GetIndent(infoPtr
);
5607 case TVM_GETINSERTMARKCOLOR
:
5608 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5610 case TVM_GETISEARCHSTRINGA
:
5611 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5614 case TVM_GETISEARCHSTRINGW
:
5615 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5620 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5621 uMsg
== TVM_GETITEMW
);
5622 case TVM_GETITEMHEIGHT
:
5623 return TREEVIEW_GetItemHeight(infoPtr
);
5625 case TVM_GETITEMRECT
:
5626 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5628 case TVM_GETITEMSTATE
:
5629 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5631 case TVM_GETLINECOLOR
:
5632 return TREEVIEW_GetLineColor(infoPtr
);
5634 case TVM_GETNEXTITEM
:
5635 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5637 case TVM_GETSCROLLTIME
:
5638 return TREEVIEW_GetScrollTime(infoPtr
);
5640 case TVM_GETTEXTCOLOR
:
5641 return TREEVIEW_GetTextColor(infoPtr
);
5643 case TVM_GETTOOLTIPS
:
5644 return TREEVIEW_GetToolTips(infoPtr
);
5646 case TVM_GETUNICODEFORMAT
:
5647 return TREEVIEW_GetUnicodeFormat(infoPtr
);
5649 case TVM_GETVISIBLECOUNT
:
5650 return TREEVIEW_GetVisibleCount(infoPtr
);
5653 return TREEVIEW_HitTest(infoPtr
, (LPTVHITTESTINFO
)lParam
);
5655 case TVM_INSERTITEMA
:
5656 case TVM_INSERTITEMW
:
5657 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
,
5658 uMsg
== TVM_INSERTITEMW
);
5659 case TVM_SELECTITEM
:
5660 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5662 case TVM_SETBKCOLOR
:
5663 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5665 case TVM_SETIMAGELIST
:
5666 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5669 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5671 case TVM_SETINSERTMARK
:
5672 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5674 case TVM_SETINSERTMARKCOLOR
:
5675 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5679 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5680 uMsg
== TVM_SETITEMW
);
5681 case TVM_SETLINECOLOR
:
5682 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5684 case TVM_SETITEMHEIGHT
:
5685 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5687 case TVM_SETSCROLLTIME
:
5688 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5690 case TVM_SETTEXTCOLOR
:
5691 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5693 case TVM_SETTOOLTIPS
:
5694 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5696 case TVM_SETUNICODEFORMAT
:
5697 return TREEVIEW_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
5699 case TVM_SORTCHILDREN
:
5700 return TREEVIEW_SortChildren(infoPtr
, lParam
);
5702 case TVM_SORTCHILDRENCB
:
5703 return TREEVIEW_SortChildrenCB(infoPtr
, (LPTVSORTCB
)lParam
);
5706 return TREEVIEW_ProcessLetterKeys(infoPtr
, wParam
, lParam
);
5709 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5712 return TREEVIEW_Destroy(infoPtr
);
5717 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5720 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5723 return TREEVIEW_GetFont(infoPtr
);
5726 return TREEVIEW_HScroll(infoPtr
, wParam
);
5729 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5732 return TREEVIEW_KillFocus(infoPtr
);
5734 case WM_LBUTTONDBLCLK
:
5735 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5737 case WM_LBUTTONDOWN
:
5738 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5740 /* WM_MBUTTONDOWN */
5743 return TREEVIEW_MouseLeave(infoPtr
);
5746 return TREEVIEW_MouseMove(infoPtr
, lParam
);
5748 case WM_NCLBUTTONDOWN
:
5749 if (infoPtr
->hwndEdit
)
5750 SetFocus(infoPtr
->hwnd
);
5754 return TREEVIEW_NCPaint (infoPtr
, (HRGN
)wParam
, lParam
);
5757 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5759 case WM_NOTIFYFORMAT
:
5760 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5762 case WM_PRINTCLIENT
:
5763 return TREEVIEW_PrintClient(infoPtr
, (HDC
)wParam
, lParam
);
5766 return TREEVIEW_Paint(infoPtr
, (HDC
)wParam
);
5768 case WM_RBUTTONDOWN
:
5769 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5772 return TREEVIEW_SetCursor(infoPtr
, wParam
, lParam
);
5775 return TREEVIEW_SetFocus(infoPtr
);
5778 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5781 return TREEVIEW_SetRedraw(infoPtr
, wParam
);
5784 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5786 case WM_STYLECHANGED
:
5787 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5789 case WM_SYSCOLORCHANGE
:
5790 COMCTL32_RefreshSysColors();
5796 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5798 case WM_THEMECHANGED
:
5799 return TREEVIEW_ThemeChanged (infoPtr
);
5802 return TREEVIEW_VScroll(infoPtr
, wParam
);
5804 /* WM_WININICHANGE */
5807 return TREEVIEW_MouseWheel(infoPtr
, wParam
, lParam
);
5810 TRACE("drawItem\n");
5814 /* This mostly catches MFC and Delphi messages. :( */
5815 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
5816 TRACE("Unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
5818 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
5823 /* Class Registration ***************************************************/
5826 TREEVIEW_Register(void)
5832 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
5833 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5834 wndClass
.lpfnWndProc
= TREEVIEW_WindowProc
;
5835 wndClass
.cbClsExtra
= 0;
5836 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5838 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
5839 wndClass
.hbrBackground
= 0;
5840 wndClass
.lpszClassName
= WC_TREEVIEWW
;
5842 RegisterClassW(&wndClass
);
5847 TREEVIEW_Unregister(void)
5849 UnregisterClassW(WC_TREEVIEWW
, NULL
);
5853 /* Tree Verification ****************************************************/
5856 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
);
5858 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5859 const TREEVIEW_ITEM
*item
)
5861 assert(infoPtr
!= NULL
);
5862 assert(item
!= NULL
);
5864 /* both NULL, or both non-null */
5865 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5867 assert(item
->firstChild
!= item
);
5868 assert(item
->lastChild
!= item
);
5870 if (item
->firstChild
)
5872 assert(item
->firstChild
->parent
== item
);
5873 assert(item
->firstChild
->prevSibling
== NULL
);
5876 if (item
->lastChild
)
5878 assert(item
->lastChild
->parent
== item
);
5879 assert(item
->lastChild
->nextSibling
== NULL
);
5882 assert(item
->nextSibling
!= item
);
5883 if (item
->nextSibling
)
5885 assert(item
->nextSibling
->parent
== item
->parent
);
5886 assert(item
->nextSibling
->prevSibling
== item
);
5889 assert(item
->prevSibling
!= item
);
5890 if (item
->prevSibling
)
5892 assert(item
->prevSibling
->parent
== item
->parent
);
5893 assert(item
->prevSibling
->nextSibling
== item
);
5898 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5900 assert(item
!= NULL
);
5902 assert(item
->parent
!= NULL
);
5903 assert(item
->parent
!= item
);
5904 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5906 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5908 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5910 TREEVIEW_VerifyChildren(infoPtr
, item
);
5914 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5916 const TREEVIEW_ITEM
*child
;
5917 assert(item
!= NULL
);
5919 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5920 TREEVIEW_VerifyItem(infoPtr
, child
);
5924 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5926 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5928 assert(root
!= NULL
);
5929 assert(root
->iLevel
== -1);
5930 assert(root
->parent
== NULL
);
5931 assert(root
->prevSibling
== NULL
);
5933 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
5935 TREEVIEW_VerifyChildren(infoPtr
, root
);
5939 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
5941 if (!TRACE_ON(treeview
)) return;
5943 assert(infoPtr
!= NULL
);
5944 TREEVIEW_VerifyRoot(infoPtr
);