Started the Mac OS X implementation of Area.OpenTextFieldAt().
This commit is contained in:
parent
c7268f8fee
commit
89ea8f5cbb
|
@ -3,6 +3,7 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -14,17 +15,21 @@ import "C"
|
||||||
type area struct {
|
type area struct {
|
||||||
*areabase
|
*areabase
|
||||||
|
|
||||||
_id C.id
|
_id C.id
|
||||||
scroller *scroller
|
scroller *scroller
|
||||||
|
textfield C.id
|
||||||
|
textfielddone *event
|
||||||
}
|
}
|
||||||
|
|
||||||
func newArea(ab *areabase) Area {
|
func newArea(ab *areabase) Area {
|
||||||
a := &area{
|
a := &area{
|
||||||
areabase: ab,
|
areabase: ab,
|
||||||
|
textfielddone: newEvent(),
|
||||||
}
|
}
|
||||||
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))
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +58,33 @@ func (a *area) RepaintAll() {
|
||||||
C.areaRepaintAll(a._id)
|
C.areaRepaintAll(a._id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *area) TextFieldText() string {
|
||||||
|
return C.GoString(C.textFieldText(a.textfield))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *area) SetTextFieldText(text string) {
|
||||||
|
ctext := C.CString(text)
|
||||||
|
defer C.free(unsafe.Pointer(ctext))
|
||||||
|
C.textFieldSetText(a.textfield, ctext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *area) OnTextFieldDismissed(f func()) {
|
||||||
|
a.textfielddone.set(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
//export areaTextFieldDismissed
|
||||||
|
func areaTextFieldDismissed(data unsafe.Pointer) {
|
||||||
|
a := (*area)(unsafe.Pointer(data))
|
||||||
|
a.textfielddone.fire()
|
||||||
|
}
|
||||||
|
|
||||||
//export areaView_drawRect
|
//export areaView_drawRect
|
||||||
func areaView_drawRect(self C.id, rect C.struct_xrect, data unsafe.Pointer) {
|
func areaView_drawRect(self C.id, rect C.struct_xrect, data unsafe.Pointer) {
|
||||||
a := (*area)(data)
|
a := (*area)(data)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#define toNSEvent(x) ((NSEvent *) (x))
|
#define toNSEvent(x) ((NSEvent *) (x))
|
||||||
#define toNSView(x) ((NSView *) (x))
|
#define toNSView(x) ((NSView *) (x))
|
||||||
|
#define toNSTextField(x) ((NSTextField *) (x))
|
||||||
|
|
||||||
#define toNSInteger(x) ((NSInteger) (x))
|
#define toNSInteger(x) ((NSInteger) (x))
|
||||||
#define fromNSInteger(x) ((intptr_t) (x))
|
#define fromNSInteger(x) ((intptr_t) (x))
|
||||||
|
@ -203,3 +204,44 @@ void areaRepaintAll(id view)
|
||||||
{
|
{
|
||||||
[toNSView(view) display];
|
[toNSView(view) display];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface goAreaTextField : NSTextField {
|
||||||
|
@public
|
||||||
|
void *goarea;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation goAreaTextField
|
||||||
|
/*
|
||||||
|
- (BOOL)resignFirstResponder
|
||||||
|
{
|
||||||
|
[self setHidden:YES];
|
||||||
|
areaTextFieldDismissed(self->goarea);
|
||||||
|
return [super resignFirstResponder];
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
@end
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void areaTextFieldOpen(id textfield, intptr_t x, intptr_t y)
|
||||||
|
{
|
||||||
|
NSTextField *tf = toNSTextField(textfield);
|
||||||
|
|
||||||
|
[tf sizeToFit];
|
||||||
|
// TODO
|
||||||
|
[tf setFrameSize:NSMakeSize(150, 20)];
|
||||||
|
[tf setFrameOrigin:NSMakePoint((CGFloat) x, (CGFloat) y)];
|
||||||
|
[tf setHidden:NO];
|
||||||
|
[[tf window] makeFirstResponder:tf];
|
||||||
|
}
|
||||||
|
|
|
@ -106,8 +106,11 @@ void checkboxSetChecked(id c, BOOL checked)
|
||||||
}
|
}
|
||||||
|
|
||||||
// also good for labels
|
// also good for labels
|
||||||
static id finishNewTextField(NSTextField *t, BOOL bordered)
|
// not static because area_darwin.m uses it
|
||||||
|
id finishNewTextField(id _t, BOOL bordered)
|
||||||
{
|
{
|
||||||
|
NSTextField *t = toNSTextField(_t);
|
||||||
|
|
||||||
// same for text fields, password fields, and labels
|
// same for text fields, password fields, and labels
|
||||||
setStandardControlFont((id) t);
|
setStandardControlFont((id) t);
|
||||||
// these three are the same across text fields, password fields, and labels; the only difference is the setBezeled: value, and it's only different on labels
|
// these three are the same across text fields, password fields, and labels; the only difference is the setBezeled: value, and it's only different on labels
|
||||||
|
@ -131,7 +134,7 @@ id newTextField(void)
|
||||||
NSTextField *t;
|
NSTextField *t;
|
||||||
|
|
||||||
t = [[NSTextField alloc] initWithFrame:NSZeroRect];
|
t = [[NSTextField alloc] initWithFrame:NSZeroRect];
|
||||||
return finishNewTextField(t, YES);
|
return finishNewTextField((id) t, YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
id newPasswordField(void)
|
id newPasswordField(void)
|
||||||
|
@ -139,7 +142,7 @@ id newPasswordField(void)
|
||||||
NSSecureTextField *t;
|
NSSecureTextField *t;
|
||||||
|
|
||||||
t = [[NSSecureTextField alloc] initWithFrame:NSZeroRect];
|
t = [[NSSecureTextField alloc] initWithFrame:NSZeroRect];
|
||||||
return finishNewTextField(toNSTextField(t), YES);
|
return finishNewTextField((id) t, YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
void textfieldSetDelegate(id textfield, void *t)
|
void textfieldSetDelegate(id textfield, void *t)
|
||||||
|
@ -219,7 +222,7 @@ id newLabel(void)
|
||||||
[l setEditable:NO];
|
[l setEditable:NO];
|
||||||
[l setSelectable:NO];
|
[l setSelectable:NO];
|
||||||
[l setDrawsBackground:NO];
|
[l setDrawsBackground:NO];
|
||||||
return finishNewTextField(l, NO);
|
return finishNewTextField((id) l, NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
id newGroup(id container)
|
id newGroup(id container)
|
||||||
|
|
|
@ -66,6 +66,7 @@ extern id newCheckbox(void);
|
||||||
extern void checkboxSetDelegate(id, void *);
|
extern void checkboxSetDelegate(id, void *);
|
||||||
extern BOOL checkboxChecked(id);
|
extern BOOL checkboxChecked(id);
|
||||||
extern void checkboxSetChecked(id, BOOL);
|
extern void checkboxSetChecked(id, BOOL);
|
||||||
|
extern id finishNewTextField(id, BOOL);
|
||||||
extern id newTextField(void);
|
extern id newTextField(void);
|
||||||
extern id newPasswordField(void);
|
extern id newPasswordField(void);
|
||||||
extern void textfieldSetDelegate(id, void *);
|
extern void textfieldSetDelegate(id, void *);
|
||||||
|
@ -127,6 +128,8 @@ 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, intptr_t, intptr_t);
|
||||||
|
|
||||||
/* common_darwin.m */
|
/* common_darwin.m */
|
||||||
extern void disableAutocorrect(id);
|
extern void disableAutocorrect(id);
|
||||||
|
|
Loading…
Reference in New Issue