app/widgets/gimpgradienteditor.[ch] added public APIs for zooming the

2004-10-24  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpgradienteditor.[ch]
	* app/widgets/gimppaletteeditor.[ch]: added public APIs for
	zooming the editors. Use gimp_editor_add_action_button() to create
	all buttons. Removed all button callbacks and all duplicated
	button sensitivity logic.

	* app/widgets/gimpdataeditor.c (gimp_data_editor_set_data): update
	the editor's UI manager if it exists.

	* app/actions/gradient-editor-actions.c
	* app/actions/gradient-editor-commands.[ch]: added zoom actions
	and callback and call gimp_gradient_editor_zoom(). Fixed
	gradient_editor_actions_update() to actually set all items'
	sensitivity (it was possible to modify read-only gradients and
	even to crash GIMP).

	* app/actions/palette-editor-actions.c
	* app/actions/palette-editor-commands.[ch]: changed "new" and
	"zoom" actions to actually do their job instead of calling
	gtk_button_clicked(editor->foo_button).
This commit is contained in:
Michael Natterer 2004-10-24 20:38:35 +00:00 committed by Michael Natterer
parent e64a292d45
commit 714771d450
12 changed files with 669 additions and 571 deletions

View File

@ -1,3 +1,26 @@
2004-10-24 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpgradienteditor.[ch]
* app/widgets/gimppaletteeditor.[ch]: added public APIs for
zooming the editors. Use gimp_editor_add_action_button() to create
all buttons. Removed all button callbacks and all duplicated
button sensitivity logic.
* app/widgets/gimpdataeditor.c (gimp_data_editor_set_data): update
the editor's UI manager if it exists.
* app/actions/gradient-editor-actions.c
* app/actions/gradient-editor-commands.[ch]: added zoom actions
and callback and call gimp_gradient_editor_zoom(). Fixed
gradient_editor_actions_update() to actually set all items'
sensitivity (it was possible to modify read-only gradients and
even to crash GIMP).
* app/actions/palette-editor-actions.c
* app/actions/palette-editor-commands.[ch]: changed "new" and
"zoom" actions to actually do their job instead of calling
gtk_button_clicked(editor->foo_button).
2004-10-24 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpcolormapeditor.c: removed the "Edit Color"

View File

