xref: /aoo41x/main/sw/source/core/para/paratr.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include "hintids.hxx"
28 #include <swtypes.hxx>
29 #include "unomid.h"
30 #include <com/sun/star/style/LineSpacingMode.hpp>
31 #include <com/sun/star/style/ParagraphAdjust.hpp>
32 #include <com/sun/star/style/DropCapFormat.hpp>
33 #include <com/sun/star/style/LineSpacing.hpp>
34 #include <com/sun/star/text/RelOrientation.hpp>
35 #include <com/sun/star/text/VertOrientation.hpp>
36 #include <com/sun/star/text/HorizontalAdjust.hpp>
37 #include <com/sun/star/text/DocumentStatistic.hpp>
38 #include <com/sun/star/text/HoriOrientation.hpp>
39 #include <com/sun/star/text/HoriOrientationFormat.hpp>
40 #include <com/sun/star/text/NotePrintMode.hpp>
41 #include <com/sun/star/text/SizeType.hpp>
42 #include <com/sun/star/text/VertOrientationFormat.hpp>
43 #include <com/sun/star/text/WrapTextMode.hpp>
44 #include <unostyle.hxx>
45 #include <SwStyleNameMapper.hxx>
46 #include "errhdl.hxx"
47 #include "paratr.hxx"
48 #include "charfmt.hxx"
49 #include "cmdid.h"
50 
51 using namespace ::com::sun::star;
52 
53 TYPEINIT2_AUTOFACTORY( SwFmtDrop, SfxPoolItem, SwClient);
54 TYPEINIT1_AUTOFACTORY( SwRegisterItem, SfxBoolItem);
55 TYPEINIT1_AUTOFACTORY( SwNumRuleItem, SfxStringItem);
56 TYPEINIT1_AUTOFACTORY( SwParaConnectBorderItem, SfxBoolItem);
57 
58 /*************************************************************************
59 |*    Beschreibung		Methoden von SwFmtDrop
60 |*    Ersterstellung	MS  19.02.91
61 |*    Letzte Aenderung	JP 08.08.94
62 *************************************************************************/
63 
64 
65 
SwFmtDrop()66 SwFmtDrop::SwFmtDrop()
67 	: SfxPoolItem( RES_PARATR_DROP ),
68 	SwClient( 0 ),
69 	pDefinedIn( 0 ),
70 	nDistance( 0 ),
71 	nReadFmt( USHRT_MAX ),
72 	nLines( 0 ),
73 	nChars( 0 ),
74 	bWholeWord( sal_False )
75 {
76 }
77 
78 
79 
SwFmtDrop(const SwFmtDrop & rCpy)80 SwFmtDrop::SwFmtDrop( const SwFmtDrop &rCpy )
81 	: SfxPoolItem( RES_PARATR_DROP ),
82 	SwClient( rCpy.GetRegisteredInNonConst() ),
83 	pDefinedIn( 0 ),
84 	nDistance( rCpy.GetDistance() ),
85 	nReadFmt( rCpy.nReadFmt ),
86 	nLines( rCpy.GetLines() ),
87 	nChars( rCpy.GetChars() ),
88 	bWholeWord( rCpy.GetWholeWord() )
89 {
90 }
91 
92 
93 
~SwFmtDrop()94 SwFmtDrop::~SwFmtDrop()
95 {
96 }
97 
98 
99 
SetCharFmt(SwCharFmt * pNew)100 void SwFmtDrop::SetCharFmt( SwCharFmt *pNew )
101 {
102 	//Ummelden
103 	if ( GetRegisteredIn() )
104 		GetRegisteredInNonConst()->Remove( this );
105     if(pNew)
106         pNew->Add( this );
107 	nReadFmt = USHRT_MAX;
108 }
109 
110 
111 
Modify(const SfxPoolItem *,const SfxPoolItem *)112 void SwFmtDrop::Modify( const SfxPoolItem*, const SfxPoolItem * )
113 {
114 	if( pDefinedIn )
115 	{
116 		if( !pDefinedIn->ISA( SwFmt ))
117 			pDefinedIn->ModifyNotification( this, this );
118 		else if( pDefinedIn->GetDepends() &&
119 				!pDefinedIn->IsModifyLocked() )
120 		{
121 			// selbst den Abhaengigen vom Format bescheid sagen. Das
122 			// Format selbst wuerde es nicht weitergeben, weil es ueber
123 			// die Abpruefung nicht hinauskommt.
124             pDefinedIn->ModifyBroadcast( this, this );
125 		}
126 	}
127 }
128 
GetInfo(SfxPoolItem &) const129 sal_Bool SwFmtDrop::GetInfo( SfxPoolItem& ) const
130 {
131 	return sal_True;    // weiter
132 }
133 
operator ==(const SfxPoolItem & rAttr) const134 int SwFmtDrop::operator==( const SfxPoolItem& rAttr ) const
135 {
136 	ASSERT( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
137 	return ( nLines == ((SwFmtDrop&)rAttr).GetLines() &&
138 			 nChars == ((SwFmtDrop&)rAttr).GetChars() &&
139 			 nDistance ==  ((SwFmtDrop&)rAttr).GetDistance() &&
140 			 bWholeWord == ((SwFmtDrop&)rAttr).GetWholeWord() &&
141 			 GetCharFmt() == ((SwFmtDrop&)rAttr).GetCharFmt() &&
142 			 pDefinedIn == ((SwFmtDrop&)rAttr).pDefinedIn );
143 }
144 
Clone(SfxItemPool *) const145 SfxPoolItem* SwFmtDrop::Clone( SfxItemPool* ) const
146 {
147 	return new SwFmtDrop( *this );
148 }
149 
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const150 sal_Bool SwFmtDrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
151 {
152 	switch(nMemberId&~CONVERT_TWIPS)
153 	{
154         case MID_DROPCAP_LINES : rVal <<= (sal_Int16)nLines; break;
155         case MID_DROPCAP_COUNT : rVal <<= (sal_Int16)nChars; break;
156         case MID_DROPCAP_DISTANCE : rVal <<= (sal_Int16) TWIP_TO_MM100_UNSIGNED(nDistance); break;
157 		case MID_DROPCAP_FORMAT:
158 		{
159 		 	style::DropCapFormat aDrop;
160 			aDrop.Lines	= nLines   ;
161 			aDrop.Count	= nChars   ;
162 			aDrop.Distance	= TWIP_TO_MM100_UNSIGNED(nDistance);
163 			rVal.setValue(&aDrop, ::getCppuType((const style::DropCapFormat*)0));
164 		}
165 		break;
166 		case MID_DROPCAP_WHOLE_WORD:
167 			rVal.setValue(&bWholeWord, ::getBooleanCppuType());
168 		break;
169 		case MID_DROPCAP_CHAR_STYLE_NAME :
170 		{
171 			rtl::OUString sName;
172 			if(GetCharFmt())
173 				sName = SwStyleNameMapper::GetProgName(
174 						GetCharFmt()->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
175 			rVal <<= sName;
176 		}
177 		break;
178 	}
179 	return sal_True;
180 }
181 
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)182 sal_Bool SwFmtDrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
183 {
184 	switch(nMemberId&~CONVERT_TWIPS)
185 	{
186         case MID_DROPCAP_LINES :
187         {
188             sal_Int8 nTemp = 0;
189             rVal >>= nTemp;
190             if(nTemp >=1 && nTemp < 0x7f)
191                 nLines = (sal_uInt8)nTemp;
192         }
193         break;
194         case MID_DROPCAP_COUNT :
195         {
196             sal_Int16 nTemp = 0;
197             rVal >>= nTemp;
198             if(nTemp >=1 && nTemp < 0x7f)
199                 nChars = (sal_uInt8)nTemp;
200         }
201         break;
202         case MID_DROPCAP_DISTANCE :
203         {
204             sal_Int16 nVal = 0;
205             if ( rVal >>= nVal )
206                 nDistance = (sal_Int16) MM100_TO_TWIP((sal_Int32)nVal);
207             else
208                 return sal_False;
209             break;
210         }
211 		case MID_DROPCAP_FORMAT:
212 		{
213 			if(rVal.getValueType()  == ::getCppuType((const style::DropCapFormat*)0))
214 			{
215 				const style::DropCapFormat* pDrop = (const style::DropCapFormat*)rVal.getValue();
216 				nLines 		= pDrop->Lines;
217 				nChars 		= pDrop->Count;
218 				nDistance 	= MM100_TO_TWIP(pDrop->Distance);
219 			}
220 			else {
221 				//exception( wrong_type)
222 				;
223             }
224 		}
225 		break;
226 		case MID_DROPCAP_WHOLE_WORD:
227 			bWholeWord = *(sal_Bool*)rVal.getValue();
228 		break;
229 		case MID_DROPCAP_CHAR_STYLE_NAME :
230 			DBG_ERROR("char format cannot be set in PutValue()!");
231 		break;
232 	}
233 	return sal_True;
234 }
235 
236 // class SwRegisterItem -------------------------------------------------
237 
238 
Clone(SfxItemPool *) const239 SfxPoolItem* SwRegisterItem::Clone( SfxItemPool * ) const
240 {
241 	return new SwRegisterItem( *this );
242 }
243 
244 // class SwNumRuleItem -------------------------------------------------
Clone(SfxItemPool *) const245 SfxPoolItem* SwNumRuleItem::Clone( SfxItemPool * ) const
246 {
247 	return new SwNumRuleItem( *this );
248 }
operator ==(const SfxPoolItem & rAttr) const249 int SwNumRuleItem::operator==( const SfxPoolItem& rAttr ) const
250 {
251 	ASSERT( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
252     // --> OD 2008-03-04 #refactorlists# - removed <pDefinedIn>
253     return GetValue() == ((SwNumRuleItem&)rAttr).GetValue();
254     // <--
255 }
256 /* -----------------------------27.06.00 11:05--------------------------------
257 
258  ---------------------------------------------------------------------------*/
QueryValue(uno::Any & rVal,sal_uInt8) const259 sal_Bool    SwNumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 ) const
260 {
261 	rtl::OUString sRet = SwStyleNameMapper::GetProgName(GetValue(), nsSwGetPoolIdFromName::GET_POOLID_NUMRULE );
262 	rVal <<= sRet;
263 	return sal_True;
264 }
265 /* -----------------------------27.06.00 11:05--------------------------------
266 
267  ---------------------------------------------------------------------------*/
PutValue(const uno::Any & rVal,sal_uInt8)268 sal_Bool    SwNumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 )
269 {
270 	rtl::OUString uName;
271 	rVal >>= uName;
272 	SetValue(SwStyleNameMapper::GetUIName(uName, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE));
273 	return sal_True;
274 }
275 /* -----------------19.05.2003 10:44-----------------
276 
277  --------------------------------------------------*/
Clone(SfxItemPool *) const278 SfxPoolItem* SwParaConnectBorderItem::Clone( SfxItemPool * ) const
279 {
280     return new SwParaConnectBorderItem( *this );
281 }
282 
283 
284 
285