Merge branch 'treebook-refactor'

Reuse more wxBookCtrlBase code in derived classes and other
simplifications.

Closes https://github.com/wxWidgets/wxWidgets/pull/769
This commit is contained in:
Vadim Zeitlin
2018-03-31 01:45:30 +02:00
17 changed files with 110 additions and 202 deletions

View File

@@ -63,6 +63,9 @@ Changes in behaviour which may result in build errors
This only affects code defining its own custom renderers, code just using This only affects code defining its own custom renderers, code just using
wxGraphicsContext::CreatePen() continues to compile and work as before. wxGraphicsContext::CreatePen() continues to compile and work as before.
- wx/treebook.h doesn't include wx/treectrl.h (and, via it, wx/textctrl.h) any
more, include these headers explicitly from your code if necessary.
3.1.2: (released 2018-??-??) 3.1.2: (released 2018-??-??)
---------------------------- ----------------------------

View File

@@ -20,11 +20,9 @@
#if wxUSE_BOOKCTRL #if wxUSE_BOOKCTRL
#include "wx/control.h" #include "wx/control.h"
#include "wx/dynarray.h" #include "wx/vector.h"
#include "wx/withimages.h" #include "wx/withimages.h"
WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow *, wxArrayPages);
class WXDLLIMPEXP_FWD_CORE wxImageList; class WXDLLIMPEXP_FWD_CORE wxImageList;
class WXDLLIMPEXP_FWD_CORE wxBookCtrlEvent; class WXDLLIMPEXP_FWD_CORE wxBookCtrlEvent;
@@ -94,7 +92,7 @@ public:
virtual size_t GetPageCount() const { return m_pages.size(); } virtual size_t GetPageCount() const { return m_pages.size(); }
// get the panel which represents the given page // get the panel which represents the given page
virtual wxWindow *GetPage(size_t n) const { return m_pages[n]; } virtual wxWindow *GetPage(size_t n) const { return m_pages.at(n); }
// get the current page or NULL if none // get the current page or NULL if none
wxWindow *GetCurrentPage() const wxWindow *GetCurrentPage() const
@@ -292,6 +290,12 @@ protected:
// having nodes without any associated page) // having nodes without any associated page)
virtual bool AllowNullPage() const { return false; } virtual bool AllowNullPage() const { return false; }
// For classes that allow null pages, we also need a way to find the
// closest non-NULL page corresponding to the given index, e.g. the first
// leaf item in wxTreebook tree and this method must be overridden to
// return it if AllowNullPage() is overridden.
virtual wxWindow *DoGetNonNullPage(size_t page) { return m_pages[page]; }
// Remove the page and return a pointer to it. // Remove the page and return a pointer to it.
// //
// It also needs to update the current selection if necessary, i.e. if the // It also needs to update the current selection if necessary, i.e. if the
@@ -325,7 +329,7 @@ protected:
// the array of all pages of this control // the array of all pages of this control
wxArrayPages m_pages; wxVector<wxWindow*> m_pages;
// get the page area // get the page area
virtual wxRect GetPageRect() const; virtual wxRect GetPageRect() const;

View File

@@ -86,8 +86,7 @@ protected:
void UpdateSelectedPage(size_t newsel) wxOVERRIDE void UpdateSelectedPage(size_t newsel) wxOVERRIDE
{ {
m_selection = static_cast<int>(newsel); GetChoiceCtrl()->Select(newsel);
GetChoiceCtrl()->Select(m_selection);
} }
wxBookCtrlEvent* CreatePageChangingEvent() const wxOVERRIDE; wxBookCtrlEvent* CreatePageChangingEvent() const wxOVERRIDE;

View File

@@ -155,9 +155,10 @@ public:
} }
protected: protected:
virtual void UpdateSelectedPage(size_t newsel) wxOVERRIDE virtual void UpdateSelectedPage(size_t WXUNUSED(newsel)) wxOVERRIDE
{ {
m_selection = (int)newsel; // Nothing to do here, but must be overridden to avoid the assert in
// the base class version.
} }
virtual wxBookCtrlEvent* CreatePageChangingEvent() const wxOVERRIDE virtual wxBookCtrlEvent* CreatePageChangingEvent() const wxOVERRIDE

View File