@ -268,7 +268,7 @@ static GimpRadioActionEntry gradient_editor_blending_actions[] =
{ "gradient-editor-blending-varies", NULL,
N_("(Varies)"), NULL, NULL,
0,
-1,
GIMP_HELP_GRADIENT_EDITOR_BLENDING }
};
@ -291,10 +291,31 @@ static GimpRadioActionEntry gradient_editor_coloring_actions[] =
{ "gradient-editor-coloring-varies", NULL,
N_("(Varies)"), NULL, NULL,
0,
-1,
GIMP_HELP_GRADIENT_EDITOR_COLORING }
};
static GimpEnumActionEntry gradient_editor_zoom_actions[] =
{
{ "gradient-editor-zoom-in", GTK_STOCK_ZOOM_IN,
N_("Zoom In"), NULL,
N_("Zoom in"),
GIMP_ZOOM_IN,
GIMP_HELP_GRADIENT_EDITOR_ZOOM_IN },
{ "gradient-editor-zoom-out", GTK_STOCK_ZOOM_OUT,
N_("Zoom Out"), NULL,
N_("Zoom out"),
GIMP_ZOOM_OUT,
GIMP_HELP_GRADIENT_EDITOR_ZOOM_OUT },
{ "gradient-editor-zoom-all", GTK_STOCK_ZOOM_FIT,
N_("Zoom All"), NULL,
N_("Zoom all"),
GIMP_ZOOM_TO, /* abused */
GIMP_HELP_GRADIENT_EDITOR_ZOOM_ALL }
};
void
gradient_editor_actions_setup (GimpActionGroup *group)
@ -335,35 +356,72 @@ gradient_editor_actions_setup (GimpActionGroup *group)
G_N_ELEMENTS (gradient_editor_coloring_actions),
0,
G_CALLBACK (gradient_editor_coloring_type_cmd_callback));
gimp_action_group_add_enum_actions (group,
gradient_editor_zoom_actions,
G_N_ELEMENTS (gradient_editor_zoom_actions),
G_CALLBACK (gradient_editor_zoom_cmd_callback));
}
void
gradient_editor_actions_update (GimpActionGroup *group,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
GimpGradient *gradient;
GimpContext *context;
GimpGradientSegment *left_seg;
GimpGradientSegment *right_seg;
gboolean editable = FALSE;
GimpGradientSegment *left_seg = NULL;
GimpGradientSegment *right_seg = NULL;
GimpRGB fg;
GimpRGB bg;
gboolean blending_equal = TRUE;
gboolean coloring_equal = TRUE;
gboolean selection;
gboolean delete;
gboolean selection = FALSE;
gboolean delete = FALSE;
context =
gimp_get_user_context (GIMP_DATA_EDITOR (editor)->data_factory->gimp);
gradient = GIMP_GRADIENT (data_editor->data);
if (editor->control_sel_l->prev)
left_seg = editor->control_sel_l->prev;
else
left_seg = gimp_gradient_segment_get_last (editor->control_sel_l);
context = gimp_get_user_context (data_editor->data_factory->gimp);
if (editor->control_sel_r->next)
right_seg = editor->control_sel_r->next;
else
right_seg = gimp_gradient_segment_get_first (editor->control_sel_r);
if (gradient)
{
GimpGradientSegmentType type;
GimpGradientSegmentColor color;
GimpGradientSegment *seg, *aseg;
if (data_editor->data_editable)
editable = TRUE;
if (editor->control_sel_l->prev)
left_seg = editor->control_sel_l->prev;
else
left_seg = gimp_gradient_segment_get_last (editor->control_sel_l);
if (editor->control_sel_r->next)
right_seg = editor->control_sel_r->next;
else
right_seg = gimp_gradient_segment_get_first (editor->control_sel_r);
type = editor->control_sel_l->type;
color = editor->control_sel_l->color;
seg = editor->control_sel_l;
do
{
blending_equal = blending_equal && (seg->type == type);
coloring_equal = coloring_equal && (seg->color == color);
aseg = seg;
seg = seg->next;
}
while (aseg != editor->control_sel_r);
selection = (editor->control_sel_l != editor->control_sel_r);
delete = (editor->control_sel_l->prev || editor->control_sel_r->next);
}
if (context)
{
@ -371,30 +429,6 @@ gradient_editor_actions_update (GimpActionGroup *group,
gimp_context_get_background (context, &bg);
}
{
GimpGradientSegmentType type;
GimpGradientSegmentColor color;
GimpGradientSegment *seg, *aseg;
type = editor->control_sel_l->type;
color = editor->control_sel_l->color;
seg = editor->control_sel_l;
do
{
blending_equal = blending_equal && (seg->type == type);
coloring_equal = coloring_equal && (seg->color == color);
aseg = seg;
seg = seg->next;
}
while (aseg != editor->control_sel_r);
}
selection = (editor->control_sel_l != editor->control_sel_r);
delete = (editor->control_sel_l->prev || editor->control_sel_r->next);
#define SET_ACTIVE(action,condition) \
gimp_action_group_set_action_active (group, action, (condition) != 0)
#define SET_COLOR(action,color,set_label) \
@ -406,16 +440,37 @@ gradient_editor_actions_update (GimpActionGroup *group,
#define SET_VISIBLE(action,condition) \
gimp_action_group_set_action_visible (group, action, (condition) != 0)
SET_COLOR ("gradient-editor-left-color",
&editor->control_sel_l->left_color, FALSE);
SET_COLOR ("gradient-editor-load-left-left-neighbor",
&left_seg->right_color, FALSE);
SET_COLOR ("gradient-editor-load-left-right-endpoint",
&editor->control_sel_r->right_color, FALSE);
SET_SENSITIVE ("gradient-editor-left-color", editable);
SET_SENSITIVE ("gradient-editor-load-left-left-neighbor", editable);
SET_SENSITIVE ("gradient-editor-load-left-right-endpoint", editable);
if (gradient)
{
SET_COLOR ("gradient-editor-left-color",
&editor->control_sel_l->left_color, FALSE);
SET_COLOR ("gradient-editor-load-left-left-neighbor",
&left_seg->right_color, FALSE);
SET_COLOR ("gradient-editor-load-left-right-endpoint",
&editor->control_sel_r->right_color, FALSE);
}
SET_SENSITIVE ("gradient-editor-load-left-fg", editable);
SET_SENSITIVE ("gradient-editor-load-left-bg", editable);
SET_COLOR ("gradient-editor-load-left-fg", context ? &fg : NULL, FALSE);
SET_COLOR ("gradient-editor-load-left-bg", context ? &bg : NULL, FALSE);
SET_SENSITIVE ("gradient-editor-load-left-01", editable);
SET_SENSITIVE ("gradient-editor-load-left-02", editable);
SET_SENSITIVE ("gradient-editor-load-left-03", editable);
SET_SENSITIVE ("gradient-editor-load-left-04", editable);
SET_SENSITIVE ("gradient-editor-load-left-05", editable);
SET_SENSITIVE ("gradient-editor-load-left-06", editable);
SET_SENSITIVE ("gradient-editor-load-left-07", editable);
SET_SENSITIVE ("gradient-editor-load-left-08", editable);
SET_SENSITIVE ("gradient-editor-load-left-09", editable);
SET_SENSITIVE ("gradient-editor-load-left-10", editable);
SET_COLOR ("gradient-editor-load-left-01", &editor->saved_colors[0], TRUE);
SET_COLOR ("gradient-editor-load-left-02", &editor->saved_colors[1], TRUE);
SET_COLOR ("gradient-editor-load-left-03", &editor->saved_colors[2], TRUE);
@ -427,6 +482,17 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_COLOR ("gradient-editor-load-left-09", &editor->saved_colors[8], TRUE);
SET_COLOR ("gradient-editor-load-left-10", &editor->saved_colors[9], TRUE);
SET_SENSITIVE ("gradient-editor-save-left-01", gradient);
SET_SENSITIVE ("gradient-editor-save-left-02", gradient);
SET_SENSITIVE ("gradient-editor-save-left-03", gradient);
SET_SENSITIVE ("gradient-editor-save-left-04", gradient);
SET_SENSITIVE ("gradient-editor-save-left-05", gradient);
SET_SENSITIVE ("gradient-editor-save-left-06", gradient);
SET_SENSITIVE ("gradient-editor-save-left-07", gradient);
SET_SENSITIVE ("gradient-editor-save-left-08", gradient);
SET_SENSITIVE ("gradient-editor-save-left-09", gradient);
SET_SENSITIVE ("gradient-editor-save-left-10", gradient);
SET_COLOR ("gradient-editor-save-left-01", &editor->saved_colors[0], TRUE);
SET_COLOR ("gradient-editor-save-left-02", &editor->saved_colors[1], TRUE);
SET_COLOR ("gradient-editor-save-left-03", &editor->saved_colors[2], TRUE);
@ -438,16 +504,37 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_COLOR ("gradient-editor-save-left-09", &editor->saved_colors[8], TRUE);
SET_COLOR ("gradient-editor-save-left-10", &editor->saved_colors[9], TRUE);
SET_COLOR ("gradient-editor-right-color",
&editor->control_sel_r->right_color, FALSE);
SET_COLOR ("gradient-editor-load-right-right-neighbor",
&right_seg->left_color, FALSE);
SET_COLOR ("gradient-editor-load-right-left-endpoint",
&editor->control_sel_l->left_color, FALSE);
SET_SENSITIVE ("gradient-editor-right-color", editable);
SET_SENSITIVE ("gradient-editor-load-right-right-neighbor", editable);
SET_SENSITIVE ("gradient-editor-load-right-left-endpoint", editable);
if (gradient)
{
SET_COLOR ("gradient-editor-right-color",
&editor->control_sel_r->right_color, FALSE);
SET_COLOR ("gradient-editor-load-right-right-neighbor",
&right_seg->left_color, FALSE);
SET_COLOR ("gradient-editor-load-right-left-endpoint",
&editor->control_sel_l->left_color, FALSE);
}
SET_SENSITIVE ("gradient-editor-load-right-fg", editable);
SET_SENSITIVE ("gradient-editor-load-right-bg", editable);
SET_COLOR ("gradient-editor-load-right-fg", context ? &fg : NULL, FALSE);
SET_COLOR ("gradient-editor-load-right-bg", context ? &bg : NULL, FALSE);
SET_SENSITIVE ("gradient-editor-load-right-01", editable);
SET_SENSITIVE ("gradient-editor-load-right-02", editable);
SET_SENSITIVE ("gradient-editor-load-right-03", editable);
SET_SENSITIVE ("gradient-editor-load-right-04", editable);
SET_SENSITIVE ("gradient-editor-load-right-05", editable);
SET_SENSITIVE ("gradient-editor-load-right-06", editable);
SET_SENSITIVE ("gradient-editor-load-right-07", editable);
SET_SENSITIVE ("gradient-editor-load-right-08", editable);
SET_SENSITIVE ("gradient-editor-load-right-09", editable);
SET_SENSITIVE ("gradient-editor-load-right-10", editable);
SET_COLOR ("gradient-editor-load-right-01", &editor->saved_colors[0], TRUE);
SET_COLOR ("gradient-editor-load-right-02", &editor->saved_colors[1], TRUE);
SET_COLOR ("gradient-editor-load-right-03", &editor->saved_colors[2], TRUE);
@ -459,6 +546,17 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_COLOR ("gradient-editor-load-right-09", &editor->saved_colors[8], TRUE);
SET_COLOR ("gradient-editor-load-right-10", &editor->saved_colors[9], TRUE);
SET_SENSITIVE ("gradient-editor-save-right-01", gradient);
SET_SENSITIVE ("gradient-editor-save-right-02", gradient);
SET_SENSITIVE ("gradient-editor-save-right-03", gradient);
SET_SENSITIVE ("gradient-editor-save-right-04", gradient);
SET_SENSITIVE ("gradient-editor-save-right-05", gradient);
SET_SENSITIVE ("gradient-editor-save-right-06", gradient);
SET_SENSITIVE ("gradient-editor-save-right-07", gradient);
SET_SENSITIVE ("gradient-editor-save-right-08", gradient);
SET_SENSITIVE ("gradient-editor-save-right-09", gradient);
SET_SENSITIVE ("gradient-editor-save-right-10", gradient);
SET_COLOR ("gradient-editor-save-right-01", &editor->saved_colors[0], TRUE);
SET_COLOR ("gradient-editor-save-right-02", &editor->saved_colors[1], TRUE);
SET_COLOR ("gradient-editor-save-right-03", &editor->saved_colors[2], TRUE);
@ -470,6 +568,14 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_COLOR ("gradient-editor-save-right-09", &editor->saved_colors[8], TRUE);
SET_COLOR ("gradient-editor-save-right-10", &editor->saved_colors[9], TRUE);
SET_SENSITIVE ("gradient-editor-flip", editable);
SET_SENSITIVE ("gradient-editor-replicate", editable);
SET_SENSITIVE ("gradient-editor-split-midpoint", editable);
SET_SENSITIVE ("gradient-editor-split-uniform", editable);
SET_SENSITIVE ("gradient-editor-delete", editable && delete);
SET_SENSITIVE ("gradient-editor-recenter", editable);
SET_SENSITIVE ("gradient-editor-redistribute", editable);
if (! selection)
{
SET_LABEL ("gradient-editor-blending-func",
@ -516,11 +622,15 @@ gradient_editor_actions_update (GimpActionGroup *group,
}
SET_SENSITIVE ("gradient-editor-blending-varies", FALSE);
SET_SENSITIVE ("gradient-editor-coloring-varies", FALSE);
SET_VISIBLE ("gradient-editor-blending-varies", ! blending_equal);
SET_VISIBLE ("gradient-editor-blending-varies", ! blending_equal);
SET_SENSITIVE ("gradient-editor-blending-linear", editable);
SET_SENSITIVE ("gradient-editor-blending-curved", editable);
SET_SENSITIVE ("gradient-editor-blending-sine", editable);
SET_SENSITIVE ("gradient-editor-blending-sphere-increasing", editable);
SET_SENSITIVE ("gradient-editor-blending-sphere-decreasing", editable);
if (blending_equal)
if (blending_equal && gradient)
{
switch (editor->control_sel_l->type)
{
@ -546,9 +656,14 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_ACTIVE ("gradient-editor-blending-varies", TRUE);
}
SET_VISIBLE ("gradient-editor-coloring-varies", ! coloring_equal);
SET_SENSITIVE ("gradient-editor-coloring-varies", FALSE);
SET_VISIBLE ("gradient-editor-coloring-varies", ! coloring_equal);
if (coloring_equal)
SET_SENSITIVE ("gradient-editor-coloring-rgb", editable);
SET_SENSITIVE ("gradient-editor-coloring-hsv-ccw", editable);
SET_SENSITIVE ("gradient-editor-coloring-hsv-cw", editable);
if (coloring_equal && gradient)
{
switch (editor->control_sel_l->color)
{
@ -568,9 +683,12 @@ gradient_editor_actions_update (GimpActionGroup *group,
SET_ACTIVE ("gradient-editor-coloring-varies", TRUE);
}
SET_SENSITIVE ("gradient-editor-blend-color", selection);
SET_SENSITIVE ("gradient-editor-blend-opacity", selection);
SET_SENSITIVE ("gradient-editor-delete", delete);
SET_SENSITIVE ("gradient-editor-blend-color", editable && selection);
SET_SENSITIVE ("gradient-editor-blend-opacity", editable && selection);
SET_SENSITIVE ("gradient-editor-zoom-out", gradient);
SET_SENSITIVE ("gradient-editor-zoom-in", gradient);
SET_SENSITIVE ("gradient-editor-zoom-all", gradient);
#undef SET_ACTIVE
#undef SET_COLOR

View File

@ -276,19 +276,23 @@ gradient_editor_blending_func_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
GimpGradientSegmentType type;
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
gint value;
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
type = (GimpGradientSegmentType)
gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
gimp_gradient_segment_range_set_blending_function (gradient,
editor->control_sel_l,
editor->control_sel_r,
type);
if (gradient && value >= 0)
{
GimpGradientSegmentType type = value;
gimp_gradient_segment_range_set_blending_function (gradient,
editor->control_sel_l,
editor->control_sel_r,
type);
}
}
void
@ -296,27 +300,31 @@ gradient_editor_coloring_type_cmd_callback (GtkAction *action,
GtkAction *current,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
GimpGradientSegmentColor color;
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
gint value;
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
color = (GimpGradientSegmentColor)
gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));
gimp_gradient_segment_range_set_coloring_type (gradient,
editor->control_sel_l,
editor->control_sel_r,
color);
if (gradient && value >= 0)
{
GimpGradientSegmentColor color = value;
gimp_gradient_segment_range_set_coloring_type (gradient,
editor->control_sel_l,
editor->control_sel_r,
color);
}
}
void
gradient_editor_flip_cmd_callback (GtkAction *action,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
GimpGradient *gradient;
gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data);
@ -573,6 +581,16 @@ gradient_editor_blend_opacity_cmd_callback (GtkAction *action,
FALSE, TRUE);
}
void
gradient_editor_zoom_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpGradientEditor *editor = GIMP_GRADIENT_EDITOR (data);
gimp_gradient_editor_zoom (editor, (GimpZoomType) value);
}
/* private functions */

View File

@ -65,5 +65,9 @@ void gradient_editor_blend_color_cmd_callback (GtkAction *action,
void gradient_editor_blend_opacity_cmd_callback (GtkAction *action,
gpointer data);
void gradient_editor_zoom_cmd_callback (GtkAction *action,
gint value,
gpointer data);
#endif /* __GRADIENT_EDITOR_COMMANDS_H__ */

View File

@ -44,38 +44,51 @@ static GimpActionEntry palette_editor_actions[] =
GIMP_HELP_PALETTE_EDITOR_DIALOG },
{ "palette-editor-edit-color", GIMP_STOCK_EDIT,
N_("_Edit Color..."), "", NULL,
N_("_Edit Color..."), "",
N_("Edit color"),
G_CALLBACK (palette_editor_edit_color_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_EDIT },
{ "palette-editor-delete-color", GTK_STOCK_DELETE,
N_("_Delete Color"), "",
N_("Delete color"),
G_CALLBACK (palette_editor_delete_color_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_DELETE }
};
static GimpEnumActionEntry palette_editor_new_actions[] =
{
{ "palette-editor-new-color-fg", GTK_STOCK_NEW,
N_("New Color from _FG"), "", NULL,
G_CALLBACK (palette_editor_new_color_fg_cmd_callback),
N_("New Color from _FG"), "",
N_("New color from FG"),
FALSE,
GIMP_HELP_PALETTE_EDITOR_NEW },
{ "palette-editor-new-color-bg", GTK_STOCK_NEW,
N_("New Color from _BG"), "", NULL,
G_CALLBACK (palette_editor_new_color_bg_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_NEW },
{ "palette-editor-delete-color", GTK_STOCK_DELETE,
N_("_Delete Color"), "", NULL,
G_CALLBACK (palette_editor_delete_color_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_DELETE },
{ "palette-editor-zoom-out", GTK_STOCK_ZOOM_OUT,
N_("Zoom _Out"), "", NULL,
G_CALLBACK (palette_editor_zoom_out_cmd_callback),
GIMP_HELP_PALETTE_EDITOR_ZOOM_OUT },
N_("New Color from _BG"), "",
N_("New color from BG"),
TRUE,
GIMP_HELP_PALETTE_EDITOR_NEW }
};
static GimpEnumActionEntry palette_editor_zoom_actions[] =
{
{ "palette-editor-zoom-in", GTK_STOCK_ZOOM_IN,
N_("Zoom _In"), "", NULL,
G_CALLBACK (palette_editor_zoom_in_cmd_callback),
N_("Zoom _In"), "",
N_("Zoom in"),
GIMP_ZOOM_IN,
GIMP_HELP_PALETTE_EDITOR_ZOOM_IN },
{ "palette-editor-zoom-out", GTK_STOCK_ZOOM_OUT,
N_("Zoom _Out"), "",
N_("Zoom out"),
GIMP_ZOOM_OUT,
GIMP_HELP_PALETTE_EDITOR_ZOOM_OUT },
{ "palette-editor-zoom-all", GTK_STOCK_ZOOM_FIT,
N_("Zoom _All"), "", NULL,
G_CALLBACK (palette_editor_zoom_all_cmd_callback),
N_("Zoom _All"), "",
N_("Zoom all"),
GIMP_ZOOM_TO, /* abused */
GIMP_HELP_PALETTE_EDITOR_ZOOM_ALL }
};
@ -86,6 +99,16 @@ palette_editor_actions_setup (GimpActionGroup *group)
gimp_action_group_add_actions (group,
palette_editor_actions,
G_N_ELEMENTS (palette_editor_actions));
gimp_action_group_add_enum_actions (group,
palette_editor_new_actions,
G_N_ELEMENTS (palette_editor_new_actions),
G_CALLBACK (palette_editor_new_color_cmd_callback));
gimp_action_group_add_enum_actions (group,
palette_editor_zoom_actions,
G_N_ELEMENTS (palette_editor_zoom_actions),
G_CALLBACK (palette_editor_zoom_cmd_callback));
}
void
@ -122,17 +145,18 @@ palette_editor_actions_update (GimpActionGroup *group,
gimp_action_group_set_action_color (group, action, color, FALSE);
SET_SENSITIVE ("palette-editor-edit-color", editable && editor->color);
SET_SENSITIVE ("palette-editor-delete-color", editable && editor->color);
SET_SENSITIVE ("palette-editor-new-color-fg", editable);
SET_SENSITIVE ("palette-editor-new-color-bg", editable);
SET_SENSITIVE ("palette-editor-delete-color", editable && editor->color);
SET_COLOR ("palette-editor-new-color-fg", context ? &fg : NULL);
SET_COLOR ("palette-editor-new-color-bg", context ? &bg : NULL);
SET_SENSITIVE ("palette-editor-zoom-out", data);
SET_SENSITIVE ("palette-editor-zoom-in", data);
SET_SENSITIVE ("palette-editor-zoom-all", data);
SET_COLOR ("palette-editor-new-color-fg", context ? &fg : NULL);
SET_COLOR ("palette-editor-new-color-bg", context ? &bg : NULL);
#undef SET_SENSITIVE
#undef SET_COLOR
}

View File

@ -24,10 +24,27 @@
#include "actions-types.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpdatafactory.h"
#include "core/gimppalette.h"
#include "widgets/gimpcolordialog.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimppaletteeditor.h"
#include "palette-editor-commands.h"
#include "gimp-intl.h"
/* local function prototypes */
static void palette_editor_edit_color_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpPaletteEditor *editor);
/* public functions */
@ -35,69 +52,123 @@ void
palette_editor_edit_color_cmd_callback (GtkAction *action,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
GimpPalette *palette;
if (GTK_WIDGET_SENSITIVE (editor->edit_button))
gtk_button_clicked (GTK_BUTTON (editor->edit_button));
if (! (data_editor->data && data_editor->data_editable && editor->color))
return;
palette = GIMP_PALETTE (data_editor->data);
if (! editor->color_dialog)
{
editor->color_dialog =
gimp_color_dialog_new (GIMP_VIEWABLE (palette),
_("Edit Palette Color"),
GIMP_STOCK_PALETTE,
_("Edit Color Palette Entry"),
GTK_WIDGET (editor),
gimp_dialog_factory_from_name ("toplevel"),
"gimp-palette-editor-color-dialog",
(const GimpRGB *) &editor->color->color,
FALSE, FALSE);
g_signal_connect (editor->color_dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&editor->color_dialog);
g_signal_connect (editor->color_dialog, "update",
G_CALLBACK (palette_editor_edit_color_update),
editor);
}
else
{
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog),
GIMP_VIEWABLE (palette));
gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog),
&editor->color->color);
}
gtk_window_present (GTK_WINDOW (editor->color_dialog));
}
void
palette_editor_new_color_fg_cmd_callback (GtkAction *action,
gpointer data)
palette_editor_new_color_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->new_button))
gimp_button_extended_clicked (GIMP_BUTTON (editor->new_button), 0);
}
if (data_editor->data && data_editor->data_editable)
{
GimpPalette *palette = GIMP_PALETTE (data_editor->data);
GimpContext *context;
GimpRGB color;
void
palette_editor_new_color_bg_cmd_callback (GtkAction *action,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
context = gimp_get_user_context (data_editor->data_factory->gimp);
if (GTK_WIDGET_SENSITIVE (editor->new_button))
gimp_button_extended_clicked (GIMP_BUTTON (editor->new_button),
GDK_CONTROL_MASK);
if (value)
gimp_context_get_background (context, &color);
else
gimp_context_get_foreground (context, &color);
editor->color = gimp_palette_add_entry (palette, NULL, &color);
}
}
void
palette_editor_delete_color_cmd_callback (GtkAction *action,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->delete_button))
gtk_button_clicked (GTK_BUTTON (editor->delete_button));
if (data_editor->data && data_editor->data_editable && editor->color)
{
GimpPalette *palette = GIMP_PALETTE (data_editor->data);
gimp_palette_delete_entry (palette, editor->color);
}
}
void
palette_editor_zoom_in_cmd_callback (GtkAction *action,
gpointer data)
palette_editor_zoom_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->zoom_in_button))
gtk_button_clicked (GTK_BUTTON (editor->zoom_in_button));
gimp_palette_editor_zoom (editor, (GimpZoomType) value);
}
void
palette_editor_zoom_out_cmd_callback (GtkAction *action,
gpointer data)
/* private functions */
static void
palette_editor_edit_color_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpPaletteEditor *editor)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
if (GTK_WIDGET_SENSITIVE (editor->zoom_out_button))
gtk_button_clicked (GTK_BUTTON (editor->zoom_out_button));
}
void
palette_editor_zoom_all_cmd_callback (GtkAction *action,
gpointer data)
{
GimpPaletteEditor *editor = GIMP_PALETTE_EDITOR (data);
if (GTK_WIDGET_SENSITIVE (editor->zoom_all_button))
gtk_button_clicked (GTK_BUTTON (editor->zoom_all_button));
switch (state)
{
case GIMP_COLOR_DIALOG_UPDATE:
break;
case GIMP_COLOR_DIALOG_OK:
if (editor->color)
{
editor->color->color = *color;
gimp_data_dirty (GIMP_DATA (palette));
}
/* Fallthrough */
case GIMP_COLOR_DIALOG_CANCEL:
gtk_widget_hide (editor->color_dialog);
break;
}
}

