]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/app.cpp
wxSystemSettings class API face lift: better names for its methods
[wxWidgets.git] / src / mac / carbon / app.cpp
index b27475c3f1b1006ba86adc35a53e8c03102551e7..1a02ff2e587aeacf24f0a864ab6d37b20b158502 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "wx/window.h"
 #include "wx/frame.h"
+#include "wx/button.h"
 #include "wx/app.h"
 #include "wx/utils.h"
 #include "wx/gdicmn.h"
@@ -975,19 +976,24 @@ bool wxApp::Yield(bool onlyIfNeeded)
 
 void wxApp::MacSuspend( bool convertClipboard )
 {
-    // we have to deactive the window manually
+    // we have to deactive the top level windows manually
 
-    wxWindow* window = GetTopWindow() ;
-    if ( window )
-        window->MacActivate( MacGetCurrentEvent() , false ) ;
+    wxNode* node = wxTopLevelWindows.First();
+    while (node)
+    {
+        wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
+        win->MacActivate( MacGetCurrentEvent() , false ) ;
 
-        s_lastMouseDown = 0 ;
-        if( convertClipboard )
-        {
-            MacConvertPrivateToPublicScrap() ;
-        }
+        node = node->Next();
+    }
+
+     s_lastMouseDown = 0 ;
+     if( convertClipboard )
+     {
+         MacConvertPrivateToPublicScrap() ;
+     }
 
-        ::HideFloatingWindows() ;
+     ::HideFloatingWindows() ;
 }
 
 void wxApp::MacResume( bool convertClipboard )
@@ -1110,7 +1116,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
         ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
 
     short windowPart = ::FindWindow(ev->where, &window);
-    wxWindow* win = wxFindWinFromMacWindow( window ) ;
+    wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
     if ( wxPendingDelete.Member(win) )
         return ;
 
@@ -1155,7 +1161,6 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                     #else
                     SetPort( (window) ) ;
                     #endif
-                    SetOrigin( 0 , 0 ) ;
                     LocalToGlobal( &pt ) ;
                     SetPort( port ) ;
                         win->SetSize( pt.h , pt.v , -1 ,
@@ -1226,7 +1231,6 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
                     #else
                     SetPort( (window) ) ;
                     #endif
-                    SetOrigin( 0 , 0 ) ;
                     SetPort( port ) ;
                 }
                 if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
@@ -1273,7 +1277,7 @@ void wxApp::MacHandleMouseUpEvent( EventRecord *ev )
             break ;
         default:
             {
-                wxWindow* win = wxFindWinFromMacWindow( window ) ;
+                wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
                 if ( win )
                     win->MacMouseUp( ev , windowPart ) ;
             }
@@ -1406,11 +1410,11 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
         short keychar ;
         keychar = short(ev->message & charCodeMask);
         keycode = short(ev->message & keyCodeMask) >> 8 ;
-
+        long keyval = wxMacTranslateKey(keychar, keycode) ;
+        bool handled = false ;
         wxWindow* focus = wxWindow::FindFocus() ;
         if ( focus )
         {
-            long keyval = wxMacTranslateKey(keychar, keycode) ;
 
             wxKeyEvent event(wxEVT_KEY_DOWN);
             event.m_shiftDown = ev->modifiers & shiftKey;
@@ -1422,7 +1426,7 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
             event.m_y = ev->where.v;
             event.m_timeStamp = ev->when;
             event.SetEventObject(focus);
-            bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
+            handled = focus->GetEventHandler()->ProcessEvent( event ) ;
             if ( !handled )
             {
                 #if wxUSE_ACCEL
@@ -1475,14 +1479,34 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
                 new_event.SetCurrentFocus( focus );
                 handled = focus->GetEventHandler()->ProcessEvent( new_event );
             }
+        }
+        if ( !handled )
+        {
+            // if window is not having a focus still testing for default enter or cancel
+            // TODO add the UMA version for ActiveNonFloatingWindow
+          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 ;
+                }
+            }
             /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
-            if ( (!handled) &&
-                 (keyval == '.' && event.ControlDown() ) )
+            else if (keyval == WXK_ESCAPE || (keyval == '.' && ev->modifiers & cmdKey ) )
             {
-                wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
-                new_event.SetEventObject( focus );
-                handled = focus->GetEventHandler()->ProcessEvent( new_event );
+                  wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
+                  new_event.SetEventObject( focus );
+                  handled = focus->GetEventHandler()->ProcessEvent( new_event );
             }
+          }
         }
     }
 }
@@ -1535,7 +1559,7 @@ void wxApp::MacHandleActivateEvent( EventRecord *ev )
             // if it is a floater we activate/deactivate the front non-floating window instead
             window = ::FrontNonFloatingWindow() ;
         }
-        wxWindow* win = wxFindWinFromMacWindow( window ) ;
+        wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
         if ( win )
             win->MacActivate( ev , activate ) ;
     }
@@ -1544,11 +1568,11 @@ void wxApp::MacHandleActivateEvent( EventRecord *ev )
 void wxApp::MacHandleUpdateEvent( EventRecord *ev )
 {
     WindowRef window = (WindowRef) ev->message ;
-    wxWindow * win = wxFindWinFromMacWindow( window ) ;
+    wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ;
     if ( win )
     {
         if ( !wxPendingDelete.Member(win) )
-            win->MacUpdate( ev ) ;
+            win->MacUpdate( ev->when ) ;
     }
     else
     {
@@ -1605,13 +1629,13 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
 
                     if ( oldFrontWindow )
                     {
-                        wxWindow* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
+                        wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
                         if ( win )
                             win->MacActivate( ev , false ) ;
                     }
                     if ( newFrontWindow )
                     {
-                        wxWindow* win = wxFindWinFromMacWindow( newFrontWindow ) ;
+                        wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ;
                         if ( win )
                             win->MacActivate( ev , true ) ;
                     }
@@ -1705,7 +1729,7 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
                             ::GetNextEvent(0, &tmp);
                             ev->modifiers = tmp.modifiers;
                             
-                            wxWindow* win = wxFindWinFromMacWindow( window ) ;
+                            wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
                             if ( win )
                                 win->MacMouseMoved( ev , windowPart ) ;
                             else