Skip to content

Commit

Permalink
Merge pull request rime#956 from fxliang/padding
Browse files Browse the repository at this point in the history
1. 修复:原来的偶发的只有背景没有文字显示的问题
2. 修复:原来部署过程中按键后重复发出部署中的tip提示窗的问题
3. 修复:一些ui内存泄漏的问题
4. 修复:几个像素级的布局小问题
5. 特性:增加hilite_padding_x, hilite_padding_y可以独立定义xy向的padding,原来的hilite_padding在前面两个没有定义的时候可以同时设定xy向的padding
6. 特性:新增schema/full_icon和schema/half_icon可用于方案中定义全角半角图标
7. 特性:切换方案后,显示方案图标和方案名称提示于tip上
8. wtl全部改成wtl10,gdi+指定1.1版,性能稍提升,代码冗余减少
9. 全部exe/dll/ime改成每显示器dpi aware
10. 删除早前误冗余的mutex限单服务进程的代码
11. 更新使用rime/artworks/weasel-icons/weasel-black.png制作的图标
12. 更新RimeWithWeasel.cpp,通过模板和函数精简代码减少代码行数,修正一些回退机制,限制部分不能为负数的数值的解析;可设定style/label_font_face: "" style/comment_font_face: "" 来强制回退到font_face设定。
13. 更新WeaselPanel.cpp,通过schema_id判断是否当前为选单界面
14. direct2d资源改用wrl的ComPtr智能指针
15. 补充Deployer的VersionInfo,减少杀软误报(本机编译已验证)
16. 增加对imtip支持相关代码,目前已经可以和imtip 兼容 rime#958
17. 重写字重和字形解析代码,增强可读性,且目前已可以在font_face字串内任一节点定义字重字形(原来只能在第一个节点内定义)
  • Loading branch information
determ1ne authored Jul 20, 2023
2 parents b9a52e4 + db04264 commit 9972aeb
Show file tree
Hide file tree
Showing 81 changed files with 7,658 additions and 66,331 deletions.
731 changes: 284 additions & 447 deletions RimeWithWeasel/RimeWithWeasel.cpp

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion WeaselDeployer/Configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ class Configurator
int SyncUserData();
};

