index c808289b21b6133f6f494cd555b988990f07d7ba..066d721752d2f5ccc82957642fe75a88521b6a5b 100644 (file)
# include <config.h>
#endif
+#include <gtk/gtkdnd.h>
#include "selected-style.h"
#include "document.h"
#include "widgets/widget-sizes.h"
#include "widgets/spinbutton-events.h"
-#include "svg/svg.h"
+#include "svg/svg-color.h"
#include "svg/css-ostringstream.h"
#include "helper/units.h"
namespace UI {
namespace Widget {
+
+typedef struct {
+ SelectedStyle* parent;
+ int item;
+} DropTracker;
+
+/* Drag and Drop */
+typedef enum {
+ APP_X_COLOR
+} ui_drop_target_info;
+
+static GtkTargetEntry ui_drop_target_entries [] = {
+ {"application/x-color", 0, APP_X_COLOR}
+};
+
+#define ENTRIES_SIZE(n) sizeof(n)/sizeof(n[0])
+static guint nui_drop_target_entries = ENTRIES_SIZE(ui_drop_target_entries);
+
+
SelectedStyle::SelectedStyle(bool layout)
: _desktop (NULL),
_sw_unit(NULL),
- _tooltips ()
+ _tooltips (),
+
+ _drop((void*[]){0,0}),
+ _dropEnabled((bool[]){false, false})
{
_fill_label.set_alignment(0.0, 0.5);
_fill_label.set_padding(0, 0);
sp_set_font_size_smaller (GTK_WIDGET(_stroke_width.gobj()));
sp_set_font_size_smaller (GTK_WIDGET(_fill_label.gobj()));
sp_set_font_size_smaller (GTK_WIDGET(_stroke_label.gobj()));
+
+ _drop[SS_FILL] = new DropTracker();
+ ((DropTracker*)_drop[SS_FILL])->parent = this;
+ ((DropTracker*)_drop[SS_FILL])->item = SS_FILL;
+
+ _drop[SS_STROKE] = new DropTracker();
+ ((DropTracker*)_drop[SS_STROKE])->parent = this;
+ ((DropTracker*)_drop[SS_STROKE])->item = SS_STROKE;
+
+ g_signal_connect(_stroke_place.gobj(),
+ "drag_data_received",
+ G_CALLBACK(dragDataReceived),
+ _drop[SS_STROKE]);
+
+ g_signal_connect(_fill_place.gobj(),
+ "drag_data_received",
+ G_CALLBACK(dragDataReceived),
+ _drop[SS_FILL]);
}
SelectedStyle::~SelectedStyle()
for (int i = SS_FILL; i <= SS_STROKE; i++) {
delete _color_preview[i];
}
+
+ delete (DropTracker*)_drop[SS_FILL];
+ delete (DropTracker*)_drop[SS_STROKE];
}
void
//_sw_unit = (SPUnit *) SP_DT_NAMEDVIEW(desktop)->doc_units;
}
+void SelectedStyle::dragDataReceived( GtkWidget *widget,
+ GdkDragContext *drag_context,
+ gint x, gint y,
+ GtkSelectionData *data,
+ guint info,
+ guint event_time,
+ gpointer user_data )
+{
+ DropTracker* tracker = (DropTracker*)user_data;
+
+ switch ( (int)tracker->item ) {
+ case SS_FILL:
+ case SS_STROKE:
+ {
+ if ( data->length == 8 ) {
+ gchar c[64];
+ // 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, (tracker->item == SS_FILL) ? "fill":"stroke", c );
+ sp_desktop_set_style( tracker->parent->_desktop, css );
+ sp_repr_css_attr_unref( css );
+ sp_document_done( SP_DT_DOCUMENT(tracker->parent->_desktop) );
+ }
+ }
+ break;
+ }
+}
+
void SelectedStyle::on_fill_remove() {
SPCSSAttr *css = sp_repr_css_attr_new ();
sp_repr_css_set_property (css, "fill", "none");
void SelectedStyle::on_fillstroke_swap() {
SPCSSAttr *css = sp_repr_css_attr_new ();
+ g_message("on_fillstroke_swap()");
+
switch (_mode[SS_FILL]) {
case SS_NA:
case SS_MANY:
place->add(_na[i]);
_tooltips.set_tip(*place, __na[i]);
_mode[i] = SS_NA;
+ if ( _dropEnabled[i] ) {
+ gtk_drag_dest_unset( GTK_WIDGET((i==SS_FILL) ? _fill_place.gobj():_stroke_place.gobj()) );
+ _dropEnabled[i] = false;
+ }
break;
case QUERY_STYLE_SINGLE:
case QUERY_STYLE_MULTIPLE_AVERAGED:
case QUERY_STYLE_MULTIPLE_SAME:
+ if ( !_dropEnabled[i] ) {
+ gtk_drag_dest_set( GTK_WIDGET( (i==SS_FILL) ? _fill_place.gobj():_stroke_place.gobj()),
+ GTK_DEST_DEFAULT_ALL,
+ ui_drop_target_entries,
+ nui_drop_target_entries,
+ GdkDragAction(GDK_ACTION_COPY | GDK_ACTION_MOVE) );
+ _dropEnabled[i] = true;
+ }
SPIPaint *paint;
if (i == SS_FILL) {
paint = &(query->fill);