objectdef.pp 58 KB

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