Qt 4.8
Classes | Macros | Functions | Variables
qdnd_mac.mm File Reference
#include "qapplication.h"
#include "qbitmap.h"
#include "qcursor.h"
#include "qevent.h"
#include "qpainter.h"
#include "qurl.h"
#include "qwidget.h"
#include "qfile.h"
#include "qfileinfo.h"
#include <stdlib.h>
#include <string.h>
#include "qaccessible.h"
#include <private/qapplication_p.h>
#include <private/qwidget_p.h>
#include <private/qdnd_p.h>
#include <private/qt_mac_p.h>

Go to the source code of this file.

Classes

struct  mac_enum_mapper
 

Macros

#define MAP_MAC_ENUM(x)   x
 

Functions

uint qGlobalPostedEventsCount ()
 
void qt_mac_copy_answer_rect (const QDragMoveEvent &event)
 
void qt_mac_dispose_rgn (RgnHandle)
 
static Qt::DropActions qt_mac_dnd_map_mac_actions (DragActions macActions)
 
static Qt::DropAction qt_mac_dnd_map_mac_default_action (DragActions macActions)
 
static DragActions qt_mac_dnd_map_qt_actions (Qt::DropActions qActions)
 
static void qt_mac_dnd_update_action (DragReference dragRef)
 
RgnHandle qt_mac_get_rgn ()
 
bool qt_mac_mouse_inside_answer_rect (QPoint mouse)
 
void qt_mac_send_modifiers_changed (quint32, QObject *)
 
static bool qt_mac_set_existing_drop_action (const DragRef &dragRef, QDropEvent &event)
 

Variables

static const char *const default_pm []
 
static const int default_pm_hotx = -2
 
static const int default_pm_hoty = -16
 
static mac_enum_mapper dnd_action_symbols []
 
static DragReference qt_mac_current_dragRef = 0
 
QMacDndAnswerRecord qt_mac_dnd_answer_rec
 
bool qt_mac_in_drag = false
 

Macro Definition Documentation

◆ MAP_MAC_ENUM

#define MAP_MAC_ENUM (   x)    x

Definition at line 119 of file qdnd_mac.mm.

Function Documentation

◆ qGlobalPostedEventsCount()

uint qGlobalPostedEventsCount ( )

Definition at line 348 of file qcoreapplication.cpp.

Referenced by qt_mac_mouse_inside_answer_rect().

349 {
350  QThreadData *currentThreadData = QThreadData::current();
351  return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset;
352 }
QPostEventList postEventList
Definition: qthread_p.h:266
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QThreadData * current()

◆ qt_mac_copy_answer_rect()

void qt_mac_copy_answer_rect ( const QDragMoveEvent event)

If an answer rect has been set on the event (after being sent to the global event processor), we store that rect so we can check if the mouse is in the same area upon next drag move event.

Definition at line 318 of file qdnd_mac.mm.

Referenced by QMacDndAnswerRecord::clear(), and qt_mac_mouse_inside_answer_rect().

319 {
320  if (!event.answerRect().isEmpty()) {
321  qt_mac_dnd_answer_rec.rect = event.answerRect();
322  qt_mac_dnd_answer_rec.buttons = event.mouseButtons();
323  qt_mac_dnd_answer_rec.modifiers = event.keyboardModifiers();
324  qt_mac_dnd_answer_rec.lastAction = event.dropAction();
325  }
326 }
Qt::KeyboardModifiers modifiers
Definition: qt_mac_p.h:268
QRect answerRect() const
Returns the rectangle in the widget where the drop will occur if accepted.
Definition: qevent.h:537
Qt::MouseButtons buttons
Definition: qt_mac_p.h:269
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
QMacDndAnswerRecord qt_mac_dnd_answer_rec
Definition: qdnd_mac.mm:67
Qt::DropAction lastAction
Definition: qt_mac_p.h:270

◆ qt_mac_dispose_rgn()

void qt_mac_dispose_rgn ( RgnHandle  )

◆ qt_mac_dnd_map_mac_actions()

static Qt::DropActions qt_mac_dnd_map_mac_actions ( DragActions  macActions)
static

Definition at line 146 of file qdnd_mac.mm.

