Merge branch 'notebook-add-page-events'
Harmonize events sent by wxNotebook::AddPage(): they are now sent only when adding any page except the first one if it is selected in all ports. See https://github.com/wxWidgets/wxWidgets/pull/1192
This commit is contained in:
@@ -62,6 +62,9 @@ Changes in behaviour not resulting in compilation errors
|
|||||||
- Generic wxDataViewCtrl now always resizes its last column to fill all the
|
- Generic wxDataViewCtrl now always resizes its last column to fill all the
|
||||||
available space, as the GTK+ version always did.
|
available space, as the GTK+ version always did.
|
||||||
|
|
||||||
|
- wxGTK wxNotebook::AddPage() doesn't generate any events any more for the
|
||||||
|
first page being added, for consistency with the other ports.
|
||||||
|
|
||||||
|
|
||||||
Changes in behaviour which may result in build errors
|
Changes in behaviour which may result in build errors
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
|
@@ -42,8 +42,8 @@ public:
|
|||||||
|
|
||||||
virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
|
virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
|
||||||
|
|
||||||
int SetSelection(size_t nPage) { return DoSetSelection(nPage, SetSelection_SendEvent); }
|
int SetSelection(size_t nPage);
|
||||||
int ChangeSelection(size_t nPage) { return DoSetSelection(nPage); }
|
int ChangeSelection(size_t nPage);
|
||||||
|
|
||||||
virtual bool DeleteAllPages() wxOVERRIDE;
|
virtual bool DeleteAllPages() wxOVERRIDE;
|
||||||
|
|
||||||
@@ -51,7 +51,6 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual wxWindow *DoRemovePage(size_t page);
|
virtual wxWindow *DoRemovePage(size_t page);
|
||||||
int DoSetSelection(size_t nPage, int flags = 0);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTabWidget *m_qtTabWidget;
|
QTabWidget *m_qtTabWidget;
|
||||||
|
@@ -249,7 +249,10 @@ public:
|
|||||||
The page must have the book control itself as the parent and must not
|
The page must have the book control itself as the parent and must not
|
||||||
have been added to this control previously.
|
have been added to this control previously.
|
||||||
|
|
||||||
The call to this function may generate the page changing events.
|
The call to this function will generate the page changing and page
|
||||||
|
changed events if @a select is true, but not when inserting the very
|
||||||
|
first page (as there is no previous page selection to switch from in
|
||||||
|
this case and so it wouldn't make sense to e.g. veto such event).
|
||||||
|
|
||||||
@param page
|
@param page
|
||||||
Specifies the new page.
|
Specifies the new page.
|
||||||
|
@@ -464,7 +464,12 @@ bool wxNotebook::InsertPage( size_t position,
|
|||||||
pageData->m_label, false, false, m_padding);
|
pageData->m_label, false, false, m_padding);
|
||||||
|
|
||||||
gtk_widget_show_all(pageData->m_box);
|
gtk_widget_show_all(pageData->m_box);
|
||||||
|
|
||||||
|
// Inserting the page may generate selection changing events that are not
|
||||||
|
// expected here: we will send them ourselves below if necessary.
|
||||||
|
g_signal_handlers_block_by_func(m_widget, (void*)switch_page, this);
|
||||||
gtk_notebook_insert_page(notebook, win->m_widget, pageData->m_box, position);
|
gtk_notebook_insert_page(notebook, win->m_widget, pageData->m_box, position);
|
||||||
|
g_signal_handlers_unblock_by_func(m_widget, (void*)switch_page, this);
|
||||||
|
|
||||||
/* apply current style */
|
/* apply current style */
|
||||||
#ifdef __WXGTK3__
|
#ifdef __WXGTK3__
|
||||||
@@ -478,10 +483,7 @@ bool wxNotebook::InsertPage( size_t position,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (select && GetPageCount() > 1)
|
DoSetSelectionAfterInsertion(position, select);
|
||||||
{
|
|
||||||
SetSelection( position );
|
|
||||||
}
|
|
||||||
|
|
||||||
InvalidateBestSize();
|
InvalidateBestSize();
|
||||||
return true;
|
return true;
|
||||||
|
@@ -154,12 +154,8 @@ bool wxNotebook::InsertPage(size_t n, wxWindow *page, const wxString& text,
|
|||||||
|
|
||||||
// reenable firing qt signals as internal wx initialization was completed
|
// reenable firing qt signals as internal wx initialization was completed
|
||||||
m_qtTabWidget->blockSignals(false);
|
m_qtTabWidget->blockSignals(false);
|
||||||
m_selection = m_qtTabWidget->currentIndex();
|
|
||||||
|
|
||||||
if (bSelect && GetPageCount() > 1)
|
DoSetSelectionAfterInsertion(n, bSelect);
|
||||||
{
|
|
||||||
SetSelection( n );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -180,27 +176,31 @@ bool wxNotebook::DeleteAllPages()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNotebook::DoSetSelection(size_t page, int flags)
|
int wxNotebook::SetSelection(size_t page)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index");
|
wxCHECK_MSG(page < GetPageCount(), wxNOT_FOUND, "invalid notebook index");
|
||||||
|
|
||||||
int selOld = GetSelection();
|
int selOld = GetSelection();
|
||||||
|
|
||||||
// do not fire signals for certain methods (i.e. ChangeSelection
|
|
||||||
if ( !(flags & SetSelection_SendEvent) )
|
|
||||||
{
|
|
||||||
m_qtTabWidget->blockSignals(true);
|
|
||||||
}
|
|
||||||
// change the QTabWidget selected page:
|
// change the QTabWidget selected page:
|
||||||
m_selection = page;
|
m_selection = page;
|
||||||
m_qtTabWidget->setCurrentIndex( page );
|
m_qtTabWidget->setCurrentIndex( page );
|
||||||
if ( !(flags & SetSelection_SendEvent) )
|
|
||||||
{
|
|
||||||
m_qtTabWidget->blockSignals(false);
|
|
||||||
}
|
|
||||||
return selOld;
|
return selOld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wxNotebook::ChangeSelection(size_t nPage)
|
||||||
|
{
|
||||||
|
// ChangeSelection() is not supposed to generate events, unlike
|
||||||
|
// SetSelection().
|
||||||
|
m_qtTabWidget->blockSignals(true);
|
||||||
|
|
||||||
|
const int selOld = SetSelection(nPage);
|
||||||
|
|
||||||
|
m_qtTabWidget->blockSignals(false);
|
||||||
|
|
||||||
|
return selOld;
|
||||||
|
}
|
||||||
|
|
||||||
wxWindow *wxNotebook::DoRemovePage(size_t page)
|
wxWindow *wxNotebook::DoRemovePage(size_t page)
|
||||||
{
|
{
|
||||||
|
@@ -20,7 +20,9 @@
|
|||||||
#endif // WX_PRECOMP
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
#include "wx/notebook.h"
|
#include "wx/notebook.h"
|
||||||
|
|
||||||
#include "bookctrlbasetest.h"
|
#include "bookctrlbasetest.h"
|
||||||
|
#include "testableframe.h"
|
||||||
|
|
||||||
class NotebookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase
|
class NotebookTestCase : public BookCtrlBaseTestCase, public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
@@ -118,4 +120,48 @@ void NotebookTestCase::NoEventsOnDestruction()
|
|||||||
CHECK( m_numPageChanges == 1 );
|
CHECK( m_numPageChanges == 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("wxNotebook::AddPageEvents", "[wxNotebook][AddPage][event]")
|
||||||
|
{
|
||||||
|
wxNotebook* const
|
||||||
|
notebook = new wxNotebook(wxTheApp->GetTopWindow(), wxID_ANY,
|
||||||
|
wxDefaultPosition, wxSize(400, 200));
|
||||||
|
|
||||||
|
CHECK( notebook->GetSelection() == wxNOT_FOUND );
|
||||||
|
|
||||||
|
EventCounter countPageChanging(notebook, wxEVT_NOTEBOOK_PAGE_CHANGING);
|
||||||
|
EventCounter countPageChanged(notebook, wxEVT_NOTEBOOK_PAGE_CHANGED);
|
||||||
|
|
||||||
|
// Add the first page, it is special.
|
||||||
|
notebook->AddPage(new wxPanel(notebook), "Initial page");
|
||||||
|
|
||||||
|
// The selection should have been changed.
|
||||||
|
CHECK( notebook->GetSelection() == 0 );
|
||||||
|
|
||||||
|
// But no events should have been generated.
|
||||||
|
CHECK( countPageChanging.GetCount() == 0 );
|
||||||
|
CHECK( countPageChanged.GetCount() == 0 );
|
||||||
|
|
||||||
|
|
||||||
|
// Add another page without selecting it.
|
||||||
|
notebook->AddPage(new wxPanel(notebook), "Unselected page");
|
||||||
|
|
||||||
|
// Selection shouldn't have changed.
|
||||||
|
CHECK( notebook->GetSelection() == 0 );
|
||||||
|
|
||||||
|
// And no events should have been generated, of course.
|
||||||
|
CHECK( countPageChanging.GetCount() == 0 );
|
||||||
|
CHECK( countPageChanged.GetCount() == 0 );
|
||||||
|
|
||||||
|
|
||||||
|
// Finally add another page and do select it.
|
||||||
|
notebook->AddPage(new wxPanel(notebook), "Selected page", true);
|
||||||
|
|
||||||
|
// It should have become selected.
|
||||||
|
CHECK( notebook->GetSelection() == 2 );
|
||||||
|
|
||||||
|
// And events for the selection change should have been generated.
|
||||||
|
CHECK( countPageChanging.GetCount() == 1 );
|
||||||
|
CHECK( countPageChanged.GetCount() == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
#endif //wxUSE_NOTEBOOK
|
#endif //wxUSE_NOTEBOOK
|
||||||
|
Reference in New Issue
Block a user