]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/window.cpp
fix compilation error after r50329: wxMenu doesn't have HandleWindowEvent() as it...
[wxWidgets.git] / src / mac / carbon / window.cpp
index 766257f0a18cdd99e93fd3b0f54332e3b7f44331..6c158e6acdee9fda4e7098e7723a77d9ef7f8c0e 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 ;
@@ -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);
         }
     }
 }
@@ -2290,7 +2388,7 @@ void wxWindowMac::DoUpdateScrollbarVisibility()
     {
         wxSizeEvent event(GetSize(), m_windowId);
         event.SetEventObject(this);
-        GetEventHandler()->ProcessEvent(event);
+        HandleWindowEvent(event);
     }
 }
 
@@ -2402,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);
     }
 }
 
@@ -2414,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
@@ -2495,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() ;
@@ -2713,7 +2763,7 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time )
 
             wxEraseEvent eevent( GetId(), dc );
             eevent.SetEventObject( this );
-            GetEventHandler()->ProcessEvent( eevent );
+            HandleWindowEvent( eevent );
             delete dc ;
         }
 
@@ -2731,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 ;
         }
 
@@ -2770,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) ;
                 }
@@ -3105,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