Skip to content

Commit

Permalink
* Implement compartment handling and handle keyboard status correctly.
Browse files Browse the repository at this point in the history
* Change coding style. Replace "using namespace Ime" with "namespace Ime {}".
  • Loading branch information
PCMan committed Sep 17, 2013
1 parent 97eec56 commit ce12f2a
Show file tree
Hide file tree
Showing 23 changed files with 429 additions and 47 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project(windows-chewing-tsf)
# http://www.utf8everywhere.org/
add_definitions(
/D_UNICODE=1 /DUNICODE=1 # do Unicode build
/D_CRT_SECURE_NO_WARNINGS # disable warnings about old libc functions
/GR- # turn off C++ RTTI
)

Expand Down
4 changes: 3 additions & 1 deletion ChewingTextService/ChewingConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "ChewingConfig.h"

using namespace Chewing;
namespace Chewing {

#define DEF_FONT_SIZE 16

Expand Down Expand Up @@ -167,3 +167,5 @@ void Config::save() {
// Luckily, TSF global compartment sink is a perfect way to do this.
// So no complicated IPC is needed here.
}

} // namespace Chewing
4 changes: 3 additions & 1 deletion ChewingTextService/ChewingImeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <string>
#include <ShlObj.h>

using namespace Chewing;
namespace Chewing {

// CLSID of our Text service
// {13F2EF08-575C-4D8C-88E0-F67BB8052B84}
Expand Down Expand Up @@ -69,3 +69,5 @@ Ime::TextService* ImeModule::createTextService() {
TextService* service = new Chewing::TextService(this);
return service;
}

} // namespace Chewing
5 changes: 4 additions & 1 deletion ChewingTextService/ChewingTextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
#include <Shellapi.h>
#include "TypingPage.h"

using namespace Chewing;
using namespace std;

namespace Chewing {

// {B59D51B9-B832-40D2-9A8D-56959372DDC7}
static const GUID g_modeButtonGuid = // English/Chinses mode switch
{ 0xb59d51b9, 0xb832, 0x40d2, { 0x9a, 0x8d, 0x56, 0x95, 0x93, 0x72, 0xdd, 0xc7 } };
Expand Down Expand Up @@ -519,3 +520,5 @@ void TextService::updateLangButtons() {
switchShapeButton_->setIcon(shapeMode == FULLSHAPE_MODE ? IDI_FULL_SHAPE : IDI_HALF_SHAPE);
}
}

} // namespace Chewing
3 changes: 2 additions & 1 deletion ChewingTextService/TypingPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "resource.h"
#include <WindowsX.h>

