improved connected scroll and active image switching
authorVladimir Nadvornik <nadvornik@suse.cz>
Tue, 10 Jul 2007 21:25:51 +0000 (21:25 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Tue, 10 Jul 2007 21:25:51 +0000 (21:25 +0000)
src/image.c
src/image.h
src/layout_image.c
src/pixbuf-renderer.c
src/pixbuf-renderer.h
src/typedefs.h

index 0c8398e..a3b2108 100644 (file)
@@ -64,6 +64,19 @@ static void image_click_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer d
                }
 }
 
+static void image_drag_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data)
+{
+       ImageWindow *imd = data;
+
+       if (imd->func_drag)
+               {
+               imd->func_drag(imd, event->button, event->time,
+                                event->x, event->y, event->state,
+                                event->x - pr->drag_last_x, event->y - pr->drag_last_y,
+                                imd->data_button);
+               }
+}
+
 static void image_scroll_notify_cb(PixbufRenderer *pr, gpointer data)
 {
        ImageWindow *imd = data;
@@ -1103,6 +1116,14 @@ void image_set_button_func(ImageWindow *imd,
        imd->data_button = data;
 }
 
+void image_set_drag_func(ImageWindow *imd,
+                          void (*func)(ImageWindow *, gint button, guint32 time, gdouble x, gdouble y, guint state, gdouble dx, gdouble dy, gpointer),
+                          gpointer data)
+{
+       imd->func_drag = func;
+       imd->data_drag = data;
+}
+
 void image_set_scroll_func(ImageWindow *imd,
                           void (*func)(ImageWindow *, GdkScrollDirection direction, guint32 time, gdouble x, gdouble y, guint state, gpointer),
                           gpointer data)
@@ -1836,6 +1857,8 @@ ImageWindow *image_new(gint frame)
                         G_CALLBACK(image_zoom_cb), imd);
        g_signal_connect(G_OBJECT(imd->pr), "render_complete",
                         G_CALLBACK(image_render_complete_cb), imd);
+       g_signal_connect(G_OBJECT(imd->pr), "drag",
+                        G_CALLBACK(image_drag_cb), imd);
 
        image_list = g_list_append(image_list, imd);
 
index ec4ff2c..f3bb35e 100644 (file)
@@ -25,6 +25,9 @@ void image_set_update_func(ImageWindow *imd,
 void image_set_button_func(ImageWindow *imd,
        void (*func)(ImageWindow *, gint button, guint32 time, gdouble x, gdouble y, guint state, gpointer),
        gpointer data);
+void image_set_drag_func(ImageWindow *imd,
+       void (*func)(ImageWindow *, gint button, guint32 time, gdouble x, gdouble y, guint state, gdouble dx, gdouble dy, gpointer),
+       gpointer data);
 void image_set_scroll_func(ImageWindow *imd,
        void (*func)(ImageWindow *, GdkScrollDirection direction, guint32 time, gdouble x, gdouble y, guint state, gpointer),
         gpointer data);
index 65a609d..ef60ce6 100644 (file)
@@ -1526,10 +1526,10 @@ static void layout_image_scroll_cb(ImageWindow *imd, GdkScrollDirection directio
                }
 }
 
-static void layout_image_scroll_notify_cb(ImageWindow *imd, gint x, gint y, gint width, gint height, gpointer data)
+static void layout_image_drag_cb(ImageWindow *imd, gint button, guint32 time,
+                                gdouble x, gdouble y, guint state, gdouble dx, gdouble dy, gpointer data)
 {
        gint i;
-       printf("scroll cb %d %d %d %d\n", x,y,width, height);
        LayoutWindow *lw = data;
 
 
@@ -1554,6 +1554,7 @@ static void layout_image_button_inactive_cb(ImageWindow *imd, gint button, guint
                                   gdouble x, gdouble y, guint state, gpointer data)
 {
        LayoutWindow *lw = data;
+       GtkWidget *menu;
        gint i = image_idx(lw, imd);
        
        if (i != -1)
@@ -1561,8 +1562,48 @@ static void layout_image_button_inactive_cb(ImageWindow *imd, gint button, guint
                printf("image activate %d\n", i);
                layout_image_activate(lw, i);
                }
+
+       switch (button)
+               {
+               case 3:
+                       menu = layout_image_pop_menu(lw);
+                       if (imd == lw->image)
+                               {
+                               g_object_set_data(G_OBJECT(menu), "click_parent", imd->widget);
+                               }
+                       gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, time);
+                       break;
+               default:
+                       break;
+               }
+
 }
 
