ExCtrls: Split off designtime package. Add float property editor for usage in TFloatSISpinEditEx.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8586 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-11-04 16:27:49 +00:00
parent 6de5c1085d
commit 960452948f
6 changed files with 125 additions and 32 deletions

View File

@@ -3,7 +3,6 @@
<Package Version="5"> <Package Version="5">
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Name Value="ExCtrlsPkg"/> <Name Value="ExCtrlsPkg"/>
<Type Value="RunAndDesignTime"/>
<Author Value="Lazarus team"/> <Author Value="Lazarus team"/>
<CompilerOptions> <CompilerOptions>
<Version Value="11"/> <Version Value="11"/>
@@ -19,7 +18,7 @@
- TRadioButton, TCheckbox, TRadioGroup and TCheckGroup: drawn by ThemeServices/Canvas, not by widgetset, button/text layout, wordwrap, user-provided check images - TRadioButton, TCheckbox, TRadioGroup and TCheckGroup: drawn by ThemeServices/Canvas, not by widgetset, button/text layout, wordwrap, user-provided check images
- TColumnComboBoxEx"/> - TColumnComboBoxEx"/>
<License Value="LGPL with linking exception (like Lazarus LCL)."/> <License Value="LGPL with linking exception (like Lazarus LCL)."/>
<Files Count="8"> <Files Count="7">
<Item1> <Item1>
<Filename Value="source\excheckctrls.pas"/> <Filename Value="source\excheckctrls.pas"/>
<UnitName Value="ExCheckCtrls"/> <UnitName Value="ExCheckCtrls"/>
@@ -29,30 +28,25 @@
<UnitName Value="ExEditCtrls"/> <UnitName Value="ExEditCtrls"/>
</Item2> </Item2>
<Item3> <Item3>
<Filename Value="source\exctrlsreg.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="ExCtrlsReg"/>
</Item3>
<Item4>
<Filename Value="source\exbuttons.pas"/> <Filename Value="source\exbuttons.pas"/>
<UnitName Value="ExButtons"/> <UnitName Value="ExButtons"/>
</Item4> </Item3>
<Item5> <Item4>
<Filename Value="source\excombo.pas"/> <Filename Value="source\excombo.pas"/>
<UnitName Value="ExCombo"/> <UnitName Value="ExCombo"/>
</Item5> </Item4>
<Item6> <Item5>
<Filename Value="source\excheckcombo.pas"/> <Filename Value="source\excheckcombo.pas"/>
<UnitName Value="ExCheckCombo"/> <UnitName Value="ExCheckCombo"/>
</Item6> </Item5>
<Item7> <Item6>
<Filename Value="source\exquestiondlg.pas"/> <Filename Value="source\exquestiondlg.pas"/>
<UnitName Value="ExQuestionDlg"/> <UnitName Value="ExQuestionDlg"/>
</Item7> </Item6>
<Item8> <Item7>
<Filename Value="source\exshape.pas"/> <Filename Value="source\exshape.pas"/>
<UnitName Value="ExShape"/> <UnitName Value="ExShape"/>
</Item8> </Item7>
</Files> </Files>
<CompatibilityMode Value="True"/> <CompatibilityMode Value="True"/>
<LazDoc Paths="fpdoc"/> <LazDoc Paths="fpdoc"/>

View File

@@ -8,16 +8,9 @@ unit ExCtrlsPkg;
interface interface
uses uses
ExCheckCtrls, ExEditCtrls, ExCtrlsReg, ExButtons, ExCombo, ExCheckCombo, ExCheckCtrls, ExEditCtrls, ExButtons, ExCombo, ExCheckCombo, ExQuestionDlg,
ExQuestionDlg, ExShape, LazarusPackageIntf; ExShape;
implementation implementation
procedure Register;
begin
RegisterUnit('ExCtrlsReg', @ExCtrlsReg.Register);
end;
initialization
RegisterPackage('ExCtrlsPkg', @Register);
end. end.

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="5">
<PathDelim Value="\"/>
<Name Value="exctrlspkg_dsgn"/>
<Type Value="DesignTime"/>
<Author Value="Lazarus team"/>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="source"/>
<OtherUnitFiles Value="source"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Description Value="Designtime package for the extended standard controls (ExCtrls) runtime package
"/>
<License Value="LGPL with linking exception (like Lazarus LCL)."/>
<Files>
<Item>
<Filename Value="source\exctrlsreg.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="exctrlsreg"/>
</Item>
</Files>
<RequiredPkgs>
<Item>
<PackageName Value="ExCtrlsPkg"/>
</Item>
<Item>
<PackageName Value="IDEIntf"/>
</Item>
<Item>
<PackageName Value="FCL"/>
</Item>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@@ -0,0 +1,22 @@
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
}
unit exctrlspkg_dsgn;
{$warn 5023 off : no warning about unused units}
interface
uses
exctrlsreg, LazarusPackageIntf;
implementation
procedure Register;
begin
RegisterUnit('exctrlsreg', @exctrlsreg.Register);
end;
initialization
RegisterPackage('exctrlspkg_dsgn', @Register);
end.

View File

@@ -5,18 +5,49 @@ unit ExCtrlsReg;
interface interface
uses uses
Classes, SysUtils; Classes, SysUtils, PropEdits;
type
TFloatSIPropertyEditor = class(TFloatPropertyEditor)
public
function GetValue: ansistring; override;
procedure SetValue(const NewValue: ansistring); override;
end;
procedure Register; procedure Register;
implementation implementation
uses
ExButtons, ExCheckCtrls, ExEditCtrls, ExCombo, ExCheckCombo, ExShape;
{$R exctrlsreg.res} {$R exctrlsreg.res}
uses
ExButtons, ExCheckCtrls, ExEditCtrls, ExCombo, ExCheckCombo, ExShape; //, ExImgList;
function TFloatSIPropertyEditor.GetValue: ansistring;
begin
Result := FormatValue(GetFloatValue);
end;
procedure TFloatSIPropertyEditor.SetValue(const NewValue: ansistring);
var
newVal: String;
prefix: TSIPrefix;
prefixStr: String;
begin
newVal := NewValue;
if TCustomFloatSISpinEditEx.EndsWithSIPrefix(newVal, prefix) then
begin
if prefix <> ONE then
begin
prefixStr := FormatFloat('0e+00', TCustomFloatSISpinEditEx.PrefixFactor(prefix)); // e.g. 'k' --> '1E+03'
Delete(prefixStr, 1, 1); // Delete the '1' from '1E+03' ...
newVal := newVal + prefixStr; // ... and add the rest to the number string
end;
end;
inherited SetValue(newVal)
end;
procedure Register; procedure Register;
begin begin
RegisterComponents('ExCtrls', [ RegisterComponents('ExCtrls', [
@@ -25,8 +56,9 @@ begin
TColumnComboBoxEx, TCheckComboBoxEx, TColumnComboBoxEx, TCheckComboBoxEx,
TShapeEx TShapeEx
]); ]);
end;
RegisterPropertyEditor(TypeInfo(double), TCustomFloatSISpinEditEx, '', TFloatSIPropertyEditor);
end;
end. end.

View File

@@ -186,7 +186,6 @@ type
TCustomFloatSISpinEditEx = class(TCustomFloatSpinEditEx) TCustomFloatSISpinEditEx = class(TCustomFloatSpinEditEx)
private private
function EndsWithSIPrefix(var S: String; out APrefix: TSIPrefix): Boolean;
protected protected
{$IF LCL_FullVersion < 2010000} {$IF LCL_FullVersion < 2010000}
procedure EditKeyPress(var Key: char); override; procedure EditKeyPress(var Key: char); override;
@@ -197,6 +196,8 @@ type
{$IF LCL_FullVersion >= 2010000} {$IF LCL_FullVersion >= 2010000}
function KeyAllowed({%H-}Key: Char): Boolean; override; function KeyAllowed({%H-}Key: Char): Boolean; override;
{$endif} {$endif}
class function EndsWithSIPrefix(var S: String; out APrefix: TSIPrefix): Boolean;
class function PrefixFactor(APrefix: TSIPrefix): double;
end; end;
TFloatSISpinEditEx = class(TCustomFloatSISpinEditEx) TFloatSISpinEditEx = class(TCustomFloatSISpinEditEx)
@@ -539,7 +540,7 @@ end;
{ TCustomFloatSISpinEditEx } { TCustomFloatSISpinEditEx }
function TCustomFloatSISpinEditEx.EndsWithSIPrefix(var S: String; out APrefix: TSIPrefix): Boolean; class function TCustomFloatSISpinEditEx.EndsWithSIPrefix(var S: String; out APrefix: TSIPrefix): Boolean;
var var
PrefixStr: String; PrefixStr: String;
begin begin
@@ -562,6 +563,11 @@ begin
end; end;
{$endif} {$endif}
class function TCustomFloatSISpinEditEx.PrefixFactor(APrefix: TSIPrefix): Double;
begin
Result := SIFactors[APrefix];
end;
function TCustomFloatSISpinEditEx.TextIsNumber(const S: String; out ANumber: Double): Boolean; function TCustomFloatSISpinEditEx.TextIsNumber(const S: String; out ANumber: Double): Boolean;
var var
ValueStr: String; ValueStr: String;