From 131153743504a3c290d5cf724d9c5123017dc0a5 Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Wed, 31 Jan 2024 12:21:09 +0900 Subject: [PATCH] [MSUTB][SDK] Implement DoCloseLangbar (#6423) Supporting Language Bar... JIRA issue: CORE-19363 - Implement GetGlobalCompartment function. - Implement GetGlobalCompartmentDWORD and SetGlobalCompartmentDWORD helper functions. - Implement TurnOffSpeechIfItsOn and DoCloseLangbar functions. --- dll/win32/msutb/msutb.cpp | 85 +++++++++++++++++++++++++++-- dll/win32/msutb/precomp.h | 1 + sdk/include/reactos/cicero/cicutb.h | 2 + 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/dll/win32/msutb/msutb.cpp b/dll/win32/msutb/msutb.cpp index d6344a59a0c..9a4a96e8553 100644 --- a/dll/win32/msutb/msutb.cpp +++ b/dll/win32/msutb/msutb.cpp @@ -35,6 +35,85 @@ class CCicLibMenuItem; class CTipbarAccItem; class CUTBMenuItem; +HRESULT GetGlobalCompartment(REFGUID rguid, ITfCompartment **ppComp) +{ + ITfCompartmentMgr *pCompMgr = NULL; + HRESULT hr = TF_GetGlobalCompartment(&pCompMgr); + if (FAILED(hr)) + return hr; + + if (!pCompMgr) + return E_FAIL; + + hr = pCompMgr->GetCompartment(rguid, ppComp); + pCompMgr->Release(); + return hr; +} + +HRESULT GetGlobalCompartmentDWORD(REFGUID rguid, LPDWORD pdwValue) +{ + *pdwValue = 0; + ITfCompartment *pComp; + HRESULT hr = GetGlobalCompartment(rguid, &pComp); + if (SUCCEEDED(hr)) + { + VARIANT vari; + hr = pComp->GetValue(&vari); + if (hr == S_OK) + *pdwValue = V_I4(&vari); + pComp->Release(); + } + return hr; +} + +HRESULT SetGlobalCompartmentDWORD(REFGUID rguid, DWORD dwValue) +{ + VARIANT vari; + ITfCompartment *pComp; + HRESULT hr = GetGlobalCompartment(rguid, &pComp); + if (SUCCEEDED(hr)) + { + V_VT(&vari) = VT_I4; + V_I4(&vari) = dwValue; + hr = pComp->SetValue(0, &vari); + pComp->Release(); + } + return hr; +} + +void TurnOffSpeechIfItsOn(void) +{ + DWORD dwValue = 0; + HRESULT hr = GetGlobalCompartmentDWORD(GUID_COMPARTMENT_SPEECH_OPENCLOSE, &dwValue); + if (SUCCEEDED(hr) && dwValue) + SetGlobalCompartmentDWORD(GUID_COMPARTMENT_SPEECH_OPENCLOSE, 0); +} + +void DoCloseLangbar(void) +{ + ITfLangBarMgr *pLangBarMgr = NULL; + HRESULT hr = TF_CreateLangBarMgr(&pLangBarMgr); + if (FAILED(hr)) + return; + + if (pLangBarMgr) + { + hr = pLangBarMgr->ShowFloating(8); + pLangBarMgr->Release(); + pLangBarMgr = NULL; + } + + if (SUCCEEDED(hr)) + TurnOffSpeechIfItsOn(); + + CicRegKey regKey; + LSTATUS error = regKey.Open(HKEY_CURRENT_USER, + TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), + KEY_ALL_ACCESS); + if (error == ERROR_SUCCESS) + ::RegDeleteValue(regKey, TEXT("ctfmon.exe")); +} + /***********************************************************************/ class CUTBLangBarDlg @@ -511,12 +590,6 @@ STDMETHODIMP_(BOOL) CUTBCloseLangBarDlg::DoModal(HWND hDlg) return TRUE; } -/// @unimplemented -void DoCloseLangbar(void) -{ - //FIXME -} - STDMETHODIMP_(BOOL) CUTBCloseLangBarDlg::OnCommand(HWND hDlg, WPARAM wParam, LPARAM lParam) { switch (LOWORD(wParam)) diff --git a/dll/win32/msutb/precomp.h b/dll/win32/msutb/precomp.h index 8bc4c4140a9..d198ded03f1 100644 --- a/dll/win32/msutb/precomp.h +++ b/dll/win32/msutb/precomp.h @@ -28,6 +28,7 @@ #include "resource.h" #include +#include #include #include diff --git a/sdk/include/reactos/cicero/cicutb.h b/sdk/include/reactos/cicero/cicutb.h index 1865cbdaf7c..9c0ff831530 100644 --- a/sdk/include/reactos/cicero/cicutb.h +++ b/sdk/include/reactos/cicero/cicutb.h @@ -7,6 +7,8 @@ #pragma once +DEFINE_GUID(GUID_COMPARTMENT_SPEECH_OPENCLOSE, 0x544D6A63, 0xE2E8, 0x4752, 0xBB, 0xD1, 0x00, 0x09, 0x60, 0xBC, 0xA0, 0x83); + EXTERN_C LPVOID WINAPI GetLibTls(VOID); EXTERN_C BOOL WINAPI GetPopupTipbar(HWND hWnd, BOOL fWinLogon); EXTERN_C HRESULT WINAPI SetRegisterLangBand(BOOL bRegister);