The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../../juce_core/system/juce_TargetPlatform.h"
  18. #include "../utility/juce_CheckSettingMacros.h"
  19. // (these functions are in their own file because of problems including windows.h
  20. // at the same time as the Digi headers)
  21. #if JucePlugin_Build_RTAS
  22. #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY // (workaround for a VC build problem)
  23. #undef _WIN32_WINNT
  24. #define _WIN32_WINNT 0x0500
  25. #undef STRICT
  26. #define STRICT
  27. #include <intrin.h>
  28. #include <windows.h>
  29. #pragma pack (push, 8)
  30. #include "../utility/juce_IncludeModuleHeaders.h"
  31. #pragma pack (pop)
  32. //==============================================================================
  33. void JUCE_CALLTYPE attachSubWindow (void* hostWindow,
  34. int& titleW, int& titleH,
  35. Component* comp)
  36. {
  37. RECT clientRect;
  38. GetClientRect ((HWND) hostWindow, &clientRect);
  39. titleW = clientRect.right - clientRect.left;
  40. titleH = jmax (0, (int) (clientRect.bottom - clientRect.top) - comp->getHeight());
  41. comp->setTopLeftPosition (0, titleH);
  42. comp->addToDesktop (0);
  43. HWND plugWnd = (HWND) comp->getWindowHandle();
  44. SetParent (plugWnd, (HWND) hostWindow);
  45. DWORD val = GetWindowLong (plugWnd, GWL_STYLE);
  46. val = (val & ~WS_POPUP) | WS_CHILD;
  47. SetWindowLong (plugWnd, GWL_STYLE, val);
  48. val = GetWindowLong ((HWND) hostWindow, GWL_STYLE);
  49. SetWindowLong ((HWND) hostWindow, GWL_STYLE, val | WS_CLIPCHILDREN);
  50. }
  51. void JUCE_CALLTYPE resizeHostWindow (void* hostWindow,
  52. int& titleW, int& titleH,
  53. Component* comp)
  54. {
  55. RECT clientRect, windowRect;
  56. GetClientRect ((HWND) hostWindow, &clientRect);
  57. GetWindowRect ((HWND) hostWindow, &windowRect);
  58. const int borderW = (windowRect.right - windowRect.left) - (clientRect.right - clientRect.left);
  59. const int borderH = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
  60. SetWindowPos ((HWND) hostWindow, 0, 0, 0,
  61. borderW + jmax (titleW, comp->getWidth()),
  62. borderH + comp->getHeight() + titleH,
  63. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  64. }
  65. extern "C" BOOL WINAPI DllMainRTAS (HINSTANCE, DWORD, LPVOID);
  66. extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD reason, LPVOID reserved)
  67. {
  68. if (reason == DLL_PROCESS_ATTACH)
  69. Process::setCurrentModuleInstanceHandle (instance);
  70. if (GetModuleHandleA ("DAE.DLL") != 0)
  71. return DllMainRTAS (instance, reason, reserved);
  72. ignoreUnused (reserved);
  73. return TRUE;
  74. }
  75. #if ! JucePlugin_EditorRequiresKeyboardFocus
  76. namespace
  77. {
  78. HWND findMDIParentOf (HWND w)
  79. {
  80. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  81. while (w != 0)
  82. {
  83. HWND parent = GetParent (w);
  84. if (parent == 0)
  85. break;
  86. TCHAR windowType [32] = { 0 };
  87. GetClassName (parent, windowType, 31);
  88. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  89. {
  90. w = parent;
  91. break;
  92. }
  93. RECT windowPos, parentPos;
  94. GetWindowRect (w, &windowPos);
  95. GetWindowRect (parent, &parentPos);
  96. int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  97. int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  98. if (dw > 100 || dh > 100)
  99. break;
  100. w = parent;
  101. if (dw == 2 * frameThickness)
  102. break;
  103. }
  104. return w;
  105. }
  106. }
  107. void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
  108. {
  109. SetFocus (findMDIParentOf ((HWND) hostWindow));
  110. }
  111. #endif
  112. #endif