Qt 4.8
Classes | Typedefs | Enumerations | Functions
qt_cocoa_helpers_mac_p.h File Reference
#include <private/qt_mac_p.h>
#include <qapplication.h>
#include <qdesktopwidget.h>
#include <qwidget.h>
#include <qevent.h>
#include <qhash.h>
#include <qlabel.h>
#include <qpointer.h>
#include <qstyle.h>
#include <qstyleoption.h>
#include <qstylepainter.h>
#include <qtimer.h>
#include <qtooltip.h>
#include <private/qeffects_p.h>
#include <private/qwidget_p.h>
#include <qtextdocument.h>
#include <qdebug.h>
#include <qpoint.h>

Go to the source code of this file.

Classes

class  QMacScrollOptimization
 

Typedefs

typedef struct CGPoint NSPoint
 

Enumerations

enum  { QtCocoaEventSubTypeWakeup = SHRT_MAX, QtCocoaEventSubTypePostMessage = SHRT_MAX-1 }
 

Functions

QPointF flipPoint (const NSPoint &p)
 
NSPoint flipPoint (const QPoint &p)
 
NSPoint flipPoint (const QPointF &p)
 
int flipYCoordinate (int y)
 
qreal flipYCoordinate (qreal y)
 
void macSendToolbarChangeEvent (QWidget *widget)
 
void macWindowFade (void *window, float durationSeconds=0.15)
 
void macWindowFlush (void *window)
 
bool macWindowIsTextured (void *window)
 
void macWindowSetHasShadow (void *window, bool hasShadow)
 
bool macWindowToolbarIsVisible (void *window)
 
void macWindowToolbarSet (void *window, void *toolbarRef)
 
void macWindowToolbarShow (const QWidget *widget, bool show)
 
QApplicationqAppInstance ()
 
Qt::KeyboardModifiers qt_cocoaDragOperation2QtModifiers (uint dragOperations)
 
Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers (ulong modifierFlags)
 
bool qt_dispatchKeyEvent (void *keyEvent, QWidget *widgetToGetEvent)
 
void qt_dispatchModifiersChanged (void *flagsChangedEvent, QWidget *widgetToGetEvent)
 
void qt_dispatchTabletProximityEvent (void *tabletEvent)
 
void qt_dispatchTabletProximityEvent (const ::TabletProximityRec &proxRec)
 
bool qt_mac_checkForNativeSizeGrip (const QWidget *widget)
 
void qt_mac_constructQIconFromIconRef (const IconRef icon, const IconRef overlayIcon, QIcon *retIcon, QStyle::StandardPixmap standardIcon=QStyle::SP_CustomBase)
 
QPixmap qt_mac_convert_iconref (const IconRef icon, int width, int height)
 
void * qt_mac_create_nsimage (const QPixmap &pm)
 
void qt_mac_draw_image (CGContextRef context, CGContextRef imageContext, CGRect area, CGRect drawingArea)
 
OSStatus qt_mac_drawCGImage (CGContextRef cg, const CGRect *inbounds, CGImageRef)
 
Qt::MouseButton qt_mac_get_button (EventMouseButton button)
 
Qt::MouseButtons qt_mac_get_buttons (int buttons)
 
QString qt_mac_get_pasteboardString (OSPasteboardRef paste)
 
CGFloat qt_mac_get_scalefactor ()
 
bool qt_mac_handleTabletEvent (void *view, void *event)
 
QStringList qt_mac_NSArrayToQStringList (void *nsarray)
 
void qt_mac_post_retranslateAppMenu ()
 
void * qt_mac_QStringListToNSMutableArrayVoid (const QStringList &list)
 
void qt_mac_release_graphics_context (CGContextRef context)
 
void qt_mac_replaceDrawRect (void *window, QWidgetPrivate *widget)
 
void qt_mac_replaceDrawRectOriginal (void *window, QWidgetPrivate *widget)
 
void qt_mac_retain_graphics_context (CGContextRef context)
 
void qt_mac_showBaseLineSeparator (void *window, bool show)
 
void qt_mac_update_mouseTracking (QWidget *widget)
 
void qt_mac_updateContentBorderMetricts (void *window, const ::HIContentBorderMetrics &metrics)
 
void qt_syncCocoaTitleBarButtons (OSWindowRef window, QWidget *widgetForWindow)
 

Typedef Documentation

◆ NSPoint

typedef struct CGPoint NSPoint

Definition at line 118 of file qt_cocoa_helpers_mac_p.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
QtCocoaEventSubTypeWakeup 
QtCocoaEventSubTypePostMessage 

Definition at line 123 of file qt_cocoa_helpers_mac_p.h.

Function Documentation

◆ flipPoint() [1/3]

QPointF flipPoint ( const NSPoint p)

Definition at line 862 of file qt_cocoa_helpers_mac.mm.

Referenced by flipPoint(), flipYCoordinate(), QWidget::mapToGlobal(), QCursor::pos(), qt_mac_handleTabletEvent(), and QApplication::topLevelAt().

863 {
864  return QPointF(p.x, flipYCoordinate(p.y));
865 }
int flipYCoordinate(int y)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214

◆ flipPoint() [2/3]

NSPoint flipPoint ( const QPoint p)

Definition at line 867 of file qt_cocoa_helpers_mac.mm.

868 {
869  return NSMakePoint(p.x(), flipYCoordinate(p.y()));
870 }
int flipYCoordinate(int y)
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128

