📄 qmotifdnd_x11.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. 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.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************//* The following copyright notice pertains to the code as contributedto Trolltech, not to Trolltech's modifications. It is replicatedin doc/dnd.doc, where the documentation system can see it. *//* Copyright 1996 Daniel Dardailler. Permission to use, copy, modify, distribute, and sell this software for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Daniel Dardailler not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Daniel Dardailler makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. Modifications Copyright 1999 Matt Koss, under the same license as above.************************************************************//***********************************************************//* Motif Drag&Drop Dynamic Protocol messaging API code *//* Only requires Xlib layer - not MT safe *//* Author: Daniel Dardailler, daniel@x.org *//* Adapted by: Matt Koss, koss@napri.sk *//* Further adaptions by: Trolltech ASA *//***********************************************************/#include "qplatformdefs.h"#include "qapplication.h"#ifndef QT_NO_DRAGANDDROP#include "qdebug.h"#include "qtextcodec.h"#include "qwidget.h"#include "qevent.h"#include "qt_x11_p.h"#include "qx11info_x11.h"#include "qiodevice.h"#include "qdnd_p.h"#include <stdlib.h>static Window sourceWindow = XNone;static QWidget *dropWidget = 0;static Qt::DropAction lastAcceptedAction = Qt::IgnoreAction;static Atom Dnd_selection = 0;static Time Dnd_selection_time;static Atom * src_targets ;static ushort num_src_targets ;// Motif definitions#define DndVersion 1#define DndRevision 0#define DndIncludeVersion (DndVersion * 10 + DndRevision)/* The following values are used in the DndData structure *//* protocol style */#define DND_DRAG_NONE 0#define DND_DRAG_DROP_ONLY 1#define DND_DRAG_DYNAMIC 5/* message type */#define DND_TOP_LEVEL_ENTER 0#define DND_TOP_LEVEL_LEAVE 1#define DND_DRAG_MOTION 2#define DND_DROP_SITE_ENTER 3#define DND_DROP_SITE_LEAVE 4#define DND_DROP_START 5#define DND_OPERATION_CHANGED 8/* operation(s) */#define DND_NOOP 0L#define DND_MOVE (1L << 0)#define DND_COPY (1L << 1)#define DND_LINK (1L << 2)Qt::DropActions DndOperationsToQtDropActions(uchar op){ Qt::DropActions actions = Qt::IgnoreAction; if (op | DND_MOVE) actions |= Qt::MoveAction; if (op | DND_COPY) actions |= Qt::CopyAction; if (op | DND_LINK) actions |= Qt::LinkAction; return actions;}uchar QtDropActionToDndOperation(Qt::DropAction action){ switch (action & Qt::ActionMask) { case Qt::CopyAction: default: return DND_COPY; case Qt::MoveAction: return DND_MOVE; case Qt::LinkAction: return DND_LINK; }}/* status */#define DND_NO_DROP_SITE 1#define DND_INVALID_DROP_SITE 2#define DND_VALID_DROP_SITE 3/* completion */#define DND_DROP 0#define DND_DROP_HELP 1#define DND_DROP_CANCEL 2#define BYTE unsigned char#define CARD32 unsigned int#define CARD16 unsigned short#define INT16 signed short/* Client side structure used in the API */typedef struct { unsigned char reason; /* message type: DND_TOP_LEVEL_ENTER, etc */ Time time ; unsigned char operation; unsigned char operations; unsigned char status; unsigned char completion; short x ; short y ; Window src_window ; Atom property ;} DndData ;typedef struct _DndSrcProp { BYTE byte_order ; BYTE protocol_version ; CARD16 target_index ; CARD32 selection ;} DndSrcProp ;typedef struct _DndReceiverProp { BYTE byte_order ; BYTE protocol_version ; BYTE protocol_style ; BYTE pad1; CARD32 proxy_window; CARD16 num_drop_sites ; CARD16 pad2; CARD32 total_size;} DndReceiverProp ;/* need to use some union hack since window and property are in different order depending on the message ... */typedef struct _DndTop { CARD32 src_window; CARD32 property;} DndTop ;typedef struct _DndPot { INT16 x; INT16 y; CARD32 property; CARD32 src_window;} DndPot ;typedef struct _DndMessage { BYTE reason; BYTE byte_order; CARD16 flags; CARD32 time; union { DndTop top ; DndPot pot ; } data ;} DndMessage ;typedef struct { BYTE byte_order; BYTE protocol_version; CARD16 num_target_lists; CARD32 data_size; /* then come series of CARD16,CARD32,CARD32,CARD32... */} DndTargets;/* protocol version */#define DND_PROTOCOL_VERSION 0#define DND_EVENT_TYPE_MASK ((BYTE)0x80)#define DND_EVENT_TYPE_SHIFT 7#define DND_CLEAR_EVENT_TYPE ((BYTE)0x7F)/* message_type is data[0] of the client_message this return 1 (receiver bit up) or 0 (initiator) */#define DND_GET_EVENT_TYPE(message_type) \((char) (((message_type) & DND_EVENT_TYPE_MASK) >> DND_EVENT_TYPE_SHIFT))/* event_type can be 0 (initiator) or 1 (receiver) */#define DND_SET_EVENT_TYPE(event_type) \(((BYTE)(event_type) << DND_EVENT_TYPE_SHIFT) & DND_EVENT_TYPE_MASK)#define DND_OPERATION_MASK ((CARD16) 0x000F)#define DND_OPERATION_SHIFT 0#define DND_STATUS_MASK ((CARD16) 0x00F0)#define DND_STATUS_SHIFT 4#define DND_OPERATIONS_MASK ((CARD16) 0x0F00)#define DND_OPERATIONS_SHIFT 8#define DND_COMPLETION_MASK ((CARD16) 0xF000)#define DND_COMPLETION_SHIFT 12#define DND_GET_OPERATION(flags) \((unsigned char) \(((flags) & DND_OPERATION_MASK) >> DND_OPERATION_SHIFT))#define DND_SET_OPERATION(operation) \(((CARD16)(operation) << DND_OPERATION_SHIFT)\& DND_OPERATION_MASK)#define DND_GET_STATUS(flags) \((unsigned char) \(((flags) & DND_STATUS_MASK) >> DND_STATUS_SHIFT))#define DND_SET_STATUS(status) \(((CARD16)(status) << DND_STATUS_SHIFT)\& DND_STATUS_MASK)#define DND_GET_OPERATIONS(flags) \((unsigned char) \(((flags) & DND_OPERATIONS_MASK) >> DND_OPERATIONS_SHIFT))#define DND_SET_OPERATIONS(operation) \(((CARD16)(operation) << DND_OPERATIONS_SHIFT)\& DND_OPERATIONS_MASK)#define DND_GET_COMPLETION(flags) \((unsigned char) \(((flags) & DND_COMPLETION_MASK) >> DND_COMPLETION_SHIFT))#define DND_SET_COMPLETION(completion) \(((CARD16)(completion) << DND_COMPLETION_SHIFT)\& DND_COMPLETION_MASK)#define SWAP4BYTES(l) {\struct { unsigned t :32;} bit32;\char n, *tp = (char *) &bit32;\bit32.t = l;\n = tp[0]; tp[0] = tp[3]; tp[3] = n;\n = tp[1]; tp[1] = tp[2]; tp[2] = n;\l = bit32.t;\}#define SWAP2BYTES(s) {\struct { unsigned t :16; } bit16;\char n, *tp = (char *) &bit16;\bit16.t = s;\n = tp[0]; tp[0] = tp[1]; tp[1] = n;\s = bit16.t;\}/** Private extern functions */static unsigned char DndByteOrder ();/***** Targets/Index stuff */typedef struct { int num_targets; Atom *targets;} DndTargetsTableEntryRec, * DndTargetsTableEntry;typedef struct { int num_entries; DndTargetsTableEntry entries;} DndTargetsTableRec, * DndTargetsTable;static int _DndIndexToTargets(Display * display, int index, Atom ** targets);extern void qt_x11_intern_atom(const char *, Atom *);/////////////////////////////////////////////////////////////////static unsigned char DndByteOrder (){ static unsigned char byte_order = 0; if (!byte_order) { unsigned int endian = 1; byte_order = (*((char *)&endian))?'l':'B';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -