]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/window.cpp
some != NULL checks
[wxWidgets.git] / src / mac / window.cpp
index 18ab38338affebb05e738ede0f61c16741bcfddd..f8099265a2094b1dc026ee55dc26349fdf83653d 100644 (file)
 #include "wx/menuitem.h"
 #include "wx/log.h"
 
+#if wxUSE_CARET
+    #include "wx/caret.h"
+#endif // wxUSE_CARET
+
 #define wxWINDOW_HSCROLL 5998
 #define wxWINDOW_VSCROLL 5997
 #define MAC_SCROLLBAR_SIZE 16
@@ -50,7 +54,6 @@
 extern wxList wxPendingDelete;
 wxWindow* gFocusWindow = NULL ;
 
-#if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
 
 BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
@@ -58,9 +61,9 @@ BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
   EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
   EVT_INIT_DIALOG(wxWindow::OnInitDialog)
   EVT_IDLE(wxWindow::OnIdle)
+//  EVT_SCROLL(wxWindow::OnScroll)
 END_EVENT_TABLE()
 
-#endif
 
 
 
@@ -197,25 +200,45 @@ void wxWindow::SetFocus()
        {
                if (gFocusWindow )
                {
+                       #if wxUSE_CARET
+                           // Deal with caret
+                           if ( gFocusWindow->m_caret )
+                           {
+                                 gFocusWindow->m_caret->OnKillFocus();
+                           }
+                       #endif // wxUSE_CARET
                        wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
                        if ( control && control->GetMacControl() )
                        {
                                UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl()  , kControlFocusNoPart ) ;
                        }
-           wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
-           event.SetEventObject(gFocusWindow);
+               wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
+               event.SetEventObject(gFocusWindow);
                        gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
                }
                gFocusWindow = this ;
                {
+                       #if wxUSE_CARET
+                   // Deal with caret
+                   if ( m_caret )
+                   {
+                       m_caret->OnSetFocus();
+                   }
+                       #endif // wxUSE_CARET
+                       // panel wants to track the window which was the last to have focus in it
+               wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
+               if ( panel )
+               {
+                       panel->SetLastFocus(this);
+               }
                        wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
                        if ( control && control->GetMacControl() )
                        {
                                UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl()  , kControlEditTextPart ) ;
                        }
 
-           wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
-           event.SetEventObject(this);
+               wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
+               event.SetEventObject(this);
                        GetEventHandler()->ProcessEvent(event) ;
                }
        }
@@ -295,6 +318,25 @@ void wxWindow::DoGetPosition(int *x, int *y) const
     }
 }
 
+
+
+
+
+bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
+{
+       menu->SetInvokingWindow(this);
+    menu->UpdateUI();
+       ClientToScreen( &x , &y ) ;
+
+       ::InsertMenu( menu->GetHMenu() , -1 ) ;
+       long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ;
+       menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ;
+       ::DeleteMenu( menu->MacGetMenuId() ) ;
+       menu->SetInvokingWindow(NULL);
+
+  return TRUE;
+}
+
 void wxWindow::DoScreenToClient(int *x, int *y) const
 {
        WindowRef window = GetMacRootWindow() ;
@@ -401,6 +443,28 @@ void wxWindow::DoGetClientSize(int *x, int *y) const
        (*y) -= MAC_SCROLLBAR_SIZE;
 }
 
+
+// ----------------------------------------------------------------------------
+// tooltips
+// ----------------------------------------------------------------------------
+
+#if wxUSE_TOOLTIPS
+
+void wxWindow::DoSetToolTip(wxToolTip *tooltip)
+{
+    wxWindowBase::DoSetToolTip(tooltip);
+
+//    if ( m_tooltip )
+//        m_tooltip->SetWindow(this);
+}
+
+#endif // wxUSE_TOOLTIPS
+
+void wxWindow::DoMoveWindow(int x, int y, int width, int height)
+{
+       DoSetSize( x,y, width, height ) ;
+}
+
 void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 {
        int former_x = m_x ;
@@ -578,11 +642,24 @@ bool wxWindow::Show(bool show)
                UMAHideWindow( m_macWindowData->m_macWindow ) ;
          }
        }
+       MacSuperShown( show ) ;
        Refresh() ;
 
     return TRUE;
 }
 
+void wxWindow::MacSuperShown( bool show ) 
+{
+       wxNode *node = GetChildren().First();
+       while ( node )
+       {
+               wxWindow *child = (wxWindow *)node->Data();
+               if ( child->m_isShown )
+                       child->MacSuperShown( show ) ;
+               node = node->Next();
+       }
+}
+
 int wxWindow::GetCharHeight() const
 {
        wxClientDC dc ( (wxWindow*)this ) ;
@@ -601,17 +678,14 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
     const wxFont *fontToUse = theFont;
     if ( !fontToUse )
         fontToUse = &m_font;
-/*
-    if ( x )
-        *x = sizeRect.cx;
-    if ( y )
-        *y = sizeRect.cy;
-    if ( descent )
-        *descent = tm.tmDescent;
-    if ( externalLeading )
-        *externalLeading = tm.tmExternalLeading;
-*/
-
+        
+    wxClientDC dc( this ) ;
+    long lx,ly,ld,le ;
+    dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ;
+    *externalLeading = le ;
+    *descent = ld ;
+    *x = lx ;
+    *y = ly ;
 }
 
 void wxWindow::MacEraseBackground( Rect *rect )
@@ -790,7 +864,6 @@ void wxWindow::WarpPointer (int x_pos, int y_pos)
 void wxWindow::OnEraseBackground(wxEraseEvent& event)
 {
     // TODO : probably we would adopt the EraseEvent structure
-    Default();
 }
 
 int wxWindow::GetScrollPos(int orient) const
