FRAMEMAN.MOD 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. IMPLEMENTATION MODULE FrameManager;
  2. (*
  3. * REPERTOIRE
  4. * Release 1.6
  5. * By Charles Bradford and Cole Brecheen
  6. * (c) Copyright 1985-1992 PMI
  7. * Green Bay, Wisconsin
  8. * All rights reserved
  9. * (414) 468-6040
  10. *
  11. * $Header: D:/logfiles/mods/frameman.mov 1.5 10 Mar 1991 15:27:50 coleb $
  12. *
  13. *)
  14. (*
  15. IMPORT Diagnostics;
  16. *)
  17. IMPORT ErrorManager;
  18. IMPORT FramePainter;
  19. IMPORT GenLists;
  20. IMPORT Hash;
  21. IMPORT ListUtils;
  22. IMPORT Rectangles;
  23. IMPORT ScrnTypes;
  24. IMPORT SYSTEM;
  25. IMPORT VWindows;
  26. VAR
  27. Initialized : BOOLEAN;
  28. (* The idea here is that we have a list of windows, each of
  29. which has a list of active DisplayFrames (pointers to
  30. DisplayFrameRecs) in the position immediately following it.
  31. A DisplayFrame's position in the window list indicates how
  32. it is stacked --position 1 means it is in the foreground,
  33. and each position after that means it is farther into the
  34. background *)
  35. CONST
  36. FrameCode = 65529;
  37. WindowCode = 65528;
  38. (* arbitrary *)
  39. VAR
  40. WindowListInitialized : BOOLEAN;
  41. WindowList: GenLists.GenList;
  42. PROCEDURE CleanUp();
  43. BEGIN
  44. (*
  45. Diagnostics.diagS( 'About to DisposeList', '' );
  46. *)
  47. GenLists.DisposeList( WindowList );
  48. END CleanUp;
  49. PROCEDURE AddWindow( TheWindow: VWindows.AWindowHandle );
  50. VAR
  51. ActiveFrameList : GenLists.GenList;
  52. BEGIN
  53. IF NOT WindowListInitialized THEN
  54. GenLists.NewList( WindowList );
  55. WindowListInitialized := TRUE;
  56. ErrorManager.AddTermProc( CleanUp );
  57. END;
  58. IF ListUtils.ObjectSpot( TheWindow, WindowList, 1, 65535 ) > 0 THEN
  59. (*TheWindow is already in WindowList. We don't complain
  60. about redundant adds because most frames will be
  61. associated with the same window, and we don't want
  62. InitDisplayFrame to have to worry about whether a
  63. window has already been added. *)
  64. RETURN;
  65. END;
  66. GenLists.NewList( ActiveFrameList );
  67. GenLists.ListInsert( ActiveFrameList, GenLists.ListCode, WindowList, 1 );
  68. GenLists.ListInsert( TheWindow, WindowCode, WindowList, 1 );
  69. END AddWindow;
  70. PROCEDURE DeleteWindow( TheWindow: VWindows.AWindowHandle );
  71. VAR
  72. ActiveFrameList : GenLists.GenList;
  73. spot : CARDINAL;
  74. BEGIN
  75. spot := ListUtils.ObjectSpot( TheWindow, WindowList, 1, 65535 );
  76. IF spot > 0 THEN
  77. GenLists.ListDelete( WindowList, spot, 2 );
  78. END;
  79. END DeleteWindow;
  80. PROCEDURE GetAssociatedFrames( TheWindow:
  81. VWindows.AWindowHandle; VAR FrameList: GenLists.GenList );
  82. VAR
  83. spot: CARDINAL;
  84. BEGIN
  85. spot := ListUtils.ObjectSpot( TheWindow, WindowList, 1, 65535 );
  86. IF spot > 0 THEN
  87. GenLists.GetChildList( WindowList, spot + 1, FrameList );
  88. IF GenLists.Initialized( FrameList ) THEN
  89. RETURN;
  90. END;
  91. END;
  92. ErrorManager.WARN( "You're missing a call to AddWindow somewhere" );
  93. END GetAssociatedFrames;
  94. PROCEDURE FrameIsInForeGround( TheFrame: ScrnTypes.DisplayFrame );
  95. VAR
  96. ActiveFrameList : GenLists.GenList;
  97. spot: CARDINAL;
  98. BEGIN
  99. GetAssociatedFrames( TheFrame^.WindowHandle, ActiveFrameList );
  100. spot := ListUtils.ObjectSpot( TheFrame, ActiveFrameList, 1, 65535 );
  101. IF spot = 0 THEN
  102. ErrorManager.WARN( 'Frame not active' );
  103. END;
  104. (* Now move TheFrame to the front of ActiveFrameList. *)
  105. IF spot # 1 THEN
  106. GenLists.ListDelete( ActiveFrameList, spot, 1 );
  107. GenLists.ListInsert( TheFrame, FrameCode, ActiveFrameList, 1 );
  108. END;
  109. END FrameIsInForeGround;
  110. PROCEDURE GetFrameFromList( list: GenLists.GenList; spot:
  111. CARDINAL; VAR frame: ScrnTypes.DisplayFrame );
  112. VAR
  113. TypeCode: CARDINAL;
  114. BEGIN
  115. GenLists.GetElmt( list, spot, frame, TypeCode );
  116. IF TypeCode # FrameCode THEN
  117. ErrorManager.WARN( 'Error in frame list' );
  118. END;
  119. END GetFrameFromList;
  120. PROCEDURE FrameActivated( TheFrame: ScrnTypes.DisplayFrame );
  121. VAR
  122. ActiveFrameList : GenLists.GenList;
  123. spot : CARDINAL;
  124. BEGIN
  125. GetAssociatedFrames( TheFrame^.WindowHandle, ActiveFrameList );
  126. spot := ListUtils.ObjectSpot( TheFrame, ActiveFrameList, 1, 65535 );
  127. IF spot > 0 THEN
  128. (* TheFrame is already in the list. *)
  129. RETURN;
  130. END;
  131. GenLists.ListInsert( TheFrame, FrameCode, ActiveFrameList, 1 );
  132. END FrameActivated;
  133. PROCEDURE FrameDeactivated( TheFrame: ScrnTypes.DisplayFrame );
  134. VAR
  135. ActiveFrameList : GenLists.GenList;
  136. spot : CARDINAL;
  137. BEGIN
  138. GetAssociatedFrames( TheFrame^.WindowHandle, ActiveFrameList );
  139. spot := ListUtils.ObjectSpot( TheFrame, ActiveFrameList, 1, 65535 );
  140. IF spot = 0 THEN
  141. (* TheFrame is not in the list. *)
  142. RETURN;
  143. END;
  144. GenLists.ListDelete( ActiveFrameList, spot, 1 );
  145. END FrameDeactivated;
  146. PROCEDURE GetFrameCoords( TheFrame: ScrnTypes.DisplayFrame; VAR
  147. rect: Rectangles.ARectangle );
  148. BEGIN
  149. Rectangles.DefineRectangle( rect, TheFrame^.startcol +
  150. 1, TheFrame^.startrow + 1, TheFrame^.endcol + 1,
  151. TheFrame^.endrow + 1 )
  152. END GetFrameCoords;
  153. PROCEDURE IsFrameObscured( TheFrame: ScrnTypes.DisplayFrame ):
  154. BOOLEAN;
  155. VAR
  156. FrameRect, tmprect, intersection : Rectangles.ARectangle;
  157. ActiveFrameList : GenLists.GenList;
  158. ListEnd, cnt, spot : CARDINAL;
  159. TmpFrame : ScrnTypes.DisplayFrame;
  160. BEGIN
  161. GetAssociatedFrames( TheFrame^.WindowHandle, ActiveFrameList );
  162. spot := ListUtils.ObjectSpot( TheFrame, ActiveFrameList, 1, 65535 );
  163. IF spot = 0 THEN
  164. (* The frame itself has got to be in the list. *)
  165. ErrorManager.WARN( 'Error in frame list' );
  166. RETURN FALSE;
  167. ELSIF spot = 1 THEN
  168. (* We return if it's 1 because, if the system is working,
  169. a frame that's at the top of the list will never be
  170. obscured *)
  171. RETURN FALSE;
  172. END;
  173. GetFrameCoords( TheFrame, FrameRect );
  174. ListEnd := GenLists.ListLength( ActiveFrameList );
  175. FOR cnt := 1 TO (spot - 1) DO
  176. GetFrameFromList( ActiveFrameList, cnt, TmpFrame );
  177. GetFrameCoords( TmpFrame, tmprect );
  178. IF Rectangles.RectsIntersect( FrameRect, tmprect,
  179. intersection ) THEN
  180. RETURN TRUE;
  181. END;
  182. END;
  183. RETURN FALSE;
  184. END IsFrameObscured;
  185. PROCEDURE EraseFrame( TheFrame: ScrnTypes.DisplayFrame );
  186. VAR
  187. FrameRect, tmprect, intersection : Rectangles.ARectangle;
  188. ActiveFrameList : GenLists.GenList;
  189. ListEnd, cnt, spot : CARDINAL;
  190. TmpFrame : ScrnTypes.DisplayFrame;
  191. BEGIN
  192. FrameIsInForeGround( TheFrame );
  193. FrameDeactivated( TheFrame );
  194. GetFrameCoords( TheFrame, FrameRect );
  195. GetAssociatedFrames( TheFrame^.WindowHandle, ActiveFrameList );
  196. ListEnd := GenLists.ListLength( ActiveFrameList );
  197. (* If FrameRect is wholly within an unobscured frame,
  198. redraw that frame. *)
  199. FOR cnt := 1 TO ListEnd DO
  200. GetFrameFromList( ActiveFrameList, cnt, TmpFrame );
  201. GetFrameCoords( TmpFrame, tmprect );
  202. IF (NOT IsFrameObscured( TmpFrame )) AND
  203. (Rectangles.RectIsInside( FrameRect, tmprect ) ) THEN
  204. FramePainter.RedrawArea( TmpFrame, FrameRect.col1,
  205. FrameRect.row1, FrameRect.col2, FrameRect.row2 );
  206. RETURN
  207. END;
  208. END;
  209. (* otherwise clearpart(rec), then start from bottom and call
  210. redrawarea for each frame that extends into rec *)
  211. VWindows.SetBackColor( TheFrame^.WindowHandle,
  212. VWindows.BackColor(TheFrame^.WindowHandle) );
  213. VWindows.SetMonoAttr( TheFrame^.WindowHandle,
  214. VWindows.MonoAttr(TheFrame^.WindowHandle) );
  215. VWindows.ClearPart( TheFrame^.WindowHandle, FrameRect.col1,
  216. FrameRect.row1, FrameRect.col2, FrameRect.row2 );
  217. cnt := ListEnd;
  218. WHILE cnt >= 1 DO
  219. GetFrameFromList( ActiveFrameList, cnt, TmpFrame );
  220. GetFrameCoords( TmpFrame, tmprect );
  221. IF Rectangles.RectsIntersect( FrameRect, tmprect, intersection ) THEN
  222. FramePainter.RedrawArea( TmpFrame, intersection.col1,
  223. intersection.row1, intersection.col2, intersection.row2 );
  224. END;
  225. DEC( cnt );
  226. END;
  227. END EraseFrame;
  228. PROCEDURE RestoreWholeWindow( TheWindow: VWindows.AWindowHandle );
  229. VAR
  230. ActiveFrameList : GenLists.GenList;
  231. ListEnd, cnt: CARDINAL;
  232. TmpFrame: ScrnTypes.DisplayFrame;
  233. BEGIN
  234. GetAssociatedFrames( TheWindow, ActiveFrameList );
  235. VWindows.SetBackColor( TheWindow, VWindows.BackColor(TheWindow) );
  236. VWindows.SetMonoAttr( TheWindow, VWindows.MonoAttr(TheWindow) );
  237. VWindows.ClearPart( TheWindow, 1, 1, VWindows.EndCol(TheWindow),
  238. VWindows.EndRow(TheWindow) );
  239. ListEnd := GenLists.ListLength( ActiveFrameList );
  240. cnt := ListEnd;
  241. WHILE cnt >= 1 DO
  242. GetFrameFromList( ActiveFrameList, cnt, TmpFrame );
  243. FramePainter.RedrawArea( TmpFrame, TmpFrame^.startcol + 1,
  244. TmpFrame^.startrow + 1, TmpFrame^.endcol + 1,
  245. TmpFrame^.endrow + 1 );
  246. (* Corrected 3 Nov 88 thanks to John McMonagle; was
  247. 0,0,0,0 in 1.5c *)
  248. DEC( cnt );
  249. END;
  250. END RestoreWholeWindow;
  251. PROCEDURE Init();
  252. BEGIN
  253. IF Initialized THEN
  254. RETURN;
  255. ELSE
  256. Initialized := TRUE;
  257. END;
  258. WindowListInitialized := FALSE;
  259. (*
  260. Diagnostics.Init();
  261. *)
  262. ErrorManager.Init();
  263. FramePainter.Init();
  264. GenLists.Init();
  265. Hash.Init();
  266. ListUtils.Init();
  267. Rectangles.Init();
  268. ScrnTypes.Init();
  269. VWindows.Init();
  270. END Init;
  271. BEGIN
  272. Initialized := FALSE;
  273. Init();
  274. END FrameManager.