WMWindowManager.Mod 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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. (* global to local transformation by sequencer thread: *)
  372. m.x := m.x-bounds.l;
  373. m.y := m.y-bounds.t;
  374. IF m.msgSubType = Messages.MsgSubPointerMove THEN
  375. IF (m.dz # 0) THEN WheelMove(m.dz) END;
  376. PointerMove(m.x, m.y, m.flags)
  377. ELSIF m.msgSubType = Messages.MsgSubPointerDown THEN PointerDown(m.x, m.y, m.flags)
  378. ELSIF m.msgSubType = Messages.MsgSubPointerUp THEN PointerUp(m.x, m.y, m.flags)
  379. ELSIF m.msgSubType = Messages.MsgSubPointerLeave THEN PointerLeave
  380. END
  381. ELSIF m.msgType = Messages.MsgDrag THEN
  382. IF m.msgSubType = Messages.MsgDragOver THEN
  383. IF (m.ext # NIL) THEN
  384. DragOver(m.x, m.y, m.ext(DragInfo))
  385. END
  386. ELSIF m.msgSubType = Messages.MsgDragDropped THEN
  387. IF (m.ext # NIL) THEN
  388. DragDropped(m.x, m.y, m.ext(DragInfo))
  389. END
  390. END
  391. ELSIF m.msgType = Messages.MsgClose THEN Close
  392. ELSIF m.msgType = Messages.MsgFocus THEN
  393. IF m.msgSubType = Messages.MsgSubFocusGot THEN FocusGot
  394. ELSIF m.msgSubType = Messages.MsgSubFocusLost THEN FocusLost
  395. END
  396. ELSIF m.msgType = Messages.MsgStyleChanged THEN StyleChanged
  397. ELSIF m.msgType = Messages.MsgResized THEN Resized(m.x, m.y)
  398. END;
  399. END Handle;
  400. (** Draw request form the window manager. The canvas becomes invalid when the method ends. The
  401. draw method may not modify window or WindowManager properties.
  402. w, h is the area in view coordinates, q is the Quality 0 lowest 1 mid 2 high. A window may ignore q *)
  403. PROCEDURE Draw*(canvas : Graphics.Canvas; w, h, q : LONGINT);
  404. END Draw;
  405. (** Is called by the windowmanager with reduce set, if the window is resized or moved on slow machines *)
  406. PROCEDURE HintReduceQuality*(reduce : BOOLEAN);
  407. BEGIN
  408. IF reduce # reduceQuality THEN
  409. reduceQuality := reduce;
  410. IF ~reduceQuality THEN
  411. IF manager # NIL THEN manager.AddVisibleDirty(SELF, bounds) END
  412. END
  413. END
  414. END HintReduceQuality;
  415. END Window;
  416. (** assumes the window is size agnostic, handles all the zooming issues directly *)
  417. BufferWindow* = OBJECT(Window)
  418. VAR
  419. img* : Graphics.Image;
  420. canvas* : Graphics.BufferCanvas;
  421. canvasGen-: Graphics.CanvasGenerator;
  422. pointerThreshold*,
  423. maxInterpolation* : LONGINT; (* allows limiting the interpolation degree on Draw *)
  424. PROCEDURE &Init*(w, h : LONGINT; alpha : BOOLEAN);
  425. BEGIN
  426. Init^(w, h, alpha);
  427. NEW(img);
  428. IF alpha THEN Raster.Create(img, w, h, Raster.BGRA8888) ELSE Raster.Create(img, w, h, format) END;
  429. SetCanvasGenerator(Graphics.GenCanvas);
  430. pointerThreshold := 1; (* invisible pixels are treated as invisible *)
  431. maxInterpolation := Graphics.ScaleBilinear;
  432. END Init;
  433. PROCEDURE SetCanvasGenerator*(canvasGen:Graphics.CanvasGenerator);
  434. BEGIN{EXCLUSIVE}
  435. SELF.canvasGen:=canvasGen; IF img # NIL THEN canvas:=canvasGen(img); END;
  436. IF manager # NIL THEN manager.AddVisibleDirty(SELF, bounds) END
  437. END SetCanvasGenerator;
  438. PROCEDURE IsHit(x, y : LONGINT) : BOOLEAN;
  439. VAR w, h : LONGINT; fx, fy : REAL;
  440. BEGIN
  441. w := GetWidth(); h := GetHeight();
  442. IF (w > 0) & (h > 0) & ((w # img.width) OR (h # img.height)) THEN
  443. fx := img.width / w; fy := img.height / h;
  444. RETURN Graphics.IsBitmapHit(ENTIER(x * fx), ENTIER(y * fy), pointerThreshold, img)
  445. ELSE RETURN Graphics.IsBitmapHit(x, y, pointerThreshold, img)
  446. END
  447. END IsHit;
  448. PROCEDURE Draw*(canvas : Graphics.Canvas; w, h, q : LONGINT);
  449. VAR img: Graphics.Image;
  450. BEGIN
  451. img := SELF.img;
  452. IF reduceQuality THEN q := 0 END;
  453. IF img # NIL THEN
  454. IF (w = img.width) & (h = img.height) THEN
  455. IF useAlpha THEN canvas.DrawImage(0, 0, img, Graphics.ModeSrcOverDst)
  456. ELSE canvas.DrawImage(0, 0, img, Graphics.ModeCopy)
  457. END
  458. ELSE
  459. IF useAlpha THEN
  460. canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
  461. Rectangles.MakeRect(0, 0, w, h), Graphics.ModeSrcOverDst, MIN( q,maxInterpolation))
  462. ELSE
  463. canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
  464. Rectangles.MakeRect(0, 0, w, h), Graphics.ModeCopy, MIN(q,maxInterpolation))
  465. END
  466. END
  467. END;
  468. INC(timestamp);
  469. END Draw;
  470. PROCEDURE Invalidate*(rect : Rectangle);
  471. VAR w, h : LONGINT; fx, fy : REAL;
  472. BEGIN
  473. w := GetWidth(); h := GetHeight();
  474. IF (w > 0) & (h > 0) & ((w # img.width) OR (h # img.height)) THEN
  475. fx := w / img.width; fy := h / img.height;
  476. rect.l := ENTIER(rect.l * fx); rect.t := ENTIER(rect.t * fy);
  477. rect.r := ENTIER(rect.r * fx + 0.5); rect.b := ENTIER(rect.b * fy + 0.5)
  478. END;
  479. Invalidate^(rect)
  480. END Invalidate;
  481. PROCEDURE Handle*(VAR m : Message);
  482. VAR w, h : LONGINT; fx, fy : REAL;
  483. BEGIN
  484. w := GetWidth(); h := GetHeight();
  485. IF (w > 0) & (h > 0) & ((w # img.width) OR (h # img.height)) & (m.msgType = Messages.MsgPointer) THEN
  486. m.x := m.x-bounds.l; m.y := m.y-bounds.t;
  487. fx := img.width / w; fy := img.height / h; m.x := ENTIER(m.x * fx); m.y := ENTIER(m.y * fy);
  488. m.x := m.x + bounds.l; m.y := m.y+bounds.l;
  489. END;
  490. Handle^(m)
  491. END Handle;
  492. END BufferWindow;
  493. DoubleBufferWindow* = OBJECT(BufferWindow)
  494. VAR
  495. visibleCanvas : Graphics.BufferCanvas;
  496. backImg* : Graphics.Image;
  497. swapping, drawing : BOOLEAN;
  498. PROCEDURE &Init*(w, h: LONGINT; alpha : BOOLEAN);
  499. BEGIN
  500. NEW(backImg);
  501. IF alpha THEN Raster.Create(backImg, w, h, Raster.BGRA8888) ELSE Raster.Create(backImg, w, h, format) END;
  502. Init^(w, h, alpha);
  503. END Init;
  504. PROCEDURE ReInit*(w, h : LONGINT);
  505. BEGIN {EXCLUSIVE}
  506. AWAIT(~drawing);
  507. IF useAlpha THEN
  508. Raster.Create(img, w, h, Raster.BGRA8888);
  509. Raster.Create(backImg, w, h, Raster.BGRA8888)
  510. ELSE
  511. Raster.Create(img, w, h, format);
  512. Raster.Create(backImg, w, h, format)
  513. END;
  514. visibleCanvas:=canvasGen(img);
  515. canvas:=canvasGen(backImg);
  516. END ReInit;
  517. PROCEDURE SetCanvasGenerator*(canvasGen:Graphics.CanvasGenerator);
  518. BEGIN
  519. SELF.canvasGen:=canvasGen;
  520. IF img # NIL THEN visibleCanvas:=canvasGen(img); END;
  521. IF backImg # NIL THEN canvas:=canvasGen(backImg); END;
  522. IF manager # NIL THEN manager.AddVisibleDirty(SELF, bounds) END
  523. END SetCanvasGenerator;
  524. PROCEDURE Draw*(canvas : Graphics.Canvas; w, h, q : LONGINT);
  525. BEGIN
  526. BEGIN{EXCLUSIVE}
  527. AWAIT(~swapping); drawing := TRUE;
  528. END;
  529. IF reduceQuality THEN q := 0 END;
  530. IF img # NIL THEN
  531. IF (w = img.width) & (h = img.height) THEN
  532. IF useAlpha THEN canvas.DrawImage(0, 0, img, Graphics.ModeSrcOverDst)
  533. ELSE canvas.DrawImage(0, 0, img, Graphics.ModeCopy)
  534. END
  535. ELSE
  536. IF useAlpha THEN
  537. canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
  538. Rectangles.MakeRect(0, 0, w, h), Graphics.ModeSrcOverDst, MIN(q,maxInterpolation))
  539. ELSE
  540. canvas.ScaleImage(img, Rectangles.MakeRect(0, 0, img.width, img.height),
  541. Rectangles.MakeRect(0, 0, w, h), Graphics.ModeCopy, MIN(q,maxInterpolation))
  542. END
  543. END
  544. END;
  545. BEGIN{EXCLUSIVE}
  546. drawing := FALSE;
  547. END;
  548. INC(timestamp);
  549. END Draw;
  550. PROCEDURE CopyRect*(rect : Rectangle);
  551. BEGIN {EXCLUSIVE}
  552. swapping := TRUE;
  553. AWAIT(~drawing);
  554. visibleCanvas.SetClipRect(rect);
  555. visibleCanvas.DrawImage(0, 0, backImg, Graphics.ModeCopy);
  556. visibleCanvas.SetClipRect(visibleCanvas.limits);
  557. swapping := FALSE
  558. END CopyRect;
  559. PROCEDURE Swap*;
  560. VAR tmp : Graphics.Image; tmpc : Graphics.BufferCanvas;
  561. BEGIN {EXCLUSIVE}
  562. swapping := TRUE;
  563. AWAIT(~drawing);
  564. tmp := img; img := backImg; backImg := tmp;
  565. tmpc := canvas; canvas := visibleCanvas; visibleCanvas := tmpc;
  566. swapping := FALSE
  567. END Swap;
  568. END DoubleBufferWindow;
  569. (** A ViewPort observes the global coordinate space. The WindowManager calls the view on all changes that occur
  570. in the observed range. *)
  571. ViewPort* = OBJECT (Plugins.Plugin)
  572. VAR
  573. next* : ViewPort;
  574. manager* : WindowManager;
  575. range* : RealRect;
  576. (* Width and height of viewport at 1:1 zoom. Will be set once in the constructor of the ViewPort implementation *)
  577. width0*, height0* : LONGINT; (* read-only! *)
  578. (** The WindowManager calls the Update Procedure in locked state. *)
  579. PROCEDURE Update*(r : Rectangle; top : Window);
  580. END Update;
  581. (** The WindowManager calls the Update Procedure in locked state. *)
  582. PROCEDURE Refresh*(top : Window);
  583. END Refresh;
  584. (** Set the observed range *)
  585. PROCEDURE SetRange*(x, y, w, h : REAL; showTransition : BOOLEAN);
  586. END SetRange;
  587. (** Return the modifier keys that are pressed in the view *)
  588. PROCEDURE GetKeyState*(VAR state : SET);
  589. END GetKeyState;
  590. END ViewPort;
  591. Decorator* = PROCEDURE {DELEGATE} (w : Window);
  592. WindowManager* = OBJECT(Plugins.Plugin)
  593. VAR
  594. pointerNull*, pointerStandard*, pointerMove*, pointerText*, pointerCrosshair*,
  595. pointerLeftRight*, pointerUpDown*, pointerULDR*, pointerURDL*, pointerLink* : PointerInfo;
  596. decorate* : Decorator;
  597. viewRegistry- : Plugins.Registry;
  598. sequencer- : Messages.MsgSequencer; (** PROTECTED *)
  599. lock- : Locks.RWLock; (** PROTECTED *)
  600. messagePreviewList : MessagePreviewList;
  601. style : WindowStyle;
  602. PROCEDURE &Init*;
  603. BEGIN
  604. NEW(pointerNull);
  605. InitCursors;
  606. decorate := NIL;
  607. NEW(viewRegistry, "View#", "Views Port Window Manager");
  608. NEW(sequencer, Handle); lock := sequencer.lock;
  609. messagePreviewList := NIL;
  610. NEW(style);
  611. END Init;
  612. PROCEDURE InitCursors;
  613. BEGIN
  614. LoadCursor("ZeroSkin.zip://arrow.png", 0, 0, pointerStandard);
  615. LoadCursor("ZeroSkin.zip://move.png", 15, 15, pointerMove);
  616. LoadCursor("ZeroSkin.zip://text.png", 13, 12, pointerText);
  617. LoadCursor("ZeroSkin.zip://crosshair.png", 13, 12, pointerCrosshair);
  618. LoadCursor("ZeroSkin.zip://leftright.png", 13, 12, pointerLeftRight);
  619. LoadCursor("ZeroSkin.zip://updown.png", 13, 12, pointerUpDown);
  620. LoadCursor("ZeroSkin.zip://uldr.png", 13, 12, pointerULDR);
  621. LoadCursor("ZeroSkin.zip://urdl.png", 13, 12, pointerURDL);
  622. LoadCursor("ZeroSkin.zip://hand.png", 6, 0, pointerLink);
  623. END InitCursors;
  624. PROCEDURE ZeroSkin*;
  625. BEGIN
  626. lock.AcquireWrite;
  627. style.Init;
  628. SetStyle(style);
  629. InitCursors;
  630. lock.ReleaseWrite
  631. END ZeroSkin;
  632. PROCEDURE ShutDown*;
  633. BEGIN
  634. ASSERT(lock.HasWriteLock());
  635. Plugins.main.Remove(viewRegistry)
  636. END ShutDown;
  637. (** Window management *)
  638. (** Add adds a window at pos l, t with flags *)
  639. PROCEDURE Add*(l, t : LONGINT; item : Window; flags:SET);
  640. END Add;
  641. (** Remove removes a window *)
  642. PROCEDURE Remove*(item : Window);
  643. END Remove;
  644. (** Set the position of a window *)
  645. PROCEDURE SetWindowPos*(vs : Window; x, y : LONGINT);
  646. END SetWindowPos;
  647. (** Set the size of a window. Return the new size in width and height *)
  648. (** If the window contains left, top, right or bottom, SetWindowSize is called
  649. appropriately *)
  650. PROCEDURE SetWindowSize*(vs : Window; VAR width, height : LONGINT);
  651. END SetWindowSize;
  652. (** Add a region to be refreshed *)
  653. PROCEDURE AddDirty*(VAR rect:Rectangle);
  654. END AddDirty;
  655. (** Add a dirty region. The region is in window coordinates and will be clipped against non transparent
  656. windows above *)
  657. PROCEDURE AddVisibleDirty*(w : Window; rect : Rectangle);
  658. END AddVisibleDirty;
  659. (** Set the keyboard focus to the window w *)
  660. PROCEDURE SetFocus*(w : Window);
  661. END SetFocus;
  662. (** Add a decoration window w to window to. The window w must separately be added to the wm *)
  663. (** A window MUST NOT be added more than once *)
  664. (** MUST hold lock *)
  665. PROCEDURE AddDecorWindow*(to, decor : Window);
  666. VAR dl : DecorList;
  667. BEGIN
  668. lock.AcquireWrite;
  669. INCL(decor.flags, FlagDecorWindow);
  670. INCL(decor.flags, FlagHidden);
  671. decor.master := to;
  672. NEW(dl); dl.w := decor; dl.next := to.decor; to.decor := dl;
  673. lock.ReleaseWrite
  674. END AddDecorWindow;
  675. (** Remove a decoration window w from window from. The window w must separately be removed from the wm *)
  676. (** MUST hold lock *)
  677. PROCEDURE RemoveDecorWindow*(w, from : Window);
  678. VAR dl : DecorList;
  679. BEGIN
  680. lock.AcquireWrite;
  681. IF (from.decor # NIL) & (from.decor.w = w) THEN from.decor := from.decor.next
  682. ELSE
  683. dl := from.decor;
  684. WHILE (dl.next # NIL) & (dl.next.w # w) DO dl := dl.next END;
  685. IF dl.next # NIL THEN dl.next := dl.next.next END
  686. END;
  687. lock.ReleaseWrite
  688. END RemoveDecorWindow;
  689. PROCEDURE SetStyle*(x : WindowStyle);
  690. VAR m : Message;
  691. BEGIN
  692. ASSERT(style # NIL);
  693. style := x; m.msgType := Messages.MsgStyleChanged; m.ext := style;
  694. Broadcast(m)
  695. END SetStyle;
  696. PROCEDURE GetStyle*() : WindowStyle;
  697. BEGIN
  698. ASSERT(style # NIL);
  699. RETURN style
  700. END GetStyle;
  701. (** Move Window w to front. If FlagStayOnTop is not set in w.flags, w will stay behind all windows with this flag set *)
  702. PROCEDURE ToFront*(w : Window);
  703. END ToFront;
  704. (** Move Window w to the background. If FlagStayOnTop is not set in w.flags, w will stay behind all windows *)
  705. PROCEDURE ToBack*(w : Window);
  706. END ToBack;
  707. PROCEDURE SetIsVisible*(w : Window; isVisible : BOOLEAN);
  708. VAR d : DecorList;
  709. BEGIN
  710. ASSERT(w # NIL);
  711. lock.AcquireWrite;
  712. IF (w.isVisible # isVisible) THEN
  713. w.isVisible := isVisible;
  714. IF (w.leftW # NIL) THEN w.leftW.isVisible := isVisible; END;
  715. IF (w.rightW # NIL) THEN w.rightW.isVisible := isVisible; END;
  716. IF (w.topW # NIL) THEN w.topW.isVisible := isVisible; END;
  717. IF (w.bottomW # NIL) THEN w.bottomW.isVisible := isVisible; END;
  718. AddDirty(w.bounds);
  719. IF (w.decor # NIL) THEN
  720. d := w.decor;
  721. WHILE (d # NIL) & (d.w # NIL) DO
  722. AddDirty(d.w.bounds);
  723. d := d.next;
  724. END;
  725. END;
  726. IncOTimestamp;
  727. END;
  728. lock.ReleaseWrite;
  729. END SetIsVisible;
  730. (** Set icon for a given window. Icon may be set to NIL. *)
  731. PROCEDURE SetWindowIcon*(w : Window; icon : Graphics.Image);
  732. VAR tw : Window;
  733. BEGIN
  734. ASSERT(w # NIL);
  735. lock.AcquireWrite;
  736. w.icon := icon;
  737. tw := w.topW;
  738. IF tw # NIL THEN AddVisibleDirty(tw, tw.bounds) END;
  739. lock.ReleaseWrite;
  740. IncOTimestamp;
  741. END SetWindowIcon;
  742. (** Return the window at postition x, y in global space. *)
  743. (** Windows that have the FlagNavigate flag set will not be considered *)
  744. (** Must hold WM lock *)
  745. PROCEDURE GetPositionOwner*(x, y : LONGINT) : Window;
  746. END GetPositionOwner;
  747. PROCEDURE GetFocusOwner*() : Window;
  748. END GetFocusOwner;
  749. (** Set the title of a window as UTF-8 string *)
  750. PROCEDURE SetWindowTitle*(w : Window; title : String);
  751. VAR tw : Window;
  752. BEGIN
  753. lock.AcquireWrite;
  754. w.title := title;
  755. tw := w.topW;
  756. IF tw # NIL THEN AddVisibleDirty(tw, tw.bounds) END;
  757. lock.ReleaseWrite;
  758. IncWTimestamp; (* since navigation elements care about window title *)
  759. END SetWindowTitle;
  760. (** Get the title of a window as UTF-8 string *)
  761. PROCEDURE GetWindowTitle*(w : Window) : String;
  762. BEGIN
  763. RETURN w.title
  764. END GetWindowTitle;
  765. PROCEDURE SetWindowInfo*(w : Window; CONST info : WindowInfo);
  766. BEGIN
  767. ASSERT(w # NIL);
  768. lock.AcquireWrite;
  769. IF (w.info = NIL) THEN NEW(w.info); END;
  770. w.info^ := info;
  771. lock.ReleaseWrite;
  772. IncOTimestamp;
  773. END SetWindowInfo;
  774. PROCEDURE GetWindowInfo*(w : Window; VAR info : WindowInfo) : BOOLEAN;
  775. VAR infoPtr : WindowInfoPtr;
  776. BEGIN
  777. ASSERT(w # NIL);
  778. lock.AcquireRead;
  779. infoPtr := w.info;
  780. IF (infoPtr # NIL) THEN
  781. info := infoPtr^;
  782. END;
  783. lock.ReleaseRead;
  784. RETURN (infoPtr # NIL);
  785. END GetWindowInfo;
  786. (** Set or unset a window flag
  787. Note: Setting FlagStayOnTop unsets FlagStayOnBottom and vice versa *)
  788. PROCEDURE SetWindowFlag*(w : Window; flag : LONGINT; value : BOOLEAN);
  789. BEGIN
  790. ASSERT(w # NIL);
  791. ASSERT((flag = FlagFrame) OR (flag = FlagStayOnTop) OR (flag = FlagStayOnBottom) OR (flag = FlagHidden));
  792. END SetWindowFlag;
  793. (** Set if the window is willing to accept a dropped item *)
  794. PROCEDURE SetAcceptDrag*(w : Window; accept : BOOLEAN);
  795. BEGIN
  796. lock.AcquireWrite;
  797. w.acceptDrag := accept;
  798. lock.ReleaseWrite
  799. END SetAcceptDrag;
  800. PROCEDURE StartDrag*(w : Window; sender, data : ANY; img : Graphics.Image; offsetX, offsetY: LONGINT; onAccept, onReject : Messages.CompCommand) : BOOLEAN;
  801. END StartDrag;
  802. (** a pointer button must be pressed *)
  803. PROCEDURE TransferPointer*( to : Window) : BOOLEAN;
  804. END TransferPointer;
  805. (** Adjust pointer to new position / check picture *)
  806. PROCEDURE CheckPointerImage*;
  807. END CheckPointerImage;
  808. (** View management *)
  809. (** Add a view *)
  810. PROCEDURE AddView*(v : ViewPort);
  811. END AddView;
  812. (** Add the whole View.range as dirty and cause a redraw *)
  813. PROCEDURE RefreshView*(v : ViewPort);
  814. END RefreshView;
  815. (** RemoveView from windowmanager *)
  816. PROCEDURE RemoveView*(v : ViewPort);
  817. END RemoveView;
  818. (** Messages *)
  819. PROCEDURE Broadcast*(VAR m : Message);
  820. END Broadcast;
  821. PROCEDURE SendMessage*(dest : Window; VAR m : Message) : BOOLEAN;
  822. BEGIN
  823. IF dest.sequencer # NIL THEN RETURN dest.sequencer.Add(m)
  824. ELSE dest.Handle(m); RETURN TRUE
  825. END
  826. END SendMessage;
  827. (** Install a message preview procedure. The window manager calls the MessagePreviewProc for
  828. all external messages so that they can be recorded, changed or discarded *)
  829. PROCEDURE InstallMessagePreview*(x : MessagePreviewProc);
  830. VAR mpl : MessagePreviewList;
  831. BEGIN
  832. lock.AcquireWrite;
  833. NEW(mpl); mpl.next := messagePreviewList; mpl.proc := x; messagePreviewList := mpl;
  834. lock.ReleaseWrite
  835. END InstallMessagePreview;
  836. (** Remove a MessagePreviewProc *)
  837. PROCEDURE RemoveMessagePreview*(x : MessagePreviewProc);
  838. VAR cur : MessagePreviewList;
  839. BEGIN
  840. lock.AcquireWrite;
  841. IF (messagePreviewList # NIL) & (messagePreviewList.proc = x) THEN messagePreviewList := messagePreviewList.next
  842. ELSE
  843. cur := messagePreviewList;
  844. WHILE cur # NIL DO
  845. IF (cur.next # NIL) & (cur.next.proc = x) THEN cur.next := cur.next.next; lock.ReleaseWrite; RETURN
  846. ELSE cur := cur.next END
  847. END
  848. END;
  849. lock.ReleaseWrite
  850. END RemoveMessagePreview;
  851. (** Preview message to all installed message preview handlers. Only to be used by WindowManager itself *)
  852. PROCEDURE PreviewMessage*(VAR m : Message; VAR discard : BOOLEAN); (* protected *)
  853. VAR mpl : MessagePreviewList;
  854. BEGIN
  855. ASSERT(lock.HasReadLock());
  856. discard := FALSE;
  857. mpl := messagePreviewList;
  858. WHILE (mpl # NIL) & ~discard DO mpl.proc(m, discard); mpl := mpl.next END;
  859. END PreviewMessage;
  860. (** Enumeration *)
  861. (** Get the first "user" window --> May return NIL if only background and pointer window are installed *)
  862. (** Must hold lock *)
  863. PROCEDURE GetFirst*() : Window;
  864. END GetFirst;
  865. (** Get the window next "user" window on top of x *)
  866. PROCEDURE GetNext*(x : Window) : Window;
  867. END GetNext;
  868. (** Get the "user" window below x *)
  869. PROCEDURE GetPrev*(x : Window) : Window;
  870. END GetPrev;
  871. (** Replace the background window with w. Return the current background window *)
  872. PROCEDURE ReplaceBackground*(w : Window) : Window;
  873. END ReplaceBackground;
  874. (** Return the area that is actually occupied *)
  875. PROCEDURE GetPopulatedArea*(VAR r : Rectangle);
  876. END GetPopulatedArea;
  877. (** Internal handler for message that are directed to the window manager never call directly ! *)
  878. PROCEDURE HandleInternal*(VAR msg : Messages.Message); (** PROTECTED *)
  879. BEGIN
  880. ASSERT(sequencer.IsCallFromSequencer())
  881. END HandleInternal;
  882. (** All external events of the window manager are inserted here *)
  883. PROCEDURE Handle*(VAR msg : Messages.Message);
  884. VAR discard : BOOLEAN;
  885. BEGIN
  886. IF sequencer.IsCallFromSequencer() THEN
  887. PreviewMessage(msg, discard);
  888. IF ~discard THEN HandleInternal(msg) END
  889. ELSE
  890. IF ~sequencer.Add(msg) THEN
  891. KernelLog.String("A message sent to the WM could not be handled "); KernelLog.Ln
  892. END
  893. END
  894. END Handle;
  895. END WindowManager;
  896. VAR
  897. registry- : Plugins.Registry;
  898. pointerNull: PointerInfo;
  899. (* Changes whenever a Window is added or removed to/from a WindowManager *)
  900. wTimestamp- : LONGINT;
  901. (* Changes whenever the keyboard focus is given to another window or the visibility of a window changed *)
  902. oTimestamp- : LONGINT;
  903. (* Coordinate offsets use to determine position of a new window *)
  904. x1, y1 : LONGINT;
  905. format* : Raster.Format;
  906. nextId : LONGINT;
  907. standardCursorImage: Graphics.Image;
  908. (* Get a unique identifier *)
  909. PROCEDURE GetId() : LONGINT;
  910. BEGIN {EXCLUSIVE}
  911. INC(nextId);
  912. RETURN nextId;
  913. END GetId;
  914. PROCEDURE IncWTimestamp*;
  915. BEGIN {EXCLUSIVE}
  916. INC(wTimestamp);
  917. END IncWTimestamp;
  918. PROCEDURE IncOTimestamp*;
  919. BEGIN {EXCLUSIVE}
  920. INC(oTimestamp);
  921. END IncOTimestamp;
  922. (** Block until a window is added/removed, changes its visibility or the keyboard focus changes *)
  923. PROCEDURE AwaitChange*(wTs, oTs : LONGINT);
  924. BEGIN {EXCLUSIVE}
  925. AWAIT((wTimestamp # wTs) OR (oTimestamp # oTs));
  926. END AwaitChange;
  927. PROCEDURE ClearInfo*(VAR info : WindowInfo);
  928. VAR i : LONGINT;
  929. BEGIN
  930. FOR i := 0 TO LEN(info.openDocuments)-1 DO
  931. info.openDocuments[i].id := 0;
  932. info.openDocuments[i].name := "";
  933. info.openDocuments[i].fullname := "";
  934. info.openDocuments[i].modified := FALSE;
  935. info.openDocuments[i].hasFocus := FALSE;
  936. END;
  937. info.handleDocumentInfo := NIL;
  938. info.vc.width := 0;
  939. info.vc.height := 0;
  940. info.vc.generator := NIL;
  941. END ClearInfo;
  942. PROCEDURE NewString*(CONST x : ARRAY OF CHAR) : String;
  943. VAR t : String;
  944. BEGIN
  945. NEW(t, LEN(x)); COPY(x, t^); RETURN t
  946. END NewString;
  947. PROCEDURE LoadCursor*(CONST name : ARRAY OF CHAR; hx, hy : LONGINT; VAR pi : PointerInfo);
  948. BEGIN
  949. IF pi = NIL THEN NEW(pi) END;
  950. pi.img := Graphics.LoadImage(name, TRUE); pi.hotX := hx; pi.hotY := hy;
  951. IF pi.img = NIL THEN
  952. KernelLog.String("Picture not loaded : "); KernelLog.String(name); KernelLog.Ln;
  953. IF standardCursorImage = NIL THEN CreateStandardCursorImage END;
  954. pi.img := standardCursorImage; pi.hotX := 0; pi.hotY := 0;
  955. END
  956. END LoadCursor;
  957. PROCEDURE GetDefaultManager*() : WindowManager;
  958. VAR p : Plugins.Plugin;
  959. BEGIN
  960. p := registry.Await("");
  961. RETURN p(WindowManager)
  962. END GetDefaultManager;
  963. PROCEDURE GetDefaultView*() : ViewPort;
  964. VAR p : Plugins.Plugin; m : WindowManager;
  965. BEGIN
  966. m := GetDefaultManager();
  967. p := m.viewRegistry.Await("");
  968. RETURN p(ViewPort)
  969. END GetDefaultView;
  970. PROCEDURE ResetNextPosition*;
  971. BEGIN {EXCLUSIVE}
  972. x1 := 0; y1 := 0;
  973. END ResetNextPosition;
  974. PROCEDURE GetNextPosition*(window : Window; manager : WindowManager; view : ViewPort; VAR dx, dy : LONGINT);
  975. VAR style : WindowStyle; x, y : LONGINT;
  976. BEGIN {EXCLUSIVE}
  977. ASSERT((window # NIL) & (manager # NIL) & (view # NIL));
  978. style := manager.GetStyle();
  979. x := style.lw; y := style.th;
  980. dx := x + X0 + x1; dy := y + Y0 + y1;
  981. INC(x1, x); INC(y1, y);
  982. IF (x1 > ENTIER(0.3 * view.width0)) OR (y1 > ENTIER(0.3 * view.height0)) THEN
  983. x1 := 0; y1 := 0;
  984. END;
  985. END GetNextPosition;
  986. PROCEDURE DefaultAddWindow*(w : Window);
  987. VAR manager : WindowManager; view : ViewPort; dy, dx : LONGINT;
  988. BEGIN
  989. manager := GetDefaultManager();
  990. view := GetDefaultView();
  991. GetNextPosition(w, manager, view, dx, dy);
  992. manager.Add(ENTIER(view.range.l) + dx, ENTIER(view.range.t) + dy, w, {FlagFrame, FlagClose, FlagMinimize});
  993. manager.SetFocus(w)
  994. END DefaultAddWindow;
  995. PROCEDURE AddWindow*(w : Window; dx, dy : LONGINT);
  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, {FlagFrame, FlagClose, FlagMinimize})
  1001. END AddWindow;
  1002. PROCEDURE ExtAddWindow*(w : Window; dx, dy : LONGINT; flags : SET);
  1003. VAR manager : WindowManager; view : ViewPort;
  1004. BEGIN
  1005. manager := GetDefaultManager();
  1006. view := GetDefaultView();
  1007. manager.Add(ENTIER(view.range.l) + dx, ENTIER(view.range.t) + dy, w, flags)
  1008. END ExtAddWindow;
  1009. PROCEDURE ExtAddViewBoundWindow*(w : Window; dx, dy : LONGINT; view : ViewPort; flags : SET);
  1010. VAR manager : WindowManager;
  1011. BEGIN
  1012. flags := flags + {FlagNavigation};
  1013. manager := GetDefaultManager();
  1014. manager.Add(dx, dy, w, flags);
  1015. END ExtAddViewBoundWindow;
  1016. (** move a window to the default view *)
  1017. PROCEDURE DefaultBringToView*(w : Window; toFront : BOOLEAN);
  1018. VAR manager : WindowManager; view : ViewPort; dy, dx : LONGINT;
  1019. BEGIN
  1020. manager := GetDefaultManager();
  1021. view := GetDefaultView();
  1022. GetNextPosition(w, manager, view, dx, dy);
  1023. manager.SetWindowPos(w, ENTIER(view.range.l) + dx, ENTIER(view.range.t) + dy);
  1024. manager.SetFocus(w);
  1025. IF toFront THEN manager.ToFront(w) END
  1026. END DefaultBringToView;
  1027. PROCEDURE CleanUp;
  1028. BEGIN
  1029. Plugins.main.Remove(registry)
  1030. END CleanUp;
  1031. PROCEDURE CreateStandardCursorImage;
  1032. CONST Width = 32; Height = 32;
  1033. VAR canvas: Graphics.BufferCanvas; rect: Rectangles.Rectangle; points: ARRAY 3 OF Graphics.Point2d;
  1034. BEGIN
  1035. NEW(standardCursorImage);
  1036. Raster.Create(standardCursorImage, Width, Height, Raster.BGRA8888);
  1037. NEW(canvas, standardCursorImage);
  1038. Rectangles.SetRect (rect, 0, 0, Width, Height);
  1039. canvas.Fill(rect, 0H, Graphics.ModeCopy);
  1040. points[0].x := Width; points[0].y := Height DIV 2;
  1041. points[1].x := 0; points[1].y := 0;
  1042. points[2].x := Width DIV 2; points[2].y := Height;
  1043. canvas.FillPolygonFlat(points, 3, Graphics.White - 080H, Graphics.ModeCopy);
  1044. canvas.PolyLine(points, 3, FALSE, Graphics.Black, Graphics.ModeCopy);
  1045. END CreateStandardCursorImage;
  1046. BEGIN
  1047. Modules.InstallTermHandler(CleanUp);
  1048. NEW(registry, "WM#", "Window Managers");
  1049. nextId := 0; x1 := 0; y1 := 0;
  1050. wTimestamp := 0; oTimestamp := 0;
  1051. format := Raster.BGRA8888;
  1052. NEW(pointerNull);
  1053. standardCursorImage := NIL;
  1054. END WMWindowManager.