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

« back to all changes in this revision

Viewing changes to app/widgets/gimpuimanager.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:
4
4
 * gimpuimanager.c
5
5
 * Copyright (C) 2004 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
 
24
23
#include <string.h>
25
24
 
 
25
#undef GSEAL_ENABLE
 
26
 
26
27
#include <gtk/gtk.h>
27
28
#include <gdk/gdkkeysyms.h>
28
29
 
58
59
};
59
60
 
60
61
 
61
 
static GObject *  gimp_ui_manager_constructor         (GType           type,
62
 
                                                       guint           n_params,
63
 
                                                       GObjectConstructParam *params);
 
62
static void       gimp_ui_manager_constructed         (GObject        *object);
64
63
static void       gimp_ui_manager_dispose             (GObject        *object);
65
64
static void       gimp_ui_manager_finalize            (GObject        *object);
66
65
static void       gimp_ui_manager_set_property        (GObject        *object,
127
126
  GObjectClass      *object_class  = G_OBJECT_CLASS (klass);
128
127
  GtkUIManagerClass *manager_class = GTK_UI_MANAGER_CLASS (klass);
129
128
 
130
 
  object_class->constructor    = gimp_ui_manager_constructor;
 
129
  object_class->constructed    = gimp_ui_manager_constructed;
131
130
  object_class->dispose        = gimp_ui_manager_dispose;
132
131
  object_class->finalize       = gimp_ui_manager_finalize;
133
132
  object_class->set_property   = gimp_ui_manager_set_property;
194
193
  manager->gimp = NULL;
195
194
}
196
195
 
197
 
static GObject *
198
 
gimp_ui_manager_constructor (GType                  type,
199
 
                             guint                  n_params,
200
 
                             GObjectConstructParam *params)
 
196
static void
 
197
gimp_ui_manager_constructed (GObject *object)
201
198
{
202
 
  GObject       *object;
203
 
  GimpUIManager *manager;
204
 
 
205
 
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
206
 
 
207
 
  manager = GIMP_UI_MANAGER (object);
 
199
  GimpUIManager *manager = GIMP_UI_MANAGER (object);
 
200
 
 
201
  if (G_OBJECT_CLASS (parent_class)->constructed)
 
202
    G_OBJECT_CLASS (parent_class)->constructed (object);
208
203
 
209
204
  if (manager->name)
210
205
    {
220
215
      g_hash_table_replace (manager_class->managers,
221
216
                            g_strdup (manager->name), list);
222
217
    }
223
 
 
224
 
  return object;
225
218
}
226
219
 
227
220
static void
298
291
      g_free (manager->name);
299
292
      manager->name = g_value_dup_string (value);
300
293
      break;
 
294
 
301
295
    case PROP_GIMP:
302
296
      manager->gimp = g_value_get_object (value);
303
297
      break;
 
298
 
304
299
    default:
305
300
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
306
301
      break;
320
315
    case PROP_NAME:
321
316
      g_value_set_string (value, manager->name);
322
317
      break;
 
318
 
323
319
    case PROP_GIMP:
324
320
      g_value_set_object (value, manager->gimp);
325
321
      break;
 
322
 
326
323
    default:
327
324
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
328
325
      break;
335
332
                               GtkWidget    *proxy)
336
333
{
337
334
  g_object_set_qdata (G_OBJECT (proxy), GIMP_HELP_ID,
338
 
                      g_object_get_qdata (G_OBJECT (action),
339
 
                                          GIMP_HELP_ID));
 
335
                      g_object_get_qdata (G_OBJECT (action), GIMP_HELP_ID));
340
336
 
341
337
  if (GTK_IS_MENU_ITEM (proxy))
342
338
    {
690
686
                            GimpUIManagerUIEntry  *entry,
691
687
                            GError               **error)
