]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/window.cpp
corrected the invalidation when resizing windows (was only invalidating the client...
[wxWidgets.git] / src / mac / window.cpp
index 8c14292b7ddd2bc865723694f97eb30b04e9cb15..6aa38ca851694ac1760d6fe557e887c65e4d3535 100644 (file)
@@ -23,6 +23,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"
@@ -31,7 +33,7 @@
 #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/window.h"
 
 #include "wx/menuitem.h"
 #include "wx/log.h"
@@ -437,8 +439,8 @@ void wxWindow::DoGetClientSize(int *x, int *y) const
     *x = m_width ;
     *y = m_height ;
 
-       *x -= 2 * MacGetBorderSize(  ) ;
-       *y -= 2 * MacGetBorderSize(  ) ;
+       *x -= MacGetLeftBorderSize(  )  + MacGetRightBorderSize(  ) ;
+       *y -= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( );
        
   if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar  && m_hScrollBar->IsShown()) )
   {
@@ -562,13 +564,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 ;
@@ -595,14 +596,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
                }
@@ -627,7 +631,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 
 wxPoint wxWindow::GetClientAreaOrigin() const
 {
-    return wxPoint(MacGetBorderSize(  ) , MacGetBorderSize(  ) );
+    return wxPoint(MacGetLeftBorderSize(  ) , MacGetTopBorderSize(  ) );
 }
 
 // Makes an adjustment to the window position (for example, a frame that has
@@ -725,7 +729,7 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
     if ( !fontToUse )
         fontToUse = &m_font;
         
-    wxClientDC dc( this ) ;
+    wxClientDC dc( (wxWindow*) this ) ;
     long lx,ly,ld,le ;
     dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ;
     if ( externalLeading )
@@ -999,8 +1003,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) )
        {
@@ -1037,8 +1041,6 @@ void  wxWindow::MacCreateRealWindow( const wxString& title,
                wclass = kModalWindowClass ;
        }
        
-       attr = kWindowNoAttributes ;
-       
        if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
        {
                attr |= kWindowFullZoomAttribute ;
@@ -1271,36 +1273,26 @@ void wxWindow::MacOnScroll(wxScrollEvent &event )
            wevent.SetOrientation(event.GetOrientation());
            wevent.m_eventObject = this;
        
-           switch ( event.m_eventType )
-           {
-           case wxEVT_SCROLL_TOP:
+       if (event.m_eventType == wxEVT_SCROLL_TOP) {
                wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
-               break;
-       
-           case wxEVT_SCROLL_BOTTOM:
+           } else
+       if (event.m_eventType == wxEVT_SCROLL_BOTTOM) {
                wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
-               break;
-       
-           case wxEVT_SCROLL_LINEUP:
+           } else
+       if (event.m_eventType == wxEVT_SCROLL_LINEUP) {
                wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
-               break;
-       
-           case wxEVT_SCROLL_LINEDOWN:
+           } else
+       if (event.m_eventType == wxEVT_SCROLL_LINEDOWN) {
                wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
-               break;
-       
-           case wxEVT_SCROLL_PAGEUP:
+           } else
+       if (event.m_eventType == wxEVT_SCROLL_PAGEUP) {
                wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
-               break;
-       
-           case wxEVT_SCROLL_PAGEDOWN:
+           } else
+       if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN) {
                wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
-               break;
-       
-           case wxEVT_SCROLL_THUMBTRACK:
+           } else
+       if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK) {
                wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
-               break;
-       
            }
                
            GetEventHandler()->ProcessEvent(wevent);
@@ -1427,8 +1419,8 @@ void wxWindow::DoSetClientSize(int width, int height)
                if ( height != -1 && m_vScrollBar )
                        height += MAC_SCROLLBAR_SIZE ;
 
-               width += 2 * MacGetBorderSize(  ) ;
-               height += 2 * MacGetBorderSize(  ) ;
+               width += MacGetLeftBorderSize(  ) + MacGetRightBorderSize( ) ;
+               height += MacGetTopBorderSize(  ) + MacGetBottomBorderSize( ) ;
 
                DoSetSize( -1 , -1 , width , height ) ;
        }
