Esempio n. 1
0
static OSErr QT_AddUserDataTextToMovie (Movie theMovie, char *theText, OSType theType)
{
	UserData					myUserData = NULL;
	Handle						myHandle = NULL;
	long						myLength = strlen(theText);
	OSErr						myErr = noErr;

	// get the movie's user data list
	myUserData = GetMovieUserData(theMovie);
	if (myUserData == NULL)
		return(paramErr);
	
	// copy the specified text into a new handle
	myHandle = NewHandleClear(myLength);
	if (myHandle == NULL)
		return(MemError());

	BlockMoveData(theText, *myHandle, myLength);

	// add the data to the movie's user data
	myErr = AddUserDataText(myUserData, myHandle, theType, 1, (short)GetScriptManagerVariable(smRegionCode));

	// clean up
	DisposeHandle(myHandle);
	return(myErr);
}
Esempio n. 2
0
static void
InitKeyMaps()
{
    Tcl_HashEntry *hPtr;
    KeyInfo *kPtr;
    int dummy;
		
    Tcl_InitHashTable(&keycodeTable, TCL_ONE_WORD_KEYS);
    for (kPtr = keyArray; kPtr->keycode != 0; kPtr++) {
	hPtr = Tcl_CreateHashEntry(&keycodeTable, (char *) kPtr->keycode,
		&dummy);
	Tcl_SetHashValue(hPtr, kPtr->keysym);
    }
    Tcl_InitHashTable(&vkeyTable, TCL_ONE_WORD_KEYS);
    for (kPtr = vituralkeyArray; kPtr->keycode != 0; kPtr++) {
	hPtr = Tcl_CreateHashEntry(&vkeyTable, (char *) kPtr->keycode,
		&dummy);
	Tcl_SetHashValue(hPtr, kPtr->keysym);
    }
    KCHRPtr = (Ptr) GetScriptManagerVariable(smKCHRCache);
    if (!KCHRPtr){
        fprintf(stderr,"GetScriptManagerVariable failed\n");
    }
    initialized = 1;
}
Esempio n. 3
0
static void
InitLatin1Table(
    Display *display)
{
    static Boolean latin1_initialized = false;
    static SInt16 lastKeyLayoutID = -1;

    SInt16 keyScript;
    SInt16 keyLayoutID;

    keyScript = GetScriptManagerVariable(smKeyScript);
    keyLayoutID = GetScriptVariable(keyScript,smScriptKeys);

    if (!latin1_initialized || (lastKeyLayoutID != keyLayoutID)) {
        int keycode;
        KeySym keysym;
        int state;
        int modifiers;

        latin1_initialized = true;
        lastKeyLayoutID = keyLayoutID;

        memset(latin1Table, 0, sizeof(latin1Table));
        
        /*
         * In the common X11 implementations, a keymap has four columns
         * "plain", "Shift", "Mode_switch" and "Mode_switch + Shift".  We
         * don't use "Mode_switch", but we use "Option" instead.  (This is
         * similar to Apple's X11 implementation, where "Mode_switch" is used
         * as an alias for "Option".)
         *
         * So here we go through all 4 columns of the keymap and find all
         * Latin-1 compatible keycodes.  We go through the columns
         * back-to-front from the more exotic columns to the more simple, so
         * that simple keycode-modifier combinations are preferred in the
         * resulting table.
         */

        for (state = 3; state >= 0; state--) {
            modifiers = 0;
            if (state & 1) {
                modifiers |= shiftKey;
            }
            if (state & 2) {
                modifiers |= optionKey;
            }

            for (keycode = 0; keycode <= MAC_KEYCODE_MAX; keycode++) {
                keysym = XKeycodeToKeysym(display,keycode<<16,state);
                if (keysym <= LATIN1_MAX) {
                    latin1Table[keysym] = keycode | modifiers;
                }
            }
        }
    }
}
static GHOST_TKey convertKey(int rawCode) 
{	
	/* This bit of magic converts the rawCode into a virtual
	 * Mac key based on the current keyboard mapping, but
	 * without regard to the modifiers (so we don't get 'a'
	 * and 'A' for example.
	 */
	static UInt32 dummy = 0;
	Handle transData = (Handle) GetScriptManagerVariable(smKCHRCache);
	unsigned char vk = KeyTranslate(transData, rawCode, &dummy);
	/* Map numpad based on rawcodes first, otherwise they
	 * look like non-numpad events.
	 * Added too: mapping the number keys, for french keyboards etc (ton)
	 */
	// printf("GHOST: vk: %d %c raw: %d\n", vk, vk, rawCode);
		 
	switch (rawCode) {
		case 18:    return GHOST_kKey1;
		case 19:    return GHOST_kKey2;
		case 20:    return GHOST_kKey3;
		case 21:    return GHOST_kKey4;
		case 23:    return GHOST_kKey5;
		case 22:    return GHOST_kKey6;
		case 26:    return GHOST_kKey7;
		case 28:    return GHOST_kKey8;
		case 25:    return GHOST_kKey9;
		case 29:    return GHOST_kKey0;

		case 82:    return GHOST_kKeyNumpad0;
		case 83:    return GHOST_kKeyNumpad1;
		case 84:    return GHOST_kKeyNumpad2;
		case 85:    return GHOST_kKeyNumpad3;
		case 86:    return GHOST_kKeyNumpad4;
		case 87:    return GHOST_kKeyNumpad5;
		case 88:    return GHOST_kKeyNumpad6;
		case 89:    return GHOST_kKeyNumpad7;
		case 91:    return GHOST_kKeyNumpad8;
		case 92:    return GHOST_kKeyNumpad9;
		case 65:    return GHOST_kKeyNumpadPeriod;
		case 76:    return GHOST_kKeyNumpadEnter;
		case 69:    return GHOST_kKeyNumpadPlus;
		case 78:    return GHOST_kKeyNumpadMinus;
		case 67:    return GHOST_kKeyNumpadAsterisk;
		case 75:    return GHOST_kKeyNumpadSlash;
	}
	
	if ((vk >= 'a') && (vk <= 'z')) {
		return (GHOST_TKey) (vk - 'a' + GHOST_kKeyA);
	}
	else if ((vk >= '0') && (vk <= '9')) {
		return (GHOST_TKey) (vk - '0' + GHOST_kKey0);
	}
	else if (vk == 16) {
		switch (rawCode) {
			case 122:   return GHOST_kKeyF1;
			case 120:   return GHOST_kKeyF2;
			case 99:    return GHOST_kKeyF3;
			case 118:   return GHOST_kKeyF4;
			case 96:    return GHOST_kKeyF5;
			case 97:    return GHOST_kKeyF6;
			case 98:    return GHOST_kKeyF7;
			case 100:   return GHOST_kKeyF8;
			case 101:   return GHOST_kKeyF9;
			case 109:   return GHOST_kKeyF10;
			case 103:   return GHOST_kKeyF11;
			case 111:   return GHOST_kKeyF12; // Never get, is used for ejecting the CD!
		}
	}
	else {
		switch (vk) {
			case kUpArrowCharCode:      return GHOST_kKeyUpArrow;
			case kDownArrowCharCode:    return GHOST_kKeyDownArrow;
			case kLeftArrowCharCode:    return GHOST_kKeyLeftArrow;
			case kRightArrowCharCode:   return GHOST_kKeyRightArrow;

			case kReturnCharCode:       return GHOST_kKeyEnter;
			case kBackspaceCharCode:    return GHOST_kKeyBackSpace;
			case kDeleteCharCode:       return GHOST_kKeyDelete;
			case kEscapeCharCode:       return GHOST_kKeyEsc;
			case kTabCharCode:          return GHOST_kKeyTab;
			case kSpaceCharCode:        return GHOST_kKeySpace;

			case kHomeCharCode:         return GHOST_kKeyHome;
			case kEndCharCode:          return GHOST_kKeyEnd;
			case kPageUpCharCode:       return GHOST_kKeyUpPage;
			case kPageDownCharCode:     return GHOST_kKeyDownPage;

			case '-':   return GHOST_kKeyMinus;
			case '=':   return GHOST_kKeyEqual;
			case ',':   return GHOST_kKeyComma;
			case '.':   return GHOST_kKeyPeriod;
			case '/':   return GHOST_kKeySlash;
			case ';':   return GHOST_kKeySemicolon;
			case '\'':  return GHOST_kKeyQuote;
			case '\\':  return GHOST_kKeyBackslash;
			case '[':   return GHOST_kKeyLeftBracket;
			case ']':   return GHOST_kKeyRightBracket;
			case '`':   return GHOST_kKeyAccentGrave;
		}
	}
	
	// printf("GHOST: unknown key: %d %d\n", vk, rawCode);
	
	return GHOST_kKeyUnknown;
}
Esempio n. 5
0
// This method handles common code for SendKeyDown, SendKeyUp, and SendChar events.
void wxApp::MacCreateKeyEvent( wxKeyEvent& event, wxWindow* focus , long keymessage , long modifiers , long when , wxChar uniChar )
{
#if wxOSX_USE_COCOA_OR_CARBON
    
    short keycode, keychar ;

    keychar = short(keymessage & charCodeMask);
    keycode = short(keymessage & keyCodeMask) >> 8 ;
    if ( !(event.GetEventType() == wxEVT_CHAR) && (modifiers & (controlKey | shiftKey | optionKey) ) )
    {
        // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
        // and look at the character after
#ifdef __LP64__
        // TODO new implementation using TextInputSources
#else
        UInt32 state = 0;
        UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey | shiftKey | optionKey))) | keycode, &state);
        keychar = short(keyInfo & charCodeMask);
