1 { LazReport dialogs control
2 
3   Copyright (C) 2012-2013 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 lrFormStorageEditor;
32 
33 {$mode objfpc}{$H+}
34 
35 interface
36 
37 uses
38   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel,
39   StdCtrls, ExtCtrls, LR_Class;
40 
41 type
42 
43   { TlrFormStorageEditorForm }
44 
45   TlrFormStorageEditorForm = class(TfrObjEditorForm)
46     ButtonPanel1: TButtonPanel;
47     ListBoxSaved: TListBox;
48     ListBoxObjects: TListBox;
49     ListBoxProps: TListBox;
50     Panel1: TPanel;
51     Splitter1: TSplitter;
52     Splitter2: TSplitter;
53     procedure FormCreate(Sender: TObject);
54     procedure ListBoxObjectsClick(Sender: TObject);
55     procedure ListBoxPropsDblClick(Sender: TObject);
56     procedure ListBoxSavedDblClick(Sender: TObject);
57   private
58     //
59   public
60     procedure ShowEditor({%H-}t: TfrView); override;
61   end;
62 
63 implementation
64 uses LRDialogControls, lrFormStorage, PropEdits, typinfo, FPCAdds;
65 
66 {$R *.lfm}
67 
68 { TlrFormStorageEditorForm }
69 
70 procedure TlrFormStorageEditorForm.FormCreate(Sender: TObject);
71 begin
72   //
73 end;
74 
75 procedure TlrFormStorageEditorForm.ListBoxObjectsClick(Sender: TObject);
76 var
77   t: TfrView;
78 
79   TypeInfo: PTypeInfo;
80   TypeData: PTypeData;
81   PropInfo: PPropInfo;
82   PropData: ^TPropData;
83   CurCount: integer;
84 begin
85   ListBoxProps.Items.Clear;
86 
87   if (ListBoxObjects.ItemIndex<0) or (ListBoxObjects.Items.Count = 0) then exit;
88 
89   T:=ListBoxObjects.Items.Objects[ListBoxObjects.ItemIndex] as TfrView;
90   if not Assigned(T) then exit;
91 
92 
93   // read all properties and remove doubles
94   TypeInfo:=T.ClassInfo;
95   repeat
96     // read all property infos of current class
97     TypeData:=GetTypeData(TypeInfo);
98     // skip unitname
99     PropData:=AlignToPtr(PByte(@TypeData^.UnitName)+Length(TypeData^.UnitName)+1);
100     // read property count
101     CurCount:=PWord(PropData)^;
102     PropInfo:=PPropInfo(@PropData^.PropList);
103 
104     // read properties
105     while CurCount>0 do
106     begin
107       ListBoxProps.Items.Add(PropInfo^.Name);
108       PropInfo:=PPropInfo(AlignToPtr(pointer(@PropInfo^.Name)+PByte(@PropInfo^.Name)^+1));
109       dec(CurCount);
110     end;
111     TypeInfo:=TypeData^.ParentInfo;
112     if TypeInfo=nil then
113       break;
114   until false;
115 end;
116 
117 procedure TlrFormStorageEditorForm.ListBoxPropsDblClick(Sender: TObject);
118 var
119   S:string;
120 begin
121   S:=ListBoxObjects.Items[ListBoxObjects.ItemIndex]+'.'+ListBoxProps.Items[ListBoxProps.ItemIndex];
122   if ListBoxSaved.Items.IndexOf(S)<0 then
123     ListBoxSaved.Items.Add(S);
124 end;
125 
126 procedure TlrFormStorageEditorForm.ListBoxSavedDblClick(Sender: TObject);
127 begin
128   if (ListBoxSaved.ItemIndex>-1) and (ListBoxSaved.ItemIndex < ListBoxSaved.Items.Count) then
129     ListBoxSaved.Items.Delete(ListBoxSaved.ItemIndex);
130 end;
131 
132 type
133   THackObj = class(TfrObject);
134 
135 procedure TlrFormStorageEditorForm.ShowEditor(t: TfrView);
136 var
137   P:TfrObject;
138   i:integer;
139   FPage:TfrPage;
140 begin
141   FPage:=THackObj(t).OwnerPage;
142   ListBoxObjects.Items.Clear;
143 
144   if (FPage is TfrPageDialog) then
145   begin
146     for i:=0 to FPage.Objects.Count-1 do
147     begin
148       P:=TfrObject(FPage.Objects[i]);
149       if P is TlrVisualControl then
150       begin
151         ListBoxObjects.Items.Add(P.Name);
152         ListBoxObjects.Items.Objects[ListBoxObjects.Items.Count-1]:=P;
153       end;
154     end;
155   end;
156 
157   ListBoxSaved.Items.Assign(TLRFormStorage(T).StoredProperties);
158   if ShowModal = mrOk then
159   begin
160     TLRFormStorage(T).StoredProperties.Assign(ListBoxSaved.Items);
161     frDesigner.Modified := True;
162   end;
163 end;
164 
165 end.
166 
167