wxWidgets/C++ Tabbed Text Editor 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.
timw4mail
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sun Mar 23, 2008 6:59 pm
Location: United States
Contact:

wxWidgets/C++ Tabbed Text Editor

Post by timw4mail » Sat Apr 05, 2008 3:36 pm

I'm trying to write a simple text-editor with tabs to open multiple documents. I'm currently simply using the wxTextCtrl, but plan on moving to wxScintilla or the StyledTextCtrl.

I'm getting a runtime error when I click "new" under the toolbar or the menu... is there something I'm really off on?
I'm also getting a
bitmaps/help.xpm:71: warning: deprecated conversion from string constant to 'char*'
error for all the xpm files.

Here's what I have:

Code: Select all

/////////////////////////////////////////////////////////////////////////////
// Name:        CWebGUI.h
// Purpose:     Text Editor for web development
// Author:      Timothy J. Warren
// Created:     2008-02
// Copyright:   (c) 2008 Timothy J. Warren
// Licence:     Source on request
/////////////////////////////////////////////////////////////////////////////


#include "wx/wxprec.h"


#ifndef WX_PRECOMP
    #include "wx/wx.h"
    //#include "wx/cmdproc.h"
    #include "wx/notebook.h"
    //#include "wx/print.h"
    //#include "wx/printdlg.h"
#endif

/*
#if wxUSE_FILESYSTEM
    #include "wx/filesys.h"
    #include "wx/fs_mem.h"
#endif
*/
#ifdef __WXMSW__
    #define USE_WXMSW 1
#else
    #define USE_WXMSW 0
#endif

#ifdef __WXUNIVERSAL__
    #define USE_WXUNIVERSAL 1
#else
    #define USE_WXUNIVERSAL 0
#endif

#ifdef __WXMAC__
    #define USE_WXMAC 1
#else
    #define USE_WXMAC 0
#endif

#ifdef __WXGTK__
    #define USE_WXGTK 1
#else
    #define USE_WXGTK 0
#endif

#ifdef __WXMOTIF__
    #define USE_WXMOTIF 1
#else
    #define USE_WXMOTIF 0
#endif

//Image files

#include "app.xpm"
#include "child.xpm"
#include "bitmaps/new.xpm"
#include "bitmaps/open.xpm"
#include "bitmaps/save.xpm"
#include "bitmaps/copy.xpm"
#include "bitmaps/cut.xpm"
#include "bitmaps/paste.xpm"
#include "bitmaps/print.xpm"
#include "bitmaps/help.xpm"


//Declare the application class
class MyApp : public wxApp{
public:
     virtual bool OnInit();

};

DECLARE_APP(MyApp)

//Declare our main frame class
//class MyCanvas;
class MyFrame : public wxFrame {
public:
    MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, 
            const wxPoint& pos, const wxSize& size, const long type);
    wxNotebook* Notebook;/*(wxWindow *parent, const wxWindowID id, const wxString& title, 
            const wxPoint& pos, const wxSize& size, const long type);*/
    wxTextCtrl* m_text;
    void InitToolBar(wxToolBar* toolBar);
    
    /*-----Event handlers-----*/
    //File Menu 
    void OnNew (wxCommandEvent& event);
    void OnOpen(wxCommandEvent& event);
    void OnSave(wxCommandEvent& event);
    void OnQuit (wxCommandEvent& event);

    //Help Menu
    void OnAbout (wxCommandEvent& event);
    
private:
    //This class handles events
    DECLARE_EVENT_TABLE()
};


//Event table for MyFrame
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    //File Menu
    EVT_MENU(wxID_NEW, MyFrame::OnNew)
    EVT_MENU(wxID_OPEN, MyFrame::OnOpen)
    EVT_MENU(wxID_SAVE, MyFrame::OnSave)
     /*
    #if wxUSE_CLIPBOARD
        EVT_MENU(wxID_COPY, MyChild::OnCopy)
        EVT_MENU(wxID_CUT, MyChild::OnCut)
        EVT_MENU(wxID_PASTE, MyChild::OnPaste)
    #endif //Use Clipboard
    EVT_MENU(wxID_SAVEAS, MyFrame::OnSaveAs)
    EVT_MENU(ID_PRINT, MyFrame::OnPrint)
    EVT_MENU(ID_PREVIEW, MyFrame::OnPreview)
    EVT_MENU(ID_PAGE_SETUP, MyFrame::OnPageSetup)*/
    EVT_MENU(wxID_EXIT,  MyFrame::OnQuit)
    //Help Menu
    EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
END_EVENT_TABLE()
        
/*
enum{

    ID_PRINT,
    ID_PREVIEW,
    ID_PAGE_SETUP

};
   */     

Code: Select all

/////////////////////////////////////////////////////////////////////////////
// Name:        CWebGUI.cpp
// Purpose:     Text Editor for web development
// Author:      Timothy J. Warren
// Created:     2008-02
// Copyright:   (c) 2008 Timothy J. Warren
// Licence:     Source on request
/////////////////////////////////////////////////////////////////////////////


#include "CWebGUI.h" //For Includes and Classes

static int gs_nFrames = 0;

IMPLEMENT_APP(MyApp);

//Initialize the application
bool MyApp::OnInit(){
    MyFrame *frame = new MyFrame (NULL, wxID_ANY, _T("CWebGUI"), wxPoint(0,0),
    wxSize(640, 480), wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
    
    //Set the frame icon
    frame->SetIcon(wxICON(app));

    //File Menu
    wxMenu *fileMenu = new wxMenu;
    fileMenu->Append(wxID_NEW, wxT("&New\tCtrl+N"),wxT("Create a new file"));
    fileMenu->AppendSeparator();
    fileMenu->Append(wxID_OPEN, wxT("&Open\tCtrl+O"),wxT("Open a file"));
    //fileMenu->Append(wxID_CLOSE, wxT("&Close\tCtrl+W"),wxT("Close current file"));
    fileMenu->Append(wxID_SAVE, wxT("&Save\tCtrl+S"),wxT("Save current file"));
    //fileMenu->Append(wxID_SAVEAS, wxT("Save &As...\tShift+Ctrl+S"),wxT("Save current file as..."));
    /*
    fileMenu->AppendSeparator();
    fileMenu->Append(wxID_PRINT, wxT("Print\tCtrl+P"), wxT("Print current document"));
    fileMenu->Append(wxID_PRINT_SETUP, wxT("Print Setup\tShift+Ctrl+P"), wxT("Set printing options"));
    fileMenu->Append(wxID_PREVIEW, wxT("Print Pre&view"), wxT("Preview the printout of the current document"));
    fileMenu->AppendSeparator();*/
    fileMenu->Append(wxID_EXIT, wxT("E&xit\tCtrl+Q"),wxT("Quit this program"));

    
    //Edit Menu
    /*
    #if wxUSE_CLIPBOARD
        wxMenu *edit_menu = new wxMenu;
        edit_menu->Append(wxID_CUT, wxT("Cut\tCtrl+X"), wxT("Cut the selected text"));
        edit_menu->Append(wxID_COPY, wxT("Copy\tCtrl+C"), wxT("Copy the selected text"));
        edit_menu->Append(wxID_PASTE, wxT("Paste\tCtrl+V"), wxT("Paste text from the clipboard"));
    #endif
    */
    
    //Help Menu
    wxMenu *help_Menu = new wxMenu;
    help_Menu->Append(wxID_ABOUT, wxT("&About...\tF1"),wxT("Show about dialog"));
    
    //Now append the freshly created menu to the menu bar
    wxMenuBar *menu_Bar = new wxMenuBar();
    menu_Bar->Append(fileMenu, wxT("&File"));
    /*if(edit_menu){
        menu_Bar->Append(edit_menu, wxT("&Edit"));
    }*/
    menu_Bar->Append(help_Menu, wxT("&Help"));
    
    #ifdef __WXMAC__
        wxMenuBar::MacSetCommonMenuBar (menu_Bar);
    #endif
    
    //attach menu bar to frame
    frame->SetMenuBar(menu_Bar);
        
    //Create status bar just for fun
    frame->CreateStatusBar();
    frame->SetStatusText(wxT("Welcome to CWebGUI!"));
    
    frame->CenterOnScreen();
    
    wxNotebook* Notebook = new wxNotebook(frame, wxID_ANY, wxDefaultPosition, wxSize(640,480), wxNB_LEFT);
    wxTextCtrl* m_text = new wxTextCtrl( Notebook, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
    //Show it
    #ifndef __WXMAC__
        frame->Show(true);
    #endif 
    //Start the event loop
    return true;
}

/*-------My Frame Event Functions-------*/
void MyFrame:: OnQuit(wxCommandEvent& WXUNUSED(event)){
    //Destroy the frame
    Close();
}

#if wxUSE_TOOLBAR
    void MyFrame::InitToolBar(wxToolBar* toolBar){
        wxBitmap bitmaps[8];

        bitmaps[0] = wxBitmap( new_xpm );
        bitmaps[1] = wxBitmap( open_xpm );
        bitmaps[2] = wxBitmap( save_xpm );
        bitmaps[3] = wxBitmap( copy_xpm );
        bitmaps[4] = wxBitmap( cut_xpm );
        bitmaps[5] = wxBitmap( paste_xpm );
        bitmaps[6] = wxBitmap( print_xpm );
        bitmaps[7] = wxBitmap( help_xpm );
        
        toolBar->AddTool(wxID_NEW, _T("New"), bitmaps[0], _T("New file"));
        toolBar->AddTool(wxID_OPEN, _T("Open"), bitmaps[1], _T("Open file"));
        toolBar->AddTool(wxID_SAVE, _T("Save"), bitmaps[2], _T("Save file"));
        
        #if wxUSE_CLIPBOARD
            toolBar->AddSeparator();
            toolBar->AddTool(wxID_COPY, _T("Copy"), bitmaps[3], _T("Copy"));
            toolBar->AddTool(wxID_CUT, _T("Cut"), bitmaps[4], _T("Cut"));
            toolBar->AddTool(wxID_PASTE, _T("Paste"), bitmaps[5], _T("Paste"));
            toolBar->AddSeparator();
        #endif //wxUSE_CLIPBOARD

        //toolBar->AddTool(wxID_PRINT, _T("Print"), bitmaps[6], _T("Print"));
        //toolBar->AddSeparator();
        toolBar->AddTool(wxID_ABOUT, _T("About"), bitmaps[7], _T("Help"));

        toolBar->Realize();
    }
#endif // wxUSE_TOOLBAR

//Help menu
void MyFrame:: OnAbout(wxCommandEvent& WXUNUSED(event)){
    wxString msg; //Dialog Message string
    msg.Printf(
    wxT("CWebGUI, a text editor for web development\n Version 1.1.0 Pre-Alpha \n Copyright 2008, Timothy J. Warren"));
    wxMessageBox(msg, wxT("About CWebGUI"), //wxT("Title")
            wxOK | wxICON_INFORMATION, this);
}

/*-----End My Frame Event Functions-----*/


MyFrame::MyFrame(wxWindow *parent,const wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size, long style):
wxFrame(parent, id, title, pos, size, style){
    MyFrame *frame = this;
    #if wxUSE_TOOLBAR
        CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL);
        InitToolBar(GetToolBar());
    #endif // wxUSE_TOOLBAR
}


void MyFrame::OnNew(wxCommandEvent& event){
    m_text = new wxTextCtrl;
    Notebook->AddPage(m_text, _T("Untitled %d"), ++gs_nFrames);
    //Notebook->SetIcon(wxIcon(child_xpm));
    
}


void MyFrame::OnOpen(wxCommandEvent& event){
    
    wxString file = ::wxFileSelector(wxT("Open file"));
    if (file.IsEmpty() == false){
        m_text->LoadFile(file);
    }
    
    wxString title;
    title.Printf(file, ++gs_nFrames);
    
    m_text = new wxTextCtrl;
    Notebook->AddPage(m_text, title, ++gs_nFrames);
    
    
}

void MyFrame::OnSave(wxCommandEvent& event){
    wxString file = ::wxFileSelector(wxT("Save file"));
    if (file.IsEmpty() == false){
        m_text->SaveFile(file);
    }
}




Last edited by timw4mail on Sat Apr 05, 2008 6:20 pm, edited 1 time in total.
My wxWidgets Program:Snaga

Platforms:Windows, Linux, Solaris, Mac
IDE/Compiler:Netbeans with MinGW/GCC, Sun Compilers for Solaris, Xcode for Mac
wxWidgets Version:2.8.7

ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay » Sat Apr 05, 2008 3:40 pm

How are your xpm bitmaps declared in the header files? Looks like you are using "string" when it should be something like "static const char *const xxx_xpm[]". Do your xpm headers actually contain xpm character arrays?

timw4mail
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sun Mar 23, 2008 6:59 pm
Location: United States
Contact:

Post by timw4mail » Sat Apr 05, 2008 3:44 pm

ArKay wrote:How are your xpm bitmaps declared in the header files? Looks like you are using "string" when it should be something like "static const char *const xxx_xpm[]". Do your xpm headers actually contain xpm character arrays?
The xpm files are just included, like shown in the code in the post above. The first section is the header file, and the second is the actual source file.
My wxWidgets Program:Snaga

Platforms:Windows, Linux, Solaris, Mac
IDE/Compiler:Netbeans with MinGW/GCC, Sun Compilers for Solaris, Xcode for Mac
wxWidgets Version:2.8.7

ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay » Sat Apr 05, 2008 3:58 pm

I think that those .xpm files are wrong though. Take a look at samples/sample.xpm (open with a text editor) to see what they must be like.

You should also move the xpm #includes to the CWebGUI.cpp to avoid multiple declarations should you include CWebGUI.h in other sources.

timw4mail
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sun Mar 23, 2008 6:59 pm
Location: United States
Contact:

Post by timw4mail » Sat Apr 05, 2008 4:02 pm

ArKay wrote: You should also move the xpm #includes to the CWebGUI.cpp to avoid multiple declarations should you include CWebGUI.h in other sources.
I won't be using the entire header file in another project, which is why I have the classes in that header file.

I don't quite understand what you mean about the xpm files.
The ones that are used for the toolbar are from the wxWidgets samples. The "app.xpm" was crated by the GIMP from an icon.
My wxWidgets Program:Snaga

Platforms:Windows, Linux, Solaris, Mac
IDE/Compiler:Netbeans with MinGW/GCC, Sun Compilers for Solaris, Xcode for Mac
wxWidgets Version:2.8.7

Sof_T
Can't get richer than this
Can't get richer than this
Posts: 864
Joined: Thu Jul 28, 2005 9:48 pm
Location: New Forest, United Kingdom
Contact:

Post by Sof_T » Sat Apr 05, 2008 4:33 pm

Code: Select all

void MyFrame::OnNew(wxCommandEvent& event){ 
    m_text = new wxTextCtrl; 
    Notebook->AddPage(m_text, _T("Untitled %d"), ++gs_nFrames); 
    //Notebook->SetIcon(wxIcon(child_xpm)); 
    
}
You are using the default constructor for the text control. I haven't looked deeply into this but it maybe that you need to use the second form of constructor specifying a parent window and an ID for the control, otherwise it may not be constructed before you are using it.
The home of Sof.T http://www.sof-t.site88.net/
Author of Programming with wxDevC++
http://sourceforge.net/projects/wxdevcpp-book/

timw4mail
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sun Mar 23, 2008 6:59 pm
Location: United States
Contact:

Post by timw4mail » Sat Apr 05, 2008 4:45 pm

Sof_T wrote:

Code: Select all

void MyFrame::OnNew(wxCommandEvent& event){ 
    m_text = new wxTextCtrl; 
    Notebook->AddPage(m_text, _T("Untitled %d"), ++gs_nFrames); 
    //Notebook->SetIcon(wxIcon(child_xpm)); 
    
}
You are using the default constructor for the text control. I haven't looked deeply into this but it maybe that you need to use the second form of constructor specifying a parent window and an ID for the control, otherwise it may not be constructed before you are using it.
Second form of a constructor?
My wxWidgets Program:Snaga

Platforms:Windows, Linux, Solaris, Mac
IDE/Compiler:Netbeans with MinGW/GCC, Sun Compilers for Solaris, Xcode for Mac
wxWidgets Version:2.8.7

ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay » Sat Apr 05, 2008 4:48 pm

I am not getting the warnings about the xpms with GCC on Windows here, may have to do with your compiler or its settings.

There are multiple errors as far as I can see.

You create _local_ controls in MyApp::OnInit():

Code: Select all

wxNotebook* Notebook = new wxNotebook(frame, wxID_ANY, wxDefaultPosition, wxSize(640,480), wxNB_LEFT);
wxTextCtrl* m_text = new wxTextCtrl( Notebook, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
and then reference an _uninitialized_ variable in MyFrame::OnNew():

Code: Select all

Notebook->AddPage(m_text, _T("Untitled %d"));
Where does "Notebook" in MyFrame come from? It's a pointer declaration in the header which never gets initialized.

Code: Select all

class MyFrame : public wxFrame {
public:
    ...
    wxNotebook* Notebook;/*(wxWindow *parent, const wxWindowID id, const wxString& title,
            const wxPoint& pos, const wxSize& size, const long type);*/
    wxTextCtrl* m_text;

ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay » Sat Apr 05, 2008 5:05 pm

This should get you started.

Code: Select all

/////////////////////////////////////////////////////////////////////////////
// Name:        CWebGUI.cpp
// Purpose:     Text Editor for web development
// Author:      Timothy J. Warren
// Created:     2008-02
// Copyright:   (c) 2008 Timothy J. Warren
// Licence:     Source on request
/////////////////////////////////////////////////////////////////////////////


#include "CWebGUIMain.h" //For Includes and Classes

static int gs_nFrames = 0;

IMPLEMENT_APP(MyApp);

//Initialize the application
bool MyApp::OnInit(){
    MyFrame *frame = new MyFrame (NULL, wxID_ANY, _T("CWebGUI"), wxPoint(0,0),
		wxSize(640, 480), wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
    #ifndef __WXMAC__
        frame->Show(true);
    #endif
    //Start the event loop
    return true;
}

/*-------My Frame Event Functions-------*/
void MyFrame:: OnQuit(wxCommandEvent& WXUNUSED(event)){
    //Destroy the frame
    Close();
}

#if wxUSE_TOOLBAR
    void MyFrame::InitToolBar(wxToolBar* toolBar){
        wxBitmap bitmaps[8];

        bitmaps[0] = wxBitmap( new_xpm );
        bitmaps[1] = wxBitmap( open_xpm );
        bitmaps[2] = wxBitmap( save_xpm );
        bitmaps[3] = wxBitmap( copy_xpm );
        bitmaps[4] = wxBitmap( cut_xpm );
        bitmaps[5] = wxBitmap( paste_xpm );
        bitmaps[6] = wxBitmap( print_xpm );
        bitmaps[7] = wxBitmap( help_xpm );

        toolBar->AddTool(wxID_NEW, _T("New"), bitmaps[0], _T("New file"));
        toolBar->AddTool(wxID_OPEN, _T("Open"), bitmaps[1], _T("Open file"));
        toolBar->AddTool(wxID_SAVE, _T("Save"), bitmaps[2], _T("Save file"));

        #if wxUSE_CLIPBOARD
            toolBar->AddSeparator();
            toolBar->AddTool(wxID_COPY, _T("Copy"), bitmaps[3], _T("Copy"));
            toolBar->AddTool(wxID_CUT, _T("Cut"), bitmaps[4], _T("Cut"));
            toolBar->AddTool(wxID_PASTE, _T("Paste"), bitmaps[5], _T("Paste"));
            toolBar->AddSeparator();
        #endif //wxUSE_CLIPBOARD

        //toolBar->AddTool(wxID_PRINT, _T("Print"), bitmaps[6], _T("Print"));
        //toolBar->AddSeparator();
        toolBar->AddTool(wxID_ABOUT, _T("About"), bitmaps[7], _T("Help"));

        toolBar->Realize();
    }
#endif // wxUSE_TOOLBAR

//Help menu
void MyFrame:: OnAbout(wxCommandEvent& WXUNUSED(event)){
    wxString msg; //Dialog Message string
    msg.Printf(
    wxT("CWebGUI, a text editor for web development\n Version 1.1.0 Pre-Alpha \n Copyright 2008, Timothy J. Warren"));
    wxMessageBox(msg, wxT("About CWebGUI"), //wxT("Title")
            wxOK | wxICON_INFORMATION, this);
}

/*-----End My Frame Event Functions-----*/


MyFrame::MyFrame(wxWindow *parent,const wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size, long style):
wxFrame(parent, id, title, pos, size, style){
    //Set the frame icon
    SetIcon(wxICON(app));

    //File Menu
    wxMenu *fileMenu = new wxMenu;
    fileMenu->Append(wxID_NEW, wxT("&New\tCtrl+N"),wxT("Create a new file"));
    fileMenu->AppendSeparator();
    fileMenu->Append(wxID_OPEN, wxT("&Open\tCtrl+O"),wxT("Open a file"));
    //fileMenu->Append(wxID_CLOSE, wxT("&Close\tCtrl+W"),wxT("Close current file"));
    fileMenu->Append(wxID_SAVE, wxT("&Save\tCtrl+S"),wxT("Save current file"));
    //fileMenu->Append(wxID_SAVEAS, wxT("Save &As...\tShift+Ctrl+S"),wxT("Save current file as..."));
    /*
    fileMenu->AppendSeparator();
    fileMenu->Append(wxID_PRINT, wxT("Print\tCtrl+P"), wxT("Print current document"));
    fileMenu->Append(wxID_PRINT_SETUP, wxT("Print Setup\tShift+Ctrl+P"), wxT("Set printing options"));
    fileMenu->Append(wxID_PREVIEW, wxT("Print Pre&view"), wxT("Preview the printout of the current document"));
    fileMenu->AppendSeparator();*/
    fileMenu->Append(wxID_EXIT, wxT("E&xit\tCtrl+Q"),wxT("Quit this program"));


    //Edit Menu
    /*
    #if wxUSE_CLIPBOARD
        wxMenu *edit_menu = new wxMenu;
        edit_menu->Append(wxID_CUT, wxT("Cut\tCtrl+X"), wxT("Cut the selected text"));
        edit_menu->Append(wxID_COPY, wxT("Copy\tCtrl+C"), wxT("Copy the selected text"));
        edit_menu->Append(wxID_PASTE, wxT("Paste\tCtrl+V"), wxT("Paste text from the clipboard"));
    #endif
    */

    //Help Menu
    wxMenu *help_Menu = new wxMenu;
    help_Menu->Append(wxID_ABOUT, wxT("&About...\tF1"),wxT("Show about dialog"));

    //Now append the freshly created menu to the menu bar
    wxMenuBar *menu_Bar = new wxMenuBar();
    menu_Bar->Append(fileMenu, wxT("&File"));
    /*if(edit_menu){
        menu_Bar->Append(edit_menu, wxT("&Edit"));
    }*/
    menu_Bar->Append(help_Menu, wxT("&Help"));

    #ifdef __WXMAC__
        wxMenuBar::MacSetCommonMenuBar (menu_Bar);
    #endif

    //attach menu bar to frame
    SetMenuBar(menu_Bar);

    //Create status bar just for fun
    CreateStatusBar();
    SetStatusText(wxT("Welcome to CWebGUI!"));

    CenterOnScreen();

    Notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(640,480), wxNB_LEFT);
    //m_text = new wxTextCtrl( Notebook, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );

    #if wxUSE_TOOLBAR
        CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL);
        InitToolBar(GetToolBar());
    #endif // wxUSE_TOOLBAR
    gs_nFrames = 0;
}


void MyFrame::OnNew(wxCommandEvent& event){
    m_text = new wxTextCtrl(Notebook, wxID_ANY); // page parent = Notebook!
    Notebook->AddPage(m_text, wxString::Format(_T("Untitled %d"), gs_nFrames++));
    //Notebook->SetIcon(wxIcon(child_xpm));
}


void MyFrame::OnOpen(wxCommandEvent& event){

    wxString file = ::wxFileSelector(wxT("Open file"));
    if (file.IsEmpty() == false){
        m_text->LoadFile(file);
    }

    wxString title;
    title.Printf(file, ++gs_nFrames);

    m_text = new wxTextCtrl;
    Notebook->AddPage(m_text, title, ++gs_nFrames);


}

void MyFrame::OnSave(wxCommandEvent& event){
    wxString file = ::wxFileSelector(wxT("Save file"));
    if (file.IsEmpty() == false){
        m_text->SaveFile(file);
    }
}

timw4mail
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sun Mar 23, 2008 6:59 pm
Location: United States
Contact:

Post by timw4mail » Sat Apr 05, 2008 5:06 pm

ArKay wrote:I am not getting the warnings about the xpms with GCC on Windows here, may have to do with your compiler or its settings.

There are multiple errors as far as I can see.

You create _local_ controls in MyApp::OnInit():

Code: Select all

wxNotebook* Notebook = new wxNotebook(frame, wxID_ANY, wxDefaultPosition, wxSize(640,480), wxNB_LEFT);
wxTextCtrl* m_text = new wxTextCtrl( Notebook, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
How would I make them global controls, then?

I am not by any means proficient with classes and pointers, so I don't really understand all of what goes into this yet.
My wxWidgets Program:Snaga

Platforms:Windows, Linux, Solaris, Mac
IDE/Compiler:Netbeans with MinGW/GCC, Sun Compilers for Solaris, Xcode for Mac
wxWidgets Version:2.8.7

ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay » Sat Apr 05, 2008 5:08 pm

Move the control creation where it belongs (to the MyFrame class). See my previous post. :)

ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay » Sat Apr 05, 2008 5:10 pm

You have to change the #include I modified back:

#include "CWebGUIMain.h" //For Includes and Classes
to
#include "CWebGUI.h" //For Includes and Classes

timw4mail
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sun Mar 23, 2008 6:59 pm
Location: United States
Contact:

Post by timw4mail » Sat Apr 05, 2008 5:28 pm

ArKay wrote:You have to change the #include I modified back:

#include "CWebGUIMain.h" //For Includes and Classes
to
#include "CWebGUI.h" //For Includes and Classes
Now its working, but the textCtrl isn't multiline.
Where would I declare that?
My wxWidgets Program:Snaga

Platforms:Windows, Linux, Solaris, Mac
IDE/Compiler:Netbeans with MinGW/GCC, Sun Compilers for Solaris, Xcode for Mac
wxWidgets Version:2.8.7

ArKay
Knows some wx things
Knows some wx things
Posts: 41
Joined: Wed Mar 26, 2008 1:38 pm
Location: Germany

Post by ArKay » Sat Apr 05, 2008 5:48 pm

You can remove the definition of the textctrl from the header file since it's not used anywhere:

wxTextCtrl* m_text; <-

Then you can add flags to the control:

Code: Select all

void MyFrame::OnNew(wxCommandEvent& event){
    wxTextCtrl* text = new wxTextCtrl(Notebook,
		wxID_ANY, 		// ID
		_T(""), 		// Initial text
		wxDefaultPosition, 	// Position
		wxDefaultSize, 		// Size
		wxTE_MULTILINE);	// Flags
    Notebook->AddPage(text, wxString::Format(_T("Untitled %d"), gs_nFrames++));
    //Notebook->SetIcon(wxIcon(child_xpm));
}

timw4mail
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sun Mar 23, 2008 6:59 pm
Location: United States
Contact:

Post by timw4mail » Sat Apr 05, 2008 6:02 pm

ArKay wrote:You can remove the definition of the textctrl from the header file since it's not used anywhere:

wxTextCtrl* m_text; <-

Then you can add flags to the control:

Code: Select all

void MyFrame::OnNew(wxCommandEvent& event){
    wxTextCtrl* text = new wxTextCtrl(Notebook,
		wxID_ANY, 		// ID
		_T(""), 		// Initial text
		wxDefaultPosition, 	// Position
		wxDefaultSize, 		// Size
		wxTE_MULTILINE);	// Flags
    Notebook->AddPage(text, wxString::Format(_T("Untitled %d"), gs_nFrames++));
    //Notebook->SetIcon(wxIcon(child_xpm));
}
Now, for a different issue: (I hope you aren't tired of me)
I want to add an icon and/or button on each tab to close it.

How would I go about doing this?
My wxWidgets Program:Snaga

Platforms:Windows, Linux, Solaris, Mac
IDE/Compiler:Netbeans with MinGW/GCC, Sun Compilers for Solaris, Xcode for Mac
wxWidgets Version:2.8.7

Post Reply