Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / wxNotebook with various classes

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. wxNotebook with various classes
#4733
Posted by: 2004-07-07 04:03:14
Hi,

I am trying to construct a Notebook which will have 3 pages and I'm creating each page separately in 3 different classes and want to add them as pages in the notebook in the frame.

-----------------------------------
Classes:
Page1
Page2
Page3
Notebook
Frame
Appl

----------------------------------
All the Page# are similar classes with the following structure:
Page#::Page#(const wxString& title, const wxPoint& pos,  const wxSize& size )
   : wxPanel((wxPanel *) NULL, -1, pos, size, wxTAB_TRAVERSAL, title ){

wxPanel *panel = new wxPanel(m_notebook, -1, pos, size, wxTAB_TRAVERSAL, title );
(uses boxsizer)...
----------------------------------
The notebook class:

void Notebook::CreateInitialPages()
{
    wxPanel *m_panel = (wxPanel *) NULL;

    // Create and add some panels to the notebook

    m_panel = CreateMainPage();
    AddPage( m_panel, NAME, FALSE );
}

wxPanel *Notebook::CreateMainPage()
{
MainPage *m_panel = new MainPage(MAINPAGE_NAME, wxPoint(50, 50), wxSize(400, 300));

return m_panel;
}

----------------------------------
The Frame class is as follows:

// frame constructor
Frame::Frame(const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(this, -1, title, pos, size, style) {

m_panel = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize,
        wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER);

m_notebook = new Notebook(m_panel, ID_NOTEBOOK);

// Create the notebook's panels
m_notebook->CreateInitialPages();

-------------------
The Appl:

bool Appl::OnInit()
// create the main application window
wxPagesFrame *pFrame = new Frame(wxT("wxPages"), wxPoint(50, 50), wxSize(400, 300));

------------------


There must be a problem in the logic, and don't know if I'm right:
I'm creating the frame in the OnIni()
I'm creating the notebook in the Frame() which uses the m_panel as the parent and which calls a function in Notebook.h like this
m_notebook->CreateInitialPages();
In this last function I call 3 functions to create the 3 pages:
Page1 *m_panel = new Page1(PAGE_NAME, wxPoint(50, 50), wxSize(400, 300));

Anyways, first I'm having 2 link errors:
wxPagesFrm.obj : error LNK2001: unresolved external symbol "public: void __thiscall Notebook::CreateInitialPages(void)" (?CreateInitialPages@Notebook@@QAEXXZ)
wxPagesFrm.obj : error LNK2001: unresolved external symbol "public: __thiscall Notebook::Notebook(class wxWindow *,int,class wxPoint const &,class wxSize const &,long)" (??0Notebook@@QAE@PAVwxWindow@@HABVwxPoint@@ABVwxSize@@J@Z)

So it doesn't want to create the notebook and second I know that when it worked the frame came out fine but there was nothing in it and it said that it could not put windows on top child (or something similar). I've been trying to play with this for a few days and I'm going crazy!!
Thanks,

Mona
Message2. Re: wxNotebook with various classes
#4734
Posted by: 2004-07-07 04:12:53
Hi again,

I solved the link errors, now this is what I get:

==>assert "wxAssertFailure" failed: can't create wxWindow without parent

when I press Cancel it continues and opens the Frame with nothing in it and get:

==>can't create window of class wxWindowClass (error 1406: cannot create a top-level child window.)

Thanks,

Mona
Message3. Re: wxNotebook with various classes
#4738
Posted by: upCASE 2004-07-07 14:59:02
Hi!
Your problem can be easily solved by reading the asserts it gave :)

Have a look at the constructors for the pages and the frame:

Frame::Frame(const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(this, -1, title, pos, size, style)

First BIG problem -> wxFrame(this... You pass a pointer to an object as a parent window while the actual object isn't created yet. For a Frame pass NULL if it is a toplevel window.
Frame::Frame(const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(NULL, -1, title, pos, size, style)

The assert messages come from the fact that you "create wxWindows without parents", in your case wxPanels. You shoud be able to create the panels with NULL as their parent window, but it's not a good idea. Better pass them a pointer to the parent window to ensure correct window deletion.
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message4. Re: wxNotebook with various classes
#4756
Posted by: 2004-07-08 06:39:34
I don't get it!! I did a simple Frame-Notebook-panel program and it works...I get the 3 panels I need with the buttons and every thing. I created the notebook and the panels in the frame constructor and it works. Now, I want to have the definition of the panels (GUI and all) in a separate class and use it to create the pages.

This is the code that works:

wxPanel *panel1 = new wxPanel(this, -1, pos, size, wxTAB_TRAVERSAL, title);
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
m_hsizer = new wxBoxSizer( wxHORIZONTAL );
m_buttonSizer = new wxBoxSizer (wxVERTICAL);
   
m_sizerBtn1 = new wxButton(panel1, -1, _T("Test Button &1") );
m_buttonSizer->Add( m_sizerBtn1, 0, wxALL, 10 );
...

notebook_1->AddPage( panel1, "page 1", FALSE );

notebook_1->AddPage( panel2, "page2", FALSE );

notebook_1->AddPage( panel3, "page3", FALSE );

And what I would want to do is to have a class Page which will create the panel which I will use to add to my notebook. Something like that:

wxPanel *panel = new wxPage(pos, size, title, notebook_1);
panel->CreatePage(notebook_1);      //is wxPanel* CreatePage()
notebook_1->AddPage( panel, "page1", FALSE ); //needs type wxPanel

I'm trying 1000 things but it does not want to work!!

PS: I don't get the parents/child error anymore ;) ;)

Thanks,

Mona
Message5. Re: wxNotebook with various classes
#4762
Posted by: upCASE 2004-07-08 15:04:41
Hi!
For this problem we would nee to know how wxPage was implemented. Did you derive it from any wxWidgets class??

Here's how it should work:
1. Derive wxPage from wxPanel, use an appropriate ctor.
2. Create the page like wxPage* p = new wxPage(this...)
3. Add the page to the notebook
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message6. Re: wxNotebook with various classes
#4776
Posted by: 2004-07-10 01:28:28
Hello,

the wxPage is a class which is derived from wxPanel:

wxPage-------------------------------------------
wxPage::wxPage(const wxPoint& pos,  const wxSize& size, const wxString&
title, wxNotebook* notebook_1)
      : wxPanel(NULL, -1, pos, size, wxTAB_TRAVERSAL, title )
{
}

wxPanel *CreatePage(wxNotebook* notebook_1)
{
   wxBoxSizer    *m_buttonSizer;
   wxBoxSizer    *m_buttonSizer1;
...
//creates a pages with buttons using panels
}

Frame---------------------------------------------
// frame constructor
wxNotebookFrame::wxNotebookFrame(const wxString& title, const wxPoint&
pos, const wxSize& size)
       : wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
    // set the frame icon
    SetIcon(wxICON(wxNotebook));

//    wxPanel *panel = new wxPage(pos, size, title, notebook_1);
//    wxPanel *panel = new wxPage(this);
//    wxPage *panel = new wxPage(this);
//    panel->CreatePage(notebook_1);

   notebook_1->AddPage( panel, "NAME", FALSE );

}

It doesn`t work!! I have tried many many things but it just doesn`t work! I also tried to call create page from the constructor. When I create a new wxPage it should go in the constructor and create the page which should be `panel`. Since panel is a wxPage which is derived from wxPanel it should work!!!

Thanks,

PS: there is 12 hours difference

Mona

Message7. Re: wxNotebook with various classes
#4783
Posted by: upCASE 2004-07-10 22:48:43
Hi!
Have you tried with passing the notebook as a parent to the panel?

#include <wx/wx.h>

#ifndef TESTPANEL_H
#define TESTPANEL_H

class TestPanel: public wxPanel {
public:
    TestPanel(wxWindow* parent, int id, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=0);
};

#endif // TESTPANEL_H


#include "TestPanel.h"
TestPanel::TestPanel(wxWindow* parent, int id, const wxPoint& pos, const wxSize& size, long style):
    wxPanel(parent, id, pos, size, wxTAB_TRAVERSAL)
{
}


#include "MyFrame.h"

MyFrame::MyFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxFrame(parent, id, title, pos, size, wxDEFAULT_FRAME_STYLE)
{
    notebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, 0);
    notebookPage1 = new TestPanel(notebook, -1);
    
    SetTitle(wxT("Test"));
    
    wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
    notebook->AddPage(notebookPage1, wxT("Page 1"));
    topSizer->Add(new wxNotebookSizer(notebook), 1, wxEXPAND, 0);
    SetAutoLayout(true);
    SetSizer(topSizer);
    topSizer->Fit(this);
    topSizer->SetSizeHints(this);
    Layout();
}
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥880.00 ·
 
 
¥660.00 ·
 
 
¥1,580.00 ·
 
 
¥918.00 ·
 
 
¥430.00 ·
 
 
¥890.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0