3 * Copyright 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de>
4 * Copyright 1998,1999 Alex Priem <alexp@sci.kun.nl>
5 * Copyright 1999 Sylvain St-Germain
6 * Copyright 2002 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * Note that TREEVIEW_INFO * and HTREEITEM are the same thing.
26 * Note2: If item's text == LPSTR_TEXTCALLBACKA we allocate buffer
27 * of size TEXT_CALLBACK_SIZE in DoSetItem.
28 * We use callbackMask to keep track of fields to be updated.
31 * missing notifications: TVN_GETINFOTIP, TVN_KEYDOWN,
34 * missing styles: TVS_INFOTIP, TVS_RTLREADING,
36 * missing item styles: TVIS_EXPANDPARTIAL, TVIS_EX_FLAT,
39 * Make the insertion mark look right.
40 * Scroll (instead of repaint) as much as possible.
44 #include "wine/port.h"
53 #define NONAMELESSUNION
64 #include "wine/unicode.h"
65 #include "wine/debug.h"
66 #include "wine/exception.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(treeview
);
70 /* internal structures */
71 typedef struct tagTREEVIEW_INFO
74 HWND hwndNotify
; /* Owner window to send notifications to */
79 UINT uNumItems
; /* number of valid TREEVIEW_ITEMs */
80 INT cdmode
; /* last custom draw setting */
81 UINT uScrollTime
; /* max. time for scrolling in milliseconds */
82 BOOL bRedraw
; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
84 UINT uItemHeight
; /* item height */
87 LONG clientWidth
; /* width of control window */
88 LONG clientHeight
; /* height of control window */
90 LONG treeWidth
; /* width of visible tree items */
91 LONG treeHeight
; /* height of visible tree items */
93 UINT uIndent
; /* indentation in pixels */
94 HTREEITEM selectedItem
; /* handle to selected item or 0 if none */
95 HTREEITEM hotItem
; /* handle currently under cursor, 0 if none */
96 HTREEITEM focusedItem
; /* item that was under the cursor when WM_LBUTTONDOWN was received */
97 HTREEITEM editItem
; /* item being edited with builtin edit box */
99 HTREEITEM firstVisible
; /* handle to item whose top edge is at y = 0 */
100 LONG maxVisibleOrder
;
101 HTREEITEM dropItem
; /* handle to item selected by drag cursor */
102 HTREEITEM insertMarkItem
; /* item after which insertion mark is placed */
103 BOOL insertBeforeorAfter
; /* flag used by TVM_SETINSERTMARK */
104 HIMAGELIST dragList
; /* Bitmap of dragged item */
110 COLORREF clrInsertMark
;
114 HFONT hUnderlineFont
;
115 HFONT hBoldUnderlineFont
;
120 WNDPROC wpEditOrig
; /* orig window proc for subclassing edit */
121 BOOL bIgnoreEditKillFocus
;
124 BOOL bNtfUnicode
; /* TRUE if should send NOTIFY with W */
125 HIMAGELIST himlNormal
;
126 int normalImageHeight
;
127 int normalImageWidth
;
128 HIMAGELIST himlState
;
129 int stateImageHeight
;
133 DWORD lastKeyPressTimestamp
;
135 INT nSearchParamLength
;
136 WCHAR szSearchParam
[ MAX_PATH
];
139 typedef struct _TREEITEM
/* HTREEITEM is a _TREEINFO *. */
141 HTREEITEM parent
; /* handle to parent or 0 if at root */
142 HTREEITEM nextSibling
; /* handle to next item in list, 0 if last */
143 HTREEITEM firstChild
; /* handle to first child or 0 if no child */
155 int iIntegral
; /* item height multiplier (1 is normal) */
156 int iLevel
; /* indentation level:0=root level */
158 HTREEITEM prevSibling
; /* handle to prev item in list, 0 if first */
164 LONG textWidth
; /* horizontal text extent for pszText */
165 LONG visibleOrder
; /* Depth-first numbering of the items whose ancestors are all expanded,
166 corresponding to a top-to-bottom ordering in the tree view.
167 Each item takes up "item.iIntegral" spots in the visible order.
168 0 is the root's first child. */
169 const TREEVIEW_INFO
*infoPtr
; /* tree data this item belongs to */
172 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
173 #define KEY_DELAY 450
175 /* bitflags for infoPtr->uInternalStatus */
177 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
178 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
179 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
180 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
181 #define TV_RDRAG 0x10 /* ditto Rbutton */
182 #define TV_RDRAGGING 0x20
184 /* bitflags for infoPtr->timer */
186 #define TV_EDIT_TIMER 2
187 #define TV_EDIT_TIMER_SET 2
189 #define TEXT_CALLBACK_SIZE 260
191 #define TREEVIEW_LEFT_MARGIN 8
193 #define MINIMUM_INDENT 19
195 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
197 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
198 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
199 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
201 #define GETLINECOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrGrayText : (x))
202 #define GETBKCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindow : (x))
203 #define GETTXTCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindowText : (x))
204 #define GETINSCOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrBtnText : (x))
206 static const WCHAR themeClass
[] = { 'T','r','e','e','v','i','e','w',0 };
209 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
212 static VOID
TREEVIEW_Invalidate(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
214 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
215 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
216 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
217 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
218 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
219 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
221 /* Random Utilities *****************************************************/
222 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
224 /* Returns the treeview private data if hwnd is a treeview.
225 * Otherwise returns an undefined value. */
226 static inline TREEVIEW_INFO
*
227 TREEVIEW_GetInfoPtr(HWND hwnd
)
229 return (TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
232 /* Don't call this. Nothing wants an item index. */
234 TREEVIEW_GetItemIndex(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
236 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
239 /* Checks if item has changed and needs to be redrawn */
240 static inline BOOL
item_changed (const TREEVIEW_ITEM
*tiOld
, const TREEVIEW_ITEM
*tiNew
,
241 const TVITEMEXW
*tvChange
)
243 /* Number of children has changed */
244 if ((tvChange
->mask
& TVIF_CHILDREN
) && (tiOld
->cChildren
!= tiNew
->cChildren
))
247 /* Image has changed and it's not a callback */
248 if ((tvChange
->mask
& TVIF_IMAGE
) && (tiOld
->iImage
!= tiNew
->iImage
) &&
249 tiNew
->iImage
!= I_IMAGECALLBACK
)
252 /* Selected image has changed and it's not a callback */
253 if ((tvChange
->mask
& TVIF_SELECTEDIMAGE
) && (tiOld
->iSelectedImage
!= tiNew
->iSelectedImage
) &&
254 tiNew
->iSelectedImage
!= I_IMAGECALLBACK
)
257 if ((tvChange
->mask
& TVIF_EXPANDEDIMAGE
) && (tiOld
->iExpandedImage
!= tiNew
->iExpandedImage
) &&
258 tiNew
->iExpandedImage
!= I_IMAGECALLBACK
)
261 /* Text has changed and it's not a callback */
262 if ((tvChange
->mask
& TVIF_TEXT
) && (tiOld
->pszText
!= tiNew
->pszText
) &&
263 tiNew
->pszText
!= LPSTR_TEXTCALLBACKW
)
266 /* Indent has changed */
267 if ((tvChange
->mask
& TVIF_INTEGRAL
) && (tiOld
->iIntegral
!= tiNew
->iIntegral
))
270 /* Item state has changed */
271 if ((tvChange
->mask
& TVIF_STATE
) && ((tiOld
->state
^ tiNew
->state
) & tvChange
->stateMask
))
277 /***************************************************************************
278 * This method checks that handle is an item for this tree.
281 TREEVIEW_ValidItem(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
283 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
285 TRACE("invalid item %p\n", handle
);
293 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
297 GetObjectW(hOrigFont
, sizeof(font
), &font
);
298 font
.lfWeight
= FW_BOLD
;
299 return CreateFontIndirectW(&font
);
303 TREEVIEW_CreateUnderlineFont(HFONT hOrigFont
)
307 GetObjectW(hOrigFont
, sizeof(font
), &font
);
308 font
.lfUnderline
= TRUE
;
309 return CreateFontIndirectW(&font
);
313 TREEVIEW_CreateBoldUnderlineFont(HFONT hfont
)
317 GetObjectW(hfont
, sizeof(font
), &font
);
318 font
.lfWeight
= FW_BOLD
;
319 font
.lfUnderline
= TRUE
;
320 return CreateFontIndirectW(&font
);
324 TREEVIEW_FontForItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
326 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
327 return item
->state
& TVIS_BOLD
? infoPtr
->hBoldUnderlineFont
: infoPtr
->hUnderlineFont
;
328 if (item
->state
& TVIS_BOLD
)
329 return infoPtr
->hBoldFont
;
330 return infoPtr
->hFont
;
333 /* for trace/debugging purposes only */
335 TREEVIEW_ItemName(const TREEVIEW_ITEM
*item
)
337 if (item
== NULL
) return "<null item>";
338 if (item
->pszText
== LPSTR_TEXTCALLBACKW
) return "<callback>";
339 if (item
->pszText
== NULL
) return "<null>";
340 return debugstr_w(item
->pszText
);
343 /* An item is not a child of itself. */
345 TREEVIEW_IsChildOf(const TREEVIEW_ITEM
*parent
, const TREEVIEW_ITEM
*child
)
349 child
= child
->parent
;
350 if (child
== parent
) return TRUE
;
351 } while (child
!= NULL
);
357 TREEVIEW_IsFullRowSelect(const TREEVIEW_INFO
*infoPtr
)
359 return !(infoPtr
->dwStyle
& TVS_HASLINES
) && (infoPtr
->dwStyle
& TVS_FULLROWSELECT
);
363 TREEVIEW_IsItemHit(const TREEVIEW_INFO
*infoPtr
, const TVHITTESTINFO
*ht
)
365 if (TREEVIEW_IsFullRowSelect(infoPtr
))
366 return ht
->flags
& (TVHT_ONITEMINDENT
| TVHT_ONITEMBUTTON
| TVHT_ONITEM
| TVHT_ONITEMRIGHT
);
368 return ht
->flags
& TVHT_ONITEM
;
371 /* Tree Traversal *******************************************************/
373 /***************************************************************************
374 * This method returns the last expanded sibling or child child item
377 static TREEVIEW_ITEM
*
378 TREEVIEW_GetLastListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
380 if (!item
) return NULL
;
382 while (item
->lastChild
)
384 if (item
->state
& TVIS_EXPANDED
)
385 item
= item
->lastChild
;
390 if (item
== infoPtr
->root
)
396 /***************************************************************************
397 * This method returns the previous non-hidden item in the list not
398 * considering the tree hierarchy.
400 static TREEVIEW_ITEM
*
401 TREEVIEW_GetPrevListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
403 if (tvItem
->prevSibling
)
405 /* This item has a prevSibling, get the last item in the sibling's tree. */
406 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
408 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
409 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
415 /* this item does not have a prevSibling, get the parent */
416 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
421 /***************************************************************************
422 * This method returns the next physical item in the treeview not
423 * considering the tree hierarchy.
425 static TREEVIEW_ITEM
*
426 TREEVIEW_GetNextListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
429 * If this item has children and is expanded, return the first child
431 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
433 return tvItem
->firstChild
;
438 * try to get the sibling
440 if (tvItem
->nextSibling
)
441 return tvItem
->nextSibling
;
444 * Otherwise, get the parent's sibling.
446 while (tvItem
->parent
)
448 tvItem
= tvItem
->parent
;
450 if (tvItem
->nextSibling
)
451 return tvItem
->nextSibling
;
457 /***************************************************************************
458 * This method returns the nth item starting at the given item. It returns
459 * the last item (or first) we we run out of items.
461 * Will scroll backward if count is <0.
462 * forward if count is >0.
464 static TREEVIEW_ITEM
*
465 TREEVIEW_GetListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
468 TREEVIEW_ITEM
*(*next_item
)(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
469 TREEVIEW_ITEM
*previousItem
;
471 assert(item
!= NULL
);
475 next_item
= TREEVIEW_GetNextListItem
;
480 next_item
= TREEVIEW_GetPrevListItem
;
488 item
= next_item(infoPtr
, item
);
490 } while (--count
&& item
!= NULL
);
493 return item
? item
: previousItem
;
496 /* Notifications ************************************************************/
498 static INT
get_notifycode(const TREEVIEW_INFO
*infoPtr
, INT code
)
500 if (!infoPtr
->bNtfUnicode
) {
502 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
503 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
504 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
505 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
506 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
507 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
508 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
509 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
510 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
511 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
512 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
513 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
520 TREEVIEW_SendRealNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, NMHDR
*hdr
)
522 TRACE("code=%d, hdr=%p\n", code
, hdr
);
524 hdr
->hwndFrom
= infoPtr
->hwnd
;
525 hdr
->idFrom
= GetWindowLongPtrW(infoPtr
->hwnd
, GWLP_ID
);
526 hdr
->code
= get_notifycode(infoPtr
, code
);
528 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, hdr
->idFrom
, (LPARAM
)hdr
);
532 TREEVIEW_SendSimpleNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
)
535 return TREEVIEW_SendRealNotify(infoPtr
, code
, &hdr
);
539 TREEVIEW_TVItemFromItem(const TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMW
*tvItem
, TREEVIEW_ITEM
*item
)
542 tvItem
->hItem
= item
;
543 tvItem
->state
= item
->state
;
544 tvItem
->stateMask
= 0;
545 tvItem
->iImage
= item
->iImage
;
546 tvItem
->iSelectedImage
= item
->iSelectedImage
;
547 tvItem
->cChildren
= item
->cChildren
;
548 tvItem
->lParam
= item
->lParam
;
552 if (!infoPtr
->bNtfUnicode
)
554 tvItem
->cchTextMax
= WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0, NULL
, NULL
);
555 tvItem
->pszText
= Alloc (tvItem
->cchTextMax
);
556 WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, 0, 0 );
560 tvItem
->cchTextMax
= item
->cchTextMax
;
561 tvItem
->pszText
= item
->pszText
;
566 tvItem
->cchTextMax
= 0;
567 tvItem
->pszText
= NULL
;
572 TREEVIEW_SendTreeviewNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
573 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
578 TRACE("code:%d action:0x%x olditem:%p newitem:%p\n",
579 code
, action
, oldItem
, newItem
);
581 memset(&nmhdr
, 0, sizeof(NMTREEVIEWW
));
582 nmhdr
.action
= action
;
585 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
588 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
593 ret
= TREEVIEW_SendRealNotify(infoPtr
, code
, &nmhdr
.hdr
);
594 if (!infoPtr
->bNtfUnicode
)
596 Free(nmhdr
.itemOld
.pszText
);
597 Free(nmhdr
.itemNew
.pszText
);
603 TREEVIEW_SendTreeviewDnDNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
,
604 HTREEITEM dragItem
, POINT pt
)
608 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
611 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
612 nmhdr
.itemNew
.hItem
= dragItem
;
613 nmhdr
.itemNew
.state
= dragItem
->state
;
614 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
616 nmhdr
.ptDrag
.x
= pt
.x
;
617 nmhdr
.ptDrag
.y
= pt
.y
;
619 return TREEVIEW_SendRealNotify(infoPtr
, code
, &nmhdr
.hdr
);
624 TREEVIEW_SendCustomDrawNotify(const TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
627 NMTVCUSTOMDRAW nmcdhdr
;
630 TRACE("drawstage:0x%x hdc:%p\n", dwDrawStage
, hdc
);
632 nmcd
= &nmcdhdr
.nmcd
;
633 nmcd
->dwDrawStage
= dwDrawStage
;
636 nmcd
->dwItemSpec
= 0;
637 nmcd
->uItemState
= 0;
638 nmcd
->lItemlParam
= 0;
639 nmcdhdr
.clrText
= infoPtr
->clrText
;
640 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
643 return TREEVIEW_SendRealNotify(infoPtr
, NM_CUSTOMDRAW
, &nmcdhdr
.nmcd
.hdr
);
646 /* FIXME: need to find out when the flags in uItemState need to be set */
649 TREEVIEW_SendCustomDrawItemNotify(const TREEVIEW_INFO
*infoPtr
, HDC hdc
,
650 TREEVIEW_ITEM
*item
, UINT uItemDrawState
,
651 NMTVCUSTOMDRAW
*nmcdhdr
)
655 DWORD_PTR dwItemSpec
;
658 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
659 dwItemSpec
= (DWORD_PTR
)item
;
661 if (item
->state
& TVIS_SELECTED
)
662 uItemState
|= CDIS_SELECTED
;
663 if (item
== infoPtr
->selectedItem
)
664 uItemState
|= CDIS_FOCUS
;
665 if (item
== infoPtr
->hotItem
)
666 uItemState
|= CDIS_HOT
;
668 nmcd
= &nmcdhdr
->nmcd
;
669 nmcd
->dwDrawStage
= dwDrawStage
;
671 nmcd
->rc
= item
->rect
;
672 nmcd
->dwItemSpec
= dwItemSpec
;
673 nmcd
->uItemState
= uItemState
;
674 nmcd
->lItemlParam
= item
->lParam
;
675 nmcdhdr
->iLevel
= item
->iLevel
;
677 TRACE("drawstage:0x%x hdc:%p item:%lx, itemstate:0x%x, lItemlParam:0x%lx\n",
678 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
679 nmcd
->uItemState
, nmcd
->lItemlParam
);
681 return TREEVIEW_SendRealNotify(infoPtr
, NM_CUSTOMDRAW
, &nmcdhdr
->nmcd
.hdr
);
685 TREEVIEW_BeginLabelEditNotify(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
690 TREEVIEW_TVItemFromItem(infoPtr
, TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
,
691 &tvdi
.item
, editItem
);
693 ret
= TREEVIEW_SendRealNotify(infoPtr
, TVN_BEGINLABELEDITW
, &tvdi
.hdr
);
695 if (!infoPtr
->bNtfUnicode
)
696 Free(tvdi
.item
.pszText
);
702 TREEVIEW_UpdateDispInfo(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
705 NMTVDISPINFOEXW callback
;
707 TRACE("mask=0x%x, callbackmask=0x%x\n", mask
, item
->callbackMask
);
708 mask
&= item
->callbackMask
;
710 if (mask
== 0) return;
712 /* 'state' always contains valid value, as well as 'lParam'.
713 * All other parameters are uninitialized.
715 callback
.item
.pszText
= item
->pszText
;
716 callback
.item
.cchTextMax
= item
->cchTextMax
;
717 callback
.item
.mask
= mask
;
718 callback
.item
.hItem
= item
;
719 callback
.item
.state
= item
->state
;
720 callback
.item
.lParam
= item
->lParam
;
722 /* If text is changed we need to recalculate textWidth */
723 if (mask
& TVIF_TEXT
)
726 TREEVIEW_SendRealNotify(infoPtr
, TVN_GETDISPINFOW
, &callback
.hdr
);
727 TRACE("resulting code 0x%08x\n", callback
.hdr
.code
);
729 /* It may have changed due to a call to SetItem. */
730 mask
&= item
->callbackMask
;
732 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= item
->pszText
)
734 /* Instead of copying text into our buffer user specified his own */
735 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
738 int len
= MultiByteToWideChar( CP_ACP
, 0,
739 (LPSTR
)callback
.item
.pszText
, -1,
741 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
742 newText
= ReAlloc(item
->pszText
, buflen
);
744 TRACE("returned str %s, len=%d, buflen=%d\n",
745 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
749 item
->pszText
= newText
;
750 MultiByteToWideChar( CP_ACP
, 0,
751 (LPSTR
)callback
.item
.pszText
, -1,
752 item
->pszText
, buflen
/sizeof(WCHAR
));
753 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
755 /* If ReAlloc fails we have nothing to do, but keep original text */
758 int len
= max(lstrlenW(callback
.item
.pszText
) + 1,
760 LPWSTR newText
= ReAlloc(item
->pszText
, len
);
762 TRACE("returned wstr %s, len=%d\n",
763 debugstr_w(callback
.item
.pszText
), len
);
767 item
->pszText
= newText
;
768 strcpyW(item
->pszText
, callback
.item
.pszText
);
769 item
->cchTextMax
= len
;
771 /* If ReAlloc fails we have nothing to do, but keep original text */
774 else if (mask
& TVIF_TEXT
) {
775 /* User put text into our buffer, that is ok unless A string */
776 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
779 int len
= MultiByteToWideChar( CP_ACP
, 0,
780 (LPSTR
)callback
.item
.pszText
, -1,
782 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
783 newText
= Alloc(buflen
);
785 TRACE("same buffer str %s, len=%d, buflen=%d\n",
786 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
790 LPWSTR oldText
= item
->pszText
;
791 item
->pszText
= newText
;
792 MultiByteToWideChar( CP_ACP
, 0,
793 (LPSTR
)callback
.item
.pszText
, -1,
794 item
->pszText
, buflen
/sizeof(WCHAR
));
795 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
801 if (mask
& TVIF_IMAGE
)
802 item
->iImage
= callback
.item
.iImage
;
804 if (mask
& TVIF_SELECTEDIMAGE
)
805 item
->iSelectedImage
= callback
.item
.iSelectedImage
;
807 if (mask
& TVIF_EXPANDEDIMAGE
)
808 item
->iExpandedImage
= callback
.item
.iExpandedImage
;
810 if (mask
& TVIF_CHILDREN
)
811 item
->cChildren
= callback
.item
.cChildren
;
813 if (callback
.item
.mask
& TVIF_STATE
)
815 item
->state
&= ~callback
.item
.stateMask
;
816 item
->state
|= (callback
.item
.state
& callback
.item
.stateMask
);
819 /* These members are now permanently set. */
820 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
821 item
->callbackMask
&= ~callback
.item
.mask
;
824 /***************************************************************************
825 * This function uses cChildren field to decide whether the item has
827 * Note: if this returns TRUE, the child items may not actually exist,
828 * they could be virtual.
830 * Just use item->firstChild to check for physical children.
833 TREEVIEW_HasChildren(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
835 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_CHILDREN
);
836 /* Protect for a case when callback field is not changed by a host,
837 otherwise negative values trigger normal notifications. */
838 return item
->cChildren
!= 0 && item
->cChildren
!= I_CHILDRENCALLBACK
;
841 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
845 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
847 if (nCommand
!= NF_REQUERY
) return 0;
849 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
850 TRACE("format=%d\n", format
);
852 /* Invalid format returned by NF_QUERY defaults to ANSI*/
853 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
)
856 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
861 /* Item Position ********************************************************/
863 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
865 TREEVIEW_ComputeItemInternalMetrics(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
867 /* has TVS_LINESATROOT and (TVS_HASLINES|TVS_HASBUTTONS) */
868 BOOL lar
= ((infoPtr
->dwStyle
& (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
871 item
->linesOffset
= infoPtr
->uIndent
* (lar
? item
->iLevel
: item
->iLevel
- 1)
873 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
874 item
->imageOffset
= item
->stateOffset
875 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
876 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
880 TREEVIEW_ComputeTextWidth(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
886 /* DRAW's OM docker creates items like this */
887 if (item
->pszText
== NULL
)
899 hdc
= GetDC(infoPtr
->hwnd
);
900 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
903 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
904 item
->textWidth
= sz
.cx
;
908 SelectObject(hdc
, hOldFont
);
914 TREEVIEW_ComputeItemRect(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
916 item
->rect
.top
= infoPtr
->uItemHeight
*
917 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
919 item
->rect
.bottom
= item
->rect
.top
920 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
923 item
->rect
.right
= infoPtr
->clientWidth
;
926 /* We know that only items after start need their order updated. */
928 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
935 start
= infoPtr
->root
->firstChild
;
939 order
= start
->visibleOrder
;
941 for (item
= start
; item
!= NULL
;
942 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
944 if (!ISVISIBLE(item
) && order
> 0)
945 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
946 item
->visibleOrder
= order
;
947 order
+= item
->iIntegral
;
950 infoPtr
->maxVisibleOrder
= order
;
952 for (item
= start
; item
!= NULL
;
953 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
955 TREEVIEW_ComputeItemRect(infoPtr
, item
);
960 /* Update metrics of all items in selected subtree.
961 * root must be expanded
964 TREEVIEW_UpdateSubTree(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
966 TREEVIEW_ITEM
*sibling
;
970 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
973 root
->state
&= ~TVIS_EXPANDED
;
974 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
975 root
->state
|= TVIS_EXPANDED
;
977 hdc
= GetDC(infoPtr
->hwnd
);
978 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
980 for (; root
!= sibling
;
981 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
983 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
985 if (root
->callbackMask
& TVIF_TEXT
)
986 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
988 if (root
->textWidth
== 0)
990 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
991 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
995 SelectObject(hdc
, hOldFont
);
996 ReleaseDC(infoPtr
->hwnd
, hdc
);
999 /* Item Allocation **********************************************************/
1001 static TREEVIEW_ITEM
*
1002 TREEVIEW_AllocateItem(const TREEVIEW_INFO
*infoPtr
)
1004 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
1009 /* I_IMAGENONE would make more sense but this is neither what is
1010 * documented (MSDN doesn't specify) nor what Windows actually does
1011 * (it sets it to zero)... and I can so imagine an application using
1012 * inc/dec to toggle the images. */
1013 newItem
->iImage
= 0;
1014 newItem
->iSelectedImage
= 0;
1015 newItem
->iExpandedImage
= (WORD
)I_IMAGENONE
;
1016 newItem
->infoPtr
= infoPtr
;
1018 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
1027 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
1028 * free item->pszText. */
1030 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1032 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
1033 if (infoPtr
->selectedItem
== item
)
1034 infoPtr
->selectedItem
= NULL
;
1035 if (infoPtr
->hotItem
== item
)
1036 infoPtr
->hotItem
= NULL
;
1037 if (infoPtr
->focusedItem
== item
)
1038 infoPtr
->focusedItem
= NULL
;
1039 if (infoPtr
->firstVisible
== item
)
1040 infoPtr
->firstVisible
= NULL
;
1041 if (infoPtr
->dropItem
== item
)
1042 infoPtr
->dropItem
= NULL
;
1043 if (infoPtr
->insertMarkItem
== item
)
1044 infoPtr
->insertMarkItem
= NULL
;
1049 /* Item Insertion *******************************************************/
1051 /***************************************************************************
1052 * This method inserts newItem before sibling as a child of parent.
1053 * sibling can be NULL, but only if parent has no children.
1056 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1057 TREEVIEW_ITEM
*parent
)
1059 assert(parent
!= NULL
);
1061 if (sibling
!= NULL
)
1063 assert(sibling
->parent
== parent
);
1065 if (sibling
->prevSibling
!= NULL
)
1066 sibling
->prevSibling
->nextSibling
= newItem
;
1068 newItem
->prevSibling
= sibling
->prevSibling
;
1069 sibling
->prevSibling
= newItem
;
1072 newItem
->prevSibling
= NULL
;
1074 newItem
->nextSibling
= sibling
;
1076 if (parent
->firstChild
== sibling
)
1077 parent
->firstChild
= newItem
;
1079 if (parent
->lastChild
== NULL
)
1080 parent
->lastChild
= newItem
;
1083 /***************************************************************************
1084 * This method inserts newItem after sibling as a child of parent.
1085 * sibling can be NULL, but only if parent has no children.
1088 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1089 TREEVIEW_ITEM
*parent
)
1091 assert(parent
!= NULL
);
1093 if (sibling
!= NULL
)
1095 assert(sibling
->parent
== parent
);
1097 if (sibling
->nextSibling
!= NULL
)
1098 sibling
->nextSibling
->prevSibling
= newItem
;
1100 newItem
->nextSibling
= sibling
->nextSibling
;
1101 sibling
->nextSibling
= newItem
;
1104 newItem
->nextSibling
= NULL
;
1106 newItem
->prevSibling
= sibling
;
1108 if (parent
->lastChild
== sibling
)
1109 parent
->lastChild
= newItem
;
1111 if (parent
->firstChild
== NULL
)
1112 parent
->firstChild
= newItem
;
1116 TREEVIEW_DoSetItemT(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
1117 const TVITEMEXW
*tvItem
, BOOL isW
)
1119 UINT callbackClear
= 0;
1120 UINT callbackSet
= 0;
1122 TRACE("item %p\n", item
);
1123 /* Do this first in case it fails. */
1124 if (tvItem
->mask
& TVIF_TEXT
)
1126 item
->textWidth
= 0; /* force width recalculation */
1127 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKW
&& tvItem
->pszText
!= NULL
) /* covers != TEXTCALLBACKA too, and undocumented: pszText of NULL also means TEXTCALLBACK */
1132 len
= lstrlenW(tvItem
->pszText
) + 1;
1134 len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1, NULL
, 0);
1136 newText
= ReAlloc(item
->pszText
, len
* sizeof(WCHAR
));
1138 if (newText
== NULL
) return FALSE
;
1140 callbackClear
|= TVIF_TEXT
;
1142 item
->pszText
= newText
;
1143 item
->cchTextMax
= len
;
1145 lstrcpynW(item
->pszText
, tvItem
->pszText
, len
);
1147 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1,
1148 item
->pszText
, len
);
1150 TRACE("setting text %s, item %p\n", debugstr_w(item
->pszText
), item
);
1154 callbackSet
|= TVIF_TEXT
;
1156 item
->pszText
= ReAlloc(item
->pszText
,
1157 TEXT_CALLBACK_SIZE
* sizeof(WCHAR
));
1158 item
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1159 TRACE("setting callback, item %p\n", item
);
1163 if (tvItem
->mask
& TVIF_CHILDREN
)
1165 item
->cChildren
= tvItem
->cChildren
;
1167 if (item
->cChildren
== I_CHILDRENCALLBACK
)
1168 callbackSet
|= TVIF_CHILDREN
;
1170 callbackClear
|= TVIF_CHILDREN
;
1173 if (tvItem
->mask
& TVIF_IMAGE
)
1175 item
->iImage
= tvItem
->iImage
;
1177 if (item
->iImage
== I_IMAGECALLBACK
)
1178 callbackSet
|= TVIF_IMAGE
;
1180 callbackClear
|= TVIF_IMAGE
;
1183 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1185 item
->iSelectedImage
= tvItem
->iSelectedImage
;
1187 if (item
->iSelectedImage
== I_IMAGECALLBACK
)
1188 callbackSet
|= TVIF_SELECTEDIMAGE
;
1190 callbackClear
|= TVIF_SELECTEDIMAGE
;
1193 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
1195 item
->iExpandedImage
= tvItem
->iExpandedImage
;
1197 if (item
->iExpandedImage
== I_IMAGECALLBACK
)
1198 callbackSet
|= TVIF_EXPANDEDIMAGE
;
1200 callbackClear
|= TVIF_EXPANDEDIMAGE
;
1203 if (tvItem
->mask
& TVIF_PARAM
)
1204 item
->lParam
= tvItem
->lParam
;
1206 /* If the application sets TVIF_INTEGRAL without
1207 * supplying a TVITEMEX structure, it's toast. */
1208 if (tvItem
->mask
& TVIF_INTEGRAL
)
1209 item
->iIntegral
= tvItem
->iIntegral
;
1211 if (tvItem
->mask
& TVIF_STATE
)
1213 TRACE("prevstate 0x%x, state 0x%x, mask 0x%x\n", item
->state
, tvItem
->state
,
1215 item
->state
&= ~tvItem
->stateMask
;
1216 item
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1219 if (tvItem
->mask
& TVIF_STATEEX
)
1221 FIXME("New extended state: 0x%x\n", tvItem
->uStateEx
);
1224 item
->callbackMask
|= callbackSet
;
1225 item
->callbackMask
&= ~callbackClear
;
1230 /* Note that the new item is pre-zeroed. */
1232 TREEVIEW_InsertItemT(TREEVIEW_INFO
*infoPtr
, const TVINSERTSTRUCTW
*ptdi
, BOOL isW
)
1234 const TVITEMEXW
*tvItem
= &ptdi
->u
.itemex
;
1235 HTREEITEM insertAfter
;
1236 TREEVIEW_ITEM
*newItem
, *parentItem
;
1237 BOOL bTextUpdated
= FALSE
;
1239 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1241 parentItem
= infoPtr
->root
;
1245 parentItem
= ptdi
->hParent
;
1247 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1249 WARN("invalid parent %p\n", parentItem
);
1254 insertAfter
= ptdi
->hInsertAfter
;
1256 /* Validate this now for convenience. */
1257 switch ((DWORD_PTR
)insertAfter
)
1259 case (DWORD_PTR
)TVI_FIRST
:
1260 case (DWORD_PTR
)TVI_LAST
:
1261 case (DWORD_PTR
)TVI_SORT
:
1265 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1266 insertAfter
->parent
!= parentItem
)
1268 WARN("invalid insert after %p\n", insertAfter
);
1269 insertAfter
= TVI_LAST
;
1273 TRACE("parent %p position %p: %s\n", parentItem
, insertAfter
,
1274 (tvItem
->mask
& TVIF_TEXT
)
1275 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKW
) ? "<callback>"
1276 : (isW
? debugstr_w(tvItem
->pszText
) : debugstr_a((LPSTR
)tvItem
->pszText
)))
1279 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1280 if (newItem
== NULL
)
1283 newItem
->parent
= parentItem
;
1284 newItem
->iIntegral
= 1;
1285 newItem
->visibleOrder
= -1;
1287 if (!TREEVIEW_DoSetItemT(infoPtr
, newItem
, tvItem
, isW
))
1290 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1292 infoPtr
->uNumItems
++;
1294 switch ((DWORD_PTR
)insertAfter
)
1296 case (DWORD_PTR
)TVI_FIRST
:
1298 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1299 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1300 if (infoPtr
->firstVisible
== originalFirst
)
1301 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1305 case (DWORD_PTR
)TVI_LAST
:
1306 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1309 /* hInsertAfter names a specific item we want to insert after */
1311 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1314 case (DWORD_PTR
)TVI_SORT
:
1316 TREEVIEW_ITEM
*aChild
;
1317 TREEVIEW_ITEM
*previousChild
= NULL
;
1318 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1319 BOOL bItemInserted
= FALSE
;
1321 aChild
= parentItem
->firstChild
;
1323 bTextUpdated
= TRUE
;
1324 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1326 /* Iterate the parent children to see where we fit in */
1327 while (aChild
!= NULL
)
1331 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1332 comp
= lstrcmpW(newItem
->pszText
, aChild
->pszText
);
1334 if (comp
< 0) /* we are smaller than the current one */
1336 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1337 if (infoPtr
->firstVisible
== originalFirst
&&
1338 aChild
== originalFirst
)
1339 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1340 bItemInserted
= TRUE
;
1343 else if (comp
> 0) /* we are bigger than the current one */
1345 previousChild
= aChild
;
1347 /* This will help us to exit if there is no more sibling */
1348 aChild
= (aChild
->nextSibling
== 0)
1350 : aChild
->nextSibling
;
1352 /* Look at the next item */
1358 * An item with this name is already existing, therefore,
1359 * we add after the one we found
1361 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1362 bItemInserted
= TRUE
;
1368 * we reach the end of the child list and the item has not
1369 * yet been inserted, therefore, insert it after the last child.
1371 if ((!bItemInserted
) && (aChild
== NULL
))
1372 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1379 TRACE("new item %p; parent %p, mask 0x%x\n", newItem
,
1380 newItem
->parent
, tvItem
->mask
);
1382 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1384 if (newItem
->parent
->cChildren
== 0)
1385 newItem
->parent
->cChildren
= 1;
1387 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1389 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1390 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1393 if (infoPtr
->firstVisible
== NULL
)
1394 infoPtr
->firstVisible
= newItem
;
1396 TREEVIEW_VerifyTree(infoPtr
);
1398 if (!infoPtr
->bRedraw
) return (LRESULT
)newItem
;
1400 if (parentItem
== infoPtr
->root
||
1401 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1403 TREEVIEW_ITEM
*item
;
1404 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1406 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1407 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1410 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1412 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1413 TREEVIEW_UpdateScrollBars(infoPtr
);
1415 * if the item was inserted in a visible part of the tree,
1416 * invalidate it, as well as those after it
1418 for (item
= newItem
;
1420 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1421 TREEVIEW_Invalidate(infoPtr
, item
);
1425 /* refresh treeview if newItem is the first item inserted under parentItem */
1426 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1428 /* parent got '+' - update it */
1429 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1433 return (LRESULT
)newItem
;
1436 /* Item Deletion ************************************************************/
1438 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
1441 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*parentItem
)
1443 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1445 while (kill
!= NULL
)
1447 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1449 TREEVIEW_RemoveItem(infoPtr
, kill
);
1454 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1455 assert(parentItem
->firstChild
== NULL
);
1456 assert(parentItem
->lastChild
== NULL
);
1460 TREEVIEW_UnlinkItem(const TREEVIEW_ITEM
*item
)
1462 TREEVIEW_ITEM
*parentItem
;
1464 assert(item
!= NULL
);
1465 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1467 parentItem
= item
->parent
;
1469 if (parentItem
->firstChild
== item
)
1470 parentItem
->firstChild
= item
->nextSibling
;
1472 if (parentItem
->lastChild
== item
)
1473 parentItem
->lastChild
= item
->prevSibling
;
1475 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1476 && parentItem
->cChildren
> 0)
1477 parentItem
->cChildren
= 0;
1479 if (item
->prevSibling
)
1480 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1482 if (item
->nextSibling
)
1483 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1487 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1489 TRACE("%p, (%s)\n", item
, TREEVIEW_ItemName(item
));
1491 if (item
->firstChild
)
1492 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
1494 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1495 TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
1497 TREEVIEW_UnlinkItem(item
);
1499 infoPtr
->uNumItems
--;
1501 if (item
->pszText
!= LPSTR_TEXTCALLBACKW
)
1502 Free(item
->pszText
);
1504 TREEVIEW_FreeItem(infoPtr
, item
);
1508 /* Empty out the tree. */
1510 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1512 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1514 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1518 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
)
1520 TREEVIEW_ITEM
*newSelection
= NULL
;
1521 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1522 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1523 BOOL visible
= FALSE
;
1525 if (item
== TVI_ROOT
|| !item
)
1527 TRACE("TVI_ROOT\n");
1528 parent
= infoPtr
->root
;
1529 newSelection
= NULL
;
1531 TREEVIEW_RemoveTree(infoPtr
);
1535 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1538 TRACE("%p (%s)\n", item
, TREEVIEW_ItemName(item
));
1539 parent
= item
->parent
;
1541 if (ISVISIBLE(item
))
1543 prev
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
1547 if (infoPtr
->selectedItem
!= NULL
1548 && (item
== infoPtr
->selectedItem
1549 || TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
)))
1551 if (item
->nextSibling
)
1552 newSelection
= item
->nextSibling
;
1553 else if (item
->parent
!= infoPtr
->root
)
1554 newSelection
= item
->parent
;
1556 newSelection
= item
->prevSibling
;
1557 TRACE("newSelection = %p\n", newSelection
);
1560 if (infoPtr
->firstVisible
== item
)
1563 if (item
->nextSibling
)
1564 newFirstVisible
= item
->nextSibling
;
1565 else if (item
->prevSibling
)
1566 newFirstVisible
= item
->prevSibling
;
1567 else if (item
->parent
!= infoPtr
->root
)
1568 newFirstVisible
= item
->parent
;
1569 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1572 newFirstVisible
= infoPtr
->firstVisible
;
1574 TREEVIEW_RemoveItem(infoPtr
, item
);
1577 /* Don't change if somebody else already has (infoPtr->selectedItem is cleared by FreeItem). */
1578 if (!infoPtr
->selectedItem
&& newSelection
)
1580 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1581 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1584 /* Validate insertMark dropItem.
1585 * hotItem ??? - used for comparison only.
1587 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1588 infoPtr
->insertMarkItem
= 0;
1590 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1591 infoPtr
->dropItem
= 0;
1593 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1594 newFirstVisible
= infoPtr
->root
->firstChild
;
1596 TREEVIEW_VerifyTree(infoPtr
);
1599 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1601 if (!infoPtr
->bRedraw
) return TRUE
;
1605 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1606 TREEVIEW_UpdateScrollBars(infoPtr
);
1607 TREEVIEW_Invalidate(infoPtr
, NULL
);
1609 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1611 /* parent lost '+/-' - update it */
1612 TREEVIEW_Invalidate(infoPtr
, parent
);
1619 /* Get/Set Messages *********************************************************/
1621 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
)
1623 infoPtr
->bRedraw
= wParam
!= 0;
1625 if (infoPtr
->bRedraw
)
1627 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1628 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1629 TREEVIEW_UpdateScrollBars(infoPtr
);
1630 TREEVIEW_Invalidate(infoPtr
, NULL
);
1636 TREEVIEW_GetIndent(const TREEVIEW_INFO
*infoPtr
)
1639 return infoPtr
->uIndent
;
1643 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1647 if (newIndent
< MINIMUM_INDENT
)
1648 newIndent
= MINIMUM_INDENT
;
1650 if (infoPtr
->uIndent
!= newIndent
)
1652 infoPtr
->uIndent
= newIndent
;
1653 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1654 TREEVIEW_UpdateScrollBars(infoPtr
);
1655 TREEVIEW_Invalidate(infoPtr
, NULL
);
1663 TREEVIEW_GetToolTips(const TREEVIEW_INFO
*infoPtr
)
1666 return (LRESULT
)infoPtr
->hwndToolTip
;
1670 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1675 prevToolTip
= infoPtr
->hwndToolTip
;
1676 infoPtr
->hwndToolTip
= hwndTT
;
1678 return (LRESULT
)prevToolTip
;
1682 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO
*infoPtr
, BOOL fUnicode
)
1684 BOOL rc
= infoPtr
->bNtfUnicode
;
1685 infoPtr
->bNtfUnicode
= fUnicode
;
1690 TREEVIEW_GetUnicodeFormat(const TREEVIEW_INFO
*infoPtr
)
1692 return infoPtr
->bNtfUnicode
;
1696 TREEVIEW_GetScrollTime(const TREEVIEW_INFO
*infoPtr
)
1698 return infoPtr
->uScrollTime
;
1702 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1704 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1706 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1708 return uOldScrollTime
;
1713 TREEVIEW_GetImageList(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1720 return (LRESULT
)infoPtr
->himlNormal
;
1723 return (LRESULT
)infoPtr
->himlState
;
1730 #define TVHEIGHT_MIN 16
1731 #define TVHEIGHT_FONT_ADJUST 3 /* 2 for focus border + 1 for margin some apps assume */
1733 /* Compute the natural height for items. */
1735 TREEVIEW_NaturalHeight(const TREEVIEW_INFO
*infoPtr
)
1739 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1742 /* Height is the maximum of:
1743 * 16 (a hack because our fonts are tiny), and
1744 * The text height + border & margin, and
1745 * The size of the normal image list
1747 GetTextMetricsW(hdc
, &tm
);
1748 SelectObject(hdc
, hOldFont
);
1751 height
= TVHEIGHT_MIN
;
1752 if (height
< tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
)
1753 height
= tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
;
1754 if (height
< infoPtr
->normalImageHeight
)
1755 height
= infoPtr
->normalImageHeight
;
1757 /* Round down, unless we support odd ("non even") heights. */
1758 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1765 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, UINT type
, HIMAGELIST himlNew
)
1767 HIMAGELIST himlOld
= 0;
1768 int oldWidth
= infoPtr
->normalImageWidth
;
1769 int oldHeight
= infoPtr
->normalImageHeight
;
1771 TRACE("%u,%p\n", type
, himlNew
);
1776 himlOld
= infoPtr
->himlNormal
;
1777 infoPtr
->himlNormal
= himlNew
;
1780 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1781 &infoPtr
->normalImageHeight
);
1784 infoPtr
->normalImageWidth
= 0;
1785 infoPtr
->normalImageHeight
= 0;
1791 himlOld
= infoPtr
->himlState
;
1792 infoPtr
->himlState
= himlNew
;
1795 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1796 &infoPtr
->stateImageHeight
);
1799 infoPtr
->stateImageWidth
= 0;
1800 infoPtr
->stateImageHeight
= 0;
1806 ERR("unknown imagelist type %u\n", type
);
1809 if (oldWidth
!= infoPtr
->normalImageWidth
||
1810 oldHeight
!= infoPtr
->normalImageHeight
)
1812 BOOL bRecalcVisible
= FALSE
;
1814 if (oldHeight
!= infoPtr
->normalImageHeight
&&
1815 !infoPtr
->bHeightSet
)
1817 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1818 bRecalcVisible
= TRUE
;
1821 if (infoPtr
->normalImageWidth
> MINIMUM_INDENT
&&
1822 infoPtr
->normalImageWidth
!= infoPtr
->uIndent
)
1824 infoPtr
->uIndent
= infoPtr
->normalImageWidth
;
1825 bRecalcVisible
= TRUE
;
1829 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1831 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1832 TREEVIEW_UpdateScrollBars(infoPtr
);
1835 TREEVIEW_Invalidate(infoPtr
, NULL
);
1837 return (LRESULT
)himlOld
;
1841 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1843 INT prevHeight
= infoPtr
->uItemHeight
;
1845 TRACE("new=%d, old=%d\n", newHeight
, prevHeight
);
1846 if (newHeight
== -1)
1848 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1849 infoPtr
->bHeightSet
= FALSE
;
1853 if (newHeight
== 0) newHeight
= 1;
1854 infoPtr
->uItemHeight
= newHeight
;
1855 infoPtr
->bHeightSet
= TRUE
;
1858 /* Round down, unless we support odd ("non even") heights. */
1859 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
) && infoPtr
->uItemHeight
!= 1)
1861 infoPtr
->uItemHeight
&= ~1;
1862 TRACE("after rounding=%d\n", infoPtr
->uItemHeight
);
1865 if (infoPtr
->uItemHeight
!= prevHeight
)
1867 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1868 TREEVIEW_UpdateScrollBars(infoPtr
);
1869 TREEVIEW_Invalidate(infoPtr
, NULL
);
1876 TREEVIEW_GetItemHeight(const TREEVIEW_INFO
*infoPtr
)
1879 return infoPtr
->uItemHeight
;
1884 TREEVIEW_GetFont(const TREEVIEW_INFO
*infoPtr
)
1886 TRACE("%p\n", infoPtr
->hFont
);
1887 return (LRESULT
)infoPtr
->hFont
;
1892 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1896 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1902 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1904 UINT uHeight
= infoPtr
->uItemHeight
;
1906 TRACE("%p %i\n", hFont
, bRedraw
);
1908 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
1910 DeleteObject(infoPtr
->hBoldFont
);
1911 DeleteObject(infoPtr
->hUnderlineFont
);
1912 DeleteObject(infoPtr
->hBoldUnderlineFont
);
1913 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1914 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
1915 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
1917 if (!infoPtr
->bHeightSet
)
1918 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1920 if (uHeight
!= infoPtr
->uItemHeight
)
1921 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1923 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1925 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1926 TREEVIEW_UpdateScrollBars(infoPtr
);
1929 TREEVIEW_Invalidate(infoPtr
, NULL
);
1936 TREEVIEW_GetLineColor(const TREEVIEW_INFO
*infoPtr
)
1939 return (LRESULT
)infoPtr
->clrLine
;
1943 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1945 COLORREF prevColor
= infoPtr
->clrLine
;
1948 infoPtr
->clrLine
= color
;
1949 return (LRESULT
)prevColor
;
1954 TREEVIEW_GetTextColor(const TREEVIEW_INFO
*infoPtr
)
1957 return (LRESULT
)infoPtr
->clrText
;
1961 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1963 COLORREF prevColor
= infoPtr
->clrText
;
1966 infoPtr
->clrText
= color
;
1968 if (infoPtr
->clrText
!= prevColor
)
1969 TREEVIEW_Invalidate(infoPtr
, NULL
);
1971 return (LRESULT
)prevColor
;
1976 TREEVIEW_GetBkColor(const TREEVIEW_INFO
*infoPtr
)
1979 return (LRESULT
)infoPtr
->clrBk
;
1983 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1985 COLORREF prevColor
= infoPtr
->clrBk
;
1988 infoPtr
->clrBk
= newColor
;
1990 if (newColor
!= prevColor
)
1991 TREEVIEW_Invalidate(infoPtr
, NULL
);
1993 return (LRESULT
)prevColor
;
1998 TREEVIEW_GetInsertMarkColor(const TREEVIEW_INFO
*infoPtr
)
2001 return (LRESULT
)infoPtr
->clrInsertMark
;
2005 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
2007 COLORREF prevColor
= infoPtr
->clrInsertMark
;
2009 TRACE("0x%08x\n", color
);
2010 infoPtr
->clrInsertMark
= color
;
2012 return (LRESULT
)prevColor
;
2017 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
2019 TRACE("%d %p\n", wParam
, item
);
2021 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2024 infoPtr
->insertBeforeorAfter
= wParam
;
2025 infoPtr
->insertMarkItem
= item
;
2027 TREEVIEW_Invalidate(infoPtr
, NULL
);
2033 /************************************************************************
2034 * Some serious braindamage here. lParam is a pointer to both the
2035 * input HTREEITEM and the output RECT.
2038 TREEVIEW_GetItemRect(const TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
2040 TREEVIEW_ITEM
*item
;
2041 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
2049 if (!TREEVIEW_ValidItem(infoPtr
, item
) || !ISVISIBLE(item
))
2053 * If wParam is TRUE return the text size otherwise return
2054 * the whole item size
2058 /* Windows does not send TVN_GETDISPINFO here. */
2060 lpRect
->top
= item
->rect
.top
;
2061 lpRect
->bottom
= item
->rect
.bottom
;
2063 lpRect
->left
= item
->textOffset
;
2064 if (!item
->textWidth
)
2065 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2067 lpRect
->right
= item
->textOffset
+ item
->textWidth
+ 4;
2071 *lpRect
= item
->rect
;
2074 TRACE("%s [%s]\n", fTextRect
? "text" : "item", wine_dbgstr_rect(lpRect
));
2079 static inline LRESULT
2080 TREEVIEW_GetVisibleCount(const TREEVIEW_INFO
*infoPtr
)
2082 /* Surprise! This does not take integral height into account. */
2083 TRACE("client=%d, item=%d\n", infoPtr
->clientHeight
, infoPtr
->uItemHeight
);
2084 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2089 TREEVIEW_GetItemT(const TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2091 TREEVIEW_ITEM
*item
= tvItem
->hItem
;
2093 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2095 BOOL valid_item
= FALSE
;
2096 if (!item
) return FALSE
;
2100 infoPtr
= item
->infoPtr
;
2101 TRACE("got item from different tree %p, called from %p\n", item
->infoPtr
, infoPtr
);
2102 valid_item
= TREEVIEW_ValidItem(infoPtr
, item
);
2108 if (!valid_item
) return FALSE
;
2111 TREEVIEW_UpdateDispInfo(infoPtr
, item
, tvItem
->mask
);
2113 if (tvItem
->mask
& TVIF_CHILDREN
)
2115 if (item
->cChildren
==I_CHILDRENCALLBACK
)
2116 FIXME("I_CHILDRENCALLBACK not supported\n");
2117 tvItem
->cChildren
= item
->cChildren
;
2120 if (tvItem
->mask
& TVIF_HANDLE
)
2121 tvItem
->hItem
= item
;
2123 if (tvItem
->mask
& TVIF_IMAGE
)
2124 tvItem
->iImage
= item
->iImage
;
2126 if (tvItem
->mask
& TVIF_INTEGRAL
)
2127 tvItem
->iIntegral
= item
->iIntegral
;
2129 /* undocumented: (mask & TVIF_PARAM) ignored and lParam is always set */
2130 tvItem
->lParam
= item
->lParam
;
2132 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2133 tvItem
->iSelectedImage
= item
->iSelectedImage
;
2135 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
2136 tvItem
->iExpandedImage
= item
->iExpandedImage
;
2138 /* undocumented: stateMask and (state & TVIF_STATE) ignored, so state is always set */
2139 tvItem
->state
= item
->state
;
2141 if (tvItem
->mask
& TVIF_TEXT
)
2143 if (item
->pszText
== NULL
)
2145 if (tvItem
->cchTextMax
> 0)
2146 tvItem
->pszText
[0] = '\0';
2150 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2152 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2153 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2157 lstrcpynW(tvItem
->pszText
, item
->pszText
, tvItem
->cchTextMax
);
2162 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2164 tvItem
->pszText
= (LPWSTR
)LPSTR_TEXTCALLBACKA
;
2165 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2169 WideCharToMultiByte(CP_ACP
, 0, item
->pszText
, -1,
2170 (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, NULL
, NULL
);
2175 if (tvItem
->mask
& TVIF_STATEEX
)
2177 FIXME("Extended item state not supported, returning 0.\n");
2178 tvItem
->uStateEx
= 0;
2181 TRACE("item <%p>, txt %p, img %d, mask 0x%x\n",
2182 item
, tvItem
->pszText
, tvItem
->iImage
, tvItem
->mask
);
2187 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2188 * which is wrong. */
2190 TREEVIEW_SetItemT(TREEVIEW_INFO
*infoPtr
, const TVITEMEXW
*tvItem
, BOOL isW
)
2192 TREEVIEW_ITEM
*item
;
2193 TREEVIEW_ITEM originalItem
;
2195 item
= tvItem
->hItem
;
2197 TRACE("item %d, mask 0x%x\n", TREEVIEW_GetItemIndex(infoPtr
, item
),
2200 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2203 /* store the original item values */
2204 originalItem
= *item
;
2206 if (!TREEVIEW_DoSetItemT(infoPtr
, item
, tvItem
, isW
))
2209 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2210 if ((tvItem
->mask
& TVIF_TEXT
2211 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2214 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_TEXT
);
2215 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2218 if (tvItem
->mask
!= 0 && ISVISIBLE(item
))
2220 /* The refresh updates everything, but we can't wait until then. */
2221 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
2223 /* if any of the item's values changed and it's not a callback, redraw the item */
2224 if (item_changed(&originalItem
, item
, tvItem
))
2226 if (tvItem
->mask
& TVIF_INTEGRAL
)
2228 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
2229 TREEVIEW_UpdateScrollBars(infoPtr
);
2231 TREEVIEW_Invalidate(infoPtr
, NULL
);
2235 TREEVIEW_UpdateScrollBars(infoPtr
);
2236 TREEVIEW_Invalidate(infoPtr
, item
);
2245 TREEVIEW_GetItemState(const TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, UINT mask
)
2249 if (!item
|| !TREEVIEW_ValidItem(infoPtr
, item
))
2252 return (item
->state
& mask
);
2256 TREEVIEW_GetNextItem(const TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM item
)
2258 TREEVIEW_ITEM
*retval
;
2262 /* handle all the global data here */
2265 case TVGN_CHILD
: /* Special case: child of 0 is root */
2270 retval
= infoPtr
->root
->firstChild
;
2274 retval
= infoPtr
->selectedItem
;
2277 case TVGN_FIRSTVISIBLE
:
2278 retval
= infoPtr
->firstVisible
;
2281 case TVGN_DROPHILITE
:
2282 retval
= infoPtr
->dropItem
;
2285 case TVGN_LASTVISIBLE
:
2286 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2292 TRACE("flags:0x%x, returns %p\n", which
, retval
);
2293 return (LRESULT
)retval
;
2296 if (item
== TVI_ROOT
) item
= infoPtr
->root
;
2298 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2304 retval
= item
->nextSibling
;
2307 retval
= item
->prevSibling
;
2310 retval
= (item
->parent
!= infoPtr
->root
) ? item
->parent
: NULL
;
2313 retval
= item
->firstChild
;
2315 case TVGN_NEXTVISIBLE
:
2316 retval
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2318 case TVGN_PREVIOUSVISIBLE
:
2319 retval
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
2322 TRACE("Unknown msg 0x%x, item %p\n", which
, item
);
2326 TRACE("flags: 0x%x, item %p;returns %p\n", which
, item
, retval
);
2327 return (LRESULT
)retval
;
2332 TREEVIEW_GetCount(const TREEVIEW_INFO
*infoPtr
)
2334 TRACE(" %d\n", infoPtr
->uNumItems
);
2335 return (LRESULT
)infoPtr
->uNumItems
;
2339 TREEVIEW_ToggleItemState(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2341 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2343 static const unsigned int state_table
[] = { 0, 2, 1 };
2347 state
= STATEIMAGEINDEX(item
->state
);
2348 TRACE("state: 0x%x\n", state
);
2349 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2352 state
= state_table
[state
];
2354 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2356 TRACE("state: 0x%x\n", state
);
2357 TREEVIEW_Invalidate(infoPtr
, item
);
2362 /* Painting *************************************************************/
2364 /* Draw the lines and expand button for an item. Also draws one section
2365 * of the line from item's parent to item's parent's next sibling. */
2367 TREEVIEW_DrawItemLines(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const TREEVIEW_ITEM
*item
)
2369 LONG centerx
, centery
;
2370 BOOL lar
= ((infoPtr
->dwStyle
2371 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2374 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2376 if (!lar
&& item
->iLevel
== 0)
2379 hbr
= CreateSolidBrush(clrBk
);
2380 hbrOld
= SelectObject(hdc
, hbr
);
2382 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2383 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2385 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2387 HPEN hOldPen
, hNewPen
;
2391 /* Get a dotted grey pen */
2392 lb
.lbStyle
= BS_SOLID
;
2393 lb
.lbColor
= GETLINECOLOR(infoPtr
->clrLine
);
2394 hNewPen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, NULL
);
2395 hOldPen
= SelectObject(hdc
, hNewPen
);
2397 /* Make sure the center is on a dot (using +2 instead
2398 * of +1 gives us pixel-by-pixel compat with native) */
2399 centery
= (centery
+ 2) & ~1;
2401 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2402 LineTo(hdc
, centerx
- 1, centery
);
2404 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2406 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2407 LineTo(hdc
, centerx
, centery
);
2410 if (item
->nextSibling
)
2412 MoveToEx(hdc
, centerx
, centery
, NULL
);
2413 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2416 /* Draw the line from our parent to its next sibling. */
2417 parent
= item
->parent
;
2418 while (parent
!= infoPtr
->root
)
2420 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2422 if (parent
->nextSibling
2423 /* skip top-levels unless TVS_LINESATROOT */
2424 && parent
->stateOffset
> parent
->linesOffset
)
2426 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2427 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2430 parent
= parent
->parent
;
2433 SelectObject(hdc
, hOldPen
);
2434 DeleteObject(hNewPen
);
2438 * Display the (+/-) signs
2441 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2443 if (item
->cChildren
)
2445 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
2448 RECT glyphRect
= item
->rect
;
2449 glyphRect
.left
= item
->linesOffset
;
2450 glyphRect
.right
= item
->stateOffset
;
2451 DrawThemeBackground (theme
, hdc
, TVP_GLYPH
,
2452 (item
->state
& TVIS_EXPANDED
) ? GLPS_OPENED
: GLPS_CLOSED
,
2457 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2458 LONG width
= item
->stateOffset
- item
->linesOffset
;
2459 LONG rectsize
= min(height
, width
) / 4;
2460 /* plussize = ceil(rectsize * 3/4) */
2461 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2463 HPEN new_pen
= CreatePen(PS_SOLID
, 0, GETLINECOLOR(infoPtr
->clrLine
));
2464 HPEN old_pen
= SelectObject(hdc
, new_pen
);
2466 Rectangle(hdc
, centerx
- rectsize
- 1, centery
- rectsize
- 1,
2467 centerx
+ rectsize
+ 2, centery
+ rectsize
+ 2);
2469 SelectObject(hdc
, old_pen
);
2470 DeleteObject(new_pen
);
2472 /* draw +/- signs with current text color */
2473 new_pen
= CreatePen(PS_SOLID
, 0, GETTXTCOLOR(infoPtr
->clrText
));
2474 old_pen
= SelectObject(hdc
, new_pen
);
2476 if (height
< 18 || width
< 18)
2478 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2479 LineTo(hdc
, centerx
+ plussize
, centery
);
2481 if (!(item
->state
& TVIS_EXPANDED
) ||
2482 (item
->state
& TVIS_EXPANDPARTIAL
))
2484 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2485 LineTo(hdc
, centerx
, centery
+ plussize
);
2490 Rectangle(hdc
, centerx
- plussize
+ 1, centery
- 1,
2491 centerx
+ plussize
, centery
+ 2);
2493 if (!(item
->state
& TVIS_EXPANDED
) ||
2494 (item
->state
& TVIS_EXPANDPARTIAL
))
2496 Rectangle(hdc
, centerx
- 1, centery
- plussize
+ 1,
2497 centerx
+ 2, centery
+ plussize
);
2498 SetPixel(hdc
, centerx
- 1, centery
, clrBk
);
2499 SetPixel(hdc
, centerx
+ 1, centery
, clrBk
);
2503 SelectObject(hdc
, old_pen
);
2504 DeleteObject(new_pen
);
2508 SelectObject(hdc
, hbrOld
);
2513 TREEVIEW_DrawItem(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*item
)
2517 COLORREF oldTextColor
, oldTextBkColor
;
2519 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2520 NMTVCUSTOMDRAW nmcdhdr
;
2522 TREEVIEW_UpdateDispInfo(infoPtr
, item
, CALLBACK_MASK_ALL
);
2524 /* - If item is drop target or it is selected and window is in focus -
2525 * use blue background (COLOR_HIGHLIGHT).
2526 * - If item is selected, window is not in focus, but it has style
2527 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2528 * - Otherwise - use background color
2530 if ((item
->state
& TVIS_DROPHILITED
) || ((item
== infoPtr
->focusedItem
) && !(item
->state
& TVIS_SELECTED
)) ||
2531 ((item
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
|| item
== infoPtr
->focusedItem
) &&
2532 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2534 if ((item
->state
& TVIS_DROPHILITED
) || inFocus
)
2536 nmcdhdr
.clrTextBk
= comctl32_color
.clrHighlight
;
2537 nmcdhdr
.clrText
= comctl32_color
.clrHighlightText
;
2541 nmcdhdr
.clrTextBk
= comctl32_color
.clrBtnFace
;
2542 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2547 nmcdhdr
.clrTextBk
= GETBKCOLOR(infoPtr
->clrBk
);
2548 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
2549 nmcdhdr
.clrText
= comctl32_color
.clrHighlight
;
2551 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2554 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
2556 /* The custom draw handler can query the text rectangle,
2558 /* should already be known, set to 0 when changed */
2559 if (!item
->textWidth
)
2560 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2564 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2566 cditem
= TREEVIEW_SendCustomDrawItemNotify
2567 (infoPtr
, hdc
, item
, CDDS_ITEMPREPAINT
, &nmcdhdr
);
2568 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2570 if (cditem
& CDRF_SKIPDEFAULT
)
2572 SelectObject(hdc
, hOldFont
);
2577 if (cditem
& CDRF_NEWFONT
)
2578 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2580 if (TREEVIEW_IsFullRowSelect(infoPtr
))
2582 HBRUSH brush
= CreateSolidBrush(nmcdhdr
.clrTextBk
);
2583 FillRect(hdc
, &item
->rect
, brush
);
2584 DeleteObject(brush
);
2587 TREEVIEW_DrawItemLines(infoPtr
, hdc
, item
);
2589 /* Set colors. Custom draw handler can change these so we do this after it. */
2590 oldTextColor
= SetTextColor(hdc
, nmcdhdr
.clrText
);
2591 oldTextBkColor
= SetBkColor(hdc
, nmcdhdr
.clrTextBk
);
2593 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2596 * Display the images associated with this item
2601 /* State images are displayed to the left of the Normal image
2602 * image number is in state; zero should be `display no image'.
2604 imageIndex
= STATEIMAGEINDEX(item
->state
);
2606 if (infoPtr
->himlState
&& imageIndex
)
2608 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2610 centery
- infoPtr
->stateImageHeight
/ 2,
2614 /* Now, draw the normal image; can be either selected,
2615 * non-selected or expanded image.
2618 if ((item
->state
& TVIS_SELECTED
) && (item
->iSelectedImage
>= 0))
2620 /* The item is currently selected */
2621 imageIndex
= item
->iSelectedImage
;
2623 else if ((item
->state
& TVIS_EXPANDED
) && (item
->iExpandedImage
!= (WORD
)I_IMAGENONE
))
2625 /* The item is currently not selected but expanded */
2626 imageIndex
= item
->iExpandedImage
;
2630 /* The item is not selected and not expanded */
2631 imageIndex
= item
->iImage
;
2634 if (infoPtr
->himlNormal
)
2636 UINT style
= item
->state
& TVIS_CUT
? ILD_SELECTED
: ILD_NORMAL
;
2638 style
|= item
->state
& TVIS_OVERLAYMASK
;
2640 ImageList_DrawEx(infoPtr
->himlNormal
, imageIndex
, hdc
,
2641 item
->imageOffset
, centery
- infoPtr
->normalImageHeight
/ 2,
2642 0, 0, infoPtr
->clrBk
, item
->state
& TVIS_CUT
? GETBKCOLOR(infoPtr
->clrBk
) : CLR_DEFAULT
,
2649 * Display the text associated with this item
2652 /* Don't paint item's text if it's being edited */
2653 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= item
))
2661 rcText
.top
= item
->rect
.top
;
2662 rcText
.bottom
= item
->rect
.bottom
;
2663 rcText
.left
= item
->textOffset
;
2664 rcText
.right
= rcText
.left
+ item
->textWidth
+ 4;
2666 TRACE("drawing text %s at (%s)\n",
2667 debugstr_w(item
->pszText
), wine_dbgstr_rect(&rcText
));
2670 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
2672 align
= SetTextAlign(hdc
, TA_LEFT
| TA_TOP
);
2673 ExtTextOutW(hdc
, rcText
.left
+ 2, (rcText
.top
+ rcText
.bottom
- sz
.cy
) / 2,
2674 ETO_CLIPPED
| ETO_OPAQUE
,
2677 lstrlenW(item
->pszText
),
2679 SetTextAlign(hdc
, align
);
2681 /* Draw focus box around the selected item */
2682 if ((item
== infoPtr
->selectedItem
) && inFocus
)
2684 DrawFocusRect(hdc
,&rcText
);
2689 /* Draw insertion mark if necessary */
2691 if (infoPtr
->insertMarkItem
)
2692 TRACE("item:%d,mark:%p\n",
2693 TREEVIEW_GetItemIndex(infoPtr
, item
),
2694 infoPtr
->insertMarkItem
);
2696 if (item
== infoPtr
->insertMarkItem
)
2698 HPEN hNewPen
, hOldPen
;
2702 hNewPen
= CreatePen(PS_SOLID
, 2, GETINSCOLOR(infoPtr
->clrInsertMark
));
2703 hOldPen
= SelectObject(hdc
, hNewPen
);
2705 if (infoPtr
->insertBeforeorAfter
)
2706 offset
= item
->rect
.bottom
- 1;
2708 offset
= item
->rect
.top
+ 1;
2710 left
= item
->textOffset
- 2;
2711 right
= item
->textOffset
+ item
->textWidth
+ 2;
2713 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2714 LineTo(hdc
, left
, offset
+ 4);
2716 MoveToEx(hdc
, left
, offset
, NULL
);
2717 LineTo(hdc
, right
+ 1, offset
);
2719 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2720 LineTo(hdc
, right
, offset
- 4);
2722 SelectObject(hdc
, hOldPen
);
2723 DeleteObject(hNewPen
);
2726 /* Restore the hdc state */
2727 SetTextColor(hdc
, oldTextColor
);
2728 SetBkColor(hdc
, oldTextBkColor
);
2729 SelectObject(hdc
, hOldFont
);
2731 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2733 cditem
= TREEVIEW_SendCustomDrawItemNotify
2734 (infoPtr
, hdc
, item
, CDDS_ITEMPOSTPAINT
, &nmcdhdr
);
2735 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2739 /* Computes treeHeight and treeWidth and updates the scroll bars.
2742 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2744 TREEVIEW_ITEM
*item
;
2745 HWND hwnd
= infoPtr
->hwnd
;
2749 LONG scrollX
= infoPtr
->scrollX
;
2751 infoPtr
->treeWidth
= 0;
2752 infoPtr
->treeHeight
= 0;
2754 /* We iterate through all visible items in order to get the tree height
2756 item
= infoPtr
->root
->firstChild
;
2758 while (item
!= NULL
)
2760 if (ISVISIBLE(item
))
2762 /* actually we draw text at textOffset + 2 */
2763 if (2+item
->textOffset
+item
->textWidth
> infoPtr
->treeWidth
)
2764 infoPtr
->treeWidth
= item
->textOffset
+item
->textWidth
+2;
2766 /* This is scroll-adjusted, but we fix this below. */
2767 infoPtr
->treeHeight
= item
->rect
.bottom
;
2770 item
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2773 /* Fix the scroll adjusted treeHeight and treeWidth. */
2774 if (infoPtr
->root
->firstChild
)
2775 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2777 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2779 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2781 /* Adding one scroll bar may take up enough space that it forces us
2782 * to add the other as well. */
2783 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2787 if (infoPtr
->treeWidth
2788 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2791 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
|| infoPtr
->scrollX
> 0)
2794 if (!vert
&& horz
&& infoPtr
->treeHeight
2795 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2798 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2800 si
.cbSize
= sizeof(SCROLLINFO
);
2801 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2806 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2807 if ( si
.nPage
&& NULL
!= infoPtr
->firstVisible
)
2809 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2810 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2812 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2814 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2815 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2816 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2820 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2821 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2822 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2827 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2828 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2829 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2834 si
.nPage
= infoPtr
->clientWidth
;
2835 si
.nPos
= infoPtr
->scrollX
;
2836 si
.nMax
= infoPtr
->treeWidth
- 1;
2838 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2840 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2844 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2845 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2846 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2848 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2849 TREEVIEW_HScroll(infoPtr
,
2850 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2854 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2855 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2856 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2859 if (infoPtr
->scrollX
!= 0)
2861 TREEVIEW_HScroll(infoPtr
,
2862 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2867 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2871 TREEVIEW_FillBkgnd(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2874 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2876 hBrush
= CreateSolidBrush(clrBk
);
2877 FillRect(hdc
, rc
, hBrush
);
2878 DeleteObject(hBrush
);
2881 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2883 TREEVIEW_EraseBackground(const TREEVIEW_INFO
*infoPtr
, HDC hdc
)
2887 TRACE("%p\n", infoPtr
);
2889 GetClientRect(infoPtr
->hwnd
, &rect
);
2890 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rect
);
2896 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2898 HWND hwnd
= infoPtr
->hwnd
;
2900 TREEVIEW_ITEM
*item
;
2902 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2904 TRACE("empty window\n");
2908 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2911 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2913 ReleaseDC(hwnd
, hdc
);
2917 for (item
= infoPtr
->root
->firstChild
;
2919 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
2921 if (ISVISIBLE(item
))
2923 /* Avoid unneeded calculations */
2924 if (item
->rect
.top
> rect
.bottom
)
2926 if (item
->rect
.bottom
< rect
.top
)
2929 TREEVIEW_DrawItem(infoPtr
, hdc
, item
);
2933 TREEVIEW_UpdateScrollBars(infoPtr
);
2935 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2937 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2941 TREEVIEW_InvalidateItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2943 if (item
) InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2947 TREEVIEW_Invalidate(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2950 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2952 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2956 TREEVIEW_InitCheckboxes(TREEVIEW_INFO
*infoPtr
)
2959 HBITMAP hbm
, hbmOld
;
2963 infoPtr
->himlState
= ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
2965 hdcScreen
= GetDC(0);
2967 hdc
= CreateCompatibleDC(hdcScreen
);
2968 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
2969 hbmOld
= SelectObject(hdc
, hbm
);
2971 SetRect(&rc
, 0, 0, 48, 16);
2972 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
2974 SetRect(&rc
, 18, 2, 30, 14);
2975 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2976 DFCS_BUTTONCHECK
|DFCS_FLAT
);
2978 SetRect(&rc
, 34, 2, 46, 14);
2979 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2980 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
2982 SelectObject(hdc
, hbmOld
);
2983 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
2984 comctl32_color
.clrWindow
);
2985 TRACE("checkbox index %d\n", nIndex
);
2989 ReleaseDC(0, hdcScreen
);
2991 infoPtr
->stateImageWidth
= 16;
2992 infoPtr
->stateImageHeight
= 16;
2996 TREEVIEW_ResetImageStateIndex(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2998 TREEVIEW_ITEM
*child
= item
->firstChild
;
3000 item
->state
&= ~TVIS_STATEIMAGEMASK
;
3001 item
->state
|= INDEXTOSTATEIMAGEMASK(1);
3005 TREEVIEW_ITEM
*next
= child
->nextSibling
;
3006 TREEVIEW_ResetImageStateIndex(infoPtr
, child
);
3012 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, HDC hdc_ref
)
3018 TRACE("(%p %p)\n", infoPtr
, hdc_ref
);
3020 if ((infoPtr
->dwStyle
& TVS_CHECKBOXES
) && !infoPtr
->himlState
)
3022 TREEVIEW_InitCheckboxes(infoPtr
);
3023 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
3025 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
3026 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
3027 TREEVIEW_UpdateScrollBars(infoPtr
);
3028 TREEVIEW_Invalidate(infoPtr
, NULL
);
3034 GetClientRect(infoPtr
->hwnd
, &rc
);
3035 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
3039 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
3042 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
3045 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
3046 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
3049 EndPaint(infoPtr
->hwnd
, &ps
);
3055 TREEVIEW_PrintClient(TREEVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
3057 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
3059 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwnd
))
3062 if (options
& PRF_ERASEBKGND
)
3063 TREEVIEW_EraseBackground(infoPtr
, hdc
);
3065 if (options
& PRF_CLIENT
)
3068 GetClientRect(infoPtr
->hwnd
, &rc
);
3069 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
3075 /* Sorting **************************************************************/
3077 /***************************************************************************
3078 * Forward the DPA local callback to the treeview owner callback
3081 TREEVIEW_CallBackCompare(const TREEVIEW_ITEM
*first
, const TREEVIEW_ITEM
*second
,
3082 const TVSORTCB
*pCallBackSort
)
3084 /* Forward the call to the client-defined callback */
3085 return pCallBackSort
->lpfnCompare(first
->lParam
,
3087 pCallBackSort
->lParam
);
3090 /***************************************************************************
3091 * Treeview native sort routine: sort on item text.
3094 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
3095 const TREEVIEW_INFO
*infoPtr
)
3097 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
3098 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
3100 if(first
->pszText
&& second
->pszText
)
3101 return lstrcmpiW(first
->pszText
, second
->pszText
);
3102 else if(first
->pszText
)
3104 else if(second
->pszText
)
3110 /* Returns the number of physical children belonging to item. */
3112 TREEVIEW_CountChildren(const TREEVIEW_ITEM
*item
)
3117 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
3123 /* Returns a DPA containing a pointer to each physical child of item in
3124 * sibling order. If item has no children, an empty DPA is returned. */
3126 TREEVIEW_BuildChildDPA(const TREEVIEW_ITEM
*item
)
3130 HDPA list
= DPA_Create(8);
3131 if (list
== 0) return NULL
;
3133 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
3135 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
3145 /***************************************************************************
3146 * Setup the treeview structure with regards of the sort method
3147 * and sort the children of the TV item specified in lParam
3148 * fRecurse: currently unused. Should be zero.
3149 * parent: if pSort!=NULL, should equal pSort->hParent.
3150 * otherwise, item which child items are to be sorted.
3151 * pSort: sort method info. if NULL, sort on item text.
3152 * if non-NULL, sort on item's lParam content, and let the
3153 * application decide what that means. See also TVM_SORTCHILDRENCB.
3157 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, HTREEITEM parent
,
3161 PFNDPACOMPARE pfnCompare
;
3164 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
3165 if (parent
== TVI_ROOT
|| parent
== NULL
)
3166 parent
= infoPtr
->root
;
3168 /* Check for a valid handle to the parent item */
3169 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
3171 ERR("invalid item hParent=%p\n", parent
);
3177 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
3178 lpCompare
= (LPARAM
)pSort
;
3182 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
3183 lpCompare
= (LPARAM
)infoPtr
;
3186 cChildren
= TREEVIEW_CountChildren(parent
);
3188 /* Make sure there is something to sort */
3191 /* TREEVIEW_ITEM rechaining */
3194 HTREEITEM nextItem
= 0;
3195 HTREEITEM prevItem
= 0;
3197 HDPA sortList
= TREEVIEW_BuildChildDPA(parent
);
3199 if (sortList
== NULL
)
3202 /* let DPA sort the list */
3203 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
3205 /* The order of DPA entries has been changed, so fixup the
3206 * nextSibling and prevSibling pointers. */
3208 item
= DPA_GetPtr(sortList
, count
++);
3209 while ((nextItem
= DPA_GetPtr(sortList
, count
++)) != NULL
)
3211 /* link the two current item together */
3212 item
->nextSibling
= nextItem
;
3213 nextItem
->prevSibling
= item
;
3215 if (prevItem
== NULL
)
3217 /* this is the first item, update the parent */
3218 parent
->firstChild
= item
;
3219 item
->prevSibling
= NULL
;
3223 /* fix the back chaining */
3224 item
->prevSibling
= prevItem
;
3227 /* get ready for the next one */
3232 /* the last item is pointed to by item and never has a sibling */
3233 item
->nextSibling
= NULL
;
3234 parent
->lastChild
= item
;
3236 DPA_Destroy(sortList
);
3238 TREEVIEW_VerifyTree(infoPtr
);
3240 if (parent
->state
& TVIS_EXPANDED
)
3242 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3244 if (parent
== infoPtr
->root
)
3245 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3247 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3249 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3251 TREEVIEW_ITEM
*item
;
3253 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3254 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3256 if (item
->visibleOrder
== visOrder
)
3260 if (!item
) item
= parent
->firstChild
;
3261 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3264 TREEVIEW_Invalidate(infoPtr
, NULL
);
3273 /***************************************************************************
3274 * Setup the treeview structure with regards of the sort method
3275 * and sort the children of the TV item specified in lParam
3278 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, LPTVSORTCB pSort
)
3280 return TREEVIEW_Sort(infoPtr
, pSort
->hParent
, pSort
);
3284 /***************************************************************************
3285 * Sort the children of the TV item specified in lParam.
3288 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3290 return TREEVIEW_Sort(infoPtr
, (HTREEITEM
)lParam
, NULL
);
3294 /* Expansion/Collapse ***************************************************/
3297 TREEVIEW_SendExpanding(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3300 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3301 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3302 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3307 TREEVIEW_SendExpanded(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3310 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3311 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3312 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3317 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3318 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3320 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3321 BOOL bRemoveChildren
, BOOL bUser
)
3323 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3324 BOOL bSetSelection
, bSetFirstVisible
;
3326 LONG scrollDist
= 0;
3327 TREEVIEW_ITEM
*nextItem
= NULL
, *tmpItem
;
3330 TRACE("TVE_COLLAPSE %p %s\n", item
, TREEVIEW_ItemName(item
));
3332 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3336 TREEVIEW_SendExpanding(infoPtr
, item
, action
);
3338 if (item
->firstChild
== NULL
)
3341 wasExpanded
= (item
->state
& TVIS_EXPANDED
) != 0;
3342 item
->state
&= ~TVIS_EXPANDED
;
3344 if (wasExpanded
&& bUser
)
3345 TREEVIEW_SendExpanded(infoPtr
, item
, action
);
3347 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3348 && TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
));
3350 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3351 && TREEVIEW_IsChildOf(item
, infoPtr
->firstVisible
));
3356 if (tmpItem
->nextSibling
)
3358 nextItem
= tmpItem
->nextSibling
;
3361 tmpItem
= tmpItem
->parent
;
3365 scrollDist
= nextItem
->rect
.top
;
3367 if (bRemoveChildren
)
3369 INT old_cChildren
= item
->cChildren
;
3370 TRACE("TVE_COLLAPSERESET\n");
3371 item
->state
&= ~TVIS_EXPANDEDONCE
;
3372 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
3373 item
->cChildren
= old_cChildren
;
3378 if (item
->firstChild
)
3380 TREEVIEW_ITEM
*i
, *sibling
;
3382 sibling
= TREEVIEW_GetNextListItem(infoPtr
, item
);
3384 for (i
= item
->firstChild
; i
!= sibling
;
3385 i
= TREEVIEW_GetNextListItem(infoPtr
, i
))
3387 i
->visibleOrder
= -1;
3391 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3394 scrollDist
= -(scrollDist
- nextItem
->rect
.top
);
3398 /* Don't call DoSelectItem, it sends notifications. */
3399 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3400 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3401 item
->state
|= TVIS_SELECTED
;
3402 infoPtr
->selectedItem
= item
;
3405 TREEVIEW_UpdateScrollBars(infoPtr
);
3407 scrollRect
.left
= 0;
3408 scrollRect
.right
= infoPtr
->clientWidth
;
3409 scrollRect
.bottom
= infoPtr
->clientHeight
;
3413 scrollRect
.top
= nextItem
->rect
.top
;
3415 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, &scrollRect
,
3416 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3417 TREEVIEW_Invalidate(infoPtr
, item
);
3419 scrollRect
.top
= item
->rect
.top
;
3420 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, TRUE
);
3423 TREEVIEW_SetFirstVisible(infoPtr
,
3424 bSetFirstVisible
? item
: infoPtr
->firstVisible
,
3431 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3432 BOOL partial
, BOOL user
)
3435 LONG orgNextTop
= 0;
3437 TREEVIEW_ITEM
*nextItem
, *tmpItem
;
3438 BOOL sendsNotifications
;
3440 TRACE("(%p, %p, partial=%d, %d)\n", infoPtr
, item
, partial
, user
);
3442 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3445 tmpItem
= item
; nextItem
= NULL
;
3448 if (tmpItem
->nextSibling
)
3450 nextItem
= tmpItem
->nextSibling
;
3453 tmpItem
= tmpItem
->parent
;
3457 orgNextTop
= nextItem
->rect
.top
;
3459 TRACE("TVE_EXPAND %p %s\n", item
, TREEVIEW_ItemName(item
));
3461 sendsNotifications
= user
|| ((item
->cChildren
!= 0) &&
3462 !(item
->state
& TVIS_EXPANDEDONCE
));
3463 if (sendsNotifications
)
3465 if (!TREEVIEW_SendExpanding(infoPtr
, item
, TVE_EXPAND
))
3467 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3471 if (!item
->firstChild
)
3474 item
->state
|= TVIS_EXPANDED
;
3477 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3479 if (ISVISIBLE(item
))
3481 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3482 TREEVIEW_UpdateSubTree(infoPtr
, item
);
3483 TREEVIEW_UpdateScrollBars(infoPtr
);
3485 scrollRect
.left
= 0;
3486 scrollRect
.bottom
= infoPtr
->treeHeight
;
3487 scrollRect
.right
= infoPtr
->clientWidth
;
3490 scrollDist
= nextItem
->rect
.top
- orgNextTop
;
3491 scrollRect
.top
= orgNextTop
;
3493 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3494 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3495 TREEVIEW_Invalidate (infoPtr
, item
);
3497 scrollRect
.top
= item
->rect
.top
;
3498 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, FALSE
);
3501 /* Scroll up so that as many children as possible are visible.
3502 * This fails when expanding causes an HScroll bar to appear, but we
3503 * don't know that yet, so the last item is obscured. */
3504 if (item
->firstChild
!= NULL
)
3506 int nChildren
= item
->lastChild
->visibleOrder
3507 - item
->firstChild
->visibleOrder
+ 1;
3509 int visible_pos
= item
->visibleOrder
3510 - infoPtr
->firstVisible
->visibleOrder
;
3512 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3514 if (visible_pos
> 0 && nChildren
> rows_below
)
3516 int scroll
= nChildren
- rows_below
;
3518 if (scroll
> visible_pos
)
3519 scroll
= visible_pos
;
3523 TREEVIEW_ITEM
*newFirstVisible
3524 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3528 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3534 if (sendsNotifications
) {
3535 TREEVIEW_SendExpanded(infoPtr
, item
, TVE_EXPAND
);
3536 item
->state
|= TVIS_EXPANDEDONCE
;
3542 /* Handler for TVS_SINGLEEXPAND behaviour. Used on response
3543 to mouse messages and TVM_SELECTITEM.
3545 selection - previously selected item, used to collapse a part of a tree
3546 item - new selected item
3548 static void TREEVIEW_SingleExpand(TREEVIEW_INFO
*infoPtr
,
3549 HTREEITEM selection
, HTREEITEM item
)
3551 TREEVIEW_ITEM
*prev
, *curr
;
3553 if ((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) == 0 || infoPtr
->hwndEdit
|| !item
) return;
3555 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
3558 * Close the previous item and its ancestors as long as they are not
3559 * ancestors of the current item
3561 for (prev
= selection
; prev
&& TREEVIEW_ValidItem(infoPtr
, prev
); prev
= prev
->parent
)
3563 for (curr
= item
; curr
&& TREEVIEW_ValidItem(infoPtr
, curr
); curr
= curr
->parent
)
3568 TREEVIEW_Collapse(infoPtr
, prev
, FALSE
, TRUE
);
3573 * Expand the current item
3575 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3579 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, BOOL user
)
3581 TRACE("item=%p, user=%d\n", item
, user
);
3583 if (item
->state
& TVIS_EXPANDED
)
3584 return TREEVIEW_Collapse(infoPtr
, item
, FALSE
, user
);
3586 return TREEVIEW_Expand(infoPtr
, item
, FALSE
, user
);
3590 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3592 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3594 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3596 if (TREEVIEW_HasChildren(infoPtr
, item
))
3597 TREEVIEW_ExpandAll(infoPtr
, item
);
3601 /* Note:If the specified item is the child of a collapsed parent item,
3602 the parent's list of child items is (recursively) expanded to reveal the
3603 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3604 know if it also applies here.
3608 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM item
)
3610 if (!TREEVIEW_ValidItem(infoPtr
, item
))
3613 TRACE("For (%s) item:%d, flags 0x%x, state:%d\n",
3614 TREEVIEW_ItemName(item
), TREEVIEW_GetItemIndex(infoPtr
, item
),
3617 switch (flag
& TVE_TOGGLE
)
3620 return TREEVIEW_Collapse(infoPtr
, item
, flag
& TVE_COLLAPSERESET
,
3624 return TREEVIEW_Expand(infoPtr
, item
, flag
& TVE_EXPANDPARTIAL
,
3628 return TREEVIEW_Toggle(infoPtr
, item
, FALSE
);
3635 /* Hit-Testing **********************************************************/
3637 static TREEVIEW_ITEM
*
3638 TREEVIEW_HitTestPoint(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3640 TREEVIEW_ITEM
*item
;
3643 if (!infoPtr
->firstVisible
)
3646 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3648 for (item
= infoPtr
->firstVisible
; item
!= NULL
;
3649 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3651 if (row
>= item
->visibleOrder
3652 && row
< item
->visibleOrder
+ item
->iIntegral
)
3659 static TREEVIEW_ITEM
*
3660 TREEVIEW_HitTest(const TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3662 TREEVIEW_ITEM
*item
;
3668 GetClientRect(infoPtr
->hwnd
, &rect
);
3675 status
|= TVHT_TOLEFT
;
3677 else if (x
> rect
.right
)
3679 status
|= TVHT_TORIGHT
;
3684 status
|= TVHT_ABOVE
;
3686 else if (y
> rect
.bottom
)
3688 status
|= TVHT_BELOW
;
3693 lpht
->flags
= status
;
3697 item
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3700 lpht
->flags
= TVHT_NOWHERE
;
3704 if (x
>= item
->textOffset
+ item
->textWidth
)
3706 lpht
->flags
= TVHT_ONITEMRIGHT
;
3708 else if (x
>= item
->textOffset
)
3710 lpht
->flags
= TVHT_ONITEMLABEL
;
3712 else if (x
>= item
->imageOffset
)
3714 lpht
->flags
= TVHT_ONITEMICON
;
3716 else if (x
>= item
->stateOffset
)
3718 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3720 else if (x
>= item
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3722 lpht
->flags
= TVHT_ONITEMBUTTON
;
3726 lpht
->flags
= TVHT_ONITEMINDENT
;
3730 TRACE("(%d,%d):result 0x%x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3735 /* Item Label Editing ***************************************************/
3738 TREEVIEW_GetEditControl(const TREEVIEW_INFO
*infoPtr
)
3740 return (LRESULT
)infoPtr
->hwndEdit
;
3743 static LRESULT CALLBACK
3744 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3746 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3747 BOOL bCancel
= FALSE
;
3753 TRACE("WM_PAINT start\n");
3754 rc
= CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3756 TRACE("WM_PAINT done\n");
3760 if (infoPtr
->bIgnoreEditKillFocus
)
3766 WNDPROC editProc
= infoPtr
->wpEditOrig
;
3767 infoPtr
->wpEditOrig
= 0;
3768 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
3769 return CallWindowProcW(editProc
, hwnd
, uMsg
, wParam
, lParam
);
3773 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3776 if (wParam
== VK_ESCAPE
)
3781 else if (wParam
== VK_RETURN
)
3788 return CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3791 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3792 /* eg. Using a messagebox */
3794 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3795 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3796 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3802 /* should handle edit control messages here */
3805 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3807 TRACE("code=0x%x, id=0x%x, handle=0x%lx\n", HIWORD(wParam
), LOWORD(wParam
), lParam
);
3809 switch (HIWORD(wParam
))
3814 * Adjust the edit window size
3817 TREEVIEW_ITEM
*editItem
= infoPtr
->editItem
;
3818 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3820 HFONT hFont
, hOldFont
= 0;
3822 TRACE("edit=%p\n", infoPtr
->hwndEdit
);
3824 if (!IsWindow(infoPtr
->hwndEdit
) || !hdc
) return FALSE
;
3826 infoPtr
->bLabelChanged
= TRUE
;
3828 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
3830 /* Select font to get the right dimension of the string */
3831 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3835 hOldFont
= SelectObject(hdc
, hFont
);
3838 if (GetTextExtentPoint32W(hdc
, buffer
, strlenW(buffer
), &sz
))
3840 TEXTMETRICW textMetric
;
3842 /* Add Extra spacing for the next character */
3843 GetTextMetricsW(hdc
, &textMetric
);
3844 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3846 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3848 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3850 SetWindowPos(infoPtr
->hwndEdit
,
3855 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3856 SWP_NOMOVE
| SWP_DRAWFRAME
);
3861 SelectObject(hdc
, hOldFont
);
3864 ReleaseDC(infoPtr
->hwnd
, hdc
);
3868 /* apparently we should respect passed handle value */
3869 if (infoPtr
->hwndEdit
!= (HWND
)lParam
) return FALSE
;
3871 TREEVIEW_EndEditLabelNow(infoPtr
, FALSE
);
3875 return SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3882 TREEVIEW_EditLabel(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3884 HWND hwnd
= infoPtr
->hwnd
;
3887 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
);
3890 TEXTMETRICW textMetric
;
3892 TRACE("%p %p\n", hwnd
, hItem
);
3893 if (!(infoPtr
->dwStyle
& TVS_EDITLABELS
))
3896 if (!TREEVIEW_ValidItem(infoPtr
, hItem
))
3899 if (infoPtr
->hwndEdit
)
3900 return infoPtr
->hwndEdit
;
3902 infoPtr
->bLabelChanged
= FALSE
;
3904 /* make edit item visible */
3905 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3907 TREEVIEW_UpdateDispInfo(infoPtr
, hItem
, TVIF_TEXT
);
3910 /* Select the font to get appropriate metric dimensions */
3911 if (infoPtr
->hFont
!= 0)
3913 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3916 /* Get string length in pixels */
3918 GetTextExtentPoint32W(hdc
, hItem
->pszText
, strlenW(hItem
->pszText
),
3921 GetTextExtentPoint32A(hdc
, "", 0, &sz
);
3923 /* Add Extra spacing for the next character */
3924 GetTextMetricsW(hdc
, &textMetric
);
3925 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3927 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3928 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- hItem
->textOffset
+ 2);
3930 if (infoPtr
->hFont
!= 0)
3932 SelectObject(hdc
, hOldFont
);
3935 ReleaseDC(hwnd
, hdc
);
3937 infoPtr
->editItem
= hItem
;
3939 hwndEdit
= CreateWindowExW(WS_EX_LEFT
,
3942 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3943 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3944 ES_LEFT
, hItem
->textOffset
- 2,
3945 hItem
->rect
.top
- 1, sz
.cx
+ 3,
3946 hItem
->rect
.bottom
-
3947 hItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3948 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3950 infoPtr
->hwndEdit
= hwndEdit
;
3952 /* Get a 2D border. */
3953 SetWindowLongW(hwndEdit
, GWL_EXSTYLE
,
3954 GetWindowLongW(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3955 SetWindowLongW(hwndEdit
, GWL_STYLE
,
3956 GetWindowLongW(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3958 SendMessageW(hwndEdit
, WM_SETFONT
,
3959 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, hItem
), FALSE
);
3961 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
,
3963 TREEVIEW_Edit_SubclassProc
);
3965 SetWindowTextW(hwndEdit
, hItem
->pszText
);
3967 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, hItem
))
3969 DestroyWindow(hwndEdit
);
3970 infoPtr
->hwndEdit
= 0;
3971 infoPtr
->editItem
= NULL
;
3976 SendMessageW(hwndEdit
, EM_SETSEL
, 0, -1);
3977 ShowWindow(hwndEdit
, SW_SHOW
);
3984 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3986 TREEVIEW_ITEM
*editedItem
= infoPtr
->editItem
;
3989 WCHAR tmpText
[1024] = { '\0' };
3990 WCHAR
*newText
= tmpText
;
3993 if (!IsWindow(infoPtr
->hwndEdit
)) return FALSE
;
3996 tvdi
.item
.hItem
= editedItem
;
3997 tvdi
.item
.state
= editedItem
->state
;
3998 tvdi
.item
.lParam
= editedItem
->lParam
;
4002 if (!infoPtr
->bNtfUnicode
)
4003 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, (LPSTR
)tmpText
, 1023);
4005 iLength
= GetWindowTextW(infoPtr
->hwndEdit
, tmpText
, 1023);
4007 if (iLength
>= 1023)
4009 ERR("Insufficient space to retrieve new item label\n");
4012 tvdi
.item
.mask
= TVIF_TEXT
;
4013 tvdi
.item
.pszText
= tmpText
;
4014 tvdi
.item
.cchTextMax
= iLength
+ 1;
4018 tvdi
.item
.pszText
= NULL
;
4019 tvdi
.item
.cchTextMax
= 0;
4022 bCommit
= TREEVIEW_SendRealNotify(infoPtr
, TVN_ENDLABELEDITW
, &tvdi
.hdr
);
4024 if (!bCancel
&& bCommit
) /* Apply the changes */
4026 if (!infoPtr
->bNtfUnicode
)
4028 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, NULL
, 0 );
4029 newText
= Alloc(len
* sizeof(WCHAR
));
4030 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, newText
, len
);
4034 if (strcmpW(newText
, editedItem
->pszText
) != 0)
4036 WCHAR
*ptr
= ReAlloc(editedItem
->pszText
, sizeof(WCHAR
)*(iLength
+ 1));
4039 ERR("OutOfMemory, cannot allocate space for label\n");
4040 if(newText
!= tmpText
) Free(newText
);
4041 DestroyWindow(infoPtr
->hwndEdit
);
4042 infoPtr
->hwndEdit
= 0;
4043 infoPtr
->editItem
= NULL
;
4048 editedItem
->pszText
= ptr
;
4049 editedItem
->cchTextMax
= iLength
+ 1;
4050 strcpyW(editedItem
->pszText
, newText
);
4051 TREEVIEW_ComputeTextWidth(infoPtr
, editedItem
, 0);
4054 if(newText
!= tmpText
) Free(newText
);
4057 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
4058 DestroyWindow(infoPtr
->hwndEdit
);
4059 infoPtr
->hwndEdit
= 0;
4060 infoPtr
->editItem
= NULL
;
4065 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4067 if (wParam
!= TV_EDIT_TIMER
)
4069 ERR("got unknown timer\n");
4073 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4074 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
4076 TREEVIEW_EditLabel(infoPtr
, infoPtr
->selectedItem
);
4082 /* Mouse Tracking/Drag **************************************************/
4084 /***************************************************************************
4085 * This is quite unusual piece of code, but that's how it's implemented in
4089 TREEVIEW_TrackMouse(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
4091 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
4092 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
4096 r
.top
= pt
.y
- cyDrag
;
4097 r
.left
= pt
.x
- cxDrag
;
4098 r
.bottom
= pt
.y
+ cyDrag
;
4099 r
.right
= pt
.x
+ cxDrag
;
4101 SetCapture(infoPtr
->hwnd
);
4105 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
4107 if (msg
.message
== WM_MOUSEMOVE
)
4109 pt
.x
= (short)LOWORD(msg
.lParam
);
4110 pt
.y
= (short)HIWORD(msg
.lParam
);
4111 if (PtInRect(&r
, pt
))
4119 else if (msg
.message
>= WM_LBUTTONDOWN
&&
4120 msg
.message
<= WM_RBUTTONDBLCLK
)
4125 DispatchMessageW(&msg
);
4128 if (GetCapture() != infoPtr
->hwnd
)
4138 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4140 TREEVIEW_ITEM
*item
;
4144 SetFocus(infoPtr
->hwnd
);
4146 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4148 /* If there is pending 'edit label' event - kill it now */
4149 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4152 hit
.pt
.x
= (short)LOWORD(lParam
);
4153 hit
.pt
.y
= (short)HIWORD(lParam
);
4155 item
= TREEVIEW_HitTest(infoPtr
, &hit
);
4158 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, item
));
4160 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
4164 case TVHT_ONITEMRIGHT
:
4165 /* FIXME: we should not have sent NM_DBLCLK in this case. */
4168 case TVHT_ONITEMINDENT
:
4169 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
4175 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
4176 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
4178 while (item
->iLevel
> level
)
4180 item
= item
->parent
;
4186 case TVHT_ONITEMLABEL
:
4187 case TVHT_ONITEMICON
:
4188 case TVHT_ONITEMBUTTON
:
4189 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4192 case TVHT_ONITEMSTATEICON
:
4193 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4194 TREEVIEW_ToggleItemState(infoPtr
, item
);
4196 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4205 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4207 BOOL do_track
, do_select
, bDoLabelEdit
;
4208 HWND hwnd
= infoPtr
->hwnd
;
4211 /* If Edit control is active - kill it and return.
4212 * The best way to do it is to set focus to itself.
4213 * Edit control subclassed procedure will automatically call
4216 if (infoPtr
->hwndEdit
)
4222 ht
.pt
.x
= (short)LOWORD(lParam
);
4223 ht
.pt
.y
= (short)HIWORD(lParam
);
4225 TREEVIEW_HitTest(infoPtr
, &ht
);
4226 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
4228 /* update focusedItem and redraw both items */
4233 if (TREEVIEW_IsFullRowSelect(infoPtr
))
4234 do_focus
= ht
.flags
& (TVHT_ONITEMINDENT
| TVHT_ONITEM
| TVHT_ONITEMRIGHT
);
4236 do_focus
= ht
.flags
& TVHT_ONITEM
;
4240 infoPtr
->focusedItem
= ht
.hItem
;
4241 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4242 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4246 if (!(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
))
4248 if (TREEVIEW_IsFullRowSelect(infoPtr
))
4249 do_track
= ht
.flags
& (TVHT_ONITEMINDENT
| TVHT_ONITEM
| TVHT_ONITEMRIGHT
);
4251 do_track
= ht
.flags
& TVHT_ONITEM
;
4257 * If the style allows editing and the node is already selected
4258 * and the click occurred on the item label...
4260 bDoLabelEdit
= (infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
4261 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
);
4263 /* Send NM_CLICK right away */
4264 if (!do_track
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4267 if (ht
.flags
& TVHT_ONITEMBUTTON
)
4269 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
4273 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
4274 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4276 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
4277 infoPtr
->dropItem
= ht
.hItem
;
4279 /* clean up focusedItem as we dragged and won't select this item */
4280 if(infoPtr
->focusedItem
)
4282 /* refresh the item that was focused */
4283 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4284 infoPtr
->focusedItem
= NULL
;
4286 /* refresh the selected item to return the filled background */
4287 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4294 if (do_track
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4297 if (TREEVIEW_IsFullRowSelect(infoPtr
))
4298 do_select
= ht
.flags
& (TVHT_ONITEMINDENT
| TVHT_ONITEMICON
| TVHT_ONITEMLABEL
| TVHT_ONITEMRIGHT
);
4300 do_select
= ht
.flags
& (TVHT_ONITEMICON
| TVHT_ONITEMLABEL
);
4304 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4305 KillTimer(hwnd
, TV_EDIT_TIMER
);
4307 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
4308 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
4312 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4314 /* Select the current item */
4315 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4316 TREEVIEW_SingleExpand(infoPtr
, selection
, ht
.hItem
);
4318 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4320 /* TVS_CHECKBOXES requires us to toggle the current state */
4321 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4322 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4332 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4336 if (infoPtr
->hwndEdit
)
4338 SetFocus(infoPtr
->hwnd
);
4342 ht
.pt
.x
= (short)LOWORD(lParam
);
4343 ht
.pt
.y
= (short)HIWORD(lParam
);
4345 TREEVIEW_HitTest(infoPtr
, &ht
);
4347 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4351 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4352 infoPtr
->dropItem
= ht
.hItem
;
4357 SetFocus(infoPtr
->hwnd
);
4358 if(!TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
))
4360 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
4361 SendMessageW(infoPtr
->hwndNotify
, WM_CONTEXTMENU
,
4362 (WPARAM
)infoPtr
->hwnd
, (LPARAM
)GetMessagePos());
4370 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4372 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4376 HBITMAP hbmp
, hOldbmp
;
4383 if (!(infoPtr
->himlNormal
))
4386 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4389 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4391 hwtop
= GetDesktopWindow();
4392 htopdc
= GetDC(hwtop
);
4393 hdc
= CreateCompatibleDC(htopdc
);
4395 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4397 if (dragItem
->pszText
)
4398 GetTextExtentPoint32W(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
),
4401 GetTextExtentPoint32A(hdc
, "", 0, &size
);
4403 TRACE("%d %d %s\n", size
.cx
, size
.cy
, debugstr_w(dragItem
->pszText
));
4404 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4405 hOldbmp
= SelectObject(hdc
, hbmp
);
4407 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4412 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4413 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4417 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4418 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4421 /* draw item text */
4423 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4425 if (dragItem
->pszText
)
4426 DrawTextW(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
), &rc
,
4429 SelectObject(hdc
, hOldFont
);
4430 SelectObject(hdc
, hOldbmp
);
4432 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4436 ReleaseDC(hwtop
, htopdc
);
4438 return (LRESULT
)infoPtr
->dragList
;
4441 /* Selection ************************************************************/
4444 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4447 TREEVIEW_ITEM
*prevSelect
;
4449 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4451 TRACE("Entering item %p (%s), flag 0x%x, cause 0x%x, state %d\n",
4452 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4453 newSelect
? newSelect
->state
: 0);
4455 /* reset and redraw focusedItem if focusedItem was set so we don't */
4456 /* have to worry about the previously focused item when we set a new one */
4457 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4458 infoPtr
->focusedItem
= NULL
;
4462 case TVGN_CARET
|TVSI_NOSINGLEEXPAND
:
4463 FIXME("TVSI_NOSINGLEEXPAND specified.\n");
4466 prevSelect
= infoPtr
->selectedItem
;
4468 if (prevSelect
== newSelect
) {
4469 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4473 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4476 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4482 prevSelect
->state
&= ~TVIS_SELECTED
;
4484 newSelect
->state
|= TVIS_SELECTED
;
4486 infoPtr
->selectedItem
= newSelect
;
4488 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4490 TREEVIEW_InvalidateItem(infoPtr
, prevSelect
);
4491 TREEVIEW_InvalidateItem(infoPtr
, newSelect
);
4493 TREEVIEW_SendTreeviewNotify(infoPtr
,
4496 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4501 case TVGN_DROPHILITE
:
4502 prevSelect
= infoPtr
->dropItem
;
4505 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4507 infoPtr
->dropItem
= newSelect
;
4510 newSelect
->state
|= TVIS_DROPHILITED
;
4512 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4513 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4516 case TVGN_FIRSTVISIBLE
:
4517 if (newSelect
!= NULL
)
4519 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4520 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4521 TREEVIEW_Invalidate(infoPtr
, NULL
);
4526 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4530 /* FIXME: handle NM_KILLFOCUS etc */
4532 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4534 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4536 if (item
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4539 if (item
== infoPtr
->selectedItem
)
4542 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4544 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4547 TREEVIEW_SingleExpand(infoPtr
, selection
, item
);
4552 /*************************************************************************
4553 * TREEVIEW_ProcessLetterKeys
4555 * Processes keyboard messages generated by pressing the letter keys
4557 * What this does is perform a case insensitive search from the
4558 * current position with the following quirks:
4559 * - If two chars or more are pressed in quick succession we search
4560 * for the corresponding string (e.g. 'abc').
4561 * - If there is a delay we wipe away the current search string and
4562 * restart with just that char.
4563 * - If the user keeps pressing the same character, whether slowly or
4564 * fast, so that the search string is entirely composed of this
4565 * character ('aaaaa' for instance), then we search for first item
4566 * that starting with that character.
4567 * - If the user types the above character in quick succession, then
4568 * we must also search for the corresponding string ('aaaaa'), and
4569 * go to that string if there is a match.
4577 * - The current implementation has a list of characters it will
4578 * accept and it ignores everything else. In particular it will
4579 * ignore accentuated characters which seems to match what
4580 * Windows does. But I'm not sure it makes sense to follow
4582 * - We don't sound a beep when the search fails.
4583 * - The search should start from the focused item, not from the selected
4584 * item. One reason for this is to allow for multiple selections in trees.
4585 * But currently infoPtr->focusedItem does not seem very usable.
4589 * TREEVIEW_ProcessLetterKeys
4591 static INT
TREEVIEW_ProcessLetterKeys(TREEVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
4594 HTREEITEM endidx
,idx
;
4596 WCHAR buffer
[MAX_PATH
];
4597 DWORD timestamp
,elapsed
;
4599 /* simple parameter checking */
4600 if (!charCode
|| !keyData
) return 0;
4602 /* only allow the valid WM_CHARs through */
4603 if (!isalnum(charCode
) &&
4604 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4605 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4606 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4607 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4608 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4609 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4610 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4611 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4612 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4615 /* compute how much time elapsed since last keypress */
4616 timestamp
= GetTickCount();
4617 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4618 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4620 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4623 /* update the search parameters */
4624 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4625 if (elapsed
< KEY_DELAY
) {
4626 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
) / sizeof(WCHAR
)) {
4627 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4629 if (infoPtr
->charCode
!= charCode
) {
4630 infoPtr
->charCode
=charCode
=0;
4633 infoPtr
->charCode
=charCode
;
4634 infoPtr
->szSearchParam
[0]=charCode
;
4635 infoPtr
->nSearchParamLength
=1;
4636 /* Redundant with the 1 char string */
4640 /* and search from the current position */
4642 if (infoPtr
->selectedItem
!= NULL
) {
4643 endidx
=infoPtr
->selectedItem
;
4644 /* if looking for single character match,
4645 * then we must always move forward
4647 if (infoPtr
->nSearchParamLength
== 1)
4648 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4653 idx
=infoPtr
->root
->firstChild
;
4656 /* At the end point, sort out wrapping */
4659 /* If endidx is null, stop at the last item (ie top to bottom) */
4663 /* Otherwise, start again at the very beginning */
4664 idx
=infoPtr
->root
->firstChild
;
4666 /* But if we are stopping on the first child, end now! */
4667 if (idx
== endidx
) break;
4671 ZeroMemory(&item
, sizeof(item
));
4672 item
.mask
= TVIF_TEXT
;
4674 item
.pszText
= buffer
;
4675 item
.cchTextMax
= sizeof(buffer
);
4676 TREEVIEW_GetItemT( infoPtr
, &item
, TRUE
);
4678 /* check for a match */
4679 if (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4682 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4683 (nItem
!= infoPtr
->selectedItem
) &&
4684 (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4685 /* This would work but we must keep looking for a longer match */
4688 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4689 } while (idx
!= endidx
);
4691 if (nItem
!= NULL
) {
4692 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4693 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4700 /* Scrolling ************************************************************/
4703 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4706 BOOL hasFirstVisible
= infoPtr
->firstVisible
!= NULL
;
4707 HTREEITEM newFirstVisible
= NULL
;
4708 int visible_pos
= -1;
4710 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4713 if (!ISVISIBLE(item
))
4715 /* Expand parents as necessary. */
4718 /* see if we are trying to ensure that root is visible */
4719 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4720 parent
= item
->parent
;
4722 parent
= item
; /* this item is the topmost item */
4724 while (parent
!= infoPtr
->root
)
4726 if (!(parent
->state
& TVIS_EXPANDED
))
4727 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, TRUE
);
4729 parent
= parent
->parent
;
4733 viscount
= TREEVIEW_GetVisibleCount(infoPtr
);
4735 TRACE("%p (%s) %d - %d viscount(%d)\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4736 hasFirstVisible
? infoPtr
->firstVisible
->visibleOrder
: -1, viscount
);
4738 if (hasFirstVisible
)
4739 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4741 if (visible_pos
< 0)
4743 /* item is before the start of the list: put it at the top. */
4744 newFirstVisible
= item
;
4746 else if (visible_pos
>= viscount
4747 /* Sometimes, before we are displayed, GVC is 0, causing us to
4748 * spuriously scroll up. */
4749 && visible_pos
> 0 && !(infoPtr
->dwStyle
& TVS_NOSCROLL
) )
4751 /* item is past the end of the list. */
4752 int scroll
= visible_pos
- viscount
;
4754 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4760 /* Scroll window so item's text is visible as much as possible */
4761 /* Calculation of amount of extra space is taken from EditLabel code */
4763 TEXTMETRICW textMetric
;
4764 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4766 x
= item
->textWidth
;
4768 GetTextMetricsW(hdc
, &textMetric
);
4769 ReleaseDC(infoPtr
->hwnd
, hdc
);
4771 x
+= (textMetric
.tmMaxCharWidth
* 2);
4772 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4774 if (item
->textOffset
< 0)
4775 pos
= item
->textOffset
;
4776 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4778 if (x
> infoPtr
->clientWidth
)
4779 pos
= item
->textOffset
;
4781 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4786 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4789 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4791 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4800 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4801 TREEVIEW_ITEM
*newFirstVisible
,
4802 BOOL bUpdateScrollPos
)
4806 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4808 if (newFirstVisible
!= NULL
)
4810 /* Prevent an empty gap from appearing at the bottom... */
4811 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4812 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4816 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4819 /* ... unless we just don't have enough items. */
4820 if (newFirstVisible
== NULL
)
4821 newFirstVisible
= infoPtr
->root
->firstChild
;
4825 if (infoPtr
->firstVisible
!= newFirstVisible
)
4827 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4829 infoPtr
->firstVisible
= newFirstVisible
;
4830 TREEVIEW_Invalidate(infoPtr
, NULL
);
4834 TREEVIEW_ITEM
*item
;
4835 int scroll
= infoPtr
->uItemHeight
*
4836 (infoPtr
->firstVisible
->visibleOrder
4837 - newFirstVisible
->visibleOrder
);
4839 infoPtr
->firstVisible
= newFirstVisible
;
4841 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4842 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4844 item
->rect
.top
+= scroll
;
4845 item
->rect
.bottom
+= scroll
;
4848 if (bUpdateScrollPos
)
4849 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4850 newFirstVisible
->visibleOrder
, TRUE
);
4852 ScrollWindowEx(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
, NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
4857 /************************************************************************
4858 * VScroll is always in units of visible items. i.e. we always have a
4859 * visible item aligned to the top of the control. (Unless we have no
4863 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4865 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4866 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4868 int nScrollCode
= LOWORD(wParam
);
4870 TRACE("wp %lx\n", wParam
);
4872 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4875 if (!oldFirstVisible
)
4877 assert(infoPtr
->root
->firstChild
== NULL
);
4881 switch (nScrollCode
)
4884 newFirstVisible
= infoPtr
->root
->firstChild
;
4888 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4892 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4896 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4900 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4901 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4905 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4906 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4910 case SB_THUMBPOSITION
:
4911 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4912 infoPtr
->root
->firstChild
,
4913 (LONG
)(SHORT
)HIWORD(wParam
));
4920 if (newFirstVisible
!= NULL
)
4922 if (newFirstVisible
!= oldFirstVisible
)
4923 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4924 nScrollCode
!= SB_THUMBTRACK
);
4925 else if (nScrollCode
== SB_THUMBPOSITION
)
4926 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4927 newFirstVisible
->visibleOrder
, TRUE
);
4934 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4937 int scrollX
= infoPtr
->scrollX
;
4938 int nScrollCode
= LOWORD(wParam
);
4940 TRACE("wp %lx\n", wParam
);
4942 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4945 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4946 /* shall never occur */
4953 switch (nScrollCode
)
4956 scrollX
-= infoPtr
->uItemHeight
;
4959 scrollX
+= infoPtr
->uItemHeight
;
4962 scrollX
-= infoPtr
->clientWidth
;
4965 scrollX
+= infoPtr
->clientWidth
;
4969 case SB_THUMBPOSITION
:
4970 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4977 if (scrollX
> maxWidth
)
4979 else if (scrollX
< 0)
4983 if (scrollX
!= infoPtr
->scrollX
)
4985 TREEVIEW_ITEM
*item
;
4986 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4988 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4989 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4991 item
->linesOffset
+= scroll_pixels
;
4992 item
->stateOffset
+= scroll_pixels
;
4993 item
->imageOffset
+= scroll_pixels
;
4994 item
->textOffset
+= scroll_pixels
;
4997 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4998 infoPtr
->scrollX
= scrollX
;
4999 UpdateWindow(infoPtr
->hwnd
);
5002 if (nScrollCode
!= SB_THUMBTRACK
)
5003 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
5009 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5012 UINT pulScrollLines
= 3;
5014 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
5015 return DefWindowProcW(infoPtr
->hwnd
, WM_MOUSEWHEEL
, wParam
, lParam
);
5017 if (infoPtr
->firstVisible
== NULL
)
5020 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
5022 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
5023 /* if scrolling changes direction, ignore left overs */
5024 if ((wheelDelta
< 0 && infoPtr
->wheelRemainder
< 0) ||
5025 (wheelDelta
> 0 && infoPtr
->wheelRemainder
> 0))
5026 infoPtr
->wheelRemainder
+= wheelDelta
;
5028 infoPtr
->wheelRemainder
= wheelDelta
;
5030 if (infoPtr
->wheelRemainder
&& pulScrollLines
)
5036 lineScroll
= pulScrollLines
* (float)infoPtr
->wheelRemainder
/ WHEEL_DELTA
;
5037 infoPtr
->wheelRemainder
-= WHEEL_DELTA
* lineScroll
/ (int)pulScrollLines
;
5039 newDy
= infoPtr
->firstVisible
->visibleOrder
- lineScroll
;
5040 maxDy
= infoPtr
->maxVisibleOrder
;
5048 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
5053 /* Create/Destroy *******************************************************/
5056 TREEVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5059 TREEVIEW_INFO
*infoPtr
;
5062 TRACE("wnd %p, style 0x%x\n", hwnd
, GetWindowLongW(hwnd
, GWL_STYLE
));
5064 infoPtr
= Alloc(sizeof(TREEVIEW_INFO
));
5066 if (infoPtr
== NULL
)
5068 ERR("could not allocate info memory!\n");
5072 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
5074 infoPtr
->hwnd
= hwnd
;
5075 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5077 infoPtr
->uNumItems
= 0;
5078 infoPtr
->cdmode
= 0;
5079 infoPtr
->uScrollTime
= 300; /* milliseconds */
5080 infoPtr
->bRedraw
= TRUE
;
5082 GetClientRect(hwnd
, &rcClient
);
5084 /* No scroll bars yet. */
5085 infoPtr
->clientWidth
= rcClient
.right
;
5086 infoPtr
->clientHeight
= rcClient
.bottom
;
5087 infoPtr
->uInternalStatus
= 0;
5089 infoPtr
->treeWidth
= 0;
5090 infoPtr
->treeHeight
= 0;
5092 infoPtr
->uIndent
= MINIMUM_INDENT
;
5093 infoPtr
->selectedItem
= NULL
;
5094 infoPtr
->focusedItem
= NULL
;
5095 infoPtr
->hotItem
= NULL
;
5096 infoPtr
->editItem
= NULL
;
5097 infoPtr
->firstVisible
= NULL
;
5098 infoPtr
->maxVisibleOrder
= 0;
5099 infoPtr
->dropItem
= NULL
;
5100 infoPtr
->insertMarkItem
= NULL
;
5101 infoPtr
->insertBeforeorAfter
= 0;
5104 infoPtr
->scrollX
= 0;
5105 infoPtr
->wheelRemainder
= 0;
5107 infoPtr
->clrBk
= CLR_NONE
; /* use system color */
5108 infoPtr
->clrText
= CLR_NONE
; /* use system color */
5109 infoPtr
->clrLine
= CLR_DEFAULT
;
5110 infoPtr
->clrInsertMark
= CLR_DEFAULT
;
5114 infoPtr
->hwndEdit
= NULL
;
5115 infoPtr
->wpEditOrig
= NULL
;
5116 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
5117 infoPtr
->bLabelChanged
= FALSE
;
5119 infoPtr
->himlNormal
= NULL
;
5120 infoPtr
->himlState
= NULL
;
5121 infoPtr
->normalImageWidth
= 0;
5122 infoPtr
->normalImageHeight
= 0;
5123 infoPtr
->stateImageWidth
= 0;
5124 infoPtr
->stateImageHeight
= 0;
5126 infoPtr
->items
= DPA_Create(16);
5128 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
5129 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW(&lf
);
5130 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
5131 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
5132 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
5133 infoPtr
->hcurHand
= LoadCursorW(NULL
, (LPWSTR
)IDC_HAND
);
5135 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
5137 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
5138 infoPtr
->root
->state
= TVIS_EXPANDED
;
5139 infoPtr
->root
->iLevel
= -1;
5140 infoPtr
->root
->visibleOrder
= -1;
5142 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5143 infoPtr
->hwndToolTip
= 0;
5145 /* Determine what type of notify should be issued (sets infoPtr->bNtfUnicode) */
5146 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
5148 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
5149 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
5150 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
5153 /* Make sure actual scrollbar state is consistent with uInternalStatus */
5154 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
5155 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
5157 OpenThemeData (hwnd
, themeClass
);
5164 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
5168 /* free item data */
5169 TREEVIEW_RemoveTree(infoPtr
);
5170 /* root isn't freed with other items */
5171 TREEVIEW_FreeItem(infoPtr
, infoPtr
->root
);
5172 DPA_Destroy(infoPtr
->items
);
5174 /* tool tip is automatically destroyed: we are its owner */
5176 /* Restore original wndproc */
5177 if (infoPtr
->hwndEdit
)
5178 SetWindowLongPtrW(infoPtr
->hwndEdit
, GWLP_WNDPROC
,
5179 (DWORD_PTR
)infoPtr
->wpEditOrig
);
5181 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
5183 /* Deassociate treeview from the window before doing anything drastic. */
5184 SetWindowLongPtrW(infoPtr
->hwnd
, 0, 0);
5186 DeleteObject(infoPtr
->hDefaultFont
);
5187 DeleteObject(infoPtr
->hBoldFont
);
5188 DeleteObject(infoPtr
->hUnderlineFont
);
5189 DeleteObject(infoPtr
->hBoldUnderlineFont
);
5195 /* Miscellaneous Messages ***********************************************/
5198 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
5206 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
5207 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
5208 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
5209 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
5210 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
5211 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
5212 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
5213 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
5214 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
5218 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
5220 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
5222 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
5224 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
5230 /************************************************************************
5233 * VK_UP Move selection to the previous non-hidden item.
5234 * VK_DOWN Move selection to the next non-hidden item.
5235 * VK_HOME Move selection to the first item.
5236 * VK_END Move selection to the last item.
5237 * VK_LEFT If expanded then collapse, otherwise move to parent.
5238 * VK_RIGHT If collapsed then expand, otherwise move to first child.
5240 * VK_SUBTRACT Collapse.
5241 * VK_MULTIPLY Expand all.
5242 * VK_PRIOR Move up GetVisibleCount items.
5243 * VK_NEXT Move down GetVisibleCount items.
5244 * VK_BACK Move to parent.
5245 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
5248 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
5250 /* If it is non-NULL and different, it will be selected and visible. */
5251 TREEVIEW_ITEM
*newSelection
= NULL
;
5252 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
5253 NMTVKEYDOWN nmkeydown
;
5255 TRACE("%lx\n", wParam
);
5257 nmkeydown
.wVKey
= wParam
;
5258 nmkeydown
.flags
= 0;
5259 TREEVIEW_SendRealNotify(infoPtr
, TVN_KEYDOWN
, &nmkeydown
.hdr
);
5261 if (prevItem
== NULL
)
5264 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
5265 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
5270 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
5272 newSelection
= infoPtr
->root
->firstChild
;
5276 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
5280 TREEVIEW_SendSimpleNotify(infoPtr
, NM_RETURN
);
5284 newSelection
= infoPtr
->root
->firstChild
;
5288 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
5292 if (prevItem
->state
& TVIS_EXPANDED
)
5294 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5296 else if (prevItem
->parent
!= infoPtr
->root
)
5298 newSelection
= prevItem
->parent
;
5303 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
5305 if (!(prevItem
->state
& TVIS_EXPANDED
))
5306 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5309 newSelection
= prevItem
->firstChild
;
5316 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5320 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5324 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5329 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5330 -TREEVIEW_GetVisibleCount(infoPtr
));
5335 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5336 TREEVIEW_GetVisibleCount(infoPtr
));
5340 newSelection
= prevItem
->parent
;
5341 if (newSelection
== infoPtr
->root
)
5342 newSelection
= NULL
;
5346 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5347 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5351 if (newSelection
&& newSelection
!= prevItem
)
5353 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5356 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5364 TREEVIEW_MouseLeave (TREEVIEW_INFO
* infoPtr
)
5366 /* remove hot effect from item */
5367 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5368 infoPtr
->hotItem
= NULL
;
5374 TREEVIEW_MouseMove (TREEVIEW_INFO
* infoPtr
, LPARAM lParam
)
5376 TRACKMOUSEEVENT trackinfo
;
5377 TREEVIEW_ITEM
* item
;
5381 if (!(infoPtr
->dwStyle
& TVS_TRACKSELECT
)) return 0;
5383 /* fill in the TRACKMOUSEEVENT struct */
5384 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5385 trackinfo
.dwFlags
= TME_QUERY
;
5386 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5388 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5389 _TrackMouseEvent(&trackinfo
);
5391 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5392 if(!(trackinfo
.dwFlags
& TME_LEAVE
))
5394 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5395 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5396 /* do it as fast as possible, minimal systimer latency will be used */
5397 trackinfo
.dwHoverTime
= 1;
5399 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5400 /* and can properly deactivate the hot item */
5401 _TrackMouseEvent(&trackinfo
);
5404 ht
.pt
.x
= (short)LOWORD(lParam
);
5405 ht
.pt
.y
= (short)HIWORD(lParam
);
5407 item
= TREEVIEW_HitTest(infoPtr
, &ht
);
5408 item_hit
= TREEVIEW_IsItemHit(infoPtr
, &ht
);
5409 if ((item
!= infoPtr
->hotItem
) || !item_hit
)
5411 /* redraw old hot item */
5412 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5413 infoPtr
->hotItem
= NULL
;
5414 if (item
&& item_hit
)
5416 infoPtr
->hotItem
= item
;
5417 /* redraw new hot item */
5418 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5425 /* Draw themed border */
5426 static BOOL
TREEVIEW_NCPaint (const TREEVIEW_INFO
*infoPtr
, HRGN region
, LPARAM lParam
)
5428 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5432 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
5433 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
5436 return DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)region
, lParam
);
5438 GetWindowRect(infoPtr
->hwnd
, &r
);
5440 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
5441 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
5442 if (region
!= (HRGN
)1)
5443 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
5444 OffsetRect(&r
, -r
.left
, -r
.top
);
5446 dc
= GetDCEx(infoPtr
->hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
5447 OffsetRect(&r
, -r
.left
, -r
.top
);
5449 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
5450 DrawThemeParentBackground(infoPtr
->hwnd
, dc
, &r
);
5451 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
5452 ReleaseDC(infoPtr
->hwnd
, dc
);
5454 /* Call default proc to get the scrollbars etc. painted */
5455 DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
5461 TREEVIEW_Notify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5463 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5465 if (lpnmh
->code
== PGN_CALCSIZE
) {
5466 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5468 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5469 lppgc
->iWidth
= infoPtr
->treeWidth
;
5470 TRACE("got PGN_CALCSIZE, returning horz size = %d, client=%d\n",
5471 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5474 lppgc
->iHeight
= infoPtr
->treeHeight
;
5475 TRACE("got PGN_CALCSIZE, returning vert size = %d, client=%d\n",
5476 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5480 return DefWindowProcW(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5484 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5486 if (wParam
== SIZE_RESTORED
)
5488 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5489 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5491 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5492 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5493 TREEVIEW_UpdateScrollBars(infoPtr
);
5497 FIXME("WM_SIZE flag %lx %lx not handled\n", wParam
, lParam
);
5500 TREEVIEW_Invalidate(infoPtr
, NULL
);
5505 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5507 TRACE("(%lx %lx)\n", wParam
, lParam
);
5509 if (wParam
== GWL_STYLE
)
5511 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5513 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_CHECKBOXES
)
5515 if (dwNewStyle
& TVS_CHECKBOXES
)
5517 TREEVIEW_InitCheckboxes(infoPtr
);
5518 TRACE("checkboxes enabled\n");
5520 /* set all items to state image index 1 */
5521 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
5525 FIXME("tried to disable checkboxes\n");
5529 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5531 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5533 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5534 TRACE("tooltips enabled\n");
5538 DestroyWindow(infoPtr
->hwndToolTip
);
5539 infoPtr
->hwndToolTip
= 0;
5540 TRACE("tooltips disabled\n");
5544 infoPtr
->dwStyle
= dwNewStyle
;
5547 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
5548 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5549 TREEVIEW_UpdateScrollBars(infoPtr
);
5550 TREEVIEW_Invalidate(infoPtr
, NULL
);
5556 TREEVIEW_SetCursor(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5558 TREEVIEW_ITEM
* item
;
5562 GetCursorPos(&ht
.pt
);
5563 ScreenToClient(infoPtr
->hwnd
, &ht
.pt
);
5565 item
= TREEVIEW_HitTest(infoPtr
, &ht
);
5567 memset(&nmmouse
, 0, sizeof(nmmouse
));
5570 nmmouse
.dwItemSpec
= (DWORD_PTR
)item
;
5571 nmmouse
.dwItemData
= item
->lParam
;
5575 nmmouse
.dwHitInfo
= lParam
;
5576 if (TREEVIEW_SendRealNotify(infoPtr
, NM_SETCURSOR
, &nmmouse
.hdr
))
5579 if (item
&& (infoPtr
->dwStyle
& TVS_TRACKSELECT
) && TREEVIEW_IsItemHit(infoPtr
, &ht
))
5581 SetCursor(infoPtr
->hcurHand
);
5585 return DefWindowProcW(infoPtr
->hwnd
, WM_SETCURSOR
, wParam
, lParam
);
5589 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5593 if (!infoPtr
->selectedItem
)
5595 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5599 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5600 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5605 TREEVIEW_KillFocus(const TREEVIEW_INFO
*infoPtr
)
5609 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5610 UpdateWindow(infoPtr
->hwnd
);
5611 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5615 /* update theme after a WM_THEMECHANGED message */
5616 static LRESULT
TREEVIEW_ThemeChanged(const TREEVIEW_INFO
*infoPtr
)
5618 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5619 CloseThemeData (theme
);
5620 OpenThemeData (infoPtr
->hwnd
, themeClass
);
5625 static LRESULT WINAPI
5626 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5628 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5630 TRACE("hwnd %p msg %04x wp=%08lx lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5632 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5635 if (uMsg
== WM_CREATE
)
5636 TREEVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
5643 case TVM_CREATEDRAGIMAGE
:
5644 return TREEVIEW_CreateDragImage(infoPtr
, lParam
);
5646 case TVM_DELETEITEM
:
5647 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5649 case TVM_EDITLABELA
:
5650 case TVM_EDITLABELW
:
5651 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5653 case TVM_ENDEDITLABELNOW
:
5654 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5656 case TVM_ENSUREVISIBLE
:
5657 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5660 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5662 case TVM_GETBKCOLOR
:
5663 return TREEVIEW_GetBkColor(infoPtr
);
5666 return TREEVIEW_GetCount(infoPtr
);
5668 case TVM_GETEDITCONTROL
:
5669 return TREEVIEW_GetEditControl(infoPtr
);
5671 case TVM_GETIMAGELIST
:
5672 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5675 return TREEVIEW_GetIndent(infoPtr
);
5677 case TVM_GETINSERTMARKCOLOR
:
5678 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5680 case TVM_GETISEARCHSTRINGA
:
5681 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5684 case TVM_GETISEARCHSTRINGW
:
5685 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5690 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5691 uMsg
== TVM_GETITEMW
);
5692 case TVM_GETITEMHEIGHT
:
5693 return TREEVIEW_GetItemHeight(infoPtr
);
5695 case TVM_GETITEMRECT
:
5696 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5698 case TVM_GETITEMSTATE
:
5699 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5701 case TVM_GETLINECOLOR
:
5702 return TREEVIEW_GetLineColor(infoPtr
);
5704 case TVM_GETNEXTITEM
:
5705 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5707 case TVM_GETSCROLLTIME
:
5708 return TREEVIEW_GetScrollTime(infoPtr
);
5710 case TVM_GETTEXTCOLOR
:
5711 return TREEVIEW_GetTextColor(infoPtr
);
5713 case TVM_GETTOOLTIPS
:
5714 return TREEVIEW_GetToolTips(infoPtr
);
5716 case TVM_GETUNICODEFORMAT
:
5717 return TREEVIEW_GetUnicodeFormat(infoPtr
);
5719 case TVM_GETVISIBLECOUNT
:
5720 return TREEVIEW_GetVisibleCount(infoPtr
);
5723 return (LRESULT
)TREEVIEW_HitTest(infoPtr
, (TVHITTESTINFO
*)lParam
);
5725 case TVM_INSERTITEMA
:
5726 case TVM_INSERTITEMW
:
5727 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
,
5728 uMsg
== TVM_INSERTITEMW
);
5729 case TVM_SELECTITEM
:
5730 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5732 case TVM_SETBKCOLOR
:
5733 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5735 case TVM_SETIMAGELIST
:
5736 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5739 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5741 case TVM_SETINSERTMARK
:
5742 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5744 case TVM_SETINSERTMARKCOLOR
:
5745 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5749 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5750 uMsg
== TVM_SETITEMW
);
5751 case TVM_SETLINECOLOR
:
5752 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5754 case TVM_SETITEMHEIGHT
:
5755 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5757 case TVM_SETSCROLLTIME
:
5758 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5760 case TVM_SETTEXTCOLOR
:
5761 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5763 case TVM_SETTOOLTIPS
:
5764 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5766 case TVM_SETUNICODEFORMAT
:
5767 return TREEVIEW_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
5769 case TVM_SORTCHILDREN
:
5770 return TREEVIEW_SortChildren(infoPtr
, lParam
);
5772 case TVM_SORTCHILDRENCB
:
5773 return TREEVIEW_SortChildrenCB(infoPtr
, (LPTVSORTCB
)lParam
);
5776 return TREEVIEW_ProcessLetterKeys(infoPtr
, wParam
, lParam
);
5779 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5782 return TREEVIEW_Destroy(infoPtr
);
5787 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5790 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5793 return TREEVIEW_GetFont(infoPtr
);
5796 return TREEVIEW_HScroll(infoPtr
, wParam
);
5800 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5803 return TREEVIEW_KillFocus(infoPtr
);
5805 case WM_LBUTTONDBLCLK
:
5806 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5808 case WM_LBUTTONDOWN
:
5809 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5811 /* WM_MBUTTONDOWN */
5814 return TREEVIEW_MouseLeave(infoPtr
);
5817 return TREEVIEW_MouseMove(infoPtr
, lParam
);
5819 case WM_NCLBUTTONDOWN
:
5820 if (infoPtr
->hwndEdit
)
5821 SetFocus(infoPtr
->hwnd
);
5825 return TREEVIEW_NCPaint (infoPtr
, (HRGN
)wParam
, lParam
);
5828 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5830 case WM_NOTIFYFORMAT
:
5831 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5833 case WM_PRINTCLIENT
:
5834 return TREEVIEW_PrintClient(infoPtr
, (HDC
)wParam
, lParam
);
5837 return TREEVIEW_Paint(infoPtr
, (HDC
)wParam
);
5839 case WM_RBUTTONDOWN
:
5840 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5843 return TREEVIEW_SetCursor(infoPtr
, wParam
, lParam
);
5846 return TREEVIEW_SetFocus(infoPtr
);
5849 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5852 return TREEVIEW_SetRedraw(infoPtr
, wParam
);
5855 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5857 case WM_STYLECHANGED
:
5858 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5860 case WM_SYSCOLORCHANGE
:
5861 COMCTL32_RefreshSysColors();
5865 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5867 case WM_THEMECHANGED
:
5868 return TREEVIEW_ThemeChanged (infoPtr
);
5871 return TREEVIEW_VScroll(infoPtr
, wParam
);
5873 /* WM_WININICHANGE */
5876 return TREEVIEW_MouseWheel(infoPtr
, wParam
, lParam
);
5879 TRACE("drawItem\n");
5883 /* This mostly catches MFC and Delphi messages. :( */
5884 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
5885 TRACE("Unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
5887 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
5892 /* Class Registration ***************************************************/
5895 TREEVIEW_Register(void)
5901 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
5902 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5903 wndClass
.lpfnWndProc
= TREEVIEW_WindowProc
;
5904 wndClass
.cbClsExtra
= 0;
5905 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5907 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
5908 wndClass
.hbrBackground
= 0;
5909 wndClass
.lpszClassName
= WC_TREEVIEWW
;
5911 RegisterClassW(&wndClass
);
5916 TREEVIEW_Unregister(void)
5918 UnregisterClassW(WC_TREEVIEWW
, NULL
);
5922 /* Tree Verification ****************************************************/
5925 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
);
5927 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5928 const TREEVIEW_ITEM
*item
)
5930 assert(infoPtr
!= NULL
);
5931 assert(item
!= NULL
);
5933 /* both NULL, or both non-null */
5934 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5936 assert(item
->firstChild
!= item
);
5937 assert(item
->lastChild
!= item
);
5939 if (item
->firstChild
)
5941 assert(item
->firstChild
->parent
== item
);
5942 assert(item
->firstChild
->prevSibling
== NULL
);
5945 if (item
->lastChild
)
5947 assert(item
->lastChild
->parent
== item
);
5948 assert(item
->lastChild
->nextSibling
== NULL
);
5951 assert(item
->nextSibling
!= item
);
5952 if (item
->nextSibling
)
5954 assert(item
->nextSibling
->parent
== item
->parent
);
5955 assert(item
->nextSibling
->prevSibling
== item
);
5958 assert(item
->prevSibling
!= item
);
5959 if (item
->prevSibling
)
5961 assert(item
->prevSibling
->parent
== item
->parent
);
5962 assert(item
->prevSibling
->nextSibling
== item
);
5967 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5969 assert(item
!= NULL
);
5971 assert(item
->parent
!= NULL
);
5972 assert(item
->parent
!= item
);
5973 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5975 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5977 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5979 TREEVIEW_VerifyChildren(infoPtr
, item
);
5983 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5985 const TREEVIEW_ITEM
*child
;
5986 assert(item
!= NULL
);
5988 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5989 TREEVIEW_VerifyItem(infoPtr
, child
);
5993 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5995 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5997 assert(root
!= NULL
);
5998 assert(root
->iLevel
== -1);
5999 assert(root
->parent
== NULL
);
6000 assert(root
->prevSibling
== NULL
);
6002 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
6004 TREEVIEW_VerifyChildren(infoPtr
, root
);
6008 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
6010 if (!TRACE_ON(treeview
)) return;
6012 assert(infoPtr
!= NULL
);
6013 TREEVIEW_VerifyRoot(infoPtr
);