]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/app.cpp
??
[wxWidgets.git] / src / mac / app.cpp
index 7d28b4bb304cc63538e7159b52e8ace2a62bb191..d5bb4c82d188b089dd992d65a076b4d0473353c1 100644 (file)
@@ -39,7 +39,7 @@
 
 #if __option(profile)
        #include <profiler.h>
-#endif 
+#endif
 
 #include "apprsrc.h"
 
@@ -52,12 +52,10 @@ extern wxList *wxWinMacControlList;
 
 wxApp *wxTheApp = NULL;
 
-#if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
     EVT_IDLE(wxApp::OnIdle)
 END_EVENT_TABLE()
-#endif
 
 
 const short    kMacMinHeap = (29 * 1024) ;
@@ -102,7 +100,7 @@ OSErr AEHandleQuit( AppleEvent *event , AppleEvent *reply , long refcon )
        return wxTheApp->MacHandleAEQuit( event , reply) ;
 }
 
-OSErr wxApp::MacHandleAEODoc(AppleEvent *event , AppleEvent *reply) 
+OSErr wxApp::MacHandleAEODoc(AppleEvent *event , AppleEvent *reply)
 {
        ProcessSerialNumber PSN ;
        PSN.highLongOfPSN = 0 ;
@@ -111,17 +109,17 @@ OSErr wxApp::MacHandleAEODoc(AppleEvent *event , AppleEvent *reply)
        return noErr ;
 }
 
-OSErr wxApp::MacHandleAEPDoc(AppleEvent *event , AppleEvent *reply) 
+OSErr wxApp::MacHandleAEPDoc(AppleEvent *event , AppleEvent *reply)
 {
        return noErr ;
 }
 
-OSErr wxApp::MacHandleAEOApp(AppleEvent *event , AppleEvent *reply) 
+OSErr wxApp::MacHandleAEOApp(AppleEvent *event , AppleEvent *reply)
 {
        return noErr ;
 }
 
-OSErr wxApp::MacHandleAEQuit(AppleEvent *event , AppleEvent *reply) 
+OSErr wxApp::MacHandleAEQuit(AppleEvent *event , AppleEvent *reply)
 {
        wxWindow* win = GetTopWindow() ;
        if ( win )
@@ -160,7 +158,7 @@ void wxMacConvertFromPC( const char *from , char *to , int len )
                        if ( c != NULL )
                        {
                                *to = StringMac[ c - StringANSI] ;
-                       }       
+                       }
                        ++to ;
                        ++from ;
                }
@@ -173,7 +171,7 @@ void wxMacConvertFromPC( const char *from , char *to , int len )
                        if ( c != NULL )
                        {
                                *to = StringMac[ c - StringANSI] ;
-                       }       
+                       }
                        else
                        {
                                *to = *from ;
@@ -195,7 +193,7 @@ void wxMacConvertToPC( const char *from , char *to , int len )
                        if ( c != NULL )
                        {
                                *to = StringANSI[ c - StringMac] ;
-                       }       
+                       }
                        ++to ;
                        ++from ;
                }
@@ -208,7 +206,7 @@ void wxMacConvertToPC( const char *from , char *to , int len )
                        if ( c != NULL )
                        {
                                *to = StringANSI[ c - StringMac] ;
-                       }       
+                       }
                        else
                        {
                                *to = *from ;
@@ -219,19 +217,19 @@ void wxMacConvertToPC( const char *from , char *to , int len )
        }
 }
 
-void wxMacConvertFromPC( char * p ) 
+void wxMacConvertFromPC( char * p )
 {
        char *ptr = p ;
        int len = strlen ( p ) ;
-       
+
        wxMacConvertFromPC( ptr , ptr , len ) ;
 }
 
-void wxMacConvertFromPCForControls( char * p ) 
+void wxMacConvertFromPCForControls( char * p )
 {
        char *ptr = p ;
        int len = strlen ( p ) ;
-       
+
        wxMacConvertFromPC( ptr , ptr , len ) ;
        for ( int i = 0 ; i < strlen ( ptr ) ; i++ )
        {
@@ -242,22 +240,22 @@ void wxMacConvertFromPCForControls( char * p )
        }
 }
 
