void gimp_image_map_tool_edit_as (GimpImageMapTool *im_tool, const gchar *new_tool_id, GimpConfig *config) { GimpDisplay *display; GimpContext *user_context; GimpToolInfo *tool_info; GimpTool *new_tool; g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (im_tool)); g_return_if_fail (new_tool_id); g_return_if_fail (GIMP_IS_CONFIG (config)); display = GIMP_TOOL (im_tool)->display; user_context = gimp_get_user_context (display->gimp); tool_info = (GimpToolInfo *) gimp_container_get_child_by_name (display->gimp->tool_info_list, new_tool_id); gimp_context_set_tool (user_context, tool_info); tool_manager_initialize_active (display->gimp, display); new_tool = tool_manager_get_active (display->gimp); GIMP_IMAGE_MAP_TOOL (new_tool)->default_config = g_object_ref (config); gimp_image_map_tool_reset (GIMP_IMAGE_MAP_TOOL (new_tool)); }
void vectors_edit_cmd_callback (GtkAction *action, gpointer data) { GimpImage *image; GimpVectors *vectors; GimpTool *active_tool; return_if_no_vectors (image, vectors, data); active_tool = tool_manager_get_active (image->gimp); if (! GIMP_IS_VECTOR_TOOL (active_tool)) { GimpToolInfo *tool_info = gimp_get_tool_info (image->gimp, "gimp-vector-tool"); if (GIMP_IS_TOOL_INFO (tool_info)) { gimp_context_set_tool (action_data_get_context (data), tool_info); active_tool = tool_manager_get_active (image->gimp); } } if (GIMP_IS_VECTOR_TOOL (active_tool)) gimp_vector_tool_set_vectors (GIMP_VECTOR_TOOL (active_tool), vectors); }
static void tool_manager_preset_changed (GimpContext *user_context, GimpToolPreset *preset, GimpToolManager *tool_manager) { GimpToolInfo *preset_tool; gboolean tool_change = FALSE; if (! preset || user_context->gimp->busy) return; preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options)); if (preset_tool != gimp_context_get_tool (user_context)) tool_change = TRUE; if (! tool_change) tool_manager_disconnect_options (user_context, preset_tool); gimp_config_copy (GIMP_CONFIG (preset->tool_options), GIMP_CONFIG (preset_tool->tool_options), 0); if (tool_change) gimp_context_set_tool (user_context, preset_tool); else tool_manager_connect_options (user_context, preset_tool); gimp_context_copy_properties (GIMP_CONTEXT (preset->tool_options), user_context, gimp_tool_preset_get_prop_mask (preset)); }
void layers_text_tool_cmd_callback (GtkAction *action, gpointer data) { GimpImage *image; GimpLayer *layer; GtkWidget *widget; GimpTool *active_tool; return_if_no_layer (image, layer, data); return_if_no_widget (widget, data); if (! gimp_item_is_text_layer (GIMP_ITEM (layer))) { layers_edit_attributes_cmd_callback (action, data); return; } active_tool = tool_manager_get_active (image->gimp); if (! GIMP_IS_TEXT_TOOL (active_tool)) { GimpToolInfo *tool_info = gimp_get_tool_info (image->gimp, "gimp-text-tool"); if (GIMP_IS_TOOL_INFO (tool_info)) { gimp_context_set_tool (action_data_get_context (data), tool_info); active_tool = tool_manager_get_active (image->gimp); } } if (GIMP_IS_TEXT_TOOL (active_tool)) gimp_text_tool_set_layer (GIMP_TEXT_TOOL (active_tool), layer); }
static void gui_initialize_after_callback (Gimp *gimp, GimpInitStatusFunc status_callback) { const gchar *name = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); if (gimp->be_verbose) g_print ("INIT: %s\n", G_STRFUNC); #if defined (GDK_WINDOWING_X11) name = "DISPLAY"; #elif defined (GDK_WINDOWING_DIRECTFB) || defined (GDK_WINDOWING_FB) name = "GDK_DISPLAY"; #endif /* TODO: Need to care about display migration with GTK+ 2.2 at some point */ if (name) { gchar *display = gdk_get_display (); gimp_environ_table_add (gimp->plug_in_manager->environ_table, name, display, NULL); g_free (display); } gimp_tools_init (gimp); gimp_context_set_tool (gimp_get_user_context (gimp), gimp_tool_info_get_standard (gimp)); }
static void tool_manager_preset_changed (GimpContext *user_context, GimpToolPreset *preset, GimpToolManager *tool_manager) { GimpToolInfo *preset_tool; gchar *options_name; gboolean tool_change = FALSE; if (! preset || user_context->gimp->busy) return; preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options)); if (preset_tool != gimp_context_get_tool (user_context)) tool_change = TRUE; /* save the name, we don't want to overwrite it */ options_name = g_strdup (gimp_object_get_name (preset_tool->tool_options)); gimp_config_copy (GIMP_CONFIG (preset->tool_options), GIMP_CONFIG (preset_tool->tool_options), 0); /* restore the saved name */ gimp_object_take_name (GIMP_OBJECT (preset_tool->tool_options), options_name); if (tool_change) gimp_context_set_tool (user_context, preset_tool); gimp_context_copy_properties (GIMP_CONTEXT (preset->tool_options), user_context, gimp_tool_preset_get_prop_mask (preset)); if (GIMP_IS_PAINT_OPTIONS (preset->tool_options)) { GimpToolOptions *src; GimpToolOptions *dest; GimpContextPropMask prop_mask = 0; src = preset->tool_options; dest = tool_manager->active_tool->tool_info->tool_options; /* copy various data objects' additional tool options again * manually, they might have been overwritten by e.g. the "link * brush stuff to brush defaults" logic in gimptooloptions.c */ if (preset->use_brush) prop_mask |= GIMP_CONTEXT_PROP_MASK_BRUSH; if (preset->use_dynamics) prop_mask |= GIMP_CONTEXT_PROP_MASK_DYNAMICS; if (preset->use_gradient) prop_mask |= GIMP_CONTEXT_PROP_MASK_GRADIENT; gimp_paint_options_copy_props (GIMP_PAINT_OPTIONS (src), GIMP_PAINT_OPTIONS (dest), prop_mask); } }
static void gimp_toolbox_drop_tool (GtkWidget *widget, gint x, gint y, GimpViewable *viewable, gpointer data) { GimpContext *context = GIMP_CONTEXT (data); if (context->gimp->busy) return; gimp_context_set_tool (context, GIMP_TOOL_INFO (viewable)); }
void tools_select_cmd_callback (GtkAction *action, const gchar *value, gpointer data) { Gimp *gimp; GimpToolInfo *tool_info; GimpContext *context; GimpDisplay *display; gboolean rotate_layer = FALSE; return_if_no_gimp (gimp, data); /* special case gimp-rotate-tool being called from the Layer menu */ if (strcmp (value, "gimp-rotate-layer") == 0) { rotate_layer = TRUE; value = "gimp-rotate-tool"; } tool_info = gimp_get_tool_info (gimp, value); context = gimp_get_user_context (gimp); /* always allocate a new tool when selected from the image menu */ if (gimp_context_get_tool (context) != tool_info) { gimp_context_set_tool (context, tool_info); if (rotate_layer) g_object_set (tool_info->tool_options, "type", GIMP_TRANSFORM_TYPE_LAYER, NULL); } else { gimp_context_tool_changed (context); } display = gimp_context_get_display (context); if (display && gimp_display_get_image (display)) tool_manager_initialize_active (gimp, display); }
void gimp_device_info_set_default_tool (GimpDeviceInfo *info) { g_return_if_fail (GIMP_IS_DEVICE_INFO (info)); if (info->device && gdk_device_get_source (info->device) == GDK_SOURCE_ERASER) { GimpContainer *tools = GIMP_CONTEXT (info)->gimp->tool_info_list; GimpToolInfo *eraser; eraser = GIMP_TOOL_INFO (gimp_container_get_child_by_name (tools, "gimp-eraser-tool")); if (eraser) gimp_context_set_tool (GIMP_CONTEXT (info), eraser); } }
void gimp_tools_restore (Gimp *gimp) { GimpContainer *gimp_list; GimpObject *object; GFile *file; GList *list; GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); gimp_list = gimp_list_new (GIMP_TYPE_TOOL_INFO, FALSE); file = gimp_directory_file ("toolrc", NULL); if (gimp->be_verbose) g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file)); if (gimp_config_deserialize_gfile (GIMP_CONFIG (gimp_list), file, NULL, NULL)) { gint n = gimp_container_get_n_children (gimp->tool_info_list); gint i; gimp_list_reverse (GIMP_LIST (gimp_list)); for (list = GIMP_LIST (gimp_list)->list, i = 0; list; list = g_list_next (list), i++) { const gchar *name; name = gimp_object_get_name (list->data); object = gimp_container_get_child_by_name (gimp->tool_info_list, name); if (object) { g_object_set (object, "visible", GIMP_TOOL_INFO (list->data)->visible, NULL); gimp_container_reorder (gimp->tool_info_list, object, MIN (i, n - 1)); } } } g_object_unref (file); g_object_unref (gimp_list); /* make the generic operation tool invisible by default */ object = gimp_container_get_child_by_name (gimp->tool_info_list, "gimp-operation-tool"); if (object) g_object_set (object, "visible", FALSE, NULL); for (list = gimp_get_tool_info_iter (gimp); list; list = g_list_next (list)) { GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data); /* get default values from prefs (see bug #120832) */ gimp_config_reset (GIMP_CONFIG (tool_info->tool_options)); } if (! gimp_contexts_load (gimp, &error)) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_WARNING, error->message); g_clear_error (&error); } /* make sure there is always a tool active, so broken config files * can't leave us with no initial tool */ if (! gimp_context_get_tool (gimp_get_user_context (gimp))) { gimp_context_set_tool (gimp_get_user_context (gimp), gimp_get_tool_info_iter (gimp)->data); } for (list = gimp_get_tool_info_iter (gimp); list; list = g_list_next (list)) { GimpToolInfo *tool_info = GIMP_TOOL_INFO (list->data); GimpToolOptionsGUIFunc options_gui_func; GtkWidget *options_gui; /* copy all context properties except those the tool actually * uses, because the subsequent deserialize() on the tool * options will only set the properties that were set to * non-default values at the time of saving, and we want to * keep these default values as if they have been saved. * (see bug #541586). */ gimp_context_copy_properties (gimp_get_user_context (gimp), GIMP_CONTEXT (tool_info->tool_options), GIMP_CONTEXT_PROP_MASK_ALL &~ (tool_info->context_props | GIMP_CONTEXT_PROP_MASK_TOOL | GIMP_CONTEXT_PROP_MASK_PAINT_INFO)); gimp_tool_options_deserialize (tool_info->tool_options, NULL); options_gui_func = g_object_get_data (G_OBJECT (tool_info), "gimp-tool-options-gui-func"); if (options_gui_func) { options_gui = (* options_gui_func) (tool_info->tool_options); } else { GtkWidget *label; options_gui = gimp_tool_options_gui (tool_info->tool_options); label = gtk_label_new (_("This tool has\nno options.")); gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER); gimp_label_set_attributes (GTK_LABEL (label), PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC, -1); gtk_box_pack_start (GTK_BOX (options_gui), label, FALSE, FALSE, 6); gtk_widget_show (label); } gimp_tools_set_tool_options_gui (tool_info->tool_options, g_object_ref_sink (options_gui)); } }
static void tool_manager_tool_changed (GimpContext *user_context, GimpToolInfo *tool_info, GimpToolManager *tool_manager) { GimpTool *new_tool = NULL; if (! tool_info) return; /* FIXME: gimp_busy HACK */ if (user_context->gimp->busy) { /* there may be contexts waiting for the user_context's "tool-changed" * signal, so stop emitting it. */ g_signal_stop_emission_by_name (user_context, "tool-changed"); if (G_TYPE_FROM_INSTANCE (tool_manager->active_tool) != tool_info->tool_type) { g_signal_handlers_block_by_func (user_context, tool_manager_tool_changed, tool_manager); /* explicitly set the current tool */ gimp_context_set_tool (user_context, tool_manager->active_tool->tool_info); g_signal_handlers_unblock_by_func (user_context, tool_manager_tool_changed, tool_manager); } return; } if (g_type_is_a (tool_info->tool_type, GIMP_TYPE_TOOL)) { new_tool = g_object_new (tool_info->tool_type, "tool-info", tool_info, NULL); } else { g_warning ("%s: tool_info->tool_type is no GimpTool subclass", G_STRFUNC); return; } /* disconnect the old tool's context */ if (tool_manager->active_tool && tool_manager->active_tool->tool_info) { tool_manager_disconnect_options (user_context, tool_manager->active_tool->tool_info); } /* connect the new tool's context */ tool_manager_connect_options (user_context, tool_info); tool_manager_select_tool (user_context->gimp, new_tool); g_object_unref (new_tool); }
static void tool_manager_preset_changed (GimpContext *user_context, GimpToolPreset *preset, GimpToolManager *tool_manager) { GimpToolInfo *preset_tool; gchar *options_name; gboolean tool_change = FALSE; if (! preset || user_context->gimp->busy) return; preset_tool = gimp_context_get_tool (GIMP_CONTEXT (preset->tool_options)); if (preset_tool != gimp_context_get_tool (user_context)) tool_change = TRUE; if (! tool_change) tool_manager_disconnect_options (tool_manager, user_context, preset_tool); /* save the name, we don't want to overwrite it */ options_name = g_strdup (gimp_object_get_name (preset_tool->tool_options)); gimp_config_copy (GIMP_CONFIG (preset->tool_options), GIMP_CONFIG (preset_tool->tool_options), 0); /* restore the saved name */ gimp_object_take_name (GIMP_OBJECT (preset_tool->tool_options), options_name); if (tool_change) gimp_context_set_tool (user_context, preset_tool); else tool_manager_connect_options (tool_manager, user_context, preset_tool); gimp_context_copy_properties (GIMP_CONTEXT (preset->tool_options), user_context, gimp_tool_preset_get_prop_mask (preset)); if (GIMP_IS_PAINT_OPTIONS (preset->tool_options)) { GimpCoreConfig *config = user_context->gimp->config; GimpToolOptions *src = preset->tool_options; GimpToolOptions *dest = tool_manager->active_tool->tool_info->tool_options; /* if connect_options() did overwrite the brush options and the * preset contains a brush, use the brush options from the * preset */ if (config->global_brush && preset->use_brush) gimp_paint_options_copy_brush_props (GIMP_PAINT_OPTIONS (src), GIMP_PAINT_OPTIONS (dest)); if (config->global_dynamics && preset->use_dynamics) gimp_paint_options_copy_dynamics_props (GIMP_PAINT_OPTIONS (src), GIMP_PAINT_OPTIONS (dest)); if (config->global_gradient && preset->use_gradient) gimp_paint_options_copy_gradient_props (GIMP_PAINT_OPTIONS (src), GIMP_PAINT_OPTIONS (dest)); } }
static void tool_manager_tool_changed (GimpContext *user_context, GimpToolInfo *tool_info, GimpToolManager *tool_manager) { GimpTool *new_tool = NULL; if (! tool_info) return; if (! g_type_is_a (tool_info->tool_type, GIMP_TYPE_TOOL)) { g_warning ("%s: tool_info->tool_type is no GimpTool subclass", G_STRFUNC); return; } /* FIXME: gimp_busy HACK */ if (user_context->gimp->busy) { /* there may be contexts waiting for the user_context's "tool-changed" * signal, so stop emitting it. */ g_signal_stop_emission_by_name (user_context, "tool-changed"); if (G_TYPE_FROM_INSTANCE (tool_manager->active_tool) != tool_info->tool_type) { g_signal_handlers_block_by_func (user_context, tool_manager_tool_changed, tool_manager); /* explicitly set the current tool */ gimp_context_set_tool (user_context, tool_manager->active_tool->tool_info); g_signal_handlers_unblock_by_func (user_context, tool_manager_tool_changed, tool_manager); } return; } if (tool_manager->active_tool) { GimpTool *active_tool = tool_manager->active_tool; GimpDisplay *display; /* NULL image returns any display (if there is any) */ display = gimp_tool_has_image (active_tool, NULL); /* commit the old tool's operation before creating the new tool * because creating a tool might mess with the old tool's * options (old and new tool might be the same) */ if (display) tool_manager_control_active (user_context->gimp, GIMP_TOOL_ACTION_COMMIT, display); } new_tool = g_object_new (tool_info->tool_type, "tool-info", tool_info, NULL); tool_manager_select_tool (user_context->gimp, new_tool); g_object_unref (new_tool); /* ??? */ tool_manager_cast_spell (tool_info); }