]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/window.cpp
textctrl always needs ATSU...
[wxWidgets.git] / src / mac / carbon / window.cpp
index 0b6532ed843e156dbce1f661f7085cbc4231771a..b9f08d6a90d12100ec07468f67d759cf63017c6a 100644 (file)
@@ -78,8 +78,6 @@ BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
     EVT_NC_PAINT(wxWindowMac::OnNcPaint)
     EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
     EVT_PAINT(wxWindowMac::OnPaint)
-    EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
-    EVT_KILL_FOCUS(wxWindowMac::OnSetFocus)
     EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
 END_EVENT_TABLE()
 
@@ -160,6 +158,7 @@ static const EventTypeSpec eventList[] =
     { kEventClassControl , kEventControlDeactivate } ,
 
     { kEventClassControl , kEventControlSetFocusPart } ,
+    { kEventClassControl , kEventControlFocusPartChanged } ,
 
     { kEventClassService , kEventServiceGetTypes },
     { kEventClassService , kEventServiceCopy },
@@ -190,7 +189,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
 
                 if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
                 {
-                    updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
+                    HIShapeGetAsQDRgn( visRegion.GetWXHRGN(), updateRgn );
                 }
                 else
                 {
@@ -301,26 +300,33 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
 #endif
             break ;
 
-        // we emulate this event under Carbon CFM
-        case kEventControlSetFocusPart :
+        //
+        // focus handling
+        // different handling on OS X
+        //
+            
+        case kEventControlFocusPartChanged :
+            // the event is emulated by wxmac for systems lower than 10.5
             {
-                Boolean focusEverything = false ;
-                ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
+                ControlPartCode previousControlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPreviousPart , typeControlPartCode );
+                ControlPartCode currentControlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlCurrentPart , typeControlPartCode );
 
-                if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
+                if ( thisWindow->MacGetTopLevelWindow() && thisWindow->GetPeer()->NeedsFocusRect() )
                 {
+                    thisWindow->MacInvalidateBorders();
                 }
-
-                if ( thisWindow->MacIsUserPane() )
-                    result = noErr ;
-
-                if ( controlPart == kControlFocusNoPart )
+                
+                if ( currentControlPart == 0 )
                 {
+                    // kill focus
 #if wxUSE_CARET
                     if ( thisWindow->GetCaret() )
                         thisWindow->GetCaret()->OnKillFocus();
 #endif
-
+                    
+                    wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow));
+                    
+                    // remove this as soon as posting the synthesized event works properly
                     static bool inKillFocusEvent = false ;
 
                     if ( !inKillFocusEvent )
@@ -328,24 +334,116 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
                         inKillFocusEvent = true ;
                         wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
                         event.SetEventObject(thisWindow);
-                        thisWindow->GetEventHandler()->ProcessEvent(event) ;
+                        thisWindow->HandleWindowEvent(event) ;
                         inKillFocusEvent = false ;
                     }
                 }
-                else
+                else if ( previousControlPart == 0 )
                 {
+                    // set focus
                     // panel wants to track the window which was the last to have focus in it
-                    wxChildFocusEvent eventFocus(thisWindow);
-                    thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
-
+                    wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow));
+                    wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
+                    thisWindow->HandleWindowEvent(eventFocus);
+                    
 #if wxUSE_CARET
                     if ( thisWindow->GetCaret() )
                         thisWindow->GetCaret()->OnSetFocus();
 #endif
-
+                    
                     wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
                     event.SetEventObject(thisWindow);
-                    thisWindow->GetEventHandler()->ProcessEvent(event) ;
+                    thisWindow->HandleWindowEvent(event) ;
+                }
+            }
+            break;
+        case kEventControlSetFocusPart :
+            {
+#ifdef __WXMAC_OSX__
+                Boolean focusEverything = false ;
+                if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
+                {
+                    // put a breakpoint here to catch focus everything events
+                }
+#endif                
+                ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
+                
+                ControlPartCode previousControlPart = 0;
+                verify_noerr( HIViewGetFocusPart(controlRef, &previousControlPart));
+
+                if ( thisWindow->MacIsUserPane() )
+                {
+                    if ( controlPart != kControlFocusNoPart )
+                        cEvent.SetParameter<ControlPartCode>( kEventParamControlPart, typeControlPartCode, 1 ) ;
+                    result = noErr ;
+                }
+                else
+                    result = CallNextEventHandler(handler, event);
+                
+                if ( UMAGetSystemVersion() < 0x1050 )
+                {
+// set back to 0 if problems arise
+#if 1   
+                    ControlPartCode currentControlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
+                    // synthesize the event focus changed event
+                    EventRef evRef = NULL ;
+                    
+                    OSStatus err = MacCreateEvent(
+                                         NULL , kEventClassControl , kEventControlFocusPartChanged , TicksToEventTime( TickCount() ) ,
+                                         kEventAttributeUserEvent , &evRef );
+                    verify_noerr( err );
+                    
+                    wxMacCarbonEvent iEvent( evRef ) ;
+                    iEvent.SetParameter<ControlRef>( kEventParamDirectObject , controlRef ) ;
+                    iEvent.SetParameter<ControlPartCode>( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart ) ;
+                    iEvent.SetParameter<ControlPartCode>( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart ) ;
+   
+#if 0
+                    // TODO test this first, avoid double posts etc...
+                    PostEventToQueue( GetMainEventQueue(), evRef , kEventPriorityHigh );
+#else
+                    wxMacWindowControlEventHandler( NULL , evRef , data ) ;
+#endif
+                    ReleaseEvent( evRef ) ;
+#else
+                    // old implementation, to be removed if the new one works
+                    if ( controlPart == kControlFocusNoPart )
+                    {
+#if wxUSE_CARET
+                        if ( thisWindow->GetCaret() )
+                            thisWindow->GetCaret()->OnKillFocus();
+#endif
+
+                        wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow));
+                        
+                        static bool inKillFocusEvent = false ;
+
+                        if ( !inKillFocusEvent )
+                        {
+                            inKillFocusEvent = true ;
+                            wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
+                            event.SetEventObject(thisWindow);
+                            thisWindow->HandleWindowEvent(event) ;
+                            inKillFocusEvent = false ;
+                        }
+                    }
+                    else
+                    {
+                        // panel wants to track the window which was the last to have focus in it
+                        wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow));
+                        wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
+                        thisWindow->HandleWindowEvent(eventFocus);
+
+    #if wxUSE_CARET
+                        if ( thisWindow->GetCaret() )
+                            thisWindow->GetCaret()->OnSetFocus();
+    #endif
+
+                        wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
+                        event.SetEventObject(thisWindow);
+                        thisWindow->HandleWindowEvent(event) ;
+                    }
+#endif
                 }
             }
             break ;
@@ -1003,7 +1101,7 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
     m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
 
     wxFont font ;
-    font.MacCreateThemeFont( themeFont ) ;
+    font.MacCreateFromThemeFont( themeFont ) ;
     SetFont( font ) ;
 }
 
@@ -1581,7 +1679,7 @@ void wxWindowMac::MacInvalidateBorders()
         return ;
 
     int outerBorder = MacGetLeftBorderSize() ;
-    if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
+    if ( m_peer->NeedsFocusRect() /* && m_peer->HasFocus() */ )
         outerBorder += 4 ;
 
     if ( outerBorder == 0 )
@@ -1677,7 +1775,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
             wxPoint point(actualX, actualY);
             wxMoveEvent event(point, m_windowId);
             event.SetEventObject(this);
-            GetEventHandler()->ProcessEvent(event) ;
+            HandleWindowEvent(event) ;
         }
 
         if ( doResize )
@@ -1686,7 +1784,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
             wxSize size(actualWidth, actualHeight);
             wxSizeEvent event(size, m_windowId);
             event.SetEventObject(this);
-            GetEventHandler()->ProcessEvent(event);
+            HandleWindowEvent(event);
         }
     }
 }
@@ -2041,17 +2139,22 @@ void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
 {
     if ( MacGetTopLevelWindow() == NULL )
         return ;
-
+/*
 #if TARGET_API_MAC_OSX
     if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
     {
-        event.Skip() ;
     }
     else
 #endif
+*/
+    if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR )
     {
         event.GetDC()->Clear() ;
     }
