1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** Copyright (C) 2009 netlabs.org. OS/2 parts.
|
---|
7 | **
|
---|
8 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
9 | **
|
---|
10 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
11 | ** Commercial Usage
|
---|
12 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
13 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
14 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
15 | ** a written agreement between you and Nokia.
|
---|
16 | **
|
---|
17 | ** GNU Lesser General Public License Usage
|
---|
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
19 | ** General Public License version 2.1 as published by the Free Software
|
---|
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
21 | ** packaging of this file. Please review the following information to
|
---|
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
24 | **
|
---|
25 | ** In addition, as a special exception, Nokia gives you certain
|
---|
26 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
27 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
28 | ** package.
|
---|
29 | **
|
---|
30 | ** GNU General Public License Usage
|
---|
31 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
32 | ** General Public License version 3.0 as published by the Free Software
|
---|
33 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
34 | ** packaging of this file. Please review the following information to
|
---|
35 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
36 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
37 | **
|
---|
38 | ** If you are unsure which license is appropriate for your use, please
|
---|
39 | ** contact the sales department at [email protected].
|
---|
40 | ** $QT_END_LICENSE$
|
---|
41 | **
|
---|
42 | ****************************************************************************/
|
---|
43 |
|
---|
44 | #include "qmime.h"
|
---|
45 |
|
---|
46 | #include "qimagereader.h"
|
---|
47 | #include "qimagewriter.h"
|
---|
48 | #include "qdatastream.h"
|
---|
49 | #include "qbuffer.h"
|
---|
50 | #include "qt_os2.h"
|
---|
51 | #include "qapplication_p.h"
|
---|
52 | #include "qtextcodec.h"
|
---|
53 | #include "qregexp.h"
|
---|
54 | #include "qalgorithms.h"
|
---|
55 | #include "qmap.h"
|
---|
56 | #include "qdnd_p.h"
|
---|
57 | #include "qurl.h"
|
---|
58 | #include "qvariant.h"
|
---|
59 | #include "qtextdocument.h"
|
---|
60 | #include "qdir.h"
|
---|
61 |
|
---|
62 | #define QMIME_DEBUG
|
---|
63 |
|
---|
64 | QT_BEGIN_NAMESPACE
|
---|
65 |
|
---|
66 | class QPMMimeList
|
---|
67 | {
|
---|
68 | public:
|
---|
69 | QPMMimeList();
|
---|
70 | ~QPMMimeList();
|
---|
71 | void addMime(QPMMime *mime);
|
---|
72 | void removeMime(QPMMime *mime);
|
---|
73 | QList<QPMMime*> mimes();
|
---|
74 |
|
---|
75 | private:
|
---|
76 | void init();
|
---|
77 | bool initialized;
|
---|
78 | QList<QPMMime*> list;
|
---|
79 | };
|
---|
80 |
|
---|
81 | Q_GLOBAL_STATIC(QPMMimeList, theMimeList);
|
---|
82 |
|
---|
83 |
|
---|
84 | /*!
|
---|
85 | \class QPMMime
|
---|
86 | \brief The QMPMime class maps open-standard MIME to OS/2 PM Clipboard
|
---|
87 | formats.
|
---|
88 | \ingroup io
|
---|
89 | \ingroup draganddrop
|
---|
90 | \ingroup misc
|
---|
91 |
|
---|
92 | Qt's drag-and-drop and clipboard facilities use the MIME standard.
|
---|
93 | On X11, this maps trivially to the Xdnd protocol, but on OS/2
|
---|
94 | although some applications use MIME types to describe clipboard
|
---|
95 | formats, others use arbitrary non-standardized naming conventions,
|
---|
96 | or unnamed built-in formats of the Presentation Manager.
|
---|
97 |
|
---|
98 | By instantiating subclasses of QPMMime that provide conversions between OS/2
|
---|
99 | PM Clipboard and MIME formats, you can convert proprietary clipboard formats
|
---|
100 | to MIME formats.
|
---|
101 |
|
---|
102 | Qt has predefined support for the following PM Clipboard formats:
|
---|
103 |
|
---|
104 | \table
|
---|
105 | \header \o PM Format \o Equivalent MIME type
|
---|
106 | \row \o \c CF_TEXT \o \c text/plain
|
---|
107 | \row \o \c CF_BITMAP \o \c{image/xyz}, where \c xyz is
|
---|
108 | a \l{QImageWriter::supportedImageFormats()}{Qt image format}
|
---|
109 | \endtable
|
---|
110 |
|
---|
111 | An example use of this class would be to map the PM Metafile
|
---|
112 | clipboard format (\c CF_METAFILE) to and from the MIME type
|
---|
113 | \c{image/x-metafile}. This conversion might simply be adding or removing a
|
---|
114 | header, or even just passing on the data. See \l{Drag and Drop} for more
|
---|
115 | information on choosing and definition MIME types.
|
---|
116 | */
|
---|
117 |
|
---|
118 | /*!
|
---|
119 | Constructs a new conversion object, adding it to the globally accessed
|
---|
120 | list of available converters.
|
---|
121 | */
|
---|
122 | QPMMime::QPMMime()
|
---|
123 | {
|
---|
124 | theMimeList()->addMime(this);
|
---|
125 | }
|
---|
126 |
|
---|
127 | /*!
|
---|
128 | Destroys a conversion object, removing it from the global
|
---|
129 | list of available converters.
|
---|
130 | */
|
---|
131 | QPMMime::~QPMMime()
|
---|
132 | {
|
---|
133 | theMimeList()->removeMime(this);
|
---|
134 | }
|
---|
135 |
|
---|
136 | /*!
|
---|
137 | Registers the MIME type \a mime, and returns an ID number
|
---|
138 | identifying the format on OS/2. Intended to be used by QPMMime
|
---|
139 | implementations for registering custom clipboard formats they use.
|
---|
140 | */
|
---|
141 | // static
|
---|
142 | ULONG QPMMime::registerMimeType(const QString &mime)
|
---|
143 | {
|
---|
144 | ULONG cf = WinAddAtom(WinQuerySystemAtomTable(), mime.toLocal8Bit());
|
---|
145 | if (!cf) {
|
---|
146 | #ifndef QT_NO_DEBUG
|
---|
147 | qWarning("QPMMime: WinAddAtom failed with %lX",
|
---|
148 | WinGetLastError(NULLHANDLE));
|
---|
149 | #endif
|
---|
150 | return 0;
|
---|
151 | }
|
---|
152 |
|
---|
153 | return cf;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /*!
|
---|
157 | Allocates a block of shared memory of the given size and returns the address
|
---|
158 | of this block. This memory block may be then filled with data and returned
|
---|
159 | by convertFromMimeData() as the value of the CFI_POINTER type.
|
---|
160 | */
|
---|
161 | // static
|
---|
162 | ULONG QPMMime::allocateMemory(size_t size)
|
---|
163 | {
|
---|
164 | if (size == 0)
|
---|
165 | return 0;
|
---|
166 |
|
---|
167 | ULONG data = 0;
|
---|
168 |
|
---|
169 | // allocate giveable memory for the array + dword for its size
|
---|
170 | APIRET arc = DosAllocSharedMem((PVOID *)&data, NULL, size + 4,
|
---|
171 | PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE);
|
---|
172 | if (arc != NO_ERROR) {
|
---|
173 | #ifndef QT_NO_DEBUG
|
---|
174 | qWarning("QPMMime::allocateMemory: DosAllocSharedMem failed with %lu", arc);
|
---|
175 | #endif
|
---|
176 | return 0;
|
---|
177 | }
|
---|
178 |
|
---|
179 | /// @todo I think we don't need it any more
|
---|
180 | #if 0
|
---|
181 | // get the size rounded to the page boundary (4K)
|
---|
182 | ULONG sz = ~0, flags = 0;
|
---|
183 | arc = DosQueryMem((PVOID)(data + size - 1), &sz, &flags);
|
---|
184 | if (arc != NO_ERROR) {
|
---|
185 | #ifndef QT_NO_DEBUG
|
---|
186 | qWarning("QPMMime::allocateMemory: DosQueryMem failed with %lu", arc);
|
---|
187 | #endif
|
---|
188 | DosFreeMem((PVOID)data);
|
---|
189 | return 0;
|
---|
190 | }
|
---|
191 | sz += (size - 1);
|
---|
|
---|