Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sun, 28 Apr 2019 17:02:15 UTC Commit: 4bceddb449b8727e1d8b449a5d92af5fa53a2405 https://github.com/geany/geany/commit/4bceddb449b8727e1d8b449a5d92af5fa53a24...
Log Message: ----------- Update Scintilla to version 3.10.4
Modified Paths: -------------- scintilla/Makefile.am scintilla/gtk/Converter.h scintilla/gtk/PlatGTK.cxx scintilla/gtk/ScintillaGTK.cxx scintilla/gtk/ScintillaGTK.h scintilla/gtk/ScintillaGTKAccessible.cxx scintilla/include/Platform.h scintilla/include/SciLexer.h scintilla/include/Scintilla.h scintilla/include/Scintilla.iface scintilla/lexers/LexCPP.cxx scintilla/lexers/LexHaskell.cxx scintilla/lexers/LexTCL.cxx scintilla/lexlib/CharacterCategory.cxx scintilla/lexlib/CharacterCategory.h scintilla/lexlib/CharacterSet.h scintilla/lexlib/StyleContext.cxx scintilla/scintilla_changes.patch scintilla/src/CallTip.cxx scintilla/src/CaseConvert.cxx scintilla/src/CaseFolder.cxx scintilla/src/CaseFolder.h scintilla/src/CharClassify.cxx scintilla/src/ContractionState.cxx scintilla/src/ContractionState.h scintilla/src/DBCS.h scintilla/src/Document.cxx scintilla/src/Document.h scintilla/src/EditModel.cxx scintilla/src/EditModel.h scintilla/src/EditView.cxx scintilla/src/EditView.h scintilla/src/Editor.cxx scintilla/src/Editor.h scintilla/src/ElapsedPeriod.h scintilla/src/Indicator.cxx scintilla/src/Indicator.h scintilla/src/KeyMap.h scintilla/src/LineMarker.cxx scintilla/src/LineMarker.h scintilla/src/MarginView.cxx scintilla/src/MarginView.h scintilla/src/PerLine.h scintilla/src/PositionCache.cxx scintilla/src/PositionCache.h scintilla/src/RESearch.h scintilla/src/ScintillaBase.cxx scintilla/src/ScintillaBase.h scintilla/src/Selection.cxx scintilla/src/Selection.h scintilla/src/Style.cxx scintilla/src/Style.h scintilla/src/UniConversion.cxx scintilla/src/UniConversion.h scintilla/src/UniqueString.cxx scintilla/src/UniqueString.h scintilla/src/ViewStyle.cxx scintilla/src/ViewStyle.h scintilla/src/XPM.h scintilla/version.txt
Modified: scintilla/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -148,6 +148,7 @@ src/Style.h \ src/UniConversion.cxx \ src/UniConversion.h \ src/UnicodeFromUTF8.h \ +src/UniqueString.cxx \ src/UniqueString.h \ src/ViewStyle.cxx \ src/ViewStyle.h \
Modified: scintilla/gtk/Converter.h 14 lines changed, 7 insertions(+), 7 deletions(-) =================================================================== @@ -15,24 +15,24 @@ const gsize sizeFailure = static_cast<gsize>(-1); */ class Converter { GIConv iconvh; - void OpenHandle(const char *fullDestination, const char *charSetSource) { + void OpenHandle(const char *fullDestination, const char *charSetSource) noexcept { iconvh = g_iconv_open(fullDestination, charSetSource); } - bool Succeeded() const { + bool Succeeded() const noexcept { return iconvh != iconvhBad; } public: - Converter() { + Converter() noexcept { iconvh = iconvhBad; } Converter(const char *charSetDestination, const char *charSetSource, bool transliterations) { iconvh = iconvhBad; - Open(charSetDestination, charSetSource, transliterations); + Open(charSetDestination, charSetSource, transliterations); } ~Converter() { Close(); } - operator bool() const { + operator bool() const noexcept { return Succeeded(); } void Open(const char *charSetDestination, const char *charSetSource, bool transliterations) { @@ -50,13 +50,13 @@ class Converter { } } } - void Close() { + void Close() noexcept { if (Succeeded()) { g_iconv_close(iconvh); iconvh = iconvhBad; } } - gsize Convert(char** src, gsize *srcleft, char **dst, gsize *dstleft) const { + gsize Convert(char **src, gsize *srcleft, char **dst, gsize *dstleft) const noexcept { if (!Succeeded()) { return sizeFailure; } else {
Modified: scintilla/gtk/PlatGTK.cxx 393 lines changed, 202 insertions(+), 191 deletions(-) =================================================================== @@ -12,6 +12,7 @@ #include <string> #include <vector> #include <map> +#include <algorithm> #include <memory> #include <sstream>
@@ -26,56 +27,63 @@ #include "Scintilla.h" #include "ScintillaWidget.h" #include "StringCopy.h" +#include "IntegerRectangle.h" #include "XPM.h" #include "UniConversion.h"
#include "Converter.h"
-static const double kPi = 3.14159265358979323846; +#ifdef _MSC_VER +// Ignore unreferenced local functions in GTK+ headers +#pragma warning(disable: 4505) +#endif + +using namespace Scintilla; + +namespace { + +const double kPi = 3.14159265358979323846;
// The Pango version guard for pango_units_from_double and pango_units_to_double // is more complex than simply implementing these here.
-static int pangoUnitsFromDouble(double d) { +int pangoUnitsFromDouble(double d) noexcept { return static_cast<int>(d * PANGO_SCALE + 0.5); }
-static double doubleFromPangoUnits(int pu) { - return static_cast<double>(pu) / PANGO_SCALE; +float floatFromPangoUnits(int pu) noexcept { + return static_cast<float>(pu) / PANGO_SCALE; }
-static cairo_surface_t *CreateSimilarSurface(GdkWindow *window, cairo_content_t content, int width, int height) { +cairo_surface_t *CreateSimilarSurface(GdkWindow *window, cairo_content_t content, int width, int height) noexcept { return gdk_window_create_similar_surface(window, content, width, height); }
-static GdkWindow *WindowFromWidget(GtkWidget *w) { +GdkWindow *WindowFromWidget(GtkWidget *w) noexcept { return gtk_widget_get_window(w); }
-#ifdef _MSC_VER -// Ignore unreferenced local functions in GTK+ headers -#pragma warning(disable: 4505) -#endif - -using namespace Scintilla; +GtkWidget *PWidget(WindowID wid) noexcept { + return static_cast<GtkWidget *>(wid); +}
-enum encodingType { singleByte, UTF8, dbcs}; +enum encodingType { singleByte, UTF8, dbcs };
// Holds a PangoFontDescription*. class FontHandle { public: PangoFontDescription *pfd; int characterSet; - FontHandle() : pfd(0), characterSet(-1) { + FontHandle() noexcept : pfd(nullptr), characterSet(-1) { } - FontHandle(PangoFontDescription *pfd_, int characterSet_) { + FontHandle(PangoFontDescription *pfd_, int characterSet_) noexcept { pfd = pfd_; characterSet = characterSet_; } ~FontHandle() { if (pfd) pango_font_description_free(pfd); - pfd = 0; + pfd = nullptr; } static FontHandle *CreateNewFont(const FontParameters &fp); }; @@ -88,24 +96,22 @@ FontHandle *FontHandle::CreateNewFont(const FontParameters &fp) { pango_font_description_set_size(pfd, pangoUnitsFromDouble(fp.size)); pango_font_description_set_weight(pfd, static_cast<PangoWeight>(fp.weight)); pango_font_description_set_style(pfd, fp.italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); - return new FontHandle(pfd,fp.characterSet); + return new FontHandle(pfd, fp.characterSet); }
- return NULL; + return nullptr; }
// X has a 16 bit coordinate space, so stop drawing here to avoid wrapping -static const int maxCoordinate = 32000; +const int maxCoordinate = 32000;
-static FontHandle *PFont(Font &f) { +FontHandle *PFont(const Font &f) noexcept { return static_cast<FontHandle *>(f.GetID()); }
-static GtkWidget *PWidget(WindowID wid) { - return static_cast<GtkWidget *>(wid); }
-Font::Font() noexcept : fid(0) {} +Font::Font() noexcept : fid(nullptr) {}
Font::~Font() {}
@@ -117,7 +123,7 @@ void Font::Create(const FontParameters &fp) { void Font::Release() { if (fid) delete static_cast<FontHandle *>(fid); - fid = 0; + fid = nullptr; }
// Required on OS X @@ -138,14 +144,14 @@ class SurfaceImpl : public Surface { int characterSet; void SetConverter(int characterSet_); public: - SurfaceImpl(); + SurfaceImpl() noexcept; ~SurfaceImpl() override;
void Init(WindowID wid) override; void Init(SurfaceID sid, WindowID wid) override; void InitPixMap(int width, int height, Surface *surface_, WindowID wid) override;
- void Clear(); + void Clear() noexcept; void Release() override; bool Initialised() override; void PenColour(ColourDesired fore) override; @@ -185,7 +191,7 @@ class SurfaceImpl : public Surface { }; }
-const char *CharacterSetID(int characterSet) { +const char *CharacterSetID(int characterSet) noexcept { switch (characterSet) { case SC_CHARSET_ANSI: return ""; @@ -243,33 +249,33 @@ void SurfaceImpl::SetConverter(int characterSet_) { } }
-SurfaceImpl::SurfaceImpl() : et(singleByte), -context(0), -psurf(0), -x(0), y(0), inited(false), createdGC(false) -, pcontext(0), layout(0), characterSet(-1) { +SurfaceImpl::SurfaceImpl() noexcept : et(singleByte), +context(nullptr), +psurf(nullptr), +x(0), y(0), inited(false), createdGC(false), +pcontext(nullptr), layout(nullptr), characterSet(-1) { }
SurfaceImpl::~SurfaceImpl() { Clear(); }
-void SurfaceImpl::Clear() { +void SurfaceImpl::Clear() noexcept { et = singleByte; if (createdGC) { createdGC = false; cairo_destroy(context); } - context = 0; + context = nullptr; if (psurf) cairo_surface_destroy(psurf); - psurf = 0; + psurf = nullptr; if (layout) g_object_unref(layout); - layout = 0; + layout = nullptr; if (pcontext) g_object_unref(pcontext); - pcontext = 0; + pcontext = nullptr; conv.Close(); characterSet = -1; x = 0; @@ -306,8 +312,8 @@ void SurfaceImpl::Init(WindowID wid) { Release(); PLATFORM_ASSERT(wid); // if we are only created from a window ID, we can't perform drawing - psurf = 0; - context = 0; + psurf = nullptr; + context = nullptr; createdGC = false; pcontext = gtk_widget_create_pango_context(PWidget(wid)); PLATFORM_ASSERT(pcontext); @@ -361,7 +367,7 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface *surface_, WindowID
void SurfaceImpl::PenColour(ColourDesired fore) { if (context) { - ColourDesired cdFore(fore.AsInteger()); + const ColourDesired cdFore(fore.AsInteger()); cairo_set_source_rgb(context, cdFore.GetRed() / 255.0, cdFore.GetGreen() / 255.0, @@ -374,7 +380,7 @@ int SurfaceImpl::LogPixelsY() { }
int SurfaceImpl::DeviceHeightFont(int points) { - int logPix = LogPixelsY(); + const int logPix = LogPixelsY(); return (points * logPix + logPix / 2) / 72; }
@@ -383,7 +389,7 @@ void SurfaceImpl::MoveTo(int x_, int y_) { y = y_; }
-static int Delta(int difference) { +static int Delta(int difference) noexcept { if (difference < 0) return -1; else if (difference > 0) @@ -396,21 +402,21 @@ void SurfaceImpl::LineTo(int x_, int y_) { // cairo_line_to draws the end position, unlike Win32 or GDK with GDK_CAP_NOT_LAST. // For simple cases, move back one pixel from end. if (context) { - int xDiff = x_ - x; - int xDelta = Delta(xDiff); - int yDiff = y_ - y; - int yDelta = Delta(yDiff); + const int xDiff = x_ - x; + const int xDelta = Delta(xDiff); + const int yDiff = y_ - y; + const int yDelta = Delta(yDiff); if ((xDiff == 0) || (yDiff == 0)) { // Horizontal or vertical lines can be more precisely drawn as a filled rectangle - int xEnd = x_ - xDelta; - int left = std::min(x, xEnd); - int width = abs(x - xEnd) + 1; - int yEnd = y_ - yDelta; - int top = std::min(y, yEnd); - int height = abs(y - yEnd) + 1; + const int xEnd = x_ - xDelta; + const int left = std::min(x, xEnd); + const int width = std::abs(x - xEnd) + 1; + const int yEnd = y_ - yDelta; + const int top = std::min(y, yEnd); + const int height = std::abs(y - yEnd) + 1; cairo_rectangle(context, left, top, width, height); cairo_fill(context); - } else if ((abs(xDiff) == abs(yDiff))) { + } else if ((std::abs(xDiff) == std::abs(yDiff))) { // 45 degree slope cairo_move_to(context, x + 0.5, y + 0.5); cairo_line_to(context, x_ + 0.5 - xDelta, y_ + 0.5 - yDelta); @@ -453,8 +459,8 @@ void SurfaceImpl::RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) { PenColour(back); if (context && (rc.left < maxCoordinate)) { // Protect against out of range - rc.left = lround(rc.left); - rc.right = lround(rc.right); + rc.left = std::round(rc.left); + rc.right = std::round(rc.right); cairo_rectangle(context, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); cairo_fill(context); @@ -463,17 +469,18 @@ void SurfaceImpl::FillRectangle(PRectangle rc, ColourDesired back) {
void SurfaceImpl::FillRectangle(PRectangle rc, Surface &surfacePattern) { SurfaceImpl &surfi = static_cast<SurfaceImpl &>(surfacePattern); - bool canDraw = surfi.psurf != NULL; + const bool canDraw = surfi.psurf != nullptr; if (canDraw) { PLATFORM_ASSERT(context); // Tile pattern over rectangle // Currently assumes 8x8 pattern - int widthPat = 8; - int heightPat = 8; - for (int xTile = rc.left; xTile < rc.right; xTile += widthPat) { - int widthx = (xTile + widthPat > rc.right) ? rc.right - xTile : widthPat; - for (int yTile = rc.top; yTile < rc.bottom; yTile += heightPat) { - int heighty = (yTile + heightPat > rc.bottom) ? rc.bottom - yTile : heightPat; + const int widthPat = 8; + const int heightPat = 8; + const IntegerRectangle irc(rc); + for (int xTile = irc.left; xTile < irc.right; xTile += widthPat) { + const int widthx = (xTile + widthPat > irc.right) ? irc.right - xTile : widthPat; + for (int yTile = irc.top; yTile < irc.bottom; yTile += heightPat) { + const int heighty = (yTile + heightPat > irc.bottom) ? irc.bottom - yTile : heightPat; cairo_set_source_surface(context, surfi.psurf, xTile, yTile); cairo_rectangle(context, xTile, yTile, widthx, heighty); cairo_fill(context); @@ -505,8 +512,8 @@ 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; +static void PathRoundRectangle(cairo_t *context, double left, double top, double width, double height, int radius) noexcept { + const double degrees = kPi / 180.0;
cairo_new_sub_path(context); cairo_arc(context, left + width - radius, top + radius, radius, -90 * degrees, 0 * degrees); @@ -519,7 +526,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.AsInteger()); + const ColourDesired cdFill(fill.AsInteger()); cairo_set_source_rgba(context, cdFill.GetRed() / 255.0, cdFill.GetGreen() / 255.0, @@ -531,7 +538,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.AsInteger()); + const ColourDesired cdOutline(outline.AsInteger()); cairo_set_source_rgba(context, cdOutline.GetRed() / 255.0, cdOutline.GetGreen() / 255.0, @@ -581,12 +588,12 @@ void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsi rc.bottom = rc.top + height;
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); - int ucs = stride * height; + const int ucs = stride * height; std::vector<unsigned char> image(ucs); for (int iy=0; iy<height; iy++) { for (int ix=0; ix<width; ix++) { unsigned char *pixel = &image[0] + iy*stride + ix * 4; - unsigned char alpha = pixelsImage[3]; + const unsigned char alpha = pixelsImage[3]; pixel[2] = (*pixelsImage++) * alpha / 255; pixel[1] = (*pixelsImage++) * alpha / 255; pixel[0] = (*pixelsImage++) * alpha / 255; @@ -614,7 +621,7 @@ void SurfaceImpl::Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back)
void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) { SurfaceImpl &surfi = static_cast<SurfaceImpl &>(surfaceSource); - bool canDraw = surfi.psurf != NULL; + const bool canDraw = surfi.psurf != nullptr; if (canDraw) { PLATFORM_ASSERT(context); cairo_set_source_surface(context, surfi.psurf, @@ -648,7 +655,7 @@ static std::string UTF8FromIconv(const Converter &conv, const char *s, int len) char *putf = &utfForm[0]; char *pout = putf; gsize outLeft = len*3+1; - gsize conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); + const gsize conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); if (conversions != sizeFailure) { *pout = '\0'; utfForm.resize(pout - putf); @@ -667,7 +674,7 @@ static size_t MultiByteLenFromIconv(const Converter &conv, const char *s, size_t gsize inLeft = lenMB; char *pout = wcForm; gsize outLeft = 2; - gsize conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); + const gsize conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); if (conversions != sizeFailure) { return lenMB; } @@ -679,7 +686,7 @@ void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, XYPOSITION ybase, con ColourDesired fore) { PenColour(fore); if (context) { - XYPOSITION xText = rc.left; + const XYPOSITION xText = rc.left; if (PFont(font_)->pfd) { std::string utfForm; if (et == UTF8) { @@ -694,7 +701,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); - PangoLayoutLine *pll = pango_layout_get_line_readonly(layout,0); + PangoLayoutLine *pll = pango_layout_get_line_readonly(layout, 0); cairo_move_to(context, xText, ybase); pango_cairo_show_layout_line(context, pll); } @@ -735,24 +742,24 @@ class ClusterIterator { XYPOSITION position; XYPOSITION distance; int curIndex; - ClusterIterator(PangoLayout *layout, int len) : lenPositions(len), finished(false), + ClusterIterator(PangoLayout *layout, int len) noexcept : lenPositions(len), finished(false), positionStart(0), position(0), distance(0), curIndex(0) { iter = pango_layout_get_iter(layout); - pango_layout_iter_get_cluster_extents(iter, NULL, &pos); + pango_layout_iter_get_cluster_extents(iter, nullptr, &pos); } ~ClusterIterator() { pango_layout_iter_free(iter); }
- void Next() { + void Next() noexcept { positionStart = position; if (pango_layout_iter_next_cluster(iter)) { - pango_layout_iter_get_cluster_extents(iter, NULL, &pos); - position = doubleFromPangoUnits(pos.x); + pango_layout_iter_get_cluster_extents(iter, nullptr, &pos); + position = floatFromPangoUnits(pos.x); curIndex = pango_layout_iter_get_index(iter); } else { finished = true; - position = doubleFromPangoUnits(pos.x + pos.width); + position = floatFromPangoUnits(pos.x + pos.width); curIndex = lenPositions; } distance = position - positionStart; @@ -771,7 +778,7 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION ClusterIterator iti(layout, lenPositions); while (!iti.finished) { iti.Next(); - int places = iti.curIndex - i; + const int places = iti.curIndex - i; while (i < iti.curIndex) { // Evenly distribute space among bytes of this cluster. // Would be better to find number of characters and then @@ -798,8 +805,8 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION ClusterIterator iti(layout, strlen(utfForm.c_str())); while (!iti.finished) { iti.Next(); - int clusterEnd = iti.curIndex; - int places = g_utf8_strlen(utfForm.c_str() + clusterStart, clusterEnd - clusterStart); + const int clusterEnd = iti.curIndex; + const int places = g_utf8_strlen(utfForm.c_str() + clusterStart, clusterEnd - clusterStart); int place = 1; while (clusterStart < clusterEnd) { size_t lenChar = MultiByteLenFromIconv(convMeasure, s+i, len-i); @@ -814,7 +821,7 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION PLATFORM_ASSERT(i == lenPositions); } } - if (positionsCalculated < 1 ) { + if (positionsCalculated < 1) { // Either 8-bit or DBCS conversion failed so treat as 8-bit. SetConverter(PFont(font_)->characterSet); const bool rtlCheck = PFont(font_)->characterSet == SC_CHARSET_HEBREW || @@ -831,13 +838,13 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION ClusterIterator iti(layout, utfForm.length()); while (!iti.finished) { iti.Next(); - int clusterEnd = iti.curIndex; - int ligatureLength = g_utf8_strlen(utfForm.c_str() + clusterStart, clusterEnd - clusterStart); + const int clusterEnd = iti.curIndex; + const int ligatureLength = g_utf8_strlen(utfForm.c_str() + clusterStart, clusterEnd - clusterStart); if (rtlCheck && ((clusterEnd <= clusterStart) || (ligatureLength == 0) || (ligatureLength > 3))) { // Something has gone wrong: exit quickly but pretend all the characters are equally spaced: int widthLayout = 0; - pango_layout_get_size(layout, &widthLayout, NULL); - XYPOSITION widthTotal = doubleFromPangoUnits(widthLayout); + pango_layout_get_size(layout, &widthLayout, nullptr); + const XYPOSITION widthTotal = floatFromPangoUnits(widthLayout); for (int bytePos=0; bytePos<lenPositions; bytePos++) { positions[bytePos] = widthTotal / lenPositions * (bytePos + 1); } @@ -881,9 +888,9 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) { } pango_layout_set_text(layout, utfForm.c_str(), utfForm.length()); } - PangoLayoutLine *pangoLine = pango_layout_get_line_readonly(layout,0); - pango_layout_line_get_extents(pangoLine, NULL, &pos); - return doubleFromPangoUnits(pos.width); + PangoLayoutLine *pangoLine = pango_layout_get_line_readonly(layout, 0); + pango_layout_line_get_extents(pangoLine, nullptr, &pos); + return floatFromPangoUnits(pos.width); } return 1; } else { @@ -896,12 +903,12 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) { XYPOSITION SurfaceImpl::Ascent(Font &font_) { if (!(font_.GetID())) return 1; - int ascent = 0; + XYPOSITION ascent = 0; if (PFont(font_)->pfd) { PangoFontMetrics *metrics = pango_context_get_metrics(pcontext, PFont(font_)->pfd, pango_context_get_language(pcontext)); - ascent = - doubleFromPangoUnits(pango_font_metrics_get_ascent(metrics)); + ascent = std::floor(floatFromPangoUnits( + pango_font_metrics_get_ascent(metrics))); pango_font_metrics_unref(metrics); } if (ascent == 0) { @@ -916,7 +923,8 @@ XYPOSITION SurfaceImpl::Descent(Font &font_) { if (PFont(font_)->pfd) { PangoFontMetrics *metrics = pango_context_get_metrics(pcontext, PFont(font_)->pfd, pango_context_get_language(pcontext)); - int descent = doubleFromPangoUnits(pango_font_metrics_get_descent(metrics)); + const XYPOSITION descent = std::floor(floatFromPangoUnits( + pango_font_metrics_get_descent(metrics))); pango_font_metrics_unref(metrics); return descent; } @@ -961,7 +969,7 @@ Window::~Window() {}
void Window::Destroy() { if (wid) { - ListBox *listbox = dynamic_cast<ListBox*>(this); + ListBox *listbox = dynamic_cast<ListBox *>(this); if (listbox) { gtk_widget_hide(GTK_WIDGET(wid)); // clear up window content @@ -972,7 +980,7 @@ void Window::Destroy() { } else { gtk_widget_destroy(GTK_WIDGET(wid)); } - wid = 0; + wid = nullptr; } }
@@ -982,8 +990,8 @@ PRectangle Window::GetPosition() const { if (wid) { GtkAllocation allocation; gtk_widget_get_allocation(PWidget(wid), &allocation); - rc.left = allocation.x; - rc.top = allocation.y; + rc.left = static_cast<XYPOSITION>(allocation.x); + rc.top = static_cast<XYPOSITION>(allocation.y); if (allocation.width > 20) { rc.right = rc.left + allocation.width; rc.bottom = rc.top + allocation.height; @@ -994,10 +1002,10 @@ PRectangle Window::GetPosition() const {
void Window::SetPosition(PRectangle rc) { GtkAllocation alloc; - alloc.x = rc.left; - alloc.y = rc.top; - alloc.width = rc.Width(); - alloc.height = rc.Height(); + alloc.x = static_cast<int>(rc.left); + alloc.y = static_cast<int>(rc.top); + alloc.width = static_cast<int>(rc.Width()); + alloc.height = static_cast<int>(rc.Height()); gtk_widget_size_allocate(PWidget(wid), &alloc); }
@@ -1011,8 +1019,8 @@ GdkRectangle MonitorRectangleForWidget(GtkWidget *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); + GdkScreen *screen = gtk_widget_get_screen(wid); + const gint monitor_num = gdk_screen_get_monitor_at_window(screen, wnd); gdk_screen_get_monitor_geometry(screen, monitor_num, &rcScreen); #endif return rcScreen; @@ -1021,18 +1029,19 @@ GdkRectangle MonitorRectangleForWidget(GtkWidget *wid) { }
void Window::SetPositionRelative(PRectangle rc, const Window *relativeTo) { + const IntegerRectangle irc(rc); int ox = 0; int oy = 0; GdkWindow *wndRelativeTo = WindowFromWidget(PWidget(relativeTo->wid)); gdk_window_get_origin(wndRelativeTo, &ox, &oy); - ox += rc.left; - oy += rc.top; + ox += irc.left; + oy += irc.top;
- GdkRectangle rcMonitor = MonitorRectangleForWidget(PWidget(relativeTo->wid)); + const GdkRectangle rcMonitor = MonitorRectangleForWidget(PWidget(relativeTo->wid));
/* do some corrections to fit into screen */ - int sizex = rc.right - rc.left; - int sizey = rc.bottom - rc.top; + const int sizex = irc.Width(); + const int sizey = irc.Height(); if (sizex > rcMonitor.width || ox < rcMonitor.x) ox = rcMonitor.x; /* the best we can do */ else if (ox + sizex > rcMonitor.x + rcMonitor.width) @@ -1065,9 +1074,10 @@ void Window::InvalidateAll() {
void Window::InvalidateRectangle(PRectangle rc) { if (wid) { + const IntegerRectangle irc(rc); gtk_widget_queue_draw_area(PWidget(wid), - rc.left, rc.top, - rc.right - rc.left, rc.bottom - rc.top); + irc.left, irc.top, + irc.Width(), irc.Height()); } }
@@ -1134,24 +1144,24 @@ PRectangle Window::GetMonitorRect(Point pt) { 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, + GdkScreen *screen = gtk_widget_get_screen(PWidget(wid)); + const 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); + return PRectangle::FromInts(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); }
-typedef std::map<int, RGBAImage*> ImageMap; +typedef std::map<int, RGBAImage *> ImageMap;
struct ListImage { const RGBAImage *rgba_data; GdkPixbuf *pixbuf; };
-static void list_image_free(gpointer, gpointer value, gpointer) { +static void list_image_free(gpointer, gpointer value, gpointer) noexcept { ListImage *list_image = static_cast<ListImage *>(value); if (list_image->pixbuf) g_object_unref(list_image->pixbuf); @@ -1176,8 +1186,8 @@ class ListBoxX : public ListBox { WindowID list; WindowID scroller; void *pixhash; - GtkCellRenderer* pixbuf_renderer; - GtkCellRenderer* renderer; + GtkCellRenderer *pixbuf_renderer; + GtkCellRenderer *renderer; RGBAImageSet images; int desiredVisibleRows; unsigned int maxItemCharacters; @@ -1188,28 +1198,29 @@ class ListBoxX : public ListBox { public: IListBoxDelegate *delegate;
- ListBoxX() : widCached(0), frame(0), list(0), scroller(0), pixhash(NULL), pixbuf_renderer(0), - renderer(0), + ListBoxX() noexcept : widCached(nullptr), frame(nullptr), list(nullptr), scroller(nullptr), + pixhash(nullptr), pixbuf_renderer(nullptr), + renderer(nullptr), desiredVisibleRows(5), maxItemCharacters(0), aveCharWidth(1), #if GTK_CHECK_VERSION(3,0,0) - cssProvider(NULL), + cssProvider(nullptr), #endif delegate(nullptr) { } ~ListBoxX() override { if (pixhash) { - g_hash_table_foreach((GHashTable *) pixhash, list_image_free, NULL); + g_hash_table_foreach((GHashTable *) pixhash, list_image_free, nullptr); g_hash_table_destroy((GHashTable *) pixhash); } if (widCached) { gtk_widget_destroy(GTK_WIDGET(widCached)); - wid = widCached = 0; + wid = widCached = nullptr; } #if GTK_CHECK_VERSION(3,0,0) if (cssProvider) { g_object_unref(cssProvider); - cssProvider = NULL; + cssProvider = nullptr; } #endif } @@ -1247,18 +1258,18 @@ static int treeViewGetRowHeight(GtkTreeView *view) { // version is inaccurate for GTK 3.14. GdkRectangle rect; GtkTreePath *path = gtk_tree_path_new_first(); - gtk_tree_view_get_background_area(view, path, NULL, &rect); + gtk_tree_view_get_background_area(view, path, nullptr, &rect); gtk_tree_path_free(path); return rect.height; #else int row_height=0; int vertical_separator=0; int expander_size=0; GtkTreeViewColumn *column = gtk_tree_view_get_column(view, 0); - gtk_tree_view_column_cell_get_size(column, NULL, NULL, NULL, NULL, &row_height); + gtk_tree_view_column_cell_get_size(column, nullptr, nullptr, nullptr, nullptr, &row_height); gtk_widget_style_get(GTK_WIDGET(view), "vertical-separator", &vertical_separator, - "expander-size", &expander_size, NULL); + "expander-size", &expander_size, nullptr); row_height += vertical_separator; row_height = std::max(row_height, expander_size); return row_height; @@ -1292,7 +1303,7 @@ static void small_scroller_get_preferred_height(GtkWidget *widget, gint *min, gi GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget)); if (GTK_IS_TREE_VIEW(child)) { GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(child)); - int n_rows = gtk_tree_model_iter_n_children(model, NULL); + int n_rows = gtk_tree_model_iter_n_children(model, nullptr); int row_height = treeViewGetRowHeight(GTK_TREE_VIEW(child));
*min = MAX(1, row_height); @@ -1318,11 +1329,11 @@ static void small_scroller_class_init(SmallScrollerClass *klass) { #endif }
-static void small_scroller_init(SmallScroller *){} +static void small_scroller_init(SmallScroller *) {}
-static gboolean ButtonPress(GtkWidget *, GdkEventButton* ev, gpointer p) { +static gboolean ButtonPress(GtkWidget *, GdkEventButton *ev, gpointer p) { try { - ListBoxX* lb = static_cast<ListBoxX*>(p); + ListBoxX *lb = static_cast<ListBoxX *>(p); if (ev->type == GDK_2BUTTON_PRESS && lb->delegate) { ListBoxEvent event(ListBoxEvent::EventType::doubleClick); lb->delegate->ListNotify(&event); @@ -1335,9 +1346,9 @@ static gboolean ButtonPress(GtkWidget *, GdkEventButton* ev, gpointer p) { return FALSE; }
-static gboolean ButtonRelease(GtkWidget *, GdkEventButton* ev, gpointer p) { +static gboolean ButtonRelease(GtkWidget *, GdkEventButton *ev, gpointer p) { try { - ListBoxX* lb = static_cast<ListBoxX*>(p); + ListBoxX *lb = static_cast<ListBoxX *>(p); if (ev->type != GDK_2BUTTON_PRESS && lb->delegate) { ListBoxEvent event(ListBoxEvent::EventType::selectionChange); lb->delegate->ListNotify(&event); @@ -1351,9 +1362,9 @@ static gboolean ButtonRelease(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*) { +static void StyleSet(GtkWidget *w, GtkStyle *, void *) {
- g_return_if_fail(w != NULL); + g_return_if_fail(w != nullptr);
/* 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 @@ -1365,7 +1376,7 @@ static void StyleSet(GtkWidget *w, GtkStyle*, void*) { // The *override* calls are deprecated now, so only call them for older versions of GTK+. #elif GTK_CHECK_VERSION(3,0,0) GtkStyleContext *styleContext = gtk_widget_get_style_context(w); - if (styleContext == NULL) + if (styleContext == nullptr) return;
GdkRGBA colourForeSelected; @@ -1376,7 +1387,7 @@ static void StyleSet(GtkWidget *w, GtkStyle*, void*) { gtk_widget_override_color(w, GTK_STATE_FLAG_ACTIVE, &colourForeSelected);
styleContext = gtk_widget_get_style_context(w); - if (styleContext == NULL) + if (styleContext == nullptr) return;
GdkRGBA colourBaseSelected; @@ -1387,20 +1398,20 @@ static void StyleSet(GtkWidget *w, GtkStyle*, void*) { gtk_widget_override_background_color(w, GTK_STATE_FLAG_ACTIVE, &colourBaseSelected); #else GtkStyle *style = gtk_widget_get_style(w); - if (style == NULL) + if (style == nullptr) 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) + if (style == nullptr) 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 &parent, int, Point, int, bool, int) { - if (widCached != 0) { + if (widCached != nullptr) { wid = widCached; return; } @@ -1413,13 +1424,13 @@ void ListBoxX::Create(Window &parent, int, Point, int, bool, int) {
wid = widCached = gtk_window_new(GTK_WINDOW_POPUP);
- frame = gtk_frame_new(NULL); + frame = gtk_frame_new(nullptr); gtk_widget_show(PWidget(frame)); gtk_container_add(GTK_CONTAINER(GetID()), PWidget(frame)); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); gtk_container_set_border_width(GTK_CONTAINER(frame), 0);
- scroller = g_object_new(small_scroller_get_type(), NULL); + scroller = g_object_new(small_scroller_get_type(), nullptr); gtk_container_set_border_width(GTK_CONTAINER(scroller), 0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); @@ -1431,7 +1442,7 @@ void ListBoxX::Create(Window &parent, int, Point, int, bool, int) { gtk_list_store_new(N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING);
list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - g_signal_connect(G_OBJECT(list), "style-set", G_CALLBACK(StyleSet), NULL); + g_signal_connect(G_OBJECT(list), "style-set", G_CALLBACK(StyleSet), nullptr);
#if GTK_CHECK_VERSION(3,0,0) GtkStyleContext *styleContext = gtk_widget_get_style_context(GTK_WIDGET(list)); @@ -1466,7 +1477,7 @@ void ListBoxX::Create(Window &parent, int, Point, int, bool, int) {
gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); if (g_object_class_find_property(G_OBJECT_GET_CLASS(list), "fixed-height-mode")) - g_object_set(G_OBJECT(list), "fixed-height-mode", TRUE, NULL); + g_object_set(G_OBJECT(list), "fixed-height-mode", TRUE, nullptr);
GtkWidget *widget = PWidget(list); // No code inside the G_OBJECT macro gtk_container_add(GTK_CONTAINER(PWidget(scroller)), widget); @@ -1496,7 +1507,7 @@ void ListBoxX::SetFont(Font &font) { // On GTK < 3.21.0 the units are incorrectly parsed, so a font size in points // need to use the "px" unit. Normally we only get fonts in points here, so // don't bother to handle the case the font is actually in pixels on < 3.21.0. - if (gtk_check_version(3, 21, 0) != NULL || // on < 3.21.0 + if (gtk_check_version(3, 21, 0) != nullptr || // on < 3.21.0 pango_font_description_get_size_is_absolute(pfd)) { ssFontSetting << "px; "; } else { @@ -1505,7 +1516,7 @@ void ListBoxX::SetFont(Font &font) { ssFontSetting << "font-weight:"<< pango_font_description_get_weight(pfd) << "; "; ssFontSetting << "}"; gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(cssProvider), - ssFontSetting.str().c_str(), -1, NULL); + ssFontSetting.str().c_str(), -1, nullptr); } #else gtk_widget_modify_font(PWidget(list), PFont(font)->pfd); @@ -1543,7 +1554,7 @@ PRectangle ListBoxX::GetDesiredRect() { // This, apparently unnecessary call, ensures gtk_tree_view_column_cell_get_size // returns reasonable values. #if GTK_CHECK_VERSION(3,0,0) - gtk_widget_get_preferred_size(GTK_WIDGET(frame), NULL, &req); + gtk_widget_get_preferred_size(GTK_WIDGET(frame), nullptr, &req); #else gtk_widget_size_request(GTK_WIDGET(frame), &req); #endif @@ -1552,7 +1563,7 @@ PRectangle ListBoxX::GetDesiredRect() { // First calculate height of the clist for our desired visible // row count otherwise it tries to expand to the total # of rows // Get cell height - int row_height = GetRowHeight(); + const int row_height = GetRowHeight(); #if GTK_CHECK_VERSION(3,0,0) GtkStyleContext *styleContextFrame = gtk_widget_get_style_context(PWidget(frame)); GtkStateFlags stateFlagsFrame = gtk_style_context_get_state(styleContextFrame); @@ -1573,7 +1584,7 @@ PRectangle ListBoxX::GetDesiredRect() { gtk_style_context_get_border(styleContextFrameBorder, stateFlagsFrame, &border_border); g_object_unref(styleContextFrameBorder); # else // < 3.20 - if (gtk_check_version(3, 20, 0) == NULL) { + if (gtk_check_version(3, 20, 0) == nullptr) { // default to 1px all around as it's likely what it is, and so we don't miss 2px height // on GTK 3.20 when built against an earlier version. border_border.top = border_border.bottom = border_border.left = border_border.right = 1; @@ -1599,7 +1610,7 @@ PRectangle ListBoxX::GetDesiredRect() { // Add horizontal padding and borders int horizontal_separator=0; gtk_widget_style_get(PWidget(list), - "horizontal-separator", &horizontal_separator, NULL); + "horizontal-separator", &horizontal_separator, nullptr); rc.right += horizontal_separator; #if GTK_CHECK_VERSION(3,0,0) rc.right += (padding.left + padding.right @@ -1615,7 +1626,7 @@ PRectangle ListBoxX::GetDesiredRect() { GtkWidget *vscrollbar = gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(scroller)); #if GTK_CHECK_VERSION(3,0,0) - gtk_widget_get_preferred_size(vscrollbar, NULL, &req); + gtk_widget_get_preferred_size(vscrollbar, nullptr, &req); #else gtk_widget_size_request(vscrollbar, &req); #endif @@ -1651,32 +1662,32 @@ static void init_pixmap(ListImage *list_image) { list_image->rgba_data->GetWidth(), list_image->rgba_data->GetHeight(), list_image->rgba_data->GetWidth() * 4, - NULL, - NULL); + nullptr, + nullptr); } }
#define SPACING 5
void ListBoxX::Append(char *s, int type) { - ListImage *list_image = NULL; + ListImage *list_image = nullptr; if ((type >= 0) && pixhash) { - list_image = static_cast<ListImage *>(g_hash_table_lookup((GHashTable *) pixhash - , (gconstpointer) GINT_TO_POINTER(type))); + list_image = static_cast<ListImage *>(g_hash_table_lookup((GHashTable *) pixhash, + GINT_TO_POINTER(type))); } GtkTreeIter iter; GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list))); gtk_list_store_append(GTK_LIST_STORE(store), &iter); if (list_image) { - if (NULL == list_image->pixbuf) + if (nullptr == list_image->pixbuf) init_pixmap(list_image); if (list_image->pixbuf) { gtk_list_store_set(GTK_LIST_STORE(store), &iter, PIXBUF_COLUMN, list_image->pixbuf, TEXT_COLUMN, s, -1);
- gint pixbuf_width = gdk_pixbuf_get_width(list_image->pixbuf); + const gint pixbuf_width = gdk_pixbuf_get_width(list_image->pixbuf); gint renderer_height, renderer_width; gtk_cell_renderer_get_fixed_size(pixbuf_renderer, &renderer_width, &renderer_height); @@ -1691,15 +1702,15 @@ void ListBoxX::Append(char *s, int type) { gtk_list_store_set(GTK_LIST_STORE(store), &iter, TEXT_COLUMN, s, -1); } - size_t len = strlen(s); + const size_t len = strlen(s); if (maxItemCharacters < len) maxItemCharacters = len; }
int ListBoxX::Length() { if (wid) return gtk_tree_model_iter_n_children(gtk_tree_view_get_model - (GTK_TREE_VIEW(list)), NULL); + (GTK_TREE_VIEW(list)), nullptr); return 0; }
@@ -1714,31 +1725,31 @@ void ListBoxX::Select(int n) { return; }
- bool valid = gtk_tree_model_iter_nth_child(model, &iter, NULL, n) != FALSE; + const bool valid = gtk_tree_model_iter_nth_child(model, &iter, nullptr, n) != FALSE; if (valid) { gtk_tree_selection_select_iter(selection, &iter);
// Move the scrollbar to show the selection. - int total = Length(); + const int total = Length(); #if GTK_CHECK_VERSION(3,0,0) GtkAdjustment *adj = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(list)); #else GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(list)); #endif - gfloat value = ((gfloat)n / total) * (gtk_adjustment_get_upper(adj) - gtk_adjustment_get_lower(adj)) + gfloat value = (static_cast<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; // Get cell height - int row_height = GetRowHeight(); + const int row_height = GetRowHeight();
int rows = Length(); if ((rows == 0) || (rows > desiredVisibleRows)) rows = desiredVisibleRows; if (rows & 0x1) { // Odd rows to display -- We are now in the middle. // Align it so that we don't chop off rows. - value += (gfloat)row_height / 2.0; + value += static_cast<gfloat>(row_height) / 2.0f; } // Clamp it. value = (value < 0)? 0 : value; @@ -1765,7 +1776,7 @@ int ListBoxX::GetSelection() { selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list)); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { GtkTreePath *path = gtk_tree_model_get_path(model, &iter); - int *indices = gtk_tree_path_get_indices(path); + const int *indices = gtk_tree_path_get_indices(path); // Don't free indices. if (indices) index = indices[0]; @@ -1780,7 +1791,7 @@ int ListBoxX::Find(const char *prefix) { gtk_tree_view_get_model(GTK_TREE_VIEW(list)); bool valid = gtk_tree_model_get_iter_first(model, &iter) != FALSE; int i = 0; - while(valid) { + while (valid) { gchar *s; gtk_tree_model_get(model, &iter, TEXT_COLUMN, &s, -1); if (s && (0 == strncmp(prefix, s, strlen(prefix)))) { @@ -1795,10 +1806,10 @@ int ListBoxX::Find(const char *prefix) { }
void ListBoxX::GetValue(int n, char *value, int len) { - char *text = NULL; + char *text = nullptr; GtkTreeIter iter; GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list)); - bool valid = gtk_tree_model_iter_nth_child(model, &iter, NULL, n) != FALSE; + const bool valid = gtk_tree_model_iter_nth_child(model, &iter, nullptr, n) != FALSE; if (valid) { gtk_tree_model_get(model, &iter, TEXT_COLUMN, &text, -1); } @@ -1822,12 +1833,12 @@ void ListBoxX::RegisterRGBA(int type, RGBAImage *image) { pixhash = g_hash_table_new(g_direct_hash, g_direct_equal); } ListImage *list_image = static_cast<ListImage *>(g_hash_table_lookup((GHashTable *) pixhash, - (gconstpointer) GINT_TO_POINTER(type))); + GINT_TO_POINTER(type))); if (list_image) { // Drop icon already registered if (list_image->pixbuf) g_object_unref(list_image->pixbuf); - list_image->pixbuf = NULL; + list_image->pixbuf = nullptr; list_image->rgba_data = image; } else { list_image = g_new0(ListImage, 1); @@ -1857,10 +1868,10 @@ void ListBoxX::SetDelegate(IListBoxDelegate *lbDelegate) {
void ListBoxX::SetList(const char *listText, char separator, char typesep) { Clear(); - int count = strlen(listText) + 1; + const size_t count = strlen(listText) + 1; std::vector<char> words(listText, listText+count); char *startword = &words[0]; - char *numword = NULL; + char *numword = nullptr; int i = 0; for (; words[i]; i++) { if (words[i] == separator) { @@ -1869,7 +1880,7 @@ void ListBoxX::SetList(const char *listText, char separator, char typesep) { *numword = '\0'; Append(startword, numword?atoi(numword + 1):-1); startword = &words[0] + i + 1; - numword = NULL; + numword = nullptr; } else if (words[i] == typesep) { numword = &words[0] + i; } @@ -1881,7 +1892,7 @@ void ListBoxX::SetList(const char *listText, char separator, char typesep) { } }
-Menu::Menu() noexcept : mid(0) {} +Menu::Menu() noexcept : mid(nullptr) {}
void Menu::CreatePopUp() { Destroy(); @@ -1892,7 +1903,7 @@ void Menu::CreatePopUp() { void Menu::Destroy() { if (mid) g_object_unref(G_OBJECT(mid)); - mid = 0; + mid = nullptr; }
#if !GTK_CHECK_VERSION(3,22,0) @@ -1908,12 +1919,12 @@ void Menu::Show(Point pt, Window &w) { 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); + gtk_menu_popup_at_pointer(widget, nullptr); #else - GdkRectangle rcMonitor = MonitorRectangleForWidget(PWidget(w.GetID())); + const GdkRectangle rcMonitor = MonitorRectangleForWidget(PWidget(w.GetID())); GtkRequisition requisition; #if GTK_CHECK_VERSION(3,0,0) - gtk_widget_get_preferred_size(GTK_WIDGET(widget), NULL, &requisition); + gtk_widget_get_preferred_size(GTK_WIDGET(widget), nullptr, &requisition); #else gtk_widget_size_request(GTK_WIDGET(widget), &requisition); #endif @@ -1923,46 +1934,46 @@ void Menu::Show(Point pt, Window &w) { if ((pt.y + requisition.height) > rcMonitor.y + rcMonitor.height) { pt.y = rcMonitor.y + rcMonitor.height - requisition.height; } - gtk_menu_popup(widget, NULL, NULL, MenuPositionFunc, + gtk_menu_popup(widget, nullptr, nullptr, MenuPositionFunc, GINT_TO_POINTER((static_cast<int>(pt.y) << 16) | static_cast<int>(pt.x)), 0, gtk_get_current_event_time()); #endif }
class DynamicLibraryImpl : public DynamicLibrary { protected: - GModule* m; + GModule *m; public: - explicit DynamicLibraryImpl(const char *modulePath) { + explicit DynamicLibraryImpl(const char *modulePath) noexcept { m = g_module_open(modulePath, G_MODULE_BIND_LAZY); }
~DynamicLibraryImpl() override { - if (m != NULL) + if (m != nullptr) g_module_close(m); }
// Use g_module_symbol to get a pointer to the relevant function. Function FindFunction(const char *name) override { - if (m != NULL) { - gpointer fn_address = NULL; - gboolean status = g_module_symbol(m, name, &fn_address); + if (m != nullptr) { + gpointer fn_address = nullptr; + const gboolean status = g_module_symbol(m, name, &fn_address); if (status) return static_cast<Function>(fn_address); else - return NULL; + return nullptr; } else { - return NULL; + return nullptr; } }
bool IsValid() override { - return m != NULL; + return m != nullptr; } };
DynamicLibrary *DynamicLibrary::Load(const char *modulePath) { - return static_cast<DynamicLibrary *>( new DynamicLibraryImpl(modulePath) ); + return static_cast<DynamicLibrary *>(new DynamicLibraryImpl(modulePath)); }
ColourDesired Platform::Chrome() { @@ -2017,7 +2028,7 @@ void Platform::DebugPrintf(const char *, ...) {} static bool assertionPopUps = true;
bool Platform::ShowAssertionPopUps(bool assertionPopUps_) { - bool ret = assertionPopUps; + const bool ret = assertionPopUps; assertionPopUps = assertionPopUps_; return ret; }
Modified: scintilla/gtk/ScintillaGTK.cxx 773 lines changed, 408 insertions(+), 365 deletions(-) =================================================================== @@ -7,7 +7,6 @@ #include <cstdlib> #include <cassert> #include <cstring> -#include <cctype> #include <cstdio> #include <ctime> #include <cmath> @@ -29,7 +28,10 @@ #include <gdk/gdkwayland.h> #endif
-#if defined(__WIN32__) || defined(_MSC_VER) +#if defined(_WIN32) +// On Win32 use windows.h to access clipboard (rectangular format) and systems parameters +#undef NOMINMAX +#define NOMINMAX #include <windows.h> #endif
@@ -43,6 +45,7 @@ #include "SciLexer.h" #endif #include "StringCopy.h" +#include "CharacterCategory.h" #ifdef SCI_LEXER #include "LexerModule.h" #endif @@ -92,7 +95,7 @@ #define SC_INDICATOR_CONVERTED INDIC_IME+2 #define SC_INDICATOR_UNKNOWN INDIC_IME_MAX
-static GdkWindow *WindowFromWidget(GtkWidget *w) { +static GdkWindow *WindowFromWidget(GtkWidget *w) noexcept { return gtk_widget_get_window(w); }
@@ -105,34 +108,33 @@ static GdkWindow *WindowFromWidget(GtkWidget *w) {
using namespace Scintilla;
-static GdkWindow *PWindow(const Window &w) { +static GdkWindow *PWindow(const Window &w) noexcept { GtkWidget *widget = static_cast<GtkWidget *>(w.GetID()); return gtk_widget_get_window(widget); }
extern std::string UTF8FromLatin1(const char *s, int len);
enum { - COMMAND_SIGNAL, - NOTIFY_SIGNAL, - LAST_SIGNAL + COMMAND_SIGNAL, + NOTIFY_SIGNAL, + LAST_SIGNAL };
static gint scintilla_signals[LAST_SIGNAL] = { 0 };
enum { - TARGET_STRING, - TARGET_TEXT, - TARGET_COMPOUND_TEXT, - TARGET_UTF8_STRING, - TARGET_URI + TARGET_STRING, + TARGET_TEXT, + TARGET_COMPOUND_TEXT, + TARGET_UTF8_STRING, + TARGET_URI };
-GdkAtom ScintillaGTK::atomClipboard = 0; -GdkAtom ScintillaGTK::atomUTF8 = 0; -GdkAtom ScintillaGTK::atomString = 0; -GdkAtom ScintillaGTK::atomUriList = 0; -GdkAtom ScintillaGTK::atomDROPFILES_DND = 0; +GdkAtom ScintillaGTK::atomUTF8 = nullptr; +GdkAtom ScintillaGTK::atomString = nullptr; +GdkAtom ScintillaGTK::atomUriList = nullptr; +GdkAtom ScintillaGTK::atomDROPFILES_DND = nullptr;
static const GtkTargetEntry clipboardCopyTargets[] = { { (gchar *) "UTF8_STRING", 0, TARGET_UTF8_STRING }, @@ -149,7 +151,7 @@ static const gint nClipboardPasteTargets = ELEMENTS(clipboardPasteTargets);
static const GdkDragAction actionCopyOrMove = static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE);
-static GtkWidget *PWidget(Window &w) { +static GtkWidget *PWidget(const Window &w) noexcept { return static_cast<GtkWidget *>(w.GetID()); }
@@ -159,20 +161,25 @@ ScintillaGTK *ScintillaGTK::FromWidget(GtkWidget *widget) { }
ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) : - adjustmentv(0), adjustmenth(0), - verticalScrollBarWidth(30), horizontalScrollBarHeight(30), - evbtn(nullptr), capturedMouse(false), dragWasDropped(false), - lastKey(0), rectangularSelectionModifier(SCMOD_CTRL), parentClass(0), - im_context(NULL), lastNonCommonScript(PANGO_SCRIPT_INVALID_CODE), - lastWheelMouseDirection(0), - wheelMouseIntensity(0), - smoothScrollY(0), - smoothScrollX(0), - rgnUpdate(0), - repaintFullWindow(false), - styleIdleID(0), - accessibilityEnabled(SC_ACCESSIBILITY_ENABLED), - accessible(0) { + adjustmentv(nullptr), adjustmenth(nullptr), + verticalScrollBarWidth(30), horizontalScrollBarHeight(30), + evbtn(nullptr), + buttonMouse(0), + capturedMouse(false), dragWasDropped(false), + lastKey(0), rectangularSelectionModifier(SCMOD_CTRL), + parentClass(nullptr), + atomSought(nullptr), + im_context(nullptr), + lastNonCommonScript(PANGO_SCRIPT_INVALID_CODE), + lastWheelMouseDirection(0), + wheelMouseIntensity(0), + smoothScrollY(0), + smoothScrollX(0), + rgnUpdate(nullptr), + repaintFullWindow(false), + styleIdleID(0), + accessibilityEnabled(SC_ACCESSIBILITY_ENABLED), + accessible(nullptr) { sci = sci_; wMain = GTK_WIDGET(sci);
@@ -182,7 +189,7 @@ ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) : // There does not seem to be a real standard for indicating that the clipboard // contains a rectangular selection, so copy Developer Studio. cfColumnSelect = static_cast<CLIPFORMAT>( - ::RegisterClipboardFormat("MSDEVColumnSelect")); + ::RegisterClipboardFormat("MSDEVColumnSelect"));
// Get intellimouse parameters when running on win32; otherwise use // reasonable default @@ -241,21 +248,21 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) { 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_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_CURSOR)); #if GTK_CHECK_VERSION(3,8,0) gtk_widget_register_window(widget, gtk_widget_get_window(widget)); #else gdk_window_set_user_data(gtk_widget_get_window(widget), widget); #endif #if !GTK_CHECK_VERSION(3,18,0) gtk_style_context_set_background(gtk_widget_get_style_context(widget), - gtk_widget_get_window(widget)); + gtk_widget_get_window(widget)); #endif 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_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]); @@ -267,15 +274,15 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) {
im_context = gtk_im_multicontext_new(); g_signal_connect(G_OBJECT(im_context), "commit", - G_CALLBACK(Commit), this); + G_CALLBACK(Commit), this); g_signal_connect(G_OBJECT(im_context), "preedit_changed", - G_CALLBACK(PreeditChanged), this); + G_CALLBACK(PreeditChanged), this); 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); + G_CALLBACK(ScintillaGTK::StyleSetText), nullptr); g_signal_connect_after(G_OBJECT(widtxt), "realize", - G_CALLBACK(ScintillaGTK::RealizeText), NULL); + G_CALLBACK(ScintillaGTK::RealizeText), nullptr); gtk_widget_realize(widtxt); gtk_widget_realize(PWidget(scrollbarv)); gtk_widget_realize(PWidget(scrollbarh)); @@ -296,7 +303,7 @@ void ScintillaGTK::RealizeThis(GtkWidget *widget) { 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); + clipboardCopyTargets, nClipboardCopyTargets); }
void ScintillaGTK::Realize(GtkWidget *widget) { @@ -321,7 +328,7 @@ void ScintillaGTK::UnRealizeThis(GtkWidget *widget) { gtk_widget_unrealize(PWidget(wPreedit)); gtk_widget_unrealize(PWidget(wPreeditDraw)); g_object_unref(im_context); - im_context = NULL; + im_context = nullptr; if (GTK_WIDGET_CLASS(parentClass)->unrealize) GTK_WIDGET_CLASS(parentClass)->unrealize(widget);
@@ -338,8 +345,8 @@ void ScintillaGTK::UnRealize(GtkWidget *widget) {
static void MapWidget(GtkWidget *widget) { if (widget && - gtk_widget_get_visible(GTK_WIDGET(widget)) && - !IS_WIDGET_MAPPED(widget)) { + gtk_widget_get_visible(GTK_WIDGET(widget)) && + !IS_WIDGET_MAPPED(widget)) { gtk_widget_map(widget); } } @@ -389,11 +396,11 @@ void ScintillaGTK::UnMap(GtkWidget *widget) {
void ScintillaGTK::ForAll(GtkCallback callback, gpointer callback_data) { try { - (*callback) (PWidget(wText), callback_data); + (*callback)(PWidget(wText), callback_data); if (PWidget(scrollbarv)) - (*callback) (PWidget(scrollbarv), callback_data); + (*callback)(PWidget(scrollbarv), callback_data); if (PWidget(scrollbarh)) - (*callback) (PWidget(scrollbarh), callback_data); + (*callback)(PWidget(scrollbarh), callback_data); } catch (...) { errorStatus = SC_STATUS_FAILURE; } @@ -402,7 +409,7 @@ void ScintillaGTK::ForAll(GtkCallback callback, gpointer callback_data) { void ScintillaGTK::MainForAll(GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data) { ScintillaGTK *sciThis = FromWidget((GtkWidget *)container);
- if (callback != NULL && include_internals) { + if (callback && include_internals) { sciThis->ForAll(callback, callback_data); } } @@ -421,7 +428,7 @@ class PreEditString {
explicit PreEditString(GtkIMContext *im_context) { gtk_im_context_get_preedit_string(im_context, &str, &attrs, &cursor_pos); - validUTF8 = g_utf8_validate(str, strlen(str), NULL); + validUTF8 = g_utf8_validate(str, strlen(str), nullptr); uniStr = g_utf8_to_ucs4_fast(str, strlen(str), &uniStrLen); pscript = pango_script_for_unichar(uniStr[0]); } @@ -437,9 +444,9 @@ class PreEditString { gint ScintillaGTK::FocusInThis(GtkWidget *) { try { SetFocusState(true); - if (im_context != NULL) { + if (im_context) { PreEditString pes(im_context); - if (PWidget(wPreedit) != NULL) { + if (PWidget(wPreedit)) { if (strlen(pes.str) > 0) { gtk_widget_show(PWidget(wPreedit)); } else { @@ -464,9 +471,9 @@ gint ScintillaGTK::FocusOutThis(GtkWidget *) { try { SetFocusState(false);
- if (PWidget(wPreedit) != NULL) + if (PWidget(wPreedit)) gtk_widget_hide(PWidget(wPreedit)); - if (im_context != NULL) + if (im_context) gtk_im_context_focus_out(im_context);
} catch (...) { @@ -486,8 +493,8 @@ void ScintillaGTK::SizeRequest(GtkWidget *widget, GtkRequisition *requisition) { 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); + gtk_widget_get_preferred_size(PWidget(sciThis->scrollbarh), nullptr, &child_requisition); + gtk_widget_get_preferred_size(PWidget(sciThis->scrollbarv), nullptr, &child_requisition); #else gtk_widget_size_request(PWidget(sciThis->scrollbarh), &child_requisition); gtk_widget_size_request(PWidget(sciThis->scrollbarv), &child_requisition); @@ -516,10 +523,10 @@ void ScintillaGTK::SizeAllocate(GtkWidget *widget, GtkAllocation *allocation) { gtk_widget_set_allocation(widget, allocation); if (IS_WIDGET_REALIZED(widget)) gdk_window_move_resize(WindowFromWidget(widget), - allocation->x, - allocation->y, - allocation->width, - allocation->height); + allocation->x, + allocation->y, + allocation->width, + allocation->height);
sciThis->Resize(allocation->width, allocation->height);
@@ -530,7 +537,7 @@ void ScintillaGTK::SizeAllocate(GtkWidget *widget, GtkAllocation *allocation) {
void ScintillaGTK::Init() { parentClass = reinterpret_cast<GtkWidgetClass *>( - g_type_class_ref(gtk_container_get_type())); + g_type_class_ref(gtk_container_get_type()));
gint maskSmooth = 0; #if defined(GDK_WINDOWING_WAYLAND) @@ -544,34 +551,34 @@ void ScintillaGTK::Init() { 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 - | GDK_FOCUS_CHANGE_MASK - | GDK_LEAVE_NOTIFY_MASK - | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK - | GDK_POINTER_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK); + GDK_EXPOSURE_MASK + | GDK_SCROLL_MASK + | maskSmooth + | GDK_STRUCTURE_MASK + | GDK_KEY_PRESS_MASK + | GDK_KEY_RELEASE_MASK + | GDK_FOCUS_CHANGE_MASK + | GDK_LEAVE_NOTIFY_MASK + | GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK + | GDK_POINTER_MOTION_MASK + | GDK_POINTER_MOTION_HINT_MASK);
wText = gtk_drawing_area_new(); 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); + G_CALLBACK(ScintillaGTK::DrawText), this); #else g_signal_connect(G_OBJECT(widtxt), "expose_event", - G_CALLBACK(ScintillaGTK::ExposeText), this); + G_CALLBACK(ScintillaGTK::ExposeText), this); #endif #if GTK_CHECK_VERSION(3,0,0) // we need a runtime check because we don't want double buffering when // running on >= 3.9.2 - if (gtk_check_version(3,9,2) != NULL /* on < 3.9.2 */) + if (gtk_check_version(3, 9, 2) != nullptr /* on < 3.9.2 */) #endif { #if !GTK_CHECK_VERSION(3,14,0) @@ -589,7 +596,7 @@ void ScintillaGTK::Init() { #endif gtk_widget_set_can_focus(PWidget(scrollbarv), FALSE); g_signal_connect(G_OBJECT(adjustmentv), "value_changed", - G_CALLBACK(ScrollSignal), this); + G_CALLBACK(ScrollSignal), this); gtk_widget_set_parent(PWidget(scrollbarv), PWidget(wMain)); gtk_widget_show(PWidget(scrollbarv));
@@ -601,26 +608,26 @@ void ScintillaGTK::Init() { #endif gtk_widget_set_can_focus(PWidget(scrollbarh), FALSE); g_signal_connect(G_OBJECT(adjustmenth), "value_changed", - G_CALLBACK(ScrollHSignal), this); + G_CALLBACK(ScrollHSignal), this); gtk_widget_set_parent(PWidget(scrollbarh), PWidget(wMain)); gtk_widget_show(PWidget(scrollbarh));
gtk_widget_grab_focus(PWidget(wMain));
gtk_drag_dest_set(GTK_WIDGET(PWidget(wMain)), - GTK_DEST_DEFAULT_ALL, clipboardPasteTargets, nClipboardPasteTargets, - actionCopyOrMove); + GTK_DEST_DEFAULT_ALL, clipboardPasteTargets, nClipboardPasteTargets, + actionCopyOrMove);
/* create pre-edit window */ 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); + G_CALLBACK(DrawPreedit), this); #else g_signal_connect(G_OBJECT(predrw), "expose_event", - G_CALLBACK(ExposePreedit), this); + G_CALLBACK(ExposePreedit), this); #endif gtk_container_add(GTK_CONTAINER(PWidget(wPreedit)), predrw); gtk_widget_show(predrw); @@ -630,15 +637,15 @@ void ScintillaGTK::Init() { if (g_object_class_find_property(G_OBJECT_GET_CLASS( G_OBJECT(gtk_settings_get_default())), "gtk-cursor-blink")) { g_object_get(G_OBJECT( - gtk_settings_get_default()), "gtk-cursor-blink", &blinkOn, NULL); + gtk_settings_get_default()), "gtk-cursor-blink", &blinkOn, nullptr); } if (blinkOn && - g_object_class_find_property(G_OBJECT_GET_CLASS( - G_OBJECT(gtk_settings_get_default())), "gtk-cursor-blink-time")) { + g_object_class_find_property(G_OBJECT_GET_CLASS( + G_OBJECT(gtk_settings_get_default())), "gtk-cursor-blink-time")) { gint value; g_object_get(G_OBJECT( - gtk_settings_get_default()), "gtk-cursor-blink-time", &value, NULL); - caret.period = gint(value / 1.75); + gtk_settings_get_default()), "gtk-cursor-blink-time", &value, nullptr); + caret.period = static_cast<int>(value / 1.75); } else { caret.period = 0; } @@ -658,9 +665,9 @@ void ScintillaGTK::Finalise() { FineTickerCancel(tr); } if (accessible) { - gtk_accessible_set_widget(GTK_ACCESSIBLE(accessible), NULL); + gtk_accessible_set_widget(GTK_ACCESSIBLE(accessible), nullptr); g_object_unref(accessible); - accessible = 0; + accessible = nullptr; }
ScintillaBase::Finalise(); @@ -682,7 +689,7 @@ void ScintillaGTK::DisplayCursor(Window::Cursor c) {
bool ScintillaGTK::DragThreshold(Point ptStart, Point ptNow) { return gtk_drag_check_threshold(GTK_WIDGET(PWidget(wMain)), - ptStart.x, ptStart.y, ptNow.x, ptNow.y); + ptStart.x, ptStart.y, ptNow.x, ptNow.y); }
void ScintillaGTK::StartDrag() { @@ -692,23 +699,23 @@ void ScintillaGTK::StartDrag() { 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, - actionCopyOrMove, - buttonMouse, - evbtn, - -1, -1); + tl, + actionCopyOrMove, + buttonMouse, + evbtn, + -1, -1); #else gtk_drag_begin(GTK_WIDGET(PWidget(wMain)), - tl, - actionCopyOrMove, - buttonMouse, - evbtn); + tl, + actionCopyOrMove, + buttonMouse, + evbtn); #endif }
namespace Scintilla { std::string ConvertText(const char *s, size_t len, const char *charSetDest, - const char *charSetSource, bool transliterations, bool silent) { + const char *charSetSource, bool transliterations, bool silent) { // s is not const because of different versions of iconv disagreeing about const std::string destForm; Converter conv(charSetDest, charSetSource, transliterations); @@ -720,7 +727,7 @@ std::string ConvertText(const char *s, size_t len, const char *charSetDest, gsize inLeft = len; char *putf = &destForm[0]; char *pout = putf; - gsize conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); + const gsize conversions = conv.Convert(&pin, &inLeft, &pout, &outLeft); if (conversions == sizeFailure) { if (!silent) { if (len == 1) @@ -744,7 +751,7 @@ std::string ConvertText(const char *s, size_t len, const char *charSetDest, // Returns the target converted to UTF8. // Return the length in bytes. Sci::Position ScintillaGTK::TargetAsUTF8(char *text) const { - Sci::Position targetLength = targetEnd - targetStart; + const Sci::Position targetLength = targetEnd - targetStart; if (IsUnicodeMode()) { if (text) { pdoc->GetCharRange(text, targetStart, targetLength); @@ -771,7 +778,7 @@ Sci::Position ScintillaGTK::TargetAsUTF8(char *text) const { // Translates a nul terminated UTF8 string into the document encoding. // Return the length of the result in bytes. Sci::Position ScintillaGTK::EncodedFromUTF8(const char *utf8, char *encoded) const { - Sci::Position inputLength = (lengthForEncode >= 0) ? lengthForEncode : strlen(utf8); + const Sci::Position inputLength = (lengthForEncode >= 0) ? lengthForEncode : strlen(utf8); if (IsUnicodeMode()) { if (encoded) { memcpy(encoded, utf8, inputLength); @@ -799,12 +806,12 @@ Sci::Position ScintillaGTK::EncodedFromUTF8(const char *utf8, char *encoded) con
bool ScintillaGTK::ValidCodePage(int codePage) const { return codePage == 0 - || codePage == SC_CP_UTF8 - || codePage == 932 - || codePage == 936 - || codePage == 949 - || codePage == 950 - || codePage == 1361; + || codePage == SC_CP_UTF8 + || codePage == 932 + || codePage == 936 + || codePage == 949 + || codePage == 950 + || codePage == 1361; }
sptr_t ScintillaGTK::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { @@ -831,7 +838,7 @@ sptr_t ScintillaGTK::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
case SCI_ENCODEDFROMUTF8: return EncodedFromUTF8(ConstCharPtrFromUPtr(wParam), - CharPtrFromSPtr(lParam)); + CharPtrFromSPtr(lParam));
case SCI_SETRECTANGULARSELECTIONMODIFIER: rectangularSelectionModifier = wParam; @@ -841,15 +848,15 @@ sptr_t ScintillaGTK::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam return rectangularSelectionModifier;
case SCI_SETREADONLY: { - sptr_t ret = ScintillaBase::WndProc(iMessage, wParam, lParam); - if (accessible) { - ScintillaGTKAccessible *sciAccessible = ScintillaGTKAccessible::FromAccessible(accessible); - if (sciAccessible) { - sciAccessible->NotifyReadOnly(); + const sptr_t ret = ScintillaBase::WndProc(iMessage, wParam, lParam); + if (accessible) { + ScintillaGTKAccessible *sciAccessible = ScintillaGTKAccessible::FromAccessible(accessible); + if (sciAccessible) { + sciAccessible->NotifyReadOnly(); + } } + return ret; } - return ret; - }
case SCI_GETACCESSIBILITY: return accessibilityEnabled; @@ -867,7 +874,7 @@ sptr_t ScintillaGTK::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam default: return ScintillaBase::WndProc(iMessage, wParam, lParam); } - } catch (std::bad_alloc&) { + } catch (std::bad_alloc &) { errorStatus = SC_STATUS_BADALLOC; } catch (...) { errorStatus = SC_STATUS_FAILURE; @@ -901,7 +908,7 @@ bool ScintillaGTK::SetIdle(bool on) { if (!idler.state) { idler.state = true; idler.idlerID = GUINT_TO_POINTER( - gdk_threads_add_idle_full(G_PRIORITY_DEFAULT_IDLE, IdleCallback, this, NULL)); + gdk_threads_add_idle_full(G_PRIORITY_DEFAULT_IDLE, IdleCallback, this, nullptr)); } } else { // Stop idler, if it's running @@ -959,11 +966,13 @@ bool ScintillaGTK::PaintContains(PRectangle rc) { } 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}; + rc.right - rc.left, rc.bottom - rc.top + }; contains = CRectListContains(rgnUpdate, grc); #else GdkRectangle grc = {static_cast<gint>(rc.left), static_cast<gint>(rc.top), - static_cast<gint>(rc.right - rc.left), static_cast<gint>(rc.bottom - rc.top)}; + static_cast<gint>(rc.right - rc.left), static_cast<gint>(rc.bottom - rc.top) + }; if (gdk_region_rect_in(rgnUpdate, &grc) != GDK_OVERLAP_RECTANGLE_IN) { contains = false; } @@ -1023,35 +1032,35 @@ void ScintillaGTK::SetHorizontalScrollPos() {
bool ScintillaGTK::ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) { bool modified = false; - int pageScroll = LinesToScroll(); + const int pageScroll = LinesToScroll();
if (gtk_adjustment_get_upper(adjustmentv) != (nMax + 1) || - gtk_adjustment_get_page_size(adjustmentv) != nPage || - gtk_adjustment_get_page_increment(adjustmentv) != pageScroll) { + 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_set_page_size(adjustmentv, nPage); + gtk_adjustment_set_page_increment(adjustmentv, pageScroll); #if !GTK_CHECK_VERSION(3,18,0) gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmentv)); #endif modified = true; }
- PRectangle rcText = GetTextRectangle(); + const PRectangle rcText = GetTextRectangle(); int horizEndPreferred = scrollWidth; if (horizEndPreferred < 0) horizEndPreferred = 0; - unsigned int pageWidth = rcText.Width(); - unsigned int pageIncrement = pageWidth / 3; - unsigned int charWidth = vs.styles[STYLE_DEFAULT].aveCharWidth; + const unsigned int pageWidth = static_cast<unsigned int>(rcText.Width()); + const unsigned int pageIncrement = pageWidth / 3; + const unsigned int charWidth = vs.styles[STYLE_DEFAULT].aveCharWidth; 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_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_set_page_size(adjustmenth, pageWidth); + gtk_adjustment_set_page_increment(adjustmenth, pageIncrement); + gtk_adjustment_set_step_increment(adjustmenth, charWidth); #if !GTK_CHECK_VERSION(3,18,0) gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmenth)); #endif @@ -1065,28 +1074,28 @@ bool ScintillaGTK::ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) { }
void ScintillaGTK::ReconfigureScrollBars() { - PRectangle rc = wMain.GetClientPosition(); - Resize(rc.Width(), rc.Height()); + const PRectangle rc = wMain.GetClientPosition(); + Resize(static_cast<int>(rc.Width()), static_cast<int>(rc.Height())); }
void ScintillaGTK::NotifyChange() { g_signal_emit(G_OBJECT(sci), scintilla_signals[COMMAND_SIGNAL], 0, - Platform::LongFromTwoShorts(GetCtrlID(), SCEN_CHANGE), PWidget(wMain)); + Platform::LongFromTwoShorts(GetCtrlID(), SCEN_CHANGE), PWidget(wMain)); }
void ScintillaGTK::NotifyFocus(bool focus) { if (commandEvents) g_signal_emit(G_OBJECT(sci), scintilla_signals[COMMAND_SIGNAL], 0, - Platform::LongFromTwoShorts - (GetCtrlID(), focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS), PWidget(wMain)); + Platform::LongFromTwoShorts + (GetCtrlID(), focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS), PWidget(wMain)); Editor::NotifyFocus(focus); }
void ScintillaGTK::NotifyParent(SCNotification scn) { scn.nmhdr.hwndFrom = PWidget(wMain); scn.nmhdr.idFrom = GetCtrlID(); g_signal_emit(G_OBJECT(sci), scintilla_signals[NOTIFY_SIGNAL], 0, - GetCtrlID(), &scn); + GetCtrlID(), &scn); }
void ScintillaGTK::NotifyKey(int key, int modifiers) { @@ -1124,7 +1133,7 @@ class CaseFolderDBCS : public CaseFolderTable { return 1; } else if (*charSet) { std::string sUTF8 = ConvertText(mixed, lenMixed, - "UTF-8", charSet, false); + "UTF-8", charSet, false); if (!sUTF8.empty()) { gchar *mapped = g_utf8_casefold(sUTF8.c_str(), sUTF8.length()); size_t lenMapped = strlen(mapped); @@ -1159,12 +1168,12 @@ CaseFolder *ScintillaGTK::CaseFolderForEncoding() { sCharacter[0] = i; // Silent as some bytes have no assigned character std::string sUTF8 = ConvertText(sCharacter, 1, - "UTF-8", charSetBuffer, false, true); + "UTF-8", charSetBuffer, false, true); if (!sUTF8.empty()) { gchar *mapped = g_utf8_casefold(sUTF8.c_str(), sUTF8.length()); if (mapped) { std::string mappedBack = ConvertText(mapped, strlen(mapped), - charSetBuffer, "UTF-8", false, true); + charSetBuffer, "UTF-8", false, true); if ((mappedBack.length() == 1) && (mappedBack[0] != sCharacter[0])) { pcf->SetTranslation(sCharacter[0], mappedBack[0]); } @@ -1177,7 +1186,7 @@ CaseFolder *ScintillaGTK::CaseFolderForEncoding() { return new CaseFolderDBCS(charSetBuffer); } } - return 0; + return nullptr; } }
@@ -1205,8 +1214,8 @@ std::string ScintillaGTK::CaseMapString(const std::string &s, int caseMapping) {
if (IsUnicodeMode()) { std::string retMapped(s.length() * maxExpansionCaseConversion, 0); - size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(), - (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); + const size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(), + (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); retMapped.resize(lenMapped); return retMapped; } @@ -1219,7 +1228,7 @@ std::string ScintillaGTK::CaseMapString(const std::string &s, int caseMapping) { } else { // Change text to UTF-8 std::string sUTF8 = ConvertText(s.c_str(), s.length(), - "UTF-8", charSetBuffer, false); + "UTF-8", charSetBuffer, false); CaseMapper mapper(sUTF8, caseMapping == cmUpper); return ConvertText(mapper.mapped, strlen(mapper.mapped), charSetBuffer, "UTF-8", false); } @@ -1252,37 +1261,47 @@ void ScintillaGTK::Copy() { } }
-void ScintillaGTK::Paste() { - atomSought = atomUTF8; - GtkClipboard *clipBoard = - gtk_widget_get_clipboard(GTK_WIDGET(PWidget(wMain)), atomClipboard); - if (clipBoard == NULL) - return; +namespace {
- // helper class for the asynchronous paste not to risk calling in a destroyed ScintillaGTK - class Helper : GObjectWatcher { - ScintillaGTK *sci; +// Helper class for the asynchronous paste not to risk calling in a destroyed ScintillaGTK
- void Destroyed() override { - sci = 0; - } +class SelectionReceiver : GObjectWatcher { + ScintillaGTK *sci;
- public: - Helper(ScintillaGTK *sci_) : - GObjectWatcher(G_OBJECT(PWidget(sci_->wMain))), - sci(sci_) { - } + void Destroyed() override { + sci = nullptr; + }
- static void ClipboardReceived(GtkClipboard *, GtkSelectionData *selection_data, gpointer data) { - Helper *self = static_cast<Helper*>(data); - if (self->sci != 0) { - self->sci->ReceivedSelection(selection_data); - } - delete self; +public: + SelectionReceiver(ScintillaGTK *sci_) : + GObjectWatcher(G_OBJECT(sci_->MainObject())), + sci(sci_) { + } + + static void ClipboardReceived(GtkClipboard *, GtkSelectionData *selection_data, gpointer data) { + SelectionReceiver *self = static_cast<SelectionReceiver *>(data); + if (self->sci) { + self->sci->ReceivedClipboard(selection_data); } - }; + delete self; + } +};
- gtk_clipboard_request_contents(clipBoard, atomSought, Helper::ClipboardReceived, new Helper(this)); +} + +void ScintillaGTK::RequestSelection(GdkAtom atomSelection) { + atomSought = atomUTF8; + GtkClipboard *clipBoard = + gtk_widget_get_clipboard(GTK_WIDGET(PWidget(wMain)), atomSelection); + if (clipBoard) { + gtk_clipboard_request_contents(clipBoard, atomSought, + SelectionReceiver::ClipboardReceived, + new SelectionReceiver(this)); + } +} + +void ScintillaGTK::Paste() { + RequestSelection(GDK_SELECTION_CLIPBOARD); }
void ScintillaGTK::CreateCallTipWindow(PRectangle rc) { @@ -1293,23 +1312,25 @@ void ScintillaGTK::CreateCallTipWindow(PRectangle rc) { 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); + G_CALLBACK(ScintillaGTK::DrawCT), &ct); #else g_signal_connect(G_OBJECT(widcdrw), "expose_event", - G_CALLBACK(ScintillaGTK::ExposeCT), &ct); + G_CALLBACK(ScintillaGTK::ExposeCT), &ct); #endif g_signal_connect(G_OBJECT(widcdrw), "button_press_event", - G_CALLBACK(ScintillaGTK::PressCT), this); + G_CALLBACK(ScintillaGTK::PressCT), this); gtk_widget_set_events(widcdrw, - GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); + 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_WINDOW(top)); } - gtk_widget_set_size_request(PWidget(ct.wDraw), rc.Width(), rc.Height()); + const int width = static_cast<int>(rc.Width()); + const int height = static_cast<int>(rc.Height()); + gtk_widget_set_size_request(PWidget(ct.wDraw), width, height); ct.wDraw.Show(); if (PWindow(ct.wCallTip)) { - gdk_window_resize(PWindow(ct.wCallTip), rc.Width(), rc.Height()); + gdk_window_resize(PWindow(ct.wCallTip), width, height); } }
@@ -1321,7 +1342,7 @@ void ScintillaGTK::AddToPopUp(const char *label, int cmd, bool enabled) { menuItem = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(popup.GetID()), menuItem); g_object_set_data(G_OBJECT(menuItem), "CmdNum", GINT_TO_POINTER(cmd)); - g_signal_connect(G_OBJECT(menuItem),"activate", G_CALLBACK(PopUpCB), this); + g_signal_connect(G_OBJECT(menuItem), "activate", G_CALLBACK(PopUpCB), this);
if (cmd) { if (menuItem) @@ -1332,7 +1353,7 @@ void ScintillaGTK::AddToPopUp(const char *label, int cmd, bool enabled) { bool ScintillaGTK::OwnPrimarySelection() { return (wSelection.Created() && (gdk_selection_owner_get(GDK_SELECTION_PRIMARY) == PWindow(wSelection)) && - (PWindow(wSelection) != NULL)); + (PWindow(wSelection) != nullptr)); }
void ScintillaGTK::ClaimSelection() { @@ -1341,12 +1362,12 @@ void ScintillaGTK::ClaimSelection() { if (!sel.Empty() && wSelection.Created() && IS_WIDGET_REALIZED(GTK_WIDGET(PWidget(wSelection)))) { primarySelection = true; gtk_selection_owner_set(GTK_WIDGET(PWidget(wSelection)), - GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); + GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); primary.Clear(); } else if (OwnPrimarySelection()) { primarySelection = true; if (primary.Empty()) - gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); + gtk_selection_owner_set(nullptr, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); } else { primarySelection = false; primary.Clear(); @@ -1396,47 +1417,67 @@ void ScintillaGTK::GetGtkSelectionText(GtkSelectionData *selectionData, Selectio } else { // Assume buffer is in same encoding as selection selText.Copy(dest, pdoc->dbcsCodePage, - vs.styles[STYLE_DEFAULT].characterSet, isRectangular, false); + vs.styles[STYLE_DEFAULT].characterSet, isRectangular, false); } } else { // UTF-8 const char *charSetBuffer = CharacterSetID(); if (!IsUnicodeMode() && *charSetBuffer) { // Convert to locale dest = ConvertText(dest.c_str(), dest.length(), charSetBuffer, "UTF-8", true); selText.Copy(dest, pdoc->dbcsCodePage, - vs.styles[STYLE_DEFAULT].characterSet, isRectangular, false); + vs.styles[STYLE_DEFAULT].characterSet, isRectangular, false); } else { selText.Copy(dest, SC_CP_UTF8, 0, isRectangular, false); } } }
+void ScintillaGTK::InsertSelection(GtkSelectionData *selectionData) { + const gint length = gtk_selection_data_get_length(selectionData); + if (length >= 0) { + GdkAtom selection = gtk_selection_data_get_selection(selectionData); + SelectionText selText; + GetGtkSelectionText(selectionData, selText); + + UndoGroup ug(pdoc); + if (selection == GDK_SELECTION_CLIPBOARD) { + ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH); + } + + InsertPasteShape(selText.Data(), selText.Length(), + selText.rectangular ? pasteRectangular : pasteStream); + EnsureCaretVisible(); + } + Redraw(); +} + +GObject *ScintillaGTK::MainObject() const noexcept { + return G_OBJECT(PWidget(wMain)); +} + +void ScintillaGTK::ReceivedClipboard(GtkSelectionData *selection_data) noexcept { + try { + InsertSelection(selection_data); + } catch (...) { + errorStatus = SC_STATUS_FAILURE; + } +} + void ScintillaGTK::ReceivedSelection(GtkSelectionData *selection_data) { try { - if ((SelectionOfGSD(selection_data) == atomClipboard) || - (SelectionOfGSD(selection_data) == GDK_SELECTION_PRIMARY)) { + if ((SelectionOfGSD(selection_data) == GDK_SELECTION_CLIPBOARD) || + (SelectionOfGSD(selection_data) == GDK_SELECTION_PRIMARY)) { if ((atomSought == atomUTF8) && (LengthOfGSD(selection_data) <= 0)) { atomSought = atomString; gtk_selection_convert(GTK_WIDGET(PWidget(wMain)), - SelectionOfGSD(selection_data), atomSought, GDK_CURRENT_TIME); + 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 (SelectionOfGSD(selection_data) != GDK_SELECTION_PRIMARY) { - ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH); - } - - InsertPasteShape(selText.Data(), selText.Length(), - selText.rectangular ? pasteRectangular : pasteStream); - EnsureCaretVisible(); + ((TypeOfGSD(selection_data) == GDK_TARGET_STRING) || (TypeOfGSD(selection_data) == atomUTF8))) { + InsertSelection(selection_data); } } // else fprintf(stderr, "Target non string %d %d\n", (int)(selection_data->type), // (int)(atomUTF8)); - Redraw(); } catch (...) { errorStatus = SC_STATUS_FAILURE; } @@ -1507,29 +1548,29 @@ void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, Se gtk_selection_data_set_text(selection_data, textData, len); } else { gtk_selection_data_set(selection_data, - static_cast<GdkAtom>(GDK_SELECTION_TYPE_STRING), - 8, reinterpret_cast<const guchar *>(textData), len); + static_cast<GdkAtom>(GDK_SELECTION_TYPE_STRING), + 8, reinterpret_cast<const guchar *>(textData), len); } }
void ScintillaGTK::StoreOnClipboard(SelectionText *clipText) { GtkClipboard *clipBoard = - gtk_widget_get_clipboard(GTK_WIDGET(PWidget(wMain)), atomClipboard); - if (clipBoard == NULL) // Occurs if widget isn't in a toplevel + gtk_widget_get_clipboard(GTK_WIDGET(PWidget(wMain)), GDK_SELECTION_CLIPBOARD); + if (clipBoard == nullptr) // Occurs if widget isn't in a toplevel return;
if (gtk_clipboard_set_with_data(clipBoard, clipboardCopyTargets, nClipboardCopyTargets, - ClipboardGetSelection, ClipboardClearSelection, clipText)) { + ClipboardGetSelection, ClipboardClearSelection, clipText)) { gtk_clipboard_set_can_store(clipBoard, clipboardCopyTargets, nClipboardCopyTargets); } }
void ScintillaGTK::ClipboardGetSelection(GtkClipboard *, GtkSelectionData *selection_data, guint info, void *data) { - GetSelection(selection_data, info, static_cast<SelectionText*>(data)); + GetSelection(selection_data, info, static_cast<SelectionText *>(data)); }
void ScintillaGTK::ClipboardClearSelection(GtkClipboard *, void *data) { - SelectionText *obj = static_cast<SelectionText*>(data); + SelectionText *obj = static_cast<SelectionText *>(data); delete obj; }
@@ -1595,9 +1636,9 @@ void ScintillaGTK::Resize(int width, int height) {
// These allocations should never produce negative sizes as they would wrap around to huge // unsigned numbers inside GTK+ causing warnings. - bool showSBHorizontal = horizontalScrollBarVisible && !Wrapping(); + const bool showSBHorizontal = horizontalScrollBarVisible && !Wrapping();
- GtkAllocation alloc; + GtkAllocation alloc = {}; if (showSBHorizontal) { gtk_widget_show(GTK_WIDGET(PWidget(scrollbarh))); alloc.x = 0; @@ -1632,7 +1673,7 @@ void ScintillaGTK::Resize(int width, int height) { #if GTK_CHECK_VERSION(3, 0, 0) // please GTK 3.20 and ask wText what size it wants, although we know it doesn't really need // anything special as it's ours. - gtk_widget_get_preferred_size(PWidget(wText), &requisition, NULL); + gtk_widget_get_preferred_size(PWidget(wText), &requisition, nullptr); alloc.width = requisition.width; alloc.height = requisition.height; #endif @@ -1641,10 +1682,12 @@ void ScintillaGTK::Resize(int width, int height) { gtk_widget_size_allocate(GTK_WIDGET(PWidget(wText)), &alloc); }
-static void SetAdjustmentValue(GtkAdjustment *object, int value) { +namespace { + +void SetAdjustmentValue(GtkAdjustment *object, int value) { GtkAdjustment *adjustment = GTK_ADJUSTMENT(object); - int maxValue = static_cast<int>( - gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment)); + const int maxValue = static_cast<int>( + gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment));
if (value > maxValue) value = maxValue; @@ -1653,21 +1696,29 @@ static void SetAdjustmentValue(GtkAdjustment *object, int value) { gtk_adjustment_set_value(adjustment, value); }
-static int modifierTranslated(int sciModifier) { +int modifierTranslated(int sciModifier) noexcept { switch (sciModifier) { - case SCMOD_SHIFT: - return GDK_SHIFT_MASK; - case SCMOD_CTRL: - return GDK_CONTROL_MASK; - case SCMOD_ALT: - return GDK_MOD1_MASK; - case SCMOD_SUPER: - return GDK_MOD4_MASK; - default: - return 0; + case SCMOD_SHIFT: + return GDK_SHIFT_MASK; + case SCMOD_CTRL: + return GDK_CONTROL_MASK; + case SCMOD_ALT: + return GDK_MOD1_MASK; + case SCMOD_SUPER: + return GDK_MOD4_MASK; + default: + return 0; } }
+Point PointOfEvent(const GdkEventButton *event) noexcept { + // Use floor as want to round in the same direction (-infinity) so + // there is no stickiness crossing 0.0. + return Point(static_cast<XYPOSITION>(std::floor(event->x)), static_cast<XYPOSITION>(std::floor(event->y))); +} + +} + gint ScintillaGTK::PressThis(GdkEventButton *event) { try { //Platform::DebugPrintf("Press %x time=%d state = %x button = %x\n",this,event->time, event->state, event->button); @@ -1680,46 +1731,42 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) { } evbtn = gdk_event_copy(reinterpret_cast<GdkEvent *>(event)); buttonMouse = event->button; - Point pt; - pt.x = floor(event->x); - pt.y = floor(event->y); - PRectangle rcClient = GetClientRectangle(); + const Point pt = PointOfEvent(event); + const 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); if ((pt.x > rcClient.right) || (pt.y > rcClient.bottom)) { Platform::DebugPrintf("Bad location\n"); return FALSE; }
- bool shift = (event->state & GDK_SHIFT_MASK) != 0; + const bool shift = (event->state & GDK_SHIFT_MASK) != 0; bool ctrl = (event->state & GDK_CONTROL_MASK) != 0; // On X, instead of sending literal modifiers use the user specified // modifier, defaulting to control instead of alt. // This is because most X window managers grab alt + click for moving - bool alt = (event->state & modifierTranslated(rectangularSelectionModifier)) != 0; + const bool alt = (event->state & modifierTranslated(rectangularSelectionModifier)) != 0;
gtk_widget_grab_focus(PWidget(wMain)); if (event->button == 1) { #if PLAT_GTK_MACOSX - bool meta = ctrl; + const bool meta = ctrl; // GDK reports the Command modifer key as GDK_MOD2_MASK for button events, // not GDK_META_MASK like in key events. ctrl = (event->state & GDK_MOD2_MASK) != 0; #else - bool meta = false; + const bool meta = false; #endif ButtonDownWithModifiers(pt, event->time, ModifierFlags(shift, ctrl, alt, meta)); } else if (event->button == 2) { // Grab the primary selection if it exists - SelectionPosition pos = SPositionFromLocation(pt, false, false, UserVirtualSpace()); + const SelectionPosition pos = SPositionFromLocation(pt, false, false, UserVirtualSpace()); if (OwnPrimarySelection() && primary.Empty()) CopySelectionRange(&primary);
sel.Clear(); SetSelection(pos, pos); - atomSought = atomUTF8; - gtk_selection_convert(GTK_WIDGET(PWidget(wMain)), GDK_SELECTION_PRIMARY, - atomSought, event->time); + RequestSelection(GDK_SELECTION_PRIMARY); } else if (event->button == 3) { if (!PointInSelection(pt)) SetEmptySelection(PositionFromLocation(pt)); @@ -1732,12 +1779,12 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) { ContextMenu(Point(pt.x + ox, pt.y + oy)); } else { #if PLAT_GTK_MACOSX - bool meta = ctrl; + const bool meta = ctrl; // GDK reports the Command modifer key as GDK_MOD2_MASK for button events, // not GDK_META_MASK like in key events. ctrl = (event->state & GDK_MOD2_MASK) != 0; #else - bool meta = false; + const bool meta = false; #endif RightButtonDownWithModifiers(pt, event->time, ModifierFlags(shift, ctrl, alt, meta)); return FALSE; @@ -1775,19 +1822,17 @@ gint ScintillaGTK::MouseRelease(GtkWidget *widget, GdkEventButton *event) { if (!sciThis->HaveMouseCapture()) return FALSE; if (event->button == 1) { - Point pt; - pt.x = int(event->x); - pt.y = int(event->y); + Point pt = PointOfEvent(event); //Platform::DebugPrintf("Up %x %x %d %d %d\n", // sciThis,event->window,event->time, pt.x, pt.y); 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; const int modifiers = ModifierFlags( - (event->state & GDK_SHIFT_MASK) != 0, - (event->state & GDK_CONTROL_MASK) != 0, - (event->state & modifierTranslated(sciThis->rectangularSelectionModifier)) != 0); + (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 (...) { @@ -1802,7 +1847,7 @@ gint ScintillaGTK::ScrollEvent(GtkWidget *widget, GdkEventScroll *event) { ScintillaGTK *sciThis = FromWidget(widget); try {
- if (widget == NULL || event == NULL) + if (widget == nullptr || event == nullptr) return FALSE;
#if defined(GDK_WINDOWING_WAYLAND) @@ -1811,12 +1856,12 @@ gint ScintillaGTK::ScrollEvent(GtkWidget *widget, GdkEventScroll *event) { sciThis->smoothScrollY += event->delta_y * smoothScrollFactor; sciThis->smoothScrollX += event->delta_x * smoothScrollFactor;; if (ABS(sciThis->smoothScrollY) >= 1.0) { - const int scrollLines = trunc(sciThis->smoothScrollY); + const int scrollLines = std::trunc(sciThis->smoothScrollY); sciThis->ScrollTo(sciThis->topLine + scrollLines); sciThis->smoothScrollY -= scrollLines; } if (ABS(sciThis->smoothScrollX) >= 1.0) { - const int scrollPixels = trunc(sciThis->smoothScrollX); + const int scrollPixels = std::trunc(sciThis->smoothScrollX); sciThis->HorizontalScrollTo(sciThis->xOffset + scrollPixels); sciThis->smoothScrollX -= scrollPixels; } @@ -1913,7 +1958,7 @@ gint ScintillaGTK::Motion(GtkWidget *widget, GdkEventMotion *event) { if (event->is_hint) { #if GTK_CHECK_VERSION(3,0,0) gdk_window_get_device_position(event->window, - event->device, &x, &y, &state); + event->device, &x, &y, &state); #else gdk_window_get_pointer(event->window, &x, &y, &state); #endif @@ -1924,11 +1969,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); + const Point pt(static_cast<XYPOSITION>(x), static_cast<XYPOSITION>(y)); const int modifiers = ModifierFlags( - (event->state & GDK_SHIFT_MASK) != 0, - (event->state & GDK_CONTROL_MASK) != 0, - (event->state & modifierTranslated(sciThis->rectangularSelectionModifier)) != 0); + (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; @@ -2090,10 +2135,10 @@ gboolean ScintillaGTK::KeyThis(GdkEventKey *event) { return true; }
- bool shift = (event->state & GDK_SHIFT_MASK) != 0; + const bool shift = (event->state & GDK_SHIFT_MASK) != 0; bool ctrl = (event->state & GDK_CONTROL_MASK) != 0; - bool alt = (event->state & GDK_MOD1_MASK) != 0; - bool super = (event->state & GDK_MOD4_MASK) != 0; + const bool alt = (event->state & GDK_MOD1_MASK) != 0; + const bool super = (event->state & GDK_MOD4_MASK) != 0; guint key = event->keyval; if ((ctrl || alt) && (key < 128)) key = toupper(key); @@ -2110,12 +2155,12 @@ gboolean ScintillaGTK::KeyThis(GdkEventKey *event) {
bool consumed = false; #if !(PLAT_GTK_MACOSX) - bool meta = false; + const bool meta = false; #else - bool meta = ctrl; + const bool meta = ctrl; ctrl = (event->state & GDK_META_MASK) != 0; #endif - bool added = KeyDownWithModifiers(key, ModifierFlags(shift, ctrl, alt, meta, super), &consumed) != 0; + const bool added = KeyDownWithModifiers(key, ModifierFlags(shift, ctrl, alt, meta, super), &consumed) != 0; if (!consumed) consumed = added; //fprintf(stderr, "SK-key: %d %x %x\n",event->keyval, event->state, consumed); @@ -2204,7 +2249,7 @@ bool ScintillaGTK::KoreanIME() { void ScintillaGTK::MoveImeCarets(int pos) { // Move carets relatively by bytes for (size_t r=0; r<sel.Count(); r++) { - int positionInsert = sel.Range(r).Start().Position(); + const Sci::Position positionInsert = sel.Range(r).Start().Position(); sel.Range(r).caret.SetPosition(positionInsert + pos); sel.Range(r).anchor.SetPosition(positionInsert + pos); } @@ -2220,7 +2265,7 @@ void ScintillaGTK::DrawImeIndicator(int indicator, int len) { } pdoc->DecorationSetCurrentIndicator(indicator); for (size_t r=0; r<sel.Count(); r++) { - int positionInsert = sel.Range(r).Start().Position(); + const Sci::Position positionInsert = sel.Range(r).Start().Position(); pdoc->DecorationFillRange(positionInsert - len, 1, len); } } @@ -2229,17 +2274,17 @@ static std::vector<int> MapImeIndicators(PangoAttrList *attrs, const char *u8Str // Map input style to scintilla ime indicator. // Attrs position points between UTF-8 bytes. // Indicator index to be returned is character based though. - glong charactersLen = g_utf8_strlen(u8Str, strlen(u8Str)); + const glong charactersLen = g_utf8_strlen(u8Str, strlen(u8Str)); std::vector<int> indicator(charactersLen, SC_INDICATOR_UNKNOWN);
PangoAttrIterator *iterunderline = pango_attr_list_get_iterator(attrs); if (iterunderline) { do { PangoAttribute *attrunderline = pango_attr_iterator_get(iterunderline, PANGO_ATTR_UNDERLINE); if (attrunderline) { - glong start = g_utf8_strlen(u8Str, attrunderline->start_index); - glong end = g_utf8_strlen(u8Str, attrunderline->end_index); - PangoUnderline uline = (PangoUnderline)((PangoAttrInt *)attrunderline)->value; + const glong start = g_utf8_strlen(u8Str, attrunderline->start_index); + const glong end = g_utf8_strlen(u8Str, attrunderline->end_index); + const PangoUnderline uline = (PangoUnderline)((PangoAttrInt *)attrunderline)->value; for (glong i=start; i < end; ++i) { switch (uline) { case PANGO_UNDERLINE_NONE: @@ -2262,10 +2307,10 @@ static std::vector<int> MapImeIndicators(PangoAttrList *attrs, const char *u8Str PangoAttrIterator *itercolor = pango_attr_list_get_iterator(attrs); if (itercolor) { do { - PangoAttribute *backcolor = pango_attr_iterator_get(itercolor, PANGO_ATTR_BACKGROUND); + const PangoAttribute *backcolor = pango_attr_iterator_get(itercolor, PANGO_ATTR_BACKGROUND); if (backcolor) { - glong start = g_utf8_strlen(u8Str, backcolor->start_index); - glong end = g_utf8_strlen(u8Str, backcolor->end_index); + const glong start = g_utf8_strlen(u8Str, backcolor->start_index); + const glong end = g_utf8_strlen(u8Str, backcolor->end_index); for (glong i=start; i < end; ++i) { indicator[i] = SC_INDICATOR_TARGET; // target converted } @@ -2278,10 +2323,10 @@ static std::vector<int> MapImeIndicators(PangoAttrList *attrs, const char *u8Str
void ScintillaGTK::SetCandidateWindowPos() { // Composition box accompanies candidate box. - Point pt = PointMainCaret(); + const Point pt = PointMainCaret(); GdkRectangle imeBox = {0}; // No need to set width - imeBox.x = pt.x; // Only need positiion - imeBox.y = pt.y + vs.lineHeight; // underneath the first charater + imeBox.x = static_cast<gint>(pt.x); // Only need positiion + imeBox.y = static_cast<gint>(pt.y) + vs.lineHeight; // underneath the first charater gtk_im_context_set_cursor_location(im_context, &imeBox); }
@@ -2300,7 +2345,7 @@ void ScintillaGTK::CommitThis(char *commitStr) { gunichar *uniStr = g_utf8_to_ucs4_fast(commitStr, strlen(commitStr), &uniStrLen); for (glong i = 0; i < uniStrLen; i++) { gchar u8Char[UTF8MaxBytes+2] = {0}; - gint u8CharLen = g_unichar_to_utf8(uniStr[i], u8Char); + const gint u8CharLen = g_unichar_to_utf8(uniStr[i], u8Char); std::string docChar = u8Char; if (!IsUnicodeMode()) docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true); @@ -2341,7 +2386,7 @@ void ScintillaGTK::PreeditChangedInlineThis() { PreEditString preeditStr(im_context); const char *charSetSource = CharacterSetID();
- if (!preeditStr.validUTF8 || (charSetSource == NULL)) { + if (!preeditStr.validUTF8 || (charSetSource == nullptr)) { ShowCaretAtCurrentPosition(); return; } @@ -2358,11 +2403,11 @@ void ScintillaGTK::PreeditChangedInlineThis() {
std::vector<int> indicator = MapImeIndicators(preeditStr.attrs, preeditStr.str);
- bool tmpRecordingMacro = recordingMacro; + const bool tmpRecordingMacro = recordingMacro; recordingMacro = false; for (glong i = 0; i < preeditStr.uniStrLen; i++) { gchar u8Char[UTF8MaxBytes+2] = {0}; - gint u8CharLen = g_unichar_to_utf8(preeditStr.uniStr[i], u8Char); + const gint u8CharLen = g_u@@ Diff output truncated at 100000 characters. @@
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).