src/gui/kernel/qdnd.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    58 #include "qimagereader.h"
    58 #include "qimagereader.h"
    59 #include "qimagewriter.h"
    59 #include "qimagewriter.h"
    60 #include "qdebug.h"
    60 #include "qdebug.h"
    61 #include <ctype.h>
    61 #include <ctype.h>
    62 
    62 
       
    63 #include <private/qapplication_p.h>
       
    64 
    63 #ifndef QT_NO_DRAGANDDROP
    65 #ifndef QT_NO_DRAGANDDROP
    64 
    66 
    65 QT_BEGIN_NAMESPACE
    67 QT_BEGIN_NAMESPACE
    66 
       
    67 // These pixmaps approximate the images in the Windows User Interface Guidelines.
       
    68 
       
    69 // XPM
       
    70 
       
    71 static const char * const move_xpm[] = {
       
    72 "11 20 3 1",
       
    73 ".        c None",
       
    74 #if defined(Q_WS_WIN)
       
    75 "a        c #000000",
       
    76 "X        c #FFFFFF", // Windows cursor is traditionally white
       
    77 #else
       
    78 "a        c #FFFFFF",
       
    79 "X        c #000000", // X11 cursor is traditionally black
       
    80 #endif
       
    81 "aa.........",
       
    82 "aXa........",
       
    83 "aXXa.......",
       
    84 "aXXXa......",
       
    85 "aXXXXa.....",
       
    86 "aXXXXXa....",
       
    87 "aXXXXXXa...",
       
    88 "aXXXXXXXa..",
       
    89 "aXXXXXXXXa.",
       
    90 "aXXXXXXXXXa",
       
    91 "aXXXXXXaaaa",
       
    92 "aXXXaXXa...",
       
    93 "aXXaaXXa...",
       
    94 "aXa..aXXa..",
       
    95 "aa...aXXa..",
       
    96 "a.....aXXa.",
       
    97 "......aXXa.",
       
    98 ".......aXXa",
       
    99 ".......aXXa",
       
   100 "........aa."};
       
   101 
       
   102 #ifdef Q_WS_WIN
       
   103 /* XPM */
       
   104 static const char * const ignore_xpm[] = {
       
   105 "24 30 3 1",
       
   106 ".        c None",
       
   107 "a        c #000000",
       
   108 "X        c #FFFFFF",
       
   109 "aa......................",
       
   110 "aXa.....................",
       
   111 "aXXa....................",
       
   112 "aXXXa...................",
       
   113 "aXXXXa..................",
       
   114 "aXXXXXa.................",
       
   115 "aXXXXXXa................",
       
   116 "aXXXXXXXa...............",
       
   117 "aXXXXXXXXa..............",
       
   118 "aXXXXXXXXXa.............",
       
   119 "aXXXXXXaaaa.............",
       
   120 "aXXXaXXa................",
       
   121 "aXXaaXXa................",
       
   122 "aXa..aXXa...............",
       
   123 "aa...aXXa...............",
       
   124 "a.....aXXa..............",
       
   125 "......aXXa.....XXXX.....",
       
   126 ".......aXXa..XXaaaaXX...",
       
   127 ".......aXXa.XaaaaaaaaX..",
       
   128 "........aa.XaaaXXXXaaaX.",
       
   129 "...........XaaaaX..XaaX.",
       
   130 "..........XaaXaaaX..XaaX",
       
   131 "..........XaaXXaaaX.XaaX",
       
   132 "..........XaaX.XaaaXXaaX",
       
   133 "..........XaaX..XaaaXaaX",
       
   134 "...........XaaX..XaaaaX.",
       
   135 "...........XaaaXXXXaaaX.",
       
   136 "............XaaaaaaaaX..",
       
   137 ".............XXaaaaXX...",
       
   138 "...............XXXX....."};
       
   139 #endif
       
   140 
       
   141 /* XPM */
       
   142 static const char * const copy_xpm[] = {
       
   143 "24 30 3 1",
       
   144 ".        c None",
       
   145 "a        c #000000",
       
   146 "X        c #FFFFFF",
       
   147 #if defined(Q_WS_WIN) // Windows cursor is traditionally white
       
   148 "aa......................",
       
   149 "aXa.....................",
       
   150 "aXXa....................",
       
   151 "aXXXa...................",
       
   152 "aXXXXa..................",
       
   153 "aXXXXXa.................",
       
   154 "aXXXXXXa................",
       
   155 "aXXXXXXXa...............",
       
   156 "aXXXXXXXXa..............",
       
   157 "aXXXXXXXXXa.............",
       
   158 "aXXXXXXaaaa.............",
       
   159 "aXXXaXXa................",
       
   160 "aXXaaXXa................",
       
   161 "aXa..aXXa...............",
       
   162 "aa...aXXa...............",
       
   163 "a.....aXXa..............",
       
   164 "......aXXa..............",
       
   165 ".......aXXa.............",
       
   166 ".......aXXa.............",
       
   167 "........aa...aaaaaaaaaaa",
       
   168 #else
       
   169 "XX......................",
       
   170 "XaX.....................",
       
   171 "XaaX....................",
       
   172 "XaaaX...................",
       
   173 "XaaaaX..................",
       
   174 "XaaaaaX.................",
       
   175 "XaaaaaaX................",
       
   176 "XaaaaaaaX...............",
       
   177 "XaaaaaaaaX..............",
       
   178 "XaaaaaaaaaX.............",
       
   179 "XaaaaaaXXXX.............",
       
   180 "XaaaXaaX................",
       
   181 "XaaXXaaX................",
       
   182 "XaX..XaaX...............",
       
   183 "XX...XaaX...............",
       
   184 "X.....XaaX..............",
       
   185 "......XaaX..............",
       
   186 ".......XaaX.............",
       
   187 ".......XaaX.............",
       
   188 "........XX...aaaaaaaaaaa",
       
   189 #endif
       
   190 ".............aXXXXXXXXXa",
       
   191 ".............aXXXXXXXXXa",
       
   192 ".............aXXXXaXXXXa",
       
   193 ".............aXXXXaXXXXa",
       
   194 ".............aXXaaaaaXXa",
       
   195 ".............aXXXXaXXXXa",
       
   196 ".............aXXXXaXXXXa",
       
   197 ".............aXXXXXXXXXa",
       
   198 ".............aXXXXXXXXXa",
       
   199 ".............aaaaaaaaaaa"};
       
   200 
       
   201 /* XPM */
       
   202 static const char * const link_xpm[] = {
       
   203 "24 30 3 1",
       
   204 ".        c None",
       
   205 "a        c #000000",
       
   206 "X        c #FFFFFF",
       
   207 #if defined(Q_WS_WIN) // Windows cursor is traditionally white
       
   208 "aa......................",
       
   209 "aXa.....................",
       
   210 "aXXa....................",
       
   211 "aXXXa...................",
       
   212 "aXXXXa..................",
       
   213 "aXXXXXa.................",
       
   214 "aXXXXXXa................",
       
   215 "aXXXXXXXa...............",
       
   216 "aXXXXXXXXa..............",
       
   217 "aXXXXXXXXXa.............",
       
   218 "aXXXXXXaaaa.............",
       
   219 "aXXXaXXa................",
       
   220 "aXXaaXXa................",
       
   221 "aXa..aXXa...............",
       
   222 "aa...aXXa...............",
       
   223 "a.....aXXa..............",
       
   224 "......aXXa..............",
       
   225 ".......aXXa.............",
       
   226 ".......aXXa.............",
       
   227 "........aa...aaaaaaaaaaa",
       
   228 #else
       
   229 "XX......................",
       
   230 "XaX.....................",
       
   231 "XaaX....................",
       
   232 "XaaaX...................",
       
   233 "XaaaaX..................",
       
   234 "XaaaaaX.................",
       
   235 "XaaaaaaX................",
       
   236 "XaaaaaaaX...............",
       
   237 "XaaaaaaaaX..............",
       
   238 "XaaaaaaaaaX.............",
       
   239 "XaaaaaaXXXX.............",
       
   240 "XaaaXaaX................",
       
   241 "XaaXXaaX................",
       
   242 "XaX..XaaX...............",
       
   243 "XX...XaaX...............",
       
   244 "X.....XaaX..............",
       
   245 "......XaaX..............",
       
   246 ".......XaaX.............",
       
   247 ".......XaaX.............",
       
   248 "........XX...aaaaaaaaaaa",
       
   249 #endif
       
   250 ".............aXXXXXXXXXa",
       
   251 ".............aXXXaaaaXXa",
       
   252 ".............aXXXXaaaXXa",
       
   253 ".............aXXXaaaaXXa",
       
   254 ".............aXXaaaXaXXa",
       
   255 ".............aXXaaXXXXXa",
       
   256 ".............aXXaXXXXXXa",
       
   257 ".............aXXXaXXXXXa",
       
   258 ".............aXXXXXXXXXa",
       
   259 ".............aaaaaaaaaaa"};
       
   260 
    68 
   261 #ifndef QT_NO_DRAGANDDROP
    69 #ifndef QT_NO_DRAGANDDROP
   262 
    70 
   263 //#define QDND_DEBUG
    71 //#define QDND_DEBUG
   264 
    72 
   324 QDragManager::QDragManager()
   132 QDragManager::QDragManager()
   325     : QObject(qApp)
   133     : QObject(qApp)
   326 {
   134 {
   327     Q_ASSERT(!instance);
   135     Q_ASSERT(!instance);
   328 
   136 
   329 #ifdef Q_WS_WIN
       
   330     n_cursor = 4;
       
   331 #else
       
   332     n_cursor = 3;
       
   333 #endif
       
   334 
       
   335 #ifdef Q_WS_QWS
   137 #ifdef Q_WS_QWS
   336     currentActionForOverrideCursor = Qt::IgnoreAction;
   138     currentActionForOverrideCursor = Qt::IgnoreAction;
   337 #endif
       
   338     pm_cursor = new QPixmap[n_cursor];
       
   339     pm_cursor[0] = QPixmap((const char **)move_xpm);
       
   340     pm_cursor[1] = QPixmap((const char **)copy_xpm);
       
   341     pm_cursor[2] = QPixmap((const char **)link_xpm);
       
   342 #ifdef Q_WS_WIN
       
   343     pm_cursor[3] = QPixmap((const char **)ignore_xpm);
       
   344 #endif
   139 #endif
   345     object = 0;
   140     object = 0;
   346     beingCancelled = false;
   141     beingCancelled = false;
   347     restoreCursor = false;
   142     restoreCursor = false;
   348     willDrop = false;
   143     willDrop = false;
   360 #ifndef QT_NO_CURSOR
   155 #ifndef QT_NO_CURSOR
   361     if (restoreCursor)
   156     if (restoreCursor)
   362         QApplication::restoreOverrideCursor();
   157         QApplication::restoreOverrideCursor();
   363 #endif
   158 #endif
   364     instance = 0;
   159     instance = 0;
   365     delete [] pm_cursor;
       
   366     delete dropData;
   160     delete dropData;
   367 }
   161 }
   368 
   162 
   369 QDragManager *QDragManager::self()
   163 QDragManager *QDragManager::self()
   370 {
   164 {
   377 {
   171 {
   378     QDragPrivate * d = dragPrivate();
   172     QDragPrivate * d = dragPrivate();
   379     if (d && d->customCursors.contains(action))
   173     if (d && d->customCursors.contains(action))
   380         return d->customCursors[action];
   174         return d->customCursors[action];
   381     else if (action == Qt::MoveAction)
   175     else if (action == Qt::MoveAction)
   382         return pm_cursor[0];
   176         return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragMoveCursor);
   383     else if (action == Qt::CopyAction)
   177     else if (action == Qt::CopyAction)
   384         return pm_cursor[1];
   178         return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragCopyCursor);
   385     else if (action == Qt::LinkAction)
   179     else if (action == Qt::LinkAction)
   386         return pm_cursor[2];
   180         return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragLinkCursor);
   387 #ifdef Q_WS_WIN
   181 #ifdef Q_WS_WIN
   388     else if (action == Qt::IgnoreAction)
   182     else if (action == Qt::IgnoreAction)
   389         return pm_cursor[3];
   183         return QApplicationPrivate::instance()->getPixmapCursor(Qt::ForbiddenCursor);
   390 #endif
   184 #endif
   391     return QPixmap();
   185     return QPixmap();
   392 }
   186 }
   393 
   187 
   394 bool QDragManager::hasCustomDragCursors() const
   188 bool QDragManager::hasCustomDragCursors() const