Skip to content

Commit

Permalink
Update Scintilla to version 3.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
b4n committed Feb 21, 2017
1 parent f096fa2 commit 2219ab7
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 81 deletions.
62 changes: 51 additions & 11 deletions scintilla/gtk/PlatGTK.cxx
Expand Up @@ -1034,22 +1034,44 @@ void Window::SetPosition(PRectangle rc) {
gtk_widget_size_allocate(PWidget(wid), &alloc);
}

namespace {

GdkRectangle MonitorRectangleForWidget(GtkWidget *wid) {
GdkWindow *wnd = WindowFromWidget(wid);
GdkRectangle rcScreen = GdkRectangle();
#if GTK_CHECK_VERSION(3,22,0)
GdkDisplay *pdisplay = gtk_widget_get_display(wid);
GdkMonitor *monitor = gdk_display_get_monitor_at_window(pdisplay, wnd);
gdk_monitor_get_geometry(monitor, &rcScreen);
#else
GdkScreen* screen = gtk_widget_get_screen(wid);
gint monitor_num = gdk_screen_get_monitor_at_window(screen, wnd);
gdk_screen_get_monitor_geometry(screen, monitor_num, &rcScreen);
#endif
return rcScreen;
}

}

void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
int ox = 0;
int oy = 0;
gdk_window_get_origin(WindowFromWidget(PWidget(relativeTo.wid)), &ox, &oy);
GdkWindow *wndRelativeTo = WindowFromWidget(PWidget(relativeTo.wid));
gdk_window_get_origin(wndRelativeTo, &ox, &oy);
ox += rc.left;
if (ox < 0)
ox = 0;
oy += rc.top;
if (oy < 0)
oy = 0;

GdkRectangle rcScreen = MonitorRectangleForWidget(PWidget(relativeTo.wid));

