prevent double registration of ALSA sequencer MIDI ports
[ardour.git] / patches / gtk-osx.patch
1 Index: gtk/gtktreeview.c
2 ===================================================================
3 --- gtk/gtktreeview.c   (revision 21475)
4 +++ gtk/gtktreeview.c   (working copy)
5 @@ -99,6 +99,9 @@
6  
7    guint source_set : 1;
8    guint dest_set : 1;
9 +
10 +  GtkTreePath* path;
11 +  GtkTreeModel* model;
12  };
13  
14  
15 @@ -2534,6 +2537,7 @@
16        gboolean row_double_click = FALSE;
17        gboolean rtl;
18        gboolean node_selected;
19 +      gboolean edits_allowed;
20  
21        /* Empty tree? */
22        if (tree_view->priv->tree == NULL)
23 @@ -2643,9 +2647,17 @@
24  
25        tree_view->priv->focus_column = column;
26  
27 +      /* ARDOUR HACK */
28 +
29 +      if (g_object_get_data (G_OBJECT(tree_view), "mouse-edits-require-mod1")) {
30 +             edits_allowed = (event->state & GDK_MOD1_MASK);
31 +      } else {
32 +             /* regular GTK design: do edits if none of the default modifiers are active  */
33 +             edits_allowed = !(event->state & gtk_accelerator_get_default_mod_mask ());
34 +      }
35 +
36        /* decide if we edit */
37 -      if (event->type == GDK_BUTTON_PRESS && event->button == 1 &&
38 -         !(event->state & gtk_accelerator_get_default_mod_mask ()))
39 +      if (event->type == GDK_BUTTON_PRESS && event->button == 1 && edits_allowed)
40         {
41           GtkTreePath *anchor;
42           GtkTreeIter iter;
43 @@ -3010,8 +3022,7 @@
44        if (tree_view->priv->button_pressed_node == tree_view->priv->prelight_node &&
45            GTK_TREE_VIEW_FLAG_SET (tree_view, GTK_TREE_VIEW_ARROW_PRELIT))
46         {
47 -         GtkTreePath *path = NULL;
48 -
49 +          GtkTreePath *path = NULL;
50           path = _gtk_tree_view_find_path (tree_view,
51                                            tree_view->priv->button_pressed_tree,
52                                            tree_view->priv->button_pressed_node);
53 @@ -6967,6 +6978,19 @@
54    return path;
55  }
56  
57 +#ifdef GDK_WINDOWING_QUARTZ
58 +
59 +static void
60 +gtk_tree_view_catch_drag_begin (GtkWidget* widget,
61 +                               GdkDragContext* context,
62 +                               gpointer user_data)
63 +{
64 +       TreeViewDragInfo* drag_info = (TreeViewDragInfo*) user_data;
65 +       set_source_row (context, drag_info->model, drag_info->path);
66 +}
67 +
68 +#endif
69 +
70  static gboolean
71  gtk_tree_view_maybe_begin_dragging_row (GtkTreeView      *tree_view,
72                                          GdkEventMotion   *event)
73 @@ -6979,6 +7003,7 @@
74    gint cell_x, cell_y;
75    GtkTreeModel *model;
76    gboolean retval = FALSE;
77 +  gint drag_begin_id;
78  
79    di = get_info (tree_view);
80  
81 @@ -7025,13 +7050,26 @@
82  
83    retval = TRUE;
84  
85 +#ifdef GDK_WINDOWING_QUARTZ
86 +
87 +  /* catch drag-being signal */
88 +  di->model = model;
89 +  di->path = path;
90 +  drag_begin_id = g_signal_connect (tree_view, "drag-begin", G_CALLBACK (gtk_tree_view_catch_drag_begin), (gpointer) di);
91 +#endif
92 +
93    context = gtk_drag_begin (widget,
94                              gtk_drag_source_get_target_list (widget),
95                              di->source_actions,
96                              button,
97                              (GdkEvent*)event);
98  
99 +#ifndef GDK_WINDOWING_QUARTZ
100    set_source_row (context, model, path);
101 +#else 
102 +  /* disconnect drag-begin and catch drag-end */
103 +  g_signal_handler_disconnect (tree_view, drag_begin_id);
104 +#endif
105  
106   out:
107    if (path)
108 Index: gtk/gtkquartz.c
109 ===================================================================
110 --- gtk/gtkquartz.c     (revision 21475)
111 +++ gtk/gtkquartz.c     (working copy)
112 @@ -24,6 +24,23 @@
113  #include "gtkalias.h"
114  
115  NSImage *
116 +_gtk_quartz_create_image_from_drawable (GdkDrawable* drawable)
117 +{
118 +       GdkPixbuf* pixbuf;
119 +       NSImage* image = NULL;
120 +
121 +       pixbuf = gdk_pixbuf_get_from_drawable (NULL, drawable, NULL, 
122 +                                                 0, 0, /* src */
123 +                                                 0, 0, /* dst */
124 +                                                 -1, -1);
125 +       if (pixbuf) 
126 +         image = _gtk_quartz_create_image_from_pixbuf (pixbuf);
127 +       
128 +       return image;
129 +}
130 +
131 +
132 +NSImage *
133  _gtk_quartz_create_image_from_pixbuf (GdkPixbuf *pixbuf)
134  {
135    CGColorSpaceRef colorspace;
136 Index: gtk/gtkquartz.h
137 ===================================================================
138 --- gtk/gtkquartz.h     (revision 21475)
139 +++ gtk/gtkquartz.h     (working copy)
140 @@ -41,6 +41,7 @@
141                                                     GtkSelectionData *selection_data);
142                         
143  NSImage *_gtk_quartz_create_image_from_pixbuf (GdkPixbuf *pixbuf);
144 +NSImage *_gtk_quartz_create_image_from_drawable (GdkDrawable *drawable);
145                             
146  G_END_DECLS
147  
148 Index: gtk/gtkdnd-quartz.c
149 ===================================================================
150 --- gtk/gtkdnd-quartz.c (revision 21475)
151 +++ gtk/gtkdnd-quartz.c (working copy)
152 @@ -1086,13 +1086,13 @@
153                 GdkPixbuf *pixbuf;
154  
155                 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 1, 1);
156 -               gdk_pixbuf_fill (pixbuf, 0xffffff);
157 -           
158 -               gtk_drag_set_icon_pixbuf (context,
159 -                                         pixbuf,
160 +               gdk_pixbuf_fill (pixbuf, 0xffffff);
161 +
162 +               gtk_drag_set_icon_pixbuf (context,
163 +                                         pixbuf,
164                                           0, 0);
165  
166 -               g_object_unref (pixbuf);
167 +               g_object_unref (pixbuf);
168               }
169             break;
170           case GTK_IMAGE_PIXBUF:
171 @@ -1668,7 +1668,20 @@
172                           gint               hot_x,
173                           gint               hot_y)
174  {
175 -  g_warning ("gtk_drag_set_icon_pixmap is not supported on Mac OS X");
176 +  GdkPixbuf *pixbuf;
177 +  
178 +  g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
179 +  g_return_if_fail (context->is_source);
180 +  g_return_if_fail (GDK_IS_COLORMAP (colormap));
181 +  g_return_if_fail (GDK_IS_PIXMAP (pixmap));
182 +  
183 +  pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap,
184 +                                        0, 0, /* src */
185 +                                        0, 0, /* dst */
186 +                                        -1, -1);
187 +  
188 +  gtk_drag_set_icon_pixbuf (context, pixbuf, hot_x, hot_y);
189 +  g_object_unref (pixbuf);
190  }
191  
192  /**
193 Index: gdk/quartz/gdkevents-quartz.c
194 ===================================================================
195 --- gdk/quartz/gdkevents-quartz.c       (revision 21475)
196 +++ gdk/quartz/gdkevents-quartz.c       (working copy)
197 @@ -112,6 +112,18 @@
198    return ((GdkEventPrivate *) event)->windowing_data;
199  }
200  
201 +/* A category that exposes the protected carbon event for an NSEvent. */
202 +@interface NSEvent (GdkQuartzNSEvent)
203 +- (void *)gdk_quartz_event_ref;
204 +@end 
205 +
206 +@implementation NSEvent (GdkQuartzNSEvent)
207 +- (void *)gdk_quartz_event_ref
208 +{
209 +  return _eventRef;
210 +}
211 +@end
212 +
213  void 
214  _gdk_events_init (void)
215  {
216 @@ -1670,6 +1682,65 @@
217  }
218  
219  static gboolean
220 +_gdk_quartz_possibly_forward_accelerator (NSEvent* nsevent)
221 +{
222 +  /* Special-case menu shortcut events. We create command events for
223 +   * those and forward to the corresponding menu.
224 +   */
225 +  if ((!_gdk_quartz_keyboard_grab_window ||
226 +       (_gdk_quartz_keyboard_grab_window && keyboard_grab_owner_events)) &&
227 +      [nsevent type] == NSKeyDown)
228 +    {
229 +      EventRef event_ref;
230 +      MenuRef menu_ref;
231 +      MenuItemIndex index;
232 +
233 +      event_ref = [nsevent gdk_quartz_event_ref];
234 +      if (IsMenuKeyEvent (NULL, event_ref,
235 +                          kMenuEventQueryOnly, 
236 +                          &menu_ref, &index))
237 +        {
238 +          MenuCommand menu_command;
239 +          HICommand hi_command;
240 +
241 +          if (GetMenuItemCommandID (menu_ref, index, &menu_command) != noErr)
242 +            return FALSE;
243 +   
244 +          hi_command.commandID = menu_command;
245 +          hi_command.menu.menuRef = menu_ref;
246 +          hi_command.menu.menuItemIndex = index;
247 +
248 +          CreateEvent (NULL, kEventClassCommand, kEventCommandProcess, 
249 +                       0, kEventAttributeUserEvent, &event_ref);
250 +          SetEventParameter (event_ref, kEventParamDirectObject, 
251 +                             typeHICommand, 
252 +                             sizeof (HICommand), &hi_command);
253 +
254 +          SendEventToEventTarget (event_ref, GetMenuEventTarget (menu_ref));
255 +
256 +          ReleaseEvent (event_ref);
257 +
258 +          return TRUE;
259 +        }
260 +    }
261 +  return FALSE;
262 +}
263 +
264 +gboolean
265 +gdk_quartz_possibly_forward (GdkEvent* event)
266 +{
267 +  NSEvent *nsevent;
268 +  g_return_val_if_fail (event != NULL, FALSE);
269 +
270 +  nsevent = ((GdkEventPrivate*)event)->windowing_data;
271 +
272 +  if (nsevent)
273 +    return _gdk_quartz_possibly_forward_accelerator (nsevent);
274 +
275 +  return FALSE;
276 +}
277 +
278 +static gboolean
279  gdk_event_translate (NSEvent *nsevent)
280  {
281    NSWindow *nswindow;