Skip to content

Commit

Permalink
support dialogs in macos webview
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed May 4, 2024
1 parent 93dffb5 commit 62a37f3
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 107 deletions.
2 changes: 1 addition & 1 deletion src/DPF
Submodule DPF updated 1 files
+2 −0 Makefile.base.mk
2 changes: 1 addition & 1 deletion src/PawPaw
Submodule PawPaw updated 1 files
+4 −1 setup/env.sh
28 changes: 15 additions & 13 deletions src/plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ FILES_DSP = \
FILES_UI = DesktopUI.cpp NanoButton.cpp utils.cpp

ifeq ($(MACOS),true)
FILES_UI += WebView.mm
FILES_UI += WebViewWK.mm
else ifeq ($(WINDOWS),true)
FILES_UI += WebViewWin32.cpp
FILES_UI += WebViewCHOC.cpp
else
FILES_UI += WebViewX11.cpp
endif
Expand All @@ -40,29 +40,31 @@ USING_WEBVIEW = true

include ../DPF/Makefile.plugins.mk

BUILD_CXX_FLAGS += -DVERSION='"$(shell cat ../../VERSION)"'
TARGETS = features au clap lv2_sep vst2 vst3

BUILD_CXX_FLAGS += -DVERSION='"$(shell cat ../../VERSION)"'
BUILD_CXX_FLAGS += -pthread
LINK_FLAGS += -pthread

ifeq ($(MACOS),true)
LINK_FLAGS += -framework CoreFoundation -framework IOKit -framework WebKit
else ifeq ($(WINDOWS),true)
LINK_FLAGS += -lwinmm
else ifeq ($(LINUX),true)
BUILD_CXX_FLAGS += -I../CHOC
else
BUILD_CXX_FLAGS += $(shell $(PKG_CONFIG) --cflags Qt5Core)
# -std=gnu++14
LINK_FLAGS += -ldl -lrt
endif

TARGETS = features au clap lv2_sep vst2 vst3
LINK_FLAGS += -pthread

ifeq ($(WINDOWS),true)
BUILD_CXX_FLAGS += -I../CHOC
LINK_FLAGS += -lole32
$(BUILD_DIR)/WebViewWin32.cpp.o: BUILD_CXX_FLAGS += -std=gnu++17
ifeq ($(MACOS),true)
LINK_FLAGS += -framework CoreFoundation -framework IOKit -framework WebKit
else ifeq ($(WINDOWS),true)
LINK_FLAGS += -lole32 -lwinmm
else
LINK_FLAGS += -ldl -lrt
endif

$(BUILD_DIR)/WebViewCHOC.cpp.o: BUILD_CXX_FLAGS += -std=gnu++17

# ---------------------------------------------------------------------------------------------------------------------

all: $(TARGETS)
78 changes: 0 additions & 78 deletions src/plugin/WebView.mm

This file was deleted.

42 changes: 32 additions & 10 deletions src/plugin/WebViewWin32.cpp → src/plugin/WebViewCHOC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,50 @@
#define WC_ERR_INVALID_CHARS 0
#include "gui/choc_WebView.h"

#ifdef __APPLE__
# import <Cocoa/Cocoa.h>
#endif

START_NAMESPACE_DISTRHO

// -----------------------------------------------------------------------------------------------------------

void* addWebView(const uintptr_t parentWinId, const double scaleFactor, const uint port)
{
std::unique_ptr<choc::ui::WebView> webview = std::make_unique<choc::ui::WebView>(choc::ui::WebView());
std::unique_ptr<choc::ui::WebView> webview = std::make_unique<choc::ui::WebView>();
DISTRHO_SAFE_ASSERT_RETURN(webview->loadedOK(), nullptr);

const HWND handle = static_cast<HWND>(webview->getViewHandle());
void* const handle = webview->getViewHandle();
DISTRHO_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);

char url[32] = {};
std::snprintf(url, 31, "http://127.0.0.1:%u/", port);
webview->navigate(url);

LONG_PTR flags = GetWindowLongPtr(handle, -16);
#if defined(__APPLE__)
NSView* const view = static_cast<NSView*>(handle);

[reinterpret_cast<NSView*>(parentWinId) addSubview:view];
[view setFrame:NSMakeRect(0,
kVerticalOffset,
DISTRHO_UI_DEFAULT_WIDTH,
DISTRHO_UI_DEFAULT_HEIGHT - kVerticalOffset)];
#elif defined(_WIN32)
const HWND hwnd = static_cast<HWND>(handle);

LONG_PTR flags = GetWindowLongPtr(hwnd, -16);
flags = (flags & ~WS_POPUP) | WS_CHILD;
SetWindowLongPtr(handle, -16, flags);
SetWindowLongPtr(hwnd, -16, flags);

SetParent(handle, reinterpret_cast<HWND>(parentWinId));
SetWindowPos(handle, nullptr,
0, kVerticalOffset * scaleFactor,
SetParent(hwnd, reinterpret_cast<HWND>(parentWinId));
SetWindowPos(hwnd, nullptr,
0,
kVerticalOffset * scaleFactor,
DISTRHO_UI_DEFAULT_WIDTH * scaleFactor,
(DISTRHO_UI_DEFAULT_HEIGHT - kVerticalOffset) * scaleFactor,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
ShowWindow(handle, SW_SHOW);
ShowWindow(hwnd, SW_SHOW);
#endif

return webview.release();
}
Expand All @@ -56,8 +73,13 @@ void resizeWebView(void* const webviewptr, const uint offset, const uint width,
{
choc::ui::WebView* const webview = static_cast<choc::ui::WebView*>(webviewptr);

const HWND handle = static_cast<HWND>(webview->getViewHandle());
SetWindowPos(handle, nullptr, 0, offset, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
#if defined(__APPLE__)
NSView* const view = static_cast<NSView*>(webview->getViewHandle());
[view setFrame:NSMakeRect(0, offset, width, height)];
#elif defined(_WIN32)
const HWND hwnd = static_cast<HWND>(webview->getViewHandle());
SetWindowPos(hwnd, nullptr, 0, offset, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
#endif
}

// -----------------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 62a37f3

Please sign in to comment.