1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2001-2004 Michael Natterer <mitch@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include "libgimpwidgets/gimpwidgets.h"
28
#include "widgets-types.h"
30
#include "core/gimp.h"
31
#include "core/gimpcontainer.h"
32
#include "core/gimpcontext.h"
33
#include "core/gimptoolinfo.h"
35
#include "gimpcontainertreeview.h"
36
#include "gimpcontainerview.h"
37
#include "gimpviewrenderer.h"
38
#include "gimptoolview.h"
39
#include "gimphelp-ids.h"
40
#include "gimpuimanager.h"
41
#include "gimpwidgets-utils.h"
43
#include "gimp-intl.h"
46
static void gimp_tool_view_class_init (GimpToolViewClass *klass);
47
static void gimp_tool_view_init (GimpToolView *view);
49
static void gimp_tool_view_destroy (GtkObject *object);
51
static void gimp_tool_view_select_item (GimpContainerEditor *editor,
52
GimpViewable *viewable);
53
static void gimp_tool_view_activate_item (GimpContainerEditor *editor,
54
GimpViewable *viewable);
56
static void gimp_tool_view_visible_notify (GimpToolInfo *tool_info,
58
GimpContainerTreeView *tree_view);
59
static void gimp_tool_view_eye_data_func (GtkTreeViewColumn *tree_column,
60
GtkCellRenderer *cell,
61
GtkTreeModel *tree_model,
64
static void gimp_tool_view_eye_clicked (GtkCellRendererToggle *toggle,
66
GdkModifierType state,
67
GimpContainerTreeView *tree_view);
70
static GimpContainerEditorClass *parent_class = NULL;
74
gimp_tool_view_get_type (void)
76
static GType view_type = 0;
80
static const GTypeInfo view_info =
82
sizeof (GimpToolViewClass),
84
NULL, /* base_finalize */
85
(GClassInitFunc) gimp_tool_view_class_init,
86
NULL, /* class_finalize */
87
NULL, /* class_data */
88
sizeof (GimpToolView),
90
(GInstanceInitFunc) gimp_tool_view_init,
93
view_type = g_type_register_static (GIMP_TYPE_CONTAINER_EDITOR,
102
gimp_tool_view_class_init (GimpToolViewClass *klass)
104
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
105
GimpContainerEditorClass *editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
107
parent_class = g_type_class_peek_parent (klass);
109
object_class->destroy = gimp_tool_view_destroy;
111
editor_class->select_item = gimp_tool_view_select_item;
112
editor_class->activate_item = gimp_tool_view_activate_item;
116
gimp_tool_view_init (GimpToolView *view)
118
view->visible_handler_id = 0;
119
view->reset_button = NULL;
123
gimp_tool_view_destroy (GtkObject *object)
125
GimpToolView *tool_view = GIMP_TOOL_VIEW (object);
127
if (tool_view->visible_handler_id)
129
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (tool_view);
130
GimpContainerView *view = GIMP_CONTAINER_VIEW (editor->view);
132
gimp_container_remove_handler (gimp_container_view_get_container (view),
133
tool_view->visible_handler_id);
134
tool_view->visible_handler_id = 0;
137
GTK_OBJECT_CLASS (parent_class)->destroy (object);
141
gimp_tool_view_new (GimpViewType view_type,
142
GimpContainer *container,
143
GimpContext *context,
145
gint preview_border_width,
146
GimpMenuFactory *menu_factory)
148
GimpToolView *tool_view;
149
GimpContainerEditor *editor;
151
tool_view = g_object_new (GIMP_TYPE_TOOL_VIEW, NULL);
153
if (! gimp_container_editor_construct (GIMP_CONTAINER_EDITOR (tool_view),
156
preview_size, preview_border_width,
157
menu_factory, "<Tools>",
160
g_object_unref (tool_view);
164
editor = GIMP_CONTAINER_EDITOR (tool_view);
166
tool_view->reset_button =
167
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
168
"tools-reset", NULL);
170
if (view_type == GIMP_VIEW_TYPE_LIST)
172
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (editor->view);
173
GtkWidget *tree_widget = GTK_WIDGET (tree_view);
174
GtkTreeViewColumn *column;
175
GtkCellRenderer *eye_cell;
176
GtkIconSize icon_size;
178
column = gtk_tree_view_column_new ();
179
gtk_tree_view_insert_column (tree_view->view, column, 0);
181
eye_cell = gimp_cell_renderer_toggle_new (GIMP_STOCK_VISIBLE);
183
icon_size = gimp_get_icon_size (GTK_WIDGET (tree_view),
185
GTK_ICON_SIZE_BUTTON,
187
2 * tree_widget->style->xthickness,
189
2 * tree_widget->style->ythickness);
190
g_object_set (eye_cell, "stock-size", icon_size, NULL);
192
gtk_tree_view_column_pack_start (column, eye_cell, FALSE);
193
gtk_tree_view_column_set_cell_data_func (column, eye_cell,
194
gimp_tool_view_eye_data_func,
198
tree_view->toggle_cells = g_list_prepend (tree_view->toggle_cells,
201
g_signal_connect (eye_cell, "clicked",
202
G_CALLBACK (gimp_tool_view_eye_clicked),
205
tool_view->visible_handler_id =
206
gimp_container_add_handler (container, "notify::visible",
207
G_CALLBACK (gimp_tool_view_visible_notify),
211
gimp_ui_manager_update (GIMP_EDITOR (editor->view)->ui_manager, editor);
213
return GTK_WIDGET (tool_view);
217
gimp_tool_view_select_item (GimpContainerEditor *editor,
218
GimpViewable *viewable)
220
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item)
221
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item (editor, viewable);
225
gimp_tool_view_activate_item (GimpContainerEditor *editor,
226
GimpViewable *viewable)
228
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
229
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
233
/* "visible" callbaks */
236
gimp_tool_view_visible_notify (GimpToolInfo *tool_info,
238
GimpContainerTreeView *tree_view)
242
iter = gimp_container_view_lookup (GIMP_CONTAINER_VIEW (tree_view),
243
(GimpViewable *) tool_info);
249
path = gtk_tree_model_get_path (tree_view->model, iter);
251
gtk_tree_model_row_changed (tree_view->model, path, iter);
253
gtk_tree_path_free (path);
258
gimp_tool_view_eye_data_func (GtkTreeViewColumn *tree_column,
259
GtkCellRenderer *cell,
260
GtkTreeModel *tree_model,
264
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (data);
265
GimpViewRenderer *renderer;
268
gtk_tree_model_get (tree_model, iter,
269
tree_view->model_column_renderer, &renderer,
272
g_object_get (renderer->viewable, "visible", &visible, NULL);
274
g_object_unref (renderer);
276
g_object_set (cell, "active", visible, NULL);
280
gimp_tool_view_eye_clicked (GtkCellRendererToggle *toggle,
282
GdkModifierType state,
283
GimpContainerTreeView *tree_view)
288
path = gtk_tree_path_new_from_string (path_str);
290
if (gtk_tree_model_get_iter (tree_view->model, &iter, path))
292
GimpViewRenderer *renderer;
295
g_object_get (toggle,
299
gtk_tree_model_get (tree_view->model, &iter,
300
tree_view->model_column_renderer, &renderer,
303
g_object_set (renderer->viewable, "visible", ! active, NULL);
305
g_object_unref (renderer);