2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: msw/ole/automtn.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxAutomationObject
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxAutomationObject
|
2008-03-09 08:33:59 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The @b wxAutomationObject class represents an OLE automation object containing
|
|
|
|
a single data member,
|
|
|
|
an IDispatch pointer. It contains a number of functions that make it easy to
|
|
|
|
perform
|
|
|
|
automation operations, and set and get properties. The class makes heavy use of
|
|
|
|
the wxVariant class.
|
2008-03-09 08:33:59 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The usage of these classes is quite close to OLE automation usage in Visual
|
|
|
|
Basic. The API is
|
|
|
|
high-level, and the application can specify multiple properties in a single
|
|
|
|
string. The following example
|
|
|
|
gets the current Excel instance, and if it exists, makes the active cell bold.
|
2008-03-09 08:33:59 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
wxAutomationObject excelObject;
|
|
|
|
if (excelObject.GetInstance("Excel.Application"))
|
|
|
|
excelObject.PutProperty("ActiveCell.Font.Bold", @true);
|
|
|
|
@endcode
|
2008-03-09 08:33:59 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Note that this class obviously works under Windows only.
|
2008-03-09 08:33:59 -04:00
|
|
|
|
2008-03-27 16:54:47 -04:00
|
|
|
@onlyfor{wxmsw}
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
2009-02-20 06:34:52 -05:00
|
|
|
@category{data}
|
2008-03-09 08:33:59 -04:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxVariant
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxAutomationObject : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor, taking an optional IDispatch pointer which will be released when
|
|
|
|
the
|
|
|
|
object is deleted.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
wxAutomationObject(WXIDISPATCH* dispatchPtr = NULL);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor. If the internal IDispatch pointer is non-null, it will be released.
|
|
|
|
*/
|
|
|
|
~wxAutomationObject();
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Calls an automation method for this object. The first form takes a method name,
|
|
|
|
number of
|
|
|
|
arguments, and an array of variants. The second form takes a method name and
|
|
|
|
zero to six
|
|
|
|
constant references to variants. Since the variant class has constructors for
|
|
|
|
the basic
|
|
|
|
data types, and C++ provides temporary objects automatically, both of the
|
|
|
|
following lines
|
|
|
|
are syntactically valid:
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
Note that @a method can contain dot-separated property names, to save the
|
2008-03-08 08:52:38 -05:00
|
|
|
application
|
|
|
|
needing to call GetProperty several times using several temporary objects. For
|
|
|
|
example:
|
|
|
|
*/
|
|
|
|
wxVariant CallMethod(const wxString& method, int noArgs,
|
2008-03-09 12:24:26 -04:00
|
|
|
wxVariant args[]) const;
|
|
|
|
const wxVariant CallMethod(const wxString& method, ... ) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a new object based on the class id, returning @true if the object was
|
|
|
|
successfully created,
|
|
|
|
or @false if not.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool CreateInstance(const wxString& classId) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-01-25 07:04:25 -05:00
|
|
|
/**
|
|
|
|
Checks if the object is in a valid state.
|
|
|
|
|
|
|
|
Returns @true if the object was successfully initialized or @false if
|
|
|
|
it has no valid IDispatch pointer.
|
|
|
|
|
|
|
|
@see GetDispatchPtr()
|
|
|
|
*/
|
|
|
|
bool IsOk() const;
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Gets the IDispatch pointer.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
IDispatch* GetDispatchPtr() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves the current object associated with a class id, and attaches the
|
|
|
|
IDispatch pointer
|
|
|
|
to this object. Returns @true if a pointer was successfully retrieved, @false
|
|
|
|
otherwise.
|
|
|
|
Note that this cannot cope with two instances of a given OLE object being
|
|
|
|
active simultaneously,
|
|
|
|
such as two copies of Excel running. Which object is referenced cannot
|
|
|
|
currently be specified.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool GetInstance(const wxString& classId) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Retrieves a property from this object, assumed to be a dispatch pointer, and
|
2008-03-09 08:33:59 -04:00
|
|
|
initialises @a obj with it.
|
2008-03-08 08:52:38 -05:00
|
|
|
To avoid having to deal with IDispatch pointers directly, use this function in
|
|
|
|
preference
|
|
|
|
to GetProperty() when retrieving objects
|
|
|
|
from other objects.
|
|
|
|
Note that an IDispatch pointer is stored as a void* pointer in wxVariant
|
|
|
|
objects.
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see GetProperty()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool GetObject(wxAutomationObject& obj, const wxString& property,
|
|
|
|
int noArgs = 0,
|
2008-03-09 12:24:26 -04:00
|
|
|
wxVariant args[] = NULL) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Gets a property value from this object. The first form takes a property name,
|
|
|
|
number of
|
|
|
|
arguments, and an array of variants. The second form takes a property name and
|
|
|
|
zero to six
|
|
|
|
constant references to variants. Since the variant class has constructors for
|
|
|
|
the basic
|
|
|
|
data types, and C++ provides temporary objects automatically, both of the
|
|
|
|
following lines
|
|
|
|
are syntactically valid:
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
Note that @a property can contain dot-separated property names, to save the
|
2008-03-08 08:52:38 -05:00
|
|
|
application
|
|
|
|
needing to call GetProperty several times using several temporary objects.
|
|
|
|
*/
|
|
|
|
wxVariant GetProperty(const wxString& property, int noArgs,
|
2008-03-09 12:24:26 -04:00
|
|
|
wxVariant args[]) const;
|
|
|
|
const wxVariant GetProperty(const wxString& property, ... ) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
This function is a low-level implementation that allows access to the IDispatch
|
|
|
|
Invoke function.
|
|
|
|
It is not meant to be called directly by the application, but is used by other
|
|
|
|
convenience functions.
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@param member
|
|
|
|
The member function or property name.
|
|
|
|
@param action
|
|
|
|
Bitlist: may contain DISPATCH_PROPERTYPUT, DISPATCH_PROPERTYPUTREF,
|
|
|
|
DISPATCH_METHOD.
|
|
|
|
@param retValue
|
|
|
|
Return value (ignored if there is no return value)
|
|
|
|
@param noArgs
|
|
|
|
Number of arguments in args or ptrArgs.
|
|
|
|
@param args
|
|
|
|
If non-null, contains an array of variants.
|
|
|
|
@param ptrArgs
|
|
|
|
If non-null, contains an array of constant pointers to variants.
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return @true if the operation was successful, @false otherwise.
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@remarks Two types of argument array are provided, so that when possible
|
2008-03-09 08:33:59 -04:00
|
|
|
pointers are used for efficiency.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Invoke(const wxString& member, int action,
|
|
|
|
wxVariant& retValue, int noArgs,
|
|
|
|
wxVariant args[],
|
2008-03-09 12:24:26 -04:00
|
|
|
const wxVariant* ptrArgs[] = 0) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Puts a property value into this object. The first form takes a property name,
|
|
|
|
number of
|
|
|
|
arguments, and an array of variants. The second form takes a property name and
|
|
|
|
zero to six
|
|
|
|
constant references to variants. Since the variant class has constructors for
|
|
|
|
the basic
|
|
|
|
data types, and C++ provides temporary objects automatically, both of the
|
|
|
|
following lines
|
|
|
|
are syntactically valid:
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
Note that @a property can contain dot-separated property names, to save the
|
2008-03-08 08:52:38 -05:00
|
|
|
application
|
|
|
|
needing to call GetProperty several times using several temporary objects.
|
|
|
|
*/
|
|
|
|
bool PutProperty(const wxString& property, int noArgs,
|
|
|
|
wxVariant args[]);
|
2008-03-09 12:24:26 -04:00
|
|
|
const bool PutProperty(const wxString& property, ... );
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the IDispatch pointer. This function does not check if there is already an
|
|
|
|
IDispatch pointer.
|
|
|
|
You may need to cast from IDispatch* to WXIDISPATCH* when calling this function.
|
|
|
|
*/
|
|
|
|
void SetDispatchPtr(WXIDISPATCH* dispatchPtr);
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|