-void wxMacConvertFromPC( unsigned char *p ) 
+void wxMacConvertFromPC( unsigned char *p )
 {
        char *ptr = (char*) p + 1 ;
        int len = p[0] ;
-       
+
        wxMacConvertFromPC( ptr , ptr , len ) ;
 }
 
 extern char *wxBuffer ;
 
-wxString wxMacMakeMacStringFromPC( const char * p ) 
+wxString wxMacMakeMacStringFromPC( const char * p )
 {
        const char *ptr = p ;
        int len = strlen ( p ) ;
        char *buf = wxBuffer ;
-       
+
        if ( len >= BUFSIZ + 512 )
        {
                buf = new char [len+1] ;
@@ -272,28 +270,28 @@ wxString wxMacMakeMacStringFromPC( const char * p )
 }
 
 
-void wxMacConvertToPC( char * p ) 
+void wxMacConvertToPC( char * p )
 {
        char *ptr = p ;
        int len = strlen ( p ) ;
-       
+
        wxMacConvertToPC( ptr , ptr , len ) ;
 }
 
-void wxMacConvertToPC( unsigned char *p ) 
+void wxMacConvertToPC( unsigned char *p )
 {
        char *ptr = (char*) p + 1 ;
        int len = p[0] ;
-       
+
        wxMacConvertToPC( ptr , ptr , len ) ;
 }
 
-wxString wxMacMakePCStringFromMac( const char * p ) 
+wxString wxMacMakePCStringFromMac( const char * p )
 {
        const char *ptr = p ;
        int len = strlen ( p ) ;
        char *buf = wxBuffer ;
-       
+
        if ( len >= BUFSIZ + 512 )
        {
                buf = new char [len+1] ;
@@ -301,7 +299,7 @@ wxString wxMacMakePCStringFromMac( const char * p )
 
        wxMacConvertToPC( ptr , buf , len ) ;
        buf[len] = 0 ;
-       
+
        wxString result( buf ) ;
        if ( buf != wxBuffer )
                delete buf ;
@@ -313,9 +311,9 @@ wxString wxMacMakePCStringFromMac( const char * p )
 bool wxApp::Initialize()
 {
   int error = 0 ;
-       
+
   // Mac-specific
-  
+
   UMAInitToolbox( 4 ) ;
        UMAShowWatchCursor() ;
 
@@ -327,7 +325,7 @@ bool wxApp::Initialize()
        GUSISetup(GUSIwithInternetSockets);
 #endif
 
-       
+
   // test the minimal configuration necessary
 
        long theSystem ;
@@ -344,7 +342,7 @@ bool wxApp::Initialize()
        else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr )
        {
                error = kMacSTROldSystem  ;
-       }       
+       }
        else if ( theSystem < 0x0750 )
        {
                error = kMacSTROldSystem  ;
@@ -366,9 +364,9 @@ bool wxApp::Initialize()
        */
 
        // if we encountered any problems so far, give the error code and exit immediately
-       
+
   if ( error )
-  {    
+  {
                short itemHit;
                Str255 message;
 
@@ -377,16 +375,16 @@ bool wxApp::Initialize()
                ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p");
                itemHit = Alert(128, nil);
          return FALSE ;
-  }  
+  }
 
 #if __option(profile)
        ProfilerInit( collectDetailed, bestTimeBase , 20000 , 30 ) ;
-#endif 
+#endif
 
   // now avoid exceptions thrown for new (bad_alloc)
-  
+
   std::__throws_bad_alloc = FALSE ;
-  
+
        s_macCursorRgn = ::NewRgn() ;
 
 #ifdef __WXMSW__
@@ -403,7 +401,7 @@ bool wxApp::Initialize()
   wxDebugContext::SetStream(oStr, sBuf);
 #endif
 */
-  
+
   wxClassInfo::InitializeClasses();
 
   wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
@@ -426,7 +424,7 @@ bool wxApp::Initialize()
   wxWinMacControlList = new wxList(wxKEY_INTEGER);
 
        UMAShowArrowCursor() ;
-  
+
   return TRUE;
 }
 
@@ -470,11 +468,11 @@ void wxApp::CleanUp()
 #if __option(profile)
        ProfilerDump( "\papp.prof" ) ;
        ProfilerTerm() ;
-#endif 
+#endif
 
   delete wxTheApp;
   wxTheApp = NULL;
-  
+
 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
   // At this point we want to check if there are any memory
   // blocks that aren't part of the wxDebugContext itself,
@@ -488,7 +486,7 @@ void wxApp::CleanUp()
   }
 //  wxDebugContext::SetStream(NULL, NULL);
 #endif
-  
+
   // do it as the very last thing because everything else can log messages
   wxLog::DontCreateOnDemand();
   // do it as the very last thing because everything else can log messages
@@ -504,6 +502,17 @@ void wxApp::CleanUp()
 
 int wxEntry( int argc, char *argv[] )
 {
+#ifdef __MWERKS__
+#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
+    // This seems to be necessary since there are 'rogue'
+    // objects present at this point (perhaps global objects?)
+    // Setting a checkpoint will ignore them as far as the
+    // memory checking facility is concerned.
+    // Of course you may argue that memory allocated in globals should be
+    // checked, but this is a reasonable compromise.
+    wxDebugContext::SetCheckpoint();
+#endif
+#endif
   if (!wxApp::Initialize())
     return FALSE;
   if (!wxTheApp)
@@ -513,11 +522,11 @@ int wxEntry( int argc, char *argv[] )
       printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
       return 0;
     };
-    
+
        wxTheApp = (wxApp*) (* wxApp::GetInitializerFunction()) ();
   };
