wxAuiNotebook::OnLeftUp not working Topic is solved

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.
wxwxwx
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Thu Dec 20, 2012 4:25 pm

Re: wxAuiNotebook::OnLeftUp not working

Post by wxwxwx »

I mean, i like to start just with one and only one page.
This page is intended a "add a page" page ("+" page).

I checked the changing event and it does not work, when you just have one page.
Most likely, because nothing can change.

Your code works, yes, i know. Once i have 2 or more pages, i get this event.
But not with just one page.

Do you know how i mean ?
Thank you
wxwxwx
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Thu Dec 20, 2012 4:25 pm

Re: wxAuiNotebook::OnLeftUp not working

Post by wxwxwx »

ONEEYEMAN wrote: Sun Apr 18, 2021 4:54 pm Hi,
Did you try it?
And we still wants to see your reproducer...

Thank you.
I checked out the

Code: Select all

wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
event.
It is not working, when you have just one page.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7456
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxAuiNotebook::OnLeftUp not working

Post by ONEEYEMAN »

Hi,
But did you actually run the code?

And as mentioned before - could you post your code from the minimal sample so we can see what is happenning?

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxAuiNotebook::OnLeftUp not working

Post by PB »

wxwxwx wrote: Sun Apr 18, 2021 5:59 pm I checked out the

Code: Select all

wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
event.
It is not working, when you have just one page.
This is not true, at least with wxWidgets 3.1.5 on MS Windows. When I comment out this line

Code: Select all

//m_notebook->AddPage(new wxPanel(m_notebook), "Page 1", true);
i.e., m_notebook has just one page (the "Add Page"), my code still works.
wxwxwx
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Thu Dec 20, 2012 4:25 pm

Re: wxAuiNotebook::OnLeftUp not working

Post by wxwxwx »

So far i did not run your code, because have a linker problem.
My vcpkg wx version is 3.14.

But i checked this in my implmentation and event

Code: Select all

wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
did not work with one page.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxAuiNotebook::OnLeftUp not working

Post by PB »

I just checked and it works with one page even with wxWidgets 3.0.5. The only change needed with this old version was to uninitialize wxAuiManager manually.

I do not understand how can you have issues with linking with my example code, as it cannot use anything else than your code does? Even if you are incapable of creating a test wxWidgets project, you should be able to just copy and paste those 30 lines of MyFrame code to your application and create an instance of MyFrame there.

If it does not work in your code, you must be doing something differently than in my code but I obviously cannot tell what it is.
wxwxwx
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Thu Dec 20, 2012 4:25 pm

Re: wxAuiNotebook::OnLeftUp not working

Post by wxwxwx »

ONEEYEMAN wrote: Sun Apr 18, 2021 6:08 pm Hi,
But did you actually run the code?

And as mentioned before - could you post your code from the minimal sample so we can see what is happenning?

Thank you.
Hm, could link now and run code with just one page and the

Code: Select all

wxEVT_AUINOTEBOOK_PAGE_CHANGING
works.

Ok, thank you. Need to figure out the differences.
AtesComp
In need of some credit
In need of some credit
Posts: 7
Joined: Thu Jan 11, 2024 1:21 am

Re: wxAuiNotebook::OnLeftUp not working

Post by AtesComp »

This is absolutely a problem.

If a wxAuiNotebook page already has focus, a left click on the tab produces NO wxEVT_AUINOTEBOOK_PAGE_CHANGING event...it's not changing. Furthermore, the only way to capture it is with a wxEVT_LEFT_* which does not help as it does not indicate the tab.

This seems to be a strange and incomplete oversight as the right and middle are well supported:
  • EVT_AUINOTEBOOK_TAB_MIDDLE_*
  • EVT_AUINOTEBOOK_TAB_RIGHT_*
User avatar
doublemax
Moderator
Moderator
Posts: 19111
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxAuiNotebook::OnLeftUp not working

Post by doublemax »

Why would you need to react to a click on a tab that's already active? Whatever you're doing will be bad UI design. No user will expect anything to happen there.
Furthermore, the only way to capture it is with a wxEVT_LEFT_* which does not help as it does not indicate the tab.
I'm almost certain you can determine the tab through wxAuiNotebook::GetActiveTabCtrl() and wxAuiTabContainer::TabHitTest(). (I haven't tried it though)
Use the source, Luke!
AtesComp
In need of some credit
In need of some credit
Posts: 7
Joined: Thu Jan 11, 2024 1:21 am

