]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/msw/ole/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 | #ifndef _WX_AUTOMTN_H_ | |
13 | #define _WX_AUTOMTN_H_ | |
14 | ||
15 | #include "wx/defs.h" | |
16 | ||
17 | #if wxUSE_OLE_AUTOMATION | |
18 | ||
19 | #include "wx/object.h" | |
20 | #include "wx/variant.h" | |
21 | ||
22 | typedef void WXIDISPATCH; | |
23 | typedef unsigned short* WXBSTR; | |
24 | typedef unsigned long WXLCID; | |
25 | ||
26 | #ifdef GetObject | |
27 | #undef GetObject | |
28 | #endif | |
29 | ||
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. | |
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 | |
42 | }; | |
43 | ||
44 | /* | |
45 | * wxAutomationObject | |
46 | * Wraps up an IDispatch pointer and invocation; does variant conversion. | |
47 | */ | |
48 | ||
49 | class WXDLLIMPEXP_CORE wxAutomationObject: public wxObject | |
50 | { | |
51 | public: | |
52 | wxAutomationObject(WXIDISPATCH* dispatchPtr = NULL); | |
53 | virtual ~wxAutomationObject(); | |
54 | ||
55 | // Set/get dispatch pointer | |
56 | void SetDispatchPtr(WXIDISPATCH* dispatchPtr) { m_dispatchPtr = dispatchPtr; } | |
57 | WXIDISPATCH* GetDispatchPtr() const { return m_dispatchPtr; } | |
58 | bool IsOk() const { return m_dispatchPtr != NULL; } | |
59 | ||
60 | // Get a dispatch pointer from the current object associated | |
61 | // with a ProgID, such as "Excel.Application" | |
62 | bool GetInstance(const wxString& progId, | |
63 | int flags = wxAutomationInstance_CreateIfNeeded) const; | |
64 | ||
65 | // Get a dispatch pointer from a new instance of the class | |
66 | bool CreateInstance(const wxString& progId) const; | |
67 | ||
68 | // Low-level invocation function. Pass either an array of variants, | |
69 | // or an array of pointers to variants. | |
70 | bool Invoke(const wxString& member, int action, | |
71 | wxVariant& retValue, int noArgs, wxVariant args[], const wxVariant* ptrArgs[] = 0) const; | |
72 | ||
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); | |
76 | ||
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); | |
82 | ||
83 | // Get/Put property | |
84 | wxVariant GetProperty(const wxString& property, int noArgs = 0, wxVariant args[] = NULL) const; | |
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); | |
90 | ||
91 | bool PutPropertyArray(const wxString& property, int noArgs, const wxVariant **args); | |
92 | bool PutProperty(const wxString& property, int noArgs, wxVariant args[]) ; | |
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. | |
102 | WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, wxVariant args[]) const; | |
103 | WXIDISPATCH* GetDispatchProperty(const wxString& property, int noArgs, const wxVariant **args) const; | |
104 | ||
105 | // A way of initialising another wxAutomationObject with a dispatch object, | |
106 | // without having to deal with nasty IDispatch pointers. | |
107 | bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs = 0, wxVariant args[] = NULL) const; | |
108 | bool GetObject(wxAutomationObject& obj, const wxString& property, int noArgs, const wxVariant **args) const; | |
109 | ||
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. | |
113 | WXLCID GetLCID() const; | |
114 | ||
115 | // Sets the locale identifier to be used in automation calls performed by | |
116 | // this object. The default is LOCALE_SYSTEM_DEFAULT. | |
117 | void SetLCID(WXLCID lcid); | |
118 | ||
119 | public: // public for compatibility only, don't use m_dispatchPtr directly. | |
120 | WXIDISPATCH* m_dispatchPtr; | |
121 | ||
122 | private: | |
123 | WXLCID m_lcid; | |
124 | ||
125 | wxDECLARE_NO_COPY_CLASS(wxAutomationObject); | |
126 | }; | |
127 | ||
128 | #endif // wxUSE_OLE_AUTOMATION | |
129 | ||
130 | #endif // _WX_AUTOMTN_H_ |