3 * Copyright 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de>
4 * Copyright 1998,1999 Alex Priem <alexp@sci.kun.nl>
5 * Copyright 1999 Sylvain St-Germain
6 * Copyright 2002 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * Note that TREEVIEW_INFO * and HTREEITEM are the same thing.
26 * Note2: If item's text == LPSTR_TEXTCALLBACKA we allocate buffer
27 * of size TEXT_CALLBACK_SIZE in DoSetItem.
28 * We use callbackMask to keep track of fields to be updated.
31 * missing notifications: TVN_GETINFOTIP, TVN_KEYDOWN,
34 * missing styles: TVS_FULLROWSELECT, TVS_INFOTIP, TVS_RTLREADING,
36 * missing item styles: TVIS_EXPANDPARTIAL, TVIS_EX_FLAT,
39 * Make the insertion mark look right.
40 * Scroll (instead of repaint) as much as possible.
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 first visible item */
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
; /* visible ordering, 0 is first visible item */
166 const TREEVIEW_INFO
*infoPtr
; /* tree data this item belongs to */
169 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
170 #define KEY_DELAY 450
172 /* bitflags for infoPtr->uInternalStatus */
174 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
175 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
176 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
177 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
178 #define TV_RDRAG 0x10 /* ditto Rbutton */
179 #define TV_RDRAGGING 0x20
181 /* bitflags for infoPtr->timer */
183 #define TV_EDIT_TIMER 2
184 #define TV_EDIT_TIMER_SET 2
186 #define TEXT_CALLBACK_SIZE 260
188 #define TREEVIEW_LEFT_MARGIN 8
190 #define MINIMUM_INDENT 19
192 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
194 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
195 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
196 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
198 #define GETLINECOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrGrayText : (x))
199 #define GETBKCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindow : (x))
200 #define GETTXTCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindowText : (x))
201 #define GETINSCOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrBtnText : (x))
203 static const WCHAR themeClass
[] = { 'T','r','e','e','v','i','e','w',0 };
206 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
209 static VOID
TREEVIEW_Invalidate(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
211 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
212 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
213 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
214 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
215 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
216 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
218 /* Random Utilities *****************************************************/
219 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
221 /* Returns the treeview private data if hwnd is a treeview.
222 * Otherwise returns an undefined value. */
223 static inline TREEVIEW_INFO
*
224 TREEVIEW_GetInfoPtr(HWND hwnd
)
226 return (TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
229 /* Don't call this. Nothing wants an item index. */
231 TREEVIEW_GetItemIndex(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
233 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
236 /* Checks if item has changed and needs to be redrawn */
237 static inline BOOL
item_changed (const TREEVIEW_ITEM
*tiOld
, const TREEVIEW_ITEM
*tiNew
,
238 const TVITEMEXW
*tvChange
)
240 /* Number of children has changed */
241 if ((tvChange
->mask
& TVIF_CHILDREN
) && (tiOld
->cChildren
!= tiNew
->cChildren
))
244 /* Image has changed and it's not a callback */
245 if ((tvChange
->mask
& TVIF_IMAGE
) && (tiOld
->iImage
!= tiNew
->iImage
) &&
246 tiNew
->iImage
!= I_IMAGECALLBACK
)
249 /* Selected image has changed and it's not a callback */
250 if ((tvChange
->mask
& TVIF_SELECTEDIMAGE
) && (tiOld
->iSelectedImage
!= tiNew
->iSelectedImage
) &&
251 tiNew
->iSelectedImage
!= I_IMAGECALLBACK
)
254 if ((tvChange
->mask
& TVIF_EXPANDEDIMAGE
) && (tiOld
->iExpandedImage
!= tiNew
->iExpandedImage
) &&
255 tiNew
->iExpandedImage
!= I_IMAGECALLBACK
)
258 /* Text has changed and it's not a callback */
259 if ((tvChange
->mask
& TVIF_TEXT
) && (tiOld
->pszText
!= tiNew
->pszText
) &&
260 tiNew
->pszText
!= LPSTR_TEXTCALLBACKW
)
263 /* Indent has changed */
264 if ((tvChange
->mask
& TVIF_INTEGRAL
) && (tiOld
->iIntegral
!= tiNew
->iIntegral
))
267 /* Item state has changed */
268 if ((tvChange
->mask
& TVIF_STATE
) && ((tiOld
->state
^ tiNew
->state
) & tvChange
->stateMask
))
274 /***************************************************************************
275 * This method checks that handle is an item for this tree.
278 TREEVIEW_ValidItem(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
280 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
282 TRACE("invalid item %p\n", handle
);
290 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
294 GetObjectW(hOrigFont
, sizeof(font
), &font
);
295 font
.lfWeight
= FW_BOLD
;
296 return CreateFontIndirectW(&font
);
300 TREEVIEW_CreateUnderlineFont(HFONT hOrigFont
)
304 GetObjectW(hOrigFont
, sizeof(font
), &font
);
305 font
.lfUnderline
= TRUE
;
306 return CreateFontIndirectW(&font
);
310 TREEVIEW_CreateBoldUnderlineFont(HFONT hfont
)
314 GetObjectW(hfont
, sizeof(font
), &font
);
315 font
.lfWeight
= FW_BOLD
;
316 font
.lfUnderline
= TRUE
;
317 return CreateFontIndirectW(&font
);
321 TREEVIEW_FontForItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
323 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
324 return item
->state
& TVIS_BOLD
? infoPtr
->hBoldUnderlineFont
: infoPtr
->hUnderlineFont
;
325 if (item
->state
& TVIS_BOLD
)
326 return infoPtr
->hBoldFont
;
327 return infoPtr
->hFont
;
330 /* for trace/debugging purposes only */
332 TREEVIEW_ItemName(const TREEVIEW_ITEM
*item
)
334 if (item
== NULL
) return "<null item>";
335 if (item
->pszText
== LPSTR_TEXTCALLBACKW
) return "<callback>";
336 if (item
->pszText
== NULL
) return "<null>";
337 return debugstr_w(item
->pszText
);
340 /* An item is not a child of itself. */
342 TREEVIEW_IsChildOf(const TREEVIEW_ITEM
*parent
, const TREEVIEW_ITEM
*child
)
346 child
= child
->parent
;
347 if (child
== parent
) return TRUE
;
348 } while (child
!= NULL
);
354 /* Tree Traversal *******************************************************/
356 /***************************************************************************
357 * This method returns the last expanded sibling or child child item
360 static TREEVIEW_ITEM
*
361 TREEVIEW_GetLastListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
363 if (!item
) return NULL
;
365 while (item
->lastChild
)
367 if (item
->state
& TVIS_EXPANDED
)
368 item
= item
->lastChild
;
373 if (item
== infoPtr
->root
)
379 /***************************************************************************
380 * This method returns the previous non-hidden item in the list not
381 * considering the tree hierarchy.
383 static TREEVIEW_ITEM
*
384 TREEVIEW_GetPrevListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
386 if (tvItem
->prevSibling
)
388 /* This item has a prevSibling, get the last item in the sibling's tree. */
389 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
391 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
392 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
398 /* this item does not have a prevSibling, get the parent */
399 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
404 /***************************************************************************
405 * This method returns the next physical item in the treeview not
406 * considering the tree hierarchy.
408 static TREEVIEW_ITEM
*
409 TREEVIEW_GetNextListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
412 * If this item has children and is expanded, return the first child
414 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
416 return tvItem
->firstChild
;
421 * try to get the sibling
423 if (tvItem
->nextSibling
)
424 return tvItem
->nextSibling
;
427 * Otherwise, get the parent's sibling.
429 while (tvItem
->parent
)
431 tvItem
= tvItem
->parent
;
433 if (tvItem
->nextSibling
)
434 return tvItem
->nextSibling
;
440 /***************************************************************************
441 * This method returns the nth item starting at the given item. It returns
442 * the last item (or first) we we run out of items.
444 * Will scroll backward if count is <0.
445 * forward if count is >0.
447 static TREEVIEW_ITEM
*
448 TREEVIEW_GetListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
451 TREEVIEW_ITEM
*(*next_item
)(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
452 TREEVIEW_ITEM
*previousItem
;
454 assert(item
!= NULL
);
458 next_item
= TREEVIEW_GetNextListItem
;
463 next_item
= TREEVIEW_GetPrevListItem
;
471 item
= next_item(infoPtr
, item
);
473 } while (--count
&& item
!= NULL
);
476 return item
? item
: previousItem
;
479 /* Notifications ************************************************************/
481 static INT
get_notifycode(const TREEVIEW_INFO
*infoPtr
, INT code
)
483 if (!infoPtr
->bNtfUnicode
) {
485 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
486 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
487 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
488 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
489 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
490 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
491 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
492 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
493 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
494 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
495 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
496 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
503 TREEVIEW_SendRealNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, NMHDR
*hdr
)
505 TRACE("code=%d, hdr=%p\n", code
, hdr
);
507 hdr
->hwndFrom
= infoPtr
->hwnd
;
508 hdr
->idFrom
= GetWindowLongPtrW(infoPtr
->hwnd
, GWLP_ID
);
509 hdr
->code
= get_notifycode(infoPtr
, code
);
511 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, hdr
->idFrom
, (LPARAM
)hdr
);
515 TREEVIEW_SendSimpleNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
)
518 return TREEVIEW_SendRealNotify(infoPtr
, code
, &hdr
);
522 TREEVIEW_TVItemFromItem(const TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMW
*tvItem
, TREEVIEW_ITEM
*item
)
525 tvItem
->hItem
= item
;
526 tvItem
->state
= item
->state
;
527 tvItem
->stateMask
= 0;
528 tvItem
->iImage
= item
->iImage
;
529 tvItem
->iSelectedImage
= item
->iSelectedImage
;
530 tvItem
->cChildren
= item
->cChildren
;
531 tvItem
->lParam
= item
->lParam
;
535 if (!infoPtr
->bNtfUnicode
)
537 tvItem
->cchTextMax
= WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0, NULL
, NULL
);
538 tvItem
->pszText
= Alloc (tvItem
->cchTextMax
);
539 WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, 0, 0 );
543 tvItem
->cchTextMax
= item
->cchTextMax
;
544 tvItem
->pszText
= item
->pszText
;
549 tvItem
->cchTextMax
= 0;
550 tvItem
->pszText
= NULL
;
555 TREEVIEW_SendTreeviewNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
556 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
561 TRACE("code:%d action:0x%x olditem:%p newitem:%p\n",
562 code
, action
, oldItem
, newItem
);
564 memset(&nmhdr
, 0, sizeof(NMTREEVIEWW
));
565 nmhdr
.action
= action
;
568 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
571 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
576 ret
= TREEVIEW_SendRealNotify(infoPtr
, code
, &nmhdr
.hdr
);
577 if (!infoPtr
->bNtfUnicode
)
579 Free(nmhdr
.itemOld
.pszText
);
580 Free(nmhdr
.itemNew
.pszText
);
586 TREEVIEW_SendTreeviewDnDNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
,
587 HTREEITEM dragItem
, POINT pt
)
591 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
594 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
595 nmhdr
.itemNew
.hItem
= dragItem
;
596 nmhdr
.itemNew
.state
= dragItem
->state
;
597 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
599 nmhdr
.ptDrag
.x
= pt
.x
;
600 nmhdr
.ptDrag
.y
= pt
.y
;
602 return TREEVIEW_SendRealNotify(infoPtr
, code
, &nmhdr
.hdr
);
607 TREEVIEW_SendCustomDrawNotify(const TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
610 NMTVCUSTOMDRAW nmcdhdr
;
613 TRACE("drawstage:0x%x hdc:%p\n", dwDrawStage
, hdc
);
615 nmcd
= &nmcdhdr
.nmcd
;
616 nmcd
->dwDrawStage
= dwDrawStage
;
619 nmcd
->dwItemSpec
= 0;
620 nmcd
->uItemState
= 0;
621 nmcd
->lItemlParam
= 0;
622 nmcdhdr
.clrText
= infoPtr
->clrText
;
623 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
626 return TREEVIEW_SendRealNotify(infoPtr
, NM_CUSTOMDRAW
, &nmcdhdr
.nmcd
.hdr
);
629 /* FIXME: need to find out when the flags in uItemState need to be set */
632 TREEVIEW_SendCustomDrawItemNotify(const TREEVIEW_INFO
*infoPtr
, HDC hdc
,
633 TREEVIEW_ITEM
*item
, UINT uItemDrawState
,
634 NMTVCUSTOMDRAW
*nmcdhdr
)
638 DWORD_PTR dwItemSpec
;
641 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
642 dwItemSpec
= (DWORD_PTR
)item
;
644 if (item
->state
& TVIS_SELECTED
)
645 uItemState
|= CDIS_SELECTED
;
646 if (item
== infoPtr
->selectedItem
)
647 uItemState
|= CDIS_FOCUS
;
648 if (item
== infoPtr
->hotItem
)
649 uItemState
|= CDIS_HOT
;
651 nmcd
= &nmcdhdr
->nmcd
;
652 nmcd
->dwDrawStage
= dwDrawStage
;
654 nmcd
->rc
= item
->rect
;
655 nmcd
->dwItemSpec
= dwItemSpec
;
656 nmcd
->uItemState
= uItemState
;
657 nmcd
->lItemlParam
= item
->lParam
;
658 nmcdhdr
->iLevel
= item
->iLevel
;
660 TRACE("drawstage:0x%x hdc:%p item:%lx, itemstate:0x%x, lItemlParam:0x%lx\n",
661 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
662 nmcd
->uItemState
, nmcd
->lItemlParam
);
664 return TREEVIEW_SendRealNotify(infoPtr
, NM_CUSTOMDRAW
, &nmcdhdr
->nmcd
.hdr
);
668 TREEVIEW_BeginLabelEditNotify(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
673 TREEVIEW_TVItemFromItem(infoPtr
, TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
,
674 &tvdi
.item
, editItem
);
676 ret
= TREEVIEW_SendRealNotify(infoPtr
, TVN_BEGINLABELEDITW
, &tvdi
.hdr
);
678 if (!infoPtr
->bNtfUnicode
)
679 Free(tvdi
.item
.pszText
);
685 TREEVIEW_UpdateDispInfo(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
688 NMTVDISPINFOEXW callback
;
690 TRACE("mask=0x%x, callbackmask=0x%x\n", mask
, item
->callbackMask
);
691 mask
&= item
->callbackMask
;
693 if (mask
== 0) return;
695 /* 'state' always contains valid value, as well as 'lParam'.
696 * All other parameters are uninitialized.
698 callback
.item
.pszText
= item
->pszText
;
699 callback
.item
.cchTextMax
= item
->cchTextMax
;
700 callback
.item
.mask
= mask
;
701 callback
.item
.hItem
= item
;
702 callback
.item
.state
= item
->state
;
703 callback
.item
.lParam
= item
->lParam
;
705 /* If text is changed we need to recalculate textWidth */
706 if (mask
& TVIF_TEXT
)
709 TREEVIEW_SendRealNotify(infoPtr
, TVN_GETDISPINFOW
, &callback
.hdr
);
710 TRACE("resulting code 0x%08x\n", callback
.hdr
.code
);
712 /* It may have changed due to a call to SetItem. */
713 mask
&= item
->callbackMask
;
715 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= item
->pszText
)
717 /* Instead of copying text into our buffer user specified his own */
718 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
721 int len
= MultiByteToWideChar( CP_ACP
, 0,
722 (LPSTR
)callback
.item
.pszText
, -1,
724 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
725 newText
= ReAlloc(item
->pszText
, buflen
);
727 TRACE("returned str %s, len=%d, buflen=%d\n",
728 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
732 item
->pszText
= newText
;
733 MultiByteToWideChar( CP_ACP
, 0,
734 (LPSTR
)callback
.item
.pszText
, -1,
735 item
->pszText
, buflen
/sizeof(WCHAR
));
736 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
738 /* If ReAlloc fails we have nothing to do, but keep original text */
741 int len
= max(lstrlenW(callback
.item
.pszText
) + 1,
743 LPWSTR newText
= ReAlloc(item
->pszText
, len
);
745 TRACE("returned wstr %s, len=%d\n",
746 debugstr_w(callback
.item
.pszText
), len
);
750 item
->pszText
= newText
;
751 strcpyW(item
->pszText
, callback
.item
.pszText
);
752 item
->cchTextMax
= len
;
754 /* If ReAlloc fails we have nothing to do, but keep original text */
757 else if (mask
& TVIF_TEXT
) {
758 /* User put text into our buffer, that is ok unless A string */
759 if (!infoPtr
->bNtfUnicode
&& (callback
.hdr
.code
== TVN_GETDISPINFOA
)) {
762 int len
= MultiByteToWideChar( CP_ACP
, 0,
763 (LPSTR
)callback
.item
.pszText
, -1,
765 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
766 newText
= Alloc(buflen
);
768 TRACE("same buffer str %s, len=%d, buflen=%d\n",
769 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
773 LPWSTR oldText
= item
->pszText
;
774 item
->pszText
= newText
;
775 MultiByteToWideChar( CP_ACP
, 0,
776 (LPSTR
)callback
.item
.pszText
, -1,
777 item
->pszText
, buflen
/sizeof(WCHAR
));
778 item
->cchTextMax
= buflen
/sizeof(WCHAR
);
784 if (mask
& TVIF_IMAGE
)
785 item
->iImage
= callback
.item
.iImage
;
787 if (mask
& TVIF_SELECTEDIMAGE
)
788 item
->iSelectedImage
= callback
.item
.iSelectedImage
;
790 if (mask
& TVIF_EXPANDEDIMAGE
)
791 item
->iExpandedImage
= callback
.item
.iExpandedImage
;
793 if (mask
& TVIF_CHILDREN
)
794 item
->cChildren
= callback
.item
.cChildren
;
796 if (callback
.item
.mask
& TVIF_STATE
)
798 item
->state
&= ~callback
.item
.stateMask
;
799 item
->state
|= (callback
.item
.state
& callback
.item
.stateMask
);
802 /* These members are now permanently set. */
803 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
804 item
->callbackMask
&= ~callback
.item
.mask
;
807 /***************************************************************************
808 * This function uses cChildren field to decide whether the item has
810 * Note: if this returns TRUE, the child items may not actually exist,
811 * they could be virtual.
813 * Just use item->firstChild to check for physical children.
816 TREEVIEW_HasChildren(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
818 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_CHILDREN
);
820 return item
->cChildren
> 0;
823 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
827 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
829 if (nCommand
!= NF_REQUERY
) return 0;
831 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
832 TRACE("format=%d\n", format
);
834 /* Invalid format returned by NF_QUERY defaults to ANSI*/
835 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
)
838 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
843 /* Item Position ********************************************************/
845 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
847 TREEVIEW_ComputeItemInternalMetrics(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
849 /* has TVS_LINESATROOT and (TVS_HASLINES|TVS_HASBUTTONS) */
850 BOOL lar
= ((infoPtr
->dwStyle
& (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
853 item
->linesOffset
= infoPtr
->uIndent
* (lar
? item
->iLevel
: item
->iLevel
- 1)
855 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
856 item
->imageOffset
= item
->stateOffset
857 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
858 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
862 TREEVIEW_ComputeTextWidth(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
868 /* DRAW's OM docker creates items like this */
869 if (item
->pszText
== NULL
)
881 hdc
= GetDC(infoPtr
->hwnd
);
882 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
885 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
886 item
->textWidth
= sz
.cx
;
890 SelectObject(hdc
, hOldFont
);
896 TREEVIEW_ComputeItemRect(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
898 item
->rect
.top
= infoPtr
->uItemHeight
*
899 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
901 item
->rect
.bottom
= item
->rect
.top
902 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
905 item
->rect
.right
= infoPtr
->clientWidth
;
908 /* We know that only items after start need their order updated. */
910 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
917 start
= infoPtr
->root
->firstChild
;
921 order
= start
->visibleOrder
;
923 for (item
= start
; item
!= NULL
;
924 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
926 if (!ISVISIBLE(item
) && order
> 0)
927 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
928 item
->visibleOrder
= order
;
929 order
+= item
->iIntegral
;
932 infoPtr
->maxVisibleOrder
= order
;
934 for (item
= start
; item
!= NULL
;
935 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
937 TREEVIEW_ComputeItemRect(infoPtr
, item
);
942 /* Update metrics of all items in selected subtree.
943 * root must be expanded
946 TREEVIEW_UpdateSubTree(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
948 TREEVIEW_ITEM
*sibling
;
952 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
955 root
->state
&= ~TVIS_EXPANDED
;
956 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
957 root
->state
|= TVIS_EXPANDED
;
959 hdc
= GetDC(infoPtr
->hwnd
);
960 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
962 for (; root
!= sibling
;
963 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
965 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
967 if (root
->callbackMask
& TVIF_TEXT
)
968 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
970 if (root
->textWidth
== 0)
972 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
973 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
977 SelectObject(hdc
, hOldFont
);
978 ReleaseDC(infoPtr
->hwnd
, hdc
);
981 /* Item Allocation **********************************************************/
983 static TREEVIEW_ITEM
*
984 TREEVIEW_AllocateItem(const TREEVIEW_INFO
*infoPtr
)
986 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
991 /* I_IMAGENONE would make more sense but this is neither what is
992 * documented (MSDN doesn't specify) nor what Windows actually does
993 * (it sets it to zero)... and I can so imagine an application using
994 * inc/dec to toggle the images. */
996 newItem
->iSelectedImage
= 0;
997 newItem
->iExpandedImage
= (WORD
)I_IMAGENONE
;
998 newItem
->infoPtr
= infoPtr
;
1000 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
1009 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
1010 * free item->pszText. */
1012 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1014 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
1015 if (infoPtr
->selectedItem
== item
)
1016 infoPtr
->selectedItem
= NULL
;
1017 if (infoPtr
->hotItem
== item
)
1018 infoPtr
->hotItem
= NULL
;
1019 if (infoPtr
->focusedItem
== item
)
1020 infoPtr
->focusedItem
= NULL
;
1021 if (infoPtr
->firstVisible
== item
)
1022 infoPtr
->firstVisible
= NULL
;
1023 if (infoPtr
->dropItem
== item
)
1024 infoPtr
->dropItem
= NULL
;
1025 if (infoPtr
->insertMarkItem
== item
)
1026 infoPtr
->insertMarkItem
= NULL
;
1031 /* Item Insertion *******************************************************/
1033 /***************************************************************************
1034 * This method inserts newItem before sibling as a child of parent.
1035 * sibling can be NULL, but only if parent has no children.
1038 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1039 TREEVIEW_ITEM
*parent
)
1041 assert(parent
!= NULL
);
1043 if (sibling
!= NULL
)
1045 assert(sibling
->parent
== parent
);
1047 if (sibling
->prevSibling
!= NULL
)
1048 sibling
->prevSibling
->nextSibling
= newItem
;
1050 newItem
->prevSibling
= sibling
->prevSibling
;
1051 sibling
->prevSibling
= newItem
;
1054 newItem
->prevSibling
= NULL
;
1056 newItem
->nextSibling
= sibling
;
1058 if (parent
->firstChild
== sibling
)
1059 parent
->firstChild
= newItem
;
1061 if (parent
->lastChild
== NULL
)
1062 parent
->lastChild
= newItem
;
1065 /***************************************************************************
1066 * This method inserts newItem after sibling as a child of parent.
1067 * sibling can be NULL, but only if parent has no children.
1070 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1071 TREEVIEW_ITEM
*parent
)
1073 assert(parent
!= NULL
);
1075 if (sibling
!= NULL
)
1077 assert(sibling
->parent
== parent
);
1079 if (sibling
->nextSibling
!= NULL
)
1080 sibling
->nextSibling
->prevSibling
= newItem
;
1082 newItem
->nextSibling
= sibling
->nextSibling
;
1083 sibling
->nextSibling
= newItem
;
1086 newItem
->nextSibling
= NULL
;
1088 newItem
->prevSibling
= sibling
;
1090 if (parent
->lastChild
== sibling
)
1091 parent
->lastChild
= newItem
;
1093 if (parent
->firstChild
== NULL
)
1094 parent
->firstChild
= newItem
;
1098 TREEVIEW_DoSetItemT(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
1099 const TVITEMEXW
*tvItem
, BOOL isW
)
1101 UINT callbackClear
= 0;
1102 UINT callbackSet
= 0;
1104 TRACE("item %p\n", item
);
1105 /* Do this first in case it fails. */
1106 if (tvItem
->mask
& TVIF_TEXT
)
1108 item
->textWidth
= 0; /* force width recalculation */
1109 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKW
&& tvItem
->pszText
!= NULL
) /* covers != TEXTCALLBACKA too, and undocumented: pszText of NULL also means TEXTCALLBACK */
1114 len
= lstrlenW(tvItem
->pszText
) + 1;
1116 len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1, NULL
, 0);
1118 newText
= ReAlloc(item
->pszText
, len
* sizeof(WCHAR
));
1120 if (newText
== NULL
) return FALSE
;
1122 callbackClear
|= TVIF_TEXT
;
1124 item
->pszText
= newText
;
1125 item
->cchTextMax
= len
;
1127 lstrcpynW(item
->pszText
, tvItem
->pszText
, len
);
1129 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1,
1130 item
->pszText
, len
);
1132 TRACE("setting text %s, item %p\n", debugstr_w(item
->pszText
), item
);
1136 callbackSet
|= TVIF_TEXT
;
1138 item
->pszText
= ReAlloc(item
->pszText
,
1139 TEXT_CALLBACK_SIZE
* sizeof(WCHAR
));
1140 item
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1141 TRACE("setting callback, item %p\n", item
);
1145 if (tvItem
->mask
& TVIF_CHILDREN
)
1147 item
->cChildren
= tvItem
->cChildren
;
1149 if (item
->cChildren
== I_CHILDRENCALLBACK
)
1150 callbackSet
|= TVIF_CHILDREN
;
1152 callbackClear
|= TVIF_CHILDREN
;
1155 if (tvItem
->mask
& TVIF_IMAGE
)
1157 item
->iImage
= tvItem
->iImage
;
1159 if (item
->iImage
== I_IMAGECALLBACK
)
1160 callbackSet
|= TVIF_IMAGE
;
1162 callbackClear
|= TVIF_IMAGE
;
1165 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1167 item
->iSelectedImage
= tvItem
->iSelectedImage
;
1169 if (item
->iSelectedImage
== I_IMAGECALLBACK
)
1170 callbackSet
|= TVIF_SELECTEDIMAGE
;
1172 callbackClear
|= TVIF_SELECTEDIMAGE
;
1175 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
1177 item
->iExpandedImage
= tvItem
->iExpandedImage
;
1179 if (item
->iExpandedImage
== I_IMAGECALLBACK
)
1180 callbackSet
|= TVIF_EXPANDEDIMAGE
;
1182 callbackClear
|= TVIF_EXPANDEDIMAGE
;
1185 if (tvItem
->mask
& TVIF_PARAM
)
1186 item
->lParam
= tvItem
->lParam
;
1188 /* If the application sets TVIF_INTEGRAL without
1189 * supplying a TVITEMEX structure, it's toast. */
1190 if (tvItem
->mask
& TVIF_INTEGRAL
)
1191 item
->iIntegral
= tvItem
->iIntegral
;
1193 if (tvItem
->mask
& TVIF_STATE
)
1195 TRACE("prevstate 0x%x, state 0x%x, mask 0x%x\n", item
->state
, tvItem
->state
,
1197 item
->state
&= ~tvItem
->stateMask
;
1198 item
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1201 if (tvItem
->mask
& TVIF_STATEEX
)
1203 FIXME("New extended state: 0x%x\n", tvItem
->uStateEx
);
1206 item
->callbackMask
|= callbackSet
;
1207 item
->callbackMask
&= ~callbackClear
;
1212 /* Note that the new item is pre-zeroed. */
1214 TREEVIEW_InsertItemT(TREEVIEW_INFO
*infoPtr
, const TVINSERTSTRUCTW
*ptdi
, BOOL isW
)
1216 const TVITEMEXW
*tvItem
= &ptdi
->u
.itemex
;
1217 HTREEITEM insertAfter
;
1218 TREEVIEW_ITEM
*newItem
, *parentItem
;
1219 BOOL bTextUpdated
= FALSE
;
1221 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1223 parentItem
= infoPtr
->root
;
1227 parentItem
= ptdi
->hParent
;
1229 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1231 WARN("invalid parent %p\n", parentItem
);
1236 insertAfter
= ptdi
->hInsertAfter
;
1238 /* Validate this now for convenience. */
1239 switch ((DWORD_PTR
)insertAfter
)
1241 case (DWORD_PTR
)TVI_FIRST
:
1242 case (DWORD_PTR
)TVI_LAST
:
1243 case (DWORD_PTR
)TVI_SORT
:
1247 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1248 insertAfter
->parent
!= parentItem
)
1250 WARN("invalid insert after %p\n", insertAfter
);
1251 insertAfter
= TVI_LAST
;
1255 TRACE("parent %p position %p: %s\n", parentItem
, insertAfter
,
1256 (tvItem
->mask
& TVIF_TEXT
)
1257 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKW
) ? "<callback>"
1258 : (isW
? debugstr_w(tvItem
->pszText
) : debugstr_a((LPSTR
)tvItem
->pszText
)))
1261 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1262 if (newItem
== NULL
)
1265 newItem
->parent
= parentItem
;
1266 newItem
->iIntegral
= 1;
1267 newItem
->visibleOrder
= -1;
1269 if (!TREEVIEW_DoSetItemT(infoPtr
, newItem
, tvItem
, isW
))
1272 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1274 infoPtr
->uNumItems
++;
1276 switch ((DWORD_PTR
)insertAfter
)
1278 case (DWORD_PTR
)TVI_FIRST
:
1280 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1281 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1282 if (infoPtr
->firstVisible
== originalFirst
)
1283 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1287 case (DWORD_PTR
)TVI_LAST
:
1288 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1291 /* hInsertAfter names a specific item we want to insert after */
1293 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1296 case (DWORD_PTR
)TVI_SORT
:
1298 TREEVIEW_ITEM
*aChild
;
1299 TREEVIEW_ITEM
*previousChild
= NULL
;
1300 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1301 BOOL bItemInserted
= FALSE
;
1303 aChild
= parentItem
->firstChild
;
1305 bTextUpdated
= TRUE
;
1306 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1308 /* Iterate the parent children to see where we fit in */
1309 while (aChild
!= NULL
)
1313 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1314 comp
= lstrcmpW(newItem
->pszText
, aChild
->pszText
);
1316 if (comp
< 0) /* we are smaller than the current one */
1318 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1319 if (infoPtr
->firstVisible
== originalFirst
&&
1320 aChild
== originalFirst
)
1321 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1322 bItemInserted
= TRUE
;
1325 else if (comp
> 0) /* we are bigger than the current one */
1327 previousChild
= aChild
;
1329 /* This will help us to exit if there is no more sibling */
1330 aChild
= (aChild
->nextSibling
== 0)
1332 : aChild
->nextSibling
;
1334 /* Look at the next item */
1340 * An item with this name is already existing, therefore,
1341 * we add after the one we found
1343 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1344 bItemInserted
= TRUE
;
1350 * we reach the end of the child list and the item has not
1351 * yet been inserted, therefore, insert it after the last child.
1353 if ((!bItemInserted
) && (aChild
== NULL
))
1354 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1361 TRACE("new item %p; parent %p, mask 0x%x\n", newItem
,
1362 newItem
->parent
, tvItem
->mask
);
1364 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1366 if (newItem
->parent
->cChildren
== 0)
1367 newItem
->parent
->cChildren
= 1;
1369 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1371 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1372 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1375 if (infoPtr
->firstVisible
== NULL
)
1376 infoPtr
->firstVisible
= newItem
;
1378 TREEVIEW_VerifyTree(infoPtr
);
1380 if (!infoPtr
->bRedraw
) return (LRESULT
)newItem
;
1382 if (parentItem
== infoPtr
->root
||
1383 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1385 TREEVIEW_ITEM
*item
;
1386 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1388 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1389 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1392 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1394 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1395 TREEVIEW_UpdateScrollBars(infoPtr
);
1397 * if the item was inserted in a visible part of the tree,
1398 * invalidate it, as well as those after it
1400 for (item
= newItem
;
1402 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1403 TREEVIEW_Invalidate(infoPtr
, item
);
1407 /* refresh treeview if newItem is the first item inserted under parentItem */
1408 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1410 /* parent got '+' - update it */
1411 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1415 return (LRESULT
)newItem
;
1418 /* Item Deletion ************************************************************/
1420 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
1423 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*parentItem
)
1425 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1427 while (kill
!= NULL
)
1429 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1431 TREEVIEW_RemoveItem(infoPtr
, kill
);
1436 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1437 assert(parentItem
->firstChild
== NULL
);
1438 assert(parentItem
->lastChild
== NULL
);
1442 TREEVIEW_UnlinkItem(const TREEVIEW_ITEM
*item
)
1444 TREEVIEW_ITEM
*parentItem
;
1446 assert(item
!= NULL
);
1447 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1449 parentItem
= item
->parent
;
1451 if (parentItem
->firstChild
== item
)
1452 parentItem
->firstChild
= item
->nextSibling
;
1454 if (parentItem
->lastChild
== item
)
1455 parentItem
->lastChild
= item
->prevSibling
;
1457 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1458 && parentItem
->cChildren
> 0)
1459 parentItem
->cChildren
= 0;
1461 if (item
->prevSibling
)
1462 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1464 if (item
->nextSibling
)
1465 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1469 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1471 TRACE("%p, (%s)\n", item
, TREEVIEW_ItemName(item
));
1473 if (item
->firstChild
)
1474 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
1476 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1477 TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
1479 TREEVIEW_UnlinkItem(item
);
1481 infoPtr
->uNumItems
--;
1483 if (item
->pszText
!= LPSTR_TEXTCALLBACKW
)
1484 Free(item
->pszText
);
1486 TREEVIEW_FreeItem(infoPtr
, item
);
1490 /* Empty out the tree. */
1492 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1494 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1496 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1500 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
)
1502 TREEVIEW_ITEM
*newSelection
= NULL
;
1503 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1504 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1505 BOOL visible
= FALSE
;
1507 if (item
== TVI_ROOT
|| !item
)
1509 TRACE("TVI_ROOT\n");
1510 parent
= infoPtr
->root
;
1511 newSelection
= NULL
;
1513 TREEVIEW_RemoveTree(infoPtr
);
1517 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1520 TRACE("%p (%s)\n", item
, TREEVIEW_ItemName(item
));
1521 parent
= item
->parent
;
1523 if (ISVISIBLE(item
))
1525 prev
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
1529 if (infoPtr
->selectedItem
!= NULL
1530 && (item
== infoPtr
->selectedItem
1531 || TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
)))
1533 if (item
->nextSibling
)
1534 newSelection
= item
->nextSibling
;
1535 else if (item
->parent
!= infoPtr
->root
)
1536 newSelection
= item
->parent
;
1538 newSelection
= item
->prevSibling
;
1539 TRACE("newSelection = %p\n", newSelection
);
1542 if (infoPtr
->firstVisible
== item
)
1544 if (item
->nextSibling
)
1545 newFirstVisible
= item
->nextSibling
;
1546 else if (item
->prevSibling
)
1547 newFirstVisible
= item
->prevSibling
;
1548 else if (item
->parent
!= infoPtr
->root
)
1549 newFirstVisible
= item
->parent
;
1550 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1553 newFirstVisible
= infoPtr
->firstVisible
;
1555 TREEVIEW_RemoveItem(infoPtr
, item
);
1558 /* Don't change if somebody else already has (infoPtr->selectedItem is cleared by FreeItem). */
1559 if (!infoPtr
->selectedItem
&& newSelection
)
1561 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1562 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1565 /* Validate insertMark dropItem.
1566 * hotItem ??? - used for comparison only.
1568 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1569 infoPtr
->insertMarkItem
= 0;
1571 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1572 infoPtr
->dropItem
= 0;
1574 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1575 newFirstVisible
= infoPtr
->root
->firstChild
;
1577 TREEVIEW_VerifyTree(infoPtr
);
1579 if (!infoPtr
->bRedraw
) return TRUE
;
1583 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1584 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1585 TREEVIEW_UpdateScrollBars(infoPtr
);
1586 TREEVIEW_Invalidate(infoPtr
, NULL
);
1588 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1590 /* parent lost '+/-' - update it */
1591 TREEVIEW_Invalidate(infoPtr
, parent
);
1598 /* Get/Set Messages *********************************************************/
1600 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
)
1602 infoPtr
->bRedraw
= wParam
!= 0;
1604 if (infoPtr
->bRedraw
)
1606 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1607 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1608 TREEVIEW_UpdateScrollBars(infoPtr
);
1609 TREEVIEW_Invalidate(infoPtr
, NULL
);
1615 TREEVIEW_GetIndent(const TREEVIEW_INFO
*infoPtr
)
1618 return infoPtr
->uIndent
;
1622 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1626 if (newIndent
< MINIMUM_INDENT
)
1627 newIndent
= MINIMUM_INDENT
;
1629 if (infoPtr
->uIndent
!= newIndent
)
1631 infoPtr
->uIndent
= newIndent
;
1632 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1633 TREEVIEW_UpdateScrollBars(infoPtr
);
1634 TREEVIEW_Invalidate(infoPtr
, NULL
);
1642 TREEVIEW_GetToolTips(const TREEVIEW_INFO
*infoPtr
)
1645 return (LRESULT
)infoPtr
->hwndToolTip
;
1649 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1654 prevToolTip
= infoPtr
->hwndToolTip
;
1655 infoPtr
->hwndToolTip
= hwndTT
;
1657 return (LRESULT
)prevToolTip
;
1661 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO
*infoPtr
, BOOL fUnicode
)
1663 BOOL rc
= infoPtr
->bNtfUnicode
;
1664 infoPtr
->bNtfUnicode
= fUnicode
;
1669 TREEVIEW_GetUnicodeFormat(const TREEVIEW_INFO
*infoPtr
)
1671 return infoPtr
->bNtfUnicode
;
1675 TREEVIEW_GetScrollTime(const TREEVIEW_INFO
*infoPtr
)
1677 return infoPtr
->uScrollTime
;
1681 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1683 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1685 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1687 return uOldScrollTime
;
1692 TREEVIEW_GetImageList(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1699 return (LRESULT
)infoPtr
->himlNormal
;
1702 return (LRESULT
)infoPtr
->himlState
;
1709 #define TVHEIGHT_MIN 16
1710 #define TVHEIGHT_FONT_ADJUST 3 /* 2 for focus border + 1 for margin some apps assume */
1712 /* Compute the natural height for items. */
1714 TREEVIEW_NaturalHeight(const TREEVIEW_INFO
*infoPtr
)
1718 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1721 /* Height is the maximum of:
1722 * 16 (a hack because our fonts are tiny), and
1723 * The text height + border & margin, and
1724 * The size of the normal image list
1726 GetTextMetricsW(hdc
, &tm
);
1727 SelectObject(hdc
, hOldFont
);
1730 height
= TVHEIGHT_MIN
;
1731 if (height
< tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
)
1732 height
= tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
;
1733 if (height
< infoPtr
->normalImageHeight
)
1734 height
= infoPtr
->normalImageHeight
;
1736 /* Round down, unless we support odd ("non even") heights. */
1737 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1744 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, UINT type
, HIMAGELIST himlNew
)
1746 HIMAGELIST himlOld
= 0;
1747 int oldWidth
= infoPtr
->normalImageWidth
;
1748 int oldHeight
= infoPtr
->normalImageHeight
;
1750 TRACE("%u,%p\n", type
, himlNew
);
1755 himlOld
= infoPtr
->himlNormal
;
1756 infoPtr
->himlNormal
= himlNew
;
1759 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1760 &infoPtr
->normalImageHeight
);
1763 infoPtr
->normalImageWidth
= 0;
1764 infoPtr
->normalImageHeight
= 0;
1770 himlOld
= infoPtr
->himlState
;
1771 infoPtr
->himlState
= himlNew
;
1774 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1775 &infoPtr
->stateImageHeight
);
1778 infoPtr
->stateImageWidth
= 0;
1779 infoPtr
->stateImageHeight
= 0;
1785 ERR("unknown imagelist type %u\n", type
);
1788 if (oldWidth
!= infoPtr
->normalImageWidth
||
1789 oldHeight
!= infoPtr
->normalImageHeight
)
1791 BOOL bRecalcVisible
= FALSE
;
1793 if (oldHeight
!= infoPtr
->normalImageHeight
&&
1794 !infoPtr
->bHeightSet
)
1796 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1797 bRecalcVisible
= TRUE
;
1800 if (infoPtr
->normalImageWidth
> MINIMUM_INDENT
&&
1801 infoPtr
->normalImageWidth
!= infoPtr
->uIndent
)
1803 infoPtr
->uIndent
= infoPtr
->normalImageWidth
;
1804 bRecalcVisible
= TRUE
;
1808 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1810 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1811 TREEVIEW_UpdateScrollBars(infoPtr
);
1814 TREEVIEW_Invalidate(infoPtr
, NULL
);
1816 return (LRESULT
)himlOld
;
1820 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1822 INT prevHeight
= infoPtr
->uItemHeight
;
1824 TRACE("new=%d, old=%d\n", newHeight
, prevHeight
);
1825 if (newHeight
== -1)
1827 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1828 infoPtr
->bHeightSet
= FALSE
;
1832 if (newHeight
== 0) newHeight
= 1;
1833 infoPtr
->uItemHeight
= newHeight
;
1834 infoPtr
->bHeightSet
= TRUE
;
1837 /* Round down, unless we support odd ("non even") heights. */
1838 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
) && infoPtr
->uItemHeight
!= 1)
1840 infoPtr
->uItemHeight
&= ~1;
1841 TRACE("after rounding=%d\n", infoPtr
->uItemHeight
);
1844 if (infoPtr
->uItemHeight
!= prevHeight
)
1846 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1847 TREEVIEW_UpdateScrollBars(infoPtr
);
1848 TREEVIEW_Invalidate(infoPtr
, NULL
);
1855 TREEVIEW_GetItemHeight(const TREEVIEW_INFO
*infoPtr
)
1858 return infoPtr
->uItemHeight
;
1863 TREEVIEW_GetFont(const TREEVIEW_INFO
*infoPtr
)
1865 TRACE("%p\n", infoPtr
->hFont
);
1866 return (LRESULT
)infoPtr
->hFont
;
1871 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1875 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1881 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1883 UINT uHeight
= infoPtr
->uItemHeight
;
1885 TRACE("%p %i\n", hFont
, bRedraw
);
1887 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
1889 DeleteObject(infoPtr
->hBoldFont
);
1890 DeleteObject(infoPtr
->hUnderlineFont
);
1891 DeleteObject(infoPtr
->hBoldUnderlineFont
);
1892 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1893 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
1894 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
1896 if (!infoPtr
->bHeightSet
)
1897 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1899 if (uHeight
!= infoPtr
->uItemHeight
)
1900 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1902 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1904 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1905 TREEVIEW_UpdateScrollBars(infoPtr
);
1908 TREEVIEW_Invalidate(infoPtr
, NULL
);
1915 TREEVIEW_GetLineColor(const TREEVIEW_INFO
*infoPtr
)
1918 return (LRESULT
)infoPtr
->clrLine
;
1922 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1924 COLORREF prevColor
= infoPtr
->clrLine
;
1927 infoPtr
->clrLine
= color
;
1928 return (LRESULT
)prevColor
;
1933 TREEVIEW_GetTextColor(const TREEVIEW_INFO
*infoPtr
)
1936 return (LRESULT
)infoPtr
->clrText
;
1940 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1942 COLORREF prevColor
= infoPtr
->clrText
;
1945 infoPtr
->clrText
= color
;
1947 if (infoPtr
->clrText
!= prevColor
)
1948 TREEVIEW_Invalidate(infoPtr
, NULL
);
1950 return (LRESULT
)prevColor
;
1955 TREEVIEW_GetBkColor(const TREEVIEW_INFO
*infoPtr
)
1958 return (LRESULT
)infoPtr
->clrBk
;
1962 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1964 COLORREF prevColor
= infoPtr
->clrBk
;
1967 infoPtr
->clrBk
= newColor
;
1969 if (newColor
!= prevColor
)
1970 TREEVIEW_Invalidate(infoPtr
, NULL
);
1972 return (LRESULT
)prevColor
;
1977 TREEVIEW_GetInsertMarkColor(const TREEVIEW_INFO
*infoPtr
)
1980 return (LRESULT
)infoPtr
->clrInsertMark
;
1984 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1986 COLORREF prevColor
= infoPtr
->clrInsertMark
;
1988 TRACE("0x%08x\n", color
);
1989 infoPtr
->clrInsertMark
= color
;
1991 return (LRESULT
)prevColor
;
1996 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
1998 TRACE("%d %p\n", wParam
, item
);
2000 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2003 infoPtr
->insertBeforeorAfter
= wParam
;
2004 infoPtr
->insertMarkItem
= item
;
2006 TREEVIEW_Invalidate(infoPtr
, NULL
);
2012 /************************************************************************
2013 * Some serious braindamage here. lParam is a pointer to both the
2014 * input HTREEITEM and the output RECT.
2017 TREEVIEW_GetItemRect(const TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
2019 TREEVIEW_ITEM
*item
;
2020 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
2028 if (!TREEVIEW_ValidItem(infoPtr
, item
) || !ISVISIBLE(item
))
2032 * If wParam is TRUE return the text size otherwise return
2033 * the whole item size
2037 /* Windows does not send TVN_GETDISPINFO here. */
2039 lpRect
->top
= item
->rect
.top
;
2040 lpRect
->bottom
= item
->rect
.bottom
;
2042 lpRect
->left
= item
->textOffset
;
2043 if (!item
->textWidth
)
2044 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2046 lpRect
->right
= item
->textOffset
+ item
->textWidth
+ 4;
2050 *lpRect
= item
->rect
;
2053 TRACE("%s [%s]\n", fTextRect
? "text" : "item", wine_dbgstr_rect(lpRect
));
2058 static inline LRESULT
2059 TREEVIEW_GetVisibleCount(const TREEVIEW_INFO
*infoPtr
)
2061 /* Surprise! This does not take integral height into account. */
2062 TRACE("client=%d, item=%d\n", infoPtr
->clientHeight
, infoPtr
->uItemHeight
);
2063 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2068 TREEVIEW_GetItemT(const TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2070 TREEVIEW_ITEM
*item
= tvItem
->hItem
;
2072 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2074 BOOL valid_item
= FALSE
;
2075 if (!item
) return FALSE
;
2079 infoPtr
= item
->infoPtr
;
2080 TRACE("got item from different tree %p, called from %p\n", item
->infoPtr
, infoPtr
);
2081 valid_item
= TREEVIEW_ValidItem(infoPtr
, item
);
2087 if (!valid_item
) return FALSE
;
2090 TREEVIEW_UpdateDispInfo(infoPtr
, item
, tvItem
->mask
);
2092 if (tvItem
->mask
& TVIF_CHILDREN
)
2094 if (item
->cChildren
==I_CHILDRENCALLBACK
)
2095 FIXME("I_CHILDRENCALLBACK not supported\n");
2096 tvItem
->cChildren
= item
->cChildren
;
2099 if (tvItem
->mask
& TVIF_HANDLE
)
2100 tvItem
->hItem
= item
;
2102 if (tvItem
->mask
& TVIF_IMAGE
)
2103 tvItem
->iImage
= item
->iImage
;
2105 if (tvItem
->mask
& TVIF_INTEGRAL
)
2106 tvItem
->iIntegral
= item
->iIntegral
;
2108 /* undocumented: (mask & TVIF_PARAM) ignored and lParam is always set */
2109 tvItem
->lParam
= item
->lParam
;
2111 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2112 tvItem
->iSelectedImage
= item
->iSelectedImage
;
2114 if (tvItem
->mask
& TVIF_EXPANDEDIMAGE
)
2115 tvItem
->iExpandedImage
= item
->iExpandedImage
;
2117 /* undocumented: stateMask and (state & TVIF_STATE) ignored, so state is always set */
2118 tvItem
->state
= item
->state
;
2120 if (tvItem
->mask
& TVIF_TEXT
)
2122 if (item
->pszText
== NULL
)
2124 if (tvItem
->cchTextMax
> 0)
2125 tvItem
->pszText
[0] = '\0';
2129 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2131 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2132 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2136 lstrcpynW(tvItem
->pszText
, item
->pszText
, tvItem
->cchTextMax
);
2141 if (item
->pszText
== LPSTR_TEXTCALLBACKW
)
2143 tvItem
->pszText
= (LPWSTR
)LPSTR_TEXTCALLBACKA
;
2144 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2148 WideCharToMultiByte(CP_ACP
, 0, item
->pszText
, -1,
2149 (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, NULL
, NULL
);
2154 if (tvItem
->mask
& TVIF_STATEEX
)
2156 FIXME("Extended item state not supported, returning 0.\n");
2157 tvItem
->uStateEx
= 0;
2160 TRACE("item <%p>, txt %p, img %d, mask 0x%x\n",
2161 item
, tvItem
->pszText
, tvItem
->iImage
, tvItem
->mask
);
2166 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2167 * which is wrong. */
2169 TREEVIEW_SetItemT(TREEVIEW_INFO
*infoPtr
, const TVITEMEXW
*tvItem
, BOOL isW
)
2171 TREEVIEW_ITEM
*item
;
2172 TREEVIEW_ITEM originalItem
;
2174 item
= tvItem
->hItem
;
2176 TRACE("item %d, mask 0x%x\n", TREEVIEW_GetItemIndex(infoPtr
, item
),
2179 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2182 /* store the original item values */
2183 originalItem
= *item
;
2185 if (!TREEVIEW_DoSetItemT(infoPtr
, item
, tvItem
, isW
))
2188 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2189 if ((tvItem
->mask
& TVIF_TEXT
2190 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2193 TREEVIEW_UpdateDispInfo(infoPtr
, item
, TVIF_TEXT
);
2194 TREEVIEW_ComputeTextWidth(infoPtr
, item
, 0);
2197 if (tvItem
->mask
!= 0 && ISVISIBLE(item
))
2199 /* The refresh updates everything, but we can't wait until then. */
2200 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
2202 /* if any of the item's values changed and it's not a callback, redraw the item */
2203 if (item_changed(&originalItem
, item
, tvItem
))
2205 if (tvItem
->mask
& TVIF_INTEGRAL
)
2207 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
2208 TREEVIEW_UpdateScrollBars(infoPtr
);
2210 TREEVIEW_Invalidate(infoPtr
, NULL
);
2214 TREEVIEW_UpdateScrollBars(infoPtr
);
2215 TREEVIEW_Invalidate(infoPtr
, item
);
2224 TREEVIEW_GetItemState(const TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, UINT mask
)
2228 if (!item
|| !TREEVIEW_ValidItem(infoPtr
, item
))
2231 return (item
->state
& mask
);
2235 TREEVIEW_GetNextItem(const TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM item
)
2237 TREEVIEW_ITEM
*retval
;
2241 /* handle all the global data here */
2244 case TVGN_CHILD
: /* Special case: child of 0 is root */
2249 retval
= infoPtr
->root
->firstChild
;
2253 retval
= infoPtr
->selectedItem
;
2256 case TVGN_FIRSTVISIBLE
:
2257 retval
= infoPtr
->firstVisible
;
2260 case TVGN_DROPHILITE
:
2261 retval
= infoPtr
->dropItem
;
2264 case TVGN_LASTVISIBLE
:
2265 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2271 TRACE("flags:0x%x, returns %p\n", which
, retval
);
2272 return (LRESULT
)retval
;
2275 if (item
== TVI_ROOT
) item
= infoPtr
->root
;
2277 if (!TREEVIEW_ValidItem(infoPtr
, item
))
2283 retval
= item
->nextSibling
;
2286 retval
= item
->prevSibling
;
2289 retval
= (item
->parent
!= infoPtr
->root
) ? item
->parent
: NULL
;
2292 retval
= item
->firstChild
;
2294 case TVGN_NEXTVISIBLE
:
2295 retval
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2297 case TVGN_PREVIOUSVISIBLE
:
2298 retval
= TREEVIEW_GetPrevListItem(infoPtr
, item
);
2301 TRACE("Unknown msg 0x%x, item %p\n", which
, item
);
2305 TRACE("flags: 0x%x, item %p;returns %p\n", which
, item
, retval
);
2306 return (LRESULT
)retval
;
2311 TREEVIEW_GetCount(const TREEVIEW_INFO
*infoPtr
)
2313 TRACE(" %d\n", infoPtr
->uNumItems
);
2314 return (LRESULT
)infoPtr
->uNumItems
;
2318 TREEVIEW_ToggleItemState(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2320 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2322 static const unsigned int state_table
[] = { 0, 2, 1 };
2326 state
= STATEIMAGEINDEX(item
->state
);
2327 TRACE("state: 0x%x\n", state
);
2328 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2331 state
= state_table
[state
];
2333 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2335 TRACE("state: 0x%x\n", state
);
2336 TREEVIEW_Invalidate(infoPtr
, item
);
2341 /* Painting *************************************************************/
2343 /* Draw the lines and expand button for an item. Also draws one section
2344 * of the line from item's parent to item's parent's next sibling. */
2346 TREEVIEW_DrawItemLines(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const TREEVIEW_ITEM
*item
)
2348 LONG centerx
, centery
;
2349 BOOL lar
= ((infoPtr
->dwStyle
2350 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2353 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2355 if (!lar
&& item
->iLevel
== 0)
2358 hbr
= CreateSolidBrush(clrBk
);
2359 hbrOld
= SelectObject(hdc
, hbr
);
2361 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2362 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2364 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2366 HPEN hOldPen
, hNewPen
;
2370 /* Get a dotted grey pen */
2371 lb
.lbStyle
= BS_SOLID
;
2372 lb
.lbColor
= GETLINECOLOR(infoPtr
->clrLine
);
2373 hNewPen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, NULL
);
2374 hOldPen
= SelectObject(hdc
, hNewPen
);
2376 /* Make sure the center is on a dot (using +2 instead
2377 * of +1 gives us pixel-by-pixel compat with native) */
2378 centery
= (centery
+ 2) & ~1;
2380 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2381 LineTo(hdc
, centerx
- 1, centery
);
2383 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2385 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2386 LineTo(hdc
, centerx
, centery
);
2389 if (item
->nextSibling
)
2391 MoveToEx(hdc
, centerx
, centery
, NULL
);
2392 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2395 /* Draw the line from our parent to its next sibling. */
2396 parent
= item
->parent
;
2397 while (parent
!= infoPtr
->root
)
2399 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2401 if (parent
->nextSibling
2402 /* skip top-levels unless TVS_LINESATROOT */
2403 && parent
->stateOffset
> parent
->linesOffset
)
2405 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2406 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2409 parent
= parent
->parent
;
2412 SelectObject(hdc
, hOldPen
);
2413 DeleteObject(hNewPen
);
2417 * Display the (+/-) signs
2420 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2422 if (item
->cChildren
)
2424 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
2427 RECT glyphRect
= item
->rect
;
2428 glyphRect
.left
= item
->linesOffset
;
2429 glyphRect
.right
= item
->stateOffset
;
2430 DrawThemeBackground (theme
, hdc
, TVP_GLYPH
,
2431 (item
->state
& TVIS_EXPANDED
) ? GLPS_OPENED
: GLPS_CLOSED
,
2436 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2437 LONG width
= item
->stateOffset
- item
->linesOffset
;
2438 LONG rectsize
= min(height
, width
) / 4;
2439 /* plussize = ceil(rectsize * 3/4) */
2440 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2442 HPEN new_pen
= CreatePen(PS_SOLID
, 0, GETLINECOLOR(infoPtr
->clrLine
));
2443 HPEN old_pen
= SelectObject(hdc
, new_pen
);
2445 Rectangle(hdc
, centerx
- rectsize
- 1, centery
- rectsize
- 1,
2446 centerx
+ rectsize
+ 2, centery
+ rectsize
+ 2);
2448 SelectObject(hdc
, old_pen
);
2449 DeleteObject(new_pen
);
2451 /* draw +/- signs with current text color */
2452 new_pen
= CreatePen(PS_SOLID
, 0, GETTXTCOLOR(infoPtr
->clrText
));
2453 old_pen
= SelectObject(hdc
, new_pen
);
2455 if (height
< 18 || width
< 18)
2457 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2458 LineTo(hdc
, centerx
+ plussize
, centery
);
2460 if (!(item
->state
& TVIS_EXPANDED
) ||
2461 (item
->state
& TVIS_EXPANDPARTIAL
))
2463 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2464 LineTo(hdc
, centerx
, centery
+ plussize
);
2469 Rectangle(hdc
, centerx
- plussize
+ 1, centery
- 1,
2470 centerx
+ plussize
, centery
+ 2);
2472 if (!(item
->state
& TVIS_EXPANDED
) ||
2473 (item
->state
& TVIS_EXPANDPARTIAL
))
2475 Rectangle(hdc
, centerx
- 1, centery
- plussize
+ 1,
2476 centerx
+ 2, centery
+ plussize
);
2477 SetPixel(hdc
, centerx
- 1, centery
, clrBk
);
2478 SetPixel(hdc
, centerx
+ 1, centery
, clrBk
);
2482 SelectObject(hdc
, old_pen
);
2483 DeleteObject(new_pen
);
2487 SelectObject(hdc
, hbrOld
);
2492 TREEVIEW_DrawItem(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*item
)
2496 COLORREF oldTextColor
, oldTextBkColor
;
2498 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2499 NMTVCUSTOMDRAW nmcdhdr
;
2501 TREEVIEW_UpdateDispInfo(infoPtr
, item
, CALLBACK_MASK_ALL
);
2503 /* - If item is drop target or it is selected and window is in focus -
2504 * use blue background (COLOR_HIGHLIGHT).
2505 * - If item is selected, window is not in focus, but it has style
2506 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2507 * - Otherwise - use background color
2509 if ((item
->state
& TVIS_DROPHILITED
) || ((item
== infoPtr
->focusedItem
) && !(item
->state
& TVIS_SELECTED
)) ||
2510 ((item
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
|| item
== infoPtr
->focusedItem
) &&
2511 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2513 if ((item
->state
& TVIS_DROPHILITED
) || inFocus
)
2515 nmcdhdr
.clrTextBk
= comctl32_color
.clrHighlight
;
2516 nmcdhdr
.clrText
= comctl32_color
.clrHighlightText
;
2520 nmcdhdr
.clrTextBk
= comctl32_color
.clrBtnFace
;
2521 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2526 nmcdhdr
.clrTextBk
= GETBKCOLOR(infoPtr
->clrBk
);
2527 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
2528 nmcdhdr
.clrText
= comctl32_color
.clrHighlight
;
2530 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2533 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
2535 /* The custom draw handler can query the text rectangle,
2537 /* should already be known, set to 0 when changed */
2538 if (!item
->textWidth
)
2539 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2543 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2545 cditem
= TREEVIEW_SendCustomDrawItemNotify
2546 (infoPtr
, hdc
, item
, CDDS_ITEMPREPAINT
, &nmcdhdr
);
2547 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2549 if (cditem
& CDRF_SKIPDEFAULT
)
2551 SelectObject(hdc
, hOldFont
);
2556 if (cditem
& CDRF_NEWFONT
)
2557 TREEVIEW_ComputeTextWidth(infoPtr
, item
, hdc
);
2559 TREEVIEW_DrawItemLines(infoPtr
, hdc
, item
);
2561 /* Set colors. Custom draw handler can change these so we do this after it. */
2562 oldTextColor
= SetTextColor(hdc
, nmcdhdr
.clrText
);
2563 oldTextBkColor
= SetBkColor(hdc
, nmcdhdr
.clrTextBk
);
2565 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2568 * Display the images associated with this item
2573 /* State images are displayed to the left of the Normal image
2574 * image number is in state; zero should be `display no image'.
2576 imageIndex
= STATEIMAGEINDEX(item
->state
);
2578 if (infoPtr
->himlState
&& imageIndex
)
2580 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2582 centery
- infoPtr
->stateImageHeight
/ 2,
2586 /* Now, draw the normal image; can be either selected,
2587 * non-selected or expanded image.
2590 if ((item
->state
& TVIS_SELECTED
) && (item
->iSelectedImage
>= 0))
2592 /* The item is currently selected */
2593 imageIndex
= item
->iSelectedImage
;
2595 else if ((item
->state
& TVIS_EXPANDED
) && (item
->iExpandedImage
!= (WORD
)I_IMAGENONE
))
2597 /* The item is currently not selected but expanded */
2598 imageIndex
= item
->iExpandedImage
;
2602 /* The item is not selected and not expanded */
2603 imageIndex
= item
->iImage
;
2606 if (infoPtr
->himlNormal
)
2608 UINT style
= item
->state
& TVIS_CUT
? ILD_SELECTED
: ILD_NORMAL
;
2610 style
|= item
->state
& TVIS_OVERLAYMASK
;
2612 ImageList_DrawEx(infoPtr
->himlNormal
, imageIndex
, hdc
,
2613 item
->imageOffset
, centery
- infoPtr
->normalImageHeight
/ 2,
2614 0, 0, infoPtr
->clrBk
, item
->state
& TVIS_CUT
? GETBKCOLOR(infoPtr
->clrBk
) : CLR_DEFAULT
,
2621 * Display the text associated with this item
2624 /* Don't paint item's text if it's being edited */
2625 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= item
))
2633 rcText
.top
= item
->rect
.top
;
2634 rcText
.bottom
= item
->rect
.bottom
;
2635 rcText
.left
= item
->textOffset
;
2636 rcText
.right
= rcText
.left
+ item
->textWidth
+ 4;
2638 TRACE("drawing text %s at (%s)\n",
2639 debugstr_w(item
->pszText
), wine_dbgstr_rect(&rcText
));
2642 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
2644 align
= SetTextAlign(hdc
, TA_LEFT
| TA_TOP
);
2645 ExtTextOutW(hdc
, rcText
.left
+ 2, (rcText
.top
+ rcText
.bottom
- sz
.cy
) / 2,
2646 ETO_CLIPPED
| ETO_OPAQUE
,
2649 lstrlenW(item
->pszText
),
2651 SetTextAlign(hdc
, align
);
2653 /* Draw focus box around the selected item */
2654 if ((item
== infoPtr
->selectedItem
) && inFocus
)
2656 DrawFocusRect(hdc
,&rcText
);
2661 /* Draw insertion mark if necessary */
2663 if (infoPtr
->insertMarkItem
)
2664 TRACE("item:%d,mark:%p\n",
2665 TREEVIEW_GetItemIndex(infoPtr
, item
),
2666 infoPtr
->insertMarkItem
);
2668 if (item
== infoPtr
->insertMarkItem
)
2670 HPEN hNewPen
, hOldPen
;
2674 hNewPen
= CreatePen(PS_SOLID
, 2, GETINSCOLOR(infoPtr
->clrInsertMark
));
2675 hOldPen
= SelectObject(hdc
, hNewPen
);
2677 if (infoPtr
->insertBeforeorAfter
)
2678 offset
= item
->rect
.bottom
- 1;
2680 offset
= item
->rect
.top
+ 1;
2682 left
= item
->textOffset
- 2;
2683 right
= item
->textOffset
+ item
->textWidth
+ 2;
2685 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2686 LineTo(hdc
, left
, offset
+ 4);
2688 MoveToEx(hdc
, left
, offset
, NULL
);
2689 LineTo(hdc
, right
+ 1, offset
);
2691 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2692 LineTo(hdc
, right
, offset
- 4);
2694 SelectObject(hdc
, hOldPen
);
2695 DeleteObject(hNewPen
);
2698 /* Restore the hdc state */
2699 SetTextColor(hdc
, oldTextColor
);
2700 SetBkColor(hdc
, oldTextBkColor
);
2701 SelectObject(hdc
, hOldFont
);
2703 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2705 cditem
= TREEVIEW_SendCustomDrawItemNotify
2706 (infoPtr
, hdc
, item
, CDDS_ITEMPOSTPAINT
, &nmcdhdr
);
2707 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2711 /* Computes treeHeight and treeWidth and updates the scroll bars.
2714 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2716 TREEVIEW_ITEM
*item
;
2717 HWND hwnd
= infoPtr
->hwnd
;
2721 LONG scrollX
= infoPtr
->scrollX
;
2723 infoPtr
->treeWidth
= 0;
2724 infoPtr
->treeHeight
= 0;
2726 /* We iterate through all visible items in order to get the tree height
2728 item
= infoPtr
->root
->firstChild
;
2730 while (item
!= NULL
)
2732 if (ISVISIBLE(item
))
2734 /* actually we draw text at textOffset + 2 */
2735 if (2+item
->textOffset
+item
->textWidth
> infoPtr
->treeWidth
)
2736 infoPtr
->treeWidth
= item
->textOffset
+item
->textWidth
+2;
2738 /* This is scroll-adjusted, but we fix this below. */
2739 infoPtr
->treeHeight
= item
->rect
.bottom
;
2742 item
= TREEVIEW_GetNextListItem(infoPtr
, item
);
2745 /* Fix the scroll adjusted treeHeight and treeWidth. */
2746 if (infoPtr
->root
->firstChild
)
2747 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2749 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2751 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2753 /* Adding one scroll bar may take up enough space that it forces us
2754 * to add the other as well. */
2755 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2759 if (infoPtr
->treeWidth
2760 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2763 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
|| infoPtr
->scrollX
> 0)
2766 if (!vert
&& horz
&& infoPtr
->treeHeight
2767 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2770 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2772 si
.cbSize
= sizeof(SCROLLINFO
);
2773 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2778 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2779 if ( si
.nPage
&& NULL
!= infoPtr
->firstVisible
)
2781 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2782 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2784 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2786 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2787 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2788 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2792 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2793 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2794 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2799 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2800 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2801 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2806 si
.nPage
= infoPtr
->clientWidth
;
2807 si
.nPos
= infoPtr
->scrollX
;
2808 si
.nMax
= infoPtr
->treeWidth
- 1;
2810 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2812 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2816 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2817 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2818 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2820 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2821 TREEVIEW_HScroll(infoPtr
,
2822 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2826 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2827 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2828 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2831 if (infoPtr
->scrollX
!= 0)
2833 TREEVIEW_HScroll(infoPtr
,
2834 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2839 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2843 TREEVIEW_FillBkgnd(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2846 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2848 hBrush
= CreateSolidBrush(clrBk
);
2849 FillRect(hdc
, rc
, hBrush
);
2850 DeleteObject(hBrush
);
2853 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2855 TREEVIEW_EraseBackground(const TREEVIEW_INFO
*infoPtr
, HDC hdc
)
2859 TRACE("%p\n", infoPtr
);
2861 GetClientRect(infoPtr
->hwnd
, &rect
);
2862 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rect
);
2868 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2870 HWND hwnd
= infoPtr
->hwnd
;
2872 TREEVIEW_ITEM
*item
;
2874 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2876 TRACE("empty window\n");
2880 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2883 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2885 ReleaseDC(hwnd
, hdc
);
2889 for (item
= infoPtr
->root
->firstChild
;
2891 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
2893 if (ISVISIBLE(item
))
2895 /* Avoid unneeded calculations */
2896 if (item
->rect
.top
> rect
.bottom
)
2898 if (item
->rect
.bottom
< rect
.top
)
2901 TREEVIEW_DrawItem(infoPtr
, hdc
, item
);
2905 TREEVIEW_UpdateScrollBars(infoPtr
);
2907 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2909 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2913 TREEVIEW_InvalidateItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2915 if (item
) InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2919 TREEVIEW_Invalidate(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2922 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2924 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2928 TREEVIEW_InitCheckboxes(TREEVIEW_INFO
*infoPtr
)
2931 HBITMAP hbm
, hbmOld
;
2935 infoPtr
->himlState
= ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
2937 hdcScreen
= GetDC(0);
2939 hdc
= CreateCompatibleDC(hdcScreen
);
2940 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
2941 hbmOld
= SelectObject(hdc
, hbm
);
2943 SetRect(&rc
, 0, 0, 48, 16);
2944 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
2946 SetRect(&rc
, 18, 2, 30, 14);
2947 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2948 DFCS_BUTTONCHECK
|DFCS_FLAT
);
2950 SetRect(&rc
, 34, 2, 46, 14);
2951 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
2952 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
2954 SelectObject(hdc
, hbmOld
);
2955 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
2956 comctl32_color
.clrWindow
);
2957 TRACE("checkbox index %d\n", nIndex
);
2961 ReleaseDC(0, hdcScreen
);
2963 infoPtr
->stateImageWidth
= 16;
2964 infoPtr
->stateImageHeight
= 16;
2968 TREEVIEW_ResetImageStateIndex(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2970 TREEVIEW_ITEM
*child
= item
->firstChild
;
2972 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2973 item
->state
|= INDEXTOSTATEIMAGEMASK(1);
2977 TREEVIEW_ITEM
*next
= child
->nextSibling
;
2978 TREEVIEW_ResetImageStateIndex(infoPtr
, child
);
2984 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, HDC hdc_ref
)
2990 TRACE("(%p %p)\n", infoPtr
, hdc_ref
);
2992 if ((infoPtr
->dwStyle
& TVS_CHECKBOXES
) && !infoPtr
->himlState
)
2994 TREEVIEW_InitCheckboxes(infoPtr
);
2995 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
2997 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
2998 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
2999 TREEVIEW_UpdateScrollBars(infoPtr
);
3000 TREEVIEW_Invalidate(infoPtr
, NULL
);
3006 GetClientRect(infoPtr
->hwnd
, &rc
);
3007 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
3011 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
3014 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
3017 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
3018 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
3021 EndPaint(infoPtr
->hwnd
, &ps
);
3027 TREEVIEW_PrintClient(TREEVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
3029 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
3031 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwnd
))
3034 if (options
& PRF_ERASEBKGND
)
3035 TREEVIEW_EraseBackground(infoPtr
, hdc
);
3037 if (options
& PRF_CLIENT
)
3040 GetClientRect(infoPtr
->hwnd
, &rc
);
3041 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
3047 /* Sorting **************************************************************/
3049 /***************************************************************************
3050 * Forward the DPA local callback to the treeview owner callback
3053 TREEVIEW_CallBackCompare(const TREEVIEW_ITEM
*first
, const TREEVIEW_ITEM
*second
,
3054 const TVSORTCB
*pCallBackSort
)
3056 /* Forward the call to the client-defined callback */
3057 return pCallBackSort
->lpfnCompare(first
->lParam
,
3059 pCallBackSort
->lParam
);
3062 /***************************************************************************
3063 * Treeview native sort routine: sort on item text.
3066 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
3067 const TREEVIEW_INFO
*infoPtr
)
3069 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
3070 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
3072 if(first
->pszText
&& second
->pszText
)
3073 return lstrcmpiW(first
->pszText
, second
->pszText
);
3074 else if(first
->pszText
)
3076 else if(second
->pszText
)
3082 /* Returns the number of physical children belonging to item. */
3084 TREEVIEW_CountChildren(const TREEVIEW_ITEM
*item
)
3089 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
3095 /* Returns a DPA containing a pointer to each physical child of item in
3096 * sibling order. If item has no children, an empty DPA is returned. */
3098 TREEVIEW_BuildChildDPA(const TREEVIEW_ITEM
*item
)
3102 HDPA list
= DPA_Create(8);
3103 if (list
== 0) return NULL
;
3105 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
3107 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
3117 /***************************************************************************
3118 * Setup the treeview structure with regards of the sort method
3119 * and sort the children of the TV item specified in lParam
3120 * fRecurse: currently unused. Should be zero.
3121 * parent: if pSort!=NULL, should equal pSort->hParent.
3122 * otherwise, item which child items are to be sorted.
3123 * pSort: sort method info. if NULL, sort on item text.
3124 * if non-NULL, sort on item's lParam content, and let the
3125 * application decide what that means. See also TVM_SORTCHILDRENCB.
3129 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, HTREEITEM parent
,
3133 PFNDPACOMPARE pfnCompare
;
3136 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
3137 if (parent
== TVI_ROOT
|| parent
== NULL
)
3138 parent
= infoPtr
->root
;
3140 /* Check for a valid handle to the parent item */
3141 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
3143 ERR("invalid item hParent=%p\n", parent
);
3149 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
3150 lpCompare
= (LPARAM
)pSort
;
3154 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
3155 lpCompare
= (LPARAM
)infoPtr
;
3158 cChildren
= TREEVIEW_CountChildren(parent
);
3160 /* Make sure there is something to sort */
3163 /* TREEVIEW_ITEM rechaining */
3166 HTREEITEM nextItem
= 0;
3167 HTREEITEM prevItem
= 0;
3169 HDPA sortList
= TREEVIEW_BuildChildDPA(parent
);
3171 if (sortList
== NULL
)
3174 /* let DPA sort the list */
3175 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
3177 /* The order of DPA entries has been changed, so fixup the
3178 * nextSibling and prevSibling pointers. */
3180 item
= DPA_GetPtr(sortList
, count
++);
3181 while ((nextItem
= DPA_GetPtr(sortList
, count
++)) != NULL
)
3183 /* link the two current item together */
3184 item
->nextSibling
= nextItem
;
3185 nextItem
->prevSibling
= item
;
3187 if (prevItem
== NULL
)
3189 /* this is the first item, update the parent */
3190 parent
->firstChild
= item
;
3191 item
->prevSibling
= NULL
;
3195 /* fix the back chaining */
3196 item
->prevSibling
= prevItem
;
3199 /* get ready for the next one */
3204 /* the last item is pointed to by item and never has a sibling */
3205 item
->nextSibling
= NULL
;
3206 parent
->lastChild
= item
;
3208 DPA_Destroy(sortList
);
3210 TREEVIEW_VerifyTree(infoPtr
);
3212 if (parent
->state
& TVIS_EXPANDED
)
3214 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3216 if (parent
== infoPtr
->root
)
3217 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3219 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3221 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3223 TREEVIEW_ITEM
*item
;
3225 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3226 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3228 if (item
->visibleOrder
== visOrder
)
3232 if (!item
) item
= parent
->firstChild
;
3233 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3236 TREEVIEW_Invalidate(infoPtr
, NULL
);
3245 /***************************************************************************
3246 * Setup the treeview structure with regards of the sort method
3247 * and sort the children of the TV item specified in lParam
3250 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, LPTVSORTCB pSort
)
3252 return TREEVIEW_Sort(infoPtr
, pSort
->hParent
, pSort
);
3256 /***************************************************************************
3257 * Sort the children of the TV item specified in lParam.
3260 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3262 return TREEVIEW_Sort(infoPtr
, (HTREEITEM
)lParam
, NULL
);
3266 /* Expansion/Collapse ***************************************************/
3269 TREEVIEW_SendExpanding(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3272 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3273 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3274 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3279 TREEVIEW_SendExpanded(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3282 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3283 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3284 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3289 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3290 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3292 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3293 BOOL bRemoveChildren
, BOOL bUser
)
3295 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3296 BOOL bSetSelection
, bSetFirstVisible
;
3298 LONG scrollDist
= 0;
3299 TREEVIEW_ITEM
*nextItem
= NULL
, *tmpItem
;
3302 TRACE("TVE_COLLAPSE %p %s\n", item
, TREEVIEW_ItemName(item
));
3304 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3308 TREEVIEW_SendExpanding(infoPtr
, item
, action
);
3310 if (item
->firstChild
== NULL
)
3313 wasExpanded
= (item
->state
& TVIS_EXPANDED
) != 0;
3314 item
->state
&= ~TVIS_EXPANDED
;
3316 if (wasExpanded
&& bUser
)
3317 TREEVIEW_SendExpanded(infoPtr
, item
, action
);
3319 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3320 && TREEVIEW_IsChildOf(item
, infoPtr
->selectedItem
));
3322 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3323 && TREEVIEW_IsChildOf(item
, infoPtr
->firstVisible
));
3328 if (tmpItem
->nextSibling
)
3330 nextItem
= tmpItem
->nextSibling
;
3333 tmpItem
= tmpItem
->parent
;
3337 scrollDist
= nextItem
->rect
.top
;
3339 if (bRemoveChildren
)
3341 INT old_cChildren
= item
->cChildren
;
3342 TRACE("TVE_COLLAPSERESET\n");
3343 item
->state
&= ~TVIS_EXPANDEDONCE
;
3344 TREEVIEW_RemoveAllChildren(infoPtr
, item
);
3345 item
->cChildren
= old_cChildren
;
3350 if (item
->firstChild
)
3352 TREEVIEW_ITEM
*i
, *sibling
;
3354 sibling
= TREEVIEW_GetNextListItem(infoPtr
, item
);
3356 for (i
= item
->firstChild
; i
!= sibling
;
3357 i
= TREEVIEW_GetNextListItem(infoPtr
, i
))
3359 i
->visibleOrder
= -1;
3363 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3366 scrollDist
= -(scrollDist
- nextItem
->rect
.top
);
3370 /* Don't call DoSelectItem, it sends notifications. */
3371 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3372 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3373 item
->state
|= TVIS_SELECTED
;
3374 infoPtr
->selectedItem
= item
;
3377 TREEVIEW_UpdateScrollBars(infoPtr
);
3379 scrollRect
.left
= 0;
3380 scrollRect
.right
= infoPtr
->clientWidth
;
3381 scrollRect
.bottom
= infoPtr
->clientHeight
;
3385 scrollRect
.top
= nextItem
->rect
.top
;
3387 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, &scrollRect
,
3388 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3389 TREEVIEW_Invalidate(infoPtr
, item
);
3391 scrollRect
.top
= item
->rect
.top
;
3392 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, TRUE
);
3395 TREEVIEW_SetFirstVisible(infoPtr
,
3396 bSetFirstVisible
? item
: infoPtr
->firstVisible
,
3403 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
,
3404 BOOL partial
, BOOL user
)
3407 LONG orgNextTop
= 0;
3409 TREEVIEW_ITEM
*nextItem
, *tmpItem
;
3410 BOOL sendsNotifications
;
3412 TRACE("(%p, %p, partial=%d, %d)\n", infoPtr
, item
, partial
, user
);
3414 if (!TREEVIEW_HasChildren(infoPtr
, item
))
3417 tmpItem
= item
; nextItem
= NULL
;
3420 if (tmpItem
->nextSibling
)
3422 nextItem
= tmpItem
->nextSibling
;
3425 tmpItem
= tmpItem
->parent
;
3429 orgNextTop
= nextItem
->rect
.top
;
3431 TRACE("TVE_EXPAND %p %s\n", item
, TREEVIEW_ItemName(item
));
3433 sendsNotifications
= user
|| ((item
->cChildren
!= 0) &&
3434 !(item
->state
& TVIS_EXPANDEDONCE
));
3435 if (sendsNotifications
)
3437 if (!TREEVIEW_SendExpanding(infoPtr
, item
, TVE_EXPAND
))
3439 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3443 if (!item
->firstChild
)
3446 item
->state
|= TVIS_EXPANDED
;
3449 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3451 if (ISVISIBLE(item
))
3453 TREEVIEW_RecalculateVisibleOrder(infoPtr
, item
);
3454 TREEVIEW_UpdateSubTree(infoPtr
, item
);
3455 TREEVIEW_UpdateScrollBars(infoPtr
);
3457 scrollRect
.left
= 0;
3458 scrollRect
.bottom
= infoPtr
->treeHeight
;
3459 scrollRect
.right
= infoPtr
->clientWidth
;
3462 scrollDist
= nextItem
->rect
.top
- orgNextTop
;
3463 scrollRect
.top
= orgNextTop
;
3465 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3466 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3467 TREEVIEW_Invalidate (infoPtr
, item
);
3469 scrollRect
.top
= item
->rect
.top
;
3470 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, FALSE
);
3473 /* Scroll up so that as many children as possible are visible.
3474 * This fails when expanding causes an HScroll bar to appear, but we
3475 * don't know that yet, so the last item is obscured. */
3476 if (item
->firstChild
!= NULL
)
3478 int nChildren
= item
->lastChild
->visibleOrder
3479 - item
->firstChild
->visibleOrder
+ 1;
3481 int visible_pos
= item
->visibleOrder
3482 - infoPtr
->firstVisible
->visibleOrder
;
3484 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3486 if (visible_pos
> 0 && nChildren
> rows_below
)
3488 int scroll
= nChildren
- rows_below
;
3490 if (scroll
> visible_pos
)
3491 scroll
= visible_pos
;
3495 TREEVIEW_ITEM
*newFirstVisible
3496 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3500 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3506 if (sendsNotifications
) {
3507 TREEVIEW_SendExpanded(infoPtr
, item
, TVE_EXPAND
);
3508 item
->state
|= TVIS_EXPANDEDONCE
;
3514 /* Handler for TVS_SINGLEEXPAND behaviour. Used on response
3515 to mouse messages and TVM_SELECTITEM.
3517 selection - previously selected item, used to collapse a part of a tree
3518 item - new selected item
3520 static void TREEVIEW_SingleExpand(TREEVIEW_INFO
*infoPtr
,
3521 HTREEITEM selection
, HTREEITEM item
)
3523 TREEVIEW_ITEM
*prev
, *curr
;
3525 if ((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) == 0 || infoPtr
->hwndEdit
|| !item
) return;
3527 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, item
, 0);
3530 * Close the previous item and its ancestors as long as they are not
3531 * ancestors of the current item
3533 for (prev
= selection
; prev
&& TREEVIEW_ValidItem(infoPtr
, prev
); prev
= prev
->parent
)
3535 for (curr
= item
; curr
&& TREEVIEW_ValidItem(infoPtr
, curr
); curr
= curr
->parent
)
3540 TREEVIEW_Collapse(infoPtr
, prev
, FALSE
, TRUE
);
3545 * Expand the current item
3547 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3551 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, BOOL user
)
3553 TRACE("item=%p, user=%d\n", item
, user
);
3555 if (item
->state
& TVIS_EXPANDED
)
3556 return TREEVIEW_Collapse(infoPtr
, item
, FALSE
, user
);
3558 return TREEVIEW_Expand(infoPtr
, item
, FALSE
, user
);
3562 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3564 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3566 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3568 if (TREEVIEW_HasChildren(infoPtr
, item
))
3569 TREEVIEW_ExpandAll(infoPtr
, item
);
3573 /* Note:If the specified item is the child of a collapsed parent item,
3574 the parent's list of child items is (recursively) expanded to reveal the
3575 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3576 know if it also applies here.
3580 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM item
)
3582 if (!TREEVIEW_ValidItem(infoPtr
, item
))
3585 TRACE("For (%s) item:%d, flags 0x%x, state:%d\n",
3586 TREEVIEW_ItemName(item
), TREEVIEW_GetItemIndex(infoPtr
, item
),
3589 switch (flag
& TVE_TOGGLE
)
3592 return TREEVIEW_Collapse(infoPtr
, item
, flag
& TVE_COLLAPSERESET
,
3596 return TREEVIEW_Expand(infoPtr
, item
, flag
& TVE_EXPANDPARTIAL
,
3600 return TREEVIEW_Toggle(infoPtr
, item
, FALSE
);
3607 /* Hit-Testing **********************************************************/
3609 static TREEVIEW_ITEM
*
3610 TREEVIEW_HitTestPoint(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3612 TREEVIEW_ITEM
*item
;
3615 if (!infoPtr
->firstVisible
)
3618 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3620 for (item
= infoPtr
->firstVisible
; item
!= NULL
;
3621 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3623 if (row
>= item
->visibleOrder
3624 && row
< item
->visibleOrder
+ item
->iIntegral
)
3632 TREEVIEW_HitTest(const TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3634 TREEVIEW_ITEM
*item
;
3640 GetClientRect(infoPtr
->hwnd
, &rect
);
3647 status
|= TVHT_TOLEFT
;
3649 else if (x
> rect
.right
)
3651 status
|= TVHT_TORIGHT
;
3656 status
|= TVHT_ABOVE
;
3658 else if (y
> rect
.bottom
)
3660 status
|= TVHT_BELOW
;
3665 lpht
->flags
= status
;
3669 item
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3672 lpht
->flags
= TVHT_NOWHERE
;
3676 if (x
>= item
->textOffset
+ item
->textWidth
)
3678 lpht
->flags
= TVHT_ONITEMRIGHT
;
3680 else if (x
>= item
->textOffset
)
3682 lpht
->flags
= TVHT_ONITEMLABEL
;
3684 else if (x
>= item
->imageOffset
)
3686 lpht
->flags
= TVHT_ONITEMICON
;
3688 else if (x
>= item
->stateOffset
)
3690 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3692 else if (x
>= item
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3694 lpht
->flags
= TVHT_ONITEMBUTTON
;
3698 lpht
->flags
= TVHT_ONITEMINDENT
;
3702 TRACE("(%d,%d):result 0x%x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3704 return (LRESULT
)item
;
3707 /* Item Label Editing ***************************************************/
3710 TREEVIEW_GetEditControl(const TREEVIEW_INFO
*infoPtr
)
3712 return (LRESULT
)infoPtr
->hwndEdit
;
3715 static LRESULT CALLBACK
3716 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3718 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3719 BOOL bCancel
= FALSE
;
3725 TRACE("WM_PAINT start\n");
3726 rc
= CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3728 TRACE("WM_PAINT done\n");
3732 if (infoPtr
->bIgnoreEditKillFocus
)
3738 WNDPROC editProc
= infoPtr
->wpEditOrig
;
3739 infoPtr
->wpEditOrig
= 0;
3740 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
3741 return CallWindowProcW(editProc
, hwnd
, uMsg
, wParam
, lParam
);
3745 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3748 if (wParam
== VK_ESCAPE
)
3753 else if (wParam
== VK_RETURN
)
3760 return CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3763 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3764 /* eg. Using a messagebox */
3766 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3767 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3768 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3774 /* should handle edit control messages here */
3777 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3779 TRACE("code=0x%x, id=0x%x, handle=0x%lx\n", HIWORD(wParam
), LOWORD(wParam
), lParam
);
3781 switch (HIWORD(wParam
))
3786 * Adjust the edit window size
3789 TREEVIEW_ITEM
*editItem
= infoPtr
->editItem
;
3790 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3792 HFONT hFont
, hOldFont
= 0;
3794 TRACE("edit=%p\n", infoPtr
->hwndEdit
);
3796 if (!IsWindow(infoPtr
->hwndEdit
) || !hdc
) return FALSE
;
3798 infoPtr
->bLabelChanged
= TRUE
;
3800 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
3802 /* Select font to get the right dimension of the string */
3803 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3807 hOldFont
= SelectObject(hdc
, hFont
);
3810 if (GetTextExtentPoint32W(hdc
, buffer
, strlenW(buffer
), &sz
))
3812 TEXTMETRICW textMetric
;
3814 /* Add Extra spacing for the next character */
3815 GetTextMetricsW(hdc
, &textMetric
);
3816 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3818 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3820 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3822 SetWindowPos(infoPtr
->hwndEdit
,
3827 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3828 SWP_NOMOVE
| SWP_DRAWFRAME
);
3833 SelectObject(hdc
, hOldFont
);
3836 ReleaseDC(infoPtr
->hwnd
, hdc
);
3840 /* apparently we should respect passed handle value */
3841 if (infoPtr
->hwndEdit
!= (HWND
)lParam
) return FALSE
;
3843 TREEVIEW_EndEditLabelNow(infoPtr
, FALSE
);
3847 return SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3854 TREEVIEW_EditLabel(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3856 HWND hwnd
= infoPtr
->hwnd
;
3859 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
);
3862 TEXTMETRICW textMetric
;
3864 TRACE("%p %p\n", hwnd
, hItem
);
3865 if (!(infoPtr
->dwStyle
& TVS_EDITLABELS
))
3868 if (!TREEVIEW_ValidItem(infoPtr
, hItem
))
3871 if (infoPtr
->hwndEdit
)
3872 return infoPtr
->hwndEdit
;
3874 infoPtr
->bLabelChanged
= FALSE
;
3876 /* make edit item visible */
3877 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3879 TREEVIEW_UpdateDispInfo(infoPtr
, hItem
, TVIF_TEXT
);
3882 /* Select the font to get appropriate metric dimensions */
3883 if (infoPtr
->hFont
!= 0)
3885 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3888 /* Get string length in pixels */
3890 GetTextExtentPoint32W(hdc
, hItem
->pszText
, strlenW(hItem
->pszText
),
3893 GetTextExtentPoint32A(hdc
, "", 0, &sz
);
3895 /* Add Extra spacing for the next character */
3896 GetTextMetricsW(hdc
, &textMetric
);
3897 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3899 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3900 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- hItem
->textOffset
+ 2);
3902 if (infoPtr
->hFont
!= 0)
3904 SelectObject(hdc
, hOldFont
);
3907 ReleaseDC(hwnd
, hdc
);
3909 infoPtr
->editItem
= hItem
;
3911 hwndEdit
= CreateWindowExW(WS_EX_LEFT
,
3914 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3915 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3916 ES_LEFT
, hItem
->textOffset
- 2,
3917 hItem
->rect
.top
- 1, sz
.cx
+ 3,
3918 hItem
->rect
.bottom
-
3919 hItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3920 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3922 infoPtr
->hwndEdit
= hwndEdit
;
3924 /* Get a 2D border. */
3925 SetWindowLongW(hwndEdit
, GWL_EXSTYLE
,
3926 GetWindowLongW(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3927 SetWindowLongW(hwndEdit
, GWL_STYLE
,
3928 GetWindowLongW(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3930 SendMessageW(hwndEdit
, WM_SETFONT
,
3931 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, hItem
), FALSE
);
3933 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
,
3935 TREEVIEW_Edit_SubclassProc
);
3937 SetWindowTextW(hwndEdit
, hItem
->pszText
);
3939 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, hItem
))
3941 DestroyWindow(hwndEdit
);
3942 infoPtr
->hwndEdit
= 0;
3943 infoPtr
->editItem
= NULL
;
3948 SendMessageW(hwndEdit
, EM_SETSEL
, 0, -1);
3949 ShowWindow(hwndEdit
, SW_SHOW
);
3956 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3958 TREEVIEW_ITEM
*editedItem
= infoPtr
->editItem
;
3961 WCHAR tmpText
[1024] = { '\0' };
3962 WCHAR
*newText
= tmpText
;
3965 if (!IsWindow(infoPtr
->hwndEdit
)) return FALSE
;
3968 tvdi
.item
.hItem
= editedItem
;
3969 tvdi
.item
.state
= editedItem
->state
;
3970 tvdi
.item
.lParam
= editedItem
->lParam
;
3974 if (!infoPtr
->bNtfUnicode
)
3975 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, (LPSTR
)tmpText
, 1023);
3977 iLength
= GetWindowTextW(infoPtr
->hwndEdit
, tmpText
, 1023);
3979 if (iLength
>= 1023)
3981 ERR("Insufficient space to retrieve new item label\n");
3984 tvdi
.item
.mask
= TVIF_TEXT
;
3985 tvdi
.item
.pszText
= tmpText
;
3986 tvdi
.item
.cchTextMax
= iLength
+ 1;
3990 tvdi
.item
.pszText
= NULL
;
3991 tvdi
.item
.cchTextMax
= 0;
3994 bCommit
= TREEVIEW_SendRealNotify(infoPtr
, TVN_ENDLABELEDITW
, &tvdi
.hdr
);
3996 if (!bCancel
&& bCommit
) /* Apply the changes */
3998 if (!infoPtr
->bNtfUnicode
)
4000 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, NULL
, 0 );
4001 newText
= Alloc(len
* sizeof(WCHAR
));
4002 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, newText
, len
);
4006 if (strcmpW(newText
, editedItem
->pszText
) != 0)
4008 WCHAR
*ptr
= ReAlloc(editedItem
->pszText
, sizeof(WCHAR
)*(iLength
+ 1));
4011 ERR("OutOfMemory, cannot allocate space for label\n");
4012 if(newText
!= tmpText
) Free(newText
);
4013 DestroyWindow(infoPtr
->hwndEdit
);
4014 infoPtr
->hwndEdit
= 0;
4015 infoPtr
->editItem
= NULL
;
4020 editedItem
->pszText
= ptr
;
4021 editedItem
->cchTextMax
= iLength
+ 1;
4022 strcpyW(editedItem
->pszText
, newText
);
4023 TREEVIEW_ComputeTextWidth(infoPtr
, editedItem
, 0);
4026 if(newText
!= tmpText
) Free(newText
);
4029 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
4030 DestroyWindow(infoPtr
->hwndEdit
);
4031 infoPtr
->hwndEdit
= 0;
4032 infoPtr
->editItem
= NULL
;
4037 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4039 if (wParam
!= TV_EDIT_TIMER
)
4041 ERR("got unknown timer\n");
4045 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4046 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
4048 TREEVIEW_EditLabel(infoPtr
, infoPtr
->selectedItem
);
4054 /* Mouse Tracking/Drag **************************************************/
4056 /***************************************************************************
4057 * This is quite unusual piece of code, but that's how it's implemented in
4061 TREEVIEW_TrackMouse(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
4063 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
4064 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
4068 r
.top
= pt
.y
- cyDrag
;
4069 r
.left
= pt
.x
- cxDrag
;
4070 r
.bottom
= pt
.y
+ cyDrag
;
4071 r
.right
= pt
.x
+ cxDrag
;
4073 SetCapture(infoPtr
->hwnd
);
4077 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
4079 if (msg
.message
== WM_MOUSEMOVE
)
4081 pt
.x
= (short)LOWORD(msg
.lParam
);
4082 pt
.y
= (short)HIWORD(msg
.lParam
);
4083 if (PtInRect(&r
, pt
))
4091 else if (msg
.message
>= WM_LBUTTONDOWN
&&
4092 msg
.message
<= WM_RBUTTONDBLCLK
)
4097 DispatchMessageW(&msg
);
4100 if (GetCapture() != infoPtr
->hwnd
)
4110 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4112 TREEVIEW_ITEM
*item
;
4116 SetFocus(infoPtr
->hwnd
);
4118 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4120 /* If there is pending 'edit label' event - kill it now */
4121 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
4124 hit
.pt
.x
= (short)LOWORD(lParam
);
4125 hit
.pt
.y
= (short)HIWORD(lParam
);
4127 item
= (TREEVIEW_ITEM
*)TREEVIEW_HitTest(infoPtr
, &hit
);
4130 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, item
));
4132 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
4136 case TVHT_ONITEMRIGHT
:
4137 /* FIXME: we should not have sent NM_DBLCLK in this case. */
4140 case TVHT_ONITEMINDENT
:
4141 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
4147 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
4148 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
4150 while (item
->iLevel
> level
)
4152 item
= item
->parent
;
4158 case TVHT_ONITEMLABEL
:
4159 case TVHT_ONITEMICON
:
4160 case TVHT_ONITEMBUTTON
:
4161 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4164 case TVHT_ONITEMSTATEICON
:
4165 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4166 TREEVIEW_ToggleItemState(infoPtr
, item
);
4168 TREEVIEW_Toggle(infoPtr
, item
, TRUE
);
4177 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4179 HWND hwnd
= infoPtr
->hwnd
;
4181 BOOL bTrack
, bDoLabelEdit
;
4183 /* If Edit control is active - kill it and return.
4184 * The best way to do it is to set focus to itself.
4185 * Edit control subclassed procedure will automatically call
4188 if (infoPtr
->hwndEdit
)
4194 ht
.pt
.x
= (short)LOWORD(lParam
);
4195 ht
.pt
.y
= (short)HIWORD(lParam
);
4197 TREEVIEW_HitTest(infoPtr
, &ht
);
4198 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
4200 /* update focusedItem and redraw both items */
4201 if(ht
.hItem
&& (ht
.flags
& TVHT_ONITEM
))
4203 infoPtr
->focusedItem
= ht
.hItem
;
4204 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4205 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4208 bTrack
= (ht
.flags
& TVHT_ONITEM
)
4209 && !(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
);
4212 * If the style allows editing and the node is already selected
4213 * and the click occurred on the item label...
4215 bDoLabelEdit
= (infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
4216 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
);
4218 /* Send NM_CLICK right away */
4220 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4223 if (ht
.flags
& TVHT_ONITEMBUTTON
)
4225 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
4229 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
4230 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4232 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
4233 infoPtr
->dropItem
= ht
.hItem
;
4235 /* clean up focusedItem as we dragged and won't select this item */
4236 if(infoPtr
->focusedItem
)
4238 /* refresh the item that was focused */
4239 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4240 infoPtr
->focusedItem
= NULL
;
4242 /* refresh the selected item to return the filled background */
4243 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4250 if (bTrack
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4255 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4256 KillTimer(hwnd
, TV_EDIT_TIMER
);
4258 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
4259 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
4261 else if (ht
.flags
& (TVHT_ONITEMICON
|TVHT_ONITEMLABEL
)) /* select the item if the hit was inside of the icon or text */
4263 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4265 /* Select the current item */
4266 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4267 TREEVIEW_SingleExpand(infoPtr
, selection
, ht
.hItem
);
4269 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4271 /* TVS_CHECKBOXES requires us to toggle the current state */
4272 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4273 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4283 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4287 if (infoPtr
->hwndEdit
)
4289 SetFocus(infoPtr
->hwnd
);
4293 ht
.pt
.x
= (short)LOWORD(lParam
);
4294 ht
.pt
.y
= (short)HIWORD(lParam
);
4296 TREEVIEW_HitTest(infoPtr
, &ht
);
4298 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4302 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4303 infoPtr
->dropItem
= ht
.hItem
;
4308 SetFocus(infoPtr
->hwnd
);
4309 if(!TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
))
4311 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
4312 SendMessageW(infoPtr
->hwndNotify
, WM_CONTEXTMENU
,
4313 (WPARAM
)infoPtr
->hwnd
, (LPARAM
)GetMessagePos());
4321 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4323 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4327 HBITMAP hbmp
, hOldbmp
;
4334 if (!(infoPtr
->himlNormal
))
4337 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4340 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4342 hwtop
= GetDesktopWindow();
4343 htopdc
= GetDC(hwtop
);
4344 hdc
= CreateCompatibleDC(htopdc
);
4346 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4348 if (dragItem
->pszText
)
4349 GetTextExtentPoint32W(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
),
4352 GetTextExtentPoint32A(hdc
, "", 0, &size
);
4354 TRACE("%d %d %s\n", size
.cx
, size
.cy
, debugstr_w(dragItem
->pszText
));
4355 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4356 hOldbmp
= SelectObject(hdc
, hbmp
);
4358 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4363 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4364 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4368 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4369 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4372 /* draw item text */
4374 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4376 if (dragItem
->pszText
)
4377 DrawTextW(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
), &rc
,
4380 SelectObject(hdc
, hOldFont
);
4381 SelectObject(hdc
, hOldbmp
);
4383 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4387 ReleaseDC(hwtop
, htopdc
);
4389 return (LRESULT
)infoPtr
->dragList
;
4392 /* Selection ************************************************************/
4395 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4398 TREEVIEW_ITEM
*prevSelect
;
4400 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4402 TRACE("Entering item %p (%s), flag 0x%x, cause 0x%x, state %d\n",
4403 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4404 newSelect
? newSelect
->state
: 0);
4406 /* reset and redraw focusedItem if focusedItem was set so we don't */
4407 /* have to worry about the previously focused item when we set a new one */
4408 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4409 infoPtr
->focusedItem
= NULL
;
4413 case TVGN_CARET
|TVSI_NOSINGLEEXPAND
:
4414 FIXME("TVSI_NOSINGLEEXPAND specified.\n");
4417 prevSelect
= infoPtr
->selectedItem
;
4419 if (prevSelect
== newSelect
) {
4420 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4424 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4427 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4433 prevSelect
->state
&= ~TVIS_SELECTED
;
4435 newSelect
->state
|= TVIS_SELECTED
;
4437 infoPtr
->selectedItem
= newSelect
;
4439 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4441 TREEVIEW_InvalidateItem(infoPtr
, prevSelect
);
4442 TREEVIEW_InvalidateItem(infoPtr
, newSelect
);
4444 TREEVIEW_SendTreeviewNotify(infoPtr
,
4447 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4452 case TVGN_DROPHILITE
:
4453 prevSelect
= infoPtr
->dropItem
;
4456 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4458 infoPtr
->dropItem
= newSelect
;
4461 newSelect
->state
|= TVIS_DROPHILITED
;
4463 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4464 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4467 case TVGN_FIRSTVISIBLE
:
4468 if (newSelect
!= NULL
)
4470 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4471 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4472 TREEVIEW_Invalidate(infoPtr
, NULL
);
4477 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4481 /* FIXME: handle NM_KILLFOCUS etc */
4483 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4485 TREEVIEW_ITEM
*selection
= infoPtr
->selectedItem
;
4487 if (item
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4490 if (item
== infoPtr
->selectedItem
)
4493 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4495 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4498 TREEVIEW_SingleExpand(infoPtr
, selection
, item
);
4503 /*************************************************************************
4504 * TREEVIEW_ProcessLetterKeys
4506 * Processes keyboard messages generated by pressing the letter keys
4508 * What this does is perform a case insensitive search from the
4509 * current position with the following quirks:
4510 * - If two chars or more are pressed in quick succession we search
4511 * for the corresponding string (e.g. 'abc').
4512 * - If there is a delay we wipe away the current search string and
4513 * restart with just that char.
4514 * - If the user keeps pressing the same character, whether slowly or
4515 * fast, so that the search string is entirely composed of this
4516 * character ('aaaaa' for instance), then we search for first item
4517 * that starting with that character.
4518 * - If the user types the above character in quick succession, then
4519 * we must also search for the corresponding string ('aaaaa'), and
4520 * go to that string if there is a match.
4528 * - The current implementation has a list of characters it will
4529 * accept and it ignores everything else. In particular it will
4530 * ignore accentuated characters which seems to match what
4531 * Windows does. But I'm not sure it makes sense to follow
4533 * - We don't sound a beep when the search fails.
4534 * - The search should start from the focused item, not from the selected
4535 * item. One reason for this is to allow for multiple selections in trees.
4536 * But currently infoPtr->focusedItem does not seem very usable.
4540 * TREEVIEW_ProcessLetterKeys
4542 static INT
TREEVIEW_ProcessLetterKeys(TREEVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
4545 HTREEITEM endidx
,idx
;
4547 WCHAR buffer
[MAX_PATH
];
4548 DWORD timestamp
,elapsed
;
4550 /* simple parameter checking */
4551 if (!charCode
|| !keyData
) return 0;
4553 /* only allow the valid WM_CHARs through */
4554 if (!isalnum(charCode
) &&
4555 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4556 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4557 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4558 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4559 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4560 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4561 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4562 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4563 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4566 /* compute how much time elapsed since last keypress */
4567 timestamp
= GetTickCount();
4568 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4569 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4571 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4574 /* update the search parameters */
4575 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4576 if (elapsed
< KEY_DELAY
) {
4577 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
) / sizeof(WCHAR
)) {
4578 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4580 if (infoPtr
->charCode
!= charCode
) {
4581 infoPtr
->charCode
=charCode
=0;
4584 infoPtr
->charCode
=charCode
;
4585 infoPtr
->szSearchParam
[0]=charCode
;
4586 infoPtr
->nSearchParamLength
=1;
4587 /* Redundant with the 1 char string */
4591 /* and search from the current position */
4593 if (infoPtr
->selectedItem
!= NULL
) {
4594 endidx
=infoPtr
->selectedItem
;
4595 /* if looking for single character match,
4596 * then we must always move forward
4598 if (infoPtr
->nSearchParamLength
== 1)
4599 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4604 idx
=infoPtr
->root
->firstChild
;
4607 /* At the end point, sort out wrapping */
4610 /* If endidx is null, stop at the last item (ie top to bottom) */
4614 /* Otherwise, start again at the very beginning */
4615 idx
=infoPtr
->root
->firstChild
;
4617 /* But if we are stopping on the first child, end now! */
4618 if (idx
== endidx
) break;
4622 ZeroMemory(&item
, sizeof(item
));
4623 item
.mask
= TVIF_TEXT
;
4625 item
.pszText
= buffer
;
4626 item
.cchTextMax
= sizeof(buffer
);
4627 TREEVIEW_GetItemT( infoPtr
, &item
, TRUE
);
4629 /* check for a match */
4630 if (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4633 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4634 (nItem
!= infoPtr
->selectedItem
) &&
4635 (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4636 /* This would work but we must keep looking for a longer match */
4639 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4640 } while (idx
!= endidx
);
4642 if (nItem
!= NULL
) {
4643 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4644 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4651 /* Scrolling ************************************************************/
4654 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4657 BOOL hasFirstVisible
= infoPtr
->firstVisible
!= NULL
;
4658 HTREEITEM newFirstVisible
= NULL
;
4659 int visible_pos
= -1;
4661 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4664 if (!ISVISIBLE(item
))
4666 /* Expand parents as necessary. */
4669 /* see if we are trying to ensure that root is visible */
4670 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4671 parent
= item
->parent
;
4673 parent
= item
; /* this item is the topmost item */
4675 while (parent
!= infoPtr
->root
)
4677 if (!(parent
->state
& TVIS_EXPANDED
))
4678 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, TRUE
);
4680 parent
= parent
->parent
;
4684 viscount
= TREEVIEW_GetVisibleCount(infoPtr
);
4686 TRACE("%p (%s) %d - %d viscount(%d)\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4687 hasFirstVisible
? infoPtr
->firstVisible
->visibleOrder
: -1, viscount
);
4689 if (hasFirstVisible
)
4690 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4692 if (visible_pos
< 0)
4694 /* item is before the start of the list: put it at the top. */
4695 newFirstVisible
= item
;
4697 else if (visible_pos
>= viscount
4698 /* Sometimes, before we are displayed, GVC is 0, causing us to
4699 * spuriously scroll up. */
4700 && visible_pos
> 0 && !(infoPtr
->dwStyle
& TVS_NOSCROLL
) )
4702 /* item is past the end of the list. */
4703 int scroll
= visible_pos
- viscount
;
4705 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4711 /* Scroll window so item's text is visible as much as possible */
4712 /* Calculation of amount of extra space is taken from EditLabel code */
4714 TEXTMETRICW textMetric
;
4715 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4717 x
= item
->textWidth
;
4719 GetTextMetricsW(hdc
, &textMetric
);
4720 ReleaseDC(infoPtr
->hwnd
, hdc
);
4722 x
+= (textMetric
.tmMaxCharWidth
* 2);
4723 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4725 if (item
->textOffset
< 0)
4726 pos
= item
->textOffset
;
4727 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4729 if (x
> infoPtr
->clientWidth
)
4730 pos
= item
->textOffset
;
4732 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4737 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4740 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4742 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4751 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4752 TREEVIEW_ITEM
*newFirstVisible
,
4753 BOOL bUpdateScrollPos
)
4757 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4759 if (newFirstVisible
!= NULL
)
4761 /* Prevent an empty gap from appearing at the bottom... */
4762 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4763 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4767 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4770 /* ... unless we just don't have enough items. */
4771 if (newFirstVisible
== NULL
)
4772 newFirstVisible
= infoPtr
->root
->firstChild
;
4776 if (infoPtr
->firstVisible
!= newFirstVisible
)
4778 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4780 infoPtr
->firstVisible
= newFirstVisible
;
4781 TREEVIEW_Invalidate(infoPtr
, NULL
);
4785 TREEVIEW_ITEM
*item
;
4786 int scroll
= infoPtr
->uItemHeight
*
4787 (infoPtr
->firstVisible
->visibleOrder
4788 - newFirstVisible
->visibleOrder
);
4790 infoPtr
->firstVisible
= newFirstVisible
;
4792 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4793 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4795 item
->rect
.top
+= scroll
;
4796 item
->rect
.bottom
+= scroll
;
4799 if (bUpdateScrollPos
)
4800 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4801 newFirstVisible
->visibleOrder
, TRUE
);
4803 ScrollWindowEx(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
, NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
4808 /************************************************************************
4809 * VScroll is always in units of visible items. i.e. we always have a
4810 * visible item aligned to the top of the control. (Unless we have no
4814 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4816 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4817 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4819 int nScrollCode
= LOWORD(wParam
);
4821 TRACE("wp %lx\n", wParam
);
4823 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4826 if (!oldFirstVisible
)
4828 assert(infoPtr
->root
->firstChild
== NULL
);
4832 switch (nScrollCode
)
4835 newFirstVisible
= infoPtr
->root
->firstChild
;
4839 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4843 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4847 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4851 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4852 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4856 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4857 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4861 case SB_THUMBPOSITION
:
4862 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4863 infoPtr
->root
->firstChild
,
4864 (LONG
)(SHORT
)HIWORD(wParam
));
4871 if (newFirstVisible
!= NULL
)
4873 if (newFirstVisible
!= oldFirstVisible
)
4874 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4875 nScrollCode
!= SB_THUMBTRACK
);
4876 else if (nScrollCode
== SB_THUMBPOSITION
)
4877 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4878 newFirstVisible
->visibleOrder
, TRUE
);
4885 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4888 int scrollX
= infoPtr
->scrollX
;
4889 int nScrollCode
= LOWORD(wParam
);
4891 TRACE("wp %lx\n", wParam
);
4893 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4896 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4897 /* shall never occur */
4904 switch (nScrollCode
)
4907 scrollX
-= infoPtr
->uItemHeight
;
4910 scrollX
+= infoPtr
->uItemHeight
;
4913 scrollX
-= infoPtr
->clientWidth
;
4916 scrollX
+= infoPtr
->clientWidth
;
4920 case SB_THUMBPOSITION
:
4921 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4928 if (scrollX
> maxWidth
)
4930 else if (scrollX
< 0)
4934 if (scrollX
!= infoPtr
->scrollX
)
4936 TREEVIEW_ITEM
*item
;
4937 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4939 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4940 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4942 item
->linesOffset
+= scroll_pixels
;
4943 item
->stateOffset
+= scroll_pixels
;
4944 item
->imageOffset
+= scroll_pixels
;
4945 item
->textOffset
+= scroll_pixels
;
4948 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4949 infoPtr
->scrollX
= scrollX
;
4950 UpdateWindow(infoPtr
->hwnd
);
4953 if (nScrollCode
!= SB_THUMBTRACK
)
4954 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
4960 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4963 UINT pulScrollLines
= 3;
4965 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4966 return DefWindowProcW(infoPtr
->hwnd
, WM_MOUSEWHEEL
, wParam
, lParam
);
4968 if (infoPtr
->firstVisible
== NULL
)
4971 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
4973 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4974 /* if scrolling changes direction, ignore left overs */
4975 if ((wheelDelta
< 0 && infoPtr
->wheelRemainder
< 0) ||
4976 (wheelDelta
> 0 && infoPtr
->wheelRemainder
> 0))
4977 infoPtr
->wheelRemainder
+= wheelDelta
;
4979 infoPtr
->wheelRemainder
= wheelDelta
;
4981 if (infoPtr
->wheelRemainder
&& pulScrollLines
)
4987 lineScroll
= pulScrollLines
* (float)infoPtr
->wheelRemainder
/ WHEEL_DELTA
;
4988 infoPtr
->wheelRemainder
-= WHEEL_DELTA
* lineScroll
/ (int)pulScrollLines
;
4990 newDy
= infoPtr
->firstVisible
->visibleOrder
- lineScroll
;
4991 maxDy
= infoPtr
->maxVisibleOrder
;
4999 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
5004 /* Create/Destroy *******************************************************/
5007 TREEVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
5010 TREEVIEW_INFO
*infoPtr
;
5013 TRACE("wnd %p, style 0x%x\n", hwnd
, GetWindowLongW(hwnd
, GWL_STYLE
));
5015 infoPtr
= Alloc(sizeof(TREEVIEW_INFO
));
5017 if (infoPtr
== NULL
)
5019 ERR("could not allocate info memory!\n");
5023 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
5025 infoPtr
->hwnd
= hwnd
;
5026 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
5028 infoPtr
->uNumItems
= 0;
5029 infoPtr
->cdmode
= 0;
5030 infoPtr
->uScrollTime
= 300; /* milliseconds */
5031 infoPtr
->bRedraw
= TRUE
;
5033 GetClientRect(hwnd
, &rcClient
);
5035 /* No scroll bars yet. */
5036 infoPtr
->clientWidth
= rcClient
.right
;
5037 infoPtr
->clientHeight
= rcClient
.bottom
;
5038 infoPtr
->uInternalStatus
= 0;
5040 infoPtr
->treeWidth
= 0;
5041 infoPtr
->treeHeight
= 0;
5043 infoPtr
->uIndent
= MINIMUM_INDENT
;
5044 infoPtr
->selectedItem
= NULL
;
5045 infoPtr
->focusedItem
= NULL
;
5046 infoPtr
->hotItem
= NULL
;
5047 infoPtr
->editItem
= NULL
;
5048 infoPtr
->firstVisible
= NULL
;
5049 infoPtr
->maxVisibleOrder
= 0;
5050 infoPtr
->dropItem
= NULL
;
5051 infoPtr
->insertMarkItem
= NULL
;
5052 infoPtr
->insertBeforeorAfter
= 0;
5055 infoPtr
->scrollX
= 0;
5056 infoPtr
->wheelRemainder
= 0;
5058 infoPtr
->clrBk
= CLR_NONE
; /* use system color */
5059 infoPtr
->clrText
= CLR_NONE
; /* use system color */
5060 infoPtr
->clrLine
= CLR_DEFAULT
;
5061 infoPtr
->clrInsertMark
= CLR_DEFAULT
;
5065 infoPtr
->hwndEdit
= NULL
;
5066 infoPtr
->wpEditOrig
= NULL
;
5067 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
5068 infoPtr
->bLabelChanged
= FALSE
;
5070 infoPtr
->himlNormal
= NULL
;
5071 infoPtr
->himlState
= NULL
;
5072 infoPtr
->normalImageWidth
= 0;
5073 infoPtr
->normalImageHeight
= 0;
5074 infoPtr
->stateImageWidth
= 0;
5075 infoPtr
->stateImageHeight
= 0;
5077 infoPtr
->items
= DPA_Create(16);
5079 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
5080 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW(&lf
);
5081 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
5082 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
5083 infoPtr
->hBoldUnderlineFont
= TREEVIEW_CreateBoldUnderlineFont(infoPtr
->hFont
);
5084 infoPtr
->hcurHand
= LoadCursorW(NULL
, (LPWSTR
)IDC_HAND
);
5086 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
5088 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
5089 infoPtr
->root
->state
= TVIS_EXPANDED
;
5090 infoPtr
->root
->iLevel
= -1;
5091 infoPtr
->root
->visibleOrder
= -1;
5093 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5094 infoPtr
->hwndToolTip
= 0;
5096 /* Determine what type of notify should be issued (sets infoPtr->bNtfUnicode) */
5097 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
5099 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
5100 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
5101 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
5104 /* Make sure actual scrollbar state is consistent with uInternalStatus */
5105 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
5106 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
5108 OpenThemeData (hwnd
, themeClass
);
5115 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
5119 /* free item data */
5120 TREEVIEW_RemoveTree(infoPtr
);
5121 /* root isn't freed with other items */
5122 TREEVIEW_FreeItem(infoPtr
, infoPtr
->root
);
5123 DPA_Destroy(infoPtr
->items
);
5125 /* tool tip is automatically destroyed: we are its owner */
5127 /* Restore original wndproc */
5128 if (infoPtr
->hwndEdit
)
5129 SetWindowLongPtrW(infoPtr
->hwndEdit
, GWLP_WNDPROC
,
5130 (DWORD_PTR
)infoPtr
->wpEditOrig
);
5132 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
5134 /* Deassociate treeview from the window before doing anything drastic. */
5135 SetWindowLongPtrW(infoPtr
->hwnd
, 0, 0);
5137 DeleteObject(infoPtr
->hDefaultFont
);
5138 DeleteObject(infoPtr
->hBoldFont
);
5139 DeleteObject(infoPtr
->hUnderlineFont
);
5140 DeleteObject(infoPtr
->hBoldUnderlineFont
);
5146 /* Miscellaneous Messages ***********************************************/
5149 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
5157 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
5158 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
5159 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
5160 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
5161 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
5162 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
5163 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
5164 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
5165 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
5169 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
5171 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
5173 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
5175 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
5181 /************************************************************************
5184 * VK_UP Move selection to the previous non-hidden item.
5185 * VK_DOWN Move selection to the next non-hidden item.
5186 * VK_HOME Move selection to the first item.
5187 * VK_END Move selection to the last item.
5188 * VK_LEFT If expanded then collapse, otherwise move to parent.
5189 * VK_RIGHT If collapsed then expand, otherwise move to first child.
5191 * VK_SUBTRACT Collapse.
5192 * VK_MULTIPLY Expand all.
5193 * VK_PRIOR Move up GetVisibleCount items.
5194 * VK_NEXT Move down GetVisibleCount items.
5195 * VK_BACK Move to parent.
5196 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
5199 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
5201 /* If it is non-NULL and different, it will be selected and visible. */
5202 TREEVIEW_ITEM
*newSelection
= NULL
;
5203 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
5204 NMTVKEYDOWN nmkeydown
;
5206 TRACE("%lx\n", wParam
);
5208 nmkeydown
.wVKey
= wParam
;
5209 nmkeydown
.flags
= 0;
5210 TREEVIEW_SendRealNotify(infoPtr
, TVN_KEYDOWN
, &nmkeydown
.hdr
);
5212 if (prevItem
== NULL
)
5215 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
5216 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
5221 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
5223 newSelection
= infoPtr
->root
->firstChild
;
5227 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
5231 TREEVIEW_SendSimpleNotify(infoPtr
, NM_RETURN
);
5235 newSelection
= infoPtr
->root
->firstChild
;
5239 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
5243 if (prevItem
->state
& TVIS_EXPANDED
)
5245 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5247 else if (prevItem
->parent
!= infoPtr
->root
)
5249 newSelection
= prevItem
->parent
;
5254 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
5256 if (!(prevItem
->state
& TVIS_EXPANDED
))
5257 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5260 newSelection
= prevItem
->firstChild
;
5267 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5271 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5275 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5280 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5281 -TREEVIEW_GetVisibleCount(infoPtr
));
5286 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5287 TREEVIEW_GetVisibleCount(infoPtr
));
5291 newSelection
= prevItem
->parent
;
5292 if (newSelection
== infoPtr
->root
)
5293 newSelection
= NULL
;
5297 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5298 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5302 if (newSelection
&& newSelection
!= prevItem
)
5304 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5307 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5315 TREEVIEW_MouseLeave (TREEVIEW_INFO
* infoPtr
)
5317 /* remove hot effect from item */
5318 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5319 infoPtr
->hotItem
= NULL
;
5325 TREEVIEW_MouseMove (TREEVIEW_INFO
* infoPtr
, LPARAM lParam
)
5328 TRACKMOUSEEVENT trackinfo
;
5329 TREEVIEW_ITEM
* item
;
5331 if (!(infoPtr
->dwStyle
& TVS_TRACKSELECT
)) return 0;
5333 /* fill in the TRACKMOUSEEVENT struct */
5334 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5335 trackinfo
.dwFlags
= TME_QUERY
;
5336 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5338 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5339 _TrackMouseEvent(&trackinfo
);
5341 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5342 if(!(trackinfo
.dwFlags
& TME_LEAVE
))
5344 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5345 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5346 /* do it as fast as possible, minimal systimer latency will be used */
5347 trackinfo
.dwHoverTime
= 1;
5349 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5350 /* and can properly deactivate the hot item */
5351 _TrackMouseEvent(&trackinfo
);
5354 pt
.x
= (short)LOWORD(lParam
);
5355 pt
.y
= (short)HIWORD(lParam
);
5357 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5359 if (item
!= infoPtr
->hotItem
)
5361 /* redraw old hot item */
5362 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5363 infoPtr
->hotItem
= item
;
5364 /* redraw new hot item */
5365 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5371 /* Draw themed border */
5372 static BOOL
TREEVIEW_NCPaint (const TREEVIEW_INFO
*infoPtr
, HRGN region
, LPARAM lParam
)
5374 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5378 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
5379 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
5382 return DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)region
, lParam
);
5384 GetWindowRect(infoPtr
->hwnd
, &r
);
5386 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
5387 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
5388 if (region
!= (HRGN
)1)
5389 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
5390 OffsetRect(&r
, -r
.left
, -r
.top
);
5392 dc
= GetDCEx(infoPtr
->hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
5393 OffsetRect(&r
, -r
.left
, -r
.top
);
5395 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
5396 DrawThemeParentBackground(infoPtr
->hwnd
, dc
, &r
);
5397 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
5398 ReleaseDC(infoPtr
->hwnd
, dc
);
5400 /* Call default proc to get the scrollbars etc. painted */
5401 DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
5407 TREEVIEW_Notify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5409 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5411 if (lpnmh
->code
== PGN_CALCSIZE
) {
5412 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5414 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5415 lppgc
->iWidth
= infoPtr
->treeWidth
;
5416 TRACE("got PGN_CALCSIZE, returning horz size = %d, client=%d\n",
5417 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5420 lppgc
->iHeight
= infoPtr
->treeHeight
;
5421 TRACE("got PGN_CALCSIZE, returning vert size = %d, client=%d\n",
5422 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5426 return DefWindowProcW(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5430 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5432 if (wParam
== SIZE_RESTORED
)
5434 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5435 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5437 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5438 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5439 TREEVIEW_UpdateScrollBars(infoPtr
);
5443 FIXME("WM_SIZE flag %lx %lx not handled\n", wParam
, lParam
);
5446 TREEVIEW_Invalidate(infoPtr
, NULL
);
5451 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5453 TRACE("(%lx %lx)\n", wParam
, lParam
);
5455 if (wParam
== GWL_STYLE
)
5457 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5459 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_CHECKBOXES
)
5461 if (dwNewStyle
& TVS_CHECKBOXES
)
5463 TREEVIEW_InitCheckboxes(infoPtr
);
5464 TRACE("checkboxes enabled\n");
5466 /* set all items to state image index 1 */
5467 TREEVIEW_ResetImageStateIndex(infoPtr
, infoPtr
->root
);
5471 FIXME("tried to disable checkboxes\n");
5475 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5477 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5479 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5480 TRACE("tooltips enabled\n");
5484 DestroyWindow(infoPtr
->hwndToolTip
);
5485 infoPtr
->hwndToolTip
= 0;
5486 TRACE("tooltips disabled\n");
5490 infoPtr
->dwStyle
= dwNewStyle
;
5493 TREEVIEW_EndEditLabelNow(infoPtr
, TRUE
);
5494 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5495 TREEVIEW_UpdateScrollBars(infoPtr
);
5496 TREEVIEW_Invalidate(infoPtr
, NULL
);
5502 TREEVIEW_SetCursor(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5505 TREEVIEW_ITEM
* item
;
5509 ScreenToClient(infoPtr
->hwnd
, &pt
);
5511 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5513 memset(&nmmouse
, 0, sizeof(nmmouse
));
5516 nmmouse
.dwItemSpec
= (DWORD_PTR
)item
;
5517 nmmouse
.dwItemData
= item
->lParam
;
5521 nmmouse
.dwHitInfo
= lParam
;
5522 if (TREEVIEW_SendRealNotify(infoPtr
, NM_SETCURSOR
, &nmmouse
.hdr
))
5525 if (item
&& (infoPtr
->dwStyle
& TVS_TRACKSELECT
))
5527 SetCursor(infoPtr
->hcurHand
);
5531 return DefWindowProcW(infoPtr
->hwnd
, WM_SETCURSOR
, wParam
, lParam
);
5535 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5539 if (!infoPtr
->selectedItem
)
5541 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5545 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5546 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5551 TREEVIEW_KillFocus(const TREEVIEW_INFO
*infoPtr
)
5555 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5556 UpdateWindow(infoPtr
->hwnd
);
5557 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5561 /* update theme after a WM_THEMECHANGED message */
5562 static LRESULT
TREEVIEW_ThemeChanged(const TREEVIEW_INFO
*infoPtr
)
5564 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5565 CloseThemeData (theme
);
5566 OpenThemeData (infoPtr
->hwnd
, themeClass
);
5571 static LRESULT WINAPI
5572 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5574 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5576 TRACE("hwnd %p msg %04x wp=%08lx lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5578 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5581 if (uMsg
== WM_CREATE
)
5582 TREEVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
5589 case TVM_CREATEDRAGIMAGE
:
5590 return TREEVIEW_CreateDragImage(infoPtr
, lParam
);
5592 case TVM_DELETEITEM
:
5593 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5595 case TVM_EDITLABELA
:
5596 case TVM_EDITLABELW
:
5597 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5599 case TVM_ENDEDITLABELNOW
:
5600 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5602 case TVM_ENSUREVISIBLE
:
5603 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5606 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5608 case TVM_GETBKCOLOR
:
5609 return TREEVIEW_GetBkColor(infoPtr
);
5612 return TREEVIEW_GetCount(infoPtr
);
5614 case TVM_GETEDITCONTROL
:
5615 return TREEVIEW_GetEditControl(infoPtr
);
5617 case TVM_GETIMAGELIST
:
5618 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5621 return TREEVIEW_GetIndent(infoPtr
);
5623 case TVM_GETINSERTMARKCOLOR
:
5624 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5626 case TVM_GETISEARCHSTRINGA
:
5627 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5630 case TVM_GETISEARCHSTRINGW
:
5631 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5636 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5637 uMsg
== TVM_GETITEMW
);
5638 case TVM_GETITEMHEIGHT
:
5639 return TREEVIEW_GetItemHeight(infoPtr
);
5641 case TVM_GETITEMRECT
:
5642 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5644 case TVM_GETITEMSTATE
:
5645 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5647 case TVM_GETLINECOLOR
:
5648 return TREEVIEW_GetLineColor(infoPtr
);
5650 case TVM_GETNEXTITEM
:
5651 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5653 case TVM_GETSCROLLTIME
:
5654 return TREEVIEW_GetScrollTime(infoPtr
);
5656 case TVM_GETTEXTCOLOR
:
5657 return TREEVIEW_GetTextColor(infoPtr
);
5659 case TVM_GETTOOLTIPS
:
5660 return TREEVIEW_GetToolTips(infoPtr
);
5662 case TVM_GETUNICODEFORMAT
:
5663 return TREEVIEW_GetUnicodeFormat(infoPtr
);
5665 case TVM_GETVISIBLECOUNT
:
5666 return TREEVIEW_GetVisibleCount(infoPtr
);
5669 return TREEVIEW_HitTest(infoPtr
, (LPTVHITTESTINFO
)lParam
);
5671 case TVM_INSERTITEMA
:
5672 case TVM_INSERTITEMW
:
5673 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
,
5674 uMsg
== TVM_INSERTITEMW
);
5675 case TVM_SELECTITEM
:
5676 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5678 case TVM_SETBKCOLOR
:
5679 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5681 case TVM_SETIMAGELIST
:
5682 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5685 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5687 case TVM_SETINSERTMARK
:
5688 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5690 case TVM_SETINSERTMARKCOLOR
:
5691 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5695 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5696 uMsg
== TVM_SETITEMW
);
5697 case TVM_SETLINECOLOR
:
5698 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5700 case TVM_SETITEMHEIGHT
:
5701 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5703 case TVM_SETSCROLLTIME
:
5704 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5706 case TVM_SETTEXTCOLOR
:
5707 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5709 case TVM_SETTOOLTIPS
:
5710 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5712 case TVM_SETUNICODEFORMAT
:
5713 return TREEVIEW_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
5715 case TVM_SORTCHILDREN
:
5716 return TREEVIEW_SortChildren(infoPtr
, lParam
);
5718 case TVM_SORTCHILDRENCB
:
5719 return TREEVIEW_SortChildrenCB(infoPtr
, (LPTVSORTCB
)lParam
);
5722 return TREEVIEW_ProcessLetterKeys(infoPtr
, wParam
, lParam
);
5725 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5728 return TREEVIEW_Destroy(infoPtr
);
5733 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5736 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5739 return TREEVIEW_GetFont(infoPtr
);
5742 return TREEVIEW_HScroll(infoPtr
, wParam
);
5745 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5748 return TREEVIEW_KillFocus(infoPtr
);
5750 case WM_LBUTTONDBLCLK
:
5751 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5753 case WM_LBUTTONDOWN
:
5754 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5756 /* WM_MBUTTONDOWN */
5759 return TREEVIEW_MouseLeave(infoPtr
);
5762 return TREEVIEW_MouseMove(infoPtr
, lParam
);
5764 case WM_NCLBUTTONDOWN
:
5765 if (infoPtr
->hwndEdit
)
5766 SetFocus(infoPtr
->hwnd
);
5770 return TREEVIEW_NCPaint (infoPtr
, (HRGN
)wParam
, lParam
);
5773 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5775 case WM_NOTIFYFORMAT
:
5776 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5778 case WM_PRINTCLIENT
:
5779 return TREEVIEW_PrintClient(infoPtr
, (HDC
)wParam
, lParam
);
5782 return TREEVIEW_Paint(infoPtr
, (HDC
)wParam
);
5784 case WM_RBUTTONDOWN
:
5785 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5788 return TREEVIEW_SetCursor(infoPtr
, wParam
, lParam
);
5791 return TREEVIEW_SetFocus(infoPtr
);
5794 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5797 return TREEVIEW_SetRedraw(infoPtr
, wParam
);
5800 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5802 case WM_STYLECHANGED
:
5803 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5805 case WM_SYSCOLORCHANGE
:
5806 COMCTL32_RefreshSysColors();
5812 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5814 case WM_THEMECHANGED
:
5815 return TREEVIEW_ThemeChanged (infoPtr
);
5818 return TREEVIEW_VScroll(infoPtr
, wParam
);
5820 /* WM_WININICHANGE */
5823 return TREEVIEW_MouseWheel(infoPtr
, wParam
, lParam
);
5826 TRACE("drawItem\n");
5830 /* This mostly catches MFC and Delphi messages. :( */
5831 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
5832 TRACE("Unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
5834 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
5839 /* Class Registration ***************************************************/
5842 TREEVIEW_Register(void)
5848 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
5849 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5850 wndClass
.lpfnWndProc
= TREEVIEW_WindowProc
;
5851 wndClass
.cbClsExtra
= 0;
5852 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5854 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
5855 wndClass
.hbrBackground
= 0;
5856 wndClass
.lpszClassName
= WC_TREEVIEWW
;
5858 RegisterClassW(&wndClass
);
5863 TREEVIEW_Unregister(void)
5865 UnregisterClassW(WC_TREEVIEWW
, NULL
);
5869 /* Tree Verification ****************************************************/
5872 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
);
5874 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5875 const TREEVIEW_ITEM
*item
)
5877 assert(infoPtr
!= NULL
);
5878 assert(item
!= NULL
);
5880 /* both NULL, or both non-null */
5881 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5883 assert(item
->firstChild
!= item
);
5884 assert(item
->lastChild
!= item
);
5886 if (item
->firstChild
)
5888 assert(item
->firstChild
->parent
== item
);
5889 assert(item
->firstChild
->prevSibling
== NULL
);
5892 if (item
->lastChild
)
5894 assert(item
->lastChild
->parent
== item
);
5895 assert(item
->lastChild
->nextSibling
== NULL
);
5898 assert(item
->nextSibling
!= item
);
5899 if (item
->nextSibling
)
5901 assert(item
->nextSibling
->parent
== item
->parent
);
5902 assert(item
->nextSibling
->prevSibling
== item
);
5905 assert(item
->prevSibling
!= item
);
5906 if (item
->prevSibling
)
5908 assert(item
->prevSibling
->parent
== item
->parent
);
5909 assert(item
->prevSibling
->nextSibling
== item
);
5914 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5916 assert(item
!= NULL
);
5918 assert(item
->parent
!= NULL
);
5919 assert(item
->parent
!= item
);
5920 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5922 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5924 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5926 TREEVIEW_VerifyChildren(infoPtr
, item
);
5930 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
5932 const TREEVIEW_ITEM
*child
;
5933 assert(item
!= NULL
);
5935 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5936 TREEVIEW_VerifyItem(infoPtr
, child
);
5940 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5942 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5944 assert(root
!= NULL
);
5945 assert(root
->iLevel
== -1);
5946 assert(root
->parent
== NULL
);
5947 assert(root
->prevSibling
== NULL
);
5949 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
5951 TREEVIEW_VerifyChildren(infoPtr
, root
);
5955 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
5957 if (!TRACE_ON(treeview
)) return;
5959 assert(infoPtr
!= NULL
);
5960 TREEVIEW_VerifyRoot(infoPtr
);