Skip to content

Commit

Permalink
Implement ITfFnConfigure so the config dialog can be launched in cont…
Browse files Browse the repository at this point in the history
…rol panel.
  • Loading branch information
PCMan committed Sep 12, 2013
1 parent fc540a6 commit 2ce8e2e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 13 deletions.
19 changes: 15 additions & 4 deletions ChewingTextService/ChewingTextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,7 @@ bool TextService::onCommand(UINT id) {
break;
case ID_CONFIG: // show config dialog
if(!isImmersive()) { // only do this in desktop app mode
Ime::PropertyDialog dlg;
TypingPage* typingPage = new TypingPage();
dlg.addPage(typingPage);
dlg.showModal(this->module()->hInstance(), (LPCTSTR)IDS_CONFIG_TITLE);
onConfigure(HWND_DESKTOP);
}
break;
case ID_ABOUT: // show about dialog
Expand Down Expand Up @@ -404,6 +401,20 @@ bool TextService::onCommand(UINT id) {
return true;
}

// virtual
bool TextService::onConfigure(HWND hwndParent) {
// FIXME: alternatively, should we make the configuration
// dialog a separate program and launch it instead?

// FIXME: something wrong causing crashes here.
// I'm not sure what's the problem yet.
Ime::PropertyDialog dlg;
TypingPage* typingPage = new TypingPage();
dlg.addPage(typingPage);
dlg.showModal(this->module()->hInstance(), (LPCTSTR)IDS_CONFIG_TITLE, 0, hwndParent);
return true;
}


void TextService::updateCandidates(Ime::EditSession* session) {
assert(candidateWindow_);
Expand Down
3 changes: 3 additions & 0 deletions ChewingTextService/ChewingTextService.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class TextService: public Ime::TextService {

virtual bool onCommand(UINT id);

// called when config dialog needs to be launched
virtual bool onConfigure(HWND hwndParent);

ChewingContext* chewingContext() {
return chewingContext_;
}
Expand Down
4 changes: 2 additions & 2 deletions libIME/PropertyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using namespace Ime;
using namespace std;

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

PropertyDialog::PropertyDialog(void) {
Expand All @@ -21,7 +21,7 @@ PropertyDialog::~PropertyDialog(void) {
}
}

INT_PTR PropertyDialog::showModal(HINSTANCE hInstance, LPCTSTR captionId, LPCTSTR iconId, DWORD flags, HWND parent) {
INT_PTR PropertyDialog::showModal(HINSTANCE hInstance, LPCTSTR captionId, LPCTSTR iconId, HWND parent, DWORD flags) {
assert(pages_.size() > 0);

// Windows 8 does not allow linking to comctl32.dll
Expand Down
2 changes: 1 addition & 1 deletion libIME/PropertyDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PropertyDialog {

void addPage(PropertyPage* page);
void removePage(PropertyPage* page);
INT_PTR showModal(HINSTANCE hInstance, LPCTSTR captionId = 0, LPCTSTR iconId = 0, DWORD flags = PSH_NOAPPLYNOW | PSH_USEICONID | PSH_PROPSHEETPAGE, HWND parent = HWND_DESKTOP);
INT_PTR showModal(HINSTANCE hInstance, LPCTSTR captionId = 0, LPCTSTR iconId = 0, HWND parent = HWND_DESKTOP, DWORD flags = PSH_NOAPPLYNOW | PSH_USEICONID | PSH_PROPSHEETPAGE);

private:
std::vector<PropertyPage*> pages_;
Expand Down
22 changes: 20 additions & 2 deletions libIME/TextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ bool TextService::onCommand(UINT id) {
return false;
}

// virtual
bool TextService::onConfigure(HWND hwndParent) {
return true;
}


// COM stuff

Expand All @@ -289,8 +294,10 @@ STDMETHODIMP TextService::QueryInterface(REFIID riid, void **ppvObj) {
*ppvObj = (ITfTextInputProcessor*)this;
else if(IsEqualIID(riid, IID_ITfDisplayAttributeProvider))
*ppvObj = (ITfDisplayAttributeProvider*)this;
else if(IsEqualIID(riid, IID_ITfThreadMgrEventSink))
*ppvObj = (ITfThreadMgrEventSink*)this;
else if(IsEqualIID(riid, IID_ITfDisplayAttributeProvider))
*ppvObj = (ITfDisplayAttributeProvider*)this;
else if(IsEqualIID(riid, IID_ITfFnConfigure ))
*ppvObj = (ITfFnConfigure *)this;
else if(IsEqualIID(riid, IID_ITfTextEditSink))
*ppvObj = (ITfTextEditSink*)this;
else if(IsEqualIID(riid, IID_ITfKeyEventSink))
Expand Down Expand Up @@ -423,6 +430,17 @@ STDMETHODIMP TextService::Deactivate() {
}


// ITfFnConfigure
STDMETHODIMP TextService::Show(HWND hwndParent, LANGID langid, REFGUID rguidProfile) {
return onConfigure(hwndParent) ? S_OK : E_FAIL;
}

// ITfFunction
STDMETHODIMP TextService::GetDisplayName(BSTR *pbstrName) {
*pbstrName = ::SysAllocString(L"Configuration");
return S_OK;
}

// ITfThreadMgrEventSink
STDMETHODIMP TextService::OnInitDocumentMgr(ITfDocumentMgr *pDocMgr) {
return S_OK;
Expand Down
24 changes: 20 additions & 4 deletions libIME/TextService.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@

#include "libIME.h"
#include <msctf.h>
#include <Ctffunc.h>
#include "EditSession.h"
#include "KeyEvent.h"
#include "ComPtr.h"

#include <vector>

// for Windows 8 support
#ifndef TF_TMF_IMMERSIVEMODE // this is defined in Win 8 SDK
#define TF_TMF_IMMERSIVEMODE 0x40000000
#endif

namespace Ime {

class ImeModule;
Expand All @@ -19,6 +25,7 @@ class TextService:
// TSF interfaces
public ITfTextInputProcessor,
public ITfDisplayAttributeProvider,
public ITfFnConfigure,
// event sinks
public ITfThreadMgrEventSink,
public ITfTextEditSink,
Expand Down Expand Up @@ -88,6 +95,9 @@ class TextService:
// called when a language button or menu item is clicked
virtual bool onCommand(UINT id);

// called when config dialog needs to be launched
virtual bool onConfigure(HWND hwndParent);

// COM related stuff
public:
// IUnknown
Expand All @@ -99,6 +109,16 @@ class TextService:
STDMETHODIMP Activate(ITfThreadMgr *pThreadMgr, TfClientId tfClientId);
STDMETHODIMP Deactivate();

// ITfDisplayAttributeProvider
STDMETHODIMP EnumDisplayAttributeInfo(IEnumTfDisplayAttributeInfo **ppEnum);
STDMETHODIMP GetDisplayAttributeInfo(REFGUID guidInfo, ITfDisplayAttributeInfo **ppInfo);

// ITfFnConfigure
STDMETHODIMP Show(HWND hwndParent, LANGID langid, REFGUID rguidProfile);

// ITfFunction
STDMETHODIMP GetDisplayName(BSTR *pbstrName);

// ITfThreadMgrEventSink
STDMETHODIMP OnInitDocumentMgr(ITfDocumentMgr *pDocMgr);
STDMETHODIMP OnUninitDocumentMgr(ITfDocumentMgr *pDocMgr);
Expand All @@ -120,10 +140,6 @@ class TextService:
// ITfCompositionSink
STDMETHODIMP OnCompositionTerminated(TfEditCookie ecWrite, ITfComposition *pComposition);

// ITfDisplayAttributeProvider
STDMETHODIMP EnumDisplayAttributeInfo(IEnumTfDisplayAttributeInfo **ppEnum);
STDMETHODIMP GetDisplayAttributeInfo(REFGUID guidInfo, ITfDisplayAttributeInfo **ppInfo);

protected:
// edit session classes, used with TSF
class KeyEditSession: public EditSession {
Expand Down

0 comments on commit 2ce8e2e

Please sign in to comment.