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.

142 lines
4.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. // Your project must contain an AppConfig.h file with your project-specific settings in it,
  19. // and your header search path must make it accessible to the module's files.
  20. #include "AppConfig.h"
  21. #include "../utility/juce_CheckSettingMacros.h"
  22. // (these functions are in their own file because of problems including windows.h
  23. // at the same time as the Digi headers)
  24. #if JucePlugin_Build_RTAS
  25. #define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY // (workaround for a VC build problem)
  26. #undef _WIN32_WINNT
  27. #define _WIN32_WINNT 0x0500
  28. #undef STRICT
  29. #define STRICT
  30. #include <intrin.h>
  31. #include <windows.h>
  32. #pragma pack (push, 8)
  33. #include "../utility/juce_IncludeModuleHeaders.h"
  34. #pragma pack (pop)
  35. //==============================================================================
  36. void JUCE_CALLTYPE attachSubWindow (void* hostWindow,
  37. int& titleW, int& titleH,
  38. Component* comp)
  39. {
  40. RECT clientRect;
  41. GetClientRect ((HWND) hostWindow, &clientRect);
  42. titleW = clientRect.right - clientRect.left;
  43. titleH = jmax (0, (int) (clientRect.bottom - clientRect.top) - comp->getHeight());
  44. comp->setTopLeftPosition (0, titleH);
  45. comp->addToDesktop (0);
  46. HWND plugWnd = (HWND) comp->getWindowHandle();
  47. SetParent (plugWnd, (HWND) hostWindow);
  48. DWORD val = GetWindowLong (plugWnd, GWL_STYLE);
  49. val = (val & ~WS_POPUP) | WS_CHILD;
  50. SetWindowLong (plugWnd, GWL_STYLE, val);
  51. val = GetWindowLong ((HWND) hostWindow, GWL_STYLE);
  52. SetWindowLong ((HWND) hostWindow, GWL_STYLE, val | WS_CLIPCHILDREN);
  53. }
  54. void JUCE_CALLTYPE resizeHostWindow (void* hostWindow,
  55. int& titleW, int& titleH,
  56. Component* comp)
  57. {
  58. RECT clientRect, windowRect;
  59. GetClientRect ((HWND) hostWindow, &clientRect);
  60. GetWindowRect ((HWND) hostWindow, &windowRect);
  61. const int borderW = (windowRect.right - windowRect.left) - (clientRect.right - clientRect.left);
  62. const int borderH = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
  63. SetWindowPos ((HWND) hostWindow, 0, 0, 0,
  64. borderW + jmax (titleW, comp->getWidth()),
  65. borderH + comp->getHeight() + titleH,
  66. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  67. }
  68. #if ! JucePlugin_EditorRequiresKeyboardFocus
  69. namespace
  70. {
  71. HWND findMDIParentOf (HWND w)
  72. {
  73. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  74. while (w != 0)
  75. {
  76. HWND parent = GetParent (w);
  77. if (parent == 0)
  78. break;
  79. TCHAR windowType [32] = { 0 };
  80. GetClassName (parent, windowType, 31);
  81. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  82. {
  83. w = parent;
  84. break;
  85. }
  86. RECT windowPos, parentPos;
  87. GetWindowRect (w, &windowPos);
  88. GetWindowRect (parent, &parentPos);
  89. int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  90. int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  91. if (dw > 100 || dh > 100)
  92. break;
  93. w = parent;
  94. if (dw == 2 * frameThickness)
  95. break;
  96. }
  97. return w;
  98. }
  99. }
  100. void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
  101. {
  102. SetFocus (findMDIParentOf ((HWND) hostWindow));
  103. }
  104. #endif
  105. #endif