diff --git a/components/jujiboutils/changes.txt b/components/jujiboutils/changes.txt index e4544d936..bbf1ccc46 100644 --- a/components/jujiboutils/changes.txt +++ b/components/jujiboutils/changes.txt @@ -5,7 +5,8 @@ Note: Lazarus Trunk required Version pre-1.0 -------------------------------------------------- -2011-09-26 Added: TDateTimeEdit, TLabeledDateTimeEdit +2011-09-26 Added: TJDateTimeEdit, TJLabeledDateTimeEdit + TJDBDateTimeEdit, TJDBLabeledDateTimeEdit 2011-09-23 Added: TJDBLabeledEdit, TJTimeEdit, TJLabeledTimeEdit, TJDBTimeEdit, TJDBLabeledTimeEdit 2011-09-22 Added: ftTime support diff --git a/components/jujiboutils/jujibo-utils/jujibocontrols.lpk b/components/jujiboutils/jujibo-utils/jujibocontrols.lpk index 24105ba5b..eb3ad0893 100644 --- a/components/jujiboutils/jujibo-utils/jujibocontrols.lpk +++ b/components/jujiboutils/jujibo-utils/jujibocontrols.lpk @@ -18,7 +18,7 @@ - + @@ -127,6 +127,16 @@ + + + + + + + + + + diff --git a/components/jujiboutils/jujibo-utils/jujibocontrols.pas b/components/jujiboutils/jujibo-utils/jujibocontrols.pas index db9ee753f..a06bc1734 100644 --- a/components/jujiboutils/jujibo-utils/jujibocontrols.pas +++ b/components/jujiboutils/jujibo-utils/jujibocontrols.pas @@ -12,7 +12,8 @@ uses JIntegerEdit, JLabeledIntegerEdit, JCurrencyEdit, JLabeledCurrencyEdit, JDateEdit, JLabeledDateEdit, JDBGridControl, jdbgridutils, JDBLabeledEdit, JTimeEdit, JLabeledTimeEdit, JDBTimeEdit, JDBLabeledTimeEdit, JDateTimeEdit, - JLabeledDateTimeEdit, LazarusPackageIntf; + JLabeledDateTimeEdit, JDBDateTimeEdit, JDBLabeledDateTimeEdit, + LazarusPackageIntf; implementation @@ -38,6 +39,8 @@ begin RegisterUnit('JDBLabeledTimeEdit', @JDBLabeledTimeEdit.Register); RegisterUnit('JDateTimeEdit', @JDateTimeEdit.Register); RegisterUnit('JLabeledDateTimeEdit', @JLabeledDateTimeEdit.Register); + RegisterUnit('JDBDateTimeEdit', @JDBDateTimeEdit.Register); + RegisterUnit('JDBLabeledDateTimeEdit', @JDBLabeledDateTimeEdit.Register); end; initialization diff --git a/components/jujiboutils/jujibo-utils/src/jdatetimeedit.pas b/components/jujiboutils/jujibo-utils/src/jdatetimeedit.pas index 48158ceed..49ace2458 100644 --- a/components/jujiboutils/jujibo-utils/src/jdatetimeedit.pas +++ b/components/jujiboutils/jujibo-utils/src/jdatetimeedit.pas @@ -1,3 +1,21 @@ +{ TJDateTimeEdit + + 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 JDateTimeEdit; {$mode objfpc}{$H+} diff --git a/components/jujiboutils/jujibo-utils/src/jdbdatetimeedit.pas b/components/jujiboutils/jujibo-utils/src/jdbdatetimeedit.pas new file mode 100644 index 000000000..cdbb5b20d --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jdbdatetimeedit.pas @@ -0,0 +1,352 @@ +{ TJDBDateTimeEdit + + 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 JDBDateTimeEdit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, LResources, Controls, StdCtrls, DB, DBCtrls, LMessages, LCLType, Dialogs, + SysUtils; + +type + + { TJDBDateTimeEdit } + + TJDBDateTimeEdit = class(TCustomEdit) + private + fFormat: string; + FDataLink: TFieldDataLink; + + procedure DataChange(Sender: TObject); + procedure UpdateData(Sender: TObject); + procedure FocusRequest(Sender: TObject); + + function GetDataField: string; + function GetDataSource: TDataSource; + function GetField: TField; + + function IsReadOnly: boolean; + + function getFormat: string; + procedure setFormat(const AValue: string); + procedure formatInput; + + procedure SetDataField(const Value: string); + procedure SetDataSource(Value: TDataSource); + procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK; + + protected + procedure Loaded; override; + procedure Notification(AComponent: TComponent; Operation: TOperation); override; + procedure ActiveChange(Sender: TObject); virtual; + procedure KeyDown(var Key: word; Shift: TShiftState); override; + procedure KeyPress(var Key: char); override; + procedure DoEnter; override; + function GetReadOnly: boolean; override; + procedure SetReadOnly(Value: boolean); override; + + public + constructor Create(TheOwner: TComponent); override; + destructor Destroy; override; + procedure EditingDone; override; + property Field: TField read GetField; + + published + property DisplayFormat: string read getFormat write setFormat; + property DataField: string read GetDataField write SetDataField; + property DataSource: TDataSource read GetDataSource write SetDataSource; + property ReadOnly: boolean read GetReadOnly write SetReadOnly default False; + + // From TEdit + 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 + jcontrolutils; + +procedure Register; +begin + {$I jdbdatetimeedit_icon.lrs} + RegisterComponents('Data Controls', [TJDBDateTimeEdit]); +end; + + +procedure TJDBDateTimeEdit.DataChange(Sender: TObject); +begin + if FDataLink.Field <> nil then + begin + if not Focused then + formatInput + else + Caption := FDataLink.Field.AsString; + end + else + Text := ''; +end; + +procedure TJDBDateTimeEdit.UpdateData(Sender: TObject); +var + theValue: string; +begin + if FDataLink.Field <> nil then + begin + theValue := NormalizeDateTime(Text, FDataLink.Field.AsDateTime); + if Text = '' then + FDataLink.Field.Text := Text + else + if IsValidDateTimeString(theValue) then + begin + FDataLink.Field.Text := theValue; + end + else + begin + ShowMessage(Caption + ' no es un valor válido'); + Caption := FDataLink.Field.AsString; + SelectAll; + SetFocus; + end; + end + else + Text := ''; +end; + +procedure TJDBDateTimeEdit.FocusRequest(Sender: TObject); +begin + SetFocus; +end; + +function TJDBDateTimeEdit.GetDataField: string; +begin + Result := FDataLink.FieldName; +end; + +function TJDBDateTimeEdit.GetDataSource: TDataSource; +begin + Result := FDataLink.DataSource; +end; + +function TJDBDateTimeEdit.GetField: TField; +begin + Result := FDataLink.Field; +end; + +function TJDBDateTimeEdit.IsReadOnly: boolean; +begin + if FDatalink.Active then + Result := not FDatalink.CanModify + else + Result := False; +end; + +function TJDBDateTimeEdit.getFormat: string; +begin + Result := fFormat; +end; + +procedure TJDBDateTimeEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + if not Focused then + formatInput; +end; + +procedure TJDBDateTimeEdit.formatInput; +begin + if FDataLink.Field <> nil then + if (fFormat <> '') and (not FDataLink.Field.IsNull) then + Caption := FormatDateTime(fFormat, FDataLink.Field.AsDateTime) + else + Caption := FDataLink.Field.DisplayText + else + Caption := 'nil'; +end; + +function TJDBDateTimeEdit.GetReadOnly: boolean; +begin + Result := FDataLink.ReadOnly; +end; + +procedure TJDBDateTimeEdit.SetReadOnly(Value: boolean); +begin + inherited; + FDataLink.ReadOnly := Value; +end; + +procedure TJDBDateTimeEdit.SetDataField(const Value: string); +begin + FDataLink.FieldName := Value; +end; + +procedure TJDBDateTimeEdit.SetDataSource(Value: TDataSource); +begin + if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then + ChangeDataSource(Self, FDataLink, Value); +end; + +procedure TJDBDateTimeEdit.CMGetDataLink(var Message: TLMessage); +begin + Message.Result := PtrUInt(FDataLink); // Delphi dbctrls compatibility? +end; + +procedure TJDBDateTimeEdit.Loaded; +begin + inherited Loaded; + if (csDesigning in ComponentState) then + DataChange(Self); +end; + +procedure TJDBDateTimeEdit.Notification(AComponent: TComponent; Operation: TOperation); +begin + inherited Notification(AComponent, Operation); + // clean up + if (Operation = opRemove) then + begin + if (FDataLink <> nil) and (AComponent = DataSource) then + DataSource := nil; + end; +end; + +procedure TJDBDateTimeEdit.ActiveChange(Sender: TObject); +begin + if FDatalink.Active then + datachange(Sender) + else + Text := ''; +end; + +procedure TJDBDateTimeEdit.KeyDown(var Key: word; Shift: TShiftState); +begin + inherited KeyDown(Key, Shift); + if Key = VK_ESCAPE then + begin + FDataLink.Reset; + SelectAll; + Key := VK_UNKNOWN; + end + else + if Key in [VK_DELETE, VK_BACK] then + begin + if not IsReadOnly then + FDatalink.Edit + else + Key := VK_UNKNOWN; + end; +end; + +procedure TJDBDateTimeEdit.KeyPress(var Key: char); +begin + if not (Key in ['0'..'9', #8, #9, '.', '-', '/', ',', ':', ' ']) then + Key := #0 + else + if not IsReadOnly then + FDatalink.Edit; + inherited KeyPress(Key); +end; + +procedure TJDBDateTimeEdit.DoEnter; +begin + if FDataLink.Field <> nil then + Caption := FDataLink.Field.AsString; + inherited DoEnter; +end; + +constructor TJDBDateTimeEdit.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + ControlStyle := ControlStyle + [csReplicatable]; + FDataLink := TFieldDataLink.Create; + FDataLink.Control := Self; + FDataLink.OnDataChange := @DataChange; + FDataLink.OnUpdateData := @UpdateData; + FDataLInk.OnActiveChange := @ActiveChange; + // Set default values + //fFormat := ShortDateFormat; +end; + +destructor TJDBDateTimeEdit.Destroy; +begin + FDataLink.Free; + FDataLink := nil; + inherited Destroy; +end; + +procedure TJDBDateTimeEdit.EditingDone; +begin + inherited EditingDone; + if DataSource.State in [dsEdit, dsInsert] then + UpdateData(self); +end; + + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/jdbdatetimeedit_icon.lrs b/components/jujiboutils/jujibo-utils/src/jdbdatetimeedit_icon.lrs new file mode 100644 index 000000000..7195f4f07 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jdbdatetimeedit_icon.lrs @@ -0,0 +1,49 @@ +LazarusResources.Add('tjdbdatetimeedit','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#23#14 + +#5#13'}'#171#238#233#0#0#3#233'IDATH'#199#181#150']L'#155'U'#28#198#127'oi' + +#233'w'#161#133'A`'#3#198#16'p'#192'p'#3'D'#152#3#9's'#138#155'Qj'#212#152#24 + +#227#197#212#11#141#17'c'#194'.'#184'1Q'#226#136#154#204#152'x'#161#153#201 + +'LH'#156'.i6G'#22#199#220'`+'#3#17#28#31#11#3#25#155'P`PXi'#161'P'#250'y'#188 + +' L'#176'lCtOrr'#206#249#231#228#249#229'}'#206#251#190#231'HB'#8'6'#162#166 + +#227#159#150'+#'#220'5J'#149'og'#132'"B'#31#12#8'<'#243#30#199#188#155'6O@]' + +#247#252'['#181#173#0#210'J'#192#247#151'n'#137'oN'#223'X'#211#240#205'g'#183 + +#241'JI'#130#4'p'#233#199'O'#190#138#142#158'=hL'#169#140'T'#26'6'#161#212#24 + +#17'"'#132#219'9'#142'c'#180#143#241#254#11#243#174'9E'#221#203'U_~$'#9'!V' + +#25#127#241#206'#'#228'$'#235#184':'#226#198#238#244'bw'#249#176';'#189#156 + +#180#142#1#240'A'#137#157#204#132'IL)'#251#153'Z'#208#211';'#228#194'>'#179 + +'@ (0'#234'Ud'#167#233'0'#138#27'\'#187#248#29#147#246'@'#181'$'#132'`'#239 + +#161#22#145#155'n"5^MN'#138#158#184'h'#229'*s'#187#203#199#252'b'#16#149#223 + +#142'ys'#3'iEo'#211'7'#174'd'#218#233'%'#247'!'#19#209#6#25#2#9#135'+H{'#255 + +#20':'#165#140#237#134#1':N'#31'['#144#1'lK2'#208'3'#232#224#164'ul'#149#233 + +'J'#243#158'A'#7#169#161'NL'#201#229'Ly'#12'L8'#22'1'#151'm'#197#164#23'8' + +#220'nt'#6'-'#201'I'#6'*'#159'Lcr.'#196#180','#139#248#212#205#26'9@'#204'h' + +#19'1'#210'R'#214']'#13#191#135#229#175#4#30#149' YmCkz'#138#243#253#14#242 + +#178#226'X'#8#8#20#10#5#141'?[x'#241#5'3j'#149#138#198#230#203'de'#228#209 + +#218'9LEF!'#242'e'#147#170'*'#243'}'#223#156'k'#231'>C'#165'52>}'#155'}1j' + +#188'A'#129'V'#163'atd'#132#198#243#205#244'vw'#177#247#233#10#140'q'#26'n9' + +#22#137'*'#218#250'7`YG'#142'X'#238#10'(M'#245#18#10'y'#241#248'Bx'#131'K5' + +#187'k'#14#173'NGow'#23#7'*'#205'l'#207#217#193#176#203#143#223#31'B'#132'|' + +#225#128'{=I'#231#169'!\'#147#127#16#165'M'#228#230#196#2#233'['#162'@'#166 + +'"'#175#160#136#135'w'#228#160#137'2'#224#246#130'mb'#30#131'V'#198#204'X7' + +#178#181#140#204#181#131#152'k'#7#195'j'#214#145#24'l}'#205#20'f'#170'i'#189 + +'2'#137'B'#9'Z'#149#130'=%'#187#137'5'#26'P'#2':'#21#252'v'#197'Ni'#182#140 + +#225#158#203#225#128#127#26#175'T|'#214'>F'#175#219'0'#249#219'H'#210#187#249 + +#246#196#0#195'cN$'#175#31#201#227'g'#196#230#228#235#31#250'IV'#219#217#228 + +'9'#131'mh~1,"KM:'#245'->N4'#13#135#1#142#183'z'#200'U?'#134#236#220'O'#236 + +'*s'#147#24'S'#200#153'&'''#206#185' '#193#144'@'#175#129#226',A'#172#247',' + +#237'g'#219#241'G'#198#212#201#215#251#239#177#212#164#3'P'#223#146#194#133 + +#214#0#158#134'&b'#19#173'Tdd'#19#157#144#2'"'#192#237#209'A'#254'l'#187#202 + +#205'i'#5#153#187'_'#162#236#185#131#31#174#27'P'#223#226#227#213#199'#'#1 + +#232#245#238#164#234#181'b'#6':~'#161#185#161#27#181#188#3#191#223#143#206#24 + +'G'#247#245'E'#14'}'#252'9'#26#253#210#218'u'#3#150'"K'#185'37'#197'o'#161 + +#248#192#235#252':h'#225#153#253#187'x'#162't'#15#5#5#5'ttt'#0'0'#235#180#173 + +#13'X'#185#201#203'cKM:'#150#154#244'U'#243#245'J~'#183#172#239#181#15#255'F' + +#242#245'|'#193#255'Er'#128#195#135#223#149#154'/Z'#197#3'!'#8'!'#194#218#209 + +#163#199#196#251#239#189'!'#132#16#162#188#218'*'#252#129#160'('#175#182#222 + +'i'#203#245#229#177#16'B'#228#231#231#175#234']3#B'#8'q'#127#192'F'#181#12 + +#144#214':'#244'g'#157#182#255'%.Ct'#146'$m'#244'V'#177'^'#201'x'#192#250#11 + +#171'TF'#11#166#129'pf'#0#0#0#0'IEND'#174'B`'#130 +]); + diff --git a/components/jujiboutils/jujibo-utils/src/jdblabeleddatetimeedit.pas b/components/jujiboutils/jujibo-utils/src/jdblabeleddatetimeedit.pas new file mode 100644 index 000000000..a3c0b724d --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jdblabeleddatetimeedit.pas @@ -0,0 +1,352 @@ +{ JDBLabeledDateTimeEdit + + 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 JDBLabeledDateTimeEdit; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, LResources, Controls, ExtCtrls, DB, DBCtrls, LMessages, LCLType, Dialogs, + SysUtils; + +type + + { TJDBLabeledDateTimeEdit } + + TJDBLabeledDateTimeEdit = class(TCustomLabeledEdit) + private + fFormat: string; + FDataLink: TFieldDataLink; + + procedure DataChange(Sender: TObject); + procedure UpdateData(Sender: TObject); + procedure FocusRequest(Sender: TObject); + + function GetDataField: string; + function GetDataSource: TDataSource; + function GetField: TField; + + function IsReadOnly: boolean; + + function getFormat: string; + procedure setFormat(const AValue: string); + procedure formatInput; + + procedure SetDataField(const Value: string); + procedure SetDataSource(Value: TDataSource); + procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK; + + protected + procedure Loaded; override; + procedure Notification(AComponent: TComponent; Operation: TOperation); override; + procedure ActiveChange(Sender: TObject); virtual; + procedure KeyDown(var Key: word; Shift: TShiftState); override; + procedure KeyPress(var Key: char); override; + procedure DoEnter; override; + function GetReadOnly: boolean; override; + procedure SetReadOnly(Value: boolean); override; + + public + constructor Create(TheOwner: TComponent); override; + destructor Destroy; override; + procedure EditingDone; override; + property Field: TField read GetField; + + published + property DisplayFormat: string read getFormat write setFormat; + property DataField: string read GetDataField write SetDataField; + property DataSource: TDataSource read GetDataSource write SetDataSource; + property ReadOnly: boolean read GetReadOnly write SetReadOnly default False; + + // From TEdit + 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 + jcontrolutils; + +procedure Register; +begin + {$I jdblabeleddatetimeedit_icon.lrs} + RegisterComponents('Data Controls', [TJDBLabeledDateTimeEdit]); +end; + +procedure TJDBLabeledDateTimeEdit.DataChange(Sender: TObject); +begin + if FDataLink.Field <> nil then + begin + if not Focused then + formatInput + else + Caption := FDataLink.Field.AsString; + end + else + Text := ''; +end; + +procedure TJDBLabeledDateTimeEdit.UpdateData(Sender: TObject); +var + theValue: string; +begin + if FDataLink.Field <> nil then + begin + theValue := NormalizeDateTime(Text, FDataLink.Field.AsDateTime); + if Text = '' then + FDataLink.Field.Text := Text + else + if IsValidDateTimeString(theValue) then + begin + FDataLink.Field.Text := theValue; + end + else + begin + ShowMessage(Caption + ' no es un valor válido'); + Caption := FDataLink.Field.AsString; + SelectAll; + SetFocus; + end; + end + else + Text := ''; +end; + +procedure TJDBLabeledDateTimeEdit.FocusRequest(Sender: TObject); +begin + SetFocus; +end; + +function TJDBLabeledDateTimeEdit.GetDataField: string; +begin + Result := FDataLink.FieldName; +end; + +function TJDBLabeledDateTimeEdit.GetDataSource: TDataSource; +begin + Result := FDataLink.DataSource; +end; + +function TJDBLabeledDateTimeEdit.GetField: TField; +begin + Result := FDataLink.Field; +end; + +function TJDBLabeledDateTimeEdit.IsReadOnly: boolean; +begin + if FDatalink.Active then + Result := not FDatalink.CanModify + else + Result := False; +end; + +function TJDBLabeledDateTimeEdit.getFormat: string; +begin + Result := fFormat; +end; + +procedure TJDBLabeledDateTimeEdit.setFormat(const AValue: string); +begin + fFormat := AValue; + if not Focused then + formatInput; +end; + +procedure TJDBLabeledDateTimeEdit.formatInput; +begin + if FDataLink.Field <> nil then + if (fFormat <> '') and (not FDataLink.Field.IsNull) then + Caption := FormatDateTime(fFormat, FDataLink.Field.AsDateTime) + else + Caption := FDataLink.Field.DisplayText + else + Caption := 'nil'; +end; + +function TJDBLabeledDateTimeEdit.GetReadOnly: boolean; +begin + Result := FDataLink.ReadOnly; +end; + +procedure TJDBLabeledDateTimeEdit.SetReadOnly(Value: boolean); +begin + inherited; + FDataLink.ReadOnly := Value; +end; + +procedure TJDBLabeledDateTimeEdit.SetDataField(const Value: string); +begin + FDataLink.FieldName := Value; +end; + +procedure TJDBLabeledDateTimeEdit.SetDataSource(Value: TDataSource); +begin + if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then + ChangeDataSource(Self, FDataLink, Value); +end; + +procedure TJDBLabeledDateTimeEdit.CMGetDataLink(var Message: TLMessage); +begin + Message.Result := PtrUInt(FDataLink); // Delphi dbctrls compatibility? +end; + +procedure TJDBLabeledDateTimeEdit.Loaded; +begin + inherited Loaded; + if (csDesigning in ComponentState) then + DataChange(Self); +end; + +procedure TJDBLabeledDateTimeEdit.Notification(AComponent: TComponent; + Operation: TOperation); +begin + inherited Notification(AComponent, Operation); + // clean up + if (Operation = opRemove) then + begin + if (FDataLink <> nil) and (AComponent = DataSource) then + DataSource := nil; + end; +end; + +procedure TJDBLabeledDateTimeEdit.ActiveChange(Sender: TObject); +begin + if FDatalink.Active then + datachange(Sender) + else + Text := ''; +end; + +procedure TJDBLabeledDateTimeEdit.KeyDown(var Key: word; Shift: TShiftState); +begin + inherited KeyDown(Key, Shift); + if Key = VK_ESCAPE then + begin + FDataLink.Reset; + SelectAll; + Key := VK_UNKNOWN; + end + else + if Key in [VK_DELETE, VK_BACK] then + begin + if not IsReadOnly then + FDatalink.Edit + else + Key := VK_UNKNOWN; + end; +end; + +procedure TJDBLabeledDateTimeEdit.KeyPress(var Key: char); +begin + if not (Key in ['0'..'9', #8, #9, '.', '-', '/', ',', ':', ' ']) then + Key := #0 + else + if not IsReadOnly then + FDatalink.Edit; + inherited KeyPress(Key); +end; + +procedure TJDBLabeledDateTimeEdit.DoEnter; +begin + if FDataLink.Field <> nil then + Caption := FDataLink.Field.AsString; + inherited DoEnter; +end; + +constructor TJDBLabeledDateTimeEdit.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + ControlStyle := ControlStyle + [csReplicatable]; + FDataLink := TFieldDataLink.Create; + FDataLink.Control := Self; + FDataLink.OnDataChange := @DataChange; + FDataLink.OnUpdateData := @UpdateData; + FDataLInk.OnActiveChange := @ActiveChange; + // Set default values + //fFormat := ShortDateFormat; +end; + +destructor TJDBLabeledDateTimeEdit.Destroy; +begin + FDataLink.Free; + FDataLink := nil; + inherited Destroy; +end; + +procedure TJDBLabeledDateTimeEdit.EditingDone; +begin + inherited EditingDone; + if DataSource.State in [dsEdit, dsInsert] then + UpdateData(self); +end; + + +end. + diff --git a/components/jujiboutils/jujibo-utils/src/jdblabeleddatetimeedit_icon.lrs b/components/jujiboutils/jujibo-utils/src/jdblabeleddatetimeedit_icon.lrs new file mode 100644 index 000000000..0dea9dc68 --- /dev/null +++ b/components/jujiboutils/jujibo-utils/src/jdblabeleddatetimeedit_icon.lrs @@ -0,0 +1,49 @@ +LazarusResources.Add('tjdblabeleddatetimeedit','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#23#14 + +#6#30#210'8'#252#244#0#0#4#0'IDATH'#199#213#148'mL[U'#28#198#127#183#20'J'#11 + +#237'h'#7#155#128#131'1Vqc'#1#204'*'#17'67'#134']'#130#147'(|Pc'#140'!'#209 + +'-K4'#153','#139#144#134'/'#243'm7'#204'h'#208#24#253#160#139'b$SCR1'#16#151 + +#209#5#182#181#131'm'#213#133#23'q'#11#130#178#23#24#29#22#24#133#210#215#227 + +#135'Y'#194#155#11'['#162#137'Ors'#254#231#229'>'#191#156#243#156'{%'#238'Sm' + +#223#28'-VEyjT'#177#254#188#168#232'(m(('#240'N{'#221#211#30':'#189'Aum'#217 + +#254'#'#29#0#210#252#151#142#159#25#22#159'5'#15'.k'#184#175't'#3'/'#236'H' + +#145#0#206'|w'#228#147#132#132#219#175#232#211#203'bT'#186'$T'#26'=B'#132#241 + +'L'#12#227#190#222#199#240#229#182#233#201#169#232#218#231#15'~'#252#182#180 + +#216#248#195#215'r'#217#146#22'O'#239'U'#15#174#9#31#174'I?'#174#9#31'M'#246 + +#27#0#28'z'#220'EV'#242'('#134#244'='#220#154#209#210'30'#137'k|'#134'`H'#160 + +#215#198#146#157#25#143'^'#12#242#235#153#175#24'u'#5#171'$'#128#226'*'#187 + +#200'1'#26#200'X'#171'fK'#186#150'5'#9#170#5#230#174'I?'#211#179'!b'#3'.'#202 + +'S['#200'|'#236'U'#250#134'U'#140'M'#248#200#217'h A'#167'@ '#225#158#12'q' + +#225#242'-'#226'U'#10'6'#233#174#224'l'#174#159'Q'#0'lX'#167#163#187#223'M' + +#147#253#198#2#211#249#230#221#253'n2'#194'?aH+'#230#150'W'#199'M'#247','#229 + +'E'#235'1h'#5'n'#143#135'x]'#28'i'#235't'#148#153'3'#25#157#10'3'#166#216#204 + +#218#140'TM'#20#192#238#156'M'#135'S'#165#17'R'#165#17'n'#246#247'1'#208#211 + +#195#215#159'V'#147#20#173'&'#236#26'@'#233#30'$U'#26'!'#247#129'!'#214'e'#23 + +'q'#238'J'#128#220#135#147#136#211#196#160' '#140#181#169#137#204#13#25'<' + +#177'};)'#25'F'#214'o'#204#164#179'{'#148'<'#163#234'N'#200#213#213#31#137 + +#202#202#242#185'@KK'#203#230#234#230#230#239'q8'#206'#'#203'2'#0#22#139#133 + +'A'#159#145'o?x'#153'V'#199#5#226'T'#10#10'M'#166#5#23#226#203'S'#29'|'#209 + +'p'#137#202'='#160'X|['#234#234#172#152#205#21#0#152#205#21#212#213'Y'#145'e' + +#25#179#185#130#183#246'='#138','#203'x'#253'a,'#22#11#187#183#229'Sh2a'#177 + +'X0'#151'>'#13#192#137'N'''#190' '#4#2'aDx'#22#229'b@d''6['#253#130#218'f' + +#171#199#246#247#154'Uq'#10#146'r'#205#192#157']i'#18#147#217#127'`7'#182#230 + +#31#240#248#225#218#205'itq'#10#198'ot-'#5#0#148#191#219#191'd,'#186#224'=' + +#138'V'#217')'#201#153'!&K'#205'p'#151'mnnfl'#132'D}!'#0#241#177'p'#241#146 + +#139#157#217#10#134'~>'#183#244#136#230#155'G'#178#176'X,'#4':'#222#160#245 + +'D'#19#135#142#182'b'#8't"'#203'2'#207'U7'#240'y'#163#13'Y'#150#145#188#1#0 + +'J'#242'M'#164#169']$y'#127#228#218#192#244#236#178'!78'#252'4'#182#15'a'#173 + +'1.'#1#231#168'{)Z}'#150#188#162']'#140'*'#242#233#248'%'#200#196'T'#136'PX' + +#160#213'@'#193'fA'#162#239'$'#23'O^'#192#203#234'7'#149'+'#253#247'D`'#13 + +#142't'#218':'#130'x['#218'IL'#177'S'#242'P6'#9#201#233' '#130#252'y'#189#159 + +'?:{'#249'},'#154#172#194'g'#217#245#204#222#195'+'#6'48'#252#188#184'-'#6 + +#128#30'_'#30#149'/'#21'p'#197'y'#138#211'-]'#168#149'N'#2#129#0#241#250'5t' + +#253'6K'#245';'#239#163#209#222'Y'#187'b@c'#251#16#144'>'#215'7'#172'}'#144 + +#130#167'*8'#223'o'#229#201'='#143#176's'#199'vL&'#19'N'#167#19#128#219#19 + +#215#150#7#204#15'9R[k'#140'Xk'#140#11#250'+'#149#242#159#206#250'n9'#220#139 + +#148#243#191#224#127'CJ'#128#218#218#3'R'#251#233#179#130#255'J'#199#142#213 + +#139#131#175#239#21'B'#8'Q\e'#23#129'`H'#20'W'#217#231#158#200'x'#164#22'B' + +#136#173'['#183'.h'''#199#175#138#21#1#238'W'#17#128#180#28#224#174#244'{' + +#208'*}'#154#196#255'^'#127#1#218'f 9O'#6'WZ'#0#0#0#0'IEND'#174'B`'#130 +]); diff --git a/components/jujiboutils/jujibo-utils/src/jdbtimeedit.pas b/components/jujiboutils/jujibo-utils/src/jdbtimeedit.pas index 4a4ab5a60..3496e154d 100644 --- a/components/jujiboutils/jujibo-utils/src/jdbtimeedit.pas +++ b/components/jujiboutils/jujibo-utils/src/jdbtimeedit.pas @@ -1,3 +1,20 @@ +{ TJDBTimeEdit + + 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 JDBTimeEdit; {$mode objfpc}{$H+} diff --git a/components/jujiboutils/jujibo-utils/src/jlabeleddatetimeedit.pas b/components/jujiboutils/jujibo-utils/src/jlabeleddatetimeedit.pas index 9215d5d7d..8c57d72c6 100644 --- a/components/jujiboutils/jujibo-utils/src/jlabeleddatetimeedit.pas +++ b/components/jujiboutils/jujibo-utils/src/jlabeleddatetimeedit.pas @@ -1,3 +1,22 @@ +{ TJDateTimeEdit + + 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 JLabeledDateTimeEdit; {$mode objfpc}{$H+} diff --git a/components/jujiboutils/jujibo-utils/src/jlabeledtimeedit.pas b/components/jujiboutils/jujibo-utils/src/jlabeledtimeedit.pas index af77a9e17..e9d3ea9bb 100644 --- a/components/jujiboutils/jujibo-utils/src/jlabeledtimeedit.pas +++ b/components/jujiboutils/jujibo-utils/src/jlabeledtimeedit.pas @@ -1,3 +1,20 @@ +{ TJLabeledTimeEdit + + 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 JLabeledTimeEdit; {$mode objfpc}{$H+}