1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir #include "rtattributehandler.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #ifndef _SVX_SVXIDS_HRC
29cdf0e10cSrcweir #include <svx/svxids.hrc>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include <editeng/eeitem.hxx>
32cdf0e10cSrcweir #include <svl/itemset.hxx>
33cdf0e10cSrcweir #include <svl/itempool.hxx>
34cdf0e10cSrcweir #include <tools/mapunit.hxx>
35cdf0e10cSrcweir #include <vcl/mapmod.hxx>
36cdf0e10cSrcweir #include <vcl/outdev.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #define ITEMID_ADJUST       EE_PARA_JUST
39cdf0e10cSrcweir #include <editeng/adjitem.hxx>
40cdf0e10cSrcweir #define ITEMID_WEIGHT       EE_CHAR_WEIGHT
41cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
42cdf0e10cSrcweir #define ITEMID_ESCAPEMENT   EE_CHAR_ESCAPEMENT
43cdf0e10cSrcweir #include <editeng/escpitem.hxx>
44cdf0e10cSrcweir #define ITEMID_LINESPACING  EE_PARA_SBL
45cdf0e10cSrcweir #include <editeng/lspcitem.hxx>
46cdf0e10cSrcweir #define ITEMID_FONTHEIGHT   EE_CHAR_FONTHEIGHT
47cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
48cdf0e10cSrcweir #define ITEMID_FRAMEDIR     EE_PARA_WRITINGDIR
49cdf0e10cSrcweir #include <editeng/frmdiritem.hxx>
50cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //........................................................................
53cdf0e10cSrcweir namespace frm
54cdf0e10cSrcweir {
55cdf0e10cSrcweir //........................................................................
56cdf0e10cSrcweir     //====================================================================
57cdf0e10cSrcweir 	//= ReferenceBase
58cdf0e10cSrcweir 	//====================================================================
59cdf0e10cSrcweir 	//--------------------------------------------------------------------
acquire()60cdf0e10cSrcweir     oslInterlockedCount SAL_CALL ReferenceBase::acquire()
61cdf0e10cSrcweir     {
62cdf0e10cSrcweir         return osl_incrementInterlockedCount( &m_refCount );
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	//--------------------------------------------------------------------
release()66cdf0e10cSrcweir 	oslInterlockedCount SAL_CALL ReferenceBase::release()
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         return osl_decrementInterlockedCount( &m_refCount );
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	//--------------------------------------------------------------------
~ReferenceBase()72cdf0e10cSrcweir     ReferenceBase::~ReferenceBase()
73cdf0e10cSrcweir     {
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     //====================================================================
77cdf0e10cSrcweir 	//= AttributeHandler
78cdf0e10cSrcweir 	//====================================================================
79cdf0e10cSrcweir 	//--------------------------------------------------------------------
AttributeHandler(AttributeId _nAttributeId,WhichId _nWhichId)80cdf0e10cSrcweir     AttributeHandler::AttributeHandler( AttributeId _nAttributeId, WhichId _nWhichId )
81cdf0e10cSrcweir         :m_nAttribute( _nAttributeId )
82cdf0e10cSrcweir         ,m_nWhich    ( _nWhichId     )
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	//--------------------------------------------------------------------
~AttributeHandler()87cdf0e10cSrcweir     AttributeHandler::~AttributeHandler()
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	//--------------------------------------------------------------------
acquire()92cdf0e10cSrcweir 	oslInterlockedCount SAL_CALL AttributeHandler::acquire()
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         return ReferenceBase::acquire();
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	//--------------------------------------------------------------------
release()98cdf0e10cSrcweir 	oslInterlockedCount SAL_CALL AttributeHandler::release()
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         return ReferenceBase::release();
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	//--------------------------------------------------------------------
getAttributeId() const104cdf0e10cSrcweir     AttributeId AttributeHandler::getAttributeId( ) const
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         return getAttribute();
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	//--------------------------------------------------------------------
implGetCheckState(const SfxPoolItem &) const110cdf0e10cSrcweir     AttributeCheckState AttributeHandler::implGetCheckState( const SfxPoolItem& /*_rItem*/ ) const
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         OSL_ENSURE( sal_False, "AttributeHandler::implGetCheckState: not to be called!" );
113cdf0e10cSrcweir         return eIndetermined;
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	//--------------------------------------------------------------------
putItemForScript(SfxItemSet & _rAttribs,const SfxPoolItem & _rItem,ScriptType _nForScriptType) const117cdf0e10cSrcweir     void AttributeHandler::putItemForScript( SfxItemSet& _rAttribs, const SfxPoolItem& _rItem, ScriptType _nForScriptType ) const
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         SvxScriptSetItem aSetItem( (WhichId)getAttributeId(), *_rAttribs.GetPool() );
120cdf0e10cSrcweir         aSetItem.PutItemForScriptType( _nForScriptType, _rItem );
121cdf0e10cSrcweir         _rAttribs.Put( aSetItem.GetItemSet(), sal_False );
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	//--------------------------------------------------------------------
getCheckState(const SfxItemSet & _rAttribs) const125cdf0e10cSrcweir     AttributeCheckState AttributeHandler::getCheckState( const SfxItemSet& _rAttribs ) const
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         AttributeCheckState eSimpleState( eIndetermined );
128cdf0e10cSrcweir         const SfxPoolItem* pItem = _rAttribs.GetItem( getWhich() );
129cdf0e10cSrcweir         if ( pItem )
130cdf0e10cSrcweir             eSimpleState = implGetCheckState( *pItem );
131cdf0e10cSrcweir         return eSimpleState;
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	//--------------------------------------------------------------------
getState(const SfxItemSet & _rAttribs) const135cdf0e10cSrcweir     AttributeState AttributeHandler::getState( const SfxItemSet& _rAttribs ) const
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         AttributeState aState( eIndetermined );
138cdf0e10cSrcweir         aState.eSimpleState = getCheckState( _rAttribs );
139cdf0e10cSrcweir         return aState;
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     //====================================================================
143cdf0e10cSrcweir 	//= AttributeHandlerFactory
144cdf0e10cSrcweir 	//====================================================================
145cdf0e10cSrcweir 	//--------------------------------------------------------------------
146cdf0e10cSrcweir     namespace
147cdf0e10cSrcweir     {
lcl_implGetWhich(const SfxItemPool & _rPool,AttributeId _nAttributeId)148cdf0e10cSrcweir         static WhichId lcl_implGetWhich( const SfxItemPool& _rPool, AttributeId _nAttributeId )
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir             WhichId nWhich = 0;
151cdf0e10cSrcweir             switch ( _nAttributeId )
152cdf0e10cSrcweir             {
153cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_FONTHEIGHT:nWhich = EE_CHAR_FONTHEIGHT;break;
154cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_FONT:      nWhich = EE_CHAR_FONTINFO;  break;
155cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_LANGUAGE:  nWhich = EE_CHAR_LANGUAGE;  break;
156cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_POSTURE:   nWhich = EE_CHAR_ITALIC;    break;
157cdf0e10cSrcweir             case SID_ATTR_CHAR_LATIN_WEIGHT:    nWhich = EE_CHAR_WEIGHT;    break;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir             default:
160cdf0e10cSrcweir                 nWhich = _rPool.GetWhich( (SfxSlotId)_nAttributeId );
161cdf0e10cSrcweir             }
162cdf0e10cSrcweir             return nWhich;
163cdf0e10cSrcweir         }
164cdf0e10cSrcweir     }
165cdf0e10cSrcweir 	//--------------------------------------------------------------------
getHandlerFor(AttributeId _nAttributeId,const SfxItemPool & _rEditEnginePool)166cdf0e10cSrcweir     ::rtl::Reference< IAttributeHandler > AttributeHandlerFactory::getHandlerFor( AttributeId _nAttributeId, const SfxItemPool& _rEditEnginePool )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir         ::rtl::Reference< IAttributeHandler > pReturn;
169cdf0e10cSrcweir         switch ( _nAttributeId )
170cdf0e10cSrcweir         {
171cdf0e10cSrcweir         case SID_ATTR_PARA_ADJUST_LEFT  :
172cdf0e10cSrcweir 		case SID_ATTR_PARA_ADJUST_CENTER:
173cdf0e10cSrcweir 		case SID_ATTR_PARA_ADJUST_RIGHT :
174cdf0e10cSrcweir 		case SID_ATTR_PARA_ADJUST_BLOCK :
175cdf0e10cSrcweir             pReturn = new ParaAlignmentHandler( _nAttributeId );
176cdf0e10cSrcweir             break;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         case SID_ATTR_PARA_LINESPACE_10:
179cdf0e10cSrcweir 	    case SID_ATTR_PARA_LINESPACE_15:
180cdf0e10cSrcweir 		case SID_ATTR_PARA_LINESPACE_20:
181cdf0e10cSrcweir             pReturn = new LineSpacingHandler( _nAttributeId );
182cdf0e10cSrcweir             break;
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         case SID_SET_SUPER_SCRIPT:
185cdf0e10cSrcweir         case SID_SET_SUB_SCRIPT:
186cdf0e10cSrcweir             pReturn = new EscapementHandler( _nAttributeId );
187cdf0e10cSrcweir             break;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         case SID_ATTR_CHAR_FONTHEIGHT:
190cdf0e10cSrcweir         case SID_ATTR_CHAR_CTL_FONTHEIGHT:
191cdf0e10cSrcweir         case SID_ATTR_CHAR_CJK_FONTHEIGHT:
192cdf0e10cSrcweir         case SID_ATTR_CHAR_LATIN_FONTHEIGHT:
193cdf0e10cSrcweir             pReturn = new FontSizeHandler( _nAttributeId, lcl_implGetWhich( _rEditEnginePool, _nAttributeId ) );
194cdf0e10cSrcweir             break;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         case SID_ATTR_PARA_LEFT_TO_RIGHT:
197cdf0e10cSrcweir         case SID_ATTR_PARA_RIGHT_TO_LEFT:
198cdf0e10cSrcweir             pReturn = new ParagraphDirectionHandler( _nAttributeId );
199cdf0e10cSrcweir             break;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         case SID_ATTR_PARA_HANGPUNCTUATION:
202cdf0e10cSrcweir         case SID_ATTR_PARA_FORBIDDEN_RULES:
203cdf0e10cSrcweir         case SID_ATTR_PARA_SCRIPTSPACE:
204cdf0e10cSrcweir             pReturn = new BooleanHandler( _nAttributeId, lcl_implGetWhich( _rEditEnginePool, _nAttributeId ) );
205cdf0e10cSrcweir             break;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         default:
208cdf0e10cSrcweir             pReturn = new SlotHandler( (SfxSlotId)_nAttributeId, lcl_implGetWhich( _rEditEnginePool, _nAttributeId ) );
209cdf0e10cSrcweir             break;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         return pReturn;
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     //====================================================================
217cdf0e10cSrcweir 	//= ParaAlignmentHandler
218cdf0e10cSrcweir 	//====================================================================
219cdf0e10cSrcweir 	//--------------------------------------------------------------------
ParaAlignmentHandler(AttributeId _nAttributeId)220cdf0e10cSrcweir     ParaAlignmentHandler::ParaAlignmentHandler( AttributeId _nAttributeId )
221cdf0e10cSrcweir         :AttributeHandler( _nAttributeId, EE_PARA_JUST )
222cdf0e10cSrcweir         ,m_eAdjust( SVX_ADJUST_CENTER )
223cdf0e10cSrcweir     {
224cdf0e10cSrcweir         switch ( getAttribute() )
225cdf0e10cSrcweir         {
226cdf0e10cSrcweir             case SID_ATTR_PARA_ADJUST_LEFT  : m_eAdjust = SVX_ADJUST_LEFT;    break;
227cdf0e10cSrcweir 	    	case SID_ATTR_PARA_ADJUST_CENTER: m_eAdjust = SVX_ADJUST_CENTER;  break;
228cdf0e10cSrcweir 		    case SID_ATTR_PARA_ADJUST_RIGHT : m_eAdjust = SVX_ADJUST_RIGHT;   break;
229cdf0e10cSrcweir 		    case SID_ATTR_PARA_ADJUST_BLOCK : m_eAdjust = SVX_ADJUST_BLOCK;   break;
230cdf0e10cSrcweir             default:
231cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "ParaAlignmentHandler::ParaAlignmentHandler: invalid slot!" );
232cdf0e10cSrcweir                 break;
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	//--------------------------------------------------------------------
implGetCheckState(const SfxPoolItem & _rItem) const237cdf0e10cSrcweir     AttributeCheckState ParaAlignmentHandler::implGetCheckState( const SfxPoolItem& _rItem ) const
238cdf0e10cSrcweir     {
239cdf0e10cSrcweir         OSL_ENSURE( _rItem.ISA( SvxAdjustItem ), "ParaAlignmentHandler::implGetCheckState: invalid pool item!" );
240cdf0e10cSrcweir         SvxAdjust eAdjust = static_cast< const SvxAdjustItem& >( _rItem ).GetAdjust();
241cdf0e10cSrcweir         return ( eAdjust == m_eAdjust ) ? eChecked : eUnchecked;
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	//--------------------------------------------------------------------
executeAttribute(const SfxItemSet &,SfxItemSet & _rNewAttribs,const SfxPoolItem * _pAdditionalArg,ScriptType) const245cdf0e10cSrcweir     void ParaAlignmentHandler::executeAttribute( const SfxItemSet& /*_rCurrentAttribs*/, SfxItemSet& _rNewAttribs, const SfxPoolItem* _pAdditionalArg, ScriptType /*_nForScriptType*/ ) const
246cdf0e10cSrcweir     {
247cdf0e10cSrcweir         OSL_ENSURE( !_pAdditionalArg, "ParaAlignmentHandler::executeAttribute: this is a simple toggle attribute - no args possible!" );
248cdf0e10cSrcweir         (void)_pAdditionalArg;
249cdf0e10cSrcweir         _rNewAttribs.Put( SvxAdjustItem( m_eAdjust, getWhich() ) );
250cdf0e10cSrcweir     }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     //====================================================================
253cdf0e10cSrcweir 	//= LineSpacingHandler
254cdf0e10cSrcweir 	//====================================================================
255cdf0e10cSrcweir 	//--------------------------------------------------------------------
LineSpacingHandler(AttributeId _nAttributeId)256cdf0e10cSrcweir     LineSpacingHandler::LineSpacingHandler( AttributeId _nAttributeId )
257cdf0e10cSrcweir         :AttributeHandler( _nAttributeId, EE_PARA_SBL )
258cdf0e10cSrcweir         ,m_nLineSpace( 100 )
259cdf0e10cSrcweir     {
260cdf0e10cSrcweir         switch ( getAttribute() )
261cdf0e10cSrcweir         {
262cdf0e10cSrcweir             case SID_ATTR_PARA_LINESPACE_10: m_nLineSpace = 100; break;
263cdf0e10cSrcweir 	    	case SID_ATTR_PARA_LINESPACE_15: m_nLineSpace = 150; break;
264cdf0e10cSrcweir 		    case SID_ATTR_PARA_LINESPACE_20: m_nLineSpace = 200; break;
265cdf0e10cSrcweir             default:
266cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "LineSpacingHandler::LineSpacingHandler: invalid slot!" );
267cdf0e10cSrcweir                 break;
268cdf0e10cSrcweir         }
269cdf0e10cSrcweir     }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	//--------------------------------------------------------------------
implGetCheckState(const SfxPoolItem & _rItem) const272cdf0e10cSrcweir     AttributeCheckState LineSpacingHandler::implGetCheckState( const SfxPoolItem& _rItem ) const
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         OSL_ENSURE( _rItem.ISA( SvxLineSpacingItem ), "LineSpacingHandler::implGetCheckState: invalid pool item!" );
275cdf0e10cSrcweir         sal_uInt16 nLineSpace = static_cast< const SvxLineSpacingItem& >( _rItem ).GetPropLineSpace();
276cdf0e10cSrcweir         return ( nLineSpace == m_nLineSpace ) ? eChecked : eUnchecked;
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	//--------------------------------------------------------------------
executeAttribute(const SfxItemSet &,SfxItemSet & _rNewAttribs,const SfxPoolItem * _pAdditionalArg,ScriptType) const280cdf0e10cSrcweir     void LineSpacingHandler::executeAttribute( const SfxItemSet& /*_rCurrentAttribs*/, SfxItemSet& _rNewAttribs, const SfxPoolItem* _pAdditionalArg, ScriptType /*_nForScriptType*/ ) const
281cdf0e10cSrcweir     {
282cdf0e10cSrcweir         OSL_ENSURE( !_pAdditionalArg, "LineSpacingHandler::executeAttribute: this is a simple toggle attribute - no args possible!" );
283cdf0e10cSrcweir         (void)_pAdditionalArg;
284cdf0e10cSrcweir 
285cdf0e10cSrcweir         SvxLineSpacingItem aLineSpacing( m_nLineSpace, getWhich() );
286cdf0e10cSrcweir         aLineSpacing.GetLineSpaceRule() = SVX_LINE_SPACE_AUTO;
287cdf0e10cSrcweir         if ( 100 == m_nLineSpace )
288cdf0e10cSrcweir             aLineSpacing.GetInterLineSpaceRule() = SVX_INTER_LINE_SPACE_OFF;
289cdf0e10cSrcweir         else
290cdf0e10cSrcweir             aLineSpacing.SetPropLineSpace( (sal_uInt8)m_nLineSpace );
291cdf0e10cSrcweir 
292cdf0e10cSrcweir         _rNewAttribs.Put( aLineSpacing );
293cdf0e10cSrcweir     }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     //====================================================================
296cdf0e10cSrcweir 	//= EscapementHandler
297cdf0e10cSrcweir 	//====================================================================
298cdf0e10cSrcweir 	//--------------------------------------------------------------------
EscapementHandler(AttributeId _nAttributeId)299cdf0e10cSrcweir     EscapementHandler::EscapementHandler( AttributeId _nAttributeId )
300cdf0e10cSrcweir         :AttributeHandler( _nAttributeId, EE_CHAR_ESCAPEMENT )
301cdf0e10cSrcweir         ,m_eEscapement( SVX_ESCAPEMENT_OFF )
302cdf0e10cSrcweir     {
303cdf0e10cSrcweir         switch ( getAttribute() )
304cdf0e10cSrcweir         {
305cdf0e10cSrcweir             case SID_SET_SUPER_SCRIPT   : m_eEscapement = SVX_ESCAPEMENT_SUPERSCRIPT; break;
306cdf0e10cSrcweir 	    	case SID_SET_SUB_SCRIPT     : m_eEscapement = SVX_ESCAPEMENT_SUBSCRIPT;   break;
307cdf0e10cSrcweir             default:
308cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "EscapementHandler::EscapementHandler: invalid slot!" );
309cdf0e10cSrcweir                 break;
310cdf0e10cSrcweir         }
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 	//--------------------------------------------------------------------
implGetCheckState(const SfxPoolItem & _rItem) const314cdf0e10cSrcweir     AttributeCheckState EscapementHandler::implGetCheckState( const SfxPoolItem& _rItem ) const
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         OSL_ENSURE( _rItem.ISA( SvxEscapementItem ), "EscapementHandler::getState: invalid pool item!" );
317cdf0e10cSrcweir         SvxEscapement eEscapement = static_cast< const SvxEscapementItem& >( _rItem ).GetEscapement();
318cdf0e10cSrcweir         return ( eEscapement == m_eEscapement ) ? eChecked : eUnchecked;
319cdf0e10cSrcweir     }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 	//--------------------------------------------------------------------
executeAttribute(const SfxItemSet & _rCurrentAttribs,SfxItemSet & _rNewAttribs,const SfxPoolItem * _pAdditionalArg,ScriptType) const322cdf0e10cSrcweir     void EscapementHandler::executeAttribute( const SfxItemSet& _rCurrentAttribs, SfxItemSet& _rNewAttribs, const SfxPoolItem* _pAdditionalArg, ScriptType /*_nForScriptType*/ ) const
323cdf0e10cSrcweir     {
324cdf0e10cSrcweir         OSL_ENSURE( !_pAdditionalArg, "EscapementHandler::executeAttribute: this is a simple toggle attribute - no args possible!" );
325cdf0e10cSrcweir             // well, in theory we could allow an SvxEscapementItem here, but this is not needed
326cdf0e10cSrcweir         (void)_pAdditionalArg;
327cdf0e10cSrcweir 
328cdf0e10cSrcweir         bool bIsChecked = getCheckState( _rCurrentAttribs ) == eChecked;
329cdf0e10cSrcweir         _rNewAttribs.Put( SvxEscapementItem( bIsChecked ? SVX_ESCAPEMENT_OFF : m_eEscapement, getWhich() ) );
330cdf0e10cSrcweir     }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     //====================================================================
333cdf0e10cSrcweir 	//= SlotHandler
334cdf0e10cSrcweir 	//====================================================================
335cdf0e10cSrcweir     //--------------------------------------------------------------------
SlotHandler(AttributeId _nAttributeId,WhichId _nWhichId)336cdf0e10cSrcweir     SlotHandler::SlotHandler( AttributeId _nAttributeId, WhichId _nWhichId )
337cdf0e10cSrcweir         :AttributeHandler( _nAttributeId, _nWhichId )
338cdf0e10cSrcweir         ,m_bScriptDependent( false )
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         m_bScriptDependent = ( SID_ATTR_CHAR_WEIGHT == _nAttributeId )
341cdf0e10cSrcweir                          ||  ( SID_ATTR_CHAR_POSTURE == _nAttributeId )
342cdf0e10cSrcweir                          ||  ( SID_ATTR_CHAR_FONT == _nAttributeId );
343cdf0e10cSrcweir     }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     //--------------------------------------------------------------------
getState(const SfxItemSet & _rAttribs) const346cdf0e10cSrcweir     AttributeState SlotHandler::getState( const SfxItemSet& _rAttribs ) const
347cdf0e10cSrcweir     {
348cdf0e10cSrcweir         AttributeState aState( eIndetermined );
349cdf0e10cSrcweir 
350cdf0e10cSrcweir         const SfxPoolItem* pItem = _rAttribs.GetItem( getWhich() );
351cdf0e10cSrcweir         if ( pItem )
352cdf0e10cSrcweir             aState.setItem( pItem->Clone() );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         return aState;
355cdf0e10cSrcweir     }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     //--------------------------------------------------------------------
executeAttribute(const SfxItemSet &,SfxItemSet & _rNewAttribs,const SfxPoolItem * _pAdditionalArg,ScriptType _nForScriptType) const358cdf0e10cSrcweir     void SlotHandler::executeAttribute( const SfxItemSet& /*_rCurrentAttribs*/, SfxItemSet& _rNewAttribs, const SfxPoolItem* _pAdditionalArg, ScriptType _nForScriptType ) const
359cdf0e10cSrcweir     {
360cdf0e10cSrcweir         if ( _pAdditionalArg )
361cdf0e10cSrcweir         {
362cdf0e10cSrcweir             SfxPoolItem* pCorrectWich = _pAdditionalArg->Clone();
363cdf0e10cSrcweir             pCorrectWich->SetWhich( getWhich() );
364cdf0e10cSrcweir 
365cdf0e10cSrcweir             if ( m_bScriptDependent )
366cdf0e10cSrcweir                 putItemForScript( _rNewAttribs, *pCorrectWich, _nForScriptType );
367cdf0e10cSrcweir             else
368cdf0e10cSrcweir                 _rNewAttribs.Put( *pCorrectWich );
369cdf0e10cSrcweir             DELETEZ( pCorrectWich );
370cdf0e10cSrcweir         }
371cdf0e10cSrcweir         else
372cdf0e10cSrcweir             OSL_ENSURE( sal_False, "SlotHandler::executeAttribute: need attributes to do something!" );
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     //====================================================================
376cdf0e10cSrcweir 	//= FontSizeHandler
377cdf0e10cSrcweir 	//====================================================================
378cdf0e10cSrcweir     //--------------------------------------------------------------------
FontSizeHandler(AttributeId _nAttributeId,WhichId _nWhichId)379cdf0e10cSrcweir     FontSizeHandler::FontSizeHandler( AttributeId _nAttributeId, WhichId _nWhichId )
380cdf0e10cSrcweir         :AttributeHandler( _nAttributeId, _nWhichId )
381cdf0e10cSrcweir     {
382cdf0e10cSrcweir         OSL_ENSURE( ( _nAttributeId == SID_ATTR_CHAR_FONTHEIGHT ) || ( _nAttributeId == SID_ATTR_CHAR_CTL_FONTHEIGHT )
383cdf0e10cSrcweir             || ( _nAttributeId == SID_ATTR_CHAR_CJK_FONTHEIGHT ) || ( _nAttributeId == SID_ATTR_CHAR_LATIN_FONTHEIGHT ),
384cdf0e10cSrcweir             "FontSizeHandler::FontSizeHandler: invalid attribute id!" );
385cdf0e10cSrcweir     }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     //--------------------------------------------------------------------
getState(const SfxItemSet & _rAttribs) const388cdf0e10cSrcweir     AttributeState FontSizeHandler::getState( const SfxItemSet& _rAttribs ) const
389cdf0e10cSrcweir     {
390cdf0e10cSrcweir         AttributeState aState( eIndetermined );
391cdf0e10cSrcweir 
392cdf0e10cSrcweir         const SfxPoolItem* pItem = _rAttribs.GetItem( getWhich() );
393cdf0e10cSrcweir         const SvxFontHeightItem* pFontHeightItem = PTR_CAST( SvxFontHeightItem, pItem );
394cdf0e10cSrcweir         OSL_ENSURE( pFontHeightItem || !pItem, "FontSizeHandler::getState: invalid item!" );
395cdf0e10cSrcweir         if ( pFontHeightItem )
396cdf0e10cSrcweir         {
397cdf0e10cSrcweir             // by definition, the item should have the unit twip
398cdf0e10cSrcweir             sal_uLong nHeight = pFontHeightItem->GetHeight();
399cdf0e10cSrcweir             if ( _rAttribs.GetPool()->GetMetric( getWhich() ) != SFX_MAPUNIT_TWIP )
400cdf0e10cSrcweir             {
401cdf0e10cSrcweir                 nHeight = OutputDevice::LogicToLogic(
402cdf0e10cSrcweir                     Size( 0, nHeight ),
403cdf0e10cSrcweir                     MapMode( (MapUnit)( _rAttribs.GetPool()->GetMetric( getWhich() ) ) ),
404cdf0e10cSrcweir                     MapMode( MAP_TWIP )
405cdf0e10cSrcweir                 ).Height();
406cdf0e10cSrcweir             }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir             SvxFontHeightItem* pNewItem = new SvxFontHeightItem( nHeight, 100, getWhich() );
409cdf0e10cSrcweir             pNewItem->SetProp( pFontHeightItem->GetProp(), pFontHeightItem->GetPropUnit() );
410cdf0e10cSrcweir             aState.setItem( pNewItem );
411cdf0e10cSrcweir         }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir         return aState;
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir     //--------------------------------------------------------------------
executeAttribute(const SfxItemSet &,SfxItemSet & _rNewAttribs,const SfxPoolItem * _pAdditionalArg,ScriptType _nForScriptType) const417cdf0e10cSrcweir     void FontSizeHandler::executeAttribute( const SfxItemSet& /*_rCurrentAttribs*/, SfxItemSet& _rNewAttribs, const SfxPoolItem* _pAdditionalArg, ScriptType _nForScriptType ) const
418cdf0e10cSrcweir     {
419cdf0e10cSrcweir         const SvxFontHeightItem* pFontHeightItem = PTR_CAST( SvxFontHeightItem, _pAdditionalArg );
420cdf0e10cSrcweir         OSL_ENSURE( pFontHeightItem, "FontSizeHandler::executeAttribute: need a FontHeightItem!" );
421cdf0e10cSrcweir 
422cdf0e10cSrcweir         if ( pFontHeightItem )
423cdf0e10cSrcweir         {
424cdf0e10cSrcweir             // corect measurement units
425cdf0e10cSrcweir             SfxMapUnit eItemMapUnit = pFontHeightItem->GetPropUnit(); (void)eItemMapUnit;
426cdf0e10cSrcweir             sal_uLong nHeight = pFontHeightItem->GetHeight();
427cdf0e10cSrcweir             if ( _rNewAttribs.GetPool()->GetMetric( getWhich() ) != SFX_MAPUNIT_TWIP )
428cdf0e10cSrcweir             {
429cdf0e10cSrcweir                 nHeight = OutputDevice::LogicToLogic(
430cdf0e10cSrcweir                     Size( 0, nHeight ),
431cdf0e10cSrcweir                     MapMode( (MapUnit)( SFX_MAPUNIT_TWIP ) ),
432cdf0e10cSrcweir                     MapMode( (MapUnit)( _rNewAttribs.GetPool()->GetMetric( getWhich() ) ) )
433cdf0e10cSrcweir                 ).Height();
434cdf0e10cSrcweir             }
435cdf0e10cSrcweir 
436cdf0e10cSrcweir             SvxFontHeightItem aNewItem( nHeight, 100, getWhich() );
437cdf0e10cSrcweir             aNewItem.SetProp( pFontHeightItem->GetProp(), pFontHeightItem->GetPropUnit() );
438cdf0e10cSrcweir 
439cdf0e10cSrcweir             if ( ( getAttributeId() == SID_ATTR_CHAR_FONTHEIGHT ) && _nForScriptType )
440cdf0e10cSrcweir                 putItemForScript( _rNewAttribs, aNewItem, _nForScriptType );
441cdf0e10cSrcweir             else
442cdf0e10cSrcweir                 _rNewAttribs.Put( aNewItem );
443cdf0e10cSrcweir         }
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir     //====================================================================
447cdf0e10cSrcweir 	//= ParagraphDirectionHandler
448cdf0e10cSrcweir 	//====================================================================
449cdf0e10cSrcweir     //--------------------------------------------------------------------
ParagraphDirectionHandler(AttributeId _nAttributeId)450cdf0e10cSrcweir     ParagraphDirectionHandler::ParagraphDirectionHandler( AttributeId _nAttributeId )
451cdf0e10cSrcweir         :AttributeHandler( _nAttributeId, EE_PARA_WRITINGDIR )
452cdf0e10cSrcweir         ,m_eParagraphDirection( FRMDIR_HORI_LEFT_TOP )
453cdf0e10cSrcweir         ,m_eDefaultAdjustment( SVX_ADJUST_RIGHT )
454cdf0e10cSrcweir         ,m_eOppositeDefaultAdjustment( SVX_ADJUST_LEFT )
455cdf0e10cSrcweir     {
456cdf0e10cSrcweir         switch ( getAttributeId() )
457cdf0e10cSrcweir         {
458cdf0e10cSrcweir             case SID_ATTR_PARA_LEFT_TO_RIGHT: m_eParagraphDirection = FRMDIR_HORI_LEFT_TOP; m_eDefaultAdjustment = SVX_ADJUST_LEFT; break;
459cdf0e10cSrcweir             case SID_ATTR_PARA_RIGHT_TO_LEFT: m_eParagraphDirection = FRMDIR_HORI_RIGHT_TOP; m_eDefaultAdjustment = SVX_ADJUST_RIGHT; break;
460cdf0e10cSrcweir             default:
461cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "ParagraphDirectionHandler::ParagraphDirectionHandler: invalid attribute id!" );
462cdf0e10cSrcweir         }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir         if ( SVX_ADJUST_RIGHT == m_eDefaultAdjustment )
465cdf0e10cSrcweir             m_eOppositeDefaultAdjustment = SVX_ADJUST_LEFT;
466cdf0e10cSrcweir         else
467cdf0e10cSrcweir             m_eOppositeDefaultAdjustment = SVX_ADJUST_RIGHT;
468cdf0e10cSrcweir     }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 	//--------------------------------------------------------------------
implGetCheckState(const SfxPoolItem & _rItem) const471cdf0e10cSrcweir     AttributeCheckState ParagraphDirectionHandler::implGetCheckState( const SfxPoolItem& _rItem ) const
472cdf0e10cSrcweir     {
473cdf0e10cSrcweir         OSL_ENSURE( _rItem.ISA( SvxFrameDirectionItem ), "ParagraphDirectionHandler::implGetCheckState: invalid pool item!" );
474cdf0e10cSrcweir         SvxFrameDirection eDirection = static_cast< SvxFrameDirection >( static_cast< const SvxFrameDirectionItem& >( _rItem ).GetValue() );
475cdf0e10cSrcweir         return ( eDirection == m_eParagraphDirection ) ? eChecked : eUnchecked;
476cdf0e10cSrcweir     }
477cdf0e10cSrcweir 
478cdf0e10cSrcweir     //--------------------------------------------------------------------
executeAttribute(const SfxItemSet & _rCurrentAttribs,SfxItemSet & _rNewAttribs,const SfxPoolItem *,ScriptType) const479cdf0e10cSrcweir     void ParagraphDirectionHandler::executeAttribute( const SfxItemSet& _rCurrentAttribs, SfxItemSet& _rNewAttribs, const SfxPoolItem* /*_pAdditionalArg*/, ScriptType /*_nForScriptType*/ ) const
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         _rNewAttribs.Put( SvxFrameDirectionItem( m_eParagraphDirection, getWhich() ) );
482cdf0e10cSrcweir 
483cdf0e10cSrcweir         // if the current adjustment of the was the default adjustment for the *previous* text direction,
484cdf0e10cSrcweir         // then we toggle the adjustment, too
485cdf0e10cSrcweir         SvxAdjust eCurrentAdjustment = SVX_ADJUST_LEFT;
486cdf0e10cSrcweir         const SfxPoolItem* pCurrentAdjustment = NULL;
487cdf0e10cSrcweir         if ( SFX_ITEM_ON == _rCurrentAttribs.GetItemState( EE_PARA_JUST, sal_True, &pCurrentAdjustment ) )
488cdf0e10cSrcweir             eCurrentAdjustment = static_cast< const SvxAdjustItem* >( pCurrentAdjustment )->GetAdjust();
489cdf0e10cSrcweir 
490cdf0e10cSrcweir         if ( eCurrentAdjustment == m_eOppositeDefaultAdjustment )
491cdf0e10cSrcweir             _rNewAttribs.Put( SvxAdjustItem( m_eDefaultAdjustment, EE_PARA_JUST ) );
492cdf0e10cSrcweir     }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir     //====================================================================
495cdf0e10cSrcweir 	//= BooleanHandler
496cdf0e10cSrcweir 	//====================================================================
497cdf0e10cSrcweir     //--------------------------------------------------------------------
BooleanHandler(AttributeId _nAttributeId,WhichId _nWhichId)498cdf0e10cSrcweir     BooleanHandler::BooleanHandler( AttributeId _nAttributeId, WhichId _nWhichId )
499cdf0e10cSrcweir         :AttributeHandler( _nAttributeId, _nWhichId )
500cdf0e10cSrcweir     {
501cdf0e10cSrcweir     }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     //--------------------------------------------------------------------
implGetCheckState(const SfxPoolItem & _rItem) const504cdf0e10cSrcweir     AttributeCheckState BooleanHandler::implGetCheckState( const SfxPoolItem& _rItem ) const
505cdf0e10cSrcweir     {
506cdf0e10cSrcweir         OSL_ENSURE( _rItem.ISA( SfxBoolItem ), "BooleanHandler::implGetCheckState: invalid item!" );
507cdf0e10cSrcweir         if ( _rItem.ISA( SfxBoolItem ) )
508cdf0e10cSrcweir             return static_cast< const SfxBoolItem& >( _rItem ).GetValue() ? eChecked : eUnchecked;
509cdf0e10cSrcweir 
510cdf0e10cSrcweir         return eIndetermined;
511cdf0e10cSrcweir     }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     //--------------------------------------------------------------------
executeAttribute(const SfxItemSet &,SfxItemSet & _rNewAttribs,const SfxPoolItem * _pAdditionalArg,ScriptType) const514cdf0e10cSrcweir     void BooleanHandler::executeAttribute( const SfxItemSet& /*_rCurrentAttribs*/, SfxItemSet& _rNewAttribs, const SfxPoolItem* _pAdditionalArg, ScriptType /*_nForScriptType*/ ) const
515cdf0e10cSrcweir     {
516cdf0e10cSrcweir         OSL_ENSURE( _pAdditionalArg && _pAdditionalArg->ISA( SfxBoolItem ), "BooleanHandler::executeAttribute: invalid argument!" );
517cdf0e10cSrcweir         if ( _pAdditionalArg )
518cdf0e10cSrcweir         {
519cdf0e10cSrcweir             SfxPoolItem* pCorrectWich = _pAdditionalArg->Clone();
520cdf0e10cSrcweir             pCorrectWich->SetWhich( getWhich() );
521cdf0e10cSrcweir             _rNewAttribs.Put( *pCorrectWich );
522cdf0e10cSrcweir             DELETEZ( pCorrectWich );
523cdf0e10cSrcweir         }
524cdf0e10cSrcweir     }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir //........................................................................
527cdf0e10cSrcweir }   // namespace frm
528cdf0e10cSrcweir //........................................................................
529