Line data Source code
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 <fmtwrapinfluenceonobjpos.hxx>
21 : #include <unomid.h>
22 : #include <osl/diagnose.h>
23 : #include <libxml/xmlwriter.h>
24 :
25 : using namespace ::com::sun::star;
26 : using namespace ::com::sun::star::uno;
27 :
28 9141 : TYPEINIT1(SwFormatWrapInfluenceOnObjPos, SfxPoolItem);
29 :
30 8482 : SwFormatWrapInfluenceOnObjPos::SwFormatWrapInfluenceOnObjPos( sal_Int16 _nWrapInfluenceOnPosition )
31 : : SfxPoolItem( RES_WRAP_INFLUENCE_ON_OBJPOS ),
32 8482 : mnWrapInfluenceOnPosition( _nWrapInfluenceOnPosition )
33 : {
34 8482 : }
35 :
36 1154 : SwFormatWrapInfluenceOnObjPos::SwFormatWrapInfluenceOnObjPos( const SwFormatWrapInfluenceOnObjPos& _rCpy )
37 : : SfxPoolItem( RES_WRAP_INFLUENCE_ON_OBJPOS ),
38 1154 : mnWrapInfluenceOnPosition( _rCpy.GetWrapInfluenceOnObjPos() )
39 : {
40 1154 : }
41 :
42 19257 : SwFormatWrapInfluenceOnObjPos::~SwFormatWrapInfluenceOnObjPos()
43 : {
44 19257 : }
45 :
46 0 : SwFormatWrapInfluenceOnObjPos& SwFormatWrapInfluenceOnObjPos::operator=( const SwFormatWrapInfluenceOnObjPos& _rSource )
47 : {
48 0 : mnWrapInfluenceOnPosition = _rSource.GetWrapInfluenceOnObjPos();
49 :
50 0 : return *this;
51 : }
52 :
53 1144 : bool SwFormatWrapInfluenceOnObjPos::operator==( const SfxPoolItem& rAttr ) const
54 : {
55 : assert(SfxPoolItem::operator==(rAttr));
56 1144 : return ( mnWrapInfluenceOnPosition ==
57 : static_cast<const SwFormatWrapInfluenceOnObjPos&>(rAttr).
58 1144 : GetWrapInfluenceOnObjPos() );
59 : }
60 :
61 1154 : SfxPoolItem* SwFormatWrapInfluenceOnObjPos::Clone( SfxItemPool * ) const
62 : {
63 1154 : return new SwFormatWrapInfluenceOnObjPos(*this);
64 : }
65 :
66 26 : bool SwFormatWrapInfluenceOnObjPos::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
67 : {
68 26 : nMemberId &= ~CONVERT_TWIPS;
69 26 : bool bRet = true;
70 26 : if( nMemberId == MID_WRAP_INFLUENCE )
71 : {
72 26 : rVal <<= GetWrapInfluenceOnObjPos();
73 : }
74 : else
75 : {
76 : OSL_FAIL( "<SwFormatWrapInfluenceOnObjPos::QueryValue()> - unknown MemberId" );
77 0 : bRet = false;
78 : }
79 26 : return bRet;
80 : }
81 :
82 66 : bool SwFormatWrapInfluenceOnObjPos::PutValue( const Any& rVal, sal_uInt8 nMemberId )
83 : {
84 66 : nMemberId &= ~CONVERT_TWIPS;
85 66 : bool bRet = false;
86 :
87 66 : if( nMemberId == MID_WRAP_INFLUENCE )
88 : {
89 66 : sal_Int16 nNewWrapInfluence = 0;
90 66 : rVal >>= nNewWrapInfluence;
91 : // #i35017# - constant names have changed and <ITERATIVE> has been added
92 131 : if ( nNewWrapInfluence == text::WrapInfluenceOnPosition::ONCE_SUCCESSIVE ||
93 65 : nNewWrapInfluence == text::WrapInfluenceOnPosition::ONCE_CONCURRENT ||
94 0 : nNewWrapInfluence == text::WrapInfluenceOnPosition::ITERATIVE )
95 : {
96 66 : SetWrapInfluenceOnObjPos( nNewWrapInfluence );
97 66 : bRet = true;
98 : }
99 : else
100 : {
101 : OSL_FAIL( "<SwFormatWrapInfluenceOnObjPos::PutValue(..)> - invalid attribute value" );
102 : }
103 : }
104 : else
105 : {
106 : OSL_FAIL( "<SwFormatWrapInfluenceOnObjPos::PutValue(..)> - unknown MemberId" );
107 : }
108 66 : return bRet;
109 : }
110 :
111 66 : void SwFormatWrapInfluenceOnObjPos::SetWrapInfluenceOnObjPos( sal_Int16 _nWrapInfluenceOnPosition )
112 : {
113 : // #i35017# - constant names have changed and consider new value <ITERATIVE>
114 66 : if ( _nWrapInfluenceOnPosition == text::WrapInfluenceOnPosition::ONCE_SUCCESSIVE ||
115 0 : _nWrapInfluenceOnPosition == text::WrapInfluenceOnPosition::ONCE_CONCURRENT ||
116 : _nWrapInfluenceOnPosition == text::WrapInfluenceOnPosition::ITERATIVE )
117 : {
118 66 : mnWrapInfluenceOnPosition = _nWrapInfluenceOnPosition;
119 : }
120 : else
121 : {
122 : OSL_FAIL( "<SwFormatWrapInfluenceOnObjPos::SetWrapInfluenceOnObjPos(..)> - invalid attribute value" );
123 : }
124 66 : }
125 :
126 : // #i35017# - add parameter <_bIterativeAsOnceConcurrent> to control, if
127 : // value <ITERATIVE> has to be treated as <ONCE_CONCURRENT>
128 6513 : sal_Int16 SwFormatWrapInfluenceOnObjPos::GetWrapInfluenceOnObjPos(
129 : const bool _bIterativeAsOnceConcurrent ) const
130 : {
131 6513 : sal_Int16 nWrapInfluenceOnPosition( mnWrapInfluenceOnPosition );
132 :
133 6513 : if ( _bIterativeAsOnceConcurrent &&
134 : nWrapInfluenceOnPosition == text::WrapInfluenceOnPosition::ITERATIVE )
135 : {
136 0 : nWrapInfluenceOnPosition = text::WrapInfluenceOnPosition::ONCE_CONCURRENT;
137 : }
138 :
139 6513 : return nWrapInfluenceOnPosition;
140 : }
141 :
142 0 : void SwFormatWrapInfluenceOnObjPos::dumpAsXml(xmlTextWriterPtr pWriter) const
143 : {
144 0 : xmlTextWriterStartElement(pWriter, BAD_CAST("swFormatWrapInfluenceOnObjPos"));
145 0 : xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
146 0 : xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nWrapInfluenceOnPosition"), BAD_CAST(OString::number(mnWrapInfluenceOnPosition).getStr()));
147 0 : xmlTextWriterEndElement(pWriter);
148 0 : }
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|