50#define NONAMELESSUNION
174#define TV_HSCROLL 0x01
175#define TV_VSCROLL 0x02
177#define TV_LDRAGGING 0x08
179#define TV_RDRAGGING 0x20
183#define TV_EDIT_TIMER 2
184#define TV_EDIT_TIMER_SET 2
186#define TEXT_CALLBACK_SIZE 260
188#define TREEVIEW_LEFT_MARGIN 8
190#define MINIMUM_INDENT 19
192#define CALLBACK_MASK_ALL (TVIF_TEXT|TVIF_CHILDREN|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
194#define STATEIMAGEINDEX(x) (((x) >> 12) & 0x0f)
195#define OVERLAYIMAGEINDEX(x) (((x) >> 8) & 0x0f)
196#define ISVISIBLE(x) ((x)->visibleOrder >= 0)
198#define GETLINECOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrGrayText : (x))
199#define GETBKCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindow : (x))
200#define GETTXTCOLOR(x) ((x) == CLR_NONE ? comctl32_color.clrWindowText : (x))
201#define GETINSCOLOR(x) ((x) == CLR_DEFAULT ? comctl32_color.clrBtnText : (x))
327 return infoPtr->
hFont;
334 if (
item ==
NULL)
return "<null item>";
336 if (
item->pszText ==
NULL)
return "<null>";
379 while (
item->lastChild)
575 TRACE(
"code:%d action:0x%x olditem:%p newitem:%p\n",
605 TRACE(
"code:%d dragitem:%p\n",
code, dragItem);
627 TRACE(
"drawstage:0x%x hdc:%p\n", dwDrawStage,
hdc);
629 nmcd = &nmcdhdr.
nmcd;
655 dwDrawStage =
CDDS_ITEM | uItemDrawState;
665 nmcd = &nmcdhdr->
nmcd;
674 TRACE(
"drawstage:0x%x hdc:%p item:%lx, itemstate:0x%x, lItemlParam:0x%lx\n",
688 &tvdi.
item, editItem);
704 TRACE(
"mask=0x%x, callbackmask=0x%x\n",
mask,
item->callbackMask);
707 if (
mask == 0)
return;
741 TRACE(
"returned str %s, len=%d, buflen=%d\n",
746 item->pszText = newText;
759 TRACE(
"returned wstr %s, len=%d\n",
764 item->pszText = newText;
782 TRACE(
"same buffer str %s, len=%d, buflen=%d\n",
788 item->pszText = newText;
812 item->state &= ~callback.item.stateMask;
818 item->callbackMask &= ~callback.item.mask;
842 TRACE(
"(hwndFrom=%p, nCommand=%d)\n", hwndFrom, nCommand);
871 item->imageOffset =
item->stateOffset
970 root->state &= ~TVIS_EXPANDED;
977 for (;
root != sibling;
985 if (
root->textWidth == 0)
1058 if (sibling !=
NULL)
1073 if (
parent->firstChild == sibling)
1074 parent->firstChild = newItem;
1077 parent->lastChild = newItem;
1090 if (sibling !=
NULL)
1105 if (
parent->lastChild == sibling)
1106 parent->lastChild = newItem;
1109 parent->firstChild = newItem;
1116 UINT callbackClear = 0;
1117 UINT callbackSet = 0;
1123 item->textWidth = 0;
1143 item->pszText = newText;
1158 TRACE(
"setting callback, item %p\n",
item);
1212 TRACE(
"prevstate 0x%x, state 0x%x, mask 0x%x\n",
item->state, tvItem->
state,
1214 item->state &= ~tvItem->stateMask;
1218 if (tvItem->
mask & TVIF_STATEEX)
1223 item->callbackMask |= callbackSet;
1224 item->callbackMask &= ~callbackClear;
1240 parentItem = infoPtr->
root;
1248 WARN(
"invalid parent %p\n", parentItem);
1265 insertAfter->
parent != parentItem)
1267 WARN(
"invalid insert after %p\n", insertAfter);
1272 TRACE(
"parent %p position %p: %s\n", parentItem, insertAfter,
1279 if (newItem ==
NULL)
1282 newItem->
parent = parentItem;
1322 bTextUpdated =
TRUE;
1326 while (aChild !=
NULL)
1337 aChild == originalFirst)
1339 bItemInserted =
TRUE;
1344 previousChild = aChild;
1361 bItemInserted =
TRUE;
1370 if ((!bItemInserted) && (aChild ==
NULL))
1378 TRACE(
"new item %p; parent %p, mask 0x%x\n", newItem,
1399 if (parentItem == infoPtr->
root ||
1417 for (
item = newItem;
1444 while (kill !=
NULL)
1466 parentItem =
item->parent;
1478 if (
item->prevSibling)
1479 item->prevSibling->nextSibling =
item->nextSibling;
1481 if (
item->nextSibling)
1482 item->nextSibling->prevSibling =
item->prevSibling;
1490 if (
item->firstChild)
1526 TRACE(
"TVI_ROOT\n");
1528 newSelection =
NULL;
1550 if (
item->nextSibling)
1551 newSelection =
item->nextSibling;
1552 else if (
item->parent != infoPtr->
root)
1553 newSelection =
item->parent;
1555 newSelection =
item->prevSibling;
1556 TRACE(
"newSelection = %p\n", newSelection);
1562 if (
item->nextSibling)
1563 newFirstVisible =
item->nextSibling;
1564 else if (
item->prevSibling)
1565 newFirstVisible =
item->prevSibling;
1566 else if (
item->parent != infoPtr->
root)
1567 newFirstVisible =
item->parent;
1649 if (infoPtr->
uIndent != newIndent)
1707 return uOldScrollTime;
1729#define TVHEIGHT_MIN 16
1730#define TVHEIGHT_FONT_ADJUST 3
1753 if (height < infoPtr->normalImageHeight)
1805 ERR(
"unknown imagelist type %u\n",
type);
1817 bRecalcVisible =
TRUE;
1824 bRecalcVisible =
TRUE;
1844 TRACE(
"new=%d, old=%d\n", newHeight, prevHeight);
1845 if (newHeight == -1)
1852 if (newHeight == 0) newHeight = 1;
1967 if (infoPtr->
clrText != prevColor)
1987 infoPtr->
clrBk = newColor;
1989 if (newColor != prevColor)
2063 if (!
item->textWidth)
2070 *lpRect =
item->rect;
2099 infoPtr =
item->infoPtr;
2100 TRACE(
"got item from different tree %p, called from %p\n",
item->infoPtr, infoPtr);
2107 if (!valid_item)
return FALSE;
2115 FIXME(
"I_CHILDRENCALLBACK not supported\n");
2152 FIXME(
" GetItem called with LPSTR_TEXTCALLBACK\n");
2164 FIXME(
" GetItem called with LPSTR_TEXTCALLBACK\n");
2174 if (tvItem->
mask & TVIF_STATEEX)
2176 FIXME(
"Extended item state not supported, returning 0.\n");
2180 TRACE(
"item <%p>, txt %p, img %d, mask 0x%x\n",
2203 originalItem = *
item;
2291 TRACE(
"flags:0x%x, returns %p\n",
which, retval);
2303 retval =
item->nextSibling;
2306 retval =
item->prevSibling;
2312 retval =
item->firstChild;
2352 static const unsigned int state_table[] = { 0, 2, 1 };
2358 item->state &= ~TVIS_STATEIMAGEMASK;
2381 LONG centerx, centery;
2388 if (!lar &&
item->iLevel == 0)
2394 centerx = (
item->linesOffset +
item->stateOffset) / 2;
2395 centery = (
item->rect.top +
item->rect.bottom) / 2;
2399 HPEN hOldPen, hNewPen;
2411 centery = (centery + 2) & ~1;
2416 if (
item->prevSibling ||
item->parent != infoPtr->
root)
2422 if (
item->nextSibling)
2432 int pcenterx = (
parent->linesOffset +
parent->stateOffset) / 2;
2455 if (
item->cChildren)
2461 glyphRect.
left =
item->linesOffset;
2473 LONG plussize = (rectsize + 1) * 3 / 4;
2478 Rectangle(
hdc, centerx - rectsize - 1, centery - rectsize - 1,
2479 centerx + rectsize + 2, centery + rectsize + 2);
2491 LineTo(
hdc, centerx + plussize, centery);
2497 LineTo(
hdc, centerx, centery + plussize);
2503 centerx + plussize, centery + 2);
2509 centerx + 2, centery + plussize);
2529 COLORREF oldTextColor, oldTextBkColor;
2573 if (!
item->textWidth)
2582 TRACE(
"prepaint:cditem-app returns 0x%x\n", cditem);
2607 centery = (
item->rect.top +
item->rect.bottom) / 2;
2635 imageIndex =
item->iSelectedImage;
2640 imageIndex =
item->iExpandedImage;
2645 imageIndex =
item->iImage;
2682 TRACE(
"drawing text %s at (%s)\n",
2708 TRACE(
"item:%d,mark:%p\n",
2714 HPEN hNewPen, hOldPen;
2751 TRACE(
"postpaint:cditem-app returns 0x%x\n", cditem);
2903 TRACE(
"%p\n", infoPtr);
2920 TRACE(
"empty window\n");
2988 hdcScreen =
GetDC(0);
3008 TRACE(
"checkbox index %d\n", nIndex);
3023 item->state &= ~TVIS_STATEIMAGEMASK;
3041 TRACE(
"(%p %p)\n", infoPtr, hdc_ref);
3125 else if(
first->pszText)
3194 ERR(
"invalid item hParent=%p\n",
parent);
3201 lpCompare = (
LPARAM)pSort;
3206 lpCompare = (
LPARAM)infoPtr;
3222 if (sortList ==
NULL)
3226 DPA_Sort(sortList, pfnCompare, lpCompare);
3235 item->nextSibling = nextItem;
3238 if (prevItem ==
NULL)
3247 item->prevSibling = prevItem;
3279 if (
item->visibleOrder == visOrder)
3347 BOOL bSetSelection, bSetFirstVisible;
3349 LONG scrollDist = 0;
3365 item->state &= ~TVIS_EXPANDED;
3367 if (wasExpanded && bUser)
3379 if (tmpItem->nextSibling)
3384 tmpItem = tmpItem->
parent;
3388 scrollDist = nextItem->
rect.
top;
3390 if (bRemoveChildren)
3392 INT old_cChildren =
item->cChildren;
3393 TRACE(
"TVE_COLLAPSERESET\n");
3394 item->state &= ~TVIS_EXPANDEDONCE;
3396 item->cChildren = old_cChildren;
3401 if (
item->firstChild)
3407 for (
i =
item->firstChild;
i != sibling;
3410 i->visibleOrder = -1;
3417 scrollDist = -(scrollDist - nextItem->
rect.
top);
3430 scrollRect.
left = 0;
3442 scrollRect.
top =
item->rect.top;
3458 LONG orgNextTop = 0;
3461 BOOL sendsNotifications;
3463 TRACE(
"(%p, %p, partial=%d, %d)\n", infoPtr,
item, partial,
user);
3476 tmpItem = tmpItem->
parent;
3480 orgNextTop = nextItem->
rect.
top;
3484 sendsNotifications =
user || ((
item->cChildren != 0) &&
3486 if (sendsNotifications)
3490 TRACE(
" TVN_ITEMEXPANDING returned TRUE, exiting...\n");
3494 if (!
item->firstChild)
3500 FIXME(
"TVE_EXPANDPARTIAL not implemented\n");
3508 scrollRect.
left = 0;
3513 scrollDist = nextItem->
rect.
top - orgNextTop;
3514 scrollRect.
top = orgNextTop;
3520 scrollRect.
top =
item->rect.top;
3529 int nChildren =
item->lastChild->visibleOrder
3530 -
item->firstChild->visibleOrder + 1;
3532 int visible_pos =
item->visibleOrder
3537 if (visible_pos > 0 && nChildren > rows_below)
3539 int scroll = nChildren - rows_below;
3541 if (scroll > visible_pos)
3542 scroll = visible_pos;
3557 if (sendsNotifications) {
3636 TRACE(
"For (%s) item:%d, flags 0x%x, state:%d\n",
3675 && row < item->visibleOrder +
item->iIntegral)
3700 else if (
x >
rect.right)
3709 else if (
y >
rect.bottom)
3727 if (!
item->textWidth)
3730 if (
x >=
item->textOffset +
item->textWidth)
3734 else if (
x >=
item->textOffset)
3738 else if (
x >=
item->imageOffset)
3742 else if (
x >=
item->stateOffset)
3779 TRACE(
"WM_PAINT start\n");
3782 TRACE(
"WM_PAINT done\n");
3937 if (infoPtr->
hFont != 0)
3956 if (infoPtr->
hFont != 0)
4046 if (!bCancel && bCommit)
4063 ERR(
"OutOfMemory, cannot allocate space for label\n");
4064 if (newText != tmpText)
heap_free(newText);
4078 if (newText != tmpText)
heap_free(newText);
4093 ERR(
"got unknown timer\n");
4098 infoPtr->
Timer &= ~TV_EDIT_TIMER_SET;
4120 r.top =
pt.y - cyDrag;
4121 r.left =
pt.x - cxDrag;
4122 r.bottom =
pt.y + cyDrag;
4123 r.right =
pt.x + cxDrag;