From 3fa7576e13e129900a6e0acbd5460237f9a1b614 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Wed, 1 Aug 2018 14:51:52 +0200 Subject: [PATCH] Update Scintilla to version 3.10.0 Scintilla 3.7.6/4.0.0 deprecated `SCE_*STYLEBITS*` and moved it to deprecated features that require a build-time flag to be available. Thus, drop use of those (as they are now no-ops anyway) and bump the ABI (so plugins depending on those don't build mistakenly load) and API (so a developer can guard use of those if wanted) version accordingly. --- plugins/export.c | 10 +- scintilla/License.txt | 28 +- scintilla/Makefile.am | 6 + scintilla/gtk/Converter.h | 4 - scintilla/gtk/PlatGTK.cxx | 280 ++--- scintilla/gtk/ScintillaGTK.cxx | 183 ++- scintilla/gtk/ScintillaGTK.h | 17 +- scintilla/gtk/ScintillaGTKAccessible.cxx | 7 +- scintilla/gtk/ScintillaGTKAccessible.h | 6 +- scintilla/gtk/scintilla-marshal.c | 33 +- scintilla/gtk/scintilla-marshal.h | 44 +- scintilla/gtk/scintilla-marshal.list | 4 +- scintilla/include/ILexer.h | 22 +- scintilla/include/ILoader.h | 21 + scintilla/include/Platform.h | 299 +++-- scintilla/include/SciLexer.h | 14 + scintilla/include/Sci_Position.h | 12 +- scintilla/include/Scintilla.h | 26 +- scintilla/include/Scintilla.iface | 85 +- scintilla/lexers/LexAbaqus.cxx | 2 - scintilla/lexers/LexAda.cxx | 2 - scintilla/lexers/LexAsm.cxx | 5 +- scintilla/lexers/LexBash.cxx | 2 - scintilla/lexers/LexBasic.cxx | 5 +- scintilla/lexers/LexBatch.cxx | 2 - scintilla/lexers/LexCOBOL.cxx | 2 - scintilla/lexers/LexCPP.cxx | 183 ++- scintilla/lexers/LexCSS.cxx | 6 +- scintilla/lexers/LexCaml.cxx | 7 +- scintilla/lexers/LexCmake.cxx | 2 - scintilla/lexers/LexCoffeeScript.cxx | 7 +- scintilla/lexers/LexD.cxx | 5 +- scintilla/lexers/LexDiff.cxx | 10 +- scintilla/lexers/LexErlang.cxx | 7 +- scintilla/lexers/LexForth.cxx | 2 - scintilla/lexers/LexFortran.cxx | 16 +- scintilla/lexers/LexHTML.cxx | 820 ++++++++----- scintilla/lexers/LexHaskell.cxx | 5 +- scintilla/lexers/LexLaTeX.cxx | 4 +- scintilla/lexers/LexLisp.cxx | 2 - scintilla/lexers/LexLua.cxx | 184 ++- scintilla/lexers/LexMake.cxx | 2 - scintilla/lexers/LexMarkdown.cxx | 2 - scintilla/lexers/LexMatlab.cxx | 29 +- scintilla/lexers/LexNsis.cxx | 2 - scintilla/lexers/LexNull.cxx | 2 - scintilla/lexers/LexPO.cxx | 2 - scintilla/lexers/LexPascal.cxx | 2 - scintilla/lexers/LexPerl.cxx | 18 +- scintilla/lexers/LexPowerShell.cxx | 2 - scintilla/lexers/LexProps.cxx | 2 - scintilla/lexers/LexPython.cxx | 53 +- scintilla/lexers/LexR.cxx | 2 - scintilla/lexers/LexRuby.cxx | 4 +- scintilla/lexers/LexRust.cxx | 11 +- scintilla/lexers/LexSQL.cxx | 7 +- scintilla/lexers/LexTCL.cxx | 3 +- scintilla/lexers/LexTxt2tags.cxx | 2 - scintilla/lexers/LexVHDL.cxx | 101 +- scintilla/lexers/LexVerilog.cxx | 5 +- scintilla/lexers/LexYAML.cxx | 2 - scintilla/lexlib/Accessor.cxx | 2 - scintilla/lexlib/Accessor.h | 4 - scintilla/lexlib/CharacterCategory.cxx | 9 +- scintilla/lexlib/CharacterCategory.h | 4 - scintilla/lexlib/CharacterSet.cxx | 14 +- scintilla/lexlib/CharacterSet.h | 16 +- scintilla/lexlib/DefaultLexer.cxx | 125 ++ scintilla/lexlib/DefaultLexer.h | 51 + scintilla/lexlib/LexAccessor.h | 18 +- scintilla/lexlib/LexerBase.cxx | 65 +- scintilla/lexlib/LexerBase.h | 46 +- scintilla/lexlib/LexerModule.cxx | 35 +- scintilla/lexlib/LexerModule.h | 33 +- scintilla/lexlib/LexerNoExceptions.cxx | 2 - scintilla/lexlib/LexerNoExceptions.h | 12 +- scintilla/lexlib/LexerSimple.cxx | 6 +- scintilla/lexlib/LexerSimple.h | 10 +- scintilla/lexlib/OptionSet.h | 4 - scintilla/lexlib/PropSetSimple.cxx | 36 +- scintilla/lexlib/PropSetSimple.h | 6 +- scintilla/lexlib/SparseState.h | 22 +- scintilla/lexlib/StringCopy.h | 4 - scintilla/lexlib/StyleContext.cxx | 8 +- scintilla/lexlib/StyleContext.h | 17 +- scintilla/lexlib/SubStyles.h | 38 +- scintilla/lexlib/WordList.cxx | 14 +- scintilla/lexlib/WordList.h | 4 - scintilla/scintilla_changes.patch | 4 +- scintilla/src/AutoComplete.cxx | 17 +- scintilla/src/AutoComplete.h | 18 +- scintilla/src/CallTip.cxx | 53 +- scintilla/src/CallTip.h | 8 +- scintilla/src/CaseConvert.cxx | 435 +++---- scintilla/src/CaseConvert.h | 4 - scintilla/src/CaseFolder.cxx | 5 +- scintilla/src/CaseFolder.h | 6 +- scintilla/src/Catalogue.cxx | 6 +- scintilla/src/Catalogue.h | 6 +- scintilla/src/CellBuffer.cxx | 219 ++-- scintilla/src/CellBuffer.h | 64 +- scintilla/src/CharClassify.cxx | 4 +- scintilla/src/CharClassify.h | 4 - scintilla/src/ContractionState.cxx | 274 +++-- scintilla/src/ContractionState.h | 78 +- scintilla/src/DBCS.cxx | 42 + scintilla/src/DBCS.h | 17 + scintilla/src/Decoration.cxx | 226 +++- scintilla/src/Decoration.h | 88 +- scintilla/src/Document.cxx | 715 ++++++----- scintilla/src/Document.h | 181 +-- scintilla/src/EditModel.cxx | 10 +- scintilla/src/EditModel.h | 10 +- scintilla/src/EditView.cxx | 430 ++++--- scintilla/src/EditView.h | 26 +- scintilla/src/Editor.cxx | 1434 +++++++++++----------- scintilla/src/Editor.h | 86 +- scintilla/src/ElapsedPeriod.h | 35 + scintilla/src/ExternalLexer.cxx | 4 +- scintilla/src/ExternalLexer.h | 13 +- scintilla/src/FontQuality.h | 4 - scintilla/src/Indicator.cxx | 132 +- scintilla/src/Indicator.h | 4 - scintilla/src/IntegerRectangle.h | 29 + scintilla/src/KeyMap.cxx | 3 +- scintilla/src/KeyMap.h | 4 - scintilla/src/LineMarker.cxx | 137 ++- scintilla/src/LineMarker.h | 46 +- scintilla/src/MarginView.cxx | 80 +- scintilla/src/MarginView.h | 4 - scintilla/src/Partitioning.h | 87 +- scintilla/src/PerLine.cxx | 26 +- scintilla/src/PerLine.h | 44 +- scintilla/src/Position.h | 15 +- scintilla/src/PositionCache.cxx | 113 +- scintilla/src/PositionCache.h | 45 +- scintilla/src/RESearch.cxx | 48 +- scintilla/src/RESearch.h | 12 +- scintilla/src/RunStyles.cxx | 142 ++- scintilla/src/RunStyles.h | 59 +- scintilla/src/ScintillaBase.cxx | 210 +++- scintilla/src/ScintillaBase.h | 20 +- scintilla/src/Selection.cxx | 12 +- scintilla/src/Selection.h | 4 - scintilla/src/SparseVector.h | 58 +- scintilla/src/SplitVector.h | 91 +- scintilla/src/Style.cxx | 12 +- scintilla/src/Style.h | 18 +- scintilla/src/UniConversion.cxx | 350 +++--- scintilla/src/UniConversion.h | 42 +- scintilla/src/UniqueString.h | 4 - scintilla/src/ViewStyle.cxx | 21 +- scintilla/src/ViewStyle.h | 16 +- scintilla/src/XPM.cxx | 59 +- scintilla/src/XPM.h | 25 +- scintilla/version.txt | 2 +- src/highlighting.c | 2 - src/plugindata.h | 4 +- 158 files changed, 5488 insertions(+), 4257 deletions(-) create mode 100644 scintilla/include/ILoader.h create mode 100644 scintilla/lexlib/DefaultLexer.cxx create mode 100644 scintilla/lexlib/DefaultLexer.h create mode 100644 scintilla/src/DBCS.cxx create mode 100644 scintilla/src/DBCS.h create mode 100644 scintilla/src/ElapsedPeriod.h create mode 100644 scintilla/src/IntegerRectangle.h diff --git a/plugins/export.c b/plugins/export.c index e5165f6c..1ed398b4 100644 --- a/plugins/export.c +++ b/plugins/export.c @@ -374,10 +374,9 @@ static void write_latex_file(GeanyDocument *doc, const gchar *filename, GString *body; GString *cmds; GString *latex; - gint style_max = pow(2, scintilla_send_message(sci, SCI_GETSTYLEBITS, 0, 0)); /* first read all styles from Scintilla */ - for (i = 0; i < style_max; i++) + for (i = 0; i < STYLE_MAX; i++) { styles[i][FORE] = scintilla_send_message(sci, SCI_STYLEGETFORE, i, 0); styles[i][BACK] = scintilla_send_message(sci, SCI_STYLEGETBACK, i, 0); @@ -517,7 +516,7 @@ static void write_latex_file(GeanyDocument *doc, const gchar *filename, /* write used styles in the header */ cmds = g_string_new(""); - for (i = 0; i < style_max; i++) + for (i = 0; i < STYLE_MAX; i++) { if (styles[i][USED]) { @@ -578,10 +577,9 @@ static void write_html_file(GeanyDocument *doc, const gchar *filename, GString *body; GString *css; GString *html; - gint style_max = pow(2, scintilla_send_message(sci, SCI_GETSTYLEBITS, 0, 0)); /* first read all styles from Scintilla */ - for (i = 0; i < style_max; i++) + for (i = 0; i < STYLE_MAX; i++) { styles[i][FORE] = ROTATE_RGB(scintilla_send_message(sci, SCI_STYLEGETFORE, i, 0)); styles[i][BACK] = ROTATE_RGB(scintilla_send_message(sci, SCI_STYLEGETBACK, i, 0)); @@ -707,7 +705,7 @@ static void write_html_file(GeanyDocument *doc, const gchar *filename, "\tbody\n\t{\n\t\tfont-family: %s, monospace;\n\t\tfont-size: %dpt;\n\t}\n", font_name, font_size); - for (i = 0; i < style_max; i++) + for (i = 0; i < STYLE_MAX; i++) { if (styles[i][USED]) { diff --git a/scintilla/License.txt b/scintilla/License.txt index cbe25b2f..47c79265 100644 --- a/scintilla/License.txt +++ b/scintilla/License.txt @@ -2,19 +2,19 @@ License for Scintilla and SciTE Copyright 1998-2003 by Neil Hodgson -All Rights Reserved +All Rights Reserved -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation. +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. -NEIL HODGSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS, IN NO EVENT SHALL NEIL HODGSON BE LIABLE FOR ANY -SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE -OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file +NEIL HODGSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS, IN NO EVENT SHALL NEIL HODGSON BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE +OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/scintilla/Makefile.am b/scintilla/Makefile.am index ad157371..970807b5 100644 --- a/scintilla/Makefile.am +++ b/scintilla/Makefile.am @@ -64,6 +64,8 @@ lexlib/CharacterCategory.cxx \ lexlib/CharacterCategory.h \ lexlib/CharacterSet.cxx \ lexlib/CharacterSet.h \ +lexlib/DefaultLexer.cxx \ +lexlib/DefaultLexer.h \ lexlib/LexAccessor.h \ lexlib/LexerBase.cxx \ lexlib/LexerBase.h \ @@ -99,6 +101,8 @@ src/CharClassify.cxx \ src/CharClassify.h \ src/ContractionState.cxx \ src/ContractionState.h \ +src/DBCS.cxx \ +src/DBCS.h \ src/Decoration.cxx \ src/Decoration.h \ src/Document.cxx \ @@ -109,11 +113,13 @@ src/EditModel.cxx \ src/EditModel.h \ src/EditView.cxx \ src/EditView.h \ +src/ElapsedPeriod.h \ src/ExternalLexer.cxx \ src/ExternalLexer.h \ src/FontQuality.h \ src/Indicator.cxx \ src/Indicator.h \ +src/IntegerRectangle.h \ src/KeyMap.cxx \ src/KeyMap.h \ src/LineMarker.cxx \ diff --git a/scintilla/gtk/Converter.h b/scintilla/gtk/Converter.h index f17949d9..0ef80ae2 100644 --- a/scintilla/gtk/Converter.h +++ b/scintilla/gtk/Converter.h @@ -6,9 +6,7 @@ #ifndef CONVERTER_H #define CONVERTER_H -#ifdef SCI_NAMESPACE namespace Scintilla { -#endif const GIConv iconvhBad = (GIConv)(-1); const gsize sizeFailure = static_cast(-1); @@ -67,8 +65,6 @@ public: } }; -#ifdef SCI_NAMESPACE } -#endif #endif diff --git a/scintilla/gtk/PlatGTK.cxx b/scintilla/gtk/PlatGTK.cxx index ee001cde..26e1b5f5 100644 --- a/scintilla/gtk/PlatGTK.cxx +++ b/scintilla/gtk/PlatGTK.cxx @@ -45,21 +45,7 @@ static double doubleFromPangoUnits(int pu) { } static cairo_surface_t *CreateSimilarSurface(GdkWindow *window, cairo_content_t content, int width, int height) { -#if GTK_CHECK_VERSION(2,22,0) return gdk_window_create_similar_surface(window, content, width, height); -#else - cairo_surface_t *window_surface, *surface; - - g_return_val_if_fail(GDK_IS_WINDOW(window), NULL); - - window_surface = GDK_DRAWABLE_GET_CLASS(window)->ref_cairo_surface(window); - - surface = cairo_surface_create_similar(window_surface, content, width, height); - - cairo_surface_destroy(window_surface); - - return surface; -#endif } static GdkWindow *WindowFromWidget(GtkWidget *w) { @@ -71,9 +57,7 @@ static GdkWindow *WindowFromWidget(GtkWidget *w) { #pragma warning(disable: 4505) #endif -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif enum encodingType { singleByte, UTF8, dbcs}; @@ -121,13 +105,7 @@ static GtkWidget *PWidget(WindowID wid) { return static_cast(wid); } -Point Point::FromLong(long lpoint) { - return Point( - Platform::LowShortFromLong(lpoint), - Platform::HighShortFromLong(lpoint)); -} - -Font::Font() : fid(0) {} +Font::Font() noexcept : fid(0) {} Font::~Font() {} @@ -143,9 +121,7 @@ void Font::Release() { } // Required on OS X -#ifdef SCI_NAMESPACE namespace Scintilla { -#endif // SurfaceID is a cairo_t* class SurfaceImpl : public Surface { @@ -177,13 +153,14 @@ public: int DeviceHeightFont(int points) override; void MoveTo(int x_, int y_) override; void LineTo(int x_, int y_) override; - void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back) override; + void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) override; void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back) override; void FillRectangle(PRectangle rc, ColourDesired back) override; void FillRectangle(PRectangle rc, Surface &surfacePattern) override; void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back) override; void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, ColourDesired outline, int alphaOutline, int flags) override; + void GradientRectangle(PRectangle rc, const std::vector &stops, GradientOptions options) override; void DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) override; void Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back) override; void Copy(PRectangle rc, Point from, Surface &surfaceSource) override; @@ -194,11 +171,9 @@ public: void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore) override; void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions) override; XYPOSITION WidthText(Font &font_, const char *s, int len) override; - XYPOSITION WidthChar(Font &font_, char ch) override; XYPOSITION Ascent(Font &font_) override; XYPOSITION Descent(Font &font_) override; XYPOSITION InternalLeading(Font &font_) override; - XYPOSITION ExternalLeading(Font &font_) override; XYPOSITION Height(Font &font_) override; XYPOSITION AverageCharWidth(Font &font_) override; @@ -208,9 +183,7 @@ public: void SetUnicodeMode(bool unicodeMode_) override; void SetDBCSMode(int codePage) override; }; -#ifdef SCI_NAMESPACE } -#endif const char *CharacterSetID(int characterSet) { switch (characterSet) { @@ -310,7 +283,6 @@ void SurfaceImpl::Release() { } bool SurfaceImpl::Initialised() { -#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 8, 0) if (inited && context) { if (cairo_status(context) == CAIRO_STATUS_SUCCESS) { // Even when status is success, the target surface may have been @@ -327,7 +299,6 @@ bool SurfaceImpl::Initialised() { } return cairo_status(context) == CAIRO_STATUS_SUCCESS; } -#endif return inited; } @@ -390,7 +361,7 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface *surface_, WindowID void SurfaceImpl::PenColour(ColourDesired fore) { if (context) { - ColourDesired cdFore(fore.AsLong()); + ColourDesired cdFore(fore.AsInteger()); cairo_set_source_rgb(context, cdFore.GetRed() / 255.0, cdFore.GetGreen() / 255.0, @@ -432,10 +403,10 @@ void SurfaceImpl::LineTo(int x_, int y_) { if ((xDiff == 0) || (yDiff == 0)) { // Horizontal or vertical lines can be more precisely drawn as a filled rectangle int xEnd = x_ - xDelta; - int left = Platform::Minimum(x, xEnd); + int left = std::min(x, xEnd); int width = abs(x - xEnd) + 1; int yEnd = y_ - yDelta; - int top = Platform::Minimum(y, yEnd); + int top = std::min(y, yEnd); int height = abs(y - yEnd) + 1; cairo_rectangle(context, left, top, width, height); cairo_fill(context); @@ -454,12 +425,12 @@ void SurfaceImpl::LineTo(int x_, int y_) { y = y_; } -void SurfaceImpl::Polygon(Point *pts, int npts, ColourDesired fore, +void SurfaceImpl::Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back) { PLATFORM_ASSERT(context); PenColour(back); cairo_move_to(context, pts[0].x + 0.5, pts[0].y + 0.5); - for (int i = 1; i < npts; i++) { + for (size_t i = 1; i < npts; i++) { cairo_line_to(context, pts[i].x + 0.5, pts[i].y + 0.5); } cairo_close_path(context); @@ -537,12 +508,7 @@ void SurfaceImpl::RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesi static void PathRoundRectangle(cairo_t *context, double left, double top, double width, double height, int radius) { double degrees = kPi / 180.0; -#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0) cairo_new_sub_path(context); -#else - // First arc is in the top-right corner and starts from a point on the top line - cairo_move_to(context, left + width - radius, top); -#endif cairo_arc(context, left + width - radius, top + radius, radius, -90 * degrees, 0 * degrees); cairo_arc(context, left + width - radius, top + height - radius, radius, 0 * degrees, 90 * degrees); cairo_arc(context, left + radius, top + height - radius, radius, 90 * degrees, 180 * degrees); @@ -553,7 +519,7 @@ static void PathRoundRectangle(cairo_t *context, double left, double top, double void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, ColourDesired outline, int alphaOutline, int /*flags*/) { if (context && rc.Width() > 0) { - ColourDesired cdFill(fill.AsLong()); + ColourDesired cdFill(fill.AsInteger()); cairo_set_source_rgba(context, cdFill.GetRed() / 255.0, cdFill.GetGreen() / 255.0, @@ -565,7 +531,7 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fi cairo_rectangle(context, rc.left + 1.0, rc.top + 1.0, rc.right - rc.left - 2.0, rc.bottom - rc.top - 2.0); cairo_fill(context); - ColourDesired cdOutline(outline.AsLong()); + ColourDesired cdOutline(outline.AsInteger()); cairo_set_source_rgba(context, cdOutline.GetRed() / 255.0, cdOutline.GetGreen() / 255.0, @@ -579,6 +545,32 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fi } } +void SurfaceImpl::GradientRectangle(PRectangle rc, const std::vector &stops, GradientOptions options) { + if (context) { + cairo_pattern_t *pattern; + switch (options) { + case GradientOptions::leftToRight: + pattern = cairo_pattern_create_linear(rc.left, rc.top, rc.right, rc.top); + break; + case GradientOptions::topToBottom: + default: + pattern = cairo_pattern_create_linear(rc.left, rc.top, rc.left, rc.bottom); + break; + } + for (const ColourStop &stop : stops) { + cairo_pattern_add_color_stop_rgba(pattern, stop.position, + stop.colour.GetRedComponent(), + stop.colour.GetGreenComponent(), + stop.colour.GetBlueComponent(), + stop.colour.GetAlphaComponent()); + } + cairo_rectangle(context, rc.left, rc.top, rc.Width(), rc.Height()); + cairo_set_source(context, pattern); + cairo_fill(context); + cairo_pattern_destroy(pattern); + } +} + void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) { PLATFORM_ASSERT(context); if (rc.Width() > width) @@ -588,11 +580,7 @@ void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsi rc.top += (rc.Height() - height) / 2; rc.bottom = rc.top + height; -#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,6,0) int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); -#else - int stride = width * 4; -#endif int ucs = stride * height; std::vector image(ucs); for (int iy=0; iypfd); pango_cairo_update_layout(context, layout); -#ifdef PANGO_VERSION PangoLayoutLine *pll = pango_layout_get_line_readonly(layout,0); -#else - PangoLayoutLine *pll = pango_layout_get_line(layout,0); -#endif cairo_move_to(context, xText, ybase); pango_cairo_show_layout_line(context, pll); } @@ -823,7 +807,7 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION positions[i++] = iti.position - (places - place) * iti.distance / places; positionsCalculated++; } - clusterStart += UTF8CharLength(static_cast(utfForm.c_str()[clusterStart])); + clusterStart += UTF8BytesOfLead[static_cast(utfForm.c_str()[clusterStart])]; place++; } } @@ -897,11 +881,7 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) { } pango_layout_set_text(layout, utfForm.c_str(), utfForm.length()); } -#ifdef PANGO_VERSION PangoLayoutLine *pangoLine = pango_layout_get_line_readonly(layout,0); -#else - PangoLayoutLine *pangoLine = pango_layout_get_line(layout,0); -#endif pango_layout_line_get_extents(pangoLine, NULL, &pos); return doubleFromPangoUnits(pos.width); } @@ -911,17 +891,6 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) { } } -XYPOSITION SurfaceImpl::WidthChar(Font &font_, char ch) { - if (font_.GetID()) { - if (PFont(font_)->pfd) { - return WidthText(font_, &ch, 1); - } - return 1; - } else { - return 1; - } -} - // Ascent and descent determined by Pango font metrics. XYPOSITION SurfaceImpl::Ascent(Font &font_) { @@ -958,16 +927,12 @@ XYPOSITION SurfaceImpl::InternalLeading(Font &) { return 0; } -XYPOSITION SurfaceImpl::ExternalLeading(Font &) { - return 0; -} - XYPOSITION SurfaceImpl::Height(Font &font_) { return Ascent(font_) + Descent(font_); } XYPOSITION SurfaceImpl::AverageCharWidth(Font &font_) { - return WidthChar(font_, 'n'); + return WidthText(font_, "n", 1); } void SurfaceImpl::SetClip(PRectangle rc) { @@ -1011,11 +976,7 @@ void Window::Destroy() { } } -bool Window::HasFocus() { - return gtk_widget_has_focus(GTK_WIDGET(wid)); -} - -PRectangle Window::GetPosition() { +PRectangle Window::GetPosition() const { // Before any size allocated pretend its 1000 wide so not scrolled PRectangle rc(0, 0, 1000, 1000); if (wid) { @@ -1059,15 +1020,15 @@ GdkRectangle MonitorRectangleForWidget(GtkWidget *wid) { } -void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { +void Window::SetPositionRelative(PRectangle rc, const Window *relativeTo) { int ox = 0; int oy = 0; - GdkWindow *wndRelativeTo = WindowFromWidget(PWidget(relativeTo.wid)); + GdkWindow *wndRelativeTo = WindowFromWidget(PWidget(relativeTo->wid)); gdk_window_get_origin(wndRelativeTo, &ox, &oy); ox += rc.left; oy += rc.top; - GdkRectangle rcMonitor = MonitorRectangleForWidget(PWidget(relativeTo.wid)); + GdkRectangle rcMonitor = MonitorRectangleForWidget(PWidget(relativeTo->wid)); /* do some corrections to fit into screen */ int sizex = rc.right - rc.left; @@ -1086,7 +1047,7 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { gtk_window_resize(GTK_WINDOW(wid), sizex, sizey); } -PRectangle Window::GetClientPosition() { +PRectangle Window::GetClientPosition() const { // On GTK+, the client position is the window position return GetPosition(); } @@ -1158,10 +1119,6 @@ void Window::SetCursor(Cursor curs) { #endif } -void Window::SetTitle(const char *s) { - gtk_window_set_title(GTK_WINDOW(wid), s); -} - /* Returns rectangle of monitor pt is on, both rect and pt are in Window's gdk window coordinates */ PRectangle Window::GetMonitorRect(Point pt) { @@ -1201,7 +1158,7 @@ static void list_image_free(gpointer, gpointer value, gpointer) { g_free(list_image); } -ListBox::ListBox() { +ListBox::ListBox() noexcept { } ListBox::~ListBox() { @@ -1229,8 +1186,7 @@ class ListBoxX : public ListBox { GtkCssProvider *cssProvider; #endif public: - CallBackAction doubleClickAction; - void *doubleClickActionData; + IListBoxDelegate *delegate; ListBoxX() : widCached(0), frame(0), list(0), scroller(0), pixhash(NULL), pixbuf_renderer(0), renderer(0), @@ -1239,7 +1195,7 @@ public: #if GTK_CHECK_VERSION(3,0,0) cssProvider(NULL), #endif - doubleClickAction(NULL), doubleClickActionData(NULL) { + delegate(nullptr) { } ~ListBoxX() override { if (pixhash) { @@ -1276,10 +1232,7 @@ public: void RegisterImage(int type, const char *xpm_data) override; void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) override; void ClearRegisteredImages() override; - void SetDoubleClickAction(CallBackAction action, void *data) override { - doubleClickAction = action; - doubleClickActionData = data; - } + void SetDelegate(IListBoxDelegate *lbDelegate) override; void SetList(const char *listText, char separator, char typesep) override; }; @@ -1307,7 +1260,7 @@ static int treeViewGetRowHeight(GtkTreeView *view) { "vertical-separator", &vertical_separator, "expander-size", &expander_size, NULL); row_height += vertical_separator; - row_height = Platform::Maximum(row_height, expander_size); + row_height = std::max(row_height, expander_size); return row_height; #endif } @@ -1370,8 +1323,9 @@ static void small_scroller_init(SmallScroller *){} static gboolean ButtonPress(GtkWidget *, GdkEventButton* ev, gpointer p) { try { ListBoxX* lb = static_cast(p); - if (ev->type == GDK_2BUTTON_PRESS && lb->doubleClickAction != NULL) { - lb->doubleClickAction(lb->doubleClickActionData); + if (ev->type == GDK_2BUTTON_PRESS && lb->delegate) { + ListBoxEvent event(ListBoxEvent::EventType::doubleClick); + lb->delegate->ListNotify(&event); return TRUE; } @@ -1381,6 +1335,20 @@ static gboolean ButtonPress(GtkWidget *, GdkEventButton* ev, gpointer p) { return FALSE; } +static gboolean ButtonRelease(GtkWidget *, GdkEventButton* ev, gpointer p) { + try { + ListBoxX* lb = static_cast(p); + if (ev->type != GDK_2BUTTON_PRESS && lb->delegate) { + ListBoxEvent event(ListBoxEvent::EventType::selectionChange); + lb->delegate->ListNotify(&event); + return TRUE; + } + } catch (...) { + // No pointer back to Scintilla to save status + } + return FALSE; +} + /* Change the active color to the selected color so the listbox uses the color scheme that it would use if it had the focus. */ static void StyleSet(GtkWidget *w, GtkStyle*, void*) { @@ -1505,6 +1473,8 @@ void ListBoxX::Create(Window &parent, int, Point, int, bool, int) { gtk_widget_show(widget); g_signal_connect(G_OBJECT(widget), "button_press_event", G_CALLBACK(ButtonPress), this); + g_signal_connect(G_OBJECT(widget), "button_release_event", + G_CALLBACK(ButtonRelease), this); GtkWidget *top = gtk_widget_get_toplevel(static_cast(parent.GetID())); gtk_window_set_transient_for(GTK_WINDOW(static_cast(wid)), @@ -1780,6 +1750,11 @@ void ListBoxX::Select(int n) { } else { gtk_tree_selection_unselect_all(selection); } + + if (delegate) { + ListBoxEvent event(ListBoxEvent::EventType::selectionChange); + delegate->ListNotify(&event); + } } int ListBoxX::GetSelection() { @@ -1876,6 +1851,10 @@ void ListBoxX::ClearRegisteredImages() { images.Clear(); } +void ListBoxX::SetDelegate(IListBoxDelegate *lbDelegate) { + delegate = lbDelegate; +} + void ListBoxX::SetList(const char *listText, char separator, char typesep) { Clear(); int count = strlen(listText) + 1; @@ -1902,7 +1881,7 @@ void ListBoxX::SetList(const char *listText, char separator, char typesep) { } } -Menu::Menu() : mid(0) {} +Menu::Menu() noexcept : mid(0) {} void Menu::CreatePopUp() { Destroy(); @@ -1950,13 +1929,6 @@ void Menu::Show(Point pt, Window &w) { #endif } -ElapsedTime::ElapsedTime() { - GTimeVal curTime; - g_get_current_time(&curTime); - bigBit = curTime.tv_sec; - littleBit = curTime.tv_usec; -} - class DynamicLibraryImpl : public DynamicLibrary { protected: GModule* m; @@ -1993,21 +1965,6 @@ DynamicLibrary *DynamicLibrary::Load(const char *modulePath) { return static_cast( new DynamicLibraryImpl(modulePath) ); } -double ElapsedTime::Duration(bool reset) { - GTimeVal curTime; - g_get_current_time(&curTime); - long endBigBit = curTime.tv_sec; - long endLittleBit = curTime.tv_usec; - double result = 1000000.0 * (endBigBit - bigBit); - result += endLittleBit - littleBit; - result /= 1000000.0; - if (reset) { - bigBit = endBigBit; - littleBit = endLittleBit; - } - return result; -} - ColourDesired Platform::Chrome() { return ColourDesired(0xe0, 0xe0, 0xe0); } @@ -2036,83 +1993,10 @@ unsigned int Platform::DoubleClickTime() { return 500; // Half a second } -bool Platform::MouseButtonBounce() { - return true; -} - void Platform::DebugDisplay(const char *s) { fprintf(stderr, "%s", s); } -bool Platform::IsKeyDown(int) { - // TODO: discover state of keys in GTK+/X - return false; -} - -long Platform::SendScintilla( - WindowID w, unsigned int msg, unsigned long wParam, long lParam) { - return scintilla_send_message(SCINTILLA(w), msg, wParam, lParam); -} - -long Platform::SendScintillaPointer( - WindowID w, unsigned int msg, unsigned long wParam, void *lParam) { - return scintilla_send_message(SCINTILLA(w), msg, wParam, - reinterpret_cast(lParam)); -} - -bool Platform::IsDBCSLeadByte(int codePage, char ch) { - // Byte ranges found in Wikipedia articles with relevant search strings in each case - unsigned char uch = static_cast(ch); - switch (codePage) { - case 932: - // Shift_jis - return ((uch >= 0x81) && (uch <= 0x9F)) || - ((uch >= 0xE0) && (uch <= 0xFC)); - // Lead bytes F0 to FC may be a Microsoft addition. - case 936: - // GBK - return (uch >= 0x81) && (uch <= 0xFE); - case 950: - // Big5 - return (uch >= 0x81) && (uch <= 0xFE); - // Korean EUC-KR may be code page 949. - } - return false; -} - -int Platform::DBCSCharLength(int codePage, const char *s) { - if (codePage == 932 || codePage == 936 || codePage == 950) { - return IsDBCSLeadByte(codePage, s[0]) ? 2 : 1; - } else { - int bytes = mblen(s, MB_CUR_MAX); - if (bytes >= 1) - return bytes; - else - return 1; - } -} - -int Platform::DBCSCharMaxLength() { - return MB_CUR_MAX; - //return 2; -} - -// These are utility functions not really tied to a platform - -int Platform::Minimum(int a, int b) { - if (a < b) - return a; - else - return b; -} - -int Platform::Maximum(int a, int b) { - if (a > b) - return a; - else - return b; -} - //#define TRACE #ifdef TRACE @@ -2145,14 +2029,6 @@ void Platform::Assert(const char *c, const char *file, int line) { abort(); } -int Platform::Clamp(int val, int minVal, int maxVal) { - if (val > maxVal) - val = maxVal; - if (val < minVal) - val = minVal; - return val; -} - void Platform_Initialise() { } diff --git a/scintilla/gtk/ScintillaGTK.cxx b/scintilla/gtk/ScintillaGTK.cxx index 3e48ed60..a736f3b6 100644 --- a/scintilla/gtk/ScintillaGTK.cxx +++ b/scintilla/gtk/ScintillaGTK.cxx @@ -35,6 +35,7 @@ #include "Platform.h" +#include "ILoader.h" #include "ILexer.h" #include "Scintilla.h" #include "ScintillaWidget.h" @@ -55,7 +56,6 @@ #include "CallTip.h" #include "KeyMap.h" #include "Indicator.h" -#include "XPM.h" #include "LineMarker.h" #include "Style.h" #include "ViewStyle.h" @@ -65,7 +65,6 @@ #include "Document.h" #include "CaseConvert.h" #include "UniConversion.h" -#include "UnicodeFromUTF8.h" #include "Selection.h" #include "PositionCache.h" #include "EditModel.h" @@ -85,13 +84,8 @@ #include "Converter.h" -#if GTK_CHECK_VERSION(2,20,0) #define IS_WIDGET_REALIZED(w) (gtk_widget_get_realized(GTK_WIDGET(w))) #define IS_WIDGET_MAPPED(w) (gtk_widget_get_mapped(GTK_WIDGET(w))) -#else -#define IS_WIDGET_REALIZED(w) (GTK_WIDGET_REALIZED(w)) -#define IS_WIDGET_MAPPED(w) (GTK_WIDGET_MAPPED(w)) -#endif #define SC_INDICATOR_INPUT INDIC_IME #define SC_INDICATOR_TARGET INDIC_IME+1 @@ -109,9 +103,7 @@ static GdkWindow *WindowFromWidget(GtkWidget *w) { #pragma warning(disable: 4505) #endif -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static GdkWindow *PWindow(const Window &w) { GtkWidget *widget = static_cast(w.GetID()); @@ -155,6 +147,8 @@ static const GtkTargetEntry clipboardPasteTargets[] = { }; static const gint nClipboardPasteTargets = ELEMENTS(clipboardPasteTargets); +static const GdkDragAction actionCopyOrMove = static_cast(GDK_ACTION_COPY | GDK_ACTION_MOVE); + static GtkWidget *PWidget(Window &w) { return static_cast(w.GetID()); } @@ -167,7 +161,7 @@ ScintillaGTK *ScintillaGTK::FromWidget(GtkWidget *widget) { ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) : adjustmentv(0), adjustmenth(0), verticalScrollBarWidth(30), horizontalScrollBarHeight(30), - evbtn(0), capturedMouse(false), dragWasDropped(false), + evbtn(nullptr), capturedMouse(false), dragWasDropped(false), lastKey(0), rectangularSelectionModifier(SCMOD_CTRL), parentClass(0), im_context(NULL), lastNonCommonScript(PANGO_SCRIPT_INVALID_CODE), lastWheelMouseDirection(0), @@ -182,11 +176,7 @@ ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) : sci = sci_; wMain = GTK_WIDGET(sci); -#if PLAT_GTK_WIN32 rectangularSelectionModifier = SCMOD_ALT; -#else - rectangularSelectionModifier = SCMOD_CTRL; -#endif #if PLAT_GTK_WIN32 // There does not seem to be a real standard for indicating that the clipboard @@ -215,8 +205,8 @@ ScintillaGTK::~ScintillaGTK() { styleIdleID = 0; } if (evbtn) { - gdk_event_free(reinterpret_cast(evbtn)); - evbtn = 0; + gdk_event_free(evbtn); + evbtn = nullptr; } wPreedit.Destroy(); } @@ -231,11 +221,7 @@ static void UnRefCursor(GdkCursor *cursor) { void ScintillaGTK::RealizeThis(GtkWidget *widget) { //Platform::DebugPrintf("ScintillaGTK::realize this\n"); -#if GTK_CHECK_VERSION(2,20,0) gtk_widget_set_realized(widget, TRUE); -#else - GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); -#endif GdkWindowAttr attrs; attrs.window_type = GDK_WINDOW_CHILD; GtkAllocation allocation; @@ -306,7 +292,10 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) { gdk_window_set_cursor(PWindow(scrollbarh), cursor); UnRefCursor(cursor); - gtk_selection_add_targets(widget, GDK_SELECTION_PRIMARY, + wSelection = gtk_invisible_new(); + g_signal_connect(PWidget(wSelection), "selection_get", G_CALLBACK(PrimarySelection), (gpointer) this); + g_signal_connect(PWidget(wSelection), "selection_clear_event", G_CALLBACK(PrimaryClear), (gpointer) this); + gtk_selection_add_targets(PWidget(wSelection), GDK_SELECTION_PRIMARY, clipboardCopyTargets, nClipboardCopyTargets); } @@ -317,16 +306,13 @@ void ScintillaGTK::Realize(GtkWidget *widget) { void ScintillaGTK::UnRealizeThis(GtkWidget *widget) { try { - gtk_selection_clear_targets(widget, GDK_SELECTION_PRIMARY); + gtk_selection_clear_targets(PWidget(wSelection), GDK_SELECTION_PRIMARY); + wSelection.Destroy(); if (IS_WIDGET_MAPPED(widget)) { gtk_widget_unmap(widget); } -#if GTK_CHECK_VERSION(2,20,0) gtk_widget_set_realized(widget, FALSE); -#else - GTK_WIDGET_UNSET_FLAGS(widget, GTK_REALIZED); -#endif gtk_widget_unrealize(PWidget(wText)); if (PWidget(scrollbarv)) gtk_widget_unrealize(PWidget(scrollbarv)); @@ -361,11 +347,7 @@ static void MapWidget(GtkWidget *widget) { void ScintillaGTK::MapThis() { try { //Platform::DebugPrintf("ScintillaGTK::map this\n"); -#if GTK_CHECK_VERSION(2,20,0) gtk_widget_set_mapped(PWidget(wMain), TRUE); -#else - GTK_WIDGET_SET_FLAGS(PWidget(wMain), GTK_MAPPED); -#endif MapWidget(PWidget(wText)); MapWidget(PWidget(scrollbarh)); MapWidget(PWidget(scrollbarv)); @@ -387,11 +369,7 @@ void ScintillaGTK::Map(GtkWidget *widget) { void ScintillaGTK::UnMapThis() { try { //Platform::DebugPrintf("ScintillaGTK::unmap this\n"); -#if GTK_CHECK_VERSION(2,20,0) gtk_widget_set_mapped(PWidget(wMain), FALSE); -#else - GTK_WIDGET_UNSET_FLAGS(PWidget(wMain), GTK_MAPPED); -#endif DropGraphics(false); gdk_window_hide(PWindow(wMain)); gtk_widget_unmap(PWidget(wText)); @@ -631,7 +609,7 @@ void ScintillaGTK::Init() { gtk_drag_dest_set(GTK_WIDGET(PWidget(wMain)), GTK_DEST_DEFAULT_ALL, clipboardPasteTargets, nClipboardPasteTargets, - static_cast(GDK_ACTION_COPY | GDK_ACTION_MOVE)); + actionCopyOrMove); /* create pre-edit window */ wPreedit = gtk_window_new(GTK_WINDOW_POPUP); @@ -708,29 +686,27 @@ bool ScintillaGTK::DragThreshold(Point ptStart, Point ptNow) { } void ScintillaGTK::StartDrag() { - PLATFORM_ASSERT(evbtn != 0); + PLATFORM_ASSERT(evbtn); dragWasDropped = false; inDragDrop = ddDragging; GtkTargetList *tl = gtk_target_list_new(clipboardCopyTargets, nClipboardCopyTargets); #if GTK_CHECK_VERSION(3,10,0) gtk_drag_begin_with_coordinates(GTK_WIDGET(PWidget(wMain)), tl, - static_cast(GDK_ACTION_COPY | GDK_ACTION_MOVE), - evbtn->button, - reinterpret_cast(evbtn), + actionCopyOrMove, + buttonMouse, + evbtn, -1, -1); #else gtk_drag_begin(GTK_WIDGET(PWidget(wMain)), tl, - static_cast(GDK_ACTION_COPY | GDK_ACTION_MOVE), - evbtn->button, - reinterpret_cast(evbtn)); + actionCopyOrMove, + buttonMouse, + evbtn); #endif } -#ifdef SCI_NAMESPACE namespace Scintilla { -#endif std::string ConvertText(const char *s, size_t len, const char *charSetDest, const char *charSetSource, bool transliterations, bool silent) { // s is not const because of different versions of iconv disagreeing about const @@ -763,14 +739,12 @@ std::string ConvertText(const char *s, size_t len, const char *charSetDest, } return destForm; } -#ifdef SCI_NAMESPACE } -#endif // Returns the target converted to UTF8. // Return the length in bytes. -int ScintillaGTK::TargetAsUTF8(char *text) { - int targetLength = targetEnd - targetStart; +Sci::Position ScintillaGTK::TargetAsUTF8(char *text) const { + Sci::Position targetLength = targetEnd - targetStart; if (IsUnicodeMode()) { if (text) { pdoc->GetCharRange(text, targetStart, targetLength); @@ -796,8 +770,8 @@ int ScintillaGTK::TargetAsUTF8(char *text) { // Translates a nul terminated UTF8 string into the document encoding. // Return the length of the result in bytes. -int ScintillaGTK::EncodedFromUTF8(char *utf8, char *encoded) const { - int inputLength = (lengthForEncode >= 0) ? lengthForEncode : strlen(utf8); +Sci::Position ScintillaGTK::EncodedFromUTF8(const char *utf8, char *encoded) const { + Sci::Position inputLength = (lengthForEncode >= 0) ? lengthForEncode : strlen(utf8); if (IsUnicodeMode()) { if (encoded) { memcpy(encoded, utf8, inputLength); @@ -849,15 +823,15 @@ sptr_t ScintillaGTK::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam #ifdef SCI_LEXER case SCI_LOADLEXERLIBRARY: - LexerManager::GetInstance()->Load(reinterpret_cast(lParam)); + LexerManager::GetInstance()->Load(ConstCharPtrFromSPtr(lParam)); break; #endif case SCI_TARGETASUTF8: - return TargetAsUTF8(reinterpret_cast(lParam)); + return TargetAsUTF8(CharPtrFromSPtr(lParam)); case SCI_ENCODEDFROMUTF8: - return EncodedFromUTF8(reinterpret_cast(wParam), - reinterpret_cast(lParam)); + return EncodedFromUTF8(ConstCharPtrFromUPtr(wParam), + CharPtrFromSPtr(lParam)); case SCI_SETRECTANGULARSELECTIONMODIFIER: rectangularSelectionModifier = wParam; @@ -898,20 +872,13 @@ sptr_t ScintillaGTK::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam } catch (...) { errorStatus = SC_STATUS_FAILURE; } - return 0l; + return 0; } sptr_t ScintillaGTK::DefWndProc(unsigned int, uptr_t, sptr_t) { return 0; } -/** -* Report that this Editor subclass has a working implementation of FineTickerStart. -*/ -bool ScintillaGTK::FineTickerAvailable() { - return true; -} - bool ScintillaGTK::FineTickerRunning(TickReason reason) { return timers[reason].timer != 0; } @@ -933,7 +900,7 @@ bool ScintillaGTK::SetIdle(bool on) { // Start idler, if it's not running. if (!idler.state) { idler.state = true; - idler.idlerID = reinterpret_cast( + idler.idlerID = GUINT_TO_POINTER( gdk_threads_add_idle_full(G_PRIORITY_DEFAULT_IDLE, IdleCallback, this, NULL)); } } else { @@ -1012,8 +979,7 @@ void ScintillaGTK::FullPaint() { } PRectangle ScintillaGTK::GetClientRectangle() const { - Window win = wMain; - PRectangle rc = win.GetClientPosition(); + PRectangle rc = wMain.GetClientPosition(); if (verticalScrollBarVisible) rc.right -= verticalScrollBarWidth; if (horizontalScrollBarVisible && !Wrapping()) @@ -1332,7 +1298,7 @@ void ScintillaGTK::CreateCallTipWindow(PRectangle rc) { G_CALLBACK(ScintillaGTK::ExposeCT), &ct); #endif g_signal_connect(G_OBJECT(widcdrw), "button_press_event", - G_CALLBACK(ScintillaGTK::PressCT), static_cast(this)); + G_CALLBACK(ScintillaGTK::PressCT), this); gtk_widget_set_events(widcdrw, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); GtkWidget *top = gtk_widget_get_toplevel(static_cast(wMain.GetID())); @@ -1363,17 +1329,17 @@ void ScintillaGTK::AddToPopUp(const char *label, int cmd, bool enabled) { } bool ScintillaGTK::OwnPrimarySelection() { - return ((gdk_selection_owner_get(GDK_SELECTION_PRIMARY) - == PWindow(wMain)) && - (PWindow(wMain) != NULL)); + return (wSelection.Created() && + (gdk_selection_owner_get(GDK_SELECTION_PRIMARY) == PWindow(wSelection)) && + (PWindow(wSelection) != NULL)); } void ScintillaGTK::ClaimSelection() { // X Windows has a 'primary selection' as well as the clipboard. // Whenever the user selects some text, we become the primary selection - if (!sel.Empty() && IS_WIDGET_REALIZED(GTK_WIDGET(PWidget(wMain)))) { + if (!sel.Empty() && wSelection.Created() && IS_WIDGET_REALIZED(GTK_WIDGET(PWidget(wSelection)))) { primarySelection = true; - gtk_selection_owner_set(GTK_WIDGET(PWidget(wMain)), + gtk_selection_owner_set(GTK_WIDGET(PWidget(wSelection)), GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); primary.Clear(); } else if (OwnPrimarySelection()) { @@ -1541,7 +1507,7 @@ void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, Se } else { gtk_selection_data_set(selection_data, static_cast(GDK_SELECTION_TYPE_STRING), - 8, reinterpret_cast(textData), len); + 8, reinterpret_cast(textData), len); } } @@ -1582,6 +1548,27 @@ void ScintillaGTK::UnclaimSelection(GdkEventSelection *selection_event) { } } +void ScintillaGTK::PrimarySelection(GtkWidget *, GtkSelectionData *selection_data, guint info, guint, ScintillaGTK *sciThis) { + try { + if (SelectionOfGSD(selection_data) == GDK_SELECTION_PRIMARY) { + if (sciThis->primary.Empty()) { + sciThis->CopySelectionRange(&sciThis->primary); + } + sciThis->GetSelection(selection_data, info, &sciThis->primary); + } + } catch (...) { + sciThis->errorStatus = SC_STATUS_FAILURE; + } +} + +gboolean ScintillaGTK::PrimaryClear(GtkWidget *widget, GdkEventSelection *event, ScintillaGTK *sciThis) { + sciThis->UnclaimSelection(event); + if (GTK_WIDGET_CLASS(sciThis->parentClass)->selection_clear_event) { + return GTK_WIDGET_CLASS(sciThis->parentClass)->selection_clear_event(widget, event); + } + return TRUE; +} + void ScintillaGTK::Resize(int width, int height) { //Platform::DebugPrintf("Resize %d %d\n", width, height); //printf("Resize %d %d\n", width, height); @@ -1614,7 +1601,7 @@ void ScintillaGTK::Resize(int width, int height) { gtk_widget_show(GTK_WIDGET(PWidget(scrollbarh))); alloc.x = 0; alloc.y = height - horizontalScrollBarHeight; - alloc.width = Platform::Maximum(minHScrollBarWidth, width - verticalScrollBarWidth); + alloc.width = std::max(minHScrollBarWidth, width - verticalScrollBarWidth); alloc.height = horizontalScrollBarHeight; gtk_widget_size_allocate(GTK_WIDGET(PWidget(scrollbarh)), &alloc); } else { @@ -1627,7 +1614,7 @@ void ScintillaGTK::Resize(int width, int height) { alloc.x = width - verticalScrollBarWidth; alloc.y = 0; alloc.width = verticalScrollBarWidth; - alloc.height = Platform::Maximum(minVScrollBarHeight, height - horizontalScrollBarHeight); + alloc.height = std::max(minVScrollBarHeight, height - horizontalScrollBarHeight); gtk_widget_size_allocate(GTK_WIDGET(PWidget(scrollbarv)), &alloc); } else { gtk_widget_hide(GTK_WIDGET(PWidget(scrollbarv))); @@ -1648,8 +1635,8 @@ void ScintillaGTK::Resize(int width, int height) { alloc.width = requisition.width; alloc.height = requisition.height; #endif - alloc.width = Platform::Maximum(alloc.width, width - verticalScrollBarWidth); - alloc.height = Platform::Maximum(alloc.height, height - horizontalScrollBarHeight); + alloc.width = std::max(alloc.width, width - verticalScrollBarWidth); + alloc.height = std::max(alloc.height, height - horizontalScrollBarHeight); gtk_widget_size_allocate(GTK_WIDGET(PWidget(wText)), &alloc); } @@ -1688,13 +1675,13 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) { return FALSE; if (evbtn) { - gdk_event_free(reinterpret_cast(evbtn)); - evbtn = 0; + gdk_event_free(evbtn); } - evbtn = reinterpret_cast(gdk_event_copy(reinterpret_cast(event))); + evbtn = gdk_event_copy(reinterpret_cast(event)); + buttonMouse = event->button; Point pt; - pt.x = int(event->x); - pt.y = int(event->y); + pt.x = floor(event->x); + pt.y = floor(event->y); PRectangle rcClient = GetClientRectangle(); //Platform::DebugPrintf("Press %0d,%0d in %0d,%0d %0d,%0d\n", // pt.x, pt.y, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); @@ -1796,7 +1783,11 @@ gint ScintillaGTK::MouseRelease(GtkWidget *widget, GdkEventButton *event) { // If mouse released on scroll bar then the position is relative to the // scrollbar, not the drawing window so just repeat the most recent point. pt = sciThis->ptMouseLast; - sciThis->ButtonUp(pt, event->time, (event->state & GDK_CONTROL_MASK) != 0); + const int modifiers = ModifierFlags( + (event->state & GDK_SHIFT_MASK) != 0, + (event->state & GDK_CONTROL_MASK) != 0, + (event->state & modifierTranslated(sciThis->rectangularSelectionModifier)) != 0); + sciThis->ButtonUpWithModifiers(pt, event->time, modifiers); } } catch (...) { sciThis->errorStatus = SC_STATUS_FAILURE; @@ -1933,10 +1924,11 @@ gint ScintillaGTK::Motion(GtkWidget *widget, GdkEventMotion *event) { //Platform::DebugPrintf("Move %x %x %d %c %d %d\n", // sciThis,event->window,event->time,event->is_hint? 'h' :'.', x, y); Point pt(x, y); - int modifiers = ((event->state & GDK_SHIFT_MASK) != 0 ? SCI_SHIFT : 0) | - ((event->state & GDK_CONTROL_MASK) != 0 ? SCI_CTRL : 0) | - ((event->state & modifierTranslated(sciThis->rectangularSelectionModifier)) != 0 ? SCI_ALT : 0); - sciThis->ButtonMoveWithModifiers(pt, modifiers); + const int modifiers = ModifierFlags( + (event->state & GDK_SHIFT_MASK) != 0, + (event->state & GDK_CONTROL_MASK) != 0, + (event->state & modifierTranslated(sciThis->rectangularSelectionModifier)) != 0); + sciThis->ButtonMoveWithModifiers(pt, event->time, modifiers); } catch (...) { sciThis->errorStatus = SC_STATUS_FAILURE; } @@ -2465,8 +2457,8 @@ static GObjectClass *scintilla_class_parent_class; void ScintillaGTK::Dispose(GObject *object) { try { - ScintillaObject *scio = reinterpret_cast(object); - ScintillaGTK *sciThis = reinterpret_cast(scio->pscin); + ScintillaObject *scio = SCINTILLA(object); + ScintillaGTK *sciThis = static_cast(scio->pscin); if (PWidget(sciThis->scrollbarv)) { gtk_widget_unparent(PWidget(sciThis->scrollbarv)); @@ -2622,11 +2614,12 @@ gboolean ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *os Paint(surfaceWindow.get(), rcPaint); surfaceWindow->Release(); cairo_destroy(cr); - if (paintState == paintAbandoned) { + if ((paintState == paintAbandoned) || repaintFullWindow) { // Painting area was insufficient to cover new styling or brace highlight positions FullPaint(); } paintState = notPainting; + repaintFullWindow = false; if (rgnUpdate) { gdk_region_destroy(rgnUpdate); @@ -2723,20 +2716,14 @@ gboolean ScintillaGTK::DragMotionThis(GdkDragContext *context, try { Point npt(x, y); SetDragPosition(SPositionFromLocation(npt, false, false, UserVirtualSpace())); -#if GTK_CHECK_VERSION(2,22,0) GdkDragAction preferredAction = gdk_drag_context_get_suggested_action(context); GdkDragAction actions = gdk_drag_context_get_actions(context); -#else - GdkDragAction preferredAction = context->suggested_action; - GdkDragAction actions = context->actions; -#endif SelectionPosition pos = SPositionFromLocation(npt); if ((inDragDrop == ddDragging) && (PositionInSelection(pos.Position()))) { // Avoid dragging selection onto itself as that produces a move // with no real effect but which creates undo actions. preferredAction = static_cast(0); - } else if (actions == static_cast - (GDK_ACTION_COPY | GDK_ACTION_MOVE)) { + } else if (actions == actionCopyOrMove) { preferredAction = GDK_ACTION_MOVE; } gdk_drag_status(context, preferredAction, dragtime); @@ -2807,11 +2794,7 @@ void ScintillaGTK::DragDataGet(GtkWidget *widget, GdkDragContext *context, if (!sciThis->sel.Empty()) { sciThis->GetSelection(selection_data, info, &sciThis->drag); } -#if GTK_CHECK_VERSION(2,22,0) GdkDragAction action = gdk_drag_context_get_selected_action(context); -#else - GdkDragAction action = context->action; -#endif if (action == GDK_ACTION_MOVE) { for (size_t r=0; rsel.Count(); r++) { if (sciThis->posDrop >= sciThis->sel.Range(r).Start()) { diff --git a/scintilla/gtk/ScintillaGTK.h b/scintilla/gtk/ScintillaGTK.h index a20f3bcd..7cff34ff 100644 --- a/scintilla/gtk/ScintillaGTK.h +++ b/scintilla/gtk/ScintillaGTK.h @@ -6,9 +6,7 @@ #ifndef SCINTILLAGTK_H #define SCINTILLAGTK_H -#ifdef SCI_NAMESPACE namespace Scintilla { -#endif class ScintillaGTKAccessible; @@ -23,12 +21,14 @@ class ScintillaGTK : public ScintillaBase { Window scrollbarh; GtkAdjustment *adjustmentv; GtkAdjustment *adjustmenth; + Window wSelection; int verticalScrollBarWidth; int horizontalScrollBarHeight; SelectionText primary; - GdkEventButton *evbtn; + GdkEvent *evbtn; + guint buttonMouse; bool capturedMouse; bool dragWasDropped; int lastKey; @@ -75,7 +75,9 @@ public: explicit ScintillaGTK(_ScintillaObject *sci_); // Deleted so ScintillaGTK objects can not be copied. ScintillaGTK(const ScintillaGTK &) = delete; + ScintillaGTK(ScintillaGTK &&) = delete; ScintillaGTK &operator=(const ScintillaGTK &) = delete; + ScintillaGTK &operator=(ScintillaGTK &&) = delete; virtual ~ScintillaGTK(); static ScintillaGTK *FromWidget(GtkWidget *widget); static void ClassInit(OBJECT_CLASS* object_class, GtkWidgetClass *widget_class, GtkContainerClass *container_class); @@ -86,8 +88,8 @@ private: void DisplayCursor(Window::Cursor c) override; bool DragThreshold(Point ptStart, Point ptNow) override; void StartDrag() override; - int TargetAsUTF8(char *text); - int EncodedFromUTF8(char *utf8, char *encoded) const; + Sci::Position TargetAsUTF8(char *text) const; + Sci::Position EncodedFromUTF8(const char *utf8, char *encoded) const; bool ValidCodePage(int codePage) const override; public: // Public for scintilla_send_message sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) override; @@ -100,7 +102,6 @@ private: TimeThunk() : reason(tickCaret), scintilla(NULL), timer(0) {} }; TimeThunk timers[tickDwell+1]; - bool FineTickerAvailable() override; bool FineTickerRunning(TickReason reason) override; void FineTickerStart(TickReason reason, int millis, int tolerance) override; void FineTickerCancel(TickReason reason) override; @@ -140,6 +141,8 @@ private: static void ClipboardClearSelection(GtkClipboard* clip, void *data); void UnclaimSelection(GdkEventSelection *selection_event); + static void PrimarySelection(GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint time_stamp, ScintillaGTK *sciThis); + static gboolean PrimaryClear(GtkWidget *widget, GdkEventSelection *event, ScintillaGTK *sciThis); void Resize(int width, int height); // Callback functions @@ -282,8 +285,6 @@ public: std::string ConvertText(const char *s, size_t len, const char *charSetDest, const char *charSetSource, bool transliterations, bool silent=false); -#ifdef SCI_NAMESPACE } -#endif #endif diff --git a/scintilla/gtk/ScintillaGTKAccessible.cxx b/scintilla/gtk/ScintillaGTKAccessible.cxx index fdcc20db..ffcba560 100644 --- a/scintilla/gtk/ScintillaGTKAccessible.cxx +++ b/scintilla/gtk/ScintillaGTKAccessible.cxx @@ -84,6 +84,7 @@ // ScintillaGTK.h and stuff it needs #include "Platform.h" +#include "ILoader.h" #include "ILexer.h" #include "Scintilla.h" #include "ScintillaWidget.h" @@ -104,7 +105,6 @@ #include "CallTip.h" #include "KeyMap.h" #include "Indicator.h" -#include "XPM.h" #include "LineMarker.h" #include "Style.h" #include "ViewStyle.h" @@ -114,7 +114,6 @@ #include "Document.h" #include "CaseConvert.h" #include "UniConversion.h" -#include "UnicodeFromUTF8.h" #include "Selection.h" #include "PositionCache.h" #include "EditModel.h" @@ -127,9 +126,7 @@ #include "ScintillaGTK.h" #include "ScintillaGTKAccessible.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif struct ScintillaObjectAccessiblePrivate { ScintillaGTKAccessible *pscin; @@ -764,7 +761,7 @@ void ScintillaGTKAccessible::PasteText(int charPosition) { } static void TextReceivedCallback(GtkClipboard *clipboard, const gchar *text, gpointer data) { - Helper *helper = reinterpret_cast(data); + Helper *helper = static_cast(data); try { if (helper->scia != 0) { helper->TextReceived(clipboard, text); diff --git a/scintilla/gtk/ScintillaGTKAccessible.h b/scintilla/gtk/ScintillaGTKAccessible.h index bb47ddf3..2c39d525 100644 --- a/scintilla/gtk/ScintillaGTKAccessible.h +++ b/scintilla/gtk/ScintillaGTKAccessible.h @@ -6,9 +6,7 @@ #ifndef SCINTILLAGTKACCESSIBLE_H #define SCINTILLAGTKACCESSIBLE_H -#ifdef SCI_NAMESPACE namespace Scintilla { -#endif #ifndef ATK_CHECK_VERSION # define ATK_CHECK_VERSION(x, y, z) 0 @@ -34,7 +32,7 @@ private: void Notify(GtkWidget *widget, gint code, SCNotification *nt); static void SciNotify(GtkWidget *widget, gint code, SCNotification *nt, gpointer data) { try { - reinterpret_cast(data)->Notify(widget, code, nt); + static_cast(data)->Notify(widget, code, nt); } catch (...) {} } @@ -188,9 +186,7 @@ public: }; }; -#ifdef SCI_NAMESPACE } -#endif #endif /* SCINTILLAGTKACCESSIBLE_H */ diff --git a/scintilla/gtk/scintilla-marshal.c b/scintilla/gtk/scintilla-marshal.c index c91bd0bc..ea013eb9 100644 --- a/scintilla/gtk/scintilla-marshal.c +++ b/scintilla/gtk/scintilla-marshal.c @@ -1,6 +1,4 @@ - -#include - +#include #ifdef G_ENABLE_DEBUG #define g_marshal_value_peek_boolean(v) g_value_get_boolean (v) @@ -48,8 +46,7 @@ #define g_marshal_value_peek_variant(v) (v)->data[0].v_pointer #endif /* !G_ENABLE_DEBUG */ - -/* NONE:INT,OBJECT (scintilla-marshal.list:1) */ +/* VOID:INT,OBJECT (scintilla-marshal.list:1) */ void scintilla_marshal_VOID__INT_OBJECT (GClosure *closure, GValue *return_value G_GNUC_UNUSED, @@ -58,13 +55,13 @@ scintilla_marshal_VOID__INT_OBJECT (GClosure *closure, gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data) { - typedef void (*GMarshalFunc_VOID__INT_OBJECT) (gpointer data1, - gint arg_1, - gpointer arg_2, - gpointer data2); - GMarshalFunc_VOID__INT_OBJECT callback; - GCClosure *cc = (GCClosure*) closure; + typedef void (*GMarshalFunc_VOID__INT_OBJECT) (gpointer data1, + gint arg1, + gpointer arg2, + gpointer data2); + GCClosure *cc = (GCClosure *) closure; gpointer data1, data2; + GMarshalFunc_VOID__INT_OBJECT callback; g_return_if_fail (n_param_values == 3); @@ -86,7 +83,7 @@ scintilla_marshal_VOID__INT_OBJECT (GClosure *closure, data2); } -/* NONE:INT,BOXED (scintilla-marshal.list:2) */ +/* VOID:INT,BOXED (scintilla-marshal.list:2) */ void scintilla_marshal_VOID__INT_BOXED (GClosure *closure, GValue *return_value G_GNUC_UNUSED, @@ -95,13 +92,13 @@ scintilla_marshal_VOID__INT_BOXED (GClosure *closure, gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data) { - typedef void (*GMarshalFunc_VOID__INT_BOXED) (gpointer data1, - gint arg_1, - gpointer arg_2, - gpointer data2); - GMarshalFunc_VOID__INT_BOXED callback; - GCClosure *cc = (GCClosure*) closure; + typedef void (*GMarshalFunc_VOID__INT_BOXED) (gpointer data1, + gint arg1, + gpointer arg2, + gpointer data2); + GCClosure *cc = (GCClosure *) closure; gpointer data1, data2; + GMarshalFunc_VOID__INT_BOXED callback; g_return_if_fail (n_param_values == 3); diff --git a/scintilla/gtk/scintilla-marshal.h b/scintilla/gtk/scintilla-marshal.h index 7d5e17bb..cac17ad6 100644 --- a/scintilla/gtk/scintilla-marshal.h +++ b/scintilla/gtk/scintilla-marshal.h @@ -1,30 +1,30 @@ +/* This file is generated, all changes will be lost */ +#ifndef __SCINTILLA_MARSHAL_MARSHAL_H__ +#define __SCINTILLA_MARSHAL_MARSHAL_H__ -#ifndef __scintilla_marshal_MARSHAL_H__ -#define __scintilla_marshal_MARSHAL_H__ - -#include +#include G_BEGIN_DECLS -/* NONE:INT,OBJECT (scintilla-marshal.list:1) */ -extern void scintilla_marshal_VOID__INT_OBJECT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); -#define scintilla_marshal_NONE__INT_OBJECT scintilla_marshal_VOID__INT_OBJECT +/* VOID:INT,OBJECT (scintilla-marshal.list:1) */ +extern +void scintilla_marshal_VOID__INT_OBJECT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +/* VOID:INT,BOXED (scintilla-marshal.list:2) */ +extern +void scintilla_marshal_VOID__INT_BOXED (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); -/* NONE:INT,BOXED (scintilla-marshal.list:2) */ -extern void scintilla_marshal_VOID__INT_BOXED (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); -#define scintilla_marshal_NONE__INT_BOXED scintilla_marshal_VOID__INT_BOXED G_END_DECLS -#endif /* __scintilla_marshal_MARSHAL_H__ */ - +#endif /* __SCINTILLA_MARSHAL_MARSHAL_H__ */ diff --git a/scintilla/gtk/scintilla-marshal.list b/scintilla/gtk/scintilla-marshal.list index ddc8ae87..b2e2a212 100644 --- a/scintilla/gtk/scintilla-marshal.list +++ b/scintilla/gtk/scintilla-marshal.list @@ -1,2 +1,2 @@ -NONE:INT,OBJECT -NONE:INT,BOXED +VOID:INT,OBJECT +VOID:INT,BOXED diff --git a/scintilla/include/ILexer.h b/scintilla/include/ILexer.h index f0102917..42f980f8 100644 --- a/scintilla/include/ILexer.h +++ b/scintilla/include/ILexer.h @@ -10,15 +10,7 @@ #include "Sci_Position.h" -#ifdef SCI_NAMESPACE namespace Scintilla { -#endif - -#ifdef _WIN32 - #define SCI_METHOD __stdcall -#else - #define SCI_METHOD -#endif enum { dvOriginal=0, dvLineEnd=1 }; @@ -54,7 +46,7 @@ public: virtual int SCI_METHOD GetCharacterAndWidth(Sci_Position position, Sci_Position *pWidth) const = 0; }; -enum { lvOriginal=0, lvSubStyles=1 }; +enum { lvOriginal=0, lvSubStyles=1, lvMetaData=2 }; class ILexer { public: @@ -85,16 +77,14 @@ public: virtual const char * SCI_METHOD GetSubStyleBases() = 0; }; -class ILoader { +class ILexerWithMetaData : public ILexerWithSubStyles { public: - virtual int SCI_METHOD Release() = 0; - // Returns a status code from SC_STATUS_* - virtual int SCI_METHOD AddData(char *data, Sci_Position length) = 0; - virtual void * SCI_METHOD ConvertToDocument() = 0; + virtual int SCI_METHOD NamedStyles() = 0; + virtual const char * SCI_METHOD NameOfStyle(int style) = 0; + virtual const char * SCI_METHOD TagsOfStyle(int style) = 0; + virtual const char * SCI_METHOD DescriptionOfStyle(int style) = 0; }; -#ifdef SCI_NAMESPACE } -#endif #endif diff --git a/scintilla/include/ILoader.h b/scintilla/include/ILoader.h new file mode 100644 index 00000000..e989de87 --- /dev/null +++ b/scintilla/include/ILoader.h @@ -0,0 +1,21 @@ +// Scintilla source code edit control +/** @file ILoader.h + ** Interface for loading into a Scintilla document from a background thread. + **/ +// Copyright 1998-2017 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#ifndef ILOADER_H +#define ILOADER_H + +#include "Sci_Position.h" + +class ILoader { +public: + virtual int SCI_METHOD Release() = 0; + // Returns a status code from SC_STATUS_* + virtual int SCI_METHOD AddData(const char *data, Sci_Position length) = 0; + virtual void * SCI_METHOD ConvertToDocument() = 0; +}; + +#endif diff --git a/scintilla/include/Platform.h b/scintilla/include/Platform.h index 570ba738..4299546a 100644 --- a/scintilla/include/Platform.h +++ b/scintilla/include/Platform.h @@ -71,15 +71,10 @@ #endif -#ifdef SCI_NAMESPACE namespace Scintilla { -#endif typedef float XYPOSITION; typedef double XYACCUMULATOR; -inline int RoundXYPosition(XYPOSITION xyPos) { - return static_cast(xyPos + 0.5); -} // Underlying the implementation of the platform classes are platform specific types. // Sometimes these need to be passed around by client code so they are defined here @@ -101,21 +96,19 @@ public: XYPOSITION x; XYPOSITION y; - explicit Point(XYPOSITION x_=0, XYPOSITION y_=0) : x(x_), y(y_) { + constexpr explicit Point(XYPOSITION x_=0, XYPOSITION y_=0) noexcept : x(x_), y(y_) { } - static Point FromInts(int x_, int y_) { + static Point FromInts(int x_, int y_) noexcept { return Point(static_cast(x_), static_cast(y_)); } // Other automatically defined methods (assignment, copy constructor, destructor) are fine - - static Point FromLong(long lpoint); }; /** * A geometric rectangle class. - * PRectangle is similar to the Win32 RECT. + * PRectangle is similar to Win32 RECT. * PRectangles contain their top and left sides, but not their right and bottom sides. */ class PRectangle { @@ -125,113 +118,147 @@ public: XYPOSITION right; XYPOSITION bottom; - explicit PRectangle(XYPOSITION left_=0, XYPOSITION top_=0, XYPOSITION right_=0, XYPOSITION bottom_ = 0) : + constexpr explicit PRectangle(XYPOSITION left_=0, XYPOSITION top_=0, XYPOSITION right_=0, XYPOSITION bottom_ = 0) noexcept : left(left_), top(top_), right(right_), bottom(bottom_) { } - static PRectangle FromInts(int left_, int top_, int right_, int bottom_) { + static PRectangle FromInts(int left_, int top_, int right_, int bottom_) noexcept { return PRectangle(static_cast(left_), static_cast(top_), static_cast(right_), static_cast(bottom_)); } // Other automatically defined methods (assignment, copy constructor, destructor) are fine - bool operator==(const PRectangle &rc) const { + bool operator==(const PRectangle &rc) const noexcept { return (rc.left == left) && (rc.right == right) && (rc.top == top) && (rc.bottom == bottom); } - bool Contains(Point pt) const { + bool Contains(Point pt) const noexcept { return (pt.x >= left) && (pt.x <= right) && (pt.y >= top) && (pt.y <= bottom); } - bool ContainsWholePixel(Point pt) const { + bool ContainsWholePixel(Point pt) const noexcept { // Does the rectangle contain all of the pixel to left/below the point return (pt.x >= left) && ((pt.x+1) <= right) && (pt.y >= top) && ((pt.y+1) <= bottom); } - bool Contains(PRectangle rc) const { + bool Contains(PRectangle rc) const noexcept { return (rc.left >= left) && (rc.right <= right) && (rc.top >= top) && (rc.bottom <= bottom); } - bool Intersects(PRectangle other) const { + bool Intersects(PRectangle other) const noexcept { return (right > other.left) && (left < other.right) && (bottom > other.top) && (top < other.bottom); } - void Move(XYPOSITION xDelta, XYPOSITION yDelta) { + void Move(XYPOSITION xDelta, XYPOSITION yDelta) noexcept { left += xDelta; top += yDelta; right += xDelta; bottom += yDelta; } - XYPOSITION Width() const { return right - left; } - XYPOSITION Height() const { return bottom - top; } - bool Empty() const { + XYPOSITION Width() const noexcept { return right - left; } + XYPOSITION Height() const noexcept { return bottom - top; } + bool Empty() const noexcept { return (Height() <= 0) || (Width() <= 0); } }; /** - * Holds a desired RGB colour. + * Holds an RGB colour with 8 bits for each component. */ +constexpr const float componentMaximum = 255.0f; class ColourDesired { - long co; + int co; public: - ColourDesired(long lcol=0) { - co = lcol; + explicit ColourDesired(int co_=0) noexcept : co(co_) { } - ColourDesired(unsigned int red, unsigned int green, unsigned int blue) { - Set(red, green, blue); + ColourDesired(unsigned int red, unsigned int green, unsigned int blue) noexcept : + co(red | (green << 8) | (blue << 16)) { } - bool operator==(const ColourDesired &other) const { + bool operator==(const ColourDesired &other) const noexcept { return co == other.co; } - void Set(long lcol) { - co = lcol; - } - - void Set(unsigned int red, unsigned int green, unsigned int blue) { - co = red | (green << 8) | (blue << 16); - } - - static inline unsigned int ValueOfHex(const char ch) { - if (ch >= '0' && ch <= '9') - return ch - '0'; - else if (ch >= 'A' && ch <= 'F') - return ch - 'A' + 10; - else if (ch >= 'a' && ch <= 'f') - return ch - 'a' + 10; - else - return 0; - } - - void Set(const char *val) { - if (*val == '#') { - val++; - } - unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]); - unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]); - unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]); - Set(r, g, b); - } - - long AsLong() const { + int AsInteger() const noexcept { return co; } - unsigned int GetRed() const { + // Red, green and blue values as bytes 0..255 + unsigned char GetRed() const noexcept { return co & 0xff; } - - unsigned int GetGreen() const { + unsigned char GetGreen() const noexcept { return (co >> 8) & 0xff; } - - unsigned int GetBlue() const { + unsigned char GetBlue() const noexcept { return (co >> 16) & 0xff; } + + // Red, green and blue values as float 0..1.0 + float GetRedComponent() const noexcept { + return GetRed() / componentMaximum; + } + float GetGreenComponent() const noexcept { + return GetGreen() / componentMaximum; + } + float GetBlueComponent() const noexcept { + return GetBlue() / componentMaximum; + } +}; + +/** +* Holds an RGBA colour. +*/ +class ColourAlpha : public ColourDesired { +public: + explicit ColourAlpha(int co_ = 0) noexcept : ColourDesired(co_) { + } + + ColourAlpha(unsigned int red, unsigned int green, unsigned int blue) noexcept : + ColourDesired(red | (green << 8) | (blue << 16)) { + } + + ColourAlpha(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha) noexcept : + ColourDesired(red | (green << 8) | (blue << 16) | (alpha << 24)) { + } + + ColourAlpha(ColourDesired cd, unsigned int alpha) noexcept : + ColourDesired(cd.AsInteger() | (alpha << 24)) { + } + + ColourDesired GetColour() const noexcept { + return ColourDesired(AsInteger() & 0xffffff); + } + + unsigned char GetAlpha() const noexcept { + return (AsInteger() >> 24) & 0xff; + } + + float GetAlphaComponent() const noexcept { + return GetAlpha() / componentMaximum; + } + + ColourAlpha MixedWith(ColourAlpha other) const noexcept { + const unsigned int red = (GetRed() + other.GetRed()) / 2; + const unsigned int green = (GetGreen() + other.GetGreen()) / 2; + const unsigned int blue = (GetBlue() + other.GetBlue()) / 2; + const unsigned int alpha = (GetAlpha() + other.GetAlpha()) / 2; + return ColourAlpha(red, green, blue, alpha); + } +}; + +/** +* Holds an element of a gradient with an RGBA colour and a relative position. +*/ +class ColourStop { +public: + float position; + ColourAlpha colour; + ColourStop(float position_, ColourAlpha colour_) noexcept : + position(position_), colour(colour_) { + } }; /** @@ -254,7 +281,7 @@ struct FontParameters { bool italic_=false, int extraFontFlag_=0, int technology_=0, - int characterSet_=0) : + int characterSet_=0) noexcept : faceName(faceName_), size(size_), @@ -271,19 +298,21 @@ struct FontParameters { class Font { protected: FontID fid; - // Private so Font objects can not be copied - Font(const Font &); - Font &operator=(const Font &); public: - Font(); + Font() noexcept; + // Deleted so Font objects can not be copied + Font(const Font &) = delete; + Font(Font &&) = delete; + Font &operator=(const Font &) = delete; + Font &operator=(Font &&) = delete; virtual ~Font(); virtual void Create(const FontParameters &fp); virtual void Release(); - FontID GetID() { return fid; } + FontID GetID() const noexcept { return fid; } // Alias another font - caller guarantees not to Release - void SetID(FontID fid_) { fid = fid_; } + void SetID(FontID fid_) noexcept { fid = fid_; } friend class Surface; friend class SurfaceImpl; }; @@ -292,12 +321,12 @@ public: * A surface abstracts a place to draw. */ class Surface { -private: - // Private so Surface objects can not be copied - Surface(const Surface &) {} - Surface &operator=(const Surface &) { return *this; } public: - Surface() {} + Surface() noexcept = default; + Surface(const Surface &) = delete; + Surface(Surface &&) = delete; + Surface &operator=(const Surface &) = delete; + Surface &operator=(Surface &&) = delete; virtual ~Surface() {} static Surface *Allocate(int technology); @@ -312,13 +341,15 @@ public: virtual int DeviceHeightFont(int points)=0; virtual void MoveTo(int x_, int y_)=0; virtual void LineTo(int x_, int y_)=0; - virtual void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back)=0; + virtual void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back)=0; virtual void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back)=0; virtual void FillRectangle(PRectangle rc, ColourDesired back)=0; virtual void FillRectangle(PRectangle rc, Surface &surfacePattern)=0; virtual void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back)=0; virtual void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, ColourDesired outline, int alphaOutline, int flags)=0; + enum class GradientOptions { leftToRight, topToBottom }; + virtual void GradientRectangle(PRectangle rc, const std::vector &stops, GradientOptions options)=0; virtual void DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) = 0; virtual void Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back)=0; virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource)=0; @@ -328,11 +359,9 @@ public: virtual void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore)=0; virtual void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions)=0; virtual XYPOSITION WidthText(Font &font_, const char *s, int len)=0; - virtual XYPOSITION WidthChar(Font &font_, char ch)=0; virtual XYPOSITION Ascent(Font &font_)=0; virtual XYPOSITION Descent(Font &font_)=0; virtual XYPOSITION InternalLeading(Font &font_)=0; - virtual XYPOSITION ExternalLeading(Font &font_)=0; virtual XYPOSITION Height(Font &font_)=0; virtual XYPOSITION AverageCharWidth(Font &font_)=0; @@ -343,11 +372,6 @@ public: virtual void SetDBCSMode(int codePage)=0; }; -/** - * A simple callback action passing one piece of untyped user data. - */ -typedef void (*CallBackAction)(void*); - /** * Class to hide the details of window manipulation. * Does not own the window which will normally have a longer life than this object. @@ -356,38 +380,31 @@ class Window { protected: WindowID wid; public: - Window() : wid(0), cursorLast(cursorInvalid) { + Window() noexcept : wid(nullptr), cursorLast(cursorInvalid) { } - Window(const Window &source) : wid(source.wid), cursorLast(cursorInvalid) { - } - virtual ~Window(); - Window &operator=(WindowID wid_) { + Window(const Window &source) = delete; + Window(Window &&) = delete; + Window &operator=(WindowID wid_) noexcept { wid = wid_; cursorLast = cursorInvalid; return *this; } - Window &operator=(const Window &other) { - if (this != &other) { - wid = other.wid; - cursorLast = other.cursorLast; - } - return *this; - } - WindowID GetID() const { return wid; } - bool Created() const { return wid != 0; } + Window &operator=(const Window &) = delete; + Window &operator=(Window &&) = delete; + virtual ~Window(); + WindowID GetID() const noexcept { return wid; } + bool Created() const noexcept { return wid != nullptr; } void Destroy(); - bool HasFocus(); - PRectangle GetPosition(); + PRectangle GetPosition() const; void SetPosition(PRectangle rc); - void SetPositionRelative(PRectangle rc, Window relativeTo); - PRectangle GetClientPosition(); + void SetPositionRelative(PRectangle rc, const Window *relativeTo); + PRectangle GetClientPosition() const; void Show(bool show=true); void InvalidateAll(); void InvalidateRectangle(PRectangle rc); virtual void SetFont(Font &font); enum Cursor { cursorInvalid, cursorText, cursorArrow, cursorUp, cursorWait, cursorHoriz, cursorVert, cursorReverseArrow, cursorHand }; void SetCursor(Cursor curs); - void SetTitle(const char *s); PRectangle GetMonitorRect(Point pt); private: Cursor cursorLast; @@ -397,13 +414,26 @@ private: * Listbox management. */ +// ScintillaBase implements IListBoxDelegate to receive ListBoxEvents from a ListBox + +struct ListBoxEvent { + enum class EventType { selectionChange, doubleClick } event; + ListBoxEvent(EventType event_) noexcept : event(event_) { + } +}; + +class IListBoxDelegate { +public: + virtual void ListNotify(ListBoxEvent *plbe)=0; +}; + class ListBox : public Window { public: - ListBox(); - virtual ~ListBox(); + ListBox() noexcept; + ~ListBox() override; static ListBox *Allocate(); - virtual void SetFont(Font &font)=0; + void SetFont(Font &font) override =0; virtual void Create(Window &parent, int ctrlID, Point location, int lineHeight_, bool unicodeMode_, int technology_)=0; virtual void SetAverageCharWidth(int width)=0; virtual void SetVisibleRows(int rows)=0; @@ -420,7 +450,7 @@ public: virtual void RegisterImage(int type, const char *xpm_data)=0; virtual void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) = 0; virtual void ClearRegisteredImages()=0; - virtual void SetDoubleClickAction(CallBackAction, void *)=0; + virtual void SetDelegate(IListBoxDelegate *lbDelegate)=0; virtual void SetList(const char* list, char separator, char typesep)=0; }; @@ -430,27 +460,19 @@ public: class Menu { MenuID mid; public: - Menu(); - MenuID GetID() { return mid; } + Menu() noexcept; + MenuID GetID() const noexcept { return mid; } void CreatePopUp(); void Destroy(); void Show(Point pt, Window &w); }; -class ElapsedTime { - long bigBit; - long littleBit; -public: - ElapsedTime(); - double Duration(bool reset=false); -}; - /** * Dynamic Library (DLL/SO/...) loading */ class DynamicLibrary { public: - virtual ~DynamicLibrary() {} + virtual ~DynamicLibrary() = default; /// @return Pointer to function "name", or NULL on failure. virtual Function FindFunction(const char *name) = 0; @@ -477,61 +499,34 @@ public: * and chrome colour. Not a creatable object, more of a module with several functions. */ class Platform { - // Private so Platform objects can not be copied - Platform(const Platform &) {} - Platform &operator=(const Platform &) { return *this; } public: - // Should be private because no new Platforms are ever created - // but gcc warns about this - Platform() {} - ~Platform() {} + Platform() = default; + Platform(const Platform &) = delete; + Platform(Platform &&) = delete; + Platform &operator=(const Platform &) = delete; + Platform &operator=(Platform &&) = delete; + ~Platform() = default; static ColourDesired Chrome(); static ColourDesired ChromeHighlight(); static const char *DefaultFont(); static int DefaultFontSize(); static unsigned int DoubleClickTime(); - static bool MouseButtonBounce(); static void DebugDisplay(const char *s); - static bool IsKeyDown(int key); - static long SendScintilla( - WindowID w, unsigned int msg, unsigned long wParam=0, long lParam=0); - static long SendScintillaPointer( - WindowID w, unsigned int msg, unsigned long wParam=0, void *lParam=0); - static bool IsDBCSLeadByte(int codePage, char ch); - static int DBCSCharLength(int codePage, const char *s); - static int DBCSCharMaxLength(); - - // These are utility functions not really tied to a platform - static int Minimum(int a, int b); - static int Maximum(int a, int b); - // Next three assume 16 bit shorts and 32 bit longs - static long LongFromTwoShorts(short a,short b) { + static constexpr long LongFromTwoShorts(short a,short b) noexcept { return (a) | ((b) << 16); } - static short HighShortFromLong(long x) { - return static_cast(x >> 16); - } - static short LowShortFromLong(long x) { - return static_cast(x & 0xffff); - } + static void DebugPrintf(const char *format, ...); static bool ShowAssertionPopUps(bool assertionPopUps_); static void Assert(const char *c, const char *file, int line) CLANG_ANALYZER_NORETURN; - static int Clamp(int val, int minVal, int maxVal); }; #ifdef NDEBUG #define PLATFORM_ASSERT(c) ((void)0) #else -#ifdef SCI_NAMESPACE #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Scintilla::Platform::Assert(#c, __FILE__, __LINE__)) -#else -#define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Platform::Assert(#c, __FILE__, __LINE__)) -#endif #endif -#ifdef SCI_NAMESPACE } -#endif #endif diff --git a/scintilla/include/SciLexer.h b/scintilla/include/SciLexer.h index cc5139e9..cde410f9 100644 --- a/scintilla/include/SciLexer.h +++ b/scintilla/include/SciLexer.h @@ -135,6 +135,8 @@ #define SCLEX_JSON 120 #define SCLEX_EDIFACT 121 #define SCLEX_INDENT 122 +#define SCLEX_MAXIMA 123 +#define SCLEX_LPEG 999 #define SCLEX_AUTOMATIC 1000 #define SCE_P_DEFAULT 0 #define SCE_P_COMMENTLINE 1 @@ -557,6 +559,10 @@ #define SCE_DIFF_DELETED 5 #define SCE_DIFF_ADDED 6 #define SCE_DIFF_CHANGED 7 +#define SCE_DIFF_PATCH_ADD 8 +#define SCE_DIFF_PATCH_DELETE 9 +#define SCE_DIFF_REMOVED_PATCH_ADD 10 +#define SCE_DIFF_REMOVED_PATCH_DELETE 11 #define SCE_CONF_DEFAULT 0 #define SCE_CONF_COMMENT 1 #define SCE_CONF_NUMBER 2 @@ -672,6 +678,14 @@ #define SCE_MATLAB_OPERATOR 6 #define SCE_MATLAB_IDENTIFIER 7 #define SCE_MATLAB_DOUBLEQUOTESTRING 8 +#define SCE_MAXIMA_OPERATOR 0 +#define SCE_MAXIMA_COMMANDENDING 1 +#define SCE_MAXIMA_COMMENT 2 +#define SCE_MAXIMA_NUMBER 3 +#define SCE_MAXIMA_STRING 4 +#define SCE_MAXIMA_COMMAND 5 +#define SCE_MAXIMA_VARIABLE 6 +#define SCE_MAXIMA_UNKNOWN 7 #define SCE_SCRIPTOL_DEFAULT 0 #define SCE_SCRIPTOL_WHITE 1 #define SCE_SCRIPTOL_COMMENTLINE 2 diff --git a/scintilla/include/Sci_Position.h b/scintilla/include/Sci_Position.h index a83e2864..abd0f340 100644 --- a/scintilla/include/Sci_Position.h +++ b/scintilla/include/Sci_Position.h @@ -9,13 +9,21 @@ #ifndef SCI_POSITION_H #define SCI_POSITION_H +#include + // Basic signed type used throughout interface -typedef int Sci_Position; +typedef ptrdiff_t Sci_Position; // Unsigned variant used for ILexer::Lex and ILexer::Fold -typedef unsigned int Sci_PositionU; +typedef size_t Sci_PositionU; // For Sci_CharacterRange which is defined as long to be compatible with Win32 CHARRANGE typedef long Sci_PositionCR; +#ifdef _WIN32 + #define SCI_METHOD __stdcall +#else + #define SCI_METHOD +#endif + #endif diff --git a/scintilla/include/Scintilla.h b/scintilla/include/Scintilla.h index 58643a8d..70f17918 100644 --- a/scintilla/include/Scintilla.h +++ b/scintilla/include/Scintilla.h @@ -27,12 +27,7 @@ int Scintilla_LinkLexers(void); #endif // Include header that defines basic numeric types. -#if defined(_MSC_VER) -// Older releases of MSVC did not have stdint.h. -#include -#else #include -#endif // Define uptr_t, an unsigned integer type large enough to hold a pointer. typedef uintptr_t uptr_t; @@ -293,6 +288,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define INDIC_TEXTFORE 17 #define INDIC_POINT 18 #define INDIC_POINTCHARACTER 19 +#define INDIC_GRADIENT 20 +#define INDIC_GRADIENTCENTRE 21 #define INDIC_IME 32 #define INDIC_IME_MAX 35 #define INDIC_MAX 35 @@ -320,8 +317,6 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETWHITESPACEBACK 2085 #define SCI_SETWHITESPACESIZE 2086 #define SCI_GETWHITESPACESIZE 2087 -#define SCI_SETSTYLEBITS 2090 -#define SCI_GETSTYLEBITS 2091 #define SCI_SETLINESTATE 2092 #define SCI_GETLINESTATE 2093 #define SCI_GETMAXLINESTATE 2094 @@ -397,6 +392,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_PRINT_BLACKONWHITE 2 #define SC_PRINT_COLOURONWHITE 3 #define SC_PRINT_COLOURONWHITEDEFAULTBG 4 +#define SC_PRINT_SCREENCOLOURS 5 #define SCI_SETPRINTCOLOURMODE 2148 #define SCI_GETPRINTCOLOURMODE 2149 #define SCFIND_WHOLEWORD 0x2 @@ -552,6 +548,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_WRAPINDENT_FIXED 0 #define SC_WRAPINDENT_SAME 1 #define SC_WRAPINDENT_INDENT 2 +#define SC_WRAPINDENT_DEEPINDENT 3 #define SCI_SETWRAPINDENTMODE 2472 #define SCI_GETWRAPINDENTMODE 2473 #define SC_CACHE_NONE 0 @@ -693,9 +690,13 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SELECTIONISRECTANGLE 2372 #define SCI_SETZOOM 2373 #define SCI_GETZOOM 2374 +#define SC_DOCUMENTOPTION_DEFAULT 0 +#define SC_DOCUMENTOPTION_STYLES_NONE 0x1 +#define SC_DOCUMENTOPTION_TEXT_LARGE 0x100 #define SCI_CREATEDOCUMENT 2375 #define SCI_ADDREFDOCUMENT 2376 #define SCI_RELEASEDOCUMENT 2377 +#define SCI_GETDOCUMENTOPTIONS 2379 #define SCI_GETMODEVENTMASK 2378 #define SCI_SETFOCUS 2380 #define SCI_GETFOCUS 2381 @@ -762,6 +763,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_SEL_THIN 3 #define SCI_SETSELECTIONMODE 2422 #define SCI_GETSELECTIONMODE 2423 +#define SCI_GETMOVEEXTENDSSELECTION 2706 #define SCI_GETLINESELSTARTPOSITION 2424 #define SCI_GETLINESELENDPOSITION 2425 #define SCI_LINEDOWNRECTEXTEND 2426 @@ -990,7 +992,6 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETPROPERTY 4008 #define SCI_GETPROPERTYEXPANDED 4009 #define SCI_GETPROPERTYINT 4010 -#define SCI_GETSTYLEBITSNEEDED 4011 #define SCI_GETLEXERLANGUAGE 4012 #define SCI_PRIVATELEXERCALL 4013 #define SCI_PROPERTYNAMES 4014 @@ -1010,6 +1011,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETIDENTIFIERS 4024 #define SCI_DISTANCETOSECONDARYSTYLES 4025 #define SCI_GETSUBSTYLEBASES 4026 +#define SCI_GETNAMEDSTYLES 4029 +#define SCI_NAMEOFSTYLE 4030 +#define SCI_TAGSOFSTYLE 4031 +#define SCI_DESCRIPTIONOFSTYLE 4032 #define SC_MOD_INSERTTEXT 0x1 #define SC_MOD_DELETETEXT 0x2 #define SC_MOD_CHANGESTYLE 0x4 @@ -1102,6 +1107,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCN_FOCUSOUT 2029 #define SCN_AUTOCCOMPLETED 2030 #define SCN_MARGINRIGHTCLICK 2031 +#define SCN_AUTOCSELECTIONCHANGE 2032 /* --Autogenerated -- end of section automatically generated from Scintilla.iface */ /* These structures are defined to be exactly the same shape as the Win32 @@ -1210,6 +1216,10 @@ struct SCNotification { #define RangeToFormat Sci_RangeToFormat #define NotifyHeader Sci_NotifyHeader +#define SCI_SETSTYLEBITS 2090 +#define SCI_GETSTYLEBITS 2091 +#define SCI_GETSTYLEBITSNEEDED 4011 + #endif #endif diff --git a/scintilla/include/Scintilla.iface b/scintilla/include/Scintilla.iface index f3520699..d7f7d68e 100644 --- a/scintilla/include/Scintilla.iface +++ b/scintilla/include/Scintilla.iface @@ -639,6 +639,8 @@ val INDIC_FULLBOX=16 val INDIC_TEXTFORE=17 val INDIC_POINT=18 val INDIC_POINTCHARACTER=19 +val INDIC_GRADIENT=20 +val INDIC_GRADIENTCENTRE=21 val INDIC_IME=32 val INDIC_IME_MAX=35 val INDIC_MAX=35 @@ -702,14 +704,6 @@ set void SetWhitespaceSize=2086(int size,) # Get the size of the dots used to mark space characters. get int GetWhitespaceSize=2087(,) -# Divide each styling byte into lexical class bits (default: 5) and indicator -# bits (default: 3). If a lexer requires more than 32 lexical states, then this -# is used to expand the possible states. -set void SetStyleBits=2090(int bits,) - -# Retrieve number of bits in style bytes used to hold the lexical state. -get int GetStyleBits=2091(,) - # Used to hold extra styling information for each line. set void SetLineState=2092(int line, int state) @@ -930,6 +924,7 @@ get int GetPrintMagnification=2147(,) enu PrintOption=SC_PRINT_ # PrintColourMode - use same colours as screen. +# with the exception of line number margins, which use a white background val SC_PRINT_NORMAL=0 # PrintColourMode - invert the light value of each style for printing. val SC_PRINT_INVERTLIGHT=1 @@ -939,6 +934,8 @@ val SC_PRINT_BLACKONWHITE=2 val SC_PRINT_COLOURONWHITE=3 # PrintColourMode - only the default-background is forced to be white for printing. val SC_PRINT_COLOURONWHITEDEFAULTBG=4 +# PrintColourMode - use same colours as screen, including line number margins. +val SC_PRINT_SCREENCOLOURS=5 # Modify colours when printing for clearer printed text. set void SetPrintColourMode=2148(int mode,) @@ -997,7 +994,7 @@ fun int GetSelText=2161(, stringresult text) # Return the length of the text. fun int GetTextRange=2162(, textrange tr) -# Draw the selection in normal style or with selection highlighted. +# Draw the selection either highlighted or in normal (non-highlighted) style. fun void HideSelection=2163(bool hide,) # Retrieve the x value of the point in the window where a position is displayed. @@ -1362,6 +1359,7 @@ enu WrapIndentMode=SC_WRAPINDENT_ val SC_WRAPINDENT_FIXED=0 val SC_WRAPINDENT_SAME=1 val SC_WRAPINDENT_INDENT=2 +val SC_WRAPINDENT_DEEPINDENT=3 # Sets how wrapped sublines are placed. Default is fixed. set void SetWrapIndentMode=2472(int wrapIndentMode,) @@ -1786,14 +1784,22 @@ set void SetZoom=2373(int zoomInPoints,) # Retrieve the zoom level. get int GetZoom=2374(,) +enu DocumentOption=SC_DOCUMENTOPTION_ +val SC_DOCUMENTOPTION_DEFAULT=0 +val SC_DOCUMENTOPTION_STYLES_NONE=0x1 +val SC_DOCUMENTOPTION_TEXT_LARGE=0x100 + # Create a new document object. # Starts with reference count of 1 and not selected into editor. -fun int CreateDocument=2375(,) +fun int CreateDocument=2375(int bytes, int documentOptions) # Extend life of document. fun void AddRefDocument=2376(, int doc) # Release a reference to the document, deleting document if it fades to black. fun void ReleaseDocument=2377(, int doc) +# Get which document options are set. +get int GetDocumentOptions=2379(,) + # Get which document modification events are sent to the container. get int GetModEventMask=2378(,) @@ -1979,6 +1985,9 @@ set void SetSelectionMode=2422(int selectionMode,) # Get the mode of the current selection. get int GetSelectionMode=2423(,) +# Get whether or not regular caret moves will extend or reduce the selection. +get bool GetMoveExtendsSelection=2706(,) + # Retrieve the position of the start of the selection at the given line (INVALID_POSITION if no selection on this line). fun position GetLineSelStartPosition=2424(int line,) @@ -2552,7 +2561,7 @@ set void SetTechnology=2630(int technology,) get int GetTechnology=2631(,) # Create an ILoader*. -fun int CreateLoader=2632(int bytes,) +fun int CreateLoader=2632(int bytes, int documentOptions) # On OS X, show a find indicator. fun void FindIndicatorShow=2640(position start, position end) @@ -2645,9 +2654,6 @@ get int GetPropertyExpanded=4009(string key, stringresult value) # interpreted as an int AFTER any "$()" variable replacement. get int GetPropertyInt=4010(string key, int defaultValue) -# Retrieve the number of bits the current lexer needs for styling. -get int GetStyleBitsNeeded=4011(,) - # Retrieve the name of the lexer. # Return the length of the text. # Result is NUL-terminated. @@ -2709,6 +2715,21 @@ get int DistanceToSecondaryStyles=4025(,) # Result is NUL-terminated. get int GetSubStyleBases=4026(, stringresult styles) +# Retrieve the number of named styles for the lexer. +get int GetNamedStyles=4029(,) + +# Retrieve the name of a style. +# Result is NUL-terminated. +fun int NameOfStyle=4030(int style, stringresult name) + +# Retrieve a ' ' separated list of style tags like "literal quoted string". +# Result is NUL-terminated. +fun int TagsOfStyle=4031(int style, stringresult tags) + +# Retrieve a description of a style. +# Result is NUL-terminated. +fun int DescriptionOfStyle=4032(int style, stringresult description) + # Notifications # Type of modification and the action which caused the modification. # These are defined as a bit mask to make it easy to specify which notifications are wanted. @@ -2917,6 +2938,8 @@ val SCLEX_TEHEX=119 val SCLEX_JSON=120 val SCLEX_EDIFACT=121 val SCLEX_INDENT=122 +val SCLEX_MAXIMA=123 +val SCLEX_LPEG=999 # When a lexer specifies its language as SCLEX_AUTOMATIC it receives a # value assigned in sequence from SCLEX_AUTOMATIC+1. @@ -2944,7 +2967,11 @@ val SCE_P_FSTRING=16 val SCE_P_FCHARACTER=17 val SCE_P_FTRIPLE=18 val SCE_P_FTRIPLEDOUBLE=19 -# Lexical states for SCLEX_CPP, SCLEX_BULLANT, SCLEX_COBOL, SCLEX_TACL, SCLEX_TAL +# Lexical states for SCLEX_CPP +# Lexical states for SCLEX_BULLANT +# Lexical states for SCLEX_COBOL +# Lexical states for SCLEX_TACL +# Lexical states for SCLEX_TAL lex Cpp=SCLEX_CPP SCE_C_ lex BullAnt=SCLEX_BULLANT SCE_C_ lex COBOL=SCLEX_COBOL SCE_C_ @@ -3397,6 +3424,10 @@ val SCE_DIFF_POSITION=4 val SCE_DIFF_DELETED=5 val SCE_DIFF_ADDED=6 val SCE_DIFF_CHANGED=7 +val SCE_DIFF_PATCH_ADD=8 +val SCE_DIFF_PATCH_DELETE=9 +val SCE_DIFF_REMOVED_PATCH_ADD=10 +val SCE_DIFF_REMOVED_PATCH_DELETE=11 # Lexical states for SCLEX_CONF (Apache Configuration Files Lexer) lex Conf=SCLEX_CONF SCE_CONF_ val SCE_CONF_DEFAULT=0 @@ -3532,6 +3563,16 @@ val SCE_MATLAB_STRING=5 val SCE_MATLAB_OPERATOR=6 val SCE_MATLAB_IDENTIFIER=7 val SCE_MATLAB_DOUBLEQUOTESTRING=8 +# Lexical states for SCLEX_MAXIMA +lex Maxima=SCLEX_MAXIMA SCE_MAXIMA_ +val SCE_MAXIMA_OPERATOR=0 +val SCE_MAXIMA_COMMANDENDING=1 +val SCE_MAXIMA_COMMENT=2 +val SCE_MAXIMA_NUMBER=3 +val SCE_MAXIMA_STRING=4 +val SCE_MAXIMA_COMMAND=5 +val SCE_MAXIMA_VARIABLE=6 +val SCE_MAXIMA_UNKNOWN=7 # Lexical states for SCLEX_SCRIPTOL lex Sol=SCLEX_SCRIPTOL SCE_SCRIPTOL_ val SCE_SCRIPTOL_DEFAULT=0 @@ -4855,13 +4896,25 @@ evt void FocusIn=2028(void) evt void FocusOut=2029(void) evt void AutoCCompleted=2030(string text, int position, int ch, CompletionMethods listCompletionMethod) evt void MarginRightClick=2031(int modifiers, int position, int margin) +evt void AutoCSelectionChange=2032(int listType, string text, int position) -# There are no provisional APIs currently, but some arguments to SCI_SETTECHNOLOGY are provisional. +# There are no provisional APIs currently. cat Provisional cat Deprecated +# Divide each styling byte into lexical class bits (default: 5) and indicator +# bits (default: 3). If a lexer requires more than 32 lexical states, then this +# is used to expand the possible states. +set void SetStyleBits=2090(int bits,) + +# Retrieve number of bits in style bytes used to hold the lexical state. +get int GetStyleBits=2091(,) + +# Retrieve the number of bits the current lexer needs for styling. +get int GetStyleBitsNeeded=4011(,) + # Deprecated in 3.5.5 # Always interpret keyboard input as Unicode diff --git a/scintilla/lexers/LexAbaqus.cxx b/scintilla/lexers/LexAbaqus.cxx index 5f265c72..96a7b886 100644 --- a/scintilla/lexers/LexAbaqus.cxx +++ b/scintilla/lexers/LexAbaqus.cxx @@ -26,9 +26,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAKeywordChar(const int ch) { return (ch < 0x80 && (isalnum(ch) || (ch == '_') || (ch == ' '))); diff --git a/scintilla/lexers/LexAda.cxx b/scintilla/lexers/LexAda.cxx index df26d757..9d7f5d0f 100644 --- a/scintilla/lexers/LexAda.cxx +++ b/scintilla/lexers/LexAda.cxx @@ -25,9 +25,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /* * Interface diff --git a/scintilla/lexers/LexAsm.cxx b/scintilla/lexers/LexAsm.cxx index 78550bba..bd82b162 100644 --- a/scintilla/lexers/LexAsm.cxx +++ b/scintilla/lexers/LexAsm.cxx @@ -30,10 +30,9 @@ #include "CharacterSet.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '.' || @@ -139,7 +138,7 @@ struct OptionSetAsm : public OptionSet { } }; -class LexerAsm : public ILexer { +class LexerAsm : public DefaultLexer { WordList cpuInstruction; WordList mathInstruction; WordList registers; diff --git a/scintilla/lexers/LexBash.cxx b/scintilla/lexers/LexBash.cxx index 9c02c289..931d1bf4 100644 --- a/scintilla/lexers/LexBash.cxx +++ b/scintilla/lexers/LexBash.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif #define HERE_DELIM_MAX 256 diff --git a/scintilla/lexers/LexBasic.cxx b/scintilla/lexers/LexBasic.cxx index 4aa449d4..4ec58dcd 100644 --- a/scintilla/lexers/LexBasic.cxx +++ b/scintilla/lexers/LexBasic.cxx @@ -37,10 +37,9 @@ #include "CharacterSet.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /* Bits: * 1 - whitespace @@ -226,7 +225,7 @@ struct OptionSetBasic : public OptionSet { } }; -class LexerBasic : public ILexer { +class LexerBasic : public DefaultLexer { char comment_char; int (*CheckFoldPoint)(char const *, int &); WordList keywordlists[4]; diff --git a/scintilla/lexers/LexBatch.cxx b/scintilla/lexers/LexBatch.cxx index 377b2cbf..db7e3768 100644 --- a/scintilla/lexers/LexBatch.cxx +++ b/scintilla/lexers/LexBatch.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static bool Is0To9(char ch) { return (ch >= '0') && (ch <= '9'); diff --git a/scintilla/lexers/LexCOBOL.cxx b/scintilla/lexers/LexCOBOL.cxx index 3150e333..f0374824 100644 --- a/scintilla/lexers/LexCOBOL.cxx +++ b/scintilla/lexers/LexCOBOL.cxx @@ -26,9 +26,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif #define IN_DIVISION 0x01 #define IN_DECLARATIVES 0x02 diff --git a/scintilla/lexers/LexCPP.cxx b/scintilla/lexers/LexCPP.cxx index 238856b1..d6f6f63d 100644 --- a/scintilla/lexers/LexCPP.cxx +++ b/scintilla/lexers/LexCPP.cxx @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,7 @@ #include "Scintilla.h" #include "SciLexer.h" +#include "StringCopy.h" #include "WordList.h" #include "LexAccessor.h" #include "Accessor.h" @@ -32,14 +34,12 @@ #include "SparseState.h" #include "SubStyles.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif namespace { // Use an unnamed namespace to protect the functions and classes from name conflicts -bool IsSpaceEquiv(int state) { +bool IsSpaceEquiv(int state) noexcept { return (state <= SCE_C_COMMENTDOC) || // including SCE_C_DEFAULT, SCE_C_COMMENT, SCE_C_COMMENTLINE (state == SCE_C_COMMENTLINEDOC) || (state == SCE_C_COMMENTDOCKEYWORD) || @@ -53,8 +53,8 @@ bool IsSpaceEquiv(int state) { // a = b+++/ptn/... // Putting a space between the '++' post-inc operator and the '+' binary op // fixes this, and is highly recommended for readability anyway. -bool FollowsPostfixOperator(StyleContext &sc, LexAccessor &styler) { - Sci_Position pos = static_cast(sc.currentPos); +bool FollowsPostfixOperator(const StyleContext &sc, LexAccessor &styler) { + Sci_Position pos = sc.currentPos; while (--pos > 0) { const char ch = styler[pos]; if (ch == '+' || ch == '-') { @@ -64,10 +64,10 @@ bool FollowsPostfixOperator(StyleContext &sc, LexAccessor &styler) { return false; } -bool followsReturnKeyword(StyleContext &sc, LexAccessor &styler) { +bool followsReturnKeyword(const StyleContext &sc, LexAccessor &styler) { // Don't look at styles, so no need to flush. - Sci_Position pos = static_cast(sc.currentPos); - Sci_Position currentLine = styler.GetLine(pos); + Sci_Position pos = sc.currentPos; + const Sci_Position currentLine = styler.GetLine(pos); const Sci_Position lineStartPos = styler.LineStart(currentLine); while (--pos > lineStartPos) { const char ch = styler.SafeGetCharAt(pos); @@ -86,11 +86,11 @@ bool followsReturnKeyword(StyleContext &sc, LexAccessor &styler) { return !*s; } -bool IsSpaceOrTab(int ch) { +bool IsSpaceOrTab(int ch) noexcept { return ch == ' ' || ch == '\t'; } -bool OnlySpaceOrTab(const std::string &s) { +bool OnlySpaceOrTab(const std::string &s) noexcept { for (const char ch : s) { if (!IsSpaceOrTab(ch)) return false; @@ -102,7 +102,7 @@ std::vector StringSplit(const std::string &text, int separator) { std::vector vs(text.empty() ? 0 : 1); for (const char ch : text) { if (ch == separator) { - vs.push_back(std::string()); + vs.emplace_back(); } else { vs.back() += ch; } @@ -144,8 +144,8 @@ void highlightTaskMarker(StyleContext &sc, LexAccessor &styler, int activity, const WordList &markerList, bool caseSensitive){ if ((isoperator(sc.chPrev) || IsASpace(sc.chPrev)) && markerList.Length()) { const int lengthMarker = 50; - char marker[lengthMarker+1]; - Sci_Position currPos = static_cast(sc.currentPos); + char marker[lengthMarker+1] = ""; + const Sci_Position currPos = static_cast(sc.currentPos); int i = 0; while (i < lengthMarker) { const char ch = styler.SafeGetCharAt(currPos + i); @@ -155,7 +155,7 @@ void highlightTaskMarker(StyleContext &sc, LexAccessor &styler, if (caseSensitive) marker[i] = ch; else - marker[i] = static_cast(tolower(ch)); + marker[i] = MakeLowerCase(ch); i++; } marker[i] = '\0'; @@ -216,7 +216,7 @@ std::string GetRestOfLine(LexAccessor &styler, Sci_Position start, bool allowSpa return restOfLine; } -bool IsStreamCommentStyle(int style) { +bool IsStreamCommentStyle(int style) noexcept { return style == SCE_C_COMMENT || style == SCE_C_COMMENTDOC || style == SCE_C_COMMENTDOCKEYWORD || @@ -238,22 +238,22 @@ class LinePPState { int state; int ifTaken; int level; - bool ValidLevel() const { + bool ValidLevel() const noexcept { return level >= 0 && level < 32; } - int maskLevel() const { + int maskLevel() const noexcept { return 1 << level; } public: LinePPState() : state(0), ifTaken(0), level(-1) { } - bool IsInactive() const { + bool IsInactive() const noexcept { return state != 0; } - bool CurrentIfTaken() const { + bool CurrentIfTaken() const noexcept { return (ifTaken & maskLevel()) != 0; } - void StartSection(bool on) { + void StartSection(bool on) noexcept { level++; if (ValidLevel()) { if (on) { @@ -265,14 +265,14 @@ public: } } } - void EndSection() { + void EndSection() noexcept { if (ValidLevel()) { state &= ~maskLevel(); ifTaken &= ~maskLevel(); } level--; } - void InvertCurrentLevel() { + void InvertCurrentLevel() noexcept { if (ValidLevel()) { state ^= maskLevel(); ifTaken |= maskLevel(); @@ -413,7 +413,7 @@ struct OptionSetCPP : public OptionSet { DefineProperty("fold.cpp.explicit.anywhere", &OptionsCPP::foldExplicitAnywhere, "Set this property to 1 to enable explicit fold points anywhere, not just in line comments."); - + DefineProperty("fold.cpp.preprocessor.at.else", &OptionsCPP::foldPreprocessorAtElse, "This option enables folding on a preprocessor #else or #endif line of an #if statement."); @@ -432,9 +432,41 @@ struct OptionSetCPP : public OptionSet { const char styleSubable[] = {SCE_C_IDENTIFIER, SCE_C_COMMENTDOCKEYWORD, 0}; +LexicalClass lexicalClasses[] = { + // Lexer Cpp SCLEX_CPP SCE_C_: + 0, "SCE_C_DEFAULT", "default", "White space", + 1, "SCE_C_COMMENT", "comment", "Comment: /* */.", + 2, "SCE_C_COMMENTLINE", "comment line", "Line Comment: //.", + 3, "SCE_C_COMMENTDOC", "comment documentation", "Doc comment: block comments beginning with /** or /*!", + 4, "SCE_C_NUMBER", "literal numeric", "Number", + 5, "SCE_C_WORD", "keyword", "Keyword", + 6, "SCE_C_STRING", "literal string", "Double quoted string", + 7, "SCE_C_CHARACTER", "literal string character", "Single quoted string", + 8, "SCE_C_UUID", "literal uuid", "UUIDs (only in IDL)", + 9, "SCE_C_PREPROCESSOR", "preprocessor", "Preprocessor", + 10, "SCE_C_OPERATOR", "operator", "Operators", + 11, "SCE_C_IDENTIFIER", "identifier", "Identifiers", + 12, "SCE_C_STRINGEOL", "error literal string", "End of line where string is not closed", + 13, "SCE_C_VERBATIM", "literal string multiline raw", "Verbatim strings for C#", + 14, "SCE_C_REGEX", "literal regex", "Regular expressions for JavaScript", + 15, "SCE_C_COMMENTLINEDOC", "comment documentation line", "Doc Comment Line: line comments beginning with /// or //!.", + 16, "SCE_C_WORD2", "identifier", "Keywords2", + 17, "SCE_C_COMMENTDOCKEYWORD", "comment documentation keyword", "Comment keyword", + 18, "SCE_C_COMMENTDOCKEYWORDERROR", "error comment documentation keyword", "Comment keyword error", + 19, "SCE_C_GLOBALCLASS", "identifier", "Global class", + 20, "SCE_C_STRINGRAW", "literal string multiline raw", "Raw strings for C++0x", + 21, "SCE_C_TRIPLEVERBATIM", "literal string multiline raw", "Triple-quoted strings for Vala", + 22, "SCE_C_HASHQUOTEDSTRING", "literal string", "Hash-quoted strings for Pike", + 23, "SCE_C_PREPROCESSORCOMMENT", "comment preprocessor", "Preprocessor stream comment", + 24, "SCE_C_PREPROCESSORCOMMENTDOC", "comment preprocessor documentation", "Preprocessor stream doc comment", + 25, "SCE_C_USERLITERAL", "literal", "User defined literals", + 26, "SCE_C_TASKMARKER", "comment taskmarker", "Task Marker", + 27, "SCE_C_ESCAPESEQUENCE", "literal string escapesequence", "Escape sequence", +}; + } -class LexerCPP : public ILexerWithSubStyles { +class LexerCPP : public ILexerWithMetaData { bool caseSensitive; CharacterSet setWord; CharacterSet setNegationOp; @@ -460,7 +492,7 @@ class LexerCPP : public ILexerWithSubStyles { arguments.clear(); return *this; } - bool IsMacro() const { + bool IsMacro() const noexcept { return !arguments.empty(); } }; @@ -473,6 +505,7 @@ class LexerCPP : public ILexerWithSubStyles { enum { activeFlag = 0x40 }; enum { ssIdentifier, ssDocKeyword }; SubStyles subStyles; + std::string returnBuffer; public: explicit LexerCPP(bool caseSensitive_) : caseSensitive(caseSensitive_), @@ -489,7 +522,7 @@ public: delete this; } int SCI_METHOD Version() const override { - return lvSubStyles; + return lvMetaData; } const char * SCI_METHOD PropertyNames() override { return osCPP.PropertyNames(); @@ -532,7 +565,7 @@ public: } int SCI_METHOD PrimaryStyleFromStyle(int style) override { return MaskActive(style); - } + } void SCI_METHOD FreeSubStyles() override { subStyles.Free(); } @@ -545,6 +578,59 @@ public: const char * SCI_METHOD GetSubStyleBases() override { return styleSubable; } + int SCI_METHOD NamedStyles() override { + return std::max(subStyles.LastAllocated() + 1, + static_cast(ELEMENTS(lexicalClasses))) + + activeFlag; + } + const char * SCI_METHOD NameOfStyle(int style) override { + if (style >= NamedStyles()) + return ""; + if (style < static_cast(ELEMENTS(lexicalClasses))) + return lexicalClasses[style].name; + // TODO: inactive and substyles + return ""; + } + const char * SCI_METHOD TagsOfStyle(int style) override { + if (style >= NamedStyles()) + return "Excess"; + returnBuffer.clear(); + const int firstSubStyle = subStyles.FirstAllocated(); + if (firstSubStyle >= 0) { + const int lastSubStyle = subStyles.LastAllocated(); + if (((style >= firstSubStyle) && (style <= (lastSubStyle))) || + ((style >= firstSubStyle + activeFlag) && (style <= (lastSubStyle + activeFlag)))) { + int styleActive = style; + if (style > lastSubStyle) { + returnBuffer = "inactive "; + styleActive -= activeFlag; + } + const int styleMain = StyleFromSubStyle(styleActive); + returnBuffer += lexicalClasses[styleMain].tags; + return returnBuffer.c_str(); + } + } + if (style < static_cast(ELEMENTS(lexicalClasses))) + return lexicalClasses[style].tags; + if (style >= activeFlag) { + returnBuffer = "inactive "; + const int styleActive = style - activeFlag; + if (styleActive < static_cast(ELEMENTS(lexicalClasses))) + returnBuffer += lexicalClasses[styleActive].tags; + else + returnBuffer = ""; + return returnBuffer.c_str(); + } + return ""; + } + const char * SCI_METHOD DescriptionOfStyle(int style) override { + if (style >= NamedStyles()) + return ""; + if (style < static_cast(ELEMENTS(lexicalClasses))) + return lexicalClasses[style].description; + // TODO: inactive and substyles + return ""; + } static ILexer *LexerFactoryCPP() { return new LexerCPP(true); @@ -552,7 +638,7 @@ public: static ILexer *LexerFactoryCPPInsensitive() { return new LexerCPP(false); } - static int MaskActive(int style) { + static int MaskActive(int style) noexcept { return style & ~activeFlag; } void EvaluateTokens(std::vector &tokens, const SymbolTable &preprocessorDefinitions); @@ -611,8 +697,8 @@ Sci_Position SCI_METHOD LexerCPP::WordListSet(int n, const char *wl) { if (cpEquals) { std::string name(cpDefinition, cpEquals - cpDefinition); std::string val(cpEquals+1); - size_t bracket = name.find('('); - size_t bracketEnd = name.find(')'); + const size_t bracket = name.find('('); + const size_t bracketEnd = name.find(')'); if ((bracket != std::string::npos) && (bracketEnd != std::string::npos)) { // Macro std::string args = name.substr(bracket + 1, bracketEnd - bracket - 1); @@ -633,15 +719,6 @@ Sci_Position SCI_METHOD LexerCPP::WordListSet(int n, const char *wl) { return firstModification; } -// Functor used to truncate history -struct After { - Sci_Position line; - explicit After(Sci_Position line_) : line(line_) {} - bool operator()(const PPDefinition &p) const { - return p.line > line; - } -}; - void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) { LexAccessor styler(pAccess); @@ -675,7 +752,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i (MaskActive(initStyle) == SCE_C_COMMENTLINEDOC)) { // Set continuationLine if last character of previous line is '\' if (lineCurrent > 0) { - Sci_Position endLinePrevious = styler.LineEnd(lineCurrent - 1); + const Sci_Position endLinePrevious = styler.LineEnd(lineCurrent - 1); if (endLinePrevious > 0) { continuationLine = styler.SafeGetCharAt(endLinePrevious-1) == '\\'; } @@ -702,7 +779,8 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i if (!options.updatePreprocessor) ppDefineHistory.clear(); - std::vector::iterator itInvalid = std::find_if(ppDefineHistory.begin(), ppDefineHistory.end(), After(lineCurrent-1)); + std::vector::iterator itInvalid = std::find_if(ppDefineHistory.begin(), ppDefineHistory.end(), + [lineCurrent](const PPDefinition &p) { return p.line >= lineCurrent; }); if (itInvalid != ppDefineHistory.end()) { ppDefineHistory.erase(itInvalid, ppDefineHistory.end()); definitionsChanged = true; @@ -1060,7 +1138,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i } break; case SCE_C_TRIPLEVERBATIM: - if (sc.Match("\"\"\"")) { + if (sc.Match(R"(""")")) { while (sc.Match('"')) { sc.Forward(); } @@ -1091,7 +1169,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i if (sc.Match('@', '\"')) { sc.SetState(SCE_C_VERBATIM|activitySet); sc.Forward(); - } else if (options.triplequotedStrings && sc.Match("\"\"\"")) { + } else if (options.triplequotedStrings && sc.Match(R"(""")")) { sc.SetState(SCE_C_TRIPLEVERBATIM|activitySet); sc.Forward(2); } else if (options.hashquotedStrings && sc.Match('#', '\"')) { @@ -1141,7 +1219,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i sc.SetState(SCE_C_STRINGRAW|activitySet); rawStringTerminator = ")"; for (Sci_Position termPos = sc.currentPos + 1;; termPos++) { - char chTerminator = styler.SafeGetCharAt(termPos, '('); + const char chTerminator = styler.SafeGetCharAt(termPos, '('); if (chTerminator == '(') break; rawStringTerminator += chTerminator; @@ -1172,14 +1250,14 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i } else { if (options.trackPreprocessor) { if (sc.Match("ifdef") || sc.Match("ifndef")) { - bool isIfDef = sc.Match("ifdef"); - int i = isIfDef ? 5 : 6; - std::string restOfLine = GetRestOfLine(styler, sc.currentPos + i + 1, false); + const bool isIfDef = sc.Match("ifdef"); + const int startRest = isIfDef ? 5 : 6; + std::string restOfLine = GetRestOfLine(styler, sc.currentPos + startRest + 1, false); bool foundDef = preprocessorDefinitions.find(restOfLine) != preprocessorDefinitions.end(); preproc.StartSection(isIfDef == foundDef); } else if (sc.Match("if")) { std::string restOfLine = GetRestOfLine(styler, sc.currentPos + 2, true); - bool ifGood = EvaluateExpression(restOfLine, preprocessorDefinitions); + const bool ifGood = EvaluateExpression(restOfLine, preprocessorDefinitions); preproc.StartSection(ifGood); } else if (sc.Match("else")) { if (!preproc.CurrentIfTaken()) { @@ -1246,6 +1324,8 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i while ((startValue < restOfLine.length()) && IsSpaceOrTab(restOfLine[startValue])) startValue++; std::string value = restOfLine.substr(startValue); + if (OnlySpaceOrTab(value)) + value = "1"; // No value defaults to 1 preprocessorDefinitions[key] = value; ppDefineHistory.push_back(PPDefinition(lineCurrent, key, value)); definitionsChanged = true; @@ -1354,7 +1434,7 @@ void SCI_METHOD LexerCPP::Fold(Sci_PositionU startPos, Sci_Position length, int } else if (styler.Match(j, "end")) { levelNext--; } - + if (options.foldPreprocessorAtElse && (styler.Match(j, "else") || styler.Match(j, "elif"))) { levelMinCurrent--; } @@ -1433,6 +1513,7 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl if (it != preprocessorDefinitions.end()) { val = "1"; } + tokens.erase(tokens.begin() + i + 1, tokens.begin() + i + 2); } tokens[i] = val; } else { @@ -1495,8 +1576,8 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl tokens.insert(tokens.begin() + i, macroTokens.begin(), macroTokens.end()); } } else { - // Identifier not found - tokens.erase(tokens.begin() + i); + // Identifier not found and value defaults to zero + tokens[i] = "0"; } } else { i++; diff --git a/scintilla/lexers/LexCSS.cxx b/scintilla/lexers/LexCSS.cxx index 19345af5..c1a86f53 100644 --- a/scintilla/lexers/LexCSS.cxx +++ b/scintilla/lexers/LexCSS.cxx @@ -1,7 +1,8 @@ // Scintilla source code edit control +// Encoding: UTF-8 /** @file LexCSS.cxx ** Lexer for Cascading Style Sheets - ** Written by Jakub Vrána + ** Written by Jakub Vrána ** Improved by Philippe Lhoste (CSS2) ** Improved by Ross McKay (SCSS mode; see http://sass-lang.com/ ) **/ @@ -31,9 +32,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const unsigned int ch) { @@ -347,6 +346,7 @@ static void ColouriseCssDoc(Sci_PositionU startPos, Sci_Position length, int ini case SCE_CSS_DEFAULT: if (isLessDocument) // give priority to pseudo elements break; + // Falls through. case SCE_CSS_VALUE: lastStateVar = sc.state; sc.SetState(SCE_CSS_VARIABLE); diff --git a/scintilla/lexers/LexCaml.cxx b/scintilla/lexers/LexCaml.cxx index df878154..1339b5dc 100644 --- a/scintilla/lexers/LexCaml.cxx +++ b/scintilla/lexers/LexCaml.cxx @@ -37,6 +37,10 @@ #include "CharacterSet.h" #include "LexerModule.h" +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wcomma" +#endif + // Since the Microsoft __iscsym[f] funcs are not ANSI... inline int iscaml(int c) {return isalnum(c) || c == '_';} inline int iscamlf(int c) {return isalpha(c) || c == '_';} @@ -46,9 +50,7 @@ static const int baseT[24] = { 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0,16 /* M - X */ }; -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif #ifdef BUILD_AS_EXTERNAL_LEXER /* @@ -368,6 +370,7 @@ void ColouriseCamlDoc( break; }/* else // fall through for SML char literal (handle like string) */ + // Falls through. case SCE_CAML_STRING: // [try to] interpret as [additional] [SML char/] string literal char diff --git a/scintilla/lexers/LexCmake.cxx b/scintilla/lexers/LexCmake.cxx index 1cbca361..b8fe1549 100644 --- a/scintilla/lexers/LexCmake.cxx +++ b/scintilla/lexers/LexCmake.cxx @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static bool isCmakeNumber(char ch) { diff --git a/scintilla/lexers/LexCoffeeScript.cxx b/scintilla/lexers/LexCoffeeScript.cxx index 63ee172e..a0016233 100644 --- a/scintilla/lexers/LexCoffeeScript.cxx +++ b/scintilla/lexers/LexCoffeeScript.cxx @@ -14,7 +14,8 @@ #include #include -#include "Platform.h" +#include + #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" @@ -26,9 +27,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static bool IsSpaceEquiv(int state) { return (state == SCE_COFFEESCRIPT_DEFAULT @@ -427,7 +426,7 @@ static void FoldCoffeeScriptDoc(Sci_PositionU startPos, Sci_Position length, int } const int levelAfterComments = indentNext & SC_FOLDLEVELNUMBERMASK; - const int levelBeforeComments = Platform::Maximum(indentCurrentLevel,levelAfterComments); + const int levelBeforeComments = std::max(indentCurrentLevel,levelAfterComments); // Now set all the indent levels on the lines we skipped // Do this from end to start. Once we encounter one line diff --git a/scintilla/lexers/LexD.cxx b/scintilla/lexers/LexD.cxx index ededccdf..acbf462e 100644 --- a/scintilla/lexers/LexD.cxx +++ b/scintilla/lexers/LexD.cxx @@ -27,10 +27,9 @@ #include "CharacterSet.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /* Nested comments require keeping the value of the nesting level for every position in the document. But since scintilla always styles line by line, @@ -145,7 +144,7 @@ struct OptionSetD : public OptionSet { } }; -class LexerD : public ILexer { +class LexerD : public DefaultLexer { bool caseSensitive; WordList keywords; WordList keywords2; diff --git a/scintilla/lexers/LexDiff.cxx b/scintilla/lexers/LexDiff.cxx index 9512550c..dd008c5c 100644 --- a/scintilla/lexers/LexDiff.cxx +++ b/scintilla/lexers/LexDiff.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool AtEOL(Accessor &styler, Sci_PositionU i) { return (styler[i] == '\n') || @@ -80,6 +78,14 @@ static void ColouriseDiffLine(char *lineBuffer, Sci_Position endLine, Accessor & styler.ColourTo(endLine, SCE_DIFF_POSITION); } else if (lineBuffer[0] >= '0' && lineBuffer[0] <= '9') { styler.ColourTo(endLine, SCE_DIFF_POSITION); + } else if (0 == strncmp(lineBuffer, "++", 2)) { + styler.ColourTo(endLine, SCE_DIFF_PATCH_ADD); + } else if (0 == strncmp(lineBuffer, "+-", 2)) { + styler.ColourTo(endLine, SCE_DIFF_PATCH_DELETE); + } else if (0 == strncmp(lineBuffer, "-+", 2)) { + styler.ColourTo(endLine, SCE_DIFF_REMOVED_PATCH_ADD); + } else if (0 == strncmp(lineBuffer, "--", 2)) { + styler.ColourTo(endLine, SCE_DIFF_REMOVED_PATCH_DELETE); } else if (lineBuffer[0] == '-' || lineBuffer[0] == '<') { styler.ColourTo(endLine, SCE_DIFF_DELETED); } else if (lineBuffer[0] == '+' || lineBuffer[0] == '>') { diff --git a/scintilla/lexers/LexErlang.cxx b/scintilla/lexers/LexErlang.cxx index 3d3c1e89..4ca5962c 100644 --- a/scintilla/lexers/LexErlang.cxx +++ b/scintilla/lexers/LexErlang.cxx @@ -1,11 +1,12 @@ // Scintilla source code edit control +// Encoding: UTF-8 // Copyright 1998-2001 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. /** @file LexErlang.cxx ** Lexer for Erlang. ** Enhanced by Etienne 'Lenain' Girondel (lenaing@gmail.com) ** Originally wrote by Peter-Henry Mander, - ** based on Matlab lexer by José Fonseca. + ** based on Matlab lexer by José Fonseca. **/ #include @@ -26,9 +27,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static int is_radix(int radix, int ch) { int digit; @@ -116,6 +115,7 @@ static void ColouriseErlangDoc(Sci_PositionU startPos, Sci_Position length, int } } // V--- Falling through! + // Falls through. case COMMENT_FUNCTION : { if (sc.ch != '%') { to_late_to_comment = true; @@ -128,6 +128,7 @@ static void ColouriseErlangDoc(Sci_PositionU startPos, Sci_Position length, int } } // V--- Falling through! + // Falls through. case COMMENT_MODULE : { if (parse_state != COMMENT) { // Search for comment documentation diff --git a/scintilla/lexers/LexForth.cxx b/scintilla/lexers/LexForth.cxx index 63d3f4f6..80842097 100644 --- a/scintilla/lexers/LexForth.cxx +++ b/scintilla/lexers/LexForth.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordStart(int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.'); diff --git a/scintilla/lexers/LexFortran.cxx b/scintilla/lexers/LexFortran.cxx index 495b0021..3adee583 100644 --- a/scintilla/lexers/LexFortran.cxx +++ b/scintilla/lexers/LexFortran.cxx @@ -25,9 +25,7 @@ #include "LexerModule.h" /***************************************/ -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /***********************************************/ static inline bool IsAWordChar(const int ch) { @@ -257,7 +255,7 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int } /***************************************/ static void CheckLevelCommentLine(const unsigned int nComL, - int nComColB[], int nComColF[], int &nComCur, + Sci_Position nComColB[], Sci_Position nComColF[], Sci_Position &nComCur, bool comLineB[], bool comLineF[], bool &comLineCur, int &levelDeltaNext) { levelDeltaNext = 0; @@ -362,7 +360,7 @@ static void CheckBackComLines(Accessor &styler, bool isFixFormat, Sci_Position l } Sci_Position lineC = lineCurrent - nComL + 1; - unsigned int iStart; + Sci_PositionU iStart; if (lineC <= 0) { lineC = 0; iStart = nComL - lineCurrent; @@ -373,11 +371,11 @@ static void CheckBackComLines(Accessor &styler, bool isFixFormat, Sci_Position l bool levChanged = false; int lev = styler.LevelAt(lineC) & SC_FOLDLEVELNUMBERMASK; - for (unsigned int i=iStart; i<=nComL; i++) { + for (Sci_PositionU i=iStart; i<=nComL; i++) { if (comL[i] && (!comL[i-1] || nComCol[i] != nComCol[i-1])) { bool increase = true; - unsigned int until = i + nComL; - for (unsigned int j=i+1; j<=until; j++) { + Sci_PositionU until = i + nComL; + for (Sci_PositionU j=i+1; j<=until; j++) { if (!comL[j] || nComCol[j] != nComCol[i]) { increase = false; break; @@ -445,7 +443,7 @@ static int classifyFoldPointFortran(const char* s, const char* prevWord, const c || strcmp(s, "endsubroutine") == 0 || strcmp(s, "endtype") == 0 || strcmp(s, "endwhere") == 0 || strcmp(s, "endcritical") == 0 || (strcmp(prevWord, "module") == 0 && strcmp(s, "procedure") == 0) // Take care of the "module procedure" statement - || strcmp(s, "endsubmodule") == 0) { + || strcmp(s, "endsubmodule") == 0 || strcmp(s, "endteam") == 0) { lev = -1; } else if (strcmp(prevWord, "end") == 0 && strcmp(s, "if") == 0){ // end if lev = 0; @@ -454,6 +452,8 @@ static int classifyFoldPointFortran(const char* s, const char* prevWord, const c } else if ((strcmp(prevWord, "end") == 0 && strcmp(s, "procedure") == 0) || strcmp(s, "endprocedure") == 0) { lev = 1; // level back to 0, because no folding support for "module procedure" in submodule + } else if (strcmp(prevWord, "change") == 0 && strcmp(s, "team") == 0){ // change team + lev = 1; } return lev; } diff --git a/scintilla/lexers/LexHTML.cxx b/scintilla/lexers/LexHTML.cxx index 028c5ec9..65011222 100644 --- a/scintilla/lexers/LexHTML.cxx +++ b/scintilla/lexers/LexHTML.cxx @@ -11,11 +11,13 @@ #include #include #include +#include +#include +#include #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" - #include "StringCopy.h" #include "WordList.h" #include "LexAccessor.h" @@ -23,10 +25,12 @@ #include "StyleContext.h" #include "CharacterSet.h" #include "LexerModule.h" +#include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif + +namespace { #define SCE_HA_JS (SCE_HJA_START - SCE_HJ_START) #define SCE_HA_VBS (SCE_HBA_START - SCE_HB_START) @@ -35,11 +39,11 @@ using namespace Scintilla; enum script_type { eScriptNone = 0, eScriptJS, eScriptVBS, eScriptPython, eScriptPHP, eScriptXML, eScriptSGML, eScriptSGMLblock, eScriptComment }; enum script_mode { eHtml = 0, eNonHtmlScript, eNonHtmlPreProc, eNonHtmlScriptPreProc }; -static inline bool IsAWordChar(const int ch) { +inline bool IsAWordChar(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_'); } -static inline bool IsAWordStart(const int ch) { +inline bool IsAWordStart(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '_'); } @@ -57,31 +61,38 @@ inline bool IsOperator(int ch) { return false; } -static void GetTextSegment(Accessor &styler, Sci_PositionU start, Sci_PositionU end, char *s, size_t len) { +void GetTextSegment(Accessor &styler, Sci_PositionU start, Sci_PositionU end, char *s, size_t len) { Sci_PositionU i = 0; for (; (i < end - start + 1) && (i < len-1); i++) { - s[i] = static_cast(MakeLowerCase(styler[start + i])); + s[i] = MakeLowerCase(styler[start + i]); } s[i] = '\0'; } -static const char *GetNextWord(Accessor &styler, Sci_PositionU start, char *s, size_t sLen) { - +std::string GetStringSegment(Accessor &styler, Sci_PositionU start, Sci_PositionU end) { + std::string s; Sci_PositionU i = 0; - for (; i < sLen-1; i++) { - char ch = static_cast(styler.SafeGetCharAt(start + i)); + for (; (i < end - start + 1); i++) { + s.push_back(MakeLowerCase(styler[start + i])); + } + return s; +} + +std::string GetNextWord(Accessor &styler, Sci_PositionU start) { + std::string ret; + Sci_PositionU i = 0; + for (; i < 200; i++) { // Put an upper limit to bound time taken for unexpected text. + const char ch = styler.SafeGetCharAt(start + i); if ((i == 0) && !IsAWordStart(ch)) break; if ((i > 0) && !IsAWordChar(ch)) break; - s[i] = ch; + ret.push_back(ch); } - s[i] = '\0'; - - return s; + return ret; } -static script_type segIsScriptingIndicator(Accessor &styler, Sci_PositionU start, Sci_PositionU end, script_type prevValue) { +script_type segIsScriptingIndicator(Accessor &styler, Sci_PositionU start, Sci_PositionU end, script_type prevValue) { char s[100]; GetTextSegment(styler, start, end, s, sizeof(s)); //Platform::DebugPrintf("Scripting indicator [%s]\n", s); @@ -110,18 +121,16 @@ static script_type segIsScriptingIndicator(Accessor &styler, Sci_PositionU start return prevValue; } -static int PrintScriptingIndicatorOffset(Accessor &styler, Sci_PositionU start, Sci_PositionU end) { +int PrintScriptingIndicatorOffset(Accessor &styler, Sci_PositionU start, Sci_PositionU end) { int iResult = 0; - char s[100]; - GetTextSegment(styler, start, end, s, sizeof(s)); - if (0 == strncmp(s, "php", 3)) { + std::string s = GetStringSegment(styler, start, end); + if (0 == strncmp(s.c_str(), "php", 3)) { iResult = 3; } - return iResult; } -static script_type ScriptOfState(int state) { +script_type ScriptOfState(int state) { if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) { return eScriptPython; } else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) { @@ -139,7 +148,7 @@ static script_type ScriptOfState(int state) { } } -static int statePrintForState(int state, script_mode inScriptType) { +int statePrintForState(int state, script_mode inScriptType) { int StateToPrint = state; if (state >= SCE_HJ_START) { @@ -155,7 +164,7 @@ static int statePrintForState(int state, script_mode inScriptType) { return StateToPrint; } -static int stateForPrintState(int StateToPrint) { +int stateForPrintState(int StateToPrint) { int state; if ((StateToPrint >= SCE_HPA_START) && (StateToPrint <= SCE_HPA_IDENTIFIER)) { @@ -171,12 +180,12 @@ static int stateForPrintState(int StateToPrint) { return state; } -static inline bool IsNumber(Sci_PositionU start, Accessor &styler) { +inline bool IsNumber(Sci_PositionU start, Accessor &styler) { return IsADigit(styler[start]) || (styler[start] == '.') || (styler[start] == '-') || (styler[start] == '#'); } -static inline bool isStringState(int state) { +inline bool isStringState(int state) { bool bResult; switch (state) { @@ -207,7 +216,7 @@ static inline bool isStringState(int state) { return bResult; } -static inline bool stateAllowsTermination(int state) { +inline bool stateAllowsTermination(int state) { bool allowTermination = !isStringState(state); if (allowTermination) { switch (state) { @@ -222,7 +231,7 @@ static inline bool stateAllowsTermination(int state) { } // not really well done, since it's only comments that should lex the %> and <% -static inline bool isCommentASPState(int state) { +inline bool isCommentASPState(int state) { bool bResult; switch (state) { @@ -242,15 +251,14 @@ static inline bool isCommentASPState(int state) { return bResult; } -static void classifyAttribHTML(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler) { - bool wordIsNumber = IsNumber(start, styler); +void classifyAttribHTML(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler) { + const bool wordIsNumber = IsNumber(start, styler); char chAttr = SCE_H_ATTRIBUTEUNKNOWN; if (wordIsNumber) { chAttr = SCE_H_NUMBER; } else { - char s[100]; - GetTextSegment(styler, start, end, s, sizeof(s)); - if (keywords.InList(s)) + std::string s = GetStringSegment(styler, start, end); + if (keywords.InList(s.c_str())) chAttr = SCE_H_ATTRIBUTE; } if ((chAttr == SCE_H_ATTRIBUTEUNKNOWN) && !keywords) @@ -259,47 +267,36 @@ static void classifyAttribHTML(Sci_PositionU start, Sci_PositionU end, WordList styler.ColourTo(end, chAttr); } -static int classifyTagHTML(Sci_PositionU start, Sci_PositionU end, - WordList &keywords, Accessor &styler, bool &tagDontFold, - bool caseSensitive, bool isXml, bool allowScripts) { - char withSpace[30 + 2] = " "; - const char *s = withSpace + 1; +int classifyTagHTML(Sci_PositionU start, Sci_PositionU end, + const WordList &keywords, Accessor &styler, bool &tagDontFold, + bool caseSensitive, bool isXml, bool allowScripts, + const std::set &nonFoldingTags) { + std::string tag; // Copy after the '<' - Sci_PositionU i = 1; - for (Sci_PositionU cPos = start; cPos <= end && i < 30; cPos++) { - char ch = styler[cPos]; + for (Sci_PositionU cPos = start; cPos <= end; cPos++) { + const char ch = styler[cPos]; if ((ch != '<') && (ch != '/')) { - withSpace[i++] = caseSensitive ? ch : static_cast(MakeLowerCase(ch)); + tag.push_back(caseSensitive ? ch : MakeLowerCase(ch)); } } - - //The following is only a quick hack, to see if this whole thing would work - //we first need the tagname with a trailing space... - withSpace[i] = ' '; - withSpace[i+1] = '\0'; - // if the current language is XML, I can fold any tag // if the current language is HTML, I don't want to fold certain tags (input, meta, etc.) //...to find it in the list of no-container-tags - tagDontFold = (!isXml) && (NULL != strstr(" area base basefont br col command embed frame hr img input isindex keygen link meta param source track wbr ", withSpace)); - - //now we can remove the trailing space - withSpace[i] = '\0'; - + tagDontFold = (!isXml) && (nonFoldingTags.count(tag) > 0); // No keywords -> all are known char chAttr = SCE_H_TAGUNKNOWN; - if (s[0] == '!') { + if (!tag.empty() && (tag[0] == '!')) { chAttr = SCE_H_SGML_DEFAULT; - } else if (!keywords || keywords.InList(s)) { + } else if (!keywords || keywords.InList(tag.c_str())) { chAttr = SCE_H_TAG; } styler.ColourTo(end, chAttr); if (chAttr == SCE_H_TAG) { - if (allowScripts && 0 == strcmp(s, "script")) { + if (allowScripts && (tag == "script")) { // check to see if this is a self-closing tag by sniffing ahead bool isSelfClose = false; for (Sci_PositionU cPos = end; cPos <= end + 200; cPos++) { - char ch = styler.SafeGetCharAt(cPos, '\0'); + const char ch = styler.SafeGetCharAt(cPos, '\0'); if (ch == '\0' || ch == '>') break; else if (ch == '/' && styler.SafeGetCharAt(cPos + 1, '\0') == '>') { @@ -311,15 +308,15 @@ static int classifyTagHTML(Sci_PositionU start, Sci_PositionU end, // do not enter a script state if the tag self-closed if (!isSelfClose) chAttr = SCE_H_SCRIPT; - } else if (!isXml && 0 == strcmp(s, "comment")) { + } else if (!isXml && (tag == "comment")) { chAttr = SCE_H_COMMENT; } } return chAttr; } -static void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end, - WordList &keywords, Accessor &styler, script_mode inScriptType) { +void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end, + const WordList &keywords, Accessor &styler, script_mode inScriptType) { char s[30 + 1]; Sci_PositionU i = 0; for (; i < end - start + 1 && i < 30; i++) { @@ -328,7 +325,7 @@ static void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end, s[i] = '\0'; char chAttr = SCE_HJ_WORD; - bool wordIsNumber = IsADigit(s[0]) || ((s[0] == '.') && IsADigit(s[1])); + const bool wordIsNumber = IsADigit(s[0]) || ((s[0] == '.') && IsADigit(s[1])); if (wordIsNumber) { chAttr = SCE_HJ_NUMBER; } else if (keywords.InList(s)) { @@ -337,17 +334,16 @@ static void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end, styler.ColourTo(end, statePrintForState(chAttr, inScriptType)); } -static int classifyWordHTVB(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler, script_mode inScriptType) { +int classifyWordHTVB(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler, script_mode inScriptType) { char chAttr = SCE_HB_IDENTIFIER; - bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.'); + const bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.'); if (wordIsNumber) { chAttr = SCE_HB_NUMBER; } else { - char s[100]; - GetTextSegment(styler, start, end, s, sizeof(s)); - if (keywords.InList(s)) { + std::string s = GetStringSegment(styler, start, end); + if (keywords.InList(s.c_str())) { chAttr = SCE_HB_WORD; - if (strcmp(s, "rem") == 0) + if (s == "rem") chAttr = SCE_HB_COMMENTLINE; } } @@ -358,67 +354,60 @@ static int classifyWordHTVB(Sci_PositionU start, Sci_PositionU end, WordList &ke return SCE_HB_DEFAULT; } -static void classifyWordHTPy(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler, char *prevWord, script_mode inScriptType, bool isMako) { - bool wordIsNumber = IsADigit(styler[start]); - char s[30 + 1]; - Sci_PositionU i = 0; - for (; i < end - start + 1 && i < 30; i++) { - s[i] = styler[start + i]; +void classifyWordHTPy(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler, std::string &prevWord, script_mode inScriptType, bool isMako) { + const bool wordIsNumber = IsADigit(styler[start]); + std::string s; + for (Sci_PositionU i = 0; i < end - start + 1 && i < 30; i++) { + s.push_back(styler[start + i]); } - s[i] = '\0'; char chAttr = SCE_HP_IDENTIFIER; - if (0 == strcmp(prevWord, "class")) + if (prevWord == "class") chAttr = SCE_HP_CLASSNAME; - else if (0 == strcmp(prevWord, "def")) + else if (prevWord == "def") chAttr = SCE_HP_DEFNAME; else if (wordIsNumber) chAttr = SCE_HP_NUMBER; - else if (keywords.InList(s)) + else if (keywords.InList(s.c_str())) chAttr = SCE_HP_WORD; - else if (isMako && 0 == strcmp(s, "block")) + else if (isMako && (s == "block")) chAttr = SCE_HP_WORD; styler.ColourTo(end, statePrintForState(chAttr, inScriptType)); - strcpy(prevWord, s); + prevWord = s; } // Update the word colour to default or keyword // Called when in a PHP word -static void classifyWordHTPHP(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler) { +void classifyWordHTPHP(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler) { char chAttr = SCE_HPHP_DEFAULT; - bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.' && start+1 <= end && IsADigit(styler[start+1])); + const bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.' && start+1 <= end && IsADigit(styler[start+1])); if (wordIsNumber) { chAttr = SCE_HPHP_NUMBER; } else { - char s[100]; - GetTextSegment(styler, start, end, s, sizeof(s)); - if (keywords.InList(s)) + std::string s = GetStringSegment(styler, start, end); + if (keywords.InList(s.c_str())) chAttr = SCE_HPHP_WORD; } styler.ColourTo(end, chAttr); } -static bool isWordHSGML(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler) { - char s[30 + 1]; - Sci_PositionU i = 0; - for (; i < end - start + 1 && i < 30; i++) { - s[i] = styler[start + i]; +bool isWordHSGML(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler) { + std::string s; + for (Sci_PositionU i = 0; i < end - start + 1 && i < 30; i++) { + s.push_back(styler[start + i]); } - s[i] = '\0'; - return keywords.InList(s); + return keywords.InList(s.c_str()); } -static bool isWordCdata(Sci_PositionU start, Sci_PositionU end, Accessor &styler) { - char s[30 + 1]; - Sci_PositionU i = 0; - for (; i < end - start + 1 && i < 30; i++) { - s[i] = styler[start + i]; +bool isWordCdata(Sci_PositionU start, Sci_PositionU end, Accessor &styler) { + std::string s; + for (Sci_PositionU i = 0; i < end - start + 1 && i < 30; i++) { + s.push_back(styler[start + i]); } - s[i] = '\0'; - return (0 == strcmp(s, "[CDATA[")); + return s == "[CDATA["; } // Return the first state to reach when entering a scripting language -static int StateForScript(script_type scriptLanguage) { +int StateForScript(script_type scriptLanguage) { int Result; switch (scriptLanguage) { case eScriptVBS: @@ -446,20 +435,20 @@ static int StateForScript(script_type scriptLanguage) { return Result; } -static inline bool issgmlwordchar(int ch) { +inline bool issgmlwordchar(int ch) { return !IsASCII(ch) || (isalnum(ch) || ch == '.' || ch == '_' || ch == ':' || ch == '!' || ch == '#' || ch == '['); } -static inline bool IsPhpWordStart(int ch) { +inline bool IsPhpWordStart(int ch) { return (IsASCII(ch) && (isalpha(ch) || (ch == '_'))) || (ch >= 0x7f); } -static inline bool IsPhpWordChar(int ch) { +inline bool IsPhpWordChar(int ch) { return IsADigit(ch) || IsPhpWordStart(ch); } -static bool InTagState(int state) { +bool InTagState(int state) { return state == SCE_H_TAG || state == SCE_H_TAGUNKNOWN || state == SCE_H_SCRIPT || state == SCE_H_ATTRIBUTE || state == SCE_H_ATTRIBUTEUNKNOWN || @@ -467,52 +456,52 @@ static bool InTagState(int state) { state == SCE_H_DOUBLESTRING || state == SCE_H_SINGLESTRING; } -static bool IsCommentState(const int state) { +bool IsCommentState(const int state) { return state == SCE_H_COMMENT || state == SCE_H_SGML_COMMENT; } -static bool IsScriptCommentState(const int state) { +bool IsScriptCommentState(const int state) { return state == SCE_HJ_COMMENT || state == SCE_HJ_COMMENTLINE || state == SCE_HJA_COMMENT || state == SCE_HJA_COMMENTLINE || state == SCE_HB_COMMENTLINE || state == SCE_HBA_COMMENTLINE; } -static bool isLineEnd(int ch) { +bool isLineEnd(int ch) { return ch == '\r' || ch == '\n'; } -static bool isMakoBlockEnd(const int ch, const int chNext, const char *blockType) { - if (strlen(blockType) == 0) { +bool isMakoBlockEnd(const int ch, const int chNext, const std::string &blockType) { + if (blockType.empty()) { return ((ch == '%') && (chNext == '>')); - } else if ((0 == strcmp(blockType, "inherit")) || - (0 == strcmp(blockType, "namespace")) || - (0 == strcmp(blockType, "include")) || - (0 == strcmp(blockType, "page"))) { + } else if ((blockType == "inherit") || + (blockType == "namespace") || + (blockType == "include") || + (blockType == "page")) { return ((ch == '/') && (chNext == '>')); - } else if (0 == strcmp(blockType, "%")) { + } else if (blockType == "%") { if (ch == '/' && isLineEnd(chNext)) return true; else return isLineEnd(ch); - } else if (0 == strcmp(blockType, "{")) { + } else if (blockType == "{") { return ch == '}'; } else { return (ch == '>'); } } -static bool isDjangoBlockEnd(const int ch, const int chNext, const char *blockType) { - if (strlen(blockType) == 0) { +bool isDjangoBlockEnd(const int ch, const int chNext, const std::string &blockType) { + if (blockType.empty()) { return false; - } else if (0 == strcmp(blockType, "%")) { + } else if (blockType == "%") { return ((ch == '%') && (chNext == '}')); - } else if (0 == strcmp(blockType, "{")) { + } else if (blockType == "{") { return ((ch == '}') && (chNext == '}')); } else { return false; } } -static bool isPHPStringState(int state) { +bool isPHPStringState(int state) { return (state == SCE_HPHP_HSTRING) || (state == SCE_HPHP_SIMPLESTRING) || @@ -520,29 +509,27 @@ static bool isPHPStringState(int state) { (state == SCE_HPHP_COMPLEX_VARIABLE); } -static Sci_Position FindPhpStringDelimiter(char *phpStringDelimiter, const int phpStringDelimiterSize, Sci_Position i, const Sci_Position lengthDoc, Accessor &styler, bool &isSimpleString) { +Sci_Position FindPhpStringDelimiter(std::string &phpStringDelimiter, Sci_Position i, const Sci_Position lengthDoc, Accessor &styler, bool &isSimpleString) { Sci_Position j; const Sci_Position beginning = i - 1; bool isValidSimpleString = false; while (i < lengthDoc && (styler[i] == ' ' || styler[i] == '\t')) i++; - char ch = styler.SafeGetCharAt(i); const char chNext = styler.SafeGetCharAt(i + 1); + phpStringDelimiter.clear(); if (!IsPhpWordStart(ch)) { if (ch == '\'' && IsPhpWordStart(chNext)) { i++; ch = chNext; isSimpleString = true; } else { - phpStringDelimiter[0] = '\0'; return beginning; } } - phpStringDelimiter[0] = ch; + phpStringDelimiter.push_back(ch); i++; - for (j = i; j < lengthDoc && !isLineEnd(styler[j]); j++) { if (!IsPhpWordChar(styler[j])) { if (isSimpleString && (styler[j] == '\'') && isLineEnd(styler.SafeGetCharAt(j + 1))) { @@ -550,49 +537,403 @@ static Sci_Position FindPhpStringDelimiter(char *phpStringDelimiter, const int p j++; break; } else { - phpStringDelimiter[0] = '\0'; + phpStringDelimiter.clear(); return beginning; } } - if (j - i < phpStringDelimiterSize - 2) - phpStringDelimiter[j-i+1] = styler[j]; - else - i++; + phpStringDelimiter.push_back(styler[j]); } if (isSimpleString && !isValidSimpleString) { - phpStringDelimiter[0] = '\0'; + phpStringDelimiter.clear(); return beginning; } - phpStringDelimiter[j-i+1 - (isSimpleString ? 1 : 0)] = '\0'; return j - 1; } -static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], - Accessor &styler, bool isXml) { - WordList &keywords = *keywordlists[0]; - WordList &keywords2 = *keywordlists[1]; - WordList &keywords3 = *keywordlists[2]; - WordList &keywords4 = *keywordlists[3]; - WordList &keywords5 = *keywordlists[4]; - WordList &keywords6 = *keywordlists[5]; // SGML (DTD) keywords +// Options used for LexerHTML +struct OptionsHTML { + int aspDefaultLanguage = eScriptJS; + bool caseSensitive = false; + bool allowScripts = true; + bool isMako = false; + bool isDjango = false; + bool fold = false; + bool foldHTML = false; + bool foldHTMLPreprocessor = true; + bool foldCompact = true; + bool foldComment = false; + bool foldHeredoc = false; + OptionsHTML() noexcept { + } +}; +const char * const htmlWordListDesc[] = { + "HTML elements and attributes", + "JavaScript keywords", + "VBScript keywords", + "Python keywords", + "PHP keywords", + "SGML and DTD keywords", + 0, +}; + +const char * const phpscriptWordListDesc[] = { + "", //Unused + "", //Unused + "", //Unused + "", //Unused + "PHP keywords", + "", //Unused + 0, +}; + +struct OptionSetHTML : public OptionSet { + OptionSetHTML(bool isPHPScript_) { + + DefineProperty("asp.default.language", &OptionsHTML::aspDefaultLanguage, + "Script in ASP code is initially assumed to be in JavaScript. " + "To change this to VBScript set asp.default.language to 2. Python is 3."); + + DefineProperty("html.tags.case.sensitive", &OptionsHTML::caseSensitive, + "For XML and HTML, setting this property to 1 will make tags match in a case " + "sensitive way which is the expected behaviour for XML and XHTML."); + + DefineProperty("lexer.xml.allow.scripts", &OptionsHTML::allowScripts, + "Set to 0 to disable scripts in XML."); + + DefineProperty("lexer.html.mako", &OptionsHTML::isMako, + "Set to 1 to enable the mako template language."); + + DefineProperty("lexer.html.django", &OptionsHTML::isDjango, + "Set to 1 to enable the django template language."); + + DefineProperty("fold", &OptionsHTML::fold); + + DefineProperty("fold.html", &OptionsHTML::foldHTML, + "Folding is turned on or off for HTML and XML files with this option. " + "The fold option must also be on for folding to occur."); + + DefineProperty("fold.html.preprocessor", &OptionsHTML::foldHTMLPreprocessor, + "Folding is turned on or off for scripts embedded in HTML files with this option. " + "The default is on."); + + DefineProperty("fold.compact", &OptionsHTML::foldCompact); + + DefineProperty("fold.hypertext.comment", &OptionsHTML::foldComment, + "Allow folding for comments in scripts embedded in HTML. " + "The default is off."); + + DefineProperty("fold.hypertext.heredoc", &OptionsHTML::foldHeredoc, + "Allow folding for heredocs in scripts embedded in HTML. " + "The default is off."); + + DefineWordListSets(isPHPScript_ ? phpscriptWordListDesc : htmlWordListDesc); + } +}; + +LexicalClass lexicalClassesHTML[] = { + // Lexer HTML SCLEX_HTML SCE_H_ SCE_HJ_ SCE_HJA_ SCE_HB_ SCE_HBA_ SCE_HP_ SCE_HPHP_ SCE_HPA_: + 0, "SCE_H_DEFAULT", "default", "Text", + 1, "SCE_H_TAG", "tag", "Tags", + 2, "SCE_H_ERRORTAGUNKNOWN", "error tag", "Unknown Tags", + 3, "SCE_H_ATTRIBUTE", "attribute", "Attributes", + 4, "SCE_H_ATTRIBUTEUNKNOWN", "error attribute", "Unknown Attributes", + 5, "SCE_H_NUMBER", "literal numeric", "Numbers", + 6, "SCE_H_DOUBLESTRING", "literal string", "Double quoted strings", + 7, "SCE_H_SINGLESTRING", "literal string", "Single quoted strings", + 8, "SCE_H_OTHER", "tag operator", "Other inside tag, including space and '='", + 9, "SCE_H_COMMENT", "comment", "Comment", + 10, "SCE_H_ENTITY", "literal", "Entities", + 11, "SCE_H_TAGEND", "tag", "XML style tag ends '/>'", + 12, "SCE_H_XMLSTART", "identifier", "XML identifier start ''", + 14, "SCE_H_SCRIPT", "error", "Internal state which should never be visible", + 15, "SCE_H_ASP", "preprocessor", "ASP <% ... %>", + 16, "SCE_H_ASPAT", "preprocessor", "ASP <% ... %>", + 17, "SCE_H_CDATA", "literal", "CDATA", + 18, "SCE_H_QUESTION", "preprocessor", "PHP", + 19, "SCE_H_VALUE", "literal string", "Unquoted values", + 20, "SCE_H_XCCOMMENT", "comment", "JSP Comment <%-- ... --%>", + 21, "SCE_H_SGML_DEFAULT", "default", "SGML tags ", + 22, "SCE_H_SGML_COMMAND", "preprocessor", "SGML command", + 23, "SCE_H_SGML_1ST_PARAM", "preprocessor", "SGML 1st param", + 24, "SCE_H_SGML_DOUBLESTRING", "literal string", "SGML double string", + 25, "SCE_H_SGML_SIMPLESTRING", "literal string", "SGML single string", + 26, "SCE_H_SGML_ERROR", "error", "SGML error", + 27, "SCE_H_SGML_SPECIAL", "literal", "SGML special (#XXXX type)", + 28, "SCE_H_SGML_ENTITY", "literal", "SGML entity", + 29, "SCE_H_SGML_COMMENT", "comment", "SGML comment", + 30, "SCE_H_SGML_1ST_PARAM_COMMENT", "error comment", "SGML first parameter - lexer internal. It is an error if any text is in this style.", + 31, "SCE_H_SGML_BLOCK_DEFAULT", "default", "SGML block", + 32, "", "predefined", "", + 33, "", "predefined", "", + 34, "", "predefined", "", + 35, "", "predefined", "", + 36, "", "predefined", "", + 37, "", "predefined", "", + 38, "", "predefined", "", + 39, "", "predefined", "", + 40, "SCE_HJ_START", "client javascript default", "JS Start - allows eol filled background to not start on same line as SCRIPT tag", + 41, "SCE_HJ_DEFAULT", "client javascript default", "JS Default", + 42, "SCE_HJ_COMMENT", "client javascript comment", "JS Comment", + 43, "SCE_HJ_COMMENTLINE", "client javascript comment line", "JS Line Comment", + 44, "SCE_HJ_COMMENTDOC", "client javascript comment documentation", "JS Doc comment", + 45, "SCE_HJ_NUMBER", "client javascript literal numeric", "JS Number", + 46, "SCE_HJ_WORD", "client javascript identifier", "JS Word", + 47, "SCE_HJ_KEYWORD", "client javascript keyword", "JS Keyword", + 48, "SCE_HJ_DOUBLESTRING", "client javascript literal string", "JS Double quoted string", + 49, "SCE_HJ_SINGLESTRING", "client javascript literal string", "JS Single quoted string", + 50, "SCE_HJ_SYMBOLS", "client javascript operator", "JS Symbols", + 51, "SCE_HJ_STRINGEOL", "client javascript error literal string", "JavaScript EOL", + 52, "SCE_HJ_REGEX", "client javascript literal regex", "JavaScript RegEx", + 53, "", "unused", "", + 54, "", "unused", "", + 55, "SCE_HJA_START", "server javascript default", "JS Start - allows eol filled background to not start on same line as SCRIPT tag", + 56, "SCE_HJA_DEFAULT", "server javascript default", "JS Default", + 57, "SCE_HJA_COMMENT", "server javascript comment", "JS Comment", + 58, "SCE_HJA_COMMENTLINE", "server javascript comment line", "JS Line Comment", + 59, "SCE_HJA_COMMENTDOC", "server javascript comment documentation", "JS Doc comment", + 60, "SCE_HJA_NUMBER", "server javascript literal numeric", "JS Number", + 61, "SCE_HJA_WORD", "server javascript identifier", "JS Word", + 62, "SCE_HJA_KEYWORD", "server javascript keyword", "JS Keyword", + 63, "SCE_HJA_DOUBLESTRING", "server javascript literal string", "JS Double quoted string", + 64, "SCE_HJA_SINGLESTRING", "server javascript literal string", "JS Single quoted string", + 65, "SCE_HJA_SYMBOLS", "server javascript operator", "JS Symbols", + 66, "SCE_HJA_STRINGEOL", "server javascript error literal string", "JavaScript EOL", + 67, "SCE_HJA_REGEX", "server javascript literal regex", "JavaScript RegEx", + 68, "", "unused", "", + 69, "", "unused", "", + 70, "SCE_HB_START", "client basic default", "Start", + 71, "SCE_HB_DEFAULT", "client basic default", "Default", + 72, "SCE_HB_COMMENTLINE", "client basic comment line", "Comment", + 73, "SCE_HB_NUMBER", "client basic literal numeric", "Number", + 74, "SCE_HB_WORD", "client basic keyword", "KeyWord", + 75, "SCE_HB_STRING", "client basic literal string", "String", + 76, "SCE_HB_IDENTIFIER", "client basic identifier", "Identifier", + 77, "SCE_HB_STRINGEOL", "client basic literal string", "Unterminated string", + 78, "", "unused", "", + 79, "", "unused", "", + 80, "SCE_HBA_START", "server basic default", "Start", + 81, "SCE_HBA_DEFAULT", "server basic default", "Default", + 82, "SCE_HBA_COMMENTLINE", "server basic comment line", "Comment", + 83, "SCE_HBA_NUMBER", "server basic literal numeric", "Number", + 84, "SCE_HBA_WORD", "server basic keyword", "KeyWord", + 85, "SCE_HBA_STRING", "server basic literal string", "String", + 86, "SCE_HBA_IDENTIFIER", "server basic identifier", "Identifier", + 87, "SCE_HBA_STRINGEOL", "server basic literal string", "Unterminated string", + 88, "", "unused", "", + 89, "", "unused", "", + 90, "SCE_HP_START", "client python default", "Embedded Python", + 91, "SCE_HP_DEFAULT", "client python default", "Embedded Python", + 92, "SCE_HP_COMMENTLINE", "client python comment line", "Comment", + 93, "SCE_HP_NUMBER", "client python literal numeric", "Number", + 94, "SCE_HP_STRING", "client python literal string", "String", + 95, "SCE_HP_CHARACTER", "client python literal string character", "Single quoted string", + 96, "SCE_HP_WORD", "client python keyword", "Keyword", + 97, "SCE_HP_TRIPLE", "client python literal string", "Triple quotes", + 98, "SCE_HP_TRIPLEDOUBLE", "client python literal string", "Triple double quotes", + 99, "SCE_HP_CLASSNAME", "client python identifier", "Class name definition", + 100, "SCE_HP_DEFNAME", "client python identifier", "Function or method name definition", + 101, "SCE_HP_OPERATOR", "client python operator", "Operators", + 102, "SCE_HP_IDENTIFIER", "client python identifier", "Identifiers", + 103, "", "unused", "", + 104, "SCE_HPHP_COMPLEX_VARIABLE", "server php identifier", "PHP complex variable", + 105, "SCE_HPA_START", "server python default", "ASP Python", + 106, "SCE_HPA_DEFAULT", "server python default", "ASP Python", + 107, "SCE_HPA_COMMENTLINE", "server python comment line", "Comment", + 108, "SCE_HPA_NUMBER", "server python literal numeric", "Number", + 109, "SCE_HPA_STRING", "server python literal string", "String", + 110, "SCE_HPA_CHARACTER", "server python literal string character", "Single quoted string", + 111, "SCE_HPA_WORD", "server python keyword", "Keyword", + 112, "SCE_HPA_TRIPLE", "server python literal string", "Triple quotes", + 113, "SCE_HPA_TRIPLEDOUBLE", "server python literal string", "Triple double quotes", + 114, "SCE_HPA_CLASSNAME", "server python identifier", "Class name definition", + 115, "SCE_HPA_DEFNAME", "server python identifier", "Function or method name definition", + 116, "SCE_HPA_OPERATOR", "server python operator", "Operators", + 117, "SCE_HPA_IDENTIFIER", "server python identifier", "Identifiers", + 118, "SCE_HPHP_DEFAULT", "server php default", "Default", + 119, "SCE_HPHP_HSTRING", "server php literal string", "Double quoted String", + 120, "SCE_HPHP_SIMPLESTRING", "server php literal string", "Single quoted string", + 121, "SCE_HPHP_WORD", "server php keyword", "Keyword", + 122, "SCE_HPHP_NUMBER", "server php literal numeric", "Number", + 123, "SCE_HPHP_VARIABLE", "server php identifier", "Variable", + 124, "SCE_HPHP_COMMENT", "server php comment", "Comment", + 125, "SCE_HPHP_COMMENTLINE", "server php comment line", "One line comment", + 126, "SCE_HPHP_HSTRING_VARIABLE", "server php literal string identifier", "PHP variable in double quoted string", + 127, "SCE_HPHP_OPERATOR", "server php operator", "PHP operator", +}; + +LexicalClass lexicalClassesXML[] = { + // Lexer.Secondary XML SCLEX_XML SCE_H_: + 0, "SCE_H_DEFAULT", "default", "Default", + 1, "SCE_H_TAG", "tag", "Tags", + 2, "SCE_H_TAGUNKNOWN", "error tag", "Unknown Tags", + 3, "SCE_H_ATTRIBUTE", "attribute", "Attributes", + 4, "SCE_H_ERRORATTRIBUTEUNKNOWN", "error attribute", "Unknown Attributes", + 5, "SCE_H_NUMBER", "literal numeric", "Numbers", + 6, "SCE_H_DOUBLESTRING", "literal string", "Double quoted strings", + 7, "SCE_H_SINGLESTRING", "literal string", "Single quoted strings", + 8, "SCE_H_OTHER", "tag operator", "Other inside tag, including space and '='", + 9, "SCE_H_COMMENT", "comment", "Comment", + 10, "SCE_H_ENTITY", "literal", "Entities", + 11, "SCE_H_TAGEND", "tag", "XML style tag ends '/>'", + 12, "SCE_H_XMLSTART", "identifier", "XML identifier start ''", + 14, "", "unused", "", + 15, "", "unused", "", + 16, "", "unused", "", + 17, "SCE_H_CDATA", "literal", "CDATA", + 18, "SCE_H_QUESTION", "preprocessor", "Question", + 19, "SCE_H_VALUE", "literal string", "Unquoted Value", + 20, "", "unused", "", + 21, "SCE_H_SGML_DEFAULT", "default", "SGML tags ", + 22, "SCE_H_SGML_COMMAND", "preprocessor", "SGML command", + 23, "SCE_H_SGML_1ST_PARAM", "preprocessor", "SGML 1st param", + 24, "SCE_H_SGML_DOUBLESTRING", "literal string", "SGML double string", + 25, "SCE_H_SGML_SIMPLESTRING", "literal string", "SGML single string", + 26, "SCE_H_SGML_ERROR", "error", "SGML error", + 27, "SCE_H_SGML_SPECIAL", "literal", "SGML special (#XXXX type)", + 28, "SCE_H_SGML_ENTITY", "literal", "SGML entity", + 29, "SCE_H_SGML_COMMENT", "comment", "SGML comment", + 30, "", "unused", "", + 31, "SCE_H_SGML_BLOCK_DEFAULT", "default", "SGML block", +}; + +const char *tagsThatDoNotFold[] = { + "area", + "base", + "basefont", + "br", + "col", + "command", + "embed", + "frame", + "hr", + "img", + "input", + "isindex", + "keygen", + "link", + "meta", + "param", + "source", + "track", + "wbr" +}; + +} +class LexerHTML : public DefaultLexer { + bool isXml; + bool isPHPScript; + WordList keywords; + WordList keywords2; + WordList keywords3; + WordList keywords4; + WordList keywords5; + WordList keywords6; // SGML (DTD) keywords + OptionsHTML options; + OptionSetHTML osHTML; + std::set nonFoldingTags; +public: + explicit LexerHTML(bool isXml_, bool isPHPScript_) : + DefaultLexer(isXml_ ? lexicalClassesHTML : lexicalClassesXML, + isXml_ ? ELEMENTS(lexicalClassesHTML) : ELEMENTS(lexicalClassesXML)), + isXml(isXml_), + isPHPScript(isPHPScript_), + osHTML(isPHPScript_), + nonFoldingTags(std::begin(tagsThatDoNotFold), std::end(tagsThatDoNotFold)) { + } + ~LexerHTML() override { + } + void SCI_METHOD Release() override { + delete this; + } + const char *SCI_METHOD PropertyNames() override { + return osHTML.PropertyNames(); + } + int SCI_METHOD PropertyType(const char *name) override { + return osHTML.PropertyType(name); + } + const char *SCI_METHOD DescribeProperty(const char *name) override { + return osHTML.DescribeProperty(name); + } + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char *SCI_METHOD DescribeWordListSets() override { + return osHTML.DescribeWordListSets(); + } + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + // No Fold as all folding performs in Lex. + + static ILexer *LexerFactoryHTML() { + return new LexerHTML(false, false); + } + static ILexer *LexerFactoryXML() { + return new LexerHTML(true, false); + } + static ILexer *LexerFactoryPHPScript() { + return new LexerHTML(false, true); + } +}; + +Sci_Position SCI_METHOD LexerHTML::PropertySet(const char *key, const char *val) { + if (osHTML.PropertySet(&options, key, val)) { + return 0; + } + return -1; +} + +Sci_Position SCI_METHOD LexerHTML::WordListSet(int n, const char *wl) { + WordList *wordListN = 0; + switch (n) { + case 0: + wordListN = &keywords; + break; + case 1: + wordListN = &keywords2; + break; + case 2: + wordListN = &keywords3; + break; + case 3: + wordListN = &keywords4; + break; + case 4: + wordListN = &keywords5; + break; + case 5: + wordListN = &keywords6; + break; + } + Sci_Position firstModification = -1; + if (wordListN) { + WordList wlNew; + wlNew.Set(wl); + if (*wordListN != wlNew) { + wordListN->Set(wl); + firstModification = 0; + } + } + return firstModification; +} + +void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) { + Accessor styler(pAccess, nullptr); + if (isPHPScript && (startPos == 0)) { + initStyle = SCE_HPHP_DEFAULT; + } styler.StartAt(startPos); - char prevWord[200]; - prevWord[0] = '\0'; - char phpStringDelimiter[200]; // PHP is not limited in length, we are - phpStringDelimiter[0] = '\0'; + std::string prevWord; + std::string phpStringDelimiter; int StateToPrint = initStyle; int state = stateForPrintState(StateToPrint); - char makoBlockType[200]; - makoBlockType[0] = '\0'; + std::string makoBlockType; int makoComment = 0; - char djangoBlockType[2]; - djangoBlockType[0] = '\0'; - + std::string djangoBlockType; // If inside a tag, it may be a script tag, so reread from the start of line starting tag to ensure any language tags are seen if (InTagState(state)) { while ((startPos > 0) && (InTagState(styler.StyleAt(startPos - 1)))) { - Sci_Position backLineStart = styler.LineStart(styler.GetLine(startPos-1)); + const Sci_Position backLineStart = styler.LineStart(styler.GetLine(startPos-1)); length += startPos - backLineStart; startPos = backLineStart; } @@ -628,18 +969,15 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } else { // Default client and ASP scripting language is JavaScript lineState = eScriptJS << 8; - - // property asp.default.language - // Script in ASP code is initially assumed to be in JavaScript. - // To change this to VBScript set asp.default.language to 2. Python is 3. - lineState |= styler.GetPropertyInt("asp.default.language", eScriptJS) << 4; + lineState |= options.aspDefaultLanguage << 4; } - script_mode inScriptType = script_mode((lineState >> 0) & 0x03); // 2 bits of scripting mode + script_mode inScriptType = static_cast((lineState >> 0) & 0x03); // 2 bits of scripting mode + bool tagOpened = (lineState >> 2) & 0x01; // 1 bit to know if we are in an opened tag bool tagClosing = (lineState >> 3) & 0x01; // 1 bit to know if we are in a closing tag bool tagDontFold = false; //some HTML tags should not be folded - script_type aspScript = script_type((lineState >> 4) & 0x0F); // 4 bits of script name - script_type clientScript = script_type((lineState >> 8) & 0x0F); // 4 bits of script name + script_type aspScript = static_cast((lineState >> 4) & 0x0F); // 4 bits of script name + script_type clientScript = static_cast((lineState >> 8) & 0x0F); // 4 bits of script name int beforePreProc = (lineState >> 12) & 0xFF; // 8 bits of state script_type scriptLanguage = ScriptOfState(state); @@ -648,48 +986,16 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i scriptLanguage = eScriptComment; } script_type beforeLanguage = ScriptOfState(beforePreProc); - - // property fold.html - // Folding is turned on or off for HTML and XML files with this option. - // The fold option must also be on for folding to occur. - const bool foldHTML = styler.GetPropertyInt("fold.html", 0) != 0; - - const bool fold = foldHTML && styler.GetPropertyInt("fold", 0); - - // property fold.html.preprocessor - // Folding is turned on or off for scripts embedded in HTML files with this option. - // The default is on. - const bool foldHTMLPreprocessor = foldHTML && styler.GetPropertyInt("fold.html.preprocessor", 1); - - const bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0; - - // property fold.hypertext.comment - // Allow folding for comments in scripts embedded in HTML. - // The default is off. - const bool foldComment = fold && styler.GetPropertyInt("fold.hypertext.comment", 0) != 0; - - // property fold.hypertext.heredoc - // Allow folding for heredocs in scripts embedded in HTML. - // The default is off. - const bool foldHeredoc = fold && styler.GetPropertyInt("fold.hypertext.heredoc", 0) != 0; - - // property html.tags.case.sensitive - // For XML and HTML, setting this property to 1 will make tags match in a case - // sensitive way which is the expected behaviour for XML and XHTML. - const bool caseSensitive = styler.GetPropertyInt("html.tags.case.sensitive", 0) != 0; - - // property lexer.xml.allow.scripts - // Set to 0 to disable scripts in XML. - const bool allowScripts = styler.GetPropertyInt("lexer.xml.allow.scripts", 1) != 0; - - // property lexer.html.mako - // Set to 1 to enable the mako template language. - const bool isMako = styler.GetPropertyInt("lexer.html.mako", 0) != 0; - - // property lexer.html.django - // Set to 1 to enable the django template language. - const bool isDjango = styler.GetPropertyInt("lexer.html.django", 0) != 0; - + const bool foldHTML = options.foldHTML; + const bool fold = foldHTML && options.fold; + const bool foldHTMLPreprocessor = foldHTML && options.foldHTMLPreprocessor; + const bool foldCompact = options.foldCompact; + const bool foldComment = fold && options.foldComment; + const bool foldHeredoc = fold && options.foldHeredoc; + const bool caseSensitive = options.caseSensitive; + const bool allowScripts = options.allowScripts; + const bool isMako = options.isMako; + const bool isDjango = options.isDjango; const CharacterSet setHTMLWord(CharacterSet::setAlphaNum, ".-_:!#", 0x80, true); const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", 0x80, true); const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", 0x80, true); @@ -781,7 +1087,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i // check if the number of tabs is lower than the level int Findlevel = (levelCurrent & ~SC_FOLDLEVELBASE) * 8; for (Sci_Position j = 0; Findlevel > 0; j++) { - char chTmp = styler.SafeGetCharAt(i + j + 1); + const char chTmp = styler.SafeGetCharAt(i + j + 1); if (chTmp == '\t') { Findlevel -= 8; } else if (chTmp == ' ') { @@ -846,10 +1152,9 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_H_DEFAULT; } } - // Allow falling through to mako handling code if newline is going to end a block if (((ch == '\r' && chNext != '\n') || (ch == '\n')) && - (!isMako || (0 != strcmp(makoBlockType, "%")))) { + (!isMako || (makoBlockType != "%"))) { } // Ignore everything in mako comment until the line ends else if (isMako && makoComment) { @@ -948,13 +1253,13 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i (ch == '$' && chNext == '{') || (ch == '<' && chNext == '/' && chNext2 == '%'))) { if (ch == '%' || ch == '/') - StringCopy(makoBlockType, "%"); + makoBlockType = "%"; else if (ch == '$') - StringCopy(makoBlockType, "{"); + makoBlockType = "{"; else if (chNext == '/') - GetNextWord(styler, i+3, makoBlockType, sizeof(makoBlockType)); + makoBlockType = GetNextWord(styler, i+3); else - GetNextWord(styler, i+2, makoBlockType, sizeof(makoBlockType)); + makoBlockType = GetNextWord(styler, i+2); styler.ColourTo(i - 1, StateToPrint); beforePreProc = state; if (inScriptType == eNonHtmlScript) @@ -972,11 +1277,10 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_HP_START; scriptLanguage = eScriptPython; styler.ColourTo(i, SCE_H_ASP); - if (ch != '%' && ch != '$' && ch != '/') { - i += static_cast(strlen(makoBlockType)); - visibleChars += static_cast(strlen(makoBlockType)); - if (keywords4.InList(makoBlockType)) + i += makoBlockType.length(); + visibleChars += static_cast(makoBlockType.length()); + if (keywords4.InList(makoBlockType.c_str())) styler.ColourTo(i, SCE_HP_WORD); else styler.ColourTo(i, SCE_H_TAGUNKNOWN); @@ -1017,11 +1321,11 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } // handle the start Django template code - else if (isDjango && scriptLanguage != eScriptPython && (ch == '{' && (chNext == '%' || chNext == '{'))) { + else if (isDjango && scriptLanguage != eScriptPython && scriptLanguage != eScriptComment && (ch == '{' && (chNext == '%' || chNext == '{'))) { if (chNext == '%') - StringCopy(djangoBlockType, "%"); + djangoBlockType = "%"; else - StringCopy(djangoBlockType, "{"); + djangoBlockType = "{"; styler.ColourTo(i - 1, StateToPrint); beforePreProc = state; if (inScriptType == eNonHtmlScript) @@ -1120,15 +1424,15 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } else { styler.ColourTo(i - 1, StateToPrint); } - if (0 != strcmp(makoBlockType, "%") && (0 != strcmp(makoBlockType, "{")) && ch != '>') { + if ((makoBlockType != "%") && (makoBlockType != "{") && ch != '>') { i++; visibleChars++; } - else if (0 == strcmp(makoBlockType, "%") && ch == '/') { + else if ((makoBlockType == "%") && ch == '/') { i++; visibleChars++; } - if (0 != strcmp(makoBlockType, "%") || ch == '/') { + if ((makoBlockType != "%") || ch == '/') { styler.ColourTo(i, SCE_H_ASP); } state = beforePreProc; @@ -1406,7 +1710,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i case SCE_H_TAGUNKNOWN: if (!setTagContinue.Contains(ch) && !((ch == '/') && (chPrev == '<'))) { int eClass = classifyTagHTML(styler.GetStartSegment(), - i - 1, keywords, styler, tagDontFold, caseSensitive, isXml, allowScripts); + i - 1, keywords, styler, tagDontFold, caseSensitive, isXml, allowScripts, nonFoldingTags); if (eClass == SCE_H_SCRIPT || eClass == SCE_H_COMMENT) { if (!tagClosing) { inScriptType = eNonHtmlScript; @@ -1457,7 +1761,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i case SCE_H_ATTRIBUTE: if (!setAttributeContinue.Contains(ch)) { if (inScriptType == eNonHtmlScript) { - int scriptLanguagePrev = scriptLanguage; + const int scriptLanguagePrev = scriptLanguage; clientScript = segIsScriptingIndicator(styler, styler.GetStartSegment(), i - 1, scriptLanguage); scriptLanguage = clientScript; if ((scriptLanguagePrev != scriptLanguage) && (scriptLanguage == eScriptNone)) @@ -1936,17 +2240,17 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_HPHP_COMMENTLINE; } else if (ch == '\"') { state = SCE_HPHP_HSTRING; - StringCopy(phpStringDelimiter, "\""); + phpStringDelimiter = "\""; } else if (styler.Match(i, "<<<")) { bool isSimpleString = false; - i = FindPhpStringDelimiter(phpStringDelimiter, sizeof(phpStringDelimiter), i + 3, lengthDoc, styler, isSimpleString); - if (strlen(phpStringDelimiter)) { + i = FindPhpStringDelimiter(phpStringDelimiter, i + 3, lengthDoc, styler, isSimpleString); + if (!phpStringDelimiter.empty()) { state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING); if (foldHeredoc) levelCurrent++; } } else if (ch == '\'') { state = SCE_HPHP_SIMPLESTRING; - StringCopy(phpStringDelimiter, "\'"); + phpStringDelimiter = "\'"; } else if (ch == '$' && IsPhpWordStart(chNext)) { state = SCE_HPHP_VARIABLE; } else if (IsOperator(ch)) { @@ -1987,7 +2291,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } break; case SCE_HPHP_HSTRING: - if (ch == '\\' && (phpStringDelimiter[0] == '\"' || chNext == '$' || chNext == '{')) { + if (ch == '\\' && ((phpStringDelimiter == "\"") || chNext == '$' || chNext == '{')) { // skip the next char i++; } else if (((ch == '{' && chNext == '$') || (ch == '$' && chNext == '{')) @@ -1997,12 +2301,12 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } else if (ch == '$' && IsPhpWordStart(chNext)) { styler.ColourTo(i - 1, StateToPrint); state = SCE_HPHP_HSTRING_VARIABLE; - } else if (styler.Match(i, phpStringDelimiter)) { - if (phpStringDelimiter[0] == '\"') { + } else if (styler.Match(i, phpStringDelimiter.c_str())) { + if (phpStringDelimiter == "\"") { styler.ColourTo(i, StateToPrint); state = SCE_HPHP_DEFAULT; } else if (isLineEnd(chPrev)) { - const int psdLength = static_cast(strlen(phpStringDelimiter)); + const int psdLength = static_cast(phpStringDelimiter.length()); const char chAfterPsd = styler.SafeGetCharAt(i + psdLength); const char chAfterPsd2 = styler.SafeGetCharAt(i + psdLength + 1); if (isLineEnd(chAfterPsd) || @@ -2016,7 +2320,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } break; case SCE_HPHP_SIMPLESTRING: - if (phpStringDelimiter[0] == '\'') { + if (phpStringDelimiter == "\'") { if (ch == '\\') { // skip the next char i++; @@ -2024,8 +2328,8 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i styler.ColourTo(i, StateToPrint); state = SCE_HPHP_DEFAULT; } - } else if (isLineEnd(chPrev) && styler.Match(i, phpStringDelimiter)) { - const int psdLength = static_cast(strlen(phpStringDelimiter)); + } else if (isLineEnd(chPrev) && styler.Match(i, phpStringDelimiter.c_str())) { + const int psdLength = static_cast(phpStringDelimiter.length()); const char chAfterPsd = styler.SafeGetCharAt(i + psdLength); const char chAfterPsd2 = styler.SafeGetCharAt(i + psdLength + 1); if (isLineEnd(chAfterPsd) || @@ -2066,17 +2370,17 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_HPHP_COMMENTLINE; } else if (ch == '\"') { state = SCE_HPHP_HSTRING; - StringCopy(phpStringDelimiter, "\""); + phpStringDelimiter = "\""; } else if (styler.Match(i, "<<<")) { bool isSimpleString = false; - i = FindPhpStringDelimiter(phpStringDelimiter, sizeof(phpStringDelimiter), i + 3, lengthDoc, styler, isSimpleString); - if (strlen(phpStringDelimiter)) { + i = FindPhpStringDelimiter(phpStringDelimiter, i + 3, lengthDoc, styler, isSimpleString); + if (!phpStringDelimiter.empty()) { state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING); if (foldHeredoc) levelCurrent++; } } else if (ch == '\'') { state = SCE_HPHP_SIMPLESTRING; - StringCopy(phpStringDelimiter, "\'"); + phpStringDelimiter = "\'"; } else if (ch == '$' && IsPhpWordStart(chNext)) { state = SCE_HPHP_VARIABLE; } else if (IsOperator(ch)) { @@ -2091,7 +2395,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i // Some of the above terminated their lexeme but since the same character starts // the same class again, only reenter if non empty segment. - bool nonEmptySegment = i >= static_cast(styler.GetStartSegment()); + const bool nonEmptySegment = i >= static_cast(styler.GetStartSegment()); if (state == SCE_HB_DEFAULT) { // One of the above succeeded if ((ch == '\"') && (nonEmptySegment)) { state = SCE_HB_STRING; @@ -2154,50 +2458,12 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i // Fill in the real level of the next line, keeping the current flags as they will be filled in later if (fold) { - int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; + const int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; styler.SetLevel(lineCurrent, levelPrev | flagsNext); } + styler.Flush(); } -static void ColouriseXMLDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], - Accessor &styler) { - // Passing in true because we're lexing XML - ColouriseHyperTextDoc(startPos, length, initStyle, keywordlists, styler, true); -} - -static void ColouriseHTMLDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], - Accessor &styler) { - // Passing in false because we're notlexing XML - ColouriseHyperTextDoc(startPos, length, initStyle, keywordlists, styler, false); -} - -static void ColourisePHPScriptDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], - Accessor &styler) { - if (startPos == 0) - initStyle = SCE_HPHP_DEFAULT; - ColouriseHTMLDoc(startPos, length, initStyle, keywordlists, styler); -} - -static const char * const htmlWordListDesc[] = { - "HTML elements and attributes", - "JavaScript keywords", - "VBScript keywords", - "Python keywords", - "PHP keywords", - "SGML and DTD keywords", - 0, -}; - -static const char * const phpscriptWordListDesc[] = { - "", //Unused - "", //Unused - "", //Unused - "", //Unused - "PHP keywords", - "", //Unused - 0, -}; - -LexerModule lmHTML(SCLEX_HTML, ColouriseHTMLDoc, "hypertext", 0, htmlWordListDesc); -LexerModule lmXML(SCLEX_XML, ColouriseXMLDoc, "xml", 0, htmlWordListDesc); -LexerModule lmPHPSCRIPT(SCLEX_PHPSCRIPT, ColourisePHPScriptDoc, "phpscript", 0, phpscriptWordListDesc); +LexerModule lmHTML(SCLEX_HTML, LexerHTML::LexerFactoryHTML, "hypertext", htmlWordListDesc); +LexerModule lmXML(SCLEX_XML, LexerHTML::LexerFactoryXML, "xml", htmlWordListDesc); +LexerModule lmPHPSCRIPT(SCLEX_PHPSCRIPT, LexerHTML::LexerFactoryPHPScript, "phpscript", phpscriptWordListDesc); diff --git a/scintilla/lexers/LexHaskell.cxx b/scintilla/lexers/LexHaskell.cxx index 26657830..680a0f29 100644 --- a/scintilla/lexers/LexHaskell.cxx +++ b/scintilla/lexers/LexHaskell.cxx @@ -41,10 +41,9 @@ #include "CharacterCategory.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // See https://github.com/ghc/ghc/blob/master/compiler/parser/Lexer.x#L1682 // Note, letter modifiers are prohibited. @@ -269,7 +268,7 @@ struct OptionSetHaskell : public OptionSet { } }; -class LexerHaskell : public ILexer { +class LexerHaskell : public DefaultLexer { bool literate; Sci_Position firstImportLine; int firstImportIndent; diff --git a/scintilla/lexers/LexLaTeX.cxx b/scintilla/lexers/LexLaTeX.cxx index 612ef486..ed9e6a6b 100644 --- a/scintilla/lexers/LexLaTeX.cxx +++ b/scintilla/lexers/LexLaTeX.cxx @@ -28,9 +28,7 @@ #include "LexerModule.h" #include "LexerBase.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif using namespace std; @@ -42,7 +40,7 @@ struct latexFoldSave { for (int i = 0; i < 8; ++i) openBegins[i] = save.openBegins[i]; } int openBegins[8]; - int structLev; + Sci_Position structLev; }; class LexerLaTeX : public LexerBase { diff --git a/scintilla/lexers/LexLisp.cxx b/scintilla/lexers/LexLisp.cxx index 8d81eae2..8e758635 100644 --- a/scintilla/lexers/LexLisp.cxx +++ b/scintilla/lexers/LexLisp.cxx @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif #define SCE_LISP_CHARACTER 29 #define SCE_LISP_MACRO 30 diff --git a/scintilla/lexers/LexLua.cxx b/scintilla/lexers/LexLua.cxx index 9e86b8a1..9e6e8a70 100644 --- a/scintilla/lexers/LexLua.cxx +++ b/scintilla/lexers/LexLua.cxx @@ -14,10 +14,13 @@ #include #include +#include + #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" +#include "StringCopy.h" #include "WordList.h" #include "LexAccessor.h" #include "Accessor.h" @@ -25,9 +28,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // Test for [=[ ... ]=] delimiters, returns 0 if it's only a [ or ], // return 1 for [[ or ]], returns >=2 for [=[ or ]=] and so on. @@ -83,6 +84,12 @@ static void ColouriseLuaDoc( stringWs = lineState & 0x100; } + // results of identifier/keyword matching + Sci_Position idenPos = 0; + Sci_Position idenWordPos = 0; + int idenStyle = SCE_LUA_IDENTIFIER; + bool foundGoto = false; + // Do not leak onto next line if (initStyle == SCE_LUA_STRINGEOL || initStyle == SCE_LUA_COMMENTLINE || initStyle == SCE_LUA_PREPROCESSOR) { initStyle = SCE_LUA_DEFAULT; @@ -178,40 +185,32 @@ static void ColouriseLuaDoc( sc.SetState(SCE_LUA_DEFAULT); } } else if (sc.state == SCE_LUA_IDENTIFIER) { - if (!(setWord.Contains(sc.ch) || sc.ch == '.') || sc.Match('.', '.')) { - char s[100]; - sc.GetCurrent(s, sizeof(s)); - if (keywords.InList(s)) { - sc.ChangeState(SCE_LUA_WORD); - if (strcmp(s, "goto") == 0) { // goto