EVT_NOTEBOOK_PAGE_CHANGING: can i change the new page?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

EVT_NOTEBOOK_PAGE_CHANGING: can i change the new page?

Post by Parduz »

I need to "intercept" a page change and "redirect" it to another page (as example, it is changing to page 1 and i want it to land on page 9).

The Page Changing event seemed the right place to do it by using the event->SetSelection, but the wxBookCtrlBase::DoSetSelection ignores the values of the event other than "allowed", so i can't follow that route.

What should be the best way to do this?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: EVT_NOTEBOOK_PAGE_CHANGING: can i change the new page?

Post by PB »

Mhm, this looks quite odd to me from the user view point.

Anyway, did you try in the page changing event handler just vetoing the change and then calling wxNotebook::ChangeSelection() with CallAfter()?
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: EVT_NOTEBOOK_PAGE_CHANGING: can i change the new page?

Post by Parduz »

PB wrote: Fri Feb 21, 2020 4:21 pm Mhm, this looks quite odd to me from the user view point.

Anyway, did you try in the page changing event handler just vetoing the change and then calling wxNotebook::ChangeSelection() with CallAfter()?
I'm a bit lost, as it seems i'm not able to write a CallAfter() call which compiles.

Code: Select all

CallAfter( [m_MainPages] { m_MainPages->SetSelection(9); } );
gives invalid use of non-static data member (i have a similar call in my code which is working).

Code: Select all

CallAfter( m_MainPages->SetSelection(9) );
gives wxWidgets-3.0.4\include\wx\event.h|1498|error: expression cannot be used as a function|.
How should i write that call?
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: EVT_NOTEBOOK_PAGE_CHANGING: can i change the new page?

Post by Kvaz1r »

It seems that m_MainPages is a member so capture this instead:

Code: Select all

CallAfter( [this] { m_MainPages->SetSelection(9); } );
Post Reply