Browse Source

Win32: center plugin UIs when opening them

tags/1.9.8
falkTX 7 years ago
parent
commit
a1faf83953
2 changed files with 65 additions and 9 deletions
  1. +37
    -6
      source/modules/dgl/src/Window.cpp
  2. +28
    -3
      source/utils/CarlaPluginUI.cpp

+ 37
- 6
source/modules/dgl/src/Window.cpp View File

@@ -87,7 +87,8 @@ struct Window::PrivateData {
fWidgets(),
fModal(),
#if defined(DISTRHO_OS_WINDOWS)
hwnd(0)
hwnd(nullptr),
hwndParent(nullptr)
#elif defined(DISTRHO_OS_MAC)
fNeedsIdle(true),
mView(nullptr),
@@ -115,7 +116,8 @@ struct Window::PrivateData {
fWidgets(),
fModal(parent.pData),
#if defined(DISTRHO_OS_WINDOWS)
hwnd(0)
hwnd(nullptr),
hwndParent(nullptr)
#elif defined(DISTRHO_OS_MAC)
fNeedsIdle(false),
mView(nullptr),
@@ -132,7 +134,8 @@ struct Window::PrivateData {

// NOTE: almost a 1:1 copy of setTransientWinId()
#if defined(DISTRHO_OS_WINDOWS)
SetWindowLongPtr(hwnd, GWLP_HWNDPARENT, (LONG_PTR)parentImpl->hwnd);
hwndParent = parentImpl->hwnd;
SetWindowLongPtr(hwnd, GWLP_HWNDPARENT, (LONG_PTR)hwndParent);
#elif defined(DISTRHO_OS_MAC)
[mWindow orderWindow:NSWindowBelow relativeTo:parentImpl->window];
#else
@@ -154,7 +157,8 @@ struct Window::PrivateData {
fWidgets(),
fModal(),
#if defined(DISTRHO_OS_WINDOWS)
hwnd(0)
hwnd(nullptr),
hwndParent(nullptr)
#elif defined(DISTRHO_OS_MAC)
fNeedsIdle(parentId == 0),
mView(nullptr),
@@ -434,9 +438,34 @@ struct Window::PrivateData {

#if defined(DISTRHO_OS_WINDOWS)
if (yesNo)
ShowWindow(hwnd, fFirstInit ? SW_SHOWNORMAL : SW_RESTORE);
{
if (fFirstInit)
{
RECT rectChild, rectParent;

if (hwndParent != nullptr &&
GetWindowRect(hwnd, &rectChild) &&
GetWindowRect(hwndParent, &rectParent))
{
SetWindowPos(hwnd, hwndParent,
rectParent.left + (rectChild.right-rectChild.left)/2,
rectParent.top + (rectChild.bottom-rectChild.top)/2,
0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
}
else
{
ShowWindow(hwnd, SW_SHOWNORMAL);
}
}
else
{
ShowWindow(hwnd, SW_RESTORE);
}
}
else
{
ShowWindow(hwnd, SW_HIDE);
}

UpdateWindow(hwnd);
#elif defined(DISTRHO_OS_MAC)
@@ -624,6 +653,7 @@ struct Window::PrivateData {
DISTRHO_SAFE_ASSERT_RETURN(winId != 0,);

#if defined(DISTRHO_OS_WINDOWS)
hwndParent = (HWND)winId;
SetWindowLongPtr(hwnd, GWLP_HWNDPARENT, (LONG_PTR)winId);
#elif defined(DISTRHO_OS_MAC)
NSWindow* const window = [NSApp windowWithWindowNumber:winId];
@@ -979,7 +1009,8 @@ struct Window::PrivateData {
} fModal;

#if defined(DISTRHO_OS_WINDOWS)
HWND hwnd;
HWND hwnd;
HWND hwndParent;
#elif defined(DISTRHO_OS_MAC)
bool fNeedsIdle;
PuglOpenGLView* mView;


+ 28
- 3
source/utils/CarlaPluginUI.cpp View File

@@ -599,7 +599,8 @@ class WindowsPluginUI : public CarlaPluginUI
public:
WindowsPluginUI(Callback* const cb, const uintptr_t parentId, const bool isResizable) noexcept
: CarlaPluginUI(cb, isResizable),
fWindow(0),
fWindow(nullptr),
fParentWindow(nullptr),
fIsVisible(false),
fFirstShow(true)
{
@@ -668,9 +669,31 @@ public:
{
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);

ShowWindow(fWindow, fFirstShow ? SW_SHOWNORMAL : SW_RESTORE);
if (fFirstShow)
{
fFirstShow = false;
RECT rectChild, rectParent;

if (fParentWindow != nullptr &&
GetWindowRect(fWindow, &rectChild) &&
GetWindowRect(fParentWindow, &rectParent))
{
SetWindowPos(fWindow, fParentWindow,
rectParent.left + (rectChild.right-rectChild.left)/2,
rectParent.top + (rectChild.bottom-rectChild.top)/2,
0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
}
else
{
ShowWindow(fWindow, SW_SHOWNORMAL);
}
}
else
{
ShowWindow(fWindow, SW_RESTORE);
}

fIsVisible = true;
fFirstShow = false;
UpdateWindow(fWindow);
}

@@ -762,6 +785,7 @@ public:
{
CARLA_SAFE_ASSERT_RETURN(fWindow != 0,);

fParentWindow = (HWND)winId;
SetWindowLongPtr(fWindow, GWLP_HWNDPARENT, (LONG_PTR)winId);
}

@@ -782,6 +806,7 @@ public:

private:
HWND fWindow;
HWND fParentWindow;
WNDCLASS fWindowClass;

bool fIsVisible;


Loading…
Cancel
Save