1 { LazReport dialogs control
2 
3   Copyright (C) 2012-2014 alexs alexs75.at.yandex.ru
4 
5   This library is free software; you can redistribute it and/or modify it
6   under the terms of the GNU Library General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or (at your
8   option) any later version with the following modification:
9 
10   As a special exception, the copyright holders of this library give you
11   permission to link this library with independent modules to produce an
12   executable, regardless of the license terms of these independent modules,and
13   to copy and distribute the resulting executable under terms of your choice,
14   provided that you also meet, for each linked independent module, the terms
15   and conditions of the license of that module. An independent module is a
16   module which is not derived from or based on this library. If you modify
17   this library, you may extend this exception to your version of the library,
18   but you are not obligated to do so. If you do not wish to do so, delete this
19   exception statement from your version.
20 
21   This program is distributed in the hope that it will be useful, but WITHOUT
22   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
24   for more details.
25 
26   You should have received a copy of the GNU Library General Public License
27   along with this library; if not, write to the Free Software Foundation,
28   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.
29 }
30 
31 unit LRDialogControls;
32 
33 {$mode objfpc}{$H+}
34 
35 interface
36 
37 uses
38   Classes, SysUtils, Graphics, DB, LR_Class, Controls, StdCtrls, CheckLst,
39   LMessages, LCLType, LCLIntf, Buttons, EditBtn, Themes, ButtonPanel, ExtCtrls;
40 
41 type
42   TLRDialogControls = class(TComponent)
43   end;
44 
45   { TlrVisualControl }
46 
47   TlrVisualControl = class(TfrControl)
48   private
GetAutoSizenull49     function GetAutoSize: Boolean;
GetCaptionnull50     function GetCaption: string;
GetColornull51     function GetColor: TColor;
GetEnablednull52     function GetEnabled: boolean;
GetFontnull53     function GetFont: TFont;
GetHintnull54     function GetHint: string;
GetOnClicknull55     function GetOnClick: TfrScriptStrings;
56     procedure SetAutoSize(AValue: Boolean);
57     procedure SetCaption(AValue: string);
58     procedure SetColor(AValue: TColor);
59     procedure SetEnabled(AValue: boolean);
60     procedure SetFont(AValue: TFont);
61     procedure OnClickHandle(Sender: TObject);
62     procedure SetHint(AValue: string);
63     procedure SetOnClick(AValue: TfrScriptStrings);
64   protected
65     FControl: TControl;
66     procedure SetVisible(AValue: Boolean);override;
67     procedure PaintDesignControl; override;
68     procedure SetName(const AValue: string); override;
69     procedure AfterCreate;override;
CreateControlnull70     function CreateControl:TControl;virtual;abstract;
71   public
72     constructor Create(AOwnerPage:TfrPage); override;
73     destructor Destroy; override;
74     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
75     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
76     procedure UpdateControlPosition; override;
77     procedure AttachToParent; override;
78     procedure Assign(Source: TPersistent); override;
79 
80     property Control: TControl read FControl write FControl;
81     property AutoSize: Boolean read GetAutoSize write SetAutoSize;
82     property Color:TColor read GetColor write SetColor;
83     property Caption:string read GetCaption write SetCaption;
84     property Text:string read GetCaption write SetCaption;
85     property Font:TFont read GetFont write SetFont;
86     property Hint:string read GetHint write SetHint;
87     property OnClick:TfrScriptStrings read GetOnClick write SetOnClick;
88   published
89     property Enabled:boolean read GetEnabled write SetEnabled;
90   end;
91   TlrVisualControlClass = class of TlrVisualControl;
92 
93   { TlrLabel }
94 
95   TlrLabel = class(TlrVisualControl)
96   private
GetAlignmentnull97     function GetAlignment: TAlignment;
GetWordWrapnull98     function GetWordWrap: boolean;
99     procedure SetAlignment(AValue: TAlignment);
100     procedure SetWordWrap(AValue: boolean);
101   protected
102     procedure PaintDesignControl; override;
CreateControlnull103     function CreateControl:TControl;override;
104   public
105     constructor Create(AOwnerPage:TfrPage); override;
106     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
107     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
108     procedure Assign(Source: TPersistent); override;
109   published
110     property Alignment: TAlignment read GetAlignment write SetAlignment;
111     property WordWrap:boolean read GetWordWrap write SetWordWrap;
112     property AutoSize;
113     property Color;
114     property Caption;
115     property Font;
116     property Hint;
117     property OnClick;
118   end;
119 
120   { TlrEdit }
121 
122   TlrEdit = class(TlrVisualControl)
123   private
124   protected
125     procedure PaintDesignControl; override;
CreateControlnull126     function CreateControl:TControl;override;
127   public
128     constructor Create(AOwnerPage:TfrPage); override;
129     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
130     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
131   published
132     property Color;
133     property Enabled;
134     property Text;
135     property Hint;
136     property OnClick;
137   end;
138 
139   { TlrMemo }
140 
141   TlrMemo = class(TlrVisualControl)
142   private
143     procedure MemoChange(Sender: TObject);
144   protected
145     procedure PaintDesignControl; override;
CreateControlnull146     function CreateControl:TControl;override;
GetTextnull147     function GetText:string;override;
148     procedure SetText(AValue:string);override;
149   public
150     constructor Create(AOwnerPage:TfrPage); override;
151     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
152     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
153   published
154     property Color;
155     property Enabled;
156     property Memo;
157     property Hint;
158     property OnClick;
159   end;
160 
161   { TlrButton }
162 
163   TlrButton = class(TlrVisualControl)
164   private
GetKindnull165     function GetKind: TBitBtnKind;
166     procedure SetKind(AValue: TBitBtnKind);
167   protected
168     procedure PaintDesignControl; override;
CreateControlnull169     function CreateControl:TControl;override;
170   public
171     constructor Create(AOwnerPage:TfrPage); override;
172     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
173     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
174     procedure Assign(Source: TPersistent); override;
175   published
176     property AutoSize;
177     property Color;
178     property Enabled;
179     property Caption;
180     property Hint;
181     property Kind: TBitBtnKind read GetKind write SetKind;
182     property OnClick;
183   end;
184 
185   { TlrCheckBox }
186 
187   TlrCheckBox = class(TlrVisualControl)
188   private
GetCheckednull189     function GetChecked: boolean;
190     procedure SetChecked(AValue: boolean);
191   protected
192     procedure PaintDesignControl; override;
CreateControlnull193     function CreateControl:TControl;override;
GetCheckStylenull194     function GetCheckStyle(ACheck:boolean):TThemedButton;virtual;
195   public
196     constructor Create(AOwnerPage:TfrPage); override;
197     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
198     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
199     procedure Assign(Source: TPersistent); override;
200   published
201     property AutoSize;
202     property Color;
203     property Enabled;
204     property Caption;
205     property Hint;
206     property Checked:boolean read GetChecked write SetChecked;
207     property OnClick;
208   end;
209 
210   { TlrRadioButton }
211 
212   TlrRadioButton = class(TlrCheckBox)
213   protected
CreateControlnull214     function CreateControl:TControl;override;
GetCheckStylenull215     function GetCheckStyle(ACheck:boolean):TThemedButton;override;
216   public
217     constructor Create(AOwnerPage:TfrPage); override;
218   end;
219 
220   { TlrListBox }
221 
222   TlrListBox = class(TlrVisualControl)
223   private
GetItemIndexnull224     function GetItemIndex: integer;
GetItemsnull225     function GetItems: TStrings;
226     procedure SetItemIndex(AValue: integer);
227     procedure SetItems(AValue: TStrings);
228   protected
229     procedure PaintDesignControl; override;
CreateControlnull230     function CreateControl:TControl;override;
231   public
232     constructor Create(AOwnerPage:TfrPage); override;
233     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
234     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
235     procedure Assign(Source: TPersistent); override;
236   published
237     property Color;
238     property Enabled;
239     property Items:TStrings read GetItems write SetItems;
240     property ItemIndex:integer read GetItemIndex write SetItemIndex;
241     property Hint;
242     property OnClick;
243   end;
244 
245   { TlrComboBox }
246 
247   TlrComboBox = class(TlrVisualControl)
248   private
GetDropDownCountnull249     function GetDropDownCount: integer;
GetItemIndexnull250     function GetItemIndex: integer;
GetItemsnull251     function GetItems: TStrings;
GetStylenull252     function GetStyle: TComboBoxStyle;
253     procedure SetDropDownCount(AValue: integer);
254     procedure SetItemIndex(AValue: integer);
255     procedure SetItems(AValue: TStrings);
256     procedure SetStyle(AValue: TComboBoxStyle);
257   protected
258     procedure PaintDesignControl; override;
CreateControlnull259     function CreateControl:TControl;override;
260   public
261     constructor Create(AOwnerPage:TfrPage); override;
262     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
263     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
264     procedure Assign(Source: TPersistent); override;
265   published
266     property Color;
267     property Enabled;
268     property Text;
269     property AutoSize;
270     property Hint;
271     property Style:TComboBoxStyle read GetStyle write SetStyle;
272     property Items:TStrings read GetItems write SetItems;
273     property ItemIndex:integer read GetItemIndex write SetItemIndex;
274     property DropDownCount:integer read GetDropDownCount write SetDropDownCount;
275     property OnClick;
276   end;
277 
278   { TlrDateEdit }
279 
280   TlrDateEdit = class(TlrVisualControl)
281   private
GetDatenull282     function GetDate: TDateTime;
283     procedure SetDate(AValue: TDateTime);
284   protected
285     procedure PaintDesignControl; override;
CreateControlnull286     function CreateControl:TControl;override;
287   public
288     constructor Create(AOwnerPage:TfrPage); override;
289     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
290     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
291     procedure Assign(Source: TPersistent); override;
292   published
293     property Color;
294     property Enabled;
295     property Hint;
296     property Date:TDateTime read GetDate write SetDate;
297     property OnClick;
298   end;
299 
300   { TlrButtonPanel }
301 
302   TlrButtonPanel = class(TlrVisualControl)
303   private
GetButtonOrdernull304     function GetButtonOrder: TButtonOrder;
GetShowButtonsnull305     function GetShowButtons: TPanelButtons;
306     procedure SetButtonOrder(AValue: TButtonOrder);
307     procedure SetShowButtons(AValue: TPanelButtons);
308   protected
309     procedure PaintDesignControl; override;
CreateControlnull310     function CreateControl:TControl;override;
311     procedure AfterCreate;override;
312   public
313     constructor Create(AOwnerPage:TfrPage); override;
314     procedure UpdateControlPosition; override;
315     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
316     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
317     procedure Assign(Source: TPersistent); override;
318   published
319     property ButtonOrder: TButtonOrder read GetButtonOrder write SetButtonOrder default boDefault;
320     property ShowButtons: TPanelButtons read GetShowButtons write SetShowButtons default DefShowButtons;
321     property Color;
322     property Enabled;
323     property Text;
324     property Hint;
325     property OnClick;
326   end;
327 
328   { TlrCheckListBox }
329 
330   TlrCheckListBox = class(TlrVisualControl)
331   private
GetItemIndexnull332     function GetItemIndex: integer;
GetItemsnull333     function GetItems: TStrings;
GetItemsCountnull334     function GetItemsCount: integer;
335     procedure SetItemIndex(AValue: integer);
336     procedure SetItems(AValue: TStrings);
337   protected
338     procedure PaintDesignControl; override;
CreateControlnull339     function CreateControl:TControl;override;
ExecMetodnull340     function ExecMetod(const AName: String; p1, p2, p3: Variant; var Val: Variant):boolean;override;
341   public
342     constructor Create(AOwnerPage:TfrPage); override;
343     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
344     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
345     procedure Assign(Source: TPersistent); override;
346   published
347     property Color;
348     property Enabled;
349     property Items:TStrings read GetItems write SetItems;
350     property ItemIndex:integer read GetItemIndex write SetItemIndex;
351     property ItemsCount:integer read GetItemsCount;
352     property Hint;
353     property OnClick;
354   end;
355 
356   { TlrRadioGroup }
357 
358   TlrRadioGroup = class(TlrVisualControl)
359   private
GetItemIndexnull360     function GetItemIndex: integer;
GetItemsnull361     function GetItems: TStrings;
GetItemsCountnull362     function GetItemsCount: integer;
363     procedure SetItemIndex(AValue: integer);
364     procedure SetItems(AValue: TStrings);
365   protected
366     procedure PaintDesignControl; override;
CreateControlnull367     function CreateControl:TControl;override;
368   public
369     constructor Create(AOwnerPage:TfrPage); override;
370     procedure LoadFromXML(XML: TLrXMLConfig; const Path: String); override;
371     procedure SaveToXML(XML: TLrXMLConfig; const Path: String); override;
372     procedure Assign(Source: TPersistent); override;
373   published
374     property Color;
375     property Enabled;
376     property Items:TStrings read GetItems write SetItems;
377     property ItemIndex:integer read GetItemIndex write SetItemIndex;
378     property ItemsCount:integer read GetItemsCount;
379     property Hint;
380     property OnClick;
381     property Caption;
382   end;
383 
384 procedure Register;
385 
386 procedure DoRegsiterControl(var cmpBMP:TBitmap; lrClass:TlrVisualControlClass);
387 implementation
388 
389 uses typinfo, types, lrDBDialogControls, math, lrFormStorage;
390 
391 {$R lrdialogcontrols_img.res}
392 
393 procedure Register;
394 begin
395   RegisterComponents('LazReport',[TLRDialogControls]);
396 end;
397 
398 var
399   lrBMP_LRLabel:TBitmap = nil;
400   lrBMP_LREdit:TBitmap = nil;
401   lrBMP_LRButton:TBitmap = nil;
402   lrBMP_LRCheckBox:TBitmap = nil;
403   lrBMP_LRComboBox:TBitmap = nil;
404   lrBMP_LRRadioButton:TBitmap = nil;
405   lrBMP_LRMemo:TBitmap = nil;
406   lrBMP_LRListBox:TBitmap = nil;
407   lrBMP_LRDateEdit:TBitmap = nil;
408   lrBMP_LRButtonPanel:TBitmap = nil;
409   lrBMP_LRCheckListBox:TBitmap = nil;
410   lrBMP_LRRadioGroupBox:TBitmap = nil;
411 
412 procedure DoRegsiterControl(var cmpBMP:TBitmap; lrClass:TlrVisualControlClass);
413 begin
414   if not assigned(cmpBMP) then
415   begin
416     cmpBMP := TBitmap.Create;
417     cmpBMP.LoadFromResourceName(HInstance, lrClass.ClassName);
418     frRegisterObject(lrClass, cmpBMP, lrClass.ClassName, nil, otlUIControl, nil);
419   end;
420 end;
421 
422 procedure InitLRComp;
423 begin
424   DoRegsiterControl(lrBMP_LRLabel, TlrLabel);
425   DoRegsiterControl(lrBMP_LREdit, TlrEdit);
426   DoRegsiterControl(lrBMP_LRMemo, TlrMemo);
427   DoRegsiterControl(lrBMP_LRButton, TlrButton);
428   DoRegsiterControl(lrBMP_LRCheckBox, TlrCheckBox);
429   DoRegsiterControl(lrBMP_LRComboBox, TlrComboBox);
430   DoRegsiterControl(lrBMP_LRRadioButton, TlrRadioButton);
431   DoRegsiterControl(lrBMP_LRListBox, TlrListBox);
432   DoRegsiterControl(lrBMP_LRDateEdit, TlrDateEdit);
433   DoRegsiterControl(lrBMP_LRButtonPanel, TlrButtonPanel);
434   DoRegsiterControl(lrBMP_LRCheckListBox, TlrCheckListBox);
435   DoRegsiterControl(lrBMP_LRRadioGroupBox, TlrRadioGroup);
436 end;
437 
438 procedure DoneLRComp;
439 begin
440   if Assigned(lrBMP_LRLabel) then
441     FreeAndNil(lrBMP_LRLabel);
442   if Assigned(lrBMP_LREdit) then
443     FreeAndNil(lrBMP_LREdit);
444   if Assigned(lrBMP_LRButton) then
445     FreeAndNil(lrBMP_LRButton);
446   if Assigned(lrBMP_LRCheckBox) then
447     FreeAndNil(lrBMP_LRCheckBox);
448   if Assigned(lrBMP_LRComboBox) then
449     FreeAndNil(lrBMP_LRComboBox);
450   if Assigned(lrBMP_LRRadioButton) then
451     FreeAndNil(lrBMP_LRRadioButton);
452   if Assigned(lrBMP_LRMemo) then
453     FreeAndNil(lrBMP_LRMemo);
454   if Assigned(lrBMP_LRListBox) then
455     FreeAndNil(lrBMP_LRListBox);
456   if Assigned(lrBMP_LRDateEdit) then
457     FreeAndNil(lrBMP_LRDateEdit);
458   if Assigned(lrBMP_LRButtonPanel) then
459     FreeAndNil(lrBMP_LRButtonPanel);
460   if Assigned(lrBMP_LRCheckListBox) then
461     FreeAndNil(lrBMP_LRCheckListBox);
462   if Assigned(lrBMP_LRRadioGroupBox) then
463     FreeAndNil(lrBMP_LRRadioGroupBox);
464 end;
465 
466 { TlrRadioGroup }
467 
GetItemIndexnull468 function TlrRadioGroup.GetItemIndex: integer;
469 begin
470   Result:=TRadioGroup(FControl).ItemIndex;
471 end;
472 
TlrRadioGroup.GetItemsnull473 function TlrRadioGroup.GetItems: TStrings;
474 begin
475   Result:=TRadioGroup(FControl).Items;
476 end;
477 
GetItemsCountnull478 function TlrRadioGroup.GetItemsCount: integer;
479 begin
480   Result:=TRadioGroup(FControl).Items.Count;
481 end;
482 
483 procedure TlrRadioGroup.SetItemIndex(AValue: integer);
484 begin
485   TRadioGroup(FControl).ItemIndex:=AValue;
486 end;
487 
488 procedure TlrRadioGroup.SetItems(AValue: TStrings);
489 begin
490   TRadioGroup(FControl).Items:=AValue;
491   if Assigned(frDesigner) then
492     frDesigner.Modified:=true;
493 end;
494 
495 procedure TlrRadioGroup.PaintDesignControl;
496 var
497   AY, aH, i:integer;
498   S:string;
499 
500 var
501   details, details_chek: TThemedElementDetails;
502   PaintRect: TRect;
503   CSize: TSize;
504 begin
505   Canvas.Frame3d(DRect, 1, bvLowered);
506   Canvas.Brush.Color := Color; // FControl.Color;
507   Canvas.FillRect(DRect);
508   Canvas.Font:=FControl.Font;
509 
510   AY:=DRect.Top + 3;
511   aH:=Canvas.TextHeight('Wg');
512 
513   if Text<>'' then
514   begin
515     Canvas.TextRect(DRect, DRect.Left + 3, AY, Text);
516     inc(AY, aH + 3);
517   end;
518   i:=0;
519 
520   Details := ThemeServices.GetElementDetails(tbRadioButtonUncheckedNormal);
521   details_chek:=ThemeServices.GetElementDetails(tbRadioButtonCheckedNormal);
522   CSize := ThemeServices.GetDetailSize(Details);
523 
524 
525   while (AY < DRect.Bottom) and (i<TRadioGroup(FControl).Items.Count) do
526   begin
527     PaintRect := Bounds(DRect.Left, AY, CSize.cx, CSize.cy);
528     if ItemIndex = i then
529       ThemeServices.DrawElement(Canvas.Handle, details_chek, PaintRect, nil)
530     else
531       ThemeServices.DrawElement(Canvas.Handle, Details, PaintRect, nil);
532 
533 
534 
535     S:=TRadioGroup(FControl).Items[i];
536     Canvas.TextRect(DRect, DRect.Left + 3 + CSize.cx, AY, S);
537     inc(AY, aH + 3);
538     inc(i);
539   end;
540 end;
541 
542 
TlrRadioGroup.CreateControlnull543 function TlrRadioGroup.CreateControl: TControl;
544 begin
545   Result:=TRadioGroup.Create(nil);
546   TRadioGroup(Result).OnClick:=@OnClickHandle;
547 end;
548 
549 constructor TlrRadioGroup.Create(AOwnerPage: TfrPage);
550 begin
551   inherited Create(AOwnerPage);
552   BaseName := 'lrRadioGroup';
553   AutoSize:=false;
554 end;
555 
556 procedure TlrRadioGroup.LoadFromXML(XML: TLrXMLConfig; const Path: String);
557 begin
558   inherited LoadFromXML(XML, Path);
559   Items.Text:=XML.GetValue(Path+'Items/Text/Value'{%H-}, '');
560   ItemIndex:=XML.GetValue(Path+'ItemIndex/Value'{%H-}, -1);
561 end;
562 
563 procedure TlrRadioGroup.SaveToXML(XML: TLrXMLConfig; const Path: String);
564 begin
565   inherited SaveToXML(XML, Path);
566   XML.SetValue(Path+'Items/Text/Value'{%H-}, Items.Text);
567   XML.SetValue(Path+'ItemIndex/Value'{%H-}, ItemIndex);
568 end;
569 
570 procedure TlrRadioGroup.Assign(Source: TPersistent);
571 begin
572   inherited Assign(Source);
573   if Source is TlrRadioGroup then
574   begin
575     Items.Assign(TlrRadioGroup(Source).Items);
576     ItemIndex:=TlrRadioGroup(Source).ItemIndex;
577   end;
578 end;
579 
580 { TlrCheckListBox }
581 
TlrCheckListBox.GetItemIndexnull582 function TlrCheckListBox.GetItemIndex: integer;
583 begin
584   Result:=TCheckListBox(FControl).ItemIndex;
585 end;
586 
TlrCheckListBox.GetItemsnull587 function TlrCheckListBox.GetItems: TStrings;
588 begin
589   Result:=TCheckListBox(FControl).Items;
590 end;
591 
GetItemsCountnull592 function TlrCheckListBox.GetItemsCount: integer;
593 begin
594   Result:=TCheckListBox(FControl).Items.Count;
595 end;
596 
597 procedure TlrCheckListBox.SetItemIndex(AValue: integer);
598 begin
599   TCheckListBox(FControl).ItemIndex:=AValue;
600 end;
601 
602 procedure TlrCheckListBox.SetItems(AValue: TStrings);
603 begin
604   TCheckListBox(FControl).Items:=AValue;
605   if Assigned(frDesigner) then
606     frDesigner.Modified:=true;
607 end;
608 
609 procedure TlrCheckListBox.PaintDesignControl;
610 var
611   AY, aH, i:integer;
612   S:string;
613 
614 var
615 //  ChkBitmap: TBitmap;
616 //  XPos,YPos: Integer;
617   details: TThemedElementDetails;
618   PaintRect: TRect;
619   CSize: TSize;
620 //  bmpAlign: TAlignment;
621 begin
622   Canvas.Frame3d(DRect, 1, bvLowered);
623   Canvas.Brush.Color := FControl.Color;
624   Canvas.FillRect(DRect);
625   Canvas.Font:=FControl.Font;
626   AY:=DRect.Top + 1;
627   i:=0;
628 
629   Details := ThemeServices.GetElementDetails(tbCheckBoxUncheckedNormal);
630   CSize := ThemeServices.GetDetailSize(Details);
631 
632   aH:=Max(Canvas.TextHeight(Text) div 2, CSize.cy);
633 
634   while (AY < DRect.Bottom) and (i<TListBox(FControl).Items.Count) do
635   begin
636     PaintRect := Bounds(DRect.Left, AY, CSize.cx, CSize.cy);
637     ThemeServices.DrawElement(Canvas.Handle, Details, PaintRect, nil);
638 
639 
640     S:=TCheckListBox(FControl).Items[i];
641     Canvas.TextRect(DRect, DRect.Left + 3 + CSize.cx, AY, S);
642     inc(AY, aH + 3);
643     inc(i);
644   end;
645 end;
646 
TlrCheckListBox.CreateControlnull647 function TlrCheckListBox.CreateControl: TControl;
648 begin
649   Result:=TCheckListBox.Create(nil);
650 end;
651 
ExecMetodnull652 function TlrCheckListBox.ExecMetod(const AName: String; p1, p2, p3: Variant;
653   var Val: Variant): boolean;
654 begin
655   if AName = 'SETINDEXPROPERTY' then
656   begin
657     if p1 = 'CHECKED' then
658       TCheckListBox(FControl).Checked[p2]:=p3
659     else
660     if p1 = 'ITEMS' then
661       TCheckListBox(FControl).Items[p2]:=p3
662   end
663   else
664   if AName = 'GETINDEXPROPERTY' then
665   begin
666     if p1 = 'CHECKED' then
667       Val:=TCheckListBox(FControl).Checked[p2]
668     else
669     if p1 = 'ITEMS' then
670       Val:=TCheckListBox(FControl).Items[p2]
671   end
672   else
673   if AName = 'ITEMS.ADD' then
674     Val:=TCheckListBox(FControl).Items.Add(frParser.Calc(P1))
675   else
676   if AName = 'ITEMS.DELETE' then
677     TCheckListBox(FControl).Items.Delete(frParser.Calc(P1))
678   else
679   if AName = 'ITEMS.CLEAR' then
680     TCheckListBox(FControl).Items.Clear
681   else
682   if AName = 'ITEMS.INDEXOF' then
683     Val:=TCheckListBox(FControl).Items.IndexOf(frParser.Calc(P1))
684 end;
685 
686 constructor TlrCheckListBox.Create(AOwnerPage: TfrPage);
687 begin
688   inherited Create(AOwnerPage);
689   BaseName := 'lrCheckListBox';
690   AutoSize:=true;
691 end;
692 
693 procedure TlrCheckListBox.LoadFromXML(XML: TLrXMLConfig; const Path: String);
694 begin
695   inherited LoadFromXML(XML, Path);
696   Items.Text:=XML.GetValue(Path+'Items/Text/Value'{%H-}, '');
697   ItemIndex:=XML.GetValue(Path+'ItemIndex/Value'{%H-}, -1);
698 end;
699 
700 procedure TlrCheckListBox.SaveToXML(XML: TLrXMLConfig; const Path: String);
701 begin
702   inherited SaveToXML(XML, Path);
703   XML.SetValue(Path+'Items/Text/Value'{%H-}, Items.Text);
704   XML.SetValue(Path+'ItemIndex/Value'{%H-}, ItemIndex);
705 end;
706 
707 procedure TlrCheckListBox.Assign(Source: TPersistent);
708 begin
709   inherited Assign(Source);
710   if Source is TlrCheckListBox then
711   begin
712     Items.Assign(TlrCheckListBox(Source).Items);
713     ItemIndex:=TlrCheckListBox(Source).ItemIndex;
714   end;
715 end;
716 
717 { TlrButtonPanel }
718 
GetButtonOrdernull719 function TlrButtonPanel.GetButtonOrder: TButtonOrder;
720 begin
721   Result:= TButtonPanel(FControl).ButtonOrder;
722 end;
723 
TlrButtonPanel.GetShowButtonsnull724 function TlrButtonPanel.GetShowButtons: TPanelButtons;
725 begin
726   Result:= TButtonPanel(FControl).ShowButtons;
727 end;
728 
729 procedure TlrButtonPanel.SetButtonOrder(AValue: TButtonOrder);
730 begin
731   TButtonPanel(FControl).ButtonOrder:=AValue;
732 end;
733 
734 procedure TlrButtonPanel.SetShowButtons(AValue: TPanelButtons);
735 begin
736   TButtonPanel(FControl).ShowButtons:=AValue;
737 end;
738 
739 procedure TlrButtonPanel.PaintDesignControl;
740 var
741   AY, AX, aH, aW, W1:integer;
742   R1:TRect;
743   i:TPanelButton;
744 
745   B:TPanelBitBtn;
746   TR: TTextStyle;
747 begin
748   AY:=(DRect.Top + DRect.Bottom) div 2;
749   aH:=Canvas.TextHeight(Text) div 2;
750   Canvas.Frame3d(DRect, 1, bvLowered);
751   Canvas.Brush.Color := FControl.Color;
752   Canvas.FillRect(DRect);
753 
754   R1:=DRect;
755   R1.Right:=R1.Right - 6;
756   R1.Top:=R1.Top + 6;
757   R1.Bottom:=R1.Bottom - 6;
758 
759   for i:=Low(TPanelButton) to High(TPanelButton) do
760   begin
761     if i in ShowButtons then
762     begin
763 
764       case i of
765         pbOK:B:=TButtonPanel(FControl).OKButton;
766         pbCancel:B:=TButtonPanel(FControl).CancelButton;
767         pbClose:B:=TButtonPanel(FControl).CloseButton;
768         pbHelp:B:=TButtonPanel(FControl).HelpButton;
769       else
770         b:=nil;
771       end;
772       if Assigned(B) then
773       begin
774         if B.Width <= 0 then
775           W1:=75
776         else
777           W1:=B.Width;
778 
779         R1.Left:=R1.Right - W1;
780 
781         DrawFrameControl(Canvas.Handle, R1, DFC_BUTTON, DFCS_BUTTONPUSH);
782 
783         AX:=(R1.Left +  R1.Right) div 2;
784         AY:=(R1.Top +  R1.Bottom) div 2;
785         aW:=Canvas.TextWidth(B.Caption);
786         aH:=Canvas.TextHeight(B.Caption) div 2;
787 
788         FillChar(TR,SizeOf(TR),0);
789         TR.ShowPrefix := true;
790 
791         if aW>W1 then
792           Canvas.TextRect(R1, 0, AY - aH, B.Caption, TR)
793         else
794           Canvas.TextRect(R1, AX - (aW div 2), AY - aH, B.Caption, TR)
795 
796       end;
797       R1.Right:=R1.Left - 6;
798     end;
799   end;
800 end;
801 
TlrButtonPanel.CreateControlnull802 function TlrButtonPanel.CreateControl: TControl;
803 begin
804   Result:=TButtonPanel.Create(nil);
805 end;
806 
807 procedure TlrButtonPanel.AfterCreate;
808 begin
809   inherited AfterCreate;
810   FControl.OnClick:=nil;
811   TButtonPanel(FControl).OKButton.OnClick:=@OnClickHandle;
812 end;
813 
814 constructor TlrButtonPanel.Create(AOwnerPage: TfrPage);
815 begin
816   inherited Create(AOwnerPage);
817   BaseName := 'lrButtonPanel';
818   AutoSize:=true;
819   UpdateControlPosition;
820 end;
821 
822 procedure TlrButtonPanel.UpdateControlPosition;
823 begin
824   X:=2;
825   if Assigned(OwnerPage) then
826   begin
827     Y:=OwnerPage.Height - FControl.Height - 4;
828     Dx:=OwnerPage.Width-8;
829   end
830   else
831   begin
832     Y:=2;
833     DX:=FControl.Width;
834   end;
835   Dy:=FControl.Height;
836 end;
837 
838 procedure TlrButtonPanel.LoadFromXML(XML: TLrXMLConfig; const Path: String);
839 begin
840   inherited LoadFromXML(XML, Path);
841   RestoreProperty('ButtonOrder',XML.GetValue(Path+'ButtonOrder', 'boDefault'));
842   RestoreProperty('ShowButtons',XML.GetValue(Path+'ShowButtons', 'pbOK, pbCancel, pbClose, pbHelp'));
843   UpdateControlPosition;
844 end;
845 
846 procedure TlrButtonPanel.SaveToXML(XML: TLrXMLConfig; const Path: String);
847 begin
848   inherited SaveToXML(XML, Path);
849   XML.SetValue(Path+'ButtonOrder', GetSaveProperty('ButtonOrder'));
850   XML.SetValue(Path+'ShowButtons', GetSaveProperty('ShowButtons'));
851 end;
852 
853 procedure TlrButtonPanel.Assign(Source: TPersistent);
854 begin
855   inherited Assign(Source);
856   if Source is TlrButtonPanel then
857   begin
858     ButtonOrder:=TlrButtonPanel(Source).ButtonOrder;
859     ShowButtons:=TlrButtonPanel(Source).ShowButtons;
860   end;
861 end;
862 
863 { TlrDateEdit }
864 
GetDatenull865 function TlrDateEdit.GetDate: TDateTime;
866 begin
867   Result:=TDateEdit(FControl).Date;
868 end;
869 
870 procedure TlrDateEdit.SetDate(AValue: TDateTime);
871 begin
872   TDateEdit(FControl).Date:=AValue;
873 end;
874 
875 procedure TlrDateEdit.PaintDesignControl;
876 var
877   AY, aH:integer;
878   R1:TRect;
879 begin
880   AY:=(DRect.Top + DRect.Bottom) div 2;
881   aH:=Canvas.TextHeight(Text) div 2;
882   Canvas.Frame3d(DRect, 1, bvLowered);
883   Canvas.Brush.Color := FControl.Color;
884   Canvas.FillRect(DRect);
885   Canvas.Font:=FControl.Font;
886   Canvas.TextRect(DRect, DRect.Left + 3, AY - aH, Text);
887 
888   R1:=DRect;
889   R1.Left:=R1.Right - 16;
890   DrawFrameControl(Canvas.Handle, R1, DFC_BUTTON, DFCS_BUTTONPUSH);
891 end;
892 
TlrDateEdit.CreateControlnull893 function TlrDateEdit.CreateControl: TControl;
894 begin
895   Result:=TDateEdit.Create(nil);
896 end;
897 
898 constructor TlrDateEdit.Create(AOwnerPage: TfrPage);
899 begin
900   inherited Create(AOwnerPage);
901   BaseName := 'lrDateEdit';
902   AutoSize:=true;
903 end;
904 
905 procedure TlrDateEdit.LoadFromXML(XML: TLrXMLConfig; const Path: String);
906 begin
907   inherited LoadFromXML(XML, Path);
908 end;
909 
910 procedure TlrDateEdit.SaveToXML(XML: TLrXMLConfig; const Path: String);
911 begin
912   inherited SaveToXML(XML, Path);
913 end;
914 
915 procedure TlrDateEdit.Assign(Source: TPersistent);
916 begin
917   inherited Assign(Source);
918   if Source is TlrDateEdit then
919     Date:=TlrDateEdit(Source).Date;
920 end;
921 
922 { TlrListBox }
923 
GetItemIndexnull924 function TlrListBox.GetItemIndex: integer;
925 begin
926   Result:=TListBox(FControl).ItemIndex;
927 end;
928 
GetItemsnull929 function TlrListBox.GetItems: TStrings;
930 begin
931   Result:=TListBox(FControl).Items;
932 end;
933 
934 procedure TlrListBox.SetItemIndex(AValue: integer);
935 begin
936   TListBox(FControl).ItemIndex:=AValue;
937 end;
938 
939 procedure TlrListBox.SetItems(AValue: TStrings);
940 begin
941   TListBox(FControl).Items:=AValue;
942   if Assigned(frDesigner) then
943     frDesigner.Modified:=true;
944 end;
945 
946 procedure TlrListBox.PaintDesignControl;
947 var
948   AY, aH, i:integer;
949   S:string;
950 begin
951   aH:=Canvas.TextHeight(Text) div 2;
952   Canvas.Frame3d(DRect, 1, bvLowered);
953   Canvas.Brush.Color := FControl.Color;
954   Canvas.FillRect(DRect);
955   Canvas.Font:=FControl.Font;
956   AY:=DRect.Top + 1;
957   i:=0;
958   while (AY < DRect.Bottom) and (i<TListBox(FControl).Items.Count) do
959   begin
960     S:=TListBox(FControl).Items[i];
961     Canvas.TextRect(DRect, DRect.Left + 3, AY, S);
962     inc(AY, aH + 3);
963     inc(i);
964   end;
965 end;
966 
TlrListBox.CreateControlnull967 function TlrListBox.CreateControl: TControl;
968 begin
969   Result:=TListBox.Create(nil);
970 end;
971 
972 constructor TlrListBox.Create(AOwnerPage: TfrPage);
973 begin
974   inherited Create(AOwnerPage);
975   BaseName := 'lrListBox';
976   AutoSize:=true;
977 end;
978 
979 procedure TlrListBox.LoadFromXML(XML: TLrXMLConfig; const Path: String);
980 begin
981   inherited LoadFromXML(XML, Path);
982   Items.Text:=XML.GetValue(Path+'Items/Text/Value'{%H-}, '');
983   ItemIndex:=XML.GetValue(Path+'ItemIndex/Value'{%H-}, -1);
984 end;
985 
986 procedure TlrListBox.SaveToXML(XML: TLrXMLConfig; const Path: String);
987 begin
988   inherited SaveToXML(XML, Path);
989   XML.SetValue(Path+'Items/Text/Value'{%H-}, Items.Text);
990   XML.SetValue(Path+'ItemIndex/Value'{%H-}, ItemIndex);
991 end;
992 
993 procedure TlrListBox.Assign(Source: TPersistent);
994 begin
995   inherited Assign(Source);
996   if Source is TlrListBox then
997   begin
998     Items.Assign(TlrListBox(Source).Items);
999     ItemIndex:=TlrListBox(Source).ItemIndex;
1000   end;
1001 end;
1002 
1003 { TlrMemo }
1004 
1005 procedure TlrMemo.MemoChange(Sender: TObject);
1006 begin
1007   if Assigned(FControl) then
1008     TMemo(FControl).Lines.Assign(Memo);
1009 end;
1010 
1011 procedure TlrMemo.PaintDesignControl;
1012 var
1013   AY, aH, i:integer;
1014   S:string;
1015 begin
1016   aH:=Canvas.TextHeight(Text) div 2;
1017   Canvas.Frame3d(DRect, 1, bvLowered);
1018   Canvas.Brush.Color := FControl.Color;
1019   Canvas.FillRect(DRect);
1020   Canvas.Font:=FControl.Font;
1021   AY:=DRect.Top + 1;
1022   i:=0;
1023   while (AY < DRect.Bottom) and (i<TMemo(FControl).Lines.Count) do
1024   begin
1025     S:=TMemo(FControl).Lines[i];
1026     Canvas.TextRect(DRect, DRect.Left + 3, AY, S);
1027     inc(AY, aH + 3);
1028     inc(i);
1029   end;
1030 end;
1031 
TlrMemo.CreateControlnull1032 function TlrMemo.CreateControl: TControl;
1033 begin
1034   Result:=TMemo.Create(nil);
1035 end;
1036 
GetTextnull1037 function TlrMemo.GetText: string;
1038 begin
1039   Result:=TMemo(FControl).Lines.Text;
1040 end;
1041 
1042 procedure TlrMemo.SetText(AValue: string);
1043 begin
1044   TMemo(FControl).Lines.Text:=AValue;
1045 end;
1046 
1047 constructor TlrMemo.Create(AOwnerPage: TfrPage);
1048 begin
1049   inherited Create(AOwnerPage);
1050   BaseName := 'lrMemo';
1051   Memo.OnChange:=@MemoChange;
1052 end;
1053 
1054 procedure TlrMemo.LoadFromXML(XML: TLrXMLConfig; const Path: String);
1055 begin
1056   inherited LoadFromXML(XML, Path);
1057 end;
1058 
1059 procedure TlrMemo.SaveToXML(XML: TLrXMLConfig; const Path: String);
1060 begin
1061   inherited SaveToXML(XML, Path);
1062 end;
1063 
1064 { TlrRadioButton }
1065 
TlrRadioButton.CreateControlnull1066 function TlrRadioButton.CreateControl: TControl;
1067 begin
1068   Result:=TRadioButton.Create(nil);
1069 end;
1070 
GetCheckStylenull1071 function TlrRadioButton.GetCheckStyle(ACheck: boolean): TThemedButton;
1072 begin
1073   if ACheck then
1074     Result:=tbRadioButtonCheckedNormal
1075   else
1076     Result:=tbRadioButtonUncheckedNormal
1077 end;
1078 
1079 constructor TlrRadioButton.Create(AOwnerPage: TfrPage);
1080 begin
1081   inherited Create(AOwnerPage);
1082   BaseName := 'lrRadioButton';
1083 end;
1084 
1085 
1086 { TlrComboBox }
1087 
GetDropDownCountnull1088 function TlrComboBox.GetDropDownCount: integer;
1089 begin
1090   Result:=TComboBox(FControl).DropDownCount;
1091 end;
1092 
GetItemIndexnull1093 function TlrComboBox.GetItemIndex: integer;
1094 begin
1095   Result:=TComboBox(FControl).ItemIndex;
1096 end;
1097 
GetItemsnull1098 function TlrComboBox.GetItems: TStrings;
1099 begin
1100   Result:=TComboBox(FControl).Items;
1101 end;
1102 
GetStylenull1103 function TlrComboBox.GetStyle: TComboBoxStyle;
1104 begin
1105   Result:=TComboBox(FControl).Style;
1106 end;
1107 
1108 procedure TlrComboBox.SetDropDownCount(AValue: integer);
1109 begin
1110   TComboBox(FControl).DropDownCount:=AValue;
1111 end;
1112 
1113 procedure TlrComboBox.SetItemIndex(AValue: integer);
1114 begin
1115   TComboBox(FControl).ItemIndex:=AValue;
1116 end;
1117 
1118 procedure TlrComboBox.SetItems(AValue: TStrings);
1119 begin
1120   TComboBox(FControl).Items:=AValue;
1121   if Assigned(frDesigner) then
1122     frDesigner.Modified:=true;
1123 end;
1124 
1125 procedure TlrComboBox.SetStyle(AValue: TComboBoxStyle);
1126 begin
1127   TComboBox(FControl).Style:=AValue;
1128 end;
1129 
1130 procedure TlrComboBox.PaintDesignControl;
1131 var
1132   AY, aH:integer;
1133   R1:TRect;
1134 begin
1135   AY:=(DRect.Top + DRect.Bottom) div 2;
1136   aH:=Canvas.TextHeight(Text) div 2;
1137   Canvas.Frame3d(DRect, 1, bvLowered);
1138   Canvas.Brush.Color := FControl.Color;
1139   Canvas.FillRect(DRect);
1140   Canvas.Font:=FControl.Font;
1141   Canvas.TextRect(DRect, DRect.Left + 3, AY - aH, Text);
1142 
1143   R1:=DRect;
1144   R1.Left:=R1.Right - 16;
1145   DrawFrameControl(Canvas.Handle, R1, DFC_BUTTON, DFCS_BUTTONPUSH);
1146 end;
1147 
TlrComboBox.CreateControlnull1148 function TlrComboBox.CreateControl: TControl;
1149 begin
1150   Result:=TComboBox.Create(nil);
1151 end;
1152 
1153 constructor TlrComboBox.Create(AOwnerPage: TfrPage);
1154 begin
1155   inherited Create(AOwnerPage);
1156   BaseName := 'lrComboBox';
1157   AutoSize:=true;
1158 end;
1159 
1160 procedure TlrComboBox.LoadFromXML(XML: TLrXMLConfig; const Path: String);
1161 begin
1162   inherited LoadFromXML(XML, Path);
1163   Items.Text:=XML.GetValue(Path+'Items/Text/Value'{%H-}, '');
1164   RestoreProperty('Style',XML.GetValue(Path+'Style/Value','csDropDown'));
1165   ItemIndex:=XML.GetValue(Path+'ItemIndex/Value'{%H-}, -1);
1166   DropDownCount:=XML.GetValue(Path+'DropDownCount/Value'{%H-}, DropDownCount);
1167 end;
1168 
1169 procedure TlrComboBox.SaveToXML(XML: TLrXMLConfig; const Path: String);
1170 begin
1171   inherited SaveToXML(XML, Path);
1172   XML.SetValue(Path+'Items/Text/Value'{%H-}, Items.Text);
1173   XML.SetValue(Path+'Style/Value', GetSaveProperty('Style'));
1174   XML.SetValue(Path+'ItemIndex/Value'{%H-}, ItemIndex);
1175   XML.SetValue(Path+'DropDownCount/Value'{%H-}, DropDownCount);
1176 end;
1177 
1178 procedure TlrComboBox.Assign(Source: TPersistent);
1179 begin
1180   inherited Assign(Source);
1181   if Source is TlrComboBox then
1182   begin
1183     Style:=TlrComboBox(Source).Style;
1184     Items.Assign(TlrComboBox(Source).Items);
1185     ItemIndex:=TlrComboBox(Source).ItemIndex;
1186     DropDownCount:=TlrComboBox(Source).DropDownCount;
1187   end;
1188 end;
1189 
1190 { TlrCheckBox }
1191 
1192 type
1193   THackChekBox = class(TCustomCheckBox);
1194 
TlrCheckBox.GetCheckednull1195 function TlrCheckBox.GetChecked: boolean;
1196 begin
1197   Result:=THackChekBox(FControl).Checked;
1198 end;
1199 
1200 procedure TlrCheckBox.SetChecked(AValue: boolean);
1201 begin
1202   THackChekBox(FControl).Checked:=AValue;
1203 end;
1204 
1205 procedure TlrCheckBox.PaintDesignControl;
1206 var
1207   AX, AY, aW, aH:integer;
1208   CSize: TSize;
1209   PaintRect:TRect;
1210   details: TThemedElementDetails;
1211 begin
1212   Details := ThemeServices.GetElementDetails(GetCheckStyle(Checked));
1213   CSize := ThemeServices.GetDetailSize(Details);
1214   PaintRect.Left := DRect.Left;
1215   PaintRect.Top  := (DRect.Top + DRect.Bottom - CSize.cy) div 2;
1216   PaintRect := Bounds(PaintRect.Left, PaintRect.Top, CSize.cx, CSize.cy);
1217   ThemeServices.DrawElement(Canvas.Handle, Details, PaintRect, nil);
1218 
1219   AX:=DRect.Left + CSize.cx + 2;
1220   AY:=(DRect.Top +  DRect.Bottom) div 2;
1221 //  aW:=Canvas.TextWidth(Caption);
1222   aH:=Canvas.TextHeight(Caption) div 2;
1223   Canvas.TextRect(DRect, AX, AY - aH, Caption)
1224 end;
1225 
CreateControlnull1226 function TlrCheckBox.CreateControl: TControl;
1227 begin
1228   Result:=TCheckBox.Create(nil);
1229 end;
1230 
TlrCheckBox.GetCheckStylenull1231 function TlrCheckBox.GetCheckStyle(ACheck: boolean): TThemedButton;
1232 begin
1233   if ACheck then
1234     Result:=tbCheckBoxCheckedNormal
1235   else
1236     Result:=tbCheckBoxUncheckedNormal
1237 end;
1238 
1239 constructor TlrCheckBox.Create(AOwnerPage: TfrPage);
1240 begin
1241   inherited Create(AOwnerPage);
1242   BaseName:='lrCheckBox';
1243   AutoSize:=true;
1244 end;
1245 
1246 procedure TlrCheckBox.LoadFromXML(XML: TLrXMLConfig; const Path: String);
1247 begin
1248   inherited LoadFromXML(XML, Path);
1249   Checked:=XML.GetValue(Path+'Checked/Value'{%H-}, false);
1250 end;
1251 
1252 procedure TlrCheckBox.SaveToXML(XML: TLrXMLConfig; const Path: String);
1253 begin
1254   inherited SaveToXML(XML, Path);
1255   XML.SetValue(Path+'Checked/Value'{%H-}, Checked);
1256 end;
1257 
1258 procedure TlrCheckBox.Assign(Source: TPersistent);
1259 begin
1260   inherited Assign(Source);
1261   if Source is TlrCheckBox then
1262     Checked:=TlrCheckBox(Source).Checked;
1263 end;
1264 
1265 { TlrButton }
1266 
GetKindnull1267 function TlrButton.GetKind: TBitBtnKind;
1268 begin
1269   Result:=TBitBtn(FControl).Kind;
1270 end;
1271 
1272 procedure TlrButton.SetKind(AValue: TBitBtnKind);
1273 begin
1274   TBitBtn(FControl).Kind:=AValue;
1275 end;
1276 
1277 procedure TlrButton.PaintDesignControl;
1278 var
1279   AX, AY, aW, aH:integer;
1280 begin
1281   DrawFrameControl(Canvas.Handle, DRect, DFC_BUTTON, DFCS_BUTTONPUSH);
1282   AX:=(DRect.Left +  DRect.Right) div 2;
1283   AY:=(DRect.Top +  DRect.Bottom) div 2;
1284   aW:=Canvas.TextWidth(Caption);
1285   aH:=Canvas.TextHeight(Caption) div 2;
1286   if aW>Width then
1287     Canvas.TextRect(DRect, 0, AY - aH, Caption)
1288   else
1289     Canvas.TextRect(DRect, AX - (aW div 2), AY - aH, Caption)
1290 end;
1291 
TlrButton.CreateControlnull1292 function TlrButton.CreateControl: TControl;
1293 begin
1294   Result:=TBitBtn.Create(nil);
1295   Result.AutoSize:=true;
1296 end;
1297 
1298 constructor TlrButton.Create(AOwnerPage: TfrPage);
1299 begin
1300   inherited Create(AOwnerPage);
1301   BaseName := 'lrButton';
1302 end;
1303 
1304 procedure TlrButton.LoadFromXML(XML: TLrXMLConfig; const Path: String);
1305 begin
1306   inherited LoadFromXML(XML, Path);
1307   RestoreProperty('Kind',XML.GetValue(Path+'Kind/Value','bkCustom'));
1308 end;
1309 
1310 procedure TlrButton.SaveToXML(XML: TLrXMLConfig; const Path: String);
1311 begin
1312   inherited SaveToXML(XML, Path);
1313   XML.SetValue(Path+'Kind/Value', GetSaveProperty('Kind'));
1314 end;
1315 
1316 procedure TlrButton.Assign(Source: TPersistent);
1317 begin
1318   inherited Assign(Source);
1319   if Source is TlrButton then
1320     Kind:=TlrButton(Source).Kind;
1321 end;
1322 
1323 { TlrEdit }
1324 
1325 procedure TlrEdit.PaintDesignControl;
1326 var
1327   AY, aH:integer;
1328 begin
1329   AY:=(DRect.Top + DRect.Bottom) div 2;
1330   aH:=Canvas.TextHeight(Text) div 2;
1331   Canvas.Frame3d(DRect, 1, bvLowered);
1332   Canvas.Brush.Color := FControl.Color;
1333   Canvas.FillRect(DRect);
1334   Canvas.Font:=FControl.Font;
1335   Canvas.TextRect(DRect, DRect.Left + 3, AY - aH, Text)
1336 end;
1337 
CreateControlnull1338 function TlrEdit.CreateControl: TControl;
1339 begin
1340   Result:=TEdit.Create(nil);
1341 end;
1342 
1343 constructor TlrEdit.Create(AOwnerPage: TfrPage);
1344 begin
1345   inherited Create(AOwnerPage);
1346   BaseName := 'lrEdit';
1347 end;
1348 
1349 procedure TlrEdit.LoadFromXML(XML: TLrXMLConfig; const Path: String);
1350 begin
1351   inherited LoadFromXML(XML, Path);
1352   Text:=XML.GetValue(Path+'Text/Value'{%H-}, '');
1353 end;
1354 
1355 procedure TlrEdit.SaveToXML(XML: TLrXMLConfig; const Path: String);
1356 begin
1357   inherited SaveToXML(XML, Path);
1358   XML.SetValue(Path+'Text/Value'{%H-}, Text);
1359 end;
1360 
1361 { TlrLabel }
1362 
GetAlignmentnull1363 function TlrLabel.GetAlignment: TAlignment;
1364 begin
1365   Result:=TLabel(FControl).Alignment;
1366 end;
1367 
TlrLabel.GetWordWrapnull1368 function TlrLabel.GetWordWrap: boolean;
1369 begin
1370   Result:=TLabel(FControl).WordWrap;
1371 end;
1372 
1373 procedure TlrLabel.SetAlignment(AValue: TAlignment);
1374 begin
1375   TLabel(FControl).Alignment:=AValue;
1376 end;
1377 
1378 procedure TlrLabel.SetWordWrap(AValue: boolean);
1379 begin
1380   TLabel(FControl).WordWrap:=AValue;
1381 end;
1382 
1383 procedure TlrLabel.PaintDesignControl;
1384 var
1385   AY, aH:integer;
1386 begin
1387   AY:=(DRect.Top + DRect.Bottom) div 2;
1388   aH:=Canvas.TextHeight(Text) div 2;
1389   Canvas.Brush.Color := FControl.Color;
1390   Canvas.FillRect(DRect);
1391   Canvas.Font:=FControl.Font;
1392   Canvas.TextRect(DRect, DRect.Left + 3, AY - aH, Text)
1393 end;
1394 
CreateControlnull1395 function TlrLabel.CreateControl: TControl;
1396 begin
1397   Result:=TLabel.Create(nil);
1398 end;
1399 
1400 
1401 constructor TlrLabel.Create(AOwnerPage: TfrPage);
1402 begin
1403   inherited Create(AOwnerPage);
1404   BaseName := 'lrLabel';
1405 end;
1406 
1407 procedure TlrLabel.LoadFromXML(XML: TLrXMLConfig; const Path: String);
1408 begin
1409   inherited LoadFromXML(XML, Path);
1410   WordWrap:=XML.GetValue(Path+'WordWrap/Value'{%H-}, false);
1411   RestoreProperty('Alignment',XML.GetValue(Path+'Alignment/Value',''));
1412 end;
1413 
1414 procedure TlrLabel.SaveToXML(XML: TLrXMLConfig; const Path: String);
1415 begin
1416   inherited SaveToXML(XML, Path);
1417   XML.SetValue(Path+'WordWrap/Value'{%H-}, WordWrap);
1418   XML.SetValue(Path+'Alignment/Value', GetSaveProperty('Alignment'));
1419 end;
1420 
1421 procedure TlrLabel.Assign(Source: TPersistent);
1422 begin
1423   inherited Assign(Source);
1424   if Source is TlrLabel then
1425   begin
1426     Alignment:=TlrLabel(Source).Alignment;
1427     WordWrap:=TlrLabel(Source).WordWrap;
1428   end;
1429 end;
1430 
1431 
1432 { TlrVisualControl }
1433 
1434 procedure TlrVisualControl.SetColor(AValue: TColor);
1435 begin
1436   FControl.Color:=AValue;
1437   Invalidate;
1438 end;
1439 
GetAutoSizenull1440 function TlrVisualControl.GetAutoSize: Boolean;
1441 begin
1442   Result:=FControl.AutoSize;
1443 end;
1444 
TlrVisualControl.GetCaptionnull1445 function TlrVisualControl.GetCaption: string;
1446 begin
1447   Result:=FControl.Caption;
1448 end;
1449 
GetColornull1450 function TlrVisualControl.GetColor: TColor;
1451 begin
1452   Result:=FControl.Color;
1453 end;
1454 
TlrVisualControl.GetEnablednull1455 function TlrVisualControl.GetEnabled: boolean;
1456 begin
1457   Result:=FControl.Enabled;
1458 end;
1459 
TlrVisualControl.GetFontnull1460 function TlrVisualControl.GetFont: TFont;
1461 begin
1462   Result:=FControl.Font;
1463 end;
1464 
GetHintnull1465 function TlrVisualControl.GetHint: string;
1466 begin
1467   Result:=FControl.Hint;
1468 end;
1469 
TlrVisualControl.GetOnClicknull1470 function TlrVisualControl.GetOnClick: TfrScriptStrings;
1471 begin
1472   Result:=Script;
1473 end;
1474 
1475 procedure TlrVisualControl.SetAutoSize(AValue: Boolean);
1476 begin
1477   FControl.AutoSize:=AValue;
1478 end;
1479 
1480 procedure TlrVisualControl.SetCaption(AValue: string);
1481 begin
1482   FControl.Caption:=AValue;
1483 {  DX:=FControl.Width;
1484   DY:=FControl.Height;}
1485   Invalidate;
1486 end;
1487 
1488 procedure TlrVisualControl.SetEnabled(AValue: boolean);
1489 begin
1490   FControl.Enabled:=AValue;
1491   Invalidate;
1492 end;
1493 
1494 procedure TlrVisualControl.SetFont(AValue: TFont);
1495 begin
1496   FControl.Font:=AValue;
1497   Invalidate;
1498 end;
1499 
1500 procedure TlrVisualControl.OnClickHandle(Sender: TObject);
1501 var
1502   FSaveView:TfrView;
1503   FSavePage:TfrPage;
1504   CmdList, ErrorList:TStringList;
1505   FSaveBand: TfrBand;
1506 begin
1507   if (DocMode = dmPrinting) and (Script.Count>0) and (Trim(Script.Text)<>'') and (Assigned(CurReport))then
1508   begin
1509     FSaveView:=CurView;
1510     FSavePage:=CurPage;
1511     FSaveBand:=CurBand;
1512 
1513     CmdList:=TStringList.Create;
1514     ErrorList:=TStringList.Create;
1515     try
1516       CurView := Self;
1517       CurPage:=OwnerPage;
1518       CurBand:=nil;
1519       frInterpretator.PrepareScript(Script, CmdList, ErrorList);
1520       frInterpretator.DoScript(CmdList);
1521     finally
1522       CurPage:=FSavePage;
1523       CurView := FSaveView;
1524       CurBand:=FSaveBand;
1525       FreeAndNil(CmdList);
1526       FreeAndNil(ErrorList);
1527     end;
1528   end;
1529 end;
1530 
1531 procedure TlrVisualControl.SetHint(AValue: string);
1532 begin
1533   FControl.Hint:=AValue;
1534 end;
1535 
1536 procedure TlrVisualControl.SetOnClick(AValue: TfrScriptStrings);
1537 begin
1538   Script:=AValue;
1539 end;
1540 
1541 procedure TlrVisualControl.SetVisible(AValue: Boolean);
1542 begin
1543   inherited SetVisible(AValue);
1544   FControl.Visible:=AValue;
1545 end;
1546 
1547 procedure TlrVisualControl.PaintDesignControl;
1548 var
1549   AY, aH:integer;
1550   S:string;
1551 begin
1552   AY:=(DRect.Top + DRect.Bottom) div 2;
1553   aH:=Canvas.TextHeight(Text) div 2;
1554   Canvas.Brush.Color := clRed;
1555   Canvas.FillRect(DRect);
1556   Canvas.Font:=FControl.Font;
1557   Canvas.TextRect(DRect, DRect.Left + 3, AY - aH, Name)
1558 end;
1559 
1560 procedure TlrVisualControl.SetName(const AValue: string);
1561 begin
1562   inherited SetName(AValue);
1563   FControl.Name:=Name;
1564 end;
1565 
1566 procedure TlrVisualControl.UpdateControlPosition;
1567 begin
1568   FControl.Left:=round(Left);
1569   FControl.Top:=round(Top) - 20; //Header width
1570   FControl.Width:=round(Width);
1571   FControl.Height:=round(Height);
1572 end;
1573 
1574 procedure TlrVisualControl.AttachToParent;
1575 begin
1576   FControl.Parent := OwnerForm;
1577 end;
1578 
1579 procedure TlrVisualControl.Assign(Source: TPersistent);
1580 begin
1581   inherited Assign(Source);
1582   if Source is TlrVisualControl then
1583   begin
1584     AutoSize:=TlrVisualControl(Source).AutoSize;
1585     Color:=TlrVisualControl(Source).Color;
1586     Caption:=TlrVisualControl(Source).Caption;
1587     Text:=TlrVisualControl(Source).Text;
1588     Font:=TlrVisualControl(Source).Font;
1589     Hint:=TlrVisualControl(Source).Hint;
1590     OnClick:=TlrVisualControl(Source).OnClick;
1591   end;
1592 end;
1593 
1594 procedure TlrVisualControl.AfterCreate;
1595 begin
1596   inherited AfterCreate;
1597   if Assigned(FControl) then
1598     FControl.OnClick:=@OnClickHandle;
1599 end;
1600 
1601 constructor TlrVisualControl.Create(AOwnerPage: TfrPage);
1602 begin
1603   inherited Create(AOwnerPage);
1604   FControl:=CreateControl;
1605   if Assigned(FControl) then
1606   begin
1607     x:=FControl.Left;
1608     Y:=FControl.Top;
1609     DX:=FControl.Width;
1610     DY:=FControl.Height;
1611   end;
1612 end;
1613 
1614 destructor TlrVisualControl.Destroy;
1615 begin
1616   FControl.Free;
1617   FControl := nil;
1618   inherited Destroy;
1619 end;
1620 
1621 procedure TlrVisualControl.LoadFromXML(XML: TLrXMLConfig; const Path: String);
1622 begin
1623   inherited LoadFromXML(XML, Path);
1624   Enabled:=XML.GetValue(Path+'Enabled/Value'{%H-}, true);
1625   Font.Name := XML.GetValue(Path+'Font/Name/Value', 'Arial'); // todo chk
1626   Font.Size := XML.GetValue(Path+'Font/Size/Value'{%H-}, 10); // todo chk
1627   RestoreProperty('CharSet',XML.GetValue(Path+'Font/Charset/Value',''),Font);
1628   RestoreProperty('Style',XML.GetValue(Path+'Font/Style/Value',''),Font);
1629   Font.Color := StringToColor(XML.GetValue(Path+'Font/Color/Value','clBlack')); // todo chk
1630   Caption:=XML.GetValue(Path+'Caption/Value'{%H-}, '');
1631   AutoSize:=XML.GetValue(Path+'AutoSize/Value'{%H-}, true);
1632   Color:= StringToColor(XML.GetValue(Path+'Color/Value', 'clNone'));
1633   Hint:=XML.GetValue(Path+'Hint/Value'{%H-}, '');
1634   if StreamMode = smDesigning then
1635   begin
1636     OnClick.Text:=XML.GetValue(Path+'Event/OnClick/Value', '');
1637   end;
1638 end;
1639 
1640 procedure TlrVisualControl.SaveToXML(XML: TLrXMLConfig; const Path: String);
1641 begin
1642   inherited SaveToXML(XML, Path);
1643   XML.SetValue(Path+'Enabled/Value'{%H-}, Enabled);
1644   XML.SetValue(Path+'Font/Name/Value', Font.Name);
1645   XML.SetValue(Path+'Font/Size/Value'{%H-}, Font.Size);
1646   XML.SetValue(Path+'Font/Color/Value', ColorToString(Font.Color));
1647   XML.SetValue(Path+'Font/Charset/Value', GetSaveProperty('CharSet',Font));
1648   XML.SetValue(Path+'Font/Style/Value', GetSaveProperty('Style',Font));
1649   XML.SetValue(Path+'Caption/Value'{%H-}, Caption);
1650   XML.SetValue(Path+'AutoSize/Value'{%H-}, AutoSize);
1651   XML.SetValue(Path+'Color/Value', ColorToString(Color));
1652   XML.SetValue(Path+'Hint/Value'{%H-}, Hint);
1653 
1654   if StreamMode = smDesigning then
1655   begin
1656     if IsPublishedProp(self,'OnClick') then
1657       XML.SetValue(Path+'Event/OnClick/Value', OnClick.Text);
1658   end;
1659 end;
1660 
1661 
1662 initialization
1663   InitLRComp;
1664 
1665 finalization
1666   DoneLRComp;
1667 end.
1668 
1669 
1670