aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtk/PlatGTK.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'gtk/PlatGTK.cxx')
-rwxr-xr-xgtk/PlatGTK.cxx55
1 files changed, 30 insertions, 25 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;