View File

@ -22,18 +22,14 @@
void palette_editor_edit_color_cmd_callback (GtkAction *action,
gpointer data);
void palette_editor_new_color_fg_cmd_callback (GtkAction *action,
gpointer data);
void palette_editor_new_color_bg_cmd_callback (GtkAction *action,
void palette_editor_new_color_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void palette_editor_delete_color_cmd_callback (GtkAction *action,
gpointer data);
void palette_editor_zoom_in_cmd_callback (GtkAction *action,
gpointer data);
void palette_editor_zoom_out_cmd_callback (GtkAction *action,
gpointer data);
void palette_editor_zoom_all_cmd_callback (GtkAction *action,
void palette_editor_zoom_cmd_callback (GtkAction *action,
gint value,
gpointer data);

View File

@ -39,6 +39,7 @@
#include "gimpdocked.h"
#include "gimpmenufactory.h"
#include "gimpsessioninfo.h"
#include "gimpuimanager.h"
#include "gimp-intl.h"
@ -56,6 +57,9 @@ static void gimp_data_editor_init (GimpDataEditor *view);
static void gimp_data_editor_docked_iface_init (GimpDockedInterface *docked_iface);
static GObject * gimp_data_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_data_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
@ -136,6 +140,7 @@ gimp_data_editor_class_init (GimpDataEditorClass *klass)
parent_class = g_type_class_peek_parent (klass);
object_class->constructor = gimp_data_editor_constructor;
object_class->set_property = gimp_data_editor_set_property;
object_class->get_property = gimp_data_editor_get_property;
object_class->dispose = gimp_data_editor_dispose;
@ -173,6 +178,26 @@ gimp_data_editor_init (GimpDataEditor *editor)
g_signal_connect (editor->name_entry, "focus_out_event",
G_CALLBACK (gimp_data_editor_name_focus_out),
editor);
}
static void
gimp_data_editor_docked_iface_init (GimpDockedInterface *docked_iface)
{
docked_iface->set_aux_info = gimp_data_editor_set_aux_info;
docked_iface->get_aux_info = gimp_data_editor_get_aux_info;
}
static GObject *
gimp_data_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpDataEditor *editor;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
editor = GIMP_DATA_EDITOR (object);
editor->save_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
@ -189,13 +214,8 @@ gimp_data_editor_init (GimpDataEditor *editor)
G_CALLBACK (gimp_data_editor_revert_clicked),
NULL,
editor);
}
static void
gimp_data_editor_docked_iface_init (GimpDockedInterface *docked_iface)
{
docked_iface->set_aux_info = gimp_data_editor_set_aux_info;
docked_iface->get_aux_info = gimp_data_editor_get_aux_info;
return object;
}
static void
@ -356,6 +376,10 @@ gimp_data_editor_set_data (GimpDataEditor *editor,
GIMP_DATA_EDITOR_GET_CLASS (editor)->set_data (editor, data);
g_object_notify (G_OBJECT (editor), "data");
if (GIMP_EDITOR (editor)->ui_manager)
gimp_ui_manager_update (GIMP_EDITOR (editor)->ui_manager,
GIMP_EDITOR (editor)->popup_data);
}
}

