Implemented TextField on Mac OS X.
This commit is contained in:
parent
348b3f7032
commit
e8df54cb82
|
@ -96,3 +96,29 @@ func (c *checkbox) Checked() bool {
|
|||
func (c *checkbox) SetChecked(checked bool) {
|
||||
C.checkboxSetChecked(c.id, toBOOL(checked))
|
||||
}
|
||||
|
||||
type textField struct {
|
||||
*widgetbase
|
||||
}
|
||||
|
||||
func newTextField() *textField {
|
||||
return &textField{
|
||||
widgetbase: newWidget(C.newTextField()),
|
||||
}
|
||||
}
|
||||
|
||||
func newPasswordField() *textField {
|
||||
return &textField{
|
||||
widgetbase: newWidget(C.newPasswordField()),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *textField) Text() string {
|
||||
return C.GoString(C.textFieldText(t.id))
|
||||
}
|
||||
|
||||
func (t *textField) SetText(text string) {
|
||||
ctext := C.CString(text)
|
||||
defer C.free(unsafe.Pointer(ctext))
|
||||
C.textFieldSetText(t.id, ctext)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define toNSWindow(x) ((NSWindow *) (x))
|
||||
#define toNSControl(x) ((NSControl *) (x))
|
||||
#define toNSButton(x) ((NSButton *) (x))
|
||||
#define toNSTextField(x) ((NSTextField *) (x))
|
||||
|
||||
void parent(id control, id parentid)
|
||||
{
|
||||
|
@ -101,3 +102,42 @@ void checkboxSetChecked(id c, BOOL checked)
|
|||
state = NSOffState;
|
||||
[toNSButton(c) setState:state];
|
||||
}
|
||||
|
||||
static id finishNewTextField(NSTextField *t)
|
||||
{
|
||||
// TODO font
|
||||
// TODO smart quotes
|
||||
// Interface Builder does this to make the text box behave properly
|
||||
// this disables both word wrap AND ellipsizing in one fell swoop
|
||||
// however, we need to send it to the control's cell, not to the control directly
|
||||
[[t cell] setLineBreakMode:NSLineBreakByClipping];
|
||||
// Interface Builder also sets this to allow horizontal scrolling
|
||||
[[t cell] setScrollable:YES];
|
||||
return (id) t;
|
||||
}
|
||||
|
||||
id newTextField(void)
|
||||
{
|
||||
NSTextField *t;
|
||||
|
||||
t = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
|
||||
return finishNewTextField(t);
|
||||
}
|
||||
|
||||
id newPasswordField(void)
|
||||
{
|
||||
NSSecureTextField *t;
|
||||
|
||||
t = [[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
|
||||
return finishNewTextField(toNSTextField(t));
|
||||
}
|
||||
|
||||
const char *textFieldText(id t)
|
||||
{
|
||||
return [[toNSTextField(t) stringValue] UTF8String];
|
||||
}
|
||||
|
||||
void textFieldSetText(id t, char *text)
|
||||
{
|
||||
[toNSTextField(t) setStringValue:[NSString stringWithUTF8String:text]];
|
||||
}
|
||||
|
|
|
@ -41,6 +41,10 @@ extern void buttonSetText(id, char *);
|
|||
extern id newCheckbox(void);
|
||||
extern BOOL checkboxChecked(id);
|
||||
extern void checkboxSetChecked(id, BOOL);
|
||||
extern id newTextField(void);
|
||||
extern id newPasswordField(void);
|
||||
extern const char *textFieldText(id);
|
||||
extern void textFieldSetText(id, char *);
|
||||
|
||||
/* sizing_darwin.m */
|
||||
extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t);
|
||||
|
|
Loading…
Reference in New Issue