Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'scintilla-update'

  • Loading branch information...
commit a0367acd2dc154ed0158b0b85f1b2ebf88a3246f 2 parents cdb748c + 24dd733
@b4n b4n authored
Showing with 4,228 additions and 1,414 deletions.
  1. +6 −0 NEWS
  2. +9 −0 data/filetypes.latex
  3. +1 −0  data/filetypes.lua
  4. +12 −0 data/filetypes.perl
  5. +258 −86 scintilla/gtk/PlatGTK.cxx
  6. +544 −101 scintilla/gtk/ScintillaGTK.cxx
  7. +14 −3 scintilla/include/Platform.h
  8. +19 −0 scintilla/include/SciLexer.h
  9. +43 −4 scintilla/include/Scintilla.h
  10. +96 −7 scintilla/include/Scintilla.iface
  11. +255 −117 scintilla/lexers/LexBasic.cxx
  12. +8 −0 scintilla/lexers/LexCOBOL.cxx
  13. +31 −24 scintilla/lexers/LexCPP.cxx
  14. +87 −38 scintilla/lexers/LexHTML.cxx
  15. +106 −13 scintilla/lexers/LexLua.cxx
  16. +15 −8 scintilla/lexers/LexMarkdown.cxx
  17. +6 −6 scintilla/lexers/LexMatlab.cxx
  18. +229 −31 scintilla/lexers/LexOthers.cxx
  19. +812 −424 scintilla/lexers/LexPerl.cxx
  20. +35 −36 scintilla/lexers/LexPython.cxx
  21. +8 −3 scintilla/lexers/LexRuby.cxx
  22. +18 −4 scintilla/lexers/LexSQL.cxx
  23. +1 −1  scintilla/lexers/LexVHDL.cxx
  24. +21 −9 scintilla/lexers/LexVerilog.cxx
  25. +1 −1  scintilla/lexlib/Accessor.cxx
  26. +0 −1  scintilla/lexlib/CharacterSet.h
  27. +4 −3 scintilla/lexlib/PropSetSimple.cxx
  28. +3 −3 scintilla/lexlib/SparseState.h
  29. +1 −1  scintilla/lexlib/StyleContext.h
  30. +21 −7 scintilla/lexlib/WordList.cxx
  31. +1 −1  scintilla/scintilla_changes.patch
  32. +1 −1  scintilla/src/CallTip.cxx
  33. +11 −1 scintilla/src/ContractionState.cxx
  34. +1 −0  scintilla/src/ContractionState.h
  35. +5 −1 scintilla/src/Decoration.cxx
  36. +161 −24 scintilla/src/Document.cxx
  37. +45 −3 scintilla/src/Document.h
  38. +510 −189 scintilla/src/Editor.cxx
  39. +16 −4 scintilla/src/Editor.h
  40. +56 −2 scintilla/src/Indicator.cxx
  41. +2 −1  scintilla/src/Indicator.h
  42. +38 −9 scintilla/src/KeyMap.cxx
  43. +1 −0  scintilla/src/KeyMap.h
  44. +115 −38 scintilla/src/LineMarker.cxx
  45. +16 −2 scintilla/src/LineMarker.h
  46. +2 −2 scintilla/src/PerLine.cxx
  47. +37 −50 scintilla/src/PositionCache.cxx
  48. +13 −12 scintilla/src/PositionCache.h
  49. +3 −3 scintilla/src/RESearch.cxx
  50. +33 −1 scintilla/src/RunStyles.cxx
  51. +6 −2 scintilla/src/RunStyles.h
  52. +12 −5 scintilla/src/ScintillaBase.cxx
  53. +65 −81 scintilla/src/Style.cxx
  54. +45 −17 scintilla/src/Style.h
  55. +115 −20 scintilla/src/ViewStyle.cxx
  56. +20 −0 scintilla/src/ViewStyle.h
  57. +138 −5 scintilla/src/XPM.cxx
  58. +48 −2 scintilla/src/XPM.h
  59. +1 −1  scintilla/version.txt
  60. +47 −6 src/highlighting.c