const WCHAR* utf8towcs(const char* utf8_str);
11 changes: 7 additions & 4 deletions WeaselDeployer/DictManagementDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ void DictManagementDialog::Populate() {
RimeUserDictIterator iter = {0};
api_->user_dict_iterator_init(&iter);
while (const char* dict = api_->next_user_dict(&iter)) {
user_dict_list_.AddString(utf8towcs(dict));
std::wstring txt = string_to_wstring(dict, CP_UTF8);
user_dict_list_.AddString(txt.c_str());
}
api_->user_dict_iterator_destroy(&iter);
user_dict_list_.SetCurSel(-1);
Expand Down Expand Up @@ -69,7 +70,8 @@ LRESULT DictManagementDialog::OnBackup(WORD, WORD code, HWND, BOOL&) {
WCHAR dict_name[100] = {0};
user_dict_list_.GetText(sel, dict_name);
path += std::wstring(L"\\") + dict_name + L".userdb.txt";
if (!api_->backup_user_dict(wcstoutf8(dict_name))) {
std::string dict_name_str = wstring_to_string(dict_name, CP_UTF8);
if (!api_->backup_user_dict(dict_name_str.c_str())) {
MessageBox(L"不知哪裏出錯了,未能完成導出操作。", L":-(", MB_OK | MB_ICONERROR);
return 0;
}
Expand Down Expand Up @@ -112,7 +114,8 @@ LRESULT DictManagementDialog::OnExport(WORD, WORD code, HWND, BOOL&) {
if (IDOK == dlg.DoModal()) {
char path[MAX_PATH] = {0};
WideCharToMultiByte(CP_ACP, 0, dlg.m_szFileName, -1, path, _countof(path), NULL, NULL);
int result = api_->export_user_dict(wcstoutf8(dict_name), path);
std::string dict_name_str = wstring_to_string(dict_name, CP_UTF8);
int result = api_->export_user_dict(dict_name_str.c_str(), path);
if (result < 0) {
MessageBox(L"不知哪裏出錯了,未能完成操作。", L":-(", MB_OK | MB_ICONERROR);
}
Expand Down Expand Up @@ -143,7 +146,7 @@ LRESULT DictManagementDialog::OnImport(WORD, WORD code, HWND, BOOL&) {
if (IDOK == dlg.DoModal()) {
char path[MAX_PATH] = {0};
WideCharToMultiByte(CP_ACP, 0, dlg.m_szFileName, -1, path, _countof(path), NULL, NULL);
int result = api_->import_user_dict(wcstoutf8(dict_name), path);
int result = api_->import_user_dict(wstring_to_string(dict_name, CP_UTF8).c_str(), path);
if (result < 0) {
MessageBox(L"不知哪裏出錯了,未能完成操作。", L":-(", MB_OK | MB_ICONERROR);
}
Expand Down
14 changes: 9 additions & 5 deletions WeaselDeployer/SwitcherSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void SwitcherSettingsDialog::Populate() {
RimeSchemaInfo* info = (RimeSchemaInfo*)item.reserved;
if (!strcmp(item.schema_id, schema_id) && recruited.find(info) == recruited.end()) {
recruited.insert(info);
schema_list_.AddItem(k, 0, utf8towcs(item.name));
std::wstring itemwstr = string_to_wstring(item.name, CP_UTF8);
schema_list_.AddItem(k, 0, itemwstr.c_str());
schema_list_.SetItemData(k, (DWORD_PTR)info);
schema_list_.SetCheckState(k, TRUE);
++k;
Expand All @@ -47,12 +48,14 @@ void SwitcherSettingsDialog::Populate() {
RimeSchemaInfo* info = (RimeSchemaInfo*)item.reserved;
if (recruited.find(info) == recruited.end()) {
recruited.insert(info);
schema_list_.AddItem(k, 0, utf8towcs(item.name));
std::wstring itemwstr = string_to_wstring(item.name, CP_UTF8);
schema_list_.AddItem(k, 0, itemwstr.c_str());
schema_list_.SetItemData(k, (DWORD_PTR)info);
++k;
}
}
hotkeys_.SetWindowTextW(utf8towcs(api_->get_hotkeys(settings_)));
std::wstring txt = string_to_wstring(api_->get_hotkeys(settings_), CP_UTF8);
hotkeys_.SetWindowTextW(txt.c_str());
loaded_ = true;
modified_ = false;
}
Expand All @@ -69,14 +72,15 @@ void SwitcherSettingsDialog::ShowDetails(RimeSchemaInfo* info) {
if (const char* description = api_->get_schema_description(info)) {
(details += "\n\n") += description;
}
description_.SetWindowTextW(utf8towcs(details.c_str()));
std::wstring txt = string_to_wstring(details.c_str(), CP_UTF8);
description_.SetWindowTextW(txt.c_str());
}

LRESULT SwitcherSettingsDialog::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) {
schema_list_.SubclassWindow(GetDlgItem(IDC_SCHEMA_LIST));
schema_list_.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
schema_list_.AddColumn(L"方案名稱", 0);
WTL::CRect rc;
CRect rc;
schema_list_.GetClientRect(&rc);
schema_list_.SetColumnWidth(0, rc.Width() - 20);

Expand Down
3 changes: 2 additions & 1 deletion WeaselDeployer/UIStyleSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void UIStyleSettingsDialog::Populate() {
int active_index = -1;
settings_->GetPresetColorSchemes(&preset_);
for (size_t i = 0; i < preset_.size(); ++i) {
color_schemes_.AddString(utf8towcs(preset_[i].name.c_str()));
std::wstring txt = string_to_wstring(preset_[i].name.c_str(), CP_UTF8);
color_schemes_.AddString(txt.c_str());
if (preset_[i].color_scheme_id == active) {
active_index = i;
}
Expand Down
Binary file modified WeaselDeployer/WeaselDeployer.rc
Binary file not shown.
3 changes: 3 additions & 0 deletions WeaselDeployer/WeaselDeployer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
<AdditionalLibraryDirectories>$(SolutionDir)\lib;$(BOOST_ROOT)\stage\lib;$(SolutionDir)\librime\build\lib\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OutputFile>$(SolutionDir)output\$(ProjectName)$(TargetExt)</OutputFile>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Configurator.h" />
Expand Down
3 changes: 3 additions & 0 deletions WeaselIME/WeaselIME.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
<ResourceCompile>
<AdditionalIncludeDirectories>$(SolutionDir)\include</AdditionalIncludeDirectories>
</ResourceCompile>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseHant|Win32'">
<ClCompile>
Expand Down
12 changes: 12 additions & 0 deletions WeaselIPC/ContextUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ void StatusUpdater::Store(Deserializer::KeyType const& k, std::wstring const& va

bool bool_value = (!value.empty() && value != L"0");

if (k[1] == L"schema_id")
{
m_pTarget->p_status->schema_id = value;
return;
}

if (k[1] == L"ascii_mode")
{
m_pTarget->p_status->ascii_mode = bool_value;
Expand All @@ -130,4 +136,10 @@ void StatusUpdater::Store(Deserializer::KeyType const& k, std::wstring const& va
m_pTarget->p_status->disabled = bool_value;
return;
}

if (k[1] == L"full_shape")
{
m_pTarget->p_status->full_shape = bool_value;
return;
}
}
8 changes: 0 additions & 8 deletions WeaselServer/WeaselServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lp
CreateDirectory(WeaselUserDataPath().c_str(), NULL);

int nRet = 0;
// named mutex to ensure only one instance running
HANDLE hMutex = CreateMutex(NULL, FALSE, L"WeaselServerNamedMutex");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
CloseHandle(hMutex);
::MessageBox(NULL, L"已有算法服务實例正在運行", L"已有算法服务實例正在運行", MB_ICONINFORMATION);
return 0;
}
try
{
WeaselServerApp app;
Expand All @@ -107,6 +100,5 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lp
_Module.Term();
::CoUninitialize();

CloseHandle(hMutex);
return nRet;
}
8 changes: 6 additions & 2 deletions WeaselServer/WeaselTrayIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static UINT mode_icon[] = { IDI_ZH, IDI_ZH, IDI_EN, IDI_RELOAD };
static const WCHAR *mode_label[] = { NULL, /*L"中文"*/ NULL, /*L"西文"*/ NULL, L"維護中" };

WeaselTrayIcon::WeaselTrayIcon(weasel::UI &ui)
: m_style(ui.style()), m_status(ui.status()), m_mode(INITIAL), m_schema_zhung_icon(), m_schema_ascii_icon()
: m_style(ui.style()), m_status(ui.status()), m_mode(INITIAL), m_schema_zhung_icon(), m_schema_ascii_icon(), m_disabled(false)
{
}

Expand Down Expand Up @@ -43,6 +43,7 @@ void WeaselTrayIcon::Refresh()
RemoveIcon();
m_mode = INITIAL;
}
m_disabled = false;
return;
}
WeaselTrayMode mode = m_status.disabled ? DISABLED :
Expand Down Expand Up @@ -79,10 +80,13 @@ void WeaselTrayIcon::Refresh()
else
SetIcon(mode_icon[mode]);

if (mode_label[mode])
if (mode_label[mode] && m_disabled == false)
{
ShowBalloon(mode_label[mode], WEASEL_IME_NAME);
m_disabled = true;
}
if(m_mode != DISABLED)
m_disabled = false;
}
else if (!Visible())
{
Expand Down
1 change: 1 addition & 0 deletions WeaselServer/WeaselTrayIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ class WeaselTrayIcon : public CSystemTray
WeaselTrayMode m_mode;
std::wstring m_schema_zhung_icon;
std::wstring m_schema_ascii_icon;
bool m_disabled;
};

3 changes: 2 additions & 1 deletion WeaselServer/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
#pragma conform(forScope, off)
#pragma comment(linker, "/NODEFAULTLIB:atlthunk.lib")
#endif // _WTL_SUPPORT_SDK_ATL3

// wtl10 require _RICHEDIT_VER > 0x0300, undef it first
#undef _RICHEDIT_VER
#include <atlbase.h>
#include <atlwin.h>

Expand Down
6 changes: 3 additions & 3 deletions WeaselSetup/WeaselSetup.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>$(PLATFORM_TOOLSET)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down Expand Up @@ -72,7 +72,7 @@
</Link>
<ResourceCompile>
<Culture>0x7804</Culture>
<AdditionalIncludeDirectories>$(SolutionDir)\include\wtl10;$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)\include\wtl;$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Midl>
Expand Down
8 changes: 4 additions & 4 deletions WeaselSetup/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

#include <atlbase.h>
#include <wtl10/atlapp.h>
#include <wtl/atlapp.h>

extern CAppModule _Module;

#include <atlwin.h>

#include <wtl10/atlframe.h>
#include <wtl10/atlctrls.h>
#include <wtl10/atldlgs.h>
#include <wtl/atlframe.h>
#include <wtl/atlctrls.h>
#include <wtl/atldlgs.h>

#include <string>
#include <shellapi.h>
Expand Down
2 changes: 1 addition & 1 deletion WeaselTSF/CandidateList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void CCandidateList::_DisposeUIWindowAll()
return;
}

// call _ui->DestroyAll() to clean resources
// call _ui->Destroy(true) to clean resources
_ui->Destroy(true);
}

Expand Down
66 changes: 66 additions & 0 deletions WeaselTSF/Compartment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "Compartment.h"
#include <resource.h>
#include <functional>
#include "ResponseParser.h"
#include "CandidateList.h"

STDAPI CCompartmentEventSink::QueryInterface(REFIID riid, _Outptr_ void **ppvObj)
{
Expand Down Expand Up @@ -195,6 +197,48 @@ HRESULT WeaselTSF::_SetKeyboardOpen(BOOL fOpen)
return hr;
}

HRESULT WeaselTSF::_GetCompartmentDWORD(DWORD& value, const GUID guid)
{
HRESULT hr = E_FAIL;
com_ptr<ITfCompartmentMgr> pComMgr;
if (_pThreadMgr->QueryInterface(&pComMgr) == S_OK)
{
ITfCompartment* pCompartment;
if (pComMgr->GetCompartment(guid, &pCompartment) == S_OK)
{
VARIANT var;
if (pCompartment->GetValue(&var) == S_OK)
{
if (var.vt == VT_I4)
value = var.lVal;
else
hr = S_FALSE;
}
}
pCompartment->Release();
}
return hr;
}

HRESULT WeaselTSF::_SetCompartmentDWORD(const DWORD& value, const GUID guid)
{
HRESULT hr = S_OK;
com_ptr<ITfCompartmentMgr> pComMgr;
if (_pThreadMgr->QueryInterface(&pComMgr) == S_OK)
{
ITfCompartment* pCompartment;
if (pComMgr->GetCompartment(guid, &pCompartment) == S_OK)
{
VARIANT var;
var.vt = VT_I4;
var.lVal = value;
hr = pCompartment->SetValue(_tfClientId, &var);
}
pCompartment->Release();
}
return hr;
}

BOOL WeaselTSF::_InitCompartment()
{
using namespace std::placeholders;
Expand All @@ -207,6 +251,14 @@ BOOL WeaselTSF::_InitCompartment()
(IUnknown *)_pThreadMgr,
GUID_COMPARTMENT_KEYBOARD_OPENCLOSE
);

_pConvertionCompartmentSink = new CCompartmentEventSink(callback);
if (!_pConvertionCompartmentSink)
return FALSE;
hr = _pConvertionCompartmentSink->_Advise(
(IUnknown*)_pThreadMgr,
GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION
);
return SUCCEEDED(hr);
}

Expand All @@ -216,6 +268,10 @@ void WeaselTSF::_UninitCompartment()
_pKeyboardCompartmentSink->_Unadvise();
_pKeyboardCompartmentSink = NULL;
}
if (_pConvertionCompartmentSink) {
_pConvertionCompartmentSink->_Unadvise();
_pConvertionCompartmentSink = NULL;
}

}

Expand All @@ -229,5 +285,15 @@ HRESULT WeaselTSF::_HandleCompartment(REFGUID guidCompartment)
}
_EnableLanguageBar(isOpen);
}
else if (IsEqualGUID(guidCompartment, GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION))
{
BOOL isOpen = _IsKeyboardOpen();
if (isOpen)
{
weasel::ResponseParser parser(NULL, NULL, &_status, NULL, &_cand->style());
bool ok = m_client.GetResponseData(std::ref(parser));
_UpdateLanguageBar(_status);
}
}
return S_OK;
}
3 changes: 1 addition & 2 deletions WeaselTSF/Composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ void WeaselTSF::_EndComposition(com_ptr<ITfContext> pContext, BOOL clear)
CEndCompositionEditSession *pEditSession;
HRESULT hr;

_cand->EndUI();
if ((pEditSession = new CEndCompositionEditSession(this, pContext, _pComposition, clear)) != NULL)
{
pContext->RequestEditSession(_tfClientId, pEditSession, TF_ES_SYNC | TF_ES_READWRITE, &hr);
pEditSession->Release();
}
// after pEditSession, less flicker
_cand->EndUI();
}

/* Get Text Extent */
Expand Down
Loading

0 comments on commit 9972aeb

Please sign in to comment.