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,
32 * TVN_SETDISPINFO, TVN_SINGLEEXPAND
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.
44 #include "wine/port.h"
53 #define NONAMELESSUNION
54 #define NONAMELESSSTRUCT
64 #include "wine/unicode.h"
65 #include "wine/debug.h"
67 WINE_DEFAULT_DEBUG_CHANNEL(treeview
);
69 /* internal structures */
70 typedef struct tagTREEVIEW_INFO
73 HWND hwndNotify
; /* Owner window to send notifications to */
78 UINT uNumItems
; /* number of valid TREEVIEW_ITEMs */
79 INT cdmode
; /* last custom draw setting */
80 UINT uScrollTime
; /* max. time for scrolling in milliseconds */
81 BOOL bRedraw
; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
83 UINT uItemHeight
; /* item height */
86 LONG clientWidth
; /* width of control window */
87 LONG clientHeight
; /* height of control window */
89 LONG treeWidth
; /* width of visible tree items */
90 LONG treeHeight
; /* height of visible tree items */
92 UINT uIndent
; /* indentation in pixels */
93 HTREEITEM selectedItem
; /* handle to selected item or 0 if none */
94 HTREEITEM hotItem
; /* handle currently under cursor, 0 if none */
95 HTREEITEM focusedItem
; /* item that was under the cursor when WM_LBUTTONDOWN was received */
96 HTREEITEM editItem
; /* item being edited with builtin edit box */
98 HTREEITEM firstVisible
; /* handle to first visible item */
100 HTREEITEM dropItem
; /* handle to item selected by drag cursor */
101 HTREEITEM insertMarkItem
; /* item after which insertion mark is placed */
102 BOOL insertBeforeorAfter
; /* flag used by TVM_SETINSERTMARK */
103 HIMAGELIST dragList
; /* Bitmap of dragged item */
109 COLORREF clrInsertMark
;
113 HFONT hUnderlineFont
;
114 HFONT hBoldUnderlineFont
;
119 WNDPROC wpEditOrig
; /* orig window proc for subclassing edit */
120 BOOL bIgnoreEditKillFocus
;
123 BOOL bNtfUnicode
; /* TRUE if should send NOTIFY with W */
124 HIMAGELIST himlNormal
;
125 int normalImageHeight
;
126 int normalImageWidth
;
127 HIMAGELIST himlState
;
128 int stateImageHeight
;
132 DWORD lastKeyPressTimestamp
;
134 INT nSearchParamLength
;
135 WCHAR szSearchParam
[ MAX_PATH
];
138 typedef struct _TREEITEM
/* HTREEITEM is a _TREEINFO *. */
140 HTREEITEM parent
; /* handle to parent or 0 if at root */
141 HTREEITEM nextSibling
; /* handle to next item in list, 0 if last */
142 HTREEITEM firstChild
; /* handle to first child or 0 if no child */
154 int iIntegral
; /* item height multiplier (1 is normal) */
155 int iLevel
; /* indentation level:0=root level */
157 HTREEITEM prevSibling
; /* handle to prev item in list, 0 if first */
163 LONG textWidth
; /* horizontal text extent for pszText */
164 LONG visibleOrder
; /* visible ordering, 0 is first visible item */
165 const TREEVIEW_INFO
*infoPtr
; /* tree data this item belongs to */
168 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
169 #define KEY_DELAY 450
171 /* bitflags for infoPtr->uInternalStatus */
173 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
174 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
175 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
176 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
177 #define TV_RDRAG 0x10 /* ditto Rbutton */
178 #define TV_RDRAGGING 0x20
180 /* bitflags for infoPtr->timer */
182 #define TV_EDIT_TIMER 2
183 #define TV_EDIT_TIMER_SET 2
185 #define TEXT_CALLBACK_SIZE 260
187 #define TREEVIEW_LEFT_MARGIN 8
189 #define MINIMUM_INDENT 19
191 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
193 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
194 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
195 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
197 #define GETLINECOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrGrayText : (x))
198 #define GETBKCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindow : (x))
199 #define GETTXTCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindowText : (x))
200 #define GETINSCOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrBtnText : (x))
202 static const WCHAR themeClass
[] = { 'T','r','e','e','v','i','e','w',0 };
205 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
208 static VOID
TREEVIEW_Invalidate(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
210 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
211 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
212 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
213 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
214 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
215 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
217 /* Random Utilities *****************************************************/
218 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
220 /* Returns the treeview private data if hwnd is a treeview.
221 * Otherwise returns an undefined value. */
222 static inline TREEVIEW_INFO
*
223 TREEVIEW_GetInfoPtr(HWND hwnd
)
225 return (TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
228 /* Don't call this. Nothing wants an item index. */
230 TREEVIEW_GetItemIndex(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
232 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
235 /* Checks if item has changed and needs to be redrawn */
236 static inline BOOL
item_changed (const TREEVIEW_ITEM
*tiOld
, const TREEVIEW_ITEM
*tiNew
,
237 const TVITEMEXW
*tvChange
)
239 /* Number of children has changed */
240 if ((tvChange
->mask
& TVIF_CHILDREN
) && (tiOld
->cChildren
!= tiNew
->cChildren
))
243 /* Image has changed and it's not a callback */
244 if ((tvChange
->mask
& TVIF_IMAGE
) && (tiOld
->iImage
!= tiNew
->iImage
) &&
245 tiNew
->iImage
!= I_IMAGECALLBACK
)
248 /* Selected image has changed and it's not a callback */
249 if ((tvChange
->mask
& TVIF_SELECTEDIMAGE
) && (tiOld
->iSelectedImage
!= tiNew
->iSelectedImage
) &&
250 tiNew
->iSelectedImage
!= I_IMAGECALLBACK
)
253 if ((tvChange
->mask
& TVIF_EXPANDEDIMAGE
) && (tiOld
->iExpandedImage
!= tiNew
->iExpandedImage
) &&
254 tiNew
->iExpandedImage
!= I_IMAGECALLBACK
)
257 /* Text has changed and it's not a callback */
258 if ((tvChange
->mask
& TVIF_TEXT
) && (tiOld
->pszText
!= tiNew
->pszText
) &&
259 tiNew
->pszText
!= LPSTR_TEXTCALLBACKW
)
262 /* Indent has changed */
263 if ((tvChange
->mask
& TVIF_INTEGRAL
) && (tiOld
->iIntegral
!= tiNew
->iIntegral
))
266 /* Item state has changed */
267 if ((tvChange
->mask
& TVIF_STATE
) && ((tiOld
->state
^ tiNew
->state
) & tvChange
->stateMask
))
273 /***************************************************************************
274 * This method checks that handle is an item for this tree.
277 TREEVIEW_ValidItem(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
279 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
281 TRACE("invalid item %p\n", handle
);
289 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
293 GetObjectW(hOrigFont
, sizeof(font
), &font
);
294 font
.lfWeight
= FW_BOLD
;
295 return CreateFontIndirectW(&font
);
299 TREEVIEW_CreateUnderlineFont(HFONT hOrigFont
)
303 GetObjectW(hOrigFont
, sizeof(font
), &font
);
304 font
.lfUnderline
= TRUE
;
305 return CreateFontIndirectW(&font
);
309 TREEVIEW_CreateBoldUnderlineFont(HFONT hfont
)
313 GetObjectW(hfont
, sizeof(font
), &font
);
314 font
.lfWeight
= FW_BOLD
;
315 font
.lfUnderline
= TRUE
;
316 return CreateFontIndirectW(&font
);
320 TREEVIEW_FontForItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
322 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
323 return item
->state
& TVIS_BOLD
? infoPtr
->hBoldUnderlineFont
: infoPtr
->hUnderlineFont
;
324 if (item
->state
& TVIS_BOLD
)
325 return infoPtr
->hBoldFont
;
326 return infoPtr
->hFont
;
329 /* for trace/debugging purposes only */
331 TREEVIEW_ItemName(const TREEVIEW_ITEM
*item
)
333 if (item
== NULL
) return "<null item>";
334 if (item
->pszText
== LPSTR_TEXTCALLBACKW
) return "<callback>";
335 if (item
->pszText
== NULL
) return "<null>";
336 return debugstr_w(item
->pszText
);
339 /* An item is not a child of itself. */
341 TREEVIEW_IsChildOf(const TREEVIEW_ITEM
*parent
, const TREEVIEW_ITEM
*child
)
345 child
= child
->parent
;
346 if (child
== parent
) return TRUE
;
347 } while (child
!= NULL
);
353 /* Tree Traversal *******************************************************/
355 /***************************************************************************
356 * This method returns the last expanded sibling or child child item
359 static TREEVIEW_ITEM
*
360 TREEVIEW_GetLastListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
362 if (!item
) return NULL
;
364 while (item
->lastChild
)
366 if (item
->state
& TVIS_EXPANDED
)
367 item
= item
->lastChild
;
372 if (item
== infoPtr
->root
)
378 /***************************************************************************
379 * This method returns the previous non-hidden item in the list not
380 * considering the tree hierarchy.
382 static TREEVIEW_ITEM
*
383 TREEVIEW_GetPrevListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
385 if (tvItem
->prevSibling
)
387 /* This item has a prevSibling, get the last item in the sibling's tree. */
388 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
390 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
391 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
397 /* this item does not have a prevSibling, get the parent */
398 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
403 /***************************************************************************
404 * This method returns the next physical item in the treeview not
405 * considering the tree hierarchy.
407 static TREEVIEW_ITEM
*
408 TREEVIEW_GetNextListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
411 * If this item has children and is expanded, return the first child
413 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
415 return tvItem
->firstChild
;
420 * try to get the sibling
422 if (tvItem
->nextSibling
)
423 return tvItem
->nextSibling
;
426 * Otherwise, get the parent's sibling.
428 while (tvItem
->parent
)
430 tvItem
= tvItem
->parent
;
432 if (tvItem
->nextSibling
)
433 return tvItem
->nextSibling
;
439 /***************************************************************************
440 * This method returns the nth item starting at the given item. It returns
441 * the last item (or first) we we run out of items.
443 * Will scroll backward if count is <0.
444 * forward if count is >0.
446 static TREEVIEW_ITEM
*
447 TREEVIEW_GetListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
450 TREEVIEW_ITEM
*(*next_item
)(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
451 TREEVIEW_ITEM
*previousItem
;
453 assert(item
!= NULL
);
457 next_item
= TREEVIEW_GetNextListItem
;
462 next_item
= TREEVIEW_GetPrevListItem
;
470 item
= next_item(infoPtr
, item
);
472 } while (--count
&& item
!= NULL
);
475 return item
? item
: previousItem
;
478 /* Notifications ************************************************************/
480 static INT
get_notifycode(const TREEVIEW_INFO
*infoPtr
, INT code
)
482 if (!infoPtr
->bNtfUnicode
) {
484 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
485 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
486 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
487 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
488 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
489 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
490 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
491 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
492 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
493 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
494 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
495 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
502 TREEVIEW_SendRealNotify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPNMHDR pnmh
)
504 TRACE("wParam=%ld, lParam=%p\n", wParam
, pnmh
);
505 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, wParam
, (LPARAM
)pnmh
);
509 TREEVIEW_SendSimpleNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
)
512 HWND hwnd
= infoPtr
->hwnd
;
515 nmhdr
.hwndFrom
= hwnd
;
516 nmhdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
517 nmhdr
.code
= get_notifycode(infoPtr
, code
);
519 return TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.idFrom
, &nmhdr
);
523 TREEVIEW_TVItemFromItem(const TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMW
*tvItem
, TREEVIEW_ITEM
*item
)
526 tvItem
->hItem
= item
;
527 tvItem
->state
= item
->state
;
528 tvItem
->stateMask
= 0;
529 tvItem
->iImage
= item
->iImage
;
530 tvItem
->iSelectedImage
= item
->iSelectedImage
;
531 tvItem
->cChildren
= item
->cChildren
;
532 tvItem
->lParam
= item
->lParam
;
536 if (!infoPtr
->bNtfUnicode
)
538 tvItem
->cchTextMax
= WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0, NULL
, NULL
);
539 tvItem
->pszText
= Alloc (tvItem
->cchTextMax
);
540 WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, 0, 0 );
544 tvItem
->cchTextMax
= item
->cchTextMax
;
545 tvItem
->pszText
= item
->pszText
;
550 tvItem
->cchTextMax
= 0;
551 tvItem
->pszText
= NULL
;
556 TREEVIEW_SendTreeviewNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
557 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
559 HWND hwnd
= infoPtr
->hwnd
;
563 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
564 code
, action
, oldItem
, newItem
);
566 ZeroMemory(&nmhdr
, sizeof(NMTREEVIEWW
));
568 nmhdr
.hdr
.hwndFrom
= hwnd
;
569 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
570 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
571 nmhdr
.action
= action
;
574 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
577 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
582 ret
= TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.hdr
.idFrom
, &nmhdr
.hdr
);
583 if (!infoPtr
->bNtfUnicode
)
585 Free(nmhdr
.itemOld
.pszText
);
586 Free(nmhdr
.itemNew
.pszText
);
592 TREEVIEW_SendTreeviewDnDNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
,
593 HTREEITEM dragItem
, POINT pt
)
595 HWND hwnd
= infoPtr
->hwnd
;
598 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
600 nmhdr
.hdr
.hwndFrom
= hwnd
;
601 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
602 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
604 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
605 nmhdr
.itemNew
.hItem
= dragItem
;
606 nmhdr
.itemNew
.state
= dragItem
->state
;
607 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
609 nmhdr
.ptDrag
.x
= pt
.x
;
610 nmhdr
.ptDrag
.y
= pt
.y
;
612 return TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.hdr
.idFrom
, &nmhdr
.hdr
);
617 TREEVIEW_SendCustomDrawNotify(const TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
620 HWND hwnd
= infoPtr
->hwnd
;
621 NMTVCUSTOMDRAW nmcdhdr
;
624 TRACE("drawstage:%x hdc:%p\n", dwDrawStage
, hdc
);
626 nmcd
= &nmcdhdr
.nmcd
;
627 nmcd
->hdr
.hwndFrom
= hwnd
;
628 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
629 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
630 nmcd
->dwDrawStage
= dwDrawStage
;
633 nmcd
->dwItemSpec
= 0;
634 nmcd
->uItemState
= 0;
635 nmcd
->lItemlParam
= 0;
636 nmcdhdr
.clrText
= infoPtr
->clrText
;
637 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
640 return TREEVIEW_SendRealNotify(infoPtr
, nmcd
->hdr
.idFrom
, &nmcdhdr
.nmcd
.hdr
);
645 /* FIXME: need to find out when the flags in uItemState need to be set */
648 TREEVIEW_SendCustomDrawItemNotify(const TREEVIEW_INFO
*infoPtr
, HDC hdc
,
649 TREEVIEW_ITEM
*item
, UINT uItemDrawState
,
650 NMTVCUSTOMDRAW
*nmcdhdr
)
652 HWND hwnd
= infoPtr
->hwnd
;
655 DWORD_PTR dwItemSpec
;
658 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
659 dwItemSpec
= (DWORD_PTR
)item
;
661 if (item
->state
& TVIS_SELECTED
)
662 uItemState
|= CDIS_SELECTED
;
663 if (item
== infoPtr
->selectedItem
)
664 uItemState
|= CDIS_FOCUS
;
665 if (item
== infoPtr
->hotItem
)
666 uItemState
|= CDIS_HOT
;
668 nmcd
= &nmcdhdr
->nmcd
;
669 nmcd
->hdr
.hwndFrom
= hwnd
;
670 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
671 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
672 nmcd
->dwDrawStage
= dwDrawStage
;
674 nmcd
->rc
= item
->rect
;
675 nmcd
->dwItemSpec
= dwItemSpec
;
676 nmcd
->uItemState
= uItemState
;
677 nmcd
->lItemlParam
= item
->lParam
;
678 nmcdhdr
->iLevel
= item
->iLevel
;
680 TRACE("drawstage:%x hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
681 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
682 nmcd
->uItemState
, nmcd
->lItemlParam
);
684 return TREEVIEW_SendRealNotify(infoPtr
, nmcd
->hdr
.idFrom
, &nmcdhdr
->nmcd
.hdr
);
688 TREEVIEW_BeginLabelEditNotify(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
690 HWND hwnd
= infoPtr
->hwnd
;
694 tvdi
.hdr
.hwndFrom
= hwnd
;
695 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
696 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_BEGINLABELEDITW
);
698 TREEVIEW_TVItemFromItem(infoPtr
, TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
,
699 &tvdi
.item
, editItem
);
701 ret
= TREEVIEW_SendRealNotify(infoPtr
, tvdi
.hdr
.idFrom
, &tvdi
.hdr
);
703 if (!infoPtr
->bNtfUnicode
)
704 Free(tvdi
.item
.pszText
);
710 TREEVIEW_UpdateDispInfo(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
713 NMTVDISPINFOEXW callback
;
714 HWND hwnd
= infoPtr
->hwnd
;
716 TRACE("mask=0x%x, callbackmask=0x%x\n", mask
, item
->callbackMask
);
717 mask
&= item
->callbackMask
;
719 if (mask
== 0) return;
721 callback
.hdr
.hwndFrom
= hwnd
;
722 callback
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
723 callback
.hdr
.code
= get_notifycode(infoPtr
, TVN_GETDISPINFOW
);
725 /* 'state' always contains valid value, as well as 'lParam'.
726 * All other parameters are uninitialized.
728 callback
.item
.pszText
= item
->pszText
;
729 callback
.item
.cchTextMax
= item
->cchTextMax
;
730 callback
.item
.mask
= mask
;
731 callback
.item
.hItem
= item
;
732 callback
.item
.state
= item
->state
;
733 callback
.item
.lParam
= item
->lParam
;
735 /* If text is changed we need to recalculate textWidth */
736 if (mask
& TVIF_TEXT
)
739 TREEVIEW_SendRealNotify(infoPtr
, callback
.hdr
.idFrom
, &callback
.hdr
);
740 TRACE("resulting code 0x%08x\n", callback
.hdr
.code
);
742 /* It may have changed due to a call to SetItem. */
743 mask
&= item
->callbackMask
;
745 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= item
->pszText
)
747 /* Instead of copying text into our buffer user specified his own */
748 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
751 int len
= MultiByteToWideChar( CP_ACP
, 0,
752 (LPSTR
)callback
.item
.pszText
, -1,
754 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
755 newText
= ReAlloc(item
->pszText
, buflen
);
757 TRACE("returned str %s, len=%d, buflen=%d\n",
758 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
762 item
->pszText
= newText
;
763 MultiByteToWideChar( CP_ACP
, 0,
764 (LPSTR
)callback
.item
.pszText
, -1,
765 item
->pszText
, buflen
/sizeof(WCHAR
));
766 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
768 /* If ReAlloc fails we have nothing to do, but keep original text */
771 int len
= max(lstrlenW(callback
.item
.pszText
) + 1,
773 LPWSTR newText
= ReAlloc(item
->pszText
, len
);
775 TRACE("returned wstr %s, len=%d\n",
776 debugstr_w(callback
.item
.pszText
), len
);
780 item
->pszText
= newText
;
781 strcpyW(item
->pszText
, callback
.item
.pszText
);
782 item
->cchTextMax
= len
;
784 /* If ReAlloc fails we have nothing to do, but keep original text */
787 else if (mask
& TVIF_TEXT
) {
788 /* User put text into our buffer, that is ok unless A string */
789 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
792 int len
= MultiByteToWideChar( CP_ACP
, 0,
793 (LPSTR
)callback
.item
.pszText
, -1,
795 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
796 newText
= Alloc(buflen
);
798 TRACE("same buffer str %s, len=%d, buflen=%d\n",
799 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
803 LPWSTR oldText
= item
->pszText
;
804 item
->pszText
= newText
;
805 MultiByteToWideChar( CP_ACP
, 0,
806 (LPSTR
)callback
.item
.pszText
, -1,
807 item
->pszText
, buflen
/sizeof(WCHAR
));
808 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
814 if (mask
& TVIF_IMAGE
)
815 item
->iImage
= callback
.item
.iImage
;
817 if (mask
& TVIF_SELECTEDIMAGE
)
818 item
->iSelectedImage
= callback
.item
.iSelectedImage
;
820 if (mask
& TVIF_EXPANDEDIMAGE
)
821 item
->iExpandedImage
= callback
.item
.iExpandedImage
;
823 if (mask
& TVIF_CHILDREN
)
824 item
->cChildren
= callback
.item
.cChildren
;
826 if (callback
.item
.mask
& TVIF_STATE
)
828 item
->state
&= ~callback
.item
.stateMask
;
829 item
->state
|= (callback
.item
.state
& callback
.item
.stateMask
);
832 /* These members are now permanently set. */
833 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
834 item
->callbackMask
&= ~callback
.item
.mask
;
837 /***************************************************************************
838 * This function uses cChildren field to decide whether the item has
840 * Note: if this returns TRUE, the child items may not actually exist,
841 * they could be virtual.
843 * Just use item->firstChild to check for physical children.
846 TREEVIEW_HasChildren(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
848 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_CHILDREN
);
850 return item
->cChildren
> 0;
853 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
857 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
859 if (nCommand
!= NF_REQUERY
) return 0;
861 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
862 TRACE("format=%d\n", format
);
864 /* Invalid format returned by NF_QUERY defaults to ANSI*/
865 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
)
868 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
873 /* Item Position ********************************************************/
875 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
877 TREEVIEW_ComputeItemInternalMetrics(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
879 /* has TVS_LINESATROOT and (TVS_HASLINES|TVS_HASBUTTONS) */
880 BOOL lar
= ((infoPtr
->dwStyle
& (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
883 item
->linesOffset
= infoPtr
->uIndent
* (lar
? item
->iLevel
: item
->iLevel
- 1)
885 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
886 item
->imageOffset
= item
->stateOffset
887 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
888 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
892 TREEVIEW_ComputeTextWidth(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
898 /* DRAW's OM docker creates items like this */
899 if (item
->pszText
== NULL
)
911 hdc
= GetDC(infoPtr
->hwnd
);
912 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
915 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
916 item
->textWidth
= sz
.cx
;
920 SelectObject(hdc
, hOldFont
);
926 TREEVIEW_ComputeItemRect(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
928 item
->rect
.top
= infoPtr
->uItemHeight
*
929 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
931 item
->rect
.bottom
= item
->rect
.top
932 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
935 item
->rect
.right
= infoPtr
->clientWidth
;
938 /* We know that only items after start need their order updated. */
940 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
947 start
= infoPtr
->root
->firstChild
;
951 order
= start
->visibleOrder
;
953 for (item
= start
; item
!= NULL
;
954 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
956 if (!ISVISIBLE(item
) && order
> 0)
957 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
958 item
->visibleOrder
= order
;
959 order
+= item
->iIntegral
;
962 infoPtr
->maxVisibleOrder
= order
;
964 for (item
= start
; item
!= NULL
;
965 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
967 TREEVIEW_ComputeItemRect(infoPtr
, item
);
972 /* Update metrics of all items in selected subtree.
973 * root must be expanded
976 TREEVIEW_UpdateSubTree(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
978 TREEVIEW_ITEM
*sibling
;
982 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
985 root
->state
&= ~TVIS_EXPANDED
;
986 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
987 root
->state
|= TVIS_EXPANDED
;
989 hdc
= GetDC(infoPtr
->hwnd
);
990 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
992 for (; root
!= sibling
;
993 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
995 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
997 if (root
->callbackMask
& TVIF_TEXT
)
998 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
1000 if (root
->textWidth
== 0)
1002 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
1003 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
1007 SelectObject(hdc
, hOldFont
);
1008 ReleaseDC(infoPtr
->hwnd
, hdc
);
1011 /* Item Allocation **********************************************************/
1013 static TREEVIEW_ITEM
*
1014 TREEVIEW_AllocateItem(const TREEVIEW_INFO
*infoPtr
)
1016 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
1021 /* I_IMAGENONE would make more sense but this is neither what is
1022 * documented (MSDN doesn't specify) nor what Windows actually does
1023 * (it sets it to zero)... and I can so imagine an application using
1024 * inc/dec to toggle the images. */
1025 newItem
->iImage
= 0;
1026 newItem
->iSelectedImage
= 0;
1027 newItem
->iExpandedImage
= (WORD
)I_IMAGENONE
;
1028 newItem
->infoPtr
= infoPtr
;
1030 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
1039 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
1040 * free item->pszText. */
1042 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1044 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
1045 if (infoPtr
->selectedItem
== item
)
1046 infoPtr
->selectedItem
= NULL
;
1047 if (infoPtr
->hotItem
== item
)
1048 infoPtr
->hotItem
= NULL
;
1049 if (infoPtr
->focusedItem
== item
)
1050 infoPtr
->focusedItem
= NULL
;
1051 if (infoPtr
->firstVisible
== item
)
1052 infoPtr
->firstVisible
= NULL
;
1053 if (infoPtr
->dropItem
== item
)
1054 infoPtr
->dropItem
= NULL
;
1055 if (infoPtr
->insertMarkItem
== item
)
1056 infoPtr
->insertMarkItem
= NULL
;
1061 /* Item Insertion *******************************************************/
1063 /***************************************************************************
1064 * This method inserts newItem before sibling as a child of parent.
1065 * sibling can be NULL, but only if parent has no children.
1068 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1069 TREEVIEW_ITEM
*parent
)
1071 assert(parent
!= NULL
);
1073 if (sibling
!= NULL
)
1075 assert(sibling
->parent
== parent
);
1077 if (sibling
->prevSibling
!= NULL
)
1078 sibling
->prevSibling
->nextSibling
= newItem
;
1080 newItem
->prevSibling
= sibling
->prevSibling
;
1081 sibling
->prevSibling
= newItem
;
1084 newItem
->prevSibling
= NULL
;
1086 newItem
->nextSibling
= sibling
;
1088 if (parent
->firstChild
== sibling
)
1089 parent
->firstChild
= newItem
;
1091 if (parent
->lastChild
== NULL
)
1092 parent
->lastChild
= newItem
;
1095 /***************************************************************************
1096 * This method inserts newItem after sibling as a child of parent.
1097 * sibling can be NULL, but only if parent has no children.
1100 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1101 TREEVIEW_ITEM
*parent
)
1103 assert(parent
!= NULL
);
1105 if (sibling
!= NULL
)
1107 assert(sibling
->parent
== parent
);
1109 if (sibling
->nextSibling
!= NULL
)
1110 sibling
->nextSibling
->prevSibling
= newItem
;
1112 newItem
->nextSibling
= sibling
->nextSibling
;
1113 sibling
->nextSibling
= newItem
;
1116 newItem
->nextSibling
= NULL
;
1118 newItem
->prevSibling
= sibling
;
1120 if (parent
->lastChild
== sibling
)
1121 parent
->lastChild
= newItem
;
1123 if (parent
->firstChild
== NULL
)
1124 parent
->firstChild
= newItem
;
1128 TREEVIEW_DoSetItemT(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
1129 const TVITEMEXW
*tvItem
, BOOL isW
)
1131 UINT callbackClear
= 0;
1132 UINT callbackSet
= 0;
1134 TRACE("item %p\n", item
);
1135 /* Do this first in case it fails. */
1136 if (tvItem
->mask
& TVIF_TEXT
)
1138 item
->textWidth
= 0; /* force width recalculation */
1139 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKW
&& tvItem
->pszText
!= NULL
) /* covers != TEXTCALLBACKA too, and undocumented: pszText of NULL also means TEXTCALLBACK */
1144 len
= lstrlenW(tvItem
->pszText
) + 1;
1146 len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1, NULL
, 0);
1148 newText
= ReAlloc(item
->pszText
, len
* sizeof(WCHAR
));
1150 if (newText
== NULL
) return FALSE
;
1152 callbackClear
|= TVIF_TEXT
;
1154 item
->pszText
= newText
;
1155 item
->cchTextMax
= len
;
1157 lstrcpynW(item
->pszText
, tvItem
->pszText
, len
);
1159 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1,
1160 item
->pszText
, len
);
1162 TRACE("setting text %s, item %p\n", debugstr_w(item
->pszText
), item
);
1166 callbackSet
|= TVIF_TEXT
;
1168 item
->pszText
= ReAlloc(item
->pszText
,
1169 TEXT_CALLBACK_SIZE
* sizeof(WCHAR
));
1170 item
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1171 TRACE("setting callback, item %p\n", item
);
1175 if (tvItem
->mask
& TVIF_CHILDREN
)
1177 item
->cChildren
= tvItem
->cChildren
;
1179 if (item
->cChildren
== I_CHILDRENCALLBACK
)
1180 callbackSet
|= TVIF_CHILDREN
;
1182 callbackClear
|= TVIF_CHILDREN
;
1185 if (tvItem
->mask
& TVIF_IMAGE
)
1187 item
->iImage
= tvItem
->iImage
;
1189 if (item
->iImage
== I_IMAGECALLBACK
)
1190 callbackSet
|= TVIF_IMAGE
;
1192 callbackClear
|= TVIF_IMAGE
;
1195 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1197 item
->iSelectedImage
= tvItem
->iSelectedImage
;
1199 if (item
->iSelectedImage
== I_IMAGECALLBACK
)
1200 callbackSet
|= TVIF_SELECTEDIMAGE
;
1202 callbackClear
|= TVIF_SELECTEDIMAGE
;
1205 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
1207 item
->iExpandedImage
= tvItem
->iExpandedImage
;
1209 if (item
->iExpandedImage
== I_IMAGECALLBACK
)
1210 callbackSet
|= TVIF_EXPANDEDIMAGE
;
1212 callbackClear
|= TVIF_EXPANDEDIMAGE
;
1215 if (tvItem
->mask
& TVIF_PARAM
)
1216 item
->lParam
= tvItem
->lParam
;
1218 /* If the application sets TVIF_INTEGRAL without
1219 * supplying a TVITEMEX structure, it's toast. */
1220 if (tvItem
->mask
& TVIF_INTEGRAL
)
1221 item
->iIntegral
= tvItem
->iIntegral
;
1223 if (tvItem
->mask
& TVIF_STATE
)
1225 TRACE("prevstate,state,mask:%x,%x,%x\n", item
->state
, tvItem
->state
,
1227 item
->state
&= ~tvItem
->stateMask
;
1228 item
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1231 if (tvItem
->mask
& TVIF_STATEEX
)
1233 FIXME("New extended state: %x\n", tvItem
->uStateEx
);
1236 item
->callbackMask
|= callbackSet
;
1237 item
->callbackMask
&= ~callbackClear
;
1242 /* Note that the new item is pre-zeroed. */
1244 TREEVIEW_InsertItemT(TREEVIEW_INFO
*infoPtr
, const TVINSERTSTRUCTW
*ptdi
, BOOL isW
)
1246 const TVITEMEXW
*tvItem
= &ptdi
->u
.itemex
;
1247 HTREEITEM insertAfter
;
1248 TREEVIEW_ITEM
*newItem
, *parentItem
;
1249 BOOL bTextUpdated
= FALSE
;
1251 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1253 parentItem
= infoPtr
->root
;
1257 parentItem
= ptdi
->hParent
;
1259 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1261 WARN("invalid parent %p\n", parentItem
);
1266 insertAfter
= ptdi
->hInsertAfter
;
1268 /* Validate this now for convenience. */
1269 switch ((DWORD_PTR
)insertAfter
)
1271 case (DWORD_PTR
)TVI_FIRST
:
1272 case (DWORD_PTR
)TVI_LAST
:
1273 case (DWORD_PTR
)TVI_SORT
:
1277 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1278 insertAfter
->parent
!= parentItem
)
1280 WARN("invalid insert after %p\n", insertAfter
);
1281 insertAfter
= TVI_LAST
;
1285 TRACE("parent %p position %p: %s\n", parentItem
, insertAfter
,
1286 (tvItem
->mask
& TVIF_TEXT
)
1287 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKW
) ? "<callback>"
1288 : (isW
? debugstr_w(tvItem
->pszText
) : debugstr_a((LPSTR
)tvItem
->pszText
)))
1291 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1292 if (newItem
== NULL
)
1295 newItem
->parent
= parentItem
;
1296 newItem
->iIntegral
= 1;
1297 newItem
->visibleOrder
= -1;
1299 if (!TREEVIEW_DoSetItemT(infoPtr
, newItem
, tvItem
, isW
))
1302 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1304 infoPtr
->uNumItems
++;
1306 switch ((DWORD_PTR
)insertAfter
)
1308 case (DWORD_PTR
)TVI_FIRST
:
1310 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1311 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1312 if (infoPtr
->firstVisible
== originalFirst
)
1313 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1317 case (DWORD_PTR
)TVI_LAST
:
1318 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1321 /* hInsertAfter names a specific item we want to insert after */
1323 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1326 case (DWORD_PTR
)TVI_SORT
:
1328 TREEVIEW_ITEM
*aChild
;
1329 TREEVIEW_ITEM
*previousChild
= NULL
;
1330 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1331 BOOL bItemInserted
= FALSE
;
1333 aChild
= parentItem
->firstChild
;
1335 bTextUpdated
= TRUE
;
1336 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1338 /* Iterate the parent children to see where we fit in */
1339 while (aChild
!= NULL
)
1343 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1344 comp
= lstrcmpW(newItem
->pszText
, aChild
->pszText
);
1346 if (comp
< 0) /* we are smaller than the current one */
1348 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1349 if (infoPtr
->firstVisible
== originalFirst
&&
1350 aChild
== originalFirst
)
1351 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1352 bItemInserted
= TRUE
;
1355 else if (comp
> 0) /* we are bigger than the current one */
1357 previousChild
= aChild
;
1359 /* This will help us to exit if there is no more sibling */
1360 aChild
= (aChild
->nextSibling
== 0)
1362 : aChild
->nextSibling
;
1364 /* Look at the next item */
1370 * An item with this name is already existing, therefore,
1371 * we add after the one we found
1373 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1374 bItemInserted
= TRUE
;
1380 * we reach the end of the child list and the item has not
1381 * yet been inserted, therefore, insert it after the last child.
1383 if ((!bItemInserted
) && (aChild
== NULL
))
1384 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1391 TRACE("new item %p; parent %p, mask %x\n", newItem
,
1392 newItem
->parent
, tvItem
->mask
);
1394 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1396 if (newItem
->parent
->cChildren
== 0)
1397 newItem
->parent
->cChildren
= 1;
1399 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1401 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1402 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1405 if (infoPtr
->firstVisible
== NULL
)
1406 infoPtr
->firstVisible
= newItem
;
1408 TREEVIEW_VerifyTree(infoPtr
);
1410 if (!infoPtr
->bRedraw
) return (LRESULT
)newItem
;
1412 if (parentItem
== infoPtr
->root
||
1413 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1415 TREEVIEW_ITEM
*item
;
1416 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1418 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1419 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1422 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1424 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1425 TREEVIEW_UpdateScrollBars(infoPtr
);
1427 * if the item was inserted in a visible part of the tree,
1428 * invalidate it, as well as those after it
1430 for (item
= newItem
;
1432 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1433 TREEVIEW_Invalidate(infoPtr
, item
);
1437 /* refresh treeview if newItem is the first item inserted under parentItem */
1438 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1440 /* parent got '+' - update it */
1441 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1445 return (LRESULT
)newItem
;
1448 /* Item Deletion ************************************************************/
1450 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
1453 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*parentItem
)
1455 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1457 while (kill
!= NULL
)
1459 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1461 TREEVIEW_RemoveItem(infoPtr
, kill
);
1466 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1467 assert(parentItem
->firstChild
== NULL
);
1468 assert(parentItem
->lastChild
== NULL
);
1472 TREEVIEW_UnlinkItem(const TREEVIEW_ITEM
*item
)
1474 TREEVIEW_ITEM
*parentItem
= item
->parent
;
1476 assert(item
!= NULL
);
1477 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1479 if (parentItem
->firstChild
== item
)
1480 parentItem
->firstChild
= item
->nextSibling
;
1482 if (parentItem
->lastChild
== item
)
1483 parentItem
->lastChild
= item
->prevSibling
;
1485 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1486 && parentItem
->cChildren
> 0)
1487 parentItem
->cChildren
= 0;
1489 if (item
->prevSibling
)
1490 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1492 if (item
->nextSibling
)
1493 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1497 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1499 TRACE("%p, (%s)\n", item
, TREEVIEW_ItemName(item
));
1501 if (item
->firstChild
)
1502 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
1504 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1505 TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
1507 TREEVIEW_UnlinkItem(item
);
1509 infoPtr
->uNumItems
--;
1511 if (item
->pszText
!= LPSTR_TEXTCALLBACKW
)
1512 Free(item
->pszText
);
1514 TREEVIEW_FreeItem(infoPtr
, item
);
1518 /* Empty out the tree. */
1520 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1522 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1524 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1528 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
)
1530 TREEVIEW_ITEM
*newSelection
= NULL
;
1531 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1532 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1533 BOOL visible
= FALSE
;
1535 if (item
== TVI_ROOT
|| !item
)
1537 TRACE("TVI_ROOT\n");
1538 parent
= infoPtr
->root
;
1539 newSelection
= NULL
;
1541 TREEVIEW_RemoveTree(infoPtr
);
1545 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1548 TRACE("%p (%s)\n", item
, TREEVIEW_ItemName(item
));
1549 parent
= item
->parent
;
1551 if (ISVISIBLE(item
))
1553 prev
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
1557 if (infoPtr
->selectedItem
!= NULL
1558 && (item
== infoPtr
->selectedItem
1559 || TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
)))
1561 if (item
->nextSibling
)
1562 newSelection
= item
->nextSibling
;
1563 else if (item
->parent
!= infoPtr
->root
)
1564 newSelection
= item
->parent
;
1566 newSelection
= item
->prevSibling
;
1567 TRACE("newSelection = %p\n", newSelection
);
1570 if (infoPtr
->firstVisible
== item
)
1572 if (item
->nextSibling
)
1573 newFirstVisible
= item
->nextSibling
;
1574 else if (item
->prevSibling
)
1575 newFirstVisible
= item
->prevSibling
;
1576 else if (item
->parent
!= infoPtr
->root
)
1577 newFirstVisible
= item
->parent
;
1578 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1581 newFirstVisible
= infoPtr
->firstVisible
;
1583 TREEVIEW_RemoveItem(infoPtr
, item
);
1586 /* Don't change if somebody else already has (infoPtr->selectedItem is cleared by FreeItem). */
1587 if (!infoPtr
->selectedItem
&& newSelection
)
1589 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1590 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1593 /* Validate insertMark dropItem.
1594 * hotItem ??? - used for comparison only.
1596 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1597 infoPtr
->insertMarkItem
= 0;
1599 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1600 infoPtr
->dropItem
= 0;
1602 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1603 newFirstVisible
= infoPtr
->root
->firstChild
;
1605 TREEVIEW_VerifyTree(infoPtr
);
1607 if (!infoPtr
->bRedraw
) return TRUE
;
1611 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1612 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1613 TREEVIEW_UpdateScrollBars(infoPtr
);
1614 TREEVIEW_Invalidate(infoPtr
, NULL
);
1616 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1618 /* parent lost '+/-' - update it */
1619 TREEVIEW_Invalidate(infoPtr
, parent
);
1626 /* Get/Set Messages *********************************************************/
1628 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
)
1630 infoPtr
->bRedraw
= wParam
!= 0;
1632 if (infoPtr
->bRedraw
)
1634 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1635 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1636 TREEVIEW_UpdateScrollBars(infoPtr
);
1637 TREEVIEW_Invalidate(infoPtr
, NULL
);
1643 TREEVIEW_GetIndent(const TREEVIEW_INFO
*infoPtr
)
1646 return infoPtr
->uIndent
;
1650 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1654 if (newIndent
< MINIMUM_INDENT
)
1655 newIndent
= MINIMUM_INDENT
;
1657 if (infoPtr
->uIndent
!= newIndent
)
1659 infoPtr
->uIndent
= newIndent
;
1660 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1661 TREEVIEW_UpdateScrollBars(infoPtr
);
1662 TREEVIEW_Invalidate(infoPtr
, NULL
);
1670 TREEVIEW_GetToolTips(const TREEVIEW_INFO
*infoPtr
)
1673 return (LRESULT
)infoPtr
->hwndToolTip
;
1677 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1682 prevToolTip
= infoPtr
->hwndToolTip
;
1683 infoPtr
->hwndToolTip
= hwndTT
;
1685 return (LRESULT
)prevToolTip
;
1689 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO
*infoPtr
, BOOL fUnicode
)
1691 BOOL rc
= infoPtr
->bNtfUnicode
;
1692 infoPtr
->bNtfUnicode
= fUnicode
;
1697 TREEVIEW_GetUnicodeFormat(const TREEVIEW_INFO
*infoPtr
)
1699 return infoPtr
->bNtfUnicode
;
1703 TREEVIEW_GetScrollTime(const TREEVIEW_INFO
*infoPtr
)
1705 return infoPtr
->uScrollTime
;
1709 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1711 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1713 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1715 return uOldScrollTime
;
1720 TREEVIEW_GetImageList(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1727 return (LRESULT
)infoPtr
->himlNormal
;
1730 return (LRESULT
)infoPtr
->himlState
;
1737 #define TVHEIGHT_MIN 16
1738 #define TVHEIGHT_FONT_ADJUST 3 /* 2 for focus border + 1 for margin some apps assume */
1740 /* Compute the natural height for items. */
1742 TREEVIEW_NaturalHeight(const TREEVIEW_INFO
*infoPtr
)
1746 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1749 /* Height is the maximum of:
1750 * 16 (a hack because our fonts are tiny), and
1751 * The text height + border & margin, and
1752 * The size of the normal image list
1754 GetTextMetricsW(hdc
, &tm
);
1755 SelectObject(hdc
, hOldFont
);
1758 height
= TVHEIGHT_MIN
;
1759 if (height
< tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
)
1760 height
= tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
;
1761 if (height
< infoPtr
->normalImageHeight
)
1762 height
= infoPtr
->normalImageHeight
;
1764 /* Round down, unless we support odd ("non even") heights. */
1765 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1772 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, UINT type
, HIMAGELIST himlNew
)
1774 HIMAGELIST himlOld
= 0;
1775 int oldWidth
= infoPtr
->normalImageWidth
;
1776 int oldHeight
= infoPtr
->normalImageHeight
;
1778 TRACE("%u,%p\n", type
, himlNew
);
1783 himlOld
= infoPtr
->himlNormal
;
1784 infoPtr
->himlNormal
= himlNew
;
1787 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1788 &infoPtr
->normalImageHeight
);
1791 infoPtr
->normalImageWidth
= 0;
1792 infoPtr
->normalImageHeight
= 0;
1798 himlOld
= infoPtr
->himlState
;
1799 infoPtr
->himlState
= himlNew
;
1802 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1803 &infoPtr
->stateImageHeight
);
1806 infoPtr
->stateImageWidth
= 0;
1807 infoPtr
->stateImageHeight
= 0;
1813 ERR("unknown imagelist type %u\n", type
);
1816 if (oldWidth
!= infoPtr
->normalImageWidth
||
1817 oldHeight
!= infoPtr
->normalImageHeight
)
1819 BOOL bRecalcVisible
= FALSE
;
1821 if (oldHeight
!= infoPtr
->normalImageHeight
&&
1822 !infoPtr
->bHeightSet
)
1824 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1825 bRecalcVisible
= TRUE
;
1828 if (infoPtr
->normalImageWidth
> MINIMUM_INDENT
&&
1829 infoPtr
->normalImageWidth
!= infoPtr
->uIndent
)
1831 infoPtr
->uIndent
= infoPtr
->normalImageWidth
;
1832 bRecalcVisible
= TRUE
;
1836 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1838 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1839 TREEVIEW_UpdateScrollBars(infoPtr
);
1842 TREEVIEW_Invalidate(infoPtr
, NULL
);
1844 return (LRESULT
)himlOld
;
1848 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1850 INT prevHeight
= infoPtr
->uItemHeight
;
1852 TRACE("new=%d, old=%d\n", newHeight
, prevHeight
);
1853 if (newHeight
== -1)
1855 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1856 infoPtr
->bHeightSet
= FALSE
;
1860 if (newHeight
== 0) newHeight
= 1;
1861 infoPtr
->uItemHeight
= newHeight
;
1862 infoPtr
->bHeightSet
= TRUE
;
1865 /* Round down, unless we support odd ("non even") heights. */
1866 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
) && infoPtr
->uItemHeight
!= 1)
1868 infoPtr
->uItemHeight
&= ~1;
1869 TRACE("after rounding=%d\n", infoPtr
->uItemHeight
);
1872 if (infoPtr
->uItemHeight
!= prevHeight
)
1874 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1875 TREEVIEW_UpdateScrollBars(infoPtr
);
1876 TREEVIEW_Invalidate(infoPtr
, NULL
);
1883 TREEVIEW_GetItemHeight(const TREEVIEW_INFO
*infoPtr
)
1886 return infoPtr
->uItemHeight
;
1891 TREEVIEW_GetFont(const TREEVIEW_INFO
*infoPtr
)
1893 TRACE("%p\n", infoPtr
->hFont
);
1894 return (LRESULT
)infoPtr
->hFont
;
1899 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1903 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1909 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1911 UINT uHeight
= infoPtr
->uItemHeight
;
1913 TRACE("%p %i\n", hFont
, bRedraw
);
1915 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
1917 DeleteObject(infoPtr
->hBoldFont
);
1918 DeleteObject(infoPtr
->hUnderlineFont
);
1919 DeleteObject(infoPtr
->hBoldUnderlineFont
);
1920 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1921 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
1922 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
1924 if (!infoPtr
->bHeightSet
)
1925 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1927 if (uHeight
!= infoPtr
->uItemHeight
)
1928 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1930 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1932 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1933 TREEVIEW_UpdateScrollBars(infoPtr
);
1936 TREEVIEW_Invalidate(infoPtr
, NULL
);
1943 TREEVIEW_GetLineColor(const TREEVIEW_INFO
*infoPtr
)
1946 return (LRESULT
)infoPtr
->clrLine
;
1950 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1952 COLORREF prevColor
= infoPtr
->clrLine
;
1955 infoPtr
->clrLine
= color
;
1956 return (LRESULT
)prevColor
;
1961 TREEVIEW_GetTextColor(const TREEVIEW_INFO
*infoPtr
)
1964 return (LRESULT
)infoPtr
->clrText
;
1968 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1970 COLORREF prevColor
= infoPtr
->clrText
;
1973 infoPtr
->clrText
= color
;
1975 if (infoPtr
->clrText
!= prevColor
)
1976 TREEVIEW_Invalidate(infoPtr
, NULL
);
1978 return (LRESULT
)prevColor
;
1983 TREEVIEW_GetBkColor(const TREEVIEW_INFO
*infoPtr
)
1986 return (LRESULT
)infoPtr
->clrBk
;
1990 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1992 COLORREF prevColor
= infoPtr
->clrBk
;
1995 infoPtr
->clrBk
= newColor
;
1997 if (newColor
!= prevColor
)
1998 TREEVIEW_Invalidate(infoPtr
, NULL
);
2000 return (LRESULT
)prevColor
;
2005 TREEVIEW_GetInsertMarkColor(const TREEVIEW_INFO
*infoPtr
)
2008 return (LRESULT
)infoPtr
->clrInsertMark
;
2012 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
2014 COLORREF prevColor
= infoPtr
->clrInsertMark
;
2016 TRACE("%x\n", color
);
2017 infoPtr
->clrInsertMark
= color
;
2019 return (LRESULT
)prevColor
;
2024 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
2026 TRACE("%d %p\n", wParam
, item
);
2028 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2031 infoPtr
->insertBeforeorAfter
= wParam
;
2032 infoPtr
->insertMarkItem
= item
;
2034 TREEVIEW_Invalidate(infoPtr
, NULL
);
2040 /************************************************************************
2041 * Some serious braindamage here. lParam is a pointer to both the
2042 * input HTREEITEM and the output RECT.
2045 TREEVIEW_GetItemRect(const TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
2047 TREEVIEW_ITEM
*item
;
2048 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
2056 if (!TREEVIEW_ValidItem(infoPtr
, item
) || !ISVISIBLE(item
))
2060 * If wParam is TRUE return the text size otherwise return
2061 * the whole item size
2065 /* Windows does not send TVN_GETDISPINFO here. */
2067 lpRect
->top
= item
->rect
.top
;
2068 lpRect
->bottom
= item
->rect
.bottom
;
2070 lpRect
->left
= item
->textOffset
;
2071 if (!item
->textWidth
)
2072 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2074 lpRect
->right
= item
->textOffset
+ item
->textWidth
+ 4;
2078 *lpRect
= item
->rect
;
2081 TRACE("%s [%s]\n", fTextRect
? "text" : "item", wine_dbgstr_rect(lpRect
));
2086 static inline LRESULT
2087 TREEVIEW_GetVisibleCount(const TREEVIEW_INFO
*infoPtr
)
2089 /* Surprise! This does not take integral height into account. */
2090 TRACE("client=%d, item=%d\n", infoPtr
->clientHeight
, infoPtr
->uItemHeight
);
2091 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2096 TREEVIEW_GetItemT(const TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2098 TREEVIEW_ITEM
*item
= tvItem
->hItem
;
2100 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2102 if (!item
) return FALSE
;
2104 TRACE("got item from different tree %p, called from %p\n", item
->infoPtr
, infoPtr
);
2105 infoPtr
= item
->infoPtr
;
2106 if (!TREEVIEW_ValidItem(infoPtr
, item
)) return FALSE
;
2109 TREEVIEW_UpdateDispInfo(infoPtr
, item
, tvItem
->mask
);
2111 if (tvItem
->mask
& TVIF_CHILDREN
)
2113 if (item
->cChildren
==I_CHILDRENCALLBACK
)
2114 FIXME("I_CHILDRENCALLBACK not supported\n");
2115 tvItem
->cChildren
= item
->cChildren
;
2118 if (tvItem
->mask
& TVIF_HANDLE
)
2119 tvItem
->hItem
= item
;
2121 if (tvItem
->mask
& TVIF_IMAGE
)
2122 tvItem
->iImage
= item
->iImage
;
2124 if (tvItem
->mask
& TVIF_INTEGRAL
)
2125 tvItem
->iIntegral
= item
->iIntegral
;
2127 /* undocumented: (mask & TVIF_PARAM) ignored and lParam is always set */
2128 tvItem
->lParam
= item
->lParam
;
2130 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2131 tvItem
->iSelectedImage
= item
->iSelectedImage
;
2133 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
2134 tvItem
->iExpandedImage
= item
->iExpandedImage
;
2136 /* undocumented: stateMask and (state & TVIF_STATE) ignored, so state is always set */
2137 tvItem
->state
= item
->state
;
2139 if (tvItem
->mask
& TVIF_TEXT
)
2141 if (item
->pszText
== NULL
)
2143 if (tvItem
->cchTextMax
> 0)
2144 tvItem
->pszText
[0] = '\0';
2148 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2150 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2151 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2155 lstrcpynW(tvItem
->pszText
, item
->pszText
, tvItem
->cchTextMax
);
2160 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2162 tvItem
->pszText
= (LPWSTR
)LPSTR_TEXTCALLBACKA
;
2163 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2167 WideCharToMultiByte(CP_ACP
, 0, item
->pszText
, -1,
2168 (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, NULL
, NULL
);
2173 if (tvItem
->mask
& TVIF_STATEEX
)
2175 FIXME("Extended item state not supported, returning 0.\n");
2176 tvItem
->uStateEx
= 0;
2179 TRACE("item <%p>, txt %p, img %d, mask %x\n",
2180 item
, tvItem
->pszText
, tvItem
->iImage
, tvItem
->mask
);
2185 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2186 * which is wrong. */
2188 TREEVIEW_SetItemT(TREEVIEW_INFO
*infoPtr
, const TVITEMEXW
*tvItem
, BOOL isW
)
2190 TREEVIEW_ITEM
*item
;
2191 TREEVIEW_ITEM originalItem
;
2193 item
= tvItem
->hItem
;
2195 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr
, item
),
2198 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2201 /* store the original item values */
2202 originalItem
= *item
;
2204 if (!TREEVIEW_DoSetItemT(infoPtr
, item
, tvItem
, isW
))
2207 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2208 if ((tvItem
->mask
& TVIF_TEXT
2209 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2212 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_TEXT
);
2213 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2216 if (tvItem
->mask
!= 0 && ISVISIBLE(item
))
2218 /* The refresh updates everything, but we can't wait until then. */
2219 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
2221 /* if any of the item's values changed and it's not a callback, redraw the item */
2222 if (item_changed(&originalItem
, item
, tvItem
))
2224 if (tvItem
->mask
& TVIF_INTEGRAL
)
2226 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
2227 TREEVIEW_UpdateScrollBars(infoPtr
);
2229 TREEVIEW_Invalidate(infoPtr
, NULL
);
2233 TREEVIEW_UpdateScrollBars(infoPtr
);
2234 TREEVIEW_Invalidate(infoPtr
, item
);
2243 TREEVIEW_GetItemState(const TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, UINT mask
)
2247 if (!item
|| !TREEVIEW_ValidItem(infoPtr
, item
))
2250 return (item
->state
& mask
);
2254 TREEVIEW_GetNextItem(const TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM item
)
2256 TREEVIEW_ITEM
*retval
;
2260 /* handle all the global data here */
2263 case TVGN_CHILD
: /* Special case: child of 0 is root */
2268 retval
= infoPtr
->root
->firstChild
;
2272 retval
= infoPtr
->selectedItem
;
2275 case TVGN_FIRSTVISIBLE
:
2276 retval
= infoPtr
->firstVisible
;
2279 case TVGN_DROPHILITE
:
2280 retval
= infoPtr
->dropItem
;
2283 case TVGN_LASTVISIBLE
:
2284 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2290 TRACE("flags:%x, returns %p\n", which
, retval
);
2291 return (LRESULT
)retval
;
2294 if (item
== TVI_ROOT
) item
= infoPtr
->root
;
2296 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2302 retval
= item
->nextSibling
;
2305 retval
= item
->prevSibling
;
2308 retval
= (item
->parent
!= infoPtr
->root
) ? item
->parent
: NULL
;
2311 retval
= item
->firstChild
;
2313 case TVGN_NEXTVISIBLE
:
2314 retval
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2316 case TVGN_PREVIOUSVISIBLE
:
2317 retval
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
2320 TRACE("Unknown msg %x,item %p\n", which
, item
);
2324 TRACE("flags:%x, item %p;returns %p\n", which
, item
, retval
);
2325 return (LRESULT
)retval
;
2330 TREEVIEW_GetCount(const TREEVIEW_INFO
*infoPtr
)
2332 TRACE(" %d\n", infoPtr
->uNumItems
);
2333 return (LRESULT
)infoPtr
->uNumItems
;
2337 TREEVIEW_ToggleItemState(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2339 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2341 static const unsigned int state_table
[] = { 0, 2, 1 };
2345 state
= STATEIMAGEINDEX(item
->state
);
2346 TRACE("state:%x\n", state
);
2347 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2350 state
= state_table
[state
];
2352 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2354 TRACE("state:%x\n", state
);
2355 TREEVIEW_Invalidate(infoPtr
, item
);
2360 /* Painting *************************************************************/
2362 /* Draw the lines and expand button for an item. Also draws one section
2363 * of the line from item's parent to item's parent's next sibling. */
2365 TREEVIEW_DrawItemLines(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const TREEVIEW_ITEM
*item
)
2367 LONG centerx
, centery
;
2368 BOOL lar
= ((infoPtr
->dwStyle
2369 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2372 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2374 if (!lar
&& item
->iLevel
== 0)
2377 hbr
= CreateSolidBrush(clrBk
);
2378 hbrOld
= SelectObject(hdc
, hbr
);
2380 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2381 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2383 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2385 HPEN hOldPen
, hNewPen
;
2389 /* Get a dotted grey pen */
2390 lb
.lbStyle
= BS_SOLID
;
2391 lb
.lbColor
= GETLINECOLOR(infoPtr
->clrLine
);
2392 hNewPen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, NULL
);
2393 hOldPen
= SelectObject(hdc
, hNewPen
);
2395 /* Make sure the center is on a dot (using +2 instead
2396 * of +1 gives us pixel-by-pixel compat with native) */
2397 centery
= (centery
+ 2) & ~1;
2399 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2400 LineTo(hdc
, centerx
- 1, centery
);
2402 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2404 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2405 LineTo(hdc
, centerx
, centery
);
2408 if (item
->nextSibling
)
2410 MoveToEx(hdc
, centerx
, centery
, NULL
);
2411 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2414 /* Draw the line from our parent to its next sibling. */
2415 parent
= item
->parent
;
2416 while (parent
!= infoPtr
->root
)
2418 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2420 if (parent
->nextSibling
2421 /* skip top-levels unless TVS_LINESATROOT */
2422 && parent
->stateOffset
> parent
->linesOffset
)
2424 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2425 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2428 parent
= parent
->parent
;
2431 SelectObject(hdc
, hOldPen
);
2432 DeleteObject(hNewPen
);
2436 * Display the (+/-) signs
2439 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2441 if (item
->cChildren
)
2443 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
2446 RECT glyphRect
= item
->rect
;
2447 glyphRect
.left
= item
->linesOffset
;
2448 glyphRect
.right
= item
->stateOffset
;
2449 DrawThemeBackground (theme
, hdc
, TVP_GLYPH
,
2450 (item
->state
& TVIS_EXPANDED
) ? GLPS_OPENED
: GLPS_CLOSED
,
2455 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2456 LONG width
= item
->stateOffset
- item
->linesOffset
;
2457 LONG rectsize
= min(height
, width
) / 4;
2458 /* plussize = ceil(rectsize * 3/4) */
2459 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2461 HPEN new_pen
= CreatePen(PS_SOLID
, 0, GETLINECOLOR(infoPtr
->clrLine
));
2462 HPEN old_pen
= SelectObject(hdc
, new_pen
);
2464 Rectangle(hdc
, centerx
- rectsize
- 1, centery
- rectsize
- 1,
2465 centerx
+ rectsize
+ 2, centery
+ rectsize
+ 2);
2467 SelectObject(hdc
, old_pen
);
2468 DeleteObject(new_pen
);
2470 /* draw +/- signs with current text color */
2471 new_pen
= CreatePen(PS_SOLID
, 0, GETTXTCOLOR(infoPtr
->clrText
));
2472 old_pen
= SelectObject(hdc
, new_pen
);
2474 if (height
< 18 || width
< 18)
2476 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2477 LineTo(hdc
, centerx
+ plussize
, centery
);
2479 if (!(item
->state
& TVIS_EXPANDED
) ||
2480 (item
->state
& TVIS_EXPANDPARTIAL
))
2482 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2483 LineTo(hdc
, centerx
, centery
+ plussize
);
2488 Rectangle(hdc
, centerx
- plussize
+ 1, centery
- 1,
2489 centerx
+ plussize
, centery
+ 2);
2491 if (!(item
->state
& TVIS_EXPANDED
) ||
2492 (item
->state
& TVIS_EXPANDPARTIAL
))
2494 Rectangle(hdc
, centerx
- 1, centery
- plussize
+ 1,
2495 centerx
+ 2, centery
+ plussize
);
2496 SetPixel(hdc
, centerx
- 1, centery
, clrBk
);
2497 SetPixel(hdc
, centerx
+ 1, centery
, clrBk
);
2501 SelectObject(hdc
, old_pen
);
2502 DeleteObject(new_pen
);
2506 SelectObject(hdc
, hbrOld
);
2511 TREEVIEW_DrawItem(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*item
)
2515 COLORREF oldTextColor
, oldTextBkColor
;
2517 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2518 NMTVCUSTOMDRAW nmcdhdr
;
2520 TREEVIEW_UpdateDispInfo(infoPtr
, item
, CALLBACK_MASK_ALL
);
2522 /* - If item is drop target or it is selected and window is in focus -
2523 * use blue background (COLOR_HIGHLIGHT).
2524 * - If item is selected, window is not in focus, but it has style
2525 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2526 * - Otherwise - use background color
2528 if ((item
->state
& TVIS_DROPHILITED
) || ((item
== infoPtr
->focusedItem
) && !(item
->state
& TVIS_SELECTED
)) ||
2529 ((item
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
|| item
== infoPtr
->focusedItem
) &&
2530 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2532 if ((item
->state
& TVIS_DROPHILITED
) || inFocus
)
2534 nmcdhdr
.clrTextBk
= comctl32_color
.clrHighlight
;
2535 nmcdhdr
.clrText
= comctl32_color
.clrHighlightText
;
2539 nmcdhdr
.clrTextBk
= comctl32_color
.clrBtnFace
;
2540 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2545 nmcdhdr
.clrTextBk
= GETBKCOLOR(infoPtr
->clrBk
);
2546 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
2547 nmcdhdr
.clrText
= comctl32_color
.clrHighlight
;
2549 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2552 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
2554 /* The custom draw handler can query the text rectangle,
2556 /* should already be known, set to 0 when changed */
2557 if (!item
->textWidth
)
2558 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2562 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2564 cditem
= TREEVIEW_SendCustomDrawItemNotify
2565 (infoPtr
, hdc
, item
, CDDS_ITEMPREPAINT
, &nmcdhdr
);
2566 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2568 if (cditem
& CDRF_SKIPDEFAULT
)
2570 SelectObject(hdc
, hOldFont
);
2575 if (cditem
& CDRF_NEWFONT
)
2576 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2578 TREEVIEW_DrawItemLines(infoPtr
, hdc
, item
);
2580 /* Set colors. Custom draw handler can change these so we do this after it. */
2581 oldTextColor
= SetTextColor(hdc
, nmcdhdr
.clrText
);
2582 oldTextBkColor
= SetBkColor(hdc
, nmcdhdr
.clrTextBk
);
2584 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2587 * Display the images associated with this item
2592 /* State images are displayed to the left of the Normal image
2593 * image number is in state; zero should be `display no image'.
2595 imageIndex
= STATEIMAGEINDEX(item
->state
);
2597 if (infoPtr
->himlState
&& imageIndex
)
2599 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2601 centery
- infoPtr
->stateImageHeight
/ 2,
2605 /* Now, draw the normal image; can be either selected,
2606 * non-selected or expanded image.
2609 if ((item
->state
& TVIS_SELECTED
) && (item
->iSelectedImage
>= 0))
2611 /* The item is currently selected */
2612 imageIndex
= item
->iSelectedImage
;
2614 else if ((item
->state
& TVIS_EXPANDED
) && (item
->iExpandedImage
!= (WORD
)I_IMAGENONE
))
2616 /* The item is currently not selected but expanded */
2617 imageIndex
= item
->iExpandedImage
;
2621 /* The item is not selected and not expanded */
2622 imageIndex
= item
->iImage
;
2625 if (infoPtr
->himlNormal
)
2627 UINT style
= item
->state
& TVIS_CUT
? ILD_SELECTED
: ILD_NORMAL
;
2629 style
|= item
->state
& TVIS_OVERLAYMASK
;
2631 ImageList_DrawEx(infoPtr
->himlNormal
, imageIndex
, hdc
,
2632 item
->imageOffset
, centery
- infoPtr
->normalImageHeight
/ 2,
2633 0, 0, infoPtr
->clrBk
, item
->state
& TVIS_CUT
? GETBKCOLOR(infoPtr
->clrBk
) : CLR_DEFAULT
,
2640 * Display the text associated with this item
2643 /* Don't paint item's text if it's being edited */
2644 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= item
))
2652 rcText
.top
= item
->rect
.top
;
2653 rcText
.bottom
= item
->rect
.bottom
;
2654 rcText
.left
= item
->textOffset
;
2655 rcText
.right
= rcText
.left
+ item
->textWidth
+ 4;
2657 TRACE("drawing text %s at (%s)\n",
2658 debugstr_w(item
->pszText
), wine_dbgstr_rect(&rcText
));
2661 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
2663 align
= SetTextAlign(hdc
, TA_LEFT
| TA_TOP
);
2664 ExtTextOutW(hdc
, rcText
.left
+ 2, (rcText
.top
+ rcText
.bottom
- sz
.cy
) / 2,
2665 ETO_CLIPPED
| ETO_OPAQUE
,
2668 lstrlenW(item
->pszText
),
2670 SetTextAlign(hdc
, align
);
2672 /* Draw focus box around the selected item */
2673 if ((item
== infoPtr
->selectedItem
) && inFocus
)
2675 DrawFocusRect(hdc
,&rcText
);
2680 /* Draw insertion mark if necessary */
2682 if (infoPtr
->insertMarkItem
)
2683 TRACE("item:%d,mark:%p\n",
2684 TREEVIEW_GetItemIndex(infoPtr
, item
),
2685 infoPtr
->insertMarkItem
);
2687 if (item
== infoPtr
->insertMarkItem
)
2689 HPEN hNewPen
, hOldPen
;
2693 hNewPen
= CreatePen(PS_SOLID
, 2, GETINSCOLOR(infoPtr
->clrInsertMark
));
2694 hOldPen
= SelectObject(hdc
, hNewPen
);
2696 if (infoPtr
->insertBeforeorAfter
)
2697 offset
= item
->rect
.bottom
- 1;
2699 offset
= item
->rect
.top
+ 1;
2701 left
= item
->textOffset
- 2;
2702 right
= item
->textOffset
+ item
->textWidth
+ 2;
2704 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2705 LineTo(hdc
, left
, offset
+ 4);
2707 MoveToEx(hdc
, left
, offset
, NULL
);
2708 LineTo(hdc
, right
+ 1, offset
);
2710 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2711 LineTo(hdc
, right
, offset
- 4);
2713 SelectObject(hdc
, hOldPen
);
2714 DeleteObject(hNewPen
);
2717 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2719 cditem
= TREEVIEW_SendCustomDrawItemNotify
2720 (infoPtr
, hdc
, item
, CDDS_ITEMPOSTPAINT
, &nmcdhdr
);
2721 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2724 /* Restore the hdc state */
2725 SetTextColor(hdc
, oldTextColor
);
2726 SetBkColor(hdc
, oldTextBkColor
);
2727 SelectObject(hdc
, hOldFont
);
2730 /* Computes treeHeight and treeWidth and updates the scroll bars.
2733 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2735 TREEVIEW_ITEM
*item
;
2736 HWND hwnd
= infoPtr
->hwnd
;
2740 LONG scrollX
= infoPtr
->scrollX
;
2742 infoPtr
->treeWidth
= 0;
2743 infoPtr
->treeHeight
= 0;
2745 /* We iterate through all visible items in order to get the tree height
2747 item
= infoPtr
->root
->firstChild
;
2749 while (item
!= NULL
)
2751 if (ISVISIBLE(item
))
2753 /* actually we draw text at textOffset + 2 */
2754 if (2+item
->textOffset
+item
->textWidth
> infoPtr
->treeWidth
)
2755 infoPtr
->treeWidth
= item
->textOffset
+item
->textWidth
+2;
2757 /* This is scroll-adjusted, but we fix this below. */
2758 infoPtr
->treeHeight
= item
->rect
.bottom
;
2761 item
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2764 /* Fix the scroll adjusted treeHeight and treeWidth. */
2765 if (infoPtr
->root
->firstChild
)
2766 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2768 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2770 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2772 /* Adding one scroll bar may take up enough space that it forces us
2773 * to add the other as well. */
2774 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2778 if (infoPtr
->treeWidth
2779 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2782 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
|| infoPtr
->scrollX
> 0)
2785 if (!vert
&& horz
&& infoPtr
->treeHeight
2786 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2789 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2791 si
.cbSize
= sizeof(SCROLLINFO
);
2792 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2797 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2798 if ( si
.nPage
&& NULL
!= infoPtr
->firstVisible
)
2800 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2801 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2803 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2805 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2806 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2807 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2811 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2812 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2813 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2818 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2819 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2820 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2825 si
.nPage
= infoPtr
->clientWidth
;
2826 si
.nPos
= infoPtr
->scrollX
;
2827 si
.nMax
= infoPtr
->treeWidth
- 1;
2829 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2831 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2835 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2836 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2837 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2839 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2840 TREEVIEW_HScroll(infoPtr
,
2841 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2845 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2846 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2847 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2850 if (infoPtr
->scrollX
!= 0)
2852 TREEVIEW_HScroll(infoPtr
,
2853 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2858 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2862 TREEVIEW_FillBkgnd(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2865 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2867 hBrush
= CreateSolidBrush(clrBk
);
2868 FillRect(hdc
, rc
, hBrush
);
2869 DeleteObject(hBrush
);
2872 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2874 TREEVIEW_EraseBackground(const TREEVIEW_INFO
*infoPtr
, HDC hdc
)
2878 TRACE("%p\n", infoPtr
);
2880 GetClientRect(infoPtr
->hwnd
, &rect
);
2881 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rect
);
2887 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2889 HWND hwnd
= infoPtr
->hwnd
;
2891 TREEVIEW_ITEM
*item
;
2893 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2895 TRACE("empty window\n");
2899 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2902 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2904 ReleaseDC(hwnd
, hdc
);
2908 for (item
= infoPtr
->root
->firstChild
;
2910 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
2912 if (ISVISIBLE(item
))
2914 /* Avoid unneeded calculations */
2915 if (item
->rect
.top
> rect
.bottom
)
2917 if (item
->rect
.bottom
< rect
.top
)
2920 TREEVIEW_DrawItem(infoPtr
, hdc
, item
);
2924 TREEVIEW_UpdateScrollBars(infoPtr
);
2926 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2928 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2932 TREEVIEW_InvalidateItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2934 if (item
) InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2938 TREEVIEW_Invalidate(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2941 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2943 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2947 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, HDC hdc_ref
)
2953 TRACE("(%p %p)\n", infoPtr
, hdc_ref
);
2958 GetClientRect(infoPtr
->hwnd
, &rc
);
2959 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
2963 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
2966 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
2969 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
2970 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
2973 EndPaint(infoPtr
->hwnd
, &ps
);
2979 TREEVIEW_PrintClient(TREEVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
2981 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
2983 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwnd
))
2986 if (options
& PRF_ERASEBKGND
)
2987 TREEVIEW_EraseBackground(infoPtr
, hdc
);
2989 if (options
& PRF_CLIENT
)
2992 GetClientRect(infoPtr
->hwnd
, &rc
);
2993 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
2999 /* Sorting **************************************************************/
3001 /***************************************************************************
3002 * Forward the DPA local callback to the treeview owner callback
3005 TREEVIEW_CallBackCompare(const TREEVIEW_ITEM
*first
, const TREEVIEW_ITEM
*second
,
3006 const TVSORTCB
*pCallBackSort
)
3008 /* Forward the call to the client-defined callback */
3009 return pCallBackSort
->lpfnCompare(first
->lParam
,
3011 pCallBackSort
->lParam
);
3014 /***************************************************************************
3015 * Treeview native sort routine: sort on item text.
3018 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
3019 const TREEVIEW_INFO
*infoPtr
)
3021 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
3022 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
3024 if(first
->pszText
&& second
->pszText
)
3025 return lstrcmpiW(first
->pszText
, second
->pszText
);
3026 else if(first
->pszText
)
3028 else if(second
->pszText
)
3034 /* Returns the number of physical children belonging to item. */
3036 TREEVIEW_CountChildren(const TREEVIEW_ITEM
*item
)
3041 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
3047 /* Returns a DPA containing a pointer to each physical child of item in
3048 * sibling order. If item has no children, an empty DPA is returned. */
3050 TREEVIEW_BuildChildDPA(const TREEVIEW_ITEM
*item
)
3054 HDPA list
= DPA_Create(8);
3055 if (list
== 0) return NULL
;
3057 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
3059 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
3069 /***************************************************************************
3070 * Setup the treeview structure with regards of the sort method
3071 * and sort the children of the TV item specified in lParam
3072 * fRecurse: currently unused. Should be zero.
3073 * parent: if pSort!=NULL, should equal pSort->hParent.
3074 * otherwise, item which child items are to be sorted.
3075 * pSort: sort method info. if NULL, sort on item text.
3076 * if non-NULL, sort on item's lParam content, and let the
3077 * application decide what that means. See also TVM_SORTCHILDRENCB.
3081 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, HTREEITEM parent
,
3085 PFNDPACOMPARE pfnCompare
;
3088 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
3089 if (parent
== TVI_ROOT
|| parent
== NULL
)
3090 parent
= infoPtr
->root
;
3092 /* Check for a valid handle to the parent item */
3093 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
3095 ERR("invalid item hParent=%p\n", parent
);
3101 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
3102 lpCompare
= (LPARAM
)pSort
;
3106 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
3107 lpCompare
= (LPARAM
)infoPtr
;
3110 cChildren
= TREEVIEW_CountChildren(parent
);
3112 /* Make sure there is something to sort */
3115 /* TREEVIEW_ITEM rechaining */
3118 HTREEITEM nextItem
= 0;
3119 HTREEITEM prevItem
= 0;
3121 HDPA sortList
= TREEVIEW_BuildChildDPA(parent
);
3123 if (sortList
== NULL
)
3126 /* let DPA sort the list */
3127 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
3129 /* The order of DPA entries has been changed, so fixup the
3130 * nextSibling and prevSibling pointers. */
3132 item
= DPA_GetPtr(sortList
, count
++);
3133 while ((nextItem
= DPA_GetPtr(sortList
, count
++)) != NULL
)
3135 /* link the two current item together */
3136 item
->nextSibling
= nextItem
;
3137 nextItem
->prevSibling
= item
;
3139 if (prevItem
== NULL
)
3141 /* this is the first item, update the parent */
3142 parent
->firstChild
= item
;
3143 item
->prevSibling
= NULL
;
3147 /* fix the back chaining */
3148 item
->prevSibling
= prevItem
;
3151 /* get ready for the next one */
3156 /* the last item is pointed to by item and never has a sibling */
3157 item
->nextSibling
= NULL
;
3158 parent
->lastChild
= item
;
3160 DPA_Destroy(sortList
);
3162 TREEVIEW_VerifyTree(infoPtr
);
3164 if (parent
->state
& TVIS_EXPANDED
)
3166 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3168 if (parent
== infoPtr
->root
)
3169 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3171 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3173 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3175 TREEVIEW_ITEM
*item
;
3177 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3178 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3180 if (item
->visibleOrder
== visOrder
)
3184 if (!item
) item
= parent
->firstChild
;
3185 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3188 TREEVIEW_Invalidate(infoPtr
, NULL
);
3197 /***************************************************************************
3198 * Setup the treeview structure with regards of the sort method
3199 * and sort the children of the TV item specified in lParam
3202 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, LPTVSORTCB pSort
)
3204 return TREEVIEW_Sort(infoPtr
, pSort
->hParent
, pSort
);
3208 /***************************************************************************
3209 * Sort the children of the TV item specified in lParam.
3212 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3214 return TREEVIEW_Sort(infoPtr
, (HTREEITEM
)lParam
, NULL
);
3218 /* Expansion/Collapse ***************************************************/
3221 TREEVIEW_SendExpanding(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3224 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3225 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3226 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3231 TREEVIEW_SendExpanded(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3234 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3235 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3236 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3241 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3242 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3244 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3245 BOOL bRemoveChildren
, BOOL bUser
)
3247 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3248 BOOL bSetSelection
, bSetFirstVisible
;
3250 LONG scrollDist
= 0;
3251 TREEVIEW_ITEM
*nextItem
= NULL
, *tmpItem
;
3254 TRACE("TVE_COLLAPSE %p %s\n", item
, TREEVIEW_ItemName(item
));
3256 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3260 TREEVIEW_SendExpanding(infoPtr
, item
, action
);
3262 if (item
->firstChild
== NULL
)
3265 wasExpanded
= (item
->state
& TVIS_EXPANDED
) != 0;
3266 item
->state
&= ~TVIS_EXPANDED
;
3268 if (wasExpanded
&& bUser
)
3269 TREEVIEW_SendExpanded(infoPtr
, item
, action
);
3271 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3272 && TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
));
3274 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3275 && TREEVIEW_IsChildOf(item
, infoPtr
->firstVisible
));
3280 if (tmpItem
->nextSibling
)
3282 nextItem
= tmpItem
->nextSibling
;
3285 tmpItem
= tmpItem
->parent
;
3289 scrollDist
= nextItem
->rect
.top
;
3291 if (bRemoveChildren
)
3293 INT old_cChildren
= item
->cChildren
;
3294 TRACE("TVE_COLLAPSERESET\n");
3295 item
->state
&= ~TVIS_EXPANDEDONCE
;
3296 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
3297 item
->cChildren
= old_cChildren
;
3300 if (item
->firstChild
)
3302 TREEVIEW_ITEM
*i
, *sibling
;
3304 sibling
= TREEVIEW_GetNextListItem(infoPtr
, item
);
3306 for (i
= item
->firstChild
; i
!= sibling
;
3307 i
= TREEVIEW_GetNextListItem(infoPtr
, i
))
3309 i
->visibleOrder
= -1;
3313 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3316 scrollDist
= -(scrollDist
- nextItem
->rect
.top
);
3320 /* Don't call DoSelectItem, it sends notifications. */
3321 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3322 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3323 item
->state
|= TVIS_SELECTED
;
3324 infoPtr
->selectedItem
= item
;
3327 TREEVIEW_UpdateScrollBars(infoPtr
);
3329 scrollRect
.left
= 0;
3330 scrollRect
.right
= infoPtr
->clientWidth
;
3331 scrollRect
.bottom
= infoPtr
->clientHeight
;
3335 scrollRect
.top
= nextItem
->rect
.top
;
3337 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, &scrollRect
,
3338 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3339 TREEVIEW_Invalidate(infoPtr
, item
);
3341 scrollRect
.top
= item
->rect
.top
;
3342 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, TRUE
);
3345 TREEVIEW_SetFirstVisible(infoPtr
,
3346 bSetFirstVisible
? item
: infoPtr
->firstVisible
,
3353 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3354 BOOL partial
, BOOL user
)
3357 LONG orgNextTop
= 0;
3359 TREEVIEW_ITEM
*nextItem
, *tmpItem
;
3360 BOOL sendsNotifications
;
3362 TRACE("(%p, %p, partial=%d, %d\n", infoPtr
, item
, partial
, user
);
3364 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3367 tmpItem
= item
; nextItem
= NULL
;
3370 if (tmpItem
->nextSibling
)
3372 nextItem
= tmpItem
->nextSibling
;
3375 tmpItem
= tmpItem
->parent
;
3379 orgNextTop
= nextItem
->rect
.top
;
3381 TRACE("TVE_EXPAND %p %s\n", item
, TREEVIEW_ItemName(item
));
3383 sendsNotifications
= user
|| ((item
->cChildren
!= 0) &&
3384 !(item
->state
& TVIS_EXPANDEDONCE
));
3385 if (sendsNotifications
)
3387 if (!TREEVIEW_SendExpanding(infoPtr
, item
, TVE_EXPAND
))
3389 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3393 if (!item
->firstChild
)
3396 item
->state
|= TVIS_EXPANDED
;
3399 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3401 if (ISVISIBLE(item
))
3403 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3404 TREEVIEW_UpdateSubTree(infoPtr
, item
);
3405 TREEVIEW_UpdateScrollBars(infoPtr
);
3407 scrollRect
.left
= 0;
3408 scrollRect
.bottom
= infoPtr
->treeHeight
;
3409 scrollRect
.right
= infoPtr
->clientWidth
;
3412 scrollDist
= nextItem
->rect
.top
- orgNextTop
;
3413 scrollRect
.top
= orgNextTop
;
3415 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3416 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3417 TREEVIEW_Invalidate (infoPtr
, item
);
3419 scrollRect
.top
= item
->rect
.top
;
3420 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, FALSE
);
3423 /* Scroll up so that as many children as possible are visible.
3424 * This fails when expanding causes an HScroll bar to appear, but we
3425 * don't know that yet, so the last item is obscured. */
3426 if (item
->firstChild
!= NULL
)
3428 int nChildren
= item
->lastChild
->visibleOrder
3429 - item
->firstChild
->visibleOrder
+ 1;
3431 int visible_pos
= item
->visibleOrder
3432 - infoPtr
->firstVisible
->visibleOrder
;
3434 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3436 if (visible_pos
> 0 && nChildren
> rows_below
)
3438 int scroll
= nChildren
- rows_below
;
3440 if (scroll
> visible_pos
)
3441 scroll
= visible_pos
;
3445 TREEVIEW_ITEM
*newFirstVisible
3446 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3450 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3456 if (sendsNotifications
) {
3457 TREEVIEW_SendExpanded(infoPtr
, item
, TVE_EXPAND
);
3458 item
->state
|= TVIS_EXPANDEDONCE
;
3464 /* Handler for TVS_SINGLEEXPAND behaviour. Used on response
3465 to mouse messages and TVM_SELECTITEM.
3467 selection - previously selected item, used to collapse a part of a tree
3468 item - new selected item
3470 static void TREEVIEW_SingleExpand(TREEVIEW_INFO
*infoPtr
,
3471 HTREEITEM selection
, HTREEITEM item
)
3473 TREEVIEW_ITEM
*SelItem
;
3475 if ((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) == 0 || infoPtr
->hwndEdit
|| !item
) return;
3477 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
3480 * Close the previous selection all the way to the root
3481 * as long as the new selection is not a child
3483 if(selection
&& (selection
!= item
))
3485 BOOL closeit
= TRUE
;
3488 /* determine if the hitItem is a child of the currently selected item */
3489 while(closeit
&& SelItem
&& TREEVIEW_ValidItem(infoPtr
, SelItem
) &&
3490 (SelItem
->parent
!= infoPtr
->root
))
3492 closeit
= (SelItem
!= selection
);
3493 SelItem
= SelItem
->parent
;
3498 if(TREEVIEW_ValidItem(infoPtr
, selection
))
3499 SelItem
= selection
;
3501 while(SelItem
&& (SelItem
!= item
) && TREEVIEW_ValidItem(infoPtr
, SelItem
) &&
3502 SelItem
->parent
!= infoPtr
->root
)
3504 TREEVIEW_Collapse(infoPtr
, SelItem
, FALSE
, FALSE
);
3505 SelItem
= SelItem
->parent
;
3511 * Expand the current item
3513 TREEVIEW_Expand(infoPtr
, item
, FALSE
, FALSE
);
3517 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, BOOL user
)
3519 TRACE("item=%p, user=%d\n", item
, user
);
3521 if (item
->state
& TVIS_EXPANDED
)
3522 return TREEVIEW_Collapse(infoPtr
, item
, FALSE
, user
);
3524 return TREEVIEW_Expand(infoPtr
, item
, FALSE
, user
);
3528 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3530 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3532 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3534 if (TREEVIEW_HasChildren(infoPtr
, item
))
3535 TREEVIEW_ExpandAll(infoPtr
, item
);
3539 /* Note:If the specified item is the child of a collapsed parent item,
3540 the parent's list of child items is (recursively) expanded to reveal the
3541 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3542 know if it also applies here.
3546 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM item
)
3548 if (!TREEVIEW_ValidItem(infoPtr
, item
))
3551 TRACE("For (%s) item:%d, flags 0x%x, state:%d\n",
3552 TREEVIEW_ItemName(item
), TREEVIEW_GetItemIndex(infoPtr
, item
),
3555 switch (flag
& TVE_TOGGLE
)
3558 return TREEVIEW_Collapse(infoPtr
, item
, flag
& TVE_COLLAPSERESET
,
3562 return TREEVIEW_Expand(infoPtr
, item
, flag
& TVE_EXPANDPARTIAL
,
3566 return TREEVIEW_Toggle(infoPtr
, item
, FALSE
);
3573 /* Hit-Testing **********************************************************/
3575 static TREEVIEW_ITEM
*
3576 TREEVIEW_HitTestPoint(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3578 TREEVIEW_ITEM
*item
;
3581 if (!infoPtr
->firstVisible
)
3584 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3586 for (item
= infoPtr
->firstVisible
; item
!= NULL
;
3587 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3589 if (row
>= item
->visibleOrder
3590 && row
< item
->visibleOrder
+ item
->iIntegral
)
3598 TREEVIEW_HitTest(const TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3600 TREEVIEW_ITEM
*item
;
3606 GetClientRect(infoPtr
->hwnd
, &rect
);
3613 status
|= TVHT_TOLEFT
;
3615 else if (x
> rect
.right
)
3617 status
|= TVHT_TORIGHT
;
3622 status
|= TVHT_ABOVE
;
3624 else if (y
> rect
.bottom
)
3626 status
|= TVHT_BELOW
;
3631 lpht
->flags
= status
;
3635 item
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3638 lpht
->flags
= TVHT_NOWHERE
;
3642 if (x
>= item
->textOffset
+ item
->textWidth
)
3644 lpht
->flags
= TVHT_ONITEMRIGHT
;
3646 else if (x
>= item
->textOffset
)
3648 lpht
->flags
= TVHT_ONITEMLABEL
;
3650 else if (x
>= item
->imageOffset
)
3652 lpht
->flags
= TVHT_ONITEMICON
;
3654 else if (x
>= item
->stateOffset
)
3656 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3658 else if (x
>= item
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3660 lpht
->flags
= TVHT_ONITEMBUTTON
;
3664 lpht
->flags
= TVHT_ONITEMINDENT
;
3668 TRACE("(%d,%d):result %x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3670 return (LRESULT
)item
;
3673 /* Item Label Editing ***************************************************/
3676 TREEVIEW_GetEditControl(const TREEVIEW_INFO
*infoPtr
)
3678 return (LRESULT
)infoPtr
->hwndEdit
;
3681 static LRESULT CALLBACK
3682 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3684 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3685 BOOL bCancel
= FALSE
;
3691 TRACE("WM_PAINT start\n");
3692 rc
= CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3694 TRACE("WM_PAINT done\n");
3698 if (infoPtr
->bIgnoreEditKillFocus
)
3704 WNDPROC editProc
= infoPtr
->wpEditOrig
;
3705 infoPtr
->wpEditOrig
= 0;
3706 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
3707 return CallWindowProcW(editProc
, hwnd
, uMsg
, wParam
, lParam
);
3711 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3714 if (wParam
== VK_ESCAPE
)
3719 else if (wParam
== VK_RETURN
)
3726 return CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3729 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3730 /* eg. Using a messagebox */
3732 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3733 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3734 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3740 /* should handle edit control messages here */
3743 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3745 TRACE("code=%x, id=%x, handle=%lx\n", HIWORD(wParam
), LOWORD(wParam
), lParam
);
3747 switch (HIWORD(wParam
))
3752 * Adjust the edit window size
3755 TREEVIEW_ITEM
*editItem
= infoPtr
->editItem
;
3756 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3758 HFONT hFont
, hOldFont
= 0;
3760 TRACE("edit=%p\n", infoPtr
->hwndEdit
);
3762 if (!IsWindow(infoPtr
->hwndEdit
) || !hdc
) return FALSE
;
3764 infoPtr
->bLabelChanged
= TRUE
;
3766 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
3768 /* Select font to get the right dimension of the string */
3769 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3773 hOldFont
= SelectObject(hdc
, hFont
);
3776 if (GetTextExtentPoint32W(hdc
, buffer
, strlenW(buffer
), &sz
))
3778 TEXTMETRICW textMetric
;
3780 /* Add Extra spacing for the next character */
3781 GetTextMetricsW(hdc
, &textMetric
);
3782 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3784 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3786 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3788 SetWindowPos(infoPtr
->hwndEdit
,
3793 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3794 SWP_NOMOVE
| SWP_DRAWFRAME
);
3799 SelectObject(hdc
, hOldFont
);
3802 ReleaseDC(infoPtr
->hwnd
, hdc
);
3806 /* apparently we should respect passed handle value */
3807 if (infoPtr
->hwndEdit
!= (HWND
)lParam
) return FALSE
;
3809 TREEVIEW_EndEditLabelNow(infoPtr
, FALSE
);
3813 return SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3820 TREEVIEW_EditLabel(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3822 HWND hwnd
= infoPtr
->hwnd
;
3825 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
);
3828 TEXTMETRICW textMetric
;
3830 TRACE("%p %p\n", hwnd
, hItem
);
3831 if (!(infoPtr
->dwStyle
& TVS_EDITLABELS
))
3834 if (!TREEVIEW_ValidItem(infoPtr
, hItem
))
3837 if (infoPtr
->hwndEdit
)
3838 return infoPtr
->hwndEdit
;
3840 infoPtr
->bLabelChanged
= FALSE
;
3842 /* make edit item visible */
3843 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3845 TREEVIEW_UpdateDispInfo(infoPtr
, hItem
, TVIF_TEXT
);
3848 /* Select the font to get appropriate metric dimensions */
3849 if (infoPtr
->hFont
!= 0)
3851 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3854 /* Get string length in pixels */
3856 GetTextExtentPoint32W(hdc
, hItem
->pszText
, strlenW(hItem
->pszText
),
3859 GetTextExtentPoint32A(hdc
, "", 0, &sz
);
3861 /* Add Extra spacing for the next character */
3862 GetTextMetricsW(hdc
, &textMetric
);
3863 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3865 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3866 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- hItem
->textOffset
+ 2);
3868 if (infoPtr
->hFont
!= 0)
3870 SelectObject(hdc
, hOldFont
);
3873 ReleaseDC(hwnd
, hdc
);
3875 infoPtr
->editItem
= hItem
;
3877 hwndEdit
= CreateWindowExW(WS_EX_LEFT
,
3880 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3881 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3882 ES_LEFT
, hItem
->textOffset
- 2,
3883 hItem
->rect
.top
- 1, sz
.cx
+ 3,
3884 hItem
->rect
.bottom
-
3885 hItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3886 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3888 infoPtr
->hwndEdit
= hwndEdit
;
3890 /* Get a 2D border. */
3891 SetWindowLongW(hwndEdit
, GWL_EXSTYLE
,
3892 GetWindowLongW(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3893 SetWindowLongW(hwndEdit
, GWL_STYLE
,
3894 GetWindowLongW(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3896 SendMessageW(hwndEdit
, WM_SETFONT
,
3897 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, hItem
), FALSE
);
3899 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
,
3901 TREEVIEW_Edit_SubclassProc
);
3903 SetWindowTextW(hwndEdit
, hItem
->pszText
);
3905 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, hItem
))
3907 DestroyWindow(hwndEdit
);
3908 infoPtr
->hwndEdit
= 0;
3909 infoPtr
->editItem
= NULL
;
3914 SendMessageW(hwndEdit
, EM_SETSEL
, 0, -1);
3915 ShowWindow(hwndEdit
, SW_SHOW
);
3922 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3924 HWND hwnd
= infoPtr
->hwnd
;
3925 TREEVIEW_ITEM
*editedItem
= infoPtr
->editItem
;
3928 WCHAR tmpText
[1024] = { '\0' };
3929 WCHAR
*newText
= tmpText
;
3932 if (!IsWindow(infoPtr
->hwndEdit
)) return FALSE
;
3934 tvdi
.hdr
.hwndFrom
= hwnd
;
3935 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
3936 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_ENDLABELEDITW
);
3938 tvdi
.item
.hItem
= editedItem
;
3939 tvdi
.item
.state
= editedItem
->state
;
3940 tvdi
.item
.lParam
= editedItem
->lParam
;
3944 if (!infoPtr
->bNtfUnicode
)
3945 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, (LPSTR
)tmpText
, 1023);
3947 iLength
= GetWindowTextW(infoPtr
->hwndEdit
, tmpText
, 1023);
3949 if (iLength
>= 1023)
3951 ERR("Insufficient space to retrieve new item label\n");
3954 tvdi
.item
.mask
= TVIF_TEXT
;
3955 tvdi
.item
.pszText
= tmpText
;
3956 tvdi
.item
.cchTextMax
= iLength
+ 1;
3960 tvdi
.item
.pszText
= NULL
;
3961 tvdi
.item
.cchTextMax
= 0;
3964 bCommit
= TREEVIEW_SendRealNotify(infoPtr
, tvdi
.hdr
.idFrom
, &tvdi
.hdr
);
3966 if (!bCancel
&& bCommit
) /* Apply the changes */
3968 if (!infoPtr
->bNtfUnicode
)
3970 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, NULL
, 0 );
3971 newText
= Alloc(len
* sizeof(WCHAR
));
3972 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, newText
, len
);
3976 if (strcmpW(newText
, editedItem
->pszText
) != 0)
3978 WCHAR
*ptr
= ReAlloc(editedItem
->pszText
, sizeof(WCHAR
)*(iLength
+ 1));
3981 ERR("OutOfMemory, cannot allocate space for label\n");
3982 if(newText
!= tmpText
) Free(newText
);
3983 DestroyWindow(infoPtr
->hwndEdit
);
3984 infoPtr
->hwndEdit
= 0;
3985 infoPtr
->editItem
= NULL
;
3990 editedItem
->pszText
= ptr
;
3991 editedItem
->cchTextMax
= iLength
+ 1;
3992 strcpyW(editedItem
->pszText
, newText
);
3993 TREEVIEW_ComputeTextWidth(infoPtr
, editedItem
, 0);
3996 if(newText
!= tmpText
) Free(newText
);
3999 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
4000 DestroyWindow(infoPtr
->hwndEdit
);
4001 infoPtr
->hwndEdit
= 0;
4002 infoPtr
->editItem
= NULL
;
4007 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4009 if (wParam
!= TV_EDIT_TIMER
)
4011 ERR("got unknown timer\n");
4015 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4016 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
4018 TREEVIEW_EditLabel(infoPtr
, infoPtr
->selectedItem
);
4024 /* Mouse Tracking/Drag **************************************************/
4026 /***************************************************************************
4027 * This is quite unusual piece of code, but that's how it's implemented in
4031 TREEVIEW_TrackMouse(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
4033 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
4034 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
4038 r
.top
= pt
.y
- cyDrag
;
4039 r
.left
= pt
.x
- cxDrag
;
4040 r
.bottom
= pt
.y
+ cyDrag
;
4041 r
.right
= pt
.x
+ cxDrag
;
4043 SetCapture(infoPtr
->hwnd
);
4047 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
4049 if (msg
.message
== WM_MOUSEMOVE
)
4051 pt
.x
= (short)LOWORD(msg
.lParam
);
4052 pt
.y
= (short)HIWORD(msg
.lParam
);
4053 if (PtInRect(&r
, pt
))
4061 else if (msg
.message
>= WM_LBUTTONDOWN
&&
4062 msg
.message
<= WM_RBUTTONDBLCLK
)
4067 DispatchMessageW(&msg
);
4070 if (GetCapture() != infoPtr
->hwnd
)
4080 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4082 TREEVIEW_ITEM
*item
;
4086 SetFocus(infoPtr
->hwnd
);
4088 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4090 /* If there is pending 'edit label' event - kill it now */
4091 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4094 hit
.pt
.x
= (short)LOWORD(lParam
);
4095 hit
.pt
.y
= (short)HIWORD(lParam
);
4097 item
= (TREEVIEW_ITEM
*)TREEVIEW_HitTest(infoPtr
, &hit
);
4100 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, item
));
4102 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
4106 case TVHT_ONITEMRIGHT
:
4107 /* FIXME: we should not have sent NM_DBLCLK in this case. */
4110 case TVHT_ONITEMINDENT
:
4111 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
4117 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
4118 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
4120 while (item
->iLevel
> level
)
4122 item
= item
->parent
;
4128 case TVHT_ONITEMLABEL
:
4129 case TVHT_ONITEMICON
:
4130 case TVHT_ONITEMBUTTON
:
4131 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4134 case TVHT_ONITEMSTATEICON
:
4135 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4136 TREEVIEW_ToggleItemState(infoPtr
, item
);
4138 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4147 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4149 HWND hwnd
= infoPtr
->hwnd
;
4151 BOOL bTrack
, bDoLabelEdit
;
4153 /* If Edit control is active - kill it and return.
4154 * The best way to do it is to set focus to itself.
4155 * Edit control subclassed procedure will automatically call
4158 if (infoPtr
->hwndEdit
)
4164 ht
.pt
.x
= (short)LOWORD(lParam
);
4165 ht
.pt
.y
= (short)HIWORD(lParam
);
4167 TREEVIEW_HitTest(infoPtr
, &ht
);
4168 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
4170 /* update focusedItem and redraw both items */
4171 if(ht
.hItem
&& (ht
.flags
& TVHT_ONITEM
))
4173 infoPtr
->focusedItem
= ht
.hItem
;
4174 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4175 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4178 bTrack
= (ht
.flags
& TVHT_ONITEM
)
4179 && !(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
);
4182 * If the style allows editing and the node is already selected
4183 * and the click occurred on the item label...
4185 bDoLabelEdit
= (infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
4186 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
);
4188 /* Send NM_CLICK right away */
4190 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4193 if (ht
.flags
& TVHT_ONITEMBUTTON
)
4195 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
4199 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
4200 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4202 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
4203 infoPtr
->dropItem
= ht
.hItem
;
4205 /* clean up focusedItem as we dragged and won't select this item */
4206 if(infoPtr
->focusedItem
)
4208 /* refresh the item that was focused */
4209 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4210 infoPtr
->focusedItem
= NULL
;
4212 /* refresh the selected item to return the filled background */
4213 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4220 if (bTrack
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4225 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4226 KillTimer(hwnd
, TV_EDIT_TIMER
);
4228 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
4229 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
4231 else if (ht
.flags
& (TVHT_ONITEMICON
|TVHT_ONITEMLABEL
)) /* select the item if the hit was inside of the icon or text */
4233 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4235 /* Select the current item */
4236 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4237 TREEVIEW_SingleExpand(infoPtr
, selection
, ht
.hItem
);
4239 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4241 /* TVS_CHECKBOXES requires us to toggle the current state */
4242 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4243 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4253 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4257 if (infoPtr
->hwndEdit
)
4259 SetFocus(infoPtr
->hwnd
);
4263 ht
.pt
.x
= (short)LOWORD(lParam
);
4264 ht
.pt
.y
= (short)HIWORD(lParam
);
4266 TREEVIEW_HitTest(infoPtr
, &ht
);
4268 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4272 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4273 infoPtr
->dropItem
= ht
.hItem
;
4278 SetFocus(infoPtr
->hwnd
);
4279 if(!TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
))
4281 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
4282 SendMessageW(infoPtr
->hwndNotify
, WM_CONTEXTMENU
,
4283 (WPARAM
)infoPtr
->hwnd
, (LPARAM
)GetMessagePos());
4291 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4293 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4297 HBITMAP hbmp
, hOldbmp
;
4304 if (!(infoPtr
->himlNormal
))
4307 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4310 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4312 hwtop
= GetDesktopWindow();
4313 htopdc
= GetDC(hwtop
);
4314 hdc
= CreateCompatibleDC(htopdc
);
4316 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4318 if (dragItem
->pszText
)
4319 GetTextExtentPoint32W(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
),
4322 GetTextExtentPoint32A(hdc
, "", 0, &size
);
4324 TRACE("%d %d %s\n", size
.cx
, size
.cy
, debugstr_w(dragItem
->pszText
));
4325 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4326 hOldbmp
= SelectObject(hdc
, hbmp
);
4328 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4333 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4334 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4338 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4339 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4342 /* draw item text */
4344 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4346 if (dragItem
->pszText
)
4347 DrawTextW(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
), &rc
,
4350 SelectObject(hdc
, hOldFont
);
4351 SelectObject(hdc
, hOldbmp
);
4353 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4357 ReleaseDC(hwtop
, htopdc
);
4359 return (LRESULT
)infoPtr
->dragList
;
4362 /* Selection ************************************************************/
4365 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4368 TREEVIEW_ITEM
*prevSelect
;
4370 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4372 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4373 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4374 newSelect
? newSelect
->state
: 0);
4376 /* reset and redraw focusedItem if focusedItem was set so we don't */
4377 /* have to worry about the previously focused item when we set a new one */
4378 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4379 infoPtr
->focusedItem
= NULL
;
4383 case TVGN_CARET
|TVSI_NOSINGLEEXPAND
:
4384 FIXME("TVSI_NOSINGLEEXPAND specified.\n");
4387 prevSelect
= infoPtr
->selectedItem
;
4389 if (prevSelect
== newSelect
) {
4390 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4394 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4397 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4403 prevSelect
->state
&= ~TVIS_SELECTED
;
4405 newSelect
->state
|= TVIS_SELECTED
;
4407 infoPtr
->selectedItem
= newSelect
;
4409 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4411 TREEVIEW_InvalidateItem(infoPtr
, prevSelect
);
4412 TREEVIEW_InvalidateItem(infoPtr
, newSelect
);
4414 TREEVIEW_SendTreeviewNotify(infoPtr
,
4417 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4422 case TVGN_DROPHILITE
:
4423 prevSelect
= infoPtr
->dropItem
;
4426 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4428 infoPtr
->dropItem
= newSelect
;
4431 newSelect
->state
|= TVIS_DROPHILITED
;
4433 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4434 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4437 case TVGN_FIRSTVISIBLE
:
4438 if (newSelect
!= NULL
)
4440 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4441 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4442 TREEVIEW_Invalidate(infoPtr
, NULL
);
4447 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4451 /* FIXME: handle NM_KILLFOCUS etc */
4453 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4455 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4457 if (item
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4460 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4462 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4465 TREEVIEW_SingleExpand(infoPtr
, selection
, item
);
4470 /*************************************************************************
4471 * TREEVIEW_ProcessLetterKeys
4473 * Processes keyboard messages generated by pressing the letter keys
4475 * What this does is perform a case insensitive search from the
4476 * current position with the following quirks:
4477 * - If two chars or more are pressed in quick succession we search
4478 * for the corresponding string (e.g. 'abc').
4479 * - If there is a delay we wipe away the current search string and
4480 * restart with just that char.
4481 * - If the user keeps pressing the same character, whether slowly or
4482 * fast, so that the search string is entirely composed of this
4483 * character ('aaaaa' for instance), then we search for first item
4484 * that starting with that character.
4485 * - If the user types the above character in quick succession, then
4486 * we must also search for the corresponding string ('aaaaa'), and
4487 * go to that string if there is a match.
4495 * - The current implementation has a list of characters it will
4496 * accept and it ignores everything else. In particular it will
4497 * ignore accentuated characters which seems to match what
4498 * Windows does. But I'm not sure it makes sense to follow
4500 * - We don't sound a beep when the search fails.
4501 * - The search should start from the focused item, not from the selected
4502 * item. One reason for this is to allow for multiple selections in trees.
4503 * But currently infoPtr->focusedItem does not seem very usable.
4507 * TREEVIEW_ProcessLetterKeys
4509 static INT
TREEVIEW_ProcessLetterKeys(TREEVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
4512 HTREEITEM endidx
,idx
;
4514 WCHAR buffer
[MAX_PATH
];
4515 DWORD timestamp
,elapsed
;
4517 /* simple parameter checking */
4518 if (!charCode
|| !keyData
) return 0;
4520 /* only allow the valid WM_CHARs through */
4521 if (!isalnum(charCode
) &&
4522 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4523 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4524 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4525 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4526 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4527 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4528 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4529 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4530 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4533 /* compute how much time elapsed since last keypress */
4534 timestamp
= GetTickCount();
4535 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4536 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4538 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4541 /* update the search parameters */
4542 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4543 if (elapsed
< KEY_DELAY
) {
4544 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
) / sizeof(WCHAR
)) {
4545 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4547 if (infoPtr
->charCode
!= charCode
) {
4548 infoPtr
->charCode
=charCode
=0;
4551 infoPtr
->charCode
=charCode
;
4552 infoPtr
->szSearchParam
[0]=charCode
;
4553 infoPtr
->nSearchParamLength
=1;
4554 /* Redundant with the 1 char string */
4558 /* and search from the current position */
4560 if (infoPtr
->selectedItem
!= NULL
) {
4561 endidx
=infoPtr
->selectedItem
;
4562 /* if looking for single character match,
4563 * then we must always move forward
4565 if (infoPtr
->nSearchParamLength
== 1)
4566 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4571 idx
=infoPtr
->root
->firstChild
;
4574 /* At the end point, sort out wrapping */
4577 /* If endidx is null, stop at the last item (ie top to bottom) */
4581 /* Otherwise, start again at the very beginning */
4582 idx
=infoPtr
->root
->firstChild
;
4584 /* But if we are stopping on the first child, end now! */
4585 if (idx
== endidx
) break;
4589 ZeroMemory(&item
, sizeof(item
));
4590 item
.mask
= TVIF_TEXT
;
4592 item
.pszText
= buffer
;
4593 item
.cchTextMax
= sizeof(buffer
);
4594 TREEVIEW_GetItemT( infoPtr
, &item
, TRUE
);
4596 /* check for a match */
4597 if (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4600 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4601 (nItem
!= infoPtr
->selectedItem
) &&
4602 (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4603 /* This would work but we must keep looking for a longer match */
4606 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4607 } while (idx
!= endidx
);
4609 if (nItem
!= NULL
) {
4610 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4611 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4618 /* Scrolling ************************************************************/
4621 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4624 BOOL hasFirstVisible
= infoPtr
->firstVisible
!= NULL
;
4625 HTREEITEM newFirstVisible
= NULL
;
4626 int visible_pos
= -1;
4628 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4631 if (!ISVISIBLE(item
))
4633 /* Expand parents as necessary. */
4636 /* see if we are trying to ensure that root is visible */
4637 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4638 parent
= item
->parent
;
4640 parent
= item
; /* this item is the topmost item */
4642 while (parent
!= infoPtr
->root
)
4644 if (!(parent
->state
& TVIS_EXPANDED
))
4645 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, FALSE
);
4647 parent
= parent
->parent
;
4651 viscount
= TREEVIEW_GetVisibleCount(infoPtr
);
4653 TRACE("%p (%s) %d - %d viscount(%d)\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4654 hasFirstVisible
? infoPtr
->firstVisible
->visibleOrder
: -1, viscount
);
4656 if (hasFirstVisible
)
4657 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4659 if (visible_pos
< 0)
4661 /* item is before the start of the list: put it at the top. */
4662 newFirstVisible
= item
;
4664 else if (visible_pos
>= viscount
4665 /* Sometimes, before we are displayed, GVC is 0, causing us to
4666 * spuriously scroll up. */
4667 && visible_pos
> 0 && !(infoPtr
->dwStyle
& TVS_NOSCROLL
) )
4669 /* item is past the end of the list. */
4670 int scroll
= visible_pos
- viscount
;
4672 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4678 /* Scroll window so item's text is visible as much as possible */
4679 /* Calculation of amount of extra space is taken from EditLabel code */
4681 TEXTMETRICW textMetric
;
4682 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4684 x
= item
->textWidth
;
4686 GetTextMetricsW(hdc
, &textMetric
);
4687 ReleaseDC(infoPtr
->hwnd
, hdc
);
4689 x
+= (textMetric
.tmMaxCharWidth
* 2);
4690 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4692 if (item
->textOffset
< 0)
4693 pos
= item
->textOffset
;
4694 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4696 if (x
> infoPtr
->clientWidth
)
4697 pos
= item
->textOffset
;
4699 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4704 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4707 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4709 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4718 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4719 TREEVIEW_ITEM
*newFirstVisible
,
4720 BOOL bUpdateScrollPos
)
4724 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4726 if (newFirstVisible
!= NULL
)
4728 /* Prevent an empty gap from appearing at the bottom... */
4729 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4730 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4734 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4737 /* ... unless we just don't have enough items. */
4738 if (newFirstVisible
== NULL
)
4739 newFirstVisible
= infoPtr
->root
->firstChild
;
4743 if (infoPtr
->firstVisible
!= newFirstVisible
)
4745 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4747 infoPtr
->firstVisible
= newFirstVisible
;
4748 TREEVIEW_Invalidate(infoPtr
, NULL
);
4752 TREEVIEW_ITEM
*item
;
4753 int scroll
= infoPtr
->uItemHeight
*
4754 (infoPtr
->firstVisible
->visibleOrder
4755 - newFirstVisible
->visibleOrder
);
4757 infoPtr
->firstVisible
= newFirstVisible
;
4759 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4760 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4762 item
->rect
.top
+= scroll
;
4763 item
->rect
.bottom
+= scroll
;
4766 if (bUpdateScrollPos
)
4767 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4768 newFirstVisible
->visibleOrder
, TRUE
);
4770 ScrollWindowEx(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
, NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
4775 /************************************************************************
4776 * VScroll is always in units of visible items. i.e. we always have a
4777 * visible item aligned to the top of the control. (Unless we have no
4781 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4783 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4784 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4786 int nScrollCode
= LOWORD(wParam
);
4788 TRACE("wp %lx\n", wParam
);
4790 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4793 if (!oldFirstVisible
)
4795 assert(infoPtr
->root
->firstChild
== NULL
);
4799 switch (nScrollCode
)
4802 newFirstVisible
= infoPtr
->root
->firstChild
;
4806 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4810 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4814 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4818 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4819 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4823 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4824 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4828 case SB_THUMBPOSITION
:
4829 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4830 infoPtr
->root
->firstChild
,
4831 (LONG
)(SHORT
)HIWORD(wParam
));
4838 if (newFirstVisible
!= NULL
)
4840 if (newFirstVisible
!= oldFirstVisible
)
4841 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4842 nScrollCode
!= SB_THUMBTRACK
);
4843 else if (nScrollCode
== SB_THUMBPOSITION
)
4844 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4845 newFirstVisible
->visibleOrder
, TRUE
);
4852 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4855 int scrollX
= infoPtr
->scrollX
;
4856 int nScrollCode
= LOWORD(wParam
);
4858 TRACE("wp %lx\n", wParam
);
4860 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4863 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4864 /* shall never occur */
4871 switch (nScrollCode
)
4874 scrollX
-= infoPtr
->uItemHeight
;
4877 scrollX
+= infoPtr
->uItemHeight
;
4880 scrollX
-= infoPtr
->clientWidth
;
4883 scrollX
+= infoPtr
->clientWidth
;
4887 case SB_THUMBPOSITION
:
4888 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4895 if (scrollX
> maxWidth
)
4897 else if (scrollX
< 0)
4901 if (scrollX
!= infoPtr
->scrollX
)
4903 TREEVIEW_ITEM
*item
;
4904 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4906 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4907 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4909 item
->linesOffset
+= scroll_pixels
;
4910 item
->stateOffset
+= scroll_pixels
;
4911 item
->imageOffset
+= scroll_pixels
;
4912 item
->textOffset
+= scroll_pixels
;
4915 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4916 infoPtr
->scrollX
= scrollX
;
4917 UpdateWindow(infoPtr
->hwnd
);
4920 if (nScrollCode
!= SB_THUMBTRACK
)
4921 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
4927 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4930 UINT pulScrollLines
= 3;
4932 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4933 return DefWindowProcW(infoPtr
->hwnd
, WM_MOUSEWHEEL
, wParam
, lParam
);
4935 if (infoPtr
->firstVisible
== NULL
)
4938 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
4940 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4941 /* if scrolling changes direction, ignore left overs */
4942 if ((wheelDelta
< 0 && infoPtr
->wheelRemainder
< 0) ||
4943 (wheelDelta
> 0 && infoPtr
->wheelRemainder
> 0))
4944 infoPtr
->wheelRemainder
+= wheelDelta
;
4946 infoPtr
->wheelRemainder
= wheelDelta
;
4948 if (infoPtr
->wheelRemainder
&& pulScrollLines
)
4954 lineScroll
= pulScrollLines
* (float)infoPtr
->wheelRemainder
/ WHEEL_DELTA
;
4955 infoPtr
->wheelRemainder
-= WHEEL_DELTA
* lineScroll
/ (int)pulScrollLines
;
4957 newDy
= infoPtr
->firstVisible
->visibleOrder
- lineScroll
;
4958 maxDy
= infoPtr
->maxVisibleOrder
;
4966 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
4971 /* Create/Destroy *******************************************************/
4974 TREEVIEW_InitCheckboxes(TREEVIEW_INFO
*infoPtr
)
4977 HBITMAP hbm
, hbmOld
;
4981 infoPtr
->himlState
= ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
4983 hdcScreen
= GetDC(0);
4985 hdc
= CreateCompatibleDC(hdcScreen
);
4986 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
4987 hbmOld
= SelectObject(hdc
, hbm
);
4989 SetRect(&rc
, 0, 0, 48, 16);
4990 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
4992 SetRect(&rc
, 18, 2, 30, 14);
4993 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4994 DFCS_BUTTONCHECK
|DFCS_FLAT
);
4996 SetRect(&rc
, 34, 2, 46, 14);
4997 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4998 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
5000 SelectObject(hdc
, hbmOld
);
5001 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
5002 comctl32_color
.clrWindow
);
5003 TRACE("checkbox index %d\n", nIndex
);
5007 ReleaseDC(0, hdcScreen
);
5009 infoPtr
->stateImageWidth
= 16;
5010 infoPtr
->stateImageHeight
= 16;
5014 TREEVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5017 TREEVIEW_INFO
*infoPtr
;
5020 TRACE("wnd %p, style %x\n", hwnd
, GetWindowLongW(hwnd
, GWL_STYLE
));
5022 infoPtr
= Alloc(sizeof(TREEVIEW_INFO
));
5024 if (infoPtr
== NULL
)
5026 ERR("could not allocate info memory!\n");
5030 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
5032 infoPtr
->hwnd
= hwnd
;
5033 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5035 infoPtr
->uNumItems
= 0;
5036 infoPtr
->cdmode
= 0;
5037 infoPtr
->uScrollTime
= 300; /* milliseconds */
5038 infoPtr
->bRedraw
= TRUE
;
5040 GetClientRect(hwnd
, &rcClient
);
5042 /* No scroll bars yet. */
5043 infoPtr
->clientWidth
= rcClient
.right
;
5044 infoPtr
->clientHeight
= rcClient
.bottom
;
5045 infoPtr
->uInternalStatus
= 0;
5047 infoPtr
->treeWidth
= 0;
5048 infoPtr
->treeHeight
= 0;
5050 infoPtr
->uIndent
= MINIMUM_INDENT
;
5051 infoPtr
->selectedItem
= NULL
;
5052 infoPtr
->focusedItem
= NULL
;
5053 infoPtr
->hotItem
= NULL
;
5054 infoPtr
->editItem
= NULL
;
5055 infoPtr
->firstVisible
= NULL
;
5056 infoPtr
->maxVisibleOrder
= 0;
5057 infoPtr
->dropItem
= NULL
;
5058 infoPtr
->insertMarkItem
= NULL
;
5059 infoPtr
->insertBeforeorAfter
= 0;
5062 infoPtr
->scrollX
= 0;
5063 infoPtr
->wheelRemainder
= 0;
5065 infoPtr
->clrBk
= CLR_NONE
; /* use system color */
5066 infoPtr
->clrText
= CLR_NONE
; /* use system color */
5067 infoPtr
->clrLine
= CLR_DEFAULT
;
5068 infoPtr
->clrInsertMark
= CLR_DEFAULT
;
5072 infoPtr
->hwndEdit
= NULL
;
5073 infoPtr
->wpEditOrig
= NULL
;
5074 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
5075 infoPtr
->bLabelChanged
= FALSE
;
5077 infoPtr
->himlNormal
= NULL
;
5078 infoPtr
->himlState
= NULL
;
5079 infoPtr
->normalImageWidth
= 0;
5080 infoPtr
->normalImageHeight
= 0;
5081 infoPtr
->stateImageWidth
= 0;
5082 infoPtr
->stateImageHeight
= 0;
5084 infoPtr
->items
= DPA_Create(16);
5086 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
5087 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW(&lf
);
5088 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
5089 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
5090 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
5091 infoPtr
->hcurHand
= LoadCursorW(NULL
, (LPWSTR
)IDC_HAND
);
5093 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
5095 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
5096 infoPtr
->root
->state
= TVIS_EXPANDED
;
5097 infoPtr
->root
->iLevel
= -1;
5098 infoPtr
->root
->visibleOrder
= -1;
5100 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5101 infoPtr
->hwndToolTip
= 0;
5103 /* Determine what type of notify should be issued (sets infoPtr->bNtfUnicode) */
5104 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
5106 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
5107 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
5108 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
5111 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5112 TREEVIEW_InitCheckboxes(infoPtr
);
5114 /* Make sure actual scrollbar state is consistent with uInternalStatus */
5115 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
5116 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
5118 OpenThemeData (hwnd
, themeClass
);
5125 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
5129 /* free item data */
5130 TREEVIEW_RemoveTree(infoPtr
);
5131 /* root isn't freed with other items */
5132 TREEVIEW_FreeItem(infoPtr
, infoPtr
->root
);
5133 DPA_Destroy(infoPtr
->items
);
5135 /* tool tip is automatically destroyed: we are its owner */
5137 /* Restore original wndproc */
5138 if (infoPtr
->hwndEdit
)
5139 SetWindowLongPtrW(infoPtr
->hwndEdit
, GWLP_WNDPROC
,
5140 (DWORD_PTR
)infoPtr
->wpEditOrig
);
5142 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
5144 /* Deassociate treeview from the window before doing anything drastic. */
5145 SetWindowLongPtrW(infoPtr
->hwnd
, 0, 0);
5147 DeleteObject(infoPtr
->hDefaultFont
);
5148 DeleteObject(infoPtr
->hBoldFont
);
5149 DeleteObject(infoPtr
->hUnderlineFont
);
5150 DeleteObject(infoPtr
->hBoldUnderlineFont
);
5156 /* Miscellaneous Messages ***********************************************/
5159 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
5167 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
5168 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
5169 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
5170 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
5171 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
5172 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
5173 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
5174 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
5175 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
5179 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
5181 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
5183 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
5185 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
5191 /************************************************************************
5194 * VK_UP Move selection to the previous non-hidden item.
5195 * VK_DOWN Move selection to the next non-hidden item.
5196 * VK_HOME Move selection to the first item.
5197 * VK_END Move selection to the last item.
5198 * VK_LEFT If expanded then collapse, otherwise move to parent.
5199 * VK_RIGHT If collapsed then expand, otherwise move to first child.
5201 * VK_SUBTRACT Collapse.
5202 * VK_MULTIPLY Expand all.
5203 * VK_PRIOR Move up GetVisibleCount items.
5204 * VK_NEXT Move down GetVisibleCount items.
5205 * VK_BACK Move to parent.
5206 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
5209 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
5211 /* If it is non-NULL and different, it will be selected and visible. */
5212 TREEVIEW_ITEM
*newSelection
= NULL
;
5214 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
5216 TRACE("%lx\n", wParam
);
5218 if (prevItem
== NULL
)
5221 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
5222 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
5227 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
5229 newSelection
= infoPtr
->root
->firstChild
;
5233 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
5237 newSelection
= infoPtr
->root
->firstChild
;
5241 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
5245 if (prevItem
->state
& TVIS_EXPANDED
)
5247 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5249 else if (prevItem
->parent
!= infoPtr
->root
)
5251 newSelection
= prevItem
->parent
;
5256 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
5258 if (!(prevItem
->state
& TVIS_EXPANDED
))
5259 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5262 newSelection
= prevItem
->firstChild
;
5269 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5273 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5277 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5282 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5283 -TREEVIEW_GetVisibleCount(infoPtr
));
5288 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5289 TREEVIEW_GetVisibleCount(infoPtr
));
5293 newSelection
= prevItem
->parent
;
5294 if (newSelection
== infoPtr
->root
)
5295 newSelection
= NULL
;
5299 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5300 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5304 if (newSelection
&& newSelection
!= prevItem
)
5306 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5309 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5317 TREEVIEW_MouseLeave (TREEVIEW_INFO
* infoPtr
)
5319 /* remove hot effect from item */
5320 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5321 infoPtr
->hotItem
= NULL
;
5327 TREEVIEW_MouseMove (TREEVIEW_INFO
* infoPtr
, LPARAM lParam
)
5330 TRACKMOUSEEVENT trackinfo
;
5331 TREEVIEW_ITEM
* item
;
5333 if (!(infoPtr
->dwStyle
& TVS_TRACKSELECT
)) return 0;
5335 /* fill in the TRACKMOUSEEVENT struct */
5336 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5337 trackinfo
.dwFlags
= TME_QUERY
;
5338 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5340 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5341 _TrackMouseEvent(&trackinfo
);
5343 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5344 if(!(trackinfo
.dwFlags
& TME_LEAVE
))
5346 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5347 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5348 /* do it as fast as possible, minimal systimer latency will be used */
5349 trackinfo
.dwHoverTime
= 1;
5351 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5352 /* and can properly deactivate the hot item */
5353 _TrackMouseEvent(&trackinfo
);
5356 pt
.x
= (short)LOWORD(lParam
);
5357 pt
.y
= (short)HIWORD(lParam
);
5359 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5361 if (item
!= infoPtr
->hotItem
)
5363 /* redraw old hot item */
5364 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5365 infoPtr
->hotItem
= item
;
5366 /* redraw new hot item */
5367 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5373 /* Draw themed border */
5374 static BOOL
TREEVIEW_NCPaint (const TREEVIEW_INFO
*infoPtr
, HRGN region
, LPARAM lParam
)
5376 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5380 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
5381 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
5384 return DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)region
, lParam
);
5386 GetWindowRect(infoPtr
->hwnd
, &r
);
5388 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
5389 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
5390 if (region
!= (HRGN
)1)
5391 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
5392 OffsetRect(&r
, -r
.left
, -r
.top
);
5394 dc
= GetDCEx(infoPtr
->hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
5395 OffsetRect(&r
, -r
.left
, -r
.top
);
5397 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
5398 DrawThemeParentBackground(infoPtr
->hwnd
, dc
, &r
);
5399 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
5400 ReleaseDC(infoPtr
->hwnd
, dc
);
5402 /* Call default proc to get the scrollbars etc. painted */
5403 DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
5409 TREEVIEW_Notify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5411 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5413 if (lpnmh
->code
== PGN_CALCSIZE
) {
5414 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5416 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5417 lppgc
->iWidth
= infoPtr
->treeWidth
;
5418 TRACE("got PGN_CALCSIZE, returning horz size = %d, client=%d\n",
5419 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5422 lppgc
->iHeight
= infoPtr
->treeHeight
;
5423 TRACE("got PGN_CALCSIZE, returning vert size = %d, client=%d\n",
5424 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5428 return DefWindowProcW(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5432 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5434 if (wParam
== SIZE_RESTORED
)
5436 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5437 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5439 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5440 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5441 TREEVIEW_UpdateScrollBars(infoPtr
);
5445 FIXME("WM_SIZE flag %lx %lx not handled\n", wParam
, lParam
);
5448 TREEVIEW_Invalidate(infoPtr
, NULL
);
5452 static void TREEVIEW_ResetImageStateIndex(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
5454 TREEVIEW_ITEM
*child
= item
->firstChild
;
5456 item
->state
&= ~TVIS_STATEIMAGEMASK
;
5457 item
->state
|= INDEXTOSTATEIMAGEMASK(1);
5461 TREEVIEW_ITEM
*next
= child
->nextSibling
;
5462 TREEVIEW_ResetImageStateIndex(infoPtr
, child
);
5468 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5470 TRACE("(%lx %lx)\n", wParam
, lParam
);
5472 if (wParam
== GWL_STYLE
)
5474 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5476 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_CHECKBOXES
)
5478 if (dwNewStyle
& TVS_CHECKBOXES
)
5480 TREEVIEW_InitCheckboxes(infoPtr
);
5481 TRACE("checkboxes enabled\n");
5483 /* set all items to state image index 1 */
5484 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
5488 FIXME("tried to disable checkboxes\n");
5492 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5494 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5496 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5497 TRACE("tooltips enabled\n");
5501 DestroyWindow(infoPtr
->hwndToolTip
);
5502 infoPtr
->hwndToolTip
= 0;
5503 TRACE("tooltips disabled\n");
5507 infoPtr
->dwStyle
= dwNewStyle
;
5510 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5511 TREEVIEW_UpdateScrollBars(infoPtr
);
5512 TREEVIEW_Invalidate(infoPtr
, NULL
);
5518 TREEVIEW_SetCursor(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5521 TREEVIEW_ITEM
* item
;
5525 ScreenToClient(infoPtr
->hwnd
, &pt
);
5527 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5529 memset(&nmmouse
, 0, sizeof(nmmouse
));
5530 nmmouse
.hdr
.hwndFrom
= infoPtr
->hwnd
;
5531 nmmouse
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwnd
, GWLP_ID
);
5532 nmmouse
.hdr
.code
= NM_SETCURSOR
;
5535 nmmouse
.dwItemSpec
= (DWORD_PTR
)item
;
5536 nmmouse
.dwItemData
= item
->lParam
;
5540 nmmouse
.dwHitInfo
= lParam
;
5541 if (TREEVIEW_SendRealNotify(infoPtr
, nmmouse
.hdr
.idFrom
, &nmmouse
.hdr
))
5544 if (item
&& (infoPtr
->dwStyle
& TVS_TRACKSELECT
))
5546 SetCursor(infoPtr
->hcurHand
);
5550 return DefWindowProcW(infoPtr
->hwnd
, WM_SETCURSOR
, wParam
, lParam
);
5554 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5558 if (!infoPtr
->selectedItem
)
5560 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5564 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5565 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5570 TREEVIEW_KillFocus(const TREEVIEW_INFO
*infoPtr
)
5574 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5575 UpdateWindow(infoPtr
->hwnd
);
5576 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5580 /* update theme after a WM_THEMECHANGED message */
5581 static LRESULT
TREEVIEW_ThemeChanged(const TREEVIEW_INFO
*infoPtr
)
5583 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5584 CloseThemeData (theme
);
5585 OpenThemeData (infoPtr
->hwnd
, themeClass
);
5590 static LRESULT WINAPI
5591 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5593 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5595 TRACE("hwnd %p msg %04x wp=%08lx lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5597 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5600 if (uMsg
== WM_CREATE
)
5601 TREEVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
5608 case TVM_CREATEDRAGIMAGE
:
5609 return TREEVIEW_CreateDragImage(infoPtr
, lParam
);
5611 case TVM_DELETEITEM
:
5612 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5614 case TVM_EDITLABELA
:
5615 case TVM_EDITLABELW
:
5616 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5618 case TVM_ENDEDITLABELNOW
:
5619 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5621 case TVM_ENSUREVISIBLE
:
5622 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5625 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5627 case TVM_GETBKCOLOR
:
5628 return TREEVIEW_GetBkColor(infoPtr
);
5631 return TREEVIEW_GetCount(infoPtr
);
5633 case TVM_GETEDITCONTROL
:
5634 return TREEVIEW_GetEditControl(infoPtr
);
5636 case TVM_GETIMAGELIST
:
5637 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5640 return TREEVIEW_GetIndent(infoPtr
);
5642 case TVM_GETINSERTMARKCOLOR
:
5643 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5645 case TVM_GETISEARCHSTRINGA
:
5646 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5649 case TVM_GETISEARCHSTRINGW
:
5650 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5655 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5656 uMsg
== TVM_GETITEMW
);
5657 case TVM_GETITEMHEIGHT
:
5658 return TREEVIEW_GetItemHeight(infoPtr
);
5660 case TVM_GETITEMRECT
:
5661 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5663 case TVM_GETITEMSTATE
:
5664 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5666 case TVM_GETLINECOLOR
:
5667 return TREEVIEW_GetLineColor(infoPtr
);
5669 case TVM_GETNEXTITEM
:
5670 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5672 case TVM_GETSCROLLTIME
:
5673 return TREEVIEW_GetScrollTime(infoPtr
);
5675 case TVM_GETTEXTCOLOR
:
5676 return TREEVIEW_GetTextColor(infoPtr
);
5678 case TVM_GETTOOLTIPS
:
5679 return TREEVIEW_GetToolTips(infoPtr
);
5681 case TVM_GETUNICODEFORMAT
:
5682 return TREEVIEW_GetUnicodeFormat(infoPtr
);
5684 case TVM_GETVISIBLECOUNT
:
5685 return TREEVIEW_GetVisibleCount(infoPtr
);
5688 return TREEVIEW_HitTest(infoPtr
, (LPTVHITTESTINFO
)lParam
);
5690 case TVM_INSERTITEMA
:
5691 case TVM_INSERTITEMW
:
5692 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
,
5693 uMsg
== TVM_INSERTITEMW
);
5694 case TVM_SELECTITEM
:
5695 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5697 case TVM_SETBKCOLOR
:
5698 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5700 case TVM_SETIMAGELIST
:
5701 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5704 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5706 case TVM_SETINSERTMARK
:
5707 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5709 case TVM_SETINSERTMARKCOLOR
:
5710 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5714 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5715 uMsg
== TVM_SETITEMW
);
5716 case TVM_SETLINECOLOR
:
5717 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5719 case TVM_SETITEMHEIGHT
:
5720 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5722 case TVM_SETSCROLLTIME
:
5723 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5725 case TVM_SETTEXTCOLOR
:
5726 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5728 case TVM_SETTOOLTIPS
:
5729 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5731 case TVM_SETUNICODEFORMAT
:
5732 return TREEVIEW_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
5734 case TVM_SORTCHILDREN
:
5735 return TREEVIEW_SortChildren(infoPtr
, lParam
);
5737 case TVM_SORTCHILDRENCB
:
5738 return TREEVIEW_SortChildrenCB(infoPtr
, (LPTVSORTCB
)lParam
);
5741 return TREEVIEW_ProcessLetterKeys(infoPtr
, wParam
, lParam
);
5744 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5747 return TREEVIEW_Destroy(infoPtr
);
5752 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5755 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5758 return TREEVIEW_GetFont(infoPtr
);
5761 return TREEVIEW_HScroll(infoPtr
, wParam
);
5764 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5767 return TREEVIEW_KillFocus(infoPtr
);
5769 case WM_LBUTTONDBLCLK
:
5770 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5772 case WM_LBUTTONDOWN
:
5773 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5775 /* WM_MBUTTONDOWN */
5778 return TREEVIEW_MouseLeave(infoPtr
);
5781 return TREEVIEW_MouseMove(infoPtr
, lParam
);
5783 case WM_NCLBUTTONDOWN
:
5784 if (infoPtr
->hwndEdit
)
5785 SetFocus(infoPtr
->hwnd
);
5789 return TREEVIEW_NCPaint (infoPtr
, (HRGN
)wParam
, lParam
);
5792 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5794 case WM_NOTIFYFORMAT
:
5795 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5797 case WM_PRINTCLIENT
:
5798 return TREEVIEW_PrintClient(infoPtr
, (HDC
)wParam
, lParam
);
5801 return TREEVIEW_Paint(infoPtr
, (HDC
)wParam
);
5803 case WM_RBUTTONDOWN
:
5804 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5807 return TREEVIEW_SetCursor(infoPtr
, wParam
, lParam
);
5810 return TREEVIEW_SetFocus(infoPtr
);
5813 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5816 return TREEVIEW_SetRedraw(infoPtr
, wParam
);
5819 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5821 case WM_STYLECHANGED
:
5822 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5824 case WM_SYSCOLORCHANGE
:
5825 COMCTL32_RefreshSysColors();
5831 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5833 case WM_THEMECHANGED
:
5834 return TREEVIEW_ThemeChanged (infoPtr
);
5837 return TREEVIEW_VScroll(infoPtr
, wParam
);
5839 /* WM_WININICHANGE */
5842 return TREEVIEW_MouseWheel(infoPtr
, wParam
, lParam
);
5845 TRACE("drawItem\n");
5849 /* This mostly catches MFC and Delphi messages. :( */
5850 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
5851 TRACE("Unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
5853 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
5858 /* Class Registration ***************************************************/
5861 TREEVIEW_Register(void)
5867 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
5868 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5869 wndClass
.lpfnWndProc
= TREEVIEW_WindowProc
;
5870 wndClass
.cbClsExtra
= 0;
5871 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5873 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
5874 wndClass
.hbrBackground
= 0;
5875 wndClass
.lpszClassName
= WC_TREEVIEWW
;
5877 RegisterClassW(&wndClass
);
5882 TREEVIEW_Unregister(void)
5884 UnregisterClassW(WC_TREEVIEWW
, NULL
);
5888 /* Tree Verification ****************************************************/
5891 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
);
5893 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5894 const TREEVIEW_ITEM
*item
)
5896 assert(infoPtr
!= NULL
);
5897 assert(item
!= NULL
);
5899 /* both NULL, or both non-null */
5900 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5902 assert(item
->firstChild
!= item
);
5903 assert(item
->lastChild
!= item
);
5905 if (item
->firstChild
)
5907 assert(item
->firstChild
->parent
== item
);
5908 assert(item
->firstChild
->prevSibling
== NULL
);
5911 if (item
->lastChild
)
5913 assert(item
->lastChild
->parent
== item
);
5914 assert(item
->lastChild
->nextSibling
== NULL
);
5917 assert(item
->nextSibling
!= item
);
5918 if (item
->nextSibling
)
5920 assert(item
->nextSibling
->parent
== item
->parent
);
5921 assert(item
->nextSibling
->prevSibling
== item
);
5924 assert(item
->prevSibling
!= item
);
5925 if (item
->prevSibling
)
5927 assert(item
->prevSibling
->parent
== item
->parent
);
5928 assert(item
->prevSibling
->nextSibling
== item
);
5933 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5935 assert(item
!= NULL
);
5937 assert(item
->parent
!= NULL
);
5938 assert(item
->parent
!= item
);
5939 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5941 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5943 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5945 TREEVIEW_VerifyChildren(infoPtr
, item
);
5949 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5951 const TREEVIEW_ITEM
*child
;
5952 assert(item
!= NULL
);
5954 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5955 TREEVIEW_VerifyItem(infoPtr
, child
);
5959 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5961 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5963 assert(root
!= NULL
);
5964 assert(root
->iLevel
== -1);
5965 assert(root
->parent
== NULL
);
5966 assert(root
->prevSibling
== NULL
);
5968 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
5970 TREEVIEW_VerifyChildren(infoPtr
, root
);
5974 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
5976 if (!TRACE_ON(treeview
)) return;
5978 assert(infoPtr
!= NULL
);
5979 TREEVIEW_VerifyRoot(infoPtr
);