~ubuntu-branches/ubuntu/intrepid/gimp/intrepid

« back to all changes in this revision

Viewing changes to app/widgets/gimpuimanager.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20081006133041-axco233xt49jobn7
Tags: 2.6.0-1ubuntu1
* Sync on debian and new version (lp: #276839)
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch:
  - updated some strings for ubuntu
* debian/rules:
  - updated translation templates

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
};
59
59
 
60
60
 
61
 
static GObject * gimp_ui_manager_constructor    (GType               type,
62
 
                                                 guint               n_params,
63
 
                                                 GObjectConstructParam *params);
64
 
static void     gimp_ui_manager_dispose         (GObject            *object);
65
 
static void     gimp_ui_manager_finalize        (GObject            *object);
66
 
static void     gimp_ui_manager_set_property    (GObject            *object,
67
 
                                                 guint               prop_id,
68
 
                                                 const GValue       *value,
69
 
                                                 GParamSpec         *pspec);
70
 
static void     gimp_ui_manager_get_property    (GObject            *object,
71
 
                                                 guint               prop_id,
72
 
                                                 GValue             *value,
73
 
                                                 GParamSpec         *pspec);
74
 
static void     gimp_ui_manager_connect_proxy   (GtkUIManager       *manager,
75
 
                                                 GtkAction          *action,
76
 
                                                 GtkWidget          *proxy);
77
 
static GtkWidget * gimp_ui_manager_get_widget   (GtkUIManager       *manager,
78
 
                                                 const gchar        *path);
79
 
static GtkAction * gimp_ui_manager_get_action   (GtkUIManager       *manager,
80
 
                                                 const gchar        *path);
81
 
static void     gimp_ui_manager_real_update     (GimpUIManager      *manager,
82
 
                                                 gpointer            update_data);
83
 
static GimpUIManagerUIEntry *
84
 
                gimp_ui_manager_entry_get       (GimpUIManager      *manager,
85
 
                                                 const gchar        *ui_path);
86
 
static gboolean gimp_ui_manager_entry_load      (GimpUIManager      *manager,
87
 
                                                 GimpUIManagerUIEntry *entry,
88
 
                                                 GError            **error);
89
 
static GimpUIManagerUIEntry *
90
 
                gimp_ui_manager_entry_ensure    (GimpUIManager      *manager,
91
 
                                                 const gchar        *path);
92
 
static void     gimp_ui_manager_menu_position   (GtkMenu            *menu,
93
 
                                                 gint               *x,
94
 
                                                 gint               *y,
95
 
                                                 gpointer            data);
96
 
static void     gimp_ui_manager_menu_pos        (GtkMenu            *menu,
97
 
                                                 gint               *x,
98
 
                                                 gint               *y,
99
 
                                                 gboolean           *push_in,
100
 
                                                 gpointer            data);
101
 
static void
102
 
            gimp_ui_manager_delete_popdown_data (GtkObject          *object,
103
 
                                                 GimpUIManager      *manager);
104
 
static void     gimp_ui_manager_item_realize    (GtkWidget          *widget,
105
 
                                                 GimpUIManager      *manager);
106
 
static void    gimp_ui_manager_menu_item_select (GtkWidget          *widget,
107
 
                                                 GimpUIManager      *manager);
108
 
static void  gimp_ui_manager_menu_item_deselect (GtkWidget          *widget,
109
 
                                                 GimpUIManager      *manager);
110
 
static gboolean gimp_ui_manager_item_key_press  (GtkWidget          *widget,
111
 
                                                 GdkEventKey        *kevent,
112
 
                                                 GimpUIManager      *manager);
 
61
static GObject *  gimp_ui_manager_constructor         (GType           type,
 
62
                                                       guint           n_params,
 
63
                                                       GObjectConstructParam *params);
 
64
static void       gimp_ui_manager_dispose             (GObject        *object);
 
65
static void       gimp_ui_manager_finalize            (GObject        *object);
 
66
static void       gimp_ui_manager_set_property        (GObject        *object,
 
67
                                                       guint           prop_id,
 
68
                                                       const GValue   *value,
 
69
                                                       GParamSpec     *pspec);
 
70
static void       gimp_ui_manager_get_property        (GObject        *object,
 
71
                                                       guint           prop_id,
 
72
                                                       GValue         *value,
 
73
                                                       GParamSpec     *pspec);
 
