1/*
2 * tkMacOSXEvent.c --
3 *
4 *	This file contains the basic Mac OS X Event handling routines.
5 *
6 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
7 * Copyright 2001-2009, Apple Inc.
8 * Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net>
9 *
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 *
13 * RCS: @(#) $Id$
14 */
15
16#include "tkMacOSXPrivate.h"
17#include "tkMacOSXEvent.h"
18#include "tkMacOSXDebug.h"
19
20#pragma mark TKApplication(TKEvent)
21
22enum {
23    NSWindowWillMoveEventType = 20
24};
25
26@implementation TKApplication(TKEvent)
27/* TODO: replace by +[addLocalMonitorForEventsMatchingMask ? */
28- (NSEvent *)tkProcessEvent:(NSEvent *)theEvent {
29#ifdef TK_MAC_DEBUG_EVENTS
30    TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent);
31#endif
32    NSEvent	    *processedEvent = theEvent;
33    NSEventType	    type = [theEvent type];
34    NSInteger	    subtype;
35    NSUInteger	    flags;
36
37    switch ((NSInteger)type) {
38    case NSAppKitDefined:
39        subtype = [theEvent subtype];
40
41	switch (subtype) {
42	case NSApplicationActivatedEventType:
43	    break;
44	case NSApplicationDeactivatedEventType:
45	    break;
46	case NSWindowExposedEventType:
47	case NSScreenChangedEventType:
48	    break;
49	case NSWindowMovedEventType:
50	    break;
51        case NSWindowWillMoveEventType:
52            break;
53
54        default:
55            break;
56	}
57	break;
58    case NSKeyUp:
59    case NSKeyDown:
60    case NSFlagsChanged:
61	flags = [theEvent modifierFlags];
62	processedEvent = [self tkProcessKeyEvent:theEvent];
63	break;
64    case NSLeftMouseDown:
65    case NSLeftMouseUp:
66    case NSRightMouseDown:
67    case NSRightMouseUp:
68    case NSLeftMouseDragged:
69    case NSRightMouseDragged:
70    case NSMouseMoved:
71    case NSMouseEntered:
72    case NSMouseExited:
73    case NSScrollWheel:
74    case NSOtherMouseDown:
75    case NSOtherMouseUp:
76    case NSOtherMouseDragged:
77    case NSTabletPoint:
78    case NSTabletProximity:
79	processedEvent = [self tkProcessMouseEvent:theEvent];
80	break;
81#if 0
82    case NSSystemDefined:
83        subtype = [theEvent subtype];
84	break;
85    case NSApplicationDefined: {
86	id win;
87	win = [theEvent window];
88	break;
89	}
90    case NSCursorUpdate:
91        break;
92#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
93    case NSEventTypeGesture:
94    case NSEventTypeMagnify:
95    case NSEventTypeRotate:
96    case NSEventTypeSwipe:
97    case NSEventTypeBeginGesture:
98    case NSEventTypeEndGesture:
99        break;
100#endif
101#endif
102
103    default:
104	break;
105    }
106    return processedEvent;
107}
108@end
109
110#pragma mark -
111
112/*
113 *----------------------------------------------------------------------
114 *
115 * TkMacOSXFlushWindows --
116 *
117 *	This routine flushes all the windows of the application. It is
118 *	called by XSync().
119 *
120 * Results:
121 *	None.
122 *
123 * Side effects:
124 *	Flushes all Carbon windows
125 *
126 *----------------------------------------------------------------------
127 */
128
129MODULE_SCOPE void
130TkMacOSXFlushWindows(void)
131{
132    NSInteger windowCount;
133    NSInteger *windowNumbers;
134
135    NSCountWindows(&windowCount);
136    if(windowCount) {
137	windowNumbers = (NSInteger *) ckalloc(windowCount * sizeof(NSInteger));
138	NSWindowList(windowCount, windowNumbers);
139	for (NSInteger index = 0; index < windowCount; index++) {
140	    NSWindow *w = [NSApp windowWithWindowNumber:windowNumbers[index]];
141	    if (TkMacOSXGetXWindow(w)) {
142		[w flushWindow];
143	    }
144	}
145	ckfree((char*) windowNumbers);
146    }
147}
148
149/*
150 * Local Variables:
151 * mode: c
152 * c-basic-offset: 4
153 * fill-column: 79
154 * coding: utf-8
155 * End:
156 */
157