diff --git a/components/jujiboutils/changes.txt b/components/jujiboutils/changes.txt index 7de4553ef..0818a9c0a 100644 --- a/components/jujiboutils/changes.txt +++ b/components/jujiboutils/changes.txt @@ -7,6 +7,7 @@ Version pre-1.0 -------------------------------------------------- 2011-09-20 Added: TJIntegerEdit, TJLabeledIntegerEdit TJCurrencyEdit, TJLabeledCurrencyEdit + TJDateEdit, TJLabeledDateEdit 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 diff --git a/components/jujiboutils/jujibo-utils/jujibocontrols.lpk b/components/jujiboutils/jujibo-utils/jujibocontrols.lpk index 66fdb96ad..d6d410841 100644 --- a/components/jujiboutils/jujibo-utils/jujibocontrols.lpk +++ b/components/jujiboutils/jujibo-utils/jujibocontrols.lpk @@ -12,30 +12,31 @@ - + - - - - - - - - - - + + + + + + + + + + - - - - + + + + + @@ -43,9 +44,8 @@ - - - + + @@ -67,6 +67,16 @@ + + + + + + + + + + diff --git a/components/jujiboutils/jujibo-utils/jujibocontrols.pas b/components/jujiboutils/jujibo-utils/jujibocontrols.pas index 505af159f..778ea8f53 100644 --- a/components/jujiboutils/jujibo-utils/jujibocontrols.pas +++ b/components/jujiboutils/jujibo-utils/jujibocontrols.pas @@ -7,25 +7,27 @@ unit jujibocontrols; interface uses - jdbcurrencyedit, jdbdateedit, jdbintegeredit, jcontrolutils, - jdblabeledcurrencyedit, jdblabeleddateedit, jdblabeledintegeredit, + jdbintegeredit, jdblabeledintegeredit, jdbcurrencyedit, + jdblabeledcurrencyedit, jdbdateedit, jdblabeleddateedit, jcontrolutils, JIntegerEdit, JLabeledIntegerEdit, JCurrencyEdit, JLabeledCurrencyEdit, - LazarusPackageIntf; + JDateEdit, JLabeledDateEdit, LazarusPackageIntf; implementation procedure Register; begin - RegisterUnit('jdbcurrencyedit', @jdbcurrencyedit.Register); - RegisterUnit('jdbdateedit', @jdbdateedit.Register); RegisterUnit('jdbintegeredit', @jdbintegeredit.Register); - RegisterUnit('jdblabeledcurrencyedit', @jdblabeledcurrencyedit.Register); - RegisterUnit('jdblabeleddateedit', @jdblabeleddateedit.Register); RegisterUnit('jdblabeledintegeredit', @jdblabeledintegeredit.Register); + RegisterUnit('jdbcurrencyedit', @jdbcurrencyedit.Register); + RegisterUnit('jdblabeledcurrencyedit', @jdblabeledcurrencyedit.Register); + RegisterUnit('jdbdateedit', @jdbdateedit.Register); + RegisterUnit('jdblabeleddateedit', @jdblabeleddateedit.Register); RegisterUnit('JIntegerEdit', @JIntegerEdit.Register); RegisterUnit('JLabeledIntegerEdit', @JLabeledIntegerEdit.Register); RegisterUnit('JCurrencyEdit', @JCurrencyEdit.Register); RegisterUnit('JLabeledCurrencyEdit', @JLabeledCurrencyEdit.Register); + RegisterUnit('JDateEdit', @JDateEdit.Register); + RegisterUnit('JLabeledDateEdit', @JLabeledDateEdit.Register); end; initialization diff --git a/components/jujiboutils/jujibo-utils/src/jdateedit.pas b/components/jujiboutils/jujibo-utils/src/jdateedit.pas new file mode 100644 index 000000000..365c29fce --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jdateedit.pas @@ -0,0 +1,186 @@ +unit JDateEdit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, LResources, Forms, Controls, StdCtrls, Graphics, + Dialogs, jcontrolutils; + +type + + { TJDateEdit } + + TJDateEdit = class(TCustomEdit) + private + { Private declarations } + theValue: TDateTime; + fFormat: string; + function getFormat: string; + function getValue: TDateTime; + procedure formatInput; + procedure setFormat(const AValue: string); + procedure setValue(const AValue: TDateTime); + 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 } + function isNull: boolean; + property DisplayFormat: string read getFormat write setFormat; + property Value: TDateTime 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 + +procedure Register; +begin + {$I jdateedit_icon.lrs} + RegisterComponents('Additional', [TJDateEdit]); +end; + +{ TJDateEdit } + +function TJDateEdit.getFormat: string; +begin + Result := fFormat; +end; + +function TJDateEdit.getValue: TDateTime; +begin + Result := theValue; +end; + +procedure TJDateEdit.formatInput; +begin + if theValue <> 0 then + Text := FormatDateTime(DisplayFormat, theValue); +end; + +procedure TJDateEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + formatInput; +end; + +procedure TJDateEdit.setValue(const AValue: TDateTime); +begin + theValue := AValue; + formatInput; +end; + +procedure TJDateEdit.DoEnter; +begin + inherited DoEnter; + if theValue <> 0 then + Text := FormatDateTime(DisplayFormat, theValue) + else + Text := ''; + SelectAll; +end; + +procedure TJDateEdit.DoExit; +begin + inherited DoExit; + Text := NormalizeDate(Text, theValue); + if Length(Text) = 0 then + theValue := 0 + else + if IsValidDateString(Text) then + theValue := StrToDate(Text) + else + begin + ShowMessage(Text + ' no es una fecha válida'); + SetFocus; + end; + formatInput; +end; + +procedure TJDateEdit.KeyPress(var Key: char); +begin + if not (Key in ['0'..'9', #8, #9, '.', '-', '/']) then + Key := #0; + inherited KeyPress(Key); +end; + +constructor TJDateEdit.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + Text := ''; + fFormat := ShortDateFormat; + theValue := 0; + formatInput; +end; + +destructor TJDateEdit.Destroy; +begin + inherited Destroy; +end; + +function TJDateEdit.isNull: boolean; +begin + Result := theValue = 0; +end; + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/jdateedit_icon.lrs b/components/jujiboutils/jujibo-utils/src/jdateedit_icon.lrs new file mode 100644 index 000000000..c86f5165d --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jdateedit_icon.lrs @@ -0,0 +1,25 @@ +LazarusResources.Add('tjdateedit','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 + +#28'0'#169'9'#178#139#0#0#1#190'IDATH'#199#181'V=H'#195'@'#20#254#174#136'"' + +#168#20#7#197#161#6#11#221'D'#135'f'#171#191'uu'#169't'#16#4#135#162#147#136 + +#186#168#208#185'P'#23#169'8'#138#5#133#130#131#16#4'W'#193#182#233#150#169 + +'t'#11#20#180#136#208#161#182'EA'#163#242#156'"I'#147#180'I'#180#15#30#151 + +#187'w'#247'}w'#223'{'#199#133#17#17#186'i='#218#206'U'#254#25'g'#183'e'#211 + +#137#155#203'~'#172#206#142'9&`D'#164#3'>'#217#154#198#228#248#0'J'#143#175 + +#168#214'?Pm('#168#214'?p#>'#185'"bD'#132#165#131#2#166#2#195#152#24#237#199 + +'$7'#136#17'o'#159#14#188#218'P'#240#246#254#141#215#247'/'#148'+M'#220#29 + +#133#156'I'#228#247#13#161'('#215'P'#148#129#17#175#31#0#12#224'E'#185#6'u' + +#174'c'#137#14#15'O'#255#148#233'dr'#155'uL'#242#238'n'#196#21'x*%'#216#175 + +'";'#11#204'6'#148#205#137'4?7'#195'l'#17#184'='#137#237#19#0'@$!'#3#0#132'x' + +#192'0'#166#154'6'#230#136#160#21'Hk'#209#5#14'k'#161'^'#211'X:}i('#148'Xl' + +#157'yZ'#7#133'x'#0#209#5#206#20#228#250#254#193'r'#3#165'b^'#231#209#149'Ek' + +#137#204'L'#149'$SP'#16'I'#200#6#137#142'Sg'#186'~'#179'^'#1#0'x'#236#18'd' + +#10'J'#219'8'#207#243#186#182'm'#146#173#228#1'8'#203#184'$I'#224'y'#30#146 + +'$'#217'O'#178#182#154#132'x'#192#180#186#28'WQ'#187#197'N'#128#13#4'vo'#176 + +'+'#130'dr'#155'esbw'#158'6"2'#248#249#249#5#237#237'l'#16#17'Qx_'#164#207 + +#175'o'#10#239#139#191#174#142#171#223'DD'#193'`P'#215'6^'#30#137#136':'#19 + +#184'5'#149#128#153'='#250#205'z'#229'_'#228#26#242#250#24#235#246'_'#133#7 + +']'#182#31#245#153'Q='#238'^'#250#139#0#0#0#0'IEND'#174'B`'#130 +]); diff --git a/components/jujiboutils/jujibo-utils/src/jlabeleddateedit.pas b/components/jujiboutils/jujibo-utils/src/jlabeleddateedit.pas new file mode 100644 index 000000000..9f3b3831b --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jlabeleddateedit.pas @@ -0,0 +1,181 @@ +unit JLabeledDateEdit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, LResources, Forms, Controls, ExtCtrls, Graphics, + Dialogs, jcontrolutils; + +type + + { TJLabeledDateEdit } + + TJLabeledDateEdit = class(TCustomLabeledEdit) + private + theValue: TDateTime; + fFormat: string; + function getFormat: string; + function getValue: TDateTime; + procedure formatInput; + procedure setFormat(const AValue: string); + procedure setValue(const AValue: TDateTime); + 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 } + function isNull: boolean; + property DisplayFormat: string read getFormat write setFormat; + property Value: TDateTime read getValue write setValue; + + property Action; + property Align; + property Alignment; + property Anchors; + property AutoSelect; + property AutoSize; + property BidiMode; + property BorderSpacing; + property BorderStyle; + property CharCase; + property Color; + property Constraints; + property DragCursor; + property DragMode; + property EditLabel; + property Enabled; + property Font; + property LabelPosition; + property LabelSpacing; + property MaxLength; + property ParentColor; + property ParentFont; + property ParentShowHint; + property PopupMenu; + property ReadOnly; + property ShowHint; + property TabOrder; + property TabStop; + property Visible; + property OnChange; + property OnClick; + property OnDblClick; + property OnDragDrop; + property OnDragOver; + property OnEditingDone; + property OnEndDrag; + property OnEnter; + property OnExit; + property OnKeyDown; + property OnKeyPress; + property OnKeyUp; + property OnMouseDown; + property OnMouseMove; + property OnMouseUp; + property OnStartDrag; + property OnUTF8KeyPress; + end; + +procedure Register; + +implementation + +procedure Register; +begin + {$I jlabeleddateedit_icon.lrs} + RegisterComponents('Additional', [TJLabeledDateEdit]); +end; + +{ TJLabeledDateEdit } + +function TJLabeledDateEdit.getFormat: string; +begin + Result := fFormat; +end; + +function TJLabeledDateEdit.getValue: TDateTime; +begin + Result := theValue; +end; + +procedure TJLabeledDateEdit.formatInput; +begin + if theValue <> 0 then + Text := FormatDateTime(DisplayFormat, theValue); +end; + +procedure TJLabeledDateEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + formatInput; +end; + +procedure TJLabeledDateEdit.setValue(const AValue: TDateTime); +begin + theValue := AValue; + formatInput; +end; + +procedure TJLabeledDateEdit.DoEnter; +begin + inherited DoEnter; + if theValue <> 0 then + Text := FormatDateTime(DisplayFormat, theValue) + else + Text := ''; + SelectAll; +end; + +procedure TJLabeledDateEdit.DoExit; +begin + inherited DoExit; + Text := NormalizeDate(Text, theValue); + if Length(Text) = 0 then + theValue := 0 + else + if IsValidDateString(Text) then + theValue := StrToDate(Text) + else + begin + ShowMessage(Text + ' no es una fecha válida'); + SetFocus; + end; + formatInput; +end; + +procedure TJLabeledDateEdit.KeyPress(var Key: char); +begin + if not (Key in ['0'..'9', #8, #9, '.', '-', '/']) then + Key := #0; + inherited KeyPress(Key); +end; + +constructor TJLabeledDateEdit.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + Text := ''; + fFormat := ShortDateFormat; + theValue := 0; + formatInput; +end; + +destructor TJLabeledDateEdit.Destroy; +begin + inherited Destroy; +end; + +function TJLabeledDateEdit.isNull: boolean; +begin + Result := theValue = 0; +end; + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/jlabeleddateedit_icon.lrs b/components/jujiboutils/jujibo-utils/src/jlabeleddateedit_icon.lrs new file mode 100644 index 000000000..8178cf707 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jlabeleddateedit_icon.lrs @@ -0,0 +1,24 @@ +LazarusResources.Add('tjlabeleddateedit','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 + +#29#27#28#158'z'#138#0#0#1#171'IDATH'#199#237'U=O'#2'A'#16'}gN['#163#165#133 + +'T'#252#130'9'#11'c'#131#198'?'#128#217#206#130'Bk'#197#198#11#161'&'#132'h' + +#12#161'5'#20'W'#216'mr'#20#148'W@'#144#194#228'h'#140#29#149'RP'#250'Q'#162 + +'f'#172#246#194#193#238#137'bLL|'#201'f'#231#235'fv'#223#236#222#2#255#152#7 + +'D'#196#243'~'#179#240'Y'#160#154#165#148'LDLD,'#165#228#201'd'#202'7i'#183#0 + +#192'uk'#218#149#6#129#135#221#221#156'Q'#222#216'XC'#185'\'#6#0#20#10#5#8'!' + +',"'#226'^'#175'g'#169#28#182#18#242#249#172#182#128#178#7#129#135' '#240'`' + +#138#23'BX'#186'E'#218#147#134'j'#213'7'#234'j'#7#10#221#238'M$K)'#217'T'#4 + +#174'['#227#225'p05'#20#175#195#225#128#199'{'#160'lD'#196#174'['#227'V'#187 + +#19#227#127#188#7#182#174'`'#182#212#7#0'4'#155#141#200'v'#222'Z'#197#226#230 + +'Y,'#174#217'lD;T'#188#143#243#175'-'#160#146#235' 2)'#236'o-i}'#245#186'7uP' + +#14#14'r'#214#212'1'#245#139'i'#136'LJ'#155'D'#182#238#141#11#184#187#237#196 + +#134#216#219'6S'#164#131'_L'#3#0#174#186'#dK'#253'HW'#184#168'^'#198#244#151 + +#167'A'#242'E'#155#196'Uw'#148#232'w'#28'''6''6'#217'D'#15#144'2'#250#195'0' + +#132#227'8'#8#195#16'37Y'#201'~1'#13#191#152#142#233#179#194'6q'#157#212#135 + +#175#192'6'#221#224#159#130#13#0#149#202#145#213'jw'#248#215#222#129'z'#221 + +#227#147#227'Cff'#222'9'#189#230#215#183'w'#222'9'#189#142#134#178'+'#153#153 + +#153#136'b'#243#243#227#3#207'T'#224#187'P'#5#180#127#191#196#234'_'#192#242 + +#202#186#245#247#223#245#15#177'oA'#194#17#168'PG'#0#0#0#0'IEND'#174'B`'#130 +]);