/*************************************************************************
 *
 *  $RCSfile: msocximp.hxx,v $
 *
 *  $Revision: 1.1.1.1 $
 *
 *  last change: $Author: hr $ $Date: 2000/09/18 17:14:58 $
 *
 *  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 _MSOCXIMP_HXX
#define _MSOCXIMP_HXX

#ifndef _SVSTOR_HXX
#include <so3/svstor.hxx>
#endif

#ifndef C2U
#define C2U(cChar)	rtl::OUString::createFromAscii(cChar)
#endif

namespace com{namespace sun{namespace star{
        namespace drawing{
                class XDrawPage;
                class XShape;
                class XShapes;
        }
        /*
        namespace awt{
                struct Size;
        }
        */
        namespace form{
                class XFormComponent;
        }
        namespace lang{
                class XMultiServiceFactory;
        }
        namespace container{
                class XIndexContainer;
        }
        namespace beans{
                class XPropertySet;
        }
        namespace text{
                class XText;
        }
        namespace awt{
                struct Size;
        }

}}}


class OCX_Control;
class SfxObjectShell;
class SwPaM;


class SwImportOCX
{
public:
	SwImportOCX( SfxObjectShell *pDSh,SwPaM *pP ) :
		pDocSh( pDSh ), pPaM(pP),nEdit( 0 ), nCheckbox( 0 )
	{ ASSERT( pDocSh, "No DocShell, Cannot do Controls" ); }

	sal_Bool ReadOCXStream( SvStorageRef& rSrc1, ::com::sun::star::uno::Reference< com::sun::star::drawing::XShape > *pShapeRef=0,
							BOOL bFloatingCtrl=FALSE );
	OCX_Control *OCX_Factory(const String &sName);
	::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >  InsertControl(
		const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > & rFComp,
		const ::com::sun::star::awt::Size& rSize,
		//const com::sun::star::awt::Size& rSize,
		BOOL bFloatingCtrl );

	/*begin: Backwards compatability with office 95 import, modify later*/
	const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & GetServiceFactory();
	sal_uInt16 GetEditNum() { return ++nEdit; }
	sal_uInt16 GetCheckboxNum() { return ++nCheckbox; }
	/*end: Backwards compatability*/
private:
	const ::com::sun::star::uno::Reference< com::sun::star::drawing::XShapes > & 			GetShapes();
	const ::com::sun::star::uno::Reference< com::sun::star::container::XIndexContainer > & 	GetFormComps();

	SfxObjectShell *pDocSh;
	SwPaM *pPaM;

	// gecachte Interfaces
	::com::sun::star::uno::Reference< com::sun::star::drawing::XDrawPage >  			xDrawPage;
	::com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >   				xShapes;
	::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > 		xServiceFactory;

	// das einzige Formular
	::com::sun::star::uno::Reference< com::sun::star::container::XIndexContainer > 			xFormComps;

	sal_uInt16 nEdit;
	sal_uInt16 nCheckbox;

	const ::com::sun::star::uno::Reference< com::sun::star::drawing::XDrawPage > & GetDrawPage();
};

class OCX_FontData
{
public:
	OCX_FontData() : nFontNameLen(0), fBold(0),fItalic(0),fUnderline(0),
		fStrike(0),nJustification(0),pFontName(0) {}
	~OCX_FontData()  {
		if (pFontName)
		delete [] pFontName;
	}
	sal_Bool Read(SvStorageStream *pS);
	void Convert(com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > &rPropSet);

	sal_uInt16 nIdentifier;
	sal_uInt16 nFixedAreaLen;
	sal_uInt8 pBlockFlags[4];

	sal_uInt32 nFontNameLen;

	sal_uInt8   fBold:1;
	sal_uInt8   fItalic:1;
	sal_uInt8   fUnderline:1;
	sal_uInt8   fStrike:1;
	sal_uInt8   fUnknown1:4;

	sal_uInt8   nUnknown2;
	sal_uInt8   nUnknown3;
	sal_uInt8   nUnknown4;

	sal_uInt32  nFontSize;
	sal_uInt16 nLanguageID;
	sal_uInt8   nJustification;

	char *pFontName;
};