@@ -17,10 +17,12 @@
#include "wx/bookctrl.h" #include "wx/bookctrl.h"
#include "wx/containr.h" #include "wx/containr.h"
#include "wx/treectrl.h" // for wxArrayTreeItemIds #include "wx/treebase.h" // for wxTreeItemId
#include "wx/vector.h"
typedef wxWindow wxTreebookPage; typedef wxWindow wxTreebookPage;
class WXDLLIMPEXP_FWD_CORE wxTreeCtrl;
class WXDLLIMPEXP_FWD_CORE wxTreeEvent; class WXDLLIMPEXP_FWD_CORE wxTreeEvent;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -36,7 +38,6 @@ public:
// Default ctor doesn't create the control, use Create() afterwards // Default ctor doesn't create the control, use Create() afterwards
wxTreebook() wxTreebook()
{ {
Init();
} }
// This ctor creates the tree book control // This ctor creates the tree book control
@@ -47,8 +48,6 @@ public:
long style = wxBK_DEFAULT, long style = wxBK_DEFAULT,
const wxString& name = wxEmptyString) const wxString& name = wxEmptyString)
{ {
Init();
(void)Create(parent, id, pos, size, style, name); (void)Create(parent, id, pos, size, style, name);
} }
@@ -143,22 +142,16 @@ protected:
// This subclass of wxBookCtrlBase accepts NULL page pointers (empty pages) // This subclass of wxBookCtrlBase accepts NULL page pointers (empty pages)
virtual bool AllowNullPage() const wxOVERRIDE { return true; } virtual bool AllowNullPage() const wxOVERRIDE { return true; }
virtual wxWindow *DoGetNonNullPage(size_t page) wxOVERRIDE;
// event handlers // event handlers
void OnTreeSelectionChange(wxTreeEvent& event); void OnTreeSelectionChange(wxTreeEvent& event);
void OnTreeNodeExpandedCollapsed(wxTreeEvent& event); void OnTreeNodeExpandedCollapsed(wxTreeEvent& event);
// array of page ids and page windows // array of tree item ids corresponding to the page indices
wxArrayTreeItemIds m_treeIds; wxVector<wxTreeItemId> m_treeIds;
// in the situation when m_selection page is not wxNOT_FOUND but page is
// NULL this is the first (sub)child that has a non-NULL page
int m_actualSelection;
private: private:
// common part of all constructors
void Init();
// The real implementations of page insertion functions // The real implementations of page insertion functions
// ------------------------------------------------------ // ------------------------------------------------------
// All DoInsert/Add(Sub)Page functions add the page into : // All DoInsert/Add(Sub)Page functions add the page into :
@@ -180,12 +173,11 @@ private:
bool bSelect = false, bool bSelect = false,
int imageId = NO_IMAGE); int imageId = NO_IMAGE);
// Sets selection in the tree control and updates the page being shown. // Overridden methods used by the base class DoSetSelection()
int DoSetSelection(size_t pos, int flags = 0) wxOVERRIDE; // implementation.
void UpdateSelectedPage(size_t newsel) wxOVERRIDE;
// Returns currently shown page. In a case when selected the node wxBookCtrlEvent* CreatePageChangingEvent() const wxOVERRIDE;
// has empty (NULL) page finds first (sub)child with not-empty page. void MakeChangedEvent(wxBookCtrlEvent &event) wxOVERRIDE;
wxTreebookPage *DoGetCurrentPage() const;
// Does the selection update. Called from page insertion functions // Does the selection update. Called from page insertion functions
// to update selection if the selected page was pushed by the newly inserted // to update selection if the selected page was pushed by the newly inserted
@@ -216,7 +208,7 @@ private:
// Returns internal number of pages which can be different from // Returns internal number of pages which can be different from
// GetPageCount() while performing a page insertion or removal. // GetPageCount() while performing a page insertion or removal.
size_t DoInternalGetPageCount() const { return m_treeIds.GetCount(); } size_t DoInternalGetPageCount() const { return m_treeIds.size(); }
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();

View File

@@ -49,6 +49,7 @@
#include "wx/numdlg.h" #include "wx/numdlg.h"
#include "wx/textdlg.h" #include "wx/textdlg.h"
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/treectrl.h"
#include "wx/wupdlock.h" #include "wx/wupdlock.h"
#include "wx/textcompleter.h" #include "wx/textcompleter.h"
@@ -723,20 +724,7 @@ void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent& event)
{ {
wxWindowUpdateLocker noUpdates(curPage); wxWindowUpdateLocker noUpdates(curPage);
curPage->CreateContent(); curPage->CreateContent();
//curPage->Layout(); curPage->Layout();
curPage->GetSizer()->Fit(curPage);
WidgetsBookCtrl *book = wxStaticCast(curPage->GetParent(), WidgetsBookCtrl);
wxSize size;
for ( size_t i = 0; i < book->GetPageCount(); ++i )
{
wxWindow *page = book->GetPage(i);
if ( page )
{
size.IncTo(page->GetSize());
}
}
curPage->SetSize(size);
} }
// re-apply the attributes to the widget(s) // re-apply the attributes to the widget(s)
curPage->SetUpWidget(); curPage->SetUpWidget();

