X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cdef03346586b83cb87ed1e9d239f236ce8baaf7..8c981ec64d9a86e9bad5f4ef16f496513bce31f6:/src/mac/carbon/window.cpp diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index a82b7e19a7..1a23e54047 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -11,31 +11,33 @@ #include "wx/wxprec.h" -#include "wx/menu.h" #include "wx/window.h" -#include "wx/dc.h" -#include "wx/dcclient.h" -#include "wx/utils.h" -#include "wx/app.h" -#include "wx/panel.h" -#include "wx/layout.h" -#include "wx/dialog.h" -#include "wx/scrolbar.h" -#include "wx/statbox.h" -#include "wx/button.h" -#include "wx/settings.h" -#include "wx/msgdlg.h" -#include "wx/frame.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/panel.h" + #include "wx/frame.h" + #include "wx/dc.h" + #include "wx/dcclient.h" + #include "wx/button.h" + #include "wx/menu.h" + #include "wx/dialog.h" + #include "wx/settings.h" + #include "wx/msgdlg.h" + #include "wx/scrolbar.h" + #include "wx/statbox.h" + #include "wx/textctrl.h" + #include "wx/toolbar.h" + #include "wx/layout.h" + #include "wx/statusbr.h" + #include "wx/menuitem.h" +#endif + #include "wx/tooltip.h" -#include "wx/statusbr.h" -#include "wx/menuitem.h" #include "wx/spinctrl.h" -#include "wx/log.h" #include "wx/geometry.h" -#include "wx/textctrl.h" - -#include "wx/toolbar.h" -#include "wx/dc.h" #if wxUSE_CARET #include "wx/caret.h" @@ -65,8 +67,6 @@ #include -extern wxList wxPendingDelete; - #ifdef __WXUNIVERSAL__ IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase) #else @@ -203,43 +203,22 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl wxRegion visRegion = thisWindow->MacGetVisibleRegion() ; Rect controlBounds ; - if ( ! thisWindow->GetPeer()->IsCompositing() ) - { - if ( thisWindow->GetPeer()->IsRootControl() ) - thisWindow->GetPeer()->GetRect( &controlBounds ) ; - else - GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ; - } - if ( cEvent.GetParameter(kEventParamRgnHandle, &updateRgn) != noErr ) { updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; } else { - if ( ! thisWindow->GetPeer()->IsCompositing() ) + if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 ) { + // as this update region is in native window locals we must adapt it to wx window local allocatedRgn = NewRgn() ; CopyRgn( updateRgn , allocatedRgn ) ; - OffsetRgn( allocatedRgn , -controlBounds.left , -controlBounds.top ) ; // hide the given region by the new region that must be shifted wxMacNativeToWindow( thisWindow , allocatedRgn ) ; updateRgn = allocatedRgn ; } - else - { - if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 ) - { - // as this update region is in native window locals we must adapt it to wx window local - allocatedRgn = NewRgn() ; - CopyRgn( updateRgn , allocatedRgn ) ; - - // hide the given region by the new region that must be shifted - wxMacNativeToWindow( thisWindow , allocatedRgn ) ; - updateRgn = allocatedRgn ; - } - } } Rect rgnBounds ; @@ -272,43 +251,25 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl #if wxMAC_USE_CORE_GRAPHICS bool created = false ; CGContextRef cgContext = NULL ; - if ( cEvent.GetParameter(kEventParamCGContextRef, &cgContext) != noErr ) - { - wxASSERT( thisWindow->GetPeer()->IsCompositing() == false ) ; - - // this parameter is not provided on non-composited windows - created = true ; - - // rest of the code expects this to be already transformed and clipped for local - CGrafPtr port = GetWindowPort( (WindowRef) thisWindow->MacGetTopLevelWindowRef() ) ; - Rect bounds ; - GetPortBounds( port , &bounds ) ; - CreateCGContextForPort( port , &cgContext ) ; - - wxMacWindowToNative( thisWindow , updateRgn ) ; - OffsetRgn( updateRgn , controlBounds.left , controlBounds.top ) ; - ClipCGContextToRegion( cgContext , &bounds , updateRgn ) ; - wxMacNativeToWindow( thisWindow , updateRgn ) ; - OffsetRgn( updateRgn , -controlBounds.left , -controlBounds.top ) ; - - CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ; - CGContextScaleCTM( cgContext , 1 , -1 ) ; - - CGContextTranslateCTM( cgContext , controlBounds.left , controlBounds.top ) ; - -#if 0 - CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ; - CGContextFillRect( cgContext , - CGRectMake( 0 , 0 , - controlBounds.right - controlBounds.left , - controlBounds.bottom - controlBounds.top ) ); -#endif - } - + OSStatus err = cEvent.GetParameter(kEventParamCGContextRef, &cgContext) ; + wxASSERT_MSG( err == noErr , wxT("Unable to retrieve CGContextRef") ) ; thisWindow->MacSetCGContextRef( cgContext ) ; { wxMacCGContextStateSaver sg( cgContext ) ; + float alpha = 1.0 ; + { + wxWindow* iter = thisWindow ; + while ( iter ) + { + alpha *= (float) iter->GetTransparent()/255.0 ; + if ( iter->IsTopLevel() ) + iter = NULL ; + else + iter = iter->GetParent() ; + } + } + CGContextSetAlpha( cgContext , alpha ) ; #endif if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) result = noErr ; @@ -498,25 +459,26 @@ pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , Even wchar_t* uniChars = NULL ; UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; - UniChar* charBuf; + UniChar* charBuf = NULL; UInt32 dataSize = 0 ; int numChars = 0 ; UniChar buf[2] ; if ( GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr ) { - numChars = dataSize / sizeof( UniChar) ; + numChars = dataSize / sizeof( UniChar) + 1; charBuf = buf ; - if ( dataSize > sizeof(buf) ) + if ( (size_t) numChars * 2 > sizeof(buf) ) charBuf = new UniChar[ numChars ] ; else charBuf = buf ; 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 , dataSize ) ; + memcpy( uniChars , charBuf , numChars * 2 ) ; #else // the resulting string will never have more chars than the utf16 version, so this is safe wxMBConvUTF16 converter ; @@ -587,7 +549,7 @@ pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , Even delete [] uniChars ; if ( charBuf != buf ) delete [] charBuf ; - + return result ; } @@ -940,6 +902,7 @@ void wxWindowMac::Init() { m_peer = NULL ; m_frozenness = 0 ; + m_macAlpha = 255 ; #if WXWIN_COMPATIBILITY_2_4 m_backgroundTransparent = false; @@ -992,11 +955,11 @@ wxWindowMac::~wxWindowMac() // wxRemoveMacControlAssociation( this ) ; // If we delete an item, we should initialize the parent panel, // because it could now be invalid. - wxWindow *parent = GetParent() ; - if ( parent ) + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + if ( tlw ) { - if (parent->GetDefaultItem() == (wxButton*) this) - parent->SetDefaultItem(NULL); + if ( tlw->GetDefaultItem() == (wxButton*) this) + tlw->SetDefaultItem(NULL); } if ( m_peer && m_peer->Ok() ) @@ -1135,7 +1098,7 @@ void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size) // adjust font, controlsize etc DoSetWindowVariant( m_windowVariant ) ; - m_peer->SetLabel( wxStripMenuCodes(m_label) ) ; + m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics) ) ; if (!m_macIsUserPane) SetInitialBestSize(size); @@ -1259,14 +1222,16 @@ void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) bool wxWindowMac::MacCanFocus() const { // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so - // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning, but the value range - // is nowhere documented + // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning, + // but the value range is nowhere documented Boolean keyExistsAndHasValidFormat ; - CFIndex fullKeyboardAccess = CFPreferencesGetAppIntegerValue ( CFSTR("AppleKeyboardUIMode" ) , - kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat); - + CFIndex fullKeyboardAccess = CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) , + kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat ); + if ( keyExistsAndHasValidFormat && fullKeyboardAccess > 0 ) + { return true ; + } else { UInt32 features = 0 ; @@ -1336,7 +1301,7 @@ void wxWindowMac::DoCaptureMouse() wxApp::s_captureWindow = this ; } -wxWindow* wxWindowBase::GetCapture() +wxWindow * wxWindowBase::GetCapture() { return wxApp::s_captureWindow ; } @@ -1362,7 +1327,7 @@ void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget) #endif -// Old style file-manager drag&drop +// Old-style File Manager Drag & Drop void wxWindowMac::DragAcceptFiles(bool accept) { // TODO: @@ -1385,10 +1350,7 @@ bool wxWindowMac::MacGetBoundsForControl( int& x, int& y, int& w, int& h , bool adjustOrigin ) const { - bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ; - // the desired size, minus the border pixels gives the correct size of the control - x = (int)pos.x; y = (int)pos.y; @@ -1396,9 +1358,6 @@ bool wxWindowMac::MacGetBoundsForControl( w = wxMax(size.x, 0) ; // WidthDefault( size.x ); h = wxMax(size.y, 0) ; // HeightDefault( size.y ) ; - if ( !isCompositing ) - GetParent()->MacWindowToRootWindow( &x , &y ) ; - x += MacGetLeftBorderSize() ; y += MacGetTopBorderSize() ; w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ; @@ -1760,7 +1719,7 @@ bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) menu->SetInvokingWindow(this); menu->UpdateUI(); - if ( x == -1 && y == -1 ) + if ( x == wxDefaultCoord && y == wxDefaultCoord ) { wxPoint mouse = wxGetMousePosition(); x = mouse.x; @@ -2087,7 +2046,7 @@ void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) void wxWindowMac::SetLabel(const wxString& title) { - m_label = wxStripMenuCodes(title) ; + m_label = wxStripMenuCodes(title, wxStrip_Mnemonics) ; if ( m_peer && m_peer->Ok() ) m_peer->SetLabel( m_label ) ; @@ -2356,7 +2315,7 @@ void wxWindowMac::OnEraseBackground(wxEraseEvent& event) return ; #if TARGET_API_MAC_OSX - if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush.Ok() || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) ) + if ( !m_macBackgroundBrush.Ok() || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) { event.Skip() ; } @@ -2544,6 +2503,7 @@ void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, int range, bool refresh) { bool showScroller; + bool triggerSizeEvent = false; if ( orient == wxHORIZONTAL ) { @@ -2551,7 +2511,10 @@ void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, { showScroller = ((range != 0) && (range > thumbVisible)); if ( m_hScrollBar->IsShown() != showScroller ) - m_hScrollBar->Show( showScroller ) ; + { + m_hScrollBar->Show( showScroller ); + triggerSizeEvent = true; + } m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; } @@ -2562,13 +2525,22 @@ void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible, { showScroller = ((range != 0) && (range > thumbVisible)); if ( m_vScrollBar->IsShown() != showScroller ) + { m_vScrollBar->Show( showScroller ) ; + triggerSizeEvent = true; + } m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ; } } MacRepositionScrollBars() ; + if ( triggerSizeEvent ) + { + wxSizeEvent event(GetSize(), m_windowId); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); + } } // Does a physical scroll @@ -2581,7 +2553,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) GetClientSize( &width , &height ) ; #if TARGET_API_MAC_OSX - if ( true /* m_peer->IsCompositing() */ ) + if ( true ) { // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control // area is scrolled, this does not occur if width and height are 2 pixels less, @@ -2601,7 +2573,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) // this would be the preferred version for fast drawing controls #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 - if ( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() ) + if ( UMAGetSystemVersion() >= 0x1030 ) HIViewRender(m_peer->GetControlRef()) ; else #endif @@ -2622,7 +2594,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) // this would be the preferred version for fast drawing controls #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 - if ( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() ) + if ( UMAGetSystemVersion() >= 0x1030 ) HIViewRender(m_peer->GetControlRef()) ; else #endif @@ -3436,3 +3408,32 @@ bool wxWindowMac::Reparent(wxWindowBase *newParentBase) return true; } + +bool wxWindowMac::SetTransparent(wxByte alpha) +{ +#if wxMAC_USE_CORE_GRAPHICS + if ( alpha != m_macAlpha ) + { + m_macAlpha = alpha ; + Refresh() ; + } + return true ; +#else + return false ; +#endif +} + + +bool wxWindowMac::CanSetTransparent() +{ +#if wxMAC_USE_CORE_GRAPHICS + return true ; +#else + return false ; +#endif +} + +wxByte wxWindowMac::GetTransparent() const +{ + return m_macAlpha ; +} \ No newline at end of file