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.
This commit is contained in:
Colomban Wendling 2018-08-01 14:51:52 +02:00
parent 958deb55fe
commit 3fa7576e13
158 changed files with 5488 additions and 4257 deletions

View File

@ -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])
{

View File

@ -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 \

View File

@ -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<gsize>(-1);
@ -67,8 +65,6 @@ public:
}
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -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<GtkWidget *>(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<ColourStop> &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<ColourStop> &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<unsigned char> image(ucs);
for (int iy=0; iy<height; iy++) {
@ -618,7 +606,7 @@ void SurfaceImpl::Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back)
PLATFORM_ASSERT(context);
PenColour(back);
cairo_arc(context, (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2,
Platform::Minimum(rc.Width(), rc.Height()) / 2, 0, 2*kPi);
std::min(rc.Width(), rc.Height()) / 2, 0, 2*kPi);
cairo_fill_preserve(context);
PenColour(fore);
cairo_stroke(context);
@ -706,11 +694,7 @@ void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, XYPOSITION ybase, con
}
pango_layout_set_font_description(layout, PFont(font_)->pfd);
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<unsigned char>(utfForm.c_str()[clusterStart]));
clusterStart += UTF8BytesOfLead[static_cast<unsigned char>(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<ListBoxX*>(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<ListBoxX*>(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<GtkWidget *>(parent.GetID()));
gtk_window_set_transient_for(GTK_WINDOW(static_cast<GtkWidget *>(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<DynamicLibrary *>( 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<sptr_t>(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<unsigned char>(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() {
}

View File

@ -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<GtkWidget *>(w.GetID());
@ -155,6 +147,8 @@ static const GtkTargetEntry clipboardPasteTargets[] = {
};
static const gint nClipboardPasteTargets = ELEMENTS(clipboardPasteTargets);
static const GdkDragAction actionCopyOrMove = static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE);
static GtkWidget *PWidget(Window &w) {
return static_cast<GtkWidget *>(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<GdkEvent *>(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<GdkDragAction>(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<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE),
evbtn->button,
reinterpret_cast<GdkEvent *>(evbtn),
actionCopyOrMove,
buttonMouse,
evbtn,
-1, -1);
#else
gtk_drag_begin(GTK_WIDGET(PWidget(wMain)),
tl,
static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE),
evbtn->button,
reinterpret_cast<GdkEvent *>(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<const char*>(lParam));
LexerManager::GetInstance()->Load(ConstCharPtrFromSPtr(lParam));
break;
#endif
case SCI_TARGETASUTF8:
return TargetAsUTF8(reinterpret_cast<char*>(lParam));
return TargetAsUTF8(CharPtrFromSPtr(lParam));
case SCI_ENCODEDFROMUTF8:
return EncodedFromUTF8(reinterpret_cast<char*>(wParam),
reinterpret_cast<char*>(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<IdlerID>(
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<void *>(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<GtkWidget *>(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<GdkAtom>(GDK_SELECTION_TYPE_STRING),
8, reinterpret_cast<const unsigned char *>(textData), len);
8, reinterpret_cast<const guchar *>(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<GdkEvent *>(evbtn));
evbtn = 0;
gdk_event_free(evbtn);
}
evbtn = reinterpret_cast<GdkEventButton *>(gdk_event_copy(reinterpret_cast<GdkEvent *>(event)));
evbtn = gdk_event_copy(reinterpret_cast<GdkEvent *>(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<ScintillaObject *>(object);
ScintillaGTK *sciThis = reinterpret_cast<ScintillaGTK *>(scio->pscin);
ScintillaObject *scio = SCINTILLA(object);
ScintillaGTK *sciThis = static_cast<ScintillaGTK *>(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<GdkDragAction>(0);
} else if (actions == static_cast<GdkDragAction>
(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; r<sciThis->sel.Count(); r++) {
if (sciThis->posDrop >= sciThis->sel.Range(r).Start()) {

View File

@ -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

View File

@ -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<Helper*>(data);
Helper *helper = static_cast<Helper*>(data);
try {
if (helper->scia != 0) {
helper->TextReceived(clipboard, text);

View File

@ -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<ScintillaGTKAccessible*>(data)->Notify(widget, code, nt);
static_cast<ScintillaGTKAccessible*>(data)->Notify(widget, code, nt);
} catch (...) {}
}
@ -188,9 +186,7 @@ public:
};
};
#ifdef SCI_NAMESPACE
}
#endif
#endif /* SCINTILLAGTKACCESSIBLE_H */

View File

@ -1,7 +1,5 @@
#include <glib-object.h>
#ifdef G_ENABLE_DEBUG
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
#define g_marshal_value_peek_char(v) g_value_get_schar (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,
@ -59,12 +56,12 @@ scintilla_marshal_VOID__INT_OBJECT (GClosure *closure,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__INT_OBJECT) (gpointer data1,
gint arg_1,
gpointer arg_2,
gint arg1,
gpointer arg2,
gpointer data2);
GMarshalFunc_VOID__INT_OBJECT callback;
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,
@ -96,12 +93,12 @@ scintilla_marshal_VOID__INT_BOXED (GClosure *closure,
gpointer marshal_data)
{
typedef void (*GMarshalFunc_VOID__INT_BOXED) (gpointer data1,
gint arg_1,
gpointer arg_2,
gint arg1,
gpointer arg2,
gpointer data2);
GMarshalFunc_VOID__INT_BOXED callback;
GCClosure *cc = (GCClosure *) closure;
gpointer data1, data2;
GMarshalFunc_VOID__INT_BOXED callback;
g_return_if_fail (n_param_values == 3);

View File

@ -1,30 +1,30 @@
#ifndef __scintilla_marshal_MARSHAL_H__
#define __scintilla_marshal_MARSHAL_H__
/* This file is generated, all changes will be lost */
#ifndef __SCINTILLA_MARSHAL_MARSHAL_H__
#define __SCINTILLA_MARSHAL_MARSHAL_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* NONE:INT,OBJECT (scintilla-marshal.list:1) */
extern void scintilla_marshal_VOID__INT_OBJECT (GClosure *closure,
/* 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);
#define scintilla_marshal_NONE__INT_OBJECT scintilla_marshal_VOID__INT_OBJECT
/* NONE:INT,BOXED (scintilla-marshal.list:2) */
extern void scintilla_marshal_VOID__INT_BOXED (GClosure *closure,
/* 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);
#define scintilla_marshal_NONE__INT_BOXED scintilla_marshal_VOID__INT_BOXED
G_END_DECLS
#endif /* __scintilla_marshal_MARSHAL_H__ */
#endif /* __SCINTILLA_MARSHAL_MARSHAL_H__ */

View File

@ -1,2 +1,2 @@
NONE:INT,OBJECT
NONE:INT,BOXED
VOID:INT,OBJECT
VOID:INT,BOXED

View File

@ -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

View File

@ -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 <neilh@scintilla.org>
// 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

View File

@ -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<int>(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<XYPOSITION>(x_), static_cast<XYPOSITION>(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<XYPOSITION>(left_), static_cast<XYPOSITION>(top_),
static_cast<XYPOSITION>(right_), static_cast<XYPOSITION>(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<ColourStop> &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<short>(x >> 16);
}
static short LowShortFromLong(long x) {
return static_cast<short>(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

View File

@ -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

View File

@ -9,13 +9,21 @@
#ifndef SCI_POSITION_H
#define SCI_POSITION_H
#include <stddef.h>
// 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

View File

@ -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 <stddef.h>
#else
#include <stdint.h>
#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

View File

@ -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

View File

@ -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 == ' ')));

View File

@ -25,9 +25,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
/*
* Interface

View File

@ -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<OptionsAsm> {
}
};
class LexerAsm : public ILexer {
class LexerAsm : public DefaultLexer {
WordList cpuInstruction;
WordList mathInstruction;
WordList registers;

View File

@ -23,9 +23,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
#define HERE_DELIM_MAX 256

View File

@ -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<OptionsBasic> {
}
};
class LexerBasic : public ILexer {
class LexerBasic : public DefaultLexer {
char comment_char;
int (*CheckFoldPoint)(char const *, int &);
WordList keywordlists[4];

View File

@ -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');

View File

@ -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

View File

@ -13,6 +13,7 @@
#include <assert.h>
#include <ctype.h>
#include <utility>
#include <string>
#include <vector>
#include <map>
@ -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<Sci_Position>(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<Sci_Position>(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<std::string> StringSplit(const std::string &text, int separator) {
std::vector<std::string> 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<Sci_Position>(sc.currentPos);
char marker[lengthMarker+1] = "";
const Sci_Position currPos = static_cast<Sci_Position>(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<char>(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();
@ -432,9 +432,41 @@ struct OptionSetCPP : public OptionSet<OptionsCPP> {
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();
@ -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<int>(ELEMENTS(lexicalClasses))) +
activeFlag;
}
const char * SCI_METHOD NameOfStyle(int style) override {
if (style >= NamedStyles())
return "";
if (style < static_cast<int>(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<int>(ELEMENTS(lexicalClasses)))
return lexicalClasses[style].tags;
if (style >= activeFlag) {
returnBuffer = "inactive ";
const int styleActive = style - activeFlag;
if (styleActive < static_cast<int>(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<int>(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<std::string> &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<PPDefinition>::iterator itInvalid = std::find_if(ppDefineHistory.begin(), ppDefineHistory.end(), After(lineCurrent-1));
std::vector<PPDefinition>::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;
@ -1433,6 +1513,7 @@ void LexerCPP::EvaluateTokens(std::vector<std::string> &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<std::string> &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++;

View File

@ -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);

View File

@ -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

View File

@ -24,9 +24,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static bool isCmakeNumber(char ch)
{

View File

@ -14,7 +14,8 @@
#include <assert.h>
#include <ctype.h>
#include "Platform.h"
#include <algorithm>
#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

View File

@ -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<OptionsD> {
}
};
class LexerD : public ILexer {
class LexerD : public DefaultLexer {
bool caseSensitive;
WordList keywords;
WordList keywords2;

View File

@ -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] == '>') {

View File

@ -1,11 +1,12 @@
// Scintilla source code edit control
// Encoding: UTF-8
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
// 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 <stdlib.h>
@ -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

View File

@ -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 == '.');

View File

@ -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;
}

File diff suppressed because it is too large Load Diff

View File

@ -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<OptionsHaskell> {
}
};
class LexerHaskell : public ILexer {
class LexerHaskell : public DefaultLexer {
bool literate;
Sci_Position firstImportLine;
int firstImportIndent;

View File

@ -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 {

View File

@ -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

View File

@ -14,10 +14,13 @@
#include <assert.h>
#include <ctype.h>
#include <string>
#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,13 +185,21 @@ 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 <label> forward scan
idenPos--; // commit already-scanned identitier/word parts
if (idenWordPos > 0) {
idenWordPos--;
sc.ChangeState(idenStyle);
sc.ForwardBytes(idenWordPos);
idenPos -= idenWordPos;
if (idenPos > 0) {
sc.SetState(SCE_LUA_IDENTIFIER);
sc.ForwardBytes(idenPos);
}
} else {
sc.ForwardBytes(idenPos);
}
sc.SetState(SCE_LUA_DEFAULT);
if (foundGoto) { // goto <label> forward scan
while (IsASpaceOrTab(sc.ch) && !sc.atLineEnd)
sc.Forward();
if (setWordStart.Contains(sc.ch)) {
@ -192,29 +207,13 @@ static void ColouriseLuaDoc(
sc.Forward();
while (setWord.Contains(sc.ch))
sc.Forward();
char s[100];
sc.GetCurrent(s, sizeof(s));
if (keywords.InList(s))
if (keywords.InList(s)) // labels cannot be keywords
sc.ChangeState(SCE_LUA_WORD);
}
sc.SetState(SCE_LUA_DEFAULT);
}
} else if (keywords2.InList(s)) {
sc.ChangeState(SCE_LUA_WORD2);
} else if (keywords3.InList(s)) {
sc.ChangeState(SCE_LUA_WORD3);
} else if (keywords4.InList(s)) {
sc.ChangeState(SCE_LUA_WORD4);
} else if (keywords5.InList(s)) {
sc.ChangeState(SCE_LUA_WORD5);
} else if (keywords6.InList(s)) {
sc.ChangeState(SCE_LUA_WORD6);
} else if (keywords7.InList(s)) {
sc.ChangeState(SCE_LUA_WORD7);
} else if (keywords8.InList(s)) {
sc.ChangeState(SCE_LUA_WORD8);
}
sc.SetState(SCE_LUA_DEFAULT);
}
} else if (sc.state == SCE_LUA_COMMENTLINE || sc.state == SCE_LUA_PREPROCESSOR) {
if (sc.atLineEnd) {
sc.ForwardSetState(SCE_LUA_DEFAULT);
@ -285,6 +284,66 @@ static void ColouriseLuaDoc(
sc.Forward();
}
} else if (setWordStart.Contains(sc.ch)) {
// For matching various identifiers with dots and colons, multiple
// matches are done as identifier segments are added. Longest match is
// set to a word style. The non-matched part is in identifier style.
std::string ident;
idenPos = 0;
idenWordPos = 0;
idenStyle = SCE_LUA_IDENTIFIER;
foundGoto = false;
int cNext;
do {
int c;
const Sci_Position idenPosOld = idenPos;
std::string identSeg;
identSeg += static_cast<char>(sc.GetRelative(idenPos++));
while (setWord.Contains(c = sc.GetRelative(idenPos))) {
identSeg += static_cast<char>(c);
idenPos++;
}
if (keywords.InList(identSeg.c_str()) && (idenPosOld > 0)) {
idenPos = idenPosOld - 1; // keywords cannot mix
ident.pop_back();
break;
}
ident += identSeg;
const char* s = ident.c_str();
int newStyle = SCE_LUA_IDENTIFIER;
if (keywords.InList(s)) {
newStyle = SCE_LUA_WORD;
} else if (keywords2.InList(s)) {
newStyle = SCE_LUA_WORD2;
} else if (keywords3.InList(s)) {
newStyle = SCE_LUA_WORD3;
} else if (keywords4.InList(s)) {
newStyle = SCE_LUA_WORD4;
} else if (keywords5.InList(s)) {
newStyle = SCE_LUA_WORD5;
} else if (keywords6.InList(s)) {
newStyle = SCE_LUA_WORD6;
} else if (keywords7.InList(s)) {
newStyle = SCE_LUA_WORD7;
} else if (keywords8.InList(s)) {
newStyle = SCE_LUA_WORD8;
}
if (newStyle != SCE_LUA_IDENTIFIER) {
idenStyle = newStyle;
idenWordPos = idenPos;
}
if (idenStyle == SCE_LUA_WORD) // keywords cannot mix
break;
cNext = sc.GetRelative(idenPos + 1);
if ((c == '.' || c == ':') && setWordStart.Contains(cNext)) {
ident += static_cast<char>(c);
idenPos++;
} else {
cNext = 0;
}
} while (cNext);
if ((idenStyle == SCE_LUA_WORD) && (ident.compare("goto") == 0)) {
foundGoto = true;
}
sc.SetState(SCE_LUA_IDENTIFIER);
} else if (sc.ch == '\"') {
sc.SetState(SCE_LUA_STRING);
@ -322,28 +381,6 @@ static void ColouriseLuaDoc(
}
}
if (setWord.Contains(sc.chPrev) || sc.chPrev == '.') {
char s[100];
sc.GetCurrent(s, sizeof(s));
if (keywords.InList(s)) {
sc.ChangeState(SCE_LUA_WORD);
} else if (keywords2.InList(s)) {
sc.ChangeState(SCE_LUA_WORD2);
} else if (keywords3.InList(s)) {
sc.ChangeState(SCE_LUA_WORD3);
} else if (keywords4.InList(s)) {
sc.ChangeState(SCE_LUA_WORD4);
} else if (keywords5.InList(s)) {
sc.ChangeState(SCE_LUA_WORD5);
} else if (keywords6.InList(s)) {
sc.ChangeState(SCE_LUA_WORD6);
} else if (keywords7.InList(s)) {
sc.ChangeState(SCE_LUA_WORD7);
} else if (keywords8.InList(s)) {
sc.ChangeState(SCE_LUA_WORD8);
}
}
sc.Complete();
}
@ -433,4 +470,33 @@ static const char * const luaWordListDesc[] = {
0
};
LexerModule lmLua(SCLEX_LUA, ColouriseLuaDoc, "lua", FoldLuaDoc, luaWordListDesc);
namespace {
LexicalClass lexicalClasses[] = {
// Lexer Lua SCLEX_LUA SCE_LUA_:
0, "SCE_LUA_DEFAULT", "default", "White space: Visible only in View Whitespace mode (or if it has a back colour)",
1, "SCE_LUA_COMMENT", "comment", "Block comment (Lua 5.0)",
2, "SCE_LUA_COMMENTLINE", "comment line", "Line comment",
3, "SCE_LUA_COMMENTDOC", "comment documentation", "Doc comment -- Not used in Lua (yet?)",
4, "SCE_LUA_NUMBER", "literal numeric", "Number",
5, "SCE_LUA_WORD", "keyword", "Keyword",
6, "SCE_LUA_STRING", "literal string", "(Double quoted) String",
7, "SCE_LUA_CHARACTER", "literal string character", "Character (Single quoted string)",
8, "SCE_LUA_LITERALSTRING", "literal string", "Literal string",
9, "SCE_LUA_PREPROCESSOR", "preprocessor", "Preprocessor (obsolete in Lua 4.0 and up)",
10, "SCE_LUA_OPERATOR", "operator", "Operators",
11, "SCE_LUA_IDENTIFIER", "identifier", "Identifier (everything else...)",
12, "SCE_LUA_STRINGEOL", "error literal string", "End of line where string is not closed",
13, "SCE_LUA_WORD2", "identifier", "Other keywords",
14, "SCE_LUA_WORD3", "identifier", "Other keywords",
15, "SCE_LUA_WORD4", "identifier", "Other keywords",
16, "SCE_LUA_WORD5", "identifier", "Other keywords",
17, "SCE_LUA_WORD6", "identifier", "Other keywords",
18, "SCE_LUA_WORD7", "identifier", "Other keywords",
19, "SCE_LUA_WORD8", "identifier", "Other keywords",
20, "SCE_LUA_LABEL", "label", "Labels",
};
}
LexerModule lmLua(SCLEX_LUA, ColouriseLuaDoc, "lua", FoldLuaDoc, luaWordListDesc, lexicalClasses, ELEMENTS(lexicalClasses));

View File

@ -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') ||

View File

@ -51,9 +51,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static inline bool IsNewline(const int ch) {
return (ch == '\n' || ch == '\r');

View File

@ -1,7 +1,8 @@
// Scintilla source code edit control
// Encoding: UTF-8
/** @file LexMatlab.cxx
** Lexer for Matlab.
** Written by José Fonseca
** Written by José Fonseca
**
** Changes by Christoph Dalitz 2003/12/04:
** - added support for Octave
@ -43,9 +44,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static bool IsMatlabCommentChar(int c) {
return (c == '%') ;
@ -65,6 +64,7 @@ static int CheckKeywordFoldPoint(char *str) {
if (strcmp ("if", str) == 0 ||
strcmp ("for", str) == 0 ||
strcmp ("switch", str) == 0 ||
strcmp ("while", str) == 0 ||
strcmp ("try", str) == 0 ||
strcmp ("do", str) == 0 ||
strcmp ("parfor", str) == 0 ||
@ -100,6 +100,9 @@ static void ColouriseMatlabOctaveDoc(
// of a string
bool transpose = false;
// count of brackets as boolean for when end could be an operator not a keyword
int allow_end_op = 0;
// approximate position of first non space character in a line
int nonSpaceColumn = -1;
// approximate column position of the current character in a line
@ -153,7 +156,11 @@ static void ColouriseMatlabOctaveDoc(
if (!isalnum(sc.ch) && sc.ch != '_') {
char s[100];
sc.GetCurrentLowered(s, sizeof(s));
if (keywords.InList(s)) {
if (strcmp ("end", s) == 0 && allow_end_op) {
sc.ChangeState(SCE_MATLAB_NUMBER);
}
sc.SetState(SCE_MATLAB_DEFAULT);
transpose = false;
} else {
@ -253,6 +260,12 @@ static void ColouriseMatlabOctaveDoc(
} else if (isalpha(sc.ch)) {
sc.SetState(SCE_MATLAB_KEYWORD);
} else if (isoperator(static_cast<char>(sc.ch)) || sc.ch == '@' || sc.ch == '\\') {
if (sc.ch == '(' || sc.ch == '[' || sc.ch == '{') {
allow_end_op ++;
} else if ((sc.ch == ')' || sc.ch == ']' || sc.ch == '}') && (allow_end_op > 0)) {
allow_end_op --;
}
if (sc.ch == ')' || sc.ch == ']' || sc.ch == '}') {
transpose = true;
} else {
@ -281,6 +294,12 @@ static void FoldMatlabOctaveDoc(Sci_PositionU startPos, Sci_Position length, int
WordList *[], Accessor &styler,
bool (*IsComment)(int ch)) {
if (styler.GetPropertyInt("fold") == 0)
return;
const bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
const bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
Sci_PositionU endPos = startPos + length;
int visibleChars = 0;
Sci_Position lineCurrent = styler.GetLine(startPos);
@ -301,7 +320,7 @@ static void FoldMatlabOctaveDoc(Sci_PositionU startPos, Sci_Position length, int
bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
// a line that starts with a comment
if (style == SCE_MATLAB_COMMENT && IsComment(ch) && visibleChars == 0) {
if (foldComment && style == SCE_MATLAB_COMMENT && IsComment(ch) && visibleChars == 0) {
// start/end of block comment
if (chNext == '{' && IsSpaceToEOL(i+2, styler))
levelNext ++;
@ -327,7 +346,7 @@ static void FoldMatlabOctaveDoc(Sci_PositionU startPos, Sci_Position length, int
if (atEOL || (i == endPos-1)) {
int levelUse = levelCurrent;
int lev = levelUse | levelNext << 16;
if (visibleChars == 0)
if (visibleChars == 0 && foldCompact)
lev |= SC_FOLDLEVELWHITEFLAG;
if (levelUse < levelNext)
lev |= SC_FOLDLEVELHEADERFLAG;

View File

@ -24,9 +24,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
/*
// located in SciLexer.h

View File

@ -23,9 +23,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static void ColouriseNullDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *[],
Accessor &styler) {

View File

@ -31,9 +31,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static void ColourisePODoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *[], Accessor &styler) {
StyleContext sc(startPos, length, initStyle, styler);

View File

@ -128,9 +128,7 @@ contains requires
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static void GetRangeLowered(Sci_PositionU start,
Sci_PositionU end,

View File

@ -27,10 +27,9 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#include "OptionSet.h"
#include "DefaultLexer.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
// Info for HERE document handling from perldata.pod (reformatted):
// ----------------------------------------------------------------
@ -122,8 +121,8 @@ static int disambiguateBareword(LexAccessor &styler, Sci_PositionU bk, Sci_Posit
// if ch isn't one of '[{(,' we can skip the test
if ((ch == '{' || ch == '(' || ch == '['|| ch == ',')
&& fw < endPos) {
while (ch = static_cast<unsigned char>(styler.SafeGetCharAt(fw)),
IsASpaceOrTab(ch) && fw < endPos) {
while (IsASpaceOrTab(ch = static_cast<unsigned char>(styler.SafeGetCharAt(fw)))
&& fw < endPos) {
fw++;
}
if ((ch == '}' && brace)
@ -138,11 +137,13 @@ static int disambiguateBareword(LexAccessor &styler, Sci_PositionU bk, Sci_Posit
static void skipWhitespaceComment(LexAccessor &styler, Sci_PositionU &p) {
// when backtracking, we need to skip whitespace and comments
int style;
while ((p > 0) && (style = styler.StyleAt(p),
style == SCE_PL_DEFAULT || style == SCE_PL_COMMENTLINE))
while (p > 0) {
const int style = styler.StyleAt(p);
if (style != SCE_PL_DEFAULT && style != SCE_PL_COMMENTLINE)
break;
p--;
}
}
static int findPrevLexeme(LexAccessor &styler, Sci_PositionU &bk, int &style) {
// scan backward past whitespace and comments to find a lexeme
@ -398,7 +399,7 @@ struct OptionSetPerl : public OptionSet<OptionsPerl> {
}
};
class LexerPerl : public ILexer {
class LexerPerl : public DefaultLexer {
CharacterSet setWordStart;
CharacterSet setWord;
CharacterSet setSpecialVar;
@ -1174,6 +1175,7 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int
break;
}
// (continued for ' delim)
// Falls through.
default: // non-interpolated path
sc.Forward(sLen);
}

View File

@ -23,9 +23,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
// Extended to accept accented characters
static inline bool IsAWordChar(int ch) {

View File

@ -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') ||

View File

@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include "ILexer.h"
#include "Scintilla.h"
@ -30,10 +31,9 @@
#include "LexerModule.h"
#include "OptionSet.h"
#include "SubStyles.h"
#include "DefaultLexer.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
namespace {
// Use an unnamed namespace to protect the functions and classes from name conflicts
@ -308,21 +308,46 @@ struct OptionSetPython : public OptionSet<OptionsPython> {
const char styleSubable[] = { SCE_P_IDENTIFIER, 0 };
LexicalClass lexicalClasses[] = {
// Lexer Python SCLEX_PYTHON SCE_P_:
0, "SCE_P_DEFAULT", "default", "White space",
1, "SCE_P_COMMENTLINE", "comment line", "Comment",
2, "SCE_P_NUMBER", "literal numeric", "Number",
3, "SCE_P_STRING", "literal string", "String",
4, "SCE_P_CHARACTER", "literal string", "Single quoted string",
5, "SCE_P_WORD", "keyword", "Keyword",
6, "SCE_P_TRIPLE", "literal string", "Triple quotes",
7, "SCE_P_TRIPLEDOUBLE", "literal string", "Triple double quotes",
8, "SCE_P_CLASSNAME", "identifier", "Class name definition",
9, "SCE_P_DEFNAME", "identifier", "Function or method name definition",
10, "SCE_P_OPERATOR", "operator", "Operators",
11, "SCE_P_IDENTIFIER", "identifier", "Identifiers",
12, "SCE_P_COMMENTBLOCK", "comment", "Comment-blocks",
13, "SCE_P_STRINGEOL", "error literal string", "End of line where string is not closed",
14, "SCE_P_WORD2", "identifier", "Highlighted identifiers",
15, "SCE_P_DECORATOR", "preprocessor", "Decorators",
16, "SCE_P_FSTRING", "literal string interpolated", "F-String",
17, "SCE_P_FCHARACTER", "literal string interpolated", "Single quoted f-string",
18, "SCE_P_FTRIPLE", "literal string interpolated", "Triple quoted f-string",
19, "SCE_P_FTRIPLEDOUBLE", "literal string interpolated", "Triple double quoted f-string",
};
}
class LexerPython : public ILexerWithSubStyles {
class LexerPython : public DefaultLexer {
WordList keywords;
WordList keywords2;
OptionsPython options;
OptionSetPython osPython;
enum { ssIdentifier };
SubStyles subStyles;
std::map<int, std::vector<SingleFStringExpState> > ftripleStateAtEol;
std::map<Sci_Position, std::vector<SingleFStringExpState> > ftripleStateAtEol;
public:
explicit LexerPython() :
DefaultLexer(lexicalClasses, ELEMENTS(lexicalClasses)),
subStyles(styleSubable, 0x80, 0x40, 0) {
}
virtual ~LexerPython() {
~LexerPython() override {
}
void SCI_METHOD Release() override {
delete this;
@ -440,7 +465,7 @@ void LexerPython::ProcessLineEnd(StyleContext &sc, std::vector<SingleFStringExpS
}
}
if (!fstringStateStack.empty()) {
std::pair<int, std::vector<SingleFStringExpState> > val;
std::pair<Sci_Position, std::vector<SingleFStringExpState> > val;
val.first = sc.currentLine;
val.second = fstringStateStack;
@ -503,7 +528,7 @@ void SCI_METHOD LexerPython::Lex(Sci_PositionU startPos, Sci_Position length, in
}
// Set up fstate stack from last line and remove any subsequent ftriple at eol states
std::map<int, std::vector<SingleFStringExpState> >::iterator it;
std::map<Sci_Position, std::vector<SingleFStringExpState> >::iterator it;
it = ftripleStateAtEol.find(lineCurrent - 1);
if (it != ftripleStateAtEol.end() && !it->second.empty()) {
fstringStateStack = it->second;
@ -659,7 +684,7 @@ void SCI_METHOD LexerPython::Lex(Sci_PositionU startPos, Sci_Position length, in
} else if ((sc.state == SCE_P_TRIPLE) || (sc.state == SCE_P_FTRIPLE)) {
if (sc.ch == '\\') {
sc.Forward();
} else if (sc.Match("\'\'\'")) {
} else if (sc.Match(R"(''')")) {
sc.Forward();
sc.Forward();
sc.ForwardSetState(SCE_P_DEFAULT);
@ -668,7 +693,7 @@ void SCI_METHOD LexerPython::Lex(Sci_PositionU startPos, Sci_Position length, in
} else if ((sc.state == SCE_P_TRIPLEDOUBLE) || (sc.state == SCE_P_FTRIPLEDOUBLE)) {
if (sc.ch == '\\') {
sc.Forward();
} else if (sc.Match("\"\"\"")) {
} else if (sc.Match(R"(""")")) {
sc.Forward();
sc.Forward();
sc.ForwardSetState(SCE_P_DEFAULT);
@ -699,7 +724,7 @@ void SCI_METHOD LexerPython::Lex(Sci_PositionU startPos, Sci_Position length, in
if (sc.ch == quote) {
if (IsPySingleQuoteStringState(stack_state)) {
matching_stack_i = stack_i;
} else if (quote == '"' ? sc.Match("\"\"\"") : sc.Match("'''")) {
} else if (quote == '"' ? sc.Match(R"(""")") : sc.Match("'''")) {
matching_stack_i = stack_i;
}
}
@ -812,7 +837,7 @@ static bool IsCommentLine(Sci_Position line, Accessor &styler) {
static bool IsQuoteLine(Sci_Position line, const Accessor &styler) {
const int style = styler.StyleAt(styler.LineStart(line)) & 31;
return ((style == SCE_P_TRIPLE) || (style == SCE_P_TRIPLEDOUBLE));
return IsPyTripleQuoteStringState(style);
}
@ -848,7 +873,7 @@ void SCI_METHOD LexerPython::Fold(Sci_PositionU startPos, Sci_Position length, i
int prev_state = SCE_P_DEFAULT & 31;
if (lineCurrent >= 1)
prev_state = styler.StyleAt(startPos - 1) & 31;
int prevQuote = options.foldQuotes && ((prev_state == SCE_P_TRIPLE) || (prev_state == SCE_P_TRIPLEDOUBLE));
int prevQuote = options.foldQuotes && IsPyTripleQuoteStringState(prev_state);
// Process all characters to end of requested range or end of any triple quote
//that hangs over the end of the range. Cap processing in all cases
@ -865,7 +890,7 @@ void SCI_METHOD LexerPython::Fold(Sci_PositionU startPos, Sci_Position length, i
indentNext = styler.IndentAmount(lineNext, &spaceFlags, NULL);
Sci_Position lookAtPos = (styler.LineStart(lineNext) == styler.Length()) ? styler.Length() - 1 : styler.LineStart(lineNext);
const int style = styler.StyleAt(lookAtPos) & 31;
quote = options.foldQuotes && ((style == SCE_P_TRIPLE) || (style == SCE_P_TRIPLEDOUBLE));
quote = options.foldQuotes && IsPyTripleQuoteStringState(style);
}
const int quote_start = (quote && !prevQuote);
const int quote_continue = (quote && prevQuote);
@ -905,7 +930,7 @@ void SCI_METHOD LexerPython::Fold(Sci_PositionU startPos, Sci_Position length, i
}
const int levelAfterComments = ((lineNext < docLines) ? indentNext & SC_FOLDLEVELNUMBERMASK : minCommentLevel);
const int levelBeforeComments = 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

View File

@ -24,9 +24,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static inline bool IsAWordChar(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');

View File

@ -23,9 +23,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
//XXX Identical to Perl, put in common area
static inline bool isEOLChar(char ch) {
@ -346,7 +344,7 @@ static bool RE_CanFollowKeyword(const char *keyword) {
// Look at chars up to but not including endPos
// Don't look at styles in case we're looking forward
static int skipWhitespace(Sci_Position startPos,
static Sci_Position skipWhitespace(Sci_Position startPos,
Sci_Position endPos,
Accessor &styler) {
for (Sci_Position i = startPos; i < endPos; i++) {

View File

@ -29,10 +29,9 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#include "OptionSet.h"
#include "DefaultLexer.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static const int NUM_RUST_KEYWORD_LISTS = 7;
static const int MAX_RUST_IDENT_CHARS = 1023;
@ -116,7 +115,7 @@ struct OptionSetRust : public OptionSet<OptionsRust> {
}
};
class LexerRust : public ILexer {
class LexerRust : public DefaultLexer {
WordList keywords[NUM_RUST_KEYWORD_LISTS];
OptionsRust options;
OptionSetRust osRust;
@ -213,7 +212,7 @@ static void ScanIdentifier(Accessor& styler, Sci_Position& pos, WordList *keywor
styler.ColourTo(pos - 1, SCE_RUST_MACRO);
} else {
char s[MAX_RUST_IDENT_CHARS + 1];
int len = pos - start;
Sci_Position len = pos - start;
len = len > MAX_RUST_IDENT_CHARS ? MAX_RUST_IDENT_CHARS : len;
GrabString(s, styler, start, len);
bool keyword = false;
@ -271,7 +270,7 @@ static void ScanNumber(Accessor& styler, Sci_Position& pos) {
pos++;
c = styler.SafeGetCharAt(pos, '\0');
n = styler.SafeGetCharAt(pos + 1, '\0');
if (c == '8' || c == 's') {
if (c == '8') {
pos++;
} else if (c == '1' && n == '6') {
pos += 2;
@ -279,6 +278,8 @@ static void ScanNumber(Accessor& styler, Sci_Position& pos) {
pos += 2;
} else if (c == '6' && n == '4') {
pos += 2;
} else if (styler.Match(pos, "size")) {
pos += 4;
} else {
error = true;
}

View File

@ -31,10 +31,9 @@
#include "LexerModule.h"
#include "OptionSet.h"
#include "SparseState.h"
#include "DefaultLexer.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static inline bool IsAWordChar(int ch, bool sqlAllowDottedWord) {
if (!sqlAllowDottedWord)
@ -302,7 +301,7 @@ struct OptionSetSQL : public OptionSet<OptionsSQL> {
}
};
class LexerSQL : public ILexer {
class LexerSQL : public DefaultLexer {
public :
LexerSQL() {}
@ -546,7 +545,7 @@ void SCI_METHOD LexerSQL::Lex(Sci_PositionU startPos, Sci_Position length, int i
}
break;
case SCE_SQL_STRING:
if (sc.ch == '\\') {
if (options.sqlBackslashEscapes && sc.ch == '\\') {
// Escape sequence
sc.Forward();
} else if (sc.ch == '\"') {

View File

@ -23,9 +23,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
// Extended to accept accented characters
static inline bool IsAWordChar(int ch) {
@ -314,6 +312,7 @@ next:
break;
case '[':
expected = true;
// Falls through.
case ']':
case '(':
case ')':

View File

@ -34,9 +34,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif

View File

@ -28,9 +28,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static void ColouriseVHDLDoc(
Sci_PositionU startPos,
@ -74,8 +72,9 @@ static void ColouriseVHDLDoc(
StyleContext sc(startPos, length, initStyle, styler);
bool isExtendedId = false; // true when parsing an extended identifier
for (; sc.More(); sc.Forward())
while (sc.More())
{
bool advance = true;
// Determine if the current state should terminate.
if (sc.state == SCE_VHDL_OPERATOR) {
@ -108,24 +107,28 @@ static void ColouriseVHDLDoc(
// extended identifiers are terminated by backslash, check for end of line in case we have invalid syntax
isExtendedId = false;
sc.ForwardSetState(SCE_VHDL_DEFAULT);
advance = false;
}
} else if (sc.state == SCE_VHDL_COMMENT || sc.state == SCE_VHDL_COMMENTLINEBANG) {
if (sc.atLineEnd) {
sc.SetState(SCE_VHDL_DEFAULT);
}
} else if (sc.state == SCE_VHDL_STRING) {
if (sc.ch == '\\') {
if (sc.chNext == '\"' || sc.chNext == '\'' || sc.chNext == '\\') {
if (sc.ch == '"') {
advance = false;
sc.Forward();
}
} else if (sc.ch == '\"') {
sc.ForwardSetState(SCE_VHDL_DEFAULT);
if (sc.ch == '"')
sc.Forward();
else
sc.SetState(SCE_VHDL_DEFAULT);
} else if (sc.atLineEnd) {
advance = false;
sc.ChangeState(SCE_VHDL_STRINGEOL);
sc.ForwardSetState(SCE_VHDL_DEFAULT);
}
} else if (sc.state == SCE_VHDL_BLOCK_COMMENT){
if(sc.ch == '*' && sc.chNext == '/'){
advance = false;
sc.Forward();
sc.ForwardSetState(SCE_VHDL_DEFAULT);
}
@ -144,8 +147,19 @@ static void ColouriseVHDLDoc(
sc.SetState(SCE_VHDL_COMMENT);
} else if (sc.Match('/', '*')){
sc.SetState(SCE_VHDL_BLOCK_COMMENT);
} else if (sc.ch == '\"') {
} else if (sc.ch == '"') {
sc.SetState(SCE_VHDL_STRING);
} else if (sc.ch == '\'') {
if (sc.GetRelative(2) == '\''){
if (sc.chNext != '(' || sc.GetRelative(4) != '\''){
// Can only be a character literal
sc.SetState(SCE_VHDL_STRING);
sc.Forward();
sc.Forward();
sc.ForwardSetState(SCE_VHDL_DEFAULT);
advance = false;
} // else can be a tick or a character literal, need more context, eg.: identifier'('x')
} // else can only be a tick
} else if (sc.ch == '\\') {
isExtendedId = true;
sc.SetState(SCE_VHDL_IDENTIFIER);
@ -153,6 +167,9 @@ static void ColouriseVHDLDoc(
sc.SetState(SCE_VHDL_OPERATOR);
}
}
if (advance)
sc.Forward();
}
sc.Complete();
}

View File

@ -31,10 +31,9 @@
#include "OptionSet.h"
#include "SubStyles.h"
#include "DefaultLexer.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
namespace {
// Use an unnamed namespace to protect the functions and classes from name conflicts
@ -172,7 +171,7 @@ const char styleSubable[] = {0};
}
class LexerVerilog : public ILexerWithSubStyles {
class LexerVerilog : public DefaultLexer {
CharacterSet setWord;
WordList keywords;
WordList keywords2;

View File

@ -23,9 +23,7 @@
#include "CharacterSet.h"
#include "LexerModule.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static const char * const yamlWordListDesc[] = {
"Keywords",

View File

@ -17,9 +17,7 @@
#include "LexAccessor.h"
#include "Accessor.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
Accessor::Accessor(IDocument *pAccess_, PropSetSimple *pprops_) : LexAccessor(pAccess_), pprops(pprops_) {
}

View File

@ -8,9 +8,7 @@
#ifndef ACCESSOR_H
#define ACCESSOR_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
enum { wsSpace=1, wsTab=2, wsSpaceTab=4, wsInconsistent=8 };
@ -28,8 +26,6 @@ public:
int IndentAmount(Sci_Position line, int *flags, PFNIsCommentLeader pfnIsCommentLeader = 0);
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -8,13 +8,11 @@
// The License.txt file describes the conditions under which this software may be distributed.
#include <algorithm>
#include <iterator>
#include "StringCopy.h"
#include "CharacterCategory.h"
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
namespace {
// Use an unnamed namespace to protect the declarations from name conflicts
@ -3681,7 +3679,6 @@ const int catRanges[] = {
const int maxUnicode = 0x10ffff;
const int maskCategory = 0x1F;
const int nRanges = ELEMENTS(catRanges);
}
@ -3700,7 +3697,7 @@ CharacterCategory CategoriseCharacter(int character) {
if (character < 0 || character > maxUnicode)
return ccCn;
const int baseValue = character * (maskCategory+1) + maskCategory;
const int *placeAfter = std::lower_bound(catRanges, catRanges+nRanges, baseValue);
const int *placeAfter = std::lower_bound(catRanges, std::end(catRanges), baseValue);
return static_cast<CharacterCategory>(*(placeAfter-1) & maskCategory);
}
@ -3850,6 +3847,4 @@ bool IsXidContinue(int character) {
}
}
#ifdef SCI_NAMESPACE
}
#endif

View File

@ -8,9 +8,7 @@
#ifndef CHARACTERCATEGORY_H
#define CHARACTERCATEGORY_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
enum CharacterCategory {
ccLu, ccLl, ccLt, ccLm, ccLo,
@ -30,8 +28,6 @@ bool IsIdContinue(int character);
bool IsXidStart(int character);
bool IsXidContinue(int character);
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -11,19 +11,15 @@
#include "CharacterSet.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
int CompareCaseInsensitive(const char *a, const char *b) {
while (*a && *b) {
if (*a != *b) {
const char upperA = static_cast<char>(MakeUpperCase(*a));
const char upperB = static_cast<char>(MakeUpperCase(*b));
const char upperA = MakeUpperCase(*a);
const char upperB = MakeUpperCase(*b);
if (upperA != upperB)
return upperA - upperB;
}
@ -37,8 +33,8 @@ int CompareCaseInsensitive(const char *a, const char *b) {
int CompareNCaseInsensitive(const char *a, const char *b, size_t len) {
while (*a && *b && len) {
if (*a != *b) {
const char upperA = static_cast<char>(MakeUpperCase(*a));
const char upperB = static_cast<char>(MakeUpperCase(*b));
const char upperA = MakeUpperCase(*a);
const char upperB = MakeUpperCase(*b);
if (upperA != upperB)
return upperA - upperB;
}
@ -53,6 +49,4 @@ int CompareNCaseInsensitive(const char *a, const char *b, size_t len) {
return *a - *b;
}
#ifdef SCI_NAMESPACE
}
#endif

View File

@ -8,9 +8,7 @@
#ifndef CHARACTERSET_H
#define CHARACTERSET_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
class CharacterSet {
int size;
@ -61,7 +59,7 @@ public:
}
~CharacterSet() {
delete []bset;
bset = 0;
bset = nullptr;
size = 0;
}
CharacterSet &operator=(const CharacterSet &other) {
@ -169,16 +167,18 @@ inline bool isoperator(int ch) {
return false;
}
// Simple case functions for ASCII.
// Simple case functions for ASCII supersets.
inline int MakeUpperCase(int ch) {
template <typename T>
inline T MakeUpperCase(T ch) {
if (ch < 'a' || ch > 'z')
return ch;
else
return static_cast<char>(ch - 'a' + 'A');
return ch - 'a' + 'A';
}
inline int MakeLowerCase(int ch) {
template <typename T>
inline T MakeLowerCase(T ch) {
if (ch < 'A' || ch > 'Z')
return ch;
else
@ -188,8 +188,6 @@ inline int MakeLowerCase(int ch) {
int CompareCaseInsensitive(const char *a, const char *b);
int CompareNCaseInsensitive(const char *a, const char *b, size_t len);
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -0,0 +1,125 @@
// Scintilla source code edit control
/** @file DefaultLexer.cxx
** A lexer base class that provides reasonable default behaviour.
**/
// Copyright 2017 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <cstdlib>
#include <cassert>
#include <cstring>
#include "ILexer.h"
#include "Scintilla.h"
#include "SciLexer.h"
#include "PropSetSimple.h"
#include "WordList.h"
#include "LexAccessor.h"
#include "Accessor.h"
#include "LexerModule.h"
#include "DefaultLexer.h"
using namespace Scintilla;
static const char styleSubable[] = { 0 };
DefaultLexer::DefaultLexer(const LexicalClass *lexClasses_, size_t nClasses_) :
lexClasses(lexClasses_), nClasses(nClasses_) {
}
DefaultLexer::~DefaultLexer() {
}
void SCI_METHOD DefaultLexer::Release() {
delete this;
}
int SCI_METHOD DefaultLexer::Version() const {
return lvMetaData;
}
const char * SCI_METHOD DefaultLexer::PropertyNames() {
return "";
}
int SCI_METHOD DefaultLexer::PropertyType(const char *) {
return SC_TYPE_BOOLEAN;
}
const char * SCI_METHOD DefaultLexer::DescribeProperty(const char *) {
return "";
}
Sci_Position SCI_METHOD DefaultLexer::PropertySet(const char *, const char *) {
return -1;
}
const char * SCI_METHOD DefaultLexer::DescribeWordListSets() {
return "";
}
Sci_Position SCI_METHOD DefaultLexer::WordListSet(int, const char *) {
return -1;
}
void SCI_METHOD DefaultLexer::Fold(Sci_PositionU, Sci_Position, int, IDocument *) {
}
void * SCI_METHOD DefaultLexer::PrivateCall(int, void *) {
return nullptr;
}
int SCI_METHOD DefaultLexer::LineEndTypesSupported() {
return SC_LINE_END_TYPE_DEFAULT;
}
int SCI_METHOD DefaultLexer::AllocateSubStyles(int, int) {
return -1;
}
int SCI_METHOD DefaultLexer::SubStylesStart(int) {
return -1;
}
int SCI_METHOD DefaultLexer::SubStylesLength(int) {
return 0;
}
int SCI_METHOD DefaultLexer::StyleFromSubStyle(int subStyle) {
return subStyle;
}
int SCI_METHOD DefaultLexer::PrimaryStyleFromStyle(int style) {
return style;
}
void SCI_METHOD DefaultLexer::FreeSubStyles() {
}
void SCI_METHOD DefaultLexer::SetIdentifiers(int, const char *) {
}
int SCI_METHOD DefaultLexer::DistanceToSecondaryStyles() {
return 0;
}
const char * SCI_METHOD DefaultLexer::GetSubStyleBases() {
return styleSubable;
}
int SCI_METHOD DefaultLexer::NamedStyles() {
return static_cast<int>(nClasses);
}
const char * SCI_METHOD DefaultLexer::NameOfStyle(int style) {
return (style < NamedStyles()) ? lexClasses[style].name : "";
}
const char * SCI_METHOD DefaultLexer::TagsOfStyle(int style) {
return (style < NamedStyles()) ? lexClasses[style].tags : "";
}
const char * SCI_METHOD DefaultLexer::DescriptionOfStyle(int style) {
return (style < NamedStyles()) ? lexClasses[style].description : "";
}

View File

@ -0,0 +1,51 @@
// Scintilla source code edit control
/** @file DefaultLexer.h
** A lexer base class with default empty implementations of methods.
** For lexers that do not support all features so do not need real implementations.
** Does have real implementation for style metadata.
**/
// Copyright 2017 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#ifndef DEFAULTLEXER_H
#define DEFAULTLEXER_H
namespace Scintilla {
// A simple lexer with no state
class DefaultLexer : public ILexerWithMetaData {
const LexicalClass *lexClasses;
size_t nClasses;
public:
DefaultLexer(const LexicalClass *lexClasses_ = nullptr, size_t nClasses_ = 0);
virtual ~DefaultLexer();
void SCI_METHOD Release() override;
int SCI_METHOD Version() const override;
const char * SCI_METHOD PropertyNames() override;
int SCI_METHOD PropertyType(const char *name) override;
const char * SCI_METHOD DescribeProperty(const char *name) override;
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override;
const char * SCI_METHOD DescribeWordListSets() override;
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override;
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override = 0;
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override;
void * SCI_METHOD PrivateCall(int operation, void *pointer) override;
int SCI_METHOD LineEndTypesSupported() override;
int SCI_METHOD AllocateSubStyles(int styleBase, int numberStyles) override;
int SCI_METHOD SubStylesStart(int styleBase) override;
int SCI_METHOD SubStylesLength(int styleBase) override;
int SCI_METHOD StyleFromSubStyle(int subStyle) override;
int SCI_METHOD PrimaryStyleFromStyle(int style) override;
void SCI_METHOD FreeSubStyles() override;
void SCI_METHOD SetIdentifiers(int style, const char *identifiers) override;
int SCI_METHOD DistanceToSecondaryStyles() override;
const char * SCI_METHOD GetSubStyleBases() override;
int SCI_METHOD NamedStyles() override;
const char * SCI_METHOD NameOfStyle(int style) override;
const char * SCI_METHOD TagsOfStyle(int style) override;
const char * SCI_METHOD DescriptionOfStyle(int style) override;
};
}
#endif

View File

@ -8,9 +8,7 @@
#ifndef LEXACCESSOR_H
#define LEXACCESSOR_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
enum EncodingType { enc8bit, encUnicode, encDBCS };
@ -111,7 +109,7 @@ public:
return true;
}
char StyleAt(Sci_Position position) const {
return static_cast<char>(pAccess->StyleAt(position));
return pAccess->StyleAt(position);
}
Sci_Position GetLine(Sci_Position position) const {
return pAccess->LineFromPosition(position);
@ -172,13 +170,14 @@ public:
if (validLen + (pos - startSeg + 1) >= bufferSize)
Flush();
const char attr = static_cast<char>(chAttr);
if (validLen + (pos - startSeg + 1) >= bufferSize) {
// Too big for buffer so send directly
pAccess->SetStyleFor(pos - startSeg + 1, static_cast<char>(chAttr));
pAccess->SetStyleFor(pos - startSeg + 1, attr);
} else {
for (Sci_PositionU i = startSeg; i <= pos; i++) {
assert((startPosStyling + validLen) < Length());
styleBuf[validLen++] = static_cast<char>(chAttr);
styleBuf[validLen++] = attr;
}
}
}
@ -197,8 +196,13 @@ public:
}
};
#ifdef SCI_NAMESPACE
struct LexicalClass {
int value;
const char *name;
const char *tags;
const char *description;
};
}
#endif
#endif

View File

@ -20,11 +20,12 @@
#include "LexerModule.h"
#include "LexerBase.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
LexerBase::LexerBase() {
static const char styleSubable[] = { 0 };
LexerBase::LexerBase(const LexicalClass *lexClasses_, size_t nClasses_) :
lexClasses(lexClasses_), nClasses(nClasses_) {
for (int wl = 0; wl < numWordLists; wl++)
keyWordLists[wl] = new WordList;
keyWordLists[numWordLists] = 0;
@ -43,7 +44,7 @@ void SCI_METHOD LexerBase::Release() {
}
int SCI_METHOD LexerBase::Version() const {
return lvOriginal;
return lvMetaData;
}
const char * SCI_METHOD LexerBase::PropertyNames() {
@ -61,7 +62,7 @@ const char * SCI_METHOD LexerBase::DescribeProperty(const char *) {
Sci_Position SCI_METHOD LexerBase::PropertySet(const char *key, const char *val) {
const char *valOld = props.Get(key);
if (strcmp(val, valOld) != 0) {
props.Set(key, val);
props.Set(key, val, strlen(key), strlen(val));
return 0;
} else {
return -1;
@ -85,5 +86,59 @@ Sci_Position SCI_METHOD LexerBase::WordListSet(int n, const char *wl) {
}
void * SCI_METHOD LexerBase::PrivateCall(int, void *) {
return nullptr;
}
int SCI_METHOD LexerBase::LineEndTypesSupported() {
return SC_LINE_END_TYPE_DEFAULT;
}
int SCI_METHOD LexerBase::AllocateSubStyles(int, int) {
return -1;
}
int SCI_METHOD LexerBase::SubStylesStart(int) {
return -1;
}
int SCI_METHOD LexerBase::SubStylesLength(int) {
return 0;
}
int SCI_METHOD LexerBase::StyleFromSubStyle(int subStyle) {
return subStyle;
}
int SCI_METHOD LexerBase::PrimaryStyleFromStyle(int style) {
return style;
}
void SCI_METHOD LexerBase::FreeSubStyles() {
}
void SCI_METHOD LexerBase::SetIdentifiers(int, const char *) {
}
int SCI_METHOD LexerBase::DistanceToSecondaryStyles() {
return 0;
}
const char * SCI_METHOD LexerBase::GetSubStyleBases() {
return styleSubable;
}
int SCI_METHOD LexerBase::NamedStyles() {
return static_cast<int>(nClasses);
}
const char * SCI_METHOD LexerBase::NameOfStyle(int style) {
return (style < NamedStyles()) ? lexClasses[style].name : "";
}
const char * SCI_METHOD LexerBase::TagsOfStyle(int style) {
return (style < NamedStyles()) ? lexClasses[style].tags : "";
}
const char * SCI_METHOD LexerBase::DescriptionOfStyle(int style) {
return (style < NamedStyles()) ? lexClasses[style].description : "";
}

View File

@ -8,34 +8,46 @@
#ifndef LEXERBASE_H
#define LEXERBASE_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
// A simple lexer with no state
class LexerBase : public ILexer {
class LexerBase : public ILexerWithMetaData {
protected:
const LexicalClass *lexClasses;
size_t nClasses;
PropSetSimple props;
enum {numWordLists=KEYWORDSET_MAX+1};
WordList *keyWordLists[numWordLists+1];
public:
LexerBase();
LexerBase(const LexicalClass *lexClasses_=nullptr, size_t nClasses_=0);
virtual ~LexerBase();
void SCI_METHOD Release();
int SCI_METHOD Version() const;
const char * SCI_METHOD PropertyNames();
int SCI_METHOD PropertyType(const char *name);
const char * SCI_METHOD DescribeProperty(const char *name);
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val);
const char * SCI_METHOD DescribeWordListSets();
Sci_Position SCI_METHOD WordListSet(int n, const char *wl);
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) = 0;
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) = 0;
void * SCI_METHOD PrivateCall(int operation, void *pointer);
void SCI_METHOD Release() override;
int SCI_METHOD Version() const override;
const char * SCI_METHOD PropertyNames() override;
int SCI_METHOD PropertyType(const char *name) override;
const char * SCI_METHOD DescribeProperty(const char *name) override;
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override;
const char * SCI_METHOD DescribeWordListSets() override;
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override;
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override = 0;
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override = 0;
void * SCI_METHOD PrivateCall(int operation, void *pointer) override;
int SCI_METHOD LineEndTypesSupported() override;
int SCI_METHOD AllocateSubStyles(int styleBase, int numberStyles) override;
int SCI_METHOD SubStylesStart(int styleBase) override;
int SCI_METHOD SubStylesLength(int styleBase) override;
int SCI_METHOD StyleFromSubStyle(int subStyle) override;
int SCI_METHOD PrimaryStyleFromStyle(int style) override;
void SCI_METHOD FreeSubStyles() override;
void SCI_METHOD SetIdentifiers(int style, const char *identifiers) override;
int SCI_METHOD DistanceToSecondaryStyles() override;
const char * SCI_METHOD GetSubStyleBases() override;
int SCI_METHOD NamedStyles() override;
const char * SCI_METHOD NameOfStyle(int style) override;
const char * SCI_METHOD TagsOfStyle(int style) override;
const char * SCI_METHOD DescriptionOfStyle(int style) override;
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -22,20 +22,22 @@
#include "LexerBase.h"
#include "LexerSimple.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
LexerModule::LexerModule(int language_,
LexerFunction fnLexer_,
const char *languageName_,
LexerFunction fnFolder_,
const char *const wordListDescriptions_[]) :
const char *const wordListDescriptions_[],
const LexicalClass *lexClasses_,
size_t nClasses_) :
language(language_),
fnLexer(fnLexer_),
fnFolder(fnFolder_),
fnFactory(0),
fnFactory(nullptr),
wordListDescriptions(wordListDescriptions_),
lexClasses(lexClasses_),
nClasses(nClasses_),
languageName(languageName_) {
}
@ -44,15 +46,24 @@ LexerModule::LexerModule(int language_,
const char *languageName_,
const char * const wordListDescriptions_[]) :
language(language_),
fnLexer(0),
fnFolder(0),
fnLexer(nullptr),
fnFolder(nullptr),
fnFactory(fnFactory_),
wordListDescriptions(wordListDescriptions_),
lexClasses(nullptr),
nClasses(0),
languageName(languageName_) {
}
LexerModule::~LexerModule() {
}
int LexerModule::GetLanguage() const {
return language;
}
int LexerModule::GetNumWordLists() const {
if (wordListDescriptions == NULL) {
if (!wordListDescriptions) {
return -1;
} else {
int numWordLists = 0;
@ -74,6 +85,14 @@ const char *LexerModule::GetWordListDescription(int index) const {
}
}
const LexicalClass *LexerModule::LexClasses() const {
return lexClasses;
}
size_t LexerModule::NamedStyles() const {
return nClasses;
}
ILexer *LexerModule::Create() const {
if (fnFactory)
return fnFactory();
@ -94,7 +113,7 @@ void LexerModule::Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initS
// Move back one line in case deletion wrecked current line fold state
if (lineCurrent > 0) {
lineCurrent--;
Sci_Position newStartPos = styler.LineStart(lineCurrent);
const Sci_Position newStartPos = styler.LineStart(lineCurrent);
lengthDoc += startPos - newStartPos;
startPos = newStartPos;
initStyle = 0;

View File

@ -8,12 +8,11 @@
#ifndef LEXERMODULE_H
#define LEXERMODULE_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
class Accessor;
class WordList;
struct LexicalClass;
typedef void (*LexerFunction)(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
WordList *keywordlists[], Accessor &styler);
@ -21,8 +20,9 @@ typedef ILexer *(*LexerFactoryFunction)();
/**
* A LexerModule is responsible for lexing and folding a particular language.
* The class maintains a list of LexerModules which can be searched to find a
* The Catalogue class maintains a list of LexerModules which can be searched to find a
* module appropriate to a particular language.
* The ExternalLexerModule subclass holds lexers loaded from DLLs or shared libraries.
*/
class LexerModule {
protected:
@ -31,25 +31,32 @@ protected:
LexerFunction fnFolder;
LexerFactoryFunction fnFactory;
const char * const * wordListDescriptions;
const LexicalClass *lexClasses;
size_t nClasses;
public:
const char *languageName;
LexerModule(int language_,
LexerModule(
int language_,
LexerFunction fnLexer_,
const char *languageName_=0,
LexerFunction fnFolder_=0,
const char * const wordListDescriptions_[] = NULL);
LexerModule(int language_,
const char *languageName_=nullptr,
LexerFunction fnFolder_= nullptr,
const char * const wordListDescriptions_[]=nullptr,
const LexicalClass *lexClasses_=nullptr,
size_t nClasses_=0);
LexerModule(
int language_,
LexerFactoryFunction fnFactory_,
const char *languageName_,
const char * const wordListDescriptions_[] = NULL);
virtual ~LexerModule() {
}
int GetLanguage() const { return language; }
const char * const wordListDescriptions_[]=nullptr);
virtual ~LexerModule();
int GetLanguage() const;
// -1 is returned if no WordList information is available
int GetNumWordLists() const;
const char *GetWordListDescription(int index) const;
const LexicalClass *LexClasses() const;
size_t NamedStyles() const;
ILexer *Create() const;
@ -75,8 +82,6 @@ inline int Maximum(int a, int b) {
#pragma GCC diagnostic ignored "-Wshadow"
#endif
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -20,9 +20,7 @@
#include "LexerBase.h"
#include "LexerNoExceptions.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
Sci_Position SCI_METHOD LexerNoExceptions::PropertySet(const char *key, const char *val) {
try {

View File

@ -8,25 +8,21 @@
#ifndef LEXERNOEXCEPTIONS_H
#define LEXERNOEXCEPTIONS_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
// A simple lexer with no state
class LexerNoExceptions : public LexerBase {
public:
// TODO Also need to prevent exceptions in constructor and destructor
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val);
Sci_Position SCI_METHOD WordListSet(int n, const char *wl);
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess);
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *);
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override;
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override;
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override;
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *) override;
virtual void Lexer(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess, Accessor &styler) = 0;
virtual void Folder(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess, Accessor &styler) = 0;
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -22,11 +22,11 @@
#include "LexerBase.h"
#include "LexerSimple.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
LexerSimple::LexerSimple(const LexerModule *module_) : module(module_) {
LexerSimple::LexerSimple(const LexerModule *module_) :
LexerBase(module_->LexClasses(), module_->NamedStyles()),
module(module_) {
for (int wl = 0; wl < module->GetNumWordLists(); wl++) {
if (!wordLists.empty())
wordLists += "\n";

View File

@ -8,9 +8,7 @@
#ifndef LEXERSIMPLE_H
#define LEXERSIMPLE_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
// A simple lexer with no state
class LexerSimple : public LexerBase {
@ -18,13 +16,11 @@ class LexerSimple : public LexerBase {
std::string wordLists;
public:
explicit LexerSimple(const LexerModule *module_);
const char * SCI_METHOD DescribeWordListSets();
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess);
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess);
const char * SCI_METHOD DescribeWordListSets() override;
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override;
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override;
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -10,9 +10,7 @@
#ifndef OPTIONSET_H
#define OPTIONSET_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
template <typename T>
class OptionSet {
@ -135,8 +133,6 @@ public:
}
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -1,6 +1,6 @@
// SciTE - Scintilla based Text Editor
// Scintilla source code edit control
/** @file PropSetSimple.cxx
** A Java style properties file module.
** A basic string to string map.
**/
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
@ -15,31 +15,33 @@
#include "PropSetSimple.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
namespace {
typedef std::map<std::string, std::string> mapss;
mapss *PropsFromPointer(void *impl) {
return static_cast<mapss *>(impl);
}
}
PropSetSimple::PropSetSimple() {
mapss *props = new mapss;
impl = static_cast<void *>(props);
}
PropSetSimple::~PropSetSimple() {
mapss *props = static_cast<mapss *>(impl);
mapss *props = PropsFromPointer(impl);
delete props;
impl = 0;
}
void PropSetSimple::Set(const char *key, const char *val, int lenKey, int lenVal) {
mapss *props = static_cast<mapss *>(impl);
void PropSetSimple::Set(const char *key, const char *val, size_t lenKey, size_t lenVal) {
mapss *props = PropsFromPointer(impl);
if (!*key) // Empty keys are not supported
return;
if (lenKey == -1)
lenKey = static_cast<int>(strlen(key));
if (lenVal == -1)
lenVal = static_cast<int>(strlen(val));
(*props)[std::string(key, lenKey)] = std::string(val, lenVal);
}
@ -55,10 +57,10 @@ void PropSetSimple::Set(const char *keyVal) {
endVal++;
const char *eqAt = strchr(keyVal, '=');
if (eqAt) {
Set(keyVal, eqAt + 1, static_cast<int>(eqAt-keyVal),
static_cast<int>(endVal - eqAt - 1));
Set(keyVal, eqAt + 1, eqAt-keyVal,
endVal - eqAt - 1);
} else if (*keyVal) { // No '=' so assume '=1'
Set(keyVal, "1", static_cast<int>(endVal-keyVal), 1);
Set(keyVal, "1", endVal-keyVal, 1);
}
}
@ -73,7 +75,7 @@ void PropSetSimple::SetMultiple(const char *s) {
}
const char *PropSetSimple::Get(const char *key) const {
mapss *props = static_cast<mapss *>(impl);
mapss *props = PropsFromPointer(impl);
mapss::const_iterator keyPos = props->find(std::string(key));
if (keyPos != props->end()) {
return keyPos->second.c_str();
@ -88,7 +90,7 @@ const char *PropSetSimple::Get(const char *key) const {
// for that, through a recursive function and a simple chain of pointers.
struct VarChain {
VarChain(const char *var_=NULL, const VarChain *link_=NULL): var(var_), link(link_) {}
VarChain(const char *var_=nullptr, const VarChain *link_= nullptr): var(var_), link(link_) {}
bool contains(const char *testVar) const {
return (var && (0 == strcmp(var, testVar)))
@ -102,7 +104,7 @@ struct VarChain {
static int ExpandAllInPlace(const PropSetSimple &props, std::string &withVars, int maxExpands, const VarChain &blankVars) {
size_t varStart = withVars.find("$(");
while ((varStart != std::string::npos) && (maxExpands > 0)) {
size_t varEnd = withVars.find(")", varStart+2);
const size_t varEnd = withVars.find(')', varStart+2);
if (varEnd == std::string::npos) {
break;
}

View File

@ -8,9 +8,7 @@
#ifndef PROPSETSIMPLE_H
#define PROPSETSIMPLE_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
class PropSetSimple {
void *impl;
@ -18,15 +16,13 @@ class PropSetSimple {
public:
PropSetSimple();
virtual ~PropSetSimple();
void Set(const char *key, const char *val, int lenKey=-1, int lenVal=-1);
void Set(const char *key, const char *val, size_t lenKey, size_t lenVal);
void SetMultiple(const char *);
const char *Get(const char *key) const;
int GetExpanded(const char *key, char *result) const;
int GetInt(const char *key, int defaultValue=0) const;
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -10,16 +10,14 @@
#ifndef SPARSESTATE_H
#define SPARSESTATE_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
template <typename T>
class SparseState {
struct State {
int position;
Sci_Position position;
T value;
State(int position_, T value_) : position(position_), value(value_) {
State(Sci_Position position_, T value_) : position(position_), value(value_) {
}
inline bool operator<(const State &other) const {
return position < other.position;
@ -28,26 +26,26 @@ class SparseState {
return (position == other.position) && (value == other.value);
}
};
int positionFirst;
Sci_Position positionFirst;
typedef std::vector<State> stateVector;
stateVector states;
typename stateVector::iterator Find(int position) {
typename stateVector::iterator Find(Sci_Position position) {
State searchValue(position, T());
return std::lower_bound(states.begin(), states.end(), searchValue);
}
public:
explicit SparseState(int positionFirst_=-1) {
explicit SparseState(Sci_Position positionFirst_=-1) {
positionFirst = positionFirst_;
}
void Set(int position, T value) {
void Set(Sci_Position position, T value) {
Delete(position);
if (states.empty() || (value != states[states.size()-1].value)) {
states.push_back(State(position, value));
}
}
T ValueAt(int position) {
T ValueAt(Sci_Position position) {
if (states.empty())
return T();
if (position < states[0].position)
@ -62,7 +60,7 @@ public:
return low->value;
}
}
bool Delete(int position) {
bool Delete(Sci_Position position) {
typename stateVector::iterator low = Find(position);
if (low != states.end()) {
states.erase(low, states.end());
@ -75,7 +73,7 @@ public:
}
// Returns true if Merge caused a significant change
bool Merge(const SparseState<T> &other, int ignoreAfter) {
bool Merge(const SparseState<T> &other, Sci_Position ignoreAfter) {
// Changes caused beyond ignoreAfter are not significant
Delete(ignoreAfter+1);
@ -103,8 +101,6 @@ public:
}
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -9,9 +9,7 @@
#ifndef STRINGCOPY_H
#define STRINGCOPY_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
// Safer version of string copy functions like strcpy, wcsncpy, etc.
// Instantiate over fixed length strings of both char and wchar_t.
@ -29,8 +27,6 @@ void StringCopy(T (&dest)[count], const T* source) {
#define ELEMENTS(a) (sizeof(a) / sizeof(a[0]))
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -16,9 +16,7 @@
#include "StyleContext.h"
#include "CharacterSet.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
bool StyleContext::MatchIgnoreCase(const char *s) {
if (MakeLowerCase(ch) != static_cast<unsigned char>(*s))
@ -28,8 +26,8 @@ bool StyleContext::MatchIgnoreCase(const char *s) {
return false;
s++;
for (int n = 2; *s; n++) {
if (static_cast<unsigned char>(*s) !=
MakeLowerCase(static_cast<unsigned char>(styler.SafeGetCharAt(currentPos + n, 0))))
if (*s !=
MakeLowerCase(styler.SafeGetCharAt(currentPos + n, 0)))
return false;
s++;
}
@ -60,7 +58,7 @@ static void getRangeLowered(Sci_PositionU start,
Sci_PositionU len) {
Sci_PositionU i = 0;
while ((i < end - start + 1) && (i < len-1)) {
s[i] = static_cast<char>(tolower(styler[start + i]));
s[i] = MakeLowerCase(styler[start + i]);
i++;
}
s[i] = '\0';

View File

@ -8,9 +8,7 @@
#ifndef STYLECONTEXT_H
#define STYLECONTEXT_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
// All languages handled so far can treat all characters >= 0x80 as one class
// which just continues the current token or starts an identifier if in default.
@ -59,7 +57,7 @@ public:
StyleContext(Sci_PositionU startPos, Sci_PositionU length,
int initStyle, LexAccessor &styler_, char chMask='\377') :
styler(styler_),
multiByteAccess(0),
multiByteAccess(nullptr),
endPos(startPos + length),
posRelative(0),
currentPosLastRelative(0x7FFFFFFF),
@ -133,7 +131,12 @@ public:
void ForwardBytes(Sci_Position nb) {
const Sci_PositionU forwardPos = currentPos + nb;
while (forwardPos > currentPos) {
const Sci_PositionU currentPosStart = currentPos;
Forward();
if (currentPos == currentPosStart) {
// Reached end
return;
}
}
}
void ChangeState(int state_) {
@ -164,9 +167,9 @@ public:
posRelative = currentPos;
offsetRelative = 0;
}
Sci_Position diffRelative = n - offsetRelative;
Sci_Position posNew = multiByteAccess->GetRelativePosition(posRelative, diffRelative);
const int chReturn = multiByteAccess->GetCharacterAndWidth(posNew, 0);
const Sci_Position diffRelative = n - offsetRelative;
const Sci_Position posNew = multiByteAccess->GetRelativePosition(posRelative, diffRelative);
const int chReturn = multiByteAccess->GetCharacterAndWidth(posNew, nullptr);
posRelative = posNew;
currentPosLastRelative = currentPos;
offsetRelative = n;
@ -204,8 +207,6 @@ public:
void GetCurrentLowered(char *s, Sci_PositionU len);
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -8,9 +8,7 @@
#ifndef SUBSTYLES_H
#define SUBSTYLES_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
class WordClassifier {
int baseStyle;
@ -37,6 +35,10 @@ public:
return firstStyle;
}
int Last() const {
return firstStyle + lenStyles - 1;
}
int Length() const {
return lenStyles;
}
@ -118,11 +120,11 @@ public:
}
int Allocate(int styleBase, int numberStyles) {
int block = BlockFromBaseStyle(styleBase);
const int block = BlockFromBaseStyle(styleBase);
if (block >= 0) {
if ((allocated + numberStyles) > stylesAvailable)
return -1;
int startBlock = styleFirst + allocated;
const int startBlock = styleFirst + allocated;
allocated += numberStyles;
classifiers[block].Allocate(startBlock, numberStyles);
return startBlock;
@ -132,17 +134,17 @@ public:
}
int Start(int styleBase) {
int block = BlockFromBaseStyle(styleBase);
const int block = BlockFromBaseStyle(styleBase);
return (block >= 0) ? classifiers[block].Start() : -1;
}
int Length(int styleBase) {
int block = BlockFromBaseStyle(styleBase);
const int block = BlockFromBaseStyle(styleBase);
return (block >= 0) ? classifiers[block].Length() : 0;
}
int BaseStyle(int subStyle) const {
int block = BlockFromStyle(subStyle);
const int block = BlockFromStyle(subStyle);
if (block >= 0)
return classifiers[block].Base();
else
@ -153,8 +155,26 @@ public:
return secondaryDistance;
}
int FirstAllocated() const {
int start = 257;
for (std::vector<WordClassifier>::const_iterator it = classifiers.begin(); it != classifiers.end(); ++it) {
if (start > it->Start())
start = it->Start();
}
return (start < 256) ? start : -1;
}
int LastAllocated() const {
int last = -1;
for (std::vector<WordClassifier>::const_iterator it = classifiers.begin(); it != classifiers.end(); ++it) {
if (last < it->Last())
last = it->Last();
}
return last;
}
void SetIdentifiers(int style, const char *identifiers) {
int block = BlockFromStyle(style);
const int block = BlockFromStyle(style);
if (block >= 0)
classifiers[block].SetIdentifiers(style, identifiers);
}
@ -171,8 +191,6 @@ public:
}
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -10,13 +10,11 @@
#include <cstring>
#include <algorithm>
#include <iterator>
#include "StringCopy.h"
#include "WordList.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
/**
* Creates an array that points into each word in the string and puts \0 terminators
@ -114,7 +112,7 @@ static int cmpWords(const void *a, const void *b) {
}
static void SortWordList(char **words, unsigned int len) {
qsort(static_cast<void *>(words), len, sizeof(*words), cmpWords);
qsort(words, len, sizeof(*words), cmpWords);
}
#endif
@ -130,7 +128,7 @@ void WordList::Set(const char *s) {
#else
SortWordList(words, len);
#endif
std::fill(starts, starts + ELEMENTS(starts), -1);
std::fill(starts, std::end(starts), -1);
for (int l = len - 1; l >= 0; l--) {
unsigned char indexChar = words[l][0];
starts[indexChar] = l;
@ -148,7 +146,7 @@ bool WordList::InList(const char *s) const {
const unsigned char firstChar = s[0];
int j = starts[firstChar];
if (j >= 0) {
while (static_cast<unsigned char>(words[j][0]) == firstChar) {
while (words[j][0] == firstChar) {
if (s[1] == words[j][1]) {
const char *a = words[j] + 1;
const char *b = s + 1;
@ -190,7 +188,7 @@ bool WordList::InListAbbreviated(const char *s, const char marker) const {
const unsigned char firstChar = s[0];
int j = starts[firstChar];
if (j >= 0) {
while (static_cast<unsigned char>(words[j][0]) == firstChar) {
while (words[j][0] == firstChar) {
bool isSubword = false;
int start = 1;
if (words[j][1] == marker) {
@ -244,7 +242,7 @@ bool WordList::InListAbridged(const char *s, const char marker) const {
const unsigned char firstChar = s[0];
int j = starts[firstChar];
if (j >= 0) {
while (static_cast<unsigned char>(words[j][0]) == firstChar) {
while (words[j][0] == firstChar) {
const char *a = words[j];
const char *b = s;
while (*a && *a == *b) {

View File

@ -8,9 +8,7 @@
#ifndef WORDLIST_H
#define WORDLIST_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
/**
*/
@ -35,8 +33,6 @@ public:
const char *WordAt(int n) const;
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -62,7 +62,7 @@ diff --git scintilla/src/Catalogue.cxx scintilla/src/Catalogue.cxx
index ed47aa8..e58f1ab 100644
--- scintilla/src/Catalogue.cxx
+++ scintilla/src/Catalogue.cxx
@@ -77,123 +77,50 @@ int Scintilla_LinkLexers() {
@@ -77,125 +77,50 @@ int Scintilla_LinkLexers() {
//++Autogenerated -- run scripts/LexGen.py to regenerate
//**\(\tLINK_LEXER(\*);\n\)
@ -125,11 +125,13 @@ index ed47aa8..e58f1ab 100644
- LINK_LEXER(lmLiterateHaskell);
- LINK_LEXER(lmLot);
- LINK_LEXER(lmLout);
- LINK_LEXER(lmLPeg);
LINK_LEXER(lmLua);
- LINK_LEXER(lmMagikSF);
LINK_LEXER(lmMake);
LINK_LEXER(lmMarkdown);
- LINK_LEXER(lmMatlab);
- LINK_LEXER(lmMaxima);
- LINK_LEXER(lmMETAPOST);
- LINK_LEXER(lmMMIXAL);
- LINK_LEXER(lmModula);

View File

@ -5,6 +5,7 @@
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <cstddef>
#include <cstdlib>
#include <cassert>
#include <cstring>
@ -23,9 +24,7 @@
#include "Position.h"
#include "AutoComplete.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
AutoComplete::AutoComplete() :
active(false),
@ -51,12 +50,12 @@ AutoComplete::~AutoComplete() {
}
}
bool AutoComplete::Active() const {
bool AutoComplete::Active() const noexcept {
return active;
}
void AutoComplete::Start(Window &parent, int ctrlID,
Sci::Position position, Point location, int startLen_,
Sci::Position position, Point location, Sci::Position startLen_,
int lineHeight, bool unicodeMode, int technology) {
if (active) {
Cancel();
@ -72,7 +71,7 @@ void AutoComplete::SetStopChars(const char *stopChars_) {
stopChars = stopChars_;
}
bool AutoComplete::IsStopChar(char ch) {
bool AutoComplete::IsStopChar(char ch) const noexcept {
return ch && (stopChars.find(ch) != std::string::npos);
}
@ -80,7 +79,7 @@ void AutoComplete::SetFillUpChars(const char *fillUpChars_) {
fillUpChars = fillUpChars_;
}
bool AutoComplete::IsFillUpChar(char ch) {
bool AutoComplete::IsFillUpChar(char ch) const noexcept {
return ch && (fillUpChars.find(ch) != std::string::npos);
}
@ -88,7 +87,7 @@ void AutoComplete::SetSeparator(char separator_) {
separator = separator_;
}
char AutoComplete::GetSeparator() const {
char AutoComplete::GetSeparator() const noexcept {
return separator;
}
@ -96,7 +95,7 @@ void AutoComplete::SetTypesep(char separator_) {
typesep = separator_;
}
char AutoComplete::GetTypesep() const {
char AutoComplete::GetTypesep() const noexcept {
return typesep;
}
@ -226,7 +225,7 @@ void AutoComplete::Move(int delta) {
}
void AutoComplete::Select(const char *word) {
size_t lenWord = strlen(word);
const size_t lenWord = strlen(word);
int location = -1;
int start = 0; // lower bound of the api array block to search
int end = lb->Length() - 1; // upper bound of the api array block to search

View File

@ -8,9 +8,7 @@
#ifndef AUTOCOMPLETE_H
#define AUTOCOMPLETE_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
/**
*/
@ -29,7 +27,7 @@ public:
bool chooseSingle;
std::unique_ptr<ListBox> lb;
Sci::Position posStart;
int startLen;
Sci::Position startLen;
/// Should autocompletion be canceled if editor's currentPos <= startPos?
bool cancelAtStartPos;
bool autoHide;
@ -47,27 +45,27 @@ public:
~AutoComplete();
/// Is the auto completion list displayed?
bool Active() const;
bool Active() const noexcept;
/// Display the auto completion list positioned to be near a character position
void Start(Window &parent, int ctrlID, Sci::Position position, Point location,
int startLen_, int lineHeight, bool unicodeMode, int technology);
Sci::Position startLen_, int lineHeight, bool unicodeMode, int technology);
/// The stop chars are characters which, when typed, cause the auto completion list to disappear
void SetStopChars(const char *stopChars_);
bool IsStopChar(char ch);
bool IsStopChar(char ch) const noexcept;
/// The fillup chars are characters which, when typed, fill up the selected word
void SetFillUpChars(const char *fillUpChars_);
bool IsFillUpChar(char ch);
bool IsFillUpChar(char ch) const noexcept;
/// The separator character is used when interpreting the list in SetList
void SetSeparator(char separator_);
char GetSeparator() const;
char GetSeparator() const noexcept;
/// The typesep character is used for separating the word from the type
void SetTypesep(char separator_);
char GetTypesep() const;
char GetTypesep() const noexcept;
/// The list string contains a sequence of words separated by the separator character
void SetList(const char *list);
@ -88,8 +86,6 @@ public:
void Select(const char *word);
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -5,12 +5,15 @@
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stdexcept>
#include <string>
#include <vector>
#include <algorithm>
#include <memory>
@ -20,11 +23,10 @@
#include "StringCopy.h"
#include "Position.h"
#include "IntegerRectangle.h"
#include "CallTip.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
CallTip::CallTip() {
wCallTip = 0;
@ -110,7 +112,7 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s,
int startSeg = 0;
int xEnd;
for (int seg = 0; seg<maxEnd; seg++) {
int endSeg = ends[seg];
const int endSeg = ends[seg];
if (endSeg > startSeg) {
if (IsArrowCharacter(s[startSeg])) {
xEnd = x + widthArrow;
@ -123,7 +125,7 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s,
const int centreX = x + widthArrow / 2 - 1;
const int centreY = static_cast<int>(rcClient.top + rcClient.bottom) / 2;
surface->FillRectangle(rcClient, colourBG);
PRectangle rcClientInner(rcClient.left + 1, rcClient.top + 1,
const PRectangle rcClientInner(rcClient.left + 1, rcClient.top + 1,
rcClient.right - 2, rcClient.bottom - 1);
surface->FillRectangle(rcClientInner, colourUnSel);
@ -152,7 +154,7 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s,
} else if (IsTabCharacter(s[startSeg])) {
xEnd = NextTabPos(x);
} else {
xEnd = x + RoundXYPosition(surface->WidthText(font, s + startSeg, endSeg - startSeg));
xEnd = x + static_cast<int>(lround(surface->WidthText(font, s + startSeg, endSeg - startSeg)));
if (draw) {
rcClient.left = static_cast<XYPOSITION>(x);
rcClient.right = static_cast<XYPOSITION>(xEnd);
@ -168,13 +170,13 @@ void CallTip::DrawChunk(Surface *surface, int &x, const char *s,
}
int CallTip::PaintContents(Surface *surfaceWindow, bool draw) {
PRectangle rcClientPos = wCallTip.GetClientPosition();
PRectangle rcClientSize(0.0f, 0.0f, rcClientPos.right - rcClientPos.left,
const PRectangle rcClientPos = wCallTip.GetClientPosition();
const PRectangle rcClientSize(0.0f, 0.0f, rcClientPos.right - rcClientPos.left,
rcClientPos.bottom - rcClientPos.top);
PRectangle rcClient(1.0f, 1.0f, rcClientSize.right - 1, rcClientSize.bottom - 1);
// To make a nice small call tip window, it is only sized to fit most normal characters without accents
int ascent = RoundXYPosition(surfaceWindow->Ascent(font) - surfaceWindow->InternalLeading(font));
const int ascent = static_cast<int>(lround(surfaceWindow->Ascent(font) - surfaceWindow->InternalLeading(font)));
// For each line...
// Draw the definition in three parts: before highlight, highlighted, after highlight
@ -186,7 +188,7 @@ int CallTip::PaintContents(Surface *surfaceWindow, bool draw) {
while (moreChunks) {
const char *chunkEnd = strchr(chunkVal, '\n');
if (chunkEnd == NULL) {
if (!chunkEnd) {
chunkEnd = chunkVal + strlen(chunkVal);
moreChunks = false;
}
@ -221,10 +223,10 @@ int CallTip::PaintContents(Surface *surfaceWindow, bool draw) {
void CallTip::PaintCT(Surface *surfaceWindow) {
if (val.empty())
return;
PRectangle rcClientPos = wCallTip.GetClientPosition();
PRectangle rcClientSize(0.0f, 0.0f, rcClientPos.right - rcClientPos.left,
const PRectangle rcClientPos = wCallTip.GetClientPosition();
const PRectangle rcClientSize(0.0f, 0.0f, rcClientPos.right - rcClientPos.left,
rcClientPos.bottom - rcClientPos.top);
PRectangle rcClient(1.0f, 1.0f, rcClientSize.right - 1, rcClientSize.bottom - 1);
const PRectangle rcClient(1.0f, 1.0f, rcClientSize.right - 1, rcClientSize.bottom - 1);
surfaceWindow->FillRectangle(rcClient, colourBG);
@ -234,13 +236,14 @@ void CallTip::PaintCT(Surface *surfaceWindow) {
#ifndef __APPLE__
// OSX doesn't put borders on "help tags"
// Draw a raised border around the edges of the window
surfaceWindow->MoveTo(0, static_cast<int>(rcClientSize.bottom) - 1);
const IntegerRectangle ircClientSize(rcClientSize);
surfaceWindow->MoveTo(0, ircClientSize.bottom - 1);
surfaceWindow->PenColour(colourShade);
surfaceWindow->LineTo(static_cast<int>(rcClientSize.right) - 1, static_cast<int>(rcClientSize.bottom) - 1);
surfaceWindow->LineTo(static_cast<int>(rcClientSize.right) - 1, 0);
surfaceWindow->LineTo(ircClientSize.right - 1, ircClientSize.bottom - 1);
surfaceWindow->LineTo(ircClientSize.right - 1, 0);
surfaceWindow->PenColour(colourLight);
surfaceWindow->LineTo(0, 0);
surfaceWindow->LineTo(0, static_cast<int>(rcClientSize.bottom) - 1);
surfaceWindow->LineTo(0, ircClientSize.bottom - 1);
#endif
}
@ -255,7 +258,7 @@ void CallTip::MouseClick(Point pt) {
PRectangle CallTip::CallTipStart(Sci::Position pos, Point pt, int textHeight, const char *defn,
const char *faceName, int size,
int codePage_, int characterSet,
int technology, Window &wParent) {
int technology, const Window &wParent) {
clickPlace = 0;
val = defn;
codePage = codePage_;
@ -267,28 +270,22 @@ PRectangle CallTip::CallTipStart(Sci::Position pos, Point pt, int textHeight, co
endHighlight = 0;
inCallTipMode = true;
posStartCallTip = pos;
XYPOSITION deviceHeight = static_cast<XYPOSITION>(surfaceMeasure->DeviceHeightFont(size));
FontParameters fp(faceName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, SC_WEIGHT_NORMAL, false, 0, technology, characterSet);
const XYPOSITION deviceHeight = static_cast<XYPOSITION>(surfaceMeasure->DeviceHeightFont(size));
const FontParameters fp(faceName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, SC_WEIGHT_NORMAL, false, 0, technology, characterSet);
font.Create(fp);
// Look for multiple lines in the text
// Only support \n here - simply means container must avoid \r!
int numLines = 1;
const char *newline;
const char *look = val.c_str();
const int numLines = 1 + static_cast<int>(std::count(val.begin(), val.end(), '\n'));
rectUp = PRectangle(0,0,0,0);
rectDown = PRectangle(0,0,0,0);
offsetMain = insetX; // changed to right edge of any arrows
const int width = PaintContents(surfaceMeasure.get(), false) + insetX;
while ((newline = strchr(look, '\n')) != NULL) {
look = newline + 1;
numLines++;
}
lineHeight = RoundXYPosition(surfaceMeasure->Height(font));
lineHeight = static_cast<int>(lround(surfaceMeasure->Height(font)));
// The returned
// rectangle is aligned to the right edge of the last arrow encountered in
// the tip text, else to the tip text left edge.
int height = lineHeight * numLines - static_cast<int>(surfaceMeasure->InternalLeading(font)) + borderHeight * 2;
const int height = lineHeight * numLines - static_cast<int>(surfaceMeasure->InternalLeading(font)) + borderHeight * 2;
if (above) {
return PRectangle(pt.x - offsetMain, pt.y - verticalOffset - height, pt.x + width - offsetMain, pt.y - verticalOffset);
} else {

View File

@ -8,9 +8,7 @@
#ifndef CALLTIP_H
#define CALLTIP_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
/**
*/
@ -55,7 +53,9 @@ public:
CallTip();
// Deleted so CallTip objects can not be copied.
CallTip(const CallTip &) = delete;
CallTip(CallTip &&) = delete;
CallTip &operator=(const CallTip &) = delete;
CallTip &operator=(CallTip &&) = delete;
~CallTip();
void PaintCT(Surface *surfaceWindow);
@ -65,7 +65,7 @@ public:
/// Setup the calltip and return a rectangle of the area required.
PRectangle CallTipStart(Sci::Position pos, Point pt, int textHeight, const char *defn,
const char *faceName, int size, int codePage_,
int characterSet, int technology, Window &wParent);
int characterSet, int technology, const Window &wParent);
void CallTipCancel();
@ -86,8 +86,6 @@ public:
void SetForeBack(const ColourDesired &fore, const ColourDesired &back);
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -18,11 +18,8 @@
#include "StringCopy.h"
#include "CaseConvert.h"
#include "UniConversion.h"
#include "UnicodeFromUTF8.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
namespace {
// Use an unnamed namespace to protect the declarations from name conflicts
@ -566,8 +563,7 @@ class CaseConverter : public ICaseConverter {
enum { maxConversionLength=6 };
struct ConversionString {
char conversion[maxConversionLength+1];
ConversionString() {
conversion[0] = '\0';
ConversionString() : conversion{} {
}
};
// Conversions are initially store in a vector of structs but then decomposed into
@ -575,10 +571,10 @@ class CaseConverter : public ICaseConverter {
struct CharacterConversion {
int character;
ConversionString conversion;
CharacterConversion(int character_=0, const char *conversion_="") : character(character_) {
CharacterConversion(int character_=0, const char *conversion_="") noexcept : character(character_) {
StringCopy(conversion.conversion, conversion_);
}
bool operator<(const CharacterConversion &other) const {
bool operator<(const CharacterConversion &other) const noexcept {
return character < other.character;
}
};
@ -591,11 +587,12 @@ class CaseConverter : public ICaseConverter {
public:
CaseConverter() {
}
virtual ~CaseConverter() = default;
bool Initialised() const {
return characters.size() > 0;
}
void Add(int character, const char *conversion) {
characterToConversion.push_back(CharacterConversion(character, conversion));
characterToConversion.emplace_back(character, conversion);
}
const char *Find(int character) {
const std::vector<int>::iterator it = std::lower_bound(characters.begin(), characters.end(), character);
@ -609,9 +606,9 @@ public:
size_t CaseConvertString(char *converted, size_t sizeConverted, const char *mixed, size_t lenMixed) override {
size_t lenConverted = 0;
size_t mixedPos = 0;
unsigned char bytes[UTF8MaxBytes + 1];
unsigned char bytes[UTF8MaxBytes + 1]{};
while (mixedPos < lenMixed) {
const unsigned char leadByte = static_cast<unsigned char>(mixed[mixedPos]);
const unsigned char leadByte = mixed[mixedPos];
const char *caseConverted = 0;
size_t lenMixedChar = 1;
if (UTF8IsAscii(leadByte)) {
@ -622,11 +619,11 @@ public:
for (int b=1; b<widthCharBytes; b++) {
bytes[b] = (mixedPos+b < lenMixed) ? mixed[mixedPos+b] : 0;
}
int classified = UTF8Classify(bytes, widthCharBytes);
const int classified = UTF8Classify(bytes, widthCharBytes);
if (!(classified & UTF8MaskInvalid)) {
// valid UTF-8
lenMixedChar = classified & UTF8MaskWidth;
int character = UnicodeFromUTF8(bytes);
const int character = UnicodeFromUTF8(bytes);
caseConverted = Find(character);
}
}
@ -666,26 +663,6 @@ CaseConverter caseConvFold;
CaseConverter caseConvUp;
CaseConverter caseConvLow;
void UTF8FromUTF32Character(int uch, char *putf) {
size_t k = 0;
if (uch < 0x80) {
putf[k++] = static_cast<char>(uch);
} else if (uch < 0x800) {
putf[k++] = static_cast<char>(0xC0 | (uch >> 6));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
} else if (uch < 0x10000) {
putf[k++] = static_cast<char>(0xE0 | (uch >> 12));
putf[k++] = static_cast<char>(0x80 | ((uch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
} else {
putf[k++] = static_cast<char>(0xF0 | (uch >> 18));
putf[k++] = static_cast<char>(0x80 | ((uch >> 12) & 0x3f));
putf[k++] = static_cast<char>(0x80 | ((uch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
}
putf[k] = 0;
}
void AddSymmetric(enum CaseConversion conversion, int lower,int upper) {
char lowerUTF8[UTF8MaxBytes+1];
UTF8FromUTF32Character(lower, lowerUTF8);
@ -727,10 +704,10 @@ void SetupConversions(enum CaseConversion conversion) {
while (*sComplex) {
// Longest ligature is 3 character so 5 for safety
const size_t lenUTF8 = 5*UTF8MaxBytes+1;
char originUTF8[lenUTF8];
char foldedUTF8[lenUTF8];
char lowerUTF8[lenUTF8];
char upperUTF8[lenUTF8];
unsigned char originUTF8[lenUTF8]{};
char foldedUTF8[lenUTF8]{};
char lowerUTF8[lenUTF8]{};
char upperUTF8[lenUTF8]{};
size_t i = 0;
while (*sComplex && *sComplex != '|') {
originUTF8[i++] = *sComplex;
@ -760,7 +737,7 @@ void SetupConversions(enum CaseConversion conversion) {
sComplex++;
lowerUTF8[i] = 0;
int character = UnicodeFromUTF8(reinterpret_cast<unsigned char *>(originUTF8));
const int character = UnicodeFromUTF8(originUTF8);
if (conversion == CaseConversionFold && foldedUTF8[0]) {
caseConvFold.Add(character, foldedUTF8);
@ -802,9 +779,7 @@ CaseConverter *ConverterForConversion(enum CaseConversion conversion) {
}
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
ICaseConverter *ConverterFor(enum CaseConversion conversion) {
CaseConverter *pCaseConv = ConverterForConversion(conversion);
@ -829,12 +804,10 @@ size_t CaseConvertString(char *converted, size_t sizeConverted, const char *mixe
std::string CaseConvertString(const std::string &s, enum CaseConversion conversion) {
std::string retMapped(s.length() * maxExpansionCaseConversion, 0);
size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(),
const size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(),
conversion);
retMapped.resize(lenMapped);
return retMapped;
}
#ifdef SCI_NAMESPACE
}
#endif

View File

@ -10,9 +10,7 @@
#ifndef CASECONVERT_H
#define CASECONVERT_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
enum CaseConversion {
CaseConversionFold,
@ -43,8 +41,6 @@ size_t CaseConvertString(char *converted, size_t sizeConverted, const char *mixe
// Converts a mixed case string using a particular conversion.
std::string CaseConvertString(const std::string &s, enum CaseConversion conversion);
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -11,16 +11,13 @@
#include "CaseFolder.h"
#include "CaseConvert.h"
#include "UniConversion.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
CaseFolder::~CaseFolder() {
}
CaseFolderTable::CaseFolderTable() {
CaseFolderTable::CaseFolderTable() : mapping{} {
for (size_t iChar=0; iChar<sizeof(mapping); iChar++) {
mapping[iChar] = static_cast<char>(iChar);
}

View File

@ -8,9 +8,7 @@
#ifndef CASEFOLDER_H
#define CASEFOLDER_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
class CaseFolder {
public:
@ -23,7 +21,7 @@ protected:
char mapping[256];
public:
CaseFolderTable();
virtual ~CaseFolderTable();
~CaseFolderTable() override;
size_t Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) override;
void SetTranslation(char ch, char chTranslation);
void StandardASCII();
@ -38,8 +36,6 @@ public:
size_t Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) override;
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -1,6 +1,8 @@
// Scintilla source code edit control
/** @file Catalogue.cxx
** Colourise for particular languages.
** Lexer infrastructure.
** Contains a list of LexerModules which can be searched to find a module appropriate for a
** particular language.
**/
// Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
@ -19,9 +21,7 @@
#include "LexerModule.h"
#include "Catalogue.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
static std::vector<LexerModule *> lexerCatalogue;
static int nextLanguage = SCLEX_AUTOMATIC+1;

View File

@ -1,6 +1,8 @@
// Scintilla source code edit control
/** @file Catalogue.h
** Lexer infrastructure.
** Contains a list of LexerModules which can be searched to find a module appropriate for a
** particular language.
**/
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
@ -8,9 +10,7 @@
#ifndef CATALOGUE_H
#define CATALOGUE_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
class Catalogue {
public:
@ -19,8 +19,6 @@ public:
static void AddLexerModule(LexerModule *plm);
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

View File

@ -25,56 +25,80 @@
#include "CellBuffer.h"
#include "UniConversion.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
namespace Scintilla {
LineVector::LineVector() : starts(256), perLine(0) {
class ILineVector {
public:
virtual void Init() = 0;
virtual void SetPerLine(PerLine *pl) = 0;
virtual void InsertText(Sci::Line line, Sci::Position delta) = 0;
virtual void InsertLine(Sci::Line line, Sci::Position position, bool lineStart) = 0;
virtual void SetLineStart(Sci::Line line, Sci::Position position) = 0;
virtual void RemoveLine(Sci::Line line) = 0;
virtual Sci::Line Lines() const noexcept = 0;
virtual Sci::Line LineFromPosition(Sci::Position pos) const noexcept = 0;
virtual Sci::Position LineStart(Sci::Line line) const noexcept = 0;
virtual ~ILineVector() {}
};
}
using namespace Scintilla;
template <typename POS>
class LineVector : public ILineVector {
Partitioning<POS> starts;
PerLine *perLine;
public:
LineVector() : starts(256), perLine(0) {
Init();
}
LineVector::~LineVector() {
starts.DeleteAll();
// Deleted so LineVector objects can not be copied.
LineVector(const LineVector &) = delete;
LineVector(LineVector &&) = delete;
LineVector &operator=(const LineVector &) = delete;
LineVector &operator=(LineVector &&) = delete;
~LineVector() override {
}
void LineVector::Init() {
void Init() override {
starts.DeleteAll();
if (perLine) {
perLine->Init();
}
}
void LineVector::SetPerLine(PerLine *pl) {
void SetPerLine(PerLine *pl) override {
perLine = pl;
}
void LineVector::InsertText(Sci::Line line, Sci::Position delta) {
starts.InsertText(line, delta);
void InsertText(Sci::Line line, Sci::Position delta) override {
starts.InsertText(static_cast<POS>(line), static_cast<POS>(delta));
}
void LineVector::InsertLine(Sci::Line line, Sci::Position position, bool lineStart) {
starts.InsertPartition(line, position);
void InsertLine(Sci::Line line, Sci::Position position, bool lineStart) override {
starts.InsertPartition(static_cast<POS>(line), static_cast<POS>(position));
if (perLine) {
if ((line > 0) && lineStart)
line--;
perLine->InsertLine(line);
}
}
void LineVector::SetLineStart(Sci::Line line, Sci::Position position) {
starts.SetPartitionStartPosition(line, position);
void SetLineStart(Sci::Line line, Sci::Position position) override {
starts.SetPartitionStartPosition(static_cast<POS>(line), static_cast<POS>(position));
}
void LineVector::RemoveLine(Sci::Line line) {
starts.RemovePartition(line);
void RemoveLine(Sci::Line line) override {
starts.RemovePartition(static_cast<POS>(line));
if (perLine) {
perLine->RemoveLine(line);
}
}
Sci::Line LineVector::LineFromPosition(Sci::Position pos) const {
return starts.PartitionFromPosition(pos);
Sci::Line Lines() const noexcept override {
return static_cast<Sci::Line>(starts.Partitions());
}
Sci::Line LineFromPosition(Sci::Position pos) const noexcept override {
return static_cast<Sci::Line>(starts.PartitionFromPosition(static_cast<POS>(pos)));
}
Sci::Position LineStart(Sci::Line line) const noexcept override {
return starts.PositionFromPartition(static_cast<POS>(line));
}
};
Action::Action() {
at = startAction;
@ -83,14 +107,6 @@ Action::Action() {
mayCoalesce = false;
}
Action::Action(Action &&other) {
at = other.at;
position = other.position;
data = std::move(other.data);
lenData = other.lenData;
mayCoalesce = other.mayCoalesce;
}
Action::~Action() {
}
@ -344,16 +360,25 @@ void UndoHistory::CompletedRedoStep() {
currentAction++;
}
CellBuffer::CellBuffer() {
CellBuffer::CellBuffer(bool hasStyles_, bool largeDocument_) :
hasStyles(hasStyles_), largeDocument(largeDocument_) {
readOnly = false;
utf8LineEnds = 0;
collectingUndo = true;
if (largeDocument)
plv = std::unique_ptr<LineVector<Sci::Position>>(new LineVector<Sci::Position>());
else
plv = std::unique_ptr<LineVector<int>>(new LineVector<int>());
}
CellBuffer::~CellBuffer() {
}
char CellBuffer::CharAt(Sci::Position position) const {
char CellBuffer::CharAt(Sci::Position position) const noexcept {
return substance.ValueAt(position);
}
unsigned char CellBuffer::UCharAt(Sci::Position position) const noexcept {
return substance.ValueAt(position);
}
@ -370,8 +395,8 @@ void CellBuffer::GetCharRange(char *buffer, Sci::Position position, Sci::Positio
substance.GetRange(buffer, position, lengthRetrieve);
}
char CellBuffer::StyleAt(Sci::Position position) const {
return style.ValueAt(position);
char CellBuffer::StyleAt(Sci::Position position) const noexcept {
return hasStyles ? style.ValueAt(position) : 0;
}
void CellBuffer::GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const {
@ -379,6 +404,10 @@ void CellBuffer::GetStyleRange(unsigned char *buffer, Sci::Position position, Sc
return;
if (position < 0)
return;
if (!hasStyles) {
std::fill(buffer, buffer + lengthRetrieve, static_cast<unsigned char>(0));
return;
}
if ((position + lengthRetrieve) > style.Length()) {
Platform::DebugPrintf("Bad GetStyleRange %d for %d of %d\n", position,
lengthRetrieve, style.Length());
@ -416,6 +445,9 @@ const char *CellBuffer::InsertString(Sci::Position position, const char *s, Sci:
}
bool CellBuffer::SetStyleAt(Sci::Position position, char styleValue) {
if (!hasStyles) {
return false;
}
const char curVal = style.ValueAt(position);
if (curVal != styleValue) {
style.SetValueAt(position, styleValue);
@ -426,6 +458,9 @@ bool CellBuffer::SetStyleAt(Sci::Position position, char styleValue) {
}
bool CellBuffer::SetStyleFor(Sci::Position position, Sci::Position lengthStyle, char styleValue) {
if (!hasStyles) {
return false;
}
bool changed = false;
PLATFORM_ASSERT(lengthStyle == 0 ||
(lengthStyle > 0 && lengthStyle + position <= style.Length()));
@ -458,14 +493,16 @@ const char *CellBuffer::DeleteChars(Sci::Position position, Sci::Position delete
return data;
}
Sci::Position CellBuffer::Length() const {
Sci::Position CellBuffer::Length() const noexcept {
return substance.Length();
}
void CellBuffer::Allocate(Sci::Position newSize) {
substance.ReAllocate(newSize);
if (hasStyles) {
style.ReAllocate(newSize);
}
}
void CellBuffer::SetLineEndTypes(int utf8LineEnds_) {
if (utf8LineEnds != utf8LineEnds_) {
@ -494,20 +531,24 @@ bool CellBuffer::ContainsLineEnd(const char *s, Sci::Position length) const {
}
void CellBuffer::SetPerLine(PerLine *pl) {
lv.SetPerLine(pl);
plv->SetPerLine(pl);
}
Sci::Line CellBuffer::Lines() const {
return lv.Lines();
Sci::Line CellBuffer::Lines() const noexcept {
return plv->Lines();
}
Sci::Position CellBuffer::LineStart(Sci::Line line) const {
Sci::Position CellBuffer::LineStart(Sci::Line line) const noexcept {
if (line < 0)
return 0;
else if (line >= Lines())
return Length();
else
return lv.LineStart(line);
return plv->LineStart(line);
}
Sci::Line CellBuffer::LineFromPosition(Sci::Position pos) const noexcept {
return plv->LineFromPosition(pos);
}
bool CellBuffer::IsReadOnly() const {
@ -518,6 +559,14 @@ void CellBuffer::SetReadOnly(bool set) {
readOnly = set;
}
bool CellBuffer::IsLarge() const {
return largeDocument;
}
bool CellBuffer::HasStyles() const {
return hasStyles;
}
void CellBuffer::SetSavePoint() {
uh.SetSavePoint();
}
@ -545,11 +594,11 @@ bool CellBuffer::TentativeActive() const {
// Without undo
void CellBuffer::InsertLine(Sci::Line line, Sci::Position position, bool lineStart) {
lv.InsertLine(line, position, lineStart);
plv->InsertLine(line, position, lineStart);
}
void CellBuffer::RemoveLine(Sci::Line line) {
lv.RemoveLine(line);
plv->RemoveLine(line);
}
bool CellBuffer::UTF8LineEndOverlaps(Sci::Position position) const {
@ -564,13 +613,13 @@ bool CellBuffer::UTF8LineEndOverlaps(Sci::Position position) const {
void CellBuffer::ResetLineEnds() {
// Reinitialize line data -- too much work to preserve
lv.Init();
plv->Init();
Sci::Position position = 0;
Sci::Position length = Length();
const Sci::Position position = 0;
const Sci::Position length = Length();
Sci::Line lineInsert = 1;
bool atLineStart = true;
lv.InsertText(lineInsert-1, length);
const bool atLineStart = true;
plv->InsertText(lineInsert-1, length);
unsigned char chBeforePrev = 0;
unsigned char chPrev = 0;
for (Sci::Position i = 0; i < length; i++) {
@ -581,7 +630,7 @@ void CellBuffer::ResetLineEnds() {
} else if (ch == '\n') {
if (chPrev == '\r') {
// Patch up what was end of line
lv.SetLineStart(lineInsert - 1, (position + i) + 1);
plv->SetLineStart(lineInsert - 1, (position + i) + 1);
} else {
InsertLine(lineInsert, (position + i) + 1, atLineStart);
lineInsert++;
@ -610,12 +659,14 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P
}
substance.InsertFromArray(position, s, 0, insertLength);
if (hasStyles) {
style.InsertValue(position, insertLength, 0);
}
Sci::Line lineInsert = lv.LineFromPosition(position) + 1;
bool atLineStart = lv.LineStart(lineInsert-1) == position;
Sci::Line lineInsert = plv->LineFromPosition(position) + 1;
const bool atLineStart = plv->LineStart(lineInsert-1) == position;
// Point all the lines after the insertion point further along in the buffer
lv.InsertText(lineInsert-1, insertLength);
plv->InsertText(lineInsert-1, insertLength);
unsigned char chBeforePrev = substance.ValueAt(position - 2);
unsigned char chPrev = substance.ValueAt(position - 1);
if (chPrev == '\r' && chAfter == '\n') {
@ -635,7 +686,7 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P
} else if (ch == '\n') {
if (chPrev == '\r') {
// Patch up what was end of line
lv.SetLineStart(lineInsert - 1, (position + i) + 1);
plv->SetLineStart(lineInsert - 1, (position + i) + 1);
} else {
InsertLine(lineInsert, (position + i) + 1, atLineStart);
lineInsert++;
@ -682,20 +733,20 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe
if ((position == 0) && (deleteLength == substance.Length())) {
// If whole buffer is being deleted, faster to reinitialise lines data
// than to delete each line.
lv.Init();
plv->Init();
} else {
// Have to fix up line positions before doing deletion as looking at text in buffer
// to work out which lines have been removed
Sci::Line lineRemove = lv.LineFromPosition(position) + 1;
lv.InsertText(lineRemove-1, - (deleteLength));
Sci::Line lineRemove = plv->LineFromPosition(position) + 1;
plv->InsertText(lineRemove-1, - (deleteLength));
const unsigned char chPrev = substance.ValueAt(position - 1);
const unsigned char chBefore = chPrev;
unsigned char chNext = substance.ValueAt(position);
bool ignoreNL = false;
if (chPrev == '\r' && chNext == '\n') {
// Move back one
lv.SetLineStart(lineRemove, position);
plv->SetLineStart(lineRemove, position);
lineRemove++;
ignoreNL = true; // First \n is not real deletion
}
@ -736,12 +787,14 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe
if (chBefore == '\r' && chAfter == '\n') {
// Using lineRemove-1 as cr ended line before start of deletion
RemoveLine(lineRemove - 1);
lv.SetLineStart(lineRemove - 1, position + 1);
plv->SetLineStart(lineRemove - 1, position + 1);
}
}
substance.DeleteRange(position, deleteLength);
if (hasStyles) {
style.DeleteRange(position, deleteLength);
}
}
bool CellBuffer::SetUndoCollection(bool collectUndo) {
collectingUndo = collectUndo;

View File

@ -8,9 +8,7 @@
#ifndef CELLBUFFER_H
#define CELLBUFFER_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
// Interface to per-line data that wants to see each line insertion and deletion
class PerLine {
@ -24,33 +22,7 @@ public:
/**
* The line vector contains information about each of the lines in a cell buffer.
*/
class LineVector {
Partitioning starts;
PerLine *perLine;
public:
LineVector();
// Deleted so LineVector objects can not be copied.
LineVector(const LineVector &) = delete;
void operator=(const LineVector &) = delete;
~LineVector();
void Init();
void SetPerLine(PerLine *pl);
void InsertText(Sci::Line line, Sci::Position delta);
void InsertLine(Sci::Line line, Sci::Position position, bool lineStart);
void SetLineStart(Sci::Line line, Sci::Position position);
void RemoveLine(Sci::Line line);
Sci::Line Lines() const {
return starts.Partitions();
}
Sci::Line LineFromPosition(Sci::Position pos) const;
Sci::Position LineStart(Sci::Line line) const {
return starts.PositionFromPartition(line);
}
};
class ILineVector;
enum actionType { insertAction, removeAction, startAction, containerAction };
@ -71,10 +43,9 @@ public:
Action &operator=(const Action &other) = delete;
Action &operator=(const Action &&other) = delete;
// Move constructor allows vector to be resized without reallocating.
// Could use =default but MSVC 2013 warns.
Action(Action &&other);
Action(Action &&other) noexcept = default;
~Action();
void Create(actionType at_, Sci::Position position_=0, const char *data_=0, Sci::Position lenData_=0, bool mayCoalesce_=true);
void Create(actionType at_, Sci::Position position_=0, const char *data_=nullptr, Sci::Position lenData_=0, bool mayCoalesce_=true);
void Clear();
};
@ -95,7 +66,9 @@ public:
UndoHistory();
// Deleted so UndoHistory objects can not be copied.
UndoHistory(const UndoHistory &) = delete;
UndoHistory(UndoHistory &&) = delete;
void operator=(const UndoHistory &) = delete;
void operator=(UndoHistory &&) = delete;
~UndoHistory();
const char *AppendAction(actionType at, Sci::Position position, const char *data, Sci::Position lengthData, bool &startSequence, bool mayCoalesce=true);
@ -113,7 +86,7 @@ public:
// Tentative actions are used for input composition so that it can be undone cleanly
void TentativeStart();
void TentativeCommit();
bool TentativeActive() const { return tentativePoint >= 0; }
bool TentativeActive() const noexcept { return tentativePoint >= 0; }
int TentativeSteps();
/// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
@ -135,6 +108,8 @@ public:
*/
class CellBuffer {
private:
bool hasStyles;
bool largeDocument;
SplitVector<char> substance;
SplitVector<char> style;
bool readOnly;
@ -143,7 +118,7 @@ private:
bool collectingUndo;
UndoHistory uh;
LineVector lv;
std::unique_ptr<ILineVector> plv;
bool UTF8LineEndOverlaps(Sci::Position position) const;
void ResetLineEnds();
@ -153,30 +128,33 @@ private:
public:
CellBuffer();
CellBuffer(bool hasStyles_, bool largeDocument_);
// Deleted so CellBuffer objects can not be copied.
CellBuffer(const CellBuffer &) = delete;
CellBuffer(CellBuffer &&) = delete;
void operator=(const CellBuffer &) = delete;
void operator=(CellBuffer &&) = delete;
~CellBuffer();
/// Retrieving positions outside the range of the buffer works and returns 0
char CharAt(Sci::Position position) const;
char CharAt(Sci::Position position) const noexcept;
unsigned char UCharAt(Sci::Position position) const noexcept;
void GetCharRange(char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const;
char StyleAt(Sci::Position position) const;
char StyleAt(Sci::Position position) const noexcept;
void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const;
const char *BufferPointer();
const char *RangePointer(Sci::Position position, Sci::Position rangeLength);
Sci::Position GapPosition() const;
Sci::Position Length() const;
Sci::Position Length() const noexcept;
void Allocate(Sci::Position newSize);
int GetLineEndTypes() const { return utf8LineEnds; }
void SetLineEndTypes(int utf8LineEnds_);
bool ContainsLineEnd(const char *s, Sci::Position length) const;
void SetPerLine(PerLine *pl);
Sci::Line Lines() const;
Sci::Position LineStart(Sci::Line line) const;
Sci::Line LineFromPosition(Sci::Position pos) const { return lv.LineFromPosition(pos); }
Sci::Line Lines() const noexcept;
Sci::Position LineStart(Sci::Line line) const noexcept;
Sci::Line LineFromPosition(Sci::Position pos) const noexcept;
void InsertLine(Sci::Line line, Sci::Position position, bool lineStart);
void RemoveLine(Sci::Line line);
const char *InsertString(Sci::Position position, const char *s, Sci::Position insertLength, bool &startSequence);
@ -190,6 +168,8 @@ public:
bool IsReadOnly() const;
void SetReadOnly(bool set);
bool IsLarge() const;
bool HasStyles() const;
/// The save point is a marker in the undo stack where the container has stated that
/// the buffer was saved. Undo and redo can move over the save point.
@ -220,8 +200,6 @@ public:
void PerformRedoStep();
};
#ifdef SCI_NAMESPACE
}
#endif
#endif

Some files were not shown because too many files have changed in this diff Show More