~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/actions/window-actions.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

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
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "libgimpwidgets/gimpwidgets.h"
 
24
 
 
25
#include "actions-types.h"
 
26
 
 
27
#include "widgets/gimpactiongroup.h"
 
28
#include "widgets/gimphelp-ids.h"
 
29
 
 
30
#include "actions.h"
 
31
#include "window-actions.h"
 
32
#include "window-commands.h"
 
33
 
 
34
#include "gimp-intl.h"
 
35
 
 
36
 
 
37
/*  private functions  */
 
38
 
 
39
static void   window_actions_display_opened (GdkDisplayManager *manager,
 
40
                                             GdkDisplay        *display,
 
41
                                             GimpActionGroup   *group);
 
42
static void   window_actions_display_closed (GdkDisplay        *display,
 
43
                                             gboolean           is_error,
 
44
                                             GimpActionGroup   *group);
 
45
 
 
46
 
 
47
/*  public functions  */
 
48
 
 
49
void
 
50
window_actions_setup (GimpActionGroup *group,
 
51
                      const gchar     *move_to_screen_help_id)
 
52
{
 
53
  GdkDisplayManager *manager = gdk_display_manager_get ();
 
54
  GSList            *displays;
 
55
  GSList            *list;
 
56
 
 
57
  g_object_set_data_full (G_OBJECT (group), "move-to-screen-help-id",
 
58
                          g_strdup (move_to_screen_help_id),
 
59
                          (GDestroyNotify) g_free);
 
60
 
 
61
  displays = gdk_display_manager_list_displays (manager);
 
62
 
 
63
  /*  present displays in the order in which they were opened  */
 
64
  displays = g_slist_reverse (displays);
 
65
 
 
66
  for (list = displays; list; list = g_slist_next (list))
 
67
    {
 
68
      window_actions_display_opened (manager, list->data, group);
 
69
    }
 
70
 
 
71
  g_slist_free (displays);
 
72
 
 
73
  g_signal_connect_object (manager, "display-opened",
 
74
                           G_CALLBACK (window_actions_display_opened),
 
75
                           G_OBJECT (group), 0);
 
76
}
 
77
 
 
78
void
 
79
window_actions_update (GimpActionGroup *group,
 
80
                       GtkWidget       *window)
 
81
{
 
82
  const gchar *group_name;
 
83
  gint         show_menu = FALSE;
 
84
  gchar       *name;
 
85
 
 
86
  group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
 
87
 
 
88
#define SET_ACTIVE(action,active) \
 
89
        gimp_action_group_set_action_active (group, action, (active) != 0)
 
90
#define SET_VISIBLE(action,active) \
 
91
        gimp_action_group_set_action_visible (group, action, (active) != 0)
 
92
 
 
93
  if (GTK_IS_WINDOW (window))
 
94
    {
 
95
      GdkDisplay *display;
 
96
      GdkScreen  *screen;
 
97
      gchar      *screen_name;
 
98
 
 
99
      display = gtk_widget_get_display (window);
 
100
 
 
101
      show_menu = (gdk_display_get_n_screens (display) > 1);
 
102
 
 
103
#ifdef GIMP_UNSTABLE
 
104
      show_menu = TRUE;
 
105
#endif
 
106
 
 
107
      if (! show_menu)
 
108
        {
 
109
          GdkDisplayManager *manager = gdk_display_manager_get ();
 
110
          GSList            *displays;
 
111
 
 
112
          displays = gdk_display_manager_list_displays (manager);
 
113
          show_menu = (displays->next != NULL);
 
114
          g_slist_free (displays);
 
115
        }
 
116
 
 
117
      screen = gtk_widget_get_screen (window);
 
118
 
 
119
      screen_name = gdk_screen_make_display_name (screen);
 
120
      name = g_strdup_printf ("%s-move-to-screen-%s", group_name, screen_name);
 
121
      g_free (screen_name);
 
122
 
 
123
      SET_ACTIVE (name, TRUE);
 
124
      g_free (name);
 
125
    }
 
126
 
 
127
  name = g_strdup_printf ("%s-move-to-screen-menu", group_name);
 
128
  SET_VISIBLE (name, show_menu);
 
129
  g_free (name);
 
130
 
 
131
#undef SET_ACTIVE
 
132
#undef SET_VISIBLE
 
133
}
 
134
 
 
135
 
 
136
/*  private functions  */
 
137
 
 
138
static void
 
139
window_actions_display_opened (GdkDisplayManager *manager,
 
140
                               GdkDisplay        *display,
 
141
                               GimpActionGroup   *group)
 
