TQAxFactory Class

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQAxFactory Class Reference
[TQAxServer module]

The TQAxFactory class defines a factory for the creation of COM components. More...

This class is part of the TQt ActiveTQt Extension.

`#include <qaxfactory.h>`

List of all member functions.

## Public Members

- TQAxFactory ( const TQUuid & libid, const TQUuid & appid )
- virtual ~TQAxFactory ()
- virtual TQStringList featureList () const = 0
- virtual TQWidget * create ( const TQString & key, TQWidget * parent = 0, const char * name = 0 )
- virtual TQObject * createObject ( const TQString & key, TQObject * parent = 0, const char * name = 0 )
- virtual TQMetaObject * metaObject ( const TQString & key ) const
- virtual bool createObjectWrapper ( TQObject * object, IDispatch ** wrapper )
- virtual TQUuid classID ( const TQString & key ) const
- virtual TQUuid interfaceID ( const TQString & key ) const
- virtual TQUuid eventsID ( const TQString & key ) const
- virtual TQUuid typeLibID () const
- virtual TQUuid appID () const
- virtual void registerClass ( const TQString & key, TQSettings * settings ) const
- virtual void unregisterClass ( const TQString & key, TQSettings * settings ) const
- virtual bool validateLicenseKey ( const TQString & key, const TQString & licenseKey ) const
- virtual TQString exposeToSuperClass ( const TQString & key ) const
- virtual bool stayTopLevel ( const TQString & key ) const
- virtual bool hasStockEvents ( const TQString & key ) const
- virtual bool isService () const
- enum ServerType { SingleInstance, MultipleInstances }

## Static Public Members

- bool isServer ()
- TQString serverDirPath ()
- TQString serverFilePath ()
- bool startServer ( ServerType type = MultipleInstances )
- bool stopServer ()

## Detailed Description

This class is defined in the TQt ActiveTQt Extension, which can be found in the `qt/extensions` directory. It is not included in the main TQt API.

The TQAxFactory class defines a factory for the creation of COM components.

Implement this factory once in your ActiveX server to provide information about the components the server can create. If your server supports just a single ActiveX control, you can use the default factory implementation instead of implementing the factory yourself. Use the TQAXFACTORY_DEFAULT macro in any implementation file (e.g. main.cpp) to instantiate and export the default factory:

        #include <ntqapplication.h>
        #include <qaxfactory.h>

        #include "theactivex.h"

        TQAXFACTORY_DEFAULT(
            TheActiveX,                               // widget class
            "{01234567-89AB-CDEF-0123-456789ABCDEF}", // class ID
            "{01234567-89AB-CDEF-0123-456789ABCDEF}", // interface ID
            "{01234567-89AB-CDEF-0123-456789ABCDEF}", // event interface ID
            "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
            "{01234567-89AB-CDEF-0123-456789ABCDEF}"  // application ID
            )

If you implement your own factory reimplement the pure virtual functions, provide the unique identifiers for the ActiveX controls, and use the TQAXFACTORY_EXPORT macro to instantiate and export it:

        TQStringList ActiveTQtFactory::featureList() const
        {
            TQStringList list;
            list << "ActiveX1";
            list << "ActiveX2";
            ...
            return list;
        }

        TQWidget *ActiveTQtFactory::create( const TQString &key, TQWidget *parent, const char *name )
        {
            if ( key == "ActiveX1" )
                return new ActiveX1( parent, name );
            if ( key == "ActiveX2" )
                return new ActiveX2( parent, name );
            ...
            return 0;
        }

        TQUuid ActiveTQtFactory::classID( const TQString &key ) const
        {
            if ( key == "ActiveX1" )
                return "{01234567-89AB-CDEF-0123-456789ABCDEF}";
            ...
            return TQUuid();
        }

        TQUuid ActiveTQtFactory::interfaceID( const TQString &key ) const
        {
            if ( key == "ActiveX1" )
                return "{01234567-89AB-CDEF-0123-456789ABCDEF}";
            ...
            return TQUuid();
        }

        TQUuid ActiveTQtFactory::eventsID( const TQString &key ) const
        {
            if ( key == "ActiveX1" )
                return "{01234567-89AB-CDEF-0123-456789ABCDEF}";
            ...
            return TQUuid();
        }

        TQAXFACTORY_EXPORT(
            MyFactory,                                // factory class
            "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
            "{01234567-89AB-CDEF-0123-456789ABCDEF}"  // application ID
            )

