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_editeng.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 
30 #include <editeng/writingmodeitem.hxx>
31 #include <editeng/eerdll.hxx>
32 #include <editeng/editrids.hrc>
33 
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::text;
36 
37 // class SvxWritingModeItem -------------------------------------------------
38 
39 TYPEINIT1_FACTORY(SvxWritingModeItem, SfxUInt16Item, new SvxWritingModeItem(com::sun::star::text::WritingMode_LR_TB, 0));
40 
SvxWritingModeItem(WritingMode eValue,sal_uInt16 _nWhich)41 SvxWritingModeItem::SvxWritingModeItem( WritingMode eValue, sal_uInt16 _nWhich )
42     : SfxUInt16Item( _nWhich, (sal_uInt16)eValue )
43 {
44 }
45 
~SvxWritingModeItem()46 SvxWritingModeItem::~SvxWritingModeItem()
47 {
48 }
49 
operator ==(const SfxPoolItem & rCmp) const50 int SvxWritingModeItem::operator==( const SfxPoolItem& rCmp ) const
51 {
52 	DBG_ASSERT( SfxPoolItem::operator==(rCmp), "unequal types" );
53 
54 	return GetValue() == ((SvxWritingModeItem&)rCmp).GetValue();
55 }
56 
Clone(SfxItemPool *) const57 SfxPoolItem* SvxWritingModeItem::Clone( SfxItemPool * ) const
58 {
59 	return new SvxWritingModeItem( *this );
60 }
61 
Create(SvStream &,sal_uInt16) const62 SfxPoolItem* SvxWritingModeItem::Create( SvStream & , sal_uInt16  ) const
63 {
64 	DBG_ERROR("SvxWritingModeItem should not be streamed!");
65 	return NULL;
66 }
67 
Store(SvStream & rStrm,sal_uInt16) const68 SvStream& SvxWritingModeItem::Store( SvStream & rStrm, sal_uInt16  ) const
69 {
70 	DBG_ERROR("SvxWritingModeItem should not be streamed!");
71 	return rStrm;
72 }
73 
GetVersion(sal_uInt16) const74 sal_uInt16 SvxWritingModeItem::GetVersion( sal_uInt16 /*nFVer*/ ) const
75 {
76 	return USHRT_MAX;
77 }
78 
GetPresentation(SfxItemPresentation ePres,SfxMapUnit,SfxMapUnit,String & rText,const IntlWrapper *) const79 SfxItemPresentation SvxWritingModeItem::GetPresentation( SfxItemPresentation ePres,
80         SfxMapUnit /*eCoreMetric*/,
81         SfxMapUnit /*ePresMetric*/,
82         String &rText,
83         const IntlWrapper *  ) const
84 {
85 	SfxItemPresentation eRet = ePres;
86     switch( ePres )
87     {
88     case SFX_ITEM_PRESENTATION_NONE:
89         rText.Erase();
90 		break;
91 
92     case SFX_ITEM_PRESENTATION_NAMELESS:
93     case SFX_ITEM_PRESENTATION_COMPLETE:
94 		rText = String( EditResId( RID_SVXITEMS_FRMDIR_BEGIN + GetValue() ) );
95 		break;
96 
97 	default:
98 		eRet = SFX_ITEM_PRESENTATION_NONE;
99     }
100     return eRet;
101 }
102 
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)103 sal_Bool SvxWritingModeItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
104 {
105     sal_Int32 nVal = 0;
106     sal_Bool bRet = ( rVal >>= nVal );
107 
108 	if( !bRet )
109 	{
110 		WritingMode eMode;
111 		bRet = rVal >>= eMode;
112 
113 		if( bRet )
114 		{
115 			nVal = (sal_Int32)eMode;
116 		}
117 	}
118 
119     if( bRet )
120     {
121         switch( nVal )
122         {
123 			case WritingMode_LR_TB:
124 			case WritingMode_RL_TB:
125 			case WritingMode_TB_RL:
126 				SetValue( (sal_uInt16)nVal );
127 				bRet = true;
128                 break;
129             default:
130                 bRet = false;
131                 break;
132         }
133     }
134 
135 	return bRet;
136 }
137 
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const138 sal_Bool SvxWritingModeItem::QueryValue( com::sun::star::uno::Any& rVal,
139 											sal_uInt8 ) const
140 {
141 	rVal <<= (WritingMode)GetValue();
142 	return true;
143 }
144 
operator =(const SvxWritingModeItem & rItem)145 SvxWritingModeItem& SvxWritingModeItem::operator=( const SvxWritingModeItem& rItem )
146 {
147 	SetValue( rItem.GetValue() );
148 	return *this;
149 }
150