/*************************************************************************
 *
 *  $RCSfile: tabdlg.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: mba $ $Date: 2001/06/26 14:50:55 $
 *
 *  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 _SFXTABDLG_HXX
#define _SFXTABDLG_HXX

#ifndef _SV_TABDLG_HXX //autogen
#include <vcl/tabdlg.hxx>
#endif
#ifndef _SV_BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif
#ifndef _SV_TABCTRL_HXX //autogen
#include <vcl/tabctrl.hxx>
#endif
#ifndef _SV_TABPAGE_HXX //autogen
#include <vcl/tabpage.hxx>
#endif
#ifndef _SFXITEMPOOL_HXX //autogen
#include <svtools/itempool.hxx>
#endif
#ifndef _SFXITEMSET_HXX //autogen
#include <svtools/itemset.hxx>
#endif

class SfxPoolItem;
class SfxTabDialog;
class SfxViewFrame;
class SfxTabPage;
class SfxBindings;

// typedefs --------------------------------------------------------------

typedef SfxTabPage* (*CreateTabPage)(Window *pParent, const SfxItemSet &rAttrSet);
typedef USHORT*		(*GetTabPageRanges)(); // liefert internationale Which-Wert

struct TabDlg_Impl;
struct TabPageImpl;
class SfxUs_Impl;

// class SfxTabDialog ----------------------------------------------------

#define ID_TABCONTROL	1
#define RET_USER 		100
#define RET_USER_CANCEL	101

class SfxTabDialogItem: public SfxSetItem
{
public:
	TYPEINFO();
                            SfxTabDialogItem( USHORT nId, const SfxItemSet& rItemSet );
                            SfxTabDialogItem(const SfxTabDialogItem& rAttr, SfxItemPool* pItemPool=NULL);
	virtual SfxPoolItem*    Clone(SfxItemPool* pToPool) const;
	virtual SfxPoolItem*    Create(SvStream& rStream, USHORT nVersion) const;
};

class SfxTabDialog : public TabDialog
{
private:
friend class SfxTabPage;
friend class SfxTabDialogController;

	SfxViewFrame*	pFrame;

	TabControl		aTabCtrl;
	OKButton		aOKBtn;
	PushButton*		pUserBtn;
	CancelButton	aCancelBtn;
	HelpButton		aHelpBtn;
	PushButton		aResetBtn;
	PushButton		aBaseFmtBtn;

	const SfxItemSet*	pSet;
	SfxItemSet*			pOutSet;
	TabDlg_Impl*		pImpl;
	USHORT*				pRanges;
	USHORT				nResId;
	USHORT				nAppPageId;
	BOOL				bItemsReset;
	BOOL				bFmt;

#if 0 // _SOLAR__PRIVATE
	DECL_LINK( ActivatePageHdl, TabControl * );
	DECL_LINK( DeactivatePageHdl, TabControl * );
	DECL_LINK( OkHdl, Button * );
	DECL_LINK( ResetHdl, Button * );
	DECL_LINK( BaseFmtHdl, Button * );
	DECL_LINK( UserHdl, Button * );
	DECL_LINK( CancelHdl, Button * );
	void			Init_Impl(BOOL, const String *);
#endif

protected:
	virtual short				Ok();
	// wird im Sfx gel"oscht!
	virtual SfxItemSet*			CreateInputItemSet( USHORT nId );
	// wird *nicht* im Sfx gel"oscht!
	virtual const SfxItemSet*	GetRefreshedSet();
	virtual void				PageCreated( USHORT nId, SfxTabPage &rPage );
#if SUPD>=636
    virtual long                Notify( NotifyEvent& rNEvt );
#endif

	SfxItemSet*		pExampleSet;
	SfxItemSet*		GetInputSetImpl();
	SfxTabPage*		GetTabPage( USHORT nPageId ) const;

	BOOL			IsInOK() const;
	/**	prepare to leace the current page. Calls the DeactivatePage method of the current page, (if necessary),
		handles the item sets to copy.
		@return TRUE if it is allowed to leave the current page, FALSE otherwise
	*/
	BOOL			PrepareLeaveCurrentPage();

