xref: /trunk/main/sc/source/ui/view/cellsh2.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 //------------------------------------------------------------------
34 
35 // INCLUDE ---------------------------------------------------------------
36 
37 #include "scitems.hxx"
38 #include <sfx2/viewfrm.hxx>
39 #include <sfx2/app.hxx>
40 #include <sfx2/request.hxx>
41 #include <svl/aeitem.hxx>
42 #include <basic/sbxcore.hxx>
43 #include <svl/whiter.hxx>
44 #include <svl/zforlist.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <svl/stritem.hxx>
47 #include <svl/visitem.hxx>
48 #include <unotools/moduleoptions.hxx>
49 
50 #include <com/sun/star/frame/FrameSearchFlag.hpp>
51 #include <com/sun/star/sdbc/XResultSet.hpp>
52 
53 #include "cellsh.hxx"
54 #include "tabvwsh.hxx"
55 #include "sc.hrc"
56 #include "globstr.hrc"
57 #include "global.hxx"
58 #include "scmod.hxx"
59 #include "docsh.hxx"
60 #include "document.hxx"
61 #include "uiitems.hxx"
62 #include "dbfunc.hxx"
63 #include "dbdocfun.hxx"
64 //CHINA001 #include "lbseldlg.hxx"
65 //CHINA001 #include "sortdlg.hxx"
66 #include "filtdlg.hxx"
67 #include "dbnamdlg.hxx"
68 //CHINA001 #include "subtdlg.hxx"
69 #include "reffact.hxx"
70 #include "pvlaydlg.hxx"
71 #include "validat.hxx"
72 #include "scresid.hxx"
73 //CHINA001 #include "validate.hxx"
74 #include "pivot.hxx"
75 #include "dpobject.hxx"
76 //CHINA001 #include "dapitype.hxx"
77 //CHINA001 #include "dapidata.hxx"
78 #include "dpsdbtab.hxx"		// ScImportSourceDesc
79 #include "dpshttab.hxx"		// ScSheetSourceDesc
80 
81 #include "validate.hrc" //CHINA001 add for ScValidationDlg
82 #include "scui_def.hxx" //CHINA001
83 #include "scabstdlg.hxx" //CHINA001
84 #include "impex.hxx"
85 #include "asciiopt.hxx"
86 using namespace com::sun::star;
87 
88 //#include "strindlg.hxx"		//! Test !!!!!
89 
90 //static ScArea aPivotSource; 		//! wohin? (ueber den Dialog retten)
91 
92 
93 #define IS_AVAILABLE(WhichId,ppItem) \
94     (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET)
95 
96 //------------------------------------------------------------------
97 
98 bool lcl_GetTextToColumnsRange( const ScViewData* pData, ScRange& rRange )
99 {
100     DBG_ASSERT( pData, "lcl_GetTextToColumnsRange: pData is null!" );
101 
102     bool bRet = false;
103     const ScMarkData& rMark = pData->GetMarkData();
104 
105     if ( rMark.IsMarked() )
106     {
107         if ( !rMark.IsMultiMarked() )
108         {
109             rMark.GetMarkArea( rRange );
110             if ( rRange.aStart.Col() == rRange.aEnd.Col() )
111             {
112                 bRet = true;
113             }
114         }
115     }
116     else
117     {
118         const SCCOL nCol = pData->GetCurX();
119         const SCROW nRow = pData->GetCurY();
120         const SCTAB nTab = pData->GetTabNo();
121         rRange = ScRange( nCol, nRow, nTab, nCol, nRow, nTab );
122         bRet = true;
123     }
124 
125     const ScDocument* pDoc = pData->GetDocument();
126     DBG_ASSERT( pDoc, "lcl_GetTextToColumnsRange: pDoc is null!" );
127 
128     if ( bRet && pDoc->IsBlockEmpty( rRange.aStart.Tab(), rRange.aStart.Col(),
129                                      rRange.aStart.Row(), rRange.aEnd.Col(),
130                                      rRange.aEnd.Row() ) )
131     {
132         bRet = false;
133     }
134 
135     return bRet;
136 }
137 
138 sal_Bool lcl_GetSortParam( const ScViewData* pData, ScSortParam& rSortParam )
139 {
140     ScTabViewShell* pTabViewShell   = pData->GetViewShell();
141     ScDBData*	pDBData             = pTabViewShell->GetDBData();
142     ScDocument* pDoc                = pData->GetDocument();
143     SCTAB nTab                      = pData->GetTabNo();
144     ScDirection eFillDir            = DIR_TOP;
145     sal_Bool  bSort                     = sal_True;
146     ScRange aExternalRange;
147 
148     if( rSortParam.nCol1 != rSortParam.nCol2 )
149         eFillDir = DIR_LEFT;
150     if( rSortParam.nRow1 != rSortParam.nRow2 )
151         eFillDir = DIR_TOP;
152 
153     SCSIZE nCount = pDoc->GetEmptyLinesInBlock( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab, eFillDir );
154 
155     if( rSortParam.nRow2 == MAXROW )
156         aExternalRange = ScRange( rSortParam.nCol1,sal::static_int_cast<SCROW>( nCount ), nTab );
157     else
158         aExternalRange = ScRange( pData->GetCurX(), pData->GetCurY(), nTab );
159 
160     SCROW nStartRow = aExternalRange.aStart.Row();
161     SCCOL nStartCol = aExternalRange.aStart.Col();
162     SCROW nEndRow   = aExternalRange.aEnd.Row();
163     SCCOL nEndCol   = aExternalRange.aEnd.Col();
164     pDoc->GetDataArea( aExternalRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow, sal_False, false );
165     aExternalRange.aStart.SetRow( nStartRow );
166     aExternalRange.aStart.SetCol( nStartCol );
167     aExternalRange.aEnd.SetRow( nEndRow );
168     aExternalRange.aEnd.SetCol( nEndCol );
169 
170     if(( rSortParam.nCol1 == rSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col() ) ||
171         ( rSortParam.nRow1 == rSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row() ) )
172     {
173         sal_uInt16 nFmt = SCA_VALID;
174         String aExtendStr,aCurrentStr;
175 
176         pTabViewShell->AddHighlightRange( aExternalRange,Color( COL_LIGHTBLUE ) );
177         ScRange rExtendRange( aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), nTab, aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row(), nTab );
178         rExtendRange.Format( aExtendStr, nFmt, pDoc );
179 
180         ScRange rCurrentRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab );
181         rCurrentRange.Format( aCurrentStr, nFmt, pDoc );
182 
183         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
184         DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
185 
186         VclAbstractDialog* pWarningDlg = pFact->CreateScSortWarningDlg( pTabViewShell->GetDialogParent(),aExtendStr,aCurrentStr,RID_SCDLG_SORT_WARNING );
187         DBG_ASSERT(pWarningDlg, "Dialog create fail!");//CHINA001
188         short bResult = pWarningDlg->Execute();
189         if( bResult == BTN_EXTEND_RANGE || bResult == BTN_CURRENT_SELECTION )
190         {
191             if( bResult == BTN_EXTEND_RANGE )
192             {
193                 pTabViewShell->MarkRange( aExternalRange, sal_False );
194                 pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() );
195             }
196         }
197         else
198         {
199             bSort = sal_False;
200             pData->GetDocShell()->CancelAutoDBRange();
201         }
202 
203         delete pWarningDlg;
204         pTabViewShell->ClearHighlightRanges();
205     }
206     return bSort;
207 }
208 
209 //<!-- Added by PengYunQuan for Validity Cell Range Picker
210 //after end execute from !IsModalInputMode, it is safer to delay deleting
211 namespace
212 {
213 	long DelayDeleteAbstractDialog( void *pAbstractDialog, void * /*pArg*/ )
214 	{
215 		delete reinterpret_cast<VclAbstractDialog*>( pAbstractDialog );
216 		return 0;
217 	}
218 }
219 //--> Added by PengYunQuan for Validity Cell Range Picker
220 
221 void ScCellShell::ExecuteDB( SfxRequest& rReq )
222 {
223 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
224 	sal_uInt16 nSlotId = rReq.GetSlot();
225 	const SfxItemSet*	pReqArgs	= rReq.GetArgs();
226 	ScModule*			pScMod		= SC_MOD();
227 
228 	pTabViewShell->HideListBox();					// Autofilter-DropDown-Listbox
229 
230 	if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
231 	{
232 		pScMod->InputEnterHandler();
233 		pTabViewShell->UpdateInputHandler();
234 	}
235 
236 	switch ( nSlotId )
237 	{
238 		case SID_VIEW_DATA_SOURCE_BROWSER:
239 			{
240 				//	check if database beamer is open
241 
242 				SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
243 				sal_Bool bWasOpen = sal_False;
244 				{
245 					uno::Reference<frame::XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
246 					uno::Reference<frame::XFrame> xBeamerFrame = xFrame->findFrame(
247 														rtl::OUString::createFromAscii("_beamer"),
248 														frame::FrameSearchFlag::CHILDREN);
249 					if ( xBeamerFrame.is() )
250 						bWasOpen = sal_True;
251 				}
252 
253 				if ( bWasOpen )
254 				{
255 					//	close database beamer: just forward to SfxViewFrame
256 
257 					pViewFrame->ExecuteSlot( rReq );
258 				}
259 				else
260 				{
261 					//	show database beamer: SfxViewFrame call must be synchronous
262 
263 					pViewFrame->ExecuteSlot( rReq, (sal_Bool) sal_False );		// sal_False = synchronous
264 
265 					//	select current database in database beamer
266 
267 					ScImportParam aImportParam;
268 					ScDBData* pDBData = pTabViewShell->GetDBData(sal_True,SC_DB_OLD);		// don't create if none found
269 					if (pDBData)
270 						pDBData->GetImportParam( aImportParam );
271 
272 					ScDBDocFunc::ShowInBeamer( aImportParam, pTabViewShell->GetViewFrame() );
273 				}
274 				rReq.Done();		// needed because it's a toggle slot
275 			}
276 			break;
277 
278 		case SID_REIMPORT_DATA:
279 			{
280 				sal_Bool bOk = sal_False;
281 				ScDBData* pDBData = pTabViewShell->GetDBData(sal_True,SC_DB_OLD);
282 				if (pDBData)
283 				{
284 					ScImportParam aImportParam;
285 					pDBData->GetImportParam( aImportParam );
286 					if (aImportParam.bImport && !pDBData->HasImportSelection())
287 					{
288 						pTabViewShell->ImportData( aImportParam );
289 						pDBData->SetImportParam( aImportParam );	//! Undo ??
290 						bOk = sal_True;
291 					}
292 				}
293 
294 				if (!bOk && ! rReq.IsAPI() )
295 					pTabViewShell->ErrorMessage(STR_REIMPORT_EMPTY);
296 
297 				if( bOk )
298 					rReq.Done();
299 			}
300 			break;
301 
302 		case SID_REFRESH_DBAREA:
303 			{
304 				ScDBData* pDBData = pTabViewShell->GetDBData(sal_True,SC_DB_OLD);
305 				if (pDBData)
306 				{
307 					//	Import wiederholen wie SID_REIMPORT_DATA
308 
309 					sal_Bool bContinue = sal_True;
310 					ScImportParam aImportParam;
311 					pDBData->GetImportParam( aImportParam );
312 					if (aImportParam.bImport && !pDBData->HasImportSelection())
313 					{
314 						bContinue = pTabViewShell->ImportData( aImportParam );
315 						pDBData->SetImportParam( aImportParam );	//! Undo ??
316 
317 						//	markieren (Groesse kann sich geaendert haben)
318 						ScRange aNewRange;
319 						pDBData->GetArea(aNewRange);
320 						pTabViewShell->MarkRange(aNewRange);
321 					}
322 
323 					if ( bContinue )		// #41905# Fehler beim Import -> Abbruch
324 					{
325 						//	interne Operationen, wenn welche gespeichert
326 
327 						if ( pDBData->HasQueryParam() || pDBData->HasSortParam() ||
328 														  pDBData->HasSubTotalParam() )
329 							pTabViewShell->RepeatDB();
330 
331 						//	Pivottabellen die den Bereich als Quelldaten haben
332 
333 						ScRange aRange;
334 						pDBData->GetArea(aRange);
335 						GetViewData()->GetDocShell()->RefreshPivotTables(aRange);
336 					}
337 				}
338 				rReq.Done();
339 			}
340 			break;
341 
342 		case SID_SBA_BRW_INSERT:
343 			{
344 				DBG_ERROR( "Deprecated Slot" );
345 			}
346 			break;
347 
348 		case SID_SUBTOTALS:
349 			{
350 				const SfxItemSet* pArgs = rReq.GetArgs();
351 				if ( pArgs )
352 				{
353 					pTabViewShell->DoSubTotals( ((const ScSubTotalItem&) pArgs->Get( SCITEM_SUBTDATA )).
354 									GetSubTotalData() );
355 					rReq.Done();
356 				}
357 				else
358 				{
359 					//CHINA001 ScSubTotalDlg*	pDlg = NULL;
360 					SfxAbstractTabDialog * pDlg = NULL;
361 					ScSubTotalParam aSubTotalParam;
362 					SfxItemSet		aArgSet( GetPool(), SCITEM_SUBTDATA, SCITEM_SUBTDATA );
363 
364 					ScDBData* pDBData = pTabViewShell->GetDBData();
365 					pDBData->GetSubTotalParam( aSubTotalParam );
366 					aSubTotalParam.bRemoveOnly = sal_False;
367 
368 					aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, GetViewData(), &aSubTotalParam ) );
369 					//CHINA001 pDlg = new ScSubTotalDlg( pTabViewShell->GetDialogParent(), &aArgSet );
370 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
371 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
372 
373 					pDlg = pFact->CreateScSubTotalDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SUBTOTALS );
374 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
375 					pDlg->SetCurPageId(1);
376 
377 					short bResult = pDlg->Execute();
378 
379 					if ( (bResult == RET_OK) || (bResult == SCRET_REMOVE) )
380 					{
381 						const SfxItemSet* pOutSet = NULL;
382 
383 						if ( bResult == RET_OK )
384 						{
385 							pOutSet = pDlg->GetOutputItemSet();
386 							aSubTotalParam =
387 								((const ScSubTotalItem&)
388 									pOutSet->Get( SCITEM_SUBTDATA )).
389 										GetSubTotalData();
390 						}
391 						else // if (bResult == SCRET_REMOVE)
392 						{
393 							pOutSet = &aArgSet;
394 							aSubTotalParam.bRemoveOnly = sal_True;
395 							aSubTotalParam.bReplace    = sal_True;
396 							aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA,
397 														 GetViewData(),
398 														 &aSubTotalParam ) );
399 						}
400 
401 						pTabViewShell->DoSubTotals( aSubTotalParam );
402 						rReq.Done( *pOutSet );
403 					}
404                     else
405                         GetViewData()->GetDocShell()->CancelAutoDBRange();
406 
407 					delete pDlg;
408 				}
409 			}
410 			break;
411 
412         case SID_SORT_DESCENDING:
413         case SID_SORT_ASCENDING:
414             {
415                 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
416                 //the patch comes from maoyg
417                 ScSortParam aSortParam;
418                 ScDBData*	pDBData = pTabViewShell->GetDBData();
419                 ScViewData* pData   = GetViewData();
420 
421                 pDBData->GetSortParam( aSortParam );
422 
423                 if( lcl_GetSortParam( pData, aSortParam ) )
424                 {
425                     SfxItemSet  aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA );
426                     SCCOL nCol  = GetViewData()->GetCurX();
427                     SCCOL nTab  = GetViewData()->GetTabNo();
428                     ScDocument* pDoc    = GetViewData()->GetDocument();
429 
430                     pDBData->GetSortParam( aSortParam );
431                     sal_Bool bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, nTab );
432 
433                     if( nCol < aSortParam.nCol1 )
434                         nCol = aSortParam.nCol1;
435                     else if( nCol > aSortParam.nCol2 )
436                         nCol = aSortParam.nCol2;
437 
438                     aSortParam.bHasHeader		= bHasHeader;
439                     aSortParam.bByRow			= sal_True;
440                     aSortParam.bCaseSens		= sal_False;
441                     aSortParam.bIncludePattern	= sal_True;
442                     aSortParam.bInplace 		= sal_True;
443                     aSortParam.bDoSort[0]		= sal_True;
444                     aSortParam.nField[0]		= nCol;
445                     aSortParam.bAscending[0]	= (nSlotId == SID_SORT_ASCENDING);
446 
447                     for ( sal_uInt16 i=1; i<MAXSORT; i++ )
448                         aSortParam.bDoSort[i] = sal_False;
449 
450                     aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) );
451 
452                     pTabViewShell->UISort( aSortParam );		// Teilergebnisse bei Bedarf neu
453 
454                     rReq.Done();
455                 }
456             }
457             break;
458 
459         case SID_SORT:
460             {
461                 const SfxItemSet* pArgs = rReq.GetArgs();
462 
463                 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
464                 //the patch comes from maoyg
465 
466                 if ( pArgs )		// Basic
467                 {
468                     ScSortParam aSortParam;
469                     ScDBData*	pDBData = pTabViewShell->GetDBData();
470                     ScViewData* pData   = GetViewData();
471 
472                     pDBData->GetSortParam( aSortParam );
473 
474                     if( lcl_GetSortParam( pData, aSortParam ) )
475                     {
476                         ScDocument* pDoc = GetViewData()->GetDocument();
477 
478                         pDBData->GetSortParam( aSortParam );
479                         sal_Bool bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() );
480                         if( bHasHeader )
481                             aSortParam.bHasHeader = bHasHeader;
482 
483                         aSortParam.bInplace = sal_True;				// von Basic immer
484 
485                         const SfxPoolItem* pItem;
486                         if ( pArgs->GetItemState( SID_SORT_BYROW, sal_True, &pItem ) == SFX_ITEM_SET )
487                             aSortParam.bByRow = ((const SfxBoolItem*)pItem)->GetValue();
488                         if ( pArgs->GetItemState( SID_SORT_HASHEADER, sal_True, &pItem ) == SFX_ITEM_SET )
489                             aSortParam.bHasHeader = ((const SfxBoolItem*)pItem)->GetValue();
490                         if ( pArgs->GetItemState( SID_SORT_CASESENS, sal_True, &pItem ) == SFX_ITEM_SET )
491                             aSortParam.bCaseSens = ((const SfxBoolItem*)pItem)->GetValue();
492                         if ( pArgs->GetItemState( SID_SORT_ATTRIBS, sal_True, &pItem ) == SFX_ITEM_SET )
493                             aSortParam.bIncludePattern = ((const SfxBoolItem*)pItem)->GetValue();
494                         if ( pArgs->GetItemState( SID_SORT_USERDEF, sal_True, &pItem ) == SFX_ITEM_SET )
495                         {
496                             sal_uInt16 nUserIndex = ((const SfxUInt16Item*)pItem)->GetValue();
497                             aSortParam.bUserDef = ( nUserIndex != 0 );
498                             if ( nUserIndex )
499                                 aSortParam.nUserIndex = nUserIndex - 1;		// Basic: 1-basiert
500                         }
501 
502                         SCCOLROW nField0 = 0;
503                         if ( pArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) == SFX_ITEM_SET )
504                             nField0 = ((const SfxInt32Item*)pItem)->GetValue();
505                         aSortParam.bDoSort[0] = ( nField0 != 0 );
506                         aSortParam.nField[0] = nField0 > 0 ? (nField0-1) : 0;
507                         if ( pArgs->GetItemState( FN_PARAM_2, sal_True, &pItem ) == SFX_ITEM_SET )
508                             aSortParam.bAscending[0] = ((const SfxBoolItem*)pItem)->GetValue();
509                         SCCOLROW nField1 = 0;
510                         if ( pArgs->GetItemState( FN_PARAM_3, sal_True, &pItem ) == SFX_ITEM_SET )
511                             nField1 = ((const SfxInt32Item*)pItem)->GetValue();
512                         aSortParam.bDoSort[1] = ( nField1 != 0 );
513                         aSortParam.nField[1] = nField1 > 0 ? (nField1-1) : 0;
514                         if ( pArgs->GetItemState( FN_PARAM_4, sal_True, &pItem ) == SFX_ITEM_SET )
515                             aSortParam.bAscending[1] = ((const SfxBoolItem*)pItem)->GetValue();
516                         SCCOLROW nField2 = 0;
517                         if ( pArgs->GetItemState( FN_PARAM_5, sal_True, &pItem ) == SFX_ITEM_SET )
518                             nField2 = ((const SfxInt32Item*)pItem)->GetValue();
519                         aSortParam.bDoSort[2] = ( nField2 != 0 );
520                         aSortParam.nField[2] = nField2 > 0 ? (nField2-1) : 0;
521                         if ( pArgs->GetItemState( FN_PARAM_6, sal_True, &pItem ) == SFX_ITEM_SET )
522                             aSortParam.bAscending[2] = ((const SfxBoolItem*)pItem)->GetValue();
523 
524                         // Teilergebnisse bei Bedarf neu
525                         pTabViewShell->UISort( aSortParam );
526                         rReq.Done();
527                     }
528                 }
529                 else
530                 {
531                     ScSortParam aSortParam;
532                     ScDBData*	pDBData = pTabViewShell->GetDBData();
533                     ScViewData* pData   = GetViewData();
534 
535                     pDBData->GetSortParam( aSortParam );
536 
537                     if( lcl_GetSortParam( pData, aSortParam ) )
538                     {
539                         SfxAbstractTabDialog* pDlg = NULL;
540                         ScDocument* pDoc = GetViewData()->GetDocument();
541                         SfxItemSet	aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA );
542 
543                         pDBData->GetSortParam( aSortParam );
544                         sal_Bool bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() );
545                         if( bHasHeader )
546                             aSortParam.bHasHeader = bHasHeader;
547 
548                         aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) );
549 
550                         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
551                         DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
552 
553                         pDlg = pFact->CreateScSortDlg( pTabViewShell->GetDialogParent(),  &aArgSet, RID_SCDLG_SORT );
554                         DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
555                         pDlg->SetCurPageId(1);
556 
557                         if ( pDlg->Execute() == RET_OK )
558                         {
559                             const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
560                             const ScSortParam& rOutParam = ((const ScSortItem&)
561                                 pOutSet->Get( SCITEM_SORTDATA )).GetSortData();
562 
563                             // Teilergebnisse bei Bedarf neu
564                             pTabViewShell->UISort( rOutParam );
565 
566                             if ( rOutParam.bInplace )
567                             {
568                                 rReq.AppendItem( SfxBoolItem( SID_SORT_BYROW,
569                                     rOutParam.bByRow ) );
570                                 rReq.AppendItem( SfxBoolItem( SID_SORT_HASHEADER,
571                                     rOutParam.bHasHeader ) );
572                                 rReq.AppendItem( SfxBoolItem( SID_SORT_CASESENS,
573                                     rOutParam.bCaseSens ) );
574                                 rReq.AppendItem( SfxBoolItem( SID_SORT_ATTRIBS,
575                                     rOutParam.bIncludePattern ) );
576                                 sal_uInt16 nUser = rOutParam.bUserDef ? ( rOutParam.nUserIndex + 1 ) : 0;
577                                 rReq.AppendItem( SfxUInt16Item( SID_SORT_USERDEF, nUser ) );
578                                 if ( rOutParam.bDoSort[0] )
579                                 {
580                                     rReq.AppendItem( SfxInt32Item( FN_PARAM_1,
581                                         rOutParam.nField[0] + 1 ) );
582                                     rReq.AppendItem( SfxBoolItem( FN_PARAM_2,
583                                         rOutParam.bAscending[0] ) );
584                                 }
585                                 if ( rOutParam.bDoSort[1] )
586                                 {
587                                     rReq.AppendItem( SfxInt32Item( FN_PARAM_3,
588                                         rOutParam.nField[1] + 1 ) );
589                                     rReq.AppendItem( SfxBoolItem( FN_PARAM_4,
590                                         rOutParam.bAscending[1] ) );
591                                 }
592                                 if ( rOutParam.bDoSort[2] )
593                                 {
594                                     rReq.AppendItem( SfxInt32Item( FN_PARAM_5,
595                                         rOutParam.nField[2] + 1 ) );
596                                     rReq.AppendItem( SfxBoolItem( FN_PARAM_6,
597                                         rOutParam.bAscending[2] ) );
598                                 }
599                             }
600 
601                             rReq.Done();
602                         }
603                         else
604                             GetViewData()->GetDocShell()->CancelAutoDBRange();
605 
606                         delete pDlg;
607                     }
608                 }
609             }
610             break;
611 
612 		case SID_FILTER:
613 			{
614 				const SfxItemSet* pArgs = rReq.GetArgs();
615 				if ( pArgs )
616 				{
617 					DBG_ERROR("SID_FILTER with arguments?");
618 					pTabViewShell->Query( ((const ScQueryItem&)
619 							pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), NULL, sal_True );
620 					rReq.Done();
621 				}
622 				else
623 				{
624 					sal_uInt16			nId  = ScFilterDlgWrapper::GetChildWindowId();
625 					SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
626 					SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
627 
628 					pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
629 				}
630 			}
631 			break;
632 
633 		case SID_SPECIAL_FILTER:
634 			{
635 				const SfxItemSet* pArgs = rReq.GetArgs();
636 				if ( pArgs )
637 				{
638 					DBG_ERROR("SID_SPECIAL_FILTER with arguments?");
639 					pTabViewShell->Query( ((const ScQueryItem&)
640 							pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), NULL, sal_True );
641 					rReq.Done();
642 				}
643 				else
644 				{
645 					sal_uInt16			nId  = ScSpecialFilterDlgWrapper::GetChildWindowId();
646 					SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
647 					SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
648 
649 					pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
650 				}
651 			}
652 			break;
653 
654 		case FID_FILTER_OK:
655 			{
656                 const SfxPoolItem* pItem;
657                 if ( pReqArgs && SFX_ITEM_SET ==
658                         pReqArgs->GetItemState( SCITEM_QUERYDATA, sal_True, &pItem ) )
659                 {
660                     const ScQueryItem& rQueryItem = static_cast<const ScQueryItem&>(*pItem);
661 
662                     SCTAB nCurTab = GetViewData()->GetTabNo();
663                     SCTAB nRefTab = GetViewData()->GetRefTabNo();
664 
665                     // If RefInput switched to a different sheet from the data sheet,
666                     // switch back:
667 
668                     if ( nCurTab != nRefTab )
669                     {
670                         pTabViewShell->SetTabNo( nRefTab );
671                         pTabViewShell->PaintExtras();
672                     }
673 
674                     ScRange aAdvSource;
675                     if (rQueryItem.GetAdvancedQuerySource(aAdvSource))
676                         pTabViewShell->Query( rQueryItem.GetQueryData(), &aAdvSource, sal_True );
677                     else
678                         pTabViewShell->Query( rQueryItem.GetQueryData(), NULL, sal_True );
679                     rReq.Done( *pReqArgs );
680                 }
681 			}
682 			break;
683 
684 		case SID_UNFILTER:
685 			{
686 				ScQueryParam aParam;
687 				ScDBData*	 pDBData = pTabViewShell->GetDBData();
688 
689 				pDBData->GetQueryParam( aParam );
690 				SCSIZE nEC = aParam.GetEntryCount();
691 				for (SCSIZE i=0; i<nEC; i++)
692 					aParam.GetEntry(i).bDoQuery = sal_False;
693 				aParam.bDuplicate = sal_True;
694 				pTabViewShell->Query( aParam, NULL, sal_True );
695 				rReq.Done();
696 			}
697 			break;
698 
699 		case SID_AUTO_FILTER:
700 			pTabViewShell->ToggleAutoFilter();
701 			rReq.Done();
702 			break;
703 
704 		case SID_AUTOFILTER_HIDE:
705 			pTabViewShell->HideAutoFilter();
706 			rReq.Done();
707 			break;
708 
709 		case SID_PIVOT_TABLE:
710 			{
711 				const SfxPoolItem* pItem;
712 				if ( pReqArgs && SFX_ITEM_SET ==
713 						pReqArgs->GetItemState( SCITEM_PIVOTDATA, sal_True, &pItem ) )
714 				{
715 					SCTAB nCurTab = GetViewData()->GetTabNo();
716 					SCTAB nRefTab = GetViewData()->GetRefTabNo();
717 
718 					// Wenn RefInput auf andere Tabelle als Datentabelle umgeschaltet
719 					// hat wieder zurueckschalten:
720 
721 					if ( nCurTab != nRefTab )
722 					{
723 						pTabViewShell->SetTabNo( nRefTab );
724 						pTabViewShell->PaintExtras();
725 					}
726 
727 					const ScDPObject* pDPObject = pTabViewShell->GetDialogDPObject();
728 					if ( pDPObject )
729 					{
730 						const ScPivotItem* pPItem = (const ScPivotItem*)pItem;
731                         bool bSuccess = pTabViewShell->MakePivotTable(
732                             pPItem->GetData(), pPItem->GetDestRange(), pPItem->IsNewSheet(), *pDPObject );
733                         SfxBoolItem aRet(0, bSuccess);
734                         rReq.SetReturnValue(aRet);
735 					}
736 					rReq.Done();
737 				}
738 				else if (rReq.IsAPI())
739 					SbxBase::SetError(SbxERR_BAD_PARAMETER);
740 			}
741 			break;
742 
743 		case SID_OPENDLG_PIVOTTABLE:
744 			{
745 				ScViewData* pData = GetViewData();
746 				ScDocument* pDoc = pData->GetDocument();
747 
748 				ScDPObject* pNewDPObject = NULL;
749 
750 				// ScPivot is no longer used...
751 				ScDPObject* pDPObj = pDoc->GetDPAtCursor(
752 											pData->GetCurX(), pData->GetCurY(),
753 											pData->GetTabNo() );
754 				if ( pDPObj )	// on an existing table?
755 				{
756 					pNewDPObject = new ScDPObject( *pDPObj );
757 				}
758 				else	 		// create new table
759 				{
760 					//	select database range or data
761 					pTabViewShell->GetDBData( sal_True, SC_DB_OLD );
762                     ScMarkData& rMark = GetViewData()->GetMarkData();
763 					if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
764 						pTabViewShell->MarkDataArea( sal_False );
765 
766 					//	output to cursor position for non-sheet data
767 					ScAddress aDestPos( pData->GetCurX(), pData->GetCurY(),
768 											pData->GetTabNo() );
769 
770 					//	first select type of source data
771 
772 					sal_Bool bEnableExt = ScDPObject::HasRegisteredSources();
773 					//CHINA001 ScDataPilotSourceTypeDlg* pTypeDlg = new ScDataPilotSourceTypeDlg(
774 					//CHINA001 							pTabViewShell->GetDialogParent(), bEnableExt );
775 
776 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
777 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
778 
779 					AbstractScDataPilotSourceTypeDlg* pTypeDlg = pFact->CreateScDataPilotSourceTypeDlg( pTabViewShell->GetDialogParent(), bEnableExt, RID_SCDLG_DAPITYPE );
780 					DBG_ASSERT(pTypeDlg, "Dialog create fail!");//CHINA001
781 					if ( pTypeDlg->Execute() == RET_OK )
782 					{
783 						if ( pTypeDlg->IsExternal() )
784 						{
785 							uno::Sequence<rtl::OUString> aSources = ScDPObject::GetRegisteredSources();
786 							//CHINA001 ScDataPilotServiceDlg* pServDlg = new ScDataPilotServiceDlg(
787 							//CHINA001 					pTabViewShell->GetDialogParent(), aSources );
788 							AbstractScDataPilotServiceDlg* pServDlg = pFact->CreateScDataPilotServiceDlg( pTabViewShell->GetDialogParent(), aSources, RID_SCDLG_DAPISERVICE );
789 							DBG_ASSERT(pServDlg, "Dialog create fail!");//CHINA001
790 							if ( pServDlg->Execute() == RET_OK )
791 							{
792 								ScDPServiceDesc aServDesc(
793 										pServDlg->GetServiceName(),
794 										pServDlg->GetParSource(),
795 										pServDlg->GetParName(),
796 										pServDlg->GetParUser(),
797 										pServDlg->GetParPass() );
798 								pNewDPObject = new ScDPObject( pDoc );
799 								pNewDPObject->SetServiceData( aServDesc );
800 							}
801 							delete pServDlg;
802 						}
803 						else if ( pTypeDlg->IsDatabase() )
804 						{
805 							//CHINA001 ScDataPilotDatabaseDlg* pDataDlg = new ScDataPilotDatabaseDlg(
806 							//CHINA001 								pTabViewShell->GetDialogParent() );
807                             //ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
808 							DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
809 
810 							AbstractScDataPilotDatabaseDlg* pDataDlg = pFact->CreateScDataPilotDatabaseDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_DAPIDATA);
811 							DBG_ASSERT(pDataDlg, "Dialog create fail!");//CHINA001
812 							if ( pDataDlg->Execute() == RET_OK )
813 							{
814 								ScImportSourceDesc aImpDesc;
815 								pDataDlg->GetValues( aImpDesc );
816 								pNewDPObject = new ScDPObject( pDoc );
817 								pNewDPObject->SetImportDesc( aImpDesc );
818 							}
819 							delete pDataDlg;
820 						}
821 						else		// selection
822 						{
823 							//!	use database ranges (select before type dialog?)
824 							ScRange aRange;
825                             ScMarkType eType = GetViewData()->GetSimpleArea(aRange);
826                             if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
827 							{
828                                 // Shrink the range to the data area.
829                                 SCCOL nStartCol = aRange.aStart.Col(), nEndCol = aRange.aEnd.Col();
830                                 SCROW nStartRow = aRange.aStart.Row(), nEndRow = aRange.aEnd.Row();
831                                 if (pDoc->ShrinkToDataArea(aRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow))
832                                 {
833                                     aRange.aStart.SetCol(nStartCol);
834                                     aRange.aStart.SetRow(nStartRow);
835                                     aRange.aEnd.SetCol(nEndCol);
836                                     aRange.aEnd.SetRow(nEndRow);
837                                     rMark.SetMarkArea(aRange);
838                                     pTabViewShell->MarkRange(aRange);
839                                 }
840 
841 								sal_Bool bOK = sal_True;
842 								if ( pDoc->HasSubTotalCells( aRange ) )
843 								{
844 									//	confirm selection if it contains SubTotal cells
845 
846 									QueryBox aBox( pTabViewShell->GetDialogParent(),
847 													WinBits(WB_YES_NO | WB_DEF_YES),
848 													ScGlobal::GetRscString(STR_DATAPILOT_SUBTOTAL) );
849 									if (aBox.Execute() == RET_NO)
850 										bOK = sal_False;
851 								}
852 								if (bOK)
853 								{
854 									ScSheetSourceDesc aShtDesc;
855 									aShtDesc.aSourceRange = aRange;
856 									pNewDPObject = new ScDPObject( pDoc );
857 									pNewDPObject->SetSheetDesc( aShtDesc );
858 
859 									//	output below source data
860 									if ( aRange.aEnd.Row()+2 <= MAXROW - 4 )
861 										aDestPos = ScAddress( aRange.aStart.Col(),
862 																aRange.aEnd.Row()+2,
863 																aRange.aStart.Tab() );
864 								}
865 							}
866 						}
867 					}
868 					delete pTypeDlg;
869 
870 					if ( pNewDPObject )
871 						pNewDPObject->SetOutRange( aDestPos );
872 
873 #if 0
874 					ScDBData*	pDBData = pTabViewShell->GetDBData();
875 					String		aErrMsg;
876 
877 					pDBData->GetArea( nTab, nCol1, nRow1, nCol2, nRow2 );
878 
879 					bAreaOk = sal_True;
880 					if ( nRow2-nRow1 < 1 )
881 					{
882 						// "mindestens eine Datenzeile"
883 						pTabViewShell->ErrorMessage(STR_PIVOT_INVALID_DBAREA);
884 						bAreaOk = sal_False;
885 					}
886 					else if (!pDBData->HasHeader())
887 					{
888 						if ( MessBox( pTabViewShell->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
889 								ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ),		// "StarCalc"
890 								ScGlobal::GetRscString( STR_MSSG_MAKEAUTOFILTER_0 ) 	// Koepfe aus erster Zeile?
891 							).Execute() == RET_YES )
892 						{
893 							pDBData->SetHeader( sal_True ); 	//! Undo ??
894 						}
895 						else
896 							bAreaOk = sal_False;
897 					}
898 #endif
899 				}
900 
901 				pTabViewShell->SetDialogDPObject( pNewDPObject );	// is copied
902 				if ( pNewDPObject )
903 				{
904 					//	start layout dialog
905 
906 					sal_uInt16 nId  = ScPivotLayoutWrapper::GetChildWindowId();
907 					SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
908 					SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
909 					pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
910 				}
911 				delete pNewDPObject;
912 			}
913 			break;
914 
915 		case SID_DEFINE_DBNAME:
916 			{
917 
918 				sal_uInt16			nId  = ScDbNameDlgWrapper::GetChildWindowId();
919 				SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
920 				SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
921 
922 				pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
923 
924 			}
925 			break;
926 
927 		case SID_SELECT_DB:
928 			{
929 				if ( pReqArgs )
930 				{
931 					const SfxStringItem* pItem =
932 						(const SfxStringItem*)&pReqArgs->Get( SID_SELECT_DB );
933 
934 					if( pItem )
935 					{
936 						pTabViewShell->GotoDBArea( pItem->GetValue() );
937 						rReq.Done();
938 					}
939 					else
940 					{
941 						DBG_ERROR("NULL");
942 					}
943 				}
944 				else
945 				{
946 					ScDocument* 	pDoc   = GetViewData()->GetDocument();
947 					ScDBCollection* pDBCol = pDoc->GetDBCollection();
948 
949 					if ( pDBCol )
950 					{
951 						const String	aStrNoName( ScGlobal::GetRscString(STR_DB_NONAME) );
952 						List			aList;
953 						sal_uInt16			nDBCount = pDBCol->GetCount();
954 						ScDBData*		pDbData  = NULL;
955 						String*			pDBName  = NULL;
956 
957 						for ( sal_uInt16 i=0; i < nDBCount; i++ )
958 						{
959 							pDbData = (ScDBData*)(pDBCol->At( i ));
960 							if ( pDbData )
961 							{
962 								pDBName = new String;
963 								pDbData->GetName( *pDBName );
964 
965 								if ( *pDBName != aStrNoName )
966 									aList.Insert( pDBName );
967 								else
968 									DELETEZ(pDBName);
969 							}
970 						}
971 
972 //CHINA001						ScSelEntryDlg* pDlg =
973 //CHINA001						new ScSelEntryDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_SELECTDB,
974 //CHINA001						String(ScResId(SCSTR_SELECTDB)),
975 //CHINA001						String(ScResId(SCSTR_AREAS)),
976 //CHINA001						aList );
977 						ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
978 						DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
979 
980 						AbstractScSelEntryDlg* pDlg = pFact->CreateScSelEntryDlg( pTabViewShell->GetDialogParent(),
981 																				RID_SCDLG_SELECTDB,
982 																				String(ScResId(SCSTR_SELECTDB)),
983 																				String(ScResId(SCSTR_AREAS)),
984 																				aList,
985 																				RID_SCDLG_SELECTDB);
986 						DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
987 						if ( pDlg->Execute() == RET_OK )
988 						{
989 							String aName = pDlg->GetSelectEntry();
990 							pTabViewShell->GotoDBArea( aName );
991 							rReq.AppendItem( SfxStringItem( SID_SELECT_DB, aName ) );
992 							rReq.Done();
993 						}
994 
995 						delete pDlg;
996 
997 						void* pEntry = aList.First();
998 						while ( pEntry )
999 						{
1000 							delete (String*) aList.Remove( pEntry );
1001 							pEntry = aList.Next();
1002 						}
1003 					}
1004 				}
1005 			}
1006 			break;
1007 
1008 		case FID_VALIDATION:
1009 			{
1010 				const SfxPoolItem* pItem;
1011 				const SfxItemSet* pArgs = rReq.GetArgs();
1012 				if ( pArgs )
1013 				{
1014 					DBG_ERROR("spaeter...");
1015 				}
1016 				else
1017 				{
1018                     //CHINA001 SfxItemSet aArgSet( GetPool(), ScTPValidationValue::GetRanges() );
1019 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1020 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1021 					::GetTabPageRanges ScTPValidationValueGetRanges = pFact->GetTabPageRangesFunc(TP_VALIDATION_VALUES);
1022 					DBG_ASSERT(ScTPValidationValueGetRanges, "TabPage create fail!");//CHINA001
1023 					SfxItemSet aArgSet( GetPool(), (*ScTPValidationValueGetRanges)() );//CHINA001
1024 					ScValidationMode eMode = SC_VALID_ANY;
1025 					ScConditionMode eOper = SC_COND_EQUAL;
1026 					String aExpr1, aExpr2;
1027 					sal_Bool bBlank = sal_True;
1028                     sal_Int16 nListType = ValidListType::UNSORTED;
1029 					sal_Bool bShowHelp = sal_False;
1030 					String aHelpTitle, aHelpText;
1031 					sal_Bool bShowError = sal_False;
1032 					ScValidErrorStyle eErrStyle = SC_VALERR_STOP;
1033 					String aErrTitle, aErrText;
1034 
1035 					ScDocument* pDoc = GetViewData()->GetDocument();
1036 					SCCOL nCurX = GetViewData()->GetCurX();
1037 					SCROW nCurY = GetViewData()->GetCurY();
1038 					SCTAB nTab = GetViewData()->GetTabNo();
1039 					ScAddress aCursorPos( nCurX, nCurY, nTab );
1040 					sal_uLong nIndex = ((SfxUInt32Item*)pDoc->GetAttr(
1041 								nCurX, nCurY, nTab, ATTR_VALIDDATA ))->GetValue();
1042 					if ( nIndex )
1043 					{
1044 						const ScValidationData*	pOldData = pDoc->GetValidationEntry( nIndex );
1045 						if ( pOldData )
1046 						{
1047 							eMode = pOldData->GetDataMode();
1048 							eOper = pOldData->GetOperation();
1049 							sal_uLong nNumFmt = 0;
1050 							if ( eMode == SC_VALID_DATE || eMode == SC_VALID_TIME )
1051 							{
1052 								short nType = ( eMode == SC_VALID_DATE ) ? NUMBERFORMAT_DATE
1053 																		 : NUMBERFORMAT_TIME;
1054 								nNumFmt = pDoc->GetFormatTable()->GetStandardFormat(
1055 																	nType, ScGlobal::eLnge );
1056 							}
1057 							aExpr1 = pOldData->GetExpression( aCursorPos, 0, nNumFmt );
1058 							aExpr2 = pOldData->GetExpression( aCursorPos, 1, nNumFmt );
1059 							bBlank = pOldData->IsIgnoreBlank();
1060                             nListType = pOldData->GetListType();
1061 
1062 							bShowHelp = pOldData->GetInput( aHelpTitle, aHelpText );
1063 							bShowError = pOldData->GetErrMsg( aErrTitle, aErrText, eErrStyle );
1064 
1065                             aArgSet.Put( SfxAllEnumItem( FID_VALID_MODE,        sal::static_int_cast<sal_uInt16>(eMode) ) );
1066                             aArgSet.Put( SfxAllEnumItem( FID_VALID_CONDMODE,    sal::static_int_cast<sal_uInt16>(eOper) ) );
1067 							aArgSet.Put( SfxStringItem(	 FID_VALID_VALUE1,		aExpr1 ) );
1068 							aArgSet.Put( SfxStringItem(	 FID_VALID_VALUE2,		aExpr2 ) );
1069 							aArgSet.Put( SfxBoolItem(	 FID_VALID_BLANK,		bBlank ) );
1070                             aArgSet.Put( SfxInt16Item(   FID_VALID_LISTTYPE,    nListType ) );
1071 							aArgSet.Put( SfxBoolItem(	 FID_VALID_SHOWHELP,	bShowHelp ) );
1072 							aArgSet.Put( SfxStringItem(	 FID_VALID_HELPTITLE,	aHelpTitle ) );
1073 							aArgSet.Put( SfxStringItem(	 FID_VALID_HELPTEXT,	aHelpText ) );
1074 							aArgSet.Put( SfxBoolItem(	 FID_VALID_SHOWERR,		bShowError ) );
1075                             aArgSet.Put( SfxAllEnumItem( FID_VALID_ERRSTYLE,    sal::static_int_cast<sal_uInt16>(eErrStyle) ) );
1076 							aArgSet.Put( SfxStringItem(  FID_VALID_ERRTITLE,	aErrTitle ) );
1077 							aArgSet.Put( SfxStringItem(  FID_VALID_ERRTEXT,		aErrText ) );
1078 						}
1079 					}
1080 
1081 					//CHINA001 ScValidationDlg* pDlg = new ScValidationDlg( NULL, &aArgSet );
1082 					//CHINA001 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1083 					//CHINA001 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1084 
1085 					//<!--Modified by PengYunQuan for Validity Cell Range Picker
1086 					//SfxAbstractTabDialog* pDlg = pFact->CreateScValidationDlg( NULL, &aArgSet, TAB_DLG_VALIDATION );
1087 					SfxAbstractTabDialog* pDlg = pFact->CreateScValidationDlg( NULL, &aArgSet, TAB_DLG_VALIDATION, pTabViewShell );
1088 					//-->Modified by PengYunQuan for Validity Cell Range Picker
1089 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1090 
1091 					//<!--Modified by PengYunQuan for Validity Cell Range Picker
1092 					//if ( pDlg->Execute() == RET_OK )
1093 					short nResult = pDlg->Execute();
1094 					pTabViewShell->SetTabNo( nTab );//When picking Cell Range ,other Tab may be switched. Need restore the correct tab
1095 					if ( nResult == RET_OK )
1096 					//-->Modified by PengYunQuan for Validity Cell Range Picker
1097 					{
1098 						const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1099 
1100 						if ( pOutSet->GetItemState( FID_VALID_MODE, sal_True, &pItem ) == SFX_ITEM_SET )
1101 							eMode = (ScValidationMode) ((const SfxAllEnumItem*)pItem)->GetValue();
1102 						if ( pOutSet->GetItemState( FID_VALID_CONDMODE, sal_True, &pItem ) == SFX_ITEM_SET )
1103 							eOper = (ScConditionMode) ((const SfxAllEnumItem*)pItem)->GetValue();
1104 						if ( pOutSet->GetItemState( FID_VALID_VALUE1, sal_True, &pItem ) == SFX_ITEM_SET )
1105                         {
1106                             String aTemp1 = ((const SfxStringItem*)pItem)->GetValue();
1107                             if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
1108                             {
1109                                 sal_uInt32 nNumIndex = 0;
1110                                 double nVal;
1111                                 if (pDoc->GetFormatTable()->IsNumberFormat(aTemp1, nNumIndex, nVal))
1112                                     aExpr1 =String( ::rtl::math::doubleToUString( nVal,
1113                                             rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
1114                                             ScGlobal::pLocaleData->getNumDecimalSep().GetChar(0), sal_True));
1115                                 else
1116                                     aExpr1 = aTemp1;
1117                             }
1118                             else
1119                                 aExpr1 = aTemp1;
1120                         }
1121 						if ( pOutSet->GetItemState( FID_VALID_VALUE2, sal_True, &pItem ) == SFX_ITEM_SET )
1122                         {
1123                             String aTemp2 = ((const SfxStringItem*)pItem)->GetValue();
1124                             if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
1125                             {
1126                                 sal_uInt32 nNumIndex = 0;
1127                                 double nVal;
1128                                 if (pDoc->GetFormatTable()->IsNumberFormat(aTemp2, nNumIndex, nVal))
1129                                     aExpr2 =String( ::rtl::math::doubleToUString( nVal,
1130                                             rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
1131                                             ScGlobal::pLocaleData->getNumDecimalSep().GetChar(0), sal_True));
1132                                 else
1133                                     aExpr2 = aTemp2;
1134                             }
1135                             else
1136                                 aExpr2 = aTemp2;
1137                         }
1138 
1139 						if ( pOutSet->GetItemState( FID_VALID_BLANK, sal_True, &pItem ) == SFX_ITEM_SET )
1140 							bBlank = ((const SfxBoolItem*)pItem)->GetValue();
1141                         if ( pOutSet->GetItemState( FID_VALID_LISTTYPE, sal_True, &pItem ) == SFX_ITEM_SET )
1142                             nListType = ((const SfxInt16Item*)pItem)->GetValue();
1143 
1144 						if ( pOutSet->GetItemState( FID_VALID_SHOWHELP, sal_True, &pItem ) == SFX_ITEM_SET )
1145 							bShowHelp = ((const SfxBoolItem*)pItem)->GetValue();
1146 						if ( pOutSet->GetItemState( FID_VALID_HELPTITLE, sal_True, &pItem ) == SFX_ITEM_SET )
1147 							aHelpTitle = ((const SfxStringItem*)pItem)->GetValue();
1148 						if ( pOutSet->GetItemState( FID_VALID_HELPTEXT, sal_True, &pItem ) == SFX_ITEM_SET )
1149 							aHelpText = ((const SfxStringItem*)pItem)->GetValue();
1150 
1151 						if ( pOutSet->GetItemState( FID_VALID_SHOWERR, sal_True, &pItem ) == SFX_ITEM_SET )
1152 							bShowError = ((const SfxBoolItem*)pItem)->GetValue();
1153 						if ( pOutSet->GetItemState( FID_VALID_ERRSTYLE, sal_True, &pItem ) == SFX_ITEM_SET )
1154 							eErrStyle = (ScValidErrorStyle) ((const SfxAllEnumItem*)pItem)->GetValue();
1155 						if ( pOutSet->GetItemState( FID_VALID_ERRTITLE, sal_True, &pItem ) == SFX_ITEM_SET )
1156 							aErrTitle = ((const SfxStringItem*)pItem)->GetValue();
1157 						if ( pOutSet->GetItemState( FID_VALID_ERRTEXT, sal_True, &pItem ) == SFX_ITEM_SET )
1158 							aErrText = ((const SfxStringItem*)pItem)->GetValue();
1159 
1160 						ScValidationData aData( eMode, eOper, aExpr1, aExpr2, pDoc, aCursorPos );
1161 						aData.SetIgnoreBlank( bBlank );
1162                         aData.SetListType( nListType );
1163 
1164 						aData.SetInput(aHelpTitle, aHelpText);		// sets bShowInput to TRUE
1165 						if (!bShowHelp)
1166 							aData.ResetInput();						// reset only bShowInput
1167 
1168 						aData.SetError(aErrTitle, aErrText, eErrStyle);	// sets bShowError to TRUE
1169 						if (!bShowError)
1170 							aData.ResetError();						// reset only bShowError
1171 
1172 						pTabViewShell->SetValidation( aData );
1173 						rReq.Done( *pOutSet );
1174 					}
1175 					//<!-- Modified by PengYunQuan for Validity Cell Range Picker
1176 					//after end execute from !IsModalInputMode, it is safer to delay deleting
1177 					//delete pDlg;
1178 					Application::PostUserEvent( Link( pDlg, &DelayDeleteAbstractDialog ) );
1179 					//--> Modified by PengYunQuan for Validity Cell Range Picker
1180 				}
1181 			}
1182 			break;
1183 
1184         case SID_TEXT_TO_COLUMNS:
1185             {
1186                 ScViewData* pData = GetViewData();
1187                 DBG_ASSERT( pData, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pData is null!" );
1188                 ScRange aRange;
1189 
1190                 if ( lcl_GetTextToColumnsRange( pData, aRange ) )
1191                 {
1192                     ScDocument* pDoc = pData->GetDocument();
1193                     DBG_ASSERT( pDoc, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDoc is null!" );
1194 
1195                     ScImportExport aExport( pDoc, aRange );
1196                     aExport.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::None, 0, false ) );
1197 
1198                     // #i87703# text to columns fails with tab separator
1199                     aExport.SetDelimiter( static_cast< sal_Unicode >( 0 ) );
1200 
1201                     SvMemoryStream aStream;
1202                     aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
1203                     ScImportExport::SetNoEndianSwap( aStream );
1204                     aExport.ExportStream( aStream, String(), FORMAT_STRING );
1205 
1206                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1207                     DBG_ASSERT( pFact, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pFact is null!" );
1208                     AbstractScImportAsciiDlg *pDlg = pFact->CreateScImportAsciiDlg(
1209                         NULL, String(), &aStream, RID_SCDLG_ASCII );
1210                     DBG_ASSERT( pDlg, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDlg is null!" );
1211                     pDlg->SetTextToColumnsMode();
1212 
1213                     if ( pDlg->Execute() == RET_OK )
1214                     {
1215                         ScDocShell* pDocSh = pData->GetDocShell();
1216                         DBG_ASSERT( pDocSh, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" );
1217 
1218                         String aUndo = ScGlobal::GetRscString( STR_UNDO_TEXTTOCOLUMNS );
1219                         pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
1220 
1221                         ScImportExport aImport( pDoc, aRange.aStart );
1222                         ScAsciiOptions aOptions;
1223                         pDlg->GetOptions( aOptions );
1224                         aImport.SetExtOptions( aOptions );
1225                         aImport.SetApi( false );
1226                         aStream.Seek( 0 );
1227                         aImport.ImportStream( aStream, String(), FORMAT_STRING );
1228 
1229                         pDocSh->GetUndoManager()->LeaveListAction();
1230                     }
1231                     delete pDlg;
1232                 }
1233             }
1234             break;
1235 		}
1236 }
1237 
1238 void __EXPORT ScCellShell::GetDBState( SfxItemSet& rSet )
1239 {
1240 	ScTabViewShell*	pTabViewShell  	= GetViewData()->GetViewShell();
1241     ScViewData* pData       = GetViewData();
1242 	ScDocShell*	pDocSh		= pData->GetDocShell();
1243 	ScDocument* pDoc		= pDocSh->GetDocument();
1244 	SCCOL		nPosX		= pData->GetCurX();
1245 	SCROW		nPosY		= pData->GetCurY();
1246 	SCTAB		nTab		= pData->GetTabNo();
1247 
1248     sal_Bool bAutoFilter = sal_False;
1249 	sal_Bool bAutoFilterTested = sal_False;
1250 
1251 	SfxWhichIter aIter(rSet);
1252 	sal_uInt16 nWhich = aIter.FirstWhich();
1253 	while (nWhich)
1254 	{
1255 		switch (nWhich)
1256 		{
1257 			case SID_REFRESH_DBAREA:
1258 				{
1259 					//	importierte Daten ohne Selektion
1260 					//	oder Filter,Sortierung,Teilergebis (auch ohne Import)
1261 					sal_Bool bOk = sal_False;
1262 					ScDBData* pDBData = pTabViewShell->GetDBData(sal_False,SC_DB_OLD);
1263 					if (pDBData && pDoc->GetChangeTrack() == NULL)
1264 					{
1265 						if ( pDBData->HasImportParam() )
1266 							bOk = !pDBData->HasImportSelection();
1267 						else
1268 						{
1269 							bOk = pDBData->HasQueryParam() ||
1270 								  pDBData->HasSortParam() ||
1271 								  pDBData->HasSubTotalParam();
1272 						}
1273 					}
1274 					if (!bOk)
1275 						rSet.DisableItem( nWhich );
1276 				}
1277 				break;
1278 
1279 			case SID_FILTER:
1280 			case SID_SPECIAL_FILTER:
1281 				{
1282                     ScRange aDummy;
1283                     ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy);
1284 					if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1285 					{
1286 						rSet.DisableItem( nWhich );
1287 					}
1288 				}
1289 				break;
1290 
1291 
1292 				//Bei Redlining und Multiselektion Disablen
1293 			case SID_SORT_ASCENDING:
1294 			case SID_SORT_DESCENDING:
1295 			case SCITEM_SORTDATA:
1296 			case SCITEM_SUBTDATA:
1297 			case SID_OPENDLG_PIVOTTABLE:
1298 				{
1299 					//!	move ReadOnly check to idl flags
1300 
1301 					if ( pDocSh->IsReadOnly() || pDoc->GetChangeTrack()!=NULL ||
1302 							GetViewData()->IsMultiMarked() )
1303 					{
1304 						rSet.DisableItem( nWhich );
1305 					}
1306 				}
1307 				break;
1308 
1309 			case SID_REIMPORT_DATA:
1310 				{
1311 					//	nur importierte Daten ohne Selektion
1312 					ScDBData* pDBData = pTabViewShell->GetDBData(sal_False,SC_DB_OLD);
1313 					if (!pDBData || !pDBData->HasImportParam() || pDBData->HasImportSelection() ||
1314 						pDoc->GetChangeTrack()!=NULL)
1315 					{
1316 						rSet.DisableItem( nWhich );
1317 					}
1318 				}
1319 				break;
1320 
1321 			case SID_VIEW_DATA_SOURCE_BROWSER:
1322 				{
1323                     if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
1324                         rSet.Put(SfxVisibilityItem(nWhich, sal_False));
1325                     else
1326 					    //	get state (BoolItem) from SfxViewFrame
1327 					    pTabViewShell->GetViewFrame()->GetSlotState( nWhich, NULL, &rSet );
1328 				}
1329 				break;
1330 			case SID_SBA_BRW_INSERT:
1331 				{
1332 					//	SBA will ein sal_Bool-Item, damit ueberhaupt enabled
1333 
1334 					sal_Bool bEnable = sal_True;
1335 					rSet.Put(SfxBoolItem(nWhich, bEnable));
1336 				}
1337 				break;
1338 
1339 			case SID_AUTO_FILTER:
1340 			case SID_AUTOFILTER_HIDE:
1341 				{
1342 					if (!bAutoFilterTested)
1343 					{
1344 						bAutoFilter = pDoc->HasAutoFilter( nPosX, nPosY, nTab );
1345 						bAutoFilterTested = sal_True;
1346 					}
1347 					if ( nWhich == SID_AUTO_FILTER )
1348 					{
1349                         ScRange aDummy;
1350                         ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy);
1351                         if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1352 						{
1353 							rSet.DisableItem( nWhich );
1354 						}
1355 						else if (pDoc->GetDPAtBlock(aDummy))
1356                         {
1357                             rSet.DisableItem( nWhich );
1358                         }
1359                         else
1360 							rSet.Put( SfxBoolItem( nWhich, bAutoFilter ) );
1361 					}
1362 					else
1363 						if (!bAutoFilter)
1364 							rSet.DisableItem( nWhich );
1365 				}
1366 				break;
1367 
1368 			case SID_UNFILTER:
1369 				{
1370                     SCCOL nStartCol, nEndCol;
1371                     SCROW  nStartRow, nEndRow;
1372                     SCTAB  nStartTab, nEndTab;
1373                     sal_Bool bAnyQuery = sal_False;
1374 
1375                     sal_Bool bSelected = (GetViewData()->GetSimpleArea(
1376                                 nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab )
1377                             == SC_MARK_SIMPLE);
1378 
1379 					if ( bSelected )
1380 					{
1381 						if (nStartCol==nEndCol && nStartRow==nEndRow)
1382 							bSelected = sal_False;
1383 					}
1384 					else
1385 					{
1386 						nStartCol = GetViewData()->GetCurX();
1387 						nStartRow = GetViewData()->GetCurY();
1388 						nStartTab = GetViewData()->GetTabNo();
1389 					}
1390 
1391 					ScDBData* pDBData = bSelected
1392 								? pDoc->GetDBAtArea( nStartTab, nStartCol, nStartRow, nEndCol, nEndRow )
1393 								: pDoc->GetDBAtCursor( nStartCol, nStartRow, nStartTab );
1394 
1395 					if ( pDBData )
1396 					{
1397 						ScQueryParam aParam;
1398 						pDBData->GetQueryParam( aParam );
1399 						if ( aParam.GetEntry(0).bDoQuery )
1400 							bAnyQuery = sal_True;
1401 					}
1402 
1403 					if ( !bAnyQuery )
1404 						rSet.DisableItem( nWhich );
1405 				}
1406 				break;
1407 
1408             case SID_DEFINE_DBNAME:
1409                 {
1410                     if ( pDocSh && pDocSh->IsDocShared() )
1411                     {
1412                         rSet.DisableItem( nWhich );
1413                     }
1414                 }
1415                 break;
1416 
1417             case SID_TEXT_TO_COLUMNS:
1418                 {
1419                     ScRange aRange;
1420                     if ( !lcl_GetTextToColumnsRange( pData, aRange ) )
1421                     {
1422                         rSet.DisableItem( nWhich );
1423                     }
1424                 }
1425                 break;
1426 		}
1427 		nWhich = aIter.NextWhich();
1428 	}
1429 }
1430 
1431 
1432 
1433