~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/widgets/gimptoolview.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimptoolview.c
 
5
 * Copyright (C) 2001-2004 Michael Natterer <mitch@gimp.org>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#include "libgimpwidgets/gimpwidgets.h"
 
27
 
 
28
#include "widgets-types.h"
 
29
 
 
30
#include "core/gimp.h"
 
31
#include "core/gimpcontainer.h"
 
32
#include "core/gimpcontext.h"
 
33
#include "core/gimptoolinfo.h"
 
34
 
 
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"
 
42
 
 
43
#include "gimp-intl.h"
 
44
 
 
45
 
 
46
static void   gimp_tool_view_class_init     (GimpToolViewClass     *klass);
 
47
static void   gimp_tool_view_init           (GimpToolView          *view);
 
48
 
 
49
static void   gimp_tool_view_destroy        (GtkObject             *object);
 
50
 
 
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);
 
55
 
 
56
static void   gimp_tool_view_visible_notify (GimpToolInfo          *tool_info,
 
57
                                             GParamSpec            *pspec,
 
58
                                             GimpContainerTreeView *tree_view);
 
59
static void   gimp_tool_view_eye_data_func  (GtkTreeViewColumn     *tree_column,
 
60
                                             GtkCellRenderer       *cell,
 
61
                                             GtkTreeModel          *tree_model,
 
62
                                             GtkTreeIter           *iter,
 
63
                                             gpointer               data);
 
64
static void   gimp_tool_view_eye_clicked    (GtkCellRendererToggle *toggle,
 
65
                                             gchar                 *path_str,
 
66
                                             GdkModifierType        state,
 
67
                                             GimpContainerTreeView *tree_view);
 
68
 
 
69
 
 
70
static GimpContainerEditorClass *parent_class = NULL;
 
71
 
 
72
 
 
73
GType
 
74
gimp_tool_view_get_type (void)
 
75
{
 
76
  static GType view_type = 0;
 
77
 
 
78
  if (! view_type)
 
79
    {
 
80
      static const GTypeInfo view_info =
 
81
      {
 
82
        sizeof (GimpToolViewClass),
 
83
        NULL,           /* base_init */
 
84
        NULL,           /* base_finalize */
 
85
        (GClassInitFunc) gimp_tool_view_class_init,
 
86
        NULL,           /* class_finalize */
 
87
        NULL,           /* class_data */
 
88
        sizeof (GimpToolView),
 
89
        0,              /* n_preallocs */
 
90
        (GInstanceInitFunc) gimp_tool_view_init,
 
91
      };
 
92
 
 
93
      view_type = g_type_register_static (GIMP_TYPE_CONTAINER_EDITOR,
 
94
                                          "GimpToolView",
 
95
                                          &view_info, 0);
 
96
    }
 
97
 
 
98
  return view_type;
 
99
}
 
100
 
 
101
static void
 
102
gimp_tool_view_class_init (GimpToolViewClass *klass)
 
103
{
 
104
  GtkObjectClass           *object_class = GTK_OBJECT_CLASS (klass);
 
105
  GimpContainerEditorClass *editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
 
106
 
 
107
  parent_class = g_type_class_peek_parent (klass);
 
108
 
 
109
  object_class->destroy       = gimp_tool_view_destroy;
 
110
 
 
111
  editor_class->select_item   = gimp_tool_view_select_item;
 
112
  editor_class->activate_item = gimp_tool_view_activate_item;
 
113
}
 
114
 
 
115
static void
 
116
gimp_tool_view_init (GimpToolView *view)
 
117
{
 
118
  view->visible_handler_id = 0;
 
119
  view->reset_button       = NULL;
 
120
}
 
121
 
 
122
static void
 
123
gimp_tool_view_destroy (GtkObject *object)
 
124
{
 
125
  GimpToolView *tool_view = GIMP_TOOL_VIEW (object);
 
126
 
 
127
  if (tool_view->visible_handler_id)
 
128
    {
 
129
      GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (tool_view);
 
130
      GimpContainerView   *view   = GIMP_CONTAINER_VIEW (editor->view);
 
131
 
 
132
      gimp_container_remove_handler (gimp_container_view_get_container (view),
 
133
                                     tool_view->visible_handler_id);
 
134
      tool_view->visible_handler_id = 0;
 
135
    }
 
136
 
 
137
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
 
138
}
 
139
 
 
140
GtkWidget *
 
141
gimp_tool_view_new (GimpViewType     view_type,
 
142
                    GimpContainer   *container,
 
143
                    GimpContext     *context,
 
144
                    gint             preview_size,
 
145
                    gint             preview_border_width,
 
146
                    GimpMenuFactory *menu_factory)
 
147
{
 
148
  GimpToolView        *tool_view;
 
149
  GimpContainerEditor *editor;
 
150
 
 
151
  tool_view = g_object_new (GIMP_TYPE_TOOL_VIEW, NULL);
 
152
 
 
153
  if (! gimp_container_editor_construct (GIMP_CONTAINER_EDITOR (tool_view),
 
154
                                         view_type,
 
155
                                         container, context,
 
156
                                         preview_size, preview_border_width,
 
157
                                         menu_factory, "<Tools>",
 
158
                                         "/tools-popup"))
 
159
    {
 
160
      g_object_unref (tool_view);
 
161
      return NULL;
 
162
    }
 
163
 
 
164
  editor = GIMP_CONTAINER_EDITOR (tool_view);
 
165
 
 
166
  tool_view->reset_button =
 
167
    gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
 
168
                                   "tools-reset", NULL);
 
