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 "hintids.hxx"
21 : #include <swtypes.hxx>
22 : #include "unomid.h"
23 : #include <com/sun/star/style/LineSpacingMode.hpp>
24 : #include <com/sun/star/style/ParagraphAdjust.hpp>
25 : #include <com/sun/star/style/DropCapFormat.hpp>
26 : #include <com/sun/star/style/LineSpacing.hpp>
27 : #include <com/sun/star/text/RelOrientation.hpp>
28 : #include <com/sun/star/text/VertOrientation.hpp>
29 : #include <com/sun/star/text/HorizontalAdjust.hpp>
30 : #include <com/sun/star/text/DocumentStatistic.hpp>
31 : #include <com/sun/star/text/HoriOrientation.hpp>
32 : #include <com/sun/star/text/HoriOrientationFormat.hpp>
33 : #include <com/sun/star/text/NotePrintMode.hpp>
34 : #include <com/sun/star/text/SizeType.hpp>
35 : #include <com/sun/star/text/VertOrientationFormat.hpp>
36 : #include <com/sun/star/text/WrapTextMode.hpp>
37 : #include <unostyle.hxx>
38 : #include <SwStyleNameMapper.hxx>
39 : #include "paratr.hxx"
40 : #include "charfmt.hxx"
41 : #include "cmdid.h"
42 : #include <libxml/xmlwriter.h>
43 :
44 : using namespace ::com::sun::star;
45 :
46 9188 : TYPEINIT2_AUTOFACTORY( SwFormatDrop, SfxPoolItem, SwClient);
47 16450 : TYPEINIT1_AUTOFACTORY( SwRegisterItem, SfxBoolItem);
48 195155 : TYPEINIT1_AUTOFACTORY( SwNumRuleItem, SfxStringItem);
49 9024 : TYPEINIT1_AUTOFACTORY( SwParaConnectBorderItem, SfxBoolItem);
50 :
51 3008 : SwFormatDrop::SwFormatDrop()
52 : : SfxPoolItem( RES_PARATR_DROP ),
53 : SwClient( 0 ),
54 : pDefinedIn( 0 ),
55 : nDistance( 0 ),
56 : nReadFormat( USHRT_MAX ),
57 : nLines( 0 ),
58 : nChars( 0 ),
59 3008 : bWholeWord( false )
60 : {
61 3008 : }
62 :
63 91336 : SwFormatDrop::SwFormatDrop( const SwFormatDrop &rCpy )
64 : : SfxPoolItem( RES_PARATR_DROP ),
65 : SwClient( rCpy.GetRegisteredInNonConst() ),
66 : pDefinedIn( 0 ),
67 91336 : nDistance( rCpy.GetDistance() ),
68 : nReadFormat( rCpy.nReadFormat ),
69 91336 : nLines( rCpy.GetLines() ),
70 91336 : nChars( rCpy.GetChars() ),
71 365344 : bWholeWord( rCpy.GetWholeWord() )
72 : {
73 91336 : }
74 :
75 185739 : SwFormatDrop::~SwFormatDrop()
76 : {
77 185739 : }
78 :
79 6 : void SwFormatDrop::SetCharFormat( SwCharFormat *pNew )
80 : {
81 : // Rewire
82 6 : if ( GetRegisteredIn() )
83 0 : GetRegisteredInNonConst()->Remove( this );
84 6 : if(pNew)
85 6 : pNew->Add( this );
86 6 : nReadFormat = USHRT_MAX;
87 6 : }
88 :
89 12 : void SwFormatDrop::Modify( const SfxPoolItem*, const SfxPoolItem * )
90 : {
91 12 : if( pDefinedIn )
92 : {
93 6 : if( !pDefinedIn->ISA( SwFormat ))
94 6 : pDefinedIn->ModifyNotification( this, this );
95 0 : else if( pDefinedIn->HasWriterListeners() &&
96 0 : !pDefinedIn->IsModifyLocked() )
97 : {
98 : // Notify those who are dependent on the format on our own.
99 : // The format itself wouldn't pass on the notify as it does not get past the check.
100 0 : pDefinedIn->ModifyBroadcast( this, this );
101 : }
102 : }
103 12 : }
104 :
105 4 : bool SwFormatDrop::GetInfo( SfxPoolItem& ) const
106 : {
107 4 : return true; // Continue
108 : }
109 :
110 102 : bool SwFormatDrop::operator==( const SfxPoolItem& rAttr ) const
111 : {
112 : assert(SfxPoolItem::operator==(rAttr));
113 204 : return ( nLines == static_cast<const SwFormatDrop&>(rAttr).GetLines() &&
114 204 : nChars == static_cast<const SwFormatDrop&>(rAttr).GetChars() &&
115 204 : nDistance == static_cast<const SwFormatDrop&>(rAttr).GetDistance() &&
116 204 : bWholeWord == static_cast<const SwFormatDrop&>(rAttr).GetWholeWord() &&
117 291 : GetCharFormat() == static_cast<const SwFormatDrop&>(rAttr).GetCharFormat() &&
118 189 : pDefinedIn == static_cast<const SwFormatDrop&>(rAttr).pDefinedIn );
119 : }
120 :
121 91330 : SfxPoolItem* SwFormatDrop::Clone( SfxItemPool* ) const
122 : {
123 91330 : return new SwFormatDrop( *this );
124 : }
125 :
126 37 : bool SwFormatDrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
127 : {
128 37 : switch(nMemberId&~CONVERT_TWIPS)
129 : {
130 0 : case MID_DROPCAP_LINES : rVal <<= (sal_Int16)nLines; break;
131 0 : case MID_DROPCAP_COUNT : rVal <<= (sal_Int16)nChars; break;
132 0 : case MID_DROPCAP_DISTANCE : rVal <<= (sal_Int16) convertTwipToMm100(nDistance); break;
133 : case MID_DROPCAP_FORMAT:
134 : {
135 11 : style::DropCapFormat aDrop;
136 11 : aDrop.Lines = nLines ;
137 11 : aDrop.Count = nChars ;
138 11 : aDrop.Distance = convertTwipToMm100(nDistance);
139 11 : rVal.setValue(&aDrop, ::cppu::UnoType<style::DropCapFormat>::get());
140 : }
141 11 : break;
142 : case MID_DROPCAP_WHOLE_WORD:
143 11 : rVal <<= bWholeWord;
144 11 : break;
145 : case MID_DROPCAP_CHAR_STYLE_NAME :
146 : {
147 15 : OUString sName;
148 15 : if(GetCharFormat())
149 : sName = SwStyleNameMapper::GetProgName(
150 8 : GetCharFormat()->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
151 15 : rVal <<= sName;
152 : }
153 15 : break;
154 : }
155 37 : return true;
156 : }
157 :
158 22 : bool SwFormatDrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
159 : {
160 22 : switch(nMemberId&~CONVERT_TWIPS)
161 : {
162 : case MID_DROPCAP_LINES :
163 : {
164 0 : sal_Int8 nTemp = 0;
165 0 : rVal >>= nTemp;
166 0 : if(nTemp >=1 && nTemp < 0x7f)
167 0 : nLines = (sal_uInt8)nTemp;
168 : }
169 0 : break;
170 : case MID_DROPCAP_COUNT :
171 : {
172 0 : sal_Int16 nTemp = 0;
173 0 : rVal >>= nTemp;
174 0 : if(nTemp >=1 && nTemp < 0x7f)
175 0 : nChars = (sal_uInt8)nTemp;
176 : }
177 0 : break;
178 : case MID_DROPCAP_DISTANCE :
179 : {
180 0 : sal_Int16 nVal = 0;
181 0 : if ( rVal >>= nVal )
182 0 : nDistance = (sal_Int16) convertMm100ToTwip((sal_Int32)nVal);
183 : else
184 0 : return false;
185 0 : break;
186 : }
187 : case MID_DROPCAP_FORMAT:
188 : {
189 11 : if(rVal.getValueType() == ::cppu::UnoType<style::DropCapFormat>::get())
190 : {
191 11 : const style::DropCapFormat* pDrop = static_cast<const style::DropCapFormat*>(rVal.getValue());
192 11 : nLines = pDrop->Lines;
193 11 : nChars = pDrop->Count;
194 11 : nDistance = convertMm100ToTwip(pDrop->Distance);
195 : }
196 : else {
197 : }
198 : }
199 11 : break;
200 : case MID_DROPCAP_WHOLE_WORD:
201 11 : bWholeWord = *static_cast<sal_Bool const *>(rVal.getValue());
202 11 : break;
203 : case MID_DROPCAP_CHAR_STYLE_NAME :
204 : OSL_FAIL("char format cannot be set in PutValue()!");
205 0 : break;
206 : }
207 22 : return true;
208 : }
209 :
210 39403 : SfxPoolItem* SwRegisterItem::Clone( SfxItemPool * ) const
211 : {
212 39403 : return new SwRegisterItem( *this );
213 : }
214 :
215 3079 : SfxPoolItem* SwNumRuleItem::Clone( SfxItemPool * ) const
216 : {
217 3079 : return new SwNumRuleItem( *this );
218 : }
219 27858 : bool SwNumRuleItem::operator==( const SfxPoolItem& rAttr ) const
220 : {
221 : assert(SfxPoolItem::operator==(rAttr));
222 :
223 27858 : return GetValue() == static_cast<const SwNumRuleItem&>(rAttr).GetValue();
224 : }
225 :
226 1153 : bool SwNumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 ) const
227 : {
228 1153 : OUString sRet = SwStyleNameMapper::GetProgName(GetValue(), nsSwGetPoolIdFromName::GET_POOLID_NUMRULE );
229 1153 : rVal <<= sRet;
230 1153 : return true;
231 : }
232 :
233 455 : bool SwNumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 )
234 : {
235 455 : OUString uName;
236 455 : rVal >>= uName;
237 455 : SetValue(SwStyleNameMapper::GetUIName(uName, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE));
238 455 : return true;
239 : }
240 :
241 0 : void SwNumRuleItem::dumpAsXml(xmlTextWriterPtr pWriter) const
242 : {
243 0 : xmlTextWriterStartElement(pWriter, BAD_CAST("swNumRuleItem"));
244 0 : xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
245 0 : xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(GetValue().toUtf8().getStr()));
246 0 : xmlTextWriterEndElement(pWriter);
247 0 : }
248 :
249 10 : SfxPoolItem* SwParaConnectBorderItem::Clone( SfxItemPool * ) const
250 : {
251 10 : return new SwParaConnectBorderItem( *this );
252 177 : }
253 :
254 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|