EditorWidget-win.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*****************************************************************************
  2. Copyright (C) 2016-2017 by Colin Edwards.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. *****************************************************************************/
  14. #include <QGridLayout>
  15. #include "../headers/EditorWidget.h"
  16. void EditorWidget::buildEffectContainer(AEffect *effect)
  17. {
  18. WNDCLASSEXW wcex{sizeof(wcex)};
  19. wcex.lpfnWndProc = DefWindowProcW;
  20. wcex.hInstance = GetModuleHandleW(nullptr);
  21. wcex.lpszClassName = L"Minimal VST host - Guest VST Window Frame";
  22. RegisterClassExW(&wcex);
  23. const auto style = WS_CAPTION | WS_THICKFRAME | WS_OVERLAPPEDWINDOW;
  24. windowHandle = CreateWindowW(wcex.lpszClassName, TEXT(""), style, 0, 0,
  25. 0, 0, nullptr, nullptr, nullptr, nullptr);
  26. // set pointer to vst effect for window long
  27. LONG_PTR wndPtr = (LONG_PTR)effect;
  28. SetWindowLongPtr(windowHandle, -21 /*GWLP_USERDATA*/, wndPtr);
  29. QWidget *widget = QWidget::createWindowContainer(
  30. QWindow::fromWinId((WId)windowHandle), nullptr);
  31. widget->move(0, 0);
  32. QGridLayout *layout = new QGridLayout();
  33. layout->setContentsMargins(0, 0, 0, 0);
  34. layout->setSpacing(0);
  35. setLayout(layout);
  36. layout->addWidget(widget);
  37. effect->dispatcher(effect, effEditOpen, 0, 0, windowHandle, 0);
  38. VstRect *vstRect = nullptr;
  39. effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0);
  40. if (vstRect) {
  41. widget->resize(vstRect->right - vstRect->left,
  42. vstRect->bottom - vstRect->top);
  43. resize(vstRect->right - vstRect->left,
  44. vstRect->bottom - vstRect->top);
  45. } else {
  46. widget->resize(300, 300);
  47. }
  48. }
  49. void EditorWidget::handleResizeRequest(int, int)
  50. {
  51. // Some plugins can't resize automatically (like SPAN by Voxengo),
  52. // so we must resize window manually
  53. // get pointer to vst effect from window long
  54. LONG_PTR wndPtr = (LONG_PTR)GetWindowLongPtrW(windowHandle,
  55. -21 /*GWLP_USERDATA*/);
  56. AEffect *effect = (AEffect *)(wndPtr);
  57. VstRect *rec = nullptr;
  58. effect->dispatcher(effect, effEditGetRect, 0, 0, &rec, 0);
  59. if (rec) {
  60. resize(rec->right - rec->left, rec->bottom - rec->top);
  61. }
  62. }