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/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 "bitmaps/new.xpm"
#include "bitmaps/open.xpm"
#include "bitmaps/close.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);
virtual ~MyFrame(); // Destructor
wxNotebook* Notebook;
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:
wxImageList* m_imageList(int width, int height); // Image list
//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);
#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.0.0b\n Copyright 2008, Timothy J. Warren\n Special thanks to the wxWidgets Community"));
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, wxDefaultSize, wxNB_LEFT);
m_text = new wxTextCtrl(Notebook,
wxID_ANY, // ID
_T(""), // Initial text
wxDefaultPosition, // Position
wxDefaultSize, // Size
wxTE_MULTILINE); // Flags
// Create new imagelist which takes images of 16x16 pixels
m_imageList = new wxImageList(8, 8);
m_imageList->Add(wxICON(close)); // Add image 0
// Set it as the notebook's imagelist
Notebook->SetImageList(m_imageList);
#if wxUSE_TOOLBAR
CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL);
InitToolBar(GetToolBar());
#endif // wxUSE_TOOLBAR
gs_nFrames = 0;
}
void MyFrame::OnNew(wxCommandEvent& event){
Notebook->AddPage(m_text,
wxString::Format(_T("Untitled %d"), gs_nFrames++), // Title
true, // Select the tab (true/false)
0); // Image index in image list we assigned with SetImageList() before
}
void MyFrame::OnOpen(wxCommandEvent& event){
wxString wildcards = wxT("HTML files (*.html, *.htm)|*.htm*|CSS files (*.css)|*.css|PHP files (*.php)|*.php|Other (*.*)|*.*");
wxString file = ::wxFileSelector(wxT("Open file"), wxT(""), wxT(""), wxT(""), wildcards);
if (file.IsEmpty() == false){
m_text->LoadFile(file);
wxString title;
title.Printf(file, ++gs_nFrames);
wxString::Format(_T("Untitled %d"), gs_nFrames++, true, 0);
// Image index in image list we assigned with SetImageList() before
}
}
void MyFrame::OnSave(wxCommandEvent& event){
wxString wildcards = wxT("HTML files (*.html, *.htm)|*.htm*|CSS files (*.css)|*.css|PHP files (*.php)|*.php|Other (*.*)|*.*");
wxString file = ::wxFileSelector(wxT("Save file"), wxT(""), wxT(""), wxT(""), wildcards);
if (file.IsEmpty() == false){
m_text->SaveFile(file);
}
}
/* MyFrame destructor */
MyFrame::~MyFrame() {
// Have to delete the wxImageList
delete m_imageList;
}