View File

@@ -41,6 +41,7 @@ class WXDLLIMPEXP_FWD_CORE wxCheckBox;
class WXDLLIMPEXP_FWD_CORE wxSizer; class WXDLLIMPEXP_FWD_CORE wxSizer;
class WXDLLIMPEXP_FWD_CORE wxImageList; class WXDLLIMPEXP_FWD_CORE wxImageList;
class WXDLLIMPEXP_FWD_CORE wxTextCtrl; class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
class WXDLLIMPEXP_FWD_CORE wxTextEntryBase;
class WXDLLIMPEXP_FWD_CORE WidgetsBookCtrl; class WXDLLIMPEXP_FWD_CORE WidgetsBookCtrl;
class WidgetsPageInfo; class WidgetsPageInfo;

View File

@@ -241,8 +241,8 @@ void wxBookCtrlBase::DoSize()
// resize all pages to fit the new control size // resize all pages to fit the new control size
const wxRect pageRect = GetPageRect(); const wxRect pageRect = GetPageRect();
const unsigned pagesCount = m_pages.GetCount(); const size_t pagesCount = m_pages.size();
for ( unsigned int i = 0; i < pagesCount; ++i ) for ( size_t i = 0; i < pagesCount; ++i )
{ {
wxWindow * const page = m_pages[i]; wxWindow * const page = m_pages[i];
if ( !page ) if ( !page )
@@ -310,7 +310,7 @@ void wxBookCtrlBase::OnHelp(wxHelpEvent& event)
source = source->GetParent(); source = source->GetParent();
} }
if ( source && m_pages.Index(source) == wxNOT_FOUND ) if ( source && FindPage(source) == wxNOT_FOUND )
{ {
// this event is for the book control itself, redirect it to the // this event is for the book control itself, redirect it to the
// corresponding page // corresponding page
@@ -368,7 +368,7 @@ wxBookCtrlBase::InsertPage(size_t nPage,
wxCHECK_MSG( nPage <= m_pages.size(), false, wxCHECK_MSG( nPage <= m_pages.size(), false,
wxT("invalid page index in wxBookCtrlBase::InsertPage()") ); wxT("invalid page index in wxBookCtrlBase::InsertPage()") );
m_pages.Insert(page, nPage); m_pages.insert(m_pages.begin() + nPage, page);
if ( page ) if ( page )
page->SetSize(GetPageRect()); page->SetSize(GetPageRect());
@@ -395,7 +395,7 @@ wxWindow *wxBookCtrlBase::DoRemovePage(size_t nPage)
wxT("invalid page index in wxBookCtrlBase::DoRemovePage()") ); wxT("invalid page index in wxBookCtrlBase::DoRemovePage()") );
wxWindow *pageRemoved = m_pages[nPage]; wxWindow *pageRemoved = m_pages[nPage];
m_pages.RemoveAt(nPage); m_pages.erase(m_pages.begin() + nPage);
DoInvalidateBestSize(); DoInvalidateBestSize();
return pageRemoved; return pageRemoved;
@@ -479,7 +479,7 @@ int wxBookCtrlBase::DoSetSelection(size_t n, int flags)
if ( n != (size_t)oldSel ) if ( n != (size_t)oldSel )
{ {
wxBookCtrlEvent *event = CreatePageChangingEvent(); wxBookCtrlEvent *event = CreatePageChangingEvent();
bool allowed = false; bool allowed = true;
if ( flags & SetSelection_SendEvent ) if ( flags & SetSelection_SendEvent )
{ {
@@ -490,16 +490,17 @@ int wxBookCtrlBase::DoSetSelection(size_t n, int flags)
allowed = !GetEventHandler()->ProcessEvent(*event) || event->IsAllowed(); allowed = !GetEventHandler()->ProcessEvent(*event) || event->IsAllowed();
} }
if ( !(flags & SetSelection_SendEvent) || allowed) if ( allowed )
{ {
if ( oldSel != wxNOT_FOUND ) if ( oldSel != wxNOT_FOUND )
DoShowPage(m_pages[oldSel], false); DoShowPage(DoGetNonNullPage(oldSel), false);
wxWindow *page = m_pages[n]; wxWindow* const page = DoGetNonNullPage(n);
page->SetSize(GetPageRect()); page->SetSize(GetPageRect());
DoShowPage(page, true); DoShowPage(page, true);
// change selection now to ignore the selection change event // change selection now to ignore the selection change event
m_selection = n;
UpdateSelectedPage(n); UpdateSelectedPage(n);
if ( flags & SetSelection_SendEvent ) if ( flags & SetSelection_SendEvent )
@@ -509,6 +510,15 @@ int wxBookCtrlBase::DoSetSelection(size_t n, int flags)
(void)GetEventHandler()->ProcessEvent(*event); (void)GetEventHandler()->ProcessEvent(*event);
} }
} }
else
{
// Selection in the control might have already had changed.
if ( oldSel != wxNOT_FOUND )
{
m_selection = oldSel;
UpdateSelectedPage(oldSel);
}
}
delete event; delete event;
} }