@@ -854,6 +927,43 @@ void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
                }
 }
 
+void wxWindow::MacPaint( wxPaintEvent &event ) 
+{
+    wxPaintDC dc(this);
+    PrepareDC(dc);
+
+    if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
+    {
+       bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
+
+               wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
+               wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
+       
+               wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
+               wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
+               wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
+               wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
+       
+               dc.SetPen(wxPen1);
+               dc.DrawRectangle(0, 0, m_width, m_height);          // outer - right and button
+       
+           dc.SetPen(wxPen2);
+               dc.DrawRectangle(1, 1, m_width-1, m_height-1);      // outer - left and top
+       
+           dc.SetPen(wxPen3);
+               dc.DrawRectangle(0, 0, m_width-2, m_height-2);          // inner - right and button
+       
+           dc.SetPen(wxPen4);
+               dc.DrawLine(0, 0, m_width-3, 0);                 // inner - left and top
+               dc.DrawLine(0, 0, 0, m_height-3);
+    }
+    else if (HasFlag(wxSIMPLE_BORDER))
+    {
+               dc.SetPen(*wxBLACK_PEN);
+               dc.DrawRectangle(0, 0, m_width, m_height);         
+    }
+}
+
 // New function that will replace some of the above.
 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
     int range, bool refresh)
@@ -918,6 +1028,51 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
        }
 }
 
+void wxWindow::MacOnScroll(wxScrollEvent &event )
+{
+       if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
+       {
+           wxScrollWinEvent wevent;
+           wevent.SetPosition(event.GetPosition());
+           wevent.SetOrientation(event.GetOrientation());
+           wevent.m_eventObject = this;
+       
+           switch ( event.m_eventType )
+           {
+           case wxEVT_SCROLL_TOP:
+               wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
+               break;
+       
+           case wxEVT_SCROLL_BOTTOM:
+               wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
+               break;
+       
+           case wxEVT_SCROLL_LINEUP:
+               wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
+               break;
+       
+           case wxEVT_SCROLL_LINEDOWN:
+               wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
+               break;
+       
+           case wxEVT_SCROLL_PAGEUP:
+               wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
+               break;
+       
+           case wxEVT_SCROLL_PAGEDOWN:
+               wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
+               break;
+       
+           case wxEVT_SCROLL_THUMBTRACK:
+               wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
+               break;
+       
+           }
+               
+           GetEventHandler()->ProcessEvent(wevent);
+    }
+}
+
 bool wxWindow::SetFont(const wxFont& font)
 {
     if ( !wxWindowBase::SetFont(font) )
@@ -1256,6 +1411,9 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time)
                if ( focus.Ok() )
                {
                        WindowRef window = GetMacRootWindow() ;
+                       bool eraseBackground = false ;
+                       if ( m_macWindowData )
+                               eraseBackground = true ;
                        if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
                        {
                                        UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
@@ -1282,13 +1440,13 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time)
                                                        if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
                                                        {
                                                                // if we have any other colours in the hierarchy
-                                                       RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
-                                                       break ;
+                                                               RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
+                                                               break ;
                                                        }
                                                        // if we have the normal colours in the hierarchy but another control etc. -> use it's background
                                                        if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
                                                        {
-                                                               ApplyThemeBackground                    (kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true);
+                                                               ApplyThemeBackground(kThemeBackgroundTabPane, &(**updatergn).rgnBBox , kThemeStateActive,8,true);
                                                                break ;
                                                        }
                                                }
@@ -1309,8 +1467,13 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time)
                        {
                                RGBBackColor( &m_backgroundColour.GetPixel()) ;
                        }
+                       if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
+                               eraseBackground = true ;
                        SetClip( updatergn ) ;
-                       EraseRgn( updatergn ) ; 
+                       if ( eraseBackground )
+                       {
+                               EraseRgn( updatergn ) ; 
+                       }
                }
        }
 
@@ -1320,7 +1483,9 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time)
        event.m_timeStamp = time ;
        event.SetEventObject(this);
        
+       wxPaintEvent event2( event ) ;
        GetEventHandler()->ProcessEvent(event);
+       MacPaint( event2 ) ;
        
        RgnHandle childupdate = NewRgn() ;
 
@@ -1428,12 +1593,15 @@ void wxWindow::MacCreateScrollBars( long style )
        {
                m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, wxPoint(m_width-MAC_SCROLLBAR_SIZE, 0), 
                        wxSize(MAC_SCROLLBAR_SIZE, m_height - adjust), wxVERTICAL);
+//             m_vScrollBar->PushEventHandler( this ) ;
        }
        if ( style  & wxHSCROLL )
        {
                m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, wxPoint(0 , m_height-MAC_SCROLLBAR_SIZE ), 
                        wxSize( m_width - adjust, MAC_SCROLLBAR_SIZE), wxHORIZONTAL);
+//             m_hScrollBar->PushEventHandler( this ) ;
        }
+       
        // because the create does not take into account the client area origin
        MacRepositionScrollBars() ; // we might have a real position shift
 }
@@ -1458,7 +1626,10 @@ void wxWindow::MacKeyDown( EventRecord *ev )
 }
 
 
-
+bool wxWindow::AcceptsFocus() const
+{
+    return MacCanFocus() && wxWindowBase::AcceptsFocus();
+}
 
 ControlHandle wxWindow::MacGetContainerForEmbedding() 
 {
@@ -1764,13 +1935,3 @@ wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
        if ( m_formerPort != m_currentPort )
                SetPort( m_formerPort ) ;
 }
-
-// ----------------------------------------------------------------------------
-// list classes implementation
-// ----------------------------------------------------------------------------
-
-void wxWindowListNode::DeleteData()
-{
-    delete (wxWindow *)GetData();
-}
-