xref: /aoo42x/main/sot/source/sdstor/storinfo.cxx (revision 297a844a)
1046d9d1fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3046d9d1fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4046d9d1fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5046d9d1fSAndrew Rist  * distributed with this work for additional information
6046d9d1fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7046d9d1fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8046d9d1fSAndrew Rist  * "License"); you may not use this file except in compliance
9046d9d1fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10046d9d1fSAndrew Rist  *
11046d9d1fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12046d9d1fSAndrew Rist  *
13046d9d1fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14046d9d1fSAndrew Rist  * software distributed under the License is distributed on an
15046d9d1fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16046d9d1fSAndrew Rist  * KIND, either express or implied.  See the License for the
17046d9d1fSAndrew Rist  * specific language governing permissions and limitations
18046d9d1fSAndrew Rist  * under the License.
19046d9d1fSAndrew Rist  *
20046d9d1fSAndrew Rist  *************************************************************/
21046d9d1fSAndrew Rist 
22046d9d1fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sot.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sot/stg.hxx>
28cdf0e10cSrcweir #include <sot/storinfo.hxx>
29cdf0e10cSrcweir #include <sot/exchange.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir /************** class SvStorageInfoList **********************************
33cdf0e10cSrcweir *************************************************************************/
PRV_SV_IMPL_OWNER_LIST(SvStorageInfoList,SvStorageInfo) const34cdf0e10cSrcweir PRV_SV_IMPL_OWNER_LIST(SvStorageInfoList,SvStorageInfo)
35cdf0e10cSrcweir 
36cdf0e10cSrcweir const SvStorageInfo * SvStorageInfoList::Get( const String & rEleName )
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     for( sal_uLong i = 0; i < Count(); i++ )
39cdf0e10cSrcweir     {
40cdf0e10cSrcweir         const SvStorageInfo & rType = GetObject( i );
41cdf0e10cSrcweir         if( rType.GetName() == rEleName )
42cdf0e10cSrcweir             return &rType;
43cdf0e10cSrcweir     }
44cdf0e10cSrcweir     return NULL;
45cdf0e10cSrcweir }
46cdf0e10cSrcweir 
47cdf0e10cSrcweir /************** class SvStorageInfo **************************************
48cdf0e10cSrcweir *************************************************************************/
ReadClipboardFormat(SvStream & rStm)49cdf0e10cSrcweir sal_uLong ReadClipboardFormat( SvStream & rStm )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     sal_uInt32 nFormat = 0;
52cdf0e10cSrcweir     sal_Int32 nLen = 0;
53cdf0e10cSrcweir     rStm >> nLen;
54cdf0e10cSrcweir     if( rStm.IsEof() )
55cdf0e10cSrcweir         rStm.SetError( SVSTREAM_GENERALERROR );
56cdf0e10cSrcweir     if( nLen > 0 )
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir         // get a string name
59*297a844aSArmin Le Grand         sal_Char * p = new( ::std::nothrow ) sal_Char[ nLen ];
60*297a844aSArmin Le Grand         if( p && rStm.Read( p, nLen ) == (sal_uLong) nLen )
61cdf0e10cSrcweir         {
62*297a844aSArmin Le Grand             // take so much from the buffer, as the string supports
63*297a844aSArmin Le Grand             nFormat = SotExchange::RegisterFormatName( String::CreateFromAscii( p, xub_StrLen( ( nLen - 1 ) & STRING_MAXLEN ) ) );
64cdf0e10cSrcweir         }
65cdf0e10cSrcweir         else
66cdf0e10cSrcweir             rStm.SetError( SVSTREAM_GENERALERROR );
67cdf0e10cSrcweir         delete [] p;
68cdf0e10cSrcweir     }
69cdf0e10cSrcweir     else if( nLen == -1L )
70cdf0e10cSrcweir         // Windows clipboard format
71cdf0e10cSrcweir         // SV und Win stimmen ueberein (bis einschl. FORMAT_GDIMETAFILE)
72cdf0e10cSrcweir         rStm >> nFormat;
73cdf0e10cSrcweir     else if( nLen == -2L )
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         rStm >> nFormat;
76cdf0e10cSrcweir         // Mac clipboard format
77cdf0e10cSrcweir         // ??? not implemented
78cdf0e10cSrcweir         rStm.SetError( SVSTREAM_GENERALERROR );
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir     else if( nLen != 0 )
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         // unknown identifier
83cdf0e10cSrcweir         rStm.SetError( SVSTREAM_GENERALERROR );
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir     return nFormat;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
WriteClipboardFormat(SvStream & rStm,sal_uLong nFormat)88cdf0e10cSrcweir void WriteClipboardFormat( SvStream & rStm, sal_uLong nFormat )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir     // determine the clipboard format string
91cdf0e10cSrcweir     String aCbFmt;
92cdf0e10cSrcweir     if( nFormat > FORMAT_GDIMETAFILE )
93cdf0e10cSrcweir         aCbFmt = SotExchange::GetFormatName( nFormat );
94cdf0e10cSrcweir     if( aCbFmt.Len() )
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		ByteString aAsciiCbFmt( aCbFmt, RTL_TEXTENCODING_ASCII_US );
97cdf0e10cSrcweir         rStm << (sal_Int32) (aAsciiCbFmt.Len() + 1);
98cdf0e10cSrcweir 		rStm << (const char *)aAsciiCbFmt.GetBuffer();
99cdf0e10cSrcweir         rStm << (sal_uInt8) 0;
100cdf0e10cSrcweir 	}
101cdf0e10cSrcweir     else if( nFormat )
102cdf0e10cSrcweir         rStm << (sal_Int32) -1         // for Windows
103cdf0e10cSrcweir              << (sal_Int32) nFormat;
104cdf0e10cSrcweir     else
105cdf0e10cSrcweir         rStm << (sal_Int32) 0;         // no clipboard format
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
109