Remove static event tables

This commit is contained in:
Tim Warren 2015-04-09 11:45:19 -04:00
parent 946f0699de
commit dee08adda4
8 changed files with 36 additions and 73 deletions

View File

@ -8,7 +8,7 @@ PROGRAM_SRC = $(wildcard src/*.cpp src/widgets/*.cpp)
PROGRAM = build/Tyro
PROGRAM_OBJECTS = $(patsubst %.cpp,%.o, $(PROGRAM_SRC))
LDLIBS = -ldl $(TARGET) $(shell wx-config --libs all) -lssh2
LDLIBS = -ldl $(TARGET) $(shell wx-config --libs base core aui stc) -lssh2
WX_CXXFLAGS = $(shell wx-config --cxxflags)
DEV_CXXFLAGS = -g -Wall -Wextra
CXXFLAGS = -Os -I./src -I./include

View File

@ -17,6 +17,7 @@ bool TyroApp::OnInit()
{
MainFrame* frame = new MainFrame(0L, _("Tyro"));
frame->Layout();
frame->CenterOnScreen();
frame->Show(true);
SetTopWindow(frame);

View File

@ -1,21 +1,5 @@
#include "EditPane.h"
BEGIN_EVENT_TABLE(EditPane, wxStyledTextCtrl)
// common
/*EVT_SIZE (Edit::OnSize)
// edit
EVT_MENU (wxID_CLEAR, Edit::OnEditClear)
EVT_MENU (wxID_CUT, Edit::OnEditCut)
EVT_MENU (wxID_COPY, Edit::OnEditCopy)
EVT_MENU (wxID_PASTE, Edit::OnEditPaste)
EVT_MENU (myID_INDENTINC, Edit::OnEditIndentInc)
EVT_MENU (myID_INDENTRED, Edit::OnEditIndentRed)
EVT_MENU (wxID_SELECTALL, Edit::OnEditSelectAll)
EVT_MENU (myID_SELECTLINE, Edit::OnEditSelectLine)
EVT_MENU (wxID_REDO, Edit::OnEditRedo)
EVT_MENU (wxID_UNDO, Edit::OnEditUndo)*/
END_EVENT_TABLE()
EditPane::EditPane(
wxWindow *parent, wxWindowID id, const wxPoint &pos,
const wxSize &size, long style
@ -25,18 +9,3 @@ EditPane::EditPane(
}
EditPane::~EditPane() {}
void EditPane::OnMenuFileOpen(wxCommandEvent &WXUNUSED(event))
{
wxFileDialog *OpenDialog = new wxFileDialog(this, _T("Choose a file"), _(""), _(""), _("*.*"), wxFD_OPEN);
if (OpenDialog->ShowModal() == wxID_OK)
{
// Load the file into a new notebook tab and styled text control
}
OpenDialog->Close();
}
void EditPane::OnMenuFileSave(wxCommandEvent &WXUNUSED(event))
{
}

View File

@ -19,10 +19,7 @@ public:
wxVSCROLL
);
~EditPane();
void OnMenuFileOpen(wxCommandEvent &event);
void OnMenuFileSave(wxCommandEvent &event);
private:
DECLARE_EVENT_TABLE()
};
#endif // TYRODOC_FRAME_H

View File

