]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/app.cpp
fix for using wxDataObjectComposite with the clipboard
[wxWidgets.git] / src / mac / app.cpp
index 28a3bc352d8df0f696a3311d46c6f509a39aa1de..864e76018520a7cf92325d5bad8bae562e983f3f 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "wx/window.h"
 #include "wx/frame.h"
 
 #include "wx/window.h"
 #include "wx/frame.h"
+#include "wx/button.h"
 #include "wx/app.h"
 #include "wx/utils.h"
 #include "wx/gdicmn.h"
 #include "wx/app.h"
 #include "wx/utils.h"
 #include "wx/gdicmn.h"
@@ -609,6 +610,28 @@ void wxApp::CleanUp()
     #endif
 }
 
     #endif
 }
 
+//----------------------------------------------------------------------
+// wxEntry
+//----------------------------------------------------------------------
+
+int wxEntryStart( int argc, char *argv[] )
+{
+    return wxApp::Initialize();
+}
+
+
+int wxEntryInitGui()
+{
+    return wxTheApp->OnInitGui();
+}
+
+
+void wxEntryCleanup()
+{
+    wxApp::CleanUp();
+}
+
+
 int wxEntry( int argc, char *argv[] , bool enterLoop )
 {
 #ifdef __MWERKS__
 int wxEntry( int argc, char *argv[] , bool enterLoop )
 {
 #ifdef __MWERKS__
@@ -622,7 +645,7 @@ int wxEntry( int argc, char *argv[] , bool enterLoop )
     wxDebugContext::SetCheckpoint();
 #endif
 #endif
     wxDebugContext::SetCheckpoint();
 #endif
 #endif
-    if (!wxApp::Initialize()) {
+    if (!wxEntryStart(argc, argv)) {
         return 0;
     }
    // create the application object or ensure that one already exists
         return 0;
     }
    // create the application object or ensure that one already exists
@@ -639,24 +662,23 @@ int wxEntry( int argc, char *argv[] , bool enterLoop )
 
     wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
 
 
     wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
 
-#ifdef __WXMAC__
-  argc = 0 ; // currently we don't support files as parameters
+#ifndef __DARWIN__
+    argc = 0 ; // currently we don't support files as parameters
 #endif
 #endif
+    // we could try to get the open apple events here to adjust argc and argv better
 
 
-  wxTheApp->argc = argc;
-  wxTheApp->argv = argv;
+    wxTheApp->argc = argc;
+    wxTheApp->argv = argv;
 
 
-  // GUI-specific initialization, such as creating an app context.
-  wxTheApp->OnInitGui();
+    // GUI-specific initialization, such as creating an app context.
+    wxEntryInitGui();
 
 
-  // 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().
 
 
-  // Here frames insert themselves automatically
-  // into wxTopLevelWindows by getting created
-  // in OnInit().
-
-  int retValue = 0;
+    int retValue = 0;
 
     if ( wxTheApp->OnInit() )
     {
 
     if ( wxTheApp->OnInit() )
     {
@@ -689,7 +711,7 @@ int wxEntry( int argc, char *argv[] , bool enterLoop )
 
     wxTheApp->OnExit();
 
 
     wxTheApp->OnExit();
 
-    wxApp::CleanUp();
+    wxEntryCleanup();
 
     return retValue;
 }
 
     return retValue;
 }
@@ -992,11 +1014,11 @@ void wxApp::MacDoOneEvent()
 {
   EventRecord event ;
 
 {
   EventRecord event ;
 
-    long sleepTime = 1 ; // GetCaretTime() / 4 ;
+    long sleepTime = 1; // GetCaretTime() / 4 ;
 
 
-    if (WaitNextEvent(everyEvent, &event,sleepTime, s_macCursorRgn))
+    if (WaitNextEvent(everyEvent, &event, sleepTime, s_macCursorRgn))
     {
     {
-    MacHandleOneEvent( &event );
+        MacHandleOneEvent( &event );
     }
     else
     {
     }
     else
     {
@@ -1012,7 +1034,7 @@ void wxApp::MacDoOneEvent()
 
     // repeaters
 
 
     // repeaters
 
-  DeletePendingObjects() ;
+    DeletePendingObjects() ;
     wxMacProcessNotifierAndPendingEvents() ;
 }
 
     wxMacProcessNotifierAndPendingEvents() ;
 }
 
@@ -1385,11 +1407,11 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
         short keychar ;
         keychar = short(ev->message & charCodeMask);
         keycode = short(ev->message & keyCodeMask) >> 8 ;
         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 )
         {
         wxWindow* focus = wxWindow::FindFocus() ;
         if ( focus )
         {
-            long keyval = wxMacTranslateKey(keychar, keycode) ;
 
             wxKeyEvent event(wxEVT_KEY_DOWN);
             event.m_shiftDown = ev->modifiers & shiftKey;
 
             wxKeyEvent event(wxEVT_KEY_DOWN);
             event.m_shiftDown = ev->modifiers & shiftKey;
@@ -1401,7 +1423,7 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
             event.m_y = ev->where.v;
             event.m_timeStamp = ev->when;
             event.SetEventObject(focus);
             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
             if ( !handled )
             {
                 #if wxUSE_ACCEL
@@ -1454,14 +1476,34 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
                 new_event.SetCurrentFocus( focus );
                 handled = focus->GetEventHandler()->ProcessEvent( new_event );
             }
                 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) */
             /* 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 );
             }
             }
+          }
         }
     }
 }
         }
     }
 }
@@ -1670,9 +1712,20 @@ void wxApp::MacHandleOSEvent( EventRecord *ev )
                         break ;
                     default:
                         {
                         break ;
                     default:
                         {
-                            if ( s_lastMouseDown == 0 )
-                                ev->modifiers |= btnState ;
-
+                            // if ( s_lastMouseDown == 0 )
+                            //     ev->modifiers |= btnState ;
+                                
+                            // Calling GetNextEvent with a zero event mask will always
+                            // pass back a null event. However, it fills the EventRecord
+                            // with the state of the modifier keys. This is needed since
+                            // the modifier state returned by WaitForNextEvent often is
+                            // wrong mouse move events. The attempt above to correct this
+                            // didn't always work (under OS X at least).
+            
+                            EventRecord tmp;
+                            ::GetNextEvent(0, &tmp);
+                            ev->modifiers = tmp.modifiers;
+                            
                             wxWindow* win = wxFindWinFromMacWindow( window ) ;
                             if ( win )
                                 win->MacMouseMoved( ev , windowPart ) ;
                             wxWindow* win = wxFindWinFromMacWindow( window ) ;
                             if ( win )
                                 win->MacMouseMoved( ev , windowPart ) ;