diff --git a/windows/GNUfiles.mk b/windows/GNUfiles.mk index fa7897fb..083d8b36 100644 --- a/windows/GNUfiles.mk +++ b/windows/GNUfiles.mk @@ -40,6 +40,9 @@ CFILES += \ windows/utilwin.c \ windows/window.c +CXXFILES += \ + windows/drawtext.cpp + HFILES += \ windows/area.h \ windows/compilerver.h \ diff --git a/windows/draw.c b/windows/draw.c index 47aeb84b..3b90b56c 100644 --- a/windows/draw.c +++ b/windows/draw.c @@ -24,21 +24,6 @@ void uninitDraw(void) ID2D1Factory_Release(d2dfactory); } -static IDWriteFactory *dwfactory = NULL; - -HRESULT initDrawText(void) -{ - // TOOD use DWRITE_FACTORY_TYPE_ISOLATED instead? - return DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, - &IID_IDWriteFactory, - (IUnknown **) (&dwfactory)); -} - -void uninitDrawText(void) -{ - IDWriteFactory_Release(dwfactory); -} - ID2D1HwndRenderTarget *makeHWNDRenderTarget(HWND hwnd) { D2D1_RENDER_TARGET_PROPERTIES props; diff --git a/windows/drawtext.cpp b/windows/drawtext.cpp new file mode 100644 index 00000000..a5e89b67 --- /dev/null +++ b/windows/drawtext.cpp @@ -0,0 +1,20 @@ +// 22 december 2015 +// Before we begin, you may be wondering why this file is C++. +// Simple: is C++ only! Thanks Microsoft! +// And unlike UI Automation which accidentally just forgets the 'struct' and 'enum' tags in places, is a full C++ header file, with class definitions and the use of __uuidof. Oh well :/ +#include "uipriv_windows.h" + +static IDWriteFactory *dwfactory = NULL; + +HRESULT initDrawText(void) +{ + // TOOD use DWRITE_FACTORY_TYPE_ISOLATED instead? + return DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, + __uuidof (IDWriteFactory), + (IUnknown **) (&dwfactory)); +} + +void uninitDrawText(void) +{ + dwfactory->Release(); +} diff --git a/windows/uipriv_windows.h b/windows/uipriv_windows.h index 3f88a7f2..33ecb931 100644 --- a/windows/uipriv_windows.h +++ b/windows/uipriv_windows.h @@ -6,6 +6,10 @@ #include "resources.h" #include "compilerver.h" +#ifdef __cplusplus +extern "C" { +#endif + // ui internal window messages enum { // redirected WM_COMMAND and WM_NOTIFY @@ -127,8 +131,14 @@ extern int registerAreaFilter(void); // draw.c extern HRESULT initDraw(void); extern void uninitDraw(void); -extern HRESULT initDrawText(void); -extern void uninitDrawText(void); extern ID2D1HwndRenderTarget *makeHWNDRenderTarget(HWND hwnd); extern uiDrawContext *newContext(ID2D1RenderTarget *); extern void freeContext(uiDrawContext *); + +// drawtext.cpp +extern HRESULT initDrawText(void); +extern void uninitDrawText(void); + +#ifdef __cplusplus +} +#endif diff --git a/windows/winapi.h b/windows/winapi.h index 487aa158..2346d2bc 100644 --- a/windows/winapi.h +++ b/windows/winapi.h @@ -3,9 +3,12 @@ #define _UNICODE #define STRICT #define STRICT_TYPED_ITEMIDS +#ifndef __cplusplus #define CINTERFACE #define COBJMACROS +#endif // see https://github.com/golang/go/issues/9916#issuecomment-74812211 +// TODO get rid of this #define INITGUID #define _USE_MATH_DEFINES // for the manifest @@ -16,10 +19,6 @@ #define _WIN32_WINDOWS 0x0600 /* according to Microsoft's pdh.h */ #define _WIN32_IE 0x0700 /* according to Microsoft's sdkddkver.h */ #define NTDDI_VERSION 0x06000000 /* according to Microsoft's sdkddkver.h */ -// TODO cl.exe spews garbage warnings for system headers; figure out which flags cause it -#ifdef _MSC_VER -#pragma warning(push, 0) -#endif #include // Microsoft's resource compiler will segfault if we feed it headers it was not designed to handle #ifndef RC_INVOKED @@ -38,7 +37,8 @@ #include #include #include +// see drawtext.cpp for details +#ifdef __cplusplus +#include #endif -#ifdef _MSC_VER -#pragma warning(pop) #endif