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

  1. implementation module dialogAccess;
  2.  
  3.  
  4. //    Access functions on dialoghandles and the dialog device.
  5.  
  6.  
  7. import StdClass;
  8. import    StdString, StdBool, StdInt, StdMisc;
  9. import    dialogs, mac_types;
  10. import    dialogDef, ioState;
  11.  
  12.  
  13. DummyPtr            :== -1;
  14.  
  15. DummyDialogRep        :: DialogRep s (IOState s);
  16. DummyDialogRep        = (DummyDialogH, DummyPtr);
  17.  
  18. DummyDialogH        :: DialogHandle s (IOState s);
  19. DummyDialogH        = DialogH 0 "" Modal (0,0,0,0) [] [] (DialogRest Command [] 0);
  20.  
  21. DialogAccessError    :: String String -> .x;
  22. DialogAccessError    f error = Error f "dialogAccess" error;
  23.  
  24.  
  25. /*    When the definition of the dialog is passed to the user first the
  26.     edit text fields must get their current value */
  27.  
  28. RetrieveEditTexts :: !(!DialogRep s (IOState s), !Toolbox) -> (!DialogRep s (IOState s), !Toolbox);
  29. RetrieveEditTexts ((DialogH id tt md rc ps items rs, ptr), tb)
  30.     =    ((DialogH id tt md rc ps items1 rs, ptr), tb1);
  31.     where {
  32.         (items1,tb1) = RetrieveEditTextItems items ptr 1 tb;
  33.     };
  34.     
  35. RetrieveEditTextItems :: ![DialogItem s (IOState s)] !DialogPtr !Int !Toolbox
  36.     ->    (![DialogItem s (IOState s)], !Toolbox);
  37. RetrieveEditTextItems [EditText id ps wd nl text : items] dPtr nr tb
  38.     =    ([EditText id ps wd nl text` : items1],tb3);
  39.     where {
  40.         (items1,tb1)    = RetrieveEditTextItems items dPtr (inc nr) tb;
  41.         (it,h,rect,tb2)    = GetDItem dPtr nr tb1;
  42.         (text`,tb3)        = GetIText h String256 tb2;
  43.     };
  44. RetrieveEditTextItems [item=:RadioButtons id ps rc di buttons : items] dPtr nr tb
  45.     =    ([item : items1], tb1);
  46.     where {
  47.         (items1,tb1) = RetrieveEditTextItems items dPtr (nr+Length_new buttons) tb;
  48.     };
  49. RetrieveEditTextItems [item=:CheckBoxes id ps rc boxes : items] dPtr nr tb
  50.     =    ([item : items1], tb1);
  51.     where {
  52.         (items1,tb1) = RetrieveEditTextItems items dPtr (nr+Length_new boxes) tb;
  53.     };
  54. RetrieveEditTextItems [item=:DialogPopUp id ps ab di bs : items] dPtr nr tb
  55.     =    ([item : items1],tb1);
  56.     where {
  57.         (items1,tb1) = RetrieveEditTextItems items dPtr nr tb;
  58.     };
  59. RetrieveEditTextItems [item=:DialogIconButton id ps pd il ab bf : items] dPtr nr tb
  60.     =    ([item : items1], tb1);
  61.     where {
  62.         (items1,tb1) = RetrieveEditTextItems items dPtr nr tb;
  63.     };
  64. RetrieveEditTextItems [item=:Control id ps pd ab cs cl cf df : items] dPtr nr tb
  65.     =    ([item : items1], tb1);
  66.     where {
  67.         (items1,tb1) = RetrieveEditTextItems items dPtr nr tb;
  68.     };
  69. RetrieveEditTextItems [item : items] dPtr nr tb
  70.     =    ([item : items1], tb1);
  71.     where {
  72.         (items1,tb1) = RetrieveEditTextItems items dPtr (inc nr) tb;
  73.     };
  74. RetrieveEditTextItems items _ _ tb = (items,tb);
  75.  
  76.  
  77. //    Access functions on the dialog device
  78.  
  79. IOStateGetDialogs :: !(IOState s) -> (!DialogHandles s, !IOState s);
  80. IOStateGetDialogs ioState
  81. |    hasDialogs    = (DialogSystemState_DialogHandles dialogs, ioState2);
  82.                 = ([],ioState1);
  83.     where {
  84.         (hasDialogs, ioState1) = IOStateHasDevice ioState  DialogDevice;
  85.         (dialogs,     ioState2) = IOStateGetDevice ioState1 DialogDevice;
  86.     };
  87.  
  88. DialogSystemState_DialogHandles    :: !(DeviceSystemState s) -> DialogHandles s;
  89. DialogSystemState_DialogHandles (DialogSystemState dialogs) = dialogs;
  90. DialogSystemState_DialogHandles _
  91.     =     DialogAccessError "DialogSystemState_DialogHandles" "argument is no DeviceSystemState";
  92.  
  93. IOStateSetDialogs :: !(DialogHandles s) !(IOState s) -> IOState s;
  94. IOStateSetDialogs dHs ioState = IOStateSetDevice ioState (DialogSystemState dHs);
  95.  
  96. IOStateGetActiveDialogInfo :: !(IOState s) -> (!Bool, !DialogInfo, !IOState s);
  97. IOStateGetActiveDialogInfo ioState
  98. |    found    =    (found, DialogHandleToDialogInfo dH, IOStateSetToolbox tb1 ioState2);
  99.             with {
  100.                 (tb,  ioState2)    = IOStateGetToolbox ioState1;
  101.                 (dRep1, tb1)    = RetrieveEditTexts (dRep,tb);
  102.                 (dH,_)            = dRep1;
  103.             };
  104.             =    (found, DialogHandleToDialogInfo dH, ioState1);
  105.             with {
  106.                 (dH,_)            = dRep;
  107.             };
  108.     where {
  109.         (dHs, ioState1)    = IOStateGetDialogs ioState;
  110.         (found, dRep)    = GetActiveDialog dHs;
  111.     };
  112.  
  113. GetActiveDialog :: !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s));
  114. GetActiveDialog [dRep : _]    = (True , dRep);
  115. GetActiveDialog _            = (False, DummyDialogRep);
  116.  
  117. IOStateRemoveActiveDialog :: !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
  118. IOStateRemoveActiveDialog ioState
  119.     =    (found, dRep, IOStateSetDialogs dHs1 ioState1);
  120.     where {
  121.         (dHs, ioState1)        = IOStateGetDialogs ioState;
  122.         (found,dRep,dHs1)    = RemoveActiveDialog dHs;
  123.     };
  124.  
  125. RemoveActiveDialog :: !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s), !DialogHandles s);
  126. RemoveActiveDialog [dRep : dReps]    = (True, dRep, dReps);
  127. RemoveActiveDialog dReps            = (False, DummyDialogRep, dReps);
  128.  
  129. IOStateRemoveActiveDialogPtr :: !DialogPtr !(IOState s)
  130.     ->    (!Bool,!DialogRep s (IOState s),!IOState s);
  131. IOStateRemoveActiveDialogPtr dptr ioState
  132.     =    (found, dRep, IOStateSetDialogs dHs1 ioState1);
  133.     where {
  134.         (dHs, ioState1)        = IOStateGetDialogs ioState;
  135.         (found,dRep,dHs1)    = RemoveActiveDialogPtr dptr dHs;
  136.     };
  137.  
  138. RemoveActiveDialogPtr :: !DialogPtr !(DialogHandles s)
  139.     ->    (!Bool, !DialogRep s (IOState s), !DialogHandles s);
  140. RemoveActiveDialogPtr dptr [dRep=:(dH,ptr) : dHs]
  141. |    dptr == ptr                    = (True,  dRep,              dHs);
  142. RemoveActiveDialogPtr dptr dHs    = (False, DummyDialogRep, dHs);
  143.  
  144. IOStateAddDialog :: !(DialogRep s (IOState s)) !(IOState s) -> IOState s;
  145. IOStateAddDialog dRep ioState
  146.     =    IOStateSetDialogs [dRep : dHs] ioState1;
  147.     where {
  148.         (dHs, ioState1) = IOStateGetDialogs ioState;
  149.     };
  150.  
  151. IOStateAddInactiveDialog :: !(DialogRep s (IOState s)) !(IOState s) -> IOState s;
  152. IOStateAddInactiveDialog dRep ioState
  153.     =    IOStateSetDialogs (AddInactiveDialog dRep dHs) ioState1;
  154.     where {
  155.         (dHs, ioState1) = IOStateGetDialogs ioState;
  156.     };
  157.  
  158. AddInactiveDialog :: !(DialogRep s (IOState s)) !(DialogHandles s) -> DialogHandles s;
  159. AddInactiveDialog dRep [dRep` : dHs]    = [dRep`, dRep : dHs];
  160. AddInactiveDialog dRep _                = [dRep];
  161.  
  162. IOStateGetDialog :: !DialogId !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
  163. IOStateGetDialog id ioState
  164.     =    (found, dRep, ioState1);
  165.     where {
  166.         (dHs, ioState1)    = IOStateGetDialogs ioState;
  167.         (found, dRep)    = GetDialog id dHs;
  168.     };
  169.  
  170. GetDialog :: !DialogId !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s));
  171. GetDialog id [dRep : dHs]
  172. |    id ==  GetDialogRepId dRep    = (True, dRep);
  173.                                 = GetDialog id dHs;
  174. GetDialog _ _                    = (False, DummyDialogRep);
  175.  
  176. IOStateGetDialogInfo :: !DialogId !(IOState s) -> (!Bool, !DialogInfo, !IOState s);
  177. IOStateGetDialogInfo id ioState
  178. |    found    =    (found, DialogHandleToDialogInfo dH, IOStateSetToolbox tb1 ioState2);
  179.             with {
  180.                 (tb, ioState2)    = IOStateGetToolbox ioState1;
  181.                 (dRep1, tb1)    = RetrieveEditTexts (dRep,tb);
  182.                 (dH,_)            = dRep1;
  183.             };
  184.             =    (found, DialogHandleToDialogInfo dH, ioState1);
  185.             with {
  186.                 (dH,_)            = dRep;
  187.             };
  188.     where {
  189.         (found, dRep, ioState1)    = IOStateGetDialog id ioState;
  190.     };
  191.  
  192. IOStateGetDialogPtr :: !DialogPtr !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
  193. IOStateGetDialogPtr dptr ioState
  194.     =    (found, dRep, ioState1);
  195.     where {
  196.         (dHs, ioState1)    = IOStateGetDialogs ioState;
  197.         (found, dRep)    = GetDialogPtr dptr dHs;
  198.     };
  199.  
  200. GetDialogPtr :: !DialogPtr !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s));
  201. GetDialogPtr dptr [dRep=:(dH,ptr) : dHs]
  202. |    dptr == ptr        = (True, dRep);
  203.                     = GetDialogPtr dptr dHs;
  204. GetDialogPtr _ _    = (False, DummyDialogRep);
  205.  
  206. IOStateRemoveDialog :: !DialogId !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
  207. IOStateRemoveDialog id ioState
  208.     =    (found, dRep, IOStateSetDialogs dHs1 ioState1);
  209.     where {
  210.         (dHs, ioState1)        = IOStateGetDialogs ioState;
  211.         (found,dRep,dHs1)    = RemoveDialog id dHs;
  212.     };
  213.  
  214. RemoveDialog :: !DialogId !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s), !DialogHandles s);
  215. RemoveDialog id [dRep : dHs]
  216. |    id == GetDialogRepId dRep    = (True,  dRep,  dHs);
  217.                                 = (found, dRep1, [dRep : dHs1]);
  218.     where {
  219.         (found, dRep1, dHs1) = RemoveDialog id dHs;
  220.     };
  221. RemoveDialog _ _ = (False, DummyDialogRep, []);
  222.  
  223. IOStateRemoveDialogPtr :: !DialogPtr !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
  224. IOStateRemoveDialogPtr dptr ioState
  225.     =    (found, dRep, IOStateSetDialogs dHs1 ioState1);
  226.     where {
  227.         (dHs, ioState1)        = IOStateGetDialogs ioState;
  228.         (found, dRep, dHs1)    = RemoveDialogPtr dptr dHs;
  229.     };
  230.  
  231. RemoveDialogPtr :: !DialogPtr !(DialogHandles s)
  232.     ->    (!Bool, !DialogRep s (IOState s), !DialogHandles s);
  233. RemoveDialogPtr dptr [dRep=:(dH,ptr) : dHs]
  234. |    dptr == ptr    = (True,  dRep,  dHs);
  235.                 = (found, dRep1, [dRep : dHs1]);
  236.     where {
  237.         (found, dRep1, dHs1) = RemoveDialogPtr dptr dHs;
  238.     };
  239. RemoveDialogPtr _ _ = (False, DummyDialogRep, []);
  240.  
  241. IOStateReplaceDialog :: !DialogId !(DialogRep s (IOState s)) !(IOState s) -> IOState s;
  242. IOStateReplaceDialog id dRep ioState
  243.     =    IOStateSetDialogs (ReplaceDialog id dRep dHs) ioState1;
  244.     where {
  245.         (dHs, ioState1) = IOStateGetDialogs ioState;
  246.     };
  247.  
  248. ReplaceDialog :: !DialogId !(DialogRep s (IOState s)) !(DialogHandles s) -> DialogHandles s;
  249. ReplaceDialog id dRep [oldRep : dHs]
  250. |    id == GetDialogRepId oldRep    =  [dRep   : dHs];
  251.                                 =  [oldRep : ReplaceDialog id dRep dHs];
  252. ReplaceDialog _ _ _
  253.     =    DialogAccessError "ReplaceDialog" "Unknown dialog id";
  254.  
  255. IOStateSetDialogInFront :: !DialogId !(IOState s) -> (!Bool, !IOState s);
  256. IOStateSetDialogInFront id ioState
  257.     =    (found, IOStateSetDialogs dHs1 ioState1);
  258.     where {
  259.         (dHs, ioState1)    = IOStateGetDialogs ioState;
  260.         (found, dHs1)    = SetDialogInFront id dHs;
  261.     };
  262.  
  263. SetDialogInFront :: !DialogId !(DialogHandles s) -> (!Bool, !DialogHandles s);
  264. SetDialogInFront id dHs
  265. |    not found || ptr == DummyPtr    = (False, dHs);
  266.                                     = (True, [dRep : dHs1]);
  267.     where {
  268.         (found,dRep,dHs1)    = RemoveDialog id dHs;
  269.         (_,ptr)                = dRep;
  270.     };
  271.  
  272. IOStateModalDialogActive :: !(IOState s) -> (!Bool,!DialogPtr,!IOState s);
  273. IOStateModalDialogActive ioState
  274.     =    (found, dptr, ioState1);
  275.     where {
  276.         (dHs, ioState1)    = IOStateGetDialogs ioState;
  277.         (found, dptr)    = ModalDialogActive False (-1) dHs;
  278.     };
  279.  
  280. ModalDialogActive :: !Bool !DialogPtr !(DialogHandles s) -> (!Bool, !DialogPtr);
  281. ModalDialogActive found behind [dRep : dHs]
  282. |    isModal    = ModalDialogActive isModal dptr dHs;
  283.     where {
  284.         (isModal,dptr) = IsModalDialog dRep;
  285.     };
  286. ModalDialogActive found behind _ = (found,behind);
  287.  
  288. IsModalDialog :: !(DialogRep s (IOState s)) -> (!Bool, !DialogPtr);
  289. IsModalDialog (DialogH _ _ Modal _ _ _ _, dptr)
  290. |    dptr <> DummyPtr    = (True, dptr);
  291. IsModalDialog _            = (False, -1);
  292.  
  293.  
  294. //    Miscellaneous functions.
  295.  
  296. GetDialogRepId :: !(DialogRep s (IOState s)) -> DialogId;
  297. GetDialogRepId (DialogH id _ _ _ _ _ _, _) = id;
  298.  
  299. String256 :: String;
  300. String256
  301.     =    string128 +++ string128;
  302.     where {
  303.         string128 = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
  304.     };
  305.