objectdef.pp 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807
  1. {
  2. This file is part of the fpgtk package
  3. Copyright (c) 1999-2000 by Michael van Canney, Sebastian Guenther
  4. Object definitions
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$mode delphi}{$h+}
  12. unit ObjectDef;
  13. {_$define writecreate}{_$define loaddebug}
  14. interface
  15. {$IFDEF FPC_DOTTEDUNITS}
  16. uses
  17. System.SysUtils, System.Classes;
  18. {$ELSE FPC_DOTTEDUNITS}
  19. uses
  20. sysutils, Classes;
  21. {$ENDIF FPC_DOTTEDUNITS}
  22. const
  23. VersionNumber = '1.08';
  24. type
  25. TLukStepitProc = procedure of Object;
  26. TLukStepitMaxProc = procedure (Max : integer) of Object;
  27. TInterfaceSection = (isPrivate,isProtected,isPublic,isPublished);
  28. TPropType = (ptField,ptProperty,ptFunction,ptProcedure,ptSignal,
  29. ptHelperProc,ptHelperFunc,ptSignalType,ptDeclarations,ptTypeDecl,
  30. ptConstructor,ptDestructor,ptInitialization, ptFinalization);
  31. TpropFuncType = (pftGtkFunc,pftObjField,pftObjFunc,pftField,pftProc,pftNotImplemented,
  32. pftGtkMacro,pftExistingProc);
  33. TParamType = (ptNone,ptVar,ptConst);
  34. TProcType = (ptOverride, ptVirtual, ptDynamic, ptAbstract, ptCdecl,
  35. ptOverload, ptReintroduce);
  36. TProcTypeSet = set of TProcType;
  37. TObjectDefs = class;
  38. TObjectItem = class;
  39. TPropertyItem = class;
  40. TParameterItem = class (TCollectionItem)
  41. private
  42. FName : AnsiString;
  43. FConvert: boolean;
  44. FpascalType: AnsiString;
  45. FParamType: TParamType;
  46. protected
  47. function GetDisplayName : AnsiString; override;
  48. procedure SetDisplayName(Const Value : AnsiString); override;
  49. procedure AssignTo(Dest: TPersistent); override;
  50. public
  51. constructor Create (ACollection : TCollection); override;
  52. destructor destroy; override;
  53. published
  54. property Name : AnsiString read FName write FName;
  55. { De naam van de parameter }
  56. property PascalType : AnsiString read FpascalType write FPascalType;
  57. { Zijn type }
  58. property Convert : boolean read FConvert write FConvert default false;
  59. { geeft aan of er een omzetting dient te gebeuren voor het gebruiken }
  60. property ParamType : TParamType read FParamType write FParamType default ptNone;
  61. { het type van parameter : var, const of niets }
  62. end;
  63. TParamCollection = class (TCollection)
  64. private
  65. FProcedure : TPropertyItem;
  66. function GetItem(Index: Integer): TParameterItem;
  67. procedure SetItem(Index: Integer; const Value: TParameterItem);
  68. protected
  69. function GetOwner : TPersistent; override;
  70. public
  71. constructor create (AOwner : TPropertyItem);
  72. property Items[Index: Integer]: TParameterItem read GetItem write SetItem; default;
  73. end;
  74. TPropertyItem = class (TCollectionItem)
  75. private
  76. FPropType : TPropType;
  77. FName: AnsiString;
  78. FSection: TInterfaceSection;
  79. FPascalType: AnsiString;
  80. FParameters: TParamCollection;
  81. FGtkName: AnsiString;
  82. FWriteProcType: TpropFuncType;
  83. FReadFuncType: TPropFuncType;
  84. FWriteGtkName: AnsiString;
  85. FCode: TStringList;
  86. FWriteCode: TStringList;
  87. FProctypes: TProcTypeSet;
  88. FWriteConvert: boolean;
  89. FReadConvert: boolean;
  90. procedure SetCode(const Value: TStringList);
  91. procedure SetWriteCode(const Value: TStringList);
  92. procedure SetPropType(const Value: TPropType);
  93. protected
  94. function GetDisplayName: AnsiString; override;
  95. procedure SetDisplayName(const Value: AnsiString); override;
  96. procedure AssignTo(Dest: TPersistent); override;
  97. public
  98. constructor create (ACollection : TCollection); override;
  99. destructor destroy; override;
  100. published
  101. property PropType : TPropType read FPropType write SetPropType default ptProcedure;
  102. { wat voor iets het is } // Moet voor DisplayName staan voor goede inleesvolgorde
  103. property Name : AnsiString read FName write FName;
  104. { Naam van de property/functie/proc/veld/... }
  105. property Section : TInterfaceSection read FSection write FSection default isPublic;
  106. { waar het geplaats moet worden private, public, ... }
  107. property PascalType : AnsiString read FPascalType write FPascalType;
  108. { het type van property, functie, veld, signal (moet dan wel gedefinieerd zijn) }
  109. property Parameters : TParamCollection read FParameters write FParameters;
  110. { de parameters die doorgegeven moeten worden via de functie/procedure/signaltype }
  111. property GtkName : AnsiString read FGtkName write FGtkName;
  112. { de naam zoals GTK die gebruikt (waarschijnlijk met _ in) }
  113. property Code : TStringList read FCode write SetCode;
  114. { Property specifiek }
  115. // ReadGtkName wordt weggeschreven in GtkName
  116. // ReadCode wordt weggeschreven in Code
  117. // parameters worden gebruikt om indexen aan te geven
  118. property ReadFuncType : TPropFuncType read FReadFuncType write FReadFuncType default pftGtkFunc;
  119. { hoe de read functie moet werken : gtk-functie, object-veld, object-functie, eigen functie }
  120. property ReadConvert : boolean read FReadConvert write FReadConvert default false;
  121. { Geeft aan of de waarde voor toekenning aan result moet omgezet worden }
  122. property WriteProcType : TpropFuncType read FWriteProcType write FWriteProcType default pftGtkFunc;
  123. { hoe de write functie moet werken : gtk-proc, object-veld, object-proc, eigen proc }
  124. property WriteGtkName : AnsiString read FWriteGtkName write FWriteGtkName;
  125. { de naam zoals gtk of object die gebruikt. Gebruikt in write, voor read zie GtkName }
  126. property WriteConvert : boolean read FWriteConvert write FWriteConvert default false;
  127. { Geeft aan of de waarde moet omgezet worden voor het doorgeven }
  128. property WriteCode : TStringList read FWriteCode write SetWriteCode;
  129. { procedure specifiek } //gebruikt code
  130. property ProcTypes : TProcTypeSet read FProctypes write FProcTypes default [];
  131. { Duid het type procedure/functie aan : abstract, virtual, ... }
  132. end;
  133. TPropertyCollection = class (TCollection)
  134. private
  135. FObject : TobjectItem;
  136. function GetItem(Index: Integer): TPropertyItem;
  137. procedure SetItem(Index: Integer; const Value: TPropertyItem);
  138. protected
  139. function GetOwner : TPersistent; override;
  140. public
  141. constructor create (AOwner : TObjectItem);
  142. property Items[Index: Integer]: TPropertyItem read GetItem write SetItem; default;
  143. end;
  144. TObjectItem = class (TCollectionItem)
  145. private
  146. FInherit: AnsiString;
  147. FName: AnsiString;
  148. FProps: TPropertyCollection;
  149. FGtkFuncName: AnsiString;
  150. FWithPointer: boolean;
  151. FCreateObject: boolean;
  152. FGtkName: AnsiString;
  153. FCreateParams: AnsiString;
  154. procedure SetProps(const Value: TPropertyCollection);
  155. procedure SetGtkFuncName(const Value: AnsiString);
  156. protected
  157. function GetDisplayName: AnsiString; override;
  158. procedure SetDisplayName(const Value: AnsiString); override;
  159. procedure AssignTo(Dest: TPersistent); override;
  160. public
  161. constructor create (ACollection : TCollection); override;
  162. destructor destroy; override;
  163. published
  164. property Name : AnsiString read FName write FName;
  165. { Naam van het object }
  166. property Inherit : AnsiString read FInherit write FInherit;
  167. { De naam van het object dat ancester is }
  168. property GtkFuncName : AnsiString read FGtkFuncName write SetGtkFuncName;
  169. { Naam van het object in gtk zoals het in de functies en procedures gebruikt wordt }
  170. property GtkName : AnsiString read FGtkName write FGtkName;
  171. { Naam van het objectrecord in gtk zoals gebruikt in typedeclaraties}
  172. property Props : TPropertyCollection read FProps write SetProps;
  173. { De verschillende properties, procedures, ... van en voor het object }
  174. property WithPointer : boolean read FWithPointer write FWithPointer default false;
  175. { duid aan of er ook een pointerdefinitie moet zijn }
  176. property CreateObject : boolean read FCreateObject write FCreateObject default false;
  177. { duid aan of er een CreateGtkObject procedure moet aangemaakt worden }
  178. property CreateParams : AnsiString read FCreateParams write FCreateParams;
  179. { Geeft de parameters die meegeven moeten worden aan de _New functie }
  180. end;
  181. TObjectCollection = class (TCollection)
  182. private
  183. FGtkDEf : TObjectDefs;
  184. function GetItem(Index: Integer): TObjectItem;
  185. procedure SetItem(Index: Integer; const Value: TObjectItem);
  186. protected
  187. function GetOwner : TPersistent; override;
  188. public
  189. constructor create (AOwner : TObjectDefs);
  190. property Items[Index: Integer]: TObjectItem read GetItem write SetItem; default;
  191. end;
  192. TObjectDefs = class(TComponent)
  193. private
  194. FDefinition: TObjectCollection;
  195. FGtkPrefix,
  196. FUsesList,
  197. FUnitName: AnsiString;
  198. {$IFNDEF Delphi}
  199. FTop, FLeft : integer;
  200. {$ENDIF}
  201. procedure SetDefinition(const Value: TObjectCollection);
  202. { Private declarations }
  203. protected
  204. { Protected declarations }
  205. public
  206. { Public declarations }
  207. constructor create (AOwner : TComponent); override;
  208. destructor destroy; override;
  209. procedure Write (TheUnit : TStrings; StepIt : TLukStepItProc; StepItMax : TLukStepItMaxProc);
  210. procedure Save (List : TStrings);
  211. procedure Load (List : TStrings);
  212. published
  213. { Published declarations }
  214. property Definition : TObjectCollection read FDefinition write SetDefinition;
  215. property GtkPrefix : AnsiString read FGtkPrefix write FGtkPrefix;
  216. property UnitName : AnsiString read FUnitName write FUnitName;
  217. property UsesList : AnsiString read FUsesList write FUsesList;
  218. {$IFNDEF delphi}
  219. // Compatibiliteit met Delphi
  220. property Left : integer read FLeft write FLeft;
  221. property Top : integer read FTop write FTop;
  222. {$ENDIF}
  223. end;
  224. var
  225. GtkPrefix : AnsiString = 'gtk';
  226. ObjectsPrefix : AnsiString = 'FPgtk';
  227. procedure Register;
  228. implementation
  229. //uses dsgnIntf;
  230. const
  231. SectPublic = [isPublic,isPublished];
  232. SectPriv = [isPrivate,isProtected];
  233. CRLF = #13#10;
  234. PropUsesGtkName = [pftProc, pftExistingProc];
  235. var
  236. lowerObjectsPrefix : AnsiString;
  237. ObjectsPrefixLength : integer;
  238. procedure Register;
  239. begin
  240. RegisterComponents('Luk', [TObjectDefs]);
  241. end;
  242. { TParamCollection }
  243. constructor TParamCollection.create(AOwner: TPropertyItem);
  244. begin
  245. inherited Create (TParameterItem);
  246. FProcedure := AOwner;
  247. end;
  248. function TParamCollection.GetItem(Index: Integer): TParameterItem;
  249. begin
  250. result := TParameterItem (inherited Items[index]);
  251. end;
  252. function TParamCollection.GetOwner: TPersistent;
  253. begin
  254. result := FProcedure;
  255. end;
  256. procedure TParamCollection.SetItem(Index: Integer;
  257. const Value: TParameterItem);
  258. begin
  259. inherited Items[Index] := Value;
  260. end;
  261. { TParameterItem }
  262. procedure TParameterItem.AssignTo(Dest: TPersistent);
  263. begin
  264. if Dest is TParameterItem then
  265. with TParameterItem(Dest) do
  266. begin
  267. FName := Self.FName;
  268. FConvert := Self.FConvert;
  269. FpascalType := Self.FpascalType;
  270. FParamType := Self.FParamType;
  271. end
  272. else
  273. inherited;
  274. end;
  275. constructor TParameterItem.Create(ACollection: TCollection);
  276. begin
  277. inherited;
  278. FConvert := False;
  279. FParamType := ptNone;
  280. end;
  281. destructor TParameterItem.destroy;
  282. begin
  283. inherited;
  284. end;
  285. function TParameterItem.GetDisplayName: AnsiString;
  286. begin
  287. result := FName;
  288. end;
  289. procedure TParameterItem.SetDisplayName(const Value: AnsiString);
  290. begin
  291. FName := Value;
  292. end;
  293. { TPropertyItem }
  294. procedure TPropertyItem.AssignTo(Dest: TPersistent);
  295. var r : integer;
  296. begin
  297. if Dest is TPropertyItem then
  298. with TPropertyItem(Dest) do
  299. begin
  300. FPropType := Self.FPropType;
  301. FName := Self.FName;
  302. FSection := Self.FSection;
  303. FPascalType := Self.FPascalType;
  304. FParameters.clear;
  305. for r := 0 to pred(self.FParameters.count) do
  306. FParameters.Add.assign (self.FParameters[r]);
  307. FGtkName := Self.FGtkName;
  308. FWriteProcType := Self.FWriteProcType;
  309. FReadFuncType := Self.FReadFuncType;
  310. FWriteGtkName := Self.FWriteGtkName;
  311. FCode.Assign(Self.FCode);
  312. FWriteCode.assign(Self.FWriteCode);
  313. FProctypes := Self.FProctypes;
  314. FWriteConvert := Self.FWriteConvert;
  315. FReadConvert := Self.FReadConvert;
  316. end
  317. else
  318. inherited;
  319. end;
  320. constructor TPropertyItem.create(ACollection: TCollection);
  321. begin
  322. inherited;
  323. FParameters := TParamCollection.Create (Self);
  324. FPropType := ptProcedure;
  325. FSection := isPublic;
  326. FCode := TStringList.Create;
  327. FWriteCode := TStringList.Create;
  328. {$IFDEF writecreate}
  329. writeln ('Property Item created');
  330. {$ENDIF}
  331. end;
  332. destructor TPropertyItem.destroy;
  333. begin
  334. FParameters.Free;
  335. inherited;
  336. end;
  337. const
  338. DispPropType : array [TPropType] of AnsiString =
  339. ('Field','Property','Function','Procedure', 'Signal',
  340. 'HelperProc','HelperFunc','SignalType','Declarations', 'TypeDeclaration',
  341. 'Constructor','Destructor','Initialization','Finilization');
  342. function TPropertyItem.GetDisplayName: AnsiString;
  343. begin
  344. if FPropType = ptDeclarations then
  345. if Section = ispublished then
  346. result := 'Interface code before'
  347. else if Section = ispublic then
  348. result := 'Interface code after'
  349. else
  350. result := 'Implementation code'
  351. else
  352. begin
  353. result := DispProptype[FPropType];
  354. if FPropType in [ptInitialization, ptFinalization] then
  355. result := result + ' code'
  356. else
  357. result := FName + ' (' + result + ')';
  358. end;
  359. end;
  360. procedure TPropertyItem.SetCode(const Value: TStringList);
  361. begin
  362. FCode.assign (Value);
  363. end;
  364. procedure TPropertyItem.SetDisplayName(const Value: AnsiString);
  365. begin
  366. FName := Value;
  367. end;
  368. procedure TPropertyItem.SetPropType(const Value: TPropType);
  369. begin
  370. FPropType := Value;
  371. end;
  372. procedure TPropertyItem.SetWriteCode(const Value: TStringList);
  373. begin
  374. FWriteCode.assign (Value);
  375. end;
  376. { TPropertyCollection }
  377. constructor TPropertyCollection.create (AOwner : TObjectItem);
  378. begin
  379. inherited create (TPropertyItem);
  380. FObject := AOwner;
  381. end;
  382. function TPropertyCollection.GetItem(Index: Integer): TPropertyItem;
  383. begin
  384. result := TPropertyItem(inherited items[index]);
  385. end;
  386. function TPropertyCollection.GetOwner: TPersistent;
  387. begin
  388. result := FObject;
  389. end;
  390. procedure TPropertyCollection.SetItem(Index: Integer;
  391. const Value: TPropertyItem);
  392. begin
  393. Inherited Items[index] := Value;
  394. end;
  395. { TObjectItem }
  396. procedure TObjectItem.AssignTo(Dest: TPersistent);
  397. var r : integer;
  398. begin
  399. if Dest is TObjectItem then
  400. with TObjectItem(Dest) do
  401. begin
  402. FName := self.FName;
  403. FProps.clear;
  404. for r := 0 to pred(Self.FProps.count) do
  405. FProps.Add.assign (self.FProps[r]);
  406. FInherit := Self.FInherit;
  407. FGtkFuncName := Self.FGtkFuncName;
  408. FWithPointer := Self.FWithPointer;
  409. FCreateObject := Self.FCreateObject;
  410. FGtkName := Self.FGtkName;
  411. FCreateParams := Self.FCreateParams;
  412. end
  413. else
  414. inherited;
  415. end;
  416. constructor TObjectItem.create(ACollection: TCollection);
  417. begin
  418. inherited create (ACollection);
  419. FProps := TpropertyCollection.Create (Self);
  420. end;
  421. destructor TObjectItem.destroy;
  422. begin
  423. FProps.Free;
  424. inherited;
  425. end;
  426. function TObjectItem.GetDisplayName: AnsiString;
  427. begin
  428. result := FName;
  429. end;
  430. procedure TObjectItem.SetDisplayName(const Value: AnsiString);
  431. begin
  432. FName := Value;
  433. end;
  434. procedure TObjectItem.SetGtkFuncName(const Value: AnsiString);
  435. begin
  436. FGtkFuncName := Value;
  437. {$IFDEF writecreate}
  438. writeln ('GtkFuncname = ', Value);
  439. {$ENDIF}
  440. end;
  441. procedure TObjectItem.SetProps(const Value: TPropertyCollection);
  442. begin
  443. FProps.assign(Value);
  444. end;
  445. { TObjectCollection }
  446. constructor TObjectCollection.create (AOwner : TObjectDefs);
  447. begin
  448. inherited create (TObjectItem);
  449. FGtkDef := AOwner;
  450. end;
  451. function TObjectCollection.GetItem(Index: Integer): TObjectItem;
  452. begin
  453. result := TObjectItem(inherited Items[index]);
  454. end;
  455. function TObjectCollection.GetOwner: TPersistent;
  456. begin
  457. result := FGtkDef;
  458. end;
  459. procedure TObjectCollection.SetItem(Index: Integer;
  460. const Value: TObjectItem);
  461. begin
  462. inherited items[index] := Value;
  463. end;
  464. { TObjectDefs }
  465. constructor TObjectDefs.create (AOwner : TComponent);
  466. begin
  467. inherited create (AOwner);
  468. FDefinition := TObjectCollection.Create (self);
  469. FgtkPrefix := 'gtk';
  470. end;
  471. destructor TObjectDefs.destroy;
  472. begin
  473. FDefinition.Free;
  474. inherited;
  475. end;
  476. procedure TObjectDefs.SetDefinition(const Value: TObjectCollection);
  477. begin
  478. FDefinition.assign(Value);
  479. end;
  480. const
  481. DispPropFuncType : array [TPropFuncType] of AnsiString = ('GtkFunc','ObjField',
  482. 'ObjFunc','Field','Proc','NotImplemented','GtkMacro','ExistingProc');
  483. DispProcType : array [TProcType] of AnsiString = ('Override', 'Virtual', 'Dynamic',
  484. 'Abstract', 'Cdecl', 'Overload', 'Reintroduce');
  485. procedure TObjectDefs.Save (List : TStrings);
  486. procedure WriteParameter (AParameter : TParameterItem);
  487. begin
  488. with AParameter do
  489. begin
  490. List.Add (' Param=' + FName);
  491. if FConvert then
  492. List.Add (' Convert');
  493. if FpascalType <> '' then
  494. List.Add (' PascalType=' + FpascalType);
  495. if FParamType = ptVar then
  496. List.Add (' ParamType=Var')
  497. else if FParamType = ptConst then
  498. List.Add (' ParamType=Const');
  499. end;
  500. end;
  501. procedure WriteProperty (AProperty : TPropertyItem);
  502. var r : integer;
  503. pt : TProcType;
  504. begin
  505. with AProperty do
  506. begin
  507. List.Add (' Prop=' + FName);
  508. List.Add (' PropType='+DispPropType[FPropType]);
  509. if FSection = isprivate then
  510. List.Add (' Section=Private')
  511. else if FSection = isprotected then
  512. List.Add (' Section=Protected')
  513. else if FSection = isPublished then
  514. List.Add (' Section=Published');
  515. if FPascalType <> '' then
  516. List.Add (' PascalType=' + FPascalType);
  517. if FGtkName <> '' then
  518. List.Add (' GtkName=' + FGtkName);
  519. if Fcode.count > 0 then
  520. List.Add (' Code='+FCode.Commatext);
  521. if FReadConvert then
  522. List.Add (' ReadConvert');
  523. if FReadFuncType <> pftGtkFunc then
  524. List.Add (' ReadFuncType='+ DispPropFuncType[FReadFuncType]);
  525. if FWriteProcType <> pftGtkFunc then
  526. List.Add (' WriteProcType='+ DispPropFuncType[FWriteProcType]);
  527. if FWriteGtkName <> '' then
  528. List.Add (' WriteGtkName=' + FWriteGtkName);
  529. if FWritecode.count > 0 then
  530. List.Add (' WriteCode='+FWriteCode.Commatext);
  531. if FWriteConvert then
  532. List.Add (' WriteConvert');
  533. if FProcTypes <> [] then
  534. for pt := low(TProcType) to high(TProcType) do
  535. if pt in FProcTypes then
  536. List.Add (' '+DispProcType[pt]);
  537. with FParameters do
  538. begin
  539. List.Add (' Count='+inttostr(Count));
  540. for r := 0 to count-1 do
  541. WriteParameter (Items[r]);
  542. end;
  543. end;
  544. end;
  545. procedure WriteObject (AnObject : TObjectItem);
  546. var r : integer;
  547. begin
  548. with AnObject do
  549. begin
  550. List.Add (' Object=' + FName);
  551. if FInherit <> '' then
  552. List.Add (' Inherit=' + FInherit);
  553. if FGtkFuncName <> '' then
  554. List.Add (' GtkFuncName=' + FGtkFuncName);
  555. if FGtkName <> '' then
  556. List.Add (' GtkName=' + FGtkName);
  557. if FCreateParams <> '' then
  558. List.Add (' CreateParams=' + FCreateParams);
  559. if FWithPointer then
  560. List.Add (' WithPointer');
  561. if FCreateObject then
  562. List.Add (' CreateObject');
  563. with FProps do
  564. begin
  565. List.Add (' Count='+inttostr(count));
  566. for r := 0 to count-1 do
  567. WriteProperty (Items[r]);
  568. end;
  569. end;
  570. end;
  571. var r : integer;
  572. begin
  573. List.Add ('definition');
  574. if FGtkPrefix <> '' then
  575. List.Add (' GtkPrefix=' + FGtkPrefix);
  576. if FUsesList <> '' then
  577. List.Add (' UsesList=' + FUsesList);
  578. if FUnitName <> '' then
  579. List.Add (' UnitName=' + FUnitName);
  580. with Definition do
  581. begin
  582. List.Add (' Count=' + inttostr(count));
  583. for r := 0 to count-1 do
  584. WriteObject (Items[r])
  585. end;
  586. end;
  587. resourcestring
  588. sErrWrongFirstLine = 'Error: First line doesn''t contain correct word';
  589. sErrCountExpected = 'Error: "Count" expected on line %d';
  590. sErrObjectExpected = 'Error: "Object" expected on line %d';
  591. sErrPropertyExpected = 'Error: "Prop" expected on line %d';
  592. sErrProptypeExpected = 'Error: "PropType" expected on line %d';
  593. sErrParameterExpected = 'Error: "Param" expected on line %d';
  594. procedure TObjectDefs.Load (List : TStrings);
  595. var line : integer;
  596. item, value : AnsiString;
  597. HasLine : boolean;
  598. procedure SplitNext;
  599. var p : integer;
  600. begin
  601. inc (line);
  602. HasLine := (line < List.Count);
  603. if HasLine then
  604. begin
  605. item := List[Line];
  606. p := pos ('=', item);
  607. if p = 0 then
  608. value := ''
  609. else
  610. begin
  611. value := copy(item, p+1, maxint);
  612. item := copy(item, 1, p-1);
  613. end;
  614. end
  615. else
  616. begin
  617. Item := '';
  618. value := '';
  619. end;
  620. end;
  621. procedure ReadParameter (AParameter : TParameterItem);
  622. begin
  623. with AParameter do
  624. begin
  625. if HasLine and (item = ' Param') then
  626. begin
  627. FName := value;
  628. {$ifdef LoadDebug}writeln (' Parameter Name ', FName);{$endif}
  629. SplitNext;
  630. end
  631. else
  632. raise exception.CreateFmt (sErrParameterExpected, [line]);
  633. if HasLine then
  634. begin
  635. FConvert := (item = ' Convert');
  636. {$ifdef LoadDebug}writeln (' Convert ', FConvert);{$endif}
  637. if FConvert then
  638. SplitNext;
  639. end;
  640. if HasLine and (item = ' PascalType') then
  641. begin
  642. FPascalType := value;
  643. {$ifdef LoadDebug}writeln (' PascalType ', FPascalType);{$endif}
  644. SplitNext;
  645. end;
  646. if HasLine and (item = ' ParamType') then
  647. begin
  648. if Value = 'Var' then
  649. FParamType := ptVar
  650. else if Value = 'Const' then
  651. FParamType := ptConst;
  652. {$ifdef LoadDebug}writeln (' ParamType ', ord(FParamtype));{$endif}
  653. SplitNext;
  654. end;
  655. end;
  656. end;
  657. procedure ReadProperty (AProperty : TPropertyItem);
  658. var RProcType : TProcType;
  659. Rproptype : TPropType;
  660. RpropFuncType : TpropFuncType;
  661. counter : integer;
  662. s : AnsiString;
  663. begin
  664. with AProperty do
  665. begin
  666. if HasLine and (item = ' Prop') then
  667. begin
  668. FName := value;
  669. {$ifdef LoadDebug}writeln (' Property Name ', FName);{$endif}
  670. SplitNext;
  671. end
  672. else
  673. raise exception.CreateFmt (sErrPropertyExpected, [line]);
  674. if HasLine and (item = ' PropType') then
  675. begin
  676. RProptype := high(TPropType);
  677. while (RPropType > low(TPropType)) and (DispPropType[RPropType] <> value) do
  678. dec (RPropType);
  679. FPropType := RPropType;
  680. {$ifdef LoadDebug}writeln (' PropType ', ord(FPropType));{$endif}
  681. SplitNext;
  682. end
  683. else
  684. raise exception.CreateFmt (sErrPropTypeExpected, [Line]);
  685. Section := isPublic;
  686. if HasLine and (item = ' Section') then
  687. begin
  688. if value = 'Private' then
  689. Section := isPrivate
  690. else if value = 'Protected' then
  691. FSection := isprotected
  692. else if value = 'Published' then
  693. FSection := isPublished;
  694. SplitNext;
  695. {$ifdef LoadDebug}writeln (' Section ', ord(FSection));{$endif}
  696. end;
  697. if HasLine and (item = ' PascalType') then
  698. begin
  699. FPascalType := value;
  700. {$ifdef LoadDebug}writeln (' PascalType ', FPascalType);{$endif}
  701. SplitNext;
  702. end;
  703. if HasLine and (item = ' GtkName') then
  704. begin
  705. FGtkName := value;
  706. {$ifdef LoadDebug}writeln (' GtkName ', FGtkName);{$endif}
  707. SplitNext;
  708. end;
  709. if HasLine and (item = ' Code') then
  710. begin
  711. FCode.Commatext := value;
  712. {$ifdef LoadDebug}writeln (' Code set');{$endif}
  713. SplitNext;
  714. end;
  715. if HasLine then
  716. begin
  717. FReadConvert := (item = ' ReadConvert');
  718. {$ifdef LoadDebug}writeln (' ReadConvert ', FReadConvert);{$endif}
  719. if FReadConvert then
  720. SplitNext;
  721. end;
  722. if HasLine and (item = ' ReadFuncType') then
  723. begin
  724. RpropFuncType := high(TpropFuncType);
  725. while (RpropFuncType > low(TpropFuncType)) and
  726. (value <> DispPropFuncType[RpropFuncType]) do
  727. dec (RpropFuncType);
  728. FReadFuncType := RpropFuncType;
  729. {$ifdef LoadDebug}writeln (' ReadFuncType ', ord(FReadFunctype));{$endif}
  730. if RpropFuncType > low(TpropFuncType) then
  731. Splitnext;
  732. end;
  733. if HasLine and (item = ' WriteProcType') then
  734. begin
  735. RpropFuncType := high(TpropFuncType);
  736. while (RpropFuncType > low(TpropFuncType)) and
  737. (value <> DispPropFuncType[RpropFuncType]) do
  738. dec (RpropFuncType);
  739. FWriteProcType := RpropFuncType;
  740. {$ifdef LoadDebug}writeln (' WriteProcType ', ord(FWriteProcType));{$endif}
  741. if RpropFuncType > low(TpropFuncType) then
  742. Splitnext;
  743. end;
  744. if HasLine and (item = ' WriteGtkName') then
  745. begin
  746. FWriteGtkName := value;
  747. {$ifdef LoadDebug}writeln (' WriteGtkName ', FWriteGtkName);{$endif}
  748. SplitNext;
  749. end;
  750. if HasLine and (item = ' WriteCode') then
  751. begin
  752. FWriteCode.Commatext := value;
  753. {$ifdef LoadDebug}writeln (' WriteCode set');{$endif}
  754. SplitNext;
  755. end;
  756. if HasLine then
  757. begin
  758. FWriteConvert := (item = ' WriteConvert');
  759. {$ifdef LoadDebug}writeln (' WriteConvert ', FWriteConvert);{$endif}
  760. if FWriteConvert then
  761. SplitNext;
  762. end;
  763. FProcTypes := [];
  764. if HasLine then
  765. begin
  766. s := copy(item, 7, 35);
  767. for RProcType := low(TProcType) to high(TProcType) do
  768. if s = DispProcType[RProcType] then
  769. begin
  770. FProcTypes := FProcTypes + [RProcType];
  771. {$ifdef LoadDebug}writeln (' ProcType added ', s);{$endif}
  772. SplitNext;
  773. s := copy(item, 7, 35);
  774. end;
  775. end;
  776. if HasLine and (Item = ' Count') then
  777. with FParameters do
  778. begin
  779. counter := strtoint(value);
  780. {$ifdef LoadDebug}writeln (' Counter ', Counter);{$endif}
  781. SplitNext;
  782. while (Counter > 0) do
  783. begin
  784. ReadParameter (Add as TParameterItem);
  785. dec (counter);
  786. end;
  787. end
  788. else
  789. raise exception.CreateFmt (sErrCountExpected, [line]);
  790. end;
  791. end;
  792. procedure ReadObject (AnObject : TObjectItem);
  793. var counter : integer;
  794. begin
  795. with AnObject do
  796. begin
  797. if HasLine and (item = ' Object') then
  798. begin
  799. FName := value;
  800. {$ifdef LoadDebug}writeln ('Object name ', FName);{$endif}
  801. SplitNext;
  802. end
  803. else
  804. raise exception.CreateFmt (sErrObjectExpected, [line]);
  805. if HasLine and (item = ' Inherit') then
  806. begin
  807. FInherit := value;
  808. {$ifdef LoadDebug}writeln (' Inherit ', FInherit);{$endif}
  809. SplitNext;
  810. end;
  811. if HasLine and (item = ' GtkFuncName') then
  812. begin
  813. FGtkFuncName := value;
  814. {$ifdef LoadDebug}writeln (' GtkFuncName ', FGtkFuncName);{$endif}
  815. SplitNext;
  816. end;
  817. if HasLine and (item = ' GtkName') then
  818. begin
  819. FGtkName := value;
  820. {$ifdef LoadDebug}writeln (' GtkName ', FGtkName);{$endif}
  821. SplitNext;
  822. end;
  823. if HasLine and (item = ' CreateParams') then
  824. begin
  825. FCreateParams := value;
  826. {$ifdef LoadDebug}writeln (' CreateParams ', FCreateParams);{$endif}
  827. SplitNext;
  828. end;
  829. if HasLine then
  830. begin
  831. FWithPointer := (item = ' WithPointer');
  832. {$ifdef LoadDebug}writeln (' WithPointer ', FWithPointer);{$endif}
  833. if FWithPointer then
  834. SplitNext;
  835. end;
  836. if HasLine then
  837. begin
  838. FCreateObject := (item = ' CreateObject');
  839. {$ifdef LoadDebug}writeln (' CreateObject ', FCreateObject);{$endif}
  840. if FCreateObject then
  841. SplitNext;
  842. end;
  843. if HasLine and (Item = ' Count') then
  844. with FProps do
  845. begin
  846. counter := strtoint(value);
  847. {$ifdef LoadDebug}writeln (' Counter ', counter);{$endif}
  848. SplitNext;
  849. while (Counter > 0) do
  850. begin
  851. ReadProperty (Add as TPropertyItem);
  852. dec (counter);
  853. end;
  854. end
  855. else
  856. raise exception.CreateFmt (sErrCountExpected, [line]);
  857. end;
  858. end;
  859. var counter : integer;
  860. begin
  861. {$ifdef LoadDebug}writeln ('Start load');{$endif}
  862. if List[0] <> 'definition' then
  863. raise Exception.Create (sErrWrongFirstLine);
  864. {$ifdef LoadDebug}writeln ('Correct startline');{$endif}
  865. line := 0;
  866. {$ifdef LoadDebug}writeln ('Calling SplitNext');{$endif}
  867. SplitNext;
  868. if HasLine and (Item = ' GtkPrefix') then
  869. begin
  870. {$ifdef LoadDebug}writeln ('GtkPrefix=',value);{$endif}
  871. FGtkPrefix := value;
  872. SplitNext;
  873. end
  874. else
  875. FGtkPrefix := '';
  876. if HasLine and (Item = ' UsesList') then
  877. begin
  878. {$ifdef LoadDebug}writeln ('UsesList=',value);{$endif}
  879. FUsesList := value;
  880. SplitNext;
  881. end
  882. else
  883. FUsesList := '';
  884. if HasLine and (Item = ' UnitName') then
  885. begin
  886. {$ifdef LoadDebug}writeln ('UnitName=',value);{$endif}
  887. FUnitName := value;
  888. SplitNext;
  889. end
  890. else
  891. FUnitName := '';
  892. if HasLine and (Item = ' Count') then
  893. begin
  894. counter := strtoint(value);
  895. {$ifdef LoadDebug}writeln ('Counter ', counter);{$endif}
  896. if assigned(FDefinition) then
  897. begin
  898. {$ifdef LoadDebug}writeln ('Clearing ObjectDefinitions');{$endif}
  899. FDefinition.Clear;
  900. end
  901. else
  902. begin
  903. {$ifdef LoadDebug}writeln ('Creating ObjectDefinitions');{$endif}
  904. FDefinition := TObjectCollection.Create (self);
  905. end;
  906. SplitNext;
  907. while (Counter > 0) do
  908. begin
  909. ReadObject (Definition.Add as TObjectItem);
  910. dec (counter);
  911. end;
  912. end
  913. else
  914. raise exception.CreateFmt (sErrCountExpected, [line]);
  915. end;
  916. procedure TObjectDefs.Write(TheUnit : TStrings; StepIt : TLukStepItProc; StepItMax : TLukStepItMaxProc);
  917. procedure DoStepIt;
  918. begin
  919. if assigned (StepIt) then
  920. StepIt;
  921. end;
  922. procedure DoStepItMax (Max : integer);
  923. begin
  924. if assigned (StepItMax) then
  925. StepItMax (Max);
  926. end;
  927. procedure WriteObjectForward (Obj : TObjectItem);
  928. begin
  929. with obj do
  930. TheUnit.add (' T'+ObjectsPrefix+Name+' = class;');
  931. end;
  932. function CalcProcTypes (ProcTypes : TProcTypeSet; InImplementation:boolean) : AnsiString; overload;
  933. begin
  934. if not InImplementation then
  935. begin
  936. if ptOverride in ProcTypes then
  937. result := ' Override;'
  938. else
  939. begin
  940. if ptVirtual in ProcTypes then
  941. result := ' Virtual;'
  942. else if ptDynamic in ProcTypes then
  943. result := ' Dynamic;'
  944. else
  945. result := '';
  946. if (result <> '') and (ptAbstract in ProcTypes) then
  947. result := result + ' Abstract;';
  948. end;
  949. if ptreintroduce in ProcTypes then
  950. result := result + ' Reintroduce;';
  951. end;
  952. if ptCDecl in ProcTypes then
  953. result := result + ' Cdecl;';
  954. if ptOverload in ProcTypes then
  955. result := result + ' Overload;';
  956. end;
  957. function CalcProcTypes (ProcTypes : TProcTypeSet) : AnsiString; overload;
  958. begin
  959. result := CalcProcTypes (ProcTypes, False);
  960. end;
  961. type
  962. TConvType = (ToGtk, ToLuk, ToFPgtk);
  963. function ConvertType (PascalType : AnsiString; ConvType : TConvType) : AnsiString;
  964. begin
  965. PascalType := lowercase (PascalType);
  966. if ConvType = ToGtk then
  967. begin
  968. if PascalType = 'AnsiString' then
  969. result := 'pgChar'
  970. else if copy(PascalType,1,ObjectsPrefixLength+1) = 't'+LowerObjectsPrefix then
  971. result := 'PGtk' + copy (PascalType, ObjectsPrefixLength+2, maxint)
  972. else if PascalType = 'longbool' then
  973. result := 'gint'
  974. else
  975. result := PascalType;
  976. end
  977. else
  978. begin
  979. if PascalType = 'pgChar' then
  980. result := 'AnsiString'
  981. else if copy(PascalType,1,4) = 'pgtk' then
  982. result := 'T'+ObjectsPrefix + copy (PascalType, 5, maxint)
  983. else if PascalType = 'gint' then
  984. result := 'longbool'
  985. else
  986. result := PascalType;
  987. end;
  988. end;
  989. function DoConvert (Variable, PascalType : AnsiString; ConvType : TConvType) : AnsiString;
  990. var s : AnsiString;
  991. begin
  992. result := variable;
  993. PascalType := lowercase (PascalType);
  994. if PascalType = 'AnsiString' then
  995. begin
  996. if ConvType <> ToLuk then
  997. result := 'ConvertToPgchar('+result+')'
  998. end
  999. else if copy(PascalType,1,4)='pgtk' then
  1000. begin
  1001. if ConvType = ToLuk then
  1002. begin
  1003. s := 'T'+ObjectsPrefix + copy(PascalType, 5, maxint);
  1004. result := 'GetPascalInstance(PGtkObject('+result+'),'+s+') as '+ s
  1005. end
  1006. else
  1007. result := PascalType+'(ConvertToGtkObject('+result+'))'
  1008. end
  1009. else if Copy(PascalType,1,ObjectsPrefixLength+1)='t'+LowerObjectsPrefix then
  1010. begin
  1011. if ConvType = ToLuk then
  1012. result := 'GetPascalInstance(PGtkObject('+result+'),'+PascalType+') as '+PascalType
  1013. else
  1014. result := 'PGtk'+copy(PascalType,ObjectsPrefixLength+2,maxint)+'(ConvertToGtkObject('+result+'))'
  1015. end
  1016. else if PascalType = 'boolean' then
  1017. begin
  1018. if (copy(variable,1,4)='gtk.') and
  1019. (ConvType = ToLuk) then
  1020. result := 'boolean('+variable+')'
  1021. else if ConvType = ToFPGtk then
  1022. result := 'guint('+variable+')'
  1023. end
  1024. else if PascalType = 'longbool' then
  1025. begin
  1026. if (copy(variable,1,4)='gtk.') and
  1027. (ConvType = ToLuk) then
  1028. result := 'longbool('+variable+')'
  1029. else if ConvType in [ToFPGtk,ToGtk] then
  1030. result := 'gint('+variable+')';
  1031. end;
  1032. end;
  1033. function CalcParam (param : TParameterItem; Declaration : boolean; ConvType : TConvType) : AnsiString;
  1034. begin
  1035. with Param do
  1036. begin
  1037. if Declaration then
  1038. begin
  1039. case param.ParamType of
  1040. ptVar : result := 'var ';
  1041. ptconst : result := 'const ';
  1042. else result := '';
  1043. end;
  1044. result := result + Name + ':' + PascalType;
  1045. end
  1046. else
  1047. if Convert then
  1048. result := DoConvert (Name, PascalType, convType)
  1049. else
  1050. result := name;
  1051. end;
  1052. end;
  1053. type
  1054. TParamListType = (plDecl, plImpl, plImplCl, plImplLukCl);
  1055. function CalcParameterList (params : TParamCollection; PLType : TParamListType) : AnsiString; overload;
  1056. var r : integer;
  1057. Sep : AnsiString[2];
  1058. ct : TConvType;
  1059. begin
  1060. if PLType = plDecl then
  1061. Sep := '; '
  1062. else
  1063. Sep := ', ';
  1064. if PLType = plImplLukCl then
  1065. ct := ToLuk
  1066. else
  1067. ct := ToGtk;
  1068. with params do
  1069. if count = 0 then
  1070. result := ''
  1071. else
  1072. begin
  1073. result := CalcParam (Items[0], (PLType=plDecl), ct);
  1074. for r := 1 to count-1 do
  1075. result := result + Sep + CalcParam (items[r], (PLType=plDecl), ct);
  1076. if PLType <> plImpl then
  1077. result := ' (' + result + ')';
  1078. end;
  1079. end;
  1080. function CalcParameterList (params : TParamCollection) : AnsiString; overload;
  1081. var r : integer;
  1082. begin
  1083. with params do
  1084. if count = 0 then
  1085. result := ''
  1086. else
  1087. begin
  1088. with Items[0] do
  1089. result := Name + ':' + PascalType;
  1090. for r := 1 to count-1 do
  1091. with Items[r] do
  1092. result := result + '; ' + Name + ':' + PascalType;
  1093. end;
  1094. end;
  1095. var Lpublic, LProt, LPriv, LPublish : TStrings;
  1096. procedure WriteObjectInterface (Obj : TObjectItem);
  1097. var r : integer;
  1098. TheList : TStrings;
  1099. I, N, s : AnsiString;
  1100. begin
  1101. Lpublic.Clear;
  1102. LProt.Clear;
  1103. LPriv.Clear;
  1104. LPublish.clear;
  1105. with obj do
  1106. begin
  1107. // Signal declarations
  1108. with props do
  1109. begin
  1110. for r := 0 to count-1 do
  1111. with Items[r] do
  1112. begin
  1113. if (PropType = ptSignalType) then
  1114. if PascalType = '' then
  1115. TheUnit.add (' T'+ObjectsPrefix+Name+'Function = procedure' +
  1116. CalcParameterList(parameters,plDecl)+' of Object;')
  1117. else
  1118. TheUnit.add (' T'+ObjectsPrefix+Name+'Function = function' +
  1119. CalcParameterList(parameters,plDecl)+': '+PascalType+' of Object;')
  1120. else if (PropType = ptTypeDecl) then
  1121. TheUnit.AddStrings (Code);
  1122. end;
  1123. end;
  1124. TheUnit.Add ('');
  1125. // Class definition
  1126. if WithPointer then
  1127. TheUnit.Add (' P'+ObjectsPrefix+Name+' = ^T'+ObjectsPrefix+Name+';');
  1128. if Inherit = '' then
  1129. TheUnit.add (' T'+ObjectsPrefix+Name+' = class')
  1130. else
  1131. begin
  1132. if inherit[1] = '*' then
  1133. s := copy(inherit, 2, maxint)
  1134. else
  1135. s := ObjectsPrefix + Inherit;
  1136. TheUnit.add (' T'+ObjectsPrefix+Name+' = class (T'+s+')');
  1137. end;
  1138. { Filling the 4 sections with the properties }
  1139. for r := 0 to props.count-1 do
  1140. with Props[r] do
  1141. begin
  1142. case Section of
  1143. isPrivate : TheList := LPriv;
  1144. isProtected : TheList := LProt;
  1145. isPublic : TheList := LPublic;
  1146. else TheList := LPublish;
  1147. end;
  1148. case PropType of
  1149. ptField :
  1150. TheList.Insert(0,' ' + Name + ':' + PascalType + ';');
  1151. ptProperty :
  1152. begin
  1153. s := ' property ' + Name;
  1154. if (ReadFuncType <> pftNotImplemented) or
  1155. (WriteProcType <> pftNotImplemented) then
  1156. begin
  1157. if Parameters.Count > 0 then
  1158. begin
  1159. I := CalcParameterlist(parameters);
  1160. s := s + ' ['+I+'] ';
  1161. end;
  1162. s := s + ' : ' + PascalType;
  1163. if (ReadFuncType <> pftNotImplemented) then
  1164. begin
  1165. s := s + ' read ';
  1166. if ReadFuncType = pftField then
  1167. begin
  1168. if GtkName <> '' then
  1169. N := GtkName
  1170. else
  1171. N := 'F' + Name;
  1172. LPriv.insert (0, ' ' + N + ' : ' + PascalType + ';');
  1173. end
  1174. else
  1175. begin
  1176. if (ReadFuncType in PropUsesGtkName) and (GtkName <> '') then
  1177. N := GtkName
  1178. else
  1179. N := 'Get' + Name;
  1180. if (ReadFuncType <> pftExistingProc) then
  1181. begin
  1182. if parameters.count > 0 then
  1183. LPriv.Add (' function '+N+'('+I+') : '+PascalType+';')
  1184. else
  1185. LPriv.Add (' function '+N+' : '+PascalType+';');
  1186. end;
  1187. end;
  1188. s := s + N;
  1189. end;
  1190. if (WriteProcType <> pftNotImplemented) then
  1191. begin
  1192. s := s + ' write ';
  1193. if WriteProcType = pftField then
  1194. begin
  1195. if GtkName <> '' then
  1196. N := GtkName
  1197. else
  1198. N := 'F' + Name;
  1199. if (ReadFuncType <> pftField) then
  1200. LPriv.insert (0, ' ' + N + ' : ' + PascalType + ';');
  1201. end
  1202. else
  1203. begin
  1204. if (WriteProcType in PropUsesGtkName) and (WriteGtkName <> '') then
  1205. N := WriteGtkName
  1206. else
  1207. N := 'Set' + Name;
  1208. if (WriteProcType <> pftExistingProc) then
  1209. begin
  1210. if parameters.count > 0 then
  1211. LPriv.Add (' procedure '+N+' ('+I+'; TheValue : '+PascalType+');')
  1212. else
  1213. LPriv.Add (' procedure '+N+' (TheValue : '+PascalType+');');
  1214. end;
  1215. end;
  1216. s := s + N;
  1217. end;
  1218. end;
  1219. TheList.Add (s+';');
  1220. end;
  1221. ptFunction :
  1222. Thelist.Add (' function ' + Name + CalcParameterList(Parameters, plDecl)
  1223. + ' : ' + PascalType+';' + CalcProcTypes(ProcTypes));
  1224. ptProcedure :
  1225. TheList.Add (' procedure ' + Name + CalcParameterList(Parameters, plDecl)
  1226. + ';' + CalcProcTypes(ProcTypes));
  1227. ptSignal :
  1228. begin
  1229. TheList.Add (' function Connect'+Name+' (proc:T'+ObjectsPrefix+PascalType+'Function; data:pointer) : guint;');
  1230. TheList.Add (' function ConnectAfter'+Name+' (proc:T'+ObjectsPrefix+PascalType+'Function; data:pointer) : guint;');
  1231. end;
  1232. ptSignalType :
  1233. begin
  1234. TheList.Add (' function ' + Name + 'Connect (Signal:AnsiString; Proc:T'+ObjectsPrefix+Name+'Function; data:pointer) : guint;');
  1235. TheList.Add (' function ' + Name + 'ConnectAfter (Signal:AnsiString; Proc:T'+ObjectsPrefix+Name+'Function; data:pointer) : guint;');
  1236. end;
  1237. ptConstructor :
  1238. TheList.Add (' constructor ' + Name + CalcParameterList(Parameters, plDecl)
  1239. + ';' + CalcProcTypes(ProcTypes));
  1240. ptDestructor :
  1241. TheList.Add (' destructor ' + Name + CalcParameterList(Parameters, plDecl)
  1242. + ';' + CalcProcTypes(ProcTypes));
  1243. end;
  1244. end;
  1245. { Adding the sections }
  1246. if LPriv.count > 0 then
  1247. begin
  1248. TheUnit.add (' Private');
  1249. TheUnit.AddStrings (Lpriv);
  1250. end;
  1251. if (LProt.count > 0) or CreateObject then
  1252. begin
  1253. TheUnit.add (' Protected');
  1254. if CreateObject then
  1255. TheUnit.add (' procedure CreateGtkObject; override;');
  1256. if LProt.Count >= 0 then
  1257. TheUnit.AddStrings (Lprot);
  1258. end;
  1259. if (GtkFuncName <> '') or (LPublic.count >= 0) then
  1260. begin
  1261. TheUnit.add (' Public');
  1262. if (GtkFuncName <> '') then
  1263. TheUnit.add (' function TheGtkObject : PGtk'+Name+';');
  1264. if LPublic.count >= 0 then
  1265. TheUnit.AddStrings (Lpublic);
  1266. end;
  1267. if LPublish.count > 0 then
  1268. begin
  1269. TheUnit.add (' Publish');
  1270. TheUnit.AddStrings (Lpublish);
  1271. end;
  1272. end;
  1273. TheUnit.Add (' end;');
  1274. TheUnit.add ('');
  1275. DoStepIt;
  1276. end;
  1277. procedure WriteObjectImplementation (Obj : TObjectItem);
  1278. var gn, n, s, start, midden, eind, res : AnsiString;
  1279. r, l, p : integer;
  1280. begin
  1281. with Obj, TheUnit do
  1282. begin
  1283. n := Name;
  1284. gn := GtkFuncName;
  1285. add (' { T'+ObjectsPrefix+N+' }'+CRLF);
  1286. if gn <> '' then
  1287. // Functie voor alle objecten en header
  1288. add ('function T'+ObjectsPrefix+N+'.TheGtkObject : PGtk'+N+';'+CRLF+
  1289. 'begin'+CRLF+
  1290. ' result := P'+GtkPrefix+N+'(FGtkObject);'+CRLF+
  1291. 'end;'+CRLF);
  1292. if CreateObject then
  1293. begin
  1294. eind := CreateParams;
  1295. if eind <> '' then
  1296. eind := ' (' + eind + ')';
  1297. add ('procedure T'+ObjectsPrefix+N+'.CreateGtkObject;'+CRLF+
  1298. 'begin'+CRLF+
  1299. ' FGtkObject := PGtkObject(gtk_'+gn+'_new'+eind+');'+CRLF+
  1300. 'end;'+CRLF);
  1301. end;
  1302. // Declarations toevoegen
  1303. for r := 0 to Props.count-1 do
  1304. with Props[r] do
  1305. if (PropType = ptDeclarations) and (Section in sectPriv) then
  1306. AddStrings (Code);
  1307. // Properties toevoegen
  1308. add ('');
  1309. for r := 0 to props.count-1 do
  1310. with Props[r] do
  1311. begin
  1312. case PropType of
  1313. ptFunction :
  1314. if not (ptAbstract in ProcTypes) then
  1315. begin
  1316. Add ('function T'+ObjectsPrefix + N + '.' + Name +
  1317. CalcParameterList(Parameters, plDecl) +
  1318. ' : ' + PascalType+';' + CalcProcTypes(ProcTypes,true));
  1319. if GtkName = '' then
  1320. AddStrings (Code)
  1321. else
  1322. begin
  1323. s := CalcParameterList (Parameters, plImpl);
  1324. if s <> '' then
  1325. s := ', ' + s;
  1326. Add ('begin' + CRLF +
  1327. ' result := ' + GtkPrefix + '_' + GN + '_' + GtkName +
  1328. ' (TheGtkObject' + s + ');' + CRLF +
  1329. 'end;');
  1330. end;
  1331. add ('');
  1332. end;
  1333. ptHelperFunc :
  1334. begin
  1335. Add ('function ' + Name + CalcParameterList(Parameters, plDecl) +
  1336. ' : ' + PascalType+';'+CalcProcTypes(ProcTypes)+CRLF+Code.Text+CRLF);
  1337. end;
  1338. ptProcedure :
  1339. if not (ptAbstract in ProcTypes) then
  1340. begin
  1341. Add ('procedure T'+ObjectsPrefix + N + '.' + Name+
  1342. CalcParameterList(Parameters,plDecl) + ';' +
  1343. CalcProcTypes(ProcTypes, True));
  1344. if GtkName = '' then
  1345. AddStrings (Code)
  1346. else
  1347. begin
  1348. s := CalcParameterList (Parameters, plImpl);
  1349. if s <> '' then
  1350. s := ', ' + s;
  1351. Add ('begin' + CRLF +
  1352. ' ' + GtkPrefix + '_' + GN + '_' + GtkName +
  1353. ' (TheGtkObject' + s + ');' + CRLF +
  1354. 'end;');
  1355. end;
  1356. add ('');
  1357. end;
  1358. ptHelperProc :
  1359. Add ('procedure ' + Name + CalcParameterList(Parameters, plDecl) +
  1360. ';'+CalcProcTypes(ProcTypes)+CRLF+Code.Text+CRLF);
  1361. ptConstructor :
  1362. Add ('constructor T'+ObjectsPrefix + N + '.' + Name+
  1363. CalcParameterList(Parameters,plDecl) + ';'+CRLF+Code.Text+CRLF);
  1364. ptDestructor :
  1365. Add ('destructor T'+ObjectsPrefix + N + '.' + Name+
  1366. CalcParameterList(Parameters,plDecl) + ';'+CRLF+Code.Text+CRLF);
  1367. ptSignal :
  1368. begin
  1369. start := 'function T'+ObjectsPrefix + N + '.Connect';
  1370. midden := Name + ' (proc:T'+ObjectsPrefix + PascalType + 'Function; data:pointer) : guint;'+CRLF+
  1371. 'begin' + CRLF +
  1372. ' result := ' + PascalType + 'Connect';
  1373. eind := ' (sg' + Name + ', proc, data);' + CRLF +
  1374. 'end;'+CRLF;
  1375. Add (start+midden+eind);
  1376. Add (start+'After'+midden+'After'+eind);
  1377. end;
  1378. ptSignalType :
  1379. begin
  1380. midden := '';
  1381. with parameters do
  1382. begin
  1383. if count > 0 then
  1384. begin
  1385. {if lowercase(Items[0].Name) = 'sender' then
  1386. l := 1
  1387. else
  1388. l := 0;
  1389. p := count - 1;
  1390. if lowercase(Items[p].name) = 'data' then
  1391. dec (p);
  1392. }
  1393. // s = ParameterList for call; midden = parameter for declaration
  1394. //s := DoConvert ('TheWidget',ConvertType(Items[0].PascalType,ToGtk),ToLuk);
  1395. s := 'TheWidget as ' + Items[0].PascalType;
  1396. midden := Items[0].Name+':'+ConvertType(Items[0].PascalType,ToGtk);
  1397. for l := 1 to count-2 do
  1398. begin
  1399. case Items[l].ParamType of
  1400. ptVar : start := 'var ';
  1401. ptconst : start := 'const ';
  1402. else start := '';
  1403. end;
  1404. with Items[l] do
  1405. if Convert then
  1406. begin
  1407. midden := midden+'; '+start+Name+':'+ConvertType(PascalType, ToGtk);
  1408. s := s+', '+DoConvert (Name,ConvertType(PascalType,ToGtk),ToLuk);
  1409. end
  1410. else
  1411. begin
  1412. midden := midden+'; '+start+Name+':'+PascalType;
  1413. s := s+', '+Name;
  1414. end
  1415. end;
  1416. p := count - 1;
  1417. midden := midden+'; '+Items[p].Name+':'+ConvertType(Items[p].PascalType, ToGtk);
  1418. s := s+', TheData';
  1419. end
  1420. else
  1421. begin
  1422. s := '';
  1423. midden := '';
  1424. end;
  1425. end;
  1426. if PascalType = '' then
  1427. begin
  1428. start := 'procedure';
  1429. eind := '';
  1430. res := '';
  1431. end
  1432. else
  1433. begin
  1434. start := 'function';
  1435. eind := 'result := ';
  1436. res := ' : '+PascalType;
  1437. end;
  1438. Add (start+' '+Name+copy(start,1,4)+' ('+midden+')'+res+'; cdecl;'+CRLF+
  1439. 'var p : T'+ObjectsPrefix+Name+'Function;'+CRLF+
  1440. 'begin'+CRLF+
  1441. 'with PSignalData(data)^ do'+CRLF+
  1442. ' begin'+CRLF+
  1443. ' p := T'+ObjectsPrefix+Name+'Function (TheSignalProc);'+CRLF+
  1444. ' '+eind+'p ('+s+')'+CRLF+
  1445. ' end;'+CRLF+
  1446. 'end;'+CRLF);
  1447. midden := ' (signal:AnsiString; proc:T'+ObjectsPrefix+Name+
  1448. 'Function; data:pointer) : guint;'+CRLF+
  1449. 'begin'+CRLF+
  1450. ' result := '+GtkPrefix+'_signal_connect';
  1451. eind:= ' (FGtkObject, pgChar(signal), '+GtkPrefix+'_signal_func(@'+Name+copy(start,1,4)+'), '+
  1452. 'ConvertSignalData(T'+ObjectsPrefix+'SignalFunction(proc), data, true));'+CRLF+
  1453. 'end;'+CRLF;
  1454. start := 'function T'+ObjectsPrefix+N+'.'+Name+'Connect';
  1455. Add (start+midden+eind);
  1456. Add (start+'After'+midden+'_After'+eind);
  1457. end;
  1458. ptProperty :
  1459. begin
  1460. midden := Name;
  1461. if parameters.count > 0 then
  1462. start := ','+CalcParameterList (parameters, plImpl)
  1463. else
  1464. start := '';
  1465. if parameters.count > 0 then
  1466. eind := CalcParameterList (parameters)
  1467. else
  1468. eind := '';
  1469. // Read Function
  1470. if ReadFuncType = pftProc then
  1471. begin
  1472. s := Code.Text;
  1473. if GtkName <> '' then
  1474. midden := GtkName
  1475. else
  1476. midden := 'Get' + midden;
  1477. end
  1478. else if ReadFuncType in [pftGtkFunc, pftObjField, pftObjFunc, pftGtkMacro] then
  1479. begin
  1480. midden := 'Get'+midden;
  1481. case ReadFuncType of
  1482. pftGtkFunc : s := GtkPrefix+'_'+gn+'_get_'+GtkName+'(TheGtkObject'+start+')';
  1483. pftObjField: s := 'TheGtkObject^.'+GtkName;
  1484. pftObjFunc : s := 'gtk.'+GtkName+'(TheGtkObject^'+start+')';
  1485. pftGtkMacro: s := GtkPrefix+'_'+gn+'_'+GtkName+'(TheGtkObject'+start+')';
  1486. end;
  1487. if ReadConvert then
  1488. s := DoConvert (s, PascalType, ToLuk);
  1489. s := 'begin'+CRLF+' result := '+s+';'+CRLF+'end;'+CRLF;
  1490. end
  1491. else
  1492. s := '';
  1493. if s <> '' then
  1494. begin
  1495. if eind = '' then
  1496. Add ('function T'+ObjectsPrefix+N+'.'+midden+' : '+PascalType+';'+CRLF+s)
  1497. else
  1498. Add ('function T'+ObjectsPrefix+N+'.'+midden+' ('+eind+') : '+PascalType+';'+CRLF+s);
  1499. end;
  1500. // Write procedure
  1501. midden := Name;
  1502. if (WriteProcType in [pftGtkFunc,pftObjField,pftObjFunc,pftGtkMacro]) then
  1503. begin
  1504. midden := 'Set' + midden;
  1505. if WriteConvert then
  1506. if WriteProcType in [pftObjField, pftObjFunc] then
  1507. s := DoConvert ('TheValue', PascalType, ToFPGtk)
  1508. else
  1509. s := DoConvert ('TheValue', PascalType, ToGtk)
  1510. else
  1511. s := 'TheValue';
  1512. case WriteProcType of
  1513. pftGtkFunc : s := GtkPrefix+'_'+gn+'_set_'+writeGtkName+'(TheGtkObject'+start+','+s+');';
  1514. pftGtkMacro: s := GtkPrefix+'_'+gn+'_'+writeGtkName+'(TheGtkObject'+start+','+s+');';
  1515. pftObjField: s := 'TheGtkObject^.'+writeGtkName+' := '+s+';';
  1516. pftObjFunc : s := 'gtk.'+'Set_'+WriteGtkName+'(TheGtkObject^'+start+','+s+')';
  1517. end;
  1518. s := 'begin'+CRLF+' '+s+CRLF+'end;'+CRLF;
  1519. end
  1520. else if WriteProcType = pftProc then
  1521. begin
  1522. s := WriteCode.Text;
  1523. if writegtkname <> '' then
  1524. midden := writegtkname
  1525. else
  1526. midden := 'Set' + midden;
  1527. end
  1528. else
  1529. s := '';
  1530. if s <> '' then
  1531. begin
  1532. if eind = '' then
  1533. Add ('procedure T'+ObjectsPrefix+N+'.'+midden+' ('+'TheValue:' + PascalType+');'+CRLF+s)
  1534. else
  1535. Add ('procedure T'+ObjectsPrefix+N+'.'+midden+' ('+eind+'; TheValue:' + PascalType+');'+CRLF+s);
  1536. end;
  1537. end;
  1538. end;
  1539. end;
  1540. end;
  1541. DoStepIt;
  1542. end;
  1543. var r, t : integer;
  1544. Need : boolean;
  1545. UsedSignals : TStringList;
  1546. begin
  1547. LPublic := TStringList.Create;
  1548. LPublish := TStringList.Create;
  1549. LPriv := TStringList.Create;
  1550. LProt := TStringList.Create;
  1551. UsedSignals := TStringList.Create;
  1552. UsedSignals.Sorted := True;
  1553. lowerObjectsPrefix := lowercase (ObjectsPrefix);
  1554. ObjectsPrefixLength := length(lowerObjectsPrefix);
  1555. with TheUnit do
  1556. try
  1557. DoStepItMax (FDefinition.Count * 2 + 4);
  1558. clear;
  1559. capacity := 70 * FDefinition.Count;
  1560. add ('{$mode objfpc}{$h+} {$ifdef win32}{$define gtkwin}{$endif}'+CRLF+
  1561. 'UNIT '+UnitName+';'+CRLF+CRLF+
  1562. '// Generated with GtkWrite by Luk Vandelaer (version '+versionnumber+')'+CRLF+CRLF+
  1563. 'INTERFACE'+CRLF+CRLF+
  1564. 'USES '+UsesList+';');
  1565. // public declarations before classtypes
  1566. for r := 0 to pred(FDefinition.count) do
  1567. with FDefinition[r] do
  1568. begin
  1569. Need := True;
  1570. for t := 0 to Props.count-1 do
  1571. with Props[t] do
  1572. if (PropType = ptDeclarations) and (Section = ispublished) then
  1573. begin
  1574. if Need then
  1575. begin
  1576. add ('{ T'+ObjectsPrefix + FDefinition[r].Name + ' }');
  1577. Need := False;
  1578. end;
  1579. AddStrings (Code);
  1580. end;
  1581. end;
  1582. DoStepIt;
  1583. Add (CRLF+'TYPE'+CRLF);
  1584. //Forward en implementation moeten in dezelfde Type block zitten
  1585. // Forward declarations
  1586. for r := 0 to pred(FDefinition.count) do
  1587. WriteObjectForward (FDefinition[r]);
  1588. // class declaration
  1589. add ('');
  1590. DoStepIt;
  1591. for r := 0 to pred(FDefinition.count) do
  1592. WriteObjectInterface (FDefinition[r]);
  1593. // public declarations after classtypes
  1594. for r := 0 to pred(FDefinition.count) do
  1595. with FDefinition[r] do
  1596. begin
  1597. Need := True;
  1598. for t := 0 to Props.count-1 do
  1599. with Props[t] do
  1600. if (PropType = ptDeclarations) and (Section = ispublic) then
  1601. begin
  1602. if Need then
  1603. begin
  1604. add ('{ T'+ObjectsPrefix + FDefinition[r].Name + ' }');
  1605. Need := False;
  1606. end;
  1607. AddStrings (Code);
  1608. end;
  1609. end;
  1610. // declaration of signal constants
  1611. Add (CRLF+'Const');
  1612. for r := 0 to pred(FDefinition.count) do
  1613. with FDefinition[r] do
  1614. begin
  1615. Need := True;
  1616. for t := 0 to Props.count-1 do
  1617. with Props[t] do
  1618. if (Section <> isPrivate) and
  1619. (PropType = ptsignal) and
  1620. (UsedSignals.indexof (Name) < 0) then
  1621. begin
  1622. if Need then
  1623. begin
  1624. add ('// T'+ObjectsPrefix + FDefinition[r].Name);
  1625. Need := False;
  1626. end;
  1627. Add (' sg' + Name + ' = ''' + lowercase(GtkName)+ ''';');
  1628. UsedSignals.Add (Name);
  1629. end;
  1630. end;
  1631. Add ('');
  1632. // public helper functions en procedures
  1633. for r := 0 to pred(FDefinition.count) do
  1634. with FDefinition[r] do
  1635. begin
  1636. Need := True;
  1637. for t := 0 to Props.count-1 do
  1638. with Props[t] do
  1639. if (Section in sectPublic) then
  1640. if (PropType = ptHelperFunc) then
  1641. begin
  1642. if Need then
  1643. begin
  1644. add ('// T'+ObjectsPrefix + FDefinition[r].Name);
  1645. Need := False;
  1646. end;
  1647. Add ('function ' + Name + CalcParameterList(Parameters, plDecl)
  1648. + ' : ' + PascalType+';' + CalcProcTypes(ProcTypes));
  1649. end
  1650. else if (PropType = ptHelperProc) then
  1651. begin
  1652. if Need then
  1653. begin
  1654. add ('// T'+ObjectsPrefix + FDefinition[r].Name);
  1655. Need := False;
  1656. end;
  1657. Add ('procedure ' + Name + CalcParameterList(Parameters, plDecl)
  1658. + ';' + CalcProcTypes(ProcTypes));
  1659. end;
  1660. end;
  1661. // Start implementation
  1662. add (CRLF+'IMPLEMENTATION'+CRLF);
  1663. // Object implementations
  1664. for r := 0 to pred(FDefinition.count) do
  1665. WriteObjectImplementation (FDefinition[r]);
  1666. // Initializations
  1667. Add ('INITIALIZATION');
  1668. DoStepIt;
  1669. for r := 0 to pred(FDefinition.count) do
  1670. with FDefinition[r] do
  1671. begin
  1672. for t := 0 to Props.count-1 do
  1673. with Props[t] do
  1674. if (PropType = ptInitialization) then
  1675. AddStrings (Code);
  1676. end;
  1677. // Finalizations
  1678. Add (CRLF+'FINALIZATION');
  1679. DoStepIt;
  1680. for r := 0 to pred(FDefinition.count) do
  1681. with FDefinition[r] do
  1682. begin
  1683. for t := 0 to Props.count-1 do
  1684. with Props[t] do
  1685. if (PropType = ptFinalization) then
  1686. AddStrings (Code);
  1687. end;
  1688. add (CRLF+'End.');
  1689. finally
  1690. LPublic.Free;
  1691. LPublish.Free;
  1692. LPriv.Free;
  1693. LProt.Free;
  1694. UsedSignals.Free;
  1695. end;
  1696. end;
  1697. end.