692
688
{
693
 
  gchar *filename;
 
689
  gchar       *filename           = NULL;
 
690
  const gchar *menus_dir_override = g_getenv ("GIMP_TESTING_MENUS_DIR");
694
691
 
695
 
  filename = g_build_filename (gimp_data_directory (), "menus",
696
 
                               entry->basename, NULL);
 
692
  /* In order for test cases to be able to run without GIMP being
 
693
   * installed yet, allow them to override the menus directory to the
 
694
   * menus dir in the source root
 
695
   */
 
696
  if (menus_dir_override)
 
697
    filename = g_build_filename (menus_dir_override, entry->basename, NULL);
 
698
  else
 
699
    filename = g_build_filename (gimp_data_directory (), "menus",
 
700
                                 entry->basename, NULL);
697
701
 
698
702
  if (manager->gimp->be_verbose)
699
703
    g_print ("loading menu '%s' for %s\n",
737
741
                            "%s\n\n%s\n\n%s",
738
742
                            _("Your GIMP installation is incomplete:"),
739
743
                            error->message,
740
 
                            _("Plase make sure the menu XML files are correctly "
741
 
                              "installed."));
 
744
                            _("Please make sure the menu XML files are "
 
745
                              "correctly installed."));
742
746
            }
743
747
          else
