代码之家  ›  专栏  ›  技术社区  ›  Edwin Yip

虚拟字符串树:如何确定节点文本是否完全显示?

  •  3
  • Edwin Yip  · 技术社区  · 16 年前

    当tvirtualstreetree.hintmode=hmtooltip时,当鼠标悬停在节点和列上且节点文本未完全显示时,节点文本将成为提示文本。但是我必须设置hintmode=hmhint,这样我可以在偶数处理程序中根据当前鼠标光标所在的位置提供各种提示文本,并且在该hintmode中,提示文本不会自动生成。

    我的问题是如何知道A节点文本是否完全显示,以便我知道应该提供节点文本或空字符串作为提示文本?
    谢谢。

    2 回复  |  直到 16 年前
        1
  •  1
  •   Ondrej Kelle    16 年前

    你可以打电话 TBaseVirtualTree.GetDisplayRect 确定节点的文本边界。取决于 Unclipped 参数,它将为您提供完整或实际的文本宽度。 TextOnly 应设置为 True :

    function IsTreeTextClipped(Tree: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex): Boolean;
    var
      FullRect, ClippedRect: TRect;
    begin
      FullRect := Tree.GetDisplayRect(Node, Column, True, True);
      ClippedRect := Tree.GetDisplayRect(Node, Column, True, False);
      Result := (ClippedRect.Right - ClippedRect.Left) < (FullRect.Right - FullRect.Left);
    end;
    

    注意,如果尚未初始化节点,函数将隐式初始化该节点。

        2
  •  0
  •   Rob Kennedy    16 年前

    您可以使用树控件本身使用的内容。这是 cm_HintShow 单行节点的消息处理程序 hmTooltip 模式生效。

    NodeRect := GetDisplayRect(HitInfo.HitNode, HitInfo.HitColumn, True, True, True);
    BottomRightCellContentMargin := DoGetCellContentMargin(HitInfo.HitNode, HitInfo.HitColumn
    , ccmtBottomRightOnly);
    
    ShowOwnHint := (HitInfo.HitColumn > InvalidColumn) and PtInRect(NodeRect, CursorPos) and
      (CursorPos.X <= ColRight) and (CursorPos.X >= ColLeft) and
      (
        // Show hint also if the node text is partially out of the client area.
        // "ColRight - 1", since the right column border is not part of this cell.
        ( (NodeRect.Right + BottomRightCellContentMargin.X) > Min(ColRight - 1, ClientWidth) ) or
        (NodeRect.Left < Max(ColLeft, 0)) or
        ( (NodeRect.Bottom + BottomRightCellContentMargin.Y) > ClientHeight ) or
        (NodeRect.Top < 0)
      );
    

    如果 ShowOwnHint 为true,则应将节点的文本作为提示文本返回。否则,将提示文本留空。

    使用该代码的主要障碍是 DoGetCellContentMargin 受保护,因此不能直接调用。您可以编辑源以将其公开,或者在自己的函数中复制其功能;如果您不处理 OnBeforeCellPaint 事件,则它始终返回(0,0)。

    这个 HitInfo 数据来自调用 GetHitTestInfoAt .