Changeset 96


Ignore:
Timestamp:
Jul 6, 2006, 11:11:46 PM (19 years ago)
Author:
dmik
Message:

QTextDrag: decode() gives mime types in Unicode encodings a higher priprity (to guarantee loseless decoding); "text/whatever" w/o any charset is reported as the first mime format (for better integration with native drop targets).

Location:
trunk/src/kernel
Files:
2 edited

Legend:

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

    r20 r96  
    156156    }
    157157
    158     // Not efficient to iterate over this (so we provide provides() above).
    159 
    160     // In order to be able to use UniCode characters, we have to give
    161     // it a higher priority than single-byte characters.  To do this, we
    162     // treat CF_TEXT as a special case and postpone its processing until
    163     // we're sure we do not have CF_TextUnicode ("text/unicode" atom)
    164158    const char* format( int n ) const
    165159    {
    166160        const char* mime = 0;
    167         bool sawText = false;
    168161
    169162        if ( n >= 0 ) {
     
    171164                ulong cf = 0;
    172165                while ( (cf = WinEnumClipbrdFmts( 0, cf )) ) {
    173                     if ( cf == CF_TEXT ) {
    174                         sawText = true;
    175                     } else {
    176                         mime = QPMMime::cfToMime( cf );
    177                         if ( mime ) {
    178                             if ( !n )
    179                                 break; // COME FROM HERE
    180                             n--;
    181                             mime = 0;
    182                         }
    183                     }
    184                 }
    185                 // COME FROM BREAK
    186 
    187                 // If we did not find a suitable mime type, yet skipped
    188                 // CF_TEXT due to the priorities above, give it a shot
    189                 if ( !mime && sawText && !n ) {
    190                     mime = QPMMime::cfToMime( CF_TEXT );
     166                    mime = QPMMime::cfToMime( cf );
     167                    if ( mime ) {
     168                        if ( !n )
     169                            break;
     170                        n--;
     171                        mime = 0;
     172                    }
    191173                }
    192174                WinCloseClipbrd( 0 );
     
    617599                    }
    618600                }
     601                // Don't search for other formats for the same mime type --
     602                // we've already represented it in the clipboard and adding a
     603                // new format would just introduce mime type duplicates on the
     604                // clipboard reader's side (where the first encountered format
     605                // would be used for actual data transfer anyway).
     606                // See also QDragManager::drag().
     607                break;
    619608            }
    620609        }
  • trunk/src/kernel/qdragobject.cpp

    r8 r96  
    607607
    608608    switch ( i ) {
     609#if defined(Q_WS_PM)
     610      // We want "text/whatever" w/o any charset to be the first (the "default")
     611      // mime type of the QTextDrag object, so that a rendering mechanism/format
     612      // pair for it will be the first in the RMF list, wchich is essential for
     613      // some native drop targets (i.e. WPS) to render text correctly. Note that
     614      // it won't hide unicode data from Qt apps because QTextDrag::decode()
     615      // for Q_WS_PM prefers unicode mime types (see the implementation below).
     616      case 0:
     617        return "";
     618      case 1:
     619        if ( localcharset.isNull() ) {
     620            QTextCodec *localCodec = QTextCodec::codecForLocale();
     621            if ( localCodec ) {
     622                localcharset = localCodec->name();
     623                localcharset = localcharset.lower();
     624                stripws(localcharset);
     625            } else {
     626                localcharset = "";
     627            }
     628        }
     629        return localcharset;
     630      case 2:
     631        return "UTF-8";
     632      case 3:
     633        return "ISO-10646-UCS-2";
     634#else
    609635      case 0:
    610636        return "UTF-8";
     
    625651        }
    626652        return localcharset;
     653#endif       
    627654    }
    628655    return 0;
     
    898925    }
    899926
     927#if defined(Q_WS_PM)
     928    // We give Unicode formats a higher priority, so that if there are several
     929    // encodings of the same subtype present in the given mime source, a
     930    // Unicode one will be used for decoding. Otherwise, the first recognized
     931    // format will be choosen.
     932    int fallbackMime = -1;
     933    bool secondPass = FALSE;
     934
     935    const char *mime;
     936    for( int i = 0; /* FOREVER */; ++i ) {
     937        mime = e->format( i );
     938        if ( !mime ) {
     939            // We went through all mimes but didn't find Unicode. If there is
     940            // a fall-back mime, iterate again starting directly from it.
     941            if ( !secondPass && fallbackMime >= 0 ) {
     942                i = fallbackMime - 1; // will do ++i on continue
     943                secondPass = TRUE;
     944                continue;
     945            }
     946            break;
     947        }
     948#else       
    900949    const char* mime;
    901950    for (int i=0; (mime = e->format(i)); i++) {
     951#endif   
    902952        if ( 0==qstrnicmp(mime,"text/",5) ) {
    903953            QCString m(mime);
     
    916966                    codec = qt_findcharset(m);
    917967                if ( codec ) {
     968#if defined(Q_WS_PM)
     969                    if ( codec->mibEnum() == 1000 /* ISO-10646-UCS-2 */ ||
     970                         codec->mibEnum() == 106 /* UTF-8 */ ) {
     971                        // no need to try it again on the second pass
     972                        if ( secondPass )
     973                            continue;
     974                    } else if ( !secondPass ) {
     975                        // memorize the fall-back mime on the first pass
     976                        if ( fallbackMime < 0 )
     977                            fallbackMime = i;
     978                        continue;
     979                    }
     980#endif
    918981                    QByteArray payload;
    919 
    920982                    payload = e->encodedData(mime);
    921983                    if ( payload.size() ) {
Note: See TracChangeset for help on using the changeset viewer.