/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: sc_cellsh2.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2006/10/27 17:07:31 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 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
 *
 ************************************************************************/

#ifdef PCH
#endif

#pragma hdrstop

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

#define _BIGINT_HXX
//#define _BASEDLGS_HXX ***
#define _CACHESTR_HXX
//#define _CLIP_HXX
#define _CONFIG_HXX
#define _CURSOR_HXX
#define _DLGCFG_HXX
#define _DYNARR_HXX
#define _EXTATTR_HXX
//#define _FILTER_HXX
#define _FONTDLG_HXX
#define _MACRODLG_HXX
#define _MODALDLG_HXX
#define _MOREBUTTON_HXX
#define _OUTLINER_HXX
#define _PASSWD_HXX
//#define _PRNDLG_HXX
#define _POLY_HXX
#define _PRVWIN_HXX
#define _QUEUE_HXX
//#define _RULER_HXX
#define _SCRWIN_HXX
#define _SOUND_HXX
#define _STACK_HXX
//#define _STATUS_HXX ***
#define _STDMENU_HXX
#define _TABBAR_HXX
//#define _TREELIST_HXX
#define _SFXBASIC_HXX
#define _SFX_DOCFILE_HXX
//#define _SFX_DOCFILT_HXX
#define _SFX_DOCINF_HXX
#define _SFX_DOCSH_HXX
#define _SFX_TEMPLDLG_HXX
#define _SFXSTBMGR_HXX
#define _SFXTBXMGR_HXX
#define _SFXIMGMGR_HXX
#define _SFXFILEDLG_HXX
#define _SFXIMGMGR_HXX
#define _SFXIPFRM_HXX
#define _SFX_MACRO_HXX
#define _SFXMNUITEM_HXX
#define _SFXMNUMGR_HXX
#define _SFXMULTISEL_HXX
#define _SFXSTBITEM_HXX
#define _SFXTBXCTRL_HXX

#define _SI_DLL_HXX
#define _SIDLL_HXX
#define _SI_NOITEMS
#define _SI_NOOTHERFORMS
#define _SI_NOSBXCONTROLS
#define _SINOSBXCONTROLS
#define _SI_NODRW		  //
#define _SI_NOCONTROL

#define _SVBOXITM_HXX
//#define _SVCONTNR_HXX
#define _SVDATTR_HXX
#define _SVDXOUT_HXX
#define _SVDEC_HXX
#define _SVDIO_HXX
#define _SVDLAYER_HXX
#define _SVDRAG_HXX
#define _SVINCVW_HXX
#define _SV_MULTISEL_HXX
#define _SVRTV_HXX
#define _SVTABBX_HXX


#define _SVX_DAILDLL_HXX
#define _SVX_HYPHEN_HXX
#define _SVX_IMPGRF_HXX
#define _SVX_OPTITEMS_HXX
#define _SVX_OPTGERL_HXX
#define _SVX_OPTSAVE_HXX
#define _SVX_OPTSPELL_HXX
#define _SVX_OPTPATH_HXX
#define _SVX_OPTLINGU_HXX
#define _SVX_RULER_HXX
#define _SVX_RULRITEM_HXX
#define _SVX_SPLWRAP_HXX
#define _SVX_SPLDLG_HXX
#define _SVX_THESDLG_HXX


// INCLUDE ---------------------------------------------------------------

#include "scitems.hxx"
#include <bf_sfx2/request.hxx>
#include <svtools/whiter.hxx>
#include <bf_offmgr/sbaitems.hxx>
#include <bf_offmgr/sbasltid.hrc>


#include "dbcolect.hxx"
#include "cellsh.hxx"
#include "tabvwsh.hxx"
#include "bf_sc.hrc"
#include "globstr.hrc"
#include "docsh.hxx"

