forked from EasyIME/PIME
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix reference counting bug in ComPtr.
* Move ITfDisplayAttributeProvider to its own class.
- Loading branch information
Showing
12 changed files
with
233 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "DisplayAttributeProvider.h" | ||
#include "DisplayAttributeInfo.h" | ||
#include "DisplayAttributeInfoEnum.h" | ||
#include "ImeModule.h" | ||
#include <assert.h> | ||
|
||
using namespace Ime; | ||
using namespace std; | ||
|
||
DisplayAttributeProvider::DisplayAttributeProvider(ImeModule* module): | ||
imeModule_(module), | ||
refCount_(1) { | ||
} | ||
|
||
DisplayAttributeProvider::~DisplayAttributeProvider(void) { | ||
} | ||
|
||
|
||
// COM stuff | ||
|
||
// IUnknown | ||
STDMETHODIMP DisplayAttributeProvider::QueryInterface(REFIID riid, void **ppvObj) { | ||
if (ppvObj == NULL) | ||
return E_INVALIDARG; | ||
if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfDisplayAttributeProvider)) | ||
*ppvObj = (ITfDisplayAttributeProvider*)this; | ||
else | ||
*ppvObj = NULL; | ||
|
||
if(*ppvObj) { | ||
AddRef(); | ||
return S_OK; | ||
} | ||
return E_NOINTERFACE; | ||
} | ||
|
||
// IUnknown implementation | ||
STDMETHODIMP_(ULONG) DisplayAttributeProvider::AddRef(void) { | ||
return ++refCount_; | ||
} | ||
|
||
STDMETHODIMP_(ULONG) DisplayAttributeProvider::Release(void) { | ||
assert(refCount_ > 0); | ||
--refCount_; | ||
if(0 == refCount_) | ||
delete this; | ||
return refCount_; | ||
} | ||
|
||
|
||
// ITfDisplayAttributeProvider | ||
STDMETHODIMP DisplayAttributeProvider::EnumDisplayAttributeInfo(IEnumTfDisplayAttributeInfo **ppEnum) { | ||
*ppEnum = (IEnumTfDisplayAttributeInfo*)new DisplayAttributeInfoEnum(this); | ||
return S_OK; | ||
} | ||
|
||
STDMETHODIMP DisplayAttributeProvider::GetDisplayAttributeInfo(REFGUID guidInfo, ITfDisplayAttributeInfo **ppInfo) { | ||
list<DisplayAttributeInfo*>& displayAttrInfos = imeModule_->displayAttrInfos(); | ||
list<DisplayAttributeInfo*>::iterator it; | ||
for(it = displayAttrInfos.begin(); it != displayAttrInfos.end(); ++it) { | ||
DisplayAttributeInfo* info = *it; | ||
if(::IsEqualGUID(info->guid(), guidInfo)) { | ||
*ppInfo = info; | ||
info->AddRef(); | ||
return S_OK; | ||
} | ||
} | ||
return E_INVALIDARG; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef IME_DISPLAY_ATTRIBUTE_PROVIDER_H | ||
#define IME_DISPLAY_ATTRIBUTE_PROVIDER_H | ||
|
||
#include <msctf.h> | ||
#include <list> | ||
#include "ComPtr.h" | ||
|
||
namespace Ime { | ||
|
||
class ImeModule; | ||
class DisplayAttributeInfo; | ||
|
||
class DisplayAttributeProvider : public ITfDisplayAttributeProvider { | ||
public: | ||
|
||
friend class DisplayAttributeInfoEnum; | ||
|
||
DisplayAttributeProvider(ImeModule* module); | ||
virtual ~DisplayAttributeProvider(void); | ||
|
||
// COM stuff | ||
|
||
// IUnknown | ||
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj); | ||
STDMETHODIMP_(ULONG) AddRef(void); | ||
STDMETHODIMP_(ULONG) Release(void); | ||
|
||
// ITfDisplayAttributeProvider | ||
STDMETHODIMP EnumDisplayAttributeInfo(IEnumTfDisplayAttributeInfo **ppEnum); | ||
STDMETHODIMP GetDisplayAttributeInfo(REFGUID guidInfo, ITfDisplayAttributeInfo **ppInfo); | ||
|
||
private: | ||
int refCount_; | ||
ComPtr<ImeModule> imeModule_; | ||
}; | ||
|
||
} | ||
|
||
#endif | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.