]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/carbon/window.cpp
clang compat.
[wxWidgets.git] / src / osx / carbon / window.cpp
index 87c1eb5d8985fe1e7fbb1a32349b35a183e6da46..aa7fc3fd3400aa2879555cfd34eea65e7f53921a 100644 (file)
@@ -65,7 +65,7 @@
 #include "wx/osx/uma.h"
 #else
 #include "wx/osx/private.h"
-// bring in themeing
+// bring in theming
 #include <Carbon/Carbon.h>
 #endif
 
 #define wxMAC_DEBUG_REDRAW 0
 #endif
 
+// Get the window with the focus
+WXWidget wxWidgetImpl::FindFocus()
+{
+    ControlRef control = NULL ;
+    GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
+    return control;
+}
+
 // ---------------------------------------------------------------------------
 // Carbon Events
 // ---------------------------------------------------------------------------
@@ -176,12 +184,17 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
 #endif
 
                 {
-                    bool created = false ;
                     CGContextRef cgContext = NULL ;
                     OSStatus err = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) ;
                     if ( err != noErr )
                     {
-                        wxFAIL_MSG("Unable to retrieve CGContextRef");
+                        // for non-composite drawing, since we don't support it ourselves, send it through the
+                        // the default handler
+                        // CallNextEventHandler( handler,event ) ;
+                        // result = noErr ;
+                        if ( allocatedRgn )
+                            CFRelease( allocatedRgn ) ;
+                        break;
                     }
 
                     thisWindow->MacSetCGContextRef( cgContext ) ;
@@ -200,7 +213,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                                     iter = iter->GetParent() ;
                             }
                         }
-                        CGContextSetAlpha( cgContext , alpha ) ;
+                        CGContextSetAlpha( cgContext, alpha ) ;
 
                         if ( thisWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
                         {
@@ -217,20 +230,24 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                             if ( !thisWindow->MacDoRedraw( cEvent.GetTicks() ) )
                             {
                                // for native controls: call their native paint method
-                                if ( !thisWindow->MacIsUserPane() || 
+                                if ( !thisWindow->MacIsUserPane() ||
                                     ( thisWindow->IsTopLevel() && thisWindow->GetBackgroundStyle() == wxBG_STYLE_SYSTEM ) )
                                 {
                                     if ( thisWindow->GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT )
-                                        CallNextEventHandler( handler ,event ) ;
+                                    {
+                                        CallNextEventHandler( handler,event ) ;
+                                        result = noErr ;
+                                    }
                                 }
                             }
+                            else
+                            {
+                                result = noErr ;
+                            }
                             thisWindow->MacPaintChildrenBorders();
                         }
                         thisWindow->MacSetCGContextRef( NULL ) ;
                     }
-
-                    if ( created )
-                        CGContextRelease( cgContext ) ;
                 }
 
                 if ( allocatedRgn )
@@ -298,8 +315,8 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                         thisWindow->GetCaret()->OnKillFocus();
 #endif
 
-                    wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
-                    
+                    wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
+
                     // remove this as soon as posting the synthesized event works properly
                     static bool inKillFocusEvent = false ;
 
