X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2fca5a00045426b4e59c14a575b2baa3628e3847..cd3c2375e6fddd3d478a6776900c21aaeb2d0f08:/src/mac/app.cpp diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 1fe4f67e18..587cdeb344 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -133,23 +133,88 @@ pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long WX return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ; } -short wxApp::MacHandleAEODoc(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) +// new virtual public method in wxApp +void wxApp::MacOpenFile(const wxString & WXUNUSED(fileName) ) { - SysBeep(40) ; +} + +void wxApp::MacPrintFile(const wxString & WXUNUSED(fileName) ) +{ +} + +void wxApp::MacNewFile() +{ +} + +// new implementation, which parses the event and calls +// MacOpenFile on each of the files it's passed +short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply)) +{ + AEDescList docList; + AEKeyword keywd; + DescType returnedType; + Size actualSize; + long itemsInList; + FSSpec theSpec; + OSErr err; + short i; + err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList); + if (err != noErr) + return err; + + err = AECountItems(&docList, &itemsInList); + if (err != noErr) + return err; + ProcessSerialNumber PSN ; PSN.highLongOfPSN = 0 ; PSN.lowLongOfPSN = kCurrentProcess ; SetFrontProcess( &PSN ) ; - return noErr ; -} - -short wxApp::MacHandleAEPDoc(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) -{ - return noErr ; + + for (i = 1; i <= itemsInList; i++) { + AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType, + (Ptr) & theSpec, sizeof(theSpec), &actualSize); + wxString fName = wxMacFSSpec2MacFilename(&theSpec); + MacOpenFile(fName); + } + return noErr; +} + +short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply)) +{ + AEDescList docList; + AEKeyword keywd; + DescType returnedType; + Size actualSize; + long itemsInList; + FSSpec theSpec; + OSErr err; + short i; + err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList); + if (err != noErr) + return err; + + err = AECountItems(&docList, &itemsInList); + if (err != noErr) + return err; + + ProcessSerialNumber PSN ; + PSN.highLongOfPSN = 0 ; + PSN.lowLongOfPSN = kCurrentProcess ; + SetFrontProcess( &PSN ) ; + + for (i = 1; i <= itemsInList; i++) { + AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType, + (Ptr) & theSpec, sizeof(theSpec), &actualSize); + wxString fName = wxMacFSSpec2MacFilename(&theSpec); + MacPrintFile(fName); + } + return noErr; } short wxApp::MacHandleAEOApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) { + MacNewFile() ; return noErr ; } @@ -399,7 +464,7 @@ bool wxApp::Initialize() // __wxinitialize in Mach-O shared libraries wxStAppResource::OpenSharedLibraryResource(NULL); #endif - + #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , NewAEEventHandlerUPP(AEHandleODoc) , @@ -496,7 +561,7 @@ bool wxApp::Initialize() s_macCursorRgn = ::NewRgn() ; wxBuffer = new char[BUFSIZ + 512]; - + wxClassInfo::InitializeClasses(); #if wxUSE_RESOURCES @@ -506,7 +571,7 @@ bool wxApp::Initialize() #if wxUSE_THREADS wxPendingEventsLocker = new wxCriticalSection; #endif - + wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); wxTheColourDatabase->Initialize(); @@ -592,7 +657,7 @@ void wxApp::CleanUp() delete wxWinMacControlList ; } delete wxPendingEvents; - + #if wxUSE_THREADS delete wxPendingEventsLocker; // If we don't do the following, we get an apparent memory leak. @@ -635,12 +700,12 @@ void wxApp::CleanUp() // __wxterminate in Mach-O shared libraries wxStAppResource::CloseSharedLibraryResource(); #endif - + UMACleanupToolbox() ; if (s_macCursorRgn) { ::DisposeRgn((RgnHandle)s_macCursorRgn); } - + #if 0 TerminateAE() ; #endif @@ -683,14 +748,14 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock) if ( initBlock != NULL ) { const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock; FSSpec *fileSpec = NULL; - + if (theInitBlock->fragLocator.where == kDataForkCFragLocator) { fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec; } else if (theInitBlock->fragLocator.where == kResourceCFragLocator) { fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec; } - + if (fileSpec != NULL) { gSharedLibraryResource = FSpOpenResFile(fileSpec, fsRdPerm); } @@ -701,12 +766,12 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock) NSSymbol theSymbol; NSModule theModule; const char *theLibPath; - + gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows")); if (gSharedLibraryBundle != NULL) { // wxWindows has been bundled into a framework // load the framework resources - + gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle); } else { @@ -717,7 +782,7 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock) char *theExt; FSRef theResRef; OSErr theErr = noErr; - + // get the library path theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource"); theModule = NSModuleForSymbol(theSymbol); @@ -735,7 +800,7 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock) theExt = strstr(theName, ".dylib"); // overwrite extension with ".rsrc" strcpy(theExt, ".rsrc"); - + wxLogDebug( theResPath ); theErr = FSPathMakeRef((UInt8 *) theResPath, &theResRef, false); @@ -743,7 +808,7 @@ void wxStAppResource::OpenSharedLibraryResource(const void *initBlock) // try in current directory (using name only) theErr = FSPathMakeRef((UInt8 *) theName, &theResRef, false); } - + // free duplicated resource file path free(theResPath); @@ -776,7 +841,7 @@ void wxStAppResource::CloseSharedLibraryResource() CloseResFile(gSharedLibraryResource); } gSharedLibraryResource = kResFileNotOpened; - } + } #endif /* WXMAKINGDLL */ } @@ -860,12 +925,12 @@ int wxEntry( int argc, char *argv[] , bool enterLoop ) if (argc > 1) { char theArg[6] = ""; strncpy(theArg, argv[1], 5); - + if (strcmp(theArg, "-psn_") == 0) { // assume the argument is always the only one and remove it --argc; } - } + } #else argc = 0 ; // currently we don't support files as parameters #endif @@ -932,7 +997,7 @@ bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) case kEventClassKeyboard : { converted = true ; - switch( GetEventKind(event) ) + switch( GetEventKind(event) ) { case kEventRawKeyDown : rec->what = keyDown ; @@ -995,14 +1060,14 @@ bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) break ; } } - + return converted ; } pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { OSStatus result = eventNotHandledErr ; - + EventRecord rec ; switch ( GetEventClass( event ) ) { @@ -1034,20 +1099,20 @@ bool wxApp::OnInit() { if ( ! wxAppBase::OnInit() ) return FALSE ; - + #if 0 // TARGET_CARBON - static const EventTypeSpec eventList[] = + static const EventTypeSpec eventList[] = { { kEventClassKeyboard, kEventRawKeyDown } , { kEventClassKeyboard, kEventRawKeyRepeat } , { kEventClassKeyboard, kEventRawKeyUp } , { kEventClassKeyboard, kEventRawKeyModifiersChanged } , - + { kEventClassTextInput , kEventTextInputUnicodeForKeyEvent } , } ; - + InstallApplicationEventHandler(NewEventHandlerUPP(wxMacApplicationEventHandler) - , WXSIZEOF(eventList), eventList, this, NULL); + , WXSIZEOF(eventList), eventList, this, NULL); #endif return TRUE ; } @@ -1067,7 +1132,6 @@ wxApp::wxApp() argv = NULL; m_printMode = wxPRINT_WINDOWS; - m_exitOnFrameDelete = TRUE; m_auto3D = TRUE; } @@ -1302,13 +1366,13 @@ void wxApp::MacSuspend( bool convertClipboard ) node = node->Next(); } - + s_lastMouseDown = 0 ; if( convertClipboard ) { MacConvertPrivateToPublicScrap() ; } - + ::HideFloatingWindows() ; } @@ -1321,9 +1385,9 @@ void wxApp::MacResume( bool convertClipboard ) { MacConvertPublicToPrivateScrap() ; } - + ::ShowFloatingWindows() ; - + // raise modal dialogs in case a non modal window was selected to activate the app wxNode* node = wxModalDialogs.First(); @@ -1331,7 +1395,7 @@ void wxApp::MacResume( bool convertClipboard ) { wxDialog* dialog = (wxDialog *) node->Data(); dialog->Raise(); - + node = node->Next(); } } @@ -1385,7 +1449,11 @@ void wxApp::MacHandleModifierEvents( WXEVENTREF evr ) } else { - ev->modifiers = GetCurrentKeyModifiers() ; + EventRecord nev ; + WaitNextEvent( 0 , &nev , 0 , NULL ) ; + ev->modifiers = nev.modifiers ; + // KeyModifiers unfortunately don't include btnState... +// ev->modifiers = GetCurrentKeyModifiers() ; } #endif if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL ) @@ -1402,23 +1470,23 @@ void wxApp::MacHandleModifierEvents( WXEVENTREF evr ) event.m_timeStamp = ev->when; wxWindow* focus = wxWindow::FindFocus() ; event.SetEventObject(focus); - + if ( (ev->modifiers ^ s_lastModifiers ) & controlKey ) { event.m_keyCode = WXK_CONTROL ; - event.SetEventType( ( ev->modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; + event.SetEventType( ( ev->modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->GetEventHandler()->ProcessEvent( event ) ; } if ( (ev->modifiers ^ s_lastModifiers ) & shiftKey ) { event.m_keyCode = WXK_SHIFT ; - event.SetEventType( ( ev->modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; + event.SetEventType( ( ev->modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->GetEventHandler()->ProcessEvent( event ) ; } if ( (ev->modifiers ^ s_lastModifiers ) & optionKey ) { event.m_keyCode = WXK_ALT ; - event.SetEventType( ( ev->modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; + event.SetEventType( ( ev->modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->GetEventHandler()->ProcessEvent( event ) ; } s_lastModifiers = ev->modifiers ; @@ -1656,7 +1724,7 @@ void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr ) { window = (WindowRef) s_captureWindow->MacGetRootWindow() ; windowPart = inContent ; - } + } else { windowPart = ::FindWindow(ev->where, &window) ; @@ -1684,34 +1752,34 @@ long wxMacTranslateKey(unsigned char key, unsigned char code) long retval = key ; switch (key) { - case 0x01 : + case kHomeCharCode : retval = WXK_HOME; break; - case 0x03 : + case kEnterCharCode : retval = WXK_RETURN; break; - case 0x04 : + case kEndCharCode : retval = WXK_END; break; - case 0x05 : + case kHelpCharCode : retval = WXK_HELP; break; - case 0x08 : + case kBackspaceCharCode : retval = WXK_BACK; break; - case 0x09 : + case kTabCharCode : retval = WXK_TAB; break; - case 0x0b : + case kPageUpCharCode : retval = WXK_PAGEUP; break; - case 0x0c : + case kPageDownCharCode : retval = WXK_PAGEDOWN; break; - case 0x0d : + case kReturnCharCode : retval = WXK_RETURN; break; - case 0x10 : + case kFunctionKeyCharCode : { switch( code ) { @@ -1763,22 +1831,22 @@ long wxMacTranslateKey(unsigned char key, unsigned char code) } } break ; - case 0x1b : + case kEscapeCharCode : retval = WXK_ESCAPE ; break ; - case 0x1c : + case kLeftArrowCharCode : retval = WXK_LEFT ; break ; - case 0x1d : + case kRightArrowCharCode : retval = WXK_RIGHT ; break ; - case 0x1e : + case kUpArrowCharCode : retval = WXK_UP ; break ; - case 0x1f : + case kDownArrowCharCode : retval = WXK_DOWN ; break ; - case 0x7F : + case kDeleteCharCode : retval = WXK_DELETE ; default: break ; @@ -1800,39 +1868,59 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) } else { - short keycode ; - short keychar ; - keychar = short(ev->message & charCodeMask); - keycode = short(ev->message & keyCodeMask) >> 8 ; - wxWindow* focus = wxWindow::FindFocus() ; - // it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value - if ( (ev->modifiers & controlKey) && keychar >= 0 && keychar < 0x20 ) - { - keychar += 0x40 ; - } - long keyval = wxMacTranslateKey(keychar, keycode) ; - - if ( MacSendKeyDownEvent( focus , keyval , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false ) + wxWindow* focus = wxWindow::FindFocus() ; + + if ( MacSendKeyDownEvent( focus , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false ) { // has not been handled -> perform default wxControl* control = wxDynamicCast( focus , wxControl ) ; if ( control && control->GetMacControl() != NULL ) { + short keycode ; + short keychar ; + keychar = short(ev->message & charCodeMask); + keycode = short(ev->message & keyCodeMask) >> 8 ; ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ; } } } } -bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey ) +bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) { + 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); + keycode = short(keyInfo & keyCodeMask) >> 8 ; + } + 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 ) ; + } + 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 = wxToupper(keyval ); + event.m_keyCode = keyval ; event.m_x = wherex; event.m_y = wherey; @@ -1867,7 +1955,8 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keyval , long modifiers { event.Skip( FALSE ) ; event.SetEventType( wxEVT_CHAR ) ; - event.m_keyCode = keyval ; + // raw value again + event.m_keyCode = realkeyval ; handled = focus->GetEventHandler()->ProcessEvent( event ) ; if ( handled && event.GetSkipped() ) @@ -1939,41 +2028,49 @@ void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr ) } else { - short keycode ; - short keychar ; - keychar = short(ev->message & charCodeMask); - keycode = short(ev->message & keyCodeMask) >> 8 ; - // it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value - if ( (ev->modifiers & controlKey) && keychar >= 0 && keychar < 0x20 ) - { - keychar += 0x40 ; - } - long keyval = wxMacTranslateKey(keychar, keycode) ; - - wxWindow* focus = wxWindow::FindFocus() ; - bool handled = MacSendKeyUpEvent( focus , keyval , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ; - // we don't have to do anything under classic here + MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ; } } -bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey ) +bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) { - bool handled = false ; - if ( focus ) - { - 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 = wxToupper(keyval ); - - event.m_x = wherex; - event.m_y = wherey; - event.m_timeStamp = when; - event.SetEventObject(focus); - handled = focus->GetEventHandler()->ProcessEvent( event ) ; + 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); + keycode = short(keyInfo & keyCodeMask) >> 8 ; } + long keyval = wxMacTranslateKey(keychar, keycode) ; + + if ( keyval == keychar ) + { + keyval = wxToupper( keyval ) ; + } + 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 ; + + event.m_x = wherex; + event.m_y = wherey; + event.m_timeStamp = when; + event.SetEventObject(focus); + handled = focus->GetEventHandler()->ProcessEvent( event ) ; + return handled ; } void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) @@ -2099,8 +2196,16 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) wxWindow* currentMouseWindow = NULL ; - wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , - ¤tMouseWindow ) ; + if (s_captureWindow ) + { + currentMouseWindow = s_captureWindow ; + } + else + { + wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , + ¤tMouseWindow ) ; + } + if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) { wxMouseEvent event ; @@ -2119,14 +2224,14 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) event.m_y = ev->where.v; event.m_timeStamp = ev->when; event.SetEventObject(this); - + if ( wxWindow::s_lastMouseWindow ) { wxMouseEvent eventleave(event); eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; - + wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); } if ( currentMouseWindow ) @@ -2140,27 +2245,44 @@ void wxApp::MacHandleOSEvent( WXEVENTREF evr ) wxWindow::s_lastMouseWindow = currentMouseWindow ; } - short windowPart = ::FindWindow(ev->where, &window); - + short windowPart = inNoWindow ; + + if ( s_captureWindow ) + { + window = (WindowRef) s_captureWindow->MacGetRootWindow() ; + windowPart = inContent ; + } + else + { + windowPart = ::FindWindow(ev->where, &window); + } + switch (windowPart) { - // fixes for setting the cursor back from dominic mazzoni - case inMenuBar : - UMAShowArrowCursor(); - break ; - case inSysWindow : - UMAShowArrowCursor(); - break ; - default: + case inContent : { wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( win ) win->MacMouseMoved( ev , windowPart ) ; else - UMAShowArrowCursor(); - + { + if ( wxIsBusy() ) + { + } + else + UMAShowArrowCursor(); + } } break; + default : + { + if ( wxIsBusy() ) + { + } + else + UMAShowArrowCursor(); + } + break ; } } break ;