Skip to content

Commit

Permalink
Merge pull request #182 from chewing/libime-cleanup
Browse files Browse the repository at this point in the history
libIME cleanup
  • Loading branch information
kanru authored Aug 7, 2024
2 parents c73f93f + 4c96098 commit 367f398
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 47 deletions.
2 changes: 1 addition & 1 deletion ChewingPreferences/AboutDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define CHEWING_ABOUT_DIALOG_H
#pragma once

#include <libIME\Dialog.h>
#include "Dialog.h"

namespace Chewing {

Expand Down
17 changes: 6 additions & 11 deletions ChewingPreferences/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ChewingPreferences/ChewingPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
//

#include <Windows.h>
#include <libIME/Dialog.h>
#include <libIME/PropertyDialog.h>
#include <libIME/WindowsVersion.h>
#include <libIME/ComPtr.h>
#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 <CommCtrl.h>
Expand Down
8 changes: 6 additions & 2 deletions libIME/Dialog.cpp → ChewingPreferences/Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@

namespace Ime {

Dialog::Dialog(void):
Window() {
std::map<HWND, Dialog*> Dialog::hwndMap_;

Dialog::Dialog(void): hwnd_(NULL) {
}

Dialog::~Dialog(void) {
if(hwnd_) {
DestroyWindow(hwnd_);
}
}

bool Dialog::Create(HINSTANCE hinstance, UINT dialogId, HWND parent) { // modaless
Expand Down
7 changes: 5 additions & 2 deletions libIME/Dialog.h → ChewingPreferences/Dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
#ifndef IME_DIALOG_H
#define IME_DIALOG_H

#include "Window.h"
#include <windows.h>

#include <map>

namespace Ime {

class Dialog : public Window {
class Dialog {
public:
Dialog(void);
virtual ~Dialog(void);
Expand All @@ -45,6 +46,8 @@ class Dialog : public Window {
virtual void onOK();
virtual void onCancel();

HWND hwnd_;
static std::map<HWND, Dialog*> hwndMap_;
private:
};

Expand Down
2 changes: 1 addition & 1 deletion ChewingPreferences/KeyboardPropertyPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define CHEWING_KEYBOARD_PROPERTY_PAGE_H
#pragma once

#include <libIME/PropertyPage.h>
#include "PropertyPage.h"
#include <ChewingTextService/ChewingConfig.h>

namespace Chewing {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 20 additions & 11 deletions ChewingPreferences/SymbolsPropertyPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion ChewingPreferences/SymbolsPropertyPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define CHEWING_SYMBOLS_PROPERTY_PAGE
#pragma once

#include <libIME/PropertyPage.h>
#include "PropertyPage.h"
#include <ChewingTextService/ChewingConfig.h>
#include <string>

Expand Down
2 changes: 1 addition & 1 deletion ChewingPreferences/TypingPropertyPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef CHEWING_TYPING_PROPERTY_PAGE_H
#define CHEWING_TYPING_PROPERTY_PAGE_H

#include <libIME/PropertyPage.h>
#include "PropertyPage.h"
#include <ChewingTextService/ChewingConfig.h>

namespace Chewing {
Expand Down
2 changes: 1 addition & 1 deletion ChewingPreferences/UiPropertyPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define CHEWING_UI_PROPERTY_PAGE_H
#pragma once

#include <libIME/PropertyPage.h>
#include "PropertyPage.h"
#include <ChewingTextService/ChewingConfig.h>

namespace Chewing {
Expand Down
14 changes: 0 additions & 14 deletions libIME/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 367f398

Please sign in to comment.