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