+void wxApp::MacHandleOneEvent( EventRecord *ev )
+{
+ m_macCurrentEvent = ev ;
+
+ wxApp::sm_lastMessageTime = ev->when ;
+
+ switch (ev->what)
+ {
+ case mouseDown:
+ MacHandleMouseDownEvent( ev ) ;
+ if ( ev->modifiers & controlKey )
+ s_lastMouseDown = 2;
+ else
+ s_lastMouseDown = 1;
+ break;
+ case mouseUp:
+ if ( s_lastMouseDown == 2 )
+ {
+ ev->modifiers |= controlKey ;
+ }
+ else
+ {
+ ev->modifiers &= ~controlKey ;
+ }
+ MacHandleMouseUpEvent( ev ) ;
+ s_lastMouseDown = 0;
+ break;
+ case activateEvt:
+ MacHandleActivateEvent( ev ) ;
+ break;
+ case updateEvt:
+ MacHandleUpdateEvent( ev ) ;
+ break;
+ case keyDown:
+ case autoKey:
+ MacHandleKeyDownEvent( ev ) ;
+ break;
+ case keyUp:
+ MacHandleKeyUpEvent( ev ) ;
+ break;
+ case diskEvt:
+ MacHandleDiskEvent( ev ) ;
+ break;
+ case osEvt:
+ MacHandleOSEvent( ev ) ;
+ break;
+ case kHighLevelEvent:
+ MacHandleHighLevelEvent( ev ) ;
+ break;
+ default:
+ break;
+ }
+ wxMacProcessNotifierAndPendingEvents() ;
+}
+
+void wxApp::MacHandleHighLevelEvent( EventRecord *ev )
+{
+ ::AEProcessAppleEvent( ev ) ;
+}
+
+bool s_macIsInModalLoop = false ;
+
+void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
+{
+ wxToolTip::RemoveToolTips() ;
+
+ WindowRef window;
+ WindowRef frontWindow = UMAFrontNonFloatingWindow() ;
+ WindowAttributes frontWindowAttributes = NULL ;
+ if ( frontWindow )
+ UMAGetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
+
+ short windowPart = ::FindWindow(ev->where, &window);
+ wxWindow* win = wxFindWinFromMacWindow( window ) ;
+ if ( wxPendingDelete.Member(win) )
+ return ;
+
+ BitMap screenBits;
+ GetQDGlobalsScreenBits( &screenBits );
+
+ switch (windowPart)
+ {
+ case inMenuBar :
+ if ( s_macIsInModalLoop )
+ {
+ SysBeep ( 30 ) ;
+ }
+ else
+ {
+ UInt32 menuresult = MenuSelect(ev->where) ;
+ MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
+ s_lastMouseDown = 0;
+ }
+ break ;
+#if !TARGET_CARBON
+ case inSysWindow :
+ SystemClick( ev , window ) ;
+ s_lastMouseDown = 0;
+ break ;
+#endif
+ case inDrag :
+ if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) )
+ {
+ SysBeep ( 30 ) ;
+ }
+ else
+ {
+ DragWindow(window, ev->where, &screenBits.bounds);
+ if (win)
+ {
+ GrafPtr port ;
+ GetPort( &port ) ;
+ Point pt = { 0, 0 } ;
+ #if TARGET_CARBON
+ SetPort( GetWindowPort(window) ) ;
+ #else
+ SetPort( (window) ) ;
+ #endif
+ SetOrigin( 0 , 0 ) ;
+ LocalToGlobal( &pt ) ;
+ SetPort( port ) ;
+ win->SetSize( pt.h , pt.v , -1 ,
+ -1 , wxSIZE_USE_EXISTING);
+ }
+ s_lastMouseDown = 0;
+ }
+ break ;
+ case inGoAway:
+ if (TrackGoAway(window, ev->where))
+ {
+ if ( win )
+ win->Close() ;
+ }
+ s_lastMouseDown = 0;
+ break;
+ case inGrow:
+ {
+ int growResult = GrowWindow(window , ev->where, &screenBits.bounds);
+ if (growResult != 0)
+ {
+ int newWidth = LoWord(growResult);
+ int newHeight = HiWord(growResult);
+ int oldWidth, oldHeight;
+
+
+ if (win)
+ {
+ win->GetSize(&oldWidth, &oldHeight);
+ if (newWidth == 0)
+ newWidth = oldWidth;
+ if (newHeight == 0)
+ newHeight = oldHeight;
+ win->SetSize( -1, -1, newWidth, newHeight, wxSIZE_USE_EXISTING);
+ }
+ }
+ s_lastMouseDown = 0;
+ }
+ break;
+ case inZoomIn:
+ case inZoomOut:
+ if (TrackBox(window, ev->where, windowPart))
+ {
+ // TODO setup size event
+ ZoomWindow( window , windowPart , false ) ;
+ if (win)
+ {
+ Rect tempRect ;
+
+ GetWindowPortBounds(window, &tempRect ) ;
+ win->SetSize( -1, -1, tempRect.right-tempRect.left ,
+ tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
+ }
+ }
+ s_lastMouseDown = 0;
+ break;
+ case inCollapseBox :
+ // TODO setup size event
+ s_lastMouseDown = 0;
+ break ;
+
+ case inContent :
+ {
+ GrafPtr port ;
+ GetPort( &port ) ;
+ #if TARGET_CARBON
+ SetPort( GetWindowPort(window) ) ;
+ #else
+ SetPort( (window) ) ;
+ #endif
+ SetOrigin( 0 , 0 ) ;
+ SetPort( port ) ;
+ }
+ if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
+ {
+ if ( s_macIsInModalLoop )
+ {
+ SysBeep ( 30 ) ;
+ }
+ else if ( UMAIsWindowFloating( window ) )
+ {
+ if ( win )
+ win->MacMouseDown( ev , windowPart ) ;
+ }
+ else
+ {
+ if ( win )
+ win->MacMouseDown( ev , windowPart ) ;
+ UMASelectWindow( window ) ;
+ }
+ }
+ else
+ {
+ if ( win )
+ win->MacMouseDown( ev , windowPart ) ;
+ }
+ break ;
+
+ default:
+ break;
+ }
+}
+
+void wxApp::MacHandleMouseUpEvent( EventRecord *ev )
+{
+ WindowRef window;
+
+ short windowPart = ::FindWindow(ev->where, &window);
+
+ switch (windowPart)
+ {
+ case inMenuBar :
+ break ;
+ case inSysWindow :
+ break ;
+ default:
+ {
+ wxWindow* win = wxFindWinFromMacWindow( window ) ;
+ if ( win )
+ win->MacMouseUp( ev , windowPart ) ;
+ }
+ break;
+ }
+}
+
+long wxMacTranslateKey(unsigned char key, unsigned char code)
+{
+ long retval = key ;
+ switch (key)
+ {
+ case 0x01 :
+ retval = WXK_HOME;
+ break;
+ case 0x03 :
+ retval = WXK_RETURN;
+ break;
+ case 0x04 :
+ retval = WXK_END;
+ break;
+ case 0x05 :
+ retval = WXK_HELP;
+ break;
+ case 0x08 :
+ retval = WXK_BACK;
+ break;
+ case 0x09 :
+ retval = WXK_TAB;
+ break;
+ case 0x0b :
+ retval = WXK_PAGEUP;
+ break;
+ case 0x0c :
+ retval = WXK_PAGEDOWN;
+ break;
+ case 0x0d :
+ retval = WXK_RETURN;
+ break;
+ case 0x10 :
+ {
+ switch( code )
+ {
+ case 0x7a :
+ retval = WXK_F1 ;
+ break;
+ case 0x78 :
+ retval = WXK_F2 ;
+ break;
+ case 0x63 :
+ retval = WXK_F3 ;
+ break;
+ case 0x76 :
+ retval = WXK_F4 ;
+ break;
+ case 0x60 :
+ retval = WXK_F5 ;
+ break;
+ case 0x61 :
+ retval = WXK_F6 ;
+ break;
+ case 0x62:
+ retval = WXK_F7 ;
+ break;
+ case 0x64 :
+ retval = WXK_F8 ;
+ break;
+ case 0x65 :
+ retval = WXK_F9 ;
+ break;
+ case 0x6D :
+ retval = WXK_F10 ;
+ break;
+ case 0x67 :
+ retval = WXK_F11 ;
+ break;
+ case 0x6F :
+ retval = WXK_F12 ;
+ break;
+ case 0x69 :
+ retval = WXK_F13 ;
+ break;
+ case 0x6B :
+ retval = WXK_F14 ;
+ break;
+ case 0x71 :
+ retval = WXK_F15 ;
+ break;
+ }
+ }
+ break ;
+ case 0x1b :
+ retval = WXK_ESCAPE ;
+ break ;
+ case 0x1c :
+ retval = WXK_LEFT ;
+ break ;
+ case 0x1d :
+ retval = WXK_RIGHT ;
+ break ;
+ case 0x1e :
+ retval = WXK_UP ;
+ break ;
+ case 0x1f :
+ retval = WXK_DOWN ;
+ break ;
+ case 0x7F :
+ retval = WXK_DELETE ;
+ default:
+ break ;
+ } // end switch
+
+ return retval;
+}
+
+void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
+{
+ wxToolTip::RemoveToolTips() ;
+
+ UInt32 menuresult = UMAMenuEvent(ev) ;
+ if ( HiWord( menuresult ) )
+ {
+ if ( !s_macIsInModalLoop )
+ MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
+ }
+ else
+ {
+ short keycode ;
+ short keychar ;
+ keychar = short(ev->message & charCodeMask);
+ keycode = short(ev->message & keyCodeMask) >> 8 ;
+
+ wxWindow* focus = wxWindow::FindFocus() ;
+ if ( focus )
+ {
+ long keyval = wxMacTranslateKey(keychar, keycode) ;
+
+ wxKeyEvent event(wxEVT_KEY_DOWN);
+ event.m_shiftDown = ev->modifiers & shiftKey;
+ event.m_controlDown = ev->modifiers & controlKey;
+ event.m_altDown = ev->modifiers & optionKey;
+ event.m_metaDown = ev->modifiers & cmdKey;
+ event.m_keyCode = keyval;
+ event.m_x = ev->where.h;
+ event.m_y = ev->where.v;
+ event.m_timeStamp = ev->when;
+ event.SetEventObject(focus);
+ bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
+ 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->m_isFrame)
+ break;
+ ancestor = ancestor->GetParent();
+ }
+ */
+ }
+ #endif // wxUSE_ACCEL
+ }
+ if (!handled)
+ {
+ wxKeyEvent event(wxEVT_CHAR);
+ event.m_shiftDown = ev->modifiers & shiftKey;
+ event.m_controlDown = ev->modifiers & controlKey;
+ event.m_altDown = ev->modifiers & optionKey;
+ event.m_metaDown = ev->modifiers & cmdKey;
+ event.m_keyCode = keyval;
+ event.m_x = ev->where.h;
+ event.m_y = ev->where.v;
+ event.m_timeStamp = ev->when;
+ event.SetEventObject(focus);
+ handled = focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ if ( !handled &&
+ (keyval == WXK_TAB) &&
+ (!focus->HasFlag(wxTE_PROCESS_TAB)) &&
+ (focus->GetParent()) &&
+ (focus->GetParent()->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->GetEventHandler()->ProcessEvent( new_event );
+ }
+ /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
+ if ( (!handled) &&
+ (keyval == '.' && event.ControlDown() ) )
+ {
+ wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
+ new_event.SetEventObject( focus );
+ handled = focus->GetEventHandler()->ProcessEvent( new_event );
+ }
+ }
+ }
+}
+
+void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
+{
+ wxToolTip::RemoveToolTips() ;
+
+ UInt32 menuresult = UMAMenuEvent(ev) ;
+ if ( HiWord( menuresult ) )
+ {
+ }
+ else
+ {
+ short keycode ;
+ short keychar ;
+ keychar = short(ev->message & charCodeMask);
+ keycode = short(ev->message & keyCodeMask) >> 8 ;
+
+ wxWindow* focus = wxWindow::FindFocus() ;
+ if ( focus )
+ {
+ long keyval = wxMacTranslateKey(keychar, keycode) ;
+
+ wxKeyEvent event(wxEVT_KEY_UP);
+ event.m_shiftDown = ev->modifiers & shiftKey;
+ event.m_controlDown = ev->modifiers & controlKey;
+ event.m_altDown = ev->modifiers & optionKey;
+ event.m_metaDown = ev->modifiers & cmdKey;
+ event.m_keyCode = keyval;
+ event.m_x = ev->where.h;
+ event.m_y = ev->where.v;
+ event.m_timeStamp = ev->when;
+ event.SetEventObject(focus);
+ bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
+ }
+ }
+}
+
+void wxApp::MacHandleActivateEvent( EventRecord *ev )
+{
+ WindowRef window = (WindowRef) ev->message ;
+ if ( window )
+ {
+ bool activate = (ev->modifiers & activeFlag ) ;
+ WindowClass wclass ;
+ UMAGetWindowClass ( window , &wclass ) ;
+ if ( wclass == kFloatingWindowClass )
+ {
+ // if it is a floater we activate/deactivate the front non-floating window instead
+ window = UMAFrontNonFloatingWindow() ;
+ }
+ wxWindow* win = wxFindWinFromMacWindow( window ) ;
+ if ( win )
+ win->MacActivate( ev , activate ) ;
+ }
+}
+
+void wxApp::MacHandleUpdateEvent( EventRecord *ev )
+{
+ WindowRef window = (WindowRef) ev->message ;
+ wxWindow * win = wxFindWinFromMacWindow( window ) ;
+ if ( win )
+ {
+ if ( !wxPendingDelete.Member(win) )
+ win->MacUpdate( ev ) ;
+ }
+ else
+ {
+ // since there is no way of telling this foreign window to update itself
+ // we have to invalidate the update region otherwise we keep getting the same
+ // event over and over again
+ BeginUpdate( window ) ;
+ EndUpdate( window ) ;
+ }
+}
+
+void wxApp::MacHandleDiskEvent( EventRecord *ev )
+{
+ if ( HiWord( ev->message ) != noErr )
+ {
+ #if !TARGET_CARBON
+ OSErr err ;
+ Point point ;
+ SetPt( &point , 100 , 100 ) ;
+
+ err = DIBadMount( point , ev->message ) ;
+ wxASSERT( err == noErr ) ;
+#endif
+ }
+}
+
+void wxApp::MacHandleOSEvent( EventRecord *ev )
+{
+ switch( ( ev->message & osEvtMessageMask ) >> 24 )
+ {
+ case suspendResumeMessage :
+ {
+ bool isResuming = ev->message & resumeFlag ;
+#if !TARGET_CARBON
+ bool convertClipboard = ev->message & convertClipboardFlag ;
+#else
+ bool convertClipboard = false;
+#endif
+ bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
+ if ( isResuming )
+ {
+ WindowRef oldFrontWindow = NULL ;
+ WindowRef newFrontWindow = NULL ;
+
+ // in case we don't take care of activating ourselves, we have to synchronize
+ // our idea of the active window with the process manager's - which it already activated
+
+ if ( !doesActivate )
+ oldFrontWindow = UMAFrontNonFloatingWindow() ;
+
+ MacResume( convertClipboard ) ;
+
+ newFrontWindow = UMAFrontNonFloatingWindow() ;
+
+ if ( oldFrontWindow )
+ {
+ wxWindow* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
+ if ( win )
+ win->MacActivate( ev , false ) ;
+ }
+ if ( newFrontWindow )
+ {
+ wxWindow* win = wxFindWinFromMacWindow( newFrontWindow ) ;
+ if ( win )
+ win->MacActivate( ev , true ) ;
+ }
+ }
+ else
+ {
+ MacSuspend( convertClipboard ) ;
+
+ // in case this suspending did close an active window, another one might
+ // have surfaced -> lets deactivate that one
+
+ WindowRef newActiveWindow = UMAGetActiveNonFloatingWindow() ;
+ if ( newActiveWindow )
+ {
+ wxWindow* win = wxFindWinFromMacWindow( newActiveWindow ) ;
+ if ( win )
+ win->MacActivate( ev , false ) ;
+ }
+ }
+ }
+ break ;
+ case mouseMovedMessage :
+ {
+ WindowRef window;
+
+ wxWindow* currentMouseWindow = NULL ;
+
+ wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
+ ¤tMouseWindow ) ;
+
+ if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
+ {
+ wxMouseEvent event ;
+
+ bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
+ bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
+
+ event.m_leftDown = isDown && !controlDown;
+ event.m_middleDown = FALSE;
+ event.m_rightDown = isDown && controlDown;
+ event.m_shiftDown = ev->modifiers & shiftKey;
+ event.m_controlDown = ev->modifiers & controlKey;
+ event.m_altDown = ev->modifiers & optionKey;
+ event.m_metaDown = ev->modifiers & cmdKey;
+ event.m_x = ev->where.h;
+ 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->GetEventHandler()->ProcessEvent(eventleave);
+ }
+ if ( currentMouseWindow )
+ {
+ wxMouseEvent evententer(event ) ;
+ evententer.SetEventType( wxEVT_ENTER_WINDOW ) ;
+ currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
+ }
+ wxWindow::s_lastMouseWindow = currentMouseWindow ;
+ }
+
+ short 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:
+ {
+ if ( s_lastMouseDown == 0 )
+ ev->modifiers |= btnState ;
+
+ wxWindow* win = wxFindWinFromMacWindow( window ) ;
+ if ( win )
+ win->MacMouseMoved( ev , windowPart ) ;
+ else
+ UMAShowArrowCursor();
+
+ }
+ break;
+ }
+ }
+ break ;
+
+ }
+}
+
+void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
+{
+ if (macMenuId == 0)
+ return; // no menu item selected
+
+ if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1)
+ {
+ #if ! TARGET_CARBON
+ Str255 deskAccessoryName ;
+ GrafPtr savedPort ;
+
+ GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName);
+ GetPort(&savedPort);
+ OpenDeskAcc(deskAccessoryName);
+ SetPort(savedPort);
+ #endif
+ }
+ else
+ {
+ wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ;
+ if ( frontwindow && wxMenuBar::MacGetInstalledMenuBar() )
+ wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ;
+ }
+ HiliteMenu(0);
+}
+
+/*
+long wxApp::MacTranslateKey(char key, int mods)
+{
+}
+
+void wxApp::MacAdjustCursor()
+{
+}
+
+*/
+/*
+void
+wxApp::macAdjustCursor()
+{
+ if (ev->what != kHighLevelEvent)
+ {
+ wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+ if (theMacWxFrame)
+ {
+ if (!theMacWxFrame->MacAdjustCursor(ev->where))
+ ::SetCursor(&(qd.arrow));
+ }
+ }
+}
+*/