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.

138 lines
4.3KB

  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. #if ! JucePlugin_EditorRequiresKeyboardFocus
  66. namespace
  67. {
  68. HWND findMDIParentOf (HWND w)
  69. {
  70. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  71. while (w != 0)
  72. {
  73. HWND parent = GetParent (w);
  74. if (parent == 0)
  75. break;
  76. TCHAR windowType [32] = { 0 };
  77. GetClassName (parent, windowType, 31);
  78. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  79. {
  80. w = parent;
  81. break;
  82. }
  83. RECT windowPos, parentPos;
  84. GetWindowRect (w, &windowPos);
  85. GetWindowRect (parent, &parentPos);
  86. int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  87. int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  88. if (dw > 100 || dh > 100)
  89. break;
  90. w = parent;
  91. if (dw == 2 * frameThickness)
  92. break;
  93. }
  94. return w;
  95. }
  96. }
  97. void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
  98. {
  99. SetFocus (findMDIParentOf ((HWND) hostWindow));
  100. }
  101. #endif
  102. #endif