Updated to Scintilla 1.54

Applied most of patch #806092
Added new wxSTC sample from Otto Wyss


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23654 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-09-18 05:05:52 +00:00
parent a47ae718e2
commit 88a8b04e9c
136 changed files with 9108 additions and 1232 deletions

View File

@@ -40,7 +40,9 @@ STCTEST_CXXFLAGS = $(CPPFLAGS) -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \
-I$(srcdir)/../../../samples -I$(srcdir)/../../include $(CXXFLAGS)
STCTEST_OBJECTS = \
$(__stctest___win32rc) \
stctest_stctest.o
stctest_stctest.o \
stctest_edit.o \
stctest_prefs.o
WX_VERSION = 2.5.1
### Conditionally set variables: ###
@@ -102,7 +104,7 @@ COND_PLATFORM_OS2_1___stctest___os2_emxbindcmd = $(NM) stctest$(EXEEXT) | if \
### Targets: ###
all: stctest$(EXEEXT) $(__stctest_bundle___depname) data
all: stctest$(EXEEXT) $(__stctest_bundle___depname)
clean:
rm -rf ./.deps ./.pch
@@ -110,14 +112,6 @@ clean:
rm -f stctest$(EXEEXT)
rm -rf stctest.app
data:
@mkdir -p .
@for f in stctest.cpp; do \
if test \( ! -s ./$$f \) -o \( $(srcdir)/$$f -nt ./$$f \) ; then \
cp -pRf $(srcdir)/$$f . ; \
fi; \
done
distclean: clean
rm -f configure config.cache config.log config.status bk-deps bk-make-pch shared-ld-sh Makefile
@@ -155,6 +149,12 @@ stctest.app/Contents/PkgInfo: stctest$(EXEEXT) $(top_srcdir)/src/mac/Info.plist.
@COND_PLATFORM_MACOSX_1@stctest_bundle: stctest.app/Contents/PkgInfo
stctest_edit.o: $(srcdir)/edit.cpp
$(CXXC) -c -o $@ $(STCTEST_CXXFLAGS) $<
stctest_prefs.o: $(srcdir)/prefs.cpp
$(CXXC) -c -o $@ $(STCTEST_CXXFLAGS) $<
stctest_sample_rc.o: $(srcdir)/../../../samples/sample.rc
$(RESCOMP) -i$< -o$@ --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_2) --include-dir $(top_srcdir)/include --include-dir $(srcdir) $(__DLLFLAG_p_2) --include-dir $(srcdir)/../../../samples
@@ -167,4 +167,4 @@ uninstall:
# Include dependency info, if present:
@IF_GNU_MAKE@-include .deps/*.d
.PHONY: all clean data distclean install stctest_bundle uninstall
.PHONY: all clean distclean install stctest_bundle uninstall

104
samples/stc/defsext.h Normal file
View File

@@ -0,0 +1,104 @@
/////////////////////////////////////////////////////////////////////////////
// Name: defsext.h extensions
// Purpose: STC test declarations
// Maintainer: Wyo
// Created: 2003-09-01
// RCS-ID: $Id$
// Copyright: (c) wxGuide
// Licence: wxWindows licence
//////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DEFSEXT_H_
#define _WX_DEFSEXT_H_
//----------------------------------------------------------------------------
// headers
//----------------------------------------------------------------------------
//! wxWindows headers
#include <wx/print.h> // printing support
#include <wx/printdlg.h> // printing dialog
//============================================================================
// declarations
//============================================================================
#define DEFAULT_LANGUAGE _("<default>")
#define PAGE_COMMON _("Common")
#define PAGE_LANGUAGES _("Languages")
#define PAGE_STYLE_TYPES _("Style types")
#define STYLE_TYPES_COUNT 32
// ----------------------------------------------------------------------------
// standard IDs
// ----------------------------------------------------------------------------
enum {
// menu IDs
myID_PROPERTIES = wxID_HIGHEST,
myID_INDENTINC,
myID_INDENTRED,
myID_FINDNEXT,
myID_REPLACE,
myID_REPLACENEXT,
myID_BRACEMATCH,
myID_GOTO,
myID_PAGEACTIVE,
myID_DISPLAYEOL,
myID_INDENTGUIDE,
myID_LINENUMBER,
myID_LONGLINEON,
myID_WHITESPACE,
myID_FOLDTOGGLE,
myID_OVERTYPE,
myID_READONLY,
myID_WRAPMODEON,
myID_CHANGECASE,
myID_CHANGELOWER,
myID_CHANGEUPPER,
myID_HILIGHTLANG,
myID_HILIGHTFIRST,
myID_HILIGHTLAST = myID_HILIGHTFIRST + 99,
myID_CONVERTEOL,
myID_CONVERTCR,
myID_CONVERTCRLF,
myID_CONVERTLF,
myID_USECHARSET,
myID_CHARSETANSI,
myID_CHARSETMAC,
myID_PAGEPREV,
myID_PAGENEXT,
myID_SELECTLINE,
// other IDs
myID_STATUSBAR,
myID_TITLEBAR,
myID_ABOUTTIMER,
myID_UPDATETIMER,
// dialog find IDs
myID_DLG_FIND_TEXT,
// preferences IDs
myID_PREFS_LANGUAGE,
myID_PREFS_STYLETYPE,
myID_PREFS_KEYWORDS,
};
// ----------------------------------------------------------------------------
// global items
// ----------------------------------------------------------------------------
//! global application name
extern wxString *g_appname;
//! global print data, to remember settings during the session
extern wxPrintData *g_printData;
extern wxPageSetupData *g_pageSetupData;
#endif // _WX_DEFSEXT_H_

825
samples/stc/edit.cpp Normal file
View File

@@ -0,0 +1,825 @@
//////////////////////////////////////////////////////////////////////////////
// File: edit.cpp
// Purpose: STC test module
// Maintainer: Wyo
// Created: 2003-09-01
// RCS-ID: $Id$
// Copyright: (c) wxGuide
// Licence: wxWindows licence
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// informations
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// 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/file.h> // raw file io support
#include <wx/filename.h> // filename support
//! application headers
#include "defsext.h" // additional definitions
#include "edit.h" // edit module
//----------------------------------------------------------------------------
// resources
//----------------------------------------------------------------------------
//============================================================================
// declarations
//============================================================================
//============================================================================
// implementation
//============================================================================
//----------------------------------------------------------------------------
// Edit
//----------------------------------------------------------------------------
BEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl)
// common
EVT_SIZE ( Edit::OnSize)
// edit
EVT_MENU (wxID_CLEAR, Edit::OnEditClear)
EVT_MENU (wxID_CUT, Edit::OnEditCut)
EVT_MENU (wxID_COPY, Edit::OnEditCopy)
EVT_MENU (wxID_PASTE, Edit::OnEditPaste)
EVT_MENU (myID_INDENTINC, Edit::OnEditIndentInc)
EVT_MENU (myID_INDENTRED, Edit::OnEditIndentRed)
EVT_MENU (wxID_SELECTALL, Edit::OnEditSelectAll)
EVT_MENU (myID_SELECTLINE, Edit::OnEditSelectLine)
EVT_MENU (wxID_REDO, Edit::OnEditRedo)
EVT_MENU (wxID_UNDO, Edit::OnEditUndo)
// find
EVT_MENU (wxID_FIND, Edit::OnFind)
EVT_MENU (myID_FINDNEXT, Edit::OnFindNext)
EVT_MENU (myID_REPLACE, Edit::OnReplace)
EVT_MENU (myID_REPLACENEXT, Edit::OnReplaceNext)
EVT_MENU (myID_BRACEMATCH, Edit::OnBraceMatch)
EVT_MENU (myID_GOTO, Edit::OnGoto)
// view
EVT_MENU_RANGE (myID_HILIGHTFIRST, myID_HILIGHTLAST,
Edit::OnHilightLang)
EVT_MENU (myID_DISPLAYEOL, Edit::OnDisplayEOL)
EVT_MENU (myID_INDENTGUIDE, Edit::OnIndentGuide)
EVT_MENU (myID_LINENUMBER, Edit::OnLineNumber)
EVT_MENU (myID_LONGLINEON, Edit::OnLongLineOn)
EVT_MENU (myID_WHITESPACE, Edit::OnWhiteSpace)
EVT_MENU (myID_FOLDTOGGLE, Edit::OnFoldToggle)
EVT_MENU (myID_OVERTYPE, Edit::OnSetOverType)
EVT_MENU (myID_READONLY, Edit::OnSetReadOnly)
EVT_MENU (myID_WRAPMODEON, Edit::OnWrapmodeOn)
EVT_MENU (myID_CHARSETANSI, Edit::OnUseCharset)
EVT_MENU (myID_CHARSETMAC, Edit::OnUseCharset)
// extra
EVT_MENU (myID_CHANGELOWER, Edit::OnChangeCase)
EVT_MENU (myID_CHANGEUPPER, Edit::OnChangeCase)
EVT_MENU (myID_CONVERTCR, Edit::OnConvertEOL)
EVT_MENU (myID_CONVERTCRLF, Edit::OnConvertEOL)
EVT_MENU (myID_CONVERTLF, Edit::OnConvertEOL)
// stc
EVT_STC_MARGINCLICK (-1, Edit::OnMarginClick)
EVT_STC_CHARADDED (-1, Edit::OnCharAdded)
END_EVENT_TABLE()
Edit::Edit (wxWindow *parent, wxWindowID id,
const wxPoint &pos,
const wxSize &size,
long style)
: wxStyledTextCtrl (parent, id, pos, size, style) {
m_filename = _T("");
m_LineNrID = 0;
m_DividerID = 1;
m_FoldingID = 2;
// initialize language
m_language = NULL;
// default font for all styles
SetViewEOL (g_CommonPrefs.displayEOLEnable);
SetIndentationGuides (g_CommonPrefs.indentGuideEnable);
SetEdgeMode (g_CommonPrefs.longLineOnEnable?
wxSTC_EDGE_LINE: wxSTC_EDGE_NONE);
SetViewWhiteSpace (g_CommonPrefs.whiteSpaceEnable?
wxSTC_WS_VISIBLEALWAYS: wxSTC_WS_INVISIBLE);
SetOvertype (g_CommonPrefs.overTypeInitial);
SetReadOnly (g_CommonPrefs.readOnlyInitial);
SetWrapMode (g_CommonPrefs.wrapModeInitial?
wxSTC_WRAP_WORD: wxSTC_WRAP_NONE);
wxFont font (10, wxMODERN, wxNORMAL, wxNORMAL);
StyleSetFont (wxSTC_STYLE_DEFAULT, font);
StyleSetForeground (wxSTC_STYLE_DEFAULT, wxColour ("BLACK"));
StyleSetBackground (wxSTC_STYLE_DEFAULT, wxColour ("WHITE"));
StyleSetForeground (wxSTC_STYLE_LINENUMBER, wxColour ("DARK GREY"));
StyleSetBackground (wxSTC_STYLE_LINENUMBER, wxColour ("WHITE"));
StyleSetForeground(wxSTC_STYLE_INDENTGUIDE, wxColour ("DARK GREY"));
InitializePrefs (DEFAULT_LANGUAGE);
// set visibility
SetVisiblePolicy (wxSTC_VISIBLE_STRICT|wxSTC_VISIBLE_SLOP, 1);
SetXCaretPolicy (wxSTC_CARET_EVEN|wxSTC_VISIBLE_STRICT|wxSTC_CARET_SLOP, 1);
SetYCaretPolicy (wxSTC_CARET_EVEN|wxSTC_VISIBLE_STRICT|wxSTC_CARET_SLOP, 1);
// markers
MarkerDefine (wxSTC_MARKNUM_FOLDER, wxSTC_MARK_DOTDOTDOT, "BLACK", "BLACK");
MarkerDefine (wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_ARROWDOWN, "BLACK", "BLACK");
MarkerDefine (wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_EMPTY, "BLACK", "BLACK");
MarkerDefine (wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_DOTDOTDOT, "BLACK", "WHITE");
MarkerDefine (wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_ARROWDOWN, "BLACK", "WHITE");
MarkerDefine (wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_EMPTY, "BLACK", "BLACK");
MarkerDefine (wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_EMPTY, "BLACK", "BLACK");
// miscelaneous
m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, _T("_999999"));
m_FoldingMargin = 16;
SetMarginWidth (m_LineNrID,
g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0);
CmdKeyClear (wxSTC_KEY_TAB, 0); // this is done by the menu accelerator key
UsePopUp (0);
SetLayoutCache (wxSTC_CACHE_PAGE);
}
Edit::~Edit () {}
//----------------------------------------------------------------------------
// common event handlers
void Edit::OnSize( wxSizeEvent& event ) {
int x = GetClientSize().x +
(g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0) +
(g_CommonPrefs.foldEnable? m_FoldingMargin: 0);
if (x > 0) SetScrollWidth (x);
event.Skip();
}
// edit event handlers
void Edit::OnEditRedo (wxCommandEvent &WXUNUSED(event)) {
if (!CanRedo()) return;
Redo ();
}
void Edit::OnEditUndo (wxCommandEvent &WXUNUSED(event)) {
if (!CanUndo()) return;
Undo ();
}
void Edit::OnEditClear (wxCommandEvent &WXUNUSED(event)) {
if (GetReadOnly()) return;
Clear ();
}
void Edit::OnEditCut (wxCommandEvent &WXUNUSED(event)) {
if (GetReadOnly() || (GetSelectionEnd()-GetSelectionStart() <= 0)) return;
Cut ();
}
void Edit::OnEditCopy (wxCommandEvent &WXUNUSED(event)) {
if (GetSelectionEnd()-GetSelectionStart() <= 0) return;
Copy ();
}
void Edit::OnEditPaste (wxCommandEvent &WXUNUSED(event)) {
if (!CanPaste()) return;
Paste ();
}
void Edit::OnFind (wxCommandEvent &WXUNUSED(event)) {
}
void Edit::OnFindNext (wxCommandEvent &WXUNUSED(event)) {
}
void Edit::OnReplace (wxCommandEvent &WXUNUSED(event)) {
}
void Edit::OnReplaceNext (wxCommandEvent &WXUNUSED(event)) {
}
void Edit::OnBraceMatch (wxCommandEvent &WXUNUSED(event)) {
int min = GetCurrentPos ();
int max = BraceMatch (min);
if (max > (min+1)) {
BraceHighlight (min+1, max);
SetSelection (min+1, max);
}else{
BraceBadLight (min);
}
}
void Edit::OnGoto (wxCommandEvent &WXUNUSED(event)) {
}
void Edit::OnEditIndentInc (wxCommandEvent &event) {
CmdKeyExecute (wxSTC_CMD_TAB);
}
void Edit::OnEditIndentRed (wxCommandEvent &event) {
CmdKeyExecute (wxSTC_CMD_DELETEBACK);
}
void Edit::OnEditSelectAll (wxCommandEvent &WXUNUSED(event)) {
SetSelection (0, GetTextLength ());
}
void Edit::OnEditSelectLine (wxCommandEvent &WXUNUSED(event)) {
int lineStart = PositionFromLine (GetCurrentLine());
int lineEnd = PositionFromLine (GetCurrentLine() + 1);
SetSelection (lineStart, lineEnd);
}
void Edit::OnHilightLang (wxCommandEvent &event) {
InitializePrefs (g_LanguagePrefs [event.GetId() - myID_HILIGHTFIRST].name);
}
void Edit::OnDisplayEOL (wxCommandEvent &WXUNUSED(event)) {
SetViewEOL (!GetViewEOL());
}
void Edit::OnIndentGuide (wxCommandEvent &WXUNUSED(event)) {
SetIndentationGuides (!GetIndentationGuides());
}
void Edit::OnLineNumber (wxCommandEvent &WXUNUSED(event)) {
SetMarginWidth (m_LineNrID,
GetMarginWidth (m_LineNrID) == 0? m_LineNrMargin: 0);
}
void Edit::OnLongLineOn (wxCommandEvent &WXUNUSED(event)) {
SetEdgeMode (GetEdgeMode() == 0? wxSTC_EDGE_LINE: wxSTC_EDGE_NONE);
}
void Edit::OnWhiteSpace (wxCommandEvent &WXUNUSED(event)) {
SetViewWhiteSpace (GetViewWhiteSpace() == 0?
wxSTC_WS_VISIBLEALWAYS: wxSTC_WS_INVISIBLE);
}
void Edit::OnFoldToggle (wxCommandEvent &WXUNUSED(event)) {
ToggleFold (GetFoldParent(GetCurrentLine()));
}
void Edit::OnSetOverType (wxCommandEvent &WXUNUSED(event)) {
SetOvertype (!GetOvertype());
}
void Edit::OnSetReadOnly (wxCommandEvent &WXUNUSED(event)) {
SetReadOnly (!GetReadOnly());
}
void Edit::OnWrapmodeOn (wxCommandEvent &WXUNUSED(event)) {
SetWrapMode (GetWrapMode() == 0? wxSTC_WRAP_WORD: wxSTC_WRAP_NONE);
}
void Edit::OnUseCharset (wxCommandEvent &event) {
int Nr;
int charset = GetCodePage();
switch (event.GetId()) {
case myID_CHARSETANSI: {charset = wxSTC_CHARSET_ANSI; break;}
case myID_CHARSETMAC: {charset = wxSTC_CHARSET_ANSI; break;}
}
for (Nr = 0; Nr < wxSTC_STYLE_LASTPREDEFINED; Nr++) {
StyleSetCharacterSet (Nr, charset);
}
SetCodePage (charset);
}
void Edit::OnChangeCase (wxCommandEvent &event) {
switch (event.GetId()) {
case myID_CHANGELOWER: {
CmdKeyExecute (wxSTC_CMD_LOWERCASE);
break;
}
case myID_CHANGEUPPER: {
CmdKeyExecute (wxSTC_CMD_UPPERCASE);
break;
}
}
}
void Edit::OnConvertEOL (wxCommandEvent &event) {
int eolMode = GetEOLMode();
switch (event.GetId()) {
case myID_CONVERTCR: { eolMode = wxSTC_EOL_CR; break;}
case myID_CONVERTCRLF: { eolMode = wxSTC_EOL_CRLF; break;}
case myID_CONVERTLF: { eolMode = wxSTC_EOL_LF; break;}
}
ConvertEOLs (eolMode);
SetEOLMode (eolMode);
}
//! misc
void Edit::OnMarginClick (wxStyledTextEvent &event) {
if (event.GetMargin() == 2) {
int lineClick = LineFromPosition (event.GetPosition());
int levelClick = GetFoldLevel (lineClick);
if ((levelClick & wxSTC_FOLDLEVELHEADERFLAG) > 0) {
ToggleFold (lineClick);
}
}
}
void Edit::OnCharAdded (wxStyledTextEvent &event) {
char chr = event.GetKey();
int currentLine = GetCurrentLine();
// Change this if support for mac files with \r is needed
if (chr == '\n') {
int lineInd = 0;
if (currentLine > 0) {
lineInd = GetLineIndentation(currentLine - 1);
}
if (lineInd == 0) return;
SetLineIndentation (currentLine, lineInd);
GotoPos(PositionFromLine (currentLine) + lineInd);
}
}
//----------------------------------------------------------------------------
// private functions
wxString Edit::DeterminePrefs (const wxString &filename) {
LanguageInfo const* curInfo = NULL;
// determine language from filepatterns
int languageNr;
for (languageNr = 0; languageNr < g_LanguagePrefsSize; languageNr++) {
curInfo = &g_LanguagePrefs [languageNr];
wxString filepattern = curInfo->filepattern;
filepattern.Lower();
while (!filepattern.IsEmpty()) {
wxString cur = filepattern.BeforeFirst (';');
if ((cur == filename) ||
(cur == (filename.BeforeLast ('.') + _T(".*"))) ||
(cur == (_T("*.") + filename.AfterLast ('.')))) {
return curInfo->name;
}
filepattern = filepattern.AfterFirst (';');
}
}
return wxEmptyString;
}
bool Edit::InitializePrefs (const wxString &name) {
// initialize styles
StyleClearAll();
LanguageInfo const* curInfo = NULL;
// determine language
bool found = false;
int languageNr;
for (languageNr = 0; languageNr < g_LanguagePrefsSize; languageNr++) {
curInfo = &g_LanguagePrefs [languageNr];
if (curInfo->name == name) {
found = true;
break;
}
}
if (!found) return false;
// set lexer and language
SetLexer (curInfo->lexer);
m_language = curInfo;
// set margin for line numbers
SetMarginType (m_LineNrID, wxSTC_MARGIN_NUMBER);
StyleSetForeground (wxSTC_STYLE_LINENUMBER, wxColour ("DARK GREY"));
StyleSetBackground (wxSTC_STYLE_LINENUMBER, wxColour ("WHITE"));
SetMarginWidth (m_LineNrID,
g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0);
// default fonts for all styles!
int Nr;
for (Nr = 0; Nr < wxSTC_STYLE_LASTPREDEFINED; Nr++) {
wxFont font (10, wxMODERN, wxNORMAL, wxNORMAL);
StyleSetFont (Nr, font);
}
// set common styles
StyleSetForeground (wxSTC_STYLE_DEFAULT, wxColour ("DARK GREY"));
StyleSetForeground (wxSTC_STYLE_INDENTGUIDE, wxColour ("DARK GREY"));
// initialize settings
if (g_CommonPrefs.syntaxEnable) {
int keywordnr = 0;
for (Nr = 0; Nr < STYLE_TYPES_COUNT; Nr++) {
if (curInfo->styles[Nr].type == -1) continue;
const StyleInfo &curType = g_StylePrefs [curInfo->styles[Nr].type];
wxFont font (curType.fontsize, wxMODERN, wxNORMAL, wxNORMAL, false,
curType.fontname);
StyleSetFont (Nr, font);
if (curType.foreground) {
StyleSetForeground (Nr, wxColour (curType.foreground));
}
if (curType.background) {
StyleSetBackground (Nr, wxColour (curType.background));
}
StyleSetBold (Nr, (curType.fontstyle & mySTC_STYLE_BOLD) > 0);
StyleSetItalic (Nr, (curType.fontstyle & mySTC_STYLE_ITALIC) > 0);
StyleSetUnderline (Nr, (curType.fontstyle & mySTC_STYLE_UNDERL) > 0);
StyleSetVisible (Nr, (curType.fontstyle & mySTC_STYLE_HIDDEN) == 0);
StyleSetCase (Nr, curType.lettercase);
const wxChar *pwords = curInfo->styles[Nr].words;
if (pwords) {
SetKeyWords (keywordnr, pwords);
keywordnr += 1;
}
}
}
// set margin as unused
SetMarginType (m_DividerID, wxSTC_MARGIN_SYMBOL);
SetMarginWidth (m_DividerID, 0);
SetMarginSensitive (m_DividerID, false);
// folding
SetMarginType (m_FoldingID, wxSTC_MARGIN_SYMBOL);
SetMarginMask (m_FoldingID, wxSTC_MASK_FOLDERS);
StyleSetBackground (m_FoldingID, wxColour ("WHITE"));
SetMarginWidth (m_FoldingID, 0);
SetMarginSensitive (m_FoldingID, false);
if (g_CommonPrefs.foldEnable) {
SetMarginWidth (m_FoldingID, curInfo->folds != 0? m_FoldingMargin: 0);
SetMarginSensitive (m_FoldingID, curInfo->folds != 0);
SetProperty (_T("fold"), curInfo->folds != 0? _T("1"): _T("0"));
SetProperty (_T("fold.comment"),
(curInfo->folds & mySTC_FOLD_COMMENT) > 0? _T("1"): _T("0"));
SetProperty (_T("fold.compact"),
(curInfo->folds & mySTC_FOLD_COMPACT) > 0? _T("1"): _T("0"));
SetProperty (_T("fold.preprocessor"),
(curInfo->folds & mySTC_FOLD_PREPROC) > 0? _T("1"): _T("0"));
SetProperty (_T("fold.html"),
(curInfo->folds & mySTC_FOLD_HTML) > 0? _T("1"): _T("0"));
SetProperty (_T("fold.html.preprocessor"),
(curInfo->folds & mySTC_FOLD_HTMLPREP) > 0? _T("1"): _T("0"));
SetProperty (_T("fold.comment.python"),
(curInfo->folds & mySTC_FOLD_COMMENTPY) > 0? _T("1"): _T("0"));
SetProperty (_T("fold.quotes.python"),
(curInfo->folds & mySTC_FOLD_QUOTESPY) > 0? _T("1"): _T("0"));
}
SetFoldFlags (wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED |
wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
// set spaces and indention
SetTabWidth (4);
SetUseTabs (false);
SetTabIndents (true);
SetBackSpaceUnIndents (true);
SetIndent (g_CommonPrefs.indentEnable? 4: 0);
// others
SetViewEOL (g_CommonPrefs.displayEOLEnable);
SetIndentationGuides (g_CommonPrefs.indentGuideEnable);
SetEdgeColumn (80);
SetEdgeMode (g_CommonPrefs.longLineOnEnable? wxSTC_EDGE_LINE: wxSTC_EDGE_NONE);
SetViewWhiteSpace (g_CommonPrefs.whiteSpaceEnable?
wxSTC_WS_VISIBLEALWAYS: wxSTC_WS_INVISIBLE);
SetOvertype (g_CommonPrefs.overTypeInitial);
SetReadOnly (g_CommonPrefs.readOnlyInitial);
SetWrapMode (g_CommonPrefs.wrapModeInitial?
wxSTC_WRAP_WORD: wxSTC_WRAP_NONE);
return true;
}
bool Edit::LoadFile () {
// get filname
if (!m_filename) {
wxFileDialog dlg (this, _T("Open file"), _T(""), _T(""),
_T("Any file (*)|*"), wxOPEN | wxFILE_MUST_EXIST | wxCHANGE_DIR);
if (dlg.ShowModal() != wxID_OK) return false;
m_filename = dlg.GetPath();
}
// load file
return LoadFile (m_filename);
}
bool Edit::LoadFile (const wxString &filename) {
// load file in edit and clear undo
if (!filename.IsEmpty()) m_filename = filename;
// wxFile file (m_filename);
// if (!file.IsOpened()) return false;
ClearAll ();
// long lng = file.Length ();
// if (lng > 0) {
// wxString buf;
// wxChar *buff = buf.GetWriteBuf (lng);
// file.Read (buff, lng);
// buf.UngetWriteBuf ();
// InsertText (0, buf);
// }
// file.Close();
wxStyledTextCtrl::LoadFile(m_filename);
EmptyUndoBuffer();
// determine lexer language
wxFileName fname (m_filename);
InitializePrefs (DeterminePrefs (fname.GetFullName()));
return true;
}
bool Edit::SaveFile () {
// return if no change
if (!Modified()) return true;
// get filname
if (!m_filename) {
wxFileDialog dlg (this, _T("Save file"), _T(""), _T(""), _T("Any file (*)|*"),
wxSAVE | wxOVERWRITE_PROMPT);
if (dlg.ShowModal() != wxID_OK) return false;
m_filename = dlg.GetPath();
}
// save file
return SaveFile (m_filename);
}
bool Edit::SaveFile (const wxString &filename) {
// return if no change
if (!Modified()) return true;
// // save edit in file and clear undo
// if (!filename.IsEmpty()) m_filename = filename;
// wxFile file (m_filename, wxFile::write);
// if (!file.IsOpened()) return false;
// wxString buf = GetText();
// bool okay = file.Write (buf);
// file.Close();
// if (!okay) return false;
// EmptyUndoBuffer();
// SetSavePoint();
// return true;
return wxStyledTextCtrl::SaveFile(filename);
}
bool Edit::Modified () {
// return modified state
return (GetModify() && !GetReadOnly());
}
//----------------------------------------------------------------------------
// EditProperties
//----------------------------------------------------------------------------
EditProperties::EditProperties (Edit *edit,
long style)
: wxDialog (edit, -1, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
// sets the application title
SetTitle (_("Properties"));
wxString text;
// fullname
wxBoxSizer *fullname = new wxBoxSizer (wxHORIZONTAL);
fullname->Add (10, 0);
fullname->Add (new wxStaticText (this, -1, _("Full filename"),
wxDefaultPosition, wxSize(80, -1)),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
fullname->Add (new wxStaticText (this, -1, edit->GetFilename()),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
// text info
wxGridSizer *textinfo = new wxGridSizer (4, 0, 2);
textinfo->Add (new wxStaticText (this, -1, _("Language"),
wxDefaultPosition, wxSize(80, -1)),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
textinfo->Add (new wxStaticText (this, -1, edit->m_language->name),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
textinfo->Add (new wxStaticText (this, -1, _("Lexer-ID: "),
wxDefaultPosition, wxSize(80, -1)),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
text = wxString::Format (_T("%d"), edit->GetLexer());
textinfo->Add (new wxStaticText (this, -1, text),
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
wxString EOLtype = _T("");
switch (edit->GetEOLMode()) {
case wxSTC_EOL_CR: {EOLtype = _T("CR (Unix)"); break; }
case wxSTC_EOL_CRLF: {EOLtype = _T("CRLF (Windows)"); break; }
case wxSTC_EOL_LF: {EOLtype = _T("CR (Macintosh)"); break; }
}
textinfo->Add (new wxStaticText (this, -1, _("Line endings"),
wxDefaultPosition, wxSize(80, -1)),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
textinfo->Add (new wxStaticText (this, -1, EOLtype),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
// text info box
wxStaticBoxSizer *textinfos = new wxStaticBoxSizer (
new wxStaticBox (this, -1, _("Informations")),
wxVERTICAL);
textinfos->Add (textinfo, 0, wxEXPAND);
textinfos->Add (0, 6);
// statistic
wxGridSizer *statistic = new wxGridSizer (4, 0, 2);
statistic->Add (new wxStaticText (this, -1, _("Total lines"),
wxDefaultPosition, wxSize(80, -1)),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
text = wxString::Format (_T("%d"), edit->GetLineCount());
statistic->Add (new wxStaticText (this, -1, text),
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
statistic->Add (new wxStaticText (this, -1, _("Total chars"),
wxDefaultPosition, wxSize(80, -1)),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
text = wxString::Format (_T("%d"), edit->GetTextLength());
statistic->Add (new wxStaticText (this, -1, text),
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
statistic->Add (new wxStaticText (this, -1, _("Current line"),
wxDefaultPosition, wxSize(80, -1)),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
text = wxString::Format (_T("%d"), edit->GetCurrentLine());
statistic->Add (new wxStaticText (this, -1, text),
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
statistic->Add (new wxStaticText (this, -1, _("Current pos"),
wxDefaultPosition, wxSize(80, -1)),
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
text = wxString::Format (_T("%d"), edit->GetCurrentPos());
statistic->Add (new wxStaticText (this, -1, text),
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
// char/line statistics
wxStaticBoxSizer *statistics = new wxStaticBoxSizer (
new wxStaticBox (this, -1, _("Statistics")),
wxVERTICAL);
statistics->Add (statistic, 0, wxEXPAND);
statistics->Add (0, 6);
// total pane
wxBoxSizer *totalpane = new wxBoxSizer (wxVERTICAL);
totalpane->Add (fullname, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
totalpane->Add (0, 6);
totalpane->Add (textinfos, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
totalpane->Add (0, 10);
totalpane->Add (statistics, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
totalpane->Add (0, 6);
wxButton *okButton = new wxButton (this, wxID_OK, _("OK"));
okButton->SetDefault();
totalpane->Add (okButton, 0, wxALIGN_CENTER | wxALL, 10);
SetSizerAndFit (totalpane);
ShowModal();
}
//----------------------------------------------------------------------------
// EditPrint
//----------------------------------------------------------------------------
EditPrint::EditPrint (Edit *edit, wxChar *title)
: wxPrintout(title) {
m_edit = edit;
m_printed = 0;
}
bool EditPrint::OnPrintPage (int page) {
wxDC *dc = GetDC();
if (!dc) return false;
// scale DC
PrintScaling (dc);
// print page
if (page == 1) m_printed = 0;
m_printed = m_edit->FormatRange (1, m_printed, m_edit->GetLength(),
dc, dc, m_printRect, m_pageRect);
return true;
}
bool EditPrint::OnBeginDocument (int startPage, int endPage) {
if (!wxPrintout::OnBeginDocument (startPage, endPage)) {
return false;
}
return true;
}
void EditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) {
// initialize values
*minPage = 0;
*maxPage = 0;
*selPageFrom = 0;
*selPageTo = 0;
// scale DC if possible
wxDC *dc = GetDC();
if (!dc) return;
PrintScaling (dc);
// get print page informations and convert to printer pixels
wxSize ppiScr;
GetPPIScreen (&ppiScr.x, &ppiScr.y);
wxSize page = g_pageSetupData->GetPaperSize();
page.x = static_cast<int> (page.x * ppiScr.x / 25.4);
page.y = static_cast<int> (page.y * ppiScr.y / 25.4);
m_pageRect = wxRect (0,
0,
page.x,
page.y);
// get margins informations and convert to printer pixels
int top = 25; // default 25
int bottom = 25; // default 25
int left = 20; // default 20
int right = 20; // default 20
wxPoint (top, left) = g_pageSetupData->GetMarginTopLeft();
wxPoint (bottom, right) = g_pageSetupData->GetMarginBottomRight();
top = static_cast<int> (top * ppiScr.y / 25.4);
bottom = static_cast<int> (bottom * ppiScr.y / 25.4);
left = static_cast<int> (left * ppiScr.x / 25.4);
right = static_cast<int> (right * ppiScr.x / 25.4);
m_printRect = wxRect (left,
top,
page.x - (left + right),
page.y - (top + bottom));
// count pages
while (HasPage (*maxPage)) {
m_printed = m_edit->FormatRange (0, m_printed, m_edit->GetLength(),
dc, dc, m_printRect, m_pageRect);
*maxPage += 1;
}
if (*maxPage > 0) *minPage = 1;
*selPageFrom = *minPage;
*selPageTo = *maxPage;
}
bool EditPrint::HasPage (int page) {
return (m_printed < m_edit->GetLength());
}
bool EditPrint::PrintScaling (wxDC *dc){
// check for dc, return if none
if (!dc) return false;
// get printer and screen sizing values
wxSize ppiScr;
GetPPIScreen (&ppiScr.x, &ppiScr.y);
if (ppiScr.x == 0) { // most possible guess 96 dpi
ppiScr.x = 96;
ppiScr.y = 96;
}
wxSize ppiPrt;
GetPPIPrinter (&ppiPrt.x, &ppiPrt.y);
if (ppiPrt.x == 0) { // scaling factor to 1
ppiPrt.x = ppiScr.x;
ppiPrt.y = ppiScr.y;
}
wxSize dcSize = dc->GetSize();
wxSize pageSize;
GetPageSizePixels (&pageSize.x, &pageSize.y);
// set user scale
float scale_x = (float)(ppiPrt.x * dcSize.x) /
(float)(ppiScr.x * pageSize.x);
float scale_y = (float)(ppiPrt.y * dcSize.y) /
(float)(ppiScr.y * pageSize.y);
dc->SetUserScale (scale_x, scale_y);
return true;
}

169
samples/stc/edit.h Normal file
View File

@@ -0,0 +1,169 @@
//////////////////////////////////////////////////////////////////////////////
// File: edit.h
// Purpose: STC test module
// Maintainer: Wyo
// Created: 2003-09-01
// RCS-ID: $Id$
// Copyright: (c) wxGuide
// Licence: wxWindows licence
//////////////////////////////////////////////////////////////////////////////
#ifndef _EDIT_H_
#define _EDIT_H_
//----------------------------------------------------------------------------
// informations
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// headers
//----------------------------------------------------------------------------
//! wxWindows headers
//! wxWindows/contrib headers
#include <wx/stc/stc.h> // styled text control
//! application headers
#include "prefs.h" // preferences
//============================================================================
// declarations
//============================================================================
class EditPrint;
class EditProperties;
//----------------------------------------------------------------------------
//! Edit
class Edit: public wxStyledTextCtrl {
friend class EditProperties;
friend class EditPrint;
public:
//! constructor
Edit (wxWindow *parent, wxWindowID id = -1,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
long style = wxSUNKEN_BORDER|wxVSCROLL
);
//! destructor
~Edit ();
// event handlers
// common
void OnSize( wxSizeEvent &event );
// edit
void OnEditRedo (wxCommandEvent &event);
void OnEditUndo (wxCommandEvent &event);
void OnEditClear (wxCommandEvent &event);
void OnEditCut (wxCommandEvent &event);
void OnEditCopy (wxCommandEvent &event);
void OnEditPaste (wxCommandEvent &event);
// find
void OnFind (wxCommandEvent &event);
void OnFindNext (wxCommandEvent &event);
void OnReplace (wxCommandEvent &event);
void OnReplaceNext (wxCommandEvent &event);
void OnBraceMatch (wxCommandEvent &event);
void OnGoto (wxCommandEvent &event);
void OnEditIndentInc (wxCommandEvent &event);
void OnEditIndentRed (wxCommandEvent &event);
void OnEditSelectAll (wxCommandEvent &event);
void OnEditSelectLine (wxCommandEvent &event);
//! view
void OnHilightLang (wxCommandEvent &event);
void OnDisplayEOL (wxCommandEvent &event);
void OnIndentGuide (wxCommandEvent &event);
void OnLineNumber (wxCommandEvent &event);
void OnLongLineOn (wxCommandEvent &event);
void OnWhiteSpace (wxCommandEvent &event);
void OnFoldToggle (wxCommandEvent &event);
void OnSetOverType (wxCommandEvent &event);
void OnSetReadOnly (wxCommandEvent &event);
void OnWrapmodeOn (wxCommandEvent &event);
void OnUseCharset (wxCommandEvent &event);
//! extra
void OnChangeCase (wxCommandEvent &event);
void OnConvertEOL (wxCommandEvent &event);
// stc
void OnMarginClick (wxStyledTextEvent &event);
void OnCharAdded (wxStyledTextEvent &event);
//! language/lexer
wxString DeterminePrefs (const wxString &filename);
bool InitializePrefs (const wxString &filename);
bool UserSettings (const wxString &filename);
LanguageInfo const* GetLanguageInfo () {return m_language;};
//! load/save file
bool LoadFile ();
bool LoadFile (const wxString &filename);
bool SaveFile ();
bool SaveFile (const wxString &filename);
bool Modified ();
wxString GetFilename () {return m_filename;};
void SetFilename (const wxString &filename) {m_filename = filename;};
private:
// file
wxString m_filename;
// lanugage properties
LanguageInfo const* m_language;
// margin variables
int m_LineNrID;
int m_LineNrMargin;
int m_FoldingID;
int m_FoldingMargin;
int m_DividerID;
DECLARE_EVENT_TABLE()
};
//----------------------------------------------------------------------------
//! EditProperties
class EditProperties: public wxDialog {
public:
//! constructor
EditProperties (Edit *edit, long style = 0);
private:
};
//----------------------------------------------------------------------------
//! EditPrint
class EditPrint: public wxPrintout {
public:
//! constructor
EditPrint (Edit *edit, wxChar *title = _T(""));
//! event handlers
bool OnPrintPage (int page);
bool OnBeginDocument (int startPage, int endPage);
//! print functions
bool HasPage (int page);
void GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
private:
Edit *m_edit;
int m_printed;
wxRect m_pageRect;
wxRect m_printRect;
bool PrintScaling (wxDC *dc);
};
#endif // _EDIT_H_

View File

@@ -30,7 +30,9 @@ STCTEST_CXXFLAGS = $(CPPFLAGS) $(__RUNTIME_LIBS_6) -I$(BCCDIR)\include \
-I$(SETUPHDIR) -I. $(__DLLFLAG_p) -I.\..\..\..\samples -I.\..\..\include \
$(CXXFLAGS)
STCTEST_OBJECTS = \
$(OBJS)\stctest_stctest.obj
$(OBJS)\stctest_stctest.obj \
$(OBJS)\stctest_edit.obj \
$(OBJS)\stctest_prefs.obj
### Conditionally set variables: ###
@@ -152,7 +154,13 @@ $(OBJS):
### Targets: ###
all: $(OBJS)\stctest.exe data
all: $(OBJS)\stctest.exe
$(OBJS)\stctest_edit.obj: .\edit.cpp
$(CXX) -q -c -P -o$@ $(STCTEST_CXXFLAGS) $**
$(OBJS)\stctest_prefs.obj: .\prefs.cpp
$(CXX) -q -c -P -o$@ $(STCTEST_CXXFLAGS) $**
$(OBJS)\stctest_sample.res: .\..\..\..\samples\sample.rc
brcc32 -32 -r -fo$@ -i$(BCCDIR)\include -d__WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) -i.\..\..\..\include -i$(SETUPHDIR) -i. $(__DLLFLAG_p_1) -i.\..\..\..\samples $**
@@ -170,10 +178,6 @@ clean:
-if exist $(OBJS)\stctest.ilf del $(OBJS)\stctest.ilf
-if exist $(OBJS)\stctest.ils del $(OBJS)\stctest.ils
data:
if not exist $(OBJS) mkdir $(OBJS)
for %f in (stctest.cpp) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
$(OBJS)\stctest.exe: $(STCTEST_OBJECTS) $(OBJS)\stctest_sample.res
ilink32 -Tpe -q $(LDFLAGS) -L$(BCCDIR)\lib $(__DEBUGINFO) -L$(LIBDIRNAME) -aa @&&|
c0w32.obj $(STCTEST_OBJECTS),$@,, wx$(PORTNAME)$(WXUNIVNAME)25$(WXUNICODEFLAG)$(WXDEBUGFLAG)_stc.lib $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib wxregex$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(__UNICOWS_LIB_p) ole2w32.lib oleacc.lib import32.lib cw32mt$(__RUNTIME_LIBS_7).lib,, $(OBJS)\stctest_sample.res

View File

@@ -22,7 +22,9 @@ STCTEST_CXXFLAGS = $(CPPFLAGS) $(__DEBUGINFO) $(__OPTIMIZEFLAG_2) $(GCCFLAGS) \
$(__DLLFLAG_p) -I.\..\..\..\samples -I.\..\..\include $(CXXFLAGS)
STCTEST_OBJECTS = \
$(OBJS)\stctest_sample_rc.o \
$(OBJS)\stctest_stctest.o
$(OBJS)\stctest_stctest.o \
$(OBJS)\stctest_edit.o \
$(OBJS)\stctest_prefs.o
### Conditionally set variables: ###
@@ -145,7 +147,13 @@ $(OBJS):
### Targets: ###
all: $(OBJS)\stctest.exe data
all: $(OBJS)\stctest.exe
$(OBJS)\stctest_edit.o: ./edit.cpp
$(CXX) -c -o $@ $(STCTEST_CXXFLAGS) $<
$(OBJS)\stctest_prefs.o: ./prefs.cpp
$(CXX) -c -o $@ $(STCTEST_CXXFLAGS) $<
$(OBJS)\stctest_sample_rc.o: ./../../../samples/sample.rc
windres --use-temp-file -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) --include-dir ./../../../include --include-dir $(SETUPHDIR) --include-dir . $(__DLLFLAG_p_1) --include-dir ./../../../samples
@@ -157,11 +165,7 @@ clean:
-if exist $(OBJS)\*.o del $(OBJS)\*.o
-if exist $(OBJS)\stctest.exe del $(OBJS)\stctest.exe
data:
if not exist $(OBJS) mkdir $(OBJS)
for %%f in (stctest.cpp) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS)
$(OBJS)\stctest.exe: $(STCTEST_OBJECTS) $(OBJS)\stctest_sample_rc.o
$(CXX) -o $@ $(STCTEST_OBJECTS) $(LDFLAGS) $(__DEBUGINFO) -mthreads -L$(LIBDIRNAME) -Wl,--subsystem,windows -mwindows -lwx$(PORTNAME)$(WXUNIVNAME)25$(WXUNICODEFLAG)$(WXDEBUGFLAG)_stc $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG) -lwxregex$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(__UNICOWS_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lodbc32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32
.PHONY: all clean data
.PHONY: all clean

View File

@@ -24,7 +24,9 @@ STCTEST_CXXFLAGS = $(CPPFLAGS) /M$(__RUNTIME_LIBS_7)$(__DEBUGRUNTIME_3) \
/I.\..\..\include $(CXXFLAGS) /GR /GX
STCTEST_OBJECTS = \
$(OBJS)\stctest_sample.res \
$(OBJS)\stctest_stctest.obj
$(OBJS)\stctest_stctest.obj \
$(OBJS)\stctest_edit.obj \
$(OBJS)\stctest_prefs.obj
### Conditionally set variables: ###
@@ -227,7 +229,13 @@ $(OBJS):
### Targets: ###
all: $(OBJS)\stctest.exe data
all: $(OBJS)\stctest.exe
$(OBJS)\stctest_edit.obj: .\edit.cpp
$(CXX) /c /nologo /TP /Fo$@ $(STCTEST_CXXFLAGS) $**
$(OBJS)\stctest_prefs.obj: .\prefs.cpp
$(CXX) /c /nologo /TP /Fo$@ $(STCTEST_CXXFLAGS) $**
$(OBJS)\stctest_sample.res: .\..\..\..\samples\sample.rc
rc /fo$@ /d WIN32 $(____DEBUGRUNTIME_2_p_1) $(__NO_VC_CRTDBG_p_1) /d __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) /i .\..\..\..\include /i $(SETUPHDIR) /i . $(__DLLFLAG_p_1) /d _WINDOWS /i .\..\..\..\samples $**
@@ -242,10 +250,6 @@ clean:
-if exist $(OBJS)\stctest.ilk del $(OBJS)\stctest.ilk
-if exist $(OBJS)\stctest.pdb del $(OBJS)\stctest.pdb
data:
if not exist $(OBJS) mkdir $(OBJS)
for %f in (stctest.cpp) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
$(OBJS)\stctest.exe: $(STCTEST_OBJECTS) $(OBJS)\stctest_sample.res
link /NOLOGO /OUT:$@ $(LDFLAGS) $(__DEBUGINFO_1) /LIBPATH:$(LIBDIRNAME) /SUBSYSTEM:WINDOWS @<<
$(STCTEST_OBJECTS) wx$(PORTNAME)$(WXUNIVNAME)25$(WXUNICODEFLAG)$(WXDEBUGFLAG)_stc.lib $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib wxregex$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(__UNICOWS_LIB_p) kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib odbc32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib wsock32.lib oleacc.lib

View File

@@ -169,7 +169,9 @@ STCTEST_CXXFLAGS = $(CPPFLAGS) $(__DEBUGINFO_0) $(__OPTIMIZEFLAG_2) -bm &
$(__UNICODE_DEFINE_p) -i=.\..\..\..\include -i=$(SETUPHDIR) -i=. &
$(__DLLFLAG_p) -i=.\..\..\..\samples -i=.\..\..\include $(CXXFLAGS)
STCTEST_OBJECTS = &
$(OBJS)\stctest_stctest.obj
$(OBJS)\stctest_stctest.obj &
$(OBJS)\stctest_edit.obj &
$(OBJS)\stctest_prefs.obj
all : $(OBJS)
@@ -178,7 +180,13 @@ $(OBJS) :
### Targets: ###
all : .SYMBOLIC $(OBJS)\stctest.exe data
all : .SYMBOLIC $(OBJS)\stctest.exe
$(OBJS)\stctest_edit.obj : .AUTODEPEND .\edit.cpp
$(CXX) -zq -fo=$^@ $(STCTEST_CXXFLAGS) $<
$(OBJS)\stctest_prefs.obj : .AUTODEPEND .\prefs.cpp
$(CXX) -zq -fo=$^@ $(STCTEST_CXXFLAGS) $<
$(OBJS)\stctest_sample.res : .AUTODEPEND .\..\..\..\samples\sample.rc
wrc -q -ad -bt=nt -r -fo=$^@ -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__UNICODE_DEFINE_p) -i=.\..\..\..\include -i=$(SETUPHDIR) -i=. $(__DLLFLAG_p) -i=.\..\..\..\samples $<
@@ -193,10 +201,6 @@ clean : .SYMBOLIC
-if exist $(OBJS)\*.ilk del $(OBJS)\*.ilk
-if exist $(OBJS)\stctest.exe del $(OBJS)\stctest.exe
data : .SYMBOLIC
if not exist $(OBJS) mkdir $(OBJS)
for %f in (stctest.cpp) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
$(OBJS)\stctest.exe : $(STCTEST_OBJECTS) $(OBJS)\stctest_sample.res
@%create $(OBJS)\stctest.lbc
@%append $(OBJS)\stctest.lbc option quiet

BIN
samples/stc/mondrian.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

44
samples/stc/mondrian.xpm Normal file
View File

@@ -0,0 +1,44 @@
/* XPM */
static char *mondrian_xpm[] = {
/* columns rows colors chars-per-pixel */
"32 32 6 1",
" c Black",
". c Blue",
"X c #00bf00",
"o c Red",
"O c Yellow",
"+ c Gray100",
/* pixels */
" ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" oooooo +++++++++++++++++++++++ ",
" ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ .... ",
" ++++++ ++++++++++++++++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++++++++++++++++ ++++ ",
" ++++++ ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
" "
};