Re: wxAuiNotebook::OnLeftUp not working

Post by AtesComp »

No. It's just a use case you haven't thought of.

The problem is that the page content loses focus when the tab is selected. I need to return focus to the page window to grab keystrokes...particularly LEFT, UP, DOWN, and RIGHT. I can control keyboard tab selection within the page window easily enough.

I can certainly determine the tab through wxAuiNotebook::GetActiveTabCtrl(). It's just a ass to elbow solution. Regardless, which event notifies the tab was selected when its page is currently selected? NONE! It's a corner case that could easily be solved with a EVT_AUINOTEBOOK_TAB_LEFT_DOWN/UP!

I need to set a EVT_LEFT_UP bind on the wxAuiTabCtrl for each page. So, when the page becomes active, I need to set and track the binding:

Code: Select all

// Bind this active tab if not set...
if ( !this->m_CurrentPage->hasTabBind() ) {
    this->m_auiNotebook.GetActiveTabCtrl()->Bind( wxEVT_LEFT_UP, &MainFrame::OnMouseLeftUp, this );
    this->m_CurrentPage->setTabBind(true);
}
and unbind in a similar/opposite way when the page is closed.

Then,

Code: Select all

void MainFrame::OnMouseLeftUp(wxMouseEvent &eventMouse)
{
    // For wxAuiTabCtrl...
    // NOTE: Use mouse EVT_LEFT_UP since the focus occurs between EVT_LEFT_DOWN and EVT_LEFT_UP.
    //      If EVT_LEFT_DOWN were used, the event happens before the focus is set.

    wxWindow * pWin = wxWindow::FindFocus();
    if (pWin) {
        wxClassInfo * pInfo = pWin->GetClassInfo();
        const wxString strClassName = wxString( pInfo->GetClassName() );
        if (strClassName == L"wxAuiTabCtrl" ) {
            this->CallAfter(
                [this] {
                    if ( this->m_auiNotebook.GetSelection() != wxNOT_FOUND ) {
                        this->m_auiNotebook.GetCurrentPage()->SetFocus();
                        std::wcout << L"DEBUG: MainFrame::OnMouseLeftUp() : Lambda : SetFocus\n";
                    }
                }
            );
        }
    }
    else {
        std::wcout << L"DEBUG: MainFrame::OnMouseLeftUp() : Class: No CLass Found!\n";
    }
    eventMouse.Skip();
}
This would be way easier if a EVT_AUINOTEBOOK_TAB_LEFT_DOWN/UP were available!
User avatar
doublemax
Moderator
Moderator
Posts: 19111
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxAuiNotebook::OnLeftUp not working

Post by doublemax »

Any why can't you just focus the page after receiving the wxEVT_AUINOTEBOOK_PAGE_CHANGED event?
Use the source, Luke!
AtesComp
In need of some credit
In need of some credit
Posts: 7
Joined: Thu Jan 11, 2024 1:21 am

Re: wxAuiNotebook::OnLeftUp not working

Post by AtesComp »

As said before, the wxEVT_AUINOTEBOOK_PAGE_CHANGED event does NOT fire when the selected tab is ALREADY on the selected page. It's NOT changing pages. I've have code already in place looking for that event.

Code: Select all

this->Bind( wxEVT_AUINOTEBOOK_PAGE_CHANGED,  &MainFrame::OnChangedPage,  this );
No dice! Nada! Doesn't happen!
AtesComp
In need of some credit
In need of some credit
Posts: 7
Joined: Thu Jan 11, 2024 1:21 am

Re: wxAuiNotebook::OnLeftUp not working

Post by AtesComp »

Now to add insult to injury, the MainFrame::OnMouseLeftUp method is called for the count of tabs in the notebook. BUT not on each tab--on the selected tab.

I optimized the code a bit to check it...

Code: Select all

