X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a0a2b5c41c8448c478e05b7819b4c173c22c46a8..bbd92d1dbea02db8c28e9c17bfacc0563d855b25:/src/mac/carbon/window.cpp diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index fd02b9947c..e6ac15ee79 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -258,8 +258,8 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl CGContextClearRect( cgContext, bounds ); } - - + + if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) result = noErr ; @@ -304,7 +304,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl // focus handling // different handling on OS X // - + case kEventControlFocusPartChanged : // the event is emulated by wxmac for systems lower than 10.5 { @@ -315,7 +315,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl { thisWindow->MacInvalidateBorders(); } - + if ( currentControlPart == 0 ) { // kill focus @@ -323,9 +323,9 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl 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 ; @@ -334,7 +334,7 @@ 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 ; } } @@ -344,16 +344,16 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl // 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->GetEventHandler()->ProcessEvent(eventFocus); - + 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; @@ -365,9 +365,9 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl { // put a breakpoint here to catch focus everything events } -#endif +#endif ControlPartCode controlPart = cEvent.GetParameter(kEventParamControlPart , typeControlPartCode ); - + ControlPartCode previousControlPart = 0; verify_noerr( HIViewGetFocusPart(controlRef, &previousControlPart)); @@ -379,25 +379,25 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl } else result = CallNextEventHandler(handler, event); - + if ( UMAGetSystemVersion() < 0x1050 ) { // set back to 0 if problems arise -#if 1 +#if 1 ControlPartCode currentControlPart = cEvent.GetParameter(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( kEventParamDirectObject , controlRef ) ; iEvent.SetParameter( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart ) ; iEvent.SetParameter( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart ) ; - + #if 0 // TODO test this first, avoid double posts etc... PostEventToQueue( GetMainEventQueue(), evRef , kEventPriorityHigh ); @@ -415,7 +415,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl #endif wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow)); - + static bool inKillFocusEvent = false ; if ( !inKillFocusEvent ) @@ -423,7 +423,7 @@ 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 ; } } @@ -432,7 +432,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl // 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->GetEventHandler()->ProcessEvent(eventFocus); + thisWindow->HandleWindowEvent(eventFocus); #if wxUSE_CARET if ( thisWindow->GetCaret() ) @@ -441,7 +441,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); event.SetEventObject(thisWindow); - thisWindow->GetEventHandler()->ProcessEvent(event) ; + thisWindow->HandleWindowEvent(event) ; } #endif } @@ -454,7 +454,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl case kEventControlGetClickActivation : { - // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise) + // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise) WindowRef owner = cEvent.GetParameter(kEventParamWindowRef); if ( !IsWindowActive(owner) ) { @@ -605,7 +605,7 @@ pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , Even 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...) +/* 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 ; @@ -627,29 +627,29 @@ pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , Even UInt32 message = uniChars[pos] < 128 ? (char)uniChars[pos] : '?'; /* - NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent - multiple times to update the active range during inline input, so this handler will often receive - uncommited text, which should usually not trigger side effects. It might be a good idea to check the - kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h). - On the other hand, it can be useful for some applications to react to uncommitted text (for example, - to update a status display), as long as it does not disrupt the inline input session. Ideally, wx - should add new event types to support advanced text input. For now, I would keep things as they are. - - However, the code that was being used caused additional problems: + NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent + multiple times to update the active range during inline input, so this handler will often receive + uncommited text, which should usually not trigger side effects. It might be a good idea to check the + kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h). + On the other hand, it can be useful for some applications to react to uncommitted text (for example, + to update a status display), as long as it does not disrupt the inline input session. Ideally, wx + should add new event types to support advanced text input. For now, I would keep things as they are. + + However, the code that was being used caused additional problems: UInt32 message = (0 << 8) + ((char)uniChars[pos] ); - Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline - input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji - for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB - (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D - (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress. - Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only - overlap with Unicode within the (7-bit) ASCII range. - But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks - for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII - characters as they are and replaces the rest with '?', ensuring that update events are triggered. - It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but - I don't have time to look into that right now. - -- CL + Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline + input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji + for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB + (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D + (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress. + Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only + overlap with Unicode within the (7-bit) ASCII range. + But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks + for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII + characters as they are and replaces the rest with '?', ensuring that update events are triggered. + It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but + I don't have time to look into that right now. + -- CL */ if ( wxTheApp->MacSendCharEvent( focus , message , 0 , when , 0 , 0 , uniChars[pos] ) ) @@ -865,7 +865,6 @@ wxWindowMac::wxWindowMac(wxWindowMac *parent, void wxWindowMac::Init() { m_peer = NULL ; - m_frozenness = 0 ; m_macAlpha = 255 ; m_cgContextRef = NULL ; @@ -1101,7 +1100,7 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) m_peer->SetData(kControlEntireControl, kControlSizeTag, &size ) ; wxFont font ; - font.MacCreateThemeFont( themeFont ) ; + font.MacCreateFromThemeFont( themeFont ) ; SetFont( font ) ; } @@ -1775,7 +1774,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 ) @@ -1784,7 +1783,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); } } } @@ -2091,38 +2090,25 @@ void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) } } -void wxWindowMac::Freeze() +void wxWindowMac::DoFreeze() { #if TARGET_API_MAC_OSX - if ( !m_frozenness++ ) - { - if ( m_peer && m_peer->Ok() ) - m_peer->SetDrawingEnabled( false ) ; - } + if ( m_peer && m_peer->Ok() ) + m_peer->SetDrawingEnabled( false ) ; #endif } -void wxWindowMac::Thaw() +void wxWindowMac::DoThaw() { #if TARGET_API_MAC_OSX - wxASSERT_MSG( m_frozenness > 0, wxT("Thaw() without matching Freeze()") ); - - if ( !--m_frozenness ) + if ( m_peer && m_peer->Ok() ) { - if ( m_peer && m_peer->Ok() ) - { - m_peer->SetDrawingEnabled( true ) ; - m_peer->InvalidateWithChildren() ; - } + m_peer->SetDrawingEnabled( true ) ; + m_peer->InvalidateWithChildren() ; } #endif } -bool wxWindowMac::IsFrozen() const -{ - return m_frozenness != 0; -} - wxWindowMac *wxGetActiveWindow() { // actually this is a windows-only concept @@ -2263,21 +2249,21 @@ void wxWindowMac::MacPaintGrowBox() CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ; wxASSERT( cgContext ) ; - + m_peer->GetRect( &rect ) ; int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; CGContextSaveGState( cgContext ); - + if ( m_backgroundColour.Ok() ) { - CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() ); + CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() ); } else { - CGContextSetRGBFillColor( cgContext, 1.0, 1.0 , 1.0 , 1.0 ); + CGContextSetRGBFillColor( cgContext, 1.0, 1.0 , 1.0 , 1.0 ); } CGContextFillRect( cgContext, cgrect ); CGContextRestoreGState( cgContext ); @@ -2388,7 +2374,7 @@ void wxWindowMac::DoUpdateScrollbarVisibility() { wxSizeEvent event(GetSize(), m_windowId); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); } } @@ -2500,7 +2486,7 @@ void wxWindowMac::MacOnScroll( wxScrollEvent &event ) else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); - GetEventHandler()->ProcessEvent(wevent); + HandleWindowEvent(wevent); } } @@ -2516,7 +2502,7 @@ void wxWindowMac::OnInternalIdle() { // This calls the UI-update mechanism (querying windows for // menu/toolbar/control state information) - if (wxUpdateUIEvent::CanUpdate(this) && IsShown()) + if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen()) UpdateWindowUI(wxUPDATE_UI_FROMIDLE); } @@ -2545,7 +2531,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() ; @@ -2763,7 +2749,7 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time ) wxEraseEvent eevent( GetId(), dc ); eevent.SetEventObject( this ); - GetEventHandler()->ProcessEvent( eevent ); + HandleWindowEvent( eevent ); delete dc ; } @@ -2781,7 +2767,7 @@ bool wxWindowMac::MacDoRedraw( void* updatergnr , long time ) wxPaintEvent event; event.SetTimestamp(time); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); handled = true ; } @@ -2820,7 +2806,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) ; } @@ -3155,7 +3141,8 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, this->GetId(), this->ClientToScreen(event.GetPosition())); - if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) + evtCtx.SetEventObject(this); + if ( ! HandleWindowEvent(evtCtx) ) event.Skip() ; } else