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.

141 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. // Your project must contain an AppConfig.h file with your project-specific settings in it,
  18. // and your header search path must make it accessible to the module's files.
  19. #include "AppConfig.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. #if ! JucePlugin_EditorRequiresKeyboardFocus
  68. namespace
  69. {
  70. HWND findMDIParentOf (HWND w)
  71. {
  72. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  73. while (w != 0)
  74. {
  75. HWND parent = GetParent (w);
  76. if (parent == 0)
  77. break;
  78. TCHAR windowType [32] = { 0 };
  79. GetClassName (parent, windowType, 31);
  80. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  81. {
  82. w = parent;
  83. break;
  84. }
  85. RECT windowPos, parentPos;
  86. GetWindowRect (w, &windowPos);
  87. GetWindowRect (parent, &parentPos);
  88. int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  89. int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  90. if (dw > 100 || dh > 100)
  91. break;
  92. w = parent;
  93. if (dw == 2 * frameThickness)
  94. break;
  95. }
  96. return w;
  97. }
  98. }
  99. void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
  100. {
  101. SetFocus (findMDIParentOf ((HWND) hostWindow));
  102. }
  103. #endif
  104. #endif