From 86beb44ebad231296d5f315d49178c0b441d6e9f Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Thu, 1 Aug 2024 08:01:01 +0900 Subject: [PATCH 1/5] build: remove cmake minimum version for libIME --- libIME/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/libIME/CMakeLists.txt b/libIME/CMakeLists.txt index 0b8d3d8..06a4dea 100644 --- a/libIME/CMakeLists.txt +++ b/libIME/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 2.8.8) - project(libIME) # http://www.utf8everywhere.org/ From ca58210e61a350769dc277a89e60744f490fd0c3 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Thu, 1 Aug 2024 08:01:27 +0900 Subject: [PATCH 2/5] build(libime): remove UNICODE defines --- libIME/CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libIME/CMakeLists.txt b/libIME/CMakeLists.txt index 06a4dea..3bab80d 100644 --- a/libIME/CMakeLists.txt +++ b/libIME/CMakeLists.txt @@ -1,11 +1,5 @@ project(libIME) -# http://www.utf8everywhere.org/ -add_definitions( - /D_UNICODE=1 - /DUNICODE=1 -) - add_library(libIME_static STATIC # Core TSF part ${PROJECT_SOURCE_DIR}/ImeModule.cpp From 6f246eb88bbcf37a41c3c965e8a39e12b211bca8 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Thu, 1 Aug 2024 08:10:03 +0900 Subject: [PATCH 3/5] build(libime): move files only used by preferences --- ChewingPreferences/AboutDialog.h | 2 +- ChewingPreferences/CMakeLists.txt | 12 ++++++------ ChewingPreferences/ChewingPreferences.cpp | 4 ++-- {libIME => ChewingPreferences}/Dialog.cpp | 0 {libIME => ChewingPreferences}/Dialog.h | 3 ++- ChewingPreferences/KeyboardPropertyPage.h | 2 +- {libIME => ChewingPreferences}/PropertyDialog.cpp | 0 {libIME => ChewingPreferences}/PropertyDialog.h | 0 {libIME => ChewingPreferences}/PropertyPage.cpp | 0 {libIME => ChewingPreferences}/PropertyPage.h | 0 ChewingPreferences/SymbolsPropertyPage.h | 2 +- ChewingPreferences/TypingPropertyPage.h | 2 +- ChewingPreferences/UiPropertyPage.h | 2 +- libIME/CMakeLists.txt | 6 ------ 14 files changed, 15 insertions(+), 20 deletions(-) rename {libIME => ChewingPreferences}/Dialog.cpp (100%) rename {libIME => ChewingPreferences}/Dialog.h (97%) rename {libIME => ChewingPreferences}/PropertyDialog.cpp (100%) rename {libIME => ChewingPreferences}/PropertyDialog.h (100%) rename {libIME => ChewingPreferences}/PropertyPage.cpp (100%) rename {libIME => ChewingPreferences}/PropertyPage.h (100%) diff --git a/ChewingPreferences/AboutDialog.h b/ChewingPreferences/AboutDialog.h index 7ca0b35..6381ffb 100644 --- a/ChewingPreferences/AboutDialog.h +++ b/ChewingPreferences/AboutDialog.h @@ -21,7 +21,7 @@ #define CHEWING_ABOUT_DIALOG_H #pragma once -#include +#include "Dialog.h" namespace Chewing { diff --git a/ChewingPreferences/CMakeLists.txt b/ChewingPreferences/CMakeLists.txt index 3ed7573..594a341 100644 --- a/ChewingPreferences/CMakeLists.txt +++ b/ChewingPreferences/CMakeLists.txt @@ -15,13 +15,13 @@ add_executable(ChewingPreferences WIN32 ${CMAKE_SOURCE_DIR}/libIME/Utils.h ${CMAKE_SOURCE_DIR}/libIME/Window.cpp ${CMAKE_SOURCE_DIR}/libIME/Window.h - ${CMAKE_SOURCE_DIR}/libIME/Dialog.cpp - ${CMAKE_SOURCE_DIR}/libIME/Dialog.h - ${CMAKE_SOURCE_DIR}/libIME/PropertyDialog.cpp - ${CMAKE_SOURCE_DIR}/libIME/PropertyDialog.h - ${CMAKE_SOURCE_DIR}/libIME/PropertyPage.cpp - ${CMAKE_SOURCE_DIR}/libIME/PropertyPage.h # Configuration dialog + ${PROJECT_SOURCE_DIR}/Dialog.cpp + ${PROJECT_SOURCE_DIR}/Dialog.h + ${PROJECT_SOURCE_DIR}/PropertyDialog.cpp + ${PROJECT_SOURCE_DIR}/PropertyDialog.h + ${PROJECT_SOURCE_DIR}/PropertyPage.cpp + ${PROJECT_SOURCE_DIR}/PropertyPage.h ${PROJECT_SOURCE_DIR}/TypingPropertyPage.cpp ${PROJECT_SOURCE_DIR}/TypingPropertyPage.h ${PROJECT_SOURCE_DIR}/UiPropertyPage.cpp diff --git a/ChewingPreferences/ChewingPreferences.cpp b/ChewingPreferences/ChewingPreferences.cpp index 22bfc44..7032101 100644 --- a/ChewingPreferences/ChewingPreferences.cpp +++ b/ChewingPreferences/ChewingPreferences.cpp @@ -18,14 +18,14 @@ // #include -#include -#include #include #include #include "TypingPropertyPage.h" #include "UiPropertyPage.h" #include "KeyboardPropertyPage.h" #include "SymbolsPropertyPage.h" +#include "Dialog.h" +#include "PropertyDialog.h" #include "AboutDialog.h" #include "resource.h" #include diff --git a/libIME/Dialog.cpp b/ChewingPreferences/Dialog.cpp similarity index 100% rename from libIME/Dialog.cpp rename to ChewingPreferences/Dialog.cpp diff --git a/libIME/Dialog.h b/ChewingPreferences/Dialog.h similarity index 97% rename from libIME/Dialog.h rename to ChewingPreferences/Dialog.h index fa9b1b1..f98c26c 100644 --- a/libIME/Dialog.h +++ b/ChewingPreferences/Dialog.h @@ -20,7 +20,8 @@ #ifndef IME_DIALOG_H #define IME_DIALOG_H -#include "Window.h" +// FIXME +#include #include namespace Ime { diff --git a/ChewingPreferences/KeyboardPropertyPage.h b/ChewingPreferences/KeyboardPropertyPage.h index d07564a..e902209 100644 --- a/ChewingPreferences/KeyboardPropertyPage.h +++ b/ChewingPreferences/KeyboardPropertyPage.h @@ -21,7 +21,7 @@ #define CHEWING_KEYBOARD_PROPERTY_PAGE_H #pragma once -#include +#include "PropertyPage.h" #include namespace Chewing { diff --git a/libIME/PropertyDialog.cpp b/ChewingPreferences/PropertyDialog.cpp similarity index 100% rename from libIME/PropertyDialog.cpp rename to ChewingPreferences/PropertyDialog.cpp diff --git a/libIME/PropertyDialog.h b/ChewingPreferences/PropertyDialog.h similarity index 100% rename from libIME/PropertyDialog.h rename to ChewingPreferences/PropertyDialog.h diff --git a/libIME/PropertyPage.cpp b/ChewingPreferences/PropertyPage.cpp similarity index 100% rename from libIME/PropertyPage.cpp rename to ChewingPreferences/PropertyPage.cpp diff --git a/libIME/PropertyPage.h b/ChewingPreferences/PropertyPage.h similarity index 100% rename from libIME/PropertyPage.h rename to ChewingPreferences/PropertyPage.h diff --git a/ChewingPreferences/SymbolsPropertyPage.h b/ChewingPreferences/SymbolsPropertyPage.h index 6d05d87..079a888 100644 --- a/ChewingPreferences/SymbolsPropertyPage.h +++ b/ChewingPreferences/SymbolsPropertyPage.h @@ -21,7 +21,7 @@ #define CHEWING_SYMBOLS_PROPERTY_PAGE #pragma once -#include +#include "PropertyPage.h" #include #include diff --git a/ChewingPreferences/TypingPropertyPage.h b/ChewingPreferences/TypingPropertyPage.h index 8816cec..8575f2d 100644 --- a/ChewingPreferences/TypingPropertyPage.h +++ b/ChewingPreferences/TypingPropertyPage.h @@ -20,7 +20,7 @@ #ifndef CHEWING_TYPING_PROPERTY_PAGE_H #define CHEWING_TYPING_PROPERTY_PAGE_H -#include +#include "PropertyPage.h" #include namespace Chewing { diff --git a/ChewingPreferences/UiPropertyPage.h b/ChewingPreferences/UiPropertyPage.h index c0a79df..46fc835 100644 --- a/ChewingPreferences/UiPropertyPage.h +++ b/ChewingPreferences/UiPropertyPage.h @@ -21,7 +21,7 @@ #define CHEWING_UI_PROPERTY_PAGE_H #pragma once -#include +#include "PropertyPage.h" #include namespace Chewing { diff --git a/libIME/CMakeLists.txt b/libIME/CMakeLists.txt index 3bab80d..3252432 100644 --- a/libIME/CMakeLists.txt +++ b/libIME/CMakeLists.txt @@ -29,12 +29,6 @@ add_library(libIME_static STATIC ${PROJECT_SOURCE_DIR}/DrawUtils.cpp ${PROJECT_SOURCE_DIR}/Window.cpp ${PROJECT_SOURCE_DIR}/Window.h - # ${PROJECT_SOURCE_DIR}/Dialog.cpp - # ${PROJECT_SOURCE_DIR}/Dialog.h - # ${PROJECT_SOURCE_DIR}/PropertyDialog.cpp - # ${PROJECT_SOURCE_DIR}/PropertyDialog.h - # ${PROJECT_SOURCE_DIR}/PropertyPage.cpp - # ${PROJECT_SOURCE_DIR}/PropertyPage.h ${PROJECT_SOURCE_DIR}/ImeWindow.cpp ${PROJECT_SOURCE_DIR}/ImeWindow.h ${PROJECT_SOURCE_DIR}/MessageWindow.cpp From dd4d70c92d59da4cb1e4aef51e06bbd984a105ea Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Fri, 2 Aug 2024 07:29:14 +0900 Subject: [PATCH 4/5] refactor(libime): decouple Window and Dialog --- ChewingPreferences/CMakeLists.txt | 2 -- ChewingPreferences/Dialog.cpp | 8 ++++++-- ChewingPreferences/Dialog.h | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ChewingPreferences/CMakeLists.txt b/ChewingPreferences/CMakeLists.txt index 594a341..3b77d4b 100644 --- a/ChewingPreferences/CMakeLists.txt +++ b/ChewingPreferences/CMakeLists.txt @@ -13,8 +13,6 @@ add_executable(ChewingPreferences WIN32 # libIME UI code ${CMAKE_SOURCE_DIR}/libIME/Utils.cpp ${CMAKE_SOURCE_DIR}/libIME/Utils.h - ${CMAKE_SOURCE_DIR}/libIME/Window.cpp - ${CMAKE_SOURCE_DIR}/libIME/Window.h # Configuration dialog ${PROJECT_SOURCE_DIR}/Dialog.cpp ${PROJECT_SOURCE_DIR}/Dialog.h diff --git a/ChewingPreferences/Dialog.cpp b/ChewingPreferences/Dialog.cpp index af8e18f..c9b4856 100644 --- a/ChewingPreferences/Dialog.cpp +++ b/ChewingPreferences/Dialog.cpp @@ -21,11 +21,15 @@ namespace Ime { -Dialog::Dialog(void): - Window() { +std::map Dialog::hwndMap_; + +Dialog::Dialog(void): hwnd_(NULL) { } Dialog::~Dialog(void) { + if(hwnd_) { + DestroyWindow(hwnd_); + } } bool Dialog::Create(HINSTANCE hinstance, UINT dialogId, HWND parent) { // modaless diff --git a/ChewingPreferences/Dialog.h b/ChewingPreferences/Dialog.h index f98c26c..7527536 100644 --- a/ChewingPreferences/Dialog.h +++ b/ChewingPreferences/Dialog.h @@ -20,13 +20,13 @@ #ifndef IME_DIALOG_H #define IME_DIALOG_H -// FIXME -#include #include +#include + namespace Ime { -class Dialog : public Window { +class Dialog { public: Dialog(void); virtual ~Dialog(void); @@ -46,6 +46,8 @@ class Dialog : public Window { virtual void onOK(); virtual void onCancel(); + HWND hwnd_; + static std::map hwndMap_; private: }; From 4c960981167e714bee0cac7b349b92c5ef0a575e Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Fri, 2 Aug 2024 08:31:08 +0900 Subject: [PATCH 5/5] refactor(pref): decouple with libIME --- ChewingPreferences/CMakeLists.txt | 3 --- ChewingPreferences/SymbolsPropertyPage.cpp | 31 ++++++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/ChewingPreferences/CMakeLists.txt b/ChewingPreferences/CMakeLists.txt index 3b77d4b..5ed4fa0 100644 --- a/ChewingPreferences/CMakeLists.txt +++ b/ChewingPreferences/CMakeLists.txt @@ -10,9 +10,6 @@ add_executable(ChewingPreferences WIN32 # Configurations ${CMAKE_SOURCE_DIR}/ChewingTextService/ChewingConfig.cpp ${CMAKE_SOURCE_DIR}/ChewingTextService/ChewingConfig.h - # libIME UI code - ${CMAKE_SOURCE_DIR}/libIME/Utils.cpp - ${CMAKE_SOURCE_DIR}/libIME/Utils.h # Configuration dialog ${PROJECT_SOURCE_DIR}/Dialog.cpp ${PROJECT_SOURCE_DIR}/Dialog.h diff --git a/ChewingPreferences/SymbolsPropertyPage.cpp b/ChewingPreferences/SymbolsPropertyPage.cpp index 12e741a..66825b7 100644 --- a/ChewingPreferences/SymbolsPropertyPage.cpp +++ b/ChewingPreferences/SymbolsPropertyPage.cpp @@ -61,14 +61,20 @@ bool SymbolsPropertyPage::onInitDialog() { } if(file != INVALID_HANDLE_VALUE) { DWORD size = GetFileSize(file, NULL); - char* buf = new char[size+1]; + char* buf = new char[size]; DWORD rsize; ReadFile(file, buf, size, &rsize, NULL); CloseHandle(file); - buf[size] = 0; - std::wstring wstr = utf8ToUtf16(buf); + std::wstring wstr; + int wlen = ::MultiByteToWideChar(CP_UTF8, 0, buf, size, NULL, 0); + if (wlen > 0) { + wstr.resize(wlen); + ::MultiByteToWideChar(CP_UTF8, 0, buf, size, &wstr[0], wlen); + ::SetDlgItemTextW(hwnd_, IDC_EDIT, wstr.c_str()); + } else { + ::SetDlgItemTextW(hwnd_, IDC_EDIT, L"無法讀取檔案"); + } delete []buf; - ::SetDlgItemTextW(hwnd_, IDC_EDIT, wstr.c_str()); } return PropertyPage::onInitDialog(); } @@ -97,16 +103,19 @@ void SymbolsPropertyPage::onOK() { HANDLE file = CreateFile(filename.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL ); if( file != INVALID_HANDLE_VALUE ) { HWND edit = ::GetDlgItem(hwnd_, IDC_EDIT); - int len = ::GetWindowTextLengthW(edit) + 1; + int len = ::GetWindowTextLengthW(edit); wchar_t* buf = new wchar_t[len]; len = ::GetWindowText(edit, buf, len); - buf[len] = 0; - std::string ustr = utf16ToUtf8(buf); + std::string ustr; + int ulen = ::WideCharToMultiByte(CP_UTF8, 0, &buf[0], len, NULL, 0, NULL, NULL); + if (ulen > 0) { + ustr.resize(ulen); + ::WideCharToMultiByte(CP_UTF8, 0, &buf[0], len, &ustr[0], ulen, NULL, NULL); + DWORD wsize; + ::WriteFile( file, ustr.c_str(), ustr.length(), &wsize, NULL ); + ::CloseHandle(file); + } delete []buf; - - DWORD wsize; - WriteFile( file, ustr.c_str(), ustr.length(), &wsize, NULL ); - CloseHandle(file); } PropertyPage::onOK();