Skip to content

Commit

Permalink
Implement support for display attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
PCMan committed Sep 13, 2013
1 parent cbd2691 commit e14cefe
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 93 deletions.
4 changes: 2 additions & 2 deletions libIME/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ add_library(libIME_static STATIC
${PROJECT_SOURCE_DIR}/EditSession.h
${PROJECT_SOURCE_DIR}/DisplayAttributeInfo.cpp
${PROJECT_SOURCE_DIR}/DisplayAttributeInfo.h
${PROJECT_SOURCE_DIR}/EnumDisplayAttributeInfo.cpp
${PROJECT_SOURCE_DIR}/EnumDisplayAttributeInfo.h
${PROJECT_SOURCE_DIR}/DisplayAttributeInfoEnum.cpp
${PROJECT_SOURCE_DIR}/DisplayAttributeInfoEnum.h
${PROJECT_SOURCE_DIR}/LangBarButton.cpp
${PROJECT_SOURCE_DIR}/LangBarButton.h
${PROJECT_SOURCE_DIR}/Utils.cpp
Expand Down
26 changes: 24 additions & 2 deletions libIME/DisplayAttributeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@

using namespace Ime;

DisplayAttributeInfo::DisplayAttributeInfo(void):
DisplayAttributeInfo::DisplayAttributeInfo(const GUID& guid):
atom_(0),
guid_(guid),
desc_(NULL),
refCount_(1) {

Reset();
}

DisplayAttributeInfo::~DisplayAttributeInfo(void) {
if(desc_)
free(desc_);
}


// COM stuff

// IUnknown
Expand Down Expand Up @@ -43,21 +51,35 @@ STDMETHODIMP_(ULONG) DisplayAttributeInfo::Release(void) {

// ITfDisplayAttributeInfo
STDMETHODIMP DisplayAttributeInfo::GetGUID(GUID *pguid) {
*pguid = guid_;
return S_OK;
}

STDMETHODIMP DisplayAttributeInfo::GetDescription(BSTR *pbstrDesc) {
return S_OK;
if(desc_) {
*pbstrDesc = ::SysAllocString(desc_);
return S_OK;
}
*pbstrDesc = NULL;
return E_FAIL;
}

STDMETHODIMP DisplayAttributeInfo::GetAttributeInfo(TF_DISPLAYATTRIBUTE *ptfDisplayAttr) {
*ptfDisplayAttr = attrib_;
return S_OK;
}

STDMETHODIMP DisplayAttributeInfo::SetAttributeInfo(const TF_DISPLAYATTRIBUTE *ptfDisplayAttr) {
attrib_ = *ptfDisplayAttr;
return S_OK;
}

STDMETHODIMP DisplayAttributeInfo::Reset() {
attrib_.bAttr = TF_ATTR_INPUT;
attrib_.crBk.type = TF_CT_NONE;
attrib_.crLine.type = TF_CT_NONE;
attrib_.crText.type = TF_CT_NONE;
attrib_.fBoldLine = FALSE;
attrib_.lsStyle = TF_LS_NONE;
return S_OK;
}
65 changes: 64 additions & 1 deletion libIME/DisplayAttributeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,71 @@ namespace Ime {

class DisplayAttributeInfo : public ITfDisplayAttributeInfo {
public:
DisplayAttributeInfo(void);
DisplayAttributeInfo(const GUID& guid);
virtual ~DisplayAttributeInfo(void);

// public methods

void setAtom(TfGuidAtom atom) {
atom_ = atom;
}

TfGuidAtom atom() const {
return atom_;
}

void setTextColor(COLORREF color) {
attrib_.crText.type = TF_CT_COLORREF;
attrib_.crText.cr = color;
}

void setTextColor(int index) {
attrib_.crText.type = TF_CT_SYSCOLOR;
attrib_.crText.nIndex = index;
}

void setBackgroundColor(COLORREF color) {
attrib_.crBk.type = TF_CT_COLORREF;
attrib_.crBk.cr = color;
}

void setBackgroundColor(int index) {
attrib_.crBk.type = TF_CT_SYSCOLOR;
attrib_.crBk.nIndex = index;
}

void setLineColor(COLORREF color) {
attrib_.crLine.type = TF_CT_COLORREF;
attrib_.crLine.cr = color;
}

void setLineColor(int index) {
attrib_.crLine.type = TF_CT_SYSCOLOR;
attrib_.crLine.nIndex = index;
}

void setLineStyle(TF_DA_LINESTYLE style) {
attrib_.lsStyle = style;
}

void setLineBold(bool bold) {
attrib_.fBoldLine = (BOOL)bold;
}

void setAttrInfo(TF_DA_ATTR_INFO attr) {
attrib_.bAttr = attr;
}

void setDescription(wchar_t* desc) {
if(desc_)
free(desc_);
desc_ = _wcsdup(desc);
}

const GUID& guid() const {
return guid_;
}

// IUnknown
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
STDMETHODIMP_(ULONG) AddRef(void);
Expand All @@ -24,6 +86,7 @@ class DisplayAttributeInfo : public ITfDisplayAttributeInfo {

private:
int refCount_;
TfGuidAtom atom_;
GUID guid_;
wchar_t* desc_;
TF_DISPLAYATTRIBUTE attrib_;
Expand Down
83 changes: 83 additions & 0 deletions libIME/DisplayAttributeInfoEnum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "DisplayAttributeInfoEnum.h"
#include "TextService.h"
#include <assert.h>

using namespace Ime;

DisplayAttributeInfoEnum::DisplayAttributeInfoEnum(TextService* service):
textService_(service),
refCount_(1) {
iterator_ = service->displayAttrInfos_.begin();
}

DisplayAttributeInfoEnum::DisplayAttributeInfoEnum(const DisplayAttributeInfoEnum& other):
textService_(other.textService_),
iterator_(other.iterator_) {
}

DisplayAttributeInfoEnum::~DisplayAttributeInfoEnum(void) {
}

// IUnknown
STDMETHODIMP DisplayAttributeInfoEnum::QueryInterface(REFIID riid, void **ppvObj) {
if (ppvObj == NULL)
return E_INVALIDARG;

if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IEnumTfDisplayAttributeInfo))
*ppvObj = (IEnumTfDisplayAttributeInfo*)this;
else
*ppvObj = NULL;

if(*ppvObj) {
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}

STDMETHODIMP_(ULONG) DisplayAttributeInfoEnum::AddRef(void) {
return ++refCount_;
}

STDMETHODIMP_(ULONG) DisplayAttributeInfoEnum::Release(void) {
assert(refCount_ > 0);
--refCount_;
if(0 == refCount_)
delete this;
return refCount_;
}


// IEnumTfDisplayAttributeInfo
STDMETHODIMP DisplayAttributeInfoEnum::Clone(IEnumTfDisplayAttributeInfo **ppEnum) {
*ppEnum = (IEnumTfDisplayAttributeInfo*)new DisplayAttributeInfoEnum(*this);
return S_OK;
}

STDMETHODIMP DisplayAttributeInfoEnum::Next(ULONG ulCount, ITfDisplayAttributeInfo **rgInfo, ULONG *pcFetched) {
ULONG i = 0;
for(; i < ulCount; ++i) {
if(iterator_ != textService_->displayAttrInfos_.end()) {
DisplayAttributeInfo* info = *iterator_;
info->AddRef();
rgInfo[i] = info;
++iterator_;
}
else
break;
}
if(pcFetched)
*pcFetched = i;
return S_OK;
}

STDMETHODIMP DisplayAttributeInfoEnum::Reset() {
iterator_ = textService_->displayAttrInfos_.begin();
return S_OK;
}

STDMETHODIMP DisplayAttributeInfoEnum::Skip(ULONG ulCount) {
if(iterator_ != textService_->displayAttrInfos_.end())
++iterator_;
return S_OK;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#ifndef ENUM_DISPLAY_ATTRIBUTE_INFO_H
#define ENUM_DISPLAY_ATTRIBUTE_INFO_H

#include "msctf.h"
#include <msctf.h>
#include <list>
#include "DisplayAttributeInfo.h"
#include "ComPtr.h"

namespace Ime {

class TextService;

class EnumDisplayAttributeInfo : public IEnumTfDisplayAttributeInfo {
class DisplayAttributeInfoEnum : public IEnumTfDisplayAttributeInfo {
public:
EnumDisplayAttributeInfo(TextService* service);
virtual ~EnumDisplayAttributeInfo(void);
DisplayAttributeInfoEnum(TextService* service);
DisplayAttributeInfoEnum(const DisplayAttributeInfoEnum& other);
virtual ~DisplayAttributeInfoEnum(void);

// IUnknown
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
Expand All @@ -25,6 +29,8 @@ class EnumDisplayAttributeInfo : public IEnumTfDisplayAttributeInfo {

private:
int refCount_;
std::list<DisplayAttributeInfo*>::iterator iterator_;
ComPtr<TextService> textService_;
};

}
Expand Down
57 changes: 0 additions & 57 deletions libIME/EnumDisplayAttributeInfo.cpp

This file was deleted.

14 changes: 10 additions & 4 deletions libIME/ImeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Shlwapi.h>
#include <assert.h>
#include "Window.h"
#include "TextService.h"

using namespace Ime;
using namespace std;
Expand Down Expand Up @@ -119,9 +120,9 @@ HRESULT ImeModule::registerServer(wchar_t* name, const GUID& profileGuid, LANGID

// register ourself as a display attribute provider
// so later we can set change the look and feels of composition string.
//if(categoryMgr->RegisterCategory(textServiceClsid_, GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, textServiceClsid) != S_OK) {
// result = E_FAIL;
//}
if(categoryMgr->RegisterCategory(textServiceClsid_, GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, textServiceClsid_) != S_OK) {
result = E_FAIL;
}

// for Windows 8 store app support
// TODO: according to a exhaustive Google search, I found that
Expand Down Expand Up @@ -157,6 +158,7 @@ HRESULT ImeModule::unregisterServer(const GUID& profileGuid) {
ITfCategoryMgr *categoryMgr = NULL;
if(CoCreateInstance(CLSID_TF_CategoryMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfCategoryMgr, (void**)&categoryMgr) == S_OK) {
categoryMgr->UnregisterCategory(textServiceClsid_, GUID_TFCAT_TIP_KEYBOARD, textServiceClsid_);
categoryMgr->UnregisterCategory(textServiceClsid_, GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, textServiceClsid_);

// Windows 8 support
categoryMgr->UnregisterCategory(textServiceClsid_, GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT, textServiceClsid_);
Expand Down Expand Up @@ -218,8 +220,12 @@ STDMETHODIMP_(ULONG) ImeModule::Release(void) {
STDMETHODIMP ImeModule::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppvObj) {
// FIXME: do we need to check riid here?
TextService* service = createTextService();
// FIXME: we should split DisplayAttributeProvider into another class
// Otherwise, everytime a new TextService object is created just for enumerating display attributes.
// This is really a waste and may cause potential side effects.
if(service) {
*ppvObj = (void*)service;
service->QueryInterface(riid, ppvObj);
service->Release();
return S_OK;
}
return S_FALSE;
Expand Down
Loading

0 comments on commit e14cefe

Please sign in to comment.