3 * Copyright 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de>
4 * Copyright 1998,1999 Alex Priem <alexp@sci.kun.nl>
5 * Copyright 1999 Sylvain St-Germain
6 * Copyright 2002 CodeWeavers, Aric Stewart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * Note that TREEVIEW_INFO * and HTREEITEM are the same thing.
26 * Note2: If item's text == LPSTR_TEXTCALLBACKA we allocate buffer
27 * of size TEXT_CALLBACK_SIZE in DoSetItem.
28 * We use callbackMask to keep track of fields to be updated.
31 * missing notifications: TVN_GETINFOTIP, TVN_KEYDOWN,
32 * TVN_SETDISPINFO, TVN_SINGLEEXPAND
34 * missing styles: TVS_FULLROWSELECT, TVS_INFOTIP, TVS_RTLREADING,
36 * missing item styles: TVIS_CUT, TVIS_EXPANDPARTIAL
38 * Make the insertion mark look right.
39 * Scroll (instead of repaint) as much as possible.
43 #include "wine/port.h"
52 #define NONAMELESSUNION
53 #define NONAMELESSSTRUCT
63 #include "wine/unicode.h"
64 #include "wine/debug.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(treeview
);
68 /* internal structures */
70 typedef struct _TREEITEM
/* HTREEITEM is a _TREEINFO *. */
81 int iIntegral
; /* item height multiplier (1 is normal) */
82 int iLevel
; /* indentation level:0=root level */
83 HTREEITEM parent
; /* handle to parent or 0 if at root */
84 HTREEITEM firstChild
; /* handle to first child or 0 if no child */
86 HTREEITEM prevSibling
; /* handle to prev item in list, 0 if first */
87 HTREEITEM nextSibling
; /* handle to next item in list, 0 if last */
93 LONG textWidth
; /* horizontal text extent for pszText */
94 LONG visibleOrder
; /* visible ordering, 0 is first visible item */
98 typedef struct tagTREEVIEW_INFO
101 HWND hwndNotify
; /* Owner window to send notifications to */
104 UINT uInternalStatus
;
106 UINT uNumItems
; /* number of valid TREEVIEW_ITEMs */
107 INT cdmode
; /* last custom draw setting */
108 UINT uScrollTime
; /* max. time for scrolling in milliseconds */
109 BOOL bRedraw
; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
111 UINT uItemHeight
; /* item height */
114 LONG clientWidth
; /* width of control window */
115 LONG clientHeight
; /* height of control window */
117 LONG treeWidth
; /* width of visible tree items */
118 LONG treeHeight
; /* height of visible tree items */
120 UINT uIndent
; /* indentation in pixels */
121 HTREEITEM selectedItem
; /* handle to selected item or 0 if none */
122 HTREEITEM hotItem
; /* handle currently under cursor, 0 if none */
123 HTREEITEM focusedItem
; /* item that was under the cursor when WM_LBUTTONDOWN was received */
124 HTREEITEM editItem
; /* item being edited with builtin edit box */
126 HTREEITEM firstVisible
; /* handle to first visible item */
127 LONG maxVisibleOrder
;
128 HTREEITEM dropItem
; /* handle to item selected by drag cursor */
129 HTREEITEM insertMarkItem
; /* item after which insertion mark is placed */
130 BOOL insertBeforeorAfter
; /* flag used by TVM_SETINSERTMARK */
131 HIMAGELIST dragList
; /* Bitmap of dragged item */
136 COLORREF clrInsertMark
;
140 HFONT hUnderlineFont
;
145 WNDPROC wpEditOrig
; /* orig window proc for subclassing edit */
146 BOOL bIgnoreEditKillFocus
;
149 BOOL bNtfUnicode
; /* TRUE if should send NOTIFY with W */
150 HIMAGELIST himlNormal
;
151 int normalImageHeight
;
152 int normalImageWidth
;
153 HIMAGELIST himlState
;
154 int stateImageHeight
;
158 DWORD lastKeyPressTimestamp
;
160 INT nSearchParamLength
;
161 WCHAR szSearchParam
[ MAX_PATH
];
165 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
166 #define KEY_DELAY 450
168 /* bitflags for infoPtr->uInternalStatus */
170 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
171 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
172 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
173 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
174 #define TV_RDRAG 0x10 /* ditto Rbutton */
175 #define TV_RDRAGGING 0x20
177 /* bitflags for infoPtr->timer */
179 #define TV_EDIT_TIMER 2
180 #define TV_EDIT_TIMER_SET 2
182 #define TEXT_CALLBACK_SIZE 260
184 #define TREEVIEW_LEFT_MARGIN 8
186 #define MINIMUM_INDENT 19
188 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
190 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
191 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
192 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
194 #define GETLINECOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrGrayText : (x))
195 #define GETBKCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindow : (x))
196 #define GETTXTCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindowText : (x))
197 #define GETINSCOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrBtnText : (x))
199 static const WCHAR themeClass
[] = { 'T','r','e','e','v','i','e','w',0 };
202 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
205 static VOID
TREEVIEW_Invalidate(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
207 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
208 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
209 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
210 static LRESULT
TREEVIEW_RButtonUp(const TREEVIEW_INFO
*, const POINT
*);
211 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
212 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
213 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
215 /* Random Utilities *****************************************************/
219 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
224 /* The definition is at the end of the file. */
225 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
228 /* Returns the treeview private data if hwnd is a treeview.
229 * Otherwise returns an undefined value. */
230 static TREEVIEW_INFO
*
231 TREEVIEW_GetInfoPtr(HWND hwnd
)
233 return (TREEVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
236 /* Don't call this. Nothing wants an item index. */
238 TREEVIEW_GetItemIndex(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
240 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
243 /* Checks if item has changed and needs to be redrawn */
244 static inline BOOL
item_changed (const TREEVIEW_ITEM
*tiOld
, const TREEVIEW_ITEM
*tiNew
,
245 const TVITEMEXW
*tvChange
)
247 /* Number of children has changed */
248 if ((tvChange
->mask
& TVIF_CHILDREN
) && (tiOld
->cChildren
!= tiNew
->cChildren
))
251 /* Image has changed and it's not a callback */
252 if ((tvChange
->mask
& TVIF_IMAGE
) && (tiOld
->iImage
!= tiNew
->iImage
) &&
253 tiNew
->iImage
!= I_IMAGECALLBACK
)
256 /* Selected image has changed and it's not a callback */
257 if ((tvChange
->mask
& TVIF_SELECTEDIMAGE
) && (tiOld
->iSelectedImage
!= tiNew
->iSelectedImage
) &&
258 tiNew
->iSelectedImage
!= I_IMAGECALLBACK
)
261 /* Text has changed and it's not a callback */
262 if ((tvChange
->mask
& TVIF_TEXT
) && (tiOld
->pszText
!= tiNew
->pszText
) &&
263 tiNew
->pszText
!= LPSTR_TEXTCALLBACKW
)
266 /* Indent has changed */
267 if ((tvChange
->mask
& TVIF_INTEGRAL
) && (tiOld
->iIntegral
!= tiNew
->iIntegral
))
270 /* Item state has changed */
271 if ((tvChange
->mask
& TVIF_STATE
) && ((tiOld
->state
^ tiNew
->state
) & tvChange
->stateMask
))
277 /***************************************************************************
278 * This method checks that handle is an item for this tree.
281 TREEVIEW_ValidItem(const TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
283 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
285 TRACE("invalid item %p\n", handle
);
293 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
297 GetObjectW(hOrigFont
, sizeof(font
), &font
);
298 font
.lfWeight
= FW_BOLD
;
299 return CreateFontIndirectW(&font
);
303 TREEVIEW_CreateUnderlineFont(HFONT hOrigFont
)
307 GetObjectW(hOrigFont
, sizeof(font
), &font
);
308 font
.lfUnderline
= TRUE
;
309 return CreateFontIndirectW(&font
);
313 TREEVIEW_FontForItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
315 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (item
== infoPtr
->hotItem
))
316 return infoPtr
->hUnderlineFont
;
317 if (item
->state
& TVIS_BOLD
)
318 return infoPtr
->hBoldFont
;
319 return infoPtr
->hFont
;
322 /* for trace/debugging purposes only */
324 TREEVIEW_ItemName(const TREEVIEW_ITEM
*item
)
326 if (item
== NULL
) return "<null item>";
327 if (item
->pszText
== LPSTR_TEXTCALLBACKW
) return "<callback>";
328 if (item
->pszText
== NULL
) return "<null>";
329 return debugstr_w(item
->pszText
);
332 /* An item is not a child of itself. */
334 TREEVIEW_IsChildOf(const TREEVIEW_ITEM
*parent
, const TREEVIEW_ITEM
*child
)
338 child
= child
->parent
;
339 if (child
== parent
) return TRUE
;
340 } while (child
!= NULL
);
346 /* Tree Traversal *******************************************************/
348 /***************************************************************************
349 * This method returns the last expanded sibling or child child item
352 static TREEVIEW_ITEM
*
353 TREEVIEW_GetLastListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
358 while (wineItem
->lastChild
)
360 if (wineItem
->state
& TVIS_EXPANDED
)
361 wineItem
= wineItem
->lastChild
;
366 if (wineItem
== infoPtr
->root
)
372 /***************************************************************************
373 * This method returns the previous non-hidden item in the list not
374 * considering the tree hierarchy.
376 static TREEVIEW_ITEM
*
377 TREEVIEW_GetPrevListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
379 if (tvItem
->prevSibling
)
381 /* This item has a prevSibling, get the last item in the sibling's tree. */
382 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
384 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
385 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
391 /* this item does not have a prevSibling, get the parent */
392 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
397 /***************************************************************************
398 * This method returns the next physical item in the treeview not
399 * considering the tree hierarchy.
401 static TREEVIEW_ITEM
*
402 TREEVIEW_GetNextListItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*tvItem
)
405 * If this item has children and is expanded, return the first child
407 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
409 return tvItem
->firstChild
;
414 * try to get the sibling
416 if (tvItem
->nextSibling
)
417 return tvItem
->nextSibling
;
420 * Otherwise, get the parent's sibling.
422 while (tvItem
->parent
)
424 tvItem
= tvItem
->parent
;
426 if (tvItem
->nextSibling
)
427 return tvItem
->nextSibling
;
433 /***************************************************************************
434 * This method returns the nth item starting at the given item. It returns
435 * the last item (or first) we we run out of items.
437 * Will scroll backward if count is <0.
438 * forward if count is >0.
440 static TREEVIEW_ITEM
*
441 TREEVIEW_GetListItem(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
444 TREEVIEW_ITEM
*(*next_item
)(const TREEVIEW_INFO
*, const TREEVIEW_ITEM
*);
445 TREEVIEW_ITEM
*previousItem
;
447 assert(wineItem
!= NULL
);
451 next_item
= TREEVIEW_GetNextListItem
;
456 next_item
= TREEVIEW_GetPrevListItem
;
463 previousItem
= wineItem
;
464 wineItem
= next_item(infoPtr
, wineItem
);
466 } while (--count
&& wineItem
!= NULL
);
469 return wineItem
? wineItem
: previousItem
;
472 /* Notifications ************************************************************/
474 static INT
get_notifycode(const TREEVIEW_INFO
*infoPtr
, INT code
)
476 if (!infoPtr
->bNtfUnicode
) {
478 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
479 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
480 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
481 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
482 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
483 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
484 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
485 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
486 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
487 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
488 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
489 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
496 TREEVIEW_SendRealNotify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
498 TRACE("wParam=%ld, lParam=%ld\n", wParam
, lParam
);
499 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, wParam
, lParam
);
503 TREEVIEW_SendSimpleNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
)
506 HWND hwnd
= infoPtr
->hwnd
;
509 nmhdr
.hwndFrom
= hwnd
;
510 nmhdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
511 nmhdr
.code
= get_notifycode(infoPtr
, code
);
513 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
517 TREEVIEW_TVItemFromItem(const TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMW
*tvItem
, TREEVIEW_ITEM
*item
)
520 tvItem
->hItem
= item
;
521 tvItem
->state
= item
->state
;
522 tvItem
->stateMask
= 0;
523 tvItem
->iImage
= item
->iImage
;
524 tvItem
->iSelectedImage
= item
->iSelectedImage
;
525 tvItem
->cChildren
= item
->cChildren
;
526 tvItem
->lParam
= item
->lParam
;
530 if (!infoPtr
->bNtfUnicode
)
532 tvItem
->cchTextMax
= WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0, NULL
, NULL
);
533 tvItem
->pszText
= Alloc (tvItem
->cchTextMax
);
534 WideCharToMultiByte( CP_ACP
, 0, item
->pszText
, -1, (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, 0, 0 );
538 tvItem
->cchTextMax
= item
->cchTextMax
;
539 tvItem
->pszText
= item
->pszText
;
544 tvItem
->cchTextMax
= 0;
545 tvItem
->pszText
= NULL
;
550 TREEVIEW_SendTreeviewNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
551 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
553 HWND hwnd
= infoPtr
->hwnd
;
557 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
558 code
, action
, oldItem
, newItem
);
560 ZeroMemory(&nmhdr
, sizeof(NMTREEVIEWW
));
562 nmhdr
.hdr
.hwndFrom
= hwnd
;
563 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
564 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
565 nmhdr
.action
= action
;
568 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
571 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
576 ret
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.hdr
.idFrom
, (LPARAM
)&nmhdr
);
577 if (!infoPtr
->bNtfUnicode
)
579 Free(nmhdr
.itemOld
.pszText
);
580 Free(nmhdr
.itemNew
.pszText
);
586 TREEVIEW_SendTreeviewDnDNotify(const TREEVIEW_INFO
*infoPtr
, UINT code
,
587 HTREEITEM dragItem
, POINT pt
)
589 HWND hwnd
= infoPtr
->hwnd
;
592 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
594 nmhdr
.hdr
.hwndFrom
= hwnd
;
595 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
596 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
598 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
599 nmhdr
.itemNew
.hItem
= dragItem
;
600 nmhdr
.itemNew
.state
= dragItem
->state
;
601 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
603 nmhdr
.ptDrag
.x
= pt
.x
;
604 nmhdr
.ptDrag
.y
= pt
.y
;
606 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, nmhdr
.hdr
.idFrom
, (LPARAM
)&nmhdr
);
611 TREEVIEW_SendCustomDrawNotify(const TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
614 HWND hwnd
= infoPtr
->hwnd
;
615 NMTVCUSTOMDRAW nmcdhdr
;
618 TRACE("drawstage:%x hdc:%p\n", dwDrawStage
, hdc
);
620 nmcd
= &nmcdhdr
.nmcd
;
621 nmcd
->hdr
.hwndFrom
= hwnd
;
622 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
623 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
624 nmcd
->dwDrawStage
= dwDrawStage
;
627 nmcd
->dwItemSpec
= 0;
628 nmcd
->uItemState
= 0;
629 nmcd
->lItemlParam
= 0;
630 nmcdhdr
.clrText
= infoPtr
->clrText
;
631 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
634 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, nmcd
->hdr
.idFrom
, (LPARAM
)&nmcdhdr
);
639 /* FIXME: need to find out when the flags in uItemState need to be set */
642 TREEVIEW_SendCustomDrawItemNotify(const TREEVIEW_INFO
*infoPtr
, HDC hdc
,
643 TREEVIEW_ITEM
*wineItem
, UINT uItemDrawState
,
644 NMTVCUSTOMDRAW
*nmcdhdr
)
646 HWND hwnd
= infoPtr
->hwnd
;
649 DWORD_PTR dwItemSpec
;
653 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
654 dwItemSpec
= (DWORD_PTR
)wineItem
;
656 if (wineItem
->state
& TVIS_SELECTED
)
657 uItemState
|= CDIS_SELECTED
;
658 if (wineItem
== infoPtr
->selectedItem
)
659 uItemState
|= CDIS_FOCUS
;
660 if (wineItem
== infoPtr
->hotItem
)
661 uItemState
|= CDIS_HOT
;
663 nmcd
= &nmcdhdr
->nmcd
;
664 nmcd
->hdr
.hwndFrom
= hwnd
;
665 nmcd
->hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
666 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
667 nmcd
->dwDrawStage
= dwDrawStage
;
669 nmcd
->rc
= wineItem
->rect
;
670 nmcd
->dwItemSpec
= dwItemSpec
;
671 nmcd
->uItemState
= uItemState
;
672 nmcd
->lItemlParam
= wineItem
->lParam
;
673 nmcdhdr
->iLevel
= wineItem
->iLevel
;
675 TRACE("drawstage:%x hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
676 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
677 nmcd
->uItemState
, nmcd
->lItemlParam
);
679 retval
= TREEVIEW_SendRealNotify(infoPtr
, nmcd
->hdr
.idFrom
, (LPARAM
)nmcdhdr
);
685 TREEVIEW_BeginLabelEditNotify(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
687 HWND hwnd
= infoPtr
->hwnd
;
691 tvdi
.hdr
.hwndFrom
= hwnd
;
692 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
693 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_BEGINLABELEDITW
);
695 TREEVIEW_TVItemFromItem(infoPtr
, TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
,
696 &tvdi
.item
, editItem
);
698 ret
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, tvdi
.hdr
.idFrom
, (LPARAM
)&tvdi
);
700 if (!infoPtr
->bNtfUnicode
)
701 Free(tvdi
.item
.pszText
);
707 TREEVIEW_UpdateDispInfo(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
710 NMTVDISPINFOEXW callback
;
711 HWND hwnd
= infoPtr
->hwnd
;
713 TRACE("mask %x callbackMask %x\n", mask
, wineItem
->callbackMask
);
714 mask
&= wineItem
->callbackMask
;
716 if (mask
== 0) return;
718 callback
.hdr
.hwndFrom
= hwnd
;
719 callback
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
720 callback
.hdr
.code
= get_notifycode(infoPtr
, TVN_GETDISPINFOW
);
722 /* 'state' always contains valid value, as well as 'lParam'.
723 * All other parameters are uninitialized.
725 callback
.item
.pszText
= wineItem
->pszText
;
726 callback
.item
.cchTextMax
= wineItem
->cchTextMax
;
727 callback
.item
.mask
= mask
;
728 callback
.item
.hItem
= wineItem
;
729 callback
.item
.state
= wineItem
->state
;
730 callback
.item
.lParam
= wineItem
->lParam
;
732 /* If text is changed we need to recalculate textWidth */
733 if (mask
& TVIF_TEXT
)
734 wineItem
->textWidth
= 0;
736 TREEVIEW_SendRealNotify(infoPtr
, callback
.hdr
.idFrom
, (LPARAM
)&callback
);
738 /* It may have changed due to a call to SetItem. */
739 mask
&= wineItem
->callbackMask
;
741 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= wineItem
->pszText
)
743 /* Instead of copying text into our buffer user specified its own */
744 if (!infoPtr
->bNtfUnicode
) {
747 int len
= MultiByteToWideChar( CP_ACP
, 0,
748 (LPSTR
)callback
.item
.pszText
, -1,
750 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
751 newText
= ReAlloc(wineItem
->pszText
, buflen
);
753 TRACE("returned str %s, len=%d, buflen=%d\n",
754 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
758 wineItem
->pszText
= newText
;
759 MultiByteToWideChar( CP_ACP
, 0,
760 (LPSTR
)callback
.item
.pszText
, -1,
761 wineItem
->pszText
, buflen
/sizeof(WCHAR
));
762 wineItem
->cchTextMax
= buflen
/sizeof(WCHAR
);
764 /* If ReAlloc fails we have nothing to do, but keep original text */
767 int len
= max(lstrlenW(callback
.item
.pszText
) + 1,
769 LPWSTR newText
= ReAlloc(wineItem
->pszText
, len
);
771 TRACE("returned wstr %s, len=%d\n",
772 debugstr_w(callback
.item
.pszText
), len
);
776 wineItem
->pszText
= newText
;
777 strcpyW(wineItem
->pszText
, callback
.item
.pszText
);
778 wineItem
->cchTextMax
= len
;
780 /* If ReAlloc fails we have nothing to do, but keep original text */
783 else if (mask
& TVIF_TEXT
) {
784 /* User put text into our buffer, that is ok unless A string */
785 if (!infoPtr
->bNtfUnicode
) {
787 LPWSTR oldText
= NULL
;
789 int len
= MultiByteToWideChar( CP_ACP
, 0,
790 (LPSTR
)callback
.item
.pszText
, -1,
792 buflen
= max((len
)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
793 newText
= Alloc(buflen
);
795 TRACE("same buffer str %s, len=%d, buflen=%d\n",
796 debugstr_a((LPSTR
)callback
.item
.pszText
), len
, buflen
);
800 oldText
= wineItem
->pszText
;
801 wineItem
->pszText
= newText
;
802 MultiByteToWideChar( CP_ACP
, 0,
803 (LPSTR
)callback
.item
.pszText
, -1,
804 wineItem
->pszText
, buflen
/sizeof(WCHAR
));
805 wineItem
->cchTextMax
= buflen
/sizeof(WCHAR
);
811 if (mask
& TVIF_IMAGE
)
812 wineItem
->iImage
= callback
.item
.iImage
;
814 if (mask
& TVIF_SELECTEDIMAGE
)
815 wineItem
->iSelectedImage
= callback
.item
.iSelectedImage
;
817 if (mask
& TVIF_CHILDREN
)
818 wineItem
->cChildren
= callback
.item
.cChildren
;
820 /* These members are now permanently set. */
821 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
822 wineItem
->callbackMask
&= ~callback
.item
.mask
;
825 /***************************************************************************
826 * This function uses cChildren field to decide whether the item has
828 * Note: if this returns TRUE, the child items may not actually exist,
829 * they could be virtual.
831 * Just use wineItem->firstChild to check for physical children.
834 TREEVIEW_HasChildren(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
836 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, TVIF_CHILDREN
);
838 return wineItem
->cChildren
> 0;
841 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
845 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
847 if (nCommand
!= NF_REQUERY
) return 0;
849 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
850 TRACE("format=%d\n", format
);
852 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
) return 0;
854 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
859 /* Item Position ********************************************************/
861 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
863 TREEVIEW_ComputeItemInternalMetrics(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
865 /* Same effect, different optimisation. */
867 BOOL lar
= ((infoPtr
->dwStyle
& TVS_LINESATROOT
)
868 && (infoPtr
->dwStyle
& (TVS_HASLINES
|TVS_HASBUTTONS
)));
870 BOOL lar
= ((infoPtr
->dwStyle
871 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
875 item
->linesOffset
= infoPtr
->uIndent
* (lar
? item
->iLevel
: item
->iLevel
- 1)
877 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
878 item
->imageOffset
= item
->stateOffset
879 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
880 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
884 TREEVIEW_ComputeTextWidth(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
890 /* DRAW's OM docker creates items like this */
891 if (item
->pszText
== NULL
)
903 hdc
= GetDC(infoPtr
->hwnd
);
904 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
907 GetTextExtentPoint32W(hdc
, item
->pszText
, strlenW(item
->pszText
), &sz
);
908 item
->textWidth
= sz
.cx
;
912 SelectObject(hdc
, hOldFont
);
918 TREEVIEW_ComputeItemRect(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
920 item
->rect
.top
= infoPtr
->uItemHeight
*
921 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
923 item
->rect
.bottom
= item
->rect
.top
924 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
927 item
->rect
.right
= infoPtr
->clientWidth
;
930 /* We know that only items after start need their order updated. */
932 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
939 start
= infoPtr
->root
->firstChild
;
943 order
= start
->visibleOrder
;
945 for (item
= start
; item
!= NULL
;
946 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
948 if (!ISVISIBLE(item
) && order
> 0)
949 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, item
);
950 item
->visibleOrder
= order
;
951 order
+= item
->iIntegral
;
954 infoPtr
->maxVisibleOrder
= order
;
956 for (item
= start
; item
!= NULL
;
957 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
959 TREEVIEW_ComputeItemRect(infoPtr
, item
);
964 /* Update metrics of all items in selected subtree.
965 * root must be expanded
968 TREEVIEW_UpdateSubTree(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
970 TREEVIEW_ITEM
*sibling
;
974 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
977 root
->state
&= ~TVIS_EXPANDED
;
978 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
979 root
->state
|= TVIS_EXPANDED
;
981 hdc
= GetDC(infoPtr
->hwnd
);
982 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
984 for (; root
!= sibling
;
985 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
987 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
989 if (root
->callbackMask
& TVIF_TEXT
)
990 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
992 if (root
->textWidth
== 0)
994 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
995 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
999 SelectObject(hdc
, hOldFont
);
1000 ReleaseDC(infoPtr
->hwnd
, hdc
);
1003 /* Item Allocation **********************************************************/
1005 static TREEVIEW_ITEM
*
1006 TREEVIEW_AllocateItem(const TREEVIEW_INFO
*infoPtr
)
1008 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
1013 /* I_IMAGENONE would make more sense but this is neither what is
1014 * documented (MSDN doesn't specify) nor what Windows actually does
1015 * (it sets it to zero)... and I can so imagine an application using
1016 * inc/dec to toggle the images. */
1017 newItem
->iImage
= 0;
1018 newItem
->iSelectedImage
= 0;
1020 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
1029 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
1030 * free item->pszText. */
1032 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
1034 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
1035 if (infoPtr
->selectedItem
== item
)
1036 infoPtr
->selectedItem
= NULL
;
1037 if (infoPtr
->hotItem
== item
)
1038 infoPtr
->hotItem
= NULL
;
1039 if (infoPtr
->focusedItem
== item
)
1040 infoPtr
->focusedItem
= NULL
;
1041 if (infoPtr
->firstVisible
== item
)
1042 infoPtr
->firstVisible
= NULL
;
1043 if (infoPtr
->dropItem
== item
)
1044 infoPtr
->dropItem
= NULL
;
1045 if (infoPtr
->insertMarkItem
== item
)
1046 infoPtr
->insertMarkItem
= NULL
;
1051 /* Item Insertion *******************************************************/
1053 /***************************************************************************
1054 * This method inserts newItem before sibling as a child of parent.
1055 * sibling can be NULL, but only if parent has no children.
1058 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1059 TREEVIEW_ITEM
*parent
)
1061 assert(parent
!= NULL
);
1063 if (sibling
!= NULL
)
1065 assert(sibling
->parent
== parent
);
1067 if (sibling
->prevSibling
!= NULL
)
1068 sibling
->prevSibling
->nextSibling
= newItem
;
1070 newItem
->prevSibling
= sibling
->prevSibling
;
1071 sibling
->prevSibling
= newItem
;
1074 newItem
->prevSibling
= NULL
;
1076 newItem
->nextSibling
= sibling
;
1078 if (parent
->firstChild
== sibling
)
1079 parent
->firstChild
= newItem
;
1081 if (parent
->lastChild
== NULL
)
1082 parent
->lastChild
= newItem
;
1085 /***************************************************************************
1086 * This method inserts newItem after sibling as a child of parent.
1087 * sibling can be NULL, but only if parent has no children.
1090 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1091 TREEVIEW_ITEM
*parent
)
1093 assert(parent
!= NULL
);
1095 if (sibling
!= NULL
)
1097 assert(sibling
->parent
== parent
);
1099 if (sibling
->nextSibling
!= NULL
)
1100 sibling
->nextSibling
->prevSibling
= newItem
;
1102 newItem
->nextSibling
= sibling
->nextSibling
;
1103 sibling
->nextSibling
= newItem
;
1106 newItem
->nextSibling
= NULL
;
1108 newItem
->prevSibling
= sibling
;
1110 if (parent
->lastChild
== sibling
)
1111 parent
->lastChild
= newItem
;
1113 if (parent
->firstChild
== NULL
)
1114 parent
->firstChild
= newItem
;
1118 TREEVIEW_DoSetItemT(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
1119 const TVITEMEXW
*tvItem
, BOOL isW
)
1121 UINT callbackClear
= 0;
1122 UINT callbackSet
= 0;
1124 TRACE("item %p\n", wineItem
);
1125 /* Do this first in case it fails. */
1126 if (tvItem
->mask
& TVIF_TEXT
)
1128 wineItem
->textWidth
= 0; /* force width recalculation */
1129 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKW
&& tvItem
->pszText
!= NULL
) /* covers != TEXTCALLBACKA too, and undocumented: pszText of NULL also means TEXTCALLBACK */
1134 len
= lstrlenW(tvItem
->pszText
) + 1;
1136 len
= MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1, NULL
, 0);
1138 newText
= ReAlloc(wineItem
->pszText
, len
* sizeof(WCHAR
));
1140 if (newText
== NULL
) return FALSE
;
1142 callbackClear
|= TVIF_TEXT
;
1144 wineItem
->pszText
= newText
;
1145 wineItem
->cchTextMax
= len
;
1147 lstrcpynW(wineItem
->pszText
, tvItem
->pszText
, len
);
1149 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)tvItem
->pszText
, -1,
1150 wineItem
->pszText
, len
);
1152 TRACE("setting text %s, item %p\n", debugstr_w(wineItem
->pszText
), wineItem
);
1156 callbackSet
|= TVIF_TEXT
;
1158 wineItem
->pszText
= ReAlloc(wineItem
->pszText
,
1159 TEXT_CALLBACK_SIZE
* sizeof(WCHAR
));
1160 wineItem
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1161 TRACE("setting callback, item %p\n", wineItem
);
1165 if (tvItem
->mask
& TVIF_CHILDREN
)
1167 wineItem
->cChildren
= tvItem
->cChildren
;
1169 if (wineItem
->cChildren
== I_CHILDRENCALLBACK
)
1170 callbackSet
|= TVIF_CHILDREN
;
1172 callbackClear
|= TVIF_CHILDREN
;
1175 if (tvItem
->mask
& TVIF_IMAGE
)
1177 wineItem
->iImage
= tvItem
->iImage
;
1179 if (wineItem
->iImage
== I_IMAGECALLBACK
)
1180 callbackSet
|= TVIF_IMAGE
;
1182 callbackClear
|= TVIF_IMAGE
;
1185 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1187 wineItem
->iSelectedImage
= tvItem
->iSelectedImage
;
1189 if (wineItem
->iSelectedImage
== I_IMAGECALLBACK
)
1190 callbackSet
|= TVIF_SELECTEDIMAGE
;
1192 callbackClear
|= TVIF_SELECTEDIMAGE
;
1195 if (tvItem
->mask
& TVIF_PARAM
)
1196 wineItem
->lParam
= tvItem
->lParam
;
1198 /* If the application sets TVIF_INTEGRAL without
1199 * supplying a TVITEMEX structure, it's toast. */
1200 if (tvItem
->mask
& TVIF_INTEGRAL
)
1201 wineItem
->iIntegral
= tvItem
->iIntegral
;
1203 if (tvItem
->mask
& TVIF_STATE
)
1205 TRACE("prevstate,state,mask:%x,%x,%x\n", wineItem
->state
, tvItem
->state
,
1207 wineItem
->state
&= ~tvItem
->stateMask
;
1208 wineItem
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1211 wineItem
->callbackMask
|= callbackSet
;
1212 wineItem
->callbackMask
&= ~callbackClear
;
1217 /* Note that the new item is pre-zeroed. */
1219 TREEVIEW_InsertItemT(TREEVIEW_INFO
*infoPtr
, const TVINSERTSTRUCTW
*ptdi
, BOOL isW
)
1221 const TVITEMEXW
*tvItem
= &ptdi
->u
.itemex
;
1222 HTREEITEM insertAfter
;
1223 TREEVIEW_ITEM
*newItem
, *parentItem
;
1224 BOOL bTextUpdated
= FALSE
;
1226 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1228 parentItem
= infoPtr
->root
;
1232 parentItem
= ptdi
->hParent
;
1234 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1236 WARN("invalid parent %p\n", parentItem
);
1241 insertAfter
= ptdi
->hInsertAfter
;
1243 /* Validate this now for convenience. */
1244 switch ((DWORD_PTR
)insertAfter
)
1246 case (DWORD_PTR
)TVI_FIRST
:
1247 case (DWORD_PTR
)TVI_LAST
:
1248 case (DWORD_PTR
)TVI_SORT
:
1252 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1253 insertAfter
->parent
!= parentItem
)
1255 WARN("invalid insert after %p\n", insertAfter
);
1256 insertAfter
= TVI_LAST
;
1260 TRACE("parent %p position %p: %s\n", parentItem
, insertAfter
,
1261 (tvItem
->mask
& TVIF_TEXT
)
1262 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKW
) ? "<callback>"
1263 : (isW
? debugstr_w(tvItem
->pszText
) : debugstr_a((LPSTR
)tvItem
->pszText
)))
1266 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1267 if (newItem
== NULL
)
1270 newItem
->parent
= parentItem
;
1271 newItem
->iIntegral
= 1;
1272 newItem
->visibleOrder
= -1;
1274 if (!TREEVIEW_DoSetItemT(infoPtr
, newItem
, tvItem
, isW
))
1277 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1279 infoPtr
->uNumItems
++;
1281 switch ((DWORD_PTR
)insertAfter
)
1283 case (DWORD_PTR
)TVI_FIRST
:
1285 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1286 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1287 if (infoPtr
->firstVisible
== originalFirst
)
1288 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1292 case (DWORD_PTR
)TVI_LAST
:
1293 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1296 /* hInsertAfter names a specific item we want to insert after */
1298 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1301 case (DWORD_PTR
)TVI_SORT
:
1303 TREEVIEW_ITEM
*aChild
;
1304 TREEVIEW_ITEM
*previousChild
= NULL
;
1305 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1306 BOOL bItemInserted
= FALSE
;
1308 aChild
= parentItem
->firstChild
;
1310 bTextUpdated
= TRUE
;
1311 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1313 /* Iterate the parent children to see where we fit in */
1314 while (aChild
!= NULL
)
1318 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1319 comp
= lstrcmpW(newItem
->pszText
, aChild
->pszText
);
1321 if (comp
< 0) /* we are smaller than the current one */
1323 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1324 if (infoPtr
->firstVisible
== originalFirst
&&
1325 aChild
== originalFirst
)
1326 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1327 bItemInserted
= TRUE
;
1330 else if (comp
> 0) /* we are bigger than the current one */
1332 previousChild
= aChild
;
1334 /* This will help us to exit if there is no more sibling */
1335 aChild
= (aChild
->nextSibling
== 0)
1337 : aChild
->nextSibling
;
1339 /* Look at the next item */
1345 * An item with this name is already existing, therefore,
1346 * we add after the one we found
1348 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1349 bItemInserted
= TRUE
;
1355 * we reach the end of the child list and the item has not
1356 * yet been inserted, therefore, insert it after the last child.
1358 if ((!bItemInserted
) && (aChild
== NULL
))
1359 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1366 TRACE("new item %p; parent %p, mask %x\n", newItem
,
1367 newItem
->parent
, tvItem
->mask
);
1369 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1371 if (newItem
->parent
->cChildren
== 0)
1372 newItem
->parent
->cChildren
= 1;
1374 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1376 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1377 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1380 if (infoPtr
->firstVisible
== NULL
)
1381 infoPtr
->firstVisible
= newItem
;
1383 TREEVIEW_VerifyTree(infoPtr
);
1385 if (!infoPtr
->bRedraw
) return (LRESULT
)newItem
;
1387 if (parentItem
== infoPtr
->root
||
1388 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1390 TREEVIEW_ITEM
*item
;
1391 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1393 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1394 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1397 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1399 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1400 TREEVIEW_UpdateScrollBars(infoPtr
);
1402 * if the item was inserted in a visible part of the tree,
1403 * invalidate it, as well as those after it
1405 for (item
= newItem
;
1407 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1408 TREEVIEW_Invalidate(infoPtr
, item
);
1412 /* refresh treeview if newItem is the first item inserted under parentItem */
1413 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1415 /* parent got '+' - update it */
1416 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1420 return (LRESULT
)newItem
;
1423 /* Item Deletion ************************************************************/
1425 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
);
1428 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*parentItem
)
1430 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1432 while (kill
!= NULL
)
1434 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1436 TREEVIEW_RemoveItem(infoPtr
, kill
);
1441 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1442 assert(parentItem
->firstChild
== NULL
);
1443 assert(parentItem
->lastChild
== NULL
);
1447 TREEVIEW_UnlinkItem(const TREEVIEW_ITEM
*item
)
1449 TREEVIEW_ITEM
*parentItem
= item
->parent
;
1451 assert(item
!= NULL
);
1452 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1454 if (parentItem
->firstChild
== item
)
1455 parentItem
->firstChild
= item
->nextSibling
;
1457 if (parentItem
->lastChild
== item
)
1458 parentItem
->lastChild
= item
->prevSibling
;
1460 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1461 && parentItem
->cChildren
> 0)
1462 parentItem
->cChildren
= 0;
1464 if (item
->prevSibling
)
1465 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1467 if (item
->nextSibling
)
1468 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1472 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
1474 TRACE("%p, (%s)\n", wineItem
, TREEVIEW_ItemName(wineItem
));
1476 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1477 TVIF_HANDLE
| TVIF_PARAM
, wineItem
, 0);
1479 if (wineItem
->firstChild
)
1480 TREEVIEW_RemoveAllChildren(infoPtr
, wineItem
);
1482 TREEVIEW_UnlinkItem(wineItem
);
1484 infoPtr
->uNumItems
--;
1486 if (wineItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
1487 Free(wineItem
->pszText
);
1489 TREEVIEW_FreeItem(infoPtr
, wineItem
);
1493 /* Empty out the tree. */
1495 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1497 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1499 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1503 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM wineItem
)
1505 TREEVIEW_ITEM
*newSelection
= NULL
;
1506 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1507 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1508 BOOL visible
= FALSE
;
1510 if (wineItem
== TVI_ROOT
)
1512 TRACE("TVI_ROOT\n");
1513 parent
= infoPtr
->root
;
1514 newSelection
= NULL
;
1516 TREEVIEW_RemoveTree(infoPtr
);
1520 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
1523 TRACE("%p (%s)\n", wineItem
, TREEVIEW_ItemName(wineItem
));
1524 parent
= wineItem
->parent
;
1526 if (ISVISIBLE(wineItem
))
1528 prev
= TREEVIEW_GetPrevListItem(infoPtr
, wineItem
);
1532 if (infoPtr
->selectedItem
!= NULL
1533 && (wineItem
== infoPtr
->selectedItem
1534 || TREEVIEW_IsChildOf(wineItem
, infoPtr
->selectedItem
)))
1536 if (wineItem
->nextSibling
)
1537 newSelection
= wineItem
->nextSibling
;
1538 else if (wineItem
->parent
!= infoPtr
->root
)
1539 newSelection
= wineItem
->parent
;
1541 newSelection
= wineItem
->prevSibling
;
1542 TRACE("newSelection = %p\n", newSelection
);
1545 if (infoPtr
->firstVisible
== wineItem
)
1547 if (wineItem
->nextSibling
)
1548 newFirstVisible
= wineItem
->nextSibling
;
1549 else if (wineItem
->prevSibling
)
1550 newFirstVisible
= wineItem
->prevSibling
;
1551 else if (wineItem
->parent
!= infoPtr
->root
)
1552 newFirstVisible
= wineItem
->parent
;
1553 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1556 newFirstVisible
= infoPtr
->firstVisible
;
1558 TREEVIEW_RemoveItem(infoPtr
, wineItem
);
1561 /* Don't change if somebody else already has (infoPtr->selectedItem is cleared by FreeItem). */
1562 if (!infoPtr
->selectedItem
&& newSelection
)
1564 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1565 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1568 /* Validate insertMark dropItem.
1569 * hotItem ??? - used for comparison only.
1571 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1572 infoPtr
->insertMarkItem
= 0;
1574 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1575 infoPtr
->dropItem
= 0;
1577 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1578 newFirstVisible
= infoPtr
->root
->firstChild
;
1580 TREEVIEW_VerifyTree(infoPtr
);
1582 if (!infoPtr
->bRedraw
) return TRUE
;
1586 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1587 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1588 TREEVIEW_UpdateScrollBars(infoPtr
);
1589 TREEVIEW_Invalidate(infoPtr
, NULL
);
1591 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1593 /* parent lost '+/-' - update it */
1594 TREEVIEW_Invalidate(infoPtr
, parent
);
1601 /* Get/Set Messages *********************************************************/
1603 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
)
1605 infoPtr
->bRedraw
= wParam
? TRUE
: FALSE
;
1607 if (infoPtr
->bRedraw
)
1609 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1610 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1611 TREEVIEW_UpdateScrollBars(infoPtr
);
1612 TREEVIEW_Invalidate(infoPtr
, NULL
);
1618 TREEVIEW_GetIndent(const TREEVIEW_INFO
*infoPtr
)
1621 return infoPtr
->uIndent
;
1625 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1629 if (newIndent
< MINIMUM_INDENT
)
1630 newIndent
= MINIMUM_INDENT
;
1632 if (infoPtr
->uIndent
!= newIndent
)
1634 infoPtr
->uIndent
= newIndent
;
1635 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1636 TREEVIEW_UpdateScrollBars(infoPtr
);
1637 TREEVIEW_Invalidate(infoPtr
, NULL
);
1645 TREEVIEW_GetToolTips(const TREEVIEW_INFO
*infoPtr
)
1648 return (LRESULT
)infoPtr
->hwndToolTip
;
1652 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1657 prevToolTip
= infoPtr
->hwndToolTip
;
1658 infoPtr
->hwndToolTip
= hwndTT
;
1660 return (LRESULT
)prevToolTip
;
1664 TREEVIEW_SetUnicodeFormat(TREEVIEW_INFO
*infoPtr
, BOOL fUnicode
)
1666 BOOL rc
= infoPtr
->bNtfUnicode
;
1667 infoPtr
->bNtfUnicode
= fUnicode
;
1672 TREEVIEW_GetUnicodeFormat(const TREEVIEW_INFO
*infoPtr
)
1674 return infoPtr
->bNtfUnicode
;
1678 TREEVIEW_GetScrollTime(const TREEVIEW_INFO
*infoPtr
)
1680 return infoPtr
->uScrollTime
;
1684 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1686 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1688 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1690 return uOldScrollTime
;
1695 TREEVIEW_GetImageList(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1702 return (LRESULT
)infoPtr
->himlNormal
;
1705 return (LRESULT
)infoPtr
->himlState
;
1712 #define TVHEIGHT_MIN 16
1713 #define TVHEIGHT_FONT_ADJUST 3 /* 2 for focus border + 1 for margin some apps assume */
1715 /* Compute the natural height for items. */
1717 TREEVIEW_NaturalHeight(const TREEVIEW_INFO
*infoPtr
)
1721 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1724 /* Height is the maximum of:
1725 * 16 (a hack because our fonts are tiny), and
1726 * The text height + border & margin, and
1727 * The size of the normal image list
1729 GetTextMetricsW(hdc
, &tm
);
1730 SelectObject(hdc
, hOldFont
);
1733 height
= TVHEIGHT_MIN
;
1734 if (height
< tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
)
1735 height
= tm
.tmHeight
+ tm
.tmExternalLeading
+ TVHEIGHT_FONT_ADJUST
;
1736 if (height
< infoPtr
->normalImageHeight
)
1737 height
= infoPtr
->normalImageHeight
;
1739 /* Round down, unless we support odd ("non even") heights. */
1740 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1747 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himlNew
)
1749 HIMAGELIST himlOld
= 0;
1750 int oldWidth
= infoPtr
->normalImageWidth
;
1751 int oldHeight
= infoPtr
->normalImageHeight
;
1754 TRACE("%lx,%p\n", wParam
, himlNew
);
1759 himlOld
= infoPtr
->himlNormal
;
1760 infoPtr
->himlNormal
= himlNew
;
1762 if (himlNew
!= NULL
)
1763 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1764 &infoPtr
->normalImageHeight
);
1767 infoPtr
->normalImageWidth
= 0;
1768 infoPtr
->normalImageHeight
= 0;
1774 himlOld
= infoPtr
->himlState
;
1775 infoPtr
->himlState
= himlNew
;
1777 if (himlNew
!= NULL
)
1778 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1779 &infoPtr
->stateImageHeight
);
1782 infoPtr
->stateImageWidth
= 0;
1783 infoPtr
->stateImageHeight
= 0;
1789 if (oldWidth
!= infoPtr
->normalImageWidth
||
1790 oldHeight
!= infoPtr
->normalImageHeight
)
1792 BOOL bRecalcVisible
= FALSE
;
1794 if (oldHeight
!= infoPtr
->normalImageHeight
&&
1795 !infoPtr
->bHeightSet
)
1797 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1798 bRecalcVisible
= TRUE
;
1801 if (infoPtr
->normalImageWidth
> MINIMUM_INDENT
&&
1802 infoPtr
->normalImageWidth
!= infoPtr
->uIndent
)
1804 infoPtr
->uIndent
= infoPtr
->normalImageWidth
;
1805 bRecalcVisible
= TRUE
;
1809 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1811 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1812 TREEVIEW_UpdateScrollBars(infoPtr
);
1815 TREEVIEW_Invalidate(infoPtr
, NULL
);
1817 return (LRESULT
)himlOld
;
1821 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1823 INT prevHeight
= infoPtr
->uItemHeight
;
1825 TRACE("%d\n", newHeight
);
1826 if (newHeight
== -1)
1828 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1829 infoPtr
->bHeightSet
= FALSE
;
1833 infoPtr
->uItemHeight
= newHeight
;
1834 infoPtr
->bHeightSet
= TRUE
;
1837 /* Round down, unless we support odd ("non even") heights. */
1838 if (!(infoPtr
->dwStyle
& TVS_NONEVENHEIGHT
))
1839 infoPtr
->uItemHeight
&= ~1;
1841 if (infoPtr
->uItemHeight
!= prevHeight
)
1843 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1844 TREEVIEW_UpdateScrollBars(infoPtr
);
1845 TREEVIEW_Invalidate(infoPtr
, NULL
);
1852 TREEVIEW_GetItemHeight(const TREEVIEW_INFO
*infoPtr
)
1855 return infoPtr
->uItemHeight
;
1860 TREEVIEW_GetFont(const TREEVIEW_INFO
*infoPtr
)
1862 TRACE("%p\n", infoPtr
->hFont
);
1863 return (LRESULT
)infoPtr
->hFont
;
1868 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1872 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1878 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1880 UINT uHeight
= infoPtr
->uItemHeight
;
1882 TRACE("%p %i\n", hFont
, bRedraw
);
1884 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
1886 DeleteObject(infoPtr
->hBoldFont
);
1887 DeleteObject(infoPtr
->hUnderlineFont
);
1888 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1889 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
1891 if (!infoPtr
->bHeightSet
)
1892 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1894 if (uHeight
!= infoPtr
->uItemHeight
)
1895 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1897 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1899 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1900 TREEVIEW_UpdateScrollBars(infoPtr
);
1903 TREEVIEW_Invalidate(infoPtr
, NULL
);
1910 TREEVIEW_GetLineColor(const TREEVIEW_INFO
*infoPtr
)
1913 return (LRESULT
)infoPtr
->clrLine
;
1917 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1919 COLORREF prevColor
= infoPtr
->clrLine
;
1922 infoPtr
->clrLine
= color
;
1923 return (LRESULT
)prevColor
;
1928 TREEVIEW_GetTextColor(const TREEVIEW_INFO
*infoPtr
)
1931 return (LRESULT
)infoPtr
->clrText
;
1935 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1937 COLORREF prevColor
= infoPtr
->clrText
;
1940 infoPtr
->clrText
= color
;
1942 if (infoPtr
->clrText
!= prevColor
)
1943 TREEVIEW_Invalidate(infoPtr
, NULL
);
1945 return (LRESULT
)prevColor
;
1950 TREEVIEW_GetBkColor(const TREEVIEW_INFO
*infoPtr
)
1953 return (LRESULT
)infoPtr
->clrBk
;
1957 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1959 COLORREF prevColor
= infoPtr
->clrBk
;
1962 infoPtr
->clrBk
= newColor
;
1964 if (newColor
!= prevColor
)
1965 TREEVIEW_Invalidate(infoPtr
, NULL
);
1967 return (LRESULT
)prevColor
;
1972 TREEVIEW_GetInsertMarkColor(const TREEVIEW_INFO
*infoPtr
)
1975 return (LRESULT
)infoPtr
->clrInsertMark
;
1979 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1981 COLORREF prevColor
= infoPtr
->clrInsertMark
;
1983 TRACE("%x\n", color
);
1984 infoPtr
->clrInsertMark
= color
;
1986 return (LRESULT
)prevColor
;
1991 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
1993 TRACE("%d %p\n", wParam
, item
);
1995 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1998 infoPtr
->insertBeforeorAfter
= wParam
;
1999 infoPtr
->insertMarkItem
= item
;
2001 TREEVIEW_Invalidate(infoPtr
, NULL
);
2007 /************************************************************************
2008 * Some serious braindamage here. lParam is a pointer to both the
2009 * input HTREEITEM and the output RECT.
2012 TREEVIEW_GetItemRect(const TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
2014 TREEVIEW_ITEM
*wineItem
;
2015 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
2019 * validate parameters
2025 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
) || !ISVISIBLE(wineItem
))
2029 * If wParam is TRUE return the text size otherwise return
2030 * the whole item size
2034 /* Windows does not send TVN_GETDISPINFO here. */
2036 lpRect
->top
= wineItem
->rect
.top
;
2037 lpRect
->bottom
= wineItem
->rect
.bottom
;
2039 lpRect
->left
= wineItem
->textOffset
;
2040 if (!wineItem
->textWidth
)
2041 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, 0);
2043 lpRect
->right
= wineItem
->textOffset
+ wineItem
->textWidth
+ 4;
2047 *lpRect
= wineItem
->rect
;
2050 TRACE("%s [%s]\n", fTextRect
? "text" : "item", wine_dbgstr_rect(lpRect
));
2055 static inline LRESULT
2056 TREEVIEW_GetVisibleCount(const TREEVIEW_INFO
*infoPtr
)
2058 /* Surprise! This does not take integral height into account. */
2059 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2064 TREEVIEW_GetItemT(const TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
, BOOL isW
)
2066 TREEVIEW_ITEM
*wineItem
;
2068 wineItem
= tvItem
->hItem
;
2069 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2072 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, tvItem
->mask
);
2074 if (tvItem
->mask
& TVIF_CHILDREN
)
2076 if (wineItem
->cChildren
==I_CHILDRENCALLBACK
)
2077 FIXME("I_CHILDRENCALLBACK not supported\n");
2078 tvItem
->cChildren
= wineItem
->cChildren
;
2081 if (tvItem
->mask
& TVIF_HANDLE
)
2082 tvItem
->hItem
= wineItem
;
2084 if (tvItem
->mask
& TVIF_IMAGE
)
2085 tvItem
->iImage
= wineItem
->iImage
;
2087 if (tvItem
->mask
& TVIF_INTEGRAL
)
2088 tvItem
->iIntegral
= wineItem
->iIntegral
;
2090 /* undocumented: windows ignores TVIF_PARAM and
2091 * * always sets lParam
2093 tvItem
->lParam
= wineItem
->lParam
;
2095 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2096 tvItem
->iSelectedImage
= wineItem
->iSelectedImage
;
2098 if (tvItem
->mask
& TVIF_STATE
)
2099 /* Careful here - Windows ignores the stateMask when you get the state
2100 That contradicts the documentation, but makes more common sense, masking
2101 retrieval in this way seems overkill */
2102 tvItem
->state
= wineItem
->state
;
2104 if (tvItem
->mask
& TVIF_TEXT
)
2106 if (wineItem
->pszText
== NULL
)
2108 if (tvItem
->cchTextMax
> 0)
2109 tvItem
->pszText
[0] = '\0';
2113 if (wineItem
->pszText
== LPSTR_TEXTCALLBACKW
)
2115 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2116 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2120 lstrcpynW(tvItem
->pszText
, wineItem
->pszText
, tvItem
->cchTextMax
);
2125 if (wineItem
->pszText
== LPSTR_TEXTCALLBACKW
)
2127 tvItem
->pszText
= (LPWSTR
)LPSTR_TEXTCALLBACKA
;
2128 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2132 WideCharToMultiByte(CP_ACP
, 0, wineItem
->pszText
, -1,
2133 (LPSTR
)tvItem
->pszText
, tvItem
->cchTextMax
, NULL
, NULL
);
2137 TRACE("item <%p>, txt %p, img %p, mask %x\n",
2138 wineItem
, tvItem
->pszText
, &tvItem
->iImage
, tvItem
->mask
);
2143 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2144 * which is wrong. */
2146 TREEVIEW_SetItemT(TREEVIEW_INFO
*infoPtr
, const TVITEMEXW
*tvItem
, BOOL isW
)
2148 TREEVIEW_ITEM
*wineItem
;
2149 TREEVIEW_ITEM originalItem
;
2151 wineItem
= tvItem
->hItem
;
2153 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr
, wineItem
),
2156 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2159 /* store the original item values */
2160 originalItem
= *wineItem
;
2162 if (!TREEVIEW_DoSetItemT(infoPtr
, wineItem
, tvItem
, isW
))
2165 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2166 if ((tvItem
->mask
& TVIF_TEXT
2167 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2168 && ISVISIBLE(wineItem
))
2170 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, TVIF_TEXT
);
2171 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, 0);
2174 if (tvItem
->mask
!= 0 && ISVISIBLE(wineItem
))
2176 /* The refresh updates everything, but we can't wait until then. */
2177 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, wineItem
);
2179 /* if any of the item's values changed and it's not a callback, redraw the item */
2180 if (item_changed(&originalItem
, wineItem
, tvItem
))
2182 if (tvItem
->mask
& TVIF_INTEGRAL
)
2184 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
2185 TREEVIEW_UpdateScrollBars(infoPtr
);
2187 TREEVIEW_Invalidate(infoPtr
, NULL
);
2191 TREEVIEW_UpdateScrollBars(infoPtr
);
2192 TREEVIEW_Invalidate(infoPtr
, wineItem
);
2201 TREEVIEW_GetItemState(const TREEVIEW_INFO
*infoPtr
, HTREEITEM wineItem
, UINT mask
)
2205 if (!wineItem
|| !TREEVIEW_ValidItem(infoPtr
, wineItem
))
2208 return (wineItem
->state
& mask
);
2212 TREEVIEW_GetNextItem(const TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM wineItem
)
2214 TREEVIEW_ITEM
*retval
;
2218 /* handle all the global data here */
2221 case TVGN_CHILD
: /* Special case: child of 0 is root */
2226 retval
= infoPtr
->root
->firstChild
;
2230 retval
= infoPtr
->selectedItem
;
2233 case TVGN_FIRSTVISIBLE
:
2234 retval
= infoPtr
->firstVisible
;
2237 case TVGN_DROPHILITE
:
2238 retval
= infoPtr
->dropItem
;
2241 case TVGN_LASTVISIBLE
:
2242 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2248 TRACE("flags:%x, returns %p\n", which
, retval
);
2249 return (LRESULT
)retval
;
2252 if (wineItem
== TVI_ROOT
) wineItem
= infoPtr
->root
;
2254 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2260 retval
= wineItem
->nextSibling
;
2263 retval
= wineItem
->prevSibling
;
2266 retval
= (wineItem
->parent
!= infoPtr
->root
) ? wineItem
->parent
: NULL
;
2269 retval
= wineItem
->firstChild
;
2271 case TVGN_NEXTVISIBLE
:
2272 retval
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
2274 case TVGN_PREVIOUSVISIBLE
:
2275 retval
= TREEVIEW_GetPrevListItem(infoPtr
, wineItem
);
2278 TRACE("Unknown msg %x,item %p\n", which
, wineItem
);
2282 TRACE("flags:%x, item %p;returns %p\n", which
, wineItem
, retval
);
2283 return (LRESULT
)retval
;
2288 TREEVIEW_GetCount(const TREEVIEW_INFO
*infoPtr
)
2290 TRACE(" %d\n", infoPtr
->uNumItems
);
2291 return (LRESULT
)infoPtr
->uNumItems
;
2295 TREEVIEW_ToggleItemState(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2297 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2299 static const unsigned int state_table
[] = { 0, 2, 1 };
2303 state
= STATEIMAGEINDEX(item
->state
);
2304 TRACE("state:%x\n", state
);
2305 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2308 state
= state_table
[state
];
2310 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2312 TRACE("state:%x\n", state
);
2313 TREEVIEW_Invalidate(infoPtr
, item
);
2318 /* Painting *************************************************************/
2320 /* Draw the lines and expand button for an item. Also draws one section
2321 * of the line from item's parent to item's parent's next sibling. */
2323 TREEVIEW_DrawItemLines(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const TREEVIEW_ITEM
*item
)
2325 LONG centerx
, centery
;
2326 BOOL lar
= ((infoPtr
->dwStyle
2327 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2330 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2332 if (!lar
&& item
->iLevel
== 0)
2335 hbr
= CreateSolidBrush(clrBk
);
2336 hbrOld
= SelectObject(hdc
, hbr
);
2338 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2339 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2341 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2343 HPEN hOldPen
, hNewPen
;
2347 /* Get a dotted grey pen */
2348 lb
.lbStyle
= BS_SOLID
;
2349 lb
.lbColor
= GETLINECOLOR(infoPtr
->clrLine
);
2350 hNewPen
= ExtCreatePen(PS_COSMETIC
|PS_ALTERNATE
, 1, &lb
, 0, NULL
);
2351 hOldPen
= SelectObject(hdc
, hNewPen
);
2353 /* Make sure the center is on a dot (using +2 instead
2354 * of +1 gives us pixel-by-pixel compat with native) */
2355 centery
= (centery
+ 2) & ~1;
2357 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2358 LineTo(hdc
, centerx
- 1, centery
);
2360 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2362 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2363 LineTo(hdc
, centerx
, centery
);
2366 if (item
->nextSibling
)
2368 MoveToEx(hdc
, centerx
, centery
, NULL
);
2369 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2372 /* Draw the line from our parent to its next sibling. */
2373 parent
= item
->parent
;
2374 while (parent
!= infoPtr
->root
)
2376 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2378 if (parent
->nextSibling
2379 /* skip top-levels unless TVS_LINESATROOT */
2380 && parent
->stateOffset
> parent
->linesOffset
)
2382 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2383 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2386 parent
= parent
->parent
;
2389 SelectObject(hdc
, hOldPen
);
2390 DeleteObject(hNewPen
);
2394 * Display the (+/-) signs
2397 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2399 if (item
->cChildren
)
2401 HTHEME theme
= GetWindowTheme(infoPtr
->hwnd
);
2404 RECT glyphRect
= item
->rect
;
2405 glyphRect
.left
= item
->linesOffset
;
2406 glyphRect
.right
= item
->stateOffset
;
2407 DrawThemeBackground (theme
, hdc
, TVP_GLYPH
,
2408 (item
->state
& TVIS_EXPANDED
) ? GLPS_OPENED
: GLPS_CLOSED
,
2413 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2414 LONG width
= item
->stateOffset
- item
->linesOffset
;
2415 LONG rectsize
= min(height
, width
) / 4;
2416 /* plussize = ceil(rectsize * 3/4) */
2417 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2419 HPEN new_pen
= CreatePen(PS_SOLID
, 0, GETLINECOLOR(infoPtr
->clrLine
));
2420 HPEN old_pen
= SelectObject(hdc
, new_pen
);
2422 Rectangle(hdc
, centerx
- rectsize
- 1, centery
- rectsize
- 1,
2423 centerx
+ rectsize
+ 2, centery
+ rectsize
+ 2);
2425 SelectObject(hdc
, old_pen
);
2426 DeleteObject(new_pen
);
2428 /* draw +/- signs with current text color */
2429 new_pen
= CreatePen(PS_SOLID
, 0, GETTXTCOLOR(infoPtr
->clrText
));
2430 old_pen
= SelectObject(hdc
, new_pen
);
2432 if (height
< 18 || width
< 18)
2434 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2435 LineTo(hdc
, centerx
+ plussize
, centery
);
2437 if (!(item
->state
& TVIS_EXPANDED
))
2439 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2440 LineTo(hdc
, centerx
, centery
+ plussize
);
2445 Rectangle(hdc
, centerx
- plussize
+ 1, centery
- 1,
2446 centerx
+ plussize
, centery
+ 2);
2448 if (!(item
->state
& TVIS_EXPANDED
))
2450 Rectangle(hdc
, centerx
- 1, centery
- plussize
+ 1,
2451 centerx
+ 2, centery
+ plussize
);
2452 SetPixel(hdc
, centerx
- 1, centery
, clrBk
);
2453 SetPixel(hdc
, centerx
+ 1, centery
, clrBk
);
2457 SelectObject(hdc
, old_pen
);
2458 DeleteObject(new_pen
);
2462 SelectObject(hdc
, hbrOld
);
2467 TREEVIEW_DrawItem(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*wineItem
)
2471 COLORREF oldTextColor
, oldTextBkColor
;
2473 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2474 NMTVCUSTOMDRAW nmcdhdr
;
2476 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, CALLBACK_MASK_ALL
);
2478 /* - If item is drop target or it is selected and window is in focus -
2479 * use blue background (COLOR_HIGHLIGHT).
2480 * - If item is selected, window is not in focus, but it has style
2481 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2482 * - Otherwise - use background color
2484 if ((wineItem
->state
& TVIS_DROPHILITED
) || ((wineItem
== infoPtr
->focusedItem
) && !(wineItem
->state
& TVIS_SELECTED
)) ||
2485 ((wineItem
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
) &&
2486 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2488 if ((wineItem
->state
& TVIS_DROPHILITED
) || inFocus
)
2490 nmcdhdr
.clrTextBk
= comctl32_color
.clrHighlight
;
2491 nmcdhdr
.clrText
= comctl32_color
.clrHighlightText
;
2495 nmcdhdr
.clrTextBk
= comctl32_color
.clrBtnFace
;
2496 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2501 nmcdhdr
.clrTextBk
= GETBKCOLOR(infoPtr
->clrBk
);
2502 if ((infoPtr
->dwStyle
& TVS_TRACKSELECT
) && (wineItem
== infoPtr
->hotItem
))
2503 nmcdhdr
.clrText
= comctl32_color
.clrHighlight
;
2505 nmcdhdr
.clrText
= GETTXTCOLOR(infoPtr
->clrText
);
2508 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, wineItem
));
2510 /* The custom draw handler can query the text rectangle,
2512 /* should already be known, set to 0 when changed */
2513 if (!wineItem
->textWidth
)
2514 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, hdc
);
2518 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2520 cditem
= TREEVIEW_SendCustomDrawItemNotify
2521 (infoPtr
, hdc
, wineItem
, CDDS_ITEMPREPAINT
, &nmcdhdr
);
2522 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2524 if (cditem
& CDRF_SKIPDEFAULT
)
2526 SelectObject(hdc
, hOldFont
);
2531 if (cditem
& CDRF_NEWFONT
)
2532 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, hdc
);
2534 TREEVIEW_DrawItemLines(infoPtr
, hdc
, wineItem
);
2536 /* Set colors. Custom draw handler can change these so we do this after it. */
2537 oldTextColor
= SetTextColor(hdc
, nmcdhdr
.clrText
);
2538 oldTextBkColor
= SetBkColor(hdc
, nmcdhdr
.clrTextBk
);
2540 centery
= (wineItem
->rect
.top
+ wineItem
->rect
.bottom
) / 2;
2543 * Display the images associated with this item
2548 /* State images are displayed to the left of the Normal image
2549 * image number is in state; zero should be `display no image'.
2551 imageIndex
= STATEIMAGEINDEX(wineItem
->state
);
2553 if (infoPtr
->himlState
&& imageIndex
)
2555 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2556 wineItem
->stateOffset
,
2557 centery
- infoPtr
->stateImageHeight
/ 2,
2561 /* Now, draw the normal image; can be either selected or
2562 * non-selected image.
2565 if ((wineItem
->state
& TVIS_SELECTED
) && (wineItem
->iSelectedImage
>= 0))
2567 /* The item is currently selected */
2568 imageIndex
= wineItem
->iSelectedImage
;
2572 /* The item is not selected */
2573 imageIndex
= wineItem
->iImage
;
2576 if (infoPtr
->himlNormal
)
2578 int ovlIdx
= wineItem
->state
& TVIS_OVERLAYMASK
;
2580 ImageList_Draw(infoPtr
->himlNormal
, imageIndex
, hdc
,
2581 wineItem
->imageOffset
,
2582 centery
- infoPtr
->normalImageHeight
/ 2,
2583 ILD_NORMAL
| ovlIdx
);
2589 * Display the text associated with this item
2592 /* Don't paint item's text if it's being edited */
2593 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= wineItem
))
2595 if (wineItem
->pszText
)
2599 rcText
.top
= wineItem
->rect
.top
;
2600 rcText
.bottom
= wineItem
->rect
.bottom
;
2601 rcText
.left
= wineItem
->textOffset
;
2602 rcText
.right
= rcText
.left
+ wineItem
->textWidth
+ 4;
2604 TRACE("drawing text %s at (%s)\n",
2605 debugstr_w(wineItem
->pszText
), wine_dbgstr_rect(&rcText
));
2608 ExtTextOutW(hdc
, rcText
.left
+ 2, rcText
.top
+ 1,
2609 ETO_CLIPPED
| ETO_OPAQUE
,
2612 lstrlenW(wineItem
->pszText
),
2615 /* Draw the box around the selected item */
2616 if ((wineItem
== infoPtr
->selectedItem
) && inFocus
)
2618 DrawFocusRect(hdc
,&rcText
);
2624 /* Draw insertion mark if necessary */
2626 if (infoPtr
->insertMarkItem
)
2627 TRACE("item:%d,mark:%p\n",
2628 TREEVIEW_GetItemIndex(infoPtr
, wineItem
),
2629 infoPtr
->insertMarkItem
);
2631 if (wineItem
== infoPtr
->insertMarkItem
)
2633 HPEN hNewPen
, hOldPen
;
2637 hNewPen
= CreatePen(PS_SOLID
, 2, GETINSCOLOR(infoPtr
->clrInsertMark
));
2638 hOldPen
= SelectObject(hdc
, hNewPen
);
2640 if (infoPtr
->insertBeforeorAfter
)
2641 offset
= wineItem
->rect
.bottom
- 1;
2643 offset
= wineItem
->rect
.top
+ 1;
2645 left
= wineItem
->textOffset
- 2;
2646 right
= wineItem
->textOffset
+ wineItem
->textWidth
+ 2;
2648 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2649 LineTo(hdc
, left
, offset
+ 4);
2651 MoveToEx(hdc
, left
, offset
, NULL
);
2652 LineTo(hdc
, right
+ 1, offset
);
2654 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2655 LineTo(hdc
, right
, offset
- 4);
2657 SelectObject(hdc
, hOldPen
);
2658 DeleteObject(hNewPen
);
2661 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2663 cditem
= TREEVIEW_SendCustomDrawItemNotify
2664 (infoPtr
, hdc
, wineItem
, CDDS_ITEMPOSTPAINT
, &nmcdhdr
);
2665 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2668 /* Restore the hdc state */
2669 SetTextColor(hdc
, oldTextColor
);
2670 SetBkColor(hdc
, oldTextBkColor
);
2671 SelectObject(hdc
, hOldFont
);
2674 /* Computes treeHeight and treeWidth and updates the scroll bars.
2677 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2679 TREEVIEW_ITEM
*wineItem
;
2680 HWND hwnd
= infoPtr
->hwnd
;
2684 LONG scrollX
= infoPtr
->scrollX
;
2686 infoPtr
->treeWidth
= 0;
2687 infoPtr
->treeHeight
= 0;
2689 /* We iterate through all visible items in order to get the tree height
2691 wineItem
= infoPtr
->root
->firstChild
;
2693 while (wineItem
!= NULL
)
2695 if (ISVISIBLE(wineItem
))
2697 /* actually we draw text at textOffset + 2 */
2698 if (2+wineItem
->textOffset
+wineItem
->textWidth
> infoPtr
->treeWidth
)
2699 infoPtr
->treeWidth
= wineItem
->textOffset
+wineItem
->textWidth
+2;
2701 /* This is scroll-adjusted, but we fix this below. */
2702 infoPtr
->treeHeight
= wineItem
->rect
.bottom
;
2705 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
2708 /* Fix the scroll adjusted treeHeight and treeWidth. */
2709 if (infoPtr
->root
->firstChild
)
2710 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2712 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2714 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2716 /* Adding one scroll bar may take up enough space that it forces us
2717 * to add the other as well. */
2718 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2722 if (infoPtr
->treeWidth
2723 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2726 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
|| infoPtr
->scrollX
> 0)
2729 if (!vert
&& horz
&& infoPtr
->treeHeight
2730 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2733 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2735 si
.cbSize
= sizeof(SCROLLINFO
);
2736 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2741 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2742 if ( si
.nPage
&& NULL
!= infoPtr
->firstVisible
)
2744 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2745 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2747 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2749 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2750 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2751 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2755 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2756 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2757 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2762 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2763 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2764 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2769 si
.nPage
= infoPtr
->clientWidth
;
2770 si
.nPos
= infoPtr
->scrollX
;
2771 si
.nMax
= infoPtr
->treeWidth
- 1;
2773 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2775 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2779 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2780 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2781 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2783 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2784 TREEVIEW_HScroll(infoPtr
,
2785 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2789 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2790 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2791 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2794 if (infoPtr
->scrollX
!= 0)
2796 TREEVIEW_HScroll(infoPtr
,
2797 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2802 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2806 TREEVIEW_FillBkgnd(const TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2809 COLORREF clrBk
= GETBKCOLOR(infoPtr
->clrBk
);
2811 hBrush
= CreateSolidBrush(clrBk
);
2812 FillRect(hdc
, rc
, hBrush
);
2813 DeleteObject(hBrush
);
2816 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2818 TREEVIEW_EraseBackground(const TREEVIEW_INFO
*infoPtr
, HDC hdc
)
2822 TRACE("%p\n", infoPtr
);
2824 GetClientRect(infoPtr
->hwnd
, &rect
);
2825 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rect
);
2831 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*rc
)
2833 HWND hwnd
= infoPtr
->hwnd
;
2835 TREEVIEW_ITEM
*wineItem
;
2837 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2839 TRACE("empty window\n");
2843 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2846 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2848 ReleaseDC(hwnd
, hdc
);
2852 for (wineItem
= infoPtr
->root
->firstChild
;
2854 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
))
2856 if (ISVISIBLE(wineItem
))
2858 /* Avoid unneeded calculations */
2859 if (wineItem
->rect
.top
> rect
.bottom
)
2861 if (wineItem
->rect
.bottom
< rect
.top
)
2864 TREEVIEW_DrawItem(infoPtr
, hdc
, wineItem
);
2869 // This is correct, but is causes and infinite loop of WM_PAINT messages, resulting
2870 // in continuous painting of the scroll bar in reactos. Comment out until the real
2873 //TREEVIEW_UpdateScrollBars(infoPtr);
2875 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2877 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2881 TREEVIEW_InvalidateItem(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2883 if (item
) InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2887 TREEVIEW_Invalidate(const TREEVIEW_INFO
*infoPtr
, const TREEVIEW_ITEM
*item
)
2890 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2892 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2896 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, HDC hdc_ref
)
2907 GetClientRect(infoPtr
->hwnd
, &rc
);
2911 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
2914 TREEVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
2917 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
2918 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
2921 EndPaint(infoPtr
->hwnd
, &ps
);
2927 TREEVIEW_PrintClient(TREEVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
2929 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
2931 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwnd
))
2934 if (options
& PRF_ERASEBKGND
)
2935 TREEVIEW_EraseBackground(infoPtr
, hdc
);
2937 if (options
& PRF_CLIENT
)
2940 GetClientRect(infoPtr
->hwnd
, &rc
);
2941 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
2947 /* Sorting **************************************************************/
2949 /***************************************************************************
2950 * Forward the DPA local callback to the treeview owner callback
2953 TREEVIEW_CallBackCompare(const TREEVIEW_ITEM
*first
, const TREEVIEW_ITEM
*second
,
2954 const TVSORTCB
*pCallBackSort
)
2956 /* Forward the call to the client-defined callback */
2957 return pCallBackSort
->lpfnCompare(first
->lParam
,
2959 pCallBackSort
->lParam
);
2962 /***************************************************************************
2963 * Treeview native sort routine: sort on item text.
2966 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
2967 const TREEVIEW_INFO
*infoPtr
)
2969 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
2970 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
2972 if(first
->pszText
&& second
->pszText
)
2973 return lstrcmpiW(first
->pszText
, second
->pszText
);
2974 else if(first
->pszText
)
2976 else if(second
->pszText
)
2982 /* Returns the number of physical children belonging to item. */
2984 TREEVIEW_CountChildren(const TREEVIEW_ITEM
*item
)
2989 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
2995 /* Returns a DPA containing a pointer to each physical child of item in
2996 * sibling order. If item has no children, an empty DPA is returned. */
2998 TREEVIEW_BuildChildDPA(const TREEVIEW_ITEM
*item
)
3000 HTREEITEM child
= item
->firstChild
;
3002 HDPA list
= DPA_Create(8);
3003 if (list
== 0) return NULL
;
3005 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
3007 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
3017 /***************************************************************************
3018 * Setup the treeview structure with regards of the sort method
3019 * and sort the children of the TV item specified in lParam
3020 * fRecurse: currently unused. Should be zero.
3021 * parent: if pSort!=NULL, should equal pSort->hParent.
3022 * otherwise, item which child items are to be sorted.
3023 * pSort: sort method info. if NULL, sort on item text.
3024 * if non-NULL, sort on item's lParam content, and let the
3025 * application decide what that means. See also TVM_SORTCHILDRENCB.
3029 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, HTREEITEM parent
,
3033 PFNDPACOMPARE pfnCompare
;
3036 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
3037 if (parent
== TVI_ROOT
|| parent
== NULL
)
3038 parent
= infoPtr
->root
;
3040 /* Check for a valid handle to the parent item */
3041 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
3043 ERR("invalid item hParent=%p\n", parent
);
3049 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
3050 lpCompare
= (LPARAM
)pSort
;
3054 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
3055 lpCompare
= (LPARAM
)infoPtr
;
3058 cChildren
= TREEVIEW_CountChildren(parent
);
3060 /* Make sure there is something to sort */
3063 /* TREEVIEW_ITEM rechaining */
3066 HTREEITEM nextItem
= 0;
3067 HTREEITEM prevItem
= 0;
3069 HDPA sortList
= TREEVIEW_BuildChildDPA(parent
);
3071 if (sortList
== NULL
)
3074 /* let DPA sort the list */
3075 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
3077 /* The order of DPA entries has been changed, so fixup the
3078 * nextSibling and prevSibling pointers. */
3080 item
= DPA_GetPtr(sortList
, count
++);
3081 while ((nextItem
= DPA_GetPtr(sortList
, count
++)) != NULL
)
3083 /* link the two current item together */
3084 item
->nextSibling
= nextItem
;
3085 nextItem
->prevSibling
= item
;
3087 if (prevItem
== NULL
)
3089 /* this is the first item, update the parent */
3090 parent
->firstChild
= item
;
3091 item
->prevSibling
= NULL
;
3095 /* fix the back chaining */
3096 item
->prevSibling
= prevItem
;
3099 /* get ready for the next one */
3104 /* the last item is pointed to by item and never has a sibling */
3105 item
->nextSibling
= NULL
;
3106 parent
->lastChild
= item
;
3108 DPA_Destroy(sortList
);
3110 TREEVIEW_VerifyTree(infoPtr
);
3112 if (parent
->state
& TVIS_EXPANDED
)
3114 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3116 if (parent
== infoPtr
->root
)
3117 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3119 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3121 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3123 TREEVIEW_ITEM
*item
;
3125 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3126 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3128 if (item
->visibleOrder
== visOrder
)
3132 if (!item
) item
= parent
->firstChild
;
3133 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3136 TREEVIEW_Invalidate(infoPtr
, NULL
);
3145 /***************************************************************************
3146 * Setup the treeview structure with regards of the sort method
3147 * and sort the children of the TV item specified in lParam
3150 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, LPTVSORTCB pSort
)
3152 return TREEVIEW_Sort(infoPtr
, pSort
->hParent
, pSort
);
3156 /***************************************************************************
3157 * Sort the children of the TV item specified in lParam.
3160 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3162 return TREEVIEW_Sort(infoPtr
, (HTREEITEM
)lParam
, NULL
);
3166 /* Expansion/Collapse ***************************************************/
3169 TREEVIEW_SendExpanding(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3172 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3173 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3174 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3179 TREEVIEW_SendExpanded(const TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3182 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3183 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3184 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3189 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3190 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3192 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3193 BOOL bRemoveChildren
, BOOL bUser
)
3195 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3196 BOOL bSetSelection
, bSetFirstVisible
;
3198 LONG scrollDist
= 0;
3199 TREEVIEW_ITEM
*nextItem
= NULL
, *tmpItem
;
3201 TRACE("TVE_COLLAPSE %p %s\n", wineItem
, TREEVIEW_ItemName(wineItem
));
3203 if (!(wineItem
->state
& TVIS_EXPANDED
))
3206 if (bUser
|| !(wineItem
->state
& TVIS_EXPANDEDONCE
))
3207 TREEVIEW_SendExpanding(infoPtr
, wineItem
, action
);
3209 if (wineItem
->firstChild
== NULL
)
3212 wineItem
->state
&= ~TVIS_EXPANDED
;
3214 if (bUser
|| !(wineItem
->state
& TVIS_EXPANDEDONCE
))
3215 TREEVIEW_SendExpanded(infoPtr
, wineItem
, action
);
3217 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3218 && TREEVIEW_IsChildOf(wineItem
, infoPtr
->selectedItem
));
3220 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3221 && TREEVIEW_IsChildOf(wineItem
, infoPtr
->firstVisible
));
3226 if (tmpItem
->nextSibling
)
3228 nextItem
= tmpItem
->nextSibling
;
3231 tmpItem
= tmpItem
->parent
;
3235 scrollDist
= nextItem
->rect
.top
;
3237 if (bRemoveChildren
)
3239 INT old_cChildren
= wineItem
->cChildren
;
3240 TRACE("TVE_COLLAPSERESET\n");
3241 wineItem
->state
&= ~TVIS_EXPANDEDONCE
;
3242 TREEVIEW_RemoveAllChildren(infoPtr
, wineItem
);
3243 wineItem
->cChildren
= old_cChildren
;
3246 if (wineItem
->firstChild
)
3248 TREEVIEW_ITEM
*item
, *sibling
;
3250 sibling
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
3252 for (item
= wineItem
->firstChild
; item
!= sibling
;
3253 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3255 item
->visibleOrder
= -1;
3259 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
3262 scrollDist
= -(scrollDist
- nextItem
->rect
.top
);
3266 /* Don't call DoSelectItem, it sends notifications. */
3267 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3268 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3269 wineItem
->state
|= TVIS_SELECTED
;
3270 infoPtr
->selectedItem
= wineItem
;
3273 TREEVIEW_UpdateScrollBars(infoPtr
);
3275 scrollRect
.left
= 0;
3276 scrollRect
.right
= infoPtr
->clientWidth
;
3277 scrollRect
.bottom
= infoPtr
->clientHeight
;
3281 scrollRect
.top
= nextItem
->rect
.top
;
3283 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, &scrollRect
,
3284 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3285 TREEVIEW_Invalidate(infoPtr
, wineItem
);
3287 scrollRect
.top
= wineItem
->rect
.top
;
3288 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, TRUE
);
3291 TREEVIEW_SetFirstVisible(infoPtr
,
3292 bSetFirstVisible
? wineItem
: infoPtr
->firstVisible
,
3299 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3300 BOOL bExpandPartial
, BOOL bUser
)
3303 LONG orgNextTop
= 0;
3305 TREEVIEW_ITEM
*nextItem
, *tmpItem
;
3309 if (wineItem
->state
& TVIS_EXPANDED
)
3312 tmpItem
= wineItem
; nextItem
= NULL
;
3315 if (tmpItem
->nextSibling
)
3317 nextItem
= tmpItem
->nextSibling
;
3320 tmpItem
= tmpItem
->parent
;
3324 orgNextTop
= nextItem
->rect
.top
;
3326 TRACE("TVE_EXPAND %p %s\n", wineItem
, TREEVIEW_ItemName(wineItem
));
3328 if (bUser
|| ((wineItem
->cChildren
!= 0) &&
3329 !(wineItem
->state
& TVIS_EXPANDEDONCE
)))
3331 if (!TREEVIEW_SendExpanding(infoPtr
, wineItem
, TVE_EXPAND
))
3333 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3337 if (!wineItem
->firstChild
)
3340 wineItem
->state
|= TVIS_EXPANDED
;
3341 TREEVIEW_SendExpanded(infoPtr
, wineItem
, TVE_EXPAND
);
3342 wineItem
->state
|= TVIS_EXPANDEDONCE
;
3346 if (!wineItem
->firstChild
)
3349 /* this item has already been expanded */
3350 wineItem
->state
|= TVIS_EXPANDED
;
3354 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3356 if (ISVISIBLE(wineItem
))
3358 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
3359 TREEVIEW_UpdateSubTree(infoPtr
, wineItem
);
3360 TREEVIEW_UpdateScrollBars(infoPtr
);
3362 scrollRect
.left
= 0;
3363 scrollRect
.bottom
= infoPtr
->treeHeight
;
3364 scrollRect
.right
= infoPtr
->clientWidth
;
3367 scrollDist
= nextItem
->rect
.top
- orgNextTop
;
3368 scrollRect
.top
= orgNextTop
;
3370 ScrollWindowEx (infoPtr
->hwnd
, 0, scrollDist
, &scrollRect
, NULL
,
3371 NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
3372 TREEVIEW_Invalidate (infoPtr
, wineItem
);
3374 scrollRect
.top
= wineItem
->rect
.top
;
3375 InvalidateRect(infoPtr
->hwnd
, &scrollRect
, FALSE
);
3378 /* Scroll up so that as many children as possible are visible.
3379 * This fails when expanding causes an HScroll bar to appear, but we
3380 * don't know that yet, so the last item is obscured. */
3381 if (wineItem
->firstChild
!= NULL
)
3383 int nChildren
= wineItem
->lastChild
->visibleOrder
3384 - wineItem
->firstChild
->visibleOrder
+ 1;
3386 int visible_pos
= wineItem
->visibleOrder
3387 - infoPtr
->firstVisible
->visibleOrder
;
3389 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3391 if (visible_pos
> 0 && nChildren
> rows_below
)
3393 int scroll
= nChildren
- rows_below
;
3395 if (scroll
> visible_pos
)
3396 scroll
= visible_pos
;
3400 TREEVIEW_ITEM
*newFirstVisible
3401 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3405 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3415 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
, BOOL bUser
)
3419 if (wineItem
->state
& TVIS_EXPANDED
)
3420 return TREEVIEW_Collapse(infoPtr
, wineItem
, FALSE
, bUser
);
3422 return TREEVIEW_Expand(infoPtr
, wineItem
, FALSE
, bUser
);
3426 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3428 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3430 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3432 if (TREEVIEW_HasChildren(infoPtr
, item
))
3433 TREEVIEW_ExpandAll(infoPtr
, item
);
3437 /* Note:If the specified item is the child of a collapsed parent item,
3438 the parent's list of child items is (recursively) expanded to reveal the
3439 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3440 know if it also applies here.
3444 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM wineItem
)
3446 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
3449 TRACE("For (%s) item:%d, flags %x, state:%d\n",
3450 TREEVIEW_ItemName(wineItem
), flag
,
3451 TREEVIEW_GetItemIndex(infoPtr
, wineItem
), wineItem
->state
);
3453 switch (flag
& TVE_TOGGLE
)
3456 return TREEVIEW_Collapse(infoPtr
, wineItem
, flag
& TVE_COLLAPSERESET
,
3460 return TREEVIEW_Expand(infoPtr
, wineItem
, flag
& TVE_EXPANDPARTIAL
,
3464 return TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3471 TRACE("Exiting, Item %p state is now %d...\n", wineItem
, wineItem
->state
);
3475 /* Hit-Testing **********************************************************/
3477 static TREEVIEW_ITEM
*
3478 TREEVIEW_HitTestPoint(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3480 TREEVIEW_ITEM
*wineItem
;
3483 if (!infoPtr
->firstVisible
)
3486 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3488 for (wineItem
= infoPtr
->firstVisible
; wineItem
!= NULL
;
3489 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
))
3491 if (row
>= wineItem
->visibleOrder
3492 && row
< wineItem
->visibleOrder
+ wineItem
->iIntegral
)
3500 TREEVIEW_HitTest(const TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3502 TREEVIEW_ITEM
*wineItem
;
3508 GetClientRect(infoPtr
->hwnd
, &rect
);
3515 status
|= TVHT_TOLEFT
;
3517 else if (x
> rect
.right
)
3519 status
|= TVHT_TORIGHT
;
3524 status
|= TVHT_ABOVE
;
3526 else if (y
> rect
.bottom
)
3528 status
|= TVHT_BELOW
;
3533 lpht
->flags
= status
;
3537 wineItem
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3540 lpht
->flags
= TVHT_NOWHERE
;
3544 if (x
>= wineItem
->textOffset
+ wineItem
->textWidth
)
3546 lpht
->flags
= TVHT_ONITEMRIGHT
;
3548 else if (x
>= wineItem
->textOffset
)
3550 lpht
->flags
= TVHT_ONITEMLABEL
;
3552 else if (x
>= wineItem
->imageOffset
)
3554 lpht
->flags
= TVHT_ONITEMICON
;
3556 else if (x
>= wineItem
->stateOffset
)
3558 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3560 else if (x
>= wineItem
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3562 lpht
->flags
= TVHT_ONITEMBUTTON
;
3566 lpht
->flags
= TVHT_ONITEMINDENT
;
3569 lpht
->hItem
= wineItem
;
3570 TRACE("(%d,%d):result %x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3572 return (LRESULT
)wineItem
;
3575 /* Item Label Editing ***************************************************/
3578 TREEVIEW_GetEditControl(const TREEVIEW_INFO
*infoPtr
)
3580 return (LRESULT
)infoPtr
->hwndEdit
;
3583 static LRESULT CALLBACK
3584 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3586 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3587 BOOL bCancel
= FALSE
;
3593 TRACE("WM_PAINT start\n");
3594 rc
= CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3596 TRACE("WM_PAINT done\n");
3600 if (infoPtr
->bIgnoreEditKillFocus
)
3606 WNDPROC editProc
= infoPtr
->wpEditOrig
;
3607 infoPtr
->wpEditOrig
= 0;
3608 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
3609 return CallWindowProcW(editProc
, hwnd
, uMsg
, wParam
, lParam
);
3613 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3616 if (wParam
== VK_ESCAPE
)
3621 else if (wParam
== VK_RETURN
)
3628 return CallWindowProcW(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3631 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3632 /* eg. Using a messagebox */
3634 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3635 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3636 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3642 /* should handle edit control messages here */
3645 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3647 TRACE("code=%x, id=%x, handle=%lx\n", HIWORD(wParam
), LOWORD(wParam
), lParam
);
3649 switch (HIWORD(wParam
))
3654 * Adjust the edit window size
3657 TREEVIEW_ITEM
*editItem
= infoPtr
->editItem
;
3658 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3660 HFONT hFont
, hOldFont
= 0;
3662 TRACE("edit=%p\n", infoPtr
->hwndEdit
);
3664 if (!IsWindow(infoPtr
->hwndEdit
) || !hdc
) return FALSE
;
3666 infoPtr
->bLabelChanged
= TRUE
;
3668 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
3670 /* Select font to get the right dimension of the string */
3671 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3675 hOldFont
= SelectObject(hdc
, hFont
);
3678 if (GetTextExtentPoint32W(hdc
, buffer
, strlenW(buffer
), &sz
))
3680 TEXTMETRICW textMetric
;
3682 /* Add Extra spacing for the next character */
3683 GetTextMetricsW(hdc
, &textMetric
);
3684 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3686 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3688 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3690 SetWindowPos(infoPtr
->hwndEdit
,
3695 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3696 SWP_NOMOVE
| SWP_DRAWFRAME
);
3701 SelectObject(hdc
, hOldFont
);
3704 ReleaseDC(infoPtr
->hwnd
, hdc
);
3708 /* apparently we should respect passed handle value */
3709 if (infoPtr
->hwndEdit
!= (HWND
)lParam
) return FALSE
;
3711 TREEVIEW_EndEditLabelNow(infoPtr
, FALSE
);
3715 return SendMessageW(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3722 TREEVIEW_EditLabel(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3724 HWND hwnd
= infoPtr
->hwnd
;
3727 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(hwnd
, GWLP_HINSTANCE
);
3730 TEXTMETRICW textMetric
;
3732 TRACE("%p %p\n", hwnd
, hItem
);
3733 if (!TREEVIEW_ValidItem(infoPtr
, hItem
))
3736 if (infoPtr
->hwndEdit
)
3737 return infoPtr
->hwndEdit
;
3739 infoPtr
->bLabelChanged
= FALSE
;
3741 /* make edit item visible */
3742 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3744 TREEVIEW_UpdateDispInfo(infoPtr
, hItem
, TVIF_TEXT
);
3747 /* Select the font to get appropriate metric dimensions */
3748 if (infoPtr
->hFont
!= 0)
3750 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3753 /* Get string length in pixels */
3755 GetTextExtentPoint32W(hdc
, hItem
->pszText
, strlenW(hItem
->pszText
),
3758 GetTextExtentPoint32A(hdc
, "", 0, &sz
);
3760 /* Add Extra spacing for the next character */
3761 GetTextMetricsW(hdc
, &textMetric
);
3762 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3764 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3765 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- hItem
->textOffset
+ 2);
3767 if (infoPtr
->hFont
!= 0)
3769 SelectObject(hdc
, hOldFont
);
3772 ReleaseDC(hwnd
, hdc
);
3774 infoPtr
->editItem
= hItem
;
3776 hwndEdit
= CreateWindowExW(WS_EX_LEFT
,
3779 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3780 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3781 ES_LEFT
, hItem
->textOffset
- 2,
3782 hItem
->rect
.top
- 1, sz
.cx
+ 3,
3783 hItem
->rect
.bottom
-
3784 hItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3785 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3787 infoPtr
->hwndEdit
= hwndEdit
;
3789 /* Get a 2D border. */
3790 SetWindowLongW(hwndEdit
, GWL_EXSTYLE
,
3791 GetWindowLongW(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3792 SetWindowLongW(hwndEdit
, GWL_STYLE
,
3793 GetWindowLongW(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3795 SendMessageW(hwndEdit
, WM_SETFONT
,
3796 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, hItem
), FALSE
);
3798 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
,
3800 TREEVIEW_Edit_SubclassProc
);
3802 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, hItem
))
3804 DestroyWindow(hwndEdit
);
3805 infoPtr
->hwndEdit
= 0;
3806 infoPtr
->editItem
= NULL
;
3811 SetWindowTextW(hwndEdit
, hItem
->pszText
);
3814 SendMessageW(hwndEdit
, EM_SETSEL
, 0, -1);
3815 ShowWindow(hwndEdit
, SW_SHOW
);
3822 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3824 HWND hwnd
= infoPtr
->hwnd
;
3825 TREEVIEW_ITEM
*editedItem
= infoPtr
->editItem
;
3828 WCHAR tmpText
[1024] = { '\0' };
3829 WCHAR
*newText
= tmpText
;
3832 if (!IsWindow(infoPtr
->hwndEdit
)) return FALSE
;
3834 tvdi
.hdr
.hwndFrom
= hwnd
;
3835 tvdi
.hdr
.idFrom
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
3836 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_ENDLABELEDITW
);
3838 tvdi
.item
.hItem
= editedItem
;
3839 tvdi
.item
.state
= editedItem
->state
;
3840 tvdi
.item
.lParam
= editedItem
->lParam
;
3844 if (!infoPtr
->bNtfUnicode
)
3845 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, (LPSTR
)tmpText
, 1023);
3847 iLength
= GetWindowTextW(infoPtr
->hwndEdit
, tmpText
, 1023);
3849 if (iLength
>= 1023)
3851 ERR("Insufficient space to retrieve new item label\n");
3854 tvdi
.item
.mask
= TVIF_TEXT
;
3855 tvdi
.item
.pszText
= tmpText
;
3856 tvdi
.item
.cchTextMax
= iLength
+ 1;
3860 tvdi
.item
.pszText
= NULL
;
3861 tvdi
.item
.cchTextMax
= 0;
3864 bCommit
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
, tvdi
.hdr
.idFrom
, (LPARAM
)&tvdi
);
3866 if (!bCancel
&& bCommit
) /* Apply the changes */
3868 if (!infoPtr
->bNtfUnicode
)
3870 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, NULL
, 0 );
3871 newText
= Alloc(len
* sizeof(WCHAR
));
3872 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)tmpText
, -1, newText
, len
);
3876 if (strcmpW(newText
, editedItem
->pszText
) != 0)
3878 WCHAR
*ptr
= ReAlloc(editedItem
->pszText
, sizeof(WCHAR
)*(iLength
+ 1));
3881 ERR("OutOfMemory, cannot allocate space for label\n");
3882 if(newText
!= tmpText
) Free(newText
);
3883 DestroyWindow(infoPtr
->hwndEdit
);
3884 infoPtr
->hwndEdit
= 0;
3885 infoPtr
->editItem
= NULL
;
3890 editedItem
->pszText
= ptr
;
3891 editedItem
->cchTextMax
= iLength
+ 1;
3892 strcpyW(editedItem
->pszText
, newText
);
3893 TREEVIEW_ComputeTextWidth(infoPtr
, editedItem
, 0);
3896 if(newText
!= tmpText
) Free(newText
);
3899 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
3900 DestroyWindow(infoPtr
->hwndEdit
);
3901 infoPtr
->hwndEdit
= 0;
3902 infoPtr
->editItem
= NULL
;
3907 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
3909 if (wParam
!= TV_EDIT_TIMER
)
3911 ERR("got unknown timer\n");
3915 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
3916 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
3918 TREEVIEW_EditLabel(infoPtr
, infoPtr
->selectedItem
);
3924 /* Mouse Tracking/Drag **************************************************/
3926 /***************************************************************************
3927 * This is quite unusual piece of code, but that's how it's implemented in
3931 TREEVIEW_TrackMouse(const TREEVIEW_INFO
*infoPtr
, POINT pt
)
3933 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
3934 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
3938 r
.top
= pt
.y
- cyDrag
;
3939 r
.left
= pt
.x
- cxDrag
;
3940 r
.bottom
= pt
.y
+ cyDrag
;
3941 r
.right
= pt
.x
+ cxDrag
;
3943 SetCapture(infoPtr
->hwnd
);
3947 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
3949 if (msg
.message
== WM_MOUSEMOVE
)
3951 pt
.x
= (short)LOWORD(msg
.lParam
);
3952 pt
.y
= (short)HIWORD(msg
.lParam
);
3953 if (PtInRect(&r
, pt
))
3961 else if (msg
.message
>= WM_LBUTTONDOWN
&&
3962 msg
.message
<= WM_RBUTTONDBLCLK
)
3964 if (msg
.message
== WM_RBUTTONUP
)
3965 TREEVIEW_RButtonUp(infoPtr
, &pt
);
3969 DispatchMessageW(&msg
);
3972 if (GetCapture() != infoPtr
->hwnd
)
3982 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3984 TREEVIEW_ITEM
*wineItem
;
3988 SetFocus(infoPtr
->hwnd
);
3990 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
3992 /* If there is pending 'edit label' event - kill it now */
3993 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
3996 hit
.pt
.x
= (short)LOWORD(lParam
);
3997 hit
.pt
.y
= (short)HIWORD(lParam
);
3999 wineItem
= (TREEVIEW_ITEM
*)TREEVIEW_HitTest(infoPtr
, &hit
);
4002 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, wineItem
));
4004 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
4008 case TVHT_ONITEMRIGHT
:
4009 /* FIXME: we should not have sent NM_DBLCLK in this case. */
4012 case TVHT_ONITEMINDENT
:
4013 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
4019 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
4020 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
4022 while (wineItem
->iLevel
> level
)
4024 wineItem
= wineItem
->parent
;
4030 case TVHT_ONITEMLABEL
:
4031 case TVHT_ONITEMICON
:
4032 case TVHT_ONITEMBUTTON
:
4033 TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
4036 case TVHT_ONITEMSTATEICON
:
4037 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4038 TREEVIEW_ToggleItemState(infoPtr
, wineItem
);
4040 TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
4049 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4051 HWND hwnd
= infoPtr
->hwnd
;
4053 BOOL bTrack
, bDoLabelEdit
;
4055 /* If Edit control is active - kill it and return.
4056 * The best way to do it is to set focus to itself.
4057 * Edit control subclassed procedure will automatically call
4060 if (infoPtr
->hwndEdit
)
4066 ht
.pt
.x
= (short)LOWORD(lParam
);
4067 ht
.pt
.y
= (short)HIWORD(lParam
);
4069 TREEVIEW_HitTest(infoPtr
, &ht
);
4070 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
4072 /* update focusedItem and redraw both items */
4073 if(ht
.hItem
&& (ht
.flags
& TVHT_ONITEM
))
4075 infoPtr
->focusedItem
= ht
.hItem
;
4076 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4077 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4080 bTrack
= (ht
.flags
& TVHT_ONITEM
)
4081 && !(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
);
4084 * If the style allows editing and the node is already selected
4085 * and the click occurred on the item label...
4087 bDoLabelEdit
= (infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
4088 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
);
4090 /* Send NM_CLICK right away */
4092 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4095 if (ht
.flags
& TVHT_ONITEMBUTTON
)
4097 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
4101 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
4102 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4104 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
4105 infoPtr
->dropItem
= ht
.hItem
;
4107 /* clean up focusedItem as we dragged and won't select this item */
4108 if(infoPtr
->focusedItem
)
4110 /* refresh the item that was focused */
4111 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4112 infoPtr
->focusedItem
= NULL
;
4114 /* refresh the selected item to return the filled background */
4115 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->selectedItem
);
4122 if (bTrack
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
4127 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
4128 KillTimer(hwnd
, TV_EDIT_TIMER
);
4130 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
4131 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
4133 else if (ht
.flags
& (TVHT_ONITEMICON
|TVHT_ONITEMLABEL
)) /* select the item if the hit was inside of the icon or text */
4136 * if we are TVS_SINGLEEXPAND then we want this single click to
4137 * do a bunch of things.
4139 if((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) &&
4140 (infoPtr
->hwndEdit
== 0))
4142 TREEVIEW_ITEM
*SelItem
;
4145 * Send the notification
4147 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, ht
.hItem
, 0);
4150 * Close the previous selection all the way to the root
4151 * as long as the new selection is not a child
4153 if((infoPtr
->selectedItem
)
4154 && (infoPtr
->selectedItem
!= ht
.hItem
))
4156 BOOL closeit
= TRUE
;
4159 /* determine if the hitItem is a child of the currently selected item */
4160 while(closeit
&& SelItem
&& TREEVIEW_ValidItem(infoPtr
, SelItem
) && (SelItem
!= infoPtr
->root
))
4162 closeit
= (SelItem
!= infoPtr
->selectedItem
);
4163 SelItem
= SelItem
->parent
;
4168 if(TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
4169 SelItem
= infoPtr
->selectedItem
;
4171 while(SelItem
&& (SelItem
!= ht
.hItem
) && TREEVIEW_ValidItem(infoPtr
, SelItem
) && (SelItem
!= infoPtr
->root
))
4173 TREEVIEW_Collapse(infoPtr
, SelItem
, FALSE
, FALSE
);
4174 SelItem
= SelItem
->parent
;
4180 * Expand the current item
4182 TREEVIEW_Expand(infoPtr
, ht
.hItem
, TVE_TOGGLE
, FALSE
);
4185 /* Select the current item */
4186 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4188 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4190 /* TVS_CHECKBOXES requires us to toggle the current state */
4191 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4192 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4202 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4206 if (infoPtr
->hwndEdit
)
4208 SetFocus(infoPtr
->hwnd
);
4212 ht
.pt
.x
= (short)LOWORD(lParam
);
4213 ht
.pt
.y
= (short)HIWORD(lParam
);
4215 TREEVIEW_HitTest(infoPtr
, &ht
);
4217 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4221 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4222 infoPtr
->dropItem
= ht
.hItem
;
4227 SetFocus(infoPtr
->hwnd
);
4228 TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
);
4235 TREEVIEW_RButtonUp(const TREEVIEW_INFO
*infoPtr
, const POINT
*pPt
)
4241 TREEVIEW_HitTest(infoPtr
, &ht
);
4245 /* Change to screen coordinate for WM_CONTEXTMENU */
4246 ClientToScreen(infoPtr
->hwnd
, &ht
.pt
);
4248 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
4249 SendMessageW(infoPtr
->hwnd
, WM_CONTEXTMENU
,
4250 (WPARAM
)infoPtr
->hwnd
, MAKELPARAM(ht
.pt
.x
, ht
.pt
.y
));
4257 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4259 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4263 HBITMAP hbmp
, hOldbmp
;
4270 if (!(infoPtr
->himlNormal
))
4273 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4276 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4278 hwtop
= GetDesktopWindow();
4279 htopdc
= GetDC(hwtop
);
4280 hdc
= CreateCompatibleDC(htopdc
);
4282 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4284 if (dragItem
->pszText
)
4285 GetTextExtentPoint32W(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
),
4288 GetTextExtentPoint32A(hdc
, "", 0, &size
);
4290 TRACE("%d %d %s\n", size
.cx
, size
.cy
, debugstr_w(dragItem
->pszText
));
4291 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4292 hOldbmp
= SelectObject(hdc
, hbmp
);
4294 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4299 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4300 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4304 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4305 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4308 /* draw item text */
4310 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4312 if (dragItem
->pszText
)
4313 DrawTextW(hdc
, dragItem
->pszText
, strlenW(dragItem
->pszText
), &rc
,
4316 SelectObject(hdc
, hOldFont
);
4317 SelectObject(hdc
, hOldbmp
);
4319 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4323 ReleaseDC(hwtop
, htopdc
);
4325 return (LRESULT
)infoPtr
->dragList
;
4328 /* Selection ************************************************************/
4331 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4334 TREEVIEW_ITEM
*prevSelect
;
4336 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4338 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4339 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4340 newSelect
? newSelect
->state
: 0);
4342 /* reset and redraw focusedItem if focusedItem was set so we don't */
4343 /* have to worry about the previously focused item when we set a new one */
4344 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->focusedItem
);
4345 infoPtr
->focusedItem
= NULL
;
4350 prevSelect
= infoPtr
->selectedItem
;
4352 if (prevSelect
== newSelect
) {
4353 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4357 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4360 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4366 prevSelect
->state
&= ~TVIS_SELECTED
;
4368 newSelect
->state
|= TVIS_SELECTED
;
4370 infoPtr
->selectedItem
= newSelect
;
4372 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4374 TREEVIEW_InvalidateItem(infoPtr
, prevSelect
);
4375 TREEVIEW_InvalidateItem(infoPtr
, newSelect
);
4377 TREEVIEW_SendTreeviewNotify(infoPtr
,
4380 TVIF_TEXT
| TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4385 case TVGN_DROPHILITE
:
4386 prevSelect
= infoPtr
->dropItem
;
4389 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4391 infoPtr
->dropItem
= newSelect
;
4394 newSelect
->state
|= TVIS_DROPHILITED
;
4396 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4397 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4400 case TVGN_FIRSTVISIBLE
:
4401 if (newSelect
!= NULL
)
4403 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4404 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4405 TREEVIEW_Invalidate(infoPtr
, NULL
);
4410 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4414 /* FIXME: handle NM_KILLFOCUS etc */
4416 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4418 if (item
!= NULL
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4421 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4423 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4429 /*************************************************************************
4430 * TREEVIEW_ProcessLetterKeys
4432 * Processes keyboard messages generated by pressing the letter keys
4434 * What this does is perform a case insensitive search from the
4435 * current position with the following quirks:
4436 * - If two chars or more are pressed in quick succession we search
4437 * for the corresponding string (e.g. 'abc').
4438 * - If there is a delay we wipe away the current search string and
4439 * restart with just that char.
4440 * - If the user keeps pressing the same character, whether slowly or
4441 * fast, so that the search string is entirely composed of this
4442 * character ('aaaaa' for instance), then we search for first item
4443 * that starting with that character.
4444 * - If the user types the above character in quick succession, then
4445 * we must also search for the corresponding string ('aaaaa'), and
4446 * go to that string if there is a match.
4454 * - The current implementation has a list of characters it will
4455 * accept and it ignores everything else. In particular it will
4456 * ignore accentuated characters which seems to match what
4457 * Windows does. But I'm not sure it makes sense to follow
4459 * - We don't sound a beep when the search fails.
4460 * - The search should start from the focused item, not from the selected
4461 * item. One reason for this is to allow for multiple selections in trees.
4462 * But currently infoPtr->focusedItem does not seem very usable.
4466 * TREEVIEW_ProcessLetterKeys
4468 static INT
TREEVIEW_ProcessLetterKeys(TREEVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
4471 HTREEITEM endidx
,idx
;
4473 WCHAR buffer
[MAX_PATH
];
4474 DWORD timestamp
,elapsed
;
4476 /* simple parameter checking */
4477 if (!charCode
|| !keyData
) return 0;
4479 /* only allow the valid WM_CHARs through */
4480 if (!isalnum(charCode
) &&
4481 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4482 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4483 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4484 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4485 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4486 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4487 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4488 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4489 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4492 /* compute how much time elapsed since last keypress */
4493 timestamp
= GetTickCount();
4494 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4495 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4497 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4500 /* update the search parameters */
4501 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4502 if (elapsed
< KEY_DELAY
) {
4503 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
) / sizeof(WCHAR
)) {
4504 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4506 if (infoPtr
->charCode
!= charCode
) {
4507 infoPtr
->charCode
=charCode
=0;
4510 infoPtr
->charCode
=charCode
;
4511 infoPtr
->szSearchParam
[0]=charCode
;
4512 infoPtr
->nSearchParamLength
=1;
4513 /* Redundant with the 1 char string */
4517 /* and search from the current position */
4519 if (infoPtr
->selectedItem
!= NULL
) {
4520 endidx
=infoPtr
->selectedItem
;
4521 /* if looking for single character match,
4522 * then we must always move forward
4524 if (infoPtr
->nSearchParamLength
== 1)
4525 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4530 idx
=infoPtr
->root
->firstChild
;
4533 /* At the end point, sort out wrapping */
4536 /* If endidx is null, stop at the last item (ie top to bottom) */
4540 /* Otherwise, start again at the very beginning */
4541 idx
=infoPtr
->root
->firstChild
;
4543 /* But if we are stopping on the first child, end now! */
4544 if (idx
== endidx
) break;
4548 ZeroMemory(&item
, sizeof(item
));
4549 item
.mask
= TVIF_TEXT
;
4551 item
.pszText
= buffer
;
4552 item
.cchTextMax
= sizeof(buffer
);
4553 TREEVIEW_GetItemT( infoPtr
, &item
, TRUE
);
4555 /* check for a match */
4556 if (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4559 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4560 (nItem
!= infoPtr
->selectedItem
) &&
4561 (strncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4562 /* This would work but we must keep looking for a longer match */
4565 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4566 } while (idx
!= endidx
);
4568 if (nItem
!= NULL
) {
4569 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4570 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4577 /* Scrolling ************************************************************/
4580 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4583 BOOL hasFirstVisible
= infoPtr
->firstVisible
!= NULL
;
4584 HTREEITEM newFirstVisible
= NULL
;
4585 int visible_pos
= -1;
4587 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4590 if (!ISVISIBLE(item
))
4592 /* Expand parents as necessary. */
4595 /* see if we are trying to ensure that root is visible */
4596 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4597 parent
= item
->parent
;
4599 parent
= item
; /* this item is the topmost item */
4601 while (parent
!= infoPtr
->root
)
4603 if (!(parent
->state
& TVIS_EXPANDED
))
4604 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, FALSE
);
4606 parent
= parent
->parent
;
4610 viscount
= TREEVIEW_GetVisibleCount(infoPtr
);
4612 TRACE("%p (%s) %d - %d viscount(%d)\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4613 hasFirstVisible
? infoPtr
->firstVisible
->visibleOrder
: -1, viscount
);
4615 if (hasFirstVisible
)
4616 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4618 if (visible_pos
< 0)
4620 /* item is before the start of the list: put it at the top. */
4621 newFirstVisible
= item
;
4623 else if (visible_pos
>= viscount
4624 /* Sometimes, before we are displayed, GVC is 0, causing us to
4625 * spuriously scroll up. */
4626 && visible_pos
> 0 && !(infoPtr
->dwStyle
& TVS_NOSCROLL
) )
4628 /* item is past the end of the list. */
4629 int scroll
= visible_pos
- viscount
;
4631 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4637 /* Scroll window so item's text is visible as much as possible */
4638 /* Calculation of amount of extra space is taken from EditLabel code */
4640 TEXTMETRICW textMetric
;
4641 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4643 x
= item
->textWidth
;
4645 GetTextMetricsW(hdc
, &textMetric
);
4646 ReleaseDC(infoPtr
->hwnd
, hdc
);
4648 x
+= (textMetric
.tmMaxCharWidth
* 2);
4649 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4651 if (item
->textOffset
< 0)
4652 pos
= item
->textOffset
;
4653 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4655 if (x
> infoPtr
->clientWidth
)
4656 pos
= item
->textOffset
;
4658 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4663 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4666 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4668 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4677 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4678 TREEVIEW_ITEM
*newFirstVisible
,
4679 BOOL bUpdateScrollPos
)
4683 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4685 if (newFirstVisible
!= NULL
)
4687 /* Prevent an empty gap from appearing at the bottom... */
4688 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4689 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4693 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4696 /* ... unless we just don't have enough items. */
4697 if (newFirstVisible
== NULL
)
4698 newFirstVisible
= infoPtr
->root
->firstChild
;
4702 if (infoPtr
->firstVisible
!= newFirstVisible
)
4704 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4706 infoPtr
->firstVisible
= newFirstVisible
;
4707 TREEVIEW_Invalidate(infoPtr
, NULL
);
4711 TREEVIEW_ITEM
*item
;
4712 int scroll
= infoPtr
->uItemHeight
*
4713 (infoPtr
->firstVisible
->visibleOrder
4714 - newFirstVisible
->visibleOrder
);
4716 infoPtr
->firstVisible
= newFirstVisible
;
4718 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4719 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4721 item
->rect
.top
+= scroll
;
4722 item
->rect
.bottom
+= scroll
;
4725 if (bUpdateScrollPos
)
4726 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4727 newFirstVisible
->visibleOrder
, TRUE
);
4729 ScrollWindowEx(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
, NULL
, NULL
, SW_ERASE
| SW_INVALIDATE
);
4734 /************************************************************************
4735 * VScroll is always in units of visible items. i.e. we always have a
4736 * visible item aligned to the top of the control. (Unless we have no
4740 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4742 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4743 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4745 int nScrollCode
= LOWORD(wParam
);
4747 TRACE("wp %lx\n", wParam
);
4749 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4752 if (!oldFirstVisible
)
4754 assert(infoPtr
->root
->firstChild
== NULL
);
4758 switch (nScrollCode
)
4761 newFirstVisible
= infoPtr
->root
->firstChild
;
4765 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4769 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4773 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4777 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4778 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4782 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4783 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4787 case SB_THUMBPOSITION
:
4788 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4789 infoPtr
->root
->firstChild
,
4790 (LONG
)(SHORT
)HIWORD(wParam
));
4797 if (newFirstVisible
!= NULL
)
4799 if (newFirstVisible
!= oldFirstVisible
)
4800 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4801 nScrollCode
!= SB_THUMBTRACK
);
4802 else if (nScrollCode
== SB_THUMBPOSITION
)
4803 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4804 newFirstVisible
->visibleOrder
, TRUE
);
4811 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4814 int scrollX
= infoPtr
->scrollX
;
4815 int nScrollCode
= LOWORD(wParam
);
4817 TRACE("wp %lx\n", wParam
);
4819 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4822 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4823 /* shall never occur */
4830 switch (nScrollCode
)
4833 scrollX
-= infoPtr
->uItemHeight
;
4836 scrollX
+= infoPtr
->uItemHeight
;
4839 scrollX
-= infoPtr
->clientWidth
;
4842 scrollX
+= infoPtr
->clientWidth
;
4846 case SB_THUMBPOSITION
:
4847 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4854 if (scrollX
> maxWidth
)
4856 else if (scrollX
< 0)
4860 if (scrollX
!= infoPtr
->scrollX
)
4862 TREEVIEW_ITEM
*item
;
4863 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4865 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4866 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4868 item
->linesOffset
+= scroll_pixels
;
4869 item
->stateOffset
+= scroll_pixels
;
4870 item
->imageOffset
+= scroll_pixels
;
4871 item
->textOffset
+= scroll_pixels
;
4874 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4875 infoPtr
->scrollX
= scrollX
;
4876 UpdateWindow(infoPtr
->hwnd
);
4879 if (nScrollCode
!= SB_THUMBTRACK
)
4880 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
4886 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4889 UINT pulScrollLines
= 3;
4891 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4892 return DefWindowProcW(infoPtr
->hwnd
, WM_MOUSEWHEEL
, wParam
, lParam
);
4894 if (infoPtr
->firstVisible
== NULL
)
4897 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
4899 gcWheelDelta
= -(short)HIWORD(wParam
);
4900 pulScrollLines
*= (gcWheelDelta
/ WHEEL_DELTA
);
4902 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
4904 int newDy
= infoPtr
->firstVisible
->visibleOrder
+ pulScrollLines
;
4905 int maxDy
= infoPtr
->maxVisibleOrder
;
4913 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
4918 /* Create/Destroy *******************************************************/
4921 initialize_checkboxes(TREEVIEW_INFO
*infoPtr
)
4924 HBITMAP hbm
, hbmOld
;
4928 infoPtr
->himlState
= ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
4930 hdcScreen
= GetDC(0);
4932 hdc
= CreateCompatibleDC(hdcScreen
);
4933 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
4934 hbmOld
= SelectObject(hdc
, hbm
);
4936 SetRect(&rc
, 0, 0, 48, 16);
4937 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
4939 SetRect(&rc
, 18, 2, 30, 14);
4940 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4941 DFCS_BUTTONCHECK
|DFCS_FLAT
);
4943 SetRect(&rc
, 34, 2, 46, 14);
4944 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4945 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
4947 SelectObject(hdc
, hbmOld
);
4948 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
4949 comctl32_color
.clrWindow
);
4950 TRACE("checkbox index %d\n", nIndex
);
4954 ReleaseDC(0, hdcScreen
);
4956 infoPtr
->stateImageWidth
= 16;
4957 infoPtr
->stateImageHeight
= 16;
4961 TREEVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
4964 TREEVIEW_INFO
*infoPtr
;
4967 TRACE("wnd %p, style %x\n", hwnd
, GetWindowLongW(hwnd
, GWL_STYLE
));
4969 infoPtr
= Alloc(sizeof(TREEVIEW_INFO
));
4971 if (infoPtr
== NULL
)
4973 ERR("could not allocate info memory!\n");
4977 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
4979 infoPtr
->hwnd
= hwnd
;
4980 infoPtr
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
4982 infoPtr
->uNumItems
= 0;
4983 infoPtr
->cdmode
= 0;
4984 infoPtr
->uScrollTime
= 300; /* milliseconds */
4985 infoPtr
->bRedraw
= TRUE
;
4987 GetClientRect(hwnd
, &rcClient
);
4989 /* No scroll bars yet. */
4990 infoPtr
->clientWidth
= rcClient
.right
;
4991 infoPtr
->clientHeight
= rcClient
.bottom
;
4992 infoPtr
->uInternalStatus
= 0;
4994 infoPtr
->treeWidth
= 0;
4995 infoPtr
->treeHeight
= 0;
4997 infoPtr
->uIndent
= MINIMUM_INDENT
;
4998 infoPtr
->selectedItem
= NULL
;
4999 infoPtr
->focusedItem
= NULL
;
5000 infoPtr
->hotItem
= NULL
;
5001 infoPtr
->editItem
= NULL
;
5002 infoPtr
->firstVisible
= NULL
;
5003 infoPtr
->maxVisibleOrder
= 0;
5004 infoPtr
->dropItem
= NULL
;
5005 infoPtr
->insertMarkItem
= NULL
;
5006 infoPtr
->insertBeforeorAfter
= 0;
5009 infoPtr
->scrollX
= 0;
5011 infoPtr
->clrBk
= CLR_NONE
; /* use system color */
5012 infoPtr
->clrText
= CLR_NONE
; /* use system color */
5013 infoPtr
->clrLine
= CLR_DEFAULT
;
5014 infoPtr
->clrInsertMark
= CLR_DEFAULT
;
5018 infoPtr
->hwndEdit
= NULL
;
5019 infoPtr
->wpEditOrig
= NULL
;
5020 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
5021 infoPtr
->bLabelChanged
= FALSE
;
5023 infoPtr
->himlNormal
= NULL
;
5024 infoPtr
->himlState
= NULL
;
5025 infoPtr
->normalImageWidth
= 0;
5026 infoPtr
->normalImageHeight
= 0;
5027 infoPtr
->stateImageWidth
= 0;
5028 infoPtr
->stateImageHeight
= 0;
5030 infoPtr
->items
= DPA_Create(16);
5032 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(lf
), &lf
, 0);
5033 infoPtr
->hFont
= infoPtr
->hDefaultFont
= CreateFontIndirectW(&lf
);
5034 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
5035 infoPtr
->hUnderlineFont
= TREEVIEW_CreateUnderlineFont(infoPtr
->hFont
);
5036 infoPtr
->hcurHand
= LoadCursorW(NULL
, (LPWSTR
)IDC_HAND
);
5038 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
5040 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
5041 infoPtr
->root
->state
= TVIS_EXPANDED
;
5042 infoPtr
->root
->iLevel
= -1;
5043 infoPtr
->root
->visibleOrder
= -1;
5045 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
5047 infoPtr
->bTransparent
= ( GetWindowLongW( hwnd
, GWL_STYLE
) & TBSTYLE_FLAT
);
5050 infoPtr
->hwndToolTip
= 0;
5052 infoPtr
->bNtfUnicode
= IsWindowUnicode (hwnd
);
5054 /* Determine what type of notify should be issued */
5055 /* sets infoPtr->bNtfUnicode */
5056 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
5058 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
5059 infoPtr
->hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
5060 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
5063 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5064 initialize_checkboxes(infoPtr
);
5066 /* Make sure actual scrollbar state is consistent with uInternalStatus */
5067 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
5068 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
5070 OpenThemeData (hwnd
, themeClass
);
5077 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
5081 /* free item data */
5082 TREEVIEW_RemoveTree(infoPtr
);
5083 /* root isn't freed with other items */
5084 TREEVIEW_FreeItem(infoPtr
, infoPtr
->root
);
5085 DPA_Destroy(infoPtr
->items
);
5087 /* tool tip is automatically destroyed: we are its owner */
5089 /* Restore original wndproc */
5090 if (infoPtr
->hwndEdit
)
5091 SetWindowLongPtrW(infoPtr
->hwndEdit
, GWLP_WNDPROC
,
5092 (DWORD_PTR
)infoPtr
->wpEditOrig
);
5094 CloseThemeData (GetWindowTheme (infoPtr
->hwnd
));
5096 /* Deassociate treeview from the window before doing anything drastic. */
5097 SetWindowLongPtrW(infoPtr
->hwnd
, 0, 0);
5100 DeleteObject(infoPtr
->hDefaultFont
);
5101 DeleteObject(infoPtr
->hBoldFont
);
5102 DeleteObject(infoPtr
->hUnderlineFont
);
5108 /* Miscellaneous Messages ***********************************************/
5111 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
5119 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
5120 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
5121 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
5122 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
5123 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
5124 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
5125 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
5126 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
5127 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
5131 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
5133 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
5135 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
5137 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
5143 /************************************************************************
5146 * VK_UP Move selection to the previous non-hidden item.
5147 * VK_DOWN Move selection to the next non-hidden item.
5148 * VK_HOME Move selection to the first item.
5149 * VK_END Move selection to the last item.
5150 * VK_LEFT If expanded then collapse, otherwise move to parent.
5151 * VK_RIGHT If collapsed then expand, otherwise move to first child.
5153 * VK_SUBTRACT Collapse.
5154 * VK_MULTIPLY Expand all.
5155 * VK_PRIOR Move up GetVisibleCount items.
5156 * VK_NEXT Move down GetVisibleCount items.
5157 * VK_BACK Move to parent.
5158 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
5161 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
5163 /* If it is non-NULL and different, it will be selected and visible. */
5164 TREEVIEW_ITEM
*newSelection
= NULL
;
5166 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
5168 TRACE("%lx\n", wParam
);
5170 if (prevItem
== NULL
)
5173 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
5174 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
5179 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
5181 newSelection
= infoPtr
->root
->firstChild
;
5185 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
5189 newSelection
= infoPtr
->root
->firstChild
;
5193 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
5197 if (prevItem
->state
& TVIS_EXPANDED
)
5199 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5201 else if (prevItem
->parent
!= infoPtr
->root
)
5203 newSelection
= prevItem
->parent
;
5208 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
5210 if (!(prevItem
->state
& TVIS_EXPANDED
))
5211 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5214 newSelection
= prevItem
->firstChild
;
5221 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5225 if (!(prevItem
->state
& TVIS_EXPANDED
))
5226 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5230 if (prevItem
->state
& TVIS_EXPANDED
)
5231 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5236 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5237 -TREEVIEW_GetVisibleCount(infoPtr
));
5242 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5243 TREEVIEW_GetVisibleCount(infoPtr
));
5247 newSelection
= prevItem
->parent
;
5248 if (newSelection
== infoPtr
->root
)
5249 newSelection
= NULL
;
5253 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5254 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5258 if (newSelection
&& newSelection
!= prevItem
)
5260 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5263 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5271 TREEVIEW_MouseLeave (TREEVIEW_INFO
* infoPtr
)
5273 /* remove hot effect from item */
5274 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5275 infoPtr
->hotItem
= NULL
;
5281 TREEVIEW_MouseMove (TREEVIEW_INFO
* infoPtr
, LPARAM lParam
)
5284 TRACKMOUSEEVENT trackinfo
;
5285 TREEVIEW_ITEM
* item
;
5287 if (!(infoPtr
->dwStyle
& TVS_TRACKSELECT
)) return 0;
5289 /* fill in the TRACKMOUSEEVENT struct */
5290 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
5291 trackinfo
.dwFlags
= TME_QUERY
;
5292 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5294 /* call _TrackMouseEvent to see if we are currently tracking for this hwnd */
5295 _TrackMouseEvent(&trackinfo
);
5297 /* Make sure tracking is enabled so we receive a WM_MOUSELEAVE message */
5298 if(!(trackinfo
.dwFlags
& TME_LEAVE
))
5300 trackinfo
.dwFlags
= TME_LEAVE
; /* notify upon leaving */
5301 trackinfo
.hwndTrack
= infoPtr
->hwnd
;
5302 /* do it as fast as possible, minimal systimer latency will be used */
5303 trackinfo
.dwHoverTime
= 1;
5305 /* call TRACKMOUSEEVENT so we receive a WM_MOUSELEAVE message */
5306 /* and can properly deactivate the hot item */
5307 _TrackMouseEvent(&trackinfo
);
5310 pt
.x
= (short)LOWORD(lParam
);
5311 pt
.y
= (short)HIWORD(lParam
);
5313 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5315 if (item
!= infoPtr
->hotItem
)
5317 /* redraw old hot item */
5318 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5319 infoPtr
->hotItem
= item
;
5320 /* redraw new hot item */
5321 TREEVIEW_InvalidateItem(infoPtr
, infoPtr
->hotItem
);
5327 /* Draw themed border */
5328 static BOOL
TREEVIEW_NCPaint (const TREEVIEW_INFO
*infoPtr
, HRGN region
, LPARAM lParam
)
5330 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5334 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
5335 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
5338 return DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)region
, lParam
);
5340 GetWindowRect(infoPtr
->hwnd
, &r
);
5342 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
5343 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
5344 if (region
!= (HRGN
)1)
5345 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
5346 OffsetRect(&r
, -r
.left
, -r
.top
);
5348 dc
= GetDCEx(infoPtr
->hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
5349 OffsetRect(&r
, -r
.left
, -r
.top
);
5351 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
5352 DrawThemeParentBackground(infoPtr
->hwnd
, dc
, &r
);
5353 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
5354 ReleaseDC(infoPtr
->hwnd
, dc
);
5356 /* Call default proc to get the scrollbars etc. painted */
5357 DefWindowProcW (infoPtr
->hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
5363 TREEVIEW_Notify(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5365 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5367 if (lpnmh
->code
== PGN_CALCSIZE
) {
5368 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5370 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5371 lppgc
->iWidth
= infoPtr
->treeWidth
;
5372 TRACE("got PGN_CALCSIZE, returning horz size = %d, client=%d\n",
5373 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5376 lppgc
->iHeight
= infoPtr
->treeHeight
;
5377 TRACE("got PGN_CALCSIZE, returning vert size = %d, client=%d\n",
5378 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5382 return DefWindowProcW(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5386 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5388 if (wParam
== SIZE_RESTORED
)
5390 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5391 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5393 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5394 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5395 TREEVIEW_UpdateScrollBars(infoPtr
);
5399 FIXME("WM_SIZE flag %lx %lx not handled\n", wParam
, lParam
);
5402 TREEVIEW_Invalidate(infoPtr
, NULL
);
5407 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5409 TRACE("(%lx %lx)\n", wParam
, lParam
);
5411 if (wParam
== GWL_STYLE
)
5413 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5415 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_CHECKBOXES
)
5417 if (dwNewStyle
& TVS_CHECKBOXES
)
5419 initialize_checkboxes(infoPtr
);
5420 TRACE("checkboxes enabled\n");
5424 FIXME("tried to disable checkboxes\n");
5428 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5430 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5432 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5433 TRACE("tooltips enabled\n");
5437 DestroyWindow(infoPtr
->hwndToolTip
);
5438 infoPtr
->hwndToolTip
= 0;
5439 TRACE("tooltips disabled\n");
5443 infoPtr
->dwStyle
= dwNewStyle
;
5446 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5447 TREEVIEW_UpdateScrollBars(infoPtr
);
5448 TREEVIEW_Invalidate(infoPtr
, NULL
);
5454 TREEVIEW_SetCursor(const TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5457 TREEVIEW_ITEM
* item
;
5461 ScreenToClient(infoPtr
->hwnd
, &pt
);
5463 item
= TREEVIEW_HitTestPoint(infoPtr
, pt
);
5465 memset(&nmmouse
, 0, sizeof(nmmouse
));
5466 nmmouse
.hdr
.hwndFrom
= infoPtr
->hwnd
;
5467 nmmouse
.hdr
.idFrom
= GetWindowLongPtrW(infoPtr
->hwnd
, GWLP_ID
);
5468 nmmouse
.hdr
.code
= NM_SETCURSOR
;
5471 nmmouse
.dwItemSpec
= (DWORD_PTR
)item
;
5472 nmmouse
.dwItemData
= item
->lParam
;
5476 nmmouse
.dwHitInfo
= lParam
;
5477 if (TREEVIEW_SendRealNotify(infoPtr
, nmmouse
.hdr
.idFrom
, (LPARAM
)&nmmouse
))
5480 if (item
&& (infoPtr
->dwStyle
& TVS_TRACKSELECT
))
5482 SetCursor(infoPtr
->hcurHand
);
5486 return DefWindowProcW(infoPtr
->hwnd
, WM_SETCURSOR
, wParam
, lParam
);
5490 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5494 if (!infoPtr
->selectedItem
)
5496 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5500 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5501 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5506 TREEVIEW_KillFocus(const TREEVIEW_INFO
*infoPtr
)
5510 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5511 UpdateWindow(infoPtr
->hwnd
);
5512 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5516 /* update theme after a WM_THEMECHANGED message */
5517 static LRESULT
TREEVIEW_ThemeChanged(const TREEVIEW_INFO
*infoPtr
)
5519 HTHEME theme
= GetWindowTheme (infoPtr
->hwnd
);
5520 CloseThemeData (theme
);
5521 OpenThemeData (infoPtr
->hwnd
, themeClass
);
5526 static LRESULT WINAPI
5527 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5529 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5531 TRACE("hwnd %p msg %04x wp=%08lx lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5533 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5536 if (uMsg
== WM_CREATE
)
5537 TREEVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
5544 case TVM_CREATEDRAGIMAGE
:
5545 return TREEVIEW_CreateDragImage(infoPtr
, lParam
);
5547 case TVM_DELETEITEM
:
5548 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5550 case TVM_EDITLABELA
:
5551 case TVM_EDITLABELW
:
5552 return (LRESULT
)TREEVIEW_EditLabel(infoPtr
, (HTREEITEM
)lParam
);
5554 case TVM_ENDEDITLABELNOW
:
5555 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5557 case TVM_ENSUREVISIBLE
:
5558 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5561 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5563 case TVM_GETBKCOLOR
:
5564 return TREEVIEW_GetBkColor(infoPtr
);
5567 return TREEVIEW_GetCount(infoPtr
);
5569 case TVM_GETEDITCONTROL
:
5570 return TREEVIEW_GetEditControl(infoPtr
);
5572 case TVM_GETIMAGELIST
:
5573 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5576 return TREEVIEW_GetIndent(infoPtr
);
5578 case TVM_GETINSERTMARKCOLOR
:
5579 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5581 case TVM_GETISEARCHSTRINGA
:
5582 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5585 case TVM_GETISEARCHSTRINGW
:
5586 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5591 return TREEVIEW_GetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5592 uMsg
== TVM_GETITEMW
);
5593 case TVM_GETITEMHEIGHT
:
5594 return TREEVIEW_GetItemHeight(infoPtr
);
5596 case TVM_GETITEMRECT
:
5597 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5599 case TVM_GETITEMSTATE
:
5600 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5602 case TVM_GETLINECOLOR
:
5603 return TREEVIEW_GetLineColor(infoPtr
);
5605 case TVM_GETNEXTITEM
:
5606 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5608 case TVM_GETSCROLLTIME
:
5609 return TREEVIEW_GetScrollTime(infoPtr
);
5611 case TVM_GETTEXTCOLOR
:
5612 return TREEVIEW_GetTextColor(infoPtr
);
5614 case TVM_GETTOOLTIPS
:
5615 return TREEVIEW_GetToolTips(infoPtr
);
5617 case TVM_GETUNICODEFORMAT
:
5618 return TREEVIEW_GetUnicodeFormat(infoPtr
);
5620 case TVM_GETVISIBLECOUNT
:
5621 return TREEVIEW_GetVisibleCount(infoPtr
);
5624 return TREEVIEW_HitTest(infoPtr
, (LPTVHITTESTINFO
)lParam
);
5626 case TVM_INSERTITEMA
:
5627 case TVM_INSERTITEMW
:
5628 return TREEVIEW_InsertItemT(infoPtr
, (LPTVINSERTSTRUCTW
)lParam
,
5629 uMsg
== TVM_INSERTITEMW
);
5630 case TVM_SELECTITEM
:
5631 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5633 case TVM_SETBKCOLOR
:
5634 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5636 case TVM_SETIMAGELIST
:
5637 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5640 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5642 case TVM_SETINSERTMARK
:
5643 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5645 case TVM_SETINSERTMARKCOLOR
:
5646 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5650 return TREEVIEW_SetItemT(infoPtr
, (LPTVITEMEXW
)lParam
,
5651 uMsg
== TVM_SETITEMW
);
5652 case TVM_SETLINECOLOR
:
5653 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5655 case TVM_SETITEMHEIGHT
:
5656 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5658 case TVM_SETSCROLLTIME
:
5659 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5661 case TVM_SETTEXTCOLOR
:
5662 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5664 case TVM_SETTOOLTIPS
:
5665 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5667 case TVM_SETUNICODEFORMAT
:
5668 return TREEVIEW_SetUnicodeFormat(infoPtr
, (BOOL
)wParam
);
5670 case TVM_SORTCHILDREN
:
5671 return TREEVIEW_SortChildren(infoPtr
, lParam
);
5673 case TVM_SORTCHILDRENCB
:
5674 return TREEVIEW_SortChildrenCB(infoPtr
, (LPTVSORTCB
)lParam
);
5677 return TREEVIEW_ProcessLetterKeys(infoPtr
, wParam
, lParam
);
5680 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5683 return TREEVIEW_Destroy(infoPtr
);
5688 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5691 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5694 return TREEVIEW_GetFont(infoPtr
);
5697 return TREEVIEW_HScroll(infoPtr
, wParam
);
5700 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5703 return TREEVIEW_KillFocus(infoPtr
);
5705 case WM_LBUTTONDBLCLK
:
5706 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5708 case WM_LBUTTONDOWN
:
5709 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5711 /* WM_MBUTTONDOWN */
5714 return TREEVIEW_MouseLeave(infoPtr
);
5717 return TREEVIEW_MouseMove(infoPtr
, lParam
);
5719 case WM_NCLBUTTONDOWN
:
5720 if (infoPtr
->hwndEdit
)
5721 SetFocus(infoPtr
->hwnd
);
5725 return TREEVIEW_NCPaint (infoPtr
, (HRGN
)wParam
, lParam
);
5728 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5730 case WM_NOTIFYFORMAT
:
5731 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5733 case WM_PRINTCLIENT
:
5734 return TREEVIEW_PrintClient(infoPtr
, (HDC
)wParam
, lParam
);
5737 return TREEVIEW_Paint(infoPtr
, (HDC
)wParam
);
5739 case WM_RBUTTONDOWN
:
5740 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5743 return TREEVIEW_SetCursor(infoPtr
, wParam
, lParam
);
5746 return TREEVIEW_SetFocus(infoPtr
);
5749 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5752 return TREEVIEW_SetRedraw(infoPtr
, wParam
);
5755 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5757 case WM_STYLECHANGED
:
5758 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5760 case WM_SYSCOLORCHANGE
:
5761 COMCTL32_RefreshSysColors();
5767 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5769 case WM_THEMECHANGED
:
5770 return TREEVIEW_ThemeChanged (infoPtr
);
5773 return TREEVIEW_VScroll(infoPtr
, wParam
);
5775 /* WM_WININICHANGE */
5778 return TREEVIEW_MouseWheel(infoPtr
, wParam
, lParam
);
5781 TRACE("drawItem\n");
5785 /* This mostly catches MFC and Delphi messages. :( */
5786 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
5787 TRACE("Unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
5789 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
5794 /* Class Registration ***************************************************/
5797 TREEVIEW_Register(void)
5803 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
5804 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5805 wndClass
.lpfnWndProc
= TREEVIEW_WindowProc
;
5806 wndClass
.cbClsExtra
= 0;
5807 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5809 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
5810 wndClass
.hbrBackground
= 0;
5811 wndClass
.lpszClassName
= WC_TREEVIEWW
;
5813 RegisterClassW(&wndClass
);
5818 TREEVIEW_Unregister(void)
5820 UnregisterClassW(WC_TREEVIEWW
, NULL
);
5824 /* Tree Verification ****************************************************/
5828 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
5830 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5831 TREEVIEW_ITEM
*item
)
5833 assert(infoPtr
!= NULL
);
5834 assert(item
!= NULL
);
5836 /* both NULL, or both non-null */
5837 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5839 assert(item
->firstChild
!= item
);
5840 assert(item
->lastChild
!= item
);
5842 if (item
->firstChild
)
5844 assert(item
->firstChild
->parent
== item
);
5845 assert(item
->firstChild
->prevSibling
== NULL
);
5848 if (item
->lastChild
)
5850 assert(item
->lastChild
->parent
== item
);
5851 assert(item
->lastChild
->nextSibling
== NULL
);
5854 assert(item
->nextSibling
!= item
);
5855 if (item
->nextSibling
)
5857 assert(item
->nextSibling
->parent
== item
->parent
);
5858 assert(item
->nextSibling
->prevSibling
== item
);
5861 assert(item
->prevSibling
!= item
);
5862 if (item
->prevSibling
)
5864 assert(item
->prevSibling
->parent
== item
->parent
);
5865 assert(item
->prevSibling
->nextSibling
== item
);
5870 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
5872 assert(item
!= NULL
);
5874 assert(item
->parent
!= NULL
);
5875 assert(item
->parent
!= item
);
5876 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5878 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5880 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5882 TREEVIEW_VerifyChildren(infoPtr
, item
);
5886 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
5888 TREEVIEW_ITEM
*child
;
5889 assert(item
!= NULL
);
5891 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5892 TREEVIEW_VerifyItem(infoPtr
, child
);
5896 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5898 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5900 assert(root
!= NULL
);
5901 assert(root
->iLevel
== -1);
5902 assert(root
->parent
== NULL
);
5903 assert(root
->prevSibling
== NULL
);
5905 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
5907 TREEVIEW_VerifyChildren(infoPtr
, root
);
5911 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
5913 assert(infoPtr
!= NULL
);
5915 TREEVIEW_VerifyRoot(infoPtr
);