mirror of
https://github.com/fltk/fltk.git
synced 2026-08-17 08:32:21 +08:00
Add FL/win32_target.h and fix pen support build on Windows
Part 1: the new file FL/win32_target.h simplifies setting minimal Windows version macros to support building with minimal Windows version symbols, such as for Windows 2000 or Windows 8, rather than hardcoding weird C/C++ macro code to define the symbols. Part 2: apply this everywhere where WINVER and _WIN32_WINNT needed to be set manually. Part 3: fix pen support builds on Windows by setting the correct minimal Windows version in the concerned source files. Part 4: fix CMake compilation test for pen support: use a symbol that's really used in the sources.
This commit is contained in:
+3
-13
@@ -21,21 +21,11 @@
|
||||
|
||||
/* We require Windows 8 or later features for Pen/Tablet support */
|
||||
|
||||
# if !defined(WINVER) || (WINVER < 0x0602)
|
||||
# ifdef WINVER
|
||||
# undef WINVER
|
||||
# endif
|
||||
# define WINVER 0x0602
|
||||
# endif
|
||||
# if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0602)
|
||||
# ifdef _WIN32_WINNT
|
||||
# undef _WIN32_WINNT
|
||||
# endif
|
||||
# define _WIN32_WINNT 0x0602
|
||||
# endif
|
||||
#define FL_WIN32_TARGET_VERSION 0x0602
|
||||
#include "../FL/win32_target.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
int main() {
|
||||
return POINTER_CHANGE_FIRSTBUTTON_DOWN; /* required symbol */
|
||||
return POINTER_FLAG_SECONDBUTTON; /* required symbol */
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Define min. Windows version macros for the Fast Light Tool Kit (FLTK).
|
||||
*
|
||||
* Copyright 1998-2026 by Bill Spitzak and others.
|
||||
*
|
||||
* This library is free software. Distribution and use rights are outlined in
|
||||
* the file "COPYING" which should have been included with this file. If this
|
||||
* file is missing or damaged, see the license at:
|
||||
*
|
||||
* https://www.fltk.org/COPYING.php
|
||||
*
|
||||
* Please see the following page on how to report bugs and issues:
|
||||
*
|
||||
* https://www.fltk.org/bugs.php
|
||||
*/
|
||||
|
||||
/**
|
||||
Define the minimum Windows target version for compilation.
|
||||
|
||||
Usage:
|
||||
\code
|
||||
#define FL_WIN32_TARGET_VERSION 0x0602 // Windows 8
|
||||
#include <FL/win32_target.h>
|
||||
#include <windows.h>
|
||||
\endcode
|
||||
|
||||
This file should be included at the very beginning of the source file.
|
||||
It should \b not be included in header files to avoid unwanted side
|
||||
effects: including a header file that wants a higher target version
|
||||
would silently raise the target version for the current source file.
|
||||
Although this would usually be benign, it shouldn't be done.
|
||||
|
||||
One notable exception is that you may have to #include fl_config.h or
|
||||
config.h before this file to determine the required target version,
|
||||
but this should be rare.
|
||||
|
||||
For specific version numbers please refer to Microsoft documentation at
|
||||
https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
|
||||
|
||||
This is an excerpt as of July 2026:
|
||||
\code
|
||||
//
|
||||
// _WIN32_WINNT version constants
|
||||
//
|
||||
#define _WIN32_WINNT_NT4 0x0400 // Windows NT 4.0
|
||||
#define _WIN32_WINNT_WIN2K 0x0500 // Windows 2000
|
||||
#define _WIN32_WINNT_WINXP 0x0501 // Windows XP
|
||||
#define _WIN32_WINNT_WS03 0x0502 // Windows Server 2003
|
||||
#define _WIN32_WINNT_WIN6 0x0600 // Windows Vista
|
||||
#define _WIN32_WINNT_VISTA 0x0600 // Windows Vista
|
||||
#define _WIN32_WINNT_WS08 0x0600 // Windows Server 2008
|
||||
#define _WIN32_WINNT_LONGHORN 0x0600 // Windows Vista
|
||||
#define _WIN32_WINNT_WIN7 0x0601 // Windows 7
|
||||
#define _WIN32_WINNT_WIN8 0x0602 // Windows 8
|
||||
#define _WIN32_WINNT_WINBLUE 0x0603 // Windows 8.1
|
||||
#define _WIN32_WINNT_WIN10 0x0A00 // Windows 10
|
||||
\endcode
|
||||
*/
|
||||
|
||||
#ifndef FL_WIN32_TARGET_VERSION
|
||||
# error "Please define FL_WIN32_TARGET_VERSION before including FL/win32_target.h"
|
||||
#endif
|
||||
|
||||
/* _WIN32_WINNT */
|
||||
#ifndef _WIN32_WINNT
|
||||
# define _WIN32_WINNT FL_WIN32_TARGET_VERSION
|
||||
#elif _WIN32_WINNT < FL_WIN32_TARGET_VERSION
|
||||
# undef _WIN32_WINNT
|
||||
# define _WIN32_WINNT FL_WIN32_TARGET_VERSION
|
||||
#endif
|
||||
|
||||
/* WINVER */
|
||||
#ifndef WINVER
|
||||
# define WINVER FL_WIN32_TARGET_VERSION
|
||||
#elif WINVER < FL_WIN32_TARGET_VERSION
|
||||
# undef WINVER
|
||||
# define WINVER FL_WIN32_TARGET_VERSION
|
||||
#endif
|
||||
|
||||
// Note: we can't undefine the macro because this would break the build.
|
||||
// #undef FL_WIN32_TARGET_VERSION
|
||||
+8
-15
@@ -21,19 +21,10 @@
|
||||
// in. Search other files for "_WIN32" or filenames ending in _win32.cxx
|
||||
// for other system-specific code.
|
||||
|
||||
/* We require Windows 2000 features (e.g. VK definitions) */
|
||||
# if !defined(WINVER) || (WINVER < 0x0500)
|
||||
# ifdef WINVER
|
||||
# undef WINVER
|
||||
# endif
|
||||
# define WINVER 0x0500
|
||||
# endif
|
||||
# if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
|
||||
# ifdef _WIN32_WINNT
|
||||
# undef _WIN32_WINNT
|
||||
# endif
|
||||
# define _WIN32_WINNT 0x0500
|
||||
# endif
|
||||
/* We require at least Windows 2000 features (e.g. VK definitions) */
|
||||
|
||||
#define FL_WIN32_TARGET_VERSION 0x0500
|
||||
#include <FL/win32_target.h>
|
||||
|
||||
// recent versions of MinGW warn: "Please include winsock2.h before windows.h"
|
||||
#if !defined(__CYGWIN__)
|
||||
@@ -59,7 +50,9 @@ void fl_cleanup_dc_list(void);
|
||||
#include "Fl_Timeout.h"
|
||||
#include "print_button.h"
|
||||
#include <FL/Fl_Graphics_Driver.H> // for fl_graphics_driver
|
||||
#if FLTK_HAVE_PEN_SUPPORT
|
||||
#include "drivers/WinAPI/Fl_WinAPI_Pen_Driver.H"
|
||||
#endif
|
||||
#include "drivers/WinAPI/Fl_WinAPI_Window_Driver.H"
|
||||
#include "drivers/WinAPI/Fl_WinAPI_System_Driver.H"
|
||||
#include "drivers/WinAPI/Fl_WinAPI_Screen_Driver.H"
|
||||
@@ -1151,7 +1144,7 @@ static const struct {
|
||||
{VK_DIVIDE, FL_KP+'/'},
|
||||
{VK_NUMLOCK, FL_Num_Lock},
|
||||
{VK_SCROLL, FL_Scroll_Lock},
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0500)
|
||||
|
||||
{VK_BROWSER_BACK, FL_Back},
|
||||
{VK_BROWSER_FORWARD, FL_Forward},
|
||||
{VK_BROWSER_REFRESH, FL_Refresh},
|
||||
@@ -1167,7 +1160,7 @@ static const struct {
|
||||
{VK_MEDIA_STOP, FL_Media_Stop},
|
||||
{VK_MEDIA_PLAY_PAUSE, FL_Media_Play},
|
||||
{VK_LAUNCH_MAIL, FL_Mail},
|
||||
#endif
|
||||
|
||||
{0xba, ';'},
|
||||
{0xbb, '='}, // 0xbb == VK_OEM_PLUS (see #1086)
|
||||
{0xbc, ','},
|
||||
|
||||
@@ -19,19 +19,11 @@
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
/* We require Windows 2000 features such as GetGlyphIndices */
|
||||
#if !defined(WINVER) || (WINVER < 0x0500)
|
||||
# ifdef WINVER
|
||||
# undef WINVER
|
||||
# endif
|
||||
# define WINVER 0x0500
|
||||
#endif
|
||||
#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
|
||||
# ifdef _WIN32_WINNT
|
||||
# undef _WIN32_WINNT
|
||||
# endif
|
||||
# define _WIN32_WINNT 0x0500
|
||||
#endif
|
||||
#define FL_WIN32_TARGET_VERSION 0x0500
|
||||
#include <FL/win32_target.h>
|
||||
#include <windows.h>
|
||||
|
||||
// Select fonts from the FLTK font table.
|
||||
#include "Fl_GDI_Graphics_Driver.H"
|
||||
|
||||
@@ -22,20 +22,6 @@
|
||||
|
||||
#include "src/drivers/Base/Fl_Base_Pen_Driver.H"
|
||||
|
||||
// The Pointer Input API (GetPointerType, GetPointerPenInfo, POINTER_PEN_INFO,
|
||||
// PEN_MASK_*, IS_POINTER_*_WPARAM, ...) requires Windows 8 (_WIN32_WINNT >=
|
||||
// 0x0602). Define this *before* <windows.h> is first included anywhere in the
|
||||
// translation unit. If FL/Fl.H or another FLTK header pulls in <windows.h>
|
||||
// first with a lower target, raise the project-wide _WIN32_WINNT instead
|
||||
// (e.g. in fl_config.h) and remove the guard below.
|
||||
#ifndef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0602
|
||||
#endif
|
||||
#ifndef WINVER
|
||||
# define WINVER _WIN32_WINNT
|
||||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
namespace Fl {
|
||||
|
||||
namespace Pen {
|
||||
|
||||
@@ -14,6 +14,16 @@
|
||||
// https://www.fltk.org/bugs.php
|
||||
//
|
||||
|
||||
// The Pointer Input API (GetPointerType, GetPointerPenInfo, POINTER_PEN_INFO,
|
||||
// PEN_MASK_*, IS_POINTER_*_WPARAM, ...) requires Windows 8 features
|
||||
// (_WIN32_WINNT >= 0x0602). Define this *before* <windows.h> is first included
|
||||
// anywhere in the translation unit. See FL/win32_target.h on how to do this.
|
||||
|
||||
#define FL_WIN32_TARGET_VERSION 0x0602
|
||||
#include <FL/win32_target.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
/*
|
||||
Design notes — Windows Pointer Input vs. Wayland/Cocoa tablet architecture
|
||||
───────────────────────────────────────────────────────────────────────────
|
||||
|
||||
+1
-1
@@ -306,7 +306,7 @@ if(CMAKE_CXX_COMPILER_ID IN_LIST _compilers)
|
||||
foreach(hd ${all_headers})
|
||||
get_filename_component(hd "${hd}" NAME)
|
||||
# skip headers that must not be included directly and fl_config.h if it exists
|
||||
string(REGEX MATCH "^(mac|win32|x11|wayland|fl_config|gl[a-z_0-9]*)\.[hH]$" skip "${hd}")
|
||||
string(REGEX MATCH "^(mac|win32.*|x11|wayland|fl_config|gl[a-z_0-9]*)\.[hH]$" skip "${hd}")
|
||||
if(skip STREQUAL "")
|
||||
file(APPEND ${include_all} "#include <FL/${hd}>\n")
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user