WMTextStyleTool.Mod 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113
  1. MODULE WMTextStyleTool; (** AUTHOR "TF"; PURPOSE "Text Tool"; *)
  2. IMPORT
  3. Commands, Streams, Texts, Strings, WMComponents, WMRestorable, WMStringGrids, WMGrids,
  4. WMEditors, WMGraphics, WMMessages, WMStandardComponents, Modules,
  5. WMPopups, WMRectangles, WMDialogs, FP1616, Files, XMLParser, XMLScanner, XML, XMLObjects,
  6. WM := WMWindowManager;
  7. CONST
  8. AlignLeft = 0; AlignCenter = 1; AlignRight = 2; AlignJustified = 3;
  9. StyleRegular = 0; StyleBold = 1; StyleItalic = 2; StyleBoldItalic = 3;
  10. (* field parameter for Change procedure *)
  11. ChangeFont = {0};
  12. ChangeSize = {1};
  13. ChangeStyle = {2};
  14. ChangeFgColor = {3};
  15. ChangeBgColor = {4};
  16. (* mode parameter for Change procedure *)
  17. Absolute = 0;
  18. IncrementBy = 1;
  19. DecrementBy = 2;
  20. TYPE
  21. KillerMsg = OBJECT
  22. END KillerMsg;
  23. ContextMenuData = OBJECT
  24. VAR val: LONGINT;
  25. PROCEDURE &New*(val: LONGINT);
  26. BEGIN
  27. SELF.val := val;
  28. END New;
  29. END ContextMenuData;
  30. TYPE
  31. ChangeInfo= OBJECT (Texts.Attributes)
  32. VAR
  33. fields : SET; (* which fields should be changed *)
  34. name : ARRAY 128 OF CHAR;
  35. deltaSizeMode : LONGINT; (* Interpretation of deltasize field: Absolute, IncrementBy, DecrementBy *)
  36. deltaSize : LONGINT;
  37. fgColor, bgColor : LONGINT;
  38. style : SET;
  39. PROCEDURE &Init*;
  40. BEGIN
  41. fields := {};
  42. deltaSizeMode := 0;
  43. deltaSize := 0;
  44. fgColor := 0; bgColor := 0;
  45. style := {};
  46. END Init;
  47. END ChangeInfo;
  48. TYPE
  49. Window* = OBJECT (WMComponents.FormWindow)
  50. VAR
  51. bold, lock, comment, stupid, assert, preferred, debug, normal,
  52. highlight, adhoc, more, edit, link, label: WMStandardComponents.Button;
  53. winpanel : WMStandardComponents.Panel;
  54. cList : WMStringGrids.StringGrid;
  55. styleEditor : StyleEditor;
  56. PROCEDURE CreateForm(): WMComponents.VisualComponent;
  57. VAR
  58. panel : WMStandardComponents.Panel;
  59. toolbar: WMStandardComponents.Panel;
  60. PROCEDURE AB(panel : WMStandardComponents.Panel; btn: WMStandardComponents.Button);
  61. BEGIN
  62. btn.alignment.Set(WMComponents.AlignLeft); btn.bounds.SetWidth(60); panel.AddContent(btn)
  63. END AB;
  64. BEGIN
  65. NEW(panel); panel.bounds.SetExtents(120, 140); panel.takesFocus.Set(TRUE);
  66. (* link & label*)
  67. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  68. panel.AddContent(toolbar);
  69. NEW(link); link.caption.SetAOC("Add Link"); AB(toolbar, link); link.clDefault.Set(080CC80H);
  70. NEW(label); label.caption.SetAOC("Add Label"); AB(toolbar, label); label.clDefault.Set(080CC80H);
  71. (* styles *)
  72. (**)
  73. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  74. panel.AddContent(toolbar);
  75. NEW(bold); bold.caption.SetAOC("Bold"); AB(toolbar, bold);
  76. NEW(lock); lock.caption.SetAOC("Lock"); AB(toolbar, lock);
  77. (**)
  78. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  79. panel.AddContent(toolbar);
  80. NEW(comment); comment.caption.SetAOC("Comment"); AB(toolbar, comment);
  81. NEW(debug); debug.caption.SetAOC("Debug"); AB(toolbar, debug);
  82. (**)
  83. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  84. panel.AddContent(toolbar);
  85. NEW(stupid); stupid.caption.SetAOC("Stupid"); AB(toolbar, stupid);
  86. NEW(assert); assert.caption.SetAOC("Assert"); AB(toolbar, assert);
  87. (**)
  88. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  89. panel.AddContent(toolbar);
  90. NEW(preferred); preferred.caption.SetAOC("Preferred"); AB(toolbar, preferred);
  91. NEW(normal); normal.caption.SetAOC("Normal"); AB(toolbar, normal);
  92. (**)
  93. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  94. panel.AddContent(toolbar);
  95. NEW(highlight); highlight.caption.SetAOC("Highlight"); AB(toolbar, highlight);
  96. NEW(adhoc); adhoc.caption.SetAOC("AdHoc"); AB(toolbar, adhoc); adhoc.clDefault.Set(0CC0080H);
  97. (* style edit *)
  98. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  99. panel.AddContent(toolbar);
  100. NEW(more); more.caption.SetAOC("More"); AB(toolbar, more); more.clDefault.Set(0CC000080H);
  101. NEW(edit); edit.caption.SetAOC("Edit"); AB(toolbar, edit); edit.clDefault.Set(0CC000080H); edit.visible.Set(FALSE);
  102. (* List *)
  103. NEW(cList); cList.alignment.Set(WMComponents.AlignClient);
  104. cList.onClick.Add(SetStyleFromList); cList.clCell.Set(0FFFFFFCCH); cList.clHover.Set(0FFFF00CCH);
  105. cList.model.Acquire;
  106. cList.model.SetNofCols(1);
  107. cList.model.SetNofRows(1);
  108. cList.SetSelectionMode(WMGrids.GridSelectSingleRow);
  109. cList.model.Release;
  110. panel.AddContent(cList);
  111. winpanel := panel;
  112. RETURN panel
  113. END CreateForm;
  114. PROCEDURE &New*(c : WMRestorable.Context);
  115. VAR vc : WMComponents.VisualComponent;
  116. xml : XML.Element;
  117. s : Strings.String;
  118. temp : BOOLEAN;
  119. BEGIN
  120. IncCount;
  121. vc := CreateForm();
  122. bold.onClick.Add(SetStyle);
  123. lock.onClick.Add(SetStyle);
  124. comment.onClick.Add(SetStyle);
  125. debug.onClick.Add(SetStyle);
  126. stupid.onClick.Add(SetStyle);
  127. assert.onClick.Add(SetStyle);
  128. preferred.onClick.Add(SetStyle);
  129. normal.onClick.Add(SetStyle);
  130. highlight.onClick.Add(SetStyle);
  131. (* adhoc style *)
  132. adhoc.onClick.Add(AdHocStyle);
  133. (* style editor *)
  134. more.onClick.Add(ShowList);
  135. edit.onClick.Add(EditStyles);
  136. link.onClick.Add(AddLink);
  137. label.onClick.Add(AddLabel);
  138. Init(vc.bounds.GetWidth(), vc.bounds.GetHeight(), TRUE);
  139. SetContent(vc);
  140. BuildList;
  141. IF c # NIL THEN
  142. WMRestorable.AddByContext(SELF, c);
  143. IF c.appData # NIL THEN
  144. xml := c.appData(XML.Element);
  145. s := xml.GetAttributeValue("expanded");
  146. IF s # NIL THEN Strings.StrToBool(s^, temp) END;
  147. IF temp THEN
  148. more.caption.SetAOC("Less");
  149. edit.visible.Set(TRUE);
  150. END;
  151. END;
  152. Resized(GetWidth(), GetHeight());
  153. ELSE WM.AddWindow(SELF, 50, 50)
  154. END;
  155. SetTitle(Strings.NewString("Text Styles"))
  156. END New;
  157. (* -- Handlers -- *)
  158. PROCEDURE AdHocStyle(sender, data : ANY);
  159. VAR adhocStyle : AdHocStyleWindow;
  160. BEGIN
  161. NEW(adhocStyle)
  162. END AdHocStyle;
  163. PROCEDURE EditStyles(sender, data: ANY);
  164. BEGIN
  165. IF styleEditor = NIL THEN
  166. NEW(styleEditor);
  167. styleEditor.UpdateProc := BuildList;
  168. END;
  169. styleEditor.Show(200, 150);
  170. END EditStyles;
  171. PROCEDURE ShowList(sender, data: ANY);
  172. VAR caption : Strings.String;
  173. button : WMStandardComponents.Button;
  174. width, height : LONGINT;
  175. BEGIN
  176. button := sender(WMStandardComponents.Button);
  177. caption := button.caption.Get();
  178. manager := WM.GetDefaultManager();
  179. IF caption^ = "More" THEN
  180. button.caption.SetAOC("Less");
  181. width := GetWidth(); height := GetHeight()+ 300;
  182. edit.visible.Set(TRUE);
  183. ELSE
  184. button.caption.SetAOC("More");
  185. width := GetWidth(); height := 140;
  186. edit.visible.Set(FALSE);
  187. END;
  188. manager.SetWindowSize(SELF, width, height); Resized(width, height);
  189. END ShowList;
  190. PROCEDURE BuildList;
  191. VAR styles : Texts.CharacterStyleArray;
  192. i : LONGINT;
  193. BEGIN
  194. styles := Texts.GetCharacterStyleArray();
  195. cList.model.Acquire;
  196. i := 0;
  197. WHILE ((i<LEN(styles)) & (styles[i] # NIL)) DO
  198. cList.model.SetNofRows(i+1);
  199. cList.model.SetCellText(0, i, Strings.NewString(styles[i].name));
  200. cList.model.SetCellData(0, i, styles[i]);
  201. INC(i);
  202. END;
  203. cList.model.Release;
  204. END BuildList;
  205. PROCEDURE SetStyleFromList(sender, data: ANY);
  206. VAR text : Texts.Text;
  207. from, to : Texts.TextPosition;
  208. a, b: LONGINT;
  209. cStyle : Texts.CharacterStyle;
  210. BEGIN
  211. IF (data # NIL ) THEN
  212. cStyle := data(Texts.CharacterStyle);
  213. IF Texts.GetLastSelection(text, from, to) THEN
  214. text.AcquireWrite;
  215. a := MIN(from.GetPosition(), to.GetPosition());
  216. b := MAX(from.GetPosition(), to.GetPosition());
  217. text.SetCharacterStyle(a, b - a, cStyle);
  218. text.ReleaseWrite
  219. END
  220. END;
  221. END SetStyleFromList;
  222. PROCEDURE SetStyle(sender, data : ANY);
  223. VAR text : Texts.Text;
  224. from, to : Texts.TextPosition;
  225. a, b: LONGINT;
  226. cStyle : Texts.CharacterStyle;
  227. BEGIN
  228. IF Texts.GetLastSelection(text, from, to) THEN
  229. IF sender = bold THEN
  230. cStyle := Texts.GetCharacterStyleByName("Bold");
  231. ELSIF sender = lock THEN
  232. cStyle := Texts.GetCharacterStyleByName("Lock");
  233. ELSIF sender = preferred THEN
  234. cStyle := Texts.GetCharacterStyleByName("Preferred");
  235. ELSIF sender = assert THEN
  236. cStyle := Texts.GetCharacterStyleByName("Assertion");
  237. ELSIF sender = comment THEN
  238. cStyle := Texts.GetCharacterStyleByName("Comment");
  239. ELSIF sender = debug THEN
  240. cStyle := Texts.GetCharacterStyleByName("Debug");
  241. ELSIF sender = stupid THEN
  242. cStyle := Texts.GetCharacterStyleByName("Stupid");
  243. ELSIF sender = normal THEN
  244. cStyle := Texts.GetCharacterStyleByName("Normal");
  245. ELSIF sender = highlight THEN
  246. cStyle := Texts.GetCharacterStyleByName("Highlight");
  247. END;
  248. text.AcquireWrite;
  249. a := MIN(from.GetPosition(), to.GetPosition());
  250. b := MAX(from.GetPosition(), to.GetPosition());
  251. text.SetCharacterStyle(a, b - a, cStyle);
  252. text.ReleaseWrite
  253. END
  254. END SetStyle;
  255. PROCEDURE AddLink(sender, data: ANY);
  256. VAR text : Texts.Text;
  257. from, to : Texts.TextPosition;
  258. a, b: LONGINT;
  259. tempLink: ARRAY 2083 OF CHAR;
  260. link : Texts.Link;
  261. BEGIN
  262. IF Texts.GetLastSelection(text, from, to) THEN
  263. IF WMDialogs.QueryString("Enter Link", tempLink) = WMDialogs.ResOk THEN
  264. link := Strings.NewString(tempLink);
  265. text.AcquireWrite;
  266. a := MIN(from.GetPosition(), to.GetPosition());
  267. b := MAX(from.GetPosition(), to.GetPosition());
  268. text.SetLink(a, b - a, link);
  269. text.ReleaseWrite
  270. END
  271. END
  272. END AddLink;
  273. PROCEDURE AddLabel(sender, data: ANY);
  274. VAR text : Texts.Text;
  275. from, to : Texts.TextPosition;
  276. a: LONGINT;
  277. label : ARRAY 256 OF CHAR;
  278. lp : Texts.LabelPiece;
  279. BEGIN
  280. IF Texts.GetLastSelection(text, from, to) THEN
  281. IF WMDialogs.QueryString("Enter Label", label) = WMDialogs.ResOk THEN
  282. NEW(lp); lp.label := Strings.NewString(label);
  283. text.AcquireWrite;
  284. a := MIN(from.GetPosition(), to.GetPosition());
  285. text.InsertPiece(a, lp);
  286. text.ReleaseWrite
  287. END
  288. END
  289. END AddLabel;
  290. PROCEDURE Close*;
  291. BEGIN
  292. IF styleEditor # NIL THEN styleEditor.Close END;
  293. Close^;
  294. DecCount
  295. END Close;
  296. PROCEDURE Handle*(VAR x: WMMessages.Message);
  297. VAR data : XML.Element; a : XML.Attribute; n, str: ARRAY 32 OF CHAR;
  298. BEGIN
  299. IF (x.msgType = WMMessages.MsgExt) & (x.ext # NIL) THEN
  300. IF (x.ext IS KillerMsg) THEN Close
  301. ELSIF (x.ext IS WMRestorable.Storage) THEN
  302. NEW(data); n := "TextStyleToolData"; data.SetName(n);
  303. NEW(a); n := "expanded"; a.SetName(n); Strings.BoolToStr(edit.visible.Get(), str); a.SetValue(str); data.AddAttribute(a);
  304. x.ext(WMRestorable.Storage).Add("WMTextStyleTool", "WMTextStyleTool.Restore", SELF, data)
  305. ELSE Handle^(x)
  306. END
  307. ELSE Handle^(x)
  308. END
  309. END Handle;
  310. END Window;
  311. (* Graphical User Interface to add AdHoc-Styles *)
  312. AdHocStyleWindow* = OBJECT(WMComponents.FormWindow)
  313. VAR
  314. get, apply: WMStandardComponents.Button;
  315. famEdit, sizeEdit, styleEdit, colorEdit, bgColEdit: WMEditors.Editor;
  316. styleB, colB, bgColB : WMStandardComponents.Button;
  317. popup : WMPopups.Popup;
  318. cStyle : Texts.CharacterStyle;
  319. PROCEDURE CreateForm(): WMComponents.VisualComponent;
  320. VAR
  321. label : WMStandardComponents.Label;
  322. panel : WMStandardComponents.Panel;
  323. toolbar: WMStandardComponents.Panel;
  324. manager : WM.WindowManager;
  325. windowStyle : WM.WindowStyle;
  326. PROCEDURE AB(panel : WMStandardComponents.Panel; btn: WMStandardComponents.Button);
  327. BEGIN
  328. btn.alignment.Set(WMComponents.AlignLeft); btn.bounds.SetWidth(60); panel.AddContent(btn)
  329. END AB;
  330. PROCEDURE AL(panel : WMStandardComponents.Panel; lbl : WMStandardComponents.Label);
  331. BEGIN
  332. lbl.alignment.Set(WMComponents.AlignLeft); lbl.bounds.SetWidth(45); label.textColor.Set(0000000FFH);
  333. lbl.fillColor.Set(windowStyle.bgColor); panel.AddContent(lbl)
  334. END AL;
  335. PROCEDURE AE(panel : WMStandardComponents.Panel; edtr : WMEditors.Editor);
  336. BEGIN
  337. edtr.alignment.Set(WMComponents.AlignClient); edtr.multiLine.Set(FALSE); edtr.fillColor.Set(0FFFFFF88H); edtr.tv.showBorder.Set(TRUE);
  338. edtr.tv.textAlignV.Set(WMGraphics.AlignCenter);
  339. edtr.tv.borders.Set(WMRectangles.MakeRect(3,3,1,1)); edtr.tv.defaultTextBgColor.Set(0FFFFFF88H);
  340. panel.AddContent(edtr)
  341. END AE;
  342. PROCEDURE AD(panel : WMStandardComponents.Panel; btn : WMStandardComponents.Button);
  343. BEGIN
  344. btn.alignment.Set(WMComponents.AlignRight); btn.bounds.SetWidth(17); panel.AddContent(btn)
  345. END AD;
  346. BEGIN
  347. NEW(panel); panel.bounds.SetExtents(120, 120); panel.takesFocus.Set(TRUE);
  348. manager := WM.GetDefaultManager();
  349. windowStyle := manager.GetStyle();
  350. (* Get/Apply *)
  351. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  352. panel.AddContent(toolbar);
  353. NEW(get); get.caption.SetAOC("Get"); AB(toolbar, get); get.clDefault.Set(088000088H);
  354. NEW(apply); apply.caption.SetAOC("Apply"); AB(toolbar, apply); apply.clDefault.Set(088000088H);
  355. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  356. panel.AddContent(toolbar);
  357. NEW(label); label.caption.SetAOC(" Font:"); AL(toolbar, label);
  358. NEW(famEdit); famEdit.SetAsString("Oberon"); AE(toolbar, famEdit);
  359. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  360. panel.AddContent(toolbar);
  361. NEW(label); label.caption.SetAOC(" Size:"); AL(toolbar, label);
  362. NEW(sizeEdit); sizeEdit.SetAsString("10"); AE(toolbar, sizeEdit);
  363. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  364. panel.AddContent(toolbar);
  365. NEW(label); label.caption.SetAOC(" Style:"); AL(toolbar, label);
  366. NEW(styleB); styleB.caption.SetAOC("+"); AD(toolbar, styleB);
  367. NEW(styleEdit); styleEdit.SetAsString("Regular"); AE(toolbar, styleEdit);
  368. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  369. panel.AddContent(toolbar);
  370. NEW(label); label.caption.SetAOC(" Color:"); AL(toolbar, label);
  371. NEW(colB); colB.caption.SetAOC("+"); AD(toolbar, colB);
  372. NEW(colorEdit); colorEdit.SetAsString("000000FF"); AE(toolbar, colorEdit);
  373. NEW(toolbar); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  374. panel.AddContent(toolbar);
  375. NEW(label); label.caption.SetAOC(" BGCol:"); AL(toolbar, label);
  376. NEW(bgColB); bgColB.caption.SetAOC("+"); AD(toolbar, bgColB);
  377. NEW(bgColEdit); bgColEdit.SetAsString("00000000"); AE(toolbar, bgColEdit);
  378. RETURN panel
  379. END CreateForm;
  380. PROCEDURE &New*;
  381. VAR vc : WMComponents.VisualComponent;
  382. BEGIN
  383. vc := CreateForm();
  384. get.onClick.Add(GetStyle);
  385. apply.onClick.Add(SetCustomStyle);
  386. styleB.SetExtPointerDownHandler(StyleDrop);
  387. colB.SetExtPointerDownHandler(ColorHandler);
  388. bgColB.SetExtPointerDownHandler(BGColorHandler);
  389. Init(vc.bounds.GetWidth(), vc.bounds.GetHeight(), TRUE);
  390. SetContent(vc);
  391. WM.ExtAddWindow(SELF, 50, 50, {WM.FlagStayOnTop, WM.FlagFrame, WM.FlagClose, WM.FlagMinimize});
  392. SetTitle(Strings.NewString("AdHoc Text Styles"))
  393. END New;
  394. PROCEDURE GetStyle(sender, data : ANY);
  395. VAR text : Texts.Text; from, to : Texts.TextPosition;
  396. utilreader : Texts.TextReader; tempString : ARRAY 256 OF CHAR;
  397. a, b, ch, temp : LONGINT;
  398. BEGIN
  399. IF Texts.GetLastSelection(text, from, to) THEN
  400. text.AcquireWrite;
  401. a := MIN(from.GetPosition(), to.GetPosition());
  402. b := MAX(from.GetPosition(), to.GetPosition());
  403. NEW(utilreader, text);
  404. utilreader.SetPosition(a);
  405. utilreader.ReadCh(ch);
  406. IF (utilreader.cstyle = NIL) & (utilreader.attributes = NIL) THEN
  407. famEdit.SetAsString("Oberon");
  408. sizeEdit.SetAsString("10");
  409. styleEdit.SetAsString("regular");
  410. colorEdit.SetAsString("000000FF");
  411. bgColEdit.SetAsString("00000000");
  412. ELSIF (utilreader.cstyle # NIL) THEN
  413. cStyle := utilreader.cstyle;
  414. famEdit.SetAsString(cStyle.family);
  415. temp := ENTIER(FP1616.FixpToFloat(cStyle.size));
  416. Strings.IntToStr(temp, tempString);
  417. sizeEdit.SetAsString(tempString);
  418. IF cStyle.style = {} THEN
  419. styleEdit.SetAsString("Regular");
  420. ELSIF cStyle.style = {0} THEN
  421. styleEdit.SetAsString("Bold");
  422. ELSIF cStyle.style = {1} THEN
  423. styleEdit.SetAsString("Italic");
  424. ELSIF cStyle.style = {0,1} THEN
  425. styleEdit.SetAsString("Bold Italic");
  426. ELSE
  427. styleEdit.SetAsString("Regular");
  428. END;
  429. Strings.IntToHexStr(cStyle.color, 7, tempString);
  430. colorEdit.SetAsString(tempString);
  431. Strings.IntToHexStr(cStyle.bgColor, 7, tempString);
  432. bgColEdit.SetAsString(tempString);
  433. ELSIF (utilreader.attributes # NIL) THEN
  434. famEdit.SetAsString(utilreader.attributes.fontInfo.name);
  435. Strings.IntToStr(utilreader.attributes.fontInfo.size, tempString);
  436. sizeEdit.SetAsString(tempString);
  437. IF utilreader.attributes.fontInfo.style = {} THEN
  438. styleEdit.SetAsString("Regular");
  439. ELSIF utilreader.attributes.fontInfo.style = {0} THEN
  440. styleEdit.SetAsString("Bold");
  441. ELSIF utilreader.attributes.fontInfo.style = {1} THEN
  442. styleEdit.SetAsString("Italic");
  443. ELSIF utilreader.attributes.fontInfo.style = {0,1} THEN
  444. styleEdit.SetAsString("Bold Italic");
  445. ELSE
  446. styleEdit.SetAsString("Regular");
  447. END;
  448. Strings.IntToHexStr(utilreader.attributes.color, 7, tempString);
  449. colorEdit.SetAsString(tempString);
  450. Strings.IntToHexStr(utilreader.attributes.bgcolor, 7, tempString);
  451. bgColEdit.SetAsString(tempString);
  452. END;
  453. text.ReleaseWrite
  454. END;
  455. END GetStyle;
  456. PROCEDURE SetCustomStyle(sender, data: ANY);
  457. VAR text : Texts.Text;
  458. from, to : Texts.TextPosition;
  459. cStyle : Texts.CharacterStyle;
  460. a, b: LONGINT;
  461. style : SET;
  462. fgColor, bgColor : LONGINT;
  463. name, tempString: ARRAY 256 OF CHAR;
  464. res: WORD; size : LONGINT;
  465. BEGIN
  466. IF Texts.GetLastSelection(text, from, to) THEN
  467. (* create new AdHoc Style *)
  468. NEW(cStyle);
  469. famEdit.GetAsString(name);
  470. COPY(name, cStyle.family);
  471. sizeEdit.GetAsString(tempString);
  472. Strings.StrToInt(tempString, size);
  473. size := FP1616.FloatToFixp(size);
  474. cStyle.size := size;
  475. styleEdit.GetAsString(tempString);
  476. IF tempString = "Regular" THEN style := {};
  477. ELSIF tempString = "Bold" THEN style := {0};
  478. ELSIF tempString = "Italic" THEN style := {1};
  479. ELSIF tempString = "Bold Italic" THEN style := {0, 1};
  480. ELSE
  481. style := {};
  482. END;
  483. cStyle.style := style;
  484. colorEdit.GetAsString(tempString);
  485. Strings.HexStrToInt(tempString, fgColor, res);
  486. cStyle.color := fgColor;
  487. bgColEdit.GetAsString(tempString);
  488. Strings.HexStrToInt(tempString, bgColor, res);
  489. cStyle.bgColor := bgColor;
  490. (* create AdHoc Name *)
  491. size := ENTIER(FP1616.FixpToFloat(size));
  492. CreateStyleName(name, style, size, fgColor, bgColor, cStyle.name);
  493. (* Set the style *)
  494. text.AcquireWrite;
  495. a := MIN(from.GetPosition(), to.GetPosition());
  496. b := MAX(from.GetPosition(), to.GetPosition());
  497. text.SetCharacterStyle(a, b - a, cStyle);
  498. text.ReleaseWrite
  499. END
  500. END SetCustomStyle;
  501. PROCEDURE StyleDrop(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  502. BEGIN
  503. NEW(popup);
  504. popup.Add("Regular", StylePopupHandler);
  505. popup.Add("Bold", StylePopupHandler);
  506. popup.Add("Italic", StylePopupHandler);
  507. popup.Add("Bold Italic", StylePopupHandler);
  508. handled := TRUE;
  509. popup.Popup(bounds.r-100, bounds.t+80);
  510. END StyleDrop;
  511. PROCEDURE StylePopupHandler(sender, data: ANY);
  512. VAR button: WMStandardComponents.Button;
  513. tempString: Strings.String;
  514. BEGIN
  515. popup.Close;
  516. IF sender IS WMStandardComponents.Button THEN
  517. button := sender(WMStandardComponents.Button);
  518. tempString := button.caption.Get();
  519. IF (tempString^ = "Regular") THEN
  520. styleEdit.SetAsString("Regular");
  521. ELSIF (tempString^ = "Bold") THEN
  522. styleEdit.SetAsString("Bold");
  523. ELSIF (tempString^ = "Italic") THEN
  524. styleEdit.SetAsString("Italic");
  525. ELSIF (tempString^ = "Bold Italic") THEN
  526. styleEdit.SetAsString("Bold Italic");
  527. ELSE
  528. styleEdit.SetAsString("Regular");
  529. END;
  530. END;
  531. END StylePopupHandler;
  532. PROCEDURE ColorHandler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  533. VAR colorPanel : WMPopups.ColorSwatchPopup;
  534. BEGIN
  535. NEW(colorPanel);
  536. colorPanel.onColorChosen := ColorPopupHandler;
  537. colorPanel.Popup(bounds.r-190, bounds.t+100);
  538. handled := TRUE;
  539. END ColorHandler;
  540. PROCEDURE ColorPopupHandler(result: WMGraphics.Color);
  541. VAR
  542. colorString: ARRAY 16 OF CHAR;
  543. BEGIN
  544. Strings.IntToHexStr(result, 7, colorString);
  545. colorEdit.SetAsString(colorString);
  546. END ColorPopupHandler;
  547. PROCEDURE BGColorHandler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  548. VAR colorPanel: WMPopups.ColorSwatchPopup;
  549. BEGIN
  550. NEW(colorPanel);
  551. colorPanel.onColorChosen := BGColorPopupHandler;
  552. colorPanel.Popup(bounds.r-190, bounds.t+220);
  553. handled := TRUE;
  554. END BGColorHandler;
  555. PROCEDURE BGColorPopupHandler(result: WMGraphics.Color);
  556. VAR
  557. colorString: ARRAY 16 OF CHAR;
  558. BEGIN
  559. Strings.IntToHexStr(result, 7, colorString);
  560. bgColEdit.SetAsString(colorString);
  561. END BGColorPopupHandler;
  562. PROCEDURE Close*;
  563. BEGIN
  564. Close^;
  565. END Close;
  566. END AdHocStyleWindow;
  567. (* Graphical User Interface to create & edit Text Styles *)
  568. StyleEditor* = OBJECT(WMComponents.FormWindow)
  569. VAR
  570. shown : BOOLEAN; popup: WMPopups.Popup;
  571. oldPStyleName, oldCStyleName: ARRAY 256 OF CHAR;
  572. tabColor, tabSelectedColor : LONGINT;
  573. previewLabel, fontNotFound : WMStandardComponents.Label;
  574. tabPanel, buttonPanel, pstylePanel, cstylePanel : WMStandardComponents.Panel;
  575. pstyleButton, cstyleButton, button : WMStandardComponents.Button;
  576. pName, pAlign, pFirstIndent, pLeftIndent, pRightIndent, pSpaceBefore, pSpaceAfter, pDefCharStyle,
  577. cName, cFont, cSize, cStyle, cBaselineShift, cLeading, cColor, cBackColor, cTracking, cStretchH, cStretchV: WMEditors.Editor;
  578. pList, cList: WMStringGrids.StringGrid;
  579. UpdateProc* : PROCEDURE {DELEGATE};
  580. currentPStyle, tempPStyle : Texts.ParagraphStyle;
  581. currentCStyle, tempCStyle : Texts.CharacterStyle;
  582. pStyles: Texts.ParagraphStyleArray;
  583. cStyles: Texts.CharacterStyleArray;
  584. vc : WMComponents.VisualComponent;
  585. PROCEDURE CreateForm() : WMComponents.VisualComponent;
  586. VAR panel, mainPanel, gridPanel, propertyPanel : WMStandardComponents.Panel;
  587. groupPanel : WMStandardComponents.GroupPanel;
  588. label : WMStandardComponents.Label;
  589. labelWidth : LONGINT;
  590. resizerH: WMStandardComponents.Resizer;
  591. manager : WM.WindowManager;
  592. windowStyle : WM.WindowStyle;
  593. PROCEDURE CreateEditor(): WMEditors.Editor;
  594. VAR editor: WMEditors.Editor;
  595. BEGIN
  596. NEW(editor); editor.alignment.Set(WMComponents.AlignClient);
  597. editor.multiLine.Set(FALSE); editor.fillColor.Set(0FFFFFFFFH); editor.tv.showBorder.Set(TRUE);
  598. editor.tv.textAlignV.Set(WMGraphics.AlignCenter);
  599. editor.tv.borders.Set(WMRectangles.MakeRect(3,3,1,1)); editor.onEnter.Add(UpdateValueHandler);
  600. RETURN editor
  601. END CreateEditor;
  602. PROCEDURE CreateLabel(CONST caption : ARRAY OF CHAR): WMStandardComponents.Label;
  603. VAR label: WMStandardComponents.Label;
  604. BEGIN
  605. NEW(label); label.bounds.SetWidth(labelWidth); label.caption.SetAOC(caption);
  606. label.alignment.Set(WMComponents.AlignLeft);
  607. RETURN label
  608. END CreateLabel;
  609. BEGIN
  610. labelWidth := 130;
  611. tabColor := 0008000FFH;
  612. tabSelectedColor := 000CC00FFH;
  613. manager := WM.GetDefaultManager();
  614. windowStyle := manager.GetStyle();
  615. NEW(mainPanel); mainPanel.bounds.SetExtents(500, 420); mainPanel.fillColor.Set(windowStyle.bgColor);
  616. mainPanel.takesFocus.Set(TRUE);
  617. (* -- tabs -- *)
  618. NEW(tabPanel); tabPanel.bounds.SetHeight(20); tabPanel.fillColor.Set(0CCCCCCFFH);
  619. tabPanel.alignment.Set(WMComponents.AlignTop);
  620. NEW(pstyleButton); pstyleButton.caption.SetAOC("Paragraph"); pstyleButton.alignment.Set(WMComponents.AlignLeft);
  621. pstyleButton.onClick.Add(TabHandler); pstyleButton.clDefault.Set(tabSelectedColor);
  622. NEW(cstyleButton); cstyleButton.caption.SetAOC("Character"); cstyleButton.alignment.Set(WMComponents.AlignLeft);
  623. cstyleButton.onClick.Add(TabHandler); cstyleButton.clDefault.Set(tabColor);
  624. (* tabPanel.AddContent(pstyleButton); *)
  625. (* tabPanel.AddContent(cstyleButton); *)
  626. mainPanel.AddContent(tabPanel);
  627. (* -- paragraph style -- *)
  628. NEW(pstylePanel); pstylePanel.alignment.Set(WMComponents.AlignClient);
  629. pstylePanel.visible.Set(FALSE);
  630. mainPanel.AddContent(pstylePanel);
  631. NEW(gridPanel); gridPanel.alignment.Set(WMComponents.AlignClient);
  632. gridPanel.fillColor.Set(0FFFFFFFFH);
  633. NEW(pList); pList.alignment.Set(WMComponents.AlignClient);
  634. pList.onClick.Add(PClickSelected);
  635. pList.model.Acquire;
  636. pList.model.SetNofCols(1);
  637. pList.model.SetNofRows(1);
  638. pList.SetSelectionMode(WMGrids.GridSelectSingleRow);
  639. pList.model.Release;
  640. gridPanel.AddContent(pList);
  641. pstylePanel.AddContent(gridPanel);
  642. NEW(propertyPanel); propertyPanel.alignment.Set(WMComponents.AlignClient);
  643. pstylePanel.AddContent(propertyPanel);
  644. NEW(label); label.bounds.SetHeight(13); label.alignment.Set(WMComponents.AlignTop);
  645. propertyPanel.AddContent(label);
  646. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  647. label := CreateLabel(" Paragraph Style Name:"); panel.AddContent(label);
  648. pName := CreateEditor(); panel.AddContent(pName);
  649. propertyPanel.AddContent(panel);
  650. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  651. label := CreateLabel(" Alignment:"); panel.AddContent(label);
  652. NEW(button); button.caption.SetAOC("+"); button.alignment.Set(WMComponents.AlignRight);
  653. button.SetExtPointerDownHandler(AlignHandler); button.bounds.SetWidth(20); panel.AddContent(button);
  654. pAlign := CreateEditor(); panel.AddContent(pAlign);
  655. propertyPanel.AddContent(panel);
  656. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  657. label := CreateLabel(" First Line Indent:"); panel.AddContent(label);
  658. pFirstIndent := CreateEditor(); panel.AddContent(pFirstIndent);
  659. propertyPanel.AddContent(panel);
  660. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  661. label := CreateLabel(" Left Line Indent:"); panel.AddContent(label);
  662. pLeftIndent := CreateEditor(); panel.AddContent(pLeftIndent);
  663. propertyPanel.AddContent(panel);
  664. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  665. label := CreateLabel(" Right Line Indent:"); panel.AddContent(label);
  666. pRightIndent := CreateEditor(); panel.AddContent(pRightIndent);
  667. propertyPanel.AddContent(panel);
  668. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  669. label := CreateLabel(" Space Before:"); panel.AddContent(label);
  670. pSpaceBefore := CreateEditor(); panel.AddContent(pSpaceBefore);
  671. propertyPanel.AddContent(panel);
  672. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  673. label := CreateLabel(" Space After:"); panel.AddContent(label);
  674. pSpaceAfter := CreateEditor(); panel.AddContent(pSpaceAfter);
  675. propertyPanel.AddContent(panel);
  676. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  677. label := CreateLabel(" Default Char Style:"); panel.AddContent(label);
  678. pSpaceAfter := CreateEditor(); panel.AddContent(pSpaceAfter);
  679. propertyPanel.AddContent(panel);
  680. (* -- paragraph panel buttons -- *)
  681. NEW(buttonPanel); buttonPanel.bounds.SetHeight(20); buttonPanel.fillColor.Set(08888FFFFH);
  682. buttonPanel.alignment.Set(WMComponents.AlignBottom);
  683. NEW(button); button.caption.SetAOC("Apply"); button.alignment.Set(WMComponents.AlignRight);
  684. button.onClick.Add(ApplyPHandler);
  685. buttonPanel.AddContent(button);
  686. NEW(button); button.caption.SetAOC("Delete"); button.alignment.Set(WMComponents.AlignRight);
  687. button.onClick.Add(RemovePHandler);
  688. buttonPanel.AddContent(button);
  689. NEW(button); button.caption.SetAOC("Import"); button.alignment.Set(WMComponents.AlignRight);
  690. button.onClick.Add(ImportPHandler);
  691. buttonPanel.AddContent(button);
  692. NEW(button); button.caption.SetAOC("New"); button.alignment.Set(WMComponents.AlignRight);
  693. button.onClick.Add(NewPHandler);
  694. buttonPanel.AddContent(button);
  695. propertyPanel.AddContent(buttonPanel);
  696. (* -- character style -- *)
  697. NEW(cstylePanel); cstylePanel.alignment.Set(WMComponents.AlignClient);
  698. cstylePanel.visible.Set(TRUE);
  699. mainPanel.AddContent(cstylePanel);
  700. NEW(gridPanel); gridPanel.bounds.SetWidth(200); gridPanel.alignment.Set(WMComponents.AlignLeft);
  701. gridPanel.fillColor.Set(0FFFFFFFFH);
  702. NEW(cList); cList.alignment.Set(WMComponents.AlignClient);
  703. cList.onClick.Add(CClickSelected);
  704. cList.model.Acquire;
  705. cList.model.SetNofCols(1);
  706. cList.model.SetNofRows(1);
  707. cList.SetSelectionMode(WMGrids.GridSelectSingleRow);
  708. cList.model.Release;
  709. NEW(resizerH); resizerH.alignment.Set(WMComponents.AlignRight);
  710. resizerH.bounds.SetWidth(4);
  711. gridPanel.AddContent(resizerH);
  712. gridPanel.AddContent(cList);
  713. cstylePanel.AddContent(gridPanel);
  714. NEW(propertyPanel); propertyPanel.alignment.Set(WMComponents.AlignClient);
  715. cstylePanel.AddContent(propertyPanel);
  716. NEW(label); label.bounds.SetHeight(13); label.alignment.Set(WMComponents.AlignTop);
  717. propertyPanel.AddContent(label);
  718. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  719. label := CreateLabel(" Character Style Name:"); panel.AddContent(label);
  720. cName := CreateEditor(); panel.AddContent(cName);
  721. propertyPanel.AddContent(panel);
  722. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  723. label := CreateLabel(" Font Name:"); panel.AddContent(label);
  724. cFont := CreateEditor(); panel.AddContent(cFont);
  725. propertyPanel.AddContent(panel);
  726. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  727. label := CreateLabel(" Font Style:"); panel.AddContent(label);
  728. NEW(button); button.caption.SetAOC("+"); button.alignment.Set(WMComponents.AlignRight);
  729. button.SetExtPointerDownHandler(StyleHandler); button.bounds.SetWidth(20); panel.AddContent(button);
  730. cStyle := CreateEditor(); panel.AddContent(cStyle);
  731. propertyPanel.AddContent(panel);
  732. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  733. label := CreateLabel(" Font Size:"); panel.AddContent(label);
  734. cSize := CreateEditor(); panel.AddContent(cSize);
  735. propertyPanel.AddContent(panel);
  736. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  737. label := CreateLabel(" Leading:"); panel.AddContent(label);
  738. cLeading := CreateEditor(); panel.AddContent(cLeading);
  739. propertyPanel.AddContent(panel);
  740. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  741. label := CreateLabel(" Baseline Shift:"); panel.AddContent(label);
  742. cBaselineShift := CreateEditor(); panel.AddContent(cBaselineShift);
  743. propertyPanel.AddContent(panel);
  744. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  745. label := CreateLabel(" Font Color:"); panel.AddContent(label);
  746. NEW(button); button.caption.SetAOC("+"); button.alignment.Set(WMComponents.AlignRight);
  747. button.SetExtPointerDownHandler(ColorHandler); button.bounds.SetWidth(20); panel.AddContent(button);
  748. cColor := CreateEditor(); panel.AddContent(cColor);
  749. propertyPanel.AddContent(panel);
  750. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  751. label := CreateLabel(" Font BG Color:"); panel.AddContent(label);
  752. NEW(button); button.caption.SetAOC("+"); button.alignment.Set(WMComponents.AlignRight);
  753. button.SetExtPointerDownHandler(BGColorHandler); button.bounds.SetWidth(20); panel.AddContent(button);
  754. cBackColor := CreateEditor(); panel.AddContent(cBackColor);
  755. propertyPanel.AddContent(panel);
  756. (* --- not used yet ---> *)
  757. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  758. label := CreateLabel(" Tracking:"); panel.AddContent(label);
  759. cTracking := CreateEditor(); panel.AddContent(cTracking);
  760. (* propertyPanel.AddContent(panel); *)
  761. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  762. label := CreateLabel(" Stretch Horizontal:"); panel.AddContent(label);
  763. cStretchH := CreateEditor(); panel.AddContent(cStretchH);
  764. (* propertyPanel.AddContent(panel); *)
  765. NEW(panel); panel.bounds.SetHeight(20); panel.alignment.Set(WMComponents.AlignTop);
  766. label := CreateLabel(" Stretch Vertical:"); panel.AddContent(label);
  767. cStretchV := CreateEditor(); panel.AddContent(cStretchV);
  768. (* propertyPanel.AddContent(panel); *)
  769. (* <---------------- *)
  770. (* preview panel *)
  771. NEW(panel); panel.bounds.SetHeight(15); panel.alignment.Set(WMComponents.AlignTop); propertyPanel.AddContent(panel);
  772. NEW(groupPanel); groupPanel.alignment.Set(WMComponents.AlignTop); groupPanel.caption.SetAOC("Preview:"); groupPanel.bounds.SetHeight(80);
  773. NEW(previewLabel); previewLabel.fillColor.Set(0FFFFFFFFH); previewLabel.alignment.Set(WMComponents.AlignClient);
  774. previewLabel.caption.SetAOC("The quick brown Fox jumped over the lazy Dog"); previewLabel.alignH.Set(1); previewLabel.alignV.Set(1);
  775. groupPanel.AddContent(previewLabel); propertyPanel.AddContent(groupPanel);
  776. NEW(fontNotFound); fontNotFound.bounds.SetHeight(20); fontNotFound.alignment.Set(WMComponents.AlignTop);
  777. fontNotFound.caption.SetAOC(" ERROR: Font not found! - using DefaultFont"); fontNotFound.visible.Set(FALSE);
  778. propertyPanel.AddContent(fontNotFound); fontNotFound.textColor.Set(0FF0000FFH);
  779. (* -- character style buttons -- *)
  780. NEW(buttonPanel); buttonPanel.bounds.SetHeight(20); buttonPanel.fillColor.Set(windowStyle.bgColor);
  781. buttonPanel.alignment.Set(WMComponents.AlignBottom);
  782. NEW(button); button.caption.SetAOC("Apply"); button.alignment.Set(WMComponents.AlignRight);
  783. button.onClick.Add(ApplyCHandler);
  784. buttonPanel.AddContent(button);
  785. NEW(button); button.caption.SetAOC("Delete"); button.alignment.Set(WMComponents.AlignRight);
  786. button.onClick.Add(RemoveCHandler);
  787. buttonPanel.AddContent(button);
  788. NEW(button); button.caption.SetAOC("Export"); button.alignment.Set(WMComponents.AlignRight);
  789. button.onClick.Add(ExportCHandler);
  790. buttonPanel.AddContent(button);
  791. NEW(button); button.caption.SetAOC("Import"); button.alignment.Set(WMComponents.AlignRight);
  792. button.onClick.Add(ImportCHandler);
  793. buttonPanel.AddContent(button);
  794. NEW(button); button.caption.SetAOC("New"); button.alignment.Set(WMComponents.AlignRight);
  795. button.onClick.Add(NewCHandler);
  796. buttonPanel.AddContent(button);
  797. propertyPanel.AddContent(buttonPanel);
  798. RETURN mainPanel;
  799. END CreateForm;
  800. PROCEDURE &New*;
  801. VAR
  802. BEGIN
  803. vc := CreateForm();
  804. Init(vc.bounds.GetWidth(), vc.bounds.GetHeight(), FALSE);
  805. SetContent(vc);
  806. SetTitle(Strings.NewString("Style Editor"));
  807. pStyles := Texts.GetParagraphStyleArray();
  808. cStyles := Texts.GetCharacterStyleArray();
  809. END New;
  810. PROCEDURE Show*(x, y: LONGINT);
  811. BEGIN
  812. LoadStyleList;
  813. IF ~shown THEN shown := TRUE;
  814. ELSE Hide; shown := TRUE; END;
  815. manager := WM.GetDefaultManager();
  816. WM.AddWindow(SELF, x, y);
  817. manager.SetFocus(SELF);
  818. cList.SetSelection(0,0,0,0)
  819. END Show;
  820. PROCEDURE Hide*;
  821. BEGIN
  822. IF shown THEN
  823. shown := FALSE;
  824. manager := WM.GetDefaultManager();
  825. manager.Remove(SELF);
  826. END;
  827. END Hide;
  828. PROCEDURE Close*;
  829. BEGIN
  830. Close^;
  831. IF UpdateProc # NIL THEN UpdateProc END;
  832. shown := FALSE;
  833. END Close;
  834. PROCEDURE LoadStyleList;
  835. VAR i : LONGINT;
  836. BEGIN
  837. vc.Acquire;
  838. pList.model.Acquire;
  839. i := 0;
  840. WHILE ((i<LEN(pStyles)) & (pStyles[i] # NIL)) DO
  841. pList.model.SetNofRows(i+1);
  842. pList.model.SetCellText(0, i, Strings.NewString(pStyles[i].name));
  843. pList.model.SetCellData(0, i, pStyles[i]);
  844. INC(i);
  845. END;
  846. pList.model.Release;
  847. cList.model.Acquire;
  848. i := 0;
  849. WHILE ((i<LEN(cStyles)) & (cStyles[i] # NIL)) DO
  850. cList.model.SetNofRows(i+1);
  851. cList.model.SetCellText(0, i, Strings.NewString(cStyles[i].name));
  852. cList.model.SetCellData(0, i, cStyles[i]);
  853. INC(i);
  854. END;
  855. IF i > 0 THEN CClickSelected(NIL, cList.model.GetCellData(0, 0)); END;
  856. cList.model.Release;
  857. vc.Release;
  858. END LoadStyleList;
  859. PROCEDURE TabHandler(sender, data: ANY);
  860. BEGIN
  861. IF (sender # NIL) & (sender IS WMStandardComponents.Button) THEN
  862. IF sender = pstyleButton THEN
  863. cstylePanel.visible.Set(FALSE); cstyleButton.clDefault.Set(tabColor);
  864. pstylePanel.visible.Set(TRUE); pstyleButton.clDefault.Set(tabSelectedColor);
  865. ELSIF sender = cstyleButton THEN
  866. pstylePanel.visible.Set(FALSE); pstyleButton.clDefault.Set(tabColor);
  867. cstylePanel.visible.Set(TRUE); cstyleButton.clDefault.Set(tabSelectedColor);
  868. ELSE
  869. END;
  870. END;
  871. END TabHandler;
  872. PROCEDURE PClickSelected(sender, data: ANY);
  873. VAR tempString: ARRAY 64 OF CHAR;
  874. BEGIN
  875. IF (data # NIL) THEN
  876. currentPStyle := data(Texts.ParagraphStyle);
  877. tempPStyle := currentPStyle.Clone();
  878. pName.SetAsString(currentPStyle.name);
  879. IF (currentPStyle.alignment = 0) THEN tempString := "Left";
  880. ELSIF (currentPStyle.alignment = 1) THEN tempString := "Center";
  881. ELSIF (currentPStyle.alignment = 2) THEN tempString := "Right";
  882. ELSE tempString := "Justified";
  883. END;
  884. pAlign.SetAsString(tempString);
  885. Strings.FloatToStr(currentPStyle.firstIndent, 0,4,0, tempString);
  886. pFirstIndent.SetAsString(tempString);
  887. Strings.FloatToStr(currentPStyle.leftIndent, 0,4,0, tempString);
  888. pLeftIndent.SetAsString(tempString);
  889. Strings.FloatToStr(currentPStyle.rightIndent, 0,4,0, tempString);
  890. pRightIndent.SetAsString(tempString);
  891. Strings.FloatToStr(currentPStyle.spaceBefore, 0,4,0, tempString);
  892. pSpaceBefore.SetAsString(tempString);
  893. Strings.FloatToStr(currentPStyle.spaceAfter, 0,4,0, tempString);
  894. pSpaceAfter.SetAsString(tempString);
  895. pDefCharStyle.SetAsString(currentPStyle.charStyle.name);
  896. COPY(currentPStyle.name, oldPStyleName);
  897. END;
  898. END PClickSelected;
  899. PROCEDURE CClickSelected(sender, data: ANY);
  900. VAR tempString: ARRAY 64 OF CHAR;
  901. tempFont: WMGraphics.Font;
  902. BEGIN
  903. IF (data # NIL) THEN
  904. currentCStyle := data(Texts.CharacterStyle);
  905. tempCStyle := currentCStyle.Clone();
  906. cName.SetAsString(currentCStyle.name);
  907. cFont.SetAsString(currentCStyle.family);
  908. IF (currentCStyle.style * {0, 1} = {}) THEN
  909. tempString := "Regular";
  910. ELSIF (currentCStyle.style * {0, 1} = {0}) THEN
  911. tempString := "Bold";
  912. ELSIF (currentCStyle.style * {0, 1} = {1}) THEN
  913. tempString := "Italic";
  914. ELSE
  915. tempString := "Bold Italic";
  916. END;
  917. cStyle.SetAsString(tempString);
  918. Strings.FloatToStr(FP1616.FixpToFloat(currentCStyle.size), 0,4,0, tempString);
  919. cSize.SetAsString(tempString);
  920. Strings.FloatToStr(FP1616.FixpToFloat(currentCStyle.leading), 0,4,0, tempString);
  921. cLeading.SetAsString(tempString);
  922. Strings.FloatToStr(currentCStyle.baselineShift, 0,4,0, tempString);
  923. cBaselineShift.SetAsString(tempString);
  924. Strings.IntToHexStr(currentCStyle.color, 7, tempString);
  925. cColor.SetAsString(tempString);
  926. Strings.IntToHexStr(currentCStyle.bgColor, 7, tempString);
  927. cBackColor.SetAsString(tempString);
  928. Strings.FloatToStr(FP1616.FixpToFloat(currentCStyle.tracking), 0,4,0, tempString);
  929. cTracking.SetAsString(tempString);
  930. Strings.FloatToStr(FP1616.FixpToFloat(currentCStyle.scaleHorizontal), 0,4,0, tempString);
  931. cStretchH.SetAsString(tempString);
  932. Strings.FloatToStr(FP1616.FixpToFloat(currentCStyle.scaleVertical), 0,4,0, tempString);
  933. cStretchV.SetAsString(tempString);
  934. COPY(currentCStyle.name, oldCStyleName);
  935. (* update preview *)
  936. tempFont := WMGraphics.GetFont(tempCStyle.family, ENTIER(FP1616.FixpToFloat(tempCStyle.size)), tempCStyle.style);
  937. previewLabel.SetFont(tempFont); previewLabel.fillColor.Set(tempCStyle.bgColor);
  938. previewLabel.textColor.Set(tempCStyle.color); previewLabel.Invalidate;
  939. END;
  940. END CClickSelected;
  941. PROCEDURE UpdateValueHandler(sender, data: ANY);
  942. VAR tempString : ARRAY 64 OF CHAR;
  943. tempLReal : LONGREAL;
  944. tempInt : LONGINT; res : WORD;
  945. tempCharStyle : Texts.CharacterStyle;
  946. tempFont : WMGraphics.Font;
  947. tempEditor : WMEditors.Editor;
  948. BEGIN
  949. (* paragraph style *)
  950. IF sender IS WMEditors.Editor THEN
  951. tempEditor := sender(WMEditors.Editor);
  952. tempEditor.GetAsString(tempString);
  953. END;
  954. IF (tempEditor = pName) THEN
  955. COPY(tempString, tempPStyle.name);
  956. ELSIF (tempEditor = pAlign) THEN
  957. Strings.LowerCase(tempString);
  958. IF (tempString = "left") THEN tempPStyle.alignment := 0; pAlign.SetAsString("Left");
  959. ELSIF (tempString = "center") THEN tempPStyle.alignment := 1; pAlign.SetAsString("Center");
  960. ELSIF (tempString = "right") THEN tempPStyle.alignment := 2; pAlign.SetAsString("Right");
  961. ELSIF (tempString = "justified") THEN tempPStyle.alignment := 3; pAlign.SetAsString("Justified");
  962. ELSE tempPStyle.alignment := 0; pAlign.SetAsString("Left"); END;
  963. ELSIF (tempEditor = pFirstIndent) THEN
  964. Strings.StrToFloat(tempString, tempLReal);
  965. tempPStyle.firstIndent := FP1616.FloatToFixp(SHORT(tempLReal));
  966. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  967. pFirstIndent.SetAsString(tempString);
  968. ELSIF (tempEditor = pLeftIndent) THEN
  969. Strings.StrToFloat(tempString, tempLReal);
  970. tempPStyle.leftIndent := FP1616.FloatToFixp(SHORT(tempLReal));
  971. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  972. pLeftIndent.SetAsString(tempString);
  973. ELSIF (tempEditor = pRightIndent) THEN
  974. Strings.StrToFloat(tempString, tempLReal);
  975. tempPStyle.rightIndent := FP1616.FloatToFixp(SHORT(tempLReal));
  976. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  977. pRightIndent.SetAsString(tempString);
  978. ELSIF (tempEditor = pSpaceBefore) THEN
  979. Strings.StrToFloat(tempString, tempLReal);
  980. tempPStyle.spaceBefore := FP1616.FloatToFixp(SHORT(tempLReal));
  981. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  982. pSpaceBefore.SetAsString(tempString);
  983. ELSIF (tempEditor = pSpaceAfter) THEN
  984. Strings.StrToFloat(tempString, tempLReal);
  985. tempPStyle.spaceAfter := FP1616.FloatToFixp(SHORT(tempLReal));
  986. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  987. pSpaceAfter.SetAsString(tempString);
  988. ELSIF (tempEditor = pDefCharStyle) THEN
  989. tempCharStyle := Texts.GetCharacterStyleByName(tempString);
  990. IF tempCharStyle # NIL THEN
  991. tempPStyle.charStyle := tempCharStyle;
  992. ELSE
  993. tempPStyle.charStyle := Texts.GetCharacterStyleByName("Normal");
  994. pDefCharStyle.SetAsString(tempPStyle.charStyle.name);
  995. END;
  996. (* character style *)
  997. ELSIF (tempEditor = cName) THEN
  998. COPY(tempString, tempCStyle.name);
  999. ELSIF (tempEditor = cFont) THEN
  1000. COPY(tempString, tempCStyle.family);
  1001. (* load font *)
  1002. tempFont := WMGraphics.GetFont(tempCStyle.family, ENTIER(FP1616.FixpToFloat(tempCStyle.size)), tempCStyle.style);
  1003. previewLabel.SetFont(tempFont); previewLabel.Invalidate;
  1004. IF (tempFont.name # tempCStyle.family) OR (tempFont.size # ENTIER(FP1616.FixpToFloat(tempCStyle.size))) THEN (* OR (tempFont.style # tempCStyle.style) *)
  1005. fontNotFound.visible.Set(TRUE);
  1006. ELSE
  1007. fontNotFound.visible.Set(FALSE);
  1008. END;
  1009. ELSIF (tempEditor = cStyle) THEN
  1010. Strings.LowerCase(tempString);
  1011. IF (tempString = "regular") THEN tempCStyle.style := {}; cStyle.SetAsString("Regular");
  1012. ELSIF (tempString = "bold") THEN tempCStyle.style := {0}; cStyle.SetAsString("Bold");
  1013. ELSIF (tempString = "italic") THEN tempCStyle.style := {1}; cStyle.SetAsString("Italic");
  1014. ELSIF (tempString = "bold italic") THEN tempCStyle.style := {0, 1}; cStyle.SetAsString("Bold Italic");
  1015. ELSE tempCStyle.style := {}; cStyle.SetAsString("Regular"); END;
  1016. tempFont := WMGraphics.GetFont(tempCStyle.family, ENTIER(FP1616.FixpToFloat(tempCStyle.size)), tempCStyle.style);
  1017. previewLabel.SetFont(tempFont); previewLabel.Invalidate;
  1018. IF (tempFont.name # tempCStyle.family) OR (tempFont.size # ENTIER(FP1616.FixpToFloat(tempCStyle.size))) THEN
  1019. fontNotFound.visible.Set(TRUE);
  1020. ELSE
  1021. fontNotFound.visible.Set(FALSE);
  1022. END;
  1023. ELSIF (tempEditor = cSize) THEN
  1024. Strings.StrToFloat(tempString, tempLReal);
  1025. tempCStyle.size := FP1616.FloatToFixp(SHORT(tempLReal));
  1026. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1027. cSize.SetAsString(tempString);
  1028. (* set leading to 120% of size *)
  1029. tempLReal := tempLReal*1.2;
  1030. tempCStyle.leading := FP1616.FloatToFixp(SHORT(tempLReal));
  1031. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1032. cLeading.SetAsString(tempString);
  1033. tempFont := WMGraphics.GetFont(tempCStyle.family, ENTIER(FP1616.FixpToFloat(tempCStyle.size)), tempCStyle.style);
  1034. previewLabel.SetFont(tempFont); previewLabel.Invalidate;
  1035. IF (tempFont.name # tempCStyle.family) OR (tempFont.size # ENTIER(FP1616.FixpToFloat(tempCStyle.size))) THEN
  1036. fontNotFound.visible.Set(TRUE);
  1037. ELSE
  1038. fontNotFound.visible.Set(FALSE);
  1039. END;
  1040. ELSIF (tempEditor = cLeading) THEN
  1041. Strings.StrToFloat(tempString, tempLReal);
  1042. tempCStyle.leading := FP1616.FloatToFixp(SHORT(tempLReal));
  1043. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1044. cLeading.SetAsString(tempString);
  1045. ELSIF (tempEditor = cBaselineShift) THEN
  1046. Strings.StrToFloat(tempString, tempLReal);
  1047. tempCStyle.baselineShift := FP1616.FloatToFixp(SHORT(tempLReal));
  1048. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1049. cBaselineShift.SetAsString(tempString);
  1050. ELSIF (tempEditor = cColor) THEN
  1051. Strings.HexStrToInt(tempString, tempInt, res);
  1052. tempCStyle.color := tempInt;
  1053. Strings.IntToHexStr(tempInt, 7, tempString);
  1054. cColor.SetAsString(tempString);
  1055. previewLabel.textColor.Set(tempInt); previewLabel.Invalidate;
  1056. ELSIF (tempEditor = cBackColor) THEN
  1057. Strings.HexStrToInt(tempString, tempInt, res);
  1058. tempCStyle.bgColor := tempInt;
  1059. Strings.IntToHexStr(tempInt, 7, tempString);
  1060. cBackColor.SetAsString(tempString);
  1061. previewLabel.fillColor.Set(tempInt); previewLabel.Invalidate;
  1062. ELSIF (tempEditor = cTracking) THEN
  1063. Strings.StrToFloat(tempString, tempLReal);
  1064. tempCStyle.tracking := FP1616.FloatToFixp(SHORT(tempLReal));
  1065. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1066. cTracking.SetAsString(tempString);
  1067. ELSIF (tempEditor = cStretchH) THEN
  1068. Strings.StrToFloat(tempString, tempLReal);
  1069. tempCStyle.scaleHorizontal := FP1616.FloatToFixp(SHORT(tempLReal));
  1070. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1071. cStretchH.SetAsString(tempString);
  1072. ELSIF (tempEditor = cStretchV) THEN
  1073. Strings.StrToFloat(tempString, tempLReal);
  1074. tempCStyle.scaleVertical := FP1616.FloatToFixp(SHORT(tempLReal));
  1075. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1076. cStretchV.SetAsString(tempString);
  1077. ELSE
  1078. END;
  1079. END UpdateValueHandler;
  1080. PROCEDURE UpdateList;
  1081. VAR i : LONGINT;
  1082. BEGIN
  1083. pList.model.Acquire;
  1084. i := 0;
  1085. WHILE ((i<LEN(pStyles)) & (pStyles[i] # NIL)) DO
  1086. pList.model.SetNofRows(i+1);
  1087. pList.model.SetCellText(0, i, Strings.NewString(pStyles[i].name));
  1088. pList.model.SetCellData(0, i, pStyles[i]);
  1089. INC(i);
  1090. END;
  1091. pList.model.Release;
  1092. cList.model.Acquire;
  1093. i := 0;
  1094. WHILE ((i<LEN(cStyles)) & (cStyles[i] # NIL)) DO
  1095. cList.model.SetNofRows(i+1);
  1096. cList.model.SetCellText(0, i, Strings.NewString(cStyles[i].name));
  1097. cList.model.SetCellData(0, i, cStyles[i]);
  1098. INC(i);
  1099. END;
  1100. cList.model.Release;
  1101. UpdateProc;
  1102. SendUpdateMsg;
  1103. END UpdateList;
  1104. PROCEDURE SendUpdateMsg;
  1105. VAR changed : Texts.StyleChangedMsg;
  1106. msg : WMMessages.Message;
  1107. m : WM.WindowManager;
  1108. BEGIN
  1109. NEW(changed); msg.ext := changed; msg.msgType := WMMessages.MsgExt;
  1110. m := WM.GetDefaultManager();
  1111. m.Broadcast(msg);
  1112. END SendUpdateMsg;
  1113. PROCEDURE NewPHandler(sender, data: ANY);
  1114. VAR newPStyle: Texts.ParagraphStyle;
  1115. tempString: ARRAY 256 OF CHAR;
  1116. BEGIN
  1117. NEW(newPStyle);
  1118. tempString := "newParagraphStyle";
  1119. WHILE Texts.GetParagraphStyleByName(tempString) # NIL DO
  1120. Strings.Append(tempString, "Copy");
  1121. END;
  1122. Strings.Append(newPStyle.name, tempString);
  1123. newPStyle.alignment := 0; (* Left Align *)
  1124. newPStyle.spaceBefore := 0;
  1125. newPStyle.spaceAfter := 0;
  1126. newPStyle.leftIndent := 0;
  1127. newPStyle.rightIndent := 0;
  1128. newPStyle.firstIndent := 0;
  1129. newPStyle.charStyle := Texts.GetCharacterStyleByName("Normal");
  1130. UpdateList;
  1131. END NewPHandler;
  1132. PROCEDURE ImportPHandler(sender, data: ANY);
  1133. VAR filename: ARRAY 128 OF CHAR;
  1134. BEGIN
  1135. filename := "";
  1136. IF WMDialogs.QueryString("Import Paragraph Styles from File:", filename) = WMDialogs.ResOk THEN
  1137. ImportParagraphStyles(filename);
  1138. END;
  1139. UpdateList;
  1140. END ImportPHandler;
  1141. PROCEDURE ImportParagraphStyles(CONST filename: ARRAY OF CHAR);
  1142. VAR tempString : ARRAY 256 OF CHAR;
  1143. tempReal : LONGREAL;
  1144. reader : Files.Reader;
  1145. parser : XMLParser.Parser;
  1146. scanner : XMLScanner.Scanner;
  1147. f : Files.File;
  1148. XMLdocStyle : XML.Document;
  1149. root: XML.Element;
  1150. cont: XMLObjects.Enumerator;
  1151. ptr: ANY;
  1152. str: Strings.String;
  1153. pStyle: Texts.ParagraphStyle;
  1154. cStyle: Texts.CharacterStyle;
  1155. BEGIN
  1156. COPY(filename, tempString);
  1157. Strings.Append(tempString, ".XML");
  1158. f := Files.Old(tempString);
  1159. IF f = NIL THEN RETURN END;
  1160. NEW(reader, f, 0);
  1161. NEW(scanner, reader);
  1162. NEW(parser, scanner);
  1163. XMLdocStyle := parser.Parse();
  1164. root := XMLdocStyle.GetRoot();
  1165. cont := root.GetContents(); cont.Reset();
  1166. WHILE cont.HasMoreElements() DO
  1167. ptr := cont.GetNext();
  1168. IF ptr IS XML.Element THEN
  1169. str := ptr(XML.Element).GetName();
  1170. IF (str # NIL) & (str^ = "paragraph-style") THEN (* paragraph styles *)
  1171. NEW(pStyle);
  1172. str := ptr(XML.Element).GetAttributeValue("name"); IF str # NIL THEN COPY(str^, pStyle.name) END;
  1173. str := ptr(XML.Element).GetAttributeValue("alignment"); IF str # NIL THEN Strings.StrToInt(str^, pStyle.alignment) END;
  1174. str := ptr(XML.Element).GetAttributeValue("first-indent"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); pStyle.firstIndent := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1175. str := ptr(XML.Element).GetAttributeValue("left-indent"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); pStyle.leftIndent := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1176. str := ptr(XML.Element).GetAttributeValue("right-indent"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); pStyle.rightIndent := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1177. str := ptr(XML.Element).GetAttributeValue("space-before"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); pStyle.spaceBefore := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1178. str := ptr(XML.Element).GetAttributeValue("space-after"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); pStyle.spaceAfter := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1179. str := ptr(XML.Element).GetAttributeValue("character-style");
  1180. IF str # NIL THEN
  1181. cStyle := Texts.GetCharacterStyleByName(str^);
  1182. IF cStyle # NIL THEN pStyle.charStyle := cStyle; END;
  1183. END;
  1184. Texts.AddParagraphStyle(pStyle);
  1185. END;
  1186. END;
  1187. END;
  1188. END ImportParagraphStyles;
  1189. PROCEDURE RemovePHandler(sender, data: ANY);
  1190. BEGIN
  1191. Texts.RemoveParagraphStyle(currentPStyle);
  1192. UpdateList;
  1193. END RemovePHandler;
  1194. PROCEDURE ApplyPHandler(sender, data: ANY);
  1195. VAR tempString : ARRAY 256 OF CHAR;
  1196. tempLReal: LONGREAL;
  1197. tempCharStyle : Texts.CharacterStyle;
  1198. BEGIN
  1199. (* retrieve tempvalues first.. *)
  1200. pName.GetAsString(tempString);
  1201. COPY(tempString, tempPStyle.name);
  1202. pAlign.GetAsString(tempString); Strings.LowerCase(tempString);
  1203. IF (tempString = "left") THEN tempPStyle.alignment := 0; pAlign.SetAsString("Left");
  1204. ELSIF (tempString = "center") THEN tempPStyle.alignment := 1; pAlign.SetAsString("Center");
  1205. ELSIF (tempString = "right") THEN tempPStyle.alignment := 2; pAlign.SetAsString("Right");
  1206. ELSIF (tempString = "justified") THEN tempPStyle.alignment := 3; pAlign.SetAsString("Justified");
  1207. ELSE tempPStyle.alignment := 0; pAlign.SetAsString("Left"); END;
  1208. pFirstIndent.GetAsString(tempString);
  1209. Strings.StrToFloat(tempString, tempLReal);
  1210. tempPStyle.firstIndent := FP1616.FloatToFixp(SHORT(tempLReal));
  1211. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1212. pFirstIndent.SetAsString(tempString);
  1213. pLeftIndent.GetAsString(tempString);
  1214. Strings.StrToFloat(tempString, tempLReal);
  1215. tempPStyle.leftIndent := FP1616.FloatToFixp(SHORT(tempLReal));
  1216. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1217. pLeftIndent.SetAsString(tempString);
  1218. pRightIndent.GetAsString(tempString);
  1219. Strings.StrToFloat(tempString, tempLReal);
  1220. tempPStyle.rightIndent := FP1616.FloatToFixp(SHORT(tempLReal));
  1221. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1222. pRightIndent.SetAsString(tempString);
  1223. pSpaceBefore.GetAsString(tempString);
  1224. Strings.StrToFloat(tempString, tempLReal);
  1225. tempPStyle.spaceBefore := FP1616.FloatToFixp(SHORT(tempLReal));
  1226. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1227. pSpaceBefore.SetAsString(tempString);
  1228. pSpaceAfter.GetAsString(tempString);
  1229. Strings.StrToFloat(tempString, tempLReal);
  1230. tempPStyle.spaceAfter := FP1616.FloatToFixp(SHORT(tempLReal));
  1231. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1232. pSpaceAfter.SetAsString(tempString);
  1233. pDefCharStyle.GetAsString(tempString);
  1234. tempCharStyle := Texts.GetCharacterStyleByName(tempString);
  1235. IF tempCharStyle # NIL THEN
  1236. tempPStyle.charStyle := tempCharStyle;
  1237. ELSE
  1238. tempPStyle.charStyle := Texts.GetCharacterStyleByName("Normal");
  1239. pDefCharStyle.SetAsString(tempPStyle.charStyle.name);
  1240. END;
  1241. (* update currentStyle with temp, refresh list *)
  1242. currentPStyle.name := tempPStyle.name;
  1243. currentPStyle.alignment := tempPStyle.alignment;
  1244. currentPStyle.firstIndent := tempPStyle.firstIndent;
  1245. currentPStyle.leftIndent := tempPStyle.leftIndent;
  1246. currentPStyle.rightIndent := tempPStyle.rightIndent;
  1247. currentPStyle.spaceBefore := tempPStyle.spaceBefore;
  1248. currentPStyle.spaceAfter := tempPStyle.spaceAfter;
  1249. currentPStyle.charStyle := tempPStyle.charStyle;
  1250. UpdateList;
  1251. END ApplyPHandler;
  1252. PROCEDURE NewCHandler(sender, data: ANY);
  1253. VAR newCStyle: Texts.CharacterStyle;
  1254. name : ARRAY 256 OF CHAR;
  1255. BEGIN
  1256. NEW(newCStyle);
  1257. IF (currentCStyle # NIL) & (currentCStyle.name # "") THEN
  1258. COPY(currentCStyle.name, name);
  1259. ELSE
  1260. COPY("NewCharacterStyle", name);
  1261. END;
  1262. WHILE Texts.GetCharacterStyleByName(name) # NIL DO
  1263. Strings.Append(name, "Copy");
  1264. END;
  1265. COPY(name, newCStyle.name);
  1266. IF currentCStyle = NIL THEN
  1267. newCStyle.family := "Oberon";
  1268. newCStyle.style := {};
  1269. newCStyle.size := FP1616.FloatToFixp(12.0);
  1270. newCStyle.leading := FP1616.FloatToFixp(14.0);
  1271. newCStyle.baselineShift := 0;
  1272. newCStyle.tracking := 0;
  1273. newCStyle.scaleHorizontal := FP1616.FloatToFixp(100.0);
  1274. newCStyle.scaleVertical := FP1616.FloatToFixp(100.0);
  1275. newCStyle.color := 0000000FFH;
  1276. newCStyle.bgColor := LONGINT(0FFFFFF00H);
  1277. ELSE
  1278. (* copy selected style *)
  1279. COPY(currentCStyle.family, newCStyle.family);
  1280. newCStyle.style := currentCStyle.style;
  1281. newCStyle.size := currentCStyle.size;
  1282. newCStyle.leading := currentCStyle.leading;
  1283. newCStyle.baselineShift := currentCStyle.baselineShift;
  1284. newCStyle.tracking := currentCStyle.tracking;
  1285. newCStyle.scaleHorizontal := currentCStyle.scaleHorizontal;
  1286. newCStyle.scaleVertical := currentCStyle.scaleVertical;
  1287. newCStyle.color := currentCStyle.color;
  1288. newCStyle.bgColor := currentCStyle.bgColor;
  1289. END;
  1290. Texts.AddCharacterStyle(newCStyle);
  1291. UpdateList;
  1292. END NewCHandler;
  1293. PROCEDURE ExportCHandler(sender, data: ANY);
  1294. VAR filename: ARRAY 128 OF CHAR;
  1295. BEGIN
  1296. filename := "UserTextStyles";
  1297. IF WMDialogs.QueryString("Export Character Styles to File:", filename) = WMDialogs.ResOk THEN
  1298. ExportCharacterStyles(filename);
  1299. END;
  1300. END ExportCHandler;
  1301. PROCEDURE ExportCharacterStyles(CONST filename: ARRAY OF CHAR);
  1302. VAR i : LONGINT; style : SET;
  1303. tempString : ARRAY 256 OF CHAR;
  1304. w : Files.Writer; f : Files.File;
  1305. cStyle : Texts.CharacterStyle;
  1306. BEGIN
  1307. (* -- Save Style File -- *)
  1308. COPY(filename, tempString);
  1309. Strings.Append(tempString, ".XML");
  1310. f := Files.New(tempString); IF f = NIL THEN RETURN END;
  1311. Files.OpenWriter(w, f, 0);
  1312. w.String('<?xml version="1.0" encoding="UTF-8"?>'); w.Ln;
  1313. w.String("<styles>"); w.Ln;
  1314. (* processing character styles *)
  1315. i := 0;
  1316. WHILE ((i<LEN(cStyles)) & (cStyles[i] #NIL)) DO
  1317. cStyle := cStyles[i];
  1318. w.String('<character-style name="'); w.String(cStyle.name);
  1319. w.String('" font-family="'); w.String(cStyle.family);
  1320. w.String('" font-style="'); style := cStyle.style;
  1321. IF (style = {}) THEN
  1322. w.Int(0, 0);
  1323. ELSIF (style = {0}) THEN
  1324. w.Int(1, 0);
  1325. ELSIF (style = {1}) THEN
  1326. w.Int(2, 0);
  1327. ELSIF (style = {0,1}) THEN
  1328. w.Int(3, 0);
  1329. ELSE
  1330. w.Int(0, 0);
  1331. END;
  1332. w.String('" font-size="'); Strings.FloatToStr(FP1616.FixpToFloat(cStyle.size), 0,4,0, tempString); Strings.TrimLeft(tempString, " "); w.String(tempString);
  1333. w.String('" leading="'); Strings.FloatToStr(FP1616.FixpToFloat(cStyle.leading), 0,4,0, tempString); Strings.TrimLeft(tempString, " "); w.String(tempString);
  1334. w.String('" baseline-shift="'); Strings.FloatToStr(FP1616.FixpToFloat(cStyle.baselineShift), 0,4,0, tempString); Strings.TrimLeft(tempString, " "); w.String(tempString);
  1335. w.String('" color="'); w.Hex(cStyle.color, 8);
  1336. w.String('" bgcolor="'); w.Hex(cStyle.bgColor, 8);
  1337. w.String('" tracking="'); Strings.FloatToStr(FP1616.FixpToFloat(cStyle.tracking), 0,4,0, tempString); Strings.TrimLeft(tempString, " "); w.String(tempString);
  1338. w.String('" h-scale="'); Strings.FloatToStr(FP1616.FixpToFloat(cStyle.scaleHorizontal), 0,4,0, tempString); Strings.TrimLeft(tempString, " "); w.String(tempString);
  1339. w.String('" v-scale="'); Strings.FloatToStr(FP1616.FixpToFloat(cStyle.scaleVertical), 0,4,0, tempString); Strings.TrimLeft(tempString, " "); w.String(tempString);
  1340. w.String('" />'); w.Ln;
  1341. INC(i);
  1342. END;
  1343. w.String("</styles>"); w.Ln;
  1344. w.Update; Files.Register(f);
  1345. END ExportCharacterStyles;
  1346. PROCEDURE ImportCHandler(sender, data: ANY);
  1347. VAR filename: ARRAY 128 OF CHAR;
  1348. BEGIN
  1349. filename := "";
  1350. IF WMDialogs.QueryString("Import Character Styles from File:", filename) = WMDialogs.ResOk THEN
  1351. ImportCharacterStyles(filename);
  1352. END;
  1353. UpdateList;
  1354. END ImportCHandler;
  1355. PROCEDURE ImportCharacterStyles(CONST filename: ARRAY OF CHAR);
  1356. VAR tempString : ARRAY 256 OF CHAR;
  1357. tempReal: LONGREAL;
  1358. tempInt: LONGINT; res: WORD;
  1359. reader : Files.Reader;
  1360. parser : XMLParser.Parser;
  1361. scanner : XMLScanner.Scanner;
  1362. f : Files.File;
  1363. XMLdocStyle : XML.Document;
  1364. root: XML.Element;
  1365. cont: XMLObjects.Enumerator;
  1366. ptr: ANY;
  1367. str: Strings.String;
  1368. cStyle: Texts.CharacterStyle;
  1369. BEGIN
  1370. COPY(filename, tempString);
  1371. Strings.Append(tempString, ".XML");
  1372. f := Files.Old(tempString);
  1373. IF f = NIL THEN RETURN END;
  1374. NEW(reader, f, 0);
  1375. NEW(scanner, reader);
  1376. NEW(parser, scanner);
  1377. XMLdocStyle := parser.Parse();
  1378. root := XMLdocStyle.GetRoot();
  1379. cont := root.GetContents(); cont.Reset();
  1380. WHILE cont.HasMoreElements() DO
  1381. ptr := cont.GetNext();
  1382. IF ptr IS XML.Element THEN
  1383. str := ptr(XML.Element).GetName();
  1384. (* KernelLog.String(str^); KernelLog.Ln; *)
  1385. IF (str # NIL) & (str^ = "character-style") THEN (* character styles *)
  1386. NEW(cStyle);
  1387. str := ptr(XML.Element).GetAttributeValue("name"); IF str # NIL THEN COPY(str^, cStyle.name) END;
  1388. str := ptr(XML.Element).GetAttributeValue("font-family"); IF str # NIL THEN COPY(str^, cStyle.family) END;
  1389. str := ptr(XML.Element).GetAttributeValue("font-style");
  1390. IF str # NIL THEN
  1391. IF (str^ = "0") THEN cStyle.style := {};
  1392. ELSIF (str^ = "1") THEN cStyle.style := {0};
  1393. ELSIF (str^ = "2") THEN cStyle.style := {1};
  1394. ELSIF (str^ = "3") THEN cStyle.style := {0,1};
  1395. ELSE cStyle.style := {};
  1396. END;
  1397. END;
  1398. str := ptr(XML.Element).GetAttributeValue("font-size"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); cStyle.size := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1399. str := ptr(XML.Element).GetAttributeValue("leading"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); cStyle.leading := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1400. str := ptr(XML.Element).GetAttributeValue("baseline-shift"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); cStyle.baselineShift := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1401. str := ptr(XML.Element).GetAttributeValue("color"); IF str # NIL THEN Strings.HexStrToInt(str^, tempInt, res); cStyle.color := tempInt; END;
  1402. str := ptr(XML.Element).GetAttributeValue("bgcolor"); IF str # NIL THEN Strings.HexStrToInt(str^, tempInt, res); cStyle.bgColor := tempInt; END;
  1403. str := ptr(XML.Element).GetAttributeValue("tracking"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); cStyle.tracking := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1404. str := ptr(XML.Element).GetAttributeValue("h-scale"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); cStyle.scaleHorizontal := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1405. str := ptr(XML.Element).GetAttributeValue("v-scale"); IF str # NIL THEN Strings.StrToFloat(str^, tempReal); cStyle.scaleVertical := FP1616.FloatToFixp(SHORT(tempReal)); END;
  1406. Texts.AddCharacterStyle(cStyle);
  1407. END;
  1408. END;
  1409. END;
  1410. END ImportCharacterStyles;
  1411. PROCEDURE RemoveCHandler(sender, data: ANY);
  1412. VAR i : LONGINT;
  1413. BEGIN
  1414. Texts.RemoveCharacterStyle(currentCStyle);
  1415. cList.model.Acquire;
  1416. i := 0;
  1417. WHILE ((i<LEN(cStyles)) & (cStyles[i] # NIL)) DO
  1418. cList.model.SetNofRows(i+1);
  1419. cList.model.SetCellText(0, i, Strings.NewString(cStyles[i].name));
  1420. cList.model.SetCellData(0, i, cStyles[i]);
  1421. INC(i);
  1422. END;
  1423. CClickSelected(NIL, cList.model.GetCellData(0, i-1));
  1424. cList.SetSelection(0,i-1, 0, i-1);
  1425. cList.model.Release;
  1426. UpdateProc;
  1427. END RemoveCHandler;
  1428. PROCEDURE ApplyCHandler(sender, data: ANY);
  1429. VAR tempString : ARRAY 256 OF CHAR;
  1430. tempLReal: LONGREAL;
  1431. tempInt : LONGINT; res: WORD;
  1432. tempFont : WMGraphics.Font;
  1433. BEGIN
  1434. (* retrieve tempvalues first for those who didn't press enter after changing a value... *)
  1435. cName.GetAsString(tempString);
  1436. COPY(tempString, tempCStyle.name);
  1437. cFont.GetAsString(tempString);
  1438. COPY(tempString, tempCStyle.family);
  1439. cStyle.GetAsString(tempString); Strings.LowerCase(tempString);
  1440. IF (tempString = "regular") THEN tempCStyle.style := {}; cStyle.SetAsString("Regular");
  1441. ELSIF (tempString = "bold") THEN tempCStyle.style := {0}; cStyle.SetAsString("Bold");
  1442. ELSIF (tempString = "italic") THEN tempCStyle.style := {1}; cStyle.SetAsString("Italic");
  1443. ELSIF (tempString = "bold italic") THEN tempCStyle.style := {0, 1}; cStyle.SetAsString("Bold Italic");
  1444. ELSE tempCStyle.style := {}; cStyle.SetAsString("Regular"); END;
  1445. cSize.GetAsString(tempString);
  1446. Strings.StrToFloat(tempString, tempLReal);
  1447. tempCStyle.size := FP1616.FloatToFixp(SHORT(tempLReal));
  1448. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1449. cSize.SetAsString(tempString);
  1450. cLeading.GetAsString(tempString);
  1451. Strings.StrToFloat(tempString, tempLReal);
  1452. tempCStyle.leading := FP1616.FloatToFixp(SHORT(tempLReal));
  1453. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1454. cLeading.SetAsString(tempString);
  1455. tempFont := WMGraphics.GetFont(tempCStyle.family, ENTIER(FP1616.FixpToFloat(tempCStyle.size)), tempCStyle.style);
  1456. previewLabel.SetFont(tempFont); previewLabel.Invalidate;
  1457. IF (tempFont.name # tempCStyle.family) OR (tempFont.size # ENTIER(FP1616.FixpToFloat(tempCStyle.size))) THEN
  1458. fontNotFound.visible.Set(TRUE);
  1459. ELSE
  1460. fontNotFound.visible.Set(FALSE);
  1461. END;
  1462. cLeading.GetAsString(tempString);
  1463. Strings.StrToFloat(tempString, tempLReal);
  1464. tempCStyle.leading := FP1616.FloatToFixp(SHORT(tempLReal));
  1465. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1466. cLeading.SetAsString(tempString);
  1467. cBaselineShift.GetAsString(tempString);
  1468. Strings.StrToFloat(tempString, tempLReal);
  1469. tempCStyle.baselineShift := FP1616.FloatToFixp(SHORT(tempLReal));
  1470. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1471. cBaselineShift.SetAsString(tempString);
  1472. cColor.GetAsString(tempString);
  1473. Strings.HexStrToInt(tempString, tempInt, res);
  1474. tempCStyle.color := tempInt;
  1475. Strings.IntToHexStr(tempInt, 7, tempString);
  1476. cColor.SetAsString(tempString);
  1477. previewLabel.textColor.Set(tempInt); previewLabel.Invalidate;
  1478. cBackColor.GetAsString(tempString);
  1479. Strings.HexStrToInt(tempString, tempInt, res);
  1480. tempCStyle.bgColor := tempInt;
  1481. Strings.IntToHexStr(tempInt, 7, tempString);
  1482. cBackColor.SetAsString(tempString);
  1483. previewLabel.fillColor.Set(tempInt); previewLabel.Invalidate;
  1484. cTracking.GetAsString(tempString);
  1485. Strings.StrToFloat(tempString, tempLReal);
  1486. tempCStyle.tracking := FP1616.FloatToFixp(SHORT(tempLReal));
  1487. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1488. cTracking.SetAsString(tempString);
  1489. cStretchH.GetAsString(tempString);
  1490. Strings.StrToFloat(tempString, tempLReal);
  1491. tempCStyle.scaleHorizontal := FP1616.FloatToFixp(SHORT(tempLReal));
  1492. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1493. cStretchH.SetAsString(tempString);
  1494. cStretchV.GetAsString(tempString);
  1495. Strings.StrToFloat(tempString, tempLReal);
  1496. tempCStyle.scaleVertical := FP1616.FloatToFixp(SHORT(tempLReal));
  1497. Strings.FloatToStr(tempLReal, 0,4,0, tempString);
  1498. cStretchV.SetAsString(tempString);
  1499. (* update currentStyle with temp, refresh list *)
  1500. currentCStyle.name := tempCStyle.name;
  1501. currentCStyle.family := tempCStyle.family;
  1502. currentCStyle.style := tempCStyle.style;
  1503. currentCStyle.size := tempCStyle.size;
  1504. currentCStyle.leading := tempCStyle.leading;
  1505. currentCStyle.baselineShift := tempCStyle.baselineShift;
  1506. currentCStyle.color := tempCStyle.color;
  1507. currentCStyle.bgColor := tempCStyle.bgColor;
  1508. currentCStyle.tracking := tempCStyle.tracking;
  1509. currentCStyle.scaleHorizontal := tempCStyle.scaleHorizontal;
  1510. currentCStyle.scaleVertical := tempCStyle.scaleVertical;
  1511. (* Invalidate Cache *)
  1512. currentCStyle.fontcache := NIL;
  1513. UpdateList;
  1514. END ApplyCHandler;
  1515. PROCEDURE AlignHandler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  1516. BEGIN
  1517. NEW(popup);
  1518. popup.AddParButton("Left", AlignPopupHandler, ctxAlignLeft);
  1519. popup.AddParButton("Center", AlignPopupHandler, ctxAlignCenter);
  1520. popup.AddParButton("Right", AlignPopupHandler, ctxAlignRight);
  1521. popup.AddParButton("Justified", AlignPopupHandler, ctxAlignJustified);
  1522. handled := TRUE;
  1523. popup.Popup(bounds.r-100, bounds.t+72);
  1524. END AlignHandler;
  1525. PROCEDURE AlignPopupHandler(sender, data: ANY);
  1526. BEGIN
  1527. IF (data # NIL) THEN
  1528. popup.Close;
  1529. IF data(ContextMenuData).val = 0 THEN
  1530. pAlign.SetAsString("Left"); tempPStyle.alignment := 0;
  1531. ELSIF data(ContextMenuData).val = 1 THEN
  1532. pAlign.SetAsString("Center"); tempPStyle.alignment := 1;
  1533. ELSIF data(ContextMenuData).val = 2 THEN
  1534. pAlign.SetAsString("Right"); tempPStyle.alignment := 2;
  1535. ELSIF data(ContextMenuData).val = 3 THEN
  1536. pAlign.SetAsString("Justified"); tempPStyle.alignment := 3;
  1537. ELSE
  1538. END;
  1539. END;
  1540. END AlignPopupHandler;
  1541. PROCEDURE StyleHandler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  1542. BEGIN
  1543. NEW(popup);
  1544. popup.AddParButton("Regular", StylePopupHandler, ctxRegular);
  1545. popup.AddParButton("Bold", StylePopupHandler, ctxBold);
  1546. popup.AddParButton("Italic", StylePopupHandler, ctxItalic);
  1547. popup.AddParButton("Bold Italic", StylePopupHandler, ctxBoldItalic);
  1548. handled := TRUE;
  1549. popup.Popup(bounds.r-100, bounds.t+92);
  1550. END StyleHandler;
  1551. PROCEDURE StylePopupHandler(sender, data: ANY);
  1552. VAR tempFont : WMGraphics.Font;
  1553. BEGIN
  1554. IF (data # NIL) THEN
  1555. popup.Close;
  1556. IF data(ContextMenuData).val = 0 THEN
  1557. cStyle.SetAsString("Regular"); tempCStyle.style := {};
  1558. ELSIF data(ContextMenuData).val = 1 THEN
  1559. cStyle.SetAsString("Bold"); tempCStyle.style := {0};
  1560. ELSIF data(ContextMenuData).val = 2 THEN
  1561. cStyle.SetAsString("Italic"); tempCStyle.style := {1};
  1562. ELSIF data(ContextMenuData).val = 3 THEN
  1563. cStyle.SetAsString("Bold Italic"); tempCStyle.style := {0,1};
  1564. ELSE
  1565. END;
  1566. tempFont := WMGraphics.GetFont(tempCStyle.family, ENTIER(FP1616.FixpToFloat(tempCStyle.size)), tempCStyle.style);
  1567. previewLabel.SetFont(tempFont); previewLabel.Invalidate;
  1568. END;
  1569. END StylePopupHandler;
  1570. PROCEDURE ColorHandler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  1571. VAR colorPanel : WMPopups.ColorSwatchPopup;
  1572. BEGIN
  1573. NEW(colorPanel);
  1574. colorPanel.onColorChosen := ColorPopupHandler;
  1575. colorPanel.Popup(bounds.r-190, bounds.t+172);
  1576. handled := TRUE;
  1577. END ColorHandler;
  1578. PROCEDURE ColorPopupHandler(result: WMGraphics.Color);
  1579. VAR
  1580. colorString: ARRAY 16 OF CHAR;
  1581. BEGIN
  1582. Strings.IntToHexStr(result, 7, colorString);
  1583. cColor.SetAsString(colorString);
  1584. tempCStyle.color := result;
  1585. previewLabel.textColor.Set(result); previewLabel.Invalidate;
  1586. END ColorPopupHandler;
  1587. PROCEDURE BGColorHandler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  1588. VAR colorPanel: WMPopups.ColorSwatchPopup;
  1589. BEGIN
  1590. NEW(colorPanel);
  1591. colorPanel.onColorChosen := BGColorPopupHandler;
  1592. colorPanel.Popup(bounds.r-190, bounds.t+192);
  1593. handled := TRUE;
  1594. END BGColorHandler;
  1595. PROCEDURE BGColorPopupHandler(result: WMGraphics.Color);
  1596. VAR
  1597. colorString: ARRAY 16 OF CHAR;
  1598. BEGIN
  1599. Strings.IntToHexStr(result, 7, colorString);
  1600. cBackColor.SetAsString(colorString);
  1601. tempCStyle.bgColor := result;
  1602. previewLabel.fillColor.Set(result); previewLabel.Invalidate;
  1603. END BGColorPopupHandler;
  1604. END StyleEditor;
  1605. VAR
  1606. nofWindows : LONGINT;
  1607. ctxAlignLeft, ctxAlignCenter, ctxAlignRight, ctxAlignJustified : ContextMenuData;
  1608. ctxRegular, ctxBold, ctxItalic, ctxBoldItalic : ContextMenuData;
  1609. PROCEDURE CreateStyleName(CONST fontname : ARRAY OF CHAR; style : SET; size, fgColor, bgColor : LONGINT; VAR name : ARRAY OF CHAR);
  1610. VAR string : ARRAY 32 OF CHAR; styleInt : LONGINT;
  1611. BEGIN
  1612. (* create AdHoc Name *)
  1613. COPY("AdHoc", name); Strings.Append(name, " ");
  1614. Strings.Append(name, fontname); Strings.Append(name, " ");
  1615. Strings.IntToStr(size, string); Strings.Append(name, string); Strings.Append(name, " ");
  1616. IF (style = {}) THEN styleInt := 0;
  1617. ELSIF (style = {0}) THEN styleInt := 1;
  1618. ELSIF (style ={1}) THEN styleInt := 2;
  1619. ELSIF (style = {0, 1}) THEN styleInt := 3;
  1620. ELSE styleInt := 0;
  1621. END;
  1622. Strings.IntToStr(styleInt, string); Strings.Append(name, string); Strings.Append(name, " ");
  1623. Strings.IntToStr(0, string); Strings.Append(name, string); Strings.Append(name, " ");
  1624. Strings.IntToHexStr(fgColor, 7, string); Strings.Append(name, string); Strings.Append(name, " ");
  1625. Strings.IntToHexStr(bgColor, 7, string); Strings.Append(name, string);
  1626. END CreateStyleName;
  1627. PROCEDURE EnsureAttribute(VAR attr : Texts.Attributes);
  1628. BEGIN
  1629. IF (attr = NIL) THEN
  1630. NEW(attr); NEW(attr.fontInfo);
  1631. attr.fontInfo.name := "Oberon";
  1632. attr.fontInfo.size := 12;
  1633. END
  1634. END EnsureAttribute;
  1635. (* Actually, this is a hack... but for now, do it. *)
  1636. PROCEDURE GetNewSize(CONST fontname : ARRAY OF CHAR; mode, value, currentSize : LONGINT; VAR newSize : LONGINT);
  1637. BEGIN
  1638. ASSERT((mode = Absolute) OR (mode = IncrementBy) OR (mode = DecrementBy));
  1639. IF (mode = Absolute) THEN
  1640. newSize := value;
  1641. ELSE
  1642. IF (fontname = "Oberon") THEN
  1643. IF (mode = IncrementBy) THEN
  1644. IF (currentSize = 8) THEN newSize := 10;
  1645. ELSIF (currentSize = 10) THEN newSize := 12;
  1646. ELSIF (currentSize = 12) THEN newSize := 14;
  1647. ELSIF (currentSize = 14) THEN newSize := 16;
  1648. ELSIF (currentSize = 16) THEN newSize := 20;
  1649. ELSIF (currentSize = 20) THEN newSize := 24;
  1650. ELSIF (currentSize = 24) THEN newSize := 24;
  1651. ELSE (* go to default *)
  1652. newSize := 12; (* max. size of Oberon font *)
  1653. END;
  1654. ELSE
  1655. IF (currentSize = 8) THEN newSize := 8;
  1656. ELSIF (currentSize = 10) THEN newSize := 8;
  1657. ELSIF (currentSize = 12) THEN newSize := 10;
  1658. ELSIF (currentSize = 14) THEN newSize := 12;
  1659. ELSIF (currentSize = 16) THEN newSize := 14;
  1660. ELSIF (currentSize = 20) THEN newSize := 16;
  1661. ELSIF (currentSize = 24) THEN newSize := 20;
  1662. ELSE
  1663. newSize := 12;
  1664. END;
  1665. END;
  1666. ELSIF (fontname = "Courier") THEN
  1667. IF (mode = IncrementBy) THEN
  1668. IF (currentSize = 10) THEN newSize := 12;
  1669. ELSE
  1670. newSize := 12;
  1671. END;
  1672. ELSE
  1673. IF (currentSize = 12) THEN newSize := 10;
  1674. ELSE
  1675. newSize := 12;
  1676. END;
  1677. END;
  1678. ELSE
  1679. IF (mode = IncrementBy) THEN newSize := currentSize + value; ELSE newSize := currentSize - value; END;
  1680. END;
  1681. END;
  1682. IF (newSize < 5) THEN newSize := 5; END;
  1683. END GetNewSize;
  1684. PROCEDURE ChangeFontSize(VAR attr : Texts.Attributes; userData : ANY);
  1685. VAR changeInfo : ChangeInfo;
  1686. BEGIN
  1687. IF (userData # NIL) & (userData IS ChangeInfo) THEN
  1688. changeInfo := userData (ChangeInfo);
  1689. EnsureAttribute(attr);
  1690. GetNewSize(attr.fontInfo.name, changeInfo.deltaSizeMode, changeInfo.deltaSize, attr.fontInfo.size, attr.fontInfo.size);
  1691. attr.fontInfo.fontcache := NIL;
  1692. END;
  1693. END ChangeFontSize;
  1694. PROCEDURE ChangeFontColor(VAR attr : Texts.Attributes; userData : ANY);
  1695. VAR changeInfo : ChangeInfo;
  1696. BEGIN
  1697. IF (userData # NIL) & (userData IS ChangeInfo) THEN
  1698. changeInfo := userData (ChangeInfo);
  1699. EnsureAttribute(attr);
  1700. IF (changeInfo.fields * ChangeFgColor # {}) THEN attr.color := changeInfo.fgColor; END;
  1701. IF (changeInfo.fields * ChangeBgColor # {}) THEN attr.bgcolor := changeInfo.bgColor; END;
  1702. attr.fontInfo.fontcache := NIL;
  1703. END;
  1704. END ChangeFontColor;
  1705. PROCEDURE ChangeFontStyle(VAR attr : Texts.Attributes; userData : ANY);
  1706. BEGIN
  1707. IF (userData # NIL) & (userData IS ChangeInfo) THEN
  1708. EnsureAttribute(attr);
  1709. attr.fontInfo.style := userData(ChangeInfo).style;
  1710. attr.fontInfo.fontcache := NIL;
  1711. END;
  1712. END ChangeFontStyle;
  1713. PROCEDURE ChangeFontName(VAR attr : Texts.Attributes; userData : ANY);
  1714. BEGIN
  1715. IF (userData # NIL) & (userData IS ChangeInfo) THEN
  1716. EnsureAttribute(attr);
  1717. COPY(userData(ChangeInfo).name, attr.fontInfo.name);
  1718. attr.fontInfo.fontcache := NIL;
  1719. END;
  1720. END ChangeFontName;
  1721. PROCEDURE Change(changeInfo : ChangeInfo);
  1722. VAR
  1723. text : Texts.Text;
  1724. from, to : Texts.TextPosition;
  1725. utilreader : Texts.TextReader;
  1726. a, b : LONGINT;
  1727. ch : Texts.Char32;
  1728. newCstyle : Texts.CharacterStyle;
  1729. BEGIN
  1730. ASSERT(changeInfo # NIL);
  1731. IF Texts.GetLastSelection(text, from, to) THEN
  1732. text.AcquireWrite;
  1733. a := MIN(from.GetPosition(), to.GetPosition());
  1734. b := MAX(from.GetPosition(), to.GetPosition());
  1735. NEW(utilreader, text);
  1736. utilreader.SetPosition(a);
  1737. utilreader.ReadCh(ch);
  1738. IF (utilreader.cstyle = NIL) & (utilreader.attributes = NIL) THEN
  1739. changeInfo.deltaSizeMode := Absolute;
  1740. changeInfo.deltaSize := 10; (* Set to reasonable default *)
  1741. text.UpdateAttributes(a, b - a, ChangeFontSize, changeInfo);
  1742. ELSIF (utilreader.cstyle # NIL) THEN
  1743. newCstyle := utilreader.cstyle.Clone();
  1744. GetNewSize(newCstyle.family, changeInfo.deltaSizeMode, changeInfo.deltaSize, newCstyle.size, newCstyle.size);
  1745. CreateStyleName(newCstyle.family, newCstyle.style, newCstyle.size, newCstyle.color, newCstyle.bgColor, newCstyle.name);
  1746. Texts.AddCharacterStyle(newCstyle);
  1747. text.SetCharacterStyle(a, b - a, newCstyle);
  1748. ELSIF (utilreader.attributes # NIL) THEN
  1749. IF (changeInfo.fields * ChangeSize # {}) THEN text.UpdateAttributes(a, b - a, ChangeFontSize, changeInfo); END;
  1750. IF (changeInfo.fields * ChangeStyle # {}) THEN text.UpdateAttributes(a, b - a, ChangeFontStyle, changeInfo); END;
  1751. IF (changeInfo.fields * (ChangeFgColor + ChangeBgColor) # {}) THEN
  1752. text.UpdateAttributes(a, b - a, ChangeFontColor, changeInfo);
  1753. END;
  1754. IF (changeInfo.fields * ChangeFont # {}) THEN text.UpdateAttributes(a, b - a, ChangeFontName, changeInfo); END;
  1755. END;
  1756. text.ReleaseWrite;
  1757. END;
  1758. END Change;
  1759. (* Set the font size of the currently selected text either relativ or absolute *)
  1760. PROCEDURE SetFontSize*(context : Commands.Context); (** ("Absolute"|"IncrementBy" |"DecrementBy") [value] ~*)
  1761. VAR changeInfo : ChangeInfo; modeStr : ARRAY 16 OF CHAR; mode, value : LONGINT;
  1762. BEGIN
  1763. context.arg.SkipWhitespace; context.arg.String(modeStr);
  1764. context.arg.SkipWhitespace; context.arg.Int(value, FALSE);
  1765. Strings.UpperCase(modeStr);
  1766. IF (modeStr = "ABSOLUTE") THEN mode := Absolute;
  1767. ELSIF (modeStr = "INCREMENTBY") THEN mode := IncrementBy;
  1768. ELSIF (modeStr = "DECREMENTBY") THEN mode := DecrementBy;
  1769. ELSE
  1770. context.error.String("WMTextStyleTool.SetFontSize: Unknown mode parameter"); context.error.Ln;
  1771. RETURN;
  1772. END;
  1773. NEW(changeInfo);
  1774. changeInfo.fields := ChangeSize;
  1775. changeInfo.deltaSizeMode := mode;
  1776. changeInfo.deltaSize := value;
  1777. IF (mode # Absolute) & (value = 0) THEN changeInfo.deltaSize := 1; (* default increment/ decrement *) END;
  1778. Change(changeInfo);
  1779. END SetFontSize;
  1780. (** Set the font style of the currently selected text. Default: Normal *)
  1781. PROCEDURE SetFontStyle*(context : Commands.Context);
  1782. VAR styleStr : ARRAY 16 OF CHAR; style : SET; changeInfo : ChangeInfo;
  1783. BEGIN
  1784. context.arg.SkipWhitespace; context.arg.String(styleStr);
  1785. Strings.UpperCase(styleStr);
  1786. IF (styleStr = "BOLD") THEN style := {WMGraphics.FontBold};
  1787. ELSIF (styleStr = "ITALIC") THEN style := {WMGraphics.FontItalic};
  1788. ELSIF (styleStr = "NORMAL") OR (styleStr = "") THEN style := {};
  1789. ELSE
  1790. context.error.String("WMTextStyleTool.SetFontStyle: Unknown font style parameter."); context.error.Ln;
  1791. RETURN;
  1792. END;
  1793. NEW(changeInfo);
  1794. changeInfo.fields := ChangeStyle;
  1795. changeInfo.style := style;
  1796. Change(changeInfo);
  1797. END SetFontStyle;
  1798. (** Set the font color of the currently selected text. If not parameter is specified, fgColor is black, bgColor is unchanged *)
  1799. PROCEDURE SetFontColor*(context : Commands.Context); (** [fgColor] [bgColor] ~ *)
  1800. VAR fgColor, bgColor : LONGINT; changeInfo : ChangeInfo;
  1801. BEGIN
  1802. context.arg.SkipWhitespace; context.arg.Int(fgColor, TRUE);
  1803. context.arg.SkipWhitespace; context.arg.Int(bgColor, TRUE);
  1804. NEW(changeInfo);
  1805. changeInfo.fields := ChangeFgColor;
  1806. changeInfo.fgColor := fgColor;
  1807. IF (context.arg.res = Streams.Ok) THEN
  1808. changeInfo.bgColor := bgColor;
  1809. changeInfo.fields := changeInfo.fields + ChangeBgColor;
  1810. END;
  1811. Change(changeInfo);
  1812. END SetFontColor;
  1813. (** Set the font for the currently selected text. Default: Oberon *)
  1814. PROCEDURE SetFontName*(context : Commands.Context); (** [fontname] ~ *)
  1815. VAR name : ARRAY 128 OF CHAR; changeInfo : ChangeInfo;
  1816. BEGIN
  1817. IF ~context.arg.GetString(name) THEN COPY("Oberon", name); END;
  1818. NEW(changeInfo);
  1819. COPY(name, changeInfo.name);
  1820. changeInfo.fields := ChangeFont;
  1821. Change(changeInfo);
  1822. END SetFontName;
  1823. (** Set the style of the currently selected text by name *)
  1824. PROCEDURE SetStyleByName*(context : Commands.Context); (* stylename ~ *)
  1825. VAR
  1826. text : Texts.Text;
  1827. from, to : Texts.TextPosition;
  1828. a, b : LONGINT;
  1829. cStyle : Texts.CharacterStyle;
  1830. cStyleStr : ARRAY 32 OF CHAR;
  1831. BEGIN
  1832. IF ~context.arg.GetString(cStyleStr) THEN RETURN END;
  1833. IF Texts.GetLastSelection(text, from, to) THEN
  1834. cStyle := Texts.GetCharacterStyleByName(cStyleStr);
  1835. IF cStyle # NIL THEN
  1836. text.AcquireWrite;
  1837. a := MIN(from.GetPosition(), to.GetPosition());
  1838. b := MAX(from.GetPosition(), to.GetPosition());
  1839. text.SetCharacterStyle(a, b - a, cStyle);
  1840. text.ReleaseWrite
  1841. END;
  1842. END;
  1843. END SetStyleByName;
  1844. PROCEDURE Open*;
  1845. VAR winstance : Window;
  1846. BEGIN
  1847. NEW(winstance, NIL);
  1848. END Open;
  1849. PROCEDURE Restore*(context : WMRestorable.Context);
  1850. VAR w : Window;
  1851. BEGIN
  1852. NEW(w, context);
  1853. END Restore;
  1854. PROCEDURE IncCount;
  1855. BEGIN {EXCLUSIVE}
  1856. INC(nofWindows)
  1857. END IncCount;
  1858. PROCEDURE DecCount;
  1859. BEGIN {EXCLUSIVE}
  1860. DEC(nofWindows)
  1861. END DecCount;
  1862. PROCEDURE Cleanup;
  1863. VAR die : KillerMsg;
  1864. msg : WMMessages.Message;
  1865. m : WM.WindowManager;
  1866. BEGIN {EXCLUSIVE}
  1867. NEW(die);
  1868. msg.ext := die;
  1869. msg.msgType := WMMessages.MsgExt;
  1870. m := WM.GetDefaultManager();
  1871. m.Broadcast(msg);
  1872. AWAIT(nofWindows = 0)
  1873. END Cleanup;
  1874. BEGIN
  1875. NEW(ctxAlignLeft, AlignLeft);
  1876. NEW(ctxAlignCenter, AlignCenter);
  1877. NEW(ctxAlignRight, AlignRight);
  1878. NEW(ctxAlignJustified, AlignJustified);
  1879. NEW(ctxRegular, StyleRegular);
  1880. NEW(ctxBold, StyleBold);
  1881. NEW(ctxItalic, StyleItalic);
  1882. NEW(ctxBoldItalic, StyleBoldItalic);
  1883. Modules.InstallTermHandler(Cleanup)
  1884. END WMTextStyleTool.
  1885. System.Free WMTextStyleTool ~
  1886. WMTextStyleTool.Open ~
  1887. WMTextStyleTool.SetStyleByName Bold ~
  1888. WMTextStyleTool.SetStyleByName Normal ~
  1889. WMTextStyleTool.SetFontName Oberon ~
  1890. WMTextStyleTool.SetFontName Courier ~
  1891. WMTextStyleTool.SetFontSize IncrementBy ~
  1892. WMTextStyleTool.SetFontSize DecrementBy ~
  1893. WMTextStyleTool.SetFontSize Absolute 20 ~
  1894. WMTextStyleTool.SetFontStyle bold ~
  1895. WMTextStyleTool.SetFontStyle normal ~
  1896. WMTextStyleTool.SetFontColor FF0000FFH ~
  1897. WMTextStyleTool.SetFontColor 0 ~