@@ -318,7 +335,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                 {
                     // set focus
                     // panel wants to track the window which was the last to have focus in it
-                    wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
+                    wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
                     wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
                     thisWindow->HandleWindowEvent(eventFocus);
 
@@ -346,14 +363,14 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                 if ( controlPart != kControlFocusNoPart )
                 {
                     targetFocusWindow = thisWindow;
-                    wxLogTrace(_T("Focus"), _T("focus to be set(%p)"), static_cast<void*>(thisWindow));
+                    wxLogTrace(wxT("Focus"), wxT("focus to be set(%p)"), static_cast<void*>(thisWindow));
                 }
                 else
                 {
                     formerFocusWindow = thisWindow;
-                    wxLogTrace(_T("Focus"), _T("focus to be lost(%p)"), static_cast<void*>(thisWindow));
+                    wxLogTrace(wxT("Focus"), wxT("focus to be lost(%p)"), static_cast<void*>(thisWindow));
                 }
-                
+
                 ControlPartCode previousControlPart = 0;
                 verify_noerr( HIViewGetFocusPart(controlRef, &previousControlPart));
 
@@ -386,7 +403,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                         iEvent.SetParameter<EventTargetRef>( kEventParamPostTarget, typeEventTargetRef, GetControlEventTarget( controlRef ) );
                         iEvent.SetParameter<ControlPartCode>( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart );
                         iEvent.SetParameter<ControlPartCode>( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart );
-        
+
 #if 1
                         // TODO test this first, avoid double posts etc...
                         PostEventToQueue( GetMainEventQueue(), evRef , kEventPriorityHigh );
@@ -404,7 +421,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                             thisWindow->GetCaret()->OnKillFocus();
 #endif
 
-                        wxLogTrace(_T("Focus"), _T("focus lost(%p)"), static_cast<void*>(thisWindow));
+                        wxLogTrace(wxT("Focus"), wxT("focus lost(%p)"), static_cast<void*>(thisWindow));
 
                         static bool inKillFocusEvent = false ;
 
@@ -420,7 +437,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                     else
                     {
                         // panel wants to track the window which was the last to have focus in it
-                        wxLogTrace(_T("Focus"), _T("focus set(%p)"), static_cast<void*>(thisWindow));
+                        wxLogTrace(wxT("Focus"), wxT("focus set(%p)"), static_cast<void*>(thisWindow));
                         wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
                         thisWindow->HandleWindowEvent(eventFocus);
 
@@ -568,7 +585,7 @@ wxMacWindowServiceEventHandler(EventHandlerCallRef WXUNUSED(handler),
     return result ;
 }
 
-pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
+WXDLLEXPORT pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
 {
     OSStatus result = eventNotHandledErr ;
     wxWindowMac* focus = (wxWindowMac*) data ;
@@ -593,14 +610,9 @@ pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , Even
         uniChars = new wchar_t[ numChars ] ;
         GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ;
         charBuf[ numChars - 1 ] = 0;
-#if SIZEOF_WCHAR_T == 2
-        uniChars = (wchar_t*) charBuf ;
-/*        memcpy( uniChars , charBuf , numChars * 2 ) ;*/   // is there any point in copying charBuf over itself? (in fact, memcpy isn't even guaranteed to work correctly if the source and destination ranges overlap...)
-#else
         // the resulting string will never have more chars than the utf16 version, so this is safe
         wxMBConvUTF16 converter ;
         numChars = converter.MB2WC( uniChars , (const char*)charBuf , numChars ) ;
-#endif
     }
 
     switch ( GetEventKind( event ) )
@@ -781,7 +793,7 @@ pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode p
     {
         wxWindow*  wx = wxFindWindowFromWXWidget(  (WXWidget) control ) ;
         if ( wx )
-        {   
+        {
             wxEventType scrollEvent = wxEVT_NULL;
             switch ( partCode )
             {
@@ -814,12 +826,17 @@ pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode p
 }
 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ;
 
-wxWidgetImplType* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
-                            long style, long extraStyle)
+wxWidgetImplType* wxWidgetImpl::CreateUserPane( wxWindowMac* wxpeer,
+                            wxWindowMac* WXUNUSED(parent),
+                            wxWindowID WXUNUSED(id),
+                            const wxPoint& pos,
+                            const wxSize& size,
+                            long WXUNUSED(style),
+                            long WXUNUSED(extraStyle))
 {
     OSStatus err = noErr;
     Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ;
-    wxMacControl* c = new wxMacControl(wxpeer) ;
+    wxMacControl* c = new wxMacControl(wxpeer, false, true) ;
     UInt32 features = 0
         | kControlSupportsEmbedding
         | kControlSupportsLiveFeedback
@@ -851,8 +868,8 @@ wxMacControl::wxMacControl()
     Init();
 }
 
-wxMacControl::wxMacControl(wxWindowMac* peer , bool isRootControl ) :
-    wxWidgetImpl( peer, isRootControl )
+wxMacControl::wxMacControl(wxWindowMac* peer , bool isRootControl, bool isUserPane ) :
+    wxWidgetImpl( peer, isRootControl, isUserPane )
 {
     Init();
 }
@@ -909,7 +926,7 @@ void wxMacControl::Raise()
 {
     verify_noerr( HIViewSetZOrder( m_controlRef, kHIViewZOrderAbove, NULL ) );
 }
-    
+
 void wxMacControl::Lower()
 {
     verify_noerr( HIViewSetZOrder( m_controlRef, kHIViewZOrderBelow, NULL ) );
@@ -918,13 +935,16 @@ void wxMacControl::Lower()
 void wxMacControl::GetContentArea(int &left , int &top , int &width , int &height) const
 {
     HIShapeRef rgn = NULL;
-    Rect content ;  
+    Rect content ;
 
     if ( HIViewCopyShape(m_controlRef, kHIViewContentMetaPart, &rgn) == noErr)
     {
         CGRect cgrect;
         HIShapeGetBounds(rgn, &cgrect);
-        content = (Rect){ cgrect.origin.y, cgrect.origin.x, cgrect.origin.y+cgrect.size.height, cgrect.origin.x+cgrect.size.width };
+        content = (Rect){ (short)cgrect.origin.y,
+                          (short)cgrect.origin.x,
+                          (short)(cgrect.origin.y+cgrect.size.height),
+                          (short)(cgrect.origin.x+cgrect.size.width) };
         CFRelease(rgn);
     }
     else
@@ -945,7 +965,17 @@ void wxMacControl::GetContentArea(int &left , int &top , int &width , int &heigh
 
 void wxMacControl::Move(int x, int y, int width, int height)
 {
+    UInt32 attr = 0 ;
+    GetWindowAttributes( GetControlOwner(m_controlRef) , &attr ) ;
+
     HIRect hir = CGRectMake(x,y,width,height);
+    if ( !(attr & kWindowCompositingAttribute) )
+    {
+        HIRect parent;
+        HIViewGetFrame( HIViewGetSuperview(m_controlRef), &parent );
+        hir.origin.x += parent.origin.x;
+        hir.origin.y += parent.origin.y;
+    }
     HIViewSetFrame ( m_controlRef , &hir );
 }
 
@@ -955,6 +985,18 @@ void wxMacControl::GetPosition( int &x, int &y ) const
     GetControlBounds( m_controlRef , &r );
     x = r.left;
     y = r.top;
+
+    UInt32 attr = 0 ;
+    GetWindowAttributes( GetControlOwner(m_controlRef) , &attr ) ;
+
+    if ( !(attr & kWindowCompositingAttribute) )
+    {
+        HIRect parent;
+        HIViewGetFrame( HIViewGetSuperview(m_controlRef), &parent );
+        x -= (int)parent.origin.x;
+        y -= (int)parent.origin.y;
+    }
+
 }
 
 void wxMacControl::GetSize( int &width, int &height ) const
@@ -965,7 +1007,7 @@ void wxMacControl::GetSize( int &width, int &height ) const
     height = r.bottom - r.top;
 }
 
-void wxMacControl::SetControlSize( wxWindowVariant variant ) 
+void wxMacControl::SetControlSize( wxWindowVariant variant )
 {
     ControlSize size ;
     switch ( variant )
@@ -988,7 +1030,7 @@ void wxMacControl::SetControlSize( wxWindowVariant variant )
             break ;
 
         default:
-            wxFAIL_MSG(_T("unexpected window variant"));
+            wxFAIL_MSG(wxT("unexpected window variant"));
             break ;
     }
 
@@ -1071,7 +1113,7 @@ bool wxMacControl::SetFocus()
     if ( err == errCouldntSetFocus )
         return false ;
     SetUserFocusWindow(GetControlOwner( m_controlRef ) );
-    
+
     return true;
 }
 
@@ -1228,7 +1270,7 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l
             flush = kHIThemeTextHorizontalFlushCenter;
         else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
             flush = kHIThemeTextHorizontalFlushRight;
-        HIViewSetTextFont( m_controlRef , part , (CTFontRef) font.MacGetCTFont() );
+        HIViewSetTextFont( m_controlRef , part , (CTFontRef) font.OSXGetCTFont() );
         HIViewSetTextHorizontalFlush( m_controlRef, part, flush );
 
         if ( foreground != *wxBLACK || ignoreBlack == false )
@@ -1269,7 +1311,7 @@ void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , l
     {
         fontStyle.font = font.MacGetFontNum();
         fontStyle.style = font.MacGetFontStyle();
-        fontStyle.size = font.MacGetFontSize();
+        fontStyle.size = font.GetPointSize();
         fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask;
     }
 
@@ -1299,6 +1341,22 @@ void wxMacControl::SetBackgroundColour( const wxColour &WXUNUSED(col) )
 //    HITextViewSetBackgroundColor( m_textView , color );
 }
 
+bool wxMacControl::SetBackgroundStyle(wxBackgroundStyle style)
+{
+    if ( style != wxBG_STYLE_PAINT )
+    {
+        OSStatus err = HIViewChangeFeatures(m_controlRef , 0 , kHIViewIsOpaque);
+        verify_noerr( err );
+    }
+    else
+    {
+        OSStatus err = HIViewChangeFeatures(m_controlRef , kHIViewIsOpaque , 0);
+        verify_noerr( err );
+    }
+
+    return true ;
+}
+
 void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
 {
     ::SetControl32BitMinimum( m_controlRef , minimum );
@@ -1448,11 +1506,21 @@ wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control)
     return NULL;
 }
 
+wxBitmap wxMacControl::GetBitmap() const
+{
+    return wxNullBitmap;
+}
+
 void wxMacControl::SetBitmap( const wxBitmap& WXUNUSED(bmp) )
 {
     // implemented in the respective subclasses
 }
 
+void wxMacControl::SetBitmapPosition( wxDirection WXUNUSED(dir) )
+{
+    // implemented in the same subclasses that implement SetBitmap()
+}
+
 void wxMacControl::SetScrollThumb( wxInt32 WXUNUSED(pos), wxInt32 WXUNUSED(viewsize) )
 {
     // implemented in respective subclass
@@ -1471,11 +1539,11 @@ OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable )
 
 // Control Factory
 
-wxWidgetImplType* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) 
+wxWidgetImplType* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
 {
     // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
     // the content view, so we have to retrieve it explicitly
-    
+
     wxMacControl* contentview = new wxMacControl(now , true /*isRootControl*/);
     HIViewFindByID( HIViewGetRoot( (WindowRef) now->GetWXWindow() ) , kHIViewWindowContentID ,
         contentview->GetControlRefAddr() ) ;
@@ -1486,6 +1554,8 @@ wxWidgetImplType* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
     }
 
     // the root control level handler
-    contentview->InstallEventHandler() ;
+    if ( !now->IsNativeWindowWrapper() )
+        contentview->InstallEventHandler() ;
+
     return contentview;
 }