* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
#include <stdlib.h>
#include <string.h>
-#include "gdkconfig.h"
-
-#include "gdk/gdkkeysyms.h"
+#include "gdk/gdk.h"
#include "gtkdnd.h"
#include "gtkiconfactory.h"
#include "gtkicontheme.h"
-#include "gtkimage.h"
+#include "gtkimageprivate.h"
#include "gtkinvisible.h"
#include "gtkmain.h"
#include "gtkplug.h"
#include "gtkintl.h"
#include "gtkquartz.h"
#include "gdk/quartz/gdkquartz.h"
+#include "gtkselectionprivate.h"
typedef struct _GtkDragSourceSite GtkDragSourceSite;
typedef struct _GtkDragSourceInfo GtkDragSourceInfo;
selection_data.data = NULL;
selection_data.length = -1;
selection_data.target = _gtk_quartz_pasteboard_type_to_atom (type);
+ selection_data.display = gdk_display_get_default ();
if (gtk_target_list_find (info->target_list,
selection_data.target,
{
gtk_drag_finish (context,
(selection_data->length >= 0),
- (context->action == GDK_ACTION_MOVE),
+ (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
time);
}
}
{
int width = gtk_widget_get_allocated_width (widget);
int height = gtk_widget_get_allocated_height (widget);
+ GtkStyleContext *context = gtk_widget_get_style_context (widget);
+
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_DND);
+
+ gtk_render_frame (context, cr, 0, 0, width, height);
- gtk_paint_shadow (gtk_widget_get_style (widget), cr,
- GTK_STATE_NORMAL, GTK_SHADOW_OUT,
- widget, "dnd",
- 0, 0, width, height);
+ gtk_style_context_restore (context);
cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
cairo_set_line_width (cr, 1.0);
if (site->track_motion || site->flags & GTK_DEST_DEFAULT_MOTION)
{
- if (context->suggested_action & site->actions)
- action = context->suggested_action;
+ if (gdk_drag_context_get_suggested_action (context) & site->actions)
+ action = gdk_drag_context_get_suggested_action (context);
if (action && gtk_drag_dest_find_target (widget, context, NULL))
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), GDK_NONE);
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_NONE);
- g_return_val_if_fail (!context->is_source, GDK_NONE);
dragging_info = gdk_quartz_drag_context_get_dragging_info_libgtk_only (context);
pasteboard = [dragging_info draggingPasteboard];
[types release];
if ((nswindow = get_toplevel_nswindow (info->source_widget)) == NULL)
- return FALSE;
+ return G_SOURCE_REMOVE;
/* Ref the context. It's unreffed when the drag has been aborted */
g_object_ref (info->context);
point = [info->nsevent locationInWindow];
drag_image = _gtk_quartz_create_image_from_pixbuf (info->icon_pixbuf);
+ if (drag_image == NULL)
+ {
+ g_object_unref (info->context);
+ return G_SOURCE_REMOVE;
+ }
point.x -= info->hot_x;
point.y -= info->hot_y;
[pool release];
- return FALSE;
+ return G_SOURCE_REMOVE;
}
+/* Fake protocol to let us call GdkNSView gdkWindow without including
+ * gdk/GdkNSView.h (which we can't because it pulls in the internal-only
+ * gdkwindow.h).
+ */
+@protocol GdkNSView
+- (GdkWindow *)gdkWindow;
+@end
static GdkDragContext *
gtk_drag_begin_internal (GtkWidget *widget,
GdkEvent *event)
{
GtkDragSourceInfo *info;
+ GdkDevice *pointer;
+ GdkWindow *window;
GdkDragContext *context;
- NSWindow *nswindow;
+ NSWindow *nswindow = get_toplevel_nswindow (widget);
+ NSPoint point = {0, 0};
+ gdouble x, y;
+ double time = (double)g_get_real_time ();
+ NSEvent *nsevent;
+ NSTimeInterval nstime;
+
+ if (event)
+ {
+ if (gdk_event_get_coords (event, &x, &y))
+ {
+ point.x = x;
+ point.y = y;
+ }
+ time = (double)gdk_event_get_time (event);
+ }
- context = gdk_drag_begin (NULL, NULL);
- context->is_source = TRUE;
+ nstime = [[NSDate dateWithTimeIntervalSince1970: time / 1000] timeIntervalSinceReferenceDate];
+ nsevent = [NSEvent mouseEventWithType: NSLeftMouseDown
+ location: point
+ modifierFlags: 0
+ timestamp: nstime
+ windowNumber: [nswindow windowNumber]
+ context: [nswindow graphicsContext]
+ eventNumber: 0
+ clickCount: 1
+ pressure: 0.0 ];
+
+ window = [(id<GdkNSView>)[nswindow contentView] gdkWindow];
+ g_return_val_if_fail (nsevent != NULL, NULL);
+
+ context = gdk_drag_begin (window, NULL);
+ g_return_val_if_fail (context != NULL, NULL);
info = gtk_drag_get_source_info (context, TRUE);
-
+ info->nsevent = nsevent;
+ [info->nsevent retain];
+
info->source_widget = g_object_ref (widget);
info->widget = g_object_ref (widget);
info->target_list = target_list;
gtk_target_list_ref (target_list);
info->possible_actions = actions;
-
+
g_signal_emit_by_name (widget, "drag-begin", info->context);
/* Ensure that we have an icon before we start the drag; the
if (!info->icon_pixbuf)
{
if (!site || site->icon_type == GTK_IMAGE_EMPTY)
- gtk_drag_set_icon_default (context);
+ gtk_drag_set_icon_default (context);
else
- switch (site->icon_type)
- {
- case GTK_IMAGE_PIXBUF:
- gtk_drag_set_icon_pixbuf (context,
- site->icon_data.pixbuf.pixbuf,
- -2, -2);
- break;
- case GTK_IMAGE_STOCK:
- gtk_drag_set_icon_stock (context,
- site->icon_data.stock.stock_id,
- -2, -2);
- break;
- case GTK_IMAGE_ICON_NAME:
- gtk_drag_set_icon_name (context,
- site->icon_data.name.icon_name,
- -2, -2);
- break;
- case GTK_IMAGE_EMPTY:
- default:
- g_assert_not_reached();
- break;
- }
+ {
+ switch (site->icon_type)
+ {
+ case GTK_IMAGE_PIXBUF:
+ gtk_drag_set_icon_pixbuf (context,
+ site->icon_data.pixbuf.pixbuf,
+ -2, -2);
+ break;
+ case GTK_IMAGE_STOCK:
+ gtk_drag_set_icon_stock (context,
+ site->icon_data.stock.stock_id,
+ -2, -2);
+ break;
+ case GTK_IMAGE_ICON_NAME:
+ gtk_drag_set_icon_name (context,
+ site->icon_data.name.icon_name,
+ -2, -2);
+ break;
+ case GTK_IMAGE_EMPTY:
+ default:
+ g_assert_not_reached();
+ break;
+ }
+ }
}
- nswindow = get_toplevel_nswindow (widget);
- info->nsevent = [nswindow currentEvent];
- [info->nsevent retain];
-
/* drag will begin in an idle handler to avoid nested run loops */
g_idle_add_full (G_PRIORITY_HIGH_IDLE, gtk_drag_begin_idle, context, NULL);
- gdk_pointer_ungrab (0);
+ pointer = gdk_drag_context_get_device (info->context);
+ gdk_device_ungrab (pointer, 0);
return context;
}
gint hot_y)
{
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
g_return_if_fail (GTK_IS_WIDGET (widget));
g_warning ("gtk_drag_set_icon_widget is not supported on Mac OS X");
if (stock_id)
{
pixbuf = gtk_widget_render_icon_pixbuf (info->widget, stock_id,
- GTK_ICON_SIZE_DND, NULL);
+ GTK_ICON_SIZE_DND);
if (!pixbuf)
{
gint hot_y)
{
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y);
{
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
g_return_if_fail (stock_id != NULL);
set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y);
double x_offset, y_offset;
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
g_return_if_fail (surface != NULL);
_gtk_cairo_surface_extents (surface, &extents);
gint width, height, icon_size;
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
g_return_if_fail (icon_name != NULL);
- screen = gdk_window_get_screen (context->source_window);
+ screen = gdk_window_get_screen (gdk_drag_context_get_source_window (context));
g_return_if_fail (screen != NULL);
settings = gtk_settings_get_for_screen (screen);
gtk_drag_set_icon_default (GdkDragContext *context)
{
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
gtk_drag_set_icon_stock (context, GTK_STOCK_DND, -2, -2);
}
static void
gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
{
+ NSPasteboard *pasteboard;
+ NSAutoreleasePool *pool;
+
if (info->icon_pixbuf)
g_object_unref (info->icon_pixbuf);
gtk_target_list_unref (info->target_list);
+ pool = [[NSAutoreleasePool alloc] init];
+
+ /* Empty the pasteboard, so that it will not accidentally access
+ * info->context after it has been destroyed.
+ */
+ pasteboard = [NSPasteboard pasteboardWithName: NSDragPboard];
+ [pasteboard declareTypes: nil owner: nil];
+
+ [pool release];
+
gtk_drag_clear_source_info (info->context);
g_object_unref (info->context);
g_free (info);
+ info = NULL;
}
static gboolean
drag_drop_finished_idle_cb (gpointer data)
{
gtk_drag_source_info_destroy (data);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static void