File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | |||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | |||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | |||
12 | * contributor license agreements. See the NOTICE file distributed | |||
13 | * with this work for additional information regarding copyright | |||
14 | * ownership. The ASF licenses this file to you under the Apache | |||
15 | * License, Version 2.0 (the "License"); you may not use this file | |||
16 | * except in compliance with the License. You may obtain a copy of | |||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | |||
18 | */ | |||
19 | ||||
20 | #include <config_features.h> | |||
21 | ||||
22 | #include <basic/sberrors.hxx> | |||
23 | #include <scitems.hxx> | |||
24 | #include <comphelper/lok.hxx> | |||
25 | #include <sfx2/viewfrm.hxx> | |||
26 | #include <sfx2/request.hxx> | |||
27 | #include <sfx2/sfxdlg.hxx> | |||
28 | #include <svl/aeitem.hxx> | |||
29 | #include <basic/sbxcore.hxx> | |||
30 | #include <svl/whiter.hxx> | |||
31 | #include <svl/zforlist.hxx> | |||
32 | #include <svl/stritem.hxx> | |||
33 | #include <svl/visitem.hxx> | |||
34 | #include <svtools/miscopt.hxx> | |||
35 | #include <unotools/moduleoptions.hxx> | |||
36 | ||||
37 | #include <com/sun/star/frame/FrameSearchFlag.hpp> | |||
38 | #include <com/sun/star/sheet/TableValidationVisibility.hpp> | |||
39 | ||||
40 | #include <cellsh.hxx> | |||
41 | #include <dbdata.hxx> | |||
42 | #include <queryparam.hxx> | |||
43 | #include <tabvwsh.hxx> | |||
44 | #include <sc.hrc> | |||
45 | #include <globstr.hrc> | |||
46 | #include <scresid.hxx> | |||
47 | #include <global.hxx> | |||
48 | #include <scmod.hxx> | |||
49 | #include <docsh.hxx> | |||
50 | #include <document.hxx> | |||
51 | #include <uiitems.hxx> | |||
52 | #include <dbdocfun.hxx> | |||
53 | #include <reffact.hxx> | |||
54 | #include <validat.hxx> | |||
55 | #include <validate.hxx> | |||
56 | #include <datamapper.hxx> | |||
57 | ||||
58 | #include <scui_def.hxx> | |||
59 | #include <scabstdlg.hxx> | |||
60 | #include <impex.hxx> | |||
61 | #include <asciiopt.hxx> | |||
62 | #include <datastream.hxx> | |||
63 | #include <datastreamdlg.hxx> | |||
64 | #include <dataproviderdlg.hxx> | |||
65 | #include <queryentry.hxx> | |||
66 | #include <markdata.hxx> | |||
67 | #include <documentlinkmgr.hxx> | |||
68 | ||||
69 | #include <o3tl/make_shared.hxx> | |||
70 | #include <memory> | |||
71 | ||||
72 | using namespace com::sun::star; | |||
73 | ||||
74 | static bool lcl_GetTextToColumnsRange( const ScViewData* pData, ScRange& rRange, bool bDoEmptyCheckOnly ) | |||
75 | { | |||
76 | OSL_ENSURE( pData, "lcl_GetTextToColumnsRange: pData is null!" )do { if (true && (!(pData))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh2.cxx" ":" "76" ": "), "%s", "lcl_GetTextToColumnsRange: pData is null!" ); } } while (false); | |||
77 | ||||
78 | bool bRet = false; | |||
79 | const ScMarkData& rMark = pData->GetMarkData(); | |||
80 | ||||
81 | if ( rMark.IsMarked() ) | |||
82 | { | |||
83 | if ( !rMark.IsMultiMarked() ) | |||
84 | { | |||
85 | rMark.GetMarkArea( rRange ); | |||
86 | if ( rRange.aStart.Col() == rRange.aEnd.Col() ) | |||
87 | { | |||
88 | bRet = true; | |||
89 | } | |||
90 | } | |||
91 | } | |||
92 | else | |||
93 | { | |||
94 | const SCCOL nCol = pData->GetCurX(); | |||
95 | const SCROW nRow = pData->GetCurY(); | |||
96 | const SCTAB nTab = pData->GetTabNo(); | |||
97 | rRange = ScRange( nCol, nRow, nTab, nCol, nRow, nTab ); | |||
98 | bRet = true; | |||
99 | } | |||
100 | ||||
101 | const ScDocument& rDoc = pData->GetDocument(); | |||
102 | ||||
103 | if ( bDoEmptyCheckOnly ) | |||
104 | { | |||
105 | if ( bRet && rDoc.IsBlockEmpty( rRange.aStart.Tab(), rRange.aStart.Col(), | |||
106 | rRange.aStart.Row(), rRange.aEnd.Col(), | |||
107 | rRange.aEnd.Row() ) ) | |||
108 | { | |||
109 | bRet = false; | |||
110 | } | |||
111 | } | |||
112 | else if ( bRet ) | |||
113 | { | |||
114 | rRange.PutInOrder(); | |||
115 | SCCOL nStartCol = rRange.aStart.Col(), nEndCol = rRange.aEnd.Col(); | |||
116 | SCROW nStartRow = rRange.aStart.Row(), nEndRow = rRange.aEnd.Row(); | |||
117 | bool bShrunk = false; | |||
118 | rDoc.ShrinkToUsedDataArea( bShrunk, rRange.aStart.Tab(), nStartCol, nStartRow, | |||
119 | nEndCol, nEndRow, false, false, true ); | |||
120 | if ( bShrunk ) | |||
121 | { | |||
122 | rRange.aStart.SetRow( nStartRow ); | |||
123 | rRange.aEnd.SetRow( nEndRow ); | |||
124 | } | |||
125 | } | |||
126 | ||||
127 | return bRet; | |||
128 | } | |||
129 | ||||
130 | static bool lcl_GetSortParam( const ScViewData* pData, const ScSortParam& rSortParam ) | |||
131 | { | |||
132 | ScTabViewShell* pTabViewShell = pData->GetViewShell(); | |||
133 | ScDBData* pDBData = pTabViewShell->GetDBData(); | |||
134 | ScDocument& rDoc = pData->GetDocument(); | |||
135 | SCTAB nTab = pData->GetTabNo(); | |||
136 | ScDirection eFillDir = DIR_TOP; | |||
137 | bool bSort = true; | |||
138 | ScRange aExternalRange; | |||
139 | ||||
140 | if( rSortParam.nCol1 != rSortParam.nCol2 ) | |||
141 | eFillDir = DIR_LEFT; | |||
142 | if( rSortParam.nRow1 != rSortParam.nRow2 ) | |||
143 | eFillDir = DIR_TOP; | |||
144 | ||||
145 | if( rSortParam.nRow2 == rDoc.MaxRow() ) | |||
146 | { | |||
147 | // Assume that user selected entire column(s), but cater for the | |||
148 | // possibility that the start row is not the first row. | |||
149 | SCSIZE nCount = rDoc.GetEmptyLinesInBlock( rSortParam.nCol1, rSortParam.nRow1, nTab, | |||
150 | rSortParam.nCol2, rSortParam.nRow2, nTab, eFillDir ); | |||
151 | aExternalRange = ScRange( rSortParam.nCol1, | |||
152 | ::std::min( rSortParam.nRow1 + sal::static_int_cast<SCROW>( nCount ), rDoc.MaxRow()), nTab, | |||
153 | rSortParam.nCol2, rSortParam.nRow2, nTab); | |||
154 | aExternalRange.PutInOrder(); | |||
155 | } | |||
156 | else if (rSortParam.nCol1 != rSortParam.nCol2 || rSortParam.nRow1 != rSortParam.nRow2) | |||
157 | { | |||
158 | // Preserve a preselected area. | |||
159 | aExternalRange = ScRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab); | |||
160 | aExternalRange.PutInOrder(); | |||
161 | } | |||
162 | else | |||
163 | aExternalRange = ScRange( pData->GetCurX(), pData->GetCurY(), nTab ); | |||
164 | ||||
165 | SCROW nStartRow = aExternalRange.aStart.Row(); | |||
166 | SCCOL nStartCol = aExternalRange.aStart.Col(); | |||
167 | SCROW nEndRow = aExternalRange.aEnd.Row(); | |||
168 | SCCOL nEndCol = aExternalRange.aEnd.Col(); | |||
169 | rDoc.GetDataArea( aExternalRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow, false, false ); | |||
170 | aExternalRange.aStart.SetRow( nStartRow ); | |||
171 | aExternalRange.aStart.SetCol( nStartCol ); | |||
172 | aExternalRange.aEnd.SetRow( nEndRow ); | |||
173 | aExternalRange.aEnd.SetCol( nEndCol ); | |||
174 | ||||
175 | // with LibreOfficeKit, don't try to interact with the user | |||
176 | if (!comphelper::LibreOfficeKit::isActive() && | |||
177 | ((rSortParam.nCol1 == rSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col()) || | |||
178 | (rSortParam.nRow1 == rSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row()))) | |||
179 | { | |||
180 | pTabViewShell->AddHighlightRange( aExternalRange,COL_LIGHTBLUE ); | |||
181 | OUString aExtendStr( aExternalRange.Format(rDoc, ScRefFlags::VALID)); | |||
182 | ||||
183 | ScRange aCurrentRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab ); | |||
184 | OUString aCurrentStr(aCurrentRange.Format(rDoc, ScRefFlags::VALID)); | |||
185 | ||||
186 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); | |||
187 | ||||
188 | ScopedVclPtr<AbstractScSortWarningDlg> pWarningDlg(pFact->CreateScSortWarningDlg(pTabViewShell->GetFrameWeld(), aExtendStr, aCurrentStr)); | |||
189 | short bResult = pWarningDlg->Execute(); | |||
190 | if( bResult == BTN_EXTEND_RANGE150 || bResult == BTN_CURRENT_SELECTION151 ) | |||
191 | { | |||
192 | if( bResult == BTN_EXTEND_RANGE150 ) | |||
193 | { | |||
194 | pTabViewShell->MarkRange( aExternalRange, false ); | |||
195 | pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() ); | |||
196 | } | |||
197 | } | |||
198 | else | |||
199 | { | |||
200 | bSort = false; | |||
201 | pData->GetDocShell()->CancelAutoDBRange(); | |||
202 | } | |||
203 | ||||
204 | pTabViewShell->ClearHighlightRanges(); | |||
205 | } | |||
206 | return bSort; | |||
207 | } | |||
208 | ||||
209 | namespace | |||
210 | { | |||
211 | // this registers the dialog which Find1RefWindow search for | |||
212 | class ScValidationRegisteredDlg | |||
213 | { | |||
214 | std::shared_ptr<SfxDialogController> m_xDlg; | |||
215 | public: | |||
216 | ScValidationRegisteredDlg(weld::Window* pParent, const std::shared_ptr<SfxDialogController>& rDlg) | |||
217 | : m_xDlg(rDlg) | |||
218 | { | |||
219 | SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule ::Calc)) )->RegisterRefController(static_cast<sal_uInt16>(ScValidationDlg::SLOTID), m_xDlg, pParent); | |||
220 | } | |||
221 | ~ScValidationRegisteredDlg() | |||
222 | { | |||
223 | m_xDlg->Close(); | |||
224 | SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule ::Calc)) )->UnregisterRefController(static_cast<sal_uInt16>(ScValidationDlg::SLOTID), m_xDlg); | |||
225 | } | |||
226 | }; | |||
227 | } | |||
228 | ||||
229 | void ScCellShell::ExecuteDB( SfxRequest& rReq ) | |||
230 | { | |||
231 | ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); | |||
232 | sal_uInt16 nSlotId = rReq.GetSlot(); | |||
233 | const SfxItemSet* pReqArgs = rReq.GetArgs(); | |||
234 | ScModule* pScMod = SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule ::Calc)) ); | |||
235 | ||||
236 | pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox | |||
237 | ||||
238 | if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) ) | |||
| ||||
239 | { | |||
240 | pScMod->InputEnterHandler(); | |||
241 | pTabViewShell->UpdateInputHandler(); | |||
242 | } | |||
243 | ||||
244 | switch ( nSlotId ) | |||
245 | { | |||
246 | case SID_VIEW_DATA_SOURCE_BROWSER(5000 + 1660): | |||
247 | { | |||
248 | // check if database beamer is open | |||
249 | ||||
250 | SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame(); | |||
251 | bool bWasOpen = false; | |||
252 | { | |||
253 | uno::Reference<frame::XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface(); | |||
254 | uno::Reference<frame::XFrame> xBeamerFrame = xFrame->findFrame( | |||
255 | "_beamer", | |||
256 | frame::FrameSearchFlag::CHILDREN); | |||
257 | if ( xBeamerFrame.is() ) | |||
258 | bWasOpen = true; | |||
259 | } | |||
260 | ||||
261 | if ( bWasOpen ) | |||
262 | { | |||
263 | // close database beamer: just forward to SfxViewFrame | |||
264 | ||||
265 | pViewFrame->ExecuteSlot( rReq ); | |||
266 | } | |||
267 | else | |||
268 | { | |||
269 | // show database beamer: SfxViewFrame call must be synchronous | |||
270 | ||||
271 | pViewFrame->ExecuteSlot( rReq, false ); // false = synchronous | |||
272 | ||||
273 | // select current database in database beamer | |||
274 | ||||
275 | ScImportParam aImportParam; | |||
276 | ScDBData* pDBData = pTabViewShell->GetDBData(true,SC_DB_OLD); // don't create if none found | |||
277 | if (pDBData) | |||
278 | pDBData->GetImportParam( aImportParam ); | |||
279 | ||||
280 | ScDBDocFunc::ShowInBeamer( aImportParam, pTabViewShell->GetViewFrame() ); | |||
281 | } | |||
282 | rReq.Done(); // needed because it's a toggle slot | |||
283 | } | |||
284 | break; | |||
285 | ||||
286 | case SID_REIMPORT_DATA((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 16): | |||
287 | { | |||
288 | bool bOk = false; | |||
289 | ScDBData* pDBData = pTabViewShell->GetDBData(true,SC_DB_OLD); | |||
290 | if (pDBData) | |||
291 | { | |||
292 | ScImportParam aImportParam; | |||
293 | pDBData->GetImportParam( aImportParam ); | |||
294 | if (aImportParam.bImport && !pDBData->HasImportSelection()) | |||
295 | { | |||
296 | pTabViewShell->ImportData( aImportParam ); | |||
297 | pDBData->SetImportParam( aImportParam ); //! Undo ?? | |||
298 | bOk = true; | |||
299 | } | |||
300 | } | |||
301 | ||||
302 | if (!bOk && ! rReq.IsAPI() ) | |||
303 | pTabViewShell->ErrorMessage(STR_REIMPORT_EMPTYreinterpret_cast<char const *>("STR_REIMPORT_EMPTY" "\004" u8"This range does not contain imported data.")); | |||
304 | ||||
305 | if( bOk ) | |||
306 | rReq.Done(); | |||
307 | } | |||
308 | break; | |||
309 | ||||
310 | case SID_REFRESH_DBAREA((((26000 + 521) + 50))+72): | |||
311 | { | |||
312 | ScDBData* pDBData = pTabViewShell->GetDBData(true,SC_DB_OLD); | |||
313 | if (pDBData) | |||
314 | { | |||
315 | // repeat import like SID_REIMPORT_DATA | |||
316 | ||||
317 | bool bContinue = true; | |||
318 | ScImportParam aImportParam; | |||
319 | pDBData->GetImportParam( aImportParam ); | |||
320 | if (aImportParam.bImport && !pDBData->HasImportSelection()) | |||
321 | { | |||
322 | bContinue = pTabViewShell->ImportData( aImportParam ); | |||
323 | pDBData->SetImportParam( aImportParam ); //! Undo ?? | |||
324 | ||||
325 | // mark (size may have been changed) | |||
326 | ScRange aNewRange; | |||
327 | pDBData->GetArea(aNewRange); | |||
328 | pTabViewShell->MarkRange(aNewRange); | |||
329 | } | |||
330 | ||||
331 | if ( bContinue ) // fail at import -> break | |||
332 | { | |||
333 | // internal operations, when any stored | |||
334 | ||||
335 | if ( pDBData->HasQueryParam() || pDBData->HasSortParam() || | |||
336 | pDBData->HasSubTotalParam() ) | |||
337 | pTabViewShell->RepeatDB(); | |||
338 | ||||
339 | // pivot tables that have the range as data source | |||
340 | ||||
341 | ScRange aRange; | |||
342 | pDBData->GetArea(aRange); | |||
343 | GetViewData()->GetDocShell()->RefreshPivotTables(aRange); | |||
344 | } | |||
345 | } | |||
346 | rReq.Done(); | |||
347 | } | |||
348 | break; | |||
349 | ||||
350 | case SID_SBA_BRW_INSERT(((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1)+101): | |||
351 | { | |||
352 | OSL_FAIL( "Deprecated Slot" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh2.cxx" ":" "352" ": "), "%s", "Deprecated Slot"); } } while (false); | |||
353 | } | |||
354 | break; | |||
355 | ||||
356 | case SID_DATA_FORM((20000 +5000)+15): | |||
357 | { | |||
358 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); | |||
359 | ||||
360 | ScopedVclPtr<AbstractScDataFormDlg> pDlg(pFact->CreateScDataFormDlg( | |||
361 | pTabViewShell->GetFrameWeld(), pTabViewShell)); | |||
362 | ||||
363 | pDlg->Execute(); | |||
364 | ||||
365 | rReq.Done(); | |||
366 | } | |||
367 | break; | |||
368 | ||||
369 | case SID_SUBTOTALS((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 13): | |||
370 | ExecuteSubtotals(rReq); | |||
371 | break; | |||
372 | ||||
373 | case SID_SORT_DESCENDING((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 23): | |||
374 | case SID_SORT_ASCENDING((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 24): | |||
375 | { | |||
376 | //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data | |||
377 | //the patch comes from maoyg | |||
378 | ScSortParam aSortParam; | |||
379 | ScDBData* pDBData = pTabViewShell->GetDBData(); | |||
380 | ScViewData* pData = GetViewData(); | |||
381 | ||||
382 | pDBData->GetSortParam( aSortParam ); | |||
383 | ||||
384 | if( lcl_GetSortParam( pData, aSortParam ) ) | |||
385 | { | |||
386 | SCCOL nCol = GetViewData()->GetCurX(); | |||
387 | SCCOL nTab = GetViewData()->GetTabNo(); | |||
388 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
389 | ||||
390 | pDBData->GetSortParam( aSortParam ); | |||
391 | bool bHasHeader = rDoc.HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, nTab ); | |||
392 | ||||
393 | if( nCol < aSortParam.nCol1 ) | |||
394 | nCol = aSortParam.nCol1; | |||
395 | else if( nCol > aSortParam.nCol2 ) | |||
396 | nCol = aSortParam.nCol2; | |||
397 | ||||
398 | aSortParam.bHasHeader = bHasHeader; | |||
399 | aSortParam.bByRow = true; | |||
400 | aSortParam.bCaseSens = false; | |||
401 | aSortParam.bNaturalSort = false; | |||
402 | aSortParam.bIncludeComments = false; | |||
403 | aSortParam.bIncludeGraphicObjects = true; | |||
404 | aSortParam.bIncludePattern = true; | |||
405 | aSortParam.bInplace = true; | |||
406 | aSortParam.maKeyState[0].bDoSort = true; | |||
407 | aSortParam.maKeyState[0].nField = nCol; | |||
408 | aSortParam.maKeyState[0].bAscending = ( nSlotId == SID_SORT_ASCENDING((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 24) ); | |||
409 | ||||
410 | for ( sal_uInt16 i=1; i<aSortParam.GetSortKeyCount(); i++ ) | |||
411 | aSortParam.maKeyState[i].bDoSort = false; | |||
412 | ||||
413 | pTabViewShell->UISort( aSortParam ); // subtotal when needed new | |||
414 | ||||
415 | rReq.Done(); | |||
416 | } | |||
417 | } | |||
418 | break; | |||
419 | ||||
420 | case SID_SORT((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 2): | |||
421 | { | |||
422 | const SfxItemSet* pArgs = rReq.GetArgs(); | |||
423 | ||||
424 | //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data | |||
425 | //the patch comes from maoyg | |||
426 | ||||
427 | if ( pArgs ) // Basic | |||
428 | { | |||
429 | ScSortParam aSortParam; | |||
430 | ScDBData* pDBData = pTabViewShell->GetDBData(); | |||
431 | ScViewData* pData = GetViewData(); | |||
432 | ||||
433 | pDBData->GetSortParam( aSortParam ); | |||
434 | ||||
435 | if( lcl_GetSortParam( pData, aSortParam ) ) | |||
436 | { | |||
437 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
438 | ||||
439 | pDBData->GetSortParam( aSortParam ); | |||
440 | bool bHasHeader = rDoc.HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() ); | |||
441 | if( bHasHeader ) | |||
442 | aSortParam.bHasHeader = bHasHeader; | |||
443 | ||||
444 | aSortParam.bInplace = true; // from Basic always | |||
445 | ||||
446 | const SfxPoolItem* pItem; | |||
447 | if ( pArgs->GetItemState( SID_SORT_BYROW((26000 + 300)), true, &pItem ) == SfxItemState::SET ) | |||
448 | aSortParam.bByRow = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
449 | if ( pArgs->GetItemState( SID_SORT_HASHEADER((26000 + 300)+1), true, &pItem ) == SfxItemState::SET ) | |||
450 | aSortParam.bHasHeader = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
451 | if ( pArgs->GetItemState( SID_SORT_CASESENS((26000 + 300)+2), true, &pItem ) == SfxItemState::SET ) | |||
452 | aSortParam.bCaseSens = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
453 | if ( pArgs->GetItemState( SID_SORT_NATURALSORT((26000 + 300)+5), true, &pItem ) == SfxItemState::SET ) | |||
454 | aSortParam.bNaturalSort = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
455 | if ( pArgs->GetItemState( SID_SORT_INCCOMMENTS((26000 + 300)+6), true, &pItem ) == SfxItemState::SET ) | |||
456 | aSortParam.bIncludeComments = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
457 | if ( pArgs->GetItemState( SID_SORT_INCIMAGES((26000 + 300)+7), true, &pItem ) == SfxItemState::SET ) | |||
458 | aSortParam.bIncludeGraphicObjects = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
459 | if ( pArgs->GetItemState( SID_SORT_ATTRIBS((26000 + 300)+3), true, &pItem ) == SfxItemState::SET ) | |||
460 | aSortParam.bIncludePattern = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
461 | if ( pArgs->GetItemState( SID_SORT_USERDEF((26000 + 300)+4), true, &pItem ) == SfxItemState::SET ) | |||
462 | { | |||
463 | sal_uInt16 nUserIndex = static_cast<const SfxUInt16Item*>(pItem)->GetValue(); | |||
464 | aSortParam.bUserDef = ( nUserIndex != 0 ); | |||
465 | if ( nUserIndex ) | |||
466 | aSortParam.nUserIndex = nUserIndex - 1; // Basic: 1-based | |||
467 | } | |||
468 | ||||
469 | SCCOLROW nField0 = 0; | |||
470 | if ( pArgs->GetItemState( FN_PARAM_1((20000 + 1100)+60), true, &pItem ) == SfxItemState::SET ) | |||
471 | nField0 = static_cast<const SfxInt32Item*>(pItem)->GetValue(); | |||
472 | aSortParam.maKeyState[0].bDoSort = ( nField0 != 0 ); | |||
473 | aSortParam.maKeyState[0].nField = nField0 > 0 ? (nField0-1) : 0; | |||
474 | if ( pArgs->GetItemState( FN_PARAM_2((20000 + 1100)+61), true, &pItem ) == SfxItemState::SET ) | |||
475 | aSortParam.maKeyState[0].bAscending = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
476 | SCCOLROW nField1 = 0; | |||
477 | if ( pArgs->GetItemState( FN_PARAM_3((20000 + 1100)+62), true, &pItem ) == SfxItemState::SET ) | |||
478 | nField1 = static_cast<const SfxInt32Item*>(pItem)->GetValue(); | |||
479 | aSortParam.maKeyState[1].bDoSort = ( nField1 != 0 ); | |||
480 | aSortParam.maKeyState[1].nField = nField1 > 0 ? (nField1-1) : 0; | |||
481 | if ( pArgs->GetItemState( FN_PARAM_4((20000 + 1100)+63), true, &pItem ) == SfxItemState::SET ) | |||
482 | aSortParam.maKeyState[1].bAscending = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
483 | SCCOLROW nField2 = 0; | |||
484 | if ( pArgs->GetItemState( FN_PARAM_5((20000 + 1100)+64), true, &pItem ) == SfxItemState::SET ) | |||
485 | nField2 = static_cast<const SfxInt32Item*>(pItem)->GetValue(); | |||
486 | aSortParam.maKeyState[2].bDoSort = ( nField2 != 0 ); | |||
487 | aSortParam.maKeyState[2].nField = nField2 > 0 ? (nField2-1) : 0; | |||
488 | if ( pArgs->GetItemState( FN_PARAM_6((20000 + 1100)+65), true, &pItem ) == SfxItemState::SET ) | |||
489 | aSortParam.maKeyState[2].bAscending = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
490 | ||||
491 | // subtotal when needed new | |||
492 | pTabViewShell->UISort( aSortParam ); | |||
493 | rReq.Done(); | |||
494 | } | |||
495 | } | |||
496 | else | |||
497 | { | |||
498 | ScSortParam aSortParam; | |||
499 | ScDBData* pDBData = pTabViewShell->GetDBData(); | |||
500 | ScViewData* pData = GetViewData(); | |||
501 | ||||
502 | pDBData->GetSortParam( aSortParam ); | |||
503 | ||||
504 | if( lcl_GetSortParam( pData, aSortParam ) ) | |||
505 | { | |||
506 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
507 | SfxItemSet aArgSet( GetPool(), svl::Items<SCITEM_SORTDATA1102, SCITEM_SORTDATA1102>{} ); | |||
508 | ||||
509 | pDBData->GetSortParam( aSortParam ); | |||
510 | bool bHasHeader = rDoc.HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() ); | |||
511 | if( bHasHeader ) | |||
512 | aSortParam.bHasHeader = bHasHeader; | |||
513 | ||||
514 | aArgSet.Put( ScSortItem( SCITEM_SORTDATA1102, GetViewData(), &aSortParam ) ); | |||
515 | ||||
516 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); | |||
517 | std::shared_ptr<ScAsyncTabController> pDlg(pFact->CreateScSortDlg(pTabViewShell->GetFrameWeld(), &aArgSet)); | |||
518 | pDlg->SetCurPageId("criteria"); // 1=sort field tab 2=sort options tab | |||
519 | ||||
520 | VclAbstractDialog::AsyncContext aContext; | |||
521 | aContext.maEndDialogFn = [pDlg, pData, pTabViewShell](sal_Int32 nResult) | |||
522 | { | |||
523 | if ( nResult == RET_OK ) | |||
524 | { | |||
525 | const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); | |||
526 | const ScSortParam& rOutParam = static_cast<const ScSortItem&>( | |||
527 | pOutSet->Get( SCITEM_SORTDATA1102 )).GetSortData(); | |||
528 | ||||
529 | // subtotal when needed new | |||
530 | ||||
531 | pTabViewShell->UISort( rOutParam ); | |||
532 | } | |||
533 | else | |||
534 | { | |||
535 | pData->GetDocShell()->CancelAutoDBRange(); | |||
536 | } | |||
537 | }; | |||
538 | ||||
539 | pDlg->StartExecuteAsync(aContext); | |||
540 | } | |||
541 | } | |||
542 | } | |||
543 | break; | |||
544 | ||||
545 | case SID_FILTER((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 3): | |||
546 | { | |||
547 | const SfxItemSet* pArgs = rReq.GetArgs(); | |||
548 | if ( pArgs ) | |||
549 | { | |||
550 | OSL_FAIL("SID_FILTER with arguments?")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh2.cxx" ":" "550" ": "), "%s", "SID_FILTER with arguments?"); } } while (false); | |||
551 | pTabViewShell->Query( static_cast<const ScQueryItem&>( | |||
552 | pArgs->Get( SCITEM_QUERYDATA1103 )).GetQueryData(), nullptr, true ); | |||
553 | rReq.Done(); | |||
554 | } | |||
555 | else | |||
556 | { | |||
557 | sal_uInt16 nId = ScFilterDlgWrapper::GetChildWindowId(); | |||
558 | SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame(); | |||
559 | SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId ); | |||
560 | ||||
561 | pScMod->SetRefDialog( nId, pWnd == nullptr ); | |||
562 | } | |||
563 | } | |||
564 | break; | |||
565 | ||||
566 | case SID_SPECIAL_FILTER((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 4): | |||
567 | { | |||
568 | const SfxItemSet* pArgs = rReq.GetArgs(); | |||
569 | if ( pArgs ) | |||
570 | { | |||
571 | OSL_FAIL("SID_SPECIAL_FILTER with arguments?")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh2.cxx" ":" "571" ": "), "%s", "SID_SPECIAL_FILTER with arguments?") ; } } while (false); | |||
572 | pTabViewShell->Query( static_cast<const ScQueryItem&>( | |||
573 | pArgs->Get( SCITEM_QUERYDATA1103 )).GetQueryData(), nullptr, true ); | |||
574 | rReq.Done(); | |||
575 | } | |||
576 | else | |||
577 | { | |||
578 | sal_uInt16 nId = ScSpecialFilterDlgWrapper::GetChildWindowId(); | |||
579 | SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame(); | |||
580 | SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId ); | |||
581 | ||||
582 | pScMod->SetRefDialog( nId, pWnd == nullptr ); | |||
583 | } | |||
584 | } | |||
585 | break; | |||
586 | ||||
587 | case FID_FILTER_OK((26000 + 100) + 8): | |||
588 | { | |||
589 | const SfxPoolItem* pItem; | |||
590 | if ( pReqArgs && SfxItemState::SET == | |||
591 | pReqArgs->GetItemState( SCITEM_QUERYDATA1103, true, &pItem ) ) | |||
592 | { | |||
593 | const ScQueryItem& rQueryItem = static_cast<const ScQueryItem&>(*pItem); | |||
594 | ||||
595 | SCTAB nCurTab = GetViewData()->GetTabNo(); | |||
596 | SCTAB nRefTab = GetViewData()->GetRefTabNo(); | |||
597 | ||||
598 | // If RefInput switched to a different sheet from the data sheet, | |||
599 | // switch back: | |||
600 | ||||
601 | if ( nCurTab != nRefTab ) | |||
602 | { | |||
603 | pTabViewShell->SetTabNo( nRefTab ); | |||
604 | pTabViewShell->PaintExtras(); | |||
605 | } | |||
606 | ||||
607 | ScRange aAdvSource; | |||
608 | if (rQueryItem.GetAdvancedQuerySource(aAdvSource)) | |||
609 | pTabViewShell->Query( rQueryItem.GetQueryData(), &aAdvSource, true ); | |||
610 | else | |||
611 | pTabViewShell->Query( rQueryItem.GetQueryData(), nullptr, true ); | |||
612 | rReq.Done( *pReqArgs ); | |||
613 | } | |||
614 | } | |||
615 | break; | |||
616 | ||||
617 | case SID_UNFILTER((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 6): | |||
618 | { | |||
619 | ScQueryParam aParam; | |||
620 | ScDBData* pDBData = pTabViewShell->GetDBData(); | |||
621 | ||||
622 | pDBData->GetQueryParam( aParam ); | |||
623 | SCSIZE nEC = aParam.GetEntryCount(); | |||
624 | for (SCSIZE i=0; i<nEC; i++) | |||
625 | aParam.GetEntry(i).bDoQuery = false; | |||
626 | aParam.bDuplicate = true; | |||
627 | pTabViewShell->Query( aParam, nullptr, true ); | |||
628 | rReq.Done(); | |||
629 | } | |||
630 | break; | |||
631 | ||||
632 | case SID_AUTO_FILTER((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 5): | |||
633 | pTabViewShell->ToggleAutoFilter(); | |||
634 | rReq.Done(); | |||
635 | break; | |||
636 | ||||
637 | case SID_AUTOFILTER_HIDE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 21): | |||
638 | pTabViewShell->HideAutoFilter(); | |||
639 | rReq.Done(); | |||
640 | break; | |||
641 | ||||
642 | case SID_PIVOT_TABLE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 17): | |||
643 | { | |||
644 | const SfxPoolItem* pItem; | |||
645 | if ( pReqArgs && SfxItemState::SET == | |||
646 | pReqArgs->GetItemState( SCITEM_PIVOTDATA1106, true, &pItem ) ) | |||
647 | { | |||
648 | SCTAB nCurTab = GetViewData()->GetTabNo(); | |||
649 | SCTAB nRefTab = GetViewData()->GetRefTabNo(); | |||
650 | ||||
651 | // If RefInput switched to a different sheet from the data sheet, | |||
652 | // switch back: | |||
653 | ||||
654 | if ( nCurTab != nRefTab ) | |||
655 | { | |||
656 | pTabViewShell->SetTabNo( nRefTab ); | |||
657 | pTabViewShell->PaintExtras(); | |||
658 | } | |||
659 | ||||
660 | const ScDPObject* pDPObject = pTabViewShell->GetDialogDPObject(); | |||
661 | if ( pDPObject ) | |||
662 | { | |||
663 | const ScPivotItem* pPItem = static_cast<const ScPivotItem*>(pItem); | |||
664 | bool bSuccess = pTabViewShell->MakePivotTable( | |||
665 | pPItem->GetData(), pPItem->GetDestRange(), pPItem->IsNewSheet(), *pDPObject ); | |||
666 | SfxBoolItem aRet(0, bSuccess); | |||
667 | rReq.SetReturnValue(aRet); | |||
668 | } | |||
669 | rReq.Done(); | |||
670 | } | |||
671 | #if HAVE_FEATURE_SCRIPTING1 | |||
672 | else if (rReq.IsAPI()) | |||
673 | SbxBase::SetError(ERRCODE_BASIC_BAD_PARAMETERErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 7)); | |||
674 | #endif | |||
675 | } | |||
676 | break; | |||
677 | ||||
678 | case SID_OPENDLG_PIVOTTABLE((26000 + 100) + 51): | |||
679 | ExecuteDataPilotDialog(); | |||
680 | break; | |||
681 | case SID_DEFINE_DBNAME((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20))): | |||
682 | { | |||
683 | ||||
684 | sal_uInt16 nId = ScDbNameDlgWrapper::GetChildWindowId(); | |||
685 | SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame(); | |||
686 | SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId ); | |||
687 | ||||
688 | pScMod->SetRefDialog( nId, pWnd == nullptr ); | |||
689 | ||||
690 | } | |||
691 | break; | |||
692 | ||||
693 | case SID_SELECT_DB((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 1): | |||
694 | { | |||
695 | if ( pReqArgs ) | |||
696 | { | |||
697 | const SfxStringItem& rItem | |||
698 | = static_cast<const SfxStringItem&>(pReqArgs->Get(SID_SELECT_DB((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 1))); | |||
699 | pTabViewShell->GotoDBArea(rItem.GetValue()); | |||
700 | rReq.Done(); | |||
701 | } | |||
702 | else | |||
703 | { | |||
704 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
705 | ScDBCollection* pDBCol = rDoc.GetDBCollection(); | |||
706 | ||||
707 | if ( pDBCol ) | |||
708 | { | |||
709 | std::vector<OUString> aList; | |||
710 | const ScDBCollection::NamedDBs& rDBs = pDBCol->getNamedDBs(); | |||
711 | for (const auto& rxDB : rDBs) | |||
712 | aList.push_back(rxDB->GetName()); | |||
713 | ||||
714 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); | |||
715 | ||||
716 | ScopedVclPtr<AbstractScSelEntryDlg> pDlg(pFact->CreateScSelEntryDlg(pTabViewShell->GetFrameWeld(), aList)); | |||
717 | if ( pDlg->Execute() == RET_OK ) | |||
718 | { | |||
719 | OUString aName = pDlg->GetSelectedEntry(); | |||
720 | pTabViewShell->GotoDBArea( aName ); | |||
721 | rReq.AppendItem( SfxStringItem( SID_SELECT_DB((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 1), aName ) ); | |||
722 | rReq.Done(); | |||
723 | } | |||
724 | } | |||
725 | } | |||
726 | } | |||
727 | break; | |||
728 | case SID_DATA_STREAMS((26000) + 35): | |||
729 | { | |||
730 | sc::DataStreamDlg aDialog(GetViewData()->GetDocShell(), pTabViewShell->GetFrameWeld()); | |||
731 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
732 | sc::DocumentLinkManager& rMgr = rDoc.GetDocLinkManager(); | |||
733 | sc::DataStream* pStrm = rMgr.getDataStream(); | |||
734 | if (pStrm) | |||
735 | aDialog.Init(*pStrm); | |||
736 | ||||
737 | if (aDialog.run() == RET_OK) | |||
738 | aDialog.StartStream(); | |||
739 | } | |||
740 | break; | |||
741 | case SID_DATA_STREAMS_PLAY((26000) + 33): | |||
742 | { | |||
743 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
744 | sc::DocumentLinkManager& rMgr = rDoc.GetDocLinkManager(); | |||
745 | sc::DataStream* pStrm = rMgr.getDataStream(); | |||
746 | if (pStrm) | |||
747 | pStrm->StartImport(); | |||
748 | } | |||
749 | break; | |||
750 | case SID_DATA_STREAMS_STOP((26000) + 34): | |||
751 | { | |||
752 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
753 | sc::DocumentLinkManager& rMgr = rDoc.GetDocLinkManager(); | |||
754 | sc::DataStream* pStrm = rMgr.getDataStream(); | |||
755 | if (pStrm) | |||
756 | pStrm->StopImport(); | |||
757 | } | |||
758 | break; | |||
759 | case SID_DATA_PROVIDER((26000) + 31): | |||
760 | { | |||
761 | auto xDoc = o3tl::make_shared<ScDocument>(); | |||
762 | xDoc->InsertTab(0, "test"); | |||
763 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
764 | ScDataProviderDlg aDialog(pTabViewShell->GetDialogParent(), xDoc, &rDoc); | |||
765 | if (aDialog.run() == RET_OK) | |||
766 | { | |||
767 | aDialog.import(rDoc); | |||
768 | } | |||
769 | } | |||
770 | break; | |||
771 | case SID_DATA_PROVIDER_REFRESH((26000) + 32): | |||
772 | { | |||
773 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
774 | auto& rDataMapper = rDoc.GetExternalDataMapper(); | |||
775 | for (auto& rDataSource : rDataMapper.getDataSources()) | |||
776 | { | |||
777 | rDataSource.refresh(&rDoc, false); | |||
778 | } | |||
779 | } | |||
780 | break; | |||
781 | case SID_MANAGE_XML_SOURCE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 8): | |||
782 | ExecuteXMLSourceDialog(); | |||
783 | break; | |||
784 | case FID_VALIDATION((((26000 + 521) + 50))+54): | |||
785 | case FID_CURRENTVALIDATION((((26000 + 521) + 50))+51): | |||
786 | { | |||
787 | const SfxPoolItem* pItem; | |||
788 | const SfxItemSet* pArgs = rReq.GetArgs(); | |||
789 | if ( pArgs ) | |||
790 | { | |||
791 | OSL_FAIL("later...")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh2.cxx" ":" "791" ": "), "%s", "later..."); } } while (false); | |||
792 | } | |||
793 | else | |||
794 | { | |||
795 | SfxItemSet aArgSet( GetPool(), ScTPValidationValue::GetRanges() ); | |||
796 | ScValidationMode eMode = SC_VALID_ANY; | |||
797 | ScConditionMode eOper = ScConditionMode::Equal; | |||
798 | OUString aExpr1, aExpr2; | |||
799 | bool bBlank = true; | |||
800 | sal_Int16 nListType = css::sheet::TableValidationVisibility::UNSORTED; | |||
801 | bool bShowHelp = false; | |||
802 | OUString aHelpTitle, aHelpText; | |||
803 | bool bShowError = false; | |||
804 | ScValidErrorStyle eErrStyle = SC_VALERR_STOP; | |||
805 | OUString aErrTitle, aErrText; | |||
806 | ||||
807 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
808 | SCCOL nCurX = GetViewData()->GetCurX(); | |||
809 | SCROW nCurY = GetViewData()->GetCurY(); | |||
810 | SCTAB nTab = GetViewData()->GetTabNo(); | |||
811 | ScAddress aCursorPos( nCurX, nCurY, nTab ); | |||
812 | sal_uLong nIndex = rDoc.GetAttr( | |||
813 | nCurX, nCurY, nTab, ATTR_VALIDDATA )->GetValue(); | |||
814 | if ( nIndex ) | |||
815 | { | |||
816 | const ScValidationData* pOldData = rDoc.GetValidationEntry( nIndex ); | |||
817 | if ( pOldData ) | |||
818 | { | |||
819 | eMode = pOldData->GetDataMode(); | |||
820 | eOper = pOldData->GetOperation(); | |||
821 | sal_uInt32 nNumFmt = 0; | |||
822 | if ( eMode == SC_VALID_DATE || eMode == SC_VALID_TIME ) | |||
823 | { | |||
824 | SvNumFormatType nType = ( eMode == SC_VALID_DATE ) ? SvNumFormatType::DATE | |||
825 | : SvNumFormatType::TIME; | |||
826 | nNumFmt = rDoc.GetFormatTable()->GetStandardFormat( | |||
827 | nType, ScGlobal::eLnge ); | |||
828 | } | |||
829 | aExpr1 = pOldData->GetExpression( aCursorPos, 0, nNumFmt ); | |||
830 | aExpr2 = pOldData->GetExpression( aCursorPos, 1, nNumFmt ); | |||
831 | bBlank = pOldData->IsIgnoreBlank(); | |||
832 | nListType = pOldData->GetListType(); | |||
833 | ||||
834 | bShowHelp = pOldData->GetInput( aHelpTitle, aHelpText ); | |||
835 | bShowError = pOldData->GetErrMsg( aErrTitle, aErrText, eErrStyle ); | |||
836 | ||||
837 | aArgSet.Put( SfxUInt16Item( FID_VALID_MODE((((26000 + 521) + 50))+60), sal::static_int_cast<sal_uInt16>(eMode) ) ); | |||
838 | aArgSet.Put( SfxUInt16Item( FID_VALID_CONDMODE((((26000 + 521) + 50))+61), sal::static_int_cast<sal_uInt16>(eOper) ) ); | |||
839 | aArgSet.Put( SfxStringItem( FID_VALID_VALUE1((((26000 + 521) + 50))+62), aExpr1 ) ); | |||
840 | aArgSet.Put( SfxStringItem( FID_VALID_VALUE2((((26000 + 521) + 50))+63), aExpr2 ) ); | |||
841 | aArgSet.Put( SfxBoolItem( FID_VALID_BLANK((((26000 + 521) + 50))+64), bBlank ) ); | |||
842 | aArgSet.Put( SfxInt16Item( FID_VALID_LISTTYPE((26000) + 93), nListType ) ); | |||
843 | aArgSet.Put( SfxBoolItem( FID_VALID_SHOWHELP((((26000 + 521) + 50))+65), bShowHelp ) ); | |||
844 | aArgSet.Put( SfxStringItem( FID_VALID_HELPTITLE((((26000 + 521) + 50))+66), aHelpTitle ) ); | |||
845 | aArgSet.Put( SfxStringItem( FID_VALID_HELPTEXT((((26000 + 521) + 50))+67), aHelpText ) ); | |||
846 | aArgSet.Put( SfxBoolItem( FID_VALID_SHOWERR((((26000 + 521) + 50))+68), bShowError ) ); | |||
847 | aArgSet.Put( SfxUInt16Item( FID_VALID_ERRSTYLE((((26000 + 521) + 50))+69), sal::static_int_cast<sal_uInt16>(eErrStyle) ) ); | |||
848 | aArgSet.Put( SfxStringItem( FID_VALID_ERRTITLE((((26000 + 521) + 50))+70), aErrTitle ) ); | |||
849 | aArgSet.Put( SfxStringItem( FID_VALID_ERRTEXT((((26000 + 521) + 50))+71), aErrText ) ); | |||
850 | } | |||
851 | } | |||
852 | ||||
853 | // cell range picker | |||
854 | vcl::Window* pWin = GetViewData()->GetActiveWin(); | |||
855 | weld::Window* pParentWin = pWin ? pWin->GetFrameWeld() : nullptr; | |||
856 | auto xDlg = std::make_shared<ScValidationDlg>(pParentWin, &aArgSet, pTabViewShell); | |||
857 | ScValidationRegisteredDlg aRegisterThatDlgExists(pParentWin, xDlg); | |||
858 | ||||
859 | short nResult = xDlg->run(); | |||
860 | if ( nResult == RET_OK ) | |||
861 | { | |||
862 | const SfxItemSet* pOutSet = xDlg->GetOutputItemSet(); | |||
863 | ||||
864 | if ( pOutSet->GetItemState( FID_VALID_MODE((((26000 + 521) + 50))+60), true, &pItem ) == SfxItemState::SET ) | |||
865 | eMode = static_cast<ScValidationMode>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); | |||
866 | if ( pOutSet->GetItemState( FID_VALID_CONDMODE((((26000 + 521) + 50))+61), true, &pItem ) == SfxItemState::SET ) | |||
867 | eOper = static_cast<ScConditionMode>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); | |||
868 | if ( pOutSet->GetItemState( FID_VALID_VALUE1((((26000 + 521) + 50))+62), true, &pItem ) == SfxItemState::SET ) | |||
869 | { | |||
870 | OUString aTemp1 = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
871 | if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME) | |||
872 | { | |||
873 | sal_uInt32 nNumIndex = 0; | |||
874 | double nVal; | |||
875 | if (rDoc.GetFormatTable()->IsNumberFormat(aTemp1, nNumIndex, nVal)) | |||
876 | aExpr1 = ::rtl::math::doubleToUString( nVal, | |||
877 | rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, | |||
878 | ScGlobal::getLocaleDataPtr()->getNumDecimalSep()[0], true); | |||
879 | else | |||
880 | aExpr1 = aTemp1; | |||
881 | } | |||
882 | else | |||
883 | aExpr1 = aTemp1; | |||
884 | } | |||
885 | if ( pOutSet->GetItemState( FID_VALID_VALUE2((((26000 + 521) + 50))+63), true, &pItem ) == SfxItemState::SET ) | |||
886 | { | |||
887 | OUString aTemp2 = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
888 | if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME) | |||
889 | { | |||
890 | sal_uInt32 nNumIndex = 0; | |||
891 | double nVal; | |||
892 | if (rDoc.GetFormatTable()->IsNumberFormat(aTemp2, nNumIndex, nVal)) | |||
893 | aExpr2 = ::rtl::math::doubleToUString( nVal, | |||
894 | rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, | |||
895 | ScGlobal::getLocaleDataPtr()->getNumDecimalSep()[0], true); | |||
896 | else | |||
897 | aExpr2 = aTemp2; | |||
898 | if ( eMode == SC_VALID_TIME ) { | |||
899 | sal_Int32 wraparound = aExpr1.compareTo(aExpr2); | |||
900 | if (wraparound > 0) { | |||
901 | if (eOper == ScConditionMode::Between) { | |||
902 | eOper = ScConditionMode::NotBetween; | |||
903 | OUString tmp = aExpr1; | |||
904 | aExpr1 = aExpr2; | |||
905 | aExpr2 = tmp; | |||
906 | } | |||
907 | else if (eOper == ScConditionMode::NotBetween) { | |||
908 | eOper = ScConditionMode::Between; | |||
909 | OUString tmp = aExpr1; | |||
910 | aExpr1 = aExpr2; | |||
911 | aExpr2 = tmp; | |||
912 | } | |||
913 | } | |||
914 | } | |||
915 | } | |||
916 | else | |||
917 | aExpr2 = aTemp2; | |||
918 | } | |||
919 | if ( pOutSet->GetItemState( FID_VALID_BLANK((((26000 + 521) + 50))+64), true, &pItem ) == SfxItemState::SET ) | |||
920 | bBlank = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
921 | if ( pOutSet->GetItemState( FID_VALID_LISTTYPE((26000) + 93), true, &pItem ) == SfxItemState::SET ) | |||
922 | nListType = static_cast<const SfxInt16Item*>(pItem)->GetValue(); | |||
923 | ||||
924 | if ( pOutSet->GetItemState( FID_VALID_SHOWHELP((((26000 + 521) + 50))+65), true, &pItem ) == SfxItemState::SET ) | |||
925 | bShowHelp = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
926 | if ( pOutSet->GetItemState( FID_VALID_HELPTITLE((((26000 + 521) + 50))+66), true, &pItem ) == SfxItemState::SET ) | |||
927 | aHelpTitle = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
928 | if ( pOutSet->GetItemState( FID_VALID_HELPTEXT((((26000 + 521) + 50))+67), true, &pItem ) == SfxItemState::SET ) | |||
929 | aHelpText = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
930 | ||||
931 | if ( pOutSet->GetItemState( FID_VALID_SHOWERR((((26000 + 521) + 50))+68), true, &pItem ) == SfxItemState::SET ) | |||
932 | bShowError = static_cast<const SfxBoolItem*>(pItem)->GetValue(); | |||
933 | if ( pOutSet->GetItemState( FID_VALID_ERRSTYLE((((26000 + 521) + 50))+69), true, &pItem ) == SfxItemState::SET ) | |||
934 | eErrStyle = static_cast<ScValidErrorStyle>(static_cast<const SfxUInt16Item*>(pItem)->GetValue()); | |||
935 | if ( pOutSet->GetItemState( FID_VALID_ERRTITLE((((26000 + 521) + 50))+70), true, &pItem ) == SfxItemState::SET ) | |||
936 | aErrTitle = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
937 | if ( pOutSet->GetItemState( FID_VALID_ERRTEXT((((26000 + 521) + 50))+71), true, &pItem ) == SfxItemState::SET ) | |||
938 | aErrText = static_cast<const SfxStringItem*>(pItem)->GetValue(); | |||
939 | ||||
940 | ScValidationData aData( eMode, eOper, aExpr1, aExpr2, rDoc, aCursorPos ); | |||
941 | aData.SetIgnoreBlank( bBlank ); | |||
942 | aData.SetListType( nListType ); | |||
943 | ||||
944 | aData.SetInput(aHelpTitle, aHelpText); // sets bShowInput to TRUE | |||
945 | if (!bShowHelp) | |||
946 | aData.ResetInput(); // reset only bShowInput | |||
947 | ||||
948 | aData.SetError(aErrTitle, aErrText, eErrStyle); // sets bShowError to TRUE | |||
949 | if (!bShowError) | |||
950 | aData.ResetError(); // reset only bShowError | |||
951 | ||||
952 | pTabViewShell->SetValidation( aData ); | |||
953 | pTabViewShell->TestHintWindow(); | |||
954 | rReq.Done( *pOutSet ); | |||
955 | } | |||
956 | } | |||
957 | } | |||
958 | break; | |||
959 | ||||
960 | case SID_TEXT_TO_COLUMNS((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 19): | |||
961 | { | |||
962 | ScViewData* pData = GetViewData(); | |||
963 | OSL_ENSURE( pData, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pData is null!" )do { if (true && (!(pData))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh2.cxx" ":" "963" ": "), "%s", "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pData is null!" ); } } while (false); | |||
964 | ScRange aRange; | |||
965 | ||||
966 | if ( lcl_GetTextToColumnsRange( pData, aRange, false ) ) | |||
967 | { | |||
968 | ScDocument& rDoc = pData->GetDocument(); | |||
969 | ||||
970 | ScImportExport aExport( rDoc, aRange ); | |||
971 | aExport.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::None, 0, false ) ); | |||
972 | ||||
973 | // #i87703# text to columns fails with tab separator | |||
974 | aExport.SetDelimiter( u'\0' ); | |||
975 | ||||
976 | SvMemoryStream aStream; | |||
977 | aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE(((rtl_TextEncoding) 0xFFFF)) ); | |||
978 | ScImportExport::SetNoEndianSwap( aStream ); | |||
979 | aExport.ExportStream( aStream, OUString(), SotClipboardFormatId::STRING ); | |||
980 | ||||
981 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); | |||
982 | ScopedVclPtr<AbstractScImportAsciiDlg> pDlg(pFact->CreateScImportAsciiDlg( | |||
983 | pTabViewShell->GetFrameWeld(), OUString(), &aStream, SC_TEXTTOCOLUMNS)); | |||
984 | ||||
985 | if ( pDlg->Execute() == RET_OK ) | |||
986 | { | |||
987 | ScDocShell* pDocSh = pData->GetDocShell(); | |||
988 | OSL_ENSURE( pDocSh, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" )do { if (true && (!(pDocSh))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh2.cxx" ":" "988" ": "), "%s", "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" ); } } while (false); | |||
989 | ||||
990 | OUString aUndo = ScResId( STR_UNDO_TEXTTOCOLUMNSreinterpret_cast<char const *>("STR_UNDO_TEXTTOCOLUMNS" "\004" u8"Text to Columns") ); | |||
991 | pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, pData->GetViewShell()->GetViewShellId() ); | |||
992 | ||||
993 | ScImportExport aImport( rDoc, aRange.aStart ); | |||
994 | ScAsciiOptions aOptions; | |||
995 | pDlg->GetOptions( aOptions ); | |||
996 | pDlg->SaveParameters(); | |||
997 | aImport.SetExtOptions( aOptions ); | |||
998 | aImport.SetApi( false ); | |||
999 | aImport.SetImportBroadcast( true ); | |||
1000 | aImport.SetOverwriting( true ); | |||
1001 | aStream.Seek( 0 ); | |||
1002 | aImport.ImportStream( aStream, OUString(), SotClipboardFormatId::STRING ); | |||
1003 | ||||
1004 | pDocSh->GetUndoManager()->LeaveListAction(); | |||
1005 | } | |||
1006 | } | |||
1007 | } | |||
1008 | break; | |||
1009 | } | |||
1010 | } | |||
1011 | ||||
1012 | void ScCellShell::GetDBState( SfxItemSet& rSet ) | |||
1013 | { | |||
1014 | ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); | |||
1015 | ScViewData* pData = GetViewData(); | |||
1016 | ScDocShell* pDocSh = pData->GetDocShell(); | |||
1017 | ScDocument& rDoc = pDocSh->GetDocument(); | |||
1018 | SCCOL nPosX = pData->GetCurX(); | |||
1019 | SCROW nPosY = pData->GetCurY(); | |||
1020 | SCTAB nTab = pData->GetTabNo(); | |||
1021 | ||||
1022 | bool bAutoFilter = false; | |||
1023 | bool bAutoFilterTested = false; | |||
1024 | ||||
1025 | SfxWhichIter aIter(rSet); | |||
1026 | sal_uInt16 nWhich = aIter.FirstWhich(); | |||
1027 | while (nWhich) | |||
1028 | { | |||
1029 | switch (nWhich) | |||
1030 | { | |||
1031 | case SID_REFRESH_DBAREA((((26000 + 521) + 50))+72): | |||
1032 | { | |||
1033 | // imported data without selection | |||
1034 | // or filter,sort,subtotal (also without import) | |||
1035 | bool bOk = false; | |||
1036 | ScDBData* pDBData = pTabViewShell->GetDBData(false,SC_DB_OLD); | |||
1037 | if (pDBData && rDoc.GetChangeTrack() == nullptr) | |||
1038 | { | |||
1039 | if ( pDBData->HasImportParam() ) | |||
1040 | bOk = !pDBData->HasImportSelection(); | |||
1041 | else | |||
1042 | { | |||
1043 | bOk = pDBData->HasQueryParam() || | |||
1044 | pDBData->HasSortParam() || | |||
1045 | pDBData->HasSubTotalParam(); | |||
1046 | } | |||
1047 | } | |||
1048 | if (!bOk) | |||
1049 | rSet.DisableItem( nWhich ); | |||
1050 | } | |||
1051 | break; | |||
1052 | ||||
1053 | case SID_FILTER((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 3): | |||
1054 | case SID_SPECIAL_FILTER((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 4): | |||
1055 | { | |||
1056 | ScRange aDummy; | |||
1057 | ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy); | |||
1058 | if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED) | |||
1059 | { | |||
1060 | rSet.DisableItem( nWhich ); | |||
1061 | } | |||
1062 | } | |||
1063 | break; | |||
1064 | ||||
1065 | //in case of Redlining and multiselection disable | |||
1066 | case SID_SORT_ASCENDING((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 24): | |||
1067 | case SID_SORT_DESCENDING((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 23): | |||
1068 | case SCITEM_SORTDATA1102: | |||
1069 | case SCITEM_SUBTDATA1104: | |||
1070 | case SID_OPENDLG_PIVOTTABLE((26000 + 100) + 51): | |||
1071 | { | |||
1072 | //! move ReadOnly check to idl flags | |||
1073 | ||||
1074 | if ( pDocSh->IsReadOnly() || rDoc.GetChangeTrack()!=nullptr || | |||
1075 | GetViewData()->IsMultiMarked() ) | |||
1076 | { | |||
1077 | rSet.DisableItem( nWhich ); | |||
1078 | } | |||
1079 | } | |||
1080 | break; | |||
1081 | ||||
1082 | case SID_REIMPORT_DATA((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 16): | |||
1083 | { | |||
1084 | // only imported data without selection | |||
1085 | ScDBData* pDBData = pTabViewShell->GetDBData(false,SC_DB_OLD); | |||
1086 | if (!pDBData || !pDBData->HasImportParam() || pDBData->HasImportSelection() || | |||
1087 | rDoc.GetChangeTrack()!=nullptr) | |||
1088 | { | |||
1089 | rSet.DisableItem( nWhich ); | |||
1090 | } | |||
1091 | } | |||
1092 | break; | |||
1093 | ||||
1094 | case SID_VIEW_DATA_SOURCE_BROWSER(5000 + 1660): | |||
1095 | { | |||
1096 | if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DATABASE)) | |||
1097 | rSet.Put(SfxVisibilityItem(nWhich, false)); | |||
1098 | else | |||
1099 | // get state (BoolItem) from SfxViewFrame | |||
1100 | pTabViewShell->GetViewFrame()->GetSlotState( nWhich, nullptr, &rSet ); | |||
1101 | } | |||
1102 | break; | |||
1103 | case SID_SBA_BRW_INSERT(((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1)+101): | |||
1104 | { | |||
1105 | // SBA wants a sal_Bool-item, enabled | |||
1106 | ||||
1107 | rSet.Put(SfxBoolItem(nWhich, true)); | |||
1108 | } | |||
1109 | break; | |||
1110 | ||||
1111 | case SID_AUTO_FILTER((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 5): | |||
1112 | case SID_AUTOFILTER_HIDE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 21): | |||
1113 | { | |||
1114 | if (!bAutoFilterTested) | |||
1115 | { | |||
1116 | bAutoFilter = rDoc.HasAutoFilter( nPosX, nPosY, nTab ); | |||
1117 | bAutoFilterTested = true; | |||
1118 | } | |||
1119 | if ( nWhich == SID_AUTO_FILTER((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 5) ) | |||
1120 | { | |||
1121 | ScRange aDummy; | |||
1122 | ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy); | |||
1123 | if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED) | |||
1124 | { | |||
1125 | rSet.DisableItem( nWhich ); | |||
1126 | } | |||
1127 | else if (rDoc.GetDPAtBlock(aDummy)) | |||
1128 | { | |||
1129 | rSet.DisableItem( nWhich ); | |||
1130 | } | |||
1131 | else | |||
1132 | rSet.Put( SfxBoolItem( nWhich, bAutoFilter ) ); | |||
1133 | } | |||
1134 | else | |||
1135 | if (!bAutoFilter) | |||
1136 | rSet.DisableItem( nWhich ); | |||
1137 | } | |||
1138 | break; | |||
1139 | ||||
1140 | case SID_UNFILTER((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 6): | |||
1141 | { | |||
1142 | SCCOL nStartCol, nEndCol; | |||
1143 | SCROW nStartRow, nEndRow; | |||
1144 | SCTAB nStartTab, nEndTab; | |||
1145 | bool bAnyQuery = false; | |||
1146 | ||||
1147 | bool bSelected = (GetViewData()->GetSimpleArea( | |||
1148 | nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab ) | |||
1149 | == SC_MARK_SIMPLE); | |||
1150 | ||||
1151 | if ( bSelected ) | |||
1152 | { | |||
1153 | if (nStartCol==nEndCol && nStartRow==nEndRow) | |||
1154 | bSelected = false; | |||
1155 | } | |||
1156 | else | |||
1157 | { | |||
1158 | nStartCol = GetViewData()->GetCurX(); | |||
1159 | nStartRow = GetViewData()->GetCurY(); | |||
1160 | nStartTab = GetViewData()->GetTabNo(); | |||
1161 | } | |||
1162 | ||||
1163 | ScDBData* pDBData = bSelected | |||
1164 | ? rDoc.GetDBAtArea( nStartTab, nStartCol, nStartRow, nEndCol, nEndRow ) | |||
1165 | : rDoc.GetDBAtCursor( nStartCol, nStartRow, nStartTab, ScDBDataPortion::AREA ); | |||
1166 | ||||
1167 | if ( pDBData ) | |||
1168 | { | |||
1169 | ScQueryParam aParam; | |||
1170 | pDBData->GetQueryParam( aParam ); | |||
1171 | if ( aParam.GetEntry(0).bDoQuery ) | |||
1172 | bAnyQuery = true; | |||
1173 | } | |||
1174 | ||||
1175 | if ( !bAnyQuery ) | |||
1176 | rSet.DisableItem( nWhich ); | |||
1177 | } | |||
1178 | break; | |||
1179 | ||||
1180 | case SID_DEFINE_DBNAME((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20))): | |||
1181 | { | |||
1182 | if ( pDocSh->IsDocShared() ) | |||
1183 | { | |||
1184 | rSet.DisableItem( nWhich ); | |||
1185 | } | |||
1186 | } | |||
1187 | break; | |||
1188 | case SID_DATA_PROVIDER((26000) + 31): | |||
1189 | break; | |||
1190 | case SID_DATA_PROVIDER_REFRESH((26000) + 32): | |||
1191 | { | |||
1192 | ScDocument& rViewDoc = GetViewData()->GetDocument(); | |||
1193 | auto& rDataMapper = rViewDoc.GetExternalDataMapper(); | |||
1194 | if (rDataMapper.getDataSources().empty()) | |||
1195 | rSet.DisableItem(nWhich); | |||
1196 | } | |||
1197 | break; | |||
1198 | case SID_DATA_STREAMS((26000) + 35): | |||
1199 | case SID_DATA_STREAMS_PLAY((26000) + 33): | |||
1200 | case SID_DATA_STREAMS_STOP((26000) + 34): | |||
1201 | { | |||
1202 | SvtMiscOptions aMiscOptions; | |||
1203 | if ( !aMiscOptions.IsExperimentalMode() ) | |||
1204 | rSet.DisableItem( nWhich ); | |||
1205 | } | |||
1206 | break; | |||
1207 | case SID_TEXT_TO_COLUMNS((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 19): | |||
1208 | { | |||
1209 | ScRange aRange; | |||
1210 | if ( !lcl_GetTextToColumnsRange( pData, aRange, true ) ) | |||
1211 | { | |||
1212 | rSet.DisableItem( nWhich ); | |||
1213 | } | |||
1214 | } | |||
1215 | break; | |||
1216 | case SID_MANAGE_XML_SOURCE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 8): | |||
1217 | break; | |||
1218 | } | |||
1219 | nWhich = aIter.NextWhich(); | |||
1220 | } | |||
1221 | } | |||
1222 | ||||
1223 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | |
20 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||||||||
2 | /* | ||||||||
3 | * This file is part of the LibreOffice project. | ||||||||
4 | * | ||||||||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | ||||||||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||||
8 | * | ||||||||
9 | * This file incorporates work covered by the following license notice: | ||||||||
10 | * | ||||||||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | ||||||||
12 | * contributor license agreements. See the NOTICE file distributed | ||||||||
13 | * with this work for additional information regarding copyright | ||||||||
14 | * ownership. The ASF licenses this file to you under the Apache | ||||||||
15 | * License, Version 2.0 (the "License"); you may not use this file | ||||||||
16 | * except in compliance with the License. You may obtain a copy of | ||||||||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | ||||||||
18 | */ | ||||||||
19 | |||||||||
20 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody
| ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody) | ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |