]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/nbkbase.cpp
Support float, double and file name values in wxGenericValidator.
[wxWidgets.git] / src / common / nbkbase.cpp
index b219336aa0d0cd6781d9c916621263a26cc6ad74..d3e76ba2503606017bae24190c47413e54223f7b 100644 (file)
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
-    #pragma implementation "notebookbase.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 #ifndef WX_PRECOMP
 #endif //WX_PRECOMP
 
 #ifndef WX_PRECOMP
 #endif //WX_PRECOMP
 
-#include "wx/imaglist.h"
 #include "wx/notebook.h"
 
 #include "wx/notebook.h"
 
-#ifdef __GNUWIN32_OLD__
-    #include "wx/msw/gnuwin32/extra.h"
-#endif
-
-#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
-#include "wx/msw/private.h"
-#include <commctrl.h>
-#include "wx/msw/winundef.h"
-#endif
-
 // ============================================================================
 // implementation
 // ============================================================================
 
 // ============================================================================
 // implementation
 // ============================================================================
 
+extern WXDLLEXPORT_DATA(const char) wxNotebookNameStr[] = "notebook";
+
+wxDEFINE_EVENT( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxBookCtrlEvent );
+wxDEFINE_EVENT( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxBookCtrlEvent );
+
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
-// constructors and destructors
+// XTI
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 
-void wxNotebookBase::Init()
+#include "wx/listimpl.cpp"
+wxDEFINE_FLAGS( wxNotebookStyle )
+wxBEGIN_FLAGS( wxNotebookStyle )
+// new style border flags, we put them first to
+// use them for streaming out
+wxFLAGS_MEMBER(wxBORDER_SIMPLE)
+wxFLAGS_MEMBER(wxBORDER_SUNKEN)
+wxFLAGS_MEMBER(wxBORDER_DOUBLE)
+wxFLAGS_MEMBER(wxBORDER_RAISED)
+wxFLAGS_MEMBER(wxBORDER_STATIC)
+wxFLAGS_MEMBER(wxBORDER_NONE)
+
+// old style border flags
+wxFLAGS_MEMBER(wxSIMPLE_BORDER)
+wxFLAGS_MEMBER(wxSUNKEN_BORDER)
+wxFLAGS_MEMBER(wxDOUBLE_BORDER)
+wxFLAGS_MEMBER(wxRAISED_BORDER)
+wxFLAGS_MEMBER(wxSTATIC_BORDER)
+wxFLAGS_MEMBER(wxBORDER)
+
+// standard window styles
+wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
+wxFLAGS_MEMBER(wxCLIP_CHILDREN)
+wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
+wxFLAGS_MEMBER(wxWANTS_CHARS)
+wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
+wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
+wxFLAGS_MEMBER(wxVSCROLL)
+wxFLAGS_MEMBER(wxHSCROLL)
+
+wxFLAGS_MEMBER(wxNB_FIXEDWIDTH)
+wxFLAGS_MEMBER(wxBK_DEFAULT)
+wxFLAGS_MEMBER(wxBK_TOP)
+wxFLAGS_MEMBER(wxBK_LEFT)
+wxFLAGS_MEMBER(wxBK_RIGHT)
+wxFLAGS_MEMBER(wxBK_BOTTOM)
+wxFLAGS_MEMBER(wxNB_NOPAGETHEME)
+wxFLAGS_MEMBER(wxNB_FLAT)
+wxEND_FLAGS( wxNotebookStyle )
+
+#if wxUSE_EXTENDED_RTTI  
+
+WX_DEFINE_LIST( wxNotebookPageInfoList )
+
+wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebookPageInfo, wxObject, "wx/notebook.h" )
+
+wxCOLLECTION_TYPE_INFO( wxNotebookPageInfo *, wxNotebookPageInfoList );
+
+template<> void wxCollectionToVariantArray( wxNotebookPageInfoList const &theList,
+                                           wxAnyList &value)
+{
+    wxListCollectionToAnyList<wxNotebookPageInfoList::compatibility_iterator>( theList, value );
+}
+
+wxBEGIN_PROPERTIES_TABLE(wxNotebookPageInfo)
+wxREADONLY_PROPERTY( Page, wxNotebookPage*, GetPage, wxEMPTY_PARAMETER_VALUE, \
+                    0 /*flags*/, wxT("Helpstring"), wxT("group"))
+wxREADONLY_PROPERTY( Text, wxString, GetText, wxString(), 0 /*flags*/, \
+                    wxT("Helpstring"), wxT("group"))
+wxREADONLY_PROPERTY( Selected, bool, GetSelected, false, 0 /*flags*/, \
+                    wxT("Helpstring"), wxT("group") )
+wxREADONLY_PROPERTY( ImageId, int, GetImageId, -1, 0 /*flags*/, \
+                    wxT("Helpstring"), wxT("group"))
+wxEND_PROPERTIES_TABLE()
+
+wxEMPTY_HANDLERS_TABLE(wxNotebookPageInfo)
+
+wxCONSTRUCTOR_4( wxNotebookPageInfo, wxNotebookPage*, Page, \
+                wxString, Text, bool, Selected, int, ImageId )
+
+// WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxNotebookPageInfo**>)
+// XTI accessors:
+
+void wxNotebookBase::AddPageInfo( wxNotebookPageInfo* info )
 {
 {
-    m_imageList = NULL;
-    m_ownsImageList = FALSE;
+    AddPage( info->GetPage(), info->GetText(), info->GetSelected(), info->GetImageId() ); 
 }
 
 }
 