class OCX_Control
{
public:
	OCX_Control(UniString sN) : sName(sN) {}
	sal_Bool FullRead(SvStorageStream *pS)
	{
		if (Read(pS))
			return(aFontData.Read(pS));
		return(sal_False);
	};
	virtual sal_Bool Read(SvStorageStream *pS) {return sal_False;}
	virtual sal_Bool Convert(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rServiceFactory,
		::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz) {return sal_False;}
	sal_Bool ReadAndConvert(SvStorageStream *pS,::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rSF,
			::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz)
	{
	if (Read(pS))
		return Convert(rSF,rFComp,rSz);
	return sal_False;
	}
	virtual ~OCX_Control() {}

	UniString sName;
	OCX_FontData aFontData;
protected:
	sal_uInt32 ConvertColor(sal_uInt32 nColorCode) const;
	sal_Int16 ConvertBorder(sal_uInt16 nSpecialEffect,sal_uInt16 nBorderStyle)
		const;
	static sal_uInt16 nStandardId;
private:
	static sal_uInt32 pColor[25];
};

class OCX_ModernControl : public OCX_Control
{
public:
	OCX_ModernControl(UniString sN) : OCX_Control(sN),
	fEnabled(1),fLocked(0),fBackStyle(1),fColumnHeads(0),fIntegralHeight(1),
	fMatchRequired(0),fAlignment(1),fDragBehaviour(0),fEnterKeyBehaviour(0),
	fEnterFieldBehaviour(0),fTabKeyBehaviour(0),fWordWrap(1),
	fSelectionMargin(1),fAutoWordSelect(1),fAutoSize(0),fHideSelection(1),
	fAutoTab(0),fMultiLine(1),nMaxLength(0),nBorderStyle(1),nScrollBars(0),
	nStyle(0), nMousePointer(0),nListWidth(0),nBoundColumn(1),nTextColumn(-1),
	nColumnCount(1),nListRows(8),nMatchEntry(2),nPasswordChar(0),nListStyle(0),
	nShowDropButtonWhen(0),nDropButtonStyle(1),nMultiState(0), nValueLen(0),
	nCaptionLen(0), nVertPos(1), nHorzPos(7),
	nSpecialEffect(2),nIcon(0),nPicture(0),nAccelerator(0),nGroupNameLen(0),
	pValue(0), pCaption(0), pGroupName(0),nIconLen(0),pIcon(0),nPictureLen(0),
	pPicture(0) {}

	~OCX_ModernControl() {
		if (pValue) delete[] pValue;
		if (pCaption) delete[] pCaption;
		if (pGroupName) delete[] pGroupName;
		if (pIcon) delete[] pIcon;
		if (pPicture) delete[] pPicture;
	}
	sal_Bool Read(SvStorageStream *pS);

	/*sal_uInt8 for sal_uInt8 Word Struct*/
	sal_uInt16  nIdentifier;
	sal_uInt16 	nFixedAreaLen;
	sal_uInt8	pBlockFlags[8];

	sal_uInt8	fUnknown1:1;
	sal_uInt8	fEnabled:1;
	sal_uInt8	fLocked:1;
	sal_uInt8	fBackStyle:1;
	sal_uInt8	fUnknown2:4;

	sal_uInt8	fUnknown3:2;
	sal_uInt8	fColumnHeads:1;
	sal_uInt8	fIntegralHeight:1;
	sal_uInt8	fMatchRequired:1;
	sal_uInt8	fAlignment:1;
	sal_uInt8	fUnknown4:2;

	sal_uInt8	fUnknown5:3;
	sal_uInt8	fDragBehaviour:1;
	sal_uInt8	fEnterKeyBehaviour:1;
	sal_uInt8	fEnterFieldBehaviour:1;
	sal_uInt8	fTabKeyBehaviour:1;
	sal_uInt8	fWordWrap:1;

	sal_uInt8	fUnknown6:2;
	sal_uInt8	fSelectionMargin:1;
	sal_uInt8	fAutoWordSelect:1;
	sal_uInt8	fAutoSize:1;
	sal_uInt8	fHideSelection:1;
	sal_uInt8	fAutoTab:1;
	sal_uInt8	fMultiLine:1;

	sal_uInt32	nBackColor;
	sal_uInt32	nForeColor;
	sal_uInt32 	nMaxLength;
	sal_uInt8	nBorderStyle;
	sal_uInt8	nScrollBars;
	sal_uInt8	nStyle;
	sal_uInt8	nMousePointer;
	sal_uInt8	nUnknown7;
	sal_uInt8	nPasswordChar;
	sal_uInt32	nListWidth;
	sal_uInt16	nBoundColumn;
	sal_Int16	nTextColumn;
	sal_uInt16	nColumnCount;
	sal_uInt16	nListRows;
	sal_uInt16	nUnknown8;
	sal_uInt8	nMatchEntry;
	sal_uInt8	nListStyle;
	sal_uInt8	nShowDropButtonWhen;
	sal_uInt8	nDropButtonStyle;
	sal_uInt8	nMultiState;
	sal_uInt32	nValueLen;
	sal_uInt32	nCaptionLen;