#endif
    }

    long keyval = wxMacTranslateKey(keychar, keycode) ;
    if ( keyval == keychar && ( event.GetEventType() == wxEVT_KEY_UP || event.GetEventType() == wxEVT_KEY_DOWN ) )
        keyval = wxToupper( keyval ) ;

    // Check for NUMPAD keys.  For KEY_UP/DOWN events we need to use the
    // WXK_NUMPAD constants, but for the CHAR event we want to use the
    // standard ascii values
    if ( event.GetEventType() != wxEVT_CHAR )
    {
        if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92)
        {
            keyval = (keyval - '0') + WXK_NUMPAD0;
        }
        else if (keycode >= 65 && keycode <= 81)
        {
            switch (keycode)
            {
                case 76 :
                    keyval = WXK_NUMPAD_ENTER;
                    break;

                case 81:
                    keyval = WXK_NUMPAD_EQUAL;
                    break;

                case 67:
                    keyval = WXK_NUMPAD_MULTIPLY;
                    break;

                case 75:
                    keyval = WXK_NUMPAD_DIVIDE;
                    break;

                case 78:
                    keyval = WXK_NUMPAD_SUBTRACT;
                    break;

                case 69:
                    keyval = WXK_NUMPAD_ADD;
                    break;

                case 65:
                    keyval = WXK_NUMPAD_DECIMAL;
                    break;
                default:
                    break;
            }
        }
    }

    event.m_shiftDown = modifiers & shiftKey;
    event.m_rawControlDown = modifiers & controlKey;
    event.m_altDown = modifiers & optionKey;
    event.m_controlDown = modifiers & cmdKey;
    event.m_keyCode = keyval ;
