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.

151 lines
4.5KB

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