Fixed Mac OS X Area.OpenTextFieldAt() not behaving properly. The behavior is still a little weird now, but permissible.

This commit is contained in:
Pietro Gagliardi 2014-08-29 17:43:54 -04:00
parent a4574d5828
commit 54efcdc5d6
2 changed files with 5 additions and 4 deletions

View File

@ -49,7 +49,7 @@ type Area interface {
// It panics if the coordinates fall outside the Area.
// Any text previously in the TextField (be it by the user or by a call to SetTextFieldText()) is retained.
// The TextField receives the input focus so the user can type things; when the TextField loses the input focus, it hides itself and signals the event set by OnTextFieldDismissed.
// TODO escape key
// The TextField will also dismiss itself on some platforms when the user "completes editing"; the exact meaning of this is platform-specific.
OpenTextFieldAt(x int, y int)
// TextFieldText and TextFieldSetText get and set the OpenTextFieldAt TextField's text, respectively.

View File

@ -6,6 +6,7 @@
#define toNSEvent(x) ((NSEvent *) (x))
#define toNSView(x) ((NSView *) (x))
#define toNSObject(x) ((NSObject *) (x))
#define toNSTextField(x) ((NSTextField *) (x))
#define toNSInteger(x) ((NSInteger) (x))
@ -100,10 +101,10 @@ retevent(doKeyDown, areaView_keyDown)
retevent(doKeyUp, areaView_keyUp)
retevent(doFlagsChanged, areaView_flagsChanged)
- (BOOL)control:(NSControl *)c textShouldEndEditing:(NSText *)t
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
areaTextFieldDismissed(self->goarea);
return YES;
[toNSObject(object) removeObserver:self forKeyPath:@"firstResponder"];
}
@end
@ -216,7 +217,6 @@ void areaSetTextField(id area, id textfield)
goAreaView *a = (goAreaView *) area;
NSTextField *tf = toNSTextField(textfield);
[tf setDelegate:a];
[a addSubview:tf];
}
@ -231,4 +231,5 @@ void areaTextFieldOpen(id area, id textfield, intptr_t x, intptr_t y)
[tf setFrameOrigin:NSMakePoint((CGFloat) x, (CGFloat) y)];
[tf setHidden:NO];
[[tf window] makeFirstResponder:tf];
[[tf window] addObserver:a forKeyPath:@"firstResponder" options:NSKeyValueObservingOptionNew context:NULL];
}