Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

show or hide title bar. hide title bar,bind StartDragging function to Drag window. #57

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# IDEA
.idea
171 changes: 171 additions & 0 deletions libs/webview/include/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,35 @@ WEBVIEW_API void *webview_get_native_handle(webview_t w,
*/
WEBVIEW_API void webview_set_title(webview_t w, const char *title);

/**
* Updates the title bar of the native window.
*
* @param w The webview instance.
* @param title The title bar Show or hide.
*/
WEBVIEW_API void webview_set_title_bar(webview_t w, int b);

/**
* Set the native window maximize.
*
* @param w The webview instance.
*/
WEBVIEW_API void webview_set_maximize(webview_t w);

/**
* Set the native window un maximize.
*
* @param w The webview instance.
*/
WEBVIEW_API void webview_set_un_maximize(webview_t w);

/**
* Set the native window minimize.
*
* @param w The webview instance.
*/
WEBVIEW_API void webview_set_minimize(webview_t w);

/**
* Updates the size of the native window.
*
Expand All @@ -265,6 +294,28 @@ WEBVIEW_API void webview_set_title(webview_t w, const char *title);
WEBVIEW_API void webview_set_size(webview_t w, int width, int height,
webview_hint_t hints);

/**
* Updates the drag of the native window.
*
* @param w The webview instance.
*/
WEBVIEW_API void webview_start_dragging(webview_t w);

/**
* Set Always On Top of the native window.
*
* @param w The webview instance.
* @param b bool.
*/
WEBVIEW_API void webview_set_always_on_top(webview_t w,int b);
/**
* Set Always On Top of the native window.
*
* @param w The webview instance.
* @param b bool.
*/
WEBVIEW_API void webview_set_resizable(webview_t w,int b);

/**
* Navigates webview to the given URL. URL may be a properly encoded data URI.
*
Expand Down Expand Up @@ -1001,11 +1052,27 @@ if (status === 0) {\
void terminate() { terminate_impl(); }
void dispatch(std::function<void()> f) { dispatch_impl(f); }
void set_title(const std::string &title) { set_title_impl(title); }
void set_title_bar(int b) { set_title_bar_impl(b); }
void set_maximize() { set_maximize_impl(); }
void set_un_maximize() { set_un_maximize_impl(); }
void set_minimize() { set_minimize_impl(); }

void set_size(int width, int height, webview_hint_t hints) {
set_size_impl(width, height, hints);
}

void start_dragging() {
start_dragging_impl();
}

void set_always_on_top(int b) {
set_always_on_top_impl(b);
}

void set_resizable(int b) {
set_resizable_impl(b);
}

void set_html(const std::string &html) { set_html_impl(html); }
void init(const std::string &js) { init_impl(js); }
void eval(const std::string &js) { eval_impl(js); }
Expand All @@ -1019,7 +1086,14 @@ if (status === 0) {\
virtual void terminate_impl() = 0;
virtual void dispatch_impl(std::function<void()> f) = 0;
virtual void set_title_impl(const std::string &title) = 0;
virtual void set_title_bar_impl(int b) = 0;
virtual void set_maximize_impl() = 0;
virtual void set_un_maximize_impl() = 0;
virtual void set_minimize_impl() = 0;
virtual void set_size_impl(int width, int height, webview_hint_t hints) = 0;
virtual void start_dragging_impl() = 0;
virtual void set_always_on_top_impl(int b) = 0;
virtual void set_resizable_impl(int b) = 0;
virtual void set_html_impl(const std::string &html) = 0;
virtual void init_impl(const std::string &js) = 0;
virtual void eval_impl(const std::string &js) = 0;
Expand Down Expand Up @@ -1335,6 +1409,14 @@ class gtk_webkit_engine : public engine_base {
gtk_window_set_title(GTK_WINDOW(m_window), title.c_str());
}

void set_title_bar_impl(int b) override {}

void set_maximize_impl() override {}

void set_un_maximize_impl() override {}

void set_minimize_impl() override {}

void set_size_impl(int width, int height, webview_hint_t hints) override {
gtk_window_set_resizable(GTK_WINDOW(m_window), hints != WEBVIEW_HINT_FIXED);
if (hints == WEBVIEW_HINT_NONE) {
Expand All @@ -1351,6 +1433,10 @@ class gtk_webkit_engine : public engine_base {
gtk_window_set_geometry_hints(GTK_WINDOW(m_window), nullptr, &g, h);
}
}
void start_dragging_impl() override {}

void set_always_on_top_impl(int b) override {}
void set_resizable_impl(int b) override {}

void navigate_impl(const std::string &url) override {
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(m_webview), url.c_str());
Expand Down Expand Up @@ -1655,6 +1741,15 @@ class cocoa_wkwebview_engine : public engine_base {
"stringWithUTF8String:"_sel,
title.c_str()));
}

void set_title_bar_impl(int b) override {}

void set_maximize_impl() override {}

void set_un_maximize_impl() override {}

void set_minimize_impl() override {}

void set_size_impl(int width, int height, webview_hint_t hints) override {
objc::autoreleasepool arp;

Expand All @@ -1679,6 +1774,9 @@ class cocoa_wkwebview_engine : public engine_base {
}
objc::msg_send<void>(m_window, "center"_sel);
}
void start_dragging_impl() override {}
void set_always_on_top_impl(int b) override {}
void set_resizable_impl(int b) override {}
void navigate_impl(const std::string &url) override {
objc::autoreleasepool arp;

Expand Down Expand Up @@ -3263,13 +3361,39 @@ class win32_edge_engine : public engine_base {
SetWindowTextW(m_window, widen_string(title).c_str());
}


void set_title_bar_impl(int b) override {
auto style = GetWindowLong(m_window, GWL_STYLE);
if (b == 0){
style &= ~WS_CAPTION;
}else{
style |= WS_CAPTION;
}
SetWindowLong(m_window, GWL_STYLE, style);
SetWindowPos(m_window, nullptr, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}

void set_maximize_impl() override {
PostMessage(m_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}

void set_un_maximize_impl() override {
PostMessage(m_window, WM_SYSCOMMAND, SC_RESTORE, 0);
}

void set_minimize_impl() override {
PostMessage(m_window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
}

void set_size_impl(int width, int height, webview_hint_t hints) override {
auto style = GetWindowLong(m_window, GWL_STYLE);
if (hints == WEBVIEW_HINT_FIXED) {
style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
} else {
style |= (WS_THICKFRAME | WS_MAXIMIZEBOX);
}

SetWindowLong(m_window, GWL_STYLE, style);

if (hints == WEBVIEW_HINT_MAX) {
Expand All @@ -3291,6 +3415,25 @@ class win32_edge_engine : public engine_base {
}
}

void start_dragging_impl() override {
ReleaseCapture();
SendMessage(m_window, WM_SYSCOMMAND, SC_MOVE| HTCAPTION, 0);
}

void set_always_on_top_impl(int b) override {
SetWindowPos(m_window, b == 0 ? HWND_NOTOPMOST : HWND_TOPMOST,0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}

void set_resizable_impl(int b) override {
auto style = GetWindowLong(m_window, GWL_STYLE);
if (b == 0) {
style &= ~WS_THICKFRAME;
} else {
style |= WS_THICKFRAME;
}
::SetWindowLong(m_window, GWL_STYLE, style);
}

void navigate_impl(const std::string &url) override {
auto wurl = widen_string(url);
m_webview->Navigate(wurl.c_str());
Expand Down Expand Up @@ -3547,11 +3690,39 @@ WEBVIEW_API void webview_set_title(webview_t w, const char *title) {
static_cast<webview::webview *>(w)->set_title(title);
}


WEBVIEW_API void webview_set_title_bar(webview_t w, int b) {
static_cast<webview::webview *>(w)->set_title_bar(b);
}

WEBVIEW_API void webview_set_maximize(webview_t w) {
static_cast<webview::webview *>(w)->set_maximize();
}

WEBVIEW_API void webview_set_un_maximize(webview_t w) {
static_cast<webview::webview *>(w)->set_un_maximize();
}

WEBVIEW_API void webview_set_minimize(webview_t w) {
static_cast<webview::webview *>(w)->set_minimize();
}

WEBVIEW_API void webview_set_size(webview_t w, int width, int height,
webview_hint_t hints) {
static_cast<webview::webview *>(w)->set_size(width, height, hints);
}

WEBVIEW_API void webview_start_dragging(webview_t w) {
static_cast<webview::webview *>(w)->start_dragging();
}

WEBVIEW_API void webview_set_always_on_top(webview_t w, int b) {
static_cast<webview::webview *>(w)->set_always_on_top(b);
}
WEBVIEW_API void webview_set_resizable(webview_t w, int b) {
static_cast<webview::webview *>(w)->set_resizable(b);
}

WEBVIEW_API void webview_navigate(webview_t w, const char *url) {
static_cast<webview::webview *>(w)->navigate(url);
}
Expand Down
53 changes: 51 additions & 2 deletions webview.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ void CgoWebViewUnbind(webview_t w, const char *name);
*/
import "C"
import (
"encoding/json"
"errors"
_ "github.com/webview/webview_go/libs/mswebview2"
_ "github.com/webview/webview_go/libs/mswebview2/include"
_ "github.com/webview/webview_go/libs/webview"
_ "github.com/webview/webview_go/libs/webview/include"
"encoding/json"
"errors"
"reflect"
"runtime"
"sync"
Expand Down Expand Up @@ -86,9 +86,30 @@ type WebView interface {
// thread.
SetTitle(title string)

// SetTitleBar show or hide title bar
SetTitleBar(b bool)

// SetMaximize set native window maximize
SetMaximize()

// SetUnMaximize set native window unmaximize
SetUnMaximize()

// SetMinimize set native window minimize
SetMinimize()

// SetSize updates native window size. See Hint constants.
SetSize(w int, h int, hint Hint)

// StartDragging Drag native window.
StartDragging()

// SetAlwaysOnTop set always on top native window.
SetAlwaysOnTop(b bool)

// SetResizable set resizable native window.
SetResizable(b bool)

// Navigate navigates webview to the given URL. URL may be a properly encoded data.
// URI. Examples:
// w.Navigate("https://github.com/webview/webview")
Expand Down Expand Up @@ -192,10 +213,38 @@ func (w *webview) SetTitle(title string) {
C.webview_set_title(w.w, s)
}

func (w *webview) SetTitleBar(b bool) {
C.webview_set_title_bar(w.w, boolToInt(b))
}

func (w *webview) SetMaximize() {
C.webview_set_maximize(w.w)
}

func (w *webview) SetUnMaximize() {
C.webview_set_un_maximize(w.w)
}

func (w *webview) SetMinimize() {
C.webview_set_minimize(w.w)
}

func (w *webview) SetSize(width int, height int, hint Hint) {
C.webview_set_size(w.w, C.int(width), C.int(height), C.webview_hint_t(hint))
}

func (w *webview) StartDragging() {
C.webview_start_dragging(w.w)
}

func (w *webview) SetAlwaysOnTop(b bool) {
C.webview_set_always_on_top(w.w, boolToInt(b))
}

func (w *webview) SetResizable(b bool) {
C.webview_set_resizable(w.w, boolToInt(b))
}

func (w *webview) Init(js string) {
s := C.CString(js)
defer C.free(unsafe.Pointer(s))
Expand Down