◆ flipPoint() [3/3]

NSPoint flipPoint ( const QPointF p)

Definition at line 872 of file qt_cocoa_helpers_mac.mm.

873 {
874  return NSMakePoint(p.x(), flipYCoordinate(p.y()));
875 }
int flipYCoordinate(int y)
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ flipYCoordinate() [1/2]

int flipYCoordinate ( int  y)
inline

Definition at line 188 of file qt_cocoa_helpers_mac_p.h.

Referenced by QWidgetPrivate::create_sys(), flipPoint(), QWidget::mapFromGlobal(), qt_mac_unregister_widget(), QWidgetPrivate::setGeometry_sys(), and updateRedirectedToGraphicsProxyWidget().

189 {
190  return QApplication::desktop()->screenGeometry(0).height() - y;
191 }
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
const QRect screenGeometry(int screen=-1) const

◆ flipYCoordinate() [2/2]

qreal flipYCoordinate ( qreal  y)
inline

Definition at line 193 of file qt_cocoa_helpers_mac_p.h.

194 {
195  return QApplication::desktop()->screenGeometry(0).height() - y;
196 }
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
const QRect screenGeometry(int screen=-1) const

◆ macSendToolbarChangeEvent()

void macSendToolbarChangeEvent ( QWidget widget)

Definition at line 435 of file qt_cocoa_helpers_mac.mm.

Referenced by make_win_eventUPP().

436 {
437  QToolBarChangeEvent ev(!(GetCurrentKeyModifiers() & cmdKey));
438  qt_sendSpontaneousEvent(widget, &ev);
439 }
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
The QToolBarChangeEvent class provides an event that is sent whenever a the toolbar button is clicked...
Definition: qevent.h:662

◆ macWindowFade()

void macWindowFade ( void *  window,
float  durationSeconds = 0.15 
)

Definition at line 155 of file qt_cocoa_helpers_mac.mm.

Referenced by QMenuPrivate::hideMenu(), QComboBox::hidePopup(), and QTipLabel::timerEvent().

156 {
157 #ifdef QT_MAC_USE_COCOA
159 #endif
160  OSWindowRef wnd = static_cast<OSWindowRef>(window);
161  if (wnd) {
162  QWidget *widget;
163 #if QT_MAC_USE_COCOA
164  widget = [wnd QT_MANGLE_NAMESPACE(qt_qwidget)];
165 #else
166  const UInt32 kWidgetCreatorQt = kEventClassQt;
167  enum {
168  kWidgetPropertyQWidget = 'QWId' //QWidget *
169  };
170  if (GetWindowProperty(static_cast<WindowRef>(window), kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(widget), 0, &widget) != noErr)
171  widget = 0;
172 #endif
173  if (widget) {
177  }
178  }
179 }
QPointer< QWidget > widget
const UInt32 kWidgetCreatorQt
Definition: qwidget_mac.mm:148
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
NSWindow * window
static QMacWindowFader * currentFader()
WindowRef OSWindowRef
void setFadeDuration(float durationInSecs)
Definition: qt_mac_p.h:136
void registerWindowToFade(QWidget *window)
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
const UInt32 kEventClassQt
Definition: qt_mac_p.h:92

◆ macWindowFlush()

void macWindowFlush ( void *  window)

Definition at line 312 of file qt_cocoa_helpers_mac.mm.

Referenced by QEventDispatcherMac::flush().

313 {
314  OSWindowRef wnd = static_cast<OSWindowRef>(window);
315 #if QT_MAC_USE_COCOA
316  [wnd flushWindowIfNeeded];
317 #else
318  HIWindowFlush(wnd);
319 #endif
320 }
NSWindow * window
WindowRef OSWindowRef

◆ macWindowIsTextured()

bool macWindowIsTextured ( void *  window)

Definition at line 245 of file qt_cocoa_helpers_mac.mm.

Referenced by qt_mac_is_metal().

246 {
247  OSWindowRef wnd = static_cast<OSWindowRef>(window);
248 #if QT_MAC_USE_COCOA
249  return ( [wnd styleMask] & NSTexturedBackgroundWindowMask ) ? true : false;
250 #else
251  WindowAttributes currentAttributes;
252  GetWindowAttributes(wnd, &currentAttributes);
253  return (currentAttributes & kWindowMetalAttribute) ? true : false;
254 #endif
255 }
NSWindow * window
WindowRef OSWindowRef

◆ macWindowSetHasShadow()

void macWindowSetHasShadow ( void *  window,
bool  hasShadow 
)

Definition at line 299 of file qt_cocoa_helpers_mac.mm.

Referenced by QRubberBand::QRubberBand().

300 {
301  OSWindowRef wnd = static_cast<OSWindowRef>(window);
302 #if QT_MAC_USE_COCOA
303  [wnd setHasShadow:BOOL(hasShadow)];
304 #else
305  if (hasShadow)
306  ChangeWindowAttributes(wnd, 0, kWindowNoShadowAttribute);
307  else
308  ChangeWindowAttributes(wnd, kWindowNoShadowAttribute, 0);
309 #endif
310 }
NSWindow * window
WindowRef OSWindowRef

◆ macWindowToolbarIsVisible()

bool macWindowToolbarIsVisible ( void *  window)

Definition at line 287 of file qt_cocoa_helpers_mac.mm.

