home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / IOInterface / Window1.icl < prev    next >
Encoding:
Modula Implementation  |  1997-04-23  |  9.8 KB  |  278 lines  |  [TEXT/3PRM]

  1. implementation module Window1;
  2.  
  3. import    StdInt, StdBool, StdString, StdFile;
  4. import    windows, quickdraw;
  5. import    Window2, commonDef, windowDevice, windowAccess;
  6. from    deltaPicture    import EraseRectangle;
  7. from    dialogAccess    import IOStateModalDialogActive;
  8. ::    DeltaWindowHandle    *s        :== !(WindowHandle s) -> !Toolbox -> (! WindowHandle s,  !Toolbox);
  9. ::    DeltaWindowHandles    *s        :== ![WindowHandle s] -> !Toolbox -> (![WindowHandle s], !Toolbox);
  10. ::    DeltaWindowDef        *s *io    :== !(WindowDef s io) -> WindowDef s io;
  11.  
  12. WindowIdOK :: WindowId -> Bool;
  13. WindowIdOK _ = True;
  14.  
  15. ChangeWindows :: !(DeltaWindowHandles s) !(IOState s) -> IOState s;
  16. ChangeWindows f ioState
  17.     =     IOStateSetDevice (IOStateSetToolbox tb1 ioState2) windows1;
  18.     where {
  19.         (windows,    ioState1)    = IOStateGetDevice  ioState WindowDevice;
  20.         (tb,        ioState2)    = IOStateGetToolbox ioState1;
  21.         (wHs,        cursor)        = WindowSystemState_WindowHandles windows;
  22.         (wHs1,        tb1)        = f wHs tb;
  23.         windows1                = WindowSystemState (wHs1, cursor);
  24.     };
  25.  
  26. ChangeWindow :: !(Cond WindowId) !(DeltaWindowHandle s) !(IOState s) -> IOState s;
  27. ChangeWindow cond f ioState = ChangeWindows (ChangeWindowHandles cond f) ioState;
  28.  
  29. ChangeWindowHandles :: !(Cond WindowId) !(DeltaWindowHandle s) ![WindowHandle s] !Toolbox
  30.         ->    (![WindowHandle s],!Toolbox);
  31. ChangeWindowHandles cond f [wH=:(wDef, window) : wHs] tb
  32. |    cond (WindowDefGetWindowId wDef)    = ([wH1 : wHs ], tb1);
  33.                                         = ([wH  : wHs1], tb2);
  34.     where {
  35.         (wH1,  tb1) = f wH tb;
  36.         (wHs1, tb2) = ChangeWindowHandles cond f wHs tb;
  37.     };
  38. ChangeWindowHandles _ _ wHs tb = (wHs, tb);
  39.  
  40.  
  41. /*    Changing the (active) WindowTitle:
  42. */
  43.  
  44. ChangeWindowTitle :: !WindowId !WindowTitle !(IOState s) -> IOState s;
  45. ChangeWindowTitle id title ioState
  46.     =     ChangeWindow ((==) id) (WindowHandleSetTitle title) ioState;
  47.  
  48. ChangeActiveWindowTitle :: !WindowTitle !(IOState s) -> IOState s;
  49. ChangeActiveWindowTitle title ioState
  50.     =     ChangeWindow WindowIdOK (WindowHandleSetTitle title) ioState;
  51.  
  52. WindowHandleSetTitle :: !WindowTitle !(WindowHandle s) !Toolbox -> (!WindowHandle s, !Toolbox);
  53. WindowHandleSetTitle title wH=:(_,(wPtr,_,_,_,_,_)) tb = (wH, SetWTitle wPtr title tb);
  54.  
  55.  
  56. /*    Changing the (active) UpdateFunction:
  57. */
  58.  
  59. ChangeUpdateFunction :: !WindowId !(UpdateFunction s) !(IOState s) -> IOState s;
  60. ChangeUpdateFunction id updateF ioState
  61.     =     ChangeWindow ((==) id) (ChangeWindowDef (WindowDefSetUpdate (Update_new updateF))) ioState;
  62.  
  63. ChangeActiveUpdateFunction :: !(UpdateFunction s) !(IOState s) -> IOState s;
  64. ChangeActiveUpdateFunction updateF ioState
  65.     =     ChangeWindow WindowIdOK (ChangeWindowDef (WindowDefSetUpdate (Update_new updateF))) ioState;
  66.  
  67. Update_new :: !(UpdateFunction *s) !UpdateArea *s -> (!*s, ![DrawFunction]);
  68. Update_new updateF updArea s
  69.     =     (s`, [EraseUpdArea updArea : fs]);
  70.     where {
  71.         (s`, fs)= updateF updArea s;
  72.     };
  73.  
  74. EraseUpdArea :: !UpdateArea !Picture -> Picture;
  75. EraseUpdArea [rect : rects] picture =  EraseUpdArea rects (EraseRectangle rect picture);
  76. EraseUpdArea rects picture =  picture;
  77.  
  78.  
  79. /*    Change the local CursorShape of the (active) window.
  80. */
  81.  
  82. ChangeWindowCursor :: !WindowId !CursorShape !(IOState s) -> IOState s;
  83. ChangeWindowCursor id shape ioState =  ChangeCursor ((==) id) shape ioState;
  84.  
  85. ChangeActiveWindowCursor :: !CursorShape !(IOState s) -> IOState s;
  86. ChangeActiveWindowCursor shape ioState =  ChangeCursor WindowIdOK shape ioState;
  87.  
  88. ChangeCursor :: !(Cond WindowId) !CursorShape !(IOState s) -> IOState s;
  89. ChangeCursor cond shape ioState
  90. |    not exists            = ioState1;
  91. |    not (cond activeId)    = ioState2;
  92.                         = SetRightCursorShape shape ioState2;
  93.     where {
  94.         f                                = ChangeWindowDef (WindowDefSetCursor shape);
  95.         (exists, activeId, ioState1)    = GetActiveWindow ioState;
  96.         ioState2                        = ChangeWindow cond f ioState1;
  97.     };
  98.  
  99. SetRightCursorShape :: !CursorShape !(IOState s) -> IOState s;
  100. SetRightCursorShape shape ioState
  101. |    globalSet || not inFrame    = ioState1;
  102.                                 = IOStateSetCursorShape shape ioState1;
  103.     where {
  104.         (globalSet, inFrame, wPtr, ioState1)= IOStateGetCursorPos ioState;
  105.     };
  106.  
  107. //    Opening windows:
  108.  
  109. OpenWindows :: ![WindowDef s (IOState s)] !(IOState s) -> IOState s;
  110. OpenWindows wDefs ioState
  111.     | IsEmptyList wDefs    = ioState;
  112.                         = ChangeWindows (Open_windows behind wDefs) ioState1;
  113.     where {
  114.         (b, behind, ioState1) = IOStateModalDialogActive ioState;
  115.     };    
  116.             
  117. //    Closing windows:
  118.  
  119. CloseWindows :: ![WindowId] !(IOState s) -> IOState s;
  120. CloseWindows ids ioState
  121. |    IsEmptyList ids    = ioState;
  122.                     = ChangeWindows (CloseWindowHandles ids) ioState;
  123.  
  124. CloseActiveWindow :: !(IOState s) -> IOState s;
  125. CloseActiveWindow ioState = ChangeWindows (CloseWindowHandle WindowIdOK) ioState;
  126.  
  127. CloseWindowHandles :: ![WindowId] ![WindowHandle s] !Toolbox -> (![WindowHandle s], !Toolbox);
  128. CloseWindowHandles [id : ids] wHs tb
  129.     =     CloseWindowHandles ids wHs1 tb1;
  130.     where {
  131.         (wHs1, tb1) = CloseWindowHandle ((==) id) wHs tb;
  132.     };
  133. CloseWindowHandles ids wHs tb = (wHs, tb);
  134.  
  135. CloseWindowHandle :: !(Cond WindowId) ![WindowHandle s] !Toolbox -> (![WindowHandle s], !Toolbox);
  136. CloseWindowHandle cond [wH=:(wDef, window) : wHs] tb
  137. |    not (cond (WindowDefGetWindowId wDef))    = ([wH : wHs1], tb1);
  138.                                             = (wHs, DisposeWindow (WindowGetPtr window) tb);
  139.     where {
  140.         (wHs1, tb1) = CloseWindowHandle cond wHs tb;
  141.     };
  142. CloseWindowHandle cond wHs tb = (wHs, tb);
  143.  
  144.  
  145. //    Making a window the active window:
  146.  
  147. ActivateWindow :: !WindowId !(IOState s) -> IOState s;
  148. ActivateWindow id ioState
  149. |    modalDialogOpen        = ioState1;
  150.                         = ChangeWindows (ActivateWindowHandle id) ioState1;
  151.     where {
  152.         (modalDialogOpen, p, ioState1) = IOStateModalDialogActive ioState;
  153.     };
  154.  
  155. ActivateWindowHandle :: !WindowId ![WindowHandle s] !Toolbox -> (![WindowHandle s], !Toolbox);
  156. ActivateWindowHandle id wHs tb
  157. |    found    = ([wH : wHs1], SelectWindow wPtr tb);
  158.             = (wHs, tb);
  159.     where {
  160.         (wPtr, hBar, vBar, pict, updArea, zoom) = window;
  161.         (wDef, window)                            = wH;
  162.         (found, wH, wHs1) = Remove (EqualWindowHandleId id) (DummyWindowHandle 0) wHs;
  163.     };
  164.  
  165. EqualWindowHandleId :: !WindowId !(WindowHandle s) -> Bool;
  166. EqualWindowHandleId id (wDef, window) = id == WindowDefGetWindowId wDef;
  167.  
  168. //    Drawing in (active) window:
  169.  
  170. DrawInWindow :: !WindowId ![DrawFunction] !(IOState s) -> IOState s;
  171. DrawInWindow id fs ioState = ChangeWindow ((==) id) (DrawInWindowHandle fs) ioState;
  172.  
  173. DrawInActiveWindow :: ![DrawFunction] !(IOState s) -> IOState s;
  174. DrawInActiveWindow fs ioState = ChangeWindow WindowIdOK (DrawInWindowHandle fs) ioState;
  175.  
  176. DrawInWindowHandle :: ![DrawFunction] !(WindowHandle s) !Toolbox -> (!WindowHandle s, !Toolbox);
  177. DrawInWindowHandle fs (wDef, window) tb
  178.     =     ((wDef, window1), tb1);
  179.     where {
  180.         (window1, tb1) = Draw_in_window window (WindowDefGetDrawMode wDef) fs tb;
  181.     };
  182.  
  183.  
  184. /*    Enabling and Disabling of the (active) WindowKeyboard attribute:
  185. */
  186.  
  187. EnableKeyboard :: !WindowId !(IOState s) -> IOState s;
  188. EnableKeyboard id ioState
  189.     =     ChangeWindow ((==) id) (ChangeWindowDef (SetSelectKeyboard Able)) ioState;
  190.  
  191. DisableKeyboard :: !WindowId !(IOState s) -> IOState s;
  192. DisableKeyboard id ioState
  193.     =     ChangeWindow ((==) id) (ChangeWindowDef (SetSelectKeyboard Unable)) ioState;
  194.  
  195. EnableActiveKeyboard :: !(IOState s) -> IOState s;
  196. EnableActiveKeyboard ioState
  197.     =     ChangeWindow WindowIdOK (ChangeWindowDef (SetSelectKeyboard Able)) ioState;
  198.  
  199. DisableActiveKeyboard :: !(IOState s) -> IOState s;
  200. DisableActiveKeyboard ioState
  201.     =     ChangeWindow WindowIdOK (ChangeWindowDef (SetSelectKeyboard Unable)) ioState;
  202.  
  203. ChangeWindowDef :: !(DeltaWindowDef s (IOState s)) !(WindowHandle s) Toolbox -> (!WindowHandle s,Toolbox);
  204. ChangeWindowDef f (wDef, window) tb = ((f wDef, window), tb);
  205.  
  206. SetSelectKeyboard :: !SelectState !(WindowDef s (IOState s)) -> WindowDef s (IOState s);
  207. SetSelectKeyboard select wDef
  208.     =     WindowDefSetKeyboard select kf wDef;
  209.     where {
  210.         (ks, kf) = WindowDefGetKeyboard wDef;
  211.     };
  212.  
  213.  
  214. /*    Changing the (active) KeyboardFunction:
  215. */
  216.  
  217. ChangeKeyboardFunction :: !WindowId !(KeyboardFunction s (IOState s)) !(IOState s) -> IOState s;
  218. ChangeKeyboardFunction id f ioState
  219.     =     ChangeWindow ((==) id) (ChangeWindowDef (SetKeyboardFunction f)) ioState;
  220.  
  221. ChangeActiveKeyboardFunction :: !(KeyboardFunction s (IOState s)) !(IOState s) -> IOState s;
  222. ChangeActiveKeyboardFunction f ioState
  223.     =     ChangeWindow WindowIdOK (ChangeWindowDef (SetKeyboardFunction f)) ioState;
  224.  
  225. SetKeyboardFunction :: !(KeyboardFunction s (IOState s)) !(WindowDef s (IOState s))
  226.     ->      WindowDef s (IOState s);
  227. SetKeyboardFunction f wDef
  228.     =     WindowDefSetKeyboard ks f wDef;
  229.     where {
  230.         (ks, kf)= WindowDefGetKeyboard wDef;
  231.     };
  232.  
  233.  
  234. /*    Enabling and Disabling of the (active) WindowMouse attribute:
  235. */
  236.  
  237. EnableMouse :: !WindowId !(IOState s) -> IOState s;
  238. EnableMouse id ioState
  239.     =     ChangeWindow ((==) id) (ChangeWindowDef (SetSelectMouse Able)) ioState;
  240.  
  241. DisableMouse :: !WindowId !(IOState s) -> IOState s;
  242. DisableMouse id ioState
  243.     =     ChangeWindow ((==) id) (ChangeWindowDef (SetSelectMouse Unable)) ioState;
  244.  
  245. EnableActiveMouse :: !(IOState s) -> IOState s;
  246. EnableActiveMouse ioState
  247.     =     ChangeWindow WindowIdOK (ChangeWindowDef (SetSelectMouse Able)) ioState;
  248.  
  249. DisableActiveMouse :: !(IOState s) -> IOState s;
  250. DisableActiveMouse ioState
  251.     =     ChangeWindow WindowIdOK (ChangeWindowDef (SetSelectMouse Unable)) ioState;
  252.  
  253. SetSelectMouse :: !SelectState !(WindowDef s (IOState s)) -> WindowDef s (IOState s);
  254. SetSelectMouse select wDef
  255.     =     WindowDefSetMouse select mf wDef;
  256.     where {
  257.         (ms, mf)= WindowDefGetMouse wDef;
  258.     };
  259.  
  260.  
  261. /*    Changing the (active) MouseFunction:
  262. */
  263.  
  264. ChangeMouseFunction :: !WindowId !(MouseFunction s (IOState s)) !(IOState s) -> IOState s;
  265. ChangeMouseFunction id f ioState
  266.     =     ChangeWindow ((==) id) (ChangeWindowDef (SetMouseFunction f)) ioState;
  267.  
  268. ChangeActiveMouseFunction :: !(MouseFunction s (IOState s)) !(IOState s) -> IOState s;
  269. ChangeActiveMouseFunction f ioState
  270.     =     ChangeWindow WindowIdOK (ChangeWindowDef (SetMouseFunction f)) ioState;
  271.  
  272. SetMouseFunction :: !(MouseFunction s (IOState s)) !(WindowDef s (IOState s)) -> WindowDef s (IOState s);
  273. SetMouseFunction f wDef
  274.     =     WindowDefSetMouse ms f wDef;
  275.     where {
  276.         (ms, mf)= WindowDefGetMouse wDef;
  277.     };
  278.