From f239af65af594968e2fe6885e389a5bd28d73d9d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 31 Jul 2012 10:31:55 +0000 Subject: [PATCH] Allow setting LCID used by wxAutomationObject. Default user-locale-dependent LCID may be inappropriate for some situations, notably Microsoft Excel uses localized formula names for non-English LCIDs. So add a way to change the LCID to use at wxAutomationObject level while preserving the old behaviour by default. Closes #14540. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72265 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/msw/ole/automtn.h | 14 +++++++++++++- interface/wx/msw/ole/automtn.h | 25 +++++++++++++++++++++++++ src/msw/ole/automtn.cpp | 17 +++++++++++++++-- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 8d14d1b268..29f4ca057a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -547,6 +547,7 @@ wxGTK: wxMSW: - Add support for CURRENCY and SCODE types to OLE Automation helpers (PB). +- Allow setting LCID used by wxAutomationObject (PB). 2.9.4: (released 2012-07-09) diff --git a/include/wx/msw/ole/automtn.h b/include/wx/msw/ole/automtn.h index d38de41be7..4f7ea97dd7 100644 --- a/include/wx/msw/ole/automtn.h +++ b/include/wx/msw/ole/automtn.h @@ -106,9 +106,21 @@ public: bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs = 0, wxVariant args[] = NULL) const; bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs, const wxVariant **args) const; -public: + // Returns the locale identifier used in automation calls. The default is + // LOCALE_SYSTEM_DEFAULT. Objects obtained by GetObject() inherit the + // locale identifier from the one that created them. + LCID GetLCID() const; + + // Sets the locale identifier to be used in automation calls performed by + // this object. The default is LOCALE_SYSTEM_DEFAULT. + void SetLCID(LCID lcid); + +public: // public for compatibility only, don't use m_dispatchPtr directly. WXIDISPATCH* m_dispatchPtr; +private: + LCID m_lcid; + wxDECLARE_NO_COPY_CLASS(wxAutomationObject); }; diff --git a/interface/wx/msw/ole/automtn.h b/interface/wx/msw/ole/automtn.h index e30c984754..9e7f3287a8 100644 --- a/interface/wx/msw/ole/automtn.h +++ b/interface/wx/msw/ole/automtn.h @@ -429,5 +429,30 @@ public: You may need to cast from IDispatch* to WXIDISPATCH* when calling this function. */ void SetDispatchPtr(WXIDISPATCH* dispatchPtr); + + /** + Returns the locale identifier used in automation calls. + + The default is LOCALE_SYSTEM_DEFAULT but the objects obtained by + GetObject() inherit the locale identifier from the one that created + them. + + @since 2.9.5 + */ + LCID GetLCID() const; + + /** + Sets the locale identifier to be used in automation calls performed by + this object. + + The default value is LOCALE_SYSTEM_DEFAULT. + + Notice that any automation objects created by this one inherit the same + LCID. + + @since 2.9.5 + */ + void SetLCID(LCID lcid); + }; diff --git a/src/msw/ole/automtn.cpp b/src/msw/ole/automtn.cpp index 10e9063a73..9c3600dd12 100644 --- a/src/msw/ole/automtn.cpp +++ b/src/msw/ole/automtn.cpp @@ -70,6 +70,7 @@ ShowException(const wxString& member, wxAutomationObject::wxAutomationObject(WXIDISPATCH* dispatchPtr) { m_dispatchPtr = dispatchPtr; + m_lcid = LOCALE_SYSTEM_DEFAULT; } wxAutomationObject::~wxAutomationObject() @@ -161,7 +162,7 @@ bool wxAutomationObject::Invoke(const wxString& member, int action, // We rely on the fact that wxBasicString is // just BSTR with some methods here. reinterpret_cast(&argNames[0]), - 1 + namedArgCount, LOCALE_SYSTEM_DEFAULT, &dispIds[0]); + 1 + namedArgCount, m_lcid, &dispIds[0]); if (FAILED(hr)) { ShowException(member, hr); @@ -194,7 +195,7 @@ bool wxAutomationObject::Invoke(const wxString& member, int action, EXCEPINFO excep; wxZeroMemory(excep); - hr = ((IDispatch*)m_dispatchPtr)->Invoke(dispIds[0], IID_NULL, LOCALE_SYSTEM_DEFAULT, + hr = ((IDispatch*)m_dispatchPtr)->Invoke(dispIds[0], IID_NULL, m_lcid, (WORD)action, &dispparams, vReturnPtr, &excep, &uiArgErr); if (FAILED(hr)) @@ -467,6 +468,7 @@ bool wxAutomationObject::GetObject(wxAutomationObject& obj, const wxString& prop if (dispatch) { obj.SetDispatchPtr(dispatch); + obj.SetLCID(GetLCID()); return true; } else @@ -480,6 +482,7 @@ bool wxAutomationObject::GetObject(wxAutomationObject& obj, const wxString& prop if (dispatch) { obj.SetDispatchPtr(dispatch); + obj.SetLCID(GetLCID()); return true; } else @@ -589,6 +592,16 @@ bool wxAutomationObject::CreateInstance(const wxString& progId) const return m_dispatchPtr != NULL; } +LCID wxAutomationObject::GetLCID() const +{ + return m_lcid; +} + +void wxAutomationObject::SetLCID(LCID lcid) +{ + m_lcid = lcid; +} + static void ShowException(const wxString& member, HRESULT hr, -- 2.45.2