379
samples/stc/prefs.cpp Normal file
View File

@@ -0,0 +1,379 @@
//////////////////////////////////////////////////////////////////////////////
// File: prefs.cpp
// Purpose: STC test Preferences initialization
// Maintainer: Wyo
// Created: 2003-09-01
// RCS-ID: $Id$
// 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' wxWindows headers)
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
//! wxWindows headers
//! wxWindows/contrib headers
//! application headers
#include "defsext.h" // Additional definitions
#include "prefs.h" // Preferences
//============================================================================
// declarations
//============================================================================
//----------------------------------------------------------------------------
//! language types
const CommonInfo g_CommonPrefs = {
// editor functionality prefs
true, // syntaxEnable
true, // foldEnable
true, // indentEnable
// display defaults prefs
false, // overTypeInitial
false, // readOnlyInitial
false, // wrapModeInitial
false, // displayEOLEnable
false, // IndentGuideEnable
true, // lineNumberEnable
false, // longLineOnEnable
false, // whiteSpaceEnable
};
//----------------------------------------------------------------------------
// keywordlists
// C++
wxChar* CppWordlist1 =
_T("asm auto bool break case catch char class const const_cast \
continue default delete do double dynamic_cast else enum explicit \
export extern false float for friend goto if inline int long \
mutable namespace new operator private protected public register \
reinterpret_cast return short signed sizeof static static_cast \
struct switch template this throw true try typedef typeid \
typename union unsigned using virtual void volatile wchar_t \
while");
wxChar* CppWordlist2 =
_T("file");
wxChar* CppWordlist3 =
_T("a addindex addtogroup anchor arg attention author b brief bug c \
class code date def defgroup deprecated dontinclude e em endcode \
endhtmlonly endif endlatexonly endlink endverbatim enum example \
exception f$ f[ f] file fn hideinitializer htmlinclude \
htmlonly if image include ingroup internal invariant interface \
latexonly li line link mainpage name namespace nosubgrouping note \
overload p page par param post pre ref relates remarks return \
retval sa section see showinitializer since skip skipline struct \
subsection test throw todo typedef union until var verbatim \
verbinclude version warning weakgroup $ @ "" & < > # { }");
// Python
wxChar* PythonWordlist1 =
_T("and assert break class continue def del elif else except exec \
finally for from global if import in is lambda None not or pass \
print raise return try while yield");
wxChar* PythonWordlist2 =
_T("ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON BEGIN \
BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS \
COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX \
DISCARDABLE EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE \
LISTBOX LTEXT MENU MENUEX MENUITEM MESSAGETABLE POPUP PUSHBUTTON \
RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 \
STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY");
//----------------------------------------------------------------------------
//! languages
const LanguageInfo g_LanguagePrefs [] = {
// C++
{_T("C++"),
_T("*.c;*.cc;*.cpp;*.cxx;*.cs;*.h;*.hh;*.hpp;*.hxx;*.sma"),
wxSTC_LEX_CPP,
{{mySTC_TYPE_DEFAULT, NULL},
{mySTC_TYPE_COMMENT, NULL},
{mySTC_TYPE_COMMENT_LINE, NULL},
{mySTC_TYPE_COMMENT_DOC, NULL},
{mySTC_TYPE_NUMBER, NULL},
{mySTC_TYPE_WORD1, CppWordlist1}, // KEYWORDS
{mySTC_TYPE_STRING, NULL},
{mySTC_TYPE_CHARACTER, NULL},
{mySTC_TYPE_UUID, NULL},
{mySTC_TYPE_PREPROCESSOR, NULL},
{mySTC_TYPE_OPERATOR, NULL},
{mySTC_TYPE_IDENTIFIER, NULL},
{mySTC_TYPE_STRING_EOL, NULL},
{mySTC_TYPE_DEFAULT, NULL}, // VERBATIM
{mySTC_TYPE_REGEX, NULL},
{mySTC_TYPE_COMMENT_SPECIAL, NULL}, // DOXY
{mySTC_TYPE_WORD2, CppWordlist2}, // EXTRA WORDS
{mySTC_TYPE_WORD3, CppWordlist3}, // DOXY KEYWORDS
{mySTC_TYPE_ERROR, NULL}, // KEYWORDS ERROR
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL}},
mySTC_FOLD_COMMENT | mySTC_FOLD_COMPACT | mySTC_FOLD_PREPROC},
// Python
{_T("Python"),
_T("*.py;*.pyw"),
wxSTC_LEX_PYTHON,
{{mySTC_TYPE_DEFAULT, NULL},
{mySTC_TYPE_COMMENT_LINE, NULL},
{mySTC_TYPE_NUMBER, NULL},
{mySTC_TYPE_STRING, NULL},
{mySTC_TYPE_CHARACTER, NULL},
{mySTC_TYPE_WORD1, PythonWordlist1}, // KEYWORDS
{mySTC_TYPE_DEFAULT, NULL}, // TRIPLE
{mySTC_TYPE_DEFAULT, NULL}, // TRIPLEDOUBLE
{mySTC_TYPE_DEFAULT, NULL}, // CLASSNAME
{mySTC_TYPE_DEFAULT, PythonWordlist2}, // DEFNAME
{mySTC_TYPE_OPERATOR, NULL},
{mySTC_TYPE_IDENTIFIER, NULL},
{mySTC_TYPE_DEFAULT, NULL}, // COMMENT_BLOCK
{mySTC_TYPE_STRING_EOL, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL}},
mySTC_FOLD_COMMENTPY | mySTC_FOLD_QUOTESPY},
// * (any)
{(wxChar *)DEFAULT_LANGUAGE,
_T("*.*"),
wxSTC_LEX_PROPERTIES,
{{mySTC_TYPE_DEFAULT, NULL},
{mySTC_TYPE_DEFAULT, NULL},
{mySTC_TYPE_DEFAULT, NULL},
{mySTC_TYPE_DEFAULT, NULL},
{mySTC_TYPE_DEFAULT, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL}},
0},
};
const int g_LanguagePrefsSize = WXSIZEOF(g_LanguagePrefs);
//----------------------------------------------------------------------------
//! style types
const StyleInfo g_StylePrefs [] = {
// mySTC_TYPE_DEFAULT
{_T("Default"),
_T("BLACK"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_WORD1
{_T("Keyword1"),
_T("BLUE"), _T("WHITE"),
_T(""), 10, mySTC_STYLE_BOLD, 0},
// mySTC_TYPE_WORD2
{_T("Keyword2"),
_T("DARK BLUE"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_WORD3
{_T("Keyword3"),
_T("CORNFLOWER BLUE"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_WORD4
{_T("Keyword4"),
_T("CYAN"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_WORD5
{_T("Keyword5"),
_T("DARK GREY"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_WORD6
{_T("Keyword6"),
_T("GREY"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_COMMENT
{_T("Comment"),
_T("FOREST GREEN"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_COMMENT_DOC
{_T("Comment (Doc)"),
_T("FOREST GREEN"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_COMMENT_LINE
{_T("Comment line"),
_T("FOREST GREEN"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_COMMENT_SPECIAL
{_T("Special comment"),
_T("FOREST GREEN"), _T("WHITE"),
_T(""), 10, mySTC_STYLE_ITALIC, 0},
// mySTC_TYPE_CHARACTER
{_T("Character"),
_T("KHAKI"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_CHARACTER_EOL
{_T("Character (EOL)"),
_T("KHAKI"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_STRING
{_T("String"),
_T("BROWN"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_STRING_EOL
{_T("String (EOL)"),
_T("BROWN"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_DELIMITER
{_T("Delimiter"),
_T("ORANGE"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_PUNCTUATION
{_T("Punctuation"),
_T("ORANGE"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_OPERATOR
{_T("Operator"),
_T("BLACK"), _T("WHITE"),
_T(""), 10, mySTC_STYLE_BOLD, 0},
// mySTC_TYPE_BRACE
{_T("Label"),
_T("VIOLET"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_COMMAND
{_T("Command"),
_T("BLUE"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_IDENTIFIER
{_T("Identifier"),
_T("BLACK"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_LABEL
{_T("Label"),
_T("VIOLET"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_NUMBER
{_T("Number"),
_T("SIENNA"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_PARAMETER
{_T("Parameter"),
_T("VIOLET"), _T("WHITE"),
_T(""), 10, mySTC_STYLE_ITALIC, 0},
// mySTC_TYPE_REGEX
{_T("Regular expression"),
_T("ORCHID"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_UUID
{_T("UUID"),
_T("ORCHID"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_VALUE
{_T("Value"),
_T("ORCHID"), _T("WHITE"),
_T(""), 10, mySTC_STYLE_ITALIC, 0},
// mySTC_TYPE_PREPROCESSOR
{_T("Preprocessor"),
_T("GREY"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_SCRIPT
{_T("Script"),
_T("DARK GREY"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_ERROR
{_T("Error"),
_T("RED"), _T("WHITE"),
_T(""), 10, 0, 0},
// mySTC_TYPE_UNDEFINED
{_T("Undefined"),
_T("ORANGE"), _T("WHITE"),
_T(""), 10, 0, 0}
};
const int g_StylePrefsSize = WXSIZEOF(g_StylePrefs);

153
samples/stc/prefs.h Normal file
View File

@@ -0,0 +1,153 @@
//////////////////////////////////////////////////////////////////////////////
// File: prefs.h
// Purpose: STC test Preferences initialization
// Maintainer: Wyo
// Created: 2003-09-01
// RCS-ID: $Id$
// Copyright: (c) wxGuide
// Licence: wxWindows licence
//////////////////////////////////////////////////////////////////////////////
#ifndef _PREFS_H_
#define _PREFS_H_
//----------------------------------------------------------------------------
// informations
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// headers
//----------------------------------------------------------------------------
//! wxWindows headers
//! wxWindows/contrib headers
#include <wx/stc/stc.h> // styled text control
//! application headers
//============================================================================
// declarations
//============================================================================
//! general style types
#define mySTC_TYPE_DEFAULT 0
#define mySTC_TYPE_WORD1 1
#define mySTC_TYPE_WORD2 2
#define mySTC_TYPE_WORD3 3
#define mySTC_TYPE_WORD4 4
#define mySTC_TYPE_WORD5 5
#define mySTC_TYPE_WORD6 6
#define mySTC_TYPE_COMMENT 7
#define mySTC_TYPE_COMMENT_DOC 8
#define mySTC_TYPE_COMMENT_LINE 9
#define mySTC_TYPE_COMMENT_SPECIAL 10
#define mySTC_TYPE_CHARACTER 11
#define mySTC_TYPE_CHARACTER_EOL 12
#define mySTC_TYPE_STRING 13
#define mySTC_TYPE_STRING_EOL 14
#define mySTC_TYPE_DELIMITER 15
#define mySTC_TYPE_PUNCTUATION 16
#define mySTC_TYPE_OPERATOR 17
#define mySTC_TYPE_BRACE 18
#define mySTC_TYPE_COMMAND 19
#define mySTC_TYPE_IDENTIFIER 20
#define mySTC_TYPE_LABEL 21
#define mySTC_TYPE_NUMBER 22
#define mySTC_TYPE_PARAMETER 23
#define mySTC_TYPE_REGEX 24
#define mySTC_TYPE_UUID 25
#define mySTC_TYPE_VALUE 26
#define mySTC_TYPE_PREPROCESSOR 27
#define mySTC_TYPE_SCRIPT 28
#define mySTC_TYPE_ERROR 29
//----------------------------------------------------------------------------
//! style bits types
#define mySTC_STYLE_BOLD 1
#define mySTC_STYLE_ITALIC 2
#define mySTC_STYLE_UNDERL 4
#define mySTC_STYLE_HIDDEN 8
//----------------------------------------------------------------------------
//! general folding types
#define mySTC_FOLD_COMMENT 1
#define mySTC_FOLD_COMPACT 2
#define mySTC_FOLD_PREPROC 4
#define mySTC_FOLD_HTML 16
#define mySTC_FOLD_HTMLPREP 32
#define mySTC_FOLD_COMMENTPY 64
#define mySTC_FOLD_QUOTESPY 128
//----------------------------------------------------------------------------
//! flags
#define mySTC_FLAG_WRAPMODE 16
//----------------------------------------------------------------------------
// CommonInfo
struct CommonInfo {
// editor functionality prefs
bool syntaxEnable;
bool foldEnable;
bool indentEnable;
// display defaults prefs
bool readOnlyInitial;
bool overTypeInitial;
bool wrapModeInitial;
bool displayEOLEnable;
bool indentGuideEnable;
bool lineNumberEnable;
bool longLineOnEnable;
bool whiteSpaceEnable;
};
extern const CommonInfo g_CommonPrefs;
//----------------------------------------------------------------------------
// LanguageInfo
struct LanguageInfo {
wxChar *name;
wxChar *filepattern;
int lexer;
struct {
int type;
const wxChar *words;
} styles [STYLE_TYPES_COUNT];
int folds;
};
extern const LanguageInfo g_LanguagePrefs[];
extern const int g_LanguagePrefsSize;
//----------------------------------------------------------------------------
// StyleInfo
struct StyleInfo {
wxChar *name;
wxChar *foreground;
wxChar *background;
wxChar *fontname;
int fontsize;
int fontstyle;
int lettercase;
};
extern const StyleInfo g_StylePrefs[];
extern const int g_StylePrefsSize;
#endif // _PREFS_H_

View File

@@ -7,16 +7,12 @@
<exe id="stctest" template="wx_contrib_sample" template_append="wx_append">
<sources>
stctest.cpp
edit.cpp
prefs.cpp
</sources>
<wx-lib>stc</wx-lib>
<wx-lib>core</wx-lib>
<wx-lib>base</wx-lib>
</exe>
<wx-data id="data">
<files>
stctest.cpp
</files>
</wx-data>
</makefile>

View File

@@ -1,254 +1,659 @@
/////////////////////////////////////////////////////////////////////////////
// Name: stctest.cpp
// Purpose: sample of using wxStyledTextCtrl
// Author: Robin Dunn
// Modified by:
// Created: 3-Feb-2000
//////////////////////////////////////////////////////////////////////////////
// File: app.cpp
// Purpose: STC test application
// Maintainer: Otto Wyss
// Created: 2003-09-01
// RCS-ID: $Id$
// Copyright: (c) 2000 by Total Control Software
// Copyright: (c) wxGuide
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma implementation "stctest.cpp"
#pragma interface "stctest.cpp"
#endif
//----------------------------------------------------------------------------
// headers
//----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
// 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
// need because it includes almost all 'standard' wxWindows headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#include <wx/wx.h>
#endif
#include <wx/wfstream.h>
//! 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/stc/stc.h>
//! application headers
#include "defsext.h" // Additional definitions
#include "edit.h" // Edit module
#include "prefs.h" // Prefs
//----------------------------------------------------------------------
class MyApp : public wxApp
{
//----------------------------------------------------------------------------
// 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/indexedit.html")
#define APP_MAINT _T("Otto Wyss")
#define APP_VENDOR _T("wxWindows")
#define APP_COPYRIGTH _T("(C) 2003 Otto Wyss")
#define APP_LICENCE _T("wxWindows")
#define APP_VERSION _T("0.1.alpha")
#define APP_BUILD __DATE__
#define APP_WEBSITE _T("http://www.wxWindows.org")
#define APP_MAIL _T("mailto://???")
#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:
virtual bool OnInit();
};
//! the main function called durning application start
virtual bool OnInit ();
//----------------------------------------------------------------------
// Make an editor class
class MySTC : public wxStyledTextCtrl
{
public:
MySTC(wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0);
void OnKeyPressed(wxKeyEvent& evt);
//! 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()
};
BEGIN_EVENT_TABLE(MySTC, wxStyledTextCtrl)
EVT_KEY_DOWN(MySTC::OnKeyPressed)
END_EVENT_TABLE()
//----------------------------------------------------------------------------
//! about box of the application APP_VENDOR-APP_NAME
class AppAbout: public wxDialog {
//----------------------------------------------------------------------
// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
//! constructor
AppAbout (wxWindow *parent,
int milliseconds = 0,
long style = 0);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
//! destructor
~AppAbout ();
// event handlers
void OnTimerEvent (wxTimerEvent &event);
private:
MySTC* ed;
// timer
wxTimer *m_timer;
DECLARE_EVENT_TABLE()
};
// IDs for the controls and the menu commands
enum
{
// menu items
ID_Quit = 1,
ID_About,
ID_ED
};
//============================================================================
// implementation
//============================================================================
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU (ID_Quit, MyFrame::OnQuit)
EVT_MENU (ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()
IMPLEMENT_APP (App)
IMPLEMENT_APP(MyApp)
//----------------------------------------------------------------------------
// App
//----------------------------------------------------------------------------
//----------------------------------------------------------------------
// `Main program' equivalent: the program execution "starts" here
bool App::OnInit () {
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(_T("Testing wxStyledTextCtrl"),
wxPoint(5, 5), wxSize(600, 600));
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);
frame->Show(TRUE);
return TRUE;
// 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 () {
// frame constructor
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
#ifdef __WXMAC__
// we need this in order to allow the about menu relocation, since ABOUT is
// not the default id of the about menu
wxApp::s_macAboutMenuItemId = ID_About;
#endif
// delete global appname
delete g_appname;
// delete global print data and setup
if (g_printData) delete g_printData;
if (g_pageSetupData) delete g_pageSetupData;
// create a menu bar
wxMenu *menuFile = new wxMenu(wxEmptyString, wxMENU_TEAROFF);
// the "About" item should be in the help menu
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(ID_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
menuFile->Append(ID_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(menuFile, _T("&File"));
menuBar->Append(helpMenu, _T("&Help"));
// ... and attach this menu bar to the frame
SetMenuBar(menuBar);
#if wxUSE_STATUSBAR
CreateStatusBar(2);
SetStatusText(_T("Testing wxStyledTextCtrl"));
#endif // wxUSE_STATUSBAR
//----------------------------------------
// Setup the editor
ed = new MySTC(this, ID_ED);
return 0;
}
//----------------------------------------------------------------------------
// AppFrame
//----------------------------------------------------------------------------
// event handlers
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, wxSize(600,400),
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 (this, 1000);
// create menu
m_menuBar = new wxMenuBar;
CreateMenu ();
// open first page
m_edit = new Edit (this, -1);
m_edit->SetFocus();
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
// TRUE is to force the frame to close
Close(TRUE);
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxString msg;
msg.Printf( _T("Testing wxStyledTextCtrl...\n"));
wxMessageBox(msg, _T("About This Test"), wxOK | wxICON_INFORMATION, this);
AppFrame::~AppFrame () {
}
//----------------------------------------------------------------------
wxChar* keywords =
_T("asm auto bool break case catch char class const \
const_cast continue default delete do double \
dynamic_cast else enum explicit export extern \
false float for friend goto if inline int long \
mutable namespace new operator private protected \
public register reinterpret_cast return short signed \
sizeof static static_cast struct switch template this \
throw true try typedef typeid typename union unsigned \
using virtual void volatile wchar_t while");
MySTC::MySTC(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style)
: wxStyledTextCtrl(parent, id, pos, size, style)
{
// Default font
wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL);
StyleSetFont(wxSTC_STYLE_DEFAULT, font);
StyleClearAll();
StyleSetForeground(0, wxColour(0x80, 0x80, 0x80));
StyleSetForeground(1, wxColour(0x00, 0x7f, 0x00));
//StyleSetForeground(2, wxColour(0x00, 0x7f, 0x00));
StyleSetForeground(3, wxColour(0x7f, 0x7f, 0x7f));
StyleSetForeground(4, wxColour(0x00, 0x7f, 0x7f));
StyleSetForeground(5, wxColour(0x00, 0x00, 0x7f));
StyleSetForeground(6, wxColour(0x7f, 0x00, 0x7f));
StyleSetForeground(7, wxColour(0x7f, 0x00, 0x7f));
StyleSetForeground(8, wxColour(0x00, 0x7f, 0x7f));
StyleSetForeground(9, wxColour(0x7f, 0x7f, 0x7f));
StyleSetForeground(10, wxColour(0x00, 0x00, 0x00));
StyleSetForeground(11, wxColour(0x00, 0x00, 0x00));
StyleSetBold(5, TRUE);
StyleSetBold(10, TRUE);
#ifdef __WXMSW__
StyleSetSpec(2, _T("fore:#007f00,bold,face:Arial,size:9"));
#else
StyleSetSpec(2, _T("fore:#007f00,bold,face:Helvetica,size:9"));
#endif
// give it some text to play with
wxString st;
wxFileInputStream stream(wxT("stctest.cpp"));
size_t sz = stream.GetSize();
char* buf = new char[sz + 1];
stream.Read((void*) buf, stream.GetSize());
buf[sz] = 0;
st = wxString::FromAscii(buf);
delete[] buf;
InsertText(0, st);
EmptyUndoBuffer();
SetLexer(wxSTC_LEX_CPP);
SetKeyWords(0, keywords);
// 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 MySTC::OnKeyPressed(wxKeyEvent& evt)
{
if (CallTipActive())
CallTipCancel();
void AppFrame::OnAbout (wxCommandEvent &WXUNUSED(event)) {
AppAbout (this);
}
int key = evt.GetKeyCode();
if ( key == WXK_SPACE && evt.ControlDown()) {
int pos = GetCurrentPos();
void AppFrame::OnExit (wxCommandEvent &WXUNUSED(event)) {
Close (true);
}
if (evt.ShiftDown()) {
// show how to do CallTips
CallTipSetBackground(wxColour(_T("YELLOW")));
CallTipShow(pos, _T("lots of of text: blah, blah, blah\n\n\
show some suff, maybe parameters..\n\n\
fubar(param1, param2)"));
}
else {
// show how to do AutoComplete
AutoCompSetIgnoreCase(false);
AutoCompShow(0, keywords); // reuse the keyword list here
// normally you would build a string of completion texts...
// file event handlers
void AppFrame::OnFileOpen (wxCommandEvent &WXUNUSED(event)) {
if (!m_edit) return;
wxString fname;
wxFileDialog dlg (this, _T("Open file"), _T(""), _T(""), _T("Any file (*)|*"),
wxOPEN | wxFILE_MUST_EXIST | wxCHANGE_DIR);
if (dlg.ShowModal() != wxID_OK) return;
fname = dlg.GetPath ();
FileOpen (fname);
}
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 ();
}
void AppFrame::OnFileSaveAs (wxCommandEvent &WXUNUSED(event)) {
if (!m_edit) return;
wxString filename = wxEmptyString;
wxFileDialog dlg (this, _T("Save file"), _T(""), _T(""), _T("Any file (*)|*"), wxSAVE|wxOVERWRITE_PROMPT);
if (dlg.ShowModal() != wxID_OK) return;
filename = dlg.GetPath();
m_edit->SaveFile (filename);
}
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;
}
}
}
else
evt.Skip();
}
// properties event handlers
void AppFrame::OnProperties (wxCommandEvent &WXUNUSED(event)) {
if (!m_edit) return;
EditProperties (m_edit, 0);
}
// print event handlers
void AppFrame::OnPrintSetup (wxCommandEvent &WXUNUSED(event)) {
(*g_pageSetupData) = * g_printData;
wxPageSetupDialog pageSetupDialog(this, g_pageSetupData);
pageSetupDialog.ShowModal();
(*g_printData) = pageSetupDialog.GetPageSetupData().GetPrintData();
(*g_pageSetupData) = pageSetupDialog.GetPageSetupData();
}
void AppFrame::OnPrintPreview (wxCommandEvent &WXUNUSED(event)) {
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);
}
void AppFrame::OnPrint (wxCommandEvent &WXUNUSED(event)) {
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;
}
}
(*g_printData) = printer.GetPrintDialogData().GetPrintData();
}
// edit events
void AppFrame::OnEdit (wxCommandEvent &event) {
if (m_edit) m_edit->ProcessEvent (event);
}
// private functions
void AppFrame::CreateMenu () {
// 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"));
menuEdit->Append (myID_INDENTRED, _("I&ndent reduce\tBksp"));
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"));
// 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);
}
void AppFrame::FileOpen (wxString fname) {
wxFileName w(fname); w.Normalize(); fname = w.GetFullPath();
m_edit->LoadFile (fname);
}
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)
: wxDialog (parent, -1, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
// 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);
aboutinfo->Add (new wxStaticText(this, -1, _("Written by: ")),
0, wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, APP_MAINT),
1, wxEXPAND | wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, _("Version: ")),
0, wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, APP_VERSION),
1, wxEXPAND | wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, _("Licence type: ")),
0, wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, APP_LICENCE),
1, wxEXPAND | wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, _("Copyright: ")),
0, wxALIGN_LEFT);
aboutinfo->Add (new wxStaticText(this, -1, APP_COPYRIGTH),
1, wxEXPAND | wxALIGN_LEFT);
// about icontitle//info
wxBoxSizer *aboutpane = new wxBoxSizer (wxHORIZONTAL);
wxBitmap bitmap = wxBitmap(wxICON (mondrian));
aboutpane->Add (new wxStaticBitmap (this, -1, bitmap),
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);
wxStaticText *appname = new wxStaticText(this, -1, *g_appname);
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);
totalpane->Add (new wxStaticText(this, -1, APP_DESCR),
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);
CenterOnScreen();
ShowModal();
}
AppAbout::~AppAbout () {
if (m_timer) {
delete m_timer;
m_timer = NULL;
}
}
//----------------------------------------------------------------------------
// event handlers
void AppAbout::OnTimerEvent (wxTimerEvent &event) {
if (m_timer) delete m_timer;
m_timer = NULL;
EndModal (wxID_OK);
}

View File

@@ -468,6 +468,14 @@ LINK32=link.exe
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\edit.cpp
# End Source File
# Begin Source File
SOURCE=.\prefs.cpp
# End Source File
# Begin Source File
SOURCE=.\..\..\..\samples\sample.rc
# End Source File
# Begin Source File

View File

@@ -1 +1,5 @@
mondrian ICON "mondrian.ico"
#include "wx/msw/wx.rc"
print BITMAP "bitmaps/print.bmp"