-  
-  if (!wxTheApp) 
+
+  if (!wxTheApp)
   {
     printf( "wxWindows error: wxTheApp == NULL\n" );
     return 0;
@@ -532,18 +541,18 @@ int wxEntry( int argc, char *argv[] )
 
   // GUI-specific initialization, such as creating an app context.
   wxTheApp->OnInitGui();
-  
+
   // we could try to get the open apple events here to adjust argc and argv better
-  
+
 
   // Here frames insert themselves automatically
   // into wxTopLevelWindows by getting created
   // in OnInit().
-  
+
   if (!wxTheApp->OnInit()) return 0;
 
   int retValue = 0;
-  
+
   if (wxTheApp->Initialized()) retValue = wxTheApp->OnRun();
 
   if (wxTheApp->GetTopWindow())
@@ -551,11 +560,11 @@ int wxEntry( int argc, char *argv[] )
     delete wxTheApp->GetTopWindow();
     wxTheApp->SetTopWindow(NULL);
   }
-  
-  wxTheApp->DeletePendingObjects();  
-  
+
+  wxTheApp->DeletePendingObjects();
+
   wxTheApp->OnExit();
-  
+
   wxApp::CleanUp();
 
   return retValue;
@@ -656,6 +665,12 @@ void wxApp::OnIdle(wxIdleEvent& event)
   inOnIdle = FALSE;
 }
 
+void wxWakeUpIdle()
+{
+    // **** please implement me! ****
+    // Wake up the idle handler processor, even if it is in another thread...
+}
+
 // Send idle event to all top-level windows
 bool wxApp::SendIdleEvents()
 {
@@ -702,7 +717,7 @@ void wxApp::DeletePendingObjects()
   while (node)
   {
     wxObject *obj = (wxObject *)node->Data();
-    
+
     delete obj;
 
     if (wxPendingDelete.Member(obj))
@@ -743,27 +758,27 @@ bool wxYield()
   return TRUE;
 }
 
-// platform specifics 
+// platform specifics
 
 void wxApp::MacSuspend( bool convertClipboard )
 {
                s_lastMouseDown = 0 ;
-               if( convertClipboard ) 
+               if( convertClipboard )
                {
                        MacConvertPrivateToPublicScrap() ;
                }
-               
+
                UMAHideFloatingWindows() ;
 }
 
 void wxApp::MacResume( bool convertClipboard )
 {
                s_lastMouseDown = 0 ;
-               if( convertClipboard ) 
+               if( convertClipboard )
                {
                        MacConvertPublicToPrivateScrap() ;
                }
-               
+
                UMAShowFloatingWindows() ;
 }
 
@@ -778,7 +793,7 @@ void wxApp::MacConvertPublicToPrivateScrap()
        ::TEFromScrap() ;
 }
 
-void wxApp::MacDoOneEvent() 
+void wxApp::MacDoOneEvent()
 {
   EventRecord event ;
 
@@ -794,7 +809,7 @@ void wxApp::MacDoOneEvent()
                WindowPtr window = UMAFrontWindow() ;
                if ( window )
                        UMAIdleControls( window ) ;
-                       
+
                wxTheApp->ProcessIdle() ;
        }
        if ( event.what != kHighLevelEvent )
@@ -803,16 +818,16 @@ void wxApp::MacDoOneEvent()
        // repeaters
 
 #if 0
-       wxMacProcessSocketEvents() ;  
+       wxMacProcessSocketEvents() ;
 #endif
 }
 
-void wxApp::MacHandleOneEvent( EventRecord *ev ) 
+void wxApp::MacHandleOneEvent( EventRecord *ev )
 {
        m_macCurrentEvent = ev ;
-       
+
        wxApp::sm_lastMessageTime = ev->when ;
-       
+
        switch (ev->what)
        {
                case mouseDown:
@@ -830,7 +845,7 @@ void wxApp::MacHandleOneEvent( EventRecord *ev )
                        else
                        {
                                ev->modifiers &= ~controlKey ;
-                       }                       
+                       }
                        MacHandleMouseUpEvent( ev ) ;
                        s_lastMouseDown = 0;
                        break;
@@ -875,14 +890,14 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
        WindowAttributes frontWindowAttributes = NULL ;
        if ( frontWindow )
                UMAGetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
-       
+
        short windowPart = ::FindWindow(ev->where, &window);
        wxWindow* win = wxFindWinFromMacWindow( window ) ;
-       
+
        switch (windowPart)
        {
                case inMenuBar :
-                       if ( s_macIsInModalLoop ) 
+                       if ( s_macIsInModalLoop )
                        {
                                SysBeep ( 30 ) ;
                        }
@@ -914,7 +929,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                                        SetOrigin( 0 , 0 ) ;
                                        LocalToGlobal( &pt ) ;
                                        SetPort( port ) ;
-                                               win->SetSize( pt.h , pt.v , -1 , 
+                                               win->SetSize( pt.h , pt.v , -1 ,
                                                        -1 , wxSIZE_USE_EXISTING);
                                }
                                s_lastMouseDown = 0;
@@ -935,13 +950,13 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                                        int newWidth = LoWord(growResult);
                                        int newHeight = HiWord(growResult);
                                        int oldWidth, oldHeight;
-                                       
+
                                        win->GetSize(&oldWidth, &oldHeight);
-                                       if (newWidth == 0) 
+                                       if (newWidth == 0)
                                                newWidth = oldWidth;
-                                       if (newHeight == 0) 
+                                       if (newHeight == 0)
                                                newHeight = oldHeight;
-                                       
+
                                        if (win)
                                                win->SetSize( -1, -1, newWidth, newHeight, wxSIZE_USE_EXISTING);
                                }
@@ -954,7 +969,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                                        // TODO setup size event
                                        ZoomWindow( window , windowPart , false ) ;
                                        if (win)
-                                               win->SetSize( -1, -1, window->portRect.right-window->portRect.left , 
+                                               win->SetSize( -1, -1, window->portRect.right-window->portRect.left ,
                                                        window->portRect.bottom-window->portRect.top, wxSIZE_USE_EXISTING);
                                }
                        s_lastMouseDown = 0;
@@ -967,7 +982,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                case inContent :
                                if ( window != frontWindow )
                                {
-                                       if ( s_macIsInModalLoop ) 
+                                       if ( s_macIsInModalLoop )
                                        {
                                                SysBeep ( 30 ) ;
                                        }
@@ -987,7 +1002,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                                                win->MacMouseDown( ev , windowPart ) ;
                                }
                        break ;
-                       
+
                default:
                        break;
        }
@@ -996,9 +1011,9 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
 void wxApp::MacHandleMouseUpEvent( EventRecord *ev )
 {
        WindowRef window;
-       
+
        short windowPart = ::FindWindow(ev->where, &window);
-       
+
        switch (windowPart)
        {
                case inMenuBar :
@@ -1015,109 +1030,112 @@ void wxApp::MacHandleMouseUpEvent( EventRecord *ev )
        }
 }
 
-long wxMacTranslateKey(char key, char code)
-{ 
-    switch (key) 
+long wxMacTranslateKey(unsigned char key, unsigned char code)
+{
+       long retval = key ;
+    switch (key)
     {
        case 0x01 :
-                               key = WXK_HOME;
+                               retval = WXK_HOME;
                  break;
        case 0x03 :
-                               key = WXK_RETURN;
+                               retval = WXK_RETURN;
                  break;
        case 0x04 :
-                               key = WXK_END;
+                               retval = WXK_END;
                  break;
        case 0x05 :
-                               key = WXK_HELP;
+                               retval = WXK_HELP;
                  break;
        case 0x08 :
-                               key = WXK_BACK;
+                               retval = WXK_BACK;
                  break;
        case 0x09 :
-                               key = WXK_TAB;
+                               retval = WXK_TAB;
                  break;
        case 0x0b :
-                               key = WXK_PAGEUP;
+                               retval = WXK_PAGEUP;
                  break;
        case 0x0c :
-                               key = WXK_PAGEDOWN;
+                               retval = WXK_PAGEDOWN;
                  break;
        case 0x0d :
-                               key = WXK_RETURN;
+                               retval = WXK_RETURN;
                  break;
                        case 0x10 :
                        {
                                switch( code )
                                {
                                        case 0x7a :
-                                               key = WXK_F1 ;
+                                               retval = WXK_F1 ;
                                                break;
                                        case 0x78 :
-                                               key = WXK_F2 ;
+                                               retval = WXK_F2 ;
                                                break;
                                        case 0x63 :
-                                               key = WXK_F3 ;
+                                               retval = WXK_F3 ;
                                                break;
                                        case 0x76 :
-                                               key = WXK_F4 ;
+                                               retval = WXK_F4 ;
                                                break;
                                        case 0x60 :
-                                               key = WXK_F5 ;
+                                               retval = WXK_F5 ;
                                                break;
                                        case 0x61 :
-                                               key = WXK_F6 ;
+                                               retval = WXK_F6 ;
                                                break;
                                        case 0x62:
-                                               key = WXK_F7 ;
+                                               retval = WXK_F7 ;
                                                break;
                                        case 0x64 :
-                                               key = WXK_F8 ;
+                                               retval = WXK_F8 ;
                                                break;
                                        case 0x65 :
-                                               key = WXK_F9 ;
+                                               retval = WXK_F9 ;
                                                break;
                                        case 0x6D :
-                                               key = WXK_F10 ;
+                                               retval = WXK_F10 ;
                                                break;
                                        case 0x67 :
-                                               key = WXK_F11 ;
+                                               retval = WXK_F11 ;
                                                break;
                                        case 0x6F :
-                                               key = WXK_F12 ;
+                                               retval = WXK_F12 ;
                                                break;
                                        case 0x69 :
-                                               key = WXK_F13 ;
+                                               retval = WXK_F13 ;
                                                break;
                                        case 0x6B :
-                                               key = WXK_F14 ;
+                                               retval = WXK_F14 ;
                                                break;
                                        case 0x71 :
-                                               key = WXK_F15 ;
+                                               retval = WXK_F15 ;
                                                break;
                                }
                        }
                        break ;
                        case 0x1b :
-                               key = WXK_DELETE ;
+                               retval = WXK_ESCAPE ;
                        break ;
                        case 0x1c :
-                               key = WXK_LEFT ;
+                               retval = WXK_LEFT ;
                        break ;
                        case 0x1d :
-                               key = WXK_RIGHT ;
+                               retval = WXK_RIGHT ;
                        break ;
                        case 0x1e :
-                               key = WXK_UP ;
+                               retval = WXK_UP ;
                        break ;
                        case 0x1f :
-                               key = WXK_DOWN ;
+                               retval = WXK_DOWN ;
                        break ;
+                       case 0x7F :
+                               retval = WXK_DELETE ;
                        default:
                        break ;
        } // end switch
-       
-       return key;
+
+       return retval;
 }
 
 void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
@@ -1130,22 +1148,84 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
                short keycode ;
                short keychar ;
                keychar = short(ev->message & charCodeMask);
-               keycode = short(ev->message & keyCodeMask) >> 8 ; 
-               
+               keycode = short(ev->message & keyCodeMask) >> 8 ;
+
                wxWindow* focus = wxWindow::FindFocus() ;
                if ( focus )
                {
-                       wxKeyEvent event(wxEVT_CHAR);
+                       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 = wxMacTranslateKey(keychar, keycode);
+                       event.m_keyCode = keyval;
                        event.m_x = ev->where.h;
                        event.m_y = ev->where.v;
                        event.m_timeStamp = ev->when;
                        event.SetEventObject(focus);
-                       focus->GetEventHandler()->ProcessEvent( event ) ;
+                       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 );
+                   }
                }
        }
 }