#if wxUSE_UNICODE
    event.m_uniChar = uniChar ;
#endif

    event.m_rawCode = keymessage;
    event.m_rawFlags = modifiers;
    event.SetTimestamp(when);
    event.SetEventObject(focus);
#else
    wxUnusedVar(event);
    wxUnusedVar(focus);
    wxUnusedVar(keymessage);
    wxUnusedVar(modifiers);
    wxUnusedVar(when);
    wxUnusedVar(uniChar);
#endif
}
OSStatus CL_DisplayWindow_OpenGL::on_window_event(EventHandlerCallRef call_ref, EventRef event_ref, void *user_data)
{
	CL_DisplayWindow_OpenGL *self = (CL_DisplayWindow_OpenGL *) user_data;

	OSStatus result = CallNextEventHandler(call_ref, event_ref);

	UInt32 event_class = GetEventClass(event_ref);
	UInt32 event_kind = GetEventKind(event_ref);
	
	if (event_class == kEventClassKeyboard)
	{
		Point mouse_pos;
		UInt32 key_modifiers = 0;
		UInt32 click_count = 0;
		UInt32 key_code = 0;
                
		// Todo:
		// KeyboardLayoutRef layout;
		// KLGetCurrentKeyboardLayout(&layout);
		// KLGetKeyboardLayoutProperty(layout, kKLuchrData, &data);
		// call UCKeyTranslate to get unicode string for keys being pressed.

		GetMouse(&mouse_pos);
		GetEventParameter(event_ref, kEventParamKeyModifiers, typeUInt32, 0, sizeof(UInt32), 0, &key_modifiers);
		GetEventParameter(event_ref, kEventParamKeyCode, typeUInt32, 0, sizeof(UInt32), 0, &key_code);
		GetEventParameter(event_ref, kEventParamClickCount, typeUInt32, 0, sizeof(UInt32), 0, &click_count);

		if (!self->fullscreen) {
			Rect wbounds;
			GetWindowBounds(self->window_ref, kWindowContentRgn, &wbounds);
			mouse_pos.h -= wbounds.left;
			mouse_pos.v -= wbounds.top;
		}

		static unsigned long state = 0;
		static Ptr keymap = nil;
		Ptr new_keymap;

		// Get the current keyboard map resource
		new_keymap = (Ptr)GetScriptManagerVariable(smKCHRCache);
		if (new_keymap != keymap)
		{
			keymap = new_keymap;
			state = 0;
		}

		CL_InputEvent event;
		event.str = KeyTranslate(keymap, key_code|key_modifiers, &state) & 0xffff;
		event.device = self->keyboard;
		event.mouse_pos = CL_Point(mouse_pos.h, mouse_pos.v);
		event.repeat_count = click_count;

		self->mouse_pos = event.mouse_pos; // if kEventParamMouseLocation is not valid here, reverse this.
		
		switch (event_kind)
		{
		case kEventRawKeyModifiersChanged:
			{
				std::set<int> current_keys = modifiercode_to_clkeys(key_modifiers);
				for (std::set<int>::iterator i=current_keys.begin(); i!=current_keys.end(); i++)
				{
					if (!self->prev_modifier_keys.count(*i))
					{
						event.id = *i;
						event.type = CL_InputEvent::pressed;
						self->keyboard.sig_key_down().call(event);
					}
				}
				for (std::set<int>::iterator i=self->prev_modifier_keys.begin(); i!=self->prev_modifier_keys.end(); i++)
				{
					if (!current_keys.count(*i))
					{
						event.id = *i;
						event.type = CL_InputEvent::released;
						self->keyboard.sig_key_up().call(event);
					}
				}
				self->prev_modifier_keys = current_keys;
				return noErr;
			}
		
		case kEventRawKeyDown:
			// first tests for cmd-q(12) or cmd-w(13) to close the window if needed
			if ((key_modifiers & cmdKey) && (key_code==12 || key_code==13))
			{
				EventRef close_event;
				CreateEvent(NULL, kEventClassWindow, kEventWindowClose, 0, kEventAttributeNone, &close_event);
				EventTargetRef target = GetWindowEventTarget(self->window_ref);
				SendEventToEventTarget(close_event, target);
				return noErr;
			}
			else
			{
				event.id = keycode_to_clkey(key_code);
				event.type = CL_InputEvent::pressed;
				self->keyboard.sig_key_down().call(event);
				return noErr;
			}
			
		case kEventRawKeyRepeat:
			event.id = keycode_to_clkey(key_code);
			event.type = CL_InputEvent::pressed;
			self->keyboard.sig_key_down().call(event);
			return noErr;
			
		case kEventRawKeyUp:
			event.id = keycode_to_clkey(key_code);
			event.type = CL_InputEvent::released;
			self->keyboard.sig_key_up().call(event);
			return noErr;
		}
	}
	else if (event_class == kEventClassMouse)
	{
		Point mouse_pos;
		EventMouseButton mouse_button;
		UInt32 key_modifiers = 0;

		GetEventParameter(event_ref, kEventParamMouseLocation, typeQDPoint, 0, sizeof(Point), 0, &mouse_pos);
		GetEventParameter(event_ref, kEventParamMouseButton, typeMouseButton, 0, sizeof(EventMouseButton), 0, &mouse_button);
		GetEventParameter(event_ref, kEventParamKeyModifiers, typeUInt32, 0, sizeof(UInt32), 0, &key_modifiers);
				
		if (!self->fullscreen) {
			Rect wbounds;
			GetWindowBounds(self->window_ref, kWindowContentRgn, &wbounds);
			mouse_pos.h -= wbounds.left;
			mouse_pos.v -= wbounds.top;
		}

		CL_InputEvent event;
		event.id = mouse_button-1;
		event.device = self->mouse;
		event.mouse_pos = CL_Point(mouse_pos.h, mouse_pos.v);

		// Simulate second mouse button.
		if ((key_modifiers & controlKey) && (event.id == CL_MOUSE_LEFT))
			event.id = CL_MOUSE_RIGHT;

		self->mouse_pos = event.mouse_pos;

		switch (event_kind)
		{
		case kEventMouseDown:
			self->mouse_states[event.id] = true;
			event.type = CL_InputEvent::pressed;
			self->mouse.sig_key_down().call(event);
			return noErr;
			
		case kEventMouseUp:
			self->mouse_states[event.id] = false;
			event.type = CL_InputEvent::released;
			self->mouse.sig_key_up().call(event);
			return noErr;
			
		case kEventMouseMoved:
		case kEventMouseDragged:
			self->mouse.sig_pointer_move().call(event);
			return noErr;

		case kEventMouseWheelMoved:
			//Note, this is not properly handling large quick wheel movements, but the implementation on other
			//platforms don't seem to either so I will do it their way for consistancy - mrfun
			
			EventMouseWheelAxis axis;
			GetEventParameter(event_ref, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis);

			if (axis == kEventMouseWheelAxisY)
			{
			
			long wheel_delta = 0;
			GetEventParameter(event_ref, kEventParamMouseWheelDelta, typeLongInteger, 0, sizeof(long), 0, &wheel_delta);
			
			//Ok, let me explain this bIgnoreThisOne thing.  We are being passed two identical wheel events for every wheel movement -
			//This behavior is also in the apple example app GLCarbonAGLWindow and I can't figure out a way to get it to send only one
			//event or a difference in the events. (like a press and release tag differentiating them)

			//So the hack solution is to simply ignore every other mouse wheel event.  This way, programs behave the same on every
			//platform instead of wheel zooming being twice as fast on macs.

			//If anybody has a better solution or finds a problem here please feel free to dig in. -mrfun
			
			static bool bIgnoreThisOne = true;
			bIgnoreThisOne = !bIgnoreThisOne;
			
			if (bIgnoreThisOne)
				if (wheel_delta)
				{
					if (wheel_delta > 0)
					{
						event.id = CL_MOUSE_WHEEL_UP;
					} else
					{
						event.id = CL_MOUSE_WHEEL_DOWN;
					}
			
					//sending both the down and up event, like the linux version
					event.type = CL_InputEvent::pressed;
					self->mouse.sig_key_down().call(event);
					event.type = CL_InputEvent::released;
					self->mouse.sig_key_up().call(event);
				} else
				{
				//handle the X axis someday?
				}
			}
			
			return noErr;
		}
	}
	else if (event_class == kEventClassWindow)
	{
		switch (event_kind)
		{
		case kEventWindowCollapsing:
			break;

		case kEventWindowDrawContent:
			{
				if (!self->fullscreen) 
				{
					Rect rectPort;
					GetWindowPortBounds(self->window_ref, &rectPort);
					self->sig_paint(
						CL_Rect(
							rectPort.left,
							rectPort.top,
							rectPort.right,
							rectPort.bottom));
				}
			}
			break;
			
		case kEventWindowShown: // called on initial show (not on un-minimize)
			break;
			
		case kEventWindowClose:
			self->sig_window_close();
			return noErr;

		case kEventWindowActivated:
		case kEventWindowFocusAcquired:
			self->focus = true;
			self->sig_got_focus();
			return noErr;
			
		case kEventWindowDeactivated:
		case kEventWindowFocusRelinquish:
			self->focus = false;
			self->sig_lost_focus();
			return noErr;
			
		case kEventWindowBoundsChanged:
			{
				if (!self->fullscreen) {
					Rect rectPort;
					GetWindowPortBounds (self->window_ref, &rectPort);
					self->set_size(rectPort.right-rectPort.left, rectPort.bottom-rectPort.top);
				}
			}
			return noErr;
			
		case kEventWindowZoomed:
			// when maximized, but kEventWindowBoundsChanged is also called
			break;
		}
	}

	return result;
}
Esempio n. 7
0
KeyID
OSXKeyState::KeyResource::getKeyID(UInt8 c)
{
	if (c == 0) {
		return kKeyNone;
	}
	else if (c >= 32 && c < 127) {
		// ASCII
		return static_cast<KeyID>(c);
	}
	else {
		// handle special keys
		switch (c) {
		case 0x01:
			return kKeyHome;

		case 0x02:
			return kKeyKP_Enter;

		case 0x03:
			return kKeyKP_Enter;

		case 0x04:
			return kKeyEnd;

		case 0x05:
			return kKeyHelp;

		case 0x08:
			return kKeyBackSpace;

		case 0x09:
			return kKeyTab;

		case 0x0b:
			return kKeyPageUp;

		case 0x0c:
			return kKeyPageDown;

		case 0x0d:
			return kKeyReturn;

		case 0x10:
			// OS X maps all the function keys (F1, etc) to this one key.
			// we can't determine the right key here so we have to do it
			// some other way.
			return kKeyNone;

		case 0x1b:
			return kKeyEscape;

		case 0x1c:
			return kKeyLeft;

		case 0x1d:
			return kKeyRight;

		case 0x1e:
			return kKeyUp;

		case 0x1f:
			return kKeyDown;

		case 0x7f:
			return kKeyDelete;

		case 0x06:
		case 0x07:
		case 0x0a:
		case 0x0e:
		case 0x0f:
		case 0x11:
		case 0x12:
		case 0x13:
		case 0x14:
		case 0x15:
		case 0x16:
		case 0x17:
		case 0x18:
		case 0x19:
		case 0x1a:
			// discard other control characters
			return kKeyNone;

		default:
			// not special or unknown
			break;
		}

		// create string with character
		char str[2];
		str[0] = static_cast<char>(c);
		str[1] = 0;

#if defined(MAC_OS_X_VERSION_10_5)
		// get current keyboard script
		TISInputSourceRef isref = TISCopyCurrentKeyboardInputSource();
		CFArrayRef langs = (CFArrayRef) TISGetInputSourceProperty(isref, kTISPropertyInputSourceLanguages);
		CFStringEncoding encoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)CFArrayGetValueAtIndex(langs, 0));
