font retrieval synched for setsize and bestsize
[wxWidgets.git] / src / mac / carbon / toplevel.cpp
index 7a1976ac09e071a99161d20e28b91e5b9b6971c3..882781e7322c6c6fac4183b503f4b6bb33fc3cfa 100644 (file)
@@ -283,6 +283,9 @@ static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent )
     
     if ( cEvent.GetKind() == kEventMouseDown )
         lastButton = button ;
+        
+    if ( button == 0 )
+        lastButton = 0 ;    
     else if ( lastButton )
         button = lastButton ;
 
@@ -303,29 +306,38 @@ static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent )
                 break ;
         }
     }
-    // determinate the correct click button
-    if ( button == kEventMouseButtonSecondary )
-    {
-        if (cEvent.GetKind() == kEventMouseDown )
-            wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
-        else if ( cEvent.GetKind() == kEventMouseUp )
-            wxevent.SetEventType(wxEVT_RIGHT_UP ) ;
-    }
-    else if ( button == kEventMouseButtonTertiary )
-    {
-        if (cEvent.GetKind() == kEventMouseDown )
-            wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
-        else if ( cEvent.GetKind() == kEventMouseUp )
-            wxevent.SetEventType(wxEVT_MIDDLE_UP ) ;
-    }
-    else
+    // translate into wx types
+    switch ( cEvent.GetKind() )
     {
-        if (cEvent.GetKind() == kEventMouseDown )
-            wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ;
-        else if ( cEvent.GetKind() == kEventMouseUp )
-            wxevent.SetEventType(wxEVT_LEFT_UP ) ;
-        else if ( cEvent.GetKind() == kEventMouseWheelMoved )
-        {
+        case kEventMouseDown :
+            switch( button )
+            {
+                case kEventMouseButtonPrimary :
+                    wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN )  ;
+                    break ;
+                case kEventMouseButtonSecondary :
+                    wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ;
+                    break ;
+                case kEventMouseButtonTertiary :
+                    wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ;
+                    break ;
+            }
+            break ;
+        case kEventMouseUp :
+            switch( button )
+            {
+                case kEventMouseButtonPrimary :
+                    wxevent.SetEventType( wxEVT_LEFT_UP )  ;
+                    break ;
+                case kEventMouseButtonSecondary :
+                    wxevent.SetEventType( wxEVT_RIGHT_UP ) ;
+                    break ;
+                case kEventMouseButtonTertiary :
+                    wxevent.SetEventType( wxEVT_MIDDLE_UP ) ;
+                    break ;
+            }
+            break ;
+        case kEventMouseWheelMoved :
             wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ;
 
             // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
@@ -334,12 +346,11 @@ static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent )
             wxevent.m_wheelRotation = delta;
             wxevent.m_wheelDelta = 1;
             wxevent.m_linesPerAction = 1;
-        }
-        else
+            break ;
+        default :
             wxevent.SetEventType(wxEVT_MOTION ) ;
-    }
-    if ( cEvent.GetKind() == kEventMouseUp )
-        lastButton = 0 ;
+            break ;
+    }       
 }
 
 ControlRef wxMacFindSubControl( Point location , ControlRef superControl , ControlPartCode *outPart )
@@ -990,6 +1001,11 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
     // the content view, so we have to retrieve it explicitely
     HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , 
         *m_peer ) ;
+    if ( !m_peer->Ok() )
+    {
+        // compatibility mode fallback
+        GetRootControl( (WindowRef) m_macWindow , *m_peer ) ;
+    }
 #else
     ::CreateRootControl( (WindowRef)m_macWindow , *m_peer ) ;
 #endif