aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xgtk/PlatGTK.cxx57
-rwxr-xr-xgtk/ScintillaGTK.cxx35
-rwxr-xr-xgtk/ScintillaGTK.h10
3 files changed, 51 insertions, 51 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index 2947ffa11..ada99aca2 100755
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -43,16 +43,16 @@ using namespace Scintilla;
namespace {
-const double kPi = 3.14159265358979323846;
+constexpr 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.
-int pangoUnitsFromDouble(double d) noexcept {
+constexpr int pangoUnitsFromDouble(double d) noexcept {
return static_cast<int>(d * PANGO_SCALE + 0.5);
}
-float floatFromPangoUnits(int pu) noexcept {
+constexpr float floatFromPangoUnits(int pu) noexcept {
return static_cast<float>(pu) / PANGO_SCALE;
}
@@ -109,7 +109,7 @@ FontHandle *FontHandle::CreateNewFont(const FontParameters &fp) {
}
// X has a 16 bit coordinate space, so stop drawing here to avoid wrapping
-const int maxCoordinate = 32000;
+constexpr int maxCoordinate = 32000;
FontHandle *PFont(const Font &f) noexcept {
return static_cast<FontHandle *>(f.GetID());
@@ -184,7 +184,7 @@ public:
std::unique_ptr<IScreenLineLayout> Layout(const IScreenLine *screenLine) override;
- void DrawTextBase(PRectangle rc, Font &font_, XYPOSITION ybase, std::string_view text, ColourDesired fore);
+ void DrawTextBase(PRectangle rc, const Font &font_, XYPOSITION ybase, std::string_view text, ColourDesired fore);
void DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase, std::string_view text, ColourDesired fore, ColourDesired back) override;
void DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase, std::string_view text, ColourDesired fore, ColourDesired back) override;
void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, std::string_view text, ColourDesired fore) override;
@@ -353,7 +353,8 @@ void SurfaceImpl::Init(SurfaceID sid, WindowID wid) {
void SurfaceImpl::InitPixMap(int width, int height, Surface *surface_, WindowID wid) {
PLATFORM_ASSERT(surface_);
Release();
- SurfaceImpl *surfImpl = static_cast<SurfaceImpl *>(surface_);
+ SurfaceImpl *surfImpl = dynamic_cast<SurfaceImpl *>(surface_);
+ PLATFORM_ASSERT(surfImpl);
PLATFORM_ASSERT(wid);
context = cairo_reference(surfImpl->context);
pcontext = gtk_widget_create_pango_context(PWidget(wid));
@@ -488,8 +489,8 @@ void SurfaceImpl::FillRectangle(PRectangle rc, Surface &surfacePattern) {
PLATFORM_ASSERT(context);
// Tile pattern over rectangle
// Currently assumes 8x8 pattern
- const int widthPat = 8;
- const int heightPat = 8;
+ constexpr int widthPat = 8;
+ constexpr 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;
@@ -527,7 +528,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 {
- const double degrees = kPi / 180.0;
+ constexpr double degrees = kPi / 180.0;
cairo_new_sub_path(context);
cairo_arc(context, left + width - radius, top + radius, radius, -90 * degrees, 0 * degrees);
@@ -647,7 +648,7 @@ std::unique_ptr<IScreenLineLayout> SurfaceImpl::Layout(const IScreenLine *) {
std::string UTF8FromLatin1(std::string_view text) {
std::string utfForm(text.length()*2 + 1, '\0');
size_t lenU = 0;
- for (char ch : text) {
+ for (const char ch : text) {
const unsigned char uch = ch;
if (uch < 0x80) {
utfForm[lenU++] = uch;
@@ -660,7 +661,9 @@ std::string UTF8FromLatin1(std::string_view text) {
return utfForm;
}
-static std::string UTF8FromIconv(const Converter &conv, std::string_view text) {
+namespace {
+
+std::string UTF8FromIconv(const Converter &conv, std::string_view text) {
if (conv) {
std::string utfForm(text.length()*3+1, '\0');
char *pin = const_cast<char *>(text.data());
@@ -680,9 +683,9 @@ static std::string UTF8FromIconv(const Converter &conv, std::string_view text) {
// Work out how many bytes are in a character by trying to convert using iconv,
// returning the first length that succeeds.
-static size_t MultiByteLenFromIconv(const Converter &conv, const char *s, size_t len) {
+size_t MultiByteLenFromIconv(const Converter &conv, const char *s, size_t len) noexcept {
for (size_t lenMB=1; (lenMB<4) && (lenMB <= len); lenMB++) {
- char wcForm[2];
+ char wcForm[2] {};
char *pin = const_cast<char *>(s);
gsize inLeft = lenMB;
char *pout = wcForm;
@@ -695,7 +698,9 @@ static size_t MultiByteLenFromIconv(const Converter &conv, const char *s, size_t
return 1;
}
-void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, XYPOSITION ybase, std::string_view text,
+}
+
+void SurfaceImpl::DrawTextBase(PRectangle rc, const Font &font_, XYPOSITION ybase, std::string_view text,
ColourDesired fore) {
PenColour(fore);
if (context) {
@@ -832,7 +837,7 @@ void SurfaceImpl::MeasureWidths(Font &font_, std::string_view text, XYPOSITION *
positions[i++] = iti.position - (places - place) * iti.distance / places;
positionsCalculated++;
}
- clusterStart += UTF8BytesOfLead[static_cast<unsigned char>(utfForm.c_str()[clusterStart])];
+ clusterStart += UTF8BytesOfLead[static_cast<unsigned char>(utfForm[clusterStart])];
place++;
}
}
@@ -896,7 +901,6 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, std::string_view text) {
if (PFont(font_)->pfd) {
std::string utfForm;
pango_layout_set_font_description(layout, PFont(font_)->pfd);
- PangoRectangle pos;
if (et == UTF8) {
pango_layout_set_text(layout, text.data(), text.length());
} else {
@@ -908,6 +912,7 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, std::string_view text) {
pango_layout_set_text(layout, utfForm.c_str(), utfForm.length());
}
PangoLayoutLine *pangoLine = pango_layout_get_line_readonly(layout, 0);
+ PangoRectangle pos {};
pango_layout_line_get_extents(pangoLine, nullptr, &pos);
return floatFromPangoUnits(pos.width);
}
@@ -1033,7 +1038,7 @@ void Window::SetPosition(PRectangle rc) {
namespace {
-GdkRectangle MonitorRectangleForWidget(GtkWidget *wid) {
+GdkRectangle MonitorRectangleForWidget(GtkWidget *wid) noexcept {
GdkWindow *wnd = WindowFromWidget(wid);
GdkRectangle rcScreen = GdkRectangle();
#if GTK_CHECK_VERSION(3,22,0)
@@ -1158,7 +1163,7 @@ PRectangle Window::GetMonitorRect(Point pt) {
gdk_window_get_origin(WindowFromWidget(PWidget(wid)), &x_offset, &y_offset);
- GdkRectangle rect;
+ GdkRectangle rect {};
#if GTK_CHECK_VERSION(3,22,0)
GdkDisplay *pdisplay = gtk_widget_get_display(PWidget(wid));
@@ -1702,7 +1707,7 @@ void ListBoxX::Append(char *s, int type) {
list_image = static_cast<ListImage *>(g_hash_table_lookup((GHashTable *) pixhash,
GINT_TO_POINTER(type)));
}
- GtkTreeIter iter;
+ 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);
@@ -1742,7 +1747,7 @@ int ListBoxX::Length() {
}
void ListBoxX::Select(int n) {
- GtkTreeIter iter;
+ GtkTreeIter iter {};
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list));
GtkTreeSelection *selection =
gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
@@ -1797,8 +1802,8 @@ void ListBoxX::Select(int n) {
int ListBoxX::GetSelection() {
int index = -1;
- GtkTreeIter iter;
- GtkTreeModel *model;
+ GtkTreeIter iter {};
+ GtkTreeModel *model {};
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
@@ -1813,13 +1818,13 @@ int ListBoxX::GetSelection() {
}
int ListBoxX::Find(const char *prefix) {
- GtkTreeIter iter;
+ GtkTreeIter iter {};
GtkTreeModel *model =
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) {
- gchar *s;
+ gchar *s = nullptr;
gtk_tree_model_get(model, &iter, TEXT_COLUMN, &s, -1);
if (s && (0 == strncmp(prefix, s, strlen(prefix)))) {
g_free(s);
@@ -1834,7 +1839,7 @@ int ListBoxX::Find(const char *prefix) {
void ListBoxX::GetValue(int n, char *value, int len) {
char *text = nullptr;
- GtkTreeIter iter;
+ GtkTreeIter iter {};
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list));
const bool valid = gtk_tree_model_iter_nth_child(model, &iter, nullptr, n) != FALSE;
if (valid) {
@@ -1934,7 +1939,7 @@ void Menu::Destroy() {
}
#if !GTK_CHECK_VERSION(3,22,0)
-static void MenuPositionFunc(GtkMenu *, gint *x, gint *y, gboolean *, gpointer userData) {
+static void MenuPositionFunc(GtkMenu *, gint *x, gint *y, gboolean *, gpointer userData) noexcept {
sptr_t intFromPointer = GPOINTER_TO_INT(userData);
*x = intFromPointer & 0xffff;
*y = intFromPointer >> 16;
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index 3560d517d..6b3684611 100755
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -122,23 +122,18 @@ enum {
TARGET_URI
};
-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 },
{ (gchar *) "STRING", 0, TARGET_STRING },
};
-static const gint nClipboardCopyTargets = ELEMENTS(clipboardCopyTargets);
+static constexpr gint nClipboardCopyTargets = ELEMENTS(clipboardCopyTargets);
static const GtkTargetEntry clipboardPasteTargets[] = {
{ (gchar *) "text/uri-list", 0, TARGET_URI },
{ (gchar *) "UTF8_STRING", 0, TARGET_UTF8_STRING },
{ (gchar *) "STRING", 0, TARGET_STRING },
};
-static const gint nClipboardPasteTargets = ELEMENTS(clipboardPasteTargets);
+static constexpr gint nClipboardPasteTargets = ELEMENTS(clipboardPasteTargets);
static const GdkDragAction actionCopyOrMove = static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE);
@@ -146,7 +141,7 @@ static GtkWidget *PWidget(const Window &w) noexcept {
return static_cast<GtkWidget *>(w.GetID());
}
-ScintillaGTK *ScintillaGTK::FromWidget(GtkWidget *widget) {
+ScintillaGTK *ScintillaGTK::FromWidget(GtkWidget *widget) noexcept {
ScintillaObject *scio = SCINTILLA(widget);
return static_cast<ScintillaGTK *>(scio->pscin);
}
@@ -208,7 +203,7 @@ ScintillaGTK::~ScintillaGTK() {
wPreedit.Destroy();
}
-static void UnRefCursor(GdkCursor *cursor) {
+static void UnRefCursor(GdkCursor *cursor) noexcept {
#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(cursor);
#else
@@ -333,7 +328,7 @@ void ScintillaGTK::UnRealize(GtkWidget *widget) {
sciThis->UnRealizeThis(widget);
}
-static void MapWidget(GtkWidget *widget) {
+static void MapWidget(GtkWidget *widget) noexcept {
if (widget &&
gtk_widget_get_visible(GTK_WIDGET(widget)) &&
!IS_WIDGET_MAPPED(widget)) {
@@ -416,7 +411,7 @@ public:
gunichar *uniStr;
PangoScript pscript;
- explicit PreEditString(GtkIMContext *im_context) {
+ explicit PreEditString(GtkIMContext *im_context) noexcept {
gtk_im_context_get_preedit_string(im_context, &str, &attrs, &cursor_pos);
validUTF8 = g_utf8_validate(str, strlen(str), nullptr);
uniStr = g_utf8_to_ucs4_fast(str, strlen(str), &uniStrLen);
@@ -531,7 +526,7 @@ void ScintillaGTK::SizeAllocate(GtkWidget *widget, GtkAllocation *allocation) {
}
void ScintillaGTK::Init() {
- parentClass = reinterpret_cast<GtkWidgetClass *>(
+ parentClass = static_cast<GtkWidgetClass *>(
g_type_class_ref(gtk_container_get_type()));
gint maskSmooth = 0;
@@ -1263,7 +1258,7 @@ namespace {
class SelectionReceiver : GObjectWatcher {
ScintillaGTK *sci;
- void Destroyed() override {
+ void Destroyed() noexcept override {
sci = nullptr;
}
@@ -1369,10 +1364,10 @@ void ScintillaGTK::ClaimSelection() {
}
}
-static const guchar *DataOfGSD(GtkSelectionData *sd) { return gtk_selection_data_get_data(sd); }
-static gint LengthOfGSD(GtkSelectionData *sd) { return gtk_selection_data_get_length(sd); }
-static GdkAtom TypeOfGSD(GtkSelectionData *sd) { return gtk_selection_data_get_data_type(sd); }
-static GdkAtom SelectionOfGSD(GtkSelectionData *sd) { return gtk_selection_data_get_selection(sd); }
+static const guchar *DataOfGSD(GtkSelectionData *sd) noexcept { return gtk_selection_data_get_data(sd); }
+static gint LengthOfGSD(GtkSelectionData *sd) noexcept { return gtk_selection_data_get_length(sd); }
+static GdkAtom TypeOfGSD(GtkSelectionData *sd) noexcept { return gtk_selection_data_get_data_type(sd); }
+static GdkAtom SelectionOfGSD(GtkSelectionData *sd) noexcept { return gtk_selection_data_get_selection(sd); }
// Detect rectangular text, convert line ends to current mode, convert from or to UTF-8
void ScintillaGTK::GetGtkSelectionText(GtkSelectionData *selectionData, SelectionText &selText) {
@@ -1679,7 +1674,7 @@ void ScintillaGTK::Resize(int width, int height) {
namespace {
-void SetAdjustmentValue(GtkAdjustment *object, int value) {
+void SetAdjustmentValue(GtkAdjustment *object, int value) noexcept {
GtkAdjustment *adjustment = GTK_ADJUSTMENT(object);
const int maxValue = static_cast<int>(
gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment));
@@ -1944,7 +1939,7 @@ gint ScintillaGTK::Motion(GtkWidget *widget, GdkEventMotion *event) {
return FALSE;
int x = 0;
int y = 0;
- GdkModifierType state;
+ GdkModifierType state {};
if (event->is_hint) {
#if GTK_CHECK_VERSION(3,0,0)
gdk_window_get_device_position(event->window,
@@ -1972,7 +1967,7 @@ gint ScintillaGTK::Motion(GtkWidget *widget, GdkEventMotion *event) {
}
// Map the keypad keys to their equivalent functions
-static int KeyTranslate(int keyIn) {
+static int KeyTranslate(int keyIn) noexcept {
switch (keyIn) {
#if GTK_CHECK_VERSION(3,0,0)
case GDK_KEY_ISO_Left_Tab:
diff --git a/gtk/ScintillaGTK.h b/gtk/ScintillaGTK.h
index 516115acc..06d0d080d 100755
--- a/gtk/ScintillaGTK.h
+++ b/gtk/ScintillaGTK.h
@@ -36,10 +36,10 @@ class ScintillaGTK : public ScintillaBase {
GtkWidgetClass *parentClass;
- static GdkAtom atomUTF8;
- static GdkAtom atomString;
- static GdkAtom atomUriList;
- static GdkAtom atomDROPFILES_DND;
+ static inline GdkAtom atomUTF8 {};
+ static inline GdkAtom atomString {};
+ static inline GdkAtom atomUriList {};
+ static inline GdkAtom atomDROPFILES_DND {};
GdkAtom atomSought;
#if PLAT_GTK_WIN32
@@ -78,7 +78,7 @@ public:
ScintillaGTK &operator=(const ScintillaGTK &) = delete;
ScintillaGTK &operator=(ScintillaGTK &&) = delete;
virtual ~ScintillaGTK();
- static ScintillaGTK *FromWidget(GtkWidget *widget);
+ static ScintillaGTK *FromWidget(GtkWidget *widget) noexcept;
static void ClassInit(OBJECT_CLASS *object_class, GtkWidgetClass *widget_class, GtkContainerClass *container_class);
private:
void Init();