using namespace ::com::sun::star;
namespace binfilter {

//#include "strindlg.hxx"		//! Test !!!!!

//static ScArea aPivotSource; 		//! wohin? (ueber den Dialog retten)


#define IS_AVAILABLE(WhichId,ppItem) \
    (pReqArgs->GetItemState((WhichId), TRUE, ppItem ) == SFX_ITEM_SET)

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


/*
			{

				USHORT			nId  = ScPivotLayoutWrapper::GetChildWindowId();
				SfxChildWindow* pWnd = pSfxApp->GetChildWindow( nId );

				pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );

			}
			break;
*/


/*M*/ void __EXPORT ScCellShell::GetDBState( SfxItemSet& rSet )
/*M*/ {
/*M*/ 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
/*M*/ 	ScViewData* pViewData	= GetViewData();
/*M*/ 	ScDocShell*	pDocSh		= pViewData->GetDocShell();
/*M*/ 	ScDocument* pDoc		= pDocSh->GetDocument();
/*M*/ 	USHORT		nPosX		= pViewData->GetCurX();
/*M*/ 	USHORT		nPosY		= pViewData->GetCurY();
/*M*/ 	USHORT		nTab		= pViewData->GetTabNo();
/*M*/ 
/*M*/ 	BOOL bAutoFilter;
/*M*/ 	BOOL bAutoFilterTested = FALSE;
/*M*/ 
/*M*/ 	SfxWhichIter aIter(rSet);
/*M*/ 	USHORT nWhich = aIter.FirstWhich();
/*M*/ 	while (nWhich)
/*M*/ 	{
/*M*/ 		switch (nWhich)
/*M*/ 		{
/*M*/ 			case SID_REFRESH_DBAREA:
/*M*/ 				{
/*M*/ 					//	importierte Daten ohne Selektion
/*M*/ 					//	oder Filter,Sortierung,Teilergebis (auch ohne Import)
/*M*/ 					BOOL bOk = FALSE;
/*M*/ 					ScDBData* pDBData = pTabViewShell->GetDBData(FALSE,SC_DB_OLD);
/*M*/ 					if (pDBData && pDoc->GetChangeTrack() == NULL)
/*M*/ 					{
/*M*/ 						if ( pDBData->HasImportParam() )
/*M*/ 							bOk = !pDBData->HasImportSelection();
/*M*/ 						else
/*M*/ 						{
/*M*/ 							bOk = pDBData->HasQueryParam() ||
/*M*/ 								  pDBData->HasSortParam() ||
/*M*/ 								  pDBData->HasSubTotalParam();
/*M*/ 							if (!bOk)
/*M*/ 							{
/*M*/ 								DBG_BF_ASSERT(0, "STRIP"); //STRIP001 //	Pivottabelle mit den Daten als Quellbereich ?
/*M*/ 							}
/*M*/ 						}
/*M*/ 					}
/*M*/ 					if (!bOk)
/*M*/ 						rSet.DisableItem( nWhich );
/*M*/ 				}
/*M*/ 				break;
/*M*/ 
/*M*/ 			case SID_FILTER:
/*M*/ 			case SID_SPECIAL_FILTER:
/*M*/ 				{
/*M*/ 					if (GetViewData()->IsMultiMarked())
/*M*/ 					{
/*M*/ 						rSet.DisableItem( nWhich );
/*M*/ 					}
/*M*/ 				}
/*M*/ 				break;
/*M*/ 
/*M*/ 
/*M*/ 				//Bei Redlining und Multiselektion Disablen
/*M*/ 			case SID_SORT_ASCENDING:
/*M*/ 			case SID_SORT_DESCENDING:
/*M*/ 			case SCITEM_SORTDATA:
/*M*/ 			case SCITEM_SUBTDATA:
/*M*/ 			case SID_OPENDLG_PIVOTTABLE:
/*M*/ 				{
/*M*/ 					//!	move ReadOnly check to idl flags
/*M*/ 
/*M*/ 					if ( pDocSh->IsReadOnly() || pDoc->GetChangeTrack()!=NULL ||
/*M*/ 							GetViewData()->IsMultiMarked() )
/*M*/ 					{
/*M*/ 						rSet.DisableItem( nWhich );
/*M*/ 					}
/*M*/ 				}
/*M*/ 				break;
/*M*/ 
/*M*/ 			case SID_REIMPORT_DATA:
/*M*/ 				{
/*M*/ 					//	nur importierte Daten ohne Selektion
/*M*/ 					ScDBData* pDBData = pTabViewShell->GetDBData(FALSE,SC_DB_OLD);
/*M*/ 					if (!pDBData || !pDBData->HasImportParam() || pDBData->HasImportSelection() ||
/*M*/ 						pDoc->GetChangeTrack()!=NULL)
/*M*/ 					{
/*M*/ 						rSet.DisableItem( nWhich );
/*M*/ 					}
/*M*/ 				}
/*M*/ 				break;
/*M*/ 
/*M*/ 			case SID_VIEW_DATA_SOURCE_BROWSER:
/*M*/ 				{
/*M*/ 					//	get state (BoolItem) from SfxViewFrame
/*M*/ 
/*M*/ 					pTabViewShell->GetViewFrame()->GetSlotState( nWhich, NULL, &rSet );
/*M*/ 				}
/*M*/ 				break;
/*M*/ 			case SID_SBA_BRW_INSERT:
/*M*/ 				{
/*M*/ 					//	SBA will ein BOOL-Item, damit ueberhaupt enabled
/*M*/ 
/*M*/ 					BOOL bEnable = TRUE;
/*M*/ 					rSet.Put(SfxBoolItem(nWhich, bEnable));
/*M*/ 				}
/*M*/ 				break;
/*M*/ 
/*M*/ 			case SID_AUTO_FILTER:
/*M*/ 			case SID_AUTOFILTER_HIDE:
/*M*/ 				{
/*M*/ 					if (!bAutoFilterTested)
/*M*/ 					{
/*M*/ 						bAutoFilter = pDoc->HasAutoFilter( nPosX, nPosY, nTab );
/*M*/ 						bAutoFilterTested = TRUE;
/*M*/ 					}
/*M*/ 					if ( nWhich == SID_AUTO_FILTER )
/*M*/ 					{
/*M*/ 						if (GetViewData()->IsMultiMarked())
/*M*/ 						{
/*M*/ 							rSet.DisableItem( nWhich );
/*M*/ 						}
/*M*/ 						else
/*M*/ 							rSet.Put( SfxBoolItem( nWhich, bAutoFilter ) );
/*M*/ 					}
/*M*/ 					else
/*M*/ 						if (!bAutoFilter)
/*M*/ 							rSet.DisableItem( nWhich );
/*M*/ 				}
/*M*/ 				break;
/*M*/ 
/*M*/ 			case SID_UNFILTER:
/*M*/ 				{
/*M*/ 					USHORT nStartCol, nStartRow, nStartTab;
/*M*/ 					USHORT nEndCol,   nEndRow,   nEndTab;
/*M*/ 					BOOL bAnyQuery = FALSE;
/*M*/ 
/*M*/ 					BOOL bSelected = GetViewData()->GetSimpleArea(
/*M*/ 							nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab );
/*M*/ 
/*M*/ 					if ( bSelected )
/*M*/ 					{
/*M*/ 						if (nStartCol==nEndCol && nStartRow==nEndRow)
/*M*/ 							bSelected = FALSE;
/*M*/ 					}
/*M*/ 					else
/*M*/ 					{
/*M*/ 						nStartCol = GetViewData()->GetCurX();
/*M*/ 						nStartRow = GetViewData()->GetCurY();
/*M*/ 						nStartTab = GetViewData()->GetTabNo();
/*M*/ 					}
/*M*/ 
/*M*/ 					ScDBData* pDBData = bSelected
/*M*/ 								? pDoc->GetDBAtArea( nStartTab, nStartCol, nStartRow, nEndCol, nEndRow )
/*M*/ 								: pDoc->GetDBAtCursor( nStartCol, nStartRow, nStartTab );
/*M*/ 
/*M*/ 					if ( pDBData )
/*M*/ 					{
/*M*/ 						ScQueryParam aParam;
/*M*/ 						pDBData->GetQueryParam( aParam );
/*M*/ 						if ( aParam.GetEntry(0).bDoQuery )
/*M*/ 							bAnyQuery = TRUE;
/*M*/ 					}
/*M*/ 
/*M*/ 					if ( !bAnyQuery )
/*M*/ 						rSet.DisableItem( nWhich );
/*M*/ 				}
/*M*/ 				break;
/*M*/ 		}
/*M*/ 		nWhich = aIter.NextWhich();
/*M*/ 	}
/*M*/ }



}