74
static void       gimp_ui_manager_connect_proxy       (GtkUIManager   *manager,
 
75
                                                       GtkAction      *action,
 
76
                                                       GtkWidget      *proxy);
 
77
static GtkWidget *gimp_ui_manager_get_widget          (GtkUIManager   *manager,
 
78
                                                       const gchar    *path);
 
79
static GtkAction *gimp_ui_manager_get_action          (GtkUIManager   *manager,
 
80
                                                       const gchar    *path);
 
81
static void       gimp_ui_manager_real_update         (GimpUIManager  *manager,
 
82
                                                       gpointer        update_data);
 
83
static GimpUIManagerUIEntry *
 
84
                  gimp_ui_manager_entry_get           (GimpUIManager  *manager,
 
85
                                                       const gchar    *ui_path);
 
86
static gboolean   gimp_ui_manager_entry_load          (GimpUIManager  *manager,
 
87
                                                       GimpUIManagerUIEntry *entry,
 
88
                                                       GError        **error);
 
89
static GimpUIManagerUIEntry *
 
90
                  gimp_ui_manager_entry_ensure        (GimpUIManager  *manager,
 
91
                                                       const gchar    *path);
 
92
static void       gimp_ui_manager_menu_position       (GtkMenu        *menu,
 
93
                                                       gint           *x,
 
94
                                                       gint           *y,
 
95
                                                       gpointer        data);
 
96
static void       gimp_ui_manager_menu_pos            (GtkMenu        *menu,
 
97
                                                       gint           *x,
 
98
                                                       gint           *y,
 
99
                                                       gboolean       *push_in,
 
100
                                                       gpointer        data);
 
101
static void       gimp_ui_manager_delete_popdown_data (GtkObject      *object,
 
102
                                                       GimpUIManager  *manager);
 
103
static void       gimp_ui_manager_item_realize        (GtkWidget      *widget,
 
104
                                                       GimpUIManager  *manager);
 
105
static void       gimp_ui_manager_menu_item_select    (GtkWidget      *widget,
 
106
                                                       GimpUIManager  *manager);
 
107
static void       gimp_ui_manager_menu_item_deselect  (GtkWidget      *widget,
 
108
                                                       GimpUIManager  *manager);
 
109
static gboolean   gimp_ui_manager_item_key_press      (GtkWidget      *widget,
 
110
                                                       GdkEventKey    *kevent,
 
111
                                                       GimpUIManager  *manager);
 
112
static GtkWidget *find_widget_under_pointer           (GdkWindow      *window,
 
113
                                                       gint           *x,
 
114
                                                       gint           *y);
113
115
 
114
116
 
115
117
G_DEFINE_TYPE (GimpUIManager, gimp_ui_manager, GTK_TYPE_UI_MANAGER)
569
571
                          GtkWidget            *parent,
570
572
                          GimpMenuPositionFunc  position_func,
571
573
                          gpointer              position_data,
572
 
                          GtkDestroyNotify      popdown_func,
 
574
                          GDestroyNotify        popdown_func,
573
575
                          gpointer              popdown_data)
