diff options
author | Neil <nyamatongwe@gmail.com> | 2019-03-27 13:23:02 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2019-03-27 13:23:02 +1100 |
commit | 8a293e05789bcae9fcd25cc0369a1f58c3b2038a (patch) | |
tree | 1abf6e81f0e3f65d8cd65cd5170a474fc97e6339 | |
parent | f0922357123335afb666eb1d8beb4e1c7f9f1def (diff) | |
download | scintilla-mirror-8a293e05789bcae9fcd25cc0369a1f58c3b2038a.tar.gz |
Use const where reasonable. Some additional type safety.
-rw-r--r-- | gtk/PlatGTK.cxx | 149 | ||||
-rw-r--r-- | gtk/ScintillaGTK.cxx | 102 |
2 files changed, 128 insertions, 123 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index fd37b0a6a..e532f52e5 100644 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -28,6 +28,7 @@ #include "Scintilla.h" #include "ScintillaWidget.h" #include "StringCopy.h" +#include "IntegerRectangle.h" #include "XPM.h" #include "UniConversion.h" @@ -51,8 +52,8 @@ int pangoUnitsFromDouble(double d) noexcept { return static_cast<int>(d * PANGO_SCALE + 0.5); } -double doubleFromPangoUnits(int pu) noexcept { - return static_cast<double>(pu) / PANGO_SCALE; +float floatFromPangoUnits(int pu) noexcept { + return static_cast<float>(pu) / PANGO_SCALE; } cairo_surface_t *CreateSimilarSurface(GdkWindow *window, cairo_content_t content, int width, int height) noexcept { @@ -370,7 +371,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, @@ -383,7 +384,7 @@ int SurfaceImpl::LogPixelsY() { } int SurfaceImpl::DeviceHeightFont(int points) { - int logPix = LogPixelsY(); + const int logPix = LogPixelsY(); return (points * logPix + logPix / 2) / 72; } @@ -405,18 +406,18 @@ 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 = std::abs(x - xEnd) + 1; - int yEnd = y_ - yDelta; - int top = std::min(y, yEnd); - int height = std::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 ((std::abs(xDiff) == std::abs(yDiff))) { @@ -472,17 +473,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 != nullptr; + 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); @@ -515,7 +517,7 @@ void SurfaceImpl::RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesi } static void PathRoundRectangle(cairo_t *context, double left, double top, double width, double height, int radius) noexcept { - double degrees = kPi / 180.0; + const double degrees = kPi / 180.0; cairo_new_sub_path(context); cairo_arc(context, left + width - radius, top + radius, radius, -90 * degrees, 0 * degrees); @@ -528,7 +530,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, @@ -540,7 +542,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, @@ -590,12 +592,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; @@ -623,7 +625,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 != nullptr; + const bool canDraw = surfi.psurf != nullptr; if (canDraw) { PLATFORM_ASSERT(context); cairo_set_source_surface(context, surfi.psurf, @@ -661,7 +663,7 @@ static std::string UTF8FromIconv(const Converter &conv, std::string_view text) { char *putf = &utfForm[0]; char *pout = putf; gsize outLeft = text.length()*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); @@ -680,7 +682,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; } @@ -692,7 +694,7 @@ void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, XYPOSITION ybase, std 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) { @@ -761,11 +763,11 @@ public: positionStart = position; if (pango_layout_iter_next_cluster(iter)) { pango_layout_iter_get_cluster_extents(iter, nullptr, &pos); - position = doubleFromPangoUnits(pos.x); + 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; @@ -783,7 +785,7 @@ void SurfaceImpl::MeasureWidths(Font &font_, std::string_view text, XYPOSITION * ClusterIterator iti(layout, text.length()); 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 @@ -810,8 +812,8 @@ void SurfaceImpl::MeasureWidths(Font &font_, std::string_view text, 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, text.data()+i, text.length()-i); @@ -844,13 +846,13 @@ void SurfaceImpl::MeasureWidths(Font &font_, std::string_view text, 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, nullptr); - XYPOSITION widthTotal = doubleFromPangoUnits(widthLayout); + const XYPOSITION widthTotal = floatFromPangoUnits(widthLayout); for (size_t bytePos=0; bytePos<lenPositions; bytePos++) { positions[bytePos] = widthTotal / lenPositions * (bytePos + 1); } @@ -896,7 +898,7 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, std::string_view text) { } PangoLayoutLine *pangoLine = pango_layout_get_line_readonly(layout,0); pango_layout_line_get_extents(pangoLine, nullptr, &pos); - return doubleFromPangoUnits(pos.width); + return floatFromPangoUnits(pos.width); } return 1; } else { @@ -909,12 +911,12 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, std::string_view text) { 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) { @@ -929,7 +931,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; } @@ -998,8 +1001,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; @@ -1010,10 +1013,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); } @@ -1028,7 +1031,7 @@ GdkRectangle MonitorRectangleForWidget(GtkWidget *wid) { 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); + const gint monitor_num = gdk_screen_get_monitor_at_window(screen, wnd); gdk_screen_get_monitor_geometry(screen, monitor_num, &rcScreen); #endif return rcScreen; @@ -1037,18 +1040,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) @@ -1081,9 +1085,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()); } } @@ -1151,13 +1156,13 @@ PRectangle Window::GetMonitorRect(Point pt) { 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, + 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; @@ -1569,7 +1574,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); @@ -1693,7 +1698,7 @@ void ListBoxX::Append(char *s, int type) { 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); @@ -1708,7 +1713,7 @@ 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; } @@ -1731,12 +1736,12 @@ void ListBoxX::Select(int n) { return; } - bool valid = gtk_tree_model_iter_nth_child(model, &iter, nullptr, 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)); @@ -1744,10 +1749,10 @@ void ListBoxX::Select(int n) { 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)) @@ -1755,7 +1760,7 @@ void ListBoxX::Select(int n) { 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; @@ -1815,7 +1820,7 @@ void ListBoxX::GetValue(int n, char *value, int len) { 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, nullptr, 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); } @@ -1874,7 +1879,7 @@ 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 = nullptr; @@ -1927,7 +1932,7 @@ void Menu::Show(Point pt, Window &w) { // Rely on GTK+ to do the right thing with positioning 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), nullptr, &requisition); @@ -1963,7 +1968,7 @@ public: Function FindFunction(const char *name) override { if (m != nullptr) { gpointer fn_address = nullptr; - gboolean status = g_module_symbol(m, name, &fn_address); + const gboolean status = g_module_symbol(m, name, &fn_address); if (status) return static_cast<Function>(fn_address); else @@ -2034,7 +2039,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; } diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 94aed4933..d067843ea 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -727,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) @@ -751,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); @@ -778,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); @@ -848,7 +848,7 @@ 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); + const sptr_t ret = ScintillaBase::WndProc(iMessage, wParam, lParam); if (accessible) { ScintillaGTKAccessible *sciAccessible = ScintillaGTKAccessible::FromAccessible(accessible); if (sciAccessible) { @@ -1030,7 +1030,7 @@ 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 || @@ -1044,13 +1044,13 @@ bool ScintillaGTK::ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) { modified = true; } - PRectangle rcText = GetTextRectangle(); + const PRectangle rcText = GetTextRectangle(); int horizEndPreferred = scrollWidth; if (horizEndPreferred < 0) horizEndPreferred = 0; - unsigned int pageWidth = static_cast<unsigned int>(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 || @@ -1072,7 +1072,7 @@ bool ScintillaGTK::ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) { } void ScintillaGTK::ReconfigureScrollBars() { - PRectangle rc = wMain.GetClientPosition(); + const PRectangle rc = wMain.GetClientPosition(); Resize(static_cast<int>(rc.Width()), static_cast<int>(rc.Height())); } @@ -1212,7 +1212,7 @@ 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(), + const size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(), (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); retMapped.resize(lenMapped); return retMapped; @@ -1604,9 +1604,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; @@ -1654,7 +1654,7 @@ namespace { void SetAdjustmentValue(GtkAdjustment *object, int value) { GtkAdjustment *adjustment = GTK_ADJUSTMENT(object); - int maxValue = static_cast<int>( + const int maxValue = static_cast<int>( gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment)); if (value > maxValue) @@ -1700,7 +1700,7 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) { evbtn = gdk_event_copy(reinterpret_cast<GdkEvent *>(event)); buttonMouse = event->button; const Point pt = PointOfEvent(event); - PRectangle rcClient = GetClientRectangle(); + 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)) { @@ -1708,27 +1708,27 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) { 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); @@ -1749,12 +1749,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; @@ -2105,10 +2105,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); @@ -2125,12 +2125,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); @@ -2219,7 +2219,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); } @@ -2235,7 +2235,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); } } @@ -2244,7 +2244,7 @@ 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); @@ -2252,9 +2252,9 @@ static std::vector<int> MapImeIndicators(PangoAttrList *attrs, const char *u8Str 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: @@ -2277,10 +2277,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 } @@ -2293,7 +2293,7 @@ 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 = static_cast<gint>(pt.x); // Only need positiion imeBox.y = static_cast<gint>(pt.y) + vs.lineHeight; // underneath the first charater @@ -2315,7 +2315,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); @@ -2373,11 +2373,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_unichar_to_utf8(preeditStr.uniStr[i], u8Char); std::string docChar = u8Char; if (!IsUnicodeMode()) docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true); @@ -2389,8 +2389,8 @@ void ScintillaGTK::PreeditChangedInlineThis() { recordingMacro = tmpRecordingMacro; // Move caret to ime cursor position. - int imeEndToImeCaretU32 = preeditStr.cursor_pos - preeditStr.uniStrLen; - int imeCaretPosDoc = pdoc->GetRelativePosition(CurrentPosition(), imeEndToImeCaretU32); + const int imeEndToImeCaretU32 = preeditStr.cursor_pos - preeditStr.uniStrLen; + const int imeCaretPosDoc = pdoc->GetRelativePosition(CurrentPosition(), imeEndToImeCaretU32); MoveImeCarets(- CurrentPosition() + imeCaretPosDoc); @@ -2623,7 +2623,7 @@ gboolean ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *os PLATFORM_ASSERT(rgnUpdate == nullptr); rgnUpdate = gdk_region_copy(ose->region); - PRectangle rcClient = GetClientRectangle(); + const PRectangle rcClient = GetClientRectangle(); paintingAllText = rcPaint.Contains(rcClient); std::unique_ptr<Surface> surfaceWindow(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); cairo_t *cr = gdk_cairo_create(PWindow(wText)); @@ -2734,8 +2734,8 @@ gboolean ScintillaGTK::DragMotionThis(GdkDragContext *context, const Point npt = Point::FromInts(x, y); SetDragPosition(SPositionFromLocation(npt, false, false, UserVirtualSpace())); GdkDragAction preferredAction = gdk_drag_context_get_suggested_action(context); - GdkDragAction actions = gdk_drag_context_get_actions(context); - SelectionPosition pos = SPositionFromLocation(npt); + const GdkDragAction actions = gdk_drag_context_get_actions(context); + const SelectionPosition pos = SPositionFromLocation(npt); if ((inDragDrop == ddDragging) && (PositionInSelection(pos.Position()))) { // Avoid dragging selection onto itself as that produces a move // with no real effect but which creates undo actions. @@ -2811,7 +2811,7 @@ void ScintillaGTK::DragDataGet(GtkWidget *widget, GdkDragContext *context, if (!sciThis->sel.Empty()) { sciThis->GetSelection(selection_data, info, &sciThis->drag); } - GdkDragAction action = gdk_drag_context_get_selected_action(context); + const GdkDragAction action = gdk_drag_context_get_selected_action(context); if (action == GDK_ACTION_MOVE) { for (size_t r=0; r<sciThis->sel.Count(); r++) { if (sciThis->posDrop >= sciThis->sel.Range(r).Start()) { @@ -2840,7 +2840,7 @@ gboolean ScintillaGTK::IdleCallback(gpointer pSci) { ScintillaGTK *sciThis = static_cast<ScintillaGTK *>(pSci); // Idler will be automatically stopped, if there is nothing // to do while idle. - bool ret = sciThis->Idle(); + const bool ret = sciThis->Idle(); if (ret == false) { // FIXME: This will remove the idler from GTK, we don't want to // remove it as it is removed automatically when this function @@ -2893,7 +2893,7 @@ void ScintillaGTK::SetDocPointer(Document *document) { } void ScintillaGTK::PopUpCB(GtkMenuItem *menuItem, ScintillaGTK *sciThis) { - guint action = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(menuItem), "CmdNum")); + guint const action = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(menuItem), "CmdNum")); if (action) { sciThis->Command(action); } @@ -3076,7 +3076,7 @@ static void scintilla_class_init(ScintillaClass *klass) { GtkWidgetClass *widget_class = (GtkWidgetClass*) klass; GtkContainerClass *container_class = (GtkContainerClass*) klass; - GSignalFlags sigflags = GSignalFlags(G_SIGNAL_ACTION | G_SIGNAL_RUN_LAST); + const GSignalFlags sigflags = GSignalFlags(G_SIGNAL_ACTION | G_SIGNAL_RUN_LAST); scintilla_signals[COMMAND_SIGNAL] = g_signal_new( "command", G_TYPE_FROM_CLASS(object_class), @@ -3148,7 +3148,7 @@ static void free_(void *) { } GType scnotification_get_type(void) { static gsize type_id = 0; if (g_once_init_enter(&type_id)) { - gsize id = (gsize) g_boxed_type_register_static( + const gsize id = (gsize) g_boxed_type_register_static( g_intern_static_string("SCNotification"), (GBoxedCopyFunc) copy_, (GBoxedFreeFunc) free_); |