744
748
            {
909
913
gimp_ui_manager_menu_item_select (GtkWidget     *widget,
910
914
                                  GimpUIManager *manager)
911
915
{
912
 
  GtkAction *action = gtk_widget_get_action (widget);
 
916
  GtkAction *action =
 
917
    gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
913
918
 
914
919
  if (action)
915
920
    {
916
 
      gchar *tooltip;
917
 
 
918
 
      g_object_get (action, "tooltip", &tooltip, NULL);
 
921
      const gchar *tooltip = gtk_action_get_tooltip (action);
919
922
 
920
923
      if (tooltip)
921
 
        {
922
 
          g_signal_emit (manager, manager_signals[SHOW_TOOLTIP], 0,
923
 
                         tooltip);
924
 
          g_free (tooltip);
925
 
        }
 
924
        g_signal_emit (manager, manager_signals[SHOW_TOOLTIP], 0, tooltip);
926
925
    }
927
926
}
928
927
 
946
945
 
947
946
      if (! menu_item && GTK_IS_MENU (widget))
948
947
        {
949
 
          GdkWindow *window = GTK_MENU (widget)->toplevel->window;
 
948
          GtkWidget *parent = gtk_widget_get_parent (widget);
 
949
          GdkWindow *window = gtk_widget_get_window (parent);
950
950
          gint       x, y;
951
951
 
952
952
          gdk_window_get_pointer (window, &x, &y, NULL);
1005
1005
   *  standard GtkMenuShell callback and assign a new shortcut, but
1006
1006
   *  don't assign a shortcut to the help menu entries ...
1007
1007
   */
1008
 
  if (kevent->keyval != GDK_F1)
 
1008
  if (kevent->keyval != GDK_KEY_F1)
1009
1009
    {
1010
1010
      if (help_id                                   &&
1011
1011
          gtk_accelerator_valid (kevent->keyval, 0) &&
1056
1056
/* Stuff below taken from gtktooltip.c
1057
1057
 */
1058
1058
 
1059
 
#ifdef __GNUC__
1060
 
#warning FIXME: remove this crack as soon as a GTK+ widget_under_pointer() is available
1061
 
#endif
 
1059
/* FIXME: remove this crack as soon as a GTK+ widget_under_pointer() is available */
1062
1060
 
1063
1061
struct ChildLocation
1064
1062
{
1071
1069
 
1072
1070
static void
1073
1071
child_location_foreach (GtkWidget *child,
1074
 
                        gpointer   data)
 
1072
                        gpointer   data)
1075
1073
{
1076
1074
  gint x, y;
1077
1075
  struct ChildLocation *child_loc = data;
1078
1076
 
1079
1077
  /* Ignore invisible widgets */
1080
 
  if (!GTK_WIDGET_DRAWABLE (child))
 
1078
  if (! gtk_widget_is_drawable (child))
1081
1079
    return;
1082
1080
 
1083
1081
  /* (child_loc->x, child_loc->y) are relative to
1084
1082
   * child_loc->container's allocation.
1085
1083
   */
1086
1084
 
1087
 
  if (!child_loc->child &&
 
1085
  if (! child_loc->child &&
1088
1086
      gtk_widget_translate_coordinates (child_loc->container, child,
1089
 
                                        child_loc->x, child_loc->y,
1090
 
                                        &x, &y))
 
1087
                                        child_loc->x, child_loc->y,
 
1088
                                        &x, &y))
1091
1089
    {
 
1090
      GtkAllocation child_allocation;
 
1091
 
 
1092
      gtk_widget_get_allocation (child, &child_allocation);
 
1093
 
1092
1094
#ifdef DEBUG_TOOLTIP
1093
1095
      g_print ("candidate: %s  alloc=[(%d,%d)  %dx%d]     (%d, %d)->(%d, %d)\n",
1094
 
               gtk_widget_get_name (child),
1095
 
               child->allocation.x,
1096
 
               child->allocation.y,
1097
 
               child->allocation.width,
1098
 
               child->allocation.height,
1099
 
               child_loc->x, child_loc->y,
1100
 
               x, y);
 
1096
               gtk_widget_get_name (child),
 
1097
               child_allocation.x,
 
1098
               child_allocation.y,
 
1099
               child_allocation.width,
 
1100
               child_allocation.height,
 
1101
               child_loc->x, child_loc->y,
 
1102
               x, y);
1101
1103
#endif /* DEBUG_TOOLTIP */
1102
1104
 
1103
1105
      /* (x, y) relative to child's allocation. */
1104
 
      if (x >= 0 && x < child->allocation.width
1105
 
          && y >= 0 && y < child->allocation.height)
 
1106
      if (x >= 0 && x < child_allocation.width
 
1107
          && y >= 0 && y < child_allocation.height)
1106
1108
        {
1107
 
          if (GTK_IS_CONTAINER (child))
1108
 
            {
1109
 
              struct ChildLocation tmp = { NULL, NULL, 0, 0 };
1110
 
 
1111
 
              /* Take (x, y) relative the child's allocation and
1112
 
               * recurse.
1113
 
               */
1114
 
              tmp.x = x;
1115
 
              tmp.y = y;
1116
 
              tmp.container = child;
1117
 
 
1118
 
              gtk_container_forall (GTK_CONTAINER (child),
1119
 
                                    child_location_foreach, &tmp);
1120
 
 
1121
 
              if (tmp.child)
1122
 
                child_loc->child = tmp.child;
1123
 
              else
1124
 
                child_loc->child = child;
1125
 
            }
1126
 
          else
1127
 
            child_loc->child = child;
1128
 
        }
 
1109
          if (GTK_IS_CONTAINER (child))
 
1110
            {
 
1111
              struct ChildLocation tmp = { NULL, NULL, 0, 0 };
 
1112
 
 
1113
              /* Take (x, y) relative the child's allocation and
 
1114
               * recurse.
 
1115
               */
 
1116
              tmp.x = x;
 
1117
              tmp.y = y;
 
1118
              tmp.container = child;
 
1119
 
 
1120
              gtk_container_forall (GTK_CONTAINER (child),
 
1121
                                    child_location_foreach, &tmp);
 
1122
 
 
1123
              if (tmp.child)
 
1124
                child_loc->child = tmp.child;
 
1125
              else
 
1126
                child_loc->child = child;
 
1127
            }
 
1128
          else
 
1129
            {
 
1130
              child_loc->child = child;
 
1131
            }
 
1132
        }
1129
1133
    }
1130
1134
}
1131
1135
 
1134
1138
 */
1135
1139
static void
1136
1140
window_to_alloc (GtkWidget *dest_widget,
1137
 
                 gint       src_x,
1138
 
                 gint       src_y,
1139
 
                 gint      *dest_x,
1140
 
                 gint      *dest_y)
 
1141
                 gint       src_x,
 
1142
                 gint       src_y,
 
1143
                 gint      *dest_x,
 
1144
                 gint      *dest_y)
