Ejemplo n.º 1
0
static PyObject *Evt_GetCaretTime(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    UInt32 _rv;
#ifndef GetCaretTime
    PyMac_PRECHECK(GetCaretTime);
#endif
    if (!PyArg_ParseTuple(_args, ""))
        return NULL;
    _rv = GetCaretTime();
    _res = Py_BuildValue("l",
                         _rv);
    return _res;
}
Ejemplo n.º 2
0
Boolean MCScreenDC::open()
{
	owndnd = False;
	mouseMoveRgn = NewRgn();
	SetRectRgn(mouseMoveRgn, 0, 0, 1, 1);

	//create a invisible window, and set port to this window
	//so that later on at the very first time MC select and set font
	//will only affect in this invisible window, not other apps on the desk top,
	// when MC is first started.  The size of the window is random.
	//  Rect invisibleWinRect;
	Rect invisibleWinRect;
	SetRect(&invisibleWinRect, 0, 0, 20, 20);


	invisibleWin = NewCWindow(nil, &invisibleWinRect, "\p", False,
	                          kUtilityWindowClass, (WindowRef)(-1L), False, 0);



	long response;
	if (Gestalt(gestaltSystemVersion, &response) == noErr)
	{
		if (response >= 0x1030 && response < 0x1040)
			MCantialiasedtextworkaround = True;
		else
			MCantialiasedtextworkaround = False;
	}

	SetGWorld(GetWindowPort(invisibleWin), GetMainDevice());

	vis = new MCVisualInfo;
	
	devdepth = 32;

	black_pixel.red = black_pixel.green = black_pixel.blue = 0; //black pixel
	white_pixel.red = white_pixel.green = white_pixel.blue = 0xFFFF; //white pixel
		black_pixel.pixel = 0;
		white_pixel.pixel = 0xFFFFFF;

			redbits = greenbits = bluebits = 8;
			redshift = 16;
			greenshift = 8;
			blueshift = 0;
			vis->red_mask = 0x00FF0000;
			vis->green_mask = 0x0000FF00;
			vis->blue_mask = 0x000000FF;

	MCzerocolor = MCbrushcolor = white_pixel;
	alloccolor(MCbrushcolor);
	MCselectioncolor = MCpencolor = black_pixel;
	alloccolor(MCselectioncolor);
	alloccolor(MCpencolor);
	gray_pixel.red = gray_pixel.green = gray_pixel.blue = 0x8888;
	alloccolor(gray_pixel);
	background_pixel.red = background_pixel.green = background_pixel.blue = 0xffff;
	alloccolor(background_pixel);

	//query the system for the hilited text color, and set ours
	RGBColor hiliteRGB;
	LMGetHiliteRGB(&hiliteRGB);
	MChilitecolor.red = hiliteRGB.red;
	MChilitecolor.green = hiliteRGB.green;
	MChilitecolor.blue = hiliteRGB.blue;
	alloccolor(MChilitecolor);

	MCColor *syscolors = getaccentcolors();
	if (syscolors != NULL)
		MCaccentcolor = syscolors[4];
	else
	{
		MCaccentcolor.red = MCaccentcolor.green = 0x0000;
		MCaccentcolor.blue = 0x8080;
	}
	alloccolor(MCaccentcolor);

	grabbed = False;
	tripleclick = doubleclick = False;
	MCdoubletime = GetDblTime() * 1000 / 60;
	opened = True;
	mousewindow = new _Drawable;
	activewindow = new _Drawable;
	lastactivewindow = new _Drawable;
	mousewindow->type = activewindow->type = lastactivewindow->type = DC_WINDOW;
	mousewindow->handle.window = activewindow->handle.window
	                             = lastactivewindow->handle.window = 0;

	//get handle of application menu bar
	menuBar = GetMenuBar();
	SetMenuBar(menuBar);  //set menu bar as current menulist
	
	//create Apple menu
	appleMenu = NewMenu(mApple, "\p\024"); //menu title is an apple icon
	InsertMenuItem(appleMenu, "\pAbout...", 0);
	InsertMenu(appleMenu, 0);
	
	DrawMenuBar(); //draw the menu bar with the Apple menu
	usetemp = False;
	Handle tmem = Get1IndResource('TMEM', 1);
	if (tmem != NULL)
	{
		char *ptr = *tmem;
		if (*(ptr + 1))
			usetemp = True;
	}
	MCtemplatescrollbar->alloccolors();
	if (IsMacEmulatedLF()) // no AM
		MCtemplatebutton->allocicons();

	// preallocate these because GetItemMark can't distinguish them
	submenuIDs[0] = 1;
	submenuIDs[checkMark] = 1;
	submenuIDs[diamondMark] = 1;
	
	MCcursors[PI_NONE] = nil;
	MCblinkrate = GetCaretTime() * 1000 / 60;

	MCDisplay const *t_displays;
	getdisplays(t_displays, false);
	MCwbr = t_displays[0] . workarea;

	//TSM - INIT TSM APPLICATION AND INSTALL REQUIRED APPLEVENT HANDLERS
	TSMPositionToOffsetUPP = NewAEEventHandlerUPP(TSMPositionToOffset);
	TSMOffsetToPositionUPP = NewAEEventHandlerUPP(TSMOffsetToPosition);
	TSMUpdateHandlerUPP = NewAEEventHandlerUPP(TSMUpdateHandler);
	TSMUnicodeNotFromInputUPP
	= NewAEEventHandlerUPP(TSMUnicodeNotFromInputHandler);
	AEInstallEventHandler(kTextServiceClass, kPos2Offset,
	                      TSMPositionToOffsetUPP, 0L , False);
	AEInstallEventHandler(kTextServiceClass, kOffset2Pos,
	                      TSMOffsetToPositionUPP, 0L , False);
	AEInstallEventHandler(kTextServiceClass, kUpdateActiveInputArea,
	                      TSMUpdateHandlerUPP, 0L , False);
	AEInstallEventHandler(kTextServiceClass, kUnicodeNotFromInputMethod,
	                      TSMUnicodeNotFromInputUPP, 0L , False);
	openIME();

	dragdropUPP = NewDragReceiveHandlerUPP(DragReceiveHandler);
	InstallReceiveHandler(dragdropUPP, NULL, NULL);
	dragmoveUPP = NewDragTrackingHandlerUPP(DragTrackingHandler);
	InstallTrackingHandler(dragmoveUPP, NULL, NULL);
	
	s_animation_current_time = s_animation_start_time = CFAbsoluteTimeGetCurrent();
	
	//// Dock Menu Initialization
	
	EventTypeSpec t_menu_event_specs[1];
	t_menu_event_specs[0] . eventClass = kEventClassMenu;
	t_menu_event_specs[0] . eventKind = kEventMenuPopulate;
	
	CreateNewMenu(0, 0, &f_icon_menu);
	s_icon_menu_event_handler_upp = NewEventHandlerUPP((EventHandlerProcPtr)handleiconmenuevent);
	InstallEventHandler(GetMenuEventTarget(f_icon_menu), s_icon_menu_event_handler_upp, 1, t_menu_event_specs, NULL, NULL);
	
	t_menu_event_specs[0] . eventClass = kEventClassCommand;
	t_menu_event_specs[0] . eventKind = kEventCommandProcess;
	InstallEventHandler(GetApplicationEventTarget(), s_icon_menu_event_handler_upp, 1, t_menu_event_specs, NULL, NULL);
	
	SetApplicationDockTileMenu(f_icon_menu);
	
	//// Color Profile Initialization
	
	CMGetDefaultProfileBySpace(cmRGBData, &m_dst_profile);

	CMProfileLocation t_location;
	t_location . locType = cmPathBasedProfile;
	strcpy(t_location . u . pathLoc . path, "/System/Library/ColorSync/Profiles/sRGB Profile.icc");
	CMOpenProfile(&m_srgb_profile, &t_location);
	
	////
	
	return True;
}
Ejemplo n.º 3
0
void slowPoll( void )
	{
	RANDOM_STATE randomState;
	BYTE buffer[ RANDOM_BUFSIZE + 8 ];
	ProcessSerialNumber psn;
	GDHandle deviceHandle;
	GrafPtr currPort;
	QElemPtr queuePtr;
	QHdrPtr queueHdr;
	static BOOLEAN addedFixedItems = FALSE;

	initRandomData( randomState, buffer, RANDOM_BUFSIZE );

	/* Walk through the list of graphics devices adding information about
	   a device (IM VI 21-21) */
	deviceHandle = GetDeviceList();
	while( deviceHandle != NULL )
		{
		GDHandle currentHandle = deviceHandle;
		GDPtr devicePtr;

		HLock( ( Handle ) currentHandle );
		devicePtr = *currentHandle;
		deviceHandle = devicePtr->gdNextGD;
		addRandomData( randomState, devicePtr, sizeof( GDevice ) );
		HUnlock( ( Handle ) currentHandle );
		}

	/* Walk through the list of processes adding information about each
	   process, including the name and serial number of the process, file and
	   resource information, memory usage information, the name of the
	   launching process, launch time, and accumulated CPU time (IM VI 29-17) */
	psn.highLongOfPSN = 0;
	psn.lowLongOfPSN = kNoProcess;
	while( !GetNextProcess( &psn ) )
		{
		ProcessInfoRec infoRec;
		GetProcessInformation( &psn, &infoRec );
		addRandomData( randomState, &infoRec, sizeof( ProcessInfoRec ) );
		}

	/* Get the command type, trap address, and parameters for all commands in
	   the file I/O queue.  The parameters are quite complex and are listed
	   on page 117 of IM IV, and include reference numbers, attributes, time
	   stamps, length and file allocation information, finder info, and large
	   amounts of other volume and filesystem-related data */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
	if( ( queueHdr = GetFSQHdr() ) != NULL )
		queuePtr = queueHdr->qHead;
		while( queuePtr != NULL )
			{
			/* The queue entries are variant records of variable length so we
			   need to adjust the length parameter depending on the record
			   type */
			addRandomData( randomState, queuePtr, 32 ); /* dunno how big.. */
			queuePtr = queuePtr->qLink;
			}
#endif
	/* The following are fixed for the lifetime of the process so we only
	   add them once */
	if( !addedFixedItems )
		{
		Str255 appName, volName;
		GDHandle deviceHandle;
		Handle appHandle;
		DrvSts driveStatus;
		MachineLocation machineLocation;
		ProcessInfoRec processInfo;
		QHdrPtr vblQueue;
		SysEnvRec sysEnvirons;
		SysPPtr pramPtr;
		DefStartRec startupInfo;
		DefVideoRec videoInfo;
		DefOSRec osInfo;
		XPPParamBlock appleTalkParams;
		unsigned char *driverNames[] = {
			"\p.AIn", "\p.AOut", "\p.AppleCD", "\p.ATP", "\p.BIn", "\p.BOut", "\p.MPP",
			"\p.Print", "\p.Sony", "\p.Sound", "\p.XPP", NULL
			};
		SInt16 count, dummy, i, node, net, vRefNum, script;
		SInt32 lcount, volume;

		/* Get the current font family ID, node ID of the local AppleMumble
		   router, caret blink delay, CPU speed, double-click delay, sound
		   volume, application and system heap zone, the number of resource
		   types in the application, the number of sounds voices available,
		   the FRef of the current resource file, volume of the sysbeep,
		   primary line direction, computer SCSI disk mode ID, timeout before
		   the screen is dimmed and before the computer is put to sleep,
		   number of available threads in the thread pool, whether hard drive
		   spin-down is disabled, the handle to the i18n resources, timeout
		   time for the internal HDD, */
		addRandomValue( randomState, GetAppFont() );
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		addRandomValue( randomState, GetBridgeAddress() );
#endif
		addRandomValue( randomState, GetCaretTime() );
/*		addRandomValue( randomState, GetCPUSpeed() ); */
		addRandomValue( randomState, GetDblTime() );
		GetSysBeepVolume( &volume );
		addRandomValue( randomState, volume );
		GetDefaultOutputVolume( &volume );
		addRandomValue( randomState, volume );
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		addRandomValue( randomState, ApplicationZone() );
		addRandomValue( randomState, SystemZone() );
#endif
		addRandomValue( randomState, CountTypes() );
/*		CountVoices( &count ); ** seems to crash
		addRandomValue( randomState, count ); */
		addRandomValue( randomState, CurResFile() );
		GetSysBeepVolume( &lcount );
		addRandomValue( randomState, lcount );
		addRandomValue( randomState, GetSysDirection() );
/*		addRandomValue( randomState, GetSCSIDiskModeAddress() );
		addRandomValue( randomState, GetDimmingTimeout() );
		addRandomValue( randomState, GetSleepTimeout() ); */
		GetFreeThreadCount( kCooperativeThread, &count );
		addRandomValue( randomState, count );
/*		addRandomValue( randomState, IsSpindownDisabled() ); */
		addRandomValue( randomState, GetIntlResource( 0 ) );
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetTimeout( &count );
		addRandomValue( randomState, count );
#endif

		/* Get the number of documents/files which were selected when the app
		   started and for each document get the vRefNum, name, type, and
		   version -- OBSOLETE
		CountAppFiles( &dummy, &count );
		addRandomValue( randomState, count );
		while( count > 0 )
			{
			AppFile theFile;
			GetAppFiles( count, &theFile );
			addRandomData( randomState, &theFile, sizeof( AppFile ) );
			count--;
			} */

		/* Get the app's name, resource file reference number, and handle to
		   the finder information -- OBSOLETE
		GetAppParams( appName, appHandle, &count );
		addRandomData( randomState, appName, sizeof( Str255 ) );
		addRandomValue( randomState, appHandle );
		addRandomValue( randomState, count ); */

		/* Get all sorts of statistics such as physical information, disk and
		   write-protect present status, error status, and handler queue
		   information, on floppy drives attached to the system.  Also get
		   the volume name, volume reference number and number of bytes free,
		   for the volume in the drive */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( !DriveStatus( 1, &driveStatus ) )
			addRandomData( randomState, &driveStatus, sizeof (DrvSts) );
#endif
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( !GetVInfo( 1, volName, &vRefNum, &lcount ) )
			{
			addRandomData( randomState, volName, sizeof( Str255 ) );
			addRandomValue( randomState, vRefNum );
			addRandomValue( randomState, lcount );
			}
#endif
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( !DriveStatus( 2, &driveStatus ) )
			addRandomData( randomState, &driveStatus, sizeof (DrvSts) );
#endif
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( !GetVInfo( 2, volName, &vRefNum, &lcount ) )
			{
			addRandomData( randomState, volName, sizeof( Str255 ) );
			addRandomValue( randomState, vRefNum );
			addRandomValue( randomState, lcount );
			}
#endif
		/* Get information on the head and tail of the vertical retrace
		   queue */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( ( vblQueue = GetVBLQHdr() ) != NULL )
			addRandomData( randomState, vblQueue, sizeof( QHdr ) );
#endif
		/* Get the parameter RAM settings */
		pramPtr = GetSysPPtr();
		addRandomData( randomState, pramPtr, sizeof( SysParmType ) );

		/* Get information about the machines geographic location */
		ReadLocation( &machineLocation );
		addRandomData( randomState, &machineLocation,
					   sizeof( MachineLocation ) );

		/* Get information on current graphics devices including device
		   information such as dimensions and cursor information, and a
		   number of handles to device-related data blocks and functions, and
		   information about the dimentions and contents of the devices pixel
		   image as well as the images resolution, storage format, depth, and
		   colour usage */
		deviceHandle = GetDeviceList();
		do
			{
			GDPtr gdPtr;

			addRandomValue( randomState, deviceHandle );
			HLock( ( Handle ) deviceHandle );
			gdPtr = ( GDPtr ) *deviceHandle;
			addRandomData( randomState, gdPtr, sizeof( GDevice ) );
			addRandomData( randomState, gdPtr->gdPMap, sizeof( PixMap ) );
			HUnlock( ( Handle ) deviceHandle );
			}
		while( ( deviceHandle = GetNextDevice( deviceHandle ) ) != NULL );

		/* Get the current system environment, including the machine and
		   system software type, the keyboard type, where there's a colour
		   display attached, the AppleTalk driver version, and the VRefNum of
		   the system folder */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		SysEnvirons( curSysEnvVers, &sysEnvirons );
		addRandomData( randomState, &sysEnvirons, sizeof( SysEnvRec ) );
#endif

		/* Get the AppleTalk node ID and network number for this machine */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( GetNodeAddress( &node, &net ) )
			{
			addRandomValue( randomState, node );
			addRandomValue( randomState, net );
			}
#endif
		/* Get information on each device connected to the ADB including the
		   device handler ID, the devices ADB address, and the address of the
		   devices handler and storage area */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		count = CountADBs();
		while( count-- > 0 )
			{
			ADBDataBlock adbInfo;

			GetIndADB( &adbInfo, count );
			addRandomData( randomState, &adbInfo, sizeof( ADBDataBlock ) );
			}
#endif
		/* Open the most common device types and get the general device
		   status information and (if possible) device-specific status.  The
		   general device information contains the device handle and flags,
		   I/O queue information, event information, and other driver-related
		   details */

/* Try something like this again.. and ur a dead man, Peter ;-)
      -xmath */

/*		for( count = 0; driverNames[ count ] != NULL; count++ )
			{
			AuxDCEHandle dceHandle;
			short driverRefNum;

			** Try and open the driver **
			if( OpenDriver( driverNames[ count ], &driverRefNum ) )
				continue;

			** Get a handle to the driver control information (this could
			   also be done with GetDCtlHandle()) **
			Status( driverRefNum, 1, &dceHandle );
			HLock( dceHandle );
			addRandomData( randomState, *dceHandle,
							 sizeof( AuxDCE ) );
			HUnlock( dceHandle );
			CloseDriver( driverRefNum );
			} */

		/* Get the name and volume reference number for the current volume */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetVol( volName, &vRefNum );
		addRandomData( randomState, volName, sizeof( Str255 ) );
		addRandomValue( randomState, vRefNum );
#endif
		/* Get the time information, attributes, directory information and
		   bitmap, volume allocation information, volume and drive
		   information, pointers to various pieces of volume-related
		   information, and details on path and directory caches, for each
		   volume */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( ( queueHdr = GetVCBQHdr() ) != NULL )
			queuePtr = queueHdr->qHead;
			while ( queuePtr != NULL )
				{
				addRandomData( randomState, queuePtr, sizeof( VCB ) );
				queuePtr = queuePtr->qLink;
				}
#endif

		/* Get the driver reference number, FS type, and media size for each
		   drive */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( ( queueHdr = GetDrvQHdr() ) != NULL )
			queuePtr = queueHdr->qHead;
			while ( queuePtr != NULL )
				{
				addRandomData( randomState, queuePtr, sizeof( DrvQEl ) );
				queuePtr = queuePtr->qLink;
				}
#endif
		/* Get global script manager variables and vectors, including the
		   globals changed count, font, script, and i18n flags, various
		   script types, and cache information */
		for( count = 0; count < 30; count++ )
			addRandomValue( randomState, GetScriptManagerVariable( count ) );

		/* Get the script code for the font script the i18n script, and for
		   each one add the changed count, font, script, i18n, and display
		   flags, resource ID's, and script file information */
		script = FontScript();
		addRandomValue( randomState, script );
		for( count = 0; count < 30; count++ )
			addRandomValue( randomState, GetScriptVariable( script, count ) );
		script = IntlScript();
		addRandomValue( randomState, script );
		for( count = 0; count < 30; count++ )
			addRandomValue( randomState, GetScriptVariable( script, count ) );

		/* Get the device ID, partition, slot number, resource ID, and driver
		   reference number for the default startup device */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetDefaultStartup( &startupInfo );
		addRandomData( randomState, &startupInfo, sizeof( DefStartRec ) );
#endif
		/* Get the slot number and resource ID for the default video device */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetVideoDefault( &videoInfo );
		addRandomData( randomState, &videoInfo, sizeof( DefVideoRec ) );
#endif
		/* Get the default OS type */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetOSDefault( &osInfo );
		addRandomData( randomState, &osInfo, sizeof( DefOSRec ) );
#endif
		/* Get the AppleTalk command block and data size and number of
		   sessions */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		ASPGetParms( &appleTalkParams, FALSE );
		addRandomData( randomState, &appleTalkParams,
					   sizeof( XPPParamBlock ) );
#endif
		addedFixedItems = TRUE;
		}

	/* Flush any remaining data through */
	endRandomData( randomState, 100 );
	}
