diff --git a/wpf/checkbox.cpp b/wpf/checkbox.cpp new file mode 100644 index 00000000..f19ec2b1 --- /dev/null +++ b/wpf/checkbox.cpp @@ -0,0 +1,71 @@ +// 26 november 2015 +#include "uipriv_wpf.hpp" + +struct uiCheckbox { + uiWindowsControl c; + gcroot *checkbox; + void (*onToggled)(uiCheckbox *, void *); + void *onToggledData; +}; + +uiWindowsDefineControl( + uiCheckbox, // type name + uiCheckboxType, // type function + checkbox // handle +) + +static void defaultOnToggled(uiCheckbox *c, void *data) +{ + // do nothing +} + +char *uiCheckboxText(uiCheckbox *c) +{ + String ^text; + + // TOOD bad cast? + text = (String ^) ((*(c->checkbox))->Content); + return uiWindowsCLRStringToText(text); +} + +void uiCheckboxSetText(uiCheckbox *c, const char *text) +{ + (*(c->checkbox))->Content = fromUTF8(text); +} + +void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *c, void *data), void *data) +{ + c->onToggled = f; + c->onToggledData = data; +} + +int uiCheckboxChecked(uiCheckbox *c) +{ + return (*(c->checkbox))->IsChecked.Value != false; +} + +void uiCheckboxSetChecked(uiCheckbox *c, int checked) +{ + bool value; + + value = checked != 0; + // TODO does this trigger an event? + (*(c->checkbox))->IsChecked = value; +} + +uiCheckbox *uiNewCheckbox(const char *text) +{ + uiCheckbox *c; + + c = (uiCheckbox *) uiNewControl(uiCheckboxType()); + + c->checkbox = new gcroot(); + *(c->checkbox) = gcnew CheckBox(); + (*(c->checkbox))->Content = fromUTF8(text); + + uiCheckboxOnToggled(c, defaultOnToggled, NULL); + + uiWindowsFinishNewControl(c, uiCheckbox, checkbox); + + return c; +} diff --git a/wpf/libui.msbuild b/wpf/libui.msbuild index eb00c511..ef0d0d13 100755 --- a/wpf/libui.msbuild +++ b/wpf/libui.msbuild @@ -77,6 +77,7 @@ + false diff --git a/wpf/xtest.go b/wpf/xtest.go index 745c88c1..0099e47f 100644 --- a/wpf/xtest.go +++ b/wpf/xtest.go @@ -18,6 +18,7 @@ var uiNewTab = libui.NewProc("uiNewTab") var uiTabAppend = libui.NewProc("uiTabAppend") var uiTabSetMargined = libui.NewProc("uiTabSetMargined") var uiNewLabel = libui.NewProc("uiNewLabel") +var uiNewCheckbox = libui.NewProc("uiNewCheckbox") var uiControlShow = libui.NewProc("uiControlShow") var uiMain = libui.NewProc("uiMain") var uiQuit = libui.NewProc("uiQuit") @@ -40,7 +41,7 @@ func main() { uiWindowOnClosing.Call(w, syscall.NewCallbackCDecl(onClosing), 0) tab, _, _ := uiNewTab.Call() box, _, _ := uiNewVerticalBox.Call() - btn, _, _ := uiNewButton.Call( + btn, _, _ := uiNewCheckbox.Call( uintptr(unsafe.Pointer(&s[0]))) uiBoxAppend.Call(box, btn, 0) btn, _, _ = uiNewButton.Call( @@ -65,7 +66,7 @@ func main() { uiTabAppend.Call(tab, uintptr(unsafe.Pointer(&s[0])), btn) - uiBoxSetPadded.Call(box, 1) +// uiBoxSetPadded.Call(box, 1) uiWindowSetMargined.Call(w, 1) uiControlShow.Call(w) uiMain.Call(w)