1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <i18nutil/unicode.hxx>
21 #include <svl/itemiter.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/GraphicAttributes.hxx>
26 #include <editeng/itemtype.hxx>
27 #include <editeng/eerdll.hxx>
28 #include <unotools/intlwrapper.hxx>
29 #include <unotools/syslocale.hxx>
30 #include <rtl/ustrbuf.hxx>
31 #include <fmtanchr.hxx>
32 #include <fmtfsize.hxx>
33 #include <fmtinfmt.hxx>
34 #include <fchrfmt.hxx>
35 #include <fmtautofmt.hxx>
36 #include <fmtsrnd.hxx>
37 #include <fmtornt.hxx>
38 #include <fmtlsplt.hxx>
39 #include <fmtrowsplt.hxx>
40 #include <fmtpdsc.hxx>
41 #include <fmtclds.hxx>
42 #include <fmteiro.hxx>
44 #include <fmthdft.hxx>
45 #include <fmtcnct.hxx>
46 #include <fmtline.hxx>
47 #include <tgrditem.hxx>
48 #include <hfspacingitem.hxx>
49 #include <fmtruby.hxx>
52 #include <pagedesc.hxx>
53 #include <charfmt.hxx>
54 #include <strings.hrc>
55 #include <fmtftntx.hxx>
56 #include <fmtfollowtextflow.hxx>
57 #include <libxml/xmlwriter.h>
59 using namespace com::sun::star
;
62 // query the attribute descriptions
63 void SwAttrSet::GetPresentation(
64 SfxItemPresentation ePres
,
67 OUString
&rText
) const
74 SfxItemIter
aIter( *this );
75 const SfxPoolItem
* pItem
= aIter
.GetCurItem();
76 const IntlWrapper
aInt(SvtSysLocale().GetUILanguageTag());
79 pItem
->GetPresentation(ePres
, eCoreMetric
, ePresMetric
, aStr
, aInt
);
80 if( rText
.getLength() && aStr
.getLength() )
83 pItem
= aIter
.NextItem();
87 bool SwFormatCharFormat::GetPresentation
89 SfxItemPresentation ePres
,
93 const IntlWrapper
& /*rIntl*/
96 const SwCharFormat
*pCharFormat
= GetCharFormat();
100 pCharFormat
->GetPresentation( ePres
, eCoreUnit
, ePresUnit
, aStr
);
101 rText
= SwResId( STR_CHARFMT
) + "(" + aStr
+ ")";
104 rText
= SwResId( STR_NO_CHARFMT
);
108 bool SwFormatAutoFormat::GetPresentation
110 SfxItemPresentation
/*ePres*/,
111 MapUnit
/*eCoreUnit*/,
112 MapUnit
/*ePresUnit*/,
114 const IntlWrapper
& /*rIntl*/
117 rText
.clear(); //TODO
121 bool SwFormatINetFormat::GetPresentation
123 SfxItemPresentation
/*ePres*/,
124 MapUnit
/*eCoreUnit*/,
125 MapUnit
/*ePresUnit*/,
127 const IntlWrapper
& /*rIntl*/
134 bool SwFormatRuby::GetPresentation( SfxItemPresentation
/*ePres*/,
135 MapUnit
/*eCoreMetric*/, MapUnit
/*ePresMetric*/,
136 OUString
&rText
, const IntlWrapper
& /*rIntl*/ ) const
142 bool SwFormatDrop::GetPresentation
144 SfxItemPresentation
/*ePres*/,
145 MapUnit
/*eCoreUnit*/,
146 MapUnit
/*ePresUnit*/,
148 const IntlWrapper
& /*rIntl*/
152 if ( GetLines() > 1 )
154 if ( GetChars() > 1 )
156 rText
= OUString::number( GetChars() ) + " ";
158 rText
+= SwResId( STR_DROP_OVER
) +
160 OUString::number( GetLines() ) +
162 SwResId( STR_DROP_LINES
);
165 rText
= SwResId( STR_NO_DROP_LINES
);
169 bool SwRegisterItem::GetPresentation
171 SfxItemPresentation
/*ePres*/,
172 MapUnit
/*eCoreUnit*/,
173 MapUnit
/*ePresUnit*/,
175 const IntlWrapper
& /*rIntl*/
178 TranslateId pId
= GetValue() ? STR_REGISTER_ON
: STR_REGISTER_OFF
;
179 rText
= SwResId(pId
);
183 bool SwNumRuleItem::GetPresentation
185 SfxItemPresentation
/*ePres*/,
186 MapUnit
/*eCoreUnit*/,
187 MapUnit
/*ePresUnit*/,
189 const IntlWrapper
& /*rIntl*/
192 if( !GetValue().isEmpty() )
193 rText
= SwResId( STR_NUMRULE_ON
).replaceFirst("%LISTSTYLENAME", GetValue());
195 rText
= SwResId( STR_NUMRULE_OFF
);
199 bool SwParaConnectBorderItem::GetPresentation
201 SfxItemPresentation
/*ePres*/,
202 MapUnit
/*eCoreUnit*/,
203 MapUnit
/*ePresUnit*/,
205 const IntlWrapper
& /*rIntl*/
208 TranslateId pId
= GetValue() ? STR_CONNECT_BORDER_ON
: STR_CONNECT_BORDER_OFF
;
209 rText
= SwResId(pId
);
215 bool SwFormatFrameSize::GetPresentation
217 SfxItemPresentation
/*ePres*/,
221 const IntlWrapper
& rIntl
224 rText
= SwResId( STR_FRM_WIDTH
) + " ";
225 if ( GetWidthPercent() )
227 rText
+= unicode::formatPercent(GetWidthPercent(),
228 Application::GetSettings().GetUILanguageTag());
232 rText
+= ::GetMetricText( GetWidth(), eCoreUnit
, ePresUnit
, &rIntl
) +
233 " " + ::EditResId( ::GetMetricId( ePresUnit
) );
235 if ( SwFrameSize::Variable
!= GetHeightSizeType() )
237 TranslateId pId
= SwFrameSize::Fixed
== m_eFrameHeightType
?
238 STR_FRM_FIXEDHEIGHT
: STR_FRM_MINHEIGHT
;
239 rText
+= ", " + SwResId(pId
) + " ";
240 if ( GetHeightPercent() )
242 rText
+= unicode::formatPercent(GetHeightPercent(),
243 Application::GetSettings().GetUILanguageTag());
247 rText
= ::GetMetricText( GetHeight(), eCoreUnit
, ePresUnit
, &rIntl
) +
248 " " + EditResId( ::GetMetricId( ePresUnit
) );
254 //Header for page formats.
255 //Client of FrameFormat which describes the header.
257 bool SwFormatHeader::GetPresentation
259 SfxItemPresentation
/*ePres*/,
260 MapUnit
/*eCoreUnit*/,
261 MapUnit
/*ePresUnit*/,
263 const IntlWrapper
& /*rIntl*/
266 TranslateId pId
= GetHeaderFormat() ? STR_HEADER
: STR_NO_HEADER
;
267 rText
= SwResId(pId
);
271 //Footer for page formats.
272 //Client of FrameFormat which describes the footer.
274 bool SwFormatFooter::GetPresentation
276 SfxItemPresentation
/*ePres*/,
277 MapUnit
/*eCoreUnit*/,
278 MapUnit
/*ePresUnit*/,
280 const IntlWrapper
& /*rIntl*/
283 TranslateId pId
= GetFooterFormat() ? STR_FOOTER
: STR_NO_FOOTER
;
284 rText
= SwResId(pId
);
288 bool SwFormatSurround::GetPresentation
290 SfxItemPresentation
/*ePres*/,
291 MapUnit
/*eCoreUnit*/,
292 MapUnit
/*ePresUnit*/,
294 const IntlWrapper
& /*rIntl*/
298 switch ( GetValue() )
300 case css::text::WrapTextMode_NONE
:
301 pId
= STR_SURROUND_NONE
;
303 case css::text::WrapTextMode_THROUGH
:
304 pId
= STR_SURROUND_THROUGH
;
306 case css::text::WrapTextMode_PARALLEL
:
307 pId
= STR_SURROUND_PARALLEL
;
309 case css::text::WrapTextMode_DYNAMIC
:
310 pId
= STR_SURROUND_IDEAL
;
312 case css::text::WrapTextMode_LEFT
:
313 pId
= STR_SURROUND_LEFT
;
315 case css::text::WrapTextMode_RIGHT
:
316 pId
= STR_SURROUND_RIGHT
;
318 default:;//prevent warning
321 rText
= SwResId(pId
);
323 if ( IsAnchorOnly() )
325 rText
+= " " + SwResId( STR_SURROUND_ANCHORONLY
);
330 //VertOrientation, how and by what orientate the FlyFrame in the vertical?
332 bool SwFormatVertOrient::GetPresentation
334 SfxItemPresentation
/*ePres*/,
338 const IntlWrapper
& rIntl
342 switch ( GetVertOrient() )
344 case text::VertOrientation::NONE
:
346 rText
+= SwResId( STR_POS_Y
) + " " +
347 ::GetMetricText( GetPos(), eCoreUnit
, ePresUnit
, &rIntl
) +
348 " " + EditResId( ::GetMetricId( ePresUnit
) );
351 case text::VertOrientation::TOP
:
354 case text::VertOrientation::CENTER
:
355 pId
= STR_VERT_CENTER
;
357 case text::VertOrientation::BOTTOM
:
358 pId
= STR_VERT_BOTTOM
;
360 case text::VertOrientation::LINE_TOP
:
363 case text::VertOrientation::LINE_CENTER
:
364 pId
= STR_LINE_CENTER
;
366 case text::VertOrientation::LINE_BOTTOM
:
367 pId
= STR_LINE_BOTTOM
;
369 default:;//prevent warning
372 rText
+= SwResId(pId
);
376 //HoriOrientation, how and by what orientate the FlyFrame in the horizontal?
378 bool SwFormatHoriOrient::GetPresentation
380 SfxItemPresentation
/*ePres*/,
384 const IntlWrapper
& rIntl
388 switch ( GetHoriOrient() )
390 case text::HoriOrientation::NONE
:
392 rText
+= SwResId( STR_POS_X
) + " " +
393 ::GetMetricText( GetPos(), eCoreUnit
, ePresUnit
, &rIntl
) +
394 " " + EditResId( ::GetMetricId( ePresUnit
) );
397 case text::HoriOrientation::RIGHT
:
398 pId
= STR_HORI_RIGHT
;
400 case text::HoriOrientation::CENTER
:
401 pId
= STR_HORI_CENTER
;
403 case text::HoriOrientation::LEFT
:
406 case text::HoriOrientation::INSIDE
:
407 pId
= STR_HORI_INSIDE
;
409 case text::HoriOrientation::OUTSIDE
:
410 pId
= STR_HORI_OUTSIDE
;
412 case text::HoriOrientation::FULL
:
415 default:;//prevent warning
418 rText
+= SwResId(pId
);
422 // FlyAnchor, Anchor of the free-flying frame
424 bool SwFormatAnchor::GetPresentation
426 SfxItemPresentation
/*ePres*/,
427 MapUnit
/*eCoreUnit*/,
428 MapUnit
/*ePresUnit*/,
430 const IntlWrapper
& /*rIntl*/
434 switch ( GetAnchorId() )
436 case RndStdIds::FLY_AT_PARA
:
437 pId
= STR_FLY_AT_PARA
;
439 case RndStdIds::FLY_AS_CHAR
:
440 pId
= STR_FLY_AS_CHAR
;
442 case RndStdIds::FLY_AT_CHAR
:
443 pId
= STR_FLY_AT_CHAR
;
445 case RndStdIds::FLY_AT_PAGE
:
446 pId
= STR_FLY_AT_PAGE
;
448 default:;//prevent warning
451 rText
+= SwResId(pId
);
455 bool SwFormatPageDesc::GetPresentation
457 SfxItemPresentation
/*ePres*/,
458 MapUnit
/*eCoreUnit*/,
459 MapUnit
/*ePresUnit*/,
461 const IntlWrapper
& /*rIntl*/
464 const SwPageDesc
*pPageDesc
= GetPageDesc();
466 rText
= pPageDesc
->GetName();
468 rText
= SwResId( STR_NO_PAGEDESC
);
472 //The ColumnDescriptor
474 bool SwFormatCol::GetPresentation
476 SfxItemPresentation
/*ePres*/,
478 MapUnit
/*ePresUnit*/,
480 const IntlWrapper
& rIntl
483 sal_uInt16 nCnt
= GetNumCols();
486 rText
= OUString::number(nCnt
) + " " + SwResId( STR_COLUMNS
);
487 if ( COLADJ_NONE
!= GetLineAdj() )
489 const tools::Long nWdth
= static_cast<tools::Long
>(GetLineWidth());
490 rText
+= " " + SwResId( STR_LINE_WIDTH
) + " " +
491 ::GetMetricText( nWdth
, eCoreUnit
,
492 MapUnit::MapPoint
, &rIntl
);
502 bool SwFormatURL::GetPresentation
504 SfxItemPresentation
/*ePres*/,
505 MapUnit
/*eCoreUnit*/,
506 MapUnit
/*ePresUnit*/,
508 const IntlWrapper
& /*rIntl*/
513 rText
+= "Client-Map";
514 if ( !m_sURL
.isEmpty() )
518 rText
+= "URL: " + m_sURL
;
519 if ( m_bIsServerMap
)
520 rText
+= " (Server-Map)";
522 if ( !m_sTargetFrameName
.isEmpty() )
524 rText
+= ", Target: " + m_sTargetFrameName
;
529 bool SwFormatEditInReadonly::GetPresentation
531 SfxItemPresentation
/*ePres*/,
532 MapUnit
/*eCoreUnit*/,
533 MapUnit
/*ePresUnit*/,
535 const IntlWrapper
& /*rIntl*/
540 rText
= SwResId(STR_EDIT_IN_READONLY
);
544 void SwFormatEditInReadonly::dumpAsXml(xmlTextWriterPtr pWriter
) const
546 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwFormatEditInReadonly"));
547 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
548 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("value"), BAD_CAST(OString::boolean(GetValue()).getStr()));
549 (void)xmlTextWriterEndElement(pWriter
);
552 bool SwFormatLayoutSplit::GetPresentation
554 SfxItemPresentation
/*ePres*/,
555 MapUnit
/*eCoreUnit*/,
556 MapUnit
/*ePresUnit*/,
558 const IntlWrapper
& /*rIntl*/
562 rText
= SwResId(STR_LAYOUT_SPLIT
);
566 bool SwFormatRowSplit::GetPresentation
568 SfxItemPresentation
/*ePres*/,
569 MapUnit
/*eCoreUnit*/,
570 MapUnit
/*ePresUnit*/,
572 const IntlWrapper
& /*rIntl*/
578 bool SwFormatFootnoteEndAtTextEnd::GetPresentation
580 SfxItemPresentation
/*ePres*/,
581 MapUnit
/*eCoreUnit*/,
582 MapUnit
/*ePresUnit*/,
584 const IntlWrapper
& /*rIntl*/
590 bool SwFormatChain::GetPresentation
592 SfxItemPresentation
/*ePres*/,
593 MapUnit
/*eCoreUnit*/,
594 MapUnit
/*ePresUnit*/,
596 const IntlWrapper
& /*rIntl*/
599 if ( GetPrev() || GetNext() )
601 rText
= SwResId(STR_CONNECT1
);
604 rText
+= GetPrev()->GetName();
606 rText
+= SwResId(STR_CONNECT2
);
609 rText
+= GetNext()->GetName();
614 bool SwFormatLineNumber::GetPresentation
616 SfxItemPresentation
/*ePres*/,
617 MapUnit
/*eCoreUnit*/,
618 MapUnit
/*ePresUnit*/,
620 const IntlWrapper
& /*rIntl*/
624 rText
+= SwResId(STR_LINECOUNT
);
626 rText
+= SwResId(STR_DONTLINECOUNT
);
627 if ( GetStartValue() )
629 rText
+= " " + SwResId(STR_LINCOUNT_START
) +
630 OUString::number( GetStartValue() );
635 bool SwTextGridItem::GetPresentation
637 SfxItemPresentation
/*ePres*/,
638 MapUnit
/*eCoreUnit*/,
639 MapUnit
/*ePresUnit*/,
641 const IntlWrapper
& /*rIntl*/
646 switch ( GetGridType() )
651 case GRID_LINES_ONLY
:
652 pId
= STR_GRID_LINES_ONLY
;
654 case GRID_LINES_CHARS
:
655 pId
= STR_GRID_LINES_CHARS
;
659 rText
+= SwResId(pId
);
663 bool SwHeaderAndFooterEatSpacingItem::GetPresentation
665 SfxItemPresentation
/*ePres*/,
666 MapUnit
/*eCoreUnit*/,
667 MapUnit
/*ePresUnit*/,
669 const IntlWrapper
& /*rIntl*/
675 // Graphic attributes
677 bool SwMirrorGrf::GetPresentation(
678 SfxItemPresentation
/*ePres*/, MapUnit
/*eCoreUnit*/, MapUnit
/*ePresUnit*/,
679 OUString
& rText
, const IntlWrapper
& /*rIntl*/ ) const
684 case MirrorGraph::Dont
: pId
= STR_NO_MIRROR
; break;
685 case MirrorGraph::Vertical
: pId
= STR_VERT_MIRROR
; break;
686 case MirrorGraph::Horizontal
: pId
= STR_HORI_MIRROR
; break;
687 case MirrorGraph::Both
: pId
= STR_BOTH_MIRROR
; break;
692 rText
= SwResId(pId
);
694 rText
+= SwResId( STR_MIRROR_TOGGLE
);
699 bool SwRotationGrf::GetPresentation(
700 SfxItemPresentation ePres
, MapUnit
/*eCoreUnit*/, MapUnit
/*ePresUnit*/,
701 OUString
&rText
, const IntlWrapper
& /*rIntl*/) const
703 if( SfxItemPresentation::Complete
== ePres
)
704 rText
= SwResId( STR_ROTATION
);
705 else if( rText
.getLength() )
707 rText
+= OUString::number( toDegrees(GetValue()) ) + "\xB0";
711 bool SwLuminanceGrf::GetPresentation(
712 SfxItemPresentation ePres
, MapUnit
/*eCoreUnit*/, MapUnit
/*ePresUnit*/,
713 OUString
&rText
, const IntlWrapper
& /*rIntl*/) const
715 if( SfxItemPresentation::Complete
== ePres
)
716 rText
= SwResId( STR_LUMINANCE
);
717 else if( rText
.getLength() )
719 rText
+= unicode::formatPercent(GetValue(),
720 Application::GetSettings().GetUILanguageTag());
724 bool SwContrastGrf::GetPresentation(
725 SfxItemPresentation ePres
, MapUnit
/*eCoreUnit*/, MapUnit
/*ePresUnit*/,
726 OUString
&rText
, const IntlWrapper
& /*rIntl*/) const
728 if( SfxItemPresentation::Complete
== ePres
)
729 rText
= SwResId( STR_CONTRAST
);
730 else if( rText
.getLength() )
732 rText
+= unicode::formatPercent(GetValue(),
733 Application::GetSettings().GetUILanguageTag());
737 bool SwChannelGrf::GetPresentation(
738 SfxItemPresentation ePres
, MapUnit
/*eCoreUnit*/, MapUnit
/*ePresUnit*/,
739 OUString
&rText
, const IntlWrapper
& /*rIntl*/) const
741 if( SfxItemPresentation::Complete
== ePres
)
746 case RES_GRFATR_CHANNELR
: pId
= STR_CHANNELR
; break;
747 case RES_GRFATR_CHANNELG
: pId
= STR_CHANNELG
; break;
748 case RES_GRFATR_CHANNELB
: pId
= STR_CHANNELB
; break;
752 rText
= SwResId(pId
);
753 else if( rText
.getLength() )
756 else if( rText
.getLength() )
758 rText
+= unicode::formatPercent(GetValue(),
759 Application::GetSettings().GetUILanguageTag());
763 bool SwGammaGrf::GetPresentation(
764 SfxItemPresentation ePres
, MapUnit
/*eCoreUnit*/, MapUnit
/*ePresUnit*/,
765 OUString
&rText
, const IntlWrapper
& /*rIntl*/) const
767 OUStringBuffer aText
;
768 if( SfxItemPresentation::Complete
== ePres
)
769 aText
.append(SwResId(STR_GAMMA
));
770 aText
.append(unicode::formatPercent(GetValue(),
771 Application::GetSettings().GetUILanguageTag()));
772 rText
= aText
.makeStringAndClear();
776 bool SwInvertGrf::GetPresentation(
777 SfxItemPresentation ePres
, MapUnit
/*eCoreUnit*/, MapUnit
/*ePresUnit*/,
778 OUString
&rText
, const IntlWrapper
& /*rIntl*/) const
781 if( SfxItemPresentation::Complete
== ePres
)
783 TranslateId pId
= GetValue() ? STR_INVERT
: STR_INVERT_NOT
;
784 rText
= SwResId(pId
);
789 bool SwTransparencyGrf::GetPresentation(
790 SfxItemPresentation ePres
, MapUnit
/*eCoreUnit*/, MapUnit
/*ePresUnit*/,
791 OUString
&rText
, const IntlWrapper
& /*rIntl*/) const
793 if( SfxItemPresentation::Complete
== ePres
)
794 rText
= SwResId( STR_TRANSPARENCY
);
795 else if( rText
.getLength() )
797 rText
+= unicode::formatPercent(GetValue(),
798 Application::GetSettings().GetUILanguageTag());
802 bool SwDrawModeGrf::GetPresentation(
803 SfxItemPresentation ePres
, MapUnit
/*eCoreUnit*/, MapUnit
/*ePresUnit*/,
804 OUString
&rText
, const IntlWrapper
& /*rIntl*/) const
807 if( SfxItemPresentation::Complete
== ePres
)
810 switch ( GetValue() )
813 case GraphicDrawMode::Greys
: pId
= STR_DRAWMODE_GREY
; break;
814 case GraphicDrawMode::Mono
: pId
= STR_DRAWMODE_BLACKWHITE
; break;
815 case GraphicDrawMode::Watermark
: pId
= STR_DRAWMODE_WATERMARK
; break;
816 default: pId
= STR_DRAWMODE_STD
; break;
818 rText
= SwResId( STR_DRAWMODE
) + SwResId(pId
);
823 bool SwFormatFollowTextFlow::GetPresentation( SfxItemPresentation ePres
,
824 MapUnit
/*eCoreMetric*/,
825 MapUnit
/*ePresMetric*/,
827 const IntlWrapper
& /*rIntl*/ ) const
830 if( SfxItemPresentation::Complete
== ePres
)
832 TranslateId pId
= GetValue() ? STR_FOLLOW_TEXT_FLOW
: STR_DONT_FOLLOW_TEXT_FLOW
;
833 rText
= SwResId(pId
);
838 void SwFormatFollowTextFlow::dumpAsXml(xmlTextWriterPtr pWriter
) const
840 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("SwFormatFollowTextFlow"));
841 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
842 (void)xmlTextWriterWriteAttribute(pWriter
, BAD_CAST("value"), BAD_CAST(OString::boolean(GetValue()).getStr()));
843 (void)xmlTextWriterEndElement(pWriter
);
846 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */