Signed-off-by: falkTX <falktx@falktx.com>popup-tests
| @@ -0,0 +1,32 @@ | |||||
| /* | |||||
| * DISTRHO Plugin Framework (DPF) | |||||
| * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com> | |||||
| * | |||||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | |||||
| * or without fee is hereby granted, provided that the above copyright notice and this | |||||
| * permission notice appear in all copies. | |||||
| * | |||||
| * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD | |||||
| * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN | |||||
| * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||||
| * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER | |||||
| * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |||||
| * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||||
| */ | |||||
| #ifndef DGL_WEB_VIEW_HPP_INCLUDED | |||||
| #define DGL_WEB_VIEW_HPP_INCLUDED | |||||
| #include "Base.hpp" | |||||
| START_NAMESPACE_DGL | |||||
| #include "../distrho/extra/WebViewImpl.hpp" | |||||
| #if defined(HAVE_X11) && defined(DISTRHO_OS_LINUX) | |||||
| int dpf_webview_start(int argc, char* argv[]); | |||||
| #endif | |||||
| END_NAMESPACE_DGL | |||||
| #endif // DGL_WEB_VIEW_HPP_INCLUDED | |||||
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
| * Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com> | |||||
| * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | * Permission to use, copy, modify, and/or distribute this software for any purpose with | ||||
| * or without fee is hereby granted, provided that the above copyright notice and this | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
| @@ -23,6 +23,10 @@ | |||||
| # include "FileBrowserDialog.hpp" | # include "FileBrowserDialog.hpp" | ||||
| #endif | #endif | ||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| # include "WebView.hpp" | |||||
| #endif | |||||
| #include <vector> | #include <vector> | ||||
| #ifdef DISTRHO_NAMESPACE | #ifdef DISTRHO_NAMESPACE | ||||
| @@ -407,6 +411,27 @@ public: | |||||
| bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options = FileBrowserOptions()); | bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options = FileBrowserOptions()); | ||||
| #endif | #endif | ||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| /** | |||||
| Create a new web view. | |||||
| The web view will be added on top of this window. | |||||
| This means it will draw on top of whatever is below it, | |||||
| something to take into consideration if mixing regular widgets with web views. | |||||
| Provided metrics in @p options must have scale factor pre-applied. | |||||
| @p url: The URL to open, assumed to be in encoded form (e.g spaces converted to %20) | |||||
| @p options: Extra options, optional | |||||
| */ | |||||
| bool createWebView(const char* url, const DGL_NAMESPACE::WebViewOptions& options = WebViewOptions()); | |||||
| /** | |||||
| Evaluate/run JavaScript on the web view. | |||||
| */ | |||||
| void evaluateJS(const char* js); | |||||
| #endif | |||||
| /** | /** | ||||
| Request repaint of this window, for the entire area. | Request repaint of this window, for the entire area. | ||||
| */ | */ | ||||
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
| * Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com> | |||||
| * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | * Permission to use, copy, modify, and/or distribute this software for any purpose with | ||||
| * or without fee is hereby granted, provided that the above copyright notice and this | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
| @@ -421,6 +421,20 @@ bool Window::openFileBrowser(const FileBrowserOptions& options) | |||||
| } | } | ||||
| #endif | #endif | ||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| bool Window::createWebView(const char* const url, const DGL_NAMESPACE::WebViewOptions& options) | |||||
| { | |||||
| return pData->createWebView(url, options); | |||||
| } | |||||
| void Window::evaluateJS(const char* const js) | |||||
| { | |||||
| DISTRHO_SAFE_ASSERT_RETURN(pData->webViewHandle != nullptr,); | |||||
| webViewEvaluateJS(pData->webViewHandle, js); | |||||
| } | |||||
| #endif | |||||
| void Window::repaint() noexcept | void Window::repaint() noexcept | ||||
| { | { | ||||
| if (pData->view == nullptr) | if (pData->view == nullptr) | ||||
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
| * Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com> | |||||
| * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | * Permission to use, copy, modify, and/or distribute this software for any purpose with | ||||
| * or without fee is hereby granted, provided that the above copyright notice and this | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
| @@ -128,6 +128,9 @@ Window::PrivateData::PrivateData(Application& a, Window* const s) | |||||
| filenameToRenderInto(nullptr), | filenameToRenderInto(nullptr), | ||||
| #ifdef DGL_USE_FILE_BROWSER | #ifdef DGL_USE_FILE_BROWSER | ||||
| fileBrowserHandle(nullptr), | fileBrowserHandle(nullptr), | ||||
| #endif | |||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| webViewHandle(nullptr), | |||||
| #endif | #endif | ||||
| modal() | modal() | ||||
| { | { | ||||
| @@ -158,6 +161,9 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, PrivateData* c | |||||
| filenameToRenderInto(nullptr), | filenameToRenderInto(nullptr), | ||||
| #ifdef DGL_USE_FILE_BROWSER | #ifdef DGL_USE_FILE_BROWSER | ||||
| fileBrowserHandle(nullptr), | fileBrowserHandle(nullptr), | ||||
| #endif | |||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| webViewHandle(nullptr), | |||||
| #endif | #endif | ||||
| modal(ppData) | modal(ppData) | ||||
| { | { | ||||
| @@ -190,6 +196,9 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, | |||||
| filenameToRenderInto(nullptr), | filenameToRenderInto(nullptr), | ||||
| #ifdef DGL_USE_FILE_BROWSER | #ifdef DGL_USE_FILE_BROWSER | ||||
| fileBrowserHandle(nullptr), | fileBrowserHandle(nullptr), | ||||
| #endif | |||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| webViewHandle(nullptr), | |||||
| #endif | #endif | ||||
| modal() | modal() | ||||
| { | { | ||||
| @@ -225,6 +234,9 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, | |||||
| filenameToRenderInto(nullptr), | filenameToRenderInto(nullptr), | ||||
| #ifdef DGL_USE_FILE_BROWSER | #ifdef DGL_USE_FILE_BROWSER | ||||
| fileBrowserHandle(nullptr), | fileBrowserHandle(nullptr), | ||||
| #endif | |||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| webViewHandle(nullptr), | |||||
| #endif | #endif | ||||
| modal() | modal() | ||||
| { | { | ||||
| @@ -245,6 +257,10 @@ Window::PrivateData::~PrivateData() | |||||
| #ifdef DGL_USE_FILE_BROWSER | #ifdef DGL_USE_FILE_BROWSER | ||||
| if (fileBrowserHandle != nullptr) | if (fileBrowserHandle != nullptr) | ||||
| fileBrowserClose(fileBrowserHandle); | fileBrowserClose(fileBrowserHandle); | ||||
| #endif | |||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| if (webViewHandle != nullptr) | |||||
| webViewDestroy(webViewHandle); | |||||
| #endif | #endif | ||||
| puglHide(view); | puglHide(view); | ||||
| appData->oneWindowClosed(); | appData->oneWindowClosed(); | ||||
| @@ -392,13 +408,21 @@ void Window::PrivateData::hide() | |||||
| if (modal.enabled) | if (modal.enabled) | ||||
| stopModal(); | stopModal(); | ||||
| #ifdef DGL_USE_FILE_BROWSER | |||||
| #ifdef DGL_USE_FILE_BROWSER | |||||
| if (fileBrowserHandle != nullptr) | if (fileBrowserHandle != nullptr) | ||||
| { | { | ||||
| fileBrowserClose(fileBrowserHandle); | fileBrowserClose(fileBrowserHandle); | ||||
| fileBrowserHandle = nullptr; | fileBrowserHandle = nullptr; | ||||
| } | } | ||||
| #endif | |||||
| #endif | |||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| if (webViewHandle != nullptr) | |||||
| { | |||||
| webViewDestroy(webViewHandle); | |||||
| webViewHandle = nullptr; | |||||
| } | |||||
| #endif | |||||
| puglHide(view); | puglHide(view); | ||||
| @@ -441,6 +465,11 @@ void Window::PrivateData::idleCallback() | |||||
| fileBrowserHandle = nullptr; | fileBrowserHandle = nullptr; | ||||
| } | } | ||||
| #endif | #endif | ||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| if (webViewHandle != nullptr) | |||||
| webViewIdle(webViewHandle); | |||||
| #endif | |||||
| } | } | ||||
| // ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
| @@ -477,7 +506,7 @@ bool Window::PrivateData::removeIdleCallback(IdleCallback* const callback) | |||||
| #ifdef DGL_USE_FILE_BROWSER | #ifdef DGL_USE_FILE_BROWSER | ||||
| // ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
| // file handling | |||||
| // file browser dialog | |||||
| bool Window::PrivateData::openFileBrowser(const FileBrowserOptions& options) | bool Window::PrivateData::openFileBrowser(const FileBrowserOptions& options) | ||||
| { | { | ||||
| @@ -500,6 +529,32 @@ bool Window::PrivateData::openFileBrowser(const FileBrowserOptions& options) | |||||
| } | } | ||||
| #endif // DGL_USE_FILE_BROWSER | #endif // DGL_USE_FILE_BROWSER | ||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| // ----------------------------------------------------------------------- | |||||
| // file browser dialog | |||||
| bool Window::PrivateData::createWebView(const char* const url, const DGL_NAMESPACE::WebViewOptions& options) | |||||
| { | |||||
| if (webViewHandle != nullptr) | |||||
| webViewDestroy(webViewHandle); | |||||
| const PuglRect rect = puglGetFrame(view); | |||||
| uint initialWidth = static_cast<uint>(rect.width) - options.offset.x; | |||||
| uint initialHeight = static_cast<uint>(rect.height) - options.offset.y; | |||||
| webViewOffset = Point<int>(options.offset.x, options.offset.y); | |||||
| webViewHandle = webViewCreate(url, | |||||
| puglGetNativeView(view), | |||||
| initialWidth, | |||||
| initialHeight, | |||||
| autoScaling ? autoScaleFactor : scaleFactor, | |||||
| options); | |||||
| return webViewHandle != nullptr; | |||||
| } | |||||
| #endif // DGL_USE_WEB_VIEW | |||||
| // ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
| // modal handling | // modal handling | ||||
| @@ -599,6 +654,14 @@ void Window::PrivateData::onPuglConfigure(const uint width, const uint height) | |||||
| const uint uwidth = d_roundToUnsignedInt(width / autoScaleFactor); | const uint uwidth = d_roundToUnsignedInt(width / autoScaleFactor); | ||||
| const uint uheight = d_roundToUnsignedInt(height / autoScaleFactor); | const uint uheight = d_roundToUnsignedInt(height / autoScaleFactor); | ||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| if (webViewHandle != nullptr) | |||||
| webViewResize(webViewHandle, | |||||
| uwidth - webViewOffset.getX(), | |||||
| uheight - webViewOffset.getY(), | |||||
| autoScaling ? autoScaleFactor : scaleFactor); | |||||
| #endif | |||||
| self->onReshape(uwidth, uheight); | self->onReshape(uwidth, uheight); | ||||
| #ifndef DPF_TEST_WINDOW_CPP | #ifndef DPF_TEST_WINDOW_CPP | ||||
| @@ -1,6 +1,6 @@ | |||||
| /* | /* | ||||
| * DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
| * Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com> | |||||
| * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com> | |||||
| * | * | ||||
| * Permission to use, copy, modify, and/or distribute this software for any purpose with | * Permission to use, copy, modify, and/or distribute this software for any purpose with | ||||
| * or without fee is hereby granted, provided that the above copyright notice and this | * or without fee is hereby granted, provided that the above copyright notice and this | ||||
| @@ -95,6 +95,12 @@ struct Window::PrivateData : IdleCallback { | |||||
| DGL_NAMESPACE::FileBrowserHandle fileBrowserHandle; | DGL_NAMESPACE::FileBrowserHandle fileBrowserHandle; | ||||
| #endif | #endif | ||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| /** Handle for web view operations. */ | |||||
| DGL_NAMESPACE::WebViewHandle webViewHandle; | |||||
| DGL_NAMESPACE::Point<int> webViewOffset; | |||||
| #endif | |||||
| /** Modal window setup. */ | /** Modal window setup. */ | ||||
| struct Modal { | struct Modal { | ||||
| PrivateData* parent; // parent of this window (so we can become modal) | PrivateData* parent; // parent of this window (so we can become modal) | ||||
| @@ -169,10 +175,15 @@ struct Window::PrivateData : IdleCallback { | |||||
| bool removeIdleCallback(IdleCallback* callback); | bool removeIdleCallback(IdleCallback* callback); | ||||
| #ifdef DGL_USE_FILE_BROWSER | #ifdef DGL_USE_FILE_BROWSER | ||||
| // file handling | |||||
| // file browser dialog | |||||
| bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options); | bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options); | ||||
| #endif | #endif | ||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| // web view | |||||
| bool createWebView(const char* url, const DGL_NAMESPACE::WebViewOptions& options); | |||||
| #endif | |||||
| static void renderToPicture(const char* filename, const GraphicsContext& context, uint width, uint height); | static void renderToPicture(const char* filename, const GraphicsContext& context, uint width, uint height); | ||||
| // modal handling | // modal handling | ||||
| @@ -110,16 +110,25 @@ | |||||
| # endif | # endif | ||||
| #endif | #endif | ||||
| #ifndef DGL_FILE_BROWSER_DISABLED | |||||
| #ifdef DGL_USE_FILE_BROWSER | |||||
| # define DGL_FILE_BROWSER_DIALOG_HPP_INCLUDED | |||||
| # define FILE_BROWSER_DIALOG_DGL_NAMESPACE | # define FILE_BROWSER_DIALOG_DGL_NAMESPACE | ||||
| # define FILE_BROWSER_DIALOG_NAMESPACE DGL_NAMESPACE | # define FILE_BROWSER_DIALOG_NAMESPACE DGL_NAMESPACE | ||||
| # define DGL_FILE_BROWSER_DIALOG_HPP_INCLUDED | |||||
| START_NAMESPACE_DGL | START_NAMESPACE_DGL | ||||
| # include "../../distrho/extra/FileBrowserDialogImpl.hpp" | # include "../../distrho/extra/FileBrowserDialogImpl.hpp" | ||||
| END_NAMESPACE_DGL | END_NAMESPACE_DGL | ||||
| # include "../../distrho/extra/FileBrowserDialogImpl.cpp" | # include "../../distrho/extra/FileBrowserDialogImpl.cpp" | ||||
| #endif | #endif | ||||
| #ifdef DGL_USE_WEB_VIEW | |||||
| # define DGL_WEB_VIEW_HPP_INCLUDED | |||||
| # define WEB_VIEW_DGL_NAMESPACE | |||||
| START_NAMESPACE_DGL | |||||
| # include "../../distrho/extra/WebViewImpl.hpp" | |||||
| END_NAMESPACE_DGL | |||||
| # include "../../distrho/extra/WebViewImpl.cpp" | |||||
| #endif | |||||
| #if defined(DGL_USING_X11) && defined(DGL_X11_WINDOW_ICON_NAME) | #if defined(DGL_USING_X11) && defined(DGL_X11_WINDOW_ICON_NAME) | ||||
| extern const ulong* DGL_X11_WINDOW_ICON_NAME; | extern const ulong* DGL_X11_WINDOW_ICON_NAME; | ||||
| #endif | #endif | ||||