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..5ed4fa0 100644 --- a/ChewingPreferences/CMakeLists.txt +++ b/ChewingPreferences/CMakeLists.txt @@ -10,18 +10,13 @@ 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 - ${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 94% rename from libIME/Dialog.cpp rename to ChewingPreferences/Dialog.cpp index af8e18f..c9b4856 100644 --- a/libIME/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/libIME/Dialog.h b/ChewingPreferences/Dialog.h similarity index 94% rename from libIME/Dialog.h rename to ChewingPreferences/Dialog.h index fa9b1b1..7527536 100644 --- a/libIME/Dialog.h +++ b/ChewingPreferences/Dialog.h @@ -20,12 +20,13 @@ #ifndef IME_DIALOG_H #define IME_DIALOG_H -#include "Window.h" #include +#include + namespace Ime { -class Dialog : public Window { +class Dialog { public: Dialog(void); virtual ~Dialog(void); @@ -45,6 +46,8 @@ class Dialog : public Window { virtual void onOK(); virtual void onCancel(); + HWND hwnd_; + static std::map hwndMap_; private: }; 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.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(); 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 0b8d3d8..3252432 100644 --- a/libIME/CMakeLists.txt +++ b/libIME/CMakeLists.txt @@ -1,13 +1,5 @@ -cmake_minimum_required(VERSION 2.8.8) - 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 @@ -37,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