xref: /AOO41X/main/svtools/source/misc/stringtransfer.cxx (revision 5900e8ec128faec89519683efce668ccd8cc6084)
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_svtools.hxx"
26 #include <svtools/stringtransfer.hxx>
27 
28 //........................................................................
29 namespace svt
30 {
31 //........................................................................
32 
33     using namespace ::com::sun::star::uno;
34     using namespace ::com::sun::star::datatransfer;
35 
36     //====================================================================
37     //= OStringTransferable
38     //====================================================================
39     //--------------------------------------------------------------------
OStringTransferable(const::rtl::OUString & _rContent)40     OStringTransferable::OStringTransferable(const ::rtl::OUString& _rContent)
41         :TransferableHelper()
42         ,m_sContent( _rContent )
43     {
44     }
45 
46     //--------------------------------------------------------------------
AddSupportedFormats()47     void OStringTransferable::AddSupportedFormats()
48     {
49         AddFormat(SOT_FORMAT_STRING);
50     }
51 
52     //--------------------------------------------------------------------
GetData(const DataFlavor & _rFlavor)53     sal_Bool OStringTransferable::GetData( const DataFlavor& _rFlavor )
54     {
55         sal_uInt32 nFormat = SotExchange::GetFormat( _rFlavor );
56         if (SOT_FORMAT_STRING == nFormat)
57             return SetString( m_sContent, _rFlavor );
58 
59         return sal_False;
60     }
61 
62     //====================================================================
63     //= OStringTransfer
64     //====================================================================
65     //--------------------------------------------------------------------
CopyString(const::rtl::OUString & _rContent,Window * _pWindow)66     void OStringTransfer::CopyString( const ::rtl::OUString& _rContent, Window* _pWindow )
67     {
68         OStringTransferable* pTransferable = new OStringTransferable( _rContent );
69         Reference< XTransferable > xTransfer = pTransferable;
70         pTransferable->CopyToClipboard( _pWindow );
71     }
72 
73     //--------------------------------------------------------------------
PasteString(::rtl::OUString & _rContent,Window * _pWindow)74     sal_Bool OStringTransfer::PasteString( ::rtl::OUString& _rContent, Window* _pWindow )
75     {
76         TransferableDataHelper aClipboardData = TransferableDataHelper::CreateFromSystemClipboard( _pWindow );
77 
78         // check for a string format
79         const DataFlavorExVector& rFormats = aClipboardData.GetDataFlavorExVector();
80         for (   DataFlavorExVector::const_iterator aSearch = rFormats.begin();
81                 aSearch != rFormats.end();
82                 ++aSearch
83             )
84         {
85             if (SOT_FORMAT_STRING == aSearch->mnSotId)
86             {
87                 String sContent;
88                 sal_Bool bSuccess = aClipboardData.GetString( SOT_FORMAT_STRING, sContent );
89                 _rContent = sContent;
90                 return bSuccess;
91             }
92         }
93 
94         return sal_False;
95     }
96 
97     //--------------------------------------------------------------------
StartStringDrag(const::rtl::OUString & _rContent,Window * _pWindow,sal_Int8 _nDragSourceActions)98     void OStringTransfer::StartStringDrag( const ::rtl::OUString& _rContent, Window* _pWindow, sal_Int8 _nDragSourceActions )
99     {
100         OStringTransferable* pTransferable = new OStringTransferable( _rContent );
101         Reference< XTransferable > xTransfer = pTransferable;
102         pTransferable->StartDrag(_pWindow, _nDragSourceActions);
103     }
104 
105 //........................................................................
106 }   // namespace svt
107 //........................................................................
108 
109