WMWindowManager.Mod 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. MODULE WMWindowManager; (** AUTHOR "TF"; PURPOSE "Generic window manager"; *)
  2. IMPORT
  3. Modules, KernelLog, Plugins, Locks, Strings, Messages := WMMessages, Graphics := WMGraphics, Raster, Rectangles := WMRectangles;
  4. CONST
  5. FlagFrame* = 0; (** The window has a frame *)
  6. FlagClose* = 1; (** The window offers a close button; only frame windows *)
  7. FlagMinimize* = 2; (** The window offers a minimize button; only frame windows *)
  8. FlagStayOnTop* = 3; (** The window will always stay above all non stay on top windows *)
  9. FlagNonDispatched* = 4; (** The window has no message queue --> BE CAREFUL *)
  10. FlagNoFocus* = 5; (** The window can never get the keyboard focus *)
  11. FlagDecorWindow* = 6; (** The window is a decor window, associated to a master window *)
  12. FlagStayOnBottom* = 7; (** The window can not be moved up *)
  13. FlagNavigation* = 8; (** The window will always appear at the same position/size on the screen independent of the range of the viewport displaying it. *)
  14. FlagHidden* = 9; (** This flag indicates whether a window should be managed by window navigation tools. It does not influence the visibiliy or behaviour of the window *)
  15. FlagNoResizing* = 10; (** If set, window resizing is disabled *)
  16. FlagNoPointer*=11; (* if set, in window there will be no pointer visible --> touch screens *)
  17. FlagStorable*=12; (* window storable*)
  18. SizeMinHeight = 3; (* Minimum height of a window *)
  19. SizeMinWidth = 3; (* Minimum width of a window *)
  20. (* result codes for Window.OpenDocument *)
  21. Ok* = 0;
  22. Error* = 1;
  23. NotSupported* = 2;
  24. (* Window position for new windows added *)
  25. X0 = 30;
  26. Y0 = 80;
  27. TYPE
  28. Rectangle = Rectangles.Rectangle;
  29. String = Strings.String;
  30. Message = Messages.Message;
  31. RealRect* = RECORD l*, t*, r*, b* : REAL END;
  32. PointerInfo* = OBJECT
  33. VAR hotX*, hotY* : LONGINT; img* : Graphics.Image;
  34. END PointerInfo;
  35. (** All fields are read-only except for the module SkinEngine.Mod!
  36. Modifications of the instance that is owned by the window manager require
  37. the window manager write lock being held!
  38. Most of the information is used by WMDefaultWindows.Mod *)
  39. WindowStyle* = OBJECT
  40. VAR
  41. (** use bitmaps for frame windows? *)
  42. useBitmaps* : BOOLEAN;
  43. (** frame color if not using bitmaps (a = active, i = inactive) *)
  44. baCol*, biCol* : LONGINT;
  45. (** frame shading width if not using bitmaps (a = active, i = inactive) *)
  46. basw*, bisw* : LONGINT;
  47. (** height / width of frame windows th = top height, bh = bottom height, lw = left width, rw = right width *)
  48. th*, bh*, lw*, rw* : LONGINT;
  49. (** frame window bitmaps
  50. 1st letter: t = top, l = left, r = right, b = bottom decor window
  51. 2nd letter: a = active, i = inactive
  52. 3rd letter: a = left bitmap, b = middle bitmap (repeated), c = right bitmap
  53. *)
  54. taa*, tab*, tac*, tia*, tib*, tic*,
  55. laa*, lab*, lac*, lia*, lib*, lic*,
  56. raa*, rab*, rac*, ria*, rib*, ric*,
  57. baa*, bab*, bac*, bia*, bib*, bic* : Graphics.Image;
  58. (** Close and minimize button images (a = active, i = inactive) *)
  59. ca*, ci*, closeHover*,
  60. ma*, mi*, minimizeHover* : Graphics.Image;
  61. minimizeOffset* : LONGINT; (** offset correction for minimize button *)
  62. (** Window title position and color (a = active, i = inactive) *)
  63. atextX*, atextY*, atextColor*, itextX*, itextY*, itextColor* : LONGINT;
  64. bgColor*, fgColor*, selectCol*, desktopColor* : Graphics.Color;
  65. topFocusThreshold*, topThreshold*, bottomFocusThreshold*, bottomThreshold*,
  66. leftFocusThreshold*, leftThreshold*, rightFocusThreshold*, rightThreshold* : LONGINT;
  67. (* Initialize/reset to zero-style for windows *)
  68. PROCEDURE &Init*;
  69. BEGIN
  70. useBitmaps := FALSE;
  71. baCol := 0FFFFH; biCol := 0FF40H;
  72. basw := 4; bisw := 3;
  73. th := 20; bh := 3; lw := 3; rw := 3;
  74. (* images *)
  75. taa := NIL; tab := NIL; tac := NIL; tia := NIL; tib := NIL; tic := NIL;
  76. laa := NIL; lab := NIL; lac := NIL; lia := NIL; lib := NIL; lic := NIL;
  77. raa := NIL; rab := NIL; rac := NIL; ria := NIL; rib := NIL; ric := NIL;
  78. baa := NIL; bab := NIL; bac := NIL; bia := NIL; bib := NIL; bic := NIL;
  79. ca := Graphics.LoadImage("ZeroSkin.zip://aclose.png", TRUE);
  80. ci := Graphics.LoadImage("ZeroSkin.zip://iclose.png", TRUE);
  81. closeHover := NIL;
  82. ma := NIL; mi := NIL; minimizeHover := NIL;
  83. minimizeOffset := 0;
  84. (* window caption *)
  85. atextX := 5; atextY := 15; atextColor := LONGINT(0FFFF00FFH);
  86. itextX := 5; itextY := 15; itextColor := 04444FFH;
  87. (* desktop *)
  88. bgColor := LONGINT(08080FFFFH);
  89. fgColor := 0000000FFH;
  90. selectCol := 0FFFFH;
  91. desktopColor := LONGINT(08080FFFFH);
  92. topFocusThreshold := 0; topThreshold := 0;
  93. bottomFocusThreshold := 0; bottomThreshold := 0;
  94. leftFocusThreshold := 0; leftThreshold := 0;
  95. rightFocusThreshold := 0; rightThreshold := 0;
  96. END Init;
  97. (** calculate distances from images *)
  98. PROCEDURE Initialize*;
  99. BEGIN
  100. IF useBitmaps THEN
  101. IF tab # NIL THEN th := tab.height END;
  102. IF bab # NIL THEN bh := bab.height END;
  103. IF lab # NIL THEN lw := lab.width END;
  104. IF rab # NIL THEN rw := rab.width END;
  105. END
  106. END Initialize;
  107. END WindowStyle;
  108. DragInfo* = OBJECT
  109. VAR
  110. data*, sender* : ANY;
  111. onAccept*, onReject* : Messages.CompCommand;
  112. offsetX*, offsetY*: LONGINT;
  113. END DragInfo;
  114. (** List of decoration - windows to a master window *)
  115. DecorList* = OBJECT
  116. VAR next* : DecorList;
  117. w* : Window;
  118. END DecorList;
  119. (** A message preview procedure can set discard to TRUE to discard the message *)
  120. MessagePreviewProc* = PROCEDURE (VAR msg : Message; VAR discard : BOOLEAN);
  121. MessagePreviewList* = OBJECT
  122. VAR proc*: MessagePreviewProc;
  123. next*:MessagePreviewList;
  124. END MessagePreviewList;
  125. DocumentInfo* = RECORD
  126. id* : LONGINT;
  127. name* : ARRAY 32 OF CHAR; (* if name = "", this document info is not valid *)
  128. fullname* : ARRAY 256 OF CHAR;
  129. modified*, hasFocus* : BOOLEAN;
  130. END;
  131. VisualComponentInfo* = RECORD
  132. width*, height* : LONGINT; (* preferred width and height of visual component *)
  133. generator* : PROCEDURE {DELEGATE} () : ANY; (* NIL if no visual component available *)
  134. END;
  135. (** A window may provide information about currently opened documents. Additionally, it can provide a visual component that controls it. *)
  136. WindowInfo* = RECORD
  137. openDocuments* : ARRAY 16 OF DocumentInfo;
  138. handleDocumentInfo* : PROCEDURE {DELEGATE} (CONST info : DocumentInfo; new : BOOLEAN; VAR res : LONGINT);
  139. vc* : VisualComponentInfo;
  140. END;
  141. WindowInfoPtr = POINTER TO WindowInfo;
  142. Window* = OBJECT
  143. VAR
  144. id- : LONGINT;
  145. timestamp* : LONGINT; (* incremented at each call of procedure Draw *)
  146. (** Ranges in global coordinates *)
  147. bounds* : Rectangle; (** current range *)
  148. initialBounds* : Rectangle; (** range at window creation *)
  149. normalBounds* : Rectangle; (** range before toggling to fullscreen *)
  150. manager* : WindowManager;
  151. sequencer* : Messages.MsgSequencer;
  152. (** window state that may only be accessed by the window manager *)
  153. prev*, next* : Window; (** previous and next window in z order *)
  154. title : String; (* window title *)
  155. info* : WindowInfoPtr;
  156. master* : Window; (** is only set if the window is a decor window *)
  157. view* : ViewPort;
  158. decor* : DecorList;
  159. flags* : SET;
  160. icon* : Graphics.Image; (** Optional icon for Window *)
  161. topW*, bottomW*, leftW*, rightW* : Window; (** Optional decor windows *)
  162. useAlpha* : BOOLEAN;
  163. isVisible* : BOOLEAN;
  164. pointerInfo- : PointerInfo;
  165. acceptDrag : BOOLEAN;
  166. reduceQuality- : BOOLEAN;
  167. PROCEDURE &Init*(w, h : LONGINT; alpha : BOOLEAN);
  168. BEGIN
  169. id := GetId();
  170. timestamp := 0;
  171. bounds := Graphics.MakeRectangle(0, 0, w, h);
  172. initialBounds := bounds;
  173. normalBounds := bounds;
  174. manager := NIL; sequencer := NIL;
  175. prev := NIL; next := NIL;
  176. title := NIL;
  177. info := NIL;
  178. master := NIL; decor := NIL;
  179. view := NIL;
  180. flags := {};
  181. icon := NIL;
  182. topW := NIL; bottomW := NIL; leftW := NIL; rightW := NIL;
  183. useAlpha := alpha;
  184. isVisible := TRUE;
  185. pointerInfo := NIL;
  186. acceptDrag := FALSE;
  187. reduceQuality := FALSE;
  188. END Init;
  189. PROCEDURE IsCallFromSequencer*() : BOOLEAN;
  190. BEGIN
  191. RETURN (sequencer # NIL) & (sequencer.IsCallFromSequencer())
  192. END IsCallFromSequencer;
  193. (** Return the window manager that handles the window *)
  194. PROCEDURE GetManager*() : WindowManager;
  195. BEGIN
  196. RETURN manager
  197. END GetManager;
  198. (** Set the window title as UTF8 string. *)
  199. PROCEDURE SetTitle*(title : String);
  200. BEGIN
  201. IF manager # NIL THEN manager.SetWindowTitle(SELF, title) ELSE SELF.title := title END
  202. END SetTitle;
  203. (** Return the title as UTF8 string. Returns NIL if no title is set *)
  204. PROCEDURE GetTitle*() : String;
  205. BEGIN
  206. IF manager # NIL THEN RETURN manager.GetWindowTitle(SELF) ELSE RETURN title END
  207. END GetTitle;
  208. PROCEDURE SetIcon*(icon : Graphics.Image);
  209. BEGIN
  210. IF (manager # NIL) THEN manager.SetWindowIcon(SELF, icon); ELSE SELF.icon := icon; END;
  211. END SetIcon;
  212. (** Return the height in client space *) (* go via manager *)
  213. PROCEDURE GetHeight*() : LONGINT;
  214. BEGIN
  215. RETURN bounds.b - bounds.t
  216. END GetHeight;
  217. (** Return the width in client space *) (* go via manager *)
  218. PROCEDURE GetWidth*() : LONGINT;
  219. BEGIN
  220. RETURN bounds.r - bounds.l
  221. END GetWidth;
  222. PROCEDURE SetInfo*(CONST info : WindowInfo);
  223. BEGIN
  224. IF (manager # NIL) THEN
  225. manager.SetWindowInfo(SELF, info);
  226. ELSE
  227. IF (SELF.info = NIL) THEN NEW(SELF.info); END;
  228. SELF.info^ := info;
  229. END;
  230. END SetInfo;
  231. PROCEDURE GetInfo*(VAR info : WindowInfo) : BOOLEAN;
  232. VAR infoPtr : WindowInfoPtr;
  233. BEGIN
  234. IF (manager # NIL) THEN
  235. RETURN manager.GetWindowInfo(SELF, info);
  236. ELSE
  237. infoPtr := SELF.info;
  238. IF (infoPtr # NIL) THEN
  239. info := infoPtr^;
  240. END;
  241. RETURN (infoPtr # NIL);
  242. END;
  243. END GetInfo;
  244. (** Resize is called by the WM if it wants to resize the window.
  245. width and height contain the desired new size. The Window should set width and height to acceptable
  246. values or return the current size, if resize is not supported *)
  247. PROCEDURE Resizing*(VAR width, height : LONGINT);
  248. BEGIN
  249. IF FlagNoResizing IN flags THEN
  250. width := GetWidth(); height := GetHeight();
  251. ELSIF width < SizeMinWidth THEN
  252. width := GetWidth();
  253. ELSIF height < SizeMinHeight THEN
  254. height := GetHeight();
  255. END
  256. END Resizing;
  257. (** May replace the back-image, if needed. MUST check if requested size is reasonable (0 < x * y < memory) *)
  258. PROCEDURE Resized*(width, height : LONGINT);
  259. END Resized;
  260. (** Invalidate a rectangle in window coordinates*)
  261. PROCEDURE Invalidate*(rect : Rectangle);
  262. BEGIN
  263. Rectangles.MoveRel(rect, bounds.l, bounds.t);
  264. Rectangles.ClipRect(rect, bounds);
  265. IF manager # NIL THEN manager.AddVisibleDirty(SELF, rect) END
  266. END Invalidate;
  267. (** Message procedures *)
  268. (** Pointer Messages *)
  269. (** PointerDown is called via the generic message handler if the pointer (or a mouse button) is pressed down and
  270. a) the pointer is in the bounding box of the window AND IsHit returns TRUE for this position
  271. or
  272. b) another mouse button was pressed down on a position where a) was met and has not yet been released.
  273. x and y are in window coordinates but may lie out of the window boundaries in case b)
  274. keys is the set of buttons that are down
  275. *)
  276. PROCEDURE PointerDown*(x, y : LONGINT; keys : SET);
  277. END PointerDown;
  278. (** PointerMove is called via the generic message handler if the pointer (mouse) is moved and
  279. a) the pointer is in the bounding box of the window AND IsHit returns TRUE for this position
  280. or
  281. b) the pointer was pressed down on a position where a) was met and has not yet been released.
  282. x and y are in window coordinates but may lie out of the window boundaries.
  283. keys is the set of buttons that are down
  284. *)
  285. PROCEDURE PointerMove*(x, y : LONGINT; keys : SET);
  286. END PointerMove;
  287. PROCEDURE WheelMove*(dz : LONGINT);
  288. END WheelMove;
  289. (** PointerUp is called via the generic message handler if the pointer (or a mouse button) went up.
  290. x and y are in window coordinates but may lie out of the window boundaries.
  291. keys is the set of buttons that are STILL DOWN
  292. *)
  293. PROCEDURE PointerUp*(x, y : LONGINT; keys : SET);
  294. END PointerUp;
  295. (** PointerLeave is called via the generic message handler if the pointer has left the window with no button pressed. *)
  296. PROCEDURE PointerLeave*;
  297. END PointerLeave;
  298. (** DragOver is called via the message handler. *)
  299. PROCEDURE DragOver*(x, y: LONGINT; dragInfo : DragInfo);
  300. END DragOver;
  301. (** Dropped is called via the message handler to indicate an item has been dropped. *)
  302. PROCEDURE DragDropped*(x, y: LONGINT; dragInfo : DragInfo);
  303. END DragDropped;
  304. (** send the srcWindow a confirmation for the completed drag operation *)
  305. PROCEDURE ConfirmDrag*(accept : BOOLEAN; dragInfo : DragInfo);
  306. BEGIN
  307. IF dragInfo # NIL THEN
  308. IF accept THEN
  309. IF dragInfo.onAccept # NIL THEN dragInfo.onAccept(SELF, dragInfo) END
  310. ELSE
  311. IF dragInfo.onReject # NIL THEN dragInfo.onReject(SELF, dragInfo) END
  312. END
  313. END
  314. END ConfirmDrag;
  315. (** Start a drag operation. *)
  316. PROCEDURE StartDrag*(sender, data : ANY; img : Graphics.Image; offsetX, offsetY: LONGINT; onAccept, onReject : Messages.CompCommand) : BOOLEAN;
  317. BEGIN
  318. RETURN manager.StartDrag(SELF, sender, data, img, offsetX, offsetY, onAccept, onReject)
  319. END StartDrag;
  320. (** Keyboard message *)
  321. (** KeyEvent is called via the generic message handler to signal a keyboard event.
  322. The window can determine wheter the key was pressed or released by examining the
  323. Inputs.Release flag in flags. ucs contains the unicode equivalent of the key. Special input editors
  324. send the generated unicode characters via KeyEvent. *)
  325. PROCEDURE KeyEvent*(ucs : LONGINT; flags : SET; keysym : LONGINT);
  326. END KeyEvent;
  327. (** Focus messages *)
  328. (** FocusGot is called via the generic message handler if the keyboard focus is transfered to this window *)
  329. PROCEDURE FocusGot*;
  330. END FocusGot;
  331. (** FocusList is called via the generic message handler if the keyboard focus is transfered to some other window *)
  332. PROCEDURE FocusLost*;
  333. END FocusLost;
  334. (** Style *)
  335. (** StyleChanged is called via the generic message handler if a change in the global style occurs. The
  336. Window should read all the style information it relies on and redraw itself *)
  337. PROCEDURE StyleChanged*;
  338. END StyleChanged;
  339. (** Closing *)
  340. PROCEDURE CanClose*() : BOOLEAN;
  341. BEGIN
  342. RETURN TRUE
  343. END CanClose;
  344. (** Close is called via the generic message handler. *)
  345. PROCEDURE Close*;
  346. BEGIN
  347. IF manager # NIL THEN manager.Remove(SELF) END;
  348. END Close;
  349. (** Return true if the window is hit at the coordinates x and y (in window coordinates). Use
  350. this to generate non-rectangular windows.
  351. This Method will be called directly by the window manager. __> Don't block, don't crash !!
  352. *)
  353. PROCEDURE IsHit*(x, y : LONGINT) : BOOLEAN;
  354. BEGIN
  355. RETURN TRUE
  356. END IsHit;
  357. PROCEDURE SetPointerInfo*(pi : PointerInfo);
  358. BEGIN
  359. IF FlagNoPointer IN flags THEN pi := pointerNull END;
  360. IF pi # pointerInfo THEN
  361. pointerInfo := pi;
  362. IF manager # NIL THEN manager.CheckPointerImage END;
  363. END
  364. END SetPointerInfo;
  365. (** Generic message handler distributes messages to the different msg-handler methods *)
  366. PROCEDURE Handle*(VAR m : Message);
  367. BEGIN
  368. IF m.msgType = Messages.MsgKey THEN
  369. KeyEvent(m.x, m.flags, m.y)
  370. ELSIF m.msgType = Messages.MsgPointer THEN
  371. IF m.msgSubType = Messages.MsgSubPointerMove THEN
  372. IF (m.dz # 0) THEN WheelMove(m.dz) END;
  373. PointerMove(m.x, m.y, m.flags)
  374. ELSIF m.msgSubType = Messages.MsgSubPointerDown THEN PointerDown(m.x, m.y, m.flags)
  375. ELSIF m.msgSubType = Messages.MsgSubPointerUp THEN PointerUp(m.x, m.y, m.flags)
  376. ELSIF m.msgSubType = Messages.MsgSubPointerLeave THEN PointerLeave
  377. END
  378. ELSIF m.msgType = Messages.MsgDrag THEN
  379. IF m.msgSubType = Messages.MsgDragOver THEN
  380. IF (m.ext # NIL) THEN
  381. DragOver(m.x, m.y, m.ext(DragInfo))
  382. END
  383. ELSIF m.msgSubType = Messages.MsgDragDropped THEN
  384. IF (m.ext # NIL) THEN
  385. DragDropped(m.x, m.y, m.ext(DragInfo))
  386. END
  387. END
  388. ELSIF m.msgType = Messages.MsgClose THEN Close
  389. ELSIF m.msgType = Messages.MsgFocus THEN
  390. IF m.msgSubType = Messages.MsgSubFocusGot THEN FocusGot
  391. ELSIF m.msgSubType = Messages.MsgSubFocusLost THEN FocusLost
  392. END
  393. ELSIF m.msgType = Messages.MsgStyleChanged THEN StyleChanged
  394. ELSIF m.msgType = Messages.MsgResized THEN Resized(m.x, m.y)
  395. END;
  396. END Handle;
  397. (** Draw request form the window manager. The canvas becomes invalid when the method ends. The
  398. draw method may not modify window or WindowManager properties.
  399. w, h is the area in view coordinates, q is the Quality 0 lowest 1 mid 2 high. A window may ignore q *)
  400. PROCEDURE Draw*(canvas : Graphics.Canvas; w, h, q : LONGINT);
  401. END Draw;
  402. (** Is called by the windowmanager with reduce set, if the window is resized or moved on slow machines *)
  403. PROCEDURE HintReduceQuality*(reduce : BOOLEAN);
  404. BEGIN
  405. IF reduce # reduceQuality THEN
  406. reduceQuality := reduce;
  407. IF ~reduceQuality THEN
  408. IF manager # NIL THEN manager.AddVisibleDirty(SELF, bounds) END
  409. END
  410. END
  411. END HintReduceQuality;
  412. END Window;
  413. (** assumes the window is size agnostic, handles all the zooming issues directly *)
  414. BufferWindow* = OBJECT(Window)
  415. VAR
  416. img* : Graphics.Image;
  417. canvas* : Graphics.BufferCanvas;
  418. canvasGen-: Graphics.CanvasGenerator;
  419. pointerThreshold*,
  420. maxInterpolation* : LONGINT; (* allows limiting the interpolation degree on Draw *)
  421. PROCEDURE &Init*(w, h : LONGINT; alpha : BOOLEAN);
  422. BEGIN
  423. Init^(w, h, alpha);
  424. NEW(img);
  425. IF alpha THEN Raster.Create(img, w, h, Raster.BGRA8888) ELSE Raster.Create(img, w, h, format) END;
  426. SetCanvasGenerator(Graphics.GenCanvas);
  427. pointerThreshold := 1; (* invisible pixels are treated as invisible *)
  428. maxInterpolation := Graphics.ScaleBilinear;
  429. END Init;
  430. PROCEDURE SetCanvasGenerator*(canvasGen:Graphics.CanvasGenerator);
  431. BEGIN{EXCLUSIVE}
  432. SELF.canvasGen:=canvasGen; canvas:=canvasGen(img);
  433. IF manager # NIL THEN manager.AddVisibleDirty(SELF, bounds) END
  434. END SetCanvasGenerator;
  435. PROCEDURE IsHit(x, y : LONGINT) : BOOLEAN;
  436. VAR w, h : LONGINT; fx, fy : REAL;
  437. BEGIN
  438. w := GetWidth(); h := GetHeight();
  439. IF (w > 0) & (h > 0) & ((w # img.width) OR (h # img.height)) THEN
  440. fx := img.width / w; fy := img.height / h;
  441. RETURN Graphics.IsBitmapHit(ENTIER(x * fx), ENTIER(y * fy), pointerThreshold, img)
  442. ELSE RETURN Graphics.IsBitmapHit(x, y, pointerThreshold, img)
  443. END
  444. END IsHit;
  445. PROCEDURE Draw*(canvas : Graphics.Canvas; w, h, q : LONGINT);
  446. BEGIN
  447. IF reduceQuality THEN q := 0 END;
  448. IF img # NIL THEN
  449. IF (w = img.width) & (h = img.height) THEN
  450. IF useAlpha THEN canvas.DrawImage(0, 0, img, Graphics.ModeSrcOverDst)
  451. ELSE canvas.DrawImage(0, 0, img, Graphics.ModeCopy)
  452. END
  453. ELSE
  454. IF useAlpha THEN
  455. canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
  456. Rectangles.MakeRect(0, 0, w, h), Graphics.ModeSrcOverDst, MIN( q,maxInterpolation))
  457. ELSE
  458. canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
  459. Rectangles.MakeRect(0, 0, w, h), Graphics.ModeCopy, MIN(q,maxInterpolation))
  460. END
  461. END
  462. END;
  463. INC(timestamp);
  464. END Draw;
  465. PROCEDURE Invalidate*(rect : Rectangle);
  466. VAR w, h : LONGINT; fx, fy : REAL;
  467. BEGIN
  468. w := GetWidth(); h := GetHeight();
  469. IF (w > 0) & (h > 0) & ((w # img.width) OR (h # img.height)) THEN
  470. fx := w / img.width; fy := h / img.height;
  471. rect.l := ENTIER(rect.l * fx); rect.t := ENTIER(rect.t * fy);
  472. rect.r := ENTIER(rect.r * fx + 0.5); rect.b := ENTIER(rect.b * fy + 0.5)
  473. END;
  474. Invalidate^(rect)
  475. END Invalidate;
  476. PROCEDURE Handle*(VAR m : Message);
  477. VAR w, h : LONGINT; fx, fy : REAL;
  478. BEGIN
  479. w := GetWidth(); h := GetHeight();
  480. IF (w > 0) & (h > 0) & ((w # img.width) OR (h # img.height)) & (m.msgType = Messages.MsgPointer) THEN
  481. fx := img.width / w; fy := img.height / h; m.x := ENTIER(m.x * fx); m.y := ENTIER(m.y * fy)
  482. END;
  483. Handle^(m)
  484. END Handle;
  485. END BufferWindow;
  486. DoubleBufferWindow* = OBJECT(BufferWindow)
  487. VAR
  488. visibleCanvas : Graphics.BufferCanvas;
  489. backImg* : Graphics.Image;
  490. swapping, drawing : BOOLEAN;
  491. PROCEDURE &Init*(w, h: LONGINT; alpha : BOOLEAN);
  492. BEGIN
  493. NEW(backImg);
  494. IF alpha THEN Raster.Create(backImg, w, h, Raster.BGRA8888) ELSE Raster.Create(backImg, w, h, format) END;
  495. Init^(w, h, alpha);
  496. END Init;
  497. PROCEDURE ReInit*(w, h : LONGINT);
  498. BEGIN {EXCLUSIVE}
  499. AWAIT(~drawing);
  500. IF useAlpha THEN
  501. Raster.Create(img, w, h, Raster.BGRA8888);
  502. Raster.Create(backImg, w, h, Raster.BGRA8888)
  503. ELSE
  504. Raster.Create(img, w, h, format);
  505. Raster.Create(backImg, w, h, format)
  506. END;
  507. visibleCanvas:=canvasGen(img);
  508. canvas:=canvasGen(backImg);
  509. END ReInit;
  510. PROCEDURE SetCanvasGenerator*(canvasGen:Graphics.CanvasGenerator);
  511. BEGIN
  512. SELF.canvasGen:=canvasGen;
  513. visibleCanvas:=canvasGen(img);
  514. canvas:=canvasGen(backImg);
  515. IF manager # NIL THEN manager.AddVisibleDirty(SELF, bounds) END
  516. END SetCanvasGenerator;
  517. PROCEDURE Draw*(canvas : Graphics.Canvas; w, h, q : LONGINT);
  518. BEGIN
  519. BEGIN{EXCLUSIVE}
  520. AWAIT(~swapping); drawing := TRUE;
  521. END;
  522. IF reduceQuality THEN q := 0 END;
  523. IF img # NIL THEN
  524. IF (w = img.width) & (h = img.height) THEN
  525. IF useAlpha THEN canvas.DrawImage(0, 0, img, Graphics.ModeSrcOverDst)
  526. ELSE canvas.DrawImage(0, 0, img, Graphics.ModeCopy)
  527. END
  528. ELSE
  529. IF useAlpha THEN
  530. canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
  531. Rectangles.MakeRect(0, 0, w, h), Graphics.ModeSrcOverDst, MIN(q,maxInterpolation))
  532. ELSE
  533. canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
  534. Rectangles.MakeRect(0, 0, w, h), Graphics.ModeCopy, MIN(q,maxInterpolation))
  535. END
  536. END
  537. END;
  538. BEGIN{EXCLUSIVE}
  539. drawing := FALSE;
  540. END;
  541. INC(timestamp);
  542. END Draw;
  543. PROCEDURE CopyRect*(rect : Rectangle);
  544. BEGIN {EXCLUSIVE}
  545. swapping := TRUE;
  546. AWAIT(~drawing);
  547. visibleCanvas.SetClipRect(rect);
  548. visibleCanvas.DrawImage(0, 0, backImg, Graphics.ModeCopy);
  549. visibleCanvas.SetClipRect(visibleCanvas.limits);
  550. swapping := FALSE
  551. END CopyRect;
  552. PROCEDURE Swap*;
  553. VAR tmp : Graphics.Image; tmpc : Graphics.BufferCanvas;
  554. BEGIN {EXCLUSIVE}
  555. swapping := TRUE;
  556. AWAIT(~drawing);
  557. tmp := img; img := backImg; backImg := tmp;
  558. tmpc := canvas; canvas := visibleCanvas; visibleCanvas := tmpc;
  559. swapping := FALSE
  560. END Swap;
  561. END DoubleBufferWindow;
  562. (** A ViewPort observes the global coordinate space. The WindowManager calls the view on all changes that occur
  563. in the observed range. *)
  564. ViewPort* = OBJECT (Plugins.Plugin)
  565. VAR
  566. next* : ViewPort;
  567. manager* : WindowManager;
  568. range* : RealRect;
  569. (* Width and height of viewport at 1:1 zoom. Will be set once in the constructor of the ViewPort implementation *)
  570. width0*, height0* : LONGINT; (* read-only! *)
  571. (** The WindowManager calls the Update Procedure in locked state. *)
  572. PROCEDURE Update*(r : Rectangle; top : Window);
  573. END Update;
  574. (** The WindowManager calls the Update Procedure in locked state. *)
  575. PROCEDURE Refresh*(top : Window);
  576. END Refresh;
  577. (** Set the observed range *)
  578. PROCEDURE SetRange*(x, y, w, h : REAL; showTransition : BOOLEAN);
  579. END SetRange;
  580. (** Return the modifier keys that are pressed in the view *)
  581. PROCEDURE GetKeyState*(VAR state : SET);
  582. END GetKeyState;
  583. END ViewPort;
  584. Decorator* = PROCEDURE {DELEGATE} (w : Window);
  585. WindowManager* = OBJECT(Plugins.Plugin)
  586. VAR
  587. pointerNull*, pointerStandard*, pointerMove*, pointerText*, pointerCrosshair*,
  588. pointerLeftRight*, pointerUpDown*, pointerULDR*, pointerURDL*, pointerLink* : PointerInfo;
  589. decorate* : Decorator;
  590. viewRegistry- : Plugins.Registry;
  591. sequencer- : Messages.MsgSequencer; (** PROTECTED *)
  592. lock- : Locks.RWLock; (** PROTECTED *)
  593. messagePreviewList : MessagePreviewList;
  594. style : WindowStyle;
  595. PROCEDURE &Init*;
  596. BEGIN
  597. NEW(pointerNull);
  598. InitCursors;
  599. decorate := NIL;
  600. NEW(viewRegistry, "View#", "Views Port Window Manager");
  601. NEW(sequencer, Handle); lock := sequencer.lock;
  602. messagePreviewList := NIL;
  603. NEW(style);
  604. END Init;
  605. PROCEDURE InitCursors;
  606. BEGIN
  607. LoadCursor("ZeroSkin.zip://arrow.png", 0, 0, pointerStandard);
  608. LoadCursor("ZeroSkin.zip://move.png", 15, 15, pointerMove);
  609. LoadCursor("ZeroSkin.zip://text.png", 13, 12, pointerText);
  610. LoadCursor("ZeroSkin.zip://crosshair.png", 13, 12, pointerCrosshair);
  611. LoadCursor("ZeroSkin.zip://leftright.png", 13, 12, pointerLeftRight);
  612. LoadCursor("ZeroSkin.zip://updown.png", 13, 12, pointerUpDown);
  613. LoadCursor("ZeroSkin.zip://uldr.png", 13, 12, pointerULDR);
  614. LoadCursor("ZeroSkin.zip://urdl.png", 13, 12, pointerURDL);
  615. LoadCursor("ZeroSkin.zip://hand.png", 6, 0, pointerLink);
  616. END InitCursors;
  617. PROCEDURE ZeroSkin*;
  618. BEGIN
  619. lock.AcquireWrite;
  620. style.Init;
  621. SetStyle(style);
  622. InitCursors;
  623. lock.ReleaseWrite
  624. END ZeroSkin;
  625. PROCEDURE ShutDown*;
  626. BEGIN
  627. ASSERT(lock.HasWriteLock());
  628. Plugins.main.Remove(viewRegistry)
  629. END ShutDown;
  630. (** Window management *)
  631. (** Add adds a window at pos l, t with flags *)
  632. PROCEDURE Add*(l, t : LONGINT; item : Window; flags:SET);
  633. END Add;
  634. (** Remove removes a window *)
  635. PROCEDURE Remove*(item : Window);
  636. END Remove;
  637. (** Set the position of a window *)
  638. PROCEDURE SetWindowPos*(vs : Window; x, y : LONGINT);
  639. END SetWindowPos;
  640. (** Set the size of a window. Return the new size in width and height *)
  641. (** If the window contains left, top, right or bottom, SetWindowSize is called
  642. appropriately *)
  643. PROCEDURE SetWindowSize*(vs : Window; VAR width, height : LONGINT);
  644. END SetWindowSize;
  645. (** Add a region to be refreshed *)
  646. PROCEDURE AddDirty*(VAR rect:Rectangle);
  647. END AddDirty;
  648. (** Add a dirty region. The region is in window coordinates and will be clipped against non transparent
  649. windows above *)
  650. PROCEDURE AddVisibleDirty*(w : Window; rect : Rectangle);
  651. END AddVisibleDirty;
  652. (** Set the keyboard focus to the window w *)
  653. PROCEDURE SetFocus*(w : Window);
  654. END SetFocus;
  655. (** Add a decoration window w to window to. The window w must separately be added to the wm *)
  656. (** A window MUST NOT be added more than once *)
  657. (** MUST hold lock *)
  658. PROCEDURE AddDecorWindow*(to, decor : Window);
  659. VAR dl : DecorList;
  660. BEGIN
  661. lock.AcquireWrite;
  662. INCL(decor.flags, FlagDecorWindow);
  663. INCL(decor.flags, FlagHidden);
  664. decor.master := to;
  665. NEW(dl); dl.w := decor; dl.next := to.decor; to.decor := dl;
  666. lock.ReleaseWrite
  667. END AddDecorWindow;
  668. (** Remove a decoration window w from window from. The window w must separately be removed from the wm *)
  669. (** MUST hold lock *)
  670. PROCEDURE RemoveDecorWindow*(w, from : Window);
  671. VAR dl : DecorList;
  672. BEGIN
  673. lock.AcquireWrite;
  674. IF (from.decor # NIL) & (from.decor.w = w) THEN from.decor := from.decor.next
  675. ELSE
  676. dl := from.decor;
  677. WHILE (dl.next # NIL) & (dl.next.w # w) DO dl := dl.next END;
  678. IF dl.next # NIL THEN dl.next := dl.next.next END
  679. END;
  680. lock.ReleaseWrite
  681. END RemoveDecorWindow;
  682. PROCEDURE SetStyle*(x : WindowStyle);
  683. VAR m : Message;
  684. BEGIN
  685. ASSERT(style # NIL);
  686. style := x; m.msgType := Messages.MsgStyleChanged; m.ext := style;
  687. Broadcast(m)
  688. END SetStyle;
  689. PROCEDURE GetStyle*() : WindowStyle;
  690. BEGIN
  691. ASSERT(style # NIL);
  692. RETURN style
  693. END GetStyle;
  694. (** Move Window w to front. If FlagStayOnTop is not set in w.flags, w will stay behind all windows with this flag set *)
  695. PROCEDURE ToFront*(w : Window);
  696. END ToFront;
  697. (** Move Window w to the background. If FlagStayOnTop is not set in w.flags, w will stay behind all windows *)
  698. PROCEDURE ToBack*(w : Window);
  699. END ToBack;
  700. PROCEDURE SetIsVisible*(w : Window; isVisible : BOOLEAN);
  701. VAR d : DecorList;
  702. BEGIN
  703. ASSERT(w # NIL);
  704. lock.AcquireWrite;
  705. IF (w.isVisible # isVisible) THEN
  706. w.isVisible := isVisible;
  707. IF (w.leftW # NIL) THEN w.leftW.isVisible := isVisible; END;
  708. IF (w.rightW # NIL) THEN w.rightW.isVisible := isVisible; END;
  709. IF (w.topW # NIL) THEN w.topW.isVisible := isVisible; END;
  710. IF (w.bottomW # NIL) THEN w.bottomW.isVisible := isVisible; END;
  711. AddDirty(w.bounds);
  712. IF (w.decor # NIL) THEN
  713. d := w.decor;
  714. WHILE (d # NIL) & (d.w # NIL) DO
  715. AddDirty(d.w.bounds);
  716. d := d.next;
  717. END;
  718. END;
  719. IncOTimestamp;
  720. END;
  721. lock.ReleaseWrite;
  722. END SetIsVisible;
  723. (** Set icon for a given window. Icon may be set to NIL. *)
  724. PROCEDURE SetWindowIcon*(w : Window; icon : Graphics.Image);
  725. VAR tw : Window;
  726. BEGIN
  727. ASSERT(w # NIL);
  728. lock.AcquireWrite;
  729. w.icon := icon;
  730. tw := w.topW;
  731. IF tw # NIL THEN AddVisibleDirty(tw, tw.bounds) END;
  732. lock.ReleaseWrite;
  733. IncOTimestamp;
  734. END SetWindowIcon;
  735. (** Return the window at postition x, y in global space. *)
  736. (** Windows that have the FlagNavigate flag set will not be considered *)
  737. (** Must hold WM lock *)
  738. PROCEDURE GetPositionOwner*(x, y : LONGINT) : Window;
  739. END GetPositionOwner;
  740. PROCEDURE GetFocusOwner*() : Window;
  741. END GetFocusOwner;
  742. (** Set the title of a window as UTF-8 string *)
  743. PROCEDURE SetWindowTitle*(w : Window; title : String);
  744. VAR tw : Window;
  745. BEGIN
  746. lock.AcquireWrite;
  747. w.title := title;
  748. tw := w.topW;
  749. IF tw # NIL THEN AddVisibleDirty(tw, tw.bounds) END;
  750. lock.ReleaseWrite;
  751. IncWTimestamp; (* since navigation elements care about window title *)
  752. END SetWindowTitle;
  753. (** Get the title of a window as UTF-8 string *)
  754. PROCEDURE GetWindowTitle*(w : Window) : String;
  755. BEGIN
  756. RETURN w.title
  757. END GetWindowTitle;
  758. PROCEDURE SetWindowInfo*(w : Window; CONST info : WindowInfo);
  759. BEGIN
  760. ASSERT(w # NIL);
  761. lock.AcquireWrite;
  762. IF (w.info = NIL) THEN NEW(w.info); END;
  763. w.info^ := info;
  764. lock.ReleaseWrite;
  765. IncOTimestamp;
  766. END SetWindowInfo;
  767. PROCEDURE GetWindowInfo*(w : Window; VAR info : WindowInfo) : BOOLEAN;
  768. VAR infoPtr : WindowInfoPtr;
  769. BEGIN
  770. ASSERT(w # NIL);
  771. lock.AcquireRead;
  772. infoPtr := w.info;
  773. IF (infoPtr # NIL) THEN
  774. info := infoPtr^;
  775. END;
  776. lock.ReleaseRead;
  777. RETURN (infoPtr # NIL);
  778. END GetWindowInfo;
  779. (** Set or unset a window flag
  780. Note: Setting FlagStayOnTop unsets FlagStayOnBottom and vice versa *)
  781. PROCEDURE SetWindowFlag*(w : Window; flag : LONGINT; value : BOOLEAN);
  782. BEGIN
  783. ASSERT(w # NIL);
  784. ASSERT((flag = FlagFrame) OR (flag = FlagStayOnTop) OR (flag = FlagStayOnBottom) OR (flag = FlagHidden));
  785. END SetWindowFlag;
  786. (** Set if the window is willing to accept a dropped item *)
  787. PROCEDURE SetAcceptDrag*(w : Window; accept : BOOLEAN);
  788. BEGIN
  789. lock.AcquireWrite;
  790. w.acceptDrag := accept;
  791. lock.ReleaseWrite
  792. END SetAcceptDrag;
  793. PROCEDURE StartDrag*(w : Window; sender, data : ANY; img : Graphics.Image; offsetX, offsetY: LONGINT; onAccept, onReject : Messages.CompCommand) : BOOLEAN;
  794. END StartDrag;
  795. (** a pointer button must be pressed *)
  796. PROCEDURE TransferPointer*( to : Window) : BOOLEAN;
  797. END TransferPointer;
  798. (** Adjust pointer to new position / check picture *)
  799. PROCEDURE CheckPointerImage*;
  800. END CheckPointerImage;
  801. (** View management *)
  802. (** Add a view *)
  803. PROCEDURE AddView*(v : ViewPort);
  804. END AddView;
  805. (** Add the whole View.range as dirty and cause a redraw *)
  806. PROCEDURE RefreshView*(v : ViewPort);
  807. END RefreshView;
  808. (** RemoveView from windowmanager *)
  809. PROCEDURE RemoveView*(v : ViewPort);
  810. END RemoveView;
  811. (** Messages *)
  812. PROCEDURE Broadcast*(VAR m : Message);
  813. END Broadcast;
  814. PROCEDURE SendMessage*(dest : Window; VAR m : Message) : BOOLEAN;
  815. BEGIN
  816. IF dest.sequencer # NIL THEN RETURN dest.sequencer.Add(m)
  817. ELSE dest.Handle(m); RETURN TRUE
  818. END
  819. END SendMessage;
  820. (** Install a message preview procedure. The window manager calls the MessagePreviewProc for
  821. all external messages so that they can be recorded, changed or discarded *)
  822. PROCEDURE InstallMessagePreview*(x : MessagePreviewProc);
  823. VAR mpl : MessagePreviewList;
  824. BEGIN
  825. lock.AcquireWrite;
  826. NEW(mpl); mpl.next := messagePreviewList; mpl.proc := x; messagePreviewList := mpl;
  827. lock.ReleaseWrite
  828. END InstallMessagePreview;
  829. (** Remove a MessagePreviewProc *)
  830. PROCEDURE RemoveMessagePreview*(x : MessagePreviewProc);
  831. VAR cur : MessagePreviewList;
  832. BEGIN
  833. lock.AcquireWrite;
  834. IF (messagePreviewList # NIL) & (messagePreviewList.proc = x) THEN messagePreviewList := messagePreviewList.next
  835. ELSE
  836. cur := messagePreviewList;
  837. WHILE cur # NIL DO
  838. IF (cur.next # NIL) & (cur.next.proc = x) THEN cur.next := cur.next.next; lock.ReleaseWrite; RETURN
  839. ELSE cur := cur.next END
  840. END
  841. END;
  842. lock.ReleaseWrite
  843. END RemoveMessagePreview;
  844. (** Preview message to all installed message preview handlers. Only to be used by WindowManager itself *)
  845. PROCEDURE PreviewMessage*(VAR m : Message; VAR discard : BOOLEAN); (* protected *)
  846. VAR mpl : MessagePreviewList;
  847. BEGIN
  848. ASSERT(lock.HasReadLock());
  849. discard := FALSE;
  850. mpl := messagePreviewList;
  851. WHILE (mpl # NIL) & ~discard DO mpl.proc(m, discard); mpl := mpl.next END;
  852. END PreviewMessage;
  853. (** Enumeration *)
  854. (** Get the first "user" window --> May return NIL if only background and pointer window are installed *)
  855. (** Must hold lock *)
  856. PROCEDURE GetFirst*() : Window;
  857. END GetFirst;
  858. (** Get the window next "user" window on top of x *)
  859. PROCEDURE GetNext*(x : Window) : Window;
  860. END GetNext;
  861. (** Get the "user" window below x *)
  862. PROCEDURE GetPrev*(x : Window) : Window;
  863. END GetPrev;
  864. (** Replace the background window with w. Return the current background window *)
  865. PROCEDURE ReplaceBackground*(w : Window) : Window;
  866. END ReplaceBackground;
  867. (** Return the area that is actually occupied *)
  868. PROCEDURE GetPopulatedArea*(VAR r : Rectangle);
  869. END GetPopulatedArea;
  870. (** Internal handler for message that are directed to the window manager never call directly ! *)
  871. PROCEDURE HandleInternal*(VAR msg : Messages.Message); (** PROTECTED *)
  872. BEGIN
  873. ASSERT(sequencer.IsCallFromSequencer())
  874. END HandleInternal;
  875. (** All external events of the window manager are inserted here *)
  876. PROCEDURE Handle*(VAR msg : Messages.Message);
  877. VAR discard : BOOLEAN;
  878. BEGIN
  879. IF sequencer.IsCallFromSequencer() THEN
  880. PreviewMessage(msg, discard);
  881. IF ~discard THEN HandleInternal(msg) END
  882. ELSE
  883. IF ~sequencer.Add(msg) THEN
  884. KernelLog.String("A message sent to the WM could not be handled "); KernelLog.Ln
  885. END
  886. END
  887. END Handle;
  888. END WindowManager;
  889. VAR
  890. registry- : Plugins.Registry;
  891. pointerNull: PointerInfo;
  892. (* Changes whenever a Window is added or removed to/from a WindowManager *)
  893. wTimestamp- : LONGINT;
  894. (* Changes whenever the keyboard focus is given to another window or the visibility of a window changed *)
  895. oTimestamp- : LONGINT;
  896. (* Coordinate offsets use to determine position of a new window *)
  897. x1, y1 : LONGINT;
  898. format* : Raster.Format;
  899. nextId : LONGINT;
  900. standardCursorImage: Graphics.Image;
  901. (* Get a unique identifier *)
  902. PROCEDURE GetId() : LONGINT;
  903. BEGIN {EXCLUSIVE}
  904. INC(nextId);
  905. RETURN nextId;
  906. END GetId;
  907. PROCEDURE IncWTimestamp*;
  908. BEGIN {EXCLUSIVE}
  909. INC(wTimestamp);
  910. END IncWTimestamp;
  911. PROCEDURE IncOTimestamp*;
  912. BEGIN {EXCLUSIVE}
  913. INC(oTimestamp);
  914. END IncOTimestamp;
  915. (** Block until a window is added/removed, changes its visibility or the keyboard focus changes *)
  916. PROCEDURE AwaitChange*(wTs, oTs : LONGINT);
  917. BEGIN {EXCLUSIVE}
  918. AWAIT((wTimestamp # wTs) OR (oTimestamp # oTs));
  919. END AwaitChange;
  920. PROCEDURE ClearInfo*(VAR info : WindowInfo);
  921. VAR i : LONGINT;
  922. BEGIN
  923. FOR i := 0 TO LEN(info.openDocuments)-1 DO
  924. info.openDocuments[i].id := 0;
  925. info.openDocuments[i].name := "";
  926. info.openDocuments[i].fullname := "";
  927. info.openDocuments[i].modified := FALSE;
  928. info.openDocuments[i].hasFocus := FALSE;
  929. END;
  930. info.handleDocumentInfo := NIL;
  931. info.vc.width := 0;
  932. info.vc.height := 0;
  933. info.vc.generator := NIL;
  934. END ClearInfo;
  935. PROCEDURE NewString*(CONST x : ARRAY OF CHAR) : String;
  936. VAR t : String;
  937. BEGIN
  938. NEW(t, LEN(x)); COPY(x, t^); RETURN t
  939. END NewString;
  940. PROCEDURE LoadCursor*(CONST name : ARRAY OF CHAR; hx, hy : LONGINT; VAR pi : PointerInfo);
  941. BEGIN
  942. IF pi = NIL THEN NEW(pi) END;
  943. pi.img := Graphics.LoadImage(name, TRUE); pi.hotX := hx; pi.hotY := hy;
  944. IF pi.img = NIL THEN
  945. KernelLog.String("Picture not loaded : "); KernelLog.String(name); KernelLog.Ln;
  946. IF standardCursorImage = NIL THEN CreateStandardCursorImage END;
  947. pi.img := standardCursorImage; pi.hotX := 0; pi.hotY := 0;
  948. END
  949. END LoadCursor;
  950. PROCEDURE GetDefaultManager*() : WindowManager;
  951. VAR p : Plugins.Plugin;
  952. BEGIN
  953. p := registry.Await("");
  954. RETURN p(WindowManager)
  955. END GetDefaultManager;
  956. PROCEDURE GetDefaultView*() : ViewPort;
  957. VAR p : Plugins.Plugin; m : WindowManager;
  958. BEGIN
  959. m := GetDefaultManager();
  960. p := m.viewRegistry.Await("");
  961. RETURN p(ViewPort)
  962. END GetDefaultView;
  963. PROCEDURE ResetNextPosition*;
  964. BEGIN {EXCLUSIVE}
  965. x1 := 0; y1 := 0;
  966. END ResetNextPosition;
  967. PROCEDURE GetNextPosition*(window : Window; manager : WindowManager; view : ViewPort; VAR dx, dy : LONGINT);
  968. VAR style : WindowStyle; x, y : LONGINT;
  969. BEGIN {EXCLUSIVE}
  970. ASSERT((window # NIL) & (manager # NIL) & (view # NIL));
  971. style := manager.GetStyle();
  972. x := style.lw; y := style.th;
  973. dx := x + X0 + x1; dy := y + Y0 + y1;
  974. INC(x1, x); INC(y1, y);
  975. IF (x1 > ENTIER(0.3 * view.width0)) OR (y1 > ENTIER(0.3 * view.height0)) THEN
  976. x1 := 0; y1 := 0;
  977. END;
  978. END GetNextPosition;
  979. PROCEDURE DefaultAddWindow*(w : Window);
  980. VAR manager : WindowManager; view : ViewPort; dy, dx : LONGINT;
  981. BEGIN
  982. manager := GetDefaultManager();
  983. view := GetDefaultView();
  984. GetNextPosition(w, manager, view, dx, dy);
  985. manager.Add(ENTIER(view.range.l) + dx, ENTIER(view.range.t) + dy, w, {FlagFrame, FlagClose, FlagMinimize});
  986. manager.SetFocus(w)
  987. END DefaultAddWindow;
  988. PROCEDURE AddWindow*(w : Window; dx, dy : LONGINT);
  989. VAR manager : WindowManager; view : ViewPort;
  990. BEGIN
  991. manager := GetDefaultManager();
  992. view := GetDefaultView();
  993. manager.Add(ENTIER(view.range.l) + dx, ENTIER(view.range.t) + dy, w, {FlagFrame, FlagClose, FlagMinimize})
  994. END AddWindow;
  995. PROCEDURE ExtAddWindow*(w : Window; dx, dy : LONGINT; flags : SET);
  996. VAR manager : WindowManager; view : ViewPort;
  997. BEGIN
  998. manager := GetDefaultManager();
  999. view := GetDefaultView();
  1000. manager.Add(ENTIER(view.range.l) + dx, ENTIER(view.range.t) + dy, w, flags)
  1001. END ExtAddWindow;
  1002. PROCEDURE ExtAddViewBoundWindow*(w : Window; dx, dy : LONGINT; view : ViewPort; flags : SET);
  1003. VAR manager : WindowManager;
  1004. BEGIN
  1005. flags := flags + {FlagNavigation};
  1006. manager := GetDefaultManager();
  1007. manager.Add(dx, dy, w, flags);
  1008. END ExtAddViewBoundWindow;
  1009. (** move a window to the default view *)
  1010. PROCEDURE DefaultBringToView*(w : Window; toFront : BOOLEAN);
  1011. VAR manager : WindowManager; view : ViewPort; dy, dx : LONGINT;
  1012. BEGIN
  1013. manager := GetDefaultManager();
  1014. view := GetDefaultView();
  1015. GetNextPosition(w, manager, view, dx, dy);
  1016. manager.SetWindowPos(w, ENTIER(view.range.l) + dx, ENTIER(view.range.t) + dy);
  1017. manager.SetFocus(w);
  1018. IF toFront THEN manager.ToFront(w) END
  1019. END DefaultBringToView;
  1020. PROCEDURE CleanUp;
  1021. BEGIN
  1022. Plugins.main.Remove(registry)
  1023. END CleanUp;
  1024. PROCEDURE CreateStandardCursorImage;
  1025. CONST Width = 32; Height = 32;
  1026. VAR canvas: Graphics.BufferCanvas; rect: Rectangles.Rectangle; points: ARRAY 3 OF Graphics.Point2d;
  1027. BEGIN
  1028. NEW(standardCursorImage);
  1029. Raster.Create(standardCursorImage, Width, Height, Raster.BGRA8888);
  1030. NEW(canvas, standardCursorImage);
  1031. Rectangles.SetRect (rect, 0, 0, Width, Height);
  1032. canvas.Fill(rect, 0H, Graphics.ModeCopy);
  1033. points[0].x := Width; points[0].y := Height DIV 2;
  1034. points[1].x := 0; points[1].y := 0;
  1035. points[2].x := Width DIV 2; points[2].y := Height;
  1036. canvas.FillPolygonFlat(points, 3, Graphics.White - 080H, Graphics.ModeCopy);
  1037. canvas.PolyLine(points, 3, FALSE, Graphics.Black, Graphics.ModeCopy);
  1038. END CreateStandardCursorImage;
  1039. BEGIN
  1040. Modules.InstallTermHandler(CleanUp);
  1041. NEW(registry, "WM#", "Window Managers");
  1042. nextId := 0; x1 := 0; y1 := 0;
  1043. wTimestamp := 0; oTimestamp := 0;
  1044. format := Raster.BGRA8888;
  1045. NEW(pointerNull);
  1046. standardCursorImage := NIL;
  1047. END WMWindowManager.