Fixed a lot of Area.OpenTextFieldAt(); thanks to mikeash in irc.freenode.net/#macdev.
This commit is contained in:
parent
89ea8f5cbb
commit
84e7d24a5c
|
@ -29,7 +29,8 @@ func newArea(ab *areabase) Area {
|
|||
a._id = C.newArea(unsafe.Pointer(a))
|
||||
a.scroller = newScroller(a._id, false) // no border on Area
|
||||
a.SetSize(a.width, a.height)
|
||||
a.textfield = C.newAreaTextField(a._id, unsafe.Pointer(a))
|
||||
a.textfield = C.newTextField()
|
||||
C.areaSetTextField(a._id, a.textfield)
|
||||
return a
|
||||
}
|
||||
|
||||
|
@ -62,7 +63,7 @@ func (a *area) OpenTextFieldAt(x, y int) {
|
|||
if x < 0 || x >= a.width || y < 0 || y >= a.height {
|
||||
panic(fmt.Errorf("point (%d,%d) outside Area in Area.OpenTextFieldAt()", x, y))
|
||||
}
|
||||
C.areaTextFieldOpen(a.textfield, C.intptr_t(x), C.intptr_t(y))
|
||||
C.areaTextFieldOpen(a._id, a.textfield, C.intptr_t(x), C.intptr_t(y))
|
||||
}
|
||||
|
||||
func (a *area) TextFieldText() string {
|
||||
|
@ -82,6 +83,8 @@ func (a *area) OnTextFieldDismissed(f func()) {
|
|||
//export areaTextFieldDismissed
|
||||
func areaTextFieldDismissed(data unsafe.Pointer) {
|
||||
a := (*area)(unsafe.Pointer(data))
|
||||
// TODO does not work?
|
||||
C.controlSetHidden(a.textfield, C.YES)
|
||||
a.textfielddone.fire()
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#define toNSUInteger(x) ((NSUInteger) (x))
|
||||
#define fromNSUInteger(x) ((uintptr_t) (x))
|
||||
|
||||
@interface goAreaView : NSView {
|
||||
@interface goAreaView : NSView <NSTextFieldDelegate> {
|
||||
@public
|
||||
void *goarea;
|
||||
NSTrackingArea *trackingArea;
|
||||
|
@ -100,6 +100,12 @@ retevent(doKeyDown, areaView_keyDown)
|
|||
retevent(doKeyUp, areaView_keyUp)
|
||||
retevent(doFlagsChanged, areaView_flagsChanged)
|
||||
|
||||
- (BOOL)control:(NSControl *)c textShouldEndEditing:(NSText *)t
|
||||
{
|
||||
areaTextFieldDismissed(self->goarea);
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Class getAreaClass(void)
|
||||
|
@ -205,42 +211,23 @@ void areaRepaintAll(id view)
|
|||
[toNSView(view) display];
|
||||
}
|
||||
|
||||
@interface goAreaTextField : NSTextField {
|
||||
@public
|
||||
void *goarea;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation goAreaTextField
|
||||
/*
|
||||
- (BOOL)resignFirstResponder
|
||||
void areaSetTextField(id area, id textfield)
|
||||
{
|
||||
[self setHidden:YES];
|
||||
areaTextFieldDismissed(self->goarea);
|
||||
return [super resignFirstResponder];
|
||||
}
|
||||
*/
|
||||
@end
|
||||
goAreaView *a = (goAreaView *) area;
|
||||
NSTextField *tf = toNSTextField(textfield);
|
||||
|
||||
id newAreaTextField(id area, void *goarea)
|
||||
{
|
||||
goAreaTextField *tf;
|
||||
|
||||
tf = [[goAreaTextField alloc] initWithFrame:NSZeroRect];
|
||||
finishNewTextField((id) tf, YES);
|
||||
[toNSView(area) addSubview:tf];
|
||||
[tf setHidden:YES];
|
||||
tf->goarea = goarea;
|
||||
return (id) tf;
|
||||
[tf setDelegate:a];
|
||||
[a addSubview:tf];
|
||||
}
|
||||
|
||||
void areaTextFieldOpen(id textfield, intptr_t x, intptr_t y)
|
||||
void areaTextFieldOpen(id area, id textfield, intptr_t x, intptr_t y)
|
||||
{
|
||||
goAreaView *a = (goAreaView *) area;
|
||||
NSTextField *tf = toNSTextField(textfield);
|
||||
|
||||
[tf sizeToFit];
|
||||
// TODO
|
||||
[tf setFrameSize:NSMakeSize(150, 20)];
|
||||
[tf setFrameSize:NSMakeSize(150, [tf frame].size.height)];
|
||||
[tf setFrameOrigin:NSMakePoint((CGFloat) x, (CGFloat) y)];
|
||||
[tf setHidden:NO];
|
||||
[[tf window] makeFirstResponder:tf];
|
||||
|
|
|
@ -128,8 +128,10 @@ extern uintptr_t pressedMouseButtons(void);
|
|||
extern uintptr_t keyCode(id);
|
||||
extern void areaRepaint(id, struct xrect);
|
||||
extern void areaRepaintAll(id);
|
||||
extern id newAreaTextField(id, void *);
|
||||
extern void areaTextFieldOpen(id, intptr_t, intptr_t);
|
||||
extern void areaTextFieldOpen(id, id, intptr_t, intptr_t);
|
||||
extern void areaSetTextField(id, id);
|
||||
extern void areaEndTextFieldEditing(id, id);
|
||||
|
||||
|
||||
/* common_darwin.m */
|
||||
extern void disableAutocorrect(id);
|
||||
|
|
Loading…
Reference in New Issue