169
 
 
170
  if (view_type == GIMP_VIEW_TYPE_LIST)
 
171
    {
 
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;
 
177
 
 
178
      column = gtk_tree_view_column_new ();
 
179
      gtk_tree_view_insert_column (tree_view->view, column, 0);
 
180
 
 
181
      eye_cell = gimp_cell_renderer_toggle_new (GIMP_STOCK_VISIBLE);
 
182
 
 
183
      icon_size = gimp_get_icon_size (GTK_WIDGET (tree_view),
 
184
                                      GIMP_STOCK_VISIBLE,
 
185
                                      GTK_ICON_SIZE_BUTTON,
 
186
                                      preview_size -
 
187
                                      2 * tree_widget->style->xthickness,
 
188
                                      preview_size -
 
189
                                      2 * tree_widget->style->ythickness);
 
190
      g_object_set (eye_cell, "stock-size", icon_size, NULL);
 
191
 
 
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,
 
195
                                                tree_view,
 
196
                                                NULL);
 
197
 
 
198
      tree_view->toggle_cells = g_list_prepend (tree_view->toggle_cells,
 
199
                                                eye_cell);
 
200
 
 
201
      g_signal_connect (eye_cell, "clicked",
 
202
                        G_CALLBACK (gimp_tool_view_eye_clicked),
 
203
                        tree_view);
 
204
 
 
205
      tool_view->visible_handler_id =
 
206
        gimp_container_add_handler (container, "notify::visible",
 
207
                                    G_CALLBACK (gimp_tool_view_visible_notify),
 
208
                                    tree_view);
 
209
    }
 
210
 
 
211
  gimp_ui_manager_update (GIMP_EDITOR (editor->view)->ui_manager, editor);
 
212
 
 
213
  return GTK_WIDGET (tool_view);
 
214
}
 
215
 
 
216
static void
 
217
gimp_tool_view_select_item (GimpContainerEditor *editor,
 
218
                            GimpViewable        *viewable)
 
219
{
 
220
  if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item)
 
221
    GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item (editor, viewable);
 
222
}
 
223
 
 
224
static void
 
225
gimp_tool_view_activate_item (GimpContainerEditor *editor,
 
226
                              GimpViewable        *viewable)
 
227
{
 
228
  if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
 
229
    GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
 
230
}
 
231
 
 
232
 
 
233
/*  "visible" callbaks  */
 
234
 
 
235
static void
 
236
gimp_tool_view_visible_notify (GimpToolInfo          *tool_info,
 
237
                               GParamSpec            *pspec,
 
238
                               GimpContainerTreeView *tree_view)
 
239
{
 
240
  GtkTreeIter *iter;
 
241
 
 
242
  iter = gimp_container_view_lookup (GIMP_CONTAINER_VIEW (tree_view),
 
243
                                     (GimpViewable *) tool_info);
 
244
 
 
245
  if (iter)
 
246
    {
 
247
      GtkTreePath *path;
 
248
 
 
249
      path = gtk_tree_model_get_path (tree_view->model, iter);
 
250
 
 
251
      gtk_tree_model_row_changed (tree_view->model, path, iter);
 
252
 
 
253
      gtk_tree_path_free (path);
 
254
    }
 
255
}
 
256
 
 
257
static void
 
258
gimp_tool_view_eye_data_func (GtkTreeViewColumn *tree_column,
 
259
                              GtkCellRenderer   *cell,
 
260
                              GtkTreeModel      *tree_model,
 
261
                              GtkTreeIter       *iter,
 
262
                              gpointer           data)
 
263
{
 
264
  GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (data);
 
265
  GimpViewRenderer      *renderer;
 
266
  gboolean               visible;
 
267
 
 
268
  gtk_tree_model_get (tree_model, iter,
 
269
                      tree_view->model_column_renderer, &renderer,
 
270
                      -1);
 
271
 
 
272
  g_object_get (renderer->viewable, "visible", &visible, NULL);
 
273
 
 
274
  g_object_unref (renderer);
 
275
 
 
276
  g_object_set (cell, "active", visible, NULL);
 
277
}
 
278
 
 
279
static void
 
280
gimp_tool_view_eye_clicked (GtkCellRendererToggle *toggle,
 
281
                            gchar                 *path_str,
 
282
                            GdkModifierType        state,
 
283
                            GimpContainerTreeView *tree_view)
 
284
{
 
285
  GtkTreePath *path;
 
286
  GtkTreeIter  iter;
 
287
 
 
288
  path = gtk_tree_path_new_from_string (path_str);
 
289
 
 
290
  if (gtk_tree_model_get_iter (tree_view->model, &iter, path))
 
291
    {
 
292
      GimpViewRenderer *renderer;
 
293
      gboolean          active;
 
294
 
 
295
      g_object_get (toggle,
 
296
                    "active", &active,
 
297
                    NULL);
 
298
 
 
299
      gtk_tree_model_get (tree_view->model, &iter,
 
300
                          tree_view->model_column_renderer, &renderer,
 
301
                          -1);
 
302
 
 
303
      g_object_set (renderer->viewable, "visible", ! active, NULL);
 
304
 
 
305
      g_object_unref (renderer);
 
306
    }
 
307
}