using namespace Chewing;
namespace Chewing {

TypingPage::TypingPage(Config* config):
Ime::PropertyPage((LPCTSTR)IDD_TYPING),
Expand Down Expand Up @@ -87,3 +87,4 @@ void TypingPage::onOK() {
PropertyPage::onOK();
}

} // namespace Chewing
2 changes: 2 additions & 0 deletions libIME/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ add_library(libIME_static STATIC
${PROJECT_SOURCE_DIR}/DisplayAttributeInfoEnum.h
${PROJECT_SOURCE_DIR}/DisplayAttributeProvider.cpp
${PROJECT_SOURCE_DIR}/DisplayAttributeProvider.h
${PROJECT_SOURCE_DIR}/CompartmentEventSink.cpp
${PROJECT_SOURCE_DIR}/CompartmentEventSink.h
${PROJECT_SOURCE_DIR}/LangBarButton.cpp
${PROJECT_SOURCE_DIR}/LangBarButton.h
${PROJECT_SOURCE_DIR}/Utils.cpp
Expand Down
5 changes: 4 additions & 1 deletion libIME/CandidateWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
#include <tchar.h>
#include <windows.h>

using namespace Ime;
using namespace std;

namespace Ime {

void CandidateWindow::updateFont() {
/*
if (font_size==g_FontSize)
Expand Down Expand Up @@ -211,3 +212,5 @@ void CandidateWindow::recalculateSize() {
::ReleaseDC(hwnd(), hDC);
resize(width, height);
}

} // namespace Ime
48 changes: 48 additions & 0 deletions libIME/CompartmentEventSink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "CompartmentEventSink.h"
#include <assert.h>

namespace Ime {

CompartmentEventSink::CompartmentEventSink(void):
refCount_(1) {
}

CompartmentEventSink::~CompartmentEventSink(void) {
}

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

if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfCompartmentEventSink))
*ppvObj = (ITfCompartmentEventSink*)this;
else
*ppvObj = NULL;

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

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

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

// ITfCompartmentEventSink
STDMETHODIMP CompartmentEventSink::OnChange(REFGUID rguid) {
return S_OK;
}

} // namespace Ime
31 changes: 31 additions & 0 deletions libIME/CompartmentEventSink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef IME_COMPARTMENT_EVENT_SINK_H
#define IME_COMPARTMENT_EVENT_SINK_H

#include <msctf.h>

namespace Ime {

// base class used to implement specific compartment sink
// currently the class is not used in libIME

class CompartmentEventSink : public ITfCompartmentEventSink {
public:
CompartmentEventSink(void);
virtual ~CompartmentEventSink(void);

// COM stuff
// IUnknown
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
STDMETHODIMP_(ULONG) AddRef(void);
STDMETHODIMP_(ULONG) Release(void);

// ITfCompartmentEventSink
STDMETHODIMP OnChange(REFGUID rguid);

private:
int refCount_;
};

}

#endif
5 changes: 4 additions & 1 deletion libIME/Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "Dialog.h"

using namespace Ime;
namespace Ime {

Dialog::Dialog(void):
Window() {
Expand Down Expand Up @@ -90,3 +90,6 @@ void Dialog::onOK() {
void Dialog::onCancel() {
endDialog(IDCANCEL);
}

} // namespace Ime

4 changes: 3 additions & 1 deletion libIME/DisplayAttributeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "DisplayAttributeInfo.h"
#include <assert.h>

using namespace Ime;
namespace Ime {

DisplayAttributeInfo::DisplayAttributeInfo(const GUID& guid):
atom_(0),
Expand Down Expand Up @@ -102,3 +102,5 @@ STDMETHODIMP DisplayAttributeInfo::Reset() {
attrib_.lsStyle = TF_LS_NONE;
return S_OK;
}

} // namespace Ime
5 changes: 4 additions & 1 deletion libIME/DisplayAttributeInfoEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "ImeModule.h"
#include <assert.h>

using namespace Ime;
namespace Ime {

DisplayAttributeInfoEnum::DisplayAttributeInfoEnum(DisplayAttributeProvider* provider):
provider_(provider),
Expand Down Expand Up @@ -105,3 +105,6 @@ STDMETHODIMP DisplayAttributeInfoEnum::Skip(ULONG ulCount) {
++iterator_;
return S_OK;
}

} // namespace Ime

5 changes: 4 additions & 1 deletion libIME/DisplayAttributeProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
#include "ImeModule.h"
#include <assert.h>

using namespace Ime;
using namespace std;

namespace Ime {

DisplayAttributeProvider::DisplayAttributeProvider(ImeModule* module):
imeModule_(module),
refCount_(1) {
Expand Down Expand Up @@ -86,3 +87,5 @@ STDMETHODIMP DisplayAttributeProvider::GetDisplayAttributeInfo(REFGUID guidInfo,
}
return E_INVALIDARG;
}

} // namespace Ime
4 changes: 3 additions & 1 deletion libIME/EditSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "TextService.h"
#include <assert.h>

using namespace Ime;
namespace Ime {

EditSession::EditSession(TextService* service, ITfContext* context):
textService_(service),
Expand Down Expand Up @@ -77,3 +77,5 @@ STDMETHODIMP EditSession::DoEditSession(TfEditCookie ec) {
editCookie_ = ec;
return S_OK;
}

} // namespace Ime
5 changes: 4 additions & 1 deletion libIME/ImeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
#include "TextService.h"
#include "DisplayAttributeProvider.h"

using namespace Ime;
using namespace std;

namespace Ime {

// these values are not defined in older TSF SDK (windows xp)
#ifndef TF_IPP_CAPS_IMMERSIVESUPPORT
// for Windows 8
Expand Down Expand Up @@ -323,3 +324,5 @@ STDMETHODIMP ImeModule::LockServer(BOOL fLock) {
Release();
return S_OK;
}

} // namespace Ime
5 changes: 4 additions & 1 deletion libIME/ImeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "ImeWindow.h"

using namespace Ime;
namespace Ime {

ImeWindow::ImeWindow() {
}
Expand Down Expand Up @@ -72,3 +72,6 @@ bool ImeWindow::workingArea(RECT* rc, HWND app_wnd) {
*rc = mi.rcWork;
return true;
}

} // namespace Ime

4 changes: 3 additions & 1 deletion libIME/KeyEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "KeyEvent.h"

using namespace Ime;
namespace Ime {

KeyEvent::KeyEvent(UINT type, WPARAM wp, LPARAM lp):
type_(type),
Expand Down Expand Up @@ -48,3 +48,5 @@ KeyEvent::KeyEvent(const KeyEvent& other):

KeyEvent::~KeyEvent(void) {
}

} // namespace Ime
5 changes: 4 additions & 1 deletion libIME/LangBarButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <assert.h>
#include <stdlib.h>

using namespace Ime;
namespace Ime {

LangBarButton::LangBarButton(TextService* service, const GUID& guid, UINT commandId, wchar_t* text, DWORD style):
textService_(service),
Expand Down Expand Up @@ -314,3 +314,6 @@ void LangBarButton::update(DWORD flags) {
}
}
}

} // namespace Ime

5 changes: 4 additions & 1 deletion libIME/PropertyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
#include <assert.h>
#include <algorithm>

using namespace Ime;
using namespace std;

namespace Ime {

typedef INT_PTR (WINAPI *PropertySheetFunc)(LPCPROPSHEETHEADER lppsph);
static PropertySheetFunc g_PropertySheetW = NULL;

Expand Down Expand Up @@ -83,3 +84,5 @@ void PropertyDialog::removePage(PropertyPage* page) {
if(it != pages_.end())
pages_.erase(it);
}

} // namespace Ime
4 changes: 3 additions & 1 deletion libIME/PropertyPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "PropertyPage.h"

using namespace Ime;
namespace Ime {

PropertyPage::PropertyPage(LPCTSTR dialogId):
Dialog(),
Expand Down Expand Up @@ -77,3 +77,5 @@ void PropertyPage::onOK() {
void PropertyPage::onCancel() {
::SetWindowLongPtr(hwnd_, DWLP_MSGRESULT, PSNRET_NOERROR);
}

} // namespace Ime
Loading

0 comments on commit ce12f2a

Please sign in to comment.