-2

Have a nice day! I am trying to customize the appearance of my Aui Notebook. To be specific, I want to locate my tab control to the left hand side of the window instead of the default top position. I also want to color each tab. I took these codes from the sample and I have been learning more about it so I am a little bit confused about where to change and what to change.

Below are some code snippets I think related to the appearance of the tab control. Please leave me a comment if you have any suggestions or questions about my code. Thank you so much for helping me out.

void CreateInitialPages(wxBookCtrlBase *parent)
{
    // Create and add some panels to the notebook
    
    parent->SetSize(wxSize(100,400));
    
    wxWindow *page = DictionaryPage(parent);
    parent->InsertPage( 0, page, DICTIONARY, false, GetIconIndex(parent) );
    
    page = CreateAddPage(parent);
    parent->AddPage( page, ADD_NEW_WORD, false, GetIconIndex(parent) );
    
    page = FavoriteList(parent);
    parent->AddPage( page, FAVOURITE_LIST, false, GetIconIndex(parent) );
    
    page = CreateGamePage(parent);
    parent->AddPage( page, GAME, false, GetIconIndex(parent) );
    
    parent->SetSelection(0);
}

wxWindow *CreatePage(wxBookCtrlBase *parent, const wxString&pageName)
{
    if ( pageName == DICTIONARY )
        return DictionaryPage(parent);
    
    if ( pageName == FAVOURITE_LIST )
        return FavoriteList(parent);
    
    if ( pageName == ADD_NEW_WORD )
        return CreateAddPage(parent);
    
    if ( pageName == GAME )
        return CreateGamePage(parent);
    
    wxFAIL_MSG( "unknown page name" );
    
    return NULL;
}
 

    void MyFrame::RecreateBook()
{
    m_bookCtrl = NULL;
    
    DISPATCH_ON_TYPE(m_bookCtrl = new, wxAuiNotebook,
                     (m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_LEFT));
    
    if ( !m_bookCtrl )
        return;
    
    m_bookCtrl->Hide();
    
    if ( m_chkShowImages )
    {
        m_bookCtrl->SetImages(m_images);
    }
    
    CreateInitialPages(m_bookCtrl);
    
    m_sizerFrame->Insert(0, m_bookCtrl, wxSizerFlags(0).Border(wxALL,5));
    
    m_sizerFrame->Show(m_bookCtrl);
    m_sizerFrame->Layout();
}

This is the constructor for the book:

MyFrame::MyFrame()
: wxFrame(NULL, wxID_ANY, wxString("wxWidgets book controls sample"),wxPoint(wxID_ANY, wxID_ANY), wxSize(1200, 680),
          wxSYSTEM_MENU | wxMINIMIZE_BOX | wxCLOSE_BOX | wxCAPTION | wxCLIP_CHILDREN)
{
    
    m_type = Type_AuiNotebook;
    this->SetBackgroundColour(wxColour(73,86,111));
    m_panel    = NULL;
    m_bookCtrl = NULL;
    m_chkShowImages = true;
    
    ::wxInitAllImageHandlers();
    wxBitmap dict("dict_unclicked.png", wxBITMAP_TYPE_ANY);
    wxBitmap add("add_unclicked.png", wxBITMAP_TYPE_ANY);
    wxBitmap fav("favorite_unclicked.png", wxBITMAP_TYPE_ANY);
    wxBitmap game("game_unclicked.png", wxBITMAP_TYPE_ANY);
    
    m_images.push_back(dict);
    m_images.push_back(add);
    m_images.push_back(fav);
    m_images.push_back(game);
    
    m_panel = new wxPanel(this);
    
    m_text = new wxStaticText(m_panel, wxID_ANY, "Username");
    m_text->SetForegroundColour(*wxGREEN);
    
    
    m_reset = new wxBitmapButton(m_panel, wxID_ANY, wxArtProvider::GetBitmap(wxART_UNDO), wxDefaultPosition, wxSize(25,25));
    m_reset->Bind(wxEVT_BUTTON, [=](wxCommandEvent& event)
                  {
        //reset function of Cuong
        
        wxLogMessage("Your data has been reset");
    });
    
    m_logout = new wxBitmapButton(m_panel, wxID_ANY, wxArtProvider::GetBitmap(wxART_QUIT), wxDefaultPosition, wxSize(25,25));
    m_logout->Bind(wxEVT_BUTTON, [=](wxCommandEvent& event)
                   {
        //reset function of Cuong
        
        this->Close();
        
        FormLogin* login = new FormLogin("Login");
        login->Show(true);
    });
    
    m_sizerFrame = new wxBoxSizer(wxVERTICAL);
    m_sizerFrame->Add(m_text, 1, wxEXPAND);
    m_sizerFrame->Add(m_reset,0);
    m_sizerFrame->Add(m_logout,0);
    
    RecreateBook();
    
    m_panel->SetSizer(m_sizerFrame);
    m_panel->Layout();
    
    wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
    sizer->Add(m_panel, wxSizerFlags(1).Expand());
    this->SetSizer(sizer);
}

I tried to add wxAUI_NB_LEFT in this line to have a left-hand tab control but it did not work.

DISPATCH_ON_TYPE(m_bookCtrl = new, wxAuiNotebook,
                 (m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_LEFT));
273K
  • 29,503
  • 10
  • 41
  • 64
  • Please read this https://stackoverflow.com/questions/20509734/null-vs-nullptr-why-was-it-replaced – 273K Aug 21 '23 at 16:27
  • @273K Hi, thank you for your comment. However, I suspect that you pasted the wrong link. I see things about nullptr in the link and not really related to my topic. Can you please resend the link? Thank you so much. – G Nguyễn Aug 22 '23 at 10:06

0 Answers0