Skip to content

Commit

Permalink
* Initialize the config dialog properly and try to save config values.
Browse files Browse the repository at this point in the history
* Fix incorrect Windows 8 detection and register the icon properly.
  • Loading branch information
PCMan committed Sep 17, 2013
1 parent 84ab251 commit a390ca0
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 65 deletions.
18 changes: 11 additions & 7 deletions ChewingTextService/ChewingConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ using namespace Chewing;

#define DEF_FONT_SIZE 16

const char* Config::selKeys[]={
"1234567890",
"asdfghjkl;",
"asdfzxcv89",
"asdfjkl789",
"aoeuhtn789",
"1234qweras",
const wchar_t* Config::selKeys[]={
L"1234567890",
L"asdfghjkl;",
L"asdfzxcv89",
L"asdfjkl789",
L"aoeuhtn789",
L"1234qweras",
NULL
};

Expand Down Expand Up @@ -162,4 +162,8 @@ void Config::save() {
::RegSetValueEx(hk, L"CheckNewVersion", 0, REG_DWORD, (LPBYTE)&checkNewVersion, sizeof(DWORD));
::RegCloseKey(hk);
}

// TODO: notify the world about the change and ask other text service instances to reload!
// Luckily, TSF global compartment sink is a perfect way to do this.
// So no complicated IPC is needed here.
}
2 changes: 1 addition & 1 deletion ChewingTextService/ChewingConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Config {
DWORD ctrlSymbol;
DWORD checkNewVersion; // Enable update notifier

static const char* selKeys[];
static const wchar_t* selKeys[];
};

}
Expand Down
101 changes: 49 additions & 52 deletions ChewingTextService/TypingPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,62 +31,59 @@ TypingPage::TypingPage(Config* config):
TypingPage::~TypingPage(void) {
}

