/*************************************************************************
 *
 *  $RCSfile: docfac.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: mba $ $Date: 2001/12/03 17:26:21 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _SFX_OBJFAC_HXX
#define _SFX_OBJFAC_HXX

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif

#ifndef _RTTI_HXX //autogen
#include <tools/rtti.hxx>
#endif
#ifndef _FACTORY_HXX //autogen
#include <so3/factory.hxx>
#endif

// SFX_IMPL_MODULE_LIB
#ifndef _VOS_MODULE_HXX_
#include <vos/module.hxx>
#endif
#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif

#include <sfx2/objsh.hxx>
#include <sfx2/sfxdefs.hxx>

class SfxObjectFactoryArr_Impl;
class SvFactory;
class SfxMedium;
class SfxFilter;
class SfxViewFactory;
struct SfxObjectFactory_Impl;
class SfxFilterContainer;
class SfxFactoryFilterContainer;
class SfxMenuBarManager;
class SfxBindings;
class SfxAcceleratorManager;

typedef SfxObjectShell *(*SfxObjectCtor)(SfxObjectCreateMode);

//====================================================================

typedef void (*SfxVoidFunc)();

#define SDT_SDT_DOCFACTPRIO     10      // Explorer
#define SDT_SW_DOCFACTPRIO      20      // Text-Dokument
#define SDT_SWW_DOCFACTPRIO     21    	// Web-Dokument
#define SDT_SC_DOCFACTPRIO      30      // Tabellen-Dokument
#define SDT_SI_DOCFACTPRIO      40      // Impress-Dokument
#define SDT_SD_DOCFACTPRIO      41      // Draw-Dokument
#define SDT_SCH_DOCFACTPRIO     50      // Chart-Dokument
#define SDT_SMA_DOCFACTPRIO     60      // Math-Dokument
#define SDT_SIM_DOCFACTPRIO     70      // Image-Dokument
#define SDT_FRM_DOCFACTPRIO    100      // Rahmen-Dokument
#define SDT_MSG_DOCFACTPRIO    110      // Nachrichten-Dokument
#define SDT_SDB_DOCFACTPRIO    200      // Datenbank-Dokument

//====================================================================

class SfxObjectFactory: public SvFactory
{
private:
	USHORT					nId;			// Factory-Id
	SfxObjectCtor			fnCreate;		// static Methode, die Ctor ruft
	const char* 			pShortName;		// Objekt-Kurzname
	SfxObjectFactory_Impl*	pImpl;			// Zusatzdaten
	SfxObjectShellFlags     nFlags;

public:
					TYPEINFO();

	SfxObjectFactory( const SvGlobalName &rName, const String &rClassName, CreateInstanceType funcCIT );
	~SfxObjectFactory();

	void			Construct( USHORT nId, SfxObjectCtor fnCreateFnc,
							   SfxObjectShellFlags, const char *pShortName = 0 );
	SfxObjectShell* CreateObject(SfxObjectCreateMode = SFX_CREATE_MODE_STANDARD) const;

	SfxObjectShellFlags GetFlags() { return nFlags; }
	USHORT			GetOrdinal() const { return nId; }
	const char* 	GetShortName() const { return pShortName; }
    String          GetModuleName() const;
	void			RegisterMenuBar( const ResId &rId );
	void			RegisterPluginMenuBar( const ResId &rId );
	void			RegisterAccel( const ResId &rId );
	void			SetDocumentTypeNameResource( const ResId& rId );
	String			GetDocumentTypeName() const;
	const ResId*	GetMenuBarId() const;
	const ResId*	GetPluginMenuBarId() const;
	const ResId*	GetAccelId() const;
	void			RegisterHelpFile( const String& );
	const String&	GetHelpFile() const;
	void			SetExplorerImageId( USHORT nImageId );
	USHORT			GetExplorerImageId() const;

	void			RegisterHelpPIFile( const String& );
	const String&	GetHelpPIFile() const;
	SfxFactoryFilterContainer *GetFilterContainer( BOOL bForceLoad = TRUE) const;

	void			SetCreateNewSlotId( USHORT nId );
	USHORT			GetCreateNewSlotId() const;
	// Views
	void			RegisterViewFactory(SfxViewFactory &rFactory);
	USHORT			GetViewFactoryCount() const;
	SfxViewFactory& GetViewFactory(USHORT i = 0) const;

	// Filter
	void            RegisterInitFactory( SfxVoidFunc pFunc );
	void     		DoInitFactory();
	void        	RegisterFilter( const String &rName,
									const String &rWildcard,
									SfxFilterFlags nFlags,
									ULONG lFormat,
									const String &rMacType,
									const String &rTypeName,
									USHORT nIconId,
									const String &rMimeType,
									const String &rUserData);
	USHORT      	 GetFilterCount() const;
	const SfxFilter* GetFilter(USHORT i) const;
	const SfxFilter* GetTemplateFilter() const;

	static const SfxObjectFactory*	GetFactory( const String& rFactoryURL );
	const String&				GetStandardTemplate() const;
	static void					SetStandardTemplate( const String& rFactoryURL, const String& rTemplateName );

	void					SetDocumentServiceName( const rtl::OUString& rServiceName );
	const rtl::OUString&	GetDocumentServiceName() const;

	DECL_LINK( InitFactoryHdl, void* );

	SfxModule*                  GetModule() const;

    static const SfxObjectFactory&     GetDefaultFactory();
    static BOOL                        HasObjectFactories();

#if 0 // _SOLAR__PRIVATE
    static void                        RemoveAll_Impl();
    static SfxObjectFactoryArr_Impl&   GetObjFacArray_Impl();
    static void                        RegisterObjectFactory_Impl(SfxObjectFactory &rObjFac);
    static USHORT                      GetObjectFactoryCount_Impl();
    static const SfxObjectFactory&     GetObjectFactory_Impl(USHORT i);
    SfxMenuBarManager*                 GetMenuBar_Impl();
    SfxAcceleratorManager*             GetAccMgr_Impl();
    void                               SetModule_Impl( SfxModule* );
#endif

private:
	// Kopieren verboten
	SfxObjectFactory(const SfxObjectFactory&);
	const SfxObjectFactory& operator=(const SfxObjectFactory &);
};

//=========================================================================

/*	SFX_DECL_OBJECTFACTORY

	[Description]

	This macro declares an SfxObjectFactory for subclasses of SfxObjectShell
    which are derived too from SfxInPlaceObject and are linked to an executable
    or linked to a permanently loaded library.
	The macro must be used in the public-area of the declaration of the
	SfxObjectShell subclass.
*/

