📄 stctest.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// File: contrib/samples/stc/stctest.cpp// Purpose: STC test application// Maintainer: Otto Wyss// Created: 2003-09-01// RCS-ID: $Id: stctest.cpp,v 1.21 2006/05/28 23:31:30 VZ Exp $// Copyright: (c) wxGuide// 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' wxWidgets headers)#ifndef WX_PRECOMP #include "wx/wx.h"#endif//! wxWidgets 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("STC-Test")#define APP_DESCR _("See http://wxguide.sourceforge.net/")#define APP_MAINT _T("Otto Wyss")#define APP_VENDOR _T("wxWidgets")#define APP_COPYRIGTH _T("(C) 2003 Otto Wyss")#define APP_LICENCE _T("wxWidgets")#define APP_VERSION _T("0.1.alpha")#define APP_BUILD __DATE__#define APP_WEBSITE _T("http://www.wxWidgets.org")#define APP_MAIL _T("mailto://???")#define NONAME _("<untitled>")class AppBook;//----------------------------------------------------------------------------//! global application namewxString *g_appname = NULL;#if wxUSE_PRINTING_ARCHITECTURE//! global print data, to remember settings during the sessionwxPrintData *g_printData = (wxPrintData*) NULL;wxPageSetupData *g_pageSetupData = (wxPageSetupData*) NULL;#endif // wxUSE_PRINTING_ARCHITECTUREclass AppFrame;//----------------------------------------------------------------------------//! 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 wxWidgetsDECLARE_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_NAMEclass 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_VENDOR); g_appname->Append (_T("-")); g_appname->Append (APP_NAME);#if wxUSE_PRINTING_ARCHITECTURE // initialize print data and setup g_printData = new wxPrintData; g_pageSetupData = new wxPageSetupDialogData;#endif // wxUSE_PRINTING_ARCHITECTURE // 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 delete g_appname;#if wxUSE_PRINTING_ARCHITECTURE // delete global print data and setup if (g_printData) delete g_printData; if (g_pageSetupData) delete g_pageSetupData;#endif // wxUSE_PRINTING_ARCHITECTURE 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, wxID_ANY, title, wxDefaultPosition, wxSize(750,550), 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 1 seconds AppAbout dlg(this, 1000); // create menu m_menuBar = new wxMenuBar; CreateMenu (); // open first page m_edit = new Edit (this, wxID_ANY); m_edit->SetFocus(); FileOpen (_T("stctest.cpp"));}AppFrame::~AppFrame () {}// common event handlersvoid 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 dlg(this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -