aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtk
diff options
context:
space:
mode:
Diffstat (limited to 'gtk')
-rwxr-xr-xgtk/PlatGTK.cxx55
-rwxr-xr-xgtk/ScintillaGTK.cxx35
-rwxr-xr-xgtk/ScintillaGTK.h2
3 files changed, 46 insertions, 46 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index f884ac565..d80daad63 100755
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -42,16 +42,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;
}
@@ -108,7 +108,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());
@@ -181,7 +181,7 @@ public:
void Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back) override;
void Copy(PRectangle rc, Point from, Surface &surfaceSource) override;
- void DrawTextBase(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore);
+ void DrawTextBase(PRectangle rc, const Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore);
void DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back) override;
void DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back) override;
void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore) override;
@@ -349,7 +349,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));
@@ -484,8 +485,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;
@@ -523,7 +524,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);
@@ -652,7 +653,9 @@ std::string UTF8FromLatin1(const char *s, int len) {
return utfForm;
}
-static std::string UTF8FromIconv(const Converter &conv, const char *s, int len) {
+namespace {
+
+std::string UTF8FromIconv(const Converter &conv, const char *s, int len) {
if (conv) {
std::string utfForm(len*3+1, '\0');
char *pin = const_cast<char *>(s);
@@ -672,9 +675,9 @@ static std::string UTF8FromIconv(const Converter &conv, const char *s, int len)
// 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;
@@ -687,7 +690,9 @@ static size_t MultiByteLenFromIconv(const Converter &conv, const char *s, size_t
return 1;
}
-void SurfaceImpl::DrawTextBase(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len,
+}
+
+void SurfaceImpl::DrawTextBase(PRectangle rc, const Font &font_, XYPOSITION ybase, const char *s, int len,
ColourDesired fore) {
PenColour(fore);
if (context) {
@@ -825,7 +830,7 @@ void SurfaceImpl::MeasureWidths(Font &font_, const char *s, int len, 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++;
}
}
@@ -888,7 +893,6 @@ XYPOSITION SurfaceImpl::WidthText(Font &font_, const char *s, int len) {
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, s, len);
} else {
@@ -900,6 +904,7 @@ 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);
+ PangoRectangle pos {};
pango_layout_line_get_extents(pangoLine, nullptr, &pos);
return floatFromPangoUnits(pos.width);
}
@@ -1022,7 +1027,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)
@@ -1147,7 +1152,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));
@@ -1691,7 +1696,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);
@@ -1731,7 +1736,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));
@@ -1786,8 +1791,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)) {
@@ -1802,13 +1807,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);
@@ -1823,7 +1828,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) {
@@ -1923,7 +1928,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 c528641fb..a295c888c 100755
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -121,23 +121,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);
@@ -145,7 +140,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);
}
@@ -207,7 +202,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
@@ -332,7 +327,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)) {
@@ -415,7 +410,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);
@@ -530,7 +525,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;
@@ -1262,7 +1257,7 @@ namespace {
class SelectionReceiver : GObjectWatcher {
ScintillaGTK *sci;
- void Destroyed() override {
+ void Destroyed() noexcept override {
sci = nullptr;
}
@@ -1368,10 +1363,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) {
@@ -1678,7 +1673,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));
@@ -1943,7 +1938,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,
@@ -1971,7 +1966,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..ed2513a3f 100755
--- a/gtk/ScintillaGTK.h
+++ b/gtk/ScintillaGTK.h
@@ -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();