Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / utlui / uiitems.cxx
blobb88751abdddbdb13af72b5671b25126c4f8fe783
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <comphelper/servicehelper.hxx>
21 #include <editeng/itemtype.hxx>
22 #include <tools/UnitConversion.hxx>
23 #include <unosett.hxx>
25 #include <swtypes.hxx>
26 #include <cmdid.h>
27 #include <uiitems.hxx>
29 #include <strings.hrc>
30 #include <unomid.h>
31 #include <numrule.hxx>
33 #include <editeng/eerdll.hxx>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
38 SwPageFootnoteInfoItem::SwPageFootnoteInfoItem( SwPageFootnoteInfo const & rInfo) :
39 SfxPoolItem( FN_PARAM_FTN_INFO ),
40 m_aFootnoteInfo(rInfo)
44 SwPageFootnoteInfoItem::~SwPageFootnoteInfoItem()
48 SwPageFootnoteInfoItem* SwPageFootnoteInfoItem::Clone( SfxItemPool * /*pPool*/ ) const
50 return new SwPageFootnoteInfoItem( *this );
53 bool SwPageFootnoteInfoItem::operator==( const SfxPoolItem& rAttr ) const
55 return SfxPoolItem::operator==(rAttr)
56 && m_aFootnoteInfo == static_cast<const SwPageFootnoteInfoItem&>(rAttr).m_aFootnoteInfo;
59 bool SwPageFootnoteInfoItem::GetPresentation
61 SfxItemPresentation /*ePres*/,
62 MapUnit eCoreUnit,
63 MapUnit ePresUnit,
64 OUString& rText,
65 const IntlWrapper& rIntl
66 ) const
68 const SwTwips nHght = GetPageFootnoteInfo().GetHeight();
69 if ( nHght )
71 rText = SwResId( STR_MAX_FTN_HEIGHT ) + " " +
72 ::GetMetricText( nHght, eCoreUnit, ePresUnit, &rIntl ) + " " +
73 EditResId( ::GetMetricId( ePresUnit ) );
75 return true;
78 bool SwPageFootnoteInfoItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
80 bool bRet = true;
81 switch(nMemberId & ~CONVERT_TWIPS)
83 case MID_FTN_HEIGHT : rVal <<= static_cast<sal_Int32>(convertTwipToMm100(m_aFootnoteInfo.GetHeight()));break;
84 case MID_LINE_WEIGHT : rVal <<= static_cast<sal_Int16>(convertTwipToMm100(m_aFootnoteInfo.GetLineWidth()));break;
85 case MID_LINE_COLOR : rVal <<= m_aFootnoteInfo.GetLineColor();break;
86 case MID_LINE_RELWIDTH :
88 Fraction aTmp( 100, 1 );
89 aTmp *= m_aFootnoteInfo.GetWidth();
90 rVal <<= static_cast<sal_Int8>(static_cast<tools::Long>(aTmp));
92 break;
93 case MID_LINE_ADJUST : rVal <<= static_cast<sal_Int16>(m_aFootnoteInfo.GetAdj());break;//text::HorizontalAdjust
94 case MID_LINE_TEXT_DIST : rVal <<= static_cast<sal_Int32>(convertTwipToMm100(m_aFootnoteInfo.GetTopDist()));break;
95 case MID_LINE_FOOTNOTE_DIST: rVal <<= static_cast<sal_Int32>(convertTwipToMm100(m_aFootnoteInfo.GetBottomDist()));break;
96 case MID_FTN_LINE_STYLE :
98 switch ( m_aFootnoteInfo.GetLineStyle( ) )
100 default:
101 case SvxBorderLineStyle::NONE : rVal <<= sal_Int8(0); break;
102 case SvxBorderLineStyle::SOLID: rVal <<= sal_Int8(1); break;
103 case SvxBorderLineStyle::DOTTED: rVal <<= sal_Int8(2); break;
104 case SvxBorderLineStyle::DASHED: rVal <<= sal_Int8(3); break;
106 break;
108 default:
109 bRet = false;
111 return bRet;
114 bool SwPageFootnoteInfoItem::PutValue(const Any& rVal, sal_uInt8 nMemberId)
116 sal_Int32 nSet32 = 0;
117 Color aColor;
118 bool bRet = true;
119 switch(nMemberId & ~CONVERT_TWIPS)
121 case MID_LINE_COLOR :
122 rVal >>= aColor;
123 m_aFootnoteInfo.SetLineColor(aColor);
124 break;
125 case MID_FTN_HEIGHT:
126 case MID_LINE_TEXT_DIST :
127 case MID_LINE_FOOTNOTE_DIST:
128 rVal >>= nSet32;
129 if(nSet32 < 0)
130 bRet = false;
131 else
133 nSet32 = o3tl::toTwips(nSet32, o3tl::Length::mm100);
134 switch(nMemberId & ~CONVERT_TWIPS)
136 case MID_FTN_HEIGHT: m_aFootnoteInfo.SetHeight(nSet32); break;
137 case MID_LINE_TEXT_DIST: m_aFootnoteInfo.SetTopDist(nSet32);break;
138 case MID_LINE_FOOTNOTE_DIST: m_aFootnoteInfo.SetBottomDist(nSet32);break;
141 break;
142 case MID_LINE_WEIGHT :
144 sal_Int16 nSet = 0;
145 rVal >>= nSet;
146 if(nSet >= 0)
147 m_aFootnoteInfo.SetLineWidth(o3tl::toTwips(nSet, o3tl::Length::mm100));
148 else
149 bRet = false;
151 break;
152 case MID_LINE_RELWIDTH :
154 sal_Int8 nSet = 0;
155 rVal >>= nSet;
156 if(nSet < 0)
157 bRet = false;
158 else
159 m_aFootnoteInfo.SetWidth(Fraction(nSet, 100));
161 break;
162 case MID_LINE_ADJUST :
164 sal_Int16 nSet = 0;
165 rVal >>= nSet;
166 if(nSet >= 0 && nSet < 3) //text::HorizontalAdjust
167 m_aFootnoteInfo.SetAdj(static_cast<css::text::HorizontalAdjust>(nSet));
168 else
169 bRet = false;
171 break;
172 case MID_FTN_LINE_STYLE:
174 SvxBorderLineStyle eStyle = SvxBorderLineStyle::NONE;
175 sal_Int8 nSet = 0;
176 rVal >>= nSet;
177 switch ( nSet )
179 case 1: eStyle = SvxBorderLineStyle::SOLID; break;
180 case 2: eStyle = SvxBorderLineStyle::DOTTED; break;
181 case 3: eStyle = SvxBorderLineStyle::DASHED; break;
182 default: break;
184 m_aFootnoteInfo.SetLineStyle( eStyle );
186 break;
187 default:
188 bRet = false;
190 return bRet;
193 SwPtrItem::SwPtrItem( const sal_uInt16 nId, void* pPtr ) :
194 SfxPoolItem( nId ),
195 m_pMisc(pPtr)
199 // Cloning
201 SwPtrItem* SwPtrItem::Clone( SfxItemPool * /*pPool*/ ) const
203 return new SwPtrItem( *this );
206 bool SwPtrItem::operator==( const SfxPoolItem& rAttr ) const
208 return SfxPoolItem::operator==(rAttr)
209 && m_pMisc == static_cast<const SwPtrItem&>(rAttr).m_pMisc;
212 // SwUINumRuleItem for the NumTabPages of the FormatNumRule/Styleists
214 SwUINumRuleItem::SwUINumRuleItem( const SwNumRule& rRul )
215 : SfxPoolItem( FN_PARAM_ACT_NUMBER ), m_pRule( new SwNumRule( rRul ) )
219 SwUINumRuleItem::SwUINumRuleItem( const SwUINumRuleItem& rItem )
220 : SfxPoolItem( rItem ),
221 m_pRule( new SwNumRule( *rItem.m_pRule ))
225 SwUINumRuleItem::~SwUINumRuleItem()
229 SwUINumRuleItem* SwUINumRuleItem::Clone( SfxItemPool * /*pPool*/ ) const
231 return new SwUINumRuleItem( *this );
234 bool SwUINumRuleItem::operator==( const SfxPoolItem& rAttr ) const
236 return SfxPoolItem::operator==(rAttr)
237 && *m_pRule == *static_cast<const SwUINumRuleItem&>(rAttr).m_pRule;
240 bool SwUINumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
242 uno::Reference< container::XIndexReplace >xRules = new SwXNumberingRules(*m_pRule);
243 rVal <<= xRules;
244 return true;
246 bool SwUINumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
248 uno::Reference< container::XIndexReplace> xRulesRef;
249 if(rVal >>= xRulesRef)
251 auto pSwXRules = dynamic_cast<SwXNumberingRules*>(xRulesRef.get());
252 if(pSwXRules)
254 *m_pRule = *pSwXRules->GetNumRule();
257 return true;
260 SwPaMItem::SwPaMItem( const sal_uInt16 nId, SwPaM* pPaM ) :
261 SfxPoolItem( nId ),
262 m_pPaM(pPaM)
266 SwPaMItem* SwPaMItem::Clone( SfxItemPool * /*pPool*/ ) const
268 return new SwPaMItem( *this );
271 bool SwPaMItem::operator==( const SfxPoolItem& rAttr ) const
273 return SfxPoolItem::operator==(rAttr)
274 && m_pPaM == static_cast<const SwPaMItem&>(rAttr).m_pPaM;
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */