diff --git a/components/jujiboutils/changes.txt b/components/jujiboutils/changes.txt index b9ebd5f5a..a5a58bed5 100644 --- a/components/jujiboutils/changes.txt +++ b/components/jujiboutils/changes.txt @@ -5,6 +5,7 @@ Note: Lazarus Trunk required Version pre-1.1 -------------------------------------------------- +2013-06-17 Added: TJDBImageBlob. Display raw images from blob fields (read only) 2013-04-29 Fixed: TJDBGridControl Focus issues 2013-01-03 Added: TJDbEnumCombo, like TDbComboBox but, uses itemindex instead of text 2012-09-20 Added: TJLabeledIntegerEdit and TJLabeledFloatEdit property CurrentValue diff --git a/components/jujiboutils/jujiboutils.lpk b/components/jujiboutils/jujiboutils.lpk index ed667d27a..97a925acc 100644 --- a/components/jujiboutils/jujiboutils.lpk +++ b/components/jujiboutils/jujiboutils.lpk @@ -21,7 +21,7 @@ different kinds of data, floats, dates, etc. while working with db and non db controls."/> - + @@ -109,6 +109,11 @@ db and non db controls."/> + + + + + @@ -129,5 +134,8 @@ db and non db controls."/> + + <_ExternHelp Items="Count"/> + diff --git a/components/jujiboutils/jujiboutils.pas b/components/jujiboutils/jujiboutils.pas index cc7207a5a..9d97edad5 100644 --- a/components/jujiboutils/jujiboutils.pas +++ b/components/jujiboutils/jujiboutils.pas @@ -12,7 +12,7 @@ uses JLabeledIntegerEdit, JLabeledFloatEdit, JLabeledCurrencyEdit, JLabeledDateEdit, jdbgridutils, JLabeledTimeEdit, JDBLabeledTimeEdit, JLabeledDateTimeEdit, JDBLabeledDateTimeEdit, jinputconsts, JDbEnumCombo, - LazarusPackageIntf; + JDBImageBlob, LazarusPackageIntf; implementation @@ -33,6 +33,7 @@ begin RegisterUnit('JLabeledDateTimeEdit', @JLabeledDateTimeEdit.Register); RegisterUnit('JDBLabeledDateTimeEdit', @JDBLabeledDateTimeEdit.Register); RegisterUnit('JDbEnumCombo', @JDbEnumCombo.Register); + RegisterUnit('JDBImageBlob', @JDBImageBlob.Register); end; initialization diff --git a/components/jujiboutils/src/jdbimageblob.pas b/components/jujiboutils/src/jdbimageblob.pas new file mode 100644 index 000000000..7d681b799 --- /dev/null +++ b/components/jujiboutils/src/jdbimageblob.pas @@ -0,0 +1,214 @@ +{ JDBGridControl + + Copyright (C) 2013 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 JDBImageBlob; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DB, DBCtrls, + ExtCtrls, LMessages; + +type + + { TJDBImageBlob } + + TJDBImageBlob = class(TCustomImage) + private + FAutoDisplay: boolean; + { Private declarations } + FDataLink: TFieldDataLink; + + procedure DataChange(Sender: TObject); + procedure SetAutoDisplay(AValue: boolean); + + function GetDataField: string; + function GetDataSource: TDataSource; + function GetField: TField; + + procedure SetDataField(const Value: string); + procedure SetDataSource(Value: TDataSource); + procedure CMGetDataLink(var Message: TLMessage); message CM_GETDATALINK; + protected + { Protected declarations } + procedure Notification(AComponent: TComponent; Operation: TOperation); override; + procedure LoadPicture; virtual; + public + { Public declarations } + constructor Create(TheOwner: TComponent); override; + destructor Destroy; override; + property Field: TField read GetField; + published + { Published declarations } + + property DataField: string read GetDataField write SetDataField; + property DataSource: TDataSource read GetDataSource write SetDataSource; + property AutoDisplay: boolean read FAutoDisplay write SetAutoDisplay default True; + + property Align; + property Anchors; + property AutoSize; + property BorderSpacing; + property Center; + property Constraints; + property DragCursor; + property DragMode; + property OnClick; + property OnDblClick; + property PopupMenu; + property OnDragDrop; + property OnDragOver; + property OnEndDrag; + property OnMouseDown; + property OnMouseMove; + property OnMouseUp; + property OnStartDrag; + property Proportional; + property Stretch; + property Transparent; + property Visible; + + end; + +procedure Register; + +implementation + +procedure Register; +begin + {$I jdbimageblob_icon.lrs} + RegisterComponents('Data Controls', [TJDBImageBlob]); +end; + +{ TJDBImageBlob } + +procedure TJDBImageBlob.DataChange(Sender: TObject); +begin + if AutoDisplay then + LoadPicture; +end; + +procedure TJDBImageBlob.SetAutoDisplay(AValue: boolean); +begin + if FAutoDisplay = AValue then + Exit; + FAutoDisplay := AValue; + if FAutoDisplay then + LoadPicture; +end; + +function TJDBImageBlob.GetDataField: string; +begin + Result := FDataLink.FieldName; +end; + +function TJDBImageBlob.GetDataSource: TDataSource; +begin + Result := FDataLink.DataSource; +end; + +function TJDBImageBlob.GetField: TField; +begin + Result := FDataLink.Field; +end; + +procedure TJDBImageBlob.SetDataField(const Value: string); +begin + FDataLink.FieldName := Value; +end; + +procedure TJDBImageBlob.SetDataSource(Value: TDataSource); +begin + if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then + ChangeDataSource(Self, FDataLink, Value); +end; + +procedure TJDBImageBlob.CMGetDataLink(var Message: TLMessage); +begin + Message.Result := PtrUInt(FDataLink); +end; + +procedure TJDBImageBlob.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 TJDBImageBlob.LoadPicture; +var + s: TStream; +begin + if not assigned(FDatalink.Field) then + Picture.Assign(FDatalink.Field) + else + if FDatalink.field.IsBlob then + begin + if FDatalink.field is TBlobField then + begin + if FDatalink.Field.IsNull then + begin + Picture.Clear; + exit; + end; + s := FDataLink.DataSet.CreateBlobStream(FDataLink.Field, bmRead); + if (s = nil) or (s.Size = 0) then + begin + Picture.Clear; + exit; + end; + try + try + Picture.LoadFromStream(s); + finally + s.Free; + end; + except + Picture.Clear; // not a valid image + end; + end; + end; +end; + +constructor TJDBImageBlob.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + ControlStyle := ControlStyle + [csReplicatable]; + FAutoDisplay:=True; + FDataLink := TFieldDataLink.Create; + FDataLink.Control := Self; + FDataLink.OnDataChange := @DataChange; +end; + +destructor TJDBImageBlob.Destroy; +begin + FDataLink.Destroy; + FDataLink := nil; + inherited Destroy; +end; + +{ TJDBImageBlob } + + + +end. diff --git a/components/jujiboutils/src/jdbimageblob_icon.lrs b/components/jujiboutils/src/jdbimageblob_icon.lrs new file mode 100644 index 000000000..3e27a5610 --- /dev/null +++ b/components/jujiboutils/src/jdbimageblob_icon.lrs @@ -0,0 +1,49 @@ +LazarusResources.Add('TJDBImageBlob','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#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#221#6#14#14'&/oz'#180#181#0#0#4#11'IDATH' + +#199#189#150']lSe'#28#198#127#231#244#227't'#235#186#206'v06'#220'G'#231#230 + +#134'+['#12#17#182#140#128'!YLpF'#140#12#133'8"Dc'#136#4#18#18#141#23#222#24 + +#179'{'#23'o4'#8#243'B'#130'_'#132#168#141'Q'#151#152#128'#~'#19#182#140#137 + +'+'#20'a'#14#247#217#173#163'v'#237#233'y'#223#215#139#209#185'baH'#162#255 + +#171#247#227#201#243#203#255'y'#207'{'#206#129#255#184#180#165#147#227#167 + +#175#169#195#161'HN'#225#243#237#213#236#220'T'#166#221#21'`'#169'q'#247#139 + +'M'#4'+'#10#24#188#26'gb6'#197'D'#204'db6'#197'''}'#163'w'#5#178#3#28#14'Eh' + +#172#245#17'('#201'cb6'#197' d'#153'O'#196'L'#26'k}'#196#147#22#183#234#240 + +#182#128#234#242'B'#6#194'Q'#6#194#176#178#168#26' '#203#252#207#164'` '#28 + +'%'#163#253#250#223#2#0'Z'#214#174'`r'#184#143#157#155'6.n'#150'?'#244'45' + +#155#247'1}'#249'{'#6'N'#188'L'#231'k'#159#2#133#183#242'z'#20#8#1#13#192'Pf' + +'Q'#7#136#140#204'e){{{y'#246#133#131#140#252#248'>O6'#187'i~'#192#191#184'w' + +#179'v'#185#210'3m'#255'p~'#138#239#134#166#1'(--'#165'lu'#197#194'S'#160#235 + +#139#226#225'+1'#2#171#11#0'^'#7'$'#16#7':o'#242'|'#3#16#192#161#172#136#214 + +'7'#20'3'#233#240'3p'#2#130#193' '#0'+'#235#183#240#241#183'q'#166'#'#11#224 + +#251'+'#189#204#140']'#4'x'#21'x'#9'X'#3#188'u#'#154'L}'#9#140#0']'#192#187 + +'9#'#10#133'B'#236'~n?S'#225'S'#236'h'#245'fEt)'#252'[f'#248#21#240#25#144#15 + +#248#151'&|c'#221#5#248'rFd'#24#6#186#21'G'#10#193#220#240#23#184#230#250#1 + +#168#213#207#241'Dc'#28#128#237#29#219#251'[7'#182#158't:'#157't'#191#217#29 + +'>p'#240'@'#8#160'cGG'#127#235#198#214#147#14#135#3' '#154'3'#162#182#182'6' + +#0':;w'#211#180#174#149'D'#234#12#0'+VU'#177#186#188#130#142#167#158#225#163 + +#15#222#195'0'#12#246#237'?D'#160#182#137#169'hb'#225#156#134'#'#244#159#251 + +#153'={'#247#208's'#180''''#170#1#180#189'rF'#173'o(f'#165#215'I'#176#210#195 + +#150'F?Gz'#142#16#184'o-o'#127#248#13#186#211#141#221'&Q('#146')'#16'B"'#164 + +'D)'#176#132#192#18#18'!$'#150#144'()ho'#169#160#190#178#144'm'#143'o'#211 + +#236#0'{'#183#6'8'#250#249'e'#132'T'#4'+'#235#23#195'4'#211#22#174'|'#15#13 + +#193#18#30#219#236'&'#26'S'#132'N%'#152#185#158#129'(,K'#144#182'$'#166'%' + +#176','#137#153#154'''i'#166#179'/Z'#230#221'r'#252#244'5'#213'u'#236#2']' + +#199'`W=h'#26#20#228';y'#176'N'#163#174#188#133#185#226'q'#206'_'#188#132'}L' + +'CH'#137#148#10'KH'#210'f'#146'T"'#134#180'yH'#153'6'#236'z'#234#159'7y)'#8 + +'`'#215#209'w'#20#128#219#229'dj'#198#195#133'+C'#204#167'Lt-'#15#191'WGI' + +#137'T '#164'dj'#244'w'#226#147#191#226#242#215#224#246#172'B'#215#205#220 + +#128'\'#229'v9@'#249'8'#127'Q'#162#148#141'<'#195#134#203#161'PJ!'#149'":' + +#249#7#227#145#179#216#236'NH'#140'SZU'#139'6'#127#253#206#0'R'#8'f'#163#227 + +'L'#140':'#0'P'#168#133'X,'#129'iZX'#194'"<'#208#135'e'#153'8'#28#18#143'?' + +#159#232#216'e'#138#220':'#154#166'-'#15#176#132#224#167's'#191'pv'#240#18'J' + +'*,!H'#153'i'#146'I'#19#165#20#186#166'p'#234'i'#132'9'#143#166')'#18'CS'#216 + +#13'7'#219#183#182#220'Y'#7'J)lv'#3#167#145#143'R'#10#135'R'#228#229#1#222'l' + +#141#20'&f2AmI'#1'EEE'#148#149#20#146'N'#155#203#3'tM'#195'S'#224#193']'#224 + +#189#237'9Y'#150'E<'#30#167#253#145'u'#212#148#23'3w}'#14#159#207#183'<'#160 + +#242#222#18#30#222'PC<'#145#204#254#198'j'#127#207'2C'#133#15#183#1#209#153 + +'('#134#203#160'yC'#179'v[@ '#16#224#234'H'#132#186#170'{r'#252#30#220'l'#191 + +'P'#177#216',"mcM}='#255'['#253#5#142#151#214#137#152'G'#158#5#0#0#0#0'IEND' + +#174'B`'#130 +]);