@@ -1191,7 +1271,7 @@ void wxApp::MacHandleDiskEvent( EventRecord *ev )
                OSErr err ;
                Point point ;
                SetPt( &point , 100 , 100 ) ;
-               
+
        err = DIBadMount( point , ev->message ) ;
                wxASSERT( err == noErr ) ;
        }
@@ -1210,17 +1290,17 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
                                {
                                        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 ) ;
@@ -1235,12 +1315,12 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
                                        }
                                }
                                else
-                               {                       
+                               {
                                        MacSuspend( convertClipboard ) ;
-                               
-                                       // in case this suspending did close an active window, another one might 
+
+                                       // in case this suspending did close an active window, another one might
                                        // have surfaced -> lets deactivate that one
-                                       
+
                                        WindowRef newActiveWindow = UMAGetActiveNonFloatingWindow() ;
                                        if ( newActiveWindow )
                                        {
@@ -1254,30 +1334,30 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
                case mouseMovedMessage :
                        {
                                WindowRef window;
-                               
+
                                wxWindow* currentMouseWindow = NULL ;
-                               
-                               MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , &currentMouseWindow ) ; 
-                               
+
+                               MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , &currentMouseWindow ) ;
+
                                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_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_metaDown = ev->modifiers & cmdKey;
                                        event.m_x = ev->where.h;
-                                       event.m_y = ev->where.v;                                        
+                                       event.m_y = ev->where.v;
                                        event.m_timeStamp = ev->when;
                                        event.SetEventObject(this);
-                                       
+
                                        if ( wxWindow::s_lastMouseWindow )
                                        {
                                                wxMouseEvent eventleave(event ) ;
@@ -1292,9 +1372,9 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
                                        }
                                        wxWindow::s_lastMouseWindow = currentMouseWindow ;
                                }
-                               
+
                                short windowPart = ::FindWindow(ev->where, &window);
-                               
+
                                switch (windowPart)
                                {
                                        case inMenuBar :
@@ -1302,7 +1382,7 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
                                        case inSysWindow :
                                                break ;
                                        default:
-                                               {                                                       
+                                               {
                                                        if ( s_lastMouseDown == 0 )
                                                                ev->modifiers |= btnState ;
 
@@ -1314,21 +1394,21 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
                                }
                        }
                        break ;
-                       
+
        }
 }
 
 void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
 {
-       if (macMenuId == 0)                                     
+       if (macMenuId == 0)
                 return; // no menu item selected
-                
-       if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1) 
+
+       if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1)
        {
                #if ! TARGET_CARBON
                Str255          deskAccessoryName ;
                GrafPtr         savedPort ;
-               
+
                GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName);
                GetPort(&savedPort);
                OpenDeskAcc(deskAccessoryName);
@@ -1340,8 +1420,8 @@ void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
                wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() )  ;
                if ( frontwindow && wxMenuBar::MacGetInstalledMenuBar() )
                        wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ;
-       }               
-       HiliteMenu(0);                                                          
+       }
+       HiliteMenu(0);
 }
 
 /*
@@ -1368,4 +1448,4 @@ wxApp::macAdjustCursor()
        }
   }
 }
-*/
\ No newline at end of file
+*/