Referenced by qt_mac_dnd_map_mac_default_action(), qt_mac_dnd_update_action(), qt_mac_mouse_inside_answer_rect(), and qt_mac_set_existing_drop_action().

147 {
148 #ifdef DEBUG_DRAG_EVENTS
149  qDebug("Converting DND ActionList: 0x%lx", macActions);
150 #endif
151  Qt::DropActions ret = Qt::IgnoreAction;
152  for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
153 #ifdef DEBUG_DRAG_EVENTS
154  qDebug(" %d) [%s] : %s", i, dnd_action_symbols[i].qt_desc,
155  (macActions & dnd_action_symbols[i].mac_code) ? "true" : "false");
156 #endif
157  if(macActions & dnd_action_symbols[i].mac_code)
158  ret |= Qt::DropAction(dnd_action_symbols[i].qt_code);
159  }
160  return ret;
161 }
static mac_enum_mapper dnd_action_symbols[]
Definition: qdnd_mac.mm:130
Q_CORE_EXPORT void qDebug(const char *,...)
DropAction
Definition: qnamespace.h:1597

◆ qt_mac_dnd_map_mac_default_action()

static Qt::DropAction qt_mac_dnd_map_mac_default_action ( DragActions  macActions)
static

Definition at line 162 of file qdnd_mac.mm.

Referenced by QDragManager::drag(), qt_mac_dnd_update_action(), and qt_mac_mouse_inside_answer_rect().

163 {
164  static Qt::DropAction preferred_actions[] = { Qt::CopyAction, Qt::LinkAction, //in order
167  const Qt::DropActions qtActions = qt_mac_dnd_map_mac_actions(macActions);
168  for(int i = 0; preferred_actions[i] != Qt::IgnoreAction; ++i) {
169  if(qtActions & preferred_actions[i]) {
170  ret = preferred_actions[i];
171  break;
172  }
173  }
174 #ifdef DEBUG_DRAG_EVENTS
175  for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
176  if(dnd_action_symbols[i].qt_code == ret) {
177  qDebug("Got default action: %s [0x%lx]", dnd_action_symbols[i].qt_desc, macActions);
178  break;
179  }
180  }
181 #endif
182  return ret;
183 }
static mac_enum_mapper dnd_action_symbols[]
Definition: qdnd_mac.mm:130
static Qt::DropActions qt_mac_dnd_map_mac_actions(DragActions macActions)
Definition: qdnd_mac.mm:146
Q_CORE_EXPORT void qDebug(const char *,...)
DropAction
Definition: qnamespace.h:1597

◆ qt_mac_dnd_map_qt_actions()

static DragActions qt_mac_dnd_map_qt_actions ( Qt::DropActions  qActions)
static

Definition at line 137 of file qdnd_mac.mm.

Referenced by QDragManager::drag(), qt_mac_dnd_update_action(), and qt_mac_mouse_inside_answer_rect().

138 {
139  DragActions ret = kDragActionNothing;
140  for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
141  if(qActions & dnd_action_symbols[i].qt_code)
142  ret |= dnd_action_symbols[i].mac_code;
143  }
144  return ret;
145 }
static mac_enum_mapper dnd_action_symbols[]
Definition: qdnd_mac.mm:130

◆ qt_mac_dnd_update_action()

static void qt_mac_dnd_update_action ( DragReference  dragRef)
static

Definition at line 184 of file qdnd_mac.mm.

Referenced by QDragManager::drag(), and qt_mac_mouse_inside_answer_rect().

184  {
185  SInt16 modifiers;
186  GetDragModifiers(dragRef, &modifiers, 0, 0);
188 
189  Qt::DropAction qtAction = Qt::IgnoreAction;
190  {
191  DragActions macAllowed = kDragActionNothing;
192  GetDragDropAction(dragRef, &macAllowed);
193  Qt::DropActions qtAllowed = qt_mac_dnd_map_mac_actions(macAllowed);
195 #if 1
196  if(!(qtAllowed & qtAction))
197  qtAction = qt_mac_dnd_map_mac_default_action(macAllowed);
198 #endif
199  }
200  DragActions macAction = qt_mac_dnd_map_qt_actions(qtAction);
201 
202  DragActions currentActions;
203  GetDragDropAction(dragRef, &currentActions);
204  if(currentActions != macAction) {
205  SetDragDropAction(dragRef, macAction);
207  }
208 }
static DragActions qt_mac_dnd_map_qt_actions(Qt::DropActions qActions)
Definition: qdnd_mac.mm:137
Qt::DropAction defaultAction(Qt::DropActions possibleActions, Qt::KeyboardModifiers modifiers) const
Definition: qdnd.cpp:194
static Qt::DropActions qt_mac_dnd_map_mac_actions(DragActions macActions)
Definition: qdnd_mac.mm:146
void emitActionChanged(Qt::DropAction newAction)
Definition: qdnd_p.h:253
static Qt::DropAction qt_mac_dnd_map_mac_default_action(DragActions macActions)
Definition: qdnd_mac.mm:162
#define qApp
DropAction
Definition: qnamespace.h:1597
static QDragManager * self()
Definition: qdnd.cpp:163
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
void qt_mac_send_modifiers_changed(quint32, QObject *)

◆ qt_mac_get_rgn()

RgnHandle qt_mac_get_rgn ( )

◆ qt_mac_mouse_inside_answer_rect()

bool qt_mac_mouse_inside_answer_rect ( QPoint  mouse)

Definition at line 328 of file qdnd_mac.mm.

Referenced by QMacDndAnswerRecord::clear(), and qt_mac_mouse_inside_answer_rect().

329 {
334  return true;
335  else
336  return false;
337 }
Qt::KeyboardModifiers modifiers
Definition: qt_mac_p.h:268
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
Qt::MouseButtons buttons
Definition: qt_mac_p.h:269
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
QMacDndAnswerRecord qt_mac_dnd_answer_rec
Definition: qdnd_mac.mm:67
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
static Qt::MouseButtons mouseButtons()
Returns the current state of the buttons on the mouse.

◆ qt_mac_send_modifiers_changed()

void qt_mac_send_modifiers_changed ( quint32  ,
QObject  
)

Definition at line 199 of file qkeymapper_mac.cpp.

Referenced by QApplicationPrivate::globalEventProcessor(), qt_dispatchModifiersChanged(), qt_mac_dnd_update_action(), and QKeyMapperPrivate::translateKeyEvent().

200 {
201  static quint32 cachedModifiers = 0;
202  quint32 lastModifiers = cachedModifiers,
203  changedModifiers = lastModifiers ^ modifiers;
204  cachedModifiers = modifiers;
205 
206  //check the bits
207  static qt_mac_enum_mapper modifier_key_symbols[] = {
208  { shiftKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Shift) },
209  { rightShiftKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Shift) }, //???
210  { controlKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Meta) },
211  { rightControlKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Meta) }, //???
212  { cmdKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Control) },
213  { optionKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Alt) },
214  { rightOptionKeyBit, QT_MAC_MAP_ENUM(Qt::Key_Alt) }, //???
215  { alphaLockBit, QT_MAC_MAP_ENUM(Qt::Key_CapsLock) },
216  { kEventKeyModifierNumLockBit, QT_MAC_MAP_ENUM(Qt::Key_NumLock) },
217  { 0, QT_MAC_MAP_ENUM(0) } };
218  for (int i = 0; i <= 32; i++) { //just check each bit
219  if (!(changedModifiers & (1 << i)))
220  continue;
222  if (lastModifiers & (1 << i))
223  etype = QEvent::KeyRelease;
224  int key = 0;
225  for (uint x = 0; modifier_key_symbols[x].mac_code; x++) {
226  if (modifier_key_symbols[x].mac_code == i) {
227 #ifdef DEBUG_KEY_BINDINGS_MODIFIERS
228  qDebug("got modifier changed: %s", modifier_key_symbols[x].desc);
229 #endif
230  key = modifier_key_symbols[x].qt_code;
231  break;
232  }
233  }
234  if (!key) {
235 #ifdef DEBUG_KEY_BINDINGS_MODIFIERS
236  qDebug("could not get modifier changed: %d", i);
237 #endif
238  continue;
239  }
240 #ifdef DEBUG_KEY_BINDINGS_MODIFIERS
241  qDebug("KeyEvent (modif): Sending %s to %s::%s: %d - 0x%08x",
242  etype == QEvent::KeyRelease ? "KeyRelease" : "KeyPress",
243  object ? object->metaObject()->className() : "none",
244  object ? object->objectName().toLatin1().constData() : "",
245  key, (int)modifiers);
246 #endif
247  QKeyEvent ke(etype, key, qt_mac_get_modifiers(modifiers ^ (1 << i)), QLatin1String(""));
248  qt_sendSpontaneousEvent(object, &ke);
249  }
250 }
The QKeyEvent class describes a key event.
Definition: qevent.h:224
Qt::KeyboardModifiers qt_mac_get_modifiers(int keys)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool qt_sendSpontaneousEvent(QObject *obj, QEvent *event)
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned int uint
Definition: qglobal.h:996
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
int key
unsigned int quint32
Definition: qglobal.h:938
#define QT_MAC_MAP_ENUM(x)

