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