reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit f31dc1fe13ef6d5ba93e1ce6c59197962d8c5685
parent eb453aaca94cc029b16ded25726ae45ed3fc75e8
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu,  7 May 2020 17:35:44 -0400

Merge branch 'hidpi'

Diffstat:
MCMakeLists.txt | 2--
Msrc/CMakeLists.txt | 1+
Msrc/dialog.cpp | 12++++++++++--
Asrc/dllimport.hpp | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/richedit-win32.cpp | 11+++++++++++
5 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -76,8 +76,6 @@ if(VCPKG_TOOLCHAIN) endif() if(WIN32) - add_compile_definitions(NOMINMAX UNICODE) - foreach(arg CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt @@ -115,6 +115,7 @@ target_include_directories(reapack PRIVATE if(WIN32) target_sources(reapack PRIVATE buildinfo.rc) target_compile_options(reapack PUBLIC /W3 /WX /wd4996) + target_compile_definitions(reapack PUBLIC NOMINMAX UNICODE) target_link_libraries(reapack Bcrypt Comctl32 Comdlg32 Gdi32 Shell32 User32) else() target_compile_options(reapack PUBLIC diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -378,8 +378,16 @@ void Dialog::restoreState(Serializer::Data &data) const auto &[x, y] = *it++; const auto &[width, height] = *it++; - SetWindowPos(m_handle, nullptr, 0, 0, - width, height, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); +#ifdef _WIN32 + // Move to the target screen first so the new size is applied with the + // correct DPI in Per-Monitor v2 mode. + // Then boundedMove will correct the position if necessary. + SetWindowPos(m_handle, nullptr, x, y, 0, 0, + SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); +#endif + + SetWindowPos(m_handle, nullptr, 0, 0, width, height, + SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); onResize(); boundedMove(x, y); diff --git a/src/dllimport.hpp b/src/dllimport.hpp @@ -0,0 +1,54 @@ +/* ReaPack: Package manager for REAPER + * Copyright (C) 2015-2020 Christian Fillion + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef REAPACK_DLLIMPORT_HPP +#define REAPACK_DLLIMPORT_HPP + +#ifndef _WIN32 +# error This file should not be included on non-Windows systems. +#endif + +#include <windows.h> + +template<typename Proc, typename = std::enable_if_t<std::is_function_v<Proc>>> +class DllImport { +public: + DllImport(const wchar_t *dll, const char *func) + { + if (m_lib = LoadLibrary(dll)) + m_proc = reinterpret_cast<Proc *>(GetProcAddress(m_lib, func)); + else + m_proc = nullptr; + } + + ~DllImport() + { + if (m_lib) + FreeLibrary(m_lib); + } + + operator bool() const { return m_proc != nullptr; } + + template<typename... Args> + auto operator()(Args&&... args) const { return m_proc(std::forward<Args>(args)...); } + +private: + HINSTANCE m_lib; + Proc *m_proc; +}; + +#endif diff --git a/src/richedit-win32.cpp b/src/richedit-win32.cpp @@ -20,6 +20,7 @@ // This is the Win32 implementation of RichEdit // The macOS implementation is in richedit.mm, Linux is in richedit-generic.cpp +#include "dllimport.hpp" #include "win32.hpp" #include <memory> @@ -51,6 +52,16 @@ RichEdit::RichEdit(HWND handle) SendMessage(handle, EM_SETEVENTMASK, 0, ENM_LINK); SendMessage(handle, EM_SETEDITSTYLE, SES_HYPERLINKTOOLTIPS, SES_HYPERLINKTOOLTIPS); + + // available since Windows 10 version 1703 + static DllImport<decltype(SetDialogControlDpiChangeBehavior)> + _SetDialogControlDpiChangeBehavior + {L"user32.dll", "SetDialogControlDpiChangeBehavior"}; + + if(_SetDialogControlDpiChangeBehavior) { + _SetDialogControlDpiChangeBehavior(handle, + DCDC_DISABLE_FONT_UPDATE, DCDC_DISABLE_FONT_UPDATE); + } } RichEdit::~RichEdit() = default;