initial commit
[rofl0r-TntUnicode.git] / Design / TntForms_Design.pas
blob4810f04c1a840d94577a30386fae425538e89c07
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 {*****************************************************************************}
12 unit TntForms_Design;
14 {$INCLUDE ..\Source\TntCompilers.inc}
16 interface
18 uses
19 Classes, Windows, DesignIntf, ToolsApi;
21 type HICON = LongWord;
23 type
24 TTntNewFormWizard = class(TNotifierObject, IOTAWizard, IOTARepositoryWizard,
25 IOTAFormWizard
26 {$IFDEF COMPILER_6_UP}, IOTARepositoryWizard60{$ENDIF}
27 {$IFDEF COMPILER_9_UP}, IOTARepositoryWizard80{$ENDIF})
28 protected
29 function ThisFormName: WideString;
30 function ThisFormClass: TComponentClass; virtual; abstract;
31 function ThisFormUnit: WideString;
32 public
33 // IOTAWizard
34 function GetIDString: AnsiString;
35 function GetName: AnsiString; virtual;
36 function GetState: TWizardState;
37 procedure Execute;
38 // IOTARepositoryWizard
39 function GetAuthor: AnsiString;
40 function GetComment: AnsiString; virtual; abstract;
41 function GetPage: AnsiString;
42 function GetGlyph: HICON;
43 {$IFDEF COMPILER_6_UP}
44 // IOTARepositoryWizard60
45 function GetDesigner: AnsiString;
46 {$ENDIF}
47 {$IFDEF COMPILER_9_UP}
48 // IOTARepositoryWizard80
49 function GetGalleryCategory: IOTAGalleryCategory;
50 function GetPersonality: AnsiString;
51 {$ENDIF}
52 end;
54 procedure Register;
56 implementation
58 uses
59 TntForms, DesignEditors, WCtlForm, TypInfo, SysUtils;
61 type
62 TTntNewTntFormWizard = class(TTntNewFormWizard)
63 protected
64 function ThisFormClass: TComponentClass; override;
65 public
66 function GetName: AnsiString; override;
67 function GetComment: AnsiString; override;
68 end;
70 TTntNewTntFrameWizard = class(TTntNewFormWizard)
71 protected
72 function ThisFormClass: TComponentClass; override;
73 public
74 function GetName: AnsiString; override;
75 function GetComment: AnsiString; override;
76 end;
78 TTntFrameCustomModule = class(TWinControlCustomModule)
79 public
80 function Nestable: Boolean; override;
81 end;
83 TTntFormCustomModule = class(TCustomModule)
84 public
85 class function DesignClass: TComponentClass; override;
86 end;
88 procedure Register;
89 begin
90 RegisterCustomModule(TTntFrame, TTntFrameCustomModule);
91 RegisterPackageWizard(TTntNewTntFrameWizard.Create);
92 //--
93 RegisterCustomModule(TTntForm, TTntFormCustomModule);
94 //--
95 RegisterPackageWizard(TTntNewTntFormWizard.Create);
96 end;
98 function GetFirstModuleSupporting(const IID: TGUID): IOTAModule;
99 var
100 ModuleServices: IOTAModuleServices;
101 i: integer;
102 begin
103 Result := nil;
104 if Assigned(BorlandIDEServices) then
105 begin
106 // look for the first project
107 ModuleServices := BorlandIDEServices as IOTAModuleServices;
108 for i := 0 to ModuleServices.ModuleCount - 1 do
109 if Supports(ModuleServices.Modules[i], IID, Result) then
110 Break;
111 end;
112 end;
114 function MyGetActiveProject: IOTAProject;
115 {$IFDEF COMPILER_7_UP}
116 begin
117 Result := ToolsAPI.GetActiveProject;
118 {$ELSE}
120 ProjectGroup: IOTAProjectGroup;
121 begin
122 ProjectGroup := GetFirstModuleSupporting(IOTAProjectGroup) as IOTAProjectGroup;
123 if ProjectGroup = nil then
124 Result := nil
125 else
126 Result := ProjectGroup.ActiveProject;
127 {$ENDIF}
128 if (Result = nil) then
129 Result := GetFirstModuleSupporting(IOTAProject) as IOTAProject;
130 end;
132 { TTntNewFormCreator }
133 type
134 TTntNewFormCreator = class(TInterfacedObject, IOTACreator, IOTAModuleCreator)
135 private
136 FAncestorName: WideString;
137 FUnitName: WideString;
138 public
139 // IOTACreator
140 function GetCreatorType: AnsiString;
141 function GetExisting: Boolean;
142 function GetFileSystem: AnsiString;
143 function GetOwner: IOTAModule;
144 function GetUnnamed: Boolean;
145 // IOTAModuleCreator
146 function GetAncestorName: AnsiString;
147 function GetImplFileName: AnsiString;
148 function GetIntfFileName: AnsiString;
149 function GetFormName: AnsiString;
150 function GetMainForm: Boolean;
151 function GetShowForm: Boolean;
152 function GetShowSource: Boolean;
153 function NewFormFile(const FormIdent, AncestorIdent: AnsiString): IOTAFile;
154 function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: AnsiString): IOTAFile;
155 function NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: AnsiString): IOTAFile;
156 procedure FormCreated(const FormEditor: IOTAFormEditor);
157 public
158 constructor Create(const UnitName, AncestorName: WideString);
159 end;
161 TTntSourceFile = class(TInterfacedObject, IOTAFile)
162 private
163 FSource: AnsiString;
164 public
165 function GetSource: AnsiString;
166 function GetAge: TDateTime;
167 constructor Create(const Source: AnsiString);
168 end;
170 constructor TTntNewFormCreator.Create(const UnitName, AncestorName: WideString);
171 begin
172 inherited Create;
173 FUnitName := UnitName;
174 FAncestorName := AncestorName;
175 end;
177 procedure TTntNewFormCreator.FormCreated(const FormEditor: IOTAFormEditor);
178 begin
179 end;
181 function TTntNewFormCreator.GetAncestorName: AnsiString;
182 begin
183 Result := FAncestorName;
184 end;
186 function TTntNewFormCreator.GetCreatorType: AnsiString;
187 begin
188 Result := sForm;
189 end;
191 function TTntNewFormCreator.GetExisting: Boolean;
192 begin
193 Result := False;
194 end;
196 function TTntNewFormCreator.GetFileSystem: AnsiString;
197 begin
198 Result := '';
199 end;
201 function TTntNewFormCreator.GetFormName: AnsiString;
202 begin
203 Result := '';
204 end;
206 function TTntNewFormCreator.GetImplFileName: AnsiString;
207 begin
208 Result := '';
209 end;
211 function TTntNewFormCreator.GetIntfFileName: AnsiString;
212 begin
213 Result := '';
214 end;
216 function TTntNewFormCreator.GetMainForm: Boolean;
217 begin
218 Result := False;
219 end;
221 function TTntNewFormCreator.GetOwner: IOTAModule;
222 begin
223 Result := MyGetActiveProject;
224 end;
226 function TTntNewFormCreator.GetShowForm: Boolean;
227 begin
228 Result := True;
229 end;
231 function TTntNewFormCreator.GetShowSource: Boolean;
232 begin
233 Result := True;
234 end;
236 function TTntNewFormCreator.GetUnnamed: Boolean;
237 begin
238 Result := True;
239 end;
241 function TTntNewFormCreator.NewFormFile(const FormIdent, AncestorIdent: AnsiString): IOTAFile;
242 begin
243 Result := nil;
244 end;
246 function TTntNewFormCreator.NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: AnsiString): IOTAFile;
247 const
248 cSource =
249 'unit %s;' + #13#10 +
250 '' + #13#10 +
251 'interface' + #13#10 +
252 '' + #13#10 +
253 'uses' + #13#10 +
254 ' Windows, Messages, SysUtils' + {$IFDEF COMPILER_6_UP}', Variants' + {$ENDIF}
255 ', Classes, Graphics, Controls, Forms,' + #13#10 + ' Dialogs, %s;' + #13#10 +
256 '' + #13#10 +
257 'type' + #13#10 +
258 ' T%s = class(T%s)' + #13#10 +
259 ' private' + #13#10 +
260 ' { Private declarations }' + #13#10 +
261 ' public' + #13#10 +
262 ' { Public declarations }' + #13#10 +
263 ' end;' + #13#10 +
264 '' + #13#10 +
265 'var' + #13#10 +
266 ' %s: T%s;' + #13#10 +
267 '' + #13#10 +
268 'implementation' + #13#10 +
269 '' + #13#10 +
270 '{$R *.DFM}' + #13#10 +
271 '' + #13#10 +
272 'end.';
273 begin
274 Result := TTntSourceFile.Create(Format{TNT-ALLOW Format}(cSource,
275 [ModuleIdent, FUnitName, FormIdent, AncestorIdent, FormIdent, FormIdent]));
276 end;
278 function TTntNewFormCreator.NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: AnsiString): IOTAFile;
279 begin
280 Result := nil;
281 end;
283 { TTntNewFormWizard }
285 function TTntNewFormWizard.ThisFormName: WideString;
286 begin
287 Result := ThisFormClass.ClassName;
288 Delete(Result, 1, 1); // drop the 'T'
289 end;
291 function TTntNewFormWizard.ThisFormUnit: WideString;
292 begin
293 Result := GetTypeData(ThisFormClass.ClassInfo).UnitName;
294 end;
296 function TTntNewFormWizard.GetName: AnsiString;
297 begin
298 Result := ThisFormName;
299 end;
301 function TTntNewFormWizard.GetAuthor: AnsiString;
302 begin
303 Result := 'Troy Wolbrink';
304 end;
306 function TTntNewFormWizard.GetPage: AnsiString;
307 begin
308 Result := 'New';
309 end;
311 function TTntNewFormWizard.GetGlyph: HICON;
312 begin
313 Result := 0;
314 end;
316 function TTntNewFormWizard.GetState: TWizardState;
317 begin
318 Result := [wsEnabled];
319 end;
321 function TTntNewFormWizard.GetIDString: AnsiString;
322 begin
323 Result := 'Tnt.Create_'+ThisFormName+'.Wizard';
324 end;
326 procedure TTntNewFormWizard.Execute;
328 Module: IOTAModule;
329 begin
330 Module := (BorlandIDEServices as IOTAModuleServices).CreateModule(TTntNewFormCreator.Create(ThisFormUnit, ThisFormName));
331 end;
333 {$IFDEF COMPILER_6_UP}
334 function TTntNewFormWizard.GetDesigner: AnsiString;
335 begin
336 Result := dVCL;
337 end;
338 {$ENDIF}
340 {$IFDEF COMPILER_9_UP}
341 function TTntNewFormWizard.GetGalleryCategory: IOTAGalleryCategory;
343 Manager: IOTAGalleryCategoryManager;
344 begin
345 Result := nil;
346 Manager := BorlandIDEServices as IOTAGalleryCategoryManager;
347 if Assigned(Manager) then
348 Result := Manager.FindCategory(sCategoryDelphiNew);
349 end;
351 function TTntNewFormWizard.GetPersonality: AnsiString;
352 begin
353 Result := sDelphiPersonality;
354 end;
355 {$ENDIF}
357 { TTntSourceFile }
359 constructor TTntSourceFile.Create(const Source: AnsiString);
360 begin
361 FSource := Source;
362 end;
364 function TTntSourceFile.GetAge: TDateTime;
365 begin
366 Result := -1;
367 end;
369 function TTntSourceFile.GetSource: AnsiString;
370 begin
371 Result := FSource;
372 end;
374 { TTntNewTntFormWizard }
376 function TTntNewTntFormWizard.ThisFormClass: TComponentClass;
377 begin
378 Result := TTntForm;
379 end;
381 function TTntNewTntFormWizard.GetName: AnsiString;
382 begin
383 Result := ThisFormName + ' (Unicode)'
384 end;
386 function TTntNewTntFormWizard.GetComment: AnsiString;
387 begin
388 Result := 'Creates a new Unicode enabled TntForm';
389 end;
391 { TTntNewTntFrameWizard }
393 function TTntNewTntFrameWizard.ThisFormClass: TComponentClass;
394 begin
395 Result := TTntFrame;
396 end;
398 function TTntNewTntFrameWizard.GetName: AnsiString;
399 begin
400 Result := ThisFormName + ' (Unicode)'
401 end;
403 function TTntNewTntFrameWizard.GetComment: AnsiString;
404 begin
405 Result := 'Creates a new Unicode enabled TntFrame';
406 end;
408 { TTntFrameCustomModule }
410 function TTntFrameCustomModule.Nestable: Boolean;
411 begin
412 Result := True;
413 end;
415 { TTntFormCustomModule }
417 class function TTntFormCustomModule.DesignClass: TComponentClass;
418 begin
419 Result := TTntForm;
420 end;
422 end.