~ubuntu-branches/ubuntu/vivid/gimp/vivid

« back to all changes in this revision

Viewing changes to app/widgets/gimptoolview.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-08 18:50:03 UTC
  • mto: (1.1.26) (0.5.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: package-import@ubuntu.com-20120508185003-tltkvbaysf8d2426
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* GIMP - The GNU 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_destroy        (GtkObject             *object);
47
 
 
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);
52
 
 
53
 
static void   gimp_tool_view_visible_notify (GimpToolInfo          *tool_info,
54
 
                                             GParamSpec            *pspec,
55
 
                                             GimpContainerTreeView *tree_view);
56
 
static void   gimp_tool_view_eye_data_func  (GtkTreeViewColumn     *tree_column,
57
 
                                             GtkCellRenderer       *cell,
58
 
                                             GtkTreeModel          *tree_model,
59
 
                                             GtkTreeIter           *iter,
60
 
                                             gpointer               data);
61
 
static void   gimp_tool_view_eye_clicked    (GtkCellRendererToggle *toggle,
62
 
                                             gchar                 *path_str,
63
 
                                             GdkModifierType        state,
64
 
                                             GimpContainerTreeView *tree_view);
65
 
 
66
 
 
67
 
G_DEFINE_TYPE (GimpToolView, gimp_tool_view, GIMP_TYPE_CONTAINER_EDITOR)
68
 
 
69
 
#define parent_class gimp_tool_view_parent_class
70
 
 
71
 
 
72
 
static void
73
 
gimp_tool_view_class_init (GimpToolViewClass *klass)
74
 
{
75
 
  GtkObjectClass           *object_class = GTK_OBJECT_CLASS (klass);
76
 
  GimpContainerEditorClass *editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
77
 
 
78
 
  object_class->destroy       = gimp_tool_view_destroy;
79
 
 
80
 
  editor_class->select_item   = gimp_tool_view_select_item;
81
 
  editor_class->activate_item = gimp_tool_view_activate_item;
82
 
}
83
 
 
84
 
static void
85
 
gimp_tool_view_init (GimpToolView *view)
86
 
{
87
 
  view->visible_handler_id = 0;
88
 
  view->raise_button       = NULL;
89
 
  view->lower_button       = NULL;
90
 
  view->reset_button       = NULL;
91
 
}
92
 
 
93
 
static void
94
 
gimp_tool_view_destroy (GtkObject *object)
95
 
{
96
 
  GimpToolView *tool_view = GIMP_TOOL_VIEW (object);
97
 
 
98
 
  if (tool_view->visible_handler_id)
99
 
    {
100
 
      GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (tool_view);
101
 
      GimpContainerView   *view   = GIMP_CONTAINER_VIEW (editor->view);
102
 
 
103
 
      gimp_container_remove_handler (gimp_container_view_get_container (view),
104
 
                                     tool_view->visible_handler_id);
105
 
      tool_view->visible_handler_id = 0;
106
 
    }
107
 
 
108
 
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
109
 
}
110
 
 
111
 
GtkWidget *
112
 
gimp_tool_view_new (GimpViewType     view_type,
113
 
                    GimpContainer   *container,
114
 
                    GimpContext     *context,
115
 
                    gint             view_size,
116
 
                    gint             view_border_width,
117
 
                    GimpMenuFactory *menu_factory)
118
 
{
119
 
  GimpToolView        *tool_view;
120
 
  GimpContainerEditor *editor;
121
 
 
122
 
  tool_view = g_object_new (GIMP_TYPE_TOOL_VIEW, NULL);
123
 
 
124
 
  if (! gimp_container_editor_construct (GIMP_CONTAINER_EDITOR (tool_view),
125
 
                                         view_type,
126
 
                                         container, context,
127
 
                                         view_size, view_border_width,
128
 
                                         menu_factory, "<Tools>",
129
 
                                         "/tools-popup"))
130
 
    {
131
 
      g_object_unref (tool_view);
132
 
      return NULL;
133
 
    }
134
 
 
135
 
  editor = GIMP_CONTAINER_EDITOR (tool_view);
136
 
 
137
 
  tool_view->raise_button =
138
 
    gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
139
 
                                   "tools-raise",
140
 
                                   "tools-raise-to-top", GDK_SHIFT_MASK,
141
 
                                   NULL);
142
 
 
143
 
  tool_view->lower_button =
144
 
    gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
145
 
                                   "tools-lower",
146
 
                                   "tools-lower-to-bottom", GDK_SHIFT_MASK,
147
 
                                    NULL);
148
 
 
149
 
  tool_view->reset_button =
150
 
    gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
151
 
                                   "tools-reset", NULL);
152
 
 
153
 
  if (view_type == GIMP_VIEW_TYPE_LIST)