574
576
{
575
577
  GtkWidget *widget;
588
590
  if (GTK_IS_MENU_ITEM (widget))
589
591
    widget = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
590
592
 
 
593
  if (! widget)
 
594
    return;
 
595
 
591
596
  g_return_if_fail (GTK_IS_MENU (widget));
592
597
 
593
598
  if (! position_func)
862
867
gimp_ui_manager_item_realize (GtkWidget     *widget,
863
868
                              GimpUIManager *manager)
864
869
{
 
870
  GtkWidget *menu;
865
871
  GtkWidget *submenu;
866
872
 
867
873
  g_signal_handlers_disconnect_by_func (widget,
868
874
                                        gimp_ui_manager_item_realize,
869
875
                                        manager);
870
876
 
871
 
  if (GTK_IS_MENU_SHELL (widget->parent))
 
877
  menu = gtk_widget_get_parent (widget);
 
878
 
 
879
  if (GTK_IS_MENU_SHELL (menu))
872
880
    {
873
881
      static GQuark quark_key_press_connected = 0;
874
882
 
876
884
        quark_key_press_connected =
877
885
          g_quark_from_static_string ("gimp-menu-item-key-press-connected");
878
886
 
879
 
      if (! GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget->parent),
 
887
      if (! GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (menu),
880
888
                                                 quark_key_press_connected)))
881
889
        {
882
 
          g_signal_connect (widget->parent, "key-press-event",
 
890
          g_signal_connect (menu, "key-press-event",
883
891
                            G_CALLBACK (gimp_ui_manager_item_key_press),
884
892
                            manager);
885
893
 
886
 
          g_object_set_qdata (G_OBJECT (widget->parent),
 
894
          g_object_set_qdata (G_OBJECT (menu),
887
895
                              quark_key_press_connected,
888
896
                              GINT_TO_POINTER (TRUE));
889
897
        }
934
942
 
935
943
  while (! help_id)
936
944
    {
937
 
      GtkWidget *menu_item;
938
 
 
939
 
      menu_item = GTK_MENU_SHELL (widget)->active_menu_item;
 
945
      GtkWidget *menu_item = GTK_MENU_SHELL (widget)->active_menu_item;
 
946
 
 
947
      if (! menu_item && GTK_IS_MENU (widget))
 
948
        {
 
949
          GdkWindow *window = GTK_MENU (widget)->toplevel->window;
 
950
          gint       x, y;
 
951
 
 
952
          gdk_window_get_pointer (window, &x, &y, NULL);
 
953
          menu_item = find_widget_under_pointer (window, &x, &y);
 
954
 
 
955
          if (menu_item && ! GTK_IS_MENU_ITEM (menu_item))
 
956
            {
 
957
              menu_item = gtk_widget_get_ancestor (menu_item,
 
958
                                                   GTK_TYPE_MENU_ITEM);
 
959
 
 
960
              if (! GTK_IS_MENU_ITEM (menu_item))
 
961
                menu_item = NULL;
 
962
            }
 
963
        }
940
964
 
941
965
      /*  first, get the help page from the item...
942
966
       */
970
994
          if (! menu_item)
971
995
            break;
972
996
 
973
 
          widget = menu_item->parent;
 
997
          widget = gtk_widget_get_parent (menu_item);
974
998
 
975
999
          if (! widget)
976
1000
            break;
1018
1042
          help_string = g_strdup (help_id);
1019
1043
        }
1020
1044
 
1021
 
      gimp_help (manager->gimp, help_domain, help_string);
 
1045
      gimp_help (manager->gimp, NULL, help_domain, help_string);
1022
1046
 
1023
1047
      g_free (help_domain);
1024
1048
      g_free (help_string);
1027
1051
 
1028
1052
  return TRUE;
1029
1053
}
 
1054
 
 
1055
 
 
1056
/* Stuff below taken from gtktooltip.c
 
1057
 */
 
1058
 
 
1059
#ifdef __GNUC__
 
1060
#warning FIXME: remove this crack as soon as a GTK+ widget_under_pointer() is available
 
1061
#endif
 
1062
 
 
1063
struct ChildLocation
 
1064
{
 
1065
  GtkWidget *child;
 
1066
  GtkWidget *container;
 
1067
 
 
1068
  gint x;
 
1069
  gint y;
 
1070
};
 
1071
 
 
1072
static void
 
1073
child_location_foreach (GtkWidget *child,
 
1074
                        gpointer   data)
 
1075
{
 
1076
  gint x, y;
 
1077
  struct ChildLocation *child_loc = data;
 
1078
 
 
1079
  /* Ignore invisible widgets */
 
1080
  if (!GTK_WIDGET_DRAWABLE (child))
 
1081
    return;
 
1082
 
 
1083
  /* (child_loc->x, child_loc->y) are relative to
 
1084
   * child_loc->container's allocation.
 
1085
   */
 
1086
 
 
1087
  if (!child_loc->child &&
 
1088
      gtk_widget_translate_coordinates (child_loc->container, child,
 
1089
                                        child_loc->x, child_loc->y,
 
1090
                                        &x, &y))
 
1091
    {
 
1092
#ifdef DEBUG_TOOLTIP
 
1093
      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);
 
1101
#endif /* DEBUG_TOOLTIP */
 
1102
 
 
1103
      /* (x, y) relative to child's allocation. */
 
1104
      if (x >= 0 && x < child->allocation.width
 
1105
          && y >= 0 && y < child->allocation.height)
 
1106
        {
 
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
        }
 
1129
    }
 
1130
}
 
1131
 
 
1132
/* Translates coordinates from dest_widget->window relative (src_x, src_y),
 
1133
 * to allocation relative (dest_x, dest_y) of dest_widget.
 
1134
 */
 
1135
static void
 
1136
window_to_alloc (GtkWidget *dest_widget,
 
1137
                 gint       src_x,
 
1138
                 gint       src_y,
 
1139
                 gint      *dest_x,
 
1140
                 gint      *dest_y)
 
1141
{
 
1142
  /* Translate from window relative to allocation relative */
 
1143
  if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
 
1144
    {
 
1145
      gint wx, wy;
 
1146
      gdk_window_get_position (dest_widget->window, &wx, &wy);
 
1147
 
 
1148
      /* Offset coordinates if widget->window is smaller than
 
1149
       * widget->allocation.
 
1150
       */
 
1151
      src_x += wx - dest_widget->allocation.x;
 
1152
      src_y += wy - dest_widget->allocation.y;
 
1153
    }
 
1154
  else
 
1155
    {
 
1156
      src_x -= dest_widget->allocation.x;
 
1157
      src_y -= dest_widget->allocation.y;
 
1158
    }
 
1159
 
 
1160
  if (dest_x)
 
1161
    *dest_x = src_x;
 
1162
  if (dest_y)
 
1163
    *dest_y = src_y;
 
1164
}
 
1165
 
 
1166
static GtkWidget *
 
1167
find_widget_under_pointer (GdkWindow *window,
 
1168
                           gint      *x,
 
1169
                           gint      *y)
 
1170
{
 
1171
  GtkWidget *event_widget;
 
1172
  struct ChildLocation child_loc = { NULL, NULL, 0, 0 };
 
1173
 
 
1174
  gdk_window_get_user_data (window, (void **)&event_widget);
 
1175
 
 
1176
  if (!event_widget)
 
1177
    return NULL;
 
1178
 
 
1179
#ifdef DEBUG_TOOLTIP
 
1180
  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);
 
1183
#endif
 
1184
 
 
1185
  /* Coordinates are relative to event window */
 
1186
  child_loc.x = *x;
 
1187
  child_loc.y = *y;
 
1188
 
 
1189
  /* We go down the window hierarchy to the widget->window,
 
1190
   * coordinates stay relative to the current window.
 
1191
   * We end up with window == widget->window, coordinates relative to that.
 
1192
   */
 
1193
  while (window && window != event_widget->window)
 
1194
    {
 
1195
      gint px, py;
 
1196
 
 
1197
      gdk_window_get_position (window, &px, &py);
 
1198
      child_loc.x += px;
 
1199
      child_loc.y += py;
 
1200
 
 
1201
      window = gdk_window_get_parent (window);
 
1202
    }
 
1203
 
 
1204
  /* Failing to find widget->window can happen for e.g. a detached handle box;
 
1205
   * chaining ::query-tooltip up to its parent probably makes little sense,
 
1206
   * and users better implement tooltips on handle_box->child.
 
1207
   * so we simply ignore the event for tooltips here.
 
1208
   */
 
1209
  if (!window)
 
1210
    return NULL;
 
1211
 
 
1212
  /* Convert the window relative coordinates to allocation
 
1213
   * relative coordinates.
 
1214
   */
 
1215
  window_to_alloc (event_widget,
 
1216
                   child_loc.x, child_loc.y,
 
1217
                   &child_loc.x, &child_loc.y);
 
1218
 
 
1219
  if (GTK_IS_CONTAINER (event_widget))
 
1220
    {
 
1221
      GtkWidget *container = event_widget;
 
1222
 
 
1223
      child_loc.container = event_widget;
 
1224
      child_loc.child = NULL;
 
1225
 
 
1226
      gtk_container_forall (GTK_CONTAINER (event_widget),
 
1227
                            child_location_foreach, &child_loc);
 
1228
 
 
1229
      /* Here we have a widget, with coordinates relative to
 
1230
       * child_loc.container's allocation.
 
1231
       */
 
1232
 
 
1233
      if (child_loc.child)
 
1234
        event_widget = child_loc.child;
 
1235
      else if (child_loc.container)
 
1236
        event_widget = child_loc.container;
 
1237
 
 
1238
      /* Translate to event_widget's allocation */
 
1239
      gtk_widget_translate_coordinates (container, event_widget,
 
1240
                                        child_loc.x, child_loc.y,
 
1241
                                        &child_loc.x, &child_loc.y);
 
1242
 
 
1243
    }
 
1244
 
 
1245
  /* We return (x, y) relative to the allocation of event_widget. */
 
1246
  if (x)
 
1247
    *x = child_loc.x;
 
1248
  if (y)
 
1249
    *y = child_loc.y;
 
1250
 
 
1251
  return event_widget;
 
1252
}