-void wxApp::doMacKeyDown(void)
-{
- long menuResult = 0 ;
- short keycode ;
- short keychar ;
- keychar = short(m_event.message & charCodeMask);
- keycode = short(m_event.message & keyCodeMask) >> 8 ;
-
- // Handle menu accelerators
- if ( gSFMacHasAppearance )
- {
- menuResult = MenuEvent( &m_event ) ;
- if ( HiWord( menuResult ) )
- {
- doMacInMenuBar( menuResult ) ;
- }
- else
- {
- ControlHandle control ;
-
- GetKeyboardFocus( FrontNonFloatingWindow() , &control ) ;
- if ( control && keychar != 0x07 )
- HandleControlKey( control , keycode , keychar , m_event.modifiers ) ;
- else
- {
- wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
- if (theMacWxFrame)
- {
- wxKeyEvent event(wxEVT_CHAR);
- event.m_shiftDown = m_event.modifiers & shiftKey;
- event.m_controlDown = m_event.modifiers & controlKey;
- event.m_altDown = m_event.modifiers & optionKey;
- event.m_metaDown = m_event.modifiers & cmdKey;
- event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
- event.m_x = m_event.where.h;
- event.m_y = m_event.where.v;
- event.m_timeStamp = m_event.when;
- event.SetEventObject(theMacWxFrame);
-
- theMacWxFrame->ProcessEvent(event);
- }
- }
- }
- }
- else
- {
- if (GetMenuHandle( kwxMacAppleMenuId ) )
- {
-// menuResult = MDEF_MenuKey(m_event.message, m_event.modifiers , GetMenuHandle( kwxMacAppleMenuId ) );
- }
- else
- {
- if (m_event.modifiers & cmdKey)
- {
- menuResult = MenuKey( keychar ) ;
- }
- }
-
- if ( HiWord( menuResult ) )
- {
- doMacInMenuBar( menuResult ) ;
- }
- else
- {
- wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
- if (theMacWxFrame)
- {
- wxKeyEvent event(wxEVT_CHAR);
- event.m_shiftDown = m_event.modifiers & shiftKey;
- event.m_controlDown = m_event.modifiers & controlKey;
- event.m_altDown = m_event.modifiers & optionKey;
- event.m_metaDown = m_event.modifiers & cmdKey;
- event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
- event.m_x = m_event.where.h;
- event.m_y = m_event.where.v;
- event.m_timeStamp = m_event.when;
- event.SetEventObject(theMacWxFrame);
-
- theMacWxFrame->ProcessEvent(event);
- }
- }
- }
-}
-
-void wxApp::doMacAutoKey(void)
-{
- doMacKeyDown();
-}
-
-void wxApp::doMacKeyUp(void)
-{
-}
-
-void wxApp::doMacActivateEvt(void)
-{
- HighlightAndActivateWindow( (WindowPtr) m_event.message , m_event.modifiers & activeFlag ) ;
-}
-
-void wxApp::doMacUpdateEvt(void)
-{
- WindowPtr theMacWindow = (WindowPtr)(m_event.message);
- ::BeginUpdate(theMacWindow);
-
- wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(theMacWindow);
- if (theMacWxFrame)
- {
-// if (!::EmptyRgn(theMacWindow->visRgn)) // this doesn't work with windowshade
-// {
- if ( theMacWxFrame->MacSetupPort() )
- {
- // Erase update region
- // we must do this, because controls add their former rect to the inval
- // rgn and the background might not have been correct at that moment
- ::EraseRect(&theMacWindow->portRect);
-
- // Can't use UpdateControls since each control has it's own coordinate system
- // ::UpdateControls(theMacWindow, theMacWindow->visRgn);
-
- ::UpdateControls( theMacWindow , theMacWindow->visRgn ) ;
- #if 0
- // Draw the grow box
- if (cStyle & wxRESIZE_BORDER)
- MacDrawGrowIcon();
- #endif
-
- wxPaintEvent event;
- event.m_timeStamp = m_event.when;
- event.SetEventObject(theMacWxFrame);
-
- theMacWxFrame->ProcessEvent(event);
- // ::SetThemeWindowBackground( theMacWindow , kThemeActiveDialogBackgroundBrush , false ) ;
- ::ClipRect( &theMacWindow->portRect ) ;
- ::SetOrigin( 0 , 0 );
- }
- else
- {
- wxASSERT_MSG( false , "unabled to setup window mac port") ;
- }
-
-// }
- }
-
- ::EndUpdate(theMacWindow);
-}
-
-void wxApp::doMacDiskEvt(void)
-{ // based on "Programming for System 7" by Gary Little and Tim Swihart
- if ((m_event.message >> 16) != noErr)
- {
- const int kDILeft = 0x0050; // top coord for disk init dialog
- const int kDITop = 0x0070; // left coord for disk init dialog
- Point mountPoint;
- mountPoint.h = kDILeft;
- mountPoint.v = kDITop;
- int myError = DIBadMount(mountPoint, m_event.message);
- }
-}
-
-void wxApp::doMacOsEvt(void)
-{ // based on "Programming for System 7" by Gary Little and Tim Swihart
- switch ((m_event.message >> 24) & 0x0ff)
- {
- case suspendResumeMessage:
- if (m_event.message & resumeFlag)
- doMacResumeEvent();
- else
- doMacSuspendEvent();
- break;
- case mouseMovedMessage:
- doMacMouseMovedMessage();
- break;
- }
-}
-
-void wxApp::doMacHighLevelEvent(void)
-{
- ::AEProcessAppleEvent(&m_event); // System 7 or higher
-}
-
-void wxApp::doMacResumeEvent(void)
-{
- wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
- if (theMacWxFrame)
- {
- if (m_event.message & convertClipboardFlag)
- ::TEFromScrap();
-
- wxActivateEvent event(wxEVT_ACTIVATE, TRUE);
- event.m_timeStamp = m_event.when;
- event.SetEventObject(theMacWxFrame);
-
- theMacWxFrame->ProcessEvent(event);
- }
-}
-
-void wxApp::doMacSuspendEvent(void)
-{
- wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
- if (theMacWxFrame)
- {
- ::ZeroScrap();
- ::TEToScrap();
-
- wxActivateEvent event(wxEVT_ACTIVATE, FALSE);
- event.m_timeStamp = m_event.when;
- event.SetEventObject(theMacWxFrame);
-
- theMacWxFrame->ProcessEvent(event);
- }
-}
-
-void wxApp::doMacMouseMovedMessage(void)
-{ // based on "Programming for System 7" by Gary Little and Tim Swihart
- if (m_cursorRgn)
- ::DisposeRgn(m_cursorRgn);
- m_cursorRgn = ::NewRgn();
- ::SetRectRgn(m_cursorRgn, -32768, -32768, 32766, 32766);
-}
-
-void wxApp::doMacInMenuBar(long menuResult)
-{
- int macMenuId = HiWord(menuResult);
- int macMenuItemNum = LoWord(menuResult); // counting from 1
-
- if (macMenuId == 0) // no menu item selected;
- return;
- if (macMenuId == 128)
- {
- if (macMenuItemNum != 1)
- { // if not the "About" entry (or the separator)
- Str255 daName;
- ::GetMenuItemText(GetMenuHandle(128), macMenuItemNum, daName);
- (void)::OpenDeskAcc(daName);
- ::HiliteMenu(0);
- return;
- }
- }
-
- wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
- if (theMacWxFrame)
- {
- if ( theMacWxFrame->IsKindOf( CLASSINFO( wxDialog ) ) )
- (( wxDialog *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
- else if ( theMacWxFrame->IsKindOf( CLASSINFO( wxFrame ) ) )
- (( wxFrame *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
- }
- ::HiliteMenu(0);
-}
-
-void wxApp::doMacInContent(WindowPtr window)
-{
- WindowPtr frontWindow = FrontWindow();
- if (window != frontWindow )
- {
-// SFSelectWindow( window ) ;
- }
- else
- {
- ControlHandle control ;
- Point localwhere = m_event.where ;
- GrafPtr port ;
- SInt16 controlpart ;
-
- ::GetPort( &port ) ;
- ::SetPort( window ) ;
- ::GlobalToLocal( &localwhere ) ;
-
- ::SetPort( port ) ;
-
- if ( !gSFMacHasAppearance )
- {
- controlpart = FindControl( localwhere , window , &control ) ;
- }
- else
- {
- control = FindControlUnderMouse( localwhere , window , &controlpart ) ;
- }
-
- if ( control && IsControlActive( control ) )
- {
- wxControl* wxc = (wxControl*) GetControlReference( control ) ;
-
- if ( wxWindow::FindFocus() != wxc && wxc->AcceptsFocus() )
- {
- wxc->SetFocus() ;
- if ( wxWindow::FindFocus() != wxc )
- control = NULL ; // we were not able to change focus
- }
-
- if ( control )
- {
- if ( !gSFMacHasAppearance)
- {
- controlpart = TrackControl( control , localwhere , NULL ) ;
- }
- else
- {
- controlpart = HandleControlClick( control , localwhere , m_event.modifiers , (ControlActionUPP) -1 ) ;
- }
-
- if ( controlpart )
- {
- wxControl* wx = (wxControl*) GetControlReference( control ) ;
- if ( wx )
- wx->MacHandleControlClick( control , controlpart ) ;
- }
- }
- }
- else
- {
- wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
- if (theMacWxFrame)
- {
- doMacContentClick((wxFrame*)theMacWxFrame); // todo : this cast is wrong
- }
- }
- }
-
-#if 0
- wxFrame* theMacWxFrame = findMacWxFrame(window);
- if (theMacWxFrame)
- {
- WindowPtr MacWindow = findFrontNonFloatingWindow();
- if (window != MacWindow)
- {
- wxFrame* frontFrame = findMacWxFrame(MacWindow);
- if (!frontFrame) wxFatalError("No wxFrame for frontnonfloatingWindow.");
- if (!frontFrame->IsModal())
- {
- frontFrame->SetFocus();
- doMacContentClick(theMacWxFrame); // jonto - to deal with doc windows behind floaters ?
- ::newSelectWindow(window); // WCH : should I be calling some wxMethod?
- if (!IsFloating(MacWindow))
- {
- KeyMap keyMap;
- GetKeys(keyMap);
- if (!(keyMap[1] & 0x8000)) theMacWxFrame->ShowAsActive(true); // temporary measure...
- }
- } // jonto : not sure yet, but let's try this ...
- else ::SysBeep(3);
- }
- else
- {
- doMacContentClick(theMacWxFrame);
- }
- }
-#endif