4

启用 toThemeAware 时,VirtualTrees.pas 版本 5.0.0 中的复选框处理出现损坏。csUncheckedNormal 的节点被绘制为选中 + 热。

要使用 DrawElement 正确绘制未选中的主题复选框,详细信息记录必须是:Element = teButton、Part = 3 和 State = 5。但是,当节点设置为 csUncheckedNormal 时,VirtualTrees.pas 最终会调用 State = 1 的 DrawElement .

VirtualTrees 中似乎声明了很多间接和额外的常量,所以我不确定如何最好地解决这个问题。欢迎提出想法...

(即使是在屏幕上获取 TVirtualStringTree 并填充一些数据的最小代码也有点冗长,无法在此处发布。除了基础知识之外,重现此内容所需要做的就是在 TreeOptions.MiscOptions 中启用 toCheckSupport 并设置 Node.CheckType : = InitNode 回调中的 ctTriStateCheckBox。)

4

1 回答 1

6

好吧,因为我认为 VirtualTreeView 在移植到 delphi XE2 时不计入 VCL 样式,所以这可能会解决您的问题。您必须在绘制之前获取元素详细信息,否则您会得到类似的东西(它是 VirtualTreeView 绘制复选框状态的模拟)。注意不同的顺序和工件;这是禁用 VCL 样式的相同代码的结果,第二次启用:

在此处输入图像描述

我知道这很奇怪,但我无法回答你为什么会这样。我可以告诉你,你应该调用TThemeServices.GetElementDetails或可选地自己计算状态索引,以使元素渲染正常工作。您可以尝试使用以下修复:

procedure TBaseVirtualTree.PaintCheckImage(Canvas: TCanvas; 
  const ImageInfo: TVTImageInfo; Selected: Boolean);
var
  // add a new variable for calculating TThemedButton state from the input
  // ImageInfo.Index; I hope ImageInfo.Index has the proper state order
  State: Integer;
begin
...
  case Index of
    0..8: // radio buttons
    begin
      // get the low index of the first radio button state and increment it by 
      // the ImageInfo.Index and get details of the button element
      State := Ord(TThemedButton(tbRadioButtonUncheckedNormal)) + Index - 1;
      Details := StyleServices.GetElementDetails(TThemedButton(State));
    end;
    9..20: // check boxes
    begin
      // get the low index of the first check box state and increment it by 
      // the ImageInfo.Index and get details of the button element
      State := Ord(TThemedButton(tbCheckBoxUncheckedNormal)) + Index - 9;
      Details := StyleServices.GetElementDetails(TThemedButton(State));
    end;
    21..24: // buttons
    begin
      // get the low index of the first push button state and increment it by 
      // the ImageInfo.Index and get details of the button element
      State := Ord(TThemedButton(tbPushButtonNormal)) + Index - 21;
      Details := StyleServices.GetElementDetails(TThemedButton(State));
    end;
  else
    Details.Part := 0;
    Details.State := 0;
  end;
...
end;

我已经对所有检查类型进行了测试,它对我有用。

于 2012-04-19T11:58:22.407 回答