3 * Copyright (C) 2005 Imendio AB
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #import "GdkQuartzWindow.h"
23 #include "gdkwindow-quartz.h"
24 #include "gdkprivate-quartz.h"
26 @implementation GdkQuartzWindow
28 -(BOOL)windowShouldClose:(id)sender
30 GdkWindow *window = [[self contentView] gdkWindow];
33 event = gdk_event_new (GDK_DELETE);
35 event->any.window = g_object_ref (window);
36 event->any.send_event = FALSE;
38 _gdk_event_queue_append (gdk_display_get_default (), event);
43 -(void)windowDidMiniaturize:(NSNotification *)aNotification
45 GdkWindow *window = [[self contentView] gdkWindow];
47 gdk_synthesize_window_state (window, 0,
48 GDK_WINDOW_STATE_ICONIFIED);
51 -(void)windowDidDeminiaturize:(NSNotification *)aNotification
53 GdkWindow *window = [[self contentView] gdkWindow];
55 gdk_synthesize_window_state (window, GDK_WINDOW_STATE_ICONIFIED, 0);
58 -(void)windowDidBecomeKey:(NSNotification *)aNotification
60 GdkWindow *window = [[self contentView] gdkWindow];
62 _gdk_quartz_update_focus_window (window);
65 -(void)windowDidMove:(NSNotification *)aNotification
67 NSRect content_rect = [self contentRectForFrameRect:[self frame]];
68 GdkWindow *window = [[self contentView] gdkWindow];
69 GdkWindowObject *private = (GdkWindowObject *)window;
70 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
73 private->x = content_rect.origin.x;
74 private->y = _gdk_quartz_get_inverted_screen_y (content_rect.origin.y) - impl->height;
76 /* Synthesize a configure event */
77 event = gdk_event_new (GDK_CONFIGURE);
78 event->configure.window = g_object_ref (window);
79 event->configure.x = private->x;
80 event->configure.y = private->y;
81 event->configure.width = impl->width;
82 event->configure.height = impl->height;
84 _gdk_event_queue_append (gdk_display_get_default (), event);
87 -(void)windowDidResize:(NSNotification *)aNotification
89 NSRect content_rect = [self contentRectForFrameRect:[self frame]];
90 GdkWindow *window = [[self contentView] gdkWindow];
91 GdkWindowObject *private = (GdkWindowObject *)window;
92 GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
95 impl->width = content_rect.size.width;
96 impl->height = content_rect.size.height;
98 /* Synthesize a configure event */
100 event = gdk_event_new (GDK_CONFIGURE);
101 event->configure.window = g_object_ref (window);
102 event->configure.x = private->x;
103 event->configure.y = private->y;
104 event->configure.width = impl->width;
105 event->configure.height = impl->height;
107 _gdk_event_queue_append (gdk_display_get_default (), event);
109 /* Update tracking rectangle */
110 [[self contentView] removeTrackingRect:impl->tracking_rect];
111 impl->tracking_rect = [impl->view addTrackingRect:NSMakeRect(0, 0, impl->width, impl->height)
117 -(id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
119 self = [super initWithContentRect:contentRect
125 /* A possible modification here would be to only accept mouse moved events
126 * if any of the child GdkWindows are interested in mouse moved events.
128 [self setAcceptsMouseMovedEvents:YES];
130 [self setDelegate:self];
131 [self setReleasedWhenClosed:YES];
136 -(BOOL)canBecomeMainWindow
141 -(BOOL)canBecomeKeyWindow
146 static GdkDragContext *current_context = NULL;
149 drag_operation_to_drag_action (NSDragOperation operation)
151 GdkDragAction result = 0;
153 if (operation & NSDragOperationGeneric)
154 result |= GDK_ACTION_COPY;
159 static NSDragOperation
160 drag_action_to_drag_operation (GdkDragAction action)
162 NSDragOperation result = 0;
164 if (action & GDK_ACTION_COPY)
165 result |= NSDragOperationCopy;
171 update_context_from_dragging_info (id <NSDraggingInfo> sender)
173 g_assert (current_context != NULL);
175 GDK_DRAG_CONTEXT_PRIVATE (current_context)->dragging_info = sender;
176 current_context->suggested_action = drag_operation_to_drag_action ([sender draggingSourceOperationMask]);
179 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
184 g_object_unref (current_context);
186 current_context = gdk_drag_context_new ();
187 update_context_from_dragging_info (sender);
189 event.dnd.type = GDK_DRAG_ENTER;
190 event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
191 event.dnd.send_event = FALSE;
192 event.dnd.context = current_context;
193 event.dnd.time = GDK_CURRENT_TIME;
195 (*_gdk_event_func) (&event, _gdk_event_data);
197 return NSDragOperationNone;
200 - (void)draggingEnded:(id <NSDraggingInfo>)sender
202 g_object_unref (current_context);
203 current_context = NULL;
206 - (void)draggingExited:(id <NSDraggingInfo>)sender
210 event.dnd.type = GDK_DRAG_LEAVE;
211 event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
212 event.dnd.send_event = FALSE;
213 event.dnd.context = current_context;
214 event.dnd.time = GDK_CURRENT_TIME;
216 (*_gdk_event_func) (&event, _gdk_event_data);
218 g_object_unref (current_context);
219 current_context = NULL;
222 - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
224 NSPoint point = [sender draggingLocation];
225 NSPoint screen_point = [self convertBaseToScreen:point];
228 update_context_from_dragging_info (sender);
230 event.dnd.type = GDK_DRAG_MOTION;
231 event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
232 event.dnd.send_event = FALSE;
233 event.dnd.context = current_context;
234 event.dnd.time = GDK_CURRENT_TIME;
235 event.dnd.x_root = screen_point.x;
236 event.dnd.y_root = _gdk_quartz_get_inverted_screen_y (screen_point.y);
238 (*_gdk_event_func) (&event, _gdk_event_data);
240 g_object_unref (event.dnd.window);
242 return drag_action_to_drag_operation (current_context->action);
245 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
247 NSPoint point = [sender draggingLocation];
248 NSPoint screen_point = [self convertBaseToScreen:point];
251 update_context_from_dragging_info (sender);
253 event.dnd.type = GDK_DROP_START;
254 event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
255 event.dnd.send_event = FALSE;
256 event.dnd.context = current_context;
257 event.dnd.time = GDK_CURRENT_TIME;
258 event.dnd.x_root = screen_point.x;
259 event.dnd.y_root = _gdk_quartz_get_inverted_screen_y (screen_point.y);
261 (*_gdk_event_func) (&event, _gdk_event_data);
263 g_object_unref (event.dnd.window);
265 g_object_unref (current_context);
266 current_context = NULL;
271 - (BOOL)wantsPeriodicDraggingUpdates
276 - (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
280 g_assert (_gdk_quartz_drag_source_context != NULL);
282 event.dnd.type = GDK_DROP_FINISHED;
283 event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
284 event.dnd.send_event = FALSE;
285 event.dnd.context = _gdk_quartz_drag_source_context;
287 (*_gdk_event_func) (&event, _gdk_event_data);
289 g_object_unref (event.dnd.window);
291 g_object_unref (_gdk_quartz_drag_source_context);
292 _gdk_quartz_drag_source_context = NULL;