595018458f2df752afa2dedc696b127a1c72f867
[profile/ivi/qtbase.git] / src / plugins / platforms / xcb / qxcbdrag.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QXCBDRAG_H
43 #define QXCBDRAG_H
44
45 #include <qpa/qplatformdrag.h>
46 #include <QtPlatformSupport/private/qsimpledrag_p.h>
47 #include <qxcbobject.h>
48 #include <xcb/xcb.h>
49 #include <qlist.h>
50 #include <qpoint.h>
51 #include <qrect.h>
52 #include <qsharedpointer.h>
53 #include <qvector.h>
54
55 #include <qpixmap.h>
56 #include <qbackingstore.h>
57
58 #include <QtCore/QDebug>
59
60 QT_BEGIN_NAMESPACE
61
62 class QMouseEvent;
63 class QWindow;
64 class QXcbConnection;
65 class QXcbWindow;
66 class QXcbDropData;
67 class QXcbScreen;
68 class QDrag;
69 class QShapedPixmapWindow;
70
71 class QXcbDrag : public QXcbObject, public QBasicDrag
72 {
73 public:
74     QXcbDrag(QXcbConnection *c);
75     ~QXcbDrag();
76
77     virtual QMimeData *platformDropData();
78
79
80     void startDrag();
81     void cancel();
82     void move(const QMouseEvent *me);
83     void drop(const QMouseEvent *me);
84     void endDrag();
85
86     void handleEnter(QWindow *window, const xcb_client_message_event_t *event);
87     void handlePosition(QWindow *w, const xcb_client_message_event_t *event);
88     void handleLeave(QWindow *w, const xcb_client_message_event_t *event);
89     void handleDrop(QWindow *, const xcb_client_message_event_t *event);
90
91     void handleStatus(const xcb_client_message_event_t *event);
92     void handleSelectionRequest(const xcb_selection_request_event_t *event);
93     void handleFinished(const xcb_client_message_event_t *event);
94
95     bool dndEnable(QXcbWindow *win, bool on);
96
97     void updatePixmap();
98
99 protected:
100     void timerEvent(QTimerEvent* e);
101
102 private:
103     friend class QXcbDropData;
104
105     void init();
106
107     void handle_xdnd_position(QWindow *w, const xcb_client_message_event_t *event);
108     void handle_xdnd_status(const xcb_client_message_event_t *event);
109     void send_leave();
110
111     Qt::DropAction toDropAction(xcb_atom_t atom) const;
112     xcb_atom_t toXdndAction(Qt::DropAction a) const;
113
114     QWeakPointer<QWindow> currentWindow;
115     QPoint currentPosition;
116
117     QXcbDropData *dropData;
118     Qt::DropAction accepted_drop_action;
119
120     QWindow *desktop_proxy;
121
122     xcb_atom_t xdnd_dragsource;
123
124     // the types in this drop. 100 is no good, but at least it's big.
125     enum { xdnd_max_type = 100 };
126     QList<xcb_atom_t> xdnd_types;
127
128     xcb_timestamp_t target_time;
129     xcb_timestamp_t source_time;
130
131     // rectangle in which the answer will be the same
132     QRect source_sameanswer;
133     bool waiting_for_status;
134
135     // top-level window we sent position to last.
136     xcb_window_t current_target;
137     // window to send events to (always valid if current_target)
138     xcb_window_t current_proxy_target;
139
140     QXcbScreen *current_screen;
141
142     int heartbeat;
143
144     QVector<xcb_atom_t> drag_types;
145
146     struct Transaction
147     {
148         xcb_timestamp_t timestamp;
149         xcb_window_t target;
150         xcb_window_t proxy_target;
151         QWindow *targetWindow;
152 //        QWidget *embedding_widget;
153         QDrag *drag;
154     };
155     QList<Transaction> transactions;
156
157     int transaction_expiry_timer;
158     void restartDropExpiryTimer();
159     int findTransactionByWindow(xcb_window_t window);
160     int findTransactionByTime(xcb_timestamp_t timestamp);
161     xcb_window_t findRealWindow(const QPoint & pos, xcb_window_t w, int md, bool ignoreNonXdndAwareWindows);
162 };
163
164 QT_END_NAMESPACE
165
166 #endif