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
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Note that TREEVIEW_INFO * and HTREEITEM are the same thing.
23 * Note2: All items always! have valid (allocated) pszText field.
24 * If item's text == LPSTR_TEXTCALLBACKA we allocate buffer
25 * of size TEXT_CALLBACK_SIZE in DoSetItem.
26 * We use callbackMask to keep track of fields to be updated.
29 * missing notifications: NM_SETCURSOR, TVN_GETINFOTIP, TVN_KEYDOWN,
30 * TVN_SETDISPINFO, TVN_SINGLEEXPAND
32 * missing styles: TVS_FULLROWSELECT, TVS_INFOTIP, TVS_NOSCROLL,
33 * TVS_RTLREADING, TVS_TRACKSELECT
35 * missing item styles: TVIS_CUT, TVIS_EXPANDPARTIAL
37 * Make the insertion mark look right.
38 * Scroll (instead of repaint) as much as possible.
42 #include "wine/port.h"
51 #define NONAMELESSUNION
52 #define NONAMELESSSTRUCT
60 #include "wine/debug.h"
62 /* internal structures */
64 typedef struct _TREEITEM
/* HTREEITEM is a _TREEINFO *. */
75 int iIntegral
; /* item height multiplier (1 is normal) */
76 int iLevel
; /* indentation level:0=root level */
77 HTREEITEM parent
; /* handle to parent or 0 if at root */
78 HTREEITEM firstChild
; /* handle to first child or 0 if no child */
80 HTREEITEM prevSibling
; /* handle to prev item in list, 0 if first */
81 HTREEITEM nextSibling
; /* handle to next item in list, 0 if last */
87 LONG textWidth
; /* horizontal text extent for pszText */
88 LONG visibleOrder
; /* visible ordering, 0 is first visible item */
92 typedef struct tagTREEVIEW_INFO
95 HWND hwndNotify
; /* Owner window to send notifications to */
100 UINT uNumItems
; /* number of valid TREEVIEW_ITEMs */
101 INT cdmode
; /* last custom draw setting */
102 UINT uScrollTime
; /* max. time for scrolling in milliseconds */
103 BOOL bRedraw
; /* if FALSE we validate but don't redraw in TREEVIEW_Paint() */
105 UINT uItemHeight
; /* item height */
108 LONG clientWidth
; /* width of control window */
109 LONG clientHeight
; /* height of control window */
111 LONG treeWidth
; /* width of visible tree items */
112 LONG treeHeight
; /* height of visible tree items */
114 UINT uIndent
; /* indentation in pixels */
115 HTREEITEM selectedItem
; /* handle to selected item or 0 if none */
116 HTREEITEM hotItem
; /* handle currently under cursor, 0 if none */
117 HTREEITEM focusedItem
; /* item that was under the cursor when WM_LBUTTONDOWN was received */
119 HTREEITEM firstVisible
; /* handle to first visible item */
120 LONG maxVisibleOrder
;
121 HTREEITEM dropItem
; /* handle to item selected by drag cursor */
122 HTREEITEM insertMarkItem
; /* item after which insertion mark is placed */
123 BOOL insertBeforeorAfter
; /* flag used by TVM_SETINSERTMARK */
124 HIMAGELIST dragList
; /* Bitmap of dragged item */
129 COLORREF clrInsertMark
;
135 WNDPROC wpEditOrig
; /* orig window proc for subclassing edit */
136 BOOL bIgnoreEditKillFocus
;
139 BOOL bNtfUnicode
; /* TRUE if should send NOTIFY with W */
140 BOOL bUnicode
; /* set by CCM_SETUNICODEFORMAT */
141 HIMAGELIST himlNormal
;
142 int normalImageHeight
;
143 int normalImageWidth
;
144 HIMAGELIST himlState
;
145 int stateImageHeight
;
149 DWORD lastKeyPressTimestamp
; /* Added */
150 WPARAM charCode
; /* Added */
151 INT nSearchParamLength
; /* Added */
152 CHAR szSearchParam
[ MAX_PATH
]; /* Added */
156 /******** Defines that TREEVIEW_ProcessLetterKeys uses ****************/
157 #define KEY_DELAY 450
159 /* bitflags for infoPtr->uInternalStatus */
161 #define TV_HSCROLL 0x01 /* treeview too large to fit in window */
162 #define TV_VSCROLL 0x02 /* (horizontal/vertical) */
163 #define TV_LDRAG 0x04 /* Lbutton pushed to start drag */
164 #define TV_LDRAGGING 0x08 /* Lbutton pushed, mouse moved. */
165 #define TV_RDRAG 0x10 /* dito Rbutton */
166 #define TV_RDRAGGING 0x20
168 /* bitflags for infoPtr->timer */
170 #define TV_EDIT_TIMER 2
171 #define TV_EDIT_TIMER_SET 2
174 VOID
TREEVIEW_Register (VOID
);
175 VOID
TREEVIEW_Unregister (VOID
);
178 WINE_DEFAULT_DEBUG_CHANNEL(treeview
);
181 #define TEXT_CALLBACK_SIZE 260
183 #define TREEVIEW_LEFT_MARGIN 8
185 #define MINIMUM_INDENT 19
187 #define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
189 #define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
190 #define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
191 #define ISVISIBLE(x) ((x)->visibleOrder >= 0)
194 typedef VOID (*TREEVIEW_ItemEnumFunc
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*,LPVOID
);
197 static VOID
TREEVIEW_Invalidate(TREEVIEW_INFO
*, TREEVIEW_ITEM
*);
199 static LRESULT
TREEVIEW_DoSelectItem(TREEVIEW_INFO
*, INT
, HTREEITEM
, INT
);
200 static VOID
TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*, TREEVIEW_ITEM
*, BOOL
);
201 static LRESULT
TREEVIEW_EnsureVisible(TREEVIEW_INFO
*, HTREEITEM
, BOOL
);
202 static LRESULT
TREEVIEW_RButtonUp(TREEVIEW_INFO
*, LPPOINT
);
203 static LRESULT
TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
);
204 static VOID
TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
);
205 static LRESULT
TREEVIEW_HScroll(TREEVIEW_INFO
*, WPARAM
);
206 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND wParam
, UINT lParam
);
209 /* Random Utilities *****************************************************/
213 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
218 /* The definition is at the end of the file. */
219 static void TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
);
222 /* Returns the treeview private data if hwnd is a treeview.
223 * Otherwise returns an undefined value. */
224 static TREEVIEW_INFO
*
225 TREEVIEW_GetInfoPtr(HWND hwnd
)
227 return (TREEVIEW_INFO
*)GetWindowLongA(hwnd
, 0);
230 /* Don't call this. Nothing wants an item index. */
232 TREEVIEW_GetItemIndex(TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
234 assert(infoPtr
!= NULL
);
236 return DPA_GetPtrIndex(infoPtr
->items
, handle
);
239 /***************************************************************************
240 * This method checks that handle is an item for this tree.
243 TREEVIEW_ValidItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM handle
)
245 if (TREEVIEW_GetItemIndex(infoPtr
, handle
) == -1)
247 TRACE("invalid item %p\n", handle
);
255 TREEVIEW_CreateBoldFont(HFONT hOrigFont
)
259 GetObjectA(hOrigFont
, sizeof(font
), &font
);
260 font
.lfWeight
= FW_BOLD
;
261 return CreateFontIndirectA(&font
);
265 TREEVIEW_FontForItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
267 return (item
->state
& TVIS_BOLD
) ? infoPtr
->hBoldFont
: infoPtr
->hFont
;
270 /* for trace/debugging purposes only */
272 TREEVIEW_ItemName(TREEVIEW_ITEM
*item
)
274 if (item
== NULL
) return "<null item>";
275 if (item
->pszText
== LPSTR_TEXTCALLBACKA
) return "<callback>";
276 if (item
->pszText
== NULL
) return "<null>";
277 return item
->pszText
;
280 /* An item is not a child of itself. */
282 TREEVIEW_IsChildOf(TREEVIEW_ITEM
*parent
, TREEVIEW_ITEM
*child
)
286 child
= child
->parent
;
287 if (child
== parent
) return TRUE
;
288 } while (child
!= NULL
);
294 /* Tree Traversal *******************************************************/
296 /***************************************************************************
297 * This method returns the last expanded sibling or child child item
300 static TREEVIEW_ITEM
*
301 TREEVIEW_GetLastListItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
306 while (wineItem
->lastChild
)
308 if (wineItem
->state
& TVIS_EXPANDED
)
309 wineItem
= wineItem
->lastChild
;
314 if (wineItem
== infoPtr
->root
)
320 /***************************************************************************
321 * This method returns the previous non-hidden item in the list not
322 * considering the tree hierarchy.
324 static TREEVIEW_ITEM
*
325 TREEVIEW_GetPrevListItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*tvItem
)
327 if (tvItem
->prevSibling
)
329 /* This item has a prevSibling, get the last item in the sibling's tree. */
330 TREEVIEW_ITEM
*upItem
= tvItem
->prevSibling
;
332 if ((upItem
->state
& TVIS_EXPANDED
) && upItem
->lastChild
!= NULL
)
333 return TREEVIEW_GetLastListItem(infoPtr
, upItem
->lastChild
);
339 /* this item does not have a prevSibling, get the parent */
340 return (tvItem
->parent
!= infoPtr
->root
) ? tvItem
->parent
: NULL
;
345 /***************************************************************************
346 * This method returns the next physical item in the treeview not
347 * considering the tree hierarchy.
349 static TREEVIEW_ITEM
*
350 TREEVIEW_GetNextListItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*tvItem
)
352 assert(tvItem
!= NULL
);
355 * If this item has children and is expanded, return the first child
357 if ((tvItem
->state
& TVIS_EXPANDED
) && tvItem
->firstChild
!= NULL
)
359 return tvItem
->firstChild
;
364 * try to get the sibling
366 if (tvItem
->nextSibling
)
367 return tvItem
->nextSibling
;
370 * Otherwise, get the parent's sibling.
372 while (tvItem
->parent
)
374 tvItem
= tvItem
->parent
;
376 if (tvItem
->nextSibling
)
377 return tvItem
->nextSibling
;
383 /***************************************************************************
384 * This method returns the nth item starting at the given item. It returns
385 * the last item (or first) we we run out of items.
387 * Will scroll backward if count is <0.
388 * forward if count is >0.
390 static TREEVIEW_ITEM
*
391 TREEVIEW_GetListItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
394 TREEVIEW_ITEM
*(*next_item
)(TREEVIEW_INFO
*, TREEVIEW_ITEM
*);
395 TREEVIEW_ITEM
*previousItem
;
397 assert(wineItem
!= NULL
);
401 next_item
= TREEVIEW_GetNextListItem
;
406 next_item
= TREEVIEW_GetPrevListItem
;
413 previousItem
= wineItem
;
414 wineItem
= next_item(infoPtr
, wineItem
);
416 } while (--count
&& wineItem
!= NULL
);
419 return wineItem
? wineItem
: previousItem
;
422 /* Notifications ************************************************************/
424 static INT
get_notifycode(TREEVIEW_INFO
*infoPtr
, INT code
)
426 if (!infoPtr
->bNtfUnicode
) {
428 case TVN_SELCHANGINGW
: return TVN_SELCHANGINGA
;
429 case TVN_SELCHANGEDW
: return TVN_SELCHANGEDA
;
430 case TVN_GETDISPINFOW
: return TVN_GETDISPINFOA
;
431 case TVN_SETDISPINFOW
: return TVN_SETDISPINFOA
;
432 case TVN_ITEMEXPANDINGW
: return TVN_ITEMEXPANDINGA
;
433 case TVN_ITEMEXPANDEDW
: return TVN_ITEMEXPANDEDA
;
434 case TVN_BEGINDRAGW
: return TVN_BEGINDRAGA
;
435 case TVN_BEGINRDRAGW
: return TVN_BEGINRDRAGA
;
436 case TVN_DELETEITEMW
: return TVN_DELETEITEMA
;
437 case TVN_BEGINLABELEDITW
: return TVN_BEGINLABELEDITA
;
438 case TVN_ENDLABELEDITW
: return TVN_ENDLABELEDITA
;
439 case TVN_GETINFOTIPW
: return TVN_GETINFOTIPA
;
446 TREEVIEW_SendRealNotify(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
448 TRACE("wParam=%d, lParam=%ld\n", wParam
, lParam
);
449 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, wParam
, lParam
);
453 TREEVIEW_SendSimpleNotify(TREEVIEW_INFO
*infoPtr
, UINT code
)
456 HWND hwnd
= infoPtr
->hwnd
;
459 nmhdr
.hwndFrom
= hwnd
;
460 nmhdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
461 nmhdr
.code
= get_notifycode(infoPtr
, code
);
463 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
464 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
468 TREEVIEW_TVItemFromItem(TREEVIEW_INFO
*infoPtr
, UINT mask
, TVITEMA
*tvItem
, TREEVIEW_ITEM
*item
)
471 tvItem
->hItem
= item
;
472 tvItem
->state
= item
->state
;
473 tvItem
->stateMask
= 0;
474 tvItem
->iImage
= item
->iImage
;
475 tvItem
->cchTextMax
= item
->cchTextMax
;
476 tvItem
->iImage
= item
->iImage
;
477 tvItem
->iSelectedImage
= item
->iSelectedImage
;
478 tvItem
->cChildren
= item
->cChildren
;
479 tvItem
->lParam
= item
->lParam
;
481 /* **** **** **** **** WARNING **** **** **** **** */
482 /* This control stores all the data in A format */
483 /* we will convert it to W if the notify format */
485 /* **** **** **** **** WARNING **** **** **** **** */
486 if (infoPtr
->bNtfUnicode
) {
487 INT len
= MultiByteToWideChar( CP_ACP
, 0, item
->pszText
, -1, NULL
, 0 );
489 tvItem
->pszText
= (LPSTR
)Alloc (len
*sizeof(WCHAR
));
490 MultiByteToWideChar( CP_ACP
, 0, item
->pszText
, -1, (LPWSTR
)tvItem
->pszText
, len
*sizeof(WCHAR
) );
494 tvItem
->pszText
= item
->pszText
;
498 TREEVIEW_SendTreeviewNotify(TREEVIEW_INFO
*infoPtr
, UINT code
, UINT action
,
499 UINT mask
, HTREEITEM oldItem
, HTREEITEM newItem
)
501 HWND hwnd
= infoPtr
->hwnd
;
505 TRACE("code:%d action:%x olditem:%p newitem:%p\n",
506 code
, action
, oldItem
, newItem
);
508 ZeroMemory(&nmhdr
, sizeof(NMTREEVIEWA
));
510 nmhdr
.hdr
.hwndFrom
= hwnd
;
511 nmhdr
.hdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
512 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
513 nmhdr
.action
= action
;
516 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemOld
, oldItem
);
519 TREEVIEW_TVItemFromItem(infoPtr
, mask
, &nmhdr
.itemNew
, newItem
);
524 ret
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
525 (WPARAM
)GetWindowLongA(hwnd
, GWL_ID
),
527 if (infoPtr
->bNtfUnicode
) {
528 Free(nmhdr
.itemOld
.pszText
);
529 Free(nmhdr
.itemNew
.pszText
);
535 TREEVIEW_SendTreeviewDnDNotify(TREEVIEW_INFO
*infoPtr
, UINT code
,
536 HTREEITEM dragItem
, POINT pt
)
538 HWND hwnd
= infoPtr
->hwnd
;
541 TRACE("code:%d dragitem:%p\n", code
, dragItem
);
543 nmhdr
.hdr
.hwndFrom
= hwnd
;
544 nmhdr
.hdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
545 nmhdr
.hdr
.code
= get_notifycode(infoPtr
, code
);
547 nmhdr
.itemNew
.mask
= TVIF_STATE
| TVIF_PARAM
| TVIF_HANDLE
;
548 nmhdr
.itemNew
.hItem
= dragItem
;
549 nmhdr
.itemNew
.state
= dragItem
->state
;
550 nmhdr
.itemNew
.lParam
= dragItem
->lParam
;
552 nmhdr
.ptDrag
.x
= pt
.x
;
553 nmhdr
.ptDrag
.y
= pt
.y
;
555 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
556 (WPARAM
)GetWindowLongA(hwnd
, GWL_ID
),
562 TREEVIEW_SendCustomDrawNotify(TREEVIEW_INFO
*infoPtr
, DWORD dwDrawStage
,
565 HWND hwnd
= infoPtr
->hwnd
;
566 NMTVCUSTOMDRAW nmcdhdr
;
569 TRACE("drawstage:%lx hdc:%p\n", dwDrawStage
, hdc
);
571 nmcd
= &nmcdhdr
.nmcd
;
572 nmcd
->hdr
.hwndFrom
= hwnd
;
573 nmcd
->hdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
574 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
575 nmcd
->dwDrawStage
= dwDrawStage
;
578 nmcd
->dwItemSpec
= 0;
579 nmcd
->uItemState
= 0;
580 nmcd
->lItemlParam
= 0;
581 nmcdhdr
.clrText
= infoPtr
->clrText
;
582 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
585 return (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
586 (WPARAM
)GetWindowLongA(hwnd
, GWL_ID
),
592 /* FIXME: need to find out when the flags in uItemState need to be set */
595 TREEVIEW_SendCustomDrawItemNotify(TREEVIEW_INFO
*infoPtr
, HDC hdc
,
596 TREEVIEW_ITEM
*wineItem
, UINT uItemDrawState
)
598 HWND hwnd
= infoPtr
->hwnd
;
599 NMTVCUSTOMDRAW nmcdhdr
;
601 DWORD dwDrawStage
, dwItemSpec
;
605 dwDrawStage
= CDDS_ITEM
| uItemDrawState
;
606 dwItemSpec
= (DWORD
)wineItem
;
608 if (wineItem
->state
& TVIS_SELECTED
)
609 uItemState
|= CDIS_SELECTED
;
610 if (wineItem
== infoPtr
->selectedItem
)
611 uItemState
|= CDIS_FOCUS
;
612 if (wineItem
== infoPtr
->hotItem
)
613 uItemState
|= CDIS_HOT
;
615 nmcd
= &nmcdhdr
.nmcd
;
616 nmcd
->hdr
.hwndFrom
= hwnd
;
617 nmcd
->hdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
618 nmcd
->hdr
.code
= NM_CUSTOMDRAW
;
619 nmcd
->dwDrawStage
= dwDrawStage
;
621 nmcd
->rc
= wineItem
->rect
;
622 nmcd
->dwItemSpec
= dwItemSpec
;
623 nmcd
->uItemState
= uItemState
;
624 nmcd
->lItemlParam
= wineItem
->lParam
;
625 nmcdhdr
.clrText
= infoPtr
->clrText
;
626 nmcdhdr
.clrTextBk
= infoPtr
->clrBk
;
627 nmcdhdr
.iLevel
= wineItem
->iLevel
;
629 TRACE("drawstage:%lx hdc:%p item:%lx, itemstate:%x, lItemlParam:%lx\n",
630 nmcd
->dwDrawStage
, nmcd
->hdc
, nmcd
->dwItemSpec
,
631 nmcd
->uItemState
, nmcd
->lItemlParam
);
633 retval
= TREEVIEW_SendRealNotify(infoPtr
,
634 (WPARAM
)GetWindowLongA(hwnd
, GWL_ID
),
637 infoPtr
->clrText
= nmcdhdr
.clrText
;
638 infoPtr
->clrBk
= nmcdhdr
.clrTextBk
;
643 TREEVIEW_BeginLabelEditNotify(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*editItem
)
645 HWND hwnd
= infoPtr
->hwnd
;
646 LPSTR allocated
= NULL
;
650 tvdi
.hdr
.hwndFrom
= hwnd
;
651 tvdi
.hdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
652 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_BEGINLABELEDITW
);
654 tvdi
.item
.mask
= TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
| TVIF_TEXT
;
655 tvdi
.item
.hItem
= editItem
;
656 tvdi
.item
.state
= editItem
->state
;
657 tvdi
.item
.lParam
= editItem
->lParam
;
658 if (infoPtr
->bNtfUnicode
) {
659 INT len
= MultiByteToWideChar( CP_ACP
, 0, editItem
->pszText
, -1, NULL
, 0 );
661 tvdi
.item
.pszText
= allocated
= (LPSTR
)Alloc (len
*sizeof(WCHAR
));
662 MultiByteToWideChar( CP_ACP
, 0, editItem
->pszText
, -1, (LPWSTR
)tvdi
.item
.pszText
, len
*sizeof(WCHAR
) );
663 tvdi
.item
.cchTextMax
= len
*sizeof(WCHAR
);
666 tvdi
.item
.pszText
= editItem
->pszText
; /* ??? */
667 tvdi
.item
.cchTextMax
= editItem
->cchTextMax
; /* ??? */
671 tvdi
.item
.pszText
= editItem
->pszText
;
672 tvdi
.item
.cchTextMax
= editItem
->cchTextMax
;
675 ret
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
684 TREEVIEW_UpdateDispInfo(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
687 NMTVDISPINFOA callback
;
688 HWND hwnd
= infoPtr
->hwnd
;
690 mask
&= wineItem
->callbackMask
;
692 if (mask
== 0) return;
694 callback
.hdr
.hwndFrom
= hwnd
;
695 callback
.hdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
696 callback
.hdr
.code
= get_notifycode(infoPtr
, TVN_GETDISPINFOW
);
698 /* 'state' always contains valid value, as well as 'lParam'.
699 * All other parameters are uninitialized.
701 callback
.item
.pszText
= wineItem
->pszText
;
702 callback
.item
.cchTextMax
= wineItem
->cchTextMax
;
703 callback
.item
.mask
= mask
;
704 callback
.item
.hItem
= wineItem
;
705 callback
.item
.state
= wineItem
->state
;
706 callback
.item
.lParam
= wineItem
->lParam
;
708 /* If text is changed we need to recalculate textWidth */
709 if (mask
& TVIF_TEXT
)
710 wineItem
->textWidth
= 0;
712 TREEVIEW_SendRealNotify(infoPtr
,
713 (WPARAM
)callback
.hdr
.idFrom
, (LPARAM
)&callback
);
715 /* It may have changed due to a call to SetItem. */
716 mask
&= wineItem
->callbackMask
;
718 if ((mask
& TVIF_TEXT
) && callback
.item
.pszText
!= wineItem
->pszText
)
720 /* Instead of copying text into our buffer user specified its own */
721 if (infoPtr
->bNtfUnicode
) {
724 int len
= WideCharToMultiByte( CP_ACP
, 0,
725 (LPWSTR
)callback
.item
.pszText
, -1,
726 NULL
, 0, NULL
, NULL
);
727 buflen
= max((len
+1)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
728 newText
= (LPWSTR
)ReAlloc(wineItem
->pszText
, buflen
);
730 TRACE("returned wstr %s, len=%d, buflen=%d\n",
731 debugstr_w((LPWSTR
)callback
.item
.pszText
), len
, buflen
);
735 wineItem
->pszText
= (LPSTR
)newText
;
736 WideCharToMultiByte( CP_ACP
, 0,
737 (LPWSTR
)callback
.item
.pszText
, -1,
738 wineItem
->pszText
, buflen
,
740 wineItem
->cchTextMax
= buflen
;
742 /* If ReAlloc fails we have nothing to do, but keep original text */
745 int len
= max(lstrlenA(callback
.item
.pszText
) + 1,
747 LPSTR newText
= ReAlloc(wineItem
->pszText
, len
);
749 TRACE("returned str %s, len=%d\n",
750 debugstr_a(callback
.item
.pszText
), len
);
754 wineItem
->pszText
= newText
;
755 strcpy(wineItem
->pszText
, callback
.item
.pszText
);
756 wineItem
->cchTextMax
= len
;
758 /* If ReAlloc fails we have nothing to do, but keep original text */
761 else if (mask
& TVIF_TEXT
) {
762 /* User put text into our buffer, that is ok unless W string */
763 if (infoPtr
->bNtfUnicode
) {
765 LPSTR oldText
= NULL
;
767 int len
= WideCharToMultiByte( CP_ACP
, 0,
768 (LPWSTR
)callback
.item
.pszText
, -1,
769 NULL
, 0, NULL
, NULL
);
770 buflen
= max((len
+1)*sizeof(WCHAR
), TEXT_CALLBACK_SIZE
);
771 newText
= (LPWSTR
)Alloc(buflen
);
773 TRACE("same buffer wstr %s, len=%d, buflen=%d\n",
774 debugstr_w((LPWSTR
)callback
.item
.pszText
), len
, buflen
);
778 oldText
= wineItem
->pszText
;
779 wineItem
->pszText
= (LPSTR
)newText
;
780 WideCharToMultiByte( CP_ACP
, 0,
781 (LPWSTR
)callback
.item
.pszText
, -1,
782 wineItem
->pszText
, buflen
, NULL
, NULL
);
783 wineItem
->cchTextMax
= buflen
;
790 if (mask
& TVIF_IMAGE
)
791 wineItem
->iImage
= callback
.item
.iImage
;
793 if (mask
& TVIF_SELECTEDIMAGE
)
794 wineItem
->iSelectedImage
= callback
.item
.iSelectedImage
;
796 if (mask
& TVIF_CHILDREN
)
797 wineItem
->cChildren
= callback
.item
.cChildren
;
799 /* These members are now permanently set. */
800 if (callback
.item
.mask
& TVIF_DI_SETITEM
)
801 wineItem
->callbackMask
&= ~callback
.item
.mask
;
804 /***************************************************************************
805 * This function uses cChildren field to decide whether the item has
807 * Note: if this returns TRUE, the child items may not actually exist,
808 * they could be virtual.
810 * Just use wineItem->firstChild to check for physical children.
813 TREEVIEW_HasChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
815 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, TVIF_CHILDREN
);
817 return wineItem
->cChildren
> 0;
821 /* Item Position ********************************************************/
823 /* Compute linesOffset, stateOffset, imageOffset, textOffset of an item. */
825 TREEVIEW_ComputeItemInternalMetrics(TREEVIEW_INFO
*infoPtr
,
828 /* Same effect, different optimisation. */
830 BOOL lar
= ((infoPtr
->dwStyle
& TVS_LINESATROOT
)
831 && (infoPtr
->dwStyle
& (TVS_HASLINES
|TVS_HASBUTTONS
)));
833 BOOL lar
= ((infoPtr
->dwStyle
834 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
838 item
->linesOffset
= infoPtr
->uIndent
* (item
->iLevel
+ lar
- 1)
840 item
->stateOffset
= item
->linesOffset
+ infoPtr
->uIndent
;
841 item
->imageOffset
= item
->stateOffset
842 + (STATEIMAGEINDEX(item
->state
) ? infoPtr
->stateImageWidth
: 0);
843 item
->textOffset
= item
->imageOffset
+ infoPtr
->normalImageWidth
;
847 TREEVIEW_ComputeTextWidth(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
, HDC hDC
)
853 /* DRAW's OM docker creates items like this */
854 if (item
->pszText
== NULL
)
860 if (item
->textWidth
!= 0 && !(item
->callbackMask
& TVIF_TEXT
))
869 hdc
= GetDC(infoPtr
->hwnd
);
870 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, item
));
873 GetTextExtentPoint32A(hdc
, item
->pszText
, strlen(item
->pszText
), &sz
);
874 item
->textWidth
= sz
.cx
;
878 SelectObject(hdc
, hOldFont
);
884 TREEVIEW_ComputeItemRect(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
886 item
->rect
.top
= infoPtr
->uItemHeight
*
887 (item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
);
889 item
->rect
.bottom
= item
->rect
.top
890 + infoPtr
->uItemHeight
* item
->iIntegral
- 1;
893 item
->rect
.right
= infoPtr
->clientWidth
;
896 /* We know that only items after start need their order updated. */
898 TREEVIEW_RecalculateVisibleOrder(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*start
)
905 start
= infoPtr
->root
->firstChild
;
909 order
= start
->visibleOrder
;
911 for (item
= start
; item
!= NULL
;
912 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
914 item
->visibleOrder
= order
;
915 order
+= item
->iIntegral
;
918 infoPtr
->maxVisibleOrder
= order
;
920 for (item
= start
; item
!= NULL
;
921 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
923 TREEVIEW_ComputeItemRect(infoPtr
, item
);
928 /* Update metrics of all items in selected subtree.
929 * root must be expanded
932 TREEVIEW_UpdateSubTree(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*root
)
934 TREEVIEW_ITEM
*sibling
;
938 if (!root
->firstChild
|| !(root
->state
& TVIS_EXPANDED
))
941 root
->state
&= ~TVIS_EXPANDED
;
942 sibling
= TREEVIEW_GetNextListItem(infoPtr
, root
);
943 root
->state
|= TVIS_EXPANDED
;
945 hdc
= GetDC(infoPtr
->hwnd
);
946 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
948 for (; root
!= sibling
;
949 root
= TREEVIEW_GetNextListItem(infoPtr
, root
))
951 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, root
);
953 if (root
->callbackMask
& TVIF_TEXT
)
954 TREEVIEW_UpdateDispInfo(infoPtr
, root
, TVIF_TEXT
);
956 if (root
->textWidth
== 0)
958 SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, root
));
959 TREEVIEW_ComputeTextWidth(infoPtr
, root
, hdc
);
963 SelectObject(hdc
, hOldFont
);
964 ReleaseDC(infoPtr
->hwnd
, hdc
);
967 /* Item Allocation **********************************************************/
969 static TREEVIEW_ITEM
*
970 TREEVIEW_AllocateItem(TREEVIEW_INFO
*infoPtr
)
972 TREEVIEW_ITEM
*newItem
= Alloc(sizeof(TREEVIEW_ITEM
));
977 if (DPA_InsertPtr(infoPtr
->items
, INT_MAX
, newItem
) == -1)
986 /* Exact opposite of TREEVIEW_AllocateItem. In particular, it does not
987 * free item->pszText. */
989 TREEVIEW_FreeItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
991 DPA_DeletePtr(infoPtr
->items
, DPA_GetPtrIndex(infoPtr
->items
, item
));
993 if (infoPtr
->selectedItem
== item
)
994 infoPtr
->selectedItem
= NULL
;
995 if (infoPtr
->hotItem
== item
)
996 infoPtr
->hotItem
= NULL
;
997 if (infoPtr
->focusedItem
== item
)
998 infoPtr
->focusedItem
= NULL
;
999 if (infoPtr
->firstVisible
== item
)
1000 infoPtr
->firstVisible
= NULL
;
1001 if (infoPtr
->dropItem
== item
)
1002 infoPtr
->dropItem
= NULL
;
1003 if (infoPtr
->insertMarkItem
== item
)
1004 infoPtr
->insertMarkItem
= NULL
;
1008 /* Item Insertion *******************************************************/
1010 /***************************************************************************
1011 * This method inserts newItem before sibling as a child of parent.
1012 * sibling can be NULL, but only if parent has no children.
1015 TREEVIEW_InsertBefore(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1016 TREEVIEW_ITEM
*parent
)
1018 assert(newItem
!= NULL
);
1019 assert(parent
!= NULL
);
1021 if (sibling
!= NULL
)
1023 assert(sibling
->parent
== parent
);
1025 if (sibling
->prevSibling
!= NULL
)
1026 sibling
->prevSibling
->nextSibling
= newItem
;
1028 newItem
->prevSibling
= sibling
->prevSibling
;
1029 sibling
->prevSibling
= newItem
;
1032 newItem
->prevSibling
= NULL
;
1034 newItem
->nextSibling
= sibling
;
1036 if (parent
->firstChild
== sibling
)
1037 parent
->firstChild
= newItem
;
1039 if (parent
->lastChild
== NULL
)
1040 parent
->lastChild
= newItem
;
1043 /***************************************************************************
1044 * This method inserts newItem after sibling as a child of parent.
1045 * sibling can be NULL, but only if parent has no children.
1048 TREEVIEW_InsertAfter(TREEVIEW_ITEM
*newItem
, TREEVIEW_ITEM
*sibling
,
1049 TREEVIEW_ITEM
*parent
)
1051 assert(newItem
!= NULL
);
1052 assert(parent
!= NULL
);
1054 if (sibling
!= NULL
)
1056 assert(sibling
->parent
== parent
);
1058 if (sibling
->nextSibling
!= NULL
)
1059 sibling
->nextSibling
->prevSibling
= newItem
;
1061 newItem
->nextSibling
= sibling
->nextSibling
;
1062 sibling
->nextSibling
= newItem
;
1065 newItem
->nextSibling
= NULL
;
1067 newItem
->prevSibling
= sibling
;
1069 if (parent
->lastChild
== sibling
)
1070 parent
->lastChild
= newItem
;
1072 if (parent
->firstChild
== NULL
)
1073 parent
->firstChild
= newItem
;
1077 TREEVIEW_DoSetItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
1078 const TVITEMEXA
*tvItem
)
1080 UINT callbackClear
= 0;
1081 UINT callbackSet
= 0;
1083 /* Do this first in case it fails. */
1084 if (tvItem
->mask
& TVIF_TEXT
)
1086 wineItem
->textWidth
= 0; /* force width recalculation */
1087 if (tvItem
->pszText
!= LPSTR_TEXTCALLBACKA
)
1089 int len
= lstrlenA(tvItem
->pszText
) + 1;
1090 LPSTR newText
= ReAlloc(wineItem
->pszText
, len
);
1092 if (newText
== NULL
) return FALSE
;
1094 callbackClear
|= TVIF_TEXT
;
1096 wineItem
->pszText
= newText
;
1097 wineItem
->cchTextMax
= len
;
1098 lstrcpynA(wineItem
->pszText
, tvItem
->pszText
, len
);
1099 TRACE("setting text %s, item %p\n",
1100 debugstr_a(wineItem
->pszText
), wineItem
);
1104 callbackSet
|= TVIF_TEXT
;
1106 wineItem
->pszText
= ReAlloc(wineItem
->pszText
,
1107 TEXT_CALLBACK_SIZE
);
1108 wineItem
->cchTextMax
= TEXT_CALLBACK_SIZE
;
1109 TRACE("setting callback, item %p\n",
1114 if (tvItem
->mask
& TVIF_CHILDREN
)
1116 wineItem
->cChildren
= tvItem
->cChildren
;
1118 if (wineItem
->cChildren
== I_CHILDRENCALLBACK
)
1119 callbackSet
|= TVIF_CHILDREN
;
1121 callbackClear
|= TVIF_CHILDREN
;
1124 if (tvItem
->mask
& TVIF_IMAGE
)
1126 wineItem
->iImage
= tvItem
->iImage
;
1128 if (wineItem
->iImage
== I_IMAGECALLBACK
)
1129 callbackSet
|= TVIF_IMAGE
;
1131 callbackClear
|= TVIF_IMAGE
;
1134 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
1136 wineItem
->iSelectedImage
= tvItem
->iSelectedImage
;
1138 if (wineItem
->iSelectedImage
== I_IMAGECALLBACK
)
1139 callbackSet
|= TVIF_SELECTEDIMAGE
;
1141 callbackClear
|= TVIF_SELECTEDIMAGE
;
1144 if (tvItem
->mask
& TVIF_PARAM
)
1145 wineItem
->lParam
= tvItem
->lParam
;
1147 /* If the application sets TVIF_INTEGRAL without
1148 * supplying a TVITEMEX structure, it's toast. */
1149 if (tvItem
->mask
& TVIF_INTEGRAL
)
1150 wineItem
->iIntegral
= tvItem
->iIntegral
;
1152 if (tvItem
->mask
& TVIF_STATE
)
1154 TRACE("prevstate,state,mask:%x,%x,%x\n", wineItem
->state
, tvItem
->state
,
1156 wineItem
->state
&= ~tvItem
->stateMask
;
1157 wineItem
->state
|= (tvItem
->state
& tvItem
->stateMask
);
1159 if (tvItem
->stateMask
& TVIS_BOLD
)
1160 callbackSet
|= TVIF_TEXT
;
1163 wineItem
->callbackMask
|= callbackSet
;
1164 wineItem
->callbackMask
&= ~callbackClear
;
1169 /* Note that the new item is pre-zeroed. */
1171 TREEVIEW_InsertItemA(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
1173 const TVINSERTSTRUCTA
*ptdi
= (LPTVINSERTSTRUCTA
) lParam
;
1174 const TVITEMEXA
*tvItem
= &ptdi
->DUMMYUNIONNAME
.itemex
;
1175 HTREEITEM insertAfter
;
1176 TREEVIEW_ITEM
*newItem
, *parentItem
;
1177 BOOL bTextUpdated
= FALSE
;
1179 if (ptdi
->hParent
== TVI_ROOT
|| ptdi
->hParent
== 0)
1181 parentItem
= infoPtr
->root
;
1185 parentItem
= ptdi
->hParent
;
1187 if (!TREEVIEW_ValidItem(infoPtr
, parentItem
))
1189 WARN("invalid parent %p\n", parentItem
);
1190 return (LRESULT
)(HTREEITEM
)NULL
;
1194 insertAfter
= ptdi
->hInsertAfter
;
1196 /* Validate this now for convenience. */
1197 switch ((DWORD
)insertAfter
)
1199 case (DWORD
)TVI_FIRST
:
1200 case (DWORD
)TVI_LAST
:
1201 case (DWORD
)TVI_SORT
:
1205 if (!TREEVIEW_ValidItem(infoPtr
, insertAfter
) ||
1206 insertAfter
->parent
!= parentItem
)
1208 WARN("invalid insert after %p\n", insertAfter
);
1209 insertAfter
= TVI_LAST
;
1213 TRACE("parent %p position %p: '%s'\n", parentItem
, insertAfter
,
1214 (tvItem
->mask
& TVIF_TEXT
)
1215 ? ((tvItem
->pszText
== LPSTR_TEXTCALLBACKA
) ? "<callback>"
1219 newItem
= TREEVIEW_AllocateItem(infoPtr
);
1220 if (newItem
== NULL
)
1221 return (LRESULT
)(HTREEITEM
)NULL
;
1223 newItem
->parent
= parentItem
;
1224 newItem
->iIntegral
= 1;
1226 if (!TREEVIEW_DoSetItem(infoPtr
, newItem
, tvItem
))
1227 return (LRESULT
)(HTREEITEM
)NULL
;
1229 /* After this point, nothing can fail. (Except for TVI_SORT.) */
1231 infoPtr
->uNumItems
++;
1233 switch ((DWORD
)insertAfter
)
1235 case (DWORD
)TVI_FIRST
:
1237 TREEVIEW_ITEM
*originalFirst
= parentItem
->firstChild
;
1238 TREEVIEW_InsertBefore(newItem
, parentItem
->firstChild
, parentItem
);
1239 if (infoPtr
->firstVisible
== originalFirst
)
1240 TREEVIEW_SetFirstVisible(infoPtr
, newItem
, TRUE
);
1244 case (DWORD
)TVI_LAST
:
1245 TREEVIEW_InsertAfter(newItem
, parentItem
->lastChild
, parentItem
);
1248 /* hInsertAfter names a specific item we want to insert after */
1250 TREEVIEW_InsertAfter(newItem
, insertAfter
, insertAfter
->parent
);
1253 case (DWORD
)TVI_SORT
:
1255 TREEVIEW_ITEM
*aChild
;
1256 TREEVIEW_ITEM
*previousChild
= NULL
;
1257 BOOL bItemInserted
= FALSE
;
1259 aChild
= parentItem
->firstChild
;
1261 bTextUpdated
= TRUE
;
1262 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1264 /* Iterate the parent children to see where we fit in */
1265 while (aChild
!= NULL
)
1269 TREEVIEW_UpdateDispInfo(infoPtr
, aChild
, TVIF_TEXT
);
1270 comp
= lstrcmpA(newItem
->pszText
, aChild
->pszText
);
1272 if (comp
< 0) /* we are smaller than the current one */
1274 TREEVIEW_InsertBefore(newItem
, aChild
, parentItem
);
1275 bItemInserted
= TRUE
;
1278 else if (comp
> 0) /* we are bigger than the current one */
1280 previousChild
= aChild
;
1282 /* This will help us to exit if there is no more sibling */
1283 aChild
= (aChild
->nextSibling
== 0)
1285 : aChild
->nextSibling
;
1287 /* Look at the next item */
1293 * An item with this name is already existing, therefore,
1294 * we add after the one we found
1296 TREEVIEW_InsertAfter(newItem
, aChild
, parentItem
);
1297 bItemInserted
= TRUE
;
1303 * we reach the end of the child list and the item has not
1304 * yet been inserted, therefore, insert it after the last child.
1306 if ((!bItemInserted
) && (aChild
== NULL
))
1307 TREEVIEW_InsertAfter(newItem
, previousChild
, parentItem
);
1314 TRACE("new item %p; parent %p, mask %x\n", newItem
,
1315 newItem
->parent
, tvItem
->mask
);
1317 newItem
->iLevel
= newItem
->parent
->iLevel
+ 1;
1319 if (newItem
->parent
->cChildren
== 0)
1320 newItem
->parent
->cChildren
= 1;
1322 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
1324 if (STATEIMAGEINDEX(newItem
->state
) == 0)
1325 newItem
->state
|= INDEXTOSTATEIMAGEMASK(1);
1328 if (infoPtr
->firstVisible
== NULL
)
1329 infoPtr
->firstVisible
= newItem
;
1331 TREEVIEW_VerifyTree(infoPtr
);
1333 if (parentItem
== infoPtr
->root
||
1334 (ISVISIBLE(parentItem
) && parentItem
->state
& TVIS_EXPANDED
))
1336 TREEVIEW_ITEM
*item
;
1337 TREEVIEW_ITEM
*prev
= TREEVIEW_GetPrevListItem(infoPtr
, newItem
);
1339 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1340 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, newItem
);
1343 TREEVIEW_UpdateDispInfo(infoPtr
, newItem
, TVIF_TEXT
);
1345 TREEVIEW_ComputeTextWidth(infoPtr
, newItem
, 0);
1346 TREEVIEW_UpdateScrollBars(infoPtr
);
1348 * if the item was inserted in a visible part of the tree,
1349 * invalidate it, as well as those after it
1351 for (item
= newItem
;
1353 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
1354 TREEVIEW_Invalidate(infoPtr
, item
);
1358 newItem
->visibleOrder
= -1;
1360 /* refresh treeview if newItem is the first item inserted under parentItem */
1361 if (ISVISIBLE(parentItem
) && newItem
->prevSibling
== newItem
->nextSibling
)
1363 /* parent got '+' - update it */
1364 TREEVIEW_Invalidate(infoPtr
, parentItem
);
1368 return (LRESULT
)newItem
;
1373 TREEVIEW_InsertItemW(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
1375 TVINSERTSTRUCTW
*tvisW
;
1376 TVINSERTSTRUCTA tvisA
;
1379 tvisW
= (LPTVINSERTSTRUCTW
) lParam
;
1381 tvisA
.hParent
= tvisW
->hParent
;
1382 tvisA
.hInsertAfter
= tvisW
->hInsertAfter
;
1384 tvisA
.DUMMYUNIONNAME
.item
.mask
= tvisW
->DUMMYUNIONNAME
.item
.mask
;
1385 tvisA
.DUMMYUNIONNAME
.item
.hItem
= tvisW
->DUMMYUNIONNAME
.item
.hItem
;
1386 tvisA
.DUMMYUNIONNAME
.item
.state
= tvisW
->DUMMYUNIONNAME
.item
.state
;
1387 tvisA
.DUMMYUNIONNAME
.item
.stateMask
= tvisW
->DUMMYUNIONNAME
.item
.stateMask
;
1388 tvisA
.DUMMYUNIONNAME
.item
.cchTextMax
=
1389 tvisW
->DUMMYUNIONNAME
.item
.cchTextMax
;
1391 if (tvisW
->DUMMYUNIONNAME
.item
.pszText
)
1393 if (tvisW
->DUMMYUNIONNAME
.item
.pszText
!= LPSTR_TEXTCALLBACKW
)
1395 int len
= WideCharToMultiByte( CP_ACP
, 0, tvisW
->DUMMYUNIONNAME
.item
.pszText
, -1,
1396 NULL
, 0, NULL
, NULL
);
1397 tvisA
.DUMMYUNIONNAME
.item
.pszText
= Alloc(len
);
1398 WideCharToMultiByte( CP_ACP
, 0, tvisW
->DUMMYUNIONNAME
.item
.pszText
, -1,
1399 tvisA
.DUMMYUNIONNAME
.item
.pszText
, len
, NULL
, NULL
);
1403 tvisA
.DUMMYUNIONNAME
.item
.pszText
= LPSTR_TEXTCALLBACKA
;
1404 tvisA
.DUMMYUNIONNAME
.item
.cchTextMax
= 0;
1408 tvisA
.DUMMYUNIONNAME
.item
.iImage
= tvisW
->DUMMYUNIONNAME
.item
.iImage
;
1409 tvisA
.DUMMYUNIONNAME
.item
.iSelectedImage
=
1410 tvisW
->DUMMYUNIONNAME
.item
.iSelectedImage
;
1411 tvisA
.DUMMYUNIONNAME
.item
.cChildren
= tvisW
->DUMMYUNIONNAME
.item
.cChildren
;
1412 tvisA
.DUMMYUNIONNAME
.item
.lParam
= tvisW
->DUMMYUNIONNAME
.item
.lParam
;
1414 lRes
= TREEVIEW_InsertItemA(infoPtr
, (LPARAM
)&tvisA
);
1416 if (tvisA
.DUMMYUNIONNAME
.item
.pszText
!= LPSTR_TEXTCALLBACKA
)
1418 Free(tvisA
.DUMMYUNIONNAME
.item
.pszText
);
1426 /* Item Deletion ************************************************************/
1428 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
);
1431 TREEVIEW_RemoveAllChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*parentItem
)
1433 TREEVIEW_ITEM
*kill
= parentItem
->firstChild
;
1435 while (kill
!= NULL
)
1437 TREEVIEW_ITEM
*next
= kill
->nextSibling
;
1439 TREEVIEW_RemoveItem(infoPtr
, kill
);
1444 assert(parentItem
->cChildren
<= 0); /* I_CHILDRENCALLBACK or 0 */
1445 assert(parentItem
->firstChild
== NULL
);
1446 assert(parentItem
->lastChild
== NULL
);
1450 TREEVIEW_UnlinkItem(TREEVIEW_ITEM
*item
)
1452 TREEVIEW_ITEM
*parentItem
= item
->parent
;
1454 assert(item
!= NULL
);
1455 assert(item
->parent
!= NULL
); /* i.e. it must not be the root */
1457 if (parentItem
->firstChild
== item
)
1458 parentItem
->firstChild
= item
->nextSibling
;
1460 if (parentItem
->lastChild
== item
)
1461 parentItem
->lastChild
= item
->prevSibling
;
1463 if (parentItem
->firstChild
== NULL
&& parentItem
->lastChild
== NULL
1464 && parentItem
->cChildren
> 0)
1465 parentItem
->cChildren
= 0;
1467 if (item
->prevSibling
)
1468 item
->prevSibling
->nextSibling
= item
->nextSibling
;
1470 if (item
->nextSibling
)
1471 item
->nextSibling
->prevSibling
= item
->prevSibling
;
1475 TREEVIEW_RemoveItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
)
1477 TRACE("%p, (%s)\n", wineItem
, TREEVIEW_ItemName(wineItem
));
1479 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_DELETEITEMW
, TVC_UNKNOWN
,
1480 TVIF_HANDLE
| TVIF_PARAM
, wineItem
, 0);
1482 if (wineItem
->firstChild
)
1483 TREEVIEW_RemoveAllChildren(infoPtr
, wineItem
);
1485 TREEVIEW_UnlinkItem(wineItem
);
1487 infoPtr
->uNumItems
--;
1489 if (wineItem
->pszText
!= LPSTR_TEXTCALLBACKA
)
1490 Free(wineItem
->pszText
);
1492 TREEVIEW_FreeItem(infoPtr
, wineItem
);
1496 /* Empty out the tree. */
1498 TREEVIEW_RemoveTree(TREEVIEW_INFO
*infoPtr
)
1500 TREEVIEW_RemoveAllChildren(infoPtr
, infoPtr
->root
);
1502 assert(infoPtr
->uNumItems
== 0); /* root isn't counted in uNumItems */
1506 TREEVIEW_DeleteItem(TREEVIEW_INFO
*infoPtr
, HTREEITEM wineItem
)
1508 TREEVIEW_ITEM
*oldSelection
= infoPtr
->selectedItem
;
1509 TREEVIEW_ITEM
*newSelection
= oldSelection
;
1510 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
1511 TREEVIEW_ITEM
*parent
, *prev
= NULL
;
1512 BOOL visible
= FALSE
;
1514 if (wineItem
== TVI_ROOT
)
1516 TRACE("TVI_ROOT\n");
1517 parent
= infoPtr
->root
;
1518 newSelection
= NULL
;
1520 TREEVIEW_RemoveTree(infoPtr
);
1524 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
1527 TRACE("%p (%s)\n", wineItem
, TREEVIEW_ItemName(wineItem
));
1528 parent
= wineItem
->parent
;
1530 if (ISVISIBLE(wineItem
))
1532 prev
= TREEVIEW_GetPrevListItem(infoPtr
, wineItem
);
1536 if (infoPtr
->selectedItem
!= NULL
1537 && (wineItem
== infoPtr
->selectedItem
1538 || TREEVIEW_IsChildOf(wineItem
, infoPtr
->selectedItem
)))
1540 if (wineItem
->nextSibling
)
1541 newSelection
= wineItem
->nextSibling
;
1542 else if (wineItem
->parent
!= infoPtr
->root
)
1543 newSelection
= wineItem
->parent
;
1546 if (infoPtr
->firstVisible
== wineItem
)
1548 if (wineItem
->nextSibling
)
1549 newFirstVisible
= wineItem
->nextSibling
;
1550 else if (wineItem
->prevSibling
)
1551 newFirstVisible
= wineItem
->prevSibling
;
1552 else if (wineItem
->parent
!= infoPtr
->root
)
1553 newFirstVisible
= wineItem
->parent
;
1554 TREEVIEW_SetFirstVisible(infoPtr
, NULL
, TRUE
);
1557 newFirstVisible
= infoPtr
->firstVisible
;
1559 TREEVIEW_RemoveItem(infoPtr
, wineItem
);
1562 /* Don't change if somebody else already has. */
1563 if (oldSelection
== infoPtr
->selectedItem
)
1565 if (TREEVIEW_ValidItem(infoPtr
, newSelection
))
1566 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
, TVC_UNKNOWN
);
1568 infoPtr
->selectedItem
= 0;
1571 /* Validate insertMark dropItem.
1572 * hotItem ??? - used for comparison only.
1574 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->insertMarkItem
))
1575 infoPtr
->insertMarkItem
= 0;
1577 if (!TREEVIEW_ValidItem(infoPtr
, infoPtr
->dropItem
))
1578 infoPtr
->dropItem
= 0;
1580 if (!TREEVIEW_ValidItem(infoPtr
, newFirstVisible
))
1581 newFirstVisible
= infoPtr
->root
->firstChild
;
1583 TREEVIEW_VerifyTree(infoPtr
);
1588 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
1589 TREEVIEW_RecalculateVisibleOrder(infoPtr
, prev
);
1590 TREEVIEW_UpdateScrollBars(infoPtr
);
1591 TREEVIEW_Invalidate(infoPtr
, NULL
);
1593 else if (ISVISIBLE(parent
) && !TREEVIEW_HasChildren(infoPtr
, parent
))
1595 /* parent lost '+/-' - update it */
1596 TREEVIEW_Invalidate(infoPtr
, parent
);
1603 /* Get/Set Messages *********************************************************/
1605 TREEVIEW_SetRedraw(TREEVIEW_INFO
* infoPtr
, WPARAM wParam
, LPARAM lParam
)
1608 infoPtr
->bRedraw
= TRUE
;
1610 infoPtr
->bRedraw
= FALSE
;
1616 TREEVIEW_GetIndent(TREEVIEW_INFO
*infoPtr
)
1619 return infoPtr
->uIndent
;
1623 TREEVIEW_SetIndent(TREEVIEW_INFO
*infoPtr
, UINT newIndent
)
1627 if (newIndent
< MINIMUM_INDENT
)
1628 newIndent
= MINIMUM_INDENT
;
1630 if (infoPtr
->uIndent
!= newIndent
)
1632 infoPtr
->uIndent
= newIndent
;
1633 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1634 TREEVIEW_UpdateScrollBars(infoPtr
);
1635 TREEVIEW_Invalidate(infoPtr
, NULL
);
1643 TREEVIEW_GetToolTips(TREEVIEW_INFO
*infoPtr
)
1646 return (LRESULT
)infoPtr
->hwndToolTip
;
1650 TREEVIEW_SetToolTips(TREEVIEW_INFO
*infoPtr
, HWND hwndTT
)
1655 prevToolTip
= infoPtr
->hwndToolTip
;
1656 infoPtr
->hwndToolTip
= hwndTT
;
1658 return (LRESULT
)prevToolTip
;
1663 TREEVIEW_GetScrollTime(TREEVIEW_INFO
*infoPtr
)
1665 return infoPtr
->uScrollTime
;
1669 TREEVIEW_SetScrollTime(TREEVIEW_INFO
*infoPtr
, UINT uScrollTime
)
1671 UINT uOldScrollTime
= infoPtr
->uScrollTime
;
1673 infoPtr
->uScrollTime
= min(uScrollTime
, 100);
1675 return uOldScrollTime
;
1680 TREEVIEW_GetImageList(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
1686 case (WPARAM
)TVSIL_NORMAL
:
1687 return (LRESULT
)infoPtr
->himlNormal
;
1689 case (WPARAM
)TVSIL_STATE
:
1690 return (LRESULT
)infoPtr
->himlState
;
1698 TREEVIEW_SetImageList(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, HIMAGELIST himlNew
)
1700 HIMAGELIST himlOld
= 0;
1701 int oldWidth
= infoPtr
->normalImageWidth
;
1702 int oldHeight
= infoPtr
->normalImageHeight
;
1705 TRACE("%x,%p\n", wParam
, himlNew
);
1709 case (WPARAM
)TVSIL_NORMAL
:
1710 himlOld
= infoPtr
->himlNormal
;
1711 infoPtr
->himlNormal
= himlNew
;
1713 if (himlNew
!= NULL
)
1714 ImageList_GetIconSize(himlNew
, &infoPtr
->normalImageWidth
,
1715 &infoPtr
->normalImageHeight
);
1718 infoPtr
->normalImageWidth
= 0;
1719 infoPtr
->normalImageHeight
= 0;
1724 case (WPARAM
)TVSIL_STATE
:
1725 himlOld
= infoPtr
->himlState
;
1726 infoPtr
->himlState
= himlNew
;
1728 if (himlNew
!= NULL
)
1729 ImageList_GetIconSize(himlNew
, &infoPtr
->stateImageWidth
,
1730 &infoPtr
->stateImageHeight
);
1733 infoPtr
->stateImageWidth
= 0;
1734 infoPtr
->stateImageHeight
= 0;
1740 if (oldWidth
!= infoPtr
->normalImageWidth
||
1741 oldHeight
!= infoPtr
->normalImageHeight
)
1743 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1744 TREEVIEW_UpdateScrollBars(infoPtr
);
1747 TREEVIEW_Invalidate(infoPtr
, NULL
);
1749 return (LRESULT
)himlOld
;
1752 /* Compute the natural height (based on the font size) for items. */
1754 TREEVIEW_NaturalHeight(TREEVIEW_INFO
*infoPtr
)
1758 HFONT hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
1760 GetTextMetricsA(hdc
, &tm
);
1762 SelectObject(hdc
, hOldFont
);
1765 /* The 16 is a hack because our fonts are tiny. */
1766 /* add 2 for the focus border and 1 more for margin some apps assume */
1767 return max(16, tm
.tmHeight
+ tm
.tmExternalLeading
+ 3);
1771 TREEVIEW_SetItemHeight(TREEVIEW_INFO
*infoPtr
, INT newHeight
)
1773 INT prevHeight
= infoPtr
->uItemHeight
;
1775 TRACE("%d \n", newHeight
);
1776 if (newHeight
== -1)
1778 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1779 infoPtr
->bHeightSet
= FALSE
;
1783 infoPtr
->uItemHeight
= newHeight
;
1784 infoPtr
->bHeightSet
= TRUE
;
1787 /* Round down, unless we support odd ("non even") heights. */
1788 if (!(infoPtr
->dwStyle
) & TVS_NONEVENHEIGHT
)
1789 infoPtr
->uItemHeight
&= ~1;
1791 if (infoPtr
->uItemHeight
!= prevHeight
)
1793 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1794 TREEVIEW_UpdateScrollBars(infoPtr
);
1795 TREEVIEW_Invalidate(infoPtr
, NULL
);
1802 TREEVIEW_GetItemHeight(TREEVIEW_INFO
*infoPtr
)
1805 return infoPtr
->uItemHeight
;
1810 TREEVIEW_GetFont(TREEVIEW_INFO
*infoPtr
)
1812 TRACE("%p\n", infoPtr
->hFont
);
1813 return (LRESULT
)infoPtr
->hFont
;
1818 TREEVIEW_ResetTextWidth(LPVOID pItem
, LPVOID unused
)
1822 ((TREEVIEW_ITEM
*)pItem
)->textWidth
= 0;
1828 TREEVIEW_SetFont(TREEVIEW_INFO
*infoPtr
, HFONT hFont
, BOOL bRedraw
)
1830 UINT uHeight
= infoPtr
->uItemHeight
;
1832 TRACE("%p %i\n", hFont
, bRedraw
);
1834 infoPtr
->hFont
= hFont
? hFont
: GetStockObject(SYSTEM_FONT
);
1836 DeleteObject(infoPtr
->hBoldFont
);
1837 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
1839 if (!infoPtr
->bHeightSet
)
1840 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
1842 if (uHeight
!= infoPtr
->uItemHeight
)
1843 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
1845 DPA_EnumCallback(infoPtr
->items
, TREEVIEW_ResetTextWidth
, 0);
1847 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
1848 TREEVIEW_UpdateScrollBars(infoPtr
);
1851 TREEVIEW_Invalidate(infoPtr
, NULL
);
1858 TREEVIEW_GetLineColor(TREEVIEW_INFO
*infoPtr
)
1861 return (LRESULT
)infoPtr
->clrLine
;
1865 TREEVIEW_SetLineColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1867 COLORREF prevColor
= infoPtr
->clrLine
;
1870 infoPtr
->clrLine
= color
;
1871 return (LRESULT
)prevColor
;
1876 TREEVIEW_GetTextColor(TREEVIEW_INFO
*infoPtr
)
1879 return (LRESULT
)infoPtr
->clrText
;
1883 TREEVIEW_SetTextColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1885 COLORREF prevColor
= infoPtr
->clrText
;
1888 infoPtr
->clrText
= color
;
1890 if (infoPtr
->clrText
!= prevColor
)
1891 TREEVIEW_Invalidate(infoPtr
, NULL
);
1893 return (LRESULT
)prevColor
;
1898 TREEVIEW_GetBkColor(TREEVIEW_INFO
*infoPtr
)
1901 return (LRESULT
)infoPtr
->clrBk
;
1905 TREEVIEW_SetBkColor(TREEVIEW_INFO
*infoPtr
, COLORREF newColor
)
1907 COLORREF prevColor
= infoPtr
->clrBk
;
1910 infoPtr
->clrBk
= newColor
;
1912 if (newColor
!= prevColor
)
1913 TREEVIEW_Invalidate(infoPtr
, NULL
);
1915 return (LRESULT
)prevColor
;
1920 TREEVIEW_GetInsertMarkColor(TREEVIEW_INFO
*infoPtr
)
1923 return (LRESULT
)infoPtr
->clrInsertMark
;
1927 TREEVIEW_SetInsertMarkColor(TREEVIEW_INFO
*infoPtr
, COLORREF color
)
1929 COLORREF prevColor
= infoPtr
->clrInsertMark
;
1931 TRACE("%lx\n", color
);
1932 infoPtr
->clrInsertMark
= color
;
1934 return (LRESULT
)prevColor
;
1939 TREEVIEW_SetInsertMark(TREEVIEW_INFO
*infoPtr
, BOOL wParam
, HTREEITEM item
)
1941 TRACE("%d %p\n", wParam
, item
);
1943 if (!TREEVIEW_ValidItem(infoPtr
, item
))
1946 infoPtr
->insertBeforeorAfter
= wParam
;
1947 infoPtr
->insertMarkItem
= item
;
1949 TREEVIEW_Invalidate(infoPtr
, NULL
);
1955 /************************************************************************
1956 * Some serious braindamage here. lParam is a pointer to both the
1957 * input HTREEITEM and the output RECT.
1960 TREEVIEW_GetItemRect(TREEVIEW_INFO
*infoPtr
, BOOL fTextRect
, LPRECT lpRect
)
1962 TREEVIEW_ITEM
*wineItem
;
1963 const HTREEITEM
*pItem
= (HTREEITEM
*)lpRect
;
1967 * validate parameters
1973 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
) || !ISVISIBLE(wineItem
))
1977 * If wParam is TRUE return the text size otherwise return
1978 * the whole item size
1982 /* Windows does not send TVN_GETDISPINFO here. */
1984 lpRect
->top
= wineItem
->rect
.top
;
1985 lpRect
->bottom
= wineItem
->rect
.bottom
;
1987 lpRect
->left
= wineItem
->textOffset
;
1988 lpRect
->right
= wineItem
->textOffset
+ wineItem
->textWidth
;
1992 *lpRect
= wineItem
->rect
;
1995 TRACE("%s [L:%ld R:%ld T:%ld B:%ld]\n", fTextRect
? "text" : "item",
1996 lpRect
->left
, lpRect
->right
, lpRect
->top
, lpRect
->bottom
);
2001 static inline LRESULT
2002 TREEVIEW_GetVisibleCount(TREEVIEW_INFO
*infoPtr
)
2004 /* Suprise! This does not take integral height into account. */
2005 return infoPtr
->clientHeight
/ infoPtr
->uItemHeight
;
2010 TREEVIEW_GetItemA(TREEVIEW_INFO
*infoPtr
, LPTVITEMEXA tvItem
)
2012 TREEVIEW_ITEM
*wineItem
;
2014 wineItem
= tvItem
->hItem
;
2015 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2018 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, tvItem
->mask
);
2020 if (tvItem
->mask
& TVIF_CHILDREN
)
2021 tvItem
->cChildren
= wineItem
->cChildren
;
2023 if (tvItem
->mask
& TVIF_HANDLE
)
2024 tvItem
->hItem
= wineItem
;
2026 if (tvItem
->mask
& TVIF_IMAGE
)
2027 tvItem
->iImage
= wineItem
->iImage
;
2029 if (tvItem
->mask
& TVIF_INTEGRAL
)
2030 tvItem
->iIntegral
= wineItem
->iIntegral
;
2032 /* undocumented: windows ignores TVIF_PARAM and
2033 * * always sets lParam
2035 tvItem
->lParam
= wineItem
->lParam
;
2037 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
)
2038 tvItem
->iSelectedImage
= wineItem
->iSelectedImage
;
2040 if (tvItem
->mask
& TVIF_STATE
) {
2041 /* Careful here - Windows ignores the stateMask when you get the state
2042 That contradicts the documentation, but makes more common sense, masking
2043 retrieval in this way seems overkill */
2044 tvItem
->state
= wineItem
->state
;
2047 if (tvItem
->mask
& TVIF_TEXT
)
2048 lstrcpynA(tvItem
->pszText
, wineItem
->pszText
, tvItem
->cchTextMax
);
2050 TRACE("item <%p>, txt %p, img %p, mask %x\n",
2051 wineItem
, tvItem
->pszText
, &tvItem
->iImage
, tvItem
->mask
);
2056 /* Beware MSDN Library Visual Studio 6.0. It says -1 on failure, 0 on success,
2057 * which is wrong. */
2059 TREEVIEW_SetItemA(TREEVIEW_INFO
*infoPtr
, LPTVITEMEXA tvItem
)
2061 TREEVIEW_ITEM
*wineItem
;
2062 TREEVIEW_ITEM originalItem
;
2064 wineItem
= tvItem
->hItem
;
2066 TRACE("item %d,mask %x\n", TREEVIEW_GetItemIndex(infoPtr
, wineItem
),
2069 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2072 /* store the orignal item values */
2073 originalItem
= *wineItem
;
2075 if (!TREEVIEW_DoSetItem(infoPtr
, wineItem
, tvItem
))
2078 /* If the text or TVIS_BOLD was changed, and it is visible, recalculate. */
2079 if ((tvItem
->mask
& TVIF_TEXT
2080 || (tvItem
->mask
& TVIF_STATE
&& tvItem
->stateMask
& TVIS_BOLD
))
2081 && ISVISIBLE(wineItem
))
2083 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, TVIF_TEXT
);
2084 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, 0);
2087 if (tvItem
->mask
!= 0 && ISVISIBLE(wineItem
))
2089 /* The refresh updates everything, but we can't wait until then. */
2090 TREEVIEW_ComputeItemInternalMetrics(infoPtr
, wineItem
);
2092 /* if any of the items values changed, redraw the item */
2093 if(memcmp(&originalItem
, wineItem
, sizeof(TREEVIEW_ITEM
)))
2095 if (tvItem
->mask
& TVIF_INTEGRAL
)
2097 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
2098 TREEVIEW_UpdateScrollBars(infoPtr
);
2100 TREEVIEW_Invalidate(infoPtr
, NULL
);
2104 TREEVIEW_UpdateScrollBars(infoPtr
);
2105 TREEVIEW_Invalidate(infoPtr
, wineItem
);
2114 TREEVIEW_GetItemW(TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
)
2116 TREEVIEW_ITEM
*wineItem
;
2118 iItem
= (INT
)tvItem
->hItem
;
2120 wineItem
= tvItem
->hItem
;
2121 if(!TREEVIEW_ValidItem (infoPtr
, wineItem
))
2124 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, tvItem
->mask
);
2126 if (tvItem
->mask
& TVIF_CHILDREN
) {
2127 if (TVIF_CHILDREN
==I_CHILDRENCALLBACK
)
2128 FIXME("I_CHILDRENCALLBACK not supported\n");
2129 tvItem
->cChildren
= wineItem
->cChildren
;
2132 if (tvItem
->mask
& TVIF_HANDLE
) {
2133 tvItem
->hItem
= wineItem
;
2135 if (tvItem
->mask
& TVIF_IMAGE
) {
2136 tvItem
->iImage
= wineItem
->iImage
;
2138 if (tvItem
->mask
& TVIF_INTEGRAL
) {
2139 tvItem
->iIntegral
= wineItem
->iIntegral
;
2141 /* undocumented: windows ignores TVIF_PARAM and
2142 * always sets lParam */
2143 tvItem
->lParam
= wineItem
->lParam
;
2144 if (tvItem
->mask
& TVIF_SELECTEDIMAGE
) {
2145 tvItem
->iSelectedImage
= wineItem
->iSelectedImage
;
2147 if (tvItem
->mask
& TVIF_STATE
) {
2148 tvItem
->state
= wineItem
->state
& tvItem
->stateMask
;
2151 if (tvItem
->mask
& TVIF_TEXT
) {
2152 if (wineItem
->pszText
== LPSTR_TEXTCALLBACKA
) {
2153 tvItem
->pszText
= LPSTR_TEXTCALLBACKW
;
2154 FIXME(" GetItem called with LPSTR_TEXTCALLBACK\n");
2156 else if (wineItem
->pszText
) {
2157 TRACE("orig str %s at %p\n",
2158 debugstr_a(wineItem
->pszText
), wineItem
->pszText
);
2159 MultiByteToWideChar(CP_ACP
, 0, wineItem
->pszText
,
2160 -1 , tvItem
->pszText
, tvItem
->cchTextMax
);
2164 TRACE("item %d<%p>, txt %p<%s>, img %p, action %x\n",
2165 iItem
, tvItem
, tvItem
->pszText
, debugstr_w(tvItem
->pszText
),
2166 &tvItem
->iImage
, tvItem
->mask
);
2171 TREEVIEW_SetItemW(TREEVIEW_INFO
*infoPtr
, LPTVITEMEXW tvItem
)
2177 tvItemA
.mask
= tvItem
->mask
;
2178 tvItemA
.hItem
= tvItem
->hItem
;
2179 tvItemA
.state
= tvItem
->state
;
2180 tvItemA
.stateMask
= tvItem
->stateMask
;
2181 if (tvItem
->mask
& TVIF_TEXT
) {
2182 len
= WideCharToMultiByte(CP_ACP
, 0, tvItem
->pszText
, -1,
2183 NULL
,0 , NULL
,NULL
);
2186 tvItemA
.pszText
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
2187 len
= WideCharToMultiByte(CP_ACP
, 0, tvItem
->pszText
, -1,
2188 tvItemA
.pszText
,len
*sizeof(WCHAR
),
2192 tvItemA
.pszText
= NULL
;
2194 tvItemA
.cchTextMax
= tvItem
->cchTextMax
;
2195 tvItemA
.iImage
= tvItem
->iImage
;
2196 tvItemA
.iSelectedImage
= tvItem
->iSelectedImage
;
2197 tvItemA
.cChildren
= tvItem
->cChildren
;
2198 tvItemA
.lParam
= tvItem
->lParam
;
2199 tvItemA
.iIntegral
= tvItem
->iIntegral
;
2201 rc
= TREEVIEW_SetItemA(infoPtr
,&tvItemA
);
2202 HeapFree(GetProcessHeap(),0,tvItemA
.pszText
);
2207 TREEVIEW_GetItemState(TREEVIEW_INFO
*infoPtr
, HTREEITEM wineItem
, UINT mask
)
2211 if (!wineItem
|| !TREEVIEW_ValidItem(infoPtr
, wineItem
))
2214 return (wineItem
->state
& mask
);
2218 TREEVIEW_GetNextItem(TREEVIEW_INFO
*infoPtr
, UINT which
, HTREEITEM wineItem
)
2220 TREEVIEW_ITEM
*retval
;
2224 /* handle all the global data here */
2227 case TVGN_CHILD
: /* Special case: child of 0 is root */
2232 retval
= infoPtr
->root
->firstChild
;
2236 retval
= infoPtr
->selectedItem
;
2239 case TVGN_FIRSTVISIBLE
:
2240 retval
= infoPtr
->firstVisible
;
2243 case TVGN_DROPHILITE
:
2244 retval
= infoPtr
->dropItem
;
2247 case TVGN_LASTVISIBLE
:
2248 retval
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
2254 TRACE("flags:%x, returns %p\n", which
, retval
);
2255 return (LRESULT
)retval
;
2258 if (wineItem
== TVI_ROOT
) wineItem
= infoPtr
->root
;
2260 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
2266 retval
= wineItem
->nextSibling
;
2269 retval
= wineItem
->prevSibling
;
2272 retval
= (wineItem
->parent
!= infoPtr
->root
) ? wineItem
->parent
: NULL
;
2275 retval
= wineItem
->firstChild
;
2277 case TVGN_NEXTVISIBLE
:
2278 retval
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
2280 case TVGN_PREVIOUSVISIBLE
:
2281 retval
= TREEVIEW_GetPrevListItem(infoPtr
, wineItem
);
2284 TRACE("Unknown msg %x,item %p\n", which
, wineItem
);
2288 TRACE("flags:%x, item %p;returns %p\n", which
, wineItem
, retval
);
2289 return (LRESULT
)retval
;
2294 TREEVIEW_GetCount(TREEVIEW_INFO
*infoPtr
)
2296 TRACE(" %d\n", infoPtr
->uNumItems
);
2297 return (LRESULT
)infoPtr
->uNumItems
;
2301 TREEVIEW_ToggleItemState(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2303 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
2305 static const unsigned int state_table
[] = { 0, 2, 1 };
2309 state
= STATEIMAGEINDEX(item
->state
);
2310 TRACE("state:%x\n", state
);
2311 item
->state
&= ~TVIS_STATEIMAGEMASK
;
2314 state
= state_table
[state
];
2316 item
->state
|= INDEXTOSTATEIMAGEMASK(state
);
2318 TRACE("state:%x\n", state
);
2319 TREEVIEW_Invalidate(infoPtr
, item
);
2324 /* Painting *************************************************************/
2326 /* Draw the lines and expand button for an item. Also draws one section
2327 * of the line from item's parent to item's parent's next sibling. */
2329 TREEVIEW_DrawItemLines(TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*item
)
2331 LONG centerx
, centery
;
2332 BOOL lar
= ((infoPtr
->dwStyle
2333 & (TVS_LINESATROOT
|TVS_HASLINES
|TVS_HASBUTTONS
))
2336 if (!lar
&& item
->iLevel
== 0)
2339 centerx
= (item
->linesOffset
+ item
->stateOffset
) / 2;
2340 centery
= (item
->rect
.top
+ item
->rect
.bottom
) / 2;
2342 if (infoPtr
->dwStyle
& TVS_HASLINES
)
2344 HPEN hOldPen
, hNewPen
;
2348 * Get a dotted grey pen
2350 hNewPen
= CreatePen(PS_ALTERNATE
, 0, infoPtr
->clrLine
);
2351 hOldPen
= SelectObject(hdc
, hNewPen
);
2353 MoveToEx(hdc
, item
->stateOffset
, centery
, NULL
);
2354 LineTo(hdc
, centerx
- 1, centery
);
2356 if (item
->prevSibling
|| item
->parent
!= infoPtr
->root
)
2358 MoveToEx(hdc
, centerx
, item
->rect
.top
, NULL
);
2359 LineTo(hdc
, centerx
, centery
);
2362 if (item
->nextSibling
)
2364 MoveToEx(hdc
, centerx
, centery
, NULL
);
2365 LineTo(hdc
, centerx
, item
->rect
.bottom
+ 1);
2368 /* Draw the line from our parent to its next sibling. */
2369 parent
= item
->parent
;
2370 while (parent
!= infoPtr
->root
)
2372 int pcenterx
= (parent
->linesOffset
+ parent
->stateOffset
) / 2;
2374 if (parent
->nextSibling
2375 /* skip top-levels unless TVS_LINESATROOT */
2376 && parent
->stateOffset
> parent
->linesOffset
)
2378 MoveToEx(hdc
, pcenterx
, item
->rect
.top
, NULL
);
2379 LineTo(hdc
, pcenterx
, item
->rect
.bottom
+ 1);
2382 parent
= parent
->parent
;
2385 SelectObject(hdc
, hOldPen
);
2386 DeleteObject(hNewPen
);
2390 * Display the (+/-) signs
2393 if (infoPtr
->dwStyle
& TVS_HASBUTTONS
)
2395 if (item
->cChildren
)
2397 LONG height
= item
->rect
.bottom
- item
->rect
.top
;
2398 LONG width
= item
->stateOffset
- item
->linesOffset
;
2399 LONG rectsize
= min(height
, width
) / 4;
2400 /* plussize = ceil(rectsize * 3/4) */
2401 LONG plussize
= (rectsize
+ 1) * 3 / 4;
2403 HPEN hNewPen
= CreatePen(PS_SOLID
, 0, infoPtr
->clrLine
);
2404 HPEN hOldPen
= SelectObject(hdc
, hNewPen
);
2405 HBRUSH hbr
= CreateSolidBrush(infoPtr
->clrBk
);
2406 HBRUSH hbrOld
= SelectObject(hdc
, hbr
);
2408 Rectangle(hdc
, centerx
- rectsize
, centery
- rectsize
,
2409 centerx
+ rectsize
+ 1, centery
+ rectsize
+ 1);
2411 SelectObject(hdc
, hbrOld
);
2414 SelectObject(hdc
, hOldPen
);
2415 DeleteObject(hNewPen
);
2417 MoveToEx(hdc
, centerx
- plussize
+ 1, centery
, NULL
);
2418 LineTo(hdc
, centerx
+ plussize
, centery
);
2420 if (!(item
->state
& TVIS_EXPANDED
))
2422 MoveToEx(hdc
, centerx
, centery
- plussize
+ 1, NULL
);
2423 LineTo(hdc
, centerx
, centery
+ plussize
);
2430 TREEVIEW_DrawItem(TREEVIEW_INFO
*infoPtr
, HDC hdc
, TREEVIEW_ITEM
*wineItem
)
2436 hOldFont
= SelectObject(hdc
, TREEVIEW_FontForItem(infoPtr
, wineItem
));
2438 TREEVIEW_UpdateDispInfo(infoPtr
, wineItem
, CALLBACK_MASK_ALL
);
2440 /* The custom draw handler can query the text rectangle,
2442 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, hdc
);
2446 if (infoPtr
->cdmode
& CDRF_NOTIFYITEMDRAW
)
2448 cditem
= TREEVIEW_SendCustomDrawItemNotify
2449 (infoPtr
, hdc
, wineItem
, CDDS_ITEMPREPAINT
);
2450 TRACE("prepaint:cditem-app returns 0x%x\n", cditem
);
2452 if (cditem
& CDRF_SKIPDEFAULT
)
2454 SelectObject(hdc
, hOldFont
);
2459 if (cditem
& CDRF_NEWFONT
)
2460 TREEVIEW_ComputeTextWidth(infoPtr
, wineItem
, hdc
);
2462 TREEVIEW_DrawItemLines(infoPtr
, hdc
, wineItem
);
2464 centery
= (wineItem
->rect
.top
+ wineItem
->rect
.bottom
) / 2;
2467 * Display the images associated with this item
2472 /* State images are displayed to the left of the Normal image
2473 * image number is in state; zero should be `display no image'.
2475 imageIndex
= STATEIMAGEINDEX(wineItem
->state
);
2477 if (infoPtr
->himlState
&& imageIndex
)
2479 ImageList_Draw(infoPtr
->himlState
, imageIndex
, hdc
,
2480 wineItem
->stateOffset
,
2481 centery
- infoPtr
->stateImageHeight
/ 2,
2485 /* Now, draw the normal image; can be either selected or
2486 * non-selected image.
2489 if ((wineItem
->state
& TVIS_SELECTED
) && (wineItem
->iSelectedImage
))
2491 /* The item is currently selected */
2492 imageIndex
= wineItem
->iSelectedImage
;
2496 /* The item is not selected */
2497 imageIndex
= wineItem
->iImage
;
2500 if (infoPtr
->himlNormal
)
2502 int ovlIdx
= wineItem
->state
& TVIS_OVERLAYMASK
;
2504 ImageList_Draw(infoPtr
->himlNormal
, imageIndex
, hdc
,
2505 wineItem
->imageOffset
,
2506 centery
- infoPtr
->normalImageHeight
/ 2,
2507 ILD_NORMAL
| ovlIdx
);
2513 * Display the text associated with this item
2516 /* Don't paint item's text if it's being edited */
2517 if (!infoPtr
->hwndEdit
|| (infoPtr
->selectedItem
!= wineItem
))
2519 if (wineItem
->pszText
)
2521 COLORREF oldTextColor
= 0;
2524 BOOL inFocus
= (GetFocus() == infoPtr
->hwnd
);
2527 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
2529 /* - If item is drop target or it is selected and window is in focus -
2530 * use blue background (COLOR_HIGHLIGHT).
2531 * - If item is selected, window is not in focus, but it has style
2532 * TVS_SHOWSELALWAYS - use grey background (COLOR_BTNFACE)
2533 * - Otherwise - don't fill background
2535 if ((wineItem
->state
& TVIS_DROPHILITED
) || ((wineItem
== infoPtr
->focusedItem
) && !(wineItem
->state
& TVIS_SELECTED
)) ||
2536 ((wineItem
->state
& TVIS_SELECTED
) && (!infoPtr
->focusedItem
) &&
2537 (inFocus
|| (infoPtr
->dwStyle
& TVS_SHOWSELALWAYS
))))
2539 if ((wineItem
->state
& TVIS_DROPHILITED
) || inFocus
)
2541 hbrBk
= CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT
));
2543 SetTextColor(hdc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2547 hbrBk
= CreateSolidBrush(GetSysColor(COLOR_BTNFACE
));
2549 if (infoPtr
->clrText
== -1)
2551 SetTextColor(hdc
, GetSysColor(COLOR_WINDOWTEXT
));
2553 oldTextColor
= SetTextColor(hdc
, infoPtr
->clrText
);
2558 if (infoPtr
->clrText
== -1)
2560 SetTextColor(hdc
, GetSysColor(COLOR_WINDOWTEXT
));
2562 oldTextColor
= SetTextColor(hdc
, infoPtr
->clrText
);
2565 rcText
.top
= wineItem
->rect
.top
;
2566 rcText
.bottom
= wineItem
->rect
.bottom
;
2567 rcText
.left
= wineItem
->textOffset
;
2568 rcText
.right
= rcText
.left
+ wineItem
->textWidth
+ 4;
2572 FillRect(hdc
, &rcText
, hbrBk
);
2573 DeleteObject(hbrBk
);
2576 /* Draw the box around the selected item */
2577 if ((wineItem
== infoPtr
->selectedItem
) && inFocus
)
2579 DrawFocusRect(hdc
,&rcText
);
2582 InflateRect(&rcText
, -2, -1); /* allow for the focus rect */
2584 TRACE("drawing text %s at (%ld,%ld)-(%ld,%ld)\n",
2585 debugstr_a(wineItem
->pszText
),
2586 rcText
.left
, rcText
.top
, rcText
.right
, rcText
.bottom
);
2591 lstrlenA(wineItem
->pszText
),
2593 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
| DT_NOPREFIX
);
2595 /* Restore the hdc state */
2596 SetTextColor(hdc
, oldTextColor
);
2598 if (oldBkMode
!= TRANSPARENT
)
2599 SetBkMode(hdc
, oldBkMode
);
2603 /* Draw insertion mark if necessary */
2605 if (infoPtr
->insertMarkItem
)
2606 TRACE("item:%d,mark:%d\n",
2607 TREEVIEW_GetItemIndex(infoPtr
, wineItem
),
2608 (int)infoPtr
->insertMarkItem
);
2610 if (wineItem
== infoPtr
->insertMarkItem
)
2612 HPEN hNewPen
, hOldPen
;
2616 hNewPen
= CreatePen(PS_SOLID
, 2, infoPtr
->clrInsertMark
);
2617 hOldPen
= SelectObject(hdc
, hNewPen
);
2619 if (infoPtr
->insertBeforeorAfter
)
2620 offset
= wineItem
->rect
.bottom
- 1;
2622 offset
= wineItem
->rect
.top
+ 1;
2624 left
= wineItem
->textOffset
- 2;
2625 right
= wineItem
->textOffset
+ wineItem
->textWidth
+ 2;
2627 MoveToEx(hdc
, left
, offset
- 3, NULL
);
2628 LineTo(hdc
, left
, offset
+ 4);
2630 MoveToEx(hdc
, left
, offset
, NULL
);
2631 LineTo(hdc
, right
+ 1, offset
);
2633 MoveToEx(hdc
, right
, offset
+ 3, NULL
);
2634 LineTo(hdc
, right
, offset
- 4);
2636 SelectObject(hdc
, hOldPen
);
2637 DeleteObject(hNewPen
);
2640 if (cditem
& CDRF_NOTIFYPOSTPAINT
)
2642 cditem
= TREEVIEW_SendCustomDrawItemNotify
2643 (infoPtr
, hdc
, wineItem
, CDDS_ITEMPOSTPAINT
);
2644 TRACE("postpaint:cditem-app returns 0x%x\n", cditem
);
2647 SelectObject(hdc
, hOldFont
);
2650 /* Computes treeHeight and treeWidth and updates the scroll bars.
2653 TREEVIEW_UpdateScrollBars(TREEVIEW_INFO
*infoPtr
)
2655 TREEVIEW_ITEM
*wineItem
;
2656 HWND hwnd
= infoPtr
->hwnd
;
2660 LONG scrollX
= infoPtr
->scrollX
;
2662 infoPtr
->treeWidth
= 0;
2663 infoPtr
->treeHeight
= 0;
2665 /* We iterate through all visible items in order to get the tree height
2667 wineItem
= infoPtr
->root
->firstChild
;
2669 while (wineItem
!= NULL
)
2671 if (ISVISIBLE(wineItem
))
2673 /* actually we draw text at textOffset + 2 */
2674 if (2+wineItem
->textOffset
+wineItem
->textWidth
> infoPtr
->treeWidth
)
2675 infoPtr
->treeWidth
= wineItem
->textOffset
+wineItem
->textWidth
+2;
2677 /* This is scroll-adjusted, but we fix this below. */
2678 infoPtr
->treeHeight
= wineItem
->rect
.bottom
;
2681 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
2684 /* Fix the scroll adjusted treeHeight and treeWidth. */
2685 if (infoPtr
->root
->firstChild
)
2686 infoPtr
->treeHeight
-= infoPtr
->root
->firstChild
->rect
.top
;
2688 infoPtr
->treeWidth
+= infoPtr
->scrollX
;
2690 if (infoPtr
->dwStyle
& TVS_NOSCROLL
) return;
2692 /* Adding one scroll bar may take up enough space that it forces us
2693 * to add the other as well. */
2694 if (infoPtr
->treeHeight
> infoPtr
->clientHeight
)
2698 if (infoPtr
->treeWidth
2699 > infoPtr
->clientWidth
- GetSystemMetrics(SM_CXVSCROLL
))
2702 else if (infoPtr
->treeWidth
> infoPtr
->clientWidth
)
2705 if (!vert
&& horz
&& infoPtr
->treeHeight
2706 > infoPtr
->clientHeight
- GetSystemMetrics(SM_CYVSCROLL
))
2709 if (horz
&& (infoPtr
->dwStyle
& TVS_NOHSCROLL
)) horz
= FALSE
;
2711 si
.cbSize
= sizeof(SCROLLINFO
);
2712 si
.fMask
= SIF_POS
|SIF_RANGE
|SIF_PAGE
;
2717 si
.nPage
= TREEVIEW_GetVisibleCount(infoPtr
);
2720 si
.nPos
= infoPtr
->firstVisible
->visibleOrder
;
2721 si
.nMax
= infoPtr
->maxVisibleOrder
- 1;
2723 SetScrollInfo(hwnd
, SB_VERT
, &si
, TRUE
);
2725 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
2726 ShowScrollBar(hwnd
, SB_VERT
, TRUE
);
2727 infoPtr
->uInternalStatus
|= TV_VSCROLL
;
2731 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2732 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2733 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2738 if (infoPtr
->uInternalStatus
& TV_VSCROLL
)
2739 ShowScrollBar(hwnd
, SB_VERT
, FALSE
);
2740 infoPtr
->uInternalStatus
&= ~TV_VSCROLL
;
2745 si
.nPage
= infoPtr
->clientWidth
;
2746 si
.nPos
= infoPtr
->scrollX
;
2747 si
.nMax
= infoPtr
->treeWidth
- 1;
2749 if (si
.nPos
> si
.nMax
- max( si
.nPage
-1, 0 ))
2751 si
.nPos
= si
.nMax
- max( si
.nPage
-1, 0 );
2755 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
2756 ShowScrollBar(hwnd
, SB_HORZ
, TRUE
);
2757 infoPtr
->uInternalStatus
|= TV_HSCROLL
;
2759 SetScrollInfo(hwnd
, SB_HORZ
, &si
, TRUE
);
2763 if (infoPtr
->uInternalStatus
& TV_HSCROLL
)
2764 ShowScrollBar(hwnd
, SB_HORZ
, FALSE
);
2765 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2770 if (infoPtr
->scrollX
!= scrollX
)
2772 TREEVIEW_HScroll(infoPtr
,
2773 MAKEWPARAM(SB_THUMBPOSITION
, scrollX
));
2777 infoPtr
->uInternalStatus
&= ~TV_HSCROLL
;
2780 /* CtrlSpy doesn't mention this, but CorelDRAW's object manager needs it. */
2782 TREEVIEW_EraseBackground(TREEVIEW_INFO
*infoPtr
, HDC hDC
)
2784 HBRUSH hBrush
= CreateSolidBrush(infoPtr
->clrBk
);
2787 GetClientRect(infoPtr
->hwnd
, &rect
);
2788 FillRect(hDC
, &rect
, hBrush
);
2789 DeleteObject(hBrush
);
2795 TREEVIEW_Refresh(TREEVIEW_INFO
*infoPtr
, HDC hdc
, RECT
*rc
)
2797 HWND hwnd
= infoPtr
->hwnd
;
2799 TREEVIEW_ITEM
*wineItem
;
2801 if (infoPtr
->clientHeight
== 0 || infoPtr
->clientWidth
== 0)
2803 TRACE("empty window\n");
2807 infoPtr
->cdmode
= TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_PREPAINT
,
2810 if (infoPtr
->cdmode
== CDRF_SKIPDEFAULT
)
2812 ReleaseDC(hwnd
, hdc
);
2816 for (wineItem
= infoPtr
->root
->firstChild
;
2818 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
))
2820 if (ISVISIBLE(wineItem
))
2822 /* Avoid unneeded calculations */
2823 if (wineItem
->rect
.top
> rect
.bottom
)
2825 if (wineItem
->rect
.bottom
< rect
.top
)
2828 TREEVIEW_DrawItem(infoPtr
, hdc
, wineItem
);
2832 TREEVIEW_UpdateScrollBars(infoPtr
);
2834 if (infoPtr
->cdmode
& CDRF_NOTIFYPOSTPAINT
)
2836 TREEVIEW_SendCustomDrawNotify(infoPtr
, CDDS_POSTPAINT
, hdc
, rect
);
2840 TREEVIEW_Invalidate(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2843 InvalidateRect(infoPtr
->hwnd
, &item
->rect
, TRUE
);
2845 InvalidateRect(infoPtr
->hwnd
, NULL
, TRUE
);
2849 TREEVIEW_Paint(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
2860 if (!GetUpdateRect(infoPtr
->hwnd
, &rc
, TRUE
))
2864 hbitmap
= GetCurrentObject(hdc
, OBJ_BITMAP
);
2865 if (!hbitmap
) return 0;
2866 GetObjectA(hbitmap
, sizeof(BITMAP
), &bitmap
);
2867 rc
.left
= 0; rc
.top
= 0;
2868 rc
.right
= bitmap
.bmWidth
;
2869 rc
.bottom
= bitmap
.bmHeight
;
2870 TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
2875 hdc
= BeginPaint(infoPtr
->hwnd
, &ps
);
2879 if(infoPtr
->bRedraw
) /* WM_SETREDRAW sets bRedraw */
2880 TREEVIEW_Refresh(infoPtr
, hdc
, &rc
);
2883 EndPaint(infoPtr
->hwnd
, &ps
);
2889 /* Sorting **************************************************************/
2891 /***************************************************************************
2892 * Forward the DPA local callback to the treeview owner callback
2895 TREEVIEW_CallBackCompare(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
, LPTVSORTCB pCallBackSort
)
2897 /* Forward the call to the client-defined callback */
2898 return pCallBackSort
->lpfnCompare(first
->lParam
,
2900 pCallBackSort
->lParam
);
2903 /***************************************************************************
2904 * Treeview native sort routine: sort on item text.
2907 TREEVIEW_SortOnName(TREEVIEW_ITEM
*first
, TREEVIEW_ITEM
*second
,
2908 TREEVIEW_INFO
*infoPtr
)
2910 TREEVIEW_UpdateDispInfo(infoPtr
, first
, TVIF_TEXT
);
2911 TREEVIEW_UpdateDispInfo(infoPtr
, second
, TVIF_TEXT
);
2913 return strcasecmp(first
->pszText
, second
->pszText
);
2916 /* Returns the number of physical children belonging to item. */
2918 TREEVIEW_CountChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2923 for (hti
= item
->firstChild
; hti
!= NULL
; hti
= hti
->nextSibling
)
2929 /* Returns a DPA containing a pointer to each physical child of item in
2930 * sibling order. If item has no children, an empty DPA is returned. */
2932 TREEVIEW_BuildChildDPA(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
2934 HTREEITEM child
= item
->firstChild
;
2936 HDPA list
= DPA_Create(8);
2937 if (list
== 0) return NULL
;
2939 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
2941 if (DPA_InsertPtr(list
, INT_MAX
, child
) == -1)
2951 /***************************************************************************
2952 * Setup the treeview structure with regards of the sort method
2953 * and sort the children of the TV item specified in lParam
2954 * fRecurse: currently unused. Should be zero.
2955 * parent: if pSort!=NULL, should equal pSort->hParent.
2956 * otherwise, item which child items are to be sorted.
2957 * pSort: sort method info. if NULL, sort on item text.
2958 * if non-NULL, sort on item's lParam content, and let the
2959 * application decide what that means. See also TVM_SORTCHILDRENCB.
2963 TREEVIEW_Sort(TREEVIEW_INFO
*infoPtr
, BOOL fRecurse
, HTREEITEM parent
,
2967 PFNDPACOMPARE pfnCompare
;
2970 /* undocumented feature: TVI_ROOT or NULL means `sort the whole tree' */
2971 if (parent
== TVI_ROOT
|| parent
== NULL
)
2972 parent
= infoPtr
->root
;
2974 /* Check for a valid handle to the parent item */
2975 if (!TREEVIEW_ValidItem(infoPtr
, parent
))
2977 ERR("invalid item hParent=%x\n", (INT
)parent
);
2983 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_CallBackCompare
;
2984 lpCompare
= (LPARAM
)pSort
;
2988 pfnCompare
= (PFNDPACOMPARE
)TREEVIEW_SortOnName
;
2989 lpCompare
= (LPARAM
)infoPtr
;
2992 cChildren
= TREEVIEW_CountChildren(infoPtr
, parent
);
2994 /* Make sure there is something to sort */
2997 /* TREEVIEW_ITEM rechaining */
3000 HTREEITEM nextItem
= 0;
3001 HTREEITEM prevItem
= 0;
3003 HDPA sortList
= TREEVIEW_BuildChildDPA(infoPtr
, parent
);
3005 if (sortList
== NULL
)
3008 /* let DPA sort the list */
3009 DPA_Sort(sortList
, pfnCompare
, lpCompare
);
3011 /* The order of DPA entries has been changed, so fixup the
3012 * nextSibling and prevSibling pointers. */
3014 item
= (HTREEITEM
)DPA_GetPtr(sortList
, count
++);
3015 while ((nextItem
= (HTREEITEM
)DPA_GetPtr(sortList
, count
++)) != NULL
)
3017 /* link the two current item toghether */
3018 item
->nextSibling
= nextItem
;
3019 nextItem
->prevSibling
= item
;
3021 if (prevItem
== NULL
)
3023 /* this is the first item, update the parent */
3024 parent
->firstChild
= item
;
3025 item
->prevSibling
= NULL
;
3029 /* fix the back chaining */
3030 item
->prevSibling
= prevItem
;
3033 /* get ready for the next one */
3038 /* the last item is pointed to by item and never has a sibling */
3039 item
->nextSibling
= NULL
;
3040 parent
->lastChild
= item
;
3042 DPA_Destroy(sortList
);
3044 TREEVIEW_VerifyTree(infoPtr
);
3046 if (parent
->state
& TVIS_EXPANDED
)
3048 int visOrder
= infoPtr
->firstVisible
->visibleOrder
;
3050 if (parent
== infoPtr
->root
)
3051 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
3053 TREEVIEW_RecalculateVisibleOrder(infoPtr
, parent
);
3055 if (TREEVIEW_IsChildOf(parent
, infoPtr
->firstVisible
))
3057 TREEVIEW_ITEM
*item
;
3059 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
3060 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3062 if (item
->visibleOrder
== visOrder
)
3066 if (!item
) item
= parent
->firstChild
;
3067 TREEVIEW_SetFirstVisible(infoPtr
, item
, FALSE
);
3070 TREEVIEW_Invalidate(infoPtr
, NULL
);
3079 /***************************************************************************
3080 * Setup the treeview structure with regards of the sort method
3081 * and sort the children of the TV item specified in lParam
3084 TREEVIEW_SortChildrenCB(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPTVSORTCB pSort
)
3086 return TREEVIEW_Sort(infoPtr
, wParam
, pSort
->hParent
, pSort
);
3090 /***************************************************************************
3091 * Sort the children of the TV item specified in lParam.
3094 TREEVIEW_SortChildren(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3096 return TREEVIEW_Sort(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
, NULL
);
3100 /* Expansion/Collapse ***************************************************/
3103 TREEVIEW_SendExpanding(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3106 return !TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDINGW
, action
,
3107 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3108 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3113 TREEVIEW_SendExpanded(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3116 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_ITEMEXPANDEDW
, action
,
3117 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
3118 | TVIF_IMAGE
| TVIF_SELECTEDIMAGE
,
3123 /* This corresponds to TVM_EXPAND with TVE_COLLAPSE.
3124 * bRemoveChildren corresponds to TVE_COLLAPSERESET. */
3126 TREEVIEW_Collapse(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3127 BOOL bRemoveChildren
, BOOL bUser
)
3129 UINT action
= TVE_COLLAPSE
| (bRemoveChildren
? TVE_COLLAPSERESET
: 0);
3130 BOOL bSetSelection
, bSetFirstVisible
;
3132 TRACE("TVE_COLLAPSE %p %s\n", wineItem
, TREEVIEW_ItemName(wineItem
));
3134 if (!(wineItem
->state
& TVIS_EXPANDED
))
3138 TREEVIEW_SendExpanding(infoPtr
, wineItem
, action
);
3140 if (wineItem
->firstChild
== NULL
)
3143 wineItem
->state
&= ~TVIS_EXPANDED
;
3146 TREEVIEW_SendExpanded(infoPtr
, wineItem
, action
);
3148 bSetSelection
= (infoPtr
->selectedItem
!= NULL
3149 && TREEVIEW_IsChildOf(wineItem
, infoPtr
->selectedItem
));
3151 bSetFirstVisible
= (infoPtr
->firstVisible
!= NULL
3152 && TREEVIEW_IsChildOf(wineItem
, infoPtr
->firstVisible
));
3154 if (bRemoveChildren
)
3156 TRACE("TVE_COLLAPSERESET\n");
3157 wineItem
->state
&= ~TVIS_EXPANDEDONCE
;
3158 TREEVIEW_RemoveAllChildren(infoPtr
, wineItem
);
3161 if (wineItem
->firstChild
)
3163 TREEVIEW_ITEM
*item
, *sibling
;
3165 sibling
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
);
3167 for (item
= wineItem
->firstChild
; item
!= sibling
;
3168 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
3170 item
->visibleOrder
= -1;
3174 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
3176 TREEVIEW_SetFirstVisible(infoPtr
, bSetFirstVisible
? wineItem
3177 : infoPtr
->firstVisible
, TRUE
);
3181 /* Don't call DoSelectItem, it sends notifications. */
3182 if (TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3183 infoPtr
->selectedItem
->state
&= ~TVIS_SELECTED
;
3184 wineItem
->state
|= TVIS_SELECTED
;
3185 infoPtr
->selectedItem
= wineItem
;
3187 TREEVIEW_EnsureVisible(infoPtr
, wineItem
, FALSE
);
3190 TREEVIEW_UpdateScrollBars(infoPtr
);
3191 TREEVIEW_Invalidate(infoPtr
, NULL
);
3197 TREEVIEW_Expand(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
,
3198 BOOL bExpandPartial
, BOOL bUser
)
3202 if (wineItem
->state
& TVIS_EXPANDED
)
3205 TRACE("TVE_EXPAND %p %s\n", wineItem
, TREEVIEW_ItemName(wineItem
));
3207 if (bUser
|| ((wineItem
->cChildren
!= 0) &&
3208 !(wineItem
->state
& TVIS_EXPANDEDONCE
)))
3210 if (!TREEVIEW_SendExpanding(infoPtr
, wineItem
, TVE_EXPAND
))
3212 TRACE(" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3216 if (!wineItem
->firstChild
)
3219 wineItem
->state
|= TVIS_EXPANDED
;
3220 TREEVIEW_SendExpanded(infoPtr
, wineItem
, TVE_EXPAND
);
3221 wineItem
->state
|= TVIS_EXPANDEDONCE
;
3225 if (!wineItem
->firstChild
)
3228 /* this item has already been expanded */
3229 wineItem
->state
|= TVIS_EXPANDED
;
3233 FIXME("TVE_EXPANDPARTIAL not implemented\n");
3235 TREEVIEW_RecalculateVisibleOrder(infoPtr
, wineItem
);
3236 TREEVIEW_UpdateSubTree(infoPtr
, wineItem
);
3237 TREEVIEW_UpdateScrollBars(infoPtr
);
3239 /* Scroll up so that as many children as possible are visible.
3240 * This looses when expanding causes an HScroll bar to appear, but we
3241 * don't know that yet, so the last item is obscured. */
3242 if (wineItem
->firstChild
!= NULL
)
3244 int nChildren
= wineItem
->lastChild
->visibleOrder
3245 - wineItem
->firstChild
->visibleOrder
+ 1;
3247 int visible_pos
= wineItem
->visibleOrder
3248 - infoPtr
->firstVisible
->visibleOrder
;
3250 int rows_below
= TREEVIEW_GetVisibleCount(infoPtr
) - visible_pos
- 1;
3252 if (visible_pos
> 0 && nChildren
> rows_below
)
3254 int scroll
= nChildren
- rows_below
;
3256 if (scroll
> visible_pos
)
3257 scroll
= visible_pos
;
3261 TREEVIEW_ITEM
*newFirstVisible
3262 = TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
3266 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
3271 TREEVIEW_Invalidate(infoPtr
, NULL
);
3277 TREEVIEW_Toggle(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*wineItem
, BOOL bUser
)
3281 if (wineItem
->state
& TVIS_EXPANDED
)
3282 return TREEVIEW_Collapse(infoPtr
, wineItem
, FALSE
, bUser
);
3284 return TREEVIEW_Expand(infoPtr
, wineItem
, FALSE
, bUser
);
3288 TREEVIEW_ExpandAll(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
3290 TREEVIEW_Expand(infoPtr
, item
, FALSE
, TRUE
);
3292 for (item
= item
->firstChild
; item
!= NULL
; item
= item
->nextSibling
)
3294 if (TREEVIEW_HasChildren(infoPtr
, item
))
3295 TREEVIEW_ExpandAll(infoPtr
, item
);
3299 /* Note:If the specified item is the child of a collapsed parent item,
3300 the parent's list of child items is (recursively) expanded to reveal the
3301 specified item. This is mentioned for TREEVIEW_SelectItem; don't
3302 know if it also applies here.
3306 TREEVIEW_ExpandMsg(TREEVIEW_INFO
*infoPtr
, UINT flag
, HTREEITEM wineItem
)
3308 if (!TREEVIEW_ValidItem(infoPtr
, wineItem
))
3311 TRACE("For (%s) item:%d, flags %x, state:%d\n",
3312 TREEVIEW_ItemName(wineItem
), flag
,
3313 TREEVIEW_GetItemIndex(infoPtr
, wineItem
), wineItem
->state
);
3315 switch (flag
& TVE_TOGGLE
)
3318 return TREEVIEW_Collapse(infoPtr
, wineItem
, flag
& TVE_COLLAPSERESET
,
3322 return TREEVIEW_Expand(infoPtr
, wineItem
, flag
& TVE_EXPANDPARTIAL
,
3326 return TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3333 TRACE("Exiting, Item %p state is now %d...\n", wineItem
, wineItem
->state
);
3337 /* Hit-Testing **********************************************************/
3339 static TREEVIEW_ITEM
*
3340 TREEVIEW_HitTestPoint(TREEVIEW_INFO
*infoPtr
, POINT pt
)
3342 TREEVIEW_ITEM
*wineItem
;
3345 if (!infoPtr
->firstVisible
)
3348 row
= pt
.y
/ infoPtr
->uItemHeight
+ infoPtr
->firstVisible
->visibleOrder
;
3350 for (wineItem
= infoPtr
->firstVisible
; wineItem
!= NULL
;
3351 wineItem
= TREEVIEW_GetNextListItem(infoPtr
, wineItem
))
3353 if (row
>= wineItem
->visibleOrder
3354 && row
< wineItem
->visibleOrder
+ wineItem
->iIntegral
)
3362 TREEVIEW_HitTest(TREEVIEW_INFO
*infoPtr
, LPTVHITTESTINFO lpht
)
3364 TREEVIEW_ITEM
*wineItem
;
3370 GetClientRect(infoPtr
->hwnd
, &rect
);
3377 status
|= TVHT_TOLEFT
;
3379 else if (x
> rect
.right
)
3381 status
|= TVHT_TORIGHT
;
3386 status
|= TVHT_ABOVE
;
3388 else if (y
> rect
.bottom
)
3390 status
|= TVHT_BELOW
;
3395 lpht
->flags
= status
;
3396 return (LRESULT
)(HTREEITEM
)NULL
;
3399 wineItem
= TREEVIEW_HitTestPoint(infoPtr
, lpht
->pt
);
3402 lpht
->flags
= TVHT_NOWHERE
;
3403 return (LRESULT
)(HTREEITEM
)NULL
;
3406 if (x
>= wineItem
->textOffset
+ wineItem
->textWidth
)
3408 lpht
->flags
= TVHT_ONITEMRIGHT
;
3410 else if (x
>= wineItem
->textOffset
)
3412 lpht
->flags
= TVHT_ONITEMLABEL
;
3414 else if (x
>= wineItem
->imageOffset
)
3416 lpht
->flags
= TVHT_ONITEMICON
;
3418 else if (x
>= wineItem
->stateOffset
)
3420 lpht
->flags
= TVHT_ONITEMSTATEICON
;
3422 else if (x
>= wineItem
->linesOffset
&& infoPtr
->dwStyle
& TVS_HASBUTTONS
)
3424 lpht
->flags
= TVHT_ONITEMBUTTON
;
3428 lpht
->flags
= TVHT_ONITEMINDENT
;
3431 lpht
->hItem
= wineItem
;
3432 TRACE("(%ld,%ld):result %x\n", lpht
->pt
.x
, lpht
->pt
.y
, lpht
->flags
);
3434 return (LRESULT
)wineItem
;
3437 /* Item Label Editing ***************************************************/
3440 TREEVIEW_GetEditControl(TREEVIEW_INFO
*infoPtr
)
3442 return (LRESULT
)infoPtr
->hwndEdit
;
3445 static LRESULT CALLBACK
3446 TREEVIEW_Edit_SubclassProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
3448 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(GetParent(hwnd
));
3449 BOOL bCancel
= FALSE
;
3455 TRACE("WM_PAINT start\n");
3456 rc
= CallWindowProcA(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
,
3458 TRACE("WM_PAINT done\n");
3462 if (infoPtr
->bIgnoreEditKillFocus
)
3467 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
3470 if (wParam
== (WPARAM
)VK_ESCAPE
)
3475 else if (wParam
== (WPARAM
)VK_RETURN
)
3482 return CallWindowProcA(infoPtr
->wpEditOrig
, hwnd
, uMsg
, wParam
, lParam
);
3485 /* Processing TVN_ENDLABELEDIT message could kill the focus */
3486 /* eg. Using a messagebox */
3488 infoPtr
->bIgnoreEditKillFocus
= TRUE
;
3489 TREEVIEW_EndEditLabelNow(infoPtr
, bCancel
|| !infoPtr
->bLabelChanged
);
3490 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
3496 /* should handle edit control messages here */
3499 TREEVIEW_Command(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
3501 TRACE("%x %ld\n", wParam
, lParam
);
3503 switch (HIWORD(wParam
))
3508 * Adjust the edit window size
3511 TREEVIEW_ITEM
*editItem
= infoPtr
->selectedItem
;
3512 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
3515 HFONT hFont
, hOldFont
= 0;
3517 infoPtr
->bLabelChanged
= TRUE
;
3519 len
= GetWindowTextA(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
));
3521 /* Select font to get the right dimension of the string */
3522 hFont
= (HFONT
)SendMessageA(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
3525 hOldFont
= SelectObject(hdc
, hFont
);
3528 if (GetTextExtentPoint32A(hdc
, buffer
, strlen(buffer
), &sz
))
3530 TEXTMETRICA textMetric
;
3532 /* Add Extra spacing for the next character */
3533 GetTextMetricsA(hdc
, &textMetric
);
3534 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3536 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3538 infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3540 SetWindowPos(infoPtr
->hwndEdit
,
3545 editItem
->rect
.bottom
- editItem
->rect
.top
+ 3,
3546 SWP_NOMOVE
| SWP_DRAWFRAME
);
3551 SelectObject(hdc
, hOldFont
);
3554 ReleaseDC(infoPtr
->hwnd
, hdc
);
3559 return SendMessageA(infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
3566 TREEVIEW_EditLabelA(TREEVIEW_INFO
*infoPtr
, HTREEITEM hItem
)
3568 HWND hwnd
= infoPtr
->hwnd
;
3571 TREEVIEW_ITEM
*editItem
= hItem
;
3572 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongA(hwnd
, GWL_HINSTANCE
);
3575 TEXTMETRICA textMetric
;
3577 TRACE("%x %p\n", (unsigned)hwnd
, hItem
);
3578 if (!TREEVIEW_ValidItem(infoPtr
, editItem
))
3581 if (infoPtr
->hwndEdit
)
3582 return infoPtr
->hwndEdit
;
3584 infoPtr
->bLabelChanged
= FALSE
;
3586 /* Make sure that edit item is selected */
3587 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, hItem
, TVC_UNKNOWN
);
3588 TREEVIEW_EnsureVisible(infoPtr
, hItem
, TRUE
);
3590 TREEVIEW_UpdateDispInfo(infoPtr
, editItem
, TVIF_TEXT
);
3593 /* Select the font to get appropriate metric dimensions */
3594 if (infoPtr
->hFont
!= 0)
3596 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
3599 /* Get string length in pixels */
3600 GetTextExtentPoint32A(hdc
, editItem
->pszText
, strlen(editItem
->pszText
),
3603 /* Add Extra spacing for the next character */
3604 GetTextMetricsA(hdc
, &textMetric
);
3605 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
3607 sz
.cx
= max(sz
.cx
, textMetric
.tmMaxCharWidth
* 3);
3608 sz
.cx
= min(sz
.cx
, infoPtr
->clientWidth
- editItem
->textOffset
+ 2);
3610 if (infoPtr
->hFont
!= 0)
3612 SelectObject(hdc
, hOldFont
);
3615 ReleaseDC(hwnd
, hdc
);
3616 hwndEdit
= CreateWindowExA(WS_EX_LEFT
,
3619 WS_CHILD
| WS_BORDER
| ES_AUTOHSCROLL
|
3620 WS_CLIPSIBLINGS
| ES_WANTRETURN
|
3621 ES_LEFT
, editItem
->textOffset
- 2,
3622 editItem
->rect
.top
- 1, sz
.cx
+ 3,
3623 editItem
->rect
.bottom
-
3624 editItem
->rect
.top
+ 3, hwnd
, 0, hinst
, 0);
3625 /* FIXME: (HMENU)IDTVEDIT,pcs->hInstance,0); */
3627 infoPtr
->hwndEdit
= hwndEdit
;
3629 /* Get a 2D border. */
3630 SetWindowLongA(hwndEdit
, GWL_EXSTYLE
,
3631 GetWindowLongA(hwndEdit
, GWL_EXSTYLE
) & ~WS_EX_CLIENTEDGE
);
3632 SetWindowLongA(hwndEdit
, GWL_STYLE
,
3633 GetWindowLongA(hwndEdit
, GWL_STYLE
) | WS_BORDER
);
3635 SendMessageA(hwndEdit
, WM_SETFONT
,
3636 (WPARAM
)TREEVIEW_FontForItem(infoPtr
, editItem
), FALSE
);
3638 infoPtr
->wpEditOrig
= (WNDPROC
)SetWindowLongA(hwndEdit
, GWL_WNDPROC
,
3640 TREEVIEW_Edit_SubclassProc
);
3642 if (TREEVIEW_BeginLabelEditNotify(infoPtr
, editItem
))
3644 DestroyWindow(hwndEdit
);
3645 infoPtr
->hwndEdit
= 0;
3649 infoPtr
->selectedItem
= hItem
;
3650 SetWindowTextA(hwndEdit
, editItem
->pszText
);
3652 SendMessageA(hwndEdit
, EM_SETSEL
, 0, -1);
3653 ShowWindow(hwndEdit
, SW_SHOW
);
3660 TREEVIEW_EndEditLabelNow(TREEVIEW_INFO
*infoPtr
, BOOL bCancel
)
3662 HWND hwnd
= infoPtr
->hwnd
;
3663 TREEVIEW_ITEM
*editedItem
= infoPtr
->selectedItem
;
3666 char tmpText
[1024] = { '\0' };
3669 if (!infoPtr
->hwndEdit
)
3672 tvdi
.hdr
.hwndFrom
= hwnd
;
3673 tvdi
.hdr
.idFrom
= GetWindowLongA(hwnd
, GWL_ID
);
3674 tvdi
.hdr
.code
= get_notifycode(infoPtr
, TVN_ENDLABELEDITW
);
3676 tvdi
.item
.hItem
= editedItem
;
3677 tvdi
.item
.state
= editedItem
->state
;
3678 tvdi
.item
.lParam
= editedItem
->lParam
;
3682 iLength
= GetWindowTextA(infoPtr
->hwndEdit
, tmpText
, 1023);
3684 if (iLength
>= 1023)
3686 ERR("Insufficient space to retrieve new item label\n");
3689 tvdi
.item
.pszText
= tmpText
;
3690 tvdi
.item
.cchTextMax
= iLength
+ 1;
3694 tvdi
.item
.pszText
= NULL
;
3695 tvdi
.item
.cchTextMax
= 0;
3698 bCommit
= (BOOL
)TREEVIEW_SendRealNotify(infoPtr
,
3699 (WPARAM
)tvdi
.hdr
.idFrom
, (LPARAM
)&tvdi
);
3701 if (!bCancel
&& bCommit
) /* Apply the changes */
3703 if (strcmp(tmpText
, editedItem
->pszText
) != 0)
3705 if (NULL
== ReAlloc(editedItem
->pszText
, iLength
+ 1))
3707 ERR("OutOfMemory, cannot allocate space for label\n");
3708 DestroyWindow(infoPtr
->hwndEdit
);
3709 infoPtr
->hwndEdit
= 0;
3714 editedItem
->cchTextMax
= iLength
+ 1;
3715 lstrcpyA(editedItem
->pszText
, tmpText
);
3720 ShowWindow(infoPtr
->hwndEdit
, SW_HIDE
);
3721 DestroyWindow(infoPtr
->hwndEdit
);
3722 infoPtr
->hwndEdit
= 0;
3727 TREEVIEW_HandleTimer(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
3729 if (wParam
!= TV_EDIT_TIMER
)
3731 ERR("got unknown timer\n");
3735 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
3736 infoPtr
->Timer
&= ~TV_EDIT_TIMER_SET
;
3738 TREEVIEW_EditLabelA(infoPtr
, infoPtr
->selectedItem
);
3744 /* Mouse Tracking/Drag **************************************************/
3746 /***************************************************************************
3747 * This is quite unusual piece of code, but that's how it's implemented in
3751 TREEVIEW_TrackMouse(TREEVIEW_INFO
*infoPtr
, POINT pt
)
3753 INT cxDrag
= GetSystemMetrics(SM_CXDRAG
);
3754 INT cyDrag
= GetSystemMetrics(SM_CYDRAG
);
3758 r
.top
= pt
.y
- cyDrag
;
3759 r
.left
= pt
.x
- cxDrag
;
3760 r
.bottom
= pt
.y
+ cyDrag
;
3761 r
.right
= pt
.x
+ cxDrag
;
3763 SetCapture(infoPtr
->hwnd
);
3767 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
3769 if (msg
.message
== WM_MOUSEMOVE
)
3771 pt
.x
= (short)LOWORD(msg
.lParam
);
3772 pt
.y
= (short)HIWORD(msg
.lParam
);
3773 if (PtInRect(&r
, pt
))
3781 else if (msg
.message
>= WM_LBUTTONDOWN
&&
3782 msg
.message
<= WM_RBUTTONDBLCLK
)
3784 if (msg
.message
== WM_RBUTTONUP
)
3785 TREEVIEW_RButtonUp(infoPtr
, &pt
);
3789 DispatchMessageA(&msg
);
3792 if (GetCapture() != infoPtr
->hwnd
)
3802 TREEVIEW_LButtonDoubleClick(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3804 TREEVIEW_ITEM
*wineItem
;
3808 SetFocus(infoPtr
->hwnd
);
3810 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
3812 /* If there is pending 'edit label' event - kill it now */
3813 KillTimer(infoPtr
->hwnd
, TV_EDIT_TIMER
);
3816 hit
.pt
.x
= (short)LOWORD(lParam
);
3817 hit
.pt
.y
= (short)HIWORD(lParam
);
3819 wineItem
= (TREEVIEW_ITEM
*)TREEVIEW_HitTest(infoPtr
, &hit
);
3822 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, wineItem
));
3824 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_DBLCLK
) == FALSE
)
3828 case TVHT_ONITEMRIGHT
:
3829 /* FIXME: we should not have sent NM_DBLCLK in this case. */
3832 case TVHT_ONITEMINDENT
:
3833 if (!(infoPtr
->dwStyle
& TVS_HASLINES
))
3839 int level
= hit
.pt
.x
/ infoPtr
->uIndent
;
3840 if (!(infoPtr
->dwStyle
& TVS_LINESATROOT
)) level
++;
3842 while (wineItem
->iLevel
> level
)
3844 wineItem
= wineItem
->parent
;
3850 case TVHT_ONITEMLABEL
:
3851 case TVHT_ONITEMICON
:
3852 case TVHT_ONITEMBUTTON
:
3853 TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3856 case TVHT_ONITEMSTATEICON
:
3857 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
3858 TREEVIEW_ToggleItemState(infoPtr
, wineItem
);
3860 TREEVIEW_Toggle(infoPtr
, wineItem
, TRUE
);
3869 TREEVIEW_LButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
3871 HWND hwnd
= infoPtr
->hwnd
;
3876 /* If Edit control is active - kill it and return.
3877 * The best way to do it is to set focus to itself.
3878 * Edit control subclassed procedure will automatically call
3881 if (infoPtr
->hwndEdit
)
3887 ht
.pt
.x
= (short)LOWORD(lParam
);
3888 ht
.pt
.y
= (short)HIWORD(lParam
);
3890 TREEVIEW_HitTest(infoPtr
, &ht
);
3891 TRACE("item %d\n", TREEVIEW_GetItemIndex(infoPtr
, ht
.hItem
));
3893 /* update focusedItem and redraw both items */
3894 if(ht
.hItem
&& (ht
.flags
& TVHT_ONITEM
))
3896 infoPtr
->focusedItem
= ht
.hItem
;
3897 InvalidateRect(hwnd
, &(((HTREEITEM
)(ht
.hItem
))->rect
), TRUE
);
3899 if(infoPtr
->selectedItem
)
3900 InvalidateRect(hwnd
, &(infoPtr
->selectedItem
->rect
), TRUE
);
3903 bTrack
= (ht
.flags
& TVHT_ONITEM
)
3904 && !(infoPtr
->dwStyle
& TVS_DISABLEDRAGDROP
);
3906 /* Send NM_CLICK right away */
3908 if (TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
3911 if (ht
.flags
& TVHT_ONITEMBUTTON
)
3913 TREEVIEW_Toggle(infoPtr
, ht
.hItem
, TRUE
);
3917 { /* if TREEVIEW_TrackMouse == 1 dragging occurred and the cursor left the dragged item's rectangle */
3918 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
3920 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINDRAGW
, ht
.hItem
, ht
.pt
);
3921 infoPtr
->dropItem
= ht
.hItem
;
3923 /* clean up focusedItem as we dragged and won't select this item */
3924 if(infoPtr
->focusedItem
)
3926 /* refresh the item that was focused */
3927 tempItem
= infoPtr
->focusedItem
;
3928 infoPtr
->focusedItem
= 0;
3929 InvalidateRect(infoPtr
->hwnd
, &tempItem
->rect
, TRUE
);
3931 /* refresh the selected item to return the filled background */
3932 InvalidateRect(infoPtr
->hwnd
, &(infoPtr
->selectedItem
->rect
), TRUE
);
3939 if (bTrack
&& TREEVIEW_SendSimpleNotify(infoPtr
, NM_CLICK
))
3943 * If the style allows editing and the node is already selected
3944 * and the click occurred on the item label...
3946 if ((infoPtr
->dwStyle
& TVS_EDITLABELS
) &&
3947 (ht
.flags
& TVHT_ONITEMLABEL
) && (infoPtr
->selectedItem
== ht
.hItem
))
3949 if (infoPtr
->Timer
& TV_EDIT_TIMER_SET
)
3950 KillTimer(hwnd
, TV_EDIT_TIMER
);
3952 SetTimer(hwnd
, TV_EDIT_TIMER
, GetDoubleClickTime(), 0);
3953 infoPtr
->Timer
|= TV_EDIT_TIMER_SET
;
3955 else if (ht
.flags
& (TVHT_ONITEMICON
|TVHT_ONITEMLABEL
)) /* select the item if the hit was inside of the icon or text */
3958 * if we are TVS_SINGLEEXPAND then we want this single click to
3959 * do a bunch of things.
3961 if((infoPtr
->dwStyle
& TVS_SINGLEEXPAND
) &&
3962 (infoPtr
->hwndEdit
== 0))
3964 TREEVIEW_ITEM
*SelItem
;
3967 * Send the notification
3969 TREEVIEW_SendTreeviewNotify(infoPtr
, TVN_SINGLEEXPAND
, TVC_UNKNOWN
, TVIF_HANDLE
| TVIF_PARAM
, ht
.hItem
, 0);
3972 * Close the previous selection all the way to the root
3973 * as long as the new selection is not a child
3975 if((infoPtr
->selectedItem
)
3976 && (infoPtr
->selectedItem
!= ht
.hItem
))
3978 BOOL closeit
= TRUE
;
3981 /* determine if the hitItem is a child of the currently selected item */
3982 while(closeit
&& SelItem
&& TREEVIEW_ValidItem(infoPtr
, SelItem
) && (SelItem
!= infoPtr
->root
))
3984 closeit
= (SelItem
!= infoPtr
->selectedItem
);
3985 SelItem
= SelItem
->parent
;
3990 if(TREEVIEW_ValidItem(infoPtr
, infoPtr
->selectedItem
))
3991 SelItem
= infoPtr
->selectedItem
;
3993 while(SelItem
&& (SelItem
!= ht
.hItem
) && TREEVIEW_ValidItem(infoPtr
, SelItem
) && (SelItem
!= infoPtr
->root
))
3995 TREEVIEW_Collapse(infoPtr
, SelItem
, FALSE
, FALSE
);
3996 SelItem
= SelItem
->parent
;
4002 * Expand the current item
4004 TREEVIEW_Expand(infoPtr
, ht
.hItem
, TVE_TOGGLE
, FALSE
);
4007 /* Select the current item */
4008 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, ht
.hItem
, TVC_BYMOUSE
);
4010 else if (ht
.flags
& TVHT_ONITEMSTATEICON
)
4012 /* TVS_CHECKBOXES requires us to toggle the current state */
4013 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4014 TREEVIEW_ToggleItemState(infoPtr
, ht
.hItem
);
4024 TREEVIEW_RButtonDown(TREEVIEW_INFO
*infoPtr
, LPARAM lParam
)
4028 if (infoPtr
->hwndEdit
)
4030 SetFocus(infoPtr
->hwnd
);
4034 ht
.pt
.x
= (short)LOWORD(lParam
);
4035 ht
.pt
.y
= (short)HIWORD(lParam
);
4037 TREEVIEW_HitTest(infoPtr
, &ht
);
4039 if (TREEVIEW_TrackMouse(infoPtr
, ht
.pt
))
4043 TREEVIEW_SendTreeviewDnDNotify(infoPtr
, TVN_BEGINRDRAGW
, ht
.hItem
, ht
.pt
);
4044 infoPtr
->dropItem
= ht
.hItem
;
4049 SetFocus(infoPtr
->hwnd
);
4050 TREEVIEW_SendSimpleNotify(infoPtr
, NM_RCLICK
);
4057 TREEVIEW_RButtonUp(TREEVIEW_INFO
*infoPtr
, LPPOINT pPt
)
4064 TREEVIEW_CreateDragImage(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
4066 TREEVIEW_ITEM
*dragItem
= (HTREEITEM
)lParam
;
4070 HBITMAP hbmp
, hOldbmp
;
4077 if (!(infoPtr
->himlNormal
))
4080 if (!dragItem
|| !TREEVIEW_ValidItem(infoPtr
, dragItem
))
4083 TREEVIEW_UpdateDispInfo(infoPtr
, dragItem
, TVIF_TEXT
);
4085 hwtop
= GetDesktopWindow();
4086 htopdc
= GetDC(hwtop
);
4087 hdc
= CreateCompatibleDC(htopdc
);
4089 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4090 GetTextExtentPoint32A(hdc
, dragItem
->pszText
, lstrlenA(dragItem
->pszText
),
4092 TRACE("%ld %ld %s %d\n", size
.cx
, size
.cy
, dragItem
->pszText
,
4093 lstrlenA(dragItem
->pszText
));
4094 hbmp
= CreateCompatibleBitmap(htopdc
, size
.cx
, size
.cy
);
4095 hOldbmp
= SelectObject(hdc
, hbmp
);
4097 ImageList_GetIconSize(infoPtr
->himlNormal
, &cx
, &cy
);
4102 infoPtr
->dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4103 ImageList_Draw(infoPtr
->himlNormal
, dragItem
->iImage
, hdc
, 0, 0,
4107 ImageList_GetImageInfo (infoPtr->himlNormal, dragItem->hItem, &iminfo);
4108 ImageList_AddMasked (infoPtr->dragList, iminfo.hbmImage, CLR_DEFAULT);
4111 /* draw item text */
4113 SetRect(&rc
, cx
, 0, size
.cx
, size
.cy
);
4114 DrawTextA(hdc
, dragItem
->pszText
, lstrlenA(dragItem
->pszText
), &rc
,
4116 SelectObject(hdc
, hOldFont
);
4117 SelectObject(hdc
, hOldbmp
);
4119 ImageList_Add(infoPtr
->dragList
, hbmp
, 0);
4123 ReleaseDC(hwtop
, htopdc
);
4125 return (LRESULT
)infoPtr
->dragList
;
4128 /* Selection ************************************************************/
4131 TREEVIEW_DoSelectItem(TREEVIEW_INFO
*infoPtr
, INT action
, HTREEITEM newSelect
,
4134 TREEVIEW_ITEM
*prevSelect
;
4137 assert(newSelect
== NULL
|| TREEVIEW_ValidItem(infoPtr
, newSelect
));
4139 TRACE("Entering item %p (%s), flag %x, cause %x, state %d\n",
4140 newSelect
, TREEVIEW_ItemName(newSelect
), action
, cause
,
4141 newSelect
? newSelect
->state
: 0);
4143 /* reset and redraw focusedItem if focusedItem was set so we don't */
4144 /* have to worry about the previously focused item when we set a new one */
4145 if(infoPtr
->focusedItem
)
4147 rcFocused
= (infoPtr
->focusedItem
)->rect
;
4148 infoPtr
->focusedItem
= 0;
4149 InvalidateRect(infoPtr
->hwnd
, &rcFocused
, TRUE
);
4155 prevSelect
= infoPtr
->selectedItem
;
4157 if (prevSelect
== newSelect
)
4160 if (TREEVIEW_SendTreeviewNotify(infoPtr
,
4163 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4169 prevSelect
->state
&= ~TVIS_SELECTED
;
4171 newSelect
->state
|= TVIS_SELECTED
;
4173 infoPtr
->selectedItem
= newSelect
;
4175 TREEVIEW_EnsureVisible(infoPtr
, infoPtr
->selectedItem
, FALSE
);
4177 TREEVIEW_SendTreeviewNotify(infoPtr
,
4180 TVIF_HANDLE
| TVIF_STATE
| TVIF_PARAM
,
4183 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4184 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4187 case TVGN_DROPHILITE
:
4188 prevSelect
= infoPtr
->dropItem
;
4191 prevSelect
->state
&= ~TVIS_DROPHILITED
;
4193 infoPtr
->dropItem
= newSelect
;
4196 newSelect
->state
|= TVIS_DROPHILITED
;
4198 TREEVIEW_Invalidate(infoPtr
, prevSelect
);
4199 TREEVIEW_Invalidate(infoPtr
, newSelect
);
4202 case TVGN_FIRSTVISIBLE
:
4203 TREEVIEW_EnsureVisible(infoPtr
, newSelect
, FALSE
);
4204 TREEVIEW_SetFirstVisible(infoPtr
, newSelect
, TRUE
);
4205 TREEVIEW_Invalidate(infoPtr
, NULL
);
4209 TRACE("Leaving state %d\n", newSelect
? newSelect
->state
: 0);
4213 /* FIXME: handle NM_KILLFOCUS etc */
4215 TREEVIEW_SelectItem(TREEVIEW_INFO
*infoPtr
, INT wParam
, HTREEITEM item
)
4217 if (item
!= NULL
&& !TREEVIEW_ValidItem(infoPtr
, item
))
4220 TRACE("%p (%s) %d\n", item
, TREEVIEW_ItemName(item
), wParam
);
4222 if (!TREEVIEW_DoSelectItem(infoPtr
, wParam
, item
, TVC_UNKNOWN
))
4228 /*************************************************************************
4229 * TREEVIEW_ProcessLetterKeys
4231 * Processes keyboard messages generated by pressing the letter keys
4233 * What this does is perform a case insensitive search from the
4234 * current position with the following quirks:
4235 * - If two chars or more are pressed in quick succession we search
4236 * for the corresponding string (e.g. 'abc').
4237 * - If there is a delay we wipe away the current search string and
4238 * restart with just that char.
4239 * - If the user keeps pressing the same character, whether slowly or
4240 * fast, so that the search string is entirely composed of this
4241 * character ('aaaaa' for instance), then we search for first item
4242 * that starting with that character.
4243 * - If the user types the above character in quick succession, then
4244 * we must also search for the corresponding string ('aaaaa'), and
4245 * go to that string if there is a match.
4253 * - The current implementation has a list of characters it will
4254 * accept and it ignores averything else. In particular it will
4255 * ignore accentuated characters which seems to match what
4256 * Windows does. But I'm not sure it makes sense to follow
4258 * - We don't sound a beep when the search fails.
4259 * - The search should start from the focused item, not from the selected
4260 * item. One reason for this is to allow for multiple selections in trees.
4261 * But currently infoPtr->focusedItem does not seem very usable.
4265 * TREEVIEW_ProcessLetterKeys
4267 static INT
TREEVIEW_ProcessLetterKeys(
4268 HWND hwnd
, /* handle to the window */
4269 WPARAM charCode
, /* the character code, the actual character */
4270 LPARAM keyData
/* key data */
4273 TREEVIEW_INFO
*infoPtr
;
4275 HTREEITEM endidx
,idx
;
4277 CHAR buffer
[MAX_PATH
];
4278 DWORD timestamp
,elapsed
;
4280 /* simple parameter checking */
4281 if (!hwnd
|| !charCode
|| !keyData
)
4284 infoPtr
=(TREEVIEW_INFO
*)GetWindowLongA(hwnd
, 0);
4288 /* only allow the valid WM_CHARs through */
4289 if (!isalnum(charCode
) &&
4290 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
4291 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
4292 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
4293 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
4294 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
4295 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
4296 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
4297 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
4298 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
4301 /* compute how much time elapsed since last keypress */
4302 timestamp
= GetTickCount();
4303 if (timestamp
> infoPtr
->lastKeyPressTimestamp
) {
4304 elapsed
=timestamp
-infoPtr
->lastKeyPressTimestamp
;
4306 elapsed
=infoPtr
->lastKeyPressTimestamp
-timestamp
;
4309 /* update the search parameters */
4310 infoPtr
->lastKeyPressTimestamp
=timestamp
;
4311 if (elapsed
< KEY_DELAY
) {
4312 if (infoPtr
->nSearchParamLength
< sizeof(infoPtr
->szSearchParam
)) {
4313 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
4315 if (infoPtr
->charCode
!= charCode
) {
4316 infoPtr
->charCode
=charCode
=0;
4319 infoPtr
->charCode
=charCode
;
4320 infoPtr
->szSearchParam
[0]=charCode
;
4321 infoPtr
->nSearchParamLength
=1;
4322 /* Redundant with the 1 char string */
4326 /* and search from the current position */
4328 if (infoPtr
->selectedItem
!= NULL
) {
4329 endidx
=infoPtr
->selectedItem
;
4330 /* if looking for single character match,
4331 * then we must always move forward
4333 if (infoPtr
->nSearchParamLength
== 1)
4334 idx
=TREEVIEW_GetNextListItem(infoPtr
,endidx
);
4339 idx
=infoPtr
->root
->firstChild
;
4345 idx
=infoPtr
->root
->firstChild
;
4349 ZeroMemory(&item
, sizeof(item
));
4350 item
.mask
= TVIF_TEXT
;
4352 item
.pszText
= buffer
;
4353 item
.cchTextMax
= sizeof(buffer
);
4354 TREEVIEW_GetItemA( infoPtr
, &item
);
4356 /* check for a match */
4357 if (strncasecmp(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
4360 } else if ( (charCode
!= 0) && (nItem
== NULL
) &&
4361 (nItem
!= infoPtr
->selectedItem
) &&
4362 (strncasecmp(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
4363 /* This would work but we must keep looking for a longer match */
4366 idx
=TREEVIEW_GetNextListItem(infoPtr
,idx
);
4367 } while (idx
!= endidx
);
4369 if (nItem
!= NULL
) {
4370 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, nItem
, TVC_BYKEYBOARD
)) {
4371 TREEVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
4378 /* Scrolling ************************************************************/
4381 TREEVIEW_EnsureVisible(TREEVIEW_INFO
*infoPtr
, HTREEITEM item
, BOOL bHScroll
)
4383 HTREEITEM newFirstVisible
= NULL
;
4386 if (!TREEVIEW_ValidItem(infoPtr
, item
))
4389 if (!ISVISIBLE(item
))
4391 /* Expand parents as necessary. */
4394 /* see if we are trying to ensure that root is vislble */
4395 if((item
!= infoPtr
->root
) && TREEVIEW_ValidItem(infoPtr
, item
))
4396 parent
= item
->parent
;
4398 parent
= item
; /* this item is the topmost item */
4400 while (parent
!= infoPtr
->root
)
4402 if (!(parent
->state
& TVIS_EXPANDED
))
4403 TREEVIEW_Expand(infoPtr
, parent
, FALSE
, FALSE
);
4405 parent
= parent
->parent
;
4409 TRACE("%p (%s) %ld - %ld\n", item
, TREEVIEW_ItemName(item
), item
->visibleOrder
,
4410 infoPtr
->firstVisible
->visibleOrder
);
4412 visible_pos
= item
->visibleOrder
- infoPtr
->firstVisible
->visibleOrder
;
4414 if (visible_pos
< 0)
4416 /* item is before the start of the list: put it at the top. */
4417 newFirstVisible
= item
;
4419 else if (visible_pos
>= TREEVIEW_GetVisibleCount(infoPtr
)
4420 /* Sometimes, before we are displayed, GVC is 0, causing us to
4421 * spuriously scroll up. */
4424 /* item is past the end of the list. */
4425 int scroll
= visible_pos
- TREEVIEW_GetVisibleCount(infoPtr
);
4427 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, infoPtr
->firstVisible
,
4433 /* Scroll window so item's text is visible as much as possible */
4434 /* Calculation of amount of extra space is taken from EditLabel code */
4436 TEXTMETRICA textMetric
;
4437 HDC hdc
= GetWindowDC(infoPtr
->hwnd
);
4439 x
= item
->textWidth
;
4441 GetTextMetricsA(hdc
, &textMetric
);
4442 ReleaseDC(infoPtr
->hwnd
, hdc
);
4444 x
+= (textMetric
.tmMaxCharWidth
* 2);
4445 x
= max(x
, textMetric
.tmMaxCharWidth
* 3);
4447 if (item
->textOffset
< 0)
4448 pos
= item
->textOffset
;
4449 else if (item
->textOffset
+ x
> infoPtr
->clientWidth
)
4451 if (x
> infoPtr
->clientWidth
)
4452 pos
= item
->textOffset
;
4454 pos
= item
->textOffset
+ x
- infoPtr
->clientWidth
;
4459 TREEVIEW_HScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, infoPtr
->scrollX
+ pos
));
4462 if (newFirstVisible
!= NULL
&& newFirstVisible
!= infoPtr
->firstVisible
)
4464 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
, TRUE
);
4473 TREEVIEW_SetFirstVisible(TREEVIEW_INFO
*infoPtr
,
4474 TREEVIEW_ITEM
*newFirstVisible
,
4475 BOOL bUpdateScrollPos
)
4479 TRACE("%p: %s\n", newFirstVisible
, TREEVIEW_ItemName(newFirstVisible
));
4481 if (newFirstVisible
!= NULL
)
4483 /* Prevent an empty gap from appearing at the bottom... */
4484 gap_size
= TREEVIEW_GetVisibleCount(infoPtr
)
4485 - infoPtr
->maxVisibleOrder
+ newFirstVisible
->visibleOrder
;
4489 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, newFirstVisible
,
4492 /* ... unless we just don't have enough items. */
4493 if (newFirstVisible
== NULL
)
4494 newFirstVisible
= infoPtr
->root
->firstChild
;
4498 if (infoPtr
->firstVisible
!= newFirstVisible
)
4500 if (infoPtr
->firstVisible
== NULL
|| newFirstVisible
== NULL
)
4502 infoPtr
->firstVisible
= newFirstVisible
;
4503 TREEVIEW_Invalidate(infoPtr
, NULL
);
4507 TREEVIEW_ITEM
*item
;
4508 int scroll
= infoPtr
->uItemHeight
*
4509 (infoPtr
->firstVisible
->visibleOrder
4510 - newFirstVisible
->visibleOrder
);
4512 infoPtr
->firstVisible
= newFirstVisible
;
4514 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4515 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4517 item
->rect
.top
+= scroll
;
4518 item
->rect
.bottom
+= scroll
;
4521 if (bUpdateScrollPos
)
4522 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4523 newFirstVisible
->visibleOrder
, TRUE
);
4525 ScrollWindow(infoPtr
->hwnd
, 0, scroll
, NULL
, NULL
);
4526 UpdateWindow(infoPtr
->hwnd
);
4531 /************************************************************************
4532 * VScroll is always in units of visible items. i.e. we always have a
4533 * visible item aligned to the top of the control. (Unless we have no
4537 TREEVIEW_VScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4539 TREEVIEW_ITEM
*oldFirstVisible
= infoPtr
->firstVisible
;
4540 TREEVIEW_ITEM
*newFirstVisible
= NULL
;
4542 int nScrollCode
= LOWORD(wParam
);
4544 TRACE("wp %x\n", wParam
);
4546 if (!(infoPtr
->uInternalStatus
& TV_VSCROLL
))
4549 if (infoPtr
->hwndEdit
)
4550 SetFocus(infoPtr
->hwnd
);
4552 if (!oldFirstVisible
)
4554 assert(infoPtr
->root
->firstChild
== NULL
);
4558 switch (nScrollCode
)
4561 newFirstVisible
= infoPtr
->root
->firstChild
;
4565 newFirstVisible
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4569 newFirstVisible
= TREEVIEW_GetPrevListItem(infoPtr
, oldFirstVisible
);
4573 newFirstVisible
= TREEVIEW_GetNextListItem(infoPtr
, oldFirstVisible
);
4577 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4578 -max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4582 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
, oldFirstVisible
,
4583 max(1, TREEVIEW_GetVisibleCount(infoPtr
)));
4587 case SB_THUMBPOSITION
:
4588 newFirstVisible
= TREEVIEW_GetListItem(infoPtr
,
4589 infoPtr
->root
->firstChild
,
4590 (LONG
)(SHORT
)HIWORD(wParam
));
4597 if (newFirstVisible
!= NULL
)
4599 if (newFirstVisible
!= oldFirstVisible
)
4600 TREEVIEW_SetFirstVisible(infoPtr
, newFirstVisible
,
4601 nScrollCode
!= SB_THUMBTRACK
);
4602 else if (nScrollCode
== SB_THUMBPOSITION
)
4603 SetScrollPos(infoPtr
->hwnd
, SB_VERT
,
4604 newFirstVisible
->visibleOrder
, TRUE
);
4611 TREEVIEW_HScroll(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4614 int scrollX
= infoPtr
->scrollX
;
4615 int nScrollCode
= LOWORD(wParam
);
4617 TRACE("wp %x\n", wParam
);
4619 if (!(infoPtr
->uInternalStatus
& TV_HSCROLL
))
4622 if (infoPtr
->hwndEdit
)
4623 SetFocus(infoPtr
->hwnd
);
4625 maxWidth
= infoPtr
->treeWidth
- infoPtr
->clientWidth
;
4626 /* shall never occur */
4633 switch (nScrollCode
)
4636 scrollX
-= infoPtr
->uItemHeight
;
4639 scrollX
+= infoPtr
->uItemHeight
;
4642 scrollX
-= infoPtr
->clientWidth
;
4645 scrollX
+= infoPtr
->clientWidth
;
4649 case SB_THUMBPOSITION
:
4650 scrollX
= (int)(SHORT
)HIWORD(wParam
);
4657 if (scrollX
> maxWidth
)
4659 else if (scrollX
< 0)
4663 if (scrollX
!= infoPtr
->scrollX
)
4665 TREEVIEW_ITEM
*item
;
4666 LONG scroll_pixels
= infoPtr
->scrollX
- scrollX
;
4668 for (item
= infoPtr
->root
->firstChild
; item
!= NULL
;
4669 item
= TREEVIEW_GetNextListItem(infoPtr
, item
))
4671 item
->linesOffset
+= scroll_pixels
;
4672 item
->stateOffset
+= scroll_pixels
;
4673 item
->imageOffset
+= scroll_pixels
;
4674 item
->textOffset
+= scroll_pixels
;
4677 ScrollWindow(infoPtr
->hwnd
, scroll_pixels
, 0, NULL
, NULL
);
4678 infoPtr
->scrollX
= scrollX
;
4679 UpdateWindow(infoPtr
->hwnd
);
4682 if (nScrollCode
!= SB_THUMBTRACK
)
4683 SetScrollPos(infoPtr
->hwnd
, SB_HORZ
, scrollX
, TRUE
);
4689 TREEVIEW_MouseWheel(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4692 UINT pulScrollLines
= 3;
4694 if (infoPtr
->firstVisible
== NULL
)
4697 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &pulScrollLines
, 0);
4699 gcWheelDelta
= -(short)HIWORD(wParam
);
4700 pulScrollLines
*= (gcWheelDelta
/ WHEEL_DELTA
);
4702 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
4704 int newDy
= infoPtr
->firstVisible
->visibleOrder
+ pulScrollLines
;
4705 int maxDy
= infoPtr
->maxVisibleOrder
;
4713 TREEVIEW_VScroll(infoPtr
, MAKEWPARAM(SB_THUMBPOSITION
, newDy
));
4718 /* Create/Destroy *******************************************************/
4721 TREEVIEW_Create(HWND hwnd
)
4724 TREEVIEW_INFO
*infoPtr
;
4726 TRACE("wnd %p, style %lx\n", hwnd
, GetWindowLongA(hwnd
, GWL_STYLE
));
4728 infoPtr
= (TREEVIEW_INFO
*)Alloc(sizeof(TREEVIEW_INFO
));
4730 if (infoPtr
== NULL
)
4732 ERR("could not allocate info memory!\n");
4736 SetWindowLongA(hwnd
, 0, (DWORD
)infoPtr
);
4738 infoPtr
->hwnd
= hwnd
;
4739 infoPtr
->dwStyle
= GetWindowLongA(hwnd
, GWL_STYLE
);
4740 infoPtr
->uInternalStatus
= 0;
4742 infoPtr
->uNumItems
= 0;
4743 infoPtr
->cdmode
= 0;
4744 infoPtr
->uScrollTime
= 300; /* milliseconds */
4745 infoPtr
->bRedraw
= TRUE
;
4747 GetClientRect(hwnd
, &rcClient
);
4749 /* No scroll bars yet. */
4750 infoPtr
->clientWidth
= rcClient
.right
;
4751 infoPtr
->clientHeight
= rcClient
.bottom
;
4753 infoPtr
->treeWidth
= 0;
4754 infoPtr
->treeHeight
= 0;
4756 infoPtr
->uIndent
= 19;
4757 infoPtr
->selectedItem
= 0;
4758 infoPtr
->focusedItem
= 0;
4760 infoPtr
->firstVisible
= 0;
4761 infoPtr
->maxVisibleOrder
= 0;
4762 infoPtr
->dropItem
= 0;
4763 infoPtr
->insertMarkItem
= 0;
4764 infoPtr
->insertBeforeorAfter
= 0;
4767 infoPtr
->scrollX
= 0;
4769 infoPtr
->clrBk
= GetSysColor(COLOR_WINDOW
);
4770 infoPtr
->clrText
= -1; /* use system color */
4771 infoPtr
->clrLine
= RGB(128, 128, 128);
4772 infoPtr
->clrInsertMark
= GetSysColor(COLOR_BTNTEXT
);
4776 infoPtr
->hwndEdit
= 0;
4777 infoPtr
->wpEditOrig
= NULL
;
4778 infoPtr
->bIgnoreEditKillFocus
= FALSE
;
4779 infoPtr
->bLabelChanged
= FALSE
;
4781 infoPtr
->himlNormal
= NULL
;
4782 infoPtr
->himlState
= NULL
;
4783 infoPtr
->normalImageWidth
= 0;
4784 infoPtr
->normalImageHeight
= 0;
4785 infoPtr
->stateImageWidth
= 0;
4786 infoPtr
->stateImageHeight
= 0;
4788 infoPtr
->items
= DPA_Create(16);
4790 infoPtr
->hFont
= GetStockObject(DEFAULT_GUI_FONT
);
4791 infoPtr
->hBoldFont
= TREEVIEW_CreateBoldFont(infoPtr
->hFont
);
4793 infoPtr
->uItemHeight
= TREEVIEW_NaturalHeight(infoPtr
);
4795 infoPtr
->root
= TREEVIEW_AllocateItem(infoPtr
);
4796 infoPtr
->root
->state
= TVIS_EXPANDED
;
4797 infoPtr
->root
->iLevel
= -1;
4798 infoPtr
->root
->visibleOrder
= -1;
4800 infoPtr
->hwndNotify
= GetParent(hwnd
);
4802 infoPtr
->bTransparent
= ( GetWindowLongA( hwnd
, GWL_STYLE
) & TBSTYLE_FLAT
);
4805 infoPtr
->hwndToolTip
= 0;
4807 infoPtr
->bUnicode
= IsWindowUnicode (hwnd
);
4809 /* Determine what type of notify should be issued */
4810 /* sets infoPtr->bNtfUnicode */
4811 TREEVIEW_NotifyFormat(infoPtr
, infoPtr
->hwndNotify
, NF_REQUERY
);
4813 if (!(infoPtr
->dwStyle
& TVS_NOTOOLTIPS
))
4814 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(hwnd
);
4816 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
4819 HBITMAP hbm
, hbmOld
;
4823 infoPtr
->himlState
=
4824 ImageList_Create(16, 16, ILC_COLOR
| ILC_MASK
, 3, 0);
4826 hdcScreen
= CreateDCA("DISPLAY", NULL
, NULL
, NULL
);
4828 /* Create a coloured bitmap compatible with the screen depth
4829 because checkboxes are not black&white */
4830 hdc
= CreateCompatibleDC(hdcScreen
);
4831 hbm
= CreateCompatibleBitmap(hdcScreen
, 48, 16);
4832 hbmOld
= SelectObject(hdc
, hbm
);
4834 rc
.left
= 0; rc
.top
= 0;
4835 rc
.right
= 48; rc
.bottom
= 16;
4836 FillRect(hdc
, &rc
, (HBRUSH
)(COLOR_WINDOW
+1));
4838 rc
.left
= 18; rc
.top
= 2;
4839 rc
.right
= 30; rc
.bottom
= 14;
4840 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4841 DFCS_BUTTONCHECK
|DFCS_FLAT
);
4843 rc
.left
= 34; rc
.right
= 46;
4844 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
,
4845 DFCS_BUTTONCHECK
|DFCS_FLAT
|DFCS_CHECKED
);
4847 SelectObject(hdc
, hbmOld
);
4848 nIndex
= ImageList_AddMasked(infoPtr
->himlState
, hbm
,
4849 GetSysColor(COLOR_WINDOW
));
4850 TRACE("checkbox index %d\n", nIndex
);
4854 DeleteDC(hdcScreen
);
4856 infoPtr
->stateImageWidth
= 16;
4857 infoPtr
->stateImageHeight
= 16;
4864 TREEVIEW_Destroy(TREEVIEW_INFO
*infoPtr
)
4868 TREEVIEW_RemoveTree(infoPtr
);
4870 /* tool tip is automatically destroyed: we are its owner */
4872 /* Restore original wndproc */
4873 if (infoPtr
->hwndEdit
)
4874 SetWindowLongA(infoPtr
->hwndEdit
, GWL_WNDPROC
,
4875 (LONG
)infoPtr
->wpEditOrig
);
4877 /* Deassociate treeview from the window before doing anything drastic. */
4878 SetWindowLongA(infoPtr
->hwnd
, 0, (LONG
)NULL
);
4880 DeleteObject(infoPtr
->hBoldFont
);
4886 /* Miscellaneous Messages ***********************************************/
4889 TREEVIEW_ScrollKeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM key
)
4897 #define SCROLL_ENTRY(dir, code) { ((dir) << 7) | (code) }
4898 SCROLL_ENTRY(SB_VERT
, SB_PAGEUP
), /* VK_PRIOR */
4899 SCROLL_ENTRY(SB_VERT
, SB_PAGEDOWN
), /* VK_NEXT */
4900 SCROLL_ENTRY(SB_VERT
, SB_BOTTOM
), /* VK_END */
4901 SCROLL_ENTRY(SB_VERT
, SB_TOP
), /* VK_HOME */
4902 SCROLL_ENTRY(SB_HORZ
, SB_LINEUP
), /* VK_LEFT */
4903 SCROLL_ENTRY(SB_VERT
, SB_LINEUP
), /* VK_UP */
4904 SCROLL_ENTRY(SB_HORZ
, SB_LINEDOWN
), /* VK_RIGHT */
4905 SCROLL_ENTRY(SB_VERT
, SB_LINEDOWN
) /* VK_DOWN */
4909 if (key
>= VK_PRIOR
&& key
<= VK_DOWN
)
4911 unsigned char code
= scroll
[key
- VK_PRIOR
].code
;
4913 (((code
& (1 << 7)) == (SB_HORZ
<< 7))
4915 : TREEVIEW_VScroll
)(infoPtr
, code
& 0x7F);
4921 /************************************************************************
4924 * VK_UP Move selection to the previous non-hidden item.
4925 * VK_DOWN Move selection to the next non-hidden item.
4926 * VK_HOME Move selection to the first item.
4927 * VK_END Move selection to the last item.
4928 * VK_LEFT If expanded then collapse, otherwise move to parent.
4929 * VK_RIGHT If collapsed then expand, otherwise move to first child.
4931 * VK_SUBTRACT Collapse.
4932 * VK_MULTIPLY Expand all.
4933 * VK_PRIOR Move up GetVisibleCount items.
4934 * VK_NEXT Move down GetVisibleCount items.
4935 * VK_BACK Move to parent.
4936 * CTRL-Left,Right,Up,Down,PgUp,PgDown,Home,End: Scroll without changing selection
4939 TREEVIEW_KeyDown(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
)
4941 /* If it is non-NULL and different, it will be selected and visible. */
4942 TREEVIEW_ITEM
*newSelection
= NULL
;
4944 TREEVIEW_ITEM
*prevItem
= infoPtr
->selectedItem
;
4946 TRACE("%x\n", wParam
);
4948 if (prevItem
== NULL
)
4951 if (GetAsyncKeyState(VK_CONTROL
) & 0x8000)
4952 return TREEVIEW_ScrollKeyDown(infoPtr
, wParam
);
4957 newSelection
= TREEVIEW_GetPrevListItem(infoPtr
, prevItem
);
4959 newSelection
= infoPtr
->root
->firstChild
;
4963 newSelection
= TREEVIEW_GetNextListItem(infoPtr
, prevItem
);
4967 newSelection
= infoPtr
->root
->firstChild
;
4971 newSelection
= TREEVIEW_GetLastListItem(infoPtr
, infoPtr
->root
);
4975 if (prevItem
->state
& TVIS_EXPANDED
)
4977 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
4979 else if (prevItem
->parent
!= infoPtr
->root
)
4981 newSelection
= prevItem
->parent
;
4986 if (TREEVIEW_HasChildren(infoPtr
, prevItem
))
4988 if (!(prevItem
->state
& TVIS_EXPANDED
))
4989 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
4992 newSelection
= prevItem
->firstChild
;
4999 TREEVIEW_ExpandAll(infoPtr
, prevItem
);
5003 if (!(prevItem
->state
& TVIS_EXPANDED
))
5004 TREEVIEW_Expand(infoPtr
, prevItem
, FALSE
, TRUE
);
5008 if (prevItem
->state
& TVIS_EXPANDED
)
5009 TREEVIEW_Collapse(infoPtr
, prevItem
, FALSE
, TRUE
);
5014 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5015 -TREEVIEW_GetVisibleCount(infoPtr
));
5020 = TREEVIEW_GetListItem(infoPtr
, prevItem
,
5021 TREEVIEW_GetVisibleCount(infoPtr
));
5025 newSelection
= prevItem
->parent
;
5026 if (newSelection
== infoPtr
->root
)
5027 newSelection
= NULL
;
5031 if (infoPtr
->dwStyle
& TVS_CHECKBOXES
)
5032 TREEVIEW_ToggleItemState(infoPtr
, prevItem
);
5036 if (newSelection
&& newSelection
!= prevItem
)
5038 if (TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, newSelection
,
5041 TREEVIEW_EnsureVisible(infoPtr
, newSelection
, FALSE
);
5049 TREEVIEW_Notify(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5051 LPNMHDR lpnmh
= (LPNMHDR
)lParam
;
5053 if (lpnmh
->code
== PGN_CALCSIZE
) {
5054 LPNMPGCALCSIZE lppgc
= (LPNMPGCALCSIZE
)lParam
;
5056 if (lppgc
->dwFlag
== PGF_CALCWIDTH
) {
5057 lppgc
->iWidth
= infoPtr
->treeWidth
;
5058 TRACE("got PGN_CALCSIZE, returning horz size = %ld, client=%ld\n",
5059 infoPtr
->treeWidth
, infoPtr
->clientWidth
);
5062 lppgc
->iHeight
= infoPtr
->treeHeight
;
5063 TRACE("got PGN_CALCSIZE, returning vert size = %ld, client=%ld\n",
5064 infoPtr
->treeHeight
, infoPtr
->clientHeight
);
5068 return DefWindowProcA(infoPtr
->hwnd
, WM_NOTIFY
, wParam
, lParam
);
5071 static INT
TREEVIEW_NotifyFormat (TREEVIEW_INFO
*infoPtr
, HWND hwndFrom
, UINT nCommand
)
5075 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
5077 if (nCommand
!= NF_REQUERY
) return 0;
5079 format
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwnd
, NF_QUERY
);
5080 TRACE("format=%d\n", format
);
5082 if (format
!= NFR_ANSI
&& format
!= NFR_UNICODE
) return 0;
5084 infoPtr
->bNtfUnicode
= (format
== NFR_UNICODE
);
5090 TREEVIEW_Size(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5092 if (wParam
== SIZE_RESTORED
)
5094 infoPtr
->clientWidth
= (short)LOWORD(lParam
);
5095 infoPtr
->clientHeight
= (short)HIWORD(lParam
);
5097 TREEVIEW_RecalculateVisibleOrder(infoPtr
, NULL
);
5098 TREEVIEW_SetFirstVisible(infoPtr
, infoPtr
->firstVisible
, TRUE
);
5099 TREEVIEW_UpdateScrollBars(infoPtr
);
5103 FIXME("WM_SIZE flag %x %lx not handled\n", wParam
, lParam
);
5106 TREEVIEW_Invalidate(infoPtr
, NULL
);
5111 TREEVIEW_StyleChanged(TREEVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
5113 TRACE("(%x %lx)\n", wParam
, lParam
);
5115 if (wParam
== GWL_STYLE
)
5117 DWORD dwNewStyle
= ((LPSTYLESTRUCT
)lParam
)->styleNew
;
5119 /* we have to take special care about tooltips */
5120 if ((infoPtr
->dwStyle
^ dwNewStyle
) & TVS_NOTOOLTIPS
)
5122 if (infoPtr
->dwStyle
& TVS_NOTOOLTIPS
)
5124 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip(infoPtr
->hwnd
);
5129 DestroyWindow(infoPtr
->hwndToolTip
);
5130 infoPtr
->hwndToolTip
= 0;
5134 infoPtr
->dwStyle
= dwNewStyle
;
5137 TREEVIEW_UpdateSubTree(infoPtr
, infoPtr
->root
);
5138 TREEVIEW_UpdateScrollBars(infoPtr
);
5139 TREEVIEW_Invalidate(infoPtr
, NULL
);
5145 TREEVIEW_SetFocus(TREEVIEW_INFO
*infoPtr
)
5149 if (!infoPtr
->selectedItem
)
5151 TREEVIEW_DoSelectItem(infoPtr
, TVGN_CARET
, infoPtr
->firstVisible
,
5155 TREEVIEW_SendSimpleNotify(infoPtr
, NM_SETFOCUS
);
5156 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5161 TREEVIEW_KillFocus(TREEVIEW_INFO
*infoPtr
)
5165 TREEVIEW_SendSimpleNotify(infoPtr
, NM_KILLFOCUS
);
5166 TREEVIEW_Invalidate(infoPtr
, infoPtr
->selectedItem
);
5171 static LRESULT WINAPI
5172 TREEVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5174 TREEVIEW_INFO
*infoPtr
= TREEVIEW_GetInfoPtr(hwnd
);
5176 TRACE("hwnd %p msg %04x wp=%08x lp=%08lx\n", hwnd
, uMsg
, wParam
, lParam
);
5178 if (infoPtr
) TREEVIEW_VerifyTree(infoPtr
);
5181 if (uMsg
== WM_CREATE
)
5182 TREEVIEW_Create(hwnd
);
5189 case TVM_CREATEDRAGIMAGE
:
5190 return TREEVIEW_CreateDragImage(infoPtr
, wParam
, lParam
);
5192 case TVM_DELETEITEM
:
5193 return TREEVIEW_DeleteItem(infoPtr
, (HTREEITEM
)lParam
);
5195 case TVM_EDITLABELA
:
5196 return (LRESULT
)TREEVIEW_EditLabelA(infoPtr
, (HTREEITEM
)lParam
);
5198 case TVM_EDITLABELW
:
5199 FIXME("Unimplemented msg TVM_EDITLABELW\n");
5202 case TVM_ENDEDITLABELNOW
:
5203 return TREEVIEW_EndEditLabelNow(infoPtr
, (BOOL
)wParam
);
5205 case TVM_ENSUREVISIBLE
:
5206 return TREEVIEW_EnsureVisible(infoPtr
, (HTREEITEM
)lParam
, TRUE
);
5209 return TREEVIEW_ExpandMsg(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5211 case TVM_GETBKCOLOR
:
5212 return TREEVIEW_GetBkColor(infoPtr
);
5215 return TREEVIEW_GetCount(infoPtr
);
5217 case TVM_GETEDITCONTROL
:
5218 return TREEVIEW_GetEditControl(infoPtr
);
5220 case TVM_GETIMAGELIST
:
5221 return TREEVIEW_GetImageList(infoPtr
, wParam
);
5224 return TREEVIEW_GetIndent(infoPtr
);
5226 case TVM_GETINSERTMARKCOLOR
:
5227 return TREEVIEW_GetInsertMarkColor(infoPtr
);
5229 case TVM_GETISEARCHSTRINGA
:
5230 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGA\n");
5233 case TVM_GETISEARCHSTRINGW
:
5234 FIXME("Unimplemented msg TVM_GETISEARCHSTRINGW\n");
5238 return TREEVIEW_GetItemA(infoPtr
, (LPTVITEMEXA
)lParam
);
5241 return TREEVIEW_GetItemW(infoPtr
, (LPTVITEMEXW
)lParam
);
5243 case TVM_GETITEMHEIGHT
:
5244 return TREEVIEW_GetItemHeight(infoPtr
);
5246 case TVM_GETITEMRECT
:
5247 return TREEVIEW_GetItemRect(infoPtr
, (BOOL
)wParam
, (LPRECT
)lParam
);
5249 case TVM_GETITEMSTATE
:
5250 return TREEVIEW_GetItemState(infoPtr
, (HTREEITEM
)wParam
, (UINT
)lParam
);
5252 case TVM_GETLINECOLOR
:
5253 return TREEVIEW_GetLineColor(infoPtr
);
5255 case TVM_GETNEXTITEM
:
5256 return TREEVIEW_GetNextItem(infoPtr
, (UINT
)wParam
, (HTREEITEM
)lParam
);
5258 case TVM_GETSCROLLTIME
:
5259 return TREEVIEW_GetScrollTime(infoPtr
);
5261 case TVM_GETTEXTCOLOR
:
5262 return TREEVIEW_GetTextColor(infoPtr
);
5264 case TVM_GETTOOLTIPS
:
5265 return TREEVIEW_GetToolTips(infoPtr
);
5267 case TVM_GETUNICODEFORMAT
:
5268 FIXME("Unimplemented msg TVM_GETUNICODEFORMAT\n");
5271 case TVM_GETVISIBLECOUNT
:
5272 return TREEVIEW_GetVisibleCount(infoPtr
);
5275 return TREEVIEW_HitTest(infoPtr
, (LPTVHITTESTINFO
)lParam
);
5277 case TVM_INSERTITEMA
:
5278 return TREEVIEW_InsertItemA(infoPtr
, lParam
);
5280 case TVM_INSERTITEMW
:
5281 return TREEVIEW_InsertItemW(infoPtr
, lParam
);
5283 case TVM_SELECTITEM
:
5284 return TREEVIEW_SelectItem(infoPtr
, (INT
)wParam
, (HTREEITEM
)lParam
);
5286 case TVM_SETBKCOLOR
:
5287 return TREEVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
5289 case TVM_SETIMAGELIST
:
5290 return TREEVIEW_SetImageList(infoPtr
, wParam
, (HIMAGELIST
)lParam
);
5293 return TREEVIEW_SetIndent(infoPtr
, (UINT
)wParam
);
5295 case TVM_SETINSERTMARK
:
5296 return TREEVIEW_SetInsertMark(infoPtr
, (BOOL
)wParam
, (HTREEITEM
)lParam
);
5298 case TVM_SETINSERTMARKCOLOR
:
5299 return TREEVIEW_SetInsertMarkColor(infoPtr
, (COLORREF
)lParam
);
5302 return TREEVIEW_SetItemA(infoPtr
, (LPTVITEMEXA
)lParam
);
5305 return TREEVIEW_SetItemW(infoPtr
, (LPTVITEMEXW
)lParam
);
5308 case TVM_SETLINECOLOR
:
5309 return TREEVIEW_SetLineColor(infoPtr
, (COLORREF
)lParam
);
5311 case TVM_SETITEMHEIGHT
:
5312 return TREEVIEW_SetItemHeight(infoPtr
, (INT
)(SHORT
)wParam
);
5314 case TVM_SETSCROLLTIME
:
5315 return TREEVIEW_SetScrollTime(infoPtr
, (UINT
)wParam
);
5317 case TVM_SETTEXTCOLOR
:
5318 return TREEVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
5320 case TVM_SETTOOLTIPS
:
5321 return TREEVIEW_SetToolTips(infoPtr
, (HWND
)wParam
);
5323 case TVM_SETUNICODEFORMAT
:
5324 FIXME("Unimplemented msg TVM_SETUNICODEFORMAT\n");
5327 case TVM_SORTCHILDREN
:
5328 return TREEVIEW_SortChildren(infoPtr
, wParam
, lParam
);
5330 case TVM_SORTCHILDRENCB
:
5331 return TREEVIEW_SortChildrenCB(infoPtr
, wParam
, (LPTVSORTCB
)lParam
);
5334 return TREEVIEW_ProcessLetterKeys( hwnd
, wParam
, lParam
);
5337 return TREEVIEW_Command(infoPtr
, wParam
, lParam
);
5340 return TREEVIEW_Destroy(infoPtr
);
5345 return TREEVIEW_EraseBackground(infoPtr
, (HDC
)wParam
);
5348 return DLGC_WANTARROWS
| DLGC_WANTCHARS
;
5351 return TREEVIEW_GetFont(infoPtr
);
5354 return TREEVIEW_HScroll(infoPtr
, wParam
);
5357 return TREEVIEW_KeyDown(infoPtr
, wParam
);
5360 return TREEVIEW_KillFocus(infoPtr
);
5362 case WM_LBUTTONDBLCLK
:
5363 return TREEVIEW_LButtonDoubleClick(infoPtr
, lParam
);
5365 case WM_LBUTTONDOWN
:
5366 return TREEVIEW_LButtonDown(infoPtr
, lParam
);
5368 /* WM_MBUTTONDOWN */
5373 return TREEVIEW_Notify(infoPtr
, wParam
, lParam
);
5375 case WM_NOTIFYFORMAT
:
5376 return TREEVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (UINT
)lParam
);
5379 return TREEVIEW_Paint(infoPtr
, wParam
);
5381 /* WM_PRINTCLIENT */
5383 case WM_RBUTTONDOWN
:
5384 return TREEVIEW_RButtonDown(infoPtr
, lParam
);
5387 return TREEVIEW_SetFocus(infoPtr
);
5390 return TREEVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (BOOL
)lParam
);
5393 return TREEVIEW_SetRedraw(infoPtr
, wParam
, lParam
);
5396 return TREEVIEW_Size(infoPtr
, wParam
, lParam
);
5398 case WM_STYLECHANGED
:
5399 return TREEVIEW_StyleChanged(infoPtr
, wParam
, lParam
);
5401 /* WM_SYSCOLORCHANGE */
5406 return TREEVIEW_HandleTimer(infoPtr
, wParam
);
5409 return TREEVIEW_VScroll(infoPtr
, wParam
);
5411 /* WM_WININICHANGE */
5414 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
5416 return TREEVIEW_MouseWheel(infoPtr
, wParam
);
5419 TRACE("drawItem\n");
5423 /* This mostly catches MFC and Delphi messages. :( */
5424 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
5425 TRACE("Unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
5427 return DefWindowProcA(hwnd
, uMsg
, wParam
, lParam
);
5433 /* Class Registration ***************************************************/
5436 TREEVIEW_Register(void)
5442 ZeroMemory(&wndClass
, sizeof(WNDCLASSA
));
5443 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
5444 wndClass
.lpfnWndProc
= (WNDPROC
)TREEVIEW_WindowProc
;
5445 wndClass
.cbClsExtra
= 0;
5446 wndClass
.cbWndExtra
= sizeof(TREEVIEW_INFO
*);
5448 wndClass
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
5449 wndClass
.hbrBackground
= 0;
5450 wndClass
.lpszClassName
= WC_TREEVIEWA
;
5452 RegisterClassA(&wndClass
);
5457 TREEVIEW_Unregister(void)
5459 UnregisterClassA(WC_TREEVIEWA
, NULL
);
5463 /* Tree Verification ****************************************************/
5467 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
);
5469 static inline void TREEVIEW_VerifyItemCommon(TREEVIEW_INFO
*infoPtr
,
5470 TREEVIEW_ITEM
*item
)
5472 assert(infoPtr
!= NULL
);
5473 assert(item
!= NULL
);
5475 /* both NULL, or both non-null */
5476 assert((item
->firstChild
== NULL
) == (item
->lastChild
== NULL
));
5478 assert(item
->firstChild
!= item
);
5479 assert(item
->lastChild
!= item
);
5481 if (item
->firstChild
)
5483 assert(item
->firstChild
->parent
== item
);
5484 assert(item
->firstChild
->prevSibling
== NULL
);
5487 if (item
->lastChild
)
5489 assert(item
->lastChild
->parent
== item
);
5490 assert(item
->lastChild
->nextSibling
== NULL
);
5493 assert(item
->nextSibling
!= item
);
5494 if (item
->nextSibling
)
5496 assert(item
->nextSibling
->parent
== item
->parent
);
5497 assert(item
->nextSibling
->prevSibling
== item
);
5500 assert(item
->prevSibling
!= item
);
5501 if (item
->prevSibling
)
5503 assert(item
->prevSibling
->parent
== item
->parent
);
5504 assert(item
->prevSibling
->nextSibling
== item
);
5509 TREEVIEW_VerifyItem(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
5511 assert(item
!= NULL
);
5513 assert(item
->parent
!= NULL
);
5514 assert(item
->parent
!= item
);
5515 assert(item
->iLevel
== item
->parent
->iLevel
+ 1);
5517 assert(DPA_GetPtrIndex(infoPtr
->items
, item
) != -1);
5519 TREEVIEW_VerifyItemCommon(infoPtr
, item
);
5521 TREEVIEW_VerifyChildren(infoPtr
, item
);
5525 TREEVIEW_VerifyChildren(TREEVIEW_INFO
*infoPtr
, TREEVIEW_ITEM
*item
)
5527 TREEVIEW_ITEM
*child
;
5528 assert(item
!= NULL
);
5530 for (child
= item
->firstChild
; child
!= NULL
; child
= child
->nextSibling
)
5531 TREEVIEW_VerifyItem(infoPtr
, child
);
5535 TREEVIEW_VerifyRoot(TREEVIEW_INFO
*infoPtr
)
5537 TREEVIEW_ITEM
*root
= infoPtr
->root
;
5539 assert(root
!= NULL
);
5540 assert(root
->iLevel
== -1);
5541 assert(root
->parent
== NULL
);
5542 assert(root
->prevSibling
== NULL
);
5544 TREEVIEW_VerifyItemCommon(infoPtr
, root
);
5546 TREEVIEW_VerifyChildren(infoPtr
, root
);
5550 TREEVIEW_VerifyTree(TREEVIEW_INFO
*infoPtr
)
5552 assert(infoPtr
!= NULL
);
5554 TREEVIEW_VerifyRoot(infoPtr
);