static int MyConvertEvent(EventRecord *event) { if (SIOUXIsAppWindow(FrontWindow())) { if (SIOUXHandleOneEvent(event)) return 0; return TkMacConvertEvent(event); } else { if (TkMacConvertEvent(event)) return 1; SIOUXHandleOneEvent(event); return 0; } }
void MacIdle(void) { extern logical anywarns; static long time = 0; EventRecord myEvent; WindowPtr whichWindow; #if TARGET_API_MAC_CARBON Rect tempRect; #endif char theChar; if (TickCount()<time) return; if (mac_quit_now) { anywarns = FALSE; /* kludge so that window doesn't sit around */ my_exit(1); } #if !TARGET_API_MAC_CARBON SystemTask(); #endif if (WaitNextEvent(everyEvent, &myEvent, 1, nil)) { if (!SIOUXHandleOneEvent(&myEvent)) switch (myEvent.what) { case mouseDown: switch (FindWindow(myEvent.where,&whichWindow)) { case inMenuBar: MenuSelect(myEvent.where); break; #if !TARGET_API_MAC_CARBON case inSysWindow: SystemClick(&myEvent,whichWindow); break; #endif case inContent: SelectWindow(whichWindow); break; case inDrag: #if TARGET_API_MAC_CARBON GetRegionBounds(GetGrayRgn(),&tempRect); DragWindow(whichWindow,myEvent.where,&tempRect); #else DragWindow(whichWindow,myEvent.where,&qd.screenBits.bounds); #endif break; } break; case keyDown: theChar = myEvent.message & charCodeMask; break; case updateEvt: BeginUpdate((WindowPtr) myEvent.message); EndUpdate((WindowPtr) myEvent.message); break; } } time=TickCount()+20; }
// YieldSomeTime() just cooperatively yields some time to other processes running on classic Mac OS static Boolean YieldSomeTime(UInt32 milliseconds) { extern Boolean SIOUXQuitting; EventRecord e; WaitNextEvent(everyEvent, &e, milliseconds / 17, NULL); SIOUXHandleOneEvent(&e); return(SIOUXQuitting); }
int raw_kbhit(void) { EventRecord event; // Allow SIOUX response for the mouse, drag, zoom, or resize. if (GetNextEvent(mDownMask|mUpMask,&event)) SIOUXHandleOneEvent(&event); /* Check for keystroke. */ return EventAvail(keyDownMask, &event); }
int main() { EventRecord dummyEvent; UInt8 theChar; SIOUXSettings.autocloseonquit = true; SIOUXSettings.asktosaveonclose = false; SIOUXSettings.showstatusline = true; printf( "FSCopyObject 1.5\n\n" ); printf( "This is a test application to demonstrate FSCopyObject and FSDeleteObjects.\n" ); printf( "Type 'c' to run FSCopyObject with kDupeActionStandard\n" ); printf( "Type 'R' to run FSCopyObject with kDupeActionReplace\n" ); printf( "Type 'r' to run FSCopyObject with kDupeActionRename\n" ); printf( "Type 'd' to run FSDeleteObjects\n\n" ); printf( "Type 'q' to quit\n\n" ); while( !SIOUXQuitting ) { WaitNextEvent( everyEvent, &dummyEvent, 10, NULL ); if( dummyEvent.what == keyDown ) { theChar = (UInt8) (dummyEvent.message & charCodeMask); switch( theChar ) { case 'c': TestFSCopyObject( kDupeActionStandard ); break; case 'R': TestFSCopyObject( kDupeActionReplace ); break; case 'r': TestFSCopyObject( kDupeActionRename ); break; case 'd': TestFSDeleteObjects(); break; case 'q': SIOUXQuitting = true; break; } } else { SIOUXHandleOneEvent(&dummyEvent); } } return 0; }
void doEvents(EventRecord *eventStrucPtr) { WindowRef windowRef; if (eventStrucPtr->what == mouseDown && FindWindow(eventStrucPtr->where,&windowRef) == inMenuBar) SelectWindow(SIOUXTextWindow->window); SIOUXSettings.standalone = true; if (SIOUXHandleOneEvent(eventStrucPtr)) { if (SIOUXQuitting) gDone = true; SIOUXSettings.standalone = false; return; } SIOUXSettings.standalone = false; switch(eventStrucPtr->what) { case kHighLevelEvent: AEProcessAppleEvent(eventStrucPtr); break; case mouseDown: doMouseDown(eventStrucPtr); break; case keyDown: case autoKey: break; case updateEvt: doUpdate(eventStrucPtr); break; case activateEvt: DrawGrowIcon(windowRef); break; case osEvt: doOSEvent(eventStrucPtr); break; } }
/* Return -1 if no char available, otherwise return char. * Return 3 if user hits the interrupt key (usually ^C, hence 3) * * Bug: This version does not set unbuffered mode on stdout, * so be sure to fflush(stdout) early and often... */ int raw_getc(void) { int c; EventRecord event; // Allow SIOUX response for the mouse, drag, zoom, or resize. if (GetNextEvent(mDownMask|mUpMask,&event)) SIOUXHandleOneEvent(&event); /* Check for keystroke. */ if (GetNextEvent(keyDownMask,&event)) { /* Get ASCII value of keystroke. */ c=event.message&charCodeMask; if (c=='.' && (event.modifiers&cmdKey)) { return 3; //exit(1); } return c; } return -1; /* No character avail */ }
int domultitask_( long *sleepTime ) { extern Boolean SIOUXQuitting; EventRecord myEvent; if( TickCount() > gNextCheck ) /* Time to check for events again? */ { if( WaitNextEvent( everyEvent, &myEvent, *sleepTime, NULL ) ) { /* Restore arrow while we're handling a real event */ SetCursor( &(qd.arrow) ); /* Need to do something with the event if we got one */ /* Add additional event handling code here if you need it */ SIOUXHandleOneEvent( &myEvent ); if( SIOUXQuitting ) sig_die("User interrupt; execution stopped", 1); /* Graceful quit */ } SpinMyCursor(); /* Spin the cursor */ gNextCheck = TickCount() + gTickSlice; /* Reset the tick count */ } return 1; }
int main( void ) { long result = 0; // initialize for carbon & QuickTime InitCursor(); if ( IsQuickTimeInstalled() ) EnterMovies(); else goto bail; GetQDGlobalsScreenBits( &screenBits ); Gestalt(gestaltMenuMgrAttr, &result); if (result & gestaltMenuMgrAquaLayoutMask) { // Mmmmmm...X SetMenuBar(GetNewMBar(129)); if (AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(doAEQuit), 0, false)) goto bail; } else { SetMenuBar(GetNewMBar(128)); } DrawMenuBar(); while (gDone == false) { EventRecord theEvent; WindowPtr pWhichWindow; short windowPart; Boolean SIOUXHandledEvent = false; WaitNextEvent(everyEvent, &theEvent, 0, NULL); #ifndef __MACH__ SIOUXHandledEvent = SIOUXHandleOneEvent(&theEvent); #endif if ( !SIOUXHandledEvent ) { switch (theEvent.what) { case updateEvt: pWhichWindow = (WindowPtr)theEvent.message; // we don't do anything for this simple sample BeginUpdate(pWhichWindow); EndUpdate(pWhichWindow); break; case keyDown: if (theEvent.modifiers & cmdKey) { doMenu(MenuKey(theEvent.message & charCodeMask)); } break; case mouseDown: windowPart = FindWindow(theEvent.where, &pWhichWindow); switch (windowPart) { case inDrag: DragWindow(pWhichWindow, theEvent.where, &screenBits.bounds); break; case inGoAway: if (TrackGoAway(pWhichWindow, theEvent.where)) DisposeWindow( pWhichWindow ); //gDone = true; break; case inContent: SelectWindow(pWhichWindow); break; case inMenuBar: doMenu(MenuSelect(theEvent.where)); break; } break; } } } bail: return 0; }
void main(void) { int code; int exit_code; int argc; char **argv; char dformat[64], ddevice[32]; SInt32 response; /* Initialize operating environment */ #if TARGET_API_MAC_CARBON MoreMasterPointers(224); #else MoreMasters(); #endif InitCursor(); FlushEvents(everyEvent,0); if (AEInstallEventHandler(kCoreEventClass,kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr) quitAppEventHandler), 0L,false) != noErr) ExitToShell(); gActionFunctionScrollUPP = NewControlActionUPP(&actionFunctionScroll); Gestalt(gestaltMenuMgrAttr,&response); if(response & gestaltMenuMgrAquaLayoutMask) gRunningOnX = true; /* Initialize SIOUX */ SIOUXSettings.initializeTB = false; SIOUXSettings.standalone = false; SIOUXSettings.asktosaveonclose = false; SIOUXSettings.sleep = GetCaretTime(); SIOUXSettings.userwindowtitle = "\pGhostscript"; /* Get arguments from user */ argc = ccommand(&argv); /* Show command line window */ if (InstallConsole(0)) ExitToShell(); /* Part of fudge to make SIOUX accept characters without becoming modal */ SelectWindow(SIOUXTextWindow->window); PostEvent(keyDown, 0x4c00); // Enter ReadCharsFromConsole(dformat, 0x7FFF); clrscr(); /* Add in the display format as the first command line argument */ if (argc >= MAX_ARGS - 1) { printf("Too many command line arguments\n"); return; } memmove(&argv[3], &argv[1], (argc-1) * sizeof(char**)); argc += 2; argv[1] = ddevice; argv[2] = dformat; gs_sprintf(ddevice, "-sDEVICE=display"); gs_sprintf(dformat, "-dDisplayFormat=%d", display_format); /* Run Ghostscript */ if (gsapi_new_instance(&instance, NULL) < 0) { printf("Can't create Ghostscript instance\n"); return; } #ifdef DEBUG visual_tracer_init(); set_visual_tracer(&visual_tracer); #endif gsapi_set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr); gsapi_set_poll(instance, gsdll_poll); gsapi_set_display_callback(instance, &display); code = gsapi_init_with_args(instance, argc, argv); if (code == 0) code = gsapi_run_string(instance, start_string, 0, &exit_code); else { printf("Failed to initialize. Error %d.\n", code); fflush(stdout); } code = gsapi_exit(instance); if (code != 0) { printf("Failed to terminate. Error %d.\n", code); fflush(stdout); } gsapi_delete_instance(instance); #ifdef DEBUG visual_tracer_close(); #endif /* Ghostscript has finished - let user see output before quitting */ WriteCharsToConsole("\r[Finished - hit any key to quit]", 33); fflush(stdout); /* Process events until a key is hit or user quits from menu */ while(!gDone) { EventRecord eventStructure; if(WaitNextEvent(everyEvent,&eventStructure,SIOUXSettings.sleep,NULL)) { if (eventStructure.what == keyDown) gDone = true; doEvents(&eventStructure); } else SIOUXHandleOneEvent(&eventStructure); } }
/* This function is a fudge which allows the SIOUX window to be waiting for input and not be modal at the same time. (Why didn't MetroWerks think of that?) It is based on the SIOUX function ReadCharsFromConsole(), and contains an event loop which allows other windows to be active. It collects characters up to when the user presses ENTER, stores the complete buffer and gives as much to the calling function as it wants until it runs out, at which point it gets another line (or set of lines if pasting from the clipboard) from the user. */ static size_t get_input(void *ptr, size_t size) { EventRecord eventStructure; long charswaiting, old_charswaiting = 0; char *text; #if SIOUX_USE_WASTE Handle textHandle; #endif /* If needing more input, set edit start position */ if (!stdin_buf) #if SIOUX_USE_WASTE SIOUXselstart = WEGetTextLength(SIOUXTextWindow->edit); #else SIOUXselstart = (*SIOUXTextWindow->edit)->teLength; #endif /* Wait until user presses exit (or quits) */ while(!gDone && !stdin_buf) { #if SIOUX_USE_WASTE charswaiting = WEGetTextLength(SIOUXTextWindow->edit) - SIOUXselstart; #else if ((*SIOUXTextWindow->edit)->teLength > 0) charswaiting = (*SIOUXTextWindow->edit)->teLength - SIOUXselstart; else charswaiting = ((unsigned short) (*SIOUXTextWindow->edit)->teLength) - SIOUXselstart; #endif /* If something has happened, see if we need to do anything */ if (charswaiting != old_charswaiting) { #if SIOUX_USE_WASTE textHandle = WEGetText(SIOUXTextWindow->edit); HLock(textHandle); text = *textHandle + SIOUXselstart; #else text = (*(*SIOUXTextWindow->edit)->hText) + SIOUXselstart; #endif /* If user has pressed enter, gather up the buffer ready for returning */ if (text[charswaiting-1] == '\r') { stdin_buf = malloc(charswaiting); if (!stdin_buf) return -1; stdin_bufsize = charswaiting; memcpy(stdin_buf, text, stdin_bufsize); SIOUXselstart += charswaiting; text = stdin_buf; while (text = memchr(text, '\r', charswaiting - (text - stdin_buf))) *text = '\n'; } #if SIOUX_USE_WASTE HUnlock(textHandle); #endif old_charswaiting = charswaiting; if (stdin_buf) break; } /* Wait for next event and process it */ SIOUXState = SCANFING; if(WaitNextEvent(everyEvent, &eventStructure, SIOUXSettings.sleep ,NULL)) doEvents(&eventStructure); else SIOUXHandleOneEvent(&eventStructure); SIOUXState = IDLE; } /* If data has been entered, return as much as has been requested */ if (stdin_buf && !gDone) { if (size >= stdin_bufsize - stdin_bufpos) { size = stdin_bufsize - stdin_bufpos; memcpy (ptr, stdin_buf + stdin_bufpos, size); free(stdin_buf); stdin_buf = NULL; stdin_bufpos = 0; stdin_bufsize = 0; } else { memcpy (ptr, stdin_buf + stdin_bufpos, size); stdin_bufpos += size; } return size; } else if (stdin_buf) { free(stdin_buf); stdin_buf = NULL; stdin_bufpos = 0; stdin_bufsize = 0; } return 0; }