]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/notebmac.cpp
document On{Open,Save}Document()
[wxWidgets.git] / src / mac / carbon / notebmac.cpp
index df02de6a4b2cc5f20549cfa9e574e0e5cd3f5eb1..6d00a7130dfd300c49cd2e47b63aaec4766261cf 100644 (file)
 
 #if wxUSE_NOTEBOOK
 
-#include "wx/app.h"
+#include "wx/notebook.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/string.h"
+    #include "wx/log.h"
+    #include "wx/app.h"
+    #include "wx/image.h"
+#endif
+
 #include "wx/string.h"
-#include "wx/log.h"
 #include "wx/imaglist.h"
-#include "wx/image.h"
-#include "wx/notebook.h"
 #include "wx/mac/uma.h"
 
 
@@ -29,7 +34,7 @@
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
 
-BEGIN_EVENT_TABLE(wxNotebook, wxControl)
+BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase)
     EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange)
 
     EVT_SIZE(wxNotebook::OnSize)
@@ -37,7 +42,7 @@ BEGIN_EVENT_TABLE(wxNotebook, wxControl)
     EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
 END_EVENT_TABLE()
 
-IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase)
 IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
 
 
@@ -75,6 +80,9 @@ bool wxNotebook::Create( wxWindow *parent,
 {
     m_macIsUserPane = false ;
 
+    if (! (style & wxBK_ALIGN_MASK))
+        style |= wxBK_TOP;
+
     if ( !wxNotebookBase::Create( parent, id, pos, size, style, name ) )
         return false;
 
@@ -96,18 +104,15 @@ bool wxNotebook::Create( wxWindow *parent,
     ControlTabSize tabsize;
     switch (GetWindowVariant())
     {
-       case wxWINDOW_VARIANT_MINI:
-            if ( UMAGetSystemVersion() >= 0x1030 )
-                tabsize = 3 ;
-            else
-                tabsize = kControlSizeSmall;
+        case wxWINDOW_VARIANT_MINI:
+            tabsize = 3 ;
             break;
 
-       case wxWINDOW_VARIANT_SMALL:
+        case wxWINDOW_VARIANT_SMALL:
             tabsize = kControlTabSizeSmall;
             break;
 
-       default:
+        default:
             tabsize = kControlTabSizeLarge;
             break;
     }
@@ -132,12 +137,12 @@ wxNotebook::~wxNotebook()
 // wxNotebook accessors
 // ----------------------------------------------------------------------------
 
-void wxNotebook::SetPadding(const wxSize& padding)
+void wxNotebook::SetPadding(const wxSize& WXUNUSED(padding))
 {
     // unsupported by OS
 }
 
-void wxNotebook::SetTabSize(const wxSize& sz)
+void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz))
 {
     // unsupported by OS
 }
@@ -152,25 +157,27 @@ wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
     return DoGetSizeFromClientSize( sizePage );
 }
 
-int wxNotebook::SetSelection(size_t nPage)
+int wxNotebook::DoSetSelection(size_t nPage, int flags)
 {
-    wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("SetSelection: invalid notebook page") );
+    wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("DoSetSelection: invalid notebook page") );
 
-    if ( int(nPage) != m_nSelection )
+    if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection )
     {
-        wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
-        event.SetSelection(nPage);
-        event.SetOldSelection(m_nSelection);
-        event.SetEventObject(this);
-        if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
+        if ( flags & SetSelection_SendEvent )
         {
-            // program allows the page change
-            event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
-            (void)GetEventHandler()->ProcessEvent(event);
+            if ( !SendPageChangingEvent(nPage) )
+            {
+                // vetoed by program
+                return m_nSelection;
+            }
+            //else: program allows the page change
 
-            ChangePage(m_nSelection, nPage);
+            SendPageChangedEvent(m_nSelection, nPage);
         }
+
+        ChangePage(m_nSelection, nPage);
     }
+    //else: no change
 
     return m_nSelection;
 }
@@ -180,7 +187,7 @@ bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
     wxCHECK_MSG( IS_VALID_PAGE(nPage), false, wxT("SetPageText: invalid notebook page") );
 
     wxNotebookPage *page = m_pages[nPage];
-    page->SetLabel(strText);
+    page->SetLabel(wxStripMenuCodes(strText));
     MacSetupTabs();
 
     return true;
