* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <string.h>
-
-#include "main.h"
#include "ui-tree-edit.h"
+#include <cstring>
+
+#include <glib-object.h>
+
+#include "compat.h"
+#include "misc.h"
+
/*
*-------------------------------------------------------------------
* cell popup editor
gdk_keyboard_ungrab(GDK_CURRENT_TIME);
gdk_pointer_ungrab(GDK_CURRENT_TIME);
- gtk_widget_destroy(ted->window);
+ gq_gtk_widget_destroy(ted->window);
g_free(ted->old_name);
g_free(ted->new_name);
static void tree_edit_do(TreeEditData *ted)
{
- ted->new_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(ted->entry)));
+ ted->new_name = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(ted->entry)));
if (strcmp(ted->new_name, ted->old_name) != 0)
{
}
}
-static gboolean tree_edit_click_end_cb(GtkWidget *UNUSED(widget), GdkEventButton *UNUSED(event), gpointer data)
+static gboolean tree_edit_click_end_cb(GtkWidget *, GdkEventButton *, gpointer data)
{
- TreeEditData *ted = (TreeEditData *)data;
+ auto ted = static_cast<TreeEditData *>(data);
tree_edit_do(ted);
tree_edit_close(ted);
return TRUE;
}
-static gboolean tree_edit_click_cb(GtkWidget *UNUSED(widget), GdkEventButton *event, gpointer data)
+static gboolean tree_edit_click_cb(GtkWidget *, GdkEventButton *event, gpointer data)
{
- TreeEditData *ted = (TreeEditData *)data;
+ auto ted = static_cast<TreeEditData *>(data);
GdkWindow *window = gtk_widget_get_window(ted->window);
- gint x, y;
- gint w, h;
+ gint x;
+ gint y;
+ gint w;
+ gint h;
- gint xr, yr;
+ gint xr;
+ gint yr;
- xr = (gint)event->x_root;
- yr = (gint)event->y_root;
+ xr = static_cast<gint>(event->x_root);
+ yr = static_cast<gint>(event->y_root);
gdk_window_get_origin(window, &x, &y);
w = gdk_window_get_width(window);
return FALSE;
}
-static gboolean tree_edit_key_press_cb(GtkWidget *UNUSED(widget), GdkEventKey *event, gpointer data)
+static gboolean tree_edit_key_press_cb(GtkWidget *, GdkEventKey *event, gpointer data)
{
- TreeEditData *ted = (TreeEditData *)data;
+ auto ted = static_cast<TreeEditData *>(data);
switch (event->keyval)
{
static gboolean tree_edit_by_path_idle_cb(gpointer data)
{
- TreeEditData *ted = (TreeEditData *)data;
+ auto ted = static_cast<TreeEditData *>(data);
GdkRectangle rect;
- gint x, y, w, h; /* geometry of cell within tree */
- gint wx, wy; /* geometry of tree from root window */
- gint sx, sw;
+ gint x;
+ gint y;
+ gint w;
+ gint h; /* geometry of cell within tree */
+ gint wx;
+ gint wy; /* geometry of tree from root window */
+ gint sx;
+ gint sw;
gtk_tree_view_get_cell_area(ted->tree, ted->path, ted->column, &rect);
/* now show it */
gtk_widget_set_size_request(ted->window, w, h);
gtk_widget_realize(ted->window);
- gtk_window_move(GTK_WINDOW(ted->window), x, y);
+ gq_gtk_window_move(GTK_WINDOW(ted->window), x, y);
gtk_window_resize(GTK_WINDOW(ted->window), w, h);
gtk_widget_show(ted->window);
gtk_widget_grab_focus(ted->entry);
gtk_grab_add(ted->window);
gdk_pointer_grab(gtk_widget_get_window(ted->window), TRUE,
- GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK,
- NULL, NULL, GDK_CURRENT_TIME);
+ static_cast<GdkEventMask>(GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK),
+ nullptr, nullptr, GDK_CURRENT_TIME);
gdk_keyboard_grab(gtk_widget_get_window(ted->window), TRUE, GDK_CURRENT_TIME);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
gboolean tree_edit_by_path(GtkTreeView *tree, GtkTreePath *tpath, gint column, const gchar *text,
{
TreeEditData *ted;
GtkTreeViewColumn *tcolumn;
- GtkCellRenderer *cell = NULL;
+ GtkCellRenderer *cell = nullptr;
GList *list;
GList *work;
work = list;
while (work && !cell)
{
- cell = work->data;
+ cell = static_cast<GtkCellRenderer *>(work->data);
if (!GTK_IS_CELL_RENDERER_TEXT(cell))
{
- cell = NULL;
+ cell = nullptr;
}
work = work->next;
}
G_CALLBACK(tree_edit_key_press_cb), ted);
ted->entry = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(ted->entry), ted->old_name);
+ gq_gtk_entry_set_text(GTK_ENTRY(ted->entry), ted->old_name);
gtk_editable_select_region(GTK_EDITABLE(ted->entry), 0, strlen(ted->old_name));
- gtk_container_add(GTK_CONTAINER(ted->window), ted->entry);
+ gq_gtk_container_add(GTK_WIDGET(ted->window), ted->entry);
gtk_widget_show(ted->entry);
/* due to the fact that gtktreeview scrolls in an idle loop, we cannot
* reliably get the cell position until those scroll priority signals are processed
*/
- g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 2, tree_edit_by_path_idle_cb, ted, NULL);
+ g_idle_add_full(G_PRIORITY_DEFAULT_IDLE - 2, tree_edit_by_path_idle_cb, ted, nullptr);
return TRUE;
}
gboolean tree_view_get_cell_origin(GtkTreeView *widget, GtkTreePath *tpath, gint column, gboolean text_cell_only,
gint *x, gint *y, gint *width, gint *height)
{
- gint x_origin, y_origin;
- gint x_offset, y_offset;
+ gint x_origin;
+ gint y_origin;
+ gint x_offset;
+ gint y_offset;
gint header_size;
GtkTreeViewColumn *tv_column;
GdkRectangle rect;
if (text_cell_only)
{
- GtkCellRenderer *cell = NULL;
+ GtkCellRenderer *cell = nullptr;
GList *renderers;
GList *work;
gint cell_x;
work = renderers;
while (work && !cell)
{
- cell = work->data;
+ cell = static_cast<GtkCellRenderer *>(work->data);
work = work->next;
- if (!GTK_IS_CELL_RENDERER_TEXT(cell)) cell = NULL;
+ if (!GTK_IS_CELL_RENDERER_TEXT(cell)) cell = nullptr;
}
g_list_free(renderers);
void tree_view_get_cell_clamped(GtkTreeView *widget, GtkTreePath *tpath, gint column, gboolean text_cell_only,
gint *x, gint *y, gint *width, gint *height)
{
- gint wx, wy, ww, wh;
+ gint wx;
+ gint wy;
+ gint ww;
+ gint wh;
GdkWindow *window;
window = gtk_widget_get_window(GTK_WIDGET(widget));
gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
{
GtkTreeModel *store;
- GtkTreePath *tpath, *start_path, *end_path;
+ GtkTreePath *tpath;
+ GtkTreePath *start_path;
+ GtkTreePath *end_path;
gint ret = 0;
if (!gtk_tree_view_get_visible_range(widget, &start_path, &end_path)) return -1; /* we will most probably scroll down, needed for tree_view_row_make_visible */
tpath = gtk_tree_model_get_path(gtk_tree_view_get_model(widget), iter);
if (center && vis != 0)
{
- gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 0.5, 0.0);
+ gtk_tree_view_scroll_to_cell(widget, tpath, nullptr, TRUE, 0.5, 0.0);
}
else if (vis < 0)
{
- gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 0.0, 0.0);
+ gtk_tree_view_scroll_to_cell(widget, tpath, nullptr, TRUE, 0.0, 0.0);
}
else if (vis > 0)
{
- gtk_tree_view_scroll_to_cell(widget, tpath, NULL, TRUE, 1.0, 0.0);
+ gtk_tree_view_scroll_to_cell(widget, tpath, nullptr, TRUE, 1.0, 0.0);
}
gtk_tree_path_free(tpath);
store = gtk_tree_view_get_model(widget);
tpath = gtk_tree_model_get_path(store, iter);
- gtk_tree_view_get_cursor(widget, &fpath, NULL);
+ gtk_tree_view_get_cursor(widget, &fpath, nullptr);
if (fpath && gtk_tree_path_compare(tpath, fpath) == 0)
{
if (move)
{
- gtk_tree_view_set_cursor(widget, tpath, NULL, FALSE);
+ gtk_tree_view_set_cursor(widget, tpath, nullptr, FALSE);
}
}
}
return move;
}
-//gint tree_path_to_row(GtkTreePath *tpath)
-//{
- //gint *indices;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gint tree_path_to_row_unused(GtkTreePath *tpath)
+{
+ gint *indices;
- //indices = gtk_tree_path_get_indices(tpath);
- //if (indices) return indices[0];
+ indices = gtk_tree_path_get_indices(tpath);
+ if (indices) return indices[0];
- //return -1;
-//}
+ return -1;
+}
+#pragma GCC diagnostic pop
/*
*-------------------------------------------------------------------
*/
-void shift_color(GdkColor *src, gshort val, gint direction)
+void shift_color(GdkRGBA *src, gshort val, gint direction)
{
- gshort cs;
+ gdouble cs;
if (val == -1)
{
{
val = CLAMP(val, 1, 100);
}
- cs = 0xffff / 100 * val;
+
+ cs = 1.0 / 100 * val;
/* up or down ? */
- if (direction < 0 ||
- (direction == 0 &&((gint)src->red + (gint)src->green + (gint)src->blue) / 3 > 0xffff / 2))
+ if (direction < 0 || (direction == 0 &&(static_cast<gdouble>(src->red) + static_cast<gdouble>(src->green) + static_cast<gdouble>(src->blue)) / 3 > 1.0 / 2))
{
src->red = MAX(0 , src->red - cs);
src->green = MAX(0 , src->green - cs);
}
else
{
- src->red = MIN(0xffff, src->red + cs);
- src->green = MIN(0xffff, src->green + cs);
- src->blue = MIN(0xffff, src->blue + cs);
+ src->red = MIN(1.0, src->red + cs);
+ src->green = MIN(1.0, src->green + cs);
+ src->blue = MIN(1.0, src->blue + cs);
}
}
-/* darkens or lightens a style's color for given state
- * esp. useful for alternating dark/light in (c)lists
- */
-//void style_shift_color(GtkStyle *style, GtkStateType type, gshort shift_value, gint direction)
-//{
- //if (!style) return;
-
- //shift_color(&style->base[type], shift_value, direction);
- //shift_color(&style->bg[type], shift_value, direction);
-//}
-
/*
*-------------------------------------------------------------------
* auto scroll by mouse position
*-------------------------------------------------------------------
*/
-#define AUTO_SCROLL_DEFAULT_SPEED 100
-#define AUTO_SCROLL_DEFAULT_REGION 20
+enum {
+ AUTO_SCROLL_DEFAULT_SPEED = 100,
+ AUTO_SCROLL_DEFAULT_REGION = 20
+};
-typedef struct _AutoScrollData AutoScrollData;
-struct _AutoScrollData
+struct AutoScrollData
{
guint timer_id; /* event source id */
gint region_size;
{
AutoScrollData *sd;
- sd = g_object_get_data(G_OBJECT(widget), "autoscroll");
+ sd = static_cast<AutoScrollData *>(g_object_get_data(G_OBJECT(widget), "autoscroll"));
if (!sd) return;
- g_object_set_data(G_OBJECT(widget), "autoscroll", NULL);
+ g_object_set_data(G_OBJECT(widget), "autoscroll", nullptr);
if (sd->timer_id) g_source_remove(sd->timer_id);
g_free(sd);
static gboolean widget_auto_scroll_cb(gpointer data)
{
- AutoScrollData *sd = (AutoScrollData *)data;
+ auto sd = static_cast<AutoScrollData *>(data);
GdkWindow *window;
- gint x, y;
- gint w, h;
+ gint x;
+ gint y;
+ gint w;
+ gint h;
gint amt = 0;
GdkSeat *seat;
GdkDevice *device;
window = gtk_widget_get_window(sd->widget);
seat = gdk_display_get_default_seat(gdk_window_get_display(window));
device = gdk_seat_get_pointer(seat);
- gdk_window_get_device_position(window, device, &x, &y, NULL);
+ gdk_window_get_device_position(window, device, &x, &y, nullptr);
w = gdk_window_get_width(window);
h = gdk_window_get_height(window);