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.

160 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #if JucePlugin_Build_RTAS
  20. #include "../../juce_core/system/juce_TargetPlatform.h"
  21. #include "../utility/juce_CheckSettingMacros.h"
  22. // (these functions are in their own file because of problems including windows.h
  23. // at the same time as the Digi headers)
  24. #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY // (workaround for a VC build problem)
  25. #undef _WIN32_WINNT
  26. #define _WIN32_WINNT 0x0500
  27. #undef STRICT
  28. #define STRICT
  29. #include <intrin.h>
  30. #include <windows.h>
  31. #pragma pack (push, 8)
  32. #include "../utility/juce_IncludeModuleHeaders.h"
  33. #pragma pack (pop)
  34. namespace juce
  35. {
  36. //==============================================================================
  37. void JUCE_CALLTYPE attachSubWindow (void* hostWindow,
  38. int& titleW, int& titleH,
  39. Component* comp)
  40. {
  41. RECT clientRect;
  42. GetClientRect ((HWND) hostWindow, &clientRect);
  43. titleW = clientRect.right - clientRect.left;
  44. titleH = jmax (0, (int) (clientRect.bottom - clientRect.top) - comp->getHeight());
  45. comp->setTopLeftPosition (0, titleH);
  46. comp->addToDesktop (0);
  47. HWND plugWnd = (HWND) comp->getWindowHandle();
  48. SetParent (plugWnd, (HWND) hostWindow);
  49. DWORD val = GetWindowLong (plugWnd, GWL_STYLE);
  50. val = (val & ~WS_POPUP) | WS_CHILD;
  51. SetWindowLong (plugWnd, GWL_STYLE, val);
  52. val = GetWindowLong ((HWND) hostWindow, GWL_STYLE);
  53. SetWindowLong ((HWND) hostWindow, GWL_STYLE, val | WS_CLIPCHILDREN);
  54. }
  55. void JUCE_CALLTYPE resizeHostWindow (void* hostWindow,
  56. int& titleW, int& titleH,
  57. Component* comp)
  58. {
  59. RECT clientRect, windowRect;
  60. GetClientRect ((HWND) hostWindow, &clientRect);
  61. GetWindowRect ((HWND) hostWindow, &windowRect);
  62. const int borderW = (windowRect.right - windowRect.left) - (clientRect.right - clientRect.left);
  63. const int borderH = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
  64. SetWindowPos ((HWND) hostWindow, 0, 0, 0,
  65. borderW + jmax (titleW, comp->getWidth()),
  66. borderH + comp->getHeight() + titleH,
  67. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  68. }
  69. extern "C" BOOL WINAPI DllMainRTAS (HINSTANCE, DWORD, LPVOID);
  70. extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD reason, LPVOID reserved)
  71. {
  72. if (reason == DLL_PROCESS_ATTACH)
  73. Process::setCurrentModuleInstanceHandle (instance);
  74. if (GetModuleHandleA ("DAE.DLL") != 0)
  75. return DllMainRTAS (instance, reason, reserved);
  76. ignoreUnused (reserved);
  77. return TRUE;
  78. }
  79. #if ! JucePlugin_EditorRequiresKeyboardFocus
  80. namespace
  81. {
  82. HWND findMDIParentOf (HWND w)
  83. {
  84. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  85. while (w != 0)
  86. {
  87. HWND parent = GetParent (w);
  88. if (parent == 0)
  89. break;
  90. TCHAR windowType [32] = { 0 };
  91. GetClassName (parent, windowType, 31);
  92. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  93. {
  94. w = parent;
  95. break;
  96. }
  97. RECT windowPos, parentPos;
  98. GetWindowRect (w, &windowPos);
  99. GetWindowRect (parent, &parentPos);
  100. int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  101. int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  102. if (dw > 100 || dh > 100)
  103. break;
  104. w = parent;
  105. if (dw == 2 * frameThickness)
  106. break;
  107. }
  108. return w;
  109. }
  110. }
  111. void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
  112. {
  113. SetFocus (findMDIParentOf ((HWND) hostWindow));
  114. }
  115. #endif
  116. } // namespace juce
  117. #endif