X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finterface.cpp;h=17248a206bd81f3dfcc894b08ed9f764eef81d28;hb=a33ac0418e3968dbc79f5ba81cbb91d10b1ea7d5;hp=4a7c12f7688fae9b19e9db60134f92c53323ee24;hpb=f951374eef04129c6a0d213e7ab4d9ed2095ca69;p=inkscape.git diff --git a/src/interface.cpp b/src/interface.cpp index 4a7c12f76..17248a206 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -33,7 +33,7 @@ #include "file.h" #include "interface.h" #include "desktop.h" -#include "object-ui.h" +#include "ui/context-menu.h" #include "selection.h" #include "selection-chemistry.h" #include "svg-view-widget.h" @@ -53,6 +53,16 @@ #include "message-context.h" +// Added for color drag-n-drop +#if ENABLE_LCMS +#include "lcms.h" +#endif // ENABLE_LCMS +#include "display/sp-canvas.h" +#include "color.h" +#include "svg/svg-color.h" +#include "desktop-style.h" +#include "style.h" + using Inkscape::IO::StringOutputStream; using Inkscape::IO::Base64OutputStream; @@ -67,7 +77,9 @@ typedef enum { SVG_DATA, PNG_DATA, JPEG_DATA, - IMAGE_DATA + IMAGE_DATA, + APP_X_INKY_COLOR, + APP_X_COLOR } ui_drop_target_info; static GtkTargetEntry ui_drop_target_entries [] = { @@ -76,6 +88,10 @@ static GtkTargetEntry ui_drop_target_entries [] = { {"image/svg", 0, SVG_DATA}, {"image/png", 0, PNG_DATA}, {"image/jpeg", 0, JPEG_DATA}, +#if ENABLE_MAGIC_COLORS + {"application/x-inkscape-color", 0, APP_X_INKY_COLOR}, +#endif // ENABLE_MAGIC_COLORS + {"application/x-color", 0, APP_X_COLOR} }; static GtkTargetEntry *completeDropTargets = 0; @@ -96,24 +112,26 @@ static void sp_ui_drag_data_received(GtkWidget *widget, static void sp_ui_menu_item_set_sensitive(SPAction *action, unsigned int sensitive, void *data); +static void sp_ui_menu_item_set_name(SPAction *action, + Glib::ustring name, + void *data); SPActionEventVector menu_item_event_vector = { {NULL}, NULL, NULL, /* set_active */ sp_ui_menu_item_set_sensitive, /* set_sensitive */ - NULL /* set_shortcut */ + NULL, /* set_shortcut */ + sp_ui_menu_item_set_name /* set_name */ }; void sp_create_window(SPViewWidget *vw, gboolean editable) { - GtkWidget *w, *hb; - g_return_if_fail(vw != NULL); g_return_if_fail(SP_IS_VIEW_WIDGET(vw)); - w = sp_window_new("", TRUE); + GtkWidget *w = sp_window_new("", TRUE); if (editable) { g_object_set_data(G_OBJECT(vw), "window", w); @@ -121,13 +139,8 @@ sp_create_window(SPViewWidget *vw, gboolean editable) static_cast((void*)w); } - hb = gtk_hbox_new(FALSE, 0); - gtk_widget_show(hb); - gtk_container_add(GTK_CONTAINER(w), hb); - g_object_set_data(G_OBJECT(w), "hbox", hb); - - /* fixme: */ if (editable) { + /* fixme: */ gtk_window_set_default_size((GtkWindow *) w, 640, 480); g_object_set_data(G_OBJECT(w), "desktop", SP_DESKTOP_WIDGET(vw)->desktop); g_object_set_data(G_OBJECT(w), "desktopwidget", vw); @@ -137,10 +150,9 @@ sp_create_window(SPViewWidget *vw, gboolean editable) gtk_window_set_policy(GTK_WINDOW(w), TRUE, TRUE, TRUE); } - gtk_box_pack_end(GTK_BOX(hb), GTK_WIDGET(vw), TRUE, TRUE, 0); + gtk_container_add(GTK_CONTAINER(w), GTK_WIDGET(vw)); gtk_widget_show(GTK_WIDGET(vw)); - if ( completeDropTargets == 0 || completeDropTargetsCount == 0 ) { std::vector types; @@ -320,7 +332,7 @@ sp_ui_menuitem_add_icon( GtkWidget *item, gchar *icon_name ) { GtkWidget *icon; - icon = sp_icon_new( GTK_ICON_SIZE_MENU, icon_name ); + icon = sp_icon_new( Inkscape::ICON_SIZE_MENU, icon_name ); gtk_widget_show(icon); gtk_image_menu_item_set_image((GtkImageMenuItem *) item, icon); } // end of sp_ui_menu_add_icon @@ -755,7 +767,7 @@ sp_ui_checkboxes_menus(GtkMenu *m, Inkscape::UI::View::View *view) // checkitem_toggled, checkitem_update, 0); sp_ui_menu_append_check_item_from_verb(m, view, _("Commands Bar"), _("Show or hide the Commands bar (under the menu)"), "commands", checkitem_toggled, checkitem_update, 0); - sp_ui_menu_append_check_item_from_verb(m, view, _("Tool Controls"), _("Show or hide the Tool Controls panel"), "toppanel", + sp_ui_menu_append_check_item_from_verb(m, view, _("Tool Controls Bar"), _("Show or hide the Tool Controls bar"), "toppanel", checkitem_toggled, checkitem_update, 0); sp_ui_menu_append_check_item_from_verb(m, view, _("_Toolbox"), _("Show or hide the main toolbox (on the left)"), "toolbox", checkitem_toggled, checkitem_update, 0); @@ -763,9 +775,9 @@ sp_ui_checkboxes_menus(GtkMenu *m, Inkscape::UI::View::View *view) checkitem_toggled, checkitem_update, Inkscape::Verb::get(SP_VERB_TOGGLE_RULERS)); sp_ui_menu_append_check_item_from_verb(m, view, NULL, NULL, "scrollbars", checkitem_toggled, checkitem_update, Inkscape::Verb::get(SP_VERB_TOGGLE_SCROLLBARS)); - sp_ui_menu_append_check_item_from_verb(m, view, _("_Statusbar"), _("Show or hide the statusbar (at the bottom of the window)"), "statusbar", + sp_ui_menu_append_check_item_from_verb(m, view, _("_Palette"), _("Show or hide the color palette"), "panels", checkitem_toggled, checkitem_update, 0); - sp_ui_menu_append_check_item_from_verb(m, view, _("_Panels"), _("Show or hide the panels"), "panels", + sp_ui_menu_append_check_item_from_verb(m, view, _("_Statusbar"), _("Show or hide the statusbar (at the bottom of the window)"), "statusbar", checkitem_toggled, checkitem_update, 0); } @@ -795,9 +807,6 @@ sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, Inkscape::UI: menu_pntr != NULL; menu_pntr = menu_pntr->next()) { if (!strcmp(menu_pntr->name(), "submenu")) { - if (!strcmp(menu_pntr->attribute("name"), "Effects") && !prefs_get_int_attribute("extensions", "show-effects-menu", 0)) { - continue; - } GtkWidget *mitem = gtk_menu_item_new_with_mnemonic(_(menu_pntr->attribute("name"))); GtkWidget *submenu = gtk_menu_new(); sp_ui_build_dyn_menus(menu_pntr->firstChild(), submenu, view); @@ -879,7 +888,7 @@ static void leave_group(GtkMenuItem *, SPDesktop *desktop) { static void enter_group(GtkMenuItem *mi, SPDesktop *desktop) { desktop->setCurrentLayer(reinterpret_cast(g_object_get_data(G_OBJECT(mi), "group"))); - SP_DT_SELECTION(desktop)->clear(); + sp_desktop_selection(desktop)->clear(); } GtkWidget * @@ -965,6 +974,120 @@ sp_ui_drag_data_received(GtkWidget *widget, gpointer user_data) { switch (info) { +#if ENABLE_MAGIC_COLORS + case APP_X_INKY_COLOR: + { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + int destX = 0; + 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 ) ) ); + + SPItem *item = desktop->item_at_point( where, true ); + if ( item ) + { + if ( data->length >= 8 ) { + cmsHPROFILE srgbProf = cmsCreate_sRGBProfile(); + + 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(); + bool updatePerformed = false; + + if ( data->length > 14 ) { + int flags = dataVals[4]; + + // piggie-backed palette entry info + int index = dataVals[5]; + Glib::ustring palName; + for ( int i = 0; i < dataVals[6]; i++ ) { + palName += (gunichar)dataVals[7+i]; + } + + // Now hook in a magic tag of some sort. + if ( !palName.empty() && (flags & 1) ) { + gchar* str = g_strdup_printf("%d|", index); + palName.insert( 0, str ); + g_free(str); + str = 0; + + sp_object_setAttribute( SP_OBJECT(item), + (drag_context->action != GDK_ACTION_MOVE) ? "inkscape:x-fill-tag":"inkscape:x-stroke-tag", + palName.c_str(), + false ); + item->updateRepr(); + + sp_repr_css_set_property( css, (drag_context->action != GDK_ACTION_MOVE) ? "fill":"stroke", c ); + updatePerformed = true; + } + } + + if ( !updatePerformed ) { + sp_repr_css_set_property( css, (drag_context->action != GDK_ACTION_MOVE) ? "fill":"stroke", c ); + } + + sp_desktop_apply_css_recursive( item, css, true ); + item->updateRepr(); + + SPDocument *doc = SP_ACTIVE_DOCUMENT; + sp_document_done( doc , SP_VERB_NONE, + _("Drop color")); + + if ( srgbProf ) { + cmsCloseProfile( srgbProf ); + } + } + } + } + break; +#endif // ENABLE_MAGIC_COLORS + + case APP_X_COLOR: + { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + int destX = 0; + 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 ) ) ); + + SPItem *item = desktop->item_at_point( where, true ); + if ( item ) + { + 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, (drag_context->action != GDK_ACTION_MOVE) ? "fill":"stroke", c ); + + sp_desktop_apply_css_recursive( item, css, true ); + item->updateRepr(); + + SPDocument *doc = SP_ACTIVE_DOCUMENT; + sp_document_done( doc , SP_VERB_NONE, + _("Drop color")); + } + } + } + break; + case SVG_DATA: case SVG_XML_DATA: { gchar *svgdata = (gchar *)data->data; @@ -998,21 +1121,22 @@ sp_ui_drag_data_received(GtkWidget *widget, SPObject *new_obj = NULL; new_obj = desktop->currentLayer()->appendChildRepr(newgroup); - Inkscape::Selection *selection = SP_DT_SELECTION(desktop); + Inkscape::Selection *selection = sp_desktop_selection(desktop); selection->set(SP_ITEM(new_obj)); // To move the imported object, we must temporarily set the "transform pattern with // object" option. { int const saved_pref = prefs_get_int_attribute("options.transform", "pattern", 1); prefs_set_int_attribute("options.transform", "pattern", 1); - sp_document_ensure_up_to_date(SP_DT_DOCUMENT(desktop)); + sp_document_ensure_up_to_date(sp_desktop_document(desktop)); NR::Point m( desktop->point() - selection->bounds().midpoint() ); sp_selection_move_relative(selection, m); prefs_set_int_attribute("options.transform", "pattern", saved_pref); } Inkscape::GC::release(newgroup); - sp_document_done(doc); + sp_document_done(doc, SP_VERB_NONE, + _("Drop SVG")); break; } @@ -1071,7 +1195,8 @@ sp_ui_drag_data_received(GtkWidget *widget, desktop->currentLayer()->appendChildRepr(newImage); Inkscape::GC::release(newImage); - sp_document_done( doc ); + sp_document_done( doc , SP_VERB_NONE, + _("Drop bitmap image")); break; } } @@ -1152,7 +1277,10 @@ sp_ui_overwrite_file(gchar const *filename) gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); hbox = gtk_hbox_new(FALSE, 5); + + // TODO - replace with Inkscape-specific call boxdata = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_widget_show(boxdata); gtk_box_pack_start(GTK_BOX(hbox), boxdata, TRUE, TRUE, 5); text = g_strdup_printf(_("The file %s already exists. Do you want to overwrite that file with the current document?"), filename); @@ -1185,6 +1313,15 @@ sp_ui_menu_item_set_sensitive(SPAction *action, unsigned int sensitive, void *da return gtk_widget_set_sensitive(GTK_WIDGET(data), sensitive); } +static void +sp_ui_menu_item_set_name(SPAction *action, Glib::ustring name, void *data) +{ + gtk_label_set_markup_with_mnemonic( + GTK_LABEL (gtk_container_get_children(GTK_CONTAINER (GTK_BIN (data)->child))->data), + name.c_str()); +} + + /* Local Variables: mode:c++