#define SFX_DECL_OBJECTFACTORY(Class)                                       \
private:																	\
	static SfxObjectFactory*	pObjectFactory;								\
protected:																	\
    virtual BOOL                Close();                   					\
public:                                                                     \
    							SO2_DECL_BASIC_CLASS(Class)                 \
	virtual BOOL				DoClose();									\
	static SfxObjectShell*		CreateObject(SfxObjectCreateMode eMode = SFX_CREATE_MODE_STANDARD); \
    static void                 InitFactory();                              \
    static SfxObjectFactory&  	Factory() { return *(SfxObjectFactory*)ClassFactory(); } \
    static void                 RegisterFactory( USHORT nPrio = USHRT_MAX );\
    virtual BOOL                DoInitNew( SvStorage * );                   \
    virtual void                ModifyChanged();                            \
    virtual SfxObjectFactory&   GetFactory() const

//-------------------------------------------------------------------------

/*	SFX_DECL_OBJECTFACTORY_DLL

	[Description]

	This macro declares an SfxObjectFactory for subclasses of SfxObjectShell
    which are derived too from SfxInPlaceObject and are linked to a DLL that
    is loaded on demand.
	The macro must be used in the public-area of the declaration of the
	SfxObjectShell subclass.
*/

#define SFX_DECL_OBJECTFACTORY_DLL(Class,FactoryPtr)						\
private:                                                                    \
    static SfxObjectFactory*	pObjectFactory;                             \
