Commanders.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. MODULE DevCommanders;
  2. (* THIS IS TEXT COPY OF BlackBox 1.6-rc6 Dev/Mod/Commanders.odc *)
  3. (* DO NOT EDIT *)
  4. IMPORT
  5. Kernel, Fonts, Ports, Stores, Models, Views, Controllers, Properties, Dialog, Controls,
  6. TextModels, TextSetters, TextMappers, Services, StdLog;
  7. CONST
  8. (* additional Scan types *)
  9. ident = 19; qualident = 20; execMark = 21;
  10. point = Ports.point;
  11. minVersion = 0; maxVersion = 0; maxStdVersion = 0;
  12. TYPE
  13. View* = POINTER TO ABSTRACT RECORD (Views.View)
  14. END;
  15. EndView* = POINTER TO ABSTRACT RECORD (Views.View)
  16. END;
  17. Par* = POINTER TO RECORD
  18. text*: TextModels.Model;
  19. beg*, end*: INTEGER
  20. END;
  21. Directory* = POINTER TO ABSTRACT RECORD END;
  22. StdView = POINTER TO RECORD (View) END;
  23. StdEndView = POINTER TO RECORD (EndView) END;
  24. StdDirectory = POINTER TO RECORD (Directory) END;
  25. Scanner = RECORD
  26. s: TextMappers.Scanner;
  27. ident: ARRAY LEN(Kernel.Name) OF CHAR;
  28. qualident: ARRAY LEN(Kernel.Name) * 2 - 1 OF CHAR
  29. END;
  30. TrapCleaner = POINTER TO RECORD (Kernel.TrapCleaner) END;
  31. VAR
  32. par*: Par;
  33. dir-, stdDir-: Directory;
  34. cleaner: TrapCleaner;
  35. cleanerInstalled: BOOLEAN;
  36. (** Cleaner **)
  37. PROCEDURE (c: TrapCleaner) Cleanup;
  38. BEGIN
  39. par := NIL;
  40. cleanerInstalled := FALSE;
  41. END Cleanup;
  42. (** View **)
  43. PROCEDURE (v: View) Externalize- (VAR wr: Stores.Writer), EXTENSIBLE;
  44. BEGIN
  45. v.Externalize^(wr);
  46. wr.WriteVersion(maxVersion);
  47. wr.WriteXInt(execMark)
  48. END Externalize;
  49. PROCEDURE (v: View) Internalize- (VAR rd: Stores.Reader), EXTENSIBLE;
  50. VAR thisVersion, type: INTEGER;
  51. BEGIN
  52. v.Internalize^(rd);
  53. IF rd.cancelled THEN RETURN END;
  54. rd.ReadVersion(minVersion, maxVersion, thisVersion);
  55. IF rd.cancelled THEN RETURN END;
  56. rd.ReadXInt(type)
  57. END Internalize;
  58. (** Directory **)
  59. PROCEDURE (d: Directory) New* (): View, NEW, ABSTRACT;
  60. PROCEDURE (d: Directory) NewEnd* (): EndView, NEW, ABSTRACT;
  61. (* auxilliary procedures *)
  62. PROCEDURE IsIdent (VAR s: ARRAY OF CHAR): BOOLEAN;
  63. VAR i: INTEGER; ch: CHAR;
  64. BEGIN
  65. ch := s[0]; i := 1;
  66. IF ("A" <= CAP(ch)) & (CAP(ch) <= "Z") OR (ch >= 0C0X) & (ch # "×") & (ch # "÷") & (ch <= 0FFX) OR (ch = "_") THEN
  67. REPEAT
  68. ch := s[i]; INC(i)
  69. UNTIL ~( ("0" <= ch) & (ch <= "9") OR ("A" <= CAP(ch)) & (CAP(ch) <= "Z")
  70. OR (ch >= 0C0X) & (ch # "×") & (ch # "÷") & (ch <= 0FFX) OR (ch = "_") );
  71. RETURN (ch = 0X) & (i <= LEN(Kernel.Name))
  72. ELSE
  73. RETURN FALSE
  74. END
  75. END IsIdent;
  76. PROCEDURE Scan (VAR s: Scanner);
  77. VAR done: BOOLEAN;
  78. BEGIN
  79. s.s.Scan;
  80. IF (s.s.type = TextMappers.view) THEN
  81. IF Properties.ThisType(s.s.view, "DevCommanders.View") # NIL THEN s.s.type := execMark END
  82. ELSIF (s.s.type = TextMappers.string) & TextMappers.IsQualIdent(s.s.string) THEN
  83. s.s.type := qualident; s.qualident := s.s.string$
  84. ELSIF (s.s.type = TextMappers.string) & IsIdent(s.s.string) THEN
  85. s.ident := s.s.string$;
  86. TextMappers.ScanQualIdent(s.s, s.qualident, done);
  87. IF done THEN s.s.type := qualident ELSE s.s.type := ident END
  88. END
  89. END Scan;
  90. PROCEDURE GetParExtend (r: TextModels.Reader; VAR end: INTEGER);
  91. VAR v, v1: Views.View;
  92. BEGIN
  93. REPEAT r.ReadView(v);
  94. IF v # NIL THEN
  95. v1 := v;
  96. v := Properties.ThisType(v1, "DevCommanders.View") ;
  97. IF v = NIL THEN v := Properties.ThisType(v1, "DevCommanders.EndView") END
  98. END
  99. UNTIL r.eot OR (v # NIL);
  100. end := r.Pos(); IF ~r.eot THEN DEC(end) END
  101. END GetParExtend;
  102. PROCEDURE Unload (cmd: Dialog.String);
  103. VAR modname: Kernel.Name; str: Dialog.String; i: INTEGER; ch: CHAR; mod: Kernel.Module;
  104. BEGIN
  105. i := 0; ch := cmd[0];
  106. WHILE (ch # 0X) & (ch # ".") DO modname[i] := SHORT(ch); INC(i); ch := cmd[i] END;
  107. modname[i] := 0X;
  108. mod := Kernel.ThisLoadedMod(modname);
  109. IF mod # NIL THEN
  110. Kernel.UnloadMod(mod);
  111. IF mod.refcnt < 0 THEN
  112. str := modname$;
  113. Dialog.MapParamString("#Dev:Unloaded", str, "", "", str);
  114. StdLog.String(str); StdLog.Ln;
  115. Controls.Relink
  116. ELSE
  117. str := modname$;
  118. Dialog.ShowParamMsg("#Dev:UnloadingFailed", str, "", "")
  119. END
  120. END
  121. END Unload;
  122. PROCEDURE Execute (t: TextModels.Model; pos: INTEGER; VAR end: INTEGER; unload: BOOLEAN);
  123. VAR s: Scanner; beg, res: INTEGER; cmd: Dialog.String;
  124. BEGIN
  125. end := t.Length();
  126. s.s.ConnectTo(t); s.s.SetPos(pos); s.s.SetOpts({TextMappers.returnViews});
  127. Scan(s); ASSERT(s.s.type = execMark, 100);
  128. Scan(s);
  129. IF s.s.type IN {qualident, TextMappers.string} THEN
  130. beg := s.s.Pos() - 1; GetParExtend(s.s.rider, end);
  131. ASSERT(~cleanerInstalled, 101);
  132. Kernel.PushTrapCleaner(cleaner); cleanerInstalled := TRUE;
  133. NEW(par); par.text := t; par.beg := beg; par.end := end;
  134. IF s.s.type = qualident THEN cmd := s.qualident$ ELSE cmd := s.s.string$ END;
  135. IF unload (* & (s.s.type = qualident)*) THEN Unload(cmd) END;
  136. Dialog.Call(cmd, " ", res);
  137. par := NIL;
  138. Kernel.PopTrapCleaner(cleaner); cleanerInstalled := FALSE;
  139. END
  140. END Execute;
  141. PROCEDURE Track (v: View; f: Views.Frame; x, y: INTEGER; buttons: SET);
  142. VAR c: Models.Context; w, h, end: INTEGER; isDown, in, in0: BOOLEAN; m: SET;
  143. BEGIN
  144. c := v.context; c.GetSize(w, h); in0 := FALSE; in := TRUE;
  145. REPEAT
  146. IF in # in0 THEN
  147. f.MarkRect(0, 0, w, h, Ports.fill, Ports.invert, Ports.show); in0 := in
  148. END;
  149. f.Input(x, y, m, isDown);
  150. in := (0 <= x) & (x < w) & (0 <= y) & (y < h)
  151. UNTIL ~isDown;
  152. IF in0 THEN
  153. f.MarkRect(0, 0, w, h, Ports.fill, Ports.invert, Ports.hide);
  154. WITH c:TextModels.Context DO
  155. Execute(c.ThisModel(), c.Pos(), end,Controllers.modify IN buttons)
  156. ELSE Dialog.Beep
  157. END
  158. END
  159. END Track;
  160. (* StdView *)
  161. PROCEDURE (v: StdView) Externalize (VAR wr: Stores.Writer);
  162. BEGIN
  163. v.Externalize^(wr);
  164. wr.WriteVersion(maxStdVersion)
  165. END Externalize;
  166. PROCEDURE (v: StdView) Internalize (VAR rd: Stores.Reader);
  167. VAR thisVersion: INTEGER;
  168. BEGIN
  169. v.Internalize^(rd);
  170. IF rd.cancelled THEN RETURN END;
  171. rd.ReadVersion(minVersion, maxStdVersion, thisVersion)
  172. END Internalize;
  173. PROCEDURE (v: StdView) Restore (f: Views.Frame; l, t, r, b: INTEGER);
  174. CONST u = point;
  175. VAR c: Models.Context; a: TextModels.Attributes; font: Fonts.Font; color: Ports.Color;
  176. size, d, w, asc, dsc, fw: INTEGER; s: ARRAY 2 OF CHAR;
  177. BEGIN
  178. ASSERT(v.context # NIL, 20);
  179. c := v.context;
  180. WITH c: TextModels.Context DO a := c.Attr(); font := a.font; color := a.color
  181. ELSE font := Fonts.dir.Default(); color := Ports.defaultColor
  182. END;
  183. font.GetBounds(asc, dsc, fw);
  184. size := asc + dsc; d := size DIV 2;
  185. f.DrawOval(u, 0, u + size, size, Ports.fill, color);
  186. s := "!";
  187. w := font.StringWidth(s);
  188. f.DrawString(u + d - w DIV 2, size - dsc, Ports.background, s, font)
  189. END Restore;
  190. PROCEDURE (v: StdView) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message;
  191. VAR focus: Views.View);
  192. BEGIN
  193. WITH msg: Controllers.TrackMsg DO
  194. Track(v, f, msg.x, msg.y, msg.modifiers)
  195. | msg: Controllers.PollCursorMsg DO
  196. msg.cursor := Ports.refCursor
  197. ELSE
  198. END
  199. END HandleCtrlMsg;
  200. PROCEDURE (v: StdView) HandlePropMsg (VAR msg: Properties.Message);
  201. VAR c: Models.Context; a: TextModels.Attributes; font: Fonts.Font; asc, dsc, fw: INTEGER;
  202. BEGIN
  203. WITH msg: Properties.Preference DO
  204. WITH msg: Properties.SizePref DO
  205. c := v.context;
  206. IF (c # NIL) & (c IS TextModels.Context) THEN
  207. a := c(TextModels.Context).Attr(); font := a.font
  208. ELSE font := Fonts.dir.Default()
  209. END;
  210. font.GetBounds(asc, dsc, fw);
  211. msg.h := asc + dsc; msg.w := msg.h + 2 * point
  212. | msg: Properties.ResizePref DO
  213. msg.fixed := TRUE
  214. | msg: Properties.FocusPref DO
  215. msg.hotFocus := TRUE
  216. | msg: TextSetters.Pref DO
  217. c := v.context;
  218. IF (c # NIL) & (c IS TextModels.Context) THEN
  219. a := c(TextModels.Context).Attr(); font := a.font
  220. ELSE font := Fonts.dir.Default()
  221. END;
  222. font.GetBounds(asc, msg.dsc, fw)
  223. | msg: Properties.TypePref DO
  224. IF Services.Is(v, msg.type) THEN msg.view := v END
  225. ELSE
  226. END
  227. ELSE
  228. END
  229. END HandlePropMsg;
  230. (* StdEndView *)
  231. PROCEDURE (v: StdEndView) Restore (f: Views.Frame; l, t, r, b: INTEGER);
  232. CONST u = point;
  233. VAR c: Models.Context; a: TextModels.Attributes; font: Fonts.Font; color: Ports.Color;
  234. size, w, asc, dsc, fw: INTEGER; s: ARRAY 2 OF CHAR;
  235. points: ARRAY 3 OF Ports.Point;
  236. BEGIN
  237. ASSERT(v.context # NIL, 20);
  238. c := v.context;
  239. WITH c: TextModels.Context DO a := c.Attr(); font := a.font; color := a.color
  240. ELSE font := Fonts.dir.Default(); color := Ports.defaultColor
  241. END;
  242. font.GetBounds(asc, dsc, fw);
  243. size := asc + dsc;
  244. points[0].x := 0; points[0].y := size;
  245. points[1].x := u + (size DIV 2); points[1].y := size DIV 2;
  246. points[2].x := u + (size DIV 2); points[2].y := size;
  247. f.DrawPath(points, 3, Ports.fill, color, Ports.closedPoly)
  248. END Restore;
  249. PROCEDURE (v: StdEndView) HandlePropMsg (VAR msg: Properties.Message);
  250. VAR c: Models.Context; a: TextModels.Attributes; font: Fonts.Font; asc, dsc, fw: INTEGER;
  251. BEGIN
  252. WITH msg: Properties.Preference DO
  253. WITH msg: Properties.SizePref DO
  254. c := v.context;
  255. IF (c # NIL) & (c IS TextModels.Context) THEN
  256. a := c(TextModels.Context).Attr(); font := a.font
  257. ELSE font := Fonts.dir.Default()
  258. END;
  259. font.GetBounds(asc, dsc, fw);
  260. msg.h := asc + dsc; msg.w := (msg.h + 2 * point) DIV 2
  261. | msg: Properties.ResizePref DO
  262. msg.fixed := TRUE
  263. | msg: Properties.FocusPref DO
  264. msg.hotFocus := TRUE
  265. | msg: TextSetters.Pref DO
  266. c := v.context;
  267. IF (c # NIL) & (c IS TextModels.Context) THEN
  268. a := c(TextModels.Context).Attr(); font := a.font
  269. ELSE font := Fonts.dir.Default()
  270. END;
  271. font.GetBounds(asc, msg.dsc, fw)
  272. | msg: Properties.TypePref DO
  273. IF Services.Is(v, msg.type) THEN msg.view := v END
  274. ELSE
  275. END
  276. ELSE
  277. END
  278. END HandlePropMsg;
  279. (* StdDirectory *)
  280. PROCEDURE (d: StdDirectory) New (): View;
  281. VAR v: StdView;
  282. BEGIN
  283. NEW(v); RETURN v
  284. END New;
  285. PROCEDURE (d: StdDirectory) NewEnd (): EndView;
  286. VAR v: StdEndView;
  287. BEGIN
  288. NEW(v); RETURN v
  289. END NewEnd;
  290. PROCEDURE Deposit*;
  291. BEGIN
  292. Views.Deposit(dir.New())
  293. END Deposit;
  294. PROCEDURE DepositEnd*;
  295. BEGIN
  296. Views.Deposit(dir.NewEnd())
  297. END DepositEnd;
  298. PROCEDURE SetDir* (d: Directory);
  299. BEGIN
  300. dir := d
  301. END SetDir;
  302. PROCEDURE Init;
  303. VAR d: StdDirectory;
  304. BEGIN
  305. NEW(d); dir := d; stdDir := d;
  306. NEW(cleaner); cleanerInstalled := FALSE;
  307. END Init;
  308. BEGIN
  309. Init
  310. END DevCommanders.