+    else
+    {
+        event.Skip() ;
+    }
 }
 
 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
@@ -2285,7 +2388,7 @@ void wxWindowMac::DoUpdateScrollbarVisibility()
     {
         wxSizeEvent event(GetSize(), m_windowId);
         event.SetEventObject(this);
-        GetEventHandler()->ProcessEvent(event);
+        HandleWindowEvent(event);
     }
 }
 
@@ -2397,7 +2500,7 @@ void wxWindowMac::MacOnScroll( wxScrollEvent &event )
         else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
             wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
 
-        GetEventHandler()->ProcessEvent(wevent);
+        HandleWindowEvent(wevent);
     }
 }
 
@@ -2409,54 +2512,6 @@ wxWindowMac *wxWindowBase::DoFindFocus()
     return wxFindControlFromMacControl( control ) ;
 }
 
-void wxWindowMac::OnSetFocus( wxFocusEvent& event )
-{
-    // panel wants to track the window which was the last to have focus in it,
-    // so we want to set ourselves as the window which last had focus
-    //
-    // notice that it's also important to do it upwards the tree because
-    // otherwise when the top level panel gets focus, it won't set it back to
-    // us, but to some other sibling
-
-    // CS: don't know if this is still needed:
-    //wxChildFocusEvent eventFocus(this);
-    //(void)GetEventHandler()->ProcessEvent(eventFocus);
-
-    if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
-    {
-        GetParent()->Refresh() ;
-        wxMacWindowStateSaver sv( this ) ;
-        Rect rect ;
-
-        m_peer->GetRect( &rect ) ;
-        // auf den umgebenden Rahmen zurチᅡ゚ck
-        InsetRect( &rect, -1 , -1 ) ;
-
-        wxTopLevelWindowMac* top = MacGetTopLevelWindow();
-        if ( top )
-        {
-            wxPoint pt(0, 0) ;
-            wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
-            rect.left += pt.x ;
-            rect.right += pt.x ;
-            rect.top += pt.y ;
-            rect.bottom += pt.y ;
-        }
-
-        bool bIsFocusEvent = (event.GetEventType() == wxEVT_SET_FOCUS);
-        DrawThemeFocusRect( &rect , bIsFocusEvent ) ;
-        if ( !bIsFocusEvent )
-        {
-            // as this erases part of the frame we have to redraw borders
-            // and because our z-ordering is not always correct (staticboxes)
-            // we have to invalidate things, we cannot simple redraw
-            MacInvalidateBorders() ;
-        }
-    }
-
-    event.Skip();
-}
-
 void wxWindowMac::OnInternalIdle()
 {
     // This calls the UI-update mechanism (querying windows for
@@ -2490,7 +2545,7 @@ bool wxWindowMac::MacSetupCursor( const wxPoint& pt )
     {
         wxSetCursorEvent event( pt.x , pt.y );
 
-        bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
+        bool processedEvtSetCursor = HandleWindowEvent(event);
         if ( processedEvtSetCursor && event.HasCursor() )
         {
             cursor = event.GetCursor() ;
@@ -2708,7 +2763,7 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
 
             wxEraseEvent eevent( GetId(), dc );
             eevent.SetEventObject( this );
-            GetEventHandler()->ProcessEvent( eevent );
+            HandleWindowEvent( eevent );
             delete dc ;
         }
 
@@ -2726,7 +2781,7 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
             wxPaintEvent event;
             event.SetTimestamp(time);
             event.SetEventObject(this);
-            GetEventHandler()->ProcessEvent(event);
+            HandleWindowEvent(event);
             handled = true ;
         }
 
@@ -2765,7 +2820,7 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
                 // paint custom borders
                 wxNcPaintEvent eventNc( child->GetId() );
                 eventNc.SetEventObject( child );
-                if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
+                if ( !child->HandleWindowEvent( eventNc ) )
                 {
                     child->MacPaintBorders(0, 0) ;
                 }
@@ -3100,7 +3155,7 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
         wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
                                   this->GetId(),
                                   this->ClientToScreen(event.GetPosition()));
-        if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
+        if ( ! HandleWindowEvent(evtCtx) )
             event.Skip() ;
     }
     else