diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..25ed932 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Google +IndentWidth: 4 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 42afabf..7c8c5e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -/build \ No newline at end of file +/build +/.cache +/rustlib/target +/tsfreg/target \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e1c65f..785907f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,23 +9,16 @@ add_definitions( /D_UNICODE=1 /DUNICODE=1 # do Unicode build /D_CRT_SECURE_NO_WARNINGS # disable warnings about old libc functions ) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8") # set source code encoding to UTF-8 -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-") # turn off C++ RTTI -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") # set source code encoding to UTF-8 -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL /Gw") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL /Gw") -set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION $) +set(CMAKE_CXX_STANDARD 17) -enable_testing() +if (MSVC) + add_compile_options(/utf-8) +endif() -set(PROJECT_LIBCHEWING ${PROJECT_SOURCE_DIR}/libchewing) -set(CHEWING_DATA_PREFIX ${PROJECT_BINARY_DIR}/libchewing/data) +# Static link MSVC runtime +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded") -add_subdirectory(${PROJECT_LIBCHEWING}) - -add_subdirectory(${PROJECT_SOURCE_DIR}/libIME) - -add_subdirectory(${PROJECT_SOURCE_DIR}/ChewingTextService) - -add_subdirectory(${PROJECT_SOURCE_DIR}/ChewingPreferences) +add_subdirectory(libchewing) +add_subdirectory(libIME) +add_subdirectory(ChewingTextService) +add_subdirectory(ChewingPreferences) diff --git a/ChewingPreferences/CMakeLists.txt b/ChewingPreferences/CMakeLists.txt index 5ed4fa0..f7ab42e 100644 --- a/ChewingPreferences/CMakeLists.txt +++ b/ChewingPreferences/CMakeLists.txt @@ -36,4 +36,4 @@ add_executable(ChewingPreferences WIN32 ) target_link_libraries(ChewingPreferences comctl32.lib -) +) \ No newline at end of file diff --git a/ChewingPreferences/ChewingPreferences.cpp b/ChewingPreferences/ChewingPreferences.cpp index 7032101..796412f 100644 --- a/ChewingPreferences/ChewingPreferences.cpp +++ b/ChewingPreferences/ChewingPreferences.cpp @@ -17,9 +17,6 @@ // Boston, MA 02110-1301, USA. // -#include -#include -#include #include "TypingPropertyPage.h" #include "UiPropertyPage.h" #include "KeyboardPropertyPage.h" @@ -31,6 +28,9 @@ #include #include +#include +#include + namespace Chewing { // {F4D1E543-FB2C-48D7-B78D-20394F355381} // global compartment GUID for config change notification @@ -51,8 +51,7 @@ static void initControls() { static void configDialog(HINSTANCE hInstance) { initControls(); - Ime::WindowsVersion winVer; - Config config(winVer); + Config config; config.load(); Ime::PropertyDialog dlg; @@ -76,14 +75,14 @@ static void configDialog(HINSTANCE hInstance) { stamp = 0; // set global compartment value to notify existing ChewingTextService instances ::CoInitialize(NULL); // initialize COM - Ime::ComPtr threadMgr; - if(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, (void**)&threadMgr) == S_OK) { + winrt::com_ptr threadMgr; + if(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, threadMgr.put_void()) == S_OK) { TfClientId clientId = 0; if(threadMgr->Activate(&clientId) == S_OK) { - Ime::ComPtr compartmentMgr; - if(threadMgr->GetGlobalCompartment(&compartmentMgr) == S_OK) { - Ime::ComPtr compartment; - if(compartmentMgr->GetCompartment(g_configChangedGuid, &compartment) == S_OK) { + winrt::com_ptr compartmentMgr; + if(threadMgr->GetGlobalCompartment(compartmentMgr.put()) == S_OK) { + winrt::com_ptr compartment; + if(compartmentMgr->GetCompartment(g_configChangedGuid, compartment.put()) == S_OK) { VARIANT var; VariantInit(&var); var.vt = VT_I4; diff --git a/ChewingPreferences/SymbolsPropertyPage.cpp b/ChewingPreferences/SymbolsPropertyPage.cpp index 66825b7..8c4e76f 100644 --- a/ChewingPreferences/SymbolsPropertyPage.cpp +++ b/ChewingPreferences/SymbolsPropertyPage.cpp @@ -20,7 +20,6 @@ #include "SymbolsPropertyPage.h" #include "resource.h" #include -#include namespace Chewing { diff --git a/ChewingPreferences/resource.h b/ChewingPreferences/resource.h index 56ea854..d1382d9 100644 Binary files a/ChewingPreferences/resource.h and b/ChewingPreferences/resource.h differ diff --git a/ChewingTextService/CMakeLists.txt b/ChewingTextService/CMakeLists.txt index 42d9eea..fcc51de 100644 --- a/ChewingTextService/CMakeLists.txt +++ b/ChewingTextService/CMakeLists.txt @@ -1,11 +1,6 @@ project(ChewingTextService) -if(NOT DEFINED PROJECT_LIBCHEWING) - message(FATAL_ERROR "PROJECT_LIBCHEWING must be provided") -endif() - include_directories( - ${PROJECT_LIBCHEWING}/include ${CMAKE_SOURCE_DIR} ) @@ -28,3 +23,7 @@ target_link_libraries(ChewingTextService libchewing libIME_static ) +target_link_options(ChewingTextService + PRIVATE /NODEFAULTLIB:MSVCRT + PRIVATE /NODEFAULTLIB:MSVCRTD +) \ No newline at end of file diff --git a/ChewingTextService/ChewingConfig.cpp b/ChewingTextService/ChewingConfig.cpp index 8fe6205..ba6ac00 100644 --- a/ChewingTextService/ChewingConfig.cpp +++ b/ChewingTextService/ChewingConfig.cpp @@ -17,8 +17,11 @@ // Boston, MA 02110-1301, USA. // -#include "ChewingConfig.h" #include +#include +#include + +#include "ChewingConfig.h" namespace Chewing { @@ -54,8 +57,7 @@ const wchar_t* Config::convEngines[]={ #define SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE 0x00000001L #endif -Config::Config(Ime::WindowsVersion winver): - winVer_(winver) { +Config::Config() { // Configuration keyboardLayout = 0; candPerRow = 3; @@ -175,7 +177,7 @@ void Config::save() { ::RegCloseKey(hk); // grant access to app containers in Windows 8 - if(winVer_.isWindows8Above()) + if(IsWindows8OrGreater()) grantAppContainerAccess(L"CURRENT_USER\\Software\\ChewingTextService", SE_REGISTRY_KEY, KEY_READ); } } diff --git a/ChewingTextService/ChewingConfig.h b/ChewingTextService/ChewingConfig.h index f161206..2164c1a 100644 --- a/ChewingTextService/ChewingConfig.h +++ b/ChewingTextService/ChewingConfig.h @@ -22,13 +22,12 @@ #include #include -#include namespace Chewing { class Config { public: - Config(Ime::WindowsVersion winver); + Config(); ~Config(void); void load(); @@ -76,7 +75,6 @@ class Config { private: DWORD stamp; // timestamp used to check if the config values are up to date - Ime::WindowsVersion winVer_; }; } diff --git a/ChewingTextService/ChewingImeModule.cpp b/ChewingTextService/ChewingImeModule.cpp index 2e3102b..3d8fc6d 100644 --- a/ChewingTextService/ChewingImeModule.cpp +++ b/ChewingTextService/ChewingImeModule.cpp @@ -31,8 +31,7 @@ const CLSID g_textServiceClsid = { }; ImeModule::ImeModule(HMODULE module): - Ime::ImeModule(module, g_textServiceClsid), - config_(windowsVersion()) { + Ime::ImeModule(module, g_textServiceClsid) { config_.load(); // load configurations diff --git a/ChewingTextService/ChewingTextService.cpp b/ChewingTextService/ChewingTextService.cpp index 7d6c74e..2dae2ab 100644 --- a/ChewingTextService/ChewingTextService.cpp +++ b/ChewingTextService/ChewingTextService.cpp @@ -18,14 +18,24 @@ // #include "ChewingTextService.h" + +#include +#include + +#include #include -#include -#include #include +#include +#include +#include + +#include +#include + #include "ChewingImeModule.h" #include "resource.h" -#include -#include +#include "libime2.h" + using namespace std; @@ -63,9 +73,7 @@ TextService::TextService(ImeModule* module): shapeMode_(-1), outputSimpChinese_(false), lastKeyDownCode_(0), - messageWindow_(NULL), messageTimerId_(0), - candidateWindow_(NULL), imeModeIcon_(NULL), symbolsFileTime_(0), chewingContext_(NULL) { @@ -95,7 +103,7 @@ TextService::TextService(ImeModule* module): button->Release(); // Windows 8 systray IME mode icon - if(imeModule()->isWindows8Above()) { + if(IsWindows8OrGreater()) { imeModeIcon_ = new Ime::LangBarButton(this, _GUID_LBI_INPUTMODE, ID_MODE_ICON); imeModeIcon_->setIcon(IDI_ENG); addButton(imeModeIcon_); @@ -103,29 +111,15 @@ 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) { if(popupMenu_) ::DestroyMenu(popupMenu_); - if(candidateWindow_) - candidateWindow_->Release(); - if(messageWindow_) hideMessage(); - if(font_) - ::DeleteObject(font_); - if(switchLangButton_) switchLangButton_->Release(); if(switchShapeButton_) @@ -155,8 +149,7 @@ void TextService::onDeactivate() { if(candidateWindow_) { showingCandidates_ = false; - candidateWindow_->Release(); - candidateWindow_ = NULL; + candidateWindow_ = nullptr; } } @@ -284,7 +277,7 @@ bool TextService::onKeyDown(Ime::KeyEvent& keyEvent, Ime::EditSession* session) // if we want to use the arrow keys to select candidate strings if(config().cursorCandList && showingCandidates() && candidateWindow_) { // if the candidate window is open, let it handle the key first - if(candidateWindow_->filterKeyEvent(keyEvent)) { + if(candidateWindow_->filterKeyEvent(keyEvent.keyCode())) { // the user selected a string from the candidate list already if(candidateWindow_->hasResult()) { wchar_t selKey = candidateWindow_->currentSelKey(); @@ -475,11 +468,21 @@ bool TextService::onCommand(UINT id, CommandType type) { assert(chewingContext_); if(type == COMMAND_RIGHT_CLICK) { if(id == ID_MODE_ICON) { // Windows 8 IME mode icon - Ime::Window window; // TrackPopupMenu requires a window to work, so let's build a transient one. - window.create(HWND_DESKTOP, 0); + // TrackPopupMenu requires a window to work, so let's build a transient one. + winrt::com_ptr window; + CreateImeWindow(window.put_void()); + window->create(HWND_DESKTOP, 0); POINT pos = {0}; ::GetCursorPos(&pos); - UINT ret = ::TrackPopupMenu(popupMenu_, TPM_NONOTIFY|TPM_RETURNCMD|TPM_LEFTALIGN|TPM_BOTTOMALIGN, pos.x, pos.y, 0, window.hwnd(), NULL); + UINT ret = ::TrackPopupMenu( + popupMenu_, + TPM_NONOTIFY|TPM_RETURNCMD|TPM_LEFTALIGN|TPM_BOTTOMALIGN, + pos.x, + pos.y, + 0, + window->hwnd(), + NULL + ); if(ret > 0) onCommand(ret, COMMAND_MENU); } @@ -708,17 +711,11 @@ void TextService::applyConfig() { chewing_config_set_int(chewingContext_, "chewing.conversion_engine", cfg.convEngine); } - // 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_); + if(messageWindow_) { + messageWindow_->setFontSize(cfg.fontSize); + } + if(candidateWindow_) { + candidateWindow_->setFontSize(cfg.fontSize); } } @@ -759,6 +756,7 @@ void TextService::updateCandidates(Ime::EditSession* session) { candidateWindow_->clear(); candidateWindow_->setUseCursor(config().cursorCandList); candidateWindow_->setCandPerRow(config().candPerRow); + candidateWindow_->setFontSize(config().fontSize); ::chewing_cand_Enumerate(chewingContext_); int* selKeys = ::chewing_get_selKey(chewingContext_); // keys used to select candidates @@ -768,7 +766,7 @@ void TextService::updateCandidates(Ime::EditSession* session) { char* str = ::chewing_cand_String(chewingContext_); std::wstring wstr = utf8ToUtf16(str); ::chewing_free(str); - candidateWindow_->add(wstr, (wchar_t)selKeys[i]); + candidateWindow_->add(wstr.c_str(), (wchar_t)selKeys[i]); } ::chewing_free(selKeys); candidateWindow_->recalculateSize(); @@ -796,8 +794,12 @@ void TextService::showCandidates(Ime::EditSession* session) { // The candidate window created should be a child window of the composition window. // Please see Ime::CandidateWindow::CandidateWindow() for an example. if(!candidateWindow_) { - candidateWindow_ = new Ime::CandidateWindow(this, session); - candidateWindow_->setFont(font_); + std::wstring bitmap_path = static_cast(imeModule())->programDir(); + bitmap_path += L"\\Assets\\bubble.9.png"; + HWND parent = this->compositionWindow(session); + candidateWindow_ = nullptr; + CreateCandidateWindow(parent, bitmap_path.c_str(), candidateWindow_.put_void()); + candidateWindow_->setFontSize(config().fontSize); } updateCandidates(session); candidateWindow_->show(); @@ -808,8 +810,7 @@ void TextService::showCandidates(Ime::EditSession* session) { void TextService::hideCandidates() { assert(candidateWindow_); if(candidateWindow_) { - candidateWindow_->Release(); - candidateWindow_ = NULL; + candidateWindow_ = nullptr; } showingCandidates_ = false; } @@ -819,9 +820,13 @@ void TextService::showMessage(Ime::EditSession* session, std::wstring message, i // remove previous message if there's any hideMessage(); // FIXME: reuse the window whenever possible - messageWindow_ = new Ime::MessageWindow(this, session); - messageWindow_->setFont(font_); - messageWindow_->setText(message); + HWND parent = this->compositionWindow(session); + messageWindow_ = nullptr; + std::wstring bitmap_path = static_cast(imeModule())->programDir(); + bitmap_path += L"\\Assets\\msg.9.png"; + CreateMessageWindow(parent, bitmap_path.c_str(), messageWindow_.put_void()); + messageWindow_->setFontSize(config().fontSize); + messageWindow_->setText(message.c_str()); int x = 0, y = 0; if(isComposing()) { @@ -834,7 +839,7 @@ void TextService::showMessage(Ime::EditSession* session, std::wstring message, i messageWindow_->move(x, y); messageWindow_->show(); - messageTimerId_ = ::SetTimer(messageWindow_->hwnd(), 1, duration * 1000, (TIMERPROC)TextService::onMessageTimeout); + messageTimerId_ = ::SetTimer(messageWindow_->hwnd(), 1, duration * 1000, nullptr); } void TextService::hideMessage() { @@ -843,27 +848,11 @@ void TextService::hideMessage() { messageTimerId_ = 0; } if(messageWindow_) { - delete messageWindow_; - messageWindow_ = NULL; + messageWindow_->destroy(); + messageWindow_ = nullptr; } } -// called when the message window timeout -void TextService::onMessageTimeout() { - hideMessage(); -} - -// static -void CALLBACK TextService::onMessageTimeout(HWND hwnd, UINT msg, UINT_PTR id, DWORD time) { - Ime::MessageWindow* messageWindow = (Ime::MessageWindow*)Ime::Window::fromHwnd(hwnd); - assert(messageWindow); - if(messageWindow) { - TextService* pThis = (Chewing::TextService*)messageWindow->textService(); - pThis->onMessageTimeout(); - } -} - - void TextService::updateLangButtons() { if(!chewingContext_) return; diff --git a/ChewingTextService/ChewingTextService.h b/ChewingTextService/ChewingTextService.h index a21ac81..b343b15 100644 --- a/ChewingTextService/ChewingTextService.h +++ b/ChewingTextService/ChewingTextService.h @@ -21,14 +21,17 @@ #define CHEWING_TEXT_SERVICE_H #include -#include -#include #include #include #include #include "ChewingImeModule.h" #include +#include +#include + +#include "libime2.h" + namespace Chewing { class TextService: public Ime::TextService { @@ -91,8 +94,6 @@ class TextService: public Ime::TextService { // message window void showMessage(Ime::EditSession* session, std::wstring message, int duration = 3); void hideMessage(); - void onMessageTimeout(); - static void CALLBACK onMessageTimeout(HWND hwnd, UINT msg, UINT_PTR id, DWORD time); void updateLangButtons(); // update status of language bar buttons @@ -108,11 +109,10 @@ class TextService: public Ime::TextService { private: ChewingContext* chewingContext_; - Ime::CandidateWindow* candidateWindow_; + winrt::com_ptr candidateWindow_; + winrt::com_ptr messageWindow_; bool showingCandidates_; - Ime::MessageWindow* messageWindow_; UINT messageTimerId_; - HFONT font_; Ime::LangBarButton* switchLangButton_; Ime::LangBarButton* switchShapeButton_; diff --git a/ChewingTextService/DllEntry.cpp b/ChewingTextService/DllEntry.cpp index b49c011..9eb0220 100644 --- a/ChewingTextService/DllEntry.cpp +++ b/ChewingTextService/DllEntry.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "ChewingImeModule.h" #include "ChewingConfig.h" #include "resource.h" @@ -47,7 +50,7 @@ STDAPI DllRegisterServer(void) { DWORD modulePathLen = GetModuleFileNameW(g_imeModule->hInstance(), modulePath, MAX_PATH); int iconIndex = 0; // use classic icon - if(g_imeModule->isWindows8Above()) + if(IsWindows8OrGreater()) iconIndex = 1; // use Windows 8 style IME icon Ime::LangProfileInfo info; @@ -63,7 +66,7 @@ STDAPI DllRegisterServer(void) { STDAPI ChewingSetup() { // The directory is already created when the ImeModule object is constructed. - if(g_imeModule->isWindows8Above()) { + if(IsWindows8OrGreater()) { // Grant permission to app containers Chewing::Config::grantAppContainerAccess(g_imeModule->userDir().c_str(), SE_FILE_OBJECT, GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE|DELETE); } diff --git a/ChewingTextService/resource.h b/ChewingTextService/resource.h index add8f47..945f7b7 100644 Binary files a/ChewingTextService/resource.h and b/ChewingTextService/resource.h differ diff --git a/assets/bubble.9.png b/assets/bubble.9.png new file mode 100644 index 0000000..1eafe2b Binary files /dev/null and b/assets/bubble.9.png differ diff --git a/assets/msg.9.png b/assets/msg.9.png new file mode 100644 index 0000000..392fb86 Binary files /dev/null and b/assets/msg.9.png differ diff --git a/installer/lgpl-2.1.rtf b/installer/lgpl-2.1.rtf index 3468f2e..b5aaa9e 100644 --- a/installer/lgpl-2.1.rtf +++ b/installer/lgpl-2.1.rtf @@ -1,251 +1,95 @@ -{\rtf1\ansi\deff3\adeflang1025 -{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fswiss\fprq2\fcharset0 Arial;}{\f3\froman\fprq2\fcharset0 Liberation Serif{\*\falt Times New Roman};}{\f4\froman\fprq0\fcharset128 Helvetica{\*\falt Arial};}{\f5\froman\fprq0\fcharset128 Courier{\*\falt Courier New};}{\f6\froman\fprq0\fcharset128 Liberation Serif{\*\falt Times New Roman};}{\f7\fswiss\fprq0\fcharset128 Liberation Sans{\*\falt Arial};}{\f8\fnil\fprq0\fcharset128 FreeSans;}{\f9\fnil\fprq2\fcharset0 FreeSans;}{\f10\fswiss\fprq0\fcharset128 FreeSans;}{\f11\fnil\fprq2\fcharset0 Liberation Serif{\*\falt Times New Roman};}} -{\colortbl;\red0\green0\blue0;\red128\green128\blue128;} -{\stylesheet{\s0\snext0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033 Normal;} -{\s15\sbasedon0\snext16\ql\nowidctlpar\sb240\sa120\keepn\ltrpar\cf1\kerning1\dbch\af8\langfe2052\dbch\af9\afs28\alang1081\loch\f7\fs28\lang1033 Heading;} -{\s16\sbasedon0\snext16\sl288\slmult1\ql\nowidctlpar\sb0\sa140\ltrpar\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033 Text Body;} -{\s17\sbasedon16\snext17\sl288\slmult1\ql\nowidctlpar\sb0\sa140\ltrpar\cf1\kerning1\dbch\af8\langfe2052\dbch\af10\afs24\alang1081\loch\f6\fs24\lang1033 List;} -{\s18\sbasedon0\snext18\ql\nowidctlpar\sb120\sa120\noline\ltrpar\cf1\i\kerning1\dbch\af8\langfe2052\dbch\af10\afs24\alang1081\ai\loch\f6\fs24\lang1033 Caption;} -{\s19\sbasedon0\snext19\ql\nowidctlpar\noline\ltrpar\cf1\kerning1\dbch\af8\langfe2052\dbch\af10\afs24\alang1081\loch\f6\fs24\lang1033 Index;} -}{\info{\creatim\yr0\mo0\dy0\hr0\min0}{\revtim\yr0\mo0\dy0\hr0\min0}{\printim\yr0\mo0\dy0\hr0\min0}{\comment LibreOffice}{\vern67241986}}\deftab720 -\viewscale100 -{\*\pgdsctbl -{\pgdsc0\pgdscuse451\pgwsxn12240\pghsxn15840\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\pgdscnxt0 Default Style;}} -\formshade{\*\pgdscno0}\paperh15840\paperw12240\margl1800\margr1800\margt1440\margb1440\sectd\sbknone\sectunlocked1\pgndec\pgwsxn12240\pghsxn15840\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc -\pgndec\pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\ul\ulc1\b\rtlch \ltrch\loch\fs28\loch\f4 -GNU LESSER GENERAL PUBLIC LICENSE} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Version 2.1, February 1999} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f5 -Copyright (C) 1991, 1999 Free Software Foundation, Inc.}{\rtlch \ltrch\loch -\line }{\cf1\rtlch \ltrch\loch\loch\f5 -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f5 -Everyone is permitted to copy and distribute verbatim copies}{\rtlch \ltrch\loch -\line }{\cf1\rtlch \ltrch\loch\loch\f5 -of this license document, but changing it is not allowed.}{\rtlch \ltrch\loch -\line \line }{\cf1\rtlch \ltrch\loch\loch\f5 -[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.]} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\ul\ulc1\b\rtlch \ltrch\loch\fs28\loch\f4 -Preamble} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\ul\ulc1\b\rtlch \ltrch\loch\fs28\loch\f4 -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -0.}{\cf1\rtlch \ltrch\loch\loch\f4 - This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -1.}{\cf1\rtlch \ltrch\loch\loch\f4 - You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -2.}{\cf1\rtlch \ltrch\loch\loch\f4 - You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -a)}{\cf1\rtlch \ltrch\loch\loch\f4 - The modified work must itself be a software library.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -b)}{\cf1\rtlch \ltrch\loch\loch\f4 - You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -c)}{\cf1\rtlch \ltrch\loch\loch\f4 - You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa180{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -d)}{\cf1\rtlch \ltrch\loch\loch\f4 - If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -3.}{\cf1\rtlch \ltrch\loch\loch\f4 - You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -This option is useful when you wish to copy part of the code of the Library into a program that is not a library.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -4.}{\cf1\rtlch \ltrch\loch\loch\f4 - You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -5.}{\cf1\rtlch \ltrch\loch\loch\f4 - A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -6.}{\cf1\rtlch \ltrch\loch\loch\f4 - As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -a)}{\cf1\rtlch \ltrch\loch\loch\f4 - Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -b)}{\cf1\rtlch \ltrch\loch\loch\f4 - Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -c)}{\cf1\rtlch \ltrch\loch\loch\f4 - Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -d)}{\cf1\rtlch \ltrch\loch\loch\f4 - If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -e)}{\cf1\rtlch \ltrch\loch\loch\f4 - Verify that the user has already received a copy of these materials or that you have already sent this user a copy.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -7.}{\cf1\rtlch \ltrch\loch\loch\f4 - You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -a)}{\cf1\rtlch \ltrch\loch\loch\f4 - Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li360\ri0\lin360\rin0\fi-360\sb0\sa0{\cf1\rtlch \ltrch\loch\f4 -\u8226\'3f}{\cf1\rtlch \ltrch\loch\loch\f4 -\tab }{\cf1\b\rtlch \ltrch\loch\loch\f4 -b)}{\cf1\rtlch \ltrch\loch\loch\f4 - Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -8.}{\cf1\rtlch \ltrch\loch\loch\f4 - You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -9.}{\cf1\rtlch \ltrch\loch\loch\f4 - You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -10.}{\cf1\rtlch \ltrch\loch\loch\f4 - Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -11.}{\cf1\rtlch \ltrch\loch\loch\f4 - If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -12.}{\cf1\rtlch \ltrch\loch\loch\f4 - If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -13.}{\cf1\rtlch \ltrch\loch\loch\f4 - The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -14.}{\cf1\rtlch \ltrch\loch\loch\f4 - If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -NO WARRANTY} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -15.}{\cf1\rtlch \ltrch\loch\loch\f4 - BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\loch\f4 -16.}{\cf1\rtlch \ltrch\loch\loch\f4 - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\b\rtlch \ltrch\loch\fs28\loch\f4 -END OF TERMS AND CONDITIONS} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\ul\ulc1\b\rtlch \ltrch\loch\fs28\loch\f4 -How to Apply These Terms to Your New Libraries} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License).} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f5 -one line to give the library's name and an idea of what it does.}{\rtlch \ltrch\loch -\line }{\cf1\rtlch \ltrch\loch\loch\f5 -Copyright (C) year name of author}{\rtlch \ltrch\loch -\line \line }{\cf1\rtlch \ltrch\loch\loch\f5 -This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.}{\rtlch \ltrch\loch -\line \line }{\cf1\rtlch \ltrch\loch\loch\f5 -This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.}{\rtlch \ltrch\loch -\line \line }{\cf1\rtlch \ltrch\loch\loch\f5 -You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -Also add information on how to contact you by electronic and paper mail.} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names:} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f5 -Yoyodyne, Inc., hereby disclaims all copyright interest in}{\rtlch \ltrch\loch -\line }{\cf1\rtlch \ltrch\loch\loch\f5 -the library `Frob' (a library for tweaking knobs) written}{\rtlch \ltrch\loch -\line }{\cf1\rtlch \ltrch\loch\loch\f5 -by James Random Hacker.}{\rtlch \ltrch\loch -\line \line }{\cf1\rtlch \ltrch\loch\loch\f5 -signature of Ty Coon, 1 April 1990}{\rtlch \ltrch\loch -\line }{\cf1\rtlch \ltrch\loch\loch\f5 -Ty Coon, President of Vice} -\par \pard\plain \s0\ql\nowidctlpar\ltrpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf1\kerning1\dbch\af8\langfe2052\dbch\af11\afs24\alang1081\loch\f6\fs24\lang1033\ql\li0\ri0\lin0\rin0\fi0\sb0\sa180{\cf1\rtlch \ltrch\loch\loch\f4 -That's all there is to it!} -\par } \ No newline at end of file +{\rtf1\ansi\ansicpg1252\deff0\nouicompat{\fonttbl{\f0\froman\fcharset128 Helvetica;}{\f1\froman\fcharset128 Liberation Serif;}{\f2\froman\fcharset128 Courier;}} +{\colortbl ;\red0\green0\blue0;} +{\*\generator Riched20 10.0.22621}\viewkind4\uc1 +\pard\nowidctlpar\sa180\cf1\ulc1\kerning1\ul\b\f0\fs28\lang1033 GNU LESSER GENERAL PUBLIC LICENSE\ulnone\b0\f1\fs24\par +\f0 Version 2.1, February 1999\f1\par +\f2 Copyright (C) 1991, 1999 Free Software Foundation, Inc.\f1\line\f2 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\f1\par +\f2 Everyone is permitted to copy and distribute verbatim copies\f1\line\f2 of this license document, but changing it is not allowed.\f1\line\line\f2 [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.]\f1\par +\ulc1\ul\b\f0\fs28 Preamble\ulnone\b0\f1\fs24\par +\f0 The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.\f1\par +\f0 This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.\f1\par +\f0 When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.\f1\par +\f0 To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.\f1\par +\f0 For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.\f1\par +\f0 We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.\f1\par +\f0 To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.\f1\par +\f0 Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.\f1\par +\f0 Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.\f1\par +\f0 When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.\f1\par +\f0 We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.\f1\par +\f0 For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.\f1\par +\f0 In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.\f1\par +\f0 Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.\f1\par +\f0 The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.\f1\par +\ulc1\ul\b\f0\fs28 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\ulnone\b0\f1\fs24\par +\b\f0 0.\b0 This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".\f1\par +\f0 A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.\f1\par +\f0 The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)\f1\par +\f0 "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.\f1\par +\f0 Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.\f1\par +\b\f0 1.\b0 You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.\f1\par +\f0 You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.\f1\par +\b\f0 2.\b0 You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:\f1\par + +\pard\nowidctlpar\fi-360\li360\f0\bullet\tab\b a)\b0 The modified work must itself be a software library.\f1\par +\f0\bullet\tab\b b)\b0 You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.\f1\par +\f0\bullet\tab\b c)\b0 You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.\f1\par + +\pard\nowidctlpar\fi-360\li360\sa180\f0\bullet\tab\b d)\b0 If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.\f1\par + +\pard\nowidctlpar\li360\sa180\f0 (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)\f1\par + +\pard\nowidctlpar\sa180\f0 These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.\f1\par +\f0 Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.\f1\par +\f0 In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.\f1\par +\b\f0 3.\b0 You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.\f1\par +\f0 Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.\f1\par +\f0 This option is useful when you wish to copy part of the code of the Library into a program that is not a library.\f1\par +\b\f0 4.\b0 You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.\f1\par +\f0 If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.\f1\par +\b\f0 5.\b0 A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.\f1\par +\f0 However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.\f1\par +\f0 When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.\f1\par +\f0 If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)\f1\par +\f0 Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.\f1\par +\b\f0 6.\b0 As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.\f1\par +\f0 You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:\f1\par + +\pard\nowidctlpar\fi-360\li360\f0\bullet\tab\b a)\b0 Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)\f1\par +\f0\bullet\tab\b b)\b0 Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.\f1\par +\f0\bullet\tab\b c)\b0 Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.\f1\par +\f0\bullet\tab\b d)\b0 If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.\f1\par +\f0\bullet\tab\b e)\b0 Verify that the user has already received a copy of these materials or that you have already sent this user a copy.\f1\par + +\pard\nowidctlpar\sa180\f0 For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.\f1\par +\f0 It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.\f1\par +\b\f0 7.\b0 You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:\f1\par + +\pard\nowidctlpar\fi-360\li360\f0\bullet\tab\b a)\b0 Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.\f1\par +\f0\bullet\tab\b b)\b0 Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.\f1\par + +\pard\nowidctlpar\sa180\b\f0 8.\b0 You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.\f1\par +\b\f0 9.\b0 You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.\f1\par +\b\f0 10.\b0 Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.\f1\par +\b\f0 11.\b0 If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.\f1\par +\f0 If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.\f1\par +\f0 It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.\f1\par +\f0 This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.\f1\par +\b\f0 12.\b0 If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.\f1\par +\b\f0 13.\b0 The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.\f1\par +\f0 Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.\f1\par +\b\f0 14.\b0 If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.\f1\par +\b\f0 NO WARRANTY\b0\f1\par +\b\f0 15.\b0 BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\f1\par +\b\f0 16.\b0 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\f1\par +\b\f0\fs28 END OF TERMS AND CONDITIONS\b0\f1\fs24\par +\ulc1\ul\b\f0\fs28 How to Apply These Terms to Your New Libraries\ulnone\b0\f1\fs24\par +\f0 If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License).\f1\par +\f0 To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.\f1\par +\f2 one line to give the library's name and an idea of what it does.\f1\line\f2 Copyright (C) year name of author\f1\line\line\f2 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.\f1\line\line\f2 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.\f1\line\line\f2 You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\f1\par +\f0 Also add information on how to contact you by electronic and paper mail.\f1\par +\f0 You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names:\f1\par +\f2 Yoyodyne, Inc., hereby disclaims all copyright interest in\f1\line\f2 the library `Frob' (a library for tweaking knobs) written\f1\line\f2 by James Random Hacker.\f1\line\line\f2 signature of Ty Coon, 1 April 1990\f1\line\f2 Ty Coon, President of Vice\f1\par +\f0 That's all there is to it!\f1\par +} + \ No newline at end of file diff --git a/installer/windows-chewing-tsf.wxs b/installer/windows-chewing-tsf.wxs index e7151cf..1d69daf 100644 --- a/installer/windows-chewing-tsf.wxs +++ b/installer/windows-chewing-tsf.wxs @@ -19,6 +19,10 @@ + + + + diff --git a/libIME/CMakeLists.txt b/libIME/CMakeLists.txt index 3252432..7a1c8ea 100644 --- a/libIME/CMakeLists.txt +++ b/libIME/CMakeLists.txt @@ -1,42 +1,71 @@ -project(libIME) +find_package(Corrosion QUIET) +if(NOT Corrosion_FOUND) + FetchContent_Declare( + Corrosion + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git + GIT_TAG 64289b1d79d6d19cd2e241db515381a086bb8407 # v0.5 + FIND_PACKAGE_ARGS + ) + FetchContent_MakeAvailable(Corrosion) +endif() + +corrosion_import_crate(MANIFEST_PATH Cargo.toml CRATES libime2 CRATE_TYPES staticlib) +corrosion_add_target_rustflags(libime2 "-C target-feature=+crt-static") + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC") + corrosion_set_env_vars(libime2 "CFLAGS=-EHsc" "CXXFLAGS=-EHsc") +endif() + +find_program(MIDL midl) +add_custom_command( + OUTPUT + dlldata.c + libime2.h + libime2_i.c + libime2_p.c + COMMAND MIDL ${CMAKE_CURRENT_SOURCE_DIR}/idl/libime2.idl + MAIN_DEPENDENCY idl/libime2.idl +) add_library(libIME_static STATIC # Core TSF part - ${PROJECT_SOURCE_DIR}/ImeModule.cpp - ${PROJECT_SOURCE_DIR}/ImeModule.h - ${PROJECT_SOURCE_DIR}/libIME.cpp - ${PROJECT_SOURCE_DIR}/libIME.h - ${PROJECT_SOURCE_DIR}/TextService.cpp - ${PROJECT_SOURCE_DIR}/TextService.h - ${PROJECT_SOURCE_DIR}/KeyEvent.cpp - ${PROJECT_SOURCE_DIR}/KeyEvent.h - ${PROJECT_SOURCE_DIR}/EditSession.cpp - ${PROJECT_SOURCE_DIR}/EditSession.h - ${PROJECT_SOURCE_DIR}/DisplayAttributeInfo.cpp - ${PROJECT_SOURCE_DIR}/DisplayAttributeInfo.h - ${PROJECT_SOURCE_DIR}/DisplayAttributeInfoEnum.cpp - ${PROJECT_SOURCE_DIR}/DisplayAttributeInfoEnum.h - ${PROJECT_SOURCE_DIR}/DisplayAttributeProvider.cpp - ${PROJECT_SOURCE_DIR}/DisplayAttributeProvider.h - ${PROJECT_SOURCE_DIR}/LangBarButton.cpp - ${PROJECT_SOURCE_DIR}/LangBarButton.h - ${PROJECT_SOURCE_DIR}/Utils.cpp - ${PROJECT_SOURCE_DIR}/Utils.h - ${PROJECT_SOURCE_DIR}/ComPtr.h - ${PROJECT_SOURCE_DIR}/WindowsVersion.h - # GUI-related code - ${PROJECT_SOURCE_DIR}/DrawUtils.h - ${PROJECT_SOURCE_DIR}/DrawUtils.cpp - ${PROJECT_SOURCE_DIR}/Window.cpp - ${PROJECT_SOURCE_DIR}/Window.h - ${PROJECT_SOURCE_DIR}/ImeWindow.cpp - ${PROJECT_SOURCE_DIR}/ImeWindow.h - ${PROJECT_SOURCE_DIR}/MessageWindow.cpp - ${PROJECT_SOURCE_DIR}/MessageWindow.h - ${PROJECT_SOURCE_DIR}/CandidateWindow.h - ${PROJECT_SOURCE_DIR}/CandidateWindow.cpp + ImeModule.cpp + ImeModule.h + libIME.cpp + libIME.h + TextService.cpp + TextService.h + KeyEvent.cpp + KeyEvent.h + EditSession.cpp + EditSession.h + DisplayAttributeInfo.cpp + DisplayAttributeInfo.h + DisplayAttributeInfoEnum.cpp + DisplayAttributeInfoEnum.h + DisplayAttributeProvider.cpp + DisplayAttributeProvider.h + LangBarButton.cpp + LangBarButton.h + Utils.cpp + Utils.h + # Rust interop + dlldata.c + libime2.h + libime2_i.c + libime2_p.c ) +target_include_directories(libIME_static PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + target_link_libraries(libIME_static - shlwapi.lib -) + PUBLIC libime2 + PUBLIC shlwapi.lib + PUBLIC d2d1.lib + PUBLIC d3d11.lib + PUBLIC dwrite.lib + PUBLIC dcomp.lib + + PUBLIC Propsys.lib + PUBLIC RuntimeObject.lib +) \ No newline at end of file diff --git a/libIME/CandidateWindow.cpp b/libIME/CandidateWindow.cpp deleted file mode 100644 index b472a6c..0000000 --- a/libIME/CandidateWindow.cpp +++ /dev/null @@ -1,434 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#include "CandidateWindow.h" -#include "DrawUtils.h" -#include "TextService.h" -#include "EditSession.h" - -#include -#include - -#include -#include - -using namespace std; - -namespace Ime { - -CandidateWindow::CandidateWindow(TextService* service, EditSession* session): - ImeWindow(service), - refCount_(1), - shown_(false), - candPerRow_(1), - textWidth_(0), - itemHeight_(0), - currentSel_(0), - hasResult_(false), - useCursor_(true), - selKeyWidth_(0) { - - if(service->isImmersive()) { // windows 8 app mode - margin_ = 10; - rowSpacing_ = 8; - colSpacing_ = 12; - } - else { // desktop mode - margin_ = 5; - rowSpacing_ = 4; - colSpacing_ = 8; - } - - HWND parent = service->compositionWindow(session); - create(parent, WS_POPUP|WS_CLIPCHILDREN, WS_EX_TOOLWINDOW|WS_EX_TOPMOST); -} - -CandidateWindow::~CandidateWindow(void) { -} - -// IUnknown -STDMETHODIMP CandidateWindow::QueryInterface(REFIID riid, void **ppvObj) { - if (!ppvObj) - return E_INVALIDARG; - - if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfCandidateListUIElement)) { - *ppvObj = (ITfCandidateListUIElement*)this; - } - else { - *ppvObj = NULL; - } - - if (!*ppvObj) { - return E_NOINTERFACE; - } - - AddRef(); - return S_OK; -} - -STDMETHODIMP_(ULONG) CandidateWindow::AddRef(void) { - return ++refCount_; -} - -STDMETHODIMP_(ULONG) CandidateWindow::Release(void) { - assert(refCount_ > 0); - const ULONG newCount = --refCount_; - if (refCount_ == 0) - delete this; - return newCount; -} - -// ITfUIElement -STDMETHODIMP CandidateWindow::GetDescription(BSTR *pbstrDescription) { - if (!pbstrDescription) - return E_INVALIDARG; - *pbstrDescription = SysAllocString(L"Candidate window~"); - return S_OK; -} - -// {BD7CCC94-57CD-41D3-A789-AF47890CEB29} -STDMETHODIMP CandidateWindow::GetGUID(GUID *pguid) { - if (!pguid) - return E_INVALIDARG; - *pguid = { 0xbd7ccc94, 0x57cd, 0x41d3, { 0xa7, 0x89, 0xaf, 0x47, 0x89, 0xc, 0xeb, 0x29 } }; - return S_OK; -} - -STDMETHODIMP CandidateWindow::Show(BOOL bShow) { - shown_ = bShow; - if (shown_) - show(); - else - hide(); - return S_OK; -} - -STDMETHODIMP CandidateWindow::IsShown(BOOL *pbShow) { - if (!pbShow) - return E_INVALIDARG; - *pbShow = shown_; - return S_OK; -} - -// ITfCandidateListUIElement -STDMETHODIMP CandidateWindow::GetUpdatedFlags(DWORD *pdwFlags) { - if (!pdwFlags) - return E_INVALIDARG; - /// XXX update all!!! - *pdwFlags = TF_CLUIE_DOCUMENTMGR | TF_CLUIE_COUNT | TF_CLUIE_SELECTION | TF_CLUIE_STRING | TF_CLUIE_PAGEINDEX | TF_CLUIE_CURRENTPAGE; - return S_OK; -} - -STDMETHODIMP CandidateWindow::GetDocumentMgr(ITfDocumentMgr **ppdim) { - if (!textService_) - return E_FAIL; - return textService_->currentContext()->GetDocumentMgr(ppdim); -} - -STDMETHODIMP CandidateWindow::GetCount(UINT *puCount) { - if (!puCount) - return E_INVALIDARG; - *puCount = std::min(10, items_.size()); - return S_OK; -} - -STDMETHODIMP CandidateWindow::GetSelection(UINT *puIndex) { - assert(currentSel_ >= 0); - if (!puIndex) - return E_INVALIDARG; - *puIndex = static_cast(currentSel_); - return S_OK; -} - -STDMETHODIMP CandidateWindow::GetString(UINT uIndex, BSTR *pbstr) { - if (!pbstr) - return E_INVALIDARG; - if (uIndex >= items_.size()) - return E_INVALIDARG; - *pbstr = SysAllocString(items_[uIndex].c_str()); - return S_OK; -} - -STDMETHODIMP CandidateWindow::GetPageIndex(UINT *puIndex, UINT uSize, UINT *puPageCnt) { - /// XXX Always return the same single page index. - if (!puPageCnt) - return E_INVALIDARG; - *puPageCnt = 1; - if (puIndex) { - if (uSize < *puPageCnt) { - return E_INVALIDARG; - } - puIndex[0] = 0; - } - return S_OK; -} - -STDMETHODIMP CandidateWindow::SetPageIndex(UINT *puIndex, UINT uPageCnt) { - /// XXX Do not let app set page indices. - if (!puIndex) - return E_INVALIDARG; - return S_OK; -} - -STDMETHODIMP CandidateWindow::GetCurrentPage(UINT *puPage) { - if (!puPage) - return E_INVALIDARG; - *puPage = 0; - return S_OK; -} - -LRESULT CandidateWindow::wndProc(UINT msg, WPARAM wp , LPARAM lp) { - switch (msg) { - case WM_PAINT: - onPaint(wp, lp); - break; - case WM_ERASEBKGND: - return TRUE; - break; - case WM_LBUTTONDOWN: - onLButtonDown(wp, lp); - break; - case WM_MOUSEMOVE: - onMouseMove(wp, lp); - break; - case WM_LBUTTONUP: - onLButtonUp(wp, lp); - break; - case WM_MOUSEACTIVATE: - return MA_NOACTIVATE; - default: - return Window::wndProc(msg, wp, lp); - } - return 0; -} - -void CandidateWindow::onPaint(WPARAM wp, LPARAM lp) { - // TODO: check isImmersive_, and draw the window differently - // in Windows 8 app immersive mode to follow windows 8 UX guidelines - PAINTSTRUCT ps; - BeginPaint(hwnd_, &ps); - HDC hDC = ps.hdc; - HFONT oldFont; - RECT rc; - - oldFont = (HFONT)SelectObject(hDC, font_); - - GetClientRect(hwnd_,&rc); - SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); - SetBkColor(hDC, GetSysColor(COLOR_WINDOW)); - - // paint window background and border - // draw a flat black border in Windows 8 app immersive mode - // draw a 3d border in desktop mode - if(isImmersive()) { - HPEN pen = ::CreatePen(PS_SOLID, 3, RGB(0, 0, 0)); - HGDIOBJ oldPen = ::SelectObject(hDC, pen); - ::Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); - ::SelectObject(hDC, oldPen); - ::DeleteObject(pen); - } - else { - // draw a 3d border in desktop mode - ::FillSolidRect(ps.hdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, GetSysColor(COLOR_WINDOW)); - ::Draw3DBorder(hDC, &rc, GetSysColor(COLOR_3DFACE), 0); - } - - // paint items - int col = 0; - int x = margin_, y = margin_; - for(int i = 0, n = items_.size(); i < n; ++i) { - paintItem(hDC, i, x, y); - ++col; // go to next column - if(col >= candPerRow_) { - col = 0; - x = margin_; - y += itemHeight_ + rowSpacing_; - } - else { - x += colSpacing_ + selKeyWidth_ + textWidth_; - } - } - SelectObject(hDC, oldFont); - EndPaint(hwnd_, &ps); -} - -void CandidateWindow::recalculateSize() { - if(items_.empty()) { - resize(margin_ * 2, margin_ * 2); - } - - HDC hDC = ::GetWindowDC(hwnd()); - int height = 0; - int width = 0; - selKeyWidth_ = 0; - textWidth_ = 0; - itemHeight_ = 0; - - HGDIOBJ oldFont = ::SelectObject(hDC, font_); - vector::const_iterator it; - for(int i = 0, n = items_.size(); i < n; ++i) { - SIZE selKeySize; - int lineHeight = 0; - // the selection key string - wchar_t selKey[] = L"?. "; - selKey[0] = selKeys_[i]; - ::GetTextExtentPoint32W(hDC, selKey, 3, &selKeySize); - if(selKeySize.cx > selKeyWidth_) - selKeyWidth_ = selKeySize.cx; - - // the candidate string - SIZE candidateSize; - wstring& item = items_.at(i); - ::GetTextExtentPoint32W(hDC, item.c_str(), item.length(), &candidateSize); - if(candidateSize.cx > textWidth_) - textWidth_ = candidateSize.cx; - int itemHeight = max(candidateSize.cy, selKeySize.cy); - if(itemHeight > itemHeight_) - itemHeight_ = itemHeight; - } - ::SelectObject(hDC, oldFont); - ::ReleaseDC(hwnd(), hDC); - - if(items_.size() <= candPerRow_) { - width = items_.size() * (selKeyWidth_ + textWidth_); - width += colSpacing_ * (items_.size() - 1); - width += margin_ * 2; - height = itemHeight_ + margin_ * 2; - } - else { - width = candPerRow_ * (selKeyWidth_ + textWidth_); - width += colSpacing_ * (candPerRow_ - 1); - width += margin_ * 2; - int rowCount = items_.size() / candPerRow_; - if(items_.size() % candPerRow_) - ++rowCount; - height = itemHeight_ * rowCount + rowSpacing_ * (rowCount - 1) + margin_ * 2; - } - resize(width, height); -} - -void CandidateWindow::setCandPerRow(int n) { - if(n != candPerRow_) { - candPerRow_ = n; - recalculateSize(); - } -} - -bool CandidateWindow::filterKeyEvent(KeyEvent& keyEvent) { - // select item with arrow keys - int oldSel = currentSel_; - switch(keyEvent.keyCode()) { - case VK_UP: - if(currentSel_ - candPerRow_ >=0) - currentSel_ -= candPerRow_; - break; - case VK_DOWN: - if(currentSel_ + candPerRow_ < items_.size()) - currentSel_ += candPerRow_; - break; - case VK_LEFT: - if(currentSel_ - 1 >=0) - --currentSel_; - break; - case VK_RIGHT: - if(currentSel_ + 1 < items_.size()) - ++currentSel_; - break; - case VK_RETURN: - hasResult_ = true; - return true; - default: - return false; - } - // if currently selected item is changed, redraw - if(currentSel_ != oldSel) { - // repaint the old and new items - RECT rect; - itemRect(oldSel, rect); - ::InvalidateRect(hwnd_, &rect, TRUE); - itemRect(currentSel_, rect); - ::InvalidateRect(hwnd_, &rect, TRUE); - return true; - } - return false; -} - -void CandidateWindow::setCurrentSel(int sel) { - if(sel >= items_.size()) - sel = 0; - if (currentSel_ != sel) { - currentSel_ = sel; - if (isVisible()) - ::InvalidateRect(hwnd_, NULL, TRUE); - } -} - -void CandidateWindow::clear() { - items_.clear(); - selKeys_.clear(); - currentSel_ = 0; - hasResult_ = false; -} - -void CandidateWindow::setUseCursor(bool use) { - useCursor_ = use; - if(isVisible()) - ::InvalidateRect(hwnd_, NULL, TRUE); -} - -void CandidateWindow::paintItem(HDC hDC, int i, int x, int y) { - RECT textRect = {x, y, 0, y + itemHeight_}; - wchar_t selKey[] = L"?. "; - selKey[0] = selKeys_[i]; - textRect.right = textRect.left + selKeyWidth_; - // FIXME: make the color of strings configurable. - COLORREF selKeyColor = RGB(0, 0, 255); - COLORREF oldColor = ::SetTextColor(hDC, selKeyColor); - // paint the selection key - ::ExtTextOut(hDC, textRect.left, textRect.top, ETO_OPAQUE, &textRect, selKey, 3, NULL); - ::SetTextColor(hDC, oldColor); // restore text color - - // paint the candidate string - wstring& item = items_.at(i); - textRect.left += selKeyWidth_; - textRect.right = textRect.left + textWidth_; - // paint the candidate string - ::ExtTextOut(hDC, textRect.left, textRect.top, ETO_OPAQUE, &textRect, item.c_str(), item.length(), NULL); - - if(useCursor_ && i == currentSel_) { // invert the selected item - int left = textRect.left; // - selKeyWidth_; - int top = textRect.top; - int width = textRect.right - left; - int height = itemHeight_; - ::BitBlt(hDC, left, top, width, itemHeight_, hDC, left, top, NOTSRCCOPY); - } -} - -void CandidateWindow::itemRect(int i, RECT& rect) { - int row, col; - row = i / candPerRow_; - col = i % candPerRow_; - rect.left = margin_ + col * (selKeyWidth_ + textWidth_ + colSpacing_); - rect.top = margin_ + row * (itemHeight_ + rowSpacing_); - rect.right = rect.left + (selKeyWidth_ + textWidth_); - rect.bottom = rect.top + itemHeight_; -} - - -} // namespace Ime diff --git a/libIME/CandidateWindow.h b/libIME/CandidateWindow.h deleted file mode 100644 index cbcf128..0000000 --- a/libIME/CandidateWindow.h +++ /dev/null @@ -1,135 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#ifndef IME_CANDIDATE_WINDOW_H -#define IME_CANDIDATE_WINDOW_H - -#include "ImeWindow.h" -#include -#include - -namespace Ime { - -class TextService; -class EditSession; -class KeyEvent; - -// TODO: make the candidate window looks different in immersive mode -class CandidateWindow : - public ImeWindow, - public ITfCandidateListUIElement { -public: - CandidateWindow(TextService* service, EditSession* session); - - // IUnknown - STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj); - STDMETHODIMP_(ULONG) AddRef(void); - STDMETHODIMP_(ULONG) Release(void); - - // ITfUIElement - STDMETHODIMP GetDescription(BSTR *pbstrDescription); - STDMETHODIMP GetGUID(GUID *pguid); - STDMETHODIMP Show(BOOL bShow); - STDMETHODIMP IsShown(BOOL *pbShow); - - // ITfCandidateListUIElement - STDMETHODIMP GetUpdatedFlags(DWORD *pdwFlags); - STDMETHODIMP GetDocumentMgr(ITfDocumentMgr **ppdim); - STDMETHODIMP GetCount(UINT *puCount); - STDMETHODIMP GetSelection(UINT *puIndex); - STDMETHODIMP GetString(UINT uIndex, BSTR *pstr); - STDMETHODIMP GetPageIndex(UINT *puIndex, UINT uSize, UINT *puPageCnt); - STDMETHODIMP SetPageIndex(UINT *puIndex, UINT uPageCnt); - STDMETHODIMP GetCurrentPage(UINT *puPage); - - const std::vector& items() const { - return items_; - } - - void setItems(const std::vector& items, const std::vector& sekKeys) { - items_ = items; - selKeys_ = selKeys_; - recalculateSize(); - refresh(); - } - - void add(std::wstring item, wchar_t selKey) { - items_.push_back(item); - selKeys_.push_back(selKey); - } - - void clear(); - - int candPerRow() const { - return candPerRow_; - } - void setCandPerRow(int n); - - virtual void recalculateSize(); - - bool filterKeyEvent(KeyEvent& keyEvent); - - int currentSel() const { - return currentSel_; - } - void setCurrentSel(int sel); - - wchar_t currentSelKey() const { - return selKeys_.at(currentSel_); - } - - bool hasResult() const { - return hasResult_; - } - - bool useCursor() const { - return useCursor_; - } - - void setUseCursor(bool use); - -protected: - LRESULT wndProc(UINT msg, WPARAM wp , LPARAM lp); - void onPaint(WPARAM wp, LPARAM lp); - void paintItem(HDC hDC, int i, int x, int y); - void itemRect(int i, RECT& rect); - -protected: // COM object should not be deleted directly. calling Release() instead. - ~CandidateWindow(void); - -private: - ULONG refCount_; - BOOL shown_; - - int selKeyWidth_; - int textWidth_; - int itemHeight_; - int candPerRow_; - int colSpacing_; - int rowSpacing_; - std::vector selKeys_; - std::vector items_; - int currentSel_; - bool hasResult_; - bool useCursor_; -}; - -} - -#endif diff --git a/libIME/Cargo.lock b/libIME/Cargo.lock new file mode 100644 index 0000000..940a43b --- /dev/null +++ b/libIME/Cargo.lock @@ -0,0 +1,198 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "libime2" +version = "0.1.0" +dependencies = [ + "log", + "nine_patch_drawable", + "win_dbg_logger", + "windows", + "windows-core", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "nine_patch_drawable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96e2f356f3fbb4179ee2a3d76ed2881553b93213a421a28975b2ea0c8d81d15" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "win_dbg_logger" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d1b4c22244dc27534d81e2f6fc3efd6b20e50c010f177efc20b719ec759a779" +dependencies = [ + "log", +] + +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core", + "windows-targets", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/libIME/Cargo.toml b/libIME/Cargo.toml new file mode 100644 index 0000000..e5e1d9e --- /dev/null +++ b/libIME/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "libime2" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["staticlib"] + +[dependencies] +log = "0.4.22" +nine_patch_drawable = "0.1.0" +win_dbg_logger = "0.1.0" +windows-core = "0.58.0" +windows = { version = "0.58.0", features = [ + "implement", + "Foundation_Numerics", + "Win32_Graphics_Direct2D_Common", + "Win32_Graphics_Direct2D", + "Win32_Graphics_Direct3D", + "Win32_Graphics_Direct3D11", + "Win32_Graphics_DirectComposition", + "Win32_Graphics_DirectWrite", + "Win32_Graphics_Dxgi_Common", + "Win32_Graphics_Dxgi", + "Win32_Graphics_Gdi", + "Win32_Graphics_Imaging", + "Win32_System_Com", + "Win32_UI_Input_KeyboardAndMouse", + "Win32_UI_TextServices", + "Win32_UI_WindowsAndMessaging", +] } diff --git a/libIME/ComPtr.h b/libIME/ComPtr.h deleted file mode 100644 index 351e47a..0000000 --- a/libIME/ComPtr.h +++ /dev/null @@ -1,158 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#ifndef IME_COM_PTR_H -#define IME_COM_PTR_H - -#include - -// ATL-indepdent smart pointers for COM objects -// very similar to the ones provided by ATL (CComPtr & CComQIPtr). - -namespace Ime { - -// a smart pointer for COM interface/object -// automatic AddRef() on copy and Release() on destruction. -template -class ComPtr { -public: - ComPtr(void): p_(nullptr) { - } - - ComPtr(T* p, bool ref = true): p_(p) { - if (p_ && ref) { - p_->AddRef(); - } - } - - ComPtr(ComPtr&& other) noexcept : p_(other.p_) { - other.p_ = nullptr; - } - - ComPtr(const ComPtr& other): p_(other.p_) { - if (p_) { - p_->AddRef(); - } - } - - ~ComPtr(void) { - if(p_) { - p_->Release(); - } - } - - T& operator * () const { - return *p_; - } - - T** operator & () { - return &p_; - } - - T* operator-> () const { - return p_; - } - - operator T* () const { - return p_; - } - - bool operator !() const { - return !p_; - } - - bool operator == (T* p) const { - return p == p_; - } - - bool operator != (T* p) const { - return p != p_; - } - - bool operator < (T* p) const { - return p_ < p; - } - - ComPtr& operator = (ComPtr&& other) noexcept { - p_ = other.p_; - other.p_ = nullptr; - return *this; - } - - ComPtr& operator = (const ComPtr& other) { - return operator = (other.p_); - } - - ComPtr& operator = (T* p) { - T* old = p_; - p_ = p; - if (p_) { - p_->AddRef(); - } - if (old) { - old->Release(); - } - return *this; - } - -protected: - T* p_; -}; - - -// a smart pointer for COM interface/object with automatic QueryInterface -// QueryInterface() for interface T was done automatically on -// assignment or construction. -// automatic AddRef() on copy and Release() on destruction. - -template -class ComQIPtr: public ComPtr { - -public: - ComQIPtr(void): ComPtr() { - } - - ComQIPtr(T* p): ComPtr(p) { - } - - ComQIPtr(const ComQIPtr& other): ComPtr(other) { - } - - ComQIPtr(ComQIPtr&& other) noexcept : ComPtr(std::move(other)) { - } - - ComQIPtr(IUnknown* p) : ComPtr() { - if(p) { - p->QueryInterface(__uuidof(T), (void**)&p_); - } - } - - ComQIPtr& operator = (IUnknown* p) { - ComPtr::operator = (nullptr); - if(p) { - p->QueryInterface(__uuidof(T), (void**)&p_); - } - return *this; - } - -}; - -} - -#endif diff --git a/libIME/DisplayAttributeInfoEnum.cpp b/libIME/DisplayAttributeInfoEnum.cpp index d9bdb1b..0b8fb83 100644 --- a/libIME/DisplayAttributeInfoEnum.cpp +++ b/libIME/DisplayAttributeInfoEnum.cpp @@ -25,8 +25,8 @@ namespace Ime { DisplayAttributeInfoEnum::DisplayAttributeInfoEnum(DisplayAttributeProvider* provider): - provider_(provider), refCount_(1) { + provider_.copy_from(provider); std::list& displayAttrInfos = provider_->imeModule_->displayAttrInfos(); iterator_ = displayAttrInfos.begin(); } diff --git a/libIME/DisplayAttributeInfoEnum.h b/libIME/DisplayAttributeInfoEnum.h index 7b41214..cb7295f 100644 --- a/libIME/DisplayAttributeInfoEnum.h +++ b/libIME/DisplayAttributeInfoEnum.h @@ -23,7 +23,9 @@ #include #include #include "DisplayAttributeInfo.h" -#include "ComPtr.h" + +#include +#include namespace Ime { @@ -51,7 +53,7 @@ class DisplayAttributeInfoEnum : public IEnumTfDisplayAttributeInfo { private: int refCount_; std::list::iterator iterator_; - ComPtr provider_; + winrt::com_ptr provider_; }; } diff --git a/libIME/DisplayAttributeProvider.cpp b/libIME/DisplayAttributeProvider.cpp index 8967fd6..5a0b57e 100644 --- a/libIME/DisplayAttributeProvider.cpp +++ b/libIME/DisplayAttributeProvider.cpp @@ -28,8 +28,8 @@ using namespace std; namespace Ime { DisplayAttributeProvider::DisplayAttributeProvider(ImeModule* module): - imeModule_(module), refCount_(1) { + imeModule_.copy_from(module); } DisplayAttributeProvider::~DisplayAttributeProvider(void) { diff --git a/libIME/DisplayAttributeProvider.h b/libIME/DisplayAttributeProvider.h index d9b8e46..b5e9d5e 100644 --- a/libIME/DisplayAttributeProvider.h +++ b/libIME/DisplayAttributeProvider.h @@ -22,7 +22,9 @@ #include #include -#include "ComPtr.h" + +#include +#include namespace Ime { @@ -52,7 +54,7 @@ class DisplayAttributeProvider : public ITfDisplayAttributeProvider { private: int refCount_; - ComPtr imeModule_; + winrt::com_ptr imeModule_; }; } diff --git a/libIME/DrawUtils.cpp b/libIME/DrawUtils.cpp deleted file mode 100644 index 9f2d6c1..0000000 --- a/libIME/DrawUtils.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#include "DrawUtils.h" - -void FillSolidRect(HDC dc, LPRECT rc, COLORREF color) { - SetBkColor(dc, color); - ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, rc, NULL, 0, NULL); -} - -void FillSolidRect(HDC dc, int l, int t, int w, int h, COLORREF color) { - RECT rc; - rc.left = l; - rc.top = t; - rc.right = rc.left + w; - rc.bottom = rc.top + h; - SetBkColor(dc, color); - ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); -} - -void Draw3DBorder(HDC hdc, LPRECT rc, COLORREF light, COLORREF dark, int width) { - MoveToEx(hdc, rc->left, rc->bottom, NULL); - - HPEN light_pen = CreatePen(PS_SOLID|PS_INSIDEFRAME, width, light); - HGDIOBJ oldPen = SelectObject(hdc, light_pen); - LineTo(hdc, rc->left, rc->top); - LineTo(hdc, rc->right-width, rc->top); - SelectObject(hdc, oldPen); - DeleteObject(light_pen); - - HPEN dark_pen = CreatePen(PS_SOLID|PS_INSIDEFRAME, width, dark); - oldPen = SelectObject(hdc, dark_pen); - LineTo(hdc, rc->right-width, rc->bottom-width); - LineTo(hdc, rc->left, rc->bottom-width); - DeleteObject(dark_pen); - SelectObject(hdc, oldPen); -} - -void DrawBitmap(HDC dc, HBITMAP bmp, int x, int y, int w, int h, int srcx, int srcy) { - HDC memdc = CreateCompatibleDC(dc); - HGDIOBJ oldobj = SelectObject(memdc, bmp); - BitBlt(dc, x, y, w, h, memdc, srcx, srcy, SRCCOPY); - SelectObject(memdc, oldobj); - DeleteDC(memdc); -} \ No newline at end of file diff --git a/libIME/DrawUtils.h b/libIME/DrawUtils.h deleted file mode 100644 index 0b3ef3f..0000000 --- a/libIME/DrawUtils.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#ifndef IME_DRAW_UTIL_H -#define IME_DRAW_UTIL_H - -#include - -void FillSolidRect( HDC dc, LPRECT rc, COLORREF color ); -void FillSolidRect( HDC dc, int l, int t, int w, int h, COLORREF color ); -void Draw3DBorder(HDC hdc, LPRECT rc, COLORREF light, COLORREF dark, int width = 1); -void DrawBitmap(HDC dc, HBITMAP bmp, int x, int y, int w, int h, int srcx, int srcy ); - -#endif \ No newline at end of file diff --git a/libIME/ImeEngine.cpp b/libIME/ImeEngine.cpp index 5fb877f..27bcbf7 100644 --- a/libIME/ImeEngine.cpp +++ b/libIME/ImeEngine.cpp @@ -1,6 +1,5 @@ #include "ImeEngine.h" #include "EditSession.h" -#include "CandidateWindow.h" #include "LangBarButton.h" #include "DisplayAttributeInfoEnum.h" #include "ImeModule.h" @@ -25,15 +24,12 @@ ImeEngine::ImeEngine(ImeModule* module): keyboardOpenEventSinkCookie_(TF_INVALID_COOKIE), globalCompartmentEventSinkCookie_(TF_INVALID_COOKIE), langBarSinkCookie_(TF_INVALID_COOKIE), - composition_(NULL), - candidateWindow_(NULL) { + composition_(NULL) { addCompartmentMonitor(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, false); } ImeEngine::~ImeEngine() { - if(candidateWindow_) - delete candidateWindow_; // This should only happen in rare cases if(!compartmentMonitors_.empty()) { diff --git a/libIME/ImeEngine.h b/libIME/ImeEngine.h index 0147e78..098b86a 100644 --- a/libIME/ImeEngine.h +++ b/libIME/ImeEngine.h @@ -5,11 +5,13 @@ #include #include "EditSession.h" #include "KeyEvent.h" -#include "ComPtr.h" #include #include +#include +#include + // for Windows 8 support #ifndef TF_TMF_IMMERSIVEMODE // this is defined in Win 8 SDK #define TF_TMF_IMMERSIVEMODE 0x40000000 @@ -18,7 +20,6 @@ namespace Ime { class ImeModule; -class CandidateWindow; class LangBarButton; class ImeEngine { @@ -85,9 +86,9 @@ class ImeEngine { void setCompositionCursor(EditSession* session, int pos); // compartment handling - ComPtr globalCompartment(const GUID& key); - ComPtr threadCompartment(const GUID& key); - ComPtr contextCompartment(const GUID& key, ITfContext* context = NULL); + winrt::com_ptr globalCompartment(const GUID& key); + winrt::com_ptr threadCompartment(const GUID& key); + winrt::com_ptr contextCompartment(const GUID& key, ITfContext* context = NULL); DWORD globalCompartmentValue(const GUID& key); DWORD threadCompartmentValue(const GUID& key); @@ -134,8 +135,8 @@ class ImeEngine { virtual void onCompositionTerminated(bool forced); private: - ComPtr module_; - ComPtr threadMgr_; + winrt::com_ptr module_; + winrt::com_ptr threadMgr_; TfClientId clientId_; DWORD activateFlags_; bool isKeyboardOpened_; @@ -149,8 +150,7 @@ class ImeEngine { DWORD langBarSinkCookie_; ITfComposition* composition_; // acquired when starting composition, released when ending composition - CandidateWindow* candidateWindow_; - ComPtr langBarMgr_; + winrt::com_ptr langBarMgr_; std::vector langBarButtons_; std::vector preservedKeys_; std::vector compartmentMonitors_; diff --git a/libIME/ImeModule.cpp b/libIME/ImeModule.cpp index 67f63f8..47cc0e3 100644 --- a/libIME/ImeModule.cpp +++ b/libIME/ImeModule.cpp @@ -17,19 +17,21 @@ // Boston, MA 02110-1301, USA. // +#include +#include + #include "ImeModule.h" #include -#include -#include #include #include #include #include #include -#include "Window.h" #include "TextService.h" #include "DisplayAttributeProvider.h" +#include "libime2.h" + using namespace std; namespace Ime { @@ -61,7 +63,8 @@ ImeModule::ImeModule(HMODULE module, const CLSID& textServiceClsid): textServiceClsid_(textServiceClsid), refCount_(1) { - Window::registerClass(hInstance_); + LibIME2Init(); + ImeWindowRegisterClass(hInstance_); // regiser default display attributes inputAttrib_ = new DisplayAttributeInfo(g_inputDisplayAttributeGuid); @@ -143,8 +146,8 @@ static void loadDefaultUserRegistry(const wchar_t* defaultUserRegKey) { HRESULT ImeModule::registerLangProfiles(LangProfileInfo* langs, int langsCount) { // register the language profile - ComPtr inputProcessProfiles; - if(CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER, IID_ITfInputProcessorProfiles, (void**)&inputProcessProfiles) == S_OK) { + winrt::com_ptr inputProcessProfiles; + if(CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER, IID_ITfInputProcessorProfiles, inputProcessProfiles.put_void()) == S_OK) { for(int i = 0; i < langsCount; ++i) { LangProfileInfo& lang = langs[i]; if(inputProcessProfiles->Register(textServiceClsid_) == S_OK) { @@ -188,7 +191,7 @@ HRESULT ImeModule::registerLangProfiles(LangProfileInfo* langs, int langsCount) // The keys under HKCU\Control Panel\ is shared between the x86 and x64 versions and // are not affected by WOW64 redirection. So doing this inside the 32-bit version is enough. - if (isWindows8Above()) { + if (IsWindows8OrGreater()) { DWORD sidCount = 0; if (::RegQueryInfoKeyW(HKEY_USERS, NULL, NULL, NULL, &sidCount, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) return E_FAIL; @@ -316,7 +319,7 @@ HRESULT ImeModule::registerServer(wchar_t* imeName, LangProfileInfo* langs, int result = E_FAIL; } - if(isWindows8Above()) { + if(IsWindows8OrGreater()) { // for Windows 8 store app support // TODO: according to a exhaustive Google search, I found that // TF_IPP_CAPS_IMMERSIVESUPPORT is required to make the IME work with Windows 8. @@ -356,7 +359,7 @@ HRESULT ImeModule::unregisterServer() { // UI less mode categoryMgr->UnregisterCategory(textServiceClsid_, GUID_TFCAT_TIPCAP_INPUTMODECOMPARTMENT, textServiceClsid_); - if(isWindows8Above()) { + if(IsWindows8OrGreater()) { // Windows 8 support categoryMgr->UnregisterCategory(textServiceClsid_, GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT, textServiceClsid_); categoryMgr->RegisterCategory(textServiceClsid_, GUID_TFCAT_TIPCAP_SYSTRAYSUPPORT, textServiceClsid_); @@ -379,7 +382,7 @@ HRESULT ImeModule::unregisterServer() { // are not affected by WOW64 redirection. So doing this inside the 32-bit version is enough. // delete settings under "HKEY_CURRENT_USER\Control Panel\International\User Profile\" for all users - if (isWindows8Above()) { + if (IsWindows8OrGreater()) { DWORD sidCount = 0; if (::RegQueryInfoKeyW(HKEY_USERS, NULL, NULL, NULL, &sidCount, NULL, NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) return E_FAIL; @@ -449,8 +452,8 @@ HRESULT ImeModule::unregisterServer() { bool ImeModule::registerDisplayAttributeInfos() { // register display attributes - ComPtr categoryMgr; - if(::CoCreateInstance(CLSID_TF_CategoryMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfCategoryMgr, (void**)&categoryMgr) == S_OK) { + winrt::com_ptr categoryMgr; + if(::CoCreateInstance(CLSID_TF_CategoryMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfCategoryMgr, categoryMgr.put_void()) == S_OK) { TfGuidAtom atom; categoryMgr->RegisterGUID(g_inputDisplayAttributeGuid, &atom); inputAttrib_->setAtom(atom); diff --git a/libIME/ImeModule.h b/libIME/ImeModule.h index a718640..18bb195 100644 --- a/libIME/ImeModule.h +++ b/libIME/ImeModule.h @@ -24,7 +24,6 @@ #include #include #include -#include "WindowsVersion.h" #include namespace Ime { @@ -58,14 +57,6 @@ class ImeModule: return textServiceClsid_; } - bool isWindows8Above() { - return winVer_.isWindows8Above(); - } - - WindowsVersion windowsVersion() const { - return winVer_; - } - // Dll entry points implementations HRESULT canUnloadNow(); HRESULT getClassObject(REFCLSID rclsid, REFIID riid, void **ppvObj); @@ -134,7 +125,6 @@ class ImeModule: DisplayAttributeInfo* inputAttrib_; // DisplayAttributeInfo* convertedAttrib_; - WindowsVersion winVer_; std::list textServices_; }; diff --git a/libIME/ImeWindow.cpp b/libIME/ImeWindow.cpp deleted file mode 100644 index afd7fff..0000000 --- a/libIME/ImeWindow.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#include "ImeWindow.h" - -namespace Ime { - -ImeWindow::ImeWindow(TextService* service): - textService_(service) { - - if(service->isImmersive()) { // windows 8 app mode - margin_ = 10; - } - else { // desktop mode - margin_ = 5; - } - - 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) { -} - -void ImeWindow::onLButtonDown(WPARAM wp, LPARAM lp) { - oldPos = MAKEPOINTS(lp); - SetCapture(hwnd_); -} - -void ImeWindow::onLButtonUp(WPARAM wp, LPARAM lp) { - ReleaseCapture(); -} - -void ImeWindow::onMouseMove(WPARAM wp, LPARAM lp) { - if(GetCapture() != hwnd_) - return; - POINTS pt = MAKEPOINTS(lp); - RECT rc; - GetWindowRect(hwnd_, &rc); - OffsetRect( &rc, (pt.x - oldPos.x), (pt.y - oldPos.y) ); - move(rc.left, rc.top); -} - -void ImeWindow::move(int x, int y) { - int w, h; - size(&w, &h); - // ensure that the window does not fall outside of the screen. - RECT rc = {x, y, x + w, y + h}; // current window rect - // get the nearest monitor - HMONITOR monitor = ::MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST); - MONITORINFO mi; - mi.cbSize = sizeof(mi); - if(GetMonitorInfo(monitor, &mi)) - rc = mi.rcWork; - if(x < rc.left) - x = rc.left; - else if((x + w) > rc.right) - x = rc.right - w; - - if(y < rc.top) - y = rc.top; - else if((y + h) > rc.bottom) - y = rc.bottom - h; - ::MoveWindow(hwnd_, x, y, w, h, TRUE); -} - -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 deleted file mode 100644 index 785a26e..0000000 --- a/libIME/ImeWindow.h +++ /dev/null @@ -1,58 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#ifndef IME_IME_WINDOW_H -#define IME_IME_WINDOW_H - -#include -#include "window.h" -#include "TextService.h" - -namespace Ime { - -class TextService; - -// base class for all IME windows (candidate, tooltip, ...etc) -class ImeWindow: public Window { -public: - ImeWindow(TextService* service); - virtual ~ImeWindow(void); - void move(int x, int y); - bool isImmersive() { - return textService_->isImmersive(); - } - - void setFont(HFONT f); - virtual void recalculateSize(); - -protected: - void onLButtonDown(WPARAM wp, LPARAM lp); - void onLButtonUp(WPARAM wp, LPARAM lp); - void onMouseMove(WPARAM wp, LPARAM lp); - -protected: - TextService* textService_; - POINTS oldPos; - HFONT font_; - int margin_; -}; - -} - -#endif diff --git a/libIME/MessageWindow.cpp b/libIME/MessageWindow.cpp deleted file mode 100644 index 572f691..0000000 --- a/libIME/MessageWindow.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#include "MessageWindow.h" -#include "TextService.h" -#include "DrawUtils.h" - -namespace Ime { - -MessageWindow::MessageWindow(TextService* service, EditSession* session): - ImeWindow(service) { - - HWND parent = service->compositionWindow(session); - create(parent, WS_POPUP|WS_CLIPCHILDREN, WS_EX_TOOLWINDOW|WS_EX_TOPMOST); -} - -MessageWindow::~MessageWindow(void) { -} - -// virtual -void MessageWindow::recalculateSize() { - SIZE size = {0}; - HDC dc = GetDC(hwnd_); - HGDIOBJ old_font = SelectObject(dc, font_); - GetTextExtentPointW(dc, text_.c_str(), text_.length(), &size); - SelectObject(dc, old_font); - ReleaseDC(hwnd_, dc); - - 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: { - PAINTSTRUCT ps; - BeginPaint(hwnd_, &ps); - onPaint(ps); - EndPaint(hwnd_, &ps); - } - break; - case WM_MOUSEACTIVATE: - return MA_NOACTIVATE; - default: - return ImeWindow::wndProc(msg, wp, lp); - } - return 0; -} - -void MessageWindow::onPaint(PAINTSTRUCT& ps) { - int len = text_.length(); - RECT rc, textrc = {0}; - GetClientRect(hwnd_, &rc); - - // draw a flat black border in Windows 8 app immersive mode - // draw a 3d border in desktop mode - HDC hDC = ps.hdc; - HFONT oldFont = (HFONT)SelectObject(hDC, font_); - - SetBkMode(hDC, TRANSPARENT); - if(isImmersive()) { - SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); - SetBkColor(hDC, GetSysColor(COLOR_WINDOW)); - HPEN pen = ::CreatePen(PS_SOLID, 3, RGB(0, 0, 0)); - HGDIOBJ oldPen = ::SelectObject(hDC, pen); - ::Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); - ::SelectObject(hDC, oldPen); - ::DeleteObject(pen); - } - else { - SetTextColor(hDC, GetSysColor(COLOR_INFOTEXT)); - SetBkColor(hDC, GetSysColor(COLOR_INFOBK)); - // draw a 3d border in desktop mode - ::FillSolidRect(hDC, &rc, ::GetSysColor(COLOR_INFOBK)); - ::Draw3DBorder(hDC, &rc, GetSysColor(COLOR_3DFACE), 0); - } - - SIZE size; - GetTextExtentPoint32W(hDC, text_.c_str(), len, &size); - rc.top += (rc.bottom - size.cy)/2; - rc.left += (rc.right - size.cx)/2; - ExtTextOutW(hDC, rc.left, rc.top, 0, &textrc, text_.c_str(), len, NULL); - - SelectObject(hDC, oldFont); -} - -} // namespace Ime diff --git a/libIME/MessageWindow.h b/libIME/MessageWindow.h deleted file mode 100644 index 6d8007e..0000000 --- a/libIME/MessageWindow.h +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#ifndef IME_MESSAGE_WINDOW_H -#define IME_MESSAGE_WINDOW_H - -#include "ImeWindow.h" -#include "EditSession.h" -#include - -namespace Ime { - -class TextService; - -class MessageWindow : public ImeWindow { -public: - MessageWindow(TextService* service, EditSession* session = NULL); - virtual ~MessageWindow(void); - - std::wstring text() { - return text_; - } - void setText(std::wstring text); - - TextService* textService() { - return textService_; - } - - virtual void recalculateSize(); -protected: - LRESULT wndProc(UINT msg, WPARAM wp, LPARAM lp); - void onPaint(PAINTSTRUCT& ps); - -private: - std::wstring text_; -}; - -} - -#endif diff --git a/libIME/TextService.cpp b/libIME/TextService.cpp index 7c528be..6e6fd35 100644 --- a/libIME/TextService.cpp +++ b/libIME/TextService.cpp @@ -19,12 +19,13 @@ #include "TextService.h" #include "EditSession.h" -#include "CandidateWindow.h" #include "LangBarButton.h" #include "DisplayAttributeInfoEnum.h" #include "ImeModule.h" #include +#include +#include #include #include @@ -33,7 +34,6 @@ using namespace std; namespace Ime { TextService::TextService(ImeModule* module): - module_(module), threadMgr_(NULL), clientId_(TF_CLIENTID_NULL), activateFlags_(0), @@ -47,7 +47,7 @@ TextService::TextService(ImeModule* module): activateLanguageProfileNotifySinkCookie_(TF_INVALID_COOKIE), composition_(NULL), refCount_(1) { - + module_.copy_from(module); addCompartmentMonitor(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, false); } @@ -57,11 +57,11 @@ TextService::~TextService(void) { if(!compartmentMonitors_.empty()) { vector::iterator it; for(it = compartmentMonitors_.begin(); it != compartmentMonitors_.end(); ++it) { - ComQIPtr source; + winrt::com_ptr source; if(it->isGlobal) - source = globalCompartment(it->guid); + source = globalCompartment(it->guid).as(); else - source = threadCompartment(it->guid); + source = threadCompartment(it->guid).as(); if (source) { source->UnadviseSink(it->cookie); } @@ -77,11 +77,11 @@ TextService::~TextService(void) { // public methods ImeModule* TextService::imeModule() const { - return module_; + return module_.get(); } ITfThreadMgr* TextService::threadMgr() const { - return threadMgr_; + return threadMgr_.get(); } TfClientId TextService::clientId() const { @@ -102,10 +102,12 @@ DWORD TextService::langBarStatus() const { void TextService::addButton(LangBarButton* button) { if(button) { - langBarButtons_.emplace_back(button); + winrt::com_ptr btn; + btn.copy_from(button); + langBarButtons_.emplace_back(btn); if(isActivated()) { - ComPtr langBarItemMgr; - if(threadMgr_->QueryInterface(IID_ITfLangBarItemMgr, (void**)&langBarItemMgr) == S_OK) { + winrt::com_ptr langBarItemMgr; + if(threadMgr_->QueryInterface(IID_ITfLangBarItemMgr, langBarItemMgr.put_void()) == S_OK) { langBarItemMgr->AddItem(button); } } @@ -114,11 +116,13 @@ void TextService::addButton(LangBarButton* button) { void TextService::removeButton(LangBarButton* button) { if(button) { - auto it = find(langBarButtons_.begin(), langBarButtons_.end(), button); + winrt::com_ptr btn; + btn.copy_from(button); + auto it = find(langBarButtons_.begin(), langBarButtons_.end(), btn); if(it != langBarButtons_.end()) { if(isActivated()) { - ComPtr langBarItemMgr; - if(threadMgr_->QueryInterface(IID_ITfLangBarItemMgr, (void**)&langBarItemMgr) == S_OK) { + winrt::com_ptr langBarItemMgr; + if(threadMgr_->QueryInterface(IID_ITfLangBarItemMgr, langBarItemMgr.put_void()) == S_OK) { langBarItemMgr->RemoveItem(button); } } @@ -232,8 +236,8 @@ void TextService::endComposition(ITfContext* context) { std::wstring TextService::compositionString(EditSession* session) { if (composition_) { - ComPtr compositionRange; - if (composition_->GetRange(&compositionRange) == S_OK) { + winrt::com_ptr compositionRange; + if (composition_->GetRange(compositionRange.put()) == S_OK) { TfEditCookie editCookie = session->editCookie(); // FIXME: the TSF API is really stupid here and it provides no way to know the size of the range. // we cannot even get the actual position of start and end to calculate by ourselves. @@ -259,8 +263,8 @@ void TextService::setCompositionString(EditSession* session, const wchar_t* str, ULONG selectionNum; // get current selection/insertion point if(context->GetSelection(editCookie, TF_DEFAULT_SELECTION, 1, &selection, &selectionNum) == S_OK) { - ComPtr compositionRange; - if(composition_->GetRange(&compositionRange) == S_OK) { + winrt::com_ptr compositionRange; + if(composition_->GetRange(compositionRange.put()) == S_OK) { bool selPosInComposition = true; // if current insertion point is not covered by composition, we cannot insert text here. if(selPosInComposition) { @@ -273,12 +277,12 @@ void TextService::setCompositionString(EditSession* session, const wchar_t* str, } // set display attribute to the composition range - ComPtr dispAttrProp; - if(context->GetProperty(GUID_PROP_ATTRIBUTE, &dispAttrProp) == S_OK) { + winrt::com_ptr dispAttrProp; + if(context->GetProperty(GUID_PROP_ATTRIBUTE, dispAttrProp.put()) == S_OK) { VARIANT val; val.vt = VT_I4; val.lVal = module_->inputAttrib()->atom(); - dispAttrProp->SetValue(editCookie, compositionRange, &val); + dispAttrProp->SetValue(editCookie, compositionRange.get(), &val); } } selection.range->Release(); @@ -312,41 +316,42 @@ void TextService::setCompositionCursor(EditSession* session, int pos) { } // compartment handling -ComPtr TextService::globalCompartment(const GUID& key) { +winrt::com_ptr TextService::globalCompartment(const GUID& key) { if(threadMgr_) { - ComQIPtr compartmentMgr; - if(threadMgr_->GetGlobalCompartment(&compartmentMgr) == S_OK) { - ComPtr compartment; - compartmentMgr->GetCompartment(key, &compartment); + winrt::com_ptr compartmentMgr; + if(threadMgr_->GetGlobalCompartment(compartmentMgr.put()) == S_OK) { + winrt::com_ptr compartment; + compartmentMgr->GetCompartment(key, compartment.put()); return compartment; } } return NULL; } -ComPtr TextService::threadCompartment(const GUID& key) { +winrt::com_ptr TextService::threadCompartment(const GUID& key) { if(threadMgr_) { - ComQIPtr compartmentMgr = threadMgr_; + winrt::com_ptr compartmentMgr = threadMgr_.as(); if(compartmentMgr) { - ComPtr compartment; - compartmentMgr->GetCompartment(key, &compartment); + winrt::com_ptr compartment; + compartmentMgr->GetCompartment(key, compartment.put()); return compartment; } } return NULL; } -ComPtr TextService::contextCompartment(const GUID& key, ITfContext* context) { - ITfContext* curContext = NULL; +winrt::com_ptr TextService::contextCompartment(const GUID& key, ITfContext* context) { + winrt::com_ptr curContext; if(!context) { - curContext = currentContext(); - context = curContext; + curContext.attach(currentContext()); + } else { + curContext.copy_from(context); } if(context) { - ComQIPtr compartmentMgr = context; + winrt::com_ptr compartmentMgr = curContext.as(); if(compartmentMgr) { - ComPtr compartment; - compartmentMgr->GetCompartment(key, &compartment); + winrt::com_ptr compartment; + compartmentMgr->GetCompartment(key, compartment.put()); return compartment; } } @@ -357,7 +362,7 @@ ComPtr TextService::contextCompartment(const GUID& key, ITfConte DWORD TextService::globalCompartmentValue(const GUID& key) { - ComPtr compartment = globalCompartment(key); + winrt::com_ptr compartment = globalCompartment(key); if(compartment) { VARIANT var; if(compartment->GetValue(&var) == S_OK && var.vt == VT_I4) { @@ -368,7 +373,7 @@ DWORD TextService::globalCompartmentValue(const GUID& key) { } DWORD TextService::threadCompartmentValue(const GUID& key) { - ComPtr compartment = threadCompartment(key); + winrt::com_ptr compartment = threadCompartment(key); if(compartment) { VARIANT var; ::VariantInit(&var); @@ -382,7 +387,7 @@ DWORD TextService::threadCompartmentValue(const GUID& key) { } DWORD TextService::contextCompartmentValue(const GUID& key, ITfContext* context) { - ComPtr compartment = contextCompartment(key, context); + winrt::com_ptr compartment = contextCompartment(key, context); if(compartment) { VARIANT var; if(compartment->GetValue(&var) == S_OK && var.vt == VT_I4) { @@ -394,7 +399,7 @@ DWORD TextService::contextCompartmentValue(const GUID& key, ITfContext* context) void TextService::setGlobalCompartmentValue(const GUID& key, DWORD value) { if(threadMgr_) { - ComPtr compartment = globalCompartment(key); + winrt::com_ptr compartment = globalCompartment(key); if(compartment) { VARIANT var; ::VariantInit(&var); @@ -406,13 +411,13 @@ void TextService::setGlobalCompartmentValue(const GUID& key, DWORD value) { else { // if we don't have a thread manager (this is possible when we try to set // a global compartment value while the text service is not activated) - ComPtr threadMgr; - if(::CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, (void**)&threadMgr) == S_OK) { + winrt::com_ptr threadMgr; + if(::CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, threadMgr.put_void()) == S_OK) { if(threadMgr) { - ComPtr compartmentMgr; - if(threadMgr->GetGlobalCompartment(&compartmentMgr) == S_OK) { - ComPtr compartment; - if(compartmentMgr->GetCompartment(key, &compartment) == S_OK && compartment) { + winrt::com_ptr compartmentMgr; + if(threadMgr->GetGlobalCompartment(compartmentMgr.put()) == S_OK) { + winrt::com_ptr compartment; + if(compartmentMgr->GetCompartment(key, compartment.put()) == S_OK && compartment) { TfClientId id; if(threadMgr->Activate(&id) == S_OK) { VARIANT var; @@ -430,7 +435,7 @@ void TextService::setGlobalCompartmentValue(const GUID& key, DWORD value) { } void TextService::setThreadCompartmentValue(const GUID& key, DWORD value) { - ComPtr compartment = threadCompartment(key); + winrt::com_ptr compartment = threadCompartment(key); if(compartment) { VARIANT var; ::VariantInit(&var); @@ -441,7 +446,7 @@ void TextService::setThreadCompartmentValue(const GUID& key, DWORD value) { } void TextService::setContextCompartmentValue(const GUID& key, DWORD value, ITfContext* context) { - ComPtr compartment = contextCompartment(key, context); + winrt::com_ptr compartment = contextCompartment(key, context); if(compartment) { VARIANT var; ::VariantInit(&var); @@ -459,11 +464,11 @@ void TextService::addCompartmentMonitor(const GUID key, bool isGlobal) { monitor.isGlobal = isGlobal; // if the text service is activated if(threadMgr_) { - ComQIPtr source; + winrt::com_ptr source; if(isGlobal) - source = globalCompartment(key); + source = globalCompartment(key).as(); else - source = threadCompartment(key); + source = threadCompartment(key).as(); if(source) { source->AdviseSink(IID_ITfCompartmentEventSink, (ITfCompartmentEventSink*)this, &monitor.cookie); } @@ -476,11 +481,11 @@ void TextService::removeCompartmentMonitor(const GUID key) { it = find(compartmentMonitors_.begin(), compartmentMonitors_.end(), key); if(it != compartmentMonitors_.end()) { if(threadMgr_) { - ComQIPtr source; + winrt::com_ptr source; if(it->isGlobal) - source = globalCompartment(key); + source = globalCompartment(key).as(); else - source = threadCompartment(key); + source = threadCompartment(key).as(); source->UnadviseSink(it->cookie); } compartmentMonitors_.erase(it); @@ -622,11 +627,11 @@ STDMETHODIMP_(ULONG) TextService::Release(void) { // ITfTextInputProcessor STDMETHODIMP TextService::Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClientId) { // store tsf manager & client id - threadMgr_ = pThreadMgr; + threadMgr_.copy_from(pThreadMgr); clientId_ = tfClientId; activateFlags_ = 0; - ComQIPtr threadMgrEx = threadMgr_; + winrt::com_ptr threadMgrEx = threadMgr_.as(); if(threadMgrEx) { threadMgrEx->GetActiveFlags(&activateFlags_); } @@ -634,7 +639,7 @@ STDMETHODIMP TextService::Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClient // advice event sinks (set up event listeners) // ITfThreadMgrEventSink, ITfActiveLanguageProfileNotifySink - ComQIPtr source = threadMgr_; + winrt::com_ptr source = threadMgr_.as(); if(source) { source->AdviseSink(IID_ITfThreadMgrEventSink, (ITfThreadMgrEventSink *)this, &threadMgrEventSinkCookie_); source->AdviseSink(IID_ITfActiveLanguageProfileNotifySink, (ITfActiveLanguageProfileNotifySink *)this, &activateLanguageProfileNotifySinkCookie_); @@ -643,7 +648,7 @@ STDMETHODIMP TextService::Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClient // ITfTextEditSink, // ITfKeyEventSink - ComQIPtr keystrokeMgr = threadMgr_; + winrt::com_ptr keystrokeMgr = threadMgr_.as(); if(keystrokeMgr) keystrokeMgr->AdviseKeyEventSink(clientId_, (ITfKeyEventSink*)this, TRUE); @@ -663,11 +668,11 @@ STDMETHODIMP TextService::Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClient if(!compartmentMonitors_.empty()) { vector::iterator it; for(it = compartmentMonitors_.begin(); it != compartmentMonitors_.end(); ++it) { - ComQIPtr compartmentSource; + winrt::com_ptr compartmentSource; if(it->isGlobal) // global compartment - compartmentSource = globalCompartment(it->guid); + compartmentSource = globalCompartment(it->guid).as(); else // thread specific compartment - compartmentSource = threadCompartment(it->guid); + compartmentSource = threadCompartment(it->guid).as(); compartmentSource->AdviseSink(IID_ITfCompartmentEventSink, (ITfCompartmentEventSink*)this, &it->cookie); } } @@ -687,10 +692,10 @@ STDMETHODIMP TextService::Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClient } // Note: language bar has no effects in Win 8 immersive mode if(!langBarButtons_.empty()) { - ComPtr langBarItemMgr; - if(threadMgr_->QueryInterface(IID_ITfLangBarItemMgr, (void**)&langBarItemMgr) == S_OK) { + winrt::com_ptr langBarItemMgr; + if(threadMgr_->QueryInterface(IID_ITfLangBarItemMgr, langBarItemMgr.put_void()) == S_OK) { for(auto& button: langBarButtons_) { - langBarItemMgr->AddItem(button); + langBarItemMgr->AddItem(button.get()); } } } @@ -715,10 +720,10 @@ STDMETHODIMP TextService::Deactivate() { // uninitialize language bar if(!langBarButtons_.empty()) { - ComPtr langBarItemMgr; - if(threadMgr_->QueryInterface(IID_ITfLangBarItemMgr, (void**)&langBarItemMgr) == S_OK) { + winrt::com_ptr langBarItemMgr; + if(threadMgr_->QueryInterface(IID_ITfLangBarItemMgr, langBarItemMgr.put_void()) == S_OK) { for(auto& button: langBarButtons_) { - langBarItemMgr->RemoveItem(button); + langBarItemMgr->RemoveItem(button.get()); } } } @@ -731,7 +736,7 @@ STDMETHODIMP TextService::Deactivate() { // unadvice event sinks // ITfThreadMgrEventSink - ComQIPtr source = threadMgr_; + winrt::com_ptr source = threadMgr_.as(); if(source) { source->UnadviseSink(threadMgrEventSinkCookie_); source->UnadviseSink(activateLanguageProfileNotifySinkCookie_); @@ -742,7 +747,7 @@ STDMETHODIMP TextService::Deactivate() { // ITfTextEditSink, // ITfKeyEventSink - ComQIPtr keystrokeMgr = threadMgr_; + winrt::com_ptr keystrokeMgr = threadMgr_.as(); if(keystrokeMgr) { keystrokeMgr->UnadviseKeyEventSink(clientId_); // unregister preserved keys @@ -759,9 +764,9 @@ STDMETHODIMP TextService::Deactivate() { // ITfCompartmentEventSink // thread specific compartment - ComPtr compartment = threadCompartment(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE); + winrt::com_ptr compartment = threadCompartment(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE); if(compartment) { - ComQIPtr compartmentSource = compartment; + winrt::com_ptr compartmentSource = compartment.as(); if(compartmentSource) compartmentSource->UnadviseSink(keyboardOpenEventSinkCookie_); keyboardOpenEventSinkCookie_ = TF_INVALID_COOKIE; @@ -830,8 +835,8 @@ STDMETHODIMP TextService::OnEndEdit(ITfContext *pContext, TfEditCookie ecReadOnl TF_SELECTION selection; ULONG selectionNum; if(pContext->GetSelection(ecReadOnly, TF_DEFAULT_SELECTION, 1, &selection, &selectionNum) == S_OK) { - ComPtr compRange; - if(composition_->GetRange(&compRange) == S_OK) { + winrt::com_ptr compRange; + if(composition_->GetRange(compRange.put()) == S_OK) { // check if two ranges overlaps // check if current selection is covered by composition range LONG compareResult1; @@ -1076,8 +1081,8 @@ HRESULT TextService::doEndCompositionEditSession(TfEditCookie cookie, EndComposi ITfRange* compositionRange; if(composition_->GetRange(&compositionRange) == S_OK) { // clear display attribute for the composition range - ComPtr dispAttrProp; - if(session->context()->GetProperty(GUID_PROP_ATTRIBUTE, &dispAttrProp) == S_OK) { + winrt::com_ptr dispAttrProp; + if(session->context()->GetProperty(GUID_PROP_ATTRIBUTE, dispAttrProp.put()) == S_OK) { dispAttrProp->Clear(cookie, compositionRange); } @@ -1114,12 +1119,12 @@ ITfContext* TextService::currentContext() { bool TextService::compositionRect(EditSession* session, RECT* rect) { bool ret = false; if(isComposing()) { - ComPtr view; - if(session->context()->GetActiveView(&view) == S_OK) { + winrt::com_ptr view; + if(session->context()->GetActiveView(view.put()) == S_OK) { BOOL clipped; - ComPtr range; - if(composition_->GetRange(&range) == S_OK) { - if(view->GetTextExt(session->editCookie(), range, rect, &clipped) == S_OK) + winrt::com_ptr range; + if(composition_->GetRange(range.put()) == S_OK) { + if(view->GetTextExt(session->editCookie(), range.get(), rect, &clipped) == S_OK) ret = true; } } @@ -1130,8 +1135,8 @@ bool TextService::compositionRect(EditSession* session, RECT* rect) { bool TextService::selectionRect(EditSession* session, RECT* rect) { bool ret = false; if(isComposing()) { - ComPtr view; - if(session->context()->GetActiveView(&view) == S_OK) { + winrt::com_ptr view; + if(session->context()->GetActiveView(view.put()) == S_OK) { BOOL clipped; TF_SELECTION selection; ULONG selectionNum; @@ -1147,8 +1152,8 @@ bool TextService::selectionRect(EditSession* session, RECT* rect) { HWND TextService::compositionWindow(EditSession* session) { HWND hwnd = NULL; - ComPtr view; - if(session->context()->GetActiveView(&view) == S_OK) { + winrt::com_ptr view; + if(session->context()->GetActiveView(view.put()) == S_OK) { // get current composition window view->GetWnd(&hwnd); } diff --git a/libIME/TextService.h b/libIME/TextService.h index 42713f9..3cbd3fd 100644 --- a/libIME/TextService.h +++ b/libIME/TextService.h @@ -24,13 +24,15 @@ #include #include "EditSession.h" #include "KeyEvent.h" -#include "ComPtr.h" #include "DisplayAttributeInfo.h" #include #include #include +#include +#include + // for Windows 8 support #ifndef TF_TMF_IMMERSIVEMODE // this is defined in Win 8 SDK #define TF_TMF_IMMERSIVEMODE 0x40000000 @@ -131,9 +133,9 @@ class TextService: void setCompositionCursor(EditSession* session, int pos); // compartment handling - ComPtr globalCompartment(const GUID& key); - ComPtr threadCompartment(const GUID& key); - ComPtr contextCompartment(const GUID& key, ITfContext* context = NULL); + winrt::com_ptr globalCompartment(const GUID& key); + winrt::com_ptr threadCompartment(const GUID& key); + winrt::com_ptr contextCompartment(const GUID& key, ITfContext* context = NULL); DWORD globalCompartmentValue(const GUID& key); DWORD threadCompartmentValue(const GUID& key); @@ -289,8 +291,8 @@ class TextService: virtual ~TextService(void); private: - ComPtr module_; - ComPtr threadMgr_; + winrt::com_ptr module_; + winrt::com_ptr threadMgr_; TfClientId clientId_; DWORD activateFlags_; bool isKeyboardOpened_; @@ -305,8 +307,8 @@ class TextService: DWORD activateLanguageProfileNotifySinkCookie_; ITfComposition* composition_; // acquired when starting composition, released when ending composition - ComPtr langBarMgr_; - std::vector> langBarButtons_; + winrt::com_ptr langBarMgr_; + std::vector> langBarButtons_; std::vector preservedKeys_; std::vector compartmentMonitors_; diff --git a/libIME/Window.cpp b/libIME/Window.cpp deleted file mode 100644 index 394fef8..0000000 --- a/libIME/Window.cpp +++ /dev/null @@ -1,99 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#include "Window.h" - -namespace Ime { - -static TCHAR g_imeWindowClassName[] = _T("LibImeWindow"); -static HINSTANCE g_hinstance = NULL; - -std::map Window::hwndMap_; - -Window::Window(): - hwnd_(NULL) { -} - -Window::~Window() { - if(hwnd_) - DestroyWindow(hwnd_); -} - -bool Window::create(HWND parent, DWORD style, DWORD exStyle) { - hwnd_ = CreateWindowEx(exStyle, g_imeWindowClassName, NULL, style, - 0, 0, 0, 0, parent, NULL, g_hinstance, NULL); - if(hwnd_) { - // associate this object with the hwnd - hwndMap_[hwnd_] = this; - return true; - } - return false; -} - -void Window::destroy(void) { - if( hwnd_ ) - DestroyWindow(hwnd_); - hwnd_ = NULL; -} - -// static -LRESULT Window::_wndProc(HWND hwnd , UINT msg, WPARAM wp , LPARAM lp) { - // get object pointer from the hwnd - Window* window = (Window*)hwndMap_[hwnd]; - // FIXME: we cannot handle WM_CREATE in Window::wndProc member function - // because the message is sent before CreateWindow returns, and - // we do SetWindowLongPtr() only after CreateWindow(). - if(window) { - LRESULT result = window->wndProc(msg, wp, lp); - if(msg == WM_NCDESTROY) - hwndMap_.erase(hwnd); - return result; - } - return ::DefWindowProc(hwnd, msg, wp, lp); -} - -LRESULT Window::wndProc(UINT msg, WPARAM wp , LPARAM lp) { - return ::DefWindowProc(hwnd_, msg, wp, lp); -} - -bool Window::registerClass(HINSTANCE hinstance) { - - if(!g_hinstance) - g_hinstance = hinstance; - - WNDCLASSEX wc; - wc.cbSize = sizeof(WNDCLASSEX); - wc.style = CS_IME; // FIXME: is this needed? - wc.lpfnWndProc = (WNDPROC)Window::_wndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hinstance; - wc.hCursor = LoadCursor(NULL, IDC_ARROW); - wc.hIcon = NULL; - wc.lpszMenuName = (LPTSTR)NULL; - wc.lpszClassName = g_imeWindowClassName; - wc.hbrBackground = NULL; - wc.hIconSm = NULL; - - if(!::RegisterClassEx((LPWNDCLASSEX)&wc)) - return false; - return true; -} - -} // namespace Ime diff --git a/libIME/Window.h b/libIME/Window.h deleted file mode 100644 index b6e6bdc..0000000 --- a/libIME/Window.h +++ /dev/null @@ -1,98 +0,0 @@ -// -// Copyright (C) 2013 Hong Jen Yee (PCMan) -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -// Boston, MA 02110-1301, USA. -// - -#if !defined(AFX_WINDOW_H__86D89A4E_5040_4FF8_B991_0C7D6502119D__INCLUDED_) -#define AFX_WINDOW_H__86D89A4E_5040_4FF8_B991_0C7D6502119D__INCLUDED_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -#include -#include -#include - -namespace Ime { - -class Window { -public: - - Window(); - virtual ~Window(); - - HWND hwnd(){ return hwnd_; } - - bool create(HWND parent, DWORD style, DWORD exStyle = 0); - void destroy(void); - - bool isVisible(){ - return !!IsWindowVisible(hwnd_); - } - - bool isWindow(){ - return !!IsWindow(hwnd_); - } - - void size(int* width, int* height) { - RECT rc; - rect(&rc); - *width = (rc.right - rc.left); - *height = (rc.bottom - rc.top); - } - - void resize(int width, int height) { - ::SetWindowPos(hwnd_, HWND_TOP, 0, 0, width, height, SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE); - } - - void clientRect(RECT* rect) { - ::GetClientRect(hwnd_, rect); - } - - void rect(RECT* rect) { - ::GetWindowRect(hwnd_, rect); - } - - void show() { - if( hwnd_ ) - ShowWindow(hwnd_, SW_SHOWNA); - } - - void hide(){ ShowWindow(hwnd_, SW_HIDE); } - - void refresh() { InvalidateRect( hwnd_, NULL, FALSE ); } - - static bool registerClass(HINSTANCE hinstance); - - static Window* fromHwnd(HWND hwnd) { - std::map::iterator it = hwndMap_.find(hwnd); - return it != hwndMap_.end() ? it->second : NULL; - } - -protected: - static LRESULT _wndProc(HWND hwnd , UINT msg, WPARAM wp , LPARAM lp); - virtual LRESULT wndProc(UINT msg, WPARAM wp , LPARAM lp); - -protected: - HWND hwnd_; - static std::map hwndMap_; -}; - -} - -#endif // !defined(AFX_WINDOW_H__86D89A4E_5040_4FF8_B991_0C7D6502119D__INCLUDED_) diff --git a/libIME/WindowsVersion.h b/libIME/WindowsVersion.h deleted file mode 100644 index 4ccc3eb..0000000 --- a/libIME/WindowsVersion.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef IME_WINDOWS_VERSION_H -#define IME_WINDOWS_VERSION_H -#pragma once - -#include - -namespace Ime { - -// Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx - -class WindowsVersion { -public: - WindowsVersion(void) { - // check Windows version (windows 8 is 6.2, and 7 is 6.1) - DWORD winVer = ::GetVersion(); - major_ = (DWORD)(LOBYTE(LOWORD(winVer))); - minor_ = (DWORD)(HIBYTE(LOWORD(winVer))); - } - - ~WindowsVersion(void) { - } - - bool isWindows8Above() const { - // Windows 8: 6.2 - return (major_ > 6 || (major_ == 6 && minor_ >= 2)); - } - - bool isWindows7() const { - // Windows 7: 6.1 - // Windows server 2008 R2: 6.1 - return (major_ == 6 && minor_ == 1); - } - - bool isWindowsVista() const { - // Windows Vista: 6.0 - // Windows server 2008: 6.0 - return (major_ == 6 && minor_ == 0); - } - - bool isWindowsXp() const { - // Windows xp: 5.1 - // Windows xp 64 bit, server 2003: 5.2 - return (major_ == 5 && (minor_ == 1 || minor_ == 2)); - } - - DWORD major() const { - return major_; - } - - DWORD minor() const { - return minor_; - } - -private: - DWORD major_; - DWORD minor_; -}; - -} - -#endif diff --git a/libIME/idl/libime2.idl b/libIME/idl/libime2.idl new file mode 100644 index 0000000..32d5c37 --- /dev/null +++ b/libIME/idl/libime2.idl @@ -0,0 +1,71 @@ +import "unknwn.idl"; +import "msctf.idl"; + +[ +object, +uuid(d73284e1-59aa-42ef-84ca-1633beca464b), +local +] +interface IWindow : IUnknown +{ + HWND hwnd(); + boolean create(HWND parent, DWORD style, [defaultvalue(0)] DWORD exStyle); + void destroy(); + boolean isVisible(); + boolean isWindow(); + void move(int x, int y); + void size([out] int *width, [out] int *height); + void resize(int width, int height); + void clientRect([out] RECT *rect); + void rect([out] RECT *rect); + void show(); + void hide(); + void refresh(); + + LRESULT wndProc(UINT msg, WPARAM wp, LPARAM lp); +} + +typedef struct _KeyEvent { + UINT type; + UINT keyCode; + UINT charCode; + LPARAM lParapm; + BYTE keyStates[256]; +} KeyEvent; + +[ +object, +uuid(d4eee9d6-60a0-4169-b3b8-d99f66ebe61a), +local +] +interface ICandidateWindow : IWindow +{ + void setFontSize(DWORD fontSize); + void add(LPCWSTR item, WCHAR selKey); + WCHAR currentSelKey(); + void clear(); + void setCandPerRow(int n); + void setUseCursor(boolean use); + boolean filterKeyEvent(UINT16 keyCode); + boolean hasResult(); + void recalculateSize(); +} + +[ +object, +uuid(7375ef7b-4564-46eb-b8d1-e27228428623), +local +] +interface IMessageWindow : IWindow +{ + const unsigned long ID_TIMEOUT = 1; + void setFontSize(DWORD fontSize); + void setText(LPCWSTR text); +} + +[local] void LibIME2Init(); +[local] void CreateImeWindow([out] void **window); +[local] void CreateMessageWindow(HWND parent, [in] LPCWSTR image_path, [out] void **messagewindow); +[local] void CreateCandidateWindow(HWND parent, [in] LPCWSTR image_path, [out] void **candidatewindow); +[local] IWindow *ImeWindowFromHwnd(HWND hwnd); +[local] boolean ImeWindowRegisterClass(HINSTANCE hinstance); \ No newline at end of file diff --git a/libIME/src/gfx.rs b/libIME/src/gfx.rs new file mode 100644 index 0000000..e8acccb --- /dev/null +++ b/libIME/src/gfx.rs @@ -0,0 +1,273 @@ +use core::slice; +use std::ptr::null_mut; + +use nine_patch_drawable::NinePatchDrawable; +use nine_patch_drawable::PatchKind; +use nine_patch_drawable::Section; +use windows::core::*; +use windows::Foundation::Numerics::*; +use windows::Win32::Foundation::*; +use windows::Win32::Graphics::Direct2D::Common::*; +use windows::Win32::Graphics::Direct2D::*; +use windows::Win32::Graphics::Direct3D::*; +use windows::Win32::Graphics::Direct3D11::*; +use windows::Win32::Graphics::DirectComposition::*; +use windows::Win32::Graphics::Dxgi::Common::*; +use windows::Win32::Graphics::Dxgi::*; +use windows::Win32::Graphics::Gdi::*; +use windows::Win32::Graphics::Imaging::*; +use windows::Win32::System::Com::*; + +#[derive(Debug)] +pub(crate) struct NinePatchBitmap { + bitmap: IWICBitmap, + nine_patch: NinePatchDrawable, +} + +impl NinePatchBitmap { + pub(crate) fn new(image_path: PCWSTR) -> Result { + unsafe { + let wicfactory: IWICImagingFactory = + CoCreateInstance(&CLSID_WICImagingFactory, None, CLSCTX_INPROC_SERVER)?; + let decoder = wicfactory.CreateDecoderFromFilename( + image_path, + None, + GENERIC_READ, + WICDecodeMetadataCacheOnDemand, + )?; + let frame = decoder.GetFrame(0)?; + let converter = wicfactory.CreateFormatConverter()?; + converter.Initialize( + &frame, + &GUID_WICPixelFormat32bppPRGBA, + WICBitmapDitherTypeNone, + None, + 0.0, + WICBitmapPaletteTypeCustom, + )?; + let bitmap = wicfactory.CreateBitmapFromSource(&converter, WICBitmapCacheOnDemand)?; + let mut width = 0; + let mut height = 0; + bitmap.GetSize(&mut width, &mut height)?; + let lock = bitmap.Lock( + &WICRect { + X: 0, + Y: 0, + Width: width as i32, + Height: height as i32, + }, + 1, + )?; + let stride = lock.GetStride()?; + + let mut len = 0; + let mut data = null_mut(); + lock.GetDataPointer(&mut len, &mut data)?; + let data_slice = slice::from_raw_parts(data, len as usize); + + let nine_patch = NinePatchDrawable::new( + data_slice, + stride as usize, + width as usize, + height as usize, + ) + .unwrap_or_else(|_| NinePatchDrawable { + width: width as usize, + height: height as usize, + h_sections: vec![Section { + start: 1.0, + len: width as f32 - 1.0, + kind: PatchKind::Stretching, + }], + v_sections: vec![Section { + start: 1.0, + len: width as f32 - 1.0, + kind: PatchKind::Stretching, + }], + margin_left: 0.0, + margin_top: 0.0, + margin_right: 0.0, + margin_bottom: 0.0, + }); + Ok(NinePatchBitmap { bitmap, nine_patch }) + } + } + pub(crate) fn draw_bitmap(&self, dc: &ID2D1DeviceContext, rect: D2D_RECT_F) -> Result<()> { + unsafe { + let bitmap = dc.CreateBitmapFromWicBitmap(&self.bitmap, None)?; + let patches = self.nine_patch.scale_to( + (rect.right - rect.left) as usize, + (rect.bottom - rect.top) as usize, + ); + for patch in patches { + let source = D2D_RECT_F { + left: patch.source.left, + top: patch.source.top, + right: patch.source.right, + bottom: patch.source.bottom, + }; + let target = D2D_RECT_F { + left: patch.target.left, + top: patch.target.top, + right: patch.target.right, + bottom: patch.target.bottom, + }; + dc.DrawBitmap( + &bitmap, + Some(&target), + 1.0, + D2D1_INTERPOLATION_MODE_LINEAR, + Some(&source), + None, + ); + } + Ok(()) + } + } + pub(crate) fn margin(&self) -> f32 { + self.nine_patch.margin_top + } +} + +pub(crate) fn create_color(gdi_color_index: SYS_COLOR_INDEX) -> D2D1_COLOR_F { + let color = unsafe { GetSysColor(gdi_color_index) }; + D2D1_COLOR_F { + r: (color & 0xFF) as f32 / 255.0, + g: ((color >> 8) & 0xFF) as f32 / 255.0, + b: ((color >> 16) & 0xFF) as f32 / 255.0, + a: 1.0, + } +} + +pub(crate) fn create_brush( + target: &ID2D1DeviceContext, + color: D2D1_COLOR_F, +) -> Result { + let properties = D2D1_BRUSH_PROPERTIES { + opacity: 0.8, + transform: Matrix3x2::identity(), + }; + + unsafe { target.CreateSolidColorBrush(&color, Some(&properties)) } +} + +pub(crate) fn create_device_with_type(drive_type: D3D_DRIVER_TYPE) -> Result { + let flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; + + let mut device = None; + + unsafe { + D3D11CreateDevice( + None, + drive_type, + None, + flags, + None, + D3D11_SDK_VERSION, + Some(&mut device), + None, + None, + ) + .map(|()| device.unwrap()) + } +} + +pub(crate) fn create_device() -> Result { + let mut result = create_device_with_type(D3D_DRIVER_TYPE_HARDWARE); + + if let Err(err) = &result { + if err.code() == DXGI_ERROR_UNSUPPORTED { + result = create_device_with_type(D3D_DRIVER_TYPE_WARP); + } + } + + result +} + +pub(crate) fn create_render_target( + factory: &ID2D1Factory1, + device: &ID3D11Device, +) -> Result { + unsafe { + let d2device = factory.CreateDevice(&device.cast::()?)?; + + let target = d2device.CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE)?; + + target.SetUnitMode(D2D1_UNIT_MODE_DIPS); + + Ok(target) + } +} + +pub(crate) fn get_dxgi_factory(device: &ID3D11Device) -> Result { + let dxdevice = device.cast::()?; + unsafe { dxdevice.GetAdapter()?.GetParent() } +} + +pub(crate) fn create_swapchain_bitmap( + swapchain: &IDXGISwapChain1, + target: &ID2D1DeviceContext, + dpi: f32, +) -> Result<()> { + let surface: IDXGISurface = unsafe { swapchain.GetBuffer(0)? }; + + let props = D2D1_BITMAP_PROPERTIES1 { + pixelFormat: D2D1_PIXEL_FORMAT { + format: DXGI_FORMAT_B8G8R8A8_UNORM, + alphaMode: D2D1_ALPHA_MODE_PREMULTIPLIED, + }, + dpiX: dpi, + dpiY: dpi, + bitmapOptions: D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, + ..Default::default() + }; + + unsafe { + let bitmap = target.CreateBitmapFromDxgiSurface(&surface, Some(&props))?; + target.SetTarget(&bitmap); + }; + + Ok(()) +} + +pub(crate) fn create_swapchain( + device: &ID3D11Device, + width: u32, + height: u32, +) -> Result { + let factory = get_dxgi_factory(device)?; + + let props = DXGI_SWAP_CHAIN_DESC1 { + Width: width, + Height: height, + Format: DXGI_FORMAT_B8G8R8A8_UNORM, + SampleDesc: DXGI_SAMPLE_DESC { + Count: 1, + Quality: 0, + }, + BufferUsage: DXGI_USAGE_RENDER_TARGET_OUTPUT, + BufferCount: 2, + SwapEffect: DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, + AlphaMode: DXGI_ALPHA_MODE_PREMULTIPLIED, + ..Default::default() + }; + + unsafe { factory.CreateSwapChainForComposition(device, &props, None) } +} + +pub(crate) fn setup_direct_composition( + device: &ID3D11Device, + window: HWND, + swapchain: &IDXGISwapChain, +) -> Result { + let dxgidevice = device.cast::()?; + unsafe { + let dcompdevice: IDCompositionDevice = DCompositionCreateDevice(&dxgidevice)?; + let dcomptarget: IDCompositionTarget = dcompdevice.CreateTargetForHwnd(window, true)?; + let visual: IDCompositionVisual = dcompdevice.CreateVisual()?; + visual.SetContent(swapchain)?; + dcomptarget.SetRoot(&visual)?; + dcompdevice.Commit()?; + Ok(dcomptarget) + } +} diff --git a/libIME/src/lib.rs b/libIME/src/lib.rs new file mode 100644 index 0000000..52fe1d0 --- /dev/null +++ b/libIME/src/lib.rs @@ -0,0 +1,7 @@ +mod gfx; +mod window; + +#[no_mangle] +unsafe extern "C" fn LibIME2Init() { + win_dbg_logger::rust_win_dbg_logger_init_debug(); +} diff --git a/libIME/src/window/candidate_window.rs b/libIME/src/window/candidate_window.rs new file mode 100644 index 0000000..72401f7 --- /dev/null +++ b/libIME/src/window/candidate_window.rs @@ -0,0 +1,639 @@ +use core::f32; +use std::{ + cell::{Cell, RefCell}, + ffi::{c_int, c_uint, c_void}, + ops::Deref, +}; + +use windows::core::*; +use windows::Win32::Foundation::*; +use windows::Win32::Graphics::Direct2D::Common::*; +use windows::Win32::Graphics::Direct2D::*; +use windows::Win32::Graphics::DirectComposition::*; +use windows::Win32::Graphics::DirectWrite::*; +use windows::Win32::Graphics::Dxgi::Common::*; +use windows::Win32::Graphics::Dxgi::*; +use windows::Win32::Graphics::Gdi::*; +use windows::Win32::UI::Input::KeyboardAndMouse::*; +use windows::Win32::UI::TextServices::*; +use windows::Win32::UI::WindowsAndMessaging::*; + +use super::{IWindow, IWindow_Impl, IWindow_Vtbl, Window}; +use crate::gfx::*; + +#[interface("d4eee9d6-60a0-4169-b3b8-d99f66ebe61a")] +unsafe trait ICandidateWindow: IWindow { + fn set_font_size(&self, font_size: u32); + fn add(&self, item: PCWSTR, sel_key: u16); + fn current_sel_key(&self) -> u16; + fn clear(&self); + fn set_cand_per_row(&self, n: c_int); + fn set_use_cursor(&self, r#use: bool); + fn filter_key_event(&self, key_event: u16) -> bool; + fn has_result(&self) -> bool; + fn recalculate_size(&self); +} + +#[derive(Debug)] +#[implement(ICandidateWindow, IWindow, ITfUIElement, ITfCandidateListUIElement)] +struct CandidateWindow { + items: RefCell>, + sel_keys: RefCell>, + current_sel: Cell, + has_result: Cell, + cand_per_row: Cell, + use_cursor: Cell, + selkey_width: Cell, + text_width: Cell, + item_height: Cell, + factory: ID2D1Factory1, + dwrite_factory: IDWriteFactory1, + text_format: RefCell, + dcomptarget: RefCell>, + target: RefCell>, + swapchain: RefCell>, + brush: RefCell>, + nine_patch_bitmap: NinePatchBitmap, + dpi: f32, + window: ComObject, +} + +const ROW_SPACING: u32 = 4; +const COL_SPACING: u32 = 8; + +impl CandidateWindow { + fn recalculate_size(&self) -> Result<()> { + let margin = self.nine_patch_bitmap.margin() as u32; + if self.items.borrow().is_empty() { + unsafe { self.window.resize(margin as i32 * 2, margin as i32 * 2) }; + self.resize_swap_chain(margin * 2, margin * 2)?; + } + + let items_len = self.items.borrow().len(); + let mut selkey_width = 0.0; + let mut text_width = 0.0; + let mut item_height = 0.0; + let selkey = "?. ".to_string(); + let mut selkey = selkey.encode_utf16().collect::>(); + for i in 0..items_len { + selkey[0] = *self.sel_keys.borrow().get(i).unwrap(); + + let mut selkey_metrics = DWRITE_TEXT_METRICS::default(); + let mut item_metrics = DWRITE_TEXT_METRICS::default(); + unsafe { + let text_layout = self.dwrite_factory.CreateTextLayout( + &selkey, + self.text_format.borrow().deref(), + f32::MAX, + f32::MAX, + )?; + text_layout.GetMetrics(&mut selkey_metrics)?; + + let items = self.items.borrow(); + let text = items.get(i).unwrap().as_wide(); + let text_layout = self.dwrite_factory.CreateTextLayout( + text, + self.text_format.borrow().deref(), + f32::MAX, + f32::MAX, + )?; + text_layout.GetMetrics(&mut item_metrics)?; + } + + selkey_width = f32::max( + selkey_width, + selkey_metrics.widthIncludingTrailingWhitespace, + ); + text_width = f32::max(text_width, item_metrics.widthIncludingTrailingWhitespace); + item_height = f32::max(item_metrics.height, selkey_metrics.height).max(item_height); + } + + self.selkey_width.set(selkey_width); + self.text_width.set(text_width); + self.item_height.set(item_height); + let cand_per_row = self.cand_per_row.get() as u32; + let (width, height) = if items_len <= self.cand_per_row.get() { + ( + items_len as u32 * (selkey_width + text_width) as u32 + + COL_SPACING * (items_len - 1) as u32 + + margin * 2, + item_height as u32 + margin * 2, + ) + } else { + ( + cand_per_row * (selkey_width + text_width) as u32 + + COL_SPACING * (cand_per_row) + + margin * 2, + (item_height as u32 + ROW_SPACING) * (items_len as u32).div_ceil(cand_per_row) + + margin * 2, + ) + }; + + unsafe { self.window.resize(width as i32, height as i32) }; + self.resize_swap_chain(width, height)?; + + Ok(()) + } + // FIXME: extract + fn resize_swap_chain(&self, width: u32, height: u32) -> Result<()> { + let target = self.target.borrow(); + let swapchain = self.swapchain.borrow(); + + if target.is_some() { + let target = target.as_ref().unwrap(); + let swapchain = swapchain.as_ref().unwrap(); + unsafe { target.SetTarget(None) }; + + if unsafe { + swapchain + .ResizeBuffers( + 0, + width, + height, + DXGI_FORMAT_B8G8R8A8_UNORM, + DXGI_SWAP_CHAIN_FLAG(0), + ) + .is_ok() + } { + create_swapchain_bitmap(swapchain, target, self.dpi)?; + } else { + self.target.take(); + self.swapchain.take(); + self.brush.take(); + } + + self.on_paint()?; + } + + Ok(()) + } + fn create_target(&self) -> Result<()> { + let create_target = self.target.borrow().is_none(); + if create_target { + let device = create_device()?; + let target = create_render_target(&self.factory, &device)?; + unsafe { target.SetDpi(self.dpi, self.dpi) }; + + let mut rc = RECT::default(); + unsafe { GetClientRect(self.window.hwnd.get(), &mut rc)? }; + + let swapchain = create_swapchain( + &device, + (rc.right - rc.left) as u32, + (rc.bottom - rc.top) as u32, + )?; + create_swapchain_bitmap(&swapchain, &target, self.dpi)?; + let dcomptarget = + setup_direct_composition(&device, self.window.hwnd.get(), &swapchain)?; + + self.brush + .replace(create_brush(&target, create_color(COLOR_INFOTEXT)).ok()); + self.dcomptarget.replace(Some(dcomptarget)); + self.target.replace(Some(target)); + self.swapchain.replace(Some(swapchain)); + } + Ok(()) + } + fn on_paint(&self) -> Result<()> { + self.create_target()?; + + let target = self.target.borrow(); + let swapchain = self.swapchain.borrow(); + let target = target.as_ref().unwrap(); + + unsafe { + let mut rc = RECT::default(); + GetClientRect(self.window.hwnd.get(), &mut rc)?; + + target.BeginDraw(); + let rect = D2D_RECT_F { + top: rc.top as f32, + left: rc.left as f32, + right: rc.right as f32, + bottom: rc.bottom as f32, + }; + self.nine_patch_bitmap.draw_bitmap(target, rect)?; + + let mut col = 0; + let margin = self.nine_patch_bitmap.margin(); + let mut x = margin; + let mut y = margin; + + for i in 0..self.items.borrow().len() { + self.paint_item(target, i, x, y)?; + col += 1; + if col >= self.cand_per_row.get() { + col = 0; + x = margin; + y += self.item_height.get() + ROW_SPACING as f32; + } else { + x += COL_SPACING as f32 + self.selkey_width.get() + self.text_width.get(); + } + } + target.EndDraw(None, None)?; + + if swapchain + .as_ref() + .unwrap() + .Present(1, DXGI_PRESENT(0)) + .is_err() + { + _ = target; + _ = swapchain; + self.target.take(); + self.swapchain.take(); + self.brush.take(); + } + } + + Ok(()) + } + + fn paint_item(&self, dc: &ID2D1DeviceContext, i: usize, left: f32, top: f32) -> Result<()> { + let mut text_rect = D2D_RECT_F { + left, + top, + right: left + self.selkey_width.get(), + bottom: top + self.item_height.get(), + }; + + // FIXME: make the color of strings configurable + let sel_key_color = create_color(COLOR_HOTLIGHT); + let text_color = create_color(COLOR_WINDOWTEXT); + let selected_text_color = D2D1_COLOR_F { + r: 1.0, + g: 1.0, + b: 1.0, + a: 1.0, + }; + let selkey = "?. ".to_string(); + let mut selkey = selkey.encode_utf16().collect::>(); + selkey[0] = *self.sel_keys.borrow().get(i).unwrap(); + + unsafe { + let selkey_brush = dc.CreateSolidColorBrush(&sel_key_color, None)?; + + dc.DrawText( + &selkey, + self.text_format.borrow().deref(), + &text_rect, + &selkey_brush, + D2D1_DRAW_TEXT_OPTIONS_NONE, + DWRITE_MEASURING_MODE_NATURAL, + ); + } + + text_rect.left += self.selkey_width.get(); + text_rect.right = text_rect.left + self.text_width.get(); + + let items = self.items.borrow(); + let item = items.get(i).unwrap(); + unsafe { + let text_brush = dc.CreateSolidColorBrush(&text_color, None)?; + let selected_text_brush = dc.CreateSolidColorBrush(&selected_text_color, None)?; + + if self.use_cursor.get() && i == self.current_sel.get() { + dc.FillRectangle(&text_rect, &text_brush); + dc.DrawText( + item.as_wide(), + self.text_format.borrow().deref(), + &text_rect, + &selected_text_brush, + D2D1_DRAW_TEXT_OPTIONS_NONE, + DWRITE_MEASURING_MODE_NATURAL, + ); + } else { + dc.DrawText( + item.as_wide(), + self.text_format.borrow().deref(), + &text_rect, + &text_brush, + D2D1_DRAW_TEXT_OPTIONS_NONE, + DWRITE_MEASURING_MODE_NATURAL, + ); + } + } + + Ok(()) + } +} + +#[no_mangle] +unsafe extern "C" fn CreateCandidateWindow( + parent: HWND, + image_path: PCWSTR, + ret: *mut *mut c_void, +) { + let window = Window::new().into_object(); + window.create( + parent, + (WS_POPUP | WS_CLIPCHILDREN).0, + (WS_EX_TOOLWINDOW | WS_EX_TOPMOST).0, + ); + + let factory: ID2D1Factory1 = D2D1CreateFactory( + D2D1_FACTORY_TYPE_SINGLE_THREADED, + Some(&D2D1_FACTORY_OPTIONS::default()), + ) + .expect("failed to create Direct2D factory"); + + let mut dpi = 0.0; + let mut dpiy = 0.0; + factory.GetDesktopDpi(&mut dpi, &mut dpiy); + + let dwrite_factory: IDWriteFactory1 = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED).unwrap(); + let text_format = dwrite_factory + .CreateTextFormat( + w!("Segoe UI"), + None, + DWRITE_FONT_WEIGHT_NORMAL, + DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_STRETCH_NORMAL, + 16.0, + w!(""), + ) + .unwrap(); + + let nine_patch_bitmap = NinePatchBitmap::new(image_path).unwrap(); + + let candidate_window = CandidateWindow { + items: RefCell::new(vec![]), + sel_keys: RefCell::new(vec![]), + current_sel: Cell::new(0), + has_result: Cell::new(false), + cand_per_row: Cell::new(10), + use_cursor: Cell::new(true), + selkey_width: Cell::new(0.0), + text_width: Cell::new(0.0), + item_height: Cell::new(0.0), + factory, + dwrite_factory, + text_format: RefCell::new(text_format), + dcomptarget: None.into(), + target: None.into(), + swapchain: None.into(), + brush: None.into(), + nine_patch_bitmap, + dpi, + window, + } + .into_object(); + Window::register_hwnd(candidate_window.hwnd(), candidate_window.to_interface()); + ret.write( + candidate_window + .into_interface::() + .into_raw(), + ) +} + +impl ICandidateWindow_Impl for CandidateWindow_Impl { + unsafe fn set_font_size(&self, font_size: u32) { + self.text_format.replace( + self.dwrite_factory + .CreateTextFormat( + w!("Segoe UI"), + None, + DWRITE_FONT_WEIGHT_NORMAL, + DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_STRETCH_NORMAL, + font_size as f32, + w!(""), + ) + .unwrap(), + ); + } + + unsafe fn add(&self, item: PCWSTR, sel_key: u16) { + self.items.borrow_mut().push(item.to_hstring().unwrap()); + self.sel_keys.borrow_mut().push(sel_key); + } + + unsafe fn current_sel_key(&self) -> u16 { + *self.sel_keys.borrow().get(self.current_sel.get()).unwrap() + } + + unsafe fn clear(&self) { + self.items.borrow_mut().clear(); + self.sel_keys.borrow_mut().clear(); + self.current_sel.set(0); + self.has_result.set(false); + } + + unsafe fn set_cand_per_row(&self, n: c_int) { + if n as usize != self.cand_per_row.get() { + self.cand_per_row.set(n as usize); + } + } + + unsafe fn set_use_cursor(&self, r#use: bool) { + self.use_cursor.set(r#use); + if self.is_visible() { + self.refresh(); + } + } + + unsafe fn filter_key_event(&self, key_code: u16) -> bool { + let mut current_sel = self.current_sel.get(); + let old_sel = self.current_sel.get(); + let cand_per_row = self.cand_per_row.get(); + match VIRTUAL_KEY(key_code) { + VK_UP => { + if current_sel >= cand_per_row { + current_sel -= cand_per_row; + } + } + VK_DOWN => { + if current_sel + cand_per_row < self.items.borrow().len() { + current_sel += cand_per_row; + } + } + VK_LEFT => { + if current_sel >= 1 { + current_sel -= 1; + } + } + VK_RIGHT => { + if current_sel < self.items.borrow().len() - 1 { + current_sel += 1; + } + } + VK_RETURN => { + self.has_result.set(true); + self.current_sel.set(current_sel); + return true; + } + _ => return false, + } + + self.current_sel.set(current_sel); + + if current_sel != old_sel { + self.refresh(); + return true; + } + false + } + + unsafe fn has_result(&self) -> bool { + self.has_result.get() + } + + unsafe fn recalculate_size(&self) { + let _ = self.this.recalculate_size(); + } +} + +impl IWindow_Impl for CandidateWindow_Impl { + unsafe fn hwnd(&self) -> HWND { + self.window.hwnd() + } + + unsafe fn create(&self, parent: HWND, style: u32, ex_style: u32) -> bool { + self.window.create(parent, style, ex_style) + } + + unsafe fn destroy(&self) { + self.window.destroy() + } + + unsafe fn is_visible(&self) -> bool { + self.window.is_visible() + } + + unsafe fn is_window(&self) -> bool { + self.window.is_window() + } + + unsafe fn r#move(&self, x: c_int, y: c_int) { + self.window.r#move(x, y) + } + + unsafe fn size(&self, width: *mut c_int, height: *mut c_int) { + self.window.size(width, height) + } + + unsafe fn resize(&self, width: c_int, height: c_int) { + self.window.resize(width, height) + } + + unsafe fn client_rect(&self, rect: *mut RECT) { + self.window.client_rect(rect) + } + + unsafe fn rect(&self, rect: *mut RECT) { + self.window.rect(rect) + } + + unsafe fn show(&self) { + self.window.show() + } + + unsafe fn hide(&self) { + self.window.hide() + } + + unsafe fn refresh(&self) { + self.window.refresh() + } + + unsafe fn wnd_proc(&self, msg: c_uint, wp: WPARAM, lp: LPARAM) -> LRESULT { + match msg { + WM_PAINT => { + let mut ps = PAINTSTRUCT::default(); + BeginPaint(self.hwnd(), &mut ps); + let _ = self.on_paint(); + let _ = EndPaint(self.hwnd(), &ps); + LRESULT(0) + } + WM_NCDESTROY => { + self.target.take(); + self.swapchain.take(); + self.brush.take(); + LRESULT(0) + } + _ => self.window.wnd_proc(msg, wp, lp), + } + } +} + +impl ITfUIElement_Impl for CandidateWindow_Impl { + fn GetDescription(&self) -> Result { + Ok("Candidate window~".into()) + } + + fn GetGUID(&self) -> Result { + Ok(GUID::from_values( + 0xBD7CCC94, + 0x57CD, + 0x41D3, + [0xA7, 0x89, 0xAF, 0x47, 0x89, 0xC, 0xEB, 0x29], + )) + } + + fn Show(&self, bshow: BOOL) -> Result<()> { + unsafe { + if bshow.as_bool() { + self.show(); + } else { + self.hide(); + } + } + Ok(()) + } + + fn IsShown(&self) -> Result { + unsafe { Ok(self.is_visible().into()) } + } +} + +impl ITfCandidateListUIElement_Impl for CandidateWindow_Impl { + fn GetUpdatedFlags(&self) -> Result { + // Update all + Ok(TF_CLUIE_DOCUMENTMGR + | TF_CLUIE_COUNT + | TF_CLUIE_SELECTION + | TF_CLUIE_STRING + | TF_CLUIE_PAGEINDEX + | TF_CLUIE_CURRENTPAGE) + } + + fn GetDocumentMgr(&self) -> Result { + // TODO + Err(Error::empty()) + } + + fn GetCount(&self) -> Result { + Ok(self.items.borrow().len().min(10) as u32) + } + + fn GetSelection(&self) -> Result { + Ok(self.current_sel.get() as u32) + } + + fn GetString(&self, uindex: u32) -> Result { + self.items + .borrow() + .get(uindex as usize) + .map(|hstr| hstr.as_wide()) + .map(|wstr| BSTR::from_wide(wstr)) + .ok_or(Error::empty())? + } + + fn GetPageIndex(&self, pindex: *mut u32, usize: u32, pupagecnt: *mut u32) -> Result<()> { + unsafe { + pupagecnt.write(1); + if usize > 0 { + pindex.write(0); + } + } + Ok(()) + } + + fn SetPageIndex(&self, _pindex: *const u32, _upagecnt: u32) -> Result<()> { + Ok(()) + } + + fn GetCurrentPage(&self) -> Result { + Ok(0) + } +} diff --git a/libIME/src/window/message_window.rs b/libIME/src/window/message_window.rs new file mode 100644 index 0000000..d555433 --- /dev/null +++ b/libIME/src/window/message_window.rs @@ -0,0 +1,347 @@ +use std::{ + cell::RefCell, + ffi::{c_int, c_uint, c_void}, + ops::Deref, +}; + +use windows::core::*; +use windows::Win32::Foundation::*; +use windows::Win32::Graphics::Direct2D::Common::*; +use windows::Win32::Graphics::Direct2D::*; +use windows::Win32::Graphics::DirectComposition::*; +use windows::Win32::Graphics::DirectWrite::*; +use windows::Win32::Graphics::Dxgi::Common::*; +use windows::Win32::Graphics::Dxgi::*; +use windows::Win32::Graphics::Gdi::*; +use windows::Win32::UI::WindowsAndMessaging::*; + +use super::{IWindow, IWindow_Impl, IWindow_Vtbl, Window}; +use crate::gfx::*; + +const ID_TIMEOUT: usize = 1; + +#[interface("7375ef7b-4564-46eb-b8d1-e27228428623")] +unsafe trait IMessageWindow: IWindow { + fn set_font_size(&self, font_size: u32); + fn set_text(&self, text: PCWSTR); +} + +#[derive(Debug)] +#[implement(IMessageWindow, IWindow)] +struct MessageWindow { + text: RefCell, + factory: ID2D1Factory1, + dwrite_factory: IDWriteFactory1, + text_format: RefCell, + target: RefCell>, + swapchain: RefCell>, + dcomptarget: RefCell>, + brush: RefCell>, + nine_patch_bitmap: NinePatchBitmap, + dpi: f32, + window: ComObject, +} + +impl MessageWindow { + fn recalculate_size(&self) -> Result<()> { + let text_layout = unsafe { + self.dwrite_factory.CreateTextLayout( + self.text.borrow().as_wide(), + self.text_format.borrow().deref(), + f32::MAX, + f32::MAX, + )? + }; + let mut metrics = DWRITE_TEXT_METRICS::default(); + unsafe { text_layout.GetMetrics(&mut metrics).unwrap() }; + + let margin = self.nine_patch_bitmap.margin(); + let width = metrics.width + margin * 2.0; + let height = metrics.height + margin * 2.0; + unsafe { + SetWindowPos( + self.window.hwnd.get(), + HWND_TOPMOST, + 0, + 0, + width as i32, + height as i32, + SWP_NOACTIVATE | SWP_NOMOVE, + )? + }; + self.resize_swap_chain(width as u32, height as u32)?; + + Ok(()) + } + + fn resize_swap_chain(&self, width: u32, height: u32) -> Result<()> { + let target = self.target.borrow(); + let swapchain = self.swapchain.borrow(); + + if target.is_some() { + let target = target.as_ref().unwrap(); + let swapchain = swapchain.as_ref().unwrap(); + unsafe { target.SetTarget(None) }; + + if unsafe { + swapchain + .ResizeBuffers( + 0, + width, + height, + DXGI_FORMAT_UNKNOWN, + DXGI_SWAP_CHAIN_FLAG(0), + ) + .is_ok() + } { + create_swapchain_bitmap(swapchain, target, self.dpi)?; + } else { + self.target.take(); + self.swapchain.take(); + self.brush.take(); + } + + self.on_paint()?; + } + + Ok(()) + } + + fn create_target(&self) -> Result<()> { + let create_target = self.target.borrow().is_none(); + if create_target { + let device = create_device()?; + let target = create_render_target(&self.factory, &device)?; + unsafe { target.SetDpi(self.dpi, self.dpi) }; + + let mut rc = RECT::default(); + unsafe { GetClientRect(self.window.hwnd.get(), &mut rc)? }; + + let swapchain = create_swapchain( + &device, + (rc.right - rc.left) as u32, + (rc.bottom - rc.top) as u32, + )?; + + create_swapchain_bitmap(&swapchain, &target, self.dpi)?; + let dcomptarget = + setup_direct_composition(&device, self.window.hwnd.get(), &swapchain)?; + + self.brush + .replace(create_brush(&target, create_color(COLOR_INFOTEXT)).ok()); + self.dcomptarget.replace(Some(dcomptarget)); + self.target.replace(Some(target)); + self.swapchain.replace(Some(swapchain)); + } + Ok(()) + } + + fn on_paint(&self) -> Result<()> { + self.create_target()?; + + let target = self.target.borrow(); + let swapchain = self.swapchain.borrow(); + let target = target.as_ref().unwrap(); + unsafe { + let mut rc = RECT::default(); + GetClientRect(self.window.hwnd.get(), &mut rc)?; + + target.BeginDraw(); + let rect = D2D_RECT_F { + top: rc.top as f32, + left: rc.left as f32, + right: rc.right as f32, + bottom: rc.bottom as f32, + }; + self.nine_patch_bitmap.draw_bitmap(target, rect)?; + let margin = self.nine_patch_bitmap.margin(); + + target.DrawText( + self.text.borrow().as_wide(), + self.text_format.borrow().deref(), + &D2D_RECT_F { + left: margin, + top: margin, + right: f32::MAX, + bottom: f32::MAX, + }, + self.brush.borrow().as_ref().unwrap(), + D2D1_DRAW_TEXT_OPTIONS_NONE, + DWRITE_MEASURING_MODE_NATURAL, + ); + target.EndDraw(None, None)?; + + if swapchain + .as_ref() + .unwrap() + .Present(1, DXGI_PRESENT(0)) + .is_err() + { + _ = target; + _ = swapchain; + self.target.take(); + self.swapchain.take(); + self.brush.take(); + } + } + + Ok(()) + } +} + +#[no_mangle] +unsafe extern "C" fn CreateMessageWindow(parent: HWND, image_path: PCWSTR, ret: *mut *mut c_void) { + let window = Window::new().into_object(); + window.create( + parent, + (WS_POPUP | WS_CLIPCHILDREN).0, + (WS_EX_TOOLWINDOW | WS_EX_TOPMOST).0, + ); + + let factory: ID2D1Factory1 = D2D1CreateFactory( + D2D1_FACTORY_TYPE_SINGLE_THREADED, + Some(&D2D1_FACTORY_OPTIONS::default()), + ) + .expect("failed to create Direct2D factory"); + + let mut dpi = 0.0; + let mut dpiy = 0.0; + factory.GetDesktopDpi(&mut dpi, &mut dpiy); + + let dwrite_factory: IDWriteFactory1 = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED).unwrap(); + let text_format = dwrite_factory + .CreateTextFormat( + w!("Segoe UI"), + None, + DWRITE_FONT_WEIGHT_NORMAL, + DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_STRETCH_NORMAL, + 16.0, + w!(""), + ) + .unwrap(); + + let nine_patch_bitmap = NinePatchBitmap::new(image_path).unwrap(); + + let message_window = MessageWindow { + text: RefCell::new(h!("").to_owned()), + factory, + dwrite_factory, + text_format: RefCell::new(text_format), + dcomptarget: None.into(), + target: None.into(), + swapchain: None.into(), + brush: None.into(), + nine_patch_bitmap, + dpi, + window, + } + .into_object(); + Window::register_hwnd(message_window.hwnd(), message_window.to_interface()); + ret.write(message_window.into_interface::().into_raw()) +} + +impl IWindow_Impl for MessageWindow_Impl { + unsafe fn hwnd(&self) -> HWND { + self.window.hwnd() + } + + unsafe fn create(&self, parent: HWND, style: u32, ex_style: u32) -> bool { + self.window.create(parent, style, ex_style) + } + + unsafe fn destroy(&self) { + self.window.destroy() + } + + unsafe fn is_visible(&self) -> bool { + self.window.is_visible() + } + + unsafe fn is_window(&self) -> bool { + self.window.is_window() + } + + unsafe fn r#move(&self, x: c_int, y: c_int) { + self.window.r#move(x, y); + } + + unsafe fn size(&self, width: *mut c_int, height: *mut c_int) { + self.window.size(width, height) + } + + unsafe fn resize(&self, width: c_int, height: c_int) { + self.window.resize(width, height) + } + + unsafe fn client_rect(&self, rect: *mut RECT) { + self.window.client_rect(rect) + } + + unsafe fn rect(&self, rect: *mut RECT) { + self.window.rect(rect) + } + + unsafe fn show(&self) { + self.window.show() + } + + unsafe fn hide(&self) { + self.window.hide() + } + + unsafe fn refresh(&self) { + self.window.refresh() + } + + unsafe fn wnd_proc(&self, msg: c_uint, wp: WPARAM, lp: LPARAM) -> LRESULT { + match msg { + WM_PAINT => { + let mut ps = PAINTSTRUCT::default(); + BeginPaint(self.hwnd(), &mut ps); + let _ = self.on_paint(); + let _ = EndPaint(self.hwnd(), &ps); + LRESULT(0) + } + WM_TIMER => { + if wp.0 == ID_TIMEOUT { + self.hide(); + KillTimer(self.hwnd(), ID_TIMEOUT).expect("failed to kill timer"); + } + LRESULT(0) + } + WM_NCDESTROY => { + self.target.take(); + self.swapchain.take(); + self.brush.take(); + LRESULT(0) + } + _ => self.window.wnd_proc(msg, wp, lp), + } + } +} + +impl IMessageWindow_Impl for MessageWindow_Impl { + unsafe fn set_font_size(&self, font_size: u32) { + self.text_format.replace( + self.dwrite_factory + .CreateTextFormat( + w!("Segoe UI"), + None, + DWRITE_FONT_WEIGHT_NORMAL, + DWRITE_FONT_STYLE_NORMAL, + DWRITE_FONT_STRETCH_NORMAL, + font_size as f32, + w!(""), + ) + .unwrap(), + ); + } + unsafe fn set_text(&self, text: PCWSTR) { + self.text.replace(text.to_hstring().unwrap()); + self.recalculate_size().unwrap(); + if self.is_visible() { + self.refresh(); + } + } +} diff --git a/libIME/src/window/mod.rs b/libIME/src/window/mod.rs new file mode 100644 index 0000000..09be715 --- /dev/null +++ b/libIME/src/window/mod.rs @@ -0,0 +1,267 @@ +use std::{ + cell::{Cell, OnceCell, RefCell}, + collections::HashMap, + ffi::{c_int, c_uint, c_void}, + ptr::null_mut, +}; + +use windows::core::*; +use windows::Win32::Foundation::*; +use windows::Win32::Graphics::Gdi::*; +use windows::Win32::UI::WindowsAndMessaging::*; + +mod candidate_window; +mod message_window; + +thread_local! { + static MODULE_HINSTANCE: OnceCell = const { OnceCell::new() }; + static HWND_MAP: RefCell>> = RefCell::new(HashMap::new()); +} + +#[interface("d73284e1-59aa-42ef-84ca-1633beca464b")] +pub(crate) unsafe trait IWindow: IUnknown { + fn hwnd(&self) -> HWND; + fn create(&self, parent: HWND, style: u32, ex_style: u32) -> bool; + fn destroy(&self); + fn is_visible(&self) -> bool; + fn is_window(&self) -> bool; + fn r#move(&self, x: c_int, y: c_int); + fn size(&self, width: *mut c_int, height: *mut c_int); + fn resize(&self, width: c_int, height: c_int); + fn client_rect(&self, rect: *mut RECT); + fn rect(&self, rect: *mut RECT); + fn show(&self); + fn hide(&self); + fn refresh(&self); + fn wnd_proc(&self, msg: c_uint, wp: WPARAM, lp: LPARAM) -> LRESULT; +} + +#[derive(Debug)] +#[implement(IWindow)] +pub(crate) struct Window { + hwnd: Cell, +} + +impl Window { + fn new() -> Window { + Window { + hwnd: Cell::new(HWND::default()), + } + } + fn register_hwnd(hwnd: HWND, window: IWindow) { + let weak_ref = window + .downgrade() + .expect("unable to create weak ref from window"); + HWND_MAP.with_borrow_mut(|hwnd_map| { + hwnd_map.insert(hwnd.0, weak_ref); + }) + } +} + +#[no_mangle] +pub unsafe extern "C" fn CreateImeWindow(ret: *mut *mut c_void) { + let window: IWindow = Window::new().into(); + ret.write(window.into_raw()) +} + +#[no_mangle] +pub unsafe extern "C" fn ImeWindowFromHwnd(hwnd: HWND) -> *mut IWindow { + HWND_MAP.with_borrow(|hwnd_map| { + if let Some(window) = hwnd_map.get(&hwnd.0).and_then(Weak::upgrade) { + window.clone().into_raw().cast() + } else { + null_mut() + } + }) +} + +#[no_mangle] +pub unsafe extern "C" fn ImeWindowRegisterClass(hinstance: HINSTANCE) -> bool { + MODULE_HINSTANCE.with(|hinst_cell| { + let hinst = hinst_cell.get_or_init(|| hinstance); + let mut wc = WNDCLASSEXW::default(); + wc.cbSize = size_of::() as u32; + wc.style = CS_IME; + wc.lpfnWndProc = Some(wnd_proc); + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = *hinst; + wc.hCursor = LoadCursorW(None, IDC_ARROW).expect("failed to load cursor"); + wc.hIcon = HICON::default(); + wc.lpszMenuName = PCWSTR::null(); + wc.lpszClassName = w!("LibIme2Window"); + wc.hbrBackground = HBRUSH::default(); + wc.hIconSm = HICON::default(); + + RegisterClassExW(&wc) > 0 + }) +} + +unsafe extern "system" fn wnd_proc( + hwnd: HWND, + msg: u32, + wparam: WPARAM, + lparam: LPARAM, +) -> LRESULT { + let result = HWND_MAP.with_borrow(|hwnd_map| { + if let Some(window) = hwnd_map.get(&hwnd.0).and_then(Weak::upgrade) { + window.wnd_proc(msg, wparam, lparam) + } else { + DefWindowProcW(hwnd, msg, wparam, lparam) + } + }); + if msg == WM_NCDESTROY { + HWND_MAP.with(|refcell| { + if let Ok(mut hwnd_map) = refcell.try_borrow_mut() { + hwnd_map.remove(&hwnd.0); + } + }); + } + result +} + +impl IWindow_Impl for Window_Impl { + unsafe fn hwnd(&self) -> HWND { + self.hwnd.get() + } + + unsafe fn create(&self, parent: HWND, style: u32, ex_style: u32) -> bool { + MODULE_HINSTANCE.with(|hinst| { + let hwnd = CreateWindowExW( + WINDOW_EX_STYLE(ex_style), + w!("LibIme2Window"), + None, + WINDOW_STYLE(style), + 0, + 0, + 0, + 0, + parent, + None, + hinst.get(), + None, + ); + match hwnd { + Ok(hwnd) => { + self.hwnd.set(hwnd); + true + } + Err(_) => false, + } + }) + } + + unsafe fn destroy(&self) { + if !self.hwnd().is_invalid() { + unsafe { + let _ = DestroyWindow(self.hwnd()); + } + self.hwnd.set(HWND::default()); + } + } + + unsafe fn is_visible(&self) -> bool { + IsWindowVisible(self.hwnd()).as_bool() + } + + unsafe fn is_window(&self) -> bool { + IsWindow(self.hwnd()).as_bool() + } + + unsafe fn r#move(&self, mut x: c_int, mut y: c_int) { + let mut w = 0; + let mut h = 0; + self.size(&mut w, &mut h); + + let mut rc = RECT { + left: x, + top: y, + right: x + w, + bottom: y + h, + }; + + // ensure that the window does not fall outside of the screen. + let monitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST); + let mut mi = MONITORINFO::default(); + mi.cbSize = size_of::() as u32; + if GetMonitorInfoW(monitor, &mut mi).as_bool() { + rc = mi.rcWork; + } + + if x < rc.left { + x = rc.left; + } else if (x + w) > rc.right { + x = rc.right - w; + } + + if y < rc.top { + y = rc.top; + } else if (y + h) > rc.bottom { + y = rc.bottom - h; + } + + let _ = MoveWindow(self.hwnd(), x, y, w, h, true); + } + + unsafe fn size(&self, width: *mut c_int, height: *mut c_int) { + let mut rc = RECT::default(); + GetWindowRect(self.hwnd(), &mut rc).expect("failed to get window rect"); + unsafe { + width.write(rc.right - rc.left); + height.write(rc.bottom - rc.top); + } + } + + unsafe fn resize(&self, width: c_int, height: c_int) { + SetWindowPos( + self.hwnd(), + HWND_TOP, + 0, + 0, + width, + height, + SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE, + ) + .expect("failed to resize window"); + } + + unsafe fn client_rect(&self, rect: *mut RECT) { + GetClientRect(self.hwnd(), rect).expect("failed to get client area"); + } + + unsafe fn rect(&self, rect: *mut RECT) { + GetWindowRect(self.hwnd(), rect).expect("failed to get window rect"); + } + + unsafe fn show(&self) { + if !self.hwnd().is_invalid() { + let _ = ShowWindow(self.hwnd(), SW_SHOWNA); + } + } + + unsafe fn hide(&self) { + if !self.hwnd().is_invalid() { + let _ = ShowWindow(self.hwnd(), SW_HIDE); + } + } + + unsafe fn refresh(&self) { + if !self.hwnd().is_invalid() { + let _ = InvalidateRect(self.hwnd(), None, true); + } + } + + unsafe fn wnd_proc(&self, msg: c_uint, wp: WPARAM, lp: LPARAM) -> LRESULT { + DefWindowProcW(self.hwnd(), msg, wp, lp) + } +} + +impl Drop for Window { + fn drop(&mut self) { + if !self.hwnd.get().is_invalid() { + unsafe { + let _ = DestroyWindow(self.hwnd.get()); + } + } + } +} diff --git a/libchewing b/libchewing index 83e03cc..e8ac272 160000 --- a/libchewing +++ b/libchewing @@ -1 +1 @@ -Subproject commit 83e03cce7d76beb36d076373dbeb4c155b551f28 +Subproject commit e8ac27270c49f9c52e2112e62ceb5f01f71c0d61 diff --git a/scripts/build_installer.bat b/scripts/build_installer.bat index 2d167e7..07542b9 100644 --- a/scripts/build_installer.bat +++ b/scripts/build_installer.bat @@ -7,6 +7,8 @@ cargo build --release popd mkdir dist mkdir build\installer +mkdir build\installer\assets +copy assets\* build\installer\assets\ copy installer\* build\installer\ copy ChewingTextService\mainicon2.ico build\installer\chewing.ico mkdir build\installer\Dictionary diff --git a/scripts/build_installer_debug.bat b/scripts/build_installer_debug.bat new file mode 100644 index 0000000..a4379c9 --- /dev/null +++ b/scripts/build_installer_debug.bat @@ -0,0 +1,29 @@ +cmake -B build\x86 -A Win32 -DBUILD_TESTING=OFF +cmake --build build\x86 --config Debug +cmake -B build\x64 -A x64 -DBUILD_TESTING=OFF +cmake --build build\x64 --config Debug +pushd tsfreg +cargo build --release +popd +mkdir dist +mkdir build\installer +mkdir build\installer\assets +copy assets\* build\installer\assets\ +copy installer\* build\installer\ +copy ChewingTextService\mainicon2.ico build\installer\chewing.ico +mkdir build\installer\Dictionary +copy libchewing\data\*.dat build\installer\Dictionary\ +copy build\x64\libchewing\data\*.dat build\installer\Dictionary\ +mkdir build\installer\x86 +copy build\x86\ChewingTextService\Debug\*.dll build\installer\x86\ +copy build\x86\libchewing\Debug\*.dll build\installer\x86\ +copy build\x86\ChewingPreferences\Debug\*.exe build\installer\ +copy build\x86\libchewing\chewing-cli.exe build\installer\ +mkdir build\installer\x64 +copy build\x64\ChewingTextService\Debug\*.dll build\installer\x64\ +copy build\x64\libchewing\Debug\*.dll build\installer\x64\ +copy tsfreg\target\release\tsfreg.exe build\installer\ +pushd build\installer +msbuild -p:Configuration=Release -restore windows-chewing-tsf.wixproj +popd +copy build\installer\bin\Release\zh-TW\windows-chewing-tsf.msi dist\windows-chewing-tsf-unsigned.msi \ No newline at end of file