void MainFrame::OnMouseLeftUp(wxMouseEvent &eventMouse)
{
    // For wxAuiTabCtrl...
    // NOTE: Use mouse EVT_LEFT_UP since the focus occurs between EVT_LEFT_DOWN and EVT_LEFT_UP.
    //      If EVT_LEFT_DOWN were used, the event happens before the focus is set.

    wxWindow * pWin = wxWindow::FindFocus();
    if (pWin) {
        wxClassInfo * pInfo = pWin->GetClassInfo();
        if ( pInfo->IsKindOf( CLASSINFO(wxAuiTabCtrl) ) ) {
            wxAuiTabCtrl * pTab = (wxAuiTabCtrl *)pWin;
            if ( this->m_auiNotebook.GetActiveTabCtrl() == pTab ) {
                this->CallAfter(
                    [this] {
                        if ( this->m_auiNotebook.GetSelection() != wxNOT_FOUND ) {
                            this->m_auiNotebook.GetCurrentPage()->SetFocus();
                            std::wcout << L"DEBUG: MainFrame::OnMouseLeftUp() : Lambda : SetFocus\n";
                        }
                    }
                );
            }
        }
    }
    else {
        std::wcout << L"DEBUG: MainFrame::OnMouseLeftUp() : Class: No Class Found!\n";
    }
    eventMouse.Skip();
}
With 3 pages open, I select the page area of the current page to make sure its ALREADY focused, then I select that page's tab title and get:

Code: Select all

DEBUG: MainFrame::OnMouseLeftUp() : Lambda : SetFocus
DEBUG: MainFrame::OnMouseLeftUp() : Lambda : SetFocus
DEBUG: MainFrame::OnMouseLeftUp() : Lambda : SetFocus
Note that no messages occur from these bound methods:

Code: Select all

        this->Bind( wxEVT_AUINOTEBOOK_PAGE_CHANGING, &MainFrame::OnChangingPage, this );
        this->Bind( wxEVT_AUINOTEBOOK_PAGE_CHANGED,  &MainFrame::OnChangedPage,  this );
UPDATE: Apparently, the wxAuiTabCtrl is a single control for the entire wxAuiNotebook and has no public methods to access the individual tabs. So, I wasted my time on creating multiple binds when creating each page as well as checking the wxAuiTabCtrl. One would suffice. That is why I got multiple EVT_LEFT_UP. i've changed the code to Bind once and I don't need to track anymore.
AtesComp
In need of some credit
In need of some credit
Posts: 7
Joined: Thu Jan 11, 2024 1:21 am

Re: wxAuiNotebook::OnLeftUp not working

Post by AtesComp »

I'm documenting in full the "more" simplified solution...

1. After the wxAuiNotebook is added via the wxAuiManager, Bind the notebook's wxAuiTabCtrl:

Code: Select all

this->m_auiNotebook.GetActiveTabCtrl()->Bind( wxEVT_LEFT_UP, &MainFrame::OnTabLeftUp, this );
2. Do similar to Unbind on clean up:

Code: Select all

this->m_auiNotebook.GetActiveTabCtrl()->Unbind( wxEVT_LEFT_UP, &MainFrame::OnTabLeftUp, this );
3. Code the OnTabLeftUp method to handle the tab selection:

Code: Select all

void MainFrame::OnTabLeftUp(wxMouseEvent &eventMouse)
{
    // For wxAuiTabCtrl...
    // NOTE: Use mouse EVT_LEFT_UP since the focus occurs between EVT_LEFT_DOWN and EVT_LEFT_UP.
    //      If EVT_LEFT_DOWN were used, the event happens before the focus is set.

    wxWindow * pWin = wxWindow::FindFocus();
    if (pWin) {
        wxClassInfo * pInfo = pWin->GetClassInfo();
        if ( pInfo->IsKindOf( CLASSINFO(wxAuiTabCtrl) ) ) {
            this->CallAfter(
                [this] {
                    if ( this->m_auiNotebook.GetSelection() != wxNOT_FOUND ) {
                        this->m_auiNotebook.GetCurrentPage()->SetFocus();
                        std::wcout << L"DEBUG: MainFrame::OnTabLeftUp() : Lambda : SetFocus\n";
                    }
                }
            );
        }
    }
    else {
        std::wcout << L"DEBUG: MainFrame::OnTabLeftUp() : Class: No Class Found!\n";
    }
    eventMouse.Skip();
}
This could be condensed a bit, but it provides the control for selecting the tab on the current page.

For selecting the other non-current tabs, the wxEVT_AUINOTEBOOK_PAGE_CHANGING and wxEVT_AUINOTEBOOK_PAGE_CHANGED event Binds provide the complete solution.
Post Reply