154
 
    {
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;
161
 
 
162
 
      column = gtk_tree_view_column_new ();
163
 
      gtk_tree_view_insert_column (tree_view->view, column, 0);
164
 
 
165
 
      eye_cell = gimp_cell_renderer_toggle_new (GIMP_STOCK_VISIBLE);
166
 
 
167
 
      icon_size = gimp_get_icon_size (GTK_WIDGET (tree_view),
168
 
                                      GIMP_STOCK_VISIBLE,
169
 
                                      GTK_ICON_SIZE_BUTTON,
170
 
                                      view_size -
171
 
                                      2 * tree_style->xthickness,
172
 
                                      view_size -
173
 
                                      2 * tree_style->ythickness);
174
 
      g_object_set (eye_cell, "stock-size", icon_size, NULL);
175
 
 
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,
179
 
                                                tree_view,
180
 
                                                NULL);
181
 
 
182
 
      tree_view->toggle_cells = g_list_prepend (tree_view->toggle_cells,
183
 
                                                eye_cell);
184
 
 
185
 
      g_signal_connect (eye_cell, "clicked",
186
 
                        G_CALLBACK (gimp_tool_view_eye_clicked),
187
 
                        tree_view);
188
 
 
189
 
      tool_view->visible_handler_id =
190
 
        gimp_container_add_handler (container, "notify::visible",
191
 
                                    G_CALLBACK (gimp_tool_view_visible_notify),
192
 
                                    tree_view);
193
 
    }
194
 
 
195
 
  gimp_ui_manager_update (GIMP_EDITOR (editor->view)->ui_manager, editor);
196
 
 
197
 
  return GTK_WIDGET (tool_view);
198
 
}
199
 
 
200
 
static void
201
 
gimp_tool_view_select_item (GimpContainerEditor *editor,
202
 
                            GimpViewable        *viewable)
203
 
{
204
 
  if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item)
205
 
    GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item (editor, viewable);
206
 
}
207
 
 
208
 
static void
209
 
gimp_tool_view_activate_item (GimpContainerEditor *editor,
210
 
                              GimpViewable        *viewable)
211
 
{
212
 
  if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
213
 
    GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
214
 
}
215
 
 
216
 
 
217
 
/*  "visible" callbaks  */
218
 
 
219
 
static void
220
 
gimp_tool_view_visible_notify (GimpToolInfo          *tool_info,
221
 
                               GParamSpec            *pspec,
222
 
                               GimpContainerTreeView *tree_view)
223
 
{
224
 
  GtkTreeIter *iter;
225
 
 
226
 
  iter = gimp_container_view_lookup (GIMP_CONTAINER_VIEW (tree_view),
227
 
                                     (GimpViewable *) tool_info);
228
 
 
229
 
  if (iter)
230
 
    {
231
 
      GtkTreePath *path;
232
 
 
233
 
      path = gtk_tree_model_get_path (tree_view->model, iter);
234
 
 
235
 
      gtk_tree_model_row_changed (tree_view->model, path, iter);
236
 
 
237
 
      gtk_tree_path_free (path);
238
 
    }
239
 
}
240
 
 
241
 
static void
242
 
gimp_tool_view_eye_data_func (GtkTreeViewColumn *tree_column,
243
 
                              GtkCellRenderer   *cell,
244
 
                              GtkTreeModel      *tree_model,
245
 
                              GtkTreeIter       *iter,
246
 
                              gpointer           data)
247
 
{
248
 
  GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (data);
249
 
  GimpViewRenderer      *renderer;
250
 
  gboolean               visible;
251
 
 
252
 
  gtk_tree_model_get (tree_model, iter,
253
 
                      tree_view->model_column_renderer, &renderer,
254
 
                      -1);
255
 
 
256
 
  g_object_get (renderer->viewable, "visible", &visible, NULL);
257
 
 
258
 
  g_object_unref (renderer);
259
 
 
260
 
  g_object_set (cell, "active", visible, NULL);
261
 
}
262
 
 
263
 
static void
264
 
gimp_tool_view_eye_clicked (GtkCellRendererToggle *toggle,
265
 
                            gchar                 *path_str,
266
 
                            GdkModifierType        state,
267
 
                            GimpContainerTreeView *tree_view)
268
 
{
269
 
  GtkTreePath *path;
270
 
  GtkTreeIter  iter;
271
 
 
272
 
  path = gtk_tree_path_new_from_string (path_str);
273
 
 
274
 
  if (gtk_tree_model_get_iter (tree_view->model, &iter, path))
275
 
    {
276
 
      GimpViewRenderer *renderer;
277
 
      gboolean          active;
278
 
 
279
 
      g_object_get (toggle,
280
 
                    "active", &active,
281
 
                    NULL);
282
 
 
283
 
      gtk_tree_model_get (tree_view->model, &iter,
284
 
                          tree_view->model_column_renderer, &renderer,
285
 
                          -1);
286
 
 
287
 
      g_object_set (renderer->viewable, "visible", ! active, NULL);
288
 
 
289
 
      g_object_unref (renderer);
290
 
    }
291
 
 
292
 
  gtk_tree_path_free (path);
293
 
}