Skip to content

Commit

Permalink
Enable choc for win32 webview
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Mar 21, 2024
1 parent aae3a52 commit 24b717a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "src/DPF"]
path = src/DPF
url = https://github.com/DISTRHO/DPF.git
[submodule "src/CHOC"]
path = src/CHOC
url = https://github.com/Tracktion/choc.git
1 change: 1 addition & 0 deletions src/CHOC
Submodule CHOC added at 337d39
10 changes: 5 additions & 5 deletions src/plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ endif

TARGETS = features au clap lv2_sep vst2 vst3

# ifeq ($(WINDOWS),true)
# BUILD_CXX_FLAGS += -DUSING_CHOC
# LINK_FLAGS += -lole32
# $(BUILD_DIR)/WebViewWin32.cpp.o: BUILD_CXX_FLAGS += -std=gnu++17
# endif
ifeq ($(WINDOWS),true)
BUILD_CXX_FLAGS += -I../CHOC
LINK_FLAGS += -lole32
$(BUILD_DIR)/WebViewWin32.cpp.o: BUILD_CXX_FLAGS += -std=gnu++17
endif

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

Expand Down
19 changes: 4 additions & 15 deletions src/plugin/WebViewWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
#include "WebView.hpp"
#include "DistrhoPluginInfo.h"

#ifdef USING_CHOC
#include "choc/gui/choc_WebView.h"
#endif
#define WC_ERR_INVALID_CHARS 0
#include "gui/choc_WebView.h"

START_NAMESPACE_DISTRHO

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

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

Expand All @@ -25,8 +23,8 @@ void* addWebView(const uintptr_t parentWinId, const double scaleFactor, const ui
std::snprintf(url, 31, "http://127.0.0.1:%u/", port);
webview->navigate(url);

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

SetParent(handle, reinterpret_cast<HWND>(parentWinId));
Expand All @@ -38,37 +36,28 @@ void* addWebView(const uintptr_t parentWinId, const double scaleFactor, const ui
ShowWindow(handle, SW_SHOW);

return webview.release();
#else
return nullptr;
#endif
}

void destroyWebView(void* const webviewptr)
{
#ifdef USING_CHOC
delete static_cast<choc::ui::WebView*>(webviewptr);
#endif
}

void reloadWebView(void* const webviewptr, const uint port)
{
#ifdef USING_CHOC
choc::ui::WebView* const webview = static_cast<choc::ui::WebView*>(webviewptr);

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

void resizeWebView(void* const webviewptr, const uint offset, const uint width, const uint height)
{
#ifdef USING_CHOC
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);
#endif
}

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

0 comments on commit 24b717a

Please sign in to comment.