home *** CD-ROM | disk | FTP | other *** search
- #include <Dialogs.h>
- #include <Controls.h>
- #include <QuickDraw.h>
- #include <Windows.h>
- #include <ToolUtils.h>
- #include <OSUtils.h>
- #include <Menus.h>
- #include <Fonts.h>
- #include <resources.h>
- #include <Sound.h>
- #include <Traps.h>
- #include <Gestaltequ.h>
- #include <Memory.h>
- #include <Scrap.h>
- #include <TextEdit.h>
-
- /* prototypes */
- ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem);
- void ToggleCheckBox(DialogPtr myDialog,short theItem);
- pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem);
-
-
- enum {
- /* ok and cancel are already defined in Dialogs.h */
- kMessUpItem = 3,
- kHiliteOK
- };
- enum {
-
- kSampleDialog = 128,
- kMessUpAlert
- };
-
- ModalFilterUPP gModalFilterUPP;
-
- #ifdef powerc
- QDGlobals qd;
- #endif
-
- main()
- {
- DialogPtr myDialog = nil; /* the dialog wee're using */
- short hitItem = 0; /* hitItem for ModalDialog */
-
- /* start up managers */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- /* set up the UPP for the Modal Dialog filter */
- gModalFilterUPP = NewModalFilterProc(filterIt);
-
- /* get our dialog */
- myDialog = GetNewDialog(kSampleDialog, nil, (WindowPtr)-1);
-
- SetDialogDefaultItem(myDialog, ok);
- SetDialogCancelItem(myDialog, cancel);
- /* dim the OK button initially */
- HiliteControl(SnatchHandle(myDialog,ok),255);
-
- do {
- ModalDialog(gModalFilterUPP, &hitItem);
- if(hitItem == kMessUpItem){
- /* bring up an alert to obscure the OK button */
- Alert(kMessUpAlert,nil);
- }
- else{
- if(hitItem == kHiliteOK)
- ToggleCheckBox(myDialog,kHiliteOK);
- HiliteControl(SnatchHandle(myDialog,ok),GetControlValue(SnatchHandle(myDialog,hitItem)) ? 0 : 255);
-
- }
-
- }
- while (hitItem != ok && hitItem != cancel);
-
- DisposeDialog(myDialog);
- InitCursor(); /* Init to prevent I-beam from hanging around in some circumstances */
-
-
- }
-
-
- pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem)
- {
- ModalFilterUPP theModalProc; /* address of standard filter */
-
-
- if (/* myDialogEvent->what == activateEvt || */myDialogEvent->what == updateEvt) {
- /* reset the state of the button based on my */
- /* check box. Use whatever conditions you need to determine the */
- /* correct highlighting */
- HiliteControl(SnatchHandle(inputDialog,ok),GetControlValue(SnatchHandle(inputDialog,kHiliteOK)) ? 0 : 255);
-
- }
- /* You must still call through the standard filter for things to work, of course */
- GetStdFilterProc(&theModalProc);
- return CallModalFilterProc(theModalProc, inputDialog, myDialogEvent, theDialogItem);
-
- }
-
- ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem)
- {
- short itemtype;
- Rect itemrect;
- Handle thandle;
-
- GetDialogItem(thebox, theGetItem, &itemtype, &thandle, &itemrect);
- return((ControlHandle)thandle);
- } /* end SnatchHandle */
-
-
- void ToggleCheckBox(DialogPtr myDialog,short theItem)
- {
-
- SetControlValue(SnatchHandle(myDialog,theItem),GetControlValue(SnatchHandle(myDialog,theItem)) ? false:true);
- }
-
-