LRESULT TypingPage::wndProc(UINT msg, WPARAM wp, LPARAM lp) {
switch(msg) {
case WM_INITDIALOG: {
CheckRadioButton(hwnd_, IDC_KB1, IDC_KB9, IDC_KB1 + config_->keyboardLayout);
// virtual
bool TypingPage::onInitDialog() {
CheckRadioButton(hwnd_, IDC_KB1, IDC_KB9, IDC_KB1 + config_->keyboardLayout);

CheckDlgButton(hwnd_, IDC_SPACESEL, config_->spaceAsSelection);
CheckDlgButton(hwnd_, IDC_ENABLE_SHIFT, config_->enableShift);
CheckDlgButton(hwnd_, IDC_SHIFT_CAPITAL, config_->shiftCapital);
CheckDlgButton(hwnd_, IDC_ADD_PHRASE_FORWARD, config_->addPhraseForward);
CheckDlgButton(hwnd_, IDC_ADV_AFTER_SEL, config_->advanceAfterSelection);
CheckDlgButton(hwnd_, IDC_CURSOR_CANDLIST, config_->cursorCandList);
CheckDlgButton(hwnd_, IDC_ENABLE_CAPSLOCK, config_->enableCapsLock);
CheckDlgButton(hwnd_, IDC_SHIFT_FULLSHAPE, config_->shiftFullShape);
CheckDlgButton(hwnd_, IDC_ESC_CLEAN_ALL_BUF, config_->escCleanAllBuf);
CheckDlgButton(hwnd_, IDC_SHIFT_SYMBOL, config_->shiftSymbol);
CheckDlgButton(hwnd_, IDC_CTRL_SYMBOL, config_->ctrlSymbol);
CheckDlgButton(hwnd_, IDC_ENABLE_Simp, config_->enableSimp);
CheckDlgButton(hwnd_, IDC_SPACESEL, config_->spaceAsSelection);
CheckDlgButton(hwnd_, IDC_ENABLE_SHIFT, config_->enableShift);
CheckDlgButton(hwnd_, IDC_SHIFT_CAPITAL, config_->shiftCapital);
CheckDlgButton(hwnd_, IDC_ADD_PHRASE_FORWARD, config_->addPhraseForward);
CheckDlgButton(hwnd_, IDC_ADV_AFTER_SEL, config_->advanceAfterSelection);
CheckDlgButton(hwnd_, IDC_CURSOR_CANDLIST, config_->cursorCandList);
CheckDlgButton(hwnd_, IDC_ENABLE_CAPSLOCK, config_->enableCapsLock);
CheckDlgButton(hwnd_, IDC_SHIFT_FULLSHAPE, config_->shiftFullShape);
CheckDlgButton(hwnd_, IDC_ESC_CLEAN_ALL_BUF, config_->escCleanAllBuf);
CheckDlgButton(hwnd_, IDC_SHIFT_SYMBOL, config_->shiftSymbol);
CheckDlgButton(hwnd_, IDC_CTRL_SYMBOL, config_->ctrlSymbol);
CheckDlgButton(hwnd_, IDC_ENABLE_Simp, config_->enableSimp);

HWND combo = GetDlgItem(hwnd_, IDC_SELKEYS);
// const TCHAR** pselkeys = config_->selKeyNames;
// while(*pselkeys)
// ComboBox_AddString(combo, *(pselkeys++));
// ComboBox_SetCurSel(combo, config_->selKeyType);
HWND combo = GetDlgItem(hwnd_, IDC_SELKEYS);
for(const wchar_t** pselkeys = config_->selKeys; *pselkeys; ++pselkeys)
ComboBox_AddString(combo, *pselkeys);
ComboBox_SetCurSel(combo, config_->selKeyType);
return PropertyPage::onInitDialog();
}

// virtual
void TypingPage::onOK() {
for(UINT id = IDC_KB1; id <= IDC_KB9; ++id) {
if(IsDlgButtonChecked(hwnd_, id)) {
config_->keyboardLayout = (id - IDC_KB1);
break;
}
return TRUE;
case WM_NOTIFY:
if(LPNMHDR(lp)->code == PSN_APPLY) {
for(UINT id = IDC_KB1; id <= IDC_KB9; ++id) {
if(IsDlgButtonChecked(hwnd_, id)) {
config_->keyboardLayout = (id - IDC_KB1);
break;
}
}
}

config_->selKeyType = ComboBox_GetCurSel(GetDlgItem(hwnd_, IDC_SELKEYS));
if(config_->selKeyType < 0)
config_->selKeyType = 0;
config_->selKeyType = ComboBox_GetCurSel(GetDlgItem(hwnd_, IDC_SELKEYS));
if(config_->selKeyType < 0)
config_->selKeyType = 0;

config_->spaceAsSelection = IsDlgButtonChecked(hwnd_, IDC_SPACESEL);
config_->enableShift = IsDlgButtonChecked(hwnd_, IDC_ENABLE_SHIFT);
config_->shiftCapital = IsDlgButtonChecked(hwnd_, IDC_SHIFT_CAPITAL);
config_->addPhraseForward = IsDlgButtonChecked(hwnd_, IDC_ADD_PHRASE_FORWARD);
config_->advanceAfterSelection = IsDlgButtonChecked(hwnd_, IDC_ADV_AFTER_SEL);
config_->cursorCandList = IsDlgButtonChecked(hwnd_, IDC_CURSOR_CANDLIST);
config_->enableCapsLock = IsDlgButtonChecked(hwnd_, IDC_ENABLE_CAPSLOCK);
config_->shiftFullShape = IsDlgButtonChecked(hwnd_, IDC_SHIFT_FULLSHAPE);
config_->escCleanAllBuf = IsDlgButtonChecked(hwnd_, IDC_ESC_CLEAN_ALL_BUF);
// if (config_->chewing!=NULL)
// config_->chewing->SetAdvanceAfterSelection((config_->AdvanceAfterSelection!=0)?true: false);
config_->shiftSymbol = IsDlgButtonChecked(hwnd_, IDC_SHIFT_SYMBOL);
config_->ctrlSymbol = IsDlgButtonChecked(hwnd_, IDC_CTRL_SYMBOL);
config_->enableSimp = IsDlgButtonChecked(hwnd_, IDC_ENABLE_Simp);
config_->spaceAsSelection = IsDlgButtonChecked(hwnd_, IDC_SPACESEL);
config_->enableShift = IsDlgButtonChecked(hwnd_, IDC_ENABLE_SHIFT);
config_->shiftCapital = IsDlgButtonChecked(hwnd_, IDC_SHIFT_CAPITAL);
config_->addPhraseForward = IsDlgButtonChecked(hwnd_, IDC_ADD_PHRASE_FORWARD);
config_->advanceAfterSelection = IsDlgButtonChecked(hwnd_, IDC_ADV_AFTER_SEL);
config_->cursorCandList = IsDlgButtonChecked(hwnd_, IDC_CURSOR_CANDLIST);
config_->enableCapsLock = IsDlgButtonChecked(hwnd_, IDC_ENABLE_CAPSLOCK);
config_->shiftFullShape = IsDlgButtonChecked(hwnd_, IDC_SHIFT_FULLSHAPE);
config_->escCleanAllBuf = IsDlgButtonChecked(hwnd_, IDC_ESC_CLEAN_ALL_BUF);
// if (config_->chewing!=NULL)
// config_->chewing->SetAdvanceAfterSelection((config_->AdvanceAfterSelection!=0)?true: false);
config_->shiftSymbol = IsDlgButtonChecked(hwnd_, IDC_SHIFT_SYMBOL);
config_->ctrlSymbol = IsDlgButtonChecked(hwnd_, IDC_CTRL_SYMBOL);
config_->enableSimp = IsDlgButtonChecked(hwnd_, IDC_ENABLE_Simp);

SetWindowLongPtr(hwnd_, DWLP_MSGRESULT, PSNRET_NOERROR);
return TRUE;
}
}
return PropertyPage::wndProc(msg, wp, lp);
config_->save();
PropertyPage::onOK();
}

3 changes: 2 additions & 1 deletion ChewingTextService/TypingPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class TypingPage : public Ime::PropertyPage {
virtual ~TypingPage(void);

protected:
LRESULT wndProc(UINT msg, WPARAM wp, LPARAM lp);
virtual bool onInitDialog();
virtual void onOK();

private:
Config* config_;
Expand Down
30 changes: 26 additions & 4 deletions libIME/Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ INT_PTR CALLBACK Dialog::_dlgProc(HWND hwnd , UINT msg, WPARAM wp , LPARAM lp) {
Dialog* pThis = (Dialog*)lp;
pThis->hwnd_ = hwnd;
hwndMap_[hwnd] = pThis;
pThis->wndProc(msg, wp, lp);
return TRUE;
return pThis->wndProc(msg, wp, lp);
}
}
return FALSE;
Expand All @@ -62,9 +61,32 @@ INT_PTR CALLBACK Dialog::_dlgProc(HWND hwnd , UINT msg, WPARAM wp , LPARAM lp) {
LRESULT Dialog::wndProc(UINT msg, WPARAM wp , LPARAM lp) {
switch(msg) {
case WM_COMMAND:
if(wp == IDOK || wp == IDCANCEL)
endDialog(wp);
switch(wp) {
case IDOK:
onOK();
return TRUE;
case IDCANCEL:
onCancel();
return TRUE;
}
break;
case WM_INITDIALOG:
return onInitDialog();
}
return FALSE;
}

// virtual
bool Dialog::onInitDialog() {
return true;
}

// virtual
void Dialog::onOK() {
endDialog(IDOK);
}

// virtual
void Dialog::onCancel() {
endDialog(IDCANCEL);
}
4 changes: 4 additions & 0 deletions libIME/Dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class Dialog : public Window {
static INT_PTR CALLBACK _dlgProc(HWND hwnd , UINT msg, WPARAM wp , LPARAM lp);
virtual LRESULT wndProc(UINT msg, WPARAM wp , LPARAM lp);

virtual bool onInitDialog();
virtual void onOK();
virtual void onCancel();

private:
};

Expand Down
1 change: 1 addition & 0 deletions libIME/ImeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static const GUID g_convertedDisplayAttributeGuid =
ImeModule::ImeModule(HMODULE module, const CLSID& textServiceClsid):
hInstance_(HINSTANCE(module)),
textServiceClsid_(textServiceClsid),
isWindows8Above_(false),
refCount_(1) {

Window::registerClass(hInstance_);
Expand Down
22 changes: 22 additions & 0 deletions libIME/PropertyPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,25 @@ INT_PTR CALLBACK PropertyPage::_dlgProc(HWND hwnd , UINT msg, WPARAM wp , LPARAM
}
return Dialog::_dlgProc(hwnd, msg, wp, lp);
}

// virtual
LRESULT PropertyPage::wndProc(UINT msg, WPARAM wp, LPARAM lp) {
switch(msg) {
case WM_NOTIFY:
if(LPNMHDR(lp)->code == PSN_APPLY) {
onOK();
}
return TRUE;
}
return Dialog::wndProc(msg, wp, lp);
}

// virtual
void PropertyPage::onOK() {
::SetWindowLongPtr(hwnd_, DWLP_MSGRESULT, PSNRET_NOERROR);
}

// virtual
void PropertyPage::onCancel() {
::SetWindowLongPtr(hwnd_, DWLP_MSGRESULT, PSNRET_NOERROR);
}
3 changes: 3 additions & 0 deletions libIME/PropertyPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class PropertyPage: public Dialog {
protected:
void setup(PROPSHEETPAGE& page);
static INT_PTR CALLBACK _dlgProc(HWND hwnd , UINT msg, WPARAM wp , LPARAM lp);
virtual LRESULT wndProc(UINT msg, WPARAM wp, LPARAM lp);
virtual void onOK();
virtual void onCancel();

private:
LPCTSTR dialogId_;
Expand Down

0 comments on commit a390ca0

Please sign in to comment.