Migrated datetimepicker.go and brought stddialogs.go back again.
This commit is contained in:
parent
7b7ae9d7ce
commit
d0fe74d603
|
@ -7,17 +7,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include <stdlib.h>
|
// #include "pkgui.h"
|
||||||
// #include <time.h>
|
|
||||||
// #include "ui.h"
|
|
||||||
// #include "util.h"
|
|
||||||
// static inline struct tm *allocTimeStruct(void)
|
|
||||||
// {
|
|
||||||
// return (struct tm *) pkguiAlloc(sizeof (struct tm));
|
|
||||||
// }
|
|
||||||
// extern void doDateTimePickerOnChanged(uiDateTimePicker *, void *);
|
|
||||||
// // see golang/go#19835
|
|
||||||
// typedef void (*dtpCallback)(uiDateTimePicker *, void *);
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// DateTimePicker is a Control that represents a field where the user
|
// DateTimePicker is a Control that represents a field where the user
|
||||||
|
@ -33,7 +23,7 @@ func finishNewDateTimePicker(dd *C.uiDateTimePicker) *DateTimePicker {
|
||||||
|
|
||||||
d.d = dd
|
d.d = dd
|
||||||
|
|
||||||
C.uiDateTimePickerOnChanged(d.d, C.dtpCallback(C.doDateTimePickerOnChanged), nil)
|
C.pkguiDateTimePickerOnChanged(d.d)
|
||||||
|
|
||||||
d.ControlBase = NewControlBase(d, uintptr(unsafe.Pointer(d.d)))
|
d.ControlBase = NewControlBase(d, uintptr(unsafe.Pointer(d.d)))
|
||||||
return d
|
return d
|
||||||
|
@ -60,8 +50,8 @@ func NewTimePicker() *DateTimePicker {
|
||||||
// Time returns the time stored in the uiDateTimePicker.
|
// Time returns the time stored in the uiDateTimePicker.
|
||||||
// The time is assumed to be local time.
|
// The time is assumed to be local time.
|
||||||
func (d *DateTimePicker) Time() time.Time {
|
func (d *DateTimePicker) Time() time.Time {
|
||||||
tm := C.allocTimeStruct()
|
tm := C.pkguiAllocTime()
|
||||||
defer C.free(unsafe.Pointer(tm))
|
defer C.pkguiFreeTime(tm)
|
||||||
C.uiDateTimePickerTime(d.d, tm)
|
C.uiDateTimePickerTime(d.d, tm)
|
||||||
return time.Date(
|
return time.Date(
|
||||||
int(tm.tm_year + 1900),
|
int(tm.tm_year + 1900),
|
||||||
|
@ -77,8 +67,8 @@ func (d *DateTimePicker) Time() time.Time {
|
||||||
// t's components are read as-is via t.Date() and t.Clock();
|
// t's components are read as-is via t.Date() and t.Clock();
|
||||||
// no time zone manipulations are done.
|
// no time zone manipulations are done.
|
||||||
func (d *DateTimePicker) SetTime(t time.Time) {
|
func (d *DateTimePicker) SetTime(t time.Time) {
|
||||||
tm := C.allocTimeStruct()
|
tm := C.pkguiAllocTime()
|
||||||
defer C.free(unsafe.Pointer(tm))
|
defer C.pkguiFreeTime(tm)
|
||||||
year, mon, mday := t.Date()
|
year, mon, mday := t.Date()
|
||||||
tm.tm_year = C.int(year - 1900)
|
tm.tm_year = C.int(year - 1900)
|
||||||
tm.tm_mon = C.int(mon - 1)
|
tm.tm_mon = C.int(mon - 1)
|
||||||
|
@ -98,8 +88,8 @@ func (d *DateTimePicker) OnChanged(f func(*DateTimePicker)) {
|
||||||
d.onChanged = f
|
d.onChanged = f
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doDateTimePickerOnChanged
|
//export pkguiDoDateTimePickerOnChanged
|
||||||
func doDateTimePickerOnChanged(dd *C.uiDateTimePicker, data unsafe.Pointer) {
|
func pkguiDoDateTimePickerOnChanged(dd *C.uiDateTimePicker, data unsafe.Pointer) {
|
||||||
d := ControlFromLibui(uintptr(unsafe.Pointer(dd))).(*DateTimePicker)
|
d := ControlFromLibui(uintptr(unsafe.Pointer(dd))).(*DateTimePicker)
|
||||||
if d.onChanged != nil {
|
if d.onChanged != nil {
|
||||||
d.onChanged(d)
|
d.onChanged(d)
|
15
pkgui.c
15
pkgui.c
|
@ -42,6 +42,21 @@ void pkguiComboboxOnSelected(uiCombobox *c)
|
||||||
uiComboboxOnSelected(c, pkguiDoComboboxOnSelected, NULL);
|
uiComboboxOnSelected(c, pkguiDoComboboxOnSelected, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pkguiDateTimePickerOnChanged(uiDateTimePicker *d)
|
||||||
|
{
|
||||||
|
uiDateTimePickerOnChanged(d, pkguiDoDateTimePickerOnChanged, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct tm *pkguiAllocTime(void)
|
||||||
|
{
|
||||||
|
return (struct tm *) pkguiAlloc(sizeof (struct tm));
|
||||||
|
}
|
||||||
|
|
||||||
|
void pkguiFreeTime(struct tm *t)
|
||||||
|
{
|
||||||
|
free(t);
|
||||||
|
}
|
||||||
|
|
||||||
void pkguiEditableComboboxOnChanged(uiEditableCombobox *c)
|
void pkguiEditableComboboxOnChanged(uiEditableCombobox *c)
|
||||||
{
|
{
|
||||||
uiEditableComboboxOnChanged(c, pkguiDoEditableComboboxOnChanged, NULL);
|
uiEditableComboboxOnChanged(c, pkguiDoEditableComboboxOnChanged, NULL);
|
||||||
|
|
6
pkgui.h
6
pkgui.h
|
@ -3,6 +3,7 @@
|
||||||
#define pkguiHFileIncluded
|
#define pkguiHFileIncluded
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
// main.go
|
// main.go
|
||||||
|
@ -23,6 +24,11 @@ extern void pkguiCheckboxOnToggled(uiCheckbox *c);
|
||||||
// combobox.go
|
// combobox.go
|
||||||
extern void pkguiComboboxOnSelected(uiCombobox *c);
|
extern void pkguiComboboxOnSelected(uiCombobox *c);
|
||||||
|
|
||||||
|
// datetimepicker.go
|
||||||
|
extern void pkguiDateTimePickerOnChanged(uiDateTimePicker *d);
|
||||||
|
extern struct tm *pkguiAllocTime(void);
|
||||||
|
extern void pkguiFreeTime(struct tm *t);
|
||||||
|
|
||||||
// editablecombobox.go
|
// editablecombobox.go
|
||||||
extern void pkguiEditableComboboxOnChanged(uiEditableCombobox *c);
|
extern void pkguiEditableComboboxOnChanged(uiEditableCombobox *c);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
// #include "ui.h"
|
// #include "pkgui.h"
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// TODO
|
// TODO
|
Loading…
Reference in New Issue