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, TRUE);
65
-(void)windowDidResignKey:(NSNotification *)aNotification
67
GdkWindow *window = [[self contentView] gdkWindow];
69
_gdk_quartz_update_focus_window (window, FALSE);
72
-(void)windowDidMove:(NSNotification *)aNotification
74
NSRect content_rect = [self contentRectForFrameRect:[self frame]];
75
GdkWindow *window = [[self contentView] gdkWindow];
76
GdkWindowObject *private = (GdkWindowObject *)window;
77
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
80
private->x = content_rect.origin.x;
81
private->y = _gdk_quartz_get_inverted_screen_y (content_rect.origin.y) - impl->height;
83
/* Synthesize a configure event */
84
event = gdk_event_new (GDK_CONFIGURE);
85
event->configure.window = g_object_ref (window);
86
event->configure.x = private->x;
87
event->configure.y = private->y;
88
event->configure.width = impl->width;
89
event->configure.height = impl->height;
91
_gdk_event_queue_append (gdk_display_get_default (), event);
94
-(void)windowDidResize:(NSNotification *)aNotification
96
NSRect content_rect = [self contentRectForFrameRect:[self frame]];
97
GdkWindow *window = [[self contentView] gdkWindow];
98
GdkWindowObject *private = (GdkWindowObject *)window;
99
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
102
impl->width = content_rect.size.width;
103
impl->height = content_rect.size.height;
105
/* Synthesize a configure event */
107
event = gdk_event_new (GDK_CONFIGURE);
108
event->configure.window = g_object_ref (window);
109
event->configure.x = private->x;
110
event->configure.y = private->y;
111
event->configure.width = impl->width;
112
event->configure.height = impl->height;
114
_gdk_event_queue_append (gdk_display_get_default (), event);
116
/* Update tracking rectangle */
117
[[self contentView] removeTrackingRect:impl->tracking_rect];
118
impl->tracking_rect = [impl->view addTrackingRect:NSMakeRect(0, 0, impl->width, impl->height)
124
-(id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
126
self = [super initWithContentRect:contentRect
132
/* A possible modification here would be to only accept mouse moved events
133
* if any of the child GdkWindows are interested in mouse moved events.
135
[self setAcceptsMouseMovedEvents:YES];
137
[self setDelegate:self];
138
[self setReleasedWhenClosed:YES];
143
-(BOOL)canBecomeMainWindow
145
GdkWindow *window = [[self contentView] gdkWindow];
146
GdkWindowObject *private = (GdkWindowObject *)window;
147
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
149
switch (impl->type_hint)
151
case GDK_WINDOW_TYPE_HINT_NORMAL:
152
case GDK_WINDOW_TYPE_HINT_DIALOG:
155
case GDK_WINDOW_TYPE_HINT_MENU:
156
case GDK_WINDOW_TYPE_HINT_TOOLBAR:
157
case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
158
case GDK_WINDOW_TYPE_HINT_UTILITY:
159
case GDK_WINDOW_TYPE_HINT_DOCK:
160
case GDK_WINDOW_TYPE_HINT_DESKTOP:
161
case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
162
case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
163
case GDK_WINDOW_TYPE_HINT_TOOLTIP:
164
case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
165
case GDK_WINDOW_TYPE_HINT_COMBO:
166
case GDK_WINDOW_TYPE_HINT_DND:
173
-(BOOL)canBecomeKeyWindow
175
GdkWindow *window = [[self contentView] gdkWindow];
176
GdkWindowObject *private = (GdkWindowObject *)window;
177
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
179
/* FIXME: Is this right? If so, the switch shouldn't be needed. Need
180
* this + some tweaking to the event/grab code to get menus
183
/*if (private->window_type == GDK_WINDOW_TEMP)
187
switch (impl->type_hint)
189
case GDK_WINDOW_TYPE_HINT_NORMAL:
190
case GDK_WINDOW_TYPE_HINT_DIALOG:
191
case GDK_WINDOW_TYPE_HINT_MENU:
192
case GDK_WINDOW_TYPE_HINT_TOOLBAR:
193
case GDK_WINDOW_TYPE_HINT_UTILITY:
194
case GDK_WINDOW_TYPE_HINT_DOCK:
195
case GDK_WINDOW_TYPE_HINT_DESKTOP:
196
case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
197
case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
198
case GDK_WINDOW_TYPE_HINT_COMBO:
201
case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
202
case GDK_WINDOW_TYPE_HINT_TOOLTIP:
203
case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
204
case GDK_WINDOW_TYPE_HINT_DND:
211
static GdkDragContext *current_context = NULL;
214
drag_operation_to_drag_action (NSDragOperation operation)
216
GdkDragAction result = 0;
218
if (operation & NSDragOperationGeneric)
219
result |= GDK_ACTION_COPY;
224
static NSDragOperation
225
drag_action_to_drag_operation (GdkDragAction action)
227
NSDragOperation result = 0;
229
if (action & GDK_ACTION_COPY)
230
result |= NSDragOperationCopy;
236
update_context_from_dragging_info (id <NSDraggingInfo> sender)
238
g_assert (current_context != NULL);
240
GDK_DRAG_CONTEXT_PRIVATE (current_context)->dragging_info = sender;
241
current_context->suggested_action = drag_operation_to_drag_action ([sender draggingSourceOperationMask]);
244
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
249
g_object_unref (current_context);
251
current_context = gdk_drag_context_new ();
252
update_context_from_dragging_info (sender);
254
event.dnd.type = GDK_DRAG_ENTER;
255
event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
256
event.dnd.send_event = FALSE;
257
event.dnd.context = current_context;
258
event.dnd.time = GDK_CURRENT_TIME;
260
(*_gdk_event_func) (&event, _gdk_event_data);
262
return NSDragOperationNone;
265
- (void)draggingEnded:(id <NSDraggingInfo>)sender
267
g_object_unref (current_context);
268
current_context = NULL;
271
- (void)draggingExited:(id <NSDraggingInfo>)sender
275
event.dnd.type = GDK_DRAG_LEAVE;
276
event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
277
event.dnd.send_event = FALSE;
278
event.dnd.context = current_context;
279
event.dnd.time = GDK_CURRENT_TIME;
281
(*_gdk_event_func) (&event, _gdk_event_data);
283
g_object_unref (current_context);
284
current_context = NULL;
287
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
289
NSPoint point = [sender draggingLocation];
290
NSPoint screen_point = [self convertBaseToScreen:point];
293
update_context_from_dragging_info (sender);
295
event.dnd.type = GDK_DRAG_MOTION;
296
event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
297
event.dnd.send_event = FALSE;
298
event.dnd.context = current_context;
299
event.dnd.time = GDK_CURRENT_TIME;
300
event.dnd.x_root = screen_point.x;
301
event.dnd.y_root = _gdk_quartz_get_inverted_screen_y (screen_point.y);
303
(*_gdk_event_func) (&event, _gdk_event_data);
305
g_object_unref (event.dnd.window);
307
return drag_action_to_drag_operation (current_context->action);
310
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
312
NSPoint point = [sender draggingLocation];
313
NSPoint screen_point = [self convertBaseToScreen:point];
316
update_context_from_dragging_info (sender);
318
event.dnd.type = GDK_DROP_START;
319
event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
320
event.dnd.send_event = FALSE;
321
event.dnd.context = current_context;
322
event.dnd.time = GDK_CURRENT_TIME;
323
event.dnd.x_root = screen_point.x;
324
event.dnd.y_root = _gdk_quartz_get_inverted_screen_y (screen_point.y);
326
(*_gdk_event_func) (&event, _gdk_event_data);
328
g_object_unref (event.dnd.window);
330
g_object_unref (current_context);
331
current_context = NULL;
336
- (BOOL)wantsPeriodicDraggingUpdates
341
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
345
g_assert (_gdk_quartz_drag_source_context != NULL);
347
event.dnd.type = GDK_DROP_FINISHED;
348
event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
349
event.dnd.send_event = FALSE;
350
event.dnd.context = _gdk_quartz_drag_source_context;
352
(*_gdk_event_func) (&event, _gdk_event_data);
354
g_object_unref (event.dnd.window);
356
g_object_unref (_gdk_quartz_drag_source_context);
357
_gdk_quartz_drag_source_context = NULL;