protected:																	\
    virtual BOOL                Close();                   					\
public:                                                                     \
								SO2_DECL_BASIC_CLASS_DLL(Class,FactoryPtr)  \
	virtual BOOL  				DoClose();									\
	static SfxObjectShell*		CreateObject(SfxObjectCreateMode eMode = SFX_CREATE_MODE_STANDARD); \
    static void                 InitFactory();                              \
    static SfxObjectFactory&  	Factory() { return *(SfxObjectFactory*)ClassFactory(); } \
    static void                 RegisterFactory( USHORT nPrio = USHRT_MAX );\
    virtual BOOL                DoInitNew( SvStorage * );                   \
    virtual void                ModifyChanged();                            \
    virtual SfxObjectFactory&   GetFactory() const

//--------------------------------------------------------------------

/*	SFX_DECL_SIMPLE_OBJECTFACTORY

	[Description]

	This macro declares an SfxObjectFactory for subclasses of SfxObjectShell
    which are NOT derived from SfxInPlaceObject but are linked to an executable
    or to permanently loaded dll.
	The macro must be used in the public-area of the declaration of the
	SfxObjectShell subclass.
*/

#define SFX_DECL_SIMPLE_OBJECTFACTORY(Class)                                \
private:																	\
	static SfxObjectFactory*	pObjectFactory;								\
public:                                                                     \
    static SfxObjectShell*      CreateObject(SfxObjectCreateMode eMode = SFX_CREATE_MODE_STANDARD); \
    static void                 InitFactory();                              \
    static SfxObjectFactory&    Factory();                                  \
    static void                 RegisterFactory( USHORT nPrio = USHRT_MAX );\
    virtual SfxObjectFactory&   GetFactory() const

//-------------------------------------------------------------------------

/*	SFX_DECL_SIMPLE_OBJECTFACTORY_DLL

	[Description]

	This macro declares an SfxObjectFactory for subclasses of SfxObjectShell
    which are NOT derived from SfxInPlaceObject and are linked to a DLL that
    is loaded on demand.
	The macro must be used in the public-area of the declaration of the
	SfxObjectShell subclass.
*/

#define SFX_DECL_SIMPLE_OBJECTFACTORY_DLL(Class ) 					\
private:															\
	static SfxObjectFactory*	pObjectFactory;								\
    static SfxObjectFactory **  GetFactoryAdress();					\
public:																\
    static SfxObjectShell*      CreateObject( SfxObjectCreateMode eMode = SFX_CREATE_MODE_STANDARD);  \
    static void                 InitFactory();			 			\
    static SfxObjectFactory&    Factory();                          \
    static void                 RegisterFactory( USHORT nPrio = USHRT_MAX ); \
    virtual SfxObjectFactory&   GetFactory() const

//=========================================================================

/*	SFX_IMPL_OBJECTFACTORY

	[Description]

	This macro implements a SfxObjectFactory for subclasses of SfxObjectShell
	which are derived too from SfxInPlaceObject an are linked to an executable.

	It must be used plain in a C++ source file, perffered where ctor an dtor
	of the SfxObjectShell subclass are implemented.
*/

