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

wxAuiNotebook::OnLeftUp not working

Post by wxwxwx »

Hello,
i am using wxWidgets on Windows 10 and

Code: Select all

wxAuiNotebook::OnLeftUp
and some other events like

Code: Select all

wxAuiNotebook::OnAux1Up
are not working in my simple aui notebook implementation.
What works is event:

Code: Select all

wxEVT_COMMAND_AUINOTEBOOK_TAB_RIGHT_UP
I use wxWidgets linked to libs provided by vcpkg.

How to get this event to work ? Just want to know, when the mouse left clicks on the tab page.
I have just 1 page. So changed and changing event not working.
I want to add a page when the first page is clicked. First page lable is a '+'. So that's the background.

Code: Select all

panel_nb_periods::panel_nb_periods( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name )
{
	m_mgr.SetManagedWindow(this);
	m_mgr.SetFlags(wxAUI_MGR_DEFAULT);

	_nb_periods = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP );
	m_mgr.AddPane( _nb_periods, wxAuiPaneInfo() .Center() .PinButton( true ).Dock().Resizable().FloatingSize( wxDefaultSize ).BottomDockable( false ).TopDockable( false ).LeftDockable( false ).RightDockable( false ).Floatable( false ) );



	m_mgr.Update();

	// Connect Events
	_nb_periods->Connect( wxEVT_AUX1_UP, wxMouseEventHandler( panel_nb_periods::on_mouse_nb_up ), NULL, this );
	_nb_periods->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( panel_nb_periods::on_left_up ), NULL, this );
	_nb_periods->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxNotebookEventHandler( panel_nb_periods::on_page_change ), NULL, this );
}

panel_nb_periods::~panel_nb_periods()
{
	// Disconnect Events
	_nb_periods->Disconnect( wxEVT_AUX1_UP, wxMouseEventHandler( panel_nb_periods::on_mouse_nb_up ), NULL, this );
	_nb_periods->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( panel_nb_periods::on_left_up ), NULL, this );
	_nb_periods->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, wxNotebookEventHandler( panel_nb_periods::on_page_change ), NULL, this );

	m_mgr.UnInit();

}
Thank you for any help
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxAuiNotebook::OnLeftUp not working

Post by ONEEYEMAN »

Hi,
Is auidemo sample works for you?

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 »

I cannot reproduce the issue (wxWidgets 3.1.5, Windows 10) with this SSCCE, which should pretty much mimic your code:

Code: Select all

#include <wx/wx.h>
#include <wx/aui/aui.h>
#include <wx/notebook.h>