+static void layout_image_drag_inactive_cb(ImageWindow *imd, gint button, guint32 time,
+                                gdouble x, gdouble y, guint state, gdouble dx, gdouble dy, gpointer data)
+{
+       LayoutWindow *lw = data;
+
+       gint i = image_idx(lw, imd);
+       
+       if (i != -1)
+               {
+               printf("image activate %d\n", i);
+               layout_image_activate(lw, i);
+               }
+
+
+       for (i=0; i < MAX_SPLIT_IMAGES; i++)
+               {
+               if (lw->split_images[i] && lw->split_images[i] != imd)
+//                     if (lw->connect_zoom)
+//                             image_sync_zoom_from_image(lw->split_images[i], imd);
+                       if (lw->connect_scroll)
+                               image_sync_scroll_from_image_absolute(lw->split_images[i], imd);
+               }
+}
+
+
 static void layout_image_set_buttons(LayoutWindow *lw)
 {
        image_set_button_func(lw->image, layout_image_button_cb, lw);
@@ -1619,7 +1660,7 @@ void layout_image_deactivate(LayoutWindow *lw, gint i)
        if (!lw->split_images[i]) return;
        image_set_update_func(lw->split_images[i], NULL, NULL);
        layout_image_set_buttons_inactive(lw, i);
-       image_set_scroll_notify_func(lw->split_images[i], NULL, NULL);
+       image_set_drag_func(lw->image, layout_image_drag_inactive_cb, lw);
 
        image_attach_window(lw->split_images[i], NULL, NULL, NULL, FALSE);
        image_select(lw->split_images[i], FALSE);
@@ -1645,7 +1686,7 @@ void layout_image_activate(LayoutWindow *lw, gint i)
        
        image_set_update_func(lw->image, layout_image_update_cb, lw);
        layout_image_set_buttons(lw);
-       image_set_scroll_notify_func(lw->image, layout_image_scroll_notify_cb, lw);
+       image_set_drag_func(lw->image, layout_image_drag_cb, lw);
 
        image_attach_window(lw->image, lw->window, NULL, "GQview", FALSE);
 
index 99d947e..07269ea 100644 (file)
@@ -136,6 +136,7 @@ enum {
        SIGNAL_CLICKED,
        SIGNAL_SCROLL_NOTIFY,
        SIGNAL_RENDER_COMPLETE,
+       SIGNAL_DRAG,
        SIGNAL_COUNT
 };
 
@@ -420,6 +421,16 @@ static void pixbuf_renderer_class_init(PixbufRendererClass *class)
                             NULL, NULL,
                             g_cclosure_marshal_VOID__VOID,
                             G_TYPE_NONE, 0);
+
+       signals[SIGNAL_DRAG] = 
+               g_signal_new("drag",
+                            G_OBJECT_CLASS_TYPE(gobject_class),
+                            G_SIGNAL_RUN_LAST,
+                            G_STRUCT_OFFSET(PixbufRendererClass, drag),
+                            NULL, NULL,
+                            g_cclosure_marshal_VOID__BOXED,
+                            G_TYPE_NONE, 1,
+                            GDK_TYPE_EVENT);
 }
 
 static void pixbuf_renderer_init(PixbufRenderer *pr)
@@ -2487,6 +2498,11 @@ static void pr_render_complete_signal(PixbufRenderer *pr)
                }
 }
 
+static void pr_drag_signal(PixbufRenderer *pr, GdkEventButton *bevent)
+{
+       g_signal_emit(pr, signals[SIGNAL_DRAG], 0, bevent);
+}
+
 /*
  *-------------------------------------------------------------------
  * sync and clamp
@@ -3000,6 +3016,8 @@ static gint pr_mouse_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpoint
        pixbuf_renderer_scroll(pr, (pr->drag_last_x - bevent->x) * accel,
                               (pr->drag_last_y - bevent->y) * accel);
 
+       pr_drag_signal(pr, bevent);
+
        pr->drag_last_x = bevent->x;
        pr->drag_last_y = bevent->y;
 
index f71806d..bd6619b 100644 (file)
@@ -141,6 +141,7 @@ struct _PixbufRendererClass
        void (* scroll_notify)  (PixbufRenderer *pr);
 
        void (* render_complete)(PixbufRenderer *pr);
+       void (* drag)           (PixbufRenderer *pr, GdkEventButton *event);
 };
 
 
index b38a07f..a3cc11c 100644 (file)
@@ -279,10 +279,13 @@ struct _ImageWindow
        /* button, scroll functions */
        void (*func_button)(ImageWindow *, gint button,
                            guint32 time, gdouble x, gdouble y, guint state, gpointer);
+       void (*func_drag)(ImageWindow *, gint button,
+                           guint32 time, gdouble x, gdouble y, guint state, gdouble dx, gdouble dy,gpointer);
        void (*func_scroll)(ImageWindow *, GdkScrollDirection direction,
                            guint32 time, gdouble x, gdouble y, guint state, gpointer);
 
        gpointer data_button;
+       gpointer data_drag;
        gpointer data_scroll;
 
        /* scroll notification (for scroll bar implementation) */