This commit is contained in:
恍兮惚兮 2024-11-21 21:50:52 +08:00
parent dc6c468f01
commit d04690b9b4
28 changed files with 180 additions and 115 deletions

View File

@ -1,7 +1,7 @@
set(VERSION_MAJOR 6)
set(VERSION_MINOR 5)
set(VERSION_PATCH 3)
set(VERSION_PATCH 4)
set(VERSION_REVISION 0)
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
add_library(VERSION_DEF INTERFACE)

View File

@ -1,4 +1,4 @@
// SimpleBrowser.cpp --- simple Win32 browser
// SimpleBrowser.cpp --- simple Win32 browser
// Copyright (C) 2019 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
// This file is public domain software.
@ -106,14 +106,77 @@ BOOL DoSetBrowserEmulation(DWORD dwValue)
return bOK;
}
extern "C" __declspec(dllexport) DWORD html_version()
class MWebBrowserEx : public MWebBrowser
{
HWND hwndParent;
public:
std::vector<std::tuple<std::optional<std::wstring>, int>> menuitems;
static MWebBrowserEx *Create(HWND _hwndParent);
// IDocHostUIHandler interface
STDMETHODIMP ShowContextMenu(
DWORD dwID,
POINT *ppt,
IUnknown *pcmdtReserved,
IDispatch *pdispReserved);
protected:
MWebBrowserEx(HWND _hwndParent);
};
MWebBrowserEx::MWebBrowserEx(HWND _hwndParent) : MWebBrowser(_hwndParent), hwndParent(_hwndParent)
{
}
MWebBrowserEx *MWebBrowserEx::Create(HWND _hwndParent)
{
MWebBrowserEx *pBrowser = new MWebBrowserEx(_hwndParent);
if (!pBrowser->IsCreated())
{
pBrowser->Release();
pBrowser = NULL;
}
return pBrowser;
}
STDMETHODIMP MWebBrowserEx::ShowContextMenu(
DWORD dwID,
POINT *ppt,
IUnknown *pcmdtReserved,
IDispatch *pdispReserved)
{
HMENU hMenu = NULL;
switch (dwID)
{
case CONTEXT_MENU_TEXTSELECT:
{
if (!menuitems.size())
return S_FALSE;
HMENU hMenu = CreatePopupMenu();
int idx = 0;
for (auto &item : menuitems)
{
if (std::get<0>(item))
{
AppendMenu(hMenu, MF_STRING, std::get<1>(item), std::get<0>(item).value().c_str());
}
else
AppendMenu(hMenu, MF_SEPARATOR, 0, nullptr);
idx += 1;
}
TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON, ppt->x, ppt->y, 0, hwndParent, nullptr);
DestroyMenu(hMenu);
return S_OK;
}
default:
return S_FALSE;
}
}
DECLARE_API DWORD html_version()
{
return getemulation();
}
extern "C" __declspec(dllexport) void *html_new(HWND parent)
DECLARE_API void *html_new(HWND parent)
{
DoSetBrowserEmulation(getemulation());
auto s_pWebBrowser = MWebBrowser::Create(parent);
auto s_pWebBrowser = MWebBrowserEx::Create(parent);
if (!s_pWebBrowser)
return NULL;
@ -124,18 +187,18 @@ extern "C" __declspec(dllexport) void *html_new(HWND parent)
return s_pWebBrowser;
}
extern "C" __declspec(dllexport) void html_navigate(void *web, wchar_t *path)
DECLARE_API void html_navigate(void *web, wchar_t *path)
{
if (!web)
return;
auto ww = static_cast<MWebBrowser *>(web);
auto ww = static_cast<MWebBrowserEx *>(web);
ww->Navigate2(path);
}
extern "C" __declspec(dllexport) void html_resize(void *web, int x, int y, int w, int h)
DECLARE_API void html_resize(void *web, int x, int y, int w, int h)
{
if (!web)
return;
auto ww = static_cast<MWebBrowser *>(web);
auto ww = static_cast<MWebBrowserEx *>(web);
RECT r;
r.left = x;
r.top = y;
@ -143,29 +206,78 @@ extern "C" __declspec(dllexport) void html_resize(void *web, int x, int y, int w
r.bottom = y + h;
ww->MoveWindow(r);
}
extern "C" __declspec(dllexport) void html_release(void *web)
DECLARE_API void html_release(void *web)
{
if (!web)
return;
auto ww = static_cast<MWebBrowser *>(web);
auto ww = static_cast<MWebBrowserEx *>(web);
ww->Destroy();
// ww->Release(); Destroy减少引用计数自动del
}
extern "C" __declspec(dllexport) void html_get_current_url(void *web, wchar_t *url)
DECLARE_API const wchar_t *html_get_current_url(void *web)
{
if (!web)
return;
auto ww = static_cast<MWebBrowser *>(web);
return L"";
auto ww = static_cast<MWebBrowserEx *>(web);
wchar_t *_u;
ww->get_LocationURL(&_u);
wcscpy(url, _u);
return _u;
}
extern "C" __declspec(dllexport) void html_set_html(void *web, wchar_t *html)
DECLARE_API void html_set_html(void *web, wchar_t *html)
{
if (!web)
return;
auto ww = static_cast<MWebBrowser *>(web);
auto ww = static_cast<MWebBrowserEx *>(web);
ww->SetHtml(html);
}
DECLARE_API void html_add_menu(void *web, int index, int command, const wchar_t *label)
{
if (!web)
return;
auto ww = static_cast<MWebBrowserEx *>(web);
std::optional<std::wstring> _label;
if (label)
_label = label;
auto ptr = ww->menuitems.begin() + index;
ww->menuitems.insert(ptr, {_label, command});
}
BSTR GetSelectedText(IHTMLDocument2 *pHTMLDoc2)
{
IHTMLSelectionObject *pSelectionObj = nullptr;
HRESULT hr = pHTMLDoc2->get_selection(&pSelectionObj);
if (FAILED(hr) || pSelectionObj == nullptr)
{
return nullptr;
}
IHTMLTxtRange *pTxtRange = nullptr;
hr = pSelectionObj->createRange((IDispatch **)&pTxtRange);
pSelectionObj->Release();
if (FAILED(hr) || pTxtRange == nullptr)
{
return nullptr;
}
BSTR selectedText = nullptr;
hr = pTxtRange->get_text(&selectedText);
pTxtRange->Release();
return selectedText;
}
DECLARE_API const wchar_t *html_get_select_text(void *web)
{
if (!web)
return L"";
auto ww = static_cast<MWebBrowserEx *>(web);
if (IHTMLDocument2 *pDocument = ww->GetIHTMLDocument2())
{
auto text = GetSelectedText(pDocument);
pDocument->Release();
// 不需要freefree会崩溃
return text;
}
return L"";
}

View File

@ -44,10 +44,6 @@ def gettempdir(filename):
return tgt
def testuseqwebengine():
return os.path.exists("./files/runtime/PyQt5/Qt5/bin/Qt5WebEngineCore.dll")
from LunaTranslator import MAINUI
baseobject: MAINUI = None

View File

@ -17,7 +17,6 @@ from gui.usefulwidget import (
D_getcolorbutton,
D_getsimplecombobox,
)
from gui.setting_display_text import on_not_find_qweb
from gui.showword import showdiction
@ -85,17 +84,13 @@ def gethiragrid(self):
def _checkmaybefailed(self, idx):
if idx == 2 and not gobject.testuseqwebengine():
self.seletengeinecombo_1.setCurrentIndex(self.seletengeinecombo_1.lastindex)
on_not_find_qweb(self)
return
self.seletengeinecombo_1.lastindex = self.seletengeinecombo_1.currentIndex()
auto_select_webview.switchtype()
def _createseletengeinecombo_1(self):
webviews = ["MSHTML", "WebView2", "QWebEngine"]
webviews = ["MSHTML", "WebView2"]
if get_platform() == "xp":
webviews = ["MSHTML"]

View File

@ -208,26 +208,6 @@ def installqwebdialog(self, link):
)
def on_not_find_qweb(self):
def _okcallback():
link = [
dynamiclink("{main_server}/Resource/QWebEngine_x86.zip"),
dynamiclink("{main_server}/Resource/QWebEngine_x64.zip"),
][platform.architecture()[0] == "64bit"]
gobject.baseobject.openlink(link)
installqwebdialog(self, link)
getQMessageBox(
self,
"错误",
"未找到QWebEngine点击确定前往下载QWebEngine",
True,
True,
okcallback=_okcallback,
)
def resetgroudswitchcallback(self, group):
if group == "QWebEngine":
group = "webview"

