Update ooo320-m1
[ooovba.git] / sc / source / ui / view / cellsh2.cxx
bloba54ea7444c0c70b953e55ab690eb01b7760f0fc3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cellsh2.cxx,v $
10 * $Revision: 1.34.24.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------
38 // INCLUDE ---------------------------------------------------------------
40 #include "scitems.hxx"
41 #include <sfx2/viewfrm.hxx>
42 #include <sfx2/app.hxx>
43 #include <sfx2/request.hxx>
44 #include <svtools/aeitem.hxx>
45 #include <basic/sbxcore.hxx>
46 #include <svtools/whiter.hxx>
47 #include <svtools/zforlist.hxx>
48 #include <vcl/msgbox.hxx>
49 #include <svtools/stritem.hxx>
50 #include <svtools/visitem.hxx>
51 #include <svtools/moduleoptions.hxx>
53 #include <com/sun/star/frame/FrameSearchFlag.hpp>
54 #include <com/sun/star/sdbc/XResultSet.hpp>
56 #include "cellsh.hxx"
57 #include "tabvwsh.hxx"
58 #include "sc.hrc"
59 #include "globstr.hrc"
60 #include "global.hxx"
61 #include "scmod.hxx"
62 #include "docsh.hxx"
63 #include "document.hxx"
64 #include "uiitems.hxx"
65 #include "dbfunc.hxx"
66 #include "dbdocfun.hxx"
67 //CHINA001 #include "lbseldlg.hxx"
68 //CHINA001 #include "sortdlg.hxx"
69 #include "filtdlg.hxx"
70 #include "dbnamdlg.hxx"
71 //CHINA001 #include "subtdlg.hxx"
72 #include "reffact.hxx"
73 #include "pvlaydlg.hxx"
74 #include "validat.hxx"
75 #include "scresid.hxx"
76 //CHINA001 #include "validate.hxx"
77 #include "pivot.hxx"
78 #include "dpobject.hxx"
79 //CHINA001 #include "dapitype.hxx"
80 //CHINA001 #include "dapidata.hxx"
81 #include "dpsdbtab.hxx" // ScImportSourceDesc
82 #include "dpshttab.hxx" // ScSheetSourceDesc
84 #include "validate.hrc" //CHINA001 add for ScValidationDlg
85 #include "scui_def.hxx" //CHINA001
86 #include "scabstdlg.hxx" //CHINA001
87 #include "impex.hxx"
88 #include "asciiopt.hxx"
89 using namespace com::sun::star;
91 //#include "strindlg.hxx" //! Test !!!!!
93 //static ScArea aPivotSource; //! wohin? (ueber den Dialog retten)
96 #define IS_AVAILABLE(WhichId,ppItem) \
97 (pReqArgs->GetItemState((WhichId), TRUE, ppItem ) == SFX_ITEM_SET)
99 //------------------------------------------------------------------
101 bool lcl_GetTextToColumnsRange( const ScViewData* pData, ScRange& rRange )
103 DBG_ASSERT( pData, "lcl_GetTextToColumnsRange: pData is null!" );
105 bool bRet = false;
106 const ScMarkData& rMark = pData->GetMarkData();
108 if ( rMark.IsMarked() )
110 if ( !rMark.IsMultiMarked() )
112 rMark.GetMarkArea( rRange );
113 if ( rRange.aStart.Col() == rRange.aEnd.Col() )
115 bRet = true;
119 else
121 const SCCOL nCol = pData->GetCurX();
122 const SCROW nRow = pData->GetCurY();
123 const SCTAB nTab = pData->GetTabNo();
124 rRange = ScRange( nCol, nRow, nTab, nCol, nRow, nTab );
125 bRet = true;
128 const ScDocument* pDoc = pData->GetDocument();
129 DBG_ASSERT( pDoc, "lcl_GetTextToColumnsRange: pDoc is null!" );
131 if ( bRet && pDoc->IsBlockEmpty( rRange.aStart.Tab(), rRange.aStart.Col(),
132 rRange.aStart.Row(), rRange.aEnd.Col(),
133 rRange.aEnd.Row() ) )
135 bRet = false;
138 return bRet;
141 BOOL lcl_GetSortParam( const ScViewData* pData, ScSortParam& rSortParam )
143 ScTabViewShell* pTabViewShell = pData->GetViewShell();
144 ScDBData* pDBData = pTabViewShell->GetDBData();
145 ScDocument* pDoc = pData->GetDocument();
146 SCTAB nTab = pData->GetTabNo();
147 ScDirection eFillDir = DIR_TOP;
148 BOOL bSort = TRUE;
149 ScRange aExternalRange;
151 if( rSortParam.nCol1 != rSortParam.nCol2 )
152 eFillDir = DIR_LEFT;
153 if( rSortParam.nRow1 != rSortParam.nRow2 )
154 eFillDir = DIR_TOP;
156 SCSIZE nCount = pDoc->GetEmptyLinesInBlock( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab, eFillDir );
158 if( rSortParam.nRow2 == MAXROW )
159 aExternalRange = ScRange( rSortParam.nCol1,sal::static_int_cast<SCROW>( nCount ), nTab );
160 else
161 aExternalRange = ScRange( pData->GetCurX(), pData->GetCurY(), nTab );
163 SCROW nStartRow = aExternalRange.aStart.Row();
164 SCCOL nStartCol = aExternalRange.aStart.Col();
165 SCROW nEndRow = aExternalRange.aEnd.Row();
166 SCCOL nEndCol = aExternalRange.aEnd.Col();
167 pDoc->GetDataArea( aExternalRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow, FALSE );
168 aExternalRange.aStart.SetRow( nStartRow );
169 aExternalRange.aStart.SetCol( nStartCol );
170 aExternalRange.aEnd.SetRow( nEndRow );
171 aExternalRange.aEnd.SetCol( nEndCol );
173 if(( rSortParam.nCol1 == rSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col() ) ||
174 ( rSortParam.nRow1 == rSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row() ) )
176 USHORT nFmt = SCA_VALID;
177 String aExtendStr,aCurrentStr;
179 pTabViewShell->AddHighlightRange( aExternalRange,Color( COL_LIGHTBLUE ) );
180 ScRange rExtendRange( aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), nTab, aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row(), nTab );
181 rExtendRange.Format( aExtendStr, nFmt, pDoc );
183 ScRange rCurrentRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab );
184 rCurrentRange.Format( aCurrentStr, nFmt, pDoc );
186 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
187 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
189 VclAbstractDialog* pWarningDlg = pFact->CreateScSortWarningDlg( pTabViewShell->GetDialogParent(),aExtendStr,aCurrentStr,RID_SCDLG_SORT_WARNING );
190 DBG_ASSERT(pWarningDlg, "Dialog create fail!");//CHINA001
191 short bResult = pWarningDlg->Execute();
192 if( bResult == BTN_EXTEND_RANGE || bResult == BTN_CURRENT_SELECTION )
194 if( bResult == BTN_EXTEND_RANGE )
196 pTabViewShell->MarkRange( aExternalRange, FALSE );
197 pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() );
200 else
202 bSort = FALSE;
203 pData->GetDocShell()->CancelAutoDBRange();
206 delete pWarningDlg;
207 pTabViewShell->ClearHighlightRanges();
209 return bSort;
212 void ScCellShell::ExecuteDB( SfxRequest& rReq )
214 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
215 USHORT nSlotId = rReq.GetSlot();
216 const SfxItemSet* pReqArgs = rReq.GetArgs();
217 ScModule* pScMod = SC_MOD();
219 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
221 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
223 pScMod->InputEnterHandler();
224 pTabViewShell->UpdateInputHandler();
227 switch ( nSlotId )
229 case SID_VIEW_DATA_SOURCE_BROWSER:
231 // check if database beamer is open
233 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
234 BOOL bWasOpen = FALSE;
236 uno::Reference<frame::XFrame> xFrame = pViewFrame->GetFrame()->GetFrameInterface();
237 uno::Reference<frame::XFrame> xBeamerFrame = xFrame->findFrame(
238 rtl::OUString::createFromAscii("_beamer"),
239 frame::FrameSearchFlag::CHILDREN);
240 if ( xBeamerFrame.is() )
241 bWasOpen = TRUE;
244 if ( bWasOpen )
246 // close database beamer: just forward to SfxViewFrame
248 pViewFrame->ExecuteSlot( rReq );
250 else
252 // show database beamer: SfxViewFrame call must be synchronous
254 pViewFrame->ExecuteSlot( rReq, (BOOL) FALSE ); // FALSE = synchronous
256 // select current database in database beamer
258 ScImportParam aImportParam;
259 ScDBData* pDBData = pTabViewShell->GetDBData(TRUE,SC_DB_OLD); // don't create if none found
260 if (pDBData)
261 pDBData->GetImportParam( aImportParam );
263 ScDBDocFunc::ShowInBeamer( aImportParam, pTabViewShell->GetViewFrame() );
265 rReq.Done(); // needed because it's a toggle slot
267 break;
269 case SID_REIMPORT_DATA:
271 BOOL bOk = FALSE;
272 ScDBData* pDBData = pTabViewShell->GetDBData(TRUE,SC_DB_OLD);
273 if (pDBData)
275 ScImportParam aImportParam;
276 pDBData->GetImportParam( aImportParam );
277 if (aImportParam.bImport && !pDBData->HasImportSelection())
279 pTabViewShell->ImportData( aImportParam );
280 pDBData->SetImportParam( aImportParam ); //! Undo ??
281 bOk = TRUE;
285 if (!bOk && ! rReq.IsAPI() )
286 pTabViewShell->ErrorMessage(STR_REIMPORT_EMPTY);
288 if( bOk )
289 rReq.Done();
291 break;
293 case SID_REFRESH_DBAREA:
295 ScDBData* pDBData = pTabViewShell->GetDBData(TRUE,SC_DB_OLD);
296 if (pDBData)
298 // Import wiederholen wie SID_REIMPORT_DATA
300 BOOL bContinue = TRUE;
301 ScImportParam aImportParam;
302 pDBData->GetImportParam( aImportParam );
303 if (aImportParam.bImport && !pDBData->HasImportSelection())
305 bContinue = pTabViewShell->ImportData( aImportParam );
306 pDBData->SetImportParam( aImportParam ); //! Undo ??
308 // markieren (Groesse kann sich geaendert haben)
309 ScRange aNewRange;
310 pDBData->GetArea(aNewRange);
311 pTabViewShell->MarkRange(aNewRange);
314 if ( bContinue ) // #41905# Fehler beim Import -> Abbruch
316 // interne Operationen, wenn welche gespeichert
318 if ( pDBData->HasQueryParam() || pDBData->HasSortParam() ||
319 pDBData->HasSubTotalParam() )
320 pTabViewShell->RepeatDB();
322 // Pivottabellen die den Bereich als Quelldaten haben
324 ScRange aRange;
325 pDBData->GetArea(aRange);
326 GetViewData()->GetDocShell()->RefreshPivotTables(aRange);
329 rReq.Done();
331 break;
333 case SID_SBA_BRW_INSERT:
335 DBG_ERROR( "Deprecated Slot" );
337 break;
339 case SID_DATA_FORM:
341 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
342 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
344 AbstractScDataFormDlg* pDlg = pFact->CreateScDataFormDlg( pTabViewShell->GetDialogParent(),RID_SCDLG_DATAFORM, pTabViewShell);
345 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
347 pDlg->Execute();
349 rReq.Done();
351 break;
353 case SID_SUBTOTALS:
355 const SfxItemSet* pArgs = rReq.GetArgs();
356 if ( pArgs )
358 pTabViewShell->DoSubTotals( ((const ScSubTotalItem&) pArgs->Get( SCITEM_SUBTDATA )).
359 GetSubTotalData() );
360 rReq.Done();
362 else
364 //CHINA001 ScSubTotalDlg* pDlg = NULL;
365 SfxAbstractTabDialog * pDlg = NULL;
366 ScSubTotalParam aSubTotalParam;
367 SfxItemSet aArgSet( GetPool(), SCITEM_SUBTDATA, SCITEM_SUBTDATA );
369 ScDBData* pDBData = pTabViewShell->GetDBData();
370 pDBData->GetSubTotalParam( aSubTotalParam );
371 aSubTotalParam.bRemoveOnly = FALSE;
373 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, GetViewData(), &aSubTotalParam ) );
374 //CHINA001 pDlg = new ScSubTotalDlg( pTabViewShell->GetDialogParent(), &aArgSet );
375 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
376 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
378 pDlg = pFact->CreateScSubTotalDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SUBTOTALS );
379 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
380 pDlg->SetCurPageId(1);
382 short bResult = pDlg->Execute();
384 if ( (bResult == RET_OK) || (bResult == SCRET_REMOVE) )
386 const SfxItemSet* pOutSet = NULL;
388 if ( bResult == RET_OK )
390 pOutSet = pDlg->GetOutputItemSet();
391 aSubTotalParam =
392 ((const ScSubTotalItem&)
393 pOutSet->Get( SCITEM_SUBTDATA )).
394 GetSubTotalData();
396 else // if (bResult == SCRET_REMOVE)
398 pOutSet = &aArgSet;
399 aSubTotalParam.bRemoveOnly = TRUE;
400 aSubTotalParam.bReplace = TRUE;
401 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA,
402 GetViewData(),
403 &aSubTotalParam ) );
406 pTabViewShell->DoSubTotals( aSubTotalParam );
407 rReq.Done( *pOutSet );
409 else
410 GetViewData()->GetDocShell()->CancelAutoDBRange();
412 delete pDlg;
415 break;
417 case SID_SORT_DESCENDING:
418 case SID_SORT_ASCENDING:
420 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
421 //the patch comes from maoyg
422 ScSortParam aSortParam;
423 ScDBData* pDBData = pTabViewShell->GetDBData();
424 ScViewData* pData = GetViewData();
426 pDBData->GetSortParam( aSortParam );
428 if( lcl_GetSortParam( pData, aSortParam ) )
430 SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA );
431 SCCOL nCol = GetViewData()->GetCurX();
432 SCCOL nTab = GetViewData()->GetTabNo();
433 ScDocument* pDoc = GetViewData()->GetDocument();
435 pDBData->GetSortParam( aSortParam );
436 BOOL bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, nTab );
438 if( nCol < aSortParam.nCol1 )
439 nCol = aSortParam.nCol1;
440 else if( nCol > aSortParam.nCol2 )
441 nCol = aSortParam.nCol2;
443 aSortParam.bHasHeader = bHasHeader;
444 aSortParam.bByRow = TRUE;
445 aSortParam.bCaseSens = FALSE;
446 aSortParam.bNaturalSort = FALSE;
447 aSortParam.bIncludePattern = TRUE;
448 aSortParam.bInplace = TRUE;
449 aSortParam.bDoSort[0] = TRUE;
450 aSortParam.nField[0] = nCol;
451 aSortParam.bAscending[0] = (nSlotId == SID_SORT_ASCENDING);
453 for ( USHORT i=1; i<MAXSORT; i++ )
454 aSortParam.bDoSort[i] = FALSE;
456 aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) );
458 pTabViewShell->UISort( aSortParam ); // Teilergebnisse bei Bedarf neu
460 rReq.Done();
463 break;
465 case SID_SORT:
467 const SfxItemSet* pArgs = rReq.GetArgs();
469 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
470 //the patch comes from maoyg
472 if ( pArgs ) // Basic
474 ScSortParam aSortParam;
475 ScDBData* pDBData = pTabViewShell->GetDBData();
476 ScViewData* pData = GetViewData();
478 pDBData->GetSortParam( aSortParam );
480 if( lcl_GetSortParam( pData, aSortParam ) )
482 ScDocument* pDoc = GetViewData()->GetDocument();
484 pDBData->GetSortParam( aSortParam );
485 BOOL bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() );
486 if( bHasHeader )
487 aSortParam.bHasHeader = bHasHeader;
489 aSortParam.bInplace = TRUE; // von Basic immer
491 const SfxPoolItem* pItem;
492 if ( pArgs->GetItemState( SID_SORT_BYROW, TRUE, &pItem ) == SFX_ITEM_SET )
493 aSortParam.bByRow = ((const SfxBoolItem*)pItem)->GetValue();
494 if ( pArgs->GetItemState( SID_SORT_HASHEADER, TRUE, &pItem ) == SFX_ITEM_SET )
495 aSortParam.bHasHeader = ((const SfxBoolItem*)pItem)->GetValue();
496 if ( pArgs->GetItemState( SID_SORT_CASESENS, TRUE, &pItem ) == SFX_ITEM_SET )
497 aSortParam.bCaseSens = ((const SfxBoolItem*)pItem)->GetValue();
498 if ( pArgs->GetItemState( SID_SORT_NATURALSORT, TRUE, &pItem ) == SFX_ITEM_SET )
499 aSortParam.bNaturalSort = ((const SfxBoolItem*)pItem)->GetValue();
500 if ( pArgs->GetItemState( SID_SORT_ATTRIBS, TRUE, &pItem ) == SFX_ITEM_SET )
501 aSortParam.bIncludePattern = ((const SfxBoolItem*)pItem)->GetValue();
502 if ( pArgs->GetItemState( SID_SORT_USERDEF, TRUE, &pItem ) == SFX_ITEM_SET )
504 USHORT nUserIndex = ((const SfxUInt16Item*)pItem)->GetValue();
505 aSortParam.bUserDef = ( nUserIndex != 0 );
506 if ( nUserIndex )
507 aSortParam.nUserIndex = nUserIndex - 1; // Basic: 1-basiert
510 SCCOLROW nField0 = 0;
511 if ( pArgs->GetItemState( FN_PARAM_1, TRUE, &pItem ) == SFX_ITEM_SET )
512 nField0 = ((const SfxInt32Item*)pItem)->GetValue();
513 aSortParam.bDoSort[0] = ( nField0 != 0 );
514 aSortParam.nField[0] = nField0 > 0 ? (nField0-1) : 0;
515 if ( pArgs->GetItemState( FN_PARAM_2, TRUE, &pItem ) == SFX_ITEM_SET )
516 aSortParam.bAscending[0] = ((const SfxBoolItem*)pItem)->GetValue();
517 SCCOLROW nField1 = 0;
518 if ( pArgs->GetItemState( FN_PARAM_3, TRUE, &pItem ) == SFX_ITEM_SET )
519 nField1 = ((const SfxInt32Item*)pItem)->GetValue();
520 aSortParam.bDoSort[1] = ( nField1 != 0 );
521 aSortParam.nField[1] = nField1 > 0 ? (nField1-1) : 0;
522 if ( pArgs->GetItemState( FN_PARAM_4, TRUE, &pItem ) == SFX_ITEM_SET )
523 aSortParam.bAscending[1] = ((const SfxBoolItem*)pItem)->GetValue();
524 SCCOLROW nField2 = 0;
525 if ( pArgs->GetItemState( FN_PARAM_5, TRUE, &pItem ) == SFX_ITEM_SET )
526 nField2 = ((const SfxInt32Item*)pItem)->GetValue();
527 aSortParam.bDoSort[2] = ( nField2 != 0 );
528 aSortParam.nField[2] = nField2 > 0 ? (nField2-1) : 0;
529 if ( pArgs->GetItemState( FN_PARAM_6, TRUE, &pItem ) == SFX_ITEM_SET )
530 aSortParam.bAscending[2] = ((const SfxBoolItem*)pItem)->GetValue();
532 // Teilergebnisse bei Bedarf neu
533 pTabViewShell->UISort( aSortParam );
534 rReq.Done();
537 else
539 ScSortParam aSortParam;
540 ScDBData* pDBData = pTabViewShell->GetDBData();
541 ScViewData* pData = GetViewData();
543 pDBData->GetSortParam( aSortParam );
545 if( lcl_GetSortParam( pData, aSortParam ) )
547 SfxAbstractTabDialog* pDlg = NULL;
548 ScDocument* pDoc = GetViewData()->GetDocument();
549 SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA );
551 pDBData->GetSortParam( aSortParam );
552 BOOL bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() );
553 if( bHasHeader )
554 aSortParam.bHasHeader = bHasHeader;
556 aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) );
558 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
559 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
561 pDlg = pFact->CreateScSortDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SORT );
562 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
563 pDlg->SetCurPageId(1); // 1=sort field tab 2=sort options tab
565 if ( pDlg->Execute() == RET_OK )
567 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
568 const ScSortParam& rOutParam = ((const ScSortItem&)
569 pOutSet->Get( SCITEM_SORTDATA )).GetSortData();
571 // Teilergebnisse bei Bedarf neu
572 pTabViewShell->UISort( rOutParam );
574 if ( rOutParam.bInplace )
576 rReq.AppendItem( SfxBoolItem( SID_SORT_BYROW,
577 rOutParam.bByRow ) );
578 rReq.AppendItem( SfxBoolItem( SID_SORT_HASHEADER,
579 rOutParam.bHasHeader ) );
580 rReq.AppendItem( SfxBoolItem( SID_SORT_CASESENS,
581 rOutParam.bCaseSens ) );
582 rReq.AppendItem( SfxBoolItem( SID_SORT_NATURALSORT,
583 rOutParam.bNaturalSort ) );
584 rReq.AppendItem( SfxBoolItem( SID_SORT_ATTRIBS,
585 rOutParam.bIncludePattern ) );
586 USHORT nUser = rOutParam.bUserDef ? ( rOutParam.nUserIndex + 1 ) : 0;
587 rReq.AppendItem( SfxUInt16Item( SID_SORT_USERDEF, nUser ) );
588 if ( rOutParam.bDoSort[0] )
590 rReq.AppendItem( SfxInt32Item( FN_PARAM_1,
591 rOutParam.nField[0] + 1 ) );
592 rReq.AppendItem( SfxBoolItem( FN_PARAM_2,
593 rOutParam.bAscending[0] ) );
595 if ( rOutParam.bDoSort[1] )
597 rReq.AppendItem( SfxInt32Item( FN_PARAM_3,
598 rOutParam.nField[1] + 1 ) );
599 rReq.AppendItem( SfxBoolItem( FN_PARAM_4,
600 rOutParam.bAscending[1] ) );
602 if ( rOutParam.bDoSort[2] )
604 rReq.AppendItem( SfxInt32Item( FN_PARAM_5,
605 rOutParam.nField[2] + 1 ) );
606 rReq.AppendItem( SfxBoolItem( FN_PARAM_6,
607 rOutParam.bAscending[2] ) );
611 rReq.Done();
613 else
614 GetViewData()->GetDocShell()->CancelAutoDBRange();
616 delete pDlg;
620 break;
622 case SID_FILTER:
624 const SfxItemSet* pArgs = rReq.GetArgs();
625 if ( pArgs )
627 DBG_ERROR("SID_FILTER with arguments?");
628 pTabViewShell->Query( ((const ScQueryItem&)
629 pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), NULL, TRUE );
630 rReq.Done();
632 else
634 USHORT nId = ScFilterDlgWrapper::GetChildWindowId();
635 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
636 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
638 pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );
641 break;
643 case SID_SPECIAL_FILTER:
645 const SfxItemSet* pArgs = rReq.GetArgs();
646 if ( pArgs )
648 DBG_ERROR("SID_SPECIAL_FILTER with arguments?");
649 pTabViewShell->Query( ((const ScQueryItem&)
650 pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), NULL, TRUE );
651 rReq.Done();
653 else
655 USHORT nId = ScSpecialFilterDlgWrapper::GetChildWindowId();
656 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
657 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
659 pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );
662 break;
664 case FID_FILTER_OK:
666 const SfxPoolItem* pItem;
667 if ( pReqArgs && SFX_ITEM_SET ==
668 pReqArgs->GetItemState( SCITEM_QUERYDATA, TRUE, &pItem ) )
670 const ScQueryItem& rQueryItem = static_cast<const ScQueryItem&>(*pItem);
672 SCTAB nCurTab = GetViewData()->GetTabNo();
673 SCTAB nRefTab = GetViewData()->GetRefTabNo();
675 // If RefInput switched to a different sheet from the data sheet,
676 // switch back:
678 if ( nCurTab != nRefTab )
680 pTabViewShell->SetTabNo( nRefTab );
681 pTabViewShell->PaintExtras();
684 ScRange aAdvSource;
685 if (rQueryItem.GetAdvancedQuerySource(aAdvSource))
686 pTabViewShell->Query( rQueryItem.GetQueryData(), &aAdvSource, TRUE );
687 else
688 pTabViewShell->Query( rQueryItem.GetQueryData(), NULL, TRUE );
689 rReq.Done( *pReqArgs );
692 break;
694 case SID_UNFILTER:
696 ScQueryParam aParam;
697 ScDBData* pDBData = pTabViewShell->GetDBData();
699 pDBData->GetQueryParam( aParam );
700 SCSIZE nEC = aParam.GetEntryCount();
701 for (SCSIZE i=0; i<nEC; i++)
702 aParam.GetEntry(i).bDoQuery = FALSE;
703 aParam.bDuplicate = TRUE;
704 pTabViewShell->Query( aParam, NULL, TRUE );
705 rReq.Done();
707 break;
709 case SID_AUTO_FILTER:
710 pTabViewShell->ToggleAutoFilter();
711 rReq.Done();
712 break;
714 case SID_AUTOFILTER_HIDE:
715 pTabViewShell->HideAutoFilter();
716 rReq.Done();
717 break;
719 case SID_PIVOT_TABLE:
721 const SfxPoolItem* pItem;
722 if ( pReqArgs && SFX_ITEM_SET ==
723 pReqArgs->GetItemState( SCITEM_PIVOTDATA, TRUE, &pItem ) )
725 SCTAB nCurTab = GetViewData()->GetTabNo();
726 SCTAB nRefTab = GetViewData()->GetRefTabNo();
728 // Wenn RefInput auf andere Tabelle als Datentabelle umgeschaltet
729 // hat wieder zurueckschalten:
731 if ( nCurTab != nRefTab )
733 pTabViewShell->SetTabNo( nRefTab );
734 pTabViewShell->PaintExtras();
737 const ScDPObject* pDPObject = pTabViewShell->GetDialogDPObject();
738 if ( pDPObject )
740 const ScPivotItem* pPItem = (const ScPivotItem*)pItem;
741 bool bSuccess = pTabViewShell->MakePivotTable(
742 pPItem->GetData(), pPItem->GetDestRange(), pPItem->IsNewSheet(), *pDPObject );
743 SfxBoolItem aRet(0, bSuccess);
744 rReq.SetReturnValue(aRet);
746 rReq.Done();
748 else if (rReq.IsAPI())
749 SbxBase::SetError(SbxERR_BAD_PARAMETER);
751 break;
753 case SID_OPENDLG_PIVOTTABLE:
755 ScViewData* pData = GetViewData();
756 ScDocument* pDoc = pData->GetDocument();
758 ScDPObject* pNewDPObject = NULL;
760 // ScPivot is no longer used...
761 ScDPObject* pDPObj = pDoc->GetDPAtCursor(
762 pData->GetCurX(), pData->GetCurY(),
763 pData->GetTabNo() );
764 if ( pDPObj ) // on an existing table?
766 pNewDPObject = new ScDPObject( *pDPObj );
768 else // create new table
770 // select database range or data
771 pTabViewShell->GetDBData( TRUE, SC_DB_OLD );
772 ScMarkData& rMark = GetViewData()->GetMarkData();
773 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
774 pTabViewShell->MarkDataArea( FALSE );
776 // output to cursor position for non-sheet data
777 ScAddress aDestPos( pData->GetCurX(), pData->GetCurY(),
778 pData->GetTabNo() );
780 // first select type of source data
782 BOOL bEnableExt = ScDPObject::HasRegisteredSources();
783 //CHINA001 ScDataPilotSourceTypeDlg* pTypeDlg = new ScDataPilotSourceTypeDlg(
784 //CHINA001 pTabViewShell->GetDialogParent(), bEnableExt );
786 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
787 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
789 AbstractScDataPilotSourceTypeDlg* pTypeDlg = pFact->CreateScDataPilotSourceTypeDlg( pTabViewShell->GetDialogParent(), bEnableExt, RID_SCDLG_DAPITYPE );
790 DBG_ASSERT(pTypeDlg, "Dialog create fail!");//CHINA001
791 if ( pTypeDlg->Execute() == RET_OK )
793 if ( pTypeDlg->IsExternal() )
795 uno::Sequence<rtl::OUString> aSources = ScDPObject::GetRegisteredSources();
796 //CHINA001 ScDataPilotServiceDlg* pServDlg = new ScDataPilotServiceDlg(
797 //CHINA001 pTabViewShell->GetDialogParent(), aSources );
798 AbstractScDataPilotServiceDlg* pServDlg = pFact->CreateScDataPilotServiceDlg( pTabViewShell->GetDialogParent(), aSources, RID_SCDLG_DAPISERVICE );
799 DBG_ASSERT(pServDlg, "Dialog create fail!");//CHINA001
800 if ( pServDlg->Execute() == RET_OK )
802 ScDPServiceDesc aServDesc(
803 pServDlg->GetServiceName(),
804 pServDlg->GetParSource(),
805 pServDlg->GetParName(),
806 pServDlg->GetParUser(),
807 pServDlg->GetParPass() );
808 pNewDPObject = new ScDPObject( pDoc );
809 pNewDPObject->SetServiceData( aServDesc );
811 delete pServDlg;
813 else if ( pTypeDlg->IsDatabase() )
815 //CHINA001 ScDataPilotDatabaseDlg* pDataDlg = new ScDataPilotDatabaseDlg(
816 //CHINA001 pTabViewShell->GetDialogParent() );
817 //ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
818 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
820 AbstractScDataPilotDatabaseDlg* pDataDlg = pFact->CreateScDataPilotDatabaseDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_DAPIDATA);
821 DBG_ASSERT(pDataDlg, "Dialog create fail!");//CHINA001
822 if ( pDataDlg->Execute() == RET_OK )
824 ScImportSourceDesc aImpDesc;
825 pDataDlg->GetValues( aImpDesc );
826 pNewDPObject = new ScDPObject( pDoc );
827 pNewDPObject->SetImportDesc( aImpDesc );
829 delete pDataDlg;
831 else // selection
833 //! use database ranges (select before type dialog?)
834 ScRange aRange;
835 ScMarkType eType = GetViewData()->GetSimpleArea(aRange);
836 if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
838 // Shrink the range to the data area.
839 SCCOL nStartCol = aRange.aStart.Col(), nEndCol = aRange.aEnd.Col();
840 SCROW nStartRow = aRange.aStart.Row(), nEndRow = aRange.aEnd.Row();
841 if (pDoc->ShrinkToDataArea(aRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow))
843 aRange.aStart.SetCol(nStartCol);
844 aRange.aStart.SetRow(nStartRow);
845 aRange.aEnd.SetCol(nEndCol);
846 aRange.aEnd.SetRow(nEndRow);
847 rMark.SetMarkArea(aRange);
848 pTabViewShell->MarkRange(aRange);
851 BOOL bOK = TRUE;
852 if ( pDoc->HasSubTotalCells( aRange ) )
854 // confirm selection if it contains SubTotal cells
856 QueryBox aBox( pTabViewShell->GetDialogParent(),
857 WinBits(WB_YES_NO | WB_DEF_YES),
858 ScGlobal::GetRscString(STR_DATAPILOT_SUBTOTAL) );
859 if (aBox.Execute() == RET_NO)
860 bOK = FALSE;
862 if (bOK)
864 ScSheetSourceDesc aShtDesc;
865 aShtDesc.aSourceRange = aRange;
866 pNewDPObject = new ScDPObject( pDoc );
867 pNewDPObject->SetSheetDesc( aShtDesc );
869 // output below source data
870 if ( aRange.aEnd.Row()+2 <= MAXROW - 4 )
871 aDestPos = ScAddress( aRange.aStart.Col(),
872 aRange.aEnd.Row()+2,
873 aRange.aStart.Tab() );
878 delete pTypeDlg;
880 if ( pNewDPObject )
881 pNewDPObject->SetOutRange( aDestPos );
883 #if 0
884 ScDBData* pDBData = pTabViewShell->GetDBData();
885 String aErrMsg;
887 pDBData->GetArea( nTab, nCol1, nRow1, nCol2, nRow2 );
889 bAreaOk = TRUE;
890 if ( nRow2-nRow1 < 1 )
892 // "mindestens eine Datenzeile"
893 pTabViewShell->ErrorMessage(STR_PIVOT_INVALID_DBAREA);
894 bAreaOk = FALSE;
896 else if (!pDBData->HasHeader())
898 if ( MessBox( pTabViewShell->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
899 ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ), // "StarCalc"
900 ScGlobal::GetRscString( STR_MSSG_MAKEAUTOFILTER_0 ) // Koepfe aus erster Zeile?
901 ).Execute() == RET_YES )
903 pDBData->SetHeader( TRUE ); //! Undo ??
905 else
906 bAreaOk = FALSE;
908 #endif
911 pTabViewShell->SetDialogDPObject( pNewDPObject ); // is copied
912 if ( pNewDPObject )
914 // start layout dialog
916 USHORT nId = ScPivotLayoutWrapper::GetChildWindowId();
917 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
918 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
919 pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );
921 delete pNewDPObject;
923 break;
925 case SID_DEFINE_DBNAME:
928 USHORT nId = ScDbNameDlgWrapper::GetChildWindowId();
929 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
930 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
932 pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );
935 break;
937 case SID_SELECT_DB:
939 if ( pReqArgs )
941 const SfxStringItem* pItem =
942 (const SfxStringItem*)&pReqArgs->Get( SID_SELECT_DB );
944 if( pItem )
946 pTabViewShell->GotoDBArea( pItem->GetValue() );
947 rReq.Done();
949 else
951 DBG_ERROR("NULL");
954 else
956 ScDocument* pDoc = GetViewData()->GetDocument();
957 ScDBCollection* pDBCol = pDoc->GetDBCollection();
959 if ( pDBCol )
961 const String aStrNoName( ScGlobal::GetRscString(STR_DB_NONAME) );
962 List aList;
963 USHORT nDBCount = pDBCol->GetCount();
964 ScDBData* pDbData = NULL;
965 String* pDBName = NULL;
967 for ( USHORT i=0; i < nDBCount; i++ )
969 pDbData = (ScDBData*)(pDBCol->At( i ));
970 if ( pDbData )
972 pDBName = new String;
973 pDbData->GetName( *pDBName );
975 if ( *pDBName != aStrNoName )
976 aList.Insert( pDBName );
977 else
978 DELETEZ(pDBName);
982 //CHINA001 ScSelEntryDlg* pDlg =
983 //CHINA001 new ScSelEntryDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_SELECTDB,
984 //CHINA001 String(ScResId(SCSTR_SELECTDB)),
985 //CHINA001 String(ScResId(SCSTR_AREAS)),
986 //CHINA001 aList );
987 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
988 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
990 AbstractScSelEntryDlg* pDlg = pFact->CreateScSelEntryDlg( pTabViewShell->GetDialogParent(),
991 RID_SCDLG_SELECTDB,
992 String(ScResId(SCSTR_SELECTDB)),
993 String(ScResId(SCSTR_AREAS)),
994 aList,
995 RID_SCDLG_SELECTDB);
996 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
997 if ( pDlg->Execute() == RET_OK )
999 String aName = pDlg->GetSelectEntry();
1000 pTabViewShell->GotoDBArea( aName );
1001 rReq.AppendItem( SfxStringItem( SID_SELECT_DB, aName ) );
1002 rReq.Done();
1005 delete pDlg;
1007 void* pEntry = aList.First();
1008 while ( pEntry )
1010 delete (String*) aList.Remove( pEntry );
1011 pEntry = aList.Next();
1016 break;
1018 case FID_VALIDATION:
1020 const SfxPoolItem* pItem;
1021 const SfxItemSet* pArgs = rReq.GetArgs();
1022 if ( pArgs )
1024 DBG_ERROR("spaeter...");
1026 else
1028 //CHINA001 SfxItemSet aArgSet( GetPool(), ScTPValidationValue::GetRanges() );
1029 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1030 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1031 ::GetTabPageRanges ScTPValidationValueGetRanges = pFact->GetTabPageRangesFunc(TP_VALIDATION_VALUES);
1032 DBG_ASSERT(ScTPValidationValueGetRanges, "TabPage create fail!");//CHINA001
1033 SfxItemSet aArgSet( GetPool(), (*ScTPValidationValueGetRanges)() );//CHINA001
1034 ScValidationMode eMode = SC_VALID_ANY;
1035 ScConditionMode eOper = SC_COND_EQUAL;
1036 String aExpr1, aExpr2;
1037 BOOL bBlank = TRUE;
1038 sal_Int16 nListType = ValidListType::UNSORTED;
1039 BOOL bShowHelp = FALSE;
1040 String aHelpTitle, aHelpText;
1041 BOOL bShowError = FALSE;
1042 ScValidErrorStyle eErrStyle = SC_VALERR_STOP;
1043 String aErrTitle, aErrText;
1045 ScDocument* pDoc = GetViewData()->GetDocument();
1046 SCCOL nCurX = GetViewData()->GetCurX();
1047 SCROW nCurY = GetViewData()->GetCurY();
1048 SCTAB nTab = GetViewData()->GetTabNo();
1049 ScAddress aCursorPos( nCurX, nCurY, nTab );
1050 ULONG nIndex = ((SfxUInt32Item*)pDoc->GetAttr(
1051 nCurX, nCurY, nTab, ATTR_VALIDDATA ))->GetValue();
1052 if ( nIndex )
1054 const ScValidationData* pOldData = pDoc->GetValidationEntry( nIndex );
1055 if ( pOldData )
1057 eMode = pOldData->GetDataMode();
1058 eOper = pOldData->GetOperation();
1059 ULONG nNumFmt = 0;
1060 if ( eMode == SC_VALID_DATE || eMode == SC_VALID_TIME )
1062 short nType = ( eMode == SC_VALID_DATE ) ? NUMBERFORMAT_DATE
1063 : NUMBERFORMAT_TIME;
1064 nNumFmt = pDoc->GetFormatTable()->GetStandardFormat(
1065 nType, ScGlobal::eLnge );
1067 aExpr1 = pOldData->GetExpression( aCursorPos, 0, nNumFmt );
1068 aExpr2 = pOldData->GetExpression( aCursorPos, 1, nNumFmt );
1069 bBlank = pOldData->IsIgnoreBlank();
1070 nListType = pOldData->GetListType();
1072 bShowHelp = pOldData->GetInput( aHelpTitle, aHelpText );
1073 bShowError = pOldData->GetErrMsg( aErrTitle, aErrText, eErrStyle );
1075 aArgSet.Put( SfxAllEnumItem( FID_VALID_MODE, sal::static_int_cast<USHORT>(eMode) ) );
1076 aArgSet.Put( SfxAllEnumItem( FID_VALID_CONDMODE, sal::static_int_cast<USHORT>(eOper) ) );
1077 aArgSet.Put( SfxStringItem( FID_VALID_VALUE1, aExpr1 ) );
1078 aArgSet.Put( SfxStringItem( FID_VALID_VALUE2, aExpr2 ) );
1079 aArgSet.Put( SfxBoolItem( FID_VALID_BLANK, bBlank ) );
1080 aArgSet.Put( SfxInt16Item( FID_VALID_LISTTYPE, nListType ) );
1081 aArgSet.Put( SfxBoolItem( FID_VALID_SHOWHELP, bShowHelp ) );
1082 aArgSet.Put( SfxStringItem( FID_VALID_HELPTITLE, aHelpTitle ) );
1083 aArgSet.Put( SfxStringItem( FID_VALID_HELPTEXT, aHelpText ) );
1084 aArgSet.Put( SfxBoolItem( FID_VALID_SHOWERR, bShowError ) );
1085 aArgSet.Put( SfxAllEnumItem( FID_VALID_ERRSTYLE, sal::static_int_cast<USHORT>(eErrStyle) ) );
1086 aArgSet.Put( SfxStringItem( FID_VALID_ERRTITLE, aErrTitle ) );
1087 aArgSet.Put( SfxStringItem( FID_VALID_ERRTEXT, aErrText ) );
1091 //CHINA001 ScValidationDlg* pDlg = new ScValidationDlg( NULL, &aArgSet );
1092 //CHINA001 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1093 //CHINA001 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1095 SfxAbstractTabDialog* pDlg = pFact->CreateScValidationDlg( NULL, &aArgSet, TAB_DLG_VALIDATION );
1096 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1098 if ( pDlg->Execute() == RET_OK )
1100 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1102 if ( pOutSet->GetItemState( FID_VALID_MODE, TRUE, &pItem ) == SFX_ITEM_SET )
1103 eMode = (ScValidationMode) ((const SfxAllEnumItem*)pItem)->GetValue();
1104 if ( pOutSet->GetItemState( FID_VALID_CONDMODE, TRUE, &pItem ) == SFX_ITEM_SET )
1105 eOper = (ScConditionMode) ((const SfxAllEnumItem*)pItem)->GetValue();
1106 if ( pOutSet->GetItemState( FID_VALID_VALUE1, TRUE, &pItem ) == SFX_ITEM_SET )
1108 String aTemp1 = ((const SfxStringItem*)pItem)->GetValue();
1109 if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
1111 sal_uInt32 nNumIndex = 0;
1112 double nVal;
1113 if (pDoc->GetFormatTable()->IsNumberFormat(aTemp1, nNumIndex, nVal))
1114 aExpr1 =String( ::rtl::math::doubleToUString( nVal,
1115 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
1116 ScGlobal::pLocaleData->getNumDecimalSep().GetChar(0), TRUE));
1117 else
1118 aExpr1 = aTemp1;
1120 else
1121 aExpr1 = aTemp1;
1123 if ( pOutSet->GetItemState( FID_VALID_VALUE2, TRUE, &pItem ) == SFX_ITEM_SET )
1125 String aTemp2 = ((const SfxStringItem*)pItem)->GetValue();
1126 if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
1128 sal_uInt32 nNumIndex = 0;
1129 double nVal;
1130 if (pDoc->GetFormatTable()->IsNumberFormat(aTemp2, nNumIndex, nVal))
1131 aExpr2 =String( ::rtl::math::doubleToUString( nVal,
1132 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
1133 ScGlobal::pLocaleData->getNumDecimalSep().GetChar(0), TRUE));
1134 else
1135 aExpr2 = aTemp2;
1137 else
1138 aExpr2 = aTemp2;
1141 if ( pOutSet->GetItemState( FID_VALID_BLANK, TRUE, &pItem ) == SFX_ITEM_SET )
1142 bBlank = ((const SfxBoolItem*)pItem)->GetValue();
1143 if ( pOutSet->GetItemState( FID_VALID_LISTTYPE, TRUE, &pItem ) == SFX_ITEM_SET )
1144 nListType = ((const SfxInt16Item*)pItem)->GetValue();
1146 if ( pOutSet->GetItemState( FID_VALID_SHOWHELP, TRUE, &pItem ) == SFX_ITEM_SET )
1147 bShowHelp = ((const SfxBoolItem*)pItem)->GetValue();
1148 if ( pOutSet->GetItemState( FID_VALID_HELPTITLE, TRUE, &pItem ) == SFX_ITEM_SET )
1149 aHelpTitle = ((const SfxStringItem*)pItem)->GetValue();
1150 if ( pOutSet->GetItemState( FID_VALID_HELPTEXT, TRUE, &pItem ) == SFX_ITEM_SET )
1151 aHelpText = ((const SfxStringItem*)pItem)->GetValue();
1153 if ( pOutSet->GetItemState( FID_VALID_SHOWERR, TRUE, &pItem ) == SFX_ITEM_SET )
1154 bShowError = ((const SfxBoolItem*)pItem)->GetValue();
1155 if ( pOutSet->GetItemState( FID_VALID_ERRSTYLE, TRUE, &pItem ) == SFX_ITEM_SET )
1156 eErrStyle = (ScValidErrorStyle) ((const SfxAllEnumItem*)pItem)->GetValue();
1157 if ( pOutSet->GetItemState( FID_VALID_ERRTITLE, TRUE, &pItem ) == SFX_ITEM_SET )
1158 aErrTitle = ((const SfxStringItem*)pItem)->GetValue();
1159 if ( pOutSet->GetItemState( FID_VALID_ERRTEXT, TRUE, &pItem ) == SFX_ITEM_SET )
1160 aErrText = ((const SfxStringItem*)pItem)->GetValue();
1162 ScValidationData aData( eMode, eOper, aExpr1, aExpr2, pDoc, aCursorPos );
1163 aData.SetIgnoreBlank( bBlank );
1164 aData.SetListType( nListType );
1166 aData.SetInput(aHelpTitle, aHelpText); // sets bShowInput to TRUE
1167 if (!bShowHelp)
1168 aData.ResetInput(); // reset only bShowInput
1170 aData.SetError(aErrTitle, aErrText, eErrStyle); // sets bShowError to TRUE
1171 if (!bShowError)
1172 aData.ResetError(); // reset only bShowError
1174 pTabViewShell->SetValidation( aData );
1175 rReq.Done( *pOutSet );
1177 delete pDlg;
1180 break;
1182 case SID_TEXT_TO_COLUMNS:
1184 ScViewData* pData = GetViewData();
1185 DBG_ASSERT( pData, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pData is null!" );
1186 ScRange aRange;
1188 if ( lcl_GetTextToColumnsRange( pData, aRange ) )
1190 ScDocument* pDoc = pData->GetDocument();
1191 DBG_ASSERT( pDoc, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDoc is null!" );
1193 ScImportExport aExport( pDoc, aRange );
1194 aExport.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::None, 0, false ) );
1196 // #i87703# text to columns fails with tab separator
1197 aExport.SetDelimiter( static_cast< sal_Unicode >( 0 ) );
1199 SvMemoryStream aStream;
1200 aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
1201 ScImportExport::SetNoEndianSwap( aStream );
1202 aExport.ExportStream( aStream, String(), FORMAT_STRING );
1204 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1205 DBG_ASSERT( pFact, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pFact is null!" );
1206 AbstractScImportAsciiDlg *pDlg = pFact->CreateScImportAsciiDlg(
1207 NULL, String(), &aStream, RID_SCDLG_ASCII );
1208 DBG_ASSERT( pDlg, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDlg is null!" );
1209 pDlg->SetTextToColumnsMode();
1211 if ( pDlg->Execute() == RET_OK )
1213 ScDocShell* pDocSh = pData->GetDocShell();
1214 DBG_ASSERT( pDocSh, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" );
1216 String aUndo = ScGlobal::GetRscString( STR_UNDO_TEXTTOCOLUMNS );
1217 pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
1219 ScImportExport aImport( pDoc, aRange.aStart );
1220 ScAsciiOptions aOptions;
1221 pDlg->GetOptions( aOptions );
1222 aImport.SetExtOptions( aOptions );
1223 aImport.SetApi( false );
1224 aStream.Seek( 0 );
1225 aImport.ImportStream( aStream, String(), FORMAT_STRING );
1227 pDocSh->GetUndoManager()->LeaveListAction();
1229 delete pDlg;
1232 break;
1236 void __EXPORT ScCellShell::GetDBState( SfxItemSet& rSet )
1238 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
1239 ScViewData* pData = GetViewData();
1240 ScDocShell* pDocSh = pData->GetDocShell();
1241 ScDocument* pDoc = pDocSh->GetDocument();
1242 SCCOL nPosX = pData->GetCurX();
1243 SCROW nPosY = pData->GetCurY();
1244 SCTAB nTab = pData->GetTabNo();
1246 BOOL bAutoFilter = FALSE;
1247 BOOL bAutoFilterTested = FALSE;
1249 SfxWhichIter aIter(rSet);
1250 USHORT nWhich = aIter.FirstWhich();
1251 while (nWhich)
1253 switch (nWhich)
1255 case SID_REFRESH_DBAREA:
1257 // importierte Daten ohne Selektion
1258 // oder Filter,Sortierung,Teilergebis (auch ohne Import)
1259 BOOL bOk = FALSE;
1260 ScDBData* pDBData = pTabViewShell->GetDBData(FALSE,SC_DB_OLD);
1261 if (pDBData && pDoc->GetChangeTrack() == NULL)
1263 if ( pDBData->HasImportParam() )
1264 bOk = !pDBData->HasImportSelection();
1265 else
1267 bOk = pDBData->HasQueryParam() ||
1268 pDBData->HasSortParam() ||
1269 pDBData->HasSubTotalParam();
1272 if (!bOk)
1273 rSet.DisableItem( nWhich );
1275 break;
1277 case SID_FILTER:
1278 case SID_SPECIAL_FILTER:
1280 ScRange aDummy;
1281 ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy);
1282 if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1284 rSet.DisableItem( nWhich );
1287 break;
1290 //Bei Redlining und Multiselektion Disablen
1291 case SID_SORT_ASCENDING:
1292 case SID_SORT_DESCENDING:
1293 case SCITEM_SORTDATA:
1294 case SCITEM_SUBTDATA:
1295 case SID_OPENDLG_PIVOTTABLE:
1297 //! move ReadOnly check to idl flags
1299 if ( pDocSh->IsReadOnly() || pDoc->GetChangeTrack()!=NULL ||
1300 GetViewData()->IsMultiMarked() )
1302 rSet.DisableItem( nWhich );
1305 break;
1307 case SID_REIMPORT_DATA:
1309 // nur importierte Daten ohne Selektion
1310 ScDBData* pDBData = pTabViewShell->GetDBData(FALSE,SC_DB_OLD);
1311 if (!pDBData || !pDBData->HasImportParam() || pDBData->HasImportSelection() ||
1312 pDoc->GetChangeTrack()!=NULL)
1314 rSet.DisableItem( nWhich );
1317 break;
1319 case SID_VIEW_DATA_SOURCE_BROWSER:
1321 if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
1322 rSet.Put(SfxVisibilityItem(nWhich, sal_False));
1323 else
1324 // get state (BoolItem) from SfxViewFrame
1325 pTabViewShell->GetViewFrame()->GetSlotState( nWhich, NULL, &rSet );
1327 break;
1328 case SID_SBA_BRW_INSERT:
1330 // SBA will ein BOOL-Item, damit ueberhaupt enabled
1332 BOOL bEnable = TRUE;
1333 rSet.Put(SfxBoolItem(nWhich, bEnable));
1335 break;
1337 case SID_AUTO_FILTER:
1338 case SID_AUTOFILTER_HIDE:
1340 if (!bAutoFilterTested)
1342 bAutoFilter = pDoc->HasAutoFilter( nPosX, nPosY, nTab );
1343 bAutoFilterTested = TRUE;
1345 if ( nWhich == SID_AUTO_FILTER )
1347 ScRange aDummy;
1348 ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy);
1349 if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1351 rSet.DisableItem( nWhich );
1353 else if (pDoc->GetDPAtBlock(aDummy))
1355 rSet.DisableItem( nWhich );
1357 else
1358 rSet.Put( SfxBoolItem( nWhich, bAutoFilter ) );
1360 else
1361 if (!bAutoFilter)
1362 rSet.DisableItem( nWhich );
1364 break;
1366 case SID_UNFILTER:
1368 SCCOL nStartCol, nEndCol;
1369 SCROW nStartRow, nEndRow;
1370 SCTAB nStartTab, nEndTab;
1371 BOOL bAnyQuery = FALSE;
1373 BOOL bSelected = (GetViewData()->GetSimpleArea(
1374 nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab )
1375 == SC_MARK_SIMPLE);
1377 if ( bSelected )
1379 if (nStartCol==nEndCol && nStartRow==nEndRow)
1380 bSelected = FALSE;
1382 else
1384 nStartCol = GetViewData()->GetCurX();
1385 nStartRow = GetViewData()->GetCurY();
1386 nStartTab = GetViewData()->GetTabNo();
1389 ScDBData* pDBData = bSelected
1390 ? pDoc->GetDBAtArea( nStartTab, nStartCol, nStartRow, nEndCol, nEndRow )
1391 : pDoc->GetDBAtCursor( nStartCol, nStartRow, nStartTab );
1393 if ( pDBData )
1395 ScQueryParam aParam;
1396 pDBData->GetQueryParam( aParam );
1397 if ( aParam.GetEntry(0).bDoQuery )
1398 bAnyQuery = TRUE;
1401 if ( !bAnyQuery )
1402 rSet.DisableItem( nWhich );
1404 break;
1406 case SID_DEFINE_DBNAME:
1408 if ( pDocSh && pDocSh->IsDocShared() )
1410 rSet.DisableItem( nWhich );
1413 break;
1415 case SID_TEXT_TO_COLUMNS:
1417 ScRange aRange;
1418 if ( !lcl_GetTextToColumnsRange( pData, aRange ) )
1420 rSet.DisableItem( nWhich );
1423 break;
1425 nWhich = aIter.NextWhich();