Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "scitems.hxx"
30 : : #include <sfx2/viewfrm.hxx>
31 : : #include <sfx2/app.hxx>
32 : : #include <sfx2/request.hxx>
33 : : #include <svl/aeitem.hxx>
34 : : #include <basic/sbxcore.hxx>
35 : : #include <svl/whiter.hxx>
36 : : #include <svl/zforlist.hxx>
37 : : #include <vcl/msgbox.hxx>
38 : : #include <svl/stritem.hxx>
39 : : #include <svl/visitem.hxx>
40 : : #include <unotools/moduleoptions.hxx>
41 : :
42 : : #include <com/sun/star/frame/FrameSearchFlag.hpp>
43 : : #include <com/sun/star/sdbc/XResultSet.hpp>
44 : :
45 : : #include "cellsh.hxx"
46 : : #include "tabvwsh.hxx"
47 : : #include "sc.hrc"
48 : : #include "globstr.hrc"
49 : : #include "global.hxx"
50 : : #include "globalnames.hxx"
51 : : #include "scmod.hxx"
52 : : #include "docsh.hxx"
53 : : #include "document.hxx"
54 : : #include "uiitems.hxx"
55 : : #include "dbfunc.hxx"
56 : : #include "dbdocfun.hxx"
57 : : #include "filtdlg.hxx"
58 : : #include "dbnamdlg.hxx"
59 : : #include "reffact.hxx"
60 : : #include "pvlaydlg.hxx"
61 : : #include "validat.hxx"
62 : : #include "scresid.hxx"
63 : :
64 : : #include "validate.hrc" // ScValidationDlg
65 : : #include "scui_def.hxx"
66 : : #include "scabstdlg.hxx"
67 : : #include "impex.hxx"
68 : : #include "asciiopt.hxx"
69 : : #include "queryentry.hxx"
70 : : #include "markdata.hxx"
71 : :
72 : : using namespace com::sun::star;
73 : :
74 : 0 : bool lcl_GetTextToColumnsRange( const ScViewData* pData, ScRange& rRange )
75 : : {
76 : : OSL_ENSURE( pData, "lcl_GetTextToColumnsRange: pData is null!" );
77 : :
78 : 0 : bool bRet = false;
79 : 0 : const ScMarkData& rMark = pData->GetMarkData();
80 : :
81 [ # # ]: 0 : if ( rMark.IsMarked() )
82 : : {
83 [ # # ]: 0 : if ( !rMark.IsMultiMarked() )
84 : : {
85 : 0 : rMark.GetMarkArea( rRange );
86 [ # # ]: 0 : if ( rRange.aStart.Col() == rRange.aEnd.Col() )
87 : : {
88 : 0 : bRet = true;
89 : : }
90 : : }
91 : : }
92 : : else
93 : : {
94 : 0 : const SCCOL nCol = pData->GetCurX();
95 : 0 : const SCROW nRow = pData->GetCurY();
96 : 0 : const SCTAB nTab = pData->GetTabNo();
97 : 0 : rRange = ScRange( nCol, nRow, nTab, nCol, nRow, nTab );
98 : 0 : bRet = true;
99 : : }
100 : :
101 : 0 : const ScDocument* pDoc = pData->GetDocument();
102 : : OSL_ENSURE( pDoc, "lcl_GetTextToColumnsRange: pDoc is null!" );
103 : :
104 [ # # ]: 0 : if ( bRet && pDoc->IsBlockEmpty( rRange.aStart.Tab(), rRange.aStart.Col(),
[ # # # # ]
105 : 0 : rRange.aStart.Row(), rRange.aEnd.Col(),
106 : 0 : rRange.aEnd.Row() ) )
107 : : {
108 : 0 : bRet = false;
109 : : }
110 : :
111 : 0 : return bRet;
112 : : }
113 : :
114 : 0 : sal_Bool lcl_GetSortParam( const ScViewData* pData, ScSortParam& rSortParam )
115 : : {
116 : 0 : ScTabViewShell* pTabViewShell = pData->GetViewShell();
117 [ # # ]: 0 : ScDBData* pDBData = pTabViewShell->GetDBData();
118 [ # # ]: 0 : ScDocument* pDoc = pData->GetDocument();
119 : 0 : SCTAB nTab = pData->GetTabNo();
120 : 0 : ScDirection eFillDir = DIR_TOP;
121 : 0 : sal_Bool bSort = sal_True;
122 : 0 : ScRange aExternalRange;
123 : :
124 [ # # ]: 0 : if( rSortParam.nCol1 != rSortParam.nCol2 )
125 : 0 : eFillDir = DIR_LEFT;
126 [ # # ]: 0 : if( rSortParam.nRow1 != rSortParam.nRow2 )
127 : 0 : eFillDir = DIR_TOP;
128 : :
129 [ # # ]: 0 : SCSIZE nCount = pDoc->GetEmptyLinesInBlock( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab, eFillDir );
130 : :
131 [ # # ]: 0 : if( rSortParam.nRow2 == MAXROW )
132 : 0 : aExternalRange = ScRange( rSortParam.nCol1,sal::static_int_cast<SCROW>( nCount ), nTab );
133 : : else
134 : 0 : aExternalRange = ScRange( pData->GetCurX(), pData->GetCurY(), nTab );
135 : :
136 : 0 : SCROW nStartRow = aExternalRange.aStart.Row();
137 : 0 : SCCOL nStartCol = aExternalRange.aStart.Col();
138 : 0 : SCROW nEndRow = aExternalRange.aEnd.Row();
139 : 0 : SCCOL nEndCol = aExternalRange.aEnd.Col();
140 [ # # ]: 0 : pDoc->GetDataArea( aExternalRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow, false, false );
141 : 0 : aExternalRange.aStart.SetRow( nStartRow );
142 : 0 : aExternalRange.aStart.SetCol( nStartCol );
143 : 0 : aExternalRange.aEnd.SetRow( nEndRow );
144 : 0 : aExternalRange.aEnd.SetCol( nEndCol );
145 : :
146 [ # # ]: 0 : if(( rSortParam.nCol1 == rSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col() ) ||
[ # # # # ]
[ # # ][ # # ]
147 : 0 : ( rSortParam.nRow1 == rSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row() ) )
148 : : {
149 : 0 : sal_uInt16 nFmt = SCA_VALID;
150 [ # # ][ # # ]: 0 : String aExtendStr,aCurrentStr;
151 : :
152 [ # # ]: 0 : pTabViewShell->AddHighlightRange( aExternalRange,Color( COL_LIGHTBLUE ) );
153 : 0 : ScRange rExtendRange( aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), nTab, aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row(), nTab );
154 [ # # ]: 0 : rExtendRange.Format( aExtendStr, nFmt, pDoc );
155 : :
156 : 0 : ScRange rCurrentRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab );
157 [ # # ]: 0 : rCurrentRange.Format( aCurrentStr, nFmt, pDoc );
158 : :
159 [ # # ]: 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
160 : : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
161 : :
162 [ # # ][ # # ]: 0 : VclAbstractDialog* pWarningDlg = pFact->CreateScSortWarningDlg( pTabViewShell->GetDialogParent(),aExtendStr,aCurrentStr,RID_SCDLG_SORT_WARNING );
163 : : OSL_ENSURE(pWarningDlg, "Dialog create fail!");
164 [ # # ]: 0 : short bResult = pWarningDlg->Execute();
165 [ # # ][ # # ]: 0 : if( bResult == BTN_EXTEND_RANGE || bResult == BTN_CURRENT_SELECTION )
166 : : {
167 [ # # ]: 0 : if( bResult == BTN_EXTEND_RANGE )
168 : : {
169 [ # # ]: 0 : pTabViewShell->MarkRange( aExternalRange, false );
170 [ # # ]: 0 : pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() );
171 : : }
172 : : }
173 : : else
174 : : {
175 : 0 : bSort = false;
176 [ # # ]: 0 : pData->GetDocShell()->CancelAutoDBRange();
177 : : }
178 : :
179 [ # # ][ # # ]: 0 : delete pWarningDlg;
180 [ # # ][ # # ]: 0 : pTabViewShell->ClearHighlightRanges();
[ # # ]
181 : : }
182 : 0 : return bSort;
183 : : }
184 : :
185 : : //after end execute from !IsModalInputMode, it is safer to delay deleting
186 : : namespace
187 : : {
188 : 0 : long DelayDeleteAbstractDialog( void *pAbstractDialog, void * /*pArg*/ )
189 : : {
190 [ # # ]: 0 : delete reinterpret_cast<VclAbstractDialog*>( pAbstractDialog );
191 : 0 : return 0;
192 : : }
193 : : }
194 : :
195 : 0 : void ScCellShell::ExecuteDB( SfxRequest& rReq )
196 : : {
197 : 0 : ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
198 : 0 : sal_uInt16 nSlotId = rReq.GetSlot();
199 : 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
200 : 0 : ScModule* pScMod = SC_MOD();
201 : :
202 : 0 : pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
203 : :
204 [ # # ]: 0 : if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
205 : : {
206 : 0 : pScMod->InputEnterHandler();
207 : 0 : pTabViewShell->UpdateInputHandler();
208 : : }
209 : :
210 [ # # # # : 0 : switch ( nSlotId )
# # # # #
# # # # #
# # # # #
# # ]
211 : : {
212 : : case SID_VIEW_DATA_SOURCE_BROWSER:
213 : : {
214 : : // check if database beamer is open
215 : :
216 : 0 : SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
217 : 0 : sal_Bool bWasOpen = false;
218 : : {
219 [ # # ][ # # ]: 0 : uno::Reference<frame::XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
220 [ # # ]: 0 : uno::Reference<frame::XFrame> xBeamerFrame = xFrame->findFrame(
221 : : rtl::OUString("_beamer"),
222 [ # # ]: 0 : frame::FrameSearchFlag::CHILDREN);
223 [ # # ]: 0 : if ( xBeamerFrame.is() )
224 : 0 : bWasOpen = sal_True;
225 : : }
226 : :
227 [ # # ]: 0 : if ( bWasOpen )
228 : : {
229 : : // close database beamer: just forward to SfxViewFrame
230 : :
231 : 0 : pViewFrame->ExecuteSlot( rReq );
232 : : }
233 : : else
234 : : {
235 : : // show database beamer: SfxViewFrame call must be synchronous
236 : :
237 [ # # ]: 0 : pViewFrame->ExecuteSlot( rReq, (sal_Bool) false ); // sal_False = synchronous
238 : :
239 : : // select current database in database beamer
240 : :
241 [ # # ]: 0 : ScImportParam aImportParam;
242 [ # # ]: 0 : ScDBData* pDBData = pTabViewShell->GetDBData(sal_True,SC_DB_OLD); // don't create if none found
243 [ # # ]: 0 : if (pDBData)
244 [ # # ]: 0 : pDBData->GetImportParam( aImportParam );
245 : :
246 [ # # ][ # # ]: 0 : ScDBDocFunc::ShowInBeamer( aImportParam, pTabViewShell->GetViewFrame() );
247 : : }
248 : 0 : rReq.Done(); // needed because it's a toggle slot
249 : : }
250 : 0 : break;
251 : :
252 : : case SID_REIMPORT_DATA:
253 : : {
254 : 0 : sal_Bool bOk = false;
255 : 0 : ScDBData* pDBData = pTabViewShell->GetDBData(sal_True,SC_DB_OLD);
256 [ # # ]: 0 : if (pDBData)
257 : : {
258 [ # # ]: 0 : ScImportParam aImportParam;
259 [ # # ]: 0 : pDBData->GetImportParam( aImportParam );
260 [ # # ][ # # ]: 0 : if (aImportParam.bImport && !pDBData->HasImportSelection())
[ # # ]
261 : : {
262 [ # # ]: 0 : pTabViewShell->ImportData( aImportParam );
263 [ # # ]: 0 : pDBData->SetImportParam( aImportParam ); //! Undo ??
264 : 0 : bOk = sal_True;
265 [ # # ]: 0 : }
266 : : }
267 : :
268 [ # # ][ # # ]: 0 : if (!bOk && ! rReq.IsAPI() )
[ # # ]
269 : 0 : pTabViewShell->ErrorMessage(STR_REIMPORT_EMPTY);
270 : :
271 [ # # ]: 0 : if( bOk )
272 : 0 : rReq.Done();
273 : : }
274 : 0 : break;
275 : :
276 : : case SID_REFRESH_DBAREA:
277 : : {
278 : 0 : ScDBData* pDBData = pTabViewShell->GetDBData(sal_True,SC_DB_OLD);
279 [ # # ]: 0 : if (pDBData)
280 : : {
281 : : // repeat import like SID_REIMPORT_DATA
282 : :
283 : 0 : sal_Bool bContinue = sal_True;
284 [ # # ]: 0 : ScImportParam aImportParam;
285 [ # # ]: 0 : pDBData->GetImportParam( aImportParam );
286 [ # # ][ # # ]: 0 : if (aImportParam.bImport && !pDBData->HasImportSelection())
[ # # ]
287 : : {
288 [ # # ]: 0 : bContinue = pTabViewShell->ImportData( aImportParam );
289 [ # # ]: 0 : pDBData->SetImportParam( aImportParam ); //! Undo ??
290 : :
291 : : // mark (size may have been changed)
292 : 0 : ScRange aNewRange;
293 [ # # ]: 0 : pDBData->GetArea(aNewRange);
294 [ # # ]: 0 : pTabViewShell->MarkRange(aNewRange);
295 : : }
296 : :
297 [ # # ]: 0 : if ( bContinue ) // fail at import -> break
298 : : {
299 : : // internal operations, when any stored
300 : :
301 [ # # ][ # # ]: 0 : if ( pDBData->HasQueryParam() || pDBData->HasSortParam() ||
[ # # ][ # # ]
[ # # ][ # # ]
302 [ # # ]: 0 : pDBData->HasSubTotalParam() )
303 [ # # ]: 0 : pTabViewShell->RepeatDB();
304 : :
305 : : // pivot tables that have the range as data source
306 : :
307 : 0 : ScRange aRange;
308 [ # # ]: 0 : pDBData->GetArea(aRange);
309 [ # # ]: 0 : GetViewData()->GetDocShell()->RefreshPivotTables(aRange);
310 [ # # ]: 0 : }
311 : : }
312 : 0 : rReq.Done();
313 : : }
314 : 0 : break;
315 : :
316 : : case SID_SBA_BRW_INSERT:
317 : : {
318 : : OSL_FAIL( "Deprecated Slot" );
319 : : }
320 : 0 : break;
321 : :
322 : : case SID_DATA_FORM:
323 : : {
324 : 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
325 : : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
326 : :
327 : 0 : AbstractScDataFormDlg* pDlg = pFact->CreateScDataFormDlg( pTabViewShell->GetDialogParent(),RID_SCDLG_DATAFORM, pTabViewShell);
328 : : OSL_ENSURE(pDlg, "Dialog create fail!");
329 : :
330 : 0 : pDlg->Execute();
331 : :
332 : 0 : rReq.Done();
333 : : }
334 : 0 : break;
335 : :
336 : : case SID_SUBTOTALS:
337 : 0 : ExecuteSubtotals(rReq);
338 : 0 : break;
339 : :
340 : : case SID_SORT_DESCENDING:
341 : : case SID_SORT_ASCENDING:
342 : : {
343 : : //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
344 : : //the patch comes from maoyg
345 [ # # ]: 0 : ScSortParam aSortParam;
346 [ # # ]: 0 : ScDBData* pDBData = pTabViewShell->GetDBData();
347 : 0 : ScViewData* pData = GetViewData();
348 : :
349 [ # # ]: 0 : pDBData->GetSortParam( aSortParam );
350 : :
351 [ # # ][ # # ]: 0 : if( lcl_GetSortParam( pData, aSortParam ) )
352 : : {
353 [ # # ]: 0 : SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA );
354 : 0 : SCCOL nCol = GetViewData()->GetCurX();
355 : 0 : SCCOL nTab = GetViewData()->GetTabNo();
356 [ # # ]: 0 : ScDocument* pDoc = GetViewData()->GetDocument();
357 : :
358 [ # # ]: 0 : pDBData->GetSortParam( aSortParam );
359 [ # # ]: 0 : sal_Bool bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, nTab );
360 : :
361 [ # # ]: 0 : if( nCol < aSortParam.nCol1 )
362 : 0 : nCol = aSortParam.nCol1;
363 [ # # ]: 0 : else if( nCol > aSortParam.nCol2 )
364 : 0 : nCol = aSortParam.nCol2;
365 : :
366 : 0 : aSortParam.bHasHeader = bHasHeader;
367 : 0 : aSortParam.bByRow = true;
368 : 0 : aSortParam.bCaseSens = false;
369 : 0 : aSortParam.bNaturalSort = false;
370 : 0 : aSortParam.bIncludePattern = true;
371 : 0 : aSortParam.bInplace = true;
372 : 0 : aSortParam.maKeyState[0].bDoSort = true;
373 : 0 : aSortParam.maKeyState[0].nField = nCol;
374 : 0 : aSortParam.maKeyState[0].bAscending = ( nSlotId == SID_SORT_ASCENDING );
375 : :
376 [ # # ]: 0 : for ( sal_uInt16 i=1; i<aSortParam.GetSortKeyCount(); i++ )
377 : 0 : aSortParam.maKeyState[i].bDoSort = false;
378 : :
379 [ # # ][ # # ]: 0 : aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) );
[ # # ]
380 : :
381 [ # # ]: 0 : pTabViewShell->UISort( aSortParam ); // subtotal when needed new
382 : :
383 [ # # ][ # # ]: 0 : rReq.Done();
384 [ # # ]: 0 : }
385 : : }
386 : 0 : break;
387 : :
388 : : case SID_SORT:
389 : : {
390 : 0 : const SfxItemSet* pArgs = rReq.GetArgs();
391 : :
392 : : //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
393 : : //the patch comes from maoyg
394 : :
395 [ # # ]: 0 : if ( pArgs ) // Basic
396 : : {
397 [ # # ]: 0 : ScSortParam aSortParam;
398 [ # # ]: 0 : ScDBData* pDBData = pTabViewShell->GetDBData();
399 : 0 : ScViewData* pData = GetViewData();
400 : :
401 [ # # ]: 0 : pDBData->GetSortParam( aSortParam );
402 : :
403 [ # # ][ # # ]: 0 : if( lcl_GetSortParam( pData, aSortParam ) )
404 : : {
405 [ # # ]: 0 : ScDocument* pDoc = GetViewData()->GetDocument();
406 : :
407 [ # # ]: 0 : pDBData->GetSortParam( aSortParam );
408 [ # # ]: 0 : sal_Bool bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() );
409 [ # # ]: 0 : if( bHasHeader )
410 : 0 : aSortParam.bHasHeader = bHasHeader;
411 : :
412 : 0 : aSortParam.bInplace = sal_True; // from Basic always
413 : :
414 : : const SfxPoolItem* pItem;
415 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( SID_SORT_BYROW, sal_True, &pItem ) == SFX_ITEM_SET )
416 : 0 : aSortParam.bByRow = static_cast<const SfxBoolItem*>(pItem)->GetValue();
417 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( SID_SORT_HASHEADER, sal_True, &pItem ) == SFX_ITEM_SET )
418 : 0 : aSortParam.bHasHeader = static_cast<const SfxBoolItem*>(pItem)->GetValue();
419 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( SID_SORT_CASESENS, sal_True, &pItem ) == SFX_ITEM_SET )
420 : 0 : aSortParam.bCaseSens = static_cast<const SfxBoolItem*>(pItem)->GetValue();
421 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( SID_SORT_NATURALSORT, true, &pItem ) == SFX_ITEM_SET )
422 : 0 : aSortParam.bNaturalSort = static_cast<const SfxBoolItem*>(pItem)->GetValue();
423 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( SID_SORT_ATTRIBS, true, &pItem ) == SFX_ITEM_SET )
424 : 0 : aSortParam.bIncludePattern = static_cast<const SfxBoolItem*>(pItem)->GetValue();
425 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( SID_SORT_USERDEF, sal_True, &pItem ) == SFX_ITEM_SET )
426 : : {
427 : 0 : sal_uInt16 nUserIndex = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
428 : 0 : aSortParam.bUserDef = ( nUserIndex != 0 );
429 [ # # ]: 0 : if ( nUserIndex )
430 : 0 : aSortParam.nUserIndex = nUserIndex - 1; // Basic: 1-based
431 : : }
432 : :
433 : 0 : SCCOLROW nField0 = 0;
434 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) == SFX_ITEM_SET )
435 : 0 : nField0 = static_cast<const SfxInt32Item*>(pItem)->GetValue();
436 : 0 : aSortParam.maKeyState[0].bDoSort = ( nField0 != 0 );
437 [ # # ]: 0 : aSortParam.maKeyState[0].nField = nField0 > 0 ? (nField0-1) : 0;
438 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( FN_PARAM_2, sal_True, &pItem ) == SFX_ITEM_SET )
439 : 0 : aSortParam.maKeyState[0].bAscending = static_cast<const SfxBoolItem*>(pItem)->GetValue();
440 : 0 : SCCOLROW nField1 = 0;
441 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( FN_PARAM_3, sal_True, &pItem ) == SFX_ITEM_SET )
442 : 0 : nField1 = static_cast<const SfxInt32Item*>(pItem)->GetValue();
443 : 0 : aSortParam.maKeyState[1].bDoSort = ( nField1 != 0 );
444 [ # # ]: 0 : aSortParam.maKeyState[1].nField = nField1 > 0 ? (nField1-1) : 0;
445 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( FN_PARAM_4, sal_True, &pItem ) == SFX_ITEM_SET )
446 : 0 : aSortParam.maKeyState[1].bAscending = static_cast<const SfxBoolItem*>(pItem)->GetValue();
447 : 0 : SCCOLROW nField2 = 0;
448 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( FN_PARAM_5, sal_True, &pItem ) == SFX_ITEM_SET )
449 : 0 : nField2 = static_cast<const SfxInt32Item*>(pItem)->GetValue();
450 : 0 : aSortParam.maKeyState[2].bDoSort = ( nField2 != 0 );
451 [ # # ]: 0 : aSortParam.maKeyState[2].nField = nField2 > 0 ? (nField2-1) : 0;
452 [ # # ][ # # ]: 0 : if ( pArgs->GetItemState( FN_PARAM_6, sal_True, &pItem ) == SFX_ITEM_SET )
453 : 0 : aSortParam.maKeyState[2].bAscending = static_cast<const SfxBoolItem*>(pItem)->GetValue();
454 : :
455 : : // subtotal when needed new
456 [ # # ]: 0 : pTabViewShell->UISort( aSortParam );
457 [ # # ]: 0 : rReq.Done();
458 [ # # ]: 0 : }
459 : : }
460 : : else
461 : : {
462 [ # # ]: 0 : ScSortParam aSortParam;
463 [ # # ]: 0 : ScDBData* pDBData = pTabViewShell->GetDBData();
464 : 0 : ScViewData* pData = GetViewData();
465 : :
466 [ # # ]: 0 : pDBData->GetSortParam( aSortParam );
467 : :
468 [ # # ][ # # ]: 0 : if( lcl_GetSortParam( pData, aSortParam ) )
469 : : {
470 : 0 : SfxAbstractTabDialog* pDlg = NULL;
471 [ # # ]: 0 : ScDocument* pDoc = GetViewData()->GetDocument();
472 [ # # ]: 0 : SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA );
473 : :
474 [ # # ]: 0 : pDBData->GetSortParam( aSortParam );
475 [ # # ]: 0 : sal_Bool bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() );
476 [ # # ]: 0 : if( bHasHeader )
477 : 0 : aSortParam.bHasHeader = bHasHeader;
478 : :
479 [ # # ][ # # ]: 0 : aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) );
[ # # ]
480 : :
481 [ # # ]: 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
482 : : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
483 : :
484 [ # # ][ # # ]: 0 : pDlg = pFact->CreateScSortDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SORT );
485 : : OSL_ENSURE(pDlg, "Dialog create fail!");
486 [ # # ]: 0 : pDlg->SetCurPageId(1); // 1=sort field tab 2=sort options tab
487 : :
488 [ # # ][ # # ]: 0 : if ( pDlg->Execute() == RET_OK )
489 : : {
490 [ # # ]: 0 : const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
491 : : const ScSortParam& rOutParam = ((const ScSortItem&)
492 [ # # ]: 0 : pOutSet->Get( SCITEM_SORTDATA )).GetSortData();
493 : :
494 : : // subtotal when needed new
495 : :
496 [ # # ]: 0 : pTabViewShell->UISort( rOutParam );
497 : :
498 [ # # ]: 0 : if ( rOutParam.bInplace )
499 : : {
500 : : rReq.AppendItem( SfxBoolItem( SID_SORT_BYROW,
501 [ # # ][ # # ]: 0 : rOutParam.bByRow ) );
[ # # ]
502 : : rReq.AppendItem( SfxBoolItem( SID_SORT_HASHEADER,
503 [ # # ][ # # ]: 0 : rOutParam.bHasHeader ) );
[ # # ]
504 : : rReq.AppendItem( SfxBoolItem( SID_SORT_CASESENS,
505 [ # # ][ # # ]: 0 : rOutParam.bCaseSens ) );
[ # # ]
506 : : rReq.AppendItem( SfxBoolItem( SID_SORT_NATURALSORT,
507 [ # # ][ # # ]: 0 : rOutParam.bNaturalSort ) );
[ # # ]
508 : : rReq.AppendItem( SfxBoolItem( SID_SORT_ATTRIBS,
509 [ # # ][ # # ]: 0 : rOutParam.bIncludePattern ) );
[ # # ]
510 [ # # ]: 0 : sal_uInt16 nUser = rOutParam.bUserDef ? ( rOutParam.nUserIndex + 1 ) : 0;
511 [ # # ][ # # ]: 0 : rReq.AppendItem( SfxUInt16Item( SID_SORT_USERDEF, nUser ) );
[ # # ]
512 [ # # ]: 0 : if ( rOutParam.maKeyState[0].bDoSort )
513 : : {
514 : : rReq.AppendItem( SfxInt32Item( FN_PARAM_1,
515 [ # # ][ # # ]: 0 : rOutParam.maKeyState[0].nField + 1 ) );
[ # # ]
516 : : rReq.AppendItem( SfxBoolItem( FN_PARAM_2,
517 [ # # ][ # # ]: 0 : rOutParam.maKeyState[0].bAscending ) );
[ # # ]
518 : : }
519 [ # # ]: 0 : if ( rOutParam.maKeyState[1].bDoSort )
520 : : {
521 : : rReq.AppendItem( SfxInt32Item( FN_PARAM_3,
522 [ # # ][ # # ]: 0 : rOutParam.maKeyState[1].nField + 1 ) );
[ # # ]
523 : : rReq.AppendItem( SfxBoolItem( FN_PARAM_4,
524 [ # # ][ # # ]: 0 : rOutParam.maKeyState[1].bAscending ) );
[ # # ]
525 : : }
526 [ # # ]: 0 : if ( rOutParam.maKeyState[2].bDoSort )
527 : : {
528 : : rReq.AppendItem( SfxInt32Item( FN_PARAM_5,
529 [ # # ][ # # ]: 0 : rOutParam.maKeyState[2].nField + 1 ) );
[ # # ]
530 : : rReq.AppendItem( SfxBoolItem( FN_PARAM_6,
531 [ # # ][ # # ]: 0 : rOutParam.maKeyState[2].bAscending ) );
[ # # ]
532 : : }
533 : : }
534 : :
535 [ # # ]: 0 : rReq.Done();
536 : : }
537 : : else
538 [ # # ]: 0 : GetViewData()->GetDocShell()->CancelAutoDBRange();
539 : :
540 [ # # ][ # # ]: 0 : delete pDlg;
[ # # ]
541 [ # # ]: 0 : }
542 : : }
543 : : }
544 : 0 : break;
545 : :
546 : : case SID_FILTER:
547 : : {
548 : 0 : const SfxItemSet* pArgs = rReq.GetArgs();
549 [ # # ]: 0 : if ( pArgs )
550 : : {
551 : : OSL_FAIL("SID_FILTER with arguments?");
552 : : pTabViewShell->Query( ((const ScQueryItem&)
553 : 0 : pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), NULL, sal_True );
554 : 0 : rReq.Done();
555 : : }
556 : : else
557 : : {
558 : 0 : sal_uInt16 nId = ScFilterDlgWrapper::GetChildWindowId();
559 : 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
560 : 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
561 : :
562 : 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
563 : : }
564 : : }
565 : 0 : break;
566 : :
567 : : case SID_SPECIAL_FILTER:
568 : : {
569 : 0 : const SfxItemSet* pArgs = rReq.GetArgs();
570 [ # # ]: 0 : if ( pArgs )
571 : : {
572 : : OSL_FAIL("SID_SPECIAL_FILTER with arguments?");
573 : : pTabViewShell->Query( ((const ScQueryItem&)
574 : 0 : pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), NULL, sal_True );
575 : 0 : rReq.Done();
576 : : }
577 : : else
578 : : {
579 : 0 : sal_uInt16 nId = ScSpecialFilterDlgWrapper::GetChildWindowId();
580 : 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
581 : 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
582 : :
583 : 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
584 : : }
585 : : }
586 : 0 : break;
587 : :
588 : : case FID_FILTER_OK:
589 : : {
590 : : const SfxPoolItem* pItem;
591 [ # # ][ # # ]: 0 : if ( pReqArgs && SFX_ITEM_SET ==
[ # # ]
592 [ # # ]: 0 : pReqArgs->GetItemState( SCITEM_QUERYDATA, sal_True, &pItem ) )
593 : : {
594 : 0 : const ScQueryItem& rQueryItem = static_cast<const ScQueryItem&>(*pItem);
595 : :
596 : 0 : SCTAB nCurTab = GetViewData()->GetTabNo();
597 : 0 : SCTAB nRefTab = GetViewData()->GetRefTabNo();
598 : :
599 : : // If RefInput switched to a different sheet from the data sheet,
600 : : // switch back:
601 : :
602 [ # # ]: 0 : if ( nCurTab != nRefTab )
603 : : {
604 [ # # ]: 0 : pTabViewShell->SetTabNo( nRefTab );
605 [ # # ]: 0 : pTabViewShell->PaintExtras();
606 : : }
607 : :
608 : 0 : ScRange aAdvSource;
609 [ # # ][ # # ]: 0 : if (rQueryItem.GetAdvancedQuerySource(aAdvSource))
610 [ # # ][ # # ]: 0 : pTabViewShell->Query( rQueryItem.GetQueryData(), &aAdvSource, sal_True );
611 : : else
612 [ # # ][ # # ]: 0 : pTabViewShell->Query( rQueryItem.GetQueryData(), NULL, sal_True );
613 [ # # ]: 0 : rReq.Done( *pReqArgs );
614 : : }
615 : : }
616 : 0 : break;
617 : :
618 : : case SID_UNFILTER:
619 : : {
620 [ # # ]: 0 : ScQueryParam aParam;
621 [ # # ]: 0 : ScDBData* pDBData = pTabViewShell->GetDBData();
622 : :
623 [ # # ]: 0 : pDBData->GetQueryParam( aParam );
624 [ # # ]: 0 : SCSIZE nEC = aParam.GetEntryCount();
625 [ # # ]: 0 : for (SCSIZE i=0; i<nEC; i++)
626 [ # # ]: 0 : aParam.GetEntry(i).bDoQuery = false;
627 : 0 : aParam.bDuplicate = sal_True;
628 [ # # ]: 0 : pTabViewShell->Query( aParam, NULL, sal_True );
629 [ # # ][ # # ]: 0 : rReq.Done();
630 : : }
631 : 0 : break;
632 : :
633 : : case SID_AUTO_FILTER:
634 : 0 : pTabViewShell->ToggleAutoFilter();
635 : 0 : rReq.Done();
636 : 0 : break;
637 : :
638 : : case SID_AUTOFILTER_HIDE:
639 : 0 : pTabViewShell->HideAutoFilter();
640 : 0 : rReq.Done();
641 : 0 : break;
642 : :
643 : : case SID_PIVOT_TABLE:
644 : : {
645 : : const SfxPoolItem* pItem;
646 [ # # ][ # # ]: 0 : if ( pReqArgs && SFX_ITEM_SET ==
[ # # ]
647 [ # # ]: 0 : pReqArgs->GetItemState( SCITEM_PIVOTDATA, sal_True, &pItem ) )
648 : : {
649 : 0 : SCTAB nCurTab = GetViewData()->GetTabNo();
650 : 0 : SCTAB nRefTab = GetViewData()->GetRefTabNo();
651 : :
652 : : // If RefInput switched to a different sheet from the data sheet,
653 : : // switch back:
654 : :
655 [ # # ]: 0 : if ( nCurTab != nRefTab )
656 : : {
657 [ # # ]: 0 : pTabViewShell->SetTabNo( nRefTab );
658 [ # # ]: 0 : pTabViewShell->PaintExtras();
659 : : }
660 : :
661 : 0 : const ScDPObject* pDPObject = pTabViewShell->GetDialogDPObject();
662 [ # # ]: 0 : if ( pDPObject )
663 : : {
664 : 0 : const ScPivotItem* pPItem = (const ScPivotItem*)pItem;
665 : : bool bSuccess = pTabViewShell->MakePivotTable(
666 [ # # ]: 0 : pPItem->GetData(), pPItem->GetDestRange(), pPItem->IsNewSheet(), *pDPObject );
667 [ # # ]: 0 : SfxBoolItem aRet(0, bSuccess);
668 [ # # ][ # # ]: 0 : rReq.SetReturnValue(aRet);
669 : : }
670 [ # # ]: 0 : rReq.Done();
671 : : }
672 : : #ifndef DISABLE_SCRIPTING
673 [ # # ][ # # ]: 0 : else if (rReq.IsAPI())
674 [ # # ]: 0 : SbxBase::SetError(SbxERR_BAD_PARAMETER);
675 : : #endif
676 : : }
677 : 0 : break;
678 : :
679 : : case SID_OPENDLG_PIVOTTABLE:
680 : 0 : ExecuteDataPilotDialog();
681 : 0 : break;
682 : : case SID_DEFINE_DBNAME:
683 : : {
684 : :
685 : 0 : sal_uInt16 nId = ScDbNameDlgWrapper::GetChildWindowId();
686 : 0 : SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
687 : 0 : SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
688 : :
689 : 0 : pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
690 : :
691 : : }
692 : 0 : break;
693 : :
694 : : case SID_SELECT_DB:
695 : : {
696 [ # # ]: 0 : if ( pReqArgs )
697 : : {
698 : : const SfxStringItem* pItem =
699 : 0 : (const SfxStringItem*)&pReqArgs->Get( SID_SELECT_DB );
700 : :
701 [ # # ]: 0 : if( pItem )
702 : : {
703 [ # # ]: 0 : pTabViewShell->GotoDBArea( pItem->GetValue() );
704 : 0 : rReq.Done();
705 : : }
706 : : else
707 : : {
708 : : OSL_FAIL("NULL");
709 : : }
710 : : }
711 : : else
712 : : {
713 : 0 : ScDocument* pDoc = GetViewData()->GetDocument();
714 : 0 : ScDBCollection* pDBCol = pDoc->GetDBCollection();
715 : :
716 [ # # ]: 0 : if ( pDBCol )
717 : : {
718 [ # # ]: 0 : std::vector<String> aList;
719 [ # # ]: 0 : const ScDBCollection::NamedDBs& rDBs = pDBCol->getNamedDBs();
720 [ # # ][ # # ]: 0 : ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
721 [ # # ][ # # ]: 0 : for (; itr != itrEnd; ++itr)
[ # # ]
722 [ # # ][ # # ]: 0 : aList.push_back(itr->GetName());
[ # # ][ # # ]
723 : :
724 [ # # ]: 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
725 : : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
726 : :
727 : : AbstractScSelEntryDlg* pDlg = pFact->CreateScSelEntryDlg( pTabViewShell->GetDialogParent(),
728 : : RID_SCDLG_SELECTDB,
729 : : String(ScResId(SCSTR_SELECTDB)),
730 : : String(ScResId(SCSTR_AREAS)),
731 : : aList,
732 [ # # ][ # # ]: 0 : RID_SCDLG_SELECTDB);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
733 : : OSL_ENSURE(pDlg, "Dialog create fail!");
734 [ # # ][ # # ]: 0 : if ( pDlg->Execute() == RET_OK )
735 : : {
736 [ # # ]: 0 : String aName = pDlg->GetSelectEntry();
737 [ # # ][ # # ]: 0 : pTabViewShell->GotoDBArea( aName );
738 [ # # ][ # # ]: 0 : rReq.AppendItem( SfxStringItem( SID_SELECT_DB, aName ) );
[ # # ]
739 [ # # ][ # # ]: 0 : rReq.Done();
740 : : }
741 : :
742 [ # # ][ # # ]: 0 : delete pDlg;
743 : : }
744 : : }
745 : : }
746 : 0 : break;
747 : :
748 : : case FID_VALIDATION:
749 : : {
750 : : const SfxPoolItem* pItem;
751 : 0 : const SfxItemSet* pArgs = rReq.GetArgs();
752 [ # # ]: 0 : if ( pArgs )
753 : : {
754 : : OSL_FAIL("later...");
755 : : }
756 : : else
757 : : {
758 [ # # ]: 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
759 : : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
760 [ # # ]: 0 : ::GetTabPageRanges ScTPValidationValueGetRanges = pFact->GetTabPageRangesFunc(TP_VALIDATION_VALUES);
761 : : OSL_ENSURE(ScTPValidationValueGetRanges, "TabPage create fail!");
762 [ # # ][ # # ]: 0 : SfxItemSet aArgSet( GetPool(), (*ScTPValidationValueGetRanges)() );
763 : 0 : ScValidationMode eMode = SC_VALID_ANY;
764 : 0 : ScConditionMode eOper = SC_COND_EQUAL;
765 [ # # ][ # # ]: 0 : String aExpr1, aExpr2;
766 : 0 : sal_Bool bBlank = sal_True;
767 : 0 : sal_Int16 nListType = ValidListType::UNSORTED;
768 : 0 : sal_Bool bShowHelp = false;
769 [ # # ][ # # ]: 0 : String aHelpTitle, aHelpText;
770 : 0 : sal_Bool bShowError = false;
771 : 0 : ScValidErrorStyle eErrStyle = SC_VALERR_STOP;
772 [ # # ][ # # ]: 0 : String aErrTitle, aErrText;
773 : :
774 [ # # ]: 0 : ScDocument* pDoc = GetViewData()->GetDocument();
775 : 0 : SCCOL nCurX = GetViewData()->GetCurX();
776 : 0 : SCROW nCurY = GetViewData()->GetCurY();
777 : 0 : SCTAB nTab = GetViewData()->GetTabNo();
778 : 0 : ScAddress aCursorPos( nCurX, nCurY, nTab );
779 : : sal_uLong nIndex = ((SfxUInt32Item*)pDoc->GetAttr(
780 [ # # ]: 0 : nCurX, nCurY, nTab, ATTR_VALIDDATA ))->GetValue();
781 [ # # ]: 0 : if ( nIndex )
782 : : {
783 [ # # ]: 0 : const ScValidationData* pOldData = pDoc->GetValidationEntry( nIndex );
784 [ # # ]: 0 : if ( pOldData )
785 : : {
786 : 0 : eMode = pOldData->GetDataMode();
787 : 0 : eOper = pOldData->GetOperation();
788 : 0 : sal_uLong nNumFmt = 0;
789 [ # # ][ # # ]: 0 : if ( eMode == SC_VALID_DATE || eMode == SC_VALID_TIME )
790 : : {
791 : : short nType = ( eMode == SC_VALID_DATE ) ? NUMBERFORMAT_DATE
792 [ # # ]: 0 : : NUMBERFORMAT_TIME;
793 : : nNumFmt = pDoc->GetFormatTable()->GetStandardFormat(
794 [ # # ][ # # ]: 0 : nType, ScGlobal::eLnge );
795 : : }
796 [ # # ][ # # ]: 0 : aExpr1 = pOldData->GetExpression( aCursorPos, 0, nNumFmt );
[ # # ]
797 [ # # ][ # # ]: 0 : aExpr2 = pOldData->GetExpression( aCursorPos, 1, nNumFmt );
[ # # ]
798 : 0 : bBlank = pOldData->IsIgnoreBlank();
799 : 0 : nListType = pOldData->GetListType();
800 : :
801 [ # # ]: 0 : bShowHelp = pOldData->GetInput( aHelpTitle, aHelpText );
802 [ # # ]: 0 : bShowError = pOldData->GetErrMsg( aErrTitle, aErrText, eErrStyle );
803 : :
804 [ # # ][ # # ]: 0 : aArgSet.Put( SfxAllEnumItem( FID_VALID_MODE, sal::static_int_cast<sal_uInt16>(eMode) ) );
[ # # ]
805 [ # # ][ # # ]: 0 : aArgSet.Put( SfxAllEnumItem( FID_VALID_CONDMODE, sal::static_int_cast<sal_uInt16>(eOper) ) );
[ # # ]
806 [ # # ][ # # ]: 0 : aArgSet.Put( SfxStringItem( FID_VALID_VALUE1, aExpr1 ) );
[ # # ]
807 [ # # ][ # # ]: 0 : aArgSet.Put( SfxStringItem( FID_VALID_VALUE2, aExpr2 ) );
[ # # ]
808 [ # # ][ # # ]: 0 : aArgSet.Put( SfxBoolItem( FID_VALID_BLANK, bBlank ) );
[ # # ]
809 [ # # ][ # # ]: 0 : aArgSet.Put( SfxInt16Item( FID_VALID_LISTTYPE, nListType ) );
[ # # ]
810 [ # # ][ # # ]: 0 : aArgSet.Put( SfxBoolItem( FID_VALID_SHOWHELP, bShowHelp ) );
[ # # ]
811 [ # # ][ # # ]: 0 : aArgSet.Put( SfxStringItem( FID_VALID_HELPTITLE, aHelpTitle ) );
[ # # ]
812 [ # # ][ # # ]: 0 : aArgSet.Put( SfxStringItem( FID_VALID_HELPTEXT, aHelpText ) );
[ # # ]
813 [ # # ][ # # ]: 0 : aArgSet.Put( SfxBoolItem( FID_VALID_SHOWERR, bShowError ) );
[ # # ]
814 [ # # ][ # # ]: 0 : aArgSet.Put( SfxAllEnumItem( FID_VALID_ERRSTYLE, sal::static_int_cast<sal_uInt16>(eErrStyle) ) );
[ # # ]
815 [ # # ][ # # ]: 0 : aArgSet.Put( SfxStringItem( FID_VALID_ERRTITLE, aErrTitle ) );
[ # # ]
816 [ # # ][ # # ]: 0 : aArgSet.Put( SfxStringItem( FID_VALID_ERRTEXT, aErrText ) );
[ # # ]
817 : : }
818 : : }
819 : :
820 : : // cell range picker
821 [ # # ]: 0 : SfxAbstractTabDialog* pDlg = pFact->CreateScValidationDlg( NULL, &aArgSet, TAB_DLG_VALIDATION, pTabViewShell );
822 : : OSL_ENSURE(pDlg, "Dialog create fail!");
823 : :
824 [ # # ]: 0 : short nResult = pDlg->Execute();
825 : : //When picking Cell Range, other Tab may be switched. Need restore the correct tab
826 [ # # ]: 0 : pTabViewShell->SetTabNo( nTab );
827 [ # # ]: 0 : if ( nResult == RET_OK )
828 : : {
829 [ # # ]: 0 : const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
830 : :
831 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_MODE, sal_True, &pItem ) == SFX_ITEM_SET )
832 : 0 : eMode = (ScValidationMode) ((const SfxAllEnumItem*)pItem)->GetValue();
833 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_CONDMODE, sal_True, &pItem ) == SFX_ITEM_SET )
834 : 0 : eOper = (ScConditionMode) ((const SfxAllEnumItem*)pItem)->GetValue();
835 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_VALUE1, sal_True, &pItem ) == SFX_ITEM_SET )
836 : : {
837 [ # # ]: 0 : String aTemp1 = ((const SfxStringItem*)pItem)->GetValue();
838 [ # # ][ # # ]: 0 : if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
839 : : {
840 : 0 : sal_uInt32 nNumIndex = 0;
841 : : double nVal;
842 [ # # ][ # # ]: 0 : if (pDoc->GetFormatTable()->IsNumberFormat(aTemp1, nNumIndex, nVal))
[ # # ]
843 : : aExpr1 =String( ::rtl::math::doubleToUString( nVal,
844 : : rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
845 [ # # ][ # # ]: 0 : ScGlobal::pLocaleData->getNumDecimalSep()[0], sal_True));
[ # # ][ # # ]
846 : : else
847 [ # # ]: 0 : aExpr1 = aTemp1;
848 : : }
849 : : else
850 [ # # ][ # # ]: 0 : aExpr1 = aTemp1;
851 : : }
852 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_VALUE2, sal_True, &pItem ) == SFX_ITEM_SET )
853 : : {
854 [ # # ]: 0 : String aTemp2 = ((const SfxStringItem*)pItem)->GetValue();
855 [ # # ][ # # ]: 0 : if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
856 : : {
857 : 0 : sal_uInt32 nNumIndex = 0;
858 : : double nVal;
859 [ # # ][ # # ]: 0 : if (pDoc->GetFormatTable()->IsNumberFormat(aTemp2, nNumIndex, nVal))
[ # # ]
860 : : aExpr2 =String( ::rtl::math::doubleToUString( nVal,
861 : : rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
862 [ # # ][ # # ]: 0 : ScGlobal::pLocaleData->getNumDecimalSep()[0], sal_True));
[ # # ][ # # ]
863 : : else
864 [ # # ]: 0 : aExpr2 = aTemp2;
865 : : }
866 : : else
867 [ # # ][ # # ]: 0 : aExpr2 = aTemp2;
868 : : }
869 : :
870 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_BLANK, sal_True, &pItem ) == SFX_ITEM_SET )
871 : 0 : bBlank = ((const SfxBoolItem*)pItem)->GetValue();
872 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_LISTTYPE, sal_True, &pItem ) == SFX_ITEM_SET )
873 : 0 : nListType = ((const SfxInt16Item*)pItem)->GetValue();
874 : :
875 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_SHOWHELP, sal_True, &pItem ) == SFX_ITEM_SET )
876 : 0 : bShowHelp = ((const SfxBoolItem*)pItem)->GetValue();
877 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_HELPTITLE, sal_True, &pItem ) == SFX_ITEM_SET )
878 [ # # ]: 0 : aHelpTitle = ((const SfxStringItem*)pItem)->GetValue();
879 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_HELPTEXT, sal_True, &pItem ) == SFX_ITEM_SET )
880 [ # # ]: 0 : aHelpText = ((const SfxStringItem*)pItem)->GetValue();
881 : :
882 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_SHOWERR, sal_True, &pItem ) == SFX_ITEM_SET )
883 : 0 : bShowError = ((const SfxBoolItem*)pItem)->GetValue();
884 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_ERRSTYLE, sal_True, &pItem ) == SFX_ITEM_SET )
885 : 0 : eErrStyle = (ScValidErrorStyle) ((const SfxAllEnumItem*)pItem)->GetValue();
886 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_ERRTITLE, sal_True, &pItem ) == SFX_ITEM_SET )
887 [ # # ]: 0 : aErrTitle = ((const SfxStringItem*)pItem)->GetValue();
888 [ # # ][ # # ]: 0 : if ( pOutSet->GetItemState( FID_VALID_ERRTEXT, sal_True, &pItem ) == SFX_ITEM_SET )
889 [ # # ]: 0 : aErrText = ((const SfxStringItem*)pItem)->GetValue();
890 : :
891 [ # # ]: 0 : ScValidationData aData( eMode, eOper, aExpr1, aExpr2, pDoc, aCursorPos );
892 [ # # ]: 0 : aData.SetIgnoreBlank( bBlank );
893 : 0 : aData.SetListType( nListType );
894 : :
895 [ # # ]: 0 : aData.SetInput(aHelpTitle, aHelpText); // sets bShowInput to TRUE
896 [ # # ]: 0 : if (!bShowHelp)
897 [ # # ]: 0 : aData.ResetInput(); // reset only bShowInput
898 : :
899 [ # # ]: 0 : aData.SetError(aErrTitle, aErrText, eErrStyle); // sets bShowError to TRUE
900 [ # # ]: 0 : if (!bShowError)
901 [ # # ]: 0 : aData.ResetError(); // reset only bShowError
902 : :
903 [ # # ]: 0 : pTabViewShell->SetValidation( aData );
904 [ # # ]: 0 : pTabViewShell->TestHintWindow();
905 [ # # ][ # # ]: 0 : rReq.Done( *pOutSet );
906 : : }
907 : : //after end execute from !IsModalInputMode, it is safer to delay deleting
908 : : //delete pDlg;
909 [ # # ][ # # ]: 0 : Application::PostUserEvent( Link( pDlg, &DelayDeleteAbstractDialog ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
910 : : }
911 : : }
912 : 0 : break;
913 : :
914 : : case SID_TEXT_TO_COLUMNS:
915 : : {
916 : 0 : ScViewData* pData = GetViewData();
917 : : OSL_ENSURE( pData, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pData is null!" );
918 : 0 : ScRange aRange;
919 : :
920 [ # # ][ # # ]: 0 : if ( lcl_GetTextToColumnsRange( pData, aRange ) )
921 : : {
922 [ # # ]: 0 : ScDocument* pDoc = pData->GetDocument();
923 : : OSL_ENSURE( pDoc, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDoc is null!" );
924 : :
925 [ # # ]: 0 : ScImportExport aExport( pDoc, aRange );
926 : 0 : aExport.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::None, 0, false ) );
927 : :
928 : : // #i87703# text to columns fails with tab separator
929 : 0 : aExport.SetDelimiter( static_cast< sal_Unicode >( 0 ) );
930 : :
931 [ # # ]: 0 : SvMemoryStream aStream;
932 : 0 : aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
933 [ # # ]: 0 : ScImportExport::SetNoEndianSwap( aStream );
934 [ # # ][ # # ]: 0 : aExport.ExportStream( aStream, String(), FORMAT_STRING );
[ # # ]
935 : :
936 [ # # ]: 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
937 : : OSL_ENSURE( pFact, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pFact is null!" );
938 : : AbstractScImportAsciiDlg *pDlg = pFact->CreateScImportAsciiDlg(
939 [ # # ][ # # ]: 0 : NULL, String(), &aStream, RID_SCDLG_ASCII,SC_TEXTTOCOLUMNS);
[ # # ]
940 : : OSL_ENSURE( pDlg, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDlg is null!" );
941 : :
942 [ # # ][ # # ]: 0 : if ( pDlg->Execute() == RET_OK )
943 : : {
944 : 0 : ScDocShell* pDocSh = pData->GetDocShell();
945 : : OSL_ENSURE( pDocSh, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" );
946 : :
947 [ # # ][ # # ]: 0 : String aUndo = ScGlobal::GetRscString( STR_UNDO_TEXTTOCOLUMNS );
948 [ # # ][ # # ]: 0 : pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
949 : :
950 [ # # ]: 0 : ScImportExport aImport( pDoc, aRange.aStart );
951 [ # # ]: 0 : ScAsciiOptions aOptions;
952 [ # # ]: 0 : pDlg->GetOptions( aOptions );
953 [ # # ]: 0 : pDlg->SaveParameters();
954 [ # # ]: 0 : aImport.SetExtOptions( aOptions );
955 : 0 : aImport.SetApi( false );
956 [ # # ]: 0 : aStream.Seek( 0 );
957 [ # # ][ # # ]: 0 : aImport.ImportStream( aStream, String(), FORMAT_STRING );
[ # # ]
958 : :
959 [ # # ][ # # ]: 0 : pDocSh->GetUndoManager()->LeaveListAction();
[ # # ][ # # ]
[ # # ]
960 : : }
961 [ # # ][ # # ]: 0 : delete pDlg;
[ # # ][ # # ]
962 : : }
963 : : }
964 : 0 : break;
965 : : }
966 : 0 : }
967 : :
968 : 654 : void ScCellShell::GetDBState( SfxItemSet& rSet )
969 : : {
970 : 654 : ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
971 : 654 : ScViewData* pData = GetViewData();
972 : 654 : ScDocShell* pDocSh = pData->GetDocShell();
973 : 654 : ScDocument* pDoc = pDocSh->GetDocument();
974 : 654 : SCCOL nPosX = pData->GetCurX();
975 : 654 : SCROW nPosY = pData->GetCurY();
976 : 654 : SCTAB nTab = pData->GetTabNo();
977 : :
978 : 654 : sal_Bool bAutoFilter = false;
979 : 654 : sal_Bool bAutoFilterTested = false;
980 : :
981 [ + - ]: 654 : SfxWhichIter aIter(rSet);
982 [ + - ]: 654 : sal_uInt16 nWhich = aIter.FirstWhich();
983 [ + + ]: 1458 : while (nWhich)
984 : : {
985 [ - - + - : 804 : switch (nWhich)
+ - - - -
- - ]
986 : : {
987 : : case SID_REFRESH_DBAREA:
988 : : {
989 : : // imported data without selection
990 : : // or filter,sort,subtotal (also without import)
991 : 0 : sal_Bool bOk = false;
992 [ # # ]: 0 : ScDBData* pDBData = pTabViewShell->GetDBData(false,SC_DB_OLD);
993 [ # # ][ # # ]: 0 : if (pDBData && pDoc->GetChangeTrack() == NULL)
[ # # ]
994 : : {
995 [ # # ][ # # ]: 0 : if ( pDBData->HasImportParam() )
996 : 0 : bOk = !pDBData->HasImportSelection();
997 : : else
998 : : {
999 [ # # ]: 0 : bOk = pDBData->HasQueryParam() ||
1000 [ # # ]: 0 : pDBData->HasSortParam() ||
1001 [ # # ][ # # ]: 0 : pDBData->HasSubTotalParam();
[ # # ][ # # ]
1002 : : }
1003 : : }
1004 [ # # ]: 0 : if (!bOk)
1005 [ # # ]: 0 : rSet.DisableItem( nWhich );
1006 : : }
1007 : 0 : break;
1008 : :
1009 : : case SID_FILTER:
1010 : : case SID_SPECIAL_FILTER:
1011 : : {
1012 : 0 : ScRange aDummy;
1013 [ # # ]: 0 : ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy);
1014 [ # # ][ # # ]: 0 : if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1015 : : {
1016 [ # # ]: 0 : rSet.DisableItem( nWhich );
1017 : : }
1018 : : }
1019 : 0 : break;
1020 : :
1021 : :
1022 : : //in case of Redlining and multiselection disable
1023 : : case SID_SORT_ASCENDING:
1024 : : case SID_SORT_DESCENDING:
1025 : : case SCITEM_SORTDATA:
1026 : : case SCITEM_SUBTDATA:
1027 : : case SID_OPENDLG_PIVOTTABLE:
1028 : : {
1029 : : //! move ReadOnly check to idl flags
1030 : :
1031 [ + - ][ + - ]: 1072 : if ( pDocSh->IsReadOnly() || pDoc->GetChangeTrack()!=NULL ||
[ + - ][ - + ]
[ - + ]
1032 [ + - ]: 536 : GetViewData()->IsMultiMarked() )
1033 : : {
1034 [ # # ]: 0 : rSet.DisableItem( nWhich );
1035 : : }
1036 : : }
1037 : 536 : break;
1038 : :
1039 : : case SID_REIMPORT_DATA:
1040 : : {
1041 : : // only imported data without selection
1042 [ # # ]: 0 : ScDBData* pDBData = pTabViewShell->GetDBData(false,SC_DB_OLD);
1043 [ # # ][ # # ]: 0 : if (!pDBData || !pDBData->HasImportParam() || pDBData->HasImportSelection() ||
[ # # ]
[ # # # # ]
[ # # ]
1044 : 0 : pDoc->GetChangeTrack()!=NULL)
1045 : : {
1046 [ # # ]: 0 : rSet.DisableItem( nWhich );
1047 : : }
1048 : : }
1049 : 0 : break;
1050 : :
1051 : : case SID_VIEW_DATA_SOURCE_BROWSER:
1052 : : {
1053 [ + - ][ + - ]: 268 : if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
[ + - ][ - + ]
1054 [ # # ][ # # ]: 0 : rSet.Put(SfxVisibilityItem(nWhich, false));
[ # # ]
1055 : : else
1056 : : // get state (BoolItem) from SfxViewFrame
1057 [ + - ]: 268 : pTabViewShell->GetViewFrame()->GetSlotState( nWhich, NULL, &rSet );
1058 : : }
1059 : 268 : break;
1060 : : case SID_SBA_BRW_INSERT:
1061 : : {
1062 : : // SBA wants a sal_Bool-item, enabled
1063 : :
1064 : 0 : sal_Bool bEnable = sal_True;
1065 [ # # ][ # # ]: 0 : rSet.Put(SfxBoolItem(nWhich, bEnable));
[ # # ]
1066 : : }
1067 : 0 : break;
1068 : :
1069 : : case SID_AUTO_FILTER:
1070 : : case SID_AUTOFILTER_HIDE:
1071 : : {
1072 [ # # ]: 0 : if (!bAutoFilterTested)
1073 : : {
1074 [ # # ]: 0 : bAutoFilter = pDoc->HasAutoFilter( nPosX, nPosY, nTab );
1075 : 0 : bAutoFilterTested = sal_True;
1076 : : }
1077 [ # # ]: 0 : if ( nWhich == SID_AUTO_FILTER )
1078 : : {
1079 : 0 : ScRange aDummy;
1080 [ # # ]: 0 : ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy);
1081 [ # # ][ # # ]: 0 : if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1082 : : {
1083 [ # # ]: 0 : rSet.DisableItem( nWhich );
1084 : : }
1085 [ # # ][ # # ]: 0 : else if (pDoc->GetDPAtBlock(aDummy))
1086 : : {
1087 [ # # ]: 0 : rSet.DisableItem( nWhich );
1088 : : }
1089 : : else
1090 [ # # ][ # # ]: 0 : rSet.Put( SfxBoolItem( nWhich, bAutoFilter ) );
[ # # ]
1091 : : }
1092 : : else
1093 [ # # ]: 0 : if (!bAutoFilter)
1094 [ # # ]: 0 : rSet.DisableItem( nWhich );
1095 : : }
1096 : 0 : break;
1097 : :
1098 : : case SID_UNFILTER:
1099 : : {
1100 : : SCCOL nStartCol, nEndCol;
1101 : : SCROW nStartRow, nEndRow;
1102 : : SCTAB nStartTab, nEndTab;
1103 : 0 : sal_Bool bAnyQuery = false;
1104 : :
1105 : : sal_Bool bSelected = (GetViewData()->GetSimpleArea(
1106 [ # # ]: 0 : nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab )
1107 : 0 : == SC_MARK_SIMPLE);
1108 : :
1109 [ # # ]: 0 : if ( bSelected )
1110 : : {
1111 [ # # ][ # # ]: 0 : if (nStartCol==nEndCol && nStartRow==nEndRow)
1112 : 0 : bSelected = false;
1113 : : }
1114 : : else
1115 : : {
1116 : 0 : nStartCol = GetViewData()->GetCurX();
1117 : 0 : nStartRow = GetViewData()->GetCurY();
1118 : 0 : nStartTab = GetViewData()->GetTabNo();
1119 : : }
1120 : :
1121 : : ScDBData* pDBData = bSelected
1122 : 0 : ? pDoc->GetDBAtArea( nStartTab, nStartCol, nStartRow, nEndCol, nEndRow )
1123 [ # # ][ # # ]: 0 : : pDoc->GetDBAtCursor( nStartCol, nStartRow, nStartTab );
[ # # ]
1124 : :
1125 [ # # ]: 0 : if ( pDBData )
1126 : : {
1127 [ # # ]: 0 : ScQueryParam aParam;
1128 [ # # ]: 0 : pDBData->GetQueryParam( aParam );
1129 [ # # ][ # # ]: 0 : if ( aParam.GetEntry(0).bDoQuery )
1130 [ # # ]: 0 : bAnyQuery = sal_True;
1131 : : }
1132 : :
1133 [ # # ]: 0 : if ( !bAnyQuery )
1134 [ # # ]: 0 : rSet.DisableItem( nWhich );
1135 : : }
1136 : 0 : break;
1137 : :
1138 : : case SID_DEFINE_DBNAME:
1139 : : {
1140 [ # # ][ # # ]: 0 : if ( pDocSh && pDocSh->IsDocShared() )
[ # # ][ # # ]
1141 : : {
1142 [ # # ]: 0 : rSet.DisableItem( nWhich );
1143 : : }
1144 : : }
1145 : 0 : break;
1146 : :
1147 : : case SID_TEXT_TO_COLUMNS:
1148 : : {
1149 : 0 : ScRange aRange;
1150 [ # # ][ # # ]: 0 : if ( !lcl_GetTextToColumnsRange( pData, aRange ) )
1151 : : {
1152 [ # # ]: 0 : rSet.DisableItem( nWhich );
1153 : : }
1154 : : }
1155 : 0 : break;
1156 : : }
1157 [ + - ]: 804 : nWhich = aIter.NextWhich();
1158 [ + - ]: 654 : }
1159 : 654 : }
1160 : :
1161 : :
1162 : :
1163 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|