Her er koden:
#include "wx/fontdlg.h"
#include "wx/wx.h"
#include "wx/stc/stc.h"
class NEdit:
public wxApp {
bool OnInit();
};
class MyFrame:
public wxFrame {
public:
wxString T;
wxPoint P;
wxSize S;
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void ReCreateToolBar();
void OnQuit(wxCommandEvent& event);
void OnOpenFile(wxCommandEvent& event);
void OnSaveFile(wxCommandEvent& event);
void OnTextStyle(wxCommandEvent& event);
// virtual wxToolBar *OnCreateToolBar(long style, wxWindowID id, const wxString& name);
private:
wxStyledTextCtrl *TextWindow;
wxToolBar *Gen_ToolBar;
DECLARE_EVENT_TABLE()
};
//const ID_TOOLBAR = 500;
//static const long TOOLBAR_STYLE = wxTB_FLAT| wxTB_DOCKABLE | wxTB_TEXT;
static const wxChar *FILETYPES = _T(
"C++/C source files | *.cpp; *.cc; *c|"
"C++/C header files | *.h; *.hpp|"
"Text files | *.txt |"
"All files | *.* |"
);
enum {
File_Quit = 1,
OpenFile = 100,
SaveFile = 200,
Edit_TextStyle = 300
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(File_Quit, MyFrame::OnQuit)
EVT_MENU(OpenFile, MyFrame::OnOpenFile)
EVT_MENU(SaveFile, MyFrame::OnSaveFile)
EVT_MENU(Edit_TextStyle, MyFrame::OnTextStyle)
END_EVENT_TABLE()
IMPLEMENT_APP(NEdit)
bool NEdit::OnInit() {
MyFrame *MainFrame = new MyFrame("NEdit", wxPoint(0, 0), wxSize(-1, -1));
MainFrame->Show(TRUE);
SetTopWindow(MainFrame);
return TRUE;
}
void ReCreateToolBar() {
/* wxToolBarBase *toolBar = GetToolBar();
long style = toolBar ? toolBar->GetWindowsStyle() : TOOLBAR_STYLE;
delete toolBar;
SetToolBar(NULL);
toolBar = CreateToolBar(style, ID_TOOLBAR); */
}
MyFrame::MyFrame (const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *)NULL, -1, title, pos, size) {
Gen_ToolBar = NULL;
TextWindow = new wxStyledTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE);
TextWindow->SetMarginWidth(0, 30);
TextWindow->SetMarginWidth(1, 0);
TextWindow->SetMarginType(0, 1);
wxMenu *menuFile = new wxMenu;
wxMenu *menuEdit = new wxMenu;
menuFile->Append(OpenFile, "&Open");
menuFile->Append(SaveFile, "¤&Save");
menuFile->AppendSeparator();
menuFile->Append(File_Quit, "&Exit");
menuEdit->Append(Edit_TextStyle, "&Text style");
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&Filer");
menuBar->Append(menuEdit, "&Edit");
SetMenuBar(menuBar);
// ReCreateToolBar();
}
void MyFrame::OnQuit(wxCommandEvent& event) {
Close(TRUE);
}
void MyFrame::OnOpenFile(wxCommandEvent& WXUNUSED(event)) {
wxFileDialog *OpenFileDialog = new wxFileDialog(this, "Open file", "", "", FILETYPES, wxOPEN, wxDefaultPosition);
if(OpenFileDialog->ShowModal() == wxID_OK) {
// SetCurrentFilename(OpenFileDialog->GetFilename());
TextWindow->LoadFile(OpenFileDialog->GetFilename());
}
}
void MyFrame::OnSaveFile(wxCommandEvent& WXUNUSED(event)) {
wxFileDialog *SaveFileDialog = new wxFileDialog(this, "Save file", "", "", FILETYPES, wxSAVE, wxDefaultPosition);
}
void MyFrame::OnTextStyle(wxCommandEvent& WXUNUSED(event)) {
wxFontData FontData;
wxFont Font;
wxColour Colour;
Font = TextWindow->GetFont();
FontData.SetInitialFont(Font);
Colour = TextWindow->GetForegroundColour();
FontData.SetColour(Colour);
FontData.SetShowHelp(FALSE);
wxFontDialog *FontDialog = new wxFontDialog(this, &FontData);
if(FontDialog->ShowModal() == wxID_OK) {
FontData = FontDialog->GetFontData();
Font = FontData.GetChosenFont();
TextWindow->SetFont(Font);
TextWindow->SetForegroundColour(FontData.GetColour());
}
}
- php-4ever
[Redigeret d. 27/10-04 14:15:29 af php-4ever]