If you use the `TQ_CLASSINFO` macro to provide the unique identifiers or other attributes for your class you can use the TQAXFACTORY_BEGIN, TQAXCLASS and TQAXFACTORY_END macros to expose one or more classes as COM objects.

        TQAXFACTORY_BEGIN(
            "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID
            "{01234567-89AB-CDEF-0123-456789ABCDEF}"  // application ID
        )
            TQAXCLASS(Class1)
            TQAXCLASS(Class2)
        TQAXFACTORY_END()

Only one TQAxFactory implementation may be instantiated and exported by an ActiveX server application. This instance is accessible through the global qAxFactory() function.

A factory can also reimplement the registerClass() and unregisterClass() functions to set additional flags for an ActiveX control in the registry. To limit the number of methods or properties a widget class exposes from its parent classes reimplement exposeToSuperClass().

## Member Type Documentation

### TQAxFactory::ServerType

This enum specifies the different types of servers that can be started with startServer.

- `TQAxFactory::SingleInstance` - The server can create only one instance of each supplied class.
- `TQAxFactory::MultipleInstances` - The server can create multiple instances of each supplied class.

## Member Function Documentation

### TQAxFactory::TQAxFactory ( const TQUuid & libid, const TQUuid & appid )

Constructs a TQAxFactory object that returns libid and appid in the implementation of the respective interface functions.

### TQAxFactory::~TQAxFactory ()`[virtual]`

Destroys the TQAxFactory object.

### TQUuid TQAxFactory::appID () const`[virtual]`

Reimplement this function to return the ActiveX server's application identifier.

### TQUuid TQAxFactory::classID ( const TQString & key ) const`[virtual]`

Reimplement this function to return the class identifier for each key returned by the featureList() implementation, or an empty TQUuid if this factory doesn't support the value of key.

The default implementation interprets key as the class name, and returns the value of the TQ_CLASSINFO entry "ClassID".

### TQWidget * TQAxFactory::create ( const TQString & key, TQWidget * parent = 0, const char * name = 0 )`[virtual]`

Reimplement this function to return a new widget for key. Propagate parent and name to the TQWidget constructor. Return 0 if this factory doesn't support the value of key.

The returned widget will be exposed as an ActiveX control, e.g. a COM object that can be embedded as a control into applications.

The default implementation returns 0.

### TQObject * TQAxFactory::createObject ( const TQString & key, TQObject * parent = 0, const char * name = 0 )`[virtual]`

Reimplement this function to return a new object for key. Propagate parent and name to the TQWidget constructor. Return 0 if this factory doesn't support the value of key.

If the object returned is a TQWidget it will be exposed as an ActiveX control, otherwise the returned object will be exposed as a COM object.

The default implementation returns the result TQAxFactory::create() if parent is 0 or a widget, otherwise returns 0.

### bool TQAxFactory::createObjectWrapper ( TQObject * object, IDispatch ** wrapper )`[virtual]`

Reimplement this function to provide the COM object for object in wrapper. Return TRUE if the function was successfull, otherwise return FALSE.

The default implementation creates a generic automation wrapper based on the meta object information of object.

### TQUuid TQAxFactory::eventsID ( const TQString & key ) const`[virtual]`

Reimplement this function to return the identifier of the event interface for each key returned by the featureList() implementation, or an empty TQUuid if this factory doesn't support the value of key.

The default implementation interprets key as the class name, and returns the value of the TQ_CLASSINFO entry "EventsID".

### TQString TQAxFactory::exposeToSuperClass ( const TQString & key ) const`[virtual]`

Reimplement this function to return the name of the super class of key up to which methods and properties should be exposed by the ActiveX control.

The default implementation interprets key as the class name, and returns the value of the TQ_CLASSINFO entry "ToSuperClass". If no such value is set the null-string is returned, and the functions and properties of all the super classes including TQWidget will be exposed.

To only expose the functions and properties of the class itself, reimplement this function to return key.

### TQStringList TQAxFactory::featureList () const`[pure virtual]`

Reimplement this function to return a list of the widgets (class names) supported by this factory.

### bool TQAxFactory::hasStockEvents ( const TQString & key ) const`[virtual]`

Reimplement this function to return TRUE if the ActiveX control key should support the standard ActiveX events