◆ qt_mac_set_existing_drop_action()

static bool qt_mac_set_existing_drop_action ( const DragRef &  dragRef,
QDropEvent event 
)
inlinestatic

If a drop action is already set on the carbon event (from e.g. an earlier enter event), we insert the same action on the new Qt event that has yet to be sendt.

Definition at line 296 of file qdnd_mac.mm.

Referenced by qt_mac_mouse_inside_answer_rect().

297 {
298 #ifndef QT_MAC_USE_COCOA
299  DragActions currentAction = kDragActionNothing;
300  OSStatus err = GetDragDropAction(dragRef, &currentAction);
301  if (err == noErr && currentAction != kDragActionNothing) {
302  // This looks a bit evil, but we only ever set one action, so it's OK.
303  event.setDropAction(Qt::DropAction(int(qt_mac_dnd_map_mac_actions(currentAction))));
304  return true;
305  }
306 #else
307  Q_UNUSED(dragRef);
308  Q_UNUSED(event);
309 #endif
310  return false;
311 }
static Qt::DropActions qt_mac_dnd_map_mac_actions(DragActions macActions)
Definition: qdnd_mac.mm:146
DropAction
Definition: qnamespace.h:1597
signed long OSStatus
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

Variable Documentation

◆ default_pm

const char* const default_pm[]
static
Initial value:
= {
"13 9 3 1",
". c None",
" c #000000",
"X c #FFFFFF",
"X X X X X X X",
" X X X X X X ",
"X ......... X",
" X.........X ",
"X ......... X",
" X.........X ",
"X ......... X",
" X X X X X X ",
"X X X X X X X",
}

Definition at line 98 of file qdnd_mac.mm.

Referenced by QDragManager::drag().

◆ default_pm_hotx

const int default_pm_hotx = -2
static

Definition at line 95 of file qdnd_mac.mm.

Referenced by QDragManager::drag().

◆ default_pm_hoty

const int default_pm_hoty = -16
static

Definition at line 96 of file qdnd_mac.mm.

Referenced by QDragManager::drag().

◆ dnd_action_symbols

mac_enum_mapper dnd_action_symbols[]
static
Initial value:
= {
{ kDragActionAlias, MAP_MAC_ENUM(Qt::LinkAction) },
{ kDragActionMove, MAP_MAC_ENUM(Qt::MoveAction) },
{ kDragActionGeneric, MAP_MAC_ENUM(Qt::CopyAction) },
{ kDragActionCopy, MAP_MAC_ENUM(Qt::CopyAction) },
{ 0, MAP_MAC_ENUM(0) }
}
#define MAP_MAC_ENUM(x)
Definition: qdnd_mac.mm:119

Definition at line 130 of file qdnd_mac.mm.

◆ qt_mac_current_dragRef

DragReference qt_mac_current_dragRef = 0
static

◆ qt_mac_dnd_answer_rec

QMacDndAnswerRecord qt_mac_dnd_answer_rec

Definition at line 67 of file qdnd_mac.mm.

Referenced by QMacDndAnswerRecord::clear().

◆ qt_mac_in_drag

bool qt_mac_in_drag = false

Definition at line 78 of file qdnd_mac.mm.

Referenced by QDragManager::drag().