Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marks dpi todo in Develop 1.8 #697

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build/vc2022/nana.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@
<ClInclude Include="..\..\include\nana\internationalization.hpp" />
<ClInclude Include="..\..\include\nana\key_type.hpp" />
<ClInclude Include="..\..\include\nana\paint\font_info.hpp" />
<ClInclude Include="..\..\include\nana\paint\graphics.hpp" />
<ClInclude Include="..\..\include\nana\paint\image.hpp" />
<ClInclude Include="..\..\include\nana\paint\image_process_interface.hpp" />
<ClInclude Include="..\..\include\nana\paint\image_process_selector.hpp" />
<ClInclude Include="..\..\include\nana\paint\pixel_buffer.hpp" />
<ClInclude Include="..\..\include\nana\paint\text_renderer.hpp" />
<ClInclude Include="..\..\include\nana\traits.hpp" />
<ClInclude Include="..\..\include\nana\unicode_bidi.hpp" />
<ClInclude Include="..\..\include\nana\verbose_preprocessor.hpp" />
Expand Down
21 changes: 21 additions & 0 deletions build/vc2022/nana.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<Filter Include="Include\gui\widgets">
<UniqueIdentifier>{0e6a58ab-652c-45d7-b9aa-8d9f2fa80ea1}</UniqueIdentifier>
</Filter>
<Filter Include="Include\paint">
<UniqueIdentifier>{fc600cb9-126e-4bda-9ba6-de1915d3b41b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\source\basic_types.cpp">
Expand Down Expand Up @@ -456,6 +459,24 @@
<ClInclude Include="..\..\include\nana\paint\font_info.hpp" />
<ClInclude Include="..\..\source\paint\detail\image_format_defs.hpp" />
<ClInclude Include="..\..\source\paint\detail\image_gif.hpp" />
<ClInclude Include="..\..\include\nana\paint\graphics.hpp">
<Filter>Include\paint</Filter>
</ClInclude>
<ClInclude Include="..\..\include\nana\paint\image.hpp">
<Filter>Include\paint</Filter>
</ClInclude>
<ClInclude Include="..\..\include\nana\paint\image_process_interface.hpp">
<Filter>Include\paint</Filter>
</ClInclude>
<ClInclude Include="..\..\include\nana\paint\image_process_selector.hpp">
<Filter>Include\paint</Filter>
</ClInclude>
<ClInclude Include="..\..\include\nana\paint\pixel_buffer.hpp">
<Filter>Include\paint</Filter>
</ClInclude>
<ClInclude Include="..\..\include\nana\paint\text_renderer.hpp">
<Filter>Include\paint</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\include\nana\pop_ignore_diagnostic">
Expand Down
2 changes: 1 addition & 1 deletion include/nana/gui/detail/window_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace nana::detail
void set_safe_place(basic_window* wd, std::function<void()>&& fn);
void call_safe_place(thread_t thread_id);

//updates the window elements when DPI is changed.
/// \todo: generalize dpi to v2 awareness - updates the window elements when DPI is changed.
void update_dpi(basic_window*);
private:
void _m_disengage(basic_window*, basic_window* for_new);
Expand Down
8 changes: 4 additions & 4 deletions include/nana/gui/msgbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ namespace nana
text& operator=(const text&) = delete;
public:
text(::std::string label, ::std::string init_text = ::std::string());
text(::std::string label, std::vector<::std::string>);
text(::std::string label, std::vector<::std::string> options);

~text();

Expand Down Expand Up @@ -254,7 +254,7 @@ namespace nana
{
struct implement;
public:
path(::std::string label, const ::nana::filebox&);
path(::std::string label, const ::nana::filebox& f_box);
~path();

::std::string value() const;
Expand All @@ -266,12 +266,12 @@ namespace nana
std::unique_ptr<implement> impl_;
};

inputbox(window owner, ///< A handle to an owner window (just a parent form or widget works)
inputbox(window owner, ///< A handle to an owner window (parent form or widget)
::std::string description, ///< tells users what the purpose for the input. It can be a formatted-text.
::std::string title = ::std::string() ///< The title for the inputbox.
);

/// shows images at left/right side of inputbox
/// shows images at left or right side of the inputbox
void image(::nana::paint::image image, ///< The image
bool is_left, ///< true to place the image at left side, false to the right side
const rectangle& valid_area = {} ///< The area of the image to be displayed
Expand Down
1 change: 1 addition & 0 deletions include/nana/gui/programming_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ namespace api
*/
::std::optional<std::pair<::nana::size, ::nana::size>> content_extent(window wd, unsigned limited_px, bool limit_width);

/// \todo: generalize dpi to v2 awareness
unsigned screen_dpi(bool x_requested);

std::size_t window_dpi(window);
Expand Down
1 change: 1 addition & 0 deletions include/nana/gui/widgets/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace nana
void cursor(nana::cursor);
nana::cursor cursor() const; ///< Retrieves the shape of cursor

/// \todo: generalize dpi to v2 awareness
void typeface(const paint::font_info&); ///< Sets font, the font will be scaled with the DPI of the window.
void typeface(const paint::font& font); ///< Sets font
paint::font typeface() const;
Expand Down
2 changes: 2 additions & 0 deletions include/nana/paint/graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace nana
font(drawable_type);
font(const font&);

/// \todo: generalize dpi to v2 awareness

/// creates a font object.
/// @param info Specifies the font family, size and styles.
/// @param dpi Specifies the DPI for scaling the font, 0 indicates the system DPI.
Expand Down
6 changes: 4 additions & 2 deletions source/detail/platform_abstraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ namespace nana

//end class revertible_mutex


/// \todo: generalize dpi to v2 awareness
struct platform_runtime
{
platform_abstraction::revertible_mutex mutex;
Expand Down Expand Up @@ -1283,6 +1283,7 @@ namespace nana
return data::storage->mutex;
}

/// \todo: generalize dpi to v2 awareness
double platform_abstraction::font_default_pt()
{
#ifdef NANA_WINDOWS
Expand Down Expand Up @@ -1344,6 +1345,7 @@ namespace nana
platform_storage().dpi = dpi;
}

/// \todo: generalize dpi to v2 awareness
std::size_t platform_abstraction::current_dpi()
{
return platform_storage().dpi;
Expand Down Expand Up @@ -1425,7 +1427,7 @@ namespace nana
}
#endif
}

/// \todo: generalize dpi to v2 awareness
unsigned platform_abstraction::screen_dpi(bool x_requested)
{
#ifdef NANA_WINDOWS
Expand Down
3 changes: 3 additions & 0 deletions source/detail/platform_abstraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ namespace nana
static void font_languages(const std::string&);
static ::std::shared_ptr<font> default_font(const ::std::shared_ptr<font>&);

/// \todo: generalize dpi to v2 awareness

/// 'manuallay' set the current system DPI, this is used for DPI scaling.
static void set_current_dpi(std::size_t dpi);
static std::size_t current_dpi();

Expand Down
4 changes: 3 additions & 1 deletion source/gui/detail/bedrock_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# define WM_MOUSEHWHEEL 0x020E
#endif

/// \todo: generalize dpi to v2 awareness
#ifndef WM_DPICHANGED
# define WM_DPICHANGED 0x02E0
#endif
Expand Down Expand Up @@ -231,6 +232,7 @@ namespace detail
restrict::imm_get_composition_string = reinterpret_cast<restrict::imm_get_composition_string_type>(
::GetProcAddress(imm32, "ImmGetCompositionStringW"));

/// \todo: generalize dpi to v2 awareness
platform_abstraction::set_current_dpi(detail::native_interface::system_dpi());
}

Expand Down Expand Up @@ -808,7 +810,7 @@ namespace detail
i->second();
}
break;
case WM_DPICHANGED:
case WM_DPICHANGED: /// \todo: generalize dpi to v2 awareness
wd_manager.update_dpi(msgwnd);
{

Expand Down
41 changes: 29 additions & 12 deletions source/gui/detail/native_window_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace nana{
namespace detail{

#if defined(NANA_WINDOWS)


/// \todo: generalize dpi to v2 awareness
struct DPI_AWARENESS_CONTEXT___ { int unused; }; typedef struct DPI_AWARENESS_CONTEXT___* DPI_AWARENESS_CONTEXT_;

#define DPI_AWARENESS_CONTEXT_UNAWARE_ ((DPI_AWARENESS_CONTEXT_)-1)
Expand All @@ -41,7 +42,7 @@ namespace nana{
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2_ ((DPI_AWARENESS_CONTEXT_)-4)
#define DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED_ ((DPI_AWARENESS_CONTEXT_)-5)

// Dynamically load Windows DPI functions to check these APIs are supported by the SDK and OS.
/// Dynamically load Windows DPI functions to check these APIs are supported by the SDK and OS.
struct dpi_function
{
enum PROCESS_DPI_AWARENESS {
Expand All @@ -57,14 +58,15 @@ namespace nana{
MDT_DEFAULT
};

HRESULT(__stdcall* SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS) {nullptr};
HRESULT(__stdcall* SetProcessDpiAwarenessContext)(DPI_AWARENESS_CONTEXT_) { nullptr };
UINT(__stdcall* GetDpiForWindow)(HWND) { nullptr };
UINT(__stdcall* GetDpiForSystem)() { nullptr };
HRESULT(__stdcall* GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*) { nullptr };
UINT(__stdcall* GetDpiFromDpiAwarenessContext)(void*) { nullptr };
void* (__stdcall* GetThreadDpiAwarenessContext)() { nullptr };
HRESULT(__stdcall* SetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT_) { nullptr };
HRESULT(__stdcall* SetProcessDPIAware )( ) { nullptr }; ///< https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiaware
HRESULT(__stdcall* SetProcessDpiAwareness )(PROCESS_DPI_AWARENESS ) { nullptr }; ///< https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-setprocessdpiawareness
HRESULT(__stdcall* SetProcessDpiAwarenessContext)(DPI_AWARENESS_CONTEXT_) { nullptr }; ///< https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiawarenesscontext
UINT (__stdcall* GetDpiForWindow )(HWND ) { nullptr };
UINT (__stdcall* GetDpiForSystem )( ) { nullptr };
HRESULT(__stdcall* GetDpiForMonitor )(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*) { nullptr };
UINT (__stdcall* GetDpiFromDpiAwarenessContext)(void* ) { nullptr };
void* (__stdcall* GetThreadDpiAwarenessContext )( ) { nullptr };
HRESULT(__stdcall* SetThreadDpiAwarenessContext )(DPI_AWARENESS_CONTEXT_) { nullptr };

dpi_function()
{
Expand Down Expand Up @@ -92,10 +94,17 @@ namespace nana{
}
}


/// todo: generalize dpi to v2 awareness - best test each function separatelly?
bool good() const
{
return this->SetProcessDpiAwareness && this->GetDpiForWindow && this->GetDpiForMonitor && this->GetDpiForSystem && this->GetThreadDpiAwarenessContext
&& this->SetThreadDpiAwarenessContext && this->SetProcessDpiAwarenessContext;
return this->SetProcessDpiAwareness
&& this->GetDpiForWindow
&& this->GetDpiForMonitor
&& this->GetDpiForSystem
&& this->GetThreadDpiAwarenessContext
&& this->SetThreadDpiAwarenessContext
&& this->SetProcessDpiAwarenessContext;
}
};

Expand Down Expand Up @@ -430,6 +439,7 @@ namespace nana{
nana::size native_interface::primary_monitor_size()
{
#if defined(NANA_WINDOWS)
/// \todo: add to dpi_function GetSystemMetricsForDpi and replace this
return nana::size(::GetSystemMetrics(SM_CXSCREEN), ::GetSystemMetrics(SM_CYSCREEN));
#elif defined(NANA_X11)
nana::detail::platform_scope_guard psg;
Expand All @@ -441,6 +451,7 @@ namespace nana{
rectangle native_interface::screen_area_from_point(const point& pos)
{
#if defined(NANA_WINDOWS)
/// \todo: make DPI AWARE
typedef HMONITOR (__stdcall * MonitorFromPointT)(POINT,DWORD);

MonitorFromPointT mfp = reinterpret_cast<MonitorFromPointT>(::GetProcAddress(::GetModuleHandleA("User32.DLL"), "MonitorFromPoint"));
Expand All @@ -451,6 +462,8 @@ namespace nana{

MONITORINFO mi;
mi.cbSize = sizeof mi;

/// \todo: make DPI AWARE
if(::GetMonitorInfo(monitor, &mi))
{
return rectangle(mi.rcWork.left, mi.rcWork.top,
Expand Down Expand Up @@ -488,6 +501,7 @@ namespace nana{
if(owner && (nested == false))
::ClientToScreen(reinterpret_cast<HWND>(owner), &pt);

/// \todo: make DPI AWARE with AdjustWindowRectExForDpi ?
HWND native_wd = ::CreateWindowEx(style_ex, L"NanaWindowInternal", L"Nana Window",
style,
pt.x, pt.y, 100, 100,
Expand Down Expand Up @@ -674,6 +688,7 @@ namespace nana{
{
if(nullptr == parent) return nullptr;
#if defined(NANA_WINDOWS)
/// \todo: make DPI AWARE with AdjustWindowRectExForDpi ?
HWND handle = ::CreateWindowEx(WS_EX_CONTROLPARENT, // Extended possibilities for variation
L"NanaWindowInternal",
L"Nana Child Window", // Title Text
Expand Down Expand Up @@ -1862,6 +1877,7 @@ namespace nana{
int y;
if(true_for_max)
{
/// \todo: add to dpi_function GetSystemMetricsForDpi and replace this
x = ::GetSystemMetrics(SM_CXMAXTRACK);
y = ::GetSystemMetrics(SM_CYMAXTRACK);
if(static_cast<unsigned>(x) < sz.width + ext_width)
Expand All @@ -1871,6 +1887,7 @@ namespace nana{
}
else
{
/// \todo: add to dpi_function GetSystemMetricsForDpi and replace this
x = ::GetSystemMetrics(SM_CXMINTRACK);
y = ::GetSystemMetrics(SM_CYMINTRACK);
if(static_cast<unsigned>(x) > sz.width + ext_width)
Expand Down
2 changes: 1 addition & 1 deletion source/gui/detail/window_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ namespace detail
}
}

//updates the window elements when DPI is changed.
/// \todo: generalize dpi to v2 awareness - updates the window elements when DPI is changed.
void window_manager::update_dpi(basic_window* wd)
{
internal_scope_guard lock;
Expand Down
12 changes: 6 additions & 6 deletions source/gui/msgbox.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/**
* A Message Box Class
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2020 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2024 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file nana/gui/msgbox.hpp
* @Contributors
* @contributors
* James Bremner
* Ariel Vina-Rodriguez
*/

#define NOMINMAX
#include <algorithm> // max
#include <functional>
Expand Down Expand Up @@ -473,15 +474,14 @@ namespace nana
//end class msgbox


//class inputbox todo: add schema

/// class inputbox todo: add schema
class inputbox_window
: public ::nana::form
{
public:
inputbox_window(window owner,
paint::image (&imgs)[4], ///< 4 ref to images
::nana::rectangle (&valid_areas)[4],
paint::image (&imgs)[4], ///< 4 ref to images
::nana::rectangle (&valid_areas)[4], ///< 4 ref to valid areas
const ::std::string & description,
const ::std::string& title,
std::size_t contents,
Expand Down
2 changes: 1 addition & 1 deletion source/gui/place.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ namespace nana

if (1 == set_weight)
{
//avoid deviation in dpi scaling.
/// \todo: generalize dpi to v2 awareness, avoid deviation in dpi scaling.
if (96 != dm.dpi)
this->weight.assign(static_cast<int>(fv * 96 / dm.dpi) + 1);
else
Expand Down
2 changes: 1 addition & 1 deletion source/gui/place_parts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ namespace nana
}moves_;
};//class dockarea


/// \todo: generalize dpi to v2 awareness
struct display_metrics
{
std::size_t dpi;
Expand Down
1 change: 1 addition & 0 deletions source/gui/programming_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,7 @@ namespace api
return false;
}

/// \todo: generalize dpi to v2 awareness
void typeface(window wd, const nana::paint::font_info& fi)
{
internal_scope_guard lock;
Expand Down
1 change: 1 addition & 0 deletions source/gui/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace nana
::nana::size screen::desktop_size()
{
#if defined(NANA_WINDOWS)
/// \todo: add to dpi_function GetSystemMetricsForDpi and replace this
auto w = static_cast<size::value_type>(::GetSystemMetrics(SM_CXVIRTUALSCREEN));
auto h = static_cast<size::value_type>(::GetSystemMetrics(SM_CYVIRTUALSCREEN));
return{w, h};
Expand Down
1 change: 1 addition & 0 deletions source/gui/widgets/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ namespace nana
_m_cursor(cur);
}

/// \todo: generalize dpi to v2 awareness
void widget::typeface(const paint::font_info& fi)
{
api::typeface(handle(), fi);
Expand Down
Loading