Referenced by QToolBar::event(), and QMainWindowLayout::toggleToolBarsVisible().

288 {
289  OSWindowRef wnd = static_cast<OSWindowRef>(window);
290 #if QT_MAC_USE_COCOA
291  if (NSToolbar *toolbar = [wnd toolbar])
292  return [toolbar isVisible];
293  return false;
294 #else
295  return IsWindowToolbarVisible(wnd);
296 #endif
297 }
NSToolbar * toolbar
NSWindow * window
WindowRef OSWindowRef

◆ macWindowToolbarSet()

void macWindowToolbarSet ( void *  window,
void *  toolbarRef 
)

Definition at line 277 of file qt_cocoa_helpers_mac.mm.

Referenced by QMainWindowLayout::insertIntoMacToolbar(), and QMainWindowLayout::updateHIToolBarStatus().

278 {
279  OSWindowRef wnd = static_cast<OSWindowRef>(window);
280 #if QT_MAC_USE_COCOA
281  [wnd setToolbar:static_cast<NSToolbar *>(toolbarRef)];
282 #else
283  SetWindowToolbar(wnd, static_cast<HIToolbarRef>(toolbarRef));
284 #endif
285 }
NSWindow * window
WindowRef OSWindowRef

◆ macWindowToolbarShow()

void macWindowToolbarShow ( const QWidget widget,
bool  show 
)

Definition at line 257 of file qt_cocoa_helpers_mac.mm.

Referenced by QToolBar::event(), QToolBarPrivate::init(), QMainWindowLayout::insertIntoMacToolbar(), QMainWindowLayout::syncUnifiedToolbarVisibility(), QMainWindowLayout::updateHIToolBarStatus(), and QToolBar::~QToolBar().

258 {
259  OSWindowRef wnd = qt_mac_window_for(widget);
260 #if QT_MAC_USE_COCOA
261  if (NSToolbar *toolbar = [wnd toolbar]) {
263  if (show != [toolbar isVisible]) {
264  [toolbar setVisible:show];
265  } else {
266  // The toolbar may be in sync, but we are not, update our framestrut.
267  qt_widget_private(const_cast<QWidget *>(widget))->updateFrameStrut();
268  }
269  }
270 #else
271  qt_widget_private(const_cast<QWidget *>(widget))->updateFrameStrut();
272  ShowHideWindowToolbar(wnd, show, false);
273 #endif
274 }
NSToolbar * toolbar
OSWindowRef qt_mac_window_for(const QWidget *)
Definition: qwidget_mac.mm:484
WindowRef OSWindowRef
void updateFrameStrut()
Computes the frame rectangle when needed.
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920

◆ qAppInstance()

QApplication* qAppInstance ( )
inline

Definition at line 158 of file qt_cocoa_helpers_mac_p.h.

Referenced by qt_mac_handleTabletEvent().

158 { return static_cast<QApplication *>(QCoreApplication::instance()); }
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.

◆ qt_cocoaDragOperation2QtModifiers()

Qt::KeyboardModifiers qt_cocoaDragOperation2QtModifiers ( uint  dragOperations)

Referenced by qAppInstance(), and qtKey2CocoaKey().

◆ qt_cocoaModifiers2QtModifiers()

Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers ( ulong  modifierFlags)

◆ qt_dispatchKeyEvent()

bool qt_dispatchKeyEvent ( void *  keyEvent,
QWidget widgetToGetEvent 
)

Definition at line 812 of file qt_cocoa_helpers_mac.mm.

813 {
814 #ifndef QT_MAC_USE_COCOA
816  Q_UNUSED(widgetToGetEvent);
817  return false;
818 #else
819  NSEvent *event = static_cast<NSEvent *>(keyEvent);
820  EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef]));
821  Q_ASSERT(key_event);
822  unsigned int info = 0;
823 
824  if ([event type] == NSKeyDown) {
825  NSString *characters = [event characters];
826  if ([characters length]) {
827  unichar value = [characters characterAtIndex:0];
828  qt_keymapper_private()->updateKeyMap(0, key_event, (void *)&value);
829  info = value;
830  }
831  }
832 
833  if (qt_mac_sendMacEventToWidget(widgetToGetEvent, key_event))
834  return true;
835 
836  if (mustUseCocoaKeyEvent())
837  return qt_dispatchKeyEventWithCocoa(keyEvent, widgetToGetEvent);
838 
839  bool consumed = qt_keymapper_private()->translateKeyEvent(widgetToGetEvent, 0, key_event, &info, true);
840  return consumed && (info != 0);
841 #endif
842 }
int type
Definition: qmetatype.cpp:239
static mach_timebase_info_data_t info
EventRef event
static void keyEvent(KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
void updateKeyMap(const MSG &msg)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool translateKeyEvent(QWidget *receiver, const MSG &msg, bool grab)
bool qt_mac_sendMacEventToWidget(QWidget *widget, EventRef ref)
Definition: qwidget_mac.mm:448
struct OpaqueEventRef * EventRef
QKeyMapperPrivate * qt_keymapper_private()
Definition: qkeymapper.cpp:113
#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

◆ qt_dispatchModifiersChanged()

void qt_dispatchModifiersChanged ( void *  flagsChangedEvent,
QWidget widgetToGetEvent 
)

Definition at line 844 of file qt_cocoa_helpers_mac.mm.

845 {
846 #ifndef QT_MAC_USE_COCOA
847  Q_UNUSED(flagsChangedEvent);
848  Q_UNUSED(widgetToGetEvent);
849 #else
850  UInt32 modifiers = 0;
851  // Sync modifiers with Qt
852  NSEvent *event = static_cast<NSEvent *>(flagsChangedEvent);
853  EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef]));
854  Q_ASSERT(key_event);
855  GetEventParameter(key_event, kEventParamKeyModifiers, typeUInt32, 0,
856  sizeof(modifiers), 0, &modifiers);
857  extern void qt_mac_send_modifiers_changed(quint32 modifiers, QObject *object);
858  qt_mac_send_modifiers_changed(modifiers, widgetToGetEvent);
859 #endif
860 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
struct OpaqueEventRef * EventRef
unsigned int quint32
Definition: qglobal.h:938
void qt_mac_send_modifiers_changed(quint32, QObject *)
#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