View
6 NEWS
@@ -1,3 +1,9 @@
+Geany 1.22 (unreleased)
+
+ Editor
+ * Update Scintilla to version 2.29.
+
+
Geany 0.21 (October 2, 2011)
General
View
9 data/filetypes.latex
@@ -6,6 +6,15 @@ command=keyword_1
tag=tag
math=number_1
comment=comment
+# mappings below may need checking
+tag2=tag
+math2=number_1
+comment2=comment
+verbatim=default
+shortcmd=keyword_1
+special=keyword_2
+cmdopt=keyword_1
+error=error
[keywords]
# all items must be in one line
View
1  data/filetypes.lua
@@ -21,6 +21,7 @@ word5=keyword_1
word6=keyword_2
word7=keyword_3
word8=keyword_4
+label=label
[keywords]
# all items must be in one line
View
12 data/filetypes.perl
@@ -31,6 +31,18 @@
string_qr=string_2
string_qw=string_2
variable_indexer=default
+# *_var mappings may need checking
+string_var=identifier_1
+regex_var=identifier_2
+regsubst_var=identifier_2
+backticks_var=identifier_2
+here_qq_var=identifier_2
+here_qx_var=identifier_2
+string_qq_var=identifier_2
+string_qx_var=identifier_2
+string_qr_var=identifier_2
+# translation: tr{}{} y{}{}
+xlat=string_2
# not used
punctuation=default
# obsolete: replaced by qq, qx, qr, qw
View
344 scintilla/gtk/PlatGTK.cxx
@@ -9,6 +9,9 @@
#include <stddef.h>
#include <math.h>
+#include <vector>
+#include <map>
+
#include <glib.h>
#include <gmodule.h>
#include <gdk/gdk.h>
@@ -40,10 +43,38 @@
#define IS_WIDGET_FOCUSSED(w) (GTK_WIDGET_HAS_FOCUS(w))
#endif
-#if GTK_CHECK_VERSION(2,22,0)
#define USE_CAIRO 1
+
+#ifdef USE_CAIRO
+
+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
+}
+
#endif
+static GdkWindow *WindowFromWidget(GtkWidget *w) {
+#if GTK_CHECK_VERSION(3,0,0)
+ return gtk_widget_get_window(w);
+#else
+ return w->window;
+#endif
+}
+
#ifdef USE_CAIRO
#define DISABLE_GDK_FONT 1
#endif
@@ -116,10 +147,17 @@ class FontHandle {
encodingType et;
public:
int ascent;
+#ifndef DISABLE_GDK_FONT
GdkFont *pfont;
+#endif
PangoFontDescription *pfd;
int characterSet;
- FontHandle(GdkFont *pfont_) {
+#ifdef DISABLE_GDK_FONT
+ FontHandle() : et(singleByte), ascent(0), pfd(0), characterSet(-1) {
+ ResetWidths(et);
+ }
+#else
+ FontHandle(GdkFont *pfont_=0) {
et = singleByte;
ascent = 0;
pfont = pfont_;
@@ -127,10 +165,13 @@ class FontHandle {
characterSet = -1;
ResetWidths(et);
}
+#endif
FontHandle(PangoFontDescription *pfd_, int characterSet_) {
et = singleByte;
ascent = 0;
+#ifndef DISABLE_GDK_FONT
pfont = 0;
+#endif
pfd = pfd_;
characterSet = characterSet_;
ResetWidths(et);
@@ -139,8 +180,8 @@ class FontHandle {
#ifndef DISABLE_GDK_FONT
if (pfont)
gdk_font_unref(pfont);
-#endif
pfont = 0;
+#endif
if (pfd)
pango_font_description_free(pfd);
pfd = 0;
@@ -183,9 +224,11 @@ static GtkWidget *PWidget(WindowID wid) {
return reinterpret_cast<GtkWidget *>(wid);
}
+#if !GTK_CHECK_VERSION(3,0,0)
static GtkWidget *PWidget(Window &w) {
return PWidget(w.GetID());
}
+#endif
Point Point::FromLong(long lpoint) {
return Point(
@@ -254,6 +297,8 @@ void Palette::WantFind(ColourPair &cp, bool want) {
}
void Palette::Allocate(Window &w) {
+#if !GTK_CHECK_VERSION(3,0,0)
+ // Disable palette on GTK+ 3.
if (allocatedPalette) {
gdk_colormap_free_colors(gtk_widget_get_colormap(PWidget(w)),
reinterpret_cast<GdkColor *>(allocatedPalette),
@@ -274,14 +319,17 @@ void Palette::Allocate(Window &w) {
paletteNew[iPal].blue = entries[iPal].desired.GetBlue() * (65535 / 255);
paletteNew[iPal].pixel = entries[iPal].desired.AsLong();
}
+#ifndef USE_CAIRO
gdk_colormap_alloc_colors(gtk_widget_get_colormap(PWidget(w)),
paletteNew, allocatedLen, FALSE, TRUE,
successPalette);
+#endif
for (iPal = 0; iPal < used; iPal++) {
entries[iPal].allocated.Set(paletteNew[iPal].pixel);
}
}
delete []successPalette;
+#endif
}
#ifndef DISABLE_GDK_FONT
@@ -671,7 +719,7 @@ FontID FontCached::CreateNewFont(const char *fontName, int characterSet,
}
return new FontHandle(newid);
#else
- return new FontHandle(0);
+ return new FontHandle();
#endif
}
@@ -695,6 +743,8 @@ void Font::Release() {
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
+
+// On GTK+ 2.x, SurfaceID is a GdkDrawable* and on GTK+ 3.x, it is a cairo_t*
class SurfaceImpl : public Surface {
encodingType et;
#ifdef USE_CAIRO
@@ -736,6 +786,7 @@ class SurfaceImpl : public Surface {
void RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back);
void AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill,
ColourAllocated outline, int alphaOutline, int flags);
+ void DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage);
void Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back);
void Copy(PRectangle rc, Point from, Surface &surfaceSource);
@@ -883,7 +934,11 @@ void SurfaceImpl::Init(WindowID wid) {
Release();
PLATFORM_ASSERT(wid);
#ifdef USE_CAIRO
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkWindow *drawable_ = gtk_widget_get_window(PWidget(wid));
+#else
GdkDrawable *drawable_ = GDK_DRAWABLE(PWidget(wid)->window);
+#endif
if (drawable_) {
context = gdk_cairo_create(drawable_);
PLATFORM_ASSERT(context);
@@ -904,14 +959,17 @@ void SurfaceImpl::Init(WindowID wid) {
void SurfaceImpl::Init(SurfaceID sid, WindowID wid) {
PLATFORM_ASSERT(sid);
- GdkDrawable *drawable_ = reinterpret_cast<GdkDrawable *>(sid);
Release();
PLATFORM_ASSERT(wid);
#ifdef USE_CAIRO
- context = gdk_cairo_create(drawable_);
+#if GTK_CHECK_VERSION(3,0,0)
+ context = cairo_reference(reinterpret_cast<cairo_t *>(sid));
+#else
+ context = gdk_cairo_create(reinterpret_cast<GdkDrawable *>(sid));
+#endif
#else
- gc = gdk_gc_new(drawable_);
- drawable = drawable_;
+ drawable = reinterpret_cast<GdkDrawable *>(sid);
+ gc = gdk_gc_new(drawable);
#endif
pcontext = gtk_widget_create_pango_context(PWidget(wid));
layout = pango_layout_new(pcontext);
@@ -942,8 +1000,8 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface *surface_, WindowID
PLATFORM_ASSERT(layout);
#ifdef USE_CAIRO
if (height > 0 && width > 0)
- psurf = gdk_window_create_similar_surface(
- gtk_widget_get_window(PWidget(wid)),
+ psurf = CreateSimilarSurface(
+ WindowFromWidget(PWidget(wid)),
CAIRO_CONTENT_COLOR_ALPHA, width, height);
#else
if (height > 0 && width > 0)
@@ -974,9 +1032,9 @@ void SurfaceImpl::PenColour(ColourAllocated fore) {
if (context) {
ColourDesired cdFore(fore.AsLong());
cairo_set_source_rgb(context,
- cdFore.GetBlue() / 255.0,
+ cdFore.GetRed() / 255.0,
cdFore.GetGreen() / 255.0,
- cdFore.GetRed() / 255.0);
+ cdFore.GetBlue() / 255.0);
}
#else
if (gc) {
@@ -1186,7 +1244,12 @@ void SurfaceImpl::RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAl
static void PathRoundRectangle(cairo_t *context, double left, double top, double width, double height, int radius) {
double degrees = M_PI / 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);
@@ -1216,8 +1279,6 @@ static guint32 u32FromRGBA(guint8 r, guint8 g, guint8 b, guint8 a) {
return converter.val;
}
-#endif
-
static unsigned int GetRValue(unsigned int co) {
return (co >> 16) & 0xff;
}
@@ -1230,24 +1291,34 @@ static unsigned int GetBValue(unsigned int co) {
return co & 0xff;
}
+#endif
+
void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill,
ColourAllocated outline, int alphaOutline, int flags) {
#ifdef USE_CAIRO
if (context && rc.Width() > 0) {
+ ColourDesired cdFill(fill.AsLong());
cairo_set_source_rgba(context,
- GetRValue(fill.AsLong()) / 255.0,
- GetGValue(fill.AsLong()) / 255.0,
- GetBValue(fill.AsLong()) / 255.0,
+ cdFill.GetRed() / 255.0,
+ cdFill.GetGreen() / 255.0,
+ cdFill.GetBlue() / 255.0,
alphaFill / 255.0);
- PathRoundRectangle(context, rc.left + 1.0, rc.top+1.0, rc.right - rc.left - 2.0, rc.bottom - rc.top - 2.0, cornerSize);
+ if (cornerSize > 0)
+ PathRoundRectangle(context, rc.left + 1.0, rc.top + 1.0, rc.right - rc.left - 2.0, rc.bottom - rc.top - 2.0, cornerSize);
+ else
+ 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());
cairo_set_source_rgba(context,
- GetRValue(outline.AsLong()) / 255.0,
- GetGValue(outline.AsLong()) / 255.0,
- GetBValue(outline.AsLong()) / 255.0,
+ cdOutline.GetRed() / 255.0,
+ cdOutline.GetGreen() / 255.0,
+ cdOutline.GetBlue() / 255.0,
alphaOutline / 255.0);
- PathRoundRectangle(context, rc.left +0.5, rc.top+0.5, rc.right - rc.left - 1, rc.bottom - rc.top - 1, cornerSize);
+ if (cornerSize > 0)
+ PathRoundRectangle(context, rc.left + 0.5, rc.top + 0.5, rc.right - rc.left - 1, rc.bottom - rc.top - 1, cornerSize);
+ else
+ cairo_rectangle(context, rc.left + 0.5, rc.top + 0.5, rc.right - rc.left - 1, rc.bottom - rc.top - 1);
cairo_stroke(context);
}
#else
@@ -1293,6 +1364,51 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated
#endif
}
+void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) {
+ if (rc.Width() > width)
+ rc.left += (rc.Width() - width) / 2;
+ rc.right = rc.left + width;
+ if (rc.Height() > height)
+ rc.top += (rc.Height() - height) / 2;
+ rc.bottom = rc.top + height;
+
+#ifdef USE_CAIRO
+ int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
+ int ucs = stride * height;
+ std::vector<unsigned char> image(ucs);
+ for (int y=0; y<height; y++) {
+ for (int x=0; x<width; x++) {
+ unsigned char *pixel = &image[0] + y*stride + x * 4;
+ unsigned char alpha = pixelsImage[3];
+ pixel[2] = (*pixelsImage++) * alpha / 255;
+ pixel[1] = (*pixelsImage++) * alpha / 255;
+ pixel[0] = (*pixelsImage++) * alpha / 255;
+ pixel[3] = *pixelsImage++;
+ }
+ }
+
+ cairo_surface_t *psurf = cairo_image_surface_create_for_data(&image[0], CAIRO_FORMAT_ARGB32, width, height, stride);
+ cairo_set_source_surface(context, psurf, rc.left, rc.top);
+ cairo_rectangle(context, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top);
+ cairo_fill(context);
+
+ cairo_surface_destroy(psurf);
+#else
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data(pixelsImage,
+ GDK_COLORSPACE_RGB,
+ TRUE,
+ 8,
+ width,
+ height,
+ width * 4,
+ NULL,
+ NULL);
+ gdk_draw_pixbuf(drawable, gc, pixbuf,
+ 0,0, rc.left,rc.top, width,height, GDK_RGB_DITHER_NORMAL, 0, 0);
+ g_object_unref(pixbuf);
+#endif
+}
+
void SurfaceImpl::Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back) {
PenColour(back);
#ifdef USE_CAIRO
@@ -1474,7 +1590,6 @@ void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, int ybase, const char
int xText = rc.left;
if (PFont(font_)->pfd) {
char *utfForm = 0;
- bool useGFree = false;
if (et == UTF8) {
pango_layout_set_text(layout, s, len);
} else {
@@ -1508,11 +1623,7 @@ void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, int ybase, const char
#else
gdk_draw_layout_line(drawable, gc, xText, ybase, pll);
#endif
- if (useGFree) {
- g_free(utfForm);
- } else {
- delete []utfForm;
- }
+ delete []utfForm;
return;
}
#ifndef DISABLE_GDK_FONT
@@ -1690,7 +1801,6 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, int *positi
}
if (positionsCalculated < 1 ) {
// Either Latin1 or DBCS conversion failed so treat as Latin1.
- bool useGFree = false;
SetConverter(PFont(font_)->characterSet);
char *utfForm = UTF8FromIconv(conv, s, len);
if (!utfForm) {
@@ -1712,11 +1822,7 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, int *positi
}
clusterStart = clusterEnd;
}
- if (useGFree) {
- g_free(utfForm);
- } else {
- delete []utfForm;
- }
+ delete []utfForm;
PLATFORM_ASSERT(i == lenPositions);
}
}
@@ -1792,7 +1898,6 @@ int SurfaceImpl::WidthText(Font &font_, const char *s, int len) {
char *utfForm = 0;
pango_layout_set_font_description(layout, PFont(font_)->pfd);
PangoRectangle pos;
- bool useGFree = false;
if (et == UTF8) {
pango_layout_set_text(layout, s, len);
} else {
@@ -1815,11 +1920,7 @@ int SurfaceImpl::WidthText(Font &font_, const char *s, int len) {
PangoLayoutLine *pangoLine = pango_layout_get_line(layout,0);
#endif
pango_layout_line_get_extents(pangoLine, NULL, &pos);
- if (useGFree) {
- g_free(utfForm);
- } else {
- delete []utfForm;
- }
+ delete []utfForm;
return PANGO_PIXELS(pos.width);
}
#ifndef DISABLE_GDK_FONT
@@ -2005,11 +2106,17 @@ PRectangle Window::GetPosition() {
// Before any size allocated pretend its 1000 wide so not scrolled
PRectangle rc(0, 0, 1000, 1000);
if (wid) {
- rc.left = PWidget(wid)->allocation.x;
- rc.top = PWidget(wid)->allocation.y;
- if (PWidget(wid)->allocation.width > 20) {
- rc.right = rc.left + PWidget(wid)->allocation.width;
- rc.bottom = rc.top + PWidget(wid)->allocation.height;
+ GtkAllocation allocation;
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_get_allocation(PWidget(wid), &allocation);
+#else
+ allocation = PWidget(wid)->allocation;
+#endif
+ rc.left = allocation.x;
+ rc.top = allocation.y;
+ if (allocation.width > 20) {
+ rc.right = rc.left + allocation.width;
+ rc.bottom = rc.top + allocation.height;
}
}
return rc;
@@ -2027,7 +2134,7 @@ void Window::SetPosition(PRectangle rc) {
void Window::SetPositionRelative(PRectangle rc, Window relativeTo) {
int ox = 0;
int oy = 0;
- gdk_window_get_origin(PWidget(relativeTo.wid)->window, &ox, &oy);
+ gdk_window_get_origin(WindowFromWidget(PWidget(relativeTo.wid)), &ox, &oy);
ox += rc.left;
if (ox < 0)
ox = 0;
@@ -2113,9 +2220,13 @@ void Window::SetCursor(Cursor curs) {
break;
}
- if (PWidget(wid)->window)
- gdk_window_set_cursor(PWidget(wid)->window, gdkCurs);
+ if (WindowFromWidget(PWidget(wid)))
+ gdk_window_set_cursor(WindowFromWidget(PWidget(wid)), gdkCurs);
+#if GTK_CHECK_VERSION(3,0,0)
+ g_object_unref(gdkCurs);
+#else
gdk_cursor_unref(gdkCurs);
+#endif
}
void Window::SetTitle(const char *s) {
@@ -2127,7 +2238,7 @@ void Window::SetTitle(const char *s) {
PRectangle Window::GetMonitorRect(Point pt) {
gint x_offset, y_offset;
- gdk_window_get_origin(PWidget(wid)->window, &x_offset, &y_offset);
+ gdk_window_get_origin(WindowFromWidget(PWidget(wid)), &x_offset, &y_offset);
#if GTK_CHECK_VERSION(2,2,0)
// GTK+ 2.2+
@@ -2150,15 +2261,17 @@ PRectangle Window::GetMonitorRect(Point pt) {
#endif
}
+typedef std::map<int, RGBAImage*> ImageMap;
+
struct ListImage {
- const char *xpm_data;
+ const RGBAImage *rgba_data;
GdkPixbuf *pixbuf;
};
static void list_image_free(gpointer, gpointer value, gpointer) {
ListImage *list_image = (ListImage *) value;
if (list_image->pixbuf)
- g_object_unref (list_image->pixbuf);
+ g_object_unref(list_image->pixbuf);
g_free(list_image);
}
@@ -2179,7 +2292,7 @@ class ListBoxX : public ListBox {
WindowID scroller;
void *pixhash;
GtkCellRenderer* pixbuf_renderer;
- XPMSet xset;
+ RGBAImageSet images;
int desiredVisibleRows;
unsigned int maxItemCharacters;
unsigned int aveCharWidth;
@@ -2211,7 +2324,9 @@ class ListBoxX : public ListBox {
virtual int GetSelection();
virtual int Find(const char *prefix);
virtual void GetValue(int n, char *value, int len);
+ void RegisterRGBA(int type, RGBAImage *image);
virtual void RegisterImage(int type, const char *xpm_data);
+ virtual void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage);
virtual void ClearRegisteredImages();
virtual void SetDoubleClickAction(CallBackAction action, void *data) {
doubleClickAction = action;
@@ -2242,24 +2357,47 @@ static gboolean ButtonPress(GtkWidget *, GdkEventButton* ev, gpointer p) {
/* 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*) {
- GtkStyle* style;
g_return_if_fail(w != NULL);
/* Copy the selected color to active. Note that the modify calls will cause
recursive calls to this function after the value is updated and w->style to
be set to a new object */
- style = gtk_widget_get_style(w);
+
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkStyleContext *styleContext = gtk_widget_get_style_context(w);
+ if (styleContext == NULL)
+ return;
+
+ GdkRGBA colourForeSelected;
+ gtk_style_context_get_color(styleContext, GTK_STATE_FLAG_SELECTED, &colourForeSelected);
+ GdkRGBA colourForeActive;
+ gtk_style_context_get_color(styleContext, GTK_STATE_FLAG_ACTIVE, &colourForeActive);
+ if (!gdk_rgba_equal(&colourForeSelected, &colourForeActive))
+ gtk_widget_override_color(w, GTK_STATE_FLAG_ACTIVE, &colourForeSelected);
+
+ styleContext = gtk_widget_get_style_context(w);
+ if (styleContext == NULL)
+ return;
+
+ GdkRGBA colourBaseSelected;
+ gtk_style_context_get_background_color(styleContext, GTK_STATE_FLAG_SELECTED, &colourBaseSelected);
+ GdkRGBA colourBaseActive;
+ gtk_style_context_get_background_color(styleContext, GTK_STATE_FLAG_ACTIVE, &colourBaseActive);
+ if (!gdk_rgba_equal(&colourBaseSelected, &colourBaseActive))
+ gtk_widget_override_background_color(w, GTK_STATE_FLAG_ACTIVE, &colourBaseSelected);
+#else
+ GtkStyle *style = gtk_widget_get_style(w);
if (style == NULL)
return;
if (!gdk_color_equal(&style->base[GTK_STATE_SELECTED], &style->base[GTK_STATE_ACTIVE]))
gtk_widget_modify_base(w, GTK_STATE_ACTIVE, &style->base[GTK_STATE_SELECTED]);
-
style = gtk_widget_get_style(w);
if (style == NULL)
return;
if (!gdk_color_equal(&style->text[GTK_STATE_SELECTED], &style->text[GTK_STATE_ACTIVE]))
gtk_widget_modify_text(w, GTK_STATE_ACTIVE, &style->text[GTK_STATE_SELECTED]);
+#endif
}
void ListBoxX::Create(Window &, int, Point, int, bool) {
@@ -2324,7 +2462,11 @@ void ListBoxX::SetFont(Font &scint_font) {
// Only do for Pango font as there have been crashes for GDK fonts
if (Created() && PFont(scint_font)->pfd) {
// Current font is Pango font
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_override_font(PWidget(list), PFont(scint_font)->pfd);
+#else
gtk_widget_modify_font(PWidget(list), PFont(scint_font)->pfd);
+#endif
}
}
@@ -2360,14 +2502,27 @@ PRectangle ListBoxX::GetDesiredRect() {
gtk_tree_view_get_column(GTK_TREE_VIEW(list), 0);
gtk_tree_view_column_cell_get_size(column, NULL,
NULL, NULL, &row_width, &row_height);
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkStyleContext *styleContextList = gtk_widget_get_style_context(PWidget(list));
+ GtkBorder padding;
+ gtk_style_context_get_padding(styleContextList, GTK_STATE_FLAG_NORMAL, &padding);
+ height = (rows * row_height
+ + padding.top + padding.bottom
+ + 2 * (gtk_container_get_border_width(GTK_CONTAINER(PWidget(list))) + 1));
+#else
int ythickness = PWidget(list)->style->ythickness;
height = (rows * row_height
+ 2 * (ythickness
+ GTK_CONTAINER(PWidget(list))->border_width + 1));
+#endif
gtk_widget_set_size_request(GTK_WIDGET(PWidget(list)), -1, height);
// Get the size of the scroller because we set usize on the window
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_get_preferred_size(GTK_WIDGET(scroller), NULL, &req);
+#else
gtk_widget_size_request(GTK_WIDGET(scroller), &req);
+#endif
rc.right = req.width;
rc.bottom = req.height;
@@ -2396,25 +2551,21 @@ void ListBoxX::Clear() {
}
static void init_pixmap(ListImage *list_image) {
- const char *textForm = list_image->xpm_data;
- const char * const * xpm_lineform = reinterpret_cast<const char * const *>(textForm);
- const char **xpm_lineformfromtext = 0;
- // The XPM data can be either in atext form as will be read from a file
- // or in a line form (array of char *) as will be used for images defined in code.
- // Test for text form and convert to line form
- if ((0 == memcmp(textForm, "/* X", 4)) && (0 == memcmp(textForm, "/* XPM */", 9))) {
- // Test done is two parts to avoid possibility of overstepping the memory
- // if memcmp implemented strangely. Must be 4 bytes at least at destination.
- xpm_lineformfromtext = XPM::LinesFormFromTextForm(textForm);
- xpm_lineform = xpm_lineformfromtext;
- }
-
- // Drop any existing pixmap/bitmap as data may have changed
- if (list_image->pixbuf)
- g_object_unref(list_image->pixbuf);
- list_image->pixbuf =
- gdk_pixbuf_new_from_xpm_data((const gchar**)xpm_lineform);
- delete []xpm_lineformfromtext;
+ if (list_image->rgba_data) {
+ // Drop any existing pixmap/bitmap as data may have changed
+ if (list_image->pixbuf)
+ g_object_unref(list_image->pixbuf);
+ list_image->pixbuf =
+ gdk_pixbuf_new_from_data(list_image->rgba_data->Pixels(),
+ GDK_COLORSPACE_RGB,
+ TRUE,
+ 8,
+ list_image->rgba_data->GetWidth(),
+ list_image->rgba_data->GetHeight(),
+ list_image->rgba_data->GetWidth() * 4,
+ NULL,
+ NULL);
+ }
}
#define SPACING 5
@@ -2481,11 +2632,17 @@ void ListBoxX::Select(int n) {
// Move the scrollbar to show the selection.
int total = Length();
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkAdjustment *adj =
+ gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(list));
+ gfloat value = ((gfloat)n / total) * (gtk_adjustment_get_upper(adj) - gtk_adjustment_get_lower(adj))
+ + gtk_adjustment_get_lower(adj) - gtk_adjustment_get_page_size(adj) / 2;
+#else
GtkAdjustment *adj =
gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(list));
gfloat value = ((gfloat)n / total) * (adj->upper - adj->lower)
+ adj->lower - adj->page_size / 2;
-
+#endif
// Get cell height
int row_width;
int row_height;
@@ -2504,8 +2661,13 @@ void ListBoxX::Select(int n) {
}
// Clamp it.
value = (value < 0)? 0 : value;
+#if GTK_CHECK_VERSION(3,0,0)
+ value = (value > (gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj)))?
+ (gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj)) : value;
+#else
value = (value > (adj->upper - adj->page_size))?
(adj->upper - adj->page_size) : value;
+#endif
// Set it.
gtk_adjustment_set_value(adj, value);
@@ -2571,13 +2733,8 @@ void ListBoxX::GetValue(int n, char *value, int len) {
#pragma warning(disable: 4127)
#endif
-void ListBoxX::RegisterImage(int type, const char *xpm_data) {
- g_return_if_fail(xpm_data);
-
- // Saved and use the saved copy so caller's copy can disappear.
- xset.Add(type, xpm_data);
- XPM *pxpm = xset.Get(type);
- xpm_data = reinterpret_cast<const char *>(pxpm->InLinesForm());
+void ListBoxX::RegisterRGBA(int type, RGBAImage *image) {
+ images.Add(type, image);
if (!pixhash) {
pixhash = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -2589,17 +2746,27 @@ void ListBoxX::RegisterImage(int type, const char *xpm_data) {
if (list_image->pixbuf)
g_object_unref(list_image->pixbuf);
list_image->pixbuf = NULL;
- list_image->xpm_data = xpm_data;
+ list_image->rgba_data = image;
} else {
list_image = g_new0(ListImage, 1);
- list_image->xpm_data = xpm_data;
+ list_image->rgba_data = image;
g_hash_table_insert((GHashTable *) pixhash, GINT_TO_POINTER(type),
(gpointer) list_image);
}
}
+void ListBoxX::RegisterImage(int type, const char *xpm_data) {
+ g_return_if_fail(xpm_data);
+ XPM xpmImage(xpm_data);
+ RegisterRGBA(type, new RGBAImage(xpmImage));
+}
+
+void ListBoxX::RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) {
+ RegisterRGBA(type, new RGBAImage(width, height, pixelsImage));
+}
+
void ListBoxX::ClearRegisteredImages() {
- xset.Clear();
+ images.Clear();
}
void ListBoxX::SetList(const char *listText, char separator, char typesep) {
@@ -2663,7 +2830,11 @@ void Menu::Show(Point pt, Window &) {
GtkMenu *widget = reinterpret_cast<GtkMenu *>(mid);
gtk_widget_show_all(GTK_WIDGET(widget));
GtkRequisition requisition;
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_get_preferred_size(GTK_WIDGET(widget), NULL, &requisition);
+#else
gtk_widget_size_request(GTK_WIDGET(widget), &requisition);
+#endif
if ((pt.x + requisition.width) > screenWidth) {
pt.x = screenWidth - requisition.width;
}
@@ -2791,7 +2962,8 @@ bool Platform::IsDBCSLeadByte(int codePage, char ch) {
case 932:
// Shift_jis
return ((uch >= 0x81) && (uch <= 0x9F)) ||
- ((uch >= 0xE0) && (uch <= 0xEF));
+ ((uch >= 0xE0) && (uch <= 0xFC));
+ // Lead bytes F0 to FC may be a Microsoft addition.
case 936:
// GBK
return (uch >= 0x81) && (uch <= 0xFE);
View
645 scintilla/gtk/ScintillaGTK.cxx
@@ -13,6 +13,7 @@
#include <string>
#include <vector>
+#include <map>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
@@ -20,7 +21,7 @@
#include "Platform.h"
#if PLAT_GTK_WIN32
-#include "windows.h"
+#include <windows.h>
#endif
#include "ILexer.h"
@@ -52,8 +53,6 @@
#include "ScintillaBase.h"
#include "UniConversion.h"
-#include "gtk/gtksignal.h"
-#include "gtk/gtkmarshal.h"
#include "scintilla-marshal.h"
#ifdef SCI_LEXER
@@ -75,9 +74,24 @@
#define IS_WIDGET_VISIBLE(w) (GTK_WIDGET_VISIBLE(w))
#endif
-#if GTK_CHECK_VERSION(2,22,0)
#define USE_CAIRO 1
+
+static GdkWindow *WindowFromWidget(GtkWidget *w) {
+#if GTK_CHECK_VERSION(3,0,0)
+ return gtk_widget_get_window(w);
+#else
+ return w->window;
+#endif
+}
+
+static GdkWindow *PWindow(const Window &w) {
+ GtkWidget *widget = reinterpret_cast<GtkWidget *>(w.GetID());
+#if GTK_CHECK_VERSION(3,0,0)
+ return gtk_widget_get_window(widget);
+#else
+ return widget->window;
#endif
+}
#ifdef _MSC_VER
// Constant conditional expressions are because of GTK+ headers
@@ -103,8 +117,8 @@ class ScintillaGTK : public ScintillaBase {
Window wText;
Window scrollbarv;
Window scrollbarh;
- GtkObject *adjustmentv;
- GtkObject *adjustmenth;
+ GtkAdjustment *adjustmentv;
+ GtkAdjustment *adjustmenth;
int scrollBarWidth;
int scrollBarHeight;
@@ -144,7 +158,11 @@ class ScintillaGTK : public ScintillaBase {
gint lastWheelMouseDirection;
gint wheelMouseIntensity;
+#if GTK_CHECK_VERSION(3,0,0)
+ cairo_rectangle_list_t *rgnUpdate;
+#else
GdkRegion *rgnUpdate;
+#endif
// Private so ScintillaGTK objects can not be copied
ScintillaGTK(const ScintillaGTK &);
@@ -223,9 +241,20 @@ class ScintillaGTK : public ScintillaBase {
gint FocusOutThis(GtkWidget *widget);
static gint FocusOut(GtkWidget *widget, GdkEventFocus *event);
static void SizeRequest(GtkWidget *widget, GtkRequisition *requisition);
+ static void GetPreferredWidth(GtkWidget *widget, gint *minimalWidth, gint *naturalWidth);
+ static void GetPreferredHeight(GtkWidget *widget, gint *minimalHeight, gint *naturalHeight);
static void SizeAllocate(GtkWidget *widget, GtkAllocation *allocation);
- gint Expose(GtkWidget *widget, GdkEventExpose *ose);
- static gint ExposeMain(GtkWidget *widget, GdkEventExpose *ose);
+#if GTK_CHECK_VERSION(3,0,0)
+ gboolean DrawTextThis(cairo_t *cr);
+ static gboolean DrawText(GtkWidget *widget, cairo_t *cr, ScintillaGTK *sciThis);
+ gboolean DrawThis(cairo_t *cr);
+ static gboolean DrawMain(GtkWidget *widget, cairo_t *cr);
+#else
+ gboolean ExposeTextThis(GtkWidget *widget, GdkEventExpose *ose);
+ static gboolean ExposeText(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis);
+ gboolean Expose(GtkWidget *widget, GdkEventExpose *ose);
+ static gboolean ExposeMain(GtkWidget *widget, GdkEventExpose *ose);
+#endif
static void Draw(GtkWidget *widget, GdkRectangle *area);
void ForAll(GtkCallback callback, gpointer callback_data);
static void MainForAll(GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data);
@@ -240,14 +269,19 @@ class ScintillaGTK : public ScintillaBase {
gboolean KeyThis(GdkEventKey *event);
static gboolean KeyPress(GtkWidget *widget, GdkEventKey *event);
static gboolean KeyRelease(GtkWidget *widget, GdkEventKey *event);
+#if GTK_CHECK_VERSION(3,0,0)
+ gboolean DrawPreeditThis(GtkWidget *widget, cairo_t *cr);
+ static gboolean DrawPreedit(GtkWidget *widget, cairo_t *cr, ScintillaGTK *sciThis);
+#else
gboolean ExposePreeditThis(GtkWidget *widget, GdkEventExpose *ose);
static gboolean ExposePreedit(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis);
+#endif
void CommitThis(char *str);
static void Commit(GtkIMContext *context, char *str, ScintillaGTK *sciThis);
void PreeditChangedThis();
static void PreeditChanged(GtkIMContext *context, ScintillaGTK *sciThis);
- static gint StyleSetText(GtkWidget *widget, GtkStyle *previous, void*);
- static gint RealizeText(GtkWidget *widget, void*);
+ static void StyleSetText(GtkWidget *widget, GtkStyle *previous, void*);
+ static void RealizeText(GtkWidget *widget, void*);
static void Destroy(GObject *object);
static void SelectionReceived(GtkWidget *widget, GtkSelectionData *selection_data,
guint time);
@@ -267,17 +301,18 @@ class ScintillaGTK : public ScintillaBase {
gint x, gint y, GtkSelectionData *selection_data, guint info, guint time);
static void DragDataGet(GtkWidget *widget, GdkDragContext *context,
GtkSelectionData *selection_data, guint info, guint time);
- static gint TimeOut(ScintillaGTK *sciThis);
+ static gboolean TimeOut(ScintillaGTK *sciThis);
static gboolean IdleCallback(ScintillaGTK *sciThis);
static gboolean StyleIdle(ScintillaGTK *sciThis);
virtual void QueueStyling(int upTo);
static void PopUpCB(GtkMenuItem *menuItem, ScintillaGTK *sciThis);
- gint ExposeTextThis(GtkWidget *widget, GdkEventExpose *ose);
- static gint ExposeText(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis);
-
- static gint ExposeCT(GtkWidget *widget, GdkEventExpose *ose, CallTip *ct);
- static gint PressCT(GtkWidget *widget, GdkEventButton *event, ScintillaGTK *sciThis);
+#if GTK_CHECK_VERSION(3,0,0)
+ static gboolean DrawCT(GtkWidget *widget, cairo_t *cr, CallTip *ctip);
+#else
+ static gboolean ExposeCT(GtkWidget *widget, GdkEventExpose *ose, CallTip *ct);
+#endif
+ static gboolean PressCT(GtkWidget *widget, GdkEventButton *event, ScintillaGTK *sciThis);
static sptr_t DirectFunction(ScintillaGTK *sciThis,
unsigned int iMessage, uptr_t wParam, sptr_t lParam);
@@ -370,6 +405,14 @@ ScintillaGTK::~ScintillaGTK() {
g_idle_remove_by_data(this);
}
+static void UnRefCursor(GdkCursor *cursor) {
+#if GTK_CHECK_VERSION(3,0,0)
+ g_object_unref(cursor);
+#else
+ gdk_cursor_unref(cursor);
+#endif
+}
+
void ScintillaGTK::RealizeThis(GtkWidget *widget) {
//Platform::DebugPrintf("ScintillaGTK::realize this\n");
#if GTK_CHECK_VERSION(2,20,0)
@@ -379,28 +422,55 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) {
#endif
GdkWindowAttr attrs;
attrs.window_type = GDK_WINDOW_CHILD;
- attrs.x = widget->allocation.x;
- attrs.y = widget->allocation.y;
- attrs.width = widget->allocation.width;
- attrs.height = widget->allocation.height;
+ GtkAllocation allocation;
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_get_allocation(widget, &allocation);
+#else
+ allocation = widget->allocation;
+#endif
+ attrs.x = allocation.x;
+ attrs.y = allocation.y;
+ attrs.width = allocation.width;
+ attrs.height = allocation.height;
attrs.wclass = GDK_INPUT_OUTPUT;
attrs.visual = gtk_widget_get_visual(widget);
+#if !GTK_CHECK_VERSION(3,0,0)
attrs.colormap = gtk_widget_get_colormap(widget);
+#endif
attrs.event_mask = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK;
GdkCursor *cursor = gdk_cursor_new(GDK_XTERM);
attrs.cursor = cursor;
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_set_window(widget, gdk_window_new(gtk_widget_get_parent_window(widget), &attrs,
+ GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_CURSOR));
+ gdk_window_set_user_data(gtk_widget_get_window(widget), widget);
+ GtkStyleContext *styleContext = gtk_widget_get_style_context(widget);
+ if (styleContext) {
+ GdkRGBA colourBackWidget;
+ gtk_style_context_get_background_color(styleContext, GTK_STATE_FLAG_NORMAL, &colourBackWidget);
+ gdk_window_set_background_rgba(gtk_widget_get_window(widget), &colourBackWidget);
+ }
+ gdk_window_show(gtk_widget_get_window(widget));
+ UnRefCursor(cursor);
+#else
widget->window = gdk_window_new(gtk_widget_get_parent_window(widget), &attrs,
GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_CURSOR);
gdk_window_set_user_data(widget->window, widget);
+ widget->style = gtk_style_attach(widget->style, widget->window);
gdk_window_set_background(widget->window, &widget->style->bg[GTK_STATE_NORMAL]);
gdk_window_show(widget->window);
- gdk_cursor_unref(cursor);
- widget->style = gtk_style_attach(widget->style, widget->window);
+ UnRefCursor(cursor);
+#endif
wPreedit = gtk_window_new(GTK_WINDOW_POPUP);
wPreeditDraw = gtk_drawing_area_new();
GtkWidget *predrw = PWidget(wPreeditDraw); // No code inside the G_OBJECT macro
+#if GTK_CHECK_VERSION(3,0,0)
+ g_signal_connect(G_OBJECT(predrw), "draw",
+ G_CALLBACK(DrawPreedit), this);
+#else
g_signal_connect(G_OBJECT(predrw), "expose_event",
G_CALLBACK(ExposePreedit), this);
+#endif
gtk_container_add(GTK_CONTAINER(PWidget(wPreedit)), predrw);
gtk_widget_realize(PWidget(wPreedit));
gtk_widget_realize(predrw);
@@ -411,7 +481,7 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) {
G_CALLBACK(Commit), this);
g_signal_connect(G_OBJECT(im_context), "preedit_changed",
G_CALLBACK(PreeditChanged), this);
- gtk_im_context_set_client_window(im_context, widget->window);
+ gtk_im_context_set_client_window(im_context, WindowFromWidget(widget));
GtkWidget *widtxt = PWidget(wText); // // No code inside the G_OBJECT macro
g_signal_connect_after(G_OBJECT(widtxt), "style_set",
G_CALLBACK(ScintillaGTK::StyleSetText), NULL);
@@ -422,20 +492,19 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) {
gtk_widget_realize(PWidget(scrollbarh));
cursor = gdk_cursor_new(GDK_XTERM);
- gdk_window_set_cursor(PWidget(wText)->window, cursor);
- gdk_cursor_unref(cursor);
+ gdk_window_set_cursor(PWindow(wText), cursor);
+ UnRefCursor(cursor);
cursor = gdk_cursor_new(GDK_LEFT_PTR);
- gdk_window_set_cursor(PWidget(scrollbarv)->window, cursor);
- gdk_cursor_unref(cursor);
+ gdk_window_set_cursor(PWindow(scrollbarv), cursor);
+ UnRefCursor(cursor);
cursor = gdk_cursor_new(GDK_LEFT_PTR);
- gdk_window_set_cursor(PWidget(scrollbarh)->window, cursor);
- gdk_cursor_unref(cursor);
+ gdk_window_set_cursor(PWindow(scrollbarh), cursor);
+ UnRefCursor(cursor);
gtk_selection_add_targets(widget, GDK_SELECTION_PRIMARY,
clipboardCopyTargets, nClipboardCopyTargets);
-
#ifndef USE_GTK_CLIPBOARD
gtk_selection_add_targets(widget, atomClipboard,
clipboardPasteTargets, nClipboardPasteTargets);
@@ -449,14 +518,11 @@ void ScintillaGTK::Realize(GtkWidget *widget) {
void ScintillaGTK::UnRealizeThis(GtkWidget *widget) {
try {
-
gtk_selection_clear_targets(widget, GDK_SELECTION_PRIMARY);
-
#ifndef USE_GTK_CLIPBOARD
gtk_selection_clear_targets(widget, atomClipboard);
#endif
-
if (IS_WIDGET_MAPPED(widget)) {
gtk_widget_unmap(widget);
}
@@ -509,7 +575,7 @@ void ScintillaGTK::MapThis() {
scrollbarv.SetCursor(Window::cursorArrow);
scrollbarh.SetCursor(Window::cursorArrow);
ChangeSize();
- gdk_window_show(PWidget(wMain)->window);
+ gdk_window_show(PWindow(wMain));
} catch (...) {
errorStatus = SC_STATUS_FAILURE;
}
@@ -529,7 +595,7 @@ void ScintillaGTK::UnMapThis() {
GTK_WIDGET_UNSET_FLAGS(PWidget(wMain), GTK_MAPPED);
#endif
DropGraphics();
- gdk_window_hide(PWidget(wMain)->window);
+ gdk_window_hide(PWindow(wMain));
gtk_widget_unmap(PWidget(wText));
gtk_widget_unmap(PWidget(scrollbarh));
gtk_widget_unmap(PWidget(scrollbarv));
@@ -613,23 +679,44 @@ gint ScintillaGTK::FocusOut(GtkWidget *widget, GdkEventFocus * /*event*/) {
void ScintillaGTK::SizeRequest(GtkWidget *widget, GtkRequisition *requisition) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
- requisition->width = 600;
- requisition->height = gdk_screen_height();
+ requisition->width = 1;
+ requisition->height = 1;
GtkRequisition child_requisition;
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_get_preferred_size(PWidget(sciThis->scrollbarh), NULL, &child_requisition);
+ gtk_widget_get_preferred_size(PWidget(sciThis->scrollbarv), NULL, &child_requisition);
+#else
gtk_widget_size_request(PWidget(sciThis->scrollbarh), &child_requisition);
gtk_widget_size_request(PWidget(sciThis->scrollbarv), &child_requisition);
+#endif
+}
+
+void ScintillaGTK::GetPreferredWidth(GtkWidget *widget, gint *minimalWidth, gint *naturalWidth) {
+ GtkRequisition requisition;
+ SizeRequest(widget, &requisition);
+ *minimalWidth = *naturalWidth = requisition.width;
+}
+
+void ScintillaGTK::GetPreferredHeight(GtkWidget *widget, gint *minimalHeight, gint *naturalHeight) {
+ GtkRequisition requisition;
+ SizeRequest(widget, &requisition);
+ *minimalHeight = *naturalHeight = requisition.height;
}
void ScintillaGTK::SizeAllocate(GtkWidget *widget, GtkAllocation *allocation) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
try {
+#if GTK_CHECK_VERSION(2,20,0)
+ gtk_widget_set_allocation(widget, allocation);
+#else
widget->allocation = *allocation;
+#endif
if (IS_WIDGET_REALIZED(widget))
- gdk_window_move_resize(widget->window,
- widget->allocation.x,
- widget->allocation.y,
- widget->allocation.width,
- widget->allocation.height);
+ gdk_window_move_resize(WindowFromWidget(widget),
+ allocation->x,
+ allocation->y,
+ allocation->width,
+ allocation->height);
sciThis->Resize(allocation->width, allocation->height);
@@ -666,13 +753,18 @@ void ScintillaGTK::Initialise() {
gtk_widget_set_parent(PWidget(wText), PWidget(wMain));
GtkWidget *widtxt = PWidget(wText); // No code inside the G_OBJECT macro
gtk_widget_show(widtxt);
+#if GTK_CHECK_VERSION(3,0,0)
+ g_signal_connect(G_OBJECT(widtxt), "draw",
+ G_CALLBACK(ScintillaGTK::DrawText), this);
+#else
g_signal_connect(G_OBJECT(widtxt), "expose_event",
G_CALLBACK(ScintillaGTK::ExposeText), this);
+#endif
gtk_widget_set_events(widtxt, GDK_EXPOSURE_MASK);
// Avoid background drawing flash
gtk_widget_set_double_buffered(widtxt, FALSE);
gtk_widget_set_size_request(widtxt, 100, 100);
- adjustmentv = gtk_adjustment_new(0.0, 0.0, 201.0, 1.0, 20.0, 20.0);
+ adjustmentv = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 201.0, 1.0, 20.0, 20.0));
scrollbarv = gtk_vscrollbar_new(GTK_ADJUSTMENT(adjustmentv));
#if GTK_CHECK_VERSION(2,20,0)
gtk_widget_set_can_focus(PWidget(scrollbarv), FALSE);
@@ -684,7 +776,7 @@ void ScintillaGTK::Initialise() {
gtk_widget_set_parent(PWidget(scrollbarv), PWidget(wMain));
gtk_widget_show(PWidget(scrollbarv));
- adjustmenth = gtk_adjustment_new(0.0, 0.0, 101.0, 1.0, 20.0, 20.0);
+ adjustmenth = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 101.0, 1.0, 20.0, 20.0));
scrollbarh = gtk_hscrollbar_new(GTK_ADJUSTMENT(adjustmenth));
#if GTK_CHECK_VERSION(2,20,0)
gtk_widget_set_can_focus(PWidget(scrollbarh), FALSE);
@@ -916,7 +1008,8 @@ void ScintillaGTK::SetTicking(bool on) {
if (timer.ticking != on) {
timer.ticking = on;
if (timer.ticking) {
- timer.tickerID = reinterpret_cast<TickerID>(g_timeout_add(timer.tickSize, (GtkFunction)TimeOut, this));
+ timer.tickerID = reinterpret_cast<TickerID>(g_timeout_add(timer.tickSize,
+ reinterpret_cast<GSourceFunc>(TimeOut), this));
} else {
g_source_remove(GPOINTER_TO_UINT(timer.tickerID));
}
@@ -958,17 +1051,46 @@ bool ScintillaGTK::HaveMouseCapture() {
return capturedMouse;
}
+#if GTK_CHECK_VERSION(3,0,0)
+
+// Is crcTest completely in crcContainer?
+static bool CRectContains(const cairo_rectangle_t &crcContainer, const cairo_rectangle_t &crcTest) {
+ return
+ (crcTest.x >= crcContainer.x) && ((crcTest.x + crcTest.width) <= (crcContainer.x + crcContainer.width)) &&
+ (crcTest.y >= crcContainer.y) && ((crcTest.y + crcTest.height) <= (crcContainer.y + crcContainer.height));
+}
+
+// Is crcTest completely in crcListContainer?
+// May incorrectly return false if complex shape
+static bool CRectListContains(const cairo_rectangle_list_t *crcListContainer, const cairo_rectangle_t &crcTest) {
+ for (int r=0; r<crcListContainer->num_rectangles; r++) {
+ if (CRectContains(crcListContainer->rectangles[r], crcTest))
+ return true;
+ }
+ return false;
+}
+
+#endif
+
bool ScintillaGTK::PaintContains(PRectangle rc) {
+ // This allows optimization when a rectangle is completely in the update region.
+ // It is OK to return false when too difficult to determine as that just performs extra drawing
bool contains = true;
if (paintState == painting) {
if (!rcPaint.Contains(rc)) {
contains = false;
} else if (rgnUpdate) {
+#if GTK_CHECK_VERSION(3,0,0)
+ cairo_rectangle_t grc = {rc.left, rc.top,
+ rc.right - rc.left, rc.bottom - rc.top};
+ contains = CRectListContains(rgnUpdate, grc);
+#else
GdkRectangle grc = {rc.left, rc.top,
rc.right - rc.left, rc.bottom - rc.top};
if (gdk_region_rect_in(rgnUpdate, &grc) != GDK_OVERLAP_RECTANGLE_IN) {
contains = false;
}
+#endif
}
}
return contains;
@@ -999,13 +1121,21 @@ void ScintillaGTK::SyncPaint(PRectangle rc) {
rcPaint = rc;
PRectangle rcClient = GetClientRectangle();
paintingAllText = rcPaint.Contains(rcClient);
- if ((PWidget(wText))->window) {
+ if (PWindow(wText)) {
Surface *sw = Surface::Allocate();
if (sw) {
- sw->Init(PWidget(wText)->window, PWidget(wText));
+#if GTK_CHECK_VERSION(3,0,0)
+ cairo_t *cr = gdk_cairo_create(PWindow(wText));
+ sw->Init(cr, PWidget(wText));
+#else
+ sw->Init(PWindow(wText), PWidget(wText));
+#endif
Paint(sw, rc);
sw->Release();
delete sw;
+#if GTK_CHECK_VERSION(3,0,0)
+ cairo_destroy(cr);
+#endif
}
}
if (paintState == paintAbandoned) {
@@ -1021,8 +1151,8 @@ void ScintillaGTK::ScrollText(int linesToMove) {
// rc.left, rc.top, rc.right, rc.bottom);
GtkWidget *wi = PWidget(wText);
- gdk_window_scroll(wi->window, 0, -diff);
- gdk_window_process_updates(wi->window, FALSE);
+ gdk_window_scroll(WindowFromWidget(wi), 0, -diff);
+ gdk_window_process_updates(WindowFromWidget(wi), FALSE);
}
void ScintillaGTK::SetVerticalScrollPos() {
@@ -1039,6 +1169,17 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) {
bool modified = false;
int pageScroll = LinesToScroll();
+#if GTK_CHECK_VERSION(3,0,0)
+ if (gtk_adjustment_get_upper(adjustmentv) != (nMax + 1) ||
+ gtk_adjustment_get_page_size(adjustmentv) != nPage ||
+ gtk_adjustment_get_page_increment(adjustmentv) != pageScroll) {
+ gtk_adjustment_set_upper(adjustmentv, nMax + 1);
+ gtk_adjustment_set_page_size(adjustmentv, nPage);
+ gtk_adjustment_set_page_increment(adjustmentv, pageScroll);
+ gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmentv));
+ modified = true;
+ }
+#else
if (GTK_ADJUSTMENT(adjustmentv)->upper != (nMax + 1) ||
GTK_ADJUSTMENT(adjustmentv)->page_size != nPage ||
GTK_ADJUSTMENT(adjustmentv)->page_increment != pageScroll) {
@@ -1048,6 +1189,7 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) {
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmentv));
modified = true;
}
+#endif
PRectangle rcText = GetTextRectangle();
int horizEndPreferred = scrollWidth;
@@ -1056,6 +1198,19 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) {
unsigned int pageWidth = rcText.Width();
unsigned int pageIncrement = pageWidth / 3;
unsigned int charWidth = vs.styles[STYLE_DEFAULT].aveCharWidth;
+#if GTK_CHECK_VERSION(3,0,0)
+ if (gtk_adjustment_get_upper(adjustmenth) != horizEndPreferred ||
+ gtk_adjustment_get_page_size(adjustmenth) != pageWidth ||
+ gtk_adjustment_get_page_increment(adjustmenth) != pageIncrement ||
+ gtk_adjustment_get_step_increment(adjustmenth) != charWidth) {
+ gtk_adjustment_set_upper(adjustmenth, horizEndPreferred);
+ gtk_adjustment_set_page_size(adjustmenth, pageWidth);
+ gtk_adjustment_set_page_increment(adjustmenth, pageIncrement);
+ gtk_adjustment_set_step_increment(adjustmenth, charWidth);
+ gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmenth));
+ modified = true;
+ }
+#else
if (GTK_ADJUSTMENT(adjustmenth)->upper != horizEndPreferred ||
GTK_ADJUSTMENT(adjustmenth)->page_size != pageWidth ||
GTK_ADJUSTMENT(adjustmenth)->page_increment != pageIncrement ||
@@ -1067,6 +1222,7 @@ bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) {
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmenth));
modified = true;
}
+#endif
return modified;
}
@@ -1324,8 +1480,13 @@ void ScintillaGTK::CreateCallTipWindow(PRectangle rc) {
ct.wDraw = gtk_drawing_area_new();
GtkWidget *widcdrw = PWidget(ct.wDraw); // // No code inside the G_OBJECT macro
gtk_container_add(GTK_CONTAINER(PWidget(ct.wCallTip)), widcdrw);
+#if GTK_CHECK_VERSION(3,0,0)
+ g_signal_connect(G_OBJECT(widcdrw), "draw",
+ G_CALLBACK(ScintillaGTK::DrawCT), &ct);
+#else
g_signal_connect(G_OBJECT(widcdrw), "expose_event",
G_CALLBACK(ScintillaGTK::ExposeCT), &ct);
+#endif
g_signal_connect(G_OBJECT(widcdrw), "button_press_event",
G_CALLBACK(ScintillaGTK::PressCT), static_cast<void *>(this));
gtk_widget_set_events(widcdrw,
@@ -1333,8 +1494,8 @@ void ScintillaGTK::CreateCallTipWindow(PRectangle rc) {
}
gtk_widget_set_size_request(PWidget(ct.wDraw), rc.Width(), rc.Height());
ct.wDraw.Show();
- if (PWidget(ct.wCallTip)->window) {
- gdk_window_resize(PWidget(ct.wCallTip)->window, rc.Width(), rc.Height());
+ if (PWindow(ct.wCallTip)) {
+ gdk_window_resize(PWindow(ct.wCallTip), rc.Width(), rc.Height());
}
}
@@ -1356,8 +1517,8 @@ void ScintillaGTK::AddToPopUp(const char *label, int cmd, bool enabled) {
bool ScintillaGTK::OwnPrimarySelection() {
return ((gdk_selection_owner_get(GDK_SELECTION_PRIMARY)
- == GTK_WIDGET(PWidget(wMain))->window) &&
- (GTK_WIDGET(PWidget(wMain))->window != NULL));
+ == PWindow(wMain)) &&
+ (PWindow(wMain) != NULL));
}
void ScintillaGTK::ClaimSelection() {
@@ -1378,11 +1539,23 @@ void ScintillaGTK::ClaimSelection() {
}
}
+#if GTK_CHECK_VERSION(3,0,0)
+static const guchar *DataOfGSD(GtkSelectionData *sd) { return gtk_selection_data_get_data(sd); }
+static gint LengthOfGSD(GtkSelectionData *sd) { return gtk_selection_data_get_length(sd); }
+static GdkAtom TypeOfGSD(GtkSelectionData *sd) { return gtk_selection_data_get_data_type(sd); }
+static GdkAtom SelectionOfGSD(GtkSelectionData *sd) { return gtk_selection_data_get_selection(sd); }
+#else
+static const guchar *DataOfGSD(GtkSelectionData *sd) { return sd->data; }
+static gint LengthOfGSD(GtkSelectionData *sd) { return sd->length; }
+static GdkAtom TypeOfGSD(GtkSelectionData *sd) { return sd->type; }
+static GdkAtom SelectionOfGSD(GtkSelectionData *sd) { return sd->selection; }
+#endif
+
// Detect rectangular text, convert line ends to current mode, convert from or to UTF-8
void ScintillaGTK::GetGtkSelectionText(GtkSelectionData *selectionData, SelectionText &selText) {
- char *data = reinterpret_cast<char *>(selectionData->data);
- int len = selectionData->length;
- GdkAtom selectionTypeData = selectionData->type;
+ const char *data = reinterpret_cast<const char *>(DataOfGSD(selectionData));
+ int len = LengthOfGSD(selectionData);
+ GdkAtom selectionTypeData = TypeOfGSD(selectionData);
// Return empty string if selection is not a string
if ((selectionTypeData != GDK_TARGET_STRING) && (selectionTypeData != atomUTF8)) {
@@ -1431,19 +1604,19 @@ void ScintillaGTK::GetGtkSelectionText(GtkSelectionData *selectionData, Selectio
void ScintillaGTK::ReceivedSelection(GtkSelectionData *selection_data) {
try {
- if ((selection_data->selection == atomClipboard) ||
- (selection_data->selection == GDK_SELECTION_PRIMARY)) {
- if ((atomSought == atomUTF8) && (selection_data->length <= 0)) {
+ if ((SelectionOfGSD(selection_data) == atomClipboard) ||
+ (SelectionOfGSD(selection_data) == GDK_SELECTION_PRIMARY)) {
+ if ((atomSought == atomUTF8) && (LengthOfGSD(selection_data) <= 0)) {
atomSought = atomString;
gtk_selection_convert(GTK_WIDGET(PWidget(wMain)),
- selection_data->selection, atomSought, GDK_CURRENT_TIME);
- } else if ((selection_data->length > 0) &&
- ((selection_data->type == GDK_TARGET_STRING) || (selection_data->type == atomUTF8))) {
+ SelectionOfGSD(selection_data), atomSought, GDK_CURRENT_TIME);
+ } else if ((LengthOfGSD(selection_data) > 0) &&
+ ((TypeOfGSD(selection_data) == GDK_TARGET_STRING) || (TypeOfGSD(selection_data) == atomUTF8))) {
SelectionText selText;
GetGtkSelectionText(selection_data, selText);
UndoGroup ug(pdoc);
- if (selection_data->selection != GDK_SELECTION_PRIMARY) {
+ if (SelectionOfGSD(selection_data) != GDK_SELECTION_PRIMARY) {
ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH);
}
SelectionPosition selStart = sel.IsRectangular() ?
@@ -1468,19 +1641,19 @@ void ScintillaGTK::ReceivedSelection(GtkSelectionData *selection_data) {
void ScintillaGTK::ReceivedDrop(GtkSelectionData *selection_data) {
dragWasDropped = true;
- if (selection_data->type == atomUriList || selection_data->type == atomDROPFILES_DND) {
- char *ptr = new char[selection_data->length + 1];
- ptr[selection_data->length] = '\0';
- memcpy(ptr, selection_data->data, selection_data->length);
+ if (TypeOfGSD(selection_data) == atomUriList || TypeOfGSD(selection_data) == atomDROPFILES_DND) {
+ char *ptr = new char[LengthOfGSD(selection_data) + 1];
+ ptr[LengthOfGSD(selection_data)] = '\0';
+ memcpy(ptr, DataOfGSD(selection_data), LengthOfGSD(selection_data));
NotifyURIDropped(ptr);
delete []ptr;
- } else if ((selection_data->type == GDK_TARGET_STRING) || (selection_data->type == atomUTF8)) {
- if (selection_data->length > 0) {
+ } else if ((TypeOfGSD(selection_data) == GDK_TARGET_STRING) || (TypeOfGSD(selection_data) == atomUTF8)) {
+ if (TypeOfGSD(selection_data) > 0) {
SelectionText selText;
GetGtkSelectionText(selection_data, selText);
DropAt(posDrop, selText.s, false, selText.rectangular);
}
- } else if (selection_data->length > 0) {
+ } else if (LengthOfGSD(selection_data) > 0) {
//~ fprintf(stderr, "ReceivedDrop other %p\n", static_cast<void *>(selection_data->type));
}
Redraw();
@@ -1588,8 +1761,16 @@ void ScintillaGTK::Resize(int width, int height) {
//printf("Resize %d %d\n", width, height);
// Not always needed, but some themes can have different sizes of scrollbars
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkRequisition requisition;
+ gtk_widget_get_requisition(PWidget(scrollbarv), &requisition);
+ scrollBarWidth = requisition.width;
+ gtk_widget_get_requisition(PWidget(scrollbarh), &requisition);
+ scrollBarHeight = requisition.height;
+#else
scrollBarWidth = GTK_WIDGET(PWidget(scrollbarv))->requisition.width;
scrollBarHeight = GTK_WIDGET(PWidget(scrollbarh))->requisition.height;
+#endif
// These allocations should never produce negative sizes as they would wrap around to huge
// unsigned numbers inside GTK+ causing warnings.
@@ -1603,7 +1784,7 @@ void ScintillaGTK::Resize(int width, int height) {
gtk_widget_show(GTK_WIDGET(PWidget(scrollbarh)));
alloc.x = 0;
alloc.y = height - scrollBarHeight;
- alloc.width = Platform::Maximum(1, width - scrollBarWidth) + 1;
+ alloc.width = Platform::Maximum(1, width - scrollBarWidth);
alloc.height = horizontalScrollBarHeight;
gtk_widget_size_allocate(GTK_WIDGET(PWidget(scrollbarh)), &alloc);
} else {
@@ -1615,7 +1796,7 @@ void ScintillaGTK::Resize(int width, int height) {
alloc.x = width - scrollBarWidth;
alloc.y = 0;
alloc.width = scrollBarWidth;
- alloc.height = Platform::Maximum(1, height - scrollBarHeight) + 1;
+ alloc.height = Platform::Maximum(1, height - scrollBarHeight);
if (!showSBHorizontal)
alloc.height += scrollBarWidth-1;
gtk_widget_size_allocate(GTK_WIDGET(PWidget(scrollbarv)), &alloc);
@@ -1637,10 +1818,16 @@ void ScintillaGTK::Resize(int width, int height) {
gtk_widget_size_allocate(GTK_WIDGET(PWidget(wText)), &alloc);
}
-static void SetAdjustmentValue(GtkObject *object, int value) {
+static void SetAdjustmentValue(GtkAdjustment *object, int value) {
GtkAdjustment *adjustment = GTK_ADJUSTMENT(object);
+#if GTK_CHECK_VERSION(3,0,0)
+ int maxValue = static_cast<int>(
+ gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment));
+#else
int maxValue = static_cast<int>(
adjustment->upper - adjustment->page_size);
+#endif
+
if (value > maxValue)
value = maxValue;
if (value < 0)
@@ -1705,12 +1892,14 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) {
gtk_selection_convert(GTK_WIDGET(PWidget(wMain)), GDK_SELECTION_PRIMARY,
atomSought, event->time);
} else if (event->button == 3) {
+ if (!PointInSelection(pt))
+ SetEmptySelection(PositionFromLocation(pt));
if (displayPopupMenu) {
// PopUp menu
// Convert to screen
int ox = 0;
int oy = 0;
- gdk_window_get_origin(PWidget(wMain)->window, &ox, &oy);
+ gdk_window_get_origin(PWindow(wMain), &ox, &oy);
ContextMenu(Point(pt.x + ox, pt.y + oy));
} else {
return FALSE;
@@ -1735,7 +1924,7 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) {
}
gint ScintillaGTK::Press(GtkWidget *widget, GdkEventButton *event) {
- if (event->window != widget->window)
+ if (event->window != WindowFromWidget(widget))
return FALSE;
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
return sciThis->PressThis(event);
@@ -1753,7 +1942,7 @@ gint ScintillaGTK::MouseRelease(GtkWidget *widget, GdkEventButton *event) {
pt.y = int(event->y);
//Platform::DebugPrintf("Up %x %x %d %d %d\n",
// sciThis,event->window,event->time, pt.x, pt.y);
- if (event->window != PWidget(sciThis->wMain)->window)
+ if (event->window != PWindow(sciThis->wMain))
// 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;
@@ -1848,7 +2037,7 @@ gint ScintillaGTK::Motion(GtkWidget *widget, GdkEventMotion *event) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
try {
//Platform::DebugPrintf("Motion %x %d\n",sciThis,event->time);
- if (event->window != widget->window)
+ if (event->window != WindowFromWidget(widget))
return FALSE;
int x = 0;
int y = 0;
@@ -1873,6 +2062,75 @@ gint ScintillaGTK::Motion(GtkWidget *widget, GdkEventMotion *event) {
// Map the keypad keys to their equivalent functions
static int KeyTranslate(int keyIn) {
switch (keyIn) {
+#if GTK_CHECK_VERSION(3,0,0)
+ case GDK_KEY_ISO_Left_Tab:
+ return SCK_TAB;
+ case GDK_KEY_KP_Down:
+ return SCK_DOWN;
+ case GDK_KEY_KP_Up:
+ return SCK_UP;
+ case GDK_KEY_KP_Left:
+ return SCK_LEFT;
+ case GDK_KEY_KP_Right:
+ return SCK_RIGHT;
+ case GDK_KEY_KP_Home:
+ return SCK_HOME;
+ case GDK_KEY_KP_End:
+ return SCK_END;
+ case GDK_KEY_KP_Page_Up:
+ return SCK_PRIOR;
+ case GDK_KEY_KP_Page_Down:
+ return SCK_NEXT;
+ case GDK_KEY_KP_Delete:
+ return SCK_DELETE;
+ case GDK_KEY_KP_Insert:
+ return SCK_INSERT;
+ case GDK_KEY_KP_Enter:
+ return SCK_RETURN;
+
+ case GDK_KEY_Down:
+ return SCK_DOWN;
+ case GDK_KEY_Up:
+ return SCK_UP;
+ case GDK_KEY_Left:
+ return SCK_LEFT;
+ case GDK_KEY_Right:
+ return SCK_RIGHT;
+ case GDK_KEY_Home:
+ return SCK_HOME;
+ case GDK_KEY_End:
+ return SCK_END;
+ case GDK_KEY_Page_Up:
+ return SCK_PRIOR;
+ case GDK_KEY_Page_Down:
+ return SCK_NEXT;
+ case GDK_KEY_Delete:
+ return SCK_DELETE;
+ case GDK_KEY_Insert:
+ return SCK_INSERT;
+ case GDK_KEY_Escape:
+ return SCK_ESCAPE;
+ case GDK_KEY_BackSpace:
+ return SCK_BACK;
+ case GDK_KEY_Tab:
+ return SCK_TAB;
+ case GDK_KEY_Return:
+ return SCK_RETURN;
+ case GDK_KEY_KP_Add:
+ return SCK_ADD;
+ case GDK_KEY_KP_Subtract:
+ return SCK_SUBTRACT;
+ case GDK_KEY_KP_Divide:
+ return SCK_DIVIDE;
+ case GDK_KEY_Super_L:
+ return SCK_WIN;
+ case GDK_KEY_Super_R:
+ return SCK_RWIN;
+ case GDK_KEY_Menu:
+ return SCK_MENU;
+
+#else
+
case GDK_ISO_Left_Tab:
return SCK_TAB;
case GDK_KP_Down:
@@ -1938,6 +2196,7 @@ static int KeyTranslate(int keyIn) {
return SCK_RWIN;
case GDK_Menu:
return SCK_MENU;
+#endif
default:
return keyIn;
}
@@ -1958,9 +2217,13 @@ gboolean ScintillaGTK::KeyThis(GdkEventKey *event) {
bool ctrl = (event->state & GDK_CONTROL_MASK) != 0;
bool alt = (event->state & GDK_MOD1_MASK) != 0;
guint key = event->keyval;
- if (ctrl && (key < 128))
+ if ((ctrl || alt) && (key < 128))
key = toupper(key);
+#if GTK_CHECK_VERSION(3,0,0)
+ else if (!ctrl && (key >= GDK_KEY_KP_Multiply && key <= GDK_KEY_KP_9))
+#else
else if (!ctrl && (key >= GDK_KP_Multiply && key <= GDK_KP_9))
+#endif
key &= 0x7F;
// Hack for keys over 256 and below command keys but makes Hungarian work.
// This will have to change for Unicode
@@ -1968,7 +2231,17 @@ gboolean ScintillaGTK::KeyThis(GdkEventKey *event) {
key = KeyTranslate(key);
bool consumed = false;
+#if !(PLAT_GTK_MACOSX)
bool added = KeyDown(key, shift, ctrl, alt, &consumed) != 0;
+#else
+ bool meta = ctrl;
+ ctrl = alt;
+ alt = (event->state & GDK_MOD5_MASK) != 0;
+ bool added = KeyDownWithModifiers(key, (shift ? SCI_SHIFT : 0) |
+ (ctrl ? SCI_CTRL : 0) |
+ (alt ? SCI_ALT : 0) |
+ (meta ? SCI_META : 0), &consumed) != 0;
+#endif
if (!consumed)
consumed = added;
//fprintf(stderr, "SK-key: %d %x %x\n",event->keyval, event->state, consumed);
@@ -1990,11 +2263,45 @@ gboolean ScintillaGTK::KeyPress(GtkWidget *widget, GdkEventKey *event) {
return sciThis->KeyThis(event);
}
-gboolean ScintillaGTK::KeyRelease(GtkWidget *, GdkEventKey * /*event*/) {
+gboolean ScintillaGTK::KeyRelease(GtkWidget *widget, GdkEventKey *event) {
//Platform::DebugPrintf("SC-keyrel: %d %x %3s\n",event->keyval, event->state, event->string);
+ ScintillaGTK *sciThis = ScintillaFromWidget(widget);
+ if (gtk_im_context_filter_keypress(sciThis->im_context, event)) {
+ return TRUE;
+ }
return FALSE;
}
+#if GTK_CHECK_VERSION(3,0,0)
+
+gboolean ScintillaGTK::DrawPreeditThis(GtkWidget *widget, cairo_t *cr) {
+ try {
+ gchar *str;
+ gint cursor_pos;
+ PangoAttrList *attrs;
+
+ gtk_im_context_get_preedit_string(im_context, &str, &attrs, &cursor_pos);
+ PangoLayout *layout = gtk_widget_create_pango_layout(PWidget(wText), str);
+ pango_layout_set_attributes(layout, attrs);
+
+ cairo_move_to(cr, 0, 0);
+ pango_cairo_show_layout(cr, layout);
+
+ g_free(str);
+ pango_attr_list_unref(attrs);
+ g_object_unref(layout);
+ } catch (...) {
+ errorStatus = SC_STATUS_FAILURE;
+ }
+ return TRUE;
+}
+
+gboolean ScintillaGTK::DrawPreedit(GtkWidget *widget, cairo_t *cr, ScintillaGTK *sciThis) {
+ return sciThis->DrawPreeditThis(widget, cr);
+}
+
+#else
+
gboolean ScintillaGTK::ExposePreeditThis(GtkWidget *widget, GdkEventExpose *ose) {
try {
gchar *str;
@@ -2005,7 +2312,12 @@ gboolean ScintillaGTK::ExposePreeditThis(GtkWidget *widget, GdkEventExpose *ose)
PangoLayout *layout = gtk_widget_create_pango_layout(PWidget(wText), str);
pango_layout_set_attributes(layout, attrs);
-#ifndef USE_CAIRO
+#ifdef USE_CAIRO
+ cairo_t *context = gdk_cairo_create(reinterpret_cast<GdkDrawable *>(WindowFromWidget(widget)));
+ cairo_move_to(context, 0, 0);
+ pango_cairo_show_layout(context, layout);
+ cairo_destroy(context);
+#else
GdkGC *gc = gdk_gc_new(widget->window);
GdkColor color[2] = { {0, 0x0000, 0x0000, 0x0000},
{0, 0xffff, 0xffff, 0xffff}
@@ -2035,6 +2347,8 @@ gboolean ScintillaGTK::ExposePreedit(GtkWidget *widget, GdkEventExpose *ose, Sci
return sciThis->ExposePreeditThis(widget, ose);
}
+#endif
+
void ScintillaGTK::CommitThis(char *utfVal) {
try {
//~ fprintf(stderr, "Commit '%s'\n", utfVal);
@@ -2086,7 +2400,7 @@ void ScintillaGTK::PreeditChangedThis() {
g_object_unref(layout);
gint x, y;
- gdk_window_get_origin((PWidget(wText))->window, &x, &y);
+ gdk_window_get_origin(PWindow(wText), &x, &y);
Point pt = PointMainCaret();
if (pt.x < 0)
@@ -2112,16 +2426,19 @@ void ScintillaGTK::PreeditChanged(GtkIMContext *, ScintillaGTK *sciThis) {
sciThis->PreeditChangedThis();
}
-gint ScintillaGTK::StyleSetText(GtkWidget *widget, GtkStyle *, void*) {
- if (widget->window != NULL)
- gdk_window_set_back_pixmap(widget->window, NULL, FALSE);
- return FALSE;
+void ScintillaGTK::StyleSetText(GtkWidget *widget, GtkStyle *, void*) {
+ RealizeText(widget, NULL);
}
-gint ScintillaGTK::RealizeText(GtkWidget *widget, void*) {
- if (widget->window != NULL)
- gdk_window_set_back_pixmap(widget->window, NULL, FALSE);
- return FALSE;
+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)
+ gdk_window_set_background_pattern(WindowFromWidget(widget), NULL);
+#else
+ gdk_window_set_back_pixmap(WindowFromWidget(widget), NULL, FALSE);
+#endif
+ }
}
void ScintillaGTK::Destroy(GObject *object) {
@@ -2141,7 +2458,80 @@ void ScintillaGTK::Destroy(GObject *object) {
}
}
-gint ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *ose) {
+#if GTK_CHECK_VERSION(3,0,0)
+
+gboolean ScintillaGTK::DrawTextThis(cairo_t *cr) {
+ try {
+ paintState = painting;
+
+ rcPaint = GetClientRectangle();
+
+ PLATFORM_ASSERT(rgnUpdate == NULL);
+ rgnUpdate = cairo_copy_clip_rectangle_list(cr);
+ if (rgnUpdate && rgnUpdate->status != CAIRO_STATUS_SUCCESS) {
+ // If not successful then ignore
+ fprintf(stderr, "DrawTextThis failed to copy update region %d [%d]\n", rgnUpdate->status, rgnUpdate->num_rectangles);
+ cairo_rectangle_list_destroy(rgnUpdate);
+ rgnUpdate = 0;
+ }
+
+ double x1, y1, x2, y2;
+ cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
+ rcPaint.left = x1;
+ rcPaint.top = y1;
+ rcPaint.right = x2;
+ rcPaint.bottom = y2;
+ PRectangle rcClient = GetClientRectangle();
+ paintingAllText = rcPaint.Contains(rcClient);
+ Surface *surfaceWindow = Surface::Allocate();
+ if (surfaceWindow) {
+ surfaceWindow->Init(cr, PWidget(wText));
+ Paint(surfaceWindow, rcPaint);
+ surfaceWindow->Release();
+ delete surfaceWindow;
+ }
+ if (paintState == paintAbandoned) {
+ // Painting area was insufficient to cover new styling or brace highlight positions
+ FullPaint();
+ }
+ paintState = notPainting;
+
+ if (rgnUpdate) {
+ cairo_rectangle_list_destroy(rgnUpdate);
+ }
+ rgnUpdate = 0;
+ paintState = notPainting;
+ } catch (...) {
+ errorStatus = SC_STATUS_FAILURE;
+ }
+
+ return FALSE;
+}
+
+gboolean ScintillaGTK::DrawText(GtkWidget *, cairo_t *cr, ScintillaGTK *sciThis) {
+ return sciThis->DrawTextThis(cr);
+}
+
+gboolean ScintillaGTK::DrawThis(cairo_t *cr) {
+ try {
+ gtk_container_propagate_draw(
+ GTK_CONTAINER(PWidget(wMain)), PWidget(scrollbarh), cr);
+ gtk_container_propagate_draw(
+ GTK_CONTAINER(PWidget(wMain)), PWidget(scrollbarv), cr);
+ } catch (...) {
+ errorStatus = SC_STATUS_FAILURE;
+ }
+ return FALSE;
+}
+
+gboolean ScintillaGTK::DrawMain(GtkWidget *widget, cairo_t *cr) {
+ ScintillaGTK *sciThis = ScintillaFromWidget(widget);
+ return sciThis->DrawThis(cr);
+}
+
+#else
+
+gboolean ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *ose) {
try {
paintState = painting;
@@ -2156,7 +2546,7 @@ gint ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *ose) {
paintingAllText = rcPaint.Contains(rcClient);
Surface *surfaceWindow = Surface::Allocate();
if (surfaceWindow) {
- surfaceWindow->Init(PWidget(wText)->window, PWidget(wText));
+ surfaceWindow->Init(PWindow(wText), PWidget(wText));
Paint(surfaceWindow, rcPaint);
surfaceWindow->Release();
delete surfaceWindow;
@@ -2178,18 +2568,18 @@ gint ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *ose) {
return FALSE;
}
-gint ScintillaGTK::ExposeText(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis) {
+gboolean ScintillaGTK::ExposeText(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis) {
return sciThis->ExposeTextThis(widget, ose);
}
-gint ScintillaGTK::ExposeMain(GtkWidget *widget, GdkEventExpose *ose) {
+gboolean ScintillaGTK::ExposeMain(GtkWidget *widget, GdkEventExpose *ose) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Expose Main %0d,%0d %0d,%0d\n",
//ose->area.x, ose->area.y, ose->area.width, ose->area.height);
return sciThis->Expose(widget, ose);
}
-gint ScintillaGTK::Expose(GtkWidget *, GdkEventExpose *ose) {
+gboolean ScintillaGTK::Expose(GtkWidget *, GdkEventExpose *ose) {
try {
//fprintf(stderr, "Expose %0d,%0d %0d,%0d\n",
//ose->area.x, ose->area.y, ose->area.width, ose->area.height);
@@ -2206,9 +2596,15 @@ gint ScintillaGTK::Expose(GtkWidget *, GdkEventExpose *ose) {
return FALSE;
}
+#endif
+
void ScintillaGTK::ScrollSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) {
try {
+#if GTK_CHECK_VERSION(3,0,0)
+ sciThis->ScrollTo(static_cast<int>(gtk_adjustment_get_value(adj)), false);
+#else
sciThis->ScrollTo(static_cast<int>(adj->value), false);
+#endif
} catch (...) {
sciThis->errorStatus = SC_STATUS_FAILURE;
}
@@ -2216,7 +2612,11 @@ void ScintillaGTK::ScrollSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) {
void ScintillaGTK::ScrollHSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) {
try {
+#if GTK_CHECK_VERSION(3,0,0)
+ sciThis->HorizontalScrollTo(static_cast<int>(gtk_adjustment_get_value(adj) * 2));
+#else
sciThis->HorizontalScrollTo(static_cast<int>(adj->value * 2));
+#endif
} catch (...) {
sciThis->errorStatus = SC_STATUS_FAILURE;
}
@@ -2234,7 +2634,7 @@ void ScintillaGTK::SelectionGet(GtkWidget *widget,
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
try {
//Platform::DebugPrintf("Selection get\n");
- if (selection_data->selection == GDK_SELECTION_PRIMARY) {
+ if (SelectionOfGSD(selection_data) == GDK_SELECTION_PRIMARY) {
if (sciThis->primary.s == NULL) {
sciThis->CopySelectionRange(&sciThis->primary);
}
@@ -2269,13 +2669,19 @@ gboolean ScintillaGTK::DragMotionThis(GdkDragContext *context,
try {
Point npt(x, y);
SetDragPosition(SPositionFromLocation(npt, false, false, UserVirtualSpace()));
+#if GTK_CHECK_VERSION(3,0,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 (context->actions == static_cast<GdkDragAction>
+ } else if (actions == static_cast<GdkDragAction>
(GDK_ACTION_COPY | GDK_ACTION_MOVE)) {
preferredAction = GDK_ACTION_MOVE;
}
@@ -2347,7 +2753,12 @@ void ScintillaGTK::DragDataGet(GtkWidget *widget, GdkDragContext *context,
if (!sciThis->sel.Empty()) {
sciThis->GetSelection(selection_data, info, &sciThis->drag);
}
- if (context->action == GDK_ACTION_MOVE) {
+#if GTK_CHECK_VERSION(3,0,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()) {
if (sciThis->posDrop > sciThis->sel.Range(r).End()) {
@@ -2410,9 +2821,9 @@ void ScintillaGTK::PopUpCB(GtkMenuItem *menuItem, ScintillaGTK *sciThis) {
}
}
-gint ScintillaGTK::PressCT(GtkWidget *widget, GdkEventButton *event, ScintillaGTK *sciThis) {
+gboolean ScintillaGTK::PressCT(GtkWidget *widget, GdkEventButton *event, ScintillaGTK *sciThis) {
try {
- if (event->window != widget->window)
+ if (event->window != WindowFromWidget(widget))
return FALSE;
if (event->type != GDK_BUTTON_PRESS)
return FALSE;
@@ -2426,11 +2837,32 @@ gint ScintillaGTK::PressCT(GtkWidget *widget, GdkEventButton *event, ScintillaGT
return TRUE;
}
-gint ScintillaGTK::ExposeCT(GtkWidget *widget, GdkEventExpose * /*ose*/, CallTip *ctip) {
+#if GTK_CHECK_VERSION(3,0,0)
+
+gboolean ScintillaGTK::DrawCT(GtkWidget *widget, cairo_t *cr, CallTip *ctip) {
+ try {
+ Surface *surfaceWindow = Surface::Allocate();
+ if (surfaceWindow) {
+ surfaceWindow->Init(cr, widget);
+ surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == ctip->codePage);
+ surfaceWindow->SetDBCSMode(ctip->codePage);
+ ctip->PaintCT(surfaceWindow);
+ surfaceWindow->Release();
+ delete surfaceWindow;
+ }
+ } catch (...) {
+ // No pointer back to Scintilla to save status
+ }
+ return TRUE;
+}
+
+#else
+
+gboolean ScintillaGTK::ExposeCT(GtkWidget *widget, GdkEventExpose * /*ose*/, CallTip *ctip) {
try {
Surface *surfaceWindow = Surface::Allocate();
if (surfaceWindow) {
- surfaceWindow->Init(widget->window, widget);
+ surfaceWindow->Init(WindowFromWidget(widget), widget);
surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == ctip->codePage);
surfaceWindow->SetDBCSMode(ctip->codePage);
ctip->PaintCT(surfaceWindow);
@@ -2443,6 +2875,8 @@ gint ScintillaGTK::ExposeCT(GtkWidget *widget, GdkEventExpose * /*ose*/, CallTip
return TRUE;
}
+#endif
+
sptr_t ScintillaGTK::DirectFunction(
ScintillaGTK *sciThis, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return sciThis->WndProc(iMessage, wParam, lParam);
@@ -2505,9 +2939,18 @@ void ScintillaGTK::ClassInit(OBJECT_CLASS* object_class, GtkWidgetClass *widget_
// in Initialise() may require coordinate translation?)
object_class->finalize = Destroy;
+#if GTK_CHECK_VERSION(3,0,0)
+ widget_class->get_preferred_width = GetPreferredWidth;
+ widget_class->get_preferred_height = GetPreferredHeight;
+#else
widget_class->size_request = SizeRequest;
+#endif
widget_class->size_allocate = SizeAllocate;
+#if GTK_CHECK_VERSION(3,0,0)
+ widget_class->draw = DrawMain;
+#else
widget_class->expose_event = ExposeMain;
+#endif
widget_class->motion_notify_event = Motion;
widget_class->button_press_event = Press;
widget_class->button_release_event = MouseRelease;
View
17 scintilla/include/Platform.h
@@ -16,6 +16,7 @@
#define PLAT_GTK 0
#define PLAT_GTK_WIN32 0
+#define PLAT_GTK_MACOSX 0
#define PLAT_MACOSX 0
#define PLAT_WIN 0
#define PLAT_WX 0
@@ -38,6 +39,11 @@
#define PLAT_GTK_WIN32 1
#endif
+#if defined(__APPLE__)
+#undef PLAT_GTK_MACOSX
+#define PLAT_GTK_MACOSX 1
+#endif
+
#elif defined(__APPLE__)
#undef PLAT_MACOSX
@@ -301,8 +307,11 @@ class Font {
FontID GetID() { return fid; }
// Alias another font - caller guarantees not to Release
void SetID(FontID fid_) { fid = fid_; }
+#if PLAT_WX
+ void SetAscent(int ascent_) { ascent = ascent_; }
+#endif
friend class Surface;
- friend class SurfaceImpl;
+ friend class SurfaceImpl;
};
/**
@@ -336,6 +345,7 @@ class Surface {
virtual void RoundedRectangle(PRectangle rc, ColourAllocated fore, ColourAllocated back)=0;
virtual void AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill,
ColourAllocated outline, int alphaOutline, int flags)=0;
+ virtual void DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) = 0;
virtual void Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back)=0;
virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource)=0;
@@ -411,8 +421,8 @@ class Window {
void SetTitle(const char *s);
PRectangle GetMonitorRect(Point pt);
#if PLAT_MACOSX
- void SetWindow(void *ref) { windowRef = ref; };
- void SetControl(void *_control) { control = _control; };
+ void SetWindow(void *ref) { windowRef = ref; }
+ void SetControl(void *_control) { control = _control; }
#endif
private:
Cursor cursorLast;
@@ -443,6 +453,7 @@ class ListBox : public Window {
virtual int Find(const char *prefix)=0;
virtual void GetValue(int n, char *value, int len)=0;
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 SetList(const char* list, char separator, char typesep)=0;
View
19 scintilla/include/SciLexer.h
@@ -344,6 +344,16 @@
#define SCE_PL_SUB_PROTOTYPE 40
#define SCE_PL_FORMAT_IDENT 41
#define SCE_PL_FORMAT 42
+#define SCE_PL_STRING_VAR 43
+#define SCE_PL_XLAT 44
+#define SCE_PL_REGEX_VAR 54
+#define SCE_PL_REGSUBST_VAR 55
+#define SCE_PL_BACKTICKS_VAR 57
+#define SCE_PL_HERE_QQ_VAR 61
+#define SCE_PL_HERE_QX_VAR 62
+#define SCE_PL_STRING_QQ_VAR 64