WMProperties.Mod 65 KB

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