/*<<<***************************************************************************
The MIT License (MIT)

Copyright(C) 2013 - 2015 Marc Mirti Mancinelli, Christophe Lardau and Philippe Pamart (xdcube.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

!! IMPORTANT !!
This plugin/software uses and integrates the following sources which are 
obviously not covered/excluded from this license: 
- Independent JPEG Group's software library 6b used for jpeg support 
	(folder jpeg-6b, see README.txt for license)
- Glenn Randers- Pehrson's libpng-1.2.8
	(folder libpng-128, see LICENSE.txt)
- Jean-loup Gailly/Mark Adler's zlib-1.2.3 for png support and gzip compression
	(folder zlib-123, see README.txt for license)

For this source, please refer to their own license.
////////////////////////////////////////////////////////////////////////////////
#Title: xdcPicStd
#Project: xdcPicStd
////////////////////////////////////////////////////////////////////////////////
#Author: Marc MIRTI MANCINELLI
#History:
<14/09/2013: creation.
12/02/2014: this notice inserted.
***************************************************************************>>>*/
// xdcPicStd.cpp : Implementation of CxdcPicStdApp and DLL registration.

#include "stdafx.h"
#include "xdcPicStd.h"
#include "xdcPicJpegPlug.h"
#include "xdcPicPngPlug.h"
#include "xdcPicGifPlug.h"
#include "xdcPicBmpPlug.h"

#include "xdcCompGzip.h"

#ifndef XDCBASE_EMBED
#include "xbLibTools.h"

int __cdecl _purecall()
{
	xbThrow xbEseh(E_ABORT,"xdcPicStd: Object of called method is in destruction (purecall)");
	return 0;
}

xbXdcLib g_xdcPicStdDLL("xdcPicStd","1");

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  dwReason,
                       LPVOID lpReserved
					 )
{
	eProtectBegin();
	g_xdcPicStdDLL.dllMainCall(hModule,dwReason);
	if (dwReason == DLL_PROCESS_DETACH)
	{
		g_PicStdFact.ForceUnload();
		g_CompStdFact.ForceUnload();
	}
	return TRUE;   // ok
	eProtectEndTrace();
	return FALSE;   // failure
}
#endif

xbHotPlugFactoryList g_PicFactList[] =
{
	{"default",jpegPlug::CreateObject,50,NULL},
	{"jpg.jpeg",jpegPlug::CreateObject,3,NULL},
	{"png",pngPlug::CreateObject,4,NULL},
	{"gif",gifPlug::CreateObject,5,NULL},
	{"bmp",bmpPlug::CreateObject,10,NULL},
	{NULL,NULL,0,NULL}
};

xbHotPlugFactoryList g_CompFactList[] =
{
	{"gzip",eproGZIPplug::CreateObject,10,NULL},
	{NULL,NULL,0,NULL}
};

PicStdFact	g_PicStdFact(
#ifndef XDCBASE_EMBED
			&g_xdcPicStdDLL,
#endif
			 &g_gdiCompressPlugType,"xdcPicStd",
			"Standard picture plugin for xdcGdi",g_PicFactList);

CompStdFact	g_CompStdFact(
#ifndef XDCBASE_EMBED
			&g_xdcPicStdDLL,
#endif
			&g_xbCompressPlugType,"xdcPicStd",
			"Standard compression plugin for xdcBase",g_CompFactList);

/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registry
#ifndef XDCBASE_EMBED

STDAPI DllRegisterServer(void)
{
	eToHRtrace(g_PicStdFact.Register());
	eToHRtrace(g_CompStdFact.Register());

	return NOERROR;
}


/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registry

STDAPI DllUnregisterServer(void)
{
	eToHRtrace(g_PicStdFact.Unregister());
	eToHRtrace(g_CompStdFact.Unregister());

	return NOERROR;
}

extern "C" void xdcPicturePluginCreateObject(IxbHotPlugin *pPluginContainer,const xbString &name,xbRefPtr<IxbObject> *ppObj,void *pCtorData)
{
	g_PicStdFact.CreateObject(pPluginContainer,name,ppObj,pCtorData);
}

extern "C" bool xdcPicturePluginUnload(IxbHotPlugin *pPluginContainer,bool bForce)
{
	return g_PicStdFact.Unload(pPluginContainer,bForce);
}

extern "C" void xdcPicturePluginLoad(IxbHotPlugin *pPluginContainer)
{
	g_PicStdFact.Load(pPluginContainer);
}

extern "C" void xdcCompressPluginCreateObject(IxbHotPlugin *pPluginContainer,const xbString &name,xbRefPtr<IxbObject> *ppObj,void *pCtorData)
{
	g_CompStdFact.CreateObject(pPluginContainer,name,ppObj,pCtorData);
}

extern "C" bool xdcCompressPluginUnload(IxbHotPlugin *pPluginContainer,bool bForce)
{
	return g_CompStdFact.Unload(pPluginContainer,bForce);
}

extern "C" void xdcCompressPluginLoad(IxbHotPlugin *pPluginContainer)
{
	g_CompStdFact.Load(pPluginContainer);
}


#endif
