- Timestamp:
- Nov 16, 2009, 1:06:34 AM (16 years ago)
- Location:
- trunk/src/gui/kernel
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/kernel/kernel.pri
r95 r323 98 98 kernel/qdesktopwidget_pm.cpp \ 99 99 kernel/qdnd_pm.cpp \ 100 kernel/qmime_pm.cpp \ 100 101 kernel/qkeymapper_pm.cpp \ 101 102 kernel/qsound_pm.cpp \ -
trunk/src/gui/kernel/qclipboard_pm.cpp
r322 r323 55 55 #include "qdnd_p.h" 56 56 57 #define QCLIPBOARD_DEBUG 58 57 59 QT_BEGIN_NAMESPACE 58 60 … … 75 77 ULONG cf = 0; 76 78 while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf))) { 77 //if (QPMMime::converterToMime(mime, cf)) {78 //ok = true;79 //break;80 //}79 if (QPMMime::converterToMime(mime, cf)) { 80 ok = true; 81 break; 82 } 81 83 } 82 84 WinCloseClipbrd(NULLHANDLE); … … 94 96 QStringList fmts; 95 97 if (WinOpenClipbrd(NULLHANDLE)) { 96 // fmts = QPMMime::allMimesForFormats(); 98 QVector<ULONG> cfs; 99 ULONG cf = 0; 100 while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf))) 101 cfs << cf; 102 fmts = QPMMime::allMimesForFormats(cfs); 97 103 WinCloseClipbrd(NULLHANDLE); 98 104 } … … 108 114 QVariant::Type type) const 109 115 { 110 QStringList fmts; 116 QVariant result; 117 111 118 if (WinOpenClipbrd(NULLHANDLE)) { 112 // @todo enumerate all formats and select the best converter 113 // QPMMime *converter = QPMMime::converterToMime(mime, cf); 114 // if (converter) 115 // result = converter->convertToMime(mime, cf, type); 119 ULONG cf = 0; 120 while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf))) { 121 QPMMime *converter = QPMMime::converterToMime(mime, cf); 122 if (converter) { 123 ULONG flags; 124 if (WinQueryClipbrdFmtInfo(NULLHANDLE, cf, &flags)) { 125 ULONG data = WinQueryClipbrdData(NULLHANDLE, cf); 126 if (data) { 127 result = converter->convertToMime(mime, type, cf, flags, data); 128 } 129 } 130 break; 131 } 132 } 116 133 WinCloseClipbrd(NULLHANDLE); 117 134 } … … 121 138 WinGetLastError(NULLHANDLE)); 122 139 #endif 123 return fmts;140 return result; 124 141 } 125 142 … … 171 188 void QClipboard::setMimeData(QMimeData *src, Mode mode) 172 189 { 173 // @todo implement 190 if (mode != Clipboard) 191 return; 192 193 if (!WinOpenClipbrd(NULLHANDLE)) { 194 #ifndef QT_NO_DEBUG 195 qWarning("QClipboard: WinOpenClipbrd failed with %lX", 196 WinGetLastError(NULLHANDLE)); 197 #endif 198 return; 199 } 200 201 // @todo 202 // QClipboardData *d = clipboardData(); 203 // d->setSource(src); 204 205 WinCloseClipbrd(NULLHANDLE); 174 206 } 175 207 -
trunk/src/gui/kernel/qmime.h
r321 r323 114 114 */ 115 115 116 typedef unsigned long ULONG; 117 116 118 class Q_GUI_EXPORT QPMMime 117 119 { … … 119 121 QPMMime(); 120 122 virtual ~QPMMime(); 123 124 // for converting from Qt 125 virtual bool canConvertFromMime(ULONG format, const QMimeData *mimeData) const = 0; 126 virtual bool convertFromMime(ULONG format, const QMimeData *mimeData, 127 ULONG &flags, ULONG &data) const = 0; 128 virtual QVector<ULONG> formatsForMime(const QString &mimeType, const QMimeData *mimeData) const = 0; 129 130 // for converting to Qt 131 virtual bool canConvertToMime(const QString &mimeType, ULONG format) const = 0; 132 virtual QVariant convertToMime(const QString &mimeType, QVariant::Type preferredType, 133 ULONG format, ULONG flags, ULONG data) const = 0; 134 virtual QString mimeForFormat(ULONG format) const = 0; 135 136 static ULONG registerMimeType(const QString &mime); 137 138 private: 139 friend class QClipboardWatcher; 140 141 static QPMMime *converterToMime(const QString &mimeType, ULONG format); 142 static QStringList allMimesForFormats(const QVector<ULONG> &formats); 143 static QPMMime *converterFromMime(ULONG format, const QMimeData *mimeData); 144 static QVector<ULONG> allFormatsForMime(const QMimeData *mimeData); 121 145 }; 122 146 -
trunk/src/gui/kernel/qmime_pm.cpp
r321 r323 60 60 #include "qdir.h" 61 61 62 #define QMIME_DEBUG 63 62 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 63 83 64 84 /*! … … 99 119 */ 100 120 101 // @todo lots of stuff... 102 121 /*! 122 Constructs a new conversion object, adding it to the globally accessed 123 list of available converters. 124 */ 103 125 QPMMime::QPMMime() 104 126 { 105 } 106 127 theMimeList()->addMime(this); 128 } 129 130 /*! 131 Destroys a conversion object, removing it from the global 132 list of available converters. 133 */ 107 134 QPMMime::~QPMMime() 108 135 { 136 theMimeList()->removeMime(this); 137 } 138 139 /*! 140 Registers the MIME type \a mime, and returns an ID number 141 identifying the format on OS/2. 142 */ 143 ULONG QPMMime::registerMimeType(const QString &mime) 144 { 145 QString atom = QLatin1String("mime:") + mime; 146 147 ULONG cf = WinAddAtom(WinQuerySystemAtomTable(), atom.toLocal8Bit()); 148 if (!cf) { 149 #ifndef QT_NO_DEBUG 150 qWarning("QPMMime: WinAddAtom failed with %lX", 151 WinGetLastError(NULLHANDLE)); 152 #endif 153 return 0; 154 } 155 156 return cf; 157 } 158 159 /*! 160 \fn bool QPMMime::canConvertFromMime(ULONG format, const QMimeData *mimeData) const 161 162 Returns true if the converter can convert from the \a mimeData to 163 the specified \a format. 164 165 All subclasses must reimplement this pure virtual function. 166 */ 167 168 /*! 169 \fn bool QPMMime::convertFromMime(ULONG format, const QMimeData *mimeData, 170 ULONG &flags, ULONG &data) const 171 172 Convert the \a mimeData to the specified \a format. 173 The converted data should then be placed in the \a data variable with the 174 necessary flags returned in the \a flags variable. 175 176 Return true if the conversion was successful. 177 178 All subclasses must reimplement this pure virtual function. 179 */ 180 181 /*! 182 \fn QVector<ULONG> QPMMime::formatsForMime(const QString &mimeType, const QMimeData *mimeData) const 183 184 Returns a QVector of ULONG values representing the different OS/2 PM clipboard 185 formats that can be provided for the \a mimeType from the \a mimeData. 186 187 All subclasses must reimplement this pure virtual function. 188 */ 189 190 /*! 191 \fn bool QPMMime::canConvertToMime(const QString &mimeType, ULONG format) const 192 193 Returns true if the converter can convert to the \a mimeType from 194 the specified \a format. 195 196 All subclasses must reimplement this pure virtual function. 197 */ 198 199 /*! 200 \fn QVariant QPMMime::convertToMime(const QString &mimeType, QVariant::Type preferredType, 201 ULONG format, ULONG flags, ULONG data) const 202 203 Returns a QVariant containing the converted data for \a mimeType from the 204 \a data in the specified \a format and \a flags. If possible the QVariant 205 should be of the \a preferredType to avoid needless conversions. 206 207 All subclasses must reimplement this pure virtual function. 208 */ 209 210 /*! 211 \fn QString QPMMime::mimeForFormat(ULONG format) const 212 213 Returns the mime type that will be created form the specified \a format, or an 214 empty string if this converter does not support \a format. 215 216 All subclasses must reimplement this pure virtual function. 217 */ 218 219 // static 220 QPMMime *QPMMime::converterToMime(const QString &mimeType, ULONG format) 221 { 222 QList<QPMMime*> mimes = theMimeList()->mimes(); 223 for (int i = mimes.size()-1; i >= 0; --i) { 224 if (mimes.at(i)->canConvertToMime(mimeType, format)) 225 return mimes.at(i); 226 } 227 return 0; 228 } 229 230 // static 231 QStringList QPMMime::allMimesForFormats(const QVector<ULONG> &formats) 232 { 233 QList<QPMMime*> mimes = theMimeList()->mimes(); 234 QStringList fmts; 235 236 foreach(ULONG cf, formats) { 237 #ifdef QMIME_DEBUG 238 HATOMTBL tbl = WinQuerySystemAtomTable(); 239 ULONG len = WinQueryAtomLength(tbl, cf); 240 QByteArray atom(len, 0); 241 WinQueryAtomName(tbl, cf, atom.data(), atom.size() + 1 /* '\0' */); 242 qDebug("QPMMime::allMimesForFormats() CF %lu (%s)", cf, atom.constData()); 243 #endif 244 for (int i = mimes.size()-1; i >= 0; --i) { 245 QString format = mimes.at(i)->mimeForFormat(cf); 246 if (!format.isEmpty() && !fmts.contains(format)) { 247 fmts += format; 248 } 249 } 250 } 251 252 return fmts; 253 } 254 255 // static 256 QPMMime *QPMMime::converterFromMime(ULONG format, const QMimeData *mimeData) 257 { 258 QList<QPMMime*> mimes = theMimeList()->mimes(); 259 for (int i = mimes.size()-1; i >= 0; --i) { 260 if (mimes.at(i)->canConvertFromMime(format, mimeData)) 261 return mimes.at(i); 262 } 263 return 0; 264 } 265 266 // static 267 QVector<ULONG> QPMMime::allFormatsForMime(const QMimeData *mimeData) 268 { 269 QList<QPMMime*> mimes = theMimeList()->mimes(); 270 QVector<ULONG> cfs(4); 271 QStringList formats = QInternalMimeData::formatsHelper(mimeData); 272 for (int f = 0; f < formats.size(); ++f) { 273 for (int i = mimes.size()-1; i >= 0; --i) 274 cfs += mimes.at(i)->formatsForMime(formats.at(f), mimeData); 275 } 276 return cfs; 277 } 278 279 //////////////////////////////////////////////////////////////////////////////// 280 281 //////////////////////////////////////////////////////////////////////////////// 282 283 QPMMimeList::QPMMimeList() 284 : initialized(false) 285 { 286 } 287 288 QPMMimeList::~QPMMimeList() 289 { 290 while (list.size()) 291 delete list.first(); 292 } 293 294 295 void QPMMimeList::init() 296 { 297 if (!initialized) { 298 initialized = true; 299 // @todo new QPMMimeXXX; 300 } 301 } 302 303 void QPMMimeList::addMime(QPMMime *mime) 304 { 305 init(); 306 list.append(mime); 307 } 308 309 void QPMMimeList::removeMime(QPMMime *mime) 310 { 311 init(); 312 list.removeAll(mime); 313 } 314 315 QList<QPMMime*> QPMMimeList::mimes() 316 { 317 init(); 318 return list; 109 319 } 110 320
Note:
See TracChangeset
for help on using the changeset viewer.