/* do some corrections to fit into screen */
int sizex = rc.right - rc.left;
int sizey = rc.bottom - rc.top;
int screenWidth = gdk_screen_width();
int screenHeight = gdk_screen_height();
const int screenWidth = rcScreen.width;
const int screenHeight = rcScreen.height;
if (sizex > screenWidth)
ox = 0; /* the best we can do */
else if (ox + sizex > screenWidth)
Expand Down Expand Up @@ -1145,13 +1167,19 @@ PRectangle Window::GetMonitorRect(Point pt) {

gdk_window_get_origin(WindowFromWidget(PWidget(wid)), &x_offset, &y_offset);

GdkScreen* screen;
gint monitor_num;
GdkRectangle rect;

screen = gtk_widget_get_screen(PWidget(wid));
monitor_num = gdk_screen_get_monitor_at_point(screen, pt.x + x_offset, pt.y + y_offset);
#if GTK_CHECK_VERSION(3,22,0)
GdkDisplay *pdisplay = gtk_widget_get_display(PWidget(wid));
GdkMonitor *monitor = gdk_display_get_monitor_at_point(pdisplay,
pt.x + x_offset, pt.y + y_offset);
gdk_monitor_get_geometry(monitor, &rect);
#else
GdkScreen* screen = gtk_widget_get_screen(PWidget(wid));
gint monitor_num = gdk_screen_get_monitor_at_point(screen,
pt.x + x_offset, pt.y + y_offset);
gdk_screen_get_monitor_geometry(screen, monitor_num, &rect);
#endif
rect.x -= x_offset;
rect.y -= y_offset;
return PRectangle(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
Expand Down Expand Up @@ -1401,7 +1429,7 @@ static void StyleSet(GtkWidget *w, GtkStyle*, void*) {
#endif
}

void ListBoxX::Create(Window &, int, Point, int, bool, int) {
void ListBoxX::Create(Window &parent, int, Point, int, bool, int) {
if (widCached != 0) {
wid = widCached;
return;
Expand Down Expand Up @@ -1475,6 +1503,10 @@ void ListBoxX::Create(Window &, int, Point, int, bool, int) {
gtk_widget_show(widget);
g_signal_connect(G_OBJECT(widget), "button_press_event",
G_CALLBACK(ButtonPress), this);

GtkWidget *top = gtk_widget_get_toplevel(static_cast<GtkWidget *>(parent.GetID()));
gtk_window_set_transient_for(GTK_WINDOW(static_cast<GtkWidget *>(wid)),
GTK_WINDOW(top));
}

void ListBoxX::SetFont(Font &scint_font) {
Expand Down Expand Up @@ -1882,17 +1914,24 @@ void Menu::Destroy() {
mid = 0;
}

#if !GTK_CHECK_VERSION(3,22,0)
static void MenuPositionFunc(GtkMenu *, gint *x, gint *y, gboolean *, gpointer userData) {
sptr_t intFromPointer = GPOINTER_TO_INT(userData);
*x = intFromPointer & 0xffff;
*y = intFromPointer >> 16;
}
#endif

void Menu::Show(Point pt, Window &) {
int screenHeight = gdk_screen_height();
int screenWidth = gdk_screen_width();
void Menu::Show(Point pt, Window &wnd) {
GtkMenu *widget = static_cast<GtkMenu *>(mid);
gtk_widget_show_all(GTK_WIDGET(widget));
#if GTK_CHECK_VERSION(3,22,0)
// Rely on GTK+ to do the right thing with positioning
gtk_menu_popup_at_pointer(widget, NULL);
#else
GdkRectangle rcScreen = MonitorRectangleForWidget(PWidget(wnd.GetID()));
const int screenWidth = rcScreen.width;
const int screenHeight = rcScreen.height;
GtkRequisition requisition;
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_get_preferred_size(GTK_WIDGET(widget), NULL, &requisition);
Expand All @@ -1908,6 +1947,7 @@ void Menu::Show(Point pt, Window &) {
gtk_menu_popup(widget, NULL, NULL, MenuPositionFunc,
GINT_TO_POINTER((static_cast<int>(pt.y) << 16) | static_cast<int>(pt.x)), 0,
gtk_get_current_event_time());
#endif
}

ElapsedTime::ElapsedTime() {
Expand Down
42 changes: 41 additions & 1 deletion scintilla/gtk/ScintillaGTK.cxx
Expand Up @@ -7,6 +7,7 @@
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <assert.h>
#include <ctype.h>

Expand All @@ -22,6 +23,9 @@
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#if defined(GDK_WINDOWING_WAYLAND)
#include <gdk/gdkwayland.h>
#endif

#if defined(__WIN32__) || defined(_MSC_VER)
#include <windows.h>
Expand Down Expand Up @@ -165,6 +169,8 @@ ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) :
im_context(NULL), lastNonCommonScript(PANGO_SCRIPT_INVALID_CODE),
lastWheelMouseDirection(0),
wheelMouseIntensity(0),
smoothScrollY(0),
smoothScrollX(0),
rgnUpdate(0),
repaintFullWindow(false),
styleIdleID(0),
Expand Down Expand Up @@ -545,11 +551,21 @@ void ScintillaGTK::Initialise() {
parentClass = reinterpret_cast<GtkWidgetClass *>(
g_type_class_ref(gtk_container_get_type()));

gint maskSmooth = 0;
#if defined(GDK_WINDOWING_WAYLAND)
GdkDisplay *pdisplay = gdk_display_get_default();
if (GDK_IS_WAYLAND_DISPLAY(pdisplay)) {
// On Wayland, touch pads only produce smooth scroll events
maskSmooth = GDK_SMOOTH_SCROLL_MASK;
}
#endif

gtk_widget_set_can_focus(PWidget(wMain), TRUE);
gtk_widget_set_sensitive(PWidget(wMain), TRUE);
gtk_widget_set_events(PWidget(wMain),
GDK_EXPOSURE_MASK
| GDK_SCROLL_MASK
| maskSmooth
| GDK_STRUCTURE_MASK
| GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE_MASK
Expand Down Expand Up @@ -1301,6 +1317,9 @@ void ScintillaGTK::CreateCallTipWindow(PRectangle rc) {
G_CALLBACK(ScintillaGTK::PressCT), static_cast<void *>(this));
gtk_widget_set_events(widcdrw,
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
GtkWidget *top = gtk_widget_get_toplevel(static_cast<GtkWidget *>(wMain.GetID()));
gtk_window_set_transient_for(GTK_WINDOW(static_cast<GtkWidget *>(PWidget(ct.wCallTip))),
GTK_WINDOW(top));
}
gtk_widget_set_size_request(PWidget(ct.wDraw), rc.Width(), rc.Height());
ct.wDraw.Show();
Expand Down Expand Up @@ -1781,6 +1800,25 @@ gint ScintillaGTK::ScrollEvent(GtkWidget *widget, GdkEventScroll *event) {
if (widget == NULL || event == NULL)
return FALSE;

#if defined(GDK_WINDOWING_WAYLAND)
if (event->direction == GDK_SCROLL_SMOOTH) {
const int smoothScrollFactor = 4;
sciThis->smoothScrollY += event->delta_y * smoothScrollFactor;
sciThis->smoothScrollX += event->delta_x * smoothScrollFactor;;
if (ABS(sciThis->smoothScrollY) >= 1.0) {
const int scrollLines = trunc(sciThis->smoothScrollY);
sciThis->ScrollTo(sciThis->topLine + scrollLines);
sciThis->smoothScrollY -= scrollLines;
}
if (ABS(sciThis->smoothScrollX) >= 1.0) {
const int scrollPixels = trunc(sciThis->smoothScrollX);
sciThis->HorizontalScrollTo(sciThis->xOffset + scrollPixels);
sciThis->smoothScrollX -= scrollPixels;
}
return TRUE;
}
#endif

// Compute amount and direction to scroll (even tho on win32 there is
// intensity of scrolling info in the native message, gtk doesn't
// support this so we simulate similarly adaptive scrolling)
Expand Down Expand Up @@ -2397,7 +2435,9 @@ void ScintillaGTK::StyleSetText(GtkWidget *widget, GtkStyle *, void*) {
void ScintillaGTK::RealizeText(GtkWidget *widget, void*) {
// Set NULL background to avoid automatic clearing so Scintilla responsible for all drawing
if (WindowFromWidget(widget)) {
#if GTK_CHECK_VERSION(3,0,0)
#if GTK_CHECK_VERSION(3,22,0)
// Appears unnecessary
#elif GTK_CHECK_VERSION(3,0,0)
gdk_window_set_background_pattern(WindowFromWidget(widget), NULL);
#else
gdk_window_set_back_pixmap(WindowFromWidget(widget), NULL, FALSE);
Expand Down
2 changes: 2 additions & 0 deletions scintilla/gtk/ScintillaGTK.h
Expand Up @@ -57,6 +57,8 @@ class ScintillaGTK : public ScintillaBase {
GTimeVal lastWheelMouseTime;
gint lastWheelMouseDirection;
gint wheelMouseIntensity;
gdouble smoothScrollY;
gdouble smoothScrollX;

#if GTK_CHECK_VERSION(3,0,0)
cairo_rectangle_list_t *rgnUpdate;
Expand Down
4 changes: 4 additions & 0 deletions scintilla/include/SciLexer.h
Expand Up @@ -151,6 +151,10 @@
#define SCE_P_STRINGEOL 13
#define SCE_P_WORD2 14
#define SCE_P_DECORATOR 15
#define SCE_P_FSTRING 16
#define SCE_P_FCHARACTER 17
#define SCE_P_FTRIPLE 18
#define SCE_P_FTRIPLEDOUBLE 19
#define SCE_C_DEFAULT 0
#define SCE_C_COMMENT 1
#define SCE_C_COMMENTLINE 2
Expand Down
8 changes: 6 additions & 2 deletions scintilla/include/Scintilla.iface
Expand Up @@ -2354,10 +2354,10 @@ get bool GetSelectionEmpty=2650(,)
fun void ClearSelections=2571(,)

# Set a simple selection
fun int SetSelection=2572(position caret, position anchor)
fun void SetSelection=2572(position caret, position anchor)

# Add a selection
fun int AddSelection=2573(position caret, position anchor)
fun void AddSelection=2573(position caret, position anchor)

# Drop one selection
fun void DropSelectionN=2671(int selection,)
Expand Down Expand Up @@ -2914,6 +2914,10 @@ val SCE_P_COMMENTBLOCK=12
val SCE_P_STRINGEOL=13
val SCE_P_WORD2=14
val SCE_P_DECORATOR=15
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
lex Cpp=SCLEX_CPP SCE_C_
lex BullAnt=SCLEX_BULLANT SCE_C_
Expand Down
4 changes: 3 additions & 1 deletion scintilla/lexers/LexDiff.cxx
Expand Up @@ -51,8 +51,10 @@ static void ColouriseDiffLine(char *lineBuffer, Sci_Position endLine, Accessor &
styler.ColourTo(endLine, SCE_DIFF_POSITION);
else if (lineBuffer[3] == '\r' || lineBuffer[3] == '\n')
styler.ColourTo(endLine, SCE_DIFF_POSITION);
else
else if (lineBuffer[3] == ' ')
styler.ColourTo(endLine, SCE_DIFF_HEADER);
else
styler.ColourTo(endLine, SCE_DIFF_DELETED);
} else if (0 == strncmp(lineBuffer, "+++ ", 4)) {
// I don't know of any diff where "+++ " is a position marker, but for
// consistency, do the same as with "--- " and "*** ".
Expand Down
4 changes: 2 additions & 2 deletions scintilla/lexers/LexLua.cxx
Expand Up @@ -89,8 +89,8 @@ static void ColouriseLuaDoc(
}

StyleContext sc(startPos, length, initStyle, styler);
if (startPos == 0 && sc.ch == '#') {
// shbang line: # is a comment only if first char of the script
if (startPos == 0 && sc.ch == '#' && sc.chNext == '!') {
// shbang line: "#!" is a comment only if located at the start of the script
sc.SetState(SCE_LUA_COMMENTLINE);
}
for (; sc.More(); sc.Forward()) {
Expand Down
33 changes: 24 additions & 9 deletions scintilla/lexers/LexMatlab.cxx
Expand Up @@ -18,6 +18,9 @@
**
** Changes by John Donoghue 2016/11/15
** - update matlab code folding
**
** Changes by John Donoghue 2017/01/18
** - update matlab block comment detection
**/
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
Expand Down Expand Up @@ -73,6 +76,15 @@ static int CheckKeywordFoldPoint(char *str) {
return 0;
}

static bool IsSpaceToEOL(Sci_Position startPos, Accessor &styler) {
Sci_Position line = styler.GetLine(startPos);
Sci_Position eol_pos = styler.LineStart(line + 1) - 1;
for (Sci_Position i = startPos; i < eol_pos; i++) {
char ch = styler[i];
if(!IsASpace(ch)) return false;
}
return true;
}

static void ColouriseMatlabOctaveDoc(
Sci_PositionU startPos, Sci_Position length, int initStyle,
Expand Down Expand Up @@ -180,7 +192,7 @@ static void ColouriseMatlabOctaveDoc(
}
} else if (sc.state == SCE_MATLAB_COMMENT) {
// end or start of a nested a block comment?
if( IsCommentChar(sc.ch) && sc.chNext == '}' && nonSpaceColumn == column) {
if( IsCommentChar(sc.ch) && sc.chNext == '}' && nonSpaceColumn == column && IsSpaceToEOL(sc.currentPos+2, styler)) {
if(commentDepth > 0) commentDepth --;

curLine = styler.GetLine(sc.currentPos);
Expand All @@ -192,7 +204,7 @@ static void ColouriseMatlabOctaveDoc(
transpose = false;
}
}
else if( IsCommentChar(sc.ch) && sc.chNext == '{' && nonSpaceColumn == column)
else if( IsCommentChar(sc.ch) && sc.chNext == '{' && nonSpaceColumn == column && IsSpaceToEOL(sc.currentPos+2, styler))
{
commentDepth ++;

Expand All @@ -214,8 +226,11 @@ static void ColouriseMatlabOctaveDoc(
if (sc.state == SCE_MATLAB_DEFAULT) {
if (IsCommentChar(sc.ch)) {
// ncrement depth if we are a block comment
if(sc.chNext == '{' && nonSpaceColumn == column)
commentDepth ++;
if(sc.chNext == '{' && nonSpaceColumn == column) {
if(IsSpaceToEOL(sc.currentPos+2, styler)) {
commentDepth ++;
}
}
curLine = styler.GetLine(sc.currentPos);
styler.SetLineState(curLine, commentDepth);
sc.SetState(SCE_MATLAB_COMMENT);
Expand Down Expand Up @@ -284,13 +299,13 @@ static void FoldMatlabOctaveDoc(Sci_PositionU startPos, Sci_Position length, int
style = styleNext;
styleNext = styler.StyleAt(i + 1);
bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');

// a line that starts with a comment
if (style == SCE_MATLAB_COMMENT && IsComment(ch) && visibleChars == 0) {
// start/end of block comment
if (chNext == '{')
// start/end of block comment
if (chNext == '{' && IsSpaceToEOL(i+2, styler))
levelNext ++;
if (chNext == '}')
if (chNext == '}' && IsSpaceToEOL(i+2, styler))
levelNext --;
}
// keyword
Expand All @@ -303,7 +318,7 @@ static void FoldMatlabOctaveDoc(Sci_PositionU startPos, Sci_Position length, int
if (styleNext != SCE_MATLAB_KEYWORD) {
word[wordlen] = '\0';
wordlen = 0;

levelNext += CheckKeywordFoldPoint(word);
}
}
Expand Down

0 comments on commit 2219ab7

Please sign in to comment.