Re-added the NSApplication support code for Area on Mac OS X.
This commit is contained in:
parent
6b7660a671
commit
c6674d1e9e
|
@ -98,11 +98,9 @@ event(flagsChanged, areaView_flagsChanged)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
Class areaClass;
|
Class getAreaClass(void)
|
||||||
|
|
||||||
void initAreaClass(void)
|
|
||||||
{
|
{
|
||||||
areaClass = [areaView class];
|
return [areaView class];
|
||||||
}
|
}
|
||||||
|
|
||||||
id newArea(void *goarea)
|
id newArea(void *goarea)
|
||||||
|
|
|
@ -94,6 +94,7 @@ struct xpoint {
|
||||||
intptr_t x;
|
intptr_t x;
|
||||||
intptr_t y;
|
intptr_t y;
|
||||||
};
|
};
|
||||||
|
extern Class getAreaClass(void);
|
||||||
extern id newArea(void *);
|
extern id newArea(void *);
|
||||||
extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
|
extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
|
||||||
extern uintptr_t modifierFlags(id);
|
extern uintptr_t modifierFlags(id);
|
||||||
|
|
|
@ -4,6 +4,46 @@
|
||||||
#import "_cgo_export.h"
|
#import "_cgo_export.h"
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
static Class areaClass;
|
||||||
|
|
||||||
|
@interface goApplication : NSApplication
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation goApplication
|
||||||
|
|
||||||
|
// 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 appDelegateClass : NSObject <NSApplicationDelegate>
|
@interface appDelegateClass : NSObject <NSApplicationDelegate>
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -19,8 +59,9 @@ id getAppDelegate(void)
|
||||||
|
|
||||||
BOOL uiinit(void)
|
BOOL uiinit(void)
|
||||||
{
|
{
|
||||||
|
areaClass = getAreaClass();
|
||||||
appDelegate = [appDelegateClass new];
|
appDelegate = [appDelegateClass new];
|
||||||
[NSApplication sharedApplication];
|
[goApplication sharedApplication];
|
||||||
// don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy!
|
// don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy!
|
||||||
// see https://github.com/andlabs/ui/issues/6
|
// see https://github.com/andlabs/ui/issues/6
|
||||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
|
|
Loading…
Reference in New Issue