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.

140 lines
4.3KB

  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.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. }
  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. static HWND findMDIParentOf (HWND w)
  67. {
  68. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  69. while (w != 0)
  70. {
  71. HWND parent = GetParent (w);
  72. if (parent == 0)
  73. break;
  74. TCHAR windowType [32];
  75. zeromem (windowType, sizeof (windowType));
  76. GetClassName (parent, windowType, 31);
  77. if (String (windowType).equalsIgnoreCase (T("MDIClient")))
  78. {
  79. w = parent;
  80. break;
  81. }
  82. RECT windowPos;
  83. GetWindowRect (w, &windowPos);
  84. RECT parentPos;
  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. void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
  97. {
  98. SetFocus (findMDIParentOf ((HWND) hostWindow));
  99. }
  100. #endif
  101. #endif