X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5b781a6729859abc77e6ca5b1f81cbaad974a78f..71e483d39adbc1c80ef2fa998bd7f18e1704440c:/src/mac/window.cpp diff --git a/src/mac/window.cpp b/src/mac/window.cpp index 9d98f35302..7d4ce35592 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -15,6 +15,7 @@ #include "wx/setup.h" #include "wx/menu.h" +#include "wx/window.h" #include "wx/dc.h" #include "wx/dcclient.h" #include "wx/utils.h" @@ -23,6 +24,8 @@ #include "wx/layout.h" #include "wx/dialog.h" #include "wx/listbox.h" +#include "wx/scrolbar.h" +#include "wx/statbox.h" #include "wx/button.h" #include "wx/settings.h" #include "wx/msgdlg.h" @@ -30,9 +33,7 @@ #include "wx/notebook.h" #include "wx/tabctrl.h" #include "wx/tooltip.h" -// TODO remove the line below, just for lookup-up convenience CS -#include "wx/mac/window.h" - +#include "wx/statusbr.h" #include "wx/menuitem.h" #include "wx/log.h" @@ -62,7 +63,7 @@ BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_INIT_DIALOG(wxWindow::OnInitDialog) EVT_IDLE(wxWindow::OnIdle) -// EVT_SCROLL(wxWindow::OnScroll) + EVT_SET_FOCUS(wxWindow::OnSetFocus) END_EVENT_TABLE() #endif @@ -107,11 +108,15 @@ void wxRemoveMacWindowAssociation(wxWindow *win) // constructors and such // ---------------------------------------------------------------------------- +WindowRef wxWindow::s_macWindowInUpdate = NULL; + void wxWindow::Init() { // generic InitBase(); + m_macEraseOnRedraw = true ; + // MSW specific m_doubleClickAllowed = 0; m_winCaptured = FALSE; @@ -129,6 +134,7 @@ void wxWindow::Init() m_isShown = TRUE; m_macWindowData = NULL ; + m_macEraseOnRedraw = true ; m_x = 0; m_y = 0 ; @@ -192,7 +198,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, m_width = WidthDefault( size.x ); m_height = HeightDefault( size.y ) ; - if ( ! IsKindOf( CLASSINFO ( wxControl ) ) ) + if ( ! IsKindOf( CLASSINFO ( wxControl ) ) && ! IsKindOf( CLASSINFO( wxStatusBar ) ) ) { MacCreateScrollBars( style ) ; } @@ -202,6 +208,9 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, void wxWindow::SetFocus() { + if ( gFocusWindow == this ) + return ; + if ( AcceptsFocus() ) { if (gFocusWindow ) @@ -507,6 +516,14 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height) DoSetSize( x,y, width, height ) ; } +// set the size of the window: if the dimensions are positive, just use them, +// but if any of them is equal to -1, it means that we must find the value for +// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in +// which case -1 is a valid value for x and y) +// +// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate +// the width/height to best suit our contents, otherwise we reuse the current +// width/height void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) { @@ -528,11 +545,49 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) actualX = currentX; if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) actualY = currentY; - if (width == -1) + + wxSize size( -1 , -1 ) ; + + if (width == -1 || height == -1 ) + { + size = DoGetBestSize() ; + } + + if ( width == -1 ) + { + if ( sizeFlags & wxSIZE_AUTO_WIDTH ) + { + actualWidth = size.x ; + if ( actualWidth == -1 ) + actualWidth = 80 ; + } + else + { actualWidth = currentW ; + } + } if (height == -1) + { + if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) + { + actualHeight = size.y ; + if ( actualHeight == -1 ) + actualHeight = 26 ; + } + else + { actualHeight = currentH ; + } + } + if ((m_minWidth != -1) && (actualWidth < m_minWidth)) + actualWidth = m_minWidth; + if ((m_minHeight != -1) && (actualHeight < m_minHeight)) + actualHeight = m_minHeight; + if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) + actualWidth = m_maxWidth; + if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) + actualHeight = m_maxHeight; if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH) { MacRepositionScrollBars() ; // we might have a real position shift @@ -562,13 +617,12 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) else { // erase former position + wxMacDrawingHelper focus( this ) ; + if ( focus.Ok() ) { - wxMacDrawingClientHelper focus( this ) ; - if ( focus.Ok() ) - { - Rect clientrect = { 0 , 0 , m_height , m_width } ; - InvalWindowRect( GetMacRootWindow() , &clientrect ) ; - } + Rect clientrect = { 0 , 0 , m_height , m_width } ; + ClipRect( &clientrect ) ; + InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } m_x = actualX ; @@ -583,7 +637,8 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ( doResize ) ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height , true); - // the OS takes care of invalidating and erasing + // the OS takes care of invalidating and erasing the new area + // we have erased the old one if ( IsKindOf( CLASSINFO( wxFrame ) ) ) { @@ -595,14 +650,17 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) else { // erase new position + { - wxMacDrawingClientHelper focus( this ) ; + wxMacDrawingHelper focus( this ) ; if ( focus.Ok() ) { Rect clientrect = { 0 , 0 , m_height , m_width } ; + ClipRect( &clientrect ) ; InvalWindowRect( GetMacRootWindow() , &clientrect ) ; } } + if ( doMove ) wxWindow::MacSuperChangedPosition() ; // like this only children will be notified } @@ -706,6 +764,24 @@ void wxWindow::MacSuperShown( bool show ) } } +bool wxWindow::MacIsReallyShown() const +{ + if ( m_isShown && (m_parent != NULL) ) { + return m_parent->MacIsReallyShown(); + } + return m_isShown; +/* + bool status = m_isShown ; + wxWindow * win = this ; + while ( status && win->m_parent != NULL ) + { + win = win->m_parent ; + status = win->m_isShown ; + } + return status ; +*/ +} + int wxWindow::GetCharHeight() const { wxClientDC dc ( (wxWindow*)this ) ; @@ -727,7 +803,7 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, wxClientDC dc( (wxWindow*) this ) ; long lx,ly,ld,le ; - dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ; + dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; if ( externalLeading ) *externalLeading = le ; if ( descent ) @@ -740,6 +816,7 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, void wxWindow::MacEraseBackground( Rect *rect ) { +/* WindowRef window = GetMacRootWindow() ; if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) ) { @@ -807,6 +884,7 @@ void wxWindow::MacEraseBackground( Rect *rect ) } } } +*/ } void wxWindow::Refresh(bool eraseBack, const wxRect *rect) @@ -999,8 +1077,8 @@ void wxWindow::MacCreateRealWindow( const wxString& title, // translate the window attributes in the appropriate window class and attributes - WindowClass wclass ; - WindowAttributes attr ; + WindowClass wclass = 0; + WindowAttributes attr = kWindowNoAttributes ; if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) ) { @@ -1010,35 +1088,22 @@ void wxWindow::MacCreateRealWindow( const wxString& title, attr |= kWindowSideTitlebarAttribute ; } } - else if ( HasFlag( wxTHICK_FRAME ) ) + else if ( HasFlag( wxCAPTION ) ) { if ( HasFlag( wxDIALOG_MODAL ) ) { wclass = kMovableModalWindowClass ; } - else if ( HasFlag( wxDIALOG_MODELESS ) ) + else { wclass = kDocumentWindowClass ; } - else - { - if ( HasFlag( wxCAPTION ) ) - { - wclass = kDocumentWindowClass ; - } - else - { - wclass = kModalWindowClass ; - } - } } else { wclass = kModalWindowClass ; } - attr = kWindowNoAttributes ; - if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ) { attr |= kWindowFullZoomAttribute ; @@ -1345,6 +1410,30 @@ wxObject* wxWindow::GetChild(int number) const } #endif // WXWIN_COMPATIBILITY +void wxWindow::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 becaus + // otherwise when the top level panel gets focus, it won't set it back to + // us, but to some other sibling + wxWindow *win = this; + while ( win ) + { + wxWindow *parent = win->GetParent(); + wxPanel *panel = wxDynamicCast(parent, wxPanel); + if ( panel ) + { + panel->SetLastFocus(win); + } + + win = parent; + } + + event.Skip(); +} + void wxWindow::Clear() { if ( m_macWindowData ) @@ -1509,6 +1598,13 @@ bool wxWindow::MacDispatchMouseEvent(wxMouseEvent& event) { m_cursor.MacInstall() ; } + + if ( event.GetEventType() == wxEVT_LEFT_DOWN ) + { + // set focus to this window + if (AcceptsFocus() && FindFocus()!=this) + SetFocus(); + } #if wxUSE_TOOLTIPS if ( event.GetEventType() == wxEVT_MOTION @@ -1658,7 +1754,7 @@ void wxWindow::MacMouseMoved( EventRecord *ev , short part) } void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating ) { - wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating); + wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId); event.m_timeStamp = ev->when ; event.SetEventObject(this); @@ -1738,8 +1834,10 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time) if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() ) eraseBackground = true ; SetClip( updatergn ) ; - if ( eraseBackground ) + if ( eraseBackground && m_macEraseOnRedraw ) { + // todo : find a clever algorithm, which only will do this + // if really necessary EraseRgn( updatergn ) ; } } @@ -2007,56 +2105,6 @@ void wxWindow::MacSuperChangedPosition() node = node->Next(); } } -/* - -bool wxWindow::MacSetupFocusPort( ) -{ - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - GrafPtr port ; - - MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; - return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; -} - -bool wxWindow::MacSetupFocusClientPort( ) -{ - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - GrafPtr port ; - - MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; - return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; -} - -bool wxWindow::MacSetupDrawingPort( ) -{ - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - GrafPtr port ; - - MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; - return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; -} - -bool wxWindow::MacSetupDrawingClientPort( ) -{ - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - GrafPtr port ; - - MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; - return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ; -} -*/ bool wxWindow::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindow* win ) { @@ -2271,37 +2319,8 @@ long wxWindow::MacRemoveBordersFromStyle( long style ) { return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; } -/* -wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow ) -{ - m_ok = false ; - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - m_currentPort = NULL ; - GetPort( &m_formerPort ) ; - if ( theWindow ) - { - - theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; - m_currentPort = UMAGetWindowPort( window ) ; - theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; - m_ok = true ; - } -} - -wxMacFocusHelper::~wxMacFocusHelper() -{ - if ( m_ok ) - { - SetPort( m_currentPort ) ; - SetOrigin( 0 , 0 ) ; - } - if ( m_formerPort != m_currentPort ) - SetPort( m_formerPort ) ; -} -*/ + + wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) { m_ok = false ; @@ -2334,43 +2353,12 @@ wxMacDrawingHelper::~wxMacDrawingHelper() Rect portRect ; GetPortBounds( m_currentPort , &portRect ) ; ClipRect( &portRect ) ; + wxDC::MacInvalidateSetup() ; } if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } -/* -wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow ) -{ - m_ok = false ; - Point localOrigin ; - Rect clipRect ; - WindowRef window ; - wxWindow *rootwin ; - m_currentPort = NULL ; - - GetPort( &m_formerPort ) ; - - if ( theWindow ) - { - theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ; - m_currentPort = UMAGetWindowPort( window ) ; - theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; - m_ok = true ; - } -} - -wxMacFocusClientHelper::~wxMacFocusClientHelper() -{ - if ( m_ok ) - { - SetPort( m_currentPort ) ; - SetOrigin( 0 , 0 ) ; - } - if ( m_formerPort != m_currentPort ) - SetPort( m_formerPort ) ; -} -*/ wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow * theWindow ) {