Avoid events when implicitly selecting first wxBookCtrl page.
The first page added to a wxBookCtrlBase-derived control is always selected, even if "bSelect" argument of AddPage() was false. This is necessary because a non-empty book control must always have a selection but the "selection changed" event generated when doing it is unexpected. Fix this by not generating any events when the first page is implicitly selected. Closes #12075. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65967 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
03263ff73b
commit
60d5c563d2
@ -252,6 +252,17 @@ protected:
|
||||
// choose the default border for this window
|
||||
virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
|
||||
|
||||
// After the insertion of the page in the method InsertPage, calling this
|
||||
// method sets the selection to the given page or the first one if there is
|
||||
// still no selection. The "selection changed" event is sent only if
|
||||
// bSelect is true, so when it is false, no event is sent even if the
|
||||
// selection changed from wxNOT_FOUND to 0 when inserting the first page.
|
||||
//
|
||||
// Returns true if the selection was set to the specified page (explicitly
|
||||
// because of bSelect == true or implicitly because it's the first page) or
|
||||
// false otherwise.
|
||||
bool DoSetSelectionAfterInsertion(size_t n, bool bSelect);
|
||||
|
||||
// set the selection to the given page, sending the events (which can
|
||||
// possibly prevent the page change from taking place) if SendEvent flag is
|
||||
// included
|
||||
|
@ -471,6 +471,19 @@ int wxBookCtrlBase::GetNextPage(bool forward) const
|
||||
return nPage;
|
||||
}
|
||||
|
||||
bool wxBookCtrlBase::DoSetSelectionAfterInsertion(size_t n, bool bSelect)
|
||||
{
|
||||
if ( bSelect )
|
||||
SetSelection(n);
|
||||
else if ( m_selection == wxNOT_FOUND )
|
||||
ChangeSelection(0);
|
||||
else // We're not going to select this page.
|
||||
return false;
|
||||
|
||||
// Return true to indicate that we selected this page.
|
||||
return true;
|
||||
}
|
||||
|
||||
int wxBookCtrlBase::DoSetSelection(size_t n, int flags)
|
||||
{
|
||||
wxCHECK_MSG( n < GetPageCount(), wxNOT_FOUND,
|
||||
|
@ -195,20 +195,9 @@ wxChoicebook::InsertPage(size_t n,
|
||||
GetChoiceCtrl()->Select(m_selection);
|
||||
}
|
||||
|
||||
// some page should be selected: either this one or the first one if there
|
||||
// is still no selection
|
||||
int selNew = wxNOT_FOUND;
|
||||
if ( bSelect )
|
||||
selNew = n;
|
||||
else if ( m_selection == wxNOT_FOUND )
|
||||
selNew = 0;
|
||||
|
||||
if ( selNew != m_selection )
|
||||
if ( !DoSetSelectionAfterInsertion(n, bSelect) )
|
||||
page->Hide();
|
||||
|
||||
if ( selNew != wxNOT_FOUND )
|
||||
SetSelection(selNew);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -343,20 +343,9 @@ wxListbook::InsertPage(size_t n,
|
||||
GetListView()->Focus(m_selection);
|
||||
}
|
||||
|
||||
// some page should be selected: either this one or the first one if there
|
||||
// is still no selection
|
||||
int selNew = wxNOT_FOUND;
|
||||
if ( bSelect )
|
||||
selNew = n;
|
||||
else if ( m_selection == wxNOT_FOUND )
|
||||
selNew = 0;
|
||||
|
||||
if ( selNew != m_selection )
|
||||
if ( !DoSetSelectionAfterInsertion(n, bSelect) )
|
||||
page->Hide();
|
||||
|
||||
if ( selNew != wxNOT_FOUND )
|
||||
SetSelection(selNew);
|
||||
|
||||
UpdateSize();
|
||||
|
||||
return true;
|
||||
|
@ -842,16 +842,7 @@ bool wxNotebook::InsertPage(size_t nPage,
|
||||
m_selection++;
|
||||
}
|
||||
|
||||
// some page should be selected: either this one or the first one if there
|
||||
// is still no selection
|
||||
int selNew = wxNOT_FOUND;
|
||||
if ( bSelect )
|
||||
selNew = nPage;
|
||||
else if ( m_selection == wxNOT_FOUND )
|
||||
selNew = 0;
|
||||
|
||||
if ( selNew != wxNOT_FOUND )
|
||||
SetSelection(selNew);
|
||||
DoSetSelectionAfterInsertion(nPage, bSelect);
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
|
@ -648,19 +648,7 @@ bool wxNotebook::InsertPage ( size_t nPage,
|
||||
pPage->Show(false);
|
||||
}
|
||||
|
||||
//
|
||||
// Some page should be selected: either this one or the first one if there is
|
||||
// still no selection
|
||||
//
|
||||
int nSelNew = wxNOT_FOUND;
|
||||
|
||||
if (bSelect)
|
||||
nSelNew = nPage;
|
||||
else if ( m_selection == wxNOT_FOUND )
|
||||
nSelNew = 0;
|
||||
|
||||
if (nSelNew != wxNOT_FOUND)
|
||||
SetSelection(nSelNew);
|
||||
DoSetSelectionAfterInsertion(nPage, bSelect);
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
|
@ -240,16 +240,7 @@ bool wxNotebook::InsertPage(size_t nPage,
|
||||
m_peer->SetValue( m_selection + 1 ) ;
|
||||
}
|
||||
|
||||
// some page should be selected: either this one or the first one if there
|
||||
// is still no selection
|
||||
int selNew = wxNOT_FOUND;
|
||||
if ( bSelect )
|
||||
selNew = nPage;
|
||||
else if ( m_selection == wxNOT_FOUND )
|
||||
selNew = 0;
|
||||
|
||||
if ( selNew != wxNOT_FOUND )
|
||||
SetSelection( selNew );
|
||||
DoSetSelectionAfterInsertion(nPage, bSelect);
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user