#else
		CFStringEncoding encoding = GetScriptManagerVariable(smKeyScript);
#endif
		// convert to unicode
		CFStringRef cfString =
			CFStringCreateWithCStringNoCopy(
				kCFAllocatorDefault, str, encoding, kCFAllocatorNull);

		// sometimes CFStringCreate...() returns NULL (e.g. Apple Korean
		// encoding with char value 214).  if it did then make no key,
		// otherwise CFStringCreateMutableCopy() will crash.
		if (cfString == NULL) {
			return kKeyNone; 
		}

		// convert to precomposed
		CFMutableStringRef mcfString =
			CFStringCreateMutableCopy(kCFAllocatorDefault, 0, cfString);
		CFRelease(cfString);
		CFStringNormalize(mcfString, kCFStringNormalizationFormC);

		// check result
		int unicodeLength = CFStringGetLength(mcfString);
		if (unicodeLength == 0) {
			CFRelease(mcfString);
			return kKeyNone;
		}
		if (unicodeLength > 1) {
			// FIXME -- more than one character, we should handle this
			CFRelease(mcfString);
			return kKeyNone;
		}

		// get unicode character
		UniChar uc = CFStringGetCharacterAtIndex(mcfString, 0);
		CFRelease(mcfString);

		// convert to KeyID
		return static_cast<KeyID>(uc);
	}
}
Esempio n. 8
0
OP_STATUS UKeyTranslate::GetUnicharFromVirtualKey(UInt32 virtualKeyCode, uni_char &outUniChar, UInt8 modifierKeyState)
{
#ifdef SIXTY_FOUR_BIT
	UInt32 deadKeyState = 0;
	OP_STATUS result = OpStatus::ERR;
	TISInputSourceRef kbInputSourceRef = TISCopyCurrentKeyboardLayoutInputSource();
	CFDataRef uchrDataRef = (CFDataRef)TISGetInputSourceProperty(kbInputSourceRef, kTISPropertyUnicodeKeyLayoutData);
	Boolean existsUchr = ((uchrDataRef != NULL) && (CFDataGetBytePtr(uchrDataRef) != NULL) && (CFDataGetLength(uchrDataRef) != 0));
	if (existsUchr)
	{
		UniCharCount actualLength = 0;
		UniChar outChar[2] = {0,0};

		OSStatus status = UCKeyTranslate((const UCKeyboardLayout *)CFDataGetBytePtr(uchrDataRef),
										 virtualKeyCode, kUCKeyActionDown,
										 modifierKeyState, LMGetKbdType(), kNilOptions,
										 &deadKeyState, 2, &actualLength, outChar);
		if (status == noErr && actualLength && outChar[0] != kFunctionKeyCharCode)
		{
			outUniChar = outChar[0];
			result = OpStatus::OK;
		}
	}
	CFRelease(kbInputSourceRef);

	return result;
#else	// !SIXTY_FOUR_BIT
	static KeyboardLayoutRef lastKbdLayout = 0;
	static const UCKeyboardLayout* ucharData = NULL;
	static const void* charData = NULL;
	KeyboardLayoutRef currentKbdLayout = 0;

	if (noErr != KLGetCurrentKeyboardLayout(&currentKbdLayout) || !currentKbdLayout)
	{
		return OpStatus::ERR;
	}

	short	keyCode;
	OSStatus error = noErr;
	UInt32 deadKeyState = 0;
	OP_STATUS result = OpStatus::ERR;

	keyCode = virtualKeyCode;

	if (!ucharData || (currentKbdLayout != lastKbdLayout))
	{
		// Don't fetch this unless we have to: Because of the KeyScript issue handled below this may in some cases return 0
		// KeyScript is an EXPENSIVE call, so by caching ucharData as long as possible we minimise the number of times
		// we need to call it.
		error = KLGetKeyboardLayoutProperty(currentKbdLayout, kKLuchrData, (const void**)&ucharData);
	}
	if (!ucharData)
	{
		static Boolean try_again = true;
		if (try_again && (smRoman == GetScriptManagerVariable(smKeyScript)))
		{
			// This is required for roman scripts in order to get something from KLGetCurrentKeyboardLayout
			KeyScript(smRoman | smKeyForceKeyScriptMask);
			error = KLGetKeyboardLayoutProperty(currentKbdLayout, kKLuchrData, (const void**)&ucharData);
			if (error || !ucharData)
				try_again = false;
		}
	}

	if ((error == noErr) && (ucharData != 0))
	{
		UniCharCount actualLength = 0;
		UniChar outChar[2] = {0,0};
		charData = NULL;
		error = UCKeyTranslate(ucharData, (unsigned short)keyCode,
									kUCKeyActionDown, modifierKeyState, LMGetKbdType(), 0,
									&deadKeyState, 2, &actualLength, outChar);
		if (error == noErr && actualLength && outChar[0] != kFunctionKeyCharCode)
		{
			outUniChar = outChar[0];
			result = OpStatus::OK;
#ifdef DEBUG_UNI_KEYSTROKES
//			if (outUniChar & 0xff00)
//				fprintf(stderr, "UKC:%x\n", outChar[0]);
#endif
		}
#ifdef DEBUG_UNI_KEYSTROKES
		else
		{
			fprintf(stderr, "UKCe:%li-%x-%lu-%x\n", error, outChar[0], virtualKeyCode, modifierKeyState);
		}
		if (actualLength != 1)
			fprintf(stderr, "UKCl:%lu-%x-%x-%lu-%x\n", actualLength, outChar[0], outChar[1], virtualKeyCode, modifierKeyState);
#endif
	}
	else
	{
#ifdef DEBUG_UNI_KEYSTROKES
		fprintf(stderr, "KLP:%li\n", error);
#endif
		error = noErr;
		if (!charData || (currentKbdLayout != lastKbdLayout))
		{
			error = KLGetKeyboardLayoutProperty(currentKbdLayout, kKLKCHRData, &charData);
		}
		if ((error == noErr) && (charData != 0))
		{
			unsigned long charcs = KeyTranslate(charData, (keyCode & 0xFF) | (modifierKeyState << 8), &deadKeyState);
			if (charcs & 0xFF)
			{
				char src = charcs & 0x00FF;
				gTextConverter->ConvertBufferFromMac(&src, 1, &outUniChar, 1);
				result = OpStatus::OK;
			}
#ifdef DEBUG_UNI_KEYSTROKES
			else
			{
				fprintf(stderr, "KTe\n", outUniChar);
			}
			if (charcs & 0xFF0000)
			{
				fprintf(stderr, "KTe:%x-%lu-%x\n", charcs, virtualKeyCode, modifierKeyState);
			}
#endif
		}
		else
		{
#ifdef DEBUG_UNI_KEYSTROKES
			fprintf(stderr, "KLPe:%li\n", error);
#endif
		}
	}
	lastKbdLayout = currentKbdLayout;
	return result;
#endif	// SIXTY_FOUR_BIT
}
Esempio n. 9
0
bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar  )
{
    if ( !focus )
        return false ;

    short keycode ;
    short keychar ;
    keychar = short(keymessage & charCodeMask);
    keycode = short(keymessage & keyCodeMask) >> 8 ;
    if ( modifiers & ( controlKey|shiftKey|optionKey ) )
    {
        // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
        // and look at the character after
        UInt32 state = 0;
        UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
        keychar = short(keyInfo & charCodeMask);
    }
    long keyval = wxMacTranslateKey(keychar, keycode) ;

    if ( keyval == keychar )
    {
        keyval = wxToupper( keyval ) ;
    }

    // Check for NUMPAD keys
    if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92)
    {
        keyval = keyval - '0' + WXK_NUMPAD0;
    }
    else if (keycode >= 67 && keycode <= 81)
    {
        switch (keycode)
        {
        case 76 :
            keyval = WXK_NUMPAD_ENTER;
            break;
        case 81:
            keyval = WXK_NUMPAD_EQUAL;
            break;
        case 67:
            keyval = WXK_NUMPAD_MULTIPLY;
            break;
        case 75:
            keyval = WXK_NUMPAD_DIVIDE;
            break;
        case 78:
            keyval = WXK_NUMPAD_SUBTRACT;
            break;
        case 69:
            keyval = WXK_NUMPAD_ADD;
            break;
        case 65:
            keyval = WXK_NUMPAD_DECIMAL;
            break;
        } // end switch
    }

    bool handled = false ;

    wxKeyEvent event(wxEVT_KEY_UP);
    event.m_shiftDown = modifiers & shiftKey;
    event.m_controlDown = modifiers & controlKey;
    event.m_altDown = modifiers & optionKey;
    event.m_metaDown = modifiers & cmdKey;
    event.m_keyCode = keyval ;