◆ qt_dispatchTabletProximityEvent() [1/2]

void qt_dispatchTabletProximityEvent ( void *  tabletEvent)

Referenced by qAppInstance().

◆ qt_dispatchTabletProximityEvent() [2/2]

void qt_dispatchTabletProximityEvent ( const ::TabletProximityRec &  proxRec)

Definition at line 477 of file qt_cocoa_helpers_mac.mm.

Referenced by QApplicationPrivate::globalEventProcessor(), qt_mac_tablet_hash(), and QApplicationPrivate::tabletProximityCallback().

478 {
479  QTabletDeviceData proximityDevice;
480  proximityDevice.tabletUniqueID = proxRec.uniqueID;
481  proximityDevice.capabilityMask = proxRec.capabilityMask;
482 
483  switch (proxRec.pointerType) {
484  case NSUnknownPointingDevice:
485  default:
486  proximityDevice.tabletPointerType = QTabletEvent::UnknownPointer;
487  break;
488  case NSPenPointingDevice:
489  proximityDevice.tabletPointerType = QTabletEvent::Pen;
490  break;
491  case NSCursorPointingDevice:
492  proximityDevice.tabletPointerType = QTabletEvent::Cursor;
493  break;
494  case NSEraserPointingDevice:
495  proximityDevice.tabletPointerType = QTabletEvent::Eraser;
496  break;
497  }
498  uint bits = proxRec.vendorPointerType;
499  if (bits == 0 && proximityDevice.tabletUniqueID != 0) {
500  // Fallback. It seems that the driver doesn't always include all the information.
501  // High-End Wacom devices store their "type" in the uper bits of the Unique ID.
502  // I'm not sure how to handle it for consumer devices, but I'll test that in a bit.
503  bits = proximityDevice.tabletUniqueID >> 32;
504  }
505  // Defined in the "EN0056-NxtGenImpGuideX"
506  // on Wacom's Developer Website (www.wacomeng.com)
507  if (((bits & 0x0006) == 0x0002) && ((bits & 0x0F06) != 0x0902)) {
508  proximityDevice.tabletDeviceType = QTabletEvent::Stylus;
509  } else {
510  switch (bits & 0x0F06) {
511  case 0x0802:
512  proximityDevice.tabletDeviceType = QTabletEvent::Stylus;
513  break;
514  case 0x0902:
515  proximityDevice.tabletDeviceType = QTabletEvent::Airbrush;
516  break;
517  case 0x0004:
518  proximityDevice.tabletDeviceType = QTabletEvent::FourDMouse;
519  break;
520  case 0x0006:
521  proximityDevice.tabletDeviceType = QTabletEvent::Puck;
522  break;
523  case 0x0804:
524  proximityDevice.tabletDeviceType = QTabletEvent::RotationStylus;
525  break;
526  default:
527  proximityDevice.tabletDeviceType = QTabletEvent::NoDevice;
528  }
529  }
530  // The deviceID is "unique" while in the proximity, it's a key that we can use for
531  // linking up TabletDeviceData to an event (especially if there are two devices in action).
532  bool entering = proxRec.enterProximity;
533  if (entering) {
534  qt_mac_tablet_hash()->insert(proxRec.deviceID, proximityDevice);
535  } else {
536  qt_mac_tablet_hash()->remove(proxRec.deviceID);
537  }
538 
539  QTabletEvent qtabletProximity(entering ? QEvent::TabletEnterProximity
541  QPoint(), QPoint(), QPointF(), proximityDevice.tabletDeviceType,
542  proximityDevice.tabletPointerType, 0., 0, 0, 0., 0., 0, 0,
543  proximityDevice.tabletUniqueID);
544 
545  qt_sendSpontaneousEvent(qApp, &qtabletProximity);
546 }
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
QMacTabletHash * qt_mac_tablet_hash()
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
#define qApp
unsigned int uint
Definition: qglobal.h:996
The QTabletEvent class contains parameters that describe a Tablet event.
Definition: qevent.h:179
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

◆ qt_mac_checkForNativeSizeGrip()

bool qt_mac_checkForNativeSizeGrip ( const QWidget widget)

Definition at line 371 of file qt_cocoa_helpers_mac.mm.

Referenced by QAbstractScrollAreaPrivate::layoutChildren().

372 {
373 #ifndef QT_MAC_USE_COCOA
374  OSViewRef nativeSizeGrip = 0;
375  HIViewFindByID(HIViewGetRoot(HIViewGetWindow(HIViewRef(widget->winId()))), kHIViewWindowGrowBoxID, &nativeSizeGrip);
376  return (nativeSizeGrip != 0);
377 #else
378  return [[reinterpret_cast<NSView *>(widget->effectiveWinId()) window] showsResizeIndicator];
379 #endif
380 }
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
NSWindow * window
struct OpaqueControlRef * HIViewRef
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
HIViewRef OSViewRef

◆ qt_mac_constructQIconFromIconRef()

void qt_mac_constructQIconFromIconRef ( const IconRef  icon,
const IconRef  overlayIcon,
QIcon retIcon,
QStyle::StandardPixmap  standardIcon = QStyle::SP_CustomBase 
)

Definition at line 1610 of file qt_cocoa_helpers_mac.mm.

Referenced by QFileIconProviderPrivate::getWinIcon(), qAppInstance(), and QCommonStyle::standardIconImplementation().

1611 {
1612  int size = 16;
1613  while (size <= 128) {
1614 
1615  const QString cacheKey = QLatin1String("qt_mac_constructQIconFromIconRef") + QString::number(standardIcon) + QString::number(size);
1616  QPixmap mainIcon;
1617  if (standardIcon >= QStyle::SP_CustomBase) {
1618  mainIcon = qt_mac_convert_iconref(icon, size, size);
1619  } else if (QPixmapCache::find(cacheKey, mainIcon) == false) {
1620  mainIcon = qt_mac_convert_iconref(icon, size, size);
1621  QPixmapCache::insert(cacheKey, mainIcon);
1622  }
1623 
1624  if (overlayIcon) {
1625  int littleSize = size / 2;
1626  QPixmap overlayPix = qt_mac_convert_iconref(overlayIcon, littleSize, littleSize);
1627  QPainter painter(&mainIcon);
1628  painter.drawPixmap(size - littleSize, size - littleSize, overlayPix);
1629  }
1630 
1631  retIcon->addPixmap(mainIcon);
1632  size += size; // 16 -> 32 -> 64 -> 128
1633  }
1634 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void addPixmap(const QPixmap &pixmap, Mode mode=Normal, State state=Off)
Adds pixmap to the icon, as a specialization for mode and state.
Definition: qicon.cpp:814
QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QPixmap * find(const QString &key)
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ qt_mac_convert_iconref()

QPixmap qt_mac_convert_iconref ( const IconRef  icon,
int  width,
int  height 
)

Definition at line 1591 of file qt_cocoa_helpers_mac.mm.

Referenced by qAppInstance(), and qt_mac_constructQIconFromIconRef().

1592 {
1593  QPixmap ret(width, height);
1594  ret.fill(QColor(0, 0, 0, 0));
1595 
1596  CGRect rect = CGRectMake(0, 0, width, height);
1597 
1599  CGAffineTransform old_xform = CGContextGetCTM(ctx);
1600  CGContextConcatCTM(ctx, CGAffineTransformInvert(old_xform));
1601  CGContextConcatCTM(ctx, CGAffineTransformIdentity);
1602 
1603  ::RGBColor b;
1604  b.blue = b.green = b.red = 255*255;
1605  PlotIconRefInContext(ctx, &rect, kAlignNone, kTransformNone, &b, kPlotIconRefNormalFlags, icon);
1606  CGContextRelease(ctx);
1607  return ret;
1608 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
CGContextRef qt_mac_cg_context(const QPaintDevice *pdev)
Returns the CoreGraphics CGContextRef of the paint device.
struct CGRect CGRect
#define ctx
Definition: qgl.cpp:6094
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
struct CGContext * CGContextRef

◆ qt_mac_create_nsimage()

void* qt_mac_create_nsimage ( const QPixmap pm)

Definition at line 322 of file qt_cocoa_helpers_mac.mm.

Referenced by qt_mac_set_app_icon(), QCursor::setPos(), QWidgetPrivate::setWindowIcon_sys(), QMenuPrivate::QMacMenuPrivate::syncAction(), and QSystemTrayIconPrivate::updateIcon_sys().

323 {
325  if(QCFType<CGImageRef> image = pm.toMacCGImageRef()) {
326  NSImage *newImage = 0;
327  NSRect imageRect = NSMakeRect(0.0, 0.0, CGImageGetWidth(image), CGImageGetHeight(image));
328  newImage = [[NSImage alloc] initWithSize:imageRect.size];
329  [newImage lockFocus];
330  {
331  CGContextRef imageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
332  CGContextDrawImage(imageContext, *(CGRect*)&imageRect, image);
333  }
334  [newImage unlockFocus];
335  return newImage;
336  }
337  return 0;
338 }
struct CGRect CGRect
struct CGContext * CGContextRef
CGImageRef toMacCGImageRef() const
Creates a CGImageRef equivalent to the QPixmap.

◆ qt_mac_draw_image()

void qt_mac_draw_image ( CGContextRef  context,
CGContextRef  imageContext,
CGRect  area,
CGRect  drawingArea 
)
inline

Definition at line 325 of file qt_cocoa_helpers_mac_p.h.

326 {
327  CGImageRef image = CGBitmapContextCreateImage(imageContext);
328  CGImageRef subImage = CGImageCreateWithImageInRect(image, area);
329 
330  CGContextTranslateCTM (context, 0, drawingArea.origin.y + CGRectGetMaxY(drawingArea));
331  CGContextScaleCTM(context, 1, -1);
332  CGContextDrawImage(context, drawingArea, subImage);
333 
334  CGImageRelease(subImage);
335  CGImageRelease(image);
336 }
struct CGImage * CGImageRef
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ qt_mac_drawCGImage()

OSStatus qt_mac_drawCGImage ( CGContextRef  cg,
const CGRect inbounds,
CGImageRef   
)

Definition at line 349 of file qt_cocoa_helpers_mac.mm.

Referenced by QCoreGraphicsPaintEngine::drawImage(), QCoreGraphicsPaintEngine::drawPixmap(), QMacWindowSurface::flush(), QRasterWindowSurface::flush(), QPixmap::fromMacCGImageRef(), qt_mac_draw_pattern(), and QMacWindowSurface::scroll().

350 {
351  // Verbatim copy if HIViewDrawCGImage (as shown on Carbon-Dev)
352  OSStatus err = noErr;
353 
354  require_action(inContext != NULL, InvalidContext, err = paramErr);
355  require_action(inBounds != NULL, InvalidBounds, err = paramErr);
356  require_action(inImage != NULL, InvalidImage, err = paramErr);
357 
358  CGContextSaveGState( inContext );
359  CGContextTranslateCTM (inContext, 0, inBounds->origin.y + CGRectGetMaxY(*inBounds));
360  CGContextScaleCTM(inContext, 1, -1);
361 
362  CGContextDrawImage(inContext, *inBounds, inImage);
363 
364  CGContextRestoreGState(inContext);
365 InvalidImage:
366 InvalidBounds:
367 InvalidContext:
368  return err;
369 }
signed long OSStatus

◆ qt_mac_get_button()

Qt::MouseButton qt_mac_get_button ( EventMouseButton  button)

Definition at line 418 of file qt_cocoa_helpers_mac.mm.

Referenced by QApplicationPrivate::globalEventProcessor().

419 {
420 #ifdef DEBUG_MOUSE_MAPS
421  qDebug("Qt: internal: **Mapping button: %d (0x%04x)", button, button);
422 #endif
423  Qt::MouseButtons ret = 0;
424  for(int i = 0; qt_mac_mouse_symbols[i].qt_code; i++) {
425  if (button == qt_mac_mouse_symbols[i].mac_code) {
426 #ifdef DEBUG_MOUSE_MAPS
427  qDebug("Qt: internal: got button: %s", qt_mac_mouse_symbols[i].desc);
428 #endif
429  return Qt::MouseButton(qt_mac_mouse_symbols[i].qt_code);
430  }
431  }
432  return Qt::NoButton;
433 }
static qt_mac_enum_mapper qt_mac_mouse_symbols[]
Q_CORE_EXPORT void qDebug(const char *,...)
MouseButton
Definition: qnamespace.h:150

◆ qt_mac_get_buttons()

Qt::MouseButtons qt_mac_get_buttons ( int  buttons)

Definition at line 402 of file qt_cocoa_helpers_mac.mm.

Referenced by flipPoint(), and QApplicationPrivate::globalEventProcessor().

403 {
404 #ifdef DEBUG_MOUSE_MAPS
405  qDebug("Qt: internal: **Mapping buttons: %d (0x%04x)", buttons, buttons);
406 #endif
407  Qt::MouseButtons ret = Qt::NoButton;
408  for(int i = 0; qt_mac_mouse_symbols[i].qt_code; i++) {
409  if (buttons & (0x01<<(qt_mac_mouse_symbols[i].mac_code-1))) {
410 #ifdef DEBUG_MOUSE_MAPS
411  qDebug("Qt: internal: got button: %s", qt_mac_mouse_symbols[i].desc);
412 #endif
413  ret |= Qt::MouseButtons(qt_mac_mouse_symbols[i].qt_code);
414  }
415  }
416  return ret;
417 }
static Qt::MouseButtons buttons
static qt_mac_enum_mapper qt_mac_mouse_symbols[]
Q_CORE_EXPORT void qDebug(const char *,...)

◆ qt_mac_get_pasteboardString()

QString qt_mac_get_pasteboardString ( OSPasteboardRef  paste)

Definition at line 1572 of file qt_cocoa_helpers_mac.mm.

Referenced by flipYCoordinate(), and QMacPasteboard::retrieveData().

1573 {
1575  NSPasteboard *pb = nil;
1576  CFStringRef pbname;
1577  if (PasteboardCopyName(paste, &pbname) == noErr) {
1578  pb = [NSPasteboard pasteboardWithName:const_cast<NSString *>(reinterpret_cast<const NSString *>(pbname))];
1579  CFRelease(pbname);
1580  } else {
1581  pb = [NSPasteboard generalPasteboard];
1582  }
1583  if (pb) {
1584  NSString *text = [pb stringForType:NSStringPboardType];
1585  if (text)
1586  return qt_mac_NSStringToQString(text);
1587  }
1588  return QString();
1589 }
const struct __CFString * CFStringRef
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define text
Definition: qobjectdefs.h:80

◆ qt_mac_get_scalefactor()

CGFloat qt_mac_get_scalefactor ( )

Definition at line 1558 of file qt_cocoa_helpers_mac.mm.

Referenced by QStyleHelper::dpiScaled(), flipYCoordinate(), QPixmapIconEngine::paint(), QIconLoaderEngine::paint(), qt_mac_grabDisplayRect(), QToolButton::sizeHint(), and QCoreGraphicsPaintEngine::updateRenderHints().

1559 {
1560 #ifndef QT_MAC_USE_COCOA
1561  return HIGetScaleFactor();
1562 #endif
1563 
1564 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
1565  NSScreen *mainScreen = [NSScreen mainScreen];
1566  if ([mainScreen respondsToSelector:@selector(backingScaleFactor)])
1567  return [mainScreen backingScaleFactor];
1568 #endif
1569  return 1.0;
1570 }

◆ qt_mac_handleTabletEvent()

bool qt_mac_handleTabletEvent ( void *  view,
void *  event 
)

Definition at line 1292 of file qt_cocoa_helpers_mac.mm.

Referenced by flipPoint().

1293 {
1294 #ifndef QT_MAC_USE_COCOA
1295  Q_UNUSED(view);
1296  Q_UNUSED(tabletEvent);
1297  return false;
1298 #else
1299  QT_MANGLE_NAMESPACE(QCocoaView) *theView = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view);
1300  NSView *theNSView = static_cast<NSView *>(view);
1301  NSEvent *theTabletEvent = static_cast<NSEvent *>(tabletEvent);
1302 
1303  NSEventType eventType = [theTabletEvent type];
1304  if (eventType != NSTabletPoint && [theTabletEvent subtype] != NSTabletPointEventSubtype)
1305  return false; // Not a tablet event.
1306 
1307  NSPoint windowPoint = [theTabletEvent locationInWindow];
1308  NSPoint globalPoint = [[theTabletEvent window] convertBaseToScreen:windowPoint];
1309 
1310  QWidget *qwidget = [theView qt_qwidget];
1311  QWidget *widgetToGetMouse = qwidget;
1312  QWidget *popup = qAppInstance()->activePopupWidget();
1313  if (popup && popup != qwidget->window())
1314  widgetToGetMouse = popup;
1315 
1316  if (qt_mac_sendMacEventToWidget(widgetToGetMouse,
1317  static_cast<EventRef>(const_cast<void *>([theTabletEvent eventRef]))))
1318  return true;
1319  if (widgetToGetMouse != qwidget) {
1320  theNSView = qt_mac_nativeview_for(widgetToGetMouse);
1321  windowPoint = [[theNSView window] convertScreenToBase:globalPoint];
1322  }
1323  NSPoint localPoint = [theNSView convertPoint:windowPoint fromView:nil];
1324  // Tablet events do not handle WA_TransparentForMouseEvents ATM
1325  // In theory, people who set the WA_TransparentForMouseEvents attribute won't handle
1326  // tablet events either in which case they will fall into the mouse event case and get
1327  // them passed on. This will NOT handle the raw events, but that might not be a big problem.
1328 
1329  const QMacTabletHash *tabletHash = qt_mac_tablet_hash();
1330  if (!tabletHash->contains([theTabletEvent deviceID])) {
1331  qWarning("QCocoaView handleTabletEvent: This tablet device is unknown"
1332  " (received no proximity event for it). Discarding event.");
1333  return false;
1334  }
1335  const QTabletDeviceData &deviceData = tabletHash->value([theTabletEvent deviceID]);
1336 
1337 
1338  QEvent::Type qType;
1339  switch (eventType) {
1340  case NSLeftMouseDown:
1341  case NSRightMouseDown:
1342  qType = QEvent::TabletPress;
1343  break;
1344  case NSLeftMouseUp:
1345  case NSRightMouseUp:
1346  qType = QEvent::TabletRelease;
1347  break;
1348  case NSMouseMoved:
1349  case NSTabletPoint:
1350  case NSLeftMouseDragged:
1351  case NSRightMouseDragged:
1352  default:
1353  qType = QEvent::TabletMove;
1354  break;
1355  }
1356 
1357  qreal pressure;
1358  if (eventType != NSMouseMoved) {
1359  pressure = [theTabletEvent pressure];
1360  } else {
1361  pressure = 0.0;
1362  }
1363 
1364  NSPoint tilt = [theTabletEvent tilt];
1365  int xTilt = qRound(tilt.x * 60.0);
1366  int yTilt = qRound(tilt.y * -60.0);
1367  qreal tangentialPressure = 0;
1368  qreal rotation = 0;
1369  int z = 0;
1370  if (deviceData.capabilityMask & 0x0200)
1371  z = [theTabletEvent absoluteZ];
1372 
1373  if (deviceData.capabilityMask & 0x0800)
1374  tangentialPressure = [theTabletEvent tangentialPressure];
1375 
1376  rotation = [theTabletEvent rotation];
1377  QPointF hiRes = flipPoint(globalPoint);
1378  QTabletEvent qtabletEvent(qType, QPoint(localPoint.x, localPoint.y),
1379  hiRes.toPoint(), hiRes,
1380  deviceData.tabletDeviceType, deviceData.tabletPointerType,
1381  pressure, xTilt, yTilt, tangentialPressure, rotation, z,
1382  qt_cocoaModifiers2QtModifiers([theTabletEvent modifierFlags]),
1383  deviceData.tabletUniqueID);
1384 
1385  qt_sendSpontaneousEvent(widgetToGetMouse, &qtabletEvent);
1386  return qtabletEvent.isAccepted();
1387 #endif
1388 }
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event)
QPointF flipPoint(const NSPoint &p)
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QMacTabletHash * qt_mac_tablet_hash()
Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags)
NSWindow * window
Q_CORE_EXPORT void qWarning(const char *,...)
bool qt_mac_sendMacEventToWidget(QWidget *widget, EventRef ref)
Definition: qwidget_mac.mm:448
The QTabletEvent class contains parameters that describe a Tablet event.
Definition: qevent.h:179
QApplication * qAppInstance()
static QWidget * activePopupWidget()
Returns the active popup widget.
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
struct CGPoint NSPoint
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
OSViewRef qt_mac_nativeview_for(const QWidget *)
Definition: qwidget_mac.mm:419
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
#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
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ qt_mac_NSArrayToQStringList()

