diff --git a/components/jujiboutils/changes.txt b/components/jujiboutils/changes.txt index 4ae9525cd..9874eda99 100644 --- a/components/jujiboutils/changes.txt +++ b/components/jujiboutils/changes.txt @@ -6,6 +6,8 @@ Note: Lazarus Trunk required Version pre-1.0 -------------------------------------------------- 2011-09-27 Added: ftDateTime support to TJDBGridControl + TJFloatEdit, TJLabeledFloatEdit + Examplenodb updated 2011-09-26 Added: TJDateTimeEdit, TJLabeledDateTimeEdit TJDBDateTimeEdit, TJDBLabeledDateTimeEdit 2011-09-23 Added: TJDBLabeledEdit, TJTimeEdit, TJLabeledTimeEdit, diff --git a/components/jujiboutils/jujibo-utils/examplenodb/main.lfm b/components/jujiboutils/jujibo-utils/examplenodb/main.lfm index 398548b86..4f3fb503f 100644 --- a/components/jujiboutils/jujibo-utils/examplenodb/main.lfm +++ b/components/jujiboutils/jujibo-utils/examplenodb/main.lfm @@ -1,11 +1,11 @@ object Form1: TForm1 - Left = 378 + Left = 365 Height = 295 - Top = 196 - Width = 332 + Top = 260 + Width = 419 Caption = 'Example' ClientHeight = 295 - ClientWidth = 332 + ClientWidth = 419 LCLVersion = '0.9.31' object Label1: TLabel Left = 8 @@ -22,10 +22,10 @@ object Form1: TForm1 Left = 24 Height = 82 Top = 40 - Width = 288 + Width = 375 Caption = 'Labeled controls' ClientHeight = 63 - ClientWidth = 284 + ClientWidth = 371 TabOrder = 0 object JLabeledIntegerEdit1: TJLabeledIntegerEdit Left = 14 @@ -35,11 +35,13 @@ object Form1: TForm1 DisplayFormat = '0' Value = 0 EditLabel.AnchorSideLeft.Control = JLabeledIntegerEdit1 + EditLabel.AnchorSideRight.Control = JLabeledIntegerEdit1 + EditLabel.AnchorSideRight.Side = asrBottom EditLabel.AnchorSideBottom.Control = JLabeledIntegerEdit1 EditLabel.Left = 14 EditLabel.Height = 18 EditLabel.Top = 2 - EditLabel.Width = 45 + EditLabel.Width = 80 EditLabel.Caption = 'Integer' EditLabel.ParentColor = False TabOrder = 0 @@ -53,11 +55,13 @@ object Form1: TForm1 Decimals = 2 Value = 0 EditLabel.AnchorSideLeft.Control = JLabeledCurrencyEdit1 + EditLabel.AnchorSideRight.Control = JLabeledCurrencyEdit1 + EditLabel.AnchorSideRight.Side = asrBottom EditLabel.AnchorSideBottom.Control = JLabeledCurrencyEdit1 EditLabel.Left = 102 EditLabel.Height = 18 EditLabel.Top = 2 - EditLabel.Width = 55 + EditLabel.Width = 80 EditLabel.Caption = 'Currency' EditLabel.ParentColor = False TabOrder = 1 @@ -70,24 +74,46 @@ object Form1: TForm1 DisplayFormat = 'dd/mm/yy' Value = 0 EditLabel.AnchorSideLeft.Control = JLabeledDateEdit1 + EditLabel.AnchorSideRight.Control = JLabeledDateEdit1 + EditLabel.AnchorSideRight.Side = asrBottom EditLabel.AnchorSideBottom.Control = JLabeledDateEdit1 EditLabel.Left = 190 EditLabel.Height = 18 EditLabel.Top = 1 - EditLabel.Width = 29 + EditLabel.Width = 80 EditLabel.Caption = 'Date' EditLabel.ParentColor = False TabOrder = 2 end + object JLabeledFloatEdit1: TJLabeledFloatEdit + Left = 280 + Height = 27 + Top = 23 + Width = 80 + DisplayFormat = '#,0.00' + Decimals = 2 + Value = 0 + EditLabel.AnchorSideLeft.Control = JLabeledFloatEdit1 + EditLabel.AnchorSideRight.Control = JLabeledFloatEdit1 + EditLabel.AnchorSideRight.Side = asrBottom + EditLabel.AnchorSideBottom.Control = JLabeledFloatEdit1 + EditLabel.Left = 280 + EditLabel.Height = 18 + EditLabel.Top = 2 + EditLabel.Width = 80 + EditLabel.Caption = 'Float' + EditLabel.ParentColor = False + TabOrder = 3 + end end object GroupBox2: TGroupBox Left = 24 Height = 105 Top = 128 - Width = 288 + Width = 376 Caption = 'Normal Controls' ClientHeight = 86 - ClientWidth = 284 + ClientWidth = 372 TabOrder = 1 object JIntegerEdit1: TJIntegerEdit Left = 14 @@ -117,9 +143,19 @@ object Form1: TForm1 Value = 0 TabOrder = 2 end + object JFloatEdit1: TJFloatEdit + Left = 280 + Height = 27 + Top = 24 + Width = 80 + DisplayFormat = '#,0.00' + Decimals = 2 + Value = 0 + TabOrder = 3 + end end object BitBtn1: TBitBtn - Left = 221 + Left = 308 Height = 30 Top = 249 Width = 91 diff --git a/components/jujiboutils/jujibo-utils/examplenodb/main.pas b/components/jujiboutils/jujibo-utils/examplenodb/main.pas index 2a290cb03..dcad2e6e8 100644 --- a/components/jujiboutils/jujibo-utils/examplenodb/main.pas +++ b/components/jujiboutils/jujibo-utils/examplenodb/main.pas @@ -7,7 +7,8 @@ interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons, JIntegerEdit, JLabeledIntegerEdit, JCurrencyEdit, - JLabeledCurrencyEdit, JDateEdit, JLabeledDateEdit; + JLabeledCurrencyEdit, JDateEdit, JLabeledDateEdit, JFloatEdit, + JLabeledFloatEdit; type @@ -19,9 +20,11 @@ type GroupBox2: TGroupBox; JCurrencyEdit1: TJCurrencyEdit; JDateEdit1: TJDateEdit; + JFloatEdit1: TJFloatEdit; JIntegerEdit1: TJIntegerEdit; JLabeledCurrencyEdit1: TJLabeledCurrencyEdit; JLabeledDateEdit1: TJLabeledDateEdit; + JLabeledFloatEdit1: TJLabeledFloatEdit; JLabeledIntegerEdit1: TJLabeledIntegerEdit; JLabeledIntegerEdit2: TJLabeledIntegerEdit; Label1: TLabel; diff --git a/components/jujiboutils/jujibo-utils/examplenodb/testnodb.lpi b/components/jujiboutils/jujibo-utils/examplenodb/testnodb.lpi index 9b2e36a78..31e2546e7 100644 --- a/components/jujiboutils/jujibo-utils/examplenodb/testnodb.lpi +++ b/components/jujiboutils/jujibo-utils/examplenodb/testnodb.lpi @@ -6,7 +6,6 @@ - @@ -61,6 +60,10 @@ + + + + diff --git a/components/jujiboutils/jujibo-utils/jujibocontrols.lpk b/components/jujiboutils/jujibo-utils/jujibocontrols.lpk index eb3ad0893..81e0436db 100644 --- a/components/jujiboutils/jujibo-utils/jujibocontrols.lpk +++ b/components/jujiboutils/jujibo-utils/jujibocontrols.lpk @@ -18,7 +18,7 @@ - + @@ -137,6 +137,16 @@ + + + + + + + + + + diff --git a/components/jujiboutils/jujibo-utils/jujibocontrols.pas b/components/jujiboutils/jujibo-utils/jujibocontrols.pas index a06bc1734..ba8406eff 100644 --- a/components/jujiboutils/jujibo-utils/jujibocontrols.pas +++ b/components/jujiboutils/jujibo-utils/jujibocontrols.pas @@ -12,8 +12,8 @@ uses JIntegerEdit, JLabeledIntegerEdit, JCurrencyEdit, JLabeledCurrencyEdit, JDateEdit, JLabeledDateEdit, JDBGridControl, jdbgridutils, JDBLabeledEdit, JTimeEdit, JLabeledTimeEdit, JDBTimeEdit, JDBLabeledTimeEdit, JDateTimeEdit, - JLabeledDateTimeEdit, JDBDateTimeEdit, JDBLabeledDateTimeEdit, - LazarusPackageIntf; + JLabeledDateTimeEdit, JDBDateTimeEdit, JDBLabeledDateTimeEdit, JFloatEdit, + JLabeledFloatEdit, LazarusPackageIntf; implementation @@ -41,6 +41,8 @@ begin RegisterUnit('JLabeledDateTimeEdit', @JLabeledDateTimeEdit.Register); RegisterUnit('JDBDateTimeEdit', @JDBDateTimeEdit.Register); RegisterUnit('JDBLabeledDateTimeEdit', @JDBLabeledDateTimeEdit.Register); + RegisterUnit('JFloatEdit', @JFloatEdit.Register); + RegisterUnit('JLabeledFloatEdit', @JLabeledFloatEdit.Register); end; initialization diff --git a/components/jujiboutils/jujibo-utils/src/jfloatedit.pas b/components/jujiboutils/jujibo-utils/src/jfloatedit.pas new file mode 100644 index 000000000..17a4c0550 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jfloatedit.pas @@ -0,0 +1,227 @@ +{ JFloatEdit + + Copyright (C) 2011 Julio Jiménez Borreguero + Contact: jujibo at gmail dot com + + This library is free software; you can redistribute it and/or modify it + under the same terms as the Lazarus Component Library (LCL) + + See the file license-jujiboutils.txt and COPYING.LGPL, included in this distribution, + for details about the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +} + +unit JFloatEdit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, LResources, Forms, Controls, StdCtrls, Graphics, Dialogs; + +type + + { TJFloatEdit } + + TJFloatEdit = class(TCustomEdit) + private + { Private declarations } + theValue: double; + fFormat: string; + fDecimals: integer; + function getDecimals: integer; + function getFormat: string; + function getValue: double; + procedure formatInput; + procedure setDecimals(const AValue: integer); + procedure setFormat(const AValue: string); + function scaleTo(const AValue: double; const NDecimals: integer): double; + function IsValidFloat(const Value: string): boolean; + procedure setValue(const AValue: double); + protected + { Protected declarations } + procedure DoEnter; override; + procedure DoExit; override; + procedure KeyPress(var Key: char); override; + public + { Public declarations } + constructor Create(TheOwner: TComponent); override; + destructor Destroy; override; + published + { Published declarations } + property DisplayFormat: string read getFormat write setFormat; + property Decimals: integer read getDecimals write setDecimals; + property Value: double read getValue write setValue; + + property Action; + property Align; + property Alignment; + property Anchors; + property AutoSize; + property AutoSelect; + property BidiMode; + property BorderStyle; + property BorderSpacing; + property CharCase; + property Color; + property Constraints; + property DragCursor; + property DragKind; + property DragMode; + property Enabled; + property Font; + property HideSelection; + property MaxLength; + property ParentBidiMode; + property OnChange; + property OnChangeBounds; + property OnClick; + property OnContextPopup; + property OnDblClick; + property OnDragDrop; + property OnDragOver; + property OnEditingDone; + property OnEndDrag; + property OnEnter; + property OnExit; + property OnKeyDown; + property OnKeyPress; + property OnKeyUp; + property OnMouseDown; + property OnMouseEnter; + property OnMouseLeave; + property OnMouseMove; + property OnMouseUp; + property OnResize; + property OnStartDrag; + property OnUTF8KeyPress; + property ParentColor; + property ParentFont; + property ParentShowHint; + property PopupMenu; + property ShowHint; + property TabStop; + property TabOrder; + property Visible; + end; + +procedure Register; + +implementation + +uses + Math; + +procedure Register; +begin + {$I jfloatedit_icon.lrs} + RegisterComponents('Additional', [TJFloatEdit]); +end; + + +function TJFloatEdit.getDecimals: integer; +begin + Result := fDecimals; +end; + +function TJFloatEdit.getFormat: string; +begin + Result := fFormat; +end; + +function TJFloatEdit.getValue: double; +begin + Result := theValue; +end; + +procedure TJFloatEdit.formatInput; +begin + Caption := FormatFloat(DisplayFormat, theValue); +end; + +procedure TJFloatEdit.setDecimals(const AValue: integer); +begin + if (AValue >= 0) and (AValue < 12) then + fDecimals := AValue; +end; + +procedure TJFloatEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + formatInput; +end; + +function TJFloatEdit.scaleTo(const AValue: double; const NDecimals: integer): double; +begin + Result := round(AValue * power(10, NDecimals)) / power(10, NDecimals); +end; + +function TJFloatEdit.IsValidFloat(const Value: string): boolean; +begin + if StrToFloatDef(Value, MaxDouble) = MaxDouble then + Result := False + else + Result := True; +end; + +procedure TJFloatEdit.setValue(const AValue: double); +begin + theValue := scaleTo(AValue, fDecimals); + formatInput; +end; + +procedure TJFloatEdit.DoEnter; +begin + inherited DoEnter; + Text := FloatToStr(theValue); + SelectAll; +end; + +procedure TJFloatEdit.DoExit; +begin + inherited DoExit; + if IsValidFloat(Text) then + theValue := StrToCurr(Text) + else + begin + ShowMessage(Text + ' no es un valor válido'); + SetFocus; + end; + theValue := scaleTo(theValue, fDecimals); + formatInput; +end; + +procedure TJFloatEdit.KeyPress(var Key: char); +begin + if (Key in ['.', ',']) then + Key := Decimalseparator; + if (key = DecimalSeparator) and (Pos(key, Text) > 0) then + key := #0; + if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then + Key := #0; + if (Key = DecimalSeparator) and (fDecimals = 0) then + Key := #0; + inherited KeyPress(Key); +end; + +constructor TJFloatEdit.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + Text := ''; + fFormat := '#,0.00'; + fDecimals := 2; + formatInput; +end; + +destructor TJFloatEdit.Destroy; +begin + inherited Destroy; +end; + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/jfloatedit_icon.lrs b/components/jujiboutils/jujibo-utils/src/jfloatedit_icon.lrs new file mode 100644 index 000000000..320d5eb3d --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jfloatedit_icon.lrs @@ -0,0 +1,28 @@ +LazarusResources.Add('tjfloatedit','PNG',[ + #137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0 + +#0#0#1'sRGB'#0#174#206#28#233#0#0#0#6'bKGD'#0#255#0#255#0#255#160#189#167#147 + +#0#0#0#9'pHYs'#0#0#11#19#0#0#11#19#1#0#154#156#24#0#0#0#7'tIME'#7#219#9#27#9 + +'.'#16'''D'#214'd'#0#0#2#10'IDATH'#199#213#150#177'K[Q'#20#198#127'7'#20#165 + +#208#198#208'6'#9#14#169#24'('#13'4'#218'!'#143#130#4#151#184#149#254#1'B' + +#160'C'#168'S'#135#210'%'#14'Bqq'#200'RZ'#232'&'#14#14#162'k'#161#29#179#212 + +'HA2E'#133'BhPCZH'#197'&'#209#130#6#243'N'#135#246#166'/'#230#5#243#162#25 + +#250#193#229#190#243#184'|'#223#185#223'9'#239#240#148#136#208'O\'#179#6'k' + +#235#223'Y'#252'P'#176'=8'#243'$'#200#244#228#176'c'#1'%"-'#196'o'#159'?$|' + +#247#6#219#251#199#148'+'#167#148#171'u'#202#149'S'#222'gJ='#9')'#17'ajv'#131 + +#241'{'#183#24#245'_''O'#16#160#141'<' + +#151'?D'#159#237#169#6#19'c^|C'#3#29'k01'#230'm'#222#194#177'@'#161'X'#195 + +#239#241#2'0'#23#15#17#27#191#221'V'#131'r'#181#142'>'#235'X '#24'p'#179#185 + +'s@'#195#20#194'#!'#219#131#159#183'~\'#206#162'G'#15#238#224#27#26'`a'#229 + +#11#11'+'#255#145'EJD'#152'y'#183#197'^'#233#136#134')'#204#197'C'#236'f?^' + +#201#231#157'H= 0) and (AValue < 12) then + fDecimals := AValue; +end; + +procedure TJLabeledFloatEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + formatInput; +end; + +function TJLabeledFloatEdit.scaleTo(const AValue: double; + const NDecimals: integer): double; +begin + Result := round(AValue * power(10, NDecimals)) / power(10, NDecimals); +end; + +function TJLabeledFloatEdit.IsValidFloat(const Value: string): boolean; +begin + if StrToFloatDef(Value, MaxDouble) = MaxDouble then + Result := False + else + Result := True; +end; + +procedure TJLabeledFloatEdit.setValue(const AValue: double); +begin + theValue := scaleTo(AValue, fDecimals); + formatInput; +end; + +procedure TJLabeledFloatEdit.DoEnter; +begin + inherited DoEnter; + Text := FloatToStr(theValue); + SelectAll; +end; + +procedure TJLabeledFloatEdit.DoExit; +begin + inherited DoExit; + if IsValidFloat(Text) then + theValue := StrToCurr(Text) + else + begin + ShowMessage(Text + ' no es un valor válido'); + SetFocus; + end; + theValue := scaleTo(theValue, fDecimals); + formatInput; +end; + +procedure TJLabeledFloatEdit.KeyPress(var Key: char); +begin + if (Key in ['.', ',']) then + Key := Decimalseparator; + if (key = DecimalSeparator) and (Pos(key, Text) > 0) then + key := #0; + if not (Key in ['0'..'9', DecimalSeparator, '+', '-', #8, #9]) then + Key := #0; + if (Key = DecimalSeparator) and (fDecimals = 0) then + Key := #0; + inherited KeyPress(Key); +end; + +constructor TJLabeledFloatEdit.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + Text := ''; + fFormat := '#,0.00'; + fDecimals := 2; + formatInput; +end; + +destructor TJLabeledFloatEdit.Destroy; +begin + inherited Destroy; +end; + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/jlabeledfloatedit_icon.lrs b/components/jujiboutils/jujibo-utils/src/jlabeledfloatedit_icon.lrs new file mode 100644 index 000000000..6d02f5000 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jlabeledfloatedit_icon.lrs @@ -0,0 +1,34 @@ +LazarusResources.Add('tjlabeledfloatedit','PNG',[ + #137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0 + +#0#0#1'sRGB'#0#174#206#28#233#0#0#0#6'bKGD'#0#255#0#255#0#255#160#189#167#147 + +#0#0#0#9'pHYs'#0#0#11#19#0#0#11#19#1#0#154#156#24#0#0#0#7'tIME'#7#219#9#27#9 + +'/'#26#222#138#14';'#0#0#2#155'IDATH'#199#181'VOH'#147'a'#24#255#189#18'z' + +#169'M,'#149'!K'#26'HBj'#200'^'#4'Y^'#182#131#18'A'#135']DIl'#228#165#14#210 + +'e"By'#9#217'%&x'#8'D'#172'C'#212#161#29#4#3'/'#187#228#188#200#23#129#127' ' + +#148'D'#29#171#248#16#219#180#192#141#182'_'#135'z?'#191#185'M'#167#185#7'^' + +#222#231'yyy~'#239#251'{~'#239#243'}'#130'$Ji'#23#204#193#219#249'o'#152#156 + +#221#200#187'q'#224#142#3#221#29#182'S'#3#8#146'Y'#137#199#31#221'D'#211#213 + +#139'X'#217#254#9'='#158#132#158'HA'#143'''1'#19#137#157#9#168#12#0'&g7'#208 + +#210'P'#133#187#183#234#160#199#147#144'R'#210#156'\O'#164#208#210'P'#5#135 + +#221'R'#240#134'RJ'#22#4'p'#216'-XZ'#223#197'L$'#6#191#175#147#0#224#247'uR' + +#143'''Q'#151#250#200#185'`'#15#231'_'#220'c'#151'm'#141#14#187'%+'#153#148 + +#146'*'#206#7'"Hb`b'#25#181#149#21#168#177#150'c&'#18'C"|'#133#219#31#193 + +#212#212'+>'#30'|@'#146't'#251'#'#204'gn'#127#132#153'L&+&I'#167#211'I'#146 + +'L'#252#216'&'#201#191'7P'#214#221'a;Q!G'#219#187':\Q'#237#250#164#196'B'#8 + +#131'&u'#16'EO'#161#131#149#21#173#231#127#201#213#172'@'#195#1#23#194#1'WN' + +#173'N'#13'`.'#178':'#173#25#236#216#239'A'#177#137#243')I'#249#225#128#11'R' + +'Jh'#154'VXEj'#152'UtT%'#197#154'R'#145#200#167#128#189'x'#244'\Z'#133#165 + +#210'.D'#169#255'*'#202'Pb'#251#3#3#157#217#235'>i'#220'Y'#0#0#0#0'IEND'#174 + +'B`'#130 +]);