glfw/src/win32_platform.h

273 lines
7.6 KiB
C
Raw Normal View History

2010-09-07 17:34:51 +02:00
//========================================================================
2015-06-01 22:55:06 +02:00
// GLFW 3.2 Win32 - www.glfw.org
2010-09-07 17:34:51 +02:00
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
2015-06-07 19:32:24 +02:00
#ifndef _glfw3_win32_platform_h_
#define _glfw3_win32_platform_h_
2010-09-07 17:34:51 +02:00
// We don't need all the fancy stuff
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN
#endif
2010-09-07 17:34:51 +02:00
2011-07-27 17:09:17 +02:00
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
2014-08-20 17:49:58 +02:00
// This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
// example to allow applications to correctly declare a GL_ARB_debug_output
// callback) but windows.h assumes no one will define APIENTRY before it does
2012-01-18 18:44:28 +01:00
#undef APIENTRY
// GLFW on Windows is Unicode only and does not work in MBCS mode
#ifndef UNICODE
#define UNICODE
#endif
// GLFW requires Windows XP or later
#if WINVER < 0x0501
#undef WINVER
2012-03-30 01:55:28 +02:00
#define WINVER 0x0501
2012-03-22 14:58:14 +01:00
#endif
#if _WIN32_WINNT < 0x0501
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
2012-02-03 20:34:24 +01:00
2014-03-31 22:33:22 +02:00
#include <windows.h>
#include <mmsystem.h>
#include <dbt.h>
#if defined(_MSC_VER)
#include <malloc.h>
#define strdup _strdup
#endif
2014-09-02 19:42:43 +02:00
// HACK: Define macros that some older windows.h variants don't
#ifndef WM_MOUSEHWHEEL
2012-02-05 02:43:49 +01:00
#define WM_MOUSEHWHEEL 0x020E
2010-09-07 17:34:51 +02:00
#endif
2013-03-11 20:54:32 +01:00
#ifndef WM_DWMCOMPOSITIONCHANGED
#define WM_DWMCOMPOSITIONCHANGED 0x031E
#endif
#ifndef WM_COPYGLOBALDATA
#define WM_COPYGLOBALDATA 0x0049
#endif
2014-03-06 23:33:09 +01:00
#ifndef WM_UNICHAR
#define WM_UNICHAR 0x0109
#endif
#ifndef UNICODE_NOCHAR
#define UNICODE_NOCHAR 0xFFFF
#endif
#ifndef WM_DPICHANGED
#define WM_DPICHANGED 0x02E0
#endif
2015-11-10 13:42:56 +01:00
#ifndef GET_XBUTTON_WPARAM
#define GET_XBUTTON_WPARAM(w) (HIWORD(w))
#endif
2014-02-10 21:12:20 +01:00
#if WINVER < 0x0601
typedef struct tagCHANGEFILTERSTRUCT
{
DWORD cbSize;
DWORD ExtStatus;
2014-02-10 21:12:20 +01:00
} CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT;
2014-02-10 21:12:20 +01:00
#ifndef MSGFLT_ALLOW
#define MSGFLT_ALLOW 1
#endif
#endif /*Windows 7*/
2010-09-07 17:34:51 +02:00
#ifndef DPI_ENUMS_DECLARED
typedef enum PROCESS_DPI_AWARENESS
{
PROCESS_DPI_UNAWARE = 0,
PROCESS_SYSTEM_DPI_AWARE = 1,
PROCESS_PER_MONITOR_DPI_AWARE = 2
} PROCESS_DPI_AWARENESS;
#endif /*DPI_ENUMS_DECLARED*/
2010-09-07 17:34:51 +02:00
// winmm.dll function pointer typedefs
typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T)(UINT,LPJOYCAPS,UINT);
typedef MMRESULT (WINAPI * JOYGETPOS_T)(UINT,LPJOYINFO);
typedef MMRESULT (WINAPI * JOYGETPOSEX_T)(UINT,LPJOYINFOEX);
typedef DWORD (WINAPI * TIMEGETTIME_T)(void);
#define _glfw_joyGetDevCaps _glfw.win32.winmm.joyGetDevCaps
#define _glfw_joyGetPos _glfw.win32.winmm.joyGetPos
#define _glfw_joyGetPosEx _glfw.win32.winmm.joyGetPosEx
#define _glfw_timeGetTime _glfw.win32.winmm.timeGetTime
2010-09-07 17:34:51 +02:00
// user32.dll function pointer typedefs
typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void);
typedef BOOL (WINAPI * CHANGEWINDOWMESSAGEFILTEREX_T)(HWND,UINT,DWORD,PCHANGEFILTERSTRUCT);
#define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware
#define _glfw_ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx
2013-03-11 20:54:32 +01:00
// dwmapi.dll function pointer typedefs
typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*);
typedef HRESULT (WINAPI * DWMFLUSH_T)(VOID);
2013-03-11 20:54:32 +01:00
#define _glfw_DwmIsCompositionEnabled _glfw.win32.dwmapi.DwmIsCompositionEnabled
#define _glfw_DwmFlush _glfw.win32.dwmapi.DwmFlush
2013-03-11 20:54:32 +01:00
// shcore.dll function pointer typedefs
typedef HRESULT (WINAPI * SETPROCESSDPIAWARENESS_T)(PROCESS_DPI_AWARENESS);
#define _glfw_SetProcessDPIAwareness _glfw.win32.shcore.SetProcessDPIAwareness
#include "win32_tls.h"
2015-05-27 15:06:52 +02:00
#include "winmm_joystick.h"
#if defined(_GLFW_WGL)
2014-04-08 16:25:35 +02:00
#include "wgl_context.h"
#elif defined(_GLFW_EGL)
#define _GLFW_EGL_NATIVE_WINDOW window->win32.handle
#define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY
2014-04-08 16:25:35 +02:00
#include "egl_context.h"
2012-12-02 19:01:20 +01:00
#else
#error "No supported context creation API selected"
#endif
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 win32
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 win32
#define _GLFW_PLATFORM_LIBRARY_TIME_STATE _GLFWtimeWin32 win32_time
#define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWin32 win32
#define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWin32 win32
2014-09-02 19:42:43 +02:00
// Win32-specific per-window data
//
typedef struct _GLFWwindowWin32
{
2014-09-02 19:42:43 +02:00
HWND handle;
2010-09-07 17:34:51 +02:00
2015-08-23 19:30:04 +02:00
GLFWbool cursorTracked;
GLFWbool iconified;
int minwidth, minheight;
int maxwidth, maxheight;
int numer, denom;
// The last received cursor position, regardless of source
int cursorPosX, cursorPosY;
2014-09-02 19:42:43 +02:00
} _GLFWwindowWin32;
2010-09-07 17:34:51 +02:00
2014-09-02 19:42:43 +02:00
// Win32-specific global data
//
typedef struct _GLFWlibraryWin32
{
2013-01-02 16:48:02 +01:00
DWORD foregroundLockTimeout;
char* clipboardString;
2015-07-02 14:24:50 +02:00
char keyName[64];
2014-03-30 16:23:22 +02:00
short int publicKeys[512];
2015-07-02 14:24:50 +02:00
short int nativeKeys[GLFW_KEY_LAST + 1];
2010-09-14 04:27:02 +02:00
// winmm.dll
struct {
2013-01-02 16:48:02 +01:00
HINSTANCE instance;
JOYGETDEVCAPS_T joyGetDevCaps;
JOYGETPOS_T joyGetPos;
JOYGETPOSEX_T joyGetPosEx;
TIMEGETTIME_T timeGetTime;
2010-09-14 04:27:02 +02:00
} winmm;
2010-09-07 17:34:51 +02:00
// user32.dll
struct {
2013-03-11 20:54:32 +01:00
HINSTANCE instance;
SETPROCESSDPIAWARE_T SetProcessDPIAware;
CHANGEWINDOWMESSAGEFILTEREX_T ChangeWindowMessageFilterEx;
} user32;
2013-03-11 20:54:32 +01:00
// dwmapi.dll
struct {
HINSTANCE instance;
DWMISCOMPOSITIONENABLED_T DwmIsCompositionEnabled;
DWMFLUSH_T DwmFlush;
2013-03-11 20:54:32 +01:00
} dwmapi;
// shcore.dll
struct {
HINSTANCE instance;
SETPROCESSDPIAWARENESS_T SetProcessDPIAwareness;
} shcore;
} _GLFWlibraryWin32;
2010-09-07 17:34:51 +02:00
2012-09-12 20:46:54 +02:00
2014-09-02 19:42:43 +02:00
// Win32-specific per-monitor data
//
typedef struct _GLFWmonitorWin32
{
// This size matches the static size of DISPLAY_DEVICE.DeviceName
WCHAR adapterName[32];
WCHAR displayName[32];
2014-10-28 15:35:03 +01:00
char publicAdapterName[64];
char publicDisplayName[64];
2015-08-23 19:30:04 +02:00
GLFWbool modesPruned;
GLFWbool modeChanged;
} _GLFWmonitorWin32;
2010-09-07 17:34:51 +02:00
2012-09-12 20:46:54 +02:00
2014-09-02 19:42:43 +02:00
// Win32-specific per-cursor data
//
typedef struct _GLFWcursorWin32
{
HCURSOR handle;
2014-09-02 19:42:43 +02:00
} _GLFWcursorWin32;
2014-09-02 19:42:43 +02:00
// Win32-specific global timer data
//
typedef struct _GLFWtimeWin32
{
2015-08-23 19:30:04 +02:00
GLFWbool hasPC;
double resolution;
unsigned __int64 base;
} _GLFWtimeWin32;
2015-08-23 19:30:04 +02:00
GLFWbool _glfwRegisterWindowClass(void);
2014-08-31 14:17:31 +02:00
void _glfwUnregisterWindowClass(void);
2013-03-11 20:54:32 +01:00
BOOL _glfwIsCompositionEnabled(void);
WCHAR* _glfwCreateWideStringFromUTF8(const char* source);
char* _glfwCreateUTF8FromWideString(const WCHAR* source);
void _glfwInitTimer(void);
2010-09-07 17:34:51 +02:00
2015-08-23 19:30:04 +02:00
GLFWbool _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoMode(_GLFWmonitor* monitor);
2010-09-07 17:34:51 +02:00
2015-06-07 19:32:24 +02:00
#endif // _glfw3_win32_platform_h_