Reconstructing a wxAuiNotebook layout

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.
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Reconstructing a wxAuiNotebook layout

Post by sparhawk »

My window layout looks like this:

Code: Select all

wxAuiMDIParentFrame -> wxAuiManager -> wxAuiNotebook -> Tab(wxPanel) : Tab(wxPanel) : Tab(wxPanel) : ...
I arranged the layout as I wanted it. When I close my app, I save all information about the states, but when I load it, the notebook layout has just the tab pages one after the other, and not the way I arranged it.

On the wxAuiManager exists a function Save-/LoadPerspective(), but the notebook doesn't have any functions as far as I can see. So how can I arrange the tab layout the same way via code as I can do with the mouse as a user?
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Reconstructing a wxAuiNotebook layout

Post by sparhawk »

After looking into this the last days, I'm still not further. Using the auidemo, it also doesn't restore the tab window to their correct position, The tabs are simply rearranged like a tab window with one tab next to the other.
Looking in the code, the wxAuiNotebook has it's own manager (which makes sense). So I tried now to manualy hardcode positions but none of the seem to work.

You can try to do this:
1. Run the auidemo
2. Move the tabs to some new positions (left, right, top, etc.)
3. Save the perspective
4. Move the tabs to new positions.
5. Restore the perspective.

You can see that the tabs are still in the same position without any change.

Since the notebook has it's own manager, I tried to use SavePerspective()/LoadPerspective() on the notebooks manager, assuming that it handles it's tabs internally, but that doesn't seem to have any effect.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Reconstructing a wxAuiNotebook layout

Post by doublemax »

Code: Select all

wxString wxAuiManager::SavePerspective()
{
    wxString result;
    result.Alloc(500);
    result = wxT("layout2|");

    int pane_i, pane_count = m_panes.GetCount();
    for (pane_i = 0; pane_i < pane_count; ++pane_i)
    {
        wxAuiPaneInfo& pane = m_panes.Item(pane_i);
        result += SavePaneInfo(pane)+wxT("|");
    }

    int dock_i, dock_count = m_docks.GetCount();
    for (dock_i = 0; dock_i < dock_count; ++dock_i)
    {
        wxAuiDockInfo& dock = m_docks.Item(dock_i);

        result += wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
                                   dock.dock_direction, dock.dock_layer,
                                   dock.dock_row, dock.size);
    }

    return result;
}
This is the complete code for SavePerspective. I don't think it does what you expect.
Use the source, Luke!
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Reconstructing a wxAuiNotebook layout

Post by sparhawk »

The problem is, when I do SavePerspective()/LoadPerspective() on the frame window manager, then it works as epxected. When I do the same on the wxAuiNotebook then it is ignored.
Since I can drag the tabs into position with the mouse, there should be a way to do this programmatically as well, but so far I haven't found a solution for this.
I mean, the fact that it works manually, means there is some code, which achieves this.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Reconstructing a wxAuiNotebook layout

Post by PB »

I am not familiar with wxAUI, but looking at the interface, I could hack moving pages programmatically. This code makes the current last page first after pressing the button:

Code: Select all

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

class MyFrame: public wxFrame
{
public:
    MyFrame() : wxFrame(nullptr, wxID_ANY, "Test")
    {
        wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);

        mainSizer->Add(new wxButton(this, wxID_ANY, "Move the last page to the front"),
            wxSizerFlags().Expand().Border());

        wxAuiNotebook* notebook = new wxAuiNotebook(this);
        for ( size_t i = 0; i < 5; ++i )
            notebook ->AddPage(new wxPanel(notebook), wxString::Format("Page %zu", i));
        mainSizer->Add(notebook, wxSizerFlags().Proportion(1).Expand().Border());

        SetSizer(mainSizer);

        Bind(wxEVT_BUTTON, [notebook](wxCommandEvent&)
            {
                const int lastPageIndex = notebook->GetPageCount() - 1;

                for ( int i = 0; i <= lastPageIndex ; ++i )
                {
                    wxWindow*     page = notebook->GetPage(i);
                    wxAuiTabCtrl* tabCtrl  = nullptr;
                    int           tabIndex = -1;

                    if ( notebook->FindTab(page, &tabCtrl, &tabIndex)
                            && tabIndex == lastPageIndex )
                    {
                        tabCtrl->MovePage(page, 0);
                        notebook->Refresh();
                        return;
                    }
                }
            });
    }
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        (new MyFrame())->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
I cannot really say it makes sense to me, in particular tabIndex vs pageIndex, but again, I am not familiar with wxAUI.
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Reconstructing a wxAuiNotebook layout

Post by sparhawk »

Thanks for the samplecode, but this doesn't do what I mean. It only moves that tabs within the tabcontrol itself. I know how this can be done. When you move some tab to a new docking position, then it doesn't do what I would expect.

If the layout is like this it works:
Tabbed.png
When I call AddPage() then it will add one tab after the other, like in the first example. But how can I move a tab to a docked position?
Docked.png
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Reconstructing a wxAuiNotebook layout

Post by PB »

I see. Sorry for having missed the actual issue.
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Reconstructing a wxAuiNotebook layout

