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:
Vadim Zeitlin
2019-01-30 17:38:51 +01:00
6 changed files with 76 additions and 23 deletions

View File

@@ -464,7 +464,12 @@ bool wxNotebook::InsertPage( size_t position,
pageData->m_label, false, false, m_padding);
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);
g_signal_handlers_unblock_by_func(m_widget, (void*)switch_page, this);
/* apply current style */
#ifdef __WXGTK3__
@@ -478,10 +483,7 @@ bool wxNotebook::InsertPage( size_t position,
}
#endif
if (select && GetPageCount() > 1)
{
SetSelection( position );
}
DoSetSelectionAfterInsertion(position, select);
InvalidateBestSize();
return true;

View File

@@ -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
m_qtTabWidget->blockSignals(false);
m_selection = m_qtTabWidget->currentIndex();
if (bSelect && GetPageCount() > 1)
{
SetSelection( n );
}
DoSetSelectionAfterInsertion(n, bSelect);
return true;
}
@@ -180,27 +176,31 @@ bool wxNotebook::DeleteAllPages()
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");
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:
m_selection = page;
m_qtTabWidget->setCurrentIndex( page );
if ( !(flags & SetSelection_SendEvent) )
{
m_qtTabWidget->blockSignals(false);
}
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)
{