@ -8,38 +8,29 @@
#include "MainFrame.h"
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_CLOSE(MainFrame::OnClose)
EVT_MENU(wxID_NEW, MainFrame::OnMenuFileNew)
EVT_MENU(wxID_OPEN, EditPane::OnMenuFileOpen)
EVT_MENU(wxID_SAVE, EditPane::OnMenuFileSave)
EVT_MENU(wxID_ABOUT, MainFrame::OnAbout)
EVT_MENU(wxID_EXIT, MainFrame::OnQuit)
END_EVENT_TABLE()
MainFrame::MainFrame(wxFrame *frame, const wxString& title)
: wxFrame(frame, -1, title)
{
// Create menus and bars
this->SetupMenu();
// create a status bar with some information about the used wxWidgets version
this->SetupStatusBar();
// create the main toolbar
this->SetupToolbar();
// Create the tab container
notebook = new TabContainer(this);
// Set up control layout
wxBoxSizer *base_sizer = new wxBoxSizer(wxVERTICAL);
notebook = this->CreateTabContainer();
base_sizer->Add(notebook, 1, wxEXPAND | wxALL, 5);
base_sizer->SetContainingWindow(this);
base_sizer->SetMinSize(800,600);
SetSizerAndFit(base_sizer);
// Finally, bind events
this->BindEvents();
}
@ -85,8 +76,8 @@ void MainFrame::SetupToolbar()
toolBar->AddTool(wxID_OPEN, "Open", bitmaps[1], "Open file");
toolBar->AddTool(wxID_SAVE, "Save", bitmaps[2], "Save file");
toolBar->AddTool(wxID_CLOSE, "Close", bitmaps[3], "Close file");
toolBar->AddSeparator();
toolBar->AddTool(wxID_ANY, "Settings", bitmaps[4], "Change Settings");
//toolBar->AddSeparator();
//toolBar->AddTool(wxID_ANY, "Settings", bitmaps[4], "Change Settings");
toolBar->Realize();
}
@ -132,11 +123,12 @@ void MainFrame::SetupMenu()
SetMenuBar(mbar);
}
TabContainer *MainFrame::CreateTabContainer()
void MainFrame::BindEvents()
{
TabContainer *notebook = new TabContainer(this);
return notebook;
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnNew, this, wxID_NEW);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnAbout, this, wxID_ABOUT);
Bind(wxEVT_COMMAND_MENU_SELECTED, &MainFrame::OnQuit, this, wxID_EXIT);
Bind(wxEVT_COMMAND_MENU_SELECTED, &TabContainer::OnEditSelectAll, notebook, wxID_SELECTALL);
}
void MainFrame::OnClose(wxCloseEvent &WXUNUSED(event))
@ -144,7 +136,7 @@ void MainFrame::OnClose(wxCloseEvent &WXUNUSED(event))
Destroy();
}
void MainFrame::OnMenuFileNew(wxCommandEvent &WXUNUSED(event))
void MainFrame::OnNew(wxCommandEvent &WXUNUSED(event))
{
notebook->AddTab();
}

View File

@ -11,6 +11,7 @@
class MainFrame: public wxFrame
{
friend class TabContainer;
public:
MainFrame(wxFrame *frame, const wxString &title);
~MainFrame();
@ -24,12 +25,11 @@ class MainFrame: public wxFrame
void SetupMenu();
void SetupToolbar();
void SetupStatusBar();
void OnMenuFileNew(wxCommandEvent &event);
void BindEvents();
void OnNew(wxCommandEvent &event);
void OnClose(wxCloseEvent &event);
void OnQuit(wxCommandEvent &event);
void OnAbout(wxCommandEvent &event);
TabContainer* CreateTabContainer();
DECLARE_EVENT_TABLE()
};

View File

@ -4,9 +4,6 @@
#include "TabContainer.h"
BEGIN_EVENT_TABLE(TabContainer, wxAuiNotebook)
END_EVENT_TABLE()
static unsigned long untitled_document_count = 0;
TabContainer::TabContainer(
@ -22,11 +19,6 @@ TabContainer::TabContainer(
TabContainer::~TabContainer() {}
EditPane *TabContainer::CreateEditor()
{
return new EditPane(this, wxID_ANY);
}
void TabContainer::AddTab()
{
untitled_document_count++;
@ -34,10 +26,22 @@ void TabContainer::AddTab()
caption.Printf("Untitled %lu", untitled_document_count);
this->AddPage(CreateEditor(), caption);
EditPane *editor = new EditPane(this, wxID_ANY);
this->AddPage(editor, caption);
}
void TabContainer::AddTab(wxString filePath)
{
wxString caption="";
EditPane *editor = new EditPane(this, wxID_ANY);
}
this->AddPage(editor, caption);
}
void TabContainer::OnEditSelectAll(wxCommandEvent &WXUNUSED(event))
{
cout << "Edit select all event called.";
//EditPane *editor = (EditPane *) this->GetCurrentPage();
//editor->SelectAll();
}

View File

@ -27,9 +27,9 @@ public:
~TabContainer();
void AddTab();
void AddTab(wxString filePath);
void OnEditSelectAll(wxCommandEvent &event);
private:
EditPane *CreateEditor();
DECLARE_EVENT_TABLE()
};
#endif /* TABCONTAINER_H */