1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
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/.
12 from com
.sun
.star
.datatransfer
import DataFlavor
13 from com
.sun
.star
.datatransfer
import UnsupportedFlavorException
14 from com
.sun
.star
.datatransfer
import XTransferable
16 # A simple transferable for the clipboard.py example
17 # contains only one format, that is, unicode text
19 class TextTransferable(unohelper
.Base
, XTransferable
):
20 UNICODE_CONTENT_TYPE
= "text/plain;charset=utf-16"
22 def __init__(self
, text
):
25 ''' XTransferable methods '''
26 def getTransferData(self
, flavor
):
27 # str.casefold() allows reliable case-insensitive comparison
28 if flavor
.MimeType
.casefold() != __class__
.UNICODE_CONTENT_TYPE
.casefold():
29 raise UnsupportedFlavorException()
32 def getTransferDataFlavors(self
):
33 unicode_flavor
= DataFlavor(__class__
.UNICODE_CONTENT_TYPE
, "Unicode Text", uno
.getTypeByName("string"))
34 return [unicode_flavor
]
36 def isDataFlavorSupported(self
, flavor
):
37 # str.casefold() allows reliable case-insensitive comparison
38 return flavor
.MimeType
.casefold() == __class__
.UNICODE_CONTENT_TYPE
.casefold()
40 # vim: set shiftwidth=4 softtabstop=4 expandtab: