This commit was manufactured by cvs2svn to create branch
'WX_2_4_BRANCH'. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@23681 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
104
contrib/samples/stc/defsext.h
Normal file
104
contrib/samples/stc/defsext.h
Normal 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
contrib/samples/stc/edit.cpp
Normal file
825
contrib/samples/stc/edit.cpp
Normal 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 (_T("BLACK")));
|
||||||
|
StyleSetBackground (wxSTC_STYLE_DEFAULT, wxColour (_T("WHITE")));
|
||||||
|
StyleSetForeground (wxSTC_STYLE_LINENUMBER, wxColour (_T("DARK GREY")));
|
||||||
|
StyleSetBackground (wxSTC_STYLE_LINENUMBER, wxColour (_T("WHITE")));
|
||||||
|
StyleSetForeground(wxSTC_STYLE_INDENTGUIDE, wxColour (_T("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, _T("BLACK"), _T("BLACK"));
|
||||||
|
MarkerDefine (wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_ARROWDOWN, _T("BLACK"), _T("BLACK"));
|
||||||
|
MarkerDefine (wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_EMPTY, _T("BLACK"), _T("BLACK"));
|
||||||
|
MarkerDefine (wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_DOTDOTDOT, _T("BLACK"), _T("WHITE"));
|
||||||
|
MarkerDefine (wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_ARROWDOWN, _T("BLACK"), _T("WHITE"));
|
||||||
|
MarkerDefine (wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_EMPTY, _T("BLACK"), _T("BLACK"));
|
||||||
|
MarkerDefine (wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_EMPTY, _T("BLACK"), _T("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 &WXUNUSED(event)) {
|
||||||
|
CmdKeyExecute (wxSTC_CMD_TAB);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Edit::OnEditIndentRed (wxCommandEvent &WXUNUSED(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 (_T("DARK GREY")));
|
||||||
|
StyleSetBackground (wxSTC_STYLE_LINENUMBER, wxColour (_T("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 (_T("DARK GREY")));
|
||||||
|
StyleSetForeground (wxSTC_STYLE_INDENTGUIDE, wxColour (_T("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 (_T("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,
|
||||||
|
style | 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 WXUNUSED(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
contrib/samples/stc/edit.h
Normal file
169
contrib/samples/stc/edit.h
Normal 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_
|
||||||
|
|
BIN
contrib/samples/stc/mondrian.ico
Normal file
BIN
contrib/samples/stc/mondrian.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 766 B |
44
contrib/samples/stc/mondrian.xpm
Normal file
44
contrib/samples/stc/mondrian.xpm
Normal 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
contrib/samples/stc/prefs.cpp
Normal file
379
contrib/samples/stc/prefs.cpp
Normal 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
contrib/samples/stc/prefs.h
Normal file
153
contrib/samples/stc/prefs.h
Normal 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_
|
||||||
|
|
183
contrib/src/stc/scintilla/src/LexMMIXAL.cxx
Normal file
183
contrib/src/stc/scintilla/src/LexMMIXAL.cxx
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
// Scintilla source code edit control
|
||||||
|
/** @file LexMMIXAL.cxx
|
||||||
|
** Lexer for MMIX Assembler Language.
|
||||||
|
** Written by Christoph H<>sler <christoph.hoesler@student.uni-tuebingen.de>
|
||||||
|
** For information about MMIX visit http://www-cs-faculty.stanford.edu/~knuth/mmix.html
|
||||||
|
**/
|
||||||
|
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
|
||||||
|
// The License.txt file describes the conditions under which this software may be distributed.
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
|
#include "PropSet.h"
|
||||||
|
#include "Accessor.h"
|
||||||
|
#include "StyleContext.h"
|
||||||
|
#include "KeyWords.h"
|
||||||
|
#include "Scintilla.h"
|
||||||
|
#include "SciLexer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static inline bool IsAWordChar(const int ch) {
|
||||||
|
return (ch < 0x80) && (isalnum(ch) || ch == ':' || ch == '_');
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool isMMIXALOperator(char ch) {
|
||||||
|
if (isalnum(ch))
|
||||||
|
return false;
|
||||||
|
if (ch == '+' || ch == '-' || ch == '|' || ch == '^' ||
|
||||||
|
ch == '*' || ch == '/' || ch == '/' ||
|
||||||
|
ch == '%' || ch == '<' || ch == '>' || ch == '&' ||
|
||||||
|
ch == '~' || ch == '$' ||
|
||||||
|
ch == ',' || ch == '(' || ch == ')' ||
|
||||||
|
ch == '[' || ch == ']')
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ColouriseMMIXALDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
|
||||||
|
Accessor &styler) {
|
||||||
|
|
||||||
|
WordList &opcodes = *keywordlists[0];
|
||||||
|
WordList &special_register = *keywordlists[1];
|
||||||
|
WordList &predef_symbols = *keywordlists[2];
|
||||||
|
|
||||||
|
StyleContext sc(startPos, length, initStyle, styler);
|
||||||
|
|
||||||
|
for (; sc.More(); sc.Forward())
|
||||||
|
{
|
||||||
|
// No EOL continuation
|
||||||
|
if (sc.atLineStart) {
|
||||||
|
if (sc.ch == '@' && sc.chNext == 'i') {
|
||||||
|
sc.SetState(SCE_MMIXAL_INCLUDE);
|
||||||
|
} else {
|
||||||
|
sc.SetState(SCE_MMIXAL_LEADWS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if first non whitespace character in line is alphanumeric
|
||||||
|
if (sc.state == SCE_MMIXAL_LEADWS && !isspace(sc.ch)) { // LEADWS
|
||||||
|
if(!IsAWordChar(sc.ch)) {
|
||||||
|
sc.SetState(SCE_MMIXAL_COMMENT);
|
||||||
|
} else {
|
||||||
|
if(sc.atLineStart) {
|
||||||
|
sc.SetState(SCE_MMIXAL_LABEL);
|
||||||
|
} else {
|
||||||
|
sc.SetState(SCE_MMIXAL_OPCODE_PRE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if the current state should terminate.
|
||||||
|
if (sc.state == SCE_MMIXAL_OPERATOR) { // OPERATOR
|
||||||
|
sc.SetState(SCE_MMIXAL_OPERANDS);
|
||||||
|
} else if (sc.state == SCE_MMIXAL_NUMBER) { // NUMBER
|
||||||
|
if (!isdigit(sc.ch)) {
|
||||||
|
if (IsAWordChar(sc.ch)) {
|
||||||
|
char s[100];
|
||||||
|
sc.GetCurrent(s, sizeof(s));
|
||||||
|
sc.ChangeState(SCE_MMIXAL_REF);
|
||||||
|
sc.SetState(SCE_MMIXAL_REF);
|
||||||
|
} else {
|
||||||
|
sc.SetState(SCE_MMIXAL_OPERANDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_MMIXAL_LABEL) { // LABEL
|
||||||
|
if (!IsAWordChar(sc.ch) ) {
|
||||||
|
sc.SetState(SCE_MMIXAL_OPCODE_PRE);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_MMIXAL_REF) { // REF
|
||||||
|
if (!IsAWordChar(sc.ch) ) {
|
||||||
|
char s[100];
|
||||||
|
sc.GetCurrent(s, sizeof(s));
|
||||||
|
if (*s == ':') { // ignore base prefix for match
|
||||||
|
for (size_t i = 0; i != sizeof(s); ++i) {
|
||||||
|
*(s+i) = *(s+i+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (special_register.InList(s)) {
|
||||||
|
sc.ChangeState(SCE_MMIXAL_REGISTER);
|
||||||
|
} else if (predef_symbols.InList(s)) {
|
||||||
|
sc.ChangeState(SCE_MMIXAL_SYMBOL);
|
||||||
|
}
|
||||||
|
sc.SetState(SCE_MMIXAL_OPERANDS);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_MMIXAL_OPCODE_PRE) { // OPCODE_PRE
|
||||||
|
if (!isspace(sc.ch)) {
|
||||||
|
sc.SetState(SCE_MMIXAL_OPCODE);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_MMIXAL_OPCODE) { // OPCODE
|
||||||
|
if (!IsAWordChar(sc.ch) ) {
|
||||||
|
char s[100];
|
||||||
|
sc.GetCurrent(s, sizeof(s));
|
||||||
|
if (opcodes.InList(s)) {
|
||||||
|
sc.ChangeState(SCE_MMIXAL_OPCODE_VALID);
|
||||||
|
} else {
|
||||||
|
sc.ChangeState(SCE_MMIXAL_OPCODE_UNKNOWN);
|
||||||
|
}
|
||||||
|
sc.SetState(SCE_MMIXAL_OPCODE_POST);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_MMIXAL_STRING) { // STRING
|
||||||
|
if (sc.ch == '\"') {
|
||||||
|
sc.ForwardSetState(SCE_MMIXAL_OPERANDS);
|
||||||
|
} else if (sc.atLineEnd) {
|
||||||
|
sc.ForwardSetState(SCE_MMIXAL_OPERANDS);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_MMIXAL_CHAR) { // CHAR
|
||||||
|
if (sc.ch == '\'') {
|
||||||
|
sc.ForwardSetState(SCE_MMIXAL_OPERANDS);
|
||||||
|
} else if (sc.atLineEnd) {
|
||||||
|
sc.ForwardSetState(SCE_MMIXAL_OPERANDS);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_MMIXAL_REGISTER) { // REGISTER
|
||||||
|
if (!isdigit(sc.ch)) {
|
||||||
|
sc.SetState(SCE_MMIXAL_OPERANDS);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_MMIXAL_HEX) { // HEX
|
||||||
|
if (!isxdigit(sc.ch)) {
|
||||||
|
sc.SetState(SCE_MMIXAL_OPERANDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if a new state should be entered.
|
||||||
|
if (sc.state == SCE_MMIXAL_OPCODE_POST || // OPCODE_POST
|
||||||
|
sc.state == SCE_MMIXAL_OPERANDS) { // OPERANDS
|
||||||
|
if (sc.state == SCE_MMIXAL_OPERANDS && isspace(sc.ch)) {
|
||||||
|
if (!sc.atLineEnd) {
|
||||||
|
sc.SetState(SCE_MMIXAL_COMMENT);
|
||||||
|
}
|
||||||
|
} else if (isdigit(sc.ch)) {
|
||||||
|
sc.SetState(SCE_MMIXAL_NUMBER);
|
||||||
|
} else if (IsAWordChar(sc.ch) || sc.Match('@')) {
|
||||||
|
sc.SetState(SCE_MMIXAL_REF);
|
||||||
|
} else if (sc.Match('\"')) {
|
||||||
|
sc.SetState(SCE_MMIXAL_STRING);
|
||||||
|
} else if (sc.Match('\'')) {
|
||||||
|
sc.SetState(SCE_MMIXAL_CHAR);
|
||||||
|
} else if (sc.Match('$')) {
|
||||||
|
sc.SetState(SCE_MMIXAL_REGISTER);
|
||||||
|
} else if (sc.Match('#')) {
|
||||||
|
sc.SetState(SCE_MMIXAL_HEX);
|
||||||
|
} else if (isMMIXALOperator(static_cast<char>(sc.ch))) {
|
||||||
|
sc.SetState(SCE_MMIXAL_OPERATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sc.Complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * const MMIXALWordListDesc[] = {
|
||||||
|
"Operation Codes",
|
||||||
|
"Special Register",
|
||||||
|
"Predefined Symbols",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
LexerModule lmMMIXAL(SCLEX_MMIXAL, ColouriseMMIXALDoc, "mmixal", 0, MMIXALWordListDesc);
|
||||||
|
|
346
contrib/src/stc/scintilla/src/LexNsis.cxx
Normal file
346
contrib/src/stc/scintilla/src/LexNsis.cxx
Normal file
@@ -0,0 +1,346 @@
|
|||||||
|
// Scintilla source code edit control
|
||||||
|
/** @file LexNsis.cxx
|
||||||
|
** Lexer for NSIS
|
||||||
|
**/
|
||||||
|
// Copyright 2003 by Angelo Mandato <angelo@spaceblue.com>
|
||||||
|
// The License.txt file describes the conditions under which this software may be distributed.
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
|
#include "PropSet.h"
|
||||||
|
#include "Accessor.h"
|
||||||
|
#include "KeyWords.h"
|
||||||
|
#include "Scintilla.h"
|
||||||
|
#include "SciLexer.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Put in SciLexer.h
|
||||||
|
#define SCLEX_NSIS 34
|
||||||
|
|
||||||
|
#define SCE_NSIS_DEFAULT 0
|
||||||
|
#define SCE_NSIS_COMMENT 1
|
||||||
|
#define SCE_NSIS_STRINGDQ 2
|
||||||
|
#define SCE_NSIS_STRINGLQ 3
|
||||||
|
#define SCE_NSIS_STRINGRQ 4
|
||||||
|
#define SCE_NSIS_FUNCTION 5
|
||||||
|
#define SCE_NSIS_VARIABLE 6
|
||||||
|
#define SCE_NSIS_LABEL 7
|
||||||
|
#define SCE_NSIS_USERDEFINED 8
|
||||||
|
#define SCE_NSIS_SECTIONDEF 9
|
||||||
|
#define SCE_NSIS_SUBSECTIONDEF 10
|
||||||
|
#define SCE_NSIS_IFDEFINEDEF 11
|
||||||
|
#define SCE_NSIS_MACRODEF 12
|
||||||
|
#define SCE_NSIS_STRINGVAR 13
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int classifyWordNsis(unsigned int start, unsigned int end, WordList *keywordLists[], Accessor &styler)
|
||||||
|
{
|
||||||
|
char s[100];
|
||||||
|
|
||||||
|
WordList &Functions = *keywordLists[0];
|
||||||
|
WordList &Variables = *keywordLists[1];
|
||||||
|
WordList &Lables = *keywordLists[2];
|
||||||
|
WordList &UserDefined = *keywordLists[3];
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < end - start + 1 && i < 30; i++)
|
||||||
|
{
|
||||||
|
s[i] = static_cast<char>( styler[ start + i ] );
|
||||||
|
s[i + 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for special words...
|
||||||
|
|
||||||
|
if( strcmp(s, "!macro") == 0 || strcmp(s, "!macroend") == 0 ) // Covers !micro and !microend
|
||||||
|
return SCE_NSIS_MACRODEF;
|
||||||
|
|
||||||
|
if( strcmp(s, "!ifdef") == 0 || strcmp(s, "!ifndef") == 0 || strcmp(s, "!endif") == 0 )
|
||||||
|
return SCE_NSIS_IFDEFINEDEF;
|
||||||
|
|
||||||
|
if( strcmp(s, "Section") == 0 || strcmp(s, "SectionEnd") == 0 ) // Covers Section and SectionEnd
|
||||||
|
return SCE_NSIS_SECTIONDEF;
|
||||||
|
|
||||||
|
if( strcmp(s, "SubSection") == 0 || strcmp(s, "SubSectionEnd") == 0 ) // Covers SubSection and SubSectionEnd
|
||||||
|
return SCE_NSIS_SUBSECTIONDEF;
|
||||||
|
|
||||||
|
if( strcmp(s, "Function") == 0 || strcmp(s, "FunctionEnd") == 0 ) // Covers SubSection and SubSectionEnd
|
||||||
|
return SCE_NSIS_FUNCTION;
|
||||||
|
|
||||||
|
if ( Functions.InList(s) )
|
||||||
|
return SCE_NSIS_FUNCTION;
|
||||||
|
|
||||||
|
if ( Variables.InList(s) )
|
||||||
|
return SCE_NSIS_VARIABLE;
|
||||||
|
|
||||||
|
if ( Lables.InList(s) )
|
||||||
|
return SCE_NSIS_LABEL;
|
||||||
|
|
||||||
|
if( UserDefined.InList(s) )
|
||||||
|
return SCE_NSIS_USERDEFINED;
|
||||||
|
|
||||||
|
if( strlen(s) > 2 )
|
||||||
|
{
|
||||||
|
if( s[1] == '{' && s[strlen(s)-1] == '}' )
|
||||||
|
return SCE_NSIS_VARIABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SCE_NSIS_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ColouriseNsisDoc(unsigned int startPos, int length, int, WordList *keywordLists[], Accessor &styler)
|
||||||
|
{
|
||||||
|
int state = SCE_NSIS_DEFAULT;
|
||||||
|
styler.StartAt( startPos );
|
||||||
|
styler.GetLine( startPos );
|
||||||
|
|
||||||
|
unsigned int nLengthDoc = startPos + length;
|
||||||
|
styler.StartSegment( startPos );
|
||||||
|
|
||||||
|
char cCurrChar;
|
||||||
|
bool bVarInString = true;
|
||||||
|
|
||||||
|
unsigned int i;
|
||||||
|
for( i = startPos; i < nLengthDoc; i++ )
|
||||||
|
{
|
||||||
|
cCurrChar = styler.SafeGetCharAt( i );
|
||||||
|
char cNextChar = styler.SafeGetCharAt( i+1, EOF );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
switch(state)
|
||||||
|
{
|
||||||
|
case SCE_NSIS_DEFAULT:
|
||||||
|
if( cNextChar == EOF )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i,SCE_NSIS_DEFAULT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( cCurrChar == ';' || cCurrChar == '#' ) // we have a comment line
|
||||||
|
{
|
||||||
|
styler.ColourTo(i-1, state );
|
||||||
|
state = SCE_NSIS_COMMENT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( cCurrChar == '"' )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i-1, state );
|
||||||
|
state = SCE_NSIS_STRINGDQ;
|
||||||
|
bVarInString = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( cCurrChar == '\'' )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i-1, state );
|
||||||
|
state = SCE_NSIS_STRINGRQ;
|
||||||
|
bVarInString = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( cCurrChar == '`' )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i-1, state );
|
||||||
|
state = SCE_NSIS_STRINGLQ;
|
||||||
|
bVarInString = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NSIS KeyWord,Function, Variable, UserDefined:
|
||||||
|
if( cCurrChar == '$' || iswordchar(cCurrChar) || cCurrChar == '!' )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i-1,state);
|
||||||
|
state = SCE_NSIS_FUNCTION;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SCE_NSIS_COMMENT:
|
||||||
|
if( cNextChar == '\n' || cNextChar == '\r' || cNextChar == EOF )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i,state);
|
||||||
|
state = SCE_NSIS_DEFAULT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SCE_NSIS_STRINGDQ:
|
||||||
|
if( cCurrChar == '"' || cNextChar == '\r' || cNextChar == '\n' )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i,SCE_NSIS_STRINGDQ);
|
||||||
|
state = SCE_NSIS_DEFAULT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SCE_NSIS_STRINGLQ:
|
||||||
|
if( cCurrChar == '`' || cNextChar == '\r' || cNextChar == '\n' )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i,SCE_NSIS_STRINGLQ);
|
||||||
|
state = SCE_NSIS_DEFAULT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SCE_NSIS_STRINGRQ:
|
||||||
|
if( cCurrChar == '\'' || cNextChar == '\r' || cNextChar == '\n' )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i,SCE_NSIS_STRINGRQ);
|
||||||
|
state = SCE_NSIS_DEFAULT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SCE_NSIS_FUNCTION:
|
||||||
|
|
||||||
|
// NSIS KeyWord:
|
||||||
|
if( (iswordchar(cCurrChar) && !iswordchar( cNextChar) && cNextChar != '}') || cCurrChar == '}' )
|
||||||
|
{
|
||||||
|
state = classifyWordNsis( styler.GetStartSegment(), i, keywordLists, styler);
|
||||||
|
styler.ColourTo( i, state);
|
||||||
|
state = SCE_NSIS_DEFAULT; // Everything after goes back to the default state
|
||||||
|
}
|
||||||
|
else if( !iswordchar( cCurrChar ) && cCurrChar != '{' && cCurrChar != '}' )
|
||||||
|
{
|
||||||
|
state = SCE_NSIS_DEFAULT;
|
||||||
|
|
||||||
|
if( cCurrChar == '"' ) // Next
|
||||||
|
{
|
||||||
|
state = SCE_NSIS_STRINGDQ;
|
||||||
|
bVarInString = false;
|
||||||
|
}
|
||||||
|
if( cCurrChar == '`' )
|
||||||
|
{
|
||||||
|
state = SCE_NSIS_STRINGLQ;
|
||||||
|
bVarInString = false;
|
||||||
|
}
|
||||||
|
if( cCurrChar == '\'' )
|
||||||
|
{
|
||||||
|
state = SCE_NSIS_STRINGRQ;
|
||||||
|
bVarInString = false;
|
||||||
|
}
|
||||||
|
if( cCurrChar == '#' || cCurrChar == ';' )
|
||||||
|
state = SCE_NSIS_COMMENT;
|
||||||
|
|
||||||
|
styler.ColourTo( i, state);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( state == SCE_NSIS_COMMENT )
|
||||||
|
{
|
||||||
|
styler.ColourTo(i,state);
|
||||||
|
}
|
||||||
|
else if( state == SCE_NSIS_STRINGDQ || state == SCE_NSIS_STRINGLQ || state == SCE_NSIS_STRINGRQ )
|
||||||
|
{
|
||||||
|
// Check for var in String..
|
||||||
|
if( bVarInString && (iswordchar(cCurrChar) || cCurrChar == '}') ) // || cCurrChar == '{' ) )
|
||||||
|
{
|
||||||
|
int nWordState = classifyWordNsis( styler.GetStartSegment(), i, keywordLists, styler);
|
||||||
|
if( nWordState == SCE_NSIS_VARIABLE )
|
||||||
|
{
|
||||||
|
styler.ColourTo( i, SCE_NSIS_STRINGVAR);
|
||||||
|
bVarInString = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( cCurrChar == '$' )
|
||||||
|
{
|
||||||
|
styler.ColourTo( i-1, state);
|
||||||
|
bVarInString = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void FoldNsisDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler)
|
||||||
|
{
|
||||||
|
// No folding enabled, no reason to continue...
|
||||||
|
if( styler.GetPropertyInt("fold") == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned int endPos = startPos + length;
|
||||||
|
int lineCurrent = styler.GetLine(startPos);
|
||||||
|
int levelCurrent = SC_FOLDLEVELBASE;
|
||||||
|
if (lineCurrent > 0)
|
||||||
|
levelCurrent = styler.LevelAt(lineCurrent-1) >> 16;
|
||||||
|
int levelNext = levelCurrent;
|
||||||
|
char chNext = styler[startPos];
|
||||||
|
int styleNext = styler.StyleAt(startPos);
|
||||||
|
int style;
|
||||||
|
|
||||||
|
for (unsigned int i = startPos; i < endPos; i++)
|
||||||
|
{
|
||||||
|
char ch = chNext;
|
||||||
|
chNext = styler.SafeGetCharAt(i + 1);
|
||||||
|
style = styleNext;
|
||||||
|
styleNext = styler.StyleAt(i + 1);
|
||||||
|
bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
|
||||||
|
// Functions Start: Function, Section, SubSection
|
||||||
|
// Functions End: FunctionEnd, SectionEnd, SubSectionEnd
|
||||||
|
// Label Start: !ifdef, !ifndef
|
||||||
|
// Label End: !endif
|
||||||
|
|
||||||
|
if( style == SCE_NSIS_FUNCTION )
|
||||||
|
{
|
||||||
|
if( styler.Match(i, "FunctionEnd") )
|
||||||
|
levelNext--;
|
||||||
|
else if( styler.Match(i, "Function") )
|
||||||
|
levelNext++;
|
||||||
|
}
|
||||||
|
else if( style == SCE_NSIS_SECTIONDEF )
|
||||||
|
{
|
||||||
|
if( styler.Match(i, "SectionEnd") )
|
||||||
|
levelNext--;
|
||||||
|
else if( styler.Match(i, "Section") )
|
||||||
|
levelNext++;
|
||||||
|
}
|
||||||
|
else if( style == SCE_NSIS_SUBSECTIONDEF )
|
||||||
|
{
|
||||||
|
if( styler.Match(i, "SubSectionEnd") )
|
||||||
|
levelNext--;
|
||||||
|
else if( styler.Match(i, "SubSection") )
|
||||||
|
levelNext++;
|
||||||
|
}
|
||||||
|
else if( style == SCE_NSIS_IFDEFINEDEF )
|
||||||
|
{
|
||||||
|
if( styler.Match(i, "!endif") )
|
||||||
|
levelNext--;
|
||||||
|
else if( styler.Match(i, "!ifdef") || styler.Match(i, "!ifndef"))
|
||||||
|
levelNext++;
|
||||||
|
}
|
||||||
|
else if( style == SCE_NSIS_MACRODEF )
|
||||||
|
{
|
||||||
|
if( styler.Match(i, "!macroend") )
|
||||||
|
levelNext--;
|
||||||
|
else if( styler.Match(i, "!macro") )
|
||||||
|
levelNext++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( atEOL )
|
||||||
|
{
|
||||||
|
int levelUse = levelCurrent;
|
||||||
|
int lev = levelUse | levelNext << 16;
|
||||||
|
if (levelUse < levelNext)
|
||||||
|
lev |= SC_FOLDLEVELHEADERFLAG;
|
||||||
|
if (lev != styler.LevelAt(lineCurrent))
|
||||||
|
{
|
||||||
|
styler.SetLevel(lineCurrent, lev);
|
||||||
|
}
|
||||||
|
lineCurrent++;
|
||||||
|
levelCurrent = levelNext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int levelUse = levelCurrent;
|
||||||
|
int lev = levelUse | levelNext << 16;
|
||||||
|
if (levelUse < levelNext)
|
||||||
|
lev |= SC_FOLDLEVELHEADERFLAG;
|
||||||
|
if (lev != styler.LevelAt(lineCurrent))
|
||||||
|
{
|
||||||
|
styler.SetLevel(lineCurrent, lev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * const nsisWordLists[] = {
|
||||||
|
"Functions",
|
||||||
|
"Variables",
|
||||||
|
"Lables",
|
||||||
|
"UserDefined",
|
||||||
|
0, };
|
||||||
|
|
||||||
|
|
||||||
|
LexerModule lmNsis(SCLEX_NSIS, ColouriseNsisDoc, "nsis", FoldNsisDoc, nsisWordLists);
|
344
contrib/src/stc/scintilla/src/LexPS.cxx
Normal file
344
contrib/src/stc/scintilla/src/LexPS.cxx
Normal file
@@ -0,0 +1,344 @@
|
|||||||
|
// Scintilla source code edit control
|
||||||
|
/** @file LexPS.cxx
|
||||||
|
** Lexer for PostScript
|
||||||
|
**
|
||||||
|
** Written by Nigel Hathaway <nigel@bprj.co.uk>.
|
||||||
|
** The License.txt file describes the conditions under which this software may be distributed.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
|
#include "PropSet.h"
|
||||||
|
#include "Accessor.h"
|
||||||
|
#include "StyleContext.h"
|
||||||
|
#include "KeyWords.h"
|
||||||
|
#include "Scintilla.h"
|
||||||
|
#include "SciLexer.h"
|
||||||
|
|
||||||
|
static inline bool IsASelfDelimitingChar(const int ch) {
|
||||||
|
return (ch == '[' || ch == ']' || ch == '{' || ch == '}' ||
|
||||||
|
ch == '/' || ch == '<' || ch == '>' ||
|
||||||
|
ch == '(' || ch == ')' || ch == '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool IsAWhitespaceChar(const int ch) {
|
||||||
|
return (ch == ' ' || ch == '\t' || ch == '\r' ||
|
||||||
|
ch == '\n' || ch == '\f' || ch == '\0');
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsABaseNDigit(const int ch, const int base) {
|
||||||
|
int maxdig = '9';
|
||||||
|
int letterext = -1;
|
||||||
|
|
||||||
|
if (base <= 10)
|
||||||
|
maxdig = '0' + base - 1;
|
||||||
|
else
|
||||||
|
letterext = base - 11;
|
||||||
|
|
||||||
|
return ((ch >= '0' && ch <= maxdig) ||
|
||||||
|
(ch >= 'A' && ch <= ('A' + letterext)) ||
|
||||||
|
(ch >= 'a' && ch <= ('a' + letterext)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool IsABase85Char(const int ch) {
|
||||||
|
return ((ch >= '!' && ch <= 'u') || ch == 'z');
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ColourisePSDoc(
|
||||||
|
unsigned int startPos,
|
||||||
|
int length,
|
||||||
|
int initStyle,
|
||||||
|
WordList *keywordlists[],
|
||||||
|
Accessor &styler) {
|
||||||
|
|
||||||
|
WordList &keywords1 = *keywordlists[0];
|
||||||
|
WordList &keywords2 = *keywordlists[1];
|
||||||
|
WordList &keywords3 = *keywordlists[2];
|
||||||
|
WordList &keywords4 = *keywordlists[3];
|
||||||
|
WordList &keywords5 = *keywordlists[4];
|
||||||
|
|
||||||
|
StyleContext sc(startPos, length, initStyle, styler);
|
||||||
|
|
||||||
|
bool tokenizing = styler.GetPropertyInt("ps.tokenize") != 0;
|
||||||
|
int pslevel = styler.GetPropertyInt("ps.level", 3);
|
||||||
|
int lineCurrent = styler.GetLine(startPos);
|
||||||
|
int nestTextCurrent = 0;
|
||||||
|
if (lineCurrent > 0 && initStyle == SCE_PS_TEXT)
|
||||||
|
nestTextCurrent = styler.GetLineState(lineCurrent - 1);
|
||||||
|
int numRadix = 0;
|
||||||
|
bool numHasPoint = false;
|
||||||
|
bool numHasExponent = false;
|
||||||
|
bool numHasSign = false;
|
||||||
|
|
||||||
|
// Clear out existing tokenization
|
||||||
|
if (tokenizing && length > 0) {
|
||||||
|
styler.StartAt(startPos, static_cast<char>(INDIC2_MASK));
|
||||||
|
styler.ColourTo(startPos + length-1, 0);
|
||||||
|
styler.Flush();
|
||||||
|
styler.StartAt(startPos);
|
||||||
|
styler.StartSegment(startPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; sc.More(); sc.Forward()) {
|
||||||
|
if (sc.atLineStart)
|
||||||
|
lineCurrent = styler.GetLine(sc.currentPos);
|
||||||
|
|
||||||
|
// Determine if the current state should terminate.
|
||||||
|
if (sc.state == SCE_PS_COMMENT || sc.state == SCE_PS_DSC_VALUE) {
|
||||||
|
if (sc.atLineEnd) {
|
||||||
|
sc.SetState(SCE_C_DEFAULT);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_PS_DSC_COMMENT) {
|
||||||
|
if (sc.ch == ':') {
|
||||||
|
sc.Forward();
|
||||||
|
if (!sc.atLineEnd)
|
||||||
|
sc.SetState(SCE_PS_DSC_VALUE);
|
||||||
|
else
|
||||||
|
sc.SetState(SCE_C_DEFAULT);
|
||||||
|
} else if (sc.atLineEnd) {
|
||||||
|
sc.SetState(SCE_C_DEFAULT);
|
||||||
|
} else if (IsAWhitespaceChar(sc.ch)) {
|
||||||
|
sc.ChangeState(SCE_PS_COMMENT);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_PS_NUMBER) {
|
||||||
|
if (IsASelfDelimitingChar(sc.ch) || IsAWhitespaceChar(sc.ch)) {
|
||||||
|
if ((sc.chPrev == '+' || sc.chPrev == '-' ||
|
||||||
|
sc.chPrev == 'E' || sc.chPrev == 'e') && numRadix == 0)
|
||||||
|
sc.ChangeState(SCE_PS_NAME);
|
||||||
|
sc.SetState(SCE_C_DEFAULT);
|
||||||
|
} else if (sc.ch == '#') {
|
||||||
|
if (numHasPoint || numHasExponent || numHasSign || numRadix != 0) {
|
||||||
|
sc.ChangeState(SCE_PS_NAME);
|
||||||
|
} else {
|
||||||
|
char szradix[5];
|
||||||
|
sc.GetCurrent(szradix, 4);
|
||||||
|
numRadix = atoi(szradix);
|
||||||
|
if (numRadix < 2 || numRadix > 36)
|
||||||
|
sc.ChangeState(SCE_PS_NAME);
|
||||||
|
}
|
||||||
|
} else if ((sc.ch == 'E' || sc.ch == 'e') && numRadix == 0) {
|
||||||
|
if (numHasExponent) {
|
||||||
|
sc.ChangeState(SCE_PS_NAME);
|
||||||
|
} else {
|
||||||
|
numHasExponent = true;
|
||||||
|
if (sc.chNext == '+' || sc.chNext == '-')
|
||||||
|
sc.Forward();
|
||||||
|
}
|
||||||
|
} else if (sc.ch == '.') {
|
||||||
|
if (numHasPoint || numHasExponent || numRadix != 0) {
|
||||||
|
sc.ChangeState(SCE_PS_NAME);
|
||||||
|
} else {
|
||||||
|
numHasPoint = true;
|
||||||
|
}
|
||||||
|
} else if (numRadix == 0) {
|
||||||
|
if (!IsABaseNDigit(sc.ch, 10))
|
||||||
|
sc.ChangeState(SCE_PS_NAME);
|
||||||
|
} else {
|
||||||
|
if (!IsABaseNDigit(sc.ch, numRadix))
|
||||||
|
sc.ChangeState(SCE_PS_NAME);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_PS_NAME || sc.state == SCE_PS_KEYWORD) {
|
||||||
|
if (IsASelfDelimitingChar(sc.ch) || IsAWhitespaceChar(sc.ch)) {
|
||||||
|
char s[100];
|
||||||
|
sc.GetCurrent(s, sizeof(s));
|
||||||
|
if ((pslevel >= 1 && keywords1.InList(s)) ||
|
||||||
|
(pslevel >= 2 && keywords2.InList(s)) ||
|
||||||
|
(pslevel >= 3 && keywords3.InList(s)) ||
|
||||||
|
keywords4.InList(s) || keywords5.InList(s)) {
|
||||||
|
sc.ChangeState(SCE_PS_KEYWORD);
|
||||||
|
}
|
||||||
|
sc.SetState(SCE_C_DEFAULT);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_PS_LITERAL || sc.state == SCE_PS_IMMEVAL) {
|
||||||
|
if (IsASelfDelimitingChar(sc.ch) || IsAWhitespaceChar(sc.ch))
|
||||||
|
sc.SetState(SCE_C_DEFAULT);
|
||||||
|
} else if (sc.state == SCE_PS_PAREN_ARRAY || sc.state == SCE_PS_PAREN_DICT ||
|
||||||
|
sc.state == SCE_PS_PAREN_PROC) {
|
||||||
|
sc.SetState(SCE_C_DEFAULT);
|
||||||
|
} else if (sc.state == SCE_PS_TEXT) {
|
||||||
|
if (sc.ch == '(') {
|
||||||
|
nestTextCurrent++;
|
||||||
|
} else if (sc.ch == ')') {
|
||||||
|
if (--nestTextCurrent == 0)
|
||||||
|
sc.ForwardSetState(SCE_PS_DEFAULT);
|
||||||
|
} else if (sc.ch == '\\') {
|
||||||
|
sc.Forward();
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_PS_HEXSTRING) {
|
||||||
|
if (sc.ch == '>') {
|
||||||
|
sc.ForwardSetState(SCE_PS_DEFAULT);
|
||||||
|
} else if (!IsABaseNDigit(sc.ch, 16) && !IsAWhitespaceChar(sc.ch)) {
|
||||||
|
sc.SetState(SCE_PS_HEXSTRING);
|
||||||
|
styler.ColourTo(sc.currentPos, SCE_PS_BADSTRINGCHAR);
|
||||||
|
}
|
||||||
|
} else if (sc.state == SCE_PS_BASE85STRING) {
|
||||||
|
if (sc.Match('~', '>')) {
|
||||||
|
sc.Forward();
|
||||||
|
sc.ForwardSetState(SCE_PS_DEFAULT);
|
||||||
|
} else if (!IsABase85Char(sc.ch) && !IsAWhitespaceChar(sc.ch)) {
|
||||||
|
sc.SetState(SCE_PS_BASE85STRING);
|
||||||
|
styler.ColourTo(sc.currentPos, SCE_PS_BADSTRINGCHAR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if a new state should be entered.
|
||||||
|
if (sc.state == SCE_C_DEFAULT) {
|
||||||
|
unsigned int tokenpos = sc.currentPos;
|
||||||
|
|
||||||
|
if (sc.ch == '[' || sc.ch == ']') {
|
||||||
|
sc.SetState(SCE_PS_PAREN_ARRAY);
|
||||||
|
} else if (sc.ch == '{' || sc.ch == '}') {
|
||||||
|
sc.SetState(SCE_PS_PAREN_PROC);
|
||||||
|
} else if (sc.ch == '/') {
|
||||||
|
if (sc.chNext == '/') {
|
||||||
|
sc.SetState(SCE_PS_IMMEVAL);
|
||||||
|
sc.Forward();
|
||||||
|
} else {
|
||||||
|
sc.SetState(SCE_PS_LITERAL);
|
||||||
|
}
|
||||||
|
} else if (sc.ch == '<') {
|
||||||
|
if (sc.chNext == '<') {
|
||||||
|
sc.SetState(SCE_PS_PAREN_DICT);
|
||||||
|
sc.Forward();
|
||||||
|
} else if (sc.chNext == '~') {
|
||||||
|
sc.SetState(SCE_PS_BASE85STRING);
|
||||||
|
sc.Forward();
|
||||||
|
} else {
|
||||||
|
sc.SetState(SCE_PS_HEXSTRING);
|
||||||
|
}
|
||||||
|
} else if (sc.ch == '>' && sc.chNext == '>') {
|
||||||
|
sc.SetState(SCE_PS_PAREN_DICT);
|
||||||
|
sc.Forward();
|
||||||
|
} else if (sc.ch == '>' || sc.ch == ')') {
|
||||||
|
sc.SetState(SCE_C_DEFAULT);
|
||||||
|
styler.ColourTo(sc.currentPos, SCE_PS_BADSTRINGCHAR);
|
||||||
|
} else if (sc.ch == '(') {
|
||||||
|
sc.SetState(SCE_PS_TEXT);
|
||||||
|
nestTextCurrent = 1;
|
||||||
|
} else if (sc.ch == '%') {
|
||||||
|
if (sc.chNext == '%' && sc.atLineStart) {
|
||||||
|
sc.SetState(SCE_PS_DSC_COMMENT);
|
||||||
|
sc.Forward();
|
||||||
|
if (sc.chNext == '+') {
|
||||||
|
sc.Forward();
|
||||||
|
sc.ForwardSetState(SCE_PS_DSC_VALUE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sc.SetState(SCE_PS_COMMENT);
|
||||||
|
}
|
||||||
|
} else if ((sc.ch == '+' || sc.ch == '-' || sc.ch == '.') &&
|
||||||
|
IsABaseNDigit(sc.chNext, 10)) {
|
||||||
|
sc.SetState(SCE_PS_NUMBER);
|
||||||
|
numRadix = 0;
|
||||||
|
numHasPoint = (sc.ch == '.');
|
||||||
|
numHasExponent = false;
|
||||||
|
numHasSign = (sc.ch == '+' || sc.ch == '-');
|
||||||
|
} else if ((sc.ch == '+' || sc.ch == '-') && sc.chNext == '.' &&
|
||||||
|
IsABaseNDigit(sc.GetRelative(2), 10)) {
|
||||||
|
sc.SetState(SCE_PS_NUMBER);
|
||||||
|
numRadix = 0;
|
||||||
|
numHasPoint = false;
|
||||||
|
numHasExponent = false;
|
||||||
|
numHasSign = true;
|
||||||
|
} else if (IsABaseNDigit(sc.ch, 10)) {
|
||||||
|
sc.SetState(SCE_PS_NUMBER);
|
||||||
|
numRadix = 0;
|
||||||
|
numHasPoint = false;
|
||||||
|
numHasExponent = false;
|
||||||
|
numHasSign = false;
|
||||||
|
} else if (!IsAWhitespaceChar(sc.ch)) {
|
||||||
|
sc.SetState(SCE_PS_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark the start of tokens
|
||||||
|
if (tokenizing && sc.state != SCE_C_DEFAULT && sc.state != SCE_PS_COMMENT &&
|
||||||
|
sc.state != SCE_PS_DSC_COMMENT && sc.state != SCE_PS_DSC_VALUE) {
|
||||||
|
styler.Flush();
|
||||||
|
styler.StartAt(tokenpos, static_cast<char>(INDIC2_MASK));
|
||||||
|
styler.ColourTo(tokenpos, INDIC2_MASK);
|
||||||
|
styler.Flush();
|
||||||
|
styler.StartAt(tokenpos);
|
||||||
|
styler.StartSegment(tokenpos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sc.atLineEnd)
|
||||||
|
styler.SetLineState(lineCurrent, nestTextCurrent);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.Complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FoldPSDoc(unsigned int startPos, int length, int, WordList *[],
|
||||||
|
Accessor &styler) {
|
||||||
|
bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
|
||||||
|
bool foldAtElse = styler.GetPropertyInt("fold.at.else", 0) != 0;
|
||||||
|
unsigned int endPos = startPos + length;
|
||||||
|
int visibleChars = 0;
|
||||||
|
int lineCurrent = styler.GetLine(startPos);
|
||||||
|
int levelCurrent = SC_FOLDLEVELBASE;
|
||||||
|
if (lineCurrent > 0)
|
||||||
|
levelCurrent = styler.LevelAt(lineCurrent-1) >> 16;
|
||||||
|
int levelMinCurrent = levelCurrent;
|
||||||
|
int levelNext = levelCurrent;
|
||||||
|
char chNext = styler[startPos];
|
||||||
|
int styleNext = styler.StyleAt(startPos);
|
||||||
|
int style;
|
||||||
|
for (unsigned int i = startPos; i < endPos; i++) {
|
||||||
|
char ch = chNext;
|
||||||
|
chNext = styler.SafeGetCharAt(i + 1);
|
||||||
|
style = styleNext;
|
||||||
|
styleNext = styler.StyleAt(i + 1);
|
||||||
|
bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); //mac??
|
||||||
|
if ((style & 31) == SCE_PS_PAREN_PROC) {
|
||||||
|
if (ch == '{') {
|
||||||
|
// Measure the minimum before a '{' to allow
|
||||||
|
// folding on "} {"
|
||||||
|
if (levelMinCurrent > levelNext) {
|
||||||
|
levelMinCurrent = levelNext;
|
||||||
|
}
|
||||||
|
levelNext++;
|
||||||
|
} else if (ch == '}') {
|
||||||
|
levelNext--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (atEOL) {
|
||||||
|
int levelUse = levelCurrent;
|
||||||
|
if (foldAtElse) {
|
||||||
|
levelUse = levelMinCurrent;
|
||||||
|
}
|
||||||
|
int lev = levelUse | levelNext << 16;
|
||||||
|
if (visibleChars == 0 && foldCompact)
|
||||||
|
lev |= SC_FOLDLEVELWHITEFLAG;
|
||||||
|
if (levelUse < levelNext)
|
||||||
|
lev |= SC_FOLDLEVELHEADERFLAG;
|
||||||
|
if (lev != styler.LevelAt(lineCurrent)) {
|
||||||
|
styler.SetLevel(lineCurrent, lev);
|
||||||
|
}
|
||||||
|
lineCurrent++;
|
||||||
|
levelCurrent = levelNext;
|
||||||
|
levelMinCurrent = levelCurrent;
|
||||||
|
visibleChars = 0;
|
||||||
|
}
|
||||||
|
if (!isspacechar(ch))
|
||||||
|
visibleChars++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * const psWordListDesc[] = {
|
||||||
|
"PS Level 1 operators",
|
||||||
|
"PS Level 2 operators",
|
||||||
|
"PS Level 3 operators",
|
||||||
|
"RIP-specific operators",
|
||||||
|
"User-defined operators",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
LexerModule lmPS(SCLEX_PS, ColourisePSDoc, "ps", FoldPSDoc, psWordListDesc);
|
427
contrib/src/stc/scintilla/src/LexScriptol.cxx
Normal file
427
contrib/src/stc/scintilla/src/LexScriptol.cxx
Normal file
@@ -0,0 +1,427 @@
|
|||||||
|
// Scintilla source code edit control
|
||||||
|
/** @file LexScriptol.cxx
|
||||||
|
** Lexer for Scriptol.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
|
#include "PropSet.h"
|
||||||
|
#include "Accessor.h"
|
||||||
|
#include "KeyWords.h"
|
||||||
|
#include "Scintilla.h"
|
||||||
|
#include "SciLexer.h"
|
||||||
|
|
||||||
|
static void ClassifyWordSol(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler, char *prevWord)
|
||||||
|
{
|
||||||
|
char s[100];
|
||||||
|
bool wordIsNumber = isdigit(styler[start]) != 0;
|
||||||
|
for (unsigned int i = 0; i < end - start + 1 && i < 30; i++)
|
||||||
|
{
|
||||||
|
s[i] = styler[start + i];
|
||||||
|
s[i + 1] = '\0';
|
||||||
|
}
|
||||||
|
char chAttr = SCE_P_IDENTIFIER;
|
||||||
|
if (0 == strcmp(prevWord, "class")) chAttr = SCE_P_CLASSNAME;
|
||||||
|
else if (wordIsNumber) chAttr = SCE_P_NUMBER;
|
||||||
|
else if (keywords.InList(s)) chAttr = SCE_P_WORD;
|
||||||
|
else for (unsigned int i = 0; i < end - start + 1; i++) // test dotted idents
|
||||||
|
{
|
||||||
|
if (styler[start + i] == '.')
|
||||||
|
{
|
||||||
|
styler.ColourTo(start + i - 1, chAttr);
|
||||||
|
styler.ColourTo(start + i, SCE_P_OPERATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
styler.ColourTo(end, chAttr);
|
||||||
|
strcpy(prevWord, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsSolComment(Accessor &styler, int pos, int len)
|
||||||
|
{
|
||||||
|
// return len > 0 && styler[pos]=='`';
|
||||||
|
char c;
|
||||||
|
if(len > 0)
|
||||||
|
{
|
||||||
|
c = styler[pos];
|
||||||
|
if(c == '`') return true;
|
||||||
|
if(len > 1)
|
||||||
|
{
|
||||||
|
if(c == '/')
|
||||||
|
{
|
||||||
|
c = styler[pos + 1];
|
||||||
|
if(c == '/') return true;
|
||||||
|
if(c == '*') return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsSolStringStart(char ch, char /*chNext*/)
|
||||||
|
{
|
||||||
|
if (ch == '\'' || ch == '"') return true;
|
||||||
|
//chNext = chNext; // for future use
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool IsSolWordStart(char ch, char chNext)
|
||||||
|
{
|
||||||
|
return (iswordchar(ch) && !IsSolStringStart(ch, chNext));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the state to use for the string starting at i; *nextIndex will be set to the first index following the quote(s) */
|
||||||
|
static int GetSolStringState(Accessor &styler, int i, int *nextIndex)
|
||||||
|
{
|
||||||
|
char ch = styler.SafeGetCharAt(i);
|
||||||
|
char chNext = styler.SafeGetCharAt(i + 1);
|
||||||
|
|
||||||
|
if (ch != '"' && ch != '\'') {
|
||||||
|
*nextIndex = i + 1;
|
||||||
|
return SCE_P_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch == chNext && ch == styler.SafeGetCharAt(i + 2))
|
||||||
|
{
|
||||||
|
*nextIndex = i + 3;
|
||||||
|
if (ch == '"') return SCE_P_TRIPLEDOUBLE;
|
||||||
|
else return SCE_P_TRIPLE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*nextIndex = i + 1;
|
||||||
|
if (ch == '"') return SCE_P_STRING;
|
||||||
|
else return SCE_P_CHARACTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ColouriseSolDoc(unsigned int startPos, int length, int initStyle,
|
||||||
|
WordList *keywordlists[], Accessor &styler)
|
||||||
|
{
|
||||||
|
|
||||||
|
int lengthDoc = startPos + length;
|
||||||
|
|
||||||
|
// Backtrack to previous line in case need to fix its tab whinging
|
||||||
|
if (startPos > 0)
|
||||||
|
{
|
||||||
|
int lineCurrent = styler.GetLine(startPos);
|
||||||
|
if (lineCurrent > 0)
|
||||||
|
{
|
||||||
|
startPos = styler.LineStart(lineCurrent-1);
|
||||||
|
if (startPos == 0) initStyle = SCE_P_DEFAULT;
|
||||||
|
else initStyle = styler.StyleAt(startPos-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
styler.StartAt(startPos, 127);
|
||||||
|
|
||||||
|
WordList &keywords = *keywordlists[0];
|
||||||
|
|
||||||
|
int whingeLevel = styler.GetPropertyInt("tab.timmy.whinge.level");
|
||||||
|
char prevWord[200];
|
||||||
|
prevWord[0] = '\0';
|
||||||
|
if (length == 0) return ;
|
||||||
|
|
||||||
|
int state = initStyle & 31;
|
||||||
|
|
||||||
|
int nextIndex = 0;
|
||||||
|
char chPrev = ' ';
|
||||||
|
//char chPrev2 = ' ';
|
||||||
|
char chNext = styler[startPos];
|
||||||
|
styler.StartSegment(startPos);
|
||||||
|
bool atStartLine = true;
|
||||||
|
int spaceFlags = 0;
|
||||||
|
for (int i = startPos; i < lengthDoc; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (atStartLine)
|
||||||
|
{
|
||||||
|
char chBad = static_cast<char>(64);
|
||||||
|
char chGood = static_cast<char>(0);
|
||||||
|
char chFlags = chGood;
|
||||||
|
|
||||||
|
if (whingeLevel == 1)
|
||||||
|
{
|
||||||
|
chFlags = (spaceFlags & wsInconsistent) ? chBad : chGood;
|
||||||
|
}
|
||||||
|
else if (whingeLevel == 2)
|
||||||
|
{
|
||||||
|
chFlags = (spaceFlags & wsSpaceTab) ? chBad : chGood;
|
||||||
|
}
|
||||||
|
else if (whingeLevel == 3)
|
||||||
|
{
|
||||||
|
chFlags = (spaceFlags & wsSpace) ? chBad : chGood;
|
||||||
|
}
|
||||||
|
else if (whingeLevel == 4)
|
||||||
|
{
|
||||||
|
chFlags = (spaceFlags & wsTab) ? chBad : chGood;
|
||||||
|
}
|
||||||
|
styler.SetFlags(chFlags, static_cast<char>(state));
|
||||||
|
atStartLine = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char ch = chNext;
|
||||||
|
chNext = styler.SafeGetCharAt(i + 1);
|
||||||
|
|
||||||
|
if ((ch == '\r' && chNext != '\n') || (ch == '\n') || (i == lengthDoc))
|
||||||
|
{
|
||||||
|
if ((state == SCE_P_DEFAULT) || (state == SCE_P_TRIPLE) || (state == SCE_P_TRIPLEDOUBLE))
|
||||||
|
{
|
||||||
|
styler.ColourTo(i, state);
|
||||||
|
}
|
||||||
|
atStartLine = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (styler.IsLeadByte(ch))
|
||||||
|
{
|
||||||
|
chNext = styler.SafeGetCharAt(i + 2);
|
||||||
|
chPrev = ' ';
|
||||||
|
//chPrev2 = ' ';
|
||||||
|
i += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == SCE_P_STRINGEOL)
|
||||||
|
{
|
||||||
|
if (ch != '\r' && ch != '\n')
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
state = SCE_P_DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == SCE_P_DEFAULT)
|
||||||
|
{
|
||||||
|
if (IsSolWordStart(ch, chNext))
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
state = SCE_P_WORD;
|
||||||
|
}
|
||||||
|
else if (ch == '`')
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
state = SCE_P_COMMENTLINE;
|
||||||
|
}
|
||||||
|
else if (ch == '/')
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
if(chNext == '/') state = SCE_P_COMMENTLINE;
|
||||||
|
if(chNext == '*') state = SCE_P_COMMENTBLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (ch == '=' && chNext == 'b')
|
||||||
|
{
|
||||||
|
// =begin indicates the start of a comment (doc) block
|
||||||
|
if(styler.SafeGetCharAt(i + 2) == 'e' && styler.SafeGetCharAt(i + 3) == 'g' && styler.SafeGetCharAt(i + 4) == 'i' && styler.SafeGetCharAt(i + 5) == 'n')
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
state = SCE_P_TRIPLEDOUBLE; //SCE_C_COMMENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (IsSolStringStart(ch, chNext))
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
state = GetSolStringState(styler, i, &nextIndex);
|
||||||
|
if (nextIndex != i + 1)
|
||||||
|
{
|
||||||
|
i = nextIndex - 1;
|
||||||
|
ch = ' ';
|
||||||
|
//chPrev = ' ';
|
||||||
|
chNext = styler.SafeGetCharAt(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isoperator(ch))
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
styler.ColourTo(i, SCE_P_OPERATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (state == SCE_P_WORD)
|
||||||
|
{
|
||||||
|
if (!iswordchar(ch))
|
||||||
|
{
|
||||||
|
ClassifyWordSol(styler.GetStartSegment(), i - 1, keywords, styler, prevWord);
|
||||||
|
state = SCE_P_DEFAULT;
|
||||||
|
if (ch == '`')
|
||||||
|
{
|
||||||
|
state = chNext == '`' ? SCE_P_COMMENTBLOCK : SCE_P_COMMENTLINE;
|
||||||
|
}
|
||||||
|
else if (IsSolStringStart(ch, chNext))
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
state = GetSolStringState(styler, i, &nextIndex);
|
||||||
|
if (nextIndex != i + 1)
|
||||||
|
{
|
||||||
|
i = nextIndex - 1;
|
||||||
|
ch = ' ';
|
||||||
|
//chPrev = ' ';
|
||||||
|
chNext = styler.SafeGetCharAt(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isoperator(ch))
|
||||||
|
{
|
||||||
|
styler.ColourTo(i, SCE_P_OPERATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (state == SCE_P_COMMENTLINE)
|
||||||
|
{
|
||||||
|
if (ch == '\r' || ch == '\n')
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
state = SCE_P_DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(state == SCE_P_COMMENTBLOCK)
|
||||||
|
{
|
||||||
|
if(ch == '*' && chNext == '/') state = SCE_P_DEFAULT;
|
||||||
|
}
|
||||||
|
else if (state == SCE_P_STRING)
|
||||||
|
{
|
||||||
|
if ((ch == '\r' || ch == '\n') && (chPrev != '\\'))
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
state = SCE_P_STRINGEOL;
|
||||||
|
}
|
||||||
|
else if (ch == '\\')
|
||||||
|
{
|
||||||
|
if (chNext == '\"' || chNext == '\'' || chNext == '\\')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
ch = chNext;
|
||||||
|
chNext = styler.SafeGetCharAt(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch == '\"')
|
||||||
|
{
|
||||||
|
styler.ColourTo(i, state);
|
||||||
|
state = SCE_P_DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (state == SCE_P_CHARACTER)
|
||||||
|
{
|
||||||
|
if ((ch == '\r' || ch == '\n') && (chPrev != '\\'))
|
||||||
|
{
|
||||||
|
styler.ColourTo(i - 1, state);
|
||||||
|
state = SCE_P_STRINGEOL;
|
||||||
|
}
|
||||||
|
else if (ch == '\\')
|
||||||
|
{
|
||||||
|
if (chNext == '\"' || chNext == '\'' || chNext == '\\')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
ch = chNext;
|
||||||
|
chNext = styler.SafeGetCharAt(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch == '\'')
|
||||||
|
{
|
||||||
|
styler.ColourTo(i, state);
|
||||||
|
state = SCE_P_DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
else if (state == SCE_P_TRIPLE)
|
||||||
|
{
|
||||||
|
if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'')
|
||||||
|
{
|
||||||
|
styler.ColourTo(i, state);
|
||||||
|
state = SCE_P_DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (state == SCE_P_TRIPLEDOUBLE)
|
||||||
|
{
|
||||||
|
// =end terminates the comment block
|
||||||
|
if (ch == 'd' && chPrev == 'n' && chPrev2 == 'e')
|
||||||
|
{
|
||||||
|
if (styler.SafeGetCharAt(i - 3) == '=')
|
||||||
|
{
|
||||||
|
styler.ColourTo(i, state);
|
||||||
|
state = SCE_P_DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
//chPrev2 = chPrev;
|
||||||
|
chPrev = ch;
|
||||||
|
}
|
||||||
|
if (state == SCE_P_WORD)
|
||||||
|
{
|
||||||
|
ClassifyWordSol(styler.GetStartSegment(), lengthDoc-1, keywords, styler, prevWord);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
styler.ColourTo(lengthDoc-1, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FoldSolDoc(unsigned int startPos, int length, int initStyle,
|
||||||
|
WordList *[], Accessor &styler)
|
||||||
|
{
|
||||||
|
int lengthDoc = startPos + length;
|
||||||
|
|
||||||
|
// Backtrack to previous line in case need to fix its fold status
|
||||||
|
int lineCurrent = styler.GetLine(startPos);
|
||||||
|
if (startPos > 0) {
|
||||||
|
if (lineCurrent > 0)
|
||||||
|
{
|
||||||
|
lineCurrent--;
|
||||||
|
startPos = styler.LineStart(lineCurrent);
|
||||||
|
if (startPos == 0)
|
||||||
|
initStyle = SCE_P_DEFAULT;
|
||||||
|
else
|
||||||
|
initStyle = styler.StyleAt(startPos-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int state = initStyle & 31;
|
||||||
|
int spaceFlags = 0;
|
||||||
|
int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, IsSolComment);
|
||||||
|
if ((state == SCE_P_TRIPLE) || (state == SCE_P_TRIPLEDOUBLE))
|
||||||
|
indentCurrent |= SC_FOLDLEVELWHITEFLAG;
|
||||||
|
char chNext = styler[startPos];
|
||||||
|
for (int i = startPos; i < lengthDoc; i++)
|
||||||
|
{
|
||||||
|
char ch = chNext;
|
||||||
|
chNext = styler.SafeGetCharAt(i + 1);
|
||||||
|
int style = styler.StyleAt(i) & 31;
|
||||||
|
|
||||||
|
if ((ch == '\r' && chNext != '\n') || (ch == '\n') || (i == lengthDoc))
|
||||||
|
{
|
||||||
|
int lev = indentCurrent;
|
||||||
|
int indentNext = styler.IndentAmount(lineCurrent + 1, &spaceFlags, IsSolComment);
|
||||||
|
if ((style == SCE_P_TRIPLE) || (style== SCE_P_TRIPLEDOUBLE))
|
||||||
|
indentNext |= SC_FOLDLEVELWHITEFLAG;
|
||||||
|
if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG))
|
||||||
|
{
|
||||||
|
// Only non whitespace lines can be headers
|
||||||
|
if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < (indentNext & SC_FOLDLEVELNUMBERMASK))
|
||||||
|
{
|
||||||
|
lev |= SC_FOLDLEVELHEADERFLAG;
|
||||||
|
} else if (indentNext & SC_FOLDLEVELWHITEFLAG)
|
||||||
|
{
|
||||||
|
// Line after is blank so check the next - maybe should continue further?
|
||||||
|
int spaceFlags2 = 0;
|
||||||
|
int indentNext2 = styler.IndentAmount(lineCurrent + 2, &spaceFlags2, IsSolComment);
|
||||||
|
if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < (indentNext2 & SC_FOLDLEVELNUMBERMASK))
|
||||||
|
{
|
||||||
|
lev |= SC_FOLDLEVELHEADERFLAG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
indentCurrent = indentNext;
|
||||||
|
styler.SetLevel(lineCurrent, lev);
|
||||||
|
lineCurrent++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LexerModule lmScriptol(SCLEX_SCRIPTOL, ColouriseSolDoc, "scriptol", FoldSolDoc);
|
Reference in New Issue
Block a user