Small refactoring

pull/15042/head
Don Ho 2024-04-23 05:21:29 +02:00
parent 560f29fc8c
commit 4ffa8fcdf9
4 changed files with 13 additions and 25 deletions

View File

@ -45,15 +45,21 @@ void ColourPopup::create(int dialogID)
display(); display();
} }
void ColourPopup::createForDpi(int dialogID) void ColourPopup::doDialog(POINT p)
{ {
if (!isCreated())
{
const DPI_AWARENESS_CONTEXT dpiContextSystem = NppDarkMode::isWindows10() ? DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED : DPI_AWARENESS_CONTEXT_SYSTEM_AWARE; const DPI_AWARENESS_CONTEXT dpiContextSystem = NppDarkMode::isWindows10() ? DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED : DPI_AWARENESS_CONTEXT_SYSTEM_AWARE;
const auto dpiContext = DPIManagerV2::setThreadDpiAwarenessContext(dpiContextSystem); const auto dpiContext = DPIManagerV2::setThreadDpiAwarenessContext(dpiContextSystem);
create(dialogID);
create(IDD_COLOUR_POPUP);
if (dpiContext != NULL) if (dpiContext != NULL)
{ {
DPIManagerV2::setThreadDpiAwarenessContext(dpiContext); DPIManagerV2::setThreadDpiAwarenessContext(dpiContext);
} }
}
::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
} }
intptr_t CALLBACK ColourPopup::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) intptr_t CALLBACK ColourPopup::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

View File

@ -37,14 +37,7 @@ public :
} }
void create(int dialogID); void create(int dialogID);
void createForDpi(int dialogID); void doDialog(POINT p);
void doDialog(POINT p)
{
if (!isCreated())
createForDpi(IDD_COLOUR_POPUP);
::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
}
virtual void destroy() virtual void destroy()
{ {

View File

@ -263,16 +263,6 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent)
::SendMessage(msgDestParent ? _hParent : (::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, reinterpret_cast<WPARAM>(_hSelf)); ::SendMessage(msgDestParent ? _hParent : (::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, reinterpret_cast<WPARAM>(_hSelf));
} }
void StaticDialog::createForDpi(int dialogID, bool isRTL, bool msgDestParent, DPI_AWARENESS_CONTEXT dpiAContext)
{
const auto dpiContext = setThreadDpiAwarenessContext(dpiAContext);
create(dialogID, isRTL, msgDestParent);
if (dpiContext != NULL)
{
setThreadDpiAwarenessContext(dpiContext);
}
}
intptr_t CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) intptr_t CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
switch (message) switch (message)

View File

@ -44,7 +44,6 @@ public :
virtual ~StaticDialog(); virtual ~StaticDialog();
virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true); virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true);
virtual void createForDpi(int dialogID, bool isRTL = false, bool msgDestParent = true, DPI_AWARENESS_CONTEXT dpiAContext = DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
virtual bool isCreated() const { virtual bool isCreated() const {
return (_hSelf != nullptr); return (_hSelf != nullptr);