Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <com/sun/star/uno/Any.hxx>
21 : :
22 : : #include <unotools/intlwrapper.hxx>
23 : : #include <tools/stream.hxx>
24 : : #include <svl/ctypeitm.hxx>
25 : :
26 : : //============================================================================
27 : : // The following defines are copied from chaos/source/items/cstritem.cxx:
28 : : #define CNTSTRINGITEM_STREAM_MAGIC ( (sal_uInt32)0xfefefefe )
29 : : #define CNTSTRINGITEM_STREAM_SEEKREL (-( (long)( sizeof( sal_uInt32 ) ) ) )
30 : :
31 : : //============================================================================
32 : : //
33 : : // class CntContentTypeItem Implementation.
34 : : //
35 : : //============================================================================
36 : :
37 [ # # ][ # # ]: 0 : TYPEINIT1_AUTOFACTORY( CntContentTypeItem, CntUnencodedStringItem );
[ # # ]
38 : :
39 : : #define CONTENT_TYPE_NOT_INIT ( (INetContentType)-1 )
40 : :
41 : : //----------------------------------------------------------------------------
42 : 0 : CntContentTypeItem::CntContentTypeItem()
43 : : : CntUnencodedStringItem(),
44 [ # # ]: 0 : _eType( CONTENT_TYPE_NOT_INIT )
45 : : {
46 : 0 : }
47 : :
48 : : //----------------------------------------------------------------------------
49 : 0 : CntContentTypeItem::CntContentTypeItem( sal_uInt16 which, const XubString& rType )
50 : : : CntUnencodedStringItem( which, rType ),
51 [ # # ]: 0 : _eType( CONTENT_TYPE_NOT_INIT )
52 : : {
53 : 0 : }
54 : :
55 : : //----------------------------------------------------------------------------
56 : 0 : CntContentTypeItem::CntContentTypeItem( const CntContentTypeItem& rOrig )
57 : : : CntUnencodedStringItem( rOrig ),
58 : : _eType( rOrig._eType ),
59 [ # # ]: 0 : _aPresentation( rOrig._aPresentation )
60 : : {
61 : 0 : }
62 : :
63 : : //============================================================================
64 : : // virtual
65 : 0 : sal_uInt16 CntContentTypeItem::GetVersion(sal_uInt16) const
66 : : {
67 : 0 : return 1; // because it uses SfxPoolItem::read/writeUnicodeString()
68 : : }
69 : :
70 : : //----------------------------------------------------------------------------
71 : : // virtual
72 : 0 : SfxPoolItem* CntContentTypeItem::Create( SvStream& rStream,
73 : : sal_uInt16 nItemVersion ) const
74 : : {
75 : : // CntContentTypeItem used to be derived from CntStringItem, so take that
76 : : // into account:
77 [ # # ]: 0 : rtl::OUString aValue = readUnicodeString(rStream, nItemVersion >= 1);
78 : 0 : sal_uInt32 nMagic = 0;
79 [ # # ]: 0 : rStream >> nMagic;
80 [ # # ]: 0 : if (nMagic == CNTSTRINGITEM_STREAM_MAGIC)
81 : : {
82 : 0 : sal_Bool bEncrypted = sal_False;
83 [ # # ]: 0 : rStream >> bEncrypted;
84 : : DBG_ASSERT(!bEncrypted,
85 : : "CntContentTypeItem::Create() reads encrypted data");
86 : : }
87 : : else
88 [ # # ]: 0 : rStream.SeekRel(CNTSTRINGITEM_STREAM_SEEKREL);
89 : :
90 [ # # ][ # # ]: 0 : return new CntContentTypeItem(Which(), aValue);
[ # # ][ # # ]
91 : : }
92 : :
93 : : //----------------------------------------------------------------------------
94 : : // virtual
95 : 0 : SvStream & CntContentTypeItem::Store(SvStream & rStream, sal_uInt16) const
96 : : {
97 : : // CntContentTypeItem used to be derived from CntStringItem, so take that
98 : : // into account:
99 [ # # ]: 0 : writeUnicodeString(rStream, GetValue());
100 : 0 : rStream << CNTSTRINGITEM_STREAM_MAGIC << sal_Bool(sal_False);
101 : 0 : return rStream;
102 : : }
103 : :
104 : : //----------------------------------------------------------------------------
105 : : // virtual
106 : 0 : int CntContentTypeItem::operator==( const SfxPoolItem& rOrig ) const
107 : : {
108 : 0 : const CntContentTypeItem& rOther = (const CntContentTypeItem&)rOrig;
109 : :
110 [ # # ][ # # ]: 0 : if ( ( _eType != CONTENT_TYPE_NOT_INIT ) &&
111 : : ( rOther._eType != CONTENT_TYPE_NOT_INIT ) )
112 : 0 : return _eType == rOther._eType;
113 : : else
114 : 0 : return CntUnencodedStringItem::operator==( rOther );
115 : : }
116 : :
117 : : //----------------------------------------------------------------------------
118 : : // virtual
119 : 0 : SfxPoolItem* CntContentTypeItem::Clone( SfxItemPool* /* pPool */ ) const
120 : : {
121 [ # # ]: 0 : return new CntContentTypeItem( *this );
122 : : }
123 : :
124 : : //----------------------------------------------------------------------------
125 : 0 : void CntContentTypeItem::SetValue( const XubString& rNewVal )
126 : : {
127 : : // De-initialize enum type and presentation.
128 : 0 : _eType = CONTENT_TYPE_NOT_INIT;
129 : 0 : _aPresentation.Erase();
130 : :
131 : 0 : CntUnencodedStringItem::SetValue( rNewVal );
132 : 0 : }
133 : :
134 : : //----------------------------------------------------------------------------
135 : 0 : int CntContentTypeItem::Compare( const SfxPoolItem &rWith, const IntlWrapper& rIntlWrapper ) const
136 : : {
137 [ # # ][ # # ]: 0 : String aOwnText, aWithText;
138 : : GetPresentation( SFX_ITEM_PRESENTATION_NAMELESS,
139 [ # # ]: 0 : SFX_MAPUNIT_APPFONT, SFX_MAPUNIT_APPFONT, aOwnText, &rIntlWrapper );
140 : : rWith.GetPresentation( SFX_ITEM_PRESENTATION_NAMELESS,
141 [ # # ]: 0 : SFX_MAPUNIT_APPFONT, SFX_MAPUNIT_APPFONT, aWithText, &rIntlWrapper );
142 [ # # ][ # # ]: 0 : return rIntlWrapper.getCollator()->compareString( aOwnText, aWithText );
[ # # ][ # # ]
[ # # ][ # # ]
143 : : }
144 : :
145 : : //----------------------------------------------------------------------------
146 : 0 : SfxItemPresentation CntContentTypeItem::GetPresentation(
147 : : SfxItemPresentation ePres,
148 : : SfxMapUnit eCoreMetric,
149 : : SfxMapUnit ePresMetric,
150 : : XubString & rText,
151 : : const IntlWrapper * pIntlWrapper) const
152 : : {
153 [ # # ]: 0 : if (_aPresentation.Len() == 0)
154 : : {
155 : : DBG_ASSERT(pIntlWrapper,
156 : : "CntContentTypeItem::GetPresentation(): No IntlWrapper");
157 [ # # ]: 0 : if (pIntlWrapper)
158 : : (const_cast< CntContentTypeItem * >(this))->_aPresentation
159 : : = INetContentTypes::GetPresentation(GetEnumValue(),
160 : : pIntlWrapper->
161 [ # # ]: 0 : getLocale());
162 : : }
163 [ # # ]: 0 : if (_aPresentation.Len() > 0)
164 : : {
165 : 0 : rText = _aPresentation;
166 : 0 : return SFX_ITEM_PRESENTATION_COMPLETE;
167 : : }
168 : : else
169 : : return CntUnencodedStringItem::GetPresentation(ePres, eCoreMetric,
170 : : ePresMetric, rText,
171 : 0 : pIntlWrapper);
172 : : }
173 : :
174 : : //----------------------------------------------------------------------------
175 : 0 : INetContentType CntContentTypeItem::GetEnumValue() const
176 : : {
177 [ # # ]: 0 : if ( _eType == CONTENT_TYPE_NOT_INIT )
178 : : {
179 : : // Not yet initialized... Get enum value for string content type.
180 : :
181 : 0 : CntContentTypeItem* pVarThis = (const_cast< CntContentTypeItem* >(this));
182 : :
183 : 0 : pVarThis->_eType = INetContentTypes::GetContentType( GetValue() );
184 : : }
185 : :
186 : 0 : return _eType;
187 : : }
188 : :
189 : : //----------------------------------------------------------------------------
190 : 0 : void CntContentTypeItem::SetValue( const INetContentType eType )
191 : : {
192 [ # # ][ # # ]: 0 : SetValue( INetContentTypes::GetContentType( eType ) );
[ # # ]
193 : :
194 : : // Note: SetValue( const String& ....) resets _eType. Set new enum value
195 : : // after(!) calling it.
196 : 0 : _eType = eType;
197 : 0 : }
198 : :
199 : : //----------------------------------------------------------------------------
200 : : // virtual
201 : 0 : bool CntContentTypeItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8) const
202 : : {
203 [ # # ]: 0 : rVal <<= rtl::OUString(GetValue());
204 : 0 : return true;
205 : : }
206 : :
207 : : //----------------------------------------------------------------------------
208 : : // virtual
209 : 0 : bool CntContentTypeItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8)
210 : : {
211 : 0 : rtl::OUString aValue;
212 [ # # ]: 0 : if ( rVal >>= aValue )
213 : : {
214 : : // SetValue with an empty string resets the item; so call that
215 : : // function when PutValue is called with an empty string
216 [ # # ]: 0 : if (aValue.isEmpty())
217 [ # # ][ # # ]: 0 : SetValue(aValue);
[ # # ]
218 : : else
219 : : SetValue(
220 [ # # ][ # # ]: 0 : INetContentTypes::RegisterContentType(aValue, UniString()));
[ # # ][ # # ]
[ # # ][ # # ]
221 : 0 : return true;
222 : : }
223 : :
224 : : OSL_FAIL( "CntContentTypeItem::PutValue - Wrong type!" );
225 : 0 : return false;
226 : : }
227 : :
228 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|