Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / src / audio / plugin_client / RTAS / juce_RTAS_WinUtilities.cpp
blob8896590b2f8e979a4a020d97847308c546688655
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 // (these functions are in their own file because of problems including windows.h
27 // at the same time as the Digi headers)
29 #if _MSC_VER
31 #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY // (workaround for a VC build problem)
32 #include <intrin.h>
33 #include <windows.h>
35 #pragma pack (push, 8)
36 #include "../juce_PluginHeaders.h"
37 #pragma pack (pop)
39 #if JucePlugin_Build_RTAS
41 //==============================================================================
42 void JUCE_CALLTYPE attachSubWindow (void* hostWindow,
43 int& titleW, int& titleH,
44 Component* comp)
46 RECT clientRect;
47 GetClientRect ((HWND) hostWindow, &clientRect);
49 titleW = clientRect.right - clientRect.left;
50 titleH = jmax (0, (int) (clientRect.bottom - clientRect.top) - comp->getHeight());
51 comp->setTopLeftPosition (0, titleH);
53 comp->addToDesktop (0);
55 HWND plugWnd = (HWND) comp->getWindowHandle();
56 SetParent (plugWnd, (HWND) hostWindow);
58 DWORD val = GetWindowLong (plugWnd, GWL_STYLE);
59 val = (val & ~WS_POPUP) | WS_CHILD;
60 SetWindowLong (plugWnd, GWL_STYLE, val);
62 val = GetWindowLong ((HWND) hostWindow, GWL_STYLE);
63 SetWindowLong ((HWND) hostWindow, GWL_STYLE, val | WS_CLIPCHILDREN);
66 void JUCE_CALLTYPE resizeHostWindow (void* hostWindow,
67 int& titleW, int& titleH,
68 Component* comp)
70 RECT clientRect, windowRect;
71 GetClientRect ((HWND) hostWindow, &clientRect);
72 GetWindowRect ((HWND) hostWindow, &windowRect);
73 const int borderW = (windowRect.right - windowRect.left) - (clientRect.right - clientRect.left);
74 const int borderH = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
76 SetWindowPos ((HWND) hostWindow, 0, 0, 0,
77 borderW + jmax (titleW, comp->getWidth()),
78 borderH + comp->getHeight() + titleH,
79 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
82 #if ! JucePlugin_EditorRequiresKeyboardFocus
84 namespace
86 HWND findMDIParentOf (HWND w)
88 const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
90 while (w != 0)
92 HWND parent = GetParent (w);
94 if (parent == 0)
95 break;
97 TCHAR windowType [32] = { 0 };
98 GetClassName (parent, windowType, 31);
100 if (String (windowType).equalsIgnoreCase ("MDIClient"))
102 w = parent;
103 break;
106 RECT windowPos, parentPos;
107 GetWindowRect (w, &windowPos);
108 GetWindowRect (parent, &parentPos);
110 int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
111 int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
113 if (dw > 100 || dh > 100)
114 break;
116 w = parent;
118 if (dw == 2 * frameThickness)
119 break;
122 return w;
126 void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
128 SetFocus (findMDIParentOf ((HWND) hostWindow));
131 #endif
132 #endif
133 #endif