~ubuntu-branches/ubuntu/quantal/gimp/quantal-updates

« back to all changes in this revision

Viewing changes to app/widgets/gimpsessioninfo-dock.c

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-05-20 19:21:01 UTC
  • mfrom: (1.1.26) (0.4.16 sid)
  • Revision ID: package-import@ubuntu.com-20120520192101-bs7zetx8ffoq2nfv
Tags: 2.8.0-2ubuntu1
* Merge from Debian unstable (LP: #908472). Remaining Changes:
  - debian/patches/02_help-message.patch,
    debian/patches/03_gimp.desktop.in.in.patch:
    + Update some strings for Ubuntu
  - debian/control:
    + Update description
  - debian/rules:
    + Set gettext domain and update translation templates
* Drop the following patches that were applied upstream:
  - debian/patches/ghost-cursor.patch: fix Wacom tablet cursor events
  - debian/patches/embed-page-setup-dialog.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * gimpsessioninfo-dock.c
5
5
 * Copyright (C) 2001-2007 Michael Natterer <mitch@gimp.org>
6
6
 *
7
 
 * This program is free software; you can redistribute it and/or modify
 
7
 * This program is free software: you can redistribute it and/or modify
8
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
 
9
 * the Free Software Foundation; either version 3 of the License, or
10
10
 * (at your option) any later version.
11
11
 *
12
12
 * This program is distributed in the hope that it will be useful,
15
15
 * GNU General Public License for more details.
16
16
 *
17
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.
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
19
 */
21
20
 
22
21
#include "config.h"
23
22
 
 
23
#include <string.h>
 
24
 
24
25
#include <gtk/gtk.h>
25
26
 
26
27
#include "libgimpconfig/gimpconfig.h"
29
30
 
30
31
#include "gimpdialogfactory.h"
31
32
#include "gimpdock.h"
 
33
#include "gimpdockbook.h"
 
34
#include "gimpdockcontainer.h"
 
35
#include "gimpdockwindow.h"
32
36
#include "gimpsessioninfo.h"
33
37
#include "gimpsessioninfo-aux.h"
34
38
#include "gimpsessioninfo-book.h"
35
39
#include "gimpsessioninfo-dock.h"
 
40
#include "gimpsessioninfo-private.h"
 
41
#include "gimptoolbox.h"
 
42
#include "gimpwidgets-utils.h"
36
43
 
37
44
 
38
45
enum
39
46
{
 
47
  SESSION_INFO_SIDE,
 
48
  SESSION_INFO_POSITION,
40
49
  SESSION_INFO_BOOK
41
50
};
42
51
 
43
52
 
 
53
static GimpAlignmentType gimp_session_info_dock_get_side (GimpDock *dock);
 
54
 
 
55
 
 
56
static GimpAlignmentType
 
57
gimp_session_info_dock_get_side (GimpDock *dock)
 
58
{
 
59
  GimpAlignmentType result   = -1;
 
60
  GtkWidget        *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (dock));
 
61
 
 
62
  if (GIMP_IS_DOCK_CONTAINER (toplevel))
 
63
    {
 
64
      GimpDockContainer *container = GIMP_DOCK_CONTAINER (toplevel);
 
65
 
 
66
      result = gimp_dock_container_get_dock_side (container, dock);
 
67
    }
 
68
 
 
69
  return result;
 
70
}
 
71
 
 
72
 
44
73
/*  public functions  */
45
74
 
46
 
void
47
 
gimp_session_info_dock_serialize (GimpConfigWriter *writer,
48
 
                                  GList            *books)
 
75
GimpSessionInfoDock *
 
76
gimp_session_info_dock_new (const gchar *dock_type)
 
77
{
 
78
  GimpSessionInfoDock *dock_info = NULL;
 
79
 
 
80
  dock_info = g_slice_new0 (GimpSessionInfoDock);
 
81
  dock_info->dock_type = g_strdup (dock_type);
 
82
  dock_info->side      = -1;
 
83
 
 
84
  return dock_info;
 
85
}
 
86
 
 
87
void
 
88
gimp_session_info_dock_free (GimpSessionInfoDock *dock_info)
 
89
{
 
90
  g_return_if_fail (dock_info != NULL);
 
91
 
 
92
  if (dock_info->dock_type)
 
93
    {
 
94
      g_free (dock_info->dock_type);
 
95
      dock_info->dock_type = NULL;
 
96
    }
 
97
 
 
98
  if (dock_info->books)
 
99
    {
 
100
      g_list_free_full (dock_info->books,
 
101
                        (GDestroyNotify) gimp_session_info_book_free);
 
102
      dock_info->books = NULL;
 
103
    }
 
104
 
 
105
  g_slice_free (GimpSessionInfoDock, dock_info);
 
106
}
 