View File

@ -106,6 +106,10 @@
static void gimp_gradient_editor_class_init (GimpGradientEditorClass *klass);
static void gimp_gradient_editor_init (GimpGradientEditor *editor);
static GObject * gimp_gradient_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_gradient_editor_set_data (GimpDataEditor *editor,
GimpData *data);
@ -116,12 +120,6 @@ static void gradient_editor_drop_gradient (GtkWidget *widget,
gpointer data);
static void gradient_editor_scrollbar_update (GtkAdjustment *adj,
GimpGradientEditor *editor);
static void gradient_editor_zoom_out_callback (GtkWidget *widget,
GimpGradientEditor *editor);
static void gradient_editor_zoom_in_callback (GtkWidget *widget,
GimpGradientEditor *editor);
static void gradient_editor_zoom_all_callback (GtkWidget *widget,
GimpGradientEditor *editor);
static void gradient_editor_instant_update_update (GtkWidget *widget,
GimpGradientEditor *editor);
@ -257,11 +255,14 @@ gimp_gradient_editor_get_type (void)
static void
gimp_gradient_editor_class_init (GimpGradientEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpDataEditorClass *editor_class = GIMP_DATA_EDITOR_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
editor_class->set_data = gimp_gradient_editor_set_data;
object_class->constructor = gimp_gradient_editor_constructor;
editor_class->set_data = gimp_gradient_editor_set_data;
}
static void
@ -351,26 +352,6 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
gtk_box_pack_start (GTK_BOX (editor), editor->scrollbar, FALSE, FALSE, 0);
gtk_widget_show (editor->scrollbar);
/* +, - and Zoom Fit buttons */
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_ZOOM_OUT, _("Zoom Out"),
GIMP_HELP_GRADIENT_EDITOR_ZOOM_OUT,
G_CALLBACK (gradient_editor_zoom_out_callback),
NULL,
editor);
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_ZOOM_IN, _("Zoom In"),
GIMP_HELP_GRADIENT_EDITOR_ZOOM_IN,
G_CALLBACK (gradient_editor_zoom_in_callback),
NULL,
editor);
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_ZOOM_FIT, _("Zoom All"),
GIMP_HELP_GRADIENT_EDITOR_ZOOM_ALL,
G_CALLBACK (gradient_editor_zoom_all_callback),
NULL,
editor);
/* Instant update toggle */
editor->instant_update = TRUE;
@ -431,6 +412,30 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
gimp_rgba_set (&editor->saved_colors[9], 1.0, 0.0, 1.0, GIMP_OPACITY_OPAQUE);
}
static GObject *
gimp_gradient_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpGradientEditor *editor;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
editor = GIMP_GRADIENT_EDITOR (object);
gimp_editor_add_action_button (GIMP_EDITOR (editor), "gradient-editor",
"gradient-editor-zoom-out", NULL);
gimp_editor_add_action_button (GIMP_EDITOR (editor), "gradient-editor",
"gradient-editor-zoom-in", NULL);
gimp_editor_add_action_button (GIMP_EDITOR (editor), "gradient-editor",
"gradient-editor-zoom-all", NULL);
return object;
}
static void
gimp_gradient_editor_set_data (GimpDataEditor *editor,
GimpData *data)
@ -535,6 +540,63 @@ gimp_gradient_editor_update (GimpGradientEditor *editor)
control_update (editor, gradient, FALSE);
}
void
gimp_gradient_editor_zoom (GimpGradientEditor *editor,
GimpZoomType zoom_type)
{
GtkAdjustment *adjustment;
gdouble old_value;
gdouble old_page_size;
gdouble value = 0.0;
gdouble page_size = 1.0;
g_return_if_fail (GIMP_IS_GRADIENT_EDITOR (editor));
adjustment = GTK_ADJUSTMENT (editor->scroll_data);
old_value = adjustment->value;
old_page_size = adjustment->page_size;
switch (zoom_type)
{
case GIMP_ZOOM_IN:
editor->zoom_factor++;
page_size = 1.0 / editor->zoom_factor;
value = old_value + (old_page_size - page_size) / 2.0;
break;
case GIMP_ZOOM_OUT:
if (editor->zoom_factor <= 1)
return;
editor->zoom_factor--;
page_size = 1.0 / editor->zoom_factor;
value = old_value - (page_size - old_page_size) / 2.0;
if (value < 0.0)
value = 0.0;
else if ((value + page_size) > 1.0)
value = 1.0 - page_size;
break;
case GIMP_ZOOM_TO: /* abused as ZOOM_ALL */
editor->zoom_factor = 1;
value = 0.0;
page_size = 1.0;
break;
}
adjustment->value = value;
adjustment->page_size = page_size;
adjustment->step_increment = page_size * GRAD_SCROLLBAR_STEP_SIZE;
adjustment->page_increment = page_size * GRAD_SCROLLBAR_PAGE_SIZE;
gtk_adjustment_changed (GTK_ADJUSTMENT (editor->scroll_data));
}
/* private functions */
@ -576,86 +638,6 @@ gradient_editor_scrollbar_update (GtkAdjustment *adjustment,
gimp_gradient_editor_update (editor);
}
static void
gradient_editor_zoom_out_callback (GtkWidget *widget,
GimpGradientEditor *editor)
{
GtkAdjustment *adjustment;
gdouble old_value;
gdouble value;
gdouble old_page_size;
gdouble page_size;
if (editor->zoom_factor <= 1)
return;
adjustment = GTK_ADJUSTMENT (editor->scroll_data);
old_value = adjustment->value;
old_page_size = adjustment->page_size;
editor->zoom_factor--;
page_size = 1.0 / editor->zoom_factor;
value = old_value - (page_size - old_page_size) / 2.0;
if (value < 0.0)
value = 0.0;
else if ((value + page_size) > 1.0)
value = 1.0 - page_size;
adjustment->value = value;
adjustment->page_size = page_size;
adjustment->step_increment = page_size * GRAD_SCROLLBAR_STEP_SIZE;
adjustment->page_increment = page_size * GRAD_SCROLLBAR_PAGE_SIZE;
gtk_adjustment_changed (GTK_ADJUSTMENT (editor->scroll_data));
}
static void
gradient_editor_zoom_in_callback (GtkWidget *widget,
GimpGradientEditor *editor)
{
GtkAdjustment *adjustment;
gdouble old_value;
gdouble old_page_size;
gdouble page_size;
adjustment = GTK_ADJUSTMENT (editor->scroll_data);
old_value = adjustment->value;
old_page_size = adjustment->page_size;
editor->zoom_factor++;
page_size = 1.0 / editor->zoom_factor;
adjustment->value = old_value + (old_page_size - page_size) / 2.0;
adjustment->page_size = page_size;
adjustment->step_increment = page_size * GRAD_SCROLLBAR_STEP_SIZE;
adjustment->page_increment = page_size * GRAD_SCROLLBAR_PAGE_SIZE;
gtk_adjustment_changed (GTK_ADJUSTMENT (editor->scroll_data));
}
static void
gradient_editor_zoom_all_callback (GtkWidget *widget,
GimpGradientEditor *editor)
{
GtkAdjustment *adjustment;
adjustment = GTK_ADJUSTMENT (editor->scroll_data);
editor->zoom_factor = 1;
adjustment->value = 0.0;
adjustment->page_size = 1.0;
adjustment->step_increment = GRAD_SCROLLBAR_STEP_SIZE;
adjustment->page_increment = GRAD_SCROLLBAR_PAGE_SIZE;
gtk_adjustment_changed (GTK_ADJUSTMENT (editor->scroll_data));
}
static void
gradient_editor_instant_update_update (GtkWidget *widget,
GimpGradientEditor *editor)
@ -765,9 +747,9 @@ view_events (GtkWidget *widget,
if (sevent->state & GDK_SHIFT_MASK)
{
if (sevent->direction == GDK_SCROLL_UP)
gradient_editor_zoom_in_callback (NULL, editor);
gimp_gradient_editor_zoom (editor, GIMP_ZOOM_IN);
else
gradient_editor_zoom_out_callback (NULL, editor);
gimp_gradient_editor_zoom (editor, GIMP_ZOOM_OUT);
}
else
{
@ -990,9 +972,9 @@ control_events (GtkWidget *widget,
if (sevent->state & GDK_SHIFT_MASK)
{
if (sevent->direction == GDK_SCROLL_UP)
gradient_editor_zoom_in_callback (NULL, editor);
gimp_gradient_editor_zoom (editor, GIMP_ZOOM_IN);
else
gradient_editor_zoom_out_callback (NULL, editor);
gimp_gradient_editor_zoom (editor, GIMP_ZOOM_OUT);
}
else
{
@ -1575,6 +1557,17 @@ control_update (GimpGradientEditor *editor,
gint pwidth = 0;
gint pheight = 0;
if (! editor->control_sel_l || ! editor->control_sel_r)
reset_selection = TRUE;
if (reset_selection)
{
if (gradient)
control_select_single_segment (editor, gradient->segments);
else
control_select_single_segment (editor, NULL);
}
if (! GTK_WIDGET_DRAWABLE (editor->control))
return;
@ -1596,17 +1589,6 @@ control_update (GimpGradientEditor *editor,
gdk_pixmap_new (editor->control->window, cwidth, cheight, -1);
}
if (! editor->control_sel_l || ! editor->control_sel_r)
reset_selection = TRUE;
if (reset_selection)
{
if (gradient)
control_select_single_segment (editor, gradient->segments);
else
control_select_single_segment (editor, NULL);
}
/* Redraw pixmap */
adjustment = GTK_ADJUSTMENT (editor->scroll_data);

View File

@ -115,6 +115,8 @@ GtkWidget * gimp_gradient_editor_new (Gimp *gimp,
GimpMenuFactory *menu_factory);
void gimp_gradient_editor_update (GimpGradientEditor *editor);
void gimp_gradient_editor_zoom (GimpGradientEditor *editor,
GimpZoomType zoom_type);
#endif /* __GIMP_GRADIENT_EDITOR_H__ */

View File

@ -39,13 +39,12 @@
#include "core/gimpdatafactory.h"
#include "core/gimppalette.h"
#include "gimpcolordialog.h"
#include "gimpdialogfactory.h"
#include "gimpdnd.h"
#include "gimpdocked.h"
#include "gimphelp-ids.h"
#include "gimppaletteeditor.h"
#include "gimpsessioninfo.h"
#include "gimpuimanager.h"
#include "gimpwidgets-utils.h"
#include "gimp-intl.h"
@ -71,6 +70,11 @@ static void gimp_palette_editor_class_init (GimpPaletteEditorClass *klass);
static void gimp_palette_editor_init (GimpPaletteEditor *editor);
static void gimp_palette_editor_docked_iface_init (GimpDockedInterface *docked_iface);
static GObject * gimp_palette_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_palette_editor_set_aux_info (GimpDocked *docked,
GList *aux_info);
static GList *gimp_palette_editor_get_aux_info (GimpDocked *docked);
@ -102,24 +106,6 @@ static void palette_editor_color_name_changed (GtkWidget *widget,
static void palette_editor_columns_changed (GtkAdjustment *adj,
GimpPaletteEditor *editor);
static void palette_editor_new_clicked (GtkWidget *widget,
GimpPaletteEditor *editor);
static void palette_editor_new_ext_clicked (GtkWidget *widget,
GdkModifierType state,
GimpPaletteEditor *editor);
static void palette_editor_edit_clicked (GtkWidget *widget,
GimpPaletteEditor *editor);
static void palette_editor_delete_clicked (GtkWidget *widget,
GimpPaletteEditor *editor);
static void palette_editor_zoom_out_clicked (GtkWidget *widget,
GimpPaletteEditor *editor);
static void palette_editor_zoom_in_clicked (GtkWidget *widget,
GimpPaletteEditor *editor);
static void palette_editor_zoom_all_clicked (GtkWidget *widget,
GimpPaletteEditor *editor);
static void palette_editor_redraw_zoom (GimpPaletteEditor *editor,
gdouble zoom_factor);
static void palette_editor_drag_color (GtkWidget *widget,
GimpRGB *color,
gpointer data);
@ -137,11 +123,6 @@ static void palette_editor_viewport_resized (GtkWidget *widget,
static void palette_editor_viewport_realize (GtkWidget *widget,
GimpPaletteEditor *editor);
static void palette_editor_color_dialog_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpPaletteEditor *editor);
static GimpDataEditorClass *parent_class = NULL;
static GimpDockedInterface *parent_docked_iface = NULL;
@ -187,17 +168,20 @@ gimp_palette_editor_get_type (void)
static void
gimp_palette_editor_class_init (GimpPaletteEditorClass *klass)
{
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpDataEditorClass *editor_class = GIMP_DATA_EDITOR_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpDataEditorClass *editor_class = GIMP_DATA_EDITOR_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->destroy = gimp_palette_editor_destroy;
object_class->constructor = gimp_palette_editor_constructor;
widget_class->unmap = gimp_palette_editor_unmap;
gtk_object_class->destroy = gimp_palette_editor_destroy;
editor_class->set_data = gimp_palette_editor_set_data;
widget_class->unmap = gimp_palette_editor_unmap;
editor_class->set_data = gimp_palette_editor_set_data;
}
static void
@ -209,7 +193,6 @@ gimp_palette_editor_init (GimpPaletteEditor *editor)
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *spinbutton;
gchar *str;
editor->zoom_factor = 1.0;
editor->col_width = 0;
@ -292,57 +275,6 @@ gimp_palette_editor_init (GimpPaletteEditor *editor)
g_signal_connect (editor->columns_data, "value_changed",
G_CALLBACK (palette_editor_columns_changed),
editor);
editor->edit_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GIMP_STOCK_EDIT, _("Edit color"),
GIMP_HELP_PALETTE_EDITOR_EDIT,
G_CALLBACK (palette_editor_edit_clicked),
NULL,
editor);
str = g_strdup_printf (_("New color from FG\n%s from BG"),
gimp_get_mod_string (GDK_CONTROL_MASK));
editor->new_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_NEW, str,
GIMP_HELP_PALETTE_EDITOR_NEW,
G_CALLBACK (palette_editor_new_clicked),
G_CALLBACK (palette_editor_new_ext_clicked),
editor);
g_free (str);
editor->delete_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_DELETE, _("Delete color"),
GIMP_HELP_PALETTE_EDITOR_DELETE,
G_CALLBACK (palette_editor_delete_clicked),
NULL,
editor);
editor->zoom_out_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_ZOOM_OUT, _("Zoom out"),
GIMP_HELP_PALETTE_EDITOR_ZOOM_OUT,
G_CALLBACK (palette_editor_zoom_out_clicked),
NULL,
editor);
editor->zoom_in_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_ZOOM_IN, _("Zoom in"),
GIMP_HELP_PALETTE_EDITOR_ZOOM_IN,
G_CALLBACK (palette_editor_zoom_in_clicked),
NULL,
editor);
editor->zoom_all_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GTK_STOCK_ZOOM_FIT, _("Zoom all"),
GIMP_HELP_PALETTE_EDITOR_ZOOM_ALL,
G_CALLBACK (palette_editor_zoom_all_clicked),
NULL,
editor);
}
static void
@ -354,6 +286,48 @@ gimp_palette_editor_docked_iface_init (GimpDockedInterface *docked_iface)
docked_iface->get_aux_info = gimp_palette_editor_get_aux_info;
}
static GObject *
gimp_palette_editor_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpPaletteEditor *editor;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
editor = GIMP_PALETTE_EDITOR (object);
editor->edit_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor), "palette-editor",
"palette-editor-edit-color", NULL);
editor->new_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor), "palette-editor",
"palette-editor-new-color-fg",
"palette-editor-new-color-bg",
GDK_CONTROL_MASK,
NULL);
editor->delete_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor), "palette-editor",
"palette-editor-delete-color", NULL);
editor->zoom_out_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor), "palette-editor",
"palette-editor-zoom-out", NULL);
editor->zoom_in_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor), "palette-editor",
"palette-editor-zoom-in", NULL);
editor->zoom_all_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor), "palette-editor",
"palette-editor-zoom-all", NULL);
return object;
}
#define AUX_INFO_ZOOM_FACTOR "zoom-factor"
static void
@ -480,18 +454,6 @@ gimp_palette_editor_set_data (GimpDataEditor *editor,
g_signal_handlers_unblock_by_func (palette_editor->columns_data,
palette_editor_columns_changed,
editor);
gtk_widget_set_sensitive (palette_editor->edit_button, FALSE);
gtk_widget_set_sensitive (palette_editor->new_button,
editor->data_editable);
gtk_widget_set_sensitive (palette_editor->delete_button, FALSE);
gtk_widget_set_sensitive (palette_editor->zoom_out_button,
editor->data != NULL);
gtk_widget_set_sensitive (palette_editor->zoom_in_button,
editor->data != NULL);
gtk_widget_set_sensitive (palette_editor->zoom_all_button,
editor->data != NULL);
}
/* public functions */
@ -542,6 +504,65 @@ gimp_palette_editor_pick_color (GimpPaletteEditor *editor,
}
}
void
gimp_palette_editor_zoom (GimpPaletteEditor *editor,
GimpZoomType zoom_type)
{
GimpPalette *palette;
gdouble zoom_factor;
g_return_if_fail (GIMP_IS_PALETTE_EDITOR (editor));
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
if (! palette)
return;
zoom_factor = editor->zoom_factor;
switch (zoom_type)
{
case GIMP_ZOOM_IN:
zoom_factor += 0.1;
break;
case GIMP_ZOOM_OUT:
zoom_factor -= 0.1;
break;
case GIMP_ZOOM_TO: /* abused as ZOOM_ALL */
{
gint height;
gint rows;
height = editor->color_area->parent->parent->parent->allocation.height;
if (palette->n_columns)
rows = palette->n_colors / palette->n_columns;
else
rows = palette->n_colors / COLUMNS;
rows = MAX (1, rows);
zoom_factor = (((gdouble) height - 2 * SPACING) /
(gdouble) rows - SPACING) / ENTRY_HEIGHT;
}
break;
}
zoom_factor = CLAMP (zoom_factor, 0.1, 4.0);
if (palette->n_columns)
editor->columns = palette->n_columns;
else
editor->columns = COLUMNS;
editor->columns_valid = FALSE;
palette_editor_redraw (editor, editor->last_width, zoom_factor);
palette_editor_scroll_top_left (editor);
}
/* private functions */
@ -621,7 +642,14 @@ palette_editor_color_area_button_press (GtkWidget *widget,
bevent->button == 1 &&
bevent->type == GDK_2BUTTON_PRESS)
{
gtk_button_clicked (GTK_BUTTON (editor->edit_button));
GtkAction *action;
action = gimp_ui_manager_get_action (GIMP_EDITOR (editor)->ui_manager,
"palette-editor",
"palette-editor-new-color");
if (action)
gtk_action_activate (action);
}
return FALSE; /* continue with eventbox_button_press */
@ -976,10 +1004,6 @@ palette_editor_select_entry (GimpPaletteEditor *editor,
gtk_widget_set_sensitive (editor->color_name,
entry && data_editor->data_editable);
gtk_widget_set_sensitive (editor->edit_button,
entry && data_editor->data_editable);
gtk_widget_set_sensitive (editor->delete_button,
entry && data_editor->data_editable);
}
}
@ -1020,169 +1044,6 @@ palette_editor_columns_changed (GtkAdjustment *adj,
}
}
/* palette zoom functions & callbacks **************************************/
static void
palette_editor_edit_clicked (GtkWidget *widget,
GimpPaletteEditor *editor)
{
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (editor);
GimpPalette *palette;
if (! (data_editor->data && data_editor->data_editable && editor->color))
return;
palette = GIMP_PALETTE (data_editor->data);
if (! editor->color_dialog)
{
GimpDialogFactory *toplevel_factory;
toplevel_factory = gimp_dialog_factory_from_name ("toplevel");
editor->color_dialog =
gimp_color_dialog_new (GIMP_VIEWABLE (palette),
_("Edit Palette Color"),
GIMP_STOCK_PALETTE,
_("Edit Color Palette Entry"),
GTK_WIDGET (editor),
toplevel_factory,
"gimp-palette-editor-color-dialog",
(const GimpRGB *) &editor->color->color,
FALSE, FALSE);
g_signal_connect (editor->color_dialog, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&editor->color_dialog);
g_signal_connect (editor->color_dialog, "update",
G_CALLBACK (palette_editor_color_dialog_update),
editor);
}
else
{
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (editor->color_dialog),
GIMP_VIEWABLE (palette));
gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (editor->color_dialog),
&editor->color->color);
}
gtk_window_present (GTK_WINDOW (editor->color_dialog));
}
static void
palette_editor_new_clicked (GtkWidget *widget,
GimpPaletteEditor *editor)
{
palette_editor_new_ext_clicked (widget, 0, editor);
}
static void
palette_editor_new_ext_clicked (GtkWidget *widget,
GdkModifierType state,
GimpPaletteEditor *editor)
{
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (editor);
if (data_editor->data && data_editor->data_editable)
{
GimpPalette *palette = GIMP_PALETTE (data_editor->data);
GimpContext *user_context;
GimpRGB color;
user_context = gimp_get_user_context (data_editor->data_factory->gimp);
if (state & GDK_CONTROL_MASK)
gimp_context_get_background (user_context, &color);
else
gimp_context_get_foreground (user_context, &color);
editor->color = gimp_palette_add_entry (palette, NULL, &color);
}
}
static void
palette_editor_delete_clicked (GtkWidget *widget,
GimpPaletteEditor *editor)
{
GimpDataEditor *data_editor = GIMP_DATA_EDITOR (editor);
if (data_editor->data && data_editor->data_editable && editor->color)
{
GimpPalette *palette = GIMP_PALETTE (data_editor->data);
gimp_palette_delete_entry (palette, editor->color);
}
}
static void
palette_editor_zoom_out_clicked (GtkWidget *widget,
GimpPaletteEditor *editor)
{
palette_editor_redraw_zoom (editor, editor->zoom_factor - 0.1);
}
static void
palette_editor_zoom_in_clicked (GtkWidget *widget,
GimpPaletteEditor *editor)
{
palette_editor_redraw_zoom (editor, editor->zoom_factor + 0.1);
}
static void
palette_editor_zoom_all_clicked (GtkWidget *widget,
GimpPaletteEditor *editor)
{
if (GIMP_DATA_EDITOR (editor)->data)
{
GimpPalette *palette;
gint window_height;
gint rows;
gdouble zoom_factor;
palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
window_height =
editor->color_area->parent->parent->parent->allocation.height;
if (palette->n_columns)
rows = palette->n_colors / palette->n_columns;
else
rows = palette->n_colors / COLUMNS;
rows = MAX (1, rows);
zoom_factor =
(((gdouble) window_height - 2 * SPACING) / (gdouble) rows - SPACING) /
ENTRY_HEIGHT;
palette_editor_redraw_zoom (editor, zoom_factor);
}
}
static void
palette_editor_redraw_zoom (GimpPaletteEditor *editor,
gdouble zoom_factor)
{
zoom_factor = CLAMP (zoom_factor, 0.1, 4.0);
if (GIMP_DATA_EDITOR (editor)->data && editor->zoom_factor != zoom_factor)
{
GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
if (palette->n_columns)
editor->columns = palette->n_columns;
else
editor->columns = COLUMNS;
editor->columns_valid = FALSE;
palette_editor_redraw (editor, editor->last_width, zoom_factor);
palette_editor_scroll_top_left (editor);
}
}
/* the palette dialog color dnd callbacks **********************************/
static void
@ -1277,30 +1138,3 @@ palette_editor_viewport_realize (GtkWidget *widget,
editor->columns_valid = FALSE;
palette_editor_redraw (editor, widget->allocation.width, editor->zoom_factor);
}
static void
palette_editor_color_dialog_update (GimpColorDialog *dialog,
const GimpRGB *color,
GimpColorDialogState state,
GimpPaletteEditor *editor)
{
GimpPalette *palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
switch (state)
{
case GIMP_COLOR_DIALOG_UPDATE:
break;
case GIMP_COLOR_DIALOG_OK:
if (editor->color)
{
editor->color->color = *color;
gimp_data_dirty (GIMP_DATA (palette));
}
/* Fallthrough */
case GIMP_COLOR_DIALOG_CANCEL:
gtk_widget_hide (editor->color_dialog);
break;
}
}

View File

@ -76,6 +76,8 @@ GtkWidget * gimp_palette_editor_new (Gimp *gimp,
void gimp_palette_editor_pick_color (GimpPaletteEditor *editor,
const GimpRGB *color,
GimpColorPickState pick_state);
void gimp_palette_editor_zoom (GimpPaletteEditor *editor,
GimpZoomType zoom_type);
#endif /* __GIMP_PALETTE_EDITOR_H__ */