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: All items always! have valid (allocated) pszText field.
27 * If item's text == LPSTR_TEXTCALLBACKA we allocate buffer
28 * of size TEXT_CALLBACK_SIZE in DoSetItem.
29 * We use callbackMask to keep track of fields to be updated.
32 * missing notifications: NM_SETCURSOR, TVN_GETINFOTIP, TVN_KEYDOWN,
33 * TVN_SETDISPINFO, TVN_SINGLEEXPAND
35 * missing styles: TVS_FULLROWSELECT, TVS_INFOTIP, TVS_RTLREADING,
37 * missing item styles: TVIS_CUT, TVIS_EXPANDPARTIAL
39 * Make the insertion mark look right.
40 * Scroll (instead of repaint) as much as possible.
44 #include "wine/port.h"
53 #define NONAMELESSUNION
54 #define NONAMELESSSTRUCT
64 #include "wine/unicode.h"
65 #include "wine/debug.h"
67 /* internal structures */
69 typedef struct _TREEITEM
/* HTREEITEM is a _TREEINFO *. */
80 int iIntegral
; /* item height multiplier (1 is normal) */
81 int iLevel
; /* indentation level:0=root level */
82 HTREEITEM parent
; /* handle to parent or 0 if at root */
83 HTREEITEM firstChild
; /* handle to first child or 0 if no child */
85 HTREEITEM prevSibling
; /* handle to prev item in list, 0 if first */
86 HTREEITEM nextSibling
; /* handle to next item in list, 0 if last */
92 LONG textWidth
; /* horizontal text extent for pszText */
93 LONG visibleOrder
; /* visible ordering, 0 is first visible item */
97 typedef struct tagTREEVIEW_INFO
100 HWND hwndNotify
; /* Owner window to send notifications to */
103 UINT uInternalStatus
;
105 UINT uNumItems
; /* number of valid TREEVIEW_ITEMs */
106 INT cdmode
; /* last custom draw setting */
107 UINT uScrollTime
; /* max. time for scrolling in milliseconds */
108 BOOL bRedraw
; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
110 UINT uItemHeight
; /* item height */
113 LONG clientWidth
; /* width of control window */
114 LONG clientHeight
; /* height of control window */
116 LONG treeWidth
; /* width of visible tree items */
117 LONG treeHeight
; /* height of visible tree items */
119 UINT uIndent
; /* indentation in pixels */
120 HTREEITEM selectedItem
; /* handle to selected item or 0 if none */
121 HTREEITEM hotItem
; /* handle currently under cursor, 0 if none */
122 HTREEITEM focusedItem
; /* item that was under the cursor when WM_LBUTTONDOWN was received */
124 HTREEITEM firstVisible
; /* handle to first visible item */
125 LONG maxVisibleOrder
;
126 HTREEITEM dropItem
; /* handle to item selected by drag cursor */
127 HTREEITEM insertMarkItem
; /* item after which insertion mark is placed */
128 BOOL insertBeforeorAfter
; /* flag used by TVM_SETINSERTMARK */
129 HIMAGELIST dragList
; /* Bitmap of dragged item */
134 COLORREF clrInsertMark
;
138 HFONT hUnderlineFont
;
143 WNDPROC wpEditOrig
; /* orig window proc for subclassing edit */
144 BOOL bIgnoreEditKillFocus
;
147 BOOL bNtfUnicode
; /* TRUE if should send NOTIFY with W */
148 HIMAGELIST himlNormal
;
149 int normalImageHeight
;
150 int normalImageWidth
;
151 HIMAGELIST himlState
;
152 int stateImageHeight
;
156 DWORD lastKeyPressTimestamp
; /* Added */
157 WPARAM charCode
; /* Added */
158 INT nSearchParamLength
; /* Added */
159 WCHAR szSearchParam
[ MAX_PATH
]; /* Added */
163 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
164 #define KEY_DELAY 450
166 /* bitflags for infoPtr->uInternalStatus */
168 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
169 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
170 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
171 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
172 #define TV_RDRAG 0x10 /* dito Rbutton */
173 #define TV_RDRAGGING 0x20
175 /* bitflags for infoPtr->timer */
177 #define TV_EDIT_TIMER 2
178 #define TV_EDIT_TIMER_SET 2
181 VOID
TREEVIEW_Register (VOID
);
182 VOID
TREEVIEW_Unregister (VOID
);
185 WINE_DEFAULT_DEBUG_CHANNEL(treeview
);
188 #define TEXT_CALLBACK_SIZE 260
190 #define TREEVIEW_LEFT_MARGIN 8
192 #define MINIMUM_INDENT 19
194 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
196 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
197 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
198 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
201 static const WCHAR themeClass
[] = { 'T','r','e','e','v','i','e','w',0 };
204 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
207 static VOID
TREEVIEW_Invalidate(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
209 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
210 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
211 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
212 static LRESULT
TREEVIEW_RButtonUp(const TREEVIEW_INFO
*, const POINT
*);
213 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
214 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
215 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
216 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND wParam
, UINT lParam
);
219 /* Random Utilities *****************************************************/
223 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
228 /* The definition is at the end of the file. */
229 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
232 /* Returns the treeview private data if hwnd is a treeview.
233 * Otherwise returns an undefined value. */
234 static TREEVIEW_INFO
*
235 TREEVIEW_GetInfoPtr(HWND hwnd
)
237 return (TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
240 /* Don't call this. Nothing wants an item index. */
242 TREEVIEW_GetItemIndex(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
244 assert(infoPtr
!= NULL
);
246 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
249 /* Checks if item has changed and needs to be redrawn */
250 static inline BOOL
item_changed (const TREEVIEW_ITEM
*tiOld
, const TREEVIEW_ITEM
*tiNew
,
251 const TVITEMEXW
*tvChange
)
253 /* Number of children has changed */
254 if ((tvChange
->mask
& TVIF_CHILDREN
) && (tiOld
->cChildren
!= tiNew
->cChildren
))
257 /* Image has changed and it's not a callback */
258 if ((tvChange
->mask
& TVIF_IMAGE
) && (tiOld
->iImage
!= tiNew
->iImage
) &&
259 tiNew
->iImage
!= I_IMAGECALLBACK
)
262 /* Selected image has changed and it's not a callback */
263 if ((tvChange
->mask
& TVIF_SELECTEDIMAGE
) && (tiOld
->iSelectedImage
!= tiNew
->iSelectedImage
) &&
264 tiNew
->iSelectedImage
!= I_IMAGECALLBACK
)
267 /* Text has changed and it's not a callback */
268 if ((tvChange
->mask
& TVIF_TEXT
) && (tiOld
->pszText
!= tiNew
->pszText
) &&
269 tiNew
->pszText
!= LPSTR_TEXTCALLBACKW
)
272 /* Indent has changed */
273 if ((tvChange
->mask
& TVIF_INTEGRAL
) && (tiOld
->iIntegral
!= tiNew
->iIntegral
))
276 /* Item state has changed */
277 if ((tvChange
->mask
& TVIF_STATE
) && ((tiOld
->state
^ tiNew
->state
) & tvChange
->stateMask
))
283 /***************************************************************************
284 * This method checks that handle is an item for this tree.
287 TREEVIEW_ValidItem(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
289 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
291 TRACE("invalid item %p\n", handle
);
299 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
303 GetObjectW(hOrigFont
, sizeof(font
), &font
);
304 font
.lfWeight
= FW_BOLD
;
305 return CreateFontIndirectW(&font
);
309 TREEVIEW_CreateUnderlineFont(HFONT hOrigFont
)
313 GetObjectW(hOrigFont
, sizeof(font
), &font
);
314 font
.lfUnderline
= TRUE
;
315 return CreateFontIndirectW(&font
);
319 TREEVIEW_FontForItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
321 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
322 return infoPtr
->hUnderlineFont
;
323 if (item
->state
& TVIS_BOLD
)
324 return infoPtr
->hBoldFont
;
325 return infoPtr
->hFont
;
328 /* for trace/debugging purposes only */
330 TREEVIEW_ItemName(const TREEVIEW_ITEM
*item
)
332 if (item
== NULL
) return "<null item>";
333 if (item
->pszText
== LPSTR_TEXTCALLBACKW
) return "<callback>";
334 if (item
->pszText
== NULL
) return "<null>";
335 return debugstr_w(item
->pszText
);
338 /* An item is not a child of itself. */
340 TREEVIEW_IsChildOf(const TREEVIEW_ITEM
*parent
, const TREEVIEW_ITEM
*child
)
344 child
= child
->parent
;
345 if (child
== parent
) return TRUE
;
346 } while (child
!= NULL
);
352 /* Tree Traversal *******************************************************/
354 /***************************************************************************
355 * This method returns the last expanded sibling or child child item
358 static TREEVIEW_ITEM
*
359 TREEVIEW_GetLastListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
364 while (wineItem
->lastChild
)
366 if (wineItem
->state
& TVIS_EXPANDED
)
367 wineItem
= wineItem
->lastChild
;
372 if (wineItem
== infoPtr
->root
)
378 /***************************************************************************
379 * This method returns the previous non-hidden item in the list not
380 * considering the tree hierarchy.
382 static TREEVIEW_ITEM
*
383 TREEVIEW_GetPrevListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
385 if (tvItem
->prevSibling
)
387 /* This item has a prevSibling, get the last item in the sibling's tree. */
388 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
390 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
391 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
397 /* this item does not have a prevSibling, get the parent */
398 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
403 /***************************************************************************
404 * This method returns the next physical item in the treeview not
405 * considering the tree hierarchy.
407 static TREEVIEW_ITEM
*
408 TREEVIEW_GetNextListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
410 assert(tvItem
!= NULL
);
413 * If this item has children and is expanded, return the first child
415 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
417 return tvItem
->firstChild
;
422 * try to get the sibling
424 if (tvItem
->nextSibling
)
425 return tvItem
->nextSibling
;
428 * Otherwise, get the parent's sibling.
430 while (tvItem
->parent
)
432 tvItem
= tvItem
->parent
;
434 if (tvItem
->nextSibling
)
435 return tvItem
->nextSibling
;
441 /***************************************************************************
442 * This method returns the nth item starting at the given item. It returns
443 * the last item (or first) we we run out of items.
445 * Will scroll backward if count is <0.
446 * forward if count is >0.
448 static TREEVIEW_ITEM
*
449 TREEVIEW_GetListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
452 TREEVIEW_ITEM
*(*next_item
)(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
453 TREEVIEW_ITEM
*previousItem
;
455 assert(wineItem
!= NULL
);
459 next_item
= TREEVIEW_GetNextListItem
;
464 next_item
= TREEVIEW_GetPrevListItem
;
471 previousItem
= wineItem
;
472 wineItem
= next_item(infoPtr
, wineItem
);
474 } while (--count
&& wineItem
!= NULL
);
477 return wineItem
? wineItem
: previousItem
;
480 /* Notifications ************************************************************/
482 static INT
get_notifycode(const TREEVIEW_INFO
*infoPtr
, INT code
)
484 if (!infoPtr
->bNtfUnicode
) {
486 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
487 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
488 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
489 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
490 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
491 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
492 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
493 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
494 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
495 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
496 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
497 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
504 TREEVIEW_SendRealNotify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
506 TRACE("wParam=%ld, lParam=%ld\n", wParam
, lParam
);
507 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, wParam
, lParam
);
511 TREEVIEW_SendSimpleNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
)
514 HWND hwnd
= infoPtr
->hwnd
;
517 nmhdr
.hwndFrom
= hwnd
;
518 nmhdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
519 nmhdr
.code
= get_notifycode(infoPtr
, code
);
521 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
525 TREEVIEW_TVItemFromItem(const TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMW
*tvItem
, TREEVIEW_ITEM
*item
)
528 tvItem
->hItem
= item
;
529 tvItem
->state
= item
->state
;
530 tvItem
->stateMask
= 0;
531 tvItem
->iImage
= item
->iImage
;
532 tvItem
->iSelectedImage
= item
->iSelectedImage
;
533 tvItem
->cChildren
= item
->cChildren
;
534 tvItem
->lParam
= item
->lParam
;
538 if (!infoPtr
->bNtfUnicode
)
540 tvItem
->cchTextMax
= WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0, NULL
, NULL
);
541 tvItem
->pszText
= Alloc (tvItem
->cchTextMax
);
542 WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, 0, 0 );
546 tvItem
->cchTextMax
= item
->cchTextMax
;
547 tvItem
->pszText
= item
->pszText
;
552 tvItem
->cchTextMax
= 0;
553 tvItem
->pszText
= NULL
;
558 TREEVIEW_SendTreeviewNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
559 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
561 HWND hwnd
= infoPtr
->hwnd
;
565 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
566 code
, action
, oldItem
, newItem
);
568 ZeroMemory(&nmhdr
, sizeof(NMTREEVIEWW
));
570 nmhdr
.hdr
.hwndFrom
= hwnd
;
571 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
572 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
573 nmhdr
.action
= action
;
576 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
579 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
584 ret
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.hdr
.idFrom
, (LPARAM
)&nmhdr
);
585 if (!infoPtr
->bNtfUnicode
)
587 Free(nmhdr
.itemOld
.pszText
);
588 Free(nmhdr
.itemNew
.pszText
);
594 TREEVIEW_SendTreeviewDnDNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
,
595 HTREEITEM dragItem
, POINT pt
)
597 HWND hwnd
= infoPtr
->hwnd
;
600 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
602 nmhdr
.hdr
.hwndFrom
= hwnd
;
603 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
604 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
606 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
607 nmhdr
.itemNew
.hItem
= dragItem
;
608 nmhdr
.itemNew
.state
= dragItem
->state
;
609 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
611 nmhdr
.ptDrag
.x
= pt
.x
;
612 nmhdr
.ptDrag
.y
= pt
.y
;
614 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.hdr
.idFrom
, (LPARAM
)&nmhdr
);
619 TREEVIEW_SendCustomDrawNotify(const TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
622 HWND hwnd
= infoPtr
->hwnd
;
623 NMTVCUSTOMDRAW nmcdhdr
;
626 TRACE("drawstage:%x hdc:%p\n", dwDrawStage
, hdc
);
628 nmcd
= &nmcdhdr
.nmcd
;
629 nmcd
->hdr
.hwndFrom
= hwnd
;
630 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
631 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
632 nmcd
->dwDrawStage
= dwDrawStage
;
635 nmcd
->dwItemSpec
= 0;
636 nmcd
->uItemState
= 0;
637 nmcd
->lItemlParam
= 0;
638 nmcdhdr
.clrText
= infoPtr
->clrText
;
639 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
642 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, nmcd
->hdr
.idFrom
, (LPARAM
)&nmcdhdr
);
647 /* FIXME: need to find out when the flags in uItemState need to be set */
650 TREEVIEW_SendCustomDrawItemNotify(const TREEVIEW_INFO
*infoPtr
, HDC hdc
,
651 TREEVIEW_ITEM
*wineItem
, UINT uItemDrawState
,
652 NMTVCUSTOMDRAW
*nmcdhdr
)
654 HWND hwnd
= infoPtr
->hwnd
;
657 DWORD_PTR dwItemSpec
;
661 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
662 dwItemSpec
= (DWORD_PTR
)wineItem
;
664 if (wineItem
->state
& TVIS_SELECTED
)
665 uItemState
|= CDIS_SELECTED
;
666 if (wineItem
== infoPtr
->selectedItem
)
667 uItemState
|= CDIS_FOCUS
;
668 if (wineItem
== infoPtr
->hotItem
)
669 uItemState
|= CDIS_HOT
;
671 nmcd
= &nmcdhdr
->nmcd
;
672 nmcd
->hdr
.hwndFrom
= hwnd
;
673 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
674 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
675 nmcd
->dwDrawStage
= dwDrawStage
;
677 nmcd
->rc
= wineItem
->rect
;
678 nmcd
->dwItemSpec
= dwItemSpec
;
679 nmcd
->uItemState
= uItemState
;
680 nmcd
->lItemlParam
= wineItem
->lParam
;
681 nmcdhdr
->iLevel
= wineItem
->iLevel
;
683 TRACE("drawstage:%x hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
684 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
685 nmcd
->uItemState
, nmcd
->lItemlParam
);
687 retval
= TREEVIEW_SendRealNotify(infoPtr
, nmcd
->hdr
.idFrom
, (LPARAM
)nmcdhdr
);
693 TREEVIEW_BeginLabelEditNotify(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
695 HWND hwnd
= infoPtr
->hwnd
;
699 tvdi
.hdr
.hwndFrom
= hwnd
;
700 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
701 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_BEGINLABELEDITW
);
703 TREEVIEW_TVItemFromItem(infoPtr
, TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
,
704 &tvdi
.item
, editItem
);
706 ret
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, tvdi
.hdr
.idFrom
, (LPARAM
)&tvdi
);
708 if (!infoPtr
->bNtfUnicode
)
709 Free(tvdi
.item
.pszText
);
715 TREEVIEW_UpdateDispInfo(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
718 NMTVDISPINFOW callback
;
719 HWND hwnd
= infoPtr
->hwnd
;
721 TRACE("mask %x callbackMask %x\n", mask
, wineItem
->callbackMask
);
722 mask
&= wineItem
->callbackMask
;
724 if (mask
== 0) return;
726 callback
.hdr
.hwndFrom
= hwnd
;
727 callback
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
728 callback
.hdr
.code
= get_notifycode(infoPtr
, TVN_GETDISPINFOW
);
730 /* 'state' always contains valid value, as well as 'lParam'.
731 * All other parameters are uninitialized.
733 callback
.item
.pszText
= wineItem
->pszText
;
734 callback
.item
.cchTextMax
= wineItem
->cchTextMax
;
735 callback
.item
.mask
= mask
;
736 callback
.item
.hItem
= wineItem
;
737 callback
.item
.state
= wineItem
->state
;
738 callback
.item
.lParam
= wineItem
->lParam
;
740 /* If text is changed we need to recalculate textWidth */
741 if (mask
& TVIF_TEXT
)
742 wineItem
->textWidth
= 0;
744 TREEVIEW_SendRealNotify(infoPtr
, callback
.hdr
.idFrom
, (LPARAM
)&callback
);
746 /* It may have changed due to a call to SetItem. */
747 mask
&= wineItem
->callbackMask
;
749 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= wineItem
->pszText
)
751 /* Instead of copying text into our buffer user specified its own */
752 if (!infoPtr
->bNtfUnicode
) {
755 int len
= MultiByteToWideChar( CP_ACP
, 0,
756 (LPSTR
)callback
.item
.pszText
, -1,
758 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
759 newText
= (LPWSTR
)ReAlloc(wineItem
->pszText
, buflen
);
761 TRACE("returned str %s, len=%d, buflen=%d\n",
762 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
766 wineItem
->pszText
= newText
;
767 MultiByteToWideChar( CP_ACP
, 0,
768 (LPSTR
)callback
.item
.pszText
, -1,
769 wineItem
->pszText
, buflen
/sizeof(WCHAR
));
770 wineItem
->cchTextMax
= buflen
/sizeof(WCHAR
);
772 /* If ReAlloc fails we have nothing to do, but keep original text */
775 int len
= max(lstrlenW(callback
.item
.pszText
) + 1,
777 LPWSTR newText
= ReAlloc(wineItem
->pszText
, len
);
779 TRACE("returned wstr %s, len=%d\n",
780 debugstr_w(callback
.item
.pszText
), len
);
784 wineItem
->pszText
= newText
;
785 strcpyW(wineItem
->pszText
, callback
.item
.pszText
);
786 wineItem
->cchTextMax
= len
;
788 /* If ReAlloc fails we have nothing to do, but keep original text */
791 else if (mask
& TVIF_TEXT
) {
792 /* User put text into our buffer, that is ok unless A string */
793 if (!infoPtr
->bNtfUnicode
) {
795 LPWSTR oldText
= NULL
;
797 int len
= MultiByteToWideChar( CP_ACP
, 0,
798 (LPSTR
)callback
.item
.pszText
, -1,
800 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
801 newText
= (LPWSTR
)Alloc(buflen
);
803 TRACE("same buffer str %s, len=%d, buflen=%d\n",
804 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
808 oldText
= wineItem
->pszText
;
809 wineItem
->pszText
= newText
;
810 MultiByteToWideChar( CP_ACP
, 0,
811 (LPSTR
)callback
.item
.pszText
, -1,
812 wineItem
->pszText
, buflen
/sizeof(WCHAR
));
813 wineItem
->cchTextMax
= buflen
/sizeof(WCHAR
);
819 if (mask
& TVIF_IMAGE
)
820 wineItem
->iImage
= callback
.item
.iImage
;
822 if (mask
& TVIF_SELECTEDIMAGE
)
823 wineItem
->iSelectedImage
= callback
.item
.iSelectedImage
;
825 if (mask
& TVIF_CHILDREN
)
826 wineItem
->cChildren
= callback
.item
.cChildren
;
828 /* These members are now permanently set. */
829 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
830 wineItem
->callbackMask
&= ~callback
.item
.mask
;
833 /***************************************************************************
834 * This function uses cChildren field to decide whether the item has
836 * Note: if this returns TRUE, the child items may not actually exist,
837 * they could be virtual.
839 * Just use wineItem->firstChild to check for physical children.
842 TREEVIEW_HasChildren(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
844 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, TVIF_CHILDREN
);
846 return wineItem
->cChildren
> 0;
850 /* Item Position ********************************************************/
852 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
854 TREEVIEW_ComputeItemInternalMetrics(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
856 /* Same effect, different optimisation. */
858 BOOL lar
= ((infoPtr
->dwStyle
& TVS_LINESATROOT
)
859 && (infoPtr
->dwStyle
& (TVS_HASLINES
|TVS_HASBUTTONS
)));
861 BOOL lar
= ((infoPtr
->dwStyle
862 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
866 item
->linesOffset
= infoPtr
->uIndent
* (item
->iLevel
+ lar
- 1)
868 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
869 item
->imageOffset
= item
->stateOffset
870 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
871 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
875 TREEVIEW_ComputeTextWidth(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
881 /* DRAW's OM docker creates items like this */
882 if (item
->pszText
== NULL
)
894 hdc
= GetDC(infoPtr
->hwnd
);
895 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
898 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
899 item
->textWidth
= sz
.cx
;
903 SelectObject(hdc
, hOldFont
);
909 TREEVIEW_ComputeItemRect(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
911 item
->rect
.top
= infoPtr
->uItemHeight
*
912 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
914 item
->rect
.bottom
= item
->rect
.top
915 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
918 item
->rect
.right
= infoPtr
->clientWidth
;
921 /* We know that only items after start need their order updated. */
923 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
930 start
= infoPtr
->root
->firstChild
;
934 order
= start
->visibleOrder
;
936 for (item
= start
; item
!= NULL
;
937 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
939 if (!ISVISIBLE(item
) && order
> 0)
940 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
941 item
->visibleOrder
= order
;
942 order
+= item
->iIntegral
;
945 infoPtr
->maxVisibleOrder
= order
;
947 for (item
= start
; item
!= NULL
;
948 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
950 TREEVIEW_ComputeItemRect(infoPtr
, item
);
955 /* Update metrics of all items in selected subtree.
956 * root must be expanded
959 TREEVIEW_UpdateSubTree(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
961 TREEVIEW_ITEM
*sibling
;
965 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
968 root
->state
&= ~TVIS_EXPANDED
;
969 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
970 root
->state
|= TVIS_EXPANDED
;
972 hdc
= GetDC(infoPtr
->hwnd
);
973 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
975 for (; root
!= sibling
;
976 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
978 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
980 if (root
->callbackMask
& TVIF_TEXT
)
981 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
983 if (root
->textWidth
== 0)
985 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
986 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
990 SelectObject(hdc
, hOldFont
);
991 ReleaseDC(infoPtr
->hwnd
, hdc
);
994 /* Item Allocation **********************************************************/
996 static TREEVIEW_ITEM
*
997 TREEVIEW_AllocateItem(const TREEVIEW_INFO
*infoPtr
)
999 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
1004 /* I_IMAGENONE would make more sense but this is neither what is
1005 * documented (MSDN doesn't specify) nor what Windows actually does
1006 * (it sets it to zero)... and I can so imagine an application using
1007 * inc/dec to toggle the images. */
1008 newItem
->iImage
= 0;
1009 newItem
->iSelectedImage
= 0;
1011 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
1020 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
1021 * free item->pszText. */
1023 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1025 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
1027 if (infoPtr
->selectedItem
== item
)
1028 infoPtr
->selectedItem
= NULL
;
1029 if (infoPtr
->hotItem
== item
)
1030 infoPtr
->hotItem
= NULL
;
1031 if (infoPtr
->focusedItem
== item
)
1032 infoPtr
->focusedItem
= NULL
;
1033 if (infoPtr
->firstVisible
== item
)
1034 infoPtr
->firstVisible
= NULL
;
1035 if (infoPtr
->dropItem
== item
)
1036 infoPtr
->dropItem
= NULL
;
1037 if (infoPtr
->insertMarkItem
== item
)
1038 infoPtr
->insertMarkItem
= NULL
;
1042 /* Item Insertion *******************************************************/
1044 /***************************************************************************
1045 * This method inserts newItem before sibling as a child of parent.
1046 * sibling can be NULL, but only if parent has no children.
1049 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1050 TREEVIEW_ITEM
*parent
)
1052 assert(newItem
!= NULL
);
1053 assert(parent
!= NULL
);
1055 if (sibling
!= NULL
)
1057 assert(sibling
->parent
== parent
);
1059 if (sibling
->prevSibling
!= NULL
)
1060 sibling
->prevSibling
->nextSibling
= newItem
;
1062 newItem
->prevSibling
= sibling
->prevSibling
;
1063 sibling
->prevSibling
= newItem
;
1066 newItem
->prevSibling
= NULL
;
1068 newItem
->nextSibling
= sibling
;
1070 if (parent
->firstChild
== sibling
)
1071 parent
->firstChild
= newItem
;
1073 if (parent
->lastChild
== NULL
)
1074 parent
->lastChild
= newItem
;
1077 /***************************************************************************
1078 * This method inserts newItem after sibling as a child of parent.
1079 * sibling can be NULL, but only if parent has no children.
1082 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1083 TREEVIEW_ITEM
*parent
)
1085 assert(newItem
!= NULL
);
1086 assert(parent
!= NULL
);
1088 if (sibling
!= NULL
)
1090 assert(sibling
->parent
== parent
);
1092 if (sibling
->nextSibling
!= NULL
)
1093 sibling
->nextSibling
->prevSibling
= newItem
;
1095 newItem
->nextSibling
= sibling
->nextSibling
;
1096 sibling
->nextSibling
= newItem
;
1099 newItem
->nextSibling
= NULL
;
1101 newItem
->prevSibling
= sibling
;
1103 if (parent
->lastChild
== sibling
)
1104 parent
->lastChild
= newItem
;
1106 if (parent
->firstChild
== NULL
)
1107 parent
->firstChild
= newItem
;
1111 TREEVIEW_DoSetItemT(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
1112 const TVITEMEXW
*tvItem
, BOOL isW
)
1114 UINT callbackClear
= 0;
1115 UINT callbackSet
= 0;
1117 TRACE("item %p\n", wineItem
);
1118 /* Do this first in case it fails. */
1119 if (tvItem
->mask
& TVIF_TEXT
)
1121 wineItem
->textWidth
= 0; /* force width recalculation */
1122 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers != TEXTCALLBACKA too */
1127 len
= lstrlenW(tvItem
->pszText
) + 1;
1129 len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1, NULL
, 0);
1131 newText
= ReAlloc(wineItem
->pszText
, len
* sizeof(WCHAR
));
1133 if (newText
== NULL
) return FALSE
;
1135 callbackClear
|= TVIF_TEXT
;
1137 wineItem
->pszText
= newText
;
1138 wineItem
->cchTextMax
= len
;
1140 lstrcpynW(wineItem
->pszText
, tvItem
->pszText
, len
);
1142 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1,
1143 wineItem
->pszText
, len
);
1145 TRACE("setting text %s, item %p\n", debugstr_w(wineItem
->pszText
), wineItem
);
1149 callbackSet
|= TVIF_TEXT
;
1151 wineItem
->pszText
= ReAlloc(wineItem
->pszText
,
1152 TEXT_CALLBACK_SIZE
* sizeof(WCHAR
));
1153 wineItem
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1154 TRACE("setting callback, item %p\n", wineItem
);
1158 if (tvItem
->mask
& TVIF_CHILDREN
)
1160 wineItem
->cChildren
= tvItem
->cChildren
;
1162 if (wineItem
->cChildren
== I_CHILDRENCALLBACK
)
1163 callbackSet
|= TVIF_CHILDREN
;
1165 callbackClear
|= TVIF_CHILDREN
;
1168 if (tvItem
->mask
& TVIF_IMAGE
)
1170 wineItem
->iImage
= tvItem
->iImage
;
1172 if (wineItem
->iImage
== I_IMAGECALLBACK
)
1173 callbackSet
|= TVIF_IMAGE
;
1175 callbackClear
|= TVIF_IMAGE
;
1178 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1180 wineItem
->iSelectedImage
= tvItem
->iSelectedImage
;
1182 if (wineItem
->iSelectedImage
== I_IMAGECALLBACK
)
1183 callbackSet
|= TVIF_SELECTEDIMAGE
;
1185 callbackClear
|= TVIF_SELECTEDIMAGE
;
1188 if (tvItem
->mask
& TVIF_PARAM
)
1189 wineItem
->lParam
= tvItem
->lParam
;
1191 /* If the application sets TVIF_INTEGRAL without
1192 * supplying a TVITEMEX structure, it's toast. */
1193 if (tvItem
->mask
& TVIF_INTEGRAL
)
1194 wineItem
->iIntegral
= tvItem
->iIntegral
;
1196 if (tvItem
->mask
& TVIF_STATE
)
1198 TRACE("prevstate,state,mask:%x,%x,%x\n", wineItem
->state
, tvItem
->state
,
1200 wineItem
->state
&= ~tvItem
->stateMask
;
1201 wineItem
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1204 wineItem
->callbackMask
|= callbackSet
;
1205 wineItem
->callbackMask
&= ~callbackClear
;
1210 /* Note that the new item is pre-zeroed. */
1212 TREEVIEW_InsertItemT(TREEVIEW_INFO
*infoPtr
, const TVINSERTSTRUCTW
*ptdi
, BOOL isW
)
1214 const TVITEMEXW
*tvItem
= &ptdi
->u
.itemex
;
1215 HTREEITEM insertAfter
;
1216 TREEVIEW_ITEM
*newItem
, *parentItem
;
1217 BOOL bTextUpdated
= FALSE
;
1219 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1221 parentItem
= infoPtr
->root
;
1225 parentItem
= ptdi
->hParent
;
1227 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1229 WARN("invalid parent %p\n", parentItem
);
1230 return (LRESULT
)(HTREEITEM
)NULL
;
1234 insertAfter
= ptdi
->hInsertAfter
;
1236 /* Validate this now for convenience. */
1237 switch ((DWORD_PTR
)insertAfter
)
1239 case (DWORD_PTR
)TVI_FIRST
:
1240 case (DWORD_PTR
)TVI_LAST
:
1241 case (DWORD_PTR
)TVI_SORT
:
1245 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1246 insertAfter
->parent
!= parentItem
)
1248 WARN("invalid insert after %p\n", insertAfter
);
1249 insertAfter
= TVI_LAST
;
1253 TRACE("parent %p position %p: %s\n", parentItem
, insertAfter
,
1254 (tvItem
->mask
& TVIF_TEXT
)
1255 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKW
) ? "<callback>"
1256 : (isW
? debugstr_w(tvItem
->pszText
) : debugstr_a((LPSTR
)tvItem
->pszText
)))
1259 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1260 if (newItem
== NULL
)
1261 return (LRESULT
)(HTREEITEM
)NULL
;
1263 newItem
->parent
= parentItem
;
1264 newItem
->iIntegral
= 1;
1266 if (!TREEVIEW_DoSetItemT(infoPtr
, newItem
, tvItem
, isW
))
1267 return (LRESULT
)(HTREEITEM
)NULL
;
1269 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1271 infoPtr
->uNumItems
++;
1273 switch ((DWORD_PTR
)insertAfter
)
1275 case (DWORD_PTR
)TVI_FIRST
:
1277 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1278 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1279 if (infoPtr
->firstVisible
== originalFirst
)
1280 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1284 case (DWORD_PTR
)TVI_LAST
:
1285 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1288 /* hInsertAfter names a specific item we want to insert after */
1290 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1293 case (DWORD_PTR
)TVI_SORT
:
1295 TREEVIEW_ITEM
*aChild
;
1296 TREEVIEW_ITEM
*previousChild
= NULL
;
1297 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1298 BOOL bItemInserted
= FALSE
;
1300 aChild
= parentItem
->firstChild
;
1302 bTextUpdated
= TRUE
;
1303 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1305 /* Iterate the parent children to see where we fit in */
1306 while (aChild
!= NULL
)
1310 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1311 comp
= lstrcmpW(newItem
->pszText
, aChild
->pszText
);
1313 if (comp
< 0) /* we are smaller than the current one */
1315 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1316 if (infoPtr
->firstVisible
== originalFirst
&&
1317 aChild
== originalFirst
)
1318 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1319 bItemInserted
= TRUE
;
1322 else if (comp
> 0) /* we are bigger than the current one */
1324 previousChild
= aChild
;
1326 /* This will help us to exit if there is no more sibling */
1327 aChild
= (aChild
->nextSibling
== 0)
1329 : aChild
->nextSibling
;
1331 /* Look at the next item */
1337 * An item with this name is already existing, therefore,
1338 * we add after the one we found
1340 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1341 bItemInserted
= TRUE
;
1347 * we reach the end of the child list and the item has not
1348 * yet been inserted, therefore, insert it after the last child.
1350 if ((!bItemInserted
) && (aChild
== NULL
))
1351 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1358 TRACE("new item %p; parent %p, mask %x\n", newItem
,
1359 newItem
->parent
, tvItem
->mask
);
1361 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1363 if (newItem
->parent
->cChildren
== 0)
1364 newItem
->parent
->cChildren
= 1;
1366 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1368 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1369 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1372 if (infoPtr
->firstVisible
== NULL
)
1373 infoPtr
->firstVisible
= newItem
;
1375 TREEVIEW_VerifyTree(infoPtr
);
1377 if (parentItem
== infoPtr
->root
||
1378 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1380 TREEVIEW_ITEM
*item
;
1381 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1383 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1384 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1387 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1389 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1390 TREEVIEW_UpdateScrollBars(infoPtr
);
1392 * if the item was inserted in a visible part of the tree,
1393 * invalidate it, as well as those after it
1395 for (item
= newItem
;
1397 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1398 TREEVIEW_Invalidate(infoPtr
, item
);
1402 newItem
->visibleOrder
= -1;
1404 /* refresh treeview if newItem is the first item inserted under parentItem */
1405 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1407 /* parent got '+' - update it */
1408 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1412 return (LRESULT
)newItem
;
1415 /* Item Deletion ************************************************************/
1417 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
);
1420 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*parentItem
)
1422 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1424 while (kill
!= NULL
)
1426 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1428 TREEVIEW_RemoveItem(infoPtr
, kill
);
1433 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1434 assert(parentItem
->firstChild
== NULL
);
1435 assert(parentItem
->lastChild
== NULL
);
1439 TREEVIEW_UnlinkItem(const TREEVIEW_ITEM
*item
)
1441 TREEVIEW_ITEM
*parentItem
= item
->parent
;
1443 assert(item
!= NULL
);
1444 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1446 if (parentItem
->firstChild
== item
)
1447 parentItem
->firstChild
= item
->nextSibling
;
1449 if (parentItem
->lastChild
== item
)
1450 parentItem
->lastChild
= item
->prevSibling
;
1452 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1453 && parentItem
->cChildren
> 0)
1454 parentItem
->cChildren
= 0;
1456 if (item
->prevSibling
)
1457 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1459 if (item
->nextSibling
)
1460 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1464 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
1466 TRACE("%p, (%s)\n", wineItem
, TREEVIEW_ItemName(wineItem
));
1468 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1469 TVIF_HANDLE
| TVIF_PARAM
, wineItem
, 0);
1471 if (wineItem
->firstChild
)
1472 TREEVIEW_RemoveAllChildren(infoPtr
, wineItem
);
1474 TREEVIEW_UnlinkItem(wineItem
);
1476 infoPtr
->uNumItems
--;
1478 if (wineItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
1479 Free(wineItem
->pszText
);
1481 TREEVIEW_FreeItem(infoPtr
, wineItem
);
1485 /* Empty out the tree. */
1487 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1489 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1491 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1495 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM wineItem
)
1497 TREEVIEW_ITEM
*newSelection
= NULL
;
1498 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1499 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1500 BOOL visible
= FALSE
;
1502 if (wineItem
== TVI_ROOT
)
1504 TRACE("TVI_ROOT\n");
1505 parent
= infoPtr
->root
;
1506 newSelection
= NULL
;
1508 TREEVIEW_RemoveTree(infoPtr
);
1512 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
1515 TRACE("%p (%s)\n", wineItem
, TREEVIEW_ItemName(wineItem
));
1516 parent
= wineItem
->parent
;
1518 if (ISVISIBLE(wineItem
))
1520 prev
= TREEVIEW_GetPrevListItem(infoPtr
, wineItem
);
1524 if (infoPtr
->selectedItem
!= NULL
1525 && (wineItem
== infoPtr
->selectedItem
1526 || TREEVIEW_IsChildOf(wineItem
, infoPtr
->selectedItem
)))
1528 if (wineItem
->nextSibling
)
1529 newSelection
= wineItem
->nextSibling
;
1530 else if (wineItem
->parent
!= infoPtr
->root
)
1531 newSelection
= wineItem
->parent
;
1533 newSelection
= wineItem
->prevSibling
;
1534 TRACE("newSelection = %p\n", newSelection
);
1537 if (infoPtr
->firstVisible
== wineItem
)
1539 if (wineItem
->nextSibling
)
1540 newFirstVisible
= wineItem
->nextSibling
;
1541 else if (wineItem
->prevSibling
)
1542 newFirstVisible
= wineItem
->prevSibling
;
1543 else if (wineItem
->parent
!= infoPtr
->root
)
1544 newFirstVisible
= wineItem
->parent
;
1545 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1548 newFirstVisible
= infoPtr
->firstVisible
;
1550 TREEVIEW_RemoveItem(infoPtr
, wineItem
);
1553 /* Don't change if somebody else already has (infoPtr->selectedItem is cleared by FreeItem). */
1554 if (!infoPtr
->selectedItem
&& newSelection
)
1556 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1557 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1560 /* Validate insertMark dropItem.
1561 * hotItem ??? - used for comparison only.
1563 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1564 infoPtr
->insertMarkItem
= 0;
1566 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1567 infoPtr
->dropItem
= 0;
1569 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1570 newFirstVisible
= infoPtr
->root
->firstChild
;
1572 TREEVIEW_VerifyTree(infoPtr
);
1577 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1578 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1579 TREEVIEW_UpdateScrollBars(infoPtr
);
1580 TREEVIEW_Invalidate(infoPtr
, NULL
);
1582 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1584 /* parent lost '+/-' - update it */
1585 TREEVIEW_Invalidate(infoPtr
, parent
);
1592 /* Get/Set Messages *********************************************************/
1594 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
, LPARAM lParam
)
1597 infoPtr
->bRedraw
= TRUE
;
1599 infoPtr
->bRedraw
= FALSE
;
1605 TREEVIEW_GetIndent(const TREEVIEW_INFO
*infoPtr
)
1608 return infoPtr
->uIndent
;
1612 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1616 if (newIndent
< MINIMUM_INDENT
)
1617 newIndent
= MINIMUM_INDENT
;
1619 if (infoPtr
->uIndent
!= newIndent
)
1621 infoPtr
->uIndent
= newIndent
;
1622 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1623 TREEVIEW_UpdateScrollBars(infoPtr
);
1624 TREEVIEW_Invalidate(infoPtr
, NULL
);
1632 TREEVIEW_GetToolTips(const TREEVIEW_INFO
*infoPtr
)
1635 return (LRESULT
)infoPtr
->hwndToolTip
;
1639 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1644 prevToolTip
= infoPtr
->hwndToolTip
;
1645 infoPtr
->hwndToolTip
= hwndTT
;
1647 return (LRESULT
)prevToolTip
;
1651 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO
*infoPtr
, BOOL fUnicode
)
1653 BOOL rc
= infoPtr
->bNtfUnicode
;
1654 infoPtr
->bNtfUnicode
= fUnicode
;
1659 TREEVIEW_GetUnicodeFormat(const TREEVIEW_INFO
*infoPtr
)
1661 return infoPtr
->bNtfUnicode
;
1665 TREEVIEW_GetScrollTime(const TREEVIEW_INFO
*infoPtr
)
1667 return infoPtr
->uScrollTime
;
1671 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1673 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1675 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1677 return uOldScrollTime
;
1682 TREEVIEW_GetImageList(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1688 case (WPARAM
)TVSIL_NORMAL
:
1689 return (LRESULT
)infoPtr
->himlNormal
;
1691 case (WPARAM
)TVSIL_STATE
:
1692 return (LRESULT
)infoPtr
->himlState
;
1699 #define TVHEIGHT_MIN 16
1700 #define TVHEIGHT_FONT_ADJUST 3 /* 2 for focus border + 1 for margin some apps assume */
1702 /* Compute the natural height for items. */
1704 TREEVIEW_NaturalHeight(const TREEVIEW_INFO
*infoPtr
)
1708 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1711 /* Height is the maximum of:
1712 * 16 (a hack because our fonts are tiny), and
1713 * The text height + border & margin, and
1714 * The size of the normal image list
1716 GetTextMetricsW(hdc
, &tm
);
1717 SelectObject(hdc
, hOldFont
);
1720 height
= TVHEIGHT_MIN
;
1721 if (height
< tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
)
1722 height
= tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
;
1723 if (height
< infoPtr
->normalImageHeight
)
1724 height
= infoPtr
->normalImageHeight
;
1726 /* Round down, unless we support odd ("non even") heights. */
1727 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1734 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himlNew
)
1736 HIMAGELIST himlOld
= 0;
1737 int oldWidth
= infoPtr
->normalImageWidth
;
1738 int oldHeight
= infoPtr
->normalImageHeight
;
1741 TRACE("%lx,%p\n", wParam
, himlNew
);
1745 case (WPARAM
)TVSIL_NORMAL
:
1746 himlOld
= infoPtr
->himlNormal
;
1747 infoPtr
->himlNormal
= himlNew
;
1749 if (himlNew
!= NULL
)
1750 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1751 &infoPtr
->normalImageHeight
);
1754 infoPtr
->normalImageWidth
= 0;
1755 infoPtr
->normalImageHeight
= 0;
1760 case (WPARAM
)TVSIL_STATE
:
1761 himlOld
= infoPtr
->himlState
;
1762 infoPtr
->himlState
= himlNew
;
1764 if (himlNew
!= NULL
)
1765 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1766 &infoPtr
->stateImageHeight
);
1769 infoPtr
->stateImageWidth
= 0;
1770 infoPtr
->stateImageHeight
= 0;
1776 if (oldWidth
!= infoPtr
->normalImageWidth
||
1777 oldHeight
!= infoPtr
->normalImageHeight
)
1779 BOOL bRecalcVisible
= FALSE
;
1781 if (oldHeight
!= infoPtr
->normalImageHeight
&&
1782 !infoPtr
->bHeightSet
)
1784 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1785 bRecalcVisible
= TRUE
;
1788 if (infoPtr
->normalImageWidth
> MINIMUM_INDENT
&&
1789 infoPtr
->normalImageWidth
!= infoPtr
->uIndent
)
1791 infoPtr
->uIndent
= infoPtr
->normalImageWidth
;
1792 bRecalcVisible
= TRUE
;
1796 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1798 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1799 TREEVIEW_UpdateScrollBars(infoPtr
);
1802 TREEVIEW_Invalidate(infoPtr
, NULL
);
1804 return (LRESULT
)himlOld
;
1808 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1810 INT prevHeight
= infoPtr
->uItemHeight
;
1812 TRACE("%d\n", newHeight
);
1813 if (newHeight
== -1)
1815 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1816 infoPtr
->bHeightSet
= FALSE
;
1820 infoPtr
->uItemHeight
= newHeight
;
1821 infoPtr
->bHeightSet
= TRUE
;
1824 /* Round down, unless we support odd ("non even") heights. */
1825 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1826 infoPtr
->uItemHeight
&= ~1;
1828 if (infoPtr
->uItemHeight
!= prevHeight
)
1830 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1831 TREEVIEW_UpdateScrollBars(infoPtr
);
1832 TREEVIEW_Invalidate(infoPtr
, NULL
);
1839 TREEVIEW_GetItemHeight(const TREEVIEW_INFO
*infoPtr
)
1842 return infoPtr
->uItemHeight
;
1847 TREEVIEW_GetFont(const TREEVIEW_INFO
*infoPtr
)
1849 TRACE("%p\n", infoPtr
->hFont
);
1850 return (LRESULT
)infoPtr
->hFont
;
1855 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1859 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1865 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1867 UINT uHeight
= infoPtr
->uItemHeight
;
1869 TRACE("%p %i\n", hFont
, bRedraw
);
1871 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
1873 DeleteObject(infoPtr
->hBoldFont
);
1874 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1875 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
1877 if (!infoPtr
->bHeightSet
)
1878 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1880 if (uHeight
!= infoPtr
->uItemHeight
)
1881 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1883 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1885 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1886 TREEVIEW_UpdateScrollBars(infoPtr
);
1889 TREEVIEW_Invalidate(infoPtr
, NULL
);
1896 TREEVIEW_GetLineColor(const TREEVIEW_INFO
*infoPtr
)
1899 return (LRESULT
)infoPtr
->clrLine
;
1903 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1905 COLORREF prevColor
= infoPtr
->clrLine
;
1908 infoPtr
->clrLine
= color
;
1909 return (LRESULT
)prevColor
;
1914 TREEVIEW_GetTextColor(const TREEVIEW_INFO
*infoPtr
)
1917 return (LRESULT
)infoPtr
->clrText
;
1921 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1923 COLORREF prevColor
= infoPtr
->clrText
;
1926 infoPtr
->clrText
= color
;
1928 if (infoPtr
->clrText
!= prevColor
)
1929 TREEVIEW_Invalidate(infoPtr
, NULL
);
1931 return (LRESULT
)prevColor
;
1936 TREEVIEW_GetBkColor(const TREEVIEW_INFO
*infoPtr
)
1939 return (LRESULT
)infoPtr
->clrBk
;
1943 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1945 COLORREF prevColor
= infoPtr
->clrBk
;
1948 infoPtr
->clrBk
= newColor
;
1950 if (newColor
!= prevColor
)
1951 TREEVIEW_Invalidate(infoPtr
, NULL
);
1953 return (LRESULT
)prevColor
;
1958 TREEVIEW_GetInsertMarkColor(const TREEVIEW_INFO
*infoPtr
)
1961 return (LRESULT
)infoPtr
->clrInsertMark
;
1965 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1967 COLORREF prevColor
= infoPtr
->clrInsertMark
;
1969 TRACE("%x\n", color
);
1970 infoPtr
->clrInsertMark
= color
;
1972 return (LRESULT
)prevColor
;
1977 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
1979 TRACE("%d %p\n", wParam
, item
);
1981 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1984 infoPtr
->insertBeforeorAfter
= wParam
;
1985 infoPtr
->insertMarkItem
= item
;
1987 TREEVIEW_Invalidate(infoPtr
, NULL
);
1993 /************************************************************************
1994 * Some serious braindamage here. lParam is a pointer to both the
1995 * input HTREEITEM and the output RECT.
1998 TREEVIEW_GetItemRect(const TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
2000 TREEVIEW_ITEM
*wineItem
;
2001 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
2005 * validate parameters
2011 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
) || !ISVISIBLE(wineItem
))
2015 * If wParam is TRUE return the text size otherwise return
2016 * the whole item size
2020 /* Windows does not send TVN_GETDISPINFO here. */
2022 lpRect
->top
= wineItem
->rect
.top
;
2023 lpRect
->bottom
= wineItem
->rect
.bottom
;
2025 lpRect
->left
= wineItem
->textOffset
;
2026 if (!wineItem
->textWidth
)
2027 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, 0);
2029 lpRect
->right
= wineItem
->textOffset
+ wineItem
->textWidth
+ 4;
2033 *lpRect
= wineItem
->rect
;
2036 TRACE("%s [L:%d R:%d T:%d B:%d]\n", fTextRect
? "text" : "item",
2037 lpRect
->left
, lpRect
->right
, lpRect
->top
, lpRect
->bottom
);
2042 static inline LRESULT
2043 TREEVIEW_GetVisibleCount(const TREEVIEW_INFO
*infoPtr
)
2045 /* Suprise! This does not take integral height into account. */
2046 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2051 TREEVIEW_GetItemT(const TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2053 TREEVIEW_ITEM
*wineItem
;
2055 wineItem
= tvItem
->hItem
;
2056 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2059 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, tvItem
->mask
);
2061 if (tvItem
->mask
& TVIF_CHILDREN
)
2063 if (wineItem
->cChildren
==I_CHILDRENCALLBACK
)
2064 FIXME("I_CHILDRENCALLBACK not supported\n");
2065 tvItem
->cChildren
= wineItem
->cChildren
;
2068 if (tvItem
->mask
& TVIF_HANDLE
)
2069 tvItem
->hItem
= wineItem
;
2071 if (tvItem
->mask
& TVIF_IMAGE
)
2072 tvItem
->iImage
= wineItem
->iImage
;
2074 if (tvItem
->mask
& TVIF_INTEGRAL
)
2075 tvItem
->iIntegral
= wineItem
->iIntegral
;
2077 /* undocumented: windows ignores TVIF_PARAM and
2078 * * always sets lParam
2080 tvItem
->lParam
= wineItem
->lParam
;
2082 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2083 tvItem
->iSelectedImage
= wineItem
->iSelectedImage
;
2085 if (tvItem
->mask
& TVIF_STATE
)
2086 /* Careful here - Windows ignores the stateMask when you get the state
2087 That contradicts the documentation, but makes more common sense, masking
2088 retrieval in this way seems overkill */
2089 tvItem
->state
= wineItem
->state
;
2091 if (tvItem
->mask
& TVIF_TEXT
)
2095 if (wineItem
->pszText
== LPSTR_TEXTCALLBACKW
)
2097 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2098 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2102 lstrcpynW(tvItem
->pszText
, wineItem
->pszText
, tvItem
->cchTextMax
);
2107 if (wineItem
->pszText
== LPSTR_TEXTCALLBACKW
)
2109 tvItem
->pszText
= (LPWSTR
)LPSTR_TEXTCALLBACKA
;
2110 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2114 WideCharToMultiByte(CP_ACP
, 0, wineItem
->pszText
, -1,
2115 (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, NULL
, NULL
);
2119 TRACE("item <%p>, txt %p, img %p, mask %x\n",
2120 wineItem
, tvItem
->pszText
, &tvItem
->iImage
, tvItem
->mask
);
2125 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2126 * which is wrong. */
2128 TREEVIEW_SetItemT(TREEVIEW_INFO
*infoPtr
, const TVITEMEXW
*tvItem
, BOOL isW
)
2130 TREEVIEW_ITEM
*wineItem
;
2131 TREEVIEW_ITEM originalItem
;
2133 wineItem
= tvItem
->hItem
;
2135 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr
, wineItem
),
2138 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2141 /* store the orignal item values */
2142 originalItem
= *wineItem
;
2144 if (!TREEVIEW_DoSetItemT(infoPtr
, wineItem
, tvItem
, isW
))
2147 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2148 if ((tvItem
->mask
& TVIF_TEXT
2149 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2150 && ISVISIBLE(wineItem
))
2152 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, TVIF_TEXT
);
2153 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, 0);
2156 if (tvItem
->mask
!= 0 && ISVISIBLE(wineItem
))
2158 /* The refresh updates everything, but we can't wait until then. */
2159 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, wineItem
);
2161 /* if any of the item's values changed and it's not a callback, redraw the item */
2162 if (item_changed(&originalItem
, wineItem
, tvItem
))
2164 if (tvItem
->mask
& TVIF_INTEGRAL
)
2166 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
2167 TREEVIEW_UpdateScrollBars(infoPtr
);
2169 TREEVIEW_Invalidate(infoPtr
, NULL
);
2173 TREEVIEW_UpdateScrollBars(infoPtr
);
2174 TREEVIEW_Invalidate(infoPtr
, wineItem
);
2183 TREEVIEW_GetItemState(const TREEVIEW_INFO
*infoPtr
, HTREEITEM wineItem
, UINT mask
)
2187 if (!wineItem
|| !TREEVIEW_ValidItem(infoPtr
, wineItem
))
2190 return (wineItem
->state
& mask
);
2194 TREEVIEW_GetNextItem(const TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM wineItem
)
2196 TREEVIEW_ITEM
*retval
;
2200 /* handle all the global data here */
2203 case TVGN_CHILD
: /* Special case: child of 0 is root */
2208 retval
= infoPtr
->root
->firstChild
;
2212 retval
= infoPtr
->selectedItem
;
2215 case TVGN_FIRSTVISIBLE
:
2216 retval
= infoPtr
->firstVisible
;
2219 case TVGN_DROPHILITE
:
2220 retval
= infoPtr
->dropItem
;
2223 case TVGN_LASTVISIBLE
:
2224 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2230 TRACE("flags:%x, returns %p\n", which
, retval
);
2231 return (LRESULT
)retval
;
2234 if (wineItem
== TVI_ROOT
) wineItem
= infoPtr
->root
;
2236 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2242 retval
= wineItem
->nextSibling
;
2245 retval
= wineItem
->prevSibling
;
2248 retval
= (wineItem
->parent
!= infoPtr
->root
) ? wineItem
->parent
: NULL
;
2251 retval
= wineItem
->firstChild
;
2253 case TVGN_NEXTVISIBLE
:
2254 retval
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
2256 case TVGN_PREVIOUSVISIBLE
:
2257 retval
= TREEVIEW_GetPrevListItem(infoPtr
, wineItem
);
2260 TRACE("Unknown msg %x,item %p\n", which
, wineItem
);
2264 TRACE("flags:%x, item %p;returns %p\n", which
, wineItem
, retval
);
2265 return (LRESULT
)retval
;
2270 TREEVIEW_GetCount(const TREEVIEW_INFO
*infoPtr
)
2272 TRACE(" %d\n", infoPtr
->uNumItems
);
2273 return (LRESULT
)infoPtr
->uNumItems
;
2277 TREEVIEW_ToggleItemState(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2279 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2281 static const unsigned int state_table
[] = { 0, 2, 1 };
2285 state
= STATEIMAGEINDEX(item
->state
);
2286 TRACE("state:%x\n", state
);
2287 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2290 state
= state_table
[state
];
2292 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2294 TRACE("state:%x\n", state
);
2295 TREEVIEW_Invalidate(infoPtr
, item
);
2300 /* Painting *************************************************************/
2302 /* Draw the lines and expand button for an item. Also draws one section
2303 * of the line from item's parent to item's parent's next sibling. */
2305 TREEVIEW_DrawItemLines(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const TREEVIEW_ITEM
*item
)
2307 LONG centerx
, centery
;
2308 BOOL lar
= ((infoPtr
->dwStyle
2309 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2313 if (!lar
&& item
->iLevel
== 0)
2316 hbr
= CreateSolidBrush(infoPtr
->clrBk
);
2317 hbrOld
= SelectObject(hdc
, hbr
);
2319 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2320 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2322 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2324 HPEN hOldPen
, hNewPen
;
2328 /* Get a dotted grey pen */
2329 lb
.lbStyle
= BS_SOLID
;
2330 lb
.lbColor
= infoPtr
->clrLine
;
2331 hNewPen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, NULL
);
2332 hOldPen
= SelectObject(hdc
, hNewPen
);
2334 /* Make sure the center is on a dot (using +2 instead
2335 * of +1 gives us pixel-by-pixel compat with native) */
2336 centery
= (centery
+ 2) & ~1;
2338 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2339 LineTo(hdc
, centerx
- 1, centery
);
2341 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2343 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2344 LineTo(hdc
, centerx
, centery
);
2347 if (item
->nextSibling
)
2349 MoveToEx(hdc
, centerx
, centery
, NULL
);
2350 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2353 /* Draw the line from our parent to its next sibling. */
2354 parent
= item
->parent
;
2355 while (parent
!= infoPtr
->root
)
2357 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2359 if (parent
->nextSibling
2360 /* skip top-levels unless TVS_LINESATROOT */
2361 && parent
->stateOffset
> parent
->linesOffset
)
2363 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2364 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2367 parent
= parent
->parent
;
2370 SelectObject(hdc
, hOldPen
);
2371 DeleteObject(hNewPen
);
2375 * Display the (+/-) signs
2378 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2380 if (item
->cChildren
)
2382 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
2385 RECT glyphRect
= item
->rect
;
2386 glyphRect
.left
= item
->linesOffset
;
2387 glyphRect
.right
= item
->stateOffset
;
2388 DrawThemeBackground (theme
, hdc
, TVP_GLYPH
,
2389 (item
->state
& TVIS_EXPANDED
) ? GLPS_OPENED
: GLPS_CLOSED
,
2394 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2395 LONG width
= item
->stateOffset
- item
->linesOffset
;
2396 LONG rectsize
= min(height
, width
) / 4;
2397 /* plussize = ceil(rectsize * 3/4) */
2398 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2400 HPEN hNewPen
= CreatePen(PS_SOLID
, 0, infoPtr
->clrLine
);
2401 HPEN hOldPen
= SelectObject(hdc
, hNewPen
);
2403 Rectangle(hdc
, centerx
- rectsize
- 1, centery
- rectsize
- 1,
2404 centerx
+ rectsize
+ 2, centery
+ rectsize
+ 2);
2406 SelectObject(hdc
, hOldPen
);
2407 DeleteObject(hNewPen
);
2409 if (height
< 18 || width
< 18)
2411 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2412 LineTo(hdc
, centerx
+ plussize
, centery
);
2414 if (!(item
->state
& TVIS_EXPANDED
))
2416 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2417 LineTo(hdc
, centerx
, centery
+ plussize
);
2422 Rectangle(hdc
, centerx
- plussize
+ 1, centery
- 1,
2423 centerx
+ plussize
, centery
+ 2);
2425 if (!(item
->state
& TVIS_EXPANDED
))
2427 Rectangle(hdc
, centerx
- 1, centery
- plussize
+ 1,
2428 centerx
+ 2, centery
+ plussize
);
2429 SetPixel(hdc
, centerx
- 1, centery
, infoPtr
->clrBk
);
2430 SetPixel(hdc
, centerx
+ 1, centery
, infoPtr
->clrBk
);
2436 SelectObject(hdc
, hbrOld
);
2441 TREEVIEW_DrawItem(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*wineItem
)
2445 COLORREF oldTextColor
, oldTextBkColor
;
2447 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2448 NMTVCUSTOMDRAW nmcdhdr
;
2450 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, CALLBACK_MASK_ALL
);
2452 /* - If item is drop target or it is selected and window is in focus -
2453 * use blue background (COLOR_HIGHLIGHT).
2454 * - If item is selected, window is not in focus, but it has style
2455 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2456 * - Otherwise - use background color
2458 if ((wineItem
->state
& TVIS_DROPHILITED
) || ((wineItem
== infoPtr
->focusedItem
) && !(wineItem
->state
& TVIS_SELECTED
)) ||
2459 ((wineItem
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
) &&
2460 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2462 if ((wineItem
->state
& TVIS_DROPHILITED
) || inFocus
)
2464 nmcdhdr
.clrTextBk
= GetSysColor(COLOR_HIGHLIGHT
);
2465 nmcdhdr
.clrText
= GetSysColor(COLOR_HIGHLIGHTTEXT
);
2469 nmcdhdr
.clrTextBk
= GetSysColor(COLOR_BTNFACE
);
2470 if (infoPtr
->clrText
== -1)
2471 nmcdhdr
.clrText
= GetSysColor(COLOR_WINDOWTEXT
);
2473 nmcdhdr
.clrText
= infoPtr
->clrText
;
2478 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
2479 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (wineItem
== infoPtr
->hotItem
))
2480 nmcdhdr
.clrText
= comctl32_color
.clrHighlight
;
2481 else if (infoPtr
->clrText
== -1)
2482 nmcdhdr
.clrText
= GetSysColor(COLOR_WINDOWTEXT
);
2484 nmcdhdr
.clrText
= infoPtr
->clrText
;
2487 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, wineItem
));
2489 /* The custom draw handler can query the text rectangle,
2491 /* should already be known, set to 0 when changed */
2492 if (!wineItem
->textWidth
)
2493 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, hdc
);
2497 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2499 cditem
= TREEVIEW_SendCustomDrawItemNotify
2500 (infoPtr
, hdc
, wineItem
, CDDS_ITEMPREPAINT
, &nmcdhdr
);
2501 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2503 if (cditem
& CDRF_SKIPDEFAULT
)
2505 SelectObject(hdc
, hOldFont
);
2510 if (cditem
& CDRF_NEWFONT
)
2511 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, hdc
);
2513 TREEVIEW_DrawItemLines(infoPtr
, hdc
, wineItem
);
2515 /* Set colors. Custom draw handler can change these so we do this after it. */
2516 oldTextColor
= SetTextColor(hdc
, nmcdhdr
.clrText
);
2517 oldTextBkColor
= SetBkColor(hdc
, nmcdhdr
.clrTextBk
);
2519 centery
= (wineItem
->rect
.top
+ wineItem
->rect
.bottom
) / 2;
2522 * Display the images associated with this item
2527 /* State images are displayed to the left of the Normal image
2528 * image number is in state; zero should be `display no image'.
2530 imageIndex
= STATEIMAGEINDEX(wineItem
->state
);
2532 if (infoPtr
->himlState
&& imageIndex
)
2534 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2535 wineItem
->stateOffset
,
2536 centery
- infoPtr
->stateImageHeight
/ 2,
2540 /* Now, draw the normal image; can be either selected or
2541 * non-selected image.
2544 if ((wineItem
->state
& TVIS_SELECTED
) && (wineItem
->iSelectedImage
>= 0))
2546 /* The item is currently selected */
2547 imageIndex
= wineItem
->iSelectedImage
;
2551 /* The item is not selected */
2552 imageIndex
= wineItem
->iImage
;
2555 if (infoPtr
->himlNormal
)
2557 int ovlIdx
= wineItem
->state
& TVIS_OVERLAYMASK
;
2559 ImageList_Draw(infoPtr
->himlNormal
, imageIndex
, hdc
,
2560 wineItem
->imageOffset
,
2561 centery
- infoPtr
->normalImageHeight
/ 2,
2562 ILD_NORMAL
| ovlIdx
);
2568 * Display the text associated with this item
2571 /* Don't paint item's text if it's being edited */
2572 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= wineItem
))
2574 if (wineItem
->pszText
)
2578 rcText
.top
= wineItem
->rect
.top
;
2579 rcText
.bottom
= wineItem
->rect
.bottom
;
2580 rcText
.left
= wineItem
->textOffset
;
2581 rcText
.right
= rcText
.left
+ wineItem
->textWidth
+ 4;
2583 TRACE("drawing text %s at (%d,%d)-(%d,%d)\n",
2584 debugstr_w(wineItem
->pszText
),
2585 rcText
.left
, rcText
.top
, rcText
.right
, rcText
.bottom
);
2588 ExtTextOutW(hdc
, rcText
.left
+ 2, rcText
.top
+ 1,
2589 ETO_CLIPPED
| ETO_OPAQUE
,
2592 lstrlenW(wineItem
->pszText
),
2595 /* Draw the box around the selected item */
2596 if ((wineItem
== infoPtr
->selectedItem
) && inFocus
)
2598 DrawFocusRect(hdc
,&rcText
);
2604 /* Draw insertion mark if necessary */
2606 if (infoPtr
->insertMarkItem
)
2607 TRACE("item:%d,mark:%p\n",
2608 TREEVIEW_GetItemIndex(infoPtr
, wineItem
),
2609 infoPtr
->insertMarkItem
);
2611 if (wineItem
== infoPtr
->insertMarkItem
)
2613 HPEN hNewPen
, hOldPen
;
2617 hNewPen
= CreatePen(PS_SOLID
, 2, infoPtr
->clrInsertMark
);
2618 hOldPen
= SelectObject(hdc
, hNewPen
);
2620 if (infoPtr
->insertBeforeorAfter
)
2621 offset
= wineItem
->rect
.bottom
- 1;
2623 offset
= wineItem
->rect
.top
+ 1;
2625 left
= wineItem
->textOffset
- 2;
2626 right
= wineItem
->textOffset
+ wineItem
->textWidth
+ 2;
2628 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2629 LineTo(hdc
, left
, offset
+ 4);
2631 MoveToEx(hdc
, left
, offset
, NULL
);
2632 LineTo(hdc
, right
+ 1, offset
);
2634 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2635 LineTo(hdc
, right
, offset
- 4);
2637 SelectObject(hdc
, hOldPen
);
2638 DeleteObject(hNewPen
);
2641 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2643 cditem
= TREEVIEW_SendCustomDrawItemNotify
2644 (infoPtr
, hdc
, wineItem
, CDDS_ITEMPOSTPAINT
, &nmcdhdr
);
2645 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2648 /* Restore the hdc state */
2649 SetTextColor(hdc
, oldTextColor
);
2650 SetBkColor(hdc
, oldTextBkColor
);
2651 SelectObject(hdc
, hOldFont
);
2654 /* Computes treeHeight and treeWidth and updates the scroll bars.
2657 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2659 TREEVIEW_ITEM
*wineItem
;
2660 HWND hwnd
= infoPtr
->hwnd
;
2664 LONG scrollX
= infoPtr
->scrollX
;
2666 infoPtr
->treeWidth
= 0;
2667 infoPtr
->treeHeight
= 0;
2669 /* We iterate through all visible items in order to get the tree height
2671 wineItem
= infoPtr
->root
->firstChild
;
2673 while (wineItem
!= NULL
)
2675 if (ISVISIBLE(wineItem
))
2677 /* actually we draw text at textOffset + 2 */
2678 if (2+wineItem
->textOffset
+wineItem
->textWidth
> infoPtr
->treeWidth
)
2679 infoPtr
->treeWidth
= wineItem
->textOffset
+wineItem
->textWidth
+2;
2681 /* This is scroll-adjusted, but we fix this below. */
2682 infoPtr
->treeHeight
= wineItem
->rect
.bottom
;
2685 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
2688 /* Fix the scroll adjusted treeHeight and treeWidth. */
2689 if (infoPtr
->root
->firstChild
)
2690 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2692 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2694 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2696 /* Adding one scroll bar may take up enough space that it forces us
2697 * to add the other as well. */
2698 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2702 if (infoPtr
->treeWidth
2703 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2706 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
|| infoPtr
->scrollX
> 0)
2709 if (!vert
&& horz
&& infoPtr
->treeHeight
2710 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2713 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2715 si
.cbSize
= sizeof(SCROLLINFO
);
2716 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2721 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2722 if ( si
.nPage
&& NULL
!= infoPtr
->firstVisible
)
2724 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2725 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2727 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2729 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2730 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2731 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2735 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2736 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2737 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2742 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2743 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2744 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2749 si
.nPage
= infoPtr
->clientWidth
;
2750 si
.nPos
= infoPtr
->scrollX
;
2751 si
.nMax
= infoPtr
->treeWidth
- 1;
2753 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2755 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2759 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2760 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2761 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2763 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2764 TREEVIEW_HScroll(infoPtr
,
2765 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2769 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2770 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2771 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2774 if (infoPtr
->scrollX
!= 0)
2776 TREEVIEW_HScroll(infoPtr
,
2777 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2782 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2785 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2787 TREEVIEW_EraseBackground(const TREEVIEW_INFO
*infoPtr
, HDC hDC
)
2789 HBRUSH hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
2792 GetClientRect(infoPtr
->hwnd
, &rect
);
2793 FillRect(hDC
, &rect
, hBrush
);
2794 DeleteObject(hBrush
);
2800 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2802 HWND hwnd
= infoPtr
->hwnd
;
2804 TREEVIEW_ITEM
*wineItem
;
2806 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2808 TRACE("empty window\n");
2812 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2815 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2817 ReleaseDC(hwnd
, hdc
);
2821 for (wineItem
= infoPtr
->root
->firstChild
;
2823 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
))
2825 if (ISVISIBLE(wineItem
))
2827 /* Avoid unneeded calculations */
2828 if (wineItem
->rect
.top
> rect
.bottom
)
2830 if (wineItem
->rect
.bottom
< rect
.top
)
2833 TREEVIEW_DrawItem(infoPtr
, hdc
, wineItem
);
2837 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2839 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2843 TREEVIEW_Invalidate(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2846 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2848 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2852 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
2863 GetClientRect(infoPtr
->hwnd
, &rc
);
2864 TREEVIEW_EraseBackground(infoPtr
, hdc
);
2868 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
2872 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
2873 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
2876 EndPaint(infoPtr
->hwnd
, &ps
);
2882 /* Sorting **************************************************************/
2884 /***************************************************************************
2885 * Forward the DPA local callback to the treeview owner callback
2888 TREEVIEW_CallBackCompare(const TREEVIEW_ITEM
*first
, const TREEVIEW_ITEM
*second
,
2889 const TVSORTCB
*pCallBackSort
)
2891 /* Forward the call to the client-defined callback */
2892 return pCallBackSort
->lpfnCompare(first
->lParam
,
2894 pCallBackSort
->lParam
);
2897 /***************************************************************************
2898 * Treeview native sort routine: sort on item text.
2901 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
2902 const TREEVIEW_INFO
*infoPtr
)
2904 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
2905 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
2907 if(first
->pszText
&& second
->pszText
)
2908 return lstrcmpiW(first
->pszText
, second
->pszText
);
2909 else if(first
->pszText
)
2911 else if(second
->pszText
)
2917 /* Returns the number of physical children belonging to item. */
2919 TREEVIEW_CountChildren(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2924 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
2930 /* Returns a DPA containing a pointer to each physical child of item in
2931 * sibling order. If item has no children, an empty DPA is returned. */
2933 TREEVIEW_BuildChildDPA(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2935 HTREEITEM child
= item
->firstChild
;
2937 HDPA list
= DPA_Create(8);
2938 if (list
== 0) return NULL
;
2940 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
2942 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
2952 /***************************************************************************
2953 * Setup the treeview structure with regards of the sort method
2954 * and sort the children of the TV item specified in lParam
2955 * fRecurse: currently unused. Should be zero.
2956 * parent: if pSort!=NULL, should equal pSort->hParent.
2957 * otherwise, item which child items are to be sorted.
2958 * pSort: sort method info. if NULL, sort on item text.
2959 * if non-NULL, sort on item's lParam content, and let the
2960 * application decide what that means. See also TVM_SORTCHILDRENCB.
2964 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, BOOL fRecurse
, HTREEITEM parent
,
2968 PFNDPACOMPARE pfnCompare
;
2971 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
2972 if (parent
== TVI_ROOT
|| parent
== NULL
)
2973 parent
= infoPtr
->root
;
2975 /* Check for a valid handle to the parent item */
2976 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
2978 ERR("invalid item hParent=%p\n", parent
);
2984 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
2985 lpCompare
= (LPARAM
)pSort
;
2989 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
2990 lpCompare
= (LPARAM
)infoPtr
;
2993 cChildren
= TREEVIEW_CountChildren(infoPtr
, parent
);
2995 /* Make sure there is something to sort */
2998 /* TREEVIEW_ITEM rechaining */
3001 HTREEITEM nextItem
= 0;
3002 HTREEITEM prevItem
= 0;
3004 HDPA sortList
= TREEVIEW_BuildChildDPA(infoPtr
, parent
);
3006 if (sortList
== NULL
)
3009 /* let DPA sort the list */
3010 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
3012 /* The order of DPA entries has been changed, so fixup the
3013 * nextSibling and prevSibling pointers. */
3015 item
= (HTREEITEM
)DPA_GetPtr(sortList
, count
++);
3016 while ((nextItem
= (HTREEITEM
)DPA_GetPtr(sortList
, count
++)) != NULL
)
3018 /* link the two current item toghether */
3019 item
->nextSibling
= nextItem
;
3020 nextItem
->prevSibling
= item
;
3022 if (prevItem
== NULL
)
3024 /* this is the first item, update the parent */
3025 parent
->firstChild
= item
;
3026 item
->prevSibling
= NULL
;
3030 /* fix the back chaining */
3031 item
->prevSibling
= prevItem
;
3034 /* get ready for the next one */
3039 /* the last item is pointed to by item and never has a sibling */
3040 item
->nextSibling
= NULL
;
3041 parent
->lastChild
= item
;
3043 DPA_Destroy(sortList
);
3045 TREEVIEW_VerifyTree(infoPtr
);
3047 if (parent
->state
& TVIS_EXPANDED
)
3049 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3051 if (parent
== infoPtr
->root
)
3052 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3054 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3056 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3058 TREEVIEW_ITEM
*item
;
3060 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3061 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3063 if (item
->visibleOrder
== visOrder
)
3067 if (!item
) item
= parent
->firstChild
;
3068 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3071 TREEVIEW_Invalidate(infoPtr
, NULL
);
3080 /***************************************************************************
3081 * Setup the treeview structure with regards of the sort method
3082 * and sort the children of the TV item specified in lParam
3085 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPTVSORTCB pSort
)
3087 return TREEVIEW_Sort(infoPtr
, wParam
, pSort
->hParent
, pSort
);
3091 /***************************************************************************
3092 * Sort the children of the TV item specified in lParam.
3095 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3097 return TREEVIEW_Sort(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
, NULL
);
3101 /* Expansion/Collapse ***************************************************/
3104 TREEVIEW_SendExpanding(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3107 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3108 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3109 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3114 TREEVIEW_SendExpanded(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3117 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3118 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3119 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3124 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3125 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3127 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3128 BOOL bRemoveChildren
, BOOL bUser
)
3130 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3131 BOOL bSetSelection
, bSetFirstVisible
;
3133 LONG scrollDist
= 0;
3134 TREEVIEW_ITEM
*nextItem
= NULL
, *tmpItem
;
3136 TRACE("TVE_COLLAPSE %p %s\n", wineItem
, TREEVIEW_ItemName(wineItem
));
3138 if (!(wineItem
->state
& TVIS_EXPANDED
))
3141 if (bUser
|| !(wineItem
->state
& TVIS_EXPANDEDONCE
))
3142 TREEVIEW_SendExpanding(infoPtr
, wineItem
, action
);
3144 if (wineItem
->firstChild
== NULL
)
3147 wineItem
->state
&= ~TVIS_EXPANDED
;
3149 if (bUser
|| !(wineItem
->state
& TVIS_EXPANDEDONCE
))
3150 TREEVIEW_SendExpanded(infoPtr
, wineItem
, action
);
3152 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3153 && TREEVIEW_IsChildOf(wineItem
, infoPtr
->selectedItem
));
3155 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3156 && TREEVIEW_IsChildOf(wineItem
, infoPtr
->firstVisible
));
3161 if (tmpItem
->nextSibling
)
3163 nextItem
= tmpItem
->nextSibling
;
3166 tmpItem
= tmpItem
->parent
;
3170 scrollDist
= nextItem
->rect
.top
;
3172 if (bRemoveChildren
)
3174 INT old_cChildren
= wineItem
->cChildren
;
3175 TRACE("TVE_COLLAPSERESET\n");
3176 wineItem
->state
&= ~TVIS_EXPANDEDONCE
;
3177 TREEVIEW_RemoveAllChildren(infoPtr
, wineItem
);
3178 wineItem
->cChildren
= old_cChildren
;
3181 if (wineItem
->firstChild
)
3183 TREEVIEW_ITEM
*item
, *sibling
;
3185 sibling
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
3187 for (item
= wineItem
->firstChild
; item
!= sibling
;
3188 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3190 item
->visibleOrder
= -1;
3194 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
3197 scrollDist
= -(scrollDist
- nextItem
->rect
.top
);
3201 /* Don't call DoSelectItem, it sends notifications. */
3202 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3203 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3204 wineItem
->state
|= TVIS_SELECTED
;
3205 infoPtr
->selectedItem
= wineItem
;
3208 TREEVIEW_UpdateScrollBars(infoPtr
);
3210 scrollRect
.left
= 0;
3211 scrollRect
.right
= infoPtr
->clientWidth
;
3212 scrollRect
.bottom
= infoPtr
->clientHeight
;
3216 scrollRect
.top
= nextItem
->rect
.top
;
3218 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3219 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3220 TREEVIEW_Invalidate(infoPtr
, wineItem
);
3222 scrollRect
.top
= wineItem
->rect
.top
;
3223 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, TRUE
);
3226 TREEVIEW_SetFirstVisible(infoPtr
,
3227 bSetFirstVisible
? wineItem
: infoPtr
->firstVisible
,
3234 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3235 BOOL bExpandPartial
, BOOL bUser
)
3238 LONG orgNextTop
= 0;
3240 TREEVIEW_ITEM
*nextItem
, *tmpItem
;
3244 if (wineItem
->state
& TVIS_EXPANDED
)
3247 tmpItem
= wineItem
; nextItem
= NULL
;
3250 if (tmpItem
->nextSibling
)
3252 nextItem
= tmpItem
->nextSibling
;
3255 tmpItem
= tmpItem
->parent
;
3259 orgNextTop
= nextItem
->rect
.top
;
3261 TRACE("TVE_EXPAND %p %s\n", wineItem
, TREEVIEW_ItemName(wineItem
));
3263 if (bUser
|| ((wineItem
->cChildren
!= 0) &&
3264 !(wineItem
->state
& TVIS_EXPANDEDONCE
)))
3266 if (!TREEVIEW_SendExpanding(infoPtr
, wineItem
, TVE_EXPAND
))
3268 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3272 if (!wineItem
->firstChild
)
3275 wineItem
->state
|= TVIS_EXPANDED
;
3276 TREEVIEW_SendExpanded(infoPtr
, wineItem
, TVE_EXPAND
);
3277 wineItem
->state
|= TVIS_EXPANDEDONCE
;
3281 if (!wineItem
->firstChild
)
3284 /* this item has already been expanded */
3285 wineItem
->state
|= TVIS_EXPANDED
;
3289 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3291 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
3292 TREEVIEW_UpdateSubTree(infoPtr
, wineItem
);
3293 TREEVIEW_UpdateScrollBars(infoPtr
);
3295 scrollRect
.left
= 0;
3296 scrollRect
.bottom
= infoPtr
->treeHeight
;
3297 scrollRect
.right
= infoPtr
->clientWidth
;
3300 scrollDist
= nextItem
->rect
.top
- orgNextTop
;
3301 scrollRect
.top
= orgNextTop
;
3303 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3304 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3305 TREEVIEW_Invalidate (infoPtr
, wineItem
);
3307 scrollRect
.top
= wineItem
->rect
.top
;
3308 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, FALSE
);
3311 /* Scroll up so that as many children as possible are visible.
3312 * This fails when expanding causes an HScroll bar to appear, but we
3313 * don't know that yet, so the last item is obscured. */
3314 if (wineItem
->firstChild
!= NULL
)
3316 int nChildren
= wineItem
->lastChild
->visibleOrder
3317 - wineItem
->firstChild
->visibleOrder
+ 1;
3319 int visible_pos
= wineItem
->visibleOrder
3320 - infoPtr
->firstVisible
->visibleOrder
;
3322 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3324 if (visible_pos
> 0 && nChildren
> rows_below
)
3326 int scroll
= nChildren
- rows_below
;
3328 if (scroll
> visible_pos
)
3329 scroll
= visible_pos
;
3333 TREEVIEW_ITEM
*newFirstVisible
3334 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3338 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3347 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
, BOOL bUser
)
3351 if (wineItem
->state
& TVIS_EXPANDED
)
3352 return TREEVIEW_Collapse(infoPtr
, wineItem
, FALSE
, bUser
);
3354 return TREEVIEW_Expand(infoPtr
, wineItem
, FALSE
, bUser
);
3358 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3360 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3362 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3364 if (TREEVIEW_HasChildren(infoPtr
, item
))
3365 TREEVIEW_ExpandAll(infoPtr
, item
);
3369 /* Note:If the specified item is the child of a collapsed parent item,
3370 the parent's list of child items is (recursively) expanded to reveal the
3371 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3372 know if it also applies here.
3376 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM wineItem
)
3378 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
3381 TRACE("For (%s) item:%d, flags %x, state:%d\n",
3382 TREEVIEW_ItemName(wineItem
), flag
,
3383 TREEVIEW_GetItemIndex(infoPtr
, wineItem
), wineItem
->state
);
3385 switch (flag
& TVE_TOGGLE
)
3388 return TREEVIEW_Collapse(infoPtr
, wineItem
, flag
& TVE_COLLAPSERESET
,
3392 return TREEVIEW_Expand(infoPtr
, wineItem
, flag
& TVE_EXPANDPARTIAL
,
3396 return TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3403 TRACE("Exiting, Item %p state is now %d...\n", wineItem
, wineItem
->state
);
3407 /* Hit-Testing **********************************************************/
3409 static TREEVIEW_ITEM
*
3410 TREEVIEW_HitTestPoint(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3412 TREEVIEW_ITEM
*wineItem
;
3415 if (!infoPtr
->firstVisible
)
3418 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3420 for (wineItem
= infoPtr
->firstVisible
; wineItem
!= NULL
;
3421 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
))
3423 if (row
>= wineItem
->visibleOrder
3424 && row
< wineItem
->visibleOrder
+ wineItem
->iIntegral
)
3432 TREEVIEW_HitTest(const TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3434 TREEVIEW_ITEM
*wineItem
;
3440 GetClientRect(infoPtr
->hwnd
, &rect
);
3447 status
|= TVHT_TOLEFT
;
3449 else if (x
> rect
.right
)
3451 status
|= TVHT_TORIGHT
;
3456 status
|= TVHT_ABOVE
;
3458 else if (y
> rect
.bottom
)
3460 status
|= TVHT_BELOW
;
3465 lpht
->flags
= status
;
3466 return (LRESULT
)(HTREEITEM
)NULL
;
3469 wineItem
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3472 lpht
->flags
= TVHT_NOWHERE
;
3473 return (LRESULT
)(HTREEITEM
)NULL
;
3476 if (x
>= wineItem
->textOffset
+ wineItem
->textWidth
)
3478 lpht
->flags
= TVHT_ONITEMRIGHT
;
3480 else if (x
>= wineItem
->textOffset
)
3482 lpht
->flags
= TVHT_ONITEMLABEL
;
3484 else if (x
>= wineItem
->imageOffset
)
3486 lpht
->flags
= TVHT_ONITEMICON
;
3488 else if (x
>= wineItem
->stateOffset
)
3490 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3492 else if (x
>= wineItem
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3494 lpht
->flags
= TVHT_ONITEMBUTTON
;
3498 lpht
->flags
= TVHT_ONITEMINDENT
;
3501 lpht
->hItem
= wineItem
;
3502 TRACE("(%d,%d):result %x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3504 return (LRESULT
)wineItem
;
3507 /* Item Label Editing ***************************************************/
3510 TREEVIEW_GetEditControl(const TREEVIEW_INFO
*infoPtr
)
3512 return (LRESULT
)infoPtr
->hwndEdit
;
3515 static LRESULT CALLBACK
3516 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3518 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3519 BOOL bCancel
= FALSE
;
3525 TRACE("WM_PAINT start\n");
3526 rc
= CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3528 TRACE("WM_PAINT done\n");
3532 if (infoPtr
->bIgnoreEditKillFocus
)
3537 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3540 if (wParam
== (WPARAM
)VK_ESCAPE
)
3545 else if (wParam
== (WPARAM
)VK_RETURN
)
3552 return CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3555 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3556 /* eg. Using a messagebox */
3558 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3559 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3560 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3566 /* should handle edit control messages here */
3569 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3571 TRACE("%lx %ld\n", wParam
, lParam
);
3573 switch (HIWORD(wParam
))
3578 * Adjust the edit window size
3581 TREEVIEW_ITEM
*editItem
= infoPtr
->selectedItem
;
3582 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3585 HFONT hFont
, hOldFont
= 0;
3587 infoPtr
->bLabelChanged
= TRUE
;
3589 len
= GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
));
3591 /* Select font to get the right dimension of the string */
3592 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3596 hOldFont
= SelectObject(hdc
, hFont
);
3599 if (GetTextExtentPoint32W(hdc
, buffer
, strlenW(buffer
), &sz
))
3601 TEXTMETRICW textMetric
;
3603 /* Add Extra spacing for the next character */
3604 GetTextMetricsW(hdc
, &textMetric
);
3605 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3607 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3609 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3611 SetWindowPos(infoPtr
->hwndEdit
,
3616 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3617 SWP_NOMOVE
| SWP_DRAWFRAME
);
3622 SelectObject(hdc
, hOldFont
);
3625 ReleaseDC(infoPtr
->hwnd
, hdc
);
3630 return SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3637 TREEVIEW_EditLabel(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3639 HWND hwnd
= infoPtr
->hwnd
;
3642 TREEVIEW_ITEM
*editItem
= hItem
;
3643 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
);
3646 TEXTMETRICW textMetric
;
3647 static const WCHAR EditW
[] = {'E','d','i','t',0};
3649 TRACE("%p %p\n", hwnd
, hItem
);
3650 if (!TREEVIEW_ValidItem(infoPtr
, editItem
))
3653 if (infoPtr
->hwndEdit
)
3654 return infoPtr
->hwndEdit
;
3656 infoPtr
->bLabelChanged
= FALSE
;
3658 /* Make sure that edit item is selected */
3659 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, hItem
, TVC_UNKNOWN
);
3660 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3662 TREEVIEW_UpdateDispInfo(infoPtr
, editItem
, TVIF_TEXT
);
3665 /* Select the font to get appropriate metric dimensions */
3666 if (infoPtr
->hFont
!= 0)
3668 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3671 /* Get string length in pixels */
3672 GetTextExtentPoint32W(hdc
, editItem
->pszText
, strlenW(editItem
->pszText
),
3675 /* Add Extra spacing for the next character */
3676 GetTextMetricsW(hdc
, &textMetric
);
3677 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3679 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3680 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3682 if (infoPtr
->hFont
!= 0)
3684 SelectObject(hdc
, hOldFont
);
3687 ReleaseDC(hwnd
, hdc
);
3688 hwndEdit
= CreateWindowExW(WS_EX_LEFT
,
3691 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3692 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3693 ES_LEFT
, editItem
->textOffset
- 2,
3694 editItem
->rect
.top
- 1, sz
.cx
+ 3,
3695 editItem
->rect
.bottom
-
3696 editItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3697 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3699 infoPtr
->hwndEdit
= hwndEdit
;
3701 /* Get a 2D border. */
3702 SetWindowLongW(hwndEdit
, GWL_EXSTYLE
,
3703 GetWindowLongW(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3704 SetWindowLongW(hwndEdit
, GWL_STYLE
,
3705 GetWindowLongW(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3707 SendMessageW(hwndEdit
, WM_SETFONT
,
3708 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, editItem
), FALSE
);
3710 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
,
3712 TREEVIEW_Edit_SubclassProc
);
3714 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, editItem
))
3716 DestroyWindow(hwndEdit
);
3717 infoPtr
->hwndEdit
= 0;
3721 infoPtr
->selectedItem
= hItem
;
3722 SetWindowTextW(hwndEdit
, editItem
->pszText
);
3724 SendMessageW(hwndEdit
, EM_SETSEL
, 0, -1);
3725 ShowWindow(hwndEdit
, SW_SHOW
);
3732 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3734 HWND hwnd
= infoPtr
->hwnd
;
3735 TREEVIEW_ITEM
*editedItem
= infoPtr
->selectedItem
;
3738 WCHAR tmpText
[1024] = { '\0' };
3739 WCHAR
*newText
= tmpText
;
3742 if (!infoPtr
->hwndEdit
)
3745 tvdi
.hdr
.hwndFrom
= hwnd
;
3746 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
3747 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_ENDLABELEDITW
);
3749 tvdi
.item
.hItem
= editedItem
;
3750 tvdi
.item
.state
= editedItem
->state
;
3751 tvdi
.item
.lParam
= editedItem
->lParam
;
3755 if (!infoPtr
->bNtfUnicode
)
3756 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, (LPSTR
)tmpText
, 1023);
3758 iLength
= GetWindowTextW(infoPtr
->hwndEdit
, tmpText
, 1023);
3760 if (iLength
>= 1023)
3762 ERR("Insufficient space to retrieve new item label\n");
3765 tvdi
.item
.mask
= TVIF_TEXT
;
3766 tvdi
.item
.pszText
= tmpText
;
3767 tvdi
.item
.cchTextMax
= iLength
+ 1;
3771 tvdi
.item
.pszText
= NULL
;
3772 tvdi
.item
.cchTextMax
= 0;
3775 bCommit
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, tvdi
.hdr
.idFrom
, (LPARAM
)&tvdi
);
3777 if (!bCancel
&& bCommit
) /* Apply the changes */
3779 if (!infoPtr
->bNtfUnicode
)
3781 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, NULL
, 0 );
3782 newText
= Alloc(len
* sizeof(WCHAR
));
3783 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, newText
, len
);
3787 if (strcmpW(newText
, editedItem
->pszText
) != 0)
3789 WCHAR
*ptr
= ReAlloc(editedItem
->pszText
, sizeof(WCHAR
)*(iLength
+ 1));
3792 ERR("OutOfMemory, cannot allocate space for label\n");
3793 if(newText
!= tmpText
) Free(newText
);
3794 DestroyWindow(infoPtr
->hwndEdit
);
3795 infoPtr
->hwndEdit
= 0;
3800 editedItem
->pszText
= ptr
;
3801 editedItem
->cchTextMax
= iLength
+ 1;
3802 strcpyW(editedItem
->pszText
, newText
);
3803 TREEVIEW_ComputeTextWidth(infoPtr
, editedItem
, 0);
3806 if(newText
!= tmpText
) Free(newText
);
3809 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
3810 DestroyWindow(infoPtr
->hwndEdit
);
3811 infoPtr
->hwndEdit
= 0;
3816 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
3818 if (wParam
!= TV_EDIT_TIMER
)
3820 ERR("got unknown timer\n");
3824 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
3825 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
3827 TREEVIEW_EditLabel(infoPtr
, infoPtr
->selectedItem
);
3833 /* Mouse Tracking/Drag **************************************************/
3835 /***************************************************************************
3836 * This is quite unusual piece of code, but that's how it's implemented in
3840 TREEVIEW_TrackMouse(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3842 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
3843 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
3847 r
.top
= pt
.y
- cyDrag
;
3848 r
.left
= pt
.x
- cxDrag
;
3849 r
.bottom
= pt
.y
+ cyDrag
;
3850 r
.right
= pt
.x
+ cxDrag
;
3852 SetCapture(infoPtr
->hwnd
);
3856 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
3858 if (msg
.message
== WM_MOUSEMOVE
)
3860 pt
.x
= (short)LOWORD(msg
.lParam
);
3861 pt
.y
= (short)HIWORD(msg
.lParam
);
3862 if (PtInRect(&r
, pt
))
3870 else if (msg
.message
>= WM_LBUTTONDOWN
&&
3871 msg
.message
<= WM_RBUTTONDBLCLK
)
3873 if (msg
.message
== WM_RBUTTONUP
)
3874 TREEVIEW_RButtonUp(infoPtr
, &pt
);
3878 DispatchMessageW(&msg
);
3881 if (GetCapture() != infoPtr
->hwnd
)
3891 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3893 TREEVIEW_ITEM
*wineItem
;
3897 SetFocus(infoPtr
->hwnd
);
3899 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
3901 /* If there is pending 'edit label' event - kill it now */
3902 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
3905 hit
.pt
.x
= (short)LOWORD(lParam
);
3906 hit
.pt
.y
= (short)HIWORD(lParam
);
3908 wineItem
= (TREEVIEW_ITEM
*)TREEVIEW_HitTest(infoPtr
, &hit
);
3911 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, wineItem
));
3913 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
3917 case TVHT_ONITEMRIGHT
:
3918 /* FIXME: we should not have sent NM_DBLCLK in this case. */
3921 case TVHT_ONITEMINDENT
:
3922 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
3928 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
3929 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
3931 while (wineItem
->iLevel
> level
)
3933 wineItem
= wineItem
->parent
;
3939 case TVHT_ONITEMLABEL
:
3940 case TVHT_ONITEMICON
:
3941 case TVHT_ONITEMBUTTON
:
3942 TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3945 case TVHT_ONITEMSTATEICON
:
3946 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
3947 TREEVIEW_ToggleItemState(infoPtr
, wineItem
);
3949 TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3958 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3960 HWND hwnd
= infoPtr
->hwnd
;
3962 BOOL bTrack
, bDoLabelEdit
;
3965 /* If Edit control is active - kill it and return.
3966 * The best way to do it is to set focus to itself.
3967 * Edit control subclassed procedure will automatically call
3970 if (infoPtr
->hwndEdit
)
3976 ht
.pt
.x
= (short)LOWORD(lParam
);
3977 ht
.pt
.y
= (short)HIWORD(lParam
);
3979 TREEVIEW_HitTest(infoPtr
, &ht
);
3980 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
3982 /* update focusedItem and redraw both items */
3983 if(ht
.hItem
&& (ht
.flags
& TVHT_ONITEM
))
3985 infoPtr
->focusedItem
= ht
.hItem
;
3986 InvalidateRect(hwnd
, &ht
.hItem
->rect
, TRUE
);
3988 if(infoPtr
->selectedItem
)
3989 InvalidateRect(hwnd
, &(infoPtr
->selectedItem
->rect
), TRUE
);
3992 bTrack
= (ht
.flags
& TVHT_ONITEM
)
3993 && !(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
);
3996 * If the style allows editing and the node is already selected
3997 * and the click occurred on the item label...
3999 bDoLabelEdit
= (infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
4000 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
);
4002 /* Send NM_CLICK right away */
4004 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4007 if (ht
.flags
& TVHT_ONITEMBUTTON
)
4009 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
4013 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
4014 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4016 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
4017 infoPtr
->dropItem
= ht
.hItem
;
4019 /* clean up focusedItem as we dragged and won't select this item */
4020 if(infoPtr
->focusedItem
)
4022 /* refresh the item that was focused */
4023 tempItem
= infoPtr
->focusedItem
;
4024 infoPtr
->focusedItem
= 0;
4025 InvalidateRect(infoPtr
->hwnd
, &tempItem
->rect
, TRUE
);
4027 /* refresh the selected item to return the filled background */
4028 InvalidateRect(infoPtr
->hwnd
, &(infoPtr
->selectedItem
->rect
), TRUE
);
4035 if (bTrack
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4040 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4041 KillTimer(hwnd
, TV_EDIT_TIMER
);
4043 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
4044 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
4046 else if (ht
.flags
& (TVHT_ONITEMICON
|TVHT_ONITEMLABEL
)) /* select the item if the hit was inside of the icon or text */
4049 * if we are TVS_SINGLEEXPAND then we want this single click to
4050 * do a bunch of things.
4052 if((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) &&
4053 (infoPtr
->hwndEdit
== 0))
4055 TREEVIEW_ITEM
*SelItem
;
4058 * Send the notification
4060 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, ht
.hItem
, 0);
4063 * Close the previous selection all the way to the root
4064 * as long as the new selection is not a child
4066 if((infoPtr
->selectedItem
)
4067 && (infoPtr
->selectedItem
!= ht
.hItem
))
4069 BOOL closeit
= TRUE
;
4072 /* determine if the hitItem is a child of the currently selected item */
4073 while(closeit
&& SelItem
&& TREEVIEW_ValidItem(infoPtr
, SelItem
) && (SelItem
!= infoPtr
->root
))
4075 closeit
= (SelItem
!= infoPtr
->selectedItem
);
4076 SelItem
= SelItem
->parent
;
4081 if(TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
4082 SelItem
= infoPtr
->selectedItem
;
4084 while(SelItem
&& (SelItem
!= ht
.hItem
) && TREEVIEW_ValidItem(infoPtr
, SelItem
) && (SelItem
!= infoPtr
->root
))
4086 TREEVIEW_Collapse(infoPtr
, SelItem
, FALSE
, FALSE
);
4087 SelItem
= SelItem
->parent
;
4093 * Expand the current item
4095 TREEVIEW_Expand(infoPtr
, ht
.hItem
, TVE_TOGGLE
, FALSE
);
4098 /* Select the current item */
4099 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4101 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4103 /* TVS_CHECKBOXES requires us to toggle the current state */
4104 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4105 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4115 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4119 if (infoPtr
->hwndEdit
)
4121 SetFocus(infoPtr
->hwnd
);
4125 ht
.pt
.x
= (short)LOWORD(lParam
);
4126 ht
.pt
.y
= (short)HIWORD(lParam
);
4128 TREEVIEW_HitTest(infoPtr
, &ht
);
4130 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4134 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4135 infoPtr
->dropItem
= ht
.hItem
;
4140 SetFocus(infoPtr
->hwnd
);
4141 TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
);
4148 TREEVIEW_RButtonUp(const TREEVIEW_INFO
*infoPtr
, const POINT
*pPt
)
4154 TREEVIEW_HitTest(infoPtr
, &ht
);
4158 /* Change to screen coordinate for WM_CONTEXTMENU */
4159 ClientToScreen(infoPtr
->hwnd
, &ht
.pt
);
4161 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
4162 SendMessageW(infoPtr
->hwnd
, WM_CONTEXTMENU
,
4163 (WPARAM
)infoPtr
->hwnd
, MAKELPARAM(ht
.pt
.x
, ht
.pt
.y
));
4170 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4172 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4176 HBITMAP hbmp
, hOldbmp
;
4183 if (!(infoPtr
->himlNormal
))
4186 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4189 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4191 hwtop
= GetDesktopWindow();
4192 htopdc
= GetDC(hwtop
);
4193 hdc
= CreateCompatibleDC(htopdc
);
4195 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4196 GetTextExtentPoint32W(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
),
4198 TRACE("%d %d %s %d\n", size
.cx
, size
.cy
, debugstr_w(dragItem
->pszText
),
4199 strlenW(dragItem
->pszText
));
4200 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4201 hOldbmp
= SelectObject(hdc
, hbmp
);
4203 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4208 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4209 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4213 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4214 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4217 /* draw item text */
4219 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4220 DrawTextW(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
), &rc
,
4222 SelectObject(hdc
, hOldFont
);
4223 SelectObject(hdc
, hOldbmp
);
4225 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4229 ReleaseDC(hwtop
, htopdc
);
4231 return (LRESULT
)infoPtr
->dragList
;
4234 /* Selection ************************************************************/
4237 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4240 TREEVIEW_ITEM
*prevSelect
;
4243 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4245 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4246 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4247 newSelect
? newSelect
->state
: 0);
4249 /* reset and redraw focusedItem if focusedItem was set so we don't */
4250 /* have to worry about the previously focused item when we set a new one */
4251 if(infoPtr
->focusedItem
)
4253 rcFocused
= (infoPtr
->focusedItem
)->rect
;
4254 infoPtr
->focusedItem
= 0;
4255 InvalidateRect(infoPtr
->hwnd
, &rcFocused
, TRUE
);
4261 prevSelect
= infoPtr
->selectedItem
;
4263 if (prevSelect
== newSelect
) {
4264 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4268 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4271 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4277 prevSelect
->state
&= ~TVIS_SELECTED
;
4279 newSelect
->state
|= TVIS_SELECTED
;
4281 infoPtr
->selectedItem
= newSelect
;
4283 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4286 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4288 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4290 TREEVIEW_SendTreeviewNotify(infoPtr
,
4293 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4298 case TVGN_DROPHILITE
:
4299 prevSelect
= infoPtr
->dropItem
;
4302 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4304 infoPtr
->dropItem
= newSelect
;
4307 newSelect
->state
|= TVIS_DROPHILITED
;
4309 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4310 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4313 case TVGN_FIRSTVISIBLE
:
4314 if (newSelect
!= NULL
)
4316 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4317 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4318 TREEVIEW_Invalidate(infoPtr
, NULL
);
4323 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4327 /* FIXME: handle NM_KILLFOCUS etc */
4329 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4331 if (item
!= NULL
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4334 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4336 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4342 /*************************************************************************
4343 * TREEVIEW_ProcessLetterKeys
4345 * Processes keyboard messages generated by pressing the letter keys
4347 * What this does is perform a case insensitive search from the
4348 * current position with the following quirks:
4349 * - If two chars or more are pressed in quick succession we search
4350 * for the corresponding string (e.g. 'abc').
4351 * - If there is a delay we wipe away the current search string and
4352 * restart with just that char.
4353 * - If the user keeps pressing the same character, whether slowly or
4354 * fast, so that the search string is entirely composed of this
4355 * character ('aaaaa' for instance), then we search for first item
4356 * that starting with that character.
4357 * - If the user types the above character in quick succession, then
4358 * we must also search for the corresponding string ('aaaaa'), and
4359 * go to that string if there is a match.
4367 * - The current implementation has a list of characters it will
4368 * accept and it ignores averything else. In particular it will
4369 * ignore accentuated characters which seems to match what
4370 * Windows does. But I'm not sure it makes sense to follow
4372 * - We don't sound a beep when the search fails.
4373 * - The search should start from the focused item, not from the selected
4374 * item. One reason for this is to allow for multiple selections in trees.
4375 * But currently infoPtr->focusedItem does not seem very usable.
4379 * TREEVIEW_ProcessLetterKeys
4381 static INT
TREEVIEW_ProcessLetterKeys(
4382 HWND hwnd
, /* handle to the window */
4383 WPARAM charCode
, /* the character code, the actual character */
4384 LPARAM keyData
/* key data */
4387 TREEVIEW_INFO
*infoPtr
;
4389 HTREEITEM endidx
,idx
;
4391 WCHAR buffer
[MAX_PATH
];
4392 DWORD timestamp
,elapsed
;
4394 /* simple parameter checking */
4395 if (!hwnd
|| !charCode
|| !keyData
)
4398 infoPtr
=(TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
4402 /* only allow the valid WM_CHARs through */
4403 if (!isalnum(charCode
) &&
4404 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4405 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4406 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4407 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4408 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4409 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4410 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4411 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4412 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4415 /* compute how much time elapsed since last keypress */
4416 timestamp
= GetTickCount();
4417 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4418 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4420 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4423 /* update the search parameters */
4424 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4425 if (elapsed
< KEY_DELAY
) {
4426 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
) / sizeof(WCHAR
)) {
4427 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4429 if (infoPtr
->charCode
!= charCode
) {
4430 infoPtr
->charCode
=charCode
=0;
4433 infoPtr
->charCode
=charCode
;
4434 infoPtr
->szSearchParam
[0]=charCode
;
4435 infoPtr
->nSearchParamLength
=1;
4436 /* Redundant with the 1 char string */
4440 /* and search from the current position */
4442 if (infoPtr
->selectedItem
!= NULL
) {
4443 endidx
=infoPtr
->selectedItem
;
4444 /* if looking for single character match,
4445 * then we must always move forward
4447 if (infoPtr
->nSearchParamLength
== 1)
4448 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4453 idx
=infoPtr
->root
->firstChild
;
4456 /* At the end point, sort out wrapping */
4459 /* If endidx is null, stop at the last item (ie top to bottom) */
4463 /* Otherwise, start again at the very beginning */
4464 idx
=infoPtr
->root
->firstChild
;
4466 /* But if we are stopping on the first child, end now! */
4467 if (idx
== endidx
) break;
4471 ZeroMemory(&item
, sizeof(item
));
4472 item
.mask
= TVIF_TEXT
;
4474 item
.pszText
= buffer
;
4475 item
.cchTextMax
= sizeof(buffer
);
4476 TREEVIEW_GetItemT( infoPtr
, &item
, TRUE
);
4478 /* check for a match */
4479 if (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4482 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4483 (nItem
!= infoPtr
->selectedItem
) &&
4484 (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4485 /* This would work but we must keep looking for a longer match */
4488 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4489 } while (idx
!= endidx
);
4491 if (nItem
!= NULL
) {
4492 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4493 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4500 /* Scrolling ************************************************************/
4503 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4506 BOOL hasFirstVisible
= infoPtr
->firstVisible
!= NULL
;
4507 HTREEITEM newFirstVisible
= NULL
;
4508 int visible_pos
= -1;
4510 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4513 if (!ISVISIBLE(item
))
4515 /* Expand parents as necessary. */
4518 /* see if we are trying to ensure that root is vislble */
4519 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4520 parent
= item
->parent
;
4522 parent
= item
; /* this item is the topmost item */
4524 while (parent
!= infoPtr
->root
)
4526 if (!(parent
->state
& TVIS_EXPANDED
))
4527 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, FALSE
);
4529 parent
= parent
->parent
;
4533 viscount
= TREEVIEW_GetVisibleCount(infoPtr
);
4535 TRACE("%p (%s) %d - %d viscount(%d)\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4536 hasFirstVisible
? infoPtr
->firstVisible
->visibleOrder
: -1, viscount
);
4538 if (hasFirstVisible
)
4539 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4541 if (visible_pos
< 0)
4543 /* item is before the start of the list: put it at the top. */
4544 newFirstVisible
= item
;
4546 else if (visible_pos
>= viscount
4547 /* Sometimes, before we are displayed, GVC is 0, causing us to
4548 * spuriously scroll up. */
4549 && visible_pos
> 0 && !(infoPtr
->dwStyle
& TVS_NOSCROLL
) )
4551 /* item is past the end of the list. */
4552 int scroll
= visible_pos
- viscount
;
4554 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4560 /* Scroll window so item's text is visible as much as possible */
4561 /* Calculation of amount of extra space is taken from EditLabel code */
4563 TEXTMETRICW textMetric
;
4564 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4566 x
= item
->textWidth
;
4568 GetTextMetricsW(hdc
, &textMetric
);
4569 ReleaseDC(infoPtr
->hwnd
, hdc
);
4571 x
+= (textMetric
.tmMaxCharWidth
* 2);
4572 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4574 if (item
->textOffset
< 0)
4575 pos
= item
->textOffset
;
4576 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4578 if (x
> infoPtr
->clientWidth
)
4579 pos
= item
->textOffset
;
4581 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4586 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4589 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4591 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4600 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4601 TREEVIEW_ITEM
*newFirstVisible
,
4602 BOOL bUpdateScrollPos
)
4606 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4608 if (newFirstVisible
!= NULL
)
4610 /* Prevent an empty gap from appearing at the bottom... */
4611 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4612 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4616 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4619 /* ... unless we just don't have enough items. */
4620 if (newFirstVisible
== NULL
)
4621 newFirstVisible
= infoPtr
->root
->firstChild
;
4625 if (infoPtr
->firstVisible
!= newFirstVisible
)
4627 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4629 infoPtr
->firstVisible
= newFirstVisible
;
4630 TREEVIEW_Invalidate(infoPtr
, NULL
);
4634 TREEVIEW_ITEM
*item
;
4635 int scroll
= infoPtr
->uItemHeight
*
4636 (infoPtr
->firstVisible
->visibleOrder
4637 - newFirstVisible
->visibleOrder
);
4639 infoPtr
->firstVisible
= newFirstVisible
;
4641 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4642 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4644 item
->rect
.top
+= scroll
;
4645 item
->rect
.bottom
+= scroll
;
4648 if (bUpdateScrollPos
)
4649 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4650 newFirstVisible
->visibleOrder
, TRUE
);
4652 ScrollWindowEx(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
, NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
4657 /************************************************************************
4658 * VScroll is always in units of visible items. i.e. we always have a
4659 * visible item aligned to the top of the control. (Unless we have no
4663 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4665 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4666 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4668 int nScrollCode
= LOWORD(wParam
);
4670 TRACE("wp %lx\n", wParam
);
4672 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4675 if (!oldFirstVisible
)
4677 assert(infoPtr
->root
->firstChild
== NULL
);
4681 switch (nScrollCode
)
4684 newFirstVisible
= infoPtr
->root
->firstChild
;
4688 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4692 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4696 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4700 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4701 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4705 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4706 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4710 case SB_THUMBPOSITION
:
4711 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4712 infoPtr
->root
->firstChild
,
4713 (LONG
)(SHORT
)HIWORD(wParam
));
4720 if (newFirstVisible
!= NULL
)
4722 if (newFirstVisible
!= oldFirstVisible
)
4723 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4724 nScrollCode
!= SB_THUMBTRACK
);
4725 else if (nScrollCode
== SB_THUMBPOSITION
)
4726 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4727 newFirstVisible
->visibleOrder
, TRUE
);
4734 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4737 int scrollX
= infoPtr
->scrollX
;
4738 int nScrollCode
= LOWORD(wParam
);
4740 TRACE("wp %lx\n", wParam
);
4742 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4745 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4746 /* shall never occur */
4753 switch (nScrollCode
)
4756 scrollX
-= infoPtr
->uItemHeight
;
4759 scrollX
+= infoPtr
->uItemHeight
;
4762 scrollX
-= infoPtr
->clientWidth
;
4765 scrollX
+= infoPtr
->clientWidth
;
4769 case SB_THUMBPOSITION
:
4770 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4777 if (scrollX
> maxWidth
)
4779 else if (scrollX
< 0)
4783 if (scrollX
!= infoPtr
->scrollX
)
4785 TREEVIEW_ITEM
*item
;
4786 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4788 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4789 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4791 item
->linesOffset
+= scroll_pixels
;
4792 item
->stateOffset
+= scroll_pixels
;
4793 item
->imageOffset
+= scroll_pixels
;
4794 item
->textOffset
+= scroll_pixels
;
4797 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4798 infoPtr
->scrollX
= scrollX
;
4799 UpdateWindow(infoPtr
->hwnd
);
4802 if (nScrollCode
!= SB_THUMBTRACK
)
4803 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
4809 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4812 UINT pulScrollLines
= 3;
4814 if (infoPtr
->firstVisible
== NULL
)
4817 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
4819 gcWheelDelta
= -(short)HIWORD(wParam
);
4820 pulScrollLines
*= (gcWheelDelta
/ WHEEL_DELTA
);
4822 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
4824 int newDy
= infoPtr
->firstVisible
->visibleOrder
+ pulScrollLines
;
4825 int maxDy
= infoPtr
->maxVisibleOrder
;
4833 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
4838 /* Create/Destroy *******************************************************/
4841 initialize_checkboxes(TREEVIEW_INFO
*infoPtr
)
4844 HBITMAP hbm
, hbmOld
;
4848 infoPtr
->himlState
= ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
4850 hdcScreen
= GetDC(0);
4852 hdc
= CreateCompatibleDC(hdcScreen
);
4853 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
4854 hbmOld
= SelectObject(hdc
, hbm
);
4856 SetRect(&rc
, 0, 0, 48, 16);
4857 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
4859 SetRect(&rc
, 18, 2, 30, 14);
4860 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4861 DFCS_BUTTONCHECK
|DFCS_FLAT
);
4863 SetRect(&rc
, 34, 2, 46, 14);
4864 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4865 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
4867 SelectObject(hdc
, hbmOld
);
4868 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
4869 GetSysColor(COLOR_WINDOW
));
4870 TRACE("checkbox index %d\n", nIndex
);
4874 ReleaseDC(0, hdcScreen
);
4876 infoPtr
->stateImageWidth
= 16;
4877 infoPtr
->stateImageHeight
= 16;
4881 TREEVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
4884 TREEVIEW_INFO
*infoPtr
;
4887 TRACE("wnd %p, style %x\n", hwnd
, GetWindowLongW(hwnd
, GWL_STYLE
));
4889 infoPtr
= (TREEVIEW_INFO
*)Alloc(sizeof(TREEVIEW_INFO
));
4891 if (infoPtr
== NULL
)
4893 ERR("could not allocate info memory!\n");
4897 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
4899 infoPtr
->hwnd
= hwnd
;
4900 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
4902 infoPtr
->uNumItems
= 0;
4903 infoPtr
->cdmode
= 0;
4904 infoPtr
->uScrollTime
= 300; /* milliseconds */
4905 infoPtr
->bRedraw
= TRUE
;
4907 GetClientRect(hwnd
, &rcClient
);
4909 /* No scroll bars yet. */
4910 infoPtr
->clientWidth
= rcClient
.right
;
4911 infoPtr
->clientHeight
= rcClient
.bottom
;
4912 infoPtr
->uInternalStatus
= 0;
4914 infoPtr
->treeWidth
= 0;
4915 infoPtr
->treeHeight
= 0;
4917 infoPtr
->uIndent
= MINIMUM_INDENT
;
4918 infoPtr
->selectedItem
= 0;
4919 infoPtr
->focusedItem
= 0;
4920 infoPtr
->hotItem
= 0;
4921 infoPtr
->firstVisible
= 0;
4922 infoPtr
->maxVisibleOrder
= 0;
4923 infoPtr
->dropItem
= 0;
4924 infoPtr
->insertMarkItem
= 0;
4925 infoPtr
->insertBeforeorAfter
= 0;
4928 infoPtr
->scrollX
= 0;
4930 infoPtr
->clrBk
= GetSysColor(COLOR_WINDOW
);
4931 infoPtr
->clrText
= -1; /* use system color */
4932 infoPtr
->clrLine
= RGB(128, 128, 128);
4933 infoPtr
->clrInsertMark
= GetSysColor(COLOR_BTNTEXT
);
4937 infoPtr
->hwndEdit
= 0;
4938 infoPtr
->wpEditOrig
= NULL
;
4939 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
4940 infoPtr
->bLabelChanged
= FALSE
;
4942 infoPtr
->himlNormal
= NULL
;
4943 infoPtr
->himlState
= NULL
;
4944 infoPtr
->normalImageWidth
= 0;
4945 infoPtr
->normalImageHeight
= 0;
4946 infoPtr
->stateImageWidth
= 0;
4947 infoPtr
->stateImageHeight
= 0;
4949 infoPtr
->items
= DPA_Create(16);
4951 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
4952 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW(&lf
);
4953 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
4954 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
4955 infoPtr
->hcurHand
= LoadCursorW(NULL
, (LPWSTR
)IDC_HAND
);
4957 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
4959 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
4960 infoPtr
->root
->state
= TVIS_EXPANDED
;
4961 infoPtr
->root
->iLevel
= -1;
4962 infoPtr
->root
->visibleOrder
= -1;
4964 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
4966 infoPtr
->bTransparent
= ( GetWindowLongW( hwnd
, GWL_STYLE
) & TBSTYLE_FLAT
);
4969 infoPtr
->hwndToolTip
= 0;
4971 infoPtr
->bNtfUnicode
= IsWindowUnicode (hwnd
);
4973 /* Determine what type of notify should be issued */
4974 /* sets infoPtr->bNtfUnicode */
4975 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
4977 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
4978 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
4979 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
4982 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4983 initialize_checkboxes(infoPtr
);
4985 /* Make sure actual scrollbar state is consistent with uInternalStatus */
4986 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
4987 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
4989 OpenThemeData (hwnd
, themeClass
);
4996 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
5000 TREEVIEW_RemoveTree(infoPtr
);
5002 /* tool tip is automatically destroyed: we are its owner */
5004 /* Restore original wndproc */
5005 if (infoPtr
->hwndEdit
)
5006 SetWindowLongPtrW(infoPtr
->hwndEdit
, GWLP_WNDPROC
,
5007 (DWORD_PTR
)infoPtr
->wpEditOrig
);
5009 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
5011 /* Deassociate treeview from the window before doing anything drastic. */
5012 SetWindowLongPtrW(infoPtr
->hwnd
, 0, (DWORD_PTR
)NULL
);
5015 DeleteObject(infoPtr
->hDefaultFont
);
5016 DeleteObject(infoPtr
->hBoldFont
);
5017 DeleteObject(infoPtr
->hUnderlineFont
);
5023 /* Miscellaneous Messages ***********************************************/
5026 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
5034 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
5035 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
5036 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
5037 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
5038 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
5039 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
5040 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
5041 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
5042 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
5046 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
5048 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
5050 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
5052 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
5058 /************************************************************************
5061 * VK_UP Move selection to the previous non-hidden item.
5062 * VK_DOWN Move selection to the next non-hidden item.
5063 * VK_HOME Move selection to the first item.
5064 * VK_END Move selection to the last item.
5065 * VK_LEFT If expanded then collapse, otherwise move to parent.
5066 * VK_RIGHT If collapsed then expand, otherwise move to first child.
5068 * VK_SUBTRACT Collapse.
5069 * VK_MULTIPLY Expand all.
5070 * VK_PRIOR Move up GetVisibleCount items.
5071 * VK_NEXT Move down GetVisibleCount items.
5072 * VK_BACK Move to parent.
5073 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
5076 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
5078 /* If it is non-NULL and different, it will be selected and visible. */
5079 TREEVIEW_ITEM
*newSelection
= NULL
;
5081 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
5083 TRACE("%lx\n", wParam
);
5085 if (prevItem
== NULL
)
5088 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
5089 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
5094 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
5096 newSelection
= infoPtr
->root
->firstChild
;
5100 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
5104 newSelection
= infoPtr
->root
->firstChild
;
5108 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
5112 if (prevItem
->state
& TVIS_EXPANDED
)
5114 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5116 else if (prevItem
->parent
!= infoPtr
->root
)
5118 newSelection
= prevItem
->parent
;
5123 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
5125 if (!(prevItem
->state
& TVIS_EXPANDED
))
5126 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5129 newSelection
= prevItem
->firstChild
;
5136 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5140 if (!(prevItem
->state
& TVIS_EXPANDED
))
5141 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5145 if (prevItem
->state
& TVIS_EXPANDED
)
5146 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5151 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5152 -TREEVIEW_GetVisibleCount(infoPtr
));
5157 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5158 TREEVIEW_GetVisibleCount(infoPtr
));
5162 newSelection
= prevItem
->parent
;
5163 if (newSelection
== infoPtr
->root
)
5164 newSelection
= NULL
;
5168 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5169 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5173 if (newSelection
&& newSelection
!= prevItem
)
5175 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5178 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5186 TREEVIEW_MouseLeave (TREEVIEW_INFO
* infoPtr
)
5188 if (infoPtr
->hotItem
)
5190 /* remove hot effect from item */
5191 InvalidateRect(infoPtr
->hwnd
, &infoPtr
->hotItem
->rect
, TRUE
);
5192 infoPtr
->hotItem
= NULL
;
5198 TREEVIEW_MouseMove (TREEVIEW_INFO
* infoPtr
, WPARAM wParam
, LPARAM lParam
)
5201 TRACKMOUSEEVENT trackinfo
;
5202 TREEVIEW_ITEM
* item
;
5204 /* fill in the TRACKMOUSEEVENT struct */
5205 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5206 trackinfo
.dwFlags
= TME_QUERY
;
5207 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5208 trackinfo
.dwHoverTime
= HOVER_DEFAULT
;
5210 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5211 _TrackMouseEvent(&trackinfo
);
5213 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5214 if(!(trackinfo
.dwFlags
& TME_LEAVE
))
5216 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5218 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5219 /* and can properly deactivate the hot item */
5220 _TrackMouseEvent(&trackinfo
);
5223 pt
.x
= (short)LOWORD(lParam
);
5224 pt
.y
= (short)HIWORD(lParam
);
5226 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5228 if (item
!= infoPtr
->hotItem
)
5230 /* redraw old hot item */
5231 if (infoPtr
->hotItem
)
5232 InvalidateRect(infoPtr
->hwnd
, &infoPtr
->hotItem
->rect
, TRUE
);
5233 infoPtr
->hotItem
= item
;
5234 /* redraw new hot item */
5235 if (infoPtr
->hotItem
)
5236 InvalidateRect(infoPtr
->hwnd
, &infoPtr
->hotItem
->rect
, TRUE
);
5242 /* Draw themed border */
5243 static BOOL
nc_paint (const TREEVIEW_INFO
*infoPtr
, HRGN region
)
5245 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5249 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
5250 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
5252 if (!theme
) return FALSE
;
5254 GetWindowRect(infoPtr
->hwnd
, &r
);
5256 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
5257 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
5258 if (region
!= (HRGN
)1)
5259 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
5260 OffsetRect(&r
, -r
.left
, -r
.top
);
5262 dc
= GetDCEx(infoPtr
->hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
5263 OffsetRect(&r
, -r
.left
, -r
.top
);
5265 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
5266 DrawThemeParentBackground(infoPtr
->hwnd
, dc
, &r
);
5267 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
5268 ReleaseDC(infoPtr
->hwnd
, dc
);
5270 /* Call default proc to get the scrollbars etc. painted */
5271 DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
5277 TREEVIEW_Notify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5279 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5281 if (lpnmh
->code
== PGN_CALCSIZE
) {
5282 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5284 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5285 lppgc
->iWidth
= infoPtr
->treeWidth
;
5286 TRACE("got PGN_CALCSIZE, returning horz size = %d, client=%d\n",
5287 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5290 lppgc
->iHeight
= infoPtr
->treeHeight
;
5291 TRACE("got PGN_CALCSIZE, returning vert size = %d, client=%d\n",
5292 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5296 return DefWindowProcW(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5299 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
5303 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
5305 if (nCommand
!= NF_REQUERY
) return 0;
5307 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
5308 TRACE("format=%d\n", format
);
5310 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
) return 0;
5312 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
5318 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5320 if (wParam
== SIZE_RESTORED
)
5322 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5323 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5325 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5326 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5327 TREEVIEW_UpdateScrollBars(infoPtr
);
5331 FIXME("WM_SIZE flag %lx %lx not handled\n", wParam
, lParam
);
5334 TREEVIEW_Invalidate(infoPtr
, NULL
);
5339 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5341 TRACE("(%lx %lx)\n", wParam
, lParam
);
5343 if (wParam
== GWL_STYLE
)
5345 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5347 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_CHECKBOXES
)
5349 if (dwNewStyle
& TVS_CHECKBOXES
)
5351 initialize_checkboxes(infoPtr
);
5352 TRACE("checkboxes enabled\n");
5356 FIXME("tried to disable checkboxes\n");
5360 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5362 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5364 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5365 TRACE("tooltips enabled\n");
5369 DestroyWindow(infoPtr
->hwndToolTip
);
5370 infoPtr
->hwndToolTip
= 0;
5371 TRACE("tooltips disabled\n");
5375 infoPtr
->dwStyle
= dwNewStyle
;
5378 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5379 TREEVIEW_UpdateScrollBars(infoPtr
);
5380 TREEVIEW_Invalidate(infoPtr
, NULL
);
5386 TREEVIEW_SetCursor(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5389 TREEVIEW_ITEM
* item
;
5392 ScreenToClient(infoPtr
->hwnd
, &pt
);
5394 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5396 /* FIXME: send NM_SETCURSOR */
5398 if (item
&& (infoPtr
->dwStyle
& TVS_TRACKSELECT
))
5400 SetCursor(infoPtr
->hcurHand
);
5404 return DefWindowProcW(infoPtr
->hwnd
, WM_SETCURSOR
, wParam
, lParam
);
5408 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5412 if (!infoPtr
->selectedItem
)
5414 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5418 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5419 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5424 TREEVIEW_KillFocus(const TREEVIEW_INFO
*infoPtr
)
5428 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5429 UpdateWindow(infoPtr
->hwnd
);
5430 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5434 /* update theme after a WM_THEMECHANGED message */
5435 static LRESULT
theme_changed(const TREEVIEW_INFO
*infoPtr
)
5437 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5438 CloseThemeData (theme
);
5439 OpenThemeData (infoPtr
->hwnd
, themeClass
);
5444 static LRESULT WINAPI
5445 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5447 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5449 TRACE("hwnd %p msg %04x wp=%08lx lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5451 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5454 if (uMsg
== WM_CREATE
)
5455 TREEVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
5462 case TVM_CREATEDRAGIMAGE
:
5463 return TREEVIEW_CreateDragImage(infoPtr
, wParam
, lParam
);
5465 case TVM_DELETEITEM
:
5466 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5468 case TVM_EDITLABELA
:
5469 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5471 case TVM_EDITLABELW
:
5472 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5474 case TVM_ENDEDITLABELNOW
:
5475 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5477 case TVM_ENSUREVISIBLE
:
5478 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5481 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5483 case TVM_GETBKCOLOR
:
5484 return TREEVIEW_GetBkColor(infoPtr
);
5487 return TREEVIEW_GetCount(infoPtr
);
5489 case TVM_GETEDITCONTROL
:
5490 return TREEVIEW_GetEditControl(infoPtr
);
5492 case TVM_GETIMAGELIST
:
5493 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5496 return TREEVIEW_GetIndent(infoPtr
);
5498 case TVM_GETINSERTMARKCOLOR
:
5499 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5501 case TVM_GETISEARCHSTRINGA
:
5502 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5505 case TVM_GETISEARCHSTRINGW
:
5506 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5510 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
, FALSE
);
5513 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
, TRUE
);
5515 case TVM_GETITEMHEIGHT
:
5516 return TREEVIEW_GetItemHeight(infoPtr
);
5518 case TVM_GETITEMRECT
:
5519 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5521 case TVM_GETITEMSTATE
:
5522 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5524 case TVM_GETLINECOLOR
:
5525 return TREEVIEW_GetLineColor(infoPtr
);
5527 case TVM_GETNEXTITEM
:
5528 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5530 case TVM_GETSCROLLTIME
:
5531 return TREEVIEW_GetScrollTime(infoPtr
);
5533 case TVM_GETTEXTCOLOR
:
5534 return TREEVIEW_GetTextColor(infoPtr
);
5536 case TVM_GETTOOLTIPS
:
5537 return TREEVIEW_GetToolTips(infoPtr
);
5539 case TVM_GETUNICODEFORMAT
:
5540 return TREEVIEW_GetUnicodeFormat(infoPtr
);
5542 case TVM_GETVISIBLECOUNT
:
5543 return TREEVIEW_GetVisibleCount(infoPtr
);
5546 return TREEVIEW_HitTest(infoPtr
, (LPTVHITTESTINFO
)lParam
);
5548 case TVM_INSERTITEMA
:
5549 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
, FALSE
);
5551 case TVM_INSERTITEMW
:
5552 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
, TRUE
);
5554 case TVM_SELECTITEM
:
5555 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5557 case TVM_SETBKCOLOR
:
5558 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5560 case TVM_SETIMAGELIST
:
5561 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5564 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5566 case TVM_SETINSERTMARK
:
5567 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5569 case TVM_SETINSERTMARKCOLOR
:
5570 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5573 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
, FALSE
);
5576 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
, TRUE
);
5578 case TVM_SETLINECOLOR
:
5579 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5581 case TVM_SETITEMHEIGHT
:
5582 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5584 case TVM_SETSCROLLTIME
:
5585 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5587 case TVM_SETTEXTCOLOR
:
5588 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5590 case TVM_SETTOOLTIPS
:
5591 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5593 case TVM_SETUNICODEFORMAT
:
5594 return TREEVIEW_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
5596 case TVM_SORTCHILDREN
:
5597 return TREEVIEW_SortChildren(infoPtr
, wParam
, lParam
);
5599 case TVM_SORTCHILDRENCB
:
5600 return TREEVIEW_SortChildrenCB(infoPtr
, wParam
, (LPTVSORTCB
)lParam
);
5603 return TREEVIEW_ProcessLetterKeys( hwnd
, wParam
, lParam
);
5606 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5609 return TREEVIEW_Destroy(infoPtr
);
5614 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5617 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5620 return TREEVIEW_GetFont(infoPtr
);
5623 return TREEVIEW_HScroll(infoPtr
, wParam
);
5626 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5629 return TREEVIEW_KillFocus(infoPtr
);
5631 case WM_LBUTTONDBLCLK
:
5632 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5634 case WM_LBUTTONDOWN
:
5635 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5637 /* WM_MBUTTONDOWN */
5640 return TREEVIEW_MouseLeave(infoPtr
);
5643 if (infoPtr
->dwStyle
& TVS_TRACKSELECT
)
5644 return TREEVIEW_MouseMove(infoPtr
, wParam
, lParam
);
5648 case WM_NCLBUTTONDOWN
:
5649 if (infoPtr
->hwndEdit
)
5650 SetFocus(infoPtr
->hwnd
);
5654 if (nc_paint (infoPtr
, (HRGN
)wParam
))
5659 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5661 case WM_NOTIFYFORMAT
:
5662 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5664 case WM_PRINTCLIENT
:
5666 return TREEVIEW_Paint(infoPtr
, wParam
);
5668 case WM_RBUTTONDOWN
:
5669 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5672 return TREEVIEW_SetCursor(infoPtr
, wParam
, lParam
);
5675 return TREEVIEW_SetFocus(infoPtr
);
5678 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5681 return TREEVIEW_SetRedraw(infoPtr
, wParam
, lParam
);
5684 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5686 case WM_STYLECHANGED
:
5687 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5689 /* WM_SYSCOLORCHANGE */
5694 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5696 case WM_THEMECHANGED
:
5697 return theme_changed (infoPtr
);
5700 return TREEVIEW_VScroll(infoPtr
, wParam
);
5702 /* WM_WININICHANGE */
5705 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
5707 return TREEVIEW_MouseWheel(infoPtr
, wParam
);
5710 TRACE("drawItem\n");
5714 /* This mostly catches MFC and Delphi messages. :( */
5715 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
5716 TRACE("Unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
5718 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
5723 /* Class Registration ***************************************************/
5726 TREEVIEW_Register(void)
5732 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
5733 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5734 wndClass
.lpfnWndProc
= TREEVIEW_WindowProc
;
5735 wndClass
.cbClsExtra
= 0;
5736 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5738 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
5739 wndClass
.hbrBackground
= 0;
5740 wndClass
.lpszClassName
= WC_TREEVIEWW
;
5742 RegisterClassW(&wndClass
);
5747 TREEVIEW_Unregister(void)
5749 UnregisterClassW(WC_TREEVIEWW
, NULL
);
5753 /* Tree Verification ****************************************************/
5757 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
5759 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5760 TREEVIEW_ITEM
*item
)
5762 assert(infoPtr
!= NULL
);
5763 assert(item
!= NULL
);
5765 /* both NULL, or both non-null */
5766 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5768 assert(item
->firstChild
!= item
);
5769 assert(item
->lastChild
!= item
);
5771 if (item
->firstChild
)
5773 assert(item
->firstChild
->parent
== item
);
5774 assert(item
->firstChild
->prevSibling
== NULL
);
5777 if (item
->lastChild
)
5779 assert(item
->lastChild
->parent
== item
);
5780 assert(item
->lastChild
->nextSibling
== NULL
);
5783 assert(item
->nextSibling
!= item
);
5784 if (item
->nextSibling
)
5786 assert(item
->nextSibling
->parent
== item
->parent
);
5787 assert(item
->nextSibling
->prevSibling
== item
);
5790 assert(item
->prevSibling
!= item
);
5791 if (item
->prevSibling
)
5793 assert(item
->prevSibling
->parent
== item
->parent
);
5794 assert(item
->prevSibling
->nextSibling
== item
);
5799 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
5801 assert(item
!= NULL
);
5803 assert(item
->parent
!= NULL
);
5804 assert(item
->parent
!= item
);
5805 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5807 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5809 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5811 TREEVIEW_VerifyChildren(infoPtr
, item
);
5815 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
5817 TREEVIEW_ITEM
*child
;
5818 assert(item
!= NULL
);
5820 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5821 TREEVIEW_VerifyItem(infoPtr
, child
);
5825 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5827 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5829 assert(root
!= NULL
);
5830 assert(root
->iLevel
== -1);
5831 assert(root
->parent
== NULL
);
5832 assert(root
->prevSibling
== NULL
);
5834 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
5836 TREEVIEW_VerifyChildren(infoPtr
, root
);
5840 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
5842 assert(infoPtr
!= NULL
);
5844 TREEVIEW_VerifyRoot(infoPtr
);