QStringList qt_mac_NSArrayToQStringList ( void *  nsarray)

Definition at line 1486 of file qt_cocoa_helpers_mac.mm.

Referenced by flipYCoordinate().

1487 {
1488  QStringList result;
1489  NSArray *array = static_cast<NSArray *>(nsarray);
1490  for (NSUInteger i=0; i<[array count]; ++i)
1491  result << qt_mac_NSStringToQString([array objectAtIndex:i]);
1492  return result;
1493 }
The QStringList class provides a list of strings.
Definition: qstringlist.h:66

◆ qt_mac_post_retranslateAppMenu()

void qt_mac_post_retranslateAppMenu ( )

Definition at line 1726 of file qt_cocoa_helpers_mac.mm.

Referenced by QApplication::event(), and QMacScrollOptimization::performDelayedScroll().

1727 {
1728 #ifdef QT_MAC_USE_COCOA
1730  qt_cocoaPostMessage([NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)], @selector(qtTranslateApplicationMenu));
1731 #endif
1732 }
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106

◆ qt_mac_QStringListToNSMutableArrayVoid()

void* qt_mac_QStringListToNSMutableArrayVoid ( const QStringList list)

Definition at line 1495 of file qt_cocoa_helpers_mac.mm.

Referenced by flipYCoordinate().