- Click
- DblClick
- KeyDown
- KeyPress
- KeyUp
- MouseDown
- MouseUp
- MouseMove

The default implementation interprets key as the class name, and returns TRUE if the value of the TQ_CLASSINFO entry "StockEvents" is "yes". Otherwise this function returns FALSE.

### TQUuid TQAxFactory::interfaceID ( const TQString & key ) const`[virtual]`

Reimplement this function to return the interface identifier for each key returned by the featureList() implementation, or an empty TQUuid if this factory doesn't support the value of key.

The default implementation interprets key as the class name, and returns the value of the TQ_CLASSINFO entry "InterfaceID".

### bool TQAxFactory::isServer ()`[static]`

Returns TRUE if the application has been started (by COM) as an ActiveX server, otherwise returns FALSE.

        int main( int argc, char**argv )
        {
            TQApplication app( argc, argv );

            if ( !TQAxFactory::isServer() ) {
                // initialize for stand-alone execution
            }

            return app.exec() // standard event processing
        }

### bool TQAxFactory::isService () const`[virtual]`

Reimplement this function to return TRUE if the server is running as a persistent service (e.g. an NT service) and should not terminate even when all objects provided have been released.

The default implementation returns FALSE.

### TQMetaObject * TQAxFactory::metaObject ( const TQString & key ) const`[virtual]`

Reimplement this function to return the TQMetaObject corresponding to key, or 0 if this factory doesn't support the value of key.

The default implementation returns the TQMetaObject for the class key.

### void TQAxFactory::registerClass ( const TQString & key, TQSettings * settings ) const`[virtual]`

Registers additional values for the class key in the system registry using the settings object. The standard values have already been registed by the framework, but additional values, e.g. implemented categories, can be added in an implementation of this function.

        settings->writeEntry( "/CLSID/" + classID(key) + "/Implemented Categories/{00000000-0000-0000-000000000000}/.", TQString::null );

If you reimplement this function you must also reimplement unregisterClass() to remove the additional registry values.

See also TQSettings.

### TQString TQAxFactory::serverDirPath ()`[static]`

Returns the directory that contains the server binary.

For out-of-process servers this is the same as TQApplication::applicationDirPath(). For in-process servers that function returns the directory that contains the hosting application.

### TQString TQAxFactory::serverFilePath ()`[static]`

Returns the file path of the server binary.

For out-of-process servers this is the same as TQApplication::applicationFilePath(). For in-process servers that function returns the file path of the hosting application.

### bool TQAxFactory::startServer ( ServerType type = MultipleInstances )`[static]`

Starts the COM server with type and returns TRUE if successful, otherwise returns FALSE.

Calling this function if the server is already running (or for an in-process server) does nothing and returns TRUE.

The server is started automatically with type set to MultipleUse if the server executable has been started with the `-activex` command line parameter.

### bool TQAxFactory::stayTopLevel ( const TQString & key ) const`[virtual]`

Reimplement this function to return TRUE if the ActiveX control key should be a top level window, e.g. a dialog. The default implementation returns FALSE.

### bool TQAxFactory::stopServer ()`[static]`

Stops the COM server and returns TRUE if successful, otherwise returns FALSE.

Calling this function if the server is not running (or for an in-process server) does nothing and returns TRUE.

Stopping the server will not invalidate existing objects, but no new objects can be created from the existing server process. Usually COM will start a new server process if additional objects are requested.

The server is stopped automatically when the main() function returns.

### TQUuid TQAxFactory::typeLibID () const`[virtual]`

Reimplement this function to return the ActiveX server's type library identifier.

### void TQAxFactory::unregisterClass ( const TQString & key, TQSettings * settings ) const`[virtual]`

Unregisters any additional values for the class key from the system registry using the settings object.

        settings->removeEntry( "/CLSID/" + classID(key) + "/Implemented Categories/{00000000-0000-0000-000000000000}/." );

See also registerClass() and TQSettings.

### bool TQAxFactory::validateLicenseKey ( const TQString & key, const TQString & licenseKey ) const`[virtual]`

Reimplement this function to return TRUE if licenseKey is a valid license for the class key, or if the current machine is licensed.

The default implementation returns TRUE if the class key is not licensed (ie. no TQ_CLASSINFO attribute "LicenseKey"), or if licenseKey matches the value of the "LicenseKey" attribute, or if the machine is licensed through a .LIC file with the same filename as this COM server.

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.