	sal_uInt16 nVertPos;
	sal_uInt16 nHorzPos;

	sal_uInt32 nBorderColor;
	sal_uInt8 nSpecialEffect;
	sal_uInt16 nIcon;
	sal_uInt16 nPicture;
	sal_uInt8 nAccelerator;
	sal_uInt8 nUnknown9;
	sal_uInt32 nGroupNameLen;

	sal_uInt32 nWidth;
	sal_uInt32 nHeight;

	char *pValue;
	char *pCaption;
	char *pGroupName;

	sal_uInt8 pIconHeader[20];
	sal_uInt32 nIconLen;
	sal_uInt8 *pIcon;

	sal_uInt8 pPictureHeader[20];
	sal_uInt32 nPictureLen;
	sal_uInt8 *pPicture;

};


class OCX_CheckBox : public OCX_ModernControl
{
public:
	OCX_CheckBox() : OCX_ModernControl(C2U("CheckBox")){
		nBackColor = 0x00FFFFFF;
		nForeColor = 0x00000000;
	}
	sal_Bool Convert(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rServiceFactory,
		::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz);
	static OCX_Control *Create() { return new OCX_CheckBox;}
};

class OCX_OptionButton : public OCX_ModernControl
{
public:
	OCX_OptionButton() : OCX_ModernControl(C2U("OptionButton"))
	{
		nBackColor =  0x00FFFFFF;
		nForeColor =  0x00000000;
	}
	sal_Bool Convert(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rServiceFactory,
		::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz);

	static OCX_Control *Create() { return new OCX_OptionButton;}
};

class OCX_TextBox : public OCX_ModernControl
{
public:
	OCX_TextBox() : OCX_ModernControl(C2U("TextBox")) {
		nBackColor = 0x80000005L;
		nForeColor = 0x80000008L;
		nBorderColor = 0x80000006L;
	}
	sal_Bool Convert(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rServiceFactory,
		::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz);
	static OCX_Control *Create() { return new OCX_TextBox;}
};

class OCX_ToggleButton : public OCX_ModernControl
{
public:
	OCX_ToggleButton() : OCX_ModernControl(C2U("ToggleButton")) {
		nBackColor = 0x8000000F;
		nForeColor = 0x80000012;
	}
	static OCX_Control *Create() { return new OCX_ToggleButton;}
	sal_Bool Convert(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rServiceFactory,
		::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz);
};

class OCX_ComboBox : public OCX_ModernControl
{
public:
	OCX_ComboBox() : OCX_ModernControl(C2U("ComboBox")){
		nBackColor = 0x80000005;
		nForeColor = 0x80000008;
		nBorderColor = 0x80000006;
	}
	static OCX_Control *Create() { return new OCX_ComboBox;}
	sal_Bool Convert(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rServiceFactory,
		::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz);
};

class OCX_ListBox : public OCX_ModernControl
{
public:
	OCX_ListBox() : OCX_ModernControl(C2U("ListBox")){
		nBackColor = 0x80000005;
		nForeColor = 0x80000008;
		nBorderColor = 0x80000006;
	}
	static OCX_Control *Create() { return new OCX_ListBox;}
	sal_Bool Convert(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rServiceFactory,
		::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz);
};

class OCX_CommandButton : public OCX_Control
{
public:
	//OCX_CommandButton() : OCX_Control(L ::com::sun::star::form"),nForeColor(0x80000012L),
	OCX_CommandButton() : OCX_Control(String::CreateFromAscii("CommandButton")),nForeColor(0x80000012L),
	nBackColor(0x8000000FL), fEnabled(1),fLocked(0), fBackStyle(1),
	fWordWrap(1),fAutoSize(0),nMousePointer(0), nCaptionLen(0),
	nAccelerator(0),nVertPos(1),nHorzPos(7), pCaption(0), nIconLen(0),
	pIcon(0), nPictureLen(0), pPicture(0),
	nIcon(0),nPicture(0) {}

	~OCX_CommandButton() {
		if (pCaption) delete[] pCaption;
		if (pIcon) delete[] pIcon;
		if (pPicture) delete[] pPicture;
	}
	sal_Bool Read(SvStorageStream *pS);