1141
1145
{
 
1146
  GtkAllocation dest_allocation;
 
1147
 
 
1148
  gtk_widget_get_allocation (dest_widget, &dest_allocation);
 
1149
 
1142
1150
  /* Translate from window relative to allocation relative */
1143
 
  if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
 
1151
  if (gtk_widget_get_has_window (dest_widget) &&
 
1152
      gtk_widget_get_parent (dest_widget))
1144
1153
    {
1145
1154
      gint wx, wy;
1146
 
      gdk_window_get_position (dest_widget->window, &wx, &wy);
 
1155
 
 
1156
      gdk_window_get_position (gtk_widget_get_window (dest_widget), &wx, &wy);
1147
1157
 
1148
1158
      /* Offset coordinates if widget->window is smaller than
1149
1159
       * widget->allocation.
1150
1160
       */
1151
 
      src_x += wx - dest_widget->allocation.x;
1152
 
      src_y += wy - dest_widget->allocation.y;
 
1161
      src_x += wx - dest_allocation.x;
 
1162
      src_y += wy - dest_allocation.y;
1153
1163
    }
1154
1164
  else
1155
1165
    {
1156
 
      src_x -= dest_widget->allocation.x;
1157
 
      src_y -= dest_widget->allocation.y;
 
1166
      src_x -= dest_allocation.x;
 
1167
      src_y -= dest_allocation.y;
1158
1168
    }
1159
1169
 
1160
1170
  if (dest_x)
1165
1175
 
1166
1176
static GtkWidget *
1167
1177
find_widget_under_pointer (GdkWindow *window,
1168
 
                           gint      *x,
1169
 
                           gint      *y)
 
1178
                           gint      *x,
 
1179
                           gint      *y)
1170
1180
{
1171
1181
  GtkWidget *event_widget;
1172
1182
  struct ChildLocation child_loc = { NULL, NULL, 0, 0 };
1173
1183
 
1174
1184
  gdk_window_get_user_data (window, (void **)&event_widget);
1175
1185
 
1176
 
  if (!event_widget)
 
1186
  if (! event_widget)
1177
1187
    return NULL;
1178
1188
 
1179
1189
#ifdef DEBUG_TOOLTIP
1180
1190
  g_print ("event window %p (belonging to %p (%s))  (%d, %d)\n",
1181
 
           window, event_widget, gtk_widget_get_name (event_widget),
1182
 
           *x, *y);
 
1191
           window, event_widget, gtk_widget_get_name (event_widget),
 
1192
           *x, *y);
1183
1193
#endif
1184
1194
 
1185
1195
  /* Coordinates are relative to event window */
1190
1200
   * coordinates stay relative to the current window.
1191
1201
   * We end up with window == widget->window, coordinates relative to that.
1192
1202
   */
1193
 
  while (window && window != event_widget->window)
 
1203
  while (window && window != gtk_widget_get_window (event_widget))
1194
1204
    {
1195
1205
      gint px, py;
1196
1206
 
1213
1223
   * relative coordinates.
1214
1224
   */
1215
1225
  window_to_alloc (event_widget,
1216
 
                   child_loc.x, child_loc.y,
1217
 
                   &child_loc.x, &child_loc.y);
 
1226
                   child_loc.x, child_loc.y,
 
1227
                   &child_loc.x, &child_loc.y);
1218
1228
 
1219
1229
  if (GTK_IS_CONTAINER (event_widget))
1220
1230
    {
1224
1234
      child_loc.child = NULL;
1225
1235
 
1226
1236
      gtk_container_forall (GTK_CONTAINER (event_widget),
1227
 
                            child_location_foreach, &child_loc);
 
1237
                            child_location_foreach, &child_loc);
1228
1238
 
1229
1239
      /* Here we have a widget, with coordinates relative to
1230
1240
       * child_loc.container's allocation.
1231
1241
       */
1232
1242
 
1233
1243
      if (child_loc.child)
1234
 
        event_widget = child_loc.child;
 
1244
        event_widget = child_loc.child;
1235
1245
      else if (child_loc.container)
1236
 
        event_widget = child_loc.container;
 
1246
        event_widget = child_loc.container;
1237
1247
 
1238
1248
      /* Translate to event_widget's allocation */
1239
1249
      gtk_widget_translate_coordinates (container, event_widget,
1240
 
                                        child_loc.x, child_loc.y,
1241
 
                                        &child_loc.x, &child_loc.y);
 
1250
                                        child_loc.x, child_loc.y,
 
1251
                                        &child_loc.x, &child_loc.y);
1242
1252
 
1243
1253
    }
1244
1254