Added uiButton to the WPF code.
This commit is contained in:
parent
4ec3632920
commit
e279c7b319
|
@ -61,7 +61,6 @@ uiButton *uiNewButton(const char *text)
|
|||
|
||||
b->button = new BButton(text, msg);
|
||||
|
||||
// TODO hook up events
|
||||
uiButtonOnClicked(b, defaultOnClicked, NULL);
|
||||
|
||||
uiHaikuFinishNewControl(b, uiButton);
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
// 25 november 2015
|
||||
#include "uipriv_wpf.hpp"
|
||||
|
||||
struct uiButton {
|
||||
uiWindowsControl c;
|
||||
gcroot<Button ^> *button;
|
||||
void (*onClicked)(uiButton *, void *);
|
||||
void *onClickedData;
|
||||
};
|
||||
|
||||
uiWindowsDefineControl(
|
||||
uiButton, // type name
|
||||
uiButtonType, // type function
|
||||
button // handle
|
||||
)
|
||||
|
||||
static void defaultOnClicked(uiButton *b, void *data)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
char *uiButtonText(uiButton *b)
|
||||
{
|
||||
String ^text;
|
||||
|
||||
// TOOD bad cast?
|
||||
text = (String ^) ((*(b->button))->Content);
|
||||
return uiWindowsCLRStringToText(text);
|
||||
}
|
||||
|
||||
void uiButtonSetText(uiButton *b, const char *text)
|
||||
{
|
||||
(*(b->button))->Content = fromUTF8(text);
|
||||
}
|
||||
|
||||
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *b, void *data), void *data)
|
||||
{
|
||||
b->onClicked = f;
|
||||
b->onClickedData = data;
|
||||
}
|
||||
|
||||
uiButton *uiNewButton(const char *text)
|
||||
{
|
||||
uiButton *b;
|
||||
|
||||
b = (uiButton *) uiNewControl(uiButtonType());
|
||||
|
||||
b->button = new gcroot<Button ^>();
|
||||
*(b->button) = gcnew Button();
|
||||
(*(b->button))->Content = fromUTF8(text);
|
||||
|
||||
// TODO hook up events
|
||||
uiButtonOnClicked(b, defaultOnClicked, NULL);
|
||||
|
||||
uiWindowsFinishNewControl(b, uiButton, button);
|
||||
|
||||
return b;
|
||||
}
|
|
@ -10,7 +10,7 @@ uintmax_t uiWindowsControlType(void)
|
|||
return type_uiWindowsControl;
|
||||
}
|
||||
|
||||
static Control ^genericHandle(uiControl *c)
|
||||
Control ^genericHandle(uiControl *c)
|
||||
{
|
||||
gcroot<Control ^> *h;
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
<ClCompile Include="alloc.c">
|
||||
<CompileAsManaged>false</CompileAsManaged>
|
||||
</ClCompile>
|
||||
<ClCompile Include="button.cpp" />
|
||||
<ClCompile Include="control.cpp" />
|
||||
<ClCompile Include="debug.c">
|
||||
<CompileAsManaged>false</CompileAsManaged>
|
||||
|
|
|
@ -15,4 +15,7 @@ using namespace System::Windows;
|
|||
using namespace System::Windows::Controls;
|
||||
|
||||
// text.cpp
|
||||
String ^fromUTF8(const char *);
|
||||
extern String ^fromUTF8(const char *);
|
||||
|
||||
// control.cpp
|
||||
extern Control ^genericHandle(uiControl *c);
|
||||
|
|
|
@ -14,6 +14,8 @@ struct uiWindow {
|
|||
gcroot<Border ^> *border;
|
||||
int margined;
|
||||
|
||||
uiControl *child;
|
||||
|
||||
int (*onClosing)(uiWindow *, void *);
|
||||
void *onClosingData;
|
||||
gcroot<CancelEventHandler ^> *onClosingDelegate;
|
||||
|
@ -96,15 +98,15 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
|
|||
|
||||
void uiWindowSetChild(uiWindow *w, uiControl *child)
|
||||
{
|
||||
/*TODO
|
||||
if (w->child != NULL)
|
||||
childRemove(w->child);
|
||||
w->child = newChild(child, uiControl(w), w->hwnd);
|
||||
if (w->child != NULL) {
|
||||
childSetSoleControlID(w->child);
|
||||
childQueueRelayout(w->child);
|
||||
(*(w->border))->Child = nullptr;
|
||||
uiControlSetParent(w->child, NULL);
|
||||
}
|
||||
w->child = child;
|
||||
if (w->child != NULL) {
|
||||
uiControlSetParent(w->child, uiControl(w));
|
||||
(*(w->border))->Child = genericHandle(w->child);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
int uiWindowMargined(uiWindow *w)
|
||||
|
|
|
@ -11,10 +11,14 @@ int main(void)
|
|||
{
|
||||
uiInitOptions o;
|
||||
uiWindow *w;
|
||||
uiButton *btn;
|
||||
if (uiInit(&o) != NULL) return 1;
|
||||
w = uiNewWindow("Hello from C",
|
||||
320, 240, 0);
|
||||
uiWindowOnClosing(w, onClosing, NULL);
|
||||
btn = uiNewButton("Hello from C");
|
||||
uiWindowSetChild(w, uiControl(btn));
|
||||
uiWindowSetMargined(w, 1);
|
||||
uiControlShow(uiControl(w));
|
||||
uiMain();
|
||||
printf("after main\n");
|
||||
|
|
|
@ -8,6 +8,9 @@ var libui = syscall.NewLazyDLL("libui.dll")
|
|||
var uiInit = libui.NewProc("uiInit")
|
||||
var uiNewWindow = libui.NewProc("uiNewWindow")
|
||||
var uiWindowOnClosing = libui.NewProc("uiWindowOnClosing")
|
||||
var uiNewButton = libui.NewProc("uiNewButton")
|
||||
var uiWindowSetChild = libui.NewProc("uiWindowSetChild")
|
||||
var uiWindowSetMargined = libui.NewProc("uiWindowSetMargined")
|
||||
var uiControlShow = libui.NewProc("uiControlShow")
|
||||
var uiMain = libui.NewProc("uiMain")
|
||||
var uiQuit = libui.NewProc("uiQuit")
|
||||
|
@ -28,6 +31,10 @@ func main() {
|
|||
uintptr(unsafe.Pointer(&s[0])),
|
||||
320, 240, 0)
|
||||
uiWindowOnClosing.Call(w, syscall.NewCallbackCDecl(onClosing), 0)
|
||||
btn, _, _ := uiNewButton.Call(
|
||||
uintptr(unsafe.Pointer(&s[0])))
|
||||
uiWindowSetChild.Call(w, btn)
|
||||
uiWindowSetMargined.Call(w, 1)
|
||||
uiControlShow.Call(w)
|
||||
uiMain.Call(w)
|
||||
fmt.Println("after main")
|
||||
|
|
Loading…
Reference in New Issue