View File

@ -3,7 +3,6 @@ import os, platform, functools, uuid, json, math, csv, io, pickle
from traceback import print_exc
import windows, qtawesome, winsharedutils, gobject
from webviewpy import webview_native_handle_kind_t, Webview
from winsharedutils import HTMLBrowser
from myutils.config import _TR, globalconfig, _TRL
from myutils.wrapper import Singleton_close, tryprint
from myutils.utils import nowisdark, checkportavailable, checkisusingwine
@ -1455,39 +1454,67 @@ class QWebWrap(abstractwebview):
class mshtmlWidget(abstractwebview):
CommandBase = 10086
def __del__(self):
if not self.browser:
return
winsharedutils.html_release(self.browser)
def __init__(self, parent=None) -> None:
super().__init__(parent)
self.callbacks = {}
iswine = checkisusingwine()
if iswine or (HTMLBrowser.version() < 10001): # ie10之前sethtml会乱码
if iswine or (winsharedutils.html_version() < 10001): # ie10之前sethtml会乱码
self.html_limit = 0
self.browser = HTMLBrowser(int(self.winId()))
self.browser = winsharedutils.html_new(int(self.winId()))
self.curr_url = None
t = QTimer(self)
t.setInterval(100)
t.timeout.connect(self.__getcurrenturl)
t.timeout.emit()
t.start()
self.add_menu(0, _TR("复制"), winsharedutils.clipboard_set)
self.add_menu(0, None, lambda: 1)
self.wndproc = windows.WNDPROCTYPE(
functools.partial(
self.extrahandle,
windows.GetWindowLongPtr(int(self.winId()), windows.GWLP_WNDPROC),
)
)
windows.SetWindowLongPtr(int(self.winId()), windows.GWLP_WNDPROC, self.wndproc)
def extrahandle(self, orig, hwnd, msg, wp, lp):
if msg == windows.WM_COMMAND:
func = self.callbacks.get(wp)
if func:
func(winsharedutils.html_get_select_text(self.browser))
return windows.WNDPROCTYPE(orig)(hwnd, msg, wp, lp)
def __getcurrenturl(self):
_u = self.browser.get_current_url()
_u = winsharedutils.html_get_current_url(self.browser)
if self.curr_url != _u:
self.curr_url = _u
self.on_load.emit(_u)
def navigate(self, url):
self.browser.navigate(url)
winsharedutils.html_navigate(self.browser, url)
def resizeEvent(self, a0: QResizeEvent) -> None:
size = a0.size() * self.devicePixelRatioF()
self.browser.resize(0, 0, size.width(), size.height())
winsharedutils.html_resize(self.browser, 0, 0, size.width(), size.height())
def setHtml(self, html):
self.browser.set_html(html)
winsharedutils.html_set_html(self.browser, html)
def parsehtml(self, html):
return self._parsehtml_codec(self._parsehtml_font(self._parsehtml_dark(html)))
def add_menu(self, index, label, callback):
command = mshtmlWidget.CommandBase + len(self.callbacks)
self.callbacks[command] = callback
winsharedutils.html_add_menu(self.browser, index, command, label)
class CustomKeySequenceEdit(QKeySequenceEdit):
changeedvent = pyqtSignal(str)
@ -1604,10 +1631,8 @@ class auto_select_webview(QWidget):
try:
if contex == 0:
browser = mshtmlWidget()
elif contex == 1:
else:
browser = WebivewWidget()
elif contex == 2:
browser = QWebWrap()
except:
print_exc()
browser = mshtmlWidget()