#if wxUSE_UNICODE
    event.m_uniChar = uniChar ;
#endif

    event.m_rawCode = keymessage;
    event.m_rawFlags = modifiers;
    event.m_x = wherex;
    event.m_y = wherey;
    event.SetTimestamp(when);
    event.SetEventObject(focus);
    handled = focus->GetEventHandler()->ProcessEvent( event ) ;

    return handled ;
}
Esempio n. 10
0
bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar  )
{
    if ( !focus )
        return false ;

    short keycode ;
    short keychar ;
    keychar = short(keymessage & charCodeMask);
    keycode = short(keymessage & keyCodeMask) >> 8 ;

    if ( modifiers & ( controlKey|shiftKey|optionKey ) )
    {
        // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
        // and look at the character after
        UInt32 state = 0;
        UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
        keychar = short(keyInfo & charCodeMask);
    }
    long keyval = wxMacTranslateKey(keychar, keycode) ;
    long realkeyval = keyval ;
    if ( keyval == keychar )
    {
        // we are not on a special character combo -> pass the real os event-value to EVT_CHAR, but not to EVT_KEY (make upper first)
        realkeyval = short(keymessage & charCodeMask) ;
        keyval = wxToupper( keyval ) ;
    }

    // Check for NUMPAD keys
    if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92)
    {
        keyval = keyval - '0' + WXK_NUMPAD0;
    }
    else if (keycode >= 67 && keycode <= 81)
    {
        switch (keycode)
        {
        case 76 :
            keyval = WXK_NUMPAD_ENTER;
            break;
        case 81:
            keyval = WXK_NUMPAD_EQUAL;
            break;
        case 67:
            keyval = WXK_NUMPAD_MULTIPLY;
            break;
        case 75:
            keyval = WXK_NUMPAD_DIVIDE;
            break;
        case 78:
            keyval = WXK_NUMPAD_SUBTRACT;
            break;
        case 69:
            keyval = WXK_NUMPAD_ADD;
            break;
        case 65:
            keyval = WXK_NUMPAD_DECIMAL;
            break;
        } // end switch
    }

    wxKeyEvent event(wxEVT_KEY_DOWN);
    bool handled = false ;
    event.m_shiftDown = modifiers & shiftKey;
    event.m_controlDown = modifiers & controlKey;
    event.m_altDown = modifiers & optionKey;
    event.m_metaDown = modifiers & cmdKey;
    event.m_keyCode = keyval ;