107
 
 
108
void
 
109
gimp_session_info_dock_serialize (GimpConfigWriter    *writer,
 
110
                                  GimpSessionInfoDock *dock_info)
49
111
{
50
112
  GList *list;
51
113
 
52
114
  g_return_if_fail (writer != NULL);
53
 
  g_return_if_fail (books != NULL);
54
 
 
55
 
  gimp_config_writer_open (writer, "dock");
56
 
 
57
 
  for (list = books; list; list = g_list_next (list))
 
115
  g_return_if_fail (dock_info != NULL);
 
116
 
 
117
  gimp_config_writer_open (writer, dock_info->dock_type);
 
118
 
 
119
  if (dock_info->side != -1)
 
120
    {
 
121
      const char *side_text =
 
122
        dock_info->side == GIMP_ALIGN_LEFT ? "left" : "right";
 
123
      
 
124
      gimp_config_writer_open (writer, "side");
 
125
      gimp_config_writer_print (writer, side_text, strlen (side_text));
 
126
      gimp_config_writer_close (writer);
 
127
    }
 
128
 
 
129
  if (dock_info->position != 0)
 
130
    gimp_session_write_position (writer, dock_info->position);
 
131
 
 
132
  for (list = dock_info->books; list; list = g_list_next (list))
58
133
    gimp_session_info_book_serialize (writer, list->data);
59
134
 
60
135
  gimp_config_writer_close (writer);
61
136
}
62
137
 
63
138
GTokenType
64
 
gimp_session_info_dock_deserialize (GScanner        *scanner,
65
 
                                    gint             scope,
66
 
                                    GimpSessionInfo *info)
 
139
gimp_session_info_dock_deserialize (GScanner             *scanner,
 
140
                                    gint                  scope,
 
141
                                    GimpSessionInfoDock **dock_info,
 
142
                                    const gchar          *dock_type)
