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.
45 WINE_DEFAULT_DEBUG_CHANNEL(treeview
);
47 /* internal structures */
48 typedef struct tagTREEVIEW_INFO
51 HWND hwndNotify
; /* Owner window to send notifications to */
56 UINT uNumItems
; /* number of valid TREEVIEW_ITEMs */
57 INT cdmode
; /* last custom draw setting */
58 UINT uScrollTime
; /* max. time for scrolling in milliseconds */
59 BOOL bRedraw
; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
61 UINT uItemHeight
; /* item height */
64 LONG clientWidth
; /* width of control window */
65 LONG clientHeight
; /* height of control window */
67 LONG treeWidth
; /* width of visible tree items */
68 LONG treeHeight
; /* height of visible tree items */
70 UINT uIndent
; /* indentation in pixels */
71 HTREEITEM selectedItem
; /* handle to selected item or 0 if none */
72 HTREEITEM hotItem
; /* handle currently under cursor, 0 if none */
73 HTREEITEM focusedItem
; /* item that was under the cursor when WM_LBUTTONDOWN was received */
74 HTREEITEM editItem
; /* item being edited with builtin edit box */
76 HTREEITEM firstVisible
; /* handle to first visible item */
78 HTREEITEM dropItem
; /* handle to item selected by drag cursor */
79 HTREEITEM insertMarkItem
; /* item after which insertion mark is placed */
80 BOOL insertBeforeorAfter
; /* flag used by TVM_SETINSERTMARK */
81 HIMAGELIST dragList
; /* Bitmap of dragged item */
87 COLORREF clrInsertMark
;
92 HFONT hBoldUnderlineFont
;
97 WNDPROC wpEditOrig
; /* orig window proc for subclassing edit */
98 BOOL bIgnoreEditKillFocus
;
101 BOOL bNtfUnicode
; /* TRUE if should send NOTIFY with W */
102 HIMAGELIST himlNormal
;
103 int normalImageHeight
;
104 int normalImageWidth
;
105 HIMAGELIST himlState
;
106 int stateImageHeight
;
110 DWORD lastKeyPressTimestamp
;
112 INT nSearchParamLength
;
113 WCHAR szSearchParam
[ MAX_PATH
];
116 typedef struct _TREEITEM
/* HTREEITEM is a _TREEINFO *. */
118 HTREEITEM parent
; /* handle to parent or 0 if at root */
119 HTREEITEM nextSibling
; /* handle to next item in list, 0 if last */
120 HTREEITEM firstChild
; /* handle to first child or 0 if no child */
132 int iIntegral
; /* item height multiplier (1 is normal) */
133 int iLevel
; /* indentation level:0=root level */
135 HTREEITEM prevSibling
; /* handle to prev item in list, 0 if first */
141 LONG textWidth
; /* horizontal text extent for pszText */
142 LONG visibleOrder
; /* visible ordering, 0 is first visible item */
143 const TREEVIEW_INFO
*infoPtr
; /* tree data this item belongs to */
146 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
147 #define KEY_DELAY 450
149 /* bitflags for infoPtr->uInternalStatus */
151 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
152 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
153 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
154 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
155 #define TV_RDRAG 0x10 /* ditto Rbutton */
156 #define TV_RDRAGGING 0x20
158 /* bitflags for infoPtr->timer */
160 #define TV_EDIT_TIMER 2
161 #define TV_EDIT_TIMER_SET 2
163 #define TEXT_CALLBACK_SIZE 260
165 #define TREEVIEW_LEFT_MARGIN 8
167 #define MINIMUM_INDENT 19
169 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
171 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
172 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
173 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
175 #define GETLINECOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrGrayText : (x))
176 #define GETBKCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindow : (x))
177 #define GETTXTCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindowText : (x))
178 #define GETINSCOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrBtnText : (x))
180 static const WCHAR themeClass
[] = { 'T','r','e','e','v','i','e','w',0 };
183 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
186 static VOID
TREEVIEW_Invalidate(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
188 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
189 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
190 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
191 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
192 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
193 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
195 /* Random Utilities *****************************************************/
196 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
198 /* Returns the treeview private data if hwnd is a treeview.
199 * Otherwise returns an undefined value. */
200 static inline TREEVIEW_INFO
*
201 TREEVIEW_GetInfoPtr(HWND hwnd
)
203 return (TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
206 /* Don't call this. Nothing wants an item index. */
208 TREEVIEW_GetItemIndex(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
210 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
213 /* Checks if item has changed and needs to be redrawn */
214 static inline BOOL
item_changed (const TREEVIEW_ITEM
*tiOld
, const TREEVIEW_ITEM
*tiNew
,
215 const TVITEMEXW
*tvChange
)
217 /* Number of children has changed */
218 if ((tvChange
->mask
& TVIF_CHILDREN
) && (tiOld
->cChildren
!= tiNew
->cChildren
))
221 /* Image has changed and it's not a callback */
222 if ((tvChange
->mask
& TVIF_IMAGE
) && (tiOld
->iImage
!= tiNew
->iImage
) &&
223 tiNew
->iImage
!= I_IMAGECALLBACK
)
226 /* Selected image has changed and it's not a callback */
227 if ((tvChange
->mask
& TVIF_SELECTEDIMAGE
) && (tiOld
->iSelectedImage
!= tiNew
->iSelectedImage
) &&
228 tiNew
->iSelectedImage
!= I_IMAGECALLBACK
)
231 if ((tvChange
->mask
& TVIF_EXPANDEDIMAGE
) && (tiOld
->iExpandedImage
!= tiNew
->iExpandedImage
) &&
232 tiNew
->iExpandedImage
!= I_IMAGECALLBACK
)
235 /* Text has changed and it's not a callback */
236 if ((tvChange
->mask
& TVIF_TEXT
) && (tiOld
->pszText
!= tiNew
->pszText
) &&
237 tiNew
->pszText
!= LPSTR_TEXTCALLBACKW
)
240 /* Indent has changed */
241 if ((tvChange
->mask
& TVIF_INTEGRAL
) && (tiOld
->iIntegral
!= tiNew
->iIntegral
))
244 /* Item state has changed */
245 if ((tvChange
->mask
& TVIF_STATE
) && ((tiOld
->state
^ tiNew
->state
) & tvChange
->stateMask
))
251 /***************************************************************************
252 * This method checks that handle is an item for this tree.
255 TREEVIEW_ValidItem(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
257 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
259 TRACE("invalid item %p\n", handle
);
267 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
271 GetObjectW(hOrigFont
, sizeof(font
), &font
);
272 font
.lfWeight
= FW_BOLD
;
273 return CreateFontIndirectW(&font
);
277 TREEVIEW_CreateUnderlineFont(HFONT hOrigFont
)
281 GetObjectW(hOrigFont
, sizeof(font
), &font
);
282 font
.lfUnderline
= TRUE
;
283 return CreateFontIndirectW(&font
);
287 TREEVIEW_CreateBoldUnderlineFont(HFONT hfont
)
291 GetObjectW(hfont
, sizeof(font
), &font
);
292 font
.lfWeight
= FW_BOLD
;
293 font
.lfUnderline
= TRUE
;
294 return CreateFontIndirectW(&font
);
298 TREEVIEW_FontForItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
300 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
301 return item
->state
& TVIS_BOLD
? infoPtr
->hBoldUnderlineFont
: infoPtr
->hUnderlineFont
;
302 if (item
->state
& TVIS_BOLD
)
303 return infoPtr
->hBoldFont
;
304 return infoPtr
->hFont
;
307 /* for trace/debugging purposes only */
309 TREEVIEW_ItemName(const TREEVIEW_ITEM
*item
)
311 if (item
== NULL
) return "<null item>";
312 if (item
->pszText
== LPSTR_TEXTCALLBACKW
) return "<callback>";
313 if (item
->pszText
== NULL
) return "<null>";
314 return debugstr_w(item
->pszText
);
317 /* An item is not a child of itself. */
319 TREEVIEW_IsChildOf(const TREEVIEW_ITEM
*parent
, const TREEVIEW_ITEM
*child
)
323 child
= child
->parent
;
324 if (child
== parent
) return TRUE
;
325 } while (child
!= NULL
);
331 /* Tree Traversal *******************************************************/
333 /***************************************************************************
334 * This method returns the last expanded sibling or child child item
337 static TREEVIEW_ITEM
*
338 TREEVIEW_GetLastListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
340 if (!item
) return NULL
;
342 while (item
->lastChild
)
344 if (item
->state
& TVIS_EXPANDED
)
345 item
= item
->lastChild
;
350 if (item
== infoPtr
->root
)
356 /***************************************************************************
357 * This method returns the previous non-hidden item in the list not
358 * considering the tree hierarchy.
360 static TREEVIEW_ITEM
*
361 TREEVIEW_GetPrevListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
363 if (tvItem
->prevSibling
)
365 /* This item has a prevSibling, get the last item in the sibling's tree. */
366 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
368 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
369 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
375 /* this item does not have a prevSibling, get the parent */
376 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
381 /***************************************************************************
382 * This method returns the next physical item in the treeview not
383 * considering the tree hierarchy.
385 static TREEVIEW_ITEM
*
386 TREEVIEW_GetNextListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
389 * If this item has children and is expanded, return the first child
391 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
393 return tvItem
->firstChild
;
398 * try to get the sibling
400 if (tvItem
->nextSibling
)
401 return tvItem
->nextSibling
;
404 * Otherwise, get the parent's sibling.
406 while (tvItem
->parent
)
408 tvItem
= tvItem
->parent
;
410 if (tvItem
->nextSibling
)
411 return tvItem
->nextSibling
;
417 /***************************************************************************
418 * This method returns the nth item starting at the given item. It returns
419 * the last item (or first) we we run out of items.
421 * Will scroll backward if count is <0.
422 * forward if count is >0.
424 static TREEVIEW_ITEM
*
425 TREEVIEW_GetListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
428 TREEVIEW_ITEM
*(*next_item
)(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
429 TREEVIEW_ITEM
*previousItem
;
431 assert(item
!= NULL
);
435 next_item
= TREEVIEW_GetNextListItem
;
440 next_item
= TREEVIEW_GetPrevListItem
;
448 item
= next_item(infoPtr
, item
);
450 } while (--count
&& item
!= NULL
);
453 return item
? item
: previousItem
;
456 /* Notifications ************************************************************/
458 static INT
get_notifycode(const TREEVIEW_INFO
*infoPtr
, INT code
)
460 if (!infoPtr
->bNtfUnicode
) {
462 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
463 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
464 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
465 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
466 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
467 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
468 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
469 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
470 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
471 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
472 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
473 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
480 TREEVIEW_SendRealNotify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPNMHDR pnmh
)
482 TRACE("wParam=%ld, lParam=%p\n", wParam
, pnmh
);
483 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, wParam
, (LPARAM
)pnmh
);
487 TREEVIEW_SendSimpleNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
)
490 HWND hwnd
= infoPtr
->hwnd
;
493 nmhdr
.hwndFrom
= hwnd
;
494 nmhdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
495 nmhdr
.code
= get_notifycode(infoPtr
, code
);
497 return TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.idFrom
, &nmhdr
);
501 TREEVIEW_TVItemFromItem(const TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMW
*tvItem
, TREEVIEW_ITEM
*item
)
504 tvItem
->hItem
= item
;
505 tvItem
->state
= item
->state
;
506 tvItem
->stateMask
= 0;
507 tvItem
->iImage
= item
->iImage
;
508 tvItem
->iSelectedImage
= item
->iSelectedImage
;
509 tvItem
->cChildren
= item
->cChildren
;
510 tvItem
->lParam
= item
->lParam
;
514 if (!infoPtr
->bNtfUnicode
)
516 tvItem
->cchTextMax
= WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0, NULL
, NULL
);
517 tvItem
->pszText
= Alloc (tvItem
->cchTextMax
);
518 WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, 0, 0 );
522 tvItem
->cchTextMax
= item
->cchTextMax
;
523 tvItem
->pszText
= item
->pszText
;
528 tvItem
->cchTextMax
= 0;
529 tvItem
->pszText
= NULL
;
534 TREEVIEW_SendTreeviewNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
535 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
537 HWND hwnd
= infoPtr
->hwnd
;
541 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
542 code
, action
, oldItem
, newItem
);
544 ZeroMemory(&nmhdr
, sizeof(NMTREEVIEWW
));
546 nmhdr
.hdr
.hwndFrom
= hwnd
;
547 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
548 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
549 nmhdr
.action
= action
;
552 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
555 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
560 ret
= TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.hdr
.idFrom
, &nmhdr
.hdr
);
561 if (!infoPtr
->bNtfUnicode
)
563 Free(nmhdr
.itemOld
.pszText
);
564 Free(nmhdr
.itemNew
.pszText
);
570 TREEVIEW_SendTreeviewDnDNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
,
571 HTREEITEM dragItem
, POINT pt
)
573 HWND hwnd
= infoPtr
->hwnd
;
576 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
578 nmhdr
.hdr
.hwndFrom
= hwnd
;
579 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
580 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
582 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
583 nmhdr
.itemNew
.hItem
= dragItem
;
584 nmhdr
.itemNew
.state
= dragItem
->state
;
585 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
587 nmhdr
.ptDrag
.x
= pt
.x
;
588 nmhdr
.ptDrag
.y
= pt
.y
;
590 return TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.hdr
.idFrom
, &nmhdr
.hdr
);
595 TREEVIEW_SendCustomDrawNotify(const TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
598 HWND hwnd
= infoPtr
->hwnd
;
599 NMTVCUSTOMDRAW nmcdhdr
;
602 TRACE("drawstage:%x hdc:%p\n", dwDrawStage
, hdc
);
604 nmcd
= &nmcdhdr
.nmcd
;
605 nmcd
->hdr
.hwndFrom
= hwnd
;
606 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
607 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
608 nmcd
->dwDrawStage
= dwDrawStage
;
611 nmcd
->dwItemSpec
= 0;
612 nmcd
->uItemState
= 0;
613 nmcd
->lItemlParam
= 0;
614 nmcdhdr
.clrText
= infoPtr
->clrText
;
615 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
618 return TREEVIEW_SendRealNotify(infoPtr
, nmcd
->hdr
.idFrom
, &nmcdhdr
.nmcd
.hdr
);
623 /* FIXME: need to find out when the flags in uItemState need to be set */
626 TREEVIEW_SendCustomDrawItemNotify(const TREEVIEW_INFO
*infoPtr
, HDC hdc
,
627 TREEVIEW_ITEM
*item
, UINT uItemDrawState
,
628 NMTVCUSTOMDRAW
*nmcdhdr
)
630 HWND hwnd
= infoPtr
->hwnd
;
633 DWORD_PTR dwItemSpec
;
636 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
637 dwItemSpec
= (DWORD_PTR
)item
;
639 if (item
->state
& TVIS_SELECTED
)
640 uItemState
|= CDIS_SELECTED
;
641 if (item
== infoPtr
->selectedItem
)
642 uItemState
|= CDIS_FOCUS
;
643 if (item
== infoPtr
->hotItem
)
644 uItemState
|= CDIS_HOT
;
646 nmcd
= &nmcdhdr
->nmcd
;
647 nmcd
->hdr
.hwndFrom
= hwnd
;
648 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
649 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
650 nmcd
->dwDrawStage
= dwDrawStage
;
652 nmcd
->rc
= item
->rect
;
653 nmcd
->dwItemSpec
= dwItemSpec
;
654 nmcd
->uItemState
= uItemState
;
655 nmcd
->lItemlParam
= item
->lParam
;
656 nmcdhdr
->iLevel
= item
->iLevel
;
658 TRACE("drawstage:%x hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
659 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
660 nmcd
->uItemState
, nmcd
->lItemlParam
);
662 return TREEVIEW_SendRealNotify(infoPtr
, nmcd
->hdr
.idFrom
, &nmcdhdr
->nmcd
.hdr
);
666 TREEVIEW_BeginLabelEditNotify(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
668 HWND hwnd
= infoPtr
->hwnd
;
672 tvdi
.hdr
.hwndFrom
= hwnd
;
673 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
674 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_BEGINLABELEDITW
);
676 TREEVIEW_TVItemFromItem(infoPtr
, TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
,
677 &tvdi
.item
, editItem
);
679 ret
= TREEVIEW_SendRealNotify(infoPtr
, tvdi
.hdr
.idFrom
, &tvdi
.hdr
);
681 if (!infoPtr
->bNtfUnicode
)
682 Free(tvdi
.item
.pszText
);
688 TREEVIEW_UpdateDispInfo(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
691 NMTVDISPINFOEXW callback
;
692 HWND hwnd
= infoPtr
->hwnd
;
694 TRACE("mask=0x%x, callbackmask=0x%x\n", mask
, item
->callbackMask
);
695 mask
&= item
->callbackMask
;
697 if (mask
== 0) return;
699 callback
.hdr
.hwndFrom
= hwnd
;
700 callback
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
701 callback
.hdr
.code
= get_notifycode(infoPtr
, TVN_GETDISPINFOW
);
703 /* 'state' always contains valid value, as well as 'lParam'.
704 * All other parameters are uninitialized.
706 callback
.item
.pszText
= item
->pszText
;
707 callback
.item
.cchTextMax
= item
->cchTextMax
;
708 callback
.item
.mask
= mask
;
709 callback
.item
.hItem
= item
;
710 callback
.item
.state
= item
->state
;
711 callback
.item
.lParam
= item
->lParam
;
713 /* If text is changed we need to recalculate textWidth */
714 if (mask
& TVIF_TEXT
)
717 TREEVIEW_SendRealNotify(infoPtr
, callback
.hdr
.idFrom
, &callback
.hdr
);
718 TRACE("resulting code 0x%08x\n", callback
.hdr
.code
);
720 /* It may have changed due to a call to SetItem. */
721 mask
&= item
->callbackMask
;
723 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= item
->pszText
)
725 /* Instead of copying text into our buffer user specified his own */
726 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
729 int len
= MultiByteToWideChar( CP_ACP
, 0,
730 (LPSTR
)callback
.item
.pszText
, -1,
732 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
733 newText
= ReAlloc(item
->pszText
, buflen
);
735 TRACE("returned str %s, len=%d, buflen=%d\n",
736 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
740 item
->pszText
= newText
;
741 MultiByteToWideChar( CP_ACP
, 0,
742 (LPSTR
)callback
.item
.pszText
, -1,
743 item
->pszText
, buflen
/sizeof(WCHAR
));
744 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
746 /* If ReAlloc fails we have nothing to do, but keep original text */
749 int len
= max(lstrlenW(callback
.item
.pszText
) + 1,
751 LPWSTR newText
= ReAlloc(item
->pszText
, len
);
753 TRACE("returned wstr %s, len=%d\n",
754 debugstr_w(callback
.item
.pszText
), len
);
758 item
->pszText
= newText
;
759 strcpyW(item
->pszText
, callback
.item
.pszText
);
760 item
->cchTextMax
= len
;
762 /* If ReAlloc fails we have nothing to do, but keep original text */
765 else if (mask
& TVIF_TEXT
) {
766 /* User put text into our buffer, that is ok unless A string */
767 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
770 int len
= MultiByteToWideChar( CP_ACP
, 0,
771 (LPSTR
)callback
.item
.pszText
, -1,
773 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
774 newText
= Alloc(buflen
);
776 TRACE("same buffer str %s, len=%d, buflen=%d\n",
777 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
781 LPWSTR oldText
= item
->pszText
;
782 item
->pszText
= newText
;
783 MultiByteToWideChar( CP_ACP
, 0,
784 (LPSTR
)callback
.item
.pszText
, -1,
785 item
->pszText
, buflen
/sizeof(WCHAR
));
786 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
792 if (mask
& TVIF_IMAGE
)
793 item
->iImage
= callback
.item
.iImage
;
795 if (mask
& TVIF_SELECTEDIMAGE
)
796 item
->iSelectedImage
= callback
.item
.iSelectedImage
;
798 if (mask
& TVIF_EXPANDEDIMAGE
)
799 item
->iExpandedImage
= callback
.item
.iExpandedImage
;
801 if (mask
& TVIF_CHILDREN
)
802 item
->cChildren
= callback
.item
.cChildren
;
804 if (callback
.item
.mask
& TVIF_STATE
)
806 item
->state
&= ~callback
.item
.stateMask
;
807 item
->state
|= (callback
.item
.state
& callback
.item
.stateMask
);
810 /* These members are now permanently set. */
811 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
812 item
->callbackMask
&= ~callback
.item
.mask
;
815 /***************************************************************************
816 * This function uses cChildren field to decide whether the item has
818 * Note: if this returns TRUE, the child items may not actually exist,
819 * they could be virtual.
821 * Just use item->firstChild to check for physical children.
824 TREEVIEW_HasChildren(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
826 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_CHILDREN
);
828 return item
->cChildren
> 0;
831 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
835 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
837 if (nCommand
!= NF_REQUERY
) return 0;
839 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
840 TRACE("format=%d\n", format
);
842 /* Invalid format returned by NF_QUERY defaults to ANSI*/
843 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
)
846 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
851 /* Item Position ********************************************************/
853 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
855 TREEVIEW_ComputeItemInternalMetrics(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
857 /* has TVS_LINESATROOT and (TVS_HASLINES|TVS_HASBUTTONS) */
858 BOOL lar
= ((infoPtr
->dwStyle
& (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
861 item
->linesOffset
= infoPtr
->uIndent
* (lar
? item
->iLevel
: item
->iLevel
- 1)
863 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
864 item
->imageOffset
= item
->stateOffset
865 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
866 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
870 TREEVIEW_ComputeTextWidth(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
876 /* DRAW's OM docker creates items like this */
877 if (item
->pszText
== NULL
)
889 hdc
= GetDC(infoPtr
->hwnd
);
890 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
893 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
894 item
->textWidth
= sz
.cx
;
898 SelectObject(hdc
, hOldFont
);
904 TREEVIEW_ComputeItemRect(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
906 item
->rect
.top
= infoPtr
->uItemHeight
*
907 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
909 item
->rect
.bottom
= item
->rect
.top
910 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
913 item
->rect
.right
= infoPtr
->clientWidth
;
916 /* We know that only items after start need their order updated. */
918 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
925 start
= infoPtr
->root
->firstChild
;
929 order
= start
->visibleOrder
;
931 for (item
= start
; item
!= NULL
;
932 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
934 if (!ISVISIBLE(item
) && order
> 0)
935 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
936 item
->visibleOrder
= order
;
937 order
+= item
->iIntegral
;
940 infoPtr
->maxVisibleOrder
= order
;
942 for (item
= start
; item
!= NULL
;
943 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
945 TREEVIEW_ComputeItemRect(infoPtr
, item
);
950 /* Update metrics of all items in selected subtree.
951 * root must be expanded
954 TREEVIEW_UpdateSubTree(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
956 TREEVIEW_ITEM
*sibling
;
960 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
963 root
->state
&= ~TVIS_EXPANDED
;
964 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
965 root
->state
|= TVIS_EXPANDED
;
967 hdc
= GetDC(infoPtr
->hwnd
);
968 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
970 for (; root
!= sibling
;
971 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
973 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
975 if (root
->callbackMask
& TVIF_TEXT
)
976 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
978 if (root
->textWidth
== 0)
980 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
981 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
985 SelectObject(hdc
, hOldFont
);
986 ReleaseDC(infoPtr
->hwnd
, hdc
);
989 /* Item Allocation **********************************************************/
991 static TREEVIEW_ITEM
*
992 TREEVIEW_AllocateItem(const TREEVIEW_INFO
*infoPtr
)
994 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
999 /* I_IMAGENONE would make more sense but this is neither what is
1000 * documented (MSDN doesn't specify) nor what Windows actually does
1001 * (it sets it to zero)... and I can so imagine an application using
1002 * inc/dec to toggle the images. */
1003 newItem
->iImage
= 0;
1004 newItem
->iSelectedImage
= 0;
1005 newItem
->iExpandedImage
= (WORD
)I_IMAGENONE
;
1006 newItem
->infoPtr
= infoPtr
;
1008 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
1017 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
1018 * free item->pszText. */
1020 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1022 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
1023 if (infoPtr
->selectedItem
== item
)
1024 infoPtr
->selectedItem
= NULL
;
1025 if (infoPtr
->hotItem
== item
)
1026 infoPtr
->hotItem
= NULL
;
1027 if (infoPtr
->focusedItem
== item
)
1028 infoPtr
->focusedItem
= NULL
;
1029 if (infoPtr
->firstVisible
== item
)
1030 infoPtr
->firstVisible
= NULL
;
1031 if (infoPtr
->dropItem
== item
)
1032 infoPtr
->dropItem
= NULL
;
1033 if (infoPtr
->insertMarkItem
== item
)
1034 infoPtr
->insertMarkItem
= NULL
;
1039 /* Item Insertion *******************************************************/
1041 /***************************************************************************
1042 * This method inserts newItem before sibling as a child of parent.
1043 * sibling can be NULL, but only if parent has no children.
1046 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1047 TREEVIEW_ITEM
*parent
)
1049 assert(parent
!= NULL
);
1051 if (sibling
!= NULL
)
1053 assert(sibling
->parent
== parent
);
1055 if (sibling
->prevSibling
!= NULL
)
1056 sibling
->prevSibling
->nextSibling
= newItem
;
1058 newItem
->prevSibling
= sibling
->prevSibling
;
1059 sibling
->prevSibling
= newItem
;
1062 newItem
->prevSibling
= NULL
;
1064 newItem
->nextSibling
= sibling
;
1066 if (parent
->firstChild
== sibling
)
1067 parent
->firstChild
= newItem
;
1069 if (parent
->lastChild
== NULL
)
1070 parent
->lastChild
= newItem
;
1073 /***************************************************************************
1074 * This method inserts newItem after sibling as a child of parent.
1075 * sibling can be NULL, but only if parent has no children.
1078 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1079 TREEVIEW_ITEM
*parent
)
1081 assert(parent
!= NULL
);
1083 if (sibling
!= NULL
)
1085 assert(sibling
->parent
== parent
);
1087 if (sibling
->nextSibling
!= NULL
)
1088 sibling
->nextSibling
->prevSibling
= newItem
;
1090 newItem
->nextSibling
= sibling
->nextSibling
;
1091 sibling
->nextSibling
= newItem
;
1094 newItem
->nextSibling
= NULL
;
1096 newItem
->prevSibling
= sibling
;
1098 if (parent
->lastChild
== sibling
)
1099 parent
->lastChild
= newItem
;
1101 if (parent
->firstChild
== NULL
)
1102 parent
->firstChild
= newItem
;
1106 TREEVIEW_DoSetItemT(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
1107 const TVITEMEXW
*tvItem
, BOOL isW
)
1109 UINT callbackClear
= 0;
1110 UINT callbackSet
= 0;
1112 TRACE("item %p\n", item
);
1113 /* Do this first in case it fails. */
1114 if (tvItem
->mask
& TVIF_TEXT
)
1116 item
->textWidth
= 0; /* force width recalculation */
1117 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKW
&& tvItem
->pszText
!= NULL
) /* covers != TEXTCALLBACKA too, and undocumented: pszText of NULL also means TEXTCALLBACK */
1122 len
= lstrlenW(tvItem
->pszText
) + 1;
1124 len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1, NULL
, 0);
1126 newText
= ReAlloc(item
->pszText
, len
* sizeof(WCHAR
));
1128 if (newText
== NULL
) return FALSE
;
1130 callbackClear
|= TVIF_TEXT
;
1132 item
->pszText
= newText
;
1133 item
->cchTextMax
= len
;
1135 lstrcpynW(item
->pszText
, tvItem
->pszText
, len
);
1137 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1,
1138 item
->pszText
, len
);
1140 TRACE("setting text %s, item %p\n", debugstr_w(item
->pszText
), item
);
1144 callbackSet
|= TVIF_TEXT
;
1146 item
->pszText
= ReAlloc(item
->pszText
,
1147 TEXT_CALLBACK_SIZE
* sizeof(WCHAR
));
1148 item
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1149 TRACE("setting callback, item %p\n", item
);
1153 if (tvItem
->mask
& TVIF_CHILDREN
)
1155 item
->cChildren
= tvItem
->cChildren
;
1157 if (item
->cChildren
== I_CHILDRENCALLBACK
)
1158 callbackSet
|= TVIF_CHILDREN
;
1160 callbackClear
|= TVIF_CHILDREN
;
1163 if (tvItem
->mask
& TVIF_IMAGE
)
1165 item
->iImage
= tvItem
->iImage
;
1167 if (item
->iImage
== I_IMAGECALLBACK
)
1168 callbackSet
|= TVIF_IMAGE
;
1170 callbackClear
|= TVIF_IMAGE
;
1173 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1175 item
->iSelectedImage
= tvItem
->iSelectedImage
;
1177 if (item
->iSelectedImage
== I_IMAGECALLBACK
)
1178 callbackSet
|= TVIF_SELECTEDIMAGE
;
1180 callbackClear
|= TVIF_SELECTEDIMAGE
;
1183 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
1185 item
->iExpandedImage
= tvItem
->iExpandedImage
;
1187 if (item
->iExpandedImage
== I_IMAGECALLBACK
)
1188 callbackSet
|= TVIF_EXPANDEDIMAGE
;
1190 callbackClear
|= TVIF_EXPANDEDIMAGE
;
1193 if (tvItem
->mask
& TVIF_PARAM
)
1194 item
->lParam
= tvItem
->lParam
;
1196 /* If the application sets TVIF_INTEGRAL without
1197 * supplying a TVITEMEX structure, it's toast. */
1198 if (tvItem
->mask
& TVIF_INTEGRAL
)
1199 item
->iIntegral
= tvItem
->iIntegral
;
1201 if (tvItem
->mask
& TVIF_STATE
)
1203 TRACE("prevstate,state,mask:%x,%x,%x\n", item
->state
, tvItem
->state
,
1205 item
->state
&= ~tvItem
->stateMask
;
1206 item
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1209 if (tvItem
->mask
& TVIF_STATEEX
)
1211 FIXME("New extended state: %x\n", tvItem
->uStateEx
);
1214 item
->callbackMask
|= callbackSet
;
1215 item
->callbackMask
&= ~callbackClear
;
1220 /* Note that the new item is pre-zeroed. */
1222 TREEVIEW_InsertItemT(TREEVIEW_INFO
*infoPtr
, const TVINSERTSTRUCTW
*ptdi
, BOOL isW
)
1224 const TVITEMEXW
*tvItem
= &ptdi
->u
.itemex
;
1225 HTREEITEM insertAfter
;
1226 TREEVIEW_ITEM
*newItem
, *parentItem
;
1227 BOOL bTextUpdated
= FALSE
;
1229 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1231 parentItem
= infoPtr
->root
;
1235 parentItem
= ptdi
->hParent
;
1237 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1239 WARN("invalid parent %p\n", parentItem
);
1244 insertAfter
= ptdi
->hInsertAfter
;
1246 /* Validate this now for convenience. */
1247 switch ((DWORD_PTR
)insertAfter
)
1249 case (DWORD_PTR
)TVI_FIRST
:
1250 case (DWORD_PTR
)TVI_LAST
:
1251 case (DWORD_PTR
)TVI_SORT
:
1255 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1256 insertAfter
->parent
!= parentItem
)
1258 WARN("invalid insert after %p\n", insertAfter
);
1259 insertAfter
= TVI_LAST
;
1263 TRACE("parent %p position %p: %s\n", parentItem
, insertAfter
,
1264 (tvItem
->mask
& TVIF_TEXT
)
1265 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKW
) ? "<callback>"
1266 : (isW
? debugstr_w(tvItem
->pszText
) : debugstr_a((LPSTR
)tvItem
->pszText
)))
1269 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1270 if (newItem
== NULL
)
1273 newItem
->parent
= parentItem
;
1274 newItem
->iIntegral
= 1;
1275 newItem
->visibleOrder
= -1;
1277 if (!TREEVIEW_DoSetItemT(infoPtr
, newItem
, tvItem
, isW
))
1280 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1282 infoPtr
->uNumItems
++;
1284 switch ((DWORD_PTR
)insertAfter
)
1286 case (DWORD_PTR
)TVI_FIRST
:
1288 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1289 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1290 if (infoPtr
->firstVisible
== originalFirst
)
1291 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1295 case (DWORD_PTR
)TVI_LAST
:
1296 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1299 /* hInsertAfter names a specific item we want to insert after */
1301 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1304 case (DWORD_PTR
)TVI_SORT
:
1306 TREEVIEW_ITEM
*aChild
;
1307 TREEVIEW_ITEM
*previousChild
= NULL
;
1308 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1309 BOOL bItemInserted
= FALSE
;
1311 aChild
= parentItem
->firstChild
;
1313 bTextUpdated
= TRUE
;
1314 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1316 /* Iterate the parent children to see where we fit in */
1317 while (aChild
!= NULL
)
1321 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1322 comp
= lstrcmpW(newItem
->pszText
, aChild
->pszText
);
1324 if (comp
< 0) /* we are smaller than the current one */
1326 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1327 if (infoPtr
->firstVisible
== originalFirst
&&
1328 aChild
== originalFirst
)
1329 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1330 bItemInserted
= TRUE
;
1333 else if (comp
> 0) /* we are bigger than the current one */
1335 previousChild
= aChild
;
1337 /* This will help us to exit if there is no more sibling */
1338 aChild
= (aChild
->nextSibling
== 0)
1340 : aChild
->nextSibling
;
1342 /* Look at the next item */
1348 * An item with this name is already existing, therefore,
1349 * we add after the one we found
1351 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1352 bItemInserted
= TRUE
;
1358 * we reach the end of the child list and the item has not
1359 * yet been inserted, therefore, insert it after the last child.
1361 if ((!bItemInserted
) && (aChild
== NULL
))
1362 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1369 TRACE("new item %p; parent %p, mask %x\n", newItem
,
1370 newItem
->parent
, tvItem
->mask
);
1372 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1374 if (newItem
->parent
->cChildren
== 0)
1375 newItem
->parent
->cChildren
= 1;
1377 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1379 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1380 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1383 if (infoPtr
->firstVisible
== NULL
)
1384 infoPtr
->firstVisible
= newItem
;
1386 TREEVIEW_VerifyTree(infoPtr
);
1388 if (!infoPtr
->bRedraw
) return (LRESULT
)newItem
;
1390 if (parentItem
== infoPtr
->root
||
1391 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1393 TREEVIEW_ITEM
*item
;
1394 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1396 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1397 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1400 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1402 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1403 TREEVIEW_UpdateScrollBars(infoPtr
);
1405 * if the item was inserted in a visible part of the tree,
1406 * invalidate it, as well as those after it
1408 for (item
= newItem
;
1410 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1411 TREEVIEW_Invalidate(infoPtr
, item
);
1415 /* refresh treeview if newItem is the first item inserted under parentItem */
1416 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1418 /* parent got '+' - update it */
1419 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1423 return (LRESULT
)newItem
;
1426 /* Item Deletion ************************************************************/
1428 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
1431 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*parentItem
)
1433 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1435 while (kill
!= NULL
)
1437 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1439 TREEVIEW_RemoveItem(infoPtr
, kill
);
1444 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1445 assert(parentItem
->firstChild
== NULL
);
1446 assert(parentItem
->lastChild
== NULL
);
1450 TREEVIEW_UnlinkItem(const TREEVIEW_ITEM
*item
)
1452 TREEVIEW_ITEM
*parentItem
= item
->parent
;
1454 assert(item
!= NULL
);
1455 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1457 if (parentItem
->firstChild
== item
)
1458 parentItem
->firstChild
= item
->nextSibling
;
1460 if (parentItem
->lastChild
== item
)
1461 parentItem
->lastChild
= item
->prevSibling
;
1463 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1464 && parentItem
->cChildren
> 0)
1465 parentItem
->cChildren
= 0;
1467 if (item
->prevSibling
)
1468 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1470 if (item
->nextSibling
)
1471 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1475 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1477 TRACE("%p, (%s)\n", item
, TREEVIEW_ItemName(item
));
1479 if (item
->firstChild
)
1480 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
1482 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1483 TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
1485 TREEVIEW_UnlinkItem(item
);
1487 infoPtr
->uNumItems
--;
1489 if (item
->pszText
!= LPSTR_TEXTCALLBACKW
)
1490 Free(item
->pszText
);
1492 TREEVIEW_FreeItem(infoPtr
, item
);
1496 /* Empty out the tree. */
1498 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1500 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1502 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1506 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
)
1508 TREEVIEW_ITEM
*newSelection
= NULL
;
1509 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1510 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1511 BOOL visible
= FALSE
;
1513 if (item
== TVI_ROOT
|| !item
)
1515 TRACE("TVI_ROOT\n");
1516 parent
= infoPtr
->root
;
1517 newSelection
= NULL
;
1519 TREEVIEW_RemoveTree(infoPtr
);
1523 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1526 TRACE("%p (%s)\n", item
, TREEVIEW_ItemName(item
));
1527 parent
= item
->parent
;
1529 if (ISVISIBLE(item
))
1531 prev
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
1535 if (infoPtr
->selectedItem
!= NULL
1536 && (item
== infoPtr
->selectedItem
1537 || TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
)))
1539 if (item
->nextSibling
)
1540 newSelection
= item
->nextSibling
;
1541 else if (item
->parent
!= infoPtr
->root
)
1542 newSelection
= item
->parent
;
1544 newSelection
= item
->prevSibling
;
1545 TRACE("newSelection = %p\n", newSelection
);
1548 if (infoPtr
->firstVisible
== item
)
1550 if (item
->nextSibling
)
1551 newFirstVisible
= item
->nextSibling
;
1552 else if (item
->prevSibling
)
1553 newFirstVisible
= item
->prevSibling
;
1554 else if (item
->parent
!= infoPtr
->root
)
1555 newFirstVisible
= item
->parent
;
1556 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1559 newFirstVisible
= infoPtr
->firstVisible
;
1561 TREEVIEW_RemoveItem(infoPtr
, item
);
1564 /* Don't change if somebody else already has (infoPtr->selectedItem is cleared by FreeItem). */
1565 if (!infoPtr
->selectedItem
&& newSelection
)
1567 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1568 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1571 /* Validate insertMark dropItem.
1572 * hotItem ??? - used for comparison only.
1574 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1575 infoPtr
->insertMarkItem
= 0;
1577 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1578 infoPtr
->dropItem
= 0;
1580 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1581 newFirstVisible
= infoPtr
->root
->firstChild
;
1583 TREEVIEW_VerifyTree(infoPtr
);
1585 if (!infoPtr
->bRedraw
) return TRUE
;
1589 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1590 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1591 TREEVIEW_UpdateScrollBars(infoPtr
);
1592 TREEVIEW_Invalidate(infoPtr
, NULL
);
1594 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1596 /* parent lost '+/-' - update it */
1597 TREEVIEW_Invalidate(infoPtr
, parent
);
1604 /* Get/Set Messages *********************************************************/
1606 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
)
1608 infoPtr
->bRedraw
= wParam
!= 0;
1610 if (infoPtr
->bRedraw
)
1612 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1613 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1614 TREEVIEW_UpdateScrollBars(infoPtr
);
1615 TREEVIEW_Invalidate(infoPtr
, NULL
);
1621 TREEVIEW_GetIndent(const TREEVIEW_INFO
*infoPtr
)
1624 return infoPtr
->uIndent
;
1628 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1632 if (newIndent
< MINIMUM_INDENT
)
1633 newIndent
= MINIMUM_INDENT
;
1635 if (infoPtr
->uIndent
!= newIndent
)
1637 infoPtr
->uIndent
= newIndent
;
1638 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1639 TREEVIEW_UpdateScrollBars(infoPtr
);
1640 TREEVIEW_Invalidate(infoPtr
, NULL
);
1648 TREEVIEW_GetToolTips(const TREEVIEW_INFO
*infoPtr
)
1651 return (LRESULT
)infoPtr
->hwndToolTip
;
1655 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1660 prevToolTip
= infoPtr
->hwndToolTip
;
1661 infoPtr
->hwndToolTip
= hwndTT
;
1663 return (LRESULT
)prevToolTip
;
1667 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO
*infoPtr
, BOOL fUnicode
)
1669 BOOL rc
= infoPtr
->bNtfUnicode
;
1670 infoPtr
->bNtfUnicode
= fUnicode
;
1675 TREEVIEW_GetUnicodeFormat(const TREEVIEW_INFO
*infoPtr
)
1677 return infoPtr
->bNtfUnicode
;
1681 TREEVIEW_GetScrollTime(const TREEVIEW_INFO
*infoPtr
)
1683 return infoPtr
->uScrollTime
;
1687 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1689 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1691 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1693 return uOldScrollTime
;
1698 TREEVIEW_GetImageList(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1705 return (LRESULT
)infoPtr
->himlNormal
;
1708 return (LRESULT
)infoPtr
->himlState
;
1715 #define TVHEIGHT_MIN 16
1716 #define TVHEIGHT_FONT_ADJUST 3 /* 2 for focus border + 1 for margin some apps assume */
1718 /* Compute the natural height for items. */
1720 TREEVIEW_NaturalHeight(const TREEVIEW_INFO
*infoPtr
)
1724 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1727 /* Height is the maximum of:
1728 * 16 (a hack because our fonts are tiny), and
1729 * The text height + border & margin, and
1730 * The size of the normal image list
1732 GetTextMetricsW(hdc
, &tm
);
1733 SelectObject(hdc
, hOldFont
);
1736 height
= TVHEIGHT_MIN
;
1737 if (height
< tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
)
1738 height
= tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
;
1739 if (height
< infoPtr
->normalImageHeight
)
1740 height
= infoPtr
->normalImageHeight
;
1742 /* Round down, unless we support odd ("non even") heights. */
1743 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1750 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, UINT type
, HIMAGELIST himlNew
)
1752 HIMAGELIST himlOld
= 0;
1753 int oldWidth
= infoPtr
->normalImageWidth
;
1754 int oldHeight
= infoPtr
->normalImageHeight
;
1756 TRACE("%u,%p\n", type
, himlNew
);
1761 himlOld
= infoPtr
->himlNormal
;
1762 infoPtr
->himlNormal
= himlNew
;
1765 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1766 &infoPtr
->normalImageHeight
);
1769 infoPtr
->normalImageWidth
= 0;
1770 infoPtr
->normalImageHeight
= 0;
1776 himlOld
= infoPtr
->himlState
;
1777 infoPtr
->himlState
= himlNew
;
1780 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1781 &infoPtr
->stateImageHeight
);
1784 infoPtr
->stateImageWidth
= 0;
1785 infoPtr
->stateImageHeight
= 0;
1791 ERR("unknown imagelist type %u\n", type
);
1794 if (oldWidth
!= infoPtr
->normalImageWidth
||
1795 oldHeight
!= infoPtr
->normalImageHeight
)
1797 BOOL bRecalcVisible
= FALSE
;
1799 if (oldHeight
!= infoPtr
->normalImageHeight
&&
1800 !infoPtr
->bHeightSet
)
1802 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1803 bRecalcVisible
= TRUE
;
1806 if (infoPtr
->normalImageWidth
> MINIMUM_INDENT
&&
1807 infoPtr
->normalImageWidth
!= infoPtr
->uIndent
)
1809 infoPtr
->uIndent
= infoPtr
->normalImageWidth
;
1810 bRecalcVisible
= TRUE
;
1814 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1816 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1817 TREEVIEW_UpdateScrollBars(infoPtr
);
1820 TREEVIEW_Invalidate(infoPtr
, NULL
);
1822 return (LRESULT
)himlOld
;
1826 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1828 INT prevHeight
= infoPtr
->uItemHeight
;
1830 TRACE("new=%d, old=%d\n", newHeight
, prevHeight
);
1831 if (newHeight
== -1)
1833 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1834 infoPtr
->bHeightSet
= FALSE
;
1838 if (newHeight
== 0) newHeight
= 1;
1839 infoPtr
->uItemHeight
= newHeight
;
1840 infoPtr
->bHeightSet
= TRUE
;
1843 /* Round down, unless we support odd ("non even") heights. */
1844 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
) && infoPtr
->uItemHeight
!= 1)
1846 infoPtr
->uItemHeight
&= ~1;
1847 TRACE("after rounding=%d\n", infoPtr
->uItemHeight
);
1850 if (infoPtr
->uItemHeight
!= prevHeight
)
1852 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1853 TREEVIEW_UpdateScrollBars(infoPtr
);
1854 TREEVIEW_Invalidate(infoPtr
, NULL
);
1861 TREEVIEW_GetItemHeight(const TREEVIEW_INFO
*infoPtr
)
1864 return infoPtr
->uItemHeight
;
1869 TREEVIEW_GetFont(const TREEVIEW_INFO
*infoPtr
)
1871 TRACE("%p\n", infoPtr
->hFont
);
1872 return (LRESULT
)infoPtr
->hFont
;
1877 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1881 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1887 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1889 UINT uHeight
= infoPtr
->uItemHeight
;
1891 TRACE("%p %i\n", hFont
, bRedraw
);
1893 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
1895 DeleteObject(infoPtr
->hBoldFont
);
1896 DeleteObject(infoPtr
->hUnderlineFont
);
1897 DeleteObject(infoPtr
->hBoldUnderlineFont
);
1898 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1899 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
1900 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
1902 if (!infoPtr
->bHeightSet
)
1903 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1905 if (uHeight
!= infoPtr
->uItemHeight
)
1906 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1908 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1910 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1911 TREEVIEW_UpdateScrollBars(infoPtr
);
1914 TREEVIEW_Invalidate(infoPtr
, NULL
);
1921 TREEVIEW_GetLineColor(const TREEVIEW_INFO
*infoPtr
)
1924 return (LRESULT
)infoPtr
->clrLine
;
1928 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1930 COLORREF prevColor
= infoPtr
->clrLine
;
1933 infoPtr
->clrLine
= color
;
1934 return (LRESULT
)prevColor
;
1939 TREEVIEW_GetTextColor(const TREEVIEW_INFO
*infoPtr
)
1942 return (LRESULT
)infoPtr
->clrText
;
1946 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1948 COLORREF prevColor
= infoPtr
->clrText
;
1951 infoPtr
->clrText
= color
;
1953 if (infoPtr
->clrText
!= prevColor
)
1954 TREEVIEW_Invalidate(infoPtr
, NULL
);
1956 return (LRESULT
)prevColor
;
1961 TREEVIEW_GetBkColor(const TREEVIEW_INFO
*infoPtr
)
1964 return (LRESULT
)infoPtr
->clrBk
;
1968 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1970 COLORREF prevColor
= infoPtr
->clrBk
;
1973 infoPtr
->clrBk
= newColor
;
1975 if (newColor
!= prevColor
)
1976 TREEVIEW_Invalidate(infoPtr
, NULL
);
1978 return (LRESULT
)prevColor
;
1983 TREEVIEW_GetInsertMarkColor(const TREEVIEW_INFO
*infoPtr
)
1986 return (LRESULT
)infoPtr
->clrInsertMark
;
1990 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1992 COLORREF prevColor
= infoPtr
->clrInsertMark
;
1994 TRACE("%x\n", color
);
1995 infoPtr
->clrInsertMark
= color
;
1997 return (LRESULT
)prevColor
;
2002 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
2004 TRACE("%d %p\n", wParam
, item
);
2006 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2009 infoPtr
->insertBeforeorAfter
= wParam
;
2010 infoPtr
->insertMarkItem
= item
;
2012 TREEVIEW_Invalidate(infoPtr
, NULL
);
2018 /************************************************************************
2019 * Some serious braindamage here. lParam is a pointer to both the
2020 * input HTREEITEM and the output RECT.
2023 TREEVIEW_GetItemRect(const TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
2025 TREEVIEW_ITEM
*item
;
2026 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
2034 if (!TREEVIEW_ValidItem(infoPtr
, item
) || !ISVISIBLE(item
))
2038 * If wParam is TRUE return the text size otherwise return
2039 * the whole item size
2043 /* Windows does not send TVN_GETDISPINFO here. */
2045 lpRect
->top
= item
->rect
.top
;
2046 lpRect
->bottom
= item
->rect
.bottom
;
2048 lpRect
->left
= item
->textOffset
;
2049 if (!item
->textWidth
)
2050 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2052 lpRect
->right
= item
->textOffset
+ item
->textWidth
+ 4;
2056 *lpRect
= item
->rect
;
2059 TRACE("%s [%s]\n", fTextRect
? "text" : "item", wine_dbgstr_rect(lpRect
));
2064 static inline LRESULT
2065 TREEVIEW_GetVisibleCount(const TREEVIEW_INFO
*infoPtr
)
2067 /* Surprise! This does not take integral height into account. */
2068 TRACE("client=%d, item=%d\n", infoPtr
->clientHeight
, infoPtr
->uItemHeight
);
2069 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2074 TREEVIEW_GetItemT(const TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2076 TREEVIEW_ITEM
*item
= tvItem
->hItem
;
2078 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2080 if (!item
) return FALSE
;
2082 TRACE("got item from different tree %p, called from %p\n", item
->infoPtr
, infoPtr
);
2083 infoPtr
= item
->infoPtr
;
2084 if (!TREEVIEW_ValidItem(infoPtr
, item
)) return FALSE
;
2087 TREEVIEW_UpdateDispInfo(infoPtr
, item
, tvItem
->mask
);
2089 if (tvItem
->mask
& TVIF_CHILDREN
)
2091 if (item
->cChildren
==I_CHILDRENCALLBACK
)
2092 FIXME("I_CHILDRENCALLBACK not supported\n");
2093 tvItem
->cChildren
= item
->cChildren
;
2096 if (tvItem
->mask
& TVIF_HANDLE
)
2097 tvItem
->hItem
= item
;
2099 if (tvItem
->mask
& TVIF_IMAGE
)
2100 tvItem
->iImage
= item
->iImage
;
2102 if (tvItem
->mask
& TVIF_INTEGRAL
)
2103 tvItem
->iIntegral
= item
->iIntegral
;
2105 /* undocumented: (mask & TVIF_PARAM) ignored and lParam is always set */
2106 tvItem
->lParam
= item
->lParam
;
2108 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2109 tvItem
->iSelectedImage
= item
->iSelectedImage
;
2111 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
2112 tvItem
->iExpandedImage
= item
->iExpandedImage
;
2114 /* undocumented: stateMask and (state & TVIF_STATE) ignored, so state is always set */
2115 tvItem
->state
= item
->state
;
2117 if (tvItem
->mask
& TVIF_TEXT
)
2119 if (item
->pszText
== NULL
)
2121 if (tvItem
->cchTextMax
> 0)
2122 tvItem
->pszText
[0] = '\0';
2126 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2128 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2129 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2133 lstrcpynW(tvItem
->pszText
, item
->pszText
, tvItem
->cchTextMax
);
2138 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2140 tvItem
->pszText
= (LPWSTR
)LPSTR_TEXTCALLBACKA
;
2141 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2145 WideCharToMultiByte(CP_ACP
, 0, item
->pszText
, -1,
2146 (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, NULL
, NULL
);
2151 if (tvItem
->mask
& TVIF_STATEEX
)
2153 FIXME("Extended item state not supported, returning 0.\n");
2154 tvItem
->uStateEx
= 0;
2157 TRACE("item <%p>, txt %p, img %d, mask %x\n",
2158 item
, tvItem
->pszText
, tvItem
->iImage
, tvItem
->mask
);
2163 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2164 * which is wrong. */
2166 TREEVIEW_SetItemT(TREEVIEW_INFO
*infoPtr
, const TVITEMEXW
*tvItem
, BOOL isW
)
2168 TREEVIEW_ITEM
*item
;
2169 TREEVIEW_ITEM originalItem
;
2171 item
= tvItem
->hItem
;
2173 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr
, item
),
2176 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2179 /* store the original item values */
2180 originalItem
= *item
;
2182 if (!TREEVIEW_DoSetItemT(infoPtr
, item
, tvItem
, isW
))
2185 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2186 if ((tvItem
->mask
& TVIF_TEXT
2187 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2190 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_TEXT
);
2191 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2194 if (tvItem
->mask
!= 0 && ISVISIBLE(item
))
2196 /* The refresh updates everything, but we can't wait until then. */
2197 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
2199 /* if any of the item's values changed and it's not a callback, redraw the item */
2200 if (item_changed(&originalItem
, item
, tvItem
))
2202 if (tvItem
->mask
& TVIF_INTEGRAL
)
2204 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
2205 TREEVIEW_UpdateScrollBars(infoPtr
);
2207 TREEVIEW_Invalidate(infoPtr
, NULL
);
2211 TREEVIEW_UpdateScrollBars(infoPtr
);
2212 TREEVIEW_Invalidate(infoPtr
, item
);
2221 TREEVIEW_GetItemState(const TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, UINT mask
)
2225 if (!item
|| !TREEVIEW_ValidItem(infoPtr
, item
))
2228 return (item
->state
& mask
);
2232 TREEVIEW_GetNextItem(const TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM item
)
2234 TREEVIEW_ITEM
*retval
;
2238 /* handle all the global data here */
2241 case TVGN_CHILD
: /* Special case: child of 0 is root */
2246 retval
= infoPtr
->root
->firstChild
;
2250 retval
= infoPtr
->selectedItem
;
2253 case TVGN_FIRSTVISIBLE
:
2254 retval
= infoPtr
->firstVisible
;
2257 case TVGN_DROPHILITE
:
2258 retval
= infoPtr
->dropItem
;
2261 case TVGN_LASTVISIBLE
:
2262 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2268 TRACE("flags:%x, returns %p\n", which
, retval
);
2269 return (LRESULT
)retval
;
2272 if (item
== TVI_ROOT
) item
= infoPtr
->root
;
2274 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2280 retval
= item
->nextSibling
;
2283 retval
= item
->prevSibling
;
2286 retval
= (item
->parent
!= infoPtr
->root
) ? item
->parent
: NULL
;
2289 retval
= item
->firstChild
;
2291 case TVGN_NEXTVISIBLE
:
2292 retval
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2294 case TVGN_PREVIOUSVISIBLE
:
2295 retval
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
2298 TRACE("Unknown msg %x,item %p\n", which
, item
);
2302 TRACE("flags:%x, item %p;returns %p\n", which
, item
, retval
);
2303 return (LRESULT
)retval
;
2308 TREEVIEW_GetCount(const TREEVIEW_INFO
*infoPtr
)
2310 TRACE(" %d\n", infoPtr
->uNumItems
);
2311 return (LRESULT
)infoPtr
->uNumItems
;
2315 TREEVIEW_ToggleItemState(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2317 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2319 static const unsigned int state_table
[] = { 0, 2, 1 };
2323 state
= STATEIMAGEINDEX(item
->state
);
2324 TRACE("state:%x\n", state
);
2325 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2328 state
= state_table
[state
];
2330 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2332 TRACE("state:%x\n", state
);
2333 TREEVIEW_Invalidate(infoPtr
, item
);
2338 /* Painting *************************************************************/
2340 /* Draw the lines and expand button for an item. Also draws one section
2341 * of the line from item's parent to item's parent's next sibling. */
2343 TREEVIEW_DrawItemLines(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const TREEVIEW_ITEM
*item
)
2345 LONG centerx
, centery
;
2346 BOOL lar
= ((infoPtr
->dwStyle
2347 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2350 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2352 if (!lar
&& item
->iLevel
== 0)
2355 hbr
= CreateSolidBrush(clrBk
);
2356 hbrOld
= SelectObject(hdc
, hbr
);
2358 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2359 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2361 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2363 HPEN hOldPen
, hNewPen
;
2367 /* Get a dotted grey pen */
2368 lb
.lbStyle
= BS_SOLID
;
2369 lb
.lbColor
= GETLINECOLOR(infoPtr
->clrLine
);
2370 hNewPen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, NULL
);
2371 hOldPen
= SelectObject(hdc
, hNewPen
);
2373 /* Make sure the center is on a dot (using +2 instead
2374 * of +1 gives us pixel-by-pixel compat with native) */
2375 centery
= (centery
+ 2) & ~1;
2377 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2378 LineTo(hdc
, centerx
- 1, centery
);
2380 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2382 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2383 LineTo(hdc
, centerx
, centery
);
2386 if (item
->nextSibling
)
2388 MoveToEx(hdc
, centerx
, centery
, NULL
);
2389 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2392 /* Draw the line from our parent to its next sibling. */
2393 parent
= item
->parent
;
2394 while (parent
!= infoPtr
->root
)
2396 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2398 if (parent
->nextSibling
2399 /* skip top-levels unless TVS_LINESATROOT */
2400 && parent
->stateOffset
> parent
->linesOffset
)
2402 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2403 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2406 parent
= parent
->parent
;
2409 SelectObject(hdc
, hOldPen
);
2410 DeleteObject(hNewPen
);
2414 * Display the (+/-) signs
2417 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2419 if (item
->cChildren
)
2421 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
2424 RECT glyphRect
= item
->rect
;
2425 glyphRect
.left
= item
->linesOffset
;
2426 glyphRect
.right
= item
->stateOffset
;
2427 DrawThemeBackground (theme
, hdc
, TVP_GLYPH
,
2428 (item
->state
& TVIS_EXPANDED
) ? GLPS_OPENED
: GLPS_CLOSED
,
2433 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2434 LONG width
= item
->stateOffset
- item
->linesOffset
;
2435 LONG rectsize
= min(height
, width
) / 4;
2436 /* plussize = ceil(rectsize * 3/4) */
2437 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2439 HPEN new_pen
= CreatePen(PS_SOLID
, 0, GETLINECOLOR(infoPtr
->clrLine
));
2440 HPEN old_pen
= SelectObject(hdc
, new_pen
);
2442 Rectangle(hdc
, centerx
- rectsize
- 1, centery
- rectsize
- 1,
2443 centerx
+ rectsize
+ 2, centery
+ rectsize
+ 2);
2445 SelectObject(hdc
, old_pen
);
2446 DeleteObject(new_pen
);
2448 /* draw +/- signs with current text color */
2449 new_pen
= CreatePen(PS_SOLID
, 0, GETTXTCOLOR(infoPtr
->clrText
));
2450 old_pen
= SelectObject(hdc
, new_pen
);
2452 if (height
< 18 || width
< 18)
2454 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2455 LineTo(hdc
, centerx
+ plussize
, centery
);
2457 if (!(item
->state
& TVIS_EXPANDED
) ||
2458 (item
->state
& TVIS_EXPANDPARTIAL
))
2460 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2461 LineTo(hdc
, centerx
, centery
+ plussize
);
2466 Rectangle(hdc
, centerx
- plussize
+ 1, centery
- 1,
2467 centerx
+ plussize
, centery
+ 2);
2469 if (!(item
->state
& TVIS_EXPANDED
) ||
2470 (item
->state
& TVIS_EXPANDPARTIAL
))
2472 Rectangle(hdc
, centerx
- 1, centery
- plussize
+ 1,
2473 centerx
+ 2, centery
+ plussize
);
2474 SetPixel(hdc
, centerx
- 1, centery
, clrBk
);
2475 SetPixel(hdc
, centerx
+ 1, centery
, clrBk
);
2479 SelectObject(hdc
, old_pen
);
2480 DeleteObject(new_pen
);
2484 SelectObject(hdc
, hbrOld
);
2489 TREEVIEW_DrawItem(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*item
)
2493 COLORREF oldTextColor
, oldTextBkColor
;
2495 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2496 NMTVCUSTOMDRAW nmcdhdr
;
2498 TREEVIEW_UpdateDispInfo(infoPtr
, item
, CALLBACK_MASK_ALL
);
2500 /* - If item is drop target or it is selected and window is in focus -
2501 * use blue background (COLOR_HIGHLIGHT).
2502 * - If item is selected, window is not in focus, but it has style
2503 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2504 * - Otherwise - use background color
2506 if ((item
->state
& TVIS_DROPHILITED
) || ((item
== infoPtr
->focusedItem
) && !(item
->state
& TVIS_SELECTED
)) ||
2507 ((item
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
|| item
== infoPtr
->focusedItem
) &&
2508 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2510 if ((item
->state
& TVIS_DROPHILITED
) || inFocus
)
2512 nmcdhdr
.clrTextBk
= comctl32_color
.clrHighlight
;
2513 nmcdhdr
.clrText
= comctl32_color
.clrHighlightText
;
2517 nmcdhdr
.clrTextBk
= comctl32_color
.clrBtnFace
;
2518 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2523 nmcdhdr
.clrTextBk
= GETBKCOLOR(infoPtr
->clrBk
);
2524 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
2525 nmcdhdr
.clrText
= comctl32_color
.clrHighlight
;
2527 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2530 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
2532 /* The custom draw handler can query the text rectangle,
2534 /* should already be known, set to 0 when changed */
2535 if (!item
->textWidth
)
2536 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2540 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2542 cditem
= TREEVIEW_SendCustomDrawItemNotify
2543 (infoPtr
, hdc
, item
, CDDS_ITEMPREPAINT
, &nmcdhdr
);
2544 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2546 if (cditem
& CDRF_SKIPDEFAULT
)
2548 SelectObject(hdc
, hOldFont
);
2553 if (cditem
& CDRF_NEWFONT
)
2554 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2556 TREEVIEW_DrawItemLines(infoPtr
, hdc
, item
);
2558 /* Set colors. Custom draw handler can change these so we do this after it. */
2559 oldTextColor
= SetTextColor(hdc
, nmcdhdr
.clrText
);
2560 oldTextBkColor
= SetBkColor(hdc
, nmcdhdr
.clrTextBk
);
2562 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2565 * Display the images associated with this item
2570 /* State images are displayed to the left of the Normal image
2571 * image number is in state; zero should be `display no image'.
2573 imageIndex
= STATEIMAGEINDEX(item
->state
);
2575 if (infoPtr
->himlState
&& imageIndex
)
2577 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2579 centery
- infoPtr
->stateImageHeight
/ 2,
2583 /* Now, draw the normal image; can be either selected,
2584 * non-selected or expanded image.
2587 if ((item
->state
& TVIS_SELECTED
) && (item
->iSelectedImage
>= 0))
2589 /* The item is currently selected */
2590 imageIndex
= item
->iSelectedImage
;
2592 else if ((item
->state
& TVIS_EXPANDED
) && (item
->iExpandedImage
!= (WORD
)I_IMAGENONE
))
2594 /* The item is currently not selected but expanded */
2595 imageIndex
= item
->iExpandedImage
;
2599 /* The item is not selected and not expanded */
2600 imageIndex
= item
->iImage
;
2603 if (infoPtr
->himlNormal
)
2605 UINT style
= item
->state
& TVIS_CUT
? ILD_SELECTED
: ILD_NORMAL
;
2607 style
|= item
->state
& TVIS_OVERLAYMASK
;
2609 ImageList_DrawEx(infoPtr
->himlNormal
, imageIndex
, hdc
,
2610 item
->imageOffset
, centery
- infoPtr
->normalImageHeight
/ 2,
2611 0, 0, infoPtr
->clrBk
, item
->state
& TVIS_CUT
? GETBKCOLOR(infoPtr
->clrBk
) : CLR_DEFAULT
,
2618 * Display the text associated with this item
2621 /* Don't paint item's text if it's being edited */
2622 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= item
))
2630 rcText
.top
= item
->rect
.top
;
2631 rcText
.bottom
= item
->rect
.bottom
;
2632 rcText
.left
= item
->textOffset
;
2633 rcText
.right
= rcText
.left
+ item
->textWidth
+ 4;
2635 TRACE("drawing text %s at (%s)\n",
2636 debugstr_w(item
->pszText
), wine_dbgstr_rect(&rcText
));
2639 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
2641 align
= SetTextAlign(hdc
, TA_LEFT
| TA_TOP
);
2642 ExtTextOutW(hdc
, rcText
.left
+ 2, (rcText
.top
+ rcText
.bottom
- sz
.cy
) / 2,
2643 ETO_CLIPPED
| ETO_OPAQUE
,
2646 lstrlenW(item
->pszText
),
2648 SetTextAlign(hdc
, align
);
2650 /* Draw focus box around the selected item */
2651 if ((item
== infoPtr
->selectedItem
) && inFocus
)
2653 DrawFocusRect(hdc
,&rcText
);
2658 /* Draw insertion mark if necessary */
2660 if (infoPtr
->insertMarkItem
)
2661 TRACE("item:%d,mark:%p\n",
2662 TREEVIEW_GetItemIndex(infoPtr
, item
),
2663 infoPtr
->insertMarkItem
);
2665 if (item
== infoPtr
->insertMarkItem
)
2667 HPEN hNewPen
, hOldPen
;
2671 hNewPen
= CreatePen(PS_SOLID
, 2, GETINSCOLOR(infoPtr
->clrInsertMark
));
2672 hOldPen
= SelectObject(hdc
, hNewPen
);
2674 if (infoPtr
->insertBeforeorAfter
)
2675 offset
= item
->rect
.bottom
- 1;
2677 offset
= item
->rect
.top
+ 1;
2679 left
= item
->textOffset
- 2;
2680 right
= item
->textOffset
+ item
->textWidth
+ 2;
2682 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2683 LineTo(hdc
, left
, offset
+ 4);
2685 MoveToEx(hdc
, left
, offset
, NULL
);
2686 LineTo(hdc
, right
+ 1, offset
);
2688 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2689 LineTo(hdc
, right
, offset
- 4);
2691 SelectObject(hdc
, hOldPen
);
2692 DeleteObject(hNewPen
);
2695 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2697 cditem
= TREEVIEW_SendCustomDrawItemNotify
2698 (infoPtr
, hdc
, item
, CDDS_ITEMPOSTPAINT
, &nmcdhdr
);
2699 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2702 /* Restore the hdc state */
2703 SetTextColor(hdc
, oldTextColor
);
2704 SetBkColor(hdc
, oldTextBkColor
);
2705 SelectObject(hdc
, hOldFont
);
2708 /* Computes treeHeight and treeWidth and updates the scroll bars.
2711 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2713 TREEVIEW_ITEM
*item
;
2714 HWND hwnd
= infoPtr
->hwnd
;
2718 LONG scrollX
= infoPtr
->scrollX
;
2720 infoPtr
->treeWidth
= 0;
2721 infoPtr
->treeHeight
= 0;
2723 /* We iterate through all visible items in order to get the tree height
2725 item
= infoPtr
->root
->firstChild
;
2727 while (item
!= NULL
)
2729 if (ISVISIBLE(item
))
2731 /* actually we draw text at textOffset + 2 */
2732 if (2+item
->textOffset
+item
->textWidth
> infoPtr
->treeWidth
)
2733 infoPtr
->treeWidth
= item
->textOffset
+item
->textWidth
+2;
2735 /* This is scroll-adjusted, but we fix this below. */
2736 infoPtr
->treeHeight
= item
->rect
.bottom
;
2739 item
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2742 /* Fix the scroll adjusted treeHeight and treeWidth. */
2743 if (infoPtr
->root
->firstChild
)
2744 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2746 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2748 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2750 /* Adding one scroll bar may take up enough space that it forces us
2751 * to add the other as well. */
2752 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2756 if (infoPtr
->treeWidth
2757 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2760 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
|| infoPtr
->scrollX
> 0)
2763 if (!vert
&& horz
&& infoPtr
->treeHeight
2764 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2767 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2769 si
.cbSize
= sizeof(SCROLLINFO
);
2770 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2775 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2776 if ( si
.nPage
&& NULL
!= infoPtr
->firstVisible
)
2778 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2779 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2781 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2783 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2784 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2785 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2789 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2790 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2791 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2796 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2797 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2798 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2803 si
.nPage
= infoPtr
->clientWidth
;
2804 si
.nPos
= infoPtr
->scrollX
;
2805 si
.nMax
= infoPtr
->treeWidth
- 1;
2807 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2809 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2813 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2814 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2815 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2817 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2818 TREEVIEW_HScroll(infoPtr
,
2819 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2823 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2824 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2825 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2828 if (infoPtr
->scrollX
!= 0)
2830 TREEVIEW_HScroll(infoPtr
,
2831 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2836 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2840 TREEVIEW_FillBkgnd(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2843 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2845 hBrush
= CreateSolidBrush(clrBk
);
2846 FillRect(hdc
, rc
, hBrush
);
2847 DeleteObject(hBrush
);
2850 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2852 TREEVIEW_EraseBackground(const TREEVIEW_INFO
*infoPtr
, HDC hdc
)
2856 TRACE("%p\n", infoPtr
);
2858 GetClientRect(infoPtr
->hwnd
, &rect
);
2859 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rect
);
2865 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2867 HWND hwnd
= infoPtr
->hwnd
;
2869 TREEVIEW_ITEM
*item
;
2871 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2873 TRACE("empty window\n");
2877 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2880 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2882 ReleaseDC(hwnd
, hdc
);
2886 for (item
= infoPtr
->root
->firstChild
;
2888 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
2890 if (ISVISIBLE(item
))
2892 /* Avoid unneeded calculations */
2893 if (item
->rect
.top
> rect
.bottom
)
2895 if (item
->rect
.bottom
< rect
.top
)
2898 TREEVIEW_DrawItem(infoPtr
, hdc
, item
);
2903 // This is correct, but is causes and infinite loop of WM_PAINT messages, resulting
2904 // in continuous painting of the scroll bar in reactos. Comment out until the real
2907 //TREEVIEW_UpdateScrollBars(infoPtr);
2909 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2911 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2915 TREEVIEW_InvalidateItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2917 if (item
) InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2921 TREEVIEW_Invalidate(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2924 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2926 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2930 TREEVIEW_InitCheckboxes(TREEVIEW_INFO
*infoPtr
)
2933 HBITMAP hbm
, hbmOld
;
2937 infoPtr
->himlState
= ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
2939 hdcScreen
= GetDC(0);
2941 hdc
= CreateCompatibleDC(hdcScreen
);
2942 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
2943 hbmOld
= SelectObject(hdc
, hbm
);
2945 SetRect(&rc
, 0, 0, 48, 16);
2946 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
2948 SetRect(&rc
, 18, 2, 30, 14);
2949 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2950 DFCS_BUTTONCHECK
|DFCS_FLAT
);
2952 SetRect(&rc
, 34, 2, 46, 14);
2953 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2954 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
2956 SelectObject(hdc
, hbmOld
);
2957 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
2958 comctl32_color
.clrWindow
);
2959 TRACE("checkbox index %d\n", nIndex
);
2963 ReleaseDC(0, hdcScreen
);
2965 infoPtr
->stateImageWidth
= 16;
2966 infoPtr
->stateImageHeight
= 16;
2970 TREEVIEW_ResetImageStateIndex(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2972 TREEVIEW_ITEM
*child
= item
->firstChild
;
2974 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2975 item
->state
|= INDEXTOSTATEIMAGEMASK(1);
2979 TREEVIEW_ITEM
*next
= child
->nextSibling
;
2980 TREEVIEW_ResetImageStateIndex(infoPtr
, child
);
2986 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, HDC hdc_ref
)
2992 TRACE("(%p %p)\n", infoPtr
, hdc_ref
);
2994 if ((infoPtr
->dwStyle
& TVS_CHECKBOXES
) && !infoPtr
->himlState
)
2996 TREEVIEW_InitCheckboxes(infoPtr
);
2997 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
2999 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
3000 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
3001 TREEVIEW_UpdateScrollBars(infoPtr
);
3002 TREEVIEW_Invalidate(infoPtr
, NULL
);
3008 GetClientRect(infoPtr
->hwnd
, &rc
);
3009 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
3013 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
3016 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
3019 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
3020 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
3023 EndPaint(infoPtr
->hwnd
, &ps
);
3029 TREEVIEW_PrintClient(TREEVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
3031 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
3033 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwnd
))
3036 if (options
& PRF_ERASEBKGND
)
3037 TREEVIEW_EraseBackground(infoPtr
, hdc
);
3039 if (options
& PRF_CLIENT
)
3042 GetClientRect(infoPtr
->hwnd
, &rc
);
3043 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
3049 /* Sorting **************************************************************/
3051 /***************************************************************************
3052 * Forward the DPA local callback to the treeview owner callback
3055 TREEVIEW_CallBackCompare(const TREEVIEW_ITEM
*first
, const TREEVIEW_ITEM
*second
,
3056 const TVSORTCB
*pCallBackSort
)
3058 /* Forward the call to the client-defined callback */
3059 return pCallBackSort
->lpfnCompare(first
->lParam
,
3061 pCallBackSort
->lParam
);
3064 /***************************************************************************
3065 * Treeview native sort routine: sort on item text.
3068 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
3069 const TREEVIEW_INFO
*infoPtr
)
3071 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
3072 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
3074 if(first
->pszText
&& second
->pszText
)
3075 return lstrcmpiW(first
->pszText
, second
->pszText
);
3076 else if(first
->pszText
)
3078 else if(second
->pszText
)
3084 /* Returns the number of physical children belonging to item. */
3086 TREEVIEW_CountChildren(const TREEVIEW_ITEM
*item
)
3091 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
3097 /* Returns a DPA containing a pointer to each physical child of item in
3098 * sibling order. If item has no children, an empty DPA is returned. */
3100 TREEVIEW_BuildChildDPA(const TREEVIEW_ITEM
*item
)
3104 HDPA list
= DPA_Create(8);
3105 if (list
== 0) return NULL
;
3107 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
3109 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
3119 /***************************************************************************
3120 * Setup the treeview structure with regards of the sort method
3121 * and sort the children of the TV item specified in lParam
3122 * fRecurse: currently unused. Should be zero.
3123 * parent: if pSort!=NULL, should equal pSort->hParent.
3124 * otherwise, item which child items are to be sorted.
3125 * pSort: sort method info. if NULL, sort on item text.
3126 * if non-NULL, sort on item's lParam content, and let the
3127 * application decide what that means. See also TVM_SORTCHILDRENCB.
3131 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, HTREEITEM parent
,
3135 PFNDPACOMPARE pfnCompare
;
3138 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
3139 if (parent
== TVI_ROOT
|| parent
== NULL
)
3140 parent
= infoPtr
->root
;
3142 /* Check for a valid handle to the parent item */
3143 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
3145 ERR("invalid item hParent=%p\n", parent
);
3151 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
3152 lpCompare
= (LPARAM
)pSort
;
3156 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
3157 lpCompare
= (LPARAM
)infoPtr
;
3160 cChildren
= TREEVIEW_CountChildren(parent
);
3162 /* Make sure there is something to sort */
3165 /* TREEVIEW_ITEM rechaining */
3168 HTREEITEM nextItem
= 0;
3169 HTREEITEM prevItem
= 0;
3171 HDPA sortList
= TREEVIEW_BuildChildDPA(parent
);
3173 if (sortList
== NULL
)
3176 /* let DPA sort the list */
3177 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
3179 /* The order of DPA entries has been changed, so fixup the
3180 * nextSibling and prevSibling pointers. */
3182 item
= DPA_GetPtr(sortList
, count
++);
3183 while ((nextItem
= DPA_GetPtr(sortList
, count
++)) != NULL
)
3185 /* link the two current item together */
3186 item
->nextSibling
= nextItem
;
3187 nextItem
->prevSibling
= item
;
3189 if (prevItem
== NULL
)
3191 /* this is the first item, update the parent */
3192 parent
->firstChild
= item
;
3193 item
->prevSibling
= NULL
;
3197 /* fix the back chaining */
3198 item
->prevSibling
= prevItem
;
3201 /* get ready for the next one */
3206 /* the last item is pointed to by item and never has a sibling */
3207 item
->nextSibling
= NULL
;
3208 parent
->lastChild
= item
;
3210 DPA_Destroy(sortList
);
3212 TREEVIEW_VerifyTree(infoPtr
);
3214 if (parent
->state
& TVIS_EXPANDED
)
3216 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3218 if (parent
== infoPtr
->root
)
3219 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3221 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3223 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3225 TREEVIEW_ITEM
*item
;
3227 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3228 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3230 if (item
->visibleOrder
== visOrder
)
3234 if (!item
) item
= parent
->firstChild
;
3235 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3238 TREEVIEW_Invalidate(infoPtr
, NULL
);
3247 /***************************************************************************
3248 * Setup the treeview structure with regards of the sort method
3249 * and sort the children of the TV item specified in lParam
3252 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, LPTVSORTCB pSort
)
3254 return TREEVIEW_Sort(infoPtr
, pSort
->hParent
, pSort
);
3258 /***************************************************************************
3259 * Sort the children of the TV item specified in lParam.
3262 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3264 return TREEVIEW_Sort(infoPtr
, (HTREEITEM
)lParam
, NULL
);
3268 /* Expansion/Collapse ***************************************************/
3271 TREEVIEW_SendExpanding(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3274 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3275 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3276 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3281 TREEVIEW_SendExpanded(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3284 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3285 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3286 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3291 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3292 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3294 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3295 BOOL bRemoveChildren
, BOOL bUser
)
3297 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3298 BOOL bSetSelection
, bSetFirstVisible
;
3300 LONG scrollDist
= 0;
3301 TREEVIEW_ITEM
*nextItem
= NULL
, *tmpItem
;
3304 TRACE("TVE_COLLAPSE %p %s\n", item
, TREEVIEW_ItemName(item
));
3306 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3310 TREEVIEW_SendExpanding(infoPtr
, item
, action
);
3312 if (item
->firstChild
== NULL
)
3315 wasExpanded
= (item
->state
& TVIS_EXPANDED
) != 0;
3316 item
->state
&= ~TVIS_EXPANDED
;
3318 if (wasExpanded
&& bUser
)
3319 TREEVIEW_SendExpanded(infoPtr
, item
, action
);
3321 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3322 && TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
));
3324 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3325 && TREEVIEW_IsChildOf(item
, infoPtr
->firstVisible
));
3330 if (tmpItem
->nextSibling
)
3332 nextItem
= tmpItem
->nextSibling
;
3335 tmpItem
= tmpItem
->parent
;
3339 scrollDist
= nextItem
->rect
.top
;
3341 if (bRemoveChildren
)
3343 INT old_cChildren
= item
->cChildren
;
3344 TRACE("TVE_COLLAPSERESET\n");
3345 item
->state
&= ~TVIS_EXPANDEDONCE
;
3346 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
3347 item
->cChildren
= old_cChildren
;
3352 if (item
->firstChild
)
3354 TREEVIEW_ITEM
*i
, *sibling
;
3356 sibling
= TREEVIEW_GetNextListItem(infoPtr
, item
);
3358 for (i
= item
->firstChild
; i
!= sibling
;
3359 i
= TREEVIEW_GetNextListItem(infoPtr
, i
))
3361 i
->visibleOrder
= -1;
3365 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3368 scrollDist
= -(scrollDist
- nextItem
->rect
.top
);
3372 /* Don't call DoSelectItem, it sends notifications. */
3373 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3374 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3375 item
->state
|= TVIS_SELECTED
;
3376 infoPtr
->selectedItem
= item
;
3379 TREEVIEW_UpdateScrollBars(infoPtr
);
3381 scrollRect
.left
= 0;
3382 scrollRect
.right
= infoPtr
->clientWidth
;
3383 scrollRect
.bottom
= infoPtr
->clientHeight
;
3387 scrollRect
.top
= nextItem
->rect
.top
;
3389 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, &scrollRect
,
3390 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3391 TREEVIEW_Invalidate(infoPtr
, item
);
3393 scrollRect
.top
= item
->rect
.top
;
3394 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, TRUE
);
3397 TREEVIEW_SetFirstVisible(infoPtr
,
3398 bSetFirstVisible
? item
: infoPtr
->firstVisible
,
3405 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3406 BOOL partial
, BOOL user
)
3409 LONG orgNextTop
= 0;
3411 TREEVIEW_ITEM
*nextItem
, *tmpItem
;
3412 BOOL sendsNotifications
;
3414 TRACE("(%p, %p, partial=%d, %d)\n", infoPtr
, item
, partial
, user
);
3416 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3419 tmpItem
= item
; nextItem
= NULL
;
3422 if (tmpItem
->nextSibling
)
3424 nextItem
= tmpItem
->nextSibling
;
3427 tmpItem
= tmpItem
->parent
;
3431 orgNextTop
= nextItem
->rect
.top
;
3433 TRACE("TVE_EXPAND %p %s\n", item
, TREEVIEW_ItemName(item
));
3435 sendsNotifications
= user
|| ((item
->cChildren
!= 0) &&
3436 !(item
->state
& TVIS_EXPANDEDONCE
));
3437 if (sendsNotifications
)
3439 if (!TREEVIEW_SendExpanding(infoPtr
, item
, TVE_EXPAND
))
3441 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3445 if (!item
->firstChild
)
3448 item
->state
|= TVIS_EXPANDED
;
3451 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3453 if (ISVISIBLE(item
))
3455 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3456 TREEVIEW_UpdateSubTree(infoPtr
, item
);
3457 TREEVIEW_UpdateScrollBars(infoPtr
);
3459 scrollRect
.left
= 0;
3460 scrollRect
.bottom
= infoPtr
->treeHeight
;
3461 scrollRect
.right
= infoPtr
->clientWidth
;
3464 scrollDist
= nextItem
->rect
.top
- orgNextTop
;
3465 scrollRect
.top
= orgNextTop
;
3467 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3468 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3469 TREEVIEW_Invalidate (infoPtr
, item
);
3471 scrollRect
.top
= item
->rect
.top
;
3472 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, FALSE
);
3475 /* Scroll up so that as many children as possible are visible.
3476 * This fails when expanding causes an HScroll bar to appear, but we
3477 * don't know that yet, so the last item is obscured. */
3478 if (item
->firstChild
!= NULL
)
3480 int nChildren
= item
->lastChild
->visibleOrder
3481 - item
->firstChild
->visibleOrder
+ 1;
3483 int visible_pos
= item
->visibleOrder
3484 - infoPtr
->firstVisible
->visibleOrder
;
3486 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3488 if (visible_pos
> 0 && nChildren
> rows_below
)
3490 int scroll
= nChildren
- rows_below
;
3492 if (scroll
> visible_pos
)
3493 scroll
= visible_pos
;
3497 TREEVIEW_ITEM
*newFirstVisible
3498 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3502 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3508 if (sendsNotifications
) {
3509 TREEVIEW_SendExpanded(infoPtr
, item
, TVE_EXPAND
);
3510 item
->state
|= TVIS_EXPANDEDONCE
;
3516 /* Handler for TVS_SINGLEEXPAND behaviour. Used on response
3517 to mouse messages and TVM_SELECTITEM.
3519 selection - previously selected item, used to collapse a part of a tree
3520 item - new selected item
3522 static void TREEVIEW_SingleExpand(TREEVIEW_INFO
*infoPtr
,
3523 HTREEITEM selection
, HTREEITEM item
)
3525 TREEVIEW_ITEM
*SelItem
;
3527 if ((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) == 0 || infoPtr
->hwndEdit
|| !item
) return;
3529 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
3532 * Close the previous selection all the way to the root
3533 * as long as the new selection is not a child
3535 if(selection
&& (selection
!= item
))
3537 BOOL closeit
= TRUE
;
3540 /* determine if the hitItem is a child of the currently selected item */
3541 while(closeit
&& SelItem
&& TREEVIEW_ValidItem(infoPtr
, SelItem
) &&
3542 (SelItem
->parent
!= infoPtr
->root
))
3544 closeit
= (SelItem
!= selection
);
3545 SelItem
= SelItem
->parent
;
3550 if(TREEVIEW_ValidItem(infoPtr
, selection
))
3551 SelItem
= selection
;
3553 while(SelItem
&& (SelItem
!= item
) && TREEVIEW_ValidItem(infoPtr
, SelItem
) &&
3554 SelItem
->parent
!= infoPtr
->root
)
3556 TREEVIEW_Collapse(infoPtr
, SelItem
, FALSE
, FALSE
);
3557 SelItem
= SelItem
->parent
;
3563 * Expand the current item
3565 TREEVIEW_Expand(infoPtr
, item
, FALSE
, FALSE
);
3569 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, BOOL user
)
3571 TRACE("item=%p, user=%d\n", item
, user
);
3573 if (item
->state
& TVIS_EXPANDED
)
3574 return TREEVIEW_Collapse(infoPtr
, item
, FALSE
, user
);
3576 return TREEVIEW_Expand(infoPtr
, item
, FALSE
, user
);
3580 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3582 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3584 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3586 if (TREEVIEW_HasChildren(infoPtr
, item
))
3587 TREEVIEW_ExpandAll(infoPtr
, item
);
3591 /* Note:If the specified item is the child of a collapsed parent item,
3592 the parent's list of child items is (recursively) expanded to reveal the
3593 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3594 know if it also applies here.
3598 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM item
)
3600 if (!TREEVIEW_ValidItem(infoPtr
, item
))
3603 TRACE("For (%s) item:%d, flags 0x%x, state:%d\n",
3604 TREEVIEW_ItemName(item
), TREEVIEW_GetItemIndex(infoPtr
, item
),
3607 switch (flag
& TVE_TOGGLE
)
3610 return TREEVIEW_Collapse(infoPtr
, item
, flag
& TVE_COLLAPSERESET
,
3614 return TREEVIEW_Expand(infoPtr
, item
, flag
& TVE_EXPANDPARTIAL
,
3618 return TREEVIEW_Toggle(infoPtr
, item
, FALSE
);
3625 /* Hit-Testing **********************************************************/
3627 static TREEVIEW_ITEM
*
3628 TREEVIEW_HitTestPoint(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3630 TREEVIEW_ITEM
*item
;
3633 if (!infoPtr
->firstVisible
)
3636 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3638 for (item
= infoPtr
->firstVisible
; item
!= NULL
;
3639 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3641 if (row
>= item
->visibleOrder
3642 && row
< item
->visibleOrder
+ item
->iIntegral
)
3650 TREEVIEW_HitTest(const TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3652 TREEVIEW_ITEM
*item
;
3658 GetClientRect(infoPtr
->hwnd
, &rect
);
3665 status
|= TVHT_TOLEFT
;
3667 else if (x
> rect
.right
)
3669 status
|= TVHT_TORIGHT
;
3674 status
|= TVHT_ABOVE
;
3676 else if (y
> rect
.bottom
)
3678 status
|= TVHT_BELOW
;
3683 lpht
->flags
= status
;
3687 item
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3690 lpht
->flags
= TVHT_NOWHERE
;
3694 if (x
>= item
->textOffset
+ item
->textWidth
)
3696 lpht
->flags
= TVHT_ONITEMRIGHT
;
3698 else if (x
>= item
->textOffset
)
3700 lpht
->flags
= TVHT_ONITEMLABEL
;
3702 else if (x
>= item
->imageOffset
)
3704 lpht
->flags
= TVHT_ONITEMICON
;
3706 else if (x
>= item
->stateOffset
)
3708 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3710 else if (x
>= item
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3712 lpht
->flags
= TVHT_ONITEMBUTTON
;
3716 lpht
->flags
= TVHT_ONITEMINDENT
;
3720 TRACE("(%d,%d):result %x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3722 return (LRESULT
)item
;
3725 /* Item Label Editing ***************************************************/
3728 TREEVIEW_GetEditControl(const TREEVIEW_INFO
*infoPtr
)
3730 return (LRESULT
)infoPtr
->hwndEdit
;
3733 static LRESULT CALLBACK
3734 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3736 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3737 BOOL bCancel
= FALSE
;
3743 TRACE("WM_PAINT start\n");
3744 rc
= CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3746 TRACE("WM_PAINT done\n");
3750 if (infoPtr
->bIgnoreEditKillFocus
)
3756 WNDPROC editProc
= infoPtr
->wpEditOrig
;
3757 infoPtr
->wpEditOrig
= 0;
3758 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
3759 return CallWindowProcW(editProc
, hwnd
, uMsg
, wParam
, lParam
);
3763 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3766 if (wParam
== VK_ESCAPE
)
3771 else if (wParam
== VK_RETURN
)
3778 return CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3781 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3782 /* eg. Using a messagebox */
3784 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3785 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3786 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3792 /* should handle edit control messages here */
3795 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3797 TRACE("code=%x, id=%x, handle=%lx\n", HIWORD(wParam
), LOWORD(wParam
), lParam
);
3799 switch (HIWORD(wParam
))
3804 * Adjust the edit window size
3807 TREEVIEW_ITEM
*editItem
= infoPtr
->editItem
;
3808 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3810 HFONT hFont
, hOldFont
= 0;
3812 TRACE("edit=%p\n", infoPtr
->hwndEdit
);
3814 if (!IsWindow(infoPtr
->hwndEdit
) || !hdc
) return FALSE
;
3816 infoPtr
->bLabelChanged
= TRUE
;
3818 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
3820 /* Select font to get the right dimension of the string */
3821 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3825 hOldFont
= SelectObject(hdc
, hFont
);
3828 if (GetTextExtentPoint32W(hdc
, buffer
, strlenW(buffer
), &sz
))
3830 TEXTMETRICW textMetric
;
3832 /* Add Extra spacing for the next character */
3833 GetTextMetricsW(hdc
, &textMetric
);
3834 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3836 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3838 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3840 SetWindowPos(infoPtr
->hwndEdit
,
3845 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3846 SWP_NOMOVE
| SWP_DRAWFRAME
);
3851 SelectObject(hdc
, hOldFont
);
3854 ReleaseDC(infoPtr
->hwnd
, hdc
);
3858 /* apparently we should respect passed handle value */
3859 if (infoPtr
->hwndEdit
!= (HWND
)lParam
) return FALSE
;
3861 TREEVIEW_EndEditLabelNow(infoPtr
, FALSE
);
3865 return SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3872 TREEVIEW_EditLabel(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3874 HWND hwnd
= infoPtr
->hwnd
;
3877 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
);
3880 TEXTMETRICW textMetric
;
3882 TRACE("%p %p\n", hwnd
, hItem
);
3883 if (!(infoPtr
->dwStyle
& TVS_EDITLABELS
))
3886 if (!TREEVIEW_ValidItem(infoPtr
, hItem
))
3889 if (infoPtr
->hwndEdit
)
3890 return infoPtr
->hwndEdit
;
3892 infoPtr
->bLabelChanged
= FALSE
;
3894 /* make edit item visible */
3895 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3897 TREEVIEW_UpdateDispInfo(infoPtr
, hItem
, TVIF_TEXT
);
3900 /* Select the font to get appropriate metric dimensions */
3901 if (infoPtr
->hFont
!= 0)
3903 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3906 /* Get string length in pixels */
3908 GetTextExtentPoint32W(hdc
, hItem
->pszText
, strlenW(hItem
->pszText
),
3911 GetTextExtentPoint32A(hdc
, "", 0, &sz
);
3913 /* Add Extra spacing for the next character */
3914 GetTextMetricsW(hdc
, &textMetric
);
3915 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3917 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3918 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- hItem
->textOffset
+ 2);
3920 if (infoPtr
->hFont
!= 0)
3922 SelectObject(hdc
, hOldFont
);
3925 ReleaseDC(hwnd
, hdc
);
3927 infoPtr
->editItem
= hItem
;
3929 hwndEdit
= CreateWindowExW(WS_EX_LEFT
,
3932 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3933 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3934 ES_LEFT
, hItem
->textOffset
- 2,
3935 hItem
->rect
.top
- 1, sz
.cx
+ 3,
3936 hItem
->rect
.bottom
-
3937 hItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3938 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3940 infoPtr
->hwndEdit
= hwndEdit
;
3942 /* Get a 2D border. */
3943 SetWindowLongW(hwndEdit
, GWL_EXSTYLE
,
3944 GetWindowLongW(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3945 SetWindowLongW(hwndEdit
, GWL_STYLE
,
3946 GetWindowLongW(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3948 SendMessageW(hwndEdit
, WM_SETFONT
,
3949 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, hItem
), FALSE
);
3951 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
,
3953 TREEVIEW_Edit_SubclassProc
);
3955 SetWindowTextW(hwndEdit
, hItem
->pszText
);
3957 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, hItem
))
3959 DestroyWindow(hwndEdit
);
3960 infoPtr
->hwndEdit
= 0;
3961 infoPtr
->editItem
= NULL
;
3966 SendMessageW(hwndEdit
, EM_SETSEL
, 0, -1);
3967 ShowWindow(hwndEdit
, SW_SHOW
);
3974 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3976 HWND hwnd
= infoPtr
->hwnd
;
3977 TREEVIEW_ITEM
*editedItem
= infoPtr
->editItem
;
3980 WCHAR tmpText
[1024] = { '\0' };
3981 WCHAR
*newText
= tmpText
;
3984 if (!IsWindow(infoPtr
->hwndEdit
)) return FALSE
;
3986 tvdi
.hdr
.hwndFrom
= hwnd
;
3987 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
3988 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_ENDLABELEDITW
);
3990 tvdi
.item
.hItem
= editedItem
;
3991 tvdi
.item
.state
= editedItem
->state
;
3992 tvdi
.item
.lParam
= editedItem
->lParam
;
3996 if (!infoPtr
->bNtfUnicode
)
3997 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, (LPSTR
)tmpText
, 1023);
3999 iLength
= GetWindowTextW(infoPtr
->hwndEdit
, tmpText
, 1023);
4001 if (iLength
>= 1023)
4003 ERR("Insufficient space to retrieve new item label\n");
4006 tvdi
.item
.mask
= TVIF_TEXT
;
4007 tvdi
.item
.pszText
= tmpText
;
4008 tvdi
.item
.cchTextMax
= iLength
+ 1;
4012 tvdi
.item
.pszText
= NULL
;
4013 tvdi
.item
.cchTextMax
= 0;
4016 bCommit
= TREEVIEW_SendRealNotify(infoPtr
, tvdi
.hdr
.idFrom
, &tvdi
.hdr
);
4018 if (!bCancel
&& bCommit
) /* Apply the changes */
4020 if (!infoPtr
->bNtfUnicode
)
4022 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, NULL
, 0 );
4023 newText
= Alloc(len
* sizeof(WCHAR
));
4024 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, newText
, len
);
4028 if (strcmpW(newText
, editedItem
->pszText
) != 0)
4030 WCHAR
*ptr
= ReAlloc(editedItem
->pszText
, sizeof(WCHAR
)*(iLength
+ 1));
4033 ERR("OutOfMemory, cannot allocate space for label\n");
4034 if(newText
!= tmpText
) Free(newText
);
4035 DestroyWindow(infoPtr
->hwndEdit
);
4036 infoPtr
->hwndEdit
= 0;
4037 infoPtr
->editItem
= NULL
;
4042 editedItem
->pszText
= ptr
;
4043 editedItem
->cchTextMax
= iLength
+ 1;
4044 strcpyW(editedItem
->pszText
, newText
);
4045 TREEVIEW_ComputeTextWidth(infoPtr
, editedItem
, 0);
4048 if(newText
!= tmpText
) Free(newText
);
4051 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
4052 DestroyWindow(infoPtr
->hwndEdit
);
4053 infoPtr
->hwndEdit
= 0;
4054 infoPtr
->editItem
= NULL
;
4059 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4061 if (wParam
!= TV_EDIT_TIMER
)
4063 ERR("got unknown timer\n");
4067 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4068 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
4070 TREEVIEW_EditLabel(infoPtr
, infoPtr
->selectedItem
);
4076 /* Mouse Tracking/Drag **************************************************/
4078 /***************************************************************************
4079 * This is quite unusual piece of code, but that's how it's implemented in
4083 TREEVIEW_TrackMouse(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
4085 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
4086 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
4090 r
.top
= pt
.y
- cyDrag
;
4091 r
.left
= pt
.x
- cxDrag
;
4092 r
.bottom
= pt
.y
+ cyDrag
;
4093 r
.right
= pt
.x
+ cxDrag
;
4095 SetCapture(infoPtr
->hwnd
);
4099 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
4101 if (msg
.message
== WM_MOUSEMOVE
)
4103 pt
.x
= (short)LOWORD(msg
.lParam
);
4104 pt
.y
= (short)HIWORD(msg
.lParam
);
4105 if (PtInRect(&r
, pt
))
4113 else if (msg
.message
>= WM_LBUTTONDOWN
&&
4114 msg
.message
<= WM_RBUTTONDBLCLK
)
4119 DispatchMessageW(&msg
);
4122 if (GetCapture() != infoPtr
->hwnd
)
4132 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4134 TREEVIEW_ITEM
*item
;
4138 SetFocus(infoPtr
->hwnd
);
4140 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4142 /* If there is pending 'edit label' event - kill it now */
4143 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4146 hit
.pt
.x
= (short)LOWORD(lParam
);
4147 hit
.pt
.y
= (short)HIWORD(lParam
);
4149 item
= (TREEVIEW_ITEM
*)TREEVIEW_HitTest(infoPtr
, &hit
);
4152 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, item
));
4154 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
4158 case TVHT_ONITEMRIGHT
:
4159 /* FIXME: we should not have sent NM_DBLCLK in this case. */
4162 case TVHT_ONITEMINDENT
:
4163 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
4169 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
4170 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
4172 while (item
->iLevel
> level
)
4174 item
= item
->parent
;
4180 case TVHT_ONITEMLABEL
:
4181 case TVHT_ONITEMICON
:
4182 case TVHT_ONITEMBUTTON
:
4183 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4186 case TVHT_ONITEMSTATEICON
:
4187 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4188 TREEVIEW_ToggleItemState(infoPtr
, item
);
4190 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4199 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4201 HWND hwnd
= infoPtr
->hwnd
;
4203 BOOL bTrack
, bDoLabelEdit
;
4205 /* If Edit control is active - kill it and return.
4206 * The best way to do it is to set focus to itself.
4207 * Edit control subclassed procedure will automatically call
4210 if (infoPtr
->hwndEdit
)
4216 ht
.pt
.x
= (short)LOWORD(lParam
);
4217 ht
.pt
.y
= (short)HIWORD(lParam
);
4219 TREEVIEW_HitTest(infoPtr
, &ht
);
4220 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
4222 /* update focusedItem and redraw both items */
4223 if(ht
.hItem
&& (ht
.flags
& TVHT_ONITEM
))
4225 infoPtr
->focusedItem
= ht
.hItem
;
4226 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4227 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4230 bTrack
= (ht
.flags
& TVHT_ONITEM
)
4231 && !(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
);
4234 * If the style allows editing and the node is already selected
4235 * and the click occurred on the item label...
4237 bDoLabelEdit
= (infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
4238 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
);
4240 /* Send NM_CLICK right away */
4242 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4245 if (ht
.flags
& TVHT_ONITEMBUTTON
)
4247 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
4251 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
4252 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4254 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
4255 infoPtr
->dropItem
= ht
.hItem
;
4257 /* clean up focusedItem as we dragged and won't select this item */
4258 if(infoPtr
->focusedItem
)
4260 /* refresh the item that was focused */
4261 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4262 infoPtr
->focusedItem
= NULL
;
4264 /* refresh the selected item to return the filled background */
4265 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4272 if (bTrack
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4277 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4278 KillTimer(hwnd
, TV_EDIT_TIMER
);
4280 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
4281 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
4283 else if (ht
.flags
& (TVHT_ONITEMICON
|TVHT_ONITEMLABEL
)) /* select the item if the hit was inside of the icon or text */
4285 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4287 /* Select the current item */
4288 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4289 TREEVIEW_SingleExpand(infoPtr
, selection
, ht
.hItem
);
4291 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4293 /* TVS_CHECKBOXES requires us to toggle the current state */
4294 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4295 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4305 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4309 if (infoPtr
->hwndEdit
)
4311 SetFocus(infoPtr
->hwnd
);
4315 ht
.pt
.x
= (short)LOWORD(lParam
);
4316 ht
.pt
.y
= (short)HIWORD(lParam
);
4318 TREEVIEW_HitTest(infoPtr
, &ht
);
4320 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4324 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4325 infoPtr
->dropItem
= ht
.hItem
;
4330 SetFocus(infoPtr
->hwnd
);
4331 if(!TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
))
4333 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
4334 SendMessageW(infoPtr
->hwndNotify
, WM_CONTEXTMENU
,
4335 (WPARAM
)infoPtr
->hwnd
, (LPARAM
)GetMessagePos());
4343 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4345 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4349 HBITMAP hbmp
, hOldbmp
;
4356 if (!(infoPtr
->himlNormal
))
4359 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4362 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4364 hwtop
= GetDesktopWindow();
4365 htopdc
= GetDC(hwtop
);
4366 hdc
= CreateCompatibleDC(htopdc
);
4368 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4370 if (dragItem
->pszText
)
4371 GetTextExtentPoint32W(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
),
4374 GetTextExtentPoint32A(hdc
, "", 0, &size
);
4376 TRACE("%d %d %s\n", size
.cx
, size
.cy
, debugstr_w(dragItem
->pszText
));
4377 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4378 hOldbmp
= SelectObject(hdc
, hbmp
);
4380 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4385 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4386 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4390 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4391 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4394 /* draw item text */
4396 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4398 if (dragItem
->pszText
)
4399 DrawTextW(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
), &rc
,
4402 SelectObject(hdc
, hOldFont
);
4403 SelectObject(hdc
, hOldbmp
);
4405 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4409 ReleaseDC(hwtop
, htopdc
);
4411 return (LRESULT
)infoPtr
->dragList
;
4414 /* Selection ************************************************************/
4417 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4420 TREEVIEW_ITEM
*prevSelect
;
4422 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4424 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4425 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4426 newSelect
? newSelect
->state
: 0);
4428 /* reset and redraw focusedItem if focusedItem was set so we don't */
4429 /* have to worry about the previously focused item when we set a new one */
4430 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4431 infoPtr
->focusedItem
= NULL
;
4435 case TVGN_CARET
|TVSI_NOSINGLEEXPAND
:
4436 FIXME("TVSI_NOSINGLEEXPAND specified.\n");
4439 prevSelect
= infoPtr
->selectedItem
;
4441 if (prevSelect
== newSelect
) {
4442 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4446 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4449 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4455 prevSelect
->state
&= ~TVIS_SELECTED
;
4457 newSelect
->state
|= TVIS_SELECTED
;
4459 infoPtr
->selectedItem
= newSelect
;
4461 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4463 TREEVIEW_InvalidateItem(infoPtr
, prevSelect
);
4464 TREEVIEW_InvalidateItem(infoPtr
, newSelect
);
4466 TREEVIEW_SendTreeviewNotify(infoPtr
,
4469 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4474 case TVGN_DROPHILITE
:
4475 prevSelect
= infoPtr
->dropItem
;
4478 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4480 infoPtr
->dropItem
= newSelect
;
4483 newSelect
->state
|= TVIS_DROPHILITED
;
4485 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4486 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4489 case TVGN_FIRSTVISIBLE
:
4490 if (newSelect
!= NULL
)
4492 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4493 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4494 TREEVIEW_Invalidate(infoPtr
, NULL
);
4499 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4503 /* FIXME: handle NM_KILLFOCUS etc */
4505 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4507 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4509 if (item
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4512 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4514 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4517 TREEVIEW_SingleExpand(infoPtr
, selection
, item
);
4522 /*************************************************************************
4523 * TREEVIEW_ProcessLetterKeys
4525 * Processes keyboard messages generated by pressing the letter keys
4527 * What this does is perform a case insensitive search from the
4528 * current position with the following quirks:
4529 * - If two chars or more are pressed in quick succession we search
4530 * for the corresponding string (e.g. 'abc').
4531 * - If there is a delay we wipe away the current search string and
4532 * restart with just that char.
4533 * - If the user keeps pressing the same character, whether slowly or
4534 * fast, so that the search string is entirely composed of this
4535 * character ('aaaaa' for instance), then we search for first item
4536 * that starting with that character.
4537 * - If the user types the above character in quick succession, then
4538 * we must also search for the corresponding string ('aaaaa'), and
4539 * go to that string if there is a match.
4547 * - The current implementation has a list of characters it will
4548 * accept and it ignores everything else. In particular it will
4549 * ignore accentuated characters which seems to match what
4550 * Windows does. But I'm not sure it makes sense to follow
4552 * - We don't sound a beep when the search fails.
4553 * - The search should start from the focused item, not from the selected
4554 * item. One reason for this is to allow for multiple selections in trees.
4555 * But currently infoPtr->focusedItem does not seem very usable.
4559 * TREEVIEW_ProcessLetterKeys
4561 static INT
TREEVIEW_ProcessLetterKeys(TREEVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
4564 HTREEITEM endidx
,idx
;
4566 WCHAR buffer
[MAX_PATH
];
4567 DWORD timestamp
,elapsed
;
4569 /* simple parameter checking */
4570 if (!charCode
|| !keyData
) return 0;
4572 /* only allow the valid WM_CHARs through */
4573 if (!isalnum(charCode
) &&
4574 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4575 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4576 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4577 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4578 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4579 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4580 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4581 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4582 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4585 /* compute how much time elapsed since last keypress */
4586 timestamp
= GetTickCount();
4587 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4588 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4590 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4593 /* update the search parameters */
4594 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4595 if (elapsed
< KEY_DELAY
) {
4596 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
) / sizeof(WCHAR
)) {
4597 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4599 if (infoPtr
->charCode
!= charCode
) {
4600 infoPtr
->charCode
=charCode
=0;
4603 infoPtr
->charCode
=charCode
;
4604 infoPtr
->szSearchParam
[0]=charCode
;
4605 infoPtr
->nSearchParamLength
=1;
4606 /* Redundant with the 1 char string */
4610 /* and search from the current position */
4612 if (infoPtr
->selectedItem
!= NULL
) {
4613 endidx
=infoPtr
->selectedItem
;
4614 /* if looking for single character match,
4615 * then we must always move forward
4617 if (infoPtr
->nSearchParamLength
== 1)
4618 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4623 idx
=infoPtr
->root
->firstChild
;
4626 /* At the end point, sort out wrapping */
4629 /* If endidx is null, stop at the last item (ie top to bottom) */
4633 /* Otherwise, start again at the very beginning */
4634 idx
=infoPtr
->root
->firstChild
;
4636 /* But if we are stopping on the first child, end now! */
4637 if (idx
== endidx
) break;
4641 ZeroMemory(&item
, sizeof(item
));
4642 item
.mask
= TVIF_TEXT
;
4644 item
.pszText
= buffer
;
4645 item
.cchTextMax
= sizeof(buffer
);
4646 TREEVIEW_GetItemT( infoPtr
, &item
, TRUE
);
4648 /* check for a match */
4649 if (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4652 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4653 (nItem
!= infoPtr
->selectedItem
) &&
4654 (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4655 /* This would work but we must keep looking for a longer match */
4658 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4659 } while (idx
!= endidx
);
4661 if (nItem
!= NULL
) {
4662 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4663 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4670 /* Scrolling ************************************************************/
4673 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4676 BOOL hasFirstVisible
= infoPtr
->firstVisible
!= NULL
;
4677 HTREEITEM newFirstVisible
= NULL
;
4678 int visible_pos
= -1;
4680 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4683 if (!ISVISIBLE(item
))
4685 /* Expand parents as necessary. */
4688 /* see if we are trying to ensure that root is visible */
4689 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4690 parent
= item
->parent
;
4692 parent
= item
; /* this item is the topmost item */
4694 while (parent
!= infoPtr
->root
)
4696 if (!(parent
->state
& TVIS_EXPANDED
))
4697 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, FALSE
);
4699 parent
= parent
->parent
;
4703 viscount
= TREEVIEW_GetVisibleCount(infoPtr
);
4705 TRACE("%p (%s) %d - %d viscount(%d)\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4706 hasFirstVisible
? infoPtr
->firstVisible
->visibleOrder
: -1, viscount
);
4708 if (hasFirstVisible
)
4709 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4711 if (visible_pos
< 0)
4713 /* item is before the start of the list: put it at the top. */
4714 newFirstVisible
= item
;
4716 else if (visible_pos
>= viscount
4717 /* Sometimes, before we are displayed, GVC is 0, causing us to
4718 * spuriously scroll up. */
4719 && visible_pos
> 0 && !(infoPtr
->dwStyle
& TVS_NOSCROLL
) )
4721 /* item is past the end of the list. */
4722 int scroll
= visible_pos
- viscount
;
4724 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4730 /* Scroll window so item's text is visible as much as possible */
4731 /* Calculation of amount of extra space is taken from EditLabel code */
4733 TEXTMETRICW textMetric
;
4734 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4736 x
= item
->textWidth
;
4738 GetTextMetricsW(hdc
, &textMetric
);
4739 ReleaseDC(infoPtr
->hwnd
, hdc
);
4741 x
+= (textMetric
.tmMaxCharWidth
* 2);
4742 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4744 if (item
->textOffset
< 0)
4745 pos
= item
->textOffset
;
4746 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4748 if (x
> infoPtr
->clientWidth
)
4749 pos
= item
->textOffset
;
4751 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4756 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4759 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4761 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4770 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4771 TREEVIEW_ITEM
*newFirstVisible
,
4772 BOOL bUpdateScrollPos
)
4776 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4778 if (newFirstVisible
!= NULL
)
4780 /* Prevent an empty gap from appearing at the bottom... */
4781 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4782 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4786 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4789 /* ... unless we just don't have enough items. */
4790 if (newFirstVisible
== NULL
)
4791 newFirstVisible
= infoPtr
->root
->firstChild
;
4795 if (infoPtr
->firstVisible
!= newFirstVisible
)
4797 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4799 infoPtr
->firstVisible
= newFirstVisible
;
4800 TREEVIEW_Invalidate(infoPtr
, NULL
);
4804 TREEVIEW_ITEM
*item
;
4805 int scroll
= infoPtr
->uItemHeight
*
4806 (infoPtr
->firstVisible
->visibleOrder
4807 - newFirstVisible
->visibleOrder
);
4809 infoPtr
->firstVisible
= newFirstVisible
;
4811 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4812 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4814 item
->rect
.top
+= scroll
;
4815 item
->rect
.bottom
+= scroll
;
4818 if (bUpdateScrollPos
)
4819 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4820 newFirstVisible
->visibleOrder
, TRUE
);
4822 ScrollWindowEx(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
, NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
4827 /************************************************************************
4828 * VScroll is always in units of visible items. i.e. we always have a
4829 * visible item aligned to the top of the control. (Unless we have no
4833 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4835 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4836 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4838 int nScrollCode
= LOWORD(wParam
);
4840 TRACE("wp %lx\n", wParam
);
4842 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4845 if (!oldFirstVisible
)
4847 assert(infoPtr
->root
->firstChild
== NULL
);
4851 switch (nScrollCode
)
4854 newFirstVisible
= infoPtr
->root
->firstChild
;
4858 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4862 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4866 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4870 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4871 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4875 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4876 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4880 case SB_THUMBPOSITION
:
4881 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4882 infoPtr
->root
->firstChild
,
4883 (LONG
)(SHORT
)HIWORD(wParam
));
4890 if (newFirstVisible
!= NULL
)
4892 if (newFirstVisible
!= oldFirstVisible
)
4893 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4894 nScrollCode
!= SB_THUMBTRACK
);
4895 else if (nScrollCode
== SB_THUMBPOSITION
)
4896 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4897 newFirstVisible
->visibleOrder
, TRUE
);
4904 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4907 int scrollX
= infoPtr
->scrollX
;
4908 int nScrollCode
= LOWORD(wParam
);
4910 TRACE("wp %lx\n", wParam
);
4912 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4915 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4916 /* shall never occur */
4923 switch (nScrollCode
)
4926 scrollX
-= infoPtr
->uItemHeight
;
4929 scrollX
+= infoPtr
->uItemHeight
;
4932 scrollX
-= infoPtr
->clientWidth
;
4935 scrollX
+= infoPtr
->clientWidth
;
4939 case SB_THUMBPOSITION
:
4940 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4947 if (scrollX
> maxWidth
)
4949 else if (scrollX
< 0)
4953 if (scrollX
!= infoPtr
->scrollX
)
4955 TREEVIEW_ITEM
*item
;
4956 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4958 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4959 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4961 item
->linesOffset
+= scroll_pixels
;
4962 item
->stateOffset
+= scroll_pixels
;
4963 item
->imageOffset
+= scroll_pixels
;
4964 item
->textOffset
+= scroll_pixels
;
4967 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4968 infoPtr
->scrollX
= scrollX
;
4969 UpdateWindow(infoPtr
->hwnd
);
4972 if (nScrollCode
!= SB_THUMBTRACK
)
4973 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
4979 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4982 UINT pulScrollLines
= 3;
4984 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4985 return DefWindowProcW(infoPtr
->hwnd
, WM_MOUSEWHEEL
, wParam
, lParam
);
4987 if (infoPtr
->firstVisible
== NULL
)
4990 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
4992 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4993 /* if scrolling changes direction, ignore left overs */
4994 if ((wheelDelta
< 0 && infoPtr
->wheelRemainder
< 0) ||
4995 (wheelDelta
> 0 && infoPtr
->wheelRemainder
> 0))
4996 infoPtr
->wheelRemainder
+= wheelDelta
;
4998 infoPtr
->wheelRemainder
= wheelDelta
;
5000 if (infoPtr
->wheelRemainder
&& pulScrollLines
)
5006 lineScroll
= pulScrollLines
* (float)infoPtr
->wheelRemainder
/ WHEEL_DELTA
;
5007 infoPtr
->wheelRemainder
-= WHEEL_DELTA
* lineScroll
/ (int)pulScrollLines
;
5009 newDy
= infoPtr
->firstVisible
->visibleOrder
- lineScroll
;
5010 maxDy
= infoPtr
->maxVisibleOrder
;
5018 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
5023 /* Create/Destroy *******************************************************/
5026 TREEVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5029 TREEVIEW_INFO
*infoPtr
;
5032 TRACE("wnd %p, style %x\n", hwnd
, GetWindowLongW(hwnd
, GWL_STYLE
));
5034 infoPtr
= Alloc(sizeof(TREEVIEW_INFO
));
5036 if (infoPtr
== NULL
)
5038 ERR("could not allocate info memory!\n");
5042 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
5044 infoPtr
->hwnd
= hwnd
;
5045 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5047 infoPtr
->uNumItems
= 0;
5048 infoPtr
->cdmode
= 0;
5049 infoPtr
->uScrollTime
= 300; /* milliseconds */
5050 infoPtr
->bRedraw
= TRUE
;
5052 GetClientRect(hwnd
, &rcClient
);
5054 /* No scroll bars yet. */
5055 infoPtr
->clientWidth
= rcClient
.right
;
5056 infoPtr
->clientHeight
= rcClient
.bottom
;
5057 infoPtr
->uInternalStatus
= 0;
5059 infoPtr
->treeWidth
= 0;
5060 infoPtr
->treeHeight
= 0;
5062 infoPtr
->uIndent
= MINIMUM_INDENT
;
5063 infoPtr
->selectedItem
= NULL
;
5064 infoPtr
->focusedItem
= NULL
;
5065 infoPtr
->hotItem
= NULL
;
5066 infoPtr
->editItem
= NULL
;
5067 infoPtr
->firstVisible
= NULL
;
5068 infoPtr
->maxVisibleOrder
= 0;
5069 infoPtr
->dropItem
= NULL
;
5070 infoPtr
->insertMarkItem
= NULL
;
5071 infoPtr
->insertBeforeorAfter
= 0;
5074 infoPtr
->scrollX
= 0;
5075 infoPtr
->wheelRemainder
= 0;
5077 infoPtr
->clrBk
= CLR_NONE
; /* use system color */
5078 infoPtr
->clrText
= CLR_NONE
; /* use system color */
5079 infoPtr
->clrLine
= CLR_DEFAULT
;
5080 infoPtr
->clrInsertMark
= CLR_DEFAULT
;
5084 infoPtr
->hwndEdit
= NULL
;
5085 infoPtr
->wpEditOrig
= NULL
;
5086 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
5087 infoPtr
->bLabelChanged
= FALSE
;
5089 infoPtr
->himlNormal
= NULL
;
5090 infoPtr
->himlState
= NULL
;
5091 infoPtr
->normalImageWidth
= 0;
5092 infoPtr
->normalImageHeight
= 0;
5093 infoPtr
->stateImageWidth
= 0;
5094 infoPtr
->stateImageHeight
= 0;
5096 infoPtr
->items
= DPA_Create(16);
5098 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
5099 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW(&lf
);
5100 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
5101 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
5102 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
5103 infoPtr
->hcurHand
= LoadCursorW(NULL
, (LPWSTR
)IDC_HAND
);
5105 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
5107 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
5108 infoPtr
->root
->state
= TVIS_EXPANDED
;
5109 infoPtr
->root
->iLevel
= -1;
5110 infoPtr
->root
->visibleOrder
= -1;
5112 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5113 infoPtr
->hwndToolTip
= 0;
5115 /* Determine what type of notify should be issued (sets infoPtr->bNtfUnicode) */
5116 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
5118 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
5119 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
5120 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
5123 /* Make sure actual scrollbar state is consistent with uInternalStatus */
5124 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
5125 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
5127 OpenThemeData (hwnd
, themeClass
);
5134 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
5138 /* free item data */
5139 TREEVIEW_RemoveTree(infoPtr
);
5140 /* root isn't freed with other items */
5141 TREEVIEW_FreeItem(infoPtr
, infoPtr
->root
);
5142 DPA_Destroy(infoPtr
->items
);
5144 /* tool tip is automatically destroyed: we are its owner */
5146 /* Restore original wndproc */
5147 if (infoPtr
->hwndEdit
)
5148 SetWindowLongPtrW(infoPtr
->hwndEdit
, GWLP_WNDPROC
,
5149 (DWORD_PTR
)infoPtr
->wpEditOrig
);
5151 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
5153 /* Deassociate treeview from the window before doing anything drastic. */
5154 SetWindowLongPtrW(infoPtr
->hwnd
, 0, 0);
5156 DeleteObject(infoPtr
->hDefaultFont
);
5157 DeleteObject(infoPtr
->hBoldFont
);
5158 DeleteObject(infoPtr
->hUnderlineFont
);
5159 DeleteObject(infoPtr
->hBoldUnderlineFont
);
5165 /* Miscellaneous Messages ***********************************************/
5168 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
5176 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
5177 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
5178 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
5179 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
5180 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
5181 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
5182 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
5183 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
5184 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
5188 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
5190 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
5192 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
5194 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
5200 /************************************************************************
5203 * VK_UP Move selection to the previous non-hidden item.
5204 * VK_DOWN Move selection to the next non-hidden item.
5205 * VK_HOME Move selection to the first item.
5206 * VK_END Move selection to the last item.
5207 * VK_LEFT If expanded then collapse, otherwise move to parent.
5208 * VK_RIGHT If collapsed then expand, otherwise move to first child.
5210 * VK_SUBTRACT Collapse.
5211 * VK_MULTIPLY Expand all.
5212 * VK_PRIOR Move up GetVisibleCount items.
5213 * VK_NEXT Move down GetVisibleCount items.
5214 * VK_BACK Move to parent.
5215 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
5218 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
5220 /* If it is non-NULL and different, it will be selected and visible. */
5221 TREEVIEW_ITEM
*newSelection
= NULL
;
5223 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
5225 TRACE("%lx\n", wParam
);
5227 if (prevItem
== NULL
)
5230 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
5231 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
5236 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
5238 newSelection
= infoPtr
->root
->firstChild
;
5242 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
5246 TREEVIEW_SendSimpleNotify(infoPtr
, NM_RETURN
);
5250 newSelection
= infoPtr
->root
->firstChild
;
5254 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
5258 if (prevItem
->state
& TVIS_EXPANDED
)
5260 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5262 else if (prevItem
->parent
!= infoPtr
->root
)
5264 newSelection
= prevItem
->parent
;
5269 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
5271 if (!(prevItem
->state
& TVIS_EXPANDED
))
5272 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5275 newSelection
= prevItem
->firstChild
;
5282 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5286 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5290 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5295 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5296 -TREEVIEW_GetVisibleCount(infoPtr
));
5301 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5302 TREEVIEW_GetVisibleCount(infoPtr
));
5306 newSelection
= prevItem
->parent
;
5307 if (newSelection
== infoPtr
->root
)
5308 newSelection
= NULL
;
5312 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5313 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5317 if (newSelection
&& newSelection
!= prevItem
)
5319 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5322 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5330 TREEVIEW_MouseLeave (TREEVIEW_INFO
* infoPtr
)
5332 /* remove hot effect from item */
5333 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5334 infoPtr
->hotItem
= NULL
;
5340 TREEVIEW_MouseMove (TREEVIEW_INFO
* infoPtr
, LPARAM lParam
)
5343 TRACKMOUSEEVENT trackinfo
;
5344 TREEVIEW_ITEM
* item
;
5346 if (!(infoPtr
->dwStyle
& TVS_TRACKSELECT
)) return 0;
5348 /* fill in the TRACKMOUSEEVENT struct */
5349 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5350 trackinfo
.dwFlags
= TME_QUERY
;
5351 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5353 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5354 _TrackMouseEvent(&trackinfo
);
5356 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5357 if(!(trackinfo
.dwFlags
& TME_LEAVE
))
5359 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5360 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5361 /* do it as fast as possible, minimal systimer latency will be used */
5362 trackinfo
.dwHoverTime
= 1;
5364 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5365 /* and can properly deactivate the hot item */
5366 _TrackMouseEvent(&trackinfo
);
5369 pt
.x
= (short)LOWORD(lParam
);
5370 pt
.y
= (short)HIWORD(lParam
);
5372 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5374 if (item
!= infoPtr
->hotItem
)
5376 /* redraw old hot item */
5377 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5378 infoPtr
->hotItem
= item
;
5379 /* redraw new hot item */
5380 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5386 /* Draw themed border */
5387 static BOOL
TREEVIEW_NCPaint (const TREEVIEW_INFO
*infoPtr
, HRGN region
, LPARAM lParam
)
5389 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5393 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
5394 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
5397 return DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)region
, lParam
);
5399 GetWindowRect(infoPtr
->hwnd
, &r
);
5401 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
5402 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
5403 if (region
!= (HRGN
)1)
5404 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
5405 OffsetRect(&r
, -r
.left
, -r
.top
);
5407 dc
= GetDCEx(infoPtr
->hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
5408 OffsetRect(&r
, -r
.left
, -r
.top
);
5410 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
5411 DrawThemeParentBackground(infoPtr
->hwnd
, dc
, &r
);
5412 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
5413 ReleaseDC(infoPtr
->hwnd
, dc
);
5415 /* Call default proc to get the scrollbars etc. painted */
5416 DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
5422 TREEVIEW_Notify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5424 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5426 if (lpnmh
->code
== PGN_CALCSIZE
) {
5427 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5429 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5430 lppgc
->iWidth
= infoPtr
->treeWidth
;
5431 TRACE("got PGN_CALCSIZE, returning horz size = %d, client=%d\n",
5432 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5435 lppgc
->iHeight
= infoPtr
->treeHeight
;
5436 TRACE("got PGN_CALCSIZE, returning vert size = %d, client=%d\n",
5437 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5441 return DefWindowProcW(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5445 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5447 if (wParam
== SIZE_RESTORED
)
5449 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5450 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5452 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5453 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5454 TREEVIEW_UpdateScrollBars(infoPtr
);
5458 FIXME("WM_SIZE flag %lx %lx not handled\n", wParam
, lParam
);
5461 TREEVIEW_Invalidate(infoPtr
, NULL
);
5466 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5468 TRACE("(%lx %lx)\n", wParam
, lParam
);
5470 if (wParam
== GWL_STYLE
)
5472 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5474 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_CHECKBOXES
)
5476 if (dwNewStyle
& TVS_CHECKBOXES
)
5478 TREEVIEW_InitCheckboxes(infoPtr
);
5479 TRACE("checkboxes enabled\n");
5481 /* set all items to state image index 1 */
5482 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
5486 FIXME("tried to disable checkboxes\n");
5490 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5492 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5494 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5495 TRACE("tooltips enabled\n");
5499 DestroyWindow(infoPtr
->hwndToolTip
);
5500 infoPtr
->hwndToolTip
= 0;
5501 TRACE("tooltips disabled\n");
5505 infoPtr
->dwStyle
= dwNewStyle
;
5508 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
5509 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5510 TREEVIEW_UpdateScrollBars(infoPtr
);
5511 TREEVIEW_Invalidate(infoPtr
, NULL
);
5517 TREEVIEW_SetCursor(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5520 TREEVIEW_ITEM
* item
;
5524 ScreenToClient(infoPtr
->hwnd
, &pt
);
5526 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5528 memset(&nmmouse
, 0, sizeof(nmmouse
));
5529 nmmouse
.hdr
.hwndFrom
= infoPtr
->hwnd
;
5530 nmmouse
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwnd
, GWLP_ID
);
5531 nmmouse
.hdr
.code
= NM_SETCURSOR
;
5534 nmmouse
.dwItemSpec
= (DWORD_PTR
)item
;
5535 nmmouse
.dwItemData
= item
->lParam
;
5539 nmmouse
.dwHitInfo
= lParam
;
5540 if (TREEVIEW_SendRealNotify(infoPtr
, nmmouse
.hdr
.idFrom
, &nmmouse
.hdr
))
5543 if (item
&& (infoPtr
->dwStyle
& TVS_TRACKSELECT
))
5545 SetCursor(infoPtr
->hcurHand
);
5549 return DefWindowProcW(infoPtr
->hwnd
, WM_SETCURSOR
, wParam
, lParam
);
5553 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5557 if (!infoPtr
->selectedItem
)
5559 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5563 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5564 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5569 TREEVIEW_KillFocus(const TREEVIEW_INFO
*infoPtr
)
5573 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5574 UpdateWindow(infoPtr
->hwnd
);
5575 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5579 /* update theme after a WM_THEMECHANGED message */
5580 static LRESULT
TREEVIEW_ThemeChanged(const TREEVIEW_INFO
*infoPtr
)
5582 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5583 CloseThemeData (theme
);
5584 OpenThemeData (infoPtr
->hwnd
, themeClass
);
5589 static LRESULT WINAPI
5590 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5592 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5594 TRACE("hwnd %p msg %04x wp=%08lx lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5596 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5599 if (uMsg
== WM_CREATE
)
5600 TREEVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
5607 case TVM_CREATEDRAGIMAGE
:
5608 return TREEVIEW_CreateDragImage(infoPtr
, lParam
);
5610 case TVM_DELETEITEM
:
5611 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5613 case TVM_EDITLABELA
:
5614 case TVM_EDITLABELW
:
5615 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5617 case TVM_ENDEDITLABELNOW
:
5618 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5620 case TVM_ENSUREVISIBLE
:
5621 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5624 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5626 case TVM_GETBKCOLOR
:
5627 return TREEVIEW_GetBkColor(infoPtr
);
5630 return TREEVIEW_GetCount(infoPtr
);
5632 case TVM_GETEDITCONTROL
:
5633 return TREEVIEW_GetEditControl(infoPtr
);
5635 case TVM_GETIMAGELIST
:
5636 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5639 return TREEVIEW_GetIndent(infoPtr
);
5641 case TVM_GETINSERTMARKCOLOR
:
5642 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5644 case TVM_GETISEARCHSTRINGA
:
5645 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5648 case TVM_GETISEARCHSTRINGW
:
5649 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5654 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5655 uMsg
== TVM_GETITEMW
);
5656 case TVM_GETITEMHEIGHT
:
5657 return TREEVIEW_GetItemHeight(infoPtr
);
5659 case TVM_GETITEMRECT
:
5660 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5662 case TVM_GETITEMSTATE
:
5663 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5665 case TVM_GETLINECOLOR
:
5666 return TREEVIEW_GetLineColor(infoPtr
);
5668 case TVM_GETNEXTITEM
:
5669 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5671 case TVM_GETSCROLLTIME
:
5672 return TREEVIEW_GetScrollTime(infoPtr
);
5674 case TVM_GETTEXTCOLOR
:
5675 return TREEVIEW_GetTextColor(infoPtr
);
5677 case TVM_GETTOOLTIPS
:
5678 return TREEVIEW_GetToolTips(infoPtr
);
5680 case TVM_GETUNICODEFORMAT
:
5681 return TREEVIEW_GetUnicodeFormat(infoPtr
);
5683 case TVM_GETVISIBLECOUNT
:
5684 return TREEVIEW_GetVisibleCount(infoPtr
);
5687 return TREEVIEW_HitTest(infoPtr
, (LPTVHITTESTINFO
)lParam
);
5689 case TVM_INSERTITEMA
:
5690 case TVM_INSERTITEMW
:
5691 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
,
5692 uMsg
== TVM_INSERTITEMW
);
5693 case TVM_SELECTITEM
:
5694 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5696 case TVM_SETBKCOLOR
:
5697 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5699 case TVM_SETIMAGELIST
:
5700 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5703 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5705 case TVM_SETINSERTMARK
:
5706 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5708 case TVM_SETINSERTMARKCOLOR
:
5709 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5713 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5714 uMsg
== TVM_SETITEMW
);
5715 case TVM_SETLINECOLOR
:
5716 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5718 case TVM_SETITEMHEIGHT
:
5719 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5721 case TVM_SETSCROLLTIME
:
5722 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5724 case TVM_SETTEXTCOLOR
:
5725 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5727 case TVM_SETTOOLTIPS
:
5728 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5730 case TVM_SETUNICODEFORMAT
:
5731 return TREEVIEW_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
5733 case TVM_SORTCHILDREN
:
5734 return TREEVIEW_SortChildren(infoPtr
, lParam
);
5736 case TVM_SORTCHILDRENCB
:
5737 return TREEVIEW_SortChildrenCB(infoPtr
, (LPTVSORTCB
)lParam
);
5740 return TREEVIEW_ProcessLetterKeys(infoPtr
, wParam
, lParam
);
5743 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5746 return TREEVIEW_Destroy(infoPtr
);
5751 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5754 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5757 return TREEVIEW_GetFont(infoPtr
);
5760 return TREEVIEW_HScroll(infoPtr
, wParam
);
5763 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5766 return TREEVIEW_KillFocus(infoPtr
);
5768 case WM_LBUTTONDBLCLK
:
5769 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5771 case WM_LBUTTONDOWN
:
5772 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5774 /* WM_MBUTTONDOWN */
5777 return TREEVIEW_MouseLeave(infoPtr
);
5780 return TREEVIEW_MouseMove(infoPtr
, lParam
);
5782 case WM_NCLBUTTONDOWN
:
5783 if (infoPtr
->hwndEdit
)
5784 SetFocus(infoPtr
->hwnd
);
5788 return TREEVIEW_NCPaint (infoPtr
, (HRGN
)wParam
, lParam
);
5791 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5793 case WM_NOTIFYFORMAT
:
5794 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5796 case WM_PRINTCLIENT
:
5797 return TREEVIEW_PrintClient(infoPtr
, (HDC
)wParam
, lParam
);
5800 return TREEVIEW_Paint(infoPtr
, (HDC
)wParam
);
5802 case WM_RBUTTONDOWN
:
5803 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5806 return TREEVIEW_SetCursor(infoPtr
, wParam
, lParam
);
5809 return TREEVIEW_SetFocus(infoPtr
);
5812 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5815 return TREEVIEW_SetRedraw(infoPtr
, wParam
);
5818 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5820 case WM_STYLECHANGED
:
5821 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5823 case WM_SYSCOLORCHANGE
:
5824 COMCTL32_RefreshSysColors();
5830 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5832 case WM_THEMECHANGED
:
5833 return TREEVIEW_ThemeChanged (infoPtr
);
5836 return TREEVIEW_VScroll(infoPtr
, wParam
);
5838 /* WM_WININICHANGE */
5841 return TREEVIEW_MouseWheel(infoPtr
, wParam
, lParam
);
5844 TRACE("drawItem\n");
5848 /* This mostly catches MFC and Delphi messages. :( */
5849 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
5850 TRACE("Unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
5852 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
5857 /* Class Registration ***************************************************/
5860 TREEVIEW_Register(void)
5866 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
5867 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5868 wndClass
.lpfnWndProc
= TREEVIEW_WindowProc
;
5869 wndClass
.cbClsExtra
= 0;
5870 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5872 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
5873 wndClass
.hbrBackground
= 0;
5874 wndClass
.lpszClassName
= WC_TREEVIEWW
;
5876 RegisterClassW(&wndClass
);
5881 TREEVIEW_Unregister(void)
5883 UnregisterClassW(WC_TREEVIEWW
, NULL
);
5887 /* Tree Verification ****************************************************/
5890 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
);
5892 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5893 const TREEVIEW_ITEM
*item
)
5895 assert(infoPtr
!= NULL
);
5896 assert(item
!= NULL
);
5898 /* both NULL, or both non-null */
5899 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5901 assert(item
->firstChild
!= item
);
5902 assert(item
->lastChild
!= item
);
5904 if (item
->firstChild
)
5906 assert(item
->firstChild
->parent
== item
);
5907 assert(item
->firstChild
->prevSibling
== NULL
);
5910 if (item
->lastChild
)
5912 assert(item
->lastChild
->parent
== item
);
5913 assert(item
->lastChild
->nextSibling
== NULL
);
5916 assert(item
->nextSibling
!= item
);
5917 if (item
->nextSibling
)
5919 assert(item
->nextSibling
->parent
== item
->parent
);
5920 assert(item
->nextSibling
->prevSibling
== item
);
5923 assert(item
->prevSibling
!= item
);
5924 if (item
->prevSibling
)
5926 assert(item
->prevSibling
->parent
== item
->parent
);
5927 assert(item
->prevSibling
->nextSibling
== item
);
5932 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5934 assert(item
!= NULL
);
5936 assert(item
->parent
!= NULL
);
5937 assert(item
->parent
!= item
);
5938 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5940 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5942 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5944 TREEVIEW_VerifyChildren(infoPtr
, item
);
5948 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5950 const TREEVIEW_ITEM
*child
;
5951 assert(item
!= NULL
);
5953 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5954 TREEVIEW_VerifyItem(infoPtr
, child
);
5958 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5960 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5962 assert(root
!= NULL
);
5963 assert(root
->iLevel
== -1);
5964 assert(root
->parent
== NULL
);
5965 assert(root
->prevSibling
== NULL
);
5967 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
5969 TREEVIEW_VerifyChildren(infoPtr
, root
);
5973 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
5975 if (!TRACE_ON(treeview
)) return;
5977 assert(infoPtr
!= NULL
);
5978 TREEVIEW_VerifyRoot(infoPtr
);