diff --git a/components/ideintf/objectinspector.pp b/components/ideintf/objectinspector.pp index b7a9276e22..aa9b79da86 100644 --- a/components/ideintf/objectinspector.pp +++ b/components/ideintf/objectinspector.pp @@ -1694,7 +1694,8 @@ begin //DebugLn(['TOICustomPropertyGrid.SetItemIndex FCurrentButton.BoundsRect=',dbgs(FCurrentButton.BoundsRect)]); end; NewValue:=NewRow.Editor.GetVisualValue; - if (NewRow.Editor is TBoolPropertyEditor) and FCheckboxForBoolean then + if ((NewRow.Editor is TBoolPropertyEditor) or (NewRow.Editor is TSetElementPropertyEditor)) + and FCheckboxForBoolean then begin FCurrentEdit:=ValueCheckBox; ValueCheckBox.Enabled:=not NewRow.IsReadOnly; diff --git a/components/ideintf/propedits.pp b/components/ideintf/propedits.pp index a681fa06b4..bfb8d3a12b 100644 --- a/components/ideintf/propedits.pp +++ b/components/ideintf/propedits.pp @@ -289,6 +289,9 @@ type FPropCount: Integer; FPropList: PInstPropList; function GetPrivateDirectory: ansistring; + protected + // Draw Checkbox for Boolean and Set element editors. + function DrawCheckbox(ACanvas: TCanvas; const ARect: TRect; IsTrue: Boolean): TRect; public constructor Create(Hook:TPropertyEditorHook; APropCount:Integer); virtual; destructor Destroy; override; @@ -538,9 +541,13 @@ type function GetAttributes: TPropertyAttributes; override; function GetName: shortstring; override; function GetValue: ansistring; override; + function GetVerbCount: Integer; override; + function GetVisualValue: ansistring; override; procedure GetValues(Proc: TGetStrProc); override; procedure SetValue(const NewValue: ansistring); override; function IsNotDefaultValue: boolean; override; + procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect; + AState: TPropEditDrawState); override; end; { TSetPropertyEditor @@ -553,6 +560,7 @@ type function GetAttributes: TPropertyAttributes; override; function GetEditLimit: Integer; override; procedure GetProperties(Proc: TGetPropEditProc); override; + procedure SetValue(const NewValue: ansistring); override; function OrdValueToVisualValue(OrdValue: longint): string; override; end; @@ -2358,6 +2366,40 @@ begin Result:=True; end; +function TPropertyEditor.DrawCheckbox(ACanvas: TCanvas; const ARect: TRect; + IsTrue: Boolean): TRect; +// Draws a Checkbox using theme services for editing booleans. +// Returns the output rectangle adjusted for new text location. +var + Details: TThemedElementDetails; + Check: TThemedButton; + Sz: TSize; + TopMargin: Integer; + VisVal: String; +begin + VisVal := GetVisualValue; + // Draw the box using theme services. + if (VisVal = '') or (VisVal = oisMixed) then + Check := tbCheckBoxMixedNormal + else if IsTrue then + Check := tbCheckBoxCheckedNormal + else + Check := tbCheckBoxUncheckedNormal; + Details := ThemeServices.GetElementDetails(Check); + Sz := ThemeServices.GetDetailSize(Details); + TopMargin := (ARect.Bottom - ARect.Top - Sz.cy) div 2; + Result := ARect; + Inc(Result.Top, TopMargin); + // Left varies by widgetset and theme etc. Real Checkbox itself has a left margin. + Inc(Result.Left, 2); // ToDo: How to find out the real margin? + Result.Right := Result.Left + Sz.cx; + Result.Bottom := Result.Top + Sz.cy; + ThemeServices.DrawElement(ACanvas.Handle, Details, Result, nil); + // Text will be written after the box. + Result := ARect; + Inc(Result.Left, Sz.cx + 4); +end; + function TPropertyEditor.GetAttributes: TPropertyAttributes; begin Result:=[paMultiSelect,paRevertable]; @@ -2548,8 +2590,7 @@ begin Result:=GetSetProp(Instance,PropInfo,Brackets); end; -function TPropertyEditor.GetSetValueAt(Index: Integer; Brackets: boolean - ): AnsiString; +function TPropertyEditor.GetSetValueAt(Index: Integer; Brackets: boolean): AnsiString; begin with FPropList^[Index] do Result:=GetSetProp(Instance,PropInfo,Brackets); @@ -2770,7 +2811,7 @@ begin with FPropList^[I] do Changed := Changed or (GetOrdProp(Instance, PropInfo) <> NewValue); if Changed then begin - for I:=0 to FPropCount-1 do + for I := 0 to FPropCount - 1 do with FPropList^[I] do SetOrdProp(Instance, PropInfo, NewValue); Modified; end; @@ -3264,38 +3305,13 @@ end; procedure TBoolPropertyEditor.PropDrawValue(ACanvas: TCanvas; const ARect: TRect; AState: TPropEditDrawState); var - BRect: TRect; - Details: TThemedElementDetails; - Check: TThemedButton; - Sz: TSize; - TopMargin: Integer; - VisVal: String; + TxtRect: TRect; begin - BRect := ARect; if FPropertyHook.GetCheckboxForBoolean then - begin - VisVal := GetVisualValue; - // Draw the box using theme services. - if (VisVal = '') or (VisVal = oisMixed) then - Check := tbCheckBoxMixedNormal - else if GetOrdValue <> 0 then - Check := tbCheckBoxCheckedNormal - else - Check := tbCheckBoxUncheckedNormal; - Details := ThemeServices.GetElementDetails(Check); - Sz := ThemeServices.GetDetailSize(Details); - TopMargin := (ARect.Bottom - ARect.Top - Sz.cy) div 2; - Inc(BRect.Top, TopMargin); - // Left varies by widgetset and theme etc. Real Checkbox itself has a left margin. - Inc(BRect.Left, 2); // ToDo: How to find out the real margin? - BRect.Right := BRect.Left + Sz.cx; - BRect.Bottom := BRect.Top + Sz.cy; - ThemeServices.DrawElement(ACanvas.Handle, Details, BRect, nil); - // Write text after the box - BRect := ARect; - Inc(BRect.Left, Sz.cx + 4); - end; - inherited PropDrawValue(ACanvas, BRect, AState); + TxtRect := DrawCheckbox(ACanvas, ARect, GetOrdValue<>0) + else + TxtRect := ARect; + inherited PropDrawValue(ACanvas, TxtRect, AState); end; { TInt64PropertyEditor } @@ -3500,6 +3516,20 @@ var begin Integer(S) := GetOrdValue; Result := BooleanIdents[FElement in S]; + if FPropertyHook.GetCheckboxForBoolean then + Result := '(' + Result + ')'; +end; + +function TSetElementPropertyEditor.GetVerbCount: Integer; +begin + Result:=0; +end; + +function TSetElementPropertyEditor.GetVisualValue: ansistring; +begin + Result := inherited GetVisualValue; + if Result = '' then + Result := oisMixed; end; procedure TSetElementPropertyEditor.GetValues(Proc: TGetStrProc); @@ -3513,7 +3543,8 @@ var S: TIntegerSet; begin Integer(S) := GetOrdValue; - if CompareText(NewValue, 'True') = 0 then + if (CompareText(NewValue, 'True') = 0) + or (CompareText(NewValue, '(True)') = 0) then Include(S, FElement) else Exclude(S, FElement); @@ -3533,6 +3564,22 @@ begin end; end; +procedure TSetElementPropertyEditor.PropDrawValue(ACanvas: TCanvas; const ARect: TRect; + AState: TPropEditDrawState); +var + S: TIntegerSet; + TxtRect: TRect; +begin + if FPropertyHook.GetCheckboxForBoolean then + begin + Integer(S) := GetOrdValue; + TxtRect := DrawCheckbox(ACanvas, ARect, FElement in S); + end + else + TxtRect := ARect; + inherited PropDrawValue(ACanvas, TxtRect, AState); +end; + { TSetPropertyEditor } function TSetPropertyEditor.GetAttributes: TPropertyAttributes; @@ -3556,6 +3603,20 @@ begin Proc(TSetElementPropertyEditor.Create(Self, I)); end; +procedure TSetPropertyEditor.SetValue(const NewValue: ansistring); +var + S: TIntegerSet; + TypeInfo: PTypeInfo; + I: Integer; +begin + S := []; + TypeInfo := GetTypeData(GetPropType)^.CompType; + for I := 0 to SizeOf(Integer) * 8 - 1 do + if Pos(GetEnumName(TypeInfo, I), NewValue) > 0 then + Include(S, I); + SetOrdValue(Integer(S)); +end; + function TSetPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string; var S: TIntegerSet;