]>
Commit | Line | Data |
---|---|---|
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
13 | #pragma interface "automtn.h" | |
14 | #endif | |
15 | ||
16 | #ifndef _WX_AUTOMTN_H_ | |
17 | #define _WX_AUTOMTN_H_ | |
18 | ||
19 | #include "wx/object.h" | |
20 | #include "wx/variant.h" | |
21 | ||
22 | typedef void WXIDISPATCH; | |
23 | typedef unsigned short* WXBSTR; | |
24 | ||
25 | #ifdef GetObject | |
26 | #undef GetObject | |
27 | #endif | |
28 | ||
29 | /* | |
30 | * wxAutomationObject | |
31 | * Wraps up an IDispatch pointer and invocation; does variant conversion. | |
32 | */ | |
33 | ||
34 | class WXDLLEXPORT wxAutomationObject: public wxObject | |
35 | { | |
36 | public: | |
37 | wxAutomationObject(WXIDISPATCH* dispatchPtr = NULL); | |
38 | ~wxAutomationObject(); | |
39 | ||
40 | // Set/get dispatch pointer | |
41 | inline void SetDispatchPtr(WXIDISPATCH* dispatchPtr) { m_dispatchPtr = dispatchPtr; }; | |
42 | inline WXIDISPATCH* GetDispatchPtr() const { return m_dispatchPtr; } | |
43 | ||
44 | // Get a dispatch pointer from the current object associated | |
45 | // with a class id, such as "Excel.Application" | |
46 | bool GetInstance(const wxString& classId) const; | |
47 | ||
48 | // Get a dispatch pointer from a new instance of the the class | |
49 | bool CreateInstance(const wxString& classId) const; | |
50 | ||
51 | // Low-level invocation function. Pass either an array of variants, | |
52 | // or an array of pointers to variants. | |
53 | bool Invoke(const wxString& member, int action, | |
54 | wxVariant& retValue, int noArgs, wxVariant args[], const wxVariant* ptrArgs[] = 0) const; | |
55 | ||
56 | // Invoke a member function | |
57 | wxVariant CallMethod(const wxString& method, int noArgs, wxVariant args[]); | |
58 | wxVariant CallMethodArray(const wxString& method, int noArgs, const wxVariant **args); | |
59 | ||
60 | // Convenience function | |
61 | wxVariant CallMethod(const wxString& method, | |
62 | const wxVariant& arg1 = wxNullVariant, const wxVariant& arg2 = wxNullVariant, | |
63 | const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant, | |
64 | const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant); | |
65 | ||
66 | // Get/Put property | |
67 | wxVariant GetProperty(const wxString& property, int noArgs = 0, wxVariant args[] = (wxVariant*) NULL) const; | |
68 | wxVariant GetPropertyArray(const wxString& property, int noArgs, const wxVariant **args) const; | |
69 | wxVariant GetProperty(const wxString& property, | |
70 | const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant, | |
71 | const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant, | |
72 | const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant); | |
73 | ||
74 | bool PutPropertyArray(const wxString& property, int noArgs, const wxVariant **args); | |
75 | bool PutProperty(const wxString& property, int noArgs, wxVariant args[]) ; | |
76 | bool PutProperty(const wxString& property, | |
77 | const wxVariant& arg1, const wxVariant& arg2 = wxNullVariant, | |
78 | const wxVariant& arg3 = wxNullVariant, const wxVariant& arg4 = wxNullVariant, | |
79 | const wxVariant& arg5 = wxNullVariant, const wxVariant& arg6 = wxNullVariant); | |
80 | ||
81 | // Uses DISPATCH_PROPERTYGET | |
82 | // and returns a dispatch pointer. The calling code should call Release | |
83 | // on the pointer, though this could be implicit by constructing an wxAutomationObject | |
84 | // with it and letting the destructor call Release. | |
85 | WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, wxVariant args[]) const; | |
86 | WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, const wxVariant **args) const; | |
87 | ||
88 | // A way of initialising another wxAutomationObject with a dispatch object, | |
89 | // without having to deal with nasty IDispatch pointers. | |
90 | bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs = 0, wxVariant args[] = (wxVariant*) NULL) const; | |
91 | bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs, const wxVariant **args) const; | |
92 | ||
93 | public: | |
94 | WXIDISPATCH* m_dispatchPtr; | |
95 | ||
96 | DECLARE_NO_COPY_CLASS(wxAutomationObject) | |
97 | }; | |
98 | ||
99 | ||
100 | #endif | |
101 | // _WX_AUTOMTN_H_ |