-wxNotebookBase::~wxNotebookBase()
+const wxNotebookPageInfoList& wxNotebookBase::GetPageInfos() const
 {
 {
-    if ( m_ownsImageList )
+    wxNotebookPageInfoList* list = const_cast< wxNotebookPageInfoList* >( &m_pageInfos );
+    WX_CLEAR_LIST( wxNotebookPageInfoList, *list );
+    for( size_t i = 0; i < GetPageCount(); ++i )
     {
     {
-        // may be NULL, ok
-        delete m_imageList;
+        wxNotebookPageInfo *info = new wxNotebookPageInfo();
+        info->Create( const_cast<wxNotebookBase*>(this)->GetPage(i), GetPageText(i),
+                     GetSelection() == int(i), GetPageImage(i) );
+        list->Append( info );
     }
     }
+    return m_pageInfos;
 }
 
 }
 
-// ----------------------------------------------------------------------------
-// image list
-// ----------------------------------------------------------------------------
+#endif
 
 
-void wxNotebookBase::SetImageList(wxImageList* imageList)
-{
-    if ( m_ownsImageList )
-    {
-        // may be NULL, ok
-        delete m_imageList;
+wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxNotebook, wxControl, "wx/notebook.h")
+wxBEGIN_PROPERTIES_TABLE(wxNotebook)
+wxEVENT_PROPERTY( PageChanging, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxNotebookEvent )
+wxEVENT_PROPERTY( PageChanged, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEvent )
 
 
-        m_ownsImageList = FALSE;
-    }
+wxPROPERTY_COLLECTION( PageInfos, wxNotebookPageInfoList, wxNotebookPageInfo*, \
+                      AddPageInfo, GetPageInfos, 0 /*flags*/, wxT("Helpstring"), \
+                      wxT("group"))
+wxPROPERTY_FLAGS( WindowStyle, wxNotebookStyle, long, SetWindowStyleFlag, \
+                 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
+                 wxT("Helpstring"), wxT("group")) // style
+wxEND_PROPERTIES_TABLE()
 
 
-    m_imageList = imageList;
-}
+wxEMPTY_HANDLERS_TABLE(wxNotebook)
 
 
-void wxNotebookBase::AssignImageList(wxImageList* imageList)
-{
-    SetImageList(imageList);
-    m_ownsImageList = TRUE;
-}
+wxCONSTRUCTOR_5( wxNotebook, wxWindow*, Parent, wxWindowID, Id, \
+                wxPoint, Position, wxSize, Size, long, WindowStyle)
 
 // ----------------------------------------------------------------------------
 // geometry
 
 // ----------------------------------------------------------------------------
 // geometry
