diff --git a/components/jujiboutils/changes.txt b/components/jujiboutils/changes.txt index 88e04bede..8ccaf35f8 100644 --- a/components/jujiboutils/changes.txt +++ b/components/jujiboutils/changes.txt @@ -5,7 +5,8 @@ JUJIBOUTILS Version pre-1.0 -------------------------------------------------- -2011-09-19 Added: JDBLabeledIntegerEdit, TJDBLabeledCurrencyEdit, TJDBLabeledDateEdit +2011-09-20 Added: TJIntegerEdit, TJLabeledIntegerEdit +2011-09-19 Added: TJDBLabeledIntegerEdit, TJDBLabeledCurrencyEdit, TJDBLabeledDateEdit 2011-09-19 First package: TJDBIntegerEdit, TJDBCurrencyEdit, TJDBDateEdit and example 2011-09-14 Add Non Database input controls example 2011-09-13 Initial commit to lazarus-ccr diff --git a/components/jujiboutils/jujibo-utils/jujibocontrols.lpk b/components/jujiboutils/jujibo-utils/jujibocontrols.lpk index 6915ee0d8..66c3fb56e 100644 --- a/components/jujiboutils/jujibo-utils/jujibocontrols.lpk +++ b/components/jujiboutils/jujibo-utils/jujibocontrols.lpk @@ -12,7 +12,7 @@ - + @@ -47,6 +47,16 @@ + + + + + + + + + + diff --git a/components/jujiboutils/jujibo-utils/jujibocontrols.pas b/components/jujiboutils/jujibo-utils/jujibocontrols.pas index 1098dc5c0..7f71f8092 100644 --- a/components/jujiboutils/jujibo-utils/jujibocontrols.pas +++ b/components/jujiboutils/jujibo-utils/jujibocontrols.pas @@ -9,7 +9,7 @@ interface uses jdbcurrencyedit, jdbdateedit, jdbintegeredit, jcontrolutils, jdblabeledcurrencyedit, jdblabeleddateedit, jdblabeledintegeredit, - LazarusPackageIntf; + JIntegerEdit, JLabeledIntegerEdit, LazarusPackageIntf; implementation @@ -21,6 +21,8 @@ begin RegisterUnit('jdblabeledcurrencyedit', @jdblabeledcurrencyedit.Register); RegisterUnit('jdblabeleddateedit', @jdblabeleddateedit.Register); RegisterUnit('jdblabeledintegeredit', @jdblabeledintegeredit.Register); + RegisterUnit('JIntegerEdit', @JIntegerEdit.Register); + RegisterUnit('JLabeledIntegerEdit', @JLabeledIntegerEdit.Register); end; initialization diff --git a/components/jujiboutils/jujibo-utils/src/jintegeredit.pas b/components/jujiboutils/jujibo-utils/src/jintegeredit.pas new file mode 100644 index 000000000..94502d385 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jintegeredit.pas @@ -0,0 +1,130 @@ +unit JIntegerEdit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, LResources, Forms, Controls, StdCtrls, Graphics, Dialogs; + +type + + { TJIntegerEdit } + + TJIntegerEdit = class(TCustomEdit) + private + { Private declarations } + theValue: integer; + fFormat: string; + function getFormat: string; + function getValue: integer; + procedure setFormat(const AValue: string); + procedure setValue(const AValue: integer); + function IsValidInteger(const Value: string): boolean; + procedure FormatInput; + 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 Value: integer read getValue write setValue; + end; + +procedure Register; + +implementation + + +procedure Register; +begin + {$I jintegeredit_icon.lrs} + RegisterComponents('Additional', [TJIntegerEdit]); +end; + +{ TJIntegerEdit } + +function TJIntegerEdit.getFormat: string; +begin + Result := fFormat; +end; + +function TJIntegerEdit.getValue: integer; +begin + Result := theValue; +end; + +procedure TJIntegerEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + formatInput; +end; + +procedure TJIntegerEdit.setValue(const AValue: integer); +begin + theValue := AValue; + formatInput; +end; + +function TJIntegerEdit.IsValidInteger(const Value: string): boolean; +begin + if StrToIntDef(Value, MaxInt) = MaxInt then + Result := False + else + Result := True; +end; + +procedure TJIntegerEdit.FormatInput; +begin + Text := FormatFloat(fFormat, theValue); +end; + +procedure TJIntegerEdit.DoEnter; +begin + inherited DoEnter; + Text := IntToStr(theValue); + SelectAll; +end; + +procedure TJIntegerEdit.DoExit; +begin + inherited DoExit; + if IsValidInteger(Text) then + theValue := StrToInt(Text) + else + begin + ShowMessage(Text + ' no es un valor válido'); + SetFocus; + end; + formatInput; +end; + +procedure TJIntegerEdit.KeyPress(var Key: char); +begin + if not (Key in ['0'..'9', #8, #9, '-']) then + Key := #0; + inherited KeyPress(Key); +end; + +constructor TJIntegerEdit.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + // Set initial values + Text := ''; + DisplayFormat := '0'; + Value := 0; +end; + +destructor TJIntegerEdit.Destroy; +begin + inherited Destroy; +end; + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/jintegeredit_icon.lrs b/components/jujiboutils/jujibo-utils/src/jintegeredit_icon.lrs new file mode 100644 index 000000000..6bc9f270e --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jintegeredit_icon.lrs @@ -0,0 +1,28 @@ +LazarusResources.Add('tjintegeredit','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#20#9 + +#22'3'#202#223#11#187#0#0#1#254'IDATH'#199#213#150#177'k'#19'q'#20#199'?'#191 + +' -'#130#166'AMB'#135'X'#26#16#3#166'u'#200'!'#20#233#146'l'#226#31'P'#8'8'#4 + +';9'#136'K2'#20#164'K'#7#23'Qp+'#29':'#20']'#11'ut'#177#9'B'#185')mA'#8#134 + +#182'!'#10#177#212'$'#173#208#134#228#158#131#220'y'#151'\'#180'I'#154#193'/' + +#252'x'#191#7#143#247#253#189#239'{'#247'8%"'#12#19#151#236#206#187#205'o,o' + +#20']'#3#231#31#134#153#155#29#239#153'@'#137#136'#'#241#235'''w'#137#222#188 + +#194#206#193#9#149#234#25#149'Z'#131'J'#245#140#245'l'#185'/"%"$29'#166'o]c2' + +'x'#153#232#196'U'#2#190'QG'#242'J'#173#193#207#211#22''''#167'M'#138#165':' + +#31'^'#220#239'M'#162'p'#200'K'#190'pD'#190#0#1'_'#24#160'#y'#190'p'#132#25 + +#219'W'#15'f'#166#252#4#198'F'#186#246'`f'#202'oU'#209'3A'#177'T'''#232#243#3 + +#176#144#140#16#159#190#222#209#131'J'#173#129#25#219'3A8'#228'ek'#247#144 + +#150'!D''"'#174#129#159#182#191#15'&'#209#189';7'#8#140#141#176#180#246#153 + +#165#181#255'H"%"'#204#191#217'f'#191'|L'#203#16#22#146#17#246#244#247#23#242 + +'y'#167'R'#143#148#171'D'#201#219#176#147#223#28'('#249#226#226#243'?'#18#237 + +#151#143#9#250'F-'#137#246#244'/'#0#188'|'#181#220'7A'#189'Z'#2#192#3#144'z0' + +#201#214#238#161#181#14#236'Hdr'#150'5'#239#205#150#225#240#1'4MsX'#11'"b' + +#157#183#31#191#18'OgYYY'#149'gO'#31#139#136'H<'#157#21';'#226#233#172#24#134 + +#225#240'M'#196'b1'#235'^'#251'q "'#242#187#2#19's'#179#227']'#247'L'#251'Z7' + +#31#213#211#186#238#6'3Q"'#147#179#30'`'#202#243#175#197'w.'#2#165'T'#7#161 + +#157#232'o$'#158#243'N'#133'=Q;'#225#192#21'4[F'#135','#237#18'i'#154#134#174 + +#235#150'u'#157'"'#243#216#167#168'_'#152'S'#164#220'&'#161'^-]'#200#170#240 + +#250'BJ'#13#251#175#194#195#144#241#11':\'#164#234#214#16'Q'#217#0#0#0#0'IEN' + +'D'#174'B`'#130 +]); diff --git a/components/jujiboutils/jujibo-utils/src/jlabeledintegeredit.pas b/components/jujiboutils/jujibo-utils/src/jlabeledintegeredit.pas new file mode 100644 index 000000000..f989e7d5b --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jlabeledintegeredit.pas @@ -0,0 +1,130 @@ +unit JLabeledIntegerEdit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, LResources, Forms, Controls, ExtCtrls, Graphics, Dialogs; + +type + + { TJLabeledIntegerEdit } + + TJLabeledIntegerEdit = class(TCustomLabeledEdit) + private + { Private declarations } + theValue: integer; + fFormat: string; + function getFormat: string; + function getValue: integer; + procedure setFormat(const AValue: string); + procedure setValue(const AValue: integer); + function IsValidInteger(const Value: string): boolean; + procedure FormatInput; + 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 Value: integer read getValue write setValue; + end; + +procedure Register; + +implementation + + +procedure Register; +begin + {$I jlabeledintegeredit_icon.lrs} + RegisterComponents('Additional', [TJLabeledIntegerEdit]); +end; + +{ TJLabeledIntegerEdit } + +function TJLabeledIntegerEdit.getFormat: string; +begin + Result := fFormat; +end; + +function TJLabeledIntegerEdit.getValue: integer; +begin + Result := theValue; +end; + +procedure TJLabeledIntegerEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + formatInput; +end; + +procedure TJLabeledIntegerEdit.setValue(const AValue: integer); +begin + theValue := AValue; + formatInput; +end; + +function TJLabeledIntegerEdit.IsValidInteger(const Value: string): boolean; +begin + if StrToIntDef(Value, MaxInt) = MaxInt then + Result := False + else + Result := True; +end; + +procedure TJLabeledIntegerEdit.FormatInput; +begin + Text := FormatFloat(fFormat, theValue); +end; + +procedure TJLabeledIntegerEdit.DoEnter; +begin + inherited DoEnter; + Text := IntToStr(theValue); + SelectAll; +end; + +procedure TJLabeledIntegerEdit.DoExit; +begin + inherited DoExit; + if IsValidInteger(Text) then + theValue := StrToInt(Text) + else + begin + ShowMessage(Text + ' no es un valor válido'); + SetFocus; + end; + formatInput; +end; + +procedure TJLabeledIntegerEdit.KeyPress(var Key: char); +begin + if not (Key in ['0'..'9', #8, #9, '-']) then + Key := #0; + inherited KeyPress(Key); +end; + +constructor TJLabeledIntegerEdit.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + // Set initial values + Text := ''; + DisplayFormat := '0'; + Value := 0; +end; + +destructor TJLabeledIntegerEdit.Destroy; +begin + inherited Destroy; +end; + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/jlabeledintegeredit_icon.lrs b/components/jujiboutils/jujibo-utils/src/jlabeledintegeredit_icon.lrs new file mode 100644 index 000000000..254d71044 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jlabeledintegeredit_icon.lrs @@ -0,0 +1,34 @@ +LazarusResources.Add('tjlabeledintegeredit','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#20#9 + +#25'-'#183'H*'#23#0#0#2#143'IDATH'#199#181'VKH[A'#20'=#E7m'#18'lU'#130#164 + +#210#128'4'#208'h'#145#12#130#180'n'#146#133'R'#10']'#188#141'D*6'#212'M'#187 + +#144'n"Ah'#221#20#233#166'$'#224#162#16#196'vQ'#218'E'#179#16','#184'q'#211 + +'$'#27'y'#165#224#7#138'R'#241'C'#218#242#16#155'h'#11'M0'#239'v'#209#206#248 + +#242'y'#214'Ds`'#152';'#143#225#158#185#231#158#25#30'#"'#212#18#231#140#139 + +#183#241'o'#136#206'm'#148#221'8r'#219#137#129'^{'#197#4#140#136#10#18'G'#30 + +'^'#135#251#242'y'#172'l'#255#132#150#206'B'#203#228#160#165#179#152'M'#164 + +#170'"'#170#3#128#232#220#6':'#219#27'q'#231'f+'#180't'#22#156's2&'#215'29t' + +#182'7'#194#233#176#152'V'#200'9''S'#2#167#195#130#165#245'='#204'&R'#8#6#250 + +#8#0#130#129'>'#210#210'Y'#180#230'>'#210'|'#216'O'#241#23'w'#169#223#190'FN' + +#135#165' '#25#231#156#196#186#28#9'#"'#140'L-'#163#197#214#128'fk=f'#19')d' + +#22'F'#201#234#139'0'#0'2'#238#233'h'#194'|'#216'O]'#195'3'#172#223#190'F' + +#147#147#147#0#128'P('#4'EQ'#24#231#156'TUee+'#216#216#217#151#31#198#7']' + +#178#23'"'#206','#140#210'|'#216'Ob'#175#162'(2'#145'16u'#145#211'a'#193#226 + +#234'.'#242':'#193#221#230'*'#217'4'#244#228#29#19'Mv:,'#136#197'bR'#138'X,F' + +#199#145#152'J'#4#0'V_'#132'='#232#254'.'#229#0#128#174#225#25#246#233#229'=' + +')'#135#144'F'#232'_,'#19'#"'#248#198#146#232#233'hB'#179#181#30#238#182#11 + +#240'v^,'#177#169#150#201#225#215#239'<'#150#214#247#176#240#236'Fe'#247'`dj' + +#25'['#169#3#228'u'#194#248#160#11#155#234#251'3'#185#222#129#192#16#147'7' + +#185#251#218'%4['#235#241#244#245'g'#12'^'#5'V'#150#226#167'J>1'#241#248#168 + +#201'['#169#3#180#216#26#164#139'6'#213'/'#0#128#231#225'h'#213#4#251#233#157 + +'#'#155#6'n]'#193#226#234#174'|'#14#140#240#141'%'#229','#226#195#188'^'#176 + +#254#215#236#130'Y'#130#136#228'x'#243#225'+'#188#193#4#166#167'_'#209#163 + +#209#251'DD'#228#13'&'#200#8'o0A'#186#174#23#172#5'<'#30#143#140'3?'#182#137 + +#136#254'V 0'#208'k7uH'#241#179'.'#14'U'#209'sm'#6#145#200'7'#150#148#7#16 + +#242#252#207#178'''"`'#140#149#16#26#137#142'#'#169';'#169'+'#140#137#138#9 + +'O]'#193'a^/'#145#165'X"'#206'9TU'#149'sY'#23#137'atQ'#181#16'.b'#229#156#176 + +#159#222'9'#147#167#194'bs0V'#235#191#138':'#212#24#127#0#29#204#221#201#197 + +#137#18#7#0#0#0#0'IEND'#174'B`'#130 +]);