Changeset 337


Ignore:
Timestamp:
Nov 22, 2009, 9:48:35 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

gui/kernel: mime: Implemented the fallback mime <-> clipboard converter for mime types not explicitly supported by specialized QPMMime implementations (see #28).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/kernel/qmime.h

    r334 r337  
    135135                                       QVariant::Type preferredType) const = 0;
    136136
     137
     138
    137139    static ULONG registerMimeType(const QString &mime);
    138140
    139141    static ULONG allocateMemory(size_t size);
    140142    static void freeMemory(ULONG addr);
     143
     144
    141145
    142146private:
  • trunk/src/gui/kernel/qmime_pm.cpp

    r335 r337  
    100100    to MIME formats.
    101101
    102     Qt has predefined support for the following PM Clipboard formats:
     102    Qt has predefined support for the following PM Clipboard formats (custom
     103    formats registered in the system atom table by name are given in double
     104    quotes):
    103105
    104106    \table
    105107    \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}
     108    \row \o \c CF_TEXT          \o \c text/plain (system codepage,
     109                                   zero-terminated string)
     110    \row \o \c "text/unicode"   \o \c text/plain (16-bit Unicode, Mozilla-compatible,
     111                                   zero-terminated string)
     112    \row \o \c CF_BITMAP        \o \c{image/xyz}, where \c xyz is
     113                                    a \l{QImageWriter::supportedImageFormats()}{Qt image format}
     114    \row \o \c "x-mime:<mime>"  \o data in the format corresponding to the given
     115                                   MIME type \c <mime>
    109116    \endtable
    110117
    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
     118    Note that all "x-mime:<mime>" formats use the CFI_POINTER storage type. That
     119    is, the clipboard contains a pointer to the memory block containing the MIME
     120    data in the corresponding format. The first 4 bytes of this memory block
     121    always contain the length of the subsequent MIME data array, in bytes.
     122
     123    An example use of this class by the user application would be to map the
     124    PM Metafile clipboard format (\c CF_METAFILE) to and from the MIME type
    113125    \c{image/x-metafile}. This conversion might simply be adding or removing a
    114126    header, or even just passing on the data. See \l{Drag and Drop} for more
     
    167179    ULONG data = 0;
    168180
    169     // allocate giveable memory for the array + dword for its size
    170     APIRET arc = DosAllocSharedMem((PVOID *)&data, NULL, size + 4,
     181    // allocate giveable memory for the array
     182    APIRET arc = DosAllocSharedMem((PVOID *)&data, NULL, size,
    171183                                   PAG_WRITE  | PAG_COMMIT | OBJ_GIVEABLE);
    172184    if (arc != NO_ERROR) {
     
    177189    }
    178190
    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);
    192     // store the exact size to the last dword of the last page
    193     *(((ULONG *)(data + sz)) - 1) = size;
    194 #endif
    195 
    196191    return data;
    197192}
     
    226221    Converts the \a mimeData to the specified \a format.
    227222
    228     If \a data is not NULL, a handle to the converted data should then be placed
     223    If \a data is not NULL, a handle to the converted data should placed
    229224    in a variable pointed to by \a data and with the necessary flags describing
    230225    the handle returned in the \a flags variable.
    231226
    232     The following flags describing the data type are recognized:
     227    The following flags describing the data type are recognized:
    233228
    234229    \table
     
    280275
    281276    QList<QPMMime*> mimes = theMimeList()->mimes();
    282     for (int i = mimes.size()-1; i >= 0; --i) {
    283         QList<MimeCFPair> fmts = mimes[i]->mimesForFormats(formats);
     277    for) {
     278        QList<MimeCFPair> fmts = mime->mimesForFormats(formats);
    284279        int priority = 0;
    285280        foreach (MimeCFPair fmt, fmts) {
     
    291286                    // replace if priority is higher, ignore otherwise
    292287                    if (priority < match.priority) {
    293                         match.converter = mimes[i];
     288                        match.converter = mime;
    294289                        match.format = fmt.second;
    295290                        match.priority = priority;
     
    299294            }
    300295            if (it == matches.end()) {
    301                 matches += Match(mimes[i], fmt.first, fmt.second, priority);
     296                matches += Match(mime, fmt.first, fmt.second, priority);
    302297            }
    303298        }
     
    313308
    314309    QList<QPMMime*> mimes = theMimeList()->mimes();
    315     for (int i = mimes.size()-1; i >= 0; --i) {
    316         QList<ULONG> cfs = mimes[i]->formatsForMimeData(mimeData);
     310    for) {
     311        QList<ULONG> cfs = mime->formatsForMimeData(mimeData);
    317312        int priority = 0;
    318313        foreach (ULONG cf, cfs) {
     
    324319                    // replace if priority is higher, ignore otherwise
    325320                    if (priority < match.priority) {
    326                         match.converter = mimes[i];
     321                        match.converter = mime;
    327322                        match.priority = priority;
    328323                    }
     
    331326            }
    332327            if (it == matches.end()) {
    333                 matches += Match(mimes[i], cf, priority);
     328                matches += Match(mime, cf, priority);
    334329            }
    335330        }
     
    337332
    338333    return matches;
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
    339347}
    340348
     
    346354    QPMMimeText();
    347355
     356
    348357    QList<ULONG> formatsForMimeData(const QMimeData *mimeData) const;
    349358    bool convertFromMimeData(const QMimeData *mimeData, ULONG format,
    350359                             ULONG &flags, ULONG *data) const;
    351360
     361
    352362    QList<MimeCFPair> mimesForFormats(const QList<ULONG> &formats) const;
    353363    QVariant convertFromFormat(ULONG format, ULONG flags, ULONG data,
     
    519529////////////////////////////////////////////////////////////////////////////////
    520530
     531
     532
     533
     534
     535
     536
     537
     538
     539
     540
     541
     542
     543
     544
     545
     546
     547
     548
     549
     550
     551
     552
     553
     554
     555
     556
     557
     558
     559
     560
     561
     562
     563
     564
     565
     566
     567
     568
     569
     570
     571
     572
     573
     574
     575
     576
     577
     578
     579
     580
     581
     582
     583
     584
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596
     597
     598
     599
     600
     601
     602
     603
     604
     605
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
     628
     629
     630
     631
     632
     633
     634
     635
     636
     637
     638
     639
     640
     641
     642
     643
     644
     645
     646
     647
     648
     649
     650
     651
     652
     653
     654
     655
     656
     657
     658
     659
     660
     661
     662
     663
     664
     665
     666
     667
     668
     669
     670
     671
     672
     673
     674
     675
     676
     677
     678
     679
     680
     681
     682
     683
     684
     685
     686
     687
     688
     689
     690
     691
     692
     693
     694
     695
     696
     697
     698
     699
     700
     701
     702
     703
     704
     705
     706
     707
     708
     709
     710
     711
     712
     713
     714
     715
     716
     717
     718
     719
     720
    521721QPMMimeList::QPMMimeList()
    522722    : initialized(false)
     
    535735    if (!initialized) {
    536736        initialized = true;
     737
    537738        new QPMMimeText;
    538739    }
     
    542743{
    543744    init();
    544     list.append(mime);
     745    list.pend(mime);
    545746}
    546747
Note: See TracChangeset for help on using the changeset viewer.