]>
Commit | Line | Data |
---|---|---|
e8b6d59d JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: automtn.h | |
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; | |
24 | ||
89c684ef JS |
25 | #ifdef GetObject |
26 | #undef GetObject | |
27 | #endif | |
28 | ||
6eefca4f VZ |
29 | // Flags used with wxAutomationObject::GetInstance() |
30 | enum wxAutomationInstanceFlags | |
31 | { | |
32 | // Only use the existing instance, never create a new one. | |
33 | wxAutomationInstance_UseExistingOnly = 0, | |
34 | ||
35 | // Create a new instance if there are no existing ones. | |
36 | wxAutomationInstance_CreateIfNeeded = 1 | |
37 | }; | |
38 | ||
e8b6d59d JS |
39 | /* |
40 | * wxAutomationObject | |
41 | * Wraps up an IDispatch pointer and invocation; does variant conversion. | |
42 | */ | |
43 | ||
53a2db12 | 44 | class WXDLLIMPEXP_CORE wxAutomationObject: public wxObject |
e8b6d59d JS |
45 | { |
46 | public: | |
47 | wxAutomationObject(WXIDISPATCH* dispatchPtr = NULL); | |
d3c7fc99 | 48 | virtual ~wxAutomationObject(); |
e8b6d59d | 49 | |
0a0e6a5b | 50 | // Set/get dispatch pointer |
bb24f84b VZ |
51 | void SetDispatchPtr(WXIDISPATCH* dispatchPtr) { m_dispatchPtr = dispatchPtr; } |
52 | WXIDISPATCH* GetDispatchPtr() const { return m_dispatchPtr; } | |
53 | bool IsOk() const { return m_dispatchPtr != NULL; } | |
e8b6d59d | 54 | |
0a0e6a5b | 55 | // Get a dispatch pointer from the current object associated |
27d76879 | 56 | // with a ProgID, such as "Excel.Application" |
6eefca4f VZ |
57 | bool GetInstance(const wxString& progId, |
58 | int flags = wxAutomationInstance_CreateIfNeeded) const; | |
e8b6d59d | 59 | |
6eefca4f | 60 | // Get a dispatch pointer from a new instance of the class |
27d76879 | 61 | bool CreateInstance(const wxString& progId) const; |
e8b6d59d | 62 | |
0a0e6a5b WS |
63 | // Low-level invocation function. Pass either an array of variants, |
64 | // or an array of pointers to variants. | |
e8b6d59d JS |
65 | bool Invoke(const wxString& member, int action, |
66 | wxVariant& retValue, int noArgs, wxVariant args[], const wxVariant* ptrArgs[] = 0) const; | |
67 | ||
0a0e6a5b WS |
68 | // Invoke a member function |
69 | wxVariant CallMethod(const wxString& method, int noArgs, wxVariant args[]); | |
70 | wxVariant CallMethodArray(const wxString& method, int noArgs, const wxVariant **args); | |
e8b6d59d | 71 | |
0a0e6a5b WS |
72 | // Convenience function |
73 | wxVariant CallMethod(const wxString& method, | |
74 | const wxVariant& arg1 = wxNullVariant, const wxVariant& arg2 = wxNullVariant, | |
75 | const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant, | |
76 | const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant); | |
e8b6d59d | 77 | |
0a0e6a5b | 78 | // Get/Put property |
d3b9f782 | 79 | wxVariant GetProperty(const wxString& property, int noArgs = 0, wxVariant args[] = NULL) const; |
0a0e6a5b WS |
80 | wxVariant GetPropertyArray(const wxString& property, int noArgs, const wxVariant **args) const; |
81 | wxVariant GetProperty(const wxString& property, | |
82 | const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant, | |
83 | const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant, | |
84 | const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant); | |
e8b6d59d | 85 | |
c55fd2c6 | 86 | bool PutPropertyArray(const wxString& property, int noArgs, const wxVariant **args); |
e8b6d59d | 87 | bool PutProperty(const wxString& property, int noArgs, wxVariant args[]) ; |
0a0e6a5b WS |
88 | bool PutProperty(const wxString& property, |
89 | const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant, | |
90 | const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant, | |
91 | const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant); | |
92 | ||
93 | // Uses DISPATCH_PROPERTYGET | |
94 | // and returns a dispatch pointer. The calling code should call Release | |
95 | // on the pointer, though this could be implicit by constructing an wxAutomationObject | |
96 | // with it and letting the destructor call Release. | |
e8b6d59d | 97 | WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, wxVariant args[]) const; |
24f4ad95 | 98 | WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, const wxVariant **args) const; |
e8b6d59d | 99 | |
0a0e6a5b WS |
100 | // A way of initialising another wxAutomationObject with a dispatch object, |
101 | // without having to deal with nasty IDispatch pointers. | |
d3b9f782 | 102 | bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs = 0, wxVariant args[] = NULL) const; |
0a0e6a5b | 103 | bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs, const wxVariant **args) const; |
e8b6d59d | 104 | |
e8b6d59d JS |
105 | public: |
106 | WXIDISPATCH* m_dispatchPtr; | |
22f3361e | 107 | |
c0c133e1 | 108 | wxDECLARE_NO_COPY_CLASS(wxAutomationObject); |
e8b6d59d JS |
109 | }; |
110 | ||
ca5c6ac3 | 111 | #endif // wxUSE_OLE_AUTOMATION |
e8b6d59d | 112 | |
ca5c6ac3 | 113 | #endif // _WX_AUTOMTN_H_ |