From 628b0bb74c3fc327efff8add9c73ada04b1cbea2 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 7 Jul 2024 13:06:00 +0900 Subject: Rename drag-n-drop nt* related files to equivalent tq* Signed-off-by: Michele Calgaro --- src/dialogs/qcolordialog.cpp | 2 +- src/dialogs/qfiledialog.cpp | 4 +- src/kernel/ntqdragobject.h | 279 ------- src/kernel/ntqdropsite.h | 59 -- src/kernel/ntqevent.h | 2 +- src/kernel/ntqmime.h | 200 ----- src/kernel/ntqt.h | 6 +- src/kernel/qapplication.cpp | 2 +- src/kernel/qclipboard.cpp | 2 +- src/kernel/qclipboard_x11.cpp | 2 +- src/kernel/qdnd_x11.cpp | 2 +- src/kernel/qdragobject.cpp | 1811 ---------------------------------------- src/kernel/qdropsite.cpp | 81 -- src/kernel/qmime.cpp | 619 -------------- src/kernel/qpixmap.cpp | 4 +- src/kernel/qrichtext.cpp | 4 +- src/kernel/qt_kernel.pri | 16 +- src/kernel/tqdragobject.cpp | 1811 ++++++++++++++++++++++++++++++++++++++++ src/kernel/tqdragobject.h | 279 +++++++ src/kernel/tqdropsite.cpp | 81 ++ src/kernel/tqdropsite.h | 59 ++ src/kernel/tqimage.cpp | 4 +- src/kernel/tqmime.cpp | 619 ++++++++++++++ src/kernel/tqmime.h | 200 +++++ src/table/qtable.cpp | 2 +- src/widgets/qlineedit.cpp | 2 +- src/widgets/qlistview.cpp | 2 +- src/widgets/qmultilineedit.cpp | 2 +- src/widgets/tqiconview.cpp | 2 +- src/widgets/tqiconview.h | 2 +- src/widgets/tqtextbrowser.cpp | 2 +- src/widgets/tqtextedit.cpp | 2 +- 32 files changed, 3082 insertions(+), 3082 deletions(-) delete mode 100644 src/kernel/ntqdragobject.h delete mode 100644 src/kernel/ntqdropsite.h delete mode 100644 src/kernel/ntqmime.h delete mode 100644 src/kernel/qdragobject.cpp delete mode 100644 src/kernel/qdropsite.cpp delete mode 100644 src/kernel/qmime.cpp create mode 100644 src/kernel/tqdragobject.cpp create mode 100644 src/kernel/tqdragobject.h create mode 100644 src/kernel/tqdropsite.cpp create mode 100644 src/kernel/tqdropsite.h create mode 100644 src/kernel/tqmime.cpp create mode 100644 src/kernel/tqmime.h (limited to 'src') diff --git a/src/dialogs/qcolordialog.cpp b/src/dialogs/qcolordialog.cpp index b46702fe8..dd01e3aaa 100644 --- a/src/dialogs/qcolordialog.cpp +++ b/src/dialogs/qcolordialog.cpp @@ -51,7 +51,7 @@ #include "ntqpixmap.h" #include "ntqdrawutil.h" #include "ntqvalidator.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqgridview.h" #include "ntqapplication.h" #include "tqstyle.h" diff --git a/src/dialogs/qfiledialog.cpp b/src/dialogs/qfiledialog.cpp index a51077dfe..a889ec621 100644 --- a/src/dialogs/qfiledialog.cpp +++ b/src/dialogs/qfiledialog.cpp @@ -63,7 +63,7 @@ #include "ntqcombobox.h" #include "ntqcstring.h" #include "ntqcursor.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqfile.h" #include "ntqguardedptr.h" #include "ntqhbox.h" @@ -76,7 +76,7 @@ #include "ntqlistview.h" #include "tqmap.h" #include "ntqmessagebox.h" -#include "ntqmime.h" +#include "tqmime.h" #include "ntqnetworkprotocol.h" #include "tqobjectlist.h" #include "ntqpainter.h" diff --git a/src/kernel/ntqdragobject.h b/src/kernel/ntqdragobject.h deleted file mode 100644 index af4a8a995..000000000 --- a/src/kernel/ntqdragobject.h +++ /dev/null @@ -1,279 +0,0 @@ -/**************************************************************************** -** -** Definition of TQDragObject -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQDRAGOBJECT_H -#define TQDRAGOBJECT_H - -class TQWidget; -class TQTextDragPrivate; -class TQDragObjectData; -class TQStoredDragData; -class TQImageDragData; - -#ifndef QT_H -#include "tqobject.h" -#include "tqimage.h" -#include "tqstrlist.h" -#include "ntqcolor.h" -#endif // QT_H - -#ifndef TQT_NO_MIME - -class TQ_EXPORT TQDragObject: public TQObject, public TQMimeSource { - TQ_OBJECT -public: - TQDragObject( TQWidget * dragSource = 0, const char * name = 0 ); - virtual ~TQDragObject(); - -#ifndef TQT_NO_DRAGANDDROP - bool drag(); - bool dragMove(); - void dragCopy(); - void dragLink(); - - virtual void setPixmap(TQPixmap); - virtual void setPixmap(TQPixmap, const TQPoint& hotspot); - TQPixmap pixmap() const; - TQPoint pixmapHotSpot() const; -#endif - - TQWidget * source(); - static TQWidget * target(); - - static void setTarget(TQWidget*); - -#ifndef TQT_NO_DRAGANDDROP - enum DragMode { DragDefault, DragCopy, DragMove, DragLink, DragCopyOrMove }; - -protected: - virtual bool drag(DragMode); -#endif - -private: - TQDragObjectData * d; -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQDragObject( const TQDragObject & ); - TQDragObject &operator=( const TQDragObject & ); -#endif -}; - -class TQ_EXPORT TQStoredDrag: public TQDragObject { - TQ_OBJECT - TQStoredDragData * d; - -public: - TQStoredDrag( const char * mimeType, - TQWidget * dragSource = 0, const char * name = 0 ); - ~TQStoredDrag(); - - virtual void setEncodedData( const TQByteArray & ); - - const char * format(int i) const; - virtual TQByteArray encodedData(const char*) const; - -private: -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQStoredDrag( const TQStoredDrag & ); - TQStoredDrag &operator=( const TQStoredDrag & ); -#endif -}; - -class TQ_EXPORT TQTextDrag: public TQDragObject { - TQ_OBJECT - TQTextDragPrivate* d; -public: - TQTextDrag( const TQString &, - TQWidget * dragSource = 0, const char * name = 0 ); - TQTextDrag( TQWidget * dragSource = 0, const char * name = 0 ); - ~TQTextDrag(); - - virtual void setText( const TQString &); - virtual void setSubtype( const TQCString &); - - const char * format(int i) const; - virtual TQByteArray encodedData(const char*) const; - - static bool canDecode( const TQMimeSource* e ); - static bool decode( const TQMimeSource* e, TQString& s ); - static bool decode( const TQMimeSource* e, TQString& s, TQCString& subtype ); - -private: -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQTextDrag( const TQTextDrag & ); - TQTextDrag &operator=( const TQTextDrag & ); -#endif -}; - -class TQ_EXPORT TQImageDrag: public TQDragObject { - TQ_OBJECT - TQImage img; - TQStrList ofmts; - TQImageDragData* d; - -public: - TQImageDrag( TQImage image, TQWidget * dragSource = 0, const char * name = 0 ); - TQImageDrag( TQWidget * dragSource = 0, const char * name = 0 ); - ~TQImageDrag(); - - virtual void setImage( TQImage image ); - - const char * format(int i) const; - virtual TQByteArray encodedData(const char*) const; - - static bool canDecode( const TQMimeSource* e ); - static bool decode( const TQMimeSource* e, TQImage& i ); - static bool decode( const TQMimeSource* e, TQPixmap& i ); - -private: -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQImageDrag( const TQImageDrag & ); - TQImageDrag &operator=( const TQImageDrag & ); -#endif -}; - - -class TQ_EXPORT TQUriDrag: public TQStoredDrag { - TQ_OBJECT - -public: - TQUriDrag( TQStrList uris, TQWidget * dragSource = 0, const char * name = 0 ); - TQUriDrag( TQWidget * dragSource = 0, const char * name = 0 ); - ~TQUriDrag(); - - void setFilenames( const TQStringList & fnames ) { setFileNames( fnames ); } - void setFileNames( const TQStringList & fnames ); - void setUnicodeUris( const TQStringList & uuris ); - virtual void setUris( TQStrList uris ); - - static TQString uriToLocalFile(const char*); - static TQCString localFileToUri(const TQString&); - static TQString uriToUnicodeUri(const char*); - static TQCString unicodeUriToUri(const TQString&); - static bool canDecode( const TQMimeSource* e ); - static bool decode( const TQMimeSource* e, TQStrList& i ); - static bool decodeToUnicodeUris( const TQMimeSource* e, TQStringList& i ); - static bool decodeLocalFiles( const TQMimeSource* e, TQStringList& i ); - -private: -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQUriDrag( const TQUriDrag & ); - TQUriDrag &operator=( const TQUriDrag & ); -#endif -}; - -class TQ_EXPORT TQColorDrag : public TQStoredDrag -{ - TQ_OBJECT - TQColor color; - -public: - TQColorDrag( const TQColor &col, TQWidget *dragsource = 0, const char *name = 0 ); - TQColorDrag( TQWidget * dragSource = 0, const char * name = 0 ); - void setColor( const TQColor &col ); - - static bool canDecode( TQMimeSource * ); - static bool decode( TQMimeSource *, TQColor &col ); - -private: -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQColorDrag( const TQColorDrag & ); - TQColorDrag &operator=( const TQColorDrag & ); -#endif -}; - -#ifndef TQT_NO_COMPAT -typedef TQUriDrag TQUrlDrag; -#endif - -#ifndef TQT_NO_DRAGANDDROP - -// TQDragManager is not part of the public API. It is defined in a -// header file simply so different .cpp files can implement different -// member functions. -// - -class TQ_EXPORT TQDragManager: public TQObject { - TQ_OBJECT - -private: - TQDragManager(); - ~TQDragManager(); - // only friend classes can use TQDragManager. - friend class TQDragObject; - friend class TQDragMoveEvent; - friend class TQDropEvent; - friend class TQApplication; - - bool eventFilter( TQObject *, TQEvent * ); - void timerEvent( TQTimerEvent* ); - - bool drag( TQDragObject *, TQDragObject::DragMode ); - - void cancel( bool deleteSource = TRUE ); - void move( const TQPoint & ); - void drop(); - void updatePixmap(); - void updatePixmap( const TQPoint& cursorPos ); - -private: - TQDragObject * object; - bool updateMode( ButtonState newstate ); - void updateCursor(); -#if defined(TQ_WS_X11) - void createCursors(); -#endif - - TQWidget * dragSource; - TQWidget * dropWidget; - bool beingCancelled; - bool restoreCursor; - bool willDrop; - - TQPixmap *pm_cursor; - int n_cursor; -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQDragManager( const TQDragManager & ); - TQDragManager &operator=( const TQDragManager & ); -#endif -}; - -#endif - -#endif // TQT_NO_MIME - -#endif // TQDRAGOBJECT_H diff --git a/src/kernel/ntqdropsite.h b/src/kernel/ntqdropsite.h deleted file mode 100644 index 3e95cdc3f..000000000 --- a/src/kernel/ntqdropsite.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Definitation of Drag and Drop support -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQDROPSITE_H -#define TQDROPSITE_H - -#ifndef QT_H -#ifndef QT_H -#include "ntqglobal.h" -#endif // QT_H -#endif - - -class TQWidget; - - -class TQ_EXPORT TQDropSite { -public: - TQDropSite( TQWidget* parent ); - virtual ~TQDropSite(); -}; - - -#endif // TQDROPSITE_H diff --git a/src/kernel/ntqevent.h b/src/kernel/ntqevent.h index 91eeb38ed..769244360 100644 --- a/src/kernel/ntqevent.h +++ b/src/kernel/ntqevent.h @@ -45,7 +45,7 @@ #include "ntqwindowdefs.h" #include "ntqregion.h" #include "ntqnamespace.h" -#include "ntqmime.h" +#include "tqmime.h" #include "tqpair.h" #endif // QT_H diff --git a/src/kernel/ntqmime.h b/src/kernel/ntqmime.h deleted file mode 100644 index 00c31a375..000000000 --- a/src/kernel/ntqmime.h +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************** -** -** Definition of mime classes -** -** Created : 981204 -** -** Copyright (C) 1998-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQMIME_H -#define TQMIME_H - -#ifndef QT_H -#include "ntqwindowdefs.h" -#include "tqmap.h" -#endif // QT_H - -#ifndef TQT_NO_MIME - -class TQImageDrag; -class TQTextDrag; - -class TQ_EXPORT TQMimeSource -{ - friend class TQClipboardData; - -public: - TQMimeSource(); - virtual ~TQMimeSource(); - virtual const char* format( int n = 0 ) const = 0; - virtual bool provides( const char* ) const; - virtual TQByteArray encodedData( const char* ) const = 0; - int serialNumber() const; - -private: - int ser_no; - enum { NoCache, Text, Graphics } cacheType; - union - { - struct - { - TQString *str; - TQCString *subtype; - } txt; - struct - { - TQImage *img; - TQPixmap *pix; - } gfx; - } cache; - void clearCache(); - - // friends for caching - friend class TQImageDrag; - friend class TQTextDrag; - -}; - -inline int TQMimeSource::serialNumber() const -{ return ser_no; } - -class TQStringList; -class TQMimeSourceFactoryData; - -class TQ_EXPORT TQMimeSourceFactory { -public: - TQMimeSourceFactory(); - virtual ~TQMimeSourceFactory(); - - static TQMimeSourceFactory* defaultFactory(); - static void setDefaultFactory( TQMimeSourceFactory* ); - static TQMimeSourceFactory* takeDefaultFactory(); - static void addFactory( TQMimeSourceFactory *f ); - static void removeFactory( TQMimeSourceFactory *f ); - - virtual const TQMimeSource* data(const TQString& abs_name) const; - virtual TQString makeAbsolute(const TQString& abs_or_rel_name, const TQString& context) const; - const TQMimeSource* data(const TQString& abs_or_rel_name, const TQString& context) const; - - virtual void setText( const TQString& abs_name, const TQString& text ); - virtual void setImage( const TQString& abs_name, const TQImage& im ); - virtual void setPixmap( const TQString& abs_name, const TQPixmap& pm ); - virtual void setData( const TQString& abs_name, TQMimeSource* data ); - virtual void setFilePath( const TQStringList& ); - virtual TQStringList filePath() const; - void addFilePath( const TQString& ); - virtual void setExtensionType( const TQString& ext, const char* mimetype ); - -private: - TQMimeSource *dataInternal(const TQString& abs_name, const TQMap &extensions ) const; - TQMimeSourceFactoryData* d; -}; - -#if defined(TQ_WS_WIN) - -#ifndef QT_H -#include "tqptrlist.h" // down here for GCC 2.7.* compatibility -#endif // QT_H - -/* - Encapsulation of conversion between MIME and Windows CLIPFORMAT. - Not need on X11, as the underlying protocol uses the MIME standard - directly. -*/ - -class TQ_EXPORT TQWindowsMime { -public: - TQWindowsMime(); - virtual ~TQWindowsMime(); - - static void initialize(); - - static TQPtrList all(); - static TQWindowsMime* convertor( const char* mime, int cf ); - static const char* cfToMime(int cf); - - static int registerMimeType(const char *mime); - - virtual const char* convertorName()=0; - virtual int countCf()=0; - virtual int cf(int index)=0; - virtual bool canConvert( const char* mime, int cf )=0; - virtual const char* mimeFor(int cf)=0; - virtual int cfFor(const char* )=0; - virtual TQByteArray convertToMime( TQByteArray data, const char* mime, int cf )=0; - virtual TQByteArray convertFromMime( TQByteArray data, const char* mime, int cf )=0; -}; - -#endif -#if defined(TQ_WS_MAC) - -#ifndef QT_H -#include "tqptrlist.h" // down here for GCC 2.7.* compatibility -#endif // QT_H - -/* - Encapsulation of conversion between MIME and Mac flavor. - Not need on X11, as the underlying protocol uses the MIME standard - directly. -*/ - -class TQ_EXPORT TQMacMime { - char type; -public: - enum TQMacMimeType { MIME_DND=0x01, MIME_CLIP=0x02, MIME_QT_CONVERTOR=0x04, MIME_ALL=MIME_DND|MIME_CLIP }; - TQMacMime(char); - virtual ~TQMacMime(); - - static void initialize(); - - static TQPtrList all(TQMacMimeType); - static TQMacMime* convertor(TQMacMimeType, const char* mime, int flav); - static const char* flavorToMime(TQMacMimeType, int flav); - - virtual const char* convertorName()=0; - virtual int countFlavors()=0; - virtual int flavor(int index)=0; - virtual bool canConvert(const char* mime, int flav)=0; - virtual const char* mimeFor(int flav)=0; - virtual int flavorFor(const char*)=0; - virtual TQByteArray convertToMime(TQValueList data, const char* mime, int flav)=0; - virtual TQValueList convertFromMime(TQByteArray data, const char* mime, int flav)=0; -}; - -#endif // TQ_WS_MAC - -#endif // TQT_NO_MIME - -#endif // TQMIME_H diff --git a/src/kernel/ntqt.h b/src/kernel/ntqt.h index c5430b8fd..778a0a93c 100644 --- a/src/kernel/ntqt.h +++ b/src/kernel/ntqt.h @@ -49,7 +49,7 @@ #include "tqvaluelist.h" #include "tqmap.h" #include "tqdatetime.h" -#include "ntqmime.h" +#include "tqmime.h" #include "ntqasciidict.h" #include "ntqpaintdevice.h" #include "ntqfontmetrics.h" @@ -90,7 +90,7 @@ #include #include #include -#include +#include #include "ntqgplugin.h" #include #include "ntqrangecontrol.h" @@ -150,7 +150,7 @@ #include "tqmenudata.h" #include #include "ntqpen.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include #include #include diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index c1387f78f..ee1395619 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -51,7 +51,7 @@ #include "ntqtranslator.h" #include "tqtextcodec.h" #include "tqsessionmanager.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqclipboard.h" #include "ntqcursor.h" #include "tqstyle.h" diff --git a/src/kernel/qclipboard.cpp b/src/kernel/qclipboard.cpp index e7768f6bd..416a5926f 100644 --- a/src/kernel/qclipboard.cpp +++ b/src/kernel/qclipboard.cpp @@ -44,7 +44,7 @@ #include "ntqapplication.h" #include "qapplication_p.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqpixmap.h" /*! diff --git a/src/kernel/qclipboard_x11.cpp b/src/kernel/qclipboard_x11.cpp index dbe3a7f78..e8eeac848 100644 --- a/src/kernel/qclipboard_x11.cpp +++ b/src/kernel/qclipboard_x11.cpp @@ -68,7 +68,7 @@ #include "ntqeventloop.h" #include "ntqbitmap.h" #include "tqdatetime.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqbuffer.h" #include "tqtextcodec.h" #include "tqvaluelist.h" diff --git a/src/kernel/qdnd_x11.cpp b/src/kernel/qdnd_x11.cpp index 7e2a1fd04..dc4b9678b 100644 --- a/src/kernel/qdnd_x11.cpp +++ b/src/kernel/qdnd_x11.cpp @@ -49,7 +49,7 @@ #include "tqdatetime.h" #include "ntqdict.h" #include "ntqguardedptr.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "tqobjectlist.h" #include "ntqcursor.h" #include "ntqbitmap.h" diff --git a/src/kernel/qdragobject.cpp b/src/kernel/qdragobject.cpp deleted file mode 100644 index 9854c33a3..000000000 --- a/src/kernel/qdragobject.cpp +++ /dev/null @@ -1,1811 +0,0 @@ -/**************************************************************************** -** -** Implementation of Drag and Drop support -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "qplatformdefs.h" - -// POSIX Large File Support redefines open -> open64 -#if defined(open) -# undef open -#endif - -#ifndef TQT_NO_MIME - -#include "ntqdragobject.h" -#include "tqtextcodec.h" -#include "ntqapplication.h" -#include "ntqpoint.h" -#include "tqwidget.h" -#include "ntqbuffer.h" -#include "ntqgif.h" -#include "ntqregexp.h" -#include "ntqdir.h" -#include - -// both a struct for storing stuff in and a wrapper to avoid polluting -// the name space - -class TQDragObjectData -{ -public: - TQDragObjectData(): hot(0,0) {} - TQPixmap pixmap; - TQPoint hot; - // store default cursors - TQPixmap *pm_cursor; -}; - -static TQWidget* last_target; - -/*! - After the drag completes, this function will return the TQWidget - which received the drop, or 0 if the data was dropped on another - application. - - This can be useful for detecting the case where drag and drop is - to and from the same widget. -*/ -TQWidget * TQDragObject::target() -{ - return last_target; -} - -/*! - \internal - Sets the target. -*/ -void TQDragObject::setTarget(TQWidget* t) -{ - last_target = t; -} - -class TQStoredDragData -{ -public: - TQStoredDragData() {} - const char* fmt; - TQByteArray enc; -}; - - -// These pixmaps approximate the images in the Windows User Interface Guidelines. - -// XPM - -static const char * const move_xpm[] = { -"11 20 3 1", -". c None", -#if defined(TQ_WS_WIN) -"a c #000000", -"X c #FFFFFF", // Windows cursor is traditionally white -#else -"a c #FFFFFF", -"X c #000000", // X11 cursor is traditionally black -#endif -"aa.........", -"aXa........", -"aXXa.......", -"aXXXa......", -"aXXXXa.....", -"aXXXXXa....", -"aXXXXXXa...", -"aXXXXXXXa..", -"aXXXXXXXXa.", -"aXXXXXXXXXa", -"aXXXXXXaaaa", -"aXXXaXXa...", -"aXXaaXXa...", -"aXa..aXXa..", -"aa...aXXa..", -"a.....aXXa.", -"......aXXa.", -".......aXXa", -".......aXXa", -"........aa."}; - -/* XPM */ -static const char * const copy_xpm[] = { -"24 30 3 1", -". c None", -"a c #000000", -"X c #FFFFFF", -#if defined(TQ_WS_WIN) // Windows cursor is traditionally white -"aa......................", -"aXa.....................", -"aXXa....................", -"aXXXa...................", -"aXXXXa..................", -"aXXXXXa.................", -"aXXXXXXa................", -"aXXXXXXXa...............", -"aXXXXXXXXa..............", -"aXXXXXXXXXa.............", -"aXXXXXXaaaa.............", -"aXXXaXXa................", -"aXXaaXXa................", -"aXa..aXXa...............", -"aa...aXXa...............", -"a.....aXXa..............", -"......aXXa..............", -".......aXXa.............", -".......aXXa.............", -"........aa...aaaaaaaaaaa", -#else -"XX......................", -"XaX.....................", -"XaaX....................", -"XaaaX...................", -"XaaaaX..................", -"XaaaaaX.................", -"XaaaaaaX................", -"XaaaaaaaX...............", -"XaaaaaaaaX..............", -"XaaaaaaaaaX.............", -"XaaaaaaXXXX.............", -"XaaaXaaX................", -"XaaXXaaX................", -"XaX..XaaX...............", -"XX...XaaX...............", -"X.....XaaX..............", -"......XaaX..............", -".......XaaX.............", -".......XaaX.............", -"........XX...aaaaaaaaaaa", -#endif -".............aXXXXXXXXXa", -".............aXXXXXXXXXa", -".............aXXXXaXXXXa", -".............aXXXXaXXXXa", -".............aXXaaaaaXXa", -".............aXXXXaXXXXa", -".............aXXXXaXXXXa", -".............aXXXXXXXXXa", -".............aXXXXXXXXXa", -".............aaaaaaaaaaa"}; - -/* XPM */ -static const char * const link_xpm[] = { -"24 30 3 1", -". c None", -"a c #000000", -"X c #FFFFFF", -#if defined(TQ_WS_WIN) // Windows cursor is traditionally white -"aa......................", -"aXa.....................", -"aXXa....................", -"aXXXa...................", -"aXXXXa..................", -"aXXXXXa.................", -"aXXXXXXa................", -"aXXXXXXXa...............", -"aXXXXXXXXa..............", -"aXXXXXXXXXa.............", -"aXXXXXXaaaa.............", -"aXXXaXXa................", -"aXXaaXXa................", -"aXa..aXXa...............", -"aa...aXXa...............", -"a.....aXXa..............", -"......aXXa..............", -".......aXXa.............", -".......aXXa.............", -"........aa...aaaaaaaaaaa", -#else -"XX......................", -"XaX.....................", -"XaaX....................", -"XaaaX...................", -"XaaaaX..................", -"XaaaaaX.................", -"XaaaaaaX................", -"XaaaaaaaX...............", -"XaaaaaaaaX..............", -"XaaaaaaaaaX.............", -"XaaaaaaXXXX.............", -"XaaaXaaX................", -"XaaXXaaX................", -"XaX..XaaX...............", -"XX...XaaX...............", -"X.....XaaX..............", -"......XaaX..............", -".......XaaX.............", -".......XaaX.............", -"........XX...aaaaaaaaaaa", -#endif -".............aXXXXXXXXXa", -".............aXXXaaaaXXa", -".............aXXXXaaaXXa", -".............aXXXaaaaXXa", -".............aXXaaaXaXXa", -".............aXXaaXXXXXa", -".............aXXaXXXXXXa", -".............aXXXaXXXXXa", -".............aXXXXXXXXXa", -".............aaaaaaaaaaa"}; - -#ifndef TQT_NO_DRAGANDDROP - -// the universe's only drag manager -TQDragManager * qt_dnd_manager = 0; - - -TQDragManager::TQDragManager() - : TQObject( tqApp, "global drag manager" ) -{ - n_cursor = 3; - pm_cursor = new TQPixmap[n_cursor]; - pm_cursor[0] = TQPixmap((const char **)move_xpm); - pm_cursor[1] = TQPixmap((const char **)copy_xpm); - pm_cursor[2] = TQPixmap((const char **)link_xpm); -#if defined(TQ_WS_X11) - createCursors(); // Xcursors cache can hold only 8 bitmaps (4 cursors) -#endif - object = 0; - dragSource = 0; - dropWidget = 0; - if ( !qt_dnd_manager ) - qt_dnd_manager = this; - beingCancelled = FALSE; - restoreCursor = FALSE; - willDrop = FALSE; -} - - -TQDragManager::~TQDragManager() -{ -#ifndef TQT_NO_CURSOR - if ( restoreCursor ) - TQApplication::restoreOverrideCursor(); -#endif - qt_dnd_manager = 0; - delete [] pm_cursor; -} - -#endif - - -/*! - Constructs a drag object called \a name, which is a child of \a - dragSource. - - Note that the drag object will be deleted when \a dragSource is - deleted. -*/ - -TQDragObject::TQDragObject( TQWidget * dragSource, const char * name ) - : TQObject( dragSource, name ) -{ - d = new TQDragObjectData(); - d->pm_cursor = 0; -#ifndef TQT_NO_DRAGANDDROP - if ( !qt_dnd_manager && tqApp ) - (void)new TQDragManager(); -#endif -} - - -/*! - Destroys the drag object, canceling any drag and drop operation in - which it is involved, and frees up the storage used. -*/ - -TQDragObject::~TQDragObject() -{ -#ifndef TQT_NO_DRAGANDDROP - if ( qt_dnd_manager && qt_dnd_manager->object == this ) - qt_dnd_manager->cancel( FALSE ); - if ( d->pm_cursor ) { - for ( int i = 0; i < qt_dnd_manager->n_cursor; i++ ) - qt_dnd_manager->pm_cursor[i] = d->pm_cursor[i]; - delete [] d->pm_cursor; - } -#endif - delete d; -} - -#ifndef TQT_NO_DRAGANDDROP -/*! - Set the pixmap \a pm to display while dragging the object. The - platform-specific implementation will use this where it can - so - provide a small masked pixmap, and do not assume that the user - will actually see it. For example, cursors on Windows 95 are of - limited size. - - The \a hotspot is the point on (or off) the pixmap that should be - under the cursor as it is dragged. It is relative to the top-left - pixel of the pixmap. - - \warning We have seen problems with drag cursors on different - graphics hardware and driver software on Windows. Setting the - graphics acceleration in the display settings down one tick solved - the problems in all cases. -*/ -void TQDragObject::setPixmap(TQPixmap pm, const TQPoint& hotspot) -{ - d->pixmap = pm; - d->hot = hotspot; - if ( qt_dnd_manager && qt_dnd_manager->object == this ) - qt_dnd_manager->updatePixmap(); -} - -/*! - \overload - Uses a hotspot that positions the pixmap below and to the right of - the mouse pointer. This allows the user to clearly see the point - on the window which they are dragging the data onto. -*/ -void TQDragObject::setPixmap(TQPixmap pm) -{ - setPixmap(pm,TQPoint(-10, -10)); -} - -/*! - Returns the currently set pixmap (which \link TQPixmap::isNull() - isNull()\endlink if none is set). -*/ -TQPixmap TQDragObject::pixmap() const -{ - return d->pixmap; -} - -/*! - Returns the currently set pixmap hotspot. -*/ -TQPoint TQDragObject::pixmapHotSpot() const -{ - return d->hot; -} - -#if 0 - -// ## reevaluate for TQt 4 -/*! - Set the \a cursor used when dragging in mode \a m. - Note: X11 only allow bitmaps for cursors. -*/ -void TQDragObject::setCursor( DragMode m, const TQPixmap &cursor ) -{ - if ( d->pm_cursor == 0 ) { - // safe default cursors - d->pm_cursor = new TQPixmap[qt_dnd_manager->n_cursor]; - for ( int i = 0; i < qt_dnd_manager->n_cursor; i++ ) - d->pm_cursor[i] = qt_dnd_manager->pm_cursor[i]; - } - - int index; - switch ( m ) { - case DragCopy: - index = 1; - break; - case DragLink: - index = 2; - break; - default: - index = 0; - break; - } - - // override default cursor - for ( index = 0; index < qt_dnd_manager->n_cursor; index++ ) - qt_dnd_manager->pm_cursor[index] = cursor; -} - -/*! - Returns the cursor used when dragging in mode \a m, or null if no cursor - has been set for that mode. -*/ -TQPixmap *TQDragObject::cursor( DragMode m ) const -{ - if ( !d->pm_cursor ) - return 0; - - int index; - switch ( m ) { - case DragCopy: - index = 1; - break; - case DragLink: - index = 2; - break; - default: - index = 0; - break; - } - - return qt_dnd_manager->pm_cursor+index; -} - -#endif // 0 - -/*! - Starts a drag operation using the contents of this object, using - DragDefault mode. - - The function returns TRUE if the caller should delete the original - copy of the dragged data (but see target()); otherwise returns - FALSE. - - If the drag contains \e references to information (e.g. file names - in a TQUriDrag are references) then the return value should always - be ignored, as the target is expected to manipulate the - referred-to content directly. On X11 the return value should - always be correct anyway, but on Windows this is not necessarily - the case (e.g. the file manager starts a background process to - move files, so the source \e{must not} delete the files!) -*/ -bool TQDragObject::drag() -{ - return drag( DragDefault ); -} - - -/*! - Starts a drag operation using the contents of this object, using - \c DragMove mode. Be sure to read the constraints described in - drag(). - - \sa drag() dragCopy() dragLink() -*/ -bool TQDragObject::dragMove() -{ - return drag( DragMove ); -} - - -/*! - Starts a drag operation using the contents of this object, using - \c DragCopy mode. Be sure to read the constraints described in - drag(). - - \sa drag() dragMove() dragLink() -*/ -void TQDragObject::dragCopy() -{ - (void)drag( DragCopy ); -} - -/*! - Starts a drag operation using the contents of this object, using - \c DragLink mode. Be sure to read the constraints described in - drag(). - - \sa drag() dragCopy() dragMove() -*/ -void TQDragObject::dragLink() -{ - (void)drag( DragLink ); -} - - -/*! - \enum TQDragObject::DragMode - - This enum describes the possible drag modes. - - \value DragDefault The mode is determined heuristically. - \value DragCopy The data is copied, never moved. - \value DragMove The data is moved, if dragged at all. - \value DragLink The data is linked, if dragged at all. - \value DragCopyOrMove The user chooses the mode by using a - control key to switch from the default. -*/ - - -/*! - \overload - Starts a drag operation using the contents of this object. - - At this point, the object becomes owned by TQt, not the - application. You should not delete the drag object or anything it - references. The actual transfer of data to the target application - will be done during future event processing - after that time the - drag object will be deleted. - - Returns TRUE if the dragged data was dragged as a \e move, - indicating that the caller should remove the original source of - the data (the drag object must continue to have a copy); otherwise - returns FALSE. - - The \a mode specifies the drag mode (see - \l{TQDragObject::DragMode}.) Normally one of the simpler drag(), - dragMove(), or dragCopy() functions would be used instead. -*/ -bool TQDragObject::drag( DragMode mode ) -{ - if ( qt_dnd_manager ) - return qt_dnd_manager->drag( this, mode ); - else - return FALSE; -} - -#endif - - -/*! - Returns a pointer to the drag source where this object originated. -*/ - -TQWidget * TQDragObject::source() -{ - if ( parent() && parent()->isWidgetType() ) - return (TQWidget *)parent(); - else - return 0; -} - - -/*! - \class TQDragObject ntqdragobject.h - - \brief The TQDragObject class encapsulates MIME-based data - transfer. - - \ingroup draganddrop - - TQDragObject is the base class for all data that needs to be - transferred between and within applications, both for drag and - drop and for the \link ntqclipboard.html clipboard\endlink. - - See the \link dnd.html Drag-and-drop documentation\endlink for an - overview of how to provide drag and drop in your application. - - See the TQClipboard documentation for an overview of how to provide - cut-and-paste in your application. - - The drag() function is used to start a drag operation. You can - specify the \l DragMode in the call or use one of the convenience - functions dragCopy(), dragMove() or dragLink(). The drag source - where the data originated is retrieved with source(). If the data - was dropped on a widget within the application, target() will - return a pointer to that widget. Specify the pixmap to display - during the drag with setPixmap(). -*/ - -static -void stripws(TQCString& s) -{ - int f; - while ( (f=s.find(' ')) >= 0 ) - s.remove(f,1); -} - -static -const char * staticCharset(int i) -{ - static TQCString localcharset; - - switch ( i ) { - case 0: - return "UTF-8"; - case 1: - return "ISO-10646-UCS-2"; - case 2: - return ""; // in the 3rd place - some Xdnd targets might only look at 3 - case 3: - if ( localcharset.isNull() ) { - TQTextCodec *localCodec = TQTextCodec::codecForLocale(); - if ( localCodec ) { - localcharset = localCodec->name(); - localcharset = localcharset.lower(); - stripws(localcharset); - } else { - localcharset = ""; - } - } - return localcharset; - } - return 0; -} - - -class TQTextDragPrivate { -public: - TQTextDragPrivate(); - - enum { nfmt=4 }; - - TQString txt; - TQCString fmt[nfmt]; - TQCString subtype; - - void setSubType(const TQCString & st) - { - subtype = st.lower(); - for ( int i=0; isetSubType(st); -} - -/*! - \class TQTextDrag ntqdragobject.h - - \brief The TQTextDrag class is a drag and drop object for - transferring plain and Unicode text. - - \ingroup draganddrop - - Plain text is passed in a TQString which may contain multiple lines - (i.e. may contain newline characters). The drag target will receive - the newlines according to the runtime environment, e.g. LF on Unix, - and CRLF on Windows. - - TQt provides no built-in mechanism for delivering only a single-line. - - For more information about drag and drop, see the TQDragObject class - and the \link dnd.html drag and drop documentation\endlink. -*/ - - -/*! - Constructs a text drag object and sets its data to \a text. \a - dragSource must be the drag source; \a name is the object name. -*/ - -TQTextDrag::TQTextDrag( const TQString &text, - TQWidget * dragSource, const char * name ) - : TQDragObject( dragSource, name ) -{ - d = new TQTextDragPrivate; - setText( text ); -} - - -/*! - Constructs a default text drag object. \a dragSource must be the - drag source; \a name is the object name. -*/ - -TQTextDrag::TQTextDrag( TQWidget * dragSource, const char * name ) - : TQDragObject( dragSource, name ) -{ - d = new TQTextDragPrivate; -} - - -/*! - Destroys the text drag object and frees up all allocated - resources. -*/ -TQTextDrag::~TQTextDrag() -{ - delete d; -} - - -/*! - Sets the text to be dragged to \a text. You will need to call this - if you did not pass the text during construction. -*/ -void TQTextDrag::setText( const TQString &text ) -{ - d->txt = text; -} - - -/*! - \reimp -*/ -const char * TQTextDrag::format(int i) const -{ - if ( i >= d->nfmt ) - return 0; - return d->fmt[i]; -} - -TQTextCodec* qt_findcharset(const TQCString& mimetype) -{ - int i=mimetype.find("charset="); - if ( i >= 0 ) { - TQCString cs = mimetype.mid(i+8); - stripws(cs); - i = cs.find(';'); - if ( i >= 0 ) - cs = cs.left(i); - // win98 often has charset=utf16, and we need to get the correct codec for - // it to be able to get Unicode text drops. - if ( cs == "utf16" ) - cs = "ISO-10646-UCS-2"; - // May return 0 if unknown charset - return TQTextCodec::codecForName(cs); - } - // no charset=, use locale - return TQTextCodec::codecForLocale(); -} - -static TQTextCodec *codecForHTML(const TQCString &ba) -{ - // determine charset - int mib = 0; - int pos; - TQTextCodec *c = 0; - - if (ba.size() > 1 && (((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff) - || ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe))) { - mib = 1000; // utf16 - } else if (ba.size() > 2 - && (uchar)ba[0] == 0xef - && (uchar)ba[1] == 0xbb - && (uchar)ba[2] == 0xbf) { - mib = 106; // utf-8 - } else { - pos = 0; - while ((pos = ba.find("format(i)); i++ ) { - bool html = !tqstrnicmp(f, "text/html", 9); - if (html) - r = codecForHTML(TQCString(e->encodedData(f))); - if (!r) - r = qt_findcharset(TQCString(f).lower()); - if (r) - return r; - } - return 0; -} - - - -/*! - \reimp -*/ -TQByteArray TQTextDrag::encodedData(const char* mime) const -{ - TQCString r; - if ( 0==tqstrnicmp(mime,"text/",5) ) { - TQCString m(mime); - m = m.lower(); - TQTextCodec *codec = qt_findcharset(m); - if ( !codec ) - return r; - TQString text( d->txt ); -#if defined(TQ_WS_WIN) - int index = text.find( TQString::fromLatin1("\r\n"), 0 ); - while ( index != -1 ) { - text.replace( index, 2, TQChar('\n') ); - index = text.find( "\r\n", index ); - } -#endif - r = codec->fromUnicode(text); - if (!codec || codec->mibEnum() != 1000) { - // Don't include NUL in size (TQCString::resize() adds NUL) -#if defined(TQ_WS_WIN) - // This is needed to ensure the \0 isn't lost on Windows 95 - if ( qWinVersion() & TQt::WV_DOS_based ) - ((TQByteArray&)r).resize(r.length()+1); - else -#endif - ((TQByteArray&)r).resize(r.length()); - } - } - return r; -} - -/*! - Returns TRUE if the information in \a e can be decoded into a - TQString; otherwise returns FALSE. - - \sa decode() -*/ -bool TQTextDrag::canDecode( const TQMimeSource* e ) -{ - const char* f; - for (int i=0; (f=e->format(i)); i++) { - if ( 0==tqstrnicmp(f,"text/",5) ) { - return findcodec(e) != 0; - } - } - return 0; -} - -/*! - \overload - - Attempts to decode the dropped information in \a e into \a str. - Returns TRUE if successful; otherwise returns FALSE. If \a subtype - is null, any text subtype is accepted; otherwise only the - specified \a subtype is accepted. - - \sa canDecode() -*/ -bool TQTextDrag::decode( const TQMimeSource* e, TQString& str, TQCString& subtype ) -{ - if(!e) - return FALSE; - - // when subtype is not specified, try text/plain first, otherwise this may read - // things like text/x-moz-url even though better targets are available - if( subtype.isNull()) { - TQCString subtmp = "plain"; - if( decode( e, str, subtmp )) { - subtype = subtmp; - return true; - } - } - - if ( e->cacheType == TQMimeSource::Text ) { - str = *e->cache.txt.str; - subtype = *e->cache.txt.subtype; - return TRUE; - } - - const char* mime; - for (int i=0; (mime = e->format(i)); i++) { - if ( 0==tqstrnicmp(mime,"text/",5) ) { - TQCString m(mime); - m = m.lower(); - int semi = m.find(';'); - if ( semi < 0 ) - semi = m.length(); - TQCString foundst = m.mid(5,semi-5); - if ( subtype.isNull() || foundst == subtype ) { - bool html = !tqstrnicmp(mime, "text/html", 9); - TQTextCodec* codec = 0; - if (html) { - TQByteArray bytes = e->encodedData(mime); - // search for the charset tag in the HTML - codec = codecForHTML(TQCString(bytes.data(), bytes.size())); - } - if (!codec) - codec = qt_findcharset(m); - if ( codec ) { - TQByteArray payload; - - payload = e->encodedData(mime); - if ( payload.size() ) { - int l; - if ( codec->mibEnum() != 1000) { - // length is at NUL or payload.size() - l = 0; - while ( l < (int)payload.size() && payload[l] ) - l++; - } else { - l = payload.size(); - } - - str = codec->toUnicode(payload,l); - - if ( subtype.isNull() ) - subtype = foundst; - - TQMimeSource *m = (TQMimeSource*)e; - m->clearCache(); - m->cacheType = TQMimeSource::Text; - m->cache.txt.str = new TQString( str ); - m->cache.txt.subtype = new TQCString( subtype ); - - return TRUE; - } - } - } - } - } - return FALSE; -} - -/*! - Attempts to decode the dropped information in \a e into \a str. - Returns TRUE if successful; otherwise returns FALSE. - - \sa canDecode() -*/ -bool TQTextDrag::decode( const TQMimeSource* e, TQString& str ) -{ - TQCString st; - return decode(e,str,st); -} - - -/* - TQImageDrag could use an internal MIME type for communicating TQPixmaps - and TQImages rather than always converting to raw data. This is available - for that purpose and others. It is not currently used. -*/ -class TQImageDragData -{ -public: -}; - - -/*! - \class TQImageDrag ntqdragobject.h - - \brief The TQImageDrag class provides a drag and drop object for - transferring images. - - \ingroup draganddrop - - Images are offered to the receiving application in multiple - formats, determined by TQt's \link TQImage::outputFormats() output - formats\endlink. - - For more information about drag and drop, see the TQDragObject - class and the \link dnd.html drag and drop documentation\endlink. -*/ - -/*! - Constructs an image drag object and sets its data to \a image. \a - dragSource must be the drag source; \a name is the object name. -*/ - -TQImageDrag::TQImageDrag( TQImage image, - TQWidget * dragSource, const char * name ) - : TQDragObject( dragSource, name ), - d(0) -{ - setImage( image ); -} - -/*! - Constructs a default image drag object. \a dragSource must be the - drag source; \a name is the object name. -*/ - -TQImageDrag::TQImageDrag( TQWidget * dragSource, const char * name ) - : TQDragObject( dragSource, name ), - d(0) -{ -} - - -/*! - Destroys the image drag object and frees up all allocated - resources. -*/ - -TQImageDrag::~TQImageDrag() -{ - // nothing -} - - -/*! - Sets the image to be dragged to \a image. You will need to call - this if you did not pass the image during construction. -*/ -void TQImageDrag::setImage( TQImage image ) -{ - img = image; // ### detach? - ofmts = TQImage::outputFormats(); - ofmts.remove("PBM"); // remove non-raw PPM - if ( image.depth()!=32 ) { - // BMP better than PPM for paletted images - if ( ofmts.remove("BMP") ) // move to front - ofmts.insert(0,"BMP"); - } - // PNG is best of all - if ( ofmts.remove("PNG") ) // move to front - ofmts.insert(0,"PNG"); - - if(cacheType == TQMimeSource::NoCache) { //cache it - cacheType = TQMimeSource::Graphics; - cache.gfx.img = new TQImage( img ); - cache.gfx.pix = 0; - } -} - -/*! - \reimp -*/ -const char * TQImageDrag::format(int i) const -{ - if ( i < (int)ofmts.count() ) { - static TQCString str; - str.sprintf("image/%s",(((TQImageDrag*)this)->ofmts).at(i)); - str = str.lower(); - if ( str == "image/pbmraw" ) - str = "image/ppm"; - return str; - } else { - return 0; - } -} - -/*! - \reimp -*/ -TQByteArray TQImageDrag::encodedData(const char* fmt) const -{ - if ( tqstrnicmp( fmt, "image/", 6 )==0 ) { - TQCString f = fmt+6; - TQByteArray data; - TQBuffer w( data ); - w.open( IO_WriteOnly ); - TQImageIO io( &w, f.upper() ); - io.setImage( img ); - if ( !io.write() ) - return TQByteArray(); - w.close(); - return data; - } else { - return TQByteArray(); - } -} - -/*! - Returns TRUE if the information in mime source \a e can be decoded - into an image; otherwise returns FALSE. - - \sa decode() -*/ -bool TQImageDrag::canDecode( const TQMimeSource* e ) { - TQStrList fileFormats = TQImageIO::inputFormats(); - - fileFormats.first(); - while ( fileFormats.current()) { - TQCString format = fileFormats.current(); - TQCString type = "image/" + format.lower(); - if ( e->provides(type.data())) - return TRUE; - fileFormats.next(); - } - - return FALSE; -} - -/*! - Attempts to decode the dropped information in mime source \a e - into \a img. Returns TRUE if successful; otherwise returns FALSE. - - \sa canDecode() -*/ -bool TQImageDrag::decode( const TQMimeSource* e, TQImage& img ) -{ - if ( !e ) - return FALSE; - if ( e->cacheType == TQMimeSource::Graphics ) { - img = *e->cache.gfx.img; - return TRUE; - } - - TQByteArray payload; - TQStrList fileFormats = TQImageIO::inputFormats(); - // PNG is best of all - if ( fileFormats.remove("PNG") ) // move to front - fileFormats.insert(0,"PNG"); - fileFormats.first(); - while ( fileFormats.current() ) { - TQCString format = fileFormats.current(); - fileFormats.next(); - - TQCString type = "image/" + format.lower(); - if ( ! e->provides( type.data() ) ) continue; - payload = e->encodedData( type.data() ); - if ( !payload.isEmpty() ) - break; - } - - if ( payload.isEmpty() ) - return FALSE; - - img.loadFromData(payload); - if ( img.isNull() ) - return FALSE; - TQMimeSource *m = (TQMimeSource*)e; - m->clearCache(); - m->cacheType = TQMimeSource::Graphics; - m->cache.gfx.img = new TQImage( img ); - m->cache.gfx.pix = 0; - return TRUE; -} - -/*! - \overload - - Attempts to decode the dropped information in mime source \a e - into pixmap \a pm. Returns TRUE if successful; otherwise returns - FALSE. - - This is a convenience function that converts to a TQPixmap via a - TQImage. - - \sa canDecode() -*/ -bool TQImageDrag::decode( const TQMimeSource* e, TQPixmap& pm ) -{ - if ( !e ) - return FALSE; - - if ( e->cacheType == TQMimeSource::Graphics && e->cache.gfx.pix) { - pm = *e->cache.gfx.pix; - return TRUE; - } - - TQImage img; - // We avoid dither, since the image probably came from this display - if ( decode( e, img ) ) { - if ( !pm.convertFromImage( img, AvoidDither ) ) - return FALSE; - // decode initialized the cache for us - - TQMimeSource *m = (TQMimeSource*)e; - m->cache.gfx.pix = new TQPixmap( pm ); - return TRUE; - } - return FALSE; -} - - - - -/*! - \class TQStoredDrag ntqdragobject.h - \brief The TQStoredDrag class provides a simple stored-value drag object for arbitrary MIME data. - - \ingroup draganddrop - - When a block of data has only one representation, you can use a - TQStoredDrag to hold it. - - For more information about drag and drop, see the TQDragObject - class and the \link dnd.html drag and drop documentation\endlink. -*/ - -/*! - Constructs a TQStoredDrag. The \a dragSource and \a name are passed - to the TQDragObject constructor, and the format is set to \a - mimeType. - - The data will be unset. Use setEncodedData() to set it. -*/ -TQStoredDrag::TQStoredDrag( const char* mimeType, TQWidget * dragSource, const char * name ) : - TQDragObject(dragSource,name) -{ - d = new TQStoredDragData(); - d->fmt = tqstrdup(mimeType); -} - -/*! - Destroys the drag object and frees up all allocated resources. -*/ -TQStoredDrag::~TQStoredDrag() -{ - delete [] (char*)d->fmt; - delete d; -} - -/*! - \reimp -*/ -const char * TQStoredDrag::format(int i) const -{ - if ( i==0 ) - return d->fmt; - else - return 0; -} - - -/*! - Sets the encoded data of this drag object to \a encodedData. The - encoded data is what's delivered to the drop sites. It must be in - a strictly defined and portable format. - - The drag object can't be dropped (by the user) until this function - has been called. -*/ - -void TQStoredDrag::setEncodedData( const TQByteArray & encodedData ) -{ - d->enc = encodedData.copy(); -} - -/*! - Returns the stored data. \a m contains the data's format. - - \sa setEncodedData() -*/ -TQByteArray TQStoredDrag::encodedData(const char* m) const -{ - if ( !tqstricmp(m,d->fmt) ) - return d->enc; - else - return TQByteArray(); -} - - -/*! - \class TQUriDrag ntqdragobject.h - \brief The TQUriDrag class provides a drag object for a list of URI references. - - \ingroup draganddrop - - URIs are a useful way to refer to files that may be distributed - across multiple machines. A URI will often refer to a file on a - machine local to both the drag source and the drop target, so the - URI can be equivalent to passing a file name but is more - extensible. - - Use URIs in Unicode form so that the user can comfortably edit and - view them. For use in HTTP or other protocols, use the correctly - escaped ASCII form. - - You can convert a list of file names to file URIs using - setFileNames(), or into human-readble form with setUnicodeUris(). - - Static functions are provided to convert between filenames and - URIs, e.g. uriToLocalFile() and localFileToUri(), and to and from - human-readable form, e.g. uriToUnicodeUri(), unicodeUriToUri(). - You can also decode URIs from a mimesource into a list with - decodeLocalFiles() and decodeToUnicodeUris(). -*/ - -/*! - Constructs an object to drag the list of URIs in \a uris. The \a - dragSource and \a name arguments are passed on to TQStoredDrag. - Note that URIs are always in escaped UTF8 encoding. -*/ -TQUriDrag::TQUriDrag( TQStrList uris, - TQWidget * dragSource, const char * name ) : - TQStoredDrag( "text/uri-list", dragSource, name ) -{ - setUris(uris); -} - -/*! - Constructs an object to drag. You must call setUris() before you - start the drag(). Passes \a dragSource and \a name to the - TQStoredDrag constructor. -*/ -TQUriDrag::TQUriDrag( TQWidget * dragSource, const char * name ) : - TQStoredDrag( "text/uri-list", dragSource, name ) -{ -} - -/*! - Destroys the object. -*/ -TQUriDrag::~TQUriDrag() -{ -} - -/*! - Changes the list of \a uris to be dragged. - - Note that URIs are always in escaped UTF8 encoding. -*/ -void TQUriDrag::setUris( TQStrList uris ) -{ - TQByteArray a; - int c=0; - for ( const char* s = uris.first(); s; s = uris.next() ) { - int l = tqstrlen(s); - a.resize(c+l+2); - memcpy(a.data()+c,s,l); - memcpy(a.data()+c+l,"\r\n",2); - c+=l+2; - } - a.resize(c+1); - a[c] = 0; - setEncodedData(a); -} - - -/*! - Returns TRUE if decode() would be able to decode \a e; otherwise - returns FALSE. -*/ -bool TQUriDrag::canDecode( const TQMimeSource* e ) -{ - return e->provides( "text/uri-list" ); -} - -/*! - Decodes URIs from \a e, placing the result in \a l (which is first - cleared). - - Returns TRUE if \a e contained a valid list of URIs; otherwise - returns FALSE. -*/ -bool TQUriDrag::decode( const TQMimeSource* e, TQStrList& l ) -{ - TQByteArray payload = e->encodedData( "text/uri-list" ); - if ( payload.size() ) { - l.clear(); - l.setAutoDelete(TRUE); - uint c=0; - const char* d = payload.data(); - while (c < payload.size() && d[c]) { - uint f = c; - // Find line end - while (c < payload.size() && d[c] && d[c]!='\r' - && d[c] != '\n') - c++; - TQCString s(d+f,c-f+1); - if ( s[0] != '#' ) // non-comment? - l.append( s ); - // Skip junk - while (c < payload.size() && d[c] && - (d[c]=='\n' || d[c]=='\r')) - c++; - } - return TRUE; - } - return FALSE; -} - -static uint htod( int h ) -{ - if ( isdigit(h) ) - return h - '0'; - return tolower( h ) - 'a' + 10; -} - -/*! - \fn TQUriDrag::setFilenames( const TQStringList & ) - \obsolete - - Use setFileNames() instead (notice the N). -*/ - -/*! - Sets the URIs to be the local-file URIs equivalent to \a fnames. - - \sa localFileToUri(), setUris() -*/ -void TQUriDrag::setFileNames( const TQStringList & fnames ) -{ - TQStrList uris; - for ( TQStringList::ConstIterator i = fnames.begin(); - i != fnames.end(); ++i ) { - TQCString fileUri = localFileToUri(*i); - if (!fileUri.isEmpty()) - uris.append(fileUri); - } - setUris( uris ); -} - -/*! - Sets the URIs in \a uuris to be the Unicode URIs (only useful for - displaying to humans). - - \sa localFileToUri(), setUris() -*/ -void TQUriDrag::setUnicodeUris( const TQStringList & uuris ) -{ - TQStrList uris; - for ( TQStringList::ConstIterator i = uuris.begin(); - i != uuris.end(); ++i ) - uris.append( unicodeUriToUri(*i) ); - setUris( uris ); -} - -/*! - Returns the URI equivalent of the Unicode URI given in \a uuri - (only useful for displaying to humans). - - \sa uriToLocalFile() -*/ -TQCString TQUriDrag::unicodeUriToUri(const TQString& uuri) -{ - TQCString utf8 = uuri.utf8(); - TQCString escutf8; - int n = utf8.length(); - bool isFile = uuri.startsWith("file://"); - for (int i=0; i= 'a' && utf8[i] <= 'z') - || utf8[i] == '/' - || (utf8[i] >= '0' && utf8[i] <= '9') - || (utf8[i] >= 'A' && utf8[i] <= 'Z') - - || utf8[i] == '-' || utf8[i] == '_' - || utf8[i] == '.' || utf8[i] == '!' - || utf8[i] == '~' || utf8[i] == '*' - || utf8[i] == '(' || utf8[i] == ')' - || utf8[i] == '\'' - - // Allow this through, so that all URI-references work. - || (!isFile && utf8[i] == '#') - - || utf8[i] == ';' - || utf8[i] == '?' || utf8[i] == ':' - || utf8[i] == '@' || utf8[i] == '&' - || utf8[i] == '=' || utf8[i] == '+' - || utf8[i] == '$' || utf8[i] == ',' ) - { - escutf8 += utf8[i]; - } else { - // Everything else is escaped as %HH - TQCString s(4); - s.sprintf("%%%02x",(uchar)utf8[i]); - escutf8 += s; - } - } - return escutf8; -} - -/*! - Returns the URI equivalent to the absolute local file \a filename. - - \sa uriToLocalFile() -*/ -TQCString TQUriDrag::localFileToUri(const TQString& filename) -{ - TQString r = filename; - - //check that it is an absolute file - if (TQDir::isRelativePath(r)) - return TQCString(); - -#ifdef TQ_WS_WIN - - - bool hasHost = FALSE; - // convert form network path - if (r.left(2) == "\\\\" || r.left(2) == "//") { - r.remove(0, 2); - hasHost = TRUE; - } - - // Slosh -> Slash - int slosh; - while ( (slosh=r.find('\\')) >= 0 ) { - r[slosh] = '/'; - } - - // Drive - if ( r[0] != '/' && !hasHost) - r.insert(0,'/'); - -#endif -#if defined ( TQ_WS_X11 ) && 0 - // URL without the hostname is considered to be errorneous by XDnD. - // See: http://www.newplanetsoftware.com/xdnd/dragging_files.html - // This feature is not active because this would break dnd between old and new qt apps. - char hostname[257]; - if ( gethostname( hostname, 255 ) == 0 ) { - hostname[256] = '\0'; - r.prepend( TQString::fromLatin1( hostname ) ); - } -#endif - return unicodeUriToUri(TQString("file://" + r)); -} - -/*! - Returns the Unicode URI (only useful for displaying to humans) - equivalent of \a uri. - - Note that URIs are always in escaped UTF8 encoding. - - \sa localFileToUri() -*/ -TQString TQUriDrag::uriToUnicodeUri(const char* uri) -{ - TQCString utf8; - - while (*uri) { - switch (*uri) { - case '%': { - uint ch = (uchar) uri[1]; - if ( ch && uri[2] ) { - ch = htod( ch ) * 16 + htod( (uchar) uri[2] ); - utf8 += (char) ch; - uri += 2; - } - } - break; - default: - utf8 += *uri; - } - ++uri; - } - - return TQString::fromUtf8(utf8); -} - -/*! - Returns the name of a local file equivalent to \a uri or a null - string if \a uri is not a local file. - - Note that URIs are always in escaped UTF8 encoding. - - \sa localFileToUri() -*/ -TQString TQUriDrag::uriToLocalFile(const char* uri) -{ - TQString file; - - if (!uri) - return file; - if (0==tqstrnicmp(uri,"file:/",6)) // It is a local file uri - uri += 6; - else if (TQString(uri).find(":/") != -1) // It is a different scheme uri - return file; - - bool local = uri[0] != '/' || ( uri[0] != '\0' && uri[1] == '/' ); -#ifdef TQ_WS_X11 - // do we have a hostname? - if ( !local && uri[0] == '/' && uri[2] != '/' ) { - // then move the pointer to after the 'hostname/' part of the uri - const char* hostname_end = strchr( uri+1, '/' ); - if ( hostname_end != NULL ) { - char hostname[ 257 ]; - if ( gethostname( hostname, 255 ) == 0 ) { - hostname[ 256 ] = '\0'; - if ( tqstrncmp( uri+1, hostname, hostname_end - ( uri+1 )) == 0 ) { - uri = hostname_end + 1; // point after the slash - local = TRUE; - } - } - } - } -#endif - if ( local ) { - file = uriToUnicodeUri(uri); - if ( uri[1] == '/' ) { - file.remove((uint)0,1); - } else { - file.insert(0,'/'); - } -#ifdef TQ_WS_WIN - if ( file.length() > 2 && file[0] == '/' && file[2] == '|' ) { - file[2] = ':'; - file.remove(0,1); - } else if (file.length() > 2 && file[0] == '/' && file[1].isLetter() && file[2] == ':') { - file.remove(0, 1); - } - // Leave slash as slashes. -#endif - } -#ifdef TQ_WS_WIN - else { - file = uriToUnicodeUri(uri); - // convert to network path - file.insert(1, '/'); // leave as forward slashes - } -#endif - - return file; -} - -/*! - Decodes URIs from the mime source event \a e, converts them to - local files if they refer to local files, and places them in \a l - (which is first cleared). - - Returns TRUE if \e contained a valid list of URIs; otherwise - returns FALSE. The list will be empty if no URIs were local files. -*/ -bool TQUriDrag::decodeLocalFiles( const TQMimeSource* e, TQStringList& l ) -{ - TQStrList u; - if ( !decode( e, u ) ) - return FALSE; - - l.clear(); - for (const char* s=u.first(); s; s=u.next()) { - TQString lf = uriToLocalFile(s); - if ( !lf.isNull() ) - l.append( lf ); - } - return TRUE; -} - -/*! - Decodes URIs from the mime source event \a e, converts them to - Unicode URIs (only useful for displaying to humans), placing them - in \a l (which is first cleared). - - Returns TRUE if \e contained a valid list of URIs; otherwise - returns FALSE. -*/ -bool TQUriDrag::decodeToUnicodeUris( const TQMimeSource* e, TQStringList& l ) -{ - TQStrList u; - if ( !decode( e, u ) ) - return FALSE; - - l.clear(); - for (const char* s=u.first(); s; s=u.next()) - l.append( uriToUnicodeUri(s) ); - - return TRUE; -} - - -#ifndef TQT_NO_DRAGANDDROP -/*! - If the source of the drag operation is a widget in this - application, this function returns that source, otherwise it - returns 0. The source of the operation is the first parameter to - drag object subclasses. - - This is useful if your widget needs special behavior when dragging - to itself, etc. - - See TQDragObject::TQDragObject() and subclasses. -*/ -TQWidget* TQDropEvent::source() const -{ - return qt_dnd_manager ? qt_dnd_manager->dragSource : 0; -} -#endif - -/*! - \class TQColorDrag ntqdragobject.h - - \brief The TQColorDrag class provides a drag and drop object for - transferring colors. - - \ingroup draganddrop - - This class provides a drag object which can be used to transfer data - about colors for drag and drop and in the clipboard. For example, it - is used in TQColorDialog. - - The color is set in the constructor but can be changed with - setColor(). - - For more information about drag and drop, see the TQDragObject class - and the \link dnd.html drag and drop documentation\endlink. -*/ - -/*! - Constructs a color drag object with the color \a col. Passes \a - dragsource and \a name to the TQStoredDrag constructor. -*/ - -TQColorDrag::TQColorDrag( const TQColor &col, TQWidget *dragsource, const char *name ) - : TQStoredDrag( "application/x-color", dragsource, name ) -{ - setColor( col ); -} - -/*! - Constructs a color drag object with a white color. Passes \a - dragsource and \a name to the TQStoredDrag constructor. -*/ - -TQColorDrag::TQColorDrag( TQWidget *dragsource, const char *name ) - : TQStoredDrag( "application/x-color", dragsource, name ) -{ - setColor( TQt::white ); -} - -/*! - Sets the color of the color drag to \a col. -*/ - -void TQColorDrag::setColor( const TQColor &col ) -{ - unsigned short r = (col.red() << 8) | col.red(); - unsigned short g = (col.green() << 8) | col.green(); - unsigned short b = (col.blue() << 8) | col.blue(); - - // make sure we transmit data in network order - r = htons(r); - g = htons(g); - b = htons(b); - - ushort rgba[4] = { - r, g, b, - 0xffff // Alpha not supported yet. - }; - TQByteArray data(sizeof(rgba)); - memcpy(data.data(), rgba, sizeof(rgba)); - setEncodedData(data); -} - -/*! - Returns TRUE if the color drag object can decode the mime source - \a e; otherwise returns FALSE. -*/ - -bool TQColorDrag::canDecode( TQMimeSource *e ) -{ - return e->provides( "application/x-color" ); -} - -/*! - Decodes the mime source \a e and sets the decoded values to \a - col. -*/ - -bool TQColorDrag::decode( TQMimeSource *e, TQColor &col ) -{ - TQByteArray data = e->encodedData("application/x-color"); - ushort rgba[4]; - if (data.size() != sizeof(rgba)) - return FALSE; - - memcpy(rgba, data.data(), sizeof(rgba)); - - short r = rgba[0]; - short g = rgba[1]; - short b = rgba[2]; - - // data is in network order - r = ntohs(r); - g = ntohs(g); - b = ntohs(b); - - r = (r >> 8) & 0xff; - g = (g >> 8) & 0xff; - b = (b >> 8) & 0xff; - - col.setRgb(r, g, b); - return TRUE; -} - -#endif // TQT_NO_MIME diff --git a/src/kernel/qdropsite.cpp b/src/kernel/qdropsite.cpp deleted file mode 100644 index a8d3a8728..000000000 --- a/src/kernel/qdropsite.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Implementation of Drag and Drop support -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqdropsite.h" - -#ifndef TQT_NO_DRAGANDDROP - -#include "tqwidget.h" - - -// NOT REVISED -/*! - \class TQDropSite ntqdropsite.h - \brief The TQDropSite class provides nothing and does nothing. - - \obsolete - - If your code uses it, you can safely delete it. - - It was used in TQt 1.x to do some drag and drop; that has since been - folded into TQWidget. - - For detailed information about drag-and-drop, see the TQDragObject class. - - \sa TQDragObject, TQTextDrag, TQImageDrag -*/ - -/*! - Constructs a TQDropSite to handle events for the widget \a self. - - Pass \c this as the \a self parameter. - This enables dropping by calling TQWidget::setAcceptDrops(TRUE). -*/ -TQDropSite::TQDropSite( TQWidget* self ) -{ - self->setAcceptDrops( TRUE ); -} - -/*! - Destroys the drop site. -*/ -TQDropSite::~TQDropSite() -{ -} - -#endif // TQT_NO_DRAGANDDROP diff --git a/src/kernel/qmime.cpp b/src/kernel/qmime.cpp deleted file mode 100644 index de6dc3403..000000000 --- a/src/kernel/qmime.cpp +++ /dev/null @@ -1,619 +0,0 @@ -/**************************************************************************** -** -** Implementation of MIME support -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqmime.h" - -#ifndef TQT_NO_MIME - -#include "tqmap.h" -#include "tqstringlist.h" -#include "ntqfileinfo.h" -#include "ntqdir.h" -#include "ntqdragobject.h" -#include "ntqcleanuphandler.h" -#include "ntqapplication.h" // ### for now -#include "ntqclipboard.h" // ### for now - -/*! - \class TQMimeSource ntqmime.h - \brief The TQMimeSource class is an abstraction of objects which provide formatted data of a certain MIME type. - - \ingroup io - \ingroup draganddrop - \ingroup misc - - \link dnd.html Drag-and-drop\endlink and - \link TQClipboard clipboard\endlink use this abstraction. - - \sa \link http://www.isi.edu/in-notes/iana/assignments/media-types/ - IANA list of MIME media types\endlink -*/ - -static int qt_mime_serial_number = 0; -static TQMimeSourceFactory* defaultfactory = 0; -static TQSingleCleanupHandler qmime_cleanup_factory; - -/*! - Constructs a mime source and assigns a globally unique serial - number to it. - - \sa serialNumber() -*/ - -TQMimeSource::TQMimeSource() -{ - ser_no = qt_mime_serial_number++; - cacheType = NoCache; -} - -/*! - \fn int TQMimeSource::serialNumber() const - - Returns the mime source's globally unique serial number. -*/ - - -void TQMimeSource::clearCache() -{ - if ( cacheType == Text ) { - delete cache.txt.str; - delete cache.txt.subtype; - cache.txt.str = 0; - cache.txt.subtype = 0; - } else if ( cacheType == Graphics ) { - delete cache.gfx.img; - delete cache.gfx.pix; - cache.gfx.img = 0; - cache.gfx.pix = 0; - } - cacheType = NoCache; -} - -/*! - Provided to ensure that subclasses destroy themselves correctly. -*/ -TQMimeSource::~TQMimeSource() -{ -#ifndef TQT_NO_CLIPBOARD - extern void tqt_clipboard_cleanup_mime_source(TQMimeSource *); - tqt_clipboard_cleanup_mime_source(this); -#endif - clearCache(); -} - -/*! - \fn TQByteArray TQMimeSource::encodedData(const char*) const - - Returns the encoded data of this object in the specified MIME - format. - - Subclasses must reimplement this function. -*/ - - - -/*! - Returns TRUE if the object can provide the data in format \a - mimeType; otherwise returns FALSE. - - If you inherit from TQMimeSource, for consistency reasons it is - better to implement the more abstract canDecode() functions such - as TQTextDrag::canDecode() and TQImageDrag::canDecode(). -*/ -bool TQMimeSource::provides(const char* mimeType) const -{ - const char* fmt; - for (int i=0; (fmt = format(i)); i++) { - if ( !tqstricmp(mimeType,fmt) ) { - return TRUE; - } - } - return FALSE; -} - - -/*! - \fn const char * TQMimeSource::format(int i) const - - Returns the \a{i}-th supported MIME format, or 0. -*/ - - - -class TQMimeSourceFactoryData { -public: - TQMimeSourceFactoryData() : - last(0) - { - } - - ~TQMimeSourceFactoryData() - { - TQMap::Iterator it = stored.begin(); - while ( it != stored.end() ) { - delete *it; - ++it; - } - delete last; - } - - TQMap stored; - TQMap extensions; - TQStringList path; - TQMimeSource* last; - TQPtrList factories; -}; - - -/*! - \class TQMimeSourceFactory ntqmime.h - \brief The TQMimeSourceFactory class is an extensible provider of mime-typed data. - - \ingroup io - \ingroup environment - - A TQMimeSourceFactory provides an abstract interface to a - collection of information. Each piece of information is - represented by a TQMimeSource object which can be examined and - converted to concrete data types by functions such as - TQImageDrag::canDecode() and TQImageDrag::decode(). - - The base TQMimeSourceFactory can be used in two ways: as an - abstraction of a collection of files or as specifically stored - data. For it to access files, call setFilePath() before accessing - data. For stored data, call setData() for each item (there are - also convenience functions, e.g. setText(), setImage() and - setPixmap(), that simply call setData() with appropriate - parameters). - - The rich text widgets, TQTextEdit and TQTextBrowser, use - TQMimeSourceFactory to resolve references such as images or links - within rich text documents. They either access the default factory - (see \l{defaultFactory()}) or their own (see - \l{TQTextEdit::setMimeSourceFactory()}). Other classes that are - capable of displaying rich text (such as TQLabel, TQWhatsThis or - TQMessageBox) always use the default factory. - - A factory can also be used as a container to store data associated - with a name. This technique is useful whenever rich text contains - images that are stored in the program itself, not loaded from the - hard disk. Your program may, for example, define some image data - as: - \code - static const char* myimage_data[]={ - "...", - ... - "..."}; - \endcode - - To be able to use this image within some rich text, for example - inside a TQLabel, you must create a TQImage from the raw data and - insert it into the factory with a unique name: - \code - TQMimeSourceFactory::defaultFactory()->setImage( "myimage", TQImage(myimage_data) ); - \endcode - - Now you can create a rich text TQLabel with - - \code - TQLabel* label = new TQLabel( - "Rich text with embedded image:" - "Isn't that cute?" ); - \endcode - - When no longer needed, you can clear the data from the factory: - - \code - delete label; - TQMimeSourceFactory::defaultFactory()->setData( "myimage", 0 ); - \endcode -*/ - - -/*! - Constructs a TQMimeSourceFactory that has no file path and no - stored content. -*/ -TQMimeSourceFactory::TQMimeSourceFactory() : - d(new TQMimeSourceFactoryData) -{ - // add some reasonable defaults - setExtensionType("htm", "text/html;charset=iso8859-1"); - setExtensionType("html", "text/html;charset=iso8859-1"); - setExtensionType("txt", "text/plain"); - setExtensionType("xml", "text/xml;charset=UTF-8"); - setExtensionType("jpg", "image/jpeg"); // support misspelled jpeg files -} - -/*! - Destroys the TQMimeSourceFactory, deleting all stored content. -*/ -TQMimeSourceFactory::~TQMimeSourceFactory() -{ - if ( defaultFactory() == this ) - defaultfactory = 0; - delete d; -} - -TQMimeSource* TQMimeSourceFactory::dataInternal(const TQString& abs_name, const TQMap &extensions ) const -{ - TQMimeSource* r = 0; - TQFileInfo fi(abs_name); - if ( fi.isReadable() ) { - - // get the right mimetype - TQString e = fi.extension(FALSE); - TQCString mimetype = "application/octet-stream"; - const char* imgfmt; - if ( extensions.contains(e) ) - mimetype = extensions[e].latin1(); - else if ( ( imgfmt = TQImage::imageFormat( abs_name ) ) ) - mimetype = TQCString("image/")+TQCString(imgfmt).lower(); - - TQFile f(abs_name); - if ( f.open(IO_ReadOnly) && f.size() ) { - TQByteArray ba(f.size()); - f.readBlock(ba.data(), ba.size()); - TQStoredDrag* sr = new TQStoredDrag( mimetype ); - sr->setEncodedData( ba ); - delete d->last; - d->last = r = sr; - } - } - - // we didn't find the mime-source, so ask the default factory for - // the mime-source (this one will iterate over all installed ones) - // - // this looks dangerous, as this dataInternal() function will be - // called again when the default factory loops over all installed - // factories (including this), but the static bool looping in - // data() avoids endless recursions - if ( !r && this != defaultFactory() ) - r = (TQMimeSource*)defaultFactory()->data( abs_name ); - - return r; -} - - -/*! - Returns a reference to the data associated with \a abs_name. The - return value remains valid only until the next data() or setData() - call, so you should immediately decode the result. - - If there is no data associated with \a abs_name in the factory's - store, the factory tries to access the local filesystem. If \a - abs_name isn't an absolute file name, the factory will search for - it in all defined paths (see \l{setFilePath()}). - - The factory understands all the image formats supported by - TQImageIO. Any other mime types are determined by the file name - extension. The default settings are - \code - setExtensionType("html", "text/html;charset=iso8859-1"); - setExtensionType("htm", "text/html;charset=iso8859-1"); - setExtensionType("txt", "text/plain"); - setExtensionType("xml", "text/xml;charset=UTF-8"); - \endcode - The effect of these is that file names ending in "txt" will be - treated as text encoded in the local encoding; those ending in - "xml" will be treated as text encoded in Unicode UTF-8 encoding. - The text/html type is treated specially, since the encoding can be - specified in the html file itself. "html" or "htm" will be treated - as text encoded in the encoding specified by the html meta tag, if - none could be found, the charset of the mime type will be used. - The text subtype ("html", "plain", or "xml") does not affect the - factory, but users of the factory may behave differently. We - recommend creating "xml" files where practical. These files can be - viewed regardless of the runtime encoding and can encode any - Unicode characters without resorting to encoding definitions - inside the file. - - Any file data that is not recognized will be retrieved as a - TQMimeSource providing the "application/octet-stream" mime type, - meaning uninterpreted binary data. - - You can add further extensions or change existing ones with - subsequent calls to setExtensionType(). If the extension mechanism - is not sufficient for your problem domain, you can inherit - TQMimeSourceFactory and reimplement this function to perform some - more specialized mime-type detection. The same applies if you want - to use the mime source factory to access URL referenced data over - a network. -*/ -const TQMimeSource* TQMimeSourceFactory::data(const TQString& abs_name) const -{ - if ( d->stored.contains(abs_name) ) - return d->stored[abs_name]; - - TQMimeSource* r = 0; - TQStringList::Iterator it; - if ( abs_name[0] == '/' -#ifdef TQ_WS_WIN - || ( abs_name[0] && abs_name[1] == ':' ) || abs_name.startsWith("\\\\") -#endif - ) - { - // handle absolute file names directly - r = dataInternal( abs_name, d->extensions); - } - else { // check list of paths - for ( it = d->path.begin(); !r && it != d->path.end(); ++it ) { - TQString filename = *it; - if ( filename[(int)filename.length()-1] != '/' ) - filename += '/'; - filename += abs_name; - r = dataInternal( filename, d->extensions ); - } - } - - static bool looping = FALSE; - if ( !r && this == defaultFactory() ) { - // we found no mime-source and we are the default factory, so - // we know all the other installed mime-source factories, so - // ask them - if ( !looping ) { - // to avoid endless recustions, don't enter the loop below - // if data() got called from within the loop below - looping = TRUE; - TQPtrListIterator it( d->factories ); - TQMimeSourceFactory *f; - while ( ( f = it.current() ) ) { - ++it; - if ( f == this ) - continue; - r = (TQMimeSource*)f->data( abs_name ); - if ( r ) { - looping = FALSE; - return r; - } - } - looping = FALSE; - } - } else if ( !r ) { - // we are not the default mime-source factory, so ask the - // default one for the mime-source, as this one will loop over - // all installed mime-source factories and ask these - r = (TQMimeSource*)defaultFactory()->data( abs_name ); - } - - return r; -} - -/*! - Sets the list of directories that will be searched when named data - is requested to the those given in the string list \a path. - - \sa filePath() -*/ -void TQMimeSourceFactory::setFilePath( const TQStringList& path ) -{ - d->path = path; -} - -/*! - Returns the currently set search paths. -*/ -TQStringList TQMimeSourceFactory::filePath() const -{ - return d->path; -} - -/*! - Adds another search path, \a p to the existing search paths. - - \sa setFilePath() -*/ -void TQMimeSourceFactory::addFilePath( const TQString& p ) -{ - d->path += p; -} - -/*! - Sets the mime-type to be associated with the file name extension, - \a ext to \a mimetype. This determines the mime-type for files - found via the paths set by setFilePath(). -*/ -void TQMimeSourceFactory::setExtensionType( const TQString& ext, const char* mimetype ) -{ - d->extensions.replace(ext, mimetype); -} - -/*! - Converts the absolute or relative data item name \a - abs_or_rel_name to an absolute name, interpreted within the - context (path) of the data item named \a context (this must be an - absolute name). -*/ -TQString TQMimeSourceFactory::makeAbsolute(const TQString& abs_or_rel_name, const TQString& context) const -{ - if ( context.isNull() || - !(context[0] == '/' -#ifdef TQ_WS_WIN - || ( context[0] && context[1] == ':') -#endif - )) - return abs_or_rel_name; - if ( abs_or_rel_name.isEmpty() ) - return context; - TQFileInfo c( context ); - if (!c.isDir()) { - TQFileInfo r( c.dir(TRUE), abs_or_rel_name ); - return r.absFilePath(); - } else { - TQDir d(context); - TQFileInfo r(d, abs_or_rel_name); - return r.absFilePath(); - } -} - -/*! - \overload - A convenience function. See data(const TQString& abs_name). The - file name is given in \a abs_or_rel_name and the path is in \a - context. -*/ -const TQMimeSource* TQMimeSourceFactory::data(const TQString& abs_or_rel_name, const TQString& context) const -{ - const TQMimeSource* r = data(makeAbsolute(abs_or_rel_name,context)); - if ( !r && !d->path.isEmpty() ) - r = data(abs_or_rel_name); - return r; -} - - -/*! - Sets \a text to be the data item associated with the absolute name - \a abs_name. - - Equivalent to setData(abs_name, new TQTextDrag(text)). -*/ -void TQMimeSourceFactory::setText( const TQString& abs_name, const TQString& text ) -{ - setData(abs_name, new TQTextDrag(text)); -} - -/*! - Sets \a image to be the data item associated with the absolute - name \a abs_name. - - Equivalent to setData(abs_name, new TQImageDrag(image)). -*/ -void TQMimeSourceFactory::setImage( const TQString& abs_name, const TQImage& image ) -{ - setData(abs_name, new TQImageDrag(image)); -} - -/*! - Sets \a pixmap to be the data item associated with the absolute - name \a abs_name. -*/ -void TQMimeSourceFactory::setPixmap( const TQString& abs_name, const TQPixmap& pixmap ) -{ - setData(abs_name, new TQImageDrag(pixmap.convertToImage())); -} - -/*! - Sets \a data to be the data item associated with - the absolute name \a abs_name. Note that the ownership of \a data is - transferred to the factory: do not delete or access the pointer after - passing it to this function. - - Passing 0 for data removes previously stored data. -*/ -void TQMimeSourceFactory::setData( const TQString& abs_name, TQMimeSource* data ) -{ - if ( d->stored.contains(abs_name) ) - delete d->stored[abs_name]; - d->stored.replace(abs_name,data); -} - - -/*! - Returns the application-wide default mime source factory. This - factory is used by rich text rendering classes such as - TQSimpleRichText, TQWhatsThis and TQMessageBox to resolve named - references within rich text documents. It serves also as the - initial factory for the more complex render widgets, TQTextEdit and - TQTextBrowser. - - \sa setDefaultFactory() -*/ -TQMimeSourceFactory* TQMimeSourceFactory::defaultFactory() -{ - if (!defaultfactory) - { - defaultfactory = new TQMimeSourceFactory(); - qmime_cleanup_factory.set( &defaultfactory ); - } - return defaultfactory; -} - -/*! - Sets the default \a factory, destroying any previously set mime - source provider. The ownership of the factory is transferred to - TQt. - - \sa defaultFactory() -*/ -void TQMimeSourceFactory::setDefaultFactory( TQMimeSourceFactory* factory) -{ - if ( !defaultfactory ) - qmime_cleanup_factory.set( &defaultfactory ); - else if ( defaultfactory != factory ) - delete defaultfactory; - defaultfactory = factory; -} - -/*! - Sets the defaultFactory() to 0 and returns the previous one. -*/ - -TQMimeSourceFactory* TQMimeSourceFactory::takeDefaultFactory() -{ - TQMimeSourceFactory *f = defaultfactory; - defaultfactory = 0; - return f; -} - -/*! - Adds the TQMimeSourceFactory \a f to the list of available - mimesource factories. If the defaultFactory() can't resolve a - data() it iterates over the list of installed mimesource factories - until the data can be resolved. - - \sa removeFactory(); -*/ - -void TQMimeSourceFactory::addFactory( TQMimeSourceFactory *f ) -{ - TQMimeSourceFactory::defaultFactory()->d->factories.append( f ); -} - -/*! - Removes the mimesource factory \a f from the list of available - mimesource factories. - - \sa addFactory(); -*/ - -void TQMimeSourceFactory::removeFactory( TQMimeSourceFactory *f ) -{ - TQMimeSourceFactory::defaultFactory()->d->factories.removeRef( f ); -} - -#endif // TQT_NO_MIME diff --git a/src/kernel/qpixmap.cpp b/src/kernel/qpixmap.cpp index 7ba49ee4e..9ac10d30c 100644 --- a/src/kernel/qpixmap.cpp +++ b/src/kernel/qpixmap.cpp @@ -49,8 +49,8 @@ #include "tqobjectlist.h" #include "ntqapplication.h" #include -#include "ntqmime.h" -#include "ntqdragobject.h" +#include "tqmime.h" +#include "tqdragobject.h" #include "ntqfile.h" /*! diff --git a/src/kernel/qrichtext.cpp b/src/kernel/qrichtext.cpp index 2e7103aec..a1dfd6719 100644 --- a/src/kernel/qrichtext.cpp +++ b/src/kernel/qrichtext.cpp @@ -51,9 +51,9 @@ #include "tqmap.h" #include "ntqfileinfo.h" #include "tqstylesheet.h" -#include "ntqmime.h" +#include "tqmime.h" #include "tqimage.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqpaintdevicemetrics.h" #include "ntqpainter.h" #include "ntqdrawutil.h" diff --git a/src/kernel/qt_kernel.pri b/src/kernel/qt_kernel.pri index daa778a13..6a6cce7ef 100644 --- a/src/kernel/qt_kernel.pri +++ b/src/kernel/qt_kernel.pri @@ -17,9 +17,9 @@ kernel { $$KERNEL_H/ntqconnection.h \ $$KERNEL_H/ntqcursor.h \ $$KERNEL_H/ntqdesktopwidget.h \ - $$KERNEL_H/ntqdragobject.h \ + $$KERNEL_H/tqdragobject.h \ $$KERNEL_H/ntqdrawutil.h \ - $$KERNEL_H/ntqdropsite.h \ + $$KERNEL_H/tqdropsite.h \ $$KERNEL_H/ntqevent.h \ $$KERNEL_H/ntqeventloop.h \ $$KERNEL_P/qeventloop_p.h \ @@ -41,7 +41,7 @@ kernel { $$KERNEL_P/qlayoutengine_p.h \ $$KERNEL_H/ntqtranslator.h \ $$KERNEL_H/ntqmetaobject.h \ - $$KERNEL_H/ntqmime.h \ + $$KERNEL_H/tqmime.h \ $$KERNEL_H/ntqmovie.h \ $$KERNEL_H/ntqnamespace.h \ $$KERNEL_H/ntqnetworkprotocol.h \ @@ -119,7 +119,7 @@ kernel { $$KERNEL_CPP/qeventloop_win.cpp \ $$KERNEL_CPP/qfont_win.cpp \ $$KERNEL_CPP/qinputcontext_win.cpp \ - $$KERNEL_CPP/qmime_win.cpp \ + $$KERNEL_CPP/tqmime_win.cpp \ $$KERNEL_CPP/qpixmap_win.cpp \ $$KERNEL_CPP/qprinter_win.cpp \ $$KERNEL_CPP/qprocess_win.cpp \ @@ -167,7 +167,7 @@ kernel { $$KERNEL_CPP/qclipboard_mac.cpp \ $$KERNEL_CPP/qcolor_mac.cpp \ $$KERNEL_CPP/qcursor_mac.cpp \ - $$KERNEL_CPP/qmime_mac.cpp \ + $$KERNEL_CPP/tqmime_mac.cpp \ $$KERNEL_CPP/qdnd_mac.cpp \ $$KERNEL_CPP/qdesktopwidget_mac.cpp \ $$KERNEL_CPP/qpixmap_mac.cpp \ @@ -205,9 +205,9 @@ kernel { $$KERNEL_CPP/qcolor_p.cpp \ $$KERNEL_CPP/qconnection.cpp \ $$KERNEL_CPP/qcursor.cpp \ - $$KERNEL_CPP/qdragobject.cpp \ + $$KERNEL_CPP/tqdragobject.cpp \ $$KERNEL_CPP/qdrawutil.cpp \ - $$KERNEL_CPP/qdropsite.cpp \ + $$KERNEL_CPP/tqdropsite.cpp \ $$KERNEL_CPP/qevent.cpp \ $$KERNEL_CPP/qeventloop.cpp \ $$KERNEL_CPP/qfocusdata.cpp \ @@ -222,7 +222,7 @@ kernel { $$KERNEL_CPP/qlayoutengine.cpp \ $$KERNEL_CPP/qtranslator.cpp \ $$KERNEL_CPP/qmetaobject.cpp \ - $$KERNEL_CPP/qmime.cpp \ + $$KERNEL_CPP/tqmime.cpp \ $$KERNEL_CPP/qmovie.cpp \ $$KERNEL_CPP/qnetworkprotocol.cpp \ $$KERNEL_CPP/tqobject.cpp \ diff --git a/src/kernel/tqdragobject.cpp b/src/kernel/tqdragobject.cpp new file mode 100644 index 000000000..77e726477 --- /dev/null +++ b/src/kernel/tqdragobject.cpp @@ -0,0 +1,1811 @@ +/**************************************************************************** +** +** Implementation of Drag and Drop support +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "qplatformdefs.h" + +// POSIX Large File Support redefines open -> open64 +#if defined(open) +# undef open +#endif + +#ifndef TQT_NO_MIME + +#include "tqdragobject.h" +#include "tqtextcodec.h" +#include "ntqapplication.h" +#include "ntqpoint.h" +#include "tqwidget.h" +#include "ntqbuffer.h" +#include "ntqgif.h" +#include "ntqregexp.h" +#include "ntqdir.h" +#include + +// both a struct for storing stuff in and a wrapper to avoid polluting +// the name space + +class TQDragObjectData +{ +public: + TQDragObjectData(): hot(0,0) {} + TQPixmap pixmap; + TQPoint hot; + // store default cursors + TQPixmap *pm_cursor; +}; + +static TQWidget* last_target; + +/*! + After the drag completes, this function will return the TQWidget + which received the drop, or 0 if the data was dropped on another + application. + + This can be useful for detecting the case where drag and drop is + to and from the same widget. +*/ +TQWidget * TQDragObject::target() +{ + return last_target; +} + +/*! + \internal + Sets the target. +*/ +void TQDragObject::setTarget(TQWidget* t) +{ + last_target = t; +} + +class TQStoredDragData +{ +public: + TQStoredDragData() {} + const char* fmt; + TQByteArray enc; +}; + + +// These pixmaps approximate the images in the Windows User Interface Guidelines. + +// XPM + +static const char * const move_xpm[] = { +"11 20 3 1", +". c None", +#if defined(TQ_WS_WIN) +"a c #000000", +"X c #FFFFFF", // Windows cursor is traditionally white +#else +"a c #FFFFFF", +"X c #000000", // X11 cursor is traditionally black +#endif +"aa.........", +"aXa........", +"aXXa.......", +"aXXXa......", +"aXXXXa.....", +"aXXXXXa....", +"aXXXXXXa...", +"aXXXXXXXa..", +"aXXXXXXXXa.", +"aXXXXXXXXXa", +"aXXXXXXaaaa", +"aXXXaXXa...", +"aXXaaXXa...", +"aXa..aXXa..", +"aa...aXXa..", +"a.....aXXa.", +"......aXXa.", +".......aXXa", +".......aXXa", +"........aa."}; + +/* XPM */ +static const char * const copy_xpm[] = { +"24 30 3 1", +". c None", +"a c #000000", +"X c #FFFFFF", +#if defined(TQ_WS_WIN) // Windows cursor is traditionally white +"aa......................", +"aXa.....................", +"aXXa....................", +"aXXXa...................", +"aXXXXa..................", +"aXXXXXa.................", +"aXXXXXXa................", +"aXXXXXXXa...............", +"aXXXXXXXXa..............", +"aXXXXXXXXXa.............", +"aXXXXXXaaaa.............", +"aXXXaXXa................", +"aXXaaXXa................", +"aXa..aXXa...............", +"aa...aXXa...............", +"a.....aXXa..............", +"......aXXa..............", +".......aXXa.............", +".......aXXa.............", +"........aa...aaaaaaaaaaa", +#else +"XX......................", +"XaX.....................", +"XaaX....................", +"XaaaX...................", +"XaaaaX..................", +"XaaaaaX.................", +"XaaaaaaX................", +"XaaaaaaaX...............", +"XaaaaaaaaX..............", +"XaaaaaaaaaX.............", +"XaaaaaaXXXX.............", +"XaaaXaaX................", +"XaaXXaaX................", +"XaX..XaaX...............", +"XX...XaaX...............", +"X.....XaaX..............", +"......XaaX..............", +".......XaaX.............", +".......XaaX.............", +"........XX...aaaaaaaaaaa", +#endif +".............aXXXXXXXXXa", +".............aXXXXXXXXXa", +".............aXXXXaXXXXa", +".............aXXXXaXXXXa", +".............aXXaaaaaXXa", +".............aXXXXaXXXXa", +".............aXXXXaXXXXa", +".............aXXXXXXXXXa", +".............aXXXXXXXXXa", +".............aaaaaaaaaaa"}; + +/* XPM */ +static const char * const link_xpm[] = { +"24 30 3 1", +". c None", +"a c #000000", +"X c #FFFFFF", +#if defined(TQ_WS_WIN) // Windows cursor is traditionally white +"aa......................", +"aXa.....................", +"aXXa....................", +"aXXXa...................", +"aXXXXa..................", +"aXXXXXa.................", +"aXXXXXXa................", +"aXXXXXXXa...............", +"aXXXXXXXXa..............", +"aXXXXXXXXXa.............", +"aXXXXXXaaaa.............", +"aXXXaXXa................", +"aXXaaXXa................", +"aXa..aXXa...............", +"aa...aXXa...............", +"a.....aXXa..............", +"......aXXa..............", +".......aXXa.............", +".......aXXa.............", +"........aa...aaaaaaaaaaa", +#else +"XX......................", +"XaX.....................", +"XaaX....................", +"XaaaX...................", +"XaaaaX..................", +"XaaaaaX.................", +"XaaaaaaX................", +"XaaaaaaaX...............", +"XaaaaaaaaX..............", +"XaaaaaaaaaX.............", +"XaaaaaaXXXX.............", +"XaaaXaaX................", +"XaaXXaaX................", +"XaX..XaaX...............", +"XX...XaaX...............", +"X.....XaaX..............", +"......XaaX..............", +".......XaaX.............", +".......XaaX.............", +"........XX...aaaaaaaaaaa", +#endif +".............aXXXXXXXXXa", +".............aXXXaaaaXXa", +".............aXXXXaaaXXa", +".............aXXXaaaaXXa", +".............aXXaaaXaXXa", +".............aXXaaXXXXXa", +".............aXXaXXXXXXa", +".............aXXXaXXXXXa", +".............aXXXXXXXXXa", +".............aaaaaaaaaaa"}; + +#ifndef TQT_NO_DRAGANDDROP + +// the universe's only drag manager +TQDragManager * qt_dnd_manager = 0; + + +TQDragManager::TQDragManager() + : TQObject( tqApp, "global drag manager" ) +{ + n_cursor = 3; + pm_cursor = new TQPixmap[n_cursor]; + pm_cursor[0] = TQPixmap((const char **)move_xpm); + pm_cursor[1] = TQPixmap((const char **)copy_xpm); + pm_cursor[2] = TQPixmap((const char **)link_xpm); +#if defined(TQ_WS_X11) + createCursors(); // Xcursors cache can hold only 8 bitmaps (4 cursors) +#endif + object = 0; + dragSource = 0; + dropWidget = 0; + if ( !qt_dnd_manager ) + qt_dnd_manager = this; + beingCancelled = FALSE; + restoreCursor = FALSE; + willDrop = FALSE; +} + + +TQDragManager::~TQDragManager() +{ +#ifndef TQT_NO_CURSOR + if ( restoreCursor ) + TQApplication::restoreOverrideCursor(); +#endif + qt_dnd_manager = 0; + delete [] pm_cursor; +} + +#endif + + +/*! + Constructs a drag object called \a name, which is a child of \a + dragSource. + + Note that the drag object will be deleted when \a dragSource is + deleted. +*/ + +TQDragObject::TQDragObject( TQWidget * dragSource, const char * name ) + : TQObject( dragSource, name ) +{ + d = new TQDragObjectData(); + d->pm_cursor = 0; +#ifndef TQT_NO_DRAGANDDROP + if ( !qt_dnd_manager && tqApp ) + (void)new TQDragManager(); +#endif +} + + +/*! + Destroys the drag object, canceling any drag and drop operation in + which it is involved, and frees up the storage used. +*/ + +TQDragObject::~TQDragObject() +{ +#ifndef TQT_NO_DRAGANDDROP + if ( qt_dnd_manager && qt_dnd_manager->object == this ) + qt_dnd_manager->cancel( FALSE ); + if ( d->pm_cursor ) { + for ( int i = 0; i < qt_dnd_manager->n_cursor; i++ ) + qt_dnd_manager->pm_cursor[i] = d->pm_cursor[i]; + delete [] d->pm_cursor; + } +#endif + delete d; +} + +#ifndef TQT_NO_DRAGANDDROP +/*! + Set the pixmap \a pm to display while dragging the object. The + platform-specific implementation will use this where it can - so + provide a small masked pixmap, and do not assume that the user + will actually see it. For example, cursors on Windows 95 are of + limited size. + + The \a hotspot is the point on (or off) the pixmap that should be + under the cursor as it is dragged. It is relative to the top-left + pixel of the pixmap. + + \warning We have seen problems with drag cursors on different + graphics hardware and driver software on Windows. Setting the + graphics acceleration in the display settings down one tick solved + the problems in all cases. +*/ +void TQDragObject::setPixmap(TQPixmap pm, const TQPoint& hotspot) +{ + d->pixmap = pm; + d->hot = hotspot; + if ( qt_dnd_manager && qt_dnd_manager->object == this ) + qt_dnd_manager->updatePixmap(); +} + +/*! + \overload + Uses a hotspot that positions the pixmap below and to the right of + the mouse pointer. This allows the user to clearly see the point + on the window which they are dragging the data onto. +*/ +void TQDragObject::setPixmap(TQPixmap pm) +{ + setPixmap(pm,TQPoint(-10, -10)); +} + +/*! + Returns the currently set pixmap (which \link TQPixmap::isNull() + isNull()\endlink if none is set). +*/ +TQPixmap TQDragObject::pixmap() const +{ + return d->pixmap; +} + +/*! + Returns the currently set pixmap hotspot. +*/ +TQPoint TQDragObject::pixmapHotSpot() const +{ + return d->hot; +} + +#if 0 + +// ## reevaluate for TQt 4 +/*! + Set the \a cursor used when dragging in mode \a m. + Note: X11 only allow bitmaps for cursors. +*/ +void TQDragObject::setCursor( DragMode m, const TQPixmap &cursor ) +{ + if ( d->pm_cursor == 0 ) { + // safe default cursors + d->pm_cursor = new TQPixmap[qt_dnd_manager->n_cursor]; + for ( int i = 0; i < qt_dnd_manager->n_cursor; i++ ) + d->pm_cursor[i] = qt_dnd_manager->pm_cursor[i]; + } + + int index; + switch ( m ) { + case DragCopy: + index = 1; + break; + case DragLink: + index = 2; + break; + default: + index = 0; + break; + } + + // override default cursor + for ( index = 0; index < qt_dnd_manager->n_cursor; index++ ) + qt_dnd_manager->pm_cursor[index] = cursor; +} + +/*! + Returns the cursor used when dragging in mode \a m, or null if no cursor + has been set for that mode. +*/ +TQPixmap *TQDragObject::cursor( DragMode m ) const +{ + if ( !d->pm_cursor ) + return 0; + + int index; + switch ( m ) { + case DragCopy: + index = 1; + break; + case DragLink: + index = 2; + break; + default: + index = 0; + break; + } + + return qt_dnd_manager->pm_cursor+index; +} + +#endif // 0 + +/*! + Starts a drag operation using the contents of this object, using + DragDefault mode. + + The function returns TRUE if the caller should delete the original + copy of the dragged data (but see target()); otherwise returns + FALSE. + + If the drag contains \e references to information (e.g. file names + in a TQUriDrag are references) then the return value should always + be ignored, as the target is expected to manipulate the + referred-to content directly. On X11 the return value should + always be correct anyway, but on Windows this is not necessarily + the case (e.g. the file manager starts a background process to + move files, so the source \e{must not} delete the files!) +*/ +bool TQDragObject::drag() +{ + return drag( DragDefault ); +} + + +/*! + Starts a drag operation using the contents of this object, using + \c DragMove mode. Be sure to read the constraints described in + drag(). + + \sa drag() dragCopy() dragLink() +*/ +bool TQDragObject::dragMove() +{ + return drag( DragMove ); +} + + +/*! + Starts a drag operation using the contents of this object, using + \c DragCopy mode. Be sure to read the constraints described in + drag(). + + \sa drag() dragMove() dragLink() +*/ +void TQDragObject::dragCopy() +{ + (void)drag( DragCopy ); +} + +/*! + Starts a drag operation using the contents of this object, using + \c DragLink mode. Be sure to read the constraints described in + drag(). + + \sa drag() dragCopy() dragMove() +*/ +void TQDragObject::dragLink() +{ + (void)drag( DragLink ); +} + + +/*! + \enum TQDragObject::DragMode + + This enum describes the possible drag modes. + + \value DragDefault The mode is determined heuristically. + \value DragCopy The data is copied, never moved. + \value DragMove The data is moved, if dragged at all. + \value DragLink The data is linked, if dragged at all. + \value DragCopyOrMove The user chooses the mode by using a + control key to switch from the default. +*/ + + +/*! + \overload + Starts a drag operation using the contents of this object. + + At this point, the object becomes owned by TQt, not the + application. You should not delete the drag object or anything it + references. The actual transfer of data to the target application + will be done during future event processing - after that time the + drag object will be deleted. + + Returns TRUE if the dragged data was dragged as a \e move, + indicating that the caller should remove the original source of + the data (the drag object must continue to have a copy); otherwise + returns FALSE. + + The \a mode specifies the drag mode (see + \l{TQDragObject::DragMode}.) Normally one of the simpler drag(), + dragMove(), or dragCopy() functions would be used instead. +*/ +bool TQDragObject::drag( DragMode mode ) +{ + if ( qt_dnd_manager ) + return qt_dnd_manager->drag( this, mode ); + else + return FALSE; +} + +#endif + + +/*! + Returns a pointer to the drag source where this object originated. +*/ + +TQWidget * TQDragObject::source() +{ + if ( parent() && parent()->isWidgetType() ) + return (TQWidget *)parent(); + else + return 0; +} + + +/*! + \class TQDragObject tqdragobject.h + + \brief The TQDragObject class encapsulates MIME-based data + transfer. + + \ingroup draganddrop + + TQDragObject is the base class for all data that needs to be + transferred between and within applications, both for drag and + drop and for the \link ntqclipboard.html clipboard\endlink. + + See the \link dnd.html Drag-and-drop documentation\endlink for an + overview of how to provide drag and drop in your application. + + See the TQClipboard documentation for an overview of how to provide + cut-and-paste in your application. + + The drag() function is used to start a drag operation. You can + specify the \l DragMode in the call or use one of the convenience + functions dragCopy(), dragMove() or dragLink(). The drag source + where the data originated is retrieved with source(). If the data + was dropped on a widget within the application, target() will + return a pointer to that widget. Specify the pixmap to display + during the drag with setPixmap(). +*/ + +static +void stripws(TQCString& s) +{ + int f; + while ( (f=s.find(' ')) >= 0 ) + s.remove(f,1); +} + +static +const char * staticCharset(int i) +{ + static TQCString localcharset; + + switch ( i ) { + case 0: + return "UTF-8"; + case 1: + return "ISO-10646-UCS-2"; + case 2: + return ""; // in the 3rd place - some Xdnd targets might only look at 3 + case 3: + if ( localcharset.isNull() ) { + TQTextCodec *localCodec = TQTextCodec::codecForLocale(); + if ( localCodec ) { + localcharset = localCodec->name(); + localcharset = localcharset.lower(); + stripws(localcharset); + } else { + localcharset = ""; + } + } + return localcharset; + } + return 0; +} + + +class TQTextDragPrivate { +public: + TQTextDragPrivate(); + + enum { nfmt=4 }; + + TQString txt; + TQCString fmt[nfmt]; + TQCString subtype; + + void setSubType(const TQCString & st) + { + subtype = st.lower(); + for ( int i=0; isetSubType(st); +} + +/*! + \class TQTextDrag tqdragobject.h + + \brief The TQTextDrag class is a drag and drop object for + transferring plain and Unicode text. + + \ingroup draganddrop + + Plain text is passed in a TQString which may contain multiple lines + (i.e. may contain newline characters). The drag target will receive + the newlines according to the runtime environment, e.g. LF on Unix, + and CRLF on Windows. + + TQt provides no built-in mechanism for delivering only a single-line. + + For more information about drag and drop, see the TQDragObject class + and the \link dnd.html drag and drop documentation\endlink. +*/ + + +/*! + Constructs a text drag object and sets its data to \a text. \a + dragSource must be the drag source; \a name is the object name. +*/ + +TQTextDrag::TQTextDrag( const TQString &text, + TQWidget * dragSource, const char * name ) + : TQDragObject( dragSource, name ) +{ + d = new TQTextDragPrivate; + setText( text ); +} + + +/*! + Constructs a default text drag object. \a dragSource must be the + drag source; \a name is the object name. +*/ + +TQTextDrag::TQTextDrag( TQWidget * dragSource, const char * name ) + : TQDragObject( dragSource, name ) +{ + d = new TQTextDragPrivate; +} + + +/*! + Destroys the text drag object and frees up all allocated + resources. +*/ +TQTextDrag::~TQTextDrag() +{ + delete d; +} + + +/*! + Sets the text to be dragged to \a text. You will need to call this + if you did not pass the text during construction. +*/ +void TQTextDrag::setText( const TQString &text ) +{ + d->txt = text; +} + + +/*! + \reimp +*/ +const char * TQTextDrag::format(int i) const +{ + if ( i >= d->nfmt ) + return 0; + return d->fmt[i]; +} + +TQTextCodec* qt_findcharset(const TQCString& mimetype) +{ + int i=mimetype.find("charset="); + if ( i >= 0 ) { + TQCString cs = mimetype.mid(i+8); + stripws(cs); + i = cs.find(';'); + if ( i >= 0 ) + cs = cs.left(i); + // win98 often has charset=utf16, and we need to get the correct codec for + // it to be able to get Unicode text drops. + if ( cs == "utf16" ) + cs = "ISO-10646-UCS-2"; + // May return 0 if unknown charset + return TQTextCodec::codecForName(cs); + } + // no charset=, use locale + return TQTextCodec::codecForLocale(); +} + +static TQTextCodec *codecForHTML(const TQCString &ba) +{ + // determine charset + int mib = 0; + int pos; + TQTextCodec *c = 0; + + if (ba.size() > 1 && (((uchar)ba[0] == 0xfe && (uchar)ba[1] == 0xff) + || ((uchar)ba[0] == 0xff && (uchar)ba[1] == 0xfe))) { + mib = 1000; // utf16 + } else if (ba.size() > 2 + && (uchar)ba[0] == 0xef + && (uchar)ba[1] == 0xbb + && (uchar)ba[2] == 0xbf) { + mib = 106; // utf-8 + } else { + pos = 0; + while ((pos = ba.find("format(i)); i++ ) { + bool html = !tqstrnicmp(f, "text/html", 9); + if (html) + r = codecForHTML(TQCString(e->encodedData(f))); + if (!r) + r = qt_findcharset(TQCString(f).lower()); + if (r) + return r; + } + return 0; +} + + + +/*! + \reimp +*/ +TQByteArray TQTextDrag::encodedData(const char* mime) const +{ + TQCString r; + if ( 0==tqstrnicmp(mime,"text/",5) ) { + TQCString m(mime); + m = m.lower(); + TQTextCodec *codec = qt_findcharset(m); + if ( !codec ) + return r; + TQString text( d->txt ); +#if defined(TQ_WS_WIN) + int index = text.find( TQString::fromLatin1("\r\n"), 0 ); + while ( index != -1 ) { + text.replace( index, 2, TQChar('\n') ); + index = text.find( "\r\n", index ); + } +#endif + r = codec->fromUnicode(text); + if (!codec || codec->mibEnum() != 1000) { + // Don't include NUL in size (TQCString::resize() adds NUL) +#if defined(TQ_WS_WIN) + // This is needed to ensure the \0 isn't lost on Windows 95 + if ( qWinVersion() & TQt::WV_DOS_based ) + ((TQByteArray&)r).resize(r.length()+1); + else +#endif + ((TQByteArray&)r).resize(r.length()); + } + } + return r; +} + +/*! + Returns TRUE if the information in \a e can be decoded into a + TQString; otherwise returns FALSE. + + \sa decode() +*/ +bool TQTextDrag::canDecode( const TQMimeSource* e ) +{ + const char* f; + for (int i=0; (f=e->format(i)); i++) { + if ( 0==tqstrnicmp(f,"text/",5) ) { + return findcodec(e) != 0; + } + } + return 0; +} + +/*! + \overload + + Attempts to decode the dropped information in \a e into \a str. + Returns TRUE if successful; otherwise returns FALSE. If \a subtype + is null, any text subtype is accepted; otherwise only the + specified \a subtype is accepted. + + \sa canDecode() +*/ +bool TQTextDrag::decode( const TQMimeSource* e, TQString& str, TQCString& subtype ) +{ + if(!e) + return FALSE; + + // when subtype is not specified, try text/plain first, otherwise this may read + // things like text/x-moz-url even though better targets are available + if( subtype.isNull()) { + TQCString subtmp = "plain"; + if( decode( e, str, subtmp )) { + subtype = subtmp; + return true; + } + } + + if ( e->cacheType == TQMimeSource::Text ) { + str = *e->cache.txt.str; + subtype = *e->cache.txt.subtype; + return TRUE; + } + + const char* mime; + for (int i=0; (mime = e->format(i)); i++) { + if ( 0==tqstrnicmp(mime,"text/",5) ) { + TQCString m(mime); + m = m.lower(); + int semi = m.find(';'); + if ( semi < 0 ) + semi = m.length(); + TQCString foundst = m.mid(5,semi-5); + if ( subtype.isNull() || foundst == subtype ) { + bool html = !tqstrnicmp(mime, "text/html", 9); + TQTextCodec* codec = 0; + if (html) { + TQByteArray bytes = e->encodedData(mime); + // search for the charset tag in the HTML + codec = codecForHTML(TQCString(bytes.data(), bytes.size())); + } + if (!codec) + codec = qt_findcharset(m); + if ( codec ) { + TQByteArray payload; + + payload = e->encodedData(mime); + if ( payload.size() ) { + int l; + if ( codec->mibEnum() != 1000) { + // length is at NUL or payload.size() + l = 0; + while ( l < (int)payload.size() && payload[l] ) + l++; + } else { + l = payload.size(); + } + + str = codec->toUnicode(payload,l); + + if ( subtype.isNull() ) + subtype = foundst; + + TQMimeSource *m = (TQMimeSource*)e; + m->clearCache(); + m->cacheType = TQMimeSource::Text; + m->cache.txt.str = new TQString( str ); + m->cache.txt.subtype = new TQCString( subtype ); + + return TRUE; + } + } + } + } + } + return FALSE; +} + +/*! + Attempts to decode the dropped information in \a e into \a str. + Returns TRUE if successful; otherwise returns FALSE. + + \sa canDecode() +*/ +bool TQTextDrag::decode( const TQMimeSource* e, TQString& str ) +{ + TQCString st; + return decode(e,str,st); +} + + +/* + TQImageDrag could use an internal MIME type for communicating TQPixmaps + and TQImages rather than always converting to raw data. This is available + for that purpose and others. It is not currently used. +*/ +class TQImageDragData +{ +public: +}; + + +/*! + \class TQImageDrag tqdragobject.h + + \brief The TQImageDrag class provides a drag and drop object for + transferring images. + + \ingroup draganddrop + + Images are offered to the receiving application in multiple + formats, determined by TQt's \link TQImage::outputFormats() output + formats\endlink. + + For more information about drag and drop, see the TQDragObject + class and the \link dnd.html drag and drop documentation\endlink. +*/ + +/*! + Constructs an image drag object and sets its data to \a image. \a + dragSource must be the drag source; \a name is the object name. +*/ + +TQImageDrag::TQImageDrag( TQImage image, + TQWidget * dragSource, const char * name ) + : TQDragObject( dragSource, name ), + d(0) +{ + setImage( image ); +} + +/*! + Constructs a default image drag object. \a dragSource must be the + drag source; \a name is the object name. +*/ + +TQImageDrag::TQImageDrag( TQWidget * dragSource, const char * name ) + : TQDragObject( dragSource, name ), + d(0) +{ +} + + +/*! + Destroys the image drag object and frees up all allocated + resources. +*/ + +TQImageDrag::~TQImageDrag() +{ + // nothing +} + + +/*! + Sets the image to be dragged to \a image. You will need to call + this if you did not pass the image during construction. +*/ +void TQImageDrag::setImage( TQImage image ) +{ + img = image; // ### detach? + ofmts = TQImage::outputFormats(); + ofmts.remove("PBM"); // remove non-raw PPM + if ( image.depth()!=32 ) { + // BMP better than PPM for paletted images + if ( ofmts.remove("BMP") ) // move to front + ofmts.insert(0,"BMP"); + } + // PNG is best of all + if ( ofmts.remove("PNG") ) // move to front + ofmts.insert(0,"PNG"); + + if(cacheType == TQMimeSource::NoCache) { //cache it + cacheType = TQMimeSource::Graphics; + cache.gfx.img = new TQImage( img ); + cache.gfx.pix = 0; + } +} + +/*! + \reimp +*/ +const char * TQImageDrag::format(int i) const +{ + if ( i < (int)ofmts.count() ) { + static TQCString str; + str.sprintf("image/%s",(((TQImageDrag*)this)->ofmts).at(i)); + str = str.lower(); + if ( str == "image/pbmraw" ) + str = "image/ppm"; + return str; + } else { + return 0; + } +} + +/*! + \reimp +*/ +TQByteArray TQImageDrag::encodedData(const char* fmt) const +{ + if ( tqstrnicmp( fmt, "image/", 6 )==0 ) { + TQCString f = fmt+6; + TQByteArray data; + TQBuffer w( data ); + w.open( IO_WriteOnly ); + TQImageIO io( &w, f.upper() ); + io.setImage( img ); + if ( !io.write() ) + return TQByteArray(); + w.close(); + return data; + } else { + return TQByteArray(); + } +} + +/*! + Returns TRUE if the information in mime source \a e can be decoded + into an image; otherwise returns FALSE. + + \sa decode() +*/ +bool TQImageDrag::canDecode( const TQMimeSource* e ) { + TQStrList fileFormats = TQImageIO::inputFormats(); + + fileFormats.first(); + while ( fileFormats.current()) { + TQCString format = fileFormats.current(); + TQCString type = "image/" + format.lower(); + if ( e->provides(type.data())) + return TRUE; + fileFormats.next(); + } + + return FALSE; +} + +/*! + Attempts to decode the dropped information in mime source \a e + into \a img. Returns TRUE if successful; otherwise returns FALSE. + + \sa canDecode() +*/ +bool TQImageDrag::decode( const TQMimeSource* e, TQImage& img ) +{ + if ( !e ) + return FALSE; + if ( e->cacheType == TQMimeSource::Graphics ) { + img = *e->cache.gfx.img; + return TRUE; + } + + TQByteArray payload; + TQStrList fileFormats = TQImageIO::inputFormats(); + // PNG is best of all + if ( fileFormats.remove("PNG") ) // move to front + fileFormats.insert(0,"PNG"); + fileFormats.first(); + while ( fileFormats.current() ) { + TQCString format = fileFormats.current(); + fileFormats.next(); + + TQCString type = "image/" + format.lower(); + if ( ! e->provides( type.data() ) ) continue; + payload = e->encodedData( type.data() ); + if ( !payload.isEmpty() ) + break; + } + + if ( payload.isEmpty() ) + return FALSE; + + img.loadFromData(payload); + if ( img.isNull() ) + return FALSE; + TQMimeSource *m = (TQMimeSource*)e; + m->clearCache(); + m->cacheType = TQMimeSource::Graphics; + m->cache.gfx.img = new TQImage( img ); + m->cache.gfx.pix = 0; + return TRUE; +} + +/*! + \overload + + Attempts to decode the dropped information in mime source \a e + into pixmap \a pm. Returns TRUE if successful; otherwise returns + FALSE. + + This is a convenience function that converts to a TQPixmap via a + TQImage. + + \sa canDecode() +*/ +bool TQImageDrag::decode( const TQMimeSource* e, TQPixmap& pm ) +{ + if ( !e ) + return FALSE; + + if ( e->cacheType == TQMimeSource::Graphics && e->cache.gfx.pix) { + pm = *e->cache.gfx.pix; + return TRUE; + } + + TQImage img; + // We avoid dither, since the image probably came from this display + if ( decode( e, img ) ) { + if ( !pm.convertFromImage( img, AvoidDither ) ) + return FALSE; + // decode initialized the cache for us + + TQMimeSource *m = (TQMimeSource*)e; + m->cache.gfx.pix = new TQPixmap( pm ); + return TRUE; + } + return FALSE; +} + + + + +/*! + \class TQStoredDrag tqdragobject.h + \brief The TQStoredDrag class provides a simple stored-value drag object for arbitrary MIME data. + + \ingroup draganddrop + + When a block of data has only one representation, you can use a + TQStoredDrag to hold it. + + For more information about drag and drop, see the TQDragObject + class and the \link dnd.html drag and drop documentation\endlink. +*/ + +/*! + Constructs a TQStoredDrag. The \a dragSource and \a name are passed + to the TQDragObject constructor, and the format is set to \a + mimeType. + + The data will be unset. Use setEncodedData() to set it. +*/ +TQStoredDrag::TQStoredDrag( const char* mimeType, TQWidget * dragSource, const char * name ) : + TQDragObject(dragSource,name) +{ + d = new TQStoredDragData(); + d->fmt = tqstrdup(mimeType); +} + +/*! + Destroys the drag object and frees up all allocated resources. +*/ +TQStoredDrag::~TQStoredDrag() +{ + delete [] (char*)d->fmt; + delete d; +} + +/*! + \reimp +*/ +const char * TQStoredDrag::format(int i) const +{ + if ( i==0 ) + return d->fmt; + else + return 0; +} + + +/*! + Sets the encoded data of this drag object to \a encodedData. The + encoded data is what's delivered to the drop sites. It must be in + a strictly defined and portable format. + + The drag object can't be dropped (by the user) until this function + has been called. +*/ + +void TQStoredDrag::setEncodedData( const TQByteArray & encodedData ) +{ + d->enc = encodedData.copy(); +} + +/*! + Returns the stored data. \a m contains the data's format. + + \sa setEncodedData() +*/ +TQByteArray TQStoredDrag::encodedData(const char* m) const +{ + if ( !tqstricmp(m,d->fmt) ) + return d->enc; + else + return TQByteArray(); +} + + +/*! + \class TQUriDrag tqdragobject.h + \brief The TQUriDrag class provides a drag object for a list of URI references. + + \ingroup draganddrop + + URIs are a useful way to refer to files that may be distributed + across multiple machines. A URI will often refer to a file on a + machine local to both the drag source and the drop target, so the + URI can be equivalent to passing a file name but is more + extensible. + + Use URIs in Unicode form so that the user can comfortably edit and + view them. For use in HTTP or other protocols, use the correctly + escaped ASCII form. + + You can convert a list of file names to file URIs using + setFileNames(), or into human-readble form with setUnicodeUris(). + + Static functions are provided to convert between filenames and + URIs, e.g. uriToLocalFile() and localFileToUri(), and to and from + human-readable form, e.g. uriToUnicodeUri(), unicodeUriToUri(). + You can also decode URIs from a mimesource into a list with + decodeLocalFiles() and decodeToUnicodeUris(). +*/ + +/*! + Constructs an object to drag the list of URIs in \a uris. The \a + dragSource and \a name arguments are passed on to TQStoredDrag. + Note that URIs are always in escaped UTF8 encoding. +*/ +TQUriDrag::TQUriDrag( TQStrList uris, + TQWidget * dragSource, const char * name ) : + TQStoredDrag( "text/uri-list", dragSource, name ) +{ + setUris(uris); +} + +/*! + Constructs an object to drag. You must call setUris() before you + start the drag(). Passes \a dragSource and \a name to the + TQStoredDrag constructor. +*/ +TQUriDrag::TQUriDrag( TQWidget * dragSource, const char * name ) : + TQStoredDrag( "text/uri-list", dragSource, name ) +{ +} + +/*! + Destroys the object. +*/ +TQUriDrag::~TQUriDrag() +{ +} + +/*! + Changes the list of \a uris to be dragged. + + Note that URIs are always in escaped UTF8 encoding. +*/ +void TQUriDrag::setUris( TQStrList uris ) +{ + TQByteArray a; + int c=0; + for ( const char* s = uris.first(); s; s = uris.next() ) { + int l = tqstrlen(s); + a.resize(c+l+2); + memcpy(a.data()+c,s,l); + memcpy(a.data()+c+l,"\r\n",2); + c+=l+2; + } + a.resize(c+1); + a[c] = 0; + setEncodedData(a); +} + + +/*! + Returns TRUE if decode() would be able to decode \a e; otherwise + returns FALSE. +*/ +bool TQUriDrag::canDecode( const TQMimeSource* e ) +{ + return e->provides( "text/uri-list" ); +} + +/*! + Decodes URIs from \a e, placing the result in \a l (which is first + cleared). + + Returns TRUE if \a e contained a valid list of URIs; otherwise + returns FALSE. +*/ +bool TQUriDrag::decode( const TQMimeSource* e, TQStrList& l ) +{ + TQByteArray payload = e->encodedData( "text/uri-list" ); + if ( payload.size() ) { + l.clear(); + l.setAutoDelete(TRUE); + uint c=0; + const char* d = payload.data(); + while (c < payload.size() && d[c]) { + uint f = c; + // Find line end + while (c < payload.size() && d[c] && d[c]!='\r' + && d[c] != '\n') + c++; + TQCString s(d+f,c-f+1); + if ( s[0] != '#' ) // non-comment? + l.append( s ); + // Skip junk + while (c < payload.size() && d[c] && + (d[c]=='\n' || d[c]=='\r')) + c++; + } + return TRUE; + } + return FALSE; +} + +static uint htod( int h ) +{ + if ( isdigit(h) ) + return h - '0'; + return tolower( h ) - 'a' + 10; +} + +/*! + \fn TQUriDrag::setFilenames( const TQStringList & ) + \obsolete + + Use setFileNames() instead (notice the N). +*/ + +/*! + Sets the URIs to be the local-file URIs equivalent to \a fnames. + + \sa localFileToUri(), setUris() +*/ +void TQUriDrag::setFileNames( const TQStringList & fnames ) +{ + TQStrList uris; + for ( TQStringList::ConstIterator i = fnames.begin(); + i != fnames.end(); ++i ) { + TQCString fileUri = localFileToUri(*i); + if (!fileUri.isEmpty()) + uris.append(fileUri); + } + setUris( uris ); +} + +/*! + Sets the URIs in \a uuris to be the Unicode URIs (only useful for + displaying to humans). + + \sa localFileToUri(), setUris() +*/ +void TQUriDrag::setUnicodeUris( const TQStringList & uuris ) +{ + TQStrList uris; + for ( TQStringList::ConstIterator i = uuris.begin(); + i != uuris.end(); ++i ) + uris.append( unicodeUriToUri(*i) ); + setUris( uris ); +} + +/*! + Returns the URI equivalent of the Unicode URI given in \a uuri + (only useful for displaying to humans). + + \sa uriToLocalFile() +*/ +TQCString TQUriDrag::unicodeUriToUri(const TQString& uuri) +{ + TQCString utf8 = uuri.utf8(); + TQCString escutf8; + int n = utf8.length(); + bool isFile = uuri.startsWith("file://"); + for (int i=0; i= 'a' && utf8[i] <= 'z') + || utf8[i] == '/' + || (utf8[i] >= '0' && utf8[i] <= '9') + || (utf8[i] >= 'A' && utf8[i] <= 'Z') + + || utf8[i] == '-' || utf8[i] == '_' + || utf8[i] == '.' || utf8[i] == '!' + || utf8[i] == '~' || utf8[i] == '*' + || utf8[i] == '(' || utf8[i] == ')' + || utf8[i] == '\'' + + // Allow this through, so that all URI-references work. + || (!isFile && utf8[i] == '#') + + || utf8[i] == ';' + || utf8[i] == '?' || utf8[i] == ':' + || utf8[i] == '@' || utf8[i] == '&' + || utf8[i] == '=' || utf8[i] == '+' + || utf8[i] == '$' || utf8[i] == ',' ) + { + escutf8 += utf8[i]; + } else { + // Everything else is escaped as %HH + TQCString s(4); + s.sprintf("%%%02x",(uchar)utf8[i]); + escutf8 += s; + } + } + return escutf8; +} + +/*! + Returns the URI equivalent to the absolute local file \a filename. + + \sa uriToLocalFile() +*/ +TQCString TQUriDrag::localFileToUri(const TQString& filename) +{ + TQString r = filename; + + //check that it is an absolute file + if (TQDir::isRelativePath(r)) + return TQCString(); + +#ifdef TQ_WS_WIN + + + bool hasHost = FALSE; + // convert form network path + if (r.left(2) == "\\\\" || r.left(2) == "//") { + r.remove(0, 2); + hasHost = TRUE; + } + + // Slosh -> Slash + int slosh; + while ( (slosh=r.find('\\')) >= 0 ) { + r[slosh] = '/'; + } + + // Drive + if ( r[0] != '/' && !hasHost) + r.insert(0,'/'); + +#endif +#if defined ( TQ_WS_X11 ) && 0 + // URL without the hostname is considered to be errorneous by XDnD. + // See: http://www.newplanetsoftware.com/xdnd/dragging_files.html + // This feature is not active because this would break dnd between old and new qt apps. + char hostname[257]; + if ( gethostname( hostname, 255 ) == 0 ) { + hostname[256] = '\0'; + r.prepend( TQString::fromLatin1( hostname ) ); + } +#endif + return unicodeUriToUri(TQString("file://" + r)); +} + +/*! + Returns the Unicode URI (only useful for displaying to humans) + equivalent of \a uri. + + Note that URIs are always in escaped UTF8 encoding. + + \sa localFileToUri() +*/ +TQString TQUriDrag::uriToUnicodeUri(const char* uri) +{ + TQCString utf8; + + while (*uri) { + switch (*uri) { + case '%': { + uint ch = (uchar) uri[1]; + if ( ch && uri[2] ) { + ch = htod( ch ) * 16 + htod( (uchar) uri[2] ); + utf8 += (char) ch; + uri += 2; + } + } + break; + default: + utf8 += *uri; + } + ++uri; + } + + return TQString::fromUtf8(utf8); +} + +/*! + Returns the name of a local file equivalent to \a uri or a null + string if \a uri is not a local file. + + Note that URIs are always in escaped UTF8 encoding. + + \sa localFileToUri() +*/ +TQString TQUriDrag::uriToLocalFile(const char* uri) +{ + TQString file; + + if (!uri) + return file; + if (0==tqstrnicmp(uri,"file:/",6)) // It is a local file uri + uri += 6; + else if (TQString(uri).find(":/") != -1) // It is a different scheme uri + return file; + + bool local = uri[0] != '/' || ( uri[0] != '\0' && uri[1] == '/' ); +#ifdef TQ_WS_X11 + // do we have a hostname? + if ( !local && uri[0] == '/' && uri[2] != '/' ) { + // then move the pointer to after the 'hostname/' part of the uri + const char* hostname_end = strchr( uri+1, '/' ); + if ( hostname_end != NULL ) { + char hostname[ 257 ]; + if ( gethostname( hostname, 255 ) == 0 ) { + hostname[ 256 ] = '\0'; + if ( tqstrncmp( uri+1, hostname, hostname_end - ( uri+1 )) == 0 ) { + uri = hostname_end + 1; // point after the slash + local = TRUE; + } + } + } + } +#endif + if ( local ) { + file = uriToUnicodeUri(uri); + if ( uri[1] == '/' ) { + file.remove((uint)0,1); + } else { + file.insert(0,'/'); + } +#ifdef TQ_WS_WIN + if ( file.length() > 2 && file[0] == '/' && file[2] == '|' ) { + file[2] = ':'; + file.remove(0,1); + } else if (file.length() > 2 && file[0] == '/' && file[1].isLetter() && file[2] == ':') { + file.remove(0, 1); + } + // Leave slash as slashes. +#endif + } +#ifdef TQ_WS_WIN + else { + file = uriToUnicodeUri(uri); + // convert to network path + file.insert(1, '/'); // leave as forward slashes + } +#endif + + return file; +} + +/*! + Decodes URIs from the mime source event \a e, converts them to + local files if they refer to local files, and places them in \a l + (which is first cleared). + + Returns TRUE if \e contained a valid list of URIs; otherwise + returns FALSE. The list will be empty if no URIs were local files. +*/ +bool TQUriDrag::decodeLocalFiles( const TQMimeSource* e, TQStringList& l ) +{ + TQStrList u; + if ( !decode( e, u ) ) + return FALSE; + + l.clear(); + for (const char* s=u.first(); s; s=u.next()) { + TQString lf = uriToLocalFile(s); + if ( !lf.isNull() ) + l.append( lf ); + } + return TRUE; +} + +/*! + Decodes URIs from the mime source event \a e, converts them to + Unicode URIs (only useful for displaying to humans), placing them + in \a l (which is first cleared). + + Returns TRUE if \e contained a valid list of URIs; otherwise + returns FALSE. +*/ +bool TQUriDrag::decodeToUnicodeUris( const TQMimeSource* e, TQStringList& l ) +{ + TQStrList u; + if ( !decode( e, u ) ) + return FALSE; + + l.clear(); + for (const char* s=u.first(); s; s=u.next()) + l.append( uriToUnicodeUri(s) ); + + return TRUE; +} + + +#ifndef TQT_NO_DRAGANDDROP +/*! + If the source of the drag operation is a widget in this + application, this function returns that source, otherwise it + returns 0. The source of the operation is the first parameter to + drag object subclasses. + + This is useful if your widget needs special behavior when dragging + to itself, etc. + + See TQDragObject::TQDragObject() and subclasses. +*/ +TQWidget* TQDropEvent::source() const +{ + return qt_dnd_manager ? qt_dnd_manager->dragSource : 0; +} +#endif + +/*! + \class TQColorDrag tqdragobject.h + + \brief The TQColorDrag class provides a drag and drop object for + transferring colors. + + \ingroup draganddrop + + This class provides a drag object which can be used to transfer data + about colors for drag and drop and in the clipboard. For example, it + is used in TQColorDialog. + + The color is set in the constructor but can be changed with + setColor(). + + For more information about drag and drop, see the TQDragObject class + and the \link dnd.html drag and drop documentation\endlink. +*/ + +/*! + Constructs a color drag object with the color \a col. Passes \a + dragsource and \a name to the TQStoredDrag constructor. +*/ + +TQColorDrag::TQColorDrag( const TQColor &col, TQWidget *dragsource, const char *name ) + : TQStoredDrag( "application/x-color", dragsource, name ) +{ + setColor( col ); +} + +/*! + Constructs a color drag object with a white color. Passes \a + dragsource and \a name to the TQStoredDrag constructor. +*/ + +TQColorDrag::TQColorDrag( TQWidget *dragsource, const char *name ) + : TQStoredDrag( "application/x-color", dragsource, name ) +{ + setColor( TQt::white ); +} + +/*! + Sets the color of the color drag to \a col. +*/ + +void TQColorDrag::setColor( const TQColor &col ) +{ + unsigned short r = (col.red() << 8) | col.red(); + unsigned short g = (col.green() << 8) | col.green(); + unsigned short b = (col.blue() << 8) | col.blue(); + + // make sure we transmit data in network order + r = htons(r); + g = htons(g); + b = htons(b); + + ushort rgba[4] = { + r, g, b, + 0xffff // Alpha not supported yet. + }; + TQByteArray data(sizeof(rgba)); + memcpy(data.data(), rgba, sizeof(rgba)); + setEncodedData(data); +} + +/*! + Returns TRUE if the color drag object can decode the mime source + \a e; otherwise returns FALSE. +*/ + +bool TQColorDrag::canDecode( TQMimeSource *e ) +{ + return e->provides( "application/x-color" ); +} + +/*! + Decodes the mime source \a e and sets the decoded values to \a + col. +*/ + +bool TQColorDrag::decode( TQMimeSource *e, TQColor &col ) +{ + TQByteArray data = e->encodedData("application/x-color"); + ushort rgba[4]; + if (data.size() != sizeof(rgba)) + return FALSE; + + memcpy(rgba, data.data(), sizeof(rgba)); + + short r = rgba[0]; + short g = rgba[1]; + short b = rgba[2]; + + // data is in network order + r = ntohs(r); + g = ntohs(g); + b = ntohs(b); + + r = (r >> 8) & 0xff; + g = (g >> 8) & 0xff; + b = (b >> 8) & 0xff; + + col.setRgb(r, g, b); + return TRUE; +} + +#endif // TQT_NO_MIME diff --git a/src/kernel/tqdragobject.h b/src/kernel/tqdragobject.h new file mode 100644 index 000000000..af4a8a995 --- /dev/null +++ b/src/kernel/tqdragobject.h @@ -0,0 +1,279 @@ +/**************************************************************************** +** +** Definition of TQDragObject +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQDRAGOBJECT_H +#define TQDRAGOBJECT_H + +class TQWidget; +class TQTextDragPrivate; +class TQDragObjectData; +class TQStoredDragData; +class TQImageDragData; + +#ifndef QT_H +#include "tqobject.h" +#include "tqimage.h" +#include "tqstrlist.h" +#include "ntqcolor.h" +#endif // QT_H + +#ifndef TQT_NO_MIME + +class TQ_EXPORT TQDragObject: public TQObject, public TQMimeSource { + TQ_OBJECT +public: + TQDragObject( TQWidget * dragSource = 0, const char * name = 0 ); + virtual ~TQDragObject(); + +#ifndef TQT_NO_DRAGANDDROP + bool drag(); + bool dragMove(); + void dragCopy(); + void dragLink(); + + virtual void setPixmap(TQPixmap); + virtual void setPixmap(TQPixmap, const TQPoint& hotspot); + TQPixmap pixmap() const; + TQPoint pixmapHotSpot() const; +#endif + + TQWidget * source(); + static TQWidget * target(); + + static void setTarget(TQWidget*); + +#ifndef TQT_NO_DRAGANDDROP + enum DragMode { DragDefault, DragCopy, DragMove, DragLink, DragCopyOrMove }; + +protected: + virtual bool drag(DragMode); +#endif + +private: + TQDragObjectData * d; +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQDragObject( const TQDragObject & ); + TQDragObject &operator=( const TQDragObject & ); +#endif +}; + +class TQ_EXPORT TQStoredDrag: public TQDragObject { + TQ_OBJECT + TQStoredDragData * d; + +public: + TQStoredDrag( const char * mimeType, + TQWidget * dragSource = 0, const char * name = 0 ); + ~TQStoredDrag(); + + virtual void setEncodedData( const TQByteArray & ); + + const char * format(int i) const; + virtual TQByteArray encodedData(const char*) const; + +private: +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQStoredDrag( const TQStoredDrag & ); + TQStoredDrag &operator=( const TQStoredDrag & ); +#endif +}; + +class TQ_EXPORT TQTextDrag: public TQDragObject { + TQ_OBJECT + TQTextDragPrivate* d; +public: + TQTextDrag( const TQString &, + TQWidget * dragSource = 0, const char * name = 0 ); + TQTextDrag( TQWidget * dragSource = 0, const char * name = 0 ); + ~TQTextDrag(); + + virtual void setText( const TQString &); + virtual void setSubtype( const TQCString &); + + const char * format(int i) const; + virtual TQByteArray encodedData(const char*) const; + + static bool canDecode( const TQMimeSource* e ); + static bool decode( const TQMimeSource* e, TQString& s ); + static bool decode( const TQMimeSource* e, TQString& s, TQCString& subtype ); + +private: +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQTextDrag( const TQTextDrag & ); + TQTextDrag &operator=( const TQTextDrag & ); +#endif +}; + +class TQ_EXPORT TQImageDrag: public TQDragObject { + TQ_OBJECT + TQImage img; + TQStrList ofmts; + TQImageDragData* d; + +public: + TQImageDrag( TQImage image, TQWidget * dragSource = 0, const char * name = 0 ); + TQImageDrag( TQWidget * dragSource = 0, const char * name = 0 ); + ~TQImageDrag(); + + virtual void setImage( TQImage image ); + + const char * format(int i) const; + virtual TQByteArray encodedData(const char*) const; + + static bool canDecode( const TQMimeSource* e ); + static bool decode( const TQMimeSource* e, TQImage& i ); + static bool decode( const TQMimeSource* e, TQPixmap& i ); + +private: +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQImageDrag( const TQImageDrag & ); + TQImageDrag &operator=( const TQImageDrag & ); +#endif +}; + + +class TQ_EXPORT TQUriDrag: public TQStoredDrag { + TQ_OBJECT + +public: + TQUriDrag( TQStrList uris, TQWidget * dragSource = 0, const char * name = 0 ); + TQUriDrag( TQWidget * dragSource = 0, const char * name = 0 ); + ~TQUriDrag(); + + void setFilenames( const TQStringList & fnames ) { setFileNames( fnames ); } + void setFileNames( const TQStringList & fnames ); + void setUnicodeUris( const TQStringList & uuris ); + virtual void setUris( TQStrList uris ); + + static TQString uriToLocalFile(const char*); + static TQCString localFileToUri(const TQString&); + static TQString uriToUnicodeUri(const char*); + static TQCString unicodeUriToUri(const TQString&); + static bool canDecode( const TQMimeSource* e ); + static bool decode( const TQMimeSource* e, TQStrList& i ); + static bool decodeToUnicodeUris( const TQMimeSource* e, TQStringList& i ); + static bool decodeLocalFiles( const TQMimeSource* e, TQStringList& i ); + +private: +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQUriDrag( const TQUriDrag & ); + TQUriDrag &operator=( const TQUriDrag & ); +#endif +}; + +class TQ_EXPORT TQColorDrag : public TQStoredDrag +{ + TQ_OBJECT + TQColor color; + +public: + TQColorDrag( const TQColor &col, TQWidget *dragsource = 0, const char *name = 0 ); + TQColorDrag( TQWidget * dragSource = 0, const char * name = 0 ); + void setColor( const TQColor &col ); + + static bool canDecode( TQMimeSource * ); + static bool decode( TQMimeSource *, TQColor &col ); + +private: +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQColorDrag( const TQColorDrag & ); + TQColorDrag &operator=( const TQColorDrag & ); +#endif +}; + +#ifndef TQT_NO_COMPAT +typedef TQUriDrag TQUrlDrag; +#endif + +#ifndef TQT_NO_DRAGANDDROP + +// TQDragManager is not part of the public API. It is defined in a +// header file simply so different .cpp files can implement different +// member functions. +// + +class TQ_EXPORT TQDragManager: public TQObject { + TQ_OBJECT + +private: + TQDragManager(); + ~TQDragManager(); + // only friend classes can use TQDragManager. + friend class TQDragObject; + friend class TQDragMoveEvent; + friend class TQDropEvent; + friend class TQApplication; + + bool eventFilter( TQObject *, TQEvent * ); + void timerEvent( TQTimerEvent* ); + + bool drag( TQDragObject *, TQDragObject::DragMode ); + + void cancel( bool deleteSource = TRUE ); + void move( const TQPoint & ); + void drop(); + void updatePixmap(); + void updatePixmap( const TQPoint& cursorPos ); + +private: + TQDragObject * object; + bool updateMode( ButtonState newstate ); + void updateCursor(); +#if defined(TQ_WS_X11) + void createCursors(); +#endif + + TQWidget * dragSource; + TQWidget * dropWidget; + bool beingCancelled; + bool restoreCursor; + bool willDrop; + + TQPixmap *pm_cursor; + int n_cursor; +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQDragManager( const TQDragManager & ); + TQDragManager &operator=( const TQDragManager & ); +#endif +}; + +#endif + +#endif // TQT_NO_MIME + +#endif // TQDRAGOBJECT_H diff --git a/src/kernel/tqdropsite.cpp b/src/kernel/tqdropsite.cpp new file mode 100644 index 000000000..b544cdab3 --- /dev/null +++ b/src/kernel/tqdropsite.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Implementation of Drag and Drop support +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqdropsite.h" + +#ifndef TQT_NO_DRAGANDDROP + +#include "tqwidget.h" + + +// NOT REVISED +/*! + \class TQDropSite tqdropsite.h + \brief The TQDropSite class provides nothing and does nothing. + + \obsolete + + If your code uses it, you can safely delete it. + + It was used in TQt 1.x to do some drag and drop; that has since been + folded into TQWidget. + + For detailed information about drag-and-drop, see the TQDragObject class. + + \sa TQDragObject, TQTextDrag, TQImageDrag +*/ + +/*! + Constructs a TQDropSite to handle events for the widget \a self. + + Pass \c this as the \a self parameter. + This enables dropping by calling TQWidget::setAcceptDrops(TRUE). +*/ +TQDropSite::TQDropSite( TQWidget* self ) +{ + self->setAcceptDrops( TRUE ); +} + +/*! + Destroys the drop site. +*/ +TQDropSite::~TQDropSite() +{ +} + +#endif // TQT_NO_DRAGANDDROP diff --git a/src/kernel/tqdropsite.h b/src/kernel/tqdropsite.h new file mode 100644 index 000000000..3e95cdc3f --- /dev/null +++ b/src/kernel/tqdropsite.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Definitation of Drag and Drop support +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQDROPSITE_H +#define TQDROPSITE_H + +#ifndef QT_H +#ifndef QT_H +#include "ntqglobal.h" +#endif // QT_H +#endif + + +class TQWidget; + + +class TQ_EXPORT TQDropSite { +public: + TQDropSite( TQWidget* parent ); + virtual ~TQDropSite(); +}; + + +#endif // TQDROPSITE_H diff --git a/src/kernel/tqimage.cpp b/src/kernel/tqimage.cpp index 46002b8f8..d7bc30d49 100644 --- a/src/kernel/tqimage.cpp +++ b/src/kernel/tqimage.cpp @@ -54,8 +54,8 @@ #include "tqimageformatinterface_p.h" #include "ntqwmatrix.h" #include "ntqapplication.h" -#include "ntqmime.h" -#include "ntqdragobject.h" +#include "tqmime.h" +#include "tqdragobject.h" #include #include diff --git a/src/kernel/tqmime.cpp b/src/kernel/tqmime.cpp new file mode 100644 index 000000000..984d88be4 --- /dev/null +++ b/src/kernel/tqmime.cpp @@ -0,0 +1,619 @@ +/**************************************************************************** +** +** Implementation of MIME support +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqmime.h" + +#ifndef TQT_NO_MIME + +#include "tqmap.h" +#include "tqstringlist.h" +#include "ntqfileinfo.h" +#include "ntqdir.h" +#include "tqdragobject.h" +#include "ntqcleanuphandler.h" +#include "ntqapplication.h" // ### for now +#include "ntqclipboard.h" // ### for now + +/*! + \class TQMimeSource tqmime.h + \brief The TQMimeSource class is an abstraction of objects which provide formatted data of a certain MIME type. + + \ingroup io + \ingroup draganddrop + \ingroup misc + + \link dnd.html Drag-and-drop\endlink and + \link TQClipboard clipboard\endlink use this abstraction. + + \sa \link http://www.isi.edu/in-notes/iana/assignments/media-types/ + IANA list of MIME media types\endlink +*/ + +static int qt_mime_serial_number = 0; +static TQMimeSourceFactory* defaultfactory = 0; +static TQSingleCleanupHandler tqmime_cleanup_factory; + +/*! + Constructs a mime source and assigns a globally unique serial + number to it. + + \sa serialNumber() +*/ + +TQMimeSource::TQMimeSource() +{ + ser_no = qt_mime_serial_number++; + cacheType = NoCache; +} + +/*! + \fn int TQMimeSource::serialNumber() const + + Returns the mime source's globally unique serial number. +*/ + + +void TQMimeSource::clearCache() +{ + if ( cacheType == Text ) { + delete cache.txt.str; + delete cache.txt.subtype; + cache.txt.str = 0; + cache.txt.subtype = 0; + } else if ( cacheType == Graphics ) { + delete cache.gfx.img; + delete cache.gfx.pix; + cache.gfx.img = 0; + cache.gfx.pix = 0; + } + cacheType = NoCache; +} + +/*! + Provided to ensure that subclasses destroy themselves correctly. +*/ +TQMimeSource::~TQMimeSource() +{ +#ifndef TQT_NO_CLIPBOARD + extern void tqt_clipboard_cleanup_mime_source(TQMimeSource *); + tqt_clipboard_cleanup_mime_source(this); +#endif + clearCache(); +} + +/*! + \fn TQByteArray TQMimeSource::encodedData(const char*) const + + Returns the encoded data of this object in the specified MIME + format. + + Subclasses must reimplement this function. +*/ + + + +/*! + Returns TRUE if the object can provide the data in format \a + mimeType; otherwise returns FALSE. + + If you inherit from TQMimeSource, for consistency reasons it is + better to implement the more abstract canDecode() functions such + as TQTextDrag::canDecode() and TQImageDrag::canDecode(). +*/ +bool TQMimeSource::provides(const char* mimeType) const +{ + const char* fmt; + for (int i=0; (fmt = format(i)); i++) { + if ( !tqstricmp(mimeType,fmt) ) { + return TRUE; + } + } + return FALSE; +} + + +/*! + \fn const char * TQMimeSource::format(int i) const + + Returns the \a{i}-th supported MIME format, or 0. +*/ + + + +class TQMimeSourceFactoryData { +public: + TQMimeSourceFactoryData() : + last(0) + { + } + + ~TQMimeSourceFactoryData() + { + TQMap::Iterator it = stored.begin(); + while ( it != stored.end() ) { + delete *it; + ++it; + } + delete last; + } + + TQMap stored; + TQMap extensions; + TQStringList path; + TQMimeSource* last; + TQPtrList factories; +}; + + +/*! + \class TQMimeSourceFactory tqmime.h + \brief The TQMimeSourceFactory class is an extensible provider of mime-typed data. + + \ingroup io + \ingroup environment + + A TQMimeSourceFactory provides an abstract interface to a + collection of information. Each piece of information is + represented by a TQMimeSource object which can be examined and + converted to concrete data types by functions such as + TQImageDrag::canDecode() and TQImageDrag::decode(). + + The base TQMimeSourceFactory can be used in two ways: as an + abstraction of a collection of files or as specifically stored + data. For it to access files, call setFilePath() before accessing + data. For stored data, call setData() for each item (there are + also convenience functions, e.g. setText(), setImage() and + setPixmap(), that simply call setData() with appropriate + parameters). + + The rich text widgets, TQTextEdit and TQTextBrowser, use + TQMimeSourceFactory to resolve references such as images or links + within rich text documents. They either access the default factory + (see \l{defaultFactory()}) or their own (see + \l{TQTextEdit::setMimeSourceFactory()}). Other classes that are + capable of displaying rich text (such as TQLabel, TQWhatsThis or + TQMessageBox) always use the default factory. + + A factory can also be used as a container to store data associated + with a name. This technique is useful whenever rich text contains + images that are stored in the program itself, not loaded from the + hard disk. Your program may, for example, define some image data + as: + \code + static const char* myimage_data[]={ + "...", + ... + "..."}; + \endcode + + To be able to use this image within some rich text, for example + inside a TQLabel, you must create a TQImage from the raw data and + insert it into the factory with a unique name: + \code + TQMimeSourceFactory::defaultFactory()->setImage( "myimage", TQImage(myimage_data) ); + \endcode + + Now you can create a rich text TQLabel with + + \code + TQLabel* label = new TQLabel( + "Rich text with embedded image:" + "Isn't that cute?" ); + \endcode + + When no longer needed, you can clear the data from the factory: + + \code + delete label; + TQMimeSourceFactory::defaultFactory()->setData( "myimage", 0 ); + \endcode +*/ + + +/*! + Constructs a TQMimeSourceFactory that has no file path and no + stored content. +*/ +TQMimeSourceFactory::TQMimeSourceFactory() : + d(new TQMimeSourceFactoryData) +{ + // add some reasonable defaults + setExtensionType("htm", "text/html;charset=iso8859-1"); + setExtensionType("html", "text/html;charset=iso8859-1"); + setExtensionType("txt", "text/plain"); + setExtensionType("xml", "text/xml;charset=UTF-8"); + setExtensionType("jpg", "image/jpeg"); // support misspelled jpeg files +} + +/*! + Destroys the TQMimeSourceFactory, deleting all stored content. +*/ +TQMimeSourceFactory::~TQMimeSourceFactory() +{ + if ( defaultFactory() == this ) + defaultfactory = 0; + delete d; +} + +TQMimeSource* TQMimeSourceFactory::dataInternal(const TQString& abs_name, const TQMap &extensions ) const +{ + TQMimeSource* r = 0; + TQFileInfo fi(abs_name); + if ( fi.isReadable() ) { + + // get the right mimetype + TQString e = fi.extension(FALSE); + TQCString mimetype = "application/octet-stream"; + const char* imgfmt; + if ( extensions.contains(e) ) + mimetype = extensions[e].latin1(); + else if ( ( imgfmt = TQImage::imageFormat( abs_name ) ) ) + mimetype = TQCString("image/")+TQCString(imgfmt).lower(); + + TQFile f(abs_name); + if ( f.open(IO_ReadOnly) && f.size() ) { + TQByteArray ba(f.size()); + f.readBlock(ba.data(), ba.size()); + TQStoredDrag* sr = new TQStoredDrag( mimetype ); + sr->setEncodedData( ba ); + delete d->last; + d->last = r = sr; + } + } + + // we didn't find the mime-source, so ask the default factory for + // the mime-source (this one will iterate over all installed ones) + // + // this looks dangerous, as this dataInternal() function will be + // called again when the default factory loops over all installed + // factories (including this), but the static bool looping in + // data() avoids endless recursions + if ( !r && this != defaultFactory() ) + r = (TQMimeSource*)defaultFactory()->data( abs_name ); + + return r; +} + + +/*! + Returns a reference to the data associated with \a abs_name. The + return value remains valid only until the next data() or setData() + call, so you should immediately decode the result. + + If there is no data associated with \a abs_name in the factory's + store, the factory tries to access the local filesystem. If \a + abs_name isn't an absolute file name, the factory will search for + it in all defined paths (see \l{setFilePath()}). + + The factory understands all the image formats supported by + TQImageIO. Any other mime types are determined by the file name + extension. The default settings are + \code + setExtensionType("html", "text/html;charset=iso8859-1"); + setExtensionType("htm", "text/html;charset=iso8859-1"); + setExtensionType("txt", "text/plain"); + setExtensionType("xml", "text/xml;charset=UTF-8"); + \endcode + The effect of these is that file names ending in "txt" will be + treated as text encoded in the local encoding; those ending in + "xml" will be treated as text encoded in Unicode UTF-8 encoding. + The text/html type is treated specially, since the encoding can be + specified in the html file itself. "html" or "htm" will be treated + as text encoded in the encoding specified by the html meta tag, if + none could be found, the charset of the mime type will be used. + The text subtype ("html", "plain", or "xml") does not affect the + factory, but users of the factory may behave differently. We + recommend creating "xml" files where practical. These files can be + viewed regardless of the runtime encoding and can encode any + Unicode characters without resorting to encoding definitions + inside the file. + + Any file data that is not recognized will be retrieved as a + TQMimeSource providing the "application/octet-stream" mime type, + meaning uninterpreted binary data. + + You can add further extensions or change existing ones with + subsequent calls to setExtensionType(). If the extension mechanism + is not sufficient for your problem domain, you can inherit + TQMimeSourceFactory and reimplement this function to perform some + more specialized mime-type detection. The same applies if you want + to use the mime source factory to access URL referenced data over + a network. +*/ +const TQMimeSource* TQMimeSourceFactory::data(const TQString& abs_name) const +{ + if ( d->stored.contains(abs_name) ) + return d->stored[abs_name]; + + TQMimeSource* r = 0; + TQStringList::Iterator it; + if ( abs_name[0] == '/' +#ifdef TQ_WS_WIN + || ( abs_name[0] && abs_name[1] == ':' ) || abs_name.startsWith("\\\\") +#endif + ) + { + // handle absolute file names directly + r = dataInternal( abs_name, d->extensions); + } + else { // check list of paths + for ( it = d->path.begin(); !r && it != d->path.end(); ++it ) { + TQString filename = *it; + if ( filename[(int)filename.length()-1] != '/' ) + filename += '/'; + filename += abs_name; + r = dataInternal( filename, d->extensions ); + } + } + + static bool looping = FALSE; + if ( !r && this == defaultFactory() ) { + // we found no mime-source and we are the default factory, so + // we know all the other installed mime-source factories, so + // ask them + if ( !looping ) { + // to avoid endless recustions, don't enter the loop below + // if data() got called from within the loop below + looping = TRUE; + TQPtrListIterator it( d->factories ); + TQMimeSourceFactory *f; + while ( ( f = it.current() ) ) { + ++it; + if ( f == this ) + continue; + r = (TQMimeSource*)f->data( abs_name ); + if ( r ) { + looping = FALSE; + return r; + } + } + looping = FALSE; + } + } else if ( !r ) { + // we are not the default mime-source factory, so ask the + // default one for the mime-source, as this one will loop over + // all installed mime-source factories and ask these + r = (TQMimeSource*)defaultFactory()->data( abs_name ); + } + + return r; +} + +/*! + Sets the list of directories that will be searched when named data + is requested to the those given in the string list \a path. + + \sa filePath() +*/ +void TQMimeSourceFactory::setFilePath( const TQStringList& path ) +{ + d->path = path; +} + +/*! + Returns the currently set search paths. +*/ +TQStringList TQMimeSourceFactory::filePath() const +{ + return d->path; +} + +/*! + Adds another search path, \a p to the existing search paths. + + \sa setFilePath() +*/ +void TQMimeSourceFactory::addFilePath( const TQString& p ) +{ + d->path += p; +} + +/*! + Sets the mime-type to be associated with the file name extension, + \a ext to \a mimetype. This determines the mime-type for files + found via the paths set by setFilePath(). +*/ +void TQMimeSourceFactory::setExtensionType( const TQString& ext, const char* mimetype ) +{ + d->extensions.replace(ext, mimetype); +} + +/*! + Converts the absolute or relative data item name \a + abs_or_rel_name to an absolute name, interpreted within the + context (path) of the data item named \a context (this must be an + absolute name). +*/ +TQString TQMimeSourceFactory::makeAbsolute(const TQString& abs_or_rel_name, const TQString& context) const +{ + if ( context.isNull() || + !(context[0] == '/' +#ifdef TQ_WS_WIN + || ( context[0] && context[1] == ':') +#endif + )) + return abs_or_rel_name; + if ( abs_or_rel_name.isEmpty() ) + return context; + TQFileInfo c( context ); + if (!c.isDir()) { + TQFileInfo r( c.dir(TRUE), abs_or_rel_name ); + return r.absFilePath(); + } else { + TQDir d(context); + TQFileInfo r(d, abs_or_rel_name); + return r.absFilePath(); + } +} + +/*! + \overload + A convenience function. See data(const TQString& abs_name). The + file name is given in \a abs_or_rel_name and the path is in \a + context. +*/ +const TQMimeSource* TQMimeSourceFactory::data(const TQString& abs_or_rel_name, const TQString& context) const +{ + const TQMimeSource* r = data(makeAbsolute(abs_or_rel_name,context)); + if ( !r && !d->path.isEmpty() ) + r = data(abs_or_rel_name); + return r; +} + + +/*! + Sets \a text to be the data item associated with the absolute name + \a abs_name. + + Equivalent to setData(abs_name, new TQTextDrag(text)). +*/ +void TQMimeSourceFactory::setText( const TQString& abs_name, const TQString& text ) +{ + setData(abs_name, new TQTextDrag(text)); +} + +/*! + Sets \a image to be the data item associated with the absolute + name \a abs_name. + + Equivalent to setData(abs_name, new TQImageDrag(image)). +*/ +void TQMimeSourceFactory::setImage( const TQString& abs_name, const TQImage& image ) +{ + setData(abs_name, new TQImageDrag(image)); +} + +/*! + Sets \a pixmap to be the data item associated with the absolute + name \a abs_name. +*/ +void TQMimeSourceFactory::setPixmap( const TQString& abs_name, const TQPixmap& pixmap ) +{ + setData(abs_name, new TQImageDrag(pixmap.convertToImage())); +} + +/*! + Sets \a data to be the data item associated with + the absolute name \a abs_name. Note that the ownership of \a data is + transferred to the factory: do not delete or access the pointer after + passing it to this function. + + Passing 0 for data removes previously stored data. +*/ +void TQMimeSourceFactory::setData( const TQString& abs_name, TQMimeSource* data ) +{ + if ( d->stored.contains(abs_name) ) + delete d->stored[abs_name]; + d->stored.replace(abs_name,data); +} + + +/*! + Returns the application-wide default mime source factory. This + factory is used by rich text rendering classes such as + TQSimpleRichText, TQWhatsThis and TQMessageBox to resolve named + references within rich text documents. It serves also as the + initial factory for the more complex render widgets, TQTextEdit and + TQTextBrowser. + + \sa setDefaultFactory() +*/ +TQMimeSourceFactory* TQMimeSourceFactory::defaultFactory() +{ + if (!defaultfactory) + { + defaultfactory = new TQMimeSourceFactory(); + tqmime_cleanup_factory.set( &defaultfactory ); + } + return defaultfactory; +} + +/*! + Sets the default \a factory, destroying any previously set mime + source provider. The ownership of the factory is transferred to + TQt. + + \sa defaultFactory() +*/ +void TQMimeSourceFactory::setDefaultFactory( TQMimeSourceFactory* factory) +{ + if ( !defaultfactory ) + tqmime_cleanup_factory.set( &defaultfactory ); + else if ( defaultfactory != factory ) + delete defaultfactory; + defaultfactory = factory; +} + +/*! + Sets the defaultFactory() to 0 and returns the previous one. +*/ + +TQMimeSourceFactory* TQMimeSourceFactory::takeDefaultFactory() +{ + TQMimeSourceFactory *f = defaultfactory; + defaultfactory = 0; + return f; +} + +/*! + Adds the TQMimeSourceFactory \a f to the list of available + mimesource factories. If the defaultFactory() can't resolve a + data() it iterates over the list of installed mimesource factories + until the data can be resolved. + + \sa removeFactory(); +*/ + +void TQMimeSourceFactory::addFactory( TQMimeSourceFactory *f ) +{ + TQMimeSourceFactory::defaultFactory()->d->factories.append( f ); +} + +/*! + Removes the mimesource factory \a f from the list of available + mimesource factories. + + \sa addFactory(); +*/ + +void TQMimeSourceFactory::removeFactory( TQMimeSourceFactory *f ) +{ + TQMimeSourceFactory::defaultFactory()->d->factories.removeRef( f ); +} + +#endif // TQT_NO_MIME diff --git a/src/kernel/tqmime.h b/src/kernel/tqmime.h new file mode 100644 index 000000000..00c31a375 --- /dev/null +++ b/src/kernel/tqmime.h @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Definition of mime classes +** +** Created : 981204 +** +** Copyright (C) 1998-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQMIME_H +#define TQMIME_H + +#ifndef QT_H +#include "ntqwindowdefs.h" +#include "tqmap.h" +#endif // QT_H + +#ifndef TQT_NO_MIME + +class TQImageDrag; +class TQTextDrag; + +class TQ_EXPORT TQMimeSource +{ + friend class TQClipboardData; + +public: + TQMimeSource(); + virtual ~TQMimeSource(); + virtual const char* format( int n = 0 ) const = 0; + virtual bool provides( const char* ) const; + virtual TQByteArray encodedData( const char* ) const = 0; + int serialNumber() const; + +private: + int ser_no; + enum { NoCache, Text, Graphics } cacheType; + union + { + struct + { + TQString *str; + TQCString *subtype; + } txt; + struct + { + TQImage *img; + TQPixmap *pix; + } gfx; + } cache; + void clearCache(); + + // friends for caching + friend class TQImageDrag; + friend class TQTextDrag; + +}; + +inline int TQMimeSource::serialNumber() const +{ return ser_no; } + +class TQStringList; +class TQMimeSourceFactoryData; + +class TQ_EXPORT TQMimeSourceFactory { +public: + TQMimeSourceFactory(); + virtual ~TQMimeSourceFactory(); + + static TQMimeSourceFactory* defaultFactory(); + static void setDefaultFactory( TQMimeSourceFactory* ); + static TQMimeSourceFactory* takeDefaultFactory(); + static void addFactory( TQMimeSourceFactory *f ); + static void removeFactory( TQMimeSourceFactory *f ); + + virtual const TQMimeSource* data(const TQString& abs_name) const; + virtual TQString makeAbsolute(const TQString& abs_or_rel_name, const TQString& context) const; + const TQMimeSource* data(const TQString& abs_or_rel_name, const TQString& context) const; + + virtual void setText( const TQString& abs_name, const TQString& text ); + virtual void setImage( const TQString& abs_name, const TQImage& im ); + virtual void setPixmap( const TQString& abs_name, const TQPixmap& pm ); + virtual void setData( const TQString& abs_name, TQMimeSource* data ); + virtual void setFilePath( const TQStringList& ); + virtual TQStringList filePath() const; + void addFilePath( const TQString& ); + virtual void setExtensionType( const TQString& ext, const char* mimetype ); + +private: + TQMimeSource *dataInternal(const TQString& abs_name, const TQMap &extensions ) const; + TQMimeSourceFactoryData* d; +}; + +#if defined(TQ_WS_WIN) + +#ifndef QT_H +#include "tqptrlist.h" // down here for GCC 2.7.* compatibility +#endif // QT_H + +/* + Encapsulation of conversion between MIME and Windows CLIPFORMAT. + Not need on X11, as the underlying protocol uses the MIME standard + directly. +*/ + +class TQ_EXPORT TQWindowsMime { +public: + TQWindowsMime(); + virtual ~TQWindowsMime(); + + static void initialize(); + + static TQPtrList all(); + static TQWindowsMime* convertor( const char* mime, int cf ); + static const char* cfToMime(int cf); + + static int registerMimeType(const char *mime); + + virtual const char* convertorName()=0; + virtual int countCf()=0; + virtual int cf(int index)=0; + virtual bool canConvert( const char* mime, int cf )=0; + virtual const char* mimeFor(int cf)=0; + virtual int cfFor(const char* )=0; + virtual TQByteArray convertToMime( TQByteArray data, const char* mime, int cf )=0; + virtual TQByteArray convertFromMime( TQByteArray data, const char* mime, int cf )=0; +}; + +#endif +#if defined(TQ_WS_MAC) + +#ifndef QT_H +#include "tqptrlist.h" // down here for GCC 2.7.* compatibility +#endif // QT_H + +/* + Encapsulation of conversion between MIME and Mac flavor. + Not need on X11, as the underlying protocol uses the MIME standard + directly. +*/ + +class TQ_EXPORT TQMacMime { + char type; +public: + enum TQMacMimeType { MIME_DND=0x01, MIME_CLIP=0x02, MIME_QT_CONVERTOR=0x04, MIME_ALL=MIME_DND|MIME_CLIP }; + TQMacMime(char); + virtual ~TQMacMime(); + + static void initialize(); + + static TQPtrList all(TQMacMimeType); + static TQMacMime* convertor(TQMacMimeType, const char* mime, int flav); + static const char* flavorToMime(TQMacMimeType, int flav); + + virtual const char* convertorName()=0; + virtual int countFlavors()=0; + virtual int flavor(int index)=0; + virtual bool canConvert(const char* mime, int flav)=0; + virtual const char* mimeFor(int flav)=0; + virtual int flavorFor(const char*)=0; + virtual TQByteArray convertToMime(TQValueList data, const char* mime, int flav)=0; + virtual TQValueList convertFromMime(TQByteArray data, const char* mime, int flav)=0; +}; + +#endif // TQ_WS_MAC + +#endif // TQT_NO_MIME + +#endif // TQMIME_H diff --git a/src/table/qtable.cpp b/src/table/qtable.cpp index c696dbaf2..4d00dbe9e 100644 --- a/src/table/qtable.cpp +++ b/src/table/qtable.cpp @@ -57,7 +57,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/widgets/qlineedit.cpp b/src/widgets/qlineedit.cpp index c2236cf17..296547aff 100644 --- a/src/widgets/qlineedit.cpp +++ b/src/widgets/qlineedit.cpp @@ -53,7 +53,7 @@ #include "ntqclipboard.h" #include "ntqapplication.h" #include "ntqvalidator.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "tqtimer.h" #include "tqpopupmenu.h" #include "tqstringlist.h" diff --git a/src/widgets/qlistview.cpp b/src/widgets/qlistview.cpp index 6ad78f0f3..ea01ae82b 100644 --- a/src/widgets/qlistview.cpp +++ b/src/widgets/qlistview.cpp @@ -57,7 +57,7 @@ #include "ntqpixmapcache.h" #include "tqpopupmenu.h" #include "ntqtl.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqlineedit.h" #include "ntqvbox.h" #include "tqtooltip.h" diff --git a/src/widgets/qmultilineedit.cpp b/src/widgets/qmultilineedit.cpp index 3a5dd652e..2d82938b2 100644 --- a/src/widgets/qmultilineedit.cpp +++ b/src/widgets/qmultilineedit.cpp @@ -47,7 +47,7 @@ #include "ntqpixmap.h" #include "ntqregexp.h" #include "ntqapplication.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "tqpopupmenu.h" #include "tqtimer.h" #include "ntqdict.h" diff --git a/src/widgets/tqiconview.cpp b/src/widgets/tqiconview.cpp index b741563bd..6703ef82d 100644 --- a/src/widgets/tqiconview.cpp +++ b/src/widgets/tqiconview.cpp @@ -52,7 +52,7 @@ #include "ntqpainter.h" #include "ntqevent.h" #include "ntqpalette.h" -#include "ntqmime.h" +#include "tqmime.h" #include "tqimage.h" #include "ntqpen.h" #include "ntqbrush.h" diff --git a/src/widgets/tqiconview.h b/src/widgets/tqiconview.h index 18fafc3bb..a15d4baae 100644 --- a/src/widgets/tqiconview.h +++ b/src/widgets/tqiconview.h @@ -48,7 +48,7 @@ #include "ntqpoint.h" #include "tqsize.h" #include "ntqfont.h" // TQString->TQFont conversion -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqbitmap.h" #include "ntqpicture.h" #endif // QT_H diff --git a/src/widgets/tqtextbrowser.cpp b/src/widgets/tqtextbrowser.cpp index d28543409..e579c6c73 100644 --- a/src/widgets/tqtextbrowser.cpp +++ b/src/widgets/tqtextbrowser.cpp @@ -55,7 +55,7 @@ #include "tqtimer.h" #include "tqimage.h" #include "ntqsimplerichtext.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqurl.h" #include "ntqcursor.h" diff --git a/src/widgets/tqtextedit.cpp b/src/widgets/tqtextedit.cpp index c3b0cb74c..8505f6c5b 100644 --- a/src/widgets/tqtextedit.cpp +++ b/src/widgets/tqtextedit.cpp @@ -66,7 +66,7 @@ #include "ntqcolordialog.h" #include "ntqfontdialog.h" #include "tqstylesheet.h" -#include "ntqdragobject.h" +#include "tqdragobject.h" #include "ntqurl.h" #include "ntqcursor.h" #include "ntqregexp.h" -- cgit v1.2.1