class MyFrame: public wxFrame
{
public:
    MyFrame() : wxFrame (nullptr, wxID_ANY, "Test")
    {
        wxPanel*    panel = new wxPanel(this);
        wxNotebook* notebook = new wxNotebook(panel, wxID_ANY);

        for ( size_t i = 0; i < 3; ++i )
            notebook ->AddPage(new wxPanel(notebook), wxString::Format("Page %zu", i));

        notebook->Bind(wxEVT_LEFT_UP, [this](wxMouseEvent& e)
            {
                wxLogMessage("wxEVT_LEFT_UP on notebook");
                e.Skip();
            } );

        m_mgr.SetManagedWindow(panel);
        m_mgr.AddPane(notebook, wxAuiPaneInfo().Center().PinButton(true).Dock().Resizable().FloatingSize(wxDefaultSize).BottomDockable(false).TopDockable(false).LeftDockable(false).RightDockable(false).Floatable(false) );
        m_mgr.Update();
    }
private:
    wxAuiManager   m_mgr;
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        (new MyFrame())->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
Clicking on the notebook tab leads to a message displayed. If you really want to get a click for the tab page (but the code you shown does not add any?), you need to bind the mouse event of this page, mouse events do not propagate.

I would start with replacing those horrible Connect()s with Bind(). I am not saying they must be the issue but Connect() is notoriously error-prone.

BTW, the thread title and part of your post refer to wxAuiNotebook; however, the largest code fragment uses wxNotebook. wxAuiNotebook and wxNotebook are two distinct classes, the latter is at least on MS Windows a native control, while the former is a custom implementation so I would not be much surprised if they behaved differently.
Last edited by PB on Sun Apr 18, 2021 2:17 pm, edited 1 time in total.
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 »

Hello,
thank you for answers. The bind also is not working.

The notebook belongs to a panel wich is page in a notbeeok in a panel.
All panels are AUI managed.

Please mind:
The right up event works.
THank you for ideas.
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 have just tried replacing wxNotebook with wxAuiNotebook and then I do not get the mouse events.

With wxAuiNotebook one has to bind EVT_AUINOTEBOOK_TAB_* events. However, there is no events for the left mouse button, only for the middle and right one. I guess the left mouse click on the tab is transformed to the appropriate EVT_AUINOTEBOOK_PAGE_* event.
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 »

...
BTW, the thread title and part of your post refer to wxAuiNotebook; however, the largest code fragment uses wxNotebook. wxAuiNotebook and wxNotebook are two distinct classes, the latter is at least on MS Windows a native control, while the former is a custom implementation so I would not be much surprised if they behaved differently.
Yes, that's correct. But in my original code, i use a wxAuiNotebook. Same problem.
I just created code using wxFormBuilder to provide a sample. Can write the same with wxAuiNotebook. It wont remove the problem.



I use wxWidgets from vcpkg. static link. The version is 3.1.4#3. There are no samples installed along with, i could check.
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 »

As I always, I would start with reducing the code to make sure the window hierarchy actually has any effect on the issue.

Often, one figures out what is wrong by themselves when doing so.
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 »

PB wrote: Sun Apr 18, 2021 2:23 pm I have just tried replacing wxNotebook with wxAuiNotebook and then I do not get the mouse events.

With wxAuiNotebook one has to bind EVT_AUINOTEBOOK_TAB_* events. However, there is no events for the left mouse button, only for the middle and right one. I guess the left mouse click on the tab is transformed to the appropriate EVT_AUINOTEBOOK_PAGE_* event.
Using wxNootebook gives me mouse left button up event. But this is not, what i want. Want to have a wxAuiNotebook.
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 2:37 pm
PB wrote: Sun Apr 18, 2021 2:23 pm With wxAuiNotebook one has to bind EVT_AUINOTEBOOK_TAB_* events. However, there is no events for the left mouse button, only for the middle and right one. I guess the left mouse click on the tab is transformed to the appropriate EVT_AUINOTEBOOK_PAGE_* event.
Using wxNootebook gives me mouse left button up event. But this is not, what i want. Want to have a wxAuiNotebook.
wxwxwx wrote: Sun Apr 18, 2021 2:37 pm Using wxNootebook gives me mouse left button up event. But this is not, what i want. Want to have a wxAuiNotebook.
I do not understand, first you said you do not get the event with wxNotebook but now you do?

Anyway, If you read what I wrote then it would seem that with wxAuiNotebook you need to handle wxEVT_AUINOTEBOOK_PAGE_CHANGING for that first page instead. As I wrote, there is no left mouse up event for wxAuiNotebook, as the left mouse click on the tab gets translated to other wxEVT_AUINOTEBOOK* events. If you want this to happen when the page itself is clicked, you need to bind the mouse even from that page...

So what exactly is the issue now?
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 »

PB wrote: Sun Apr 18, 2021 2:43 pm I do not understand, first you said you do not get the event with wxNotebook but now you do?
PB wrote: Sun Apr 18, 2021 2:33 pm As I always, I would start with reducing the code to make sure the window hierarchy actually has any effect on the issue.

Often, one figures out what is wrong by themselves when doing so.
Sorry, sorry. Yes i told this. But in fact i use wxAuiNotebook. To post this, i generated code using wxFormBuilder
and used accidently wxNotebook.

Short: wxNotebook works, wxAuiNotebook not.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxAuiNotebook::OnLeftUp not working

Post by ONEEYEMAN »

Hi,
So can we get the "minimal sample reproducing the problem"

It should be as minimal as possible and can be easily run after compiling.

Just post the sources here. Don't attach the archive.

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 »

I think the SSCCE below does what you asked, i.e., adding a page after clicking the tab of the first wxAuiNotebook page.

The code expects there is at least one more page after the "Add Page"; however, that would be easy to change (i.e., bind the mouse up from the page itself, e.g., a wxPanel), so I did not do it, to keep the code short.

Code: Select all

#include <wx/wx.h>
#include <wx/aui/aui.h>

class MyFrame: public wxFrame
{
public:
    MyFrame() : wxFrame(nullptr, wxID_ANY, "Test")
    {
        static const wxString addPageTitle = "Add Page";

        wxPanel* panel = new wxPanel(this);

        m_notebook = new wxAuiNotebook(panel, wxID_ANY);

        m_notebook->AddPage(new wxPanel(m_notebook), addPageTitle);
        m_notebook->AddPage(new wxPanel(m_notebook), "Page 1", true);
        m_notebook->Bind(wxEVT_AUINOTEBOOK_PAGE_CHANGING, [this](wxAuiNotebookEvent& e)
        {
            if ( m_notebook->GetPageText(e.GetSelection()) == addPageTitle )
            {
                m_notebook->AddPage(new wxPanel(m_notebook), wxString::Format("Page %zu", m_notebook->GetPageCount()), true);
                e.Veto();
            }
            else
                e.Skip();
        });

        m_mgr.SetManagedWindow(panel);
        m_mgr.AddPane(m_notebook, wxAuiPaneInfo().Center());
        m_mgr.Update();
    }
private:
    wxAuiManager   m_mgr;
    wxAuiNotebook* m_notebook;
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        (new MyFrame())->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
Obviously, in a real application, the code needs to do more, at least ensuring the "Add Page" is always the first page, dealing with split notebooks etc.. But those are not the topic of this thread.
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 »

Thank you for code.
I dont think this works because the page changing is not working, since you just have one page, the "+" page.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxAuiNotebook::OnLeftUp not working

Post by ONEEYEMAN »

Hi,
Did you try it?
And we still wants to see your reproducer...

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 4:49 pm I dont think this works because the page changing is not working, since you just have one page, the "+" page.
I do not understand, in my code there are always at least two pages. It also does work if there is just the "Add Page" alone. As ONEEYEMAN already wrote, did you even try running the code?

Sorry to be honest, but your answer are rather cryptic and not that helpful.
Post Reply