aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <unknown>2015-09-27 12:46:04 +1000
committerNeil <unknown>2015-09-27 12:46:04 +1000
commitb8cc0f53ef2e80f80398c7dc0bdb592b3454deb3 (patch)
tree4ebd66eca67cab48d86fa2d39df1f269352427cb
parentcd26d614fffcdd62ec7a547e979e3beb005cc1b9 (diff)
downloadscintilla-mirror-b8cc0f53ef2e80f80398c7dc0bdb592b3454deb3.tar.gz
Simplify casting by using static_cast instead of reinterpret_cast, glib macros
for passing integer values to callbacks, and avoiding casts by making functions follow prototypes exactly.
-rw-r--r--gtk/PlatGTK.cxx16
-rw-r--r--gtk/ScintillaGTK.cxx43
2 files changed, 30 insertions, 29 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index fac29fd9f..e690e0c8e 100644
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -204,11 +204,11 @@ public:
static const int maxCoordinate = 32000;
static FontHandle *PFont(Font &f) {
- return reinterpret_cast<FontHandle *>(f.GetID());
+ return static_cast<FontHandle *>(f.GetID());
}
static GtkWidget *PWidget(WindowID wid) {
- return reinterpret_cast<GtkWidget *>(wid);
+ return static_cast<GtkWidget *>(wid);
}
Point Point::FromLong(long lpoint) {
@@ -559,7 +559,7 @@ void SurfaceImpl::Init(SurfaceID sid, WindowID wid) {
PLATFORM_ASSERT(sid);
Release();
PLATFORM_ASSERT(wid);
- context = cairo_reference(reinterpret_cast<cairo_t *>(sid));
+ context = cairo_reference(static_cast<cairo_t *>(sid));
pcontext = gtk_widget_create_pango_context(PWidget(wid));
// update the Pango context in case sid isn't the widget's surface
pango_cairo_update_context(context, pcontext);
@@ -1535,7 +1535,7 @@ static void small_scroller_init(SmallScroller *){}
static gboolean ButtonPress(GtkWidget *, GdkEventButton* ev, gpointer p) {
try {
- ListBoxX* lb = reinterpret_cast<ListBoxX*>(p);
+ ListBoxX* lb = static_cast<ListBoxX*>(p);
if (ev->type == GDK_2BUTTON_PRESS && lb->doubleClickAction != NULL) {
lb->doubleClickAction(lb->doubleClickActionData);
return TRUE;
@@ -2066,8 +2066,8 @@ void Menu::Destroy() {
mid = 0;
}
-static void MenuPositionFunc(GtkMenu *, gint *x, gint *y, gboolean *, gpointer userData) {
- sptr_t intFromPointer = reinterpret_cast<sptr_t>(userData);
+static void MenuPositionFunc(GtkMenu *, gint *x, gint *y, gboolean *, gpointer userData) {
+ sptr_t intFromPointer = GPOINTER_TO_INT(userData);
*x = intFromPointer & 0xffff;
*y = intFromPointer >> 16;
}
@@ -2075,7 +2075,7 @@ static void MenuPositionFunc(GtkMenu *, gint *x, gint *y, gboolean *, gpointer
void Menu::Show(Point pt, Window &) {
int screenHeight = gdk_screen_height();
int screenWidth = gdk_screen_width();
- GtkMenu *widget = reinterpret_cast<GtkMenu *>(mid);
+ GtkMenu *widget = static_cast<GtkMenu *>(mid);
gtk_widget_show_all(GTK_WIDGET(widget));
GtkRequisition requisition;
#if GTK_CHECK_VERSION(3,0,0)
@@ -2090,7 +2090,7 @@ void Menu::Show(Point pt, Window &) {
pt.y = screenHeight - requisition.height;
}
gtk_menu_popup(widget, NULL, NULL, MenuPositionFunc,
- reinterpret_cast<void *>((static_cast<int>(pt.y) << 16) | static_cast<int>(pt.x)), 0,
+ GINT_TO_POINTER((static_cast<int>(pt.y) << 16) | static_cast<int>(pt.x)), 0,
gtk_get_current_event_time());
}
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index 64cec135b..25e3587ab 100644
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -111,7 +111,7 @@ using namespace Scintilla;
#endif
static GdkWindow *PWindow(const Window &w) {
- GtkWidget *widget = reinterpret_cast<GtkWidget *>(w.GetID());
+ GtkWidget *widget = static_cast<GtkWidget *>(w.GetID());
return gtk_widget_get_window(widget);
}
@@ -322,9 +322,9 @@ private:
gint x, gint y, GtkSelectionData *selection_data, guint info, guint time);
static void DragDataGet(GtkWidget *widget, GdkDragContext *context,
GtkSelectionData *selection_data, guint info, guint time);
- static gboolean TimeOut(TimeThunk *tt);
- static gboolean IdleCallback(ScintillaGTK *sciThis);
- static gboolean StyleIdle(ScintillaGTK *sciThis);
+ static gboolean TimeOut(gpointer ptt);
+ static gboolean IdleCallback(gpointer pSci);
+ static gboolean StyleIdle(gpointer pSci);
virtual void QueueIdleWork(WorkNeeded::workItems items, int upTo);
static void PopUpCB(GtkMenuItem *menuItem, ScintillaGTK *sciThis);
@@ -375,12 +375,12 @@ static const GtkTargetEntry clipboardPasteTargets[] = {
static const gint nClipboardPasteTargets = ELEMENTS(clipboardPasteTargets);
static GtkWidget *PWidget(Window &w) {
- return reinterpret_cast<GtkWidget *>(w.GetID());
+ return static_cast<GtkWidget *>(w.GetID());
}
static ScintillaGTK *ScintillaFromWidget(GtkWidget *widget) {
- ScintillaObject *scio = reinterpret_cast<ScintillaObject *>(widget);
- return reinterpret_cast<ScintillaGTK *>(scio->pscin);
+ ScintillaObject *scio = SCINTILLA(widget);
+ return static_cast<ScintillaGTK *>(scio->pscin);
}
ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) :
@@ -1076,7 +1076,7 @@ bool ScintillaGTK::FineTickerRunning(TickReason reason) {
void ScintillaGTK::FineTickerStart(TickReason reason, int millis, int /* tolerance */) {
FineTickerCancel(reason);
- timers[reason].timer = g_timeout_add(millis, reinterpret_cast<GSourceFunc>(TimeOut), &timers[reason]);
+ timers[reason].timer = g_timeout_add(millis, TimeOut, &timers[reason]);
}
void ScintillaGTK::FineTickerCancel(TickReason reason) {
@@ -1092,8 +1092,7 @@ bool ScintillaGTK::SetIdle(bool on) {
if (!idler.state) {
idler.state = true;
idler.idlerID = reinterpret_cast<IdlerID>(
- g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
- reinterpret_cast<GSourceFunc>(IdleCallback), this, NULL));
+ g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, IdleCallback, this, NULL));
}
} else {
// Stop idler, if it's running
@@ -1484,7 +1483,7 @@ void ScintillaGTK::AddToPopUp(const char *label, int cmd, bool enabled) {
else
menuItem = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(popup.GetID()), menuItem);
- g_object_set_data(G_OBJECT(menuItem), "CmdNum", reinterpret_cast<void *>(cmd));
+ g_object_set_data(G_OBJECT(menuItem), "CmdNum", GINT_TO_POINTER(cmd));
g_signal_connect(G_OBJECT(menuItem),"activate", G_CALLBACK(PopUpCB), this);
if (cmd) {
@@ -2586,12 +2585,12 @@ static GObjectClass *scintilla_class_parent_class;
void ScintillaGTK::Destroy(GObject *object) {
try {
- ScintillaObject *scio = reinterpret_cast<ScintillaObject *>(object);
+ ScintillaObject *scio = SCINTILLA(object);
// This avoids a double destruction
if (!scio->pscin)
return;
- ScintillaGTK *sciThis = reinterpret_cast<ScintillaGTK *>(scio->pscin);
+ ScintillaGTK *sciThis = static_cast<ScintillaGTK *>(scio->pscin);
//Platform::DebugPrintf("Destroying %x %x\n", sciThis, object);
sciThis->Finalise();
@@ -2939,12 +2938,14 @@ void ScintillaGTK::DragDataGet(GtkWidget *widget, GdkDragContext *context,
}
}
-int ScintillaGTK::TimeOut(TimeThunk *tt) {
+int ScintillaGTK::TimeOut(gpointer ptt) {
+ TimeThunk *tt = static_cast<TimeThunk *>(ptt);
tt->scintilla->TickFor(tt->reason);
return 1;
}
-gboolean ScintillaGTK::IdleCallback(ScintillaGTK *sciThis) {
+gboolean ScintillaGTK::IdleCallback(gpointer pSci) {
+ ScintillaGTK *sciThis = static_cast<ScintillaGTK *>(pSci);
// Idler will be automatically stopped, if there is nothing
// to do while idle.
#ifndef GDK_VERSION_3_6
@@ -2963,10 +2964,11 @@ gboolean ScintillaGTK::IdleCallback(ScintillaGTK *sciThis) {
return ret;
}
-gboolean ScintillaGTK::StyleIdle(ScintillaGTK *sciThis) {
+gboolean ScintillaGTK::StyleIdle(gpointer pSci) {
#ifndef GDK_VERSION_3_6
gdk_threads_enter();
#endif
+ ScintillaGTK *sciThis = static_cast<ScintillaGTK *>(pSci);
sciThis->IdleWork();
#ifndef GDK_VERSION_3_6
gdk_threads_leave();
@@ -2980,13 +2982,12 @@ void ScintillaGTK::QueueIdleWork(WorkNeeded::workItems items, int upTo) {
if (!workNeeded.active) {
// Only allow one style needed to be queued
workNeeded.active = true;
- g_idle_add_full(G_PRIORITY_HIGH_IDLE,
- reinterpret_cast<GSourceFunc>(StyleIdle), this, NULL);
+ g_idle_add_full(G_PRIORITY_HIGH_IDLE, StyleIdle, this, NULL);
}
}
void ScintillaGTK::PopUpCB(GtkMenuItem *menuItem, ScintillaGTK *sciThis) {
- guint action = (sptr_t)(g_object_get_data(G_OBJECT(menuItem), "CmdNum"));
+ guint action = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(menuItem), "CmdNum"));
if (action) {
sciThis->Command(action);
}
@@ -3056,7 +3057,7 @@ sptr_t ScintillaGTK::DirectFunction(
}
sptr_t scintilla_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
- ScintillaGTK *psci = reinterpret_cast<ScintillaGTK *>(sci->pscin);
+ ScintillaGTK *psci = static_cast<ScintillaGTK *>(sci->pscin);
return psci->WndProc(iMessage, wParam, lParam);
}
@@ -3207,7 +3208,7 @@ GtkWidget* scintilla_new() {
}
void scintilla_set_id(ScintillaObject *sci, uptr_t id) {
- ScintillaGTK *psci = reinterpret_cast<ScintillaGTK *>(sci->pscin);
+ ScintillaGTK *psci = static_cast<ScintillaGTK *>(sci->pscin);
psci->ctrlID = id;
}