]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/msw/ole/automtn.h
Add convenient wxListCtrl::AppendColumn() wrapper.
[wxWidgets.git] / interface / wx / msw / ole / automtn.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: msw/ole/automtn.h
e54c96f1 3// Purpose: interface of wxAutomationObject
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
6eefca4f
VZ
9/**
10 Automation object creation flags.
11
12 These flags can be used with wxAutomationObject::GetInstance().
13
14 @since 2.9.2
15*/
16enum wxAutomationInstanceFlags
17{
18 /**
19 Only use the existing instance, never create a new one.
20
21 This flag can be used to forbid the creation of a new instance if none
22 is currently running.
23 */
24 wxAutomationInstance_UseExistingOnly = 0,
25
26 /**
27 Create a new instance if there are no existing ones.
28
29 This flag corresponds to the default behaviour of
30 wxAutomationObject::GetInstance() and means that if getting an existing
31 instance failed, we should call wxAutomationObject::CreateInstance() to
32 create a new one.
33 */
1244d2e0
VZ
34 wxAutomationInstance_CreateIfNeeded = 1,
35
36 /**
37 Do not show an error message if no existing instance is currently
38 running.
39
40 All other errors will still be reported as usual.
41 */
42 wxAutomationInstance_SilentIfNone = 2
6eefca4f
VZ
43};
44
45
23324ae1
FM
46/**
47 @class wxAutomationObject
4cc4bfaf 48
23324ae1
FM
49 The @b wxAutomationObject class represents an OLE automation object containing
50 a single data member,
51 an IDispatch pointer. It contains a number of functions that make it easy to
52 perform
53 automation operations, and set and get properties. The class makes heavy use of
54 the wxVariant class.
4cc4bfaf 55
23324ae1
FM
56 The usage of these classes is quite close to OLE automation usage in Visual
57 Basic. The API is
58 high-level, and the application can specify multiple properties in a single
59 string. The following example
60 gets the current Excel instance, and if it exists, makes the active cell bold.
4cc4bfaf 61
23324ae1
FM
62 @code
63 wxAutomationObject excelObject;
64 if (excelObject.GetInstance("Excel.Application"))
65 excelObject.PutProperty("ActiveCell.Font.Bold", @true);
66 @endcode
4cc4bfaf 67
23324ae1 68 Note that this class obviously works under Windows only.
4cc4bfaf 69
d9faa1fe
FM
70 @onlyfor{wxmsw}
71
23324ae1 72 @library{wxcore}
3c99e2fd 73 @category{data}
4cc4bfaf 74
e54c96f1 75 @see wxVariant
23324ae1
FM
76*/
77class wxAutomationObject : public wxObject
78{
79public:
80 /**
81 Constructor, taking an optional IDispatch pointer which will be released when
82 the
83 object is deleted.
84 */
4cc4bfaf 85 wxAutomationObject(WXIDISPATCH* dispatchPtr = NULL);
23324ae1
FM
86
87 /**
88 Destructor. If the internal IDispatch pointer is non-null, it will be released.
89 */
90 ~wxAutomationObject();
91
92 //@{
93 /**
94 Calls an automation method for this object. The first form takes a method name,
95 number of
96 arguments, and an array of variants. The second form takes a method name and
97 zero to six
98 constant references to variants. Since the variant class has constructors for
99 the basic
100 data types, and C++ provides temporary objects automatically, both of the
101 following lines
102 are syntactically valid:
d9faa1fe 103
4cc4bfaf 104 Note that @a method can contain dot-separated property names, to save the
23324ae1
FM
105 application
106 needing to call GetProperty several times using several temporary objects. For
107 example:
108 */
109 wxVariant CallMethod(const wxString& method, int noArgs,
328f5751
FM
110 wxVariant args[]) const;
111 const wxVariant CallMethod(const wxString& method, ... ) const;
23324ae1
FM
112 //@}
113
114 /**
27d76879 115 Creates a new object based on the ProgID, returning @true if the object was
23324ae1
FM
116 successfully created,
117 or @false if not.
118 */
27d76879 119 bool CreateInstance(const wxString& progId) const;
23324ae1 120
bb24f84b
VZ
121 /**
122 Checks if the object is in a valid state.
123
124 Returns @true if the object was successfully initialized or @false if
125 it has no valid IDispatch pointer.
126
127 @see GetDispatchPtr()
128 */
129 bool IsOk() const;
130
23324ae1
FM
131 /**
132 Gets the IDispatch pointer.
d72177fd
VZ
133
134 Notice that the return value of this function is an untyped pointer but
135 it can be safely cast to @c IDispatch.
23324ae1 136 */
d72177fd 137 void* GetDispatchPtr() const;
23324ae1
FM
138
139 /**
27d76879
VZ
140 Retrieves the current object associated with the specified ProgID, and
141 attaches the IDispatch pointer to this object.
142
6eefca4f
VZ
143 If attaching to an existing object failed and @a flags includes
144 wxAutomationInstance_CreateIfNeeded flag, a new object will be created.
1244d2e0
VZ
145 Otherwise this function will normally log an error message which may be
146 undesirable if the object may or may not exist. The
147 wxAutomationInstance_SilentIfNone flag can be used to prevent the error
148 from being logged in this case.
6eefca4f 149
27d76879 150 Returns @true if a pointer was successfully retrieved, @false
23324ae1 151 otherwise.
6eefca4f 152
23324ae1
FM
153 Note that this cannot cope with two instances of a given OLE object being
154 active simultaneously,
155 such as two copies of Excel running. Which object is referenced cannot
156 currently be specified.
6eefca4f
VZ
157
158 @param progId COM ProgID, e.g. "Excel.Application"
159 @param flags The creation flags (this parameters was added in wxWidgets
160 2.9.2)
23324ae1 161 */
6eefca4f
VZ
162 bool GetInstance(const wxString& progId,
163 int flags = wxAutomationInstance_CreateIfNeeded) const;
23324ae1
FM
164
165 /**
166 Retrieves a property from this object, assumed to be a dispatch pointer, and
4cc4bfaf 167 initialises @a obj with it.
23324ae1
FM
168 To avoid having to deal with IDispatch pointers directly, use this function in
169 preference
170 to GetProperty() when retrieving objects
171 from other objects.
23324ae1
FM
172 Note that an IDispatch pointer is stored as a void* pointer in wxVariant
173 objects.
d9faa1fe 174
4cc4bfaf 175 @see GetProperty()
23324ae1
FM
176 */
177 bool GetObject(wxAutomationObject& obj, const wxString& property,
178 int noArgs = 0,
328f5751 179 wxVariant args[] = NULL) const;
23324ae1
FM
180
181 //@{
182 /**
183 Gets a property value from this object. The first form takes a property name,
184 number of
185 arguments, and an array of variants. The second form takes a property name and
186 zero to six
187 constant references to variants. Since the variant class has constructors for
188 the basic
189 data types, and C++ provides temporary objects automatically, both of the
190 following lines
191 are syntactically valid:
d9faa1fe 192
4cc4bfaf 193 Note that @a property can contain dot-separated property names, to save the
23324ae1
FM
194 application
195 needing to call GetProperty several times using several temporary objects.
196 */
197 wxVariant GetProperty(const wxString& property, int noArgs,
328f5751
FM
198 wxVariant args[]) const;
199 const wxVariant GetProperty(const wxString& property, ... ) const;
23324ae1
FM
200 //@}
201
202 /**
203 This function is a low-level implementation that allows access to the IDispatch
204 Invoke function.
205 It is not meant to be called directly by the application, but is used by other
206 convenience functions.
d9faa1fe 207
4cc4bfaf
FM
208 @param member
209 The member function or property name.
210 @param action
211 Bitlist: may contain DISPATCH_PROPERTYPUT, DISPATCH_PROPERTYPUTREF,
212 DISPATCH_METHOD.
213 @param retValue
214 Return value (ignored if there is no return value)
215 @param noArgs
216 Number of arguments in args or ptrArgs.
217 @param args
218 If non-null, contains an array of variants.
219 @param ptrArgs
220 If non-null, contains an array of constant pointers to variants.
d9faa1fe 221
d29a9a8a 222 @return @true if the operation was successful, @false otherwise.
d9faa1fe 223
23324ae1 224 @remarks Two types of argument array are provided, so that when possible
4cc4bfaf 225 pointers are used for efficiency.
23324ae1
FM
226 */
227 bool Invoke(const wxString& member, int action,
228 wxVariant& retValue, int noArgs,
229 wxVariant args[],
328f5751 230 const wxVariant* ptrArgs[] = 0) const;
23324ae1
FM
231
232 //@{
233 /**
234 Puts a property value into this object. The first form takes a property name,
235 number of
236 arguments, and an array of variants. The second form takes a property name and
237 zero to six
238 constant references to variants. Since the variant class has constructors for
239 the basic
240 data types, and C++ provides temporary objects automatically, both of the
241 following lines
242 are syntactically valid:
d9faa1fe 243
4cc4bfaf 244 Note that @a property can contain dot-separated property names, to save the
23324ae1
FM
245 application
246 needing to call GetProperty several times using several temporary objects.
247 */
248 bool PutProperty(const wxString& property, int noArgs,
249 wxVariant args[]);
328f5751 250 const bool PutProperty(const wxString& property, ... );
23324ae1
FM
251 //@}
252
253 /**
254 Sets the IDispatch pointer. This function does not check if there is already an
255 IDispatch pointer.
23324ae1
FM
256 You may need to cast from IDispatch* to WXIDISPATCH* when calling this function.
257 */
258 void SetDispatchPtr(WXIDISPATCH* dispatchPtr);
259};
e54c96f1 260