]>
Commit | Line | Data |
---|---|---|
e8b6d59d | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/msw/ole/automtn.h |
e8b6d59d JS |
3 | // Purpose: OLE automation utilities |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 11/6/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998, Julian Smart | |
65571936 | 9 | // Licence: wxWindows licence |
e8b6d59d JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
e8b6d59d JS |
12 | #ifndef _WX_AUTOMTN_H_ |
13 | #define _WX_AUTOMTN_H_ | |
14 | ||
ca5c6ac3 VZ |
15 | #include "wx/defs.h" |
16 | ||
17 | #if wxUSE_OLE_AUTOMATION | |
18 | ||
e8b6d59d JS |
19 | #include "wx/object.h" |
20 | #include "wx/variant.h" | |
21 | ||
22 | typedef void WXIDISPATCH; | |
23 | typedef unsigned short* WXBSTR; | |
03a1d863 | 24 | typedef unsigned long WXLCID; |
e8b6d59d | 25 | |
89c684ef JS |
26 | #ifdef GetObject |
27 | #undef GetObject | |
28 | #endif | |
29 | ||
6eefca4f VZ |
30 | // Flags used with wxAutomationObject::GetInstance() |
31 | enum wxAutomationInstanceFlags | |
32 | { | |
33 | // Only use the existing instance, never create a new one. | |
34 | wxAutomationInstance_UseExistingOnly = 0, | |
35 | ||
36 | // Create a new instance if there are no existing ones. | |
1244d2e0 VZ |
37 | wxAutomationInstance_CreateIfNeeded = 1, |
38 | ||
39 | // Do not log errors if we failed to get the existing instance because none | |
40 | // is available. | |
41 | wxAutomationInstance_SilentIfNone = 2 | |
6eefca4f VZ |
42 | }; |
43 | ||
e8b6d59d JS |
44 | /* |
45 | * wxAutomationObject | |
46 | * Wraps up an IDispatch pointer and invocation; does variant conversion. | |
47 | */ | |
48 | ||
53a2db12 | 49 | class WXDLLIMPEXP_CORE wxAutomationObject: public wxObject |
e8b6d59d JS |
50 | { |
51 | public: | |
52 | wxAutomationObject(WXIDISPATCH* dispatchPtr = NULL); | |
d3c7fc99 | 53 | virtual ~wxAutomationObject(); |
e8b6d59d | 54 | |
0a0e6a5b | 55 | // Set/get dispatch pointer |
bb24f84b VZ |
56 | void SetDispatchPtr(WXIDISPATCH* dispatchPtr) { m_dispatchPtr = dispatchPtr; } |
57 | WXIDISPATCH* GetDispatchPtr() const { return m_dispatchPtr; } | |
58 | bool IsOk() const { return m_dispatchPtr != NULL; } | |
e8b6d59d | 59 | |
0a0e6a5b | 60 | // Get a dispatch pointer from the current object associated |
27d76879 | 61 | // with a ProgID, such as "Excel.Application" |
6eefca4f VZ |
62 | bool GetInstance(const wxString& progId, |
63 | int flags = wxAutomationInstance_CreateIfNeeded) const; | |
e8b6d59d | 64 | |
6eefca4f | 65 | // Get a dispatch pointer from a new instance of the class |
27d76879 | 66 | bool CreateInstance(const wxString& progId) const; |
e8b6d59d | 67 | |
0a0e6a5b WS |
68 | // Low-level invocation function. Pass either an array of variants, |
69 | // or an array of pointers to variants. | |
e8b6d59d JS |
70 | bool Invoke(const wxString& member, int action, |
71 | wxVariant& retValue, int noArgs, wxVariant args[], const wxVariant* ptrArgs[] = 0) const; | |
72 | ||
0a0e6a5b WS |
73 | // Invoke a member function |
74 | wxVariant CallMethod(const wxString& method, int noArgs, wxVariant args[]); | |
75 | wxVariant CallMethodArray(const wxString& method, int noArgs, const wxVariant **args); | |
e8b6d59d | 76 | |
0a0e6a5b WS |
77 | // Convenience function |
78 | wxVariant CallMethod(const wxString& method, | |
79 | const wxVariant& arg1 = wxNullVariant, const wxVariant& arg2 = wxNullVariant, | |
80 | const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant, | |
81 | const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant); | |
e8b6d59d | 82 | |
0a0e6a5b | 83 | // Get/Put property |
d3b9f782 | 84 | wxVariant GetProperty(const wxString& property, int noArgs = 0, wxVariant args[] = NULL) const; |
0a0e6a5b WS |
85 | wxVariant GetPropertyArray(const wxString& property, int noArgs, const wxVariant **args) const; |
86 | wxVariant GetProperty(const wxString& property, | |
87 | const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant, | |
88 | const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant, | |
89 | const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant); | |
e8b6d59d | 90 | |
c55fd2c6 | 91 | bool PutPropertyArray(const wxString& property, int noArgs, const wxVariant **args); |
e8b6d59d | 92 | bool PutProperty(const wxString& property, int noArgs, wxVariant args[]) ; |
0a0e6a5b WS |
93 | bool PutProperty(const wxString& property, |
94 | const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant, | |
95 | const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant, | |
96 | const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant); | |
97 | ||
98 | // Uses DISPATCH_PROPERTYGET | |
99 | // and returns a dispatch pointer. The calling code should call Release | |
100 | // on the pointer, though this could be implicit by constructing an wxAutomationObject | |
101 | // with it and letting the destructor call Release. | |
e8b6d59d | 102 | WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, wxVariant args[]) const; |
24f4ad95 | 103 | WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, const wxVariant **args) const; |
e8b6d59d | 104 | |
0a0e6a5b WS |
105 | // A way of initialising another wxAutomationObject with a dispatch object, |
106 | // without having to deal with nasty IDispatch pointers. | |
d3b9f782 | 107 | bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs = 0, wxVariant args[] = NULL) const; |
0a0e6a5b | 108 | bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs, const wxVariant **args) const; |
e8b6d59d | 109 | |
f239af65 VZ |
110 | // Returns the locale identifier used in automation calls. The default is |
111 | // LOCALE_SYSTEM_DEFAULT. Objects obtained by GetObject() inherit the | |
112 | // locale identifier from the one that created them. | |
03a1d863 | 113 | WXLCID GetLCID() const; |
f239af65 VZ |
114 | |
115 | // Sets the locale identifier to be used in automation calls performed by | |
116 | // this object. The default is LOCALE_SYSTEM_DEFAULT. | |
03a1d863 | 117 | void SetLCID(WXLCID lcid); |
f239af65 VZ |
118 | |
119 | public: // public for compatibility only, don't use m_dispatchPtr directly. | |
e8b6d59d | 120 | WXIDISPATCH* m_dispatchPtr; |
22f3361e | 121 | |
f239af65 | 122 | private: |
03a1d863 | 123 | WXLCID m_lcid; |
f239af65 | 124 | |
c0c133e1 | 125 | wxDECLARE_NO_COPY_CLASS(wxAutomationObject); |
e8b6d59d JS |
126 | }; |
127 | ||
ca5c6ac3 | 128 | #endif // wxUSE_OLE_AUTOMATION |
e8b6d59d | 129 | |
ca5c6ac3 | 130 | #endif // _WX_AUTOMTN_H_ |