
#include "x/Version.h"
#include "x/scolplugin.h"
#include "scolsys.h"
#include "tests.h"
#include "objects/win.h"


//#include "fred_def.h"

cbmachine ww;
mmachine  mm;

HCURSOR   arrowCursor;


sysexe (*SCexeSearch)(char *categ, char *name);
int (*SPstorepack)(mmachine m);


extern int SCOLloadAlphaBitmap(mmachine m);
extern int SCOLloadJPEG(mmachine m);
extern int SCOLload2D(mmachine m);
extern int SCOLloadDialog(mmachine m);
extern int SCOLloadDiv(mmachine m); 
extern int SCOLloadActiveX(mmachine m);
extern int SCOLloadOsVersion(mmachine m);


int INITwindowClass()
{
    WNDCLASS    wc;
    BOOL        rc;
	
	arrowCursor = LoadCursor( NULL, IDC_ARROW );

    wc.style = CS_HREDRAW | CS_VREDRAW |CS_OWNDC |CS_DBLCLKS;
    wc.lpfnWndProc = (LPVOID) WindowProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = sizeof( DWORD );
    wc.hInstance = (HINSTANCE)SCgetExtra("this_inst");
    wc.hIcon = LoadIcon((HINSTANCE)SCgetExtra("this_inst"),"IDI_ICON1" );
    wc.hCursor = arrowCursor;
    wc.hbrBackground = GetSysColorBrush(COLOR_MENU);//COLOR_APPWORKSPACE);//COLOR_BACKGROUND;
    wc.lpszMenuName = "GenericMenu";
    wc.lpszClassName = "GenericClass2D";
    rc = RegisterClass( &wc );
    wc.hbrBackground = NULL;
    wc.lpszClassName = "NoBackgroundClass2D";
    rc = rc && RegisterClass( &wc );

    return 0;
}

int UNINITwindowClass()
{
    DeleteObject(arrowCursor);
    UnregisterClass("GenericClass2D",(HINSTANCE)SCgetExtra("this_inst"));
    UnregisterClass("NoBackgroundClass2D",(HINSTANCE)SCgetExtra("this_inst"));
    return 0;
}




/***********************************************************************************/
/*              FONCTION DE CHARGEMENT ET DECHARGEMENT DE LA LIBRAIRIE             */
/***********************************************************************************/
__declspec (dllexport) int SCOLloadLIB2D(mmachine m,cbmachine w)
{
    int k;
	ww=w;
	mm=m;


    tstscoldead = (int (__cdecl *)(int))SCgetExtra("tstscoldead");    
    SCexeSearch = (sysexe  (__cdecl *)(char *, char *))SCgetExtra("scexesearch");       
    WindowProc  = (WNDPROC) SCgetExtra("windowproc");
    SPstorepack = (int (__cdecl *)(mmachine))SCgetExtra("SPstorepack");
    
    INITwindowClass();

    if (k=SCOLload2D(m)) return k;
    if (k=SCOLloadAlphaBitmap(m)) return k;
    if (k=SCOLloadJPEG(m)) return k;
    if (k=SCOLloadDialog(m)) return k;
    if (k=SCOLloadDiv(m)) return k;
    if (k=SCOLloadActiveX(m)) return k;
    if (k=SCOLloadOsVersion(m)) return k;
    return k;
}

__declspec (dllexport) int SCOLfreeLIB2D()
{
	UNINITwindowClass();
    return 0;
}