67
143
{
68
144
  GTokenType token;
69
145
 
70
146
  g_return_val_if_fail (scanner != NULL, G_TOKEN_LEFT_PAREN);
71
 
  g_return_val_if_fail (info != NULL, G_TOKEN_LEFT_PAREN);
 
147
  g_return_val_if_fail (dock_info != NULL, G_TOKEN_LEFT_PAREN);
72
148
 
 
149
  g_scanner_scope_add_symbol (scanner, scope, "side",
 
150
                              GINT_TO_POINTER (SESSION_INFO_SIDE));
 
151
  g_scanner_scope_add_symbol (scanner, scope, "position",
 
152
                              GINT_TO_POINTER (SESSION_INFO_POSITION));
73
153
  g_scanner_scope_add_symbol (scanner, scope, "book",
74
154
                              GINT_TO_POINTER (SESSION_INFO_BOOK));
75
155
 
 
156
  *dock_info = gimp_session_info_dock_new (dock_type);
 
157
 
76
158
  token = G_TOKEN_LEFT_PAREN;
77
159
 
78
160
  while (g_scanner_peek_next_token (scanner) == token)
90
172
            {
91
173
              GimpSessionInfoBook *book;
92
174
 
 
175
            case SESSION_INFO_SIDE:
 
176
              token = G_TOKEN_IDENTIFIER;
 
177
              if (g_scanner_peek_next_token (scanner) != token)
 
178
                break;
 
179
 
 
180
              g_scanner_get_next_token (scanner);
 
181
 
 
182
              if (strcmp ("left", scanner->value.v_identifier) == 0)
 
183
                (*dock_info)->side = GIMP_ALIGN_LEFT;
 
184
              else
 
185
                (*dock_info)->side = GIMP_ALIGN_RIGHT;
 
186
              break;
 
187
 
 
188
            case SESSION_INFO_POSITION:
 
189
              token = G_TOKEN_INT;
 
190
              if (! gimp_scanner_parse_int (scanner, &((*dock_info)->position)))
 
191
                (*dock_info)->position = 0;
 
192
              break;
 
193
 
93
194
            case SESSION_INFO_BOOK:
94
195
              g_scanner_set_scope (scanner, scope + 1);
95
196
              token = gimp_session_info_book_deserialize (scanner, scope + 1,
97
198
 
98
199
              if (token == G_TOKEN_LEFT_PAREN)
99
200
                {
100
 
                  info->books = g_list_append (info->books, book);
 
201
                  (*dock_info)->books = g_list_append ((*dock_info)->books, book);
101
202
                  g_scanner_set_scope (scanner, scope);
102
203
                }
103
204
              else
121
222
    }
122
223
 
123
224
  g_scanner_scope_remove_symbol (scanner, scope, "book");
 
225
  g_scanner_scope_remove_symbol (scanner, scope, "position");
 
226
  g_scanner_scope_remove_symbol (scanner, scope, "side");
124
227
 
125
228
  return token;
126
229
}
127
230
 
128
 
GList *
 
231
GimpSessionInfoDock *
129
232
gimp_session_info_dock_from_widget (GimpDock *dock)
130
233
{
131
 
  GList *list;
132
 
  GList *infos = NULL;
 
234
  GimpSessionInfoDock *dock_info;
 
235
  GList               *list;
 
236
  GtkWidget           *parent;
133
237
 
134
238
  g_return_val_if_fail (GIMP_IS_DOCK (dock), NULL);
135
239
 
136
 
  for (list = dock->dockbooks; list; list = g_list_next (list))
 
240
  dock_info = gimp_session_info_dock_new (GIMP_IS_TOOLBOX (dock) ?
 
241
                                          "gimp-toolbox" :
 
242
                                          "gimp-dock");
 
243
 
 
244
  for (list = gimp_dock_get_dockbooks (dock); list; list = g_list_next (list))
137
245
    {
138
246
      GimpSessionInfoBook *book;
139
247
 
140
248
      book = gimp_session_info_book_from_widget (list->data);
141
249
 
142
 
      infos = g_list_prepend (infos, book);
143
 
    }
144
 
 
145
 
  return g_list_reverse (infos);
146
 
}
147
 
 
148
 
static void
149
 
gimp_session_info_dock_paned_size_allocate (GtkWidget     *paned,
150
 
                                            GtkAllocation *allocation,
151
 
                                            gpointer       data)
152
 
{
153
 
  g_signal_handlers_disconnect_by_func (paned,
154
 
                                        gimp_session_info_dock_paned_size_allocate,
155
 
                                        data);
156
 
 
157
 
  gtk_paned_set_position (GTK_PANED (paned), GPOINTER_TO_INT (data));
158
 
}
159
 
 
160
 
static void
161
 
gimp_session_info_dock_paned_map (GtkWidget *paned,
162
 
                                  gpointer   data)
163
 
{
164
 
  g_signal_handlers_disconnect_by_func (paned,
165
 
                                        gimp_session_info_dock_paned_map,
166
 
                                        data);
167
 
 
168
 
  g_signal_connect_after (paned, "size-allocate",
169
 
                          G_CALLBACK (gimp_session_info_dock_paned_size_allocate),
170
 
                          data);
171
 
}
172
 
 
173
 
void
174
 
gimp_session_info_dock_restore (GimpSessionInfo   *info,
175
 
                                GimpDialogFactory *factory,
176
 
                                GdkScreen         *screen)
177
 
{
178
 
  GimpDock *dock;
179
 
  GList    *books;
180
 
 
181
 
  g_return_if_fail (info != NULL);
182
 
  g_return_if_fail (GIMP_IS_DIALOG_FACTORY (factory));
183
 
  g_return_if_fail (GDK_IS_SCREEN (screen));
184
 
 
185
 
  dock = GIMP_DOCK (gimp_dialog_factory_dock_new (factory, screen));
186
 
 
187
 
  if (dock && info->aux_info)
188
 
    gimp_session_info_aux_set_list (GTK_WIDGET (dock), info->aux_info);
189
 
 
190
 
  for (books = info->books; books; books = g_list_next (books))
191
 
    {
192
 
      GimpSessionInfoBook *book_info = books->data;
 
250
      dock_info->books = g_list_prepend (dock_info->books, book);
 
251
    }
 
252
 
 
253
  dock_info->books = g_list_reverse (dock_info->books);
 
254
  dock_info->side  = gimp_session_info_dock_get_side (dock);
 
255
 
 
256
  parent = gtk_widget_get_parent (GTK_WIDGET (dock));
 
257
 
 
258
  if (GTK_IS_PANED (parent))
 
259
    {
 
260
      GtkPaned *paned = GTK_PANED (parent);
 
261
 
 
262
      if (GTK_WIDGET (dock) == gtk_paned_get_child2 (paned))
 
263
        dock_info->position = gtk_paned_get_position (paned);
 
264
    }
 
265
 
 
266
  return dock_info;
 
267
}
 
268
 
 
269
GimpDock *
 
270
gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
 
271
                                GimpDialogFactory   *factory,
 
272
                                GdkScreen           *screen,
 
273
                                GimpDockContainer   *dock_container)
 
