summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--area_darwin.m7
-rw-r--r--delegateuitask_darwin.m57
-rw-r--r--objc_darwin.h2
3 files changed, 49 insertions, 17 deletions
diff --git a/area_darwin.m b/area_darwin.m
index 6522ecc..5519f8b 100644
--- a/area_darwin.m
+++ b/area_darwin.m
@@ -101,6 +101,13 @@ event(flagsChanged, areaView_flagsChanged)
@end
+Class areaClass;
+
+void initAreaClass(void)
+{
+ areaClass = [areaView class];
+}
+
id makeArea(void)
{
return [[areaView alloc]
diff --git a/delegateuitask_darwin.m b/delegateuitask_darwin.m
index 09dcbfd..39bdaa1 100644
--- a/delegateuitask_darwin.m
+++ b/delegateuitask_darwin.m
@@ -35,10 +35,47 @@
#import <Foundation/NSAutoreleasePool.h>
#import <AppKit/NSEvent.h>
#import <AppKit/NSAlert.h>
-#import <AppKit/NSHelpManager.h>
extern NSRect dummyRect;
+@interface ourApplication : NSApplication
+@end
+
+@implementation ourApplication
+
+// by default, NSApplication eats some key events
+// this prevents that from happening with Area
+// see http://stackoverflow.com/questions/24099063/how-do-i-detect-keyup-in-my-nsview-with-the-command-key-held and http://lists.apple.com/archives/cocoa-dev/2003/Oct/msg00442.html
+- (void)sendEvent:(NSEvent *)e
+{
+ NSEventType type;
+
+ type = [e type];
+ if (type == NSKeyDown || type == NSKeyUp || type == NSFlagsChanged) {
+ id focused;
+
+ focused = [[e window] firstResponder];
+ // TODO can focused be nil? the isKindOfClass: docs don't say if it handles nil receivers
+ if ([focused isKindOfClass:areaClass])
+ switch (type) {
+ case NSKeyDown:
+ [focused keyDown:e];
+ return;
+ case NSKeyUp:
+ [focused keyUp:e];
+ return;
+ case NSFlagsChanged:
+ [focused flagsChanged:e];
+ return;
+ }
+ // else fall through
+ }
+ // otherwise, let NSApplication do it
+ [super sendEvent:e];
+}
+
+@end
+
@interface appDelegate : NSObject
@end
@@ -75,13 +112,6 @@ extern NSRect dummyRect;
{
}
-// see below
-// TODO is this the correct signature?
-- (void)helpbreaker:(NSNotification *)n
-{
- [NSHelpManager setContextHelpModeActive:NO];
-}
-
@end
id makeAppDelegate(void)
@@ -97,19 +127,12 @@ id windowGetContentView(id window)
BOOL initCocoa(id appDelegate)
{
dummyRect = NSMakeRect(0, 0, 100, 100);
- [NSApplication sharedApplication];
+ initAreaClass();
+ [ourApplication sharedApplication]; // makes NSApp an object of type ourApplication
if ([NSApp setActivationPolicy:NSApplicationActivationPolicyRegular] != YES)
return NO;
[NSApp activateIgnoringOtherApps:YES]; // TODO actually do C.NO here? Russ Cox does YES in his devdraw; the docs say the Finder does NO
[NSApp setDelegate:appDelegate];
- // by default, Mac OS X intercepts Help key keyDown events
- // we treat Help as Insert, so we don't want this behavior
- // this will override it; see http://stackoverflow.com/a/4078542/3408572
- // TODO this doesn't send keyDown:
- [[NSNotificationCenter defaultCenter] addObserver:appDelegate
- selector:@selector(helpbreaker:)
- name:NSContextHelpModeDidActivateNotification
- object:nil];
return YES;
}
diff --git a/objc_darwin.h b/objc_darwin.h
index d4707bc..1a29c39 100644
--- a/objc_darwin.h
+++ b/objc_darwin.h
@@ -43,6 +43,8 @@ extern void giveScrollViewBezelBorder(id);
extern id scrollViewContent(id);
/* area_darwin.m */
+extern Class areaClass;
+extern void initAreaClass(void);
extern id makeArea(void);
extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
extern uintptr_t modifierFlags(id);