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.

158 lines
4.8KB

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