142
{
 
143
  GimpRadioActionEntry *entries;
 
144
  const gchar          *help_id;
 
145
  const gchar          *group_name;
 
146
  GSList               *radio_group;
 
147
  gint                  n_screens;
 
148
  gint                  i;
 
149
 
 
150
  help_id = g_object_get_data (G_OBJECT (group), "change-to-screen-help-id");
 
151
 
 
152
  group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
 
153
 
 
154
  n_screens = gdk_display_get_n_screens (display);
 
155
 
 
156
  entries = g_new0 (GimpRadioActionEntry, n_screens);
 
157
 
 
158
  for (i = 0; i < n_screens; i++)
 
159
    {
 
160
      GdkScreen *screen = gdk_display_get_screen (display, i);
 
161
      gchar     *screen_name;
 
162
 
 
163
      screen_name = gdk_screen_make_display_name (screen);
 
164
 
 
165
      entries[i].name        = g_strdup_printf ("%s-move-to-screen-%s",
 
166
                                                group_name, screen_name);
 
167
      entries[i].stock_id    = GIMP_STOCK_MOVE_TO_SCREEN;
 
168
      entries[i].label       = g_strdup_printf (_("Screen %s"), screen_name);
 
169
      entries[i].accelerator = NULL;
 
170
      entries[i].tooltip     = g_strdup_printf (_("Move this window to "
 
171
                                                  "screen %s"), screen_name);
 
172
      entries[i].value       = g_quark_from_string (screen_name);
 
173
      entries[i].help_id     = help_id;
 
174
 
 
175
      g_free (screen_name);
 
176
    }
 
177
 
 
178
  radio_group = g_object_get_data (G_OBJECT (group),
 
179
                                   "change-to-screen-radio-group");
 
180
  radio_group = gimp_action_group_add_radio_actions (group, entries, n_screens,
 
181
                                                     radio_group, 0,
 
182
                                                     G_CALLBACK (window_move_to_screen_cmd_callback));
 
183
  g_object_set_data (G_OBJECT (group), "change-to-screen-radio-group",
 
184
                     radio_group);
 
185
 
 
186
  for (i = 0; i < n_screens; i++)
 
187
    {
 
188
      GdkScreen *screen = gdk_display_get_screen (display, i);
 
189
      GtkAction *action;
 
190
 
 
191
      action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
 
192
                                            entries[i].name);
 
193
      if (action)
 
194
        g_object_set_data (G_OBJECT (action), "screen", screen);
 
195
 
 
196
      g_free ((gchar *) entries[i].name);
 
197
      g_free ((gchar *) entries[i].tooltip);
 
198
      g_free ((gchar *) entries[i].label);
 
199
    }
 
200
 
 
201
  g_free (entries);
 
202
 
 
203
  g_signal_connect_object (display, "closed",
 
204
                           G_CALLBACK (window_actions_display_closed),
 
205
                           G_OBJECT (group), 0);
 
206
}
 
207
 
 
208
static void
 
209
window_actions_display_closed (GdkDisplay      *display,
 
210
                               gboolean         is_error,
 
211
                               GimpActionGroup *group)
 
212
{
 
213
  const gchar *group_name;
 
214
  gint         n_screens;
 
215
  gint         i;
 
216
 
 
217
  group_name = gtk_action_group_get_name (GTK_ACTION_GROUP (group));
 
218
 
 
219
  n_screens = gdk_display_get_n_screens (display);
 
220
 
 
221
  for (i = 0; i < n_screens; i++)
 
222
    {
 
223
      GdkScreen *screen = gdk_display_get_screen (display, i);
 
224
      GtkAction *action;
 
225
      gchar     *screen_name;
 
226
      gchar     *action_name;
 
227
 
 
228
      screen_name = gdk_screen_make_display_name (screen);
 
229
      action_name = g_strdup_printf ("%s-move-to-screen-%s",
 
230
                                     group_name, screen_name);
 
231
      g_free (screen_name);
 
232
 
 
233
      action = gtk_action_group_get_action (GTK_ACTION_GROUP (group),
 
234
                                            action_name);
 
235
 
 
236
      if (action)
 
237
        {
 
238
          GSList *radio_group;
 
239
 
 
240
          radio_group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
 
241
          if (radio_group->data == (gpointer) action)
 
242
            radio_group = radio_group->next;
 
243
 
 
244
          gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action);
 
245
 
 
246
          g_object_set_data (G_OBJECT (group), "change-to-screen-radio-group",
 
247
                             radio_group);
 
248
        }
 
249
 
 
250
      g_free (action_name);
 
251
    }
 
252
}