/src/libreoffice/editeng/source/items/flditem.cxx
Line | Count | Source |
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 <osl/diagnose.h> |
21 | | #include <osl/file.hxx> |
22 | | #include <utility> |
23 | | #include <svl/numformat.hxx> |
24 | | #include <svl/zforlist.hxx> |
25 | | #include <tools/urlobj.hxx> |
26 | | |
27 | | #include <editeng/flditem.hxx> |
28 | | #include <editeng/CustomPropertyField.hxx> |
29 | | #include <editeng/measfld.hxx> |
30 | | #include <editeng/unonames.hxx> |
31 | | |
32 | | #include <tools/debug.hxx> |
33 | | #include <libxml/xmlwriter.h> |
34 | | |
35 | | #include <com/sun/star/beans/XPropertySet.hpp> |
36 | | #include <com/sun/star/text/XTextContent.hpp> |
37 | | #include <com/sun/star/text/FilenameDisplayFormat.hpp> |
38 | | #include <com/sun/star/util/DateTime.hpp> |
39 | | |
40 | | using namespace com::sun::star; |
41 | | |
42 | | SvxFieldData* SvxFieldData::Create(const uno::Reference<text::XTextContent>& xTextContent) |
43 | 59.6k | { |
44 | 59.6k | uno::Reference<beans::XPropertySet> xPropSet(xTextContent, uno::UNO_QUERY); |
45 | 59.6k | if (!xPropSet.is()) |
46 | 4 | return nullptr; |
47 | | |
48 | | // we do not support these fields from Writer, so make sure we do not throw |
49 | | // here - see fdo#63436 how to possibly extend Writer to make use of this |
50 | 59.6k | uno::Any aAny; |
51 | 59.6k | try { |
52 | 59.6k | aAny = xPropSet->getPropertyValue(UNO_TC_PROP_TEXTFIELD_TYPE); |
53 | 59.6k | if ( !aAny.has<sal_Int32>() ) |
54 | 664 | return nullptr; |
55 | | |
56 | 58.9k | sal_Int32 nFieldType = aAny.get<sal_Int32>(); |
57 | | |
58 | 58.9k | switch (nFieldType) |
59 | 58.9k | { |
60 | 0 | case text::textfield::Type::TIME: |
61 | 0 | case text::textfield::Type::EXTENDED_TIME: |
62 | 3.68k | case text::textfield::Type::DATE: |
63 | 3.68k | { |
64 | 3.68k | bool bIsDate = false; |
65 | 3.68k | xPropSet->getPropertyValue(UNO_TC_PROP_IS_DATE) >>= bIsDate; |
66 | | |
67 | 3.68k | if (bIsDate) |
68 | 3.67k | { |
69 | 3.67k | util::DateTime aDateTime = xPropSet->getPropertyValue(UNO_TC_PROP_DATE_TIME).get<util::DateTime>(); |
70 | 3.67k | Date aDate(aDateTime.Day, aDateTime.Month, aDateTime.Year); |
71 | 3.67k | bool bIsFixed = false; |
72 | 3.67k | xPropSet->getPropertyValue(UNO_TC_PROP_IS_FIXED) >>= bIsFixed; |
73 | | |
74 | 3.67k | SvxDateField* pData = new SvxDateField(aDate, bIsFixed ? SvxDateType::Fix : SvxDateType::Var); |
75 | 3.67k | sal_Int32 nNumFmt = -1; |
76 | 3.67k | xPropSet->getPropertyValue(UNO_TC_PROP_NUMFORMAT) >>= nNumFmt; |
77 | 3.67k | if (static_cast<SvxDateFormat>(nNumFmt) >= SvxDateFormat::AppDefault && |
78 | 3.67k | static_cast<SvxDateFormat>(nNumFmt) <= SvxDateFormat::F) |
79 | 3.67k | pData->SetFormat(static_cast<SvxDateFormat>(nNumFmt)); |
80 | | |
81 | 3.67k | return pData; |
82 | 3.67k | } |
83 | | |
84 | 12 | if (nFieldType != text::textfield::Type::TIME) |
85 | 12 | { |
86 | 12 | util::DateTime aDateTime = xPropSet->getPropertyValue(UNO_TC_PROP_DATE_TIME).get<util::DateTime>(); |
87 | 12 | tools::Time aTime(aDateTime); |
88 | | |
89 | 12 | bool bIsFixed = false; |
90 | 12 | xPropSet->getPropertyValue(UNO_TC_PROP_IS_FIXED) >>= bIsFixed; |
91 | | |
92 | 12 | SvxExtTimeField* pData = new SvxExtTimeField(aTime, bIsFixed ? SvxTimeType::Fix : SvxTimeType::Var); |
93 | | |
94 | 12 | sal_Int32 nNumFmt = -1; |
95 | 12 | xPropSet->getPropertyValue(UNO_TC_PROP_NUMFORMAT) >>= nNumFmt; |
96 | 12 | if (static_cast<SvxTimeFormat>(nNumFmt) >= SvxTimeFormat::AppDefault && |
97 | 12 | static_cast<SvxTimeFormat>(nNumFmt) <= SvxTimeFormat::HH12_MM_SS_00_AMPM) |
98 | 12 | pData->SetFormat(static_cast<SvxTimeFormat>(nNumFmt)); |
99 | | |
100 | 12 | return pData; |
101 | 12 | } |
102 | | |
103 | 0 | return new SvxTimeField(); |
104 | 12 | } |
105 | 402 | case text::textfield::Type::URL: |
106 | 402 | { |
107 | 402 | OUString aRep, aTarget, aURL; |
108 | 402 | sal_Int16 nFmt = -1; |
109 | 402 | xPropSet->getPropertyValue(UNO_TC_PROP_URL_REPRESENTATION) >>= aRep; |
110 | 402 | xPropSet->getPropertyValue(UNO_TC_PROP_URL_TARGET) >>= aTarget; |
111 | 402 | xPropSet->getPropertyValue(UNO_TC_PROP_URL) >>= aURL; |
112 | 402 | xPropSet->getPropertyValue(UNO_TC_PROP_URL_FORMAT) >>= nFmt; |
113 | 402 | SvxURLField* pData = new SvxURLField(aURL, aRep, aRep.isEmpty() ? SvxURLFormat::Url : SvxURLFormat::Repr); |
114 | 402 | pData->SetTargetFrame(aTarget); |
115 | 402 | if (static_cast<SvxURLFormat>(nFmt) >= SvxURLFormat::AppDefault && |
116 | 402 | static_cast<SvxURLFormat>(nFmt) <= SvxURLFormat::Repr) |
117 | 402 | pData->SetFormat(static_cast<SvxURLFormat>(nFmt)); |
118 | | |
119 | 402 | return pData; |
120 | 12 | } |
121 | 32.7k | case text::textfield::Type::PAGE: |
122 | 32.7k | return new SvxPageField(); |
123 | 56 | case text::textfield::Type::PAGES: |
124 | 56 | return new SvxPagesField(); |
125 | 0 | case text::textfield::Type::PAGE_NAME: |
126 | 0 | return new SvxPageTitleField(); |
127 | 0 | case text::textfield::Type::DOCINFO_TITLE: |
128 | 0 | return new SvxFileField(); |
129 | 0 | case text::textfield::Type::TABLE: |
130 | 0 | { |
131 | 0 | sal_Int32 nTab = 0; |
132 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_TABLE_POSITION) >>= nTab; |
133 | 0 | return new SvxTableField(nTab); |
134 | 12 | } |
135 | 0 | case text::textfield::Type::EXTENDED_FILE: |
136 | 0 | { |
137 | 0 | OUString aPresentation; |
138 | 0 | bool bIsFixed = false; |
139 | 0 | sal_Int16 nFmt = text::FilenameDisplayFormat::FULL; |
140 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_IS_FIXED) >>= bIsFixed; |
141 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION) >>= aPresentation; |
142 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_FILE_FORMAT) >>= nFmt; |
143 | |
|
144 | 0 | SvxFileFormat eFmt = SvxFileFormat::NameAndExt; |
145 | 0 | switch (nFmt) |
146 | 0 | { |
147 | 0 | case text::FilenameDisplayFormat::FULL: eFmt = SvxFileFormat::PathFull; break; |
148 | 0 | case text::FilenameDisplayFormat::PATH: eFmt = SvxFileFormat::PathOnly; break; |
149 | 0 | case text::FilenameDisplayFormat::NAME: eFmt = SvxFileFormat::NameOnly; break; |
150 | 0 | default:; |
151 | 0 | } |
152 | | |
153 | | // pass fixed attribute to constructor |
154 | 0 | return new SvxExtFileField( |
155 | 0 | aPresentation, bIsFixed ? SvxFileType::Fix : SvxFileType::Var, eFmt); |
156 | 0 | } |
157 | 0 | case text::textfield::Type::AUTHOR: |
158 | 0 | { |
159 | 0 | bool bIsFixed = false; |
160 | 0 | bool bFullName = false; |
161 | 0 | sal_Int16 nFmt = -1; |
162 | 0 | OUString aPresentation, aContent, aFirstName, aLastName; |
163 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_IS_FIXED) >>= bIsFixed; |
164 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_AUTHOR_FULLNAME) >>= bFullName; |
165 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION) >>= aPresentation; |
166 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_AUTHOR_CONTENT) >>= aContent; |
167 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_AUTHOR_FORMAT) >>= nFmt; |
168 | | |
169 | | // do we have CurrentPresentation given? Mimic behaviour of |
170 | | // writer, which means: prefer CurrentPresentation over Content |
171 | | // if both are given. |
172 | 0 | if (!aPresentation.isEmpty()) |
173 | 0 | aContent = aPresentation; |
174 | |
|
175 | 0 | sal_Int32 nPos = aContent.lastIndexOf(' ', 0); |
176 | 0 | if (nPos > 0) |
177 | 0 | { |
178 | 0 | aFirstName = aContent.copy(0, nPos); |
179 | 0 | aLastName = aContent.copy(nPos + 1); |
180 | 0 | } |
181 | 0 | else |
182 | 0 | { |
183 | 0 | aLastName = aContent; |
184 | 0 | } |
185 | | |
186 | | // #92009# pass fixed attribute to constructor |
187 | 0 | SvxAuthorField* pData = new SvxAuthorField( |
188 | 0 | aFirstName, aLastName, OUString(), bIsFixed ? SvxAuthorType::Fix : SvxAuthorType::Var); |
189 | |
|
190 | 0 | if (!bIsFixed) |
191 | 0 | { |
192 | 0 | if (!bFullName) |
193 | 0 | { |
194 | 0 | pData->SetFormat(SvxAuthorFormat::ShortName); |
195 | 0 | } |
196 | 0 | else if (static_cast<SvxAuthorFormat>(nFmt) >= SvxAuthorFormat::FullName && |
197 | 0 | static_cast<SvxAuthorFormat>(nFmt) <= SvxAuthorFormat::ShortName) |
198 | 0 | { |
199 | 0 | pData->SetFormat(static_cast<SvxAuthorFormat>(nFmt)); |
200 | 0 | } |
201 | 0 | } |
202 | |
|
203 | 0 | return pData; |
204 | 0 | } |
205 | 0 | case text::textfield::Type::MEASURE: |
206 | 0 | { |
207 | 0 | SdrMeasureFieldKind eKind = SdrMeasureFieldKind::Value; |
208 | 0 | sal_Int16 nTmp = -1; |
209 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_MEASURE_KIND) >>= nTmp; |
210 | 0 | if (nTmp == static_cast<sal_Int16>(SdrMeasureFieldKind::Unit) || |
211 | 0 | nTmp == static_cast<sal_Int16>(SdrMeasureFieldKind::Rotate90Blanks)) |
212 | 0 | eKind = static_cast<SdrMeasureFieldKind>(nTmp); |
213 | |
|
214 | 0 | return new SdrMeasureField(eKind); |
215 | 0 | } |
216 | 417 | case text::textfield::Type::PRESENTATION_HEADER: |
217 | 417 | return new SvxHeaderField(); |
218 | 5.97k | case text::textfield::Type::PRESENTATION_FOOTER: |
219 | 5.97k | return new SvxFooterField(); |
220 | 6.01k | case text::textfield::Type::PRESENTATION_DATE_TIME: |
221 | 6.01k | return new SvxDateTimeField(); |
222 | 0 | case text::textfield::Type::DOCINFO_CUSTOM: |
223 | 0 | { |
224 | 0 | OUString sName; |
225 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_NAME) >>= sName; |
226 | |
|
227 | 0 | OUString sCurrentPresentation; |
228 | 0 | xPropSet->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION) >>= sCurrentPresentation; |
229 | |
|
230 | 0 | return new editeng::CustomPropertyField(sName, sCurrentPresentation); |
231 | 0 | } |
232 | 0 | default: |
233 | 0 | ; |
234 | 58.9k | }; |
235 | 0 | } catch ( const beans::UnknownPropertyException& ) |
236 | 59.6k | { |
237 | 9.61k | return nullptr; |
238 | 9.61k | } |
239 | | |
240 | 0 | return nullptr; |
241 | 59.6k | } |
242 | | |
243 | | |
244 | | SvxFieldData::SvxFieldData() |
245 | 3.87M | { |
246 | 3.87M | } |
247 | | |
248 | | |
249 | | SvxFieldData::~SvxFieldData() |
250 | 4.19M | { |
251 | 4.19M | } |
252 | | |
253 | | |
254 | | std::unique_ptr<SvxFieldData> SvxFieldData::Clone() const |
255 | 25 | { |
256 | 25 | return std::make_unique<SvxFieldData>(); |
257 | 25 | } |
258 | | |
259 | | |
260 | | bool SvxFieldData::operator==( const SvxFieldData& rFld ) const |
261 | 0 | { |
262 | 0 | DBG_ASSERT( typeid(*this) == typeid(rFld), "==: Different Types" ); |
263 | 0 | (void)rFld; |
264 | 0 | return true; // Basic class is always the same. |
265 | 0 | } |
266 | | |
267 | | |
268 | | void SvxFieldData::dumpAsXml(xmlTextWriterPtr pWriter) const |
269 | 0 | { |
270 | 0 | (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFieldData")); |
271 | 0 | (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("classId"), BAD_CAST(OString::number(GetClassId()).getStr())); |
272 | 0 | (void)xmlTextWriterEndElement(pWriter); |
273 | 0 | } |
274 | | |
275 | | |
276 | | SvxFieldItem::SvxFieldItem( std::unique_ptr<SvxFieldData> pField, const sal_uInt16 nId ) : |
277 | 15 | SfxPoolItem( nId ) |
278 | 15 | , mpField( std::move(pField) ) |
279 | 15 | { |
280 | 15 | } |
281 | | |
282 | | SvxFieldItem::SvxFieldItem( const SvxFieldData& rField, const sal_uInt16 nId ) : |
283 | 1.32M | SfxPoolItem( nId ) |
284 | 1.32M | , mpField( rField.Clone() ) |
285 | 1.32M | { |
286 | 1.32M | } |
287 | | |
288 | | |
289 | | SvxFieldItem::SvxFieldItem( const SvxFieldItem& rItem ) : |
290 | 1.53M | SfxPoolItem ( rItem ) |
291 | 1.53M | , mpField( rItem.mpField ? rItem.mpField->Clone() : nullptr ) |
292 | 1.53M | { |
293 | 1.53M | } |
294 | | |
295 | | SvxFieldItem::~SvxFieldItem() |
296 | 2.86M | { |
297 | 2.86M | } |
298 | | |
299 | | SvxFieldItem* SvxFieldItem::Clone( SfxItemPool* ) const |
300 | 1.49M | { |
301 | 1.49M | return new SvxFieldItem(*this); |
302 | 1.49M | } |
303 | | |
304 | | bool SvxFieldItem::operator==( const SfxPoolItem& rItem ) const |
305 | 3.01M | { |
306 | 3.01M | assert(SfxPoolItem::operator==(rItem)); |
307 | | |
308 | 3.01M | const SvxFieldData* pOtherFld = static_cast<const SvxFieldItem&>(rItem).GetField(); |
309 | 3.01M | if( mpField.get() == pOtherFld ) |
310 | 173 | return true; |
311 | 3.01M | if( mpField == nullptr || pOtherFld == nullptr ) |
312 | 0 | return false; |
313 | 3.01M | return ( typeid(*mpField) == typeid(*pOtherFld) ) |
314 | 1.29M | && ( *mpField == *pOtherFld ); |
315 | 3.01M | } |
316 | | |
317 | | void SvxFieldItem::dumpAsXml(xmlTextWriterPtr pWriter) const |
318 | 0 | { |
319 | 0 | (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxFieldItem")); |
320 | 0 | (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr())); |
321 | 0 | if (mpField) |
322 | 0 | mpField->dumpAsXml(pWriter); |
323 | 0 | (void)xmlTextWriterEndElement(pWriter); |
324 | 0 | } |
325 | | |
326 | | // The following are the derivatives of SvxFieldData ... |
327 | | |
328 | | |
329 | | SvxDateField::SvxDateField() |
330 | 12.5k | { |
331 | 12.5k | nFixDate = Date( Date::SYSTEM ).GetDate(); |
332 | 12.5k | eType = SvxDateType::Var; |
333 | 12.5k | eFormat = SvxDateFormat::StdSmall; |
334 | 12.5k | } |
335 | | |
336 | | |
337 | | SvxDateField::SvxDateField( const Date& rDate, SvxDateType eT, SvxDateFormat eF ) |
338 | 79.8k | { |
339 | 79.8k | nFixDate = rDate.GetDate(); |
340 | 79.8k | eType = eT; |
341 | 79.8k | eFormat = eF; |
342 | 79.8k | } |
343 | | |
344 | | |
345 | | std::unique_ptr<SvxFieldData> SvxDateField::Clone() const |
346 | 240k | { |
347 | 240k | return std::make_unique<SvxDateField>( *this ); |
348 | 240k | } |
349 | | |
350 | | |
351 | | bool SvxDateField::operator==( const SvxFieldData& rOther ) const |
352 | 20.4k | { |
353 | 20.4k | if ( typeid(rOther) != typeid(*this) ) |
354 | 0 | return false; |
355 | | |
356 | 20.4k | const SvxDateField& rOtherFld = static_cast<const SvxDateField&>(rOther); |
357 | 20.4k | return ( ( nFixDate == rOtherFld.nFixDate ) && |
358 | 20.4k | ( eType == rOtherFld.eType ) && |
359 | 20.4k | ( eFormat == rOtherFld.eFormat ) ); |
360 | 20.4k | } |
361 | | |
362 | | |
363 | | |
364 | | OUString SvxDateField::GetFormatted( SvNumberFormatter& rFormatter, LanguageType eLang ) const |
365 | 291k | { |
366 | 291k | Date aDate( Date::EMPTY ); |
367 | 291k | if ( eType == SvxDateType::Fix ) |
368 | 8 | aDate.SetDate( nFixDate ); |
369 | 291k | else |
370 | 291k | aDate = Date( Date::SYSTEM ); // current date |
371 | | |
372 | 291k | return GetFormatted( aDate, eFormat, rFormatter, eLang ); |
373 | 291k | } |
374 | | |
375 | | OUString SvxDateField::GetFormatted( Date const & aDate, SvxDateFormat eFormat, SvNumberFormatter& rFormatter, LanguageType eLang ) |
376 | 291k | { |
377 | 291k | if ( eFormat == SvxDateFormat::System ) |
378 | 0 | { |
379 | 0 | OSL_FAIL( "SvxDateFormat::System not implemented!" ); |
380 | 0 | eFormat = SvxDateFormat::StdSmall; |
381 | 0 | } |
382 | 291k | else if ( eFormat == SvxDateFormat::AppDefault ) |
383 | 0 | { |
384 | 0 | OSL_FAIL( "SvxDateFormat::AppDefault: take them from where? "); |
385 | 0 | eFormat = SvxDateFormat::StdSmall; |
386 | 0 | } |
387 | | |
388 | 291k | sal_uInt32 nFormatKey; |
389 | | |
390 | 291k | switch( eFormat ) |
391 | 291k | { |
392 | 290k | case SvxDateFormat::StdSmall: |
393 | | // short |
394 | 290k | nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYSTEM_SHORT, eLang ); |
395 | 290k | break; |
396 | 0 | case SvxDateFormat::StdBig: |
397 | | // long |
398 | 0 | nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYSTEM_LONG, eLang ); |
399 | 0 | break; |
400 | 924 | case SvxDateFormat::A: |
401 | | // 13.02.96 |
402 | 924 | nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DDMMYY, eLang ); |
403 | 924 | break; |
404 | 83 | case SvxDateFormat::B: |
405 | | // 13.02.1996 |
406 | 83 | nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLang ); |
407 | 83 | break; |
408 | 55 | case SvxDateFormat::C: |
409 | | // 13. Feb 1996 |
410 | 55 | nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DMMMYYYY, eLang ); |
411 | 55 | break; |
412 | 6 | case SvxDateFormat::D: |
413 | | // 13. February 1996 |
414 | 6 | nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DMMMMYYYY, eLang ); |
415 | 6 | break; |
416 | 0 | case SvxDateFormat::E: |
417 | | // The, 13. February 1996 |
418 | 0 | nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_NNDMMMMYYYY, eLang ); |
419 | 0 | break; |
420 | 0 | case SvxDateFormat::F: |
421 | | // Tuesday, 13. February 1996 |
422 | 0 | nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_NNNNDMMMMYYYY, eLang ); |
423 | 0 | break; |
424 | 0 | default: |
425 | 0 | nFormatKey = rFormatter.GetStandardFormat( SvNumFormatType::DATE, eLang ); |
426 | 291k | } |
427 | | |
428 | 291k | double fDiffDate = aDate - rFormatter.GetNullDate(); |
429 | 291k | OUString aStr; |
430 | 291k | const Color* pColor = nullptr; |
431 | 291k | rFormatter.GetOutputString( fDiffDate, nFormatKey, aStr, &pColor ); |
432 | 291k | return aStr; |
433 | 291k | } |
434 | | |
435 | | SvxURLField::SvxURLField() |
436 | 0 | { |
437 | 0 | eFormat = SvxURLFormat::Url; |
438 | 0 | } |
439 | | |
440 | | |
441 | | SvxURLField::SvxURLField( OUString _aURL, OUString aRepres, SvxURLFormat eFmt ) |
442 | 25.3k | : aURL(std::move( _aURL )), aRepresentation(std::move( aRepres )) |
443 | 25.3k | { |
444 | 25.3k | eFormat = eFmt; |
445 | 25.3k | } |
446 | | |
447 | | |
448 | | std::unique_ptr<SvxFieldData> SvxURLField::Clone() const |
449 | 37.5k | { |
450 | 37.5k | return std::make_unique<SvxURLField>( *this ); |
451 | 37.5k | } |
452 | | |
453 | | |
454 | | bool SvxURLField::operator==( const SvxFieldData& rOther ) const |
455 | 90.2k | { |
456 | 90.2k | if ( typeid(rOther) != typeid(*this) ) |
457 | 0 | return false; |
458 | | |
459 | 90.2k | const SvxURLField& rOtherFld = static_cast<const SvxURLField&>(rOther); |
460 | 90.2k | return ( ( eFormat == rOtherFld.eFormat ) && |
461 | 89.5k | ( aURL == rOtherFld.aURL ) && |
462 | 50.7k | ( aRepresentation == rOtherFld.aRepresentation ) && |
463 | 15.1k | ( aTargetFrame == rOtherFld.aTargetFrame ) ); |
464 | 90.2k | } |
465 | | |
466 | | |
467 | | void SvxURLField::dumpAsXml(xmlTextWriterPtr pWriter) const |
468 | 0 | { |
469 | 0 | (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxURLField")); |
470 | 0 | (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("classId"), BAD_CAST(OString::number(GetClassId()).getStr())); |
471 | 0 | (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("format"), BAD_CAST(OString::number(static_cast<int>(eFormat)).getStr())); |
472 | 0 | (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("url"), BAD_CAST(aURL.toUtf8().getStr())); |
473 | 0 | (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("representation"), BAD_CAST(aRepresentation.toUtf8().getStr())); |
474 | 0 | (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("targetFrame"), BAD_CAST(aTargetFrame.toUtf8().getStr())); |
475 | 0 | (void)xmlTextWriterEndElement(pWriter); |
476 | 0 | } |
477 | | |
478 | | |
479 | | // |
480 | | // SvxPageTitleField methods |
481 | | // |
482 | | |
483 | 0 | SvxPageTitleField::SvxPageTitleField() {} |
484 | | |
485 | | std::unique_ptr<SvxFieldData> SvxPageTitleField::Clone() const |
486 | 0 | { |
487 | 0 | return std::make_unique<SvxPageTitleField>(); |
488 | 0 | } |
489 | | |
490 | | bool SvxPageTitleField::operator==( const SvxFieldData& rCmp ) const |
491 | 0 | { |
492 | 0 | return ( dynamic_cast< const SvxPageTitleField *>(&rCmp) != nullptr ); |
493 | 0 | } |
494 | | |
495 | | // |
496 | | // SvxPagesField |
497 | | // |
498 | | // The fields that were removed from Calc: |
499 | | |
500 | | |
501 | 1.07M | SvxPageField::SvxPageField() {} |
502 | | |
503 | | std::unique_ptr<SvxFieldData> SvxPageField::Clone() const |
504 | 724k | { |
505 | 724k | return std::make_unique<SvxPageField>(); // empty |
506 | 724k | } |
507 | | |
508 | | bool SvxPageField::operator==( const SvxFieldData& rCmp ) const |
509 | 146k | { |
510 | 146k | return ( dynamic_cast< const SvxPageField *>(&rCmp) != nullptr ); |
511 | 146k | } |
512 | | |
513 | 332k | SvxPagesField::SvxPagesField() {} |
514 | | |
515 | | std::unique_ptr<SvxFieldData> SvxPagesField::Clone() const |
516 | 239k | { |
517 | 239k | return std::make_unique<SvxPagesField>(); // empty |
518 | 239k | } |
519 | | |
520 | | bool SvxPagesField::operator==( const SvxFieldData& rCmp ) const |
521 | 20.9k | { |
522 | 20.9k | return ( dynamic_cast< const SvxPagesField *>(&rCmp) != nullptr); |
523 | 20.9k | } |
524 | | |
525 | 295k | SvxTimeField::SvxTimeField() {} |
526 | | |
527 | | std::unique_ptr<SvxFieldData> SvxTimeField::Clone() const |
528 | 220k | { |
529 | 220k | return std::make_unique<SvxTimeField>(); // empty |
530 | 220k | } |
531 | | |
532 | | bool SvxTimeField::operator==( const SvxFieldData& rCmp ) const |
533 | 7.01k | { |
534 | 7.01k | return ( dynamic_cast< const SvxTimeField *>(&rCmp) != nullptr); |
535 | 7.01k | } |
536 | | |
537 | 298k | SvxFileField::SvxFileField() {} |
538 | | |
539 | | std::unique_ptr<SvxFieldData> SvxFileField::Clone() const |
540 | 221k | { |
541 | 221k | return std::make_unique<SvxFileField>(); // empty |
542 | 221k | } |
543 | | |
544 | | bool SvxFileField::operator==( const SvxFieldData& rCmp ) const |
545 | 7.01k | { |
546 | 7.01k | return ( dynamic_cast< const SvxFileField *>(&rCmp) != nullptr ); |
547 | 7.01k | } |
548 | | |
549 | 158k | SvxTableField::SvxTableField() : mnTab(0) {} |
550 | | |
551 | 434k | SvxTableField::SvxTableField(int nTab) : mnTab(nTab) {} |
552 | | |
553 | | void SvxTableField::SetTab(int nTab) |
554 | 0 | { |
555 | 0 | mnTab = nTab; |
556 | 0 | } |
557 | | |
558 | | |
559 | | std::unique_ptr<SvxFieldData> SvxTableField::Clone() const |
560 | 434k | { |
561 | 434k | return std::make_unique<SvxTableField>(mnTab); |
562 | 434k | } |
563 | | |
564 | | bool SvxTableField::operator==( const SvxFieldData& rCmp ) const |
565 | 40.6k | { |
566 | 40.6k | if (dynamic_cast<const SvxTableField *>(&rCmp) == nullptr) |
567 | 0 | return false; |
568 | | |
569 | 40.6k | return mnTab == static_cast<const SvxTableField&>(rCmp).mnTab; |
570 | 40.6k | } |
571 | | |
572 | | // SvxExtTimeField |
573 | | |
574 | | |
575 | | SvxExtTimeField::SvxExtTimeField() |
576 | 18.8k | : m_nFixTime( tools::Time(tools::Time::SYSTEM).GetTime() ) |
577 | 18.8k | { |
578 | 18.8k | eType = SvxTimeType::Var; |
579 | 18.8k | eFormat = SvxTimeFormat::Standard; |
580 | 18.8k | } |
581 | | |
582 | | |
583 | | SvxExtTimeField::SvxExtTimeField( const tools::Time& rTime, SvxTimeType eT, SvxTimeFormat eF ) |
584 | 124 | : m_nFixTime( rTime.GetTime() ) |
585 | 124 | { |
586 | 124 | eType = eT; |
587 | 124 | eFormat = eF; |
588 | 124 | } |
589 | | |
590 | | |
591 | | std::unique_ptr<SvxFieldData> SvxExtTimeField::Clone() const |
592 | 38.0k | { |
593 | 38.0k | return std::make_unique<SvxExtTimeField>( *this ); |
594 | 38.0k | } |
595 | | |
596 | | |
597 | | bool SvxExtTimeField::operator==( const SvxFieldData& rOther ) const |
598 | 754k | { |
599 | 754k | if ( typeid(rOther) != typeid(*this) ) |
600 | 0 | return false; |
601 | | |
602 | 754k | const SvxExtTimeField& rOtherFld = static_cast<const SvxExtTimeField&>(rOther); |
603 | 754k | return ((m_nFixTime == rOtherFld.m_nFixTime) && |
604 | 0 | ( eType == rOtherFld.eType ) && |
605 | 0 | ( eFormat == rOtherFld.eFormat ) ); |
606 | 754k | } |
607 | | |
608 | | |
609 | | OUString SvxExtTimeField::GetFormatted( SvNumberFormatter& rFormatter, LanguageType eLang ) const |
610 | 216 | { |
611 | 216 | tools::Time aTime(eType == SvxTimeType::Fix ? tools::Time::fromEncodedTime(m_nFixTime) |
612 | 216 | : tools::Time(tools::Time::SYSTEM)); // current time |
613 | 216 | return GetFormatted( aTime, eFormat, rFormatter, eLang ); |
614 | 216 | } |
615 | | |
616 | | OUString SvxExtTimeField::GetFormatted( tools::Time const & aTime, SvxTimeFormat eFormat, SvNumberFormatter& rFormatter, LanguageType eLang ) |
617 | 216 | { |
618 | 216 | switch( eFormat ) |
619 | 216 | { |
620 | 0 | case SvxTimeFormat::System : |
621 | 0 | OSL_FAIL( "SvxTimeFormat::System: not implemented" ); |
622 | 0 | eFormat = SvxTimeFormat::Standard; |
623 | 0 | break; |
624 | 0 | case SvxTimeFormat::AppDefault : |
625 | 0 | OSL_FAIL( "SvxTimeFormat::AppDefault: not implemented" ); |
626 | 0 | eFormat = SvxTimeFormat::Standard; |
627 | 0 | break; |
628 | 216 | default: ;//prevent warning |
629 | 216 | } |
630 | | |
631 | 216 | sal_uInt32 nFormatKey; |
632 | | |
633 | 216 | switch( eFormat ) |
634 | 216 | { |
635 | 0 | case SvxTimeFormat::HH12_MM: |
636 | 0 | nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMAMPM, eLang ); |
637 | 0 | break; |
638 | 0 | case SvxTimeFormat::HH12_MM_SS_00: |
639 | 0 | { |
640 | | // no builtin format available, try to insert or reuse |
641 | 0 | OUString aFormatCode( u"HH:MM:SS.00 AM/PM"_ustr ); |
642 | 0 | sal_Int32 nCheckPos; |
643 | 0 | SvNumFormatType nType; |
644 | 0 | rFormatter.PutandConvertEntry( aFormatCode, nCheckPos, nType, |
645 | 0 | nFormatKey, LANGUAGE_ENGLISH_US, eLang, true); |
646 | 0 | DBG_ASSERT( nCheckPos == 0, "SvxTimeFormat::HH12_MM_SS_00: could not insert format code" ); |
647 | 0 | if ( nCheckPos ) |
648 | 0 | { |
649 | 0 | nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang ); |
650 | 0 | } |
651 | 0 | break; |
652 | 0 | } |
653 | 196 | case SvxTimeFormat::HH24_MM: |
654 | 196 | nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMM, eLang ); |
655 | 196 | break; |
656 | 0 | case SvxTimeFormat::HH24_MM_SS_00: |
657 | 0 | nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang ); |
658 | 0 | break; |
659 | 8 | case SvxTimeFormat::HH12_MM_SS: |
660 | 8 | nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSSAMPM, eLang ); |
661 | 8 | break; |
662 | 0 | case SvxTimeFormat::HH24_MM_SS: |
663 | 0 | nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSS, eLang ); |
664 | 0 | break; |
665 | 12 | case SvxTimeFormat::Standard: |
666 | 12 | default: |
667 | 12 | nFormatKey = rFormatter.GetStandardFormat( SvNumFormatType::TIME, eLang ); |
668 | 216 | } |
669 | | |
670 | 216 | double fFracTime = aTime.GetTimeInDays(); |
671 | 216 | OUString aStr; |
672 | 216 | const Color* pColor = nullptr; |
673 | 216 | rFormatter.GetOutputString( fFracTime, nFormatKey, aStr, &pColor ); |
674 | 216 | return aStr; |
675 | 216 | } |
676 | | |
677 | | // SvxExtFileField |
678 | | |
679 | | |
680 | | SvxExtFileField::SvxExtFileField() |
681 | 10 | { |
682 | 10 | eType = SvxFileType::Var; |
683 | 10 | eFormat = SvxFileFormat::PathFull; |
684 | 10 | } |
685 | | |
686 | | |
687 | | SvxExtFileField::SvxExtFileField( const OUString& rStr, SvxFileType eT, SvxFileFormat eF ) |
688 | 108 | { |
689 | 108 | aFile = rStr; |
690 | 108 | eType = eT; |
691 | 108 | eFormat = eF; |
692 | 108 | } |
693 | | |
694 | | |
695 | | std::unique_ptr<SvxFieldData> SvxExtFileField::Clone() const |
696 | 229 | { |
697 | 229 | return std::make_unique<SvxExtFileField>( *this ); |
698 | 229 | } |
699 | | |
700 | | |
701 | | bool SvxExtFileField::operator==( const SvxFieldData& rOther ) const |
702 | 7 | { |
703 | 7 | if ( typeid(rOther) != typeid(*this) ) |
704 | 0 | return false; |
705 | | |
706 | 7 | const SvxExtFileField& rOtherFld = static_cast<const SvxExtFileField&>(rOther); |
707 | 7 | return ( ( aFile == rOtherFld.aFile ) && |
708 | 7 | ( eType == rOtherFld.eType ) && |
709 | 7 | ( eFormat == rOtherFld.eFormat ) ); |
710 | 7 | } |
711 | | |
712 | | |
713 | | OUString SvxExtFileField::GetFormatted() const |
714 | 0 | { |
715 | 0 | OUString aString; |
716 | |
|
717 | 0 | INetURLObject aURLObj( aFile ); |
718 | |
|
719 | 0 | if( INetProtocol::NotValid == aURLObj.GetProtocol() ) |
720 | 0 | { |
721 | | // invalid? try to interpret string as system file name |
722 | 0 | OUString aURLStr; |
723 | |
|
724 | 0 | osl::FileBase::getFileURLFromSystemPath( aFile, aURLStr ); |
725 | |
|
726 | 0 | aURLObj.SetURL( aURLStr ); |
727 | 0 | } |
728 | | |
729 | | // #92009# Be somewhat liberate when trying to |
730 | | // get formatted content out of the FileField |
731 | 0 | if( INetProtocol::NotValid == aURLObj.GetProtocol() ) |
732 | 0 | { |
733 | | // still not valid? Then output as is |
734 | 0 | aString = aFile; |
735 | 0 | } |
736 | 0 | else if( INetProtocol::File == aURLObj.GetProtocol() ) |
737 | 0 | { |
738 | 0 | switch( eFormat ) |
739 | 0 | { |
740 | 0 | case SvxFileFormat::PathFull: |
741 | 0 | aString = aURLObj.getFSysPath(FSysStyle::Detect); |
742 | 0 | break; |
743 | | |
744 | 0 | case SvxFileFormat::PathOnly: |
745 | 0 | aURLObj.removeSegment(INetURLObject::LAST_SEGMENT, false); |
746 | | // #101742# Leave trailing slash at the pathname |
747 | 0 | aURLObj.setFinalSlash(); |
748 | 0 | aString = aURLObj.getFSysPath(FSysStyle::Detect); |
749 | 0 | break; |
750 | | |
751 | 0 | case SvxFileFormat::NameOnly: |
752 | 0 | aString = aURLObj.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DecodeMechanism::Unambiguous); |
753 | 0 | break; |
754 | | |
755 | 0 | case SvxFileFormat::NameAndExt: |
756 | 0 | aString = aURLObj.getName(INetURLObject::LAST_SEGMENT,true,INetURLObject::DecodeMechanism::Unambiguous); |
757 | 0 | break; |
758 | 0 | } |
759 | 0 | } |
760 | 0 | else |
761 | 0 | { |
762 | 0 | switch( eFormat ) |
763 | 0 | { |
764 | 0 | case SvxFileFormat::PathFull: |
765 | 0 | aString = aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ); |
766 | 0 | break; |
767 | | |
768 | 0 | case SvxFileFormat::PathOnly: |
769 | 0 | aURLObj.removeSegment(INetURLObject::LAST_SEGMENT, false); |
770 | | // #101742# Leave trailing slash at the pathname |
771 | 0 | aURLObj.setFinalSlash(); |
772 | 0 | aString = aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ); |
773 | 0 | break; |
774 | | |
775 | 0 | case SvxFileFormat::NameOnly: |
776 | 0 | aString = aURLObj.getBase(); |
777 | 0 | break; |
778 | | |
779 | 0 | case SvxFileFormat::NameAndExt: |
780 | 0 | aString = aURLObj.getName(); |
781 | 0 | break; |
782 | 0 | } |
783 | 0 | } |
784 | | |
785 | 0 | return aString; |
786 | 0 | } |
787 | | |
788 | | |
789 | | // SvxAuthorField |
790 | | |
791 | | |
792 | | SvxAuthorField::SvxAuthorField( const OUString& rFirstName, |
793 | | const OUString& rLastName, |
794 | | const OUString& rShortName, |
795 | | SvxAuthorType eT, SvxAuthorFormat eF ) |
796 | 0 | { |
797 | 0 | aName = rLastName; |
798 | 0 | aFirstName = rFirstName; |
799 | 0 | aShortName = rShortName; |
800 | 0 | eType = eT; |
801 | 0 | eFormat = eF; |
802 | 0 | } |
803 | | |
804 | | |
805 | | std::unique_ptr<SvxFieldData> SvxAuthorField::Clone() const |
806 | 0 | { |
807 | 0 | return std::make_unique<SvxAuthorField>( *this ); |
808 | 0 | } |
809 | | |
810 | | |
811 | | bool SvxAuthorField::operator==( const SvxFieldData& rOther ) const |
812 | 0 | { |
813 | 0 | if ( typeid(rOther) != typeid(*this) ) |
814 | 0 | return false; |
815 | | |
816 | 0 | const SvxAuthorField& rOtherFld = static_cast<const SvxAuthorField&>(rOther); |
817 | 0 | return ( ( aName == rOtherFld.aName ) && |
818 | 0 | ( aFirstName == rOtherFld.aFirstName ) && |
819 | 0 | ( aShortName == rOtherFld.aShortName ) && |
820 | 0 | ( eType == rOtherFld.eType ) && |
821 | 0 | ( eFormat == rOtherFld.eFormat ) ); |
822 | 0 | } |
823 | | |
824 | | |
825 | | OUString SvxAuthorField::GetFormatted() const |
826 | 0 | { |
827 | 0 | OUString aString; |
828 | |
|
829 | 0 | switch( eFormat ) |
830 | 0 | { |
831 | 0 | case SvxAuthorFormat::FullName: |
832 | 0 | aString = aFirstName + " " + aName; |
833 | 0 | break; |
834 | 0 | case SvxAuthorFormat::LastName: |
835 | 0 | aString = aName; |
836 | 0 | break; |
837 | | |
838 | 0 | case SvxAuthorFormat::FirstName: |
839 | 0 | aString = aFirstName; |
840 | 0 | break; |
841 | | |
842 | 0 | case SvxAuthorFormat::ShortName: |
843 | 0 | aString = aShortName; |
844 | 0 | break; |
845 | 0 | } |
846 | | |
847 | 0 | return aString; |
848 | 0 | } |
849 | | |
850 | 287k | SvxHeaderField::SvxHeaderField() {} |
851 | | |
852 | | std::unique_ptr<SvxFieldData> SvxHeaderField::Clone() const |
853 | 176k | { |
854 | 176k | return std::make_unique<SvxHeaderField>(); // empty |
855 | 176k | } |
856 | | |
857 | | bool SvxHeaderField::operator==( const SvxFieldData& rCmp ) const |
858 | 49.3k | { |
859 | 49.3k | return ( dynamic_cast< const SvxHeaderField *>(&rCmp) != nullptr ); |
860 | 49.3k | } |
861 | | |
862 | 427k | SvxFooterField::SvxFooterField() {} |
863 | | |
864 | | std::unique_ptr<SvxFieldData> SvxFooterField::Clone() const |
865 | 264k | { |
866 | 264k | return std::make_unique<SvxFooterField>(); // empty |
867 | 264k | } |
868 | | |
869 | | bool SvxFooterField::operator==( const SvxFieldData& rCmp ) const |
870 | 77.3k | { |
871 | 77.3k | return ( dynamic_cast< const SvxFooterField *>(&rCmp) != nullptr ); |
872 | 77.3k | } |
873 | | |
874 | | std::unique_ptr<SvxFieldData> SvxDateTimeField::Clone() const |
875 | 263k | { |
876 | 263k | return std::make_unique<SvxDateTimeField>(); // empty |
877 | 263k | } |
878 | | |
879 | | bool SvxDateTimeField::operator==( const SvxFieldData& rCmp ) const |
880 | 77.3k | { |
881 | 77.3k | return ( dynamic_cast< const SvxDateTimeField *>(&rCmp) != nullptr ); |
882 | 77.3k | } |
883 | | |
884 | 427k | SvxDateTimeField::SvxDateTimeField() {} |
885 | | |
886 | | OUString SvxDateTimeField::GetFormatted( |
887 | | Date const & rDate, tools::Time const & rTime, |
888 | | SvxDateFormat eDateFormat, SvxTimeFormat eTimeFormat, |
889 | | SvNumberFormatter& rFormatter, LanguageType eLanguage ) |
890 | 0 | { |
891 | 0 | OUString aRet; |
892 | |
|
893 | 0 | if(eDateFormat != SvxDateFormat::AppDefault) |
894 | 0 | { |
895 | 0 | aRet = SvxDateField::GetFormatted( rDate, eDateFormat, rFormatter, eLanguage ); |
896 | 0 | } |
897 | |
|
898 | 0 | if(eTimeFormat != SvxTimeFormat::AppDefault) |
899 | 0 | { |
900 | 0 | OUStringBuffer aBuf(aRet); |
901 | |
|
902 | 0 | if (!aRet.isEmpty()) |
903 | 0 | aBuf.append(' '); |
904 | |
|
905 | 0 | aBuf.append( |
906 | 0 | SvxExtTimeField::GetFormatted(rTime, eTimeFormat, rFormatter, eLanguage)); |
907 | |
|
908 | 0 | aRet = aBuf.makeStringAndClear(); |
909 | 0 | } |
910 | |
|
911 | 0 | return aRet; |
912 | 0 | } |
913 | | |
914 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |