📄 test.cpp
字号:
//////////////////////////////////////////////////////////////////////////////
// File: test.cpp
// Purpose: wxScintilla test application
// Maintainer: Otto Wyss
// Created: 2003-09-01
// RCS-ID: $Id: test.cpp,v 1.2 2005/08/26 11:15:32 mandrav Exp $
// Copyright: (c) 2004 wxCode
// Licence: wxWindows licence
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// headers
//----------------------------------------------------------------------------
// For compilers that support precompilation, includes <wx/wx.h>.
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all 'standard' wxWindows headers)
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
//! wxWindows headers
#include <wx/config.h> // configuration support
#include <wx/filedlg.h> // file dialog support
#include <wx/filename.h> // filename support
#include <wx/notebook.h> // notebook support
#include <wx/settings.h> // system settings
#include <wx/string.h> // strings support
#include <wx/image.h> // images support
//! application headers
#include "defsext.h" // Additional definitions
#include "edit.h" // Edit module
#include "prefs.h" // Prefs
//----------------------------------------------------------------------------
// resources
//----------------------------------------------------------------------------
// the application icon (under Windows and OS/2 it is in resources)
#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
#include "mondrian.xpm"
#endif
//============================================================================
// declarations
//============================================================================
#define APP_NAME _T("wxScintilla-Test")
#define APP_DESCR _("See the wxScintilla website at wxCode")
#define APP_MAINT _T("Otto Wyss")
#define APP_VENDOR _T("wxCode")
#define APP_COPYRIGTH _T("(C) 2003 Otto Wyss")
#define APP_LICENCE _T("wxWindows")
#define APP_VERSION _T("1.0.0")
#define APP_BUILD __DATE__
#define APP_WEBSITE _T("http://wxcode.sourceforge.net/components/wxscintilla/index.html")
#define APP_MAIL _T("http://wxcode.sourceforge.net/feedback.php?component=wxscintilla")
#define NONAME _("<untitled>")
class AppBook;
//----------------------------------------------------------------------------
//! global application name
wxString *g_appname = NULL;
//! global print data, to remember settings during the session
wxPrintData *g_printData = (wxPrintData*) NULL;
wxPageSetupData *g_pageSetupData = (wxPageSetupData*) NULL;
//----------------------------------------------------------------------------
//! application APP_VENDOR-APP_NAME.
class App: public wxApp {
friend class AppFrame;
public:
//! the main function called durning application start
virtual bool OnInit ();
//! application exit function
virtual int OnExit ();
private:
//! frame window
AppFrame* m_frame;
};
// created dynamically by wxWindows
DECLARE_APP (App);
//----------------------------------------------------------------------------
//! frame of the application APP_VENDOR-APP_NAME.
class AppFrame: public wxFrame {
friend class App;
friend class AppBook;
friend class AppAbout;
public:
//! constructor
AppFrame (const wxString &title);
//! destructor
~AppFrame ();
//! event handlers
//! common
void OnClose (wxCloseEvent &event);
void OnAbout (wxCommandEvent &event);
void OnExit (wxCommandEvent &event);
void OnTimerEvent (wxTimerEvent &event);
//! file
void OnFileNew (wxCommandEvent &event);
void OnFileNewFrame (wxCommandEvent &event);
void OnFileOpen (wxCommandEvent &event);
void OnFileOpenFrame (wxCommandEvent &event);
void OnFileSave (wxCommandEvent &event);
void OnFileSaveAs (wxCommandEvent &event);
void OnFileClose (wxCommandEvent &event);
//! properties
void OnProperties (wxCommandEvent &event);
//! print
void OnPrintSetup (wxCommandEvent &event);
void OnPrintPreview (wxCommandEvent &event);
void OnPrint (wxCommandEvent &event);
//! edit events
void OnEdit (wxCommandEvent &event);
private:
// edit object
Edit *m_edit;
void FileOpen (wxString fname);
//! creates the application menu bar
wxMenuBar *m_menuBar;
void CreateMenu ();
// print preview position and size
wxRect DeterminePrintSize ();
DECLARE_EVENT_TABLE()
};
//----------------------------------------------------------------------------
//! about box of the application APP_VENDOR-APP_NAME
class AppAbout: public wxDialog {
public:
//! constructor
AppAbout (wxWindow *parent,
int milliseconds = 0,
long style = 0);
//! destructor
~AppAbout ();
// event handlers
void OnTimerEvent (wxTimerEvent &event);
private:
// timer
wxTimer *m_timer;
DECLARE_EVENT_TABLE()
};
//============================================================================
// implementation
//============================================================================
IMPLEMENT_APP (App)
//----------------------------------------------------------------------------
// App
//----------------------------------------------------------------------------
bool App::OnInit () {
wxInitAllImageHandlers();
// set application and vendor name
SetAppName (APP_NAME);
SetVendorName (APP_VENDOR);
g_appname = new wxString ();
g_appname->Append (APP_NAME);
// initialize print data and setup
g_printData = new wxPrintData;
g_pageSetupData = new wxPageSetupDialogData;
// create application frame
m_frame = new AppFrame (*g_appname);
// open application frame
m_frame->Layout ();
m_frame->Show (true);
SetTopWindow (m_frame);
return true;
}
int App::OnExit () {
// delete global appname
if (g_appname) delete g_appname;
// delete global print data and setup
if (g_printData) delete g_printData;
if (g_pageSetupData) delete g_pageSetupData;
return 0;
}
//----------------------------------------------------------------------------
// AppFrame
//----------------------------------------------------------------------------
BEGIN_EVENT_TABLE (AppFrame, wxFrame)
// common
EVT_CLOSE ( AppFrame::OnClose)
// file
EVT_MENU (wxID_OPEN, AppFrame::OnFileOpen)
EVT_MENU (wxID_SAVE, AppFrame::OnFileSave)
EVT_MENU (wxID_SAVEAS, AppFrame::OnFileSaveAs)
EVT_MENU (wxID_CLOSE, AppFrame::OnFileClose)
// properties
EVT_MENU (myID_PROPERTIES, AppFrame::OnProperties)
// print and exit
EVT_MENU (wxID_PRINT_SETUP, AppFrame::OnPrintSetup)
EVT_MENU (wxID_PREVIEW, AppFrame::OnPrintPreview)
EVT_MENU (wxID_PRINT, AppFrame::OnPrint)
EVT_MENU (wxID_EXIT, AppFrame::OnExit)
// edit
EVT_MENU (wxID_CLEAR, AppFrame::OnEdit)
EVT_MENU (wxID_CUT, AppFrame::OnEdit)
EVT_MENU (wxID_COPY, AppFrame::OnEdit)
EVT_MENU (wxID_PASTE, AppFrame::OnEdit)
EVT_MENU (myID_INDENTINC, AppFrame::OnEdit)
EVT_MENU (myID_INDENTRED, AppFrame::OnEdit)
EVT_MENU (wxID_SELECTALL, AppFrame::OnEdit)
EVT_MENU (myID_SELECTLINE, AppFrame::OnEdit)
EVT_MENU (wxID_REDO, AppFrame::OnEdit)
EVT_MENU (wxID_UNDO, AppFrame::OnEdit)
// find
EVT_MENU (wxID_FIND, AppFrame::OnEdit)
EVT_MENU (myID_FINDNEXT, AppFrame::OnEdit)
EVT_MENU (myID_REPLACE, AppFrame::OnEdit)
EVT_MENU (myID_REPLACENEXT, AppFrame::OnEdit)
EVT_MENU (myID_BRACEMATCH, AppFrame::OnEdit)
EVT_MENU (myID_GOTO, AppFrame::OnEdit)
// view
EVT_MENU_RANGE (myID_HILIGHTFIRST, myID_HILIGHTLAST,
AppFrame::OnEdit)
EVT_MENU (myID_DISPLAYEOL, AppFrame::OnEdit)
EVT_MENU (myID_INDENTGUIDE, AppFrame::OnEdit)
EVT_MENU (myID_LINENUMBER, AppFrame::OnEdit)
EVT_MENU (myID_LONGLINEON, AppFrame::OnEdit)
EVT_MENU (myID_WHITESPACE, AppFrame::OnEdit)
EVT_MENU (myID_FOLDTOGGLE, AppFrame::OnEdit)
EVT_MENU (myID_OVERTYPE, AppFrame::OnEdit)
EVT_MENU (myID_READONLY, AppFrame::OnEdit)
EVT_MENU (myID_WRAPMODEON, AppFrame::OnEdit)
// extra
EVT_MENU (myID_CHANGELOWER, AppFrame::OnEdit)
EVT_MENU (myID_CHANGEUPPER, AppFrame::OnEdit)
EVT_MENU (myID_CONVERTCR, AppFrame::OnEdit)
EVT_MENU (myID_CONVERTCRLF, AppFrame::OnEdit)
EVT_MENU (myID_CONVERTLF, AppFrame::OnEdit)
EVT_MENU (myID_CHARSETANSI, AppFrame::OnEdit)
EVT_MENU (myID_CHARSETMAC, AppFrame::OnEdit)
// help
EVT_MENU (wxID_ABOUT, AppFrame::OnAbout)
END_EVENT_TABLE ()
AppFrame::AppFrame (const wxString &title)
: wxFrame ((wxFrame *)NULL, -1, title, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) {
// intitialize important variables
m_edit = NULL;
// set icon and background
SetTitle (*g_appname);
SetIcon (wxICON (mondrian));
SetBackgroundColour (_T("WHITE"));
// about box shown for 5 seconds
AppAbout (this, 5000);
// create menu
m_menuBar = new wxMenuBar;
CreateMenu ();
// open first page
m_edit = new Edit (this, -1);
m_edit->SetFocus();
}
AppFrame::~AppFrame () {
}
// common event handlers
void AppFrame::OnClose (wxCloseEvent &event) {
wxCommandEvent evt;
OnFileClose (evt);
if (m_edit && m_edit->Modified()) {
if (event.CanVeto()) event.Veto (true);
return;
}
Destroy();
}
void AppFrame::OnAbout (wxCommandEvent &WXUNUSED(event)) {
AppAbout (this);
}
void AppFrame::OnExit (wxCommandEvent &WXUNUSED(event)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -