mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 13:19:21 +02:00
IdeIntf: Improve and harmonize the drawing of Boolean Checkboxes.
git-svn-id: trunk@52622 -
This commit is contained in:
parent
96e287106e
commit
d5d8e2f420
@ -2726,9 +2726,6 @@ begin
|
|||||||
// resize the edit component
|
// resize the edit component
|
||||||
if (FCurrentEdit is TEdit) or (FCurrentEdit is TComboBox) then
|
if (FCurrentEdit is TEdit) or (FCurrentEdit is TComboBox) then
|
||||||
begin
|
begin
|
||||||
{$IFnDEF LCLGTK2}
|
|
||||||
Dec(EditCompRect.Left);
|
|
||||||
{$ENDIF}
|
|
||||||
Dec(EditCompRect.Top);
|
Dec(EditCompRect.Top);
|
||||||
{$IFDEF UseOINormalCheckBox}
|
{$IFDEF UseOINormalCheckBox}
|
||||||
end
|
end
|
||||||
@ -2736,7 +2733,11 @@ begin
|
|||||||
begin
|
begin
|
||||||
with EditCompRect do // Align "normal" CheckBox to the middle vertically
|
with EditCompRect do // Align "normal" CheckBox to the middle vertically
|
||||||
Inc(Top, (Bottom - Top - ValueCheckBox.Height) div 2);
|
Inc(Top, (Bottom - Top - ValueCheckBox.Height) div 2);
|
||||||
Inc(EditCompRect.Left); // and move it a little right.
|
{$ELSE}
|
||||||
|
end
|
||||||
|
else if FCurrentEdit is TCheckBoxThemed then
|
||||||
|
begin // Move right as much as in TPropertyEditor.DrawCheckValue.
|
||||||
|
Inc(EditCompRect.Left, CheckBoxThemedLeftOffs);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
//debugln('TOICustomPropertyGrid.AlignEditComponents A ',dbgsName(FCurrentEdit),' ',dbgs(EditCompRect));
|
//debugln('TOICustomPropertyGrid.AlignEditComponents A ',dbgsName(FCurrentEdit),' ',dbgs(EditCompRect));
|
||||||
|
@ -40,6 +40,7 @@ uses
|
|||||||
|
|
||||||
const
|
const
|
||||||
MaxIdentLength: Byte = 63;
|
MaxIdentLength: Byte = 63;
|
||||||
|
CheckBoxThemedLeftOffs = 3;
|
||||||
|
|
||||||
{$IFDEF LCLCarbon}
|
{$IFDEF LCLCarbon}
|
||||||
// LineFeed symbol (UTF8) to maintain linefeeds in multiline text for Carbon TEdit.
|
// LineFeed symbol (UTF8) to maintain linefeeds in multiline text for Carbon TEdit.
|
||||||
@ -303,6 +304,8 @@ type
|
|||||||
protected
|
protected
|
||||||
// Draw Checkbox for Boolean and Set element editors.
|
// Draw Checkbox for Boolean and Set element editors.
|
||||||
function DrawCheckbox(ACanvas: TCanvas; const ARect: TRect; IsTrue: Boolean): TRect;
|
function DrawCheckbox(ACanvas: TCanvas; const ARect: TRect; IsTrue: Boolean): TRect;
|
||||||
|
function DrawCheckValue(ACanvas: TCanvas; const ARect: TRect;
|
||||||
|
AState: TPropEditDrawState; IsTrue: Boolean): TRect;
|
||||||
public
|
public
|
||||||
constructor Create(Hook:TPropertyEditorHook; APropCount:Integer); virtual;
|
constructor Create(Hook:TPropertyEditorHook; APropCount:Integer); virtual;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -2405,6 +2408,7 @@ function TPropertyEditor.DrawCheckbox(ACanvas: TCanvas; const ARect: TRect;
|
|||||||
var
|
var
|
||||||
Details: TThemedElementDetails;
|
Details: TThemedElementDetails;
|
||||||
Check: TThemedButton;
|
Check: TThemedButton;
|
||||||
|
BRect: TRect;
|
||||||
Sz: TSize;
|
Sz: TSize;
|
||||||
TopMargin: Integer;
|
TopMargin: Integer;
|
||||||
VisVal: String;
|
VisVal: String;
|
||||||
@ -2420,18 +2424,55 @@ begin
|
|||||||
Details := ThemeServices.GetElementDetails(Check);
|
Details := ThemeServices.GetElementDetails(Check);
|
||||||
Sz := ThemeServices.GetDetailSize(Details);
|
Sz := ThemeServices.GetDetailSize(Details);
|
||||||
TopMargin := (ARect.Bottom - ARect.Top - Sz.cy) div 2;
|
TopMargin := (ARect.Bottom - ARect.Top - Sz.cy) div 2;
|
||||||
Result := ARect;
|
BRect := ARect;
|
||||||
Inc(Result.Top, TopMargin);
|
|
||||||
// Left varies by widgetset and theme etc. Real Checkbox itself has a left margin.
|
// 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?
|
Inc(BRect.Left, 3); // ToDo: How to find out the real margin?
|
||||||
Result.Right := Result.Left + Sz.cx;
|
Result := BRect; // Result Rect will be used for text.
|
||||||
Result.Bottom := Result.Top + Sz.cy;
|
Inc(BRect.Top, TopMargin);
|
||||||
ThemeServices.DrawElement(ACanvas.Handle, Details, Result, nil);
|
BRect.Right := BRect.Left + Sz.cx;
|
||||||
|
BRect.Bottom := BRect.Top + Sz.cy;
|
||||||
|
ThemeServices.DrawElement(ACanvas.Handle, Details, BRect, nil);
|
||||||
// Text will be written after the box.
|
// Text will be written after the box.
|
||||||
Result := ARect;
|
|
||||||
Inc(Result.Left, Sz.cx + 4);
|
Inc(Result.Left, Sz.cx + 4);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPropertyEditor.DrawCheckValue(ACanvas: TCanvas; const ARect: TRect;
|
||||||
|
AState: TPropEditDrawState; IsTrue: Boolean): TRect;
|
||||||
|
// Draws Boolean value as text or Checkbox depending on user setting from PropertyHook.
|
||||||
|
// Uses either theme services (func DrawCheckbox) or TCheckBoxThemed depending
|
||||||
|
// on UseOINormalCheckBox define.
|
||||||
|
// Returns Rect for textual part if it must be drawn, otherwise Result.Top = -100.
|
||||||
|
{$IFnDEF UseOINormalCheckBox}
|
||||||
|
var
|
||||||
|
BRect: TRect;
|
||||||
|
VisVal: string;
|
||||||
|
stat: TCheckBoxState;
|
||||||
|
{$ENDIF}
|
||||||
|
begin
|
||||||
|
Result.Top := 0;
|
||||||
|
if FPropertyHook.GetCheckboxForBoolean then
|
||||||
|
begin // Checkbox for Booleans.
|
||||||
|
{$IFnDEF UseOINormalCheckBox}
|
||||||
|
Result.Top := -100; // No need to call PropDrawValue further.
|
||||||
|
BRect := ARect;
|
||||||
|
Inc(BRect.Left, CheckBoxThemedLeftOffs);
|
||||||
|
VisVal := GetVisualValue;
|
||||||
|
if (VisVal = '') or (VisVal = oisMixed) then
|
||||||
|
stat := cbGrayed
|
||||||
|
else if VisVal = '(True)' then
|
||||||
|
stat := cbChecked
|
||||||
|
else
|
||||||
|
stat := cbUnchecked;
|
||||||
|
TCheckBoxThemed.PaintSelf(ACanvas, VisVal, BRect, stat, False, False, False,
|
||||||
|
False, taRightJustify);
|
||||||
|
{$ELSE}
|
||||||
|
Result := DrawCheckbox(ACanvas, ARect, IsTrue);
|
||||||
|
{$ENDIF}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := ARect; // Classic Combobox for Booleans.
|
||||||
|
end;
|
||||||
|
|
||||||
function TPropertyEditor.GetAttributes: TPropertyAttributes;
|
function TPropertyEditor.GetAttributes: TPropertyAttributes;
|
||||||
begin
|
begin
|
||||||
Result:=[paMultiSelect,paRevertable];
|
Result:=[paMultiSelect,paRevertable];
|
||||||
@ -3505,29 +3546,8 @@ procedure TBoolPropertyEditor.PropDrawValue(ACanvas: TCanvas; const ARect: TRect
|
|||||||
AState: TPropEditDrawState);
|
AState: TPropEditDrawState);
|
||||||
var
|
var
|
||||||
TxtRect: TRect;
|
TxtRect: TRect;
|
||||||
{$IFnDEF UseOINormalCheckBox}
|
|
||||||
VisVal: string;
|
|
||||||
stat: TCheckBoxState;
|
|
||||||
{$ENDIF}
|
|
||||||
begin
|
begin
|
||||||
if FPropertyHook.GetCheckboxForBoolean then
|
TxtRect := DrawCheckValue(ACanvas, ARect, AState, GetOrdValue<>0);
|
||||||
begin // Checkbox for Booleans.
|
|
||||||
{$IFnDEF UseOINormalCheckBox}
|
|
||||||
TxtRect.Top := -100; // Don't call inherited PropDrawValue
|
|
||||||
VisVal := GetVisualValue;
|
|
||||||
if (VisVal = '') or (VisVal = oisMixed) then
|
|
||||||
stat := cbGrayed
|
|
||||||
else if VisVal = '(True)' then
|
|
||||||
stat := cbChecked
|
|
||||||
else
|
|
||||||
stat := cbUnchecked;
|
|
||||||
TCheckBoxThemed.PaintSelf(ACanvas, VisVal, ARect, stat, False, False, False, False, taRightJustify);
|
|
||||||
{$ELSE}
|
|
||||||
TxtRect := DrawCheckbox(ACanvas, ARect, GetOrdValue<>0);
|
|
||||||
{$ENDIF}
|
|
||||||
end
|
|
||||||
else
|
|
||||||
TxtRect := ARect; // Classic Combobox for Booleans.
|
|
||||||
if TxtRect.Top <> -100 then
|
if TxtRect.Top <> -100 then
|
||||||
inherited PropDrawValue(ACanvas, TxtRect, AState);
|
inherited PropDrawValue(ACanvas, TxtRect, AState);
|
||||||
end;
|
end;
|
||||||
@ -3757,8 +3777,7 @@ end;
|
|||||||
function TSetElementPropertyEditor.GetVisualValue: ansistring;
|
function TSetElementPropertyEditor.GetVisualValue: ansistring;
|
||||||
begin
|
begin
|
||||||
Result := inherited GetVisualValue;
|
Result := inherited GetVisualValue;
|
||||||
if Result = '' then
|
Assert(Result <> '', 'TSetElementPropertyEditor.GetVisualValue: Result="".');
|
||||||
Result := oisMixed;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSetElementPropertyEditor.GetValues(Proc: TGetStrProc);
|
procedure TSetElementPropertyEditor.GetValues(Proc: TGetStrProc);
|
||||||
@ -3799,14 +3818,10 @@ var
|
|||||||
S: TIntegerSet;
|
S: TIntegerSet;
|
||||||
TxtRect: TRect;
|
TxtRect: TRect;
|
||||||
begin
|
begin
|
||||||
if FPropertyHook.GetCheckboxForBoolean then
|
Integer(S) := GetOrdValue;
|
||||||
begin
|
TxtRect := DrawCheckValue(ACanvas, ARect, AState, FElement in S);
|
||||||
Integer(S) := GetOrdValue;
|
if TxtRect.Top <> -100 then
|
||||||
TxtRect := DrawCheckbox(ACanvas, ARect, FElement in S);
|
inherited PropDrawValue(ACanvas, TxtRect, AState);
|
||||||
end
|
|
||||||
else
|
|
||||||
TxtRect := ARect;
|
|
||||||
inherited PropDrawValue(ACanvas, TxtRect, AState);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TSetPropertyEditor }
|
{ TSetPropertyEditor }
|
||||||
|
Loading…
Reference in New Issue
Block a user