2003-09-18 05:05:52 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2006-02-10 11:59:52 +00:00
|
|
|
// File: contrib/samples/stc/stctest.cpp
|
2003-09-18 05:05:52 +00:00
|
|
|
// Purpose: STC test application
|
|
|
|
// Maintainer: Otto Wyss
|
|
|
|
// Created: 2003-09-01
|
2000-03-09 19:42:06 +00:00
|
|
|
// RCS-ID: $Id$
|
2003-09-18 05:05:52 +00:00
|
|
|
// Copyright: (c) wxGuide
|
2000-03-09 19:42:06 +00:00
|
|
|
// Licence: wxWindows licence
|
2003-09-18 05:05:52 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
//----------------------------------------------------------------------------
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2006-02-10 11:59:52 +00:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
2005-09-16 18:25:44 +00:00
|
|
|
#include "wx/wxprec.h"
|
2000-03-09 19:42:06 +00:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
2004-05-25 11:20:37 +00:00
|
|
|
// need because it includes almost all 'standard' wxWidgets headers)
|
2000-03-09 19:42:06 +00:00
|
|
|
#ifndef WX_PRECOMP
|
2005-08-23 16:02:51 +00:00
|
|
|
#include "wx/wx.h"
|
2000-03-09 19:42:06 +00:00
|
|
|
#endif
|
|
|
|
|
2004-05-25 11:20:37 +00:00
|
|
|
//! wxWidgets headers
|
2005-08-23 16:02:51 +00:00
|
|
|
#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
|
2003-09-18 05:05:52 +00:00
|
|
|
|
|
|
|
//! application headers
|
|
|
|
#include "defsext.h" // Additional definitions
|
|
|
|
#include "edit.h" // Edit module
|
|
|
|
#include "prefs.h" // Prefs
|
|
|
|
|
2009-02-08 01:01:00 +00:00
|
|
|
#ifndef __WXMSW__
|
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
2003-09-18 05:05:52 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// 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
|
|
|
|
//============================================================================
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
#define APP_NAME wxT("STC-Test")
|
2003-09-19 18:40:13 +00:00
|
|
|
#define APP_DESCR _("See http://wxguide.sourceforge.net/")
|
2003-09-18 05:05:52 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
#define APP_MAINT wxT("Otto Wyss")
|
|
|
|
#define APP_VENDOR wxT("wxWidgets")
|
|
|
|
#define APP_COPYRIGTH wxT("(C) 2003 Otto Wyss")
|
|
|
|
#define APP_LICENCE wxT("wxWidgets")
|
2003-09-18 05:05:52 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
#define APP_VERSION wxT("0.1.alpha")
|
2003-09-18 05:05:52 +00:00
|
|
|
#define APP_BUILD __DATE__
|
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
#define APP_WEBSITE wxT("http://www.wxWidgets.org")
|
|
|
|
#define APP_MAIL wxT("mailto://???")
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
#define NONAME _("<untitled>")
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
class AppBook;
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//! global application name
|
|
|
|
wxString *g_appname = NULL;
|
|
|
|
|
2005-08-23 16:02:51 +00:00
|
|
|
#if wxUSE_PRINTING_ARCHITECTURE
|
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
//! global print data, to remember settings during the session
|
|
|
|
wxPrintData *g_printData = (wxPrintData*) NULL;
|
|
|
|
wxPageSetupData *g_pageSetupData = (wxPageSetupData*) NULL;
|
|
|
|
|
2005-08-23 16:02:51 +00:00
|
|
|
#endif // wxUSE_PRINTING_ARCHITECTURE
|
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
|
2006-04-26 16:27:16 +00:00
|
|
|
class AppFrame;
|
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//! application APP_VENDOR-APP_NAME.
|
|
|
|
class App: public wxApp {
|
|
|
|
friend class AppFrame;
|
2000-03-09 19:42:06 +00:00
|
|
|
|
|
|
|
public:
|
2003-09-18 05:05:52 +00:00
|
|
|
//! the main function called durning application start
|
|
|
|
virtual bool OnInit ();
|
|
|
|
|
|
|
|
//! application exit function
|
|
|
|
virtual int OnExit ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
//! frame window
|
|
|
|
AppFrame* m_frame;
|
|
|
|
|
2009-09-24 13:08:48 +00:00
|
|
|
wxFrame* MinimalEditor();
|
|
|
|
protected:
|
|
|
|
void OnMinimalEditor(wxCommandEvent&);
|
|
|
|
DECLARE_EVENT_TABLE()
|
2000-03-09 19:42:06 +00:00
|
|
|
};
|
|
|
|
|
2004-05-25 11:20:37 +00:00
|
|
|
// created dynamically by wxWidgets
|
2003-09-18 05:05:52 +00:00
|
|
|
DECLARE_APP (App);
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//! frame of the application APP_VENDOR-APP_NAME.
|
|
|
|
class AppFrame: public wxFrame {
|
|
|
|
friend class App;
|
|
|
|
friend class AppBook;
|
|
|
|
friend class AppAbout;
|
2003-04-19 20:00:02 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
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);
|
2003-04-19 20:00:02 +00:00
|
|
|
|
|
|
|
private:
|
2003-09-18 05:05:52 +00:00
|
|
|
// 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 ();
|
|
|
|
|
2003-04-19 20:00:02 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//! about box of the application APP_VENDOR-APP_NAME
|
|
|
|
class AppAbout: public wxDialog {
|
2003-04-19 20:00:02 +00:00
|
|
|
|
2000-03-09 19:42:06 +00:00
|
|
|
public:
|
2003-09-18 05:05:52 +00:00
|
|
|
//! constructor
|
|
|
|
AppAbout (wxWindow *parent,
|
|
|
|
int milliseconds = 0,
|
|
|
|
long style = 0);
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
~AppAbout ();
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
// event handlers
|
|
|
|
void OnTimerEvent (wxTimerEvent &event);
|
2000-03-09 19:42:06 +00:00
|
|
|
|
|
|
|
private:
|
2003-09-18 05:05:52 +00:00
|
|
|
// timer
|
|
|
|
wxTimer *m_timer;
|
2000-03-09 19:42:06 +00:00
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
//============================================================================
|
|
|
|
// implementation
|
|
|
|
//============================================================================
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
IMPLEMENT_APP (App)
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2009-09-24 13:08:48 +00:00
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(App, wxApp)
|
|
|
|
EVT_MENU(myID_WINDOW_MINIMAL, App::OnMinimalEditor)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// App
|
|
|
|
//----------------------------------------------------------------------------
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
bool App::OnInit () {
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
wxInitAllImageHandlers();
|
2003-10-11 01:20:24 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
// set application and vendor name
|
|
|
|
SetAppName (APP_NAME);
|
|
|
|
SetVendorName (APP_VENDOR);
|
|
|
|
g_appname = new wxString ();
|
|
|
|
g_appname->Append (APP_VENDOR);
|
2009-07-23 20:30:22 +00:00
|
|
|
g_appname->Append (wxT("-"));
|
2003-09-18 05:05:52 +00:00
|
|
|
g_appname->Append (APP_NAME);
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2005-08-23 16:02:51 +00:00
|
|
|
#if wxUSE_PRINTING_ARCHITECTURE
|
2003-09-18 05:05:52 +00:00
|
|
|
// initialize print data and setup
|
|
|
|
g_printData = new wxPrintData;
|
|
|
|
g_pageSetupData = new wxPageSetupDialogData;
|
2005-08-23 16:02:51 +00:00
|
|
|
#endif // wxUSE_PRINTING_ARCHITECTURE
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
// create application frame
|
|
|
|
m_frame = new AppFrame (*g_appname);
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
// open application frame
|
|
|
|
m_frame->Layout ();
|
|
|
|
m_frame->Show (true);
|
|
|
|
SetTopWindow (m_frame);
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
int App::OnExit () {
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
// delete global appname
|
|
|
|
delete g_appname;
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2005-08-23 16:02:51 +00:00
|
|
|
#if wxUSE_PRINTING_ARCHITECTURE
|
2003-09-18 05:05:52 +00:00
|
|
|
// delete global print data and setup
|
|
|
|
if (g_printData) delete g_printData;
|
|
|
|
if (g_pageSetupData) delete g_pageSetupData;
|
2005-08-23 16:02:51 +00:00
|
|
|
#endif // wxUSE_PRINTING_ARCHITECTURE
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// 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)
|
2004-09-28 15:13:27 +00:00
|
|
|
: wxFrame ((wxFrame *)NULL, wxID_ANY, title, wxDefaultPosition, wxSize(750,550),
|
2009-02-08 01:01:00 +00:00
|
|
|
wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
|
|
|
|
{
|
|
|
|
SetIcon(wxICON(sample));
|
2003-09-18 05:05:52 +00:00
|
|
|
|
|
|
|
// intitialize important variables
|
|
|
|
m_edit = NULL;
|
|
|
|
|
|
|
|
// set icon and background
|
|
|
|
SetTitle (*g_appname);
|
|
|
|
SetIcon (wxICON (mondrian));
|
2009-07-23 20:30:22 +00:00
|
|
|
SetBackgroundColour (wxT("WHITE"));
|
2003-09-18 05:05:52 +00:00
|
|
|
|
|
|
|
// about box shown for 1 seconds
|
2004-12-08 17:12:53 +00:00
|
|
|
AppAbout dlg(this, 1000);
|
2003-09-18 05:05:52 +00:00
|
|
|
|
|
|
|
// create menu
|
|
|
|
m_menuBar = new wxMenuBar;
|
|
|
|
CreateMenu ();
|
|
|
|
|
|
|
|
// open first page
|
2004-09-28 15:13:27 +00:00
|
|
|
m_edit = new Edit (this, wxID_ANY);
|
2003-09-18 05:05:52 +00:00
|
|
|
m_edit->SetFocus();
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2009-07-23 20:30:22 +00:00
|
|
|
FileOpen (wxT("stctest.cpp"));
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
AppFrame::~AppFrame () {
|
|
|
|
}
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
// 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();
|
2003-04-19 20:00:02 +00:00
|
|
|
}
|
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
void AppFrame::OnAbout (wxCommandEvent &WXUNUSED(event)) {
|
2004-12-08 17:12:53 +00:00
|
|
|
AppAbout dlg(this);
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
2003-04-19 20:00:02 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
void AppFrame::OnExit (wxCommandEvent &WXUNUSED(event)) {
|
|
|
|
Close (true);
|
|
|
|
}
|
2003-04-19 20:00:02 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
// file event handlers
|
|
|
|
void AppFrame::OnFileOpen (wxCommandEvent &WXUNUSED(event)) {
|
|
|
|
if (!m_edit) return;
|
2005-08-23 16:02:51 +00:00
|
|
|
#if wxUSE_FILEDLG
|
2003-09-18 05:05:52 +00:00
|
|
|
wxString fname;
|
2009-07-23 20:30:22 +00:00
|
|
|
wxFileDialog dlg (this, wxT("Open file"), wxEmptyString, wxEmptyString, wxT("Any file (*)|*"),
|
2006-05-28 23:32:12 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR);
|
2003-09-18 05:05:52 +00:00
|
|
|
if (dlg.ShowModal() != wxID_OK) return;
|
|
|
|
fname = dlg.GetPath ();
|
|
|
|
FileOpen (fname);
|
2005-08-23 16:02:51 +00:00
|
|
|
#endif // wxUSE_FILEDLG
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppFrame::OnFileSave (wxCommandEvent &WXUNUSED(event)) {
|
|
|
|
if (!m_edit) return;
|
|
|
|
if (!m_edit->Modified()) {
|
|
|
|
wxMessageBox (_("There is nothing to save!"), _("Save file"),
|
|
|
|
wxOK | wxICON_EXCLAMATION);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_edit->SaveFile ();
|
|
|
|
}
|
2000-03-09 19:42:06 +00:00
|
|
|
|
2003-09-18 05:05:52 +00:00
|
|
|
void AppFrame::OnFileSaveAs (wxCommandEvent &WXUNUSED(event)) {
|
|
|
|
if (!m_edit) return;
|
2005-08-23 16:02:51 +00:00
|
|
|
#if wxUSE_FILEDLG
|
2003-09-18 05:05:52 +00:00
|
|
|
wxString filename = wxEmptyString;
|
2009-07-23 20:30:22 +00:00
|
|
|
wxFileDialog dlg (this, wxT("Save file"), wxEmptyString, wxEmptyString, wxT("Any file (*)|*"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
|
2003-09-18 05:05:52 +00:00
|
|
|
if (dlg.ShowModal() != wxID_OK) return;
|
|
|
|
filename = dlg.GetPath();
|
|
|
|
m_edit->SaveFile (filename);
|
2005-08-23 16:02:51 +00:00
|
|
|
#endif // wxUSE_FILEDLG
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppFrame::OnFileClose (wxCommandEvent &WXUNUSED(event)) {
|
|
|
|
if (!m_edit) return;
|
|
|
|
if (m_edit->Modified()) {
|
|
|
|
if (wxMessageBox (_("Text is not saved, save before closing?"), _("Close"),
|
|
|
|
wxYES_NO | wxICON_QUESTION) == wxYES) {
|
|
|
|
m_edit->SaveFile();
|
|
|
|
if (m_edit->Modified()) {
|
|
|
|
wxMessageBox (_("Text could not be saved!"), _("Close abort"),
|
|
|
|
wxOK | wxICON_EXCLAMATION);
|
|
|
|
return;
|
|
|
|
}
|
2003-04-19 20:00:02 +00:00
|
|
|
}
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
2003-10-11 01:20:24 +00:00
|
|
|
m_edit->SetFilename (wxEmptyString);
|
|
|
|
m_edit->ClearAll();
|
|
|
|
m_edit->SetSavePoint();
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// properties event handlers
|
|
|
|
void AppFrame::OnProperties (wxCommandEvent &WXUNUSED(event)) {
|
|
|
|
if (!m_edit) return;
|
2004-12-08 17:12:53 +00:00
|
|
|
EditProperties dlg(m_edit, 0);
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// print event handlers
|
|
|
|
void AppFrame::OnPrintSetup (wxCommandEvent &WXUNUSED(event)) {
|
2005-08-23 16:02:51 +00:00
|
|
|
#if wxUSE_PRINTING_ARCHITECTURE
|
2003-09-18 05:05:52 +00:00
|
|
|
(*g_pageSetupData) = * g_printData;
|
|
|
|
wxPageSetupDialog pageSetupDialog(this, g_pageSetupData);
|
|
|
|
pageSetupDialog.ShowModal();
|
|
|
|
(*g_printData) = pageSetupDialog.GetPageSetupData().GetPrintData();
|
|
|
|
(*g_pageSetupData) = pageSetupDialog.GetPageSetupData();
|
2005-08-23 16:02:51 +00:00
|
|
|
#endif // wxUSE_PRINTING_ARCHITECTURE
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppFrame::OnPrintPreview (wxCommandEvent &WXUNUSED(event)) {
|
2005-08-23 16:02:51 +00:00
|
|
|
#if wxUSE_PRINTING_ARCHITECTURE
|
2003-09-18 05:05:52 +00:00
|
|
|
wxPrintDialogData printDialogData( *g_printData);
|
|
|
|
wxPrintPreview *preview =
|
|
|
|
new wxPrintPreview (new EditPrint (m_edit),
|
|
|
|
new EditPrint (m_edit),
|
|
|
|
&printDialogData);
|
|
|
|
if (!preview->Ok()) {
|
|
|
|
delete preview;
|
|
|
|
wxMessageBox (_("There was a problem with previewing.\n\
|
|
|
|
Perhaps your current printer is not correctly?"),
|
|
|
|
_("Previewing"), wxOK);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wxRect rect = DeterminePrintSize();
|
|
|
|
wxPreviewFrame *frame = new wxPreviewFrame (preview, this, _("Print Preview"));
|
|
|
|
frame->SetSize (rect);
|
|
|
|
frame->Centre(wxBOTH);
|
|
|
|
frame->Initialize();
|
|
|
|
frame->Show(true);
|
2005-08-23 16:02:51 +00:00
|
|
|
#endif // wxUSE_PRINTING_ARCHITECTURE
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppFrame::OnPrint (wxCommandEvent &WXUNUSED(event)) {
|
2005-08-23 16:02:51 +00:00
|
|
|
#if wxUSE_PRINTING_ARCHITECTURE
|
2003-09-18 05:05:52 +00:00
|
|
|
wxPrintDialogData printDialogData( *g_printData);
|
|
|
|
wxPrinter printer (&printDialogData);
|
|
|
|
EditPrint printout (m_edit);
|
|
|
|
if (!printer.Print (this, &printout, true)) {
|
|
|
|
if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {
|
|
|
|
wxMessageBox (_("There was a problem with printing.\n\
|
|
|
|
Perhaps your current printer is not correctly?"),
|
|
|
|
_("Previewing"), wxOK);
|
|
|
|
return;
|
2003-04-19 20:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-18 05:05:52 +00:00
|
|
|
(*g_printData) = printer.GetPrintDialogData().GetPrintData();
|
2005-08-23 16:02:51 +00:00
|
|
|
#endif // wxUSE_PRINTING_ARCHITECTURE
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// edit events
|
|
|
|
void AppFrame::OnEdit (wxCommandEvent &event) {
|
2009-01-25 11:58:39 +00:00
|
|
|
if (m_edit) m_edit->GetEventHandler()->ProcessEvent (event);
|
2003-09-18 05:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// private functions
|
2005-08-23 16:02:51 +00:00
|
|
|
void AppFrame::CreateMenu ()
|
|
|
|
{
|
2003-09-18 05:05:52 +00:00
|
|
|
// File menu
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
|
|
|
menuFile->Append (wxID_OPEN, _("&Open ..\tCtrl+O"));
|
|
|
|
menuFile->Append (wxID_SAVE, _("&Save\tCtrl+S"));
|
|
|
|
menuFile->Append (wxID_SAVEAS, _("Save &as ..\tCtrl+Shift+S"));
|
|
|
|
menuFile->Append (wxID_CLOSE, _("&Close\tCtrl+W"));
|
|
|
|
menuFile->AppendSeparator();
|
|
|
|
menuFile->Append (myID_PROPERTIES, _("Proper&ties ..\tCtrl+I"));
|
|
|
|
menuFile->AppendSeparator();
|
|
|
|
menuFile->Append (wxID_PRINT_SETUP, _("Print Set&up .."));
|
|
|
|
menuFile->Append (wxID_PREVIEW, _("Print Pre&view\tCtrl+Shift+P"));
|
|
|
|
menuFile->Append (wxID_PRINT, _("&Print ..\tCtrl+P"));
|
|
|
|
menuFile->AppendSeparator();
|
|
|
|
menuFile->Append (wxID_EXIT, _("&Quit\tCtrl+Q"));
|
|
|
|
|
|
|
|
// Edit menu
|
|
|
|
wxMenu *menuEdit = new wxMenu;
|
|
|
|
menuEdit->Append (wxID_UNDO, _("&Undo\tCtrl+Z"));
|
|
|
|
menuEdit->Append (wxID_REDO, _("&Redo\tCtrl+Shift+Z"));
|
|
|
|
menuEdit->AppendSeparator();
|
|
|
|
menuEdit->Append (wxID_CUT, _("Cu&t\tCtrl+X"));
|
|
|
|
menuEdit->Append (wxID_COPY, _("&Copy\tCtrl+C"));
|
|
|
|
menuEdit->Append (wxID_PASTE, _("&Paste\tCtrl+V"));
|
|
|
|
menuEdit->Append (wxID_CLEAR, _("&Delete\tDel"));
|
|
|
|
menuEdit->AppendSeparator();
|
|
|
|
menuEdit->Append (wxID_FIND, _("&Find\tCtrl+F"));
|
|
|
|
menuEdit->Enable (wxID_FIND, false);
|
|
|
|
menuEdit->Append (myID_FINDNEXT, _("Find &next\tF3"));
|
|
|
|
menuEdit->Enable (myID_FINDNEXT, false);
|
|
|
|
menuEdit->Append (myID_REPLACE, _("&Replace\tCtrl+H"));
|
|
|
|
menuEdit->Enable (myID_REPLACE, false);
|
|
|
|
menuEdit->Append (myID_REPLACENEXT, _("Replace &again\tShift+F4"));
|
|
|
|
menuEdit->Enable (myID_REPLACENEXT, false);
|
|
|
|
menuEdit->AppendSeparator();
|
|
|
|
menuEdit->Append (myID_BRACEMATCH, _("&Match brace\tCtrl+M"));
|
|
|
|
menuEdit->Append (myID_GOTO, _("&Goto\tCtrl+G"));
|
|
|
|
menuEdit->Enable (myID_GOTO, false);
|
|
|
|
menuEdit->AppendSeparator();
|
|
|
|
menuEdit->Append (myID_INDENTINC, _("&Indent increase\tTab"));
|
2008-12-27 14:21:35 +00:00
|
|
|
menuEdit->Append (myID_INDENTRED, _("I&ndent reduce\tShift+Tab"));
|
2003-09-18 05:05:52 +00:00
|
|
|
menuEdit->AppendSeparator();
|
|
|
|
menuEdit->Append (wxID_SELECTALL, _("&Select all\tCtrl+A"));
|
|
|
|
menuEdit->Append (myID_SELECTLINE, _("Select &line\tCtrl+L"));
|
|
|
|
|
|
|
|
// hilight submenu
|
|
|
|
wxMenu *menuHilight = new wxMenu;
|
|
|
|
int Nr;
|
|
|
|
for (Nr = 0; Nr < g_LanguagePrefsSize; Nr++) {
|
|
|
|
menuHilight->Append (myID_HILIGHTFIRST + Nr,
|
|
|
|
g_LanguagePrefs [Nr].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// charset submenu
|
|
|
|
wxMenu *menuCharset = new wxMenu;
|
|
|
|
menuCharset->Append (myID_CHARSETANSI, _("&ANSI (Windows)"));
|
|
|
|
menuCharset->Append (myID_CHARSETMAC, _("&MAC (Macintosh)"));
|
|
|
|
|
|
|
|
// View menu
|
|
|
|
wxMenu *menuView = new wxMenu;
|
|
|
|
menuView->Append (myID_HILIGHTLANG, _("&Hilight language .."), menuHilight);
|
|
|
|
menuView->AppendSeparator();
|
|
|
|
menuView->AppendCheckItem (myID_FOLDTOGGLE, _("&Toggle current fold\tCtrl+T"));
|
|
|
|
menuView->AppendCheckItem (myID_OVERTYPE, _("&Overwrite mode\tIns"));
|
|
|
|
menuView->AppendCheckItem (myID_WRAPMODEON, _("&Wrap mode\tCtrl+U"));
|
|
|
|
menuView->AppendSeparator();
|
|
|
|
menuView->AppendCheckItem (myID_DISPLAYEOL, _("Show line &endings"));
|
|
|
|
menuView->AppendCheckItem (myID_INDENTGUIDE, _("Show &indent guides"));
|
|
|
|
menuView->AppendCheckItem (myID_LINENUMBER, _("Show line &numbers"));
|
|
|
|
menuView->AppendCheckItem (myID_LONGLINEON, _("Show &long line marker"));
|
|
|
|
menuView->AppendCheckItem (myID_WHITESPACE, _("Show white&space"));
|
|
|
|
menuView->AppendSeparator();
|
|
|
|
menuView->Append (myID_USECHARSET, _("Use &code page of .."), menuCharset);
|
|
|
|
|
|
|
|
// change case submenu
|
|
|
|
wxMenu *menuChangeCase = new wxMenu;
|
|
|
|
menuChangeCase->Append (myID_CHANGEUPPER, _("&Upper case"));
|
|
|
|
menuChangeCase->Append (myID_CHANGELOWER, _("&Lower case"));
|
|
|
|
|
|
|
|
// convert EOL submenu
|
|
|
|
wxMenu *menuConvertEOL = new wxMenu;
|
|
|
|
menuConvertEOL->Append (myID_CONVERTCR, _("CR (&Linux)"));
|
|
|
|
menuConvertEOL->Append (myID_CONVERTCRLF, _("CR+LF (&Windows)"));
|
|
|
|
menuConvertEOL->Append (myID_CONVERTLF, _("LF (&Macintosh)"));
|
|
|
|
|
|
|
|
// Extra menu
|
|
|
|
wxMenu *menuExtra = new wxMenu;
|
|
|
|
menuExtra->AppendCheckItem (myID_READONLY, _("&Readonly mode"));
|
|
|
|
menuExtra->AppendSeparator();
|
|
|
|
menuExtra->Append (myID_CHANGECASE, _("Change &case to .."), menuChangeCase);
|
|
|
|
menuExtra->AppendSeparator();
|
|
|
|
menuExtra->Append (myID_CONVERTEOL, _("Convert line &endings to .."), menuConvertEOL);
|
|
|
|
|
|
|
|
// Window menu
|
|
|
|
wxMenu *menuWindow = new wxMenu;
|
|
|
|
menuWindow->Append (myID_PAGEPREV, _("&Previous\tCtrl+Shift+Tab"));
|
|
|
|
menuWindow->Append (myID_PAGENEXT, _("&Next\tCtrl+Tab"));
|
2009-09-24 13:08:48 +00:00
|
|
|
menuWindow->Append(myID_WINDOW_MINIMAL, _("&Minimal editor"));
|
2003-09-18 05:05:52 +00:00
|
|
|
|
|
|
|
// Help menu
|
|
|
|
wxMenu *menuHelp = new wxMenu;
|
|
|
|
menuHelp->Append (wxID_ABOUT, _("&About ..\tShift+F1"));
|
|
|
|
|
|
|
|
// construct menu
|
|
|
|
m_menuBar->Append (menuFile, _("&File"));
|
|
|
|
m_menuBar->Append (menuEdit, _("&Edit"));
|
|
|
|
m_menuBar->Append (menuView, _("&View"));
|
|
|
|
m_menuBar->Append (menuExtra, _("E&xtra"));
|
|
|
|
m_menuBar->Append (menuWindow, _("&Window"));
|
|
|
|
m_menuBar->Append (menuHelp, _("&Help"));
|
|
|
|
SetMenuBar (m_menuBar);
|
|
|
|
}
|
|
|
|
|
2005-08-23 16:02:51 +00:00
|
|
|
void AppFrame::FileOpen (wxString fname)
|
|
|
|
{
|
2003-09-18 05:05:52 +00:00
|
|
|
wxFileName w(fname); w.Normalize(); fname = w.GetFullPath();
|
|
|
|
m_edit->LoadFile (fname);
|
2000-03-09 19:42:06 +00:00
|
|
|
}
|
2003-09-18 05:05:52 +00:00
|
|
|
|
|
|
|
wxRect AppFrame::DeterminePrintSize () {
|
|
|
|
|
|
|
|
wxSize scr = wxGetDisplaySize();
|
|
|
|
|
|
|
|
// determine position and size (shifting 16 left and down)
|
|
|
|
wxRect rect = GetRect();
|
|
|
|
rect.x += 16;
|
|
|
|
rect.y += 16;
|
|
|
|
rect.width = wxMin (rect.width, (scr.x - rect.x));
|
|
|
|
rect.height = wxMin (rect.height, (scr.x - rect.y));
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// AppAbout
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE (AppAbout, wxDialog)
|
|
|
|
EVT_TIMER (myID_ABOUTTIMER, AppAbout::OnTimerEvent)
|
|
|
|
END_EVENT_TABLE ()
|
|
|
|
|
|
|
|
AppAbout::AppAbout (wxWindow *parent,
|
|
|
|
int milliseconds,
|
|
|
|
long style)
|
2004-09-28 15:13:27 +00:00
|
|
|
: wxDialog (parent, wxID_ANY, wxEmptyString,
|
2003-09-18 05:05:52 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2003-09-18 17:35:31 +00:00
|
|
|
style | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
|
2003-09-18 05:05:52 +00:00
|
|
|
|
|
|
|
// set timer if any
|
|
|
|
m_timer = NULL;
|
|
|
|
if (milliseconds > 0) {
|
|
|
|
m_timer = new wxTimer (this, myID_ABOUTTIMER);
|
|
|
|
m_timer->Start (milliseconds, wxTIMER_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
// sets the application title
|
|
|
|
SetTitle (_("About .."));
|
|
|
|
|
|
|
|
// about info
|
|
|
|
wxGridSizer *aboutinfo = new wxGridSizer (2, 0, 2);
|
2004-09-28 15:13:27 +00:00
|
|
|
aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Written by: ")),
|
2003-09-18 05:05:52 +00:00
|
|
|
0, wxALIGN_LEFT);
|
2004-09-28 15:13:27 +00:00
|
|
|
aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_MAINT),
|
2003-09-18 05:05:52 +00:00
|
|
|
1, wxEXPAND | wxALIGN_LEFT);
|
2004-09-28 15:13:27 +00:00
|
|
|
aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Version: ")),
|
2003-09-18 05:05:52 +00:00
|
|
|
0, wxALIGN_LEFT);
|
2004-09-28 15:13:27 +00:00
|
|
|
aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_VERSION),
|
2003-09-18 05:05:52 +00:00
|
|
|
1, wxEXPAND | wxALIGN_LEFT);
|
2004-09-28 15:13:27 +00:00
|
|
|
aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Licence type: ")),
|
2003-09-18 05:05:52 +00:00
|
|
|
0, wxALIGN_LEFT);
|
2004-09-28 15:13:27 +00:00
|
|
|
aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_LICENCE),
|
2003-09-18 05:05:52 +00:00
|
|
|
1, wxEXPAND | wxALIGN_LEFT);
|
2004-09-28 15:13:27 +00:00
|
|
|
aboutinfo->Add (new wxStaticText(this, wxID_ANY, _("Copyright: ")),
|
2003-09-18 05:05:52 +00:00
|
|
|
0, wxALIGN_LEFT);
|
2004-09-28 15:13:27 +00:00
|
|
|
aboutinfo->Add (new wxStaticText(this, wxID_ANY, APP_COPYRIGTH),
|
2003-09-18 05:05:52 +00:00
|
|
|
1, wxEXPAND | wxALIGN_LEFT);
|
|
|
|
|
|
|
|
// about icontitle//info
|
|
|
|
wxBoxSizer *aboutpane = new wxBoxSizer (wxHORIZONTAL);
|
|
|
|
wxBitmap bitmap = wxBitmap(wxICON (mondrian));
|
2004-09-28 15:13:27 +00:00
|
|
|
aboutpane->Add (new wxStaticBitmap (this, wxID_ANY, bitmap),
|
2003-09-18 05:05:52 +00:00
|
|
|
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 20);
|
|
|
|
aboutpane->Add (aboutinfo, 1, wxEXPAND);
|
|
|
|
aboutpane->Add (60, 0);
|
|
|
|
|
|
|
|
// about complete
|
|
|
|
wxBoxSizer *totalpane = new wxBoxSizer (wxVERTICAL);
|
|
|
|
totalpane->Add (0, 20);
|
2004-09-28 15:13:27 +00:00
|
|
|
wxStaticText *appname = new wxStaticText(this, wxID_ANY, *g_appname);
|
2003-09-18 05:05:52 +00:00
|
|
|
appname->SetFont (wxFont (24, wxDEFAULT, wxNORMAL, wxBOLD));
|
|
|
|
totalpane->Add (appname, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 40);
|
|
|
|
totalpane->Add (0, 10);
|
|
|
|
totalpane->Add (aboutpane, 0, wxEXPAND | wxALL, 4);
|
2004-09-28 15:13:27 +00:00
|
|
|
totalpane->Add (new wxStaticText(this, wxID_ANY, APP_DESCR),
|
2003-09-18 05:05:52 +00:00
|
|
|
0, wxALIGN_CENTER | wxALL, 10);
|
|
|
|
wxButton *okButton = new wxButton (this, wxID_OK, _("OK"));
|
|
|
|
okButton->SetDefault();
|
|
|
|
totalpane->Add (okButton, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT | wxBOTTOM, 10);
|
|
|
|
|
|
|
|
SetSizerAndFit (totalpane);
|
|
|
|
|
2003-10-11 01:20:24 +00:00
|
|
|
CenterOnScreen();
|
2003-09-18 05:05:52 +00:00
|
|
|
ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
AppAbout::~AppAbout () {
|
|
|
|
if (m_timer) {
|
|
|
|
delete m_timer;
|
|
|
|
m_timer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// event handlers
|
2003-09-18 17:35:31 +00:00
|
|
|
void AppAbout::OnTimerEvent (wxTimerEvent &WXUNUSED(event)) {
|
2003-09-18 05:05:52 +00:00
|
|
|
if (m_timer) delete m_timer;
|
|
|
|
m_timer = NULL;
|
|
|
|
EndModal (wxID_OK);
|
|
|
|
}
|
2009-09-24 13:08:48 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Minimal editor added by Troels K 2008-04-08
|
|
|
|
// Thanks to geralds for SetLexerXml() - http://wxforum.shadonet.com/viewtopic.php?t=7155
|
|
|
|
|
|
|
|
class MinimalEditor : public wxStyledTextCtrl
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
margin_id_lineno,
|
|
|
|
margin_id_fold,
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
MinimalEditor(wxWindow* parent, wxWindowID id = wxID_ANY) : wxStyledTextCtrl(parent, id)
|
|
|
|
{
|
|
|
|
SetLexerXml();
|
|
|
|
|
|
|
|
SetProperty(wxT("fold"), wxT("1"));
|
|
|
|
SetProperty(wxT("fold.comment"), wxT("1"));
|
|
|
|
SetProperty(wxT("fold.compact"), wxT("1"));
|
|
|
|
SetProperty(wxT("fold.preprocessor"), wxT("1"));
|
|
|
|
SetProperty(wxT("fold.html"), wxT("1"));
|
|
|
|
SetProperty(wxT("fold.html.preprocessor"), wxT("1"));
|
|
|
|
|
|
|
|
SetMarginType(margin_id_lineno, wxSTC_MARGIN_NUMBER);
|
|
|
|
SetMarginWidth(margin_id_lineno, 32);
|
|
|
|
|
|
|
|
MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS, wxT("WHITE"), wxT("BLACK"));
|
|
|
|
MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS, wxT("WHITE"), wxT("BLACK"));
|
|
|
|
MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, wxT("WHITE"), wxT("BLACK"));
|
|
|
|
MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_BOXPLUSCONNECTED, wxT("WHITE"), wxT("BLACK"));
|
|
|
|
MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BOXMINUSCONNECTED, wxT("WHITE"), wxT("BLACK"));
|
|
|
|
MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, wxT("WHITE"), wxT("BLACK"));
|
|
|
|
MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, wxT("WHITE"), wxT("BLACK"));
|
|
|
|
|
|
|
|
SetMarginMask(margin_id_fold, wxSTC_MASK_FOLDERS);
|
|
|
|
SetMarginWidth(margin_id_fold, 32);
|
|
|
|
SetMarginSensitive(margin_id_fold, true);
|
|
|
|
|
|
|
|
SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
|
|
|
|
|
|
|
|
SetTabWidth(4);
|
|
|
|
SetUseTabs(false);
|
|
|
|
SetWrapMode(wxSTC_WRAP_WORD);
|
|
|
|
SetWrapVisualFlags(wxSTC_WRAPVISUALFLAG_END);
|
|
|
|
}
|
|
|
|
virtual bool SetFont(const wxFont& font)
|
|
|
|
{
|
|
|
|
StyleSetFont(wxSTC_STYLE_DEFAULT, (wxFont&)font);
|
|
|
|
return wxStyledTextCtrl::SetFont(font);
|
|
|
|
}
|
|
|
|
void SetLexerXml()
|
|
|
|
{
|
|
|
|
SetLexer(wxSTC_LEX_XML);
|
|
|
|
StyleSetForeground(wxSTC_H_DEFAULT, *wxBLACK);
|
|
|
|
StyleSetForeground(wxSTC_H_TAG, *wxBLUE);
|
|
|
|
StyleSetForeground(wxSTC_H_TAGUNKNOWN, *wxBLUE);
|
|
|
|
StyleSetForeground(wxSTC_H_ATTRIBUTE, *wxRED);
|
|
|
|
StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN, *wxRED);
|
|
|
|
StyleSetBold(wxSTC_H_ATTRIBUTEUNKNOWN, true);
|
|
|
|
StyleSetForeground(wxSTC_H_NUMBER, *wxBLACK);
|
|
|
|
StyleSetForeground(wxSTC_H_DOUBLESTRING, *wxBLACK);
|
|
|
|
StyleSetForeground(wxSTC_H_SINGLESTRING, *wxBLACK);
|
|
|
|
StyleSetForeground(wxSTC_H_OTHER, *wxBLUE);
|
|
|
|
StyleSetForeground(wxSTC_H_COMMENT, wxTheColourDatabase->Find(wxT("GREY")));
|
|
|
|
StyleSetForeground(wxSTC_H_ENTITY, *wxRED);
|
|
|
|
StyleSetBold(wxSTC_H_ENTITY, true);
|
|
|
|
StyleSetForeground(wxSTC_H_TAGEND, *wxBLUE);
|
|
|
|
StyleSetForeground(wxSTC_H_XMLSTART, *wxBLUE);
|
|
|
|
StyleSetForeground(wxSTC_H_XMLEND, *wxBLUE);
|
|
|
|
StyleSetForeground(wxSTC_H_CDATA, *wxRED);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
void OnMarginClick(wxStyledTextEvent&);
|
|
|
|
void OnText(wxStyledTextEvent&);
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MinimalEditor, wxStyledTextCtrl)
|
|
|
|
EVT_STC_MARGINCLICK(wxID_ANY, MinimalEditor::OnMarginClick)
|
|
|
|
EVT_STC_CHANGE(wxID_ANY, MinimalEditor::OnText)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
void MinimalEditor::OnMarginClick(wxStyledTextEvent &event)
|
|
|
|
{
|
|
|
|
if (event.GetMargin() == margin_id_fold)
|
|
|
|
{
|
|
|
|
int lineClick = LineFromPosition(event.GetPosition());
|
|
|
|
int levelClick = GetFoldLevel(lineClick);
|
|
|
|
if ((levelClick & wxSTC_FOLDLEVELHEADERFLAG) > 0)
|
|
|
|
{
|
|
|
|
ToggleFold(lineClick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimalEditor::OnText(wxStyledTextEvent& event)
|
|
|
|
{
|
|
|
|
wxLogDebug(wxT("Modified"));
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
class MinimalEditorFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MinimalEditorFrame() : wxFrame(NULL, wxID_ANY, _("Minimal Editor"))
|
|
|
|
{
|
|
|
|
MinimalEditor* editor = new MinimalEditor(this);
|
|
|
|
editor->SetFont(wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT));
|
|
|
|
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sizer->Add(editor, 1, wxEXPAND);
|
|
|
|
SetSizer(sizer);
|
|
|
|
editor->SetText(
|
|
|
|
"<xml>\n"
|
|
|
|
" <text>\n"
|
|
|
|
" This is xml with syntax highlighting, line numbers, folding, word wrap and context menu\n"
|
|
|
|
" </text>\n"
|
|
|
|
"</xml>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
wxFrame* App::MinimalEditor()
|
|
|
|
{
|
|
|
|
MinimalEditorFrame* frame = new MinimalEditorFrame;
|
|
|
|
frame->Show();
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void App::OnMinimalEditor(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
MinimalEditor();
|
|
|
|
}
|
|
|
|
|