Code

compile depending on WITH_LIBWPG
[inkscape.git] / src / interface.cpp
index 88031032a255bebd0f1194b1a45a4c73ca7a5af8..f7a2bc47fd799b4ff903dcf6c389c5cd5101df74 100644 (file)
@@ -65,6 +65,8 @@
 #include "svg/svg-color.h"
 #include "desktop-style.h"
 #include "style.h"
+#include "event-context.h"
+#include "gradient-drag.h"
 
 using Inkscape::IO::StringOutputStream;
 using Inkscape::IO::Base64OutputStream;
@@ -108,6 +110,17 @@ static void sp_ui_drag_data_received(GtkWidget *widget,
                                      guint info,
                                      guint event_time,
                                      gpointer user_data);
+static void sp_ui_drag_motion( GtkWidget *widget,
+                               GdkDragContext *drag_context,
+                               gint x, gint y,
+                               GtkSelectionData *data,
+                               guint info,
+                               guint event_time,
+                               gpointer user_data );
+static void sp_ui_drag_leave( GtkWidget *widget,
+                              GdkDragContext *drag_context,
+                              guint event_time,
+                              gpointer user_data );
 static void sp_ui_menu_item_set_sensitive(SPAction *action,
                                           unsigned int sensitive,
                                           void *data);
@@ -238,10 +251,20 @@ sp_create_window(SPViewWidget *vw, gboolean editable)
                       completeDropTargets,
                       completeDropTargetsCount,
                       GdkDragAction(GDK_ACTION_COPY | GDK_ACTION_MOVE));
+
+
     g_signal_connect(G_OBJECT(win->gobj()),
                      "drag_data_received",
                      G_CALLBACK(sp_ui_drag_data_received),
                      NULL);
+    g_signal_connect(G_OBJECT(win->gobj()),
+                     "drag_motion",
+                     G_CALLBACK(sp_ui_drag_motion),
+                     NULL);
+    g_signal_connect(G_OBJECT(win->gobj()),
+                     "drag_leave",
+                     G_CALLBACK(sp_ui_drag_leave),
+                     NULL);
     win->show();
 
     // needed because the first ACTIVATE_DESKTOP was sent when there was no window yet
@@ -287,7 +310,7 @@ sp_ui_new_view_preview()
  * \param widget unused
  */
 void
-sp_ui_close_view(GtkWidget *widget)
+sp_ui_close_view(GtkWidget */*widget*/)
 {
     if (SP_ACTIVE_DESKTOP == NULL) {
         return;
@@ -334,19 +357,19 @@ sp_ui_close_all(void)
  * investigate when they're called.
  */
 static void
-sp_ui_menu_activate(void *object, SPAction *action)
+sp_ui_menu_activate(void */*object*/, SPAction *action)
 {
     sp_action_perform(action, NULL);
 }
 
 static void
-sp_ui_menu_select_action(void *object, SPAction *action)
+sp_ui_menu_select_action(void */*object*/, SPAction *action)
 {
     action->view->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, action->tip);
 }
 
 static void
-sp_ui_menu_deselect_action(void *object, SPAction *action)
+sp_ui_menu_deselect_action(void */*object*/, SPAction *action)
 {
     action->view->tipsMessageContext()->clear();
 }
@@ -444,9 +467,10 @@ sp_key_name(guint keyval)
     else if (!strcmp(n, "Page_Down"  ))  return "PgDn";
     else if (!strcmp(n, "grave"      ))  return "`";
     else if (!strcmp(n, "numbersign" ))  return "#";
-    else if (!strcmp(n, "bar" ))  return "|";
-    else if (!strcmp(n, "slash" ))  return "/";
-    else if (!strcmp(n, "exclam" ))  return "!";
+    else if (!strcmp(n, "bar"        ))  return "|";
+    else if (!strcmp(n, "slash"      ))  return "/";
+    else if (!strcmp(n, "exclam"     ))  return "!";
+    else if (!strcmp(n, "percent"    ))  return "%";
     else return n;
 }
 
@@ -620,7 +644,7 @@ checkitem_toggled(GtkCheckMenuItem *menuitem, gpointer user_data)
 }
 
 static gboolean
-checkitem_update(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
+checkitem_update(GtkWidget *widget, GdkEventExpose */*event*/, gpointer user_data)
 {
     GtkCheckMenuItem *menuitem=GTK_CHECK_MENU_ITEM(widget);
 
@@ -707,13 +731,13 @@ sp_ui_menu_append_check_item_from_verb(GtkMenu *menu, Inkscape::UI::View::View *
 }
 
 static void
-sp_recent_open(GtkWidget *widget, gchar const *uri)
+sp_recent_open(GtkWidget */*widget*/, gchar const *uri)
 {
     sp_file_open(uri, NULL);
 }
 
 static void
-sp_file_new_from_template(GtkWidget *widget, gchar const *uri)
+sp_file_new_from_template(GtkWidget */*widget*/, gchar const *uri)
 {
     sp_file_new(uri);
 }
@@ -1015,8 +1039,8 @@ sp_ui_drag_data_received(GtkWidget *widget,
                          gint x, gint y,
                          GtkSelectionData *data,
                          guint info,
-                         guint event_time,
-                         gpointer user_data)
+                         guint /*event_time*/,
+                         gpointer /*user_data*/)
 {
     SPDocument *doc = SP_ACTIVE_DOCUMENT;
     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
@@ -1105,48 +1129,67 @@ sp_ui_drag_data_received(GtkWidget *widget,
             int destY = 0;
             gtk_widget_translate_coordinates( widget, &(desktop->canvas->widget), x, y, &destX, &destY );
             NR::Point where( sp_canvas_window_to_world( desktop->canvas, NR::Point( destX, destY ) ) );
-            NR::Point const button_dt(desktop->dt2doc(desktop->w2d(where)));
+            NR::Point const button_dt(desktop->w2d(where));
+            NR::Point const button_doc(desktop->dt2doc(button_dt));
+
+            if ( data->length == 8 ) {
+                gchar c[64] = {0};
+                // Careful about endian issues.
+                guint16* dataVals = (guint16*)data->data;
+                sp_svg_write_color( c, 64,
+                                    SP_RGBA32_U_COMPOSE(
+                                        0x0ff & (dataVals[0] >> 8),
+                                        0x0ff & (dataVals[1] >> 8),
+                                        0x0ff & (dataVals[2] >> 8),
+                                        0xff // can't have transparency in the color itself
+                                        //0x0ff & (data->data[3] >> 8),
+                                        ));
+
+                SPItem *item = desktop->item_at_point( where, true );
+
+                bool consumed = false;
+                if (desktop->event_context && desktop->event_context->get_drag()) {
+                    consumed = desktop->event_context->get_drag()->dropColor(item, c, button_dt);
+                    if (consumed) {
+                        sp_document_done( doc , SP_VERB_NONE, _("Drop color on gradient"));
+                        desktop->event_context->get_drag()->updateDraggers();
+                    }
+                }
 
-            SPItem *item = desktop->item_at_point( where, true );
-            if ( item )
-            {
-                bool fillnotstroke = (drag_context->action != GDK_ACTION_MOVE);
-                if (SP_IS_SHAPE(item) || SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) {
-                    Path *livarot_path = Path_for_item(item, true, true);
-                    livarot_path->ConvertWithBackData(0.04);
-
-                    NR::Maybe<Path::cut_position> position = get_nearest_position_on_Path(livarot_path, button_dt);
-                    if (position) {
-                        NR::Point nearest = get_point_on_Path(livarot_path, position->piece, position->t);
-                        NR::Point delta = nearest - button_dt;
-                        delta = desktop->d2w(delta);
-                        double stroke_tolerance =
-                            ( !SP_OBJECT_STYLE(item)->stroke.isNone() ?
-                              desktop->current_zoom() *
-                              SP_OBJECT_STYLE (item)->stroke_width.computed *
-                              sp_item_i2d_affine (item).expansion() * 0.5
-                              : 0.0)
-                            + prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100); 
-
-                        if (NR::L2 (delta) < stroke_tolerance) {
-                            fillnotstroke = false;
+                //if (!consumed && tools_active(desktop, TOOLS_TEXT)) {
+                //    consumed = sp_text_context_drop_color(c, button_doc);
+                //    if (consumed) {
+                //        sp_document_done( doc , SP_VERB_NONE, _("Drop color on gradient stop"));
+                //    }
+                //}
+
+                if (!consumed && item) {
+                    bool fillnotstroke = (drag_context->action != GDK_ACTION_MOVE);
+                    if (fillnotstroke && 
+                        (SP_IS_SHAPE(item) || SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item))) {
+                        Path *livarot_path = Path_for_item(item, true, true);
+                        livarot_path->ConvertWithBackData(0.04);
+
+                        NR::Maybe<Path::cut_position> position = get_nearest_position_on_Path(livarot_path, button_doc);
+                        if (position) {
+                            NR::Point nearest = get_point_on_Path(livarot_path, position->piece, position->t);
+                            NR::Point delta = nearest - button_doc;
+                            delta = desktop->d2w(delta);
+                            double stroke_tolerance =
+                                ( !SP_OBJECT_STYLE(item)->stroke.isNone() ?
+                                  desktop->current_zoom() *
+                                  SP_OBJECT_STYLE (item)->stroke_width.computed *
+                                  sp_item_i2d_affine (item).expansion() * 0.5
+                                  : 0.0)
+                                + prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100); 
+
+                            if (NR::L2 (delta) < stroke_tolerance) {
+                                fillnotstroke = false;
+                            }
                         }
+                        delete livarot_path;
                     }
-                    delete livarot_path;
-                }
 
-                if ( data->length == 8 ) {
-                    gchar c[64] = {0};
-                    // Careful about endian issues.
-                    guint16* dataVals = (guint16*)data->data;
-                    sp_svg_write_color( c, 64,
-                                        SP_RGBA32_U_COMPOSE(
-                                            0x0ff & (dataVals[0] >> 8),
-                                            0x0ff & (dataVals[1] >> 8),
-                                            0x0ff & (dataVals[2] >> 8),
-                                            0xff // can't have transparency in the color itself
-                                            //0x0ff & (data->data[3] >> 8),
-                                            ));
                     SPCSSAttr *css = sp_repr_css_attr_new();
                     sp_repr_css_set_property( css, fillnotstroke ? "fill":"stroke", c );
 
@@ -1273,6 +1316,31 @@ sp_ui_drag_data_received(GtkWidget *widget,
     }
 }
 
+#include "gradient-context.h"
+
+void sp_ui_drag_motion( GtkWidget */*widget*/,
+                        GdkDragContext */*drag_context*/,
+                        gint /*x*/, gint /*y*/,
+                        GtkSelectionData */*data*/,
+                        guint /*info*/,
+                        guint /*event_time*/,
+                        gpointer /*user_data*/)
+{
+//     SPDocument *doc = SP_ACTIVE_DOCUMENT;
+//     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+
+
+//     g_message("drag-n-drop motion (%4d, %4d)  at %d", x, y, event_time);
+}
+
+static void sp_ui_drag_leave( GtkWidget */*widget*/,
+                              GdkDragContext */*drag_context*/,
+                              guint /*event_time*/,
+                              gpointer /*user_data*/ )
+{
+//     g_message("drag-n-drop leave                at %d", event_time);
+}
+
 static void
 sp_ui_import_files(gchar *buffer)
 {
@@ -1285,7 +1353,7 @@ sp_ui_import_files(gchar *buffer)
 }
 
 static void
-sp_ui_import_one_file_with_check(gpointer filename, gpointer unused)
+sp_ui_import_one_file_with_check(gpointer filename, gpointer /*unused*/)
 {
     if (filename) {
         if (strlen((char const *)filename) > 2)
@@ -1361,13 +1429,13 @@ sp_ui_overwrite_file(gchar const *filename)
 }
 
 static void
-sp_ui_menu_item_set_sensitive(SPAction *action, unsigned int sensitive, void *data)
+sp_ui_menu_item_set_sensitive(SPAction */*action*/, unsigned int sensitive, void *data)
 {
     return gtk_widget_set_sensitive(GTK_WIDGET(data), sensitive);
 }
 
 static void
-sp_ui_menu_item_set_name(SPAction *action, Glib::ustring name, void *data)
+sp_ui_menu_item_set_name(SPAction */*action*/, Glib::ustring name, void *data)
 {
     void *child = GTK_BIN (data)->child;
     //child is either