Skip to content

Commit

Permalink
* Add Ime::WindowsVersion class for easy checking of Windows verion.
Browse files Browse the repository at this point in the history
* Remove Chewing::ImeModule dependency from Chewing::Config class.
  • Loading branch information
PCMan committed Sep 24, 2013
1 parent 9f1b03c commit e69e53d
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 19 deletions.
7 changes: 3 additions & 4 deletions ChewingTextService/ChewingConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//

#include "ChewingConfig.h"
#include "ChewingImeModule.h"
#include <Aclapi.h>

namespace Chewing {
Expand Down Expand Up @@ -48,8 +47,8 @@ const wchar_t* Config::selKeys[]={
#define SECURITY_BUILTIN_PACKAGE_ANY_PACKAGE 0x00000001L
#endif

Config::Config(ImeModule* module):
module_(module) {
Config::Config(Ime::WindowsVersion winver):
winVer_(winver) {
// Configuration
keyboardLayout = 0;
candPerRow = 5;
Expand Down Expand Up @@ -155,7 +154,7 @@ void Config::save() {
::RegCloseKey(hk);

// grant access to app containers in Windows 8
if(module_->isWindows8Above())
if(winVer_.isWindows8Above())
grantAppContainerAccess(L"CURRENT_USER\\Software\\ChewingTextService", SE_REGISTRY_KEY, KEY_READ);
}
}
Expand Down
7 changes: 3 additions & 4 deletions ChewingTextService/ChewingConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@

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

namespace Chewing {

class ImeModule;

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

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

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

}
Expand Down
2 changes: 1 addition & 1 deletion ChewingTextService/ChewingImeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const CLSID g_textServiceClsid = {

ImeModule::ImeModule(HMODULE module):
Ime::ImeModule(module, g_textServiceClsid),
config_(this) {
config_(windowsVersion()) {

// override default location of chewing data directories
std::wstring env;
Expand Down
1 change: 1 addition & 0 deletions libIME/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_library(libIME_static STATIC
${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
Expand Down
8 changes: 0 additions & 8 deletions libIME/ImeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,10 @@ static const GUID g_convertedDisplayAttributeGuid =
ImeModule::ImeModule(HMODULE module, const CLSID& textServiceClsid):
hInstance_(HINSTANCE(module)),
textServiceClsid_(textServiceClsid),
isWindows8Above_(false),
refCount_(1) {

Window::registerClass(hInstance_);

// check Windows version (windows 8 is 6.2, and 7 is 6.1)
DWORD winVer = ::GetVersion();
DWORD majorVersion = (DWORD)(LOBYTE(LOWORD(winVer)));
DWORD minorVersion = (DWORD)(HIBYTE(LOWORD(winVer)));
if(majorVersion > 6 || (majorVersion == 6 && minorVersion >= 2))
isWindows8Above_ = true;

// regiser default display attributes
inputAttrib_ = new DisplayAttributeInfo(g_inputDisplayAttributeGuid);
inputAttrib_->setTextColor(COLOR_WINDOWTEXT);
Expand Down
9 changes: 7 additions & 2 deletions libIME/ImeModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <Unknwn.h>
#include <Windows.h>
#include <list>
#include "WindowsVersion.h"

namespace Ime {

Expand All @@ -44,7 +45,11 @@ class ImeModule: public IClassFactory {
}

bool isWindows8Above() {
return isWindows8Above_;
return winVer_.isWindows8Above();
}

WindowsVersion windowsVersion() const {
return winVer_;
}

// Dll entry points implementations
Expand Down Expand Up @@ -94,7 +99,7 @@ class ImeModule: public IClassFactory {
DisplayAttributeInfo* inputAttrib_;
DisplayAttributeInfo* convertedAttrib_;

bool isWindows8Above_;
WindowsVersion winVer_;
};

}
Expand Down
61 changes: 61 additions & 0 deletions libIME/WindowsVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef IME_WINDOWS_VERSION_H
#define IME_WINDOWS_VERSION_H
#pragma once

#include <Windows.h>

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

0 comments on commit e69e53d

Please sign in to comment.