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.

143 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #if _MSC_VER
  24. // (these functions are in a separate file because of problems including windows.h
  25. // at the same time as the Digi headers)
  26. #include <windows.h>
  27. #ifdef _MSC_VER
  28. #pragma pack (push, 8)
  29. #endif
  30. #include "../../../../../juce_amalgamated.h"
  31. #ifdef _MSC_VER
  32. #pragma pack (pop)
  33. #endif
  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, (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. static 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];
  77. zeromem (windowType, sizeof (windowType));
  78. GetClassName (parent, windowType, 31);
  79. if (String (windowType).equalsIgnoreCase (T("MDIClient")))
  80. {
  81. w = parent;
  82. break;
  83. }
  84. RECT windowPos;
  85. GetWindowRect (w, &windowPos);
  86. RECT parentPos;
  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. void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
  99. {
  100. SetFocus (findMDIParentOf ((HWND) hostWindow));
  101. }
  102. #endif
  103. #endif