Changeset 324 for trunk/src/gui/kernel


Ignore:
Timestamp:
Nov 18, 2009, 1:49:31 AM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

gui/kernel: Improved mime <-> PM clipboard format conversion interfaces.

Location:
trunk/src/gui/kernel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/kernel/qclipboard_pm.cpp

    r323 r324  
    5252#include "qevent.h"
    5353#include "qmime.h"
     54
     55
    5456#include "qt_os2.h"
    55 #include "qdnd_p.h"
     57#include "_p.h"
    5658
    5759#define QCLIPBOARD_DEBUG
    5860
     61
     62
     63
     64
    5965QT_BEGIN_NAMESPACE
    6066
     
    6470{
    6571public:
    66     QClipboardWatcher() {}
     72    QClipboardWatcher() {}
    6773
    6874    bool hasFormat_sys(const QString &mimetype) const;
    6975    QStringList formats_sys() const;
    7076    QVariant retrieveData_sys(const QString &mimetype, QVariant::Type preferredType) const;
     77
     78
     79
     80
     81
     82
     83
     84
    7185};
    7286
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
    73111bool QClipboardWatcher::hasFormat_sys(const QString &mime) const
    74112{
    75     bool ok = false;
    76     if (WinOpenClipbrd(NULLHANDLE)) {
    77         ULONG cf = 0;
    78         while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf))) {
    79             if (QPMMime::converterToMime(mime, cf)) {
    80                 ok = true;
    81                 break;
    82             }
    83         }
    84         WinCloseClipbrd(NULLHANDLE);
    85     }
    86 #ifndef QT_NO_DEBUG
    87     else
    88         qWarning("QClipboardWatcher: WinOpenClipbrd failed with %lX",
    89                  WinGetLastError(NULLHANDLE));
    90 #endif
    91     return ok;
     113    peekData();
     114    if (isDirty)
     115        return false; // peekData() failed
     116
     117    foreach (QPMMime::Match match, matches)
     118        if (match.mime == mime)
     119            return true;
     120
     121    return false;
    92122}
    93123
     
    95125{
    96126    QStringList fmts;
    97     if (WinOpenClipbrd(NULLHANDLE)) {
    98         QVector<ULONG> cfs;
    99         ULONG cf = 0;
    100         while ((cf = WinEnumClipbrdFmts(NULLHANDLE, cf)))
    101             cfs << cf;
    102         fmts = QPMMime::allMimesForFormats(cfs);
    103         WinCloseClipbrd(NULLHANDLE);
    104     }
    105 #ifndef QT_NO_DEBUG
    106     else
    107         qWarning("QClipboardWatcher: WinOpenClipbrd failed with %lX",
    108                  WinGetLastError(NULLHANDLE));
    109 #endif
     127
     128    peekData();
     129    if (isDirty)
     130        return fmts; // peekData() failed
     131
     132    foreach (QPMMime::Match match, matches)
     133        fmts << match.mime;
     134
    110135    return fmts;
    111136}
     
    116141    QVariant result;
    117142
    118     if (WinOpenClipbrd(NULLHANDLE)) {
    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;
     143    peekData();
     144    if (isDirty)
     145        return result; // peekData() failed
     146
     147    foreach (QPMMime::Match match, matches) {
     148        if (match.mime == mime) {
     149            ULONG flags;
     150            if (WinQueryClipbrdFmtInfo(NULLHANDLE, match.format, &flags)) {
     151                ULONG data = WinQueryClipbrdData(NULLHANDLE, match.format);
     152                result = match.converter->convertFromFormat(match.format, flags,
     153                                                            data, match.mime, type);
    131154            }
     155
    132156        }
    133         WinCloseClipbrd(NULLHANDLE);
    134     }
    135 #ifndef QT_NO_DEBUG
    136     else
    137         qWarning("QClipboardWatcher: WinOpenClipbrd failed with %lX",
    138                  WinGetLastError(NULLHANDLE));
    139 #endif
     157    }
     158
    140159    return result;
    141160}
     
    143162////////////////////////////////////////////////////////////////////////////////
    144163
    145 class QClipboardData
     164class QClipboardData
    146165{
    147166public:
     
    149168    ~QClipboardData();
    150169
    151     // @todo ...
     170    void setSource(QMimeData *s)
     171    {
     172        if (s == src)
     173            return;
     174        delete src;
     175        src = s;
     176    }
     177
     178    QMimeData *source()
     179    {
     180        return src;
     181    }
     182
     183    bool setClipboard(QPMMime *converter, ULONG format, bool isDelayed);
     184
     185    MRESULT message(ULONG msg, MPARAM mp1, MPARAM mp2);
    152186
    153187private:
     188
    154189};
    155190
    156 QClipboardData::QClipboardData()
     191QClipboardData::QClipboardData()
    157192{
    158193}