3 * Copyright 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de>
4 * Copyright 1998 Alex Priem <alexp@sci.kun.nl>
8 * - Nearly all notifications.
10 * list-handling stuff: sort, sorted insertitem.
13 -small array containing info about positions.
14 -better implementation of DrawItem (connecting lines).
15 -implement partial drawing?
16 * Expand: -ctlmacro expands twice ->toggle.
23 -GetNextItem: add flag for traversing visible items
24 -DblClick: ctlmacro.exe's NM_DBLCLK seems to go wrong (returns FALSE).
36 /* ffs should be in <string.h>. */
38 /* Defines, since they do not need to return previous state, and nr
39 * has no side effects in this file.
41 #define tv_test_bit(nr,bf) (((LPBYTE)bf)[nr>>3]&(1<<(nr&7)))
42 #define tv_set_bit(nr,bf) ((LPBYTE)bf)[nr>>3]|=(1<<(nr&7))
43 #define tv_clear_bit(nr,bf) ((LPBYTE)bf)[nr>>3]&=~(1<<(nr&7))
46 #define TREEVIEW_GetInfoPtr(wndPtr) ((TREEVIEW_INFO *)wndPtr->wExtra[0])
49 TREEVIEW_SendSimpleNotify (WND *wndPtr, UINT32 code);
51 TREEVIEW_SendTreeviewNotify (WND *wndPtr, UINT32 code, UINT32 action,
52 INT32 oldItem, INT32 newItem, POINT32 pt);
54 TREEVIEW_SelectItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam);
56 TREEVIEW_Refresh (WND *wndPtr, HDC32 hdc);
62 /* helper functions. Work with the assumption that validity of operands
63 is checked beforehand */
66 static TREEVIEW_ITEM *
67 TREEVIEW_ValidItem (TREEVIEW_INFO *infoPtr,int handle)
70 if ((!handle) || (handle>infoPtr->uMaxHandle)) return NULL;
71 if (tv_test_bit (handle, infoPtr->freeList)) return NULL;
73 return & infoPtr->items[handle];
78 static TREEVIEW_ITEM *TREEVIEW_GetPrevListItem (TREEVIEW_INFO *infoPtr,
79 TREEVIEW_ITEM *tvItem)
82 TREEVIEW_ITEM *wineItem;
84 if (tvItem->upsibling)
85 return (& infoPtr->items[tvItem->upsibling]);
88 while (wineItem->parent) {
89 wineItem=& infoPtr->items[wineItem->parent];
90 if (wineItem->upsibling)
91 return (& infoPtr->items[wineItem->upsibling]);
97 static TREEVIEW_ITEM *TREEVIEW_GetNextListItem (TREEVIEW_INFO *infoPtr,
98 TREEVIEW_ITEM *tvItem)
101 TREEVIEW_ITEM *wineItem;
104 return (& infoPtr->items[tvItem->sibling]);
107 while (wineItem->parent) {
108 wineItem=& infoPtr->items [wineItem->parent];
109 if (wineItem->sibling)
110 return (& infoPtr->items [wineItem->sibling]);
116 static TREEVIEW_ITEM *TREEVIEW_GetLastListItem (TREEVIEW_INFO *infoPtr)
119 TREEVIEW_ITEM *wineItem;
122 if (infoPtr->TopRootItem)
123 wineItem=& infoPtr->items [infoPtr->TopRootItem];
124 while (wineItem->sibling)
125 wineItem=& infoPtr->items [wineItem->sibling];
134 TREEVIEW_RemoveItem (TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
137 TREEVIEW_ITEM *parentItem, *upsiblingItem, *siblingItem;
140 iItem=wineItem->hItem;
141 tv_set_bit(iItem,infoPtr->freeList);
142 infoPtr->uNumItems--;
144 if (wineItem->pszText!=LPSTR_TEXTCALLBACK32A)
145 HeapFree (GetProcessHeap (), 0, wineItem->pszText);
147 if (wineItem->parent) {
148 parentItem=& infoPtr->items[ wineItem->parent];
149 if (parentItem->cChildren==1) {
150 parentItem->cChildren=0;
151 parentItem->firstChild=0;
154 parentItem->cChildren--;
155 if (parentItem->firstChild==iItem)
156 parentItem->firstChild=wineItem->sibling;
160 if (iItem==infoPtr->TopRootItem)
161 infoPtr->TopRootItem=wineItem->sibling;
162 if (wineItem->upsibling) {
163 upsiblingItem=& infoPtr->items [wineItem->upsibling];
164 upsiblingItem->sibling=wineItem->sibling;
166 if (wineItem->sibling) {
167 siblingItem=& infoPtr->items [wineItem->sibling];
168 siblingItem->upsibling=wineItem->upsibling;
174 static void TREEVIEW_RemoveAllChildren (TREEVIEW_INFO *infoPtr,
175 TREEVIEW_ITEM *parentItem)
178 TREEVIEW_ITEM *killItem;
181 kill=parentItem->firstChild;
183 tv_set_bit ( kill, infoPtr->freeList);
184 killItem=& infoPtr->items[kill];
185 if (killItem->pszText!=LPSTR_TEXTCALLBACK32A)
186 HeapFree (GetProcessHeap (), 0, killItem->pszText);
187 kill=killItem->sibling;
189 infoPtr->uNumItems -= parentItem->cChildren;
190 parentItem->firstChild = 0;
191 parentItem->cChildren = 0;
195 /* Note:TREEVIEW_RemoveTree doesn't remove infoPtr itself */
197 static void TREEVIEW_RemoveTree (TREEVIEW_INFO *infoPtr)
201 TREEVIEW_ITEM *killItem;
204 for (i=1; i<=infoPtr->uMaxHandle; i++)
205 if (!tv_test_bit (i, infoPtr->freeList)) {
206 killItem=& infoPtr->items [i];
207 if (killItem->pszText!=LPSTR_TEXTCALLBACK32A)
208 HeapFree (GetProcessHeap (), 0, killItem->pszText);
211 if (infoPtr->uNumPtrsAlloced) {
212 HeapFree (GetProcessHeap (), 0, infoPtr->items);
213 HeapFree (GetProcessHeap (), 0, infoPtr->freeList);
214 infoPtr->uNumItems=0;
215 infoPtr->uNumPtrsAlloced=0;
216 infoPtr->uMaxHandle=0;
230 TREEVIEW_GetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
232 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
234 TRACE (treeview,"\n");
236 if (infoPtr==NULL) return 0;
238 if ((INT32)wParam == TVSIL_NORMAL)
239 return (LRESULT) infoPtr->himlNormal;
240 if ((INT32)wParam == TVSIL_STATE)
241 return (LRESULT) infoPtr->himlState;
250 TREEVIEW_SetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
252 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
255 switch ((INT32)wParam) {
257 himlTemp = infoPtr->himlNormal;
258 infoPtr->himlNormal = (HIMAGELIST)lParam;
259 return (LRESULT)himlTemp;
262 himlTemp = infoPtr->himlState;
263 infoPtr->himlState = (HIMAGELIST)lParam;
264 return (LRESULT)himlTemp;
267 return (LRESULT)NULL;
273 TREEVIEW_SetItemHeight (WND *wndPtr, WPARAM32 wParam)
275 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
276 INT32 prevHeight=infoPtr->uItemHeight;
282 hdc=GetDC32 (wndPtr->hwndSelf);
283 infoPtr->uItemHeight=-1;
284 GetTextMetrics32A (hdc, &tm);
285 infoPtr->uRealItemHeight= tm.tmHeight + tm.tmExternalLeading;
286 ReleaseDC32 (wndPtr->hwndSelf, hdc);
290 /* FIXME: check wParam > imagelist height */
292 if (!(wndPtr->dwStyle & TVS_NONEVENHEIGHT))
293 infoPtr->uItemHeight = (INT32) wParam & 0xfffffffe;
298 TREEVIEW_GetItemHeight (WND *wndPtr)
300 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
302 return infoPtr->uItemHeight;
306 TREEVIEW_SetTextColor (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
308 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
309 COLORREF prevColor=infoPtr->clrText;
311 infoPtr->clrText=(COLORREF) lParam;
312 return (LRESULT) prevColor;
316 TREEVIEW_GetTextColor (WND *wndPtr)
318 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
320 return (LRESULT) infoPtr->clrText;
325 TREEVIEW_DrawItem (WND *wndPtr, HDC32 hdc, TREEVIEW_ITEM *wineItem,
326 TREEVIEW_ITEM *upperItem, int indent)
328 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
329 INT32 oldBkMode,center,xpos;
331 UINT32 uTextJustify = DT_LEFT;
332 HPEN32 hOldPen, hnewPen,hRootPen;
335 hnewPen = CreatePen32(PS_DOT, 0, GetSysColor32(COLOR_WINDOWTEXT) );
336 hOldPen = SelectObject32( hdc, hnewPen );
340 upper=upperItem->rect;
345 center=(r.top+r.bottom)/2;
348 if (wndPtr->dwStyle & TVS_HASLINES) {
350 if ((wndPtr->dwStyle & TVS_LINESATROOT) && (indent==0)) {
351 points[0].y=points[1].y=center;
352 points[2].y=upper.top;
353 points[1].x=points[2].x=upper.left;
354 points[0].x=upper.left+12;
357 Polyline32 (hdc,points,3);
360 points[0].y=points[1].y=center;
361 points[2].y=upper.top;
362 points[1].x=points[2].x=upper.left+13;
363 points[0].x=upper.left+25;
365 Polyline32 (hdc,points,3);
369 DeleteObject32(hnewPen);
370 SelectObject32(hdc, hOldPen);
372 if ((wndPtr->dwStyle & TVS_HASBUTTONS) && (wineItem->cChildren)) {
374 hRootPen = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_WINDOW) );
375 SelectObject32( hdc, hRootPen );
378 Rectangle32 (hdc, xpos-4, center-4, xpos+5, center+5);
379 MoveToEx32 (hdc, xpos-2, center, NULL);
380 LineTo32 (hdc, xpos+3, center);
381 if (!(wineItem->state & TVIS_EXPANDED)) {
382 MoveToEx32 (hdc, xpos, center-2, NULL);
383 LineTo32 (hdc, xpos, center+3);
385 /* DeleteObject32(hRootPen); */
391 if (wineItem->mask & TVIF_IMAGE) {
392 if (wineItem->iImage!=I_IMAGECALLBACK) {
393 if (infoPtr->himlNormal) {
394 ImageList_Draw (infoPtr->himlNormal,wineItem->iImage, hdc,
395 xpos-2, r.top+1, ILD_NORMAL);
402 if ((wineItem->mask & TVIF_TEXT) && (wineItem->pszText)) {
403 if (wineItem->state & TVIS_SELECTED) {
404 oldBkMode = SetBkMode32(hdc, OPAQUE);
405 oldBkColor= SetBkColor32 (hdc, GetSysColor32( COLOR_HIGHLIGHT));
406 SetTextColor32 (hdc, GetSysColor32(COLOR_HIGHLIGHTTEXT));
409 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
413 if (infoPtr->clrText==-1)
414 SetTextColor32 (hdc, COLOR_BTNTEXT);
416 SetTextColor32 (hdc, infoPtr->clrText); /* FIXME: retval */
417 DrawText32A(hdc, wineItem->pszText, lstrlen32A(wineItem->pszText),
418 &r, uTextJustify|DT_VCENTER|DT_SINGLELINE);
419 if (oldBkMode != TRANSPARENT)
420 SetBkMode32(hdc, oldBkMode);
421 if (wineItem->state & TVIS_SELECTED)
422 SetBkColor32 (hdc, oldBkColor);
425 return wineItem->rect.right;
435 TREEVIEW_GetItemRect (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
437 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
438 TREEVIEW_ITEM *wineItem;
442 TRACE (treeview,"\n");
443 if (infoPtr==NULL) return FALSE;
445 iItem = (INT32)lParam;
446 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
447 if (!wineItem) return FALSE;
449 wineItem=& infoPtr->items[ iItem ];
450 if (!wineItem->visible) return FALSE;
452 lpRect = (LPRECT32)lParam;
453 if (lpRect == NULL) return FALSE;
455 if ((INT32) wParam) {
456 lpRect->left = wineItem->text.left;
457 lpRect->right = wineItem->text.right;
458 lpRect->bottom = wineItem->text.bottom;
459 lpRect->top = wineItem->text.top;
461 lpRect->left = wineItem->rect.left;
462 lpRect->right = wineItem->rect.right;
463 lpRect->bottom = wineItem->rect.bottom;
464 lpRect->top = wineItem->rect.top;
473 TREEVIEW_GetVisibleCount (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
476 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
478 TRACE (treeview,"\n");
480 return (LRESULT) infoPtr->uVisibleHeight / infoPtr->uRealItemHeight;
486 TREEVIEW_SetItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
488 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
489 TREEVIEW_ITEM *wineItem;
493 TRACE (treeview,"\n");
494 tvItem=(LPTVITEM) lParam;
497 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
498 if (!wineItem) return FALSE;
500 if (tvItem->mask & TVIF_CHILDREN) {
501 wineItem->cChildren=tvItem->cChildren;
504 if (tvItem->mask & TVIF_IMAGE) {
505 wineItem->iImage=tvItem->iImage;
508 if (tvItem->mask & TVIF_INTEGRAL) {
509 /* wineItem->iIntegral=tvItem->iIntegral; */
512 if (tvItem->mask & TVIF_PARAM) {
513 wineItem->lParam=tvItem->lParam;
516 if (tvItem->mask & TVIF_SELECTEDIMAGE) {
517 wineItem->iSelectedImage=tvItem->iSelectedImage;
520 if (tvItem->mask & TVIF_STATE) {
521 wineItem->state=tvItem->state & tvItem->stateMask;
524 if (tvItem->mask & TVIF_TEXT) {
525 len=tvItem->cchTextMax;
526 if (len>wineItem->cchTextMax) {
527 HeapFree (GetProcessHeap (), 0, wineItem->pszText);
528 wineItem->pszText= HeapAlloc (GetProcessHeap (),
529 HEAP_ZERO_MEMORY, len+1);
531 lstrcpyn32A (wineItem->pszText, tvItem->pszText,len);
542 TREEVIEW_Refresh (WND *wndPtr, HDC32 hdc)
545 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
546 HFONT32 hFont, hOldFont;
549 INT32 iItem, indent, x, y, height;
550 INT32 viewtop,viewbottom,viewleft,viewright;
551 TREEVIEW_ITEM *wineItem, *prevItem;
553 TRACE (treeview,"\n");
555 if (infoPtr->Timer & TV_REFRESH_TIMER_SET) {
556 KillTimer32 (wndPtr->hwndSelf, TV_REFRESH_TIMER);
557 infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
561 GetClientRect32 (wndPtr->hwndSelf, &rect);
562 if ((rect.left-rect.right ==0) || (rect.top-rect.bottom==0)) return;
564 viewbottom=infoPtr->cy + rect.bottom-rect.top;
565 viewleft=infoPtr->cx;
566 viewright=infoPtr->cx + rect.right-rect.left;
568 infoPtr->uVisibleHeight=viewbottom - viewtop;
570 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject32 (DEFAULT_GUI_FONT);
571 hOldFont = SelectObject32 (hdc, hFont);
573 /* draw background */
574 hbrBk = GetSysColorBrush32(COLOR_WINDOW);
575 FillRect32(hdc, &rect, hbrBk);
578 iItem=infoPtr->TopRootItem;
579 infoPtr->firstVisible=0;
583 TRACE (treeview, "[%d %d %d %d]\n",viewtop,viewbottom,viewleft,viewright);
587 wineItem= & infoPtr->items[iItem];
589 TRACE (treeview, "%d %d [%d %d %d %d] (%s)\n",y,x,
590 wineItem->rect.top, wineItem->rect.bottom,
591 wineItem->rect.left, wineItem->rect.right,
594 height=infoPtr->uRealItemHeight * wineItem->iIntegral;
595 if ((y >= viewtop) && (y <= viewbottom) &&
596 (x >= viewleft ) && (x <= viewright)) {
597 wineItem->rect.top = y - infoPtr->cy + rect.top;
598 wineItem->rect.bottom = wineItem->rect.top + height ;
599 wineItem->rect.left = x - infoPtr->cx + rect.left;
600 wineItem->rect.right = rect.right;
601 if (!infoPtr->firstVisible)
602 infoPtr->firstVisible=wineItem->hItem;
603 TREEVIEW_DrawItem (wndPtr, hdc, wineItem, prevItem, indent);
606 wineItem->rect.top = wineItem->rect.bottom = -1;
607 wineItem->rect.left = wineItem->rect.right = -1;
610 /* look up next item */
612 if ((wineItem->firstChild) && (wineItem->state & TVIS_EXPANDED)) {
613 iItem=wineItem->firstChild;
618 iItem=wineItem->sibling;
619 while ((!iItem) && (indent>0)) {
623 wineItem=&infoPtr->items[wineItem->parent];
624 iItem=wineItem->sibling;
630 infoPtr->uTotalHeight=y;
631 if (y >= (viewbottom-viewtop)) {
632 if (!(infoPtr->uInternalStatus & TV_VSCROLL))
633 ShowScrollBar32 (wndPtr->hwndSelf, SB_VERT, TRUE);
634 infoPtr->uInternalStatus |=TV_VSCROLL;
635 SetScrollRange32 (wndPtr->hwndSelf, SB_VERT, 0,
636 y - infoPtr->uVisibleHeight, FALSE);
637 SetScrollPos32 (wndPtr->hwndSelf, SB_VERT, infoPtr->cy, TRUE);
640 if (infoPtr->uInternalStatus & TV_VSCROLL)
641 ShowScrollBar32 (wndPtr->hwndSelf, SB_VERT, FALSE);
642 infoPtr->uInternalStatus &= ~TV_VSCROLL;
646 SelectObject32 (hdc, hOldFont);
651 TREEVIEW_HandleTimer ( WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
653 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
656 if (!infoPtr) return FALSE;
658 TRACE (treeview, "timer\n");
661 case TV_REFRESH_TIMER:
662 KillTimer32 (wndPtr->hwndSelf, TV_REFRESH_TIMER);
663 infoPtr->Timer &= ~TV_REFRESH_TIMER_SET;
664 hdc=GetDC32 (wndPtr->hwndSelf);
665 TREEVIEW_Refresh (wndPtr, hdc);
666 ReleaseDC32 (wndPtr->hwndSelf, hdc);
669 KillTimer32 (wndPtr->hwndSelf, TV_EDIT_TIMER);
670 infoPtr->Timer &= ~TV_EDIT_TIMER_SET;
679 TREEVIEW_QueueRefresh (WND *wndPtr)
682 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
684 TRACE (treeview,"queued\n");
685 if (infoPtr->Timer & TV_REFRESH_TIMER_SET) {
686 KillTimer32 (wndPtr->hwndSelf, TV_REFRESH_TIMER);
689 SetTimer32 (wndPtr->hwndSelf, TV_REFRESH_TIMER, TV_REFRESH_DELAY, 0);
690 infoPtr->Timer|=TV_REFRESH_TIMER_SET;
696 TREEVIEW_GetItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
698 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
700 TREEVIEW_ITEM *wineItem;
703 TRACE (treeview,"\n");
704 tvItem=(LPTVITEM) lParam;
707 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
708 if (!wineItem) return FALSE;
711 if (tvItem->mask & TVIF_CHILDREN) {
712 tvItem->cChildren=wineItem->cChildren;
715 if (tvItem->mask & TVIF_HANDLE) {
716 tvItem->hItem=wineItem->hItem;
719 if (tvItem->mask & TVIF_IMAGE) {
720 tvItem->iImage=wineItem->iImage;
723 if (tvItem->mask & TVIF_INTEGRAL) {
724 /* tvItem->iIntegral=wineItem->iIntegral; */
727 if (tvItem->mask & TVIF_PARAM) {
728 tvItem->lParam=wineItem->lParam;
731 if (tvItem->mask & TVIF_SELECTEDIMAGE) {
732 tvItem->iSelectedImage=wineItem->iSelectedImage;
735 if (tvItem->mask & TVIF_STATE) {
736 tvItem->state=wineItem->state & tvItem->stateMask;
739 if (tvItem->mask & TVIF_TEXT) {
740 len=wineItem->cchTextMax;
741 if (wineItem->cchTextMax>tvItem->cchTextMax)
742 len=tvItem->cchTextMax-1;
743 lstrcpyn32A (tvItem->pszText, tvItem->pszText,len);
752 TREEVIEW_GetNextItem32 (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
755 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
756 TREEVIEW_ITEM *wineItem;
760 TRACE (treeview,"item:%lu, flags:%x\n", lParam, wParam);
761 if (!infoPtr) return FALSE;
763 flag= (INT32) wParam;
765 case TVGN_ROOT: return (LRESULT) infoPtr->TopRootItem;
766 case TVGN_CARET: return (LRESULT) infoPtr->selectedItem;
767 case TVGN_FIRSTVISIBLE: return (LRESULT) infoPtr->firstVisible;
768 case TVGN_DROPHILITE: return (LRESULT) infoPtr->dropItem;
771 iItem= (INT32) lParam;
772 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
773 if (!wineItem) return FALSE;
776 case TVGN_NEXT: return (LRESULT) wineItem->sibling;
777 case TVGN_PREVIOUS: return (LRESULT) wineItem->upsibling;
778 case TVGN_PARENT: return (LRESULT) wineItem->parent;
779 case TVGN_CHILD: return (LRESULT) wineItem->firstChild;
780 case TVGN_LASTVISIBLE: FIXME (treeview,"TVGN_LASTVISIBLE not implemented\n");
782 case TVGN_NEXTVISIBLE: wineItem=TREEVIEW_GetNextListItem
785 return (LRESULT) wineItem->hItem;
788 case TVGN_PREVIOUSVISIBLE: wineItem=TREEVIEW_GetPrevListItem
791 return (LRESULT) wineItem->hItem;
794 default: FIXME (treeview,"Unknown msg %x,item %x\n", flag,iItem);
802 TREEVIEW_GetCount (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
804 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
806 return (LRESULT) infoPtr->uNumItems;
812 /* the method used below isn't the most memory-friendly, but it avoids
813 a lot of memory reallocations */
815 /* BTW: we waste handle 0; 0 is not an allowed handle. Fix this by
816 decreasing infoptr->items with 1, and increasing it by 1 if
817 it is referenced in mm-handling stuff? */
820 TREEVIEW_InsertItem32A (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
823 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
824 TVINSERTSTRUCT *ptdi;
826 TREEVIEW_ITEM *wineItem, *parentItem, *prevsib, *sibItem;
827 INT32 iItem,listItems,i,len;
829 TRACE (treeview,"\n");
830 ptdi = (TVINSERTSTRUCT *) lParam;
832 /* check if memory is available */
834 if (infoPtr->uNumPtrsAlloced==0) {
835 infoPtr->items = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
836 TVITEM_ALLOC*sizeof (TREEVIEW_ITEM));
837 infoPtr->freeList= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
838 (1+(TVITEM_ALLOC>>5)) *sizeof (INT32));
839 infoPtr->uNumPtrsAlloced=TVITEM_ALLOC;
840 infoPtr->TopRootItem=1;
843 if (infoPtr->uNumItems == (infoPtr->uNumPtrsAlloced-1) ) {
844 TREEVIEW_ITEM *oldItems = infoPtr->items;
845 INT32 *oldfreeList = infoPtr->freeList;
847 infoPtr->uNumPtrsAlloced*=2;
848 infoPtr->items = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
849 infoPtr->uNumPtrsAlloced*sizeof (TREEVIEW_ITEM));
850 infoPtr->freeList= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
851 (1+(infoPtr->uNumPtrsAlloced>>5))*sizeof (INT32));
853 memcpy (&infoPtr->items[0], &oldItems[0],
854 infoPtr->uNumPtrsAlloced/2 * sizeof(TREEVIEW_ITEM));
855 memcpy (&infoPtr->freeList[0], &oldfreeList[0],
856 (infoPtr->uNumPtrsAlloced>>6) * sizeof(INT32));
858 HeapFree (GetProcessHeap (), 0, oldItems);
859 HeapFree (GetProcessHeap (), 0, oldfreeList);
863 infoPtr->uNumItems++;
865 if (infoPtr->uMaxHandle==(infoPtr->uNumItems-1)) {
866 iItem=infoPtr->uNumItems;
867 infoPtr->uMaxHandle++;
869 else { /* check freelist */
870 for (i=0; i<infoPtr->uNumPtrsAlloced>>5; i++) {
871 if (infoPtr->freeList[i]) {
872 iItem=ffs (infoPtr->freeList[i]);
873 tv_clear_bit(iItem,&infoPtr->freeList[i]);
878 if (!iItem) ERR (treeview, "Argh -- can't find free item.\n");
880 tvItem= & ptdi->item;
881 wineItem=& infoPtr->items[iItem];
885 if ((ptdi->hParent==TVI_ROOT) || (ptdi->hParent==0)) {
888 sibItem=&infoPtr->items [infoPtr->TopRootItem];
889 listItems=infoPtr->uNumItems;
892 parentItem= &infoPtr->items[ptdi->hParent];
893 if (!parentItem->firstChild)
894 parentItem->firstChild=iItem;
895 wineItem->parent=ptdi->hParent;
896 sibItem=&infoPtr->items [parentItem->firstChild];
897 parentItem->cChildren++;
898 listItems=parentItem->cChildren;
901 wineItem->upsibling=0; /* needed in case we're the first item in a list */
903 wineItem->firstChild=0;
907 switch (ptdi->hInsertAfter) {
908 case TVI_FIRST: wineItem->sibling=infoPtr->TopRootItem;
909 infoPtr->TopRootItem=iItem;
912 while (sibItem->sibling) {
914 sibItem=&infoPtr->items [sibItem->sibling];
916 sibItem->sibling=iItem;
918 wineItem->upsibling=prevsib->hItem;
920 wineItem->sibling=0; /* terminate list */
923 FIXME (treeview, "Sorted insert not implemented yet\n");
926 while ((sibItem->sibling) && (sibItem->sibling!=iItem)) {
928 sibItem=&infoPtr->items [sibItem->sibling];
930 if (sibItem->sibling)
931 WARN (treeview, "Buggy program tried to insert item after nonexisting handle.");
932 sibItem->upsibling=iItem;
933 wineItem->sibling=sibItem->hItem;
935 wineItem->upsibling=prevsib->hItem;
941 /* Fill in info structure */
943 wineItem->mask=tvItem->mask;
944 wineItem->hItem=iItem;
945 wineItem->iIntegral=1;
947 if (tvItem->mask & TVIF_CHILDREN)
948 wineItem->cChildren=tvItem->cChildren;
950 if (tvItem->mask & TVIF_IMAGE)
951 wineItem->iImage=tvItem->iImage;
953 /* if (tvItem->mask & TVIF_INTEGRAL)
954 wineItem->iIntegral=tvItem->iIntegral; */
957 if (tvItem->mask & TVIF_PARAM)
958 wineItem->lParam=tvItem->lParam;
960 if (tvItem->mask & TVIF_SELECTEDIMAGE)
961 wineItem->iSelectedImage=tvItem->iSelectedImage;
963 if (tvItem->mask & TVIF_STATE) {
964 wineItem->state=tvItem->state;
965 wineItem->stateMask=tvItem->stateMask;
968 if (tvItem->mask & TVIF_TEXT) {
969 TRACE (treeview,"(%s)\n", tvItem->pszText);
970 if (tvItem->pszText!=LPSTR_TEXTCALLBACK32A) {
971 len = lstrlen32A (tvItem->pszText)+1;
973 HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, len+1);
974 lstrcpy32A (wineItem->pszText, tvItem->pszText);
975 wineItem->cchTextMax=len;
979 TREEVIEW_QueueRefresh (wndPtr);
981 return (LRESULT) iItem;
987 TREEVIEW_DeleteItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
989 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
992 TREEVIEW_ITEM *wineItem;
994 TRACE (treeview,"\n");
995 if (!infoPtr) return FALSE;
997 if ((INT32) lParam == TVI_ROOT) {
998 TREEVIEW_RemoveTree (infoPtr);
1000 iItem= (INT32) lParam;
1001 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
1002 if (!wineItem) return FALSE;
1003 TREEVIEW_SendTreeviewNotify (wndPtr, TVN_DELETEITEM, 0, iItem, 0, pt);
1004 TREEVIEW_RemoveItem (infoPtr, wineItem);
1007 TREEVIEW_QueueRefresh (wndPtr);
1014 TREEVIEW_GetIndent (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1016 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1018 return infoPtr->uIndent;
1022 TREEVIEW_SetIndent (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1024 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1027 newIndent=(INT32) wParam;
1028 if (newIndent < MINIMUM_INDENT) newIndent=MINIMUM_INDENT;
1029 infoPtr->uIndent=newIndent;
1039 TREEVIEW_Create (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1041 TREEVIEW_INFO *infoPtr;
1045 TRACE (treeview,"\n");
1046 /* allocate memory for info structure */
1047 infoPtr = (TREEVIEW_INFO *)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
1048 sizeof(TREEVIEW_INFO));
1050 wndPtr->wExtra[0] = (DWORD)infoPtr;
1052 if (infoPtr == NULL) {
1053 ERR (treeview, "could not allocate info memory!\n");
1057 if ((TREEVIEW_INFO*)wndPtr->wExtra[0] != infoPtr) {
1058 ERR (treeview, "pointer assignment error!\n");
1062 hdc=GetDC32 (wndPtr->hwndSelf);
1064 /* set default settings */
1065 infoPtr->uInternalStatus=0;
1066 infoPtr->uNumItems=0;
1067 infoPtr->clrBk = GetSysColor32 (COLOR_WINDOW);
1068 infoPtr->clrText = GetSysColor32 (COLOR_BTNTEXT);
1071 infoPtr->uIndent = 15;
1072 infoPtr->himlNormal = NULL;
1073 infoPtr->himlState = NULL;
1074 infoPtr->uItemHeight = -1;
1075 GetTextMetrics32A (hdc, &tm);
1076 infoPtr->uRealItemHeight= tm.tmHeight + tm.tmExternalLeading;
1078 infoPtr->items = NULL;
1079 infoPtr->selectedItem=0;
1080 infoPtr->clrText=-1; /* use system color */
1081 infoPtr->dropItem=0;
1084 infoPtr->hwndNotify = GetParent32 (wndPtr->hwndSelf);
1085 infoPtr->bTransparent = (wndPtr->dwStyle & TBSTYLE_FLAT);
1088 if (wndPtr->dwStyle & TBSTYLE_TOOLTIPS) {
1089 /* Create tooltip control */
1090 // infoPtr->hwndToolTip = CreateWindowEx32A (....);
1092 /* Send TV_TOOLTIPSCREATED notification */
1095 ReleaseDC32 (wndPtr->hwndSelf, hdc);
1103 TREEVIEW_Destroy (WND *wndPtr)
1105 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1107 TREEVIEW_RemoveTree (infoPtr);
1108 if (infoPtr->Timer & TV_REFRESH_TIMER_SET)
1109 KillTimer32 (wndPtr->hwndSelf, TV_REFRESH_TIMER);
1111 HeapFree (GetProcessHeap (), 0, infoPtr);
1118 TREEVIEW_Paint (WND *wndPtr, WPARAM32 wParam)
1123 hdc = wParam==0 ? BeginPaint32 (wndPtr->hwndSelf, &ps) : (HDC32)wParam;
1124 TREEVIEW_QueueRefresh (wndPtr);
1126 EndPaint32 (wndPtr->hwndSelf, &ps);
1133 TREEVIEW_EraseBackground (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1135 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1136 HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk);
1139 TRACE (treeview,"\n");
1140 GetClientRect32 (wndPtr->hwndSelf, &rect);
1141 FillRect32 ((HDC32)wParam, &rect, hBrush);
1142 DeleteObject32 (hBrush);
1155 TREEVIEW_SendSimpleNotify (WND *wndPtr, UINT32 code)
1159 TRACE (treeview, "%x\n",code);
1160 nmhdr.hwndFrom = wndPtr->hwndSelf;
1161 nmhdr.idFrom = wndPtr->wIDmenu;
1164 return (BOOL32) SendMessage32A (GetParent32 (wndPtr->hwndSelf), WM_NOTIFY,
1165 (WPARAM32)nmhdr.idFrom, (LPARAM)&nmhdr);
1172 TREEVIEW_SendTreeviewNotify (WND *wndPtr, UINT32 code, UINT32 action,
1173 INT32 oldItem, INT32 newItem, POINT32 pt)
1175 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1177 TREEVIEW_ITEM *wineItem;
1179 TRACE (treeview,"code:%x action:%x olditem:%x newitem:%x\n",
1180 code,action,oldItem,newItem);
1181 nmhdr.hdr.hwndFrom = wndPtr->hwndSelf;
1182 nmhdr.hdr.idFrom = wndPtr->wIDmenu;
1183 nmhdr.hdr.code = code;
1184 nmhdr.action = action;
1186 wineItem=& infoPtr->items[oldItem];
1187 nmhdr.itemOld.mask = wineItem->mask;
1188 nmhdr.itemOld.hItem = wineItem->hItem;
1189 nmhdr.itemOld.state = wineItem->state;
1190 nmhdr.itemOld.stateMask = wineItem->stateMask;
1191 nmhdr.itemOld.iImage = wineItem->iImage;
1192 nmhdr.itemOld.pszText = wineItem->pszText;
1193 nmhdr.itemOld.cchTextMax = wineItem->cchTextMax;
1194 nmhdr.itemOld.iImage = wineItem->iImage;
1195 nmhdr.itemOld.iSelectedImage = wineItem->iSelectedImage;
1196 nmhdr.itemOld.cChildren = wineItem->cChildren;
1197 nmhdr.itemOld.lParam = wineItem->lParam;
1201 wineItem=& infoPtr->items[newItem];
1202 nmhdr.itemNew.mask = wineItem->mask;
1203 nmhdr.itemNew.hItem = wineItem->hItem;
1204 nmhdr.itemNew.state = wineItem->state;
1205 nmhdr.itemNew.stateMask = wineItem->stateMask;
1206 nmhdr.itemNew.iImage = wineItem->iImage;
1207 nmhdr.itemNew.pszText = wineItem->pszText;
1208 nmhdr.itemNew.cchTextMax = wineItem->cchTextMax;
1209 nmhdr.itemNew.iImage = wineItem->iImage;
1210 nmhdr.itemNew.iSelectedImage = wineItem->iSelectedImage;
1211 nmhdr.itemNew.cChildren = wineItem->cChildren;
1212 nmhdr.itemNew.lParam = wineItem->lParam;
1215 nmhdr.ptDrag.x = pt.x;
1216 nmhdr.ptDrag.y = pt.y;
1218 return (BOOL32)SendMessage32A (GetParent32 (wndPtr->hwndSelf), WM_NOTIFY,
1219 (WPARAM32)wndPtr->wIDmenu, (LPARAM)&nmhdr);
1227 TREEVIEW_Expand (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1229 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1230 TREEVIEW_ITEM *wineItem;
1235 flag= (UINT32) wParam;
1236 expandItem= (INT32) lParam;
1237 TRACE (treeview,"flags:%x item:%x\n", expandItem, wParam);
1238 wineItem = TREEVIEW_ValidItem (infoPtr, expandItem);
1239 if (!wineItem) return 0;
1240 if (!wineItem->cChildren) return 0;
1242 if (flag & TVE_TOGGLE) { /* FIXME: check exact behaviour here */
1243 flag &= ~TVE_TOGGLE; /* ie: bitwise ops or 'case' ops */
1244 if (wineItem->state & TVIS_EXPANDED)
1245 flag |= TVE_COLLAPSE;
1251 case TVE_COLLAPSERESET:
1252 if (!wineItem->state & TVIS_EXPANDED) return 0;
1253 wineItem->state &= ~(TVIS_EXPANDEDONCE | TVIS_EXPANDED);
1254 TREEVIEW_RemoveAllChildren (infoPtr, wineItem);
1258 if (!wineItem->state & TVIS_EXPANDED) return 0;
1259 wineItem->state &= ~TVIS_EXPANDED;
1263 if (wineItem->state & TVIS_EXPANDED) return 0;
1264 if (!(wineItem->state & TVIS_EXPANDEDONCE)) {
1265 if (TREEVIEW_SendTreeviewNotify (wndPtr, TVN_ITEMEXPANDING,
1266 0, 0, expandItem, pt))
1267 return FALSE; /* FIXME: OK? */
1268 wineItem->state |= TVIS_EXPANDED | TVIS_EXPANDEDONCE;
1269 TREEVIEW_SendTreeviewNotify (wndPtr, TVN_ITEMEXPANDED,
1270 0, 0, expandItem, pt);
1272 wineItem->state |= TVIS_EXPANDED;
1274 case TVE_EXPANDPARTIAL:
1275 FIXME (treeview, "TVE_EXPANDPARTIAL not implemented\n");
1276 wineItem->state ^=TVIS_EXPANDED;
1277 wineItem->state |=TVIS_EXPANDEDONCE;
1281 TREEVIEW_QueueRefresh (wndPtr);
1289 TREEVIEW_HitTest (WND *wndPtr, LPTVHITTESTINFO lpht)
1291 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1292 TREEVIEW_ITEM *wineItem;
1298 GetClientRect32 (wndPtr->hwndSelf, &rect);
1299 TRACE (treeview,"(%d,%d)\n",lpht->pt.x, lpht->pt.y);
1304 if (x < rect.left) status|=TVHT_TOLEFT;
1305 if (x > rect.right) status|=TVHT_TORIGHT;
1306 if (y < rect.top ) status|=TVHT_ABOVE;
1307 if (y > rect.bottom) status|=TVHT_BELOW;
1313 if (!infoPtr->firstVisible) WARN (treeview,"Can't fetch first visible item");
1314 wineItem=&infoPtr->items [infoPtr->firstVisible];
1316 while ((wineItem!=NULL) && (y > wineItem->rect.bottom))
1317 wineItem=TREEVIEW_GetNextListItem (infoPtr,wineItem);
1319 if (wineItem==NULL) {
1320 lpht->flags=TVHT_NOWHERE;
1324 if (x>wineItem->rect.right) {
1325 lpht->flags|=TVHT_ONITEMRIGHT;
1326 return wineItem->hItem;
1330 if (x<wineItem->rect.left+10) lpht->flags|=TVHT_ONITEMBUTTON;
1332 lpht->flags=TVHT_ONITEMLABEL; /* FIXME: implement other flags */
1335 lpht->hItem=wineItem->hItem;
1336 return wineItem->hItem;
1341 TREEVIEW_HitTest32 (WND *wndPtr, LPARAM lParam)
1344 return (LRESULT) TREEVIEW_HitTest (wndPtr, (LPTVHITTESTINFO) lParam);
1351 TREEVIEW_LButtonDoubleClick (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1353 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1354 TREEVIEW_ITEM *wineItem;
1358 TRACE (treeview,"\n");
1359 ht.pt.x = (INT32)LOWORD(lParam);
1360 ht.pt.y = (INT32)HIWORD(lParam);
1361 SetFocus32 (wndPtr->hwndSelf);
1363 iItem=TREEVIEW_HitTest (wndPtr, &ht);
1364 TRACE (treeview,"item %d \n",iItem);
1365 wineItem=TREEVIEW_ValidItem (infoPtr, iItem);
1366 if (!wineItem) return 0;
1368 if (TREEVIEW_SendSimpleNotify (wndPtr, NM_DBLCLK)!=TRUE) { /* FIXME!*/
1369 wineItem->state &= ~TVIS_EXPANDEDONCE;
1370 TREEVIEW_Expand (wndPtr, (WPARAM32) TVE_TOGGLE, (LPARAM) iItem);
1378 TREEVIEW_LButtonDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1383 TRACE (treeview,"\n");
1384 ht.pt.x = (INT32)LOWORD(lParam);
1385 ht.pt.y = (INT32)HIWORD(lParam);
1387 SetFocus32 (wndPtr->hwndSelf);
1388 iItem=TREEVIEW_HitTest (wndPtr, &ht);
1389 TRACE (treeview,"item %d \n",iItem);
1390 if (ht.flags & TVHT_ONITEMBUTTON) {
1391 TREEVIEW_Expand (wndPtr, (WPARAM32) TVE_TOGGLE, (LPARAM) iItem);
1394 if (TREEVIEW_SelectItem (wndPtr, (WPARAM32) TVGN_CARET, (LPARAM) iItem))
1403 TREEVIEW_RButtonDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1412 /* FIXME: If the specified item is the child of a collapsed parent item,
1413 expand parent's list of child items to reveal the specified item.
1417 TREEVIEW_SelectItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1419 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1420 TREEVIEW_ITEM *prevItem,*wineItem;
1421 INT32 action,prevSelect, newSelect;
1424 TRACE (treeview,"item %lx, flag %x\n", lParam, wParam);
1425 newSelect= (INT32) lParam;
1426 wineItem = TREEVIEW_ValidItem (infoPtr, newSelect);
1427 if (!wineItem) return FALSE;
1428 prevSelect=infoPtr->selectedItem;
1429 prevItem= TREEVIEW_ValidItem (infoPtr, prevSelect);
1433 action= (INT32) wParam;
1437 if (TREEVIEW_SendTreeviewNotify (wndPtr, TVN_SELCHANGING, TVC_BYMOUSE,
1438 prevSelect, newSelect,dummy))
1439 return FALSE; /* FIXME: OK? */
1441 if (prevItem) prevItem->state &= ~TVIS_SELECTED;
1442 infoPtr->selectedItem=newSelect;
1443 wineItem->state |=TVIS_SELECTED;
1444 TREEVIEW_SendTreeviewNotify (wndPtr, TVN_SELCHANGED,
1445 TVC_BYMOUSE, prevSelect, newSelect, dummy);
1447 case TVGN_DROPHILITE:
1448 FIXME (treeview, "DROPHILITE not implemented");
1450 case TVGN_FIRSTVISIBLE:
1451 FIXME (treeview, "FIRSTVISIBLE not implemented");
1455 TREEVIEW_QueueRefresh (wndPtr);
1462 /* FIXME: does KEYDOWN also send notifications?? If so, use
1463 TREEVIEW_SelectItem.
1468 TREEVIEW_KeyDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1470 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1471 TREEVIEW_ITEM *prevItem,*newItem;
1475 TRACE (treeview,"%x %lx\n",wParam, lParam);
1476 prevSelect=infoPtr->selectedItem;
1477 if (!prevSelect) return FALSE;
1479 prevItem= TREEVIEW_ValidItem (infoPtr, prevSelect);
1484 newItem=TREEVIEW_GetPrevListItem (infoPtr, prevItem);
1486 newItem=& infoPtr->items[infoPtr->TopRootItem];
1489 newItem=TREEVIEW_GetNextListItem (infoPtr, prevItem);
1490 if (!newItem) newItem=prevItem;
1493 newItem=& infoPtr->items[infoPtr->TopRootItem];
1496 newItem=TREEVIEW_GetLastListItem (infoPtr);
1502 FIXME (treeview, "%x not implemented\n", wParam);
1506 if (!newItem) return FALSE;
1508 if (prevItem!=newItem) {
1509 prevItem->state &= ~TVIS_SELECTED;
1510 newItem->state |= TVIS_SELECTED;
1511 infoPtr->selectedItem=newItem->hItem;
1512 TREEVIEW_QueueRefresh (wndPtr);
1522 TREEVIEW_VScroll (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1525 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1528 TRACE (treeview,"wp %x, lp %lx\n", wParam, lParam);
1529 if (!infoPtr->uInternalStatus & TV_VSCROLL) return FALSE;
1531 switch (LOWORD (wParam)) {
1533 if (!infoPtr->cy) return FALSE;
1534 infoPtr->cy -= infoPtr->uRealItemHeight;
1535 if (infoPtr->cy < 0) infoPtr->cy=0;
1538 maxHeight=infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
1539 if (infoPtr->cy == maxHeight) return FALSE;
1540 infoPtr->cy += infoPtr->uRealItemHeight;
1541 if (infoPtr->cy > maxHeight)
1542 infoPtr->cy = maxHeight;
1545 if (!infoPtr->cy) return FALSE;
1546 infoPtr->cy -= infoPtr->uVisibleHeight;
1547 if (infoPtr->cy < 0) infoPtr->cy=0;
1550 maxHeight=infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
1551 if (infoPtr->cy == maxHeight) return FALSE;
1552 infoPtr->cy += infoPtr->uVisibleHeight;
1553 if (infoPtr->cy > maxHeight)
1554 infoPtr->cy = maxHeight;
1557 infoPtr->cy = HIWORD (wParam);
1562 TREEVIEW_QueueRefresh (wndPtr);
1567 TREEVIEW_HScroll (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1569 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1571 TRACE (treeview,"wp %lx, lp %x\n", lParam, wParam);
1573 if (!infoPtr->uInternalStatus & TV_HSCROLL) return FALSE;
1581 TREEVIEW_WindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
1583 WND *wndPtr = WIN_FindWndPtr(hwnd);
1587 case TVM_INSERTITEM32A:
1588 return TREEVIEW_InsertItem32A (wndPtr, wParam, lParam);
1590 case TVM_INSERTITEM32W:
1591 FIXME (treeview, "Unimplemented msg TVM_INSERTITEM32W\n");
1594 case TVM_DELETEITEM:
1595 return TREEVIEW_DeleteItem (wndPtr, wParam, lParam);
1598 return TREEVIEW_Expand (wndPtr, wParam, lParam);
1600 case TVM_GETITEMRECT:
1601 return TREEVIEW_GetItemRect (wndPtr, wParam, lParam);
1604 return TREEVIEW_GetCount (wndPtr, wParam, lParam);
1607 return TREEVIEW_GetIndent (wndPtr, wParam, lParam);
1610 return TREEVIEW_SetIndent (wndPtr, wParam, lParam);
1612 case TVM_GETIMAGELIST:
1613 return TREEVIEW_GetImageList (wndPtr, wParam, lParam);
1615 case TVM_SETIMAGELIST:
1616 return TREEVIEW_SetImageList (wndPtr, wParam, lParam);
1618 case TVM_GETNEXTITEM:
1619 return TREEVIEW_GetNextItem32 (wndPtr, wParam, lParam);
1621 case TVM_SELECTITEM:
1622 return TREEVIEW_SelectItem (wndPtr, wParam, lParam);
1624 case TVM_GETITEM32A:
1625 return TREEVIEW_GetItem (wndPtr, wParam, lParam);
1627 case TVM_GETITEM32W:
1628 FIXME (treeview, "Unimplemented msg TVM_GETITEM32W\n");
1631 case TVM_SETITEM32A:
1632 return TREEVIEW_SetItem (wndPtr, wParam, lParam);
1634 case TVM_SETITEM32W:
1635 FIXME (treeview, "Unimplemented msg TVM_SETITEMW\n");
1638 case TVM_EDITLABEL32A:
1639 FIXME (treeview, "Unimplemented msg TVM_EDITLABEL32A \n");
1642 case TVM_EDITLABEL32W:
1643 FIXME (treeview, "Unimplemented msg TVM_EDITLABEL32W \n");
1646 case TVM_GETEDITCONTROL:
1647 FIXME (treeview, "Unimplemented msg TVM_GETEDITCONTROL\n");
1650 case TVM_GETVISIBLECOUNT:
1651 return TREEVIEW_GetVisibleCount (wndPtr, wParam, lParam);
1654 return TREEVIEW_HitTest32 (wndPtr, lParam);
1656 case TVM_CREATEDRAGIMAGE:
1657 FIXME (treeview, "Unimplemented msg TVM_CREATEDRAGIMAGE\n");
1660 case TVM_SORTCHILDREN:
1661 FIXME (treeview, "Unimplemented msg TVM_SORTCHILDREN\n");
1664 case TVM_ENSUREVISIBLE:
1665 FIXME (treeview, "Unimplemented msg TVM_ENSUREVISIBLE\n");
1668 case TVM_SORTCHILDRENCB:
1669 FIXME (treeview, "Unimplemented msg TVM_SORTCHILDRENCB\n");
1672 case TVM_ENDEDITLABELNOW:
1673 FIXME (treeview, "Unimplemented msg TVM_ENDEDITLABELNOW\n");
1676 case TVM_GETISEARCHSTRING32A:
1677 FIXME (treeview, "Unimplemented msg TVM_GETISEARCHSTRING32A\n");
1680 case TVM_GETISEARCHSTRING32W:
1681 FIXME (treeview, "Unimplemented msg TVM_GETISEARCHSTRING32W\n");
1684 case TVM_SETTOOLTIPS:
1685 FIXME (treeview, "Unimplemented msg TVM_SETTOOLTIPS\n");
1688 case TVM_GETTOOLTIPS:
1689 FIXME (treeview, "Unimplemented msg TVM_GETTOOLTIPS\n");
1692 case TVM_SETINSERTMARK:
1693 FIXME (treeview, "Unimplemented msg TVM_SETINSERTMARK\n");
1696 case TVM_SETITEMHEIGHT:
1697 return TREEVIEW_SetItemHeight (wndPtr, wParam);
1699 case TVM_GETITEMHEIGHT:
1700 return TREEVIEW_GetItemHeight (wndPtr);
1702 case TVM_SETBKCOLOR:
1703 FIXME (treeview, "Unimplemented msg TVM_SETBKCOLOR\n");
1706 case TVM_SETTEXTCOLOR:
1707 return TREEVIEW_SetTextColor (wndPtr, wParam, lParam);
1709 case TVM_GETBKCOLOR:
1710 FIXME (treeview, "Unimplemented msg TVM_GETBKCOLOR\n");
1713 case TVM_GETTEXTCOLOR:
1714 return TREEVIEW_GetTextColor (wndPtr);
1716 case TVM_SETSCROLLTIME:
1717 FIXME (treeview, "Unimplemented msg TVM_SETSCROLLTIME\n");
1720 case TVM_GETSCROLLTIME:
1721 FIXME (treeview, "Unimplemented msg TVM_GETSCROLLTIME\n");
1724 case TVM_SETINSERTMARKCOLOR:
1725 FIXME (treeview, "Unimplemented msg TVM_SETINSERTMARKCOLOR\n");
1728 case TVM_SETUNICODEFORMAT:
1729 FIXME (treeview, "Unimplemented msg TVM_SETUNICODEFORMAT\n");
1732 case TVM_GETUNICODEFORMAT:
1733 FIXME (treeview, "Unimplemented msg TVM_GETUNICODEFORMAT\n");
1739 return TREEVIEW_Create (wndPtr, wParam, lParam);
1742 return TREEVIEW_Destroy (wndPtr);
1747 return TREEVIEW_EraseBackground (wndPtr, wParam, lParam);
1750 return DLGC_WANTARROWS | DLGC_WANTCHARS;
1753 return TREEVIEW_Paint (wndPtr, wParam);
1759 return TREEVIEW_KeyDown (wndPtr, wParam, lParam);
1762 // case WM_KILLFOCUS:
1763 // case WM_SETFOCUS:
1766 case WM_LBUTTONDOWN:
1767 return TREEVIEW_LButtonDown (wndPtr, wParam, lParam);
1769 case WM_LBUTTONDBLCLK:
1770 return TREEVIEW_LButtonDoubleClick (wndPtr, wParam, lParam);
1772 case WM_RBUTTONDOWN:
1773 return TREEVIEW_RButtonDown (wndPtr, wParam, lParam);
1776 // case WM_SYSCOLORCHANGE:
1777 // case WM_STYLECHANGED:
1778 // case WM_SETREDRAW:
1781 return TREEVIEW_HandleTimer (wndPtr, wParam, lParam);
1785 return TREEVIEW_HScroll (wndPtr, wParam, lParam);
1787 return TREEVIEW_VScroll (wndPtr, wParam, lParam);
1790 if (uMsg >= WM_USER)
1791 FIXME (treeview, "Unknown msg %04x wp=%08x lp=%08lx\n",
1792 uMsg, wParam, lParam);
1793 return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
1800 TREEVIEW_Register (VOID)
1802 WNDCLASS32A wndClass;
1804 TRACE (treeview,"\n");
1806 if (GlobalFindAtom32A (WC_TREEVIEW32A)) return;
1808 ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
1809 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1810 wndClass.lpfnWndProc = (WNDPROC32)TREEVIEW_WindowProc;
1811 wndClass.cbClsExtra = 0;
1812 wndClass.cbWndExtra = sizeof(TREEVIEW_INFO *);
1813 wndClass.hCursor = LoadCursor32A (0, IDC_ARROW32A);
1814 wndClass.hbrBackground = 0;
1815 wndClass.lpszClassName = WC_TREEVIEW32A;
1817 RegisterClass32A (&wndClass);
1822 TREEVIEW_Unregister (VOID)
1824 if (GlobalFindAtom32A (WC_TREEVIEW32A))
1825 UnregisterClass32A (WC_TREEVIEW32A, (HINSTANCE32)NULL);