Skip to content

Commit

Permalink
* Fix EasyIME#16 Missing keyboard layout for KB_THL_PINYIN and KB_MPS…
Browse files Browse the repository at this point in the history
…2_PINYIN.

* Fix EasyIME#15 unable to change font size of candidate window.
  • Loading branch information
PCMan committed Sep 25, 2013
1 parent ccafe3a commit a3b15b2
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 24 deletions.
Binary file modified ChewingPreferences/ChewingPreferences.rc
Binary file not shown.
7 changes: 3 additions & 4 deletions ChewingPreferences/KeyboardPropertyPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ KeyboardPropertyPage::~KeyboardPropertyPage(void) {

// virtual
bool KeyboardPropertyPage::onInitDialog() {
CheckRadioButton(hwnd_, IDC_KB1, IDC_KB9, IDC_KB1 + config_->keyboardLayout);

CheckRadioButton(hwnd_, IDC_KB1, IDC_KB11, IDC_KB1 + config_->keyboardLayout);
return PropertyPage::onInitDialog();
}

// virtual
void KeyboardPropertyPage::onOK() {
for(UINT id = IDC_KB1; id <= IDC_KB9; ++id) {
if(IsDlgButtonChecked(hwnd_, id)) {
for(UINT id = IDC_KB1; id <= IDC_KB11; ++id) {
if(IsDlgButtonChecked(hwnd_, id)) {
config_->keyboardLayout = (id - IDC_KB1);
break;
}
Expand Down
Binary file modified ChewingPreferences/resource.h
Binary file not shown.
26 changes: 26 additions & 0 deletions ChewingTextService/ChewingTextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ TextService::TextService(ImeModule* module):

// global compartment stuff
addCompartmentMonitor(g_configChangedGuid, true);

// font for candidate and mesasge windows
font_ = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
LOGFONT lf;
GetObject(font_, sizeof(lf), &lf);
lf.lfHeight = config().fontSize;
lf.lfWeight = FW_NORMAL;
font_ = CreateFontIndirect(&lf);
}

TextService::~TextService(void) {
Expand All @@ -112,6 +120,9 @@ TextService::~TextService(void) {
if(messageWindow_)
hideMessage();

if(font_)
::DeleteObject(font_);

if(switchLangButton_)
switchLangButton_->Release();
if(switchShapeButton_)
Expand Down Expand Up @@ -616,6 +627,19 @@ void TextService::applyConfig() {
selKeys[i] = (int)Config::selKeys[cfg.selKeyType][i];
::chewing_set_selKey(chewingContext_, selKeys, 10);
}

// font for candidate and mesasge windows
LOGFONT lf;
GetObject(font_, sizeof(lf), &lf);
if(lf.lfHeight != cfg.fontSize) { // font size is changed
::DeleteObject(font_); // delete old font
lf.lfHeight = cfg.fontSize; // apply the new size
font_ = CreateFontIndirect(&lf); // create new font
if(messageWindow_)
messageWindow_->setFont(font_);
if(candidateWindow_)
candidateWindow_->setFont(font_);
}
}

// toggle between English and Chinese
Expand Down Expand Up @@ -679,6 +703,7 @@ void TextService::showCandidates(Ime::EditSession* session) {
// Please see Ime::CandidateWindow::CandidateWindow() for an example.
if(!candidateWindow_) {
candidateWindow_ = new Ime::CandidateWindow(this, session);
candidateWindow_->setFont(font_);
}
updateCandidates(session);
candidateWindow_->show();
Expand All @@ -701,6 +726,7 @@ void TextService::showMessage(Ime::EditSession* session, std::wstring message, i
hideMessage();
// FIXME: reuse the window whenever possible
messageWindow_ = new Ime::MessageWindow(this, session);
messageWindow_->setFont(font_);
messageWindow_->setText(message);

int x = 0, y = 0;
Expand Down
2 changes: 1 addition & 1 deletion ChewingTextService/ChewingTextService.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class TextService: public Ime::TextService {
ChewingContext* chewingContext_;
Ime::CandidateWindow* candidateWindow_;
bool showingCandidates_;

Ime::MessageWindow* messageWindow_;
UINT messageTimerId_;
HFONT font_;

Ime::LangBarButton* switchLangButton_;
Ime::LangBarButton* switchShapeButton_;
Expand Down
2 changes: 1 addition & 1 deletion libIME/CandidateWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CandidateWindow : public ImeWindow {
}
void setCandPerRow(int n);

void recalculateSize();
virtual void recalculateSize();

bool filterKeyEvent(KeyEvent& keyEvent);

Expand Down
12 changes: 7 additions & 5 deletions libIME/ImeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
namespace Ime {

ImeWindow::ImeWindow(TextService* service):
textService_(service),
fontSize_(16) {
textService_(service) {

if(service->isImmersive()) { // windows 8 app mode
margin_ = 10;
Expand All @@ -33,17 +32,16 @@ ImeWindow::ImeWindow(TextService* service):
}

font_ = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
/*
LOGFONT lf;
GetObject(font_, sizeof(lf), &lf);
lf.lfHeight = fontSize_;
lf.lfWeight = FW_NORMAL;
font_ = CreateFontIndirect(&lf);

*/
}

ImeWindow::~ImeWindow(void) {
if(font_)
::DeleteObject(font_);
}

void ImeWindow::onLButtonDown(WPARAM wp, LPARAM lp) {
Expand Down Expand Up @@ -96,10 +94,14 @@ void ImeWindow::setFont(HFONT f) {
if(font_)
::DeleteObject(font_);
font_ = f;
recalculateSize();
if(isVisible())
::InvalidateRect(hwnd_, NULL, TRUE);
}

// virtual
void ImeWindow::recalculateSize() {
}

} // namespace Ime

2 changes: 1 addition & 1 deletion libIME/ImeWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ImeWindow: public Window {

static bool workingArea(RECT* rc, HWND app_wnd);
void setFont(HFONT f);
virtual void recalculateSize();

protected:
void onLButtonDown(WPARAM wp, LPARAM lp);
Expand All @@ -50,7 +51,6 @@ class ImeWindow: public Window {
TextService* textService_;
POINTS oldPos;
HFONT font_;
int fontSize_;
int margin_;
};

Expand Down
12 changes: 8 additions & 4 deletions libIME/MessageWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ MessageWindow::MessageWindow(TextService* service, EditSession* session):
MessageWindow::~MessageWindow(void) {
}

void MessageWindow::setText(std::wstring text) {
// FIXMEl: use different appearance under immersive mode
text_ = text;
// virtual
void MessageWindow::recalculateSize() {
SIZE size = {0};
HDC dc = GetDC(hwnd_);
HGDIOBJ old_font = SelectObject(dc, font_);
Expand All @@ -45,11 +44,16 @@ void MessageWindow::setText(std::wstring text) {

SetWindowPos(hwnd_, HWND_TOPMOST, 0, 0,
size.cx + margin_ * 2, size.cy + margin_ * 2, SWP_NOACTIVATE|SWP_NOMOVE);
}

void MessageWindow::setText(std::wstring text) {
// FIXMEl: use different appearance under immersive mode
text_ = text;
recalculateSize();
if(IsWindowVisible(hwnd_))
InvalidateRect(hwnd_, NULL, TRUE);
}


LRESULT MessageWindow::wndProc(UINT msg, WPARAM wp, LPARAM lp) {
switch(msg) {
case WM_PAINT: {
Expand Down
1 change: 1 addition & 0 deletions libIME/MessageWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MessageWindow : public ImeWindow {
return textService_;
}

virtual void recalculateSize();
protected:
LRESULT wndProc(UINT msg, WPARAM wp, LPARAM lp);
void onPaint(PAINTSTRUCT& ps);
Expand Down
16 changes: 8 additions & 8 deletions libIME/PropertyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ using namespace std;

namespace Ime {

typedef INT_PTR (WINAPI *PropertySheetFunc)(LPCPROPSHEETHEADER lppsph);
static PropertySheetFunc g_PropertySheetW = NULL;
//typedef INT_PTR (WINAPI *PropertySheetFunc)(LPCPROPSHEETHEADER lppsph);
//static PropertySheetFunc g_PropertySheetW = NULL;

PropertyDialog::PropertyDialog(void) {
}
Expand All @@ -47,10 +47,10 @@ INT_PTR PropertyDialog::showModal(HINSTANCE hInstance, LPCTSTR captionId, LPCTST
// Windows 8 does not allow linking to comctl32.dll
// when running in app containers.
// We use LoadLibrary here, but this should only be used in desktop app mode.
if(!g_PropertySheetW) {
HMODULE mod = ::LoadLibraryW(L"comctl32.dll");
g_PropertySheetW = (PropertySheetFunc)::GetProcAddress(mod, "PropertySheetW");
}
// if(!g_PropertySheetW) {
// HMODULE mod = ::LoadLibraryW(L"comctl32.dll");
// g_PropertySheetW = (PropertySheetFunc)::GetProcAddress(mod, "PropertySheetW");
// }

PROPSHEETPAGE* pages = new PROPSHEETPAGE[pages_.size()];
for(int i = 0; i < pages_.size(); ++i) {
Expand All @@ -68,8 +68,8 @@ INT_PTR PropertyDialog::showModal(HINSTANCE hInstance, LPCTSTR captionId, LPCTST
psh.ppsp = pages;
psh.pszCaption = (LPCTSTR)captionId;

assert(g_PropertySheetW);
INT_PTR result = g_PropertySheetW(&psh);
// INT_PTR result = g_PropertySheetW(&psh);
INT_PTR result =::PropertySheetW(&psh);
delete []pages;

return result;
Expand Down

0 comments on commit a3b15b2

Please sign in to comment.