Ejemplo n.º 4
0
int
tgetch()

{
	char	ch;
	EventRecord	theEvent;
	Rect cursorRect,box,windowRect;
	long	message,cursorTime,start;
	MenuHandle	theMenu;
	register short	keyCode;
	short	temp;
	term_info	*t;
	GrafPtr	oldPort,oldPort1;
	static char nextCommand;
	short aboutBox();
	char mButtonDown();
	Point	mouseLoc;
	WindowPtr	theWindow;
	void	doUpdate();
#define	clearKey	0x47
#define ESCAPEkey	0x1B
	static int see, saw = 0;
	int eye, cursOff = 100;
	boolean cursRectInv;	/* should be a macflag */
	short	fInFront = TRUE;

	t = (term_info *)GetWRefCon(HackWindow);
	mouseLoc.h = (macflags & fMoveWRTMouse) ? t->tcur_x : (u.ux-1);
	mouseLoc.v = (macflags & fMoveWRTMouse) ? t->tcur_y : (u.uy+1);
	cursorRect.left = t->tcur_x * t->charWidth + Screen_Border;
	cursorRect.right = cursorRect.left + t->charWidth - 1;
	cursorRect.top = t->height * t->tcur_y + Screen_Border;
	cursorRect.bottom = cursorRect.top + t->height - 1;
	cursorTime = GetCaretTime();
	box.left = mouseLoc.h * t->charWidth + Screen_Border - 1;
	box.right = box.left + t->charWidth + 2;
	box.top = mouseLoc.v * t->height + Screen_Border - 1;
	box.bottom = box.top + t->height + 2;
	/* permit use of cursor keys and numeric keypad */
	/* does the same translation as in msdos.c but includes cursor keys */
	ch = '\0';
	/* handle extended command from menu */
	if (nextCommand && (macflags & (fExtCmdSeq1 | fExtCmdSeq2 | fExtCmdSeq3))) {
	    if (macflags & fExtCmdSeq1) {
		ch = '#';
		macflags = macflags ^ (fExtCmdSeq1 | fExtCmdSeq2);
	    } else if (macflags & fExtCmdSeq2) {
		ch = nextCommand;
		macflags = macflags ^ (fExtCmdSeq2 | fExtCmdSeq3);
		if (!(macflags & fExtCmdSeq3))
		    nextCommand = '\0';
	    } else if (macflags & fExtCmdSeq3) {
		ch = '\r';
		macflags &= ~fExtCmdSeq3;
	    }
	}
	GetPort(&oldPort);
	SetPort(HackWindow);
	if (!(macflags & fDoNonKeyEvt)) {
		cursorPos = -1;
		if (! flags.wantspace) SetCursor(&ARROW_CURSOR);
	}
	/* initialize cursor blinking */
	message = TickCount() + ((Invisible || (macflags & fMoveWRTMouse)) ? 0L : cursorTime);
	cursRectInv = FALSE;
	while (!ch) {
		(void)WaitNextEvent(everyEvent, &theEvent, (fInFront) ? 0L : 50L, 0L);
		if ((theEvent.what == keyDown || theEvent.what == autoKey) && (FrontWindow() == HackWindow)) {
			ch = 0;
			ObscureCursor();
			/* use raw key codes */
			keyCode = (LoWord(theEvent.message) & keyCodeMask)>>8;
 			if (keyCode == clearKey) {
				macflags = macflags ^ fToggleNumPad;
				SetWTitle(HackWindow,
					(macflags & fToggleNumPad)	? "\016NetHack [MOVE]"
												: "\015NetHack [NUM]");
				ch = 0;
				continue;
			}
			if ((macflags & fToggleNumPad) && (keyCode>0x40 &&keyCode < 0x5D) 
				|| (keyCode > 0x7A && keyCode<0x7F)) {
				ch = t->keyMap[keyCode-65];
				if ((theEvent.modifiers & shiftKey) && (ch)) {
					ch = (ch == '.') ? ':' : (char)toupper(ch);
				}
				if (ch)
					break;
			}
			if (t->system.keyBoardType < 4 && keyCode == 50) {
				ch = (char)ESCAPEkey;	/* ESC */
				break;
			}			/* make the command key = control key on all non-adb keyboards
						 Now, LEAVE it this way ! Otherwise you'll render non-us
keyboards useless, since here is where "<" and ">" are located */
			if ((theEvent.message & 0xFF) == 0x60) {
				ch = (char)ESCAPEkey;
				break;
			} /* This is the way to fix backquote->esc for all macs */
			if (theEvent.modifiers & cmdKey) {
				ch = (char)(theEvent.message & 0x1F);
				if(ch == ('Q' & 0x1F)) ch = 'Q'; /* For Quit */
				break;
			}
			if (theEvent.modifiers & optionKey) {
				for(start = 43; start < 56; start++) {
					if (t->keyMap[start] == (char)(theEvent.message & 0xFFL)) {
						ch = t->keyMap[start - 13];
						break;
					}
				}
			}
			/* not a cursor key or from the numeric keypad */
			if (!ch) {
				ch = (char)(theEvent.message & 0xFF);
			}
		} else {
		/* what other events to handle */
			switch (theEvent.what) {		
Ejemplo n.º 5
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);
    }
}