Skip to content

Commit

Permalink
Merge pull request #192 from chewing/draw-with-d2d
Browse files Browse the repository at this point in the history
refactor: draw UI window with Direct2D
  • Loading branch information
kanru authored Sep 14, 2024
2 parents b31b352 + 98547c0 commit 160bbe3
Show file tree
Hide file tree
Showing 53 changed files with 2,269 additions and 1,946 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
IndentWidth: 4
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/build
/build
/.cache
/rustlib/target
/tsfreg/target
27 changes: 10 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<CONFIG:Debug>:Debug>")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION $<CONFIG:Release>)
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)
2 changes: 1 addition & 1 deletion ChewingPreferences/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ add_executable(ChewingPreferences WIN32
)
target_link_libraries(ChewingPreferences
comctl32.lib
)
)
21 changes: 10 additions & 11 deletions ChewingPreferences/ChewingPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
// Boston, MA 02110-1301, USA.
//

#include <Windows.h>
#include <libIME/WindowsVersion.h>
#include <libIME/ComPtr.h>
#include "TypingPropertyPage.h"
#include "UiPropertyPage.h"
#include "KeyboardPropertyPage.h"
Expand All @@ -31,6 +28,9 @@
#include <CommCtrl.h>
#include <Msctf.h>

#include <Unknwn.h>
#include <winrt/base.h>

namespace Chewing {

// {F4D1E543-FB2C-48D7-B78D-20394F355381} // global compartment GUID for config change notification
Expand All @@ -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;
Expand All @@ -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<ITfThreadMgr> threadMgr;
if(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, (void**)&threadMgr) == S_OK) {
winrt::com_ptr<ITfThreadMgr> 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<ITfCompartmentMgr> compartmentMgr;
if(threadMgr->GetGlobalCompartment(&compartmentMgr) == S_OK) {
Ime::ComPtr<ITfCompartment> compartment;
if(compartmentMgr->GetCompartment(g_configChangedGuid, &compartment) == S_OK) {
winrt::com_ptr<ITfCompartmentMgr> compartmentMgr;
if(threadMgr->GetGlobalCompartment(compartmentMgr.put()) == S_OK) {
winrt::com_ptr<ITfCompartment> compartment;
if(compartmentMgr->GetCompartment(g_configChangedGuid, compartment.put()) == S_OK) {
VARIANT var;
VariantInit(&var);
var.vt = VT_I4;
Expand Down
1 change: 0 additions & 1 deletion ChewingPreferences/SymbolsPropertyPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "SymbolsPropertyPage.h"
#include "resource.h"
#include <ShlObj.h>
#include <libIME/Utils.h>

namespace Chewing {

Expand Down
Binary file modified ChewingPreferences/resource.h
Binary file not shown.
9 changes: 4 additions & 5 deletions ChewingTextService/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)

Expand All @@ -28,3 +23,7 @@ target_link_libraries(ChewingTextService
libchewing
libIME_static
)
target_link_options(ChewingTextService
PRIVATE /NODEFAULTLIB:MSVCRT
PRIVATE /NODEFAULTLIB:MSVCRTD
)
10 changes: 6 additions & 4 deletions ChewingTextService/ChewingConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
// Boston, MA 02110-1301, USA.
//

#include "ChewingConfig.h"
#include <Aclapi.h>
#include <Windows.h>
#include <VersionHelpers.h>

#include "ChewingConfig.h"

namespace Chewing {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 1 addition & 3 deletions ChewingTextService/ChewingConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

#include <Windows.h>
#include <AccCtrl.h>
#include <libIME/WindowsVersion.h>

namespace Chewing {

class Config {
public:
Config(Ime::WindowsVersion winver);
Config();
~Config(void);

void load();
Expand Down Expand Up @@ -76,7 +75,6 @@ class Config {

private:
DWORD stamp; // timestamp used to check if the config values are up to date
Ime::WindowsVersion winVer_;
};

}
Expand Down
3 changes: 1 addition & 2 deletions ChewingTextService/ChewingImeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 160bbe3

Please sign in to comment.