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 <scitems.hxx> | |||
21 | ||||
22 | #include <svl/slstitm.hxx> | |||
23 | #include <svl/stritem.hxx> | |||
24 | #include <svl/whiter.hxx> | |||
25 | #include <svtools/cliplistener.hxx> | |||
26 | #include <svtools/insdlg.hxx> | |||
27 | #include <sot/formats.hxx> | |||
28 | #include <svx/hlnkitem.hxx> | |||
29 | #include <sfx2/bindings.hxx> | |||
30 | #include <sfx2/childwin.hxx> | |||
31 | #include <sfx2/objface.hxx> | |||
32 | #include <sfx2/request.hxx> | |||
33 | #include <sfx2/viewfrm.hxx> | |||
34 | #include <vcl/EnumContext.hxx> | |||
35 | #include <vcl/svapp.hxx> | |||
36 | #include <svx/clipfmtitem.hxx> | |||
37 | ||||
38 | #include <cellsh.hxx> | |||
39 | #include <sc.hrc> | |||
40 | #include <docsh.hxx> | |||
41 | #include <attrib.hxx> | |||
42 | #include <tabvwsh.hxx> | |||
43 | #include <formulacell.hxx> | |||
44 | #include <scmod.hxx> | |||
45 | #include <globstr.hrc> | |||
46 | #include <scresid.hxx> | |||
47 | #include <transobj.hxx> | |||
48 | #include <drwtrans.hxx> | |||
49 | #include <scabstdlg.hxx> | |||
50 | #include <postit.hxx> | |||
51 | #include <cliputil.hxx> | |||
52 | #include <clipparam.hxx> | |||
53 | #include <markdata.hxx> | |||
54 | #include <gridwin.hxx> | |||
55 | ||||
56 | #define ShellClass_ScCellShell | |||
57 | #define ShellClass_CellMovement | |||
58 | #include <scslots.hxx> | |||
59 | ||||
60 | ||||
61 | SFX_IMPL_INTERFACE(ScCellShell, ScFormatShell)SfxInterface* ScCellShell::pInterface = nullptr; SfxInterface * ScCellShell::GetStaticInterface() { if ( !pInterface ) { pInterface = new SfxInterface( "ScCellShell", false, GetInterfaceId(), ScFormatShell ::GetStaticInterface(), aScCellShellSlots_Impl[0], sal_uInt16 (sizeof(aScCellShellSlots_Impl) / sizeof(SfxSlot) ) ); InitInterface_Impl (); } return pInterface; } SfxInterface* ScCellShell::GetInterface () const { return GetStaticInterface(); } void ScCellShell::RegisterInterface (const SfxModule* pMod) { GetStaticInterface()->Register(pMod ); } | |||
62 | ||||
63 | void ScCellShell::InitInterface_Impl() | |||
64 | { | |||
65 | GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT1, | |||
66 | SfxVisibilityFlags::Standard | SfxVisibilityFlags::Server, | |||
67 | ToolbarId::Objectbar_Format); | |||
68 | ||||
69 | GetStaticInterface()->RegisterPopupMenu("cell"); | |||
70 | } | |||
71 | ||||
72 | ScCellShell::ScCellShell(ScViewData& rData, const VclPtr<vcl::Window>& frameWin) : | |||
73 | ScFormatShell(&rData), | |||
74 | pImpl( new CellShell_Impl() ), | |||
75 | bPastePossible(false), | |||
76 | pFrameWin(frameWin) | |||
77 | { | |||
78 | SetName("Cell"); | |||
79 | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Cell)); | |||
80 | } | |||
81 | ||||
82 | ScCellShell::~ScCellShell() | |||
83 | { | |||
84 | if ( pImpl->m_xClipEvtLstnr.is() ) | |||
| ||||
85 | { | |||
86 | pImpl->m_xClipEvtLstnr->RemoveListener( GetViewData()->GetActiveWin() ); | |||
87 | ||||
88 | // The listener may just now be waiting for the SolarMutex and call the link | |||
89 | // afterwards, in spite of RemoveListener. So the link has to be reset, too. | |||
90 | pImpl->m_xClipEvtLstnr->ClearCallbackLink(); | |||
91 | ||||
92 | pImpl->m_xClipEvtLstnr.clear(); | |||
93 | } | |||
94 | ||||
95 | pImpl->m_pLinkedDlg.disposeAndClear(); | |||
96 | delete pImpl->m_pRequest; | |||
97 | } | |||
98 | ||||
99 | void ScCellShell::GetBlockState( SfxItemSet& rSet ) | |||
100 | { | |||
101 | ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); | |||
102 | ScRange aMarkRange; | |||
103 | ScMarkType eMarkType = GetViewData()->GetSimpleArea( aMarkRange ); | |||
104 | bool bSimpleArea = (eMarkType == SC_MARK_SIMPLE); | |||
105 | bool bOnlyNotBecauseOfMatrix; | |||
106 | bool bEditable = pTabViewShell->SelectionEditable( &bOnlyNotBecauseOfMatrix ); | |||
107 | ScDocument& rDoc = GetViewData()->GetDocument(); | |||
108 | ScDocShell* pDocShell = GetViewData()->GetDocShell(); | |||
109 | ScMarkData& rMark = GetViewData()->GetMarkData(); | |||
110 | SCCOL nCol1, nCol2; | |||
111 | SCROW nRow1, nRow2; | |||
112 | nCol1 = aMarkRange.aStart.Col(); | |||
113 | nRow1 = aMarkRange.aStart.Row(); | |||
114 | nCol2 = aMarkRange.aEnd.Col(); | |||
115 | nRow2 = aMarkRange.aEnd.Row(); | |||
116 | ||||
117 | SfxWhichIter aIter(rSet); | |||
118 | sal_uInt16 nWhich = aIter.FirstWhich(); | |||
119 | while ( nWhich ) | |||
120 | { | |||
121 | bool bDisable = false; | |||
122 | bool bNeedEdit = true; // need selection be editable? | |||
123 | switch ( nWhich ) | |||
124 | { | |||
125 | case FID_FILL_TO_BOTTOM((((26000 + 200) + 20)) + 4): // fill to top / bottom | |||
126 | { | |||
127 | bDisable = !bSimpleArea || (nRow1 == 0 && nRow2 == 0); | |||
128 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
129 | bDisable = true; | |||
130 | if ( !bDisable && bEditable ) | |||
131 | { // do not damage matrix | |||
132 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
133 | nCol1, nRow1, nCol2, nRow1, rMark ); // first row | |||
134 | } | |||
135 | } | |||
136 | break; | |||
137 | case FID_FILL_TO_TOP((((26000 + 200) + 20)) + 6): | |||
138 | { | |||
139 | bDisable = (!bSimpleArea) || (nRow1 == rDoc.MaxRow() && nRow2 == rDoc.MaxRow()); | |||
140 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
141 | bDisable = true; | |||
142 | if ( !bDisable && bEditable ) | |||
143 | { // do not damage matrix | |||
144 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
145 | nCol1, nRow2, nCol2, nRow2, rMark ); // last row | |||
146 | } | |||
147 | } | |||
148 | break; | |||
149 | case FID_FILL_TO_RIGHT((((26000 + 200) + 20)) + 5): // fill to left / right | |||
150 | { | |||
151 | bDisable = !bSimpleArea || (nCol1 == 0 && nCol2 == 0); | |||
152 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
153 | bDisable = true; | |||
154 | if ( !bDisable && bEditable ) | |||
155 | { // do not damage matrix | |||
156 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
157 | nCol1, nRow1, nCol1, nRow2, rMark ); // first column | |||
158 | } | |||
159 | } | |||
160 | break; | |||
161 | case FID_FILL_TO_LEFT((((26000 + 200) + 20)) + 7): | |||
162 | { | |||
163 | bDisable = (!bSimpleArea) || (nCol1 == rDoc.MaxCol() && nCol2 == rDoc.MaxCol()); | |||
164 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
165 | bDisable = true; | |||
166 | if ( !bDisable && bEditable ) | |||
167 | { // do not damage matrix | |||
168 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
169 | nCol2, nRow1, nCol2, nRow2, rMark ); // last column | |||
170 | } | |||
171 | } | |||
172 | break; | |||
173 | ||||
174 | case SID_RANDOM_NUMBER_GENERATOR_DIALOG((26000 + 100) + 70): | |||
175 | bDisable = !bSimpleArea || GetViewData()->SelectionForbidsCellFill(); | |||
176 | break; | |||
177 | case SID_SAMPLING_DIALOG((26000 + 100) + 71): | |||
178 | case SID_DESCRIPTIVE_STATISTICS_DIALOG((26000 + 100) + 72): | |||
179 | case SID_ANALYSIS_OF_VARIANCE_DIALOG((26000 + 100) + 73): | |||
180 | case SID_CORRELATION_DIALOG((26000 + 100) + 74): | |||
181 | case SID_COVARIANCE_DIALOG((26000 + 100) + 75): | |||
182 | { | |||
183 | bDisable = !bSimpleArea; | |||
184 | } | |||
185 | break; | |||
186 | ||||
187 | case FID_FILL_SERIES((((26000 + 200) + 20)) + 9): // fill block | |||
188 | case SID_OPENDLG_TABOP((26000 + 100) + 54): // multiple-cell operations, are at least 2 cells marked? | |||
189 | if (rDoc.GetChangeTrack()!=nullptr &&nWhich ==SID_OPENDLG_TABOP((26000 + 100) + 54)) | |||
190 | bDisable = true; | |||
191 | else | |||
192 | bDisable = (!bSimpleArea) || (nCol1 == nCol2 && nRow1 == nRow2); | |||
193 | ||||
194 | if (!bDisable && GetViewData()->SelectionForbidsCellFill()) | |||
195 | bDisable = true; | |||
196 | ||||
197 | if ( !bDisable && bEditable && nWhich == FID_FILL_SERIES((((26000 + 200) + 20)) + 9) ) | |||
198 | { // do not damage matrix | |||
199 | bDisable = rDoc.HasSelectedBlockMatrixFragment( | |||
200 | nCol1, nRow1, nCol2, nRow1, rMark ) // first row | |||
201 | || rDoc.HasSelectedBlockMatrixFragment( | |||
202 | nCol1, nRow2, nCol2, nRow2, rMark ) // last row | |||
203 | || rDoc.HasSelectedBlockMatrixFragment( | |||
204 | nCol1, nRow1, nCol1, nRow2, rMark ) // first column | |||
205 | || rDoc.HasSelectedBlockMatrixFragment( | |||
206 | nCol2, nRow1, nCol2, nRow2, rMark ); // last column | |||
207 | } | |||
208 | break; | |||
209 | case FID_FILL_SINGLE_EDIT((((26000 + 200) + 20)) + 10): | |||
210 | bDisable = false; | |||
211 | break; | |||
212 | case SID_CUT(5000 + 710): // cut | |||
213 | bDisable = !bSimpleArea || GetObjectShell()->isContentExtractionLocked(); | |||
214 | break; | |||
215 | case FID_INS_CELL((((((((26000 + 200) + 20)) + 20)) + 20)) + 6): // insert cells, just simple selection | |||
216 | bDisable = (!bSimpleArea); | |||
217 | break; | |||
218 | ||||
219 | case SID_PASTE(5000 + 712): | |||
220 | case SID_PASTE_SPECIAL(5000 + 311): | |||
221 | case SID_PASTE_UNFORMATTED(5000 + 314): | |||
222 | case SID_PASTE_ONLY_VALUE(5000 + 804): | |||
223 | case SID_PASTE_ONLY_TEXT(5000 + 802): | |||
224 | case SID_PASTE_ONLY_FORMULA(5000 + 803): | |||
225 | case SID_PASTE_TEXTIMPORT_DIALOG(5000 + 805): | |||
226 | bDisable = GetViewData()->SelectionForbidsCellFill(); | |||
227 | break; | |||
228 | ||||
229 | case FID_INS_ROW((((((((26000 + 200) + 20)) + 20)) + 20)) + 7): | |||
230 | case FID_INS_ROWS_BEFORE((((((((26000 + 200) + 20)) + 20)) + 20)) + 22): // insert rows | |||
231 | case FID_INS_ROWS_AFTER((((((((26000 + 200) + 20)) + 20)) + 20)) + 20): | |||
232 | { | |||
233 | sc::ColRowEditAction eAction = sc::ColRowEditAction::InsertRowsBefore; | |||
234 | if (nWhich == FID_INS_ROWS_AFTER((((((((26000 + 200) + 20)) + 20)) + 20)) + 20)) | |||
235 | eAction = sc::ColRowEditAction::InsertRowsAfter; | |||
236 | ||||
237 | bDisable = (!bSimpleArea) || GetViewData()->SimpleColMarked(); | |||
238 | if (!bEditable && nCol1 == 0 && nCol2 == rDoc.MaxCol()) | |||
239 | { | |||
240 | // See if row insertions are allowed. | |||
241 | bEditable = rDoc.IsEditActionAllowed(eAction, rMark, nRow1, nRow2); | |||
242 | } | |||
243 | break; | |||
244 | } | |||
245 | case FID_INS_CELLSDOWN((((((((26000 + 200) + 20)) + 20)) + 20)) + 18): | |||
246 | bDisable = (!bSimpleArea) || GetViewData()->SimpleColMarked(); | |||
247 | break; | |||
248 | ||||
249 | case FID_INS_COLUMN((((((((26000 + 200) + 20)) + 20)) + 20)) + 8): | |||
250 | case FID_INS_COLUMNS_BEFORE((((((((26000 + 200) + 20)) + 20)) + 20)) + 23): // insert columns | |||
251 | case FID_INS_COLUMNS_AFTER((((((((26000 + 200) + 20)) + 20)) + 20)) + 21): | |||
252 | { | |||
253 | sc::ColRowEditAction eAction = sc::ColRowEditAction::InsertColumnsBefore; | |||
254 | if (nWhich == FID_INS_COLUMNS_AFTER((((((((26000 + 200) + 20)) + 20)) + 20)) + 21)) | |||
255 | eAction = sc::ColRowEditAction::InsertColumnsAfter; | |||
256 | ||||
257 | bDisable = (!bSimpleArea) || GetViewData()->SimpleRowMarked(); | |||
258 | if (!bEditable && nRow1 == 0 && nRow2 == rDoc.MaxRow()) | |||
259 | { | |||
260 | // See if row insertions are allowed. | |||
261 | bEditable = rDoc.IsEditActionAllowed(eAction, rMark, nCol1, nCol2); | |||
262 | } | |||
263 | break; | |||
264 | } | |||
265 | case FID_INS_CELLSRIGHT((((((((26000 + 200) + 20)) + 20)) + 20)) + 19): | |||
266 | bDisable = (!bSimpleArea) || GetViewData()->SimpleRowMarked(); | |||
267 | break; | |||
268 | ||||
269 | case SID_COPY(5000 + 711): // copy | |||
270 | // not editable because of matrix only? Do not damage matrix | |||
271 | //! is not called, when protected AND matrix, we will have | |||
272 | //! to live with this... is caught in Copy-Routine, otherwise | |||
273 | //! work is to be done once more | |||
274 | if ( bEditable || !bOnlyNotBecauseOfMatrix ) | |||
275 | bNeedEdit = false; // allowed when protected/ReadOnly | |||
276 | bDisable = GetObjectShell()->isContentExtractionLocked(); | |||
277 | break; | |||
278 | ||||
279 | case SID_AUTOFORMATTypedWhichId<SfxStringItem>( 10000 + 242 ): // Autoformat, at least 3x3 selected | |||
280 | bDisable = (!bSimpleArea) | |||
281 | || ((nCol2 - nCol1) < 2) || ((nRow2 - nRow1) < 2); | |||
282 | break; | |||
283 | ||||
284 | case SID_CELL_FORMAT_RESET((26000) + 67) : | |||
285 | case FID_CELL_FORMAT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25))) : | |||
286 | case SID_ENABLE_HYPHENATION((26000) + 87) : | |||
287 | // not editable because of matrix only? Attribute ok nonetheless | |||
288 | if ( !bEditable && bOnlyNotBecauseOfMatrix ) | |||
289 | bNeedEdit = false; | |||
290 | break; | |||
291 | ||||
292 | case FID_VALIDATION((((26000 + 521) + 50))+54): | |||
293 | { | |||
294 | if ( pDocShell && pDocShell->IsDocShared() ) | |||
295 | { | |||
296 | bDisable = true; | |||
297 | } | |||
298 | } | |||
299 | break; | |||
300 | case SID_TRANSLITERATE_HALFWIDTH( 10000 + 914 ): | |||
301 | case SID_TRANSLITERATE_FULLWIDTH( 10000 + 915 ): | |||
302 | case SID_TRANSLITERATE_HIRAGANA( 10000 + 916 ): | |||
303 | case SID_TRANSLITERATE_KATAKANA( 10000 + 917 ): | |||
304 | ScViewUtil::HideDisabledSlot( rSet, GetViewData()->GetBindings(), nWhich ); | |||
305 | break; | |||
306 | case SID_CONVERT_FORMULA_TO_VALUE((26000 + 200) + 5): | |||
307 | { | |||
308 | // Check and see if the marked range has at least one formula cell. | |||
309 | bDisable = !rDoc.HasFormulaCell(aMarkRange); | |||
310 | } | |||
311 | break; | |||
312 | } | |||
313 | if (!bDisable && bNeedEdit && !bEditable) | |||
314 | bDisable = true; | |||
315 | ||||
316 | if (bDisable) | |||
317 | rSet.DisableItem(nWhich); | |||
318 | else if (nWhich == SID_ENABLE_HYPHENATION((26000) + 87)) | |||
319 | { | |||
320 | // toggle slots need a bool item | |||
321 | rSet.Put( SfxBoolItem( nWhich, false ) ); | |||
322 | } | |||
323 | nWhich = aIter.NextWhich(); | |||
324 | } | |||
325 | } | |||
326 | ||||
327 | // functions, disabled depending on cursor position | |||
328 | // Default: | |||
329 | // SID_INSERT_POSTIT, SID_CHARMAP, SID_OPENDLG_FUNCTION | |||
330 | ||||
331 | void ScCellShell::GetCellState( SfxItemSet& rSet ) | |||
332 | { | |||
333 | ScDocShell* pDocShell = GetViewData()->GetDocShell(); | |||
334 | ScDocument& rDoc = GetViewData()->GetDocShell()->GetDocument(); | |||
335 | ScAddress aCursor( GetViewData()->GetCurX(), GetViewData()->GetCurY(), | |||
336 | GetViewData()->GetTabNo() ); | |||
337 | SfxWhichIter aIter(rSet); | |||
338 | sal_uInt16 nWhich = aIter.FirstWhich(); | |||
339 | while ( nWhich ) | |||
340 | { | |||
341 | bool bDisable = false; | |||
342 | bool bNeedEdit = true; // need cursor position be editable? | |||
343 | switch ( nWhich ) | |||
344 | { | |||
345 | case SID_THESAURUS( 10000 + 245 ): | |||
346 | { | |||
347 | CellType eType = rDoc.GetCellType( aCursor ); | |||
348 | bDisable = ( eType != CELLTYPE_STRING && eType != CELLTYPE_EDIT); | |||
349 | if (!bDisable) | |||
350 | { | |||
351 | // test for available languages | |||
352 | LanguageType nLang = ScViewUtil::GetEffLanguage( rDoc, aCursor ); | |||
353 | bDisable = !ScModule::HasThesaurusLanguage( nLang ); | |||
354 | } | |||
355 | } | |||
356 | break; | |||
357 | case SID_OPENDLG_FUNCTION((26000 + 100) + 52): | |||
358 | { | |||
359 | ScMarkData aMarkData = GetViewData()->GetMarkData(); | |||
360 | aMarkData.MarkToSimple(); | |||
361 | ScRange aRange; | |||
362 | aMarkData.GetMarkArea(aRange); | |||
363 | if(aMarkData.IsMarked()) | |||
364 | { | |||
365 | if (!rDoc.IsBlockEditable( aCursor.Tab(), aRange.aStart.Col(),aRange.aStart.Row(), | |||
366 | aRange.aEnd.Col(),aRange.aEnd.Row() )) | |||
367 | { | |||
368 | bDisable = true; | |||
369 | } | |||
370 | bNeedEdit=false; | |||
371 | } | |||
372 | ||||
373 | } | |||
374 | break; | |||
375 | case SID_INSERT_POSTIT( 10000 + 1101 ): | |||
376 | { | |||
377 | ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ); | |||
378 | if( rDoc.GetNote(aPos) ) | |||
379 | { | |||
380 | bDisable = true; | |||
381 | } | |||
382 | else | |||
383 | { | |||
384 | bDisable = false; | |||
385 | if ( pDocShell && pDocShell->IsDocShared() ) | |||
386 | { | |||
387 | bDisable = true; | |||
388 | } | |||
389 | } | |||
390 | } | |||
391 | break; | |||
392 | case SID_EDIT_POSTIT( 10000 + 1158 ): | |||
393 | { | |||
394 | ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ); | |||
395 | bDisable = rDoc.GetNote(aPos) == nullptr; | |||
396 | } | |||
397 | break; | |||
398 | } | |||
399 | if (!bDisable && bNeedEdit) | |||
400 | if (!rDoc.IsBlockEditable( aCursor.Tab(), aCursor.Col(),aCursor.Row(), | |||
401 | aCursor.Col(),aCursor.Row() )) | |||
402 | bDisable = true; | |||
403 | if (bDisable) | |||
404 | rSet.DisableItem(nWhich); | |||
405 | nWhich = aIter.NextWhich(); | |||
406 | } | |||
407 | } | |||
408 | ||||
409 | static bool lcl_TestFormat( SvxClipboardFormatItem& rFormats, const TransferableDataHelper& rDataHelper, | |||
410 | SotClipboardFormatId nFormatId ) | |||
411 | { | |||
412 | if ( rDataHelper.HasFormat( nFormatId ) ) | |||
413 | { | |||
414 | // translated format name strings are no longer inserted here, | |||
415 | // handled by "paste special" dialog / toolbox controller instead. | |||
416 | // Only the object type name has to be set here: | |||
417 | OUString aStrVal; | |||
418 | if ( nFormatId == SotClipboardFormatId::EMBED_SOURCE ) | |||
419 | { | |||
420 | TransferableObjectDescriptor aDesc; | |||
421 | if ( const_cast<TransferableDataHelper&>(rDataHelper).GetTransferableObjectDescriptor( | |||
422 | SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc ) ) | |||
423 | aStrVal = aDesc.maTypeName; | |||
424 | } | |||
425 | else if ( nFormatId == SotClipboardFormatId::EMBED_SOURCE_OLE | |||
426 | || nFormatId == SotClipboardFormatId::EMBEDDED_OBJ_OLE ) | |||
427 | { | |||
428 | OUString aSource; | |||
429 | SvPasteObjectHelper::GetEmbeddedName( rDataHelper, aStrVal, aSource, nFormatId ); | |||
430 | } | |||
431 | ||||
432 | if ( !aStrVal.isEmpty() ) | |||
433 | rFormats.AddClipbrdFormat( nFormatId, aStrVal ); | |||
434 | else | |||
435 | rFormats.AddClipbrdFormat( nFormatId ); | |||
436 | ||||
437 | return true; | |||
438 | } | |||
439 | ||||
440 | return false; | |||
441 | } | |||
442 | ||||
443 | void ScCellShell::GetPossibleClipboardFormats( SvxClipboardFormatItem& rFormats ) | |||
444 | { | |||
445 | vcl::Window* pWin = GetViewData()->GetActiveWin(); | |||
446 | bool bDraw = ScDrawTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(pWin)) != nullptr; | |||
447 | ||||
448 | TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) ); | |||
449 | ||||
450 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::DRAWING ); | |||
451 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::SVXB ); | |||
452 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::GDIMETAFILE ); | |||
453 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::PNG ); | |||
454 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::BITMAP ); | |||
455 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::EMBED_SOURCE ); | |||
456 | ||||
457 | if ( !bDraw ) | |||
458 | { | |||
459 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::LINK ); | |||
460 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::STRING ); | |||
461 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::STRING_TSVC ); | |||
462 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::DIF ); | |||
463 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::RTF ); | |||
464 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::RICHTEXT ); | |||
465 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::HTML ); | |||
466 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::HTML_SIMPLE ); | |||
467 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::BIFF_8 ); | |||
468 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::BIFF_5 ); | |||
469 | } | |||
470 | ||||
471 | if ( !lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::EMBED_SOURCE_OLE ) ) | |||
472 | lcl_TestFormat( rFormats, aDataHelper, SotClipboardFormatId::EMBEDDED_OBJ_OLE ); | |||
473 | } | |||
474 | ||||
475 | // insert, insert contents | |||
476 | ||||
477 | static bool lcl_IsCellPastePossible( const TransferableDataHelper& rData ) | |||
478 | { | |||
479 | bool bPossible = false; | |||
480 | css::uno::Reference< css::datatransfer::XTransferable2 > xTransferable(rData.GetXTransferable(), css::uno::UNO_QUERY); | |||
481 | if ( ScTransferObj::GetOwnClipboard(xTransferable) || ScDrawTransferObj::GetOwnClipboard(xTransferable) ) | |||
482 | bPossible = true; | |||
483 | else | |||
484 | { | |||
485 | if ( rData.HasFormat( SotClipboardFormatId::PNG ) || | |||
486 | rData.HasFormat( SotClipboardFormatId::BITMAP ) || | |||
487 | rData.HasFormat( SotClipboardFormatId::GDIMETAFILE ) || | |||
488 | rData.HasFormat( SotClipboardFormatId::SVXB ) || | |||
489 | rData.HasFormat( SotClipboardFormatId::PRIVATE ) || | |||
490 | rData.HasFormat( SotClipboardFormatId::RTF ) || | |||
491 | rData.HasFormat( SotClipboardFormatId::RICHTEXT ) || | |||
492 | rData.HasFormat( SotClipboardFormatId::EMBED_SOURCE ) || | |||
493 | rData.HasFormat( SotClipboardFormatId::LINK_SOURCE ) || | |||
494 | rData.HasFormat( SotClipboardFormatId::EMBED_SOURCE_OLE ) || | |||
495 | rData.HasFormat( SotClipboardFormatId::LINK_SOURCE_OLE ) || | |||
496 | rData.HasFormat( SotClipboardFormatId::EMBEDDED_OBJ_OLE ) || | |||
497 | rData.HasFormat( SotClipboardFormatId::STRING ) || | |||
498 | rData.HasFormat( SotClipboardFormatId::STRING_TSVC ) || | |||
499 | rData.HasFormat( SotClipboardFormatId::SYLK ) || | |||
500 | rData.HasFormat( SotClipboardFormatId::LINK ) || | |||
501 | rData.HasFormat( SotClipboardFormatId::HTML ) || | |||
502 | rData.HasFormat( SotClipboardFormatId::HTML_SIMPLE ) || | |||
503 | rData.HasFormat( SotClipboardFormatId::DIF ) ) | |||
504 | { | |||
505 | bPossible = true; | |||
506 | } | |||
507 | } | |||
508 | return bPossible; | |||
509 | } | |||
510 | ||||
511 | bool ScCellShell::HasClipboardFormat( SotClipboardFormatId nFormatId ) | |||
512 | { | |||
513 | vcl::Window* pWin = GetViewData()->GetActiveWin(); | |||
514 | TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin )); | |||
515 | return aDataHelper.HasFormat( nFormatId ); | |||
516 | } | |||
517 | ||||
518 | IMPL_LINK( ScCellShell, ClipboardChanged, TransferableDataHelper*, pDataHelper, void )void ScCellShell::LinkStubClipboardChanged(void * instance, TransferableDataHelper * data) { return static_cast<ScCellShell *>(instance)-> ClipboardChanged(data); } void ScCellShell::ClipboardChanged( TransferableDataHelper* pDataHelper) | |||
519 | { | |||
520 | bPastePossible = lcl_IsCellPastePossible( *pDataHelper ); | |||
521 | ||||
522 | SfxBindings& rBindings = GetViewData()->GetBindings(); | |||
523 | rBindings.Invalidate( SID_PASTE(5000 + 712) ); | |||
524 | rBindings.Invalidate( SID_PASTE_SPECIAL(5000 + 311) ); | |||
525 | rBindings.Invalidate( SID_PASTE_UNFORMATTED(5000 + 314) ); | |||
526 | rBindings.Invalidate( SID_PASTE_ONLY_VALUE(5000 + 804) ); | |||
527 | rBindings.Invalidate( SID_PASTE_ONLY_TEXT(5000 + 802) ); | |||
528 | rBindings.Invalidate( SID_PASTE_ONLY_FORMULA(5000 + 803) ); | |||
529 | rBindings.Invalidate( SID_PASTE_TEXTIMPORT_DIALOG(5000 + 805) ); | |||
530 | rBindings.Invalidate( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ); | |||
531 | } | |||
532 | ||||
533 | namespace { | |||
534 | ||||
535 | bool checkDestRanges(ScViewData& rViewData) | |||
536 | { | |||
537 | ScRange aDummy; | |||
538 | ScMarkType eMarkType = rViewData.GetSimpleArea( aDummy); | |||
539 | if (eMarkType != SC_MARK_MULTI) | |||
540 | { | |||
541 | // Single destination range. | |||
542 | if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED) | |||
543 | return false; | |||
544 | } | |||
545 | ||||
546 | if (rViewData.SelectionForbidsCellFill()) | |||
547 | return false; | |||
548 | ||||
549 | // Multiple destination ranges. | |||
550 | ||||
551 | ScDocument& rDoc = rViewData.GetDocument(); | |||
552 | vcl::Window* pWin = rViewData.GetActiveWin(); | |||
553 | if (!pWin) | |||
554 | return false; | |||
555 | ||||
556 | const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(pWin)); | |||
557 | if (!pOwnClip) | |||
558 | // If it's not a Calc document, we won't be picky. | |||
559 | return true; | |||
560 | ||||
561 | ScDocument* pClipDoc = pOwnClip->GetDocument(); | |||
562 | if (!pClipDoc) | |||
563 | return false; | |||
564 | ||||
565 | ScRange aSrcRange = pClipDoc->GetClipParam().getWholeRange(); | |||
566 | SCROW nRowSize = aSrcRange.aEnd.Row() - aSrcRange.aStart.Row() + 1; | |||
567 | SCCOL nColSize = aSrcRange.aEnd.Col() - aSrcRange.aStart.Col() + 1; | |||
568 | ||||
569 | ScMarkData aMark = rViewData.GetMarkData(); | |||
570 | ScRangeList aRanges; | |||
571 | aMark.MarkToSimple(); | |||
572 | aMark.FillRangeListWithMarks(&aRanges, false); | |||
573 | ||||
574 | return ScClipUtil::CheckDestRanges(rDoc, nColSize, nRowSize, aMark, aRanges); | |||
575 | } | |||
576 | ||||
577 | } | |||
578 | ||||
579 | void ScCellShell::GetClipState( SfxItemSet& rSet ) | |||
580 | { | |||
581 | // SID_PASTE | |||
582 | // SID_PASTE_SPECIAL | |||
583 | // SID_PASTE_UNFORMATTED | |||
584 | // SID_CLIPBOARD_FORMAT_ITEMS | |||
585 | ||||
586 | if ( !pImpl->m_xClipEvtLstnr.is() ) | |||
587 | { | |||
588 | // create listener | |||
589 | pImpl->m_xClipEvtLstnr = new TransferableClipboardListener( LINK( this, ScCellShell, ClipboardChanged )::tools::detail::makeLink( ::tools::detail::castTo<ScCellShell *>(this), &ScCellShell::LinkStubClipboardChanged) ); | |||
590 | vcl::Window* pWin = GetViewData()->GetActiveWin(); | |||
591 | pImpl->m_xClipEvtLstnr->AddListener( pWin ); | |||
592 | ||||
593 | // get initial state | |||
594 | TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pWin ) ); | |||
595 | bPastePossible = lcl_IsCellPastePossible( aDataHelper ); | |||
596 | } | |||
597 | ||||
598 | bool bDisable = !bPastePossible; | |||
599 | ||||
600 | // cell protection / multiple selection | |||
601 | ||||
602 | if (!bDisable) | |||
603 | { | |||
604 | SCCOL nCol = GetViewData()->GetCurX(); | |||
605 | SCROW nRow = GetViewData()->GetCurY(); | |||
606 | SCTAB nTab = GetViewData()->GetTabNo(); | |||
607 | ScDocument& rDoc = GetViewData()->GetDocShell()->GetDocument(); | |||
608 | if (!rDoc.IsBlockEditable( nTab, nCol,nRow, nCol,nRow )) | |||
609 | bDisable = true; | |||
610 | ||||
611 | if (!bDisable && !checkDestRanges(*GetViewData())) | |||
612 | bDisable = true; | |||
613 | } | |||
614 | ||||
615 | if (bDisable) | |||
616 | { | |||
617 | rSet.DisableItem( SID_PASTE(5000 + 712) ); | |||
618 | rSet.DisableItem( SID_PASTE_SPECIAL(5000 + 311) ); | |||
619 | rSet.DisableItem( SID_PASTE_UNFORMATTED(5000 + 314) ); | |||
620 | rSet.DisableItem( SID_PASTE_ONLY_VALUE(5000 + 804) ); | |||
621 | rSet.DisableItem( SID_PASTE_ONLY_TEXT(5000 + 802) ); | |||
622 | rSet.DisableItem( SID_PASTE_ONLY_FORMULA(5000 + 803) ); | |||
623 | rSet.DisableItem( SID_PASTE_TEXTIMPORT_DIALOG(5000 + 805) ); | |||
624 | rSet.DisableItem( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ); | |||
625 | } | |||
626 | else if ( rSet.GetItemState( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ) != SfxItemState::UNKNOWN ) | |||
627 | { | |||
628 | SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS(5000 + 312) ); | |||
629 | GetPossibleClipboardFormats( aFormats ); | |||
630 | rSet.Put( aFormats ); | |||
631 | } | |||
632 | } | |||
633 | ||||
634 | // only SID_HYPERLINK_GETLINK: | |||
635 | ||||
636 | void ScCellShell::GetHLinkState( SfxItemSet& rSet ) | |||
637 | { | |||
638 | // always return an item (or inserting will be disabled) | |||
639 | // if the cell at the cursor contains only a link, return that link | |||
640 | ||||
641 | SvxHyperlinkItem aHLinkItem; | |||
642 | if ( !GetViewData()->GetView()->HasBookmarkAtCursor( &aHLinkItem ) ) | |||
643 | { | |||
644 | //! put selected text into item? | |||
645 | } | |||
646 | ||||
647 | rSet.Put(aHLinkItem); | |||
648 | } | |||
649 | ||||
650 | void ScCellShell::GetState(SfxItemSet &rSet) | |||
651 | { | |||
652 | ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); | |||
653 | ScDocShell* pDocSh = GetViewData()->GetDocShell(); | |||
654 | ScViewData* pData = GetViewData(); | |||
655 | ScDocument& rDoc = pData->GetDocument(); | |||
656 | ScMarkData& rMark = pData->GetMarkData(); | |||
657 | SCCOL nPosX = pData->GetCurX(); | |||
658 | SCROW nPosY = pData->GetCurY(); | |||
659 | SCTAB nTab = pData->GetTabNo(); | |||
660 | ||||
661 | SCTAB nTabCount = rDoc.GetTableCount(); | |||
662 | SCTAB nTabSelCount = rMark.GetSelectCount(); | |||
663 | ||||
664 | SfxWhichIter aIter(rSet); | |||
665 | sal_uInt16 nWhich = aIter.FirstWhich(); | |||
666 | while ( nWhich ) | |||
667 | { | |||
668 | switch ( nWhich ) | |||
669 | { | |||
670 | case SID_DETECTIVE_REFRESH((((((((((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 29)) + 20))+20))+1))+50))+20))+14): | |||
671 | if (!rDoc.HasDetectiveOperations()) | |||
672 | rSet.DisableItem( nWhich ); | |||
673 | break; | |||
674 | ||||
675 | case SID_RANGE_ADDRESS((((26000 + 521) + 50))+47): | |||
676 | { | |||
677 | ScRange aRange; | |||
678 | if ( pData->GetSimpleArea( aRange ) == SC_MARK_SIMPLE ) | |||
679 | { | |||
680 | OUString aStr(aRange.Format(rDoc, ScRefFlags::VALID | ScRefFlags::TAB_3D)); | |||
681 | rSet.Put( SfxStringItem( nWhich, aStr ) ); | |||
682 | } | |||
683 | } | |||
684 | break; | |||
685 | ||||
686 | case SID_RANGE_NOTETEXT((((26000 + 521) + 50))+52): | |||
687 | { | |||
688 | // always take cursor position, do not use top-left cell of selection | |||
689 | OUString aNoteText; | |||
690 | if ( const ScPostIt* pNote = rDoc.GetNote(nPosX, nPosY, nTab) ) | |||
691 | aNoteText = pNote->GetText(); | |||
692 | rSet.Put( SfxStringItem( nWhich, aNoteText ) ); | |||
693 | } | |||
694 | break; | |||
695 | ||||
696 | case SID_RANGE_ROW((((26000 + 521) + 50))+20): | |||
697 | rSet.Put( SfxInt32Item( nWhich, nPosY+1 ) ); | |||
698 | break; | |||
699 | ||||
700 | case SID_RANGE_COL((((26000 + 521) + 50))+21): | |||
701 | rSet.Put( SfxInt16Item( nWhich, nPosX+1 ) ); | |||
702 | break; | |||
703 | ||||
704 | case SID_RANGE_TABLE((((26000 + 521) + 50))+22): | |||
705 | rSet.Put( SfxInt16Item( nWhich, nTab+1 ) ); | |||
706 | break; | |||
707 | ||||
708 | case SID_RANGE_FORMULA((((26000 + 521) + 50))+24): | |||
709 | { | |||
710 | OUString aString; | |||
711 | rDoc.GetFormula( nPosX, nPosY, nTab, aString ); | |||
712 | if( aString.isEmpty() ) | |||
713 | { | |||
714 | rDoc.GetInputString( nPosX, nPosY, nTab, aString ); | |||
715 | } | |||
716 | rSet.Put( SfxStringItem( nWhich, aString ) ); | |||
717 | } | |||
718 | break; | |||
719 | ||||
720 | case SID_RANGE_TEXTVALUE((((26000 + 521) + 50))+26): | |||
721 | { | |||
722 | OUString aString = rDoc.GetString(nPosX, nPosY, nTab); | |||
723 | rSet.Put( SfxStringItem( nWhich, aString ) ); | |||
724 | } | |||
725 | break; | |||
726 | ||||
727 | case SID_STATUS_SELMODE((26000 + 100) + 16): | |||
728 | { | |||
729 | /* 0: STD Click cancels Sel | |||
730 | * 1: ER Click extends selection | |||
731 | * 2: ERG Click defines further selection | |||
732 | */ | |||
733 | sal_uInt16 nMode = pTabViewShell->GetLockedModifiers(); | |||
734 | ||||
735 | switch ( nMode ) | |||
736 | { | |||
737 | case KEY_SHIFT: nMode = 1; break; | |||
738 | case KEY_MOD1: nMode = 2; break; // Control-key | |||
739 | case 0: | |||
740 | default: | |||
741 | nMode = 0; | |||
742 | } | |||
743 | ||||
744 | rSet.Put( SfxUInt16Item( nWhich, nMode ) ); | |||
745 | } | |||
746 | break; | |||
747 | ||||
748 | case SID_STATUS_DOCPOS((26000 + 100) + 14): | |||
749 | { | |||
750 | OUString aStr = ScResId( STR_TABLE_COUNTreinterpret_cast<char const *>("STR_TABLE_COUNT" "\004" u8"Sheet %1 of %2") ); | |||
751 | ||||
752 | aStr = aStr.replaceFirst("%1", OUString::number( nTab + 1 ) ); | |||
753 | aStr = aStr.replaceFirst("%2", OUString::number( nTabCount ) ); | |||
754 | ||||
755 | rSet.Put( SfxStringItem( nWhich, aStr ) ); } | |||
756 | break; | |||
757 | ||||
758 | case SID_ROWCOL_SELCOUNT((26000 + 100) + 38): | |||
759 | { | |||
760 | ScRange aMarkRange; | |||
761 | GetViewData()->GetSimpleArea( aMarkRange ); | |||
762 | SCCOL nCol1, nCol2; | |||
763 | SCROW nRow1, nRow2; | |||
764 | nCol1 = aMarkRange.aStart.Col(); | |||
765 | nRow1 = aMarkRange.aStart.Row(); | |||
766 | nCol2 = aMarkRange.aEnd.Col(); | |||
767 | nRow2 = aMarkRange.aEnd.Row(); | |||
768 | if( nCol2 != nCol1 || nRow1 != nRow2 ) | |||
769 | { | |||
770 | const auto nRows = nRow2 - nRow1 + 1; | |||
771 | const auto nCols = nCol2 - nCol1 + 1; | |||
772 | const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetUILocaleDataWrapper(); | |||
773 | OUString aRowArg = ScResId(STR_SELCOUNT_ROWARGreinterpret_cast<char const *>("STR_SELCOUNT_ROWARG" "\004" u8"$1 row" "\004" u8"$1 rows"), nRows).replaceAll("$1", rLocaleData.getNum(nRows, 0)); | |||
774 | OUString aColArg = ScResId(STR_SELCOUNT_COLARGreinterpret_cast<char const *>("STR_SELCOUNT_COLARG" "\004" u8"$1 column" "\004" u8"$1 columns"), nCols).replaceAll("$1", rLocaleData.getNum(nCols, 0)); | |||
775 | OUString aStr = ScResId(STR_SELCOUNTreinterpret_cast<char const *>("STR_SELCOUNT" "\004" u8"Selected: $1, $2" )); | |||
776 | aStr = aStr.replaceAll("$1", aRowArg); | |||
777 | aStr = aStr.replaceAll("$2", aColArg); | |||
778 | rSet.Put( SfxStringItem( nWhich, aStr ) ); | |||
779 | } | |||
780 | else | |||
781 | { | |||
782 | SCSIZE nSelected, nTotal; | |||
783 | rDoc.GetFilterSelCount( nPosX, nPosY, nTab, nSelected, nTotal ); | |||
784 | if( nTotal ) | |||
785 | { | |||
786 | OUString aStr = ScResId( STR_FILTER_SELCOUNTreinterpret_cast<char const *>("STR_FILTER_SELCOUNT" "\004" u8"$1 of $2 records found") ); | |||
787 | aStr = aStr.replaceAll( "$1", OUString::number( nSelected ) ); | |||
788 | aStr = aStr.replaceAll( "$2", OUString::number( nTotal ) ); | |||
789 | rSet.Put( SfxStringItem( nWhich, aStr ) ); | |||
790 | } | |||
791 | } | |||
792 | } | |||
793 | break; | |||
794 | ||||
795 | // calculations etc. with date/time/Fail/position&size together | |||
796 | ||||
797 | // #i34458# The SfxStringItem belongs only into SID_TABLE_CELL. It no longer has to be | |||
798 | // duplicated in SID_ATTR_POSITION or SID_ATTR_SIZE for SvxPosSizeStatusBarControl. | |||
799 | case SID_TABLE_CELL( 10000 + 225 ): | |||
800 | { | |||
801 | // Test, if error under cursor | |||
802 | // (not rDoc.GetErrCode, to avoid erasing circular references) | |||
803 | ||||
804 | // In interpreter may happen via rescheduled Basic | |||
805 | if ( rDoc.IsInInterpreter() ) | |||
806 | rSet.Put( SfxStringItem( nWhich, "..." ) ); | |||
807 | else | |||
808 | { | |||
809 | FormulaError nErrCode = FormulaError::NONE; | |||
810 | ScFormulaCell* pCell = rDoc.GetFormulaCell(ScAddress(nPosX, nPosY, nTab)); | |||
811 | if (pCell && !pCell->IsRunning()) | |||
812 | nErrCode = pCell->GetErrCode(); | |||
813 | ||||
814 | OUString aFuncStr; | |||
815 | if ( pTabViewShell->GetFunction( aFuncStr, nErrCode ) ) | |||
816 | rSet.Put( SfxStringItem( nWhich, aFuncStr ) ); | |||
817 | } | |||
818 | } | |||
819 | break; | |||
820 | ||||
821 | case SID_DATA_SELECT((((26000 + 521) + 50))+39): | |||
822 | // HasSelectionData includes column content and validity, | |||
823 | // page fields have to be checked separately. | |||
824 | if ( !rDoc.HasSelectionData( nPosX, nPosY, nTab ) && | |||
825 | !pTabViewShell->HasPageFieldDataAtCursor() ) | |||
826 | rSet.DisableItem( nWhich ); | |||
827 | break; | |||
828 | ||||
829 | case FID_CURRENTVALIDATION((((26000 + 521) + 50))+51): | |||
830 | if ( !rDoc.HasValidationData( nPosX, nPosY, nTab )) | |||
831 | rSet.DisableItem( nWhich ); | |||
832 | break; | |||
833 | ||||
834 | case SID_STATUS_SUM((26000 + 100) + 30): | |||
835 | { | |||
836 | OUString aFuncStr; | |||
837 | if ( pTabViewShell->GetFunction( aFuncStr, FormulaError::NONE ) ) | |||
838 | rSet.Put( SfxStringItem( nWhich, aFuncStr ) ); | |||
839 | } | |||
840 | break; | |||
841 | ||||
842 | case FID_MERGE_ON((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 15): | |||
843 | if ( rDoc.GetChangeTrack() || !pTabViewShell->TestMergeCells() ) | |||
844 | rSet.DisableItem( nWhich ); | |||
845 | break; | |||
846 | ||||
847 | case FID_MERGE_OFF((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 16): | |||
848 | if ( rDoc.GetChangeTrack() || !pTabViewShell->TestRemoveMerge() ) | |||
849 | rSet.DisableItem( nWhich ); | |||
850 | break; | |||
851 | ||||
852 | case FID_MERGE_TOGGLE((((26000 + 521) + 50))+10): | |||
853 | if ( rDoc.GetChangeTrack() ) | |||
854 | rSet.DisableItem( nWhich ); | |||
855 | else | |||
856 | { | |||
857 | bool bCanMerge = pTabViewShell->TestMergeCells(); | |||
858 | bool bCanSplit = pTabViewShell->TestRemoveMerge(); | |||
859 | if( !bCanMerge && !bCanSplit ) | |||
860 | rSet.DisableItem( nWhich ); | |||
861 | else | |||
862 | rSet.Put( SfxBoolItem( nWhich, bCanSplit ) ); | |||
863 | } | |||
864 | break; | |||
865 | ||||
866 | case FID_INS_ROWBRK((((((((26000 + 200) + 20)) + 20)) + 20)) + 1): | |||
867 | if ( nPosY==0 || (rDoc.HasRowBreak(nPosY, nTab) & ScBreakType::Manual) || rDoc.IsTabProtected(nTab) ) | |||
868 | rSet.DisableItem( nWhich ); | |||
869 | break; | |||
870 | ||||
871 | case FID_INS_COLBRK((((((((26000 + 200) + 20)) + 20)) + 20)) + 2): | |||
872 | if ( nPosX==0 || (rDoc.HasColBreak(nPosX, nTab) & ScBreakType::Manual) || rDoc.IsTabProtected(nTab) ) | |||
873 | rSet.DisableItem( nWhich ); | |||
874 | break; | |||
875 | ||||
876 | case FID_DEL_ROWBRK((((((((26000 + 200) + 20)) + 20)) + 20)) + 3): | |||
877 | if ( nPosY==0 || !(rDoc.HasRowBreak(nPosY, nTab) & ScBreakType::Manual) || rDoc.IsTabProtected(nTab) ) | |||
878 | rSet.DisableItem( nWhich ); | |||
879 | break; | |||
880 | ||||
881 | case FID_DEL_COLBRK((((((((26000 + 200) + 20)) + 20)) + 20)) + 4): | |||
882 | if ( nPosX==0 || !(rDoc.HasColBreak(nPosX, nTab) & ScBreakType::Manual) || rDoc.IsTabProtected(nTab) ) | |||
883 | rSet.DisableItem( nWhich ); | |||
884 | break; | |||
885 | ||||
886 | case FID_FILL_TAB((((26000 + 200) + 20)) + 8): | |||
887 | if ( nTabSelCount < 2 ) | |||
888 | rSet.DisableItem( nWhich ); | |||
889 | break; | |||
890 | ||||
891 | case SID_INSERT_CURRENT_DATE((20000 +5000)+16): | |||
892 | case SID_INSERT_CURRENT_TIME((20000 +5000)+17): | |||
893 | { | |||
894 | if ( rDoc.IsTabProtected(nTab) && | |||
895 | rDoc.HasAttrib(nPosX, nPosY, nTab, nPosX, nPosY, nTab, HasAttrFlags::Protected)) | |||
896 | rSet.DisableItem( nWhich ); | |||
897 | } | |||
898 | break; | |||
899 | ||||
900 | case SID_SELECT_SCENARIO((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22 )) + 20)) + 29)) + 20))+13): | |||
901 | { | |||
902 | std::vector<OUString> aList; | |||
903 | Color aDummyCol; | |||
904 | ||||
905 | if ( !rDoc.IsScenario(nTab) ) | |||
906 | { | |||
907 | OUString aStr; | |||
908 | ScScenarioFlags nFlags; | |||
909 | SCTAB nScTab = nTab + 1; | |||
910 | bool bSheetProtected = rDoc.IsTabProtected(nTab); | |||
911 | ||||
912 | while ( rDoc.IsScenario(nScTab) ) | |||
913 | { | |||
914 | rDoc.GetName( nScTab, aStr ); | |||
915 | aList.push_back(aStr); | |||
916 | rDoc.GetScenarioData( nScTab, aStr, aDummyCol, nFlags ); | |||
917 | aList.push_back(aStr); | |||
918 | // Protection is sal_True if both Sheet and Scenario are protected | |||
919 | aList.push_back((bSheetProtected && (nFlags & ScScenarioFlags::Protected)) ? OUString("1") : OUString("0")); | |||
920 | ++nScTab; | |||
921 | } | |||
922 | } | |||
923 | else | |||
924 | { | |||
925 | OUString aComment; | |||
926 | ScScenarioFlags nDummyFlags; | |||
927 | rDoc.GetScenarioData( nTab, aComment, aDummyCol, nDummyFlags ); | |||
928 | OSL_ENSURE( aList.empty(), "List not empty!" )do { if (true && (!(aList.empty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh.cxx" ":" "928" ": "), "%s", "List not empty!"); } } while (false); | |||
929 | aList.push_back(aComment); | |||
930 | } | |||
931 | ||||
932 | rSet.Put( SfxStringListItem( nWhich, &aList ) ); | |||
933 | } | |||
934 | break; | |||
935 | ||||
936 | case FID_ROW_HIDE((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 3): | |||
937 | case FID_ROW_SHOW((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 4): | |||
938 | case FID_COL_HIDE((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 7): | |||
939 | case FID_COL_SHOW((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 8): | |||
940 | case FID_COL_OPT_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 6): | |||
941 | case FID_ROW_OPT_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 2): | |||
942 | case FID_DELETE_CELL((((26000 + 200) + 20)) + 2): | |||
943 | if ( rDoc.IsTabProtected(nTab) || pDocSh->IsReadOnly()) | |||
944 | rSet.DisableItem( nWhich ); | |||
945 | break; | |||
946 | ||||
947 | case SID_OUTLINE_MAKE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 27): | |||
948 | { | |||
949 | if ( GetViewData()->GetDocument().GetDPAtCursor( GetViewData()->GetCurX(), | |||
950 | GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) ) | |||
951 | { | |||
952 | //! test for data pilot operation | |||
953 | } | |||
954 | else if (rDoc.GetChangeTrack()!=nullptr || GetViewData()->IsMultiMarked()) | |||
955 | { | |||
956 | rSet.DisableItem( nWhich ); | |||
957 | } | |||
958 | } | |||
959 | break; | |||
960 | case SID_OUTLINE_SHOW((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 26): | |||
961 | if ( GetViewData()->GetDocument().GetDPAtCursor( GetViewData()->GetCurX(), | |||
962 | GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) ) | |||
963 | { | |||
964 | //! test for data pilot operation | |||
965 | } | |||
966 | else if (!pTabViewShell->OutlinePossible(false)) | |||
967 | rSet.DisableItem( nWhich ); | |||
968 | break; | |||
969 | ||||
970 | case SID_OUTLINE_HIDE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 25): | |||
971 | if ( GetViewData()->GetDocument().GetDPAtCursor( GetViewData()->GetCurX(), | |||
972 | GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) ) | |||
973 | { | |||
974 | //! test for data pilot operation | |||
975 | } | |||
976 | else if (!pTabViewShell->OutlinePossible(true)) | |||
977 | rSet.DisableItem( nWhich ); | |||
978 | break; | |||
979 | ||||
980 | case SID_OUTLINE_REMOVE((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 28): | |||
981 | { | |||
982 | if ( GetViewData()->GetDocument().GetDPAtCursor( GetViewData()->GetCurX(), | |||
983 | GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) ) | |||
984 | { | |||
985 | //! test for data pilot operation | |||
986 | } | |||
987 | else | |||
988 | { | |||
989 | bool bCol, bRow; | |||
990 | pTabViewShell->TestRemoveOutline( bCol, bRow ); | |||
991 | if ( !bCol && !bRow ) | |||
992 | rSet.DisableItem( nWhich ); | |||
993 | } | |||
994 | } | |||
995 | break; | |||
996 | ||||
997 | case FID_COL_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 5): | |||
998 | { | |||
999 | SfxUInt16Item aWidthItem( FID_COL_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 5), rDoc.GetColWidth( nPosX , nTab) ); | |||
1000 | rSet.Put( aWidthItem ); | |||
1001 | if ( pDocSh->IsReadOnly()) | |||
1002 | rSet.DisableItem( nWhich ); | |||
1003 | ||||
1004 | //XXX disable if not conclusive | |||
1005 | } | |||
1006 | break; | |||
1007 | ||||
1008 | case FID_ROW_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 1): | |||
1009 | { | |||
1010 | SfxUInt16Item aHeightItem( FID_ROW_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 1), rDoc.GetRowHeight( nPosY , nTab) ); | |||
1011 | rSet.Put( aHeightItem ); | |||
1012 | //XXX disable if not conclusive | |||
1013 | if ( pDocSh->IsReadOnly()) | |||
1014 | rSet.DisableItem( nWhich ); | |||
1015 | } | |||
1016 | break; | |||
1017 | ||||
1018 | case SID_DETECTIVE_FILLMODE((((((((((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 29)) + 20))+20))+1))+50))+20))+6): | |||
1019 | rSet.Put(SfxBoolItem( nWhich, pTabViewShell->IsAuditShell() )); | |||
1020 | break; | |||
1021 | ||||
1022 | case FID_INPUTLINE_STATUS((26000 + 100)): | |||
1023 | OSL_FAIL( "Old update method. Use ScTabViewShell::UpdateInputHandler()." )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/cellsh.cxx" ":" "1023" ": "), "%s", "Old update method. Use ScTabViewShell::UpdateInputHandler()." ); } } while (false); | |||
1024 | break; | |||
1025 | ||||
1026 | case SID_SCENARIOS((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 12): // scenarios: | |||
1027 | if (!(rMark.IsMarked() || rMark.IsMultiMarked())) // only, if something selected | |||
1028 | rSet.DisableItem( nWhich ); | |||
1029 | break; | |||
1030 | ||||
1031 | case FID_NOTE_VISIBLE((((26000 + 521) + 50))+59): | |||
1032 | { | |||
1033 | const ScPostIt* pNote = rDoc.GetNote(nPosX, nPosY, nTab); | |||
1034 | if ( pNote && rDoc.IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) ) | |||
1035 | rSet.Put( SfxBoolItem( nWhich, pNote->IsCaptionShown() ) ); | |||
1036 | else | |||
1037 | rSet.DisableItem( nWhich ); | |||
1038 | } | |||
1039 | break; | |||
1040 | ||||
1041 | case FID_HIDE_NOTE((((26000 + 521) + 50))+101): | |||
1042 | case FID_SHOW_NOTE((((26000 + 521) + 50))+100): | |||
1043 | { | |||
1044 | bool bEnable = false; | |||
1045 | bool bSearchForHidden = nWhich == FID_SHOW_NOTE((((26000 + 521) + 50))+100); | |||
1046 | if (!rMark.IsMarked() && !rMark.IsMultiMarked()) | |||
1047 | { | |||
1048 | // Check current cell | |||
1049 | const ScPostIt* pNote = rDoc.GetNote(nPosX, nPosY, nTab); | |||
1050 | if ( pNote && rDoc.IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) ) | |||
1051 | if ( pNote->IsCaptionShown() != bSearchForHidden) | |||
1052 | bEnable = true; | |||
1053 | } | |||
1054 | else | |||
1055 | { | |||
1056 | // Check selection range | |||
1057 | ScRangeListRef aRangesRef; | |||
1058 | pData->GetMultiArea(aRangesRef); | |||
1059 | ScRangeList aRanges = *aRangesRef; | |||
1060 | std::vector<sc::NoteEntry> aNotes; | |||
1061 | rDoc.GetNotesInRange(aRanges, aNotes); | |||
1062 | for(const auto& rNote : aNotes) | |||
1063 | { | |||
1064 | const ScAddress& rAdr = rNote.maPos; | |||
1065 | if( rDoc.IsBlockEditable( rAdr.Tab(), rAdr.Col(), rAdr.Row(), rAdr.Col(), rAdr.Row() )) | |||
1066 | { | |||
1067 | if (rNote.mpNote->IsCaptionShown() != bSearchForHidden) | |||
1068 | { | |||
1069 | bEnable = true; | |||
1070 | break; | |||
1071 | } | |||
1072 | } | |||
1073 | } | |||
1074 | ||||
1075 | } | |||
1076 | if ( !bEnable ) | |||
1077 | rSet.DisableItem( nWhich ); | |||
1078 | } | |||
1079 | break; | |||
1080 | ||||
1081 | case FID_SHOW_ALL_NOTES((((26000 + 521) + 50))+102): | |||
1082 | case FID_HIDE_ALL_NOTES((((26000 + 521) + 50))+103): | |||
1083 | case FID_DELETE_ALL_NOTES((((26000 + 521) + 50))+104): | |||
1084 | { | |||
1085 | bool bHasNotes = false; | |||
1086 | ||||
1087 | for (auto const& rTab : rMark.GetSelectedTabs()) | |||
1088 | { | |||
1089 | if (rDoc.HasTabNotes( rTab )) | |||
1090 | { | |||
1091 | bHasNotes = true; | |||
1092 | break; | |||
1093 | } | |||
1094 | } | |||
1095 | ||||
1096 | if ( !bHasNotes ) | |||
1097 | rSet.DisableItem( nWhich ); | |||
1098 | } | |||
1099 | break; | |||
1100 | ||||
1101 | case SID_TOGGLE_NOTES( 10000 + 1098 ): | |||
1102 | { | |||
1103 | bool bHasNotes = false; | |||
1104 | ScRangeList aRanges; | |||
1105 | ||||
1106 | for (auto const& rTab : rMark.GetSelectedTabs()) | |||
1107 | { | |||
1108 | if (rDoc.HasTabNotes( rTab )) | |||
1109 | { | |||
1110 | bHasNotes = true; | |||
1111 | aRanges.push_back(ScRange(0,0,rTab,rDoc.MaxCol(),rDoc.MaxRow(),rTab)); | |||
1112 | } | |||
1113 | } | |||
1114 | ||||
1115 | if ( !bHasNotes ) | |||
1116 | rSet.DisableItem( nWhich ); | |||
1117 | else | |||
1118 | { | |||
1119 | CommentCaptionState eState = rDoc.GetAllNoteCaptionsState( aRanges ); | |||
1120 | bool bAllNotesInShown = (eState != ALLHIDDEN && eState != MIXED); | |||
1121 | rSet.Put( SfxBoolItem( SID_TOGGLE_NOTES( 10000 + 1098 ), bAllNotesInShown) ); | |||
1122 | } | |||
1123 | } | |||
1124 | break; | |||
1125 | ||||
1126 | case SID_DELETE_NOTE((((((((((((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) + 20)) + 29)) + 20))+20))+1))+50))+20))+20))+2 ): | |||
1127 | { | |||
1128 | bool bEnable = false; | |||
1129 | if ( rMark.IsMarked() || rMark.IsMultiMarked() ) | |||
1130 | { | |||
1131 | if ( rDoc.IsSelectionEditable( rMark ) ) | |||
1132 | { | |||
1133 | // look for at least one note in selection | |||
1134 | ScRangeList aRanges; | |||
1135 | rMark.FillRangeListWithMarks( &aRanges, false ); | |||
1136 | bEnable = rDoc.ContainsNotesInRange( aRanges ); | |||
1137 | } | |||
1138 | } | |||
1139 | else | |||
1140 | { | |||
1141 | bEnable = rDoc.IsBlockEditable( nTab, nPosX,nPosY, nPosX,nPosY ) && | |||
1142 | rDoc.GetNote(nPosX, nPosY, nTab); | |||
1143 | } | |||
1144 | if ( !bEnable ) | |||
1145 | rSet.DisableItem( nWhich ); | |||
1146 | } | |||
1147 | break; | |||
1148 | ||||
1149 | case SID_OPENDLG_CONSOLIDATE((26000 + 100) + 50): | |||
1150 | case SCITEM_CONSOLIDATEDATA1105: | |||
1151 | { | |||
1152 | if (rDoc.GetChangeTrack()!=nullptr) | |||
1153 | rSet.DisableItem( nWhich); | |||
1154 | } | |||
1155 | break; | |||
1156 | ||||
1157 | case SID_CHINESE_CONVERSION( 10000 + 1016 ): | |||
1158 | case SID_HANGUL_HANJA_CONVERSION( 10000 + 959 ): | |||
1159 | ScViewUtil::HideDisabledSlot( rSet, pData->GetBindings(), nWhich ); | |||
1160 | break; | |||
1161 | ||||
1162 | case FID_USE_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 13): | |||
1163 | { | |||
1164 | if ( pDocSh && pDocSh->IsDocShared() ) | |||
1165 | rSet.DisableItem( nWhich ); | |||
1166 | else | |||
1167 | { | |||
1168 | ScRange aRange; | |||
1169 | if ( pData->GetSimpleArea( aRange ) != SC_MARK_SIMPLE ) | |||
1170 | rSet.DisableItem( nWhich ); | |||
1171 | } | |||
1172 | } | |||
1173 | break; | |||
1174 | ||||
1175 | case FID_DEFINE_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 11): | |||
1176 | case FID_INSERT_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 12): | |||
1177 | case FID_ADD_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 16): | |||
1178 | case SID_DEFINE_COLROWNAMERANGES((((26000 + 521) + 50))+58): | |||
1179 | { | |||
1180 | if ( pDocSh && pDocSh->IsDocShared() ) | |||
1181 | { | |||
1182 | rSet.DisableItem( nWhich ); | |||
1183 | } | |||
1184 | } | |||
1185 | break; | |||
1186 | ||||
1187 | case FID_DEFINE_CURRENT_NAME((((((((26000 + 200) + 20)) + 20)) + 20)) + 24): | |||
1188 | { | |||
1189 | ScAddress aCurrentAddress( nPosX, nPosY, nTab ); | |||
1190 | ||||
1191 | if ( !rDoc.IsAddressInRangeName( RangeNameScope::GLOBAL, aCurrentAddress ) && | |||
1192 | !rDoc.IsAddressInRangeName( RangeNameScope::SHEET, aCurrentAddress )) | |||
1193 | { | |||
1194 | rSet.DisableItem( nWhich ); | |||
1195 | } | |||
1196 | } | |||
1197 | break; | |||
1198 | ||||
1199 | case SID_SPELL_DIALOG( 10000 + 243 ): | |||
1200 | { | |||
1201 | if ( pData && rDoc.IsTabProtected( pData->GetTabNo() ) ) | |||
1202 | { | |||
1203 | bool bVisible = false; | |||
1204 | SfxViewFrame* pViewFrame = ( pTabViewShell ? pTabViewShell->GetViewFrame() : nullptr ); | |||
1205 | if ( pViewFrame && pViewFrame->HasChildWindow( nWhich ) ) | |||
1206 | { | |||
1207 | SfxChildWindow* pChild = pViewFrame->GetChildWindow( nWhich ); | |||
1208 | std::shared_ptr<SfxDialogController> xController = pChild ? pChild->GetController() : nullptr; | |||
1209 | if (xController && xController->getDialog()->get_visible()) | |||
1210 | { | |||
1211 | bVisible = true; | |||
1212 | } | |||
1213 | } | |||
1214 | if ( !bVisible ) | |||
1215 | { | |||
1216 | rSet.DisableItem( nWhich ); | |||
1217 | } | |||
1218 | } | |||
1219 | } | |||
1220 | break; | |||
1221 | ||||
1222 | case SID_OPENDLG_CURRENTCONDFRMT((26000 + 100) + 58): | |||
1223 | case SID_OPENDLG_CURRENTCONDFRMT_MANAGER((26000 + 100) + 64): | |||
1224 | { | |||
1225 | const SfxPoolItem* pItem = rDoc.GetAttr( nPosX, nPosY, nTab, ATTR_CONDITIONAL ); | |||
1226 | const ScCondFormatItem* pCondFormatItem = static_cast<const ScCondFormatItem*>(pItem); | |||
1227 | ||||
1228 | if ( pCondFormatItem->GetCondFormatData().empty() ) | |||
1229 | rSet.DisableItem( nWhich ); | |||
1230 | else if ( pCondFormatItem->GetCondFormatData().size() == 1 ) | |||
1231 | rSet.DisableItem( SID_OPENDLG_CURRENTCONDFRMT_MANAGER((26000 + 100) + 64) ); | |||
1232 | else if ( pCondFormatItem->GetCondFormatData().size() > 1 ) | |||
1233 | rSet.DisableItem( SID_OPENDLG_CURRENTCONDFRMT((26000 + 100) + 58) ); | |||
1234 | } | |||
1235 | break; | |||
1236 | ||||
1237 | } // switch ( nWitch ) | |||
1238 | nWhich = aIter.NextWhich(); | |||
1239 | } // while ( nWitch ) | |||
1240 | } | |||
1241 | ||||
1242 | /* 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 |