View File

@@ -293,7 +293,6 @@ void wxListbook::SetImageList(wxImageList *imageList)
void wxListbook::UpdateSelectedPage(size_t newsel) void wxListbook::UpdateSelectedPage(size_t newsel)
{ {
m_selection = newsel;
GetListView()->Select(newsel); GetListView()->Select(newsel);
GetListView()->Focus(newsel); GetListView()->Focus(newsel);
} }

View File

@@ -197,7 +197,6 @@ void wxToolbook::MakeChangedEvent(wxBookCtrlEvent &event)
void wxToolbook::UpdateSelectedPage(size_t newsel) void wxToolbook::UpdateSelectedPage(size_t newsel)
{ {
m_selection = newsel;
GetToolBar()->ToggleTool(newsel + 1, true); GetToolBar()->ToggleTool(newsel + 1, true);
} }

View File

@@ -32,6 +32,7 @@
#endif #endif
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/treectrl.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// various wxWidgets macros // various wxWidgets macros
@@ -65,12 +66,6 @@ wxEND_EVENT_TABLE()
// wxTreebook creation // wxTreebook creation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxTreebook::Init()
{
m_selection =
m_actualSelection = wxNOT_FOUND;
}
bool bool
wxTreebook::Create(wxWindow *parent, wxTreebook::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
@@ -140,7 +135,7 @@ bool wxTreebook::InsertSubPage(size_t pagePos,
bool wxTreebook::AddPage(wxWindow *page, const wxString& text, bool bSelect, bool wxTreebook::AddPage(wxWindow *page, const wxString& text, bool bSelect,
int imageId) int imageId)
{ {
return DoInsertPage(m_treeIds.GetCount(), page, text, bSelect, imageId); return DoInsertPage(m_treeIds.size(), page, text, bSelect, imageId);
} }
// insertion time is linear to the number of top-pages // insertion time is linear to the number of top-pages
@@ -312,9 +307,7 @@ wxTreebookPage *wxTreebook::DoRemovePage(size_t pagePos)
bool wxTreebook::DeleteAllPages() bool wxTreebook::DeleteAllPages()
{ {
wxBookCtrlBase::DeleteAllPages(); wxBookCtrlBase::DeleteAllPages();
m_treeIds.Clear(); m_treeIds.clear();
m_selection =
m_actualSelection = wxNOT_FOUND;
wxTreeCtrl *tree = GetTreeCtrl(); wxTreeCtrl *tree = GetTreeCtrl();
tree->DeleteChildren(tree->GetRootItem()); tree->DeleteChildren(tree->GetRootItem());
@@ -326,32 +319,26 @@ void wxTreebook::DoInternalAddPage(size_t newPos,
wxTreebookPage *page, wxTreebookPage *page,
wxTreeItemId pageId) wxTreeItemId pageId)
{ {
wxASSERT_MSG( newPos <= m_treeIds.GetCount(), wxT("Ivalid index passed to wxTreebook::DoInternalAddPage") ); wxASSERT_MSG( newPos <= m_treeIds.size(),
wxT("Invalid index passed to wxTreebook::DoInternalAddPage") );
// hide newly inserted page initially (it will be shown when selected) // hide newly inserted page initially (it will be shown when selected)
if ( page ) if ( page )
page->Hide(); page->Hide();
if ( newPos == m_treeIds.GetCount() ) if ( newPos == m_treeIds.size() )
{ {
// append // append
m_treeIds.Add(pageId); m_treeIds.push_back(pageId);
} }
else // insert else // insert
{ {
m_treeIds.Insert(pageId, newPos); m_treeIds.insert(m_treeIds.begin() + newPos, pageId);
if ( m_selection != wxNOT_FOUND && newPos <= (size_t)m_selection ) if ( m_selection != wxNOT_FOUND && newPos <= (size_t)m_selection )
{ {
// selection has been moved one unit toward the end // selection has been moved one unit toward the end
++m_selection; ++m_selection;
if ( m_actualSelection != wxNOT_FOUND )
++m_actualSelection;
}
else if ( m_actualSelection != wxNOT_FOUND &&
newPos <= (size_t)m_actualSelection )
{
DoSetSelection(m_selection);
} }
} }
} }
@@ -361,12 +348,13 @@ void wxTreebook::DoInternalRemovePageRange(size_t pagePos, size_t subCount)
// Attention: this function is only for a situation when we delete a node // Attention: this function is only for a situation when we delete a node
// with all its children so pagePos is the node's index and subCount is the // with all its children so pagePos is the node's index and subCount is the
// node children count // node children count
wxASSERT_MSG( pagePos + subCount < m_treeIds.GetCount(), wxASSERT_MSG( pagePos + subCount < m_treeIds.size(),
wxT("Ivalid page index") ); wxT("Invalid page index") );
wxTreeItemId pageId = m_treeIds[pagePos]; wxTreeItemId pageId = m_treeIds[pagePos];
m_treeIds.RemoveAt(pagePos, subCount + 1); wxVector<wxTreeItemId>::iterator itPos = m_treeIds.begin() + pagePos;
m_treeIds.erase(itPos, itPos + subCount + 1);
if ( m_selection != wxNOT_FOUND ) if ( m_selection != wxNOT_FOUND )
{ {
@@ -374,10 +362,6 @@ void wxTreebook::DoInternalRemovePageRange(size_t pagePos, size_t subCount)
{ {
// selection is far after the deleted page, so just update the index and move on // selection is far after the deleted page, so just update the index and move on
m_selection -= 1 + subCount; m_selection -= 1 + subCount;
if ( m_actualSelection != wxNOT_FOUND)
{
m_actualSelection -= subCount + 1;
}
} }
else if ( (size_t)m_selection >= pagePos ) else if ( (size_t)m_selection >= pagePos )
{ {
@@ -388,7 +372,6 @@ void wxTreebook::DoInternalRemovePageRange(size_t pagePos, size_t subCount)
wxTreeItemId nodeId = tree->GetNextSibling(pageId); wxTreeItemId nodeId = tree->GetNextSibling(pageId);
m_selection = wxNOT_FOUND; m_selection = wxNOT_FOUND;
m_actualSelection = wxNOT_FOUND;
if ( nodeId.IsOk() ) if ( nodeId.IsOk() )
{ {
@@ -410,17 +393,6 @@ void wxTreebook::DoInternalRemovePageRange(size_t pagePos, size_t subCount)
} }
} }
} }
else if ( m_actualSelection != wxNOT_FOUND &&
(size_t)m_actualSelection >= pagePos )
{
// nothing to do -- selection is before the deleted node, but
// actually shown page (the first (sub)child with page != NULL) is
// already deleted
m_actualSelection = m_selection;
// send event as documented
DoSetSelection(m_selection, SetSelection_SendEvent);
}
//else: nothing to do -- selection is before the deleted node //else: nothing to do -- selection is before the deleted node
} }
else else
@@ -454,7 +426,7 @@ void wxTreebook::DoUpdateSelection(bool bSelect, int newPos)
wxTreeItemId wxTreebook::DoInternalGetPage(size_t pagePos) const wxTreeItemId wxTreebook::DoInternalGetPage(size_t pagePos) const
{ {
if ( pagePos >= m_treeIds.GetCount() ) if ( pagePos >= m_treeIds.size() )
{ {
// invalid position but ok here, in this internal function, don't assert // invalid position but ok here, in this internal function, don't assert
// (the caller will do it) // (the caller will do it)
@@ -466,7 +438,7 @@ wxTreeItemId wxTreebook::DoInternalGetPage(size_t pagePos) const
int wxTreebook::DoInternalFindPageById(wxTreeItemId pageId) const int wxTreebook::DoInternalFindPageById(wxTreeItemId pageId) const
{ {
const size_t count = m_treeIds.GetCount(); const size_t count = m_treeIds.size();
for ( size_t i = 0; i < count; ++i ) for ( size_t i = 0; i < count; ++i )
{ {
if ( m_treeIds[i] == pageId ) if ( m_treeIds[i] == pageId )
@@ -555,91 +527,41 @@ bool wxTreebook::SetPageImage(size_t n, int imageId)
return true; return true;
} }
int wxTreebook::DoSetSelection(size_t pagePos, int flags) void wxTreebook::UpdateSelectedPage(size_t newsel)
{ {
wxCHECK_MSG( IS_VALID_PAGE(pagePos), wxNOT_FOUND, GetTreeCtrl()->SelectItem(DoInternalGetPage(newsel));
wxT("invalid page index in wxListbook::DoSetSelection()") );
wxASSERT_MSG( GetPageCount() == DoInternalGetPageCount(),
wxT("wxTreebook logic error: m_treeIds and m_pages not in sync!"));
wxBookCtrlEvent event(wxEVT_TREEBOOK_PAGE_CHANGING, m_windowId);
const int oldSel = m_selection;
wxTreeCtrl *tree = GetTreeCtrl();
bool allowed = false;
if (flags & SetSelection_SendEvent)
{
event.SetEventObject(this);
event.SetSelection(pagePos);
event.SetOldSelection(m_selection);
// don't send the event if the old and new pages are the same; do send it
// otherwise and be prepared for it to be vetoed
allowed = (int)pagePos == m_selection ||
!GetEventHandler()->ProcessEvent(event) ||
event.IsAllowed();
}
if ( !(flags & SetSelection_SendEvent) || allowed )
{
// hide the previously shown page
wxTreebookPage * const oldPage = DoGetCurrentPage();
if ( oldPage )
oldPage->Hide();
// then show the new one
m_selection = pagePos;
wxTreebookPage *page = wxBookCtrlBase::GetPage(m_selection);
if ( !page )
{
// find the next page suitable to be shown: the first (grand)child
// of this one with a non-NULL associated page
wxTreeItemId childId = m_treeIds[pagePos];
int actualPagePos = pagePos;
while ( !page && childId.IsOk() )
{
wxTreeItemIdValue cookie;
childId = tree->GetFirstChild( childId, cookie );
if ( childId.IsOk() )
{
page = wxBookCtrlBase::GetPage(++actualPagePos);
}
}
m_actualSelection = page ? actualPagePos : m_selection;
}
if ( page )
page->Show();
tree->SelectItem(DoInternalGetPage(pagePos));
if (flags & SetSelection_SendEvent)
{
// notify about the (now completed) page change
event.SetEventType(wxEVT_TREEBOOK_PAGE_CHANGED);
(void)GetEventHandler()->ProcessEvent(event);
}
}
else if ( (flags & SetSelection_SendEvent) && !allowed) // page change vetoed
{
// tree selection might have already had changed
if ( oldSel != wxNOT_FOUND )
tree->SelectItem(DoInternalGetPage(oldSel));
}
return oldSel;
} }
wxTreebookPage *wxTreebook::DoGetCurrentPage() const wxBookCtrlEvent* wxTreebook::CreatePageChangingEvent() const
{ {
if ( m_selection == wxNOT_FOUND ) return new wxBookCtrlEvent(wxEVT_TREEBOOK_PAGE_CHANGING, m_windowId);
return NULL; }
wxTreebookPage *page = wxBookCtrlBase::GetPage(m_selection); void wxTreebook::MakeChangedEvent(wxBookCtrlEvent &event)
if ( !page && m_actualSelection != wxNOT_FOUND ) {
event.SetEventType(wxEVT_TREEBOOK_PAGE_CHANGED);
}
wxWindow *wxTreebook::DoGetNonNullPage(size_t n)
{
wxWindow* page = wxBookCtrlBase::GetPage(n);
if ( !page )
{ {
page = wxBookCtrlBase::GetPage(m_actualSelection); // Find the next suitable page, i.e. the first (grand)child
// of this one with a non-NULL associated page
wxTreeCtrl* const tree = GetTreeCtrl();
for ( wxTreeItemId childId = m_treeIds[n]; childId.IsOk(); )
{
wxTreeItemIdValue cookie;
childId = tree->GetFirstChild( childId, cookie );
if ( childId.IsOk() )
{
page = wxBookCtrlBase::GetPage(++n);
if ( page )
break;
}
}
} }
return page; return page;

View File

@@ -418,7 +418,7 @@ bool wxNotebook::InsertPage( size_t position,
wxGtkNotebookPage* pageData = new wxGtkNotebookPage; wxGtkNotebookPage* pageData = new wxGtkNotebookPage;
m_pages.Insert(win, position); m_pages.insert(m_pages.begin() + position, win);
m_pagesData.Insert(position, pageData); m_pagesData.Insert(position, pageData);
// set the label image and text // set the label image and text

View File

@@ -586,7 +586,6 @@ bool wxNotebook::DeleteAllPages()
wxASSERT_MSG( GetPageCount() == 0, wxT("all pages must have been deleted") ); wxASSERT_MSG( GetPageCount() == 0, wxT("all pages must have been deleted") );
InvalidateBestSize();
return wxNotebookBase::DeleteAllPages(); return wxNotebookBase::DeleteAllPages();
} }
@@ -661,7 +660,7 @@ bool wxNotebook::InsertPage( size_t position,
else else
m_pagesData.Insert( position, nb_page ); m_pagesData.Insert( position, nb_page );
m_pages.Insert(win, position); m_pages.insert(m_pages.begin() + position, win);
nb_page->m_box = gtk_hbox_new( FALSE, 1 ); nb_page->m_box = gtk_hbox_new( FALSE, 1 );
gtk_container_border_width( GTK_CONTAINER(nb_page->m_box), 2 ); gtk_container_border_width( GTK_CONTAINER(nb_page->m_box), 2 );

View File

@@ -309,9 +309,9 @@ wxNotebook::~wxNotebook()
size_t wxNotebook::GetPageCount() const size_t wxNotebook::GetPageCount() const
{ {
// consistency check // consistency check
wxASSERT( (int)m_pages.Count() == TabCtrl_GetItemCount(GetHwnd()) ); wxASSERT( (int)m_pages.size() == TabCtrl_GetItemCount(GetHwnd()) );
return m_pages.Count(); return m_pages.size();
} }
int wxNotebook::GetRowCount() const int wxNotebook::GetRowCount() const
@@ -404,7 +404,7 @@ bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
if ( ret && rows != GetRowCount() ) if ( ret && rows != GetRowCount() )
{ {
const wxRect r = GetPageSize(); const wxRect r = GetPageSize();
const size_t count = m_pages.Count(); const size_t count = m_pages.size();
for ( size_t page = 0; page < count; page++ ) for ( size_t page = 0; page < count; page++ )
m_pages[page]->SetSize(r); m_pages[page]->SetSize(r);
} }
@@ -578,7 +578,7 @@ wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
if ( !TabCtrl_DeleteItem(GetHwnd(), nPage) ) if ( !TabCtrl_DeleteItem(GetHwnd(), nPage) )
wxLogLastError(wxS("TabCtrl_DeleteItem()")); wxLogLastError(wxS("TabCtrl_DeleteItem()"));
if ( m_pages.IsEmpty() ) if ( m_pages.empty() )
{ {
// no selection any more, the notebook becamse empty // no selection any more, the notebook becamse empty
m_selection = wxNOT_FOUND; m_selection = wxNOT_FOUND;
@@ -622,19 +622,11 @@ wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
// remove all pages // remove all pages
bool wxNotebook::DeleteAllPages() bool wxNotebook::DeleteAllPages()
{ {
size_t nPageCount = GetPageCount(); wxBookCtrlBase::DeleteAllPages();
size_t nPage;
for ( nPage = 0; nPage < nPageCount; nPage++ )
delete m_pages[nPage];
m_pages.Clear();
if ( !TabCtrl_DeleteAllItems(GetHwnd()) ) if ( !TabCtrl_DeleteAllItems(GetHwnd()) )
wxLogLastError(wxS("TabCtrl_DeleteAllItems()")); wxLogLastError(wxS("TabCtrl_DeleteAllItems()"));
m_selection = wxNOT_FOUND;
InvalidateBestSize();
return true; return true;
} }
@@ -701,13 +693,13 @@ bool wxNotebook::InsertPage(size_t nPage,
} }
// succeeded: save the pointer to the page // succeeded: save the pointer to the page
m_pages.Insert(pPage, nPage); m_pages.insert(m_pages.begin() + nPage, pPage);
// we may need to adjust the size again if the notebook size changed: // we may need to adjust the size again if the notebook size changed:
// normally this only happens for the first page we add (the tabs which // normally this only happens for the first page we add (the tabs which
// hadn't been there before are now shown) but for a multiline notebook it // hadn't been there before are now shown) but for a multiline notebook it
// can happen for any page at all as a new row could have been started // can happen for any page at all as a new row could have been started
if ( m_pages.GetCount() == 1 || HasFlag(wxNB_MULTILINE) ) if ( m_pages.size() == 1 || HasFlag(wxNB_MULTILINE) )
{ {
AdjustPageSize(pPage); AdjustPageSize(pPage);
@@ -967,7 +959,7 @@ void wxNotebook::OnSize(wxSizeEvent& event)
int width = rc.right - rc.left, int width = rc.right - rc.left,
height = rc.bottom - rc.top; height = rc.bottom - rc.top;
size_t nCount = m_pages.Count(); size_t nCount = m_pages.size();
for ( size_t nPage = 0; nPage < nCount; nPage++ ) { for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
wxNotebookPage *pPage = m_pages[nPage]; wxNotebookPage *pPage = m_pages[nPage];
pPage->SetSize(rc.left, rc.top, width, height); pPage->SetSize(rc.left, rc.top, width, height);

View File

@@ -173,7 +173,7 @@ wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage)
wxT("DoRemovePage: invalid notebook page") ); wxT("DoRemovePage: invalid notebook page") );
wxNotebookPage* page = m_pages[nPage] ; wxNotebookPage* page = m_pages[nPage] ;
m_pages.RemoveAt(nPage); m_pages.erase(m_pages.begin() + nPage);
m_images.RemoveAt(nPage); m_images.RemoveAt(nPage);
MacSetupTabs(); MacSetupTabs();
@@ -199,11 +199,10 @@ wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage)
// remove all pages // remove all pages
bool wxNotebook::DeleteAllPages() bool wxNotebook::DeleteAllPages()
{ {
WX_CLEAR_ARRAY(m_pages); wxBookCtrlBase::DeleteAllPages();
m_images.clear(); m_images.clear();
MacSetupTabs(); MacSetupTabs();
m_selection = wxNOT_FOUND ;
InvalidateBestSize();
return true; return true;
} }
@@ -286,7 +285,7 @@ wxRect wxNotebook::GetPageRect() const
// time because doing it in ::Create() doesn't work (for unknown reasons) // time because doing it in ::Create() doesn't work (for unknown reasons)
void wxNotebook::OnSize(wxSizeEvent& event) void wxNotebook::OnSize(wxSizeEvent& event)
{ {
unsigned int nCount = m_pages.Count(); unsigned int nCount = m_pages.size();
wxRect rect = GetPageRect() ; wxRect rect = GetPageRect() ;
for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) for ( unsigned int nPage = 0; nPage < nCount; nPage++ )

View File

@@ -150,7 +150,7 @@ bool wxNotebook::InsertPage(size_t n, wxWindow *page, const wxString& text,
m_qtTabWidget->insertTab( n, page->GetHandle(), wxQtConvertString( text )); m_qtTabWidget->insertTab( n, page->GetHandle(), wxQtConvertString( text ));
} }
m_pages.Insert(page, n); m_pages.insert(m_pages.begin() + n, page);
m_images.insert(m_images.begin() + n, imageId); m_images.insert(m_images.begin() + n, imageId);
// reenable firing qt signals as internal wx initialization was completed // reenable firing qt signals as internal wx initialization was completed

View File

@@ -304,7 +304,7 @@ bool wxNotebook::InsertPage(size_t nPage,
wxT("invalid notebook page in InsertPage()") ); wxT("invalid notebook page in InsertPage()") );
// modify the data // modify the data
m_pages.Insert(pPage, nPage); m_pages.insert(m_pages.begin() + nPage, pPage);
wxString label; wxString label;
m_accels.Insert(FindAccelIndex(strText, &label), nPage); m_accels.Insert(FindAccelIndex(strText, &label), nPage);
@@ -378,7 +378,7 @@ wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, wxT("invalid notebook page") ); wxCHECK_MSG( IS_VALID_PAGE(nPage), NULL, wxT("invalid notebook page") );
wxNotebookPage *page = m_pages[nPage]; wxNotebookPage *page = m_pages[nPage];
m_pages.RemoveAt(nPage); m_pages.erase(m_pages.begin() + nPage);
m_titles.RemoveAt(nPage); m_titles.RemoveAt(nPage);
m_accels.RemoveAt(nPage); m_accels.RemoveAt(nPage);
m_widths.RemoveAt(nPage); m_widths.RemoveAt(nPage);