#define SFX_IMPL_OBJECTFACTORY( Class, nFlags, ShortName, aGlobName ) \
																			\
		SfxObjectFactory* Class::pObjectFactory = 0;						\
																			\
        SO2_IMPL_BASIC_CLASS1( Class, SfxObjectFactory, SfxInPlaceObject, aGlobName ) \
																			\
		SfxObjectShell* __EXPORT Class::CreateObject(SfxObjectCreateMode eMode) \
        { return new Class(eMode); }                						\
																			\
        void Class::RegisterFactory( USHORT nPrio )                         \
        {                                                                   \
            pObjectFactory = &Factory();                                     \
			pObjectFactory->Construct(   									 \
				nPrio,														\
				&Class::CreateObject, \
				nFlags,											 \
                #ShortName );                                               \
			pObjectFactory->RegisterInitFactory( &InitFactory	);           \
            pObjectFactory->Register(); /* Ole Anmeldung */                 \
        }                                                                   \
																			\
		BOOL __EXPORT Class::DoInitNew( SvStorage *pStor )					\
        { return SfxObjectShell::DoInitNew(pStor); }                        \
																			\
		BOOL __EXPORT Class::DoClose()										\
		{ return SfxInPlaceObject::DoClose(); }								\
																			\
		BOOL __EXPORT Class::Close()										\
        {   SvObjectRef aRef(this);											\
			SfxInPlaceObject::Close();                             			\
			return SfxObjectShell::Close(); }								\
																			\
		void __EXPORT Class::ModifyChanged()								\
        { SfxObjectShell::ModifyChanged(); }                                \
																			\
		SfxObjectFactory& __EXPORT Class::GetFactory() const				\
        {   return *(SfxObjectFactory*)ClassFactory(); }                     \
                                                                            \
        void __EXPORT Class::InitFactory()

//---------------------------------------------------------------------------
/*	SFX_IMPL_MODULE_LIB

	[Beschreibung]

	Dieses Makro implementiert exportierte Funktionen als Schnittstelle,
	die zum Laden und Initialisieren sowie zum Freigeben und Deinitialisieren
	einer DLL dienen sowie Funktionsaddressen in dieser DLL ermitteln
	k"onnen.

	Parameter:
		LibName		- "logischer" Name der DLL ( z.B. "SIM" )
		LibString	- Dateiname der DLL

	Damit auch mehrere solcherma\sen definierte Schnittstellen importiert
	werden k"onnen, wird der "LibName" mit in die Namen der definierten
	Funktionen einbezogen.
*/

extern "C"
{
	typedef void  (__LOADONCALLAPI *So2VoidFunc_TYPE) ();
}

#define SFX_IMPL_MODULE_LIB( LibName, LibString )					\
	void * GetFunc##LibName( const char * pFuncName );				\
	static ::vos::OModule* pLibHandle##LibName = NULL; 				\
	BOOL __EXPORT LoadLib##LibName()   								\
	{																\
		if( pLibHandle##LibName == NULL )							\
		{															\
			pLibHandle##LibName = new ::vos::OModule();				\
			So2VoidFunc_TYPE fFunc;									\
			if (!pLibHandle##LibName->load( LibString )) 			\
				return FALSE;										\
			fFunc = (So2VoidFunc_TYPE)GetFunc##LibName( "Init" #LibName "Dll");\
			if( fFunc )												\
				(*fFunc)();											\
		}															\
		return pLibHandle##LibName->isLoaded();						\
	}																\
	void __EXPORT FreeLib##LibName()								\
	{																\
		if( pLibHandle##LibName && pLibHandle##LibName->isLoaded() )\
		{															\
			So2VoidFunc_TYPE fFunc;									\
			fFunc = (So2VoidFunc_TYPE)GetFunc##LibName("DeInit" #LibName "Dll");\
			if( fFunc )												\
				(*fFunc)();											\
		}															\
	}																\
	void* __EXPORT GetFunc##LibName( const char * pFuncName )		\
	{																\
		if( LoadLib##LibName() )									\
            return pLibHandle##LibName->getSymbol( ::rtl::OUString::createFromAscii(pFuncName) );\
		return NULL;												\
	}

//---------------------------------------------------------------------------
/*	SFX_IMPL_MODULE_DLL

	[Beschreibung]

	Dieses Makro implementiert C-Funktionen zum Initialisieren und Deinitialisieren
	einer DLL, die wiederum statische Methoden der DLL-Klasse aufrufen.

	Parameter:
		LibName		- "logischer" Name der DLL ( z.B. "SIM" )
*/

#define SFX_IMPL_MODULE_DLL( LibName )	  									\
																			\
		extern "C" void __LOADONCALLAPI Init##LibName##Dll()                \
		{																	\
			LibName##DLL::Init();											\
		}																	\
		extern "C" void __LOADONCALLAPI DeInit##LibName##Dll()              \
		{																	\
			LibName##DLL::Exit();											\
		}

//---------------------------------------------------------------------------
 /*	SFX_IMPL_OBJECTFACTORY_DLL

	[Beschreibung]

	Die folgenden Makros implementieren eine Factory f"ur SfxObjectShell-Subklassen,
	die auch von SfxInPlaceObject abgeleitet sind und die in einer DLL definiert sind.
	Damit die DLL auch Load-On-Demand geladen werden kann, wird eine einfach
	exportierbare C-Funktion definiert, die die eigentliche Factory-Methode
	aufruft.
	Diese Funktion kann dann in eine andere, exportierte Factory-Methode
	eingebettet werden, so da\s sowohl in der DLL als auch im exportierten Interface
	jeweils eine Factory-Methode definiert sind.
	Erstere erzeugt direkt das Objekt, letztere ruft erstere "uber die
	erw"ahnte exportierte C-Funktion auf. Die Funktionsadresse wird "uber die
	Funktionen des Macros SFX_IMPL_MODULE_LIB besorgt, so da\s jedes Modul, das
	nachladbar sein soll, in seinem Interface dieses Macro einbauem mu\s.
	Dann kann es beliebig viele Interfaces zu SvObjekten mit dem Macro

				SFX_IMPL_OBJECTFACTORY_MOD

	implementieren. Der mit diesem Makro generierte Code wird zum Executable bzw.
	einer per Implib geladenen DLL gelinkt ( daher auch __EXPORT !! ).
	Die Objekte selbst werden mit dem Macro

				SFX_IMPL_OBJECTFACTORY_DLL

	in der nachzuladenden DLL implementiert.
	Das Macro

				SFX_IMPL_OBJECTFACTORY_GEN

	definiert einige Methoden, die in beiden Macros ben"otigt werden.
*/

// Typedefs f"ur die exportierten Funktionen
extern "C"
{
	typedef void* (__LOADONCALLAPI *So2CreateExtern_TYPE) ();
	typedef void* (__LOADONCALLAPI *SfxCreateExtern_TYPE) (int);
}

// Gemeinsame Funktionen in DLL und LIB
#define SFX_IMPL_OBJECTFACTORY_GEN( Class, LibType )						\
																			\
		SfxObjectShell* __EXPORT Class::CreateObject(SfxObjectCreateMode eMode) \
		{																	\
			SfxObjectShell* pDoc = CreateObj##Class##LibType((int)eMode); \
			return pDoc;													\
		}																	\
		SfxObjectFactory& __EXPORT Class::GetFactory() const				\
		{ 																	\
            return Factory();                                               \
		}

// Funktionen und Methoden in der LIB
#define SFX_IMPL_OBJECTFACTORY_MOD( ClassName, nFlags, ShortName, aGlobName, LibName, LibString ) \
        SfxObjectFactory* ClassName::pObjectFactory = 0;                        \
		extern "C" ClassName * __LOADONCALLAPI Create##ClassName##Lib()			  \
		{																		  \
			So2CreateExtern_TYPE fCreate = (So2CreateExtern_TYPE)                 \
				GetFunc##LibName( "Create" #ClassName "Dll");					  \
			if( fCreate )														  \
				return (ClassName *)(*fCreate)();								  \
			return NULL;														  \
		}																		  \
		SotFactory* __EXPORT ClassName::ClassFactory()                                     \
		{                                                                         \
            if( !pObjectFactory )                                                     \
    		{                                                                     \
                pObjectFactory = new SfxObjectFactory( aGlobName,                \
                    String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(#ClassName) ), ClassName::CreateInstance );  \
                pObjectFactory->PutSuperClass( SfxInPlaceObject::ClassFactory() );  \
    		}                                                                     \
            return pObjectFactory;                                                    \
		}                                                                         \
		void* __EXPORT ClassName::CreateInstance( SotObject ** ppObj )            \
		{                                                                         \
    		ClassName * p = Create##ClassName##Lib();                         	  \
    		SfxInPlaceObject* pSuper1 = p;                 						  \
    		SotObject* pBasicObj = pSuper1;                    					  \
    		if( ppObj )                                                           \
        		*ppObj = pBasicObj;                                               \
    		return p;                                                             \
		}																		  \
		void __EXPORT ClassName::RegisterFactory( USHORT nPrio )			\
		{																	\
			Factory().Construct(											\
				nPrio,														\
				&ClassName::CreateObject, nFlags | SFXOBJECTSHELL_HASMENU,  \
				#ShortName );												\
            Factory().RegisterInitFactory( &InitFactory );                  \
            Factory().Register();                                           \
		}																	\
		ClassName* __EXPORT CreateObj##ClassName##Lib(int nMode)				\
		{																	\
			SfxCreateExtern_TYPE fCreate = (SfxCreateExtern_TYPE)			\
				GetFunc##LibName( "CreateObj" #ClassName "Dll");            \
			if( fCreate )													\
				return (ClassName*)(*fCreate)(nMode);						\
			return NULL;													\
		}																	\
																			\
		SFX_IMPL_OBJECTFACTORY_GEN( ClassName, Lib )						\
																			\
		void __EXPORT ClassName::InitFactory()

// Funktionen und Methoden in der DLL
#define SFX_IMPL_OBJECTFACTORY_LOD( Class, ShortName, aGlobName, LibName ) \
		SO2_IMPL_BASIC_CLASS1_DLL( Class, SfxObjectFactory, SfxInPlaceObject, aGlobName ) \
		extern "C" Class* __LOADONCALLAPI Create##Class##Dll()     			\
		{																	\
			return new Class();												\
		}																	\
		extern "C" Class* __LOADONCALLAPI CreateObj##Class##Dll(int nMode)  \
		{																	\
			SfxObjectCreateMode eMode = (SfxObjectCreateMode) nMode;		\
			return new Class(eMode);										\
		}																	\
																			\
		BOOL Class::DoInitNew( SvStorage *pStor )							\
		{ return SfxObjectShell::DoInitNew(pStor); }						\
																			\
		BOOL Class::DoClose()												\
		{ return SfxInPlaceObject::DoClose(); }								\
																			\
		BOOL Class::Close()													\
        {   SvObjectRef aRef(this);											\
			SfxInPlaceObject::Close();                             			\
			return SfxObjectShell::Close(); }								\
																			\
		void Class::ModifyChanged()											\
		{ SfxObjectShell::ModifyChanged(); }								\
																			\
		SFX_IMPL_OBJECTFACTORY_GEN( Class, Dll )

// Wenn nur eine Factory pro Module vorhanden ist
#define SFX_IMPL_OBJECTFACTORY_LIB( Class, nFlags, ShortName, aGlobName, LibName,LibString ) \
		SFX_IMPL_MODULE_LIB( LibName, LibString )																									\
		SFX_IMPL_OBJECTFACTORY_MOD( Class, nFlags, ShortName, aGlobName, LibName,LibString )

#define SFX_IMPL_OBJECTFACTORY_DLL( Class, ShortName, aGlobName, LibName ) \
		SFX_IMPL_MODULE_DLL( LibName )											\
		SFX_IMPL_OBJECTFACTORY_LOD( Class, ShortName, aGlobName, LibName )

//---------------------------------------------------------------------------

/*	SFX_IMPL_SIMPLE_OBJECTFACTORY

	[Beschreibung]

	Dieses Makro implementiert eine SfxObjectFactory f"ur SfxObjectShell-
	Subklassen, die NICHT von SfxInPlaceObject abgeleitet sind und deren Code
    zum Executable oder zu einer permanent angezogenen DLL gelinkt wird.
*/

#define SFX_IMPL_SIMPLE_OBJECTFACTORY( Class, nFlags, ShortName )		\
																			\
		SfxObjectFactory* Class::pObjectFactory = 0;						\
																			\
		SfxObjectShell* __EXPORT Class::CreateObject(SfxObjectCreateMode eMode) \
        { return new Class(eMode); }                						\
																			\
        SfxObjectFactory& __EXPORT Class::Factory()                                     \
		{                                                                         \
            if( !pObjectFactory )                                                     \
    		{                                                                     \
                pObjectFactory = new SfxObjectFactory( SvGlobalName(),                \
                                        String(), 0 );  \
    		}                                                                     \
            return *pObjectFactory;                                                    \
		}                                                                         \
        void Class::RegisterFactory( USHORT nPrio )                         \
        {                                                                   \
            Factory().Construct(                                      \
				nPrio,														\
				&Class::CreateObject, nFlags,								\
                #ShortName );                                               \
            Factory().RegisterInitFactory( &InitFactory   );          \
        }                                                                   \
																			\
		SfxObjectFactory& __EXPORT Class::GetFactory() const				\
        {   return Factory(); }                                             \
																			\
		void __EXPORT Class::InitFactory()

//--------------------------------------------------------------------

/*	SFX_IMPL_SIMPLE_OBJECTFACTORY_LOD

	[Beschreibung]

	Dieses Makro implementiert eine SfxObjectFactory f"ur SfxObjectShell-
	Subklassen, die NICHT von SfxInPlaceObject abgeleitet sind und deren Code
	On-Demand geladen wird. Der mit diesem Makro generierte Code wird zur
	On-Demand zu ladenden DLL gelinkt.

	Es wird eine Klasse 'LibName##DLL' vorausgesetzt, die eine statische
	Init()- und Exit()-Methode implementiert. Diese werden gerufen wenn
	die DLL angezogen bzw. freigelassen wird.
*/

#define SFX_IMPL_SIMPLE_OBJECTFACTORY_LOD( Class, LibName, FactoryPtr )		\
    SfxObjectFactory** Class::GetFactoryAdress()                            \
    { return &FactoryPtr->p##Class##Factory; }                              \
	extern "C" Class* __LOADONCALLAPI CreateObj##Class##Dll(int nMode)      \
	{																		\
		SfxObjectCreateMode eMode = (SfxObjectCreateMode) nMode;			\
		return new Class(eMode);											\
	}																		\
	SfxObjectShell*	 Class::CreateObject(SfxObjectCreateMode eMode)			\
	{																		\
		return new Class( eMode );											\
	}																		\
    SfxObjectFactory&  Class::Factory()                                     \
        { return **GetFactoryAdress(); }                                     \
	SfxObjectFactory&  Class::GetFactory() const							\
        { return Factory(); }

//-------------------------------------------------------------------------

/*	SFX_IMPL_SIMPLE_OBJECTFACTORY_LIB

	[Beschreibung]

	Dieses Makro implementiert einen Stub f"ur eine SfxObjectFactory f"ur
	SfxObjectShell-Subklassen, die NICHT von SfxInPlaceObject abgeleitet sind
	und deren Code On-Demand geladen wird. Der mit diesem Makro generierte Code
	wird zum Executeable bzw. einer per Implib geladenen DLL gelinkt.
*/

#define SFX_IMPL_SIMPLE_OBJECTFACTORY_LIB( Class, nFlags, ShortName, LibName, FactoryPtr ) \
    SfxObjectFactory* Class::pObjectFactory = 0;                        \
    SfxObjectFactory& __EXPORT Class::Factory()                                     \
    {                                                                         \
        if( !pObjectFactory )                                                     \
        {                                                                     \
            pObjectFactory = new SfxObjectFactory( SvGlobalName(),                \
                                    String(), 0 );  \
        }                                                                     \
        return *pObjectFactory;                                                    \
    }                                                                         \
	void __EXPORT Class::RegisterFactory( USHORT nPrio )					  \
	{																		  \
            Factory().Construct(                                        \
				nPrio,														  \
				&Class::CreateObject, nFlags,								  \
				#ShortName );												  \
            Factory().RegisterInitFactory( &InitFactory    );                    \
	}																		  \
																			  \
	SfxObjectShell*	__EXPORT Class::CreateObject(SfxObjectCreateMode eMode)	  \
	{																		  \
		SfxCreateExtern_TYPE fCreate = (SfxCreateExtern_TYPE)			\
			GetFunc##LibName( "CreateObj" #Class "Dll");            \
		if( fCreate )														  \
			return (Class*)(*fCreate)(eMode);								  \
		return 0;															  \
	}																		  \
																			  \
	SfxObjectFactory& __EXPORT Class::GetFactory() const 					  \
        { return Factory(); }                                                \
																			  \
	void __EXPORT Class::InitFactory()

//--------------------------------------------------------------------

#define SFX_FILTER_REGISTRATION(aName, aWild, ePurpose, lClipboardFormat, \
    pMacType, pOS2Type, nOS2DocIcon, pUserData) \
    ((SfxObjectFactory&)Factory()).RegisterFilter( \
		aName, aWild, ePurpose, lClipboardFormat, pMacType, pOS2Type, nOS2DocIcon, String(), pUserData )

// Den eigenen Filter Registrieren und DetectFilter setzen.
#define SFX_OWN_FILTER_REGISTRATION(									\
	pDetectFilter, aName, aWild,										\
	ePurpose, lClipboardFormat,											\
	pMacType, pOS2Type, nOS2DocIcon, aMimeType, pUserData)				\
	{																	\
		SfxObjectFactory& rFact = (SfxObjectFactory&)Factory();			\
        rFact.RegisterFilter(											\
                aName, aWild, ePurpose, lClipboardFormat, pMacType,		\
		        pOS2Type, nOS2DocIcon, aMimeType, pUserData );			\
		rFact.GetFilterContainer()->SetDetectFilter( pDetectFilter );	\
 	}

// Einen Filter registrieren. Fuer nicht-Ini Factories ( z.B. Plugins )
#define SFX_SIMPLE_FILTER_REGISTRATION(								\
	aName, aWild,													\
	ePurpose, lClipboardFormat,										\
	pMacType, pOS2Type, nOS2DocIcon, aMimeType, pUserData)			\
    {																\
		SfxObjectFactory& rFact = (SfxObjectFactory&)Factory();		\
         rFact.RegisterFilter(										\
                aName, aWild, ePurpose, lClipboardFormat, pMacType,	\
		        pOS2Type, nOS2DocIcon, aMimeType, pUserData );		\
	}

// Fuer jede Applikation eine
#define SFX_APP_FILTER_REGISTRATION( aName )								\
    {																		\
		if( !SFX_APP()->GetFilterMatcher().GetContainer( aName ) )			\
		{																	\
			SfxFilterContainer* pCont = new SfxFilterContainer( aName );	\
			SFX_APP()->GetFilterMatcher().AddContainer(	pCont );			\
			pCont->LoadFilters(												\
				aName, 	TRUE, 												\
                SFX_FILTER_MAPTOAPPPLUG|SFX_FILTER_PLUGIN  );				\
		}															   		\
	}

//====================================================================
// Kompatibilit"ats-Defines

#ifdef _SFX_HXX
#define SFX_DECL_DOCUMENTFACTORY(Class) \
		SFX_DECL_OBJECTFACTORY(Class)

#define SFX_DECL_DOCUMENTFACTORY_DLL(Class,ClassFactory) \
		SFX_DECL_OBJECTFACTORY_DLL(Class,ClassFactory)

#define SFX_DECL_SIMPLE_DOCUMENTFACTORY_DLL(Class) \
		SFX_DECL_SIMPLE_OBJECTFACTORY_DLL(Class)
#endif

#endif // #ifndef _SFX_OBJFAC_HXX

