Cmds.txt 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. MODULE StdCmds;
  2. (* THIS IS TEXT COPY OF BlackBox 1.6-rc6 Std/Mod/Cmds.odc *)
  3. (* DO NOT EDIT *)
  4. IMPORT
  5. Fonts, Ports, Services, Stores, Sequencers, Models, Views,
  6. Controllers, Containers, Properties, Dialog, Documents, Windows, Strings,
  7. StdDialog, StdApi;
  8. CONST
  9. illegalSizeKey = "#System:IllegalFontSize";
  10. defaultAllocator = "TextViews.Deposit; StdCmds.Open";
  11. (* wType, hType *)
  12. fix = 0; page = 1; window = 2;
  13. VAR
  14. size*: RECORD
  15. size*: INTEGER
  16. END;
  17. layout*: RECORD
  18. wType*, hType*: INTEGER;
  19. width*, height*: REAL;
  20. doc: Documents.Document;
  21. u: INTEGER
  22. END;
  23. allocator*: Dialog.String;
  24. propEra: INTEGER; (* (propEra, props) form cache for StdProps() *)
  25. props: Properties.StdProp; (* valid iff propEra = Props.era *)
  26. prop: Properties.Property; (* usef for copy/paste properties *)
  27. (* auxiliary procedures *)
  28. PROCEDURE StdProp (): Properties.StdProp;
  29. BEGIN
  30. IF propEra # Properties.era THEN
  31. Properties.CollectStdProp(props);
  32. propEra := Properties.era
  33. END;
  34. RETURN props
  35. END StdProp;
  36. PROCEDURE Append (VAR s: ARRAY OF CHAR; t: ARRAY OF CHAR);
  37. VAR len, i, j: INTEGER; ch: CHAR;
  38. BEGIN
  39. len := LEN(s);
  40. i := 0; WHILE s[i] # 0X DO INC(i) END;
  41. j := 0; REPEAT ch := t[j]; s[i] := ch; INC(j); INC(i) UNTIL (ch = 0X) OR (i = len);
  42. s[len - 1] := 0X
  43. END Append;
  44. (* standard commands *)
  45. PROCEDURE OpenAuxDialog* (file, title: ARRAY OF CHAR);
  46. VAR v: Views.View;
  47. BEGIN
  48. StdApi.OpenAuxDialog(file, title, v)
  49. END OpenAuxDialog;
  50. PROCEDURE OpenToolDialog* (file, title: ARRAY OF CHAR);
  51. VAR v: Views.View;
  52. BEGIN
  53. StdApi.OpenToolDialog(file, title, v)
  54. END OpenToolDialog;
  55. PROCEDURE OpenDoc* (file: ARRAY OF CHAR);
  56. VAR v: Views.View;
  57. BEGIN
  58. StdApi.OpenDoc(file, v)
  59. END OpenDoc;
  60. PROCEDURE OpenCopyOf* (file: ARRAY OF CHAR);
  61. VAR v: Views.View;
  62. BEGIN
  63. StdApi.OpenCopyOf(file, v)
  64. END OpenCopyOf;
  65. PROCEDURE OpenAux* (file, title: ARRAY OF CHAR);
  66. VAR v: Views.View;
  67. BEGIN
  68. StdApi.OpenAux(file, title, v)
  69. END OpenAux;
  70. PROCEDURE OpenBrowser* (file, title: ARRAY OF CHAR);
  71. VAR v: Views.View;
  72. BEGIN
  73. StdApi.OpenBrowser(file, title, v)
  74. END OpenBrowser;
  75. PROCEDURE CloseDialog*;
  76. VAR v: Views.View;
  77. BEGIN
  78. StdApi.CloseDialog(v)
  79. END CloseDialog;
  80. PROCEDURE Open*;
  81. VAR i: INTEGER; v: Views.View;
  82. BEGIN
  83. i := Views.Available();
  84. IF i > 0 THEN Views.Fetch(v); Views.OpenView(v)
  85. ELSE Dialog.ShowMsg("#System:DepositExpected")
  86. END
  87. END Open;
  88. PROCEDURE PasteView*;
  89. VAR i: INTEGER; v: Views.View;
  90. BEGIN
  91. i := Views.Available();
  92. IF i > 0 THEN
  93. Views.Fetch(v);
  94. Controllers.PasteView(v, Views.undefined, Views.undefined, FALSE)
  95. ELSE Dialog.ShowMsg("#System:DepositExpected")
  96. END
  97. END PasteView;
  98. (* file menu commands *)
  99. PROCEDURE New*;
  100. VAR res: INTEGER;
  101. BEGIN
  102. Dialog.Call(allocator, " ", res)
  103. END New;
  104. (* edit menu commands *)
  105. PROCEDURE Undo*;
  106. VAR w: Windows.Window;
  107. BEGIN
  108. w := Windows.dir.Focus(Controllers.frontPath);
  109. IF w # NIL THEN w.seq.Undo END
  110. END Undo;
  111. PROCEDURE Redo*;
  112. VAR w: Windows.Window;
  113. BEGIN
  114. w := Windows.dir.Focus(Controllers.frontPath);
  115. IF w # NIL THEN w.seq.Redo END
  116. END Redo;
  117. PROCEDURE CopyProp*;
  118. BEGIN
  119. Properties.CollectProp(prop)
  120. END CopyProp;
  121. PROCEDURE PasteProp*;
  122. BEGIN
  123. Properties.EmitProp(NIL, prop)
  124. END PasteProp;
  125. PROCEDURE Clear*;
  126. (** remove the selection of the current focus **)
  127. VAR msg: Controllers.EditMsg;
  128. BEGIN
  129. msg.op := Controllers.cut; msg.view := NIL;
  130. msg.clipboard := FALSE;
  131. Controllers.Forward(msg)
  132. END Clear;
  133. PROCEDURE SelectAll*;
  134. (** select whole content of current focus **)
  135. VAR msg: Controllers.SelectMsg;
  136. BEGIN
  137. msg.set := TRUE; Controllers.Forward(msg)
  138. END SelectAll;
  139. PROCEDURE DeselectAll*;
  140. (** select whole content of current focus **)
  141. VAR msg: Controllers.SelectMsg;
  142. BEGIN
  143. msg.set := FALSE; Controllers.Forward(msg)
  144. END DeselectAll;
  145. PROCEDURE SelectDocument*;
  146. (** select whole document **)
  147. VAR w: Windows.Window; c: Containers.Controller;
  148. BEGIN
  149. w := Windows.dir.Focus(Controllers.path);
  150. IF w # NIL THEN
  151. c := w.doc.ThisController();
  152. IF (c # NIL) & ~(Containers.noSelection IN c.opts) & (c.Singleton() = NIL) THEN
  153. c.SetSingleton(w.doc.ThisView())
  154. END
  155. END
  156. END SelectDocument;
  157. PROCEDURE SelectNextView*;
  158. VAR c: Containers.Controller; v: Views.View;
  159. BEGIN
  160. c := Containers.Focus();
  161. IF (c # NIL) & ~(Containers.noSelection IN c.opts) THEN
  162. IF c.HasSelection() THEN v := c.Singleton() ELSE v := NIL END;
  163. IF v = NIL THEN
  164. c.GetFirstView(Containers.any, v)
  165. ELSE
  166. c.GetNextView(Containers.any, v);
  167. IF v = NIL THEN c.GetFirstView(Containers.any, v) END
  168. END;
  169. c.SelectAll(FALSE);
  170. IF v # NIL THEN c.SetSingleton(v) END
  171. ELSE Dialog.ShowMsg("#Dev:NoTargetFocusFound")
  172. END
  173. END SelectNextView;
  174. (** font menu commands **)
  175. PROCEDURE Font* (typeface: Fonts.Typeface);
  176. (** set the selection to the given font family **)
  177. VAR p: Properties.StdProp;
  178. BEGIN
  179. NEW(p); p.valid := {Properties.typeface}; p.typeface := typeface;
  180. Properties.EmitProp(NIL, p)
  181. END Font;
  182. PROCEDURE DefaultFont*;
  183. (** set the selection to the default font family **)
  184. VAR p: Properties.StdProp;
  185. BEGIN
  186. NEW(p); p.valid := {Properties.typeface}; p.typeface := Fonts.default;
  187. Properties.EmitProp(NIL, p)
  188. END DefaultFont;
  189. (** attributes menu commands **)
  190. PROCEDURE Plain*;
  191. (** reset the font attribute "weight" and all font style attributes of the selection **)
  192. VAR p: Properties.StdProp;
  193. BEGIN
  194. NEW(p); p.valid := {Properties.style, Properties.weight};
  195. p.style.val := {}; p.style.mask := {Fonts.italic, Fonts.underline, Fonts.strikeout};
  196. p.weight := Fonts.normal;
  197. Properties.EmitProp(NIL, p)
  198. END Plain;
  199. PROCEDURE Bold*;
  200. (** change the font attribute "weight" in the selection;
  201. if the selection has a homogeneously bold weight: toggle to normal, else force to bold **)
  202. VAR p, p0: Properties.StdProp;
  203. BEGIN
  204. Properties.CollectStdProp(p0);
  205. NEW(p); p.valid := {Properties.weight};
  206. IF (Properties.weight IN p0.valid) & (p0.weight # Fonts.normal) THEN
  207. p.weight := Fonts.normal
  208. ELSE p.weight := Fonts.bold
  209. END;
  210. Properties.EmitProp(NIL, p)
  211. END Bold;
  212. PROCEDURE Italic*;
  213. (** change the font style attribute "italic" in the selection;
  214. if the selection is homogeneous wrt this attribute: toggle, else force to italic **)
  215. VAR p, p0: Properties.StdProp;
  216. BEGIN
  217. Properties.CollectStdProp(p0);
  218. NEW(p); p.valid := {Properties.style}; p.style.mask := {Fonts.italic};
  219. IF (Properties.style IN p0.valid) & (Fonts.italic IN p0.style.val) THEN
  220. p.style.val := {}
  221. ELSE p.style.val := {Fonts.italic}
  222. END;
  223. Properties.EmitProp(NIL, p)
  224. END Italic;
  225. PROCEDURE Underline*;
  226. (** change the font style attribute "underline" in the selection;
  227. if the selection is homogeneous wrt this attribute: toggle, else force to underline **)
  228. VAR p, p0: Properties.StdProp;
  229. BEGIN
  230. Properties.CollectStdProp(p0);
  231. NEW(p); p.valid := {Properties.style}; p.style.mask := {Fonts.underline};
  232. IF (Properties.style IN p0.valid) & (Fonts.underline IN p0.style.val) THEN
  233. p.style.val := {}
  234. ELSE p.style.val := {Fonts.underline}
  235. END;
  236. Properties.EmitProp(NIL, p)
  237. END Underline;
  238. PROCEDURE Strikeout*;
  239. (** change the font style attribute "strikeout" in the selection,
  240. without changing other attributes;
  241. if the selection is homogeneous wrt this attribute: toggle,
  242. else force to strikeout **)
  243. VAR p, p0: Properties.StdProp;
  244. BEGIN
  245. Properties.CollectStdProp(p0);
  246. NEW(p); p.valid := {Properties.style}; p.style.mask := {Fonts.strikeout};
  247. IF (Properties.style IN p0.valid) & (Fonts.strikeout IN p0.style.val) THEN
  248. p.style.val := {}
  249. ELSE p.style.val := {Fonts.strikeout}
  250. END;
  251. Properties.EmitProp(NIL, p)
  252. END Strikeout;
  253. PROCEDURE Size* (size: INTEGER);
  254. (** set the selection to the given font size **)
  255. VAR p: Properties.StdProp;
  256. BEGIN
  257. NEW(p); p.valid := {Properties.size};
  258. p.size := size * Ports.point;
  259. Properties.EmitProp(NIL, p)
  260. END Size;
  261. PROCEDURE SetSize*;
  262. VAR p: Properties.StdProp;
  263. BEGIN
  264. IF (0 <= size.size) & (size.size < 32768) THEN
  265. NEW(p); p.valid := {Properties.size};
  266. p.size := size.size * Fonts.point;
  267. Properties.EmitProp(NIL, p)
  268. ELSE
  269. Dialog.ShowMsg(illegalSizeKey)
  270. END
  271. END SetSize;
  272. PROCEDURE InitSizeDialog*;
  273. VAR p: Properties.StdProp;
  274. BEGIN
  275. Properties.CollectStdProp(p);
  276. IF Properties.size IN p.valid THEN size.size := p.size DIV Fonts.point END
  277. END InitSizeDialog;
  278. PROCEDURE Color* (color: Ports.Color);
  279. (** set the color attributes of the selection **)
  280. VAR p: Properties.StdProp;
  281. BEGIN
  282. NEW(p); p.valid := {Properties.color};
  283. p.color.val := color;
  284. Properties.EmitProp(NIL, p)
  285. END Color;
  286. PROCEDURE UpdateAll*; (* for HostCmds.Toggle *)
  287. VAR w: Windows.Window; pw, ph: INTEGER; dirty: BOOLEAN; msg: Models.UpdateMsg;
  288. BEGIN
  289. w := Windows.dir.First();
  290. WHILE w # NIL DO
  291. IF ~w.sub THEN
  292. dirty := w.seq.Dirty();
  293. Models.Domaincast(w.doc.Domain(), msg);
  294. IF ~dirty THEN w.seq.SetDirty(FALSE) END (* not perfect: "undoable dirt" ... *)
  295. END;
  296. w.port.GetSize(pw, ph);
  297. w.Restore(0, 0, pw, ph);
  298. w := Windows.dir.Next(w)
  299. END
  300. END UpdateAll;
  301. PROCEDURE RestoreAll*;
  302. VAR w: Windows.Window; pw, ph: INTEGER;
  303. BEGIN
  304. w := Windows.dir.First();
  305. WHILE w # NIL DO
  306. w.port.GetSize(pw, ph);
  307. w.Restore(0, 0, pw, ph);
  308. w := Windows.dir.Next(w)
  309. END
  310. END RestoreAll;
  311. (** document layout dialog **)
  312. PROCEDURE SetLayout*;
  313. VAR opts: SET; l, t, r, b, r0, b0: INTEGER; c: Containers.Controller; script: Stores.Operation;
  314. BEGIN
  315. c := layout.doc.ThisController();
  316. opts := c.opts - {Documents.pageWidth..Documents.winHeight};
  317. IF layout.wType = page THEN INCL(opts, Documents.pageWidth)
  318. ELSIF layout.wType = window THEN INCL(opts, Documents.winWidth)
  319. END;
  320. IF layout.hType = page THEN INCL(opts, Documents.pageHeight)
  321. ELSIF layout.hType = window THEN INCL(opts, Documents.winHeight)
  322. END;
  323. layout.doc.PollRect(l, t, r, b); r0 := r; b0 := b;
  324. IF layout.wType = fix THEN r := l + SHORT(ENTIER(layout.width * layout.u)) END;
  325. IF layout.hType = fix THEN b := t + SHORT(ENTIER(layout.height * layout.u)) END;
  326. IF (opts # c.opts) OR (r # r0) OR (b # b0) THEN
  327. Views.BeginScript(layout.doc, "#System:ChangeLayout", script);
  328. c.SetOpts(opts);
  329. layout.doc.SetRect(l, t, r, b);
  330. Views.EndScript(layout.doc, script)
  331. END
  332. END SetLayout;
  333. PROCEDURE InitLayoutDialog*;
  334. (* guard: WindowGuard *)
  335. VAR w: Windows.Window; c: Containers.Controller; l, t, r, b: INTEGER;
  336. BEGIN
  337. w := Windows.dir.First();
  338. IF w # NIL THEN
  339. layout.doc := w.doc;
  340. c := w.doc.ThisController();
  341. IF Documents.pageWidth IN c.opts THEN layout.wType := page
  342. ELSIF Documents.winWidth IN c.opts THEN layout.wType := window
  343. ELSE layout.wType := fix
  344. END;
  345. IF Documents.pageHeight IN c.opts THEN layout.hType := page
  346. ELSIF Documents.winHeight IN c.opts THEN layout.hType := window
  347. ELSE layout.hType := fix
  348. END;
  349. IF Dialog.metricSystem THEN layout.u := Ports.mm * 10 ELSE layout.u := Ports.inch END;
  350. w.doc.PollRect(l, t, r, b);
  351. layout.width := (r - l) DIV (layout.u DIV 100) / 100;
  352. layout.height := (b - t) DIV (layout.u DIV 100) / 100
  353. END
  354. END InitLayoutDialog;
  355. PROCEDURE WidthGuard* (VAR par: Dialog.Par);
  356. BEGIN
  357. IF layout.wType # fix THEN par.readOnly := TRUE END
  358. END WidthGuard;
  359. PROCEDURE HeightGuard* (VAR par: Dialog.Par);
  360. BEGIN
  361. IF layout.hType # fix THEN par.readOnly := TRUE END
  362. END HeightGuard;
  363. PROCEDURE TypeNotifier* (op, from, to: INTEGER);
  364. VAR w, h, l, t, r, b: INTEGER; d: BOOLEAN;
  365. BEGIN
  366. layout.doc.PollRect(l, t, r, b);
  367. IF layout.wType = page THEN
  368. layout.doc.PollPage(w, h, l, t, r, b, d)
  369. ELSIF layout.wType = window THEN
  370. layout.doc.context.GetSize(w, h); r := w - l
  371. END;
  372. layout.width := (r - l) DIV (layout.u DIV 100) / 100;
  373. layout.doc.PollRect(l, t, r, b);
  374. IF layout.hType = page THEN
  375. layout.doc.PollPage(w, h, l, t, r, b, d)
  376. ELSIF layout.hType = window THEN
  377. layout.doc.context.GetSize(w, h); b := h - t
  378. END;
  379. layout.height := (b - t) DIV (layout.u DIV 100) / 100;
  380. Dialog.Update(layout)
  381. END TypeNotifier;
  382. (** window menu command **)
  383. PROCEDURE NewWindow*;
  384. (** guard ModelViewGuard **)
  385. VAR win: Windows.Window; doc: Documents.Document; v: Views.View; title: Views.Title;
  386. seq: ANYPTR; clean: BOOLEAN;
  387. BEGIN
  388. win := Windows.dir.Focus(Controllers.frontPath);
  389. IF win # NIL THEN
  390. v := win.doc.ThisView();
  391. IF v.Domain() # NIL THEN seq := v.Domain().GetSequencer() ELSE seq := NIL END;
  392. clean := (seq # NIL) & ~seq(Sequencers.Sequencer).Dirty();
  393. doc := win.doc.DocCopyOf(v);
  394. (* Stores.InitDomain(doc, v.Domain()); *)
  395. ASSERT(doc.Domain() = v.Domain(), 100);
  396. win.GetTitle(title);
  397. Windows.dir.OpenSubWindow(Windows.dir.New(), doc, win.flags, title);
  398. IF clean THEN seq(Sequencers.Sequencer).SetDirty(FALSE) END
  399. END
  400. END NewWindow;
  401. (* properties *)
  402. PROCEDURE GetCmd (name: ARRAY OF CHAR; OUT cmd: ARRAY OF CHAR);
  403. VAR i, j: INTEGER; ch, lch: CHAR; key: ARRAY 256 OF CHAR;
  404. BEGIN
  405. i := 0; ch := name[0]; key[0] := "#"; j := 1;
  406. REPEAT
  407. key[j] := ch; INC(j); lch := ch; INC(i); ch := name[i]
  408. UNTIL (ch = 0X) OR (ch = ".")
  409. OR ((ch >= "A") & (ch <= "Z") OR (ch >= "À") & (ch # "×") & (ch <= "Þ"))
  410. & ((lch < "A") OR (lch > "Z") & (lch < "À") OR (lch = "×") OR (lch > "Þ"));
  411. IF ch = "." THEN
  412. key := "#System:" + name
  413. ELSE
  414. key[j] := ":"; INC(j); key[j] := 0X; j := 0;
  415. WHILE ch # 0X DO name[j] := ch; INC(i); INC(j); ch := name[i] END;
  416. name[j] := 0X; key := key + name
  417. END;
  418. Dialog.MapString(key, cmd);
  419. IF cmd = name THEN cmd := "" END
  420. END GetCmd;
  421. PROCEDURE SearchCmd (call: BOOLEAN; OUT found: BOOLEAN);
  422. VAR p: Properties.Property; std: BOOLEAN; v: Views.View; cmd: ARRAY 256 OF CHAR; pos, res: INTEGER;
  423. BEGIN
  424. Controllers.SetCurrentPath(Controllers.targetPath);
  425. v := Containers.FocusSingleton(); found := FALSE;
  426. IF v # NIL THEN
  427. Services.GetTypeName(v, cmd);
  428. GetCmd(cmd, cmd);
  429. IF cmd # "" THEN found := TRUE;
  430. IF call THEN Dialog.Call(cmd, "", res) END
  431. END
  432. END;
  433. std := FALSE;
  434. Properties.CollectProp(p);
  435. WHILE p # NIL DO
  436. IF p IS Properties.StdProp THEN std := TRUE
  437. ELSE
  438. Services.GetTypeName(p, cmd);
  439. GetCmd(cmd, cmd);
  440. IF cmd # "" THEN found := TRUE;
  441. IF call THEN Dialog.Call(cmd, "", res) END
  442. ELSE
  443. Services.GetTypeName(p, cmd);
  444. Strings.Find(cmd, "Desc", LEN(cmd$)-4, pos);
  445. IF LEN(cmd$)-4 = pos THEN
  446. cmd[pos] := 0X; GetCmd(cmd, cmd);
  447. IF cmd # "" THEN found := TRUE;
  448. IF call THEN Dialog.Call(cmd, "", res) END
  449. END
  450. END
  451. END
  452. END;
  453. p := p.next
  454. END;
  455. IF std & ~found THEN
  456. Dialog.MapString("#Host:Properties.StdProp", cmd);
  457. IF cmd # "Properties.StdProp" THEN found := TRUE;
  458. IF call THEN Dialog.Call(cmd, "", res) END
  459. END
  460. END;
  461. IF ~found THEN
  462. Dialog.MapString("#System:ShowProp", cmd);
  463. IF cmd # "ShowProp" THEN found := TRUE;
  464. IF call THEN Dialog.Call(cmd, "", res) END
  465. END
  466. END;
  467. Controllers.ResetCurrentPath
  468. END SearchCmd;
  469. PROCEDURE ShowProp*;
  470. VAR found: BOOLEAN;
  471. BEGIN
  472. SearchCmd(TRUE, found)
  473. END ShowProp;
  474. PROCEDURE ShowPropGuard* (VAR par: Dialog.Par);
  475. VAR found: BOOLEAN;
  476. BEGIN
  477. SearchCmd(FALSE, found);
  478. IF ~found THEN par.disabled := TRUE END
  479. END ShowPropGuard;
  480. (* container commands *)
  481. PROCEDURE ActFocus (): Containers.Controller;
  482. VAR c: Containers.Controller; v: Views.View;
  483. BEGIN
  484. c := Containers.Focus();
  485. IF c # NIL THEN
  486. v := c.ThisView();
  487. IF v IS Documents.Document THEN
  488. v := v(Documents.Document).ThisView();
  489. IF v IS Containers.View THEN
  490. c := v(Containers.View).ThisController()
  491. ELSE c := NIL
  492. END
  493. END
  494. END;
  495. RETURN c
  496. END ActFocus;
  497. PROCEDURE ToggleNoFocus*;
  498. VAR c: Containers.Controller; v: Views.View;
  499. BEGIN
  500. c := ActFocus();
  501. IF c # NIL THEN
  502. v := c.ThisView();
  503. IF ~((v IS Documents.Document) OR (Containers.noSelection IN c.opts)) THEN
  504. IF Containers.noFocus IN c.opts THEN
  505. c.SetOpts(c.opts - {Containers.noFocus})
  506. ELSE
  507. c.SetOpts(c.opts + {Containers.noFocus})
  508. END
  509. END
  510. END
  511. END ToggleNoFocus;
  512. PROCEDURE OpenAsAuxDialog*;
  513. (** create a new sub-window onto the focus view shown in the top window, mask mode **)
  514. VAR win: Windows.Window; doc: Documents.Document; v, u: Views.View; title: Views.Title;
  515. c: Containers.Controller;
  516. BEGIN
  517. v := Controllers.FocusView();
  518. IF (v # NIL) & (v IS Containers.View) & ~(v IS Documents.Document) THEN
  519. win := Windows.dir.Focus(Controllers.frontPath); ASSERT(win # NIL, 100);
  520. doc := win.doc.DocCopyOf(v);
  521. u := doc.ThisView();
  522. c := u(Containers.View).ThisController();
  523. c.SetOpts(c.opts - {Containers.noFocus} + {Containers.noCaret, Containers.noSelection});
  524. IF v # win.doc.ThisView() THEN
  525. c := doc.ThisController();
  526. c.SetOpts(c.opts - {Documents.pageWidth, Documents.pageHeight}
  527. + {Documents.winWidth, Documents.winHeight})
  528. END;
  529. (* Stores.InitDomain(doc, v.Domain()); already done in DocCopyOf *)
  530. win.GetTitle(title);
  531. Windows.dir.OpenSubWindow(Windows.dir.New(), doc,
  532. {Windows.isAux, Windows.neverDirty, Windows.noResize, Windows.noHScroll, Windows.noVScroll},
  533. title)
  534. ELSE Dialog.Beep
  535. END
  536. END OpenAsAuxDialog;
  537. PROCEDURE OpenAsToolDialog*;
  538. (** create a new sub-window onto the focus view shown in the top window, mask mode **)
  539. VAR win: Windows.Window; doc: Documents.Document; v, u: Views.View; title: Views.Title;
  540. c: Containers.Controller;
  541. BEGIN
  542. v := Controllers.FocusView();
  543. IF (v # NIL) & (v IS Containers.View) & ~(v IS Documents.Document) THEN
  544. win := Windows.dir.Focus(Controllers.frontPath); ASSERT(win # NIL, 100);
  545. doc := win.doc.DocCopyOf(v);
  546. u := doc.ThisView();
  547. c := u(Containers.View).ThisController();
  548. c.SetOpts(c.opts - {Containers.noFocus} + {Containers.noCaret, Containers.noSelection});
  549. IF v # win.doc.ThisView() THEN
  550. c := doc.ThisController();
  551. c.SetOpts(c.opts - {Documents.pageWidth, Documents.pageHeight}
  552. + {Documents.winWidth, Documents.winHeight})
  553. END;
  554. (* Stores.InitDomain(doc, v.Domain()); already done in DocCopyOf *)
  555. win.GetTitle(title);
  556. Windows.dir.OpenSubWindow(Windows.dir.New(), doc,
  557. {Windows.isTool, Windows.neverDirty, Windows.noResize, Windows.noHScroll, Windows.noVScroll},
  558. title)
  559. ELSE Dialog.Beep
  560. END
  561. END OpenAsToolDialog;
  562. PROCEDURE RecalcFocusSize*;
  563. VAR c: Containers.Controller; v: Views.View; bounds: Properties.BoundsPref;
  564. BEGIN
  565. c := Containers.Focus();
  566. IF c # NIL THEN
  567. v := c.ThisView();
  568. bounds.w := Views.undefined; bounds.h := Views.undefined;
  569. Views.HandlePropMsg(v, bounds);
  570. v.context.SetSize(bounds.w, bounds.h)
  571. END
  572. END RecalcFocusSize;
  573. PROCEDURE RecalcAllSizes*;
  574. VAR w: Windows.Window;
  575. BEGIN
  576. w := Windows.dir.First();
  577. WHILE w # NIL DO
  578. StdDialog.RecalcView(w.doc.ThisView());
  579. w := Windows.dir.Next(w)
  580. END
  581. END RecalcAllSizes;
  582. PROCEDURE SetMode(opts: SET);
  583. VAR
  584. c: Containers.Controller; v: Views.View;
  585. gm: Containers.GetOpts; sm: Containers.SetOpts;
  586. w: Windows.Window;
  587. BEGIN
  588. c := Containers.Focus();
  589. gm.valid := {};
  590. IF (c # NIL) & (c.Singleton() # NIL) THEN
  591. v := c.Singleton();
  592. Views.HandlePropMsg(v, gm);
  593. END;
  594. IF gm.valid = {} THEN
  595. w := Windows.dir.Focus(Controllers.path);
  596. IF (w # NIL) & (w.doc.ThisView() IS Containers.View) THEN v := w.doc.ThisView() ELSE v := NIL END
  597. END;
  598. IF v # NIL THEN
  599. sm.valid := {Containers.noSelection, Containers.noFocus, Containers.noCaret};
  600. sm.opts := opts;
  601. Views.HandlePropMsg(v, sm);
  602. END;
  603. END SetMode;
  604. PROCEDURE GetMode(OUT found: BOOLEAN; OUT opts: SET);
  605. VAR c: Containers.Controller; gm: Containers.GetOpts; w: Windows.Window;
  606. BEGIN
  607. c := Containers.Focus();
  608. gm.valid := {};
  609. IF (c # NIL) & (c.Singleton() # NIL) THEN
  610. Views.HandlePropMsg(c.Singleton(), gm);
  611. END;
  612. IF gm.valid = {} THEN
  613. w := Windows.dir.Focus(Controllers.path);
  614. IF (w # NIL) & (w.doc.ThisView() IS Containers.View) THEN
  615. Views.HandlePropMsg(w.doc.ThisView(), gm);
  616. END
  617. END;
  618. found := gm.valid # {};
  619. opts := gm.opts
  620. END GetMode;
  621. PROCEDURE SetMaskMode*;
  622. (* Guard: SetMaskGuard *)
  623. BEGIN
  624. SetMode({Containers.noSelection, Containers.noCaret})
  625. END SetMaskMode;
  626. PROCEDURE SetEditMode*;
  627. (* Guard: SetEditGuard *)
  628. BEGIN
  629. SetMode({})
  630. END SetEditMode;
  631. PROCEDURE SetLayoutMode*;
  632. (* Guard: SetLayoutGuard *)
  633. BEGIN
  634. SetMode({Containers.noFocus})
  635. END SetLayoutMode;
  636. PROCEDURE SetBrowserMode*;
  637. (* Guard: SetBrowserGuard *)
  638. BEGIN
  639. SetMode({Containers.noCaret})
  640. END SetBrowserMode;
  641. (* standard guards *)
  642. PROCEDURE ToggleNoFocusGuard* (VAR par: Dialog.Par);
  643. VAR c: Containers.Controller; v: Views.View;
  644. BEGIN
  645. c := ActFocus();
  646. IF c # NIL THEN
  647. v := c.ThisView();
  648. IF ~((v IS Documents.Document) OR (Containers.noSelection IN c.opts)) THEN
  649. IF Containers.noFocus IN c.opts THEN par.label := "#System:AllowFocus"
  650. ELSE par.label := "#System:PreventFocus"
  651. END
  652. ELSE par.disabled := TRUE
  653. END
  654. ELSE par.disabled := TRUE
  655. END
  656. END ToggleNoFocusGuard;
  657. PROCEDURE ReadOnlyGuard* (VAR par: Dialog.Par);
  658. BEGIN
  659. par.readOnly := TRUE
  660. END ReadOnlyGuard;
  661. PROCEDURE WindowGuard* (VAR par: Dialog.Par);
  662. VAR w: Windows.Window;
  663. BEGIN
  664. w := Windows.dir.First();
  665. IF w = NIL THEN par.disabled := TRUE END
  666. END WindowGuard;
  667. PROCEDURE ModelViewGuard* (VAR par: Dialog.Par);
  668. VAR w: Windows.Window;
  669. BEGIN
  670. w := Windows.dir.Focus(Controllers.frontPath);
  671. par.disabled := (w = NIL) OR (w.doc.ThisView().ThisModel() = NIL)
  672. END ModelViewGuard;
  673. PROCEDURE SetMaskModeGuard* (VAR par: Dialog.Par);
  674. CONST mode = {Containers.noSelection, Containers.noFocus, Containers.noCaret};
  675. VAR opts: SET; found: BOOLEAN;
  676. BEGIN
  677. GetMode(found, opts);
  678. IF found THEN
  679. par.checked := opts * mode = {Containers.noSelection, Containers.noCaret}
  680. ELSE
  681. par.disabled := TRUE
  682. END
  683. END SetMaskModeGuard;
  684. PROCEDURE SetEditModeGuard* (VAR par: Dialog.Par);
  685. CONST mode = {Containers.noSelection, Containers.noFocus, Containers.noCaret};
  686. VAR opts: SET; found: BOOLEAN;
  687. BEGIN
  688. GetMode(found, opts);
  689. IF found THEN
  690. par.checked := opts * mode = {}
  691. ELSE
  692. par.disabled := TRUE
  693. END
  694. END SetEditModeGuard;
  695. PROCEDURE SetLayoutModeGuard* (VAR par: Dialog.Par);
  696. CONST mode = {Containers.noSelection, Containers.noFocus, Containers.noCaret};
  697. VAR opts: SET; found: BOOLEAN;
  698. BEGIN
  699. GetMode(found, opts);
  700. IF found THEN
  701. par.checked := opts * mode = {Containers.noFocus}
  702. ELSE
  703. par.disabled := TRUE
  704. END
  705. END SetLayoutModeGuard;
  706. PROCEDURE SetBrowserModeGuard* (VAR par: Dialog.Par);
  707. CONST mode = {Containers.noSelection, Containers.noFocus, Containers.noCaret};
  708. VAR opts: SET; found: BOOLEAN;
  709. BEGIN
  710. GetMode(found, opts);
  711. IF found THEN
  712. par.checked := opts * mode = {Containers.noCaret}
  713. ELSE
  714. par.disabled := TRUE
  715. END
  716. END SetBrowserModeGuard;
  717. PROCEDURE SelectionGuard* (VAR par: Dialog.Par);
  718. VAR ops: Controllers.PollOpsMsg;
  719. BEGIN
  720. Controllers.PollOps(ops);
  721. IF ops.valid * {Controllers.cut, Controllers.copy} = {} THEN par.disabled := TRUE END
  722. END SelectionGuard;
  723. PROCEDURE SingletonGuard* (VAR par: Dialog.Par);
  724. VAR ops: Controllers.PollOpsMsg;
  725. BEGIN
  726. Controllers.PollOps(ops);
  727. IF ops.singleton = NIL THEN par.disabled := TRUE END
  728. END SingletonGuard;
  729. PROCEDURE SelectAllGuard* (VAR par: Dialog.Par);
  730. VAR ops: Controllers.PollOpsMsg;
  731. BEGIN
  732. Controllers.PollOps(ops);
  733. IF ~ops.selectable THEN par.disabled := TRUE END
  734. END SelectAllGuard;
  735. PROCEDURE CaretGuard* (VAR par: Dialog.Par);
  736. VAR ops: Controllers.PollOpsMsg;
  737. BEGIN
  738. Controllers.PollOps(ops);
  739. IF ops.valid * {Controllers.pasteChar .. Controllers.paste} = {} THEN par.disabled := TRUE END
  740. END CaretGuard;
  741. PROCEDURE PasteCharGuard* (VAR par: Dialog.Par);
  742. VAR ops: Controllers.PollOpsMsg;
  743. BEGIN
  744. Controllers.PollOps(ops);
  745. IF ~(Controllers.pasteChar IN ops.valid) THEN par.disabled := TRUE END
  746. END PasteCharGuard;
  747. PROCEDURE PasteLCharGuard* (VAR par: Dialog.Par);
  748. VAR ops: Controllers.PollOpsMsg;
  749. BEGIN
  750. Controllers.PollOps(ops);
  751. IF ~(Controllers.pasteChar IN ops.valid) THEN par.disabled := TRUE END
  752. END PasteLCharGuard;
  753. PROCEDURE PasteViewGuard* (VAR par: Dialog.Par);
  754. VAR ops: Controllers.PollOpsMsg;
  755. BEGIN
  756. Controllers.PollOps(ops);
  757. IF ~(Controllers.paste IN ops.valid) THEN par.disabled := TRUE END
  758. END PasteViewGuard;
  759. PROCEDURE ContainerGuard* (VAR par: Dialog.Par);
  760. BEGIN
  761. IF Containers.Focus() = NIL THEN par.disabled := TRUE END
  762. END ContainerGuard;
  763. PROCEDURE UndoGuard* (VAR par: Dialog.Par);
  764. VAR f: Windows.Window; opName: Stores.OpName;
  765. BEGIN
  766. Dialog.MapString("#System:Undo", par.label);
  767. f := Windows.dir.Focus(Controllers.frontPath);
  768. IF (f # NIL) & f.seq.CanUndo() THEN
  769. f.seq.GetUndoName(opName);
  770. Dialog.MapString(opName, opName);
  771. Append(par.label, " ");
  772. Append(par.label, opName)
  773. ELSE
  774. par.disabled := TRUE
  775. END
  776. END UndoGuard;
  777. PROCEDURE RedoGuard* (VAR par: Dialog.Par);
  778. VAR f: Windows.Window; opName: Stores.OpName;
  779. BEGIN
  780. Dialog.MapString("#System:Redo", par.label);
  781. f := Windows.dir.Focus(Controllers.frontPath);
  782. IF (f # NIL) & f.seq.CanRedo() THEN
  783. f.seq.GetRedoName(opName);
  784. Dialog.MapString(opName, opName);
  785. Append(par.label, " ");
  786. Append(par.label, opName)
  787. ELSE
  788. par.disabled := TRUE
  789. END
  790. END RedoGuard;
  791. PROCEDURE PlainGuard* (VAR par: Dialog.Par);
  792. VAR props: Properties.StdProp;
  793. BEGIN
  794. props := StdProp();
  795. IF props.known * {Properties.style, Properties.weight} # {} THEN
  796. par.checked := (Properties.style IN props.valid)
  797. & (props.style.val = {}) & ({Fonts.italic, Fonts.underline, Fonts.strikeout} - props.style.mask = {})
  798. & (Properties.weight IN props.valid) & (props.weight = Fonts.normal)
  799. ELSE
  800. par.disabled := TRUE
  801. END
  802. END PlainGuard;
  803. PROCEDURE BoldGuard* (VAR par: Dialog.Par);
  804. VAR props: Properties.StdProp;
  805. BEGIN
  806. props := StdProp();
  807. IF Properties.weight IN props.known THEN
  808. par.checked := (Properties.weight IN props.valid) & (props.weight = Fonts.bold)
  809. ELSE
  810. par.disabled := TRUE
  811. END
  812. END BoldGuard;
  813. PROCEDURE ItalicGuard* (VAR par: Dialog.Par);
  814. VAR props: Properties.StdProp;
  815. BEGIN
  816. props := StdProp();
  817. IF Properties.style IN props.known THEN
  818. par.checked := (Properties.style IN props.valid) & (Fonts.italic IN props.style.val)
  819. ELSE
  820. par.disabled := TRUE
  821. END
  822. END ItalicGuard;
  823. PROCEDURE UnderlineGuard* (VAR par: Dialog.Par);
  824. VAR props: Properties.StdProp;
  825. BEGIN
  826. props := StdProp();
  827. IF Properties.style IN props.known THEN
  828. par.checked := (Properties.style IN props.valid) & (Fonts.underline IN props.style.val)
  829. ELSE
  830. par.disabled := TRUE
  831. END
  832. END UnderlineGuard;
  833. PROCEDURE StrikeoutGuard* (VAR par: Dialog.Par);
  834. VAR props: Properties.StdProp;
  835. BEGIN
  836. props := StdProp();
  837. IF Properties.style IN props.known THEN
  838. par.checked := (Properties.style IN props.valid) & (Fonts.strikeout IN props.style.val)
  839. ELSE
  840. par.disabled := TRUE
  841. END
  842. END StrikeoutGuard;
  843. PROCEDURE SizeGuard* (size: INTEGER; VAR par: Dialog.Par);
  844. VAR props: Properties.StdProp;
  845. BEGIN
  846. props := StdProp();
  847. IF Properties.size IN props.known THEN
  848. par.checked := (Properties.size IN props.valid) & (size = props.size DIV Ports.point)
  849. ELSE
  850. par.disabled := TRUE
  851. END
  852. END SizeGuard;
  853. PROCEDURE ColorGuard* (color: INTEGER; VAR par: Dialog.Par);
  854. VAR props: Properties.StdProp;
  855. BEGIN
  856. props := StdProp();
  857. IF Properties.color IN props.known THEN
  858. par.checked := (Properties.color IN props.valid) & (color = props.color.val)
  859. ELSE
  860. par.disabled := TRUE
  861. END
  862. END ColorGuard;
  863. PROCEDURE DefaultFontGuard* (VAR par: Dialog.Par);
  864. VAR props: Properties.StdProp;
  865. BEGIN
  866. props := StdProp();
  867. IF Properties.typeface IN props.known THEN
  868. par.checked := (Properties.typeface IN props.valid) & (props.typeface = Fonts.default)
  869. ELSE
  870. par.disabled := TRUE
  871. END
  872. END DefaultFontGuard;
  873. PROCEDURE TypefaceGuard* (VAR par: Dialog.Par);
  874. VAR props: Properties.StdProp;
  875. BEGIN
  876. props := StdProp();
  877. IF ~(Properties.typeface IN props.known) THEN par.disabled := TRUE END
  878. END TypefaceGuard;
  879. (* standard notifiers *)
  880. PROCEDURE DefaultOnDoubleClick* (op, from, to: INTEGER);
  881. VAR msg: Controllers.EditMsg; c: Containers.Controller;
  882. BEGIN
  883. IF (op = Dialog.pressed) & (from = 1) THEN
  884. Controllers.SetCurrentPath(Controllers.frontPath);
  885. c := Containers.Focus();
  886. Controllers.ResetCurrentPath;
  887. IF {Containers.noSelection, Containers.noCaret} - c.opts = {} THEN
  888. msg.op := Controllers.pasteChar;
  889. msg.char := 0DX; msg.modifiers := {};
  890. Controllers.ForwardVia(Controllers.frontPath, msg)
  891. END
  892. END
  893. END DefaultOnDoubleClick;
  894. PROCEDURE Init;
  895. BEGIN
  896. allocator := defaultAllocator;
  897. propEra := -1
  898. END Init;
  899. BEGIN
  900. Init
  901. END StdCmds.