1496 {
1497  NSMutableArray *result = [NSMutableArray arrayWithCapacity:list.size()];
1498  for (int i=0; i<list.size(); ++i){
1499  [result addObject:reinterpret_cast<const NSString *>(QCFString::toCFStringRef(list[i]))];
1500  }
1501  return result;
1502 }
static CFStringRef toCFStringRef(const QString &str)
Definition: qcore_mac.cpp:69
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ qt_mac_release_graphics_context()

void qt_mac_release_graphics_context ( CGContextRef  context)
inline

Definition at line 319 of file qt_cocoa_helpers_mac_p.h.

320 {
321  CGContextRestoreGState(context);
322  CGContextRelease(context);
323 }

◆ qt_mac_replaceDrawRect()

void qt_mac_replaceDrawRect ( void *  window,
QWidgetPrivate widget 
)

◆ qt_mac_replaceDrawRectOriginal()

void qt_mac_replaceDrawRectOriginal ( void *  window,
QWidgetPrivate widget 
)

◆ qt_mac_retain_graphics_context()

void qt_mac_retain_graphics_context ( CGContextRef  context)
inline

Definition at line 313 of file qt_cocoa_helpers_mac_p.h.

314 {
315  CGContextRetain(context);
316  CGContextSaveGState(context);
317 }