View File

@ -873,6 +873,7 @@ SetWindowLongPtr.restype = c_void_p
GetWindowLongPtr.argtypes = HWND, INT
GetWindowLongPtr.restype = c_void_p
WM_LBUTTONDOWN = 0x0201
WM_COMMAND = 0x0111
WM_LBUTTONUP = 0x0202
WM_MOUSEMOVE = 0x0200

View File

@ -127,44 +127,15 @@ html_resize.argtypes = c_void_p, c_uint, c_uint, c_uint, c_uint
html_release = utilsdll.html_release
html_release.argtypes = (c_void_p,)
html_get_current_url = utilsdll.html_get_current_url
html_get_current_url.argtypes = c_void_p, c_wchar_p
html_get_current_url.argtypes = (c_void_p,)
html_get_current_url.restype = c_wchar_p
html_set_html = utilsdll.html_set_html
html_set_html.argtypes = (
c_void_p,
c_wchar_p,
)
class HTMLBrowser:
@staticmethod
def version():
return html_version()
def __init__(self, parent) -> None:
self.html = html_new(parent)
def set_html(self, html):
html_set_html(self.html, html)
def resize(
self,
x,
y,
w,
h,
):
html_resize(self.html, x, y, w, h)
def navigate(self, url):
html_navigate(self.html, url)
def get_current_url(self):
w = create_unicode_buffer(65536)
html_get_current_url(self.html, w)
return w.value
def __del__(self):
html_release(self.html)
html_set_html.argtypes = (c_void_p, c_wchar_p)
html_add_menu = utilsdll.html_add_menu
html_add_menu.argtypes = (c_void_p, c_int, c_int, c_wchar_p)
html_get_select_text = utilsdll.html_get_select_text
html_get_select_text.argtypes = (c_void_p,)
html_get_select_text.restype = c_wchar_p
_GetLnkTargetPath = utilsdll.GetLnkTargetPath
@ -343,7 +314,12 @@ remove_WebMessageReceived = utilsdll.remove_WebMessageReceived
remove_WebMessageReceived.argtypes = c_void_p, c_void_p
add_ContextMenuRequested_cb = CFUNCTYPE(c_void_p, c_wchar_p)
add_ContextMenuRequested = utilsdll.add_ContextMenuRequested
add_ContextMenuRequested.argtypes = c_void_p, c_int, c_wchar_p, add_ContextMenuRequested_cb
add_ContextMenuRequested.argtypes = (
c_void_p,
c_int,
c_wchar_p,
add_ContextMenuRequested_cb,
)
add_ContextMenuRequested.restype = c_void_p
remove_ContextMenuRequested = utilsdll.remove_ContextMenuRequested
remove_ContextMenuRequested.argtypes = c_void_p, c_void_p

