#include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include /*#include #include #include #include #include #include #include #include #include #include */#include #include #include #include #include #include #include #include #define dInput 130 #define iInputTitle 1 #define iInputVLabel 2 #define iInputValue 3 #define iInputLLabel 4 #define iInputColour 5 #define iInputOk 6 #define iInputCancel 7 #define dError 131 #define iErrorTitle 1 #define iErrorMsg 2 #define iErrorOk 3 #define kReturn (SInt8) 0x0D #define kEnter (SInt8) 0x03 #define kEscape (SInt8) 0x1B #define kPeriod (SInt8) 0x2E #define dQuit 134 #define iQuitTitle 1 #define iQuitIcon 2 #define iQuitText 3 #define iQuitYes 4 #define iQuitNo 5 #define dIError 129 #define iIErrorTitle 1 #define iIErrorValue 5 #define iIErrorOk 3 #define iIErrorCancel 4 #define iIErrorText 6 #define mGraph 131 #define iBar 1 #define iPie 2 #define iHistogram 3 #define mFile 129 #define iPref 1 #define iQuit 3 #define mInput 132 #define iInput1 1 #define iInput2 2 #define iInput3 3 #define iInput4 4 #define iInput5 5 #define iInput6 6 #define iInput7 7 #define iInput8 8 #define iInput9 9 #define iInput10 10 #define mEdit 133 #define iUndo 1 #define iCut 3 #define iCopy 4 #define iPaste 5 #define iClear 6 #define mApple 130 #define iAbout 1 #define wMain 128 #define sNumInput 1 #define wPie 4 #define wBar 5 #define wHist 6 #define wSelect 3 #define pPie 134 #define pBar 135 #define pHistogram 136 /* Global Variable Definitions */ WindowPtr gWindow; PaletteHandle gPalette; struct inputRec { Str255 label; float value; RGBColor colour; }; struct dataRec { struct inputRec input[10]; float total; float max; int length; float min; Str255 curString; int window; }; RGBColor gWhiteColour = { 0xFFFF, 0xFFFF, 0xFFFF }; RGBColor gBlackColour = { 0x0000, 0x0000, 0x0000 }; RGBColor gRedColour = { 0xAAAA, 0x0000, 0x0000 }; RGBColor gYellowColour = { 0xFFFF, 0xCCCC, 0x0000 }; RGBColor gGreenColour = { 0x0000, 0x9999, 0x0000 }; RGBColor gBlueColour = { 0x6666, 0x6666, 0x9999 }; RGBColor ltGrayColour = { 0xDDDD, 0xDDDD, 0xDDDD }; RGBColor grayColour = { 0x9999, 0x9999, 0x9999 }; RGBColor dkGrayColour = { 0x4444, 0x4444, 0x4444 }; RGBColor gInColour = { 0xCCCC, 0x0000, 0x0000 }; RGBColor gOutColour; Boolean gColorPickerButton; CMRGBColor gMyRGBColor; CGrafPtr cPort; FILE *f; struct dataRec data; AEEventHandlerUPP doQuitAppEventUPP; pascal Boolean OurFilter(DialogPtr dlg, EventRecord *event, short *itemhit); int drawPie (struct dataRec data); int drawBar (struct dataRec data); int drawLegend (struct dataRec data); struct dataRec getValues (struct dataRec data); void drawHeader (void); void createPalette(); void drawFooter (void); void doCopyString(Str255, Str255); void MyPickAColor(void); pascal Boolean MyPickerEventFilterFunction (EventRecord *event); pascal void MyColorChangedFunction(long userData, PMColorPtr newColor); void chooseColour (void); int doSelectGraph(void); void doCopyString(Str255 source, Str255 dest) { SInt16 strLen; strLen = source[0]; BlockMove(source + 1, dest + 1, strLen); dest[0] = strLen; } /*struct dataRec getValues (struct dataRec data) { Rect rect; int x, nums; // drawHeader(); printf("How many students do you want to record marks for (max 25) -=> "); scanf("%i", &nums); for(x=0;x ", x+1, nums); scanf("%i", data.input[x].value); if (data.input[x].value > data.max) data.max = data.input[x].value; if (data.input[x].value < data.min) data.min = data.input[x].value; data.total = data.total + data.input[x].value; data.length = data.length +1; } return data; } int doPrint(struct dataRec) { THPrint tPrintHdl; PrOpen(void); tPrintHdl = (THPrint) NewHandleClear(sizeof(TPrint)); if(tPrintHdl != NULL ) { PrintDefault(tPrintHdl); // Sets appropriate default values for current driver. if(printError = PrError()) doPrintError(printError); } else // Handle error. void doDrawRectStrings(Str255 s1,SInt16 x1,SInt16 y1,Str255 s2,SInt16 x2, SInt16 y2,Str255 s3) { MoveTo(x1,y1); DrawString(s1); MoveTo(x2,y2); DrawString("\p("); DrawString(s2); DrawString("\p,"); DrawString(s3); DrawString("\p)"); } void doPrintRecordsInfo(void) { RGBColor oldForeColour, oldBackColour; SInt16 fontNum; Str255 s2, s3; if(FrontWindow() == gWindowPtr && gPrintStructureInited && !gInhibitPrintStructuresInfo) { GetForeColor(&oldForeColour); GetBackColor(&oldBackColour); RGBForeColor(&gWhiteColour); RGBBackColor(&gBlueColour); EraseRect(&(gWindowPtr->portRect)); GetFNum("\pGeneva",&fontNum); TextFont(fontNum); TextSize(10); MoveTo(20,25); TextFace(bold); DrawString("\pFrom TPrint, TPrInfo and TPrStl structures:"); TextFace(normal); NumToString((long) (*gTPrintHdl)->rPaper.top,s2); NumToString((long) (*gTPrintHdl)->rPaper.left,s3); doDrawRectStrings("\pPaper Rectangle (top,left):",20,45,s2,190,45,s3); NumToString((long) (*gTPrintHdl)->rPaper.bottom,s2); NumToString((long) (*gTPrintHdl)->rPaper.right,s3); doDrawRectStrings("\pPaper Rectangle (bottom,right):",20,60,s2,190,60,s3); NumToString((long) ((*gTPrintHdl)->prInfo.rPage).top,s2); NumToString((long) ((*gTPrintHdl)->prInfo.rPage).left,s3); doDrawRectStrings("\pPage Rectangle (top,left):",20,75,s2,190,75,s3); NumToString((long) ((*gTPrintHdl)->prInfo.rPage).bottom,s2); NumToString((long) ((*gTPrintHdl)->prInfo.rPage).right,s3); doDrawRectStrings("\pPage Rectangle (bottom,right):",20,90,s2,190,90,s3); MoveTo(20,105); DrawString("\pFeed Type:"); MoveTo(190,105); if((*gTPrintHdl)->prStl.feed == 0) DrawString("\pCut sheet"); else if((*gTPrintHdl)->prStl.feed == 1) DrawString("\pFanfold"); MoveTo(20,120); DrawString("\pVertical resolution:"); NumToString((long) (*gTPrintHdl)->prInfo.iVRes,s2); MoveTo(190,120); DrawString(s2); MoveTo(20,135); DrawString("\pHorizontal resolution:"); NumToString((long) (*gTPrintHdl)->prInfo.iHRes,s2); MoveTo(190,135); DrawString(s2); MoveTo(20,155); TextFace(bold); DrawString("\pFrom TPrJob structure:"); TextFace(normal); MoveTo(20,175); DrawString("\pFirst Page:"); NumToString((long) (*gTPrintHdl)->prJob.iFstPage,s2); MoveTo(190,175); DrawString(s2); MoveTo(20,190); DrawString("\pLast Page:"); NumToString((long) (*gTPrintHdl)->prJob.iLstPage,s2); MoveTo(190,190); DrawString(s2); MoveTo(20,205); DrawString("\pNumber of Copies:"); NumToString((long) (*gTPrintHdl)->prJob.iCopies,s2); MoveTo(190,205); DrawString(s2); MoveTo(20,245); DrawString("\pNote: Some printer drivers always set the iCopies field of the TPrJob"); MoveTo(20,260); DrawString("\pstructure to 1 and handle multiple copies internally."); } RGBForeColor(&oldForeColour); RGBBackColor(&oldBackColour); } void doDrawPage(Rect pageRect,SInt16 pageNumber,SInt16 numberOfpages) { Rect destRect, pictureRect; SInt16 heightDestRect, linesPerPage, numberOfLines; TEHandle pageEditRecHdl; Handle textHdl; SInt32 startOffset, endOffset; Str255 theString; SetRect(&destRect,pageRect.left + kMargin,pageRect.top + (kMargin * 1.5), pageRect.right - kMargin,pageRect.bottom - (kMargin * 1.5)); heightDestRect = destRect.bottom - destRect.top; linesPerPage = heightDestRect / (*gEditRecHdl)->lineHeight; numberOfLines = (*gEditRecHdl)->nLines; TextFont(gFontNumber); TextSize(gFontSize); pageEditRecHdl = TENew(&destRect,&destRect); textHdl = (*gEditRecHdl)->hText; startOffset = (*gEditRecHdl)->lineStarts[(pageNumber - 1) * linesPerPage]; if(pageNumber == numberOfpages) endOffset = (*gEditRecHdl)->lineStarts[numberOfLines]; else endOffset = (*gEditRecHdl)->lineStarts[pageNumber * linesPerPage]; HLock(textHdl); TEInsert(*textHdl + startOffset,endOffset - startOffset,pageEditRecHdl); HUnlock(textHdl); if(pageNumber == 1) { SetRect(&pictureRect,destRect.left,destRect.top, destRect.left + ((*gPictureHdl)->picFrame.right - (*gPictureHdl)->picFrame.left), destRect.top + ((*gPictureHdl)->picFrame.bottom - (*gPictureHdl)->picFrame.top)); DrawPicture(gPictureHdl,&pictureRect); } MoveTo(destRect.left,pageRect.bottom - 25); NumToString((SInt32) pageNumber,theString); DrawString(theString); } SInt16 doCalcNumberOfPages(Rect pageRect) { Rect destRect, pictureRect; SInt16 heightDestRect, linesPerPage, numberOfPages; RGBForeColor(&gBlackColour); RGBBackColor(&gWhiteColour); EraseRect(&(gWindowPtr->portRect)); SetRect(&destRect,pageRect.left + kMargin,pageRect.top + (kMargin * 1.5), pageRect.right - kMargin,pageRect.bottom - (kMargin * 1.5)); OffsetRect(&destRect,- (kMargin - 5),- ((kMargin * 1.5) - 5)); TextFont(gFontNumber); TextSize(gFontSize); gEditRecHdl = TENew(&destRect,&destRect); TEInsert(*gTextHdl,GetHandleSize(gTextHdl),gEditRecHdl); heightDestRect = destRect.bottom - destRect.top; linesPerPage = heightDestRect / (*gEditRecHdl)->lineHeight; numberOfPages = ((*gEditRecHdl)->nLines / linesPerPage) + 1; SetRect(&pictureRect,destRect.left,destRect.top, destRect.left + ((*gPictureHdl)->picFrame.right - (*gPictureHdl)->picFrame.left), destRect.top + ((*gPictureHdl)->picFrame.bottom - (*gPictureHdl)->picFrame.top)); DrawPicture(gPictureHdl,&pictureRect); return(numberOfPages); } void doErrorAlert(SInt16 errorType,Boolean fatal) { AlertStdAlertParamRec paramRec; Str255 theString, errorString = "\pPrinting Manager Error "; SInt16 itemHit; paramRec.movable = true; paramRec.helpButton = false; paramRec.filterProc = NULL; paramRec.defaultText = (StringPtr) kAlertDefaultOKText; paramRec.cancelText = NULL; paramRec.otherText = NULL; paramRec.defaultButton = kAlertStdAlertOKButton; paramRec.cancelButton = 0; paramRec.position = kWindowDefaultPosition; NumToString((long) errorType,theString); doConcatPStrings(errorString,theString); if(!fatal) StandardAlert(kAlertCautionAlert,errorString,NULL,¶mRec,&itemHit); else { StandardAlert(kAlertStopAlert,errorString,NULL,¶mRec,&itemHit); ExitToShell(); } } OSErr doCreatePrintRecord(void) { SInt16 printError; gTPrintHdl = (THPrint) NewHandleClear(sizeof(TPrint)); if(gTPrintHdl != NULL ) { PrintDefault(gTPrintHdl); printError = PrError(); if(printError == noErr) gPrintStructureInited = true; return(printError); } else ExitToShell(); } void doPrStyleDialog(void) { SInt16 printError; PrOpen(); printError = PrError(); if(printError == noErr) { if(!gPrintStructureInited) { printError = doCreatePrintRecord(); if(printError != noErr) doErrorAlert(printError,true); } PrStlDialog(gTPrintHdl); } else doErrorAlert(printError,false); PrClose(); } */ int drawPie (struct dataRec data) { Rect pie; float curArc,arcs; int x; curArc=0.0; RGBForeColor(&gBlackColour); SetRect(&pie, 150, 100, 450, 400); arcs = 360.0 / data.total; data.window = pPie; for (x=0;x<=data.length;x++) { RGBForeColor(&data.input[x].colour); PaintArc(&pie, curArc, (data.input[x].value * arcs) + (x == data.length ? 1 : 0)); curArc = curArc + (data.input[x].value * arcs); } drawLegend(data); // RGBForeColor(&data.input[data.length].colour); // PaintArc(&pie, curArc, 0); return 1; } int drawBar(struct dataRec data) { Rect rect, bar; float xSeg, lastSeg; int x=0, ySeg, y=0; data.window = pBar; // SetRect(&graph, 150, 75, 450, 400); RGBForeColor(&gBlackColour); // FrameRect(&graph); MoveTo(150, 70); LineTo(150, 400); LineTo(450, 400); xSeg = (300 - (10 * data.length)) / (data.length + 1); lastSeg = 150; // ySeg = (data.max / 298); // .3 ySeg = 280 / ((data.length+1) * 10); for (x=0;x<25;x++) { MoveTo(140, 75 + (13 * x)); LineTo(150, 75 + (13 * x)); for (y=0;y<75;y++) { SetRect(&rect, 153 + (4 * y), 74 + (13 * x), 155 + (4 * y), 76 + (13*x)); PaintOval(&rect); } } for (x=0;xportRect; RGBBackColor(&gBlueColour); EraseRect(&theRect); InsetRect(&theRect,55,55); // RGBForeColor(&gInColour); // PaintRect(&theRect); where.v = where.h = 0; gColorPickerButton = GetColor(where,prompt,&gInColour,&gOutColour); InvalRect(&gWindow->portRect); } void intro(void) { WindowPtr titleWindow; char text[] = " "; int AllDone=1, KindaDone=1,SortaDone=1,NotDone=1, xInt=0, counter=0, x1=-20, x2=20; long scrapOffset=0, rc=0; PicHandle title; Rect picRect[10]; EventRecord theEvent; titleWindow=GetNewWindow(129,0L,(WindowPtr)-1L); SetPort(titleWindow); title=GetPicture(137); SetRect(&picRect[1], 0, 0, 325, 225); DrawPicture(title,&picRect[1]); AllDone=0; while(AllDone<1) { WaitNextEvent(everyEvent, &theEvent,0L,0L); switch(theEvent.what) { case mouseDown: { AllDone=1; } } } DisposeWindow(titleWindow); } int doChangeInput (int x) { DialogPtr TheDialog, TheDialog2; Str255 theText, theItem; short iKind; long amount; Handle iHandle; Rect iRect; OSErr theErr; short itemHit, itemHit2; TheDialog=GetNewDialog(dInput ,nil, (WindowPtr)-1); doCopyString("\pEnter Input", theText); GetDialogItem(TheDialog, iInputTitle, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); doCopyString("\pLabel", theText); GetDialogItem(TheDialog, iInputVLabel, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); doCopyString("\p0", theText); GetDialogItem(TheDialog, iInputValue, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); do { ModalDialog(NewModalFilterProc(OurFilter), &itemHit); theErr = SetDialogDefaultItem(TheDialog, iInputOk); if (itemHit == iInputOk) { /* if (0) { TheDialog=GetNewDialog(dError,nil, (WindowPtr)-1); doCopyString("\pERROR", theText); GetDialogItem(TheDialog, iErrorTitle, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); doCopyString("\pNo colour selected", theText); GetDialogItem(TheDialog, iErrorMsg, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); do { ModalDialog(NewModalFilterProc(OurFilter), &itemHit2); theErr = SetDialogDefaultItem(TheDialog2, 2); if (itemHit2 == iErrorOk) { DisposeDialog(TheDialog2); itemHit2 = ok; } } while (itemHit2 != ok); } else { */ GetDialogItem(TheDialog, iInputVLabel, &iKind, &iHandle, &iRect); GetDialogItemText(iHandle, theItem); doCopyString(theItem, data.input[x].label); GetDialogItem(TheDialog, iInputValue, &iKind, &iHandle, &iRect); GetDialogItemText(iHandle, theItem); StringToNum(theItem, &amount); if ((amount < 0) || (amount >360)) { SysBeep(1); doCopyString("\pValue must be between 0 and 360", theText); GetDialogItem(TheDialog, iInputTitle, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); } else { InvalRect(&iRect); data.input[x].value = amount; if (amount > data.max) data.max = amount; else if (amount < data.min) data.min = amount; data.total = data.total + amount; // DisposeDialog(TheDialog); itemHit = ok; } } else if (itemHit == iInputColour) { chooseColour(); data.input[x].colour = gOutColour; } } while (itemHit != ok); DisposeDialog(TheDialog); doSelectGraph(); } int doInit (void) { MaxApplZone(); MoreMasters(); InitGraf (&qd.thePort); InitFonts(); InitWindows(); InitMenus(); TEInit(); InitDialogs(NULL); InitCursor(); FlushEvents(everyEvent,0); //RegisterAppearanceClient(); // Gestalt(gestaltColorPickerVersion, version); AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,doQuitAppEventUPP, 0L, false); } pascal OSErr doQuitAppEvent(AppleEvent *appEvent,AppleEvent *reply,SInt32 handlerRefcon) { DialogPtr TheDialog, TheDialog2; Str255 theText, theItem; short iKind; long amount; Handle iHandle; Rect iRect; OSErr theErr; short itemHit, itemHit2; /* doHasGotRequiredParams(appEvent); if(osErr == noErr) {*/ TheDialog=GetNewDialog(dQuit,nil, (WindowPtr)-1); do { ModalDialog(NewModalFilterProc(OurFilter), &itemHit); theErr = SetDialogDefaultItem(TheDialog, iQuitNo); if (itemHit == iQuitNo) break; else if (itemHit == iQuitYes) { fclose(f); break; } } while (itemHit != ok); return(noErr); // else // return(osErr); } int doSelectGraph (void) { PicHandle pic1, pic2, pic3; Rect picRect[4]; pic1 = GetPicture(pBar); SetRect(&picRect[0], 45, 270, 155, 380); DrawPicture(pic1, &picRect[0]); pic2 = GetPicture(pPie); SetRect(&picRect[1], 265, 270, 375, 380); DrawPicture(pic2, &picRect[1]); pic3 = GetPicture(pHistogram); SetRect(&picRect[2], 485, 270, 595, 380); DrawPicture(pic3, &picRect[2]); data.window = wSelect; } int main(void) { WindowPtr aWindow,helpWindow; DialogPtr TheDialog,TheDialog2; OSErr theErr; short itemHit, itemHit2; short iKind; Handle iHandle, mBarHandle; long mChoice; short theMenu,theMenuItem,done,thePart; Rect iRect; Str255 theItem,theText; EventRecord theEvent; MenuHandle mHandle; long *version, amount; char text[] = " ", input[30],strx[5]; int AllDone=1, KindaDone=1,SortaDone=1,NotDone=1, xInt=0, counter=0, x1=-20, x2=20, x,y,intx; long scrapOffset=0, rc=0; PicHandle E,G,Q,H,click,OK,back,next; Rect theRect,picRect[10],fieldRect[5],eraseRect,OKRect[5]; TEHandle mainText, fields[6]; Point thePoint,thePoint2,thePoint3; EventRecord theEvent2,theEvent3; CharsHandle theHandle; SInt8 charCode; doInit(); // ......................... create routine descriptors (required Apple event handlers) doQuitAppEventUPP = NewAEEventHandlerProc((ProcPtr) doQuitAppEvent); gWindow = GetNewWindow(128, 0L, (WindowPtr)-1L); SetPort(gWindow); mBarHandle = GetNewMBar(128); SetMenuBar(mBarHandle); DrawMenuBar(); MoveTo(100, 100); done = 0; //drawPie(data); E=GetPicture(128); SetRect(&picRect[1], 120, 38, 230, 78); DrawPicture(E,&picRect[1]); G=GetPicture(129); SetRect(&picRect[2],10, 375, 120, 415) ; DrawPicture(G,&picRect[2]); Q=GetPicture(130); SetRect(&picRect[3], 150, 375, 260, 415); DrawPicture(Q,&picRect[3]); H=GetPicture(131); SetRect(&picRect[4], 290, 375, 400, 415); DrawPicture(H,&picRect[4]); ForeColor(redColor); SetWTitle(gWindow, "\pGraphing Program"); MoveTo(10, 20); TextSize(16); DrawString("\pHow many questions did you ask in your survey?"); SetRect(&theRect, 10, 45, 95, 65); mainText = TENew(&theRect, &theRect); TEActivate(mainText); TESetText(text, strlen(text), mainText); TEUpdate(&theRect, mainText); AllDone=1; while (AllDone==1) { WaitNextEvent(everyEvent, &theEvent, 0L, 0L); switch(theEvent.what) { case mouseDown: GetMouse(&thePoint); thePart = FindWindow(theEvent.where, &aWindow); switch (thePart) { case inMenuBar: mChoice = MenuSelect(theEvent.where); if (mChoice > 0) { theMenu=HiWord(mChoice); theMenuItem=LoWord(mChoice); switch(theMenu) { case mFile: switch(theMenuItem) { case iPref: SysBeep(1); break; case 2: case iQuit: SysBeep(1); TheDialog=GetNewDialog(dQuit,nil, (WindowPtr)-1); do { ModalDialog(NewModalFilterProc(OurFilter), &itemHit); theErr = SetDialogDefaultItem(TheDialog, iQuitNo); if (itemHit == iQuitNo) break; else if (itemHit == iQuitYes) { fclose(f); break; } } while (itemHit != ok); } break; case mGraph: switch(theMenuItem) { case iBar: drawBar(data); case iPie: drawPie(data); case iHistogram: drawHistogram(data); } break; case mInput: switch(theMenuItem) { case iInput1: doChangeInput(1); case iInput2: doChangeInput(2); case iInput3: doChangeInput(3); case iInput4: doChangeInput(4); case iInput5: doChangeInput(5); case iInput6: doChangeInput(6); case iInput7: doChangeInput(7); case iInput8: doChangeInput(8); case iInput9: doChangeInput(9); case iInput10: doChangeInput(10); } break; } HiliteMenu(0); } break; } if (data.window == wSelect) { SetRect(&picRect[6], 45, 270, 155, 380); SetRect(&picRect[7], 265, 270, 375, 380); SetRect(&picRect[8], 485, 270, 595, 380); if (PtInRect(thePoint, &picRect[6])) drawPie(data); else if (PtInRect(thePoint, &picRect[7])) drawHistogram(data); else if (PtInRect(thePoint, &picRect[8])) drawBar(data); } TEClick(thePoint, FALSE, mainText); if (PtInRect(thePoint, &picRect[3])) { fclose(f); } else if (PtInRect(thePoint, &picRect[4])) { DisposeWindow(gWindow); helpWindow=GetNewWindow(130, 0L, (WindowPtr)-1L); SetPort(helpWindow); back=GetPicture(131); SetRect(&picRect[6],10, 200, 120, 230) ; DrawPicture(back,&picRect[6]); Q=GetPicture(130); SetRect(&picRect[3], 150, 200, 260, 230); DrawPicture(Q,&picRect[3]); next=GetPicture(132); SetRect(&picRect[7],290, 200,400 , 230) ; DrawPicture(next,&picRect[7]); } else if(PtInRect(thePoint, &picRect[1])) { ForeColor(blackColor); SetRect(&eraseRect,100,85,400,120); PaintRect(&eraseRect); ForeColor(redColor); MoveTo(100, 100); theHandle = TEGetText(mainText); TEDeactivate(mainText); sprintf(input , "%s", *theHandle); amount = atoi(input); if (amount > 10) { //Error dialog TheDialog=GetNewDialog(dIError,nil, (WindowPtr)-1); doCopyString("\pValue is invalid", theText); GetDialogItem(TheDialog, iIErrorTitle, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); doCopyString("\pNum between 2 and 10", theText); GetDialogItem(TheDialog, iIErrorText, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); do { ModalDialog(NewModalFilterProc(OurFilter), &itemHit); theErr = SetDialogDefaultItem(TheDialog, iIErrorOk); if (itemHit == iIErrorOk) { GetDialogItem(TheDialog, iIErrorValue, &iKind, &iHandle, &iRect); GetDialogItemText(iHandle, theItem); StringToNum(theItem, &amount); if ((amount > 10) || (amount < 2)) { SysBeep(1); doCopyString("\pValue is still invalid", theText); GetDialogItem(TheDialog, iIErrorValue, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); } else { InvalRect(&iRect); DisposeDialog(TheDialog); itemHit = ok; } } } while (itemHit != ok); } y=0; data.length = amount; TheDialog=GetNewDialog(dInput ,nil, (WindowPtr)-1); for(x=0; x<(amount-1); x++) { doCopyString("\pEnter Input", theText); GetDialogItem(TheDialog, iInputTitle, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); doCopyString("\pLabel", theText); GetDialogItem(TheDialog, iInputVLabel, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); doCopyString("\p0", theText); GetDialogItem(TheDialog, iInputValue, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); do { ModalDialog(NewModalFilterProc(OurFilter), &itemHit); theErr = SetDialogDefaultItem(TheDialog, iInputOk); if (itemHit == iInputOk) { /* if (1) { TheDialog2=GetNewDialog(dError,nil, (WindowPtr)-1); doCopyString("\pERROR", theText); GetDialogItem(TheDialog2, iErrorTitle, &iKind, &iHandle, &iRect); //SetDialogItemText(iHandle, theText); doCopyString("\pNo colour selected", theText); GetDialogItem(TheDialog2, iErrorMsg, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); do { ModalDialog(NewModalFilterProc(OurFilter), &itemHit2); theErr = SetDialogDefaultItem(TheDialog2, 2); if (itemHit2 == iErrorOk) { DisposeDialog(TheDialog2); itemHit2 = ok; } } while (itemHit2 != ok); } else { */ GetDialogItem(TheDialog, iInputVLabel, &iKind, &iHandle, &iRect); GetDialogItemText(iHandle, theItem); doCopyString(theItem, data.input[x].label); GetDialogItem(TheDialog, iInputValue, &iKind, &iHandle, &iRect); GetDialogItemText(iHandle, theItem); StringToNum(theItem, &amount); if ((amount < 0) || (amount >360)) { SysBeep(1); doCopyString("\pValue must be between 0 and 360", theText); GetDialogItem(TheDialog, iInputTitle, &iKind, &iHandle, &iRect); SetDialogItemText(iHandle, theText); } else { InvalRect(&iRect); data.input[x].value = amount; if (amount > data.max) data.max = amount; else if (amount < data.min) data.min = amount; data.total = data.total + amount; // DisposeDialog(TheDialog); itemHit = ok; } } else if (itemHit == iInputColour) { chooseColour(); data.input[x].colour = gOutColour; } } while (itemHit != ok); } DisposeDialog(TheDialog); InvalMenuBar(); mBarHandle = GetNewMBar(129); SetMenuBar(mBarHandle); mHandle = GetMenuHandle(mInput); DrawMenuBar(); (1 < data.length) ? EnableItem(mHandle, iInput1) : DisableItem(mHandle, iInput1); (2 < data.length) ? EnableItem(mHandle, iInput2) : DisableItem(mHandle, iInput2); (3 < data.length) ? EnableItem(mHandle, iInput3) : DisableItem(mHandle, iInput3); (4 < data.length) ? EnableItem(mHandle, iInput4) : DisableItem(mHandle, iInput4); (5 < data.length) ? EnableItem(mHandle, iInput5) : DisableItem(mHandle, iInput5); (6 < data.length) ? EnableItem(mHandle, iInput6) : DisableItem(mHandle, iInput6); (7 < data.length) ? EnableItem(mHandle, iInput7) : DisableItem(mHandle, iInput7); (8 < data.length) ? EnableItem(mHandle, iInput8) : DisableItem(mHandle, iInput8); (9 < data.length) ? EnableItem(mHandle, iInput9) : DisableItem(mHandle, iInput9); (10 < data.length) ? EnableItem(mHandle, iInput10) : DisableItem(mHandle, iInput10); doSelectGraph(); //sleep(3); //fclose(f); } break; case keyDown: TEKey(theEvent.message & charCodeMask, mainText); TEUpdate(&theRect, mainText); break; case osEvt: HiliteMenu(0); break; /* case kHighLevelEvent: AEProcessAppleEvent(&theEvent); break; case autoKey: charCode = *theEvent->message & charCodeMask; if((&theEvent->modifiers & cmdKey) != 0) doMenuChoice(MenuEvent(&theEvent)); break; */ } } fflush(stdin); fflush(stdout); fclose(f); return 0; } pascal Boolean OurFilter(DialogPtr dlg, EventRecord *event, short *itemHit) { return false; /* static Boolean isDisabled = false; ModalFilterUPP theProc; Boolean retVal; OSErr theErr = noErr; Str255 theItem; short iKind; Handle iHandle; Rect iRect; theErr = GetStdFilterProc(&theProc); if (theErr != noErr) ExitToShell(); if (!(retVal = CallModalFilterProc(theProc, dlg, event, itemHit))) { switch (event->what) { case nullEvent: break; case autoKey: retVal = false; break; case updateEvt: GetDialogItem(dlg, 2, &iKind, &iHandle, &iRect); GetDialogItemText(iHandle, theItem); isDisabled = theItem[0] == '\0'; GetDialogItem(dlg, ok, &iKind, &iHandle, &iRect); if (isDisabled) HiliteControl((ControlHandle)iHandle, 255); else HiliteControl((ControlHandle)iHandle,0); retVal = false; break; default: retVal = false; break; } } return retVal;*/ } /*intx=x+1; y+=30; MoveTo(75,135+y); DrawString("\pQuestion #"); sprintf(strx,"%i",intx); MoveTo(160,135+y); DrawString(CtoPstr(strx)); SetRect(&fieldRect[x], 180, 115+y, 280, 185+y); fields[x]= TENew(&fieldRect[x], &fieldRect[x]); TEActivate(fields[x]); TESetText(text, strlen(text), fields[x]); TEUpdate(&fieldRect[x], fields[x]); OK=GetPicture(139); SetRect(&OKRect[x], 290, 113+y, 320, 137+y); DrawPicture(OK,&OKRect[x]); click=GetPicture(138); SetRect(&picRect[5], 10, 310, 110, 370); DrawPicture(click,&picRect[5]); } while (KindaDone==1) { WaitNextEvent(everyEvent, &theEvent2, 0L, 0L); switch(theEvent2.what) { case mouseDown: GetMouse(&thePoint2); TEClick(thePoint2, FALSE, mainText); TEDeactivate(mainText); if (PtInRect(thePoint2, &picRect[2])) { KindaDone=0; } else if(PtInRect(thePoint2, &fieldRect[0])) { TEActivate(fields[0]); SetText(text, strlen(text), fields[0]); TEUpdate(&fieldRect[0], fields[0]); ForeColor(redColor); theHandle = TEGetText(fields[0]); while(SortaDone==1) { WaitNextEvent(everyEvent, &theEvent3,0L,0L); switch(theEvent3.what) { case mouseDown: { GetMouse(&thePoint3); TEClick(thePoint3, FALSE, fields[0]); if (PtInRect(thePoint3, &OKRect[0])) { MoveTo(350,130); //theHandle = TEGetText(fields[0]); sprintf(input , "%s", *theHandle); DrawString(CtoPstr(input)); TEDeactivate(fields[0]); SortaDone=0; } } case keyDown: TEKey(theEvent3.message & charCodeMask, fields[0]); TEUpdate(&fieldRect[0], fields[0]); break; } } } else if(PtInRect(thePoint2, &fieldRect[1])) { TEActivate(fields[1]); TESetText(text, strlen(text), fields[1]); TEUpdate(&fieldRect[1], fields[1]); ForeColor(redColor); theHandle = TEGetText(fields[1]); while(SortaDone==1) { WaitNextEvent(everyEvent, &theEvent3,0L,0L); switch(theEvent3.what) { case mouseDown: { GetMouse(&thePoint3); TEClick(thePoint3, FALSE, fields[1]); if (PtInRect(thePoint3, &OKRect[1])) { MoveTo(350,160); //theHandle = TEGetText(fields[1]); sprintf(input , "%s", *theHandle); TEDeactivate(fields[1]); SortaDone=0; } } case keyDown: TEKey(theEvent3.message & charCodeMask, fields[1]); TEUpdate(&fieldRect[1], fields[1]); break; } } } else if(PtInRect(thePoint2, &fieldRect[2])) { TEActivate(fields[2]); TESetText(text, strlen(text), fields[2]); TEUpdate(&fieldRect[2], fields[2]); ForeColor(redColor); theHandle = TEGetText(fields[2]); while(SortaDone==1) { WaitNextEvent(everyEvent, &theEvent3,0L,0L); switch(theEvent3.what) { case mouseDown: { GetMouse(&thePoint3); TEClick(thePoint3, FALSE, fields[2]); if (PtInRect(thePoint3, &OKRect[2])) { MoveTo(350,190); //theHandle = TEGetText(fields[2]); sprintf(input , "%s", *theHandle); TEDeactivate(fields[2]); SortaDone=0; } } case keyDown: TEKey(theEvent3.message & charCodeMask, fields[2]); TEUpdate(&fieldRect[2], fields[2]); break; } } } else if(PtInRect(thePoint2, &fieldRect[3])) { TEActivate(fields[3]); TESetText(text, strlen(text), fields[3]); TEUpdate(&fieldRect[3], fields[3]); ForeColor(redColor); theHandle = TEGetText(fields[3]); while(SortaDone==1) { WaitNextEvent(everyEvent, &theEvent3,0L,0L); switch(theEvent3.what) { case mouseDown: { GetMouse(&thePoint3); TEClick(thePoint3, FALSE, fields[3]); if (PtInRect(thePoint3, &OKRect[3])) { MoveTo(350,220); //theHandle = TEGetText(fields[3]); sprintf(input , "%s", *theHandle); TEDeactivate(fields[3]); SortaDone=0; } } case keyDown: TEKey(theEvent3.message & charCodeMask, fields[3]); TEUpdate(&fieldRect[3], fields[3]); break; } } } else if(PtInRect(thePoint2, &fieldRect[4])) { TEActivate(fields[4]); TESetText(text, strlen(text), fields[4]); TEUpdate(&fieldRect[4], fields[4]); ForeColor(redColor); theHandle = TEGetText(fields[4]); while(SortaDone==1) { WaitNextEvent(everyEvent, &theEvent3,0L,0L); switch(theEvent3.what) { case mouseDown: { GetMouse(&thePoint3); TEClick(thePoint3, FALSE, fields[4]); if (PtInRect(thePoint3, &OKRect[4])) { MoveTo(350,250); //theHandle = TEGetText(fields[4]); sprintf(input , "%s", *theHandle); TEDeactivate(fields[4]); SortaDone=0; } } case keyDown: TEKey(theEvent3.message & charCodeMask, fields[4]); TEUpdate(&fieldRect[4], fields[4]); break; } } } } }*/