Post by sparhawk »

PB wrote: Sat Mar 13, 2021 6:47 pm I see. Sorry for having missed the actual issue.
No need to be sorry, I didn't mean it like this! :oops: Actually I'm glad about any pointers that might help.
PB wrote: Sat Mar 13, 2021 3:48 pm I cannot really say it makes sense to me, in particular tabIndex vs pageIndex, but again, I am not familiar with wxAUI.
Actually your sample made me aware of this wxAuiTabCtrl class, and I took a look at the code what the purpose is.As far as I undestand it, the wxAuiNotebook can not manage a single window to support docked states. So if I am right, then this class is a helper which kind of mananges the different windows when it is in a docked state. The pageindex is a uniform index over all your pages currently held in the notebook. But when it is in a docked state, then you have multiple "notebooks" and the tabindex is the internal index of the a single docked window.
So for example, if you have 5 pages in your notebook, and two of them are docked above it, then you have pageindex 0..4 but one tabctrl with index 0..2 and another with index 0..1.
This gave me an idea how I can implement the missing functionality to restore the docked state as well. I have to try this today when I have more time.
If it work, as I expect it, to then I can contribute this to the wxWidget library, because IMO this should be actually part of the notebook class.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Reconstructing a wxAuiNotebook layout

Post by PB »

My apology was honest, not some passive-aggressive response. Sorry, if it came out otherwise.

Anyway, as I said I know very little about wxAUI. But I do know that while it is very powerful, some functionality which may seem basic can be missing. Additionally, its documentation may be lacking a bit so one has to look into its sources too and perhaps rely on "undocumented" API.

wxAuiNotebook also suffers from pretending it is a wxBookCtrl which leads to bugs like this
https://trac.wxwidgets.org/ticket/15932
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Reconstructing a wxAuiNotebook layout

Post by sparhawk »

PB wrote: Sun Mar 14, 2021 9:13 am wxAuiNotebook also suffers from pretending it is a wxBookCtrl which leads to bugs like this
https://trac.wxwidgets.org/ticket/15932
LOL! I'm not surprised. When I look at the wxAui code a lot looks like some prototype to me. It's not very reusable or modular, and I have the impression that the wxAuiManager (which should be responsible for the docking mechanism) is only an empty shell in the wxAuiNotebook. Also there are methods which are several hundred lines, which also is a bad sign IMO. It's very monolothic implemented.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Reconstructing a wxAuiNotebook layout

Post by ONEEYEMAN »

Hi,
wxAUI was developed as a side project by Kirix Software.
They were supporting Windows/Linux and no documentation was done.

After wxWidgets brought wxAUI in all further support and maintenance went to wxWidgets team. Absolutely no support exist from Kirix.
At one point of time Vadim expressed how sorry he is for including wxAUI in the wxWidgets mainline.

So while you can use it and in fact there are successful projects that using it - keep in mind that all issues with it (unless its a major one) may not be applied {right away}.

Thank you.
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Reconstructing a wxAuiNotebook layout

Post by sparhawk »

ONEEYEMAN wrote: Sun Mar 14, 2021 5:29 pm So while you can use it and in fact there are successful projects that using it - keep in mind that all issues with it (unless its a major one) may not be applied {right away}.
I hope this means that my chances are better, if I'm successfull with the restoration of a notebook, that it will be accepted when I contribute it. :)
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Reconstructing a wxAuiNotebook layout

Post by sparhawk »

ONEEYEMAN wrote: Sun Mar 14, 2021 5:29 pm After wxWidgets brought wxAUI in all further support and maintenance went to wxWidgets team. Absolutely no support exist from Kirix.
At one point of time Vadim expressed how sorry he is for including wxAUI in the wxWidgets mainline.
I was thinking a lot about the class design of the wxAUI stuff. Now I came to the realization, that wxWidgets already has most of the code in place to achieve what wxAUI does, but in a more uniform way.
When I think about the required functionality of a docking mechanism, then it is actually the same what already wxGridBagSizer offers. It can handle multiple panels in any kind of order and it supports a border, which makes room for the splitter handles.

So IMO extending the wxGridBagSizer would be my logical choice, of adding docking capabillity to wxWidgets. And if done right, you can also even move docked windows freely between any docking panel, which wxAUI currently can't.

I just don't know if the maintainers of wxWidget would accept such a big change. In the long run, I think this would be a benefit, because the gridbagsizer is already proven code, and fixes there, would automatically apply to the docking as well. If wxAUI is basically unmaintained, it's not of much help anyway, and the code is very hard to maintain anyway.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Reconstructing a wxAuiNotebook layout

Post by ONEEYEMAN »

Hi,
You should try asking on the wx-users mailing list, where you can catch core developers.
This a user forum and they don't come here.

Thank you.
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Reconstructing a wxAuiNotebook layout

Post by sparhawk »

ONEEYEMAN wrote: Mon Mar 15, 2021 12:27 pm You should try asking on the wx-users mailing list, where you can catch core developers.
This a user forum and they don't come here.
Thanks. I subscribed now to the dev list.
Post Reply