From a3b15b26ff7b9aaff0fc6119f3b149416163b5fd Mon Sep 17 00:00:00 2001 From: "Hong Jen Yee (PCMan)" Date: Wed, 25 Sep 2013 10:32:19 +0800 Subject: [PATCH] * Fix #16 Missing keyboard layout for KB_THL_PINYIN and KB_MPS2_PINYIN. * Fix #15 unable to change font size of candidate window. --- ChewingPreferences/ChewingPreferences.rc | Bin 29980 -> 30246 bytes ChewingPreferences/KeyboardPropertyPage.cpp | 7 +++--- ChewingPreferences/resource.h | Bin 14062 -> 14430 bytes ChewingTextService/ChewingTextService.cpp | 26 ++++++++++++++++++++ ChewingTextService/ChewingTextService.h | 2 +- libIME/CandidateWindow.h | 2 +- libIME/ImeWindow.cpp | 12 +++++---- libIME/ImeWindow.h | 2 +- libIME/MessageWindow.cpp | 12 ++++++--- libIME/MessageWindow.h | 1 + libIME/PropertyDialog.cpp | 16 ++++++------ 11 files changed, 56 insertions(+), 24 deletions(-) diff --git a/ChewingPreferences/ChewingPreferences.rc b/ChewingPreferences/ChewingPreferences.rc index 727c1e9431e404de2139230e286489aad1d7bd6f..4eb0654ddf6b35ae0cf272bb5eb613a6a5539ad0 100644 GIT binary patch delta 677 zcmZWmOKTHR6h4EkHP$gkC$UMJ7-Mylh%=LUBuGnbP12;Ii4{|;(nMVaQTqebswh~L zP(P%I;zn>GE-Z1?iVGJmM8uVQHzHDBv`ZMLM4@hk5b! zh>gLJ=9AHBMwTL%u^M_CGz7yEEwG(1wNM$}hf?1ae25)Wy=Gm?ii(Np2^Wpn>rRhp ziQ9Ya%{rY7%mu@UMUQuR>C8tUmP9$&hsDq)#uNAyHAOAUx_>n-uoW}*hStj+oBO+M z@uoOO={!ZFwKj4{@mXXFKL-odG;Zb2sh+hlMG&aBKQ*sDkfX@sU|jE2RsJ{Jd6sg+q7Ojq3Aujg0h?;Q3| y{jV^FhAu8nCGVbnq*LU8HUm4uYEXb}x`f4?_MoBO!;o^$W-oclJ9lsDg%t@T)kNqOog zgDmp!vF`%D#13$!)Q>_Xgv-6#Z3a1L_G&mv4I-rtMh)_r;gQSH<=&Jwtrn>$Yc@8t zQ9RF`#csL_@3Z_(7Le`PiCUyfgvZe!1N$il-{N^Sm}ZiVX8d+*j!7oZd5FKsbEqUj z_?37UHF;y6822Clu=|8>^TcL+29Z>_BhPOUudzvQP1#KZY@7LVyNotIB`;w(y^O7D z2qSk2?LwDBK9o!vi$eqOv$kqUtWFkk?9Kh50uHlgt7@=gqWYONj%2nKAI*%0uVVw@ zrL~)PUp=Wmz;UT378oTKyHbSDw6~!cDo(iZxG!=ZABy2NkN2|sjh)e1Mb)KDmu<+6 z*V_ZjidZd|@MpZ*DRN6naaiJu>kihh%}JEa=Mbpj@(tB%S>Sr*vu%LL@t6gmTzNg3k0gbz!T>t<8 diff --git a/ChewingPreferences/KeyboardPropertyPage.cpp b/ChewingPreferences/KeyboardPropertyPage.cpp index ec3bd7c07..02fe35f68 100644 --- a/ChewingPreferences/KeyboardPropertyPage.cpp +++ b/ChewingPreferences/KeyboardPropertyPage.cpp @@ -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; } diff --git a/ChewingPreferences/resource.h b/ChewingPreferences/resource.h index 30f57e7d630807df4aed38b28833277c91403dc3..e3b78a4786c9085e380cedddcfc8c8374774a608 100644 GIT binary patch delta 226 zcmXAiy$-=p07hLbZh!nW9Y}gBwUMTGKnH`tV6~Y00+LERhJ|l2vKi4Qu!_MTCJ{E1 z)NXLyZs(kQ$@d=L!|jw}Rneo0el6f(Q0$3|(5gqVbt16y6dUH^!RiQXJv!PY1tIN` z4r;1{3-tvJ%M53lg{S=OU?et^#?8cD(&n0jzUmVnB%kz^v>kQul{6_Z42miO%@eCn tm0_!O1wD&$zc8EdN~#FrKEqQST;Yh*Sy9%xYIJKXC|qVDY#CU#M?YVZM}z|Oo?M~@ zl4j%wOJC5kn0$y8B+W5dM;j#ZP!KH90p=vi%1?fvZ8LcTmjcLS2OSF#bFzUX-((eG vjmhtr*fwwAS|PA`i}V@B$sgqSHouY;;@<3|JBe$unv~e&2WBFZIV{2eS!Ol- diff --git a/ChewingTextService/ChewingTextService.cpp b/ChewingTextService/ChewingTextService.cpp index 797081a69..5d54dc68a 100644 --- a/ChewingTextService/ChewingTextService.cpp +++ b/ChewingTextService/ChewingTextService.cpp @@ -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) { @@ -112,6 +120,9 @@ TextService::~TextService(void) { if(messageWindow_) hideMessage(); + if(font_) + ::DeleteObject(font_); + if(switchLangButton_) switchLangButton_->Release(); if(switchShapeButton_) @@ -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 @@ -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(); @@ -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; diff --git a/ChewingTextService/ChewingTextService.h b/ChewingTextService/ChewingTextService.h index f0597a4b2..857e65525 100644 --- a/ChewingTextService/ChewingTextService.h +++ b/ChewingTextService/ChewingTextService.h @@ -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_; diff --git a/libIME/CandidateWindow.h b/libIME/CandidateWindow.h index 337ab46cf..c1e50c8d6 100644 --- a/libIME/CandidateWindow.h +++ b/libIME/CandidateWindow.h @@ -59,7 +59,7 @@ class CandidateWindow : public ImeWindow { } void setCandPerRow(int n); - void recalculateSize(); + virtual void recalculateSize(); bool filterKeyEvent(KeyEvent& keyEvent); diff --git a/libIME/ImeWindow.cpp b/libIME/ImeWindow.cpp index da698e702..7cbdbf101 100644 --- a/libIME/ImeWindow.cpp +++ b/libIME/ImeWindow.cpp @@ -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; @@ -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) { @@ -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 diff --git a/libIME/ImeWindow.h b/libIME/ImeWindow.h index 4965b0be6..00ff220fa 100644 --- a/libIME/ImeWindow.h +++ b/libIME/ImeWindow.h @@ -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); @@ -50,7 +51,6 @@ class ImeWindow: public Window { TextService* textService_; POINTS oldPos; HFONT font_; - int fontSize_; int margin_; }; diff --git a/libIME/MessageWindow.cpp b/libIME/MessageWindow.cpp index 50a57242b..572f691f5 100644 --- a/libIME/MessageWindow.cpp +++ b/libIME/MessageWindow.cpp @@ -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_); @@ -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: { diff --git a/libIME/MessageWindow.h b/libIME/MessageWindow.h index b44d0e5de..6d8007e71 100644 --- a/libIME/MessageWindow.h +++ b/libIME/MessageWindow.h @@ -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); diff --git a/libIME/PropertyDialog.cpp b/libIME/PropertyDialog.cpp index bb5f6885f..6c3f9b63c 100644 --- a/libIME/PropertyDialog.cpp +++ b/libIME/PropertyDialog.cpp @@ -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) { } @@ -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) { @@ -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;