274
{
 
275
  gint           n_books = 0;
 
276
  GtkWidget     *dock;
 
277
  GList         *iter;
 
278
  GimpUIManager *ui_manager;
 
279
 
 
280
  g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (factory), NULL);
 
281
  g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
 
282
 
 
283
  ui_manager = gimp_dock_container_get_ui_manager (dock_container);
 
284
  dock       = gimp_dialog_factory_dialog_new (factory,
 
285
                                               screen,
 
286
                                               ui_manager,
 
287
                                               dock_info->dock_type,
 
288
                                               -1 /*view_size*/,
 
289
                                               FALSE /*present*/);
 
290
 
 
291
  g_return_val_if_fail (GIMP_IS_DOCK (dock), NULL);
 
292
 
 
293
  /* Add the dock to the dock window immediately so the stuff in the
 
294
   * dock has access to e.g. a dialog factory
 
295
   */
 
296
  gimp_dock_container_add_dock (dock_container,
 
297
                                GIMP_DOCK (dock),
 
298
                                dock_info);
 
299
 
 
300
  /* Note that if it is a toolbox, we will get here even though we
 
301
   * don't have any books
 
302
   */
 
303
  for (iter = dock_info ? dock_info->books : NULL;
 
304
       iter;
 
305
       iter = g_list_next (iter))
 
306
    {
 
307
      GimpSessionInfoBook *book_info = iter->data;
193
308
      GtkWidget           *dockbook;
194
 
      GtkWidget           *parent;
195
 
 
196
 
      dockbook = GTK_WIDGET (gimp_session_info_book_restore (book_info, dock));
197
 
 
198
 
      parent = gtk_widget_get_parent (dockbook);
199
 
 
200
 
      if (GTK_IS_VPANED (parent))
201
 
        {
202
 
          GtkPaned *paned = GTK_PANED (parent);
203
 
 
204
 
          if (dockbook == gtk_paned_get_child2 (paned))
205
 
            g_signal_connect_after (paned, "map",
206
 
                                    G_CALLBACK (gimp_session_info_dock_paned_map),
207
 
                                    GINT_TO_POINTER (book_info->position));
208
 
        }
209
 
    }
210
 
 
211
 
  gtk_widget_show (GTK_WIDGET (dock));
 
309
 
 
310
      dockbook = GTK_WIDGET (gimp_session_info_book_restore (book_info,
 
311
                                                             GIMP_DOCK (dock)));
 
312
 
 
313
      if (dockbook)
 
314
        {
 
315
          GtkWidget *parent = gtk_widget_get_parent (dockbook);
 
316
 
 
317
          n_books++;
 
318
 
 
319
          if (GTK_IS_PANED (parent))
 
320
            {
 
321
              GtkPaned *paned = GTK_PANED (parent);
 
322
 
 
323
              if (dockbook == gtk_paned_get_child2 (paned))
 
324
                gtk_paned_set_position (paned, book_info->position);
 
325
            }
 
326
        }
 
327
    }
 
328
 
 
329
  /* Now remove empty dockbooks from the list, check the comment in
 
330
   * gimp_session_info_book_restore() which explains why the dock
 
331
   * can contain empty dockbooks at all
 
332
   */
 
333
  if (dock_info && dock_info->books)
 
334
    {
 
335
      GList *books;
 
336
 
 
337
      books = g_list_copy (gimp_dock_get_dockbooks (GIMP_DOCK (dock)));
 
338
 
 
339
      while (books)
 
340
        {
 
341
          GtkContainer *dockbook = books->data;
 
342
          GList        *children = gtk_container_get_children (dockbook);
 
343
 
 
344
          if (children)
 
345
            {
 
346
              g_list_free (children);
 
347
            }
 
348
          else
 
349
            {
 
350
              g_object_ref (dockbook);
 
351
              gimp_dock_remove_book (GIMP_DOCK (dock), GIMP_DOCKBOOK (dockbook));
 
352
              gtk_widget_destroy (GTK_WIDGET (dockbook));
 
353
              g_object_unref (dockbook);
 
354
 
 
355
              n_books--;
 
356
            }
 
357
 
 
358
          books = g_list_remove (books, dockbook);
 
359
        }
 
360
    }
 
361
 
 
362
  /*  if we removed all books again, the dock was destroyed, so bail out  */
 
363
  if (dock_info && dock_info->books && n_books == 0)
 
364
    {
 
365
      return NULL;
 
366
    }
 
367
 
 
368
  gtk_widget_show (dock);
 
369
 
 
370
  return GIMP_DOCK (dock);
212
371
}