home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1997-04-23 | 10.3 KB | 305 lines | [TEXT/3PRM] |
- implementation module dialogAccess;
-
-
- // Access functions on dialoghandles and the dialog device.
-
-
- import StdClass;
- import StdString, StdBool, StdInt, StdMisc;
- import dialogs, mac_types;
- import dialogDef, ioState;
-
-
- DummyPtr :== -1;
-
- DummyDialogRep :: DialogRep s (IOState s);
- DummyDialogRep = (DummyDialogH, DummyPtr);
-
- DummyDialogH :: DialogHandle s (IOState s);
- DummyDialogH = DialogH 0 "" Modal (0,0,0,0) [] [] (DialogRest Command [] 0);
-
- DialogAccessError :: String String -> .x;
- DialogAccessError f error = Error f "dialogAccess" error;
-
-
- /* When the definition of the dialog is passed to the user first the
- edit text fields must get their current value */
-
- RetrieveEditTexts :: !(!DialogRep s (IOState s), !Toolbox) -> (!DialogRep s (IOState s), !Toolbox);
- RetrieveEditTexts ((DialogH id tt md rc ps items rs, ptr), tb)
- = ((DialogH id tt md rc ps items1 rs, ptr), tb1);
- where {
- (items1,tb1) = RetrieveEditTextItems items ptr 1 tb;
- };
-
- RetrieveEditTextItems :: ![DialogItem s (IOState s)] !DialogPtr !Int !Toolbox
- -> (![DialogItem s (IOState s)], !Toolbox);
- RetrieveEditTextItems [EditText id ps wd nl text : items] dPtr nr tb
- = ([EditText id ps wd nl text` : items1],tb3);
- where {
- (items1,tb1) = RetrieveEditTextItems items dPtr (inc nr) tb;
- (it,h,rect,tb2) = GetDItem dPtr nr tb1;
- (text`,tb3) = GetIText h String256 tb2;
- };
- RetrieveEditTextItems [item=:RadioButtons id ps rc di buttons : items] dPtr nr tb
- = ([item : items1], tb1);
- where {
- (items1,tb1) = RetrieveEditTextItems items dPtr (nr+Length_new buttons) tb;
- };
- RetrieveEditTextItems [item=:CheckBoxes id ps rc boxes : items] dPtr nr tb
- = ([item : items1], tb1);
- where {
- (items1,tb1) = RetrieveEditTextItems items dPtr (nr+Length_new boxes) tb;
- };
- RetrieveEditTextItems [item=:DialogPopUp id ps ab di bs : items] dPtr nr tb
- = ([item : items1],tb1);
- where {
- (items1,tb1) = RetrieveEditTextItems items dPtr nr tb;
- };
- RetrieveEditTextItems [item=:DialogIconButton id ps pd il ab bf : items] dPtr nr tb
- = ([item : items1], tb1);
- where {
- (items1,tb1) = RetrieveEditTextItems items dPtr nr tb;
- };
- RetrieveEditTextItems [item=:Control id ps pd ab cs cl cf df : items] dPtr nr tb
- = ([item : items1], tb1);
- where {
- (items1,tb1) = RetrieveEditTextItems items dPtr nr tb;
- };
- RetrieveEditTextItems [item : items] dPtr nr tb
- = ([item : items1], tb1);
- where {
- (items1,tb1) = RetrieveEditTextItems items dPtr (inc nr) tb;
- };
- RetrieveEditTextItems items _ _ tb = (items,tb);
-
-
- // Access functions on the dialog device
-
- IOStateGetDialogs :: !(IOState s) -> (!DialogHandles s, !IOState s);
- IOStateGetDialogs ioState
- | hasDialogs = (DialogSystemState_DialogHandles dialogs, ioState2);
- = ([],ioState1);
- where {
- (hasDialogs, ioState1) = IOStateHasDevice ioState DialogDevice;
- (dialogs, ioState2) = IOStateGetDevice ioState1 DialogDevice;
- };
-
- DialogSystemState_DialogHandles :: !(DeviceSystemState s) -> DialogHandles s;
- DialogSystemState_DialogHandles (DialogSystemState dialogs) = dialogs;
- DialogSystemState_DialogHandles _
- = DialogAccessError "DialogSystemState_DialogHandles" "argument is no DeviceSystemState";
-
- IOStateSetDialogs :: !(DialogHandles s) !(IOState s) -> IOState s;
- IOStateSetDialogs dHs ioState = IOStateSetDevice ioState (DialogSystemState dHs);
-
- IOStateGetActiveDialogInfo :: !(IOState s) -> (!Bool, !DialogInfo, !IOState s);
- IOStateGetActiveDialogInfo ioState
- | found = (found, DialogHandleToDialogInfo dH, IOStateSetToolbox tb1 ioState2);
- with {
- (tb, ioState2) = IOStateGetToolbox ioState1;
- (dRep1, tb1) = RetrieveEditTexts (dRep,tb);
- (dH,_) = dRep1;
- };
- = (found, DialogHandleToDialogInfo dH, ioState1);
- with {
- (dH,_) = dRep;
- };
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (found, dRep) = GetActiveDialog dHs;
- };
-
- GetActiveDialog :: !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s));
- GetActiveDialog [dRep : _] = (True , dRep);
- GetActiveDialog _ = (False, DummyDialogRep);
-
- IOStateRemoveActiveDialog :: !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
- IOStateRemoveActiveDialog ioState
- = (found, dRep, IOStateSetDialogs dHs1 ioState1);
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (found,dRep,dHs1) = RemoveActiveDialog dHs;
- };
-
- RemoveActiveDialog :: !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s), !DialogHandles s);
- RemoveActiveDialog [dRep : dReps] = (True, dRep, dReps);
- RemoveActiveDialog dReps = (False, DummyDialogRep, dReps);
-
- IOStateRemoveActiveDialogPtr :: !DialogPtr !(IOState s)
- -> (!Bool,!DialogRep s (IOState s),!IOState s);
- IOStateRemoveActiveDialogPtr dptr ioState
- = (found, dRep, IOStateSetDialogs dHs1 ioState1);
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (found,dRep,dHs1) = RemoveActiveDialogPtr dptr dHs;
- };
-
- RemoveActiveDialogPtr :: !DialogPtr !(DialogHandles s)
- -> (!Bool, !DialogRep s (IOState s), !DialogHandles s);
- RemoveActiveDialogPtr dptr [dRep=:(dH,ptr) : dHs]
- | dptr == ptr = (True, dRep, dHs);
- RemoveActiveDialogPtr dptr dHs = (False, DummyDialogRep, dHs);
-
- IOStateAddDialog :: !(DialogRep s (IOState s)) !(IOState s) -> IOState s;
- IOStateAddDialog dRep ioState
- = IOStateSetDialogs [dRep : dHs] ioState1;
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- };
-
- IOStateAddInactiveDialog :: !(DialogRep s (IOState s)) !(IOState s) -> IOState s;
- IOStateAddInactiveDialog dRep ioState
- = IOStateSetDialogs (AddInactiveDialog dRep dHs) ioState1;
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- };
-
- AddInactiveDialog :: !(DialogRep s (IOState s)) !(DialogHandles s) -> DialogHandles s;
- AddInactiveDialog dRep [dRep` : dHs] = [dRep`, dRep : dHs];
- AddInactiveDialog dRep _ = [dRep];
-
- IOStateGetDialog :: !DialogId !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
- IOStateGetDialog id ioState
- = (found, dRep, ioState1);
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (found, dRep) = GetDialog id dHs;
- };
-
- GetDialog :: !DialogId !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s));
- GetDialog id [dRep : dHs]
- | id == GetDialogRepId dRep = (True, dRep);
- = GetDialog id dHs;
- GetDialog _ _ = (False, DummyDialogRep);
-
- IOStateGetDialogInfo :: !DialogId !(IOState s) -> (!Bool, !DialogInfo, !IOState s);
- IOStateGetDialogInfo id ioState
- | found = (found, DialogHandleToDialogInfo dH, IOStateSetToolbox tb1 ioState2);
- with {
- (tb, ioState2) = IOStateGetToolbox ioState1;
- (dRep1, tb1) = RetrieveEditTexts (dRep,tb);
- (dH,_) = dRep1;
- };
- = (found, DialogHandleToDialogInfo dH, ioState1);
- with {
- (dH,_) = dRep;
- };
- where {
- (found, dRep, ioState1) = IOStateGetDialog id ioState;
- };
-
- IOStateGetDialogPtr :: !DialogPtr !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
- IOStateGetDialogPtr dptr ioState
- = (found, dRep, ioState1);
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (found, dRep) = GetDialogPtr dptr dHs;
- };
-
- GetDialogPtr :: !DialogPtr !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s));
- GetDialogPtr dptr [dRep=:(dH,ptr) : dHs]
- | dptr == ptr = (True, dRep);
- = GetDialogPtr dptr dHs;
- GetDialogPtr _ _ = (False, DummyDialogRep);
-
- IOStateRemoveDialog :: !DialogId !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
- IOStateRemoveDialog id ioState
- = (found, dRep, IOStateSetDialogs dHs1 ioState1);
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (found,dRep,dHs1) = RemoveDialog id dHs;
- };
-
- RemoveDialog :: !DialogId !(DialogHandles s) -> (!Bool, !DialogRep s (IOState s), !DialogHandles s);
- RemoveDialog id [dRep : dHs]
- | id == GetDialogRepId dRep = (True, dRep, dHs);
- = (found, dRep1, [dRep : dHs1]);
- where {
- (found, dRep1, dHs1) = RemoveDialog id dHs;
- };
- RemoveDialog _ _ = (False, DummyDialogRep, []);
-
- IOStateRemoveDialogPtr :: !DialogPtr !(IOState s) -> (!Bool, !DialogRep s (IOState s), !IOState s);
- IOStateRemoveDialogPtr dptr ioState
- = (found, dRep, IOStateSetDialogs dHs1 ioState1);
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (found, dRep, dHs1) = RemoveDialogPtr dptr dHs;
- };
-
- RemoveDialogPtr :: !DialogPtr !(DialogHandles s)
- -> (!Bool, !DialogRep s (IOState s), !DialogHandles s);
- RemoveDialogPtr dptr [dRep=:(dH,ptr) : dHs]
- | dptr == ptr = (True, dRep, dHs);
- = (found, dRep1, [dRep : dHs1]);
- where {
- (found, dRep1, dHs1) = RemoveDialogPtr dptr dHs;
- };
- RemoveDialogPtr _ _ = (False, DummyDialogRep, []);
-
- IOStateReplaceDialog :: !DialogId !(DialogRep s (IOState s)) !(IOState s) -> IOState s;
- IOStateReplaceDialog id dRep ioState
- = IOStateSetDialogs (ReplaceDialog id dRep dHs) ioState1;
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- };
-
- ReplaceDialog :: !DialogId !(DialogRep s (IOState s)) !(DialogHandles s) -> DialogHandles s;
- ReplaceDialog id dRep [oldRep : dHs]
- | id == GetDialogRepId oldRep = [dRep : dHs];
- = [oldRep : ReplaceDialog id dRep dHs];
- ReplaceDialog _ _ _
- = DialogAccessError "ReplaceDialog" "Unknown dialog id";
-
- IOStateSetDialogInFront :: !DialogId !(IOState s) -> (!Bool, !IOState s);
- IOStateSetDialogInFront id ioState
- = (found, IOStateSetDialogs dHs1 ioState1);
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (found, dHs1) = SetDialogInFront id dHs;
- };
-
- SetDialogInFront :: !DialogId !(DialogHandles s) -> (!Bool, !DialogHandles s);
- SetDialogInFront id dHs
- | not found || ptr == DummyPtr = (False, dHs);
- = (True, [dRep : dHs1]);
- where {
- (found,dRep,dHs1) = RemoveDialog id dHs;
- (_,ptr) = dRep;
- };
-
- IOStateModalDialogActive :: !(IOState s) -> (!Bool,!DialogPtr,!IOState s);
- IOStateModalDialogActive ioState
- = (found, dptr, ioState1);
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (found, dptr) = ModalDialogActive False (-1) dHs;
- };
-
- ModalDialogActive :: !Bool !DialogPtr !(DialogHandles s) -> (!Bool, !DialogPtr);
- ModalDialogActive found behind [dRep : dHs]
- | isModal = ModalDialogActive isModal dptr dHs;
- where {
- (isModal,dptr) = IsModalDialog dRep;
- };
- ModalDialogActive found behind _ = (found,behind);
-
- IsModalDialog :: !(DialogRep s (IOState s)) -> (!Bool, !DialogPtr);
- IsModalDialog (DialogH _ _ Modal _ _ _ _, dptr)
- | dptr <> DummyPtr = (True, dptr);
- IsModalDialog _ = (False, -1);
-
-
- // Miscellaneous functions.
-
- GetDialogRepId :: !(DialogRep s (IOState s)) -> DialogId;
- GetDialogRepId (DialogH id _ _ _ _ _ _, _) = id;
-
- String256 :: String;
- String256
- = string128 +++ string128;
- where {
- string128 = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
- };
-