public:
    SfxTabDialog( Window* pParent, const ResId &rResId, USHORT nSetId, SfxBindings& rBindings,
				  BOOL bEditFmt = FALSE, const String *pUserButtonText = 0 );
	SfxTabDialog( Window* pParent, const ResId &rResId, const SfxItemSet * = 0,
				  BOOL bEditFmt = FALSE, const String *pUserButtonText = 0 );
	SfxTabDialog( SfxViewFrame *pViewFrame, Window* pParent, const ResId &rResId,
				  const SfxItemSet * = 0, BOOL bEditFmt = FALSE,
				  const String *pUserButtonText = 0 );
	~SfxTabDialog();

	void				AddTabPage( USHORT nId,
									CreateTabPage pCreateFunc,		// != 0
									GetTabPageRanges pRangesFunc,	// darf 0 sein
									BOOL bItemsOnDemand = FALSE);
	void				AddTabPage( USHORT nId,
									const String &rRiderText,
									CreateTabPage pCreateFunc,		// != 0
									GetTabPageRanges pRangesFunc,	// darf 0 sein
									BOOL bItemsOnDemand = FALSE,
									USHORT nPos = TAB_APPEND);
	void				AddTabPage( USHORT nId,
									const Bitmap &rRiderBitmap,
									CreateTabPage pCreateFunc,		// != 0
									GetTabPageRanges pRangesFunc,	// darf 0 sein
									BOOL bItemsOnDemand = FALSE,
									USHORT nPos = TAB_APPEND);
	void				RemoveTabPage( USHORT nId );

	void				SetCurPageId( USHORT nId ) { nAppPageId = nId; }
	USHORT				GetCurPageId() const
							{ return aTabCtrl.GetCurPageId(); }
	void				ShowPage( USHORT nId );

						// liefert ggf. per Map konvertierte lokale Slots
	const USHORT*		GetInputRanges( const SfxItemPool& );
	void				SetInputSet( const SfxItemSet* pInSet );
	const SfxItemSet*	GetOutputItemSet() const { return pOutSet; }
	const SfxItemSet*	GetOutputItemSet( USHORT nId ) const;
	int					FillOutputItemSet();
	const BOOL			IsFormat() const { return bFmt; }

	const OKButton& 	GetOKButton() const { return aOKBtn; }
	OKButton&			GetOKButton() { return aOKBtn; }
	const CancelButton& GetCancelButton() const { return aCancelBtn; }
	CancelButton&		GetCancelButton() { return aCancelBtn; }
	const HelpButton&	GetHelpButton() const { return aHelpBtn; }
	HelpButton&			GetHelpButton() { return aHelpBtn; }
	const PushButton& 	GetResetButton() const { return aResetBtn; }
	PushButton&			GetResetButton() { return aResetBtn; }

	const PushButton*	GetApplyButton() const;
	PushButton*			GetApplyButton();

	const PushButton*	GetUserButton() const { return pUserBtn; }
	PushButton*			GetUserButton() { return pUserBtn; }
	void				RemoveResetButton();

	short				Execute();
	void				Start( BOOL bShow = TRUE );

	const SfxItemSet*	GetExampleSet() const { return pExampleSet; }
	SfxViewFrame*		GetViewFrame() const { return pFrame; }

	void				EnableApplyButton(BOOL bEnable = TRUE);
	BOOL				IsApplyButtonEnabled() const;
	void				SetApplyHandler(const Link& _rHdl);
	Link				GetApplyHandler() const;

#if 0 // _SOLAR__PRIVATE
	void				Start_Impl();
	BOOL				OK_Impl() { return PrepareLeaveCurrentPage(); }
#endif
};

// class SfxTabPage ------------------------------------------------------

class SfxTabPage: public TabPage
{
friend class SfxTabDialog;

private:
	const SfxItemSet*	pSet;
	String				aUserString;
	BOOL				bHasExchangeSupport;
	SfxTabDialog*		pTabDlg;
	TabPageImpl*		pImpl;

	void				SetTabDialog( SfxTabDialog* pNew ) { pTabDlg = pNew; }
	void				SetInputSet( const SfxItemSet* pNew ) { pSet = pNew; }

protected:
	SfxTabPage( Window *pParent, const ResId &, const SfxItemSet &rAttrSet );
	SfxTabPage( Window *pParent, WinBits nStyle, const SfxItemSet &rAttrSet );

	USHORT				GetSlot( USHORT nWhich ) const
							{ return pSet->GetPool()->GetSlotId( nWhich ); }
	USHORT				GetWhich( USHORT nSlot ) const
							{ return pSet->GetPool()->GetWhich( nSlot ); }
	const SfxPoolItem* 	GetOldItem( const SfxItemSet& rSet, USHORT nSlot );
	const SfxPoolItem* 	GetExchangeItem( const SfxItemSet& rSet, USHORT nSlot );
	SfxTabDialog*		GetTabDialog() const { return pTabDlg; }

public:
	virtual             ~SfxTabPage();

	const SfxItemSet&	GetItemSet() const { return *pSet; }

	virtual BOOL		FillItemSet( SfxItemSet& ) = 0;
	virtual void		Reset( const SfxItemSet& ) = 0;

	BOOL				HasExchangeSupport() const
							{ return bHasExchangeSupport; }
	void				SetExchangeSupport( BOOL bNew = TRUE )
							{ bHasExchangeSupport = bNew; }

	enum {
		KEEP_PAGE = 0x0000,		// Fehlerbehandlung; Seite nicht wechseln
			// 2. F"ullen eines ItemSets f"ur die Aktualilsierung
			// "ubergeordneter Beispiele; dieser Pointer kann immer
			// NULL sein!!
		LEAVE_PAGE = 0x0001,
			// Set aktualisieren und andere Page aktualisieren
		REFRESH_SET = 0x0002
	};

	virtual void		ActivatePage( const SfxItemSet& );
	virtual int			DeactivatePage( SfxItemSet* pSet = 0 );
	void				SetUserData(const String& rString)
							{ aUserString = rString; }
	String				GetUserData() { return aUserString; }
	virtual void		FillUserData();
	virtual BOOL		IsReadOnly() const;

	static const SfxPoolItem* GetItem( const SfxItemSet& rSet, USHORT nSlot );
};

#endif

