More boilerplate. Okay, now we can get to the good stuff: the controls!

This commit is contained in:
Pietro Gagliardi 2015-11-25 15:46:57 -05:00
parent f93d9a4c91
commit 3d9aa4ce9a
6 changed files with 88 additions and 3 deletions

46
wpf/control.cpp Normal file
View File

@ -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<Control ^> *h;
h = (gcroot<Control ^> *) 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;
}

View File

@ -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)

View File

@ -75,6 +75,7 @@
<ClCompile Include="alloc.c">
<CompileAsManaged>false</CompileAsManaged>
</ClCompile>
<ClCompile Include="control.cpp" />
<ClCompile Include="debug.c">
<CompileAsManaged>false</CompileAsManaged>
</ClCompile>
@ -83,27 +84,38 @@
</ClCompile>
<ClCompile Include="main.cpp" />
<ClCompile Include="text.cpp" />
<ClCompile Include="util.c">
<CompileAsManaged>false</CompileAsManaged>
</ClCompile>
<!-- TODO find a way to get the basename of the source path so we can use dir_file.obj naming automatically -->
<ClCompile Include="..\common\areaevents.c">
<CompileAsManaged>false</CompileAsManaged>
<ObjectFileName>$(IntDir)common_areaevents.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\common\control.c">
<CompileAsManaged>false</CompileAsManaged>
<ObjectFileName>$(IntDir)common_control.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\common\matrix.c">
<CompileAsManaged>false</CompileAsManaged>
<ObjectFileName>$(IntDir)common_matrix.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\common\menu.c">
<CompileAsManaged>false</CompileAsManaged>
<ObjectFileName>$(IntDir)common_menu.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\common\ptrarray.c">
<CompileAsManaged>false</CompileAsManaged>
<ObjectFileName>$(IntDir)common_ptrarray.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\common\shouldquit.c">
<CompileAsManaged>false</CompileAsManaged>
<ObjectFileName>$(IntDir)common_shouldquit.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\common\types.c">
<CompileAsManaged>false</CompileAsManaged>
<ObjectFileName>$(IntDir)common_types.obj</ObjectFileName>
</ClCompile>
</ItemGroup>

View File

@ -1,7 +1,7 @@
// 7 april 2015
/*
This file assumes that you have included <vccrt.h> and "ui.h" beforehand, as well as #using <System.dll> (but not necessarily beforehand). It provides API-specific functions for interfacing with foreign controls in Windows.
This file assumes that you have included <vccrt.h> and "ui.h" beforehand, as well as #using <System.dll> 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<System::Windows::Controls::Control ^> *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<System::Windows::Controls::Control ^>(); \
*(uiWindowsControl(variable)->genericHandle) = *(variable->handle); \
uiWindowsFinishControl(uiControl(variable));
// This is a function used to set up a control.

View File

@ -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 *);

17
wpf/util.c Normal file
View File

@ -0,0 +1,17 @@
// 6 april 2015
#include "unmanaged.h"
#include <stdio.h>
#include <stdlib.h>
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
}