feat: Synchronize floating toolbar status via IPC
This commit is contained in:
1 parent
f61b965670
commit
97af71e9cf
5 files changed
+45
-18
No files matched your search
@@ -14,4 +14,5 @@ inline const UINT WM_LANGBAR_RIGHTCLICK = WM_USER + 102;
|
||||
inline const UINT WM_IMEACTIVATE = WM_USER + 103;
|
||||
inline const UINT WM_IMEDEACTIVATE = WM_USER + 104;
|
||||
inline const UINT WM_IMESWITCH = WM_USER + 105;
|
||||
inline const UINT WM_PUNCSWITCH = WM_USER + 106;
|
||||
inline const UINT WM_PUNCSWITCH = WM_USER + 106;
|
||||
inline const UINT UPDATE_FTB_STATUS = WM_USER + 107;
|
||||
@@ -469,6 +469,26 @@ void AuxPipeEventListenerLoopThread()
|
||||
{
|
||||
PostMessage(::global_hwnd, WM_IMEDEACTIVATE, 0, 0);
|
||||
}
|
||||
else if (boost::starts_with(message, L"ftbStatus"))
|
||||
{
|
||||
std::wstring ftbStatus = message.substr(9);
|
||||
if (ftbStatus == L"11") // 中中
|
||||
{
|
||||
PostMessage(::global_hwnd_ftb, UPDATE_FTB_STATUS, 3, 0);
|
||||
}
|
||||
else if (ftbStatus == L"00") // 英英
|
||||
{
|
||||
PostMessage(::global_hwnd_ftb, UPDATE_FTB_STATUS, 0, 0);
|
||||
}
|
||||
else if (ftbStatus == L"10") // 中英
|
||||
{
|
||||
PostMessage(::global_hwnd_ftb, UPDATE_FTB_STATUS, 2, 0);
|
||||
}
|
||||
else if (ftbStatus == L"01") // 英中
|
||||
{
|
||||
PostMessage(::global_hwnd_ftb, UPDATE_FTB_STATUS, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -988,38 +988,37 @@ void UpdateFtbCnEnState(ComPtr<ICoreWebView2> webview, int cnEnState)
|
||||
*
|
||||
* @param webview
|
||||
* @param cnEnState 1: 中文, 0: 英文
|
||||
* @param puncState 1: 中文标点, 0: 英文标点
|
||||
*/
|
||||
void UpdateFtbCnEnAndPuncState(ComPtr<ICoreWebView2> webview, int cnEnState)
|
||||
void UpdateFtbCnEnAndPuncState(ComPtr<ICoreWebView2> webview, int cnEnState, int puncState)
|
||||
{
|
||||
if (webview == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::wstring script;
|
||||
script.reserve(256);
|
||||
if (cnEnState == 1)
|
||||
{
|
||||
std::wstring script;
|
||||
script.reserve(256);
|
||||
|
||||
script.append(L"document.getElementById('cn').style.display = 'flex';");
|
||||
script.append(L"document.getElementById('en').style.display = 'none';");
|
||||
script.append(L"document.getElementById('puncCn').style.display = 'flex';");
|
||||
script.append(L"document.getElementById('puncEn').style.display = 'none';");
|
||||
|
||||
webview->ExecuteScript(script.c_str(), nullptr);
|
||||
}
|
||||
else if (cnEnState == 0)
|
||||
{
|
||||
std::wstring script;
|
||||
script.reserve(256);
|
||||
|
||||
script.append(L"document.getElementById('cn').style.display = 'none';");
|
||||
script.append(L"document.getElementById('en').style.display = 'flex';");
|
||||
}
|
||||
if (puncState == 1)
|
||||
{
|
||||
script.append(L"document.getElementById('puncCn').style.display = 'flex';");
|
||||
script.append(L"document.getElementById('puncEn').style.display = 'none';");
|
||||
}
|
||||
else if (puncState == 0)
|
||||
{
|
||||
script.append(L"document.getElementById('puncCn').style.display = 'none';");
|
||||
script.append(L"document.getElementById('puncEn').style.display = 'flex';");
|
||||
|
||||
webview->ExecuteScript(script.c_str(), nullptr);
|
||||
}
|
||||
webview->ExecuteScript(script.c_str(), nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -83,5 +83,5 @@ inline std::wstring HTMLStringFtbWnd = LR"()";
|
||||
|
||||
void InitWebviewFtbWnd(HWND hwnd);
|
||||
void UpdateFtbCnEnState(ComPtr<ICoreWebView2> webview, int cnEnState);
|
||||
void UpdateFtbCnEnAndPuncState(ComPtr<ICoreWebView2> webview, int cnEnState);
|
||||
void UpdateFtbCnEnAndPuncState(ComPtr<ICoreWebView2> webview, int cnEnState, int puncState);
|
||||
void UpdateFtbPuncState(ComPtr<ICoreWebView2> webview, int puncState);
|
||||
@@ -394,12 +394,12 @@ LRESULT CALLBACK WndProcCandWindow(HWND hwnd, UINT message, WPARAM wParam, LPARA
|
||||
if (wParam == 0) // 此时是英文状态
|
||||
{
|
||||
/* 更新 floating toolbar 的中英文状态为英文,同时更新标点的全角和半角状态 */
|
||||
UpdateFtbCnEnAndPuncState(::webviewFtbWnd, 0);
|
||||
UpdateFtbCnEnAndPuncState(::webviewFtbWnd, 0, 0);
|
||||
}
|
||||
else // 此时是中文状态
|
||||
{
|
||||
/* 更新 floating toolbar 的中英文状态为中文,同时更新标点的全角和半角状态 */
|
||||
UpdateFtbCnEnAndPuncState(::webviewFtbWnd, 1);
|
||||
UpdateFtbCnEnAndPuncState(::webviewFtbWnd, 1, 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -626,6 +626,13 @@ LRESULT CALLBACK WndProcFtbWindow(HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
||||
static int s_check_cnt = 0;
|
||||
switch (message)
|
||||
{
|
||||
case UPDATE_FTB_STATUS: {
|
||||
int cnEnState = (wParam >> 1) & 0x1;
|
||||
int puncState = wParam & 0x1;
|
||||
UpdateFtbCnEnAndPuncState(::webviewFtbWnd, cnEnState, puncState);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_TIMER: {
|
||||
if (wParam == TIMER_ID_MOVE_WEBVIEW_FTB)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user