NotebookCtrl (or general?) event handling problem

Hi,

I've attached a simplified example of some nesting I'm doing with notebooks.

I made a class called NestedNB derived from NotebookCtrl. This constructs a 2-page notebook with the pages labelled T1 and T2.

Then within the NestedNB class I created a second 2-page NotebookCtrl, and made page T1 its parent. Its pages are labelled P1 and P2.

Still in the NestedNB constructor, I bound the event NC.EVT_NOTEBOOKCTRL_PAGE_CHANGING for *both* notebooks to event handler NestedNB.OnPageChanging. This method gets the object that generated the event and prints "OnPageChanging: from x to y", where x and y are the labels of the source object's old and new pages.

When I alternately select T1 and T2 I get:
   OnPageChanging: from T1 to T2
   OnPageChanging: from T2 to T1
   etc.

However, when I alternately select P1 and P2 I get:
   OnPageChanging: from P1 to P2
   OnPageChanging: from P2 to P1
    etc.

The event handler is getting called correctly for T1 and T2. But it is getting called *twice* for each selection of P1 and P2.

Can anyone tell me why this is happening?

Chris Botos

NestedNB.zip (32.8 KB)

Chris Botos wrote:

Hi,

I've attached a simplified example of some nesting I'm doing with notebooks.

I made a class called NestedNB derived from NotebookCtrl. This constructs a 2-page notebook with the pages labelled T1 and T2.

Then within the NestedNB class I created a second 2-page NotebookCtrl, and made page T1 its parent. Its pages are labelled P1 and P2.

Still in the NestedNB constructor, I bound the event NC.EVT_NOTEBOOKCTRL_PAGE_CHANGING for *both* notebooks to event handler NestedNB.OnPageChanging. This method gets the object that generated the event and prints "OnPageChanging: from x to y", where x and y are the labels of the source object's old and new pages.

When I alternately select T1 and T2 I get:
  OnPageChanging: from T1 to T2
  OnPageChanging: from T2 to T1
  etc.

However, when I alternately select P1 and P2 I get:
  OnPageChanging: from P1 to P2
  OnPageChanging: from P2 to P1
   etc.

The event handler is getting called correctly for T1 and T2. But it is getting called *twice* for each selection of P1 and P2.

Can anyone tell me why this is happening?

You have an event.Skip() at the end of NestedNB.OnPageChanging. Don't call event.Skip() here otherwise the P1/P2 event will propagate into the parent NestedNB and trigger OnPageChanging again.

Regards,
David Hughes