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