1
/* GIMP - The GNU 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_destroy (GtkObject *object);
48
static void gimp_tool_view_select_item (GimpContainerEditor *editor,
49
GimpViewable *viewable);
50
static void gimp_tool_view_activate_item (GimpContainerEditor *editor,
51
GimpViewable *viewable);
53
static void gimp_tool_view_visible_notify (GimpToolInfo *tool_info,
55
GimpContainerTreeView *tree_view);
56
static void gimp_tool_view_eye_data_func (GtkTreeViewColumn *tree_column,
57
GtkCellRenderer *cell,
58
GtkTreeModel *tree_model,
61
static void gimp_tool_view_eye_clicked (GtkCellRendererToggle *toggle,
63
GdkModifierType state,
64
GimpContainerTreeView *tree_view);
67
G_DEFINE_TYPE (GimpToolView, gimp_tool_view, GIMP_TYPE_CONTAINER_EDITOR)
69
#define parent_class gimp_tool_view_parent_class
73
gimp_tool_view_class_init (GimpToolViewClass *klass)
75
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
76
GimpContainerEditorClass *editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
78
object_class->destroy = gimp_tool_view_destroy;
80
editor_class->select_item = gimp_tool_view_select_item;
81
editor_class->activate_item = gimp_tool_view_activate_item;
85
gimp_tool_view_init (GimpToolView *view)
87
view->visible_handler_id = 0;
88
view->raise_button = NULL;
89
view->lower_button = NULL;
90
view->reset_button = NULL;
94
gimp_tool_view_destroy (GtkObject *object)
96
GimpToolView *tool_view = GIMP_TOOL_VIEW (object);
98
if (tool_view->visible_handler_id)
100
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (tool_view);
101
GimpContainerView *view = GIMP_CONTAINER_VIEW (editor->view);
103
gimp_container_remove_handler (gimp_container_view_get_container (view),
104
tool_view->visible_handler_id);
105
tool_view->visible_handler_id = 0;
108
GTK_OBJECT_CLASS (parent_class)->destroy (object);
112
gimp_tool_view_new (GimpViewType view_type,
113
GimpContainer *container,
114
GimpContext *context,
116
gint view_border_width,
117
GimpMenuFactory *menu_factory)
119
GimpToolView *tool_view;
120
GimpContainerEditor *editor;
122
tool_view = g_object_new (GIMP_TYPE_TOOL_VIEW, NULL);
124
if (! gimp_container_editor_construct (GIMP_CONTAINER_EDITOR (tool_view),
127
view_size, view_border_width,
128
menu_factory, "<Tools>",
131
g_object_unref (tool_view);
135
editor = GIMP_CONTAINER_EDITOR (tool_view);
137
tool_view->raise_button =
138
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
140
"tools-raise-to-top", GDK_SHIFT_MASK,
143
tool_view->lower_button =
144
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
146
"tools-lower-to-bottom", GDK_SHIFT_MASK,
149
tool_view->reset_button =
150
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
151
"tools-reset", NULL);
153
if (view_type == GIMP_VIEW_TYPE_LIST)
155
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (editor->view);
156
GtkWidget *tree_widget = GTK_WIDGET (tree_view);
157
GtkStyle *tree_style = gtk_widget_get_style (tree_widget);
158
GtkTreeViewColumn *column;
159
GtkCellRenderer *eye_cell;
160
GtkIconSize icon_size;
162
column = gtk_tree_view_column_new ();
163
gtk_tree_view_insert_column (tree_view->view, column, 0);
165
eye_cell = gimp_cell_renderer_toggle_new (GIMP_STOCK_VISIBLE);
167
icon_size = gimp_get_icon_size (GTK_WIDGET (tree_view),
169
GTK_ICON_SIZE_BUTTON,
171
2 * tree_style->xthickness,
173
2 * tree_style->ythickness);
174
g_object_set (eye_cell, "stock-size", icon_size, NULL);
176
gtk_tree_view_column_pack_start (column, eye_cell, FALSE);
177
gtk_tree_view_column_set_cell_data_func (column, eye_cell,
178
gimp_tool_view_eye_data_func,
182
tree_view->toggle_cells = g_list_prepend (tree_view->toggle_cells,
185
g_signal_connect (eye_cell, "clicked",
186
G_CALLBACK (gimp_tool_view_eye_clicked),
189
tool_view->visible_handler_id =
190
gimp_container_add_handler (container, "notify::visible",
191
G_CALLBACK (gimp_tool_view_visible_notify),
195
gimp_ui_manager_update (GIMP_EDITOR (editor->view)->ui_manager, editor);
197
return GTK_WIDGET (tool_view);
201
gimp_tool_view_select_item (GimpContainerEditor *editor,
202
GimpViewable *viewable)
204
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item)
205
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item (editor, viewable);
209
gimp_tool_view_activate_item (GimpContainerEditor *editor,
210
GimpViewable *viewable)
212
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
213
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
217
/* "visible" callbaks */
220
gimp_tool_view_visible_notify (GimpToolInfo *tool_info,
222
GimpContainerTreeView *tree_view)
226
iter = gimp_container_view_lookup (GIMP_CONTAINER_VIEW (tree_view),
227
(GimpViewable *) tool_info);
233
path = gtk_tree_model_get_path (tree_view->model, iter);
235
gtk_tree_model_row_changed (tree_view->model, path, iter);
237
gtk_tree_path_free (path);
242
gimp_tool_view_eye_data_func (GtkTreeViewColumn *tree_column,
243
GtkCellRenderer *cell,
244
GtkTreeModel *tree_model,
248
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (data);
249
GimpViewRenderer *renderer;
252
gtk_tree_model_get (tree_model, iter,
253
tree_view->model_column_renderer, &renderer,
256
g_object_get (renderer->viewable, "visible", &visible, NULL);
258
g_object_unref (renderer);
260
g_object_set (cell, "active", visible, NULL);
264
gimp_tool_view_eye_clicked (GtkCellRendererToggle *toggle,
266
GdkModifierType state,
267
GimpContainerTreeView *tree_view)
272
path = gtk_tree_path_new_from_string (path_str);
274
if (gtk_tree_model_get_iter (tree_view->model, &iter, path))
276
GimpViewRenderer *renderer;
279
g_object_get (toggle,
283
gtk_tree_model_get (tree_view->model, &iter,
284
tree_view->model_column_renderer, &renderer,
287
g_object_set (renderer->viewable, "visible", ! active, NULL);
289
g_object_unref (renderer);
292
gtk_tree_path_free (path);