	/*sal_uInt8 for sal_uInt8 Word Struct*/
	sal_uInt16	nIdentifier;
	sal_uInt16	nFixedAreaLen;
	sal_uInt8	pBlockFlags[4];

	sal_uInt32	nForeColor;
	sal_uInt32	nBackColor;

	sal_uInt8	fUnknown1:1;
	sal_uInt8	fEnabled:1;
	sal_uInt8	fLocked:1;
	sal_uInt8	fBackStyle:1;
	sal_uInt8	fUnknown2:4;

	sal_uInt8	fUnknown3:8;

	sal_uInt8	fUnknown4:7;
	sal_uInt8	fWordWrap:1;

	sal_uInt8	fUnknown5:4;
	sal_uInt8	fAutoSize:1;
	sal_uInt8	fUnknown6:3;

	sal_uInt32	nCaptionLen;

	sal_uInt16  nVertPos;
	sal_uInt16  nHorzPos;

	sal_uInt16 	nMousePointer;
	sal_uInt16	nPicture;
	sal_uInt16	nAccelerator;
	sal_uInt16	nIcon;

	char *pCaption;

	sal_uInt32 	nWidth;
	sal_uInt32 	nHeight;

	sal_uInt8 pIconHeader[20];
	sal_uInt32  nIconLen;
	sal_uInt8 *pIcon;

	sal_uInt8 pPictureHeader[20];
	sal_uInt32  nPictureLen;
	sal_uInt8 *pPicture;

	static OCX_Control *Create() { return new OCX_CommandButton;}
	sal_Bool Convert(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rServiceFactory,
		::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz);
};


class OCX_Label : public OCX_Control
{
public:
	OCX_Label() : OCX_Control(C2U("Label")),nForeColor(0),nBackColor(0xFFFFFF),
	fEnabled(1),fLocked(0),fBackStyle(1),fWordWrap(1),fAutoSize(0),
	nCaptionLen(0),nVertPos(1),nHorzPos(7),nMousePointer(0),
	nBorderColor(0x80000006),nBorderStyle(0),nSpecialEffect(0),
	nPicture(0),nAccelerator(0),nIcon(0),pCaption(0),nIconLen(0),pIcon(0),
	nPictureLen(0),pPicture(0) {}

	~OCX_Label() {
		if (pCaption) delete[] pCaption;
		if (pIcon) delete[] pIcon;
		if (pPicture) delete[] pPicture;
	}
	sal_Bool Read(SvStorageStream *pS);

	/*sal_uInt8 for sal_uInt8 Word Struct*/
	sal_uInt16 nIdentifier;
	sal_uInt16 nFixedAreaLen;
	sal_uInt8	pBlockFlags[4];

	sal_uInt32	nForeColor;
	sal_uInt32	nBackColor;

	sal_uInt8	fUnknown1:1;
	sal_uInt8	fEnabled:1;
	sal_uInt8	fLocked:1;
	sal_uInt8	fBackStyle:1;
	sal_uInt8	fUnknown2:4;

	sal_uInt8	fUnknown3:8;

	sal_uInt8	fUnknown4:7;
	sal_uInt8	fWordWrap:1;

	sal_uInt8	fUnknown5:4;
	sal_uInt8	fAutoSize:1;
	sal_uInt8	fUnknown6:3;

	sal_uInt32	nCaptionLen;
	sal_uInt16  nVertPos;
	sal_uInt16  nHorzPos;
	sal_uInt8 	nMousePointer;
	sal_uInt32	nBorderColor;
	sal_uInt16	nBorderStyle;
	sal_uInt16	nSpecialEffect;
	sal_uInt16	nPicture;
	sal_uInt16	nAccelerator;
	sal_uInt16	nIcon;

	char *pCaption;

	sal_uInt32 	nWidth;
	sal_uInt32 	nHeight;

	sal_uInt8 pIconHeader[20];
	sal_uInt32  nIconLen;
	sal_uInt8 *pIcon;

	sal_uInt8 pPictureHeader[20];
	sal_uInt32  nPictureLen;
	sal_uInt8 *pPicture;

	static OCX_Control *Create() { return new OCX_Label;}
	sal_Bool Convert(const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >  &rServiceFactory,
		::com::sun::star::uno::Reference< com::sun::star::form::XFormComponent >  &rFComp,com::sun::star::awt::Size &rSz);
};
#endif
