Rewrite event generation and propagation in wxAuiNotebook

Do not use events to call wxAuiNotebook functions from wxAuiTabCtrl, as
this interfered with handling the events in the application code in
highly non-obvious ways. Just call wxAuiNotebook functions directly from
wxAuiTabCtrl code and stop handling wxEVT_AUI_XXX in wxAuiNotebook
itself.

Add wxAuiTabEventSource to avoid making wxAuiTabCtrl itself friend of
wxAuiNotebook: this allows to define the subset of private functions of
the latter that the former can call.

Also fix a couple of places where wrong indices, corresponding to the
position of the tabs in their tab control, were used instead of the
correct logical page indices.

Closes #25544.
This commit is contained in:
Vadim Zeitlin
2025-07-12 20:09:33 +02:00
parent ce1c4abc0a
commit 48bf1ac4e9
2 changed files with 174 additions and 185 deletions
+26 -12
View File
@@ -372,6 +372,9 @@ public:
// tab control in screen coordinates.
wxRect GetHintScreenRect() const;
// Get parent notebook (always valid).
wxAuiNotebook* GetBook() const;
protected:
// choose the default border for this window
virtual wxBorder GetDefaultBorder() const override { return wxBORDER_NONE; }
@@ -387,7 +390,6 @@ protected:
void OnRightUp(wxMouseEvent& evt);
void OnMotion(wxMouseEvent& evt);
void OnLeaveWindow(wxMouseEvent& evt);
void OnButton(wxAuiNotebookEvent& evt);
void OnSetFocus(wxFocusEvent& event);
void OnKillFocus(wxFocusEvent& event);
void OnChar(wxKeyEvent& event);
@@ -410,6 +412,8 @@ private:
// Reset dragging-related fields above to their initial values.
void DoEndDragging();
void OnButton(int tabIdx, int button);
#ifndef SWIG
wxDECLARE_CLASS(wxAuiTabCtrl);
wxDECLARE_EVENT_TABLE();
@@ -619,21 +623,31 @@ protected:
void OnChildFocusNotebook(wxChildFocusEvent& evt);
void OnRender(wxAuiManagerEvent& evt);
void OnSize(wxSizeEvent& evt);
void OnTabClicked(wxAuiNotebookEvent& evt);
void OnTabBeginDrag(wxAuiNotebookEvent& evt);
void OnTabDragMotion(wxAuiNotebookEvent& evt);
void OnTabEndDrag(wxAuiNotebookEvent& evt);
void OnTabCancelDrag(wxAuiNotebookEvent& evt);
void OnTabButton(wxAuiNotebookEvent& evt);
void OnTabMiddleDown(wxAuiNotebookEvent& evt);
void OnTabMiddleUp(wxAuiNotebookEvent& evt);
void OnTabRightDown(wxAuiNotebookEvent& evt);
void OnTabRightUp(wxAuiNotebookEvent& evt);
void OnTabBgDClick(wxAuiNotebookEvent& evt);
void OnNavigationKeyNotebook(wxNavigationKeyEvent& event);
void OnSysColourChanged(wxSysColourChangedEvent& event);
void OnDpiChanged(wxDPIChangedEvent& event);
// The functions below are called by wxAuiTabCtrl via wxAuiTabEventSource.
//
// They all take the control which generated the event (never null) and all
// but one take the position of the tab associated with the event in this
// control: notice that this is _not_ the same as the index of the page, in
// general, m_tabs.GetIdxFromWindow(wxAuiTabCtrl::GetWindowFromIdx()) must
// be used to get it.
friend class wxAuiTabEventSource;
void OnTabClicked(wxAuiTabCtrl* ctrl, int tabIdx);
void OnTabBeginDrag(wxAuiTabCtrl* ctrl, int tabIdx);
void OnTabDragMotion(wxAuiTabCtrl* ctrl, int tabIdx);
void OnTabEndDrag(wxAuiTabCtrl* ctrl, int tabIdx);
void OnTabCancelDrag(wxAuiTabCtrl* ctrl, int tabIdx);
void OnTabButton(wxAuiTabCtrl* ctrl, int tabIdx, int button_id);
void OnTabMiddleDown(wxAuiTabCtrl* ctrl, int tabIdx);
void OnTabMiddleUp(wxAuiTabCtrl* ctrl, int tabIdx);
void OnTabRightDown(wxAuiTabCtrl* ctrl, int tabIdx);
void OnTabRightUp(wxAuiTabCtrl* ctrl, int tabIdx);
void OnTabBgDClick(wxAuiTabCtrl* ctrl);
// set selection to the given window (which must be non-null and be one of
// our pages, otherwise an assert is raised)
void SetSelectionToWindow(wxWindow *win);
+148 -173
View File
File diff suppressed because it is too large Load Diff