@@ -1453,7 +1445,8 @@ bool wxWindow::MacGetWindowFromPointSub( const wxPoint &point , wxWindow** outWi
        for (wxNode *node = GetChildren().First(); node; node = node->Next())
        {
                wxWindow *child = (wxWindow*)node->Data();
-               if ( child->GetMacRootWindow() == window )
+               // added the m_isShown test --dmazzoni
+               if ( child->GetMacRootWindow() == window && child->m_isShown )
                {
                        if (child->MacGetWindowFromPointSub(newPoint , outWin ))
                                return TRUE;
@@ -1472,9 +1465,12 @@ bool wxWindow::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindow** ou
        {
                        wxPoint point( screenpoint ) ;
                        wxWindow* win = wxFindWinFromMacWindow( window ) ;
+                       if ( win )
+                       {
                        win->ScreenToClient( point ) ;
                        return win->MacGetWindowFromPointSub( point , outWin ) ;
        }
+       }
        return FALSE ;
 }
 
@@ -1917,8 +1913,8 @@ void wxWindow::MacRepositionScrollBars()
        int width = m_width ; 
        int height = m_height ;
 
-       width -= 2 * MacGetBorderSize() ;
-       height -= 2 * MacGetBorderSize() ;
+       width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
+       height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
        
        wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
        wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
@@ -2193,7 +2189,7 @@ void wxWindow::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, Window
        SectRect(clipRect, &myClip, clipRect);
 }
 
-long wxWindow::MacGetBorderSize( ) const
+long wxWindow::MacGetLeftBorderSize( ) const
 {
        if( m_macWindowData )
                return 0 ;
@@ -2213,41 +2209,72 @@ long wxWindow::MacGetBorderSize( ) const
        return 0 ;
 }
 
-long wxWindow::MacRemoveBordersFromStyle( long style ) 
+long wxWindow::MacGetRightBorderSize( ) const
 {
-       return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
+       if( m_macWindowData )
+               return 0 ;
+
+    if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
+    {
+               return 3 ;
+    }
+    else if (  m_windowStyle &wxDOUBLE_BORDER)
+    {
+               return 3 ;
+    }
+    else if (m_windowStyle &wxSIMPLE_BORDER)
+    {
+       return 3 ;
+    }
+       return 0 ;
 }
-/*
-wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow ) 
+
+long wxWindow::MacGetTopBorderSize( ) const
 {
-       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 ;
-       }
+       if( m_macWindowData )
+               return 0 ;
+
+    if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
+    {
+               return 2 ;
+    }
+    else if (  m_windowStyle &wxDOUBLE_BORDER)
+    {
+               return 2 ;
+    }
+    else if (m_windowStyle &wxSIMPLE_BORDER)
+    {
+       return 1 ;
+    }
+       return 0 ;
 }
-       
-wxMacFocusHelper::~wxMacFocusHelper() 
+
+long wxWindow::MacGetBottomBorderSize( ) const
 {
-       if ( m_ok )
-       {
-               SetPort( m_currentPort ) ;
-               SetOrigin( 0 , 0 ) ;
-       }
-       if ( m_formerPort != m_currentPort )
-               SetPort( m_formerPort ) ;
+       if( m_macWindowData )
+               return 0 ;
+
+    if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
+    {
+               return 3 ;
+    }
+    else if (  m_windowStyle &wxDOUBLE_BORDER)
+    {
+               return 3 ;
+    }
+    else if (m_windowStyle &wxSIMPLE_BORDER)
+    {
+       return 3 ;
+    }
+       return 0 ;
 }
-*/
+
+long wxWindow::MacRemoveBordersFromStyle( long style ) 
+{
+       return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
+}
+
+
 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) 
 {
        m_ok = false ;
@@ -2280,43 +2307,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 ) 
 {
@@ -2356,3 +2352,21 @@ wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
        if ( m_formerPort != m_currentPort )
                SetPort( m_formerPort ) ;
 }
+
+// Find the wxWindow at the current mouse position, returning the mouse
+// position.
+wxWindow* wxFindWindowAtPointer(wxPoint& pt)
+{
+    pt = wxGetMousePosition();
+    wxWindow* found = wxFindWindowAtPoint(pt);
+    return found;
+}
+
+// Get the current mouse position.
+wxPoint wxGetMousePosition()
+{
+    int x, y;
+    wxGetMousePosition(& x, & y);
+    return wxPoint(x, y);
+}
+