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.

154 lines
4.7KB

  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. #include "../../juce_core/system/juce_TargetPlatform.h"
  20. #include "../utility/juce_CheckSettingMacros.h"
  21. // (these functions are in their own file because of problems including windows.h
  22. // at the same time as the Digi headers)
  23. #if JucePlugin_Build_RTAS
  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. //==============================================================================
  35. void JUCE_CALLTYPE attachSubWindow (void* hostWindow,
  36. int& titleW, int& titleH,
  37. Component* comp)
  38. {
  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. RECT clientRect, windowRect;
  58. GetClientRect ((HWND) hostWindow, &clientRect);
  59. GetWindowRect ((HWND) hostWindow, &windowRect);
  60. const int borderW = (windowRect.right - windowRect.left) - (clientRect.right - clientRect.left);
  61. const int borderH = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
  62. SetWindowPos ((HWND) hostWindow, 0, 0, 0,
  63. borderW + jmax (titleW, comp->getWidth()),
  64. borderH + comp->getHeight() + titleH,
  65. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  66. }
  67. extern "C" BOOL WINAPI DllMainRTAS (HINSTANCE, DWORD, LPVOID);
  68. extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD reason, LPVOID reserved)
  69. {
  70. if (reason == DLL_PROCESS_ATTACH)
  71. Process::setCurrentModuleInstanceHandle (instance);
  72. if (GetModuleHandleA ("DAE.DLL") != 0)
  73. return DllMainRTAS (instance, reason, reserved);
  74. ignoreUnused (reserved);
  75. return TRUE;
  76. }
  77. #if ! JucePlugin_EditorRequiresKeyboardFocus
  78. namespace
  79. {
  80. HWND findMDIParentOf (HWND w)
  81. {
  82. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  83. while (w != 0)
  84. {
  85. HWND parent = GetParent (w);
  86. if (parent == 0)
  87. break;
  88. TCHAR windowType [32] = { 0 };
  89. GetClassName (parent, windowType, 31);
  90. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  91. {
  92. w = parent;
  93. break;
  94. }
  95. RECT windowPos, parentPos;
  96. GetWindowRect (w, &windowPos);
  97. GetWindowRect (parent, &parentPos);
  98. int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  99. int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  100. if (dw > 100 || dh > 100)
  101. break;
  102. w = parent;
  103. if (dw == 2 * frameThickness)
  104. break;
  105. }
  106. return w;
  107. }
  108. }
  109. void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
  110. {
  111. SetFocus (findMDIParentOf ((HWND) hostWindow));
  112. }
  113. #endif
  114. #endif