home *** CD-ROM | disk | FTP | other *** search
- #include "General.h"
- #include "cdev tester.proto.h"
-
- WindowPtr theControlPanel=NIL;
- Boolean gDone=FALSE,gHasCursor=FALSE;
- long cdevValue=0;
-
- void main(void)
- {
- InitGraf(&thePort);
-
- InitFonts();
- FlushEvents(everyEvent,0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- MaxApplZone();
-
- SetUpMenus();
- if(GetResource('CURS',-4064)!=NIL) gHasCursor=TRUE;
- EventLoop();
-
- }
-
- void SetUpMenus(void)
- {
- SetMenuBar(GetNewMBar(RES_ID));
- AddResMenu(GetMHandle(APPLE_MENU),'DRVR');
- MaintainMenus();
- }
-
- void MaintainMenus(void)
- {
- if(!theControlPanel)
- { DisableItem(GetMenu(EDIT_MENU),0);
- DisableItem(GetMenu(FILE_MENU),CLOSE);
- EnableItem(GetMenu(FILE_MENU),OPEN);
- }
- else
- { EnableItem(GetMenu(EDIT_MENU),0);
- EnableItem(GetMenu(FILE_MENU),CLOSE);
- DisableItem(GetMenu(FILE_MENU),OPEN);
- }
- DrawMenuBar();
- }
-
- void EventLoop(void)
- { short theChar;
- EventRecord theEvent;
- Point theMouse;
- Boolean dlogEvent;
- DialogPtr theDialog;
- int theItem;
-
- while (!gDone)
- {
- WaitNextEvent(everyEvent,&theEvent,MIN_SLEEP,NIL_MOUSE_REGION);
- dlogEvent=IsDialogEvent(&theEvent);
-
- if(dlogEvent && theEvent.what==keyDown)
- ErrorCheck(cdev(keyEvtDev,0,0,0,&theEvent,cdevValue,theControlPanel));
- DialogSelect(&theEvent,&theDialog,&theItem);
-
- switch(theEvent.what)
- { case nullEvent:
- if(dlogEvent)
- { ErrorCheck(cdev(nulDev,0,0,0,&theEvent,cdevValue,theControlPanel));
- if(gHasCursor)
- { theMouse=theEvent.where;
- GlobalToLocal(&theMouse);
- if(PtInRect(theMouse,&theControlPanel->portRect))
- ErrorCheck(cdev(cursorDev,0,0,0,&theEvent,cdevValue,theControlPanel));
- }
- }
- break;
- case mouseDown:
- if(dlogEvent)
- ErrorCheck(cdev(hitDev,theItem,0,0,&theEvent,cdevValue,theControlPanel));
- else HandleMouseDown(theEvent);
- break;
- case keyDown:
- case autoKey:
- theChar=theEvent.message & charCodeMask;
- if(theEvent.modifiers & cmdKey)
- { if(theEvent.what!=autoKey)
- HandleMenuChoice(MenuKey(theChar));
- }
- break;
- case updateEvt:
- if(dlogEvent)
- ErrorCheck(cdev(updateDev,0,0,0,&theEvent,cdevValue,theControlPanel));
- break;
- case activateEvt:
- if((theEvent.modifiers&activeFlag)!=0 && dlogEvent)
- ErrorCheck(cdev(activDev,0,0,0,&theEvent,cdevValue,theControlPanel));
- else
- ErrorCheck(cdev(deactivDev,0,0,0,&theEvent,cdevValue,theControlPanel));
- break;
- default:
- break;
- }
- }
- ExitToShell();
- }
-
- void SAlert(int index)
- { Str63 errorText;
-
- GetIndString(errorText,128,index);
- ParamText(errorText,"","","");
- StopAlert(128,NIL);
- }
-
- void ErrorCheck(long returnValue)
- { Str63 errorText;
-
- switch(returnValue)
- { case 0:
- case 1:
- SAlert(returnValue+1);
- case -1:
- cdevValue=0;
- CloseControlPanel();
- MaintainMenus();
- break;
- default:
- cdevValue=returnValue;
- break;
- }
- }
-
- Boolean CheckControlPanel(void)
- { Boolean result=1;
- machHandle machHndl;
- register int x;
-
- machHndl=(machHandle)GetResource('mach',-4064);
- if((*machHndl)->softmask==0x0000 && (*machHndl)->hardmask==0xFFFF)
- result=(Boolean)cdev(macDev,0,0,0,NIL,0,theControlPanel);
- else
- { for(x=0;x<=15;x++)
- { if(BitTst(&(*machHndl)->softmask,x)==0)
- { if(BitTst(&ROM85,x)!=0) result=0; }
- }
- /* for(x=0;x<=15;x++)
- { if(BitTst(&(*machHndl)->hardmask,x)==1)
- { if(BitTst(&HwCfgFlgs,x)!=1) result=0; }
- } */
- }
- cdevValue=cdevUnset;
- return(result);
- }
-
- void OpenControlPanel(void)
- { Rect boundsRect;
- Handle itemsHndl;
- TEHandle textHndl;
-
- boundsRect=(*(nrctHandle)GetResource('nrct',-4064))->theRect[0];
- OffsetRect(&boundsRect,-47,45);
- itemsHndl=GetResource('DITL',-4064);
- HandToHand(&itemsHndl);
- SetDAFont(geneva);
- theControlPanel=NewDialog(NIL,&boundsRect,"\pControl Panel Tester",
- FALSE,noGrowDocProc,(WindowPtr)-1L,TRUE,0L,itemsHndl);
- SetDAFont(0);
- textHndl=((DialogPeek)theControlPanel)->textH;
- (*textHndl)->txSize=9;
- (*textHndl)->lineHeight=12;
- (*textHndl)->fontAscent=10;
- TECalText(textHndl);
- SetPort(theControlPanel);
- SetOrigin(87,-1);
- TextSize(9);
-
- ShowWindow(theControlPanel);
- SelectWindow(theControlPanel);
-
- ErrorCheck(cdev(initDev,0,0,0,NIL,cdevValue,theControlPanel));
- }
-
- void CloseControlPanel(void)
- { cdev(closeDev,0,0,0,NIL,cdevValue,theControlPanel);
- CloseDialog(theControlPanel);
- theControlPanel=NIL;
- }
-
- void HandleMouseDown(EventRecord theEvent)
- { WindowPtr theWindow;
- Rect dragRect;
-
- switch(FindWindow(theEvent.where,&theWindow))
- { case inMenuBar:
- HandleMenuChoice(MenuSelect(theEvent.where));
- break;
- case inSysWindow:
- SystemClick(&theEvent,theWindow);
- MaintainMenus();
- break;
- case inDrag:
- SetRect(&dragRect,DRAG,DRAG,screenBits.bounds.right-DRAG,screenBits.bounds.bottom-DRAG);
- DragWindow(theWindow,theEvent.where,&dragRect);
- break;
- case inGoAway:
- if(TrackGoAway(theWindow,theEvent.where))
- { CloseControlPanel();
- MaintainMenus();
- }
- break;
- default:
- break;
- }
- }
-
- void HandleMenuChoice(long menuChoice)
- { int theMenu,theItem;
-
- if(menuChoice)
- { theMenu=HiShort(menuChoice);
- theItem=LoShort(menuChoice);
-
- switch(theMenu)
- { case APPLE_MENU:
- HandleAppleChoice(theItem);
- break;
- case FILE_MENU:
- HandleFileChoice(theItem);
- break;
- case EDIT_MENU:
- HandleEditChoice(theItem);
- break;
- default:
- break;
- }
- }
- HiliteMenu(0);
- }
-
- void HandleAppleChoice(int theItem)
- { Str32 accName;
- DialogPtr theDialog;
- int itemHit;
-
- switch(theItem)
- { case ABOUT:
- theDialog=GetNewDialog(128,NIL,(WindowPtr)-1L);
- ModalDialog(NIL,&itemHit);
- DisposDialog(theDialog);
- break;
- default:
- GetItem(GetMHandle(APPLE_MENU),theItem,accName);
- OpenDeskAcc(accName);
- break;
- }
- }
-
- void HandleFileChoice(int theItem)
- { switch(theItem)
- { case OPEN:
- if(!CheckControlPanel())
- { SAlert(3);
- break;
- }
- OpenControlPanel();
- MaintainMenus();
- break;
- case CLOSE:
- CloseControlPanel();
- MaintainMenus();
- break;
- case QUIT:
- if(theControlPanel!=NIL) CloseControlPanel();
- gDone=TRUE;
- break;
- default:
- break;
- }
- }
-
- void HandleEditChoice(int theItem)
- { switch(theItem)
- { case UNDO:
- ErrorCheck(cdev(undoDev,0,0,0,NIL,cdevValue,theControlPanel));
- break;
- case CUT:
- ErrorCheck(cdev(cutDev,0,0,0,NIL,cdevValue,theControlPanel));
- break;
- case COPY:
- ErrorCheck(cdev(copyDev,0,0,0,NIL,cdevValue,theControlPanel));
- break;
- case PASTE:
- ErrorCheck(cdev(pasteDev,0,0,0,NIL,cdevValue,theControlPanel));
- break;
- case CLR:
- ErrorCheck(cdev(clearDev,0,0,0,NIL,cdevValue,theControlPanel));
- break;
- }
- }