View File

@ -589,7 +589,6 @@
"投影距离": "المسافة المتوقعة",
"反转颜色": "عكس اللون",
"内嵌": "جزءا لا يتجزأ من",
"未找到QWebEngine点击确定前往下载QWebEngine": "لم يتم العثور على qwebengine ، انقر فوق موافق لتحميل qwebengine",
"网络设置": "إعدادات الشبكة",
"版本更新": "تحديث النسخة",
"词性颜色": "لون الكلام",

View File

@ -589,7 +589,6 @@
"投影距离": "投影距離",
"反转颜色": "反轉顏色",
"内嵌": "內嵌",
"未找到QWebEngine点击确定前往下载QWebEngine": "未找到 QWebEngine點擊確定前往下載 QWebEngine",
"网络设置": "網路設定",
"版本更新": "版本更新",
"词性颜色": "詞性顏色",

View File

@ -593,7 +593,6 @@
"投影距离": "Projekční vzdálenost",
"反转颜色": "invertovat barvy",
"内嵌": "Vložené",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine nebyl nalezen, klikněte na OK pro stažení QWebEngine",
"网络设置": "Nastavení sítě",
"版本更新": "Aktualizace verze",
"词性颜色": "Část barvy řeči",

View File

@ -593,7 +593,6 @@
"投影距离": "Projektionsabstand",
"反转颜色": "Farben invertieren",
"内嵌": "Eingebettet",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine nicht gefunden, klicken Sie auf OK, um QWebEngine herunterzuladen",
"网络设置": "Netzwerkeinstellungen",
"版本更新": "Versionsupdate",
"词性颜色": "Teil der Sprachfarbe",

View File

@ -588,7 +588,6 @@
"投影距离": "Projection Distance",
"反转颜色": "Invert Colors",
"内嵌": "Embedded",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine not found, click OK to download QWebEngine",
"网络设置": "Network Settings",
"版本更新": "Version Update",
"词性颜色": "Colored Parts-of-Speech",

View File

@ -589,7 +589,6 @@
"投影距离": "Distancia de proyección",
"反转颜色": "Invertir color",
"内嵌": "Incrustación",
"未找到QWebEngine点击确定前往下载QWebEngine": "No se ha encontrado qwebengine, haga clic en aceptar para descargar qwebengine",
"网络设置": "Configuración de la red",
"版本更新": "Actualización de la versión",
"词性颜色": "Color del habla",

View File

@ -589,7 +589,6 @@
"投影距离": "Distance de projection",
"反转颜色": "Inverser les couleurs",
"内嵌": "Intégré",
"未找到QWebEngine点击确定前往下载QWebEngine": "Qwebengine n'a pas été trouvé, appuyez sur OK pour aller télécharger qwebengine",
"网络设置": "Paramètres réseau",
"版本更新": "Mise à jour de la version",
"词性颜色": "La couleur des mots",

View File

@ -589,7 +589,6 @@
"投影距离": "Distanza di proiezione",
"反转颜色": "inverti colori",
"内嵌": "Incorporato",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine non trovato, fare clic su OK per scaricare QWebEngine",
"网络设置": "Impostazioni di rete",
"版本更新": "Aggiornamento della versione",
"词性颜色": "Colore di parte del discorso",

View File