@@ -274,7 +281,7 @@ bool wxNotebook::InsertPage(size_t nPage,
     // don't show pages by default (we'll need to adjust their size first)
     pPage->Show( false ) ;
 
-    pPage->SetLabel( strText );
+    pPage->SetLabel( wxStripMenuCodes(strText) );
 
     m_images.Insert( imageId, nPage );
 
@@ -319,15 +326,14 @@ int wxNotebook::HitTest(const wxPoint& pt, long * flags) const
 {
     int resultV = wxNOT_FOUND;
 
-#if TARGET_API_MAC_OSX
     const int countPages = GetPageCount();
 
     // we have to convert from Client to Window relative coordinates
-    wxPoint adjustedPt = pt + GetClientAreaOrigin(); 
+    wxPoint adjustedPt = pt + GetClientAreaOrigin();
     // and now to HIView native ones
     adjustedPt.x -= MacGetLeftBorderSize() ;
     adjustedPt.y -= MacGetTopBorderSize() ;
-    
+
     HIPoint hipoint= { adjustedPt.x , adjustedPt.y } ;
     HIViewPartCode outPart = 0 ;
     OSStatus err = HIViewGetPartHit( m_peer->GetControlRef(), &hipoint, &outPart );
@@ -360,7 +366,6 @@ int wxNotebook::HitTest(const wxPoint& pt, long * flags) const
 
     if ( outPart >= 1 && outPart <= countPages )
         resultV = outPart - 1 ;
-#endif // TARGET_API_MAC_OSX
 
     if (flags != NULL)
     {
@@ -368,9 +373,9 @@ int wxNotebook::HitTest(const wxPoint& pt, long * flags) const
 
         // we cannot differentiate better
         if (resultV >= 0)
-            *flags |= wxNB_HITTEST_ONLABEL;
+            *flags |= wxBK_HITTEST_ONLABEL;
         else
-            *flags |= wxNB_HITTEST_NOWHERE;
+            *flags |= wxBK_HITTEST_NOWHERE;
     }
 
     return resultV;
@@ -394,11 +399,11 @@ void wxNotebook::MacSetupTabs()
         page = m_pages[ii];
         info.version = kControlTabInfoVersionOne;
         info.iconSuiteID = 0;
-        wxMacCFStringHolder cflabel( page->GetLabel(), m_font.GetEncoding() ) ;
+        wxCFStringRef cflabel( page->GetLabel(), GetFont().GetEncoding() ) ;
         info.name = cflabel ;
         m_peer->SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ;
 
-        if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 )
+        if ( GetImageList() && GetPageImage(ii) >= 0 )
         {
             const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ;
             if ( bmap.Ok() )
@@ -408,7 +413,10 @@ void wxNotebook::MacSetupTabs()
                 wxMacCreateBitmapButton( &info, bmap ) ;
 
                 OSStatus err = m_peer->SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info );
-                wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ;
+                if ( err != noErr )
+                {
+                    wxFAIL_MSG("Error when setting icon on tab");
+                }
 
                 wxMacReleaseBitmapButton( &info ) ;
             }
@@ -417,9 +425,7 @@ void wxNotebook::MacSetupTabs()
         m_peer->SetTabEnabled( ii + 1, true ) ;
     }
 
-    Rect bounds;
-    m_peer->GetRectInWindowCoords( &bounds ) ;
-    InvalWindowRect( (WindowRef)MacGetTopLevelWindowRef(), &bounds );
+    Refresh();
 }
 
 wxRect wxNotebook::GetPageRect() const
@@ -506,7 +512,7 @@ void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
                 event.SetEventObject( this );
 
                 wxWindow *page = m_pages[m_nSelection];
-                if ( !page->GetEventHandler()->ProcessEvent( event ) )
+                if ( !page->HandleWindowEvent( event ) )
                 {
                     page->SetFocus();
                 }
@@ -524,7 +530,7 @@ void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
             if ( parent )
             {
                 event.SetCurrentFocus( this );
-                parent->GetEventHandler()->ProcessEvent( event );
+                parent->HandleWindowEvent( event );
             }
         }
     }
@@ -551,7 +557,7 @@ bool wxNotebook::DoPhase(int WXUNUSED(nPhase))
 
 #endif // wxUSE_CONSTRAINTS
 
-void wxNotebook::Command(wxCommandEvent& event)
+void wxNotebook::Command(wxCommandEvent& WXUNUSED(event))
 {
     wxFAIL_MSG(wxT("wxNotebook::Command not implemented"));
 }
@@ -591,7 +597,7 @@ wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTR
             wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId,
             newSel , m_nSelection );
         changing.SetEventObject( this );
-        GetEventHandler()->ProcessEvent( changing );
+        HandleWindowEvent( changing );
 
         if ( changing.IsAllowed() )
         {
@@ -599,7 +605,7 @@ wxInt32 wxNotebook::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTR
                 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId,
                 newSel, m_nSelection );
             event.SetEventObject( this );
-            GetEventHandler()->ProcessEvent( event );
+            HandleWindowEvent( event );
         }
         else
         {