File: | home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx |
Warning: | line 793, column 15 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 <memory> | ||||
21 | #include <fielduno.hxx> | ||||
22 | #include <textuno.hxx> | ||||
23 | #include <miscuno.hxx> | ||||
24 | #include <docsh.hxx> | ||||
25 | #include <hints.hxx> | ||||
26 | #include <editsrc.hxx> | ||||
27 | #include <unonames.hxx> | ||||
28 | #include <editutil.hxx> | ||||
29 | |||||
30 | #include <svl/hint.hxx> | ||||
31 | #include <vcl/svapp.hxx> | ||||
32 | |||||
33 | #include <editeng/eeitem.hxx> | ||||
34 | |||||
35 | #include <editeng/editeng.hxx> | ||||
36 | #include <editeng/editobj.hxx> | ||||
37 | #include <editeng/flditem.hxx> | ||||
38 | #include <comphelper/sequence.hxx> | ||||
39 | #include <cppuhelper/supportsservice.hxx> | ||||
40 | |||||
41 | #include <com/sun/star/beans/PropertyAttribute.hpp> | ||||
42 | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> | ||||
43 | #include <com/sun/star/text/TextContentAnchorType.hpp> | ||||
44 | #include <com/sun/star/text/WrapTextMode.hpp> | ||||
45 | #include <com/sun/star/text/FilenameDisplayFormat.hpp> | ||||
46 | #include <com/sun/star/text/textfield/Type.hpp> | ||||
47 | |||||
48 | using namespace com::sun::star; | ||||
49 | |||||
50 | namespace { | ||||
51 | |||||
52 | // no Which-ID here, map only for PropertySetInfo | ||||
53 | |||||
54 | const SfxItemPropertySet* getDateTimePropertySet() | ||||
55 | { | ||||
56 | static const SfxItemPropertyMapEntry aMapContent[] = | ||||
57 | { | ||||
58 | { u"" SC_UNONAME_DATETIME"DateTime", 0, cppu::UnoType<util::DateTime>::get(), 0, 0 }, | ||||
59 | { u"" SC_UNONAME_ISFIXED"IsFixed", 0, cppu::UnoType<bool>::get(), 0, 0 }, | ||||
60 | { u"" SC_UNONAME_ISDATE"IsDate", 0, cppu::UnoType<bool>::get(), 0, 0 }, | ||||
61 | { u"" SC_UNONAME_NUMFMT"NumberFormat", 0, cppu::UnoType<sal_Int32>::get(), 0, 0 }, | ||||
62 | { u"", 0, css::uno::Type(), 0, 0 } | ||||
63 | }; | ||||
64 | static SfxItemPropertySet aMap(aMapContent); | ||||
65 | return &aMap; | ||||
66 | } | ||||
67 | |||||
68 | const SfxItemPropertySet* getEmptyPropertySet() | ||||
69 | { | ||||
70 | static const SfxItemPropertyMapEntry aMapContent[] = | ||||
71 | { | ||||
72 | { u"", 0, css::uno::Type(), 0, 0 } | ||||
73 | }; | ||||
74 | static SfxItemPropertySet aMap(aMapContent); | ||||
75 | return &aMap; | ||||
76 | } | ||||
77 | |||||
78 | const SfxItemPropertySet* lcl_GetURLPropertySet() | ||||
79 | { | ||||
80 | static const SfxItemPropertyMapEntry aURLPropertyMap_Impl[] = | ||||
81 | { | ||||
82 | {u"" SC_UNONAME_ANCTYPE"AnchorType", 0, cppu::UnoType<text::TextContentAnchorType>::get(), beans::PropertyAttribute::READONLY, 0 }, | ||||
83 | {u"" SC_UNONAME_ANCTYPES"AnchorTypes", 0, cppu::UnoType<uno::Sequence<text::TextContentAnchorType>>::get(), beans::PropertyAttribute::READONLY, 0 }, | ||||
84 | {u"" SC_UNONAME_REPR"Representation", 0, cppu::UnoType<OUString>::get(), 0, 0}, | ||||
85 | {u"" SC_UNONAME_TARGET"TargetFrame", 0, cppu::UnoType<OUString>::get(), 0, 0}, | ||||
86 | {u"" SC_UNONAME_TEXTWRAP"TextWrap", 0, cppu::UnoType<text::WrapTextMode>::get(), beans::PropertyAttribute::READONLY, 0 }, | ||||
87 | {u"" SC_UNONAME_URL"URL", 0, cppu::UnoType<OUString>::get(), 0, 0}, | ||||
88 | { u"", 0, css::uno::Type(), 0, 0 } | ||||
89 | }; | ||||
90 | static SfxItemPropertySet aURLPropertySet_Impl( aURLPropertyMap_Impl ); | ||||
91 | return &aURLPropertySet_Impl; | ||||
92 | } | ||||
93 | |||||
94 | const SfxItemPropertySet* lcl_GetHeaderFieldPropertySet() | ||||
95 | { | ||||
96 | static const SfxItemPropertyMapEntry aHeaderFieldPropertyMap_Impl[] = | ||||
97 | { | ||||
98 | {u"" SC_UNONAME_ANCTYPE"AnchorType", 0, cppu::UnoType<text::TextContentAnchorType>::get(), beans::PropertyAttribute::READONLY, 0 }, | ||||
99 | {u"" SC_UNONAME_ANCTYPES"AnchorTypes", 0, cppu::UnoType<uno::Sequence<text::TextContentAnchorType>>::get(), beans::PropertyAttribute::READONLY, 0 }, | ||||
100 | {u"" SC_UNONAME_TEXTWRAP"TextWrap", 0, cppu::UnoType<text::WrapTextMode>::get(), beans::PropertyAttribute::READONLY, 0 }, | ||||
101 | { u"", 0, css::uno::Type(), 0, 0 } | ||||
102 | }; | ||||
103 | static SfxItemPropertySet aHeaderFieldPropertySet_Impl( aHeaderFieldPropertyMap_Impl ); | ||||
104 | return &aHeaderFieldPropertySet_Impl; | ||||
105 | } | ||||
106 | |||||
107 | const SfxItemPropertySet* lcl_GetFileFieldPropertySet() | ||||
108 | { | ||||
109 | static const SfxItemPropertyMapEntry aFileFieldPropertyMap_Impl[] = | ||||
110 | { | ||||
111 | {u"" SC_UNONAME_ANCTYPE"AnchorType", 0, cppu::UnoType<text::TextContentAnchorType>::get(), beans::PropertyAttribute::READONLY, 0 }, | ||||
112 | {u"" SC_UNONAME_ANCTYPES"AnchorTypes", 0, cppu::UnoType<uno::Sequence<text::TextContentAnchorType>>::get(), beans::PropertyAttribute::READONLY, 0 }, | ||||
113 | {u"" SC_UNONAME_FILEFORM"FileFormat", 0, cppu::UnoType<sal_Int16>::get(), 0, 0 }, | ||||
114 | {u"" SC_UNONAME_TEXTWRAP"TextWrap", 0, cppu::UnoType<text::WrapTextMode>::get(), beans::PropertyAttribute::READONLY, 0 }, | ||||
115 | { u"", 0, css::uno::Type(), 0, 0 } | ||||
116 | }; | ||||
117 | static SfxItemPropertySet aFileFieldPropertySet_Impl( aFileFieldPropertyMap_Impl ); | ||||
118 | return &aFileFieldPropertySet_Impl; | ||||
119 | } | ||||
120 | |||||
121 | SvxFileFormat lcl_UnoToSvxFileFormat( sal_Int16 nUnoValue ) | ||||
122 | { | ||||
123 | switch( nUnoValue ) | ||||
124 | { | ||||
125 | case text::FilenameDisplayFormat::FULL: return SvxFileFormat::PathFull; | ||||
126 | case text::FilenameDisplayFormat::PATH: return SvxFileFormat::PathOnly; | ||||
127 | case text::FilenameDisplayFormat::NAME: return SvxFileFormat::NameOnly; | ||||
128 | default: | ||||
129 | return SvxFileFormat::NameAndExt; | ||||
130 | } | ||||
131 | } | ||||
132 | |||||
133 | sal_Int16 lcl_SvxToUnoFileFormat( SvxFileFormat nSvxValue ) | ||||
134 | { | ||||
135 | switch( nSvxValue ) | ||||
136 | { | ||||
137 | case SvxFileFormat::NameAndExt: return text::FilenameDisplayFormat::NAME_AND_EXT; | ||||
138 | case SvxFileFormat::PathFull: return text::FilenameDisplayFormat::FULL; | ||||
139 | case SvxFileFormat::PathOnly: return text::FilenameDisplayFormat::PATH; | ||||
140 | default: | ||||
141 | return text::FilenameDisplayFormat::NAME; | ||||
142 | } | ||||
143 | } | ||||
144 | |||||
145 | } | ||||
146 | |||||
147 | SC_SIMPLE_SERVICE_INFO( ScCellFieldsObj, "ScCellFieldsObj", "com.sun.star.text.TextFields" )OUString ScCellFieldsObj::getImplementationName() { return "ScCellFieldsObj" ; } sal_Bool ScCellFieldsObj::supportsService( const OUString & ServiceName ) { return cppu::supportsService(this, ServiceName ); } css::uno::Sequence< OUString > ScCellFieldsObj::getSupportedServiceNames () { css::uno::Sequence< OUString > aRet { "com.sun.star.text.TextFields" }; return aRet; } | ||||
148 | SC_SIMPLE_SERVICE_INFO( ScHeaderFieldsObj, "ScHeaderFieldsObj", "com.sun.star.text.TextFields" )OUString ScHeaderFieldsObj::getImplementationName() { return "ScHeaderFieldsObj" ; } sal_Bool ScHeaderFieldsObj::supportsService( const OUString & ServiceName ) { return cppu::supportsService(this, ServiceName ); } css::uno::Sequence< OUString > ScHeaderFieldsObj:: getSupportedServiceNames() { css::uno::Sequence< OUString > aRet { "com.sun.star.text.TextFields" }; return aRet; } | ||||
149 | |||||
150 | namespace { | ||||
151 | |||||
152 | enum ScUnoCollectMode | ||||
153 | { | ||||
154 | SC_UNO_COLLECT_NONE, | ||||
155 | SC_UNO_COLLECT_COUNT, | ||||
156 | SC_UNO_COLLECT_FINDINDEX, | ||||
157 | SC_UNO_COLLECT_FINDPOS | ||||
158 | }; | ||||
159 | |||||
160 | /** | ||||
161 | * This class exists solely to allow searching through field items. TODO: | ||||
162 | * Look into providing the same functionality directly in EditEngine, to | ||||
163 | * avoid having this class altogether. | ||||
164 | */ | ||||
165 | class ScUnoEditEngine : public ScEditEngineDefaulter | ||||
166 | { | ||||
167 | ScUnoCollectMode eMode; | ||||
168 | sal_uInt16 nFieldCount; | ||||
169 | sal_Int32 mnFieldType; | ||||
170 | std::unique_ptr<SvxFieldData> | ||||
171 | pFound; // local copy | ||||
172 | sal_Int32 nFieldPar; | ||||
173 | sal_Int32 nFieldPos; | ||||
174 | sal_uInt16 nFieldIndex; | ||||
175 | |||||
176 | public: | ||||
177 | explicit ScUnoEditEngine(ScEditEngineDefaulter* pSource); | ||||
178 | |||||
179 | virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, | ||||
180 | std::optional<Color>& rTxtColor, std::optional<Color>& rFldColor ) override; | ||||
181 | |||||
182 | sal_uInt16 CountFields(); | ||||
183 | SvxFieldData* FindByIndex(sal_uInt16 nIndex); | ||||
184 | SvxFieldData* FindByPos(sal_Int32 nPar, sal_Int32 nPos, sal_Int32 nType); | ||||
185 | |||||
186 | sal_Int32 GetFieldPar() const { return nFieldPar; } | ||||
187 | sal_Int32 GetFieldPos() const { return nFieldPos; } | ||||
188 | }; | ||||
189 | |||||
190 | } | ||||
191 | |||||
192 | ScUnoEditEngine::ScUnoEditEngine(ScEditEngineDefaulter* pSource) | ||||
193 | : ScEditEngineDefaulter(*pSource) | ||||
194 | , eMode(SC_UNO_COLLECT_NONE) | ||||
195 | , nFieldCount(0) | ||||
196 | , mnFieldType(text::textfield::Type::UNSPECIFIED) | ||||
197 | , nFieldPar(0) | ||||
198 | , nFieldPos(0) | ||||
199 | , nFieldIndex(0) | ||||
200 | { | ||||
201 | std::unique_ptr<EditTextObject> pData = pSource->CreateTextObject(); | ||||
202 | SetTextCurrentDefaults( *pData ); | ||||
203 | } | ||||
204 | |||||
205 | OUString ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField, | ||||
206 | sal_Int32 nPara, sal_Int32 nPos, std::optional<Color>& rTxtColor, std::optional<Color>& rFldColor ) | ||||
207 | { | ||||
208 | OUString aRet(EditEngine::CalcFieldValue( rField, nPara, nPos, rTxtColor, rFldColor )); | ||||
209 | if (eMode != SC_UNO_COLLECT_NONE) | ||||
210 | { | ||||
211 | const SvxFieldData* pFieldData = rField.GetField(); | ||||
212 | if ( pFieldData ) | ||||
213 | { | ||||
214 | if (mnFieldType == text::textfield::Type::UNSPECIFIED || pFieldData->GetClassId() == mnFieldType) | ||||
215 | { | ||||
216 | if ( eMode == SC_UNO_COLLECT_FINDINDEX && !pFound && nFieldCount == nFieldIndex ) | ||||
217 | { | ||||
218 | pFound = pFieldData->Clone(); | ||||
219 | nFieldPar = nPara; | ||||
220 | nFieldPos = nPos; | ||||
221 | } | ||||
222 | if ( eMode == SC_UNO_COLLECT_FINDPOS && !pFound && | ||||
223 | nPara == nFieldPar && nPos == nFieldPos ) | ||||
224 | { | ||||
225 | pFound = pFieldData->Clone(); | ||||
226 | nFieldIndex = nFieldCount; | ||||
227 | } | ||||
228 | ++nFieldCount; | ||||
229 | } | ||||
230 | } | ||||
231 | } | ||||
232 | return aRet; | ||||
233 | } | ||||
234 | |||||
235 | sal_uInt16 ScUnoEditEngine::CountFields() | ||||
236 | { | ||||
237 | eMode = SC_UNO_COLLECT_COUNT; | ||||
238 | mnFieldType = text::textfield::Type::UNSPECIFIED; | ||||
239 | nFieldCount = 0; | ||||
240 | UpdateFields(); | ||||
241 | eMode = SC_UNO_COLLECT_NONE; | ||||
242 | |||||
243 | return nFieldCount; | ||||
244 | } | ||||
245 | |||||
246 | SvxFieldData* ScUnoEditEngine::FindByIndex(sal_uInt16 nIndex) | ||||
247 | { | ||||
248 | eMode = SC_UNO_COLLECT_FINDINDEX; | ||||
249 | nFieldIndex = nIndex; | ||||
250 | mnFieldType = text::textfield::Type::UNSPECIFIED; | ||||
251 | nFieldCount = 0; | ||||
252 | UpdateFields(); | ||||
253 | eMode = SC_UNO_COLLECT_NONE; | ||||
254 | |||||
255 | return pFound.get(); | ||||
256 | } | ||||
257 | |||||
258 | SvxFieldData* ScUnoEditEngine::FindByPos(sal_Int32 nPar, sal_Int32 nPos, sal_Int32 nType) | ||||
259 | { | ||||
260 | eMode = SC_UNO_COLLECT_FINDPOS; | ||||
261 | nFieldPar = nPar; | ||||
262 | nFieldPos = nPos; | ||||
263 | mnFieldType = nType; | ||||
264 | nFieldCount = 0; | ||||
265 | UpdateFields(); | ||||
266 | mnFieldType = text::textfield::Type::UNSPECIFIED; | ||||
267 | eMode = SC_UNO_COLLECT_NONE; | ||||
268 | |||||
269 | return pFound.get(); | ||||
270 | } | ||||
271 | |||||
272 | ScCellFieldsObj::ScCellFieldsObj( | ||||
273 | const uno::Reference<text::XTextRange>& xContent, | ||||
274 | ScDocShell* pDocSh, const ScAddress& rPos) : | ||||
275 | mxContent(xContent), | ||||
276 | pDocShell( pDocSh ), | ||||
277 | aCellPos( rPos ) | ||||
278 | { | ||||
279 | pDocShell->GetDocument().AddUnoObject(*this); | ||||
280 | |||||
281 | mpEditSource.reset( new ScCellEditSource( pDocShell, aCellPos ) ); | ||||
282 | } | ||||
283 | |||||
284 | ScCellFieldsObj::~ScCellFieldsObj() | ||||
285 | { | ||||
286 | SolarMutexGuard g; | ||||
287 | |||||
288 | if (pDocShell) | ||||
289 | pDocShell->GetDocument().RemoveUnoObject(*this); | ||||
290 | |||||
291 | mpEditSource.reset(); | ||||
292 | |||||
293 | // increment refcount to prevent double call off dtor | ||||
294 | osl_atomic_increment( &m_refCount )__sync_add_and_fetch((&m_refCount), 1); | ||||
295 | |||||
296 | if (mpRefreshListeners) | ||||
297 | { | ||||
298 | lang::EventObject aEvent; | ||||
299 | aEvent.Source.set(static_cast<cppu::OWeakObject*>(this)); | ||||
300 | mpRefreshListeners->disposeAndClear(aEvent); | ||||
301 | mpRefreshListeners.reset(); | ||||
302 | } | ||||
303 | } | ||||
304 | |||||
305 | void ScCellFieldsObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) | ||||
306 | { | ||||
307 | if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) ) | ||||
308 | { | ||||
309 | //! update of references | ||||
310 | } | ||||
311 | else if ( rHint.GetId() == SfxHintId::Dying ) | ||||
312 | { | ||||
313 | pDocShell = nullptr; // became invalid | ||||
314 | } | ||||
315 | |||||
316 | // EditSource registered itself as a listener | ||||
317 | } | ||||
318 | |||||
319 | // XIndexAccess (via XTextFields) | ||||
320 | |||||
321 | uno::Reference<text::XTextField> ScCellFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const | ||||
322 | { | ||||
323 | //! Field functions have to be passed to the forwarder !!! | ||||
324 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
325 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
326 | SvxFieldData* pData = aTempEngine.FindByIndex(static_cast<sal_uInt16>(Index)); | ||||
327 | if (!pData) | ||||
328 | return uno::Reference<text::XTextField>(); | ||||
329 | |||||
330 | sal_Int32 nPar = aTempEngine.GetFieldPar(); | ||||
331 | sal_Int32 nPos = aTempEngine.GetFieldPos(); | ||||
332 | ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Field size is 1 character | ||||
333 | |||||
334 | sal_Int32 eType = pData->GetClassId(); | ||||
335 | uno::Reference<text::XTextField> xRet( | ||||
336 | new ScEditFieldObj(mxContent, std::make_unique<ScCellEditSource>(pDocShell, aCellPos), eType, aSelection)); | ||||
337 | return xRet; | ||||
338 | } | ||||
339 | |||||
340 | sal_Int32 SAL_CALL ScCellFieldsObj::getCount() | ||||
341 | { | ||||
342 | SolarMutexGuard aGuard; | ||||
343 | |||||
344 | //! Field functions have to be passed to the forwarder !!! | ||||
345 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
346 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
347 | |||||
348 | return aTempEngine.CountFields(); // count the fields, we don't care about their type in the cell | ||||
349 | } | ||||
350 | |||||
351 | uno::Any SAL_CALL ScCellFieldsObj::getByIndex( sal_Int32 nIndex ) | ||||
352 | { | ||||
353 | SolarMutexGuard aGuard; | ||||
354 | uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex)); | ||||
355 | if (!xField.is()) | ||||
356 | throw lang::IndexOutOfBoundsException(); | ||||
357 | |||||
358 | return uno::makeAny(xField); | ||||
359 | } | ||||
360 | |||||
361 | uno::Type SAL_CALL ScCellFieldsObj::getElementType() | ||||
362 | { | ||||
363 | SolarMutexGuard aGuard; | ||||
364 | return cppu::UnoType<text::XTextField>::get(); | ||||
365 | } | ||||
366 | |||||
367 | sal_Bool SAL_CALL ScCellFieldsObj::hasElements() | ||||
368 | { | ||||
369 | SolarMutexGuard aGuard; | ||||
370 | return ( getCount() != 0 ); | ||||
371 | } | ||||
372 | |||||
373 | uno::Reference<container::XEnumeration> SAL_CALL ScCellFieldsObj::createEnumeration() | ||||
374 | { | ||||
375 | SolarMutexGuard aGuard; | ||||
376 | return new ScIndexEnumeration(this, "com.sun.star.text.TextFieldEnumeration"); | ||||
377 | } | ||||
378 | |||||
379 | void SAL_CALL ScCellFieldsObj::addContainerListener( | ||||
380 | const uno::Reference<container::XContainerListener>& /* xListener */ ) | ||||
381 | { | ||||
382 | OSL_FAIL("not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "382" ": "), "%s", "not implemented"); } } while (false); | ||||
383 | } | ||||
384 | |||||
385 | void SAL_CALL ScCellFieldsObj::removeContainerListener( | ||||
386 | const uno::Reference<container::XContainerListener>& /* xListener */ ) | ||||
387 | { | ||||
388 | OSL_FAIL("not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "388" ": "), "%s", "not implemented"); } } while (false); | ||||
389 | } | ||||
390 | |||||
391 | // XRefreshable | ||||
392 | void SAL_CALL ScCellFieldsObj::refresh( ) | ||||
393 | { | ||||
394 | if (mpRefreshListeners) | ||||
395 | { | ||||
396 | // Call all listeners. | ||||
397 | lang::EventObject aEvent; | ||||
398 | aEvent.Source.set(uno::Reference< util::XRefreshable >(this)); | ||||
399 | mpRefreshListeners->notifyEach( &util::XRefreshListener::refreshed, aEvent ); | ||||
400 | } | ||||
401 | } | ||||
402 | |||||
403 | void SAL_CALL ScCellFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener ) | ||||
404 | { | ||||
405 | if (xListener.is()) | ||||
406 | { | ||||
407 | SolarMutexGuard aGuard; | ||||
408 | if (!mpRefreshListeners) | ||||
409 | mpRefreshListeners.reset( new comphelper::OInterfaceContainerHelper2(aMutex) ); | ||||
410 | mpRefreshListeners->addInterface(xListener); | ||||
411 | } | ||||
412 | } | ||||
413 | |||||
414 | void SAL_CALL ScCellFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener ) | ||||
415 | { | ||||
416 | if (xListener.is()) | ||||
417 | { | ||||
418 | SolarMutexGuard aGuard; | ||||
419 | if (mpRefreshListeners) | ||||
420 | mpRefreshListeners->removeInterface(xListener); | ||||
421 | } | ||||
422 | } | ||||
423 | |||||
424 | ScHeaderFieldsObj::ScHeaderFieldsObj(ScHeaderFooterTextData& rData) : | ||||
425 | mrData(rData) | ||||
426 | { | ||||
427 | mpEditSource.reset( new ScHeaderFooterEditSource(rData) ); | ||||
428 | } | ||||
429 | |||||
430 | ScHeaderFieldsObj::~ScHeaderFieldsObj() | ||||
431 | { | ||||
432 | mpEditSource.reset(); | ||||
433 | |||||
434 | // increment refcount to prevent double call off dtor | ||||
435 | osl_atomic_increment( &m_refCount )__sync_add_and_fetch((&m_refCount), 1); | ||||
436 | |||||
437 | if (mpRefreshListeners) | ||||
438 | { | ||||
439 | lang::EventObject aEvent; | ||||
440 | aEvent.Source = static_cast<cppu::OWeakObject*>(this); | ||||
441 | mpRefreshListeners->disposeAndClear(aEvent); | ||||
442 | mpRefreshListeners.reset(); | ||||
443 | } | ||||
444 | } | ||||
445 | |||||
446 | // XIndexAccess (via XTextFields) | ||||
447 | |||||
448 | uno::Reference<text::XTextField> ScHeaderFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const | ||||
449 | { | ||||
450 | //! Field functions have to be passed to the forwarder !!! | ||||
451 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
452 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
453 | |||||
454 | SvxFieldData* pData = aTempEngine.FindByIndex(static_cast<sal_uInt16>(Index)); | ||||
455 | if (!pData) | ||||
456 | return nullptr; | ||||
457 | |||||
458 | // Get the parent text range instance. | ||||
459 | uno::Reference<text::XTextRange> xTextRange; | ||||
460 | uno::Reference<sheet::XHeaderFooterContent> xContentObj = mrData.GetContentObj(); | ||||
461 | if (!xContentObj.is()) | ||||
462 | throw uno::RuntimeException(""); | ||||
463 | |||||
464 | rtl::Reference<ScHeaderFooterContentObj> pContentObj = ScHeaderFooterContentObj::getImplementation(xContentObj); | ||||
465 | uno::Reference<text::XText> xText; | ||||
466 | |||||
467 | switch ( mrData.GetPart() ) | ||||
468 | { | ||||
469 | case ScHeaderFooterPart::LEFT: | ||||
470 | xText = pContentObj->getLeftText(); | ||||
471 | break; | ||||
472 | case ScHeaderFooterPart::CENTER: | ||||
473 | xText = pContentObj->getCenterText(); | ||||
474 | break; | ||||
475 | case ScHeaderFooterPart::RIGHT: | ||||
476 | xText = pContentObj->getRightText(); | ||||
477 | break; | ||||
478 | } | ||||
479 | |||||
480 | xTextRange = xText; | ||||
481 | |||||
482 | sal_Int32 nPar = aTempEngine.GetFieldPar(); | ||||
483 | sal_Int32 nPos = aTempEngine.GetFieldPos(); | ||||
484 | ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Field size is 1 character | ||||
485 | |||||
486 | sal_Int32 eRealType = pData->GetClassId(); | ||||
487 | uno::Reference<text::XTextField> xRet( | ||||
488 | new ScEditFieldObj(xTextRange, std::make_unique<ScHeaderFooterEditSource>(mrData), eRealType, aSelection)); | ||||
489 | return xRet; | ||||
490 | } | ||||
491 | |||||
492 | sal_Int32 SAL_CALL ScHeaderFieldsObj::getCount() | ||||
493 | { | ||||
494 | SolarMutexGuard aGuard; | ||||
495 | |||||
496 | //! Field functions have to be passed to the forwarder !!! | ||||
497 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
498 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
499 | return aTempEngine.CountFields(); | ||||
500 | } | ||||
501 | |||||
502 | uno::Any SAL_CALL ScHeaderFieldsObj::getByIndex( sal_Int32 nIndex ) | ||||
503 | { | ||||
504 | SolarMutexGuard aGuard; | ||||
505 | uno::Reference<text::XTextField> xField(GetObjectByIndex_Impl(nIndex)); | ||||
506 | if (!xField.is()) | ||||
507 | throw lang::IndexOutOfBoundsException(); | ||||
508 | |||||
509 | return uno::makeAny(xField); | ||||
510 | } | ||||
511 | |||||
512 | uno::Type SAL_CALL ScHeaderFieldsObj::getElementType() | ||||
513 | { | ||||
514 | SolarMutexGuard aGuard; | ||||
515 | return cppu::UnoType<text::XTextField>::get(); | ||||
516 | } | ||||
517 | |||||
518 | sal_Bool SAL_CALL ScHeaderFieldsObj::hasElements() | ||||
519 | { | ||||
520 | SolarMutexGuard aGuard; | ||||
521 | return ( getCount() != 0 ); | ||||
522 | } | ||||
523 | |||||
524 | uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFieldsObj::createEnumeration() | ||||
525 | { | ||||
526 | SolarMutexGuard aGuard; | ||||
527 | return new ScIndexEnumeration(this, "com.sun.star.text.TextFieldEnumeration"); | ||||
528 | } | ||||
529 | |||||
530 | void SAL_CALL ScHeaderFieldsObj::addContainerListener( | ||||
531 | const uno::Reference<container::XContainerListener>& /* xListener */ ) | ||||
532 | { | ||||
533 | OSL_FAIL("not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "533" ": "), "%s", "not implemented"); } } while (false); | ||||
534 | } | ||||
535 | |||||
536 | void SAL_CALL ScHeaderFieldsObj::removeContainerListener( | ||||
537 | const uno::Reference<container::XContainerListener>& /* xListener */ ) | ||||
538 | { | ||||
539 | OSL_FAIL("not implemented")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "539" ": "), "%s", "not implemented"); } } while (false); | ||||
540 | } | ||||
541 | |||||
542 | // XRefreshable | ||||
543 | void SAL_CALL ScHeaderFieldsObj::refresh( ) | ||||
544 | { | ||||
545 | if (mpRefreshListeners) | ||||
546 | { | ||||
547 | // Call all listeners. | ||||
548 | lang::EventObject aEvent; | ||||
549 | aEvent.Source.set(uno::Reference< util::XRefreshable >(this)); | ||||
550 | mpRefreshListeners->notifyEach( &util::XRefreshListener::refreshed, aEvent); | ||||
551 | } | ||||
552 | } | ||||
553 | |||||
554 | void SAL_CALL ScHeaderFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener ) | ||||
555 | { | ||||
556 | if (xListener.is()) | ||||
557 | { | ||||
558 | SolarMutexGuard aGuard; | ||||
559 | if (!mpRefreshListeners) | ||||
560 | mpRefreshListeners.reset(new comphelper::OInterfaceContainerHelper2(aMutex)); | ||||
561 | mpRefreshListeners->addInterface(xListener); | ||||
562 | } | ||||
563 | } | ||||
564 | |||||
565 | void SAL_CALL ScHeaderFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener ) | ||||
566 | { | ||||
567 | if (xListener.is()) | ||||
568 | { | ||||
569 | SolarMutexGuard aGuard; | ||||
570 | if (mpRefreshListeners) | ||||
571 | mpRefreshListeners->removeInterface(xListener); | ||||
572 | } | ||||
573 | } | ||||
574 | |||||
575 | SvxFieldData& ScEditFieldObj::getData() | ||||
576 | { | ||||
577 | if (!mpData) | ||||
578 | { | ||||
579 | switch (meType) | ||||
580 | { | ||||
581 | case text::textfield::Type::DATE: | ||||
582 | mpData.reset(new SvxDateField); | ||||
583 | break; | ||||
584 | case text::textfield::Type::EXTENDED_FILE: | ||||
585 | mpData.reset( | ||||
586 | new SvxExtFileField(OUString(), SvxFileType::Var, SvxFileFormat::NameAndExt)); | ||||
587 | break; | ||||
588 | case text::textfield::Type::PAGE: | ||||
589 | mpData.reset(new SvxPageField); | ||||
590 | break; | ||||
591 | case text::textfield::Type::PAGES: | ||||
592 | mpData.reset(new SvxPagesField); | ||||
593 | break; | ||||
594 | case text::textfield::Type::TABLE: | ||||
595 | mpData.reset(new SvxTableField); | ||||
596 | break; | ||||
597 | case text::textfield::Type::TIME: | ||||
598 | mpData.reset(new SvxTimeField); | ||||
599 | break; | ||||
600 | case text::textfield::Type::EXTENDED_TIME: | ||||
601 | { | ||||
602 | if (mbIsDate) | ||||
603 | mpData.reset(new SvxDateField); | ||||
604 | else | ||||
605 | mpData.reset(new SvxExtTimeField); | ||||
606 | } | ||||
607 | break; | ||||
608 | case text::textfield::Type::DOCINFO_TITLE: | ||||
609 | mpData.reset(new SvxFileField); | ||||
610 | break; | ||||
611 | case text::textfield::Type::URL: | ||||
612 | mpData.reset( | ||||
613 | new SvxURLField(OUString(), OUString(), SvxURLFormat::AppDefault)); | ||||
614 | break; | ||||
615 | default: | ||||
616 | mpData.reset(new SvxFieldData); | ||||
617 | } | ||||
618 | } | ||||
619 | return *mpData; | ||||
620 | } | ||||
621 | |||||
622 | void ScEditFieldObj::setPropertyValueURL(const OUString& rName, const css::uno::Any& rVal) | ||||
623 | { | ||||
624 | OUString aStrVal; | ||||
625 | if (mpEditSource) | ||||
626 | { | ||||
627 | // Edit engine instance already exists for this field item. Use it. | ||||
628 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
629 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
630 | |||||
631 | // don't care about the type (only URLs can be found in the cells) | ||||
632 | SvxFieldData* pField = aTempEngine.FindByPos( | ||||
633 | aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::UNSPECIFIED); | ||||
634 | OSL_ENSURE(pField,"setPropertyValue: Field not found")do { if (true && (!(pField))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "634" ": "), "%s", "setPropertyValue: Field not found"); } } while (false); | ||||
635 | if (!pField) | ||||
636 | return; | ||||
637 | |||||
638 | if (pField->GetClassId() != text::textfield::Type::URL) | ||||
639 | // Make sure this is indeed a URL field. | ||||
640 | return; | ||||
641 | |||||
642 | SvxURLField* pURL = static_cast<SvxURLField*>(pField); | ||||
643 | |||||
644 | if (rName == SC_UNONAME_URL"URL") | ||||
645 | { | ||||
646 | if (rVal >>= aStrVal) | ||||
647 | pURL->SetURL(aStrVal); | ||||
648 | } | ||||
649 | else if (rName == SC_UNONAME_REPR"Representation") | ||||
650 | { | ||||
651 | if (rVal >>= aStrVal) | ||||
652 | pURL->SetRepresentation(aStrVal); | ||||
653 | } | ||||
654 | else if (rName == SC_UNONAME_TARGET"TargetFrame") | ||||
655 | { | ||||
656 | if (rVal >>= aStrVal) | ||||
657 | pURL->SetTargetFrame(aStrVal); | ||||
658 | } | ||||
659 | else | ||||
660 | throw beans::UnknownPropertyException(rName); | ||||
661 | |||||
662 | pEditEngine->QuickInsertField( SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection ); | ||||
663 | mpEditSource->UpdateData(); | ||||
664 | return; | ||||
665 | } | ||||
666 | |||||
667 | // Edit engine instance not yet present. Store the item data for later use. | ||||
668 | SvxURLField& rData = static_cast<SvxURLField&>(getData()); | ||||
669 | if (rName == SC_UNONAME_URL"URL") | ||||
670 | { | ||||
671 | if (rVal >>= aStrVal) | ||||
672 | rData.SetURL(aStrVal); | ||||
673 | } | ||||
674 | else if (rName == SC_UNONAME_REPR"Representation") | ||||
675 | { | ||||
676 | if (rVal >>= aStrVal) | ||||
677 | rData.SetRepresentation(aStrVal); | ||||
678 | } | ||||
679 | else if (rName == SC_UNONAME_TARGET"TargetFrame") | ||||
680 | { | ||||
681 | if (rVal >>= aStrVal) | ||||
682 | rData.SetTargetFrame(aStrVal); | ||||
683 | } | ||||
684 | else | ||||
685 | throw beans::UnknownPropertyException(rName); | ||||
686 | } | ||||
687 | |||||
688 | uno::Any ScEditFieldObj::getPropertyValueURL(const OUString& rName) | ||||
689 | { | ||||
690 | uno::Any aRet; | ||||
691 | |||||
692 | // anchor type is always "as character", text wrap always "none" | ||||
693 | |||||
694 | if (mpEditSource) | ||||
695 | { | ||||
696 | //! Field functions have to be passed to the forwarder !!! | ||||
697 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
698 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
699 | |||||
700 | // don't care about the type (only URLs can be found in the cells) | ||||
701 | const SvxFieldData* pField = aTempEngine.FindByPos( | ||||
702 | aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::UNSPECIFIED); | ||||
703 | OSL_ENSURE(pField,"getPropertyValue: Field not found")do { if (true && (!(pField))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "703" ": "), "%s", "getPropertyValue: Field not found"); } } while (false); | ||||
704 | if (!pField) | ||||
705 | throw uno::RuntimeException(); | ||||
706 | |||||
707 | if (pField->GetClassId() != text::textfield::Type::URL) | ||||
708 | throw uno::RuntimeException(); | ||||
709 | |||||
710 | const SvxURLField* pURL = static_cast<const SvxURLField*>(pField); | ||||
711 | |||||
712 | if (rName == SC_UNONAME_URL"URL") | ||||
713 | aRet <<= pURL->GetURL(); | ||||
714 | else if (rName == SC_UNONAME_REPR"Representation") | ||||
715 | aRet <<= pURL->GetRepresentation(); | ||||
716 | else if (rName == SC_UNONAME_TARGET"TargetFrame") | ||||
717 | aRet <<= pURL->GetTargetFrame(); | ||||
718 | else | ||||
719 | throw beans::UnknownPropertyException(rName); | ||||
720 | } | ||||
721 | else // not inserted yet | ||||
722 | { | ||||
723 | const SvxURLField& rURL = static_cast<const SvxURLField&>(getData()); | ||||
724 | |||||
725 | if (rName == SC_UNONAME_URL"URL") | ||||
726 | aRet <<= rURL.GetURL(); | ||||
727 | else if (rName == SC_UNONAME_REPR"Representation") | ||||
728 | aRet <<= rURL.GetRepresentation(); | ||||
729 | else if (rName == SC_UNONAME_TARGET"TargetFrame") | ||||
730 | aRet <<= rURL.GetTargetFrame(); | ||||
731 | else | ||||
732 | throw beans::UnknownPropertyException(rName); | ||||
733 | } | ||||
734 | return aRet; | ||||
735 | } | ||||
736 | |||||
737 | void ScEditFieldObj::setPropertyValueFile(const OUString& rName, const uno::Any& rVal) | ||||
738 | { | ||||
739 | if (rName != SC_UNONAME_FILEFORM"FileFormat") | ||||
740 | throw beans::UnknownPropertyException(rName); | ||||
741 | |||||
742 | sal_Int16 nIntVal = 0; | ||||
743 | if (!(rVal >>= nIntVal)) | ||||
744 | return; | ||||
745 | |||||
746 | SvxFileFormat eFormat = lcl_UnoToSvxFileFormat(nIntVal); | ||||
747 | if (mpEditSource) | ||||
748 | { | ||||
749 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
750 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
751 | SvxFieldData* pField = aTempEngine.FindByPos( | ||||
752 | aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::EXTENDED_FILE); | ||||
753 | OSL_ENSURE(pField, "setPropertyValueFile: Field not found")do { if (true && (!(pField))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "753" ": "), "%s", "setPropertyValueFile: Field not found" ); } } while (false); | ||||
754 | if (pField) | ||||
755 | { | ||||
756 | SvxExtFileField* pExtFile = static_cast<SvxExtFileField*>(pField); // local to the ScUnoEditEngine | ||||
757 | pExtFile->SetFormat(eFormat); | ||||
758 | pEditEngine->QuickInsertField(SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection); | ||||
759 | mpEditSource->UpdateData(); | ||||
760 | } | ||||
761 | } | ||||
762 | else | ||||
763 | { | ||||
764 | SvxExtFileField& rExtFile = static_cast<SvxExtFileField&>(getData()); | ||||
765 | rExtFile.SetFormat(eFormat); | ||||
766 | } | ||||
767 | |||||
768 | } | ||||
769 | |||||
770 | uno::Any ScEditFieldObj::getPropertyValueFile(const OUString& rName) | ||||
771 | { | ||||
772 | uno::Any aRet; | ||||
773 | if (rName != SC_UNONAME_FILEFORM"FileFormat") | ||||
774 | throw beans::UnknownPropertyException(rName); | ||||
775 | |||||
776 | SvxFileFormat eFormat = SvxFileFormat::NameAndExt; | ||||
777 | const SvxFieldData* pField = nullptr; | ||||
778 | if (mpEditSource) | ||||
779 | { | ||||
780 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
781 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
782 | pField = aTempEngine.FindByPos( | ||||
783 | aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::EXTENDED_FILE); | ||||
784 | } | ||||
785 | else | ||||
786 | pField = &getData(); | ||||
787 | |||||
788 | OSL_ENSURE(pField, "setPropertyValueFile: Field not found")do { if (true && (!(pField))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "788" ": "), "%s", "setPropertyValueFile: Field not found" ); } } while (false); | ||||
789 | if (!pField
| ||||
790 | throw uno::RuntimeException(); | ||||
791 | |||||
792 | const SvxExtFileField* pExtFile = static_cast<const SvxExtFileField*>(pField); | ||||
793 | eFormat = pExtFile->GetFormat(); | ||||
| |||||
794 | sal_Int16 nIntVal = lcl_SvxToUnoFileFormat(eFormat); | ||||
795 | aRet <<= nIntVal; | ||||
796 | |||||
797 | return aRet; | ||||
798 | } | ||||
799 | |||||
800 | void ScEditFieldObj::setPropertyValueDateTime(const OUString& rName, const uno::Any& rVal) | ||||
801 | { | ||||
802 | if (mpEditSource) | ||||
803 | { | ||||
804 | // Field already inserted. | ||||
805 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
806 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
807 | SvxFieldData* pField = aTempEngine.FindByPos(aSelection.nStartPara, aSelection.nStartPos, meType); | ||||
808 | if (!pField) | ||||
809 | return; | ||||
810 | |||||
811 | switch (meType) | ||||
812 | { | ||||
813 | case text::textfield::Type::DATE: | ||||
814 | { | ||||
815 | SvxDateField* p = static_cast<SvxDateField*>(pField); | ||||
816 | if (rName == SC_UNONAME_ISDATE"IsDate") | ||||
817 | { | ||||
818 | // Do nothing for now. | ||||
819 | } | ||||
820 | else if (rName == SC_UNONAME_ISFIXED"IsFixed") | ||||
821 | { | ||||
822 | SvxDateType eType = rVal.get<bool>() ? SvxDateType::Fix : SvxDateType::Var; | ||||
823 | p->SetType(eType); | ||||
824 | } | ||||
825 | else if (rName == SC_UNONAME_DATETIME"DateTime") | ||||
826 | { | ||||
827 | maDateTime = rVal.get<util::DateTime>(); | ||||
828 | Date aDate(maDateTime.Day, maDateTime.Month, maDateTime.Year); | ||||
829 | p->SetFixDate(aDate); | ||||
830 | } | ||||
831 | else if (rName == SC_UNONAME_NUMFMT"NumberFormat") | ||||
832 | { | ||||
833 | mnNumFormat = rVal.get<sal_Int32>(); | ||||
834 | p->SetFormat(static_cast<SvxDateFormat>(mnNumFormat)); | ||||
835 | } | ||||
836 | else | ||||
837 | throw beans::UnknownPropertyException(rName); | ||||
838 | } | ||||
839 | break; | ||||
840 | case text::textfield::Type::TIME: | ||||
841 | { | ||||
842 | // SvxTimeField doesn't have any attributes. | ||||
843 | if (rName != SC_UNONAME_ISDATE"IsDate" && rName != SC_UNONAME_ISFIXED"IsFixed" && | ||||
844 | rName != SC_UNONAME_DATETIME"DateTime" && rName != SC_UNONAME_NUMFMT"NumberFormat") | ||||
845 | throw beans::UnknownPropertyException(rName); | ||||
846 | } | ||||
847 | break; | ||||
848 | case text::textfield::Type::EXTENDED_TIME: | ||||
849 | { | ||||
850 | SvxExtTimeField* p = static_cast<SvxExtTimeField*>(pField); | ||||
851 | if (rName == SC_UNONAME_ISDATE"IsDate") | ||||
852 | { | ||||
853 | // Do nothing for now. | ||||
854 | } | ||||
855 | else if (rName == SC_UNONAME_ISFIXED"IsFixed") | ||||
856 | { | ||||
857 | SvxTimeType eType = rVal.get<bool>() ? SvxTimeType::Fix : SvxTimeType::Var; | ||||
858 | p->SetType(eType); | ||||
859 | } | ||||
860 | else if (rName == SC_UNONAME_DATETIME"DateTime") | ||||
861 | { | ||||
862 | maDateTime = rVal.get<util::DateTime>(); | ||||
863 | tools::Time aTime(maDateTime); | ||||
864 | p->SetFixTime(aTime); | ||||
865 | } | ||||
866 | else if (rName == SC_UNONAME_NUMFMT"NumberFormat") | ||||
867 | { | ||||
868 | mnNumFormat = rVal.get<sal_Int32>(); | ||||
869 | p->SetFormat(static_cast<SvxTimeFormat>(mnNumFormat)); | ||||
870 | } | ||||
871 | else | ||||
872 | throw beans::UnknownPropertyException(rName); | ||||
873 | } | ||||
874 | break; | ||||
875 | default: | ||||
876 | throw beans::UnknownPropertyException(rName); | ||||
877 | } | ||||
878 | } | ||||
879 | else | ||||
880 | { | ||||
881 | if (rName == SC_UNONAME_ISDATE"IsDate") | ||||
882 | mbIsDate = rVal.get<bool>(); | ||||
883 | else if (rName == SC_UNONAME_ISFIXED"IsFixed") | ||||
884 | mbIsFixed = rVal.get<bool>(); | ||||
885 | else if (rName == SC_UNONAME_DATETIME"DateTime") | ||||
886 | maDateTime = rVal.get<util::DateTime>(); | ||||
887 | else if (rName == SC_UNONAME_NUMFMT"NumberFormat") | ||||
888 | mnNumFormat = rVal.get<sal_Int32>(); | ||||
889 | else | ||||
890 | throw beans::UnknownPropertyException(rName); | ||||
891 | } | ||||
892 | } | ||||
893 | |||||
894 | uno::Any ScEditFieldObj::getPropertyValueDateTime(const OUString& rName) | ||||
895 | { | ||||
896 | if (mpEditSource) | ||||
897 | { | ||||
898 | // Field already inserted. | ||||
899 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
900 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
901 | SvxFieldData* pField = aTempEngine.FindByPos(aSelection.nStartPara, aSelection.nStartPos, meType); | ||||
902 | if (!pField) | ||||
903 | throw uno::RuntimeException(); | ||||
904 | |||||
905 | switch (meType) | ||||
906 | { | ||||
907 | case text::textfield::Type::DATE: | ||||
908 | { | ||||
909 | SvxDateField* p = static_cast<SvxDateField*>(pField); | ||||
910 | if (rName == SC_UNONAME_ISDATE"IsDate") | ||||
911 | return uno::makeAny(true); | ||||
912 | |||||
913 | if (rName == SC_UNONAME_ISFIXED"IsFixed") | ||||
914 | return uno::makeAny<sal_Bool>(p->GetType() == SvxDateType::Fix); | ||||
915 | |||||
916 | if (rName == SC_UNONAME_DATETIME"DateTime") | ||||
917 | { | ||||
918 | Date aD(p->GetFixDate()); | ||||
919 | maDateTime.Year = aD.GetYear(); | ||||
920 | maDateTime.Month = aD.GetMonth(); | ||||
921 | maDateTime.Day = aD.GetDay(); | ||||
922 | maDateTime.Hours = 0; | ||||
923 | maDateTime.Minutes = 0; | ||||
924 | maDateTime.Seconds = 0; | ||||
925 | maDateTime.NanoSeconds = 0; | ||||
926 | return uno::makeAny(maDateTime); | ||||
927 | } | ||||
928 | |||||
929 | if (rName == SC_UNONAME_NUMFMT"NumberFormat") | ||||
930 | return uno::makeAny<sal_Int32>(static_cast<sal_Int32>(p->GetFormat())); | ||||
931 | } | ||||
932 | break; | ||||
933 | case text::textfield::Type::TIME: | ||||
934 | { | ||||
935 | // SvxTimeField doesn't have any attributes. | ||||
936 | if (rName == SC_UNONAME_ISDATE"IsDate") | ||||
937 | return uno::makeAny(false); | ||||
938 | |||||
939 | if (rName == SC_UNONAME_ISFIXED"IsFixed") | ||||
940 | return uno::makeAny(false); | ||||
941 | |||||
942 | if (rName == SC_UNONAME_DATETIME"DateTime") | ||||
943 | // This is the best we can do. | ||||
944 | return uno::makeAny(maDateTime); | ||||
945 | |||||
946 | if (rName == SC_UNONAME_NUMFMT"NumberFormat") | ||||
947 | // Same as above. | ||||
948 | return uno::makeAny<sal_Int32>(0); | ||||
949 | } | ||||
950 | break; | ||||
951 | case text::textfield::Type::EXTENDED_TIME: | ||||
952 | { | ||||
953 | SvxExtTimeField* p = static_cast<SvxExtTimeField*>(pField); | ||||
954 | if (rName == SC_UNONAME_ISDATE"IsDate") | ||||
955 | return uno::makeAny(false); | ||||
956 | |||||
957 | if (rName == SC_UNONAME_ISFIXED"IsFixed") | ||||
958 | return uno::makeAny<sal_Bool>(p->GetType() == SvxTimeType::Fix); | ||||
959 | |||||
960 | if (rName == SC_UNONAME_DATETIME"DateTime") | ||||
961 | { | ||||
962 | tools::Time aT(p->GetFixTime()); | ||||
963 | maDateTime.Year = 0; | ||||
964 | maDateTime.Month = 0; | ||||
965 | maDateTime.Day = 0; | ||||
966 | maDateTime.Hours = aT.GetHour(); | ||||
967 | maDateTime.Minutes = aT.GetMin(); | ||||
968 | maDateTime.Seconds = aT.GetSec(); | ||||
969 | maDateTime.NanoSeconds = aT.GetNanoSec(); | ||||
970 | return uno::makeAny(maDateTime); | ||||
971 | } | ||||
972 | |||||
973 | if (rName == SC_UNONAME_NUMFMT"NumberFormat") | ||||
974 | return uno::makeAny<sal_Int32>(static_cast<sal_Int32>(p->GetFormat())); | ||||
975 | } | ||||
976 | break; | ||||
977 | default: | ||||
978 | ; | ||||
979 | } | ||||
980 | } | ||||
981 | else | ||||
982 | { | ||||
983 | if (rName == SC_UNONAME_ISDATE"IsDate") | ||||
984 | return uno::makeAny<sal_Bool>(mbIsDate); | ||||
985 | |||||
986 | if (rName == SC_UNONAME_ISFIXED"IsFixed") | ||||
987 | return uno::makeAny<sal_Bool>(mbIsFixed); | ||||
988 | |||||
989 | if (rName == SC_UNONAME_DATETIME"DateTime") | ||||
990 | return uno::makeAny(maDateTime); | ||||
991 | |||||
992 | if (rName == SC_UNONAME_NUMFMT"NumberFormat") | ||||
993 | return uno::makeAny(mnNumFormat); | ||||
994 | } | ||||
995 | |||||
996 | throw beans::UnknownPropertyException(rName); | ||||
997 | } | ||||
998 | |||||
999 | void ScEditFieldObj::setPropertyValueSheet(const OUString& rName, const uno::Any& rVal) | ||||
1000 | { | ||||
1001 | if (mpEditSource) | ||||
1002 | { | ||||
1003 | // Edit engine instance already exists for this field item. Use it. | ||||
1004 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
1005 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
1006 | |||||
1007 | // don't care about the type (only URLs can be found in the cells) | ||||
1008 | SvxFieldData* pField = aTempEngine.FindByPos( | ||||
1009 | aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::UNSPECIFIED); | ||||
1010 | OSL_ENSURE(pField,"setPropertyValue: Field not found")do { if (true && (!(pField))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "1010" ": "), "%s", "setPropertyValue: Field not found") ; } } while (false); | ||||
1011 | if (!pField) | ||||
1012 | return; | ||||
1013 | |||||
1014 | if (pField->GetClassId() != text::textfield::Type::TABLE) | ||||
1015 | // Make sure this is indeed a URL field. | ||||
1016 | return; | ||||
1017 | |||||
1018 | SvxTableField* p = static_cast<SvxTableField*>(pField); | ||||
1019 | |||||
1020 | if (rName != SC_UNONAME_TABLEPOS"TablePosition") | ||||
1021 | throw beans::UnknownPropertyException(rName); | ||||
1022 | |||||
1023 | sal_Int32 nTab = rVal.get<sal_Int32>(); | ||||
1024 | p->SetTab(nTab); | ||||
1025 | |||||
1026 | |||||
1027 | pEditEngine->QuickInsertField(SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection); | ||||
1028 | mpEditSource->UpdateData(); | ||||
1029 | return; | ||||
1030 | } | ||||
1031 | |||||
1032 | // Edit engine instance not yet present. Store the item data for later use. | ||||
1033 | SvxTableField& r = static_cast<SvxTableField&>(getData()); | ||||
1034 | if (rName != SC_UNONAME_TABLEPOS"TablePosition") | ||||
1035 | throw beans::UnknownPropertyException(rName); | ||||
1036 | |||||
1037 | sal_Int32 nTab = rVal.get<sal_Int32>(); | ||||
1038 | r.SetTab(nTab); | ||||
1039 | } | ||||
1040 | |||||
1041 | ScEditFieldObj::ScEditFieldObj( | ||||
1042 | const uno::Reference<text::XTextRange>& rContent, | ||||
1043 | std::unique_ptr<ScEditSource> pEditSrc, sal_Int32 eType, const ESelection& rSel) : | ||||
1044 | OComponentHelper(getMutex()), | ||||
1045 | pPropSet(nullptr), | ||||
1046 | mpEditSource(std::move(pEditSrc)), | ||||
1047 | aSelection(rSel), | ||||
1048 | meType(eType), mpContent(rContent), mnNumFormat(0), mbIsDate(false), mbIsFixed(false) | ||||
1049 | { | ||||
1050 | switch (meType) | ||||
1051 | { | ||||
1052 | case text::textfield::Type::DOCINFO_TITLE: | ||||
1053 | pPropSet = getEmptyPropertySet(); | ||||
1054 | break; | ||||
1055 | case text::textfield::Type::EXTENDED_FILE: | ||||
1056 | pPropSet = lcl_GetFileFieldPropertySet(); | ||||
1057 | break; | ||||
1058 | case text::textfield::Type::URL: | ||||
1059 | pPropSet = lcl_GetURLPropertySet(); | ||||
1060 | break; | ||||
1061 | case text::textfield::Type::DATE: | ||||
1062 | case text::textfield::Type::TIME: | ||||
1063 | case text::textfield::Type::EXTENDED_TIME: | ||||
1064 | pPropSet = getDateTimePropertySet(); | ||||
1065 | break; | ||||
1066 | default: | ||||
1067 | pPropSet = lcl_GetHeaderFieldPropertySet(); | ||||
1068 | } | ||||
1069 | |||||
1070 | if (meType == text::textfield::Type::DATE) | ||||
1071 | mbIsDate = true; | ||||
1072 | } | ||||
1073 | |||||
1074 | void ScEditFieldObj::InitDoc( | ||||
1075 | const uno::Reference<text::XTextRange>& rContent, std::unique_ptr<ScEditSource> pEditSrc, const ESelection& rSel) | ||||
1076 | { | ||||
1077 | if (!mpEditSource) | ||||
1078 | { | ||||
1079 | mpContent = rContent; | ||||
1080 | mpData.reset(); | ||||
1081 | |||||
1082 | aSelection = rSel; | ||||
1083 | mpEditSource = std::move( pEditSrc ); | ||||
1084 | } | ||||
1085 | } | ||||
1086 | |||||
1087 | ScEditFieldObj::~ScEditFieldObj() | ||||
1088 | { | ||||
1089 | } | ||||
1090 | |||||
1091 | SvxFieldItem ScEditFieldObj::CreateFieldItem() | ||||
1092 | { | ||||
1093 | OSL_ENSURE( !mpEditSource, "CreateFieldItem with inserted field" )do { if (true && (!(!mpEditSource))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "1093" ": "), "%s", "CreateFieldItem with inserted field" ); } } while (false); | ||||
1094 | return SvxFieldItem(getData(), EE_FEATURE_FIELD); | ||||
1095 | } | ||||
1096 | |||||
1097 | void ScEditFieldObj::DeleteField() | ||||
1098 | { | ||||
1099 | if (mpEditSource) | ||||
1100 | { | ||||
1101 | SvxTextForwarder* pForwarder = mpEditSource->GetTextForwarder(); | ||||
1102 | pForwarder->QuickInsertText( OUString(), aSelection ); | ||||
1103 | mpEditSource->UpdateData(); | ||||
1104 | |||||
1105 | aSelection.nEndPara = aSelection.nStartPara; | ||||
1106 | aSelection.nEndPos = aSelection.nStartPos; | ||||
1107 | |||||
1108 | //! Broadcast in order to adjust selection in other objects | ||||
1109 | //! (also for other actions) | ||||
1110 | } | ||||
1111 | } | ||||
1112 | |||||
1113 | bool ScEditFieldObj::IsInserted() const | ||||
1114 | { | ||||
1115 | return mpEditSource != nullptr; | ||||
1116 | } | ||||
1117 | |||||
1118 | // XTextField | ||||
1119 | |||||
1120 | OUString SAL_CALL ScEditFieldObj::getPresentation( sal_Bool bShowCommand ) | ||||
1121 | { | ||||
1122 | SolarMutexGuard aGuard; | ||||
1123 | |||||
1124 | if (!mpEditSource) | ||||
1125 | return OUString(); | ||||
1126 | |||||
1127 | //! Field functions have to be passed to the forwarder !!! | ||||
1128 | ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); | ||||
1129 | ScUnoEditEngine aTempEngine(pEditEngine); | ||||
1130 | |||||
1131 | // don't care about the type (only URLs can be found in the cells) | ||||
1132 | const SvxFieldData* pField = aTempEngine.FindByPos( | ||||
1133 | aSelection.nStartPara, aSelection.nStartPos, text::textfield::Type::UNSPECIFIED); | ||||
1134 | OSL_ENSURE(pField,"getPresentation: Field not found")do { if (true && (!(pField))) { sal_detail_logFormat( (SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "1134" ": "), "%s", "getPresentation: Field not found"); } } while (false); | ||||
1135 | if (!pField) | ||||
1136 | return OUString(); | ||||
1137 | |||||
1138 | switch (meType) | ||||
1139 | { | ||||
1140 | case text::textfield::Type::URL: | ||||
1141 | { | ||||
1142 | if (pField->GetClassId() != text::textfield::Type::URL) | ||||
1143 | // Not a URL field, but URL is expected. | ||||
1144 | throw uno::RuntimeException(); | ||||
1145 | |||||
1146 | const SvxURLField* pURL = static_cast<const SvxURLField*>(pField); | ||||
1147 | return bShowCommand ? pURL->GetURL() : pURL->GetRepresentation(); | ||||
1148 | } | ||||
1149 | break; | ||||
1150 | default: | ||||
1151 | ; | ||||
1152 | } | ||||
1153 | return OUString(); | ||||
1154 | } | ||||
1155 | |||||
1156 | // XTextContent | ||||
1157 | |||||
1158 | void SAL_CALL ScEditFieldObj::attach( const uno::Reference<text::XTextRange>& xTextRange ) | ||||
1159 | { | ||||
1160 | SolarMutexGuard aGuard; | ||||
1161 | if (xTextRange.is()) | ||||
1162 | { | ||||
1163 | uno::Reference<text::XText> xText(xTextRange->getText()); | ||||
1164 | if (xText.is()) | ||||
1165 | { | ||||
1166 | xText->insertTextContent( xTextRange, this, true ); | ||||
1167 | } | ||||
1168 | } | ||||
1169 | } | ||||
1170 | |||||
1171 | uno::Reference<text::XTextRange> SAL_CALL ScEditFieldObj::getAnchor() | ||||
1172 | { | ||||
1173 | SolarMutexGuard aGuard; | ||||
1174 | return mpContent; | ||||
1175 | } | ||||
1176 | |||||
1177 | // XComponent | ||||
1178 | |||||
1179 | void SAL_CALL ScEditFieldObj::dispose() | ||||
1180 | { | ||||
1181 | OComponentHelper::dispose(); | ||||
1182 | } | ||||
1183 | |||||
1184 | void SAL_CALL ScEditFieldObj::addEventListener( | ||||
1185 | const uno::Reference<lang::XEventListener>& xListener ) | ||||
1186 | { | ||||
1187 | OComponentHelper::addEventListener( xListener ); | ||||
1188 | } | ||||
1189 | |||||
1190 | void SAL_CALL ScEditFieldObj::removeEventListener( | ||||
1191 | const uno::Reference<lang::XEventListener>& xListener ) | ||||
1192 | { | ||||
1193 | OComponentHelper::removeEventListener( xListener ); | ||||
1194 | } | ||||
1195 | |||||
1196 | // XPropertySet | ||||
1197 | |||||
1198 | uno::Reference<beans::XPropertySetInfo> SAL_CALL ScEditFieldObj::getPropertySetInfo() | ||||
1199 | { | ||||
1200 | SolarMutexGuard aGuard; | ||||
1201 | uno::Reference<beans::XPropertySetInfo> aRef = pPropSet->getPropertySetInfo(); | ||||
1202 | return aRef; | ||||
1203 | } | ||||
1204 | |||||
1205 | void SAL_CALL ScEditFieldObj::setPropertyValue( | ||||
1206 | const OUString& aPropertyName, const uno::Any& aValue ) | ||||
1207 | { | ||||
1208 | SolarMutexGuard aGuard; | ||||
1209 | if (aPropertyName == SC_UNONAME_ANCHOR"Anchor") | ||||
1210 | { | ||||
1211 | aValue >>= mpContent; | ||||
1212 | return; | ||||
1213 | } | ||||
1214 | |||||
1215 | switch (meType) | ||||
1216 | { | ||||
1217 | case text::textfield::Type::URL: | ||||
1218 | setPropertyValueURL(aPropertyName, aValue); | ||||
1219 | break; | ||||
1220 | case text::textfield::Type::EXTENDED_FILE: | ||||
1221 | setPropertyValueFile(aPropertyName, aValue); | ||||
1222 | break; | ||||
1223 | case text::textfield::Type::DATE: | ||||
1224 | case text::textfield::Type::TIME: | ||||
1225 | case text::textfield::Type::EXTENDED_TIME: | ||||
1226 | setPropertyValueDateTime(aPropertyName, aValue); | ||||
1227 | break; | ||||
1228 | case text::textfield::Type::TABLE: | ||||
1229 | setPropertyValueSheet(aPropertyName, aValue); | ||||
1230 | break; | ||||
1231 | case text::textfield::Type::DOCINFO_TITLE: | ||||
1232 | default: | ||||
1233 | throw beans::UnknownPropertyException(OUString::number(meType)); | ||||
1234 | } | ||||
1235 | } | ||||
1236 | |||||
1237 | uno::Any SAL_CALL ScEditFieldObj::getPropertyValue( const OUString& aPropertyName ) | ||||
1238 | { | ||||
1239 | SolarMutexGuard aGuard; | ||||
1240 | if (aPropertyName == SC_UNONAME_TEXTFIELD_TYPE"TextFieldType") | ||||
| |||||
1241 | return uno::makeAny(meType); | ||||
1242 | |||||
1243 | if (aPropertyName == SC_UNONAME_ANCHOR"Anchor") | ||||
1244 | return uno::makeAny(mpContent); | ||||
1245 | |||||
1246 | if (aPropertyName == SC_UNONAME_ANCTYPE"AnchorType") | ||||
1247 | { | ||||
1248 | uno::Any aRet; | ||||
1249 | aRet <<= text::TextContentAnchorType_AS_CHARACTER; | ||||
1250 | return aRet; | ||||
1251 | } | ||||
1252 | if (aPropertyName == SC_UNONAME_ANCTYPES"AnchorTypes") | ||||
1253 | { | ||||
1254 | uno::Any aRet; | ||||
1255 | uno::Sequence<text::TextContentAnchorType> aSeq(1); | ||||
1256 | aSeq[0] = text::TextContentAnchorType_AS_CHARACTER; | ||||
1257 | aRet <<= aSeq; | ||||
1258 | return aRet; | ||||
1259 | } | ||||
1260 | if (aPropertyName == SC_UNONAME_TEXTWRAP"TextWrap") | ||||
1261 | { | ||||
1262 | uno::Any aRet; | ||||
1263 | aRet <<= text::WrapTextMode_NONE; | ||||
1264 | return aRet; | ||||
1265 | } | ||||
1266 | |||||
1267 | switch (meType) | ||||
1268 | { | ||||
1269 | case text::textfield::Type::URL: | ||||
1270 | return getPropertyValueURL(aPropertyName); | ||||
1271 | case text::textfield::Type::EXTENDED_FILE: | ||||
1272 | return getPropertyValueFile(aPropertyName); | ||||
1273 | case text::textfield::Type::DATE: | ||||
1274 | case text::textfield::Type::TIME: | ||||
1275 | case text::textfield::Type::EXTENDED_TIME: | ||||
1276 | return getPropertyValueDateTime(aPropertyName); | ||||
1277 | case text::textfield::Type::DOCINFO_TITLE: | ||||
1278 | default: | ||||
1279 | throw beans::UnknownPropertyException(OUString::number(meType)); | ||||
1280 | } | ||||
1281 | } | ||||
1282 | |||||
1283 | SC_IMPL_DUMMY_PROPERTY_LISTENER( ScEditFieldObj )void ScEditFieldObj::addPropertyChangeListener( const OUString &, const uno::Reference<beans::XPropertyChangeListener >&) { do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "1283" ": "), "%s", "not implemented"); } } while (false ); } void ScEditFieldObj::removePropertyChangeListener( const OUString&, const uno::Reference<beans::XPropertyChangeListener >&) { do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "1283" ": "), "%s", "not implemented"); } } while (false ); } void ScEditFieldObj::addVetoableChangeListener( const OUString &, const uno::Reference<beans::XVetoableChangeListener >&) { do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "1283" ": "), "%s", "not implemented"); } } while (false ); } void ScEditFieldObj::removeVetoableChangeListener( const OUString&, const uno::Reference<beans::XVetoableChangeListener >&) { do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/unoobj/fielduno.cxx" ":" "1283" ": "), "%s", "not implemented"); } } while (false ); } | ||||
1284 | |||||
1285 | // XUnoTunnel | ||||
1286 | |||||
1287 | UNO3_GETIMPLEMENTATION_IMPL(ScEditFieldObj)namespace { class theScEditFieldObjUnoTunnelId : public rtl:: Static< UnoTunnelIdInit, theScEditFieldObjUnoTunnelId> { }; } const css::uno::Sequence< sal_Int8 > & ScEditFieldObj ::getUnoTunnelId() throw() { return theScEditFieldObjUnoTunnelId ::get().getSeq(); }sal_Int64 ScEditFieldObj::getSomething( const css::uno::Sequence< sal_Int8 >& rId ) { if( isUnoTunnelId <ScEditFieldObj>(rId) ) { return sal::static_int_cast< sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); } return 0; }; | ||||
1288 | |||||
1289 | // XServiceInfo | ||||
1290 | |||||
1291 | OUString SAL_CALL ScEditFieldObj::getImplementationName() | ||||
1292 | { | ||||
1293 | return "ScEditFieldObj"; | ||||
1294 | } | ||||
1295 | |||||
1296 | sal_Bool SAL_CALL ScEditFieldObj::supportsService( const OUString& rServiceName ) | ||||
1297 | { | ||||
1298 | return cppu::supportsService(this, rServiceName); | ||||
1299 | } | ||||
1300 | |||||
1301 | uno::Sequence<OUString> SAL_CALL ScEditFieldObj::getSupportedServiceNames() | ||||
1302 | { | ||||
1303 | return {"com.sun.star.text.TextField", | ||||
1304 | "com.sun.star.text.TextContent"}; | ||||
1305 | } | ||||
1306 | |||||
1307 | uno::Sequence<uno::Type> SAL_CALL ScEditFieldObj::getTypes() | ||||
1308 | { | ||||
1309 | return comphelper::concatSequences( | ||||
1310 | OComponentHelper::getTypes(), | ||||
1311 | uno::Sequence<uno::Type> | ||||
1312 | { | ||||
1313 | cppu::UnoType<text::XTextField>::get(), | ||||
1314 | cppu::UnoType<beans::XPropertySet>::get(), | ||||
1315 | cppu::UnoType<lang::XUnoTunnel>::get(), | ||||
1316 | cppu::UnoType<lang::XServiceInfo>::get() | ||||
1317 | } ); | ||||
1318 | } | ||||
1319 | |||||
1320 | uno::Sequence<sal_Int8> SAL_CALL ScEditFieldObj::getImplementationId() | ||||
1321 | { | ||||
1322 | return css::uno::Sequence<sal_Int8>(); | ||||
1323 | } | ||||
1324 | |||||
1325 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
1 | // unique_ptr implementation -*- C++ -*- |
2 | |
3 | // Copyright (C) 2008-2020 Free Software Foundation, Inc. |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free |
6 | // software; you can redistribute it and/or modify it under the |
7 | // terms of the GNU General Public License as published by the |
8 | // Free Software Foundation; either version 3, or (at your option) |
9 | // any later version. |
10 | |
11 | // This library is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU General Public License for more details. |
15 | |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version |
18 | // 3.1, as published by the Free Software Foundation. |
19 | |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
23 | // <http://www.gnu.org/licenses/>. |
24 | |
25 | /** @file bits/unique_ptr.h |
26 | * This is an internal header file, included by other library headers. |
27 | * Do not attempt to use it directly. @headername{memory} |
28 | */ |
29 | |
30 | #ifndef _UNIQUE_PTR_H1 |
31 | #define _UNIQUE_PTR_H1 1 |
32 | |
33 | #include <bits/c++config.h> |
34 | #include <debug/assertions.h> |
35 | #include <type_traits> |
36 | #include <utility> |
37 | #include <tuple> |
38 | #include <bits/stl_function.h> |
39 | #include <bits/functional_hash.h> |
40 | #if __cplusplus201703L > 201703L |
41 | # include <compare> |
42 | # include <ostream> |
43 | #endif |
44 | |
45 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
46 | { |
47 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
48 | |
49 | /** |
50 | * @addtogroup pointer_abstractions |
51 | * @{ |
52 | */ |
53 | |
54 | #if _GLIBCXX_USE_DEPRECATED1 |
55 | #pragma GCC diagnostic push |
56 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
57 | template<typename> class auto_ptr; |
58 | #pragma GCC diagnostic pop |
59 | #endif |
60 | |
61 | /// Primary template of default_delete, used by unique_ptr for single objects |
62 | template<typename _Tp> |
63 | struct default_delete |
64 | { |
65 | /// Default constructor |
66 | constexpr default_delete() noexcept = default; |
67 | |
68 | /** @brief Converting constructor. |
69 | * |
70 | * Allows conversion from a deleter for objects of another type, `_Up`, |
71 | * only if `_Up*` is convertible to `_Tp*`. |
72 | */ |
73 | template<typename _Up, |
74 | typename = _Require<is_convertible<_Up*, _Tp*>>> |
75 | default_delete(const default_delete<_Up>&) noexcept { } |
76 | |
77 | /// Calls `delete __ptr` |
78 | void |
79 | operator()(_Tp* __ptr) const |
80 | { |
81 | static_assert(!is_void<_Tp>::value, |
82 | "can't delete pointer to incomplete type"); |
83 | static_assert(sizeof(_Tp)>0, |
84 | "can't delete pointer to incomplete type"); |
85 | delete __ptr; |
86 | } |
87 | }; |
88 | |
89 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
90 | // DR 740 - omit specialization for array objects with a compile time length |
91 | |
92 | /// Specialization of default_delete for arrays, used by `unique_ptr<T[]>` |
93 | template<typename _Tp> |
94 | struct default_delete<_Tp[]> |
95 | { |
96 | public: |
97 | /// Default constructor |
98 | constexpr default_delete() noexcept = default; |
99 | |
100 | /** @brief Converting constructor. |
101 | * |
102 | * Allows conversion from a deleter for arrays of another type, such as |
103 | * a const-qualified version of `_Tp`. |
104 | * |
105 | * Conversions from types derived from `_Tp` are not allowed because |
106 | * it is undefined to `delete[]` an array of derived types through a |
107 | * pointer to the base type. |
108 | */ |
109 | template<typename _Up, |
110 | typename = _Require<is_convertible<_Up(*)[], _Tp(*)[]>>> |
111 | default_delete(const default_delete<_Up[]>&) noexcept { } |
112 | |
113 | /// Calls `delete[] __ptr` |
114 | template<typename _Up> |
115 | typename enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value>::type |
116 | operator()(_Up* __ptr) const |
117 | { |
118 | static_assert(sizeof(_Tp)>0, |
119 | "can't delete pointer to incomplete type"); |
120 | delete [] __ptr; |
121 | } |
122 | }; |
123 | |
124 | /// @cond undocumented |
125 | |
126 | // Manages the pointer and deleter of a unique_ptr |
127 | template <typename _Tp, typename _Dp> |
128 | class __uniq_ptr_impl |
129 | { |
130 | template <typename _Up, typename _Ep, typename = void> |
131 | struct _Ptr |
132 | { |
133 | using type = _Up*; |
134 | }; |
135 | |
136 | template <typename _Up, typename _Ep> |
137 | struct |
138 | _Ptr<_Up, _Ep, __void_t<typename remove_reference<_Ep>::type::pointer>> |
139 | { |
140 | using type = typename remove_reference<_Ep>::type::pointer; |
141 | }; |
142 | |
143 | public: |
144 | using _DeleterConstraint = enable_if< |
145 | __and_<__not_<is_pointer<_Dp>>, |
146 | is_default_constructible<_Dp>>::value>; |
147 | |
148 | using pointer = typename _Ptr<_Tp, _Dp>::type; |
149 | |
150 | static_assert( !is_rvalue_reference<_Dp>::value, |
151 | "unique_ptr's deleter type must be a function object type" |
152 | " or an lvalue reference type" ); |
153 | |
154 | __uniq_ptr_impl() = default; |
155 | __uniq_ptr_impl(pointer __p) : _M_t() { _M_ptr() = __p; } |
156 | |
157 | template<typename _Del> |
158 | __uniq_ptr_impl(pointer __p, _Del&& __d) |
159 | : _M_t(__p, std::forward<_Del>(__d)) { } |
160 | |
161 | __uniq_ptr_impl(__uniq_ptr_impl&& __u) noexcept |
162 | : _M_t(std::move(__u._M_t)) |
163 | { __u._M_ptr() = nullptr; } |
164 | |
165 | __uniq_ptr_impl& operator=(__uniq_ptr_impl&& __u) noexcept |
166 | { |
167 | reset(__u.release()); |
168 | _M_deleter() = std::forward<_Dp>(__u._M_deleter()); |
169 | return *this; |
170 | } |
171 | |
172 | pointer& _M_ptr() { return std::get<0>(_M_t); } |
173 | pointer _M_ptr() const { return std::get<0>(_M_t); } |
174 | _Dp& _M_deleter() { return std::get<1>(_M_t); } |
175 | const _Dp& _M_deleter() const { return std::get<1>(_M_t); } |
176 | |
177 | void reset(pointer __p) noexcept |
178 | { |
179 | const pointer __old_p = _M_ptr(); |
180 | _M_ptr() = __p; |
181 | if (__old_p) |
182 | _M_deleter()(__old_p); |
183 | } |
184 | |
185 | pointer release() noexcept |
186 | { |
187 | pointer __p = _M_ptr(); |
188 | _M_ptr() = nullptr; |
189 | return __p; |
190 | } |
191 | |
192 | void |
193 | swap(__uniq_ptr_impl& __rhs) noexcept |
194 | { |
195 | using std::swap; |
196 | swap(this->_M_ptr(), __rhs._M_ptr()); |
197 | swap(this->_M_deleter(), __rhs._M_deleter()); |
198 | } |
199 | |
200 | private: |
201 | tuple<pointer, _Dp> _M_t; |
202 | }; |
203 | |
204 | // Defines move construction + assignment as either defaulted or deleted. |
205 | template <typename _Tp, typename _Dp, |
206 | bool = is_move_constructible<_Dp>::value, |
207 | bool = is_move_assignable<_Dp>::value> |
208 | struct __uniq_ptr_data : __uniq_ptr_impl<_Tp, _Dp> |
209 | { |
210 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
211 | __uniq_ptr_data(__uniq_ptr_data&&) = default; |
212 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default; |
213 | }; |
214 | |
215 | template <typename _Tp, typename _Dp> |
216 | struct __uniq_ptr_data<_Tp, _Dp, true, false> : __uniq_ptr_impl<_Tp, _Dp> |
217 | { |
218 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
219 | __uniq_ptr_data(__uniq_ptr_data&&) = default; |
220 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete; |
221 | }; |
222 | |
223 | template <typename _Tp, typename _Dp> |
224 | struct __uniq_ptr_data<_Tp, _Dp, false, true> : __uniq_ptr_impl<_Tp, _Dp> |
225 | { |
226 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
227 | __uniq_ptr_data(__uniq_ptr_data&&) = delete; |
228 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default; |
229 | }; |
230 | |
231 | template <typename _Tp, typename _Dp> |
232 | struct __uniq_ptr_data<_Tp, _Dp, false, false> : __uniq_ptr_impl<_Tp, _Dp> |
233 | { |
234 | using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl; |
235 | __uniq_ptr_data(__uniq_ptr_data&&) = delete; |
236 | __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete; |
237 | }; |
238 | /// @endcond |
239 | |
240 | /// 20.7.1.2 unique_ptr for single objects. |
241 | template <typename _Tp, typename _Dp = default_delete<_Tp>> |
242 | class unique_ptr |
243 | { |
244 | template <typename _Up> |
245 | using _DeleterConstraint = |
246 | typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type; |
247 | |
248 | __uniq_ptr_data<_Tp, _Dp> _M_t; |
249 | |
250 | public: |
251 | using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer; |
252 | using element_type = _Tp; |
253 | using deleter_type = _Dp; |
254 | |
255 | private: |
256 | // helper template for detecting a safe conversion from another |
257 | // unique_ptr |
258 | template<typename _Up, typename _Ep> |
259 | using __safe_conversion_up = __and_< |
260 | is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>, |
261 | __not_<is_array<_Up>> |
262 | >; |
263 | |
264 | public: |
265 | // Constructors. |
266 | |
267 | /// Default constructor, creates a unique_ptr that owns nothing. |
268 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
269 | constexpr unique_ptr() noexcept |
270 | : _M_t() |
271 | { } |
272 | |
273 | /** Takes ownership of a pointer. |
274 | * |
275 | * @param __p A pointer to an object of @c element_type |
276 | * |
277 | * The deleter will be value-initialized. |
278 | */ |
279 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
280 | explicit |
281 | unique_ptr(pointer __p) noexcept |
282 | : _M_t(__p) |
283 | { } |
284 | |
285 | /** Takes ownership of a pointer. |
286 | * |
287 | * @param __p A pointer to an object of @c element_type |
288 | * @param __d A reference to a deleter. |
289 | * |
290 | * The deleter will be initialized with @p __d |
291 | */ |
292 | template<typename _Del = deleter_type, |
293 | typename = _Require<is_copy_constructible<_Del>>> |
294 | unique_ptr(pointer __p, const deleter_type& __d) noexcept |
295 | : _M_t(__p, __d) { } |
296 | |
297 | /** Takes ownership of a pointer. |
298 | * |
299 | * @param __p A pointer to an object of @c element_type |
300 | * @param __d An rvalue reference to a (non-reference) deleter. |
301 | * |
302 | * The deleter will be initialized with @p std::move(__d) |
303 | */ |
304 | template<typename _Del = deleter_type, |
305 | typename = _Require<is_move_constructible<_Del>>> |
306 | unique_ptr(pointer __p, |
307 | __enable_if_t<!is_lvalue_reference<_Del>::value, |
308 | _Del&&> __d) noexcept |
309 | : _M_t(__p, std::move(__d)) |
310 | { } |
311 | |
312 | template<typename _Del = deleter_type, |
313 | typename _DelUnref = typename remove_reference<_Del>::type> |
314 | unique_ptr(pointer, |
315 | __enable_if_t<is_lvalue_reference<_Del>::value, |
316 | _DelUnref&&>) = delete; |
317 | |
318 | /// Creates a unique_ptr that owns nothing. |
319 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
320 | constexpr unique_ptr(nullptr_t) noexcept |
321 | : _M_t() |
322 | { } |
323 | |
324 | // Move constructors. |
325 | |
326 | /// Move constructor. |
327 | unique_ptr(unique_ptr&&) = default; |
328 | |
329 | /** @brief Converting constructor from another type |
330 | * |
331 | * Requires that the pointer owned by @p __u is convertible to the |
332 | * type of pointer owned by this object, @p __u does not own an array, |
333 | * and @p __u has a compatible deleter type. |
334 | */ |
335 | template<typename _Up, typename _Ep, typename = _Require< |
336 | __safe_conversion_up<_Up, _Ep>, |
337 | typename conditional<is_reference<_Dp>::value, |
338 | is_same<_Ep, _Dp>, |
339 | is_convertible<_Ep, _Dp>>::type>> |
340 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept |
341 | : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter())) |
342 | { } |
343 | |
344 | #if _GLIBCXX_USE_DEPRECATED1 |
345 | #pragma GCC diagnostic push |
346 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
347 | /// Converting constructor from @c auto_ptr |
348 | template<typename _Up, typename = _Require< |
349 | is_convertible<_Up*, _Tp*>, is_same<_Dp, default_delete<_Tp>>>> |
350 | unique_ptr(auto_ptr<_Up>&& __u) noexcept; |
351 | #pragma GCC diagnostic pop |
352 | #endif |
353 | |
354 | /// Destructor, invokes the deleter if the stored pointer is not null. |
355 | ~unique_ptr() noexcept |
356 | { |
357 | static_assert(__is_invocable<deleter_type&, pointer>::value, |
358 | "unique_ptr's deleter must be invocable with a pointer"); |
359 | auto& __ptr = _M_t._M_ptr(); |
360 | if (__ptr != nullptr) |
361 | get_deleter()(std::move(__ptr)); |
362 | __ptr = pointer(); |
363 | } |
364 | |
365 | // Assignment. |
366 | |
367 | /** @brief Move assignment operator. |
368 | * |
369 | * Invokes the deleter if this object owns a pointer. |
370 | */ |
371 | unique_ptr& operator=(unique_ptr&&) = default; |
372 | |
373 | /** @brief Assignment from another type. |
374 | * |
375 | * @param __u The object to transfer ownership from, which owns a |
376 | * convertible pointer to a non-array object. |
377 | * |
378 | * Invokes the deleter if this object owns a pointer. |
379 | */ |
380 | template<typename _Up, typename _Ep> |
381 | typename enable_if< __and_< |
382 | __safe_conversion_up<_Up, _Ep>, |
383 | is_assignable<deleter_type&, _Ep&&> |
384 | >::value, |
385 | unique_ptr&>::type |
386 | operator=(unique_ptr<_Up, _Ep>&& __u) noexcept |
387 | { |
388 | reset(__u.release()); |
389 | get_deleter() = std::forward<_Ep>(__u.get_deleter()); |
390 | return *this; |
391 | } |
392 | |
393 | /// Reset the %unique_ptr to empty, invoking the deleter if necessary. |
394 | unique_ptr& |
395 | operator=(nullptr_t) noexcept |
396 | { |
397 | reset(); |
398 | return *this; |
399 | } |
400 | |
401 | // Observers. |
402 | |
403 | /// Dereference the stored pointer. |
404 | typename add_lvalue_reference<element_type>::type |
405 | operator*() const |
406 | { |
407 | __glibcxx_assert(get() != pointer()); |
408 | return *get(); |
409 | } |
410 | |
411 | /// Return the stored pointer. |
412 | pointer |
413 | operator->() const noexcept |
414 | { |
415 | _GLIBCXX_DEBUG_PEDASSERT(get() != pointer()); |
416 | return get(); |
417 | } |
418 | |
419 | /// Return the stored pointer. |
420 | pointer |
421 | get() const noexcept |
422 | { return _M_t._M_ptr(); } |
423 | |
424 | /// Return a reference to the stored deleter. |
425 | deleter_type& |
426 | get_deleter() noexcept |
427 | { return _M_t._M_deleter(); } |
428 | |
429 | /// Return a reference to the stored deleter. |
430 | const deleter_type& |
431 | get_deleter() const noexcept |
432 | { return _M_t._M_deleter(); } |
433 | |
434 | /// Return @c true if the stored pointer is not null. |
435 | explicit operator bool() const noexcept |
436 | { return get() == pointer() ? false : true; } |
437 | |
438 | // Modifiers. |
439 | |
440 | /// Release ownership of any stored pointer. |
441 | pointer |
442 | release() noexcept |
443 | { return _M_t.release(); } |
444 | |
445 | /** @brief Replace the stored pointer. |
446 | * |
447 | * @param __p The new pointer to store. |
448 | * |
449 | * The deleter will be invoked if a pointer is already owned. |
450 | */ |
451 | void |
452 | reset(pointer __p = pointer()) noexcept |
453 | { |
454 | static_assert(__is_invocable<deleter_type&, pointer>::value, |
455 | "unique_ptr's deleter must be invocable with a pointer"); |
456 | _M_t.reset(std::move(__p)); |
457 | } |
458 | |
459 | /// Exchange the pointer and deleter with another object. |
460 | void |
461 | swap(unique_ptr& __u) noexcept |
462 | { |
463 | static_assert(__is_swappable<_Dp>::value, "deleter must be swappable"); |
464 | _M_t.swap(__u._M_t); |
465 | } |
466 | |
467 | // Disable copy from lvalue. |
468 | unique_ptr(const unique_ptr&) = delete; |
469 | unique_ptr& operator=(const unique_ptr&) = delete; |
470 | }; |
471 | |
472 | /// 20.7.1.3 unique_ptr for array objects with a runtime length |
473 | // [unique.ptr.runtime] |
474 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
475 | // DR 740 - omit specialization for array objects with a compile time length |
476 | template<typename _Tp, typename _Dp> |
477 | class unique_ptr<_Tp[], _Dp> |
478 | { |
479 | template <typename _Up> |
480 | using _DeleterConstraint = |
481 | typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type; |
482 | |
483 | __uniq_ptr_data<_Tp, _Dp> _M_t; |
484 | |
485 | template<typename _Up> |
486 | using __remove_cv = typename remove_cv<_Up>::type; |
487 | |
488 | // like is_base_of<_Tp, _Up> but false if unqualified types are the same |
489 | template<typename _Up> |
490 | using __is_derived_Tp |
491 | = __and_< is_base_of<_Tp, _Up>, |
492 | __not_<is_same<__remove_cv<_Tp>, __remove_cv<_Up>>> >; |
493 | |
494 | public: |
495 | using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer; |
496 | using element_type = _Tp; |
497 | using deleter_type = _Dp; |
498 | |
499 | // helper template for detecting a safe conversion from another |
500 | // unique_ptr |
501 | template<typename _Up, typename _Ep, |
502 | typename _UPtr = unique_ptr<_Up, _Ep>, |
503 | typename _UP_pointer = typename _UPtr::pointer, |
504 | typename _UP_element_type = typename _UPtr::element_type> |
505 | using __safe_conversion_up = __and_< |
506 | is_array<_Up>, |
507 | is_same<pointer, element_type*>, |
508 | is_same<_UP_pointer, _UP_element_type*>, |
509 | is_convertible<_UP_element_type(*)[], element_type(*)[]> |
510 | >; |
511 | |
512 | // helper template for detecting a safe conversion from a raw pointer |
513 | template<typename _Up> |
514 | using __safe_conversion_raw = __and_< |
515 | __or_<__or_<is_same<_Up, pointer>, |
516 | is_same<_Up, nullptr_t>>, |
517 | __and_<is_pointer<_Up>, |
518 | is_same<pointer, element_type*>, |
519 | is_convertible< |
520 | typename remove_pointer<_Up>::type(*)[], |
521 | element_type(*)[]> |
522 | > |
523 | > |
524 | >; |
525 | |
526 | // Constructors. |
527 | |
528 | /// Default constructor, creates a unique_ptr that owns nothing. |
529 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
530 | constexpr unique_ptr() noexcept |
531 | : _M_t() |
532 | { } |
533 | |
534 | /** Takes ownership of a pointer. |
535 | * |
536 | * @param __p A pointer to an array of a type safely convertible |
537 | * to an array of @c element_type |
538 | * |
539 | * The deleter will be value-initialized. |
540 | */ |
541 | template<typename _Up, |
542 | typename _Vp = _Dp, |
543 | typename = _DeleterConstraint<_Vp>, |
544 | typename = typename enable_if< |
545 | __safe_conversion_raw<_Up>::value, bool>::type> |
546 | explicit |
547 | unique_ptr(_Up __p) noexcept |
548 | : _M_t(__p) |
549 | { } |
550 | |
551 | /** Takes ownership of a pointer. |
552 | * |
553 | * @param __p A pointer to an array of a type safely convertible |
554 | * to an array of @c element_type |
555 | * @param __d A reference to a deleter. |
556 | * |
557 | * The deleter will be initialized with @p __d |
558 | */ |
559 | template<typename _Up, typename _Del = deleter_type, |
560 | typename = _Require<__safe_conversion_raw<_Up>, |
561 | is_copy_constructible<_Del>>> |
562 | unique_ptr(_Up __p, const deleter_type& __d) noexcept |
563 | : _M_t(__p, __d) { } |
564 | |
565 | /** Takes ownership of a pointer. |
566 | * |
567 | * @param __p A pointer to an array of a type safely convertible |
568 | * to an array of @c element_type |
569 | * @param __d A reference to a deleter. |
570 | * |
571 | * The deleter will be initialized with @p std::move(__d) |
572 | */ |
573 | template<typename _Up, typename _Del = deleter_type, |
574 | typename = _Require<__safe_conversion_raw<_Up>, |
575 | is_move_constructible<_Del>>> |
576 | unique_ptr(_Up __p, |
577 | __enable_if_t<!is_lvalue_reference<_Del>::value, |
578 | _Del&&> __d) noexcept |
579 | : _M_t(std::move(__p), std::move(__d)) |
580 | { } |
581 | |
582 | template<typename _Up, typename _Del = deleter_type, |
583 | typename _DelUnref = typename remove_reference<_Del>::type, |
584 | typename = _Require<__safe_conversion_raw<_Up>>> |
585 | unique_ptr(_Up, |
586 | __enable_if_t<is_lvalue_reference<_Del>::value, |
587 | _DelUnref&&>) = delete; |
588 | |
589 | /// Move constructor. |
590 | unique_ptr(unique_ptr&&) = default; |
591 | |
592 | /// Creates a unique_ptr that owns nothing. |
593 | template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>> |
594 | constexpr unique_ptr(nullptr_t) noexcept |
595 | : _M_t() |
596 | { } |
597 | |
598 | template<typename _Up, typename _Ep, typename = _Require< |
599 | __safe_conversion_up<_Up, _Ep>, |
600 | typename conditional<is_reference<_Dp>::value, |
601 | is_same<_Ep, _Dp>, |
602 | is_convertible<_Ep, _Dp>>::type>> |
603 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept |
604 | : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter())) |
605 | { } |
606 | |
607 | /// Destructor, invokes the deleter if the stored pointer is not null. |
608 | ~unique_ptr() |
609 | { |
610 | auto& __ptr = _M_t._M_ptr(); |
611 | if (__ptr != nullptr) |
612 | get_deleter()(__ptr); |
613 | __ptr = pointer(); |
614 | } |
615 | |
616 | // Assignment. |
617 | |
618 | /** @brief Move assignment operator. |
619 | * |
620 | * Invokes the deleter if this object owns a pointer. |
621 | */ |
622 | unique_ptr& |
623 | operator=(unique_ptr&&) = default; |
624 | |
625 | /** @brief Assignment from another type. |
626 | * |
627 | * @param __u The object to transfer ownership from, which owns a |
628 | * convertible pointer to an array object. |
629 | * |
630 | * Invokes the deleter if this object owns a pointer. |
631 | */ |
632 | template<typename _Up, typename _Ep> |
633 | typename |
634 | enable_if<__and_<__safe_conversion_up<_Up, _Ep>, |
635 | is_assignable<deleter_type&, _Ep&&> |
636 | >::value, |
637 | unique_ptr&>::type |
638 | operator=(unique_ptr<_Up, _Ep>&& __u) noexcept |
639 | { |
640 | reset(__u.release()); |
641 | get_deleter() = std::forward<_Ep>(__u.get_deleter()); |
642 | return *this; |
643 | } |
644 | |
645 | /// Reset the %unique_ptr to empty, invoking the deleter if necessary. |
646 | unique_ptr& |
647 | operator=(nullptr_t) noexcept |
648 | { |
649 | reset(); |
650 | return *this; |
651 | } |
652 | |
653 | // Observers. |
654 | |
655 | /// Access an element of owned array. |
656 | typename std::add_lvalue_reference<element_type>::type |
657 | operator[](size_t __i) const |
658 | { |
659 | __glibcxx_assert(get() != pointer()); |
660 | return get()[__i]; |
661 | } |
662 | |
663 | /// Return the stored pointer. |
664 | pointer |
665 | get() const noexcept |
666 | { return _M_t._M_ptr(); } |
667 | |
668 | /// Return a reference to the stored deleter. |
669 | deleter_type& |
670 | get_deleter() noexcept |
671 | { return _M_t._M_deleter(); } |
672 | |
673 | /// Return a reference to the stored deleter. |
674 | const deleter_type& |
675 | get_deleter() const noexcept |
676 | { return _M_t._M_deleter(); } |
677 | |
678 | /// Return @c true if the stored pointer is not null. |
679 | explicit operator bool() const noexcept |
680 | { return get() == pointer() ? false : true; } |
681 | |
682 | // Modifiers. |
683 | |
684 | /// Release ownership of any stored pointer. |
685 | pointer |
686 | release() noexcept |
687 | { return _M_t.release(); } |
688 | |
689 | /** @brief Replace the stored pointer. |
690 | * |
691 | * @param __p The new pointer to store. |
692 | * |
693 | * The deleter will be invoked if a pointer is already owned. |
694 | */ |
695 | template <typename _Up, |
696 | typename = _Require< |
697 | __or_<is_same<_Up, pointer>, |
698 | __and_<is_same<pointer, element_type*>, |
699 | is_pointer<_Up>, |
700 | is_convertible< |
701 | typename remove_pointer<_Up>::type(*)[], |
702 | element_type(*)[] |
703 | > |
704 | > |
705 | > |
706 | >> |
707 | void |
708 | reset(_Up __p) noexcept |
709 | { _M_t.reset(std::move(__p)); } |
710 | |
711 | void reset(nullptr_t = nullptr) noexcept |
712 | { reset(pointer()); } |
713 | |
714 | /// Exchange the pointer and deleter with another object. |
715 | void |
716 | swap(unique_ptr& __u) noexcept |
717 | { |
718 | static_assert(__is_swappable<_Dp>::value, "deleter must be swappable"); |
719 | _M_t.swap(__u._M_t); |
720 | } |
721 | |
722 | // Disable copy from lvalue. |
723 | unique_ptr(const unique_ptr&) = delete; |
724 | unique_ptr& operator=(const unique_ptr&) = delete; |
725 | }; |
726 | |
727 | /// @relates unique_ptr @{ |
728 | |
729 | /// Swap overload for unique_ptr |
730 | template<typename _Tp, typename _Dp> |
731 | inline |
732 | #if __cplusplus201703L > 201402L || !defined(__STRICT_ANSI__1) // c++1z or gnu++11 |
733 | // Constrained free swap overload, see p0185r1 |
734 | typename enable_if<__is_swappable<_Dp>::value>::type |
735 | #else |
736 | void |
737 | #endif |
738 | swap(unique_ptr<_Tp, _Dp>& __x, |
739 | unique_ptr<_Tp, _Dp>& __y) noexcept |
740 | { __x.swap(__y); } |
741 | |
742 | #if __cplusplus201703L > 201402L || !defined(__STRICT_ANSI__1) // c++1z or gnu++11 |
743 | template<typename _Tp, typename _Dp> |
744 | typename enable_if<!__is_swappable<_Dp>::value>::type |
745 | swap(unique_ptr<_Tp, _Dp>&, |
746 | unique_ptr<_Tp, _Dp>&) = delete; |
747 | #endif |
748 | |
749 | /// Equality operator for unique_ptr objects, compares the owned pointers |
750 | template<typename _Tp, typename _Dp, |
751 | typename _Up, typename _Ep> |
752 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
753 | operator==(const unique_ptr<_Tp, _Dp>& __x, |
754 | const unique_ptr<_Up, _Ep>& __y) |
755 | { return __x.get() == __y.get(); } |
756 | |
757 | /// unique_ptr comparison with nullptr |
758 | template<typename _Tp, typename _Dp> |
759 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
760 | operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept |
761 | { return !__x; } |
762 | |
763 | #ifndef __cpp_lib_three_way_comparison |
764 | /// unique_ptr comparison with nullptr |
765 | template<typename _Tp, typename _Dp> |
766 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
767 | operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept |
768 | { return !__x; } |
769 | |
770 | /// Inequality operator for unique_ptr objects, compares the owned pointers |
771 | template<typename _Tp, typename _Dp, |
772 | typename _Up, typename _Ep> |
773 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
774 | operator!=(const unique_ptr<_Tp, _Dp>& __x, |
775 | const unique_ptr<_Up, _Ep>& __y) |
776 | { return __x.get() != __y.get(); } |
777 | |
778 | /// unique_ptr comparison with nullptr |
779 | template<typename _Tp, typename _Dp> |
780 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
781 | operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept |
782 | { return (bool)__x; } |
783 | |
784 | /// unique_ptr comparison with nullptr |
785 | template<typename _Tp, typename _Dp> |
786 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
787 | operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept |
788 | { return (bool)__x; } |
789 | #endif // three way comparison |
790 | |
791 | /// Relational operator for unique_ptr objects, compares the owned pointers |
792 | template<typename _Tp, typename _Dp, |
793 | typename _Up, typename _Ep> |
794 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
795 | operator<(const unique_ptr<_Tp, _Dp>& __x, |
796 | const unique_ptr<_Up, _Ep>& __y) |
797 | { |
798 | typedef typename |
799 | std::common_type<typename unique_ptr<_Tp, _Dp>::pointer, |
800 | typename unique_ptr<_Up, _Ep>::pointer>::type _CT; |
801 | return std::less<_CT>()(__x.get(), __y.get()); |
802 | } |
803 | |
804 | /// unique_ptr comparison with nullptr |
805 | template<typename _Tp, typename _Dp> |
806 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
807 | operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
808 | { |
809 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(), |
810 | nullptr); |
811 | } |
812 | |
813 | /// unique_ptr comparison with nullptr |
814 | template<typename _Tp, typename _Dp> |
815 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
816 | operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
817 | { |
818 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr, |
819 | __x.get()); |
820 | } |
821 | |
822 | /// Relational operator for unique_ptr objects, compares the owned pointers |
823 | template<typename _Tp, typename _Dp, |
824 | typename _Up, typename _Ep> |
825 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
826 | operator<=(const unique_ptr<_Tp, _Dp>& __x, |
827 | const unique_ptr<_Up, _Ep>& __y) |
828 | { return !(__y < __x); } |
829 | |
830 | /// unique_ptr comparison with nullptr |
831 | template<typename _Tp, typename _Dp> |
832 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
833 | operator<=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
834 | { return !(nullptr < __x); } |
835 | |
836 | /// unique_ptr comparison with nullptr |
837 | template<typename _Tp, typename _Dp> |
838 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
839 | operator<=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
840 | { return !(__x < nullptr); } |
841 | |
842 | /// Relational operator for unique_ptr objects, compares the owned pointers |
843 | template<typename _Tp, typename _Dp, |
844 | typename _Up, typename _Ep> |
845 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
846 | operator>(const unique_ptr<_Tp, _Dp>& __x, |
847 | const unique_ptr<_Up, _Ep>& __y) |
848 | { return (__y < __x); } |
849 | |
850 | /// unique_ptr comparison with nullptr |
851 | template<typename _Tp, typename _Dp> |
852 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
853 | operator>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
854 | { |
855 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr, |
856 | __x.get()); |
857 | } |
858 | |
859 | /// unique_ptr comparison with nullptr |
860 | template<typename _Tp, typename _Dp> |
861 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
862 | operator>(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
863 | { |
864 | return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(), |
865 | nullptr); |
866 | } |
867 | |
868 | /// Relational operator for unique_ptr objects, compares the owned pointers |
869 | template<typename _Tp, typename _Dp, |
870 | typename _Up, typename _Ep> |
871 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
872 | operator>=(const unique_ptr<_Tp, _Dp>& __x, |
873 | const unique_ptr<_Up, _Ep>& __y) |
874 | { return !(__x < __y); } |
875 | |
876 | /// unique_ptr comparison with nullptr |
877 | template<typename _Tp, typename _Dp> |
878 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
879 | operator>=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
880 | { return !(__x < nullptr); } |
881 | |
882 | /// unique_ptr comparison with nullptr |
883 | template<typename _Tp, typename _Dp> |
884 | _GLIBCXX_NODISCARD[[__nodiscard__]] inline bool |
885 | operator>=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) |
886 | { return !(nullptr < __x); } |
887 | |
888 | #ifdef __cpp_lib_three_way_comparison |
889 | template<typename _Tp, typename _Dp, typename _Up, typename _Ep> |
890 | requires three_way_comparable_with<typename unique_ptr<_Tp, _Dp>::pointer, |
891 | typename unique_ptr<_Up, _Ep>::pointer> |
892 | inline |
893 | compare_three_way_result_t<typename unique_ptr<_Tp, _Dp>::pointer, |
894 | typename unique_ptr<_Up, _Ep>::pointer> |
895 | operator<=>(const unique_ptr<_Tp, _Dp>& __x, |
896 | const unique_ptr<_Up, _Ep>& __y) |
897 | { return compare_three_way()(__x.get(), __y.get()); } |
898 | |
899 | template<typename _Tp, typename _Dp> |
900 | requires three_way_comparable<typename unique_ptr<_Tp, _Dp>::pointer> |
901 | inline |
902 | compare_three_way_result_t<typename unique_ptr<_Tp, _Dp>::pointer> |
903 | operator<=>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) |
904 | { |
905 | using pointer = typename unique_ptr<_Tp, _Dp>::pointer; |
906 | return compare_three_way()(__x.get(), static_cast<pointer>(nullptr)); |
907 | } |
908 | #endif |
909 | // @} relates unique_ptr |
910 | |
911 | /// @cond undocumented |
912 | template<typename _Up, typename _Ptr = typename _Up::pointer, |
913 | bool = __poison_hash<_Ptr>::__enable_hash_call> |
914 | struct __uniq_ptr_hash |
915 | #if ! _GLIBCXX_INLINE_VERSION0 |
916 | : private __poison_hash<_Ptr> |
917 | #endif |
918 | { |
919 | size_t |
920 | operator()(const _Up& __u) const |
921 | noexcept(noexcept(std::declval<hash<_Ptr>>()(std::declval<_Ptr>()))) |
922 | { return hash<_Ptr>()(__u.get()); } |
923 | }; |
924 | |
925 | template<typename _Up, typename _Ptr> |
926 | struct __uniq_ptr_hash<_Up, _Ptr, false> |
927 | : private __poison_hash<_Ptr> |
928 | { }; |
929 | /// @endcond |
930 | |
931 | /// std::hash specialization for unique_ptr. |
932 | template<typename _Tp, typename _Dp> |
933 | struct hash<unique_ptr<_Tp, _Dp>> |
934 | : public __hash_base<size_t, unique_ptr<_Tp, _Dp>>, |
935 | public __uniq_ptr_hash<unique_ptr<_Tp, _Dp>> |
936 | { }; |
937 | |
938 | #if __cplusplus201703L >= 201402L |
939 | /// @relates unique_ptr @{ |
940 | #define __cpp_lib_make_unique201304 201304 |
941 | |
942 | /// @cond undocumented |
943 | |
944 | template<typename _Tp> |
945 | struct _MakeUniq |
946 | { typedef unique_ptr<_Tp> __single_object; }; |
947 | |
948 | template<typename _Tp> |
949 | struct _MakeUniq<_Tp[]> |
950 | { typedef unique_ptr<_Tp[]> __array; }; |
951 | |
952 | template<typename _Tp, size_t _Bound> |
953 | struct _MakeUniq<_Tp[_Bound]> |
954 | { struct __invalid_type { }; }; |
955 | |
956 | /// @endcond |
957 | |
958 | /// std::make_unique for single objects |
959 | template<typename _Tp, typename... _Args> |
960 | inline typename _MakeUniq<_Tp>::__single_object |
961 | make_unique(_Args&&... __args) |
962 | { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } |
963 | |
964 | /// std::make_unique for arrays of unknown bound |
965 | template<typename _Tp> |
966 | inline typename _MakeUniq<_Tp>::__array |
967 | make_unique(size_t __num) |
968 | { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); } |
969 | |
970 | /// Disable std::make_unique for arrays of known bound |
971 | template<typename _Tp, typename... _Args> |
972 | inline typename _MakeUniq<_Tp>::__invalid_type |
973 | make_unique(_Args&&...) = delete; |
974 | // @} relates unique_ptr |
975 | #endif // C++14 |
976 | |
977 | #if __cplusplus201703L > 201703L && __cpp_concepts |
978 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
979 | // 2948. unique_ptr does not define operator<< for stream output |
980 | /// Stream output operator for unique_ptr |
981 | template<typename _CharT, typename _Traits, typename _Tp, typename _Dp> |
982 | inline basic_ostream<_CharT, _Traits>& |
983 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
984 | const unique_ptr<_Tp, _Dp>& __p) |
985 | requires requires { __os << __p.get(); } |
986 | { |
987 | __os << __p.get(); |
988 | return __os; |
989 | } |
990 | #endif // C++20 |
991 | |
992 | // @} group pointer_abstractions |
993 | |
994 | #if __cplusplus201703L >= 201703L |
995 | namespace __detail::__variant |
996 | { |
997 | template<typename> struct _Never_valueless_alt; // see <variant> |
998 | |
999 | // Provide the strong exception-safety guarantee when emplacing a |
1000 | // unique_ptr into a variant. |
1001 | template<typename _Tp, typename _Del> |
1002 | struct _Never_valueless_alt<std::unique_ptr<_Tp, _Del>> |
1003 | : std::true_type |
1004 | { }; |
1005 | } // namespace __detail::__variant |
1006 | #endif // C++17 |
1007 | |
1008 | _GLIBCXX_END_NAMESPACE_VERSION |
1009 | } // namespace |
1010 | |
1011 | #endif /* _UNIQUE_PTR_H */ |