#if wxUSE_UNICODE
    event.m_uniChar = uniChar ;
#endif
    event.m_rawCode = keymessage;
    event.m_rawFlags = modifiers;
    event.m_x = wherex;
    event.m_y = wherey;
    event.SetTimestamp(when);
    event.SetEventObject(focus);
    handled = focus->GetEventHandler()->ProcessEvent( event ) ;
    if ( handled && event.GetSkipped() )
        handled = false ;
    if ( !handled )
    {
#if wxUSE_ACCEL
        if (!handled)
        {
            wxWindow *ancestor = focus;
            while (ancestor)
            {
                int command = ancestor->GetAcceleratorTable()->GetCommand( event );
                if (command != -1)
                {
                    wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
                    handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
                    break;
                }
                if (ancestor->IsTopLevel())
                    break;
                ancestor = ancestor->GetParent();
            }
        }
#endif // wxUSE_ACCEL
    }
    if (!handled)
    {
        wxTopLevelWindowMac *tlw = focus->MacGetTopLevelWindow() ;

        if (tlw)
        {
            event.Skip( FALSE ) ;
            event.SetEventType( wxEVT_CHAR_HOOK );
            // raw value again
            event.m_keyCode = realkeyval ;

            handled = tlw->GetEventHandler()->ProcessEvent( event );
            if ( handled && event.GetSkipped() )
                handled = false ;
        }
    }
    
    if ( !handled )
    {        
        event.Skip( FALSE ) ;
        event.SetEventType( wxEVT_CHAR ) ;
        // raw value again
        event.m_keyCode = realkeyval ;

        handled = focus->GetEventHandler()->ProcessEvent( event ) ;
        if ( handled && event.GetSkipped() )
            handled = false ;
    }
    if ( !handled && (keyval == WXK_TAB) )
    {
        wxWindow* iter = focus->GetParent() ;
        while( iter && !handled )
        {
            if ( iter->HasFlag( wxTAB_TRAVERSAL ) )
            {
                wxNavigationKeyEvent new_event;
                new_event.SetEventObject( focus );
                new_event.SetDirection( !event.ShiftDown() );
                /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
                new_event.SetWindowChange( event.ControlDown() );
                new_event.SetCurrentFocus( focus );
                handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event );
                if ( handled && new_event.GetSkipped() )
                    handled = false ;
            }
            iter = iter->GetParent() ;
        }
    }
    // backdoor handler for default return and command escape
    if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
    {
          // if window is not having a focus still testing for default enter or cancel
          // TODO add the UMA version for ActiveNonFloatingWindow
          wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
          if ( focus )
          {
            if ( keyval == WXK_RETURN )
            {
                 wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
                                                       wxButton);
                 if ( def && def->IsEnabled() )
                 {
                     wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
                     event.SetEventObject(def);
                     def->Command(event);
                     return true ;
                }
            }
            /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
            else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
            {
                  wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
                  new_event.SetEventObject( focus );
                  handled = focus->GetEventHandler()->ProcessEvent( new_event );
            }
          }
    }
    return handled ;
}
Esempio n. 11
0
Boolean QTInfo_EditAnnotation (Movie theMovie, OSType theType)
{
    DialogPtr		myDialog = NULL;
    short 			myItem;
    short 			mySavedResFile;
    GrafPtr			mySavedPort;
    Handle			myHandle = NULL;
    short			myItemKind;
    Handle			myItemHandle;
    UserData		myUserData = NULL;
    Rect			myItemRect;
    Str255			myString;
    Boolean			myIsChanged = false;
    OSErr			myErr = noErr;

    //////////
    //
    // save the current resource file and graphics port
    //
    //////////

    mySavedResFile = CurResFile();
    GetPort(&mySavedPort);

    // set the application's resource file
    UseResFile(gAppResFile);

    // get the movie user data
    myUserData = GetMovieUserData(theMovie);
    if (myUserData == NULL)
        goto bail;

    //////////
    //
    // create the dialog box in which the user will add or edit the annotation
    //
    //////////

    myDialog = GetNewDialog(kEditTextResourceID, NULL, (WindowPtr)-1L);
    if (myDialog == NULL)
        goto bail;

    MacSetPort(GetDialogPort(myDialog));

    SetDialogDefaultItem(myDialog, kEditTextItemOK);
    SetDialogCancelItem(myDialog, kEditTextItemCancel);

    // get a string for the specified annotation type
    switch (theType) {
    case kUserDataTextFullName:
        GetIndString(myString, kTextKindsResourceID, kTextKindsFullName);
        break;

    case kUserDataTextCopyright:
        GetIndString(myString, kTextKindsResourceID, kTextKindsCopyright);
        break;

    case kUserDataTextInformation:
        GetIndString(myString, kTextKindsResourceID, kTextKindsInformation);
        break;
    }

    GetDialogItem(myDialog, kEditTextItemEditLabel, &myItemKind, &myItemHandle, &myItemRect);
    SetDialogItemText(myItemHandle, myString);

    //////////
    //
    // set the current annotation of the specified type, if it exists
    //
    //////////

    myHandle = NewHandleClear(4);
    if (myHandle != NULL) {
        myErr = GetUserDataText(myUserData, myHandle, theType, 1, GetScriptManagerVariable(smRegionCode));
        if (myErr == noErr) {
            QTInfo_TextHandleToPString(myHandle, myString);
            GetDialogItem(myDialog, kEditTextItemEditBox, &myItemKind, &myItemHandle, &myItemRect);
            SetDialogItemText(myItemHandle, myString);
            SelectDialogItemText(myDialog, kEditTextItemEditBox, 0, myString[0]);
        }

        DisposeHandle(myHandle);
    }

    MacShowWindow(GetDialogWindow(myDialog));

    //////////
    //
    // display and handle events in the dialog box until the user clicks OK or Cancel
    //
    //////////

    do {
        ModalDialog(gModalFilterUPP, &myItem);
    } while ((myItem != kEditTextItemOK) && (myItem != kEditTextItemCancel));

    //////////
    //
    // handle the selected button
    //
    //////////

    if (myItem != kEditTextItemOK)
        goto bail;

    // retrieve the edited text
    myHandle = NewHandleClear(4);
    if (myHandle != NULL) {
        GetDialogItem(myDialog, kEditTextItemEditBox, &myItemKind, &myItemHandle, &myItemRect);
        GetDialogItemText(myItemHandle, myString);
        QTInfo_PStringToTextHandle(myString, myHandle);
        myErr = AddUserDataText(myUserData, myHandle, theType, 1, GetScriptManagerVariable(smRegionCode));
        myIsChanged = (myErr == noErr);
        DisposeHandle(myHandle);
    }

bail:
    // restore the previous resource file and graphics port
    MacSetPort(mySavedPort);
    UseResFile(mySavedResFile);

    if (myDialog != NULL)
        DisposeDialog(myDialog);

    return(myIsChanged);
}
Esempio n. 12
0
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
//		¥ WEFastSetStyle
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
// Sets the style without making an undo entry and can effect any text range, not just the selection
OSErr WEFastSetStyle(
	WEStyleMode		mode,
	const TextStyle *ts,
	SInt32			inStart,
	SInt32			inEnd,
	WEHandle		hWE)
{
	WEPtr pWE;
	WEActionHandle hAction;
	ScriptCode fontScript;
	Boolean saveWELock;
	OSErr err;

	// lock the WE record
	saveWELock = _WESetHandleLock((Handle) hWE, true);
	pWE = *hWE;

	// return an error code if this instance is read-only
	err = weReadOnlyErr;
	if (BTST(pWE->features, weFReadOnly))
	{
		goto cleanup;
	}

	// stop any ongoing inline input session
	WEStopInlineSession(hWE);

	if (BTST(pWE->features, weFMonoStyled))
	{
		// MONOSTYLED TEXT
		// apply the change to the whole text, not just to the selection range
		if ((err = _WESetStyleRange(0, pWE->textLength, mode, (WETextStyle *) ts, hWE)) != noErr)
		{
			goto cleanup;
		}

		// invalidate the null style record
		BCLR(pWE->flags, weFUseNullStyle);

		// redraw the text
		if ((err = _WERedraw(0, pWE->textLength, hWE)) != noErr)
		{
			goto cleanup;
		}
	}
	else if (inStart == inEnd)
	{
		// MULTISTYLED TEXT; NULL SELECTION
		// first make sure the nullStyle field contains valid information
		_WESynchNullStyle(hWE);

		// apply style changes to the nullStyle record
		_WECopyStyle((WETextStyle *) ts, &pWE->nullStyle.runStyle, pWE->nullStyle.runStyle.tsFace, mode);

		// special case: if this instance is empty, propagate the
		// change to the style table (this avoids some subtle problems)
		if (pWE->textLength == 0)
		{
			if ((err = _WESetStyleRange(0, 0, weDoAll + weDoReplaceFace, &pWE->nullStyle.runStyle, hWE)) != noErr)
			{
				goto cleanup;
			}
		}

#if !WASTE_NO_SYNCH
		// if the font was altered, synchronize the keyboard script
		if (BTST(pWE->flags, weFNonRoman) && (mode & weDoFont))
		{
			fontScript = FontToScript(pWE->nullStyle.runStyle.tsFont);
			if (fontScript != GetScriptManagerVariable(smKeyScript))
			{
				KeyScript(fontScript);
			}
		}
#endif
	}
	else
	{
		// MULTISTYLED TEXT; NON-EMPTY SELECTION

		// increment modification count
		pWE->modCount++;

		// check for "smart" font modes
		if (BTST(pWE->flags, weFNonRoman) && ((mode & weDoSmartFont) == weDoSmartFont))
		{
			if ((err = _WESmartSetFont(mode, ts, hWE)) != noErr)
			{
				goto cleanup;
			}
			mode &= ~weDoFont;
		}

		// set the style of the selection range
		if ((err = _WESetStyleRange(inStart,inEnd, mode, (WETextStyle *) ts, hWE)) != noErr)
		{
			goto cleanup;
		}

		// and redraw the text
		if ((err = _WERedraw(inStart,inEnd, hWE)) != noErr)
		{
			goto cleanup;
		}
	}

	// clear the result code
	err = noErr;

cleanup:
	// unlock the WE record
	_WESetHandleLock((Handle) hWE, saveWELock);

	// return result code
	return err;
}
Esempio n. 13
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 );
	}