Skip to content

Commit

Permalink
feat: support config conv engine
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Aug 17, 2024
1 parent a5768c2 commit c4c863d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
Binary file modified ChewingPreferences/ChewingPreferences.rc
Binary file not shown.
10 changes: 10 additions & 0 deletions ChewingPreferences/TypingPropertyPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ bool TypingPropertyPage::onInitDialog() {
for(const wchar_t** pselkeys = config_->selKeys; *pselkeys; ++pselkeys)
ComboBox_AddString(combo, *pselkeys);
ComboBox_SetCurSel(combo, config_->selKeyType);

combo = GetDlgItem(hwnd_, IDC_CONV_ENGINES);
for(const wchar_t** pconvEngine = config_->convEngines; *pconvEngine; ++pconvEngine)
ComboBox_AddString(combo, *pconvEngine);
ComboBox_SetCurSel(combo, config_->convEngine);

return PropertyPage::onInitDialog();
}

Expand All @@ -64,6 +70,10 @@ void TypingPropertyPage::onOK() {
if(config_->selKeyType < 0)
config_->selKeyType = 0;

config_->convEngine = ComboBox_GetCurSel(GetDlgItem(hwnd_, IDC_CONV_ENGINES));
if(config_->convEngine < 0)
config_->convEngine = 0;

config_->showCandWithSpaceKey = IsDlgButtonChecked(hwnd_, IDC_SPACESEL);
config_->switchLangWithShift = IsDlgButtonChecked(hwnd_, IDC_ENABLE_SHIFT);
config_->addPhraseForward = IsDlgButtonChecked(hwnd_, IDC_ADD_PHRASE_FORWARD);
Expand Down
Binary file modified ChewingPreferences/resource.h
Binary file not shown.
10 changes: 10 additions & 0 deletions ChewingTextService/ChewingConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ const wchar_t* Config::selKeys[]={
NULL
};

const wchar_t* Config::convEngines[]={
L"簡單注音",
L"智慧選詞",
L"模糊智慧選詞",
NULL
};

// http://msdn.microsoft.com/en-us/library/windows/desktop/hh448449(v=vs.85).aspx
// define new Win 8 app related constants for older versions of SDK and VC++
#ifndef SECURITY_APP_PACKAGE_AUTHORITY
Expand Down Expand Up @@ -62,6 +69,7 @@ Config::Config(Ime::WindowsVersion winver):
advanceAfterSelection = true;
fontSize = DEF_FONT_SIZE;
selKeyType = 0;
convEngine = 1;
candPerPage = 9;
cursorCandList = 1;
enableCapsLock = 1;
Expand Down Expand Up @@ -112,6 +120,7 @@ void Config::load() {
::RegQueryValueEx(hk, L"AdvanceAfterSelection", 0, &type, (LPBYTE)&advanceAfterSelection, &size);
::RegQueryValueEx(hk, L"DefFontSize", 0, &type, (LPBYTE)&fontSize, &size);
::RegQueryValueEx(hk, L"SelKeyType", 0, &type, (LPBYTE)&selKeyType, &size);
::RegQueryValueEx(hk, L"ConvEngine", 0, &type, (LPBYTE)&convEngine, &size);
::RegQueryValueEx(hk, L"SelAreaLen", 0, &type, (LPBYTE)&candPerPage, &size);
::RegQueryValueEx(hk, L"CursorCandList", 0, &type, (LPBYTE)&cursorCandList, &size);
::RegQueryValueEx(hk, L"EnableCapsLock", 0, &type, (LPBYTE)&enableCapsLock, &size);
Expand Down Expand Up @@ -152,6 +161,7 @@ void Config::save() {
::RegSetValueEx(hk, L"AdvanceAfterSelection", 0, REG_DWORD, (LPBYTE)&advanceAfterSelection, sizeof(DWORD));
::RegSetValueEx(hk, L"DefFontSize", 0, REG_DWORD, (LPBYTE)&fontSize, sizeof(DWORD));
::RegSetValueEx(hk, L"SelKeyType", 0, REG_DWORD, (LPBYTE)&selKeyType, sizeof(DWORD));
::RegSetValueEx(hk, L"ConvEngine", 0, REG_DWORD, (LPBYTE)&convEngine, sizeof(DWORD));
::RegSetValueEx(hk, L"SelAreaLen", 0, REG_DWORD, (LPBYTE)&candPerPage, sizeof(DWORD));
::RegSetValueEx(hk, L"CursorCandList", 0, REG_DWORD, (LPBYTE)&cursorCandList, sizeof(DWORD));
::RegSetValueEx(hk, L"EnableCapsLock", 0, REG_DWORD, (LPBYTE)&enableCapsLock, sizeof(DWORD));
Expand Down
2 changes: 2 additions & 0 deletions ChewingTextService/ChewingConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Config {
DWORD advanceAfterSelection; // automatically shift cursor to the next char after choosing a candidate
DWORD fontSize; // font size of candidate window and tip window (not supported yet)
DWORD selKeyType; // keys use to select candidate strings (default: 123456789)
DWORD convEngine; // conversion engine (default: CHEWING_CONVERSION_ENGINE)
DWORD candPerPage; // number of candiate strings per page
DWORD cursorCandList; // use cursor to select items in the candidate window (not supported yet)
DWORD enableCapsLock; // use capslock to Change language mode
Expand All @@ -71,6 +72,7 @@ class Config {
DWORD easySymbolsWithCtrl; // output easy symbols when Ctrl is pressed

static const wchar_t* selKeys[]; // keys used to select candidate strings.
static const wchar_t* convEngines[];

private:
DWORD stamp; // timestamp used to check if the config values are up to date
Expand Down
2 changes: 2 additions & 0 deletions ChewingTextService/ChewingTextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ void TextService::applyConfig() {
for(int i = 0; i < 10; ++i)
selKeys[i] = (int)Config::selKeys[cfg.selKeyType][i];
::chewing_set_selKey(chewingContext_, selKeys, 10);

chewing_config_set_int(chewingContext_, "chewing.conversion_engine", cfg.convEngine);
}

// font for candidate and mesasge windows
Expand Down

0 comments on commit c4c863d

Please sign in to comment.