source: cprs/branches/tmg-cprs/TMG_Extra/tntUniCode/Design/TntDesignEditors_Design.pas@ 1035

Last change on this file since 1035 was 672, checked in by Kevin Toppenberg, 15 years ago

Adding source to tntControls for compilation

File size: 5.4 KB
Line 
1
2{*****************************************************************************}
3{ }
4{ Tnt Delphi Unicode Controls }
5{ http://www.tntware.com/delphicontrols/unicode/ }
6{ Version: 2.3.0 }
7{ }
8{ Copyright (c) 2002-2007, Troy Wolbrink (troy.wolbrink@tntware.com) }
9{ }
10{*****************************************************************************}
11
12unit TntDesignEditors_Design;
13
14{$INCLUDE ..\Source\TntCompilers.inc}
15
16interface
17
18uses
19 Classes, Forms, TypInfo, DesignIntf, DesignEditors;
20
21type
22 ITntDesigner = IDesigner;
23
24 TTntDesignerSelections = class(TInterfacedObject, IDesignerSelections)
25 private
26 FList: TList;
27 {$IFDEF COMPILER_9_UP}
28 function GetDesignObject(Index: Integer): IDesignObject;
29 {$ENDIF}
30 protected
31 function Add(const Item: TPersistent): Integer;
32 function Equals(const List: IDesignerSelections): Boolean;
33 function Get(Index: Integer): TPersistent;
34 function GetCount: Integer;
35 property Count: Integer read GetCount;
36 property Items[Index: Integer]: TPersistent read Get; default;
37 public
38 constructor Create; virtual;
39 destructor Destroy; override;
40 procedure ReplaceSelection(const OldInst, NewInst: TPersistent);
41 end;
42
43function GetObjectInspectorForm: TCustomForm;
44procedure EditPropertyWithDialog(Component: TPersistent; const PropName: AnsiString; const Designer: ITntDesigner);
45
46implementation
47
48uses
49 SysUtils;
50
51{ TTntDesignerSelections }
52
53function TTntDesignerSelections.Add(const Item: TPersistent): Integer;
54begin
55 Result := FList.Add(Item);
56end;
57
58constructor TTntDesignerSelections.Create;
59begin
60 inherited;
61 FList := TList.Create;
62end;
63
64destructor TTntDesignerSelections.Destroy;
65begin
66 FList.Free;
67 inherited;
68end;
69
70function TTntDesignerSelections.Equals(const List: IDesignerSelections): Boolean;
71var
72 I: Integer;
73begin
74 Result := False;
75 if List.Count <> Count then Exit;
76 for I := 0 to Count - 1 do
77 begin
78 if Items[I] <> List[I] then Exit;
79 end;
80 Result := True;
81end;
82
83function TTntDesignerSelections.Get(Index: Integer): TPersistent;
84begin
85 Result := TPersistent(FList[Index]);
86end;
87
88function TTntDesignerSelections.GetCount: Integer;
89begin
90 Result := FList.Count;
91end;
92
93{$IFDEF COMPILER_9_UP}
94function TTntDesignerSelections.GetDesignObject(Index: Integer): IDesignObject;
95begin
96 Result := nil; {TODO: Figure out what IDesignerSelections.GetDesignObject is all about. Must wait for more documentation!}
97end;
98{$ENDIF}
99
100procedure TTntDesignerSelections.ReplaceSelection(const OldInst, NewInst: TPersistent);
101var
102 Idx: Integer;
103begin
104 Idx := FList.IndexOf(OldInst);
105 if Idx <> -1 then
106 FList[Idx] := NewInst;
107end;
108
109{//------------------------------
110// Helpful discovery routines to explore the components and classes inside the IDE...
111//
112procedure EnumerateComponents(Comp: TComponent);
113var
114 i: integer;
115begin
116 for i := Comp.ComponentCount - 1 downto 0 do
117 MessageBoxW(0, PWideChar(WideString(Comp.Components[i].Name + ': ' + Comp.Components[i].ClassName)),
118 PWideChar(WideString(Comp.Name)), 0);
119end;
120
121procedure EnumerateClasses(Comp: TComponent);
122var
123 AClass: TClass;
124begin
125 AClass := Comp.ClassType;
126 repeat
127 MessageBoxW(0, PWideChar(WideString(AClass.ClassName)),
128 PWideChar(WideString(Comp.Name)), 0);
129 AClass := Aclass.ClassParent;
130 until AClass = nil;
131end;
132//------------------------------}
133
134//------------------------------
135function GetIdeMainForm: TCustomForm;
136var
137 Comp: TComponent;
138begin
139 Result := nil;
140 if Application <> nil then begin
141 Comp := Application.FindComponent('AppBuilder');
142 if Comp is TCustomForm then
143 Result := TCustomForm(Comp);
144 end;
145end;
146
147function GetObjectInspectorForm: TCustomForm;
148var
149 Comp: TComponent;
150 IdeMainForm: TCustomForm;
151begin
152 Result := nil;
153 IdeMainForm := GetIdeMainForm;
154 if IdeMainForm <> nil then begin
155 Comp := IdeMainForm.FindComponent('PropertyInspector');
156 if Comp is TCustomForm then
157 Result := TCustomForm(Comp);
158 end;
159end;
160
161{ TPropertyEditorWithDialog }
162type
163 TPropertyEditorWithDialog = class
164 private
165 FPropName: AnsiString;
166 procedure CheckEditProperty(const Prop: IProperty);
167 procedure EditProperty(Component: TPersistent; const PropName: AnsiString; const Designer: ITntDesigner);
168 end;
169
170procedure TPropertyEditorWithDialog.CheckEditProperty(const Prop: IProperty);
171begin
172 if Prop.GetName = FPropName then
173 Prop.Edit;
174end;
175
176procedure TPropertyEditorWithDialog.EditProperty(Component: TPersistent; const PropName: AnsiString; const Designer: ITntDesigner);
177var
178 Components: IDesignerSelections;
179begin
180 FPropName := PropName;
181 Components := TDesignerSelections.Create;
182 Components.Add(Component);
183 GetComponentProperties(Components, [tkClass], Designer, CheckEditProperty);
184end;
185
186procedure EditPropertyWithDialog(Component: TPersistent; const PropName: AnsiString; const Designer: ITntDesigner);
187begin
188 with TPropertyEditorWithDialog.Create do
189 try
190 EditProperty(Component, PropName, Designer);
191 finally
192 Free;
193 end;
194end;
195
196end.
Note: See TracBrowser for help on using the repository browser.