home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1997-04-23 | 27.2 KB | 663 lines | [TEXT/3PRM] |
- implementation module dialogDevice;
-
- import StdClass,StdBool, StdInt, StdString, StdChar;
- import OS_utilities, quickdraw, menus, events, windows, dialogs;
- import dialogAccess, dialogInternal, dialogAbout, ioState;
- from deltaTimer import UWait;
- from deltaMenu import DisableMenuSystem, EnableMenuSystem;
- from windowDevice import WindowFunctions, IOStateSetCursorShape, IOStateGetGlobalCursor;
- from menuDevice import MenuFunctions;
- from timerDevice import TimerFunctions;
- from dialogUpdate import UpdateDialog;
-
- :: EventRecord :== (!Int,!Int,!Int,!Int,!Int,!Int);
- :: IOFunction *s :== Event -> s -> *((IOState s) -> (Bool,s,IOState s));
-
- DummyPtr :== -1;
-
- //DummyItem :: DialogItem s io;
- DummyItem :== StaticText 0 Left "";
-
- DialogDeviceError :: String String -> .x;
- DialogDeviceError f error = Error f "dialogDevice" error;
-
-
- DialogFunctions :: DeviceFunctions s;
- DialogFunctions = ( ChangeDialogs ShowWindow,
- DialogOpen,
- DialogIO,
- DialogClose,
- ChangeDialogs HideWindow );
-
-
- ChangeDialogs :: !(!DialogPtr -> !Toolbox -> !Toolbox) !(IOState s) -> IOState s;
- ChangeDialogs f ioState
- = IOStateChangeToolbox (ChangeDialogs` f dHs) ioState1;
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- };
-
- ChangeDialogs` :: !(!DialogPtr -> !Toolbox -> !Toolbox) !(DialogHandles s) !Toolbox -> Toolbox;
- ChangeDialogs` f [dR : dRs] tb
- | id < 0 = tb1;
- = f ptr tb1;
- where {
- id = DialogHandleGetId dH;
- (dH, ptr) = dR;
- tb1 = ChangeDialogs` f dRs tb;
- };
- ChangeDialogs` _ _ tb = tb;
-
- DialogHandleGetId :: !(DialogHandle s io) -> DialogId;
- DialogHandleGetId (DialogH id _ _ _ _ _ _) = id;
-
- // Open all modeless dialogs in the DeviceSystem parameter.
-
- DialogOpen :: !(DeviceSystem s (IOState s)) !(IOState s) -> IOState s;
- DialogOpen (DialogSystem dHs) ioState
- = IOStateSetDialogs (Concat dHs1 aboutHs) (IOStateSetToolbox tb1 ioState1);
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- (aboutHs,dHs1,tb1) = OpenModelessDialogs [] [] dHs tb;
- };
- DialogOpen _ _
- = DialogDeviceError "DialogOpen" "argument is no DialogSystem";
-
- OpenModelessDialogs :: ![DialogId] !(DialogHandles s) ![DialogDef s (IOState s)] !Toolbox
- -> (!DialogHandles s, !DialogHandles s, !Toolbox);
- OpenModelessDialogs ids aboutHs [aboutDef=:AboutDialog an pd fs ah : dDefs] tb
- | IsEmptyList aboutHs
- = OpenModelessDialogs ids [(AboutDialogToDialogHandle aboutDef,DummyPtr)] dDefs tb;
- = OpenModelessDialogs ids aboutHs dDefs tb;
- OpenModelessDialogs ids aboutHs [dDef : dDefs] tb
- | ContainsInt ids id = OpenModelessDialogs ids aboutHs dDefs tb;
- = (aboutHs1, [dH : dHs1], tb2);
- where {
- (aboutHs1, dHs1, tb2) = OpenModelessDialogs [id : ids] aboutHs dDefs tb1;
- id = GetDialogDefId dDef;
- (dH, tb1) = OpenAnyDialog Modeless (-1) dDef tb;
- };
- OpenModelessDialogs _ aboutHs dDefs tb = (aboutHs, [], tb);
-
-
- // Close all open dialogs and remove the dialog device.
-
- DialogClose :: !(IOState s) -> IOState s;
- DialogClose ioState
- = IOStateRemoveDevice (IOStateSetToolbox (CloseDialogs dHs tb) ioState2) DialogDevice;
- where {
- (dHs,ioState1) = IOStateGetDialogs ioState;
- (tb, ioState2) = IOStateGetToolbox ioState1;
- };
-
- CloseDialogs :: !(DialogHandles *s) !Toolbox -> Toolbox;
- CloseDialogs [(_, dPtr) : dHs] tb
- | dPtr == DummyPtr = tb1;
- = DisposDialog dPtr tb1;
- where {
- tb1 = CloseDialogs dHs tb;
- };
- CloseDialogs _ tb = tb;
-
-
- // Event handling for dialogs.
-
- DialogIO :: !Event !*s !(IOState *s) -> (!Bool, !*s, !IOState *s);
- DialogIO event=:(b,wt,ma,wn,h,v,ms) s io
- | not isDialogEvent = HandleSpecialDialogEvent event s io0;
- | return_or_enter_still = (True,s, io0);
- | return_or_enter = (True,s1,io2);
- | command_period = (True,s2,io3);
- | mine = (True,s3,io4);
- = (True,s4,io5);
- where {
- eventrec = (wt,ma,wn,h,v,ms);
- (isDialogEvent,io0) = IOStateAccessToolbox (IsDialogEvent eventrec) io;
- (dSelect,io1) = IOStateAccessToolbox (GetDialogSelect eventrec) io0;
- (found,active,iowa) = IOStateRemoveActiveDialog io0;
- (s1,io2) = PressDefaultButton` found active s iowa;
- (s2,io3) = PressCancelButton` found active s iowa;
- (s3,io4) = HandleEvent drep itnr s iowd;
- (s4,io5) = HandleSpecialItemEvent eventrec s io1;
- (drep,iowd) = IOStateRemoveDialogOrAbort ptr io1;
- (mine,ptr,itnr) = dSelect;
- (return_or_enter, return_or_enter_still, command_period) = KeyEventInfo eventrec;
-
- PressDefaultButton` b active s io
- | b = PressDefaultButton active s io;
- = (s,io);
- PressCancelButton` b active s io
- | b = PressCancelButton active s io;
- = (s,io);
- };
-
- GetDialogSelect :: !EventRecord !Toolbox -> (!(!Bool,!DialogPtr,!Int),!Toolbox);
- GetDialogSelect eventrec tb
- = ((mine,ptr,itNr), tb1);
- where {
- (mine,ptr,itNr,tb1) = DialogSelect eventrec tb;
- };
-
- IOStateRemoveDialogOrAbort :: !DialogPtr !(IOState s) -> (!DialogRep s (IOState s), !IOState s);
- IOStateRemoveDialogOrAbort ptr ioState
- | found = (dRep, ioState1);
- = DialogDeviceError "DialogIO" "Dialog not present in IOState";
- where {
- (found,dRep,ioState1) = IOStateRemoveDialogPtr ptr ioState;
- };
-
- DoModalDialog :: !(DialogDef *s (IOState *s)) !*s !(IOState *s) -> (!*s, !IOState *s);
- DoModalDialog dDef=:(CommandDialog id _ _ _ _) s ioState
- | open = (s, IOStateChangeToolbox (ActivateDialog dHs) ioState1);
- = ModalIO menuIO timerIO windowIO mask dptr s (DisableMenuSystem (IOStateSetCursorShape cShape ioState3));
- where {
- (open, ioState`) = IOStateSetDialogInFront id ioState;
- (dHs, ioState1) = IOStateGetDialogs ioState`;
- (dRep, ioState2) = IOStateAccessToolbox (OpenAnyDialog Modal (-1) dDef) ioState`;
- (_, dptr) = dRep;
- (cShape,ioState3) = IOStateGetGlobalCursor (IOStateAddDialog dRep ioState2);
- (_,_,menuIO, _,_) = MenuFunctions;
- (_,_,timerIO,_,_) = TimerFunctions;
- (_,_,windowIO,_,_) = WindowFunctions;
- mask = UpdateMask bitor
- (ActivMask bitor
- (KeyboardMask bitor
- (MouseMask bitor 1)));
- };
- DoModalDialog dDef s ioState
- | id == AboutDialogID = (s, ioState);
- | open = (s, IOStateChangeToolbox (ActivateDialog dHs) ioState2);
- = (s, ioState1);
- where {
- id = GetDialogDefId dDef;
- (open,ioState1) = IOStateSetDialogInFront id ioState;
- (dHs, ioState2) = IOStateGetDialogs ioState1;
- };
-
- ModalIO :: !(IOFunction *s) !(IOFunction *s) !(IOFunction *s) !Int !DialogPtr !*s !(IOState *s) -> (!*s, !IOState *s);
- ModalIO menuIO timerIO windowIO mask thisPtr s ioState
- | quitted1 = (s, ioState1);
- | quitted2 = (s1, ioState4);
- | active = ModalIO menuIO timerIO windowIO mask thisPtr s2 ioState5;
- | other = (s2, ioState5);
- | quitted3 = (s2, ioState6);
- = (s4, EnableMenuSystem ioState8);
- where {
- (quitted1, ioState1) = IOStateClosed ioState;
- (event, ioState2) = IOStateAccessToolbox (GetEvent mask) ioState1;
- (_, s1, ioState3) = timerIO event s ioState2;
- (quitted2, ioState4) = IOStateClosed ioState3;
- (active,other,s2, ioState5) = HandleModalEvent menuIO windowIO thisPtr event s1 ioState4;
- (quitted3, ioState6) = IOStateClosed ioState5;
- (_,s3, ioState7) = menuIO event s2 ioState6;
- (_,s4, ioState8) = windowIO event s3 ioState7;
- };
-
- HandleModalEvent :: !(IOFunction *s) !(IOFunction *s) !DialogPtr !Event !*s !(IOState *s) -> (!Bool,!Bool,!*s,!IOState *s);
- HandleModalEvent menuIO windowIO thisPtr event=:(b,wt,ma,wn,h,v,ms) s io
- | not found = (False,False,s, io0);
- | not modalActive = (False,False,s, ioa);
- | other = (False,other,s, ioa);
- | noDialogEvent && mouseDown && region==InMenuBar = (True, other,sm,iom);
- | noDialogEvent && mouseDown = (True, other,s, iob);
- | noDialogEvent && (wt==ActivateEvent || wt==UpdateEvent) = (True, other,sw,iow);
- | noDialogEvent || returnOrEnterStill = (True, other,s, ioa);
- | returnOrEnter = (True, other,s1,io1);
- | commandPeriod = (True, other,s2,io2);
- | mine && mPtr <> ptr` = (True, other,s, IOStateAddDialog active iowa`);
- | mine = (True, other,s3,io3);
- = (True, other,s4,io4);
- where {
- (found,active,io0) = IOStateRemoveActiveDialog io;
- (modalActive,mPtr) = IsModalDialog active;
- other = thisPtr <> mPtr;
- eventrec = (wt,ma,wn,h,v,ms);
- (eventInfo, iowa) = IOStateAccessToolbox (GetEventInfo eventrec) io0;
- (dialogEvent,region)= eventInfo;
- noDialogEvent = not dialogEvent;
- (eventInfo2, iowa`) = IOStateAccessToolbox (GetDialogSelect eventrec) iowa;
- (mine, ptr`, itnr) = eventInfo2;
- ioa = IOStateAddDialog active iowa;
- iob = IOStateChangeToolbox (SysBeep 1) ioa;
- (b,sm,iom) = menuIO event s ioa;
- (_,sw,iow) = windowIO event s ioa;
- (s1,io1) = PressDefaultButton active s iowa;
- (s2,io2) = PressCancelButton active s iowa;
- (s3,io3) = HandleEvent active itnr s iowa`;
- (s4,io4) = HandleSpecialItemEvent eventrec s (IOStateAddDialog active iowa`);
- mouseDown = wt == MouseDownEvent;
- (returnOrEnter, returnOrEnterStill, commandPeriod) = KeyEventInfo eventrec;
- };
-
- GetEventInfo :: !EventRecord !Toolbox -> (!(!Bool,!Int), !Toolbox);
- GetEventInfo eventrec=:(_,_,_,h,v,_) tb
- = ((dialogEvent,region), tb2);
- where {
- (dialogEvent, tb1) = IsDialogEvent eventrec tb;
- (region, _, tb2) = FindWindow h v tb1;
- };
-
- KeyEventInfo :: !EventRecord -> (!Bool, !Bool, !Bool);
- KeyEventInfo (what,message,when,h,v,mods)
- | what == KeyDownEvent = (return_or_enter, False, command_period);
- | what == AutoKeyEvent = (False, return_or_enter, False);
- = (False, False, False);
- where {
- return_or_enter = ('\015' == key || '\003' == key) && ms + cmd == 0;
- command_period = '.' == key && (ms == 0 && cmd <> 0);
- ms = (mods bitand 512) + ((mods bitand 2048) + (mods bitand 4096));
- cmd = mods bitand 256;
- key = toChar (message bitand 255);
- };
-
- PressDefaultButton :: !(DialogRep *s (IOState *s)) !*s !(IOState *s) -> (!*s, !IOState *s);
- PressDefaultButton dRep=:(dH=:DialogH _ _ _ _ _ items (DialogRest _ _ defid),ptr) s ioState
- | not found = (s, IOStateAddDialog dRep ioState);
- = buttonF (DialogHandleToDialogInfo dH1) s (IOStateAddDialog dRep1 ioState2);
- where {
- (found,isIcon,rect,buttonF) = GetDialogButtonInfo defid items;
- (tb, ioState1) = IOStateGetToolbox ioState;
- tb1 = HiliteDefaultButton isIcon rect ptr tb;
- (dRep1, tb2) = RetrieveEditTexts (dRep,tb1);
- ioState2 = IOStateSetToolbox tb2 ioState1;
- (dH1,_) = dRep1;
- };
-
- PressCancelButton :: !(DialogRep *s (IOState *s)) !*s !(IOState *s) -> (!*s, !IOState *s);
- PressCancelButton dRep=:(dH=:DialogH _ _ _ _ _ items _,ptr) s ioState
- | not found = (s, IOStateAddDialog dRep ioState);
- = buttonF (DialogHandleToDialogInfo dH1) s (IOStateAddDialog dRep1 ioState2);
- where {
- (found, rect, buttonF) = GetCancelButtonInfo items;
- (tb, ioState1) = IOStateGetToolbox ioState;
- tb1 = HiliteDefaultButton False rect ptr tb;
- (dRep1,tb2) = RetrieveEditTexts (dRep,tb1);
- ioState2 = IOStateSetToolbox tb2 ioState1;
- (dH1,_) = dRep1;
- };
-
- HandleSpecialDialogEvent :: !Event !*s !(IOState *s) -> (!Bool, !*s, !IOState *s);
- HandleSpecialDialogEvent event=:(b,MouseDownEvent,ma,wn,h,v,ms) s ioState
- | NoDialogs dHs = (False, s,ioState1);
- | not mine = (False, s,ioState3);
- | region == InContent = ActivateTheDialog dRep event s ioState4;
- | region == InDrag = (True, s,DragTheDialog h v dRep ioState4);
- | region == InGoAway = (closed,s,ioState5);
- = (False, s,ioState3);
- where {
- (dHs, ioState1) = IOStateGetDialogs ioState;
- (tb, ioState2) = IOStateGetToolbox ioState1;
- (region, ptr, tb1) = FindWindow h v tb;
- ioState3 = IOStateSetToolbox tb1 ioState2;
- (mine, dRep, dHs1) = RemoveDialogPtr ptr dHs;
- ioState4 = IOStateSetDialogs dHs1 ioState3;
- (closed, ioState5) = CloseTheDialog h v dRep ioState4;
- };
- HandleSpecialDialogEvent _ s io = (False,s,io);
-
- NoDialogs :: !(DialogHandles s) -> Bool;
- NoDialogs [] = True;
- NoDialogs [(dH,ptr) : _] = (DialogHandleGetId dH) <= 0 && ptr == DummyPtr;
-
- ActivateTheDialog :: !(DialogRep *s (IOState *s)) !Event !*s !(IOState *s) -> (!Bool,!*s,!IOState *s);
- ActivateTheDialog dRep=:(dH,ptr) event s ioState
- | DialogIsStandBy dH
- = DialogIO event s (IOStateSetToolbox tb1 ioState2);
- = (True, s, IOStateSetToolbox (RemoveMouseUp tb1) ioState2);
- where {
- ioState1 = IOStateAddDialog dRep ioState;
- (tb, ioState2) = IOStateGetToolbox ioState1;
- tb1 = SelectWindow ptr tb;
- };
-
-
- DialogIsStandBy :: !(DialogHandle s (IOState s)) -> Bool;
- DialogIsStandBy (DialogH _ _ _ _ _ _ (DialogRest _ attrs _)) = ContainsStandByAttribute attrs;
-
- ContainsStandByAttribute :: [DialogAttribute] -> Bool;
- ContainsStandByAttribute [StandByDialog : _] = True;
- ContainsStandByAttribute [_ : rest] = ContainsStandByAttribute rest;
- ContainsStandByAttribute _ = False;
-
- RemoveMouseUp :: !Toolbox -> Toolbox;
- RemoveMouseUp tb
- | notUpYet = RemoveMouseUp tb1;
- = tb1;
- where {
- (notUpYet,tb1) = WaitMouseUp tb
- };
-
- DragTheDialog :: !Int !Int !(DialogRep s (IOState s)) !(IOState s) -> IOState s;
- DragTheDialog h v dRep=:(dH,ptr) ioState
- = IOStateAddDialog dRep (IOStateSetToolbox tb2 ioState1);
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- (sl,st,sr,sb,tb1) = QScreenRect tb;
- tb2 = DragWindow ptr h v (sl,st,dec sr,dec sb) tb1;
- };
-
- CloseTheDialog :: !Int !Int !(DialogRep s (IOState s)) !(IOState s) -> (!Bool,!IOState s);
- CloseTheDialog h v dRep=:(_,ptr) ioState
- | goAway = (True, IOStateSetToolbox (DisposDialog ptr tb1) ioState1);
- = (False,IOStateAddDialog dRep (IOStateSetToolbox tb1 ioState1));
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- (goAway, tb1) = TrackGoAway ptr h v tb;
- };
-
- HandleEvent :: !(DialogRep *s (IOState *s)) !Int !*s !(IOState *s) -> (!*s, !IOState *s);
- HandleEvent (dH,ptr) itemNr s ioState
- = HandleResponse resp dRep s (IOStateSetToolbox tb1 ioState1);
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- (dRep,resp,tb1) = HandleDialogEvent dH ptr tb itemNr;
- };
-
- HandleResponse :: !(Response *s) !(DialogRep *s (IOState *s)) !*s !(IOState *s) -> (!*s, !IOState *s);
- HandleResponse (RadioBox dFunc) dRep s ioState
- = (s, IOStateAddDialog dRep2 (IOStateSetToolbox tb2 ioState1));
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- (dRep1,tb1) = RetrieveEditTexts (dRep,tb);
- (dH,_) = dRep1;
- dInfo = DialogHandleToDialogInfo dH;
- (dRep2,tb2) = UnpackDialogState (dFunc dInfo (CreateDialogState (dRep1,tb1)));
- };
- HandleResponse (Final bFunc) dRep s ioState
- = bFunc dInfo s (IOStateAddDialog dRep1 (IOStateSetToolbox tb1 ioState1));
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- (dRep1,tb1) = RetrieveEditTexts (dRep,tb);
- (dH,_) = dRep1;
- dInfo = DialogHandleToDialogInfo dH;
- };
- HandleResponse Void_new dRep s ioState = (s,IOStateAddDialog dRep ioState);
-
- HandleSpecialItemEvent :: !EventRecord !*s !(IOState *s) -> (!*s, !IOState *s);
- HandleSpecialItemEvent (UpdateEvent,ptr,w,h,v,m) s ioState
- | not mine = (s,ioState1);
- = (s,IOStateChangeToolbox (UpdateDialog dRep) ioState1);
- where {
- (mine,dRep,ioState1) = IOStateGetDialogPtr ptr ioState;
- };
- HandleSpecialItemEvent (MouseDownEvent,_,when,h,v,mods) s ioState
- | region <> InContent = (s, IOStateSetToolbox tb1 ioState1);
- | not mine = (s, IOStateSetToolbox tb1 ioState`);
- | not found = (s, IOStateSetToolbox tb2 (IOStateAddDialog dRep ioState`));
- = HandleMouseEvent item (localPos, bstate, modifiers) dRep1 s ioState``;
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- (region, ptr, tb1) = FindWindow h v tb;
- (mine,dRep,ioState`)= IOStateRemoveActiveDialogPtr ptr ioState1;
- (localh,localv) = localPos;
- (localPos, tb2) = InGrafport ptr (GlobalToLocal (h,v)) tb1;
- (found,item) = GetItemPointedTo localPos dRep;
- modifiers = INTToModifiers mods;
- (dRep1, tb3) = RetrieveEditTexts (dRep,tb2);
- (bstate, ioState``) = IOStateButtonFreq when (localh,localv) ptr (IOStateSetToolbox tb3 ioState`);
- };
- HandleSpecialItemEvent _ s ioState = (s,ioState);
-
- GetItemPointedTo :: !(!Int,!Int) !(DialogRep s (IOState s)) -> (!Bool,!DialogItem s (IOState s));
- GetItemPointedTo localPos (DialogH id tt md rc ps items rs,ptr) = GetItemPtedTo localPos items;
-
- GetItemPtedTo :: !(!Int,!Int) ![DialogItem s (IOState s)] -> (!Bool,!DialogItem s (IOState s));
- GetItemPtedTo pos=:(x,y) [pop=:DialogPopUp _ (ItemBox l t w h) Able _ _ : rest]
- | IsBetween x l (l+w) && IsBetween y t (t+h) = (True,pop);
- = GetItemPtedTo pos rest;
- GetItemPtedTo pos=:(x,y) [but=:DialogIconButton _ (ItemBox l t w h) _ _ Able _ : rest]
- | IsBetween x l (l+w) && IsBetween y t (t+h) = (True,but);
- = GetItemPtedTo pos rest;
- GetItemPtedTo pos=:(x,y) [ctl=:Control _ (ItemBox l t w h) _ Able _ _ _ _ : rest]
- | IsBetween x l (l+w) && IsBetween y t (t+h) = (True,ctl);
- = GetItemPtedTo pos rest;
- GetItemPtedTo pos [_ : rest] = GetItemPtedTo pos rest;
- GetItemPtedTo _ _ = (False, DummyItem);
-
-
- // Handle mouse events in dialogs.
-
- HandleMouseEvent :: !(DialogItem *s (IOState *s)) !MouseState !(DialogRep *s (IOState *s)) !*s !(IOState *s)
- -> (!*s,!IOState *s);
- HandleMouseEvent item=:(DialogPopUp id pos=:(ItemBox l t w h) Able _ radios) ((x,_),_,_)
- dRep=:(dH,dPtr) s ioState
- | x < l = (s, IOStateAddDialog dRep ioState );
- | itemNr == 0 || itemNr == oldNr = (s, IOStateAddDialog dRep ioState1);
- = (s, IOStateAddDialog dRep2 ioState3);
- where {
- (oldNr,itemNr,menu,ioState1)= HandlePopUpMenuEvent item dRep ioState;
- (tb, ioState2) = IOStateGetToolbox ioState1;
- tb1 = CheckItem menu oldNr False tb;
- tb2 = CheckItem menu itemNr True tb1;
- tb3 = RedrawPopUpItemText pos text dPtr tb2;
- dialogH1 = ReplacePopUpInDialogHandle id item1 dH;
- item1 = DialogPopUp id pos Able ndi radios;
- dRep1 = (dialogH1, dPtr);
- dState = CreateDialogState (dRep1,tb3);
- (ndi, text, ab, dialogF) = GetIndexRadioButtonInfo itemNr radios;
- dState1 = dialogF (DialogHandleToDialogInfo dH) dState;
- (dRep2, tb4) = UnpackDialogState dState1;
- ioState3 = IOStateSetToolbox tb4 ioState2;
- };
- HandleMouseEvent (Control id pos=:(ItemBox l t w h) dom=:((dL,dT),_) ab cs look feel dialogF)
- ((x,y), button, mods) dRep=:(dialogH, dPtr) s ioState
- = (s, TrackCleanControl port tb4 dH dV id dRep2 ioState1);
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- (port, tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- tb3 = DrawIconOrControl pos dom draws dPtr tb2;
- (cs1, draws) = feel ((x+dH, y+dV), button, mods) cs;
- control1 = Control id pos dom ab cs1 look feel dialogF;
- dialogH1 = ReplaceControlInDialogHandle id control1 dialogH;
- dRep1 = (dialogH1, dPtr);
- dState = CreateDialogState (dRep1,tb3);
- dState1 = dialogF (DialogHandleToDialogInfo dialogH1) dState;
- (dRep2, tb4) = UnpackDialogState dState1;
- dH = dL-l;
- dV = dT-t;
- };
- HandleMouseEvent (DialogIconButton id pos=:(ItemBox l t w h) dom look ab buttonF) _ (dH,dPtr) s ioState
- = TrackIconButton True port tb3 dPtr rect buttonF dH s ioState1;
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- (port, tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- tb3 = QInvertRect rect tb2;
- rect = (l,t, l+w,t+h);
- };
-
- HandlePopUpMenuEvent :: !(DialogItem s (IOState s)) !(DialogRep s (IOState s)) !(IOState s)
- -> (!Int, !Int, !MacMenuHandle, !IOState s);
- HandlePopUpMenuEvent (DialogPopUp id (ItemBox l t w h) _ di radios) (dH, dPtr) ioState
- = (oldNr, itemNr, menu, ioState2);
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- tb1 = InsertMenu menu (-1) tb;
- (globalPos, tb2) = InGrafport dPtr (LocalToGlobal (l,t)) tb1;
- (globalX, globalY) = globalPos;
- (i, menu) = DialogHandleGetPopUpHandle id dH;
- oldNr = RadioButtonsIdToNr di radios;
- (menuId,itemNr,tb3) = PopUpMenuSelect menu globalY globalX oldNr tb2;
- tb4 = DeleteMenu PopUpMenuID tb3;
- ioState2 = IOStateSetToolbox tb4 ioState1;
- };
-
- TrackCleanControl :: !GrafPtr !Toolbox !Int !Int !DialogItemId !(DialogRep s (IOState s)) !(IOState s)
- -> IOState s;
- TrackCleanControl port tb dH dV id dRep ioState
- | down = TrackCleanControl port tb2 dH dV id dRep1 ioState;
- = IOStateAddDialog dRep1 (IOStateSetToolbox tb2 ioState);
- where {
- (down, tb1) = WaitMouseUp tb;
- (dRep1, tb2) = TrackCleanControlWithMouse port tb1 dH dV id down dRep;
- };
-
- TrackCleanControlWithMouse :: !GrafPtr !Toolbox !Int !Int !DialogItemId !Bool !(DialogRep s (IOState s))
- -> (!DialogRep s (IOState s), !Toolbox);
- TrackCleanControlWithMouse port tb dH dV id buttonDown (dialogH, dPtr)
- = UnpackDialogState dState1;
- where {
- (pos,dom,feel,cs,dialogF) = GetControlInfo control;
- control = GetControl id dialogH;
- (x, y, tb1) = GetMouse tb;
- (k1,k2,k3,k4,tb2) = GetKeys tb1;
- mods = KeyMapToModifiers (k1,k2,k3,k4);
- (cs1, draws1) = feel ((x+dH,y+dV), If buttonDown ButtonStillDown ButtonUp, mods) cs;
- control1 = ReplaceControlState cs1 control;
- dialogH1 = ReplaceControlInDialogHandle id control1 dialogH;
- dRep1 = (dialogH1, dPtr);
- tb3 = DrawIconOrControl pos dom draws1 dPtr tb2;
- tb4 = SetGrafportWhenUp buttonDown port tb3;
- dState = CreateDialogState (dRep1,tb4);
- dState1 = dialogF (DialogHandleToDialogInfo dialogH1) dState;
- };
-
- SetGrafportWhenUp :: !Bool !GrafPtr !Toolbox -> Toolbox;
- SetGrafportWhenUp buttonDown port tb
- | buttonDown = tb;
- = QSetPort port tb;
-
- ReplaceControlState :: !ControlState !(DialogItem s (IOState s)) -> DialogItem s (IOState s);
- ReplaceControlState state (Control id ps dm ab _ lk fl df) = Control id ps dm ab state lk fl df;
-
- GetControlInfo :: !(DialogItem s (IOState s))
- -> (ItemPos,PictureDomain,ControlFeel,ControlState,DialogFunction s (IOState s));
- GetControlInfo (Control _ pos dom _ state _ feel dfunc) = (pos,dom,feel,state,dfunc);
-
- GetControl :: !DialogItemId !(DialogHandle s (IOState s)) -> DialogItem s (IOState s);
- GetControl cid (DialogH _ _ _ _ _ items _) = GetControlInItemList cid items;
-
- GetControlInItemList :: !DialogItemId ![DialogItem s (IOState s)] -> DialogItem s (IOState s);
- GetControlInItemList cid [item=:Control id _ _ _ _ _ _ _ : items]
- | cid == id = item;
- = GetControlInItemList cid items;
- GetControlInItemList cid [_ : items] = GetControlInItemList cid items;
-
- TrackIconButton :: !Bool !GrafPtr !Toolbox !DialogPtr !Rect !(ButtonFunction *s (IOState *s))
- !(DialogHandle *s (IOState *s)) !*s !(IOState *s)
- -> (!*s, !IOState *s);
- TrackIconButton inside port tb dPtr rect=:(l,t,r,b) buttonF dialog s ioState
- | inside && stillIn = TrackIconButton` stillDown stillIn port tb2 dPtr rect buttonF dialog s ioState;
- | inside || stillIn = TrackIconButton` stillDown stillIn port tb3 dPtr rect buttonF dialog s ioState;
- = TrackIconButton` stillDown stillIn port tb2 dPtr rect buttonF dialog s ioState;
- where {
- stillIn = x >= l && y >= t && x <= r && y <= b;
- (x, y, tb1) = GetMouse tb;
- (stillDown, tb2) = WaitMouseUp tb1;
- tb3 = QInvertRect rect tb2;
- };
-
- TrackIconButton` :: !Bool !Bool !GrafPtr !Toolbox !DialogPtr !Rect !(ButtonFunction *s (IOState *s))
- !(DialogHandle *s (IOState *s)) !*s !(IOState *s)
- -> (!*s, !IOState *s);
- TrackIconButton` down inside port tb dPtr rect buttonF dialog s ioState
- | down = TrackIconButton inside port tb dPtr rect buttonF dialog s ioState;
- | inside = buttonF (DialogHandleToDialogInfo dialog) s ioState2;
- = (s, ioState3);
- where {
- dRep = (dialog, dPtr);
- ioState1 = IOStateAddDialog dRep ioState;
- ioState2 = IOStateSetToolbox (QSetPort port (QInvertRect rect tb)) ioState1;
- ioState3 = IOStateSetToolbox (QSetPort port tb) ioState1;
- };
-
- HiliteDefaultButton :: !Bool !Rect !DialogPtr !Toolbox -> Toolbox;
- HiliteDefaultButton True rect dPtr tb
- = tb7;
- where {
- (port, tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- tb3 = QInvertRect rect tb2;
- tb5 = UWait 8 tb3;
- tb6 = QInvertRect rect tb5;
- tb7 = QSetPort port tb6;
- };
- HiliteDefaultButton noIcon rect dPtr tb
- = tb9;
- where {
- (port, tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- tb3 = QInvertRoundRect rect 10 10 tb2;
- tb4 = QFrameRoundRect rect 10 10 tb3;
- tb6 = UWait 8 tb4;
- tb7 = QInvertRoundRect rect 10 10 tb6;
- tb8 = QFrameRoundRect rect 10 10 tb7;
- tb9 = QSetPort port tb8;
- };
-
-
- // Acces rules on dialogs and dialog items.
-
- GetDialogButtonInfo :: !DialogItemId ![DialogItem s (IOState s)]
- -> (!Bool, !Bool, !Rect, !ButtonFunction s (IOState s));
- GetDialogButtonInfo bid [DialogButton id (ItemBox l t w h) tt Able bf : rest]
- | bid == id = (True, False, (l,t,l + w,t + h), bf);
- = GetDialogButtonInfo bid rest;
- GetDialogButtonInfo bid [DialogIconButton id (ItemBox l t w h) pd il Able bf : rest]
- | bid == id = (True, True , (l,t,l + w,t + h), bf);
- = GetDialogButtonInfo bid rest;
- GetDialogButtonInfo bid [item : rest] = GetDialogButtonInfo bid rest;
- GetDialogButtonInfo bid _ = (False,False,(0,0,0,0),DummyButFunc);
-
- GetCancelButtonInfo :: ![DialogItem s (IOState s)] -> (!Bool, !Rect, !ButtonFunction s (IOState s));
- GetCancelButtonInfo [DialogButton id (ItemBox l t w h) title Able bfunc : rest]
- | title == "Cancel" = (True, (l,t,l + w,t + h), bfunc);
- = GetCancelButtonInfo rest;
- GetCancelButtonInfo [_ : rest] = GetCancelButtonInfo rest;
- GetCancelButtonInfo _ = (False,(0,0,0,0),DummyButFunc);
-
- // DummyButFunc :: !DialogInfo !*s !(IOState *s) -> (!*s, !IOState *s);
- DummyButFunc _ s io = (s,io);
-
- GetIndexRadioButtonInfo :: !Int ![RadioItemDef s (IOState s)]
- -> (!DialogItemId,!ItemTitle, !SelectState, !DialogFunction s (IOState s));
- GetIndexRadioButtonInfo itemnr [RadioItem id title ab df : rest]
- | itemnr == 1 = (id,title,ab,df);
- = GetIndexRadioButtonInfo (dec itemnr) rest;
- GetIndexRadioButtonInfo _ _
- = DialogDeviceError "GetIndexRadioButtonInfo" "Index out of range";
-
- RadioButtonsIdToNr :: !DialogItemId ![RadioItemDef s (IOState s)] -> Int;
- RadioButtonsIdToNr bid [RadioItem id title ab df : rest]
- | bid == id = 1;
- = inc (RadioButtonsIdToNr bid rest);
- RadioButtonsIdToNr bid _
- = DialogDeviceError "RadioButtonsIdToNr" ("Unknown item id: " +++ toString bid);
-
-
- // Access rule(s) on DialogHandles.
-
- DialogHandleGetPopUpHandle :: !DialogItemId !(DialogHandle s (IOState s)) -> PopUpHandle;
- DialogHandleGetPopUpHandle pid (DialogH _ _ _ _ popups _ _) = GetPopUpHandle pid popups;
-
- ReplacePopUpInDialogHandle :: !DialogId !(DialogItem s (IOState s)) !(DialogHandle s (IOState s))
- -> DialogHandle s (IOState s);
- ReplacePopUpInDialogHandle pid popup (DialogH id tt md rc ps items rt)
- = DialogH id tt md rc ps (ReplacePopUpInItemList pid popup items) rt;
-
- ReplacePopUpInItemList :: !DialogId !(DialogItem s (IOState s)) ![DialogItem s (IOState s)]
- -> [DialogItem s (IOState s)];
- ReplacePopUpInItemList pid popup [item=:DialogPopUp id ps ab di bs : rest]
- | pid == id = [popup : rest];
- = [item : ReplacePopUpInItemList pid popup rest];
- ReplacePopUpInItemList pid popup [item : rest]
- = [item : ReplacePopUpInItemList pid popup rest];
- ReplacePopUpInItemList pid _ _
- = DialogDeviceError "ReplacePopUpInDialogHandle" ("No PopUp with same id: " +++ toString pid);
-
- ReplaceControlInDialogHandle :: !DialogId !(DialogItem s (IOState s)) !(DialogHandle s (IOState s))
- -> DialogHandle s (IOState s);
- ReplaceControlInDialogHandle cid control (DialogH id tt md rc ps items rt)
- = DialogH id tt md rc ps (ReplaceControlInItemList cid control items) rt;
-
- ReplaceControlInItemList :: !DialogId !(DialogItem s (IOState s)) ![DialogItem s (IOState s)]
- -> [DialogItem s (IOState s)];
- ReplaceControlInItemList cid control [item=:Control id ps pd ab cs cl cf df : rest]
- | cid == id = [control : rest];
- = [item : ReplaceControlInItemList cid control rest];
- ReplaceControlInItemList cid control [item : rest]
- = [item : ReplaceControlInItemList cid control rest];
- ReplaceControlInItemList cid _ _
- = DialogDeviceError "ReplaceControlInDialogHandle" ("No Control with same id: " +++ toString cid);
-