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