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.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. #include "../utility/juce_IncludeModuleHeaders.h"
  33. //==============================================================================
  34. void JUCE_CALLTYPE attachSubWindow (void* hostWindow,
  35. int& titleW, int& titleH,
  36. Component* comp)
  37. {
  38. RECT clientRect;
  39. GetClientRect ((HWND) hostWindow, &clientRect);
  40. titleW = clientRect.right - clientRect.left;
  41. titleH = jmax (0, (int) (clientRect.bottom - clientRect.top) - comp->getHeight());
  42. comp->setTopLeftPosition (0, titleH);
  43. comp->addToDesktop (0);
  44. HWND plugWnd = (HWND) comp->getWindowHandle();
  45. SetParent (plugWnd, (HWND) hostWindow);
  46. DWORD val = GetWindowLong (plugWnd, GWL_STYLE);
  47. val = (val & ~WS_POPUP) | WS_CHILD;
  48. SetWindowLong (plugWnd, GWL_STYLE, val);
  49. val = GetWindowLong ((HWND) hostWindow, GWL_STYLE);
  50. SetWindowLong ((HWND) hostWindow, GWL_STYLE, val | WS_CLIPCHILDREN);
  51. }
  52. void JUCE_CALLTYPE resizeHostWindow (void* hostWindow,
  53. int& titleW, int& titleH,
  54. Component* comp)
  55. {
  56. RECT clientRect, windowRect;
  57. GetClientRect ((HWND) hostWindow, &clientRect);
  58. GetWindowRect ((HWND) hostWindow, &windowRect);
  59. const int borderW = (windowRect.right - windowRect.left) - (clientRect.right - clientRect.left);
  60. const int borderH = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
  61. SetWindowPos ((HWND) hostWindow, 0, 0, 0,
  62. borderW + jmax (titleW, comp->getWidth()),
  63. borderH + comp->getHeight() + titleH,
  64. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  65. }
  66. #if ! JucePlugin_EditorRequiresKeyboardFocus
  67. namespace
  68. {
  69. HWND findMDIParentOf (HWND w)
  70. {
  71. const int frameThickness = GetSystemMetrics (SM_CYFIXEDFRAME);
  72. while (w != 0)
  73. {
  74. HWND parent = GetParent (w);
  75. if (parent == 0)
  76. break;
  77. TCHAR windowType [32] = { 0 };
  78. GetClassName (parent, windowType, 31);
  79. if (String (windowType).equalsIgnoreCase ("MDIClient"))
  80. {
  81. w = parent;
  82. break;
  83. }
  84. RECT windowPos, parentPos;
  85. GetWindowRect (w, &windowPos);
  86. GetWindowRect (parent, &parentPos);
  87. int dw = (parentPos.right - parentPos.left) - (windowPos.right - windowPos.left);
  88. int dh = (parentPos.bottom - parentPos.top) - (windowPos.bottom - windowPos.top);
  89. if (dw > 100 || dh > 100)
  90. break;
  91. w = parent;
  92. if (dw == 2 * frameThickness)
  93. break;
  94. }
  95. return w;
  96. }
  97. }
  98. void JUCE_CALLTYPE passFocusToHostWindow (void* hostWindow)
  99. {
  100. SetFocus (findMDIParentOf ((HWND) hostWindow));
  101. }
  102. #endif
  103. #endif