9bed609fb8fc53fc8edebf8a4376ff092d5f3722
[profile/ivi/qtbase.git] / src / plugins / platforms / windows / qwindowsinternalmimedata.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qwindowsinternalmimedata.h"
43 #include "qwindowscontext.h"
44 #include "qplatformfunctions_wince.h"
45 #include "qwindowsmime.h"
46 #include <QDebug>
47 /*!
48     \class QWindowsInternalMimeDataBase
49     \brief Base for implementations of QInternalMimeData using a IDataObject COM object.
50
51     In clipboard handling and Drag and drop, static instances
52     of QInternalMimeData implementations are kept and passed to the client.
53
54     QInternalMimeData provides virtuals that query the formats and retrieve
55     mime data on demand when the client invokes functions like QMimeData::hasHtml(),
56     QMimeData::html() on the instance returned. Otherwise, expensive
57     construction of a new QMimeData object containing all possible
58     formats would have to be done in each call to mimeData().
59
60     The base class introduces new virtuals to obtain and release
61     the instances IDataObject from the clipboard or Drag and Drop and
62     does conversion using QWindowsMime classes.
63
64     \sa QInternalMimeData, QWindowsMime, QWindowsMimeConverter
65     \ingroup qt-lighthouse-win
66 */
67
68 bool QWindowsInternalMimeData::hasFormat_sys(const QString &mime) const
69 {
70     IDataObject *pDataObj = retrieveDataObject();
71     if (!pDataObj)
72         return false;
73
74     const QWindowsMimeConverter &mc = QWindowsContext::instance()->mimeConverter();
75     const bool has = mc.converterToMime(mime, pDataObj) != 0;
76     releaseDataObject(pDataObj);
77     if (QWindowsContext::verboseOLE)
78         qDebug() << __FUNCTION__ <<  mime << has;
79     return has;
80 }
81
82 QStringList QWindowsInternalMimeData::formats_sys() const
83 {
84     IDataObject *pDataObj = retrieveDataObject();
85     if (!pDataObj)
86         return QStringList();
87
88     const QWindowsMimeConverter &mc = QWindowsContext::instance()->mimeConverter();
89     const QStringList fmts = mc.allMimesForFormats(pDataObj);
90     releaseDataObject(pDataObj);
91     if (QWindowsContext::verboseOLE)
92         qDebug() << __FUNCTION__ <<  fmts;
93     return fmts;
94 }
95
96 QVariant QWindowsInternalMimeData::retrieveData_sys(const QString &mimeType,
97                                                         QVariant::Type type) const
98 {
99     IDataObject *pDataObj = retrieveDataObject();
100     if (!pDataObj)
101         return QVariant();
102
103     QVariant result;
104     const QWindowsMimeConverter &mc = QWindowsContext::instance()->mimeConverter();
105     if (const QWindowsMime *converter = mc.converterToMime(mimeType, pDataObj))
106         result = converter->convertToMime(mimeType, pDataObj, type);
107     releaseDataObject(pDataObj);
108     if (QWindowsContext::verboseOLE) {
109         QDebug nospace = qDebug().nospace();
110         nospace << __FUNCTION__ <<  ' '  << mimeType << ' ' << type
111                 << " returns " << result.type();
112         if (result.type() != QVariant::ByteArray)
113             nospace << ' ' << result;
114     }
115     return result;
116 }