秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
lazarus Object Inspector和combobox的下拉列表在linux时没有高亮显示选中的item,在windows是有高亮显示的,按以下方法修改就可以,如果你有更有效的方法也请与我分享。
(lazarus版本:3.2.4 for gtk2,FPC版本:3.2.2,操作系统:银河麒麟 v10sp1)
windows版本是正常的:

 

 linux版本没显示选中的item,这是修正前:

修正后:

1、lazarus/lcl/include/customcombobox.inc

将109行的procedure TCustomComboBox.DrawItem添加红色代码:
procedure TCustomComboBox.DrawItem(Index: Integer; ARect: TRect;
  State: TOwnerDrawState);
begin
  //TControlCanvas(FCanvas).UpdateTextFlags;
  //2022.05.28 LBZ
  {$ifdef linux}
  if (FDroppedDown) then
  begin
    if  (GetItemIndex=index)  then   //当为ItemIndex时高亮显示item
    begin
      FCanvas.Brush.Color := clHighlight;
      FCanvas.Font.Color :=  clHighlightText or clHighlight;
      FCanvas.FillRect(ARect);
    end;
    FCanvas.Font.Color:= clMenuText;
  end;
  {$endif}
  //2022.05.28 LBZ
  if Assigned(FOnDrawItem) then
    FOnDrawItem(Self, Index, ARect, State)
  else
  begin
    if not (odBackgroundPainted in State) then
      FCanvas.FillRect(ARect);
    InternalDrawItem(Self, FCanvas, ARect, Items[Index])
  end;
  invalidate;
end;

将1233行function TComboBoxStyleHelper.IsOwnerDrawn改为红色代码

function TComboBoxStyleHelper.IsOwnerDrawn: Boolean;
const
  ArrIsOwnerDrawn: array[TComboBoxStyle] of Boolean = (
    True, // csDropDown //LBZ =false 改为自绘模式 true  2023.2.16
    True, // csSimple   //LBZ =false 改为自绘模式 true  2023.2.16
    True, // csDropDownList //LBZ =false 改为自绘模式 true 2023.2.16
    True,  // csOwnerDrawFixed
    True,  // csOwnerDrawVariable
    True,  // csOwnerDrawEditableFixed
    True   // csOwnerDrawEditableVariable
  );
begin
  Result := ArrIsOwnerDrawn[Self];
end;

2、lazarus/components/ideintf/objectinspector.pp
将3517行的clWindowText改为clMenuText

procedure TOICustomPropertyGrid.ValueComboBoxDrawItem(Control: TWinControl;
  Index: Integer; ARect: TRect; State: TOwnerDrawState);
var
  CurRow: TOIPropertyGridRow;
  ItemValue: string;
  AState: TPropEditDrawState;
  FontColor: TColor;
begin
  if (FItemIndex>=0) and (FItemIndex<FRows.Count) then begin
    CurRow:=Rows[FItemIndex];
    if (Index>=0) and (Index<ValueComboBox.Items.Count) then
      ItemValue:=ValueComboBox.Items[Index]
    else
      ItemValue:='';
    AState:=[];
    if odSelected in State then Include(AState,pedsSelected);
    if odFocused in State then Include(AState,pedsFocused);
    if odComboBoxEdit in State then
      Include(AState,pedsInEdit)
    else
      Include(AState,pedsInComboList);

    if not(odBackgroundPainted in State) then
      ValueComboBox.Canvas.FillRect(ARect);

    FontColor := ValueComboBox.Canvas.Font.Color;
    ValueComboBox.Canvas.Font.Assign(FDefaultValueFont);
    if odSelected in State then
      ValueComboBox.Canvas.Font.Color := FontColor
    else
      ValueComboBox.Canvas.Font.Color:= clMenuText;  //clWindowText LBZ 2023.2.16
    if CurRow.Editor.HasDefaultValue and (ItemValue = CurRow.Editor.GetDefaultValue) then
      ValueComboBox.Canvas.Font.Style := ValueComboBox.Canvas.Font.Style + [fsItalic];
    CurRow.Editor.ListDrawValue(ItemValue,Index,ValueComboBox.Canvas,ARect,AState);
  end;
end;

 

posted on 2023-02-17 11:00  秋·风  阅读(209)  评论(1编辑  收藏  举报