@@ -102,7 +166,7 @@ wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) const
     // default because not all ports implement this
     wxSize sizeTotal = sizePage;
 
     // default because not all ports implement this
     wxSize sizeTotal = sizePage;
 
-    if ( HasFlag(wxNB_LEFT) || HasFlag(wxNB_RIGHT) )
+    if ( HasFlag(wxBK_LEFT) || HasFlag(wxBK_RIGHT) )
     {
         sizeTotal.x += 90;
         sizeTotal.y += 10;
     {
         sizeTotal.x += 90;
         sizeTotal.y += 10;
@@ -117,75 +181,25 @@ wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) const
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
-// pages management
+// events
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 
-bool wxNotebookBase::DeletePage(int nPage)
+bool wxNotebookBase::SendPageChangingEvent(int nPage)
 {
 {
-    wxNotebookPage *page = DoRemovePage(nPage);
-    if ( !page )
-        return FALSE;
-
-    delete page;
-
-    return TRUE;
-}
-
-wxNotebookPage *wxNotebookBase::DoRemovePage(int nPage)
-{
-    wxCHECK_MSG( nPage >= 0 && (size_t)nPage < m_pages.GetCount(), NULL,
-                 _T("invalid page index in wxNotebookBase::DoRemovePage()") );
-
-    wxNotebookPage *pageRemoved = m_pages[nPage];
-    m_pages.RemoveAt(nPage);
-
-    return pageRemoved;
-}
-
-wxSize wxNotebookBase::DoGetBestSize() const
-{
-    wxSize bestSize(0,0);
-    size_t nCount = m_pages.Count();
-
-    // iterate over all pages, get the largest width and height
-    for ( size_t nPage = 0; nPage < nCount; nPage++ )
-    {
-        wxNotebookPage *pPage = m_pages[nPage];
-        wxSize childBestSize(pPage->GetBestSize());
-
-        if ( childBestSize.x > bestSize.x )
-            bestSize.x = childBestSize.x;
-
-        if ( childBestSize.y > bestSize.y )
-            bestSize.y = childBestSize.y;
-    }
-
-    // convert display area to window area, adding the size neccessary for the tab control itself
-    return CalcSizeFromPage(bestSize);
+    wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, GetId());
+    event.SetSelection(nPage);
+    event.SetOldSelection(GetSelection());
+    event.SetEventObject(this);
+    return !GetEventHandler()->ProcessEvent(event) || event.IsAllowed();
 }
 
 }
 
-int wxNotebookBase::GetNextPage(bool forward) const
+void wxNotebookBase::SendPageChangedEvent(int nPageOld, int nPageNew)
 {
 {
-    int nPage;
-
-    int nMax = GetPageCount();
-    if ( nMax-- ) // decrement it to get the last valid index
-    {
-        int nSel = GetSelection();
-
-        // change selection wrapping if it becomes invalid
-        nPage = forward ? nSel == nMax ? 0
-                                       : nSel + 1
-                        : nSel == 0 ? nMax
-                                    : nSel - 1;
-    }
-    else // notebook is empty, no next page
-    {
-        nPage = -1;
-    }
-
-    return nPage;
+    wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, GetId());
+    event.SetSelection(nPageNew == -1 ? GetSelection() : nPageNew);
+    event.SetOldSelection(nPageOld);
+    event.SetEventObject(this);
+    GetEventHandler()->ProcessEvent(event);
 }
 
 #endif // wxUSE_NOTEBOOK
 }
 
 #endif // wxUSE_NOTEBOOK
-