xref: /trunk/main/sot/source/sdstor/storinfo.cxx (revision 046d9d1f)
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_sot.hxx"
26 
27 #include <sot/stg.hxx>
28 #include <sot/storinfo.hxx>
29 #include <sot/exchange.hxx>
30 
31 
32 /************** class SvStorageInfoList **********************************
33 *************************************************************************/
34 PRV_SV_IMPL_OWNER_LIST(SvStorageInfoList,SvStorageInfo)
35 
36 const SvStorageInfo * SvStorageInfoList::Get( const String & rEleName )
37 {
38     for( sal_uLong i = 0; i < Count(); i++ )
39     {
40         const SvStorageInfo & rType = GetObject( i );
41         if( rType.GetName() == rEleName )
42             return &rType;
43     }
44     return NULL;
45 }
46 
47 /************** class SvStorageInfo **************************************
48 *************************************************************************/
49 sal_uLong ReadClipboardFormat( SvStream & rStm )
50 {
51     sal_uInt32 nFormat = 0;
52     sal_Int32 nLen = 0;
53     rStm >> nLen;
54     if( rStm.IsEof() )
55         rStm.SetError( SVSTREAM_GENERALERROR );
56     if( nLen > 0 )
57     {
58         // get a string name
59         sal_Char * p = new sal_Char[ nLen ];
60         if( rStm.Read( p, nLen ) == (sal_uLong) nLen )
61         {
62             nFormat = SotExchange::RegisterFormatName( String::CreateFromAscii( p, short(nLen-1) ) );
63         }
64         else
65             rStm.SetError( SVSTREAM_GENERALERROR );
66         delete [] p;
67     }
68     else if( nLen == -1L )
69         // Windows clipboard format
70         // SV und Win stimmen ueberein (bis einschl. FORMAT_GDIMETAFILE)
71         rStm >> nFormat;
72     else if( nLen == -2L )
73     {
74         rStm >> nFormat;
75         // Mac clipboard format
76         // ??? not implemented
77         rStm.SetError( SVSTREAM_GENERALERROR );
78     }
79     else if( nLen != 0 )
80     {
81         // unknown identifier
82         rStm.SetError( SVSTREAM_GENERALERROR );
83     }
84     return nFormat;
85 }
86 
87 void WriteClipboardFormat( SvStream & rStm, sal_uLong nFormat )
88 {
89     // determine the clipboard format string
90     String aCbFmt;
91     if( nFormat > FORMAT_GDIMETAFILE )
92         aCbFmt = SotExchange::GetFormatName( nFormat );
93     if( aCbFmt.Len() )
94 	{
95 		ByteString aAsciiCbFmt( aCbFmt, RTL_TEXTENCODING_ASCII_US );
96         rStm << (sal_Int32) (aAsciiCbFmt.Len() + 1);
97 		rStm << (const char *)aAsciiCbFmt.GetBuffer();
98         rStm << (sal_uInt8) 0;
99 	}
100     else if( nFormat )
101         rStm << (sal_Int32) -1         // for Windows
102              << (sal_Int32) nFormat;
103     else
104         rStm << (sal_Int32) 0;         // no clipboard format
105 }
106 
107 
108