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).
34 #include <asm/bitops.h> /* FIXME: linux specific */
36 static int TREEVIEW_Timer;
40 #define TREEVIEW_GetInfoPtr(wndPtr) ((TREEVIEW_INFO *)wndPtr->wExtra[0])
44 #include <asm/bitops.h> /* FIXME: linux specific */
46 static int TREEVIEW_Timer;
49 #define TREEVIEW_GetInfoPtr(wndPtr) ((TREEVIEW_INFO *)wndPtr->wExtra[0])
55 TREEVIEW_SendSimpleNotify (WND *wndPtr, UINT32 code);
57 TREEVIEW_SendTreeviewNotify (WND *wndPtr, UINT32 code, UINT32 action,
58 INT32 oldItem, INT32 newItem, POINT32 pt);
60 TREEVIEW_SelectItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam);
62 TREEVIEW_Refresh (WND *wndPtr, HDC32 hdc);
68 /* helper functions. Work with the assumption that validity of operands
69 is checked beforehand */
72 static TREEVIEW_ITEM *
73 TREEVIEW_ValidItem (TREEVIEW_INFO *infoPtr,int handle)
76 if ((!handle) || (handle>infoPtr->uMaxHandle)) return NULL;
77 if (test_bit (handle, infoPtr->freeList)) return NULL;
79 return & infoPtr->items[handle];
84 static TREEVIEW_ITEM *TREEVIEW_GetPrevListItem (TREEVIEW_INFO *infoPtr,
85 TREEVIEW_ITEM *tvItem)
88 TREEVIEW_ITEM *wineItem;
90 if (tvItem->upsibling)
91 return (& infoPtr->items[tvItem->upsibling]);
94 while (wineItem->parent) {
95 wineItem=& infoPtr->items[wineItem->parent];
96 if (wineItem->upsibling)
97 return (& infoPtr->items[wineItem->upsibling]);
103 static TREEVIEW_ITEM *TREEVIEW_GetNextListItem (TREEVIEW_INFO *infoPtr,
104 TREEVIEW_ITEM *tvItem)
107 TREEVIEW_ITEM *wineItem;
110 return (& infoPtr->items[tvItem->sibling]);
113 while (wineItem->parent) {
114 wineItem=& infoPtr->items [wineItem->parent];
115 if (wineItem->sibling)
116 return (& infoPtr->items [wineItem->sibling]);
122 static TREEVIEW_ITEM *TREEVIEW_GetLastListItem (TREEVIEW_INFO *infoPtr)
125 TREEVIEW_ITEM *wineItem;
128 if (infoPtr->TopRootItem)
129 wineItem=& infoPtr->items [infoPtr->TopRootItem];
130 while (wineItem->sibling)
131 wineItem=& infoPtr->items [wineItem->sibling];
140 TREEVIEW_RemoveItem (TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *wineItem)
143 TREEVIEW_ITEM *parentItem, *upsiblingItem, *siblingItem;
146 iItem=wineItem->hItem;
147 set_bit ( iItem & 31, &infoPtr->freeList[iItem >>5]);
148 infoPtr->uNumItems--;
150 if (wineItem->pszText!=LPSTR_TEXTCALLBACK32A)
151 HeapFree (GetProcessHeap (), 0, wineItem->pszText);
153 if (wineItem->parent) {
154 parentItem=& infoPtr->items[ wineItem->parent];
155 if (parentItem->cChildren==1) {
156 parentItem->cChildren=0;
157 parentItem->firstChild=0;
160 parentItem->cChildren--;
161 if (parentItem->firstChild==iItem)
162 parentItem->firstChild=wineItem->sibling;
166 if (iItem==infoPtr->TopRootItem)
167 infoPtr->TopRootItem=wineItem->sibling;
168 if (wineItem->upsibling) {
169 upsiblingItem=& infoPtr->items [wineItem->upsibling];
170 upsiblingItem->sibling=wineItem->sibling;
172 if (wineItem->sibling) {
173 siblingItem=& infoPtr->items [wineItem->sibling];
174 siblingItem->upsibling=wineItem->upsibling;
180 static void TREEVIEW_RemoveAllChildren (TREEVIEW_INFO *infoPtr,
181 TREEVIEW_ITEM *parentItem)
184 TREEVIEW_ITEM *killItem;
187 kill=parentItem->firstChild;
189 set_bit ( kill & 31, &infoPtr->freeList[kill >>5]);
190 killItem=& infoPtr->items[kill];
191 if (killItem->pszText!=LPSTR_TEXTCALLBACK32A)
192 HeapFree (GetProcessHeap (), 0, killItem->pszText);
193 kill=killItem->sibling;
195 infoPtr->uNumItems -= parentItem->cChildren;
196 parentItem->firstChild = 0;
197 parentItem->cChildren = 0;
202 static void TREEVIEW_RemoveTree (TREEVIEW_INFO *infoPtr)
206 TREEVIEW_ITEM *killItem;
209 /* bummer: if we didn't delete anything, test_bit is overhead */
211 for (i=1; i<=infoPtr->uMaxHandle; i++)
212 if (!test_bit (i, infoPtr->freeList)) {
213 killItem=& infoPtr->items [i];
214 if (killItem->pszText!=LPSTR_TEXTCALLBACK32A)
215 HeapFree (GetProcessHeap (), 0, killItem->pszText);
218 if (infoPtr->uNumPtrsAlloced) {
219 HeapFree (GetProcessHeap (), 0, infoPtr->items);
220 HeapFree (GetProcessHeap (), 0, infoPtr->freeList);
221 infoPtr->uNumItems=0;
222 infoPtr->uNumPtrsAlloced=0;
223 infoPtr->uMaxHandle=0;
226 /* this function doesn't remove infoPtr itself */
239 TREEVIEW_GetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
241 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
243 TRACE (treeview,"\n");
245 if (infoPtr==NULL) return 0;
247 if ((INT32)wParam == TVSIL_NORMAL)
248 return (LRESULT) infoPtr->himlNormal;
249 if ((INT32)wParam == TVSIL_STATE)
250 return (LRESULT) infoPtr->himlState;
259 TREEVIEW_SetImageList (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
261 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
264 switch ((INT32)wParam) {
266 himlTemp = infoPtr->himlNormal;
267 infoPtr->himlNormal = (HIMAGELIST)lParam;
268 return (LRESULT)himlTemp;
271 himlTemp = infoPtr->himlState;
272 infoPtr->himlState = (HIMAGELIST)lParam;
273 return (LRESULT)himlTemp;
276 return (LRESULT)NULL;
282 TREEVIEW_SetItemHeight (WND *wndPtr, WPARAM32 wParam)
284 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
285 INT32 prevHeight=infoPtr->uItemHeight;
291 hdc=GetDC32 (wndPtr->hwndSelf);
292 infoPtr->uItemHeight=-1;
293 GetTextMetrics32A (hdc, &tm);
294 infoPtr->uRealItemHeight= tm.tmHeight + tm.tmExternalLeading;
295 ReleaseDC32 (wndPtr->hwndSelf, hdc);
299 /* FIXME: check wParam > imagelist height */
301 if (!(wndPtr->dwStyle & TVS_NONEVENHEIGHT))
302 infoPtr->uItemHeight = (INT32) wParam & 0xfffffffe;
307 TREEVIEW_GetItemHeight (WND *wndPtr)
309 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
311 return infoPtr->uItemHeight;
315 TREEVIEW_SetTextColor (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
317 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
318 COLORREF prevColor=infoPtr->clrText;
320 infoPtr->clrText=(COLORREF) lParam;
321 return (LRESULT) prevColor;
325 TREEVIEW_GetTextColor (WND *wndPtr)
327 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
329 return (LRESULT) infoPtr->clrText;
334 TREEVIEW_DrawItem (WND *wndPtr, HDC32 hdc, TREEVIEW_ITEM *wineItem,
335 TREEVIEW_ITEM *upperItem, int indent)
337 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
338 INT32 oldBkMode,center,xpos;
340 UINT32 uTextJustify = DT_LEFT;
341 HPEN32 hOldPen, hnewPen,hRootPen;
344 hnewPen = CreatePen32(PS_DOT, 0, GetSysColor32(COLOR_WINDOWTEXT) );
345 hOldPen = SelectObject32( hdc, hnewPen );
349 upper=upperItem->rect;
354 center=(r.top+r.bottom)/2;
357 if (wndPtr->dwStyle & TVS_HASLINES) {
359 if ((wndPtr->dwStyle & TVS_LINESATROOT) && (indent==0)) {
360 points[0].y=points[1].y=center;
361 points[2].y=upper.top;
362 points[1].x=points[2].x=upper.left;
363 points[0].x=upper.left+12;
366 Polyline32 (hdc,points,3);
369 points[0].y=points[1].y=center;
370 points[2].y=upper.top;
371 points[1].x=points[2].x=upper.left+13;
372 points[0].x=upper.left+25;
374 Polyline32 (hdc,points,3);
378 DeleteObject32(hnewPen);
379 SelectObject32(hdc, hOldPen);
381 if ((wndPtr->dwStyle & TVS_HASBUTTONS) && (wineItem->cChildren)) {
383 hRootPen = CreatePen32(PS_SOLID, 0, GetSysColor32(COLOR_WINDOW) );
384 SelectObject32( hdc, hRootPen );
387 Rectangle32 (hdc, xpos-4, center-4, xpos+5, center+5);
388 MoveToEx32 (hdc, xpos-2, center, NULL);
389 LineTo32 (hdc, xpos+3, center);
390 if (!(wineItem->state & TVIS_EXPANDED)) {
391 MoveToEx32 (hdc, xpos, center-2, NULL);
392 LineTo32 (hdc, xpos, center+3);
394 /* DeleteObject32(hRootPen); */
400 if (wineItem->mask & TVIF_IMAGE) {
401 if (wineItem->iImage!=I_IMAGECALLBACK) {
402 if (infoPtr->himlNormal) {
403 ImageList_Draw (infoPtr->himlNormal,wineItem->iImage, hdc,
404 xpos-2, r.top+1, ILD_NORMAL);
411 if ((wineItem->mask & TVIF_TEXT) && (wineItem->pszText)) {
412 if (wineItem->state & TVIS_SELECTED) {
413 oldBkMode = SetBkMode32(hdc, OPAQUE);
414 oldBkColor= SetBkColor32 (hdc, GetSysColor32( COLOR_HIGHLIGHT));
415 SetTextColor32 (hdc, GetSysColor32(COLOR_HIGHLIGHTTEXT));
418 oldBkMode = SetBkMode32(hdc, TRANSPARENT);
422 if (infoPtr->clrText==-1)
423 SetTextColor32 (hdc, COLOR_BTNTEXT);
425 SetTextColor32 (hdc, infoPtr->clrText); /* FIXME: retval */
426 DrawText32A(hdc, wineItem->pszText, lstrlen32A(wineItem->pszText),
427 &r, uTextJustify|DT_VCENTER|DT_SINGLELINE);
428 if (oldBkMode != TRANSPARENT)
429 SetBkMode32(hdc, oldBkMode);
430 if (wineItem->state & TVIS_SELECTED)
431 SetBkColor32 (hdc, oldBkColor);
434 return wineItem->rect.right;
444 TREEVIEW_GetItemRect (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
446 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
447 TREEVIEW_ITEM *wineItem;
451 TRACE (treeview,"\n");
452 if (infoPtr==NULL) return FALSE;
454 iItem = (INT32)lParam;
455 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
456 if (!wineItem) return FALSE;
458 wineItem=& infoPtr->items[ iItem ];
459 if (!wineItem->visible) return FALSE;
461 lpRect = (LPRECT32)lParam;
462 if (lpRect == NULL) return FALSE;
464 if ((INT32) wParam) {
465 lpRect->left = wineItem->text.left;
466 lpRect->right = wineItem->text.right;
467 lpRect->bottom = wineItem->text.bottom;
468 lpRect->top = wineItem->text.top;
470 lpRect->left = wineItem->rect.left;
471 lpRect->right = wineItem->rect.right;
472 lpRect->bottom = wineItem->rect.bottom;
473 lpRect->top = wineItem->rect.top;
482 TREEVIEW_GetVisibleCount (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
485 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
487 TRACE (treeview,"\n");
489 return (LRESULT) infoPtr->uVisibleHeight / infoPtr->uRealItemHeight;
495 TREEVIEW_SetItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
497 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
498 TREEVIEW_ITEM *wineItem;
502 TRACE (treeview,"\n");
503 tvItem=(LPTVITEM) lParam;
506 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
507 if (!wineItem) return FALSE;
509 if (tvItem->mask & TVIF_CHILDREN) {
510 wineItem->cChildren=tvItem->cChildren;
513 if (tvItem->mask & TVIF_IMAGE) {
514 wineItem->iImage=tvItem->iImage;
517 if (tvItem->mask & TVIF_INTEGRAL) {
518 /* wineItem->iIntegral=tvItem->iIntegral; */
521 if (tvItem->mask & TVIF_PARAM) {
522 wineItem->lParam=tvItem->lParam;
525 if (tvItem->mask & TVIF_SELECTEDIMAGE) {
526 wineItem->iSelectedImage=tvItem->iSelectedImage;
529 if (tvItem->mask & TVIF_STATE) {
530 wineItem->state=tvItem->state & tvItem->stateMask;
533 if (tvItem->mask & TVIF_TEXT) {
534 len=tvItem->cchTextMax;
535 if (len>wineItem->cchTextMax) {
536 HeapFree (GetProcessHeap (), 0, wineItem->pszText);
537 wineItem->pszText= HeapAlloc (GetProcessHeap (),
538 HEAP_ZERO_MEMORY, len+1);
540 lstrcpyn32A (wineItem->pszText, tvItem->pszText,len);
551 TREEVIEW_Refresh (WND *wndPtr, HDC32 hdc)
554 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
555 HFONT32 hFont, hOldFont;
558 INT32 iItem, indent, x, y, height;
559 INT32 viewtop,viewbottom,viewleft,viewright;
560 TREEVIEW_ITEM *wineItem, *prevItem;
562 TRACE (treeview,"\n");
564 if (TREEVIEW_Timer & TV_REFRESH_TIMER_SET) {
565 KillTimer32 (wndPtr->hwndSelf, TV_REFRESH_TIMER);
566 TREEVIEW_Timer &= ~TV_REFRESH_TIMER_SET;
570 GetClientRect32 (wndPtr->hwndSelf, &rect);
571 if ((rect.left-rect.right ==0) || (rect.top-rect.bottom==0)) return;
573 viewbottom=infoPtr->cy + rect.bottom-rect.top;
574 viewleft=infoPtr->cx;
575 viewright=infoPtr->cx + rect.right-rect.left;
577 infoPtr->uVisibleHeight=viewbottom - viewtop;
579 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject32 (DEFAULT_GUI_FONT);
580 hOldFont = SelectObject32 (hdc, hFont);
582 /* draw background */
583 hbrBk = GetSysColorBrush32(COLOR_WINDOW);
584 FillRect32(hdc, &rect, hbrBk);
587 iItem=infoPtr->TopRootItem;
588 infoPtr->firstVisible=0;
592 TRACE (treeview, "[%d %d %d %d]\n",viewtop,viewbottom,viewleft,viewright);
596 wineItem= & infoPtr->items[iItem];
598 TRACE (treeview, "%d %d [%d %d %d %d] (%s)\n",y,x,
599 wineItem->rect.top, wineItem->rect.bottom,
600 wineItem->rect.left, wineItem->rect.right,
603 height=infoPtr->uRealItemHeight * wineItem->iIntegral;
604 if ((y >= viewtop) && (y <= viewbottom) &&
605 (x >= viewleft ) && (x <= viewright)) {
606 wineItem->rect.top = y - infoPtr->cy + rect.top;
607 wineItem->rect.bottom = wineItem->rect.top + height ;
608 wineItem->rect.left = x - infoPtr->cx + rect.left;
609 wineItem->rect.right = rect.right;
610 if (!infoPtr->firstVisible)
611 infoPtr->firstVisible=wineItem->hItem;
612 TREEVIEW_DrawItem (wndPtr, hdc, wineItem, prevItem, indent);
615 wineItem->rect.top = wineItem->rect.bottom = -1;
616 wineItem->rect.left = wineItem->rect.right = -1;
619 /* look up next item */
621 if ((wineItem->firstChild) && (wineItem->state & TVIS_EXPANDED)) {
622 iItem=wineItem->firstChild;
627 iItem=wineItem->sibling;
628 while ((!iItem) && (indent>0)) {
632 wineItem=&infoPtr->items[wineItem->parent];
633 iItem=wineItem->sibling;
639 infoPtr->uTotalHeight=y;
640 if (y >= (viewbottom-viewtop)) {
641 if (!(infoPtr->uInternalStatus & TV_VSCROLL))
642 ShowScrollBar32 (wndPtr->hwndSelf, SB_VERT, TRUE);
643 infoPtr->uInternalStatus |=TV_VSCROLL;
644 SetScrollRange32 (wndPtr->hwndSelf, SB_VERT, 0,
645 y - infoPtr->uVisibleHeight, FALSE);
646 SetScrollPos32 (wndPtr->hwndSelf, SB_VERT, infoPtr->cy, TRUE);
649 if (infoPtr->uInternalStatus & TV_VSCROLL)
650 ShowScrollBar32 (wndPtr->hwndSelf, SB_VERT, FALSE);
651 infoPtr->uInternalStatus &= ~TV_VSCROLL;
655 SelectObject32 (hdc, hOldFont);
660 TREEVIEW_HandleTimer ( WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
662 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
665 if (!infoPtr) return FALSE;
667 TRACE (treeview, "timer\n");
670 case TV_REFRESH_TIMER:
671 KillTimer32 (wndPtr->hwndSelf, TV_REFRESH_TIMER);
672 TREEVIEW_Timer &= ~TV_REFRESH_TIMER_SET;
673 hdc=GetDC32 (wndPtr->hwndSelf);
674 TREEVIEW_Refresh (wndPtr, hdc);
675 ReleaseDC32 (wndPtr->hwndSelf, hdc);
678 KillTimer32 (wndPtr->hwndSelf, TV_EDIT_TIMER);
679 TREEVIEW_Timer &= ~TV_EDIT_TIMER_SET;
688 TREEVIEW_QueueRefresh (WND *wndPtr)
692 TRACE (treeview,"queued\n");
693 if (TREEVIEW_Timer & TV_REFRESH_TIMER_SET) {
694 KillTimer32 (wndPtr->hwndSelf, TV_REFRESH_TIMER);
697 SetTimer32 (wndPtr->hwndSelf, TV_REFRESH_TIMER, TV_REFRESH_DELAY, 0);
698 TREEVIEW_Timer|=TV_REFRESH_TIMER_SET;
704 TREEVIEW_GetItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
706 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
708 TREEVIEW_ITEM *wineItem;
711 TRACE (treeview,"\n");
712 tvItem=(LPTVITEM) lParam;
715 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
716 if (!wineItem) return FALSE;
719 if (tvItem->mask & TVIF_CHILDREN) {
720 tvItem->cChildren=wineItem->cChildren;
723 if (tvItem->mask & TVIF_HANDLE) {
724 tvItem->hItem=wineItem->hItem;
727 if (tvItem->mask & TVIF_IMAGE) {
728 tvItem->iImage=wineItem->iImage;
731 if (tvItem->mask & TVIF_INTEGRAL) {
732 /* tvItem->iIntegral=wineItem->iIntegral; */
735 if (tvItem->mask & TVIF_PARAM) {
736 tvItem->lParam=wineItem->lParam;
739 if (tvItem->mask & TVIF_SELECTEDIMAGE) {
740 tvItem->iSelectedImage=wineItem->iSelectedImage;
743 if (tvItem->mask & TVIF_STATE) {
744 tvItem->state=wineItem->state & tvItem->stateMask;
747 if (tvItem->mask & TVIF_TEXT) {
748 len=wineItem->cchTextMax;
749 if (wineItem->cchTextMax>tvItem->cchTextMax)
750 len=tvItem->cchTextMax-1;
751 lstrcpyn32A (tvItem->pszText, tvItem->pszText,len);
760 TREEVIEW_GetNextItem32 (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
763 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
764 TREEVIEW_ITEM *wineItem;
768 TRACE (treeview,"item:%lu, flags:%x\n", lParam, wParam);
769 if (!infoPtr) return FALSE;
771 flag= (INT32) wParam;
773 case TVGN_ROOT: return (LRESULT) infoPtr->TopRootItem;
774 case TVGN_CARET: return (LRESULT) infoPtr->selectedItem;
775 case TVGN_FIRSTVISIBLE: return (LRESULT) infoPtr->firstVisible;
776 case TVGN_DROPHILITE: return (LRESULT) infoPtr->dropItem;
779 iItem= (INT32) lParam;
780 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
781 if (!wineItem) return FALSE;
784 case TVGN_NEXT: return (LRESULT) wineItem->sibling;
785 case TVGN_PREVIOUS: return (LRESULT) wineItem->upsibling;
786 case TVGN_PARENT: return (LRESULT) wineItem->parent;
787 case TVGN_CHILD: return (LRESULT) wineItem->firstChild;
788 case TVGN_LASTVISIBLE: FIXME (treeview,"TVGN_LASTVISIBLE not implemented\n");
790 case TVGN_NEXTVISIBLE: wineItem=TREEVIEW_GetNextListItem
793 return (LRESULT) wineItem->hItem;
796 case TVGN_PREVIOUSVISIBLE: wineItem=TREEVIEW_GetPrevListItem
799 return (LRESULT) wineItem->hItem;
802 default: FIXME (treeview,"Unknown msg %x,item %x\n", flag,iItem);
810 TREEVIEW_GetCount (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
812 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
814 return (LRESULT) infoPtr->uNumItems;
820 /* the method used below isn't the most memory-friendly, but it avoids
821 a lot of memory reallocations */
823 /* BTW: we waste handle 0; 0 is not an allowed handle. Fix this by
824 decreasing infoptr->items with 1, and increasing it by 1 if
825 it is referenced in mm-handling stuff? */
828 TREEVIEW_InsertItem32A (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
831 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
832 TVINSERTSTRUCT *ptdi;
834 TREEVIEW_ITEM *wineItem, *parentItem, *prevsib, *sibItem;
835 INT32 iItem,listItems,i,len;
837 TRACE (treeview,"\n");
838 ptdi = (TVINSERTSTRUCT *) lParam;
840 /* check if memory is available */
842 if (infoPtr->uNumPtrsAlloced==0) {
843 infoPtr->items = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
844 TVITEM_ALLOC*sizeof (TREEVIEW_ITEM));
845 infoPtr->freeList= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
846 (1+(TVITEM_ALLOC>>5)) *sizeof (INT32));
847 infoPtr->uNumPtrsAlloced=TVITEM_ALLOC;
848 infoPtr->TopRootItem=1;
851 if (infoPtr->uNumItems == (infoPtr->uNumPtrsAlloced-1) ) {
852 TREEVIEW_ITEM *oldItems = infoPtr->items;
853 INT32 *oldfreeList = infoPtr->freeList;
855 infoPtr->uNumPtrsAlloced*=2;
856 infoPtr->items = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
857 infoPtr->uNumPtrsAlloced*sizeof (TREEVIEW_ITEM));
858 infoPtr->freeList= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
859 (1+(infoPtr->uNumPtrsAlloced>>5))*sizeof (INT32));
861 memcpy (&infoPtr->items[0], &oldItems[0],
862 infoPtr->uNumPtrsAlloced/2 * sizeof(TREEVIEW_ITEM));
863 memcpy (&infoPtr->freeList[0], &oldfreeList[0],
864 infoPtr->uNumPtrsAlloced>>6 * sizeof(INT32));
866 HeapFree (GetProcessHeap (), 0, oldItems);
867 HeapFree (GetProcessHeap (), 0, oldfreeList);
871 infoPtr->uNumItems++;
873 if (infoPtr->uMaxHandle==(infoPtr->uNumItems-1)) {
874 iItem=infoPtr->uNumItems;
875 infoPtr->uMaxHandle++;
877 else { /* check freelist */
878 for (i=0; i<infoPtr->uNumPtrsAlloced>>5; i++) {
879 if (infoPtr->freeList[i]) {
880 iItem=ffs (infoPtr->freeList[i]);
881 clear_bit (iItem & 31, & infoPtr->freeList[i]);
886 if (!iItem) ERR (treeview, "Argh -- can't find free item.\n");
888 tvItem= & ptdi->item;
889 wineItem=& infoPtr->items[iItem];
893 if ((ptdi->hParent==TVI_ROOT) || (ptdi->hParent==0)) {
896 sibItem=&infoPtr->items [infoPtr->TopRootItem];
897 listItems=infoPtr->uNumItems;
900 parentItem= &infoPtr->items[ptdi->hParent];
901 if (!parentItem->firstChild)
902 parentItem->firstChild=iItem;
903 wineItem->parent=ptdi->hParent;
904 sibItem=&infoPtr->items [parentItem->firstChild];
905 parentItem->cChildren++;
906 listItems=parentItem->cChildren;
909 wineItem->upsibling=0; /* needed in case we're the first item in a list */
911 wineItem->firstChild=0;
915 switch (ptdi->hInsertAfter) {
916 case TVI_FIRST: wineItem->sibling=infoPtr->TopRootItem;
917 infoPtr->TopRootItem=iItem;
920 while (sibItem->sibling) {
922 sibItem=&infoPtr->items [sibItem->sibling];
924 sibItem->sibling=iItem;
926 wineItem->upsibling=prevsib->hItem;
928 wineItem->sibling=0; /* terminate list */
931 FIXME (treeview, "Sorted insert not implemented yet\n");
934 while ((sibItem->sibling) && (sibItem->sibling!=iItem)) {
936 sibItem=&infoPtr->items [sibItem->sibling];
938 if (sibItem->sibling)
939 WARN (treeview, "Buggy program tried to insert item after nonexisting handle.");
940 sibItem->upsibling=iItem;
941 wineItem->sibling=sibItem->hItem;
943 wineItem->upsibling=prevsib->hItem;
949 /* Fill in info structure */
951 wineItem->mask=tvItem->mask;
952 wineItem->hItem=iItem;
953 wineItem->iIntegral=1;
955 if (tvItem->mask & TVIF_CHILDREN)
956 wineItem->cChildren=tvItem->cChildren;
958 if (tvItem->mask & TVIF_IMAGE)
959 wineItem->iImage=tvItem->iImage;
961 /* if (tvItem->mask & TVIF_INTEGRAL)
962 wineItem->iIntegral=tvItem->iIntegral; */
965 if (tvItem->mask & TVIF_PARAM)
966 wineItem->lParam=tvItem->lParam;
968 if (tvItem->mask & TVIF_SELECTEDIMAGE)
969 wineItem->iSelectedImage=tvItem->iSelectedImage;
971 if (tvItem->mask & TVIF_STATE) {
972 wineItem->state=tvItem->state;
973 wineItem->stateMask=tvItem->stateMask;
976 if (tvItem->mask & TVIF_TEXT) {
977 TRACE (treeview,"(%s)\n", tvItem->pszText);
978 if (tvItem->pszText!=LPSTR_TEXTCALLBACK32A) {
979 len = lstrlen32A (tvItem->pszText)+1;
981 HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, len+1);
982 lstrcpy32A (wineItem->pszText, tvItem->pszText);
983 wineItem->cchTextMax=len;
987 TREEVIEW_QueueRefresh (wndPtr);
989 return (LRESULT) iItem;
995 TREEVIEW_DeleteItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
997 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1000 TREEVIEW_ITEM *wineItem;
1002 TRACE (treeview,"\n");
1003 if (!infoPtr) return FALSE;
1005 if ((INT32) lParam == TVI_ROOT) {
1006 TREEVIEW_RemoveTree (infoPtr);
1008 iItem= (INT32) lParam;
1009 wineItem = TREEVIEW_ValidItem (infoPtr, iItem);
1010 if (!wineItem) return FALSE;
1011 TREEVIEW_SendTreeviewNotify (wndPtr, TVN_DELETEITEM, 0, iItem, 0, pt);
1012 TREEVIEW_RemoveItem (infoPtr, wineItem);
1015 TREEVIEW_QueueRefresh (wndPtr);
1022 TREEVIEW_GetIndent (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1024 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1026 return infoPtr->uIndent;
1030 TREEVIEW_SetIndent (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1032 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1035 newIndent=(INT32) wParam;
1036 if (newIndent < MINIMUM_INDENT) newIndent=MINIMUM_INDENT;
1037 infoPtr->uIndent=newIndent;
1047 TREEVIEW_Create (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1049 TREEVIEW_INFO *infoPtr;
1053 TRACE (treeview,"\n");
1054 /* allocate memory for info structure */
1055 infoPtr = (TREEVIEW_INFO *)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
1056 sizeof(TREEVIEW_INFO));
1058 wndPtr->wExtra[0] = (DWORD)infoPtr;
1060 if (infoPtr == NULL) {
1061 ERR (treeview, "could not allocate info memory!\n");
1065 if ((TREEVIEW_INFO*)wndPtr->wExtra[0] != infoPtr) {
1066 ERR (treeview, "pointer assignment error!\n");
1070 hdc=GetDC32 (wndPtr->hwndSelf);
1072 /* set default settings */
1073 infoPtr->uInternalStatus=0;
1074 infoPtr->uNumItems=0;
1075 infoPtr->clrBk = GetSysColor32 (COLOR_WINDOW);
1076 infoPtr->clrText = GetSysColor32 (COLOR_BTNTEXT);
1079 infoPtr->uIndent = 15;
1080 infoPtr->himlNormal = NULL;
1081 infoPtr->himlState = NULL;
1082 infoPtr->uItemHeight = -1;
1083 GetTextMetrics32A (hdc, &tm);
1084 infoPtr->uRealItemHeight= tm.tmHeight + tm.tmExternalLeading;
1086 infoPtr->items = NULL;
1087 infoPtr->selectedItem=0;
1088 infoPtr->clrText=-1; /* use system color */
1089 infoPtr->dropItem=0;
1092 infoPtr->hwndNotify = GetParent32 (wndPtr->hwndSelf);
1093 infoPtr->bTransparent = (wndPtr->dwStyle & TBSTYLE_FLAT);
1096 if (wndPtr->dwStyle & TBSTYLE_TOOLTIPS) {
1097 /* Create tooltip control */
1098 // infoPtr->hwndToolTip = CreateWindowEx32A (....);
1100 /* Send TV_TOOLTIPSCREATED notification */
1103 ReleaseDC32 (wndPtr->hwndSelf, hdc);
1111 TREEVIEW_Destroy (WND *wndPtr)
1113 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1115 TREEVIEW_RemoveTree (infoPtr);
1117 HeapFree (GetProcessHeap (), 0, infoPtr);
1124 TREEVIEW_Paint (WND *wndPtr, WPARAM32 wParam)
1129 hdc = wParam==0 ? BeginPaint32 (wndPtr->hwndSelf, &ps) : (HDC32)wParam;
1130 TREEVIEW_QueueRefresh (wndPtr);
1132 EndPaint32 (wndPtr->hwndSelf, &ps);
1139 TREEVIEW_EraseBackground (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1141 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1142 HBRUSH32 hBrush = CreateSolidBrush32 (infoPtr->clrBk);
1145 TRACE (treeview,"\n");
1146 GetClientRect32 (wndPtr->hwndSelf, &rect);
1147 FillRect32 ((HDC32)wParam, &rect, hBrush);
1148 DeleteObject32 (hBrush);
1161 TREEVIEW_SendSimpleNotify (WND *wndPtr, UINT32 code)
1165 TRACE (treeview, "%x\n",code);
1166 nmhdr.hwndFrom = wndPtr->hwndSelf;
1167 nmhdr.idFrom = wndPtr->wIDmenu;
1170 return (BOOL32) SendMessage32A (GetParent32 (wndPtr->hwndSelf), WM_NOTIFY,
1171 (WPARAM32)nmhdr.idFrom, (LPARAM)&nmhdr);
1178 TREEVIEW_SendTreeviewNotify (WND *wndPtr, UINT32 code, UINT32 action,
1179 INT32 oldItem, INT32 newItem, POINT32 pt)
1181 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1183 TREEVIEW_ITEM *wineItem;
1185 TRACE (treeview,"code:%x action:%x olditem:%x newitem:%x\n",
1186 code,action,oldItem,newItem);
1187 nmhdr.hdr.hwndFrom = wndPtr->hwndSelf;
1188 nmhdr.hdr.idFrom = wndPtr->wIDmenu;
1189 nmhdr.hdr.code = code;
1190 nmhdr.action = action;
1192 wineItem=& infoPtr->items[oldItem];
1193 nmhdr.itemOld.mask = wineItem->mask;
1194 nmhdr.itemOld.hItem = wineItem->hItem;
1195 nmhdr.itemOld.state = wineItem->state;
1196 nmhdr.itemOld.stateMask = wineItem->stateMask;
1197 nmhdr.itemOld.iImage = wineItem->iImage;
1198 nmhdr.itemOld.pszText = wineItem->pszText;
1199 nmhdr.itemOld.cchTextMax = wineItem->cchTextMax;
1200 nmhdr.itemOld.iImage = wineItem->iImage;
1201 nmhdr.itemOld.iSelectedImage = wineItem->iSelectedImage;
1202 nmhdr.itemOld.cChildren = wineItem->cChildren;
1203 nmhdr.itemOld.lParam = wineItem->lParam;
1207 wineItem=& infoPtr->items[newItem];
1208 nmhdr.itemNew.mask = wineItem->mask;
1209 nmhdr.itemNew.hItem = wineItem->hItem;
1210 nmhdr.itemNew.state = wineItem->state;
1211 nmhdr.itemNew.stateMask = wineItem->stateMask;
1212 nmhdr.itemNew.iImage = wineItem->iImage;
1213 nmhdr.itemNew.pszText = wineItem->pszText;
1214 nmhdr.itemNew.cchTextMax = wineItem->cchTextMax;
1215 nmhdr.itemNew.iImage = wineItem->iImage;
1216 nmhdr.itemNew.iSelectedImage = wineItem->iSelectedImage;
1217 nmhdr.itemNew.cChildren = wineItem->cChildren;
1218 nmhdr.itemNew.lParam = wineItem->lParam;
1221 nmhdr.ptDrag.x = pt.x;
1222 nmhdr.ptDrag.y = pt.y;
1224 return (BOOL32)SendMessage32A (GetParent32 (wndPtr->hwndSelf), WM_NOTIFY,
1225 (WPARAM32)wndPtr->wIDmenu, (LPARAM)&nmhdr);
1233 TREEVIEW_Expand (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1235 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1236 TREEVIEW_ITEM *wineItem;
1241 flag= (UINT32) wParam;
1242 expandItem= (INT32) lParam;
1243 TRACE (treeview,"flags:%x item:%x\n", expandItem, wParam);
1244 wineItem = TREEVIEW_ValidItem (infoPtr, expandItem);
1245 if (!wineItem) return 0;
1246 if (!wineItem->cChildren) return 0;
1248 if (flag & TVE_TOGGLE) { /* FIXME: check exact behaviour here */
1249 flag &= ~TVE_TOGGLE; /* ie: bitwise ops or 'case' ops */
1250 if (wineItem->state & TVIS_EXPANDED)
1251 flag |= TVE_COLLAPSE;
1257 case TVE_COLLAPSERESET:
1258 if (!wineItem->state & TVIS_EXPANDED) return 0;
1259 wineItem->state &= ~(TVIS_EXPANDEDONCE | TVIS_EXPANDED);
1260 TREEVIEW_RemoveAllChildren (infoPtr, wineItem);
1264 if (!wineItem->state & TVIS_EXPANDED) return 0;
1265 wineItem->state &= ~TVIS_EXPANDED;
1269 if (wineItem->state & TVIS_EXPANDED) return 0;
1270 if (!(wineItem->state & TVIS_EXPANDEDONCE)) {
1271 if (TREEVIEW_SendTreeviewNotify (wndPtr, TVN_ITEMEXPANDING,
1272 0, 0, expandItem, pt))
1273 return FALSE; /* FIXME: OK? */
1274 wineItem->state |= TVIS_EXPANDED | TVIS_EXPANDEDONCE;
1275 TREEVIEW_SendTreeviewNotify (wndPtr, TVN_ITEMEXPANDED,
1276 0, 0, expandItem, pt);
1278 wineItem->state |= TVIS_EXPANDED;
1280 case TVE_EXPANDPARTIAL:
1281 FIXME (treeview, "TVE_EXPANDPARTIAL not implemented\n");
1282 wineItem->state ^=TVIS_EXPANDED;
1283 wineItem->state |=TVIS_EXPANDEDONCE;
1287 TREEVIEW_QueueRefresh (wndPtr);
1295 TREEVIEW_HitTest (WND *wndPtr, LPTVHITTESTINFO lpht)
1297 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1298 TREEVIEW_ITEM *wineItem;
1304 GetClientRect32 (wndPtr->hwndSelf, &rect);
1305 TRACE (treeview,"(%d,%d)\n",lpht->pt.x, lpht->pt.y);
1310 if (x < rect.left) status|=TVHT_TOLEFT;
1311 if (x > rect.right) status|=TVHT_TORIGHT;
1312 if (y < rect.top ) status|=TVHT_ABOVE;
1313 if (y > rect.bottom) status|=TVHT_BELOW;
1319 if (!infoPtr->firstVisible) WARN (treeview,"Can't fetch first visible item");
1320 wineItem=&infoPtr->items [infoPtr->firstVisible];
1322 while ((wineItem!=NULL) && (y > wineItem->rect.bottom))
1323 wineItem=TREEVIEW_GetNextListItem (infoPtr,wineItem);
1325 if (wineItem==NULL) {
1326 lpht->flags=TVHT_NOWHERE;
1330 if (x>wineItem->rect.right) {
1331 lpht->flags|=TVHT_ONITEMRIGHT;
1332 return wineItem->hItem;
1336 if (x<wineItem->rect.left+10) lpht->flags|=TVHT_ONITEMBUTTON;
1338 lpht->flags=TVHT_ONITEMLABEL; /* FIXME: implement other flags */
1341 lpht->hItem=wineItem->hItem;
1342 return wineItem->hItem;
1347 TREEVIEW_HitTest32 (WND *wndPtr, LPARAM lParam)
1350 return (LRESULT) TREEVIEW_HitTest (wndPtr, (LPTVHITTESTINFO) lParam);
1357 TREEVIEW_LButtonDoubleClick (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1359 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1360 TREEVIEW_ITEM *wineItem;
1364 TRACE (treeview,"\n");
1365 ht.pt.x = (INT32)LOWORD(lParam);
1366 ht.pt.y = (INT32)HIWORD(lParam);
1367 SetFocus32 (wndPtr->hwndSelf);
1369 iItem=TREEVIEW_HitTest (wndPtr, &ht);
1370 TRACE (treeview,"item %d \n",iItem);
1371 wineItem=TREEVIEW_ValidItem (infoPtr, iItem);
1372 if (!wineItem) return 0;
1374 if (TREEVIEW_SendSimpleNotify (wndPtr, NM_DBLCLK)!=TRUE) { /* FIXME!*/
1375 wineItem->state &= ~TVIS_EXPANDEDONCE;
1376 TREEVIEW_Expand (wndPtr, (WPARAM32) TVE_TOGGLE, (LPARAM) iItem);
1384 TREEVIEW_LButtonDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1389 TRACE (treeview,"\n");
1390 ht.pt.x = (INT32)LOWORD(lParam);
1391 ht.pt.y = (INT32)HIWORD(lParam);
1393 SetFocus32 (wndPtr->hwndSelf);
1394 iItem=TREEVIEW_HitTest (wndPtr, &ht);
1395 TRACE (treeview,"item %d \n",iItem);
1396 if (ht.flags & TVHT_ONITEMBUTTON) {
1397 TREEVIEW_Expand (wndPtr, (WPARAM32) TVE_TOGGLE, (LPARAM) iItem);
1400 if (TREEVIEW_SelectItem (wndPtr, (WPARAM32) TVGN_CARET, (LPARAM) iItem))
1409 TREEVIEW_RButtonDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1418 /* FIXME: If the specified item is the child of a collapsed parent item,
1419 expand parent's list of child items to reveal the specified item.
1423 TREEVIEW_SelectItem (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1425 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1426 TREEVIEW_ITEM *prevItem,*wineItem;
1427 INT32 action,prevSelect, newSelect;
1430 TRACE (treeview,"item %lx, flag %x\n", lParam, wParam);
1431 newSelect= (INT32) lParam;
1432 wineItem = TREEVIEW_ValidItem (infoPtr, newSelect);
1433 if (!wineItem) return FALSE;
1434 prevSelect=infoPtr->selectedItem;
1435 prevItem= TREEVIEW_ValidItem (infoPtr, prevSelect);
1439 action= (INT32) wParam;
1443 if (TREEVIEW_SendTreeviewNotify (wndPtr, TVN_SELCHANGING, TVC_BYMOUSE,
1444 prevSelect, newSelect,dummy))
1445 return FALSE; /* FIXME: OK? */
1447 if (prevItem) prevItem->state &= ~TVIS_SELECTED;
1448 infoPtr->selectedItem=newSelect;
1449 wineItem->state |=TVIS_SELECTED;
1450 TREEVIEW_SendTreeviewNotify (wndPtr, TVN_SELCHANGED,
1451 TVC_BYMOUSE, prevSelect, newSelect, dummy);
1453 case TVGN_DROPHILITE:
1454 FIXME (treeview, "DROPHILITE not implemented");
1456 case TVGN_FIRSTVISIBLE:
1457 FIXME (treeview, "FIRSTVISIBLE not implemented");
1461 TREEVIEW_QueueRefresh (wndPtr);
1468 /* FIXME: does KEYDOWN also send notifications?? If so, use
1469 TREEVIEW_SelectItem.
1474 TREEVIEW_KeyDown (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1476 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1477 TREEVIEW_ITEM *prevItem,*newItem;
1481 TRACE (treeview,"%x %lx",wParam, lParam);
1482 prevSelect=infoPtr->selectedItem;
1483 if (!prevSelect) return FALSE;
1485 prevItem= TREEVIEW_ValidItem (infoPtr, prevSelect);
1490 newItem=TREEVIEW_GetPrevListItem (infoPtr, prevItem);
1492 newItem=& infoPtr->items[infoPtr->TopRootItem];
1495 newItem=TREEVIEW_GetNextListItem (infoPtr, prevItem);
1496 if (!newItem) newItem=prevItem;
1499 newItem=& infoPtr->items[infoPtr->TopRootItem];
1502 newItem=TREEVIEW_GetLastListItem (infoPtr);
1508 FIXME (treeview, "%x not implemented\n", wParam);
1512 if (!newItem) return FALSE;
1514 if (prevItem!=newItem) {
1515 prevItem->state &= ~TVIS_SELECTED;
1516 newItem->state |= TVIS_SELECTED;
1517 infoPtr->selectedItem=newItem->hItem;
1518 TREEVIEW_QueueRefresh (wndPtr);
1528 TREEVIEW_VScroll (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1531 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1534 TRACE (treeview,"wp %x, lp %lx\n", wParam, lParam);
1535 if (!infoPtr->uInternalStatus & TV_VSCROLL) return FALSE;
1537 switch (LOWORD (wParam)) {
1539 if (!infoPtr->cy) return FALSE;
1540 infoPtr->cy -= infoPtr->uRealItemHeight;
1541 if (infoPtr->cy < 0) infoPtr->cy=0;
1544 maxHeight=infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
1545 if (infoPtr->cy == maxHeight) return FALSE;
1546 infoPtr->cy += infoPtr->uRealItemHeight;
1547 if (infoPtr->cy > maxHeight)
1548 infoPtr->cy = maxHeight;
1551 if (!infoPtr->cy) return FALSE;
1552 infoPtr->cy -= infoPtr->uVisibleHeight;
1553 if (infoPtr->cy < 0) infoPtr->cy=0;
1556 maxHeight=infoPtr->uTotalHeight-infoPtr->uVisibleHeight;
1557 if (infoPtr->cy == maxHeight) return FALSE;
1558 infoPtr->cy += infoPtr->uVisibleHeight;
1559 if (infoPtr->cy > maxHeight)
1560 infoPtr->cy = maxHeight;
1563 infoPtr->cy = HIWORD (wParam);
1568 TREEVIEW_QueueRefresh (wndPtr);
1573 TREEVIEW_HScroll (WND *wndPtr, WPARAM32 wParam, LPARAM lParam)
1575 TREEVIEW_INFO *infoPtr = TREEVIEW_GetInfoPtr(wndPtr);
1577 TRACE (treeview,"wp %lx, lp %x\n", lParam, wParam);
1579 if (!infoPtr->uInternalStatus & TV_HSCROLL) return FALSE;
1587 TREEVIEW_WindowProc (HWND32 hwnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
1589 WND *wndPtr = WIN_FindWndPtr(hwnd);
1593 case TVM_INSERTITEM32A:
1594 return TREEVIEW_InsertItem32A (wndPtr, wParam, lParam);
1596 case TVM_INSERTITEM32W:
1597 FIXME (treeview, "Unimplemented msg TVM_INSERTITEM32W\n");
1600 case TVM_DELETEITEM:
1601 return TREEVIEW_DeleteItem (wndPtr, wParam, lParam);
1604 return TREEVIEW_Expand (wndPtr, wParam, lParam);
1606 case TVM_GETITEMRECT:
1607 return TREEVIEW_GetItemRect (wndPtr, wParam, lParam);
1610 return TREEVIEW_GetCount (wndPtr, wParam, lParam);
1613 return TREEVIEW_GetIndent (wndPtr, wParam, lParam);
1616 return TREEVIEW_SetIndent (wndPtr, wParam, lParam);
1618 case TVM_GETIMAGELIST:
1619 return TREEVIEW_GetImageList (wndPtr, wParam, lParam);
1621 case TVM_SETIMAGELIST:
1622 return TREEVIEW_SetImageList (wndPtr, wParam, lParam);
1624 case TVM_GETNEXTITEM:
1625 return TREEVIEW_GetNextItem32 (wndPtr, wParam, lParam);
1627 case TVM_SELECTITEM:
1628 return TREEVIEW_SelectItem (wndPtr, wParam, lParam);
1630 case TVM_GETITEM32A:
1631 return TREEVIEW_GetItem (wndPtr, wParam, lParam);
1633 case TVM_GETITEM32W:
1634 FIXME (treeview, "Unimplemented msg TVM_GETITEM32W\n");
1637 case TVM_SETITEM32A:
1638 return TREEVIEW_SetItem (wndPtr, wParam, lParam);
1640 case TVM_SETITEM32W:
1641 FIXME (treeview, "Unimplemented msg TVM_SETITEMW\n");
1644 case TVM_EDITLABEL32A:
1645 FIXME (treeview, "Unimplemented msg TVM_EDITLABEL32A \n");
1648 case TVM_EDITLABEL32W:
1649 FIXME (treeview, "Unimplemented msg TVM_EDITLABEL32W \n");
1652 case TVM_GETEDITCONTROL:
1653 FIXME (treeview, "Unimplemented msg TVM_GETEDITCONTROL\n");
1656 case TVM_GETVISIBLECOUNT:
1657 return TREEVIEW_GetVisibleCount (wndPtr, wParam, lParam);
1660 return TREEVIEW_HitTest32 (wndPtr, lParam);
1662 case TVM_CREATEDRAGIMAGE:
1663 FIXME (treeview, "Unimplemented msg TVM_CREATEDRAGIMAGE\n");
1666 case TVM_SORTCHILDREN:
1667 FIXME (treeview, "Unimplemented msg TVM_SORTCHILDREN\n");
1670 case TVM_ENSUREVISIBLE:
1671 FIXME (treeview, "Unimplemented msg TVM_ENSUREVISIBLE\n");
1674 case TVM_SORTCHILDRENCB:
1675 FIXME (treeview, "Unimplemented msg TVM_SORTCHILDRENCB\n");
1678 case TVM_ENDEDITLABELNOW:
1679 FIXME (treeview, "Unimplemented msg TVM_ENDEDITLABELNOW\n");
1682 case TVM_GETISEARCHSTRING32A:
1683 FIXME (treeview, "Unimplemented msg TVM_GETISEARCHSTRING32A\n");
1686 case TVM_GETISEARCHSTRING32W:
1687 FIXME (treeview, "Unimplemented msg TVM_GETISEARCHSTRING32W\n");
1690 case TVM_SETTOOLTIPS:
1691 FIXME (treeview, "Unimplemented msg TVM_SETTOOLTIPS\n");
1694 case TVM_GETTOOLTIPS:
1695 FIXME (treeview, "Unimplemented msg TVM_GETTOOLTIPS\n");
1698 case TVM_SETINSERTMARK:
1699 FIXME (treeview, "Unimplemented msg TVM_SETINSERTMARK\n");
1702 case TVM_SETITEMHEIGHT:
1703 return TREEVIEW_SetItemHeight (wndPtr, wParam);
1705 case TVM_GETITEMHEIGHT:
1706 return TREEVIEW_GetItemHeight (wndPtr);
1708 case TVM_SETBKCOLOR:
1709 FIXME (treeview, "Unimplemented msg TVM_SETBKCOLOR\n");
1712 case TVM_SETTEXTCOLOR:
1713 return TREEVIEW_SetTextColor (wndPtr, wParam, lParam);
1715 case TVM_GETBKCOLOR:
1716 FIXME (treeview, "Unimplemented msg TVM_GETBKCOLOR\n");
1719 case TVM_GETTEXTCOLOR:
1720 return TREEVIEW_GetTextColor (wndPtr);
1722 case TVM_SETSCROLLTIME:
1723 FIXME (treeview, "Unimplemented msg TVM_SETSCROLLTIME\n");
1726 case TVM_GETSCROLLTIME:
1727 FIXME (treeview, "Unimplemented msg TVM_GETSCROLLTIME\n");
1730 case TVM_SETINSERTMARKCOLOR:
1731 FIXME (treeview, "Unimplemented msg TVM_SETINSERTMARKCOLOR\n");
1734 case TVM_SETUNICODEFORMAT:
1735 FIXME (treeview, "Unimplemented msg TVM_SETUNICODEFORMAT\n");
1738 case TVM_GETUNICODEFORMAT:
1739 FIXME (treeview, "Unimplemented msg TVM_GETUNICODEFORMAT\n");
1745 return TREEVIEW_Create (wndPtr, wParam, lParam);
1748 return TREEVIEW_Destroy (wndPtr);
1753 return TREEVIEW_EraseBackground (wndPtr, wParam, lParam);
1756 return DLGC_WANTARROWS | DLGC_WANTCHARS;
1759 return TREEVIEW_Paint (wndPtr, wParam);
1765 return TREEVIEW_KeyDown (wndPtr, wParam, lParam);
1768 // case WM_KILLFOCUS:
1769 // case WM_SETFOCUS:
1772 case WM_LBUTTONDOWN:
1773 return TREEVIEW_LButtonDown (wndPtr, wParam, lParam);
1775 case WM_LBUTTONDBLCLK:
1776 return TREEVIEW_LButtonDoubleClick (wndPtr, wParam, lParam);
1778 case WM_RBUTTONDOWN:
1779 return TREEVIEW_RButtonDown (wndPtr, wParam, lParam);
1782 // case WM_SYSCOLORCHANGE:
1783 // case WM_STYLECHANGED:
1784 // case WM_SETREDRAW:
1787 return TREEVIEW_HandleTimer (wndPtr, wParam, lParam);
1791 return TREEVIEW_HScroll (wndPtr, wParam, lParam);
1793 return TREEVIEW_VScroll (wndPtr, wParam, lParam);
1796 if (uMsg >= WM_USER)
1797 FIXME (treeview, "Unknown msg %04x wp=%08x lp=%08lx\n",
1798 uMsg, wParam, lParam);
1799 return DefWindowProc32A (hwnd, uMsg, wParam, lParam);
1806 TREEVIEW_Register (void)
1808 WNDCLASS32A wndClass;
1810 TRACE (treeview,"\n");
1812 if (GlobalFindAtom32A (WC_TREEVIEW32A)) return;
1814 ZeroMemory (&wndClass, sizeof(WNDCLASS32A));
1815 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1816 wndClass.lpfnWndProc = (WNDPROC32)TREEVIEW_WindowProc;
1817 wndClass.cbClsExtra = 0;
1818 wndClass.cbWndExtra = sizeof(TREEVIEW_INFO *);
1819 wndClass.hCursor = LoadCursor32A (0, IDC_ARROW32A);
1820 wndClass.hbrBackground = 0;
1821 wndClass.lpszClassName = WC_TREEVIEW32A;
1823 RegisterClass32A (&wndClass);