◆ qt_mac_showBaseLineSeparator()

void qt_mac_showBaseLineSeparator ( void *  window,
bool  show 
)

◆ qt_mac_update_mouseTracking()

void qt_mac_update_mouseTracking ( QWidget widget)

Definition at line 340 of file qt_cocoa_helpers_mac.mm.

Referenced by QWidget::changeEvent(), and QWidget::setAttribute().

341 {
342 #ifdef QT_MAC_USE_COCOA
343  [qt_mac_nativeview_for(widget) updateTrackingAreas];
344 #else
345  Q_UNUSED(widget);
346 #endif
347 }
OSViewRef qt_mac_nativeview_for(const QWidget *)
Definition: qwidget_mac.mm:419
#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

◆ qt_mac_updateContentBorderMetricts()

void qt_mac_updateContentBorderMetricts ( void *  window,
const ::HIContentBorderMetrics &  metrics 
)

Definition at line 1390 of file qt_cocoa_helpers_mac.mm.

Referenced by QTabBarPrivate::updateMacBorderMetrics().

1391 {
1392  OSWindowRef theWindow = static_cast<OSWindowRef>(window);
1393 #if !defined(QT_MAC_USE_COCOA)
1394 # if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
1396  ::HIWindowSetContentBorderThickness(theWindow, &metrics);
1397  }
1398 # else
1399  Q_UNUSED(window);
1400  Q_UNUSED(metrics);
1401 # endif
1402 #else
1403  if ([theWindow styleMask] & NSTexturedBackgroundWindowMask)
1404  [theWindow setContentBorderThickness:metrics.top forEdge:NSMaxYEdge];
1405  [theWindow setContentBorderThickness:metrics.bottom forEdge:NSMinYEdge];
1406 #endif
1407 }
NSWindow * window
WindowRef OSWindowRef
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
#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

◆ qt_syncCocoaTitleBarButtons()

void qt_syncCocoaTitleBarButtons ( OSWindowRef  window,
QWidget widgetForWindow 
)