xref: /trunk/main/sw/source/core/para/paratr.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include "hintids.hxx"
32 #include <swtypes.hxx>
33 #include "unomid.h"
34 #include <com/sun/star/style/LineSpacingMode.hpp>
35 #include <com/sun/star/style/ParagraphAdjust.hpp>
36 #include <com/sun/star/style/DropCapFormat.hpp>
37 #include <com/sun/star/style/LineSpacing.hpp>
38 #include <com/sun/star/text/RelOrientation.hpp>
39 #include <com/sun/star/text/VertOrientation.hpp>
40 #include <com/sun/star/text/HorizontalAdjust.hpp>
41 #include <com/sun/star/text/DocumentStatistic.hpp>
42 #include <com/sun/star/text/HoriOrientation.hpp>
43 #include <com/sun/star/text/HoriOrientationFormat.hpp>
44 #include <com/sun/star/text/NotePrintMode.hpp>
45 #include <com/sun/star/text/SizeType.hpp>
46 #include <com/sun/star/text/VertOrientationFormat.hpp>
47 #include <com/sun/star/text/WrapTextMode.hpp>
48 #include <unostyle.hxx>
49 #include <SwStyleNameMapper.hxx>
50 #include "errhdl.hxx"
51 #include "paratr.hxx"
52 #include "charfmt.hxx"
53 #include "cmdid.h"
54 
55 using namespace ::com::sun::star;
56 
57 TYPEINIT2_AUTOFACTORY( SwFmtDrop, SfxPoolItem, SwClient);
58 TYPEINIT1_AUTOFACTORY( SwRegisterItem, SfxBoolItem);
59 TYPEINIT1_AUTOFACTORY( SwNumRuleItem, SfxStringItem);
60 TYPEINIT1_AUTOFACTORY( SwParaConnectBorderItem, SfxBoolItem);
61 
62 /*************************************************************************
63 |*    Beschreibung		Methoden von SwFmtDrop
64 |*    Ersterstellung	MS  19.02.91
65 |*    Letzte Aenderung	JP 08.08.94
66 *************************************************************************/
67 
68 
69 
70 SwFmtDrop::SwFmtDrop()
71 	: SfxPoolItem( RES_PARATR_DROP ),
72 	SwClient( 0 ),
73 	pDefinedIn( 0 ),
74 	nDistance( 0 ),
75 	nReadFmt( USHRT_MAX ),
76 	nLines( 0 ),
77 	nChars( 0 ),
78 	bWholeWord( sal_False )
79 {
80 }
81 
82 
83 
84 SwFmtDrop::SwFmtDrop( const SwFmtDrop &rCpy )
85 	: SfxPoolItem( RES_PARATR_DROP ),
86 	SwClient( rCpy.GetRegisteredInNonConst() ),
87 	pDefinedIn( 0 ),
88 	nDistance( rCpy.GetDistance() ),
89 	nReadFmt( rCpy.nReadFmt ),
90 	nLines( rCpy.GetLines() ),
91 	nChars( rCpy.GetChars() ),
92 	bWholeWord( rCpy.GetWholeWord() )
93 {
94 }
95 
96 
97 
98 SwFmtDrop::~SwFmtDrop()
99 {
100 }
101 
102 
103 
104 void SwFmtDrop::SetCharFmt( SwCharFmt *pNew )
105 {
106 	//Ummelden
107 	if ( GetRegisteredIn() )
108 		GetRegisteredInNonConst()->Remove( this );
109     if(pNew)
110         pNew->Add( this );
111 	nReadFmt = USHRT_MAX;
112 }
113 
114 
115 
116 void SwFmtDrop::Modify( const SfxPoolItem*, const SfxPoolItem * )
117 {
118 	if( pDefinedIn )
119 	{
120 		if( !pDefinedIn->ISA( SwFmt ))
121 			pDefinedIn->ModifyNotification( this, this );
122 		else if( pDefinedIn->GetDepends() &&
123 				!pDefinedIn->IsModifyLocked() )
124 		{
125 			// selbst den Abhaengigen vom Format bescheid sagen. Das
126 			// Format selbst wuerde es nicht weitergeben, weil es ueber
127 			// die Abpruefung nicht hinauskommt.
128             pDefinedIn->ModifyBroadcast( this, this );
129 		}
130 	}
131 }
132 
133 sal_Bool SwFmtDrop::GetInfo( SfxPoolItem& ) const
134 {
135 	return sal_True;    // weiter
136 }
137 
138 int SwFmtDrop::operator==( const SfxPoolItem& rAttr ) const
139 {
140 	ASSERT( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
141 	return ( nLines == ((SwFmtDrop&)rAttr).GetLines() &&
142 			 nChars == ((SwFmtDrop&)rAttr).GetChars() &&
143 			 nDistance ==  ((SwFmtDrop&)rAttr).GetDistance() &&
144 			 bWholeWord == ((SwFmtDrop&)rAttr).GetWholeWord() &&
145 			 GetCharFmt() == ((SwFmtDrop&)rAttr).GetCharFmt() &&
146 			 pDefinedIn == ((SwFmtDrop&)rAttr).pDefinedIn );
147 }
148 
149 SfxPoolItem* SwFmtDrop::Clone( SfxItemPool* ) const
150 {
151 	return new SwFmtDrop( *this );
152 }
153 
154 sal_Bool SwFmtDrop::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
155 {
156 	switch(nMemberId&~CONVERT_TWIPS)
157 	{
158         case MID_DROPCAP_LINES : rVal <<= (sal_Int16)nLines; break;
159         case MID_DROPCAP_COUNT : rVal <<= (sal_Int16)nChars; break;
160         case MID_DROPCAP_DISTANCE : rVal <<= (sal_Int16) TWIP_TO_MM100_UNSIGNED(nDistance); break;
161 		case MID_DROPCAP_FORMAT:
162 		{
163 		 	style::DropCapFormat aDrop;
164 			aDrop.Lines	= nLines   ;
165 			aDrop.Count	= nChars   ;
166 			aDrop.Distance	= TWIP_TO_MM100_UNSIGNED(nDistance);
167 			rVal.setValue(&aDrop, ::getCppuType((const style::DropCapFormat*)0));
168 		}
169 		break;
170 		case MID_DROPCAP_WHOLE_WORD:
171 			rVal.setValue(&bWholeWord, ::getBooleanCppuType());
172 		break;
173 		case MID_DROPCAP_CHAR_STYLE_NAME :
174 		{
175 			rtl::OUString sName;
176 			if(GetCharFmt())
177 				sName = SwStyleNameMapper::GetProgName(
178 						GetCharFmt()->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
179 			rVal <<= sName;
180 		}
181 		break;
182 	}
183 	return sal_True;
184 }
185 
186 sal_Bool SwFmtDrop::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
187 {
188 	switch(nMemberId&~CONVERT_TWIPS)
189 	{
190         case MID_DROPCAP_LINES :
191         {
192             sal_Int8 nTemp = 0;
193             rVal >>= nTemp;
194             if(nTemp >=1 && nTemp < 0x7f)
195                 nLines = (sal_uInt8)nTemp;
196         }
197         break;
198         case MID_DROPCAP_COUNT :
199         {
200             sal_Int16 nTemp = 0;
201             rVal >>= nTemp;
202             if(nTemp >=1 && nTemp < 0x7f)
203                 nChars = (sal_uInt8)nTemp;
204         }
205         break;
206         case MID_DROPCAP_DISTANCE :
207         {
208             sal_Int16 nVal = 0;
209             if ( rVal >>= nVal )
210                 nDistance = (sal_Int16) MM100_TO_TWIP((sal_Int32)nVal);
211             else
212                 return sal_False;
213             break;
214         }
215 		case MID_DROPCAP_FORMAT:
216 		{
217 			if(rVal.getValueType()  == ::getCppuType((const style::DropCapFormat*)0))
218 			{
219 				const style::DropCapFormat* pDrop = (const style::DropCapFormat*)rVal.getValue();
220 				nLines 		= pDrop->Lines;
221 				nChars 		= pDrop->Count;
222 				nDistance 	= MM100_TO_TWIP(pDrop->Distance);
223 			}
224 			else {
225 				//exception( wrong_type)
226 				;
227             }
228 		}
229 		break;
230 		case MID_DROPCAP_WHOLE_WORD:
231 			bWholeWord = *(sal_Bool*)rVal.getValue();
232 		break;
233 		case MID_DROPCAP_CHAR_STYLE_NAME :
234 			DBG_ERROR("char format cannot be set in PutValue()!");
235 		break;
236 	}
237 	return sal_True;
238 }
239 
240 // class SwRegisterItem -------------------------------------------------
241 
242 
243 SfxPoolItem* SwRegisterItem::Clone( SfxItemPool * ) const
244 {
245 	return new SwRegisterItem( *this );
246 }
247 
248 // class SwNumRuleItem -------------------------------------------------
249 SfxPoolItem* SwNumRuleItem::Clone( SfxItemPool * ) const
250 {
251 	return new SwNumRuleItem( *this );
252 }
253 int SwNumRuleItem::operator==( const SfxPoolItem& rAttr ) const
254 {
255 	ASSERT( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
256     // --> OD 2008-03-04 #refactorlists# - removed <pDefinedIn>
257     return GetValue() == ((SwNumRuleItem&)rAttr).GetValue();
258     // <--
259 }
260 /* -----------------------------27.06.00 11:05--------------------------------
261 
262  ---------------------------------------------------------------------------*/
263 sal_Bool    SwNumRuleItem::QueryValue( uno::Any& rVal, sal_uInt8 ) const
264 {
265 	rtl::OUString sRet = SwStyleNameMapper::GetProgName(GetValue(), nsSwGetPoolIdFromName::GET_POOLID_NUMRULE );
266 	rVal <<= sRet;
267 	return sal_True;
268 }
269 /* -----------------------------27.06.00 11:05--------------------------------
270 
271  ---------------------------------------------------------------------------*/
272 sal_Bool    SwNumRuleItem::PutValue( const uno::Any& rVal, sal_uInt8 )
273 {
274 	rtl::OUString uName;
275 	rVal >>= uName;
276 	SetValue(SwStyleNameMapper::GetUIName(uName, nsSwGetPoolIdFromName::GET_POOLID_NUMRULE));
277 	return sal_True;
278 }
279 /* -----------------19.05.2003 10:44-----------------
280 
281  --------------------------------------------------*/
282 SfxPoolItem* SwParaConnectBorderItem::Clone( SfxItemPool * ) const
283 {
284     return new SwParaConnectBorderItem( *this );
285 }
286 
287 
288 
289