Fix #1241: 'Go to directory view' uses hard-coded default values
[geeqie.git] / src / dnd.cc
index 861fe86..63c7ee9 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "dnd.h"
 
+#include <glib-object.h>
+#include <pango/pango.h>
+
+#include "compat.h"
+#include "options.h"
 #include "pixbuf-util.h"
 
 
@@ -32,7 +36,7 @@ GtkTargetEntry dnd_file_drag_types[] = {
 gint dnd_file_drag_types_count = 2;
 
 GtkTargetEntry dnd_file_drop_types[] = {
-       { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
+       { const_cast<gchar *>(TARGET_APP_COLLECTION_MEMBER_STRING), 0, TARGET_APP_COLLECTION_MEMBER },
        { const_cast<gchar *>("text/uri-list"), 0, TARGET_URI_LIST },
        { const_cast<gchar *>("text/plain"), 0, TARGET_TEXT_PLAIN },
 };
@@ -60,13 +64,15 @@ static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h)
                *p = 0; p++; *p = 0; p++; *p = 0; p++;
                if (alpha) { *p= 255; p++; }
                }
+
+       const gint p_step = alpha ? 4 : 3;
        for (i = 1; i < h - 1; i++)
                {
                p = pix + rs * i;
                *p = 0; p++; *p = 0; p++; *p = 0; p++;
                if (alpha) *p= 255;
 
-               p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3);
+               p = pix + rs * i + (w - 1) * p_step;
                *p = 0; p++; *p = 0; p++; *p = 0; p++;
                if (alpha) *p= 255;
                }
@@ -78,22 +84,26 @@ static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h)
                }
 }
 
-/*
-static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+static void pixbuf_draw_rect_unused(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val)
 {
        gboolean alpha;
        gint rs;
        guchar *pix;
        guchar *p;
-       gint i, j;
+       gint i;
+       gint j;
 
        alpha = gdk_pixbuf_get_has_alpha(pixbuf);
        rs = gdk_pixbuf_get_rowstride(pixbuf);
        pix = gdk_pixbuf_get_pixels(pixbuf);
 
+       const gint p_step = alpha ? 4 : 3;
+
        for (j = 0; j < h; j++)
                {
-               p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3));
+               p = pix + (rs * (y + j)) + (x * p_step);
                for (i = 0; i < w; i++)
                        {
                        *p = (*p * (256-val)) >> 8; p++;
@@ -103,14 +113,18 @@ static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h,
                        }
                }
 }
-*/
+#pragma GCC diagnostic pop
+
 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items)
 {
        GdkPixbuf *dest;
-       gint w, h;
-       gint sw, sh;
-       PangoLayout *layout = NULL;
-       gint x, y;
+       gint w;
+       gint h;
+       gint sw;
+       gint sh;
+       PangoLayout *layout = nullptr;
+       gint x;
+       gint y;
 
        x = y = 0;
 
@@ -139,9 +153,10 @@ void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pi
        if (items > 1)
                {
                gchar *buf;
-               gint lw,lh;
+               gint lw;
+               gint lh;
 
-               layout = gtk_widget_create_pango_layout(widget, NULL);
+               layout = gtk_widget_create_pango_layout(widget, nullptr);
                buf = g_strdup_printf("<small> %d </small>", items);
                pango_layout_set_markup(layout, buf, -1);
                g_free(buf);
@@ -158,8 +173,8 @@ void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pi
 
        if (layout)
                {
-               pixbuf_draw_layout(dest, layout, NULL, x+1, y+1, 0, 0, 0, 255);
-               pixbuf_draw_layout(dest, layout, NULL, x, y, 255, 255, 255, 255);
+               pixbuf_draw_layout(dest, layout, nullptr, x+1, y+1, 0, 0, 0, 255);
+               pixbuf_draw_layout(dest, layout, nullptr, x, y, 255, 255, 255, 255);
 
                g_object_unref(G_OBJECT(layout));
                }
@@ -169,11 +184,11 @@ void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pi
        g_object_unref(dest);
 }
 
-static void dnd_set_drag_label_end_cb(GtkWidget *widget, GdkDragContext *UNUSED(context), gpointer data)
+static void dnd_set_drag_label_end_cb(GtkWidget *widget, GdkDragContext *, gpointer data)
 {
-       GtkWidget *window = static_cast<GtkWidget *>(data);
+       auto window = static_cast<GtkWidget *>(data);
        g_signal_handlers_disconnect_by_func(widget, (gpointer)dnd_set_drag_label_end_cb, data);
-       gtk_widget_destroy(window);
+       gq_gtk_widget_destroy(window);
 }
 
 void dnd_set_drag_label(GtkWidget *widget, GdkDragContext *context, const gchar *text)
@@ -185,7 +200,7 @@ void dnd_set_drag_label(GtkWidget *widget, GdkDragContext *context, const gchar
        gtk_widget_realize (window);
 
        label = gtk_label_new(text);
-       gtk_container_add(GTK_CONTAINER (window), label);
+       gq_gtk_container_add(GTK_WIDGET (window), label);
        gtk_widget_show(label);
        gtk_drag_set_icon_widget(context, window, -15, 10);
        g_signal_connect(G_OBJECT(widget), "drag_end",