1{
2 /***************************************************************************
3                               FormEditor.pp
4                             -------------------
5
6 ***************************************************************************/
7
8 ***************************************************************************
9 *                                                                         *
10 *   This source is free software; you can redistribute it and/or modify   *
11 *   it under the terms of the GNU General Public License as published by  *
12 *   the Free Software Foundation; either version 2 of the License, or     *
13 *   (at your option) any later version.                                   *
14 *                                                                         *
15 *   This code is distributed in the hope that it will be useful, but      *
16 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
17 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
18 *   General Public License for more details.                              *
19 *                                                                         *
20 *   A copy of the GNU General Public License is available on the World    *
21 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
22 *   obtain it by writing to the Free Software Foundation,                 *
23 *   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA.   *
24 *                                                                         *
25 ***************************************************************************
26}
27unit FormEditor;
28
29{$mode objfpc}{$H+}
30
31interface
32
33uses
34  Classes, SysUtils,
35  // LCL
36  LCLProc, Controls, Forms,
37  RegisterLCL,  // register LCLBase
38  // IDE
39  ObjectInspector, Designer, IDECommands, FormEditingIntf, CustomFormEditor,
40  // register IDE base packages
41  LazarusPackageIntf, PkgRegisterBase, allsynedit, LazControls;
42
43type
44
45  { TFormEditor }
46
47  TFormEditor = class(TCustomFormEditor)
48  protected
49    procedure SetObj_Inspector(AnObjectInspector: TObjectInspectorDlg); override;
50  public
51    procedure PaintAllDesignerItems;
52    procedure CheckDesignerPositions;
53    function GetDesignerMediatorByComponent(AComponent: TComponent
54            ): TDesignerMediator; override;
55
56    function ComponentUsesRTTIForMethods(Component: TComponent): boolean;
57  end;
58
59var
60  FormEditor1: TFormEditor = nil;
61
62procedure CreateFormEditor;
63procedure FreeFormEditor;
64
65
66implementation
67
68procedure CreateFormEditor;
69begin
70  if FormEditor1=nil then begin
71    FormEditor1 := TFormEditor.Create;
72    BaseFormEditor1 := FormEditor1;
73    FormEditingHook := FormEditor1;
74    IDECmdScopeDesignerOnly.AddWindowClass(TDesignerIDECommandForm);
75  end;
76end;
77
78procedure FreeFormEditor;
79begin
80  if FormEditor1=nil then exit;
81  DebugLn(['FreeFormEditor: FormEditor1=', FormEditor1]);
82  FormEditingHook:=nil;
83  FormEditor1.Free;
84  FormEditor1:=nil;
85  BaseFormEditor1 := nil;
86end;
87
88procedure TFormEditor.SetObj_Inspector(AnObjectInspector: TObjectInspectorDlg);
89begin
90  if AnObjectInspector=Obj_Inspector then exit;
91  inherited SetObj_Inspector(AnObjectInspector);
92end;
93
94procedure TFormEditor.PaintAllDesignerItems;
95var
96  i: Integer;
97  ADesigner: TDesigner;
98  AForm: TCustomForm;
99begin
100  for i:=0 to JITFormList.Count-1 do begin
101    ADesigner:=TDesigner(JITFormList[i].Designer);
102    if ADesigner<>nil then ADesigner.DrawDesignerItems(true);
103  end;
104  for i:=0 to JITNonFormList.Count-1 do begin
105    AForm:=GetDesignerForm(JITNonFormList[i]);
106    if AForm=nil then continue;
107    ADesigner:=TDesigner(AForm.Designer);
108    if ADesigner<>nil then ADesigner.DrawDesignerItems(true);
109  end;
110end;
111
112procedure TFormEditor.CheckDesignerPositions;
113var
114  i: Integer;
115  ADesigner: TDesigner;
116  AForm: TCustomForm;
117begin
118  for i:=0 to JITFormList.Count-1 do begin
119    ADesigner:=TDesigner(JITFormList[i].Designer);
120    if ADesigner<>nil then ADesigner.CheckFormBounds;
121  end;
122  for i:=0 to JITNonFormList.Count-1 do begin
123    AForm:=GetDesignerForm(JITNonFormList[i]);
124    if AForm=nil then continue;
125    ADesigner:=TDesigner(AForm.Designer);
126    if ADesigner<>nil then ADesigner.CheckFormBounds;
127  end;
128end;
129
130function TFormEditor.GetDesignerMediatorByComponent(AComponent: TComponent
131  ): TDesignerMediator;
132var
133  ADesigner: TIDesigner;
134begin
135  ADesigner:=GetDesignerByComponent(AComponent);
136  if ADesigner is TDesigner then
137    Result:=TDesigner(ADesigner).Mediator
138  else
139    Result:=nil;
140end;
141
142function TFormEditor.ComponentUsesRTTIForMethods(Component: TComponent): boolean;
143var
144  Mediator: TDesignerMediator;
145begin
146  Mediator:=GetDesignerMediatorByComponent(Component);
147  Result:=(Mediator<>nil) and (Mediator.UseRTTIForMethods(Component));
148end;
149
150initialization
151  RegisterLCLBase;
152
153end.
154