WMProperties.Mod 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447
  1. MODULE WMProperties; (** AUTHOR "TF"; PURPOSE "Properties" *)
  2. IMPORT
  3. WMRectangles, WMGraphics, Strings, Localization, Repositories, WMEvents, Locks, XML, XMLObjects, Streams, Commands, Modules, KernelLog, Models, Types;
  4. TYPE
  5. String = Strings.String;
  6. Property* = OBJECT
  7. VAR
  8. name, info : String;
  9. prototype : Property;
  10. nonDefault : BOOLEAN;
  11. list : PropertyList; (* contains the list, the property is added to *)
  12. timestamp : LONGINT; (* incremented when property state is changed; *)
  13. repository: Repositories.Repository;
  14. object : Repositories.Component;
  15. repositoryName : Strings.String;
  16. componentName : Strings.String;
  17. generator : Strings.String;
  18. componentID : LONGINT;
  19. inLinkUpdate: BOOLEAN;
  20. PROCEDURE &New*(prototype : Property; name, info : String);
  21. BEGIN
  22. SELF.name := name;
  23. SELF.info := info;
  24. SELF.prototype := prototype;
  25. nonDefault := FALSE;
  26. list := NIL;
  27. timestamp := 0;
  28. END New;
  29. PROCEDURE ReplaceLink*(object: Repositories.Component);
  30. BEGIN
  31. IF SELF.object # object THEN
  32. IF (SELF.object # NIL) THEN SELF.object.onChanged.Remove(LinkChanged) END;
  33. SELF.object := object;
  34. IF object # NIL THEN object.onChanged.Add(LinkChanged); LinkChanged(SELF, object) END;
  35. END;
  36. END ReplaceLink;
  37. PROCEDURE LinkChanged(sender, object: ANY);
  38. BEGIN
  39. AcquireWrite;
  40. inLinkUpdate := TRUE;
  41. UpdateProperty;
  42. inLinkUpdate := FALSE;
  43. ReleaseWrite;
  44. END LinkChanged;
  45. PROCEDURE SetLinkAsString*(CONST string : ARRAY OF CHAR);
  46. VAR repositoryName : ARRAY 256 OF CHAR; componentName : ARRAY 128 OF CHAR; componentID : LONGINT;
  47. context : Repositories.Context; res : WORD; object: Repositories.Component;
  48. BEGIN
  49. IF Repositories.IsCommandString(string) THEN
  50. AcquireWrite;
  51. SELF.repositoryName := NIL;
  52. SELF.componentName := NIL;
  53. SELF.componentID := 0;
  54. SELF.generator := Strings.NewString(string);
  55. ReplaceLink(NIL);
  56. NotDefault;
  57. Changed;
  58. ReleaseWrite;
  59. ELSIF Repositories.SplitName(string, repositoryName, componentName, componentID) THEN
  60. AcquireWrite;
  61. IF repositoryName # "" THEN
  62. SELF.repositoryName := Strings.NewString(repositoryName);
  63. ELSE (*ASSERT(repository # NIL);*)
  64. END;
  65. SELF.componentName := Strings.NewString(componentName);
  66. SELF.componentID := componentID;
  67. SELF.generator := NIL;
  68. ReplaceLink(NIL); (* invalidate reference *)
  69. NotDefault;
  70. Changed;
  71. ReleaseWrite;
  72. ELSE
  73. Reset;
  74. END;
  75. END SetLinkAsString;
  76. PROCEDURE GetLinkAsString*(VAR string : ARRAY OF CHAR);
  77. VAR nbrStr : ARRAY 16 OF CHAR;
  78. BEGIN
  79. AcquireRead;
  80. IF (SELF.generator # NIL) THEN
  81. COPY(SELF.generator^, string);
  82. ELSIF (repositoryName # NIL) & (componentName # NIL) THEN
  83. COPY(repositoryName^, string); Strings.Append(string, Repositories.Delimiter);
  84. Strings.Append(string, componentName^); Strings.Append(string, Repositories.Delimiter);
  85. Strings.IntToStr(componentID, nbrStr); Strings.Append(string, nbrStr);
  86. ELSE
  87. string := "";
  88. END;
  89. ReleaseRead;
  90. END GetLinkAsString;
  91. PROCEDURE IsLink(p: ANY): BOOLEAN;
  92. VAR s:Strings.String; xml: XML.Element; en:XMLObjects.Enumerator;
  93. BEGIN
  94. IF (p IS XML.Element) THEN
  95. xml := p(XML.Element);
  96. s := xml.GetName();
  97. IF s # NIL THEN
  98. IF s^ = "Object" THEN
  99. en := xml.GetContents();
  100. p := en.GetNext();
  101. NotDefault;
  102. IF (p # NIL ) & (p IS XML.Chars) THEN
  103. s := p(XML.Chars).GetStr();
  104. IF s # NIL THEN
  105. Strings.Trim(s^, " ");
  106. SetLinkAsString(s^);
  107. object := GetLink();
  108. RETURN TRUE
  109. END
  110. ELSIF (p # NIL) & (p IS XML.Element) THEN
  111. ReplaceLink( Repositories.ComponentFromXML(p(XML.Element)));
  112. object := GetLink();
  113. RETURN TRUE
  114. END
  115. END;
  116. END;
  117. END;
  118. RETURN FALSE
  119. END IsLink;
  120. PROCEDURE WriteLink*(w : Streams.Writer; context: ANY; indent : LONGINT): BOOLEAN;
  121. VAR name : String; id: LONGINT; res: WORD; repository: Repositories.Repository; objectName: String;
  122. BEGIN
  123. IF object # NIL THEN
  124. Indent(w, indent);
  125. (*level := indent+1;*)
  126. w.Char("<"); w.String("Object"); w.Char(">");
  127. IF (context # NIL) & (context IS Repositories.StoreContext) THEN
  128. repository := context(Repositories.StoreContext).repository;
  129. id := 1;
  130. objectName := object.GetName();
  131. IF (objectName=NIL) OR (objectName^="") THEN objectName :=anonymous END;
  132. repository.PutComponent(object, objectName^,id,res);
  133. w.String(":"); (* <-- THIS repository *) w.String(objectName^); w.String(":"); w.Int(id, 0);
  134. ELSE
  135. ToStream(w);
  136. END;
  137. w.String("</"); w.String("Object"); w.Char(">"); w.Ln;
  138. RETURN TRUE
  139. END;
  140. RETURN FALSE;
  141. END WriteLink;
  142. PROCEDURE UpdateModel;
  143. BEGIN
  144. END UpdateModel;
  145. PROCEDURE UpdateProperty;
  146. BEGIN
  147. END UpdateProperty;
  148. PROCEDURE SetLink*(object : Repositories.Component);
  149. BEGIN
  150. AcquireWrite; (* TBD: Store object to repository *)
  151. IF (SELF.object # object) THEN ReplaceLink(object); Changed
  152. ELSIF ~ nonDefault THEN Changed END;
  153. NotDefault;
  154. ReleaseWrite;
  155. END SetLink;
  156. PROCEDURE GetLink*() : Repositories.Component;
  157. VAR object : Repositories.Component; context : Repositories.Context; res : WORD;
  158. BEGIN
  159. AcquireRead;
  160. object := SELF.object;
  161. ReleaseRead;
  162. (* late time generation of object for supporting of loading repositories *)
  163. IF (object = NIL) THEN
  164. IF (generator # NIL) THEN
  165. Repositories.CallCommand(generator^, context, res);
  166. IF (res = Repositories.Ok) & (context.object # NIL) & (context.object IS Repositories.Component) THEN
  167. object := context.object(Repositories.Component);
  168. SetLink(object)
  169. END;
  170. ELSIF (repositoryName # NIL) & (componentName # NIL) THEN
  171. Repositories.GetComponent(repositoryName^, componentName^, componentID, object, res);
  172. SetLink(object);
  173. ELSIF (componentName # NIL) & (repository # NIL) THEN
  174. object := repository.GetComponent(componentName^, componentID);
  175. SetLink(object);
  176. END;
  177. END;
  178. RETURN object
  179. END GetLink;
  180. PROCEDURE SetPrototype*(prototype : Property);
  181. BEGIN
  182. SELF.prototype := prototype;
  183. Stamp;
  184. END SetPrototype;
  185. PROCEDURE HasPrototype*() : BOOLEAN;
  186. BEGIN
  187. RETURN prototype # NIL
  188. END HasPrototype;
  189. (** Meta-data *)
  190. PROCEDURE GetInfo*() : String;
  191. BEGIN
  192. IF info # NIL THEN RETURN info
  193. ELSIF prototype # NIL THEN RETURN prototype.GetInfo()
  194. ELSE RETURN NIL
  195. END
  196. END GetInfo;
  197. PROCEDURE GetName*() : String;
  198. BEGIN
  199. IF name # NIL THEN RETURN name
  200. ELSIF prototype # NIL THEN RETURN prototype.GetName()
  201. ELSE RETURN NIL
  202. END
  203. END GetName;
  204. PROCEDURE Stamp*;
  205. BEGIN (* need protection? *)
  206. INC(timestamp)
  207. END Stamp;
  208. PROCEDURE GetTimestamp*() : LONGINT;
  209. BEGIN
  210. RETURN timestamp;
  211. END GetTimestamp;
  212. PROCEDURE Reset*;
  213. BEGIN
  214. AcquireWrite;
  215. IF nonDefault THEN nonDefault := FALSE; Changed END;
  216. ReleaseWrite
  217. END Reset;
  218. PROCEDURE Changed*; (** PROTECTED *)
  219. BEGIN
  220. IF list # NIL THEN list.Changed(SELF) END;
  221. Stamp;
  222. END Changed;
  223. PROCEDURE AcquireWrite*;
  224. BEGIN
  225. IF list # NIL THEN list.AcquireWrite END
  226. END AcquireWrite;
  227. PROCEDURE ReleaseWrite*;
  228. BEGIN
  229. IF list # NIL THEN list.ReleaseWrite END
  230. END ReleaseWrite;
  231. PROCEDURE AcquireRead*;
  232. BEGIN
  233. IF list # NIL THEN list.AcquireRead END
  234. END AcquireRead;
  235. PROCEDURE ReleaseRead*;
  236. BEGIN
  237. IF list # NIL THEN list.ReleaseRead END
  238. END ReleaseRead;
  239. PROCEDURE NotDefault*; (** PROTECTED *)
  240. BEGIN
  241. IF (nonDefault = FALSE) THEN
  242. nonDefault := TRUE;
  243. Stamp;
  244. END;
  245. END NotDefault;
  246. PROCEDURE GetIsDefault*() : BOOLEAN;
  247. BEGIN
  248. RETURN ~nonDefault
  249. END GetIsDefault;
  250. PROCEDURE FromStream*(r : Streams.Reader); (** ABSTRACT *)
  251. END FromStream;
  252. PROCEDURE ToStream*(w : Streams.Writer); (** ABSTRACT *)
  253. END ToStream;
  254. PROCEDURE FromXML*(xml : XML.Element);
  255. END FromXML;
  256. PROCEDURE ToXML*(VAR element: XML.Element);
  257. VAR name: String;
  258. BEGIN
  259. name := GetName();
  260. NEW(element); IF name # NIL THEN element.SetName(name^); END;
  261. END ToXML;
  262. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  263. END WriteXML;
  264. PROCEDURE Finalize*;
  265. BEGIN
  266. END Finalize;
  267. END Property;
  268. TYPE
  269. BooleanProperty* = OBJECT(Property)
  270. VAR
  271. value : BOOLEAN;
  272. PROCEDURE FromStream*(r : Streams.Reader);
  273. VAR token : ARRAY 5 OF CHAR; v : BOOLEAN;
  274. BEGIN
  275. AcquireWrite;
  276. NotDefault;
  277. r.Token(token); Strings.UpperCase(token); v := token = "TRUE";
  278. IF v # value THEN value := v; Changed END;
  279. ReleaseWrite
  280. END FromStream;
  281. PROCEDURE ToStream*(w : Streams.Writer);
  282. BEGIN
  283. AcquireRead;
  284. IF Get() THEN w.String("true") ELSE w.String("false") END;
  285. ReleaseRead
  286. END ToStream;
  287. PROCEDURE UpdateProperty;
  288. VAR boolean: Types.Boolean; model: Models.Model; res: WORD;
  289. BEGIN
  290. IF GetModel(object, model) THEN
  291. model.GetGeneric(boolean, res);
  292. IF res = 0 THEN Set(boolean.value) END;
  293. END;
  294. END UpdateProperty;
  295. PROCEDURE UpdateModel;
  296. VAR type: Types.Boolean; model: Models.Model; res: WORD;
  297. BEGIN
  298. IF inLinkUpdate THEN RETURN END;
  299. IF GetModel(object, model) THEN
  300. type.value := value;
  301. model.SetGeneric(type, res);
  302. END;
  303. END UpdateModel;
  304. PROCEDURE Get*() : BOOLEAN;
  305. VAR r : BOOLEAN;
  306. BEGIN
  307. AcquireRead;
  308. IF nonDefault OR (prototype = NIL) THEN r := value
  309. ELSE r := prototype(BooleanProperty).Get()
  310. END;
  311. ReleaseRead;
  312. RETURN r
  313. END Get;
  314. PROCEDURE Set*(value : BOOLEAN);
  315. BEGIN
  316. AcquireWrite;
  317. IF value # SELF.value THEN SELF.value := value; Changed;
  318. IF (object # NIL) THEN UpdateModel END;
  319. ELSIF ~ nonDefault THEN Changed END;
  320. NotDefault;
  321. ReleaseWrite;
  322. END Set;
  323. PROCEDURE FromXML*(xml : XML.Element);
  324. VAR en : XMLObjects.Enumerator; p : ANY; s : String;
  325. BEGIN
  326. en := xml.GetContents();
  327. p := en.GetNext();
  328. value := FALSE; NotDefault;
  329. IF IsLink(p) THEN
  330. ELSIF p IS XML.Chars THEN
  331. s := p(XML.Chars).GetStr();
  332. IF s # NIL THEN
  333. Strings.Trim(s^, " "); Strings.LowerCase(s^);
  334. Set(s^ = "true")
  335. END
  336. END;
  337. END FromXML;
  338. PROCEDURE ToXML*(VAR element: XML.Element);
  339. VAR chars: XML.ArrayChars; s: String;
  340. BEGIN
  341. IF (GetName # NIL) & nonDefault THEN
  342. ToXML^(element);
  343. element.SetAttributeValue("loader","WMProperties.NewBoolean");
  344. NEW(chars); element.AddContent(chars);
  345. IF Get() THEN chars.SetStr("true") ELSE chars.SetStr("false") END;
  346. s := GetName();
  347. END;
  348. END ToXML;
  349. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  350. VAR name : String;
  351. BEGIN
  352. name := GetName();
  353. IF name = NIL THEN KernelLog.String("Nameless boolean property encountered. Ignored"); KernelLog.Ln; RETURN END;
  354. IF nonDefault THEN
  355. Indent(w, indent);
  356. w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewBoolean"'); w.Char(">");
  357. IF ~WriteLink(w,context,indent) THEN
  358. IF value THEN w.String("true") ELSE w.String("false") END;
  359. END;
  360. w.String("</"); w.String(name^); w.Char(">"); w.Ln;
  361. END
  362. END WriteXML;
  363. END BooleanProperty;
  364. TYPE
  365. SetProperty* = OBJECT(Property)
  366. VAR
  367. value : SET;
  368. PROCEDURE IntToSet(h:LONGINT):SET;
  369. VAR i:LONGINT; set:SET;
  370. BEGIN
  371. i:=0;
  372. WHILE h#0 DO
  373. IF h MOD 2=1 THEN INCL(set,i) END;
  374. h:=h DIV 2;
  375. INC(i);
  376. END;
  377. RETURN set;
  378. END IntToSet;
  379. PROCEDURE SetToInt(set:SET):HUGEINT;
  380. VAR i:LONGINT; int:HUGEINT; s: String;
  381. BEGIN
  382. NEW(s, 18);
  383. FOR i:=31 TO 0 BY -1 DO
  384. int:=int * 2;
  385. IF i IN set THEN INC(int) END;
  386. END;
  387. RETURN int
  388. END SetToInt;
  389. PROCEDURE FromStream*(r : Streams.Reader);
  390. VAR token : ARRAY 10 OF CHAR; v : SET; i:LONGINT; res: WORD;
  391. BEGIN
  392. AcquireWrite;
  393. NotDefault;
  394. r.String(token); Strings.HexStrToInt(token,i,res);
  395. IF res=Strings.Ok THEN
  396. v:=IntToSet(i);
  397. IF v # value THEN value := v; Changed END;
  398. END;
  399. ReleaseWrite
  400. END FromStream;
  401. (*! to discuss: should a SET be written explicitely ? readability vs overhead*)
  402. PROCEDURE ToStream*(w : Streams.Writer);
  403. VAR s:ARRAY 10 OF CHAR;
  404. BEGIN
  405. AcquireRead;
  406. Strings.IntToHexStr(SetToInt(Get()),8,s);
  407. Strings.AppendChar(s,"H");
  408. w.String(s);
  409. ReleaseRead
  410. END ToStream;
  411. PROCEDURE UpdateProperty;
  412. VAR boolean: Types.Set; model: Models.Model; res: WORD;
  413. BEGIN
  414. IF GetModel(object, model) THEN
  415. model.GetGeneric(boolean, res);
  416. IF res = 0 THEN Set(boolean.value) END;
  417. END;
  418. END UpdateProperty;
  419. PROCEDURE UpdateModel;
  420. VAR type: Types.Set; model: Models.Model; res: WORD;
  421. BEGIN
  422. IF inLinkUpdate THEN RETURN END;
  423. IF GetModel(object, model) THEN
  424. type.value := value;
  425. model.SetGeneric(type, res);
  426. END;
  427. END UpdateModel;
  428. PROCEDURE Get*() : SET;
  429. VAR r : SET;
  430. BEGIN
  431. AcquireRead;
  432. IF nonDefault OR (prototype = NIL) THEN r := value
  433. ELSE r := prototype(SetProperty).Get()
  434. END;
  435. ReleaseRead;
  436. RETURN r
  437. END Get;
  438. PROCEDURE Set*(value : SET);
  439. BEGIN
  440. AcquireWrite;
  441. IF value # SELF.value THEN
  442. SELF.value := value;
  443. IF (object # NIL) THEN UpdateModel END;
  444. Changed
  445. ELSIF ~ nonDefault THEN Changed END;
  446. NotDefault;
  447. ReleaseWrite;
  448. END Set;
  449. (*! to discuss: should a SET be written explicitely - readability at cost of overhead*)
  450. PROCEDURE FromXML*(xml : XML.Element);
  451. VAR en : XMLObjects.Enumerator; p : ANY; s : String; i:LONGINT;
  452. BEGIN
  453. en := xml.GetContents();
  454. p := en.GetNext();
  455. NotDefault;
  456. IF IsLink(p) THEN
  457. ELSIF p IS XML.Chars THEN
  458. s := p(XML.Chars).GetStr();
  459. IF s # NIL THEN
  460. Strings.Trim(s^, " ");
  461. Strings.StrToInt(s^,i);
  462. Set(IntToSet(i))
  463. END
  464. END
  465. END FromXML;
  466. PROCEDURE ToXML*(VAR element: XML.Element);
  467. VAR chars: XML.ArrayChars;s: ARRAY 10 OF CHAR;
  468. BEGIN
  469. IF (GetName # NIL) & nonDefault THEN
  470. ToXML^(element);
  471. element.SetAttributeValue("loader","WMProperties.NewSet");
  472. NEW(chars); element.AddContent(chars);
  473. Strings.IntToHexStr(SetToInt(value),8,s); Strings.AppendChar(s,"H");
  474. chars.SetStr(s);
  475. END;
  476. END ToXML;
  477. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  478. VAR name : String; s: ARRAY 10 OF CHAR;
  479. BEGIN
  480. name := GetName();
  481. IF name = NIL THEN KernelLog.String("Nameless boolean property encountered. Ignored"); KernelLog.Ln; RETURN END;
  482. IF nonDefault THEN
  483. Indent(w, indent);
  484. w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewSet"'); w.Char(">");
  485. IF ~WriteLink(w,context,indent) THEN
  486. Strings.IntToHexStr(SetToInt(value),8,s); Strings.AppendChar(s,"H");
  487. w.String(s);
  488. END;
  489. w.String("</"); w.String(name^); w.Char(">"); w.Ln;
  490. END
  491. END WriteXML;
  492. END SetProperty;
  493. TYPE
  494. (** Accessor property to an integer value. The range of possible values can be restricted. *)
  495. Int32Property* = OBJECT(Property)
  496. VAR
  497. value : LONGINT;
  498. min, max : LONGINT;
  499. bounded : BOOLEAN;
  500. PROCEDURE UpdateProperty;
  501. VAR integer: Types.Integer; model: Models.Model; res: WORD;
  502. BEGIN
  503. IF GetModel(object, model) THEN
  504. model.GetGeneric(integer, res);
  505. IF res = 0 THEN Set(integer.value) END;
  506. END;
  507. END UpdateProperty;
  508. PROCEDURE UpdateModel;
  509. VAR type: Types.Integer; model: Models.Model; res: WORD;
  510. BEGIN
  511. IF inLinkUpdate THEN RETURN END;
  512. IF GetModel(object, model) THEN
  513. type.value := value;
  514. model.SetGeneric(type, res);
  515. END;
  516. END UpdateModel;
  517. (** Confines the possible input values between min and max. Implicitly activates the bounds check. If the current value
  518. lies outside the bounds, it is truncated to the nearest and a change notification is sent after the end of the transaction. *)
  519. PROCEDURE SetBounds*(min, max : LONGINT);
  520. BEGIN
  521. AcquireWrite;
  522. SELF.min := min; SELF.max := max; bounded := TRUE;
  523. Stamp;
  524. Set(value);
  525. ReleaseWrite
  526. END SetBounds;
  527. PROCEDURE GetBounds*(VAR min, max : LONGINT);
  528. BEGIN
  529. AcquireRead;
  530. min := SELF.min; max := SELF.max;
  531. ReleaseRead;
  532. END GetBounds;
  533. (** enables or disables the bounds of the value. If enabled, a change notification is sent if the current value had to be
  534. changed to lie within the bounds *)
  535. PROCEDURE SetIsBounded*(isBounded : BOOLEAN);
  536. BEGIN
  537. AcquireWrite;
  538. IF isBounded # bounded THEN
  539. bounded := isBounded;
  540. Stamp;
  541. Set(value);
  542. END;
  543. ReleaseWrite
  544. END SetIsBounded;
  545. PROCEDURE GetIsBounded*(VAR isBounded : BOOLEAN);
  546. BEGIN
  547. AcquireRead;
  548. isBounded := bounded;
  549. ReleaseRead;
  550. END GetIsBounded;
  551. PROCEDURE Validate(v : LONGINT) : LONGINT;
  552. BEGIN
  553. IF bounded THEN RETURN MAX(min, MIN(max, v))
  554. ELSE RETURN v
  555. END
  556. END Validate;
  557. PROCEDURE FromStream*(r : Streams.Reader);
  558. VAR v : LONGINT;
  559. BEGIN
  560. AcquireWrite;
  561. r.Int(v, TRUE);
  562. Set(v);
  563. ReleaseWrite
  564. END FromStream;
  565. PROCEDURE ToStream*(w : Streams.Writer);
  566. BEGIN
  567. AcquireRead;
  568. w.Int(value, 0);
  569. ReleaseRead
  570. END ToStream;
  571. PROCEDURE Get*() : LONGINT;
  572. VAR r : LONGINT;
  573. BEGIN
  574. AcquireRead;
  575. IF nonDefault OR (prototype = NIL) THEN r := value
  576. ELSE r := prototype(Int32Property).Get()
  577. END;
  578. ReleaseRead;
  579. RETURN r
  580. END Get;
  581. (* set without updates -- use only when you definitely want to avoid updates *)
  582. PROCEDURE SetPassive*(value: LONGINT);
  583. VAR v: LONGINT;
  584. BEGIN
  585. v := Validate(value);
  586. AcquireWrite;
  587. SELF.value := v;
  588. NotDefault;
  589. ReleaseWrite
  590. END SetPassive;
  591. PROCEDURE Set*(value : LONGINT);
  592. VAR v: LONGINT;
  593. BEGIN
  594. v := Validate(value);
  595. AcquireWrite;
  596. IF v # SELF.value THEN
  597. SELF.value := v;
  598. Changed;
  599. IF object # NIL THEN UpdateModel END;
  600. ELSIF ~nonDefault THEN
  601. Changed;
  602. END;
  603. NotDefault;
  604. ReleaseWrite
  605. END Set;
  606. PROCEDURE FromXML*(xml : XML.Element);
  607. VAR
  608. en : XMLObjects.Enumerator;
  609. p : ANY;
  610. s, mins, maxs : String;
  611. BEGIN
  612. AcquireWrite; NotDefault;
  613. mins := xml.GetAttributeValue("min");
  614. maxs := xml.GetAttributeValue("max");
  615. IF mins # NIL THEN Strings.StrToInt(mins^, min) ELSE min := MIN(LONGINT) END;
  616. IF maxs # NIL THEN Strings.StrToInt(maxs^, max) ELSE max := MAX(LONGINT) END;
  617. bounded := (mins # NIL) OR (maxs # NIL);
  618. en := xml.GetContents();
  619. IF en.HasMoreElements() THEN
  620. p := en.GetNext();
  621. IF IsLink(p) THEN
  622. ELSIF p IS XML.Chars THEN
  623. s := p(XML.Chars).GetStr();
  624. IF s # NIL THEN Strings.StrToInt(s^, value); Set(value) END
  625. END
  626. END;
  627. Stamp;
  628. ReleaseWrite
  629. END FromXML;
  630. PROCEDURE ToXML*(VAR element: XML.Element);
  631. VAR chars: XML.ArrayChars;s: ARRAY 20 OF CHAR;
  632. BEGIN
  633. IF (GetName # NIL) & nonDefault THEN
  634. ToXML^(element);
  635. element.SetAttributeValue("loader","WMProperties.NewInt32");
  636. element.AddContent(NewIntChars(value));
  637. END;
  638. END ToXML;
  639. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  640. VAR name : String;
  641. BEGIN
  642. name := GetName();
  643. IF name = NIL THEN KernelLog.String("Nameless Int32 property encountered. Ignored"); KernelLog.Ln; RETURN END;
  644. IF nonDefault THEN
  645. Indent(w, indent);
  646. w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewInt32"'); w.Char(">");
  647. IF ~WriteLink(w,context,indent) THEN
  648. w.Int(value, 0);
  649. END;
  650. w.String("</"); w.String(name^); w.Char(">"); w.Ln
  651. END
  652. END WriteXML;
  653. END Int32Property;
  654. TYPE
  655. (** Accessor property to an real value. The range of possible values can be restricted. *)
  656. RealProperty* = OBJECT(Property)
  657. VAR
  658. value : LONGREAL;
  659. min, max : LONGREAL;
  660. bounded : BOOLEAN;
  661. (** Confines the possible input values between min and max. Implicitly activates the bounds check. If the current value
  662. lies outside the bounds, it is truncated to the nearest and a change notification is sent after the end of the transaction. *)
  663. PROCEDURE SetBounds*(min, max : LONGREAL);
  664. BEGIN
  665. AcquireWrite;
  666. SELF.min := min; SELF.max := max; bounded := TRUE;
  667. Stamp;
  668. Set(value);
  669. ReleaseWrite
  670. END SetBounds;
  671. PROCEDURE GetBounds*(VAR min, max : LONGREAL);
  672. BEGIN
  673. AcquireRead;
  674. min := SELF.min; max := SELF.max;
  675. ReleaseRead;
  676. END GetBounds;
  677. (** enables or disables the bounds of the value. If enabled, a change notification is sent if the current value had to be
  678. changed to lie within the bounds *)
  679. PROCEDURE SetIsBounded*(isBounded : BOOLEAN);
  680. BEGIN
  681. AcquireWrite;
  682. IF isBounded # bounded THEN
  683. bounded := isBounded;
  684. Stamp;
  685. Set(value);
  686. END;
  687. ReleaseWrite
  688. END SetIsBounded;
  689. PROCEDURE GetIsBounded*(VAR isBounded : BOOLEAN);
  690. BEGIN
  691. AcquireRead;
  692. isBounded := bounded;
  693. ReleaseRead;
  694. END GetIsBounded;
  695. PROCEDURE Validate(v : LONGREAL) : LONGREAL;
  696. VAR result : LONGREAL;
  697. BEGIN
  698. result := v;
  699. IF bounded THEN
  700. IF (result < min) THEN result := min; ELSIF (result > max) THEN result := max; END;
  701. END;
  702. RETURN result;
  703. END Validate;
  704. PROCEDURE FromStream*(r : Streams.Reader);
  705. VAR temp : ARRAY 64 OF CHAR; value : LONGREAL;
  706. BEGIN
  707. r.String(temp);
  708. value := 0.0;
  709. Strings.StrToFloat(temp, value);
  710. Set(value);
  711. END FromStream;
  712. PROCEDURE ToStream*(w : Streams.Writer);
  713. BEGIN
  714. AcquireRead;
  715. w.Float(value, 24);
  716. ReleaseRead
  717. END ToStream;
  718. PROCEDURE UpdateProperty;
  719. VAR longreal: Types.Longreal; model: Models.Model; res: WORD; silent: BOOLEAN;
  720. BEGIN
  721. IF GetModel(object, model) THEN
  722. model.GetGeneric(longreal, res);
  723. IF res = 0 THEN Set(longreal.value) END;
  724. END;
  725. END UpdateProperty;
  726. PROCEDURE UpdateModel;
  727. VAR type: Types.Longreal; model: Models.Model; res: WORD;
  728. BEGIN
  729. IF inLinkUpdate THEN RETURN END;
  730. IF GetModel(object, model) THEN
  731. type.value := value;
  732. model.SetGeneric(type, res);
  733. END;
  734. END UpdateModel;
  735. PROCEDURE Get*() : LONGREAL;
  736. VAR r : LONGREAL;
  737. BEGIN
  738. AcquireRead;
  739. IF nonDefault OR (prototype = NIL) THEN r := value;
  740. ELSE r := prototype(RealProperty).Get();
  741. END;
  742. ReleaseRead;
  743. RETURN r
  744. END Get;
  745. PROCEDURE SetPassive*(value: LONGREAL);
  746. VAR v: LONGREAL;
  747. BEGIN
  748. v := Validate(value);
  749. AcquireWrite;
  750. SELF.value := v;
  751. NotDefault;
  752. ReleaseWrite
  753. END SetPassive;
  754. PROCEDURE Set*(value : LONGREAL);
  755. VAR v: LONGREAL;
  756. BEGIN
  757. v := Validate(value);
  758. AcquireWrite;
  759. IF v # SELF.value THEN
  760. SELF.value := v;
  761. Changed;
  762. IF object # NIL THEN UpdateModel END;
  763. ELSIF ~nonDefault THEN
  764. Changed;
  765. END;
  766. NotDefault;
  767. ReleaseWrite
  768. END Set;
  769. PROCEDURE FromXML*(xml : XML.Element);
  770. VAR
  771. en : XMLObjects.Enumerator;
  772. p : ANY;
  773. s, mins, maxs : String;
  774. BEGIN
  775. AcquireWrite; NotDefault;
  776. mins := xml.GetAttributeValue("min");
  777. maxs := xml.GetAttributeValue("max");
  778. IF mins # NIL THEN Strings.StrToFloat(mins^, min) ELSE min := MIN(LONGREAL) END;
  779. IF maxs # NIL THEN Strings.StrToFloat(maxs^, max) ELSE max := MAX(LONGREAL) END;
  780. bounded := (mins # NIL) OR (maxs # NIL);
  781. en := xml.GetContents();
  782. IF en.HasMoreElements() THEN
  783. p := en.GetNext();
  784. IF IsLink(p) THEN
  785. ELSIF p IS XML.Chars THEN
  786. s := p(XML.Chars).GetStr();
  787. IF s # NIL THEN Strings.StrToFloat(s^, value); Set(value) END
  788. END
  789. END;
  790. Stamp;
  791. ReleaseWrite
  792. END FromXML;
  793. PROCEDURE ToXML*(VAR element: XML.Element);
  794. VAR chars: XML.ArrayChars;s: ARRAY 20 OF CHAR; w: Streams.StringWriter;
  795. BEGIN
  796. IF (GetName # NIL) & nonDefault THEN
  797. ToXML^(element);
  798. element.SetAttributeValue("loader","WMProperties.NewReal");
  799. NEW(chars); element.AddContent(chars);
  800. NEW(w,30); w.Float(value,24); w.Get(s);
  801. chars.SetStr(s);
  802. END;
  803. END ToXML;
  804. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  805. VAR name : String;
  806. BEGIN
  807. name := GetName();
  808. IF name = NIL THEN KernelLog.String("Nameless Real property encountered. Ignored"); KernelLog.Ln; RETURN END;
  809. IF nonDefault THEN
  810. Indent(w, indent);
  811. w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewReal"'); w.Char(">");
  812. IF ~WriteLink(w,context,indent) THEN
  813. w.Float(value, 24);
  814. END;
  815. w.String("</"); w.String(name^); w.Char(">"); w.Ln
  816. END
  817. END WriteXML;
  818. END RealProperty;
  819. TYPE
  820. StringProperty* = OBJECT(Property)
  821. VAR
  822. value, word : String;
  823. dictionary : Repositories.Dictionary;
  824. languages : Localization.Languages;
  825. translate : BOOLEAN;
  826. PROCEDURE &New*(prototype : Property; name, info : String);
  827. BEGIN
  828. New^(prototype, name, info);
  829. value := NIL; word := NIL;
  830. dictionary := NIL;
  831. languages := Localization.GetLanguagePreferences();
  832. translate := TRUE;
  833. END New;
  834. PROCEDURE SetTranslate*(translate : BOOLEAN);
  835. BEGIN
  836. AcquireWrite;
  837. IF (SELF.translate # translate) THEN
  838. SELF.translate := translate;
  839. IF ~translate THEN
  840. dictionary := NIL; word := NIL;
  841. ELSE
  842. Translate;
  843. END;
  844. NotDefault;
  845. Changed;
  846. END;
  847. ReleaseWrite;
  848. END SetTranslate;
  849. PROCEDURE Translate;
  850. VAR res : WORD; temp : Strings.String;
  851. BEGIN (* caller holds lock *)
  852. IF translate & (SELF.value # NIL) THEN
  853. Repositories.GetTranslationInfo(SELF.value^, dictionary, word, res);
  854. IF (dictionary # NIL) & (word # NIL) THEN
  855. temp := dictionary.Translate(word, languages);
  856. IF (temp # word) THEN
  857. value := temp;
  858. END;
  859. END;
  860. END;
  861. END Translate;
  862. PROCEDURE SetLanguage*(languages : Localization.Languages);
  863. BEGIN
  864. AcquireWrite;
  865. SELF.languages := languages;
  866. IF (dictionary # NIL) & (word # NIL) THEN
  867. value := dictionary.Translate(word, languages);
  868. NotDefault;
  869. Changed;
  870. END;
  871. ReleaseWrite;
  872. END SetLanguage;
  873. PROCEDURE FromStream*(r : Streams.Reader);
  874. VAR buffer : ARRAY 1024 OF CHAR; res : WORD;
  875. BEGIN
  876. AcquireWrite;
  877. XML.UTF8FromStream(buffer, r, res);
  878. value := Strings.NewString(buffer); Translate; NotDefault; Changed;
  879. ReleaseWrite
  880. END FromStream;
  881. PROCEDURE ToStream*(w : Streams.Writer);
  882. BEGIN
  883. AcquireRead;
  884. IF (dictionary # NIL) & (word # NIL) THEN
  885. w.String("::"); w.String(dictionary.fullname^); w.String(":"); w.String(word^);
  886. ELSIF value # NIL THEN
  887. w.String(value^);
  888. END;
  889. ReleaseRead
  890. END ToStream;
  891. PROCEDURE Get*() : String;
  892. VAR r : String;
  893. BEGIN
  894. AcquireRead;
  895. IF nonDefault OR (prototype = NIL) THEN r := value
  896. ELSE r := prototype(StringProperty).Get()
  897. END;
  898. ReleaseRead;
  899. RETURN r
  900. END Get;
  901. PROCEDURE UpdateModel;
  902. VAR type: Types.String; model: Models.Model; res: WORD;
  903. BEGIN
  904. IF inLinkUpdate THEN RETURN END;
  905. IF GetModel(object, model) THEN
  906. type.value := value;
  907. model.SetGeneric(type, res);
  908. END;
  909. END UpdateModel;
  910. PROCEDURE SetPassive*(value : String);
  911. BEGIN
  912. AcquireWrite;
  913. IF (value = SELF.value) (* reset with self must lead to update *) OR (value = NIL) OR (SELF.value = NIL) OR (value^ # SELF.value^) THEN
  914. SELF.value := value; Translate;
  915. END;
  916. NotDefault;
  917. ReleaseWrite
  918. END SetPassive;
  919. PROCEDURE Set*(value : String);
  920. BEGIN
  921. AcquireWrite;
  922. IF (value = SELF.value) (* reset with self must lead to update *) OR (value = NIL) OR (SELF.value = NIL) OR (value^ # SELF.value^) THEN
  923. SELF.value := value; Translate;Changed;
  924. IF (object # NIL) THEN UpdateModel END;
  925. ELSIF ~nonDefault THEN
  926. Changed
  927. END;
  928. NotDefault;
  929. ReleaseWrite
  930. END Set;
  931. PROCEDURE UpdateProperty;
  932. VAR type: Types.String; model: Models.Model; res: WORD;
  933. BEGIN
  934. IF GetModel(object, model) THEN
  935. type.value := value; (* pass pointer to string *)
  936. model.GetGeneric(type, res);
  937. IF res = 0 THEN Set(type.value) END;
  938. END;
  939. END UpdateProperty;
  940. PROCEDURE GetAOC*(VAR value : ARRAY OF CHAR);
  941. BEGIN
  942. value := "";
  943. AcquireRead;
  944. IF (SELF.value # NIL) THEN
  945. COPY(SELF.value^, value);
  946. END;
  947. ReleaseRead;
  948. END GetAOC;
  949. PROCEDURE SetAOC*(CONST value : ARRAY OF CHAR);
  950. BEGIN
  951. AcquireWrite;
  952. Strings.SetAOC(value, SELF.value);
  953. Set(SELF.value);
  954. ReleaseWrite;
  955. END SetAOC;
  956. PROCEDURE FromXML*(xml : XML.Element);
  957. VAR en : XMLObjects.Enumerator; p : ANY;
  958. BEGIN
  959. en := xml.GetContents();
  960. p := en.GetNext();
  961. IF p # NIL THEN
  962. IF IsLink(p) THEN
  963. ELSIF p IS XML.Chars THEN
  964. Set(p(XML.Chars).GetStr())
  965. END
  966. ELSE
  967. Set(NIL)
  968. END
  969. END FromXML;
  970. PROCEDURE ToXML*(VAR element: XML.Element);
  971. VAR chars: XML.ArrayChars;s: String; w: Streams.StringWriter; res: WORD; len: LONGINT;
  972. BEGIN
  973. IF (GetName # NIL) & nonDefault THEN
  974. ToXML^(element);
  975. element.SetAttributeValue("loader","WMProperties.NewString");
  976. IF (value # NIL) OR ((dictionary # NIL) & (word # NIL)) THEN
  977. NEW(chars); element.AddContent(chars);
  978. len := 64;
  979. IF (value # NIL) THEN INC(len, LEN(value^)) END;
  980. NEW(w, len);
  981. IF (dictionary # NIL) & (word # NIL) THEN
  982. w.String("::");
  983. XML.UTF8ToStream(dictionary.fullname^, w, res);
  984. IF (res = XML.Ok) THEN
  985. w.String(":");
  986. XML.UTF8ToStream(word^, w, res);
  987. END;
  988. ELSE
  989. XML.UTF8ToStream(value^, w, res);
  990. END;
  991. NEW(s, w.Pos()+1); w.Get(s^);
  992. chars.SetStr(s^);
  993. END;
  994. END;
  995. END ToXML;
  996. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  997. VAR name : String; res : WORD;
  998. BEGIN
  999. name := GetName();
  1000. IF name = NIL THEN KernelLog.String("WMProperties: Nameless string property encountered. Ignored "); KernelLog.Ln; RETURN END;
  1001. IF nonDefault THEN
  1002. IF (value # NIL) OR ((dictionary # NIL) & (word # NIL)) THEN
  1003. Indent(w, indent);
  1004. w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewString"'); w.Char(">");
  1005. IF ~WriteLink(w,context,indent) THEN
  1006. IF (dictionary # NIL) & (word # NIL) THEN
  1007. w.String("::");
  1008. XML.UTF8ToStream(dictionary.fullname^, w, res);
  1009. IF (res = XML.Ok) THEN
  1010. w.String(":");
  1011. XML.UTF8ToStream(word^, w, res);
  1012. END;
  1013. ELSE
  1014. XML.UTF8ToStream(value^, w, res);
  1015. END;
  1016. END;
  1017. w.String("</"); w.String(name^); w.Char(">"); w.Ln;
  1018. IF (res # XML.Ok) THEN
  1019. KernelLog.String("WMProperties.StringProperty.WriteXML: Warning!"); KernelLog.Ln;
  1020. END;
  1021. END;
  1022. END
  1023. END WriteXML;
  1024. END StringProperty;
  1025. TYPE
  1026. ColorProperty* = OBJECT(Property)
  1027. VAR
  1028. value : WMGraphics.Color;
  1029. (* TODO: read hex from CCG FontConverter *)
  1030. PROCEDURE FromStream*(r : Streams.Reader);
  1031. VAR v : LONGINT;
  1032. BEGIN
  1033. AcquireWrite;
  1034. r.Int(v, TRUE); NotDefault;
  1035. IF v # value THEN value := v; Changed END;
  1036. ReleaseWrite
  1037. END FromStream;
  1038. PROCEDURE ToStream*(w : Streams.Writer);
  1039. BEGIN
  1040. AcquireRead;
  1041. w.Hex(value, -8);
  1042. ReleaseRead
  1043. END ToStream;
  1044. PROCEDURE UpdateProperty;
  1045. VAR boolean: Types.Integer; model: Models.Model; res: WORD;
  1046. BEGIN
  1047. IF GetModel(object, model) THEN
  1048. model.GetGeneric(boolean, res);
  1049. IF res = 0 THEN Set(boolean.value) END;
  1050. END;
  1051. END UpdateProperty;
  1052. PROCEDURE UpdateModel;
  1053. VAR type: Types.Integer; model: Models.Model; res: WORD;
  1054. BEGIN
  1055. IF inLinkUpdate THEN RETURN END;
  1056. IF GetModel(object, model) THEN
  1057. type.value := value;
  1058. model.SetGeneric(type, res);
  1059. END;
  1060. END UpdateModel;
  1061. PROCEDURE Get*() : WMGraphics.Color;
  1062. VAR r : WMGraphics.Color;
  1063. BEGIN
  1064. AcquireRead;
  1065. IF nonDefault OR (prototype = NIL) THEN r := value
  1066. ELSE r := prototype(ColorProperty).Get()
  1067. END;
  1068. ReleaseRead;
  1069. RETURN r
  1070. END Get;
  1071. PROCEDURE Set*(value : HUGEINT);
  1072. BEGIN
  1073. AcquireWrite;
  1074. IF SHORT(value) # SELF.value THEN
  1075. SELF.value := SHORT(value); Changed;
  1076. IF (object # NIL) THEN UpdateModel END;
  1077. ELSIF ~nonDefault THEN Changed
  1078. END;
  1079. NotDefault;
  1080. ReleaseWrite
  1081. END Set;
  1082. PROCEDURE FromXML*(xml : XML.Element);
  1083. VAR
  1084. en : XMLObjects.Enumerator;
  1085. p : ANY;
  1086. s : String; res : WORD;
  1087. BEGIN
  1088. AcquireWrite;
  1089. en := xml.GetContents();
  1090. IF en.HasMoreElements() THEN
  1091. p := en.GetNext();
  1092. IF IsLink(p) THEN
  1093. ELSIF p IS XML.Chars THEN
  1094. s := p(XML.Chars).GetStr();
  1095. IF s # NIL THEN Strings.HexStrToInt(s^, value, res) END; NotDefault
  1096. END
  1097. END;
  1098. Stamp;
  1099. ReleaseWrite
  1100. END FromXML;
  1101. PROCEDURE ToXML*(VAR element: XML.Element);
  1102. VAR chars: XML.ArrayChars;s: String; w: Streams.StringWriter; res: WORD;
  1103. BEGIN
  1104. IF (GetName # NIL) & nonDefault THEN
  1105. ToXML^(element);
  1106. element.SetAttributeValue("loader","WMProperties.NewColor");
  1107. NEW(chars); element.AddContent(chars);
  1108. NEW(w,10 );
  1109. w.Hex(value, -8);
  1110. NEW(s, w.Pos()+1); w.Get(s^);
  1111. chars.SetStr(s^);
  1112. END;
  1113. END ToXML;
  1114. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  1115. VAR name : String;
  1116. BEGIN
  1117. name := GetName();
  1118. IF name = NIL THEN KernelLog.String("Nameless color property encountered. Ignored"); KernelLog.Ln; RETURN END;
  1119. IF nonDefault THEN
  1120. Indent(w, indent);
  1121. w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewColor"'); w.Char(">");
  1122. IF ~WriteLink(w,context,indent) THEN
  1123. w.Hex(value, -8);
  1124. END;
  1125. w.String("</"); w.String(name^); w.Char(">"); w.Ln;
  1126. END
  1127. END WriteXML;
  1128. END ColorProperty;
  1129. TYPE
  1130. FontProperty* = OBJECT(Property)
  1131. VAR
  1132. font : WMGraphics.Font; (* { font # NIL } *)
  1133. PROCEDURE &New*(prototype : Property; name, info : String);
  1134. BEGIN
  1135. New^(prototype, name, info);
  1136. font := WMGraphics.GetDefaultFont();
  1137. END New;
  1138. PROCEDURE FromStream*(r : Streams.Reader);
  1139. VAR font : WMGraphics.Font; name, temp : ARRAY 32 OF CHAR; size : LONGINT; style : SET;
  1140. BEGIN
  1141. AcquireWrite;
  1142. NotDefault;
  1143. name := ""; size := 0; style := {};
  1144. IF r.GetString(name) & r.GetInteger(size, FALSE) & r.GetString(temp) THEN
  1145. Strings.StrToSet(temp, style);
  1146. IF size < 6 THEN size := 6 END;
  1147. font := WMGraphics.GetFont(name, size, style);
  1148. IF (font = NIL) THEN font := WMGraphics.GetDefaultFont(); END;
  1149. IF (SELF.font # font) THEN SELF.font := font; Changed END;
  1150. END;
  1151. ReleaseWrite
  1152. END FromStream;
  1153. PROCEDURE ToStream*(w : Streams.Writer);
  1154. VAR font : WMGraphics.Font; temp : ARRAY 32 OF CHAR;
  1155. BEGIN
  1156. AcquireRead;
  1157. font := Get();
  1158. w.String(font.name); w.Char(" "); w.Int(font.size, 0); w.Char(" ");
  1159. Strings.SetToStr(font.style, temp); w.String(temp);
  1160. ReleaseRead
  1161. END ToStream;
  1162. PROCEDURE Get*() : WMGraphics.Font;
  1163. VAR font : WMGraphics.Font;
  1164. BEGIN
  1165. AcquireRead;
  1166. IF nonDefault OR (prototype = NIL) THEN font := SELF.font;
  1167. ELSE font := prototype(FontProperty).Get()
  1168. END;
  1169. ReleaseRead;
  1170. IF (font = NIL) THEN font := WMGraphics.GetDefaultFont(); END;
  1171. ASSERT(font # NIL);
  1172. RETURN font;
  1173. END Get;
  1174. PROCEDURE Set*(font : WMGraphics.Font);
  1175. BEGIN
  1176. IF (font = NIL) THEN font := WMGraphics.GetDefaultFont(); END;
  1177. ASSERT(font # NIL);
  1178. AcquireWrite;
  1179. IF font # SELF.font THEN
  1180. SELF.font := font; Changed;
  1181. IF object # NIL THEN UpdateModel END;
  1182. ELSIF ~ nonDefault THEN Changed END;
  1183. NotDefault;
  1184. ReleaseWrite;
  1185. END Set;
  1186. PROCEDURE GetFont*(VAR name : ARRAY OF CHAR; VAR size : LONGINT; VAR style : SET);
  1187. VAR font : WMGraphics.Font;
  1188. BEGIN
  1189. font := Get();
  1190. COPY(font.name, name); size := font.size; style := font.style;
  1191. END GetFont;
  1192. PROCEDURE SetFont*(CONST name : ARRAY OF CHAR; size : LONGINT; style : SET);
  1193. VAR font : WMGraphics.Font;
  1194. BEGIN
  1195. IF size < 6 THEN size := 6 END;
  1196. font := WMGraphics.GetFont(name, size, style);
  1197. IF (font = NIL) THEN font := WMGraphics.GetDefaultFont(); END;
  1198. ASSERT(font # NIL);
  1199. AcquireWrite;
  1200. IF (SELF.font # font) THEN SELF.font := font; Changed; END;
  1201. NotDefault;
  1202. ReleaseWrite;
  1203. END SetFont;
  1204. PROCEDURE SetFontName*(CONST name : ARRAY OF CHAR);
  1205. VAR font : WMGraphics.Font;
  1206. BEGIN
  1207. AcquireWrite;
  1208. font := Get();
  1209. IF (font.name # name) THEN
  1210. font := WMGraphics.GetFont(name, font.size, font.style);
  1211. IF (font = NIL) THEN font := WMGraphics.GetDefaultFont(); END;
  1212. IF (SELF.font # font) THEN
  1213. SELF.font := font;
  1214. Changed;
  1215. END;
  1216. END;
  1217. NotDefault;
  1218. ReleaseWrite;
  1219. END SetFontName;
  1220. PROCEDURE GetFontName*(VAR name : ARRAY OF CHAR);
  1221. VAR font : WMGraphics.Font;
  1222. BEGIN
  1223. font := Get();
  1224. COPY(font.name, name);
  1225. END GetFontName;
  1226. PROCEDURE SetSize*(size : LONGINT);
  1227. VAR font : WMGraphics.Font;
  1228. BEGIN
  1229. AcquireWrite;
  1230. font := Get();
  1231. IF size < 6 THEN size := 6 END;
  1232. IF (font.size # size) THEN
  1233. font := WMGraphics.GetFont(font.name, size, font.style);
  1234. IF (font = NIL) THEN font := WMGraphics.GetDefaultFont(); END;
  1235. IF (SELF.font # font) THEN
  1236. SELF.font := font;
  1237. Changed;
  1238. END;
  1239. END;
  1240. NotDefault;
  1241. ReleaseWrite;
  1242. END SetSize;
  1243. PROCEDURE GetSize*() : LONGINT;
  1244. VAR font : WMGraphics.Font;
  1245. BEGIN
  1246. font := Get();
  1247. RETURN font.size;
  1248. END GetSize;
  1249. PROCEDURE SetStyle*(style : SET);
  1250. VAR font : WMGraphics.Font;
  1251. BEGIN
  1252. AcquireWrite;
  1253. font := Get();
  1254. IF (font.style # style) THEN
  1255. font := WMGraphics.GetFont(font.name, font.size, style);
  1256. IF (font = NIL) THEN font := WMGraphics.GetDefaultFont(); END;
  1257. IF (SELF.font # font) THEN
  1258. SELF.font := font;
  1259. Changed;
  1260. END;
  1261. END;
  1262. NotDefault;
  1263. ReleaseWrite;
  1264. END SetStyle;
  1265. PROCEDURE GetSyle*() : SET;
  1266. VAR font : WMGraphics.Font;
  1267. BEGIN
  1268. font := Get();
  1269. RETURN font.style;
  1270. END GetSyle;
  1271. PROCEDURE FromXML*(xml : XML.Element);
  1272. VAR s : String; name : ARRAY 32 OF CHAR; size : LONGINT; style : SET;
  1273. BEGIN
  1274. s := xml.GetAttributeValue("name");
  1275. IF (s # NIL) THEN COPY(s^, name); ELSE name := ""; END;
  1276. s := xml.GetAttributeValue("size");
  1277. IF (s # NIL) THEN Strings.StrToInt(s^, size); ELSE size := 0; END;
  1278. s := xml.GetAttributeValue("style");
  1279. IF (s # NIL) THEN Strings.StrToSet(s^, style); ELSE style := {}; END;
  1280. SetFont(name, size, style);
  1281. END FromXML;
  1282. PROCEDURE ToXML*(VAR element: XML.Element);
  1283. VAR s: ARRAY 32 OF CHAR;
  1284. BEGIN
  1285. IF (GetName # NIL) & nonDefault THEN
  1286. ToXML^(element);
  1287. element.SetAttributeValue("loader","WMProperties.NewFont");
  1288. element.SetAttributeValue("name",font.name);
  1289. Strings.IntToStr(font.size, s);
  1290. element.SetAttributeValue("size",s);
  1291. Strings.SetToStr(font.style, s);
  1292. element.SetAttributeValue("style",s);
  1293. END;
  1294. END ToXML;
  1295. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  1296. VAR name : String; font : WMGraphics.Font; temp : ARRAY 32 OF CHAR;
  1297. BEGIN
  1298. name := GetName();
  1299. IF name = NIL THEN KernelLog.String("Nameless boolean property encountered. Ignored"); KernelLog.Ln; RETURN END;
  1300. IF nonDefault THEN
  1301. font := Get();
  1302. Indent(w, indent);
  1303. w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewFont"');
  1304. w.String(' name="'); w.String(font.name); w.String('" size="'); w.Int(font.size, 0); w.String('" style="');
  1305. Strings.SetToStr(font.style, temp); w.String(temp); w.String('"');
  1306. w.String("/>");
  1307. w.Ln;
  1308. END
  1309. END WriteXML;
  1310. END FontProperty;
  1311. TYPE
  1312. (** Accessor property to an Point (in integer coordinates). *)
  1313. PointProperty*= OBJECT(Property)
  1314. VAR
  1315. value : WMGraphics.Point2d;
  1316. PROCEDURE FromStream*(r : Streams.Reader);
  1317. VAR new : WMGraphics.Point2d;
  1318. BEGIN
  1319. AcquireWrite;
  1320. r.SkipWhitespace; r.Int(new.x, FALSE);
  1321. r.SkipWhitespace; r.Int(new.y, FALSE);
  1322. NotDefault;
  1323. IF (new.x=value.x) & (new.y=value.y) THEN
  1324. value := new;
  1325. Changed;
  1326. END;
  1327. ReleaseWrite
  1328. END FromStream;
  1329. PROCEDURE ToStream*(w : Streams.Writer);
  1330. BEGIN
  1331. AcquireRead;
  1332. w.Int(value.x, 0); w.Char(" ");
  1333. w.Int(value.y, 0);
  1334. ReleaseRead
  1335. END ToStream;
  1336. PROCEDURE Get*() : WMGraphics.Point2d;
  1337. VAR r : WMGraphics.Point2d;
  1338. BEGIN
  1339. AcquireRead;
  1340. IF nonDefault OR (prototype = NIL) THEN r := value
  1341. ELSE r := prototype(PointProperty).Get()
  1342. END;
  1343. ReleaseRead;
  1344. RETURN r
  1345. END Get;
  1346. PROCEDURE Set*(value : WMGraphics.Point2d);
  1347. BEGIN
  1348. AcquireWrite;
  1349. IF (SELF.value.x#value.x) OR (SELF.value.y#value.y) THEN
  1350. SELF.value.x:=value.x;
  1351. SELF.value.y:=value.y;
  1352. IF object # NIL THEN UpdateModel END;
  1353. Changed;
  1354. ELSIF ~nonDefault THEN Changed
  1355. END;
  1356. NotDefault;
  1357. ReleaseWrite
  1358. END Set;
  1359. PROCEDURE SetCoordinate*(x,y : LONGINT);
  1360. BEGIN
  1361. AcquireWrite;
  1362. IF (x#value.x) OR (y#value.y) THEN
  1363. value.x:=x; value.y:=y;
  1364. Changed
  1365. END;
  1366. NotDefault;
  1367. ReleaseWrite
  1368. END SetCoordinate;
  1369. PROCEDURE GetCoordinate*(VAR x,y: LONGINT);
  1370. BEGIN
  1371. x:=value.x; y:=value.y
  1372. END GetCoordinate;
  1373. PROCEDURE SetX*(x : LONGINT);
  1374. BEGIN
  1375. AcquireWrite;
  1376. IF value.x # x THEN value.x := x; Changed END; NotDefault;
  1377. ReleaseWrite
  1378. END SetX;
  1379. PROCEDURE SetY*(y : LONGINT);
  1380. BEGIN
  1381. AcquireWrite;
  1382. IF value.y # y THEN value.y := y; Changed END; NotDefault;
  1383. ReleaseWrite
  1384. END SetY;
  1385. PROCEDURE GetX*() : LONGINT;
  1386. BEGIN
  1387. RETURN value.x
  1388. END GetX;
  1389. PROCEDURE GetY*(): LONGINT;
  1390. BEGIN
  1391. RETURN value.y
  1392. END GetY;
  1393. PROCEDURE FromXML*(xml : XML.Element);
  1394. VAR en : XMLObjects.Enumerator; p : ANY; s: String;
  1395. BEGIN
  1396. AcquireWrite;
  1397. en := xml.GetContents();
  1398. WHILE en.HasMoreElements() DO
  1399. IF en.HasMoreElements() THEN
  1400. p := en.GetNext();
  1401. IF (p IS XML.Element) THEN
  1402. s := p(XML.Element).GetName();
  1403. IF s # NIL THEN
  1404. IF s^ = "X" THEN SetX(ReadCharDataInt(p(XML.Element)))
  1405. ELSIF s^ = "Y" THEN SetY(ReadCharDataInt(p(XML.Element)))
  1406. END
  1407. END
  1408. END
  1409. END
  1410. END;
  1411. Stamp;
  1412. ReleaseWrite
  1413. END FromXML;
  1414. PROCEDURE ToXML*(VAR element: XML.Element);
  1415. VAR cs: ARRAY 10 OF CHAR; sub: XML.Element; t: WMGraphics.Point2d;
  1416. BEGIN
  1417. IF (GetName # NIL) & nonDefault THEN
  1418. ToXML^(element);
  1419. element.SetAttributeValue("loader","WMProperties.NewPoint");
  1420. t := Get();
  1421. NEW(sub); sub.SetName("X"); element.AddContent(sub);
  1422. sub.AddContent(NewIntChars(t.x));
  1423. NEW(sub); sub.SetName("Y");element.AddContent(sub);
  1424. sub.AddContent(NewIntChars(t.y));
  1425. END;
  1426. END ToXML;
  1427. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  1428. VAR name : String; t : WMGraphics.Point2d;
  1429. BEGIN
  1430. name := GetName();
  1431. IF name = NIL THEN KernelLog.String("Nameless point property encountered. Ignored"); KernelLog.Ln; RETURN END;
  1432. IF nonDefault THEN
  1433. t := Get();
  1434. Indent(w, indent);w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewPoint"'); w.Char(">"); w.Ln;
  1435. Indent(w, indent + 1); w.String("<X>"); w.Int(t.x, 0); w.String("</X>"); w.Ln;
  1436. Indent(w, indent + 1); w.String("<Y>"); w.Int(t.y, 0); w.String("</Y>"); w.Ln;
  1437. Indent(w, indent); w.String("</"); w.String(name^); w.Char(">"); w.Ln;
  1438. END
  1439. END WriteXML;
  1440. END PointProperty;
  1441. TYPE
  1442. (** Accessor property to an integer value. The range of possible values can be restricted. *)
  1443. RectangleProperty* = OBJECT(Property)
  1444. VAR
  1445. value : WMRectangles.Rectangle;
  1446. PROCEDURE FromStream*(r : Streams.Reader);
  1447. VAR new : WMRectangles.Rectangle;
  1448. BEGIN
  1449. AcquireWrite;
  1450. r.SkipWhitespace; r.Int(new.l, FALSE);
  1451. r.SkipWhitespace; r.Int(new.t, FALSE);
  1452. r.SkipWhitespace; r.Int(new.r, FALSE);
  1453. r.SkipWhitespace; r.Int(new.b, FALSE);
  1454. NotDefault;
  1455. IF ~WMRectangles.IsEqual(new, value) THEN
  1456. value := new;
  1457. Changed;
  1458. END;
  1459. ReleaseWrite
  1460. END FromStream;
  1461. PROCEDURE ToStream*(w : Streams.Writer);
  1462. BEGIN
  1463. AcquireRead;
  1464. w.Int(value.l, 0); w.Char(" "); w.Int(value.t, 0); w.Char(" ");
  1465. w.Int(value.r, 0); w.Char(" "); w.Int(value.b, 0);
  1466. ReleaseRead
  1467. END ToStream;
  1468. PROCEDURE Get*() : WMRectangles.Rectangle;
  1469. VAR r : WMRectangles.Rectangle;
  1470. BEGIN
  1471. AcquireRead;
  1472. IF nonDefault OR (prototype = NIL) THEN r := value
  1473. ELSE r := prototype(RectangleProperty).Get()
  1474. END;
  1475. ReleaseRead;
  1476. RETURN r
  1477. END Get;
  1478. PROCEDURE Set*(value : WMRectangles.Rectangle);
  1479. BEGIN
  1480. AcquireWrite;
  1481. IF (SELF.value.l # value.l) OR (SELF.value.t # value.t) OR
  1482. (SELF.value.r # value.r) OR (SELF.value.b # value.b) THEN
  1483. SELF.value := value; Changed;
  1484. IF object # NIL THEN UpdateModel END;
  1485. ELSIF ~nonDefault THEN Changed
  1486. END;
  1487. NotDefault;
  1488. ReleaseWrite
  1489. END Set;
  1490. PROCEDURE SetWidth*(w : LONGINT);
  1491. BEGIN
  1492. AcquireWrite;
  1493. IF GetWidth() # w THEN Changed END; value.r := value.l + w; NotDefault;
  1494. ReleaseWrite
  1495. END SetWidth;
  1496. PROCEDURE SetHeight*(h : LONGINT);
  1497. BEGIN
  1498. AcquireWrite;
  1499. IF GetHeight() # h THEN Changed END; value.b := value.t + h; NotDefault;
  1500. ReleaseWrite
  1501. END SetHeight;
  1502. PROCEDURE SetLeft*(l : LONGINT);
  1503. BEGIN
  1504. AcquireWrite;
  1505. IF value.l # l THEN Changed END; value.r := l + GetWidth(); value.l := l; NotDefault;
  1506. ReleaseWrite
  1507. END SetLeft;
  1508. PROCEDURE SetTop*(t : LONGINT);
  1509. BEGIN
  1510. AcquireWrite;
  1511. IF value.t # t THEN Changed END; value.b := t + GetHeight(); value.t := t; NotDefault;
  1512. ReleaseWrite
  1513. END SetTop;
  1514. PROCEDURE SetRight*(r : LONGINT);
  1515. BEGIN
  1516. AcquireWrite;
  1517. IF value.r # r THEN Changed END; value.r := r; NotDefault;
  1518. ReleaseWrite
  1519. END SetRight;
  1520. PROCEDURE SetBottom*(b : LONGINT);
  1521. BEGIN
  1522. AcquireWrite;
  1523. IF value.b # b THEN Changed END; value.b := b; NotDefault;
  1524. ReleaseWrite
  1525. END SetBottom;
  1526. PROCEDURE SetExtents*(w, h : LONGINT);
  1527. BEGIN
  1528. AcquireWrite; (* protective transaction *)
  1529. SetWidth(w); SetHeight(h);
  1530. ReleaseWrite
  1531. END SetExtents;
  1532. PROCEDURE GetWidth*() : LONGINT;
  1533. VAR r : WMRectangles.Rectangle;
  1534. BEGIN
  1535. r := Get();
  1536. RETURN r.r - r.l;
  1537. END GetWidth;
  1538. PROCEDURE GetHeight*() : LONGINT;
  1539. VAR r : WMRectangles.Rectangle;
  1540. BEGIN
  1541. r := Get();
  1542. RETURN r.b - r.t;
  1543. END GetHeight;
  1544. PROCEDURE GetLeft*() : LONGINT;
  1545. VAR r : WMRectangles.Rectangle;
  1546. BEGIN
  1547. r := Get();
  1548. RETURN r.l;
  1549. END GetLeft;
  1550. PROCEDURE GetTop*() : LONGINT;
  1551. VAR r : WMRectangles.Rectangle;
  1552. BEGIN
  1553. r := Get();
  1554. RETURN r.t;
  1555. END GetTop;
  1556. PROCEDURE GetRight*() : LONGINT;
  1557. VAR r : WMRectangles.Rectangle;
  1558. BEGIN
  1559. r := Get();
  1560. RETURN r.r;
  1561. END GetRight;
  1562. PROCEDURE GetBottom*() : LONGINT;
  1563. VAR r : WMRectangles.Rectangle;
  1564. BEGIN
  1565. r := Get();
  1566. RETURN r.b;
  1567. END GetBottom;
  1568. PROCEDURE GetExtents*(VAR width, height : LONGINT);
  1569. VAR r : WMRectangles.Rectangle;
  1570. BEGIN
  1571. r := Get();
  1572. width := r.r - r.l;
  1573. height := r.b - r.t;
  1574. END GetExtents;
  1575. PROCEDURE FromXML*(xml : XML.Element);
  1576. VAR en : XMLObjects.Enumerator; p : ANY; s: String;
  1577. BEGIN
  1578. AcquireWrite;
  1579. en := xml.GetContents();
  1580. WHILE en.HasMoreElements() DO
  1581. IF en.HasMoreElements() THEN
  1582. p := en.GetNext();
  1583. IF (p IS XML.Element) THEN
  1584. s := p(XML.Element).GetName();
  1585. IF s # NIL THEN
  1586. IF s^ = "Left" THEN SetLeft(ReadCharDataInt(p(XML.Element)))
  1587. ELSIF s^ = "Top" THEN SetTop(ReadCharDataInt(p(XML.Element)))
  1588. ELSIF s^ = "Right" THEN SetRight(ReadCharDataInt(p(XML.Element)))
  1589. ELSIF s^ = "Bottom" THEN SetBottom(ReadCharDataInt(p(XML.Element)))
  1590. ELSIF s^ = "Width" THEN SetWidth(ReadCharDataInt(p(XML.Element)))
  1591. ELSIF s^ = "Height" THEN SetHeight(ReadCharDataInt(p(XML.Element)))
  1592. END
  1593. END
  1594. END
  1595. END
  1596. END;
  1597. Stamp;
  1598. ReleaseWrite
  1599. END FromXML;
  1600. PROCEDURE ToXML*(VAR element: XML.Element);
  1601. VAR cs: ARRAY 10 OF CHAR; sub: XML.Element; t: WMRectangles.Rectangle;
  1602. BEGIN
  1603. IF (GetName # NIL) & nonDefault THEN
  1604. ToXML^(element);
  1605. element.SetAttributeValue("loader","WMProperties.NewRectangle");
  1606. t := Get();
  1607. NEW(sub); sub.SetName("Left"); element.AddContent(sub);
  1608. sub.AddContent(NewIntChars(t.l));
  1609. NEW(sub); sub.SetName("Top");element.AddContent(sub);
  1610. sub.AddContent(NewIntChars(t.t));
  1611. NEW(sub); sub.SetName("Width");element.AddContent(sub);
  1612. sub.AddContent(NewIntChars(t.r-t.l));
  1613. NEW(sub); sub.SetName("Height");element.AddContent(sub);
  1614. sub.AddContent(NewIntChars(t.b-t.t));
  1615. END;
  1616. END ToXML;
  1617. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  1618. VAR name : String; t : WMRectangles.Rectangle;
  1619. BEGIN
  1620. name := GetName();
  1621. IF name = NIL THEN KernelLog.String("Nameless rectangle property encountered. Ignored"); KernelLog.Ln; RETURN END;
  1622. IF nonDefault THEN
  1623. t := Get();
  1624. Indent(w, indent);w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewRectangle"'); w.Char(">"); w.Ln;
  1625. Indent(w, indent + 1); w.String("<Left>"); w.Int(t.l, 0); w.String("</Left>"); w.Ln;
  1626. Indent(w, indent + 1); w.String("<Top>"); w.Int(t.t, 0); w.String("</Top>"); w.Ln;
  1627. Indent(w, indent + 1); w.String("<Width>"); w.Int(t.r-t.l, 0); w.String("</Width>"); w.Ln;
  1628. Indent(w, indent + 1); w.String("<Height>"); w.Int(t.b-t.t, 0); w.String("</Height>"); w.Ln;
  1629. Indent(w, indent); w.String("</"); w.String(name^); w.Char(">"); w.Ln;
  1630. END
  1631. END WriteXML;
  1632. END RectangleProperty;
  1633. TYPE
  1634. ReferenceProperty* = OBJECT(Property)
  1635. VAR
  1636. (*
  1637. object : Repositories.Component;
  1638. repositoryName : Strings.String;
  1639. componentName : Strings.String;
  1640. generator : Strings.String;
  1641. componentID : LONGINT;
  1642. *)
  1643. (* temporary used in WriteXML *)
  1644. level: LONGINT;
  1645. PROCEDURE &NewRef*(prototype : Property; name, info : String);
  1646. BEGIN
  1647. New(prototype, name, info);
  1648. END NewRef;
  1649. PROCEDURE FromStream*(r : Streams.Reader);
  1650. VAR
  1651. fullname, repositoryName : ARRAY 256 OF CHAR; componentName : ARRAY 128 OF CHAR;
  1652. writer : Streams.Writer; buffer : Strings.Buffer; ch : CHAR;
  1653. BEGIN
  1654. r.String(fullname);
  1655. IF Repositories.IsCommandString(fullname) THEN
  1656. AcquireWrite;
  1657. SELF.repositoryName := NIL;
  1658. SELF.componentName := NIL;
  1659. componentID := 0;
  1660. NEW(buffer, 256); writer := buffer.GetWriter();
  1661. writer.String(fullname);
  1662. WHILE (r.res = Streams.Ok) DO
  1663. r.Char(ch); writer.Char(ch);
  1664. END;
  1665. SELF.generator := buffer.GetString();
  1666. ReleaseWrite;
  1667. ELSIF Repositories.SplitName(fullname, repositoryName, componentName, SELF.componentID) THEN
  1668. AcquireWrite;
  1669. NotDefault;
  1670. SELF.repositoryName := Strings.NewString(repositoryName);
  1671. SELF.componentName := Strings.NewString(componentName);
  1672. generator := NIL;
  1673. ReleaseWrite
  1674. ELSE
  1675. AcquireWrite;
  1676. SELF.repositoryName := NIL;
  1677. SELF.componentName := NIL;
  1678. componentID := 0;
  1679. generator := NIL;
  1680. ReleaseWrite
  1681. END;
  1682. END FromStream;
  1683. PROCEDURE ToStream*(w : Streams.Writer);
  1684. BEGIN
  1685. AcquireRead;
  1686. IF (generator # NIL) THEN
  1687. w.String(generator^);
  1688. ELSIF (repositoryName # NIL) & (componentName # NIL) THEN
  1689. w.String(repositoryName^); w.String(":"); w.String(componentName^); w.String(":"); w.Int(componentID, 0);
  1690. ELSIF (object # NIL) THEN
  1691. w.Ln;
  1692. Indent(w,level); object.Write(w, NIL, level);
  1693. w.Ln; Indent(w,level-1);
  1694. END;
  1695. ReleaseRead
  1696. END ToStream;
  1697. PROCEDURE Get*() : Repositories.Component;
  1698. VAR object : Repositories.Component; context : Repositories.Context; res : WORD;
  1699. BEGIN
  1700. AcquireRead;
  1701. object := SELF.object;
  1702. ReleaseRead;
  1703. (* late time generation of object for supporting of loading repositories *)
  1704. IF (object = NIL) THEN
  1705. IF (generator # NIL) THEN
  1706. Repositories.CallCommand(generator^, context, res);
  1707. IF (res = Repositories.Ok) & (context.object # NIL) & (context.object IS Repositories.Component) THEN
  1708. object := context.object(Repositories.Component);
  1709. Set(object)
  1710. END;
  1711. ELSIF (repositoryName # NIL) & (componentName # NIL) THEN
  1712. Repositories.GetComponent(repositoryName^, componentName^, componentID, object, res);
  1713. Set(object);
  1714. ELSIF (componentName # NIL) & (repository # NIL) THEN
  1715. object := repository.GetComponent(componentName^, componentID);
  1716. Set(object);
  1717. END;
  1718. END;
  1719. RETURN object
  1720. END Get;
  1721. PROCEDURE Set*(object : Repositories.Component);
  1722. BEGIN
  1723. AcquireWrite; (* TBD: Store object to repository *)
  1724. IF (SELF.object # object) THEN
  1725. ReplaceLink(object); Changed;
  1726. ELSIF ~ nonDefault THEN Changed END;
  1727. NotDefault;
  1728. ReleaseWrite;
  1729. END Set;
  1730. PROCEDURE LinkChanged(sender, object: ANY);
  1731. BEGIN
  1732. IF (list # NIL) THEN list.onLinkChanged.CallWithSender(SELF,object) END;
  1733. END LinkChanged;
  1734. PROCEDURE SetAsString*(CONST string : ARRAY OF CHAR);
  1735. BEGIN
  1736. SetLinkAsString(string)
  1737. END SetAsString;
  1738. PROCEDURE GetAsString*(VAR string : ARRAY OF CHAR);
  1739. BEGIN
  1740. GetLinkAsString(string)
  1741. END GetAsString;
  1742. PROCEDURE Reset*;
  1743. BEGIN
  1744. AcquireWrite;
  1745. ReplaceLink(NIL);
  1746. repositoryName := NIL; componentName := NIL; componentID := 0;
  1747. generator := NIL;
  1748. NotDefault;
  1749. Changed;
  1750. ReleaseWrite;
  1751. END Reset;
  1752. PROCEDURE FromXML*(xml : XML.Element);
  1753. VAR en : XMLObjects.Enumerator; p : ANY; s : String;
  1754. BEGIN
  1755. ReplaceLink(NIL);
  1756. object := NIL;
  1757. repositoryName := NIL; componentName := NIL;
  1758. componentID := 0;
  1759. en := xml.GetContents();
  1760. p := en.GetNext();
  1761. NotDefault;
  1762. IF (p # NIL ) & (p IS XML.Chars) THEN
  1763. s := p(XML.Chars).GetStr();
  1764. IF s # NIL THEN
  1765. Strings.Trim(s^, " ");
  1766. SetAsString(s^);
  1767. object := Get();
  1768. END
  1769. ELSIF (p # NIL) & (p IS XML.Element) THEN
  1770. ReplaceLink( Repositories.ComponentFromXML(p(XML.Element)));
  1771. END
  1772. END FromXML;
  1773. PROCEDURE ToXML*(VAR element: XML.Element);
  1774. VAR cs: ARRAY 10 OF CHAR; sub: XML.Element; t: WMRectangles.Rectangle;
  1775. BEGIN
  1776. IF (GetName # NIL) & nonDefault THEN
  1777. ToXML^(element);
  1778. element.SetAttributeValue("loader","WMProperties.NewReference");
  1779. (*??? how to represent this ? *)
  1780. END;
  1781. END ToXML;
  1782. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  1783. VAR name : String; id: LONGINT; res: WORD; repository: Repositories.Repository; objectName: String;
  1784. BEGIN
  1785. name := GetName();
  1786. IF name = NIL THEN KernelLog.String("Nameless boolean property encountered. Ignored"); KernelLog.Ln; RETURN END;
  1787. IF nonDefault THEN
  1788. Indent(w, indent);
  1789. level := indent+1;
  1790. w.Char("<"); w.String(name^); w.String(' loader="WMProperties.NewReference"'); w.Char(">");
  1791. IF (context # NIL) & (context IS Repositories.StoreContext) & (object # NIL) THEN
  1792. repository := context(Repositories.StoreContext).repository;
  1793. id := 1;
  1794. objectName := object.GetName();
  1795. IF (objectName=NIL) OR (objectName^="") THEN objectName :=anonymous END;
  1796. repository.PutComponent(object, objectName^,id,res);
  1797. w.String(":"); (* <-- THIS repository *) w.String(objectName^); w.String(":"); w.Int(id, 0);
  1798. ELSE
  1799. ToStream(w);
  1800. END;
  1801. w.String("</"); w.String(name^); w.Char(">"); w.Ln;
  1802. END
  1803. END WriteXML;
  1804. PROCEDURE Finalize*;
  1805. BEGIN
  1806. AcquireWrite;
  1807. ReplaceLink(NIL);
  1808. ReleaseWrite;
  1809. END Finalize;
  1810. END ReferenceProperty;
  1811. TYPE
  1812. PropertyArray* = POINTER TO ARRAY OF Property;
  1813. PropertyList* = OBJECT
  1814. VAR
  1815. properties : PropertyArray;
  1816. nofProperties- : LONGINT;
  1817. onPropertyChanged- : WMEvents.EventSource;
  1818. onLinkChanged-: WMEvents.EventSource;
  1819. lock : Locks.RWLock;
  1820. upNofChanges : LONGINT;
  1821. upChanged : Property;
  1822. propertyChanged, linkChanged: WMEvents.EventListener;
  1823. PROCEDURE &New*;
  1824. BEGIN
  1825. NEW(properties, 8);
  1826. NEW(onPropertyChanged, SELF, StringProperties, StringPropertiesInfo, NIL);
  1827. NEW(onLinkChanged, SELF, StringLinks, StringLinksInfo, NIL);
  1828. NEW(lock)
  1829. END New;
  1830. (** acquire a write lock on the object *)
  1831. PROCEDURE AcquireWrite*;
  1832. BEGIN
  1833. lock.AcquireWrite
  1834. END AcquireWrite;
  1835. (** release the write lock on the object *)
  1836. PROCEDURE ReleaseWrite*;
  1837. VAR
  1838. removeLock : BOOLEAN;
  1839. changed : Property; nofChanges : LONGINT;
  1840. BEGIN
  1841. removeLock := lock.GetWLockLevel() = 1;
  1842. IF removeLock THEN
  1843. changed := upChanged; nofChanges := upNofChanges;
  1844. upNofChanges := 0; upChanged := NIL;
  1845. END;
  1846. lock.ReleaseWrite;
  1847. IF removeLock THEN
  1848. IF nofChanges = 1 THEN onPropertyChanged.Call(changed)
  1849. ELSIF nofChanges > 0 THEN onPropertyChanged.Call(SELF)
  1850. END
  1851. END
  1852. END ReleaseWrite;
  1853. PROCEDURE AcquireRead;
  1854. BEGIN
  1855. lock.AcquireRead
  1856. END AcquireRead;
  1857. PROCEDURE ReleaseRead;
  1858. BEGIN
  1859. lock.ReleaseRead
  1860. END ReleaseRead;
  1861. PROCEDURE Add*(x : Property);
  1862. BEGIN
  1863. AcquireWrite;
  1864. x.list := SELF;
  1865. IF nofProperties = LEN(properties) THEN Grow END;
  1866. properties[nofProperties] := x;
  1867. INC(nofProperties);
  1868. ReleaseWrite
  1869. END Add;
  1870. PROCEDURE Remove*(x : Property);
  1871. VAR i : LONGINT;
  1872. BEGIN
  1873. AcquireWrite;
  1874. i := 0; WHILE (i < nofProperties) & (properties[i] # x) DO INC(i) END;
  1875. IF i < nofProperties THEN
  1876. WHILE (i < nofProperties - 1) DO properties[i] := properties[i + 1]; INC(i) END;
  1877. DEC(nofProperties);
  1878. properties[nofProperties] := NIL
  1879. END;
  1880. ReleaseWrite
  1881. END Remove;
  1882. PROCEDURE Get*(CONST name : ARRAY OF CHAR) : Property;
  1883. VAR property : Property; n : String; i : LONGINT;
  1884. BEGIN
  1885. AcquireRead;
  1886. i := 0; property := NIL;
  1887. WHILE (i < nofProperties) & (property = NIL) DO
  1888. n := properties[i].GetName();
  1889. IF (n # NIL) & (n^ = name) THEN
  1890. property := properties[i];
  1891. END;
  1892. INC(i);
  1893. END;
  1894. ReleaseRead;
  1895. RETURN property;
  1896. END Get;
  1897. PROCEDURE Grow;
  1898. VAR new: PropertyArray; i : LONGINT;
  1899. BEGIN
  1900. NEW(new, LEN(properties) * 2);
  1901. FOR i := 0 TO nofProperties - 1 DO new[i] := properties[i] END;
  1902. properties := new
  1903. END Grow;
  1904. PROCEDURE Enumerate*() : PropertyArray;
  1905. VAR current : PropertyArray; i : LONGINT;
  1906. BEGIN
  1907. AcquireWrite;
  1908. NEW(current, nofProperties);
  1909. FOR i := 0 TO nofProperties - 1 DO current[i] := properties[i] END;
  1910. ReleaseWrite;
  1911. RETURN current
  1912. END Enumerate;
  1913. PROCEDURE HasProperty*(CONST name : ARRAY OF CHAR) : BOOLEAN;
  1914. VAR n : Strings.String; found : BOOLEAN; i : LONGINT;
  1915. BEGIN
  1916. found := FALSE;
  1917. AcquireRead;
  1918. i := 0;
  1919. WHILE ~found & (i < nofProperties) DO
  1920. n := properties[i].GetName();
  1921. found := (n # NIL) & (n^ = name);
  1922. INC(i);
  1923. END;
  1924. ReleaseRead;
  1925. RETURN found;
  1926. END HasProperty;
  1927. PROCEDURE GetPropertyValue*(CONST name : ARRAY OF CHAR; VAR value : ARRAY OF CHAR) : BOOLEAN;
  1928. VAR i : LONGINT; n : String; vs : Streams.StringWriter; len : LONGINT;
  1929. BEGIN
  1930. AcquireRead;
  1931. i := 0;
  1932. WHILE i < nofProperties DO
  1933. n := properties[i].GetName();
  1934. IF (n # NIL) & (n^ = name) THEN
  1935. len := LEN(value);
  1936. NEW(vs, LEN(value)); vs.GetRaw(value, len);
  1937. properties[i].ToStream(vs);
  1938. vs.Get(value);
  1939. ReleaseRead;
  1940. RETURN TRUE;
  1941. END;
  1942. INC(i);
  1943. END;
  1944. ReleaseRead;
  1945. RETURN FALSE;
  1946. END GetPropertyValue;
  1947. PROCEDURE SetPropertyValue*(CONST name, value: ARRAY OF CHAR) : BOOLEAN;
  1948. VAR i : LONGINT; n : String; vs : Streams.StringReader;
  1949. BEGIN
  1950. AcquireWrite;
  1951. i := 0;
  1952. WHILE i < nofProperties DO
  1953. n := properties[i].GetName();
  1954. IF (n # NIL) & (n^ = name) THEN
  1955. NEW(vs, LEN(value)); vs.SetRaw(value, 0, LEN(value));
  1956. properties[i].FromStream(vs); i := nofProperties
  1957. END;
  1958. INC(i)
  1959. END;
  1960. ReleaseWrite;
  1961. RETURN (i > nofProperties) (* if no success, then i=nofProperties; patch PH 06/12 *)
  1962. END SetPropertyValue;
  1963. PROCEDURE SetXML*(xml : XML.Element);
  1964. VAR
  1965. en : XMLObjects.Enumerator;
  1966. p : ANY; s, n : String; i : LONGINT;
  1967. repository: Repositories.Repository;
  1968. BEGIN
  1969. AcquireWrite;
  1970. IF xml IS Repositories.Properties THEN repository := xml(Repositories.Properties).repository ELSE repository := NIL END;
  1971. en := xml.GetContents();
  1972. WHILE en.HasMoreElements() DO
  1973. p := en.GetNext();
  1974. IF p IS XML.Element THEN
  1975. s := p(XML.Element).GetName();
  1976. i := 0;
  1977. WHILE i < nofProperties DO
  1978. properties[i].repository := repository;
  1979. n := properties[i].GetName();
  1980. IF (n # NIL) & (n^ = s^) THEN
  1981. properties[i].FromXML(p(XML.Element)); i := nofProperties
  1982. END;
  1983. INC(i)
  1984. END
  1985. END
  1986. END;
  1987. ReleaseWrite
  1988. END SetXML;
  1989. PROCEDURE FromXML*(xml: XML.Element);
  1990. VAR generator: PROCEDURE(): Property;
  1991. VAR
  1992. property: Property;
  1993. l: Strings.String;
  1994. en : XMLObjects.Enumerator;
  1995. p : ANY; s, n : String; i : LONGINT;
  1996. moduleName, procedureName: Modules.Name;
  1997. res: WORD; msg: ARRAY 32 OF CHAR;
  1998. found: BOOLEAN;
  1999. BEGIN
  2000. IF xml # NIL THEN
  2001. AcquireWrite;
  2002. en := xml.GetContents();
  2003. WHILE en.HasMoreElements() DO
  2004. p := en.GetNext();
  2005. IF p IS XML.Element THEN
  2006. s := p(XML.Element).GetName();
  2007. (* check if property is already there (and potentially linked in application, in which case it should not be reinstalled *)
  2008. i := 0; found := FALSE;
  2009. WHILE (i < nofProperties) & ~found DO
  2010. n := properties[i].GetName();
  2011. IF (n # NIL) & (n^ = s^) THEN
  2012. found := TRUE;
  2013. properties[i].FromXML(p(XML.Element)); i := nofProperties
  2014. END;
  2015. INC(i)
  2016. END;
  2017. IF ~found THEN
  2018. l := p(XML.Element).GetAttributeValue("loader");
  2019. IF l # NIL THEN
  2020. Commands.Split(l^, moduleName, procedureName, res, msg);
  2021. IF (res = Commands.Ok) THEN
  2022. GETPROCEDURE(moduleName, procedureName, generator);
  2023. IF (generator # NIL) THEN
  2024. property := generator();
  2025. IF (property # NIL) THEN
  2026. property.New(NIL, s, NIL);
  2027. property.FromXML(p(XML.Element));
  2028. Add(property);
  2029. END;
  2030. END;
  2031. END;
  2032. END;
  2033. END;
  2034. END
  2035. END;
  2036. ReleaseWrite
  2037. END;
  2038. END FromXML;
  2039. PROCEDURE ToXML*(VAR element: XML.Element);
  2040. VAR sub: XML.Element; i : LONGINT; self: ANY;
  2041. BEGIN
  2042. NEW(element); element.SetName("Properties");
  2043. FOR i := 0 TO nofProperties-1 DO
  2044. sub := NIL;
  2045. properties[i].ToXML(sub);
  2046. IF sub # NIL THEN
  2047. element.AddContent(sub);
  2048. END;
  2049. END;
  2050. END ToXML;
  2051. PROCEDURE WriteXML*(w : Streams.Writer; context: ANY; indent : LONGINT);
  2052. VAR i : LONGINT;
  2053. BEGIN
  2054. w.Ln;
  2055. Indent(w, indent + 1);
  2056. w.String("<Properties>"); w.Ln;
  2057. AcquireRead;
  2058. FOR i := 0 TO nofProperties - 1 DO
  2059. properties[i].WriteXML(w, context, indent + 2)
  2060. END;
  2061. Indent(w, indent + 1);
  2062. w.String("</Properties>");
  2063. ReleaseRead
  2064. END WriteXML;
  2065. (*
  2066. PROCEDURE ToRepository*(CONST repository: ARRAY OF CHAR; w : Streams.Writer; indent : LONGINT);
  2067. VAR i : LONGINT;
  2068. BEGIN
  2069. w.Ln;
  2070. Indent(w, indent + 1);
  2071. w.String("<Properties>"); w.Ln;
  2072. AcquireRead;
  2073. FOR i := 0 TO nofProperties - 1 DO
  2074. properties[i].ToRepository(repository, w, indent + 2)
  2075. END;
  2076. Indent(w, indent + 1);
  2077. w.String("</Properties>");
  2078. ReleaseRead
  2079. END ToRepository;
  2080. *)
  2081. PROCEDURE Changed(p : Property);
  2082. BEGIN (* {EXCLUSIVE} *)
  2083. IF p # upChanged THEN INC(upNofChanges); upChanged := p END;
  2084. END Changed;
  2085. PROCEDURE Finalize*;
  2086. VAR i: LONGINT;
  2087. BEGIN
  2088. AcquireWrite;
  2089. FOR i := 0 TO nofProperties - 1 DO
  2090. properties[i].Finalize
  2091. END;
  2092. ReleaseWrite;
  2093. END Finalize;
  2094. END PropertyList;
  2095. Properties* = Repositories.Properties;
  2096. VAR
  2097. StringProperties, StringLinks : String;
  2098. StringPropertiesInfo, StringLinksInfo : String;
  2099. anonymous: String;
  2100. PROCEDURE Indent(w : Streams.Writer; indent : LONGINT);
  2101. VAR i : LONGINT;
  2102. BEGIN
  2103. FOR i := 0 TO indent - 1 DO w.Char(9X) END
  2104. END Indent;
  2105. PROCEDURE ReadCharDataInt(xml : XML.Element) : LONGINT;
  2106. VAR en : XMLObjects.Enumerator;
  2107. p : ANY; s : String; value : LONGINT;
  2108. BEGIN
  2109. value := 0;
  2110. en := xml.GetContents();
  2111. IF en.HasMoreElements() THEN
  2112. p := en.GetNext();
  2113. IF p IS XML.Chars THEN
  2114. s := p(XML.Chars).GetStr();
  2115. IF s # NIL THEN Strings.StrToInt(s^, value) END
  2116. END;
  2117. END;
  2118. RETURN value
  2119. END ReadCharDataInt;
  2120. PROCEDURE NewIntChars(i: LONGINT): XML.Chars;
  2121. VAR chars: XML.ArrayChars; s: ARRAY 32 OF CHAR;
  2122. BEGIN
  2123. NEW(chars);
  2124. Strings.IntToStr(i, s);
  2125. chars.SetStr(s);
  2126. RETURN chars
  2127. END NewIntChars;
  2128. PROCEDURE NewBoolean*(): Property;
  2129. VAR property: BooleanProperty;
  2130. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2131. END NewBoolean;
  2132. PROCEDURE NewSet*(): Property;
  2133. VAR property: SetProperty;
  2134. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2135. END NewSet;
  2136. PROCEDURE NewInt32*(): Property;
  2137. VAR property: Int32Property;
  2138. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2139. END NewInt32;
  2140. PROCEDURE NewReal*(): Property;
  2141. VAR property: RealProperty;
  2142. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2143. END NewReal;
  2144. PROCEDURE NewString*(): Property;
  2145. VAR property: StringProperty;
  2146. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2147. END NewString;
  2148. PROCEDURE NewColor*(): Property;
  2149. VAR property: ColorProperty;
  2150. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2151. END NewColor;
  2152. PROCEDURE NewFont*(): Property;
  2153. VAR property: FontProperty;
  2154. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2155. END NewFont;
  2156. PROCEDURE NewPoint*(): Property;
  2157. VAR property: PointProperty;
  2158. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2159. END NewPoint;
  2160. PROCEDURE NewRectangle*(): Property;
  2161. VAR property: RectangleProperty;
  2162. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2163. END NewRectangle;
  2164. PROCEDURE NewReference*(): Property;
  2165. VAR property: ReferenceProperty;
  2166. BEGIN NEW(property,NIL,NIL,NIL); RETURN property
  2167. END NewReference;
  2168. (* Get a model from either a property reference or a model pointer *)
  2169. PROCEDURE GetModel*(ref: ANY; VAR m: Models.Model): BOOLEAN;
  2170. BEGIN
  2171. IF (ref # NIL) & (ref IS ReferenceProperty) THEN ref := ref(ReferenceProperty).Get() END;
  2172. IF (ref # NIL) & (ref IS Models.Model) THEN m := ref(Models.Model); RETURN TRUE END;
  2173. RETURN FALSE
  2174. END GetModel;
  2175. BEGIN
  2176. StringProperties := Strings.NewString("PropertyChanged");
  2177. StringLinks := Strings.NewString("LinkChanged");
  2178. StringPropertiesInfo := Strings.NewString("the event is called if a property in the list is changed");
  2179. StringLinksInfo := Strings.NewString("the event is called if a link in a reference property in the list is changed");
  2180. anonymous := Strings.NewString("ANONYMOUS");
  2181. END WMProperties.