@ -589,7 +589,6 @@
"投影距离": "とうえいきょり",
"反转颜色": "色を反転",
"内嵌": "インライン",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngineが見つかりませんでした。OKをクリックしてQWebEngineをダウンロードしてください",
"网络设置": "ネットワーク設定",
"版本更新": "バージョンの更新",
"词性颜色": "品詞色",

View File

@ -589,7 +589,6 @@
"投影距离": "투영 거리",
"反转颜色": "색상 반전",
"内嵌": "내장",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine을 찾을 수 없음, 확인을 클릭하여 QWebEngine 다운로드",
"网络设置": "네트워크 설정",
"版本更新": "버전 업데이트",
"词性颜色": "단어 색상",

View File

@ -593,7 +593,6 @@
"投影距离": "Projectieafstand",
"反转颜色": "kleuren omkeren",
"内嵌": "Ingesloten",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine niet gevonden, klik op OK om QWebEngine te downloaden",
"网络设置": "Netwerkinstellingen",
"版本更新": "Versie-update",
"词性颜色": "Deel van spraakkleur",

View File

@ -589,7 +589,6 @@
"投影距离": "Odległość projekcji",
"反转颜色": "odwróć kolory",
"内嵌": "Wbudowane",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine nie znaleziono, kliknij przycisk OK, aby pobrać QWebEngine",
"网络设置": "Ustawienia sieci",
"版本更新": "Aktualizacja wersji",
"词性颜色": "Część koloru mowy",

View File

@ -593,7 +593,6 @@
"投影距离": "Distância de projeção",
"反转颜色": "inverter as cores",
"内嵌": "Incorporado",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine não encontrado, clique em OK para baixar QWebEngine",
"网络设置": "Configuração da rede",
"版本更新": "Actualização da versão",
"词性颜色": "Parte da cor da fala",

View File

@ -589,7 +589,6 @@
"投影距离": "Расстояние проекции",
"反转颜色": "Инвертировать цвет",
"内嵌": "Встраивание",
"未找到QWebEngine点击确定前往下载QWebEngine": "Не найден QWebEngine, нажмите, чтобы определить, чтобы загрузить QWebEngine",
"网络设置": "Настройки сети",
"版本更新": "Обновление версии",
"词性颜色": "Цвет слова",

View File

@ -593,7 +593,6 @@
"投影距离": "Projektionsavstånd",
"反转颜色": "invertera färger",
"内嵌": "Inbäddad",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine hittades inte, klicka på OK för att ladda ner QWebEngine",
"网络设置": "Nätverksinställningar",
"版本更新": "Versionsuppdatering",
"词性颜色": "Färgdel av tal",

View File

@ -589,7 +589,6 @@
"投影距离": "ระยะการฉาย",
"反转颜色": "การย้อนกลับสี",
"内嵌": "อินไลน์",
"未找到QWebEngine点击确定前往下载QWebEngine": "ไม่พบ QWebEngine คลิก OK เพื่อดาวน์โหลด QWebEngine",
"网络设置": "การตั้งค่าเครือข่าย",
"版本更新": "อัปเดตเวอร์ชัน",
"词性颜色": "สีของคำ",

View File

@ -589,7 +589,6 @@
"投影距离": "Projeksyon mesafesi",
"反转颜色": "Ters renkler",
"内嵌": "İçeri",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine",
"网络设置": "Ağ Ayarları",
"版本更新": "Sürüm güncelleştirme",
"词性颜色": "Konuşma renginin bir parçası",

View File

@ -589,7 +589,6 @@
"投影距离": "Відстань проекту",
"反转颜色": "звернути кольори",
"内嵌": "Вбудовано",
"未找到QWebEngine点击确定前往下载QWebEngine": "QWebEngine не знайдено, натисніть кнопку Гаразд, щоб звантажити QWebEngine",
"网络设置": "Параметри мережі",
"版本更新": "Оновлення версії",
"词性颜色": "Частина кольору мови",

View File

@ -589,7 +589,6 @@
"投影距离": "Khoảng cách chiếu",
"反转颜色": "Đảo ngược màu",
"内嵌": "Nội tuyến",
"未找到QWebEngine点击确定前往下载QWebEngine": "Không tìm thấy QWebEngine, nhấn OK để tải xuống QWebEngine",
"网络设置": "Thiết lập mạng",
"版本更新": "Cập nhật phiên bản",
"词性颜色": "Màu sắc của từ",

View File

@ -603,7 +603,6 @@
"投影距离": "",
"反转颜色": "",
"内嵌": "",
"未找到QWebEngine点击确定前往下载QWebEngine": "",
"网络设置": "",
"版本更新": "",
"词性颜色": "",