From 3d9aa4ce9a37b8785ec357a9df59664f4b9d035f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 25 Nov 2015 15:46:57 -0500 Subject: [PATCH] More boilerplate. Okay, now we can get to the good stuff: the controls! --- wpf/control.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ wpf/init.c | 4 ++++ wpf/libui.msbuild | 12 ++++++++++++ wpf/ui_wpf.hpp | 11 ++++++++--- wpf/uipriv_wpf.hpp | 1 + wpf/util.c | 17 +++++++++++++++++ 6 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 wpf/control.cpp create mode 100644 wpf/util.c diff --git a/wpf/control.cpp b/wpf/control.cpp new file mode 100644 index 00000000..55568e74 --- /dev/null +++ b/wpf/control.cpp @@ -0,0 +1,46 @@ +// 16 august 2015 +#include "uipriv_wpf.hpp" + +static uintmax_t type_uiWindowsControl = 0; + +uintmax_t uiWindowsControlType(void) +{ + if (type_uiWindowsControl == 0) + type_uiWindowsControl = uiRegisterType("uiWindowsControl", uiControlType(), sizeof (uiWindowsControl)); + return type_uiWindowsControl; +} + +static Control ^genericHandle(uiControl *c) +{ + gcroot *h; + + h = (gcroot *) uiControlHandle(c); + return *h; +} + +static void defaultCommitShow(uiControl *c) +{ + genericHandle(c)->Visibility = Visibility::Visible; +} + +static void defaultCommitHide(uiControl *c) +{ + // TODO formally document this behavior (it's how GTK+ works) + genericHandle(c)->Visibility = Visibility::Collapsed; +} + +void osCommitEnable(uiControl *c) +{ + genericHandle(c)->IsEnabled = true; +} + +void osCommitDisable(uiControl *c) +{ + genericHandle(c)->IsEnabled = false; +} + +void uiWindowsFinishControl(uiControl *c) +{ + c->CommitShow = defaultCommitShow; + c->CommitHide = defaultCommitHide; +} diff --git a/wpf/init.c b/wpf/init.c index f54121cd..5834e5d8 100644 --- a/wpf/init.c +++ b/wpf/init.c @@ -11,6 +11,9 @@ static const char *initerr(const char *message, const WCHAR *label, DWORD value) { + // TODO + return ""; +#if 0 WCHAR *sysmsg; BOOL hassysmsg; WCHAR *beforele; @@ -41,6 +44,7 @@ static const char *initerr(const char *message, const WCHAR *label, DWORD value) logLastError("error freeing system message in loadLastError()"); uiFree(wmessage); return str; +#endif } static const char *loadLastError(const char *message) diff --git a/wpf/libui.msbuild b/wpf/libui.msbuild index 9e8750a6..aabf3401 100755 --- a/wpf/libui.msbuild +++ b/wpf/libui.msbuild @@ -75,6 +75,7 @@ false + false @@ -83,27 +84,38 @@ + + false + + false + $(IntDir)common_areaevents.obj false + $(IntDir)common_control.obj false + $(IntDir)common_matrix.obj false + $(IntDir)common_menu.obj false + $(IntDir)common_ptrarray.obj false + $(IntDir)common_shouldquit.obj false + $(IntDir)common_types.obj diff --git a/wpf/ui_wpf.hpp b/wpf/ui_wpf.hpp index 7c65e1d0..db172bcf 100644 --- a/wpf/ui_wpf.hpp +++ b/wpf/ui_wpf.hpp @@ -1,7 +1,7 @@ // 7 april 2015 /* -This file assumes that you have included and "ui.h" beforehand, as well as #using (but not necessarily beforehand). It provides API-specific functions for interfacing with foreign controls in Windows. +This file assumes that you have included and "ui.h" beforehand, as well as #using and the three WPF DLLs (TODO) (but not necessarily beforehand). It provides API-specific functions for interfacing with foreign controls in Windows. */ #ifndef __LIBUI_UI_WINDOWS_H__ @@ -18,6 +18,8 @@ typedef struct uiWindowsSizing uiWindowsSizing; typedef struct uiWindowsControl uiWindowsControl; struct uiWindowsControl { uiControl c; + // TODO make truly private + gcroot *genericHandle; }; _UI_EXTERN uintmax_t uiWindowsControlType(void); #define uiWindowsControl(this) ((uiWindowsControl *) uiIsA((this), uiWindowsControlType(), 1)) @@ -35,11 +37,12 @@ _UI_EXTERN uintmax_t uiWindowsControlType(void); { \ type *hthis = type(c); \ onDestroy; \ + delete uiWindowsControl(c)->genericHandle; \ delete hthis->handle; \ } \ static uintptr_t _ ## type ## Handle(uiControl *c) \ { \ - return (uintptr_t) (type(c)->handle); \ + return (uintptr_t) (uiWindowsControl(c)->genericHandle); \ } \ static void _ ## type ## ContainerUpdateState(uiControl *c) \ { \ @@ -49,10 +52,12 @@ _UI_EXTERN uintmax_t uiWindowsControlType(void); #define uiWindowsDefineControl(type, typefn, handle) \ uiWindowsDefineControlWithOnDestroy(type, typefn, handle, (void) hthis;) -#define uiWindowsFinishNewControl(variable, type) \ +#define uiWindowsFinishNewControl(variable, type, handle) \ uiControl(variable)->CommitDestroy = _ ## type ## CommitDestroy; \ uiControl(variable)->Handle = _ ## type ## Handle; \ uiControl(variable)->ContainerUpdateState = _ ## type ## ContainerUpdateState; \ + uiWindowsControl(variable)->genericHandle = new gcroot(); \ + *(uiWindowsControl(variable)->genericHandle) = *(variable->handle); \ uiWindowsFinishControl(uiControl(variable)); // This is a function used to set up a control. diff --git a/wpf/uipriv_wpf.hpp b/wpf/uipriv_wpf.hpp index 2532ffc9..eedde4db 100644 --- a/wpf/uipriv_wpf.hpp +++ b/wpf/uipriv_wpf.hpp @@ -12,6 +12,7 @@ using namespace System; using namespace System::ComponentModel; using namespace System::Windows; +using namespace System::Windows::Controls; // text.cpp String ^fromUTF8(const char *); diff --git a/wpf/util.c b/wpf/util.c new file mode 100644 index 00000000..9196f6a6 --- /dev/null +++ b/wpf/util.c @@ -0,0 +1,17 @@ +// 6 april 2015 +#include "unmanaged.h" +#include +#include + +void complain(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fprintf(stderr, "[libui] "); + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + va_end(ap); + DebugBreak(); + abort(); // just in case +}