summaryrefslogtreecommitdiffstats
path: root/src/widgets/platforms
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/platforms')
-rw-r--r--src/widgets/platforms/mac/qapplication_mac.mm1244
-rw-r--r--src/widgets/platforms/mac/qclipboard_mac.cpp2
-rw-r--r--src/widgets/platforms/mac/qcocoaintrospection_mac.mm6
-rw-r--r--src/widgets/platforms/mac/qcocoapanel_mac.mm2
-rw-r--r--src/widgets/platforms/mac/qcocoapanel_mac_p.h2
-rw-r--r--src/widgets/platforms/mac/qcocoaview_mac.mm2
-rw-r--r--src/widgets/platforms/mac/qcocoaview_mac_p.h2
-rw-r--r--src/widgets/platforms/mac/qcocoawindow_mac.mm2
-rw-r--r--src/widgets/platforms/mac/qcocoawindow_mac_p.h2
-rw-r--r--src/widgets/platforms/mac/qcocoawindowcustomthemeframe_mac.mm2
-rw-r--r--src/widgets/platforms/mac/qcocoawindowdelegate_mac.mm2
-rw-r--r--src/widgets/platforms/mac/qcocoawindowdelegate_mac_p.h2
-rw-r--r--src/widgets/platforms/mac/qcursor_mac.mm167
-rw-r--r--src/widgets/platforms/mac/qdnd_mac.mm492
-rw-r--r--src/widgets/platforms/mac/qeventdispatcher_mac.mm73
-rw-r--r--src/widgets/platforms/mac/qeventdispatcher_mac_p.h6
-rw-r--r--src/widgets/platforms/mac/qfont_mac.cpp11
-rw-r--r--src/widgets/platforms/mac/qfontdatabase_mac.cpp126
-rw-r--r--src/widgets/platforms/mac/qfontengine_mac.mm1105
-rw-r--r--src/widgets/platforms/mac/qfontengine_mac_p.h117
-rw-r--r--src/widgets/platforms/mac/qkeymapper_mac.cpp34
-rw-r--r--src/widgets/platforms/mac/qmacgesturerecognizer_mac.mm2
-rw-r--r--src/widgets/platforms/mac/qmacgesturerecognizer_mac_p.h2
-rw-r--r--src/widgets/platforms/mac/qmacinputcontext_mac.cpp254
-rw-r--r--src/widgets/platforms/mac/qpaintengine_mac.cpp8
-rw-r--r--src/widgets/platforms/mac/qpixmap_mac.cpp112
-rw-r--r--src/widgets/platforms/mac/qprintengine_mac.mm71
-rw-r--r--src/widgets/platforms/mac/qprintengine_mac_p.h4
-rw-r--r--src/widgets/platforms/mac/qregion_mac.cpp165
-rw-r--r--src/widgets/platforms/mac/qt_cocoa_helpers_mac.mm123
-rw-r--r--src/widgets/platforms/mac/qt_mac.cpp27
-rw-r--r--src/widgets/platforms/mac/qt_mac_p.h2
-rw-r--r--src/widgets/platforms/mac/qtextengine_mac.cpp4
-rw-r--r--src/widgets/platforms/mac/qwidget_mac.mm2326
34 files changed, 3 insertions, 6498 deletions
diff --git a/src/widgets/platforms/mac/qapplication_mac.mm b/src/widgets/platforms/mac/qapplication_mac.mm
index d77c01fc95..cab207e667 100644
--- a/src/widgets/platforms/mac/qapplication_mac.mm
+++ b/src/widgets/platforms/mac/qapplication_mac.mm
@@ -186,19 +186,9 @@ static bool qt_mac_collapse_on_dblclick = true;
extern int qt_antialiasing_threshold; // from qapplication.cpp
QWidget * qt_button_down; // widget got last button-down
QPointer<QWidget> qt_last_mouse_receiver;
-#ifndef QT_MAC_USE_COCOA
-static bool qt_button_down_in_content; // whether the button_down was in the content area.
-static bool qt_mac_previous_press_in_popup_mode = false;
-static bool qt_mac_no_click_through_mode = false;
-static int tablet_button_state = 0;
-#endif
#if defined(QT_DEBUG)
static bool appNoGrab = false; // mouse/keyboard grabbing
#endif
-#ifndef QT_MAC_USE_COCOA
-static EventHandlerRef app_proc_handler = 0;
-static EventHandlerUPP app_proc_handlerUPP = 0;
-#endif
static AEEventHandlerUPP app_proc_ae_handlerUPP = NULL;
static EventHandlerRef tablet_proximity_handler = 0;
static EventHandlerUPP tablet_proximity_UPP = 0;
@@ -356,74 +346,20 @@ static void qt_mac_debug_palette(const QPalette &pal, const QPalette &pal2, cons
#endif
//raise a notification
-#ifndef QT_MAC_USE_COCOA
-static NMRec qt_mac_notification = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-#endif
void qt_mac_send_notification()
{
-#ifndef QT_MAC_USE_COCOA
- //send it
- qt_mac_notification.nmMark = 1; //non-zero magic number
- qt_mac_notification.qType = nmType;
- NMInstall(&qt_mac_notification);
-#else
QMacCocoaAutoReleasePool pool;
[[NSApplication sharedApplication] requestUserAttention:NSInformationalRequest];
-#endif
}
void qt_mac_cancel_notification()
{
-#ifndef QT_MAC_USE_COCOA
- NMRemove(&qt_mac_notification);
-#else
QMacCocoaAutoReleasePool pool;
[[NSApplication sharedApplication] cancelUserAttentionRequest:NSInformationalRequest];
-#endif
}
-#ifndef QT_MAC_USE_COCOA
-//find widget (and part) at a given point
-static short qt_mac_window_at(int x, int y, QWidget **w=0)
-{
- Point p;
- p.h = x;
- p.v = y;
- OSWindowRef wp;
- WindowPartCode wpc;
- OSStatus err = FindWindowOfClass(&p, kAllWindowClasses, &wp, &wpc);
- if(err != noErr) {
- if(w)
- (*w) = 0;
- return wpc;
- }
- if(w) {
- if(wp) {
- *w = qt_mac_find_window(wp);
-#if 0
- if(!*w)
- qWarning("QApplication: qt_mac_window_at: Couldn't find %d",(int)wp);
-#endif
- } else {
- *w = 0;
- }
- }
- return wpc;
-}
-
-#endif
-
void qt_mac_set_app_icon(const QPixmap &pixmap)
{
-#ifndef QT_MAC_USE_COCOA
- if(pixmap.isNull()) {
- RestoreApplicationDockTileImage();
- } else {
- CGImageRef img = (CGImageRef)pixmap.macCGHandle();
- SetApplicationDockTileImage(img);
- CGImageRelease(img);
- }
-#else
QMacCocoaAutoReleasePool pool;
NSImage *image = NULL;
if (pixmap.isNull()) {
@@ -435,7 +371,6 @@ void qt_mac_set_app_icon(const QPixmap &pixmap)
[NSApp setApplicationIconImage:image];
[image release];
-#endif
}
Q_GUI_EXPORT void qt_mac_set_press_and_hold_context(bool b)
@@ -680,49 +615,13 @@ static void qt_mac_event_release(EventRef &event)
ReleaseEvent(event);
event = 0;
}
-#ifndef QT_MAC_USE_COCOA
-static void qt_mac_event_release(QWidget *w, EventRef &event)
-{
- if (event) {
- QWidget *widget = 0;
- if (GetEventParameter(event, kEventParamQWidget, typeQWidget, 0, sizeof(widget), 0, &widget) == noErr
- && w == widget) {
- if (IsEventInQueue(GetMainEventQueue(), event))
- RemoveEventFromQueue(GetMainEventQueue(), event);
- qt_mac_event_release(event);
- }
- }
-}
-
-static bool qt_mac_event_remove(EventRef &event)
-{
- if (event) {
- if (IsEventInQueue(GetMainEventQueue(), event))
- RemoveEventFromQueue(GetMainEventQueue(), event);
- qt_mac_event_release(event);
- return true;
- }
- return false;
-}
-#endif
/* sheets */
-#ifndef QT_MAC_USE_COCOA
-static EventRef request_showsheet_pending = 0;
-#endif
void qt_event_request_showsheet(QWidget *w)
{
Q_ASSERT(qt_mac_is_macsheet(w));
-#ifdef QT_MAC_USE_COCOA
[NSApp beginSheet:qt_mac_window_for(w) modalForWindow:qt_mac_window_for(w->parentWidget())
modalDelegate:nil didEndSelector:nil contextInfo:0];
-#else
- qt_mac_event_remove(request_showsheet_pending);
- CreateEvent(0, kEventClassQt, kEventQtRequestShowSheet, GetCurrentEventTime(),
- kEventAttributeUserEvent, &request_showsheet_pending);
- SetEventParameter(request_showsheet_pending, kEventParamQWidget, typeQWidget, sizeof(w), &w);
- PostEventToQueue(GetMainEventQueue(), request_showsheet_pending, kEventPriorityStandard);
-#endif
}
static void qt_post_window_change_event(QWidget *widget)
@@ -770,37 +669,7 @@ void qt_mac_send_posted_gl_updates(QWidget *widget)
*/
static void qt_mac_update_intersected_gl_widgets(QWidget *widget)
{
-#ifndef QT_MAC_USE_COCOA
- QList<QWidgetPrivate::GlWidgetInfo> &glWidgets = qt_widget_private(widget->window())->glWidgets;
- if (glWidgets.isEmpty())
- return;
-
- // Exit if the window has not been created yet (mapToGlobal/size will force create it)
- if (widget->testAttribute(Qt::WA_WState_Created) == false || HIViewGetWindow(qt_mac_nativeview_for(widget)) == 0)
- return;
-
- const QRect globalWidgetRect = QRect(widget->mapToGlobal(QPoint(0, 0)), widget->size());
-
- QList<QWidgetPrivate::GlWidgetInfo>::iterator end = glWidgets.end();
- QList<QWidgetPrivate::GlWidgetInfo>::iterator it = glWidgets.begin();
-
- for (;it != end; ++it){
- QWidget *glWidget = it->widget;
- const QRect globalGlWidgetRect = QRect(glWidget->mapToGlobal(QPoint(0, 0)), glWidget->size());
- if (globalWidgetRect.intersects(globalGlWidgetRect)) {
- qt_post_window_change_event(glWidget);
- it->lastUpdateWidget = widget;
- } else if (it->lastUpdateWidget == widget) {
- // Update the gl wigets that the widget intersected the last time around,
- // and that we are not intersecting now. This prevents paint errors when the
- // intersecting widget leaves a gl widget.
- qt_post_window_change_event(glWidget);
- it->lastUpdateWidget = 0;
- }
- }
-#else
Q_UNUSED(widget);
-#endif
}
/*
@@ -888,46 +757,13 @@ void qt_event_request_activate(QWidget *w)
/* menubars */
-#ifndef QT_MAC_USE_COCOA
-static EventRef request_menubarupdate_pending = 0;
-#endif
void qt_event_request_menubarupdate()
{
-#ifndef QT_MAC_USE_COCOA
- if (request_menubarupdate_pending) {
- if (IsEventInQueue(GetMainEventQueue(), request_menubarupdate_pending))
- return;
-#ifdef DEBUG_DROPPED_EVENTS
- qDebug("%s:%d Whoa, we dropped an event on the floor!", __FILE__, __LINE__);
-#endif
- }
-
- CreateEvent(0, kEventClassQt, kEventQtRequestMenubarUpdate, GetCurrentEventTime(),
- kEventAttributeUserEvent, &request_menubarupdate_pending);
- PostEventToQueue(GetMainEventQueue(), request_menubarupdate_pending, kEventPriorityHigh);
-#else
// Just call this. The request has the benefit that we don't call this multiple times, but
// we can optimize this.
QMenuBar::macUpdateMenuBar();
-#endif
}
-#ifndef QT_MAC_USE_COCOA
-//context menu
-static EventRef request_context_pending = 0;
-static void qt_event_request_context(QWidget *w=0, EventRef *where=0)
-{
- if (!where)
- where = &request_context_pending;
- if (*where)
- return;
- CreateEvent(0, kEventClassQt, kEventQtRequestContext, GetCurrentEventTime(),
- kEventAttributeUserEvent, where);
- if (w)
- SetEventParameter(*where, kEventParamQWidget, typeQWidget, sizeof(w), &w);
- PostEventToQueue(GetMainEventQueue(), *where, kEventPriorityStandard);
-}
-#endif
void QApplicationPrivate::createEventDispatcher()
{
@@ -941,13 +777,6 @@ void QApplicationPrivate::createEventDispatcher()
/* clipboard */
void qt_event_send_clipboard_changed()
{
-#ifndef QT_MAC_USE_COCOA
- AppleEvent ae;
- if (AECreateAppleEvent(kEventClassQt, typeAEClipboardChanged, 0, kAutoGenerateReturnID, kAnyTransactionID, &ae) != noErr)
- qDebug("Can't happen!!");
- AppleEvent reply;
- AESend(&ae, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, 0, 0);
-#endif
}
/* app menu */
@@ -955,28 +784,16 @@ static QMenu *qt_mac_dock_menu = 0;
Q_GUI_EXPORT void qt_mac_set_dock_menu(QMenu *menu)
{
qt_mac_dock_menu = menu;
-#ifdef QT_MAC_USE_COCOA
[NSApp setDockMenu:menu->macMenu()];
-#else
- SetApplicationDockTileMenu(menu->macMenu());
-#endif
}
/* events that hold pointers to widgets, must be cleaned up like this */
void qt_mac_event_release(QWidget *w)
{
if (w) {
-#ifndef QT_MAC_USE_COCOA
- qt_mac_event_release(w, request_showsheet_pending);
- qt_mac_event_release(w, request_context_pending);
-#endif
if (w == qt_mac_dock_menu) {
qt_mac_dock_menu = 0;
-#ifndef QT_MAC_USE_COCOA
- SetApplicationDockTileMenu(0);
-#else
[NSApp setDockMenu:0];
-#endif
}
}
}
@@ -990,62 +807,6 @@ struct QMacAppleEventTypeSpec {
{ kInternetEventClass, kAEGetURL },
};
-#ifndef QT_MAC_USE_COCOA
-
-#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
-enum
-{
- kEventMouseScroll = 11,
- kEventParamMouseWheelSmoothVerticalDelta = 'saxy',
- kEventParamMouseWheelSmoothHorizontalDelta = 'saxx',
-};
-#endif
-
-/* watched events */
-static EventTypeSpec app_events[] = {
- { kEventClassQt, kEventQtRequestWindowChange },
- { kEventClassQt, kEventQtRequestShowSheet },
- { kEventClassQt, kEventQtRequestContext },
- { kEventClassQt, kEventQtRequestActivate },
- { kEventClassQt, kEventQtRequestMenubarUpdate },
-
- { kEventClassWindow, kEventWindowActivated },
- { kEventClassWindow, kEventWindowDeactivated },
-
- { kEventClassMouse, kEventMouseScroll },
- { kEventClassMouse, kEventMouseWheelMoved },
- { kEventClassMouse, kEventMouseDown },
- { kEventClassMouse, kEventMouseUp },
- { kEventClassMouse, kEventMouseDragged },
- { kEventClassMouse, kEventMouseMoved },
-
- { kEventClassTablet, kEventTabletProximity },
-
- { kEventClassApplication, kEventAppActivated },
- { kEventClassApplication, kEventAppDeactivated },
- { kEventClassApplication, kEventAppAvailableWindowBoundsChanged },
-
- // { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent },
- { kEventClassKeyboard, kEventRawKeyModifiersChanged },
- { kEventClassKeyboard, kEventRawKeyRepeat },
- { kEventClassKeyboard, kEventRawKeyUp },
- { kEventClassKeyboard, kEventRawKeyDown },
-
- { kEventClassCommand, kEventCommandProcess },
-
- { kEventClassAppleEvent, kEventAppleEvent },
-
- { kAppearanceEventClass, kAEAppearanceChanged }
-};
-
-void qt_init_app_proc_handler()
-{
- InstallEventHandler(GetApplicationEventTarget(), app_proc_handlerUPP,
- GetEventTypeCount(app_events), app_events, (void *)qApp,
- &app_proc_handler);
-}
-#endif // QT_MAC_USE_COCOA
-
static void qt_init_tablet_proximity_handler()
{
EventTypeSpec tabletProximityEvent = { kEventClassTablet, kEventTabletProximity };
@@ -1075,12 +836,6 @@ QString QApplicationPrivate::appName() const
void qt_release_app_proc_handler()
{
-#ifndef QT_MAC_USE_COCOA
- if (app_proc_handler) {
- RemoveEventHandler(app_proc_handler);
- app_proc_handler = 0;
- }
-#endif
}
void qt_color_profile_changed(CFNotificationCenterRef, void *, CFStringRef, const void *,
@@ -1211,13 +966,6 @@ void qt_init(QApplicationPrivate *priv, int)
if (QApplication::desktopSettingsAware())
qt_mac_update_os_settings();
-#ifndef QT_MAC_USE_COCOA
- if (!app_proc_handler) {
- app_proc_handlerUPP = NewEventHandlerUPP(QApplicationPrivate::globalEventProcessor);
- qt_init_app_proc_handler();
- }
-
-#endif
if (!app_proc_ae_handlerUPP && !QApplication::testAttribute(Qt::AA_MacPluginApplication)) {
app_proc_ae_handlerUPP = AEEventHandlerUPP(QApplicationPrivate::globalAppleEventProcessor);
for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) {
@@ -1241,7 +989,6 @@ void qt_init(QApplicationPrivate *priv, int)
QApplicationPrivate::qt_mac_apply_settings();
// Cocoa application delegate
-#ifdef QT_MAC_USE_COCOA
NSApplication *cocoaApp = [QNSApplication sharedApplication];
qt_redirectNSApplicationSendEvent();
@@ -1266,7 +1013,6 @@ void qt_init(QApplicationPrivate *priv, int)
[newDelegate setMenuLoader:qtMenuLoader];
[qtMenuLoader release];
}
-#endif
// Register for Carbon tablet proximity events on the event monitor target.
// This means that we should receive proximity events even when we aren't the active application.
if (!tablet_proximity_handler) {
@@ -1302,13 +1048,6 @@ void qt_cleanup()
CFNotificationCenterRemoveObserver(center, qApp, kCMDeviceProfilesNotification, 0);
CFNotificationCenterRemoveObserver(center, qApp, kCMDefaultDeviceProfileNotification, 0);
-#ifndef QT_MAC_USE_COCOA
- qt_release_app_proc_handler();
- if (app_proc_handlerUPP) {
- DisposeEventHandlerUPP(app_proc_handlerUPP);
- app_proc_handlerUPP = 0;
- }
-#endif
qt_release_apple_event_handler();
qt_release_tablet_proximity_handler();
if (tablet_proximity_UPP)
@@ -1360,12 +1099,7 @@ void QApplication::setOverrideCursor(const QCursor &cursor)
{
qApp->d_func()->cursor_list.prepend(cursor);
-#ifdef QT_MAC_USE_COCOA
qt_mac_update_cursor();
-#else
- if (qApp && qApp->activeWindow())
- qt_mac_set_cursor(&qApp->d_func()->cursor_list.first());
-#endif
}
void QApplication::restoreOverrideCursor()
@@ -1374,24 +1108,12 @@ void QApplication::restoreOverrideCursor()
return;
qApp->d_func()->cursor_list.removeFirst();
-#ifdef QT_MAC_USE_COCOA
qt_mac_update_cursor();
-#else
- if (qApp && qApp->activeWindow()) {
- const QCursor def(Qt::ArrowCursor);
- qt_mac_set_cursor(qApp->d_func()->cursor_list.isEmpty() ? &def : &qApp->d_func()->cursor_list.first());
- }
-#endif
}
#endif // QT_NO_CURSOR
QWidget *QApplication::topLevelAt(const QPoint &p)
{
-#ifndef QT_MAC_USE_COCOA
- QWidget *widget;
- qt_mac_window_at(p.x(), p.y(), &widget);
- return widget;
-#else
// Use a cache to avoid iterate through the whole list of windows for all
// calls to to topLevelAt. We e.g. do this for each and every mouse
// move since we need to find the widget under mouse:
@@ -1440,7 +1162,6 @@ QWidget *QApplication::topLevelAt(const QPoint &p)
topLevelAt_cache = 0;
return 0;
-#endif
}
/*****************************************************************************
@@ -1452,8 +1173,6 @@ bool QApplicationPrivate::modalState()
return app_do_modal;
}
-#ifdef QT_MAC_USE_COCOA
-#endif
void QApplicationPrivate::enterModal_sys(QWidget *widget)
{
@@ -1474,10 +1193,8 @@ void QApplicationPrivate::enterModal_sys(QWidget *widget)
app_do_modal = true;
qt_button_down = 0;
-#ifdef QT_MAC_USE_COCOA
if (!qt_mac_is_macsheet(widget))
QEventDispatcherMacPrivate::beginModalSession(widget);
-#endif
}
void QApplicationPrivate::leaveModal_sys(QWidget *widget)
@@ -1500,10 +1217,8 @@ void QApplicationPrivate::leaveModal_sys(QWidget *widget)
dispatchEnterLeave(w, qt_last_mouse_receiver); // send synthetic enter event
qt_last_mouse_receiver = w;
}
-#ifdef QT_MAC_USE_COCOA
if (!qt_mac_is_macsheet(widget))
QEventDispatcherMacPrivate::endModalSession(widget);
-#endif
}
#ifdef DEBUG_MODAL_EVENTS
else qDebug("Failure to remove %s::%s::%p -- %p", widget->metaObject()->className(), widget->objectName().toLocal8Bit().constData(), widget, qt_modal_stack);
@@ -1515,52 +1230,9 @@ void QApplicationPrivate::leaveModal_sys(QWidget *widget)
QWidget *QApplicationPrivate::tryModalHelper_sys(QWidget *top)
{
-#ifndef QT_MAC_USE_COCOA
- if(top && qt_mac_is_macsheet(top) && !IsWindowVisible(qt_mac_window_for(top))) {
- if(OSWindowRef wp = GetFrontWindowOfClass(kSheetWindowClass, true)) {
- if(QWidget *sheet = qt_mac_find_window(wp))
- top = sheet;
- }
- }
-#endif
return top;
}
-#ifndef QT_MAC_USE_COCOA
-static bool qt_try_modal(QWidget *widget, EventRef event)
-{
- QWidget * top = 0;
-
- if (QApplicationPrivate::tryModalHelper(widget, &top))
- return true;
-
- // INVARIANT: widget is modally shaddowed within its
- // window, and should therefore not handle the event.
- // However, if the window is not active, the event
- // might suggest that we should bring it to front:
-
- bool block_event = false;
-
- if (event) {
- switch (GetEventClass(event)) {
- case kEventClassMouse:
- case kEventClassKeyboard:
- block_event = true;
- break;
- }
- }
-
- QWidget *activeWidget = QApplication::activeWindow();
- if ((!activeWidget || QApplicationPrivate::isBlockedByModal(activeWidget)) &&
- top->isWindow() && block_event && !QApplicationPrivate::native_modal_dialog_active)
- top->raise();
-
-#ifdef DEBUG_MODAL_EVENTS
- qDebug("%s:%d -- final decision! (%s)", __FILE__, __LINE__, block_event ? "false" : "true");
-#endif
- return !block_event;
-}
-#endif
OSStatus QApplicationPrivate::tabletProximityCallback(EventHandlerCallRef, EventRef carbonEvent,
void *)
@@ -1581,910 +1253,12 @@ OSStatus QApplicationPrivate::tabletProximityCallback(EventHandlerCallRef, Event
OSStatus
QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event, void *data)
{
-#ifndef QT_MAC_USE_COCOA
- QApplication *app = (QApplication *)data;
- QScopedLoopLevelCounter loopLevelCounter(app->d_func()->threadData);
- long result;
- if (app->filterEvent(&event, &result))
- return result;
- if(app->macEventFilter(er, event)) //someone else ate it
- return noErr;
- QPointer<QWidget> widget;
-
- /*We assume all events are handled and in
- the code below we set it to false when we know we didn't handle it, this
- will let rogue events through (shouldn't really happen, but better safe
- than sorry) */
- bool handled_event=true;
- UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
- switch(eclass)
- {
- case kEventClassQt:
- if(ekind == kEventQtRequestShowSheet) {
- request_showsheet_pending = 0;
- QWidget *widget = 0;
- GetEventParameter(event, kEventParamQWidget, typeQWidget, 0,
- sizeof(widget), 0, &widget);
- if(widget) {
- if (widget->macEvent(er, event))
- return noErr;
- WindowPtr window = qt_mac_window_for(widget);
- bool just_show = !qt_mac_is_macsheet(widget);
- if(!just_show) {
- OSStatus err = ShowSheetWindow(window, qt_mac_window_for(widget->parentWidget()));
- if(err != noErr)
- qWarning("Qt: QWidget: Unable to show as sheet %s::%s [%ld]", widget->metaObject()->className(),
- widget->objectName().toLocal8Bit().constData(), long(err));
- just_show = true;
- }
- if(just_show) //at least the window will be visible, but the sheet flag doesn't work sadly (probalby too many sheets)
- ShowHide(window, true);
- }
- } else if(ekind == kEventQtRequestWindowChange) {
- qt_mac_event_release(request_window_change_pending);
- } else if(ekind == kEventQtRequestMenubarUpdate) {
- qt_mac_event_release(request_menubarupdate_pending);
- QMenuBar::macUpdateMenuBar();
- } else if(ekind == kEventQtRequestActivate) {
- qt_mac_event_release(request_activate_pending.event);
- if(request_activate_pending.widget) {
- QWidget *tlw = request_activate_pending.widget->window();
- if (tlw->macEvent(er, event))
- return noErr;
- request_activate_pending.widget = 0;
- tlw->activateWindow();
- SelectWindow(qt_mac_window_for(tlw));
- }
- } else if(ekind == kEventQtRequestContext) {
- bool send = false;
- if ((send = (event == request_context_pending)))
- qt_mac_event_release(request_context_pending);
- if(send) {
- //figure out which widget to send it to
- QPoint where = QCursor::pos();
- QWidget *widget = 0;
- GetEventParameter(event, kEventParamQWidget, typeQWidget, 0,
- sizeof(widget), 0, &widget);
- if(!widget) {
- if(qt_button_down)
- widget = qt_button_down;
- else
- widget = QApplication::widgetAt(where.x(), where.y());
- }
- if(widget && !isBlockedByModal(widget)) {
- if (widget->macEvent(er, event))
- return noErr;
- QPoint plocal(widget->mapFromGlobal(where));
- const Qt::KeyboardModifiers keyboardModifiers = qt_mac_get_modifiers(GetCurrentEventKeyModifiers());
- QContextMenuEvent qme(QContextMenuEvent::Mouse, plocal, where, keyboardModifiers);
- QApplication::sendEvent(widget, &qme);
- if(qme.isAccepted()) { //once this happens the events before are pitched
- qt_button_down = 0;
- qt_mac_dblclick.last_widget = 0;
- }
- } else {
- handled_event = false;
- }
- }
- } else {
- handled_event = false;
- }
- break;
- case kEventClassTablet:
- switch (ekind) {
- case kEventTabletProximity:
- // Get the current point of the device and its unique ID.
- ::TabletProximityRec proxRec;
- GetEventParameter(event, kEventParamTabletProximityRec, typeTabletProximityRec, 0,
- sizeof(proxRec), 0, &proxRec);
- qt_dispatchTabletProximityEvent(proxRec);
- }
- break;
- case kEventClassMouse:
- {
- static const int kEventParamQAppSeenMouseEvent = 'QASM';
- // Check if we've seen the event, if we have we shouldn't process
- // it again as it may lead to spurious "double events"
- bool seenEvent;
- if (GetEventParameter(event, kEventParamQAppSeenMouseEvent,
- typeBoolean, 0, sizeof(bool), 0, &seenEvent) == noErr) {
- if (seenEvent)
- return eventNotHandledErr;
- }
- seenEvent = true;
- SetEventParameter(event, kEventParamQAppSeenMouseEvent, typeBoolean,
- sizeof(bool), &seenEvent);
-
- Point where;
- bool inNonClientArea = false;
- GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0,
- sizeof(where), 0, &where);
-#if defined(DEBUG_MOUSE_MAPS)
- const char *edesc = 0;
- switch(ekind) {
- case kEventMouseDown: edesc = "MouseButtonPress"; break;
- case kEventMouseUp: edesc = "MouseButtonRelease"; break;
- case kEventMouseDragged: case kEventMouseMoved: edesc = "MouseMove"; break;
- case kEventMouseScroll: edesc = "MouseWheelScroll"; break;
- case kEventMouseWheelMoved: edesc = "MouseWheelMove"; break;
- }
- if(ekind == kEventMouseDown || ekind == kEventMouseUp)
- qDebug("Handling mouse: %s", edesc);
-#endif
- QEvent::Type etype = QEvent::None;
- Qt::KeyboardModifiers modifiers;
- {
- UInt32 mac_modifiers = 0;
- GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, 0,
- sizeof(mac_modifiers), 0, &mac_modifiers);
- modifiers = qt_mac_get_modifiers(mac_modifiers);
- }
- Qt::MouseButtons buttons;
- {
- UInt32 mac_buttons = 0;
- GetEventParameter(event, kEventParamMouseChord, typeUInt32, 0,
- sizeof(mac_buttons), 0, &mac_buttons);
- if (ekind != kEventMouseWheelMoved)
- buttons = qt_mac_get_buttons(mac_buttons);
- else
- buttons = QApplication::mouseButtons();
- }
-
- int wheel_deltaX = 0;
- int wheel_deltaY = 0;
- static EventRef compatibilityEvent = 0;
-
- if (ekind == kEventMouseScroll) {
- // kEventMouseScroll is the new way of dealing with mouse wheel
- // events (kEventMouseWheelMoved was the old). kEventMouseScroll results
- // in much smoother scrolling when using Mighty Mouse or TrackPad. For
- // compatibility with older applications, carbon will also send us
- // kEventMouseWheelMoved events if we dont eat this event
- // (actually two events; one for horizontal and one for vertical).
- // As a results of this, and to make sure we dont't receive duplicate events,
- // we try to detect when this happend by checking the 'compatibilityEvent'.
- // Since delta is delivered as pixels rather than degrees, we need to
- // convert from pixels to degrees in a sensible manner.
- // It looks like 1/4 degrees per pixel behaves most native.
- // (NB: Qt expects the unit for delta to be 8 per degree):
- const int pixelsToDegrees = 2;
- SInt32 mdelt = 0;
- GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0,
- sizeof(mdelt), 0, &mdelt);
- wheel_deltaX = mdelt * pixelsToDegrees;
- mdelt = 0;
- GetEventParameter(event, kEventParamMouseWheelSmoothVerticalDelta, typeSInt32, 0,
- sizeof(mdelt), 0, &mdelt);
- wheel_deltaY = mdelt * pixelsToDegrees;
- GetEventParameter(event, kEventParamEventRef, typeEventRef, 0,
- sizeof(compatibilityEvent), 0, &compatibilityEvent);
- } else if (ekind == kEventMouseWheelMoved) {
- if (event != compatibilityEvent) {
- compatibilityEvent = 0;
- int mdelt = 0;
- GetEventParameter(event, kEventParamMouseWheelDelta, typeSInt32, 0,
- sizeof(mdelt), 0, &mdelt);
- EventMouseWheelAxis axis;
- GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, 0,
- sizeof(axis), 0, &axis);
-
- // Remove acceleration, and use either -120 or 120 as delta:
- if (axis == kEventMouseWheelAxisX)
- wheel_deltaX = qBound(-120, int(mdelt * 10000), 120);
- else
- wheel_deltaY = qBound(-120, int(mdelt * 10000), 120);
- }
- }
-
- Qt::MouseButton button = Qt::NoButton;
- if(ekind == kEventMouseDown || ekind == kEventMouseUp) {
- EventMouseButton mac_button = 0;
- GetEventParameter(event, kEventParamMouseButton, typeMouseButton, 0,
- sizeof(mac_button), 0, &mac_button);
- button = qt_mac_get_button(mac_button);
- }
-
- switch(ekind) {
- case kEventMouseDown:
- etype = QEvent::MouseButtonPress;
- break;
- case kEventMouseUp:
- etype = QEvent::MouseButtonRelease;
- break;
- case kEventMouseDragged:
- case kEventMouseMoved:
- etype = QEvent::MouseMove;
- break;
- }
-
- const bool inPopupMode = app->d_func()->inPopupMode();
-
- // A click outside a popup closes the popup. Make sure
- // that no events are generated for the release part of that click.
- // (The press goes to the popup and closes it.)
- if (etype == QEvent::MouseButtonPress) {
- qt_mac_previous_press_in_popup_mode = inPopupMode;
- } else if (qt_mac_previous_press_in_popup_mode && !inPopupMode && etype == QEvent::MouseButtonRelease) {
- qt_mac_previous_press_in_popup_mode = false;
- handled_event = true;
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to qt_mac_previous_press_in_popup_mode");
-#endif
- break; // break from case kEventClassMouse
- }
-
- //figure out which widget to send it to
- if(inPopupMode) {
- QWidget *popup = qApp->activePopupWidget();
- if (qt_button_down && qt_button_down->window() == popup) {
- widget = qt_button_down;
- } else {
- QPoint pos = popup->mapFromGlobal(QPoint(where.h, where.v));
- widget = popup->childAt(pos);
- }
- if(!widget)
- widget = popup;
- } else {
- if(mac_mouse_grabber) {
- widget = mac_mouse_grabber;
- } else if (qt_button_down) {
- widget = qt_button_down;
- } else {
- {
- WindowPtr window = 0;
- if(GetEventParameter(event, kEventParamWindowRef, typeWindowRef, 0,
- sizeof(window), 0, &window) != noErr)
- FindWindowOfClass(&where, kAllWindowClasses, &window, 0);
- if(window) {
- HIViewRef hiview;
- if(HIViewGetViewForMouseEvent(HIViewGetRoot(window), event, &hiview) == noErr) {
- widget = QWidget::find((WId)hiview);
- if (widget) {
- // Make sure we didn't pass over a widget with a "fake hole" in it.
- QWidget *otherWidget = QApplication::widgetAt(where.h, where.v);
- if (otherWidget && otherWidget->testAttribute(Qt::WA_MouseNoMask))
- widget = otherWidget;
- }
- }
- }
- }
- if(!widget) //fallback
- widget = QApplication::widgetAt(where.h, where.v);
- if(ekind == kEventMouseUp && widget) {
- short part = qt_mac_window_at(where.h, where.v);
- if(part == inDrag) {
- UInt32 count = 0;
- GetEventParameter(event, kEventParamClickCount, typeUInt32, NULL,
- sizeof(count), NULL, &count);
- if(count == 2 && qt_mac_collapse_on_dblclick) {
- if (widget->macEvent(er, event))
- return noErr;
- widget->setWindowState(widget->windowState() | Qt::WindowMinimized);
- //we send a hide to be like X11/Windows
- QEvent e(QEvent::Hide);
- QApplication::sendSpontaneousEvent(widget, &e);
- break;
- }
- }
- }
- }
- }
- if (widget && widget->macEvent(er, event))
- return noErr;
- WindowPartCode wpc = qt_mac_window_at(where.h, where.v, 0);
- if (wpc == inProxyIcon && modifiers == Qt::ControlModifier && buttons != Qt::NoButton) {
- QIconDragEvent e;
- QApplication::sendSpontaneousEvent(widget, &e);
- if (e.isAccepted()) {
- return noErr; // IconDrag ate it.
- }
- }
- if (inPopupMode == false
- && (qt_button_down == 0 || qt_button_down_in_content == false)
- && (wpc != inContent && wpc != inStructure)) {
- inNonClientArea = true;
- switch (etype) {
- case QEvent::MouseButtonPress: {
- UInt32 count = 0;
- GetEventParameter(event, kEventParamClickCount, typeUInt32, 0,
- sizeof(count), 0, &count);
- if(count % 2 || count == 0) {
- etype = QEvent::NonClientAreaMouseButtonPress;
- } else {
- etype = QEvent::NonClientAreaMouseButtonDblClick;
- }} break;
- case QEvent::MouseButtonRelease:
- etype = QEvent::NonClientAreaMouseButtonRelease;
- break;
- case QEvent::MouseMove:
- if (widget == 0 || widget->hasMouseTracking())
- etype = QEvent::NonClientAreaMouseMove;
- break;
- default:
- break;
- }
- }
-
- if(qt_mac_find_window((FrontWindow()))) { //set the cursor up
- QCursor cursor(Qt::ArrowCursor);
- QWidget *cursor_widget = widget;
- if(cursor_widget && cursor_widget == qt_button_down && ekind == kEventMouseUp)
- cursor_widget = QApplication::widgetAt(where.h, where.v);
- if(cursor_widget) { //only over the app, do we set a cursor..
- if(!qApp->d_func()->cursor_list.isEmpty()) {
- cursor = qApp->d_func()->cursor_list.first();
- } else {
- for(; cursor_widget; cursor_widget = cursor_widget->parentWidget()) {
- QWExtra *extra = cursor_widget->d_func()->extraData();
- if(extra && extra->curs && cursor_widget->isEnabled()) {
- cursor = *extra->curs;
- break;
- }
- }
- }
- }
- qt_mac_set_cursor(&cursor);
- }
-
- //This mouse button state stuff looks like this on purpose
- //although it looks hacky it is VERY intentional..
- if(widget && app_do_modal && !qt_try_modal(widget, event)) {
- if(ekind == kEventMouseDown && qt_mac_is_macsheet(QApplication::activeModalWidget()))
- QApplication::activeModalWidget()->parentWidget()->activateWindow(); //sheets have a parent
- handled_event = false;
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to qt_try_modal");
-#endif
- break;
- }
-
- UInt32 tabletEventType = 0;
- GetEventParameter(event, kEventParamTabletEventType, typeUInt32, 0,
- sizeof(tabletEventType), 0, &tabletEventType);
- if (tabletEventType == kEventTabletPoint) {
- TabletPointRec tabletPointRec;
- GetEventParameter(event, kEventParamTabletPointRec, typeTabletPointRec, 0,
- sizeof(tabletPointRec), 0, &tabletPointRec);
- QEvent::Type t = QEvent::TabletMove; //default
- int new_tablet_button_state = tabletPointRec.buttons ? 1 : 0;
- if (new_tablet_button_state != tablet_button_state)
- if (new_tablet_button_state)
- t = QEvent::TabletPress;
- else
- t = QEvent::TabletRelease;
- tablet_button_state = new_tablet_button_state;
-
- QMacTabletHash *tabletHash = qt_mac_tablet_hash();
- if (!tabletHash->contains(tabletPointRec.deviceID) && t != QEvent::TabletRelease) {
- // Never discard TabletRelease events as they may be delivered *after* TabletLeaveProximity events
- qWarning("handleTabletEvent: This tablet device is unknown"
- " (received no proximity event for it). Discarding event.");
- return false;
- }
- QTabletDeviceData &deviceData = tabletHash->operator[](tabletPointRec.deviceID);
- if (t == QEvent::TabletPress) {
- deviceData.widgetToGetPress = widget;
- } else if (t == QEvent::TabletRelease && deviceData.widgetToGetPress) {
- widget = deviceData.widgetToGetPress;
- deviceData.widgetToGetPress = 0;
- }
-
- if (widget) {
- int tiltX = ((int)tabletPointRec.tiltX)/(32767/64); // 32K -> 60
- int tiltY = ((int)tabletPointRec.tiltY)/(-32767/64); // 32K -> 60
- HIPoint hiPoint;
- GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, 0, sizeof(HIPoint), 0, &hiPoint);
- QPointF hiRes(hiPoint.x, hiPoint.y);
- QPoint global(where.h, where.v);
-
-
-
- QPoint local(widget->mapFromGlobal(global));
- int z = 0;
- qreal rotation = 0.0;
- qreal tp = 0.0;
- // Again from the Wacom.h header
-
- if (deviceData.capabilityMask & 0x0200) // Z-axis
- z = tabletPointRec.absZ;
-
- if (deviceData.capabilityMask & 0x0800) // Tangential pressure
- tp = tabletPointRec.tangentialPressure / 32767.0;
-
- if (deviceData.capabilityMask & 0x2000) // Rotation
- rotation = qreal(tabletPointRec.rotation) / 64.0;
-
- QTabletEvent e(t, local, global, hiRes, deviceData.tabletDeviceType,
- deviceData.tabletPointerType,
- qreal(tabletPointRec.pressure / qreal(0xffff)), tiltX, tiltY,
- tp, rotation, z, modifiers, deviceData.tabletUniqueID);
- QApplication::sendSpontaneousEvent(widget, &e);
- if (e.isAccepted()) {
- if (t == QEvent::TabletPress) {
- qt_button_down = widget;
- } else if (t == QEvent::TabletRelease) {
- qt_button_down = 0;
- }
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to tablet acceptance");
-#endif
- break;
- }
- }
- }
-
- if(ekind == kEventMouseDown) {
- qt_mac_no_click_through_mode = false;
- const short windowPart = qt_mac_window_at(where.h, where.v, 0);
- // Menubar almost always wins.
- if (!inPopupMode && windowPart == inMenuBar) {
- MenuSelect(where); //allow menu tracking
- return noErr;
- }
-
- if (widget && !(GetCurrentKeyModifiers() & cmdKey)) {
- extern bool qt_isGenuineQWidget(const QWidget *); // qwidget_mac.cpp
- QWidget *window = widget->window();
- bool genuineQtWidget = qt_isGenuineQWidget(widget); // the widget, not the window.
- window->raise();
-
- bool needActivate = (window->windowType() != Qt::Desktop)
- && (window->windowType() != Qt::Popup)
- && !qt_mac_is_macsheet(window);
- if (needActivate && (!window->isModal() && qobject_cast<QDockWidget *>(window)))
- needActivate = false;
-
- if (genuineQtWidget && needActivate)
- needActivate = !window->isActiveWindow()
- || !IsWindowActive(qt_mac_window_for(window));
-
- if (needActivate) {
- window->activateWindow();
- if (!qt_mac_can_clickThrough(widget)) {
- qt_mac_no_click_through_mode = true;
- handled_event = false;
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to qt_mac_canClickThrough %s::%s", widget->metaObject()->className(),
- widget->objectName().toLocal8Bit().constData());
-#endif
- break;
- }
- }
- }
-
- if(qt_mac_dblclick.last_widget &&
- qt_mac_dblclick.last_x != -1 && qt_mac_dblclick.last_y != -1 &&
- QRect(qt_mac_dblclick.last_x-2, qt_mac_dblclick.last_y-2, 4, 4).contains(QPoint(where.h, where.v))) {
- if(qt_mac_dblclick.use_qt_time_limit) {
- EventTime now = GetEventTime(event);
- if(qt_mac_dblclick.last_time != -2 && qt_mac_dblclick.last_widget == widget &&
- now - qt_mac_dblclick.last_time <= ((double)QApplicationPrivate::mouse_double_click_time)/1000 &&
- qt_mac_dblclick.last_button == button)
- etype = QEvent::MouseButtonDblClick;
- } else {
- UInt32 count = 0;
- GetEventParameter(event, kEventParamClickCount, typeUInt32, 0,
- sizeof(count), 0, &count);
- if(!(count % 2) && qt_mac_dblclick.last_modifiers == modifiers &&
- qt_mac_dblclick.last_widget == widget && qt_mac_dblclick.last_button == button)
- etype = QEvent::MouseButtonDblClick;
- }
- if(etype == QEvent::MouseButtonDblClick)
- qt_mac_dblclick.last_widget = 0;
- }
- if(etype != QEvent::MouseButtonDblClick) {
- qt_mac_dblclick.last_x = where.h;
- qt_mac_dblclick.last_y = where.v;
- } else {
- qt_mac_dblclick.last_x = qt_mac_dblclick.last_y = -1;
- }
- } else if(qt_mac_no_click_through_mode) {
- if(ekind == kEventMouseUp)
- qt_mac_no_click_through_mode = false;
- handled_event = false;
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to qt_mac_no_click_through_mode");
-#endif
- break;
- }
-
- QPointer<QWidget> leaveAfterRelease = 0;
- switch(ekind) {
- case kEventMouseUp:
- if (!buttons) {
- if (!inPopupMode && !QWidget::mouseGrabber())
- leaveAfterRelease = qt_button_down;
- qt_button_down = 0;
- }
- break;
- case kEventMouseDown: {
- if (!qt_button_down)
- qt_button_down = widget;
- WindowPartCode wpc = qt_mac_window_at(where.h, where.v, 0);
- qt_button_down_in_content = (wpc == inContent || wpc == inStructure);
- break; }
- }
-
- // Check if we should send enter/leave events:
- switch(ekind) {
- case kEventMouseDragged:
- case kEventMouseMoved:
- case kEventMouseUp:
- case kEventMouseDown: {
- // If we are in popup mode, widget will point to the current popup no matter
- // where the mouse cursor is. In that case find out if the mouse cursor is
- // really over the popup in order to send correct enter / leave envents.
- QWidget * const enterLeaveWidget = (inPopupMode || ekind == kEventMouseUp) ?
- QApplication::widgetAt(where.h, where.v) : static_cast<QWidget*>(widget);
-
- if ((QWidget *) qt_last_mouse_receiver != enterLeaveWidget || inNonClientArea) {
-#ifdef DEBUG_MOUSE_MAPS
- qDebug("Entering: %p - %s (%s), Leaving %s (%s)", (QWidget*)enterLeaveWidget,
- enterLeaveWidget ? enterLeaveWidget->metaObject()->className() : "none",
- enterLeaveWidget ? enterLeaveWidget->objectName().toLocal8Bit().constData() : "",
- qt_last_mouse_receiver ? qt_last_mouse_receiver->metaObject()->className() : "none",
- qt_last_mouse_receiver ? qt_last_mouse_receiver->objectName().toLocal8Bit().constData() : "");
-#endif
-
- QWidget * const mouseGrabber = QWidget::mouseGrabber();
-
- if (inPopupMode) {
- QWidget *enter = enterLeaveWidget;
- QWidget *leave = qt_last_mouse_receiver;
- if (mouseGrabber) {
- QWidget * const popupWidget = qApp->activePopupWidget();
- if (leave == popupWidget)
- enter = mouseGrabber;
- if (enter == popupWidget)
- leave = mouseGrabber;
- if ((enter == mouseGrabber && leave == popupWidget)
- || (leave == mouseGrabber && enter == popupWidget)) {
- QApplicationPrivate::dispatchEnterLeave(enter, leave);
- qt_last_mouse_receiver = enter;
- }
- } else {
- QApplicationPrivate::dispatchEnterLeave(enter, leave);
- qt_last_mouse_receiver = enter;
- }
- } else if ((!qt_button_down || !qt_last_mouse_receiver) && !mouseGrabber && !leaveAfterRelease) {
- QApplicationPrivate::dispatchEnterLeave(enterLeaveWidget, qt_last_mouse_receiver);
- qt_last_mouse_receiver = enterLeaveWidget;
- }
- }
- break; }
- }
-
- if(widget) {
- QPoint p(where.h, where.v);
- QPoint plocal(widget->mapFromGlobal(p));
- if(etype == QEvent::MouseButtonPress) {
- qt_mac_dblclick.last_widget = widget;
- qt_mac_dblclick.last_modifiers = modifiers;
- qt_mac_dblclick.last_button = button;
- qt_mac_dblclick.last_time = GetEventTime(event);
- }
-
- if (wheel_deltaX || wheel_deltaY) {
-#ifndef QT_NO_WHEELEVENT
- if (wheel_deltaX) {
- QWheelEvent qwe(plocal, p, wheel_deltaX, buttons, modifiers, Qt::Horizontal);
- QApplication::sendSpontaneousEvent(widget, &qwe);
- if (!qwe.isAccepted() && QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget != widget) {
- QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(p), p,
- wheel_deltaX, buttons, modifiers, Qt::Horizontal);
- QApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2);
- if (!qwe2.isAccepted())
- handled_event = false;
- }
- }
- if (wheel_deltaY) {
- QWheelEvent qwe(plocal, p, wheel_deltaY, buttons, modifiers, Qt::Vertical);
- QApplication::sendSpontaneousEvent(widget, &qwe);
- if (!qwe.isAccepted() && QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget != widget) {
- QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(p), p,
- wheel_deltaY, buttons, modifiers, Qt::Vertical);
- QApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2);
- if (!qwe2.isAccepted())
- handled_event = false;
- }
- }
-#endif // QT_NO_WHEELEVENT
- } else {
-#ifdef QMAC_SPEAK_TO_ME
- const int speak_keys = Qt::AltModifier | Qt::ShiftModifier;
- if(etype == QMouseEvent::MouseButtonDblClick && ((modifiers & speak_keys) == speak_keys)) {
- QVariant v = widget->property("displayText");
- if(!v.isValid()) v = widget->property("text");
- if(!v.isValid()) v = widget->property("windowTitle");
- if(v.isValid()) {
- QString s = v.toString();
- s.replace(QRegExp(QString::fromLatin1("(\\&|\\<[^\\>]*\\>)")), QLatin1String(""));
- SpeechChannel ch;
- NewSpeechChannel(0, &ch);
- SpeakText(ch, s.toLatin1().constData(), s.length());
- DisposeSpeechChannel(ch);
- }
- }
-#endif
- Qt::MouseButton buttonToSend = button;
- static bool lastButtonTranslated = false;
- if(ekind == kEventMouseDown &&
- button == Qt::LeftButton && (modifiers & Qt::MetaModifier)) {
- buttonToSend = Qt::RightButton;
- lastButtonTranslated = true;
- } else if(ekind == kEventMouseUp && lastButtonTranslated) {
- buttonToSend = Qt::RightButton;
- lastButtonTranslated = false;
- }
- QMouseEvent qme(etype, plocal, p, buttonToSend, buttons, modifiers);
- QApplication::sendSpontaneousEvent(widget, &qme);
- if(!qme.isAccepted() || inNonClientArea)
- handled_event = false;
- }
-
- if (leaveAfterRelease) {
- QWidget *enter = QApplication::widgetAt(where.h, where.v);
- QApplicationPrivate::dispatchEnterLeave(enter, leaveAfterRelease);
- qt_last_mouse_receiver = enter;
- leaveAfterRelease = 0;
- }
-
- if(ekind == kEventMouseDown &&
- ((button == Qt::RightButton) ||
- (button == Qt::LeftButton && (modifiers & Qt::MetaModifier))))
- qt_event_request_context();
-
-#ifdef DEBUG_MOUSE_MAPS
- const char *event_desc = edesc;
- if(etype == QEvent::MouseButtonDblClick)
- event_desc = "Double Click";
- else if(etype == QEvent::NonClientAreaMouseButtonPress)
- event_desc = "NonClientMousePress";
- else if(etype == QEvent::NonClientAreaMouseButtonRelease)
- event_desc = "NonClientMouseRelease";
- else if(etype == QEvent::NonClientAreaMouseMove)
- event_desc = "NonClientMouseMove";
- else if(etype == QEvent::NonClientAreaMouseButtonDblClick)
- event_desc = "NonClientMouseDblClick";
- qDebug("%d %d (%d %d) - Would send (%s) event to %p %s %s (%d 0x%08x 0x%08x %d)", p.x(), p.y(),
- plocal.x(), plocal.y(), event_desc, (QWidget*)widget,
- widget ? widget->objectName().toLocal8Bit().constData() : "*Unknown*",
- widget ? widget->metaObject()->className() : "*Unknown*",
- button, (int)buttons, (int)modifiers, wheel_deltaX);
-#endif
- } else {
- handled_event = false;
- }
- break;
- }
- case kEventClassTextInput:
- case kEventClassKeyboard: {
- EventRef key_event = event;
- if(eclass == kEventClassTextInput) {
- Q_ASSERT(ekind == kEventTextInputUnicodeForKeyEvent);
- OSStatus err = GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, typeEventRef, 0,
- sizeof(key_event), 0, &key_event);
- Q_ASSERT(err == noErr);
- Q_UNUSED(err);
- }
- const UInt32 key_ekind = GetEventKind(key_event);
- Q_ASSERT(GetEventClass(key_event) == kEventClassKeyboard);
-
- if(key_ekind == kEventRawKeyDown)
- qt_keymapper_private()->updateKeyMap(er, key_event, data);
- if(mac_keyboard_grabber)
- widget = mac_keyboard_grabber;
- else if (app->activePopupWidget())
- widget = (app->activePopupWidget()->focusWidget() ?
- app->activePopupWidget()->focusWidget() : app->activePopupWidget());
- else if(QApplication::focusWidget())
- widget = QApplication::focusWidget();
- else
- widget = app->activeWindow();
-
- if (widget) {
- if (widget->macEvent(er, event))
- return noErr;
- } else {
- // Darn, I need to update tho modifier state, even though
- // Qt itself isn't getting them, otherwise the keyboard state get inconsistent.
- if (key_ekind == kEventRawKeyModifiersChanged) {
- UInt32 modifiers = 0;
- GetEventParameter(key_event, kEventParamKeyModifiers, typeUInt32, 0,
- sizeof(modifiers), 0, &modifiers);
- extern void qt_mac_send_modifiers_changed(quint32 modifiers, QObject *object); // qkeymapper_mac.cpp
- // Just send it to the qApp for the time being.
- qt_mac_send_modifiers_changed(modifiers, qApp);
- }
- handled_event = false;
- break;
- }
-
- if(app_do_modal && !qt_try_modal(widget, key_event))
- break;
- if (eclass == kEventClassTextInput) {
- handled_event = false;
- } else {
- handled_event = qt_keymapper_private()->translateKeyEvent(widget, er, key_event, data,
- widget == mac_keyboard_grabber);
- }
- break; }
- case kEventClassWindow: {
- WindowRef wid = 0;
- GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0,
- sizeof(WindowRef), 0, &wid);
- widget = qt_mac_find_window(wid);
- if (widget && widget->macEvent(er, event))
- return noErr;
- if(ekind == kEventWindowActivated) {
- if(QApplicationPrivate::app_style) {
- QEvent ev(QEvent::Style);
- QApplication::sendSpontaneousEvent(QApplicationPrivate::app_style, &ev);
- }
-
- if(widget && app_do_modal && !qt_try_modal(widget, event))
- break;
-
- if(widget && widget->window()->isVisible()) {
- QWidget *tlw = widget->window();
- if(tlw->isWindow() && !(tlw->windowType() == Qt::Popup)
- && !qt_mac_is_macdrawer(tlw)
- && (!tlw->parentWidget() || tlw->isModal()
- || !(tlw->windowType() == Qt::Tool))) {
- bool just_send_event = false;
- {
- WindowActivationScope scope;
- if(GetWindowActivationScope((WindowRef)wid, &scope) == noErr &&
- scope == kWindowActivationScopeIndependent) {
- if(GetFrontWindowOfClass(kAllWindowClasses, true) != wid)
- just_send_event = true;
- }
- }
- if(just_send_event) {
- QEvent e(QEvent::WindowActivate);
- QApplication::sendSpontaneousEvent(widget, &e);
- } else {
- app->setActiveWindow(tlw);
- }
- }
- QMenuBar::macUpdateMenuBar();
- }
- } else if(ekind == kEventWindowDeactivated) {
- if(widget && QApplicationPrivate::active_window == widget)
- app->setActiveWindow(0);
- } else {
- handled_event = false;
- }
- break; }
- case kEventClassApplication:
- if(ekind == kEventAppActivated) {
- if(QApplication::desktopSettingsAware())
- qt_mac_update_os_settings();
- if(qt_clipboard) { //manufacture an event so the clipboard can see if it has changed
- QEvent ev(QEvent::Clipboard);
- QApplication::sendSpontaneousEvent(qt_clipboard, &ev);
- }
- if(app) {
- QEvent ev(QEvent::ApplicationActivate);
- QApplication::sendSpontaneousEvent(app, &ev);
- }
- if(!app->activeWindow()) {
- WindowPtr wp = ActiveNonFloatingWindow();
- if(QWidget *tmp_w = qt_mac_find_window(wp))
- app->setActiveWindow(tmp_w);
- }
- QMenuBar::macUpdateMenuBar();
- } else if(ekind == kEventAppDeactivated) {
- //qt_mac_no_click_through_mode = false;
- while(app->d_func()->inPopupMode())
- app->activePopupWidget()->close();
- if(app) {
- QEvent ev(QEvent::ApplicationDeactivate);
- QApplication::sendSpontaneousEvent(app, &ev);
- }
- app->setActiveWindow(0);
- } else if(ekind == kEventAppAvailableWindowBoundsChanged) {
- QDesktopWidgetImplementation::instance()->onResize();
- } else {
- handled_event = false;
- }
- break;
- case kAppearanceEventClass:
- if(ekind == kAEAppearanceChanged) {
- if(QApplication::desktopSettingsAware())
- qt_mac_update_os_settings();
- if(QApplicationPrivate::app_style) {
- QEvent ev(QEvent::Style);
- QApplication::sendSpontaneousEvent(QApplicationPrivate::app_style, &ev);
- }
- } else {
- handled_event = false;
- }
- break;
- case kEventClassAppleEvent:
- if(ekind == kEventAppleEvent) {
- EventRecord erec;
- if(!ConvertEventRefToEventRecord(event, &erec))
- qDebug("Qt: internal: WH0A, unexpected condition reached. %s:%d", __FILE__, __LINE__);
- else if(AEProcessAppleEvent(&erec) != noErr)
- handled_event = false;
- } else {
- handled_event = false;
- }
- break;
- case kEventClassCommand:
- if(ekind == kEventCommandProcess) {
- HICommand cmd;
- GetEventParameter(event, kEventParamDirectObject, typeHICommand,
- 0, sizeof(cmd), 0, &cmd);
- handled_event = false;
- if(!cmd.menu.menuRef && GetApplicationDockTileMenu()) {
- EventRef copy = CopyEvent(event);
- HICommand copy_cmd;
- GetEventParameter(event, kEventParamDirectObject, typeHICommand,
- 0, sizeof(copy_cmd), 0, &copy_cmd);
- copy_cmd.menu.menuRef = GetApplicationDockTileMenu();
- SetEventParameter(copy, kEventParamDirectObject, typeHICommand, sizeof(copy_cmd), &copy_cmd);
- if(SendEventToMenu(copy, copy_cmd.menu.menuRef) == noErr)
- handled_event = true;
- }
- if(!handled_event) {
- if(cmd.commandID == kHICommandQuit) {
- // Quitting the application is not Qt's responsibility if
- // used in a plugin or just embedded into a native application.
- // In that case, let the event pass down to the native apps event handler.
- if (!QApplication::testAttribute(Qt::AA_MacPluginApplication)) {
- handled_event = true;
- HiliteMenu(0);
- bool handle_quit = true;
- if(QApplicationPrivate::modalState()) {
- int visible = 0;
- const QWidgetList tlws = QApplication::topLevelWidgets();
- for(int i = 0; i < tlws.size(); ++i) {
- if(tlws.at(i)->isVisible())
- ++visible;
- }
- handle_quit = (visible <= 1);
- }
- if(handle_quit) {
- QCloseEvent ev;
- QApplication::sendSpontaneousEvent(app, &ev);
- if(ev.isAccepted())
- app->quit();
- } else {
- QApplication::beep();
- }
- }
- } else if(cmd.commandID == kHICommandSelectWindow) {
- if((GetCurrentKeyModifiers() & cmdKey))
- handled_event = true;
- } else if(cmd.commandID == kHICommandAbout) {
- QMessageBox::aboutQt(0);
- HiliteMenu(0);
- handled_event = true;
- }
- }
- }
- break;
- }
-
-#ifdef DEBUG_EVENTS
- qDebug("%shandled event %c%c%c%c %d", handled_event ? "(*) " : "",
- char(eclass >> 24), char((eclass >> 16) & 255), char((eclass >> 8) & 255),
- char(eclass & 255), (int)ekind);
-#endif
- if(!handled_event) //let the event go through
- return eventNotHandledErr;
- return noErr; //we eat the event
-#else
Q_UNUSED(er);
Q_UNUSED(event);
Q_UNUSED(data);
return eventNotHandledErr;
-#endif
}
-#ifdef QT_MAC_USE_COCOA
void QApplicationPrivate::qt_initAfterNSAppStarted()
{
setupAppleEvents();
@@ -2511,7 +1285,6 @@ void QApplicationPrivate::setupAppleEvents()
[eventManager setEventHandler:newDelegate andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}
-#endif
// In Carbon this is your one stop for apple events.
// In Cocoa, it ISN'T. This is the catch-all Apple Event handler that exists
@@ -3013,15 +1786,8 @@ bool QApplicationPrivate::qt_mac_apply_settings()
bool QApplicationPrivate::canQuit()
{
-#ifndef QT_MAC_USE_COCOA
- return true;
-#else
Q_Q(QApplication);
-#ifdef QT_MAC_USE_COCOA
[[NSApp mainMenu] cancelTracking];
-#else
- HiliteMenu(0);
-#endif
bool handle_quit = true;
if (QApplicationPrivate::modalState() && [[[[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate]
@@ -3042,12 +1808,10 @@ bool QApplicationPrivate::canQuit()
}
}
return false;
-#endif
}
void onApplicationWindowChangedActivation(QWidget *widget, bool activated)
{
-#if QT_MAC_USE_COCOA
if (!widget)
return;
@@ -3064,16 +1828,11 @@ void onApplicationWindowChangedActivation(QWidget *widget, bool activated)
QMenuBar::macUpdateMenuBar();
qt_mac_update_cursor();
-#else
- Q_UNUSED(widget);
- Q_UNUSED(activated);
-#endif
}
void onApplicationChangedActivation( bool activated )
{
-#if QT_MAC_USE_COCOA
QApplication *app = qApp;
//NSLog(@"App Changed Activation\n");
@@ -3109,9 +1868,6 @@ void onApplicationChangedActivation( bool activated )
}
app->setActiveWindow(0);
}
-#else
- Q_UNUSED(activated);
-#endif
}
void QApplicationPrivate::initializeMultitouch_sys()
diff --git a/src/widgets/platforms/mac/qclipboard_mac.cpp b/src/widgets/platforms/mac/qclipboard_mac.cpp
index 002b8da967..b8a4d2915d 100644
--- a/src/widgets/platforms/mac/qclipboard_mac.cpp
+++ b/src/widgets/platforms/mac/qclipboard_mac.cpp
@@ -388,7 +388,6 @@ QMacPasteboard::setMimeData(QMimeData *mime_src)
clear_helper();
QStringList formats = mime_src->formats();
-#ifdef QT_MAC_USE_COCOA
// QMimeData sub classes reimplementing the formats() might not expose the
// temporary "application/x-qt-mime-type-name" mimetype. So check the existence
// of this mime type while doing drag and drop.
@@ -399,7 +398,6 @@ QMacPasteboard::setMimeData(QMimeData *mime_src)
formats.append(dummyMimeType);
}
}
-#endif
for(int f = 0; f < formats.size(); ++f) {
QString mimeType = formats.at(f);
for (QList<QMacPasteboardMime *>::Iterator it = availableConverters.begin(); it != availableConverters.end(); ++it) {
diff --git a/src/widgets/platforms/mac/qcocoaintrospection_mac.mm b/src/widgets/platforms/mac/qcocoaintrospection_mac.mm
index ed2fbeaeda..7388f5a4e9 100644
--- a/src/widgets/platforms/mac/qcocoaintrospection_mac.mm
+++ b/src/widgets/platforms/mac/qcocoaintrospection_mac.mm
@@ -79,9 +79,6 @@ QT_BEGIN_NAMESPACE
void qt_cocoa_change_implementation(Class baseClass, SEL originalSel, Class proxyClass, SEL replacementSel, SEL backupSel)
{
-#ifndef QT_MAC_USE_COCOA
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5)
-#endif
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
// The following code replaces the _implementation_ for the selector we want to hack
@@ -110,9 +107,6 @@ void qt_cocoa_change_implementation(Class baseClass, SEL originalSel, Class prox
void qt_cocoa_change_back_implementation(Class baseClass, SEL originalSel, SEL backupSel)
{
-#ifndef QT_MAC_USE_COCOA
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5)
-#endif
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
Method originalMethod = class_getInstanceMethod(baseClass, originalSel);
diff --git a/src/widgets/platforms/mac/qcocoapanel_mac.mm b/src/widgets/platforms/mac/qcocoapanel_mac.mm
index 5b490cf8b4..2dca64d5ff 100644
--- a/src/widgets/platforms/mac/qcocoapanel_mac.mm
+++ b/src/widgets/platforms/mac/qcocoapanel_mac.mm
@@ -40,7 +40,6 @@
****************************************************************************/
#import <private/qcocoapanel_mac_p.h>
-#ifdef QT_MAC_USE_COCOA
#import <private/qt_cocoa_helpers_mac_p.h>
#import <private/qcocoawindow_mac_p.h>
#import <private/qcocoawindowdelegate_mac_p.h>
@@ -67,4 +66,3 @@ QT_USE_NAMESPACE
#include "qcocoasharedwindowmethods_mac_p.h"
@end
-#endif
diff --git a/src/widgets/platforms/mac/qcocoapanel_mac_p.h b/src/widgets/platforms/mac/qcocoapanel_mac_p.h
index ad02b16657..43282be7c6 100644
--- a/src/widgets/platforms/mac/qcocoapanel_mac_p.h
+++ b/src/widgets/platforms/mac/qcocoapanel_mac_p.h
@@ -54,7 +54,6 @@
#define QCOCOAPANEL_MAC_P
#include "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
#import <Cocoa/Cocoa.h>
QT_FORWARD_DECLARE_CLASS(QStringList);
@@ -78,6 +77,5 @@ QT_FORWARD_DECLARE_CLASS(QCocoaDropData);
- (void)drawRectOriginal:(NSRect)rect;
@end
-#endif
#endif
diff --git a/src/widgets/platforms/mac/qcocoaview_mac.mm b/src/widgets/platforms/mac/qcocoaview_mac.mm
index 6c5e05b32a..61a5ee10ff 100644
--- a/src/widgets/platforms/mac/qcocoaview_mac.mm
+++ b/src/widgets/platforms/mac/qcocoaview_mac.mm
@@ -40,7 +40,6 @@
****************************************************************************/
#import <private/qcocoaview_mac_p.h>
-#ifdef QT_MAC_USE_COCOA
#include <private/qwidget_p.h>
#include <private/qt_mac_p.h>
@@ -1385,4 +1384,3 @@ Qt::DropAction QDragManager::drag(QDrag *o)
QT_END_NAMESPACE
-#endif // QT_MAC_USE_COCOA
diff --git a/src/widgets/platforms/mac/qcocoaview_mac_p.h b/src/widgets/platforms/mac/qcocoaview_mac_p.h
index 963cbe06bf..928e489abe 100644
--- a/src/widgets/platforms/mac/qcocoaview_mac_p.h
+++ b/src/widgets/platforms/mac/qcocoaview_mac_p.h
@@ -51,7 +51,6 @@
//
#include <qevent.h>
-#ifdef QT_MAC_USE_COCOA
#import <Cocoa/Cocoa.h>
@class QT_MANGLE_NAMESPACE(QCocoaView);
@@ -84,4 +83,3 @@ Q_WIDGETS_EXPORT
- (void) qt_clearQWidget;
@end
-#endif
diff --git a/src/widgets/platforms/mac/qcocoawindow_mac.mm b/src/widgets/platforms/mac/qcocoawindow_mac.mm
index fba69a3263..730504f672 100644
--- a/src/widgets/platforms/mac/qcocoawindow_mac.mm
+++ b/src/widgets/platforms/mac/qcocoawindow_mac.mm
@@ -40,7 +40,6 @@
****************************************************************************/
#include "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
#import <private/qcocoawindow_mac_p.h>
#import <private/qcocoawindowdelegate_mac_p.h>
#import <private/qcocoaview_mac_p.h>
@@ -87,4 +86,3 @@ QT_USE_NAMESPACE
#include "qcocoasharedwindowmethods_mac_p.h"
@end
-#endif
diff --git a/src/widgets/platforms/mac/qcocoawindow_mac_p.h b/src/widgets/platforms/mac/qcocoawindow_mac_p.h
index 9013f66080..704e6bd01c 100644
--- a/src/widgets/platforms/mac/qcocoawindow_mac_p.h
+++ b/src/widgets/platforms/mac/qcocoawindow_mac_p.h
@@ -53,7 +53,6 @@
#ifndef QCOCOAWINDOW_MAC_P
#define QCOCOAWINDOW_MAC_P
-#ifdef QT_MAC_USE_COCOA
#include "qmacdefines_mac.h"
#import <Cocoa/Cocoa.h>
#include <private/qapplication_p.h>
@@ -92,6 +91,5 @@ QT_FORWARD_DECLARE_CLASS(QCocoaDropData);
- (void)drawRectOriginal:(NSRect)rect;
@end
-#endif
#endif
diff --git a/src/widgets/platforms/mac/qcocoawindowcustomthemeframe_mac.mm b/src/widgets/platforms/mac/qcocoawindowcustomthemeframe_mac.mm
index cc255420b5..9e3b4cfee7 100644
--- a/src/widgets/platforms/mac/qcocoawindowcustomthemeframe_mac.mm
+++ b/src/widgets/platforms/mac/qcocoawindowcustomthemeframe_mac.mm
@@ -41,7 +41,6 @@
#include "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
#import "private/qcocoawindowcustomthemeframe_mac_p.h"
#import "private/qcocoawindow_mac_p.h"
@@ -59,4 +58,3 @@
@end
-#endif
diff --git a/src/widgets/platforms/mac/qcocoawindowdelegate_mac.mm b/src/widgets/platforms/mac/qcocoawindowdelegate_mac.mm
index 772fd2bfc7..44fb9b6eba 100644
--- a/src/widgets/platforms/mac/qcocoawindowdelegate_mac.mm
+++ b/src/widgets/platforms/mac/qcocoawindowdelegate_mac.mm
@@ -40,7 +40,6 @@
****************************************************************************/
#import "private/qcocoawindowdelegate_mac_p.h"
-#ifdef QT_MAC_USE_COCOA
#include <private/qwidget_p.h>
#include <private/qapplication_p.h>
#include <private/qt_cocoa_helpers_mac_p.h>
@@ -436,4 +435,3 @@ static void cleanupCocoaWindowDelegate()
}
@end
-#endif// QT_MAC_USE_COCOA
diff --git a/src/widgets/platforms/mac/qcocoawindowdelegate_mac_p.h b/src/widgets/platforms/mac/qcocoawindowdelegate_mac_p.h
index a510ae48ed..261d1d192a 100644
--- a/src/widgets/platforms/mac/qcocoawindowdelegate_mac_p.h
+++ b/src/widgets/platforms/mac/qcocoawindowdelegate_mac_p.h
@@ -52,7 +52,6 @@
#include "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
#import <Cocoa/Cocoa.h>
QT_BEGIN_NAMESPACE
@@ -107,4 +106,3 @@ QT_FORWARD_DECLARE_CLASS(QWidgetData)
- (QWidget *)qt_qwidgetForWindow:(NSWindow *)window;
- (void)syncContentViewFrame: (NSNotification *)notification;
@end
-#endif
diff --git a/src/widgets/platforms/mac/qcursor_mac.mm b/src/widgets/platforms/mac/qcursor_mac.mm
index 0b0abaa8c6..4247e186e9 100644
--- a/src/widgets/platforms/mac/qcursor_mac.mm
+++ b/src/widgets/platforms/mac/qcursor_mac.mm
@@ -107,33 +107,8 @@ static QCursorData *currentCursor = 0; //current cursor
void qt_mac_set_cursor(const QCursor *c)
{
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
[static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(*c)) set];
-#else
- if (!c) {
- currentCursor = 0;
- return;
- }
- c->handle(); //force the cursor to get loaded, if it's not
-
- if(currentCursor && currentCursor->type == QCursorData::TYPE_ThemeCursor
- && currentCursor->curs.tc.anim)
- currentCursor->curs.tc.anim->stop();
- if(c->d->type == QCursorData::TYPE_ImageCursor) {
- [static_cast<NSCursor *>(c->d->curs.cp.nscursor) set];
- } else if(c->d->type == QCursorData::TYPE_ThemeCursor) {
- if(SetAnimatedThemeCursor(c->d->curs.tc.curs, 0) == themeBadCursorIndexErr) {
- SetThemeCursor(c->d->curs.tc.curs);
- } else {
- if(!c->d->curs.tc.anim)
- c->d->curs.tc.anim = new QMacAnimateCursor;
- c->d->curs.tc.anim->start(c->d->curs.tc.curs);
- }
- }
-
- currentCursor = c->d;
-#endif
}
static QPointer<QWidget> lastWidgetUnderMouse = 0;
@@ -186,16 +161,12 @@ void qt_mac_updateCursorWithWidgetUnderMouse(QWidget *widgetUnderMouse)
}
}
-#ifdef QT_MAC_USE_COCOA
cursor.d->update();
NSCursor *nsCursor = static_cast<NSCursor *>(cursor.d->curs.cp.nscursor);
if ([NSCursor currentCursor] != nsCursor) {
QMacCocoaAutoReleasePool pool;
[nsCursor set];
}
-#else
- qt_mac_set_cursor(&cursor);
-#endif
}
void qt_mac_update_cursor()
@@ -206,7 +177,6 @@ void qt_mac_update_cursor()
// application has been deactivated/activated etc.
// NB: since we dont have any true native widget, the call to
// qt_mac_getTargetForMouseEvent will fail when the mouse is over QMacNativeWidgets.
-#ifdef QT_MAC_USE_COCOA
lastWidgetUnderMouse = 0;
lastMouseCursorWidget = 0;
QWidget *widgetUnderMouse = 0;
@@ -219,9 +189,6 @@ void qt_mac_update_cursor()
qt_mac_getTargetForMouseEvent(0, QEvent::None, localPoint, globalPoint, 0, &widgetUnderMouse);
}
qt_mac_updateCursorWithWidgetUnderMouse(widgetUnderMouse);
-#else
- qt_mac_updateCursorWithWidgetUnderMouse(QApplication::widgetAt(QCursor::pos()));
-#endif
}
void qt_mac_setMouseGrabCursor(bool set, QCursor *const cursor = 0)
@@ -241,12 +208,6 @@ void qt_mac_setMouseGrabCursor(bool set, QCursor *const cursor = 0)
qt_mac_update_cursor();
}
-#ifndef QT_MAC_USE_COCOA
-void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos)
-{
- qt_mac_updateCursorWithWidgetUnderMouse(QApplication::widgetAt(globalPos));
-}
-#endif
static int nextCursorId = Qt::BitmapCursor;
@@ -314,7 +275,6 @@ QPoint QCursor::pos()
void QCursor::setPos(int x, int y)
{
-#ifdef QT_MAC_USE_COCOA
CGPoint pos;
pos.x = x;
pos.y = y;
@@ -322,24 +282,6 @@ void QCursor::setPos(int x, int y)
CGEventRef e = CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, 0);
CGEventPost(kCGHIDEventTap, e);
CFRelease(e);
-#else
- CGWarpMouseCursorPosition(CGPointMake(x, y));
-
- /* I'm not too keen on doing this, but this makes it a lot easier, so I just
- send the event back through the event system and let it get propagated correctly
- ideally this would not really need to be faked --Sam
- */
- QWidget *widget = 0;
- if(QWidget *grb = QWidget::mouseGrabber())
- widget = grb;
- else
- widget = QApplication::widgetAt(QPoint(x, y));
- if(widget) {
- QMouseEvent me(QMouseEvent::MouseMove, widget->mapFromGlobal(QPoint(x, y)), Qt::NoButton,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- qt_sendSpontaneousEvent(widget, &me);
- }
-#endif
}
void QCursorData::initCursorFromBitmap()
@@ -453,7 +395,6 @@ void QCursorData::update()
#endif
const uchar *cursorData = 0;
const uchar *cursorMaskData = 0;
-#ifdef QT_MAC_USE_COCOA
switch (cshape) { // map Q cursor to MAC cursor
case Qt::BitmapCursor: {
if (pixmap.isNull())
@@ -561,114 +502,6 @@ void QCursorData::update()
qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape);
return;
}
-#else
- // Carbon
- switch (cshape) { // map Q cursor to MAC cursor
- case Qt::BitmapCursor: {
- if (pixmap.isNull())
- initCursorFromBitmap();
- else
- initCursorFromPixmap();
- break; }
- case Qt::BlankCursor: {
- pixmap = QPixmap(16, 16);
- pixmap.fill(Qt::transparent);
- initCursorFromPixmap();
- break; }
- case Qt::ArrowCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeArrowCursor;
- break; }
- case Qt::CrossCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeCrossCursor;
- break; }
- case Qt::WaitCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeWatchCursor;
- break; }
- case Qt::IBeamCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeIBeamCursor;
- break; }
- case Qt::SizeAllCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemePlusCursor;
- break; }
- case Qt::WhatsThisCursor: { //for now just use the pointing hand
- case Qt::PointingHandCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemePointingHandCursor;
- break; }
- case Qt::BusyCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeSpinningCursor;
- break; }
- case Qt::SplitVCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeResizeUpDownCursor;
- break; }
- case Qt::SplitHCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeResizeLeftRightCursor;
- break; }
- case Qt::ForbiddenCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeNotAllowedCursor;
- break; }
- case Qt::OpenHandCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeOpenHandCursor;
- break;
- case Qt::ClosedHandCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeClosedHandCursor;
- break;
- case Qt::DragMoveCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeArrowCursor;
- break;
- case Qt::DragCopyCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeCopyArrowCursor;
- break;
- case Qt::DragLinkCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeAliasArrowCursor;
- break;
-#define QT_USE_APPROXIMATE_CURSORS
-#ifdef QT_USE_APPROXIMATE_CURSORS
- case Qt::SizeVerCursor:
- cursorData = cur_ver_bits;
- cursorMaskData = mcur_ver_bits;
- hx = hy = 8;
- break;
- case Qt::SizeHorCursor:
- cursorData = cur_hor_bits;
- cursorMaskData = mcur_hor_bits;
- hx = hy = 8;
- break;
- case Qt::SizeBDiagCursor:
- cursorData = cur_fdiag_bits;
- cursorMaskData = mcur_fdiag_bits;
- hx = hy = 8;
- break;
- case Qt::SizeFDiagCursor:
- cursorData = cur_bdiag_bits;
- cursorMaskData = mcur_bdiag_bits;
- hx = hy = 8;
- break;
- case Qt::UpArrowCursor:
- cursorData = cur_up_arrow_bits;
- cursorMaskData = mcur_up_arrow_bits;
- hx = 8;
- break;
-#endif
- default:
- qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape);
- return;
- }
-#endif
if (cursorData) {
bm = new QBitmap(QBitmap::fromData(QSize(16, 16), cursorData,
diff --git a/src/widgets/platforms/mac/qdnd_mac.mm b/src/widgets/platforms/mac/qdnd_mac.mm
index 77926bde23..73acb93f0b 100644
--- a/src/widgets/platforms/mac/qdnd_mac.mm
+++ b/src/widgets/platforms/mac/qdnd_mac.mm
@@ -76,9 +76,6 @@ QMacDndAnswerRecord qt_mac_dnd_answer_rec;
QDnD globals
*****************************************************************************/
bool qt_mac_in_drag = false;
-#ifndef QT_MAC_USE_COCOA
-static DragReference qt_mac_current_dragRef = 0;
-#endif
/*****************************************************************************
Externals
@@ -91,27 +88,6 @@ extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp
QDnD utility functions
*****************************************************************************/
-//default pixmap
-static const int default_pm_hotx = -2;
-static const int default_pm_hoty = -16;
-#ifndef QT_MAC_USE_COCOA
-static const char * const default_pm[] = {
- "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",
-};
-#endif
-
//action management
#ifdef DEBUG_DRAG_EVENTS
# define MAP_MAC_ENUM(x) x, #x
@@ -126,134 +102,26 @@ struct mac_enum_mapper
char *qt_desc;
#endif
};
-#ifndef QT_MAC_USE_COCOA
-static mac_enum_mapper dnd_action_symbols[] = {
- { 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) }
-};
-static DragActions qt_mac_dnd_map_qt_actions(Qt::DropActions qActions)
-{
- DragActions ret = kDragActionNothing;
- for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
- if(qActions & dnd_action_symbols[i].qt_code)
- ret |= dnd_action_symbols[i].mac_code;
- }
- return ret;
-}
-static Qt::DropActions qt_mac_dnd_map_mac_actions(DragActions macActions)
-{
-#ifdef DEBUG_DRAG_EVENTS
- qDebug("Converting DND ActionList: 0x%lx", macActions);
-#endif
- Qt::DropActions ret = Qt::IgnoreAction;
- for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
-#ifdef DEBUG_DRAG_EVENTS
- qDebug(" %d) [%s] : %s", i, dnd_action_symbols[i].qt_desc,
- (macActions & dnd_action_symbols[i].mac_code) ? "true" : "false");
-#endif
- if(macActions & dnd_action_symbols[i].mac_code)
- ret |= Qt::DropAction(dnd_action_symbols[i].qt_code);
- }
- return ret;
-}
-static Qt::DropAction qt_mac_dnd_map_mac_default_action(DragActions macActions)
-{
- static Qt::DropAction preferred_actions[] = { Qt::CopyAction, Qt::LinkAction, //in order
- Qt::MoveAction, Qt::IgnoreAction };
- Qt::DropAction ret = Qt::IgnoreAction;
- const Qt::DropActions qtActions = qt_mac_dnd_map_mac_actions(macActions);
- for(int i = 0; preferred_actions[i] != Qt::IgnoreAction; ++i) {
- if(qtActions & preferred_actions[i]) {
- ret = preferred_actions[i];
- break;
- }
- }
-#ifdef DEBUG_DRAG_EVENTS
- for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
- if(dnd_action_symbols[i].qt_code == ret) {
- qDebug("Got default action: %s [0x%lx]", dnd_action_symbols[i].qt_desc, macActions);
- break;
- }
- }
-#endif
- return ret;
-}
-static void qt_mac_dnd_update_action(DragReference dragRef) {
- SInt16 modifiers;
- GetDragModifiers(dragRef, &modifiers, 0, 0);
- qt_mac_send_modifiers_changed(modifiers, qApp);
-
- Qt::DropAction qtAction = Qt::IgnoreAction;
- {
- DragActions macAllowed = kDragActionNothing;
- GetDragDropAction(dragRef, &macAllowed);
- Qt::DropActions qtAllowed = qt_mac_dnd_map_mac_actions(macAllowed);
- qtAction = QDragManager::self()->defaultAction(qtAllowed, QApplication::keyboardModifiers());
-#if 1
- if(!(qtAllowed & qtAction))
- qtAction = qt_mac_dnd_map_mac_default_action(macAllowed);
-#endif
- }
- DragActions macAction = qt_mac_dnd_map_qt_actions(qtAction);
-
- DragActions currentActions;
- GetDragDropAction(dragRef, &currentActions);
- if(currentActions != macAction) {
- SetDragDropAction(dragRef, macAction);
- QDragManager::self()->emitActionChanged(qtAction);
- }
-}
-#endif // !QT_MAC_USE_COCOA
/*****************************************************************************
DnD functions
*****************************************************************************/
bool QDropData::hasFormat_sys(const QString &mime) const
{
-#ifndef QT_MAC_USE_COCOA
- OSPasteboardRef board;
- if(GetDragPasteboard(qt_mac_current_dragRef, &board) != noErr) {
- qDebug("DnD: Cannot get PasteBoard!");
- return false;
- }
- return QMacPasteboard(board, QMacPasteboardMime::MIME_DND).hasFormat(mime);
-#else
Q_UNUSED(mime);
return false;
-#endif // !QT_MAC_USE_COCOA
}
QVariant QDropData::retrieveData_sys(const QString &mime, QVariant::Type type) const
{
-#ifndef QT_MAC_USE_COCOA
- OSPasteboardRef board;
- if(GetDragPasteboard(qt_mac_current_dragRef, &board) != noErr) {
- qDebug("DnD: Cannot get PasteBoard!");
- return QVariant();
- }
- return QMacPasteboard(board, QMacPasteboardMime::MIME_DND).retrieveData(mime, type);
-#else
Q_UNUSED(mime);
Q_UNUSED(type);
return QVariant();
-#endif // !QT_MAC_USE_COCOA
}
QStringList QDropData::formats_sys() const
{
-#ifndef QT_MAC_USE_COCOA
- OSPasteboardRef board;
- if(GetDragPasteboard(qt_mac_current_dragRef, &board) != noErr) {
- qDebug("DnD: Cannot get PasteBoard!");
- return QStringList();
- }
- return QMacPasteboard(board, QMacPasteboardMime::MIME_DND).formats();
-#else
return QStringList();
-#endif
}
void QDragManager::timerEvent(QTimerEvent*)
@@ -295,18 +163,8 @@ void QDragManager::drop()
*/
static inline bool qt_mac_set_existing_drop_action(const DragRef &dragRef, QDropEvent &event)
{
-#ifndef QT_MAC_USE_COCOA
- DragActions currentAction = kDragActionNothing;
- OSStatus err = GetDragDropAction(dragRef, &currentAction);
- if (err == noErr && currentAction != kDragActionNothing) {
- // This looks a bit evil, but we only ever set one action, so it's OK.
- event.setDropAction(Qt::DropAction(int(qt_mac_dnd_map_mac_actions(currentAction))));
- return true;
- }
-#else
Q_UNUSED(dragRef);
Q_UNUSED(event);
-#endif
return false;
}
@@ -338,361 +196,11 @@ bool qt_mac_mouse_inside_answer_rect(QPoint mouse)
bool QWidgetPrivate::qt_mac_dnd_event(uint kind, DragRef dragRef)
{
-#ifndef QT_MAC_USE_COCOA
- Q_Q(QWidget);
- qt_mac_current_dragRef = dragRef;
- if (kind != kEventControlDragLeave)
- qt_mac_dnd_update_action(dragRef);
-
- Point mouse;
- GetDragMouse(dragRef, &mouse, 0L);
- if(!mouse.h && !mouse.v)
- GetGlobalMouse(&mouse);
-
- if(QApplicationPrivate::modalState()) {
- for(QWidget *modal = q; modal; modal = modal->parentWidget()) {
- if(modal->isWindow()) {
- if(modal != QApplication::activeModalWidget())
- return noErr;
- break;
- }
- }
- }
-
- //lookup the possible actions
- DragActions allowed = kDragActionNothing;
- GetDragAllowableActions(dragRef, &allowed);
- Qt::DropActions qtAllowed = qt_mac_dnd_map_mac_actions(allowed);
-
- //lookup the source dragAccepted
- QMimeData *dropdata = QDragManager::self()->dropData;
- if(QDragManager::self()->source())
- dropdata = QDragManager::self()->dragPrivate()->data;
-
- // 'interrestedInDrag' should end up being 'true' if a later drop
- // will be accepted by the widget for the current mouse position
- bool interrestedInDrag = true;
-
- //Dispatch events
- if (kind == kEventControlDragWithin) {
- if (qt_mac_mouse_inside_answer_rect(q->mapFromGlobal(QPoint(mouse.h, mouse.v))))
- return qt_mac_dnd_answer_rec.lastAction == Qt::IgnoreAction;
- else
- qt_mac_dnd_answer_rec.clear();
-
- QDragMoveEvent qDMEvent(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
-
- // Accept the event by default if a
- // drag action exists on the carbon event
- if (qt_mac_set_existing_drop_action(dragRef, qDMEvent))
- qDMEvent.accept();
-
- QApplication::sendEvent(q, &qDMEvent);
- if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction)
- interrestedInDrag = false;
-
- qt_mac_copy_answer_rect(qDMEvent);
- SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(qDMEvent.dropAction()));
-
- } else if (kind == kEventControlDragEnter) {
- qt_mac_dnd_answer_rec.clear();
-
- QDragEnterEvent qDEEvent(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- qt_mac_set_existing_drop_action(dragRef, qDEEvent);
- QApplication::sendEvent(q, &qDEEvent);
- SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(qDEEvent.dropAction()));
-
- if (!qDEEvent.isAccepted())
- // The widget is simply not interested in this
- // drag. So tell carbon this by returning 'false'. We will then
- // not receive any further move, drop or leave events for this widget.
- return false;
- else {
- // Documentation states that a drag move event is sent immediately after
- // a drag enter event. So we do that. This will honor widgets overriding
- // 'dragMoveEvent' only, and not 'dragEnterEvent'
- QDragMoveEvent qDMEvent(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- qDMEvent.accept(); // accept by default, since enter event was accepted.
- qDMEvent.setDropAction(qDEEvent.dropAction());
- QApplication::sendEvent(q, &qDMEvent);
- if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction)
- interrestedInDrag = false;
-
- qt_mac_copy_answer_rect(qDMEvent);
- SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(qDMEvent.dropAction()));
- }
-
- } else if(kind == kEventControlDragLeave) {
- QDragLeaveEvent de;
- QApplication::sendEvent(q, &de);
- } else if(kind == kEventControlDragReceive) {
- QDropEvent de(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- if(QDragManager::self()->object)
- QDragManager::self()->dragPrivate()->target = q;
- QApplication::sendEvent(q, &de);
- if(!de.isAccepted()) {
- interrestedInDrag = false;
- SetDragDropAction(dragRef, kDragActionNothing);
- } else {
- if(QDragManager::self()->object)
- QDragManager::self()->dragPrivate()->executed_action = de.dropAction();
- SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(de.dropAction()));
- }
- }
-
-#ifdef DEBUG_DRAG_EVENTS
- {
- const char *desc = 0;
- switch(kind) {
- case kEventControlDragWithin: desc = "DragMove"; break;
- case kEventControlDragEnter: desc = "DragEnter"; break;
- case kEventControlDragLeave: desc = "DragLeave"; break;
- case kEventControlDragReceive: desc = "DragDrop"; break;
- }
- if(desc) {
- QPoint pos(q->mapFromGlobal(QPoint(mouse.h, mouse.v)));
- qDebug("Sending <%s>(%d, %d) event to %p(%s::%s) [%d] (%p)",
- desc, pos.x(), pos.y(), q, q->metaObject()->className(),
- q->objectName().toLocal8Bit().constData(), ret, dragRef);
- }
- }
-#endif
-
- //set the cursor
- bool found_cursor = false;
- if(kind == kEventControlDragWithin || kind == kEventControlDragEnter) {
- ThemeCursor cursor = kThemeNotAllowedCursor;
- found_cursor = true;
- if (interrestedInDrag) {
- DragActions action = kDragActionNothing;
- GetDragDropAction(dragRef, &action);
- switch(qt_mac_dnd_map_mac_default_action(action)) {
- case Qt::IgnoreAction:
- cursor = kThemeNotAllowedCursor;
- break;
- case Qt::MoveAction:
- cursor = kThemeArrowCursor;
- break;
- case Qt::CopyAction:
- cursor = kThemeCopyArrowCursor;
- break;
- case Qt::LinkAction:
- cursor = kThemeAliasArrowCursor;
- break;
- default:
- cursor = kThemeNotAllowedCursor;
- break;
- }
- }
- SetThemeCursor(cursor);
- }
- if(found_cursor) {
- qt_mac_set_cursor(0); //just use our's
- } else {
- QCursor cursor(Qt::ArrowCursor);
- if(qApp && qApp->overrideCursor()) {
- cursor = *qApp->overrideCursor();
- } else if(q) {
- for(QWidget *p = q; p; p = p->parentWidget()) {
- if(p->isEnabled() && p->testAttribute(Qt::WA_SetCursor)) {
- cursor = p->cursor();
- break;
- }
- }
- }
- qt_mac_set_cursor(&cursor);
- }
-
- //idle things
- if(qGlobalPostedEventsCount()) {
- QApplication::sendPostedEvents();
- QApplication::flush();
- }
-
- // If this was not a drop, tell carbon that we will be interresed in receiving more
- // events for the current drag. We do that by returning true.
- if (kind == kEventControlDragReceive)
- return interrestedInDrag;
- else
- return true;
-#else
Q_UNUSED(kind);
Q_UNUSED(dragRef);
return false;
-#endif // !QT_MAC_USE_COCOA
}
-#ifndef QT_MAC_USE_COCOA
-Qt::DropAction QDragManager::drag(QDrag *o)
-{
-
- if(qt_mac_in_drag) { //just make sure..
- qWarning("Qt: Internal error: WH0A, unexpected condition reached");
- return Qt::IgnoreAction;
- }
- if(object == o)
- return Qt::IgnoreAction;
- /* At the moment it seems clear that Mac OS X does not want to drag with a non-left button
- so we just bail early to prevent it */
- if(!(GetCurrentEventButtonState() & kEventMouseButtonPrimary))
- return Qt::IgnoreAction;
-
- if(object) {
- dragPrivate()->source->removeEventFilter(this);
- cancel();
- beingCancelled = false;
- }
-
- object = o;
- dragPrivate()->target = 0;
-
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart);
-#endif
-
- //setup the data
- QMacPasteboard dragBoard(QMacPasteboardMime::MIME_DND);
- dragBoard.setMimeData(dragPrivate()->data);
-
- //create the drag
- OSErr result;
- DragRef dragRef;
- if((result = NewDragWithPasteboard(dragBoard.pasteBoard(), &dragRef)))
- return Qt::IgnoreAction;
- //setup the actions
- DragActions possibleActions = qt_mac_dnd_map_qt_actions(dragPrivate()->possible_actions);
- SetDragAllowableActions(dragRef, //local
- possibleActions,
- true);
- SetDragAllowableActions(dragRef, //remote (same as local)
- possibleActions,
- false);
-
-
- QPoint hotspot;
- QPixmap pix = dragPrivate()->pixmap;
- if(pix.isNull()) {
- if(dragPrivate()->data->hasText() || dragPrivate()->data->hasUrls()) {
- //get the string
- QString s = dragPrivate()->data->hasText() ? dragPrivate()->data->text()
- : dragPrivate()->data->urls().first().toString();
- if(s.length() > 26)
- s = s.left(23) + QChar(0x2026);
- if(!s.isEmpty()) {
- //draw it
- QFont f(qApp->font());
- f.setPointSize(12);
- QFontMetrics fm(f);
- const int width = fm.width(s);
- const int height = fm.height();
- if(width > 0 && height > 0) {
- QPixmap tmp(width, height);
- QPainter p(&tmp);
- p.fillRect(0, 0, tmp.width(), tmp.height(), Qt::color0);
- p.setPen(Qt::color1);
- p.setFont(f);
- p.drawText(0, fm.ascent(), s);
- p.end();
- //save it
- pix = tmp;
- hotspot = QPoint(tmp.width() / 2, tmp.height() / 2);
- }
- }
- } else {
- pix = QPixmap(default_pm);
- hotspot = QPoint(default_pm_hotx, default_pm_hoty);
- }
- } else {
- hotspot = dragPrivate()->hotspot;
- }
-
- //so we must fake an event
- EventRecord fakeEvent;
- GetGlobalMouse(&(fakeEvent.where));
- fakeEvent.message = 0;
- fakeEvent.what = mouseDown;
- fakeEvent.when = EventTimeToTicks(GetCurrentEventTime());
- fakeEvent.modifiers = GetCurrentKeyModifiers();
- if(GetCurrentEventButtonState() & 2)
- fakeEvent.modifiers |= controlKey;
-
- //find the hotspot in relation to the pixmap
- Point boundsPoint;
- boundsPoint.h = fakeEvent.where.h - hotspot.x();
- boundsPoint.v = fakeEvent.where.v - hotspot.y();
- Rect boundsRect;
- SetRect(&boundsRect, boundsPoint.h, boundsPoint.v, boundsPoint.h + pix.width(), boundsPoint.v + pix.height());
-
- //set the drag image
- QRegion dragRegion(boundsPoint.h, boundsPoint.v, pix.width(), pix.height()), pixRegion;
- if(!pix.isNull()) {
- HIPoint hipoint = { -hotspot.x(), -hotspot.y() };
- CGImageRef img = (CGImageRef)pix.macCGHandle();
- SetDragImageWithCGImage(dragRef, img, &hipoint, 0);
- CGImageRelease(img);
- }
-
- SetDragItemBounds(dragRef, (ItemReference)1 , &boundsRect);
- { //do the drag
- qt_mac_in_drag = true;
- qt_mac_dnd_update_action(dragRef);
- result = TrackDrag(dragRef, &fakeEvent, QMacSmartQuickDrawRegion(dragRegion.toQDRgn()));
- qt_mac_in_drag = false;
- }
- object = 0;
- if(result == noErr) {
- // Check if the receiver points us to
- // a file location. If so, we need to do
- // the file copy/move ourselves:
- QCFType<CFURLRef> pasteLocation = 0;
- PasteboardCopyPasteLocation(dragBoard.pasteBoard(), &pasteLocation);
- if (pasteLocation){
- Qt::DropAction action = o->d_func()->defaultDropAction;
- if (action == Qt::IgnoreAction){
- if (o->d_func()->possible_actions & Qt::MoveAction)
- action = Qt::MoveAction;
- else if (o->d_func()->possible_actions & Qt::CopyAction)
- action = Qt::CopyAction;
-
- }
- bool atleastOne = false;
- QList<QUrl> urls = o->mimeData()->urls();
- for (int i = 0; i < urls.size(); ++i){
- QUrl fromUrl = urls.at(i);
- QString filename = QFileInfo(fromUrl.path()).fileName();
- QUrl toUrl(QCFString::toQString(CFURLGetString(pasteLocation)) + filename);
- if (action == Qt::MoveAction){
- if (QFile::rename(fromUrl.path(), toUrl.path()))
- atleastOne = true;
- } else if (action == Qt::CopyAction){
- if (QFile::copy(fromUrl.path(), toUrl.path()))
- atleastOne = true;
- }
- }
- if (atleastOne){
- DisposeDrag(dragRef);
- o->setMimeData(0);
- o->deleteLater();
- return action;
- }
- }
-
- DragActions ret = kDragActionNothing;
- GetDragDropAction(dragRef, &ret);
- DisposeDrag(dragRef); //cleanup
- o->setMimeData(0);
- o->deleteLater();
- return qt_mac_dnd_map_mac_default_action(ret);
- }
- DisposeDrag(dragRef); //cleanup
- return Qt::IgnoreAction;
-}
-#endif
-
void QDragManager::updatePixmap()
{
}
diff --git a/src/widgets/platforms/mac/qeventdispatcher_mac.mm b/src/widgets/platforms/mac/qeventdispatcher_mac.mm
index f90fb5a1d5..2a5227c19f 100644
--- a/src/widgets/platforms/mac/qeventdispatcher_mac.mm
+++ b/src/widgets/platforms/mac/qeventdispatcher_mac.mm
@@ -110,11 +110,7 @@ extern bool qt_mac_is_macsheet(const QWidget *); //qwidget_mac.cpp
static inline CFRunLoopRef mainRunLoop()
{
-#ifndef QT_MAC_USE_COCOA
- return reinterpret_cast<CFRunLoopRef>(const_cast<void *>(GetCFRunLoopFromEventLoop(GetMainEventLoop())));
-#else
return CFRunLoopGetMain();
-#endif
}
/*****************************************************************************
@@ -453,20 +449,13 @@ bool QEventDispatcherMac::hasPendingEvents()
static bool qt_mac_send_event(QEventLoop::ProcessEventsFlags, OSEventRef event, OSWindowRef pt)
{
-#ifndef QT_MAC_USE_COCOA
- if(pt && SendEventToWindow(event, pt) != eventNotHandledErr)
- return true;
- return !SendEventToEventTarget(event, GetEventDispatcherTarget());
-#else // QT_MAC_USE_COCOA
if (pt)
[pt sendEvent:event];
else
[NSApp sendEvent:event];
return true;
-#endif
}
-#ifdef QT_MAC_USE_COCOA
static bool IsMouseOrKeyEvent( NSEvent* event )
{
bool result = false;
@@ -510,13 +499,9 @@ static bool IsMouseOrKeyEvent( NSEvent* event )
}
return result;
}
-#endif
static inline void qt_mac_waitForMoreEvents()
{
-#ifndef QT_MAC_USE_COCOA
- while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, true) == kCFRunLoopRunTimedOut) ;
-#else
// If no event exist in the cocoa event que, wait
// (and free up cpu time) until at least one event occur.
// This implementation is a bit on the edge, but seems to
@@ -527,10 +512,8 @@ static inline void qt_mac_waitForMoreEvents()
dequeue:YES];
if (event)
[NSApp postEvent:event atStart:YES];
-#endif
}
-#ifdef QT_MAC_USE_COCOA
static inline void qt_mac_waitForMoreModalSessionEvents()
{
// If no event exist in the cocoa event que, wait
@@ -544,17 +527,14 @@ static inline void qt_mac_waitForMoreModalSessionEvents()
if (event)
[NSApp postEvent:event atStart:YES];
}
-#endif
bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags)
{
Q_D(QEventDispatcherMac);
d->interrupt = false;
-#ifdef QT_MAC_USE_COCOA
bool interruptLater = false;
QtMacInterruptDispatcherHelp::cancelInterruptLater();
-#endif
// In case we end up recursing while we now process events, make sure
// that we send remaining posted Qt events before this call returns:
@@ -567,7 +547,6 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags)
if (d->interrupt)
break;
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
NSEvent* event = 0;
@@ -685,40 +664,6 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags)
// disturb the 'wait for more events' below (as deleteLater will post an event):
interruptLater = true;
}
-#else
- do {
- EventRef event;
- if (!(flags & QEventLoop::ExcludeUserInputEvents)
- && !d->queuedUserInputEvents.isEmpty()) {
- // process a pending user input event
- event = static_cast<EventRef>(d->queuedUserInputEvents.takeFirst());
- } else {
- OSStatus err = ReceiveNextEvent(0,0, kEventDurationNoWait, true, &event);
- if(err != noErr)
- continue;
- // else
- if (flags & QEventLoop::ExcludeUserInputEvents) {
- UInt32 ekind = GetEventKind(event),
- eclass = GetEventClass(event);
- switch(eclass) {
- case kEventClassQt:
- if(ekind != kEventQtRequestContext)
- break;
- // fall through
- case kEventClassMouse:
- case kEventClassKeyboard:
- d->queuedUserInputEvents.append(event);
- continue;
- }
- }
- }
-
- if (!filterEvent(&event) && qt_mac_send_event(flags, event, 0))
- retVal = true;
- ReleaseEvent(event);
- } while(!d->interrupt && GetNumEventsInQueue(GetMainEventQueue()) > 0);
-
-#endif
bool canWait = (d->threadData->canWait
&& !retVal
@@ -744,10 +689,8 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags)
if (d->interrupt)
interrupt();
-#ifdef QT_MAC_USE_COCOA
if (interruptLater)
QtMacInterruptDispatcherHelp::interruptLater();
-#endif
return retVal;
}
@@ -779,7 +722,6 @@ MacTimerHash QEventDispatcherMacPrivate::macTimerHash;
bool QEventDispatcherMacPrivate::blockSendPostedEvents = false;
bool QEventDispatcherMacPrivate::interrupt = false;
-#ifdef QT_MAC_USE_COCOA
QStack<QCocoaModalSessionInfo> QEventDispatcherMacPrivate::cocoaModalSessionStack;
bool QEventDispatcherMacPrivate::currentExecIsNSAppRun = false;
bool QEventDispatcherMacPrivate::nsAppRunCalledByQt = false;
@@ -973,7 +915,6 @@ void QEventDispatcherMacPrivate::endModalSession(QWidget *widget)
}
}
-#endif
QEventDispatcherMacPrivate::QEventDispatcherMacPrivate()
{
@@ -1043,13 +984,10 @@ inline static void processPostedEvents(QEventDispatcherMacPrivate *const d, cons
return;
}
-#ifdef QT_MAC_USE_COCOA
if (d->cleanupModalSessionsNeeded)
d->cleanupModalSessions();
-#endif
if (d->interrupt) {
-#ifdef QT_MAC_USE_COCOA
if (d->currentExecIsNSAppRun) {
// The event dispatcher has been interrupted. But since
// [NSApplication run] is running the event loop, we
@@ -1060,7 +998,6 @@ inline static void processPostedEvents(QEventDispatcherMacPrivate *const d, cons
[NSApp stop:NSApp];
d->cancelWaitForMoreEvents();
}
-#endif
return;
}
@@ -1076,9 +1013,7 @@ void QEventDispatcherMacPrivate::firstLoopEntry(CFRunLoopObserverRef ref,
{
Q_UNUSED(ref);
Q_UNUSED(activity);
-#ifdef QT_MAC_USE_COCOA
QApplicationPrivate::qt_initAfterNSAppStarted();
-#endif
processPostedEvents(static_cast<QEventDispatcherMacPrivate *>(info), blockSendPostedEvents);
}
@@ -1087,7 +1022,6 @@ void QEventDispatcherMacPrivate::postedEventsSourcePerformCallback(void *info)
processPostedEvents(static_cast<QEventDispatcherMacPrivate *>(info), blockSendPostedEvents);
}
-#ifdef QT_MAC_USE_COCOA
void QEventDispatcherMacPrivate::cancelWaitForMoreEvents()
{
// In case the event dispatcher is waiting for more
@@ -1097,7 +1031,6 @@ void QEventDispatcherMacPrivate::cancelWaitForMoreEvents()
modifierFlags:0 timestamp:0. windowNumber:0 context:0
subtype:QtCocoaEventSubTypeWakeup data1:0 data2:0] atStart:NO];
}
-#endif
void QEventDispatcherMac::interrupt()
{
@@ -1105,9 +1038,6 @@ void QEventDispatcherMac::interrupt()
d->interrupt = true;
wakeUp();
-#ifndef QT_MAC_USE_COCOA
- CFRunLoopStop(mainRunLoop());
-#else
// We do nothing more here than setting d->interrupt = true, and
// poke the event loop if it is sleeping. Actually stopping
// NSApp, or the current modal session, is done inside the send
@@ -1116,7 +1046,6 @@ void QEventDispatcherMac::interrupt()
// the last event loop recursion, cocoa will just drop pending posted
// events on the floor before we get a chance to reestablish a new session.
d->cancelWaitForMoreEvents();
-#endif
}
QEventDispatcherMac::~QEventDispatcherMac()
@@ -1156,7 +1085,6 @@ QEventDispatcherMac::~QEventDispatcherMac()
CFRelease(d->firstTimeObserver);
}
-#ifdef QT_MAC_USE_COCOA
QtMacInterruptDispatcherHelp* QtMacInterruptDispatcherHelp::instance = 0;
@@ -1194,7 +1122,6 @@ void QtMacInterruptDispatcherHelp::interruptLater()
instance = new QtMacInterruptDispatcherHelp;
}
-#endif
QT_END_NAMESPACE
diff --git a/src/widgets/platforms/mac/qeventdispatcher_mac_p.h b/src/widgets/platforms/mac/qeventdispatcher_mac_p.h
index f4cf16e8a0..241adf2fce 100644
--- a/src/widgets/platforms/mac/qeventdispatcher_mac_p.h
+++ b/src/widgets/platforms/mac/qeventdispatcher_mac_p.h
@@ -95,14 +95,12 @@
QT_BEGIN_NAMESPACE
-#ifdef QT_MAC_USE_COCOA
typedef struct _NSModalSession *NSModalSession;
typedef struct _QCocoaModalSessionInfo {
QPointer<QWidget> widget;
NSModalSession session;
void *nswindow;
} QCocoaModalSessionInfo;
-#endif
class QEventDispatcherMacPrivate;
@@ -170,7 +168,6 @@ public:
// low-level cocoa functions (like beginModalForWindow). And
// use a QBoolBlocker to be safe:
static bool blockSendPostedEvents;
-#ifdef QT_MAC_USE_COCOA
// The following variables help organizing modal sessions:
static QStack<QCocoaModalSessionInfo> cocoaModalSessionStack;
static bool currentExecIsNSAppRun;
@@ -185,7 +182,6 @@ public:
static void cancelWaitForMoreEvents();
static void cleanupModalSessions();
static void ensureNSAppInitialized();
-#endif
MacSocketHash macSockets;
QList<void *> queuedUserInputEvents; // List of EventRef in Carbon, and NSEvent * in Cocoa
@@ -204,7 +200,6 @@ private:
static void firstLoopEntry(CFRunLoopObserverRef ref, CFRunLoopActivity activity, void *info);
};
-#ifdef QT_MAC_USE_COCOA
class QtMacInterruptDispatcherHelp : public QObject
{
static QtMacInterruptDispatcherHelp *instance;
@@ -217,7 +212,6 @@ class QtMacInterruptDispatcherHelp : public QObject
static void interruptLater();
static void cancelInterruptLater();
};
-#endif
QT_END_NAMESPACE
diff --git a/src/widgets/platforms/mac/qfont_mac.cpp b/src/widgets/platforms/mac/qfont_mac.cpp
index 3bbff7f4bb..4a7692ab94 100644
--- a/src/widgets/platforms/mac/qfont_mac.cpp
+++ b/src/widgets/platforms/mac/qfont_mac.cpp
@@ -100,31 +100,20 @@ void QFont::cleanup()
*/
quint32 QFont::macFontID() const // ### need 64-bit version
{
-#ifdef QT_MAC_USE_COCOA
return 0;
#elif 1
QFontEngine *fe = d->engineForScript(QUnicodeTables::Common);
if (fe && fe->type() == QFontEngine::Multi)
return static_cast<QFontEngineMacMulti*>(fe)->macFontID();
-#else
- Str255 name;
- if(FMGetFontFamilyName((FMFontFamily)((UInt32)handle()), name) == noErr) {
- short fnum;
- GetFNum(name, &fnum);
- return fnum;
- }
-#endif
return 0;
}
// Returns an ATSUFonFamilyRef
Qt::HANDLE QFont::handle() const
{
-#ifdef QT_MAC_USE_COCOA
QFontEngine *fe = d->engineForScript(QUnicodeTables::Common);
if (fe && fe->type() == QFontEngine::Multi)
return (Qt::HANDLE)static_cast<QCoreTextFontEngineMulti*>(fe)->macFontID();
-#endif
return 0;
}
diff --git a/src/widgets/platforms/mac/qfontdatabase_mac.cpp b/src/widgets/platforms/mac/qfontdatabase_mac.cpp
index 6876fae630..bbe6b56966 100644
--- a/src/widgets/platforms/mac/qfontdatabase_mac.cpp
+++ b/src/widgets/platforms/mac/qfontdatabase_mac.cpp
@@ -53,38 +53,6 @@ QT_BEGIN_NAMESPACE
int qt_mac_pixelsize(const QFontDef &def, int dpi); //qfont_mac.cpp
int qt_mac_pointsize(const QFontDef &def, int dpi); //qfont_mac.cpp
-#ifndef QT_MAC_USE_COCOA
-static void initWritingSystems(QtFontFamily *family, ATSFontRef atsFont)
-{
- ByteCount length = 0;
- if (ATSFontGetTable(atsFont, MAKE_TAG('O', 'S', '/', '2'), 0, 0, 0, &length) != noErr)
- return;
- QVarLengthArray<uchar> os2Table(length);
- if (length < 86
- || ATSFontGetTable(atsFont, MAKE_TAG('O', 'S', '/', '2'), 0, length, os2Table.data(), &length) != noErr)
- return;
-
- // See also qfontdatabase_win.cpp, offsets taken from OS/2 table in the TrueType spec
- quint32 unicodeRange[4] = {
- qFromBigEndian<quint32>(os2Table.data() + 42),
- qFromBigEndian<quint32>(os2Table.data() + 46),
- qFromBigEndian<quint32>(os2Table.data() + 50),
- qFromBigEndian<quint32>(os2Table.data() + 54)
- };
- quint32 codePageRange[2] = { qFromBigEndian<quint32>(os2Table.data() + 78), qFromBigEndian<quint32>(os2Table.data() + 82) };
- QList<QFontDatabase::WritingSystem> systems = qt_determine_writing_systems_from_truetype_bits(unicodeRange, codePageRange);
-#if 0
- QCFString name;
- ATSFontGetName(atsFont, kATSOptionFlagsDefault, &name);
- qDebug() << systems.count() << "writing systems for" << QString(name);
-qDebug() << "first char" << hex << unicodeRange[0];
- for (int i = 0; i < systems.count(); ++i)
- qDebug() << QFontDatabase::writingSystemName(systems.at(i));
-#endif
- for (int i = 0; i < systems.count(); ++i)
- family->writingSystems[systems.at(i)] = QtFontFamily::Supported;
-}
-#endif
static void initializeDb()
{
@@ -92,7 +60,7 @@ static void initializeDb()
if(!db || db->count)
return;
-#if defined(QT_MAC_USE_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
QCFType<CTFontCollectionRef> collection = CTFontCollectionCreateFromAvailableFonts(0);
if(!collection)
@@ -156,66 +124,6 @@ if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
} else
#endif
{
-#ifndef QT_MAC_USE_COCOA
- FMFontIterator it;
- if (!FMCreateFontIterator(0, 0, kFMUseGlobalScopeOption, &it)) {
- while (true) {
- FMFont fmFont;
- if (FMGetNextFont(&it, &fmFont) != noErr)
- break;
-
- FMFontFamily fmFamily;
- FMFontStyle fmStyle;
- QString familyName;
-
- QtFontStyle::Key styleKey;
-
- ATSFontRef atsFont = FMGetATSFontRefFromFont(fmFont);
-
- if (!FMGetFontFamilyInstanceFromFont(fmFont, &fmFamily, &fmStyle)) {
- { //sanity check the font, and see if we can use it at all! --Sam
- ATSUFontID fontID;
- if(ATSUFONDtoFontID(fmFamily, 0, &fontID) != noErr)
- continue;
- }
-
- if (fmStyle & ::italic)
- styleKey.style = QFont::StyleItalic;
- if (fmStyle & ::bold)
- styleKey.weight = QFont::Bold;
-
- ATSFontFamilyRef familyRef = FMGetATSFontFamilyRefFromFontFamily(fmFamily);
- QCFString cfFamilyName;;
- ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &cfFamilyName);
- familyName = cfFamilyName;
- } else {
- QCFString cfFontName;
- ATSFontGetName(atsFont, kATSOptionFlagsDefault, &cfFontName);
- familyName = cfFontName;
- quint16 macStyle = 0;
- {
- uchar data[4];
- ByteCount len = 4;
- if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'e', 'a', 'd'), 44, 4, &data, &len) == noErr)
- macStyle = qFromBigEndian<quint16>(data);
- }
- if (macStyle & 1)
- styleKey.weight = QFont::Bold;
- if (macStyle & 2)
- styleKey.style = QFont::StyleItalic;
- }
-
- QtFontFamily *family = db->family(familyName, true);
- QtFontFoundry *foundry = family->foundry(QString(), true);
- QtFontStyle *style = foundry->style(styleKey, QString(), true);
- style->pixelSize(0, true);
- style->smoothScalable = true;
-
- initWritingSystems(family, atsFont);
- }
- FMDisposeFontIterator(&it);
- }
-#endif
}
}
@@ -253,12 +161,7 @@ static inline float weightToFloat(unsigned int weight)
static QFontEngine *loadFromDatabase(const QFontDef &req, const QFontPrivate *d)
{
-#if defined(QT_MAC_USE_COCOA)
QCFString fontName = NULL;
-#else
- ATSFontFamilyRef familyRef = 0;
- ATSFontRef fontRef = 0;
-#endif
QStringList family_list = familyList(req);
@@ -277,34 +180,17 @@ static QFontEngine *loadFromDatabase(const QFontDef &req, const QFontPrivate *d)
for (int k = 0; k < db->count; ++k) {
if (db->families[k]->name.compare(family_list.at(i), Qt::CaseInsensitive) == 0) {
QByteArray family_name = db->families[k]->name.toUtf8();
-#if defined(QT_MAC_USE_COCOA)
QCFType<CTFontRef> ctFont = CTFontCreateWithName(QCFString(db->families[k]->name), 12, NULL);
if (ctFont) {
fontName = CTFontCopyFullName(ctFont);
goto found;
}
-#else
- familyRef = ATSFontFamilyFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault);
- if (familyRef) {
- fontRef = ATSFontFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault);
- goto found;
- }
-#endif
}
}
}
found:
-#ifdef QT_MAC_USE_COCOA
if (fontName)
return new QCoreTextFontEngineMulti(fontName, req, d->kerning);
-#else
- if (familyRef) {
- QCFString actualName;
- if (ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &actualName) == noErr)
- req.family = actualName;
- return new QFontEngineMacMulti(familyRef, req, fontDef, d->kerning);
- }
-#endif
return NULL;
}
@@ -349,7 +235,6 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
}
QFontEngine *engine = NULL;
-#if defined(QT_MAC_USE_COCOA)
// Shortcut to get the font directly without going through the font database
if (!req.family.isEmpty() && !req.styleName.isEmpty()) {
QCFString expectedFamily = QCFString(req.family);
@@ -371,7 +256,6 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
}
}
}
-#endif
if (!engine)
engine = loadFromDatabase(req, d);
@@ -430,7 +314,6 @@ static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
return;
fnt->families.clear();
-#if defined(QT_MAC_USE_COCOA)
// Make sure that the family name set on the font matches what
// kCTFontFamilyNameAttribute returns in initializeDb().
// So far the best solution seems find the installed font
@@ -444,13 +327,6 @@ static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
QCFString familyName = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontFamilyNameAttribute);
fnt->families.append(familyName);
}
-#else
- for(int i = 0; i < containedFonts.size(); ++i) {
- QCFString family;
- ATSFontGetName(containedFonts[i], kATSOptionFlagsDefault, &family);
- fnt->families.append(family);
- }
-#endif
fnt->handle = handle;
}
diff --git a/src/widgets/platforms/mac/qfontengine_mac.mm b/src/widgets/platforms/mac/qfontengine_mac.mm
index 6186b2f514..d043c03b9f 100644
--- a/src/widgets/platforms/mac/qfontengine_mac.mm
+++ b/src/widgets/platforms/mac/qfontengine_mac.mm
@@ -121,1109 +121,4 @@ OSStatus QMacFontPath::closePath(void *data)
return noErr;
}
-
-#ifndef QT_MAC_USE_COCOA
-QFontEngineMacMulti::QFontEngineMacMulti(const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning)
- : QFontEngineMulti(0)
-{
- this->fontDef = fontDef;
- this->kerning = kerning;
-
- // hopefully (CTFontCreateWithName or CTFontCreateWithFontDescriptor) + CTFontCreateCopyWithSymbolicTraits
- // (or CTFontCreateWithQuickdrawInstance)
- FMFontFamily fmFamily;
- FMFontStyle fntStyle = 0;
- fmFamily = FMGetFontFamilyFromATSFontFamilyRef(atsFamily);
- if (fmFamily == kInvalidFontFamily) {
- // Use the ATSFont then...
- fontID = FMGetFontFromATSFontRef(atsFontRef);
- } else {
- if (fontDef.weight >= QFont::Bold)
- fntStyle |= ::bold;
- if (fontDef.style != QFont::StyleNormal)
- fntStyle |= ::italic;
-
- FMFontStyle intrinsicStyle;
- FMFont fnt = 0;
- if (FMGetFontFromFontFamilyInstance(fmFamily, fntStyle, &fnt, &intrinsicStyle) == noErr)
- fontID = FMGetATSFontRefFromFont(fnt);
- }
-
- // CFDictionaryRef, <CTStringAttributes.h>
- OSStatus status;
-
- status = ATSUCreateTextLayout(&textLayout);
- Q_ASSERT(status == noErr);
-
- const int maxAttributeCount = 5;
- ATSUAttributeTag tags[maxAttributeCount + 1];
- ByteCount sizes[maxAttributeCount + 1];
- ATSUAttributeValuePtr values[maxAttributeCount + 1];
- int attributeCount = 0;
-
- Fixed size = FixRatio(fontDef.pixelSize, 1);
- tags[attributeCount] = kATSUSizeTag;
- sizes[attributeCount] = sizeof(size);
- values[attributeCount] = &size;
- ++attributeCount;
-
- tags[attributeCount] = kATSUFontTag;
- sizes[attributeCount] = sizeof(fontID);
- values[attributeCount] = &this->fontID;
- ++attributeCount;
-
- transform = CGAffineTransformIdentity;
- if (fontDef.stretch != 100) {
- transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1);
- tags[attributeCount] = kATSUFontMatrixTag;
- sizes[attributeCount] = sizeof(transform);
- values[attributeCount] = &transform;
- ++attributeCount;
- }
-
- status = ATSUCreateStyle(&style);
- Q_ASSERT(status == noErr);
-
- Q_ASSERT(attributeCount < maxAttributeCount + 1);
- status = ATSUSetAttributes(style, attributeCount, tags, sizes, values);
- Q_ASSERT(status == noErr);
-
- QFontEngineMac *fe = new QFontEngineMac(style, fontID, fontDef, this);
- fe->ref.ref();
- engines.append(fe);
-}
-
-QFontEngineMacMulti::~QFontEngineMacMulti()
-{
- ATSUDisposeTextLayout(textLayout);
- ATSUDisposeStyle(style);
-
- for (int i = 0; i < engines.count(); ++i) {
- QFontEngineMac *fe = const_cast<QFontEngineMac *>(static_cast<const QFontEngineMac *>(engines.at(i)));
- fe->multiEngine = 0;
- if (!fe->ref.deref())
- delete fe;
- }
- engines.clear();
-}
-
-struct QGlyphLayoutInfo
-{
- QGlyphLayout *glyphs;
- int *numGlyphs;
- bool callbackCalled;
- int *mappedFonts;
- QTextEngine::ShaperFlags flags;
- QFontEngineMacMulti::ShaperItem *shaperItem;
- unsigned int styleStrategy;
-};
-
-static OSStatus atsuPostLayoutCallback(ATSULayoutOperationSelector selector, ATSULineRef lineRef, URefCon refCon,
- void *operationExtraParameter, ATSULayoutOperationCallbackStatus *callbackStatus)
-{
- Q_UNUSED(selector);
- Q_UNUSED(operationExtraParameter);
-
- QGlyphLayoutInfo *nfo = reinterpret_cast<QGlyphLayoutInfo *>(refCon);
- nfo->callbackCalled = true;
-
- ATSLayoutRecord *layoutData = 0;
- ItemCount itemCount = 0;
-
- OSStatus e = noErr;
- e = ATSUDirectGetLayoutDataArrayPtrFromLineRef(lineRef, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
- /*iCreate =*/ false,
- (void **) &layoutData,
- &itemCount);
- if (e != noErr)
- return e;
-
- *nfo->numGlyphs = itemCount - 1;
-
- Fixed *baselineDeltas = 0;
-
- e = ATSUDirectGetLayoutDataArrayPtrFromLineRef(lineRef, kATSUDirectDataBaselineDeltaFixedArray,
- /*iCreate =*/ true,
- (void **) &baselineDeltas,
- &itemCount);
- if (e != noErr)
- return e;
-
- int nextCharStop = -1;
- int currentClusterGlyph = -1; // first glyph in log cluster
- QFontEngineMacMulti::ShaperItem *item = nfo->shaperItem;
- if (item->charAttributes) {
- item = nfo->shaperItem;
-#if !defined(QT_NO_DEBUG)
- int surrogates = 0;
- const QChar *str = item->string;
- for (int i = item->from; i < item->from + item->length - 1; ++i)
- surrogates += (str[i].isHighSurrogate() && str[i+1].isLowSurrogate());
-#endif
- for (nextCharStop = item->from; nextCharStop < item->from + item->length; ++nextCharStop)
- if (item->charAttributes[nextCharStop].charStop)
- break;
- nextCharStop -= item->from;
- }
-
- nfo->glyphs->attributes[0].clusterStart = true;
- int glyphIdx = 0;
- int glyphIncrement = 1;
- if (nfo->flags & QTextEngine::RightToLeft) {
- glyphIdx = itemCount - 2;
- glyphIncrement = -1;
- }
- for (int i = 0; i < *nfo->numGlyphs; ++i, glyphIdx += glyphIncrement) {
-
- int charOffset = layoutData[glyphIdx].originalOffset / sizeof(UniChar);
- const int fontIdx = nfo->mappedFonts[charOffset];
-
- ATSGlyphRef glyphId = layoutData[glyphIdx].glyphID;
-
- QFixed yAdvance = FixedToQFixed(baselineDeltas[glyphIdx]);
- QFixed xAdvance = FixedToQFixed(layoutData[glyphIdx + 1].realPos - layoutData[glyphIdx].realPos);
-
- if (nfo->styleStrategy & QFont::ForceIntegerMetrics) {
- yAdvance = yAdvance.round();
- xAdvance = xAdvance.round();
- }
-
- if (glyphId != 0xffff || i == 0) {
- if (i < nfo->glyphs->numGlyphs)
- {
- nfo->glyphs->glyphs[i] = (glyphId & 0x00ffffff) | (fontIdx << 24);
-
- nfo->glyphs->advances_y[i] = yAdvance;
- nfo->glyphs->advances_x[i] = xAdvance;
- }
- } else {
- // ATSUI gives us 0xffff as glyph id at the index in the glyph array for
- // a character position that maps to a ligtature. Such a glyph id does not
- // result in any visual glyph, but it may have an advance, which is why we
- // sum up the glyph advances.
- --i;
- nfo->glyphs->advances_y[i] += yAdvance;
- nfo->glyphs->advances_x[i] += xAdvance;
- *nfo->numGlyphs -= 1;
- }
-
- if (item->log_clusters) {
- if (charOffset >= nextCharStop) {
- nfo->glyphs->attributes[i].clusterStart = true;
- currentClusterGlyph = i;
-
- ++nextCharStop;
- for (; nextCharStop < item->length; ++nextCharStop)
- if (item->charAttributes[item->from + nextCharStop].charStop)
- break;
- } else {
- if (currentClusterGlyph == -1)
- currentClusterGlyph = i;
- }
- item->log_clusters[charOffset] = currentClusterGlyph;
-
- // surrogate handling
- if (charOffset < item->length - 1) {
- QChar current = item->string[item->from + charOffset];
- QChar next = item->string[item->from + charOffset + 1];
- if (current.isHighSurrogate() && next.isLowSurrogate())
- item->log_clusters[charOffset + 1] = currentClusterGlyph;
- }
- }
- }
-
- /*
- if (item) {
- qDebug() << "resulting logclusters:";
- for (int i = 0; i < item->length; ++i)
- qDebug() << "logClusters[" << i << "] =" << item->log_clusters[i];
- qDebug() << "clusterstarts:";
- for (int i = 0; i < *nfo->numGlyphs; ++i)
- qDebug() << "clusterStart[" << i << "] =" << nfo->glyphs[i].attributes.clusterStart;
- }
- */
-
- ATSUDirectReleaseLayoutDataArrayPtr(lineRef, kATSUDirectDataBaselineDeltaFixedArray,
- (void **) &baselineDeltas);
-
- ATSUDirectReleaseLayoutDataArrayPtr(lineRef, kATSUDirectDataLayoutRecordATSLayoutRecordCurrent,
- (void **) &layoutData);
-
- *callbackStatus = kATSULayoutOperationCallbackStatusHandled;
- return noErr;
-}
-
-int QFontEngineMacMulti::fontIndexForFontID(ATSUFontID id) const
-{
- for (int i = 0; i < engines.count(); ++i) {
- if (engineAt(i)->fontID == id)
- return i;
- }
-
- QFontEngineMacMulti *that = const_cast<QFontEngineMacMulti *>(this);
- QFontEngineMac *fe = new QFontEngineMac(style, id, fontDef, that);
- fe->ref.ref();
- that->engines.append(fe);
- return engines.count() - 1;
-}
-
-bool QFontEngineMacMulti::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
-{
- return stringToCMap(str, len, glyphs, nglyphs, flags, /*logClusters=*/0, /*charAttributes=*/0);
-}
-
-bool QFontEngineMacMulti::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags,
- unsigned short *logClusters, const HB_CharAttributes *charAttributes, QScriptItem *) const
-{
- if (*nglyphs < len) {
- *nglyphs = len;
- return false;
- }
-
- ShaperItem shaperItem;
- shaperItem.string = str;
- shaperItem.from = 0;
- shaperItem.length = len;
- shaperItem.glyphs = *glyphs;
- shaperItem.glyphs.numGlyphs = *nglyphs;
- shaperItem.flags = flags;
- shaperItem.log_clusters = logClusters;
- shaperItem.charAttributes = charAttributes;
-
- const int maxChars = qMax(1,
- int(SHRT_MAX / maxCharWidth())
- - 10 // subtract a few to be on the safe side
- );
- if (len < maxChars || !charAttributes)
- return stringToCMapInternal(str, len, glyphs, nglyphs, flags, &shaperItem);
-
- int charIdx = 0;
- int glyphIdx = 0;
- ShaperItem tmpItem = shaperItem;
-
- do {
- tmpItem.from = shaperItem.from + charIdx;
-
- int charCount = qMin(maxChars, len - charIdx);
-
- int lastWhitespace = tmpItem.from + charCount - 1;
- int lastSoftBreak = lastWhitespace;
- int lastCharStop = lastSoftBreak;
- for (int i = lastCharStop; i >= tmpItem.from; --i) {
- if (tmpItem.charAttributes[i].whiteSpace) {
- lastWhitespace = i;
- break;
- } if (tmpItem.charAttributes[i].lineBreakType != HB_NoBreak) {
- lastSoftBreak = i;
- } if (tmpItem.charAttributes[i].charStop) {
- lastCharStop = i;
- }
- }
- charCount = qMin(lastWhitespace, qMin(lastSoftBreak, lastCharStop)) - tmpItem.from + 1;
-
- int glyphCount = shaperItem.glyphs.numGlyphs - glyphIdx;
- if (glyphCount <= 0)
- return false;
- tmpItem.length = charCount;
- tmpItem.glyphs = shaperItem.glyphs.mid(glyphIdx, glyphCount);
- tmpItem.log_clusters = shaperItem.log_clusters + charIdx;
- if (!stringToCMapInternal(tmpItem.string + tmpItem.from, tmpItem.length,
- &tmpItem.glyphs, &glyphCount, flags,
- &tmpItem)) {
- *nglyphs = glyphIdx + glyphCount;
- return false;
- }
- for (int i = 0; i < charCount; ++i)
- tmpItem.log_clusters[i] += glyphIdx;
- glyphIdx += glyphCount;
- charIdx += charCount;
- } while (charIdx < len);
- *nglyphs = glyphIdx;
- glyphs->numGlyphs = glyphIdx;
-
- return true;
-}
-
-bool QFontEngineMacMulti::stringToCMapInternal(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags,ShaperItem *shaperItem) const
-{
- //qDebug() << "stringToCMap" << QString(str, len);
-
- OSStatus e = noErr;
-
- e = ATSUSetTextPointerLocation(textLayout, (UniChar *)(str), 0, len, len);
- if (e != noErr) {
- qWarning("Qt: internal: %ld: Error ATSUSetTextPointerLocation %s: %d", long(e), __FILE__, __LINE__);
- return false;
- }
-
- QGlyphLayoutInfo nfo;
- nfo.glyphs = glyphs;
- nfo.numGlyphs = nglyphs;
- nfo.callbackCalled = false;
- nfo.flags = flags;
- nfo.shaperItem = shaperItem;
- nfo.styleStrategy = fontDef.styleStrategy;
-
- int prevNumGlyphs = *nglyphs;
-
- QVarLengthArray<int> mappedFonts(len);
- for (int i = 0; i < len; ++i)
- mappedFonts[i] = 0;
- nfo.mappedFonts = mappedFonts.data();
-
- Q_ASSERT(sizeof(void *) <= sizeof(URefCon));
- e = ATSUSetTextLayoutRefCon(textLayout, (URefCon)&nfo);
- if (e != noErr) {
- qWarning("Qt: internal: %ld: Error ATSUSetTextLayoutRefCon %s: %d", long(e), __FILE__, __LINE__);
- return false;
- }
-
- {
- const int maxAttributeCount = 3;
- ATSUAttributeTag tags[maxAttributeCount + 1];
- ByteCount sizes[maxAttributeCount + 1];
- ATSUAttributeValuePtr values[maxAttributeCount + 1];
- int attributeCount = 0;
-
- tags[attributeCount] = kATSULineLayoutOptionsTag;
- ATSLineLayoutOptions layopts = kATSLineHasNoOpticalAlignment
- | kATSLineIgnoreFontLeading
- | kATSLineNoSpecialJustification // we do kashidas ourselves
- | kATSLineDisableAllJustification
- ;
-
- if (fontDef.styleStrategy & QFont::NoAntialias)
- layopts |= kATSLineNoAntiAliasing;
-
- if (!kerning)
- layopts |= kATSLineDisableAllKerningAdjustments;
-
- values[attributeCount] = &layopts;
- sizes[attributeCount] = sizeof(layopts);
- ++attributeCount;
-
- tags[attributeCount] = kATSULayoutOperationOverrideTag;
- ATSULayoutOperationOverrideSpecifier spec;
- spec.operationSelector = kATSULayoutOperationPostLayoutAdjustment;
- spec.overrideUPP = atsuPostLayoutCallback;
- values[attributeCount] = &spec;
- sizes[attributeCount] = sizeof(spec);
- ++attributeCount;
-
- // CTWritingDirection
- Boolean direction;
- if (flags & QTextEngine::RightToLeft)
- direction = kATSURightToLeftBaseDirection;
- else
- direction = kATSULeftToRightBaseDirection;
- tags[attributeCount] = kATSULineDirectionTag;
- values[attributeCount] = &direction;
- sizes[attributeCount] = sizeof(direction);
- ++attributeCount;
-
- Q_ASSERT(attributeCount < maxAttributeCount + 1);
- e = ATSUSetLayoutControls(textLayout, attributeCount, tags, sizes, values);
- if (e != noErr) {
- qWarning("Qt: internal: %ld: Error ATSUSetLayoutControls %s: %d", long(e), __FILE__, __LINE__);
- return false;
- }
-
- }
-
- e = ATSUSetRunStyle(textLayout, style, 0, len);
- if (e != noErr) {
- qWarning("Qt: internal: %ld: Error ATSUSetRunStyle %s: %d", long(e), __FILE__, __LINE__);
- return false;
- }
-
- if (!(fontDef.styleStrategy & QFont::NoFontMerging)) {
- int pos = 0;
- do {
- ATSUFontID substFont = 0;
- UniCharArrayOffset changedOffset = 0;
- UniCharCount changeCount = 0;
-
- e = ATSUMatchFontsToText(textLayout, pos, len - pos,
- &substFont, &changedOffset,
- &changeCount);
- if (e == kATSUFontsMatched) {
- int fontIdx = fontIndexForFontID(substFont);
- for (uint i = 0; i < changeCount; ++i)
- mappedFonts[changedOffset + i] = fontIdx;
- pos = changedOffset + changeCount;
- ATSUSetRunStyle(textLayout, engineAt(fontIdx)->style, changedOffset, changeCount);
- } else if (e == kATSUFontsNotMatched) {
- pos = changedOffset + changeCount;
- }
- } while (pos < len && e != noErr);
- }
- { // trigger the a layout
- // CFAttributedStringCreate, CTFramesetterCreateWithAttributedString (or perhaps Typesetter)
- Rect rect;
- e = ATSUMeasureTextImage(textLayout, kATSUFromTextBeginning, kATSUToTextEnd,
- /*iLocationX =*/ 0, /*iLocationY =*/ 0,
- &rect);
- if (e != noErr) {
- qWarning("Qt: internal: %ld: Error ATSUMeasureTextImage %s: %d", long(e), __FILE__, __LINE__);
- return false;
- }
- }
-
- if (!nfo.callbackCalled) {
- qWarning("Qt: internal: %ld: Error ATSUMeasureTextImage did not trigger callback %s: %d", long(e), __FILE__, __LINE__);
- return false;
- }
-
- ATSUClearLayoutCache(textLayout, kATSUFromTextBeginning);
- if (prevNumGlyphs < *nfo.numGlyphs)
- return false;
- return true;
-}
-
-void QFontEngineMacMulti::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
-{
- Q_ASSERT(false);
- Q_UNUSED(glyphs);
- Q_UNUSED(flags);
-}
-
-void QFontEngineMacMulti::doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const
-{
- //Q_ASSERT(false);
-}
-
-void QFontEngineMacMulti::loadEngine(int /*at*/)
-{
- // should never be called!
- Q_ASSERT(false);
-}
-
-bool QFontEngineMacMulti::canRender(const QChar *string, int len)
-{
- ATSUSetTextPointerLocation(textLayout, reinterpret_cast<const UniChar *>(string), 0, len, len);
- ATSUSetRunStyle(textLayout, style, 0, len);
-
- OSStatus e = noErr;
- int pos = 0;
- do {
- FMFont substFont = 0;
- UniCharArrayOffset changedOffset = 0;
- UniCharCount changeCount = 0;
-
- // CTFontCreateForString
- e = ATSUMatchFontsToText(textLayout, pos, len - pos,
- &substFont, &changedOffset,
- &changeCount);
- if (e == kATSUFontsMatched) {
- pos = changedOffset + changeCount;
- } else if (e == kATSUFontsNotMatched) {
- break;
- }
- } while (pos < len && e != noErr);
-
- return e == noErr || e == kATSUFontsMatched;
-}
-
-QFontEngineMac::QFontEngineMac(ATSUStyle baseStyle, ATSUFontID fontID, const QFontDef &def, QFontEngineMacMulti *multiEngine)
- : fontID(fontID), multiEngine(multiEngine), cmap(0), symbolCMap(false)
-{
- fontDef = def;
- ATSUCreateAndCopyStyle(baseStyle, &style);
- ATSFontRef atsFont = FMGetATSFontRefFromFont(fontID);
- cgFont = CGFontCreateWithPlatformFont(&atsFont);
-
- const int maxAttributeCount = 4;
- ATSUAttributeTag tags[maxAttributeCount + 1];
- ByteCount sizes[maxAttributeCount + 1];
- ATSUAttributeValuePtr values[maxAttributeCount + 1];
- int attributeCount = 0;
-
- synthesisFlags = 0;
-
- // synthesizing using CG is not recommended
- quint16 macStyle = 0;
- {
- uchar data[4];
- ByteCount len = 4;
- if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'e', 'a', 'd'), 44, 4, &data, &len) == noErr)
- macStyle = qFromBigEndian<quint16>(data);
- }
-
- Boolean atsuBold = false;
- Boolean atsuItalic = false;
- if (fontDef.weight >= QFont::Bold) {
- if (!(macStyle & 1)) {
- synthesisFlags |= SynthesizedBold;
- atsuBold = true;
- tags[attributeCount] = kATSUQDBoldfaceTag;
- sizes[attributeCount] = sizeof(atsuBold);
- values[attributeCount] = &atsuBold;
- ++attributeCount;
- }
- }
- if (fontDef.style != QFont::StyleNormal) {
- if (!(macStyle & 2)) {
- synthesisFlags |= SynthesizedItalic;
- atsuItalic = true;
- tags[attributeCount] = kATSUQDItalicTag;
- sizes[attributeCount] = sizeof(atsuItalic);
- values[attributeCount] = &atsuItalic;
- ++attributeCount;
- }
- }
-
- tags[attributeCount] = kATSUFontTag;
- values[attributeCount] = &fontID;
- sizes[attributeCount] = sizeof(fontID);
- ++attributeCount;
-
- Q_ASSERT(attributeCount < maxAttributeCount + 1);
- OSStatus err = ATSUSetAttributes(style, attributeCount, tags, sizes, values);
- Q_ASSERT(err == noErr);
- Q_UNUSED(err);
-
- // CTFontCopyTable
- quint16 tmpFsType;
- if (ATSFontGetTable(atsFont, MAKE_TAG('O', 'S', '/', '2'), 8, 2, &tmpFsType, 0) == noErr)
- fsType = qFromBigEndian<quint16>(tmpFsType);
- else
- fsType = 0;
-
- if (multiEngine)
- transform = multiEngine->transform;
- else
- transform = CGAffineTransformIdentity;
-
- ATSUTextMeasurement metric;
-
- ATSUGetAttribute(style, kATSUAscentTag, sizeof(metric), &metric, 0);
- m_ascent = FixRound(metric);
-
- ATSUGetAttribute(style, kATSUDescentTag, sizeof(metric), &metric, 0);
- m_descent = FixRound(metric);
-
- ATSUGetAttribute(style, kATSULeadingTag, sizeof(metric), &metric, 0);
- m_leading = FixRound(metric);
-
- ATSFontMetrics metrics;
-
- ATSFontGetHorizontalMetrics(FMGetATSFontRefFromFont(fontID), kATSOptionFlagsDefault, &metrics);
- m_maxCharWidth = metrics.maxAdvanceWidth * fontDef.pointSize;
-
- ATSFontGetHorizontalMetrics(FMGetATSFontRefFromFont(fontID), kATSOptionFlagsDefault, &metrics);
- m_xHeight = QFixed::fromReal(metrics.xHeight * fontDef.pointSize);
-
- ATSFontGetHorizontalMetrics(FMGetATSFontRefFromFont(fontID), kATSOptionFlagsDefault, &metrics);
- m_averageCharWidth = QFixed::fromReal(metrics.avgAdvanceWidth * fontDef.pointSize);
-
- // Use width of 'X' if ATSFontGetHorizontalMetrics returns 0 for avgAdvanceWidth.
- if (m_averageCharWidth == QFixed(0)) {
- QChar c('X');
- QGlyphLayoutArray<1> glyphs;
- int nglyphs = 1;
- stringToCMap(&c, 1, &glyphs, &nglyphs, 0);
- glyph_metrics_t metrics = boundingBox(glyphs);
- m_averageCharWidth = metrics.width;
- }
-}
-
-QFontEngineMac::~QFontEngineMac()
-{
- ATSUDisposeStyle(style);
-}
-
-static inline unsigned int getChar(const QChar *str, int &i, const int len)
-{
- uint ucs4 = str[i].unicode();
- if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) {
- ++i;
- ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode());
- }
- return ucs4;
-}
-
-// Not used directly for shaping, only used to calculate m_averageCharWidth
-bool QFontEngineMac::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
-{
- if (!cmap) {
- cmapTable = getSfntTable(MAKE_TAG('c', 'm', 'a', 'p'));
- int size = 0;
- cmap = getCMap(reinterpret_cast<const uchar *>(cmapTable.constData()), cmapTable.size(), &symbolCMap, &size);
- if (!cmap)
- return false;
- }
- if (symbolCMap) {
- for (int i = 0; i < len; ++i) {
- unsigned int uc = getChar(str, i, len);
- glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc);
- if(!glyphs->glyphs[i] && uc < 0x100)
- glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc + 0xf000);
- }
- } else {
- for (int i = 0; i < len; ++i) {
- unsigned int uc = getChar(str, i, len);
- glyphs->glyphs[i] = getTrueTypeGlyphIndex(cmap, uc);
- }
- }
-
- *nglyphs = len;
- glyphs->numGlyphs = *nglyphs;
-
- if (!(flags & QTextEngine::GlyphIndicesOnly))
- recalcAdvances(glyphs, flags);
-
- return true;
-}
-
-void QFontEngineMac::recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags flags) const
-{
- Q_UNUSED(flags)
-
- QVarLengthArray<GlyphID> atsuGlyphs(glyphs->numGlyphs);
- for (int i = 0; i < glyphs->numGlyphs; ++i)
- atsuGlyphs[i] = glyphs->glyphs[i];
-
- QVarLengthArray<ATSGlyphScreenMetrics> metrics(glyphs->numGlyphs);
-
- ATSUGlyphGetScreenMetrics(style, glyphs->numGlyphs, atsuGlyphs.data(), sizeof(GlyphID),
- /* iForcingAntiAlias =*/ false,
- /* iAntiAliasSwitch =*/true,
- metrics.data());
-
- for (int i = 0; i < glyphs->numGlyphs; ++i) {
- glyphs->advances_x[i] = QFixed::fromReal(metrics[i].deviceAdvance.x);
- glyphs->advances_y[i] = QFixed::fromReal(metrics[i].deviceAdvance.y);
-
- if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) {
- glyphs->advances_x[i] = glyphs->advances_x[i].round();
- glyphs->advances_y[i] = glyphs->advances_y[i].round();
- }
- }
-}
-
-glyph_metrics_t QFontEngineMac::boundingBox(const QGlyphLayout &glyphs)
-{
- QFixed w;
- bool round = fontDef.styleStrategy & QFont::ForceIntegerMetrics;
- for (int i = 0; i < glyphs.numGlyphs; ++i) {
- w += round ? glyphs.effectiveAdvance(i).round()
- : glyphs.effectiveAdvance(i);
- }
- return glyph_metrics_t(0, -(ascent()), w - lastRightBearing(glyphs, round), ascent()+descent(), w, 0);
-}
-
-glyph_metrics_t QFontEngineMac::boundingBox(glyph_t glyph)
-{
- GlyphID atsuGlyph = glyph;
-
- ATSGlyphScreenMetrics metrics;
-
- ATSUGlyphGetScreenMetrics(style, 1, &atsuGlyph, 0,
- /* iForcingAntiAlias =*/ false,
- /* iAntiAliasSwitch =*/true,
- &metrics);
-
- // ### check again
-
- glyph_metrics_t gm;
- gm.width = int(metrics.width);
- gm.height = int(metrics.height);
- gm.x = QFixed::fromReal(metrics.topLeft.x);
- gm.y = -QFixed::fromReal(metrics.topLeft.y);
- gm.xoff = QFixed::fromReal(metrics.deviceAdvance.x);
- gm.yoff = QFixed::fromReal(metrics.deviceAdvance.y);
-
- if (fontDef.styleStrategy & QFont::ForceIntegerMetrics) {
- gm.x = gm.x.floor();
- gm.y = gm.y.floor();
- gm.xoff = gm.xoff.round();
- gm.yoff = gm.yoff.round();
- }
-
- return gm;
-}
-
-QFixed QFontEngineMac::ascent() const
-{
- return (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
- ? m_ascent.round()
- : m_ascent;
-}
-
-QFixed QFontEngineMac::descent() const
-{
- // subtract a pixel to even out the historical +1 in QFontMetrics::height().
- // Fix in Qt 5.
- return (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
- ? m_descent.round() - 1
- : m_descent;
-}
-
-QFixed QFontEngineMac::leading() const
-{
- return (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
- ? m_leading.round()
- : m_leading;
-}
-
-qreal QFontEngineMac::maxCharWidth() const
-{
- return (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
- ? qRound(m_maxCharWidth)
- : m_maxCharWidth;
-}
-
-QFixed QFontEngineMac::xHeight() const
-{
- return (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
- ? m_xHeight.round()
- : m_xHeight;
-}
-
-QFixed QFontEngineMac::averageCharWidth() const
-{
- return (fontDef.styleStrategy & QFont::ForceIntegerMetrics)
- ? m_averageCharWidth.round()
- : m_averageCharWidth;
-}
-
-static void addGlyphsToPathHelper(ATSUStyle style, glyph_t *glyphs, QFixedPoint *positions, int numGlyphs, QPainterPath *path)
-{
- if (!numGlyphs)
- return;
-
- OSStatus e;
-
- QMacFontPath fontpath(0, 0, path);
- ATSCubicMoveToUPP moveTo = NewATSCubicMoveToUPP(QMacFontPath::moveTo);
- ATSCubicLineToUPP lineTo = NewATSCubicLineToUPP(QMacFontPath::lineTo);
- ATSCubicCurveToUPP cubicTo = NewATSCubicCurveToUPP(QMacFontPath::cubicTo);
- ATSCubicClosePathUPP closePath = NewATSCubicClosePathUPP(QMacFontPath::closePath);
-
- // CTFontCreatePathForGlyph
- for (int i = 0; i < numGlyphs; ++i) {
- GlyphID glyph = glyphs[i];
-
- fontpath.setPosition(positions[i].x.toReal(), positions[i].y.toReal());
- ATSUGlyphGetCubicPaths(style, glyph, moveTo, lineTo,
- cubicTo, closePath, &fontpath, &e);
- }
-
- DisposeATSCubicMoveToUPP(moveTo);
- DisposeATSCubicLineToUPP(lineTo);
- DisposeATSCubicCurveToUPP(cubicTo);
- DisposeATSCubicClosePathUPP(closePath);
-}
-
-void QFontEngineMac::addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs, QPainterPath *path,
- QTextItem::RenderFlags)
-{
- addGlyphsToPathHelper(style, glyphs, positions, numGlyphs, path);
-}
-
-
-/*!
- Helper function for alphaMapForGlyph and alphaRGBMapForGlyph. The two are identical, except for
- the subpixel antialiasing...
-*/
-QImage QFontEngineMac::imageForGlyph(glyph_t glyph, int margin, bool colorful)
-{
- const glyph_metrics_t br = boundingBox(glyph);
- QImage im(qRound(br.width)+2, qRound(br.height)+4, QImage::Format_RGB32);
- im.fill(0xff000000);
-
- CGColorSpaceRef colorspace = QCoreGraphicsPaintEngine::macGenericColorSpace();
- uint cgflags = kCGImageAlphaNoneSkipFirst;
-#ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
- cgflags |= kCGBitmapByteOrder32Host;
-#endif
- CGContextRef ctx = CGBitmapContextCreate(im.bits(), im.width(), im.height(),
- 8, im.bytesPerLine(), colorspace,
- cgflags);
- CGContextSetFontSize(ctx, fontDef.pixelSize);
- CGContextSetShouldAntialias(ctx, fontDef.pointSize > qt_antialiasing_threshold && !(fontDef.styleStrategy & QFont::NoAntialias));
- // turn off sub-pixel hinting - no support for that in OpenGL
- CGContextSetShouldSmoothFonts(ctx, colorful);
- CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx);
- CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, 1, 0, 0);
- CGAffineTransformConcat(cgMatrix, oldTextMatrix);
-
- if (synthesisFlags & QFontEngine::SynthesizedItalic)
- cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, tanf(14 * acosf(0) / 90), 1, 0, 0));
-
- cgMatrix = CGAffineTransformConcat(cgMatrix, transform);
-
- CGContextSetTextMatrix(ctx, cgMatrix);
- CGContextSetRGBFillColor(ctx, 1, 1, 1, 1);
- CGContextSetTextDrawingMode(ctx, kCGTextFill);
- CGContextSetFont(ctx, cgFont);
-
- qreal pos_x = -br.x.toReal() + 1;
- qreal pos_y = im.height() + br.y.toReal() - 2;
- CGContextSetTextPosition(ctx, pos_x, pos_y);
-
- CGSize advance;
- advance.width = 0;
- advance.height = 0;
- CGGlyph cgGlyph = glyph;
- CGContextShowGlyphsWithAdvances(ctx, &cgGlyph, &advance, 1);
-
- if (synthesisFlags & QFontEngine::SynthesizedBold) {
- CGContextSetTextPosition(ctx, pos_x + 0.5 * lineThickness().toReal(), pos_y);
- CGContextShowGlyphsWithAdvances(ctx, &cgGlyph, &advance, 1);
- }
-
- CGContextRelease(ctx);
-
- return im;
-}
-
-QImage QFontEngineMac::alphaMapForGlyph(glyph_t glyph)
-{
- QImage im = imageForGlyph(glyph, 2, false);
-
- QImage indexed(im.width(), im.height(), QImage::Format_Indexed8);
- QVector<QRgb> colors(256);
- for (int i=0; i<256; ++i)
- colors[i] = qRgba(0, 0, 0, i);
- indexed.setColorTable(colors);
-
- for (int y=0; y<im.height(); ++y) {
- uint *src = (uint*) im.scanLine(y);
- uchar *dst = indexed.scanLine(y);
- for (int x=0; x<im.width(); ++x) {
- *dst = qGray(*src);
- ++dst;
- ++src;
- }
- }
-
- return indexed;
-}
-
-QImage QFontEngineMac::alphaRGBMapForGlyph(glyph_t glyph, QFixed, int margin, const QTransform &t)
-{
- QImage im = imageForGlyph(glyph, margin, true);
-
- if (t.type() >= QTransform::TxScale) {
- im = im.transformed(t);
- }
-
- qGamma_correct_back_to_linear_cs(&im);
-
- return im;
-}
-
-
-bool QFontEngineMac::canRender(const QChar *string, int len)
-{
- Q_ASSERT(false);
- Q_UNUSED(string);
- Q_UNUSED(len);
- return false;
-}
-
-void QFontEngineMac::draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight)
-{
- QVarLengthArray<QFixedPoint> positions;
- QVarLengthArray<glyph_t> glyphs;
- QTransform matrix;
- matrix.translate(x, y);
- getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
- if (glyphs.size() == 0)
- return;
-
- CGContextSetFontSize(ctx, fontDef.pixelSize);
-
- CGAffineTransform oldTextMatrix = CGContextGetTextMatrix(ctx);
-
- CGAffineTransform cgMatrix = CGAffineTransformMake(1, 0, 0, -1, 0, -paintDeviceHeight);
-
- CGAffineTransformConcat(cgMatrix, oldTextMatrix);
-
- if (synthesisFlags & QFontEngine::SynthesizedItalic)
- cgMatrix = CGAffineTransformConcat(cgMatrix, CGAffineTransformMake(1, 0, -tanf(14 * acosf(0) / 90), 1, 0, 0));
-
- cgMatrix = CGAffineTransformConcat(cgMatrix, transform);
-
- CGContextSetTextMatrix(ctx, cgMatrix);
-
- CGContextSetTextDrawingMode(ctx, kCGTextFill);
-
-
- QVarLengthArray<CGSize> advances(glyphs.size());
- QVarLengthArray<CGGlyph> cgGlyphs(glyphs.size());
-
- for (int i = 0; i < glyphs.size() - 1; ++i) {
- advances[i].width = (positions[i + 1].x - positions[i].x).toReal();
- advances[i].height = (positions[i + 1].y - positions[i].y).toReal();
- cgGlyphs[i] = glyphs[i];
- }
- advances[glyphs.size() - 1].width = 0;
- advances[glyphs.size() - 1].height = 0;
- cgGlyphs[glyphs.size() - 1] = glyphs[glyphs.size() - 1];
-
- CGContextSetFont(ctx, cgFont);
-
- CGContextSetTextPosition(ctx, positions[0].x.toReal(), positions[0].y.toReal());
-
- CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size());
-
- if (synthesisFlags & QFontEngine::SynthesizedBold) {
- CGContextSetTextPosition(ctx, positions[0].x.toReal() + 0.5 * lineThickness().toReal(),
- positions[0].y.toReal());
-
- CGContextShowGlyphsWithAdvances(ctx, cgGlyphs.data(), advances.data(), glyphs.size());
- }
-
- CGContextSetTextMatrix(ctx, oldTextMatrix);
-}
-
-QFontEngine::FaceId QFontEngineMac::faceId() const
-{
- FaceId ret;
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
-if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
- // CTFontGetPlatformFont
- FSRef ref;
- if (ATSFontGetFileReference(FMGetATSFontRefFromFont(fontID), &ref) != noErr)
- return ret;
- ret.filename = QByteArray(128, 0);
- ret.index = fontID;
- FSRefMakePath(&ref, (UInt8 *)ret.filename.data(), ret.filename.size());
-}else
-#endif
-{
- FSSpec spec;
- if (ATSFontGetFileSpecification(FMGetATSFontRefFromFont(fontID), &spec) != noErr)
- return ret;
-
- FSRef ref;
- FSpMakeFSRef(&spec, &ref);
- ret.filename = QByteArray(128, 0);
- ret.index = fontID;
- FSRefMakePath(&ref, (UInt8 *)ret.filename.data(), ret.filename.size());
-}
- return ret;
-}
-
-QByteArray QFontEngineMac::getSfntTable(uint tag) const
-{
- ATSFontRef atsFont = FMGetATSFontRefFromFont(fontID);
-
- ByteCount length;
- OSStatus status = ATSFontGetTable(atsFont, tag, 0, 0, 0, &length);
- if (status != noErr)
- return QByteArray();
- QByteArray table(length, 0);
- // CTFontCopyTable
- status = ATSFontGetTable(atsFont, tag, 0, table.length(), table.data(), &length);
- if (status != noErr)
- return QByteArray();
- return table;
-}
-
-QFontEngine::Properties QFontEngineMac::properties() const
-{
- QFontEngine::Properties props;
- ATSFontRef atsFont = FMGetATSFontRefFromFont(fontID);
- quint16 tmp;
- // CTFontGetUnitsPerEm
- if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'e', 'a', 'd'), 18, 2, &tmp, 0) == noErr)
- props.emSquare = qFromBigEndian<quint16>(tmp);
- struct {
- qint16 xMin;
- qint16 yMin;
- qint16 xMax;
- qint16 yMax;
- } bbox;
- bbox.xMin = bbox.xMax = bbox.yMin = bbox.yMax = 0;
- // CTFontGetBoundingBox
- if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'e', 'a', 'd'), 36, 8, &bbox, 0) == noErr) {
- bbox.xMin = qFromBigEndian<quint16>(bbox.xMin);
- bbox.yMin = qFromBigEndian<quint16>(bbox.yMin);
- bbox.xMax = qFromBigEndian<quint16>(bbox.xMax);
- bbox.yMax = qFromBigEndian<quint16>(bbox.yMax);
- }
- struct {
- qint16 ascender;
- qint16 descender;
- qint16 linegap;
- } metrics;
- metrics.ascender = metrics.descender = metrics.linegap = 0;
- // CTFontGetAscent, etc.
- if (ATSFontGetTable(atsFont, MAKE_TAG('h', 'h', 'e', 'a'), 4, 6, &metrics, 0) == noErr) {
- metrics.ascender = qFromBigEndian<quint16>(metrics.ascender);
- metrics.descender = qFromBigEndian<quint16>(metrics.descender);
- metrics.linegap = qFromBigEndian<quint16>(metrics.linegap);
- }
- props.ascent = metrics.ascender;
- props.descent = -metrics.descender;
- props.leading = metrics.linegap;
- props.boundingBox = QRectF(bbox.xMin, -bbox.yMax,
- bbox.xMax - bbox.xMin,
- bbox.yMax - bbox.yMin);
- props.italicAngle = 0;
- props.capHeight = props.ascent;
-
- qint16 lw = 0;
- // fonts lie
- if (ATSFontGetTable(atsFont, MAKE_TAG('p', 'o', 's', 't'), 10, 2, &lw, 0) == noErr)
- lw = qFromBigEndian<quint16>(lw);
- props.lineWidth = lw;
-
- // CTFontCopyPostScriptName
- QCFString psName;
- if (ATSFontGetPostScriptName(FMGetATSFontRefFromFont(fontID), kATSOptionFlagsDefault, &psName) == noErr)
- props.postscriptName = QString(psName).toUtf8();
- props.postscriptName = QFontEngine::convertToPostscriptFontFamilyName(props.postscriptName);
- return props;
-}
-
-void QFontEngineMac::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
-{
- ATSUStyle unscaledStyle;
- ATSUCreateAndCopyStyle(style, &unscaledStyle);
-
- int emSquare = properties().emSquare.toInt();
-
- const int maxAttributeCount = 4;
- ATSUAttributeTag tags[maxAttributeCount + 1];
- ByteCount sizes[maxAttributeCount + 1];
- ATSUAttributeValuePtr values[maxAttributeCount + 1];
- int attributeCount = 0;
-
- Fixed size = FixRatio(emSquare, 1);
- tags[attributeCount] = kATSUSizeTag;
- sizes[attributeCount] = sizeof(size);
- values[attributeCount] = &size;
- ++attributeCount;
-
- Q_ASSERT(attributeCount < maxAttributeCount + 1);
- OSStatus err = ATSUSetAttributes(unscaledStyle, attributeCount, tags, sizes, values);
- Q_ASSERT(err == noErr);
- Q_UNUSED(err);
-
- // various CTFont metrics functions: CTFontGetBoundingRectsForGlyphs, CTFontGetAdvancesForGlyphs
- GlyphID atsuGlyph = glyph;
- ATSGlyphScreenMetrics atsuMetrics;
- ATSUGlyphGetScreenMetrics(unscaledStyle, 1, &atsuGlyph, 0,
- /* iForcingAntiAlias =*/ false,
- /* iAntiAliasSwitch =*/true,
- &atsuMetrics);
-
- metrics->width = int(atsuMetrics.width);
- metrics->height = int(atsuMetrics.height);
- metrics->x = QFixed::fromReal(atsuMetrics.topLeft.x);
- metrics->y = -QFixed::fromReal(atsuMetrics.topLeft.y);
- metrics->xoff = QFixed::fromReal(atsuMetrics.deviceAdvance.x);
- metrics->yoff = QFixed::fromReal(atsuMetrics.deviceAdvance.y);
-
- QFixedPoint p;
- addGlyphsToPathHelper(unscaledStyle, &glyph, &p, 1, path);
-
- ATSUDisposeStyle(unscaledStyle);
-}
-#endif // !QT_MAC_USE_COCOA
-
QT_END_NAMESPACE
diff --git a/src/widgets/platforms/mac/qfontengine_mac_p.h b/src/widgets/platforms/mac/qfontengine_mac_p.h
index 10561e54d6..eab28ca5ac 100644
--- a/src/widgets/platforms/mac/qfontengine_mac_p.h
+++ b/src/widgets/platforms/mac/qfontengine_mac_p.h
@@ -44,122 +44,5 @@
#include <private/qfontengine_p.h>
-#ifndef QT_MAC_USE_COCOA
-class QFontEngineMacMulti;
-class QFontEngineMac : public QFontEngine
-{
- friend class QFontEngineMacMulti;
-public:
- QFontEngineMac(ATSUStyle baseStyle, ATSUFontID fontID, const QFontDef &def, QFontEngineMacMulti *multiEngine = 0);
- virtual ~QFontEngineMac();
-
- virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *numGlyphs, QTextEngine::ShaperFlags flags) const;
- virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
-
- virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
- virtual glyph_metrics_t boundingBox(glyph_t glyph);
-
- virtual QFixed ascent() const;
- virtual QFixed descent() const;
- virtual QFixed leading() const;
- virtual QFixed xHeight() const;
- virtual qreal maxCharWidth() const;
- virtual QFixed averageCharWidth() const;
-
- virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs,
- QPainterPath *path, QTextItem::RenderFlags);
-
- virtual const char *name() const { return "QFontEngineMac"; }
-
- virtual bool canRender(const QChar *string, int len);
-
- virtual int synthesized() const { return synthesisFlags; }
-
- virtual Type type() const { return QFontEngine::Mac; }
-
- void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight);
-
- virtual FaceId faceId() const;
- virtual QByteArray getSfntTable(uint tag) const;
- virtual Properties properties() const;
- virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics);
- virtual QImage alphaMapForGlyph(glyph_t);
- virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, int margin, const QTransform &t);
-
-private:
- QImage imageForGlyph(glyph_t glyph, int margin, bool colorful);
-
- ATSUFontID fontID;
- QCFType<CGFontRef> cgFont;
- ATSUStyle style;
- int synthesisFlags;
- mutable QGlyphLayout kashidaGlyph;
- QFontEngineMacMulti *multiEngine;
- mutable const unsigned char *cmap;
- mutable bool symbolCMap;
- mutable QByteArray cmapTable;
- CGAffineTransform transform;
- QFixed m_ascent;
- QFixed m_descent;
- QFixed m_leading;
- qreal m_maxCharWidth;
- QFixed m_xHeight;
- QFixed m_averageCharWidth;
-};
-
-class QFontEngineMacMulti : public QFontEngineMulti
-{
- friend class QFontEngineMac;
-public:
- // internal
- struct ShaperItem
- {
- inline ShaperItem() : string(0), from(0), length(0),
- log_clusters(0), charAttributes(0) {}
-
- const QChar *string;
- int from;
- int length;
- QGlyphLayout glyphs;
- unsigned short *log_clusters;
- const HB_CharAttributes *charAttributes;
- QTextEngine::ShaperFlags flags;
- };
-
- QFontEngineMacMulti(const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning);
- virtual ~QFontEngineMacMulti();
-
- virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
- bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags,
- unsigned short *logClusters, const HB_CharAttributes *charAttributes, QScriptItem *) const;
-
- virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
- virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const;
-
- virtual const char *name() const { return "ATSUI"; }
-
- virtual bool canRender(const QChar *string, int len);
-
- inline ATSUFontID macFontID() const { return fontID; }
-
-protected:
- virtual void loadEngine(int at);
-
-private:
- inline const QFontEngineMac *engineAt(int i) const
- { return static_cast<const QFontEngineMac *>(engines.at(i)); }
-
- bool stringToCMapInternal(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags, ShaperItem *item) const;
-
- int fontIndexForFontID(ATSUFontID id) const;
-
- ATSUFontID fontID;
- uint kerning : 1;
-
- mutable ATSUTextLayout textLayout;
- mutable ATSUStyle style;
- CGAffineTransform transform;
-};
-#endif //!QT_MAC_USE_COCOA
#endif // QFONTENGINE_MAC_P_H
diff --git a/src/widgets/platforms/mac/qkeymapper_mac.cpp b/src/widgets/platforms/mac/qkeymapper_mac.cpp
index 75a36673be..df18511b4f 100644
--- a/src/widgets/platforms/mac/qkeymapper_mac.cpp
+++ b/src/widgets/platforms/mac/qkeymapper_mac.cpp
@@ -435,10 +435,6 @@ static Boolean qt_KeyEventComparatorProc(EventRef inEvent, void *data)
static bool translateKeyEventInternal(EventHandlerCallRef er, EventRef keyEvent, int *qtKey,
QChar *outChar, Qt::KeyboardModifiers *outModifiers, bool *outHandled)
{
-#if !defined(QT_MAC_USE_COCOA) || defined(Q_OS_MAC64)
- Q_UNUSED(er);
- Q_UNUSED(outHandled);
-#endif
const UInt32 ekind = GetEventKind(keyEvent);
{
UInt32 mac_modifiers = 0;
@@ -534,14 +530,12 @@ static bool translateKeyEventInternal(EventHandlerCallRef er, EventRef keyEvent,
rightShiftKey|alphaLock)) | keyCode,
&tmp_unused_state);
if (!translatedChar) {
-#ifdef QT_MAC_USE_COCOA
if (outHandled) {
qt_mac_eat_unicode_key = false;
if (er)
CallNextEventHandler(er, keyEvent);
*outHandled = qt_mac_eat_unicode_key;
}
-#endif
return false;
}
@@ -774,26 +768,6 @@ bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, EventHandlerCallRef e
if (widget) {
-#ifndef QT_MAC_USE_COCOA
- Q_UNUSED(info);
- // Try not to call "other" event handlers if we have a popup,
- // However, if the key has text
- // then we should pass it along because otherwise then people
- // can use input method stuff.
- if (!qApp->activePopupWidget()
- || (qApp->activePopupWidget() && !text.isEmpty())) {
- //Find out if someone else wants the event, namely
- //is it of use to text services? If so we won't bother
- //with a QKeyEvent.
- qt_mac_eat_unicode_key = false;
- if (er)
- CallNextEventHandler(er, event);
- extern bool qt_mac_menubar_is_open();
- if (qt_mac_eat_unicode_key || qt_mac_menubar_is_open()) {
- return true;
- }
- }
-#endif
// Try to compress key events.
if (!text.isEmpty() && widget->testAttribute(Qt::WA_KeyCompression)) {
EventTime lastTime = GetEventTime(event);
@@ -866,7 +840,6 @@ bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, EventHandlerCallRef e
UInt32 macModifiers = 0;
GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, 0,
sizeof(macModifiers), 0, &macModifiers);
-#ifdef QT_MAC_USE_COCOA
// The unicode characters in the range 0xF700-0xF747 are reserved
// by Mac OS X for transient use as keyboard function keys. We
// wont send 'text' for such key events. This is done to match
@@ -875,27 +848,20 @@ bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, EventHandlerCallRef e
if (*unicodeKey >= 0xf700 && *unicodeKey <= 0xf747)
text = QString();
bool isAccepted;
-#endif
handled_event = QKeyMapper::sendKeyEvent(widget, grab,
(ekind == kEventRawKeyUp) ? QEvent::KeyRelease : QEvent::KeyPress,
qtKey, modifiers, text, ekind == kEventRawKeyRepeat, 0,
macScanCode, macVirtualKey, macModifiers
-#ifdef QT_MAC_USE_COCOA
,&isAccepted
-#endif
);
-#ifdef QT_MAC_USE_COCOA
*unicodeKey = (unsigned int)isAccepted;
-#endif
}
return handled_event;
}
void
QKeyMapperPrivate::updateKeyMap(EventHandlerCallRef, EventRef event, void *
-#if defined(QT_MAC_USE_COCOA)
unicodeKey // unicode character from NSEvent (modifiers applied)
-#endif
)
{
UInt32 macVirtualKey = 0;
diff --git a/src/widgets/platforms/mac/qmacgesturerecognizer_mac.mm b/src/widgets/platforms/mac/qmacgesturerecognizer_mac.mm
index 321f4fd38e..6e77f41d2d 100644
--- a/src/widgets/platforms/mac/qmacgesturerecognizer_mac.mm
+++ b/src/widgets/platforms/mac/qmacgesturerecognizer_mac.mm
@@ -159,7 +159,6 @@ void QMacPinchGestureRecognizer::reset(QGesture *gesture)
////////////////////////////////////////////////////////////////////////
-#if defined(QT_MAC_USE_COCOA)
QMacPanGestureRecognizer::QMacPanGestureRecognizer() : _panCanceled(true)
{
@@ -265,7 +264,6 @@ void QMacPanGestureRecognizer::reset(QGesture *gesture)
g->setAcceleration(qreal(1));
QGestureRecognizer::reset(gesture);
}
-#endif // QT_MAC_USE_COCOA
QT_END_NAMESPACE
diff --git a/src/widgets/platforms/mac/qmacgesturerecognizer_mac_p.h b/src/widgets/platforms/mac/qmacgesturerecognizer_mac_p.h
index f6f207336d..8d1bd337d7 100644
--- a/src/widgets/platforms/mac/qmacgesturerecognizer_mac_p.h
+++ b/src/widgets/platforms/mac/qmacgesturerecognizer_mac_p.h
@@ -81,7 +81,6 @@ public:
void reset(QGesture *gesture);
};
-#if defined(QT_MAC_USE_COCOA)
class QMacPanGestureRecognizer : public QObject, public QGestureRecognizer
{
@@ -97,7 +96,6 @@ private:
bool _panCanceled;
};
-#endif
QT_END_NAMESPACE
diff --git a/src/widgets/platforms/mac/qmacinputcontext_mac.cpp b/src/widgets/platforms/mac/qmacinputcontext_mac.cpp
index a98cee714b..43da4a911f 100644
--- a/src/widgets/platforms/mac/qmacinputcontext_mac.cpp
+++ b/src/widgets/platforms/mac/qmacinputcontext_mac.cpp
@@ -65,21 +65,11 @@ QMacInputContext::QMacInputContext(QObject *parent)
QMacInputContext::~QMacInputContext()
{
-#ifndef QT_MAC_USE_COCOA
- if(textDocument)
- DeleteTSMDocument(textDocument);
-#endif
}
void
QMacInputContext::createTextDocument()
{
-#ifndef QT_MAC_USE_COCOA
- if(!textDocument) {
- InterfaceTypeList itl = { kUnicodeDocument };
- NewTSMDocument(1, itl, &textDocument, SRefCon(this));
- }
-#endif
}
@@ -91,103 +81,27 @@ QString QMacInputContext::language()
void QMacInputContext::mouseHandler(int pos, QMouseEvent *e)
{
-#ifndef QT_MAC_USE_COCOA
- if(e->type() != QEvent::MouseButtonPress)
- return;
-
- if (!composing)
- return;
- if (pos < 0 || pos > currentText.length())
- reset();
- // ##### handle mouse position
-#else
Q_UNUSED(pos);
Q_UNUSED(e);
-#endif
-}
-
-#if !defined QT_MAC_USE_COCOA
-
-static QTextFormat qt_mac_compose_format()
-{
- QTextCharFormat ret;
- ret.setFontUnderline(true);
- return ret;
}
-void QMacInputContext::reset()
-{
- if (recursionGuard)
- return;
- if (!currentText.isEmpty()){
- QInputMethodEvent e;
- e.setCommitString(currentText);
- qt_sendSpontaneousEvent(focusWidget(), &e);
- currentText = QString();
- }
- recursionGuard = true;
- createTextDocument();
- composing = false;
- ActivateTSMDocument(textDocument);
- FixTSMDocument(textDocument);
- recursionGuard = false;
-}
-
-bool QMacInputContext::isComposing() const
-{
- return composing;
-}
-#endif
void QMacInputContext::setFocusWidget(QWidget *w)
{
createTextDocument();
-#ifndef QT_MAC_USE_COCOA
- if(w)
- ActivateTSMDocument(textDocument);
- else
- DeactivateTSMDocument(textDocument);
-#endif
QInputContext::setFocusWidget(w);
}
-#ifndef QT_MAC_USE_COCOA
-static EventTypeSpec input_events[] = {
- { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent },
- { kEventClassTextInput, kEventTextInputOffsetToPos },
- { kEventClassTextInput, kEventTextInputUpdateActiveInputArea }
-};
-static EventHandlerUPP input_proc_handlerUPP = 0;
-static EventHandlerRef input_proc_handler = 0;
-#endif
void
QMacInputContext::initialize()
{
-#ifndef QT_MAC_USE_COCOA
- if(!input_proc_handler) {
- input_proc_handlerUPP = NewEventHandlerUPP(QMacInputContext::globalEventProcessor);
- InstallEventHandler(GetApplicationEventTarget(), input_proc_handlerUPP,
- GetEventTypeCount(input_events), input_events,
- 0, &input_proc_handler);
- }
-#endif
}
void
QMacInputContext::cleanup()
{
-#ifndef QT_MAC_USE_COCOA
- if(input_proc_handler) {
- RemoveEventHandler(input_proc_handler);
- input_proc_handler = 0;
- }
- if(input_proc_handlerUPP) {
- DisposeEventHandlerUPP(input_proc_handlerUPP);
- input_proc_handlerUPP = 0;
- }
-#endif
}
void QMacInputContext::setLastKeydownEvent(EventRef event)
@@ -203,175 +117,7 @@ void QMacInputContext::setLastKeydownEvent(EventRef event)
OSStatus
QMacInputContext::globalEventProcessor(EventHandlerCallRef, EventRef event, void *)
{
-#ifndef QT_MAC_USE_COCOA
- QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
-
- SRefCon refcon = 0;
- GetEventParameter(event, kEventParamTextInputSendRefCon, typeRefCon, 0,
- sizeof(refcon), 0, &refcon);
- QMacInputContext *context = reinterpret_cast<QMacInputContext*>(refcon);
-
- bool handled_event=true;
- UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
- switch(eclass) {
- case kEventClassTextInput: {
- handled_event = false;
- QWidget *widget = QApplicationPrivate::focus_widget;
- bool canCompose = widget && (!context || widget->inputContext() == context)
- && !(widget->inputMethodHints() & Qt::ImhDigitsOnly
- || widget->inputMethodHints() & Qt::ImhFormattedNumbersOnly
- || widget->inputMethodHints() & Qt::ImhHiddenText);
- if(!canCompose) {
- handled_event = false;
- } else if(ekind == kEventTextInputOffsetToPos) {
- if(!widget->testAttribute(Qt::WA_InputMethodEnabled)) {
- handled_event = false;
- break;
- }
-
- QRect mr(widget->inputMethodQuery(Qt::ImMicroFocus).toRect());
- QPoint mp(widget->mapToGlobal(QPoint(mr.topLeft())));
- Point pt;
- pt.h = mp.x();
- pt.v = mp.y() + mr.height();
- SetEventParameter(event, kEventParamTextInputReplyPoint, typeQDPoint,
- sizeof(pt), &pt);
- handled_event = true;
- } else if(ekind == kEventTextInputUpdateActiveInputArea) {
- if(!widget->testAttribute(Qt::WA_InputMethodEnabled)) {
- handled_event = false;
- break;
- }
-
- if (context->recursionGuard)
- break;
-
- ByteCount unilen = 0;
- GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText,
- 0, 0, &unilen, 0);
- UniChar *unicode = (UniChar*)NewPtr(unilen);
- GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText,
- 0, unilen, 0, unicode);
- QString text((QChar*)unicode, unilen / sizeof(UniChar));
- DisposePtr((char*)unicode);
-
- ByteCount fixed_length = 0;
- GetEventParameter(event, kEventParamTextInputSendFixLen, typeByteCount, 0,
- sizeof(fixed_length), 0, &fixed_length);
- if(fixed_length == ULONG_MAX || fixed_length == unilen) {
- QInputMethodEvent e;
- e.setCommitString(text);
- context->currentText = QString();
- qt_sendSpontaneousEvent(context->focusWidget(), &e);
- handled_event = true;
- context->reset();
- } else {
- ByteCount rngSize = 0;
- OSStatus err = GetEventParameter(event, kEventParamTextInputSendHiliteRng, typeTextRangeArray, 0,
- 0, &rngSize, 0);
- QVarLengthArray<TextRangeArray> highlight(rngSize);
- if (noErr == err) {
- err = GetEventParameter(event, kEventParamTextInputSendHiliteRng, typeTextRangeArray, 0,
- rngSize, &rngSize, highlight.data());
- }
- context->composing = true;
- if(fixed_length > 0) {
- const int qFixedLength = fixed_length / sizeof(UniChar);
- QList<QInputMethodEvent::Attribute> attrs;
- attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
- qFixedLength, text.length()-qFixedLength,
- qt_mac_compose_format());
- QInputMethodEvent e(text, attrs);
- context->currentText = text;
- e.setCommitString(text.left(qFixedLength), 0, qFixedLength);
- qt_sendSpontaneousEvent(widget, &e);
- handled_event = true;
- } else {
- /* Apple's enums that they have removed from Tiger :(
- enum {
- kCaretPosition = 1,
- kRawText = 2,
- kSelectedRawText = 3,
- kConvertedText = 4,
- kSelectedConvertedText = 5,
- kBlockFillText = 6,
- kOutlineText = 7,
- kSelectedText = 8
- };
- */
-#ifndef kConvertedText
-#define kConvertedText 4
-#endif
-#ifndef kCaretPosition
-#define kCaretPosition 1
-#endif
- QList<QInputMethodEvent::Attribute> attrs;
- if (!highlight.isEmpty()) {
- TextRangeArray *data = highlight.data();
- for (int i = 0; i < data->fNumOfRanges; ++i) {
- int start = data->fRange[i].fStart / sizeof(UniChar);
- int len = (data->fRange[i].fEnd - data->fRange[i].fStart) / sizeof(UniChar);
- if (data->fRange[i].fHiliteStyle == kCaretPosition) {
- attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, start, 0, QVariant());
- continue;
- }
- QTextCharFormat format;
- format.setFontUnderline(true);
- if (data->fRange[i].fHiliteStyle == kConvertedText)
- format.setUnderlineColor(Qt::gray);
- else
- format.setUnderlineColor(Qt::black);
- attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, len, format);
- }
- } else {
- attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
- 0, text.length(), qt_mac_compose_format());
- }
- context->currentText = text;
- QInputMethodEvent e(text, attrs);
- qt_sendSpontaneousEvent(widget, &e);
- handled_event = true;
- }
- }
-#if 0
- if(!context->composing)
- handled_event = false;
-#endif
-
- extern bool qt_mac_eat_unicode_key; //qapplication_mac.cpp
- qt_mac_eat_unicode_key = handled_event;
- } else if(ekind == kEventTextInputUnicodeForKeyEvent) {
- EventRef key_ev = 0;
- GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, typeEventRef, 0,
- sizeof(key_ev), 0, &key_ev);
- QString text;
- ByteCount unilen = 0;
- if(GetEventParameter(key_ev, kEventParamKeyUnicodes, typeUnicodeText, 0, 0, &unilen, 0) == noErr) {
- UniChar *unicode = (UniChar*)NewPtr(unilen);
- GetEventParameter(key_ev, kEventParamKeyUnicodes, typeUnicodeText, 0, unilen, 0, unicode);
- text = QString((QChar*)unicode, unilen / sizeof(UniChar));
- DisposePtr((char*)unicode);
- }
- unsigned char chr = 0;
- GetEventParameter(key_ev, kEventParamKeyMacCharCodes, typeChar, 0, sizeof(chr), 0, &chr);
- if(!chr || chr >= 128 || (text.length() > 0 && (text.length() > 1 || text.at(0) != QLatin1Char(chr))))
- handled_event = !widget->testAttribute(Qt::WA_InputMethodEnabled);
- QMacInputContext *context = qobject_cast<QMacInputContext*>(qApp->inputContext());
- if (context && context->lastKeydownEvent()) {
- qt_keymapper_private()->translateKeyEvent(widget, 0, context->lastKeydownEvent(),
- 0, false);
- context->setLastKeydownEvent(0);
- }
- }
- break; }
- default:
- break;
- }
- if(!handled_event) //let the event go through
- return eventNotHandledErr;
-#else
Q_UNUSED(event);
-#endif
return noErr; //we eat the event
}
diff --git a/src/widgets/platforms/mac/qpaintengine_mac.cpp b/src/widgets/platforms/mac/qpaintengine_mac.cpp
index 3def016b56..af8e0e36c3 100644
--- a/src/widgets/platforms/mac/qpaintengine_mac.cpp
+++ b/src/widgets/platforms/mac/qpaintengine_mac.cpp
@@ -556,11 +556,7 @@ QCoreGraphicsPaintEngine::end()
Q_D(QCoreGraphicsPaintEngine);
setActive(false);
if(d->pdev->devType() == QInternal::Widget && static_cast<QWidget*>(d->pdev)->windowType() == Qt::Desktop) {
-#ifndef QT_MAC_USE_COCOA
- HideWindow(qt_mac_window_for(static_cast<QWidget*>(d->pdev)));
-#else
// // ### need to do [qt_mac_window_for(static_cast<QWidget *>(d->pdev)) orderOut]; (need to rename)
-#endif
}
if(d->shading) {
@@ -1045,11 +1041,7 @@ void QCoreGraphicsPaintEngine::drawTextItem(const QPointF &pos, const QTextItem
if (ti.glyphs.numGlyphs) {
switch (fe->type()) {
case QFontEngine::Mac:
-#ifdef QT_MAC_USE_COCOA
static_cast<QCoreTextFontEngine *>(fe)->draw(d->hd, pos.x(), pos.y(), ti, paintDevice()->height());
-#else
- static_cast<QFontEngineMac *>(fe)->draw(d->hd, pos.x(), pos.y(), ti, paintDevice()->height());
-#endif
break;
case QFontEngine::Box:
d->drawBoxTextItem(pos, ti);
diff --git a/src/widgets/platforms/mac/qpixmap_mac.cpp b/src/widgets/platforms/mac/qpixmap_mac.cpp
index a375eda6a2..48835c7d46 100644
--- a/src/widgets/platforms/mac/qpixmap_mac.cpp
+++ b/src/widgets/platforms/mac/qpixmap_mac.cpp
@@ -860,28 +860,6 @@ static QPixmap qt_mac_grabScreenRect(const QRect &rect)
return QPixmap::fromMacCGImageRef(image);
}
-#ifndef QT_MAC_USE_COCOA // no QuickDraw in 64-bit mode
-static QPixmap qt_mac_grabScreenRect_10_3(int x, int y, int w, int h, QWidget *widget)
-{
- QPixmap pm = QPixmap(w, h);
- extern WindowPtr qt_mac_window_for(const QWidget *); // qwidget_mac.cpp
- const BitMap *windowPort = 0;
- if((widget->windowType() == Qt::Desktop)) {
- GDHandle gdh;
- if(!(gdh=GetMainDevice()))
- qDebug("Qt: internal: Unexpected condition reached: %s:%d", __FILE__, __LINE__);
- windowPort = (BitMap*)(*(*gdh)->gdPMap);
- } else {
- windowPort = GetPortBitMapForCopyBits(GetWindowPort(qt_mac_window_for(widget)));
- }
- const BitMap *pixmapPort = GetPortBitMapForCopyBits(static_cast<GWorldPtr>(pm.macQDHandle()));
- Rect macSrcRect, macDstRect;
- SetRect(&macSrcRect, x, y, x + w, y + h);
- SetRect(&macDstRect, 0, 0, w, h);
- CopyBits(windowPort, pixmapPort, &macSrcRect, &macDstRect, srcCopy, 0);
- return pm;
-}
-#endif
QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
{
@@ -898,18 +876,7 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
globalCoord = widget->mapToGlobal(globalCoord);
QRect rect(globalCoord.x() + x, globalCoord.y() + y, w, h);
-#ifdef QT_MAC_USE_COCOA
return qt_mac_grabScreenRect(rect);
-#else
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
- return qt_mac_grabScreenRect(rect);
- } else
-#endif
- {
- return qt_mac_grabScreenRect_10_3(x, y, w, h, widget);
- }
-#endif // ifdef Q_WS_MAC64
}
/*! \internal
@@ -1005,85 +972,6 @@ CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr)
return px->cg_mask;
}
-#ifndef QT_MAC_USE_COCOA
-IconRef qt_mac_create_iconref(const QPixmap &px)
-{
- if (px.isNull())
- return 0;
-
- //create icon
- IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0));
- //create data
- {
- struct {
- OSType mac_type;
- int width, height, depth;
- bool mask;
- } images[] = {
- { kThumbnail32BitData, 128, 128, 32, false },
- { kThumbnail8BitMask, 128, 128, 8, true },
- { 0, 0, 0, 0, false } //end marker
- };
- for(int i = 0; images[i].mac_type; i++) {
- //get QPixmap data
- QImage scaled_px = px.toImage().scaled(images[i].width, images[i].height);
-
- quint32 *sptr = (quint32 *) scaled_px.bits();
- quint32 *srow;
- uint sbpr = scaled_px.bytesPerLine();
-
- //get Handle data
- const int dbpr = images[i].width * (images[i].depth/8);
- Handle hdl = NewHandle(dbpr*images[i].height);
- if(!sptr) { //handle null pixmap
- memset((*hdl), '\0', dbpr*images[i].height);
- } else if(images[i].mask) {
- if(images[i].mac_type == kThumbnail8BitMask) {
- for(int y = 0, hindex = 0; y < images[i].height; ++y) {
- srow = sptr + (y * (sbpr/4));
- for(int x = 0; x < images[i].width; ++x)
- *((*hdl)+(hindex++)) = qAlpha(*(srow+x));
- }
- }
- } else {
- char *dest = (*hdl);
-#if defined(__i386__)
- if(images[i].depth == 32) {
- for(int y = 0; y < images[i].height; ++y) {
- uint *source = (uint*)((const uchar*)sptr+(sbpr*y));
- for(int x = 0; x < images[i].width; ++x, dest += 4)
- *((uint*)dest) = CFSwapInt32(*(source + x));
- }
- } else
-#endif
- {
- for(int y = 0; y < images[i].height; ++y)
- memcpy(dest+(y*dbpr), ((const uchar*)sptr+(sbpr*y)), dbpr);
- }
- }
-
- //set the family data to the Handle
- OSStatus set = SetIconFamilyData(iconFamily, images[i].mac_type, hdl);
- if(set != noErr)
- qWarning("%s: %d -- Unable to create icon data[%d]!! %ld",
- __FILE__, __LINE__, i, long(set));
- DisposeHandle(hdl);
- }
- }
-
- //acquire and cleanup
- IconRef ret;
- static int counter = 0;
- const OSType kQtCreator = 'CUTE';
- RegisterIconRefFromIconFamily(kQtCreator, (OSType)counter, iconFamily, &ret);
- AcquireIconRef(ret);
- UnregisterIconRef(kQtCreator, (OSType)counter);
- DisposeHandle(reinterpret_cast<Handle>(iconFamily));
- counter++;
- return ret;
-
-}
-#endif
/*! \internal */
QPaintEngine* QMacPlatformPixmap::paintEngine() const
diff --git a/src/widgets/platforms/mac/qprintengine_mac.mm b/src/widgets/platforms/mac/qprintengine_mac.mm
index fb40677e2d..b01d7a5762 100644
--- a/src/widgets/platforms/mac/qprintengine_mac.mm
+++ b/src/widgets/platforms/mac/qprintengine_mac.mm
@@ -90,12 +90,7 @@ bool QMacPrintEngine::begin(QPaintDevice *dev)
}
}
OSStatus status = noErr;
-#ifndef QT_MAC_USE_COCOA
- status = d->shouldSuppressStatus() ? PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format)
- : PMSessionBeginCGDocument(d->session, d->settings, d->format);
-#else
status = PMSessionBeginCGDocumentNoDialog(d->session, d->settings, d->format);
-#endif
if (status != noErr) {
d->state = QPrinter::Error;
@@ -139,9 +134,7 @@ Qt::HANDLE QMacPrintEngine::handle() const
QMacPrintEnginePrivate::~QMacPrintEnginePrivate()
{
-#ifdef QT_MAC_USE_COCOA
[printInfo release];
-#endif
delete paintEngine;
}
@@ -250,12 +243,7 @@ bool QMacPrintEngine::newPage()
Q_D(QMacPrintEngine);
Q_ASSERT(d->state == QPrinter::Active);
OSStatus err =
-#ifndef QT_MAC_USE_COCOA
- d->shouldSuppressStatus() ? PMSessionEndPageNoDialog(d->session)
- : PMSessionEndPage(d->session);
-#else
PMSessionEndPageNoDialog(d->session);
-#endif
if (err != noErr) {
if (err == kPMCancel) {
// User canceled, we need to abort!
@@ -357,18 +345,7 @@ int QMacPrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
PMPrinter printer;
if(PMSessionGetCurrentPrinter(d->session, &printer) == noErr) {
PMResolution resolution;
-#ifndef QT_MAC_USE_COCOA
-# if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
- PMPrinterGetOutputResolution(printer, d->settings, &resolution);
- } else
-# endif
- {
- PMPrinterGetPrinterResolution(printer, kPMCurrentValue, &resolution);
- }
-#else
PMPrinterGetOutputResolution(printer, d->settings, &resolution);
-#endif
val = (int)resolution.vRes;
break;
}
@@ -397,11 +374,7 @@ void QMacPrintEnginePrivate::initialize()
{
Q_Q(QMacPrintEngine);
-#ifndef QT_MAC_USE_COCOA
- Q_ASSERT(!session);
-#else
Q_ASSERT(!printInfo);
-#endif
if (!paintEngine)
paintEngine = new QCoreGraphicsPaintEngine();
@@ -410,14 +383,9 @@ void QMacPrintEnginePrivate::initialize()
fullPage = false;
-#ifndef QT_MAC_USE_COCOA
- if (PMCreateSession(&session) != 0)
- session = 0;
-#else
QMacCocoaAutoReleasePool pool;
printInfo = [[NSPrintInfo alloc] initWithDictionary:[NSDictionary dictionary]];
session = static_cast<PMPrintSession>([printInfo PMPrintSession]);
-#endif
PMPrinter printer;
if (session && PMSessionGetCurrentPrinter(session, &printer) == noErr) {
@@ -441,32 +409,9 @@ void QMacPrintEnginePrivate::initialize()
}
}
-#ifndef QT_MAC_USE_COCOA
- bool settingsInitialized = (settings != 0);
- bool settingsOK = !settingsInitialized ? PMCreatePrintSettings(&settings) == noErr : true;
- if (settingsOK && !settingsInitialized)
- settingsOK = PMSessionDefaultPrintSettings(session, settings) == noErr;
-
-
- bool formatInitialized = (format != 0);
- bool formatOK = !formatInitialized ? PMCreatePageFormat(&format) == noErr : true;
- if (formatOK) {
- if (!formatInitialized) {
- formatOK = PMSessionDefaultPageFormat(session, format) == noErr;
- }
- formatOK = PMSessionValidatePageFormat(session, format, kPMDontWantBoolean) == noErr;
- }
-#else
settings = static_cast<PMPrintSettings>([printInfo PMPrintSettings]);
format = static_cast<PMPageFormat>([printInfo PMPageFormat]);
-#endif
-#ifndef QT_MAC_USE_COCOA
- if (!settingsOK || !formatOK) {
- qWarning("QMacPrintEngine::initialize: Unable to initialize QPainter");
- state = QPrinter::Error;
- }
-#endif
QHash<QMacPrintEngine::PrintEnginePropertyKey, QVariant>::const_iterator propC;
for (propC = valueCache.constBegin(); propC != valueCache.constEnd(); propC++) {
@@ -476,20 +421,9 @@ void QMacPrintEnginePrivate::initialize()
void QMacPrintEnginePrivate::releaseSession()
{
-#ifndef QT_MAC_USE_COCOA
- if (shouldSuppressStatus()) {
- PMSessionEndPageNoDialog(session);
- PMSessionEndDocumentNoDialog(session);
- } else {
- PMSessionEndPage(session);
- PMSessionEndDocument(session);
- }
- PMRelease(session);
-#else
PMSessionEndPageNoDialog(session);
PMSessionEndDocumentNoDialog(session);
[printInfo release];
-#endif
printInfo = 0;
session = 0;
}
@@ -512,12 +446,7 @@ bool QMacPrintEnginePrivate::newPage_helper()
cgEngine->d_func()->restoreGraphicsState();
OSStatus status =
-#ifndef QT_MAC_USE_COCOA
- shouldSuppressStatus() ? PMSessionBeginPageNoDialog(session, format, 0)
- : PMSessionBeginPage(session, format, 0);
-#else
PMSessionBeginPageNoDialog(session, format, 0);
-#endif
if(status != noErr) {
state = QPrinter::Error;
return false;
diff --git a/src/widgets/platforms/mac/qprintengine_mac_p.h b/src/widgets/platforms/mac/qprintengine_mac_p.h
index 5c4fe944e0..6c17818fbd 100644
--- a/src/widgets/platforms/mac/qprintengine_mac_p.h
+++ b/src/widgets/platforms/mac/qprintengine_mac_p.h
@@ -150,11 +150,7 @@ public:
QList<QVariant> supportedResolutions() const;
inline bool isPrintSessionInitialized() const
{
-#ifndef QT_MAC_USE_COCOA
- return session != 0;
-#else
return printInfo != 0;
-#endif
}
bool shouldSuppressStatus() const;
};
diff --git a/src/widgets/platforms/mac/qregion_mac.cpp b/src/widgets/platforms/mac/qregion_mac.cpp
index 94805a7f80..b929d9c283 100644
--- a/src/widgets/platforms/mac/qregion_mac.cpp
+++ b/src/widgets/platforms/mac/qregion_mac.cpp
@@ -47,152 +47,6 @@ QT_BEGIN_NAMESPACE
QRegion::QRegionData QRegion::shared_empty = { Q_BASIC_ATOMIC_INITIALIZER(1), 0 };
-#if defined(Q_WS_MAC32) && !defined(QT_MAC_USE_COCOA)
-#define RGN_CACHE_SIZE 200
-#ifdef RGN_CACHE_SIZE
-static bool rgncache_init = false;
-static int rgncache_used;
-static RgnHandle rgncache[RGN_CACHE_SIZE];
-static void qt_mac_cleanup_rgncache()
-{
- rgncache_init = false;
- for(int i = 0; i < RGN_CACHE_SIZE; ++i) {
- if(rgncache[i]) {
- --rgncache_used;
- DisposeRgn(rgncache[i]);
- rgncache[i] = 0;
- }
- }
-}
-#endif
-
-Q_WIDGETS_EXPORT RgnHandle qt_mac_get_rgn()
-{
-#ifdef RGN_CACHE_SIZE
- if(!rgncache_init) {
- rgncache_used = 0;
- rgncache_init = true;
- for(int i = 0; i < RGN_CACHE_SIZE; ++i)
- rgncache[i] = 0;
- qAddPostRoutine(qt_mac_cleanup_rgncache);
- } else if(rgncache_used) {
- for(int i = 0; i < RGN_CACHE_SIZE; ++i) {
- if(rgncache[i]) {
- RgnHandle ret = rgncache[i];
- SetEmptyRgn(ret);
- rgncache[i] = 0;
- --rgncache_used;
- return ret;
- }
- }
- }
-#endif
- return NewRgn();
-}
-
-Q_WIDGETS_EXPORT void qt_mac_dispose_rgn(RgnHandle r)
-{
-#ifdef RGN_CACHE_SIZE
- if(rgncache_init && rgncache_used < RGN_CACHE_SIZE) {
- for(int i = 0; i < RGN_CACHE_SIZE; ++i) {
- if(!rgncache[i]) {
- ++rgncache_used;
- rgncache[i] = r;
- return;
- }
- }
- }
-#endif
- DisposeRgn(r);
-}
-
-static OSStatus qt_mac_get_rgn_rect(UInt16 msg, RgnHandle, const Rect *rect, void *reg)
-{
- if(msg == kQDRegionToRectsMsgParse) {
- QRect rct(rect->left, rect->top, (rect->right - rect->left), (rect->bottom - rect->top));
- if(!rct.isEmpty())
- *((QRegion *)reg) += rct;
- }
- return noErr;
-}
-
-Q_WIDGETS_EXPORT QRegion qt_mac_convert_mac_region(RgnHandle rgn)
-{
- return QRegion::fromQDRgn(rgn);
-}
-
-QRegion QRegion::fromQDRgn(RgnHandle rgn)
-{
- QRegion ret;
- ret.detach();
- OSStatus oss = QDRegionToRects(rgn, kQDParseRegionFromTopLeft, qt_mac_get_rgn_rect, (void *)&ret);
- if(oss != noErr)
- return QRegion();
- return ret;
-}
-
-/*!
- \internal
- Create's a RegionHandle, it's the caller's responsibility to release.
-*/
-RgnHandle QRegion::toQDRgn() const
-{
- RgnHandle rgnHandle = qt_mac_get_rgn();
- if(d->qt_rgn && d->qt_rgn->numRects) {
- RgnHandle tmp_rgn = qt_mac_get_rgn();
- int n = d->qt_rgn->numRects;
- const QRect *qt_r = (n == 1) ? &d->qt_rgn->extents : d->qt_rgn->rects.constData();
- while (n--) {
- SetRectRgn(tmp_rgn,
- qMax(SHRT_MIN, qt_r->x()),
- qMax(SHRT_MIN, qt_r->y()),
- qMin(SHRT_MAX, qt_r->right() + 1),
- qMin(SHRT_MAX, qt_r->bottom() + 1));
- UnionRgn(rgnHandle, tmp_rgn, rgnHandle);
- ++qt_r;
- }
- qt_mac_dispose_rgn(tmp_rgn);
- }
- return rgnHandle;
-}
-
-/*!
- \internal
- Create's a RegionHandle, it's the caller's responsibility to release.
- Returns 0 if the QRegion overflows.
-*/
-RgnHandle QRegion::toQDRgnForUpdate_sys() const
-{
- RgnHandle rgnHandle = qt_mac_get_rgn();
- if(d->qt_rgn && d->qt_rgn->numRects) {
- RgnHandle tmp_rgn = qt_mac_get_rgn();
- int n = d->qt_rgn->numRects;
- const QRect *qt_r = (n == 1) ? &d->qt_rgn->extents : d->qt_rgn->rects.constData();
- while (n--) {
-
- // detect overflow. Tested for use with HIViewSetNeedsDisplayInRegion
- // in QWidgetPrivate::update_sys().
- enum { HIViewSetNeedsDisplayInRegionOverflow = 10000 }; // empirically determined conservative value
- if (qt_r->right() > HIViewSetNeedsDisplayInRegionOverflow || qt_r->bottom() > HIViewSetNeedsDisplayInRegionOverflow) {
- qt_mac_dispose_rgn(tmp_rgn);
- qt_mac_dispose_rgn(rgnHandle);
- return 0;
- }
-
- SetRectRgn(tmp_rgn,
- qMax(SHRT_MIN, qt_r->x()),
- qMax(SHRT_MIN, qt_r->y()),
- qMin(SHRT_MAX, qt_r->right() + 1),
- qMin(SHRT_MAX, qt_r->bottom() + 1));
- UnionRgn(rgnHandle, tmp_rgn, rgnHandle);
- ++qt_r;
- }
- qt_mac_dispose_rgn(tmp_rgn);
- }
- return rgnHandle;
-}
-
-#endif
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
OSStatus QRegion::shape2QRegionHelper(int inMessage, HIShapeRef,
@@ -239,18 +93,10 @@ HIMutableShapeRef QRegion::toHIMutableShape() const
} else
#endif
{
-#ifndef QT_MAC_USE_COCOA
- QCFType<HIShapeRef> qdShape = HIShapeCreateWithQDRgn(QMacSmartQuickDrawRegion(toQDRgn()));
- HIShapeUnion(qdShape, shape, shape);
-#endif
}
return shape;
}
-#if !defined(Q_WS_MAC64) && !defined(QT_MAC_USE_COCOA)
-typedef OSStatus (*PtrHIShapeGetAsQDRgn)(HIShapeRef, RgnHandle);
-static PtrHIShapeGetAsQDRgn ptrHIShapeGetAsQDRgn = 0;
-#endif
QRegion QRegion::fromHIShapeRef(HIShapeRef shape)
@@ -268,17 +114,6 @@ QRegion QRegion::fromHIShapeRef(HIShapeRef shape)
# endif
#endif
{
-#if !defined(Q_WS_MAC64) && !defined(QT_MAC_USE_COCOA)
- if (ptrHIShapeGetAsQDRgn == 0) {
- QLibrary library(QLatin1String("/System/Library/Frameworks/Carbon.framework/Carbon"));
- library.setLoadHints(QLibrary::ExportExternalSymbolsHint);
- ptrHIShapeGetAsQDRgn = reinterpret_cast<PtrHIShapeGetAsQDRgn>(library.resolve("HIShapeGetAsQDRgn"));
- }
- RgnHandle rgn = qt_mac_get_rgn();
- ptrHIShapeGetAsQDRgn(shape, rgn);
- returnRegion = QRegion::fromQDRgn(rgn);
- qt_mac_dispose_rgn(rgn);
-#endif
}
return returnRegion;
}
diff --git a/src/widgets/platforms/mac/qt_cocoa_helpers_mac.mm b/src/widgets/platforms/mac/qt_cocoa_helpers_mac.mm
index d1620b1489..20bb6bffbb 100644
--- a/src/widgets/platforms/mac/qt_cocoa_helpers_mac.mm
+++ b/src/widgets/platforms/mac/qt_cocoa_helpers_mac.mm
@@ -93,11 +93,9 @@
QT_BEGIN_NAMESPACE
-#ifdef QT_MAC_USE_COCOA
// Cmd + left mousebutton should produce a right button
// press (mainly for mac users with one-button mice):
static bool qt_leftButtonIsRightButton = false;
-#endif
Q_GLOBAL_STATIC(QMacWindowFader, macwindowFader);
@@ -120,27 +118,17 @@ void QMacWindowFader::performFade()
{
const QWidgetList myWidgetsToFade = m_windowsToFade;
const int widgetCount = myWidgetsToFade.count();
-#if QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:NSTimeInterval(m_duration)];
-#endif
for (int i = 0; i < widgetCount; ++i) {
QWidget *widget = m_windowsToFade.at(i);
OSWindowRef window = qt_mac_window_for(widget);
-#if QT_MAC_USE_COCOA
[[window animator] setAlphaValue:0.0];
QTimer::singleShot(qRound(m_duration * 1000), widget, SLOT(hide()));
-#else
- TransitionWindowOptions options = {0, m_duration, 0, 0};
- TransitionWindowWithOptions(window, kWindowFadeTransitionEffect, kWindowHideTransitionAction,
- 0, 1, &options);
-#endif
}
-#if QT_MAC_USE_COCOA
[NSAnimationContext endGrouping];
-#endif
m_duration = 0.250;
m_windowsToFade.clear();
}
@@ -154,22 +142,11 @@ extern void qt_mac_updateCursorWithWidgetUnderMouse(QWidget *widgetUnderMouse);
void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds)
{
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
-#endif
OSWindowRef wnd = static_cast<OSWindowRef>(window);
if (wnd) {
QWidget *widget;
-#if QT_MAC_USE_COCOA
widget = [wnd QT_MANGLE_NAMESPACE(qt_qwidget)];
-#else
- const UInt32 kWidgetCreatorQt = kEventClassQt;
- enum {
- kWidgetPropertyQWidget = 'QWId' //QWidget *
- };
- if (GetWindowProperty(static_cast<WindowRef>(window), kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(widget), 0, &widget) != noErr)
- widget = 0;
-#endif
if (widget) {
QMacWindowFader::currentFader()->setFadeDuration(durationSeconds);
QMacWindowFader::currentFader()->registerWindowToFade(widget);
@@ -184,7 +161,7 @@ struct dndenum_mapper
bool Qt2Mac;
};
-#if defined(QT_MAC_USE_COCOA) && defined(__OBJC__)
+#ifdef __OBJC__
static dndenum_mapper dnd_enums[] = {
{ NSDragOperationLink, Qt::LinkAction, true },
@@ -245,19 +222,12 @@ DnDParams *macCurrentDnDParameters()
bool macWindowIsTextured( void * /*OSWindowRef*/ window )
{
OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
return ( [wnd styleMask] & NSTexturedBackgroundWindowMask ) ? true : false;
-#else
- WindowAttributes currentAttributes;
- GetWindowAttributes(wnd, &currentAttributes);
- return (currentAttributes & kWindowMetalAttribute) ? true : false;
-#endif
}
void macWindowToolbarShow(const QWidget *widget, bool show )
{
OSWindowRef wnd = qt_mac_window_for(widget);
-#if QT_MAC_USE_COCOA
if (NSToolbar *toolbar = [wnd toolbar]) {
QMacCocoaAutoReleasePool pool;
if (show != [toolbar isVisible]) {
@@ -267,65 +237,38 @@ void macWindowToolbarShow(const QWidget *widget, bool show )
qt_widget_private(const_cast<QWidget *>(widget))->updateFrameStrut();
}
}
-#else
- qt_widget_private(const_cast<QWidget *>(widget))->updateFrameStrut();
- ShowHideWindowToolbar(wnd, show, false);
-#endif
}
void macWindowToolbarSet( void * /*OSWindowRef*/ window, void *toolbarRef )
{
OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
[wnd setToolbar:static_cast<NSToolbar *>(toolbarRef)];
-#else
- SetWindowToolbar(wnd, static_cast<HIToolbarRef>(toolbarRef));
-#endif
}
bool macWindowToolbarIsVisible( void * /*OSWindowRef*/ window )
{
OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
if (NSToolbar *toolbar = [wnd toolbar])
return [toolbar isVisible];
return false;
-#else
- return IsWindowToolbarVisible(wnd);
-#endif
}
void macWindowSetHasShadow( void * /*OSWindowRef*/ window, bool hasShadow )
{
OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
[wnd setHasShadow:BOOL(hasShadow)];
-#else
- if (hasShadow)
- ChangeWindowAttributes(wnd, 0, kWindowNoShadowAttribute);
- else
- ChangeWindowAttributes(wnd, kWindowNoShadowAttribute, 0);
-#endif
}
void macWindowFlush(void * /*OSWindowRef*/ window)
{
OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
[wnd flushWindowIfNeeded];
-#else
- HIWindowFlush(wnd);
-#endif
}
void qt_mac_update_mouseTracking(QWidget *widget)
{
-#ifdef QT_MAC_USE_COCOA
[qt_mac_nativeview_for(widget) updateTrackingAreas];
-#else
- Q_UNUSED(widget);
-#endif
}
OSStatus qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage)
@@ -352,13 +295,7 @@ InvalidContext:
bool qt_mac_checkForNativeSizeGrip(const QWidget *widget)
{
-#ifndef QT_MAC_USE_COCOA
- OSViewRef nativeSizeGrip = 0;
- HIViewFindByID(HIViewGetRoot(HIViewGetWindow(HIViewRef(widget->winId()))), kHIViewWindowGrowBoxID, &nativeSizeGrip);
- return (nativeSizeGrip != 0);
-#else
return [[reinterpret_cast<NSView *>(widget->effectiveWinId()) window] showsResizeIndicator];
-#endif
}
struct qt_mac_enum_mapper
{
@@ -426,7 +363,6 @@ QMacTabletHash *qt_mac_tablet_hash()
return tablet_hash();
}
-#ifdef QT_MAC_USE_COCOA
// Clears the QWidget pointer that each QCocoaView holds.
void qt_mac_clearCocoaViewQWidgetPointers(QWidget *widget)
@@ -454,7 +390,6 @@ void qt_dispatchTabletProximityEvent(void * /*NSEvent * */ tabletEvent)
[proximityEvent isEnteringProximity] };
qt_dispatchTabletProximityEvent(carbonProximityRec);
}
-#endif // QT_MAC_USE_COCOA
void qt_dispatchTabletProximityEvent(const ::TabletProximityRec &proxRec)
{
@@ -527,7 +462,6 @@ void qt_dispatchTabletProximityEvent(const ::TabletProximityRec &proxRec)
qt_sendSpontaneousEvent(qApp, &qtabletProximity);
}
-#ifdef QT_MAC_USE_COCOA
Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags)
{
@@ -621,7 +555,6 @@ bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widge
macScanCode, [event keyCode], [event modifierFlags]);
return qt_sendSpontaneousEvent(widgetToGetEvent, &ke) && ke.isAccepted();
}
-#endif
Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
{
@@ -640,11 +573,6 @@ Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent)
{
-#ifndef QT_MAC_USE_COCOA
- Q_UNUSED(keyEvent);
- Q_UNUSED(widgetToGetEvent);
- return false;
-#else
NSEvent *event = static_cast<NSEvent *>(keyEvent);
EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef]));
Q_ASSERT(key_event);
@@ -667,15 +595,10 @@ bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEve
bool consumed = qt_keymapper_private()->translateKeyEvent(widgetToGetEvent, 0, key_event, &info, true);
return consumed && (info != 0);
-#endif
}
void qt_dispatchModifiersChanged(void * /*NSEvent * */flagsChangedEvent, QWidget *widgetToGetEvent)
{
-#ifndef QT_MAC_USE_COCOA
- Q_UNUSED(flagsChangedEvent);
- Q_UNUSED(widgetToGetEvent);
-#else
UInt32 modifiers = 0;
// Sync modifiers with Qt
NSEvent *event = static_cast<NSEvent *>(flagsChangedEvent);
@@ -685,7 +608,6 @@ void qt_dispatchModifiersChanged(void * /*NSEvent * */flagsChangedEvent, QWidget
sizeof(modifiers), 0, &modifiers);
extern void qt_mac_send_modifiers_changed(quint32 modifiers, QObject *object);
qt_mac_send_modifiers_changed(modifiers, widgetToGetEvent);
-#endif
}
QPointF flipPoint(const NSPoint &p)
@@ -703,7 +625,7 @@ NSPoint flipPoint(const QPointF &p)
return NSMakePoint(p.x(), flipYCoordinate(p.y()));
}
-#if QT_MAC_USE_COCOA && __OBJC__
+#ifdef __OBJC__
void qt_mac_handleNonClientAreaMouseEvent(NSWindow *window, NSEvent *event)
{
@@ -1116,11 +1038,6 @@ bool qt_mac_handleMouseEvent(NSEvent *event, QEvent::Type eventType, Qt::MouseBu
bool qt_mac_handleTabletEvent(void * /*QCocoaView * */view, void * /*NSEvent * */tabletEvent)
{
-#ifndef QT_MAC_USE_COCOA
- Q_UNUSED(view);
- Q_UNUSED(tabletEvent);
- return false;
-#else
QT_MANGLE_NAMESPACE(QCocoaView) *theView = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view);
NSView *theNSView = static_cast<NSView *>(view);
NSEvent *theTabletEvent = static_cast<NSEvent *>(tabletEvent);
@@ -1209,29 +1126,16 @@ bool qt_mac_handleTabletEvent(void * /*QCocoaView * */view, void * /*NSEvent * *
qt_sendSpontaneousEvent(widgetToGetMouse, &qtabletEvent);
return qtabletEvent.isAccepted();
-#endif
}
void qt_mac_updateContentBorderMetricts(void * /*OSWindowRef */window, const ::HIContentBorderMetrics &metrics)
{
OSWindowRef theWindow = static_cast<OSWindowRef>(window);
-#if !defined(QT_MAC_USE_COCOA)
-# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
- ::HIWindowSetContentBorderThickness(theWindow, &metrics);
- }
-# else
- Q_UNUSED(window);
- Q_UNUSED(metrics);
-# endif
-#else
if ([theWindow styleMask] & NSTexturedBackgroundWindowMask)
[theWindow setContentBorderThickness:metrics.top forEdge:NSMaxYEdge];
[theWindow setContentBorderThickness:metrics.bottom forEdge:NSMinYEdge];
-#endif
}
-#if QT_MAC_USE_COCOA
void qt_mac_replaceDrawRect(void * /*OSWindowRef */window, QWidgetPrivate *widget)
{
QMacCocoaAutoReleasePool pool;
@@ -1294,9 +1198,7 @@ void qt_mac_replaceDrawRectOriginal(void * /*OSWindowRef */window, QWidgetPrivat
widget->originalDrawMethod = true;
[theWindow display];
}
-#endif // QT_MAC_USE_COCOA
-#if QT_MAC_USE_COCOA
void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show)
{
if(!window)
@@ -1306,7 +1208,6 @@ void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show)
NSToolbar *macToolbar = [theWindow toolbar];
[macToolbar setShowsBaselineSeparator:show];
}
-#endif // QT_MAC_USE_COCOA
QStringList qt_mac_NSArrayToQStringList(void *nsarray)
{
@@ -1326,7 +1227,6 @@ void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list)
return result;
}
-#if QT_MAC_USE_COCOA
void qt_syncCocoaTitleBarButtons(OSWindowRef window, QWidget *widgetForWindow)
{
if (!widgetForWindow)
@@ -1351,7 +1251,6 @@ void qt_syncCocoaTitleBarButtons(OSWindowRef window, QWidget *widgetForWindow)
[window setShowsToolbarButton:uint(flags & Qt::MacWindowToolBarButtonHint) != 0];
}
-#endif // QT_MAC_USE_COCOA
// Carbon: Make sure you call QDEndContext on the context when done with it.
CGContextRef qt_mac_graphicsContextFor(QWidget *widget)
@@ -1359,13 +1258,7 @@ CGContextRef qt_mac_graphicsContextFor(QWidget *widget)
if (!widget)
return 0;
-#ifndef QT_MAC_USE_COCOA
- CGContextRef context;
- CGrafPtr port = GetWindowPort(qt_mac_window_for(widget));
- QDBeginCGContext(port, &context);
-#else
CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithWindow:qt_mac_window_for(widget)] graphicsPort];
-#endif
return context;
}
@@ -1373,20 +1266,12 @@ void qt_mac_dispatchPendingUpdateRequests(QWidget *widget)
{
if (!widget)
return;
-#ifndef QT_MAC_USE_COCOA
- HIViewRender(qt_mac_nativeview_for(widget));
-#else
[qt_mac_nativeview_for(widget) displayIfNeeded];
-#endif
}
CGFloat qt_mac_get_scalefactor()
{
-#ifndef QT_MAC_USE_COCOA
- return HIGetScaleFactor();
-#else
return [[NSScreen mainScreen] userSpaceScaleFactor];
-#endif
}
QString qt_mac_get_pasteboardString(OSPasteboardRef paste)
@@ -1455,10 +1340,8 @@ void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayI
void qt_mac_post_retranslateAppMenu()
{
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
qt_cocoaPostMessage([NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)], @selector(qtTranslateApplicationMenu));
-#endif
}
QWidgetPrivate *QMacScrollOptimization::_target = 0;
@@ -1467,7 +1350,6 @@ int QMacScrollOptimization::_dx = 0;
int QMacScrollOptimization::_dy = 0;
QRect QMacScrollOptimization::_scrollRect = QRect(0, 0, -1, -1);
-#ifdef QT_MAC_USE_COCOA
// This method implements the magic for the drawRectSpecial method.
// We draw a line at the upper edge of the content view in order to
// override the title baseline.
@@ -1558,6 +1440,5 @@ void qt_mac_setNeedsDisplayInRect(QWidget *widget, QRegion region)
}
-#endif // QT_MAC_USE_COCOA
QT_END_NAMESPACE
diff --git a/src/widgets/platforms/mac/qt_mac.cpp b/src/widgets/platforms/mac/qt_mac.cpp
index 339bc82ff5..b3c9371d24 100644
--- a/src/widgets/platforms/mac/qt_mac.cpp
+++ b/src/widgets/platforms/mac/qt_mac.cpp
@@ -45,27 +45,14 @@
#include <qdebug.h>
QT_BEGIN_NAMESPACE
-#ifdef QT_MAC_USE_COCOA
static CTFontRef CopyCTThemeFont(ThemeFontID themeID)
{
CTFontUIFontType ctID = HIThemeGetUIFontType(themeID);
return CTFontCreateUIFontForLanguage(ctID, 0, 0);
}
-#endif
QFont qfontForThemeFont(ThemeFontID themeID)
{
-#ifndef QT_MAC_USE_COCOA
- static const ScriptCode Script = smRoman;
- Str255 f_name;
- SInt16 f_size;
- Style f_style;
- GetThemeFont(themeID, Script, f_name, &f_size, &f_style);
- extern QString qt_mac_from_pascal_string(const Str255); //qglobal.cpp
- return QFont(qt_mac_from_pascal_string(f_name), f_size,
- (f_style & ::bold) ? QFont::Bold : QFont::Normal,
- (bool)(f_style & ::italic));
-#else
QCFType<CTFontRef> ctfont = CopyCTThemeFont(themeID);
QString familyName = QCFString(CTFontCopyFamilyName(ctfont));
QCFType<CFDictionaryRef> dict = CTFontCopyTraits(ctfont);
@@ -77,7 +64,6 @@ QFont qfontForThemeFont(ThemeFontID themeID)
CFNumberGetValue(num, kCFNumberFloatType, &fW);
bool italic = (fW != 0.0);
return QFont(familyName, CTFontGetSize(ctfont), wght, italic);
-#endif
}
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
@@ -110,20 +96,7 @@ static inline QColor leopardBrush(ThemeBrush brush)
QColor qcolorForTheme(ThemeBrush brush)
{
-#ifndef QT_MAC_USE_COCOA
-# if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
- return leopardBrush(brush);
- } else
-# endif
- {
- RGBColor rgbcolor;
- GetThemeBrushAsColor(brush, 32, true, &rgbcolor);
- return QColor(rgbcolor.red / 256, rgbcolor.green / 256, rgbcolor.blue / 256);
- }
-#else
return leopardBrush(brush);
-#endif
}
QColor qcolorForThemeTextColor(ThemeTextColor themeColor)
diff --git a/src/widgets/platforms/mac/qt_mac_p.h b/src/widgets/platforms/mac/qt_mac_p.h
index 80328c3497..5a1d4ee42e 100644
--- a/src/widgets/platforms/mac/qt_mac_p.h
+++ b/src/widgets/platforms/mac/qt_mac_p.h
@@ -57,9 +57,7 @@
#ifdef __OBJC__
#include <Cocoa/Cocoa.h>
-#ifdef QT_MAC_USE_COCOA
#include <objc/runtime.h>
-#endif // QT_MAC_USE_COCOA
#endif
#include <CoreServices/CoreServices.h>
diff --git a/src/widgets/platforms/mac/qtextengine_mac.cpp b/src/widgets/platforms/mac/qtextengine_mac.cpp
index 251d9b5072..8ac58bbe3d 100644
--- a/src/widgets/platforms/mac/qtextengine_mac.cpp
+++ b/src/widgets/platforms/mac/qtextengine_mac.cpp
@@ -566,11 +566,7 @@ void QTextEngine::shapeTextMac(int item) const
return;
}
-#ifndef QT_MAC_USE_COCOA
- QFontEngineMacMulti *fe = static_cast<QFontEngineMacMulti *>(font);
-#else
QCoreTextFontEngineMulti *fe = static_cast<QCoreTextFontEngineMulti *>(font);
-#endif
QTextEngine::ShaperFlags flags;
if (si.analysis.bidiLevel % 2)
flags |= RightToLeft;
diff --git a/src/widgets/platforms/mac/qwidget_mac.mm b/src/widgets/platforms/mac/qwidget_mac.mm
index 39a4895357..dd958761a1 100644
--- a/src/widgets/platforms/mac/qwidget_mac.mm
+++ b/src/widgets/platforms/mac/qwidget_mac.mm
@@ -120,15 +120,6 @@ extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
#define XCOORD_MAX 16383
#define WRECT_MAX 8191
-#ifndef QT_MAC_USE_COCOA
-
-extern "C" {
- extern OSStatus _HIViewScrollRectWithOptions(HIViewRef, const HIRect *, CGFloat, CGFloat,
- OptionBits) __attribute__ ((weak));
-}
-#define kHIViewScrollRectAdjustInvalid 1
-#define kHIViewScrollRectDontInvalidateRevealedArea 2
-#endif
/*****************************************************************************
@@ -142,38 +133,12 @@ extern "C" {
/*****************************************************************************
QWidget globals
*****************************************************************************/
-#ifndef QT_MAC_USE_COCOA
-typedef QHash<Qt::WindowFlags, WindowGroupRef> WindowGroupHash;
-Q_GLOBAL_STATIC(WindowGroupHash, qt_mac_window_groups)
-const UInt32 kWidgetCreatorQt = kEventClassQt;
-enum {
- kWidgetPropertyQWidget = 'QWId' //QWidget *
-};
-#endif
static bool qt_mac_raise_process = true;
static OSWindowRef qt_root_win = 0;
QWidget *mac_mouse_grabber = 0;
QWidget *mac_keyboard_grabber = 0;
-#ifndef QT_MAC_USE_COCOA
-#ifdef QT_NAMESPACE
-
-// produce the string "com.trolltech.qt-namespace.widget", where "namespace" is the contents of QT_NAMESPACE.
-#define SS(x) #x
-#define S0(x) SS(x)
-#define S "com.trolltech.qt-" S0(QT_NAMESPACE) ".widget"
-
-static CFStringRef kObjectQWidget = CFSTR(S);
-
-#undef SS
-#undef S0
-#undef S
-
-#else
-static CFStringRef kObjectQWidget = CFSTR("com.trolltech.qt.widget");
-#endif // QT_NAMESPACE
-#endif // QT_MAC_USE_COCOA
/*****************************************************************************
Externals
@@ -216,7 +181,6 @@ static QSize qt_mac_desktopSize()
return QSize(w, h);
}
-#ifdef QT_MAC_USE_COCOA
static NSDrawer *qt_mac_drawer_for(const QWidget *widget)
{
NSView *widgetView = reinterpret_cast<NSView *>(widget->window()->effectiveWinId());
@@ -230,25 +194,18 @@ static NSDrawer *qt_mac_drawer_for(const QWidget *widget)
}
return 0;
}
-#endif
static void qt_mac_destructView(OSViewRef view)
{
-#ifdef QT_MAC_USE_COCOA
NSWindow *window = [view window];
if ([window contentView] == view)
[window setContentView:[[NSView alloc] initWithFrame:[view bounds]]];
[view removeFromSuperview];
[view release];
-#else
- HIViewRemoveFromSuperview(view);
- CFRelease(view);
-#endif
}
static void qt_mac_destructWindow(OSWindowRef window)
{
-#ifdef QT_MAC_USE_COCOA
if ([window isVisible] && [window isSheet]){
[NSApp endSheet:window];
[window orderOut:window];
@@ -256,21 +213,12 @@ static void qt_mac_destructWindow(OSWindowRef window)
[[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] resignDelegateForWindow:window];
[window release];
-#else
- // Remove property to clean up memory:
- RemoveWindowProperty(window, kWidgetCreatorQt, kWidgetPropertyQWidget);
- CFRelease(window);
-#endif
}
static void qt_mac_destructDrawer(NSDrawer *drawer)
{
-#ifdef QT_MAC_USE_COCOA
[[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] resignDelegateForDrawer:drawer];
[drawer release];
-#else
- Q_UNUSED(drawer);
-#endif
}
bool qt_mac_can_clickThrough(const QWidget *w)
@@ -306,11 +254,7 @@ bool qt_mac_is_macdrawer(const QWidget *w)
bool qt_mac_insideKeyWindow(const QWidget *w)
{
-#ifdef QT_MAC_USE_COCOA
return [[reinterpret_cast<NSView *>(w->effectiveWinId()) window] isKeyWindow];
-#else
- Q_UNUSED(w);
-#endif
return false;
}
@@ -319,7 +263,6 @@ bool qt_mac_set_drawer_preferred_edge(QWidget *w, Qt::DockWidgetArea where) //us
if(!qt_mac_is_macdrawer(w))
return false;
-#if QT_MAC_USE_COCOA
NSDrawer *drawer = qt_mac_drawer_for(w);
if (!drawer)
return false;
@@ -343,36 +286,9 @@ bool qt_mac_set_drawer_preferred_edge(QWidget *w, Qt::DockWidgetArea where) //us
[drawer openOnEdge:edge];
}
[drawer setPreferredEdge:edge];
-#else
- OSWindowRef window = qt_mac_window_for(w);
- OptionBits edge;
- if(where & Qt::LeftDockWidgetArea)
- edge = kWindowEdgeLeft;
- else if(where & Qt::RightDockWidgetArea)
- edge = kWindowEdgeRight;
- else if(where & Qt::TopDockWidgetArea)
- edge = kWindowEdgeTop;
- else if(where & Qt::BottomDockWidgetArea)
- edge = kWindowEdgeBottom;
- else
- return false;
-
- if(edge == GetDrawerPreferredEdge(window)) //no-op
- return false;
-
- //do it
- SetDrawerPreferredEdge(window, edge);
- if(w->isVisible()) {
- CloseDrawer(window, false);
- OpenDrawer(window, edge, true);
- }
-#endif
return true;
}
-#ifndef QT_MAC_USE_COCOA
-Q_GUI_EXPORT
-#endif
QPoint qt_mac_posInWindow(const QWidget *w)
{
QPoint ret = w->data->wrect.topLeft();
@@ -386,17 +302,7 @@ QPoint qt_mac_posInWindow(const QWidget *w)
//find a QWidget from a OSWindowRef
QWidget *qt_mac_find_window(OSWindowRef window)
{
-#ifdef QT_MAC_USE_COCOA
return [window QT_MANGLE_NAMESPACE(qt_qwidget)];
-#else
- if(!window)
- return 0;
-
- QWidget *ret;
- if(GetWindowProperty(window, kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(ret), 0, &ret) == noErr)
- return ret;
- return 0;
-#endif
}
inline static void qt_mac_set_fullscreen_mode(bool b)
@@ -426,19 +332,7 @@ Q_GUI_EXPORT OSViewRef qt_mac_effectiveview_for(const QWidget *w)
Q_GUI_EXPORT OSViewRef qt_mac_get_contentview_for(OSWindowRef w)
{
-#ifdef QT_MAC_USE_COCOA
return [w contentView];
-#else
- HIViewRef contentView = 0;
- OSStatus err = GetRootControl(w, &contentView); // Returns the window's content view (Apple QA1214)
- if (err == errUnknownControl) {
- contentView = HIViewGetRoot(w);
- } else if (err != noErr) {
- qWarning("Qt:Could not get content or root view of window! %s:%d [%ld]",
- __FILE__, __LINE__, err);
- }
- return contentView;
-#endif
}
bool qt_mac_sendMacEventToWidget(QWidget *widget, EventRef ref)
@@ -448,22 +342,14 @@ bool qt_mac_sendMacEventToWidget(QWidget *widget, EventRef ref)
Q_GUI_EXPORT OSWindowRef qt_mac_window_for(OSViewRef view)
{
-#ifdef QT_MAC_USE_COCOA
if (view)
return [view window];
return 0;
-#else
- return HIViewGetWindow(view);
-#endif
}
static bool qt_isGenuineQWidget(OSViewRef ref)
{
-#ifdef QT_MAC_USE_COCOA
return [ref isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]];
-#else
- return HIObjectIsOfClass(HIObjectRef(ref), kObjectQWidget);
-#endif
}
bool qt_isGenuineQWidget(const QWidget *window)
@@ -508,82 +394,7 @@ Q_GUI_EXPORT OSWindowRef qt_mac_window_for(const QWidget *w)
return 0;
}
-#ifndef QT_MAC_USE_COCOA
-/* Checks if the current group is a 'stay on top' group. If so, the
- group gets removed from the hash table */
-static void qt_mac_release_stays_on_top_group(WindowGroupRef group)
-{
- for (WindowGroupHash::iterator it = qt_mac_window_groups()->begin(); it != qt_mac_window_groups()->end(); ++it) {
- if (it.value() == group) {
- qt_mac_window_groups()->remove(it.key());
- return;
- }
- }
-}
-
-/* Use this function instead of ReleaseWindowGroup, this will be sure to release the
- stays on top window group (created with qt_mac_get_stays_on_top_group below) */
-static void qt_mac_release_window_group(WindowGroupRef group)
-{
- ReleaseWindowGroup(group);
- if (GetWindowGroupRetainCount(group) == 0)
- qt_mac_release_stays_on_top_group(group);
-}
-#define ReleaseWindowGroup(x) Are you sure you wanted to do that? (you wanted qt_mac_release_window_group)
-
-SInt32 qt_mac_get_group_level(WindowClass wclass)
-{
- SInt32 group_level;
- CGWindowLevel tmpLevel;
- GetWindowGroupLevelOfType(GetWindowGroupOfClass(wclass), kWindowGroupLevelActive, &tmpLevel);
- group_level = tmpLevel;
- return group_level;
-}
-#endif
-
-#ifndef QT_MAC_USE_COCOA
-static void qt_mac_set_window_group(OSWindowRef window, Qt::WindowFlags flags, int level)
-{
- WindowGroupRef group = 0;
- if (qt_mac_window_groups()->contains(flags)) {
- group = qt_mac_window_groups()->value(flags);
- RetainWindowGroup(group);
- } else {
- CreateWindowGroup(kWindowActivationScopeNone, &group);
- SetWindowGroupLevel(group, level);
- SetWindowGroupParent(group, GetWindowGroupOfClass(kAllWindowClasses));
- qt_mac_window_groups()->insert(flags, group);
- }
- SetWindowGroup(window, group);
-}
-
-inline static void qt_mac_set_window_group_to_stays_on_top(OSWindowRef window, Qt::WindowType type)
-{
- // We create one static stays on top window group so that
- // all stays on top (aka popups) will fall into the same
- // group and be able to be raise()'d with releation to one another (from
- // within the same window group).
- qt_mac_set_window_group(window, type|Qt::WindowStaysOnTopHint, qt_mac_get_group_level(kOverlayWindowClass));
-}
-
-inline static void qt_mac_set_window_group_to_tooltip(OSWindowRef window)
-{
- // Since new groups are created for 'stays on top' windows, the
- // same must be done for tooltips. Otherwise, tooltips would be drawn
- // below 'stays on top' widgets even tough they are on the same level.
- // Also, add 'two' to the group level to make sure they also get on top of popups.
- qt_mac_set_window_group(window, Qt::ToolTip, qt_mac_get_group_level(kHelpWindowClass)+2);
-}
-inline static void qt_mac_set_window_group_to_popup(OSWindowRef window)
-{
- // In Qt, a popup is seen as a 'stay on top' window.
- // Since new groups are created for 'stays on top' windows, the
- // same must be done for popups. Otherwise, popups would be drawn
- // below 'stays on top' windows. Add 1 to get above pure stay-on-top windows.
- qt_mac_set_window_group(window, Qt::Popup, qt_mac_get_group_level(kOverlayWindowClass)+1);
-}
-#endif
inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const QRect &rect)
{
@@ -625,14 +436,6 @@ inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const
void QWidgetPrivate::macSetNeedsDisplay(QRegion region)
{
Q_Q(QWidget);
-#ifndef QT_MAC_USE_COCOA
- if (region.isEmpty())
- HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true);
- else if (RgnHandle rgnHandle = region.toQDRgnForUpdate_sys())
- HIViewSetNeedsDisplayInRegion(qt_mac_nativeview_for(q), QMacSmartQuickDrawRegion(rgnHandle), true);
- else
- HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true); // do a complete repaint on overflow.
-#else
if (NSView *nativeView = qt_mac_nativeview_for(q)) {
// INVARIANT: q is _not_ alien. So we can optimize a little:
if (region.isEmpty()) {
@@ -664,7 +467,6 @@ void QWidgetPrivate::macSetNeedsDisplay(QRegion region)
}
}
}
-#endif
}
void QWidgetPrivate::macUpdateIsOpaque()
@@ -672,29 +474,13 @@ void QWidgetPrivate::macUpdateIsOpaque()
Q_Q(QWidget);
if (!q->testAttribute(Qt::WA_WState_Created))
return;
-#ifndef QT_MAC_USE_COCOA
- HIViewFeatures bits;
- HIViewRef hiview = qt_mac_nativeview_for(q);
- HIViewGetFeatures(hiview, &bits);
- if ((bits & kHIViewIsOpaque) == isOpaque)
- return;
- if (isOpaque) {
- HIViewChangeFeatures(hiview, kHIViewIsOpaque, 0);
- } else {
- HIViewChangeFeatures(hiview, 0, kHIViewIsOpaque);
- }
- if (q->isVisible())
- HIViewReshapeStructure(qt_mac_nativeview_for(q));
-#else
if (isRealWindow() && !q->testAttribute(Qt::WA_MacBrushedMetal)) {
bool opaque = isOpaque;
if (extra && extra->imageMask)
opaque = false; // we are never opaque when we have a mask.
[qt_mac_window_for(q) setOpaque:opaque];
}
-#endif
}
-#ifdef QT_MAC_USE_COCOA
static OSWindowRef qt_mac_create_window(QWidget *widget, WindowClass wclass,
NSUInteger wattr, const QRect &crect)
{
@@ -770,831 +556,9 @@ static OSWindowRef qt_mac_create_window(QWidget *widget, WindowClass wclass,
qt_syncCocoaTitleBarButtons(window, widget);
return window;
}
-#else
-static OSWindowRef qt_mac_create_window(QWidget *, WindowClass wclass, WindowAttributes wattr,
- const QRect &crect)
-{
- OSWindowRef window;
- Rect geo;
- SetRect(&geo, crect.left(), crect.top(), crect.right() + 1, crect.bottom() + 1);
- OSStatus err;
- if(geo.right <= geo.left) geo.right = geo.left + 1;
- if(geo.bottom <= geo.top) geo.bottom = geo.top + 1;
- Rect null_rect;
- SetRect(&null_rect, 0, 0, 1, 1);
- err = CreateNewWindow(wclass, wattr, &null_rect, &window);
- if(err == noErr) {
- err = SetWindowBounds(window, kWindowContentRgn, &geo);
- if(err != noErr)
- qWarning("QWidget: Internal error (%s:%d)", __FILE__, __LINE__);
- }
- return window;
-}
-
-#ifndef QT_NO_GESTURES
-#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
-/* We build the release package against the 10.4 SDK.
- So, to enable gestures for applications running on
- 10.6+, we define the missing constants here: */
-enum {
- kEventClassGesture = 'gest',
- kEventGestureStarted = 1,
- kEventGestureEnded = 2,
- kEventGestureMagnify = 4,
- kEventGestureSwipe = 5,
- kEventGestureRotate = 6,
- kEventParamRotationAmount = 'rota',
- kEventParamSwipeDirection = 'swip',
- kEventParamMagnificationAmount = 'magn'
-};
-#endif
-#endif // QT_NO_GESTURES
-
-// window events
-static EventTypeSpec window_events[] = {
- { kEventClassWindow, kEventWindowClose },
- { kEventClassWindow, kEventWindowExpanded },
- { kEventClassWindow, kEventWindowHidden },
- { kEventClassWindow, kEventWindowZoom },
- { kEventClassWindow, kEventWindowZoomed },
- { kEventClassWindow, kEventWindowCollapsed },
- { kEventClassWindow, kEventWindowToolbarSwitchMode },
- { kEventClassWindow, kEventWindowProxyBeginDrag },
- { kEventClassWindow, kEventWindowProxyEndDrag },
- { kEventClassWindow, kEventWindowResizeCompleted },
- { kEventClassWindow, kEventWindowBoundsChanging },
- { kEventClassWindow, kEventWindowGetRegion },
- { kEventClassWindow, kEventWindowGetClickModality },
- { kEventClassWindow, kEventWindowTransitionCompleted },
- { kEventClassGesture, kEventGestureStarted },
- { kEventClassGesture, kEventGestureEnded },
- { kEventClassGesture, kEventGestureMagnify },
- { kEventClassGesture, kEventGestureSwipe },
- { kEventClassGesture, kEventGestureRotate },
- { kEventClassMouse, kEventMouseDown }
-};
-static EventHandlerUPP mac_win_eventUPP = 0;
-static void cleanup_win_eventUPP()
-{
- DisposeEventHandlerUPP(mac_win_eventUPP);
- mac_win_eventUPP = 0;
-}
-static const EventHandlerUPP make_win_eventUPP()
-{
- if(mac_win_eventUPP)
- return mac_win_eventUPP;
- qAddPostRoutine(cleanup_win_eventUPP);
- return mac_win_eventUPP = NewEventHandlerUPP(QWidgetPrivate::qt_window_event);
-}
-OSStatus QWidgetPrivate::qt_window_event(EventHandlerCallRef er, EventRef event, void *)
-{
- QScopedLoopLevelCounter loopLevelCounter(qApp->d_func()->threadData);
- bool handled_event = true;
- UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
- switch(eclass) {
- case kEventClassWindow: {
- WindowRef wid = 0;
- GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0,
- sizeof(WindowRef), 0, &wid);
- QWidget *widget = qt_mac_find_window(wid);
- if(!widget) {
- handled_event = false;
- } else if(ekind == kEventWindowGetClickModality) {
- // Carbon will send us kEventWindowGetClickModality before every
- // mouse press / release event. By returning 'true', we tell Carbon
- // that we would like the event target to receive the mouse event even
- // if the target is modally shaddowed. In Qt, this makes sense when we
- // e.g. have a popup showing, as the popup will grab the event
- // and perhaps use it to close itself.
- // By also setting the current modal window back into the event, we
- // help Carbon determining which window is supposed to be raised.
- handled_event = qApp->activePopupWidget() ? true : false;
- } else if(ekind == kEventWindowClose) {
- widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
- QMenuBar::macUpdateMenuBar();
- } else if (ekind == kEventWindowTransitionCompleted) {
- WindowTransitionAction transitionAction;
- GetEventParameter(event, kEventParamWindowTransitionAction, typeWindowTransitionAction,
- 0, sizeof(transitionAction), 0, &transitionAction);
- if (transitionAction == kWindowHideTransitionAction)
- widget->hide();
- } else if(ekind == kEventWindowExpanded) {
- Qt::WindowStates currState = Qt::WindowStates(widget->data->window_state);
- Qt::WindowStates newState = currState;
- if (currState & Qt::WindowMinimized)
- newState &= ~Qt::WindowMinimized;
- if (!(currState & Qt::WindowActive))
- newState |= Qt::WindowActive;
- if (newState != currState) {
- // newState will differ from currState if the window
- // was expanded after clicking on the jewels (as opposed
- // to calling QWidget::setWindowState)
- widget->data->window_state = newState;
- QWindowStateChangeEvent e(currState);
- QApplication::sendSpontaneousEvent(widget, &e);
- }
-
- QShowEvent qse;
- QApplication::sendSpontaneousEvent(widget, &qse);
- } else if(ekind == kEventWindowZoom) {
- widget->d_func()->topData()->normalGeometry = widget->geometry();
- handled_event = false;
- } else if(ekind == kEventWindowZoomed) {
- WindowPartCode windowPart;
- GetEventParameter(event, kEventParamWindowPartCode,
- typeWindowPartCode, 0, sizeof(windowPart), 0, &windowPart);
- if(windowPart == inZoomIn && widget->isMaximized()) {
-
- widget->data->window_state = widget->data->window_state & ~Qt::WindowMaximized;
- QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state | Qt::WindowMaximized));
- QApplication::sendSpontaneousEvent(widget, &e);
- } else if(windowPart == inZoomOut && !widget->isMaximized()) {
- widget->data->window_state = widget->data->window_state | Qt::WindowMaximized;
- QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
- & ~Qt::WindowMaximized));
- QApplication::sendSpontaneousEvent(widget, &e);
- }
- qt_button_down = 0;
- } else if(ekind == kEventWindowCollapsed) {
- if (!widget->isMinimized()) {
- widget->data->window_state = widget->data->window_state | Qt::WindowMinimized;
- QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state & ~Qt::WindowMinimized));
- QApplication::sendSpontaneousEvent(widget, &e);
- }
-
- // Deactivate this window:
- if (widget->isActiveWindow() && !(widget->windowType() == Qt::Popup)) {
- QWidget *w = 0;
- if (widget->parentWidget())
- w = widget->parentWidget()->window();
- if (!w || (!w->isVisible() && !w->isMinimized())) {
- for (WindowPtr wp = GetFrontWindowOfClass(kDocumentWindowClass, true);
- wp; wp = GetNextWindowOfClass(wp, kDocumentWindowClass, true)) {
- if ((w = qt_mac_find_window(wp)))
- break;
- }
- }
- if(!(w && w->isVisible() && !w->isMinimized()))
- qApp->setActiveWindow(0);
- }
-
- //we send a hide to be like X11/Windows
- QEvent e(QEvent::Hide);
- QApplication::sendSpontaneousEvent(widget, &e);
- qt_button_down = 0;
- } else if(ekind == kEventWindowToolbarSwitchMode) {
- macSendToolbarChangeEvent(widget);
- HIToolbarRef toolbar;
- if (GetWindowToolbar(wid, &toolbar) == noErr) {
- if (toolbar) {
- // Let HIToolbar do its thang, but things like the OpenGL context
- // needs to know about it.
- CallNextEventHandler(er, event);
- qt_event_request_window_change(widget);
- widget->data->fstrut_dirty = true;
- }
- }
- } else if(ekind == kEventWindowGetRegion) {
- WindowRef window;
- GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0,
- sizeof(window), 0, &window);
- WindowRegionCode wcode;
- GetEventParameter(event, kEventParamWindowRegionCode, typeWindowRegionCode, 0,
- sizeof(wcode), 0, &wcode);
- if (wcode != kWindowOpaqueRgn){
- // If the region is kWindowOpaqueRgn, don't call next
- // event handler cause this will make the shadow of
- // masked windows become offset. Unfortunately, we're not sure why.
- CallNextEventHandler(er, event);
- }
- RgnHandle rgn;
- GetEventParameter(event, kEventParamRgnHandle, typeQDRgnHandle, 0,
- sizeof(rgn), 0, &rgn);
-
- if(QWidgetPrivate::qt_widget_rgn(qt_mac_find_window(window), wcode, rgn, false))
- SetEventParameter(event, kEventParamRgnHandle, typeQDRgnHandle, sizeof(rgn), &rgn);
- } else if(ekind == kEventWindowProxyBeginDrag) {
- QIconDragEvent e;
- QApplication::sendSpontaneousEvent(widget, &e);
- } else if(ekind == kEventWindowResizeCompleted) {
- // Create a mouse up event, since such an event is not send by carbon to the
- // application event handler (while a mouse down <b>is</b> on kEventWindowResizeStarted)
- EventRef mouseUpEvent;
- CreateEvent(0, kEventClassMouse, kEventMouseUp, 0, kEventAttributeUserEvent, &mouseUpEvent);
- UInt16 mbutton = kEventMouseButtonPrimary;
- SetEventParameter(mouseUpEvent, kEventParamMouseButton, typeMouseButton, sizeof(mbutton), &mbutton);
- WindowRef window;
- GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0, sizeof(window), 0, &window);
- Rect dragRect;
- GetWindowBounds(window, kWindowGrowRgn, &dragRect);
- Point pos = {dragRect.bottom, dragRect.right};
- SetEventParameter(mouseUpEvent, kEventParamMouseLocation, typeQDPoint, sizeof(pos), &pos);
- SendEventToApplication(mouseUpEvent);
- ReleaseEvent(mouseUpEvent);
- } else if(ekind == kEventWindowBoundsChanging) {
- UInt32 flags = 0;
- GetEventParameter(event, kEventParamAttributes, typeUInt32, 0,
- sizeof(flags), 0, &flags);
- Rect nr;
- GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, 0,
- sizeof(nr), 0, &nr);
-
- QRect newRect(nr.left, nr.top, nr.right - nr.left, nr.bottom - nr.top);
-
- QTLWExtra * const tlwExtra = widget->d_func()->maybeTopData();
- if (tlwExtra && tlwExtra->isSetGeometry == 1) {
- widget->d_func()->setGeometry_sys_helper(newRect.left(), newRect.top(), newRect.width(), newRect.height(), tlwExtra->isMove);
- } else {
- //implicitly removes the maximized bit
- if((widget->data->window_state & Qt::WindowMaximized) &&
- IsWindowInStandardState(wid, 0, 0)) {
- widget->data->window_state &= ~Qt::WindowMaximized;
- QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
- | Qt::WindowMaximized));
- QApplication::sendSpontaneousEvent(widget, &e);
-
- }
-
- handled_event = false;
- const QRect oldRect = widget->data->crect;
- if((flags & kWindowBoundsChangeOriginChanged)) {
- if(nr.left != oldRect.x() || nr.top != oldRect.y()) {
- widget->data->crect.moveTo(nr.left, nr.top);
- QMoveEvent qme(widget->data->crect.topLeft(), oldRect.topLeft());
- QApplication::sendSpontaneousEvent(widget, &qme);
- }
- }
- if((flags & kWindowBoundsChangeSizeChanged)) {
- if (widget->isWindow()) {
- QSize newSize = QLayout::closestAcceptableSize(widget, newRect.size());
- int dh = newSize.height() - newRect.height();
- int dw = newSize.width() - newRect.width();
- if (dw != 0 || dh != 0) {
- handled_event = true; // We want to change the bounds, so we handle the event
-
- // set the rect, so we can also do the resize down below (yes, we need to resize).
- newRect.setBottom(newRect.bottom() + dh);
- newRect.setRight(newRect.right() + dw);
-
- nr.left = newRect.x();
- nr.top = newRect.y();
- nr.right = nr.left + newRect.width();
- nr.bottom = nr.top + newRect.height();
- SetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, sizeof(Rect), &nr);
- }
- }
-
- if (oldRect.width() != newRect.width() || oldRect.height() != newRect.height()) {
- widget->data->crect.setSize(newRect.size());
- HIRect bounds = CGRectMake(0, 0, newRect.width(), newRect.height());
-
- // If the WA_StaticContents attribute is set we can optimize the resize
- // by only repainting the newly exposed area. We do this by disabling
- // painting when setting the size of the view. The OS will invalidate
- // the newly exposed area for us.
- const bool staticContents = widget->testAttribute(Qt::WA_StaticContents);
- const HIViewRef view = qt_mac_nativeview_for(widget);
- if (staticContents)
- HIViewSetDrawingEnabled(view, false);
- HIViewSetFrame(view, &bounds);
- if (staticContents)
- HIViewSetDrawingEnabled(view, true);
-
- QResizeEvent qre(newRect.size(), oldRect.size());
- QApplication::sendSpontaneousEvent(widget, &qre);
- qt_event_request_window_change(widget);
- }
- }
- }
- } else if (ekind == kEventWindowHidden) {
- // Make sure that we also hide any visible sheets on our window.
- // Cocoa does the right thing for us.
- const QObjectList children = widget->children();
- const int childCount = children.count();
- for (int i = 0; i < childCount; ++i) {
- QObject *obj = children.at(i);
- if (obj->isWidgetType()) {
- QWidget *widget = static_cast<QWidget *>(obj);
- if (qt_mac_is_macsheet(widget) && widget->isVisible())
- widget->hide();
- }
- }
- } else {
- handled_event = false;
- }
- break; }
- case kEventClassMouse: {
-#if 0
- return SendEventToApplication(event);
-#endif
-
- bool send_to_app = false;
- {
- WindowPartCode wpc;
- if (GetEventParameter(event, kEventParamWindowPartCode, typeWindowPartCode, 0,
- sizeof(wpc), 0, &wpc) == noErr && wpc != inContent)
- send_to_app = true;
- }
- if(!send_to_app) {
- WindowRef window;
- if(GetEventParameter(event, kEventParamWindowRef, typeWindowRef, 0,
- sizeof(window), 0, &window) == noErr) {
- HIViewRef hiview;
- if(HIViewGetViewForMouseEvent(HIViewGetRoot(window), event, &hiview) == noErr) {
- if(QWidget *w = QWidget::find((WId)hiview)) {
-#if 0
- send_to_app = !w->isActiveWindow();
-#else
- Q_UNUSED(w);
- send_to_app = true;
-#endif
- }
- }
- }
- }
- if(send_to_app)
- return SendEventToApplication(event);
- handled_event = false;
- break; }
-
-#ifndef QT_NO_GESTURES
- case kEventClassGesture: {
- // First, find the widget that was under
- // the mouse when the gesture happened:
- HIPoint screenLocation;
- if (GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, 0,
- sizeof(screenLocation), 0, &screenLocation) != noErr) {
- handled_event = false;
- break;
- }
- QWidget *widget = QApplication::widgetAt(screenLocation.x, screenLocation.y);
- if (!widget) {
- handled_event = false;
- break;
- }
-
- QNativeGestureEvent qNGEvent;
- qNGEvent.position = QPoint(screenLocation.x, screenLocation.y);
-
- switch (ekind) {
- case kEventGestureStarted:
- qNGEvent.gestureType = QNativeGestureEvent::GestureBegin;
- break;
- case kEventGestureEnded:
- qNGEvent.gestureType = QNativeGestureEvent::GestureEnd;
- break;
- case kEventGestureRotate: {
- CGFloat amount;
- if (GetEventParameter(event, kEventParamRotationAmount, 'cgfl', 0,
- sizeof(amount), 0, &amount) != noErr) {
- handled_event = false;
- break;
- }
- qNGEvent.gestureType = QNativeGestureEvent::Rotate;
- qNGEvent.percentage = float(-amount);
- break; }
- case kEventGestureSwipe: {
- HIPoint swipeDirection;
- if (GetEventParameter(event, kEventParamSwipeDirection, typeHIPoint, 0,
- sizeof(swipeDirection), 0, &swipeDirection) != noErr) {
- handled_event = false;
- break;
- }
- qNGEvent.gestureType = QNativeGestureEvent::Swipe;
- if (swipeDirection.x == 1)
- qNGEvent.angle = 180.0f;
- else if (swipeDirection.x == -1)
- qNGEvent.angle = 0.0f;
- else if (swipeDirection.y == 1)
- qNGEvent.angle = 90.0f;
- else if (swipeDirection.y == -1)
- qNGEvent.angle = 270.0f;
- break; }
- case kEventGestureMagnify: {
- CGFloat amount;
- if (GetEventParameter(event, kEventParamMagnificationAmount, 'cgfl', 0,
- sizeof(amount), 0, &amount) != noErr) {
- handled_event = false;
- break;
- }
- qNGEvent.gestureType = QNativeGestureEvent::Zoom;
- qNGEvent.percentage = float(amount);
- break; }
- }
-
- QApplication::sendSpontaneousEvent(widget, &qNGEvent);
- break; }
-#endif // QT_NO_GESTURES
-
- default:
- handled_event = false;
- }
- if(!handled_event) //let the event go through
- return eventNotHandledErr;
- return noErr; //we eat the event
-}
-
-// widget events
-static HIObjectClassRef widget_class = 0;
-static EventTypeSpec widget_events[] = {
- { kEventClassHIObject, kEventHIObjectConstruct },
- { kEventClassHIObject, kEventHIObjectDestruct },
-
- { kEventClassControl, kEventControlDraw },
- { kEventClassControl, kEventControlInitialize },
- { kEventClassControl, kEventControlGetPartRegion },
- { kEventClassControl, kEventControlGetClickActivation },
- { kEventClassControl, kEventControlSetFocusPart },
- { kEventClassControl, kEventControlDragEnter },
- { kEventClassControl, kEventControlDragWithin },
- { kEventClassControl, kEventControlDragLeave },
- { kEventClassControl, kEventControlDragReceive },
- { kEventClassControl, kEventControlOwningWindowChanged },
- { kEventClassControl, kEventControlBoundsChanged },
- { kEventClassControl, kEventControlGetSizeConstraints },
- { kEventClassControl, kEventControlVisibilityChanged },
-
- { kEventClassMouse, kEventMouseDown },
- { kEventClassMouse, kEventMouseUp },
- { kEventClassMouse, kEventMouseMoved },
- { kEventClassMouse, kEventMouseDragged }
-};
-static EventHandlerUPP mac_widget_eventUPP = 0;
-static void cleanup_widget_eventUPP()
-{
- DisposeEventHandlerUPP(mac_widget_eventUPP);
- mac_widget_eventUPP = 0;
-}
-static const EventHandlerUPP make_widget_eventUPP()
-{
- if(mac_widget_eventUPP)
- return mac_widget_eventUPP;
- qAddPostRoutine(cleanup_widget_eventUPP);
- return mac_widget_eventUPP = NewEventHandlerUPP(QWidgetPrivate::qt_widget_event);
-}
-OSStatus QWidgetPrivate::qt_widget_event(EventHandlerCallRef er, EventRef event, void *)
-{
- QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
-
- bool handled_event = true;
- UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
- switch(eclass) {
- case kEventClassHIObject: {
- HIViewRef view = 0;
- GetEventParameter(event, kEventParamHIObjectInstance, typeHIObjectRef,
- 0, sizeof(view), 0, &view);
- if(ekind == kEventHIObjectConstruct) {
- if(view) {
- HIViewChangeFeatures(view, kHIViewAllowsSubviews, 0);
- SetEventParameter(event, kEventParamHIObjectInstance,
- typeVoidPtr, sizeof(view), &view);
- }
- } else if(ekind == kEventHIObjectDestruct) {
- //nothing to really do.. or is there?
- } else {
- handled_event = false;
- }
- break; }
- case kEventClassControl: {
- QWidget *widget = 0;
- HIViewRef hiview = 0;
- if(GetEventParameter(event, kEventParamDirectObject, typeControlRef,
- 0, sizeof(hiview), 0, &hiview) == noErr)
- widget = QWidget::find((WId)hiview);
- if (widget && widget->macEvent(er, event))
- return noErr;
- if(ekind == kEventControlDraw) {
- if(widget && qt_isGenuineQWidget(hiview)) {
-
- // if there is a window change event pending for any gl child wigets,
- // send it immediately. (required for flicker-free resizing)
- extern void qt_mac_send_posted_gl_updates(QWidget *widget);
- qt_mac_send_posted_gl_updates(widget);
-
- if (QApplicationPrivate::graphicsSystem() && !widget->d_func()->paintOnScreen()) {
- widget->d_func()->syncBackingStore();
- widget->d_func()->dirtyOnWidget = QRegion();
- return noErr;
- }
-
- //requested rgn
- RgnHandle rgn;
- GetEventParameter(event, kEventParamRgnHandle, typeQDRgnHandle, 0, sizeof(rgn), 0, &rgn);
- QRegion qrgn(qt_mac_convert_mac_region(rgn));
-
- //update handles
- GrafPtr qd = 0;
- CGContextRef cg = 0;
- if(GetEventParameter(event, kEventParamCGContextRef, typeCGContextRef, 0, sizeof(cg), 0, &cg) != noErr) {
- Q_ASSERT(false);
- }
- widget->d_func()->hd = cg;
- widget->d_func()->qd_hd = qd;
- CGContextSaveGState(cg);
-
-#ifdef DEBUG_WIDGET_PAINT
- const bool doDebug = true;
- if(doDebug) {
- qDebug("asked to draw %p[%p] [%s::%s] %p[%p] [%d] [%dx%d]", widget, hiview, widget->metaObject()->className(),
- widget->objectName().local8Bit().data(), widget->parentWidget(),
- (HIViewRef)(widget->parentWidget() ? qt_mac_nativeview_for(widget->parentWidget()) : (HIViewRef)0),
- HIViewIsCompositingEnabled(hiview), qt_mac_posInWindow(widget).x(), qt_mac_posInWindow(widget).y());
-#if 0
- QVector<QRect> region_rects = qrgn.rects();
- qDebug("Region! %d", region_rects.count());
- for(int i = 0; i < region_rects.count(); i++)
- qDebug("%d %d %d %d", region_rects[i].x(), region_rects[i].y(),
- region_rects[i].width(), region_rects[i].height());
- region_rects = widget->d_func()->clp.rects();
- qDebug("Widget Region! %d", region_rects.count());
- for(int i = 0; i < region_rects.count(); i++)
- qDebug("%d %d %d %d", region_rects[i].x(), region_rects[i].y(),
- region_rects[i].width(), region_rects[i].height());
-#endif
- }
-#endif
- if (widget->isVisible() && widget->updatesEnabled()) { //process the actual paint event.
- if(widget->testAttribute(Qt::WA_WState_InPaintEvent))
- qWarning("QWidget::repaint: Recursive repaint detected");
- if (widget->isWindow() && !widget->d_func()->isOpaque
- && !widget->testAttribute(Qt::WA_MacBrushedMetal)) {
- QRect qrgnRect = qrgn.boundingRect();
- CGContextClearRect(cg, CGRectMake(qrgnRect.x(), qrgnRect.y(), qrgnRect.width(), qrgnRect.height()));
- }
-
- QPoint redirectionOffset(0, 0);
- QWidget *tl = widget->window();
- if (tl) {
- Qt::WindowFlags flags = tl->windowFlags();
- if (flags & Qt::FramelessWindowHint
- || (flags & Qt::CustomizeWindowHint && !(flags & Qt::WindowTitleHint))) {
- if(tl->d_func()->extra && !tl->d_func()->extra->mask.isEmpty())
- redirectionOffset += tl->d_func()->extra->mask.boundingRect().topLeft();
- }
- }
-
- //setup the context
- widget->setAttribute(Qt::WA_WState_InPaintEvent);
- QPaintEngine *engine = widget->paintEngine();
- if (engine)
- engine->setSystemClip(qrgn);
-
- //handle the erase
- if (engine && (!widget->testAttribute(Qt::WA_NoSystemBackground)
- && (widget->isWindow() || widget->autoFillBackground())
- || widget->testAttribute(Qt::WA_TintedBackground)
- || widget->testAttribute(Qt::WA_StyledBackground))) {
-#ifdef DEBUG_WIDGET_PAINT
- if(doDebug)
- qDebug(" Handling erase for [%s::%s]", widget->metaObject()->className(),
- widget->objectName().local8Bit().data());
-#endif
- if (!redirectionOffset.isNull())
- widget->d_func()->setRedirected(widget, redirectionOffset);
-
- bool was_unclipped = widget->testAttribute(Qt::WA_PaintUnclipped);
- widget->setAttribute(Qt::WA_PaintUnclipped, false);
- QPainter p(widget);
- p.setClipping(false);
- if(was_unclipped)
- widget->setAttribute(Qt::WA_PaintUnclipped);
- widget->d_func()->paintBackground(&p, qrgn, widget->isWindow() ? DrawAsRoot : 0);
- if (widget->testAttribute(Qt::WA_TintedBackground)) {
- QColor tint = widget->palette().window().color();
- tint.setAlphaF(.6);
- const QVector<QRect> &rects = qrgn.rects();
- for (int i = 0; i < rects.size(); ++i)
- p.fillRect(rects.at(i), tint);
- }
- p.end();
- if (!redirectionOffset.isNull())
- widget->d_func()->restoreRedirected();
- }
-
- if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
- CallNextEventHandler(er, event);
-
- //send the paint
- redirectionOffset += widget->data->wrect.topLeft(); // Map from system to qt coordinates
- if (!redirectionOffset.isNull())
- widget->d_func()->setRedirected(widget, redirectionOffset);
- qrgn.translate(redirectionOffset);
- QPaintEvent e(qrgn);
- widget->d_func()->dirtyOnWidget = QRegion();
- QApplication::sendSpontaneousEvent(widget, &e);
- if (!redirectionOffset.isNull())
- widget->d_func()->restoreRedirected();
-
- //cleanup
- if (engine)
- engine->setSystemClip(QRegion());
-
- widget->setAttribute(Qt::WA_WState_InPaintEvent, false);
- if(!widget->testAttribute(Qt::WA_PaintOutsidePaintEvent) && widget->paintingActive())
- qWarning("QWidget: It is dangerous to leave painters active on a widget outside of the PaintEvent");
- }
-
- widget->d_func()->hd = 0;
- widget->d_func()->qd_hd = 0;
- CGContextRestoreGState(cg);
- } else if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) {
- CallNextEventHandler(er, event);
- }
- } else if(ekind == kEventControlInitialize) {
- if(HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) {
- UInt32 features = kControlSupportsDragAndDrop | kControlSupportsClickActivation | kControlSupportsFocus;
- SetEventParameter(event, kEventParamControlFeatures, typeUInt32, sizeof(features), &features);
- } else {
- handled_event = false;
- }
- } else if(ekind == kEventControlSetFocusPart) {
- if(widget) {
- ControlPartCode part;
- GetEventParameter(event, kEventParamControlPart, typeControlPartCode, 0,
- sizeof(part), 0, &part);
- if(part == kControlFocusNoPart){
- if (widget->hasFocus())
- QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason);
- } else
- widget->setFocus();
- }
- if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
- CallNextEventHandler(er, event);
- } else if(ekind == kEventControlGetClickActivation) {
- ClickActivationResult clickT = kActivateAndIgnoreClick;
- SetEventParameter(event, kEventParamClickActivation, typeClickActivationResult,
- sizeof(clickT), &clickT);
- } else if(ekind == kEventControlGetPartRegion) {
- handled_event = false;
- if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget) && CallNextEventHandler(er, event) == noErr) {
- handled_event = true;
- break;
- }
- if(widget && !widget->isWindow()) {
- ControlPartCode part;
- GetEventParameter(event, kEventParamControlPart, typeControlPartCode, 0,
- sizeof(part), 0, &part);
- if(part == kControlClickableMetaPart && widget->testAttribute(Qt::WA_TransparentForMouseEvents)) {
- RgnHandle rgn;
- GetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, 0,
- sizeof(rgn), 0, &rgn);
- SetEmptyRgn(rgn);
- handled_event = true;
- } else if(part == kControlStructureMetaPart || part == kControlClickableMetaPart) {
- RgnHandle rgn;
- GetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, 0,
- sizeof(rgn), 0, &rgn);
- SetRectRgn(rgn, 0, 0, widget->width(), widget->height());
- if(QWidgetPrivate::qt_widget_rgn(widget, kWindowStructureRgn, rgn, false))
- handled_event = true;
- } else if(part == kControlOpaqueMetaPart) {
- if(widget->d_func()->isOpaque) {
- RgnHandle rgn;
- GetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, 0,
- sizeof(RgnHandle), 0, &rgn);
- SetRectRgn(rgn, 0, 0, widget->width(), widget->height());
- QWidgetPrivate::qt_widget_rgn(widget, kWindowStructureRgn, rgn, false);
- SetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle,
- sizeof(RgnHandle), &rgn);
- handled_event = true;
- }
- }
- }
- } else if(ekind == kEventControlOwningWindowChanged) {
- if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
- CallNextEventHandler(er, event);
- if(widget && qt_mac_window_for(hiview)) {
- WindowRef foo = 0;
- GetEventParameter(event, kEventParamControlCurrentOwningWindow, typeWindowRef, 0,
- sizeof(foo), 0, &foo);
- widget->d_func()->initWindowPtr();
- }
- if (widget)
- qt_event_request_window_change(widget);
- } else if(ekind == kEventControlDragEnter || ekind == kEventControlDragWithin ||
- ekind == kEventControlDragLeave || ekind == kEventControlDragReceive) {
- // dnd are really handled in qdnd_mac.cpp,
- // just modularize the code a little...
- DragRef drag;
- GetEventParameter(event, kEventParamDragRef, typeDragRef, 0, sizeof(drag), 0, &drag);
- handled_event = false;
- bool drag_allowed = false;
-
- QWidget *dropWidget = widget;
- if (qobject_cast<QFocusFrame *>(widget)){
- // We might shadow widgets underneath the focus
- // frame, so stay interrested, and let the dnd through
- drag_allowed = true;
- handled_event = true;
- Point where;
- GetDragMouse(drag, &where, 0);
- dropWidget = QApplication::widgetAt(QPoint(where.h, where.v));
-
- if (dropWidget != QDragManager::self()->currentTarget()) {
- // We have to 'fake' enter and leave events for the shaddowed widgets:
- if (ekind == kEventControlDragEnter) {
- if (QDragManager::self()->currentTarget())
- QDragManager::self()->currentTarget()->d_func()->qt_mac_dnd_event(kEventControlDragLeave, drag);
- if (dropWidget) {
- dropWidget->d_func()->qt_mac_dnd_event(kEventControlDragEnter, drag);
- }
- // Set dropWidget to zero, so qt_mac_dnd_event
- // doesn't get called a second time below:
- dropWidget = 0;
- } else if (ekind == kEventControlDragLeave) {
- dropWidget = QDragManager::self()->currentTarget();
- if (dropWidget) {
- dropWidget->d_func()->qt_mac_dnd_event(kEventControlDragLeave, drag);
- }
- // Set dropWidget to zero, so qt_mac_dnd_event
- // doesn't get called a second time below:
- dropWidget = 0;
- }
- }
- }
-
- // Send the dnd event to the widget:
- if (dropWidget && dropWidget->d_func()->qt_mac_dnd_event(ekind, drag)) {
- drag_allowed = true;
- handled_event = true;
- }
-
- if (ekind == kEventControlDragEnter) {
- // If we don't accept the enter event, we will
- // receive no more drag events for this widget
- const Boolean wouldAccept = drag_allowed ? true : false;
- SetEventParameter(event, kEventParamControlWouldAcceptDrop, typeBoolean,
- sizeof(wouldAccept), &wouldAccept);
- }
- } else if (ekind == kEventControlBoundsChanged) {
- if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_Moved) || widget->testAttribute(Qt::WA_Resized)) {
- handled_event = false;
- } else {
- // Sync our view in case some other (non-Qt) view is controlling us.
- handled_event = true;
- Rect newBounds;
- GetEventParameter(event, kEventParamCurrentBounds,
- typeQDRectangle, 0, sizeof(Rect), 0, &newBounds);
- QRect rect(newBounds.left, newBounds.top,
- newBounds.right - newBounds.left, newBounds.bottom - newBounds.top);
-
- bool moved = widget->testAttribute(Qt::WA_Moved);
- bool resized = widget->testAttribute(Qt::WA_Resized);
- widget->setGeometry(rect);
- widget->setAttribute(Qt::WA_Moved, moved);
- widget->setAttribute(Qt::WA_Resized, resized);
- qt_event_request_window_change(widget);
- }
- } else if (ekind == kEventControlGetSizeConstraints) {
- if (!widget || !qt_isGenuineQWidget(widget)) {
- handled_event = false;
- } else {
- handled_event = true;
- QWidgetItem item(widget);
- QSize size = item.minimumSize();
- HISize hisize = { size.width(), size.height() };
- SetEventParameter(event, kEventParamMinimumSize, typeHISize, sizeof(HISize), &hisize);
- size = item.maximumSize();
- hisize.width = size.width() + 2; // ### shouldn't have to add 2 (but it works).
- hisize.height = size.height();
- SetEventParameter(event, kEventParamMaximumSize, typeHISize, sizeof(HISize), &hisize);
- }
- } else if (ekind == kEventControlVisibilityChanged) {
- handled_event = false;
- if (widget) {
- qt_event_request_window_change(widget);
- if (!HIViewIsVisible(HIViewRef(widget->winId()))) {
- if (widget == qt_button_down)
- qt_button_down = 0;
- }
- }
- }
- break; }
- case kEventClassMouse: {
- bool send_to_app = false;
- if(qt_button_down)
- send_to_app = true;
- if(send_to_app) {
- OSStatus err = SendEventToApplication(event);
- if(err != noErr)
- handled_event = false;
- } else {
- CallNextEventHandler(er, event);
- }
- break; }
- default:
- handled_event = false;
- break;
- }
- if(!handled_event) //let the event go through
- return eventNotHandledErr;
- return noErr; //we eat the event
-}
-#endif
OSViewRef qt_mac_create_widget(QWidget *widget, QWidgetPrivate *widgetPrivate, OSViewRef parent)
{
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
QT_MANGLE_NAMESPACE(QCocoaView) *view = [[QT_MANGLE_NAMESPACE(QCocoaView) alloc] initWithQWidget:widget widgetPrivate:widgetPrivate];
@@ -1605,31 +569,10 @@ OSViewRef qt_mac_create_widget(QWidget *widget, QWidgetPrivate *widgetPrivate, O
if (view && parent)
[parent addSubview:view];
return view;
-#else
- Q_UNUSED(widget);
- Q_UNUSED(widgetPrivate);
- if(!widget_class) {
- OSStatus err = HIObjectRegisterSubclass(kObjectQWidget, kHIViewClassID, 0, make_widget_eventUPP(),
- GetEventTypeCount(widget_events), widget_events,
- 0, &widget_class);
- if (err && err != hiObjectClassExistsErr)
- qWarning("QWidget: Internal error (%d)", __LINE__);
- }
- HIViewRef ret = 0;
- if(HIObjectCreate(kObjectQWidget, 0, (HIObjectRef*)&ret) != noErr)
- qWarning("QWidget: Internal error (%d)", __LINE__);
- if(ret && parent)
- HIViewAddSubview(parent, ret);
- return ret;
-#endif
}
void qt_mac_unregister_widget()
{
-#ifndef QT_MAC_USE_COCOA
- HIObjectUnregisterClass(widget_class);
- widget_class = 0;
-#endif
}
void QWidgetPrivate::toggleDrawers(bool visible)
@@ -1670,46 +613,18 @@ bool QWidgetPrivate::qt_mac_update_sizer(QWidget *w, int up)
topData->resizer += up;
OSWindowRef windowRef = qt_mac_window_for(OSViewRef(w->effectiveWinId()));
{
-#ifndef QT_MAC_USE_COCOA
- WindowClass wclass;
- GetWindowClass(windowRef, &wclass);
- if(!(GetAvailableWindowAttributes(wclass) & kWindowResizableAttribute))
- return true;
-#endif
}
bool remove_grip = (topData->resizer || (w->windowFlags() & Qt::FramelessWindowHint)
|| (extraData->maxw && extraData->maxh &&
extraData->maxw == extraData->minw && extraData->maxh == extraData->minh));
-#ifndef QT_MAC_USE_COCOA
- WindowAttributes attr;
- GetWindowAttributes(windowRef, &attr);
- if(remove_grip) {
- if(attr & kWindowResizableAttribute) {
- ChangeWindowAttributes(qt_mac_window_for(w), kWindowNoAttributes,
- kWindowResizableAttribute);
- ReshapeCustomWindow(qt_mac_window_for(w));
- }
- } else if(!(attr & kWindowResizableAttribute)) {
- ChangeWindowAttributes(windowRef, kWindowResizableAttribute,
- kWindowNoAttributes);
- ReshapeCustomWindow(windowRef);
- }
-#else
[windowRef setShowsResizeIndicator:!remove_grip];
-#endif
return true;
}
void QWidgetPrivate::qt_clean_root_win()
{
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
[qt_root_win release];
-#else
- if(!qt_root_win)
- return;
- CFRelease(qt_root_win);
-#endif
qt_root_win = 0;
}
@@ -1719,12 +634,7 @@ bool QWidgetPrivate::qt_create_root_win()
return false;
const QSize desktopSize = qt_mac_desktopSize();
QRect desktopRect(QPoint(0, 0), desktopSize);
-#ifdef QT_MAC_USE_COCOA
qt_root_win = qt_mac_create_window(0, kOverlayWindowClass, NSBorderlessWindowMask, desktopRect);
-#else
- WindowAttributes wattr = (kWindowCompositingAttribute | kWindowStandardHandlerAttribute);
- qt_root_win = qt_mac_create_window(0, kOverlayWindowClass, wattr, desktopRect);
-#endif
if(!qt_root_win)
return false;
qAddPostRoutine(qt_clean_root_win);
@@ -1734,53 +644,10 @@ bool QWidgetPrivate::qt_create_root_win()
bool QWidgetPrivate::qt_widget_rgn(QWidget *widget, short wcode, RgnHandle rgn, bool force = false)
{
bool ret = false;
-#ifndef QT_MAC_USE_COCOA
- switch(wcode) {
- case kWindowStructureRgn: {
- if(widget) {
- if(widget->d_func()->extra && !widget->d_func()->extra->mask.isEmpty()) {
- QRegion rin = qt_mac_convert_mac_region(rgn);
- if(!rin.isEmpty()) {
- QPoint rin_tl = rin.boundingRect().topLeft(); //in offset
- rin.translate(-rin_tl.x(), -rin_tl.y()); //bring into same space as below
- QRegion mask = widget->d_func()->extra->mask;
- Qt::WindowFlags flags = widget->windowFlags();
- if(widget->isWindow()
- && !(flags & Qt::FramelessWindowHint
- || (flags & Qt::CustomizeWindowHint && !(flags & Qt::WindowTitleHint)))) {
- QRegion title;
- {
- QMacSmartQuickDrawRegion rgn(qt_mac_get_rgn());
- GetWindowRegion(qt_mac_window_for(widget), kWindowTitleBarRgn, rgn);
- title = qt_mac_convert_mac_region(rgn);
- }
- QRect br = title.boundingRect();
- mask.translate(0, br.height()); //put the mask 'under' the title bar..
- title.translate(-br.x(), -br.y());
- mask += title;
- }
-
- QRegion cr = rin & mask;
- cr.translate(rin_tl.x(), rin_tl.y()); //translate back to incoming space
- CopyRgn(QMacSmartQuickDrawRegion(cr.toQDRgn()), rgn);
- }
- ret = true;
- } else if(force) {
- QRegion cr(widget->geometry());
- CopyRgn(QMacSmartQuickDrawRegion(cr.toQDRgn()), rgn);
- ret = true;
- }
- }
- break; }
- default: break;
- }
- //qDebug() << widget << ret << wcode << qt_mac_convert_mac_region(rgn);
-#else
Q_UNUSED(widget);
Q_UNUSED(wcode);
Q_UNUSED(rgn);
Q_UNUSED(force);
-#endif
return ret;
}
@@ -1799,160 +666,7 @@ void QWidgetPrivate::determineWindowClass()
data.window_flags |= Qt::MacWindowToolBarButtonHint;
}
#endif
-#ifndef QT_MAC_USE_COCOA
-// ### COCOA:Interleave these better!
-
- const Qt::WindowType type = q->windowType();
- Qt::WindowFlags &flags = data.window_flags;
- const bool popup = (type == Qt::Popup);
- if (type == Qt::ToolTip || type == Qt::SplashScreen || popup)
- flags |= Qt::FramelessWindowHint;
-
- WindowClass wclass = kSheetWindowClass;
- if(qt_mac_is_macdrawer(q))
- wclass = kDrawerWindowClass;
- else if (q->testAttribute(Qt::WA_ShowModal) && flags & Qt::CustomizeWindowHint)
- wclass = kDocumentWindowClass;
- else if(popup || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 && type == Qt::SplashScreen))
- wclass = kModalWindowClass;
- else if(q->testAttribute(Qt::WA_ShowModal))
- wclass = kMovableModalWindowClass;
- else if(type == Qt::ToolTip)
- wclass = kHelpWindowClass;
- else if(type == Qt::Tool || (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5
- && type == Qt::SplashScreen))
- wclass = kFloatingWindowClass;
- else
- wclass = kDocumentWindowClass;
-
- WindowGroupRef grp = 0;
- WindowAttributes wattr = (kWindowCompositingAttribute | kWindowStandardHandlerAttribute);
- if (q->testAttribute(Qt::WA_MacFrameworkScaled))
- wattr |= kWindowFrameworkScaledAttribute;
- if(qt_mac_is_macsheet(q)) {
- //grp = GetWindowGroupOfClass(kMovableModalWindowClass);
- wclass = kSheetWindowClass;
- } else {
- grp = GetWindowGroupOfClass(wclass);
- // Shift things around a bit to get the correct window class based on the presence
- // (or lack) of the border.
- bool customize = flags & Qt::CustomizeWindowHint;
- bool framelessWindow = (flags & Qt::FramelessWindowHint || (customize && !(flags & Qt::WindowTitleHint)));
- if (framelessWindow) {
- if(wclass == kDocumentWindowClass) {
- wattr |= kWindowNoTitleBarAttribute;
- } else if(wclass == kFloatingWindowClass) {
- wattr |= kWindowNoTitleBarAttribute;
- } else if (wclass == kMovableModalWindowClass) {
- wclass = kModalWindowClass;
- }
- } else {
- if(wclass != kModalWindowClass)
- wattr |= kWindowResizableAttribute;
- }
- // Only add extra decorations (well, buttons) for widgets that can have them
- // and have an actual border we can put them on.
- if(wclass != kModalWindowClass && wclass != kMovableModalWindowClass
- && wclass != kSheetWindowClass && wclass != kPlainWindowClass
- && !framelessWindow && wclass != kDrawerWindowClass
- && wclass != kHelpWindowClass) {
- if (flags & Qt::WindowMaximizeButtonHint)
- wattr |= kWindowFullZoomAttribute;
- if (flags & Qt::WindowMinimizeButtonHint)
- wattr |= kWindowCollapseBoxAttribute;
- if (flags & Qt::WindowSystemMenuHint || flags & Qt::WindowCloseButtonHint)
- wattr |= kWindowCloseBoxAttribute;
- if (flags & Qt::MacWindowToolBarButtonHint)
- wattr |= kWindowToolbarButtonAttribute;
- } else {
- // Clear these hints so that we aren't call them on invalid windows
- flags &= ~(Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint
- | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint);
- }
- }
- if((popup || type == Qt::Tool) && !q->isModal())
- wattr |= kWindowHideOnSuspendAttribute;
- wattr |= kWindowLiveResizeAttribute;
-
-#ifdef DEBUG_WINDOW_CREATE
-#define ADD_DEBUG_WINDOW_NAME(x) { x, #x }
- struct {
- UInt32 tag;
- const char *name;
- } known_attribs[] = {
- ADD_DEBUG_WINDOW_NAME(kWindowCompositingAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowMetalAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowCollapseBoxAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowHorizontalZoomAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowVerticalZoomAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowResizableAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowNoActivatesAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowNoUpdatesAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowOpaqueForEventsAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowLiveResizeAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowCloseBoxAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute),
- { 0, 0 }
- }, known_classes[] = {
- ADD_DEBUG_WINDOW_NAME(kHelpWindowClass),
- ADD_DEBUG_WINDOW_NAME(kPlainWindowClass),
- ADD_DEBUG_WINDOW_NAME(kDrawerWindowClass),
- ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass),
- ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass),
- ADD_DEBUG_WINDOW_NAME(kSheetWindowClass),
- ADD_DEBUG_WINDOW_NAME(kFloatingWindowClass),
- ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass),
- ADD_DEBUG_WINDOW_NAME(kDocumentWindowClass),
- ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass),
- ADD_DEBUG_WINDOW_NAME(kMovableModalWindowClass),
- ADD_DEBUG_WINDOW_NAME(kModalWindowClass),
- { 0, 0 }
- };
- qDebug("Qt: internal: ************* Creating new window %p (%s::%s)", q, q->metaObject()->className(),
- q->objectName().toLocal8Bit().constData());
- bool found_class = false;
- for(int i = 0; known_classes[i].name; i++) {
- if(wclass == known_classes[i].tag) {
- found_class = true;
- qDebug("Qt: internal: ** Class: %s", known_classes[i].name);
- break;
- }
- }
- if(!found_class)
- qDebug("Qt: internal: !! Class: Unknown! (%d)", (int)wclass);
- if(wattr) {
- WindowAttributes tmp_wattr = wattr;
- qDebug("Qt: internal: ** Attributes:");
- for(int i = 0; tmp_wattr && known_attribs[i].name; i++) {
- if((tmp_wattr & known_attribs[i].tag) == known_attribs[i].tag) {
- tmp_wattr ^= known_attribs[i].tag;
- qDebug("Qt: internal: * %s %s", known_attribs[i].name,
- (GetAvailableWindowAttributes(wclass) & known_attribs[i].tag) ? "" : "(*)");
- }
- }
- if(tmp_wattr)
- qDebug("Qt: internal: !! Attributes: Unknown (%d)", (int)tmp_wattr);
- }
-#endif
- /* Just to be extra careful we will change to the kUtilityWindowClass if the
- requested attributes cannot be used */
- if((GetAvailableWindowAttributes(wclass) & wattr) != wattr) {
- WindowClass tmp_class = wclass;
- if(wclass == kToolbarWindowClass || wclass == kUtilityWindowClass)
- wclass = kFloatingWindowClass;
- if(tmp_class != wclass) {
- if(!grp)
- grp = GetWindowGroupOfClass(wclass);
- wclass = tmp_class;
- }
- }
- topData()->wclass = wclass;
- topData()->wattr = wattr;
-#else
const Qt::WindowType type = q->windowType();
Qt::WindowFlags &flags = data.window_flags;
const bool popup = (type == Qt::Popup);
@@ -1984,9 +698,6 @@ void QWidgetPrivate::determineWindowClass()
wclass = kSheetWindowClass;
wattr = NSTitledWindowMask | NSResizableWindowMask;
} else {
-#ifndef QT_MAC_USE_COCOA
- grp = GetWindowGroupOfClass(wclass);
-#endif
// Shift things around a bit to get the correct window class based on the presence
// (or lack) of the border.
bool customize = flags & Qt::CustomizeWindowHint;
@@ -2085,193 +796,11 @@ void QWidgetPrivate::determineWindowClass()
}
#endif
-#ifndef QT_MAC_USE_COCOA
- /* Just to be extra careful we will change to the kUtilityWindowClass if the
- requested attributes cannot be used */
- if((GetAvailableWindowAttributes(wclass) & wattr) != wattr) {
- WindowClass tmp_class = wclass;
- if(wclass == kToolbarWindowClass || wclass == kUtilityWindowClass)
- wclass = kFloatingWindowClass;
- if(tmp_class != wclass) {
- if(!grp)
- grp = GetWindowGroupOfClass(wclass);
- wclass = tmp_class;
- }
- }
-#endif
-#endif
topData()->wclass = wclass;
topData()->wattr = wattr;
}
-#ifndef QT_MAC_USE_COCOA // This is handled in Cocoa via our category.
-void QWidgetPrivate::initWindowPtr()
-{
- Q_Q(QWidget);
- OSWindowRef windowRef = qt_mac_window_for(qt_mac_nativeview_for(q)); //do not create!
- if(!windowRef)
- return;
- QWidget *window = q->window(), *oldWindow = 0;
- if(GetWindowProperty(windowRef, kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(oldWindow), 0, &oldWindow) == noErr) {
- Q_ASSERT(window == oldWindow);
- return;
- }
-
- if(SetWindowProperty(windowRef, kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(window), &window) != noErr)
- qWarning("Qt:Internal error (%s:%d)", __FILE__, __LINE__); //no real way to recover
- if(!q->windowType() != Qt::Desktop) { //setup an event callback handler on the window
- InstallWindowEventHandler(windowRef, make_win_eventUPP(), GetEventTypeCount(window_events),
- window_events, static_cast<void *>(qApp), &window_event);
- }
-}
-
-void QWidgetPrivate::finishCreateWindow_sys_Carbon(OSWindowRef windowRef)
-{
- Q_Q(QWidget);
- const Qt::WindowType type = q->windowType();
- Qt::WindowFlags &flags = data.window_flags;
- QWidget *parentWidget = q->parentWidget();
-
- const bool desktop = (type == Qt::Desktop);
- const bool dialog = (type == Qt::Dialog
- || type == Qt::Sheet
- || type == Qt::Drawer
- || (flags & Qt::MSWindowsFixedSizeDialogHint));
- QTLWExtra *topExtra = topData();
- quint32 wattr = topExtra->wattr;
- if (!desktop)
- SetAutomaticControlDragTrackingEnabledForWindow(windowRef, true);
- HIWindowChangeFeatures(windowRef, kWindowCanCollapse, 0);
- if (wattr & kWindowHideOnSuspendAttribute)
- HIWindowChangeAvailability(windowRef, kHIWindowExposeHidden, 0);
- else
- HIWindowChangeAvailability(windowRef, 0, kHIWindowExposeHidden);
- if ((flags & Qt::WindowStaysOnTopHint))
- ChangeWindowAttributes(windowRef, kWindowNoAttributes, kWindowHideOnSuspendAttribute);
- if (qt_mac_is_macdrawer(q) && parentWidget)
- SetDrawerParent(windowRef, qt_mac_window_for (parentWidget));
- if (topExtra->group) {
- qt_mac_release_window_group(topExtra->group);
- topExtra->group = 0;
- }
- if (type == Qt::ToolTip)
- qt_mac_set_window_group_to_tooltip(windowRef);
- else if (type == Qt::Popup && (flags & Qt::WindowStaysOnTopHint))
- qt_mac_set_window_group_to_popup(windowRef);
- else if (flags & Qt::WindowStaysOnTopHint)
- qt_mac_set_window_group_to_stays_on_top(windowRef, type);
- else if (dialog)
- SetWindowGroup(windowRef, GetWindowGroupOfClass(kMovableModalWindowClass));
-
-#ifdef DEBUG_WINDOW_CREATE
- if (WindowGroupRef grpf = GetWindowGroup(windowRef)) {
- QCFString cfname;
- CopyWindowGroupName(grpf, &cfname);
- SInt32 lvl;
- GetWindowGroupLevel(grpf, &lvl);
- const char *from = "Default";
- if (topExtra && grpf == topData()->group)
- from = "Created";
- else if (grpf == grp)
- from = "Copied";
- qDebug("Qt: internal: With window group '%s' [%p] @ %d: %s",
- static_cast<QString>(cfname).toLatin1().constData(), grpf, (int)lvl, from);
- } else {
- qDebug("Qt: internal: No window group!!!");
- }
- HIWindowAvailability hi_avail = 0;
- if (HIWindowGetAvailability(windowRef, &hi_avail) == noErr) {
- struct {
- UInt32 tag;
- const char *name;
- } known_avail[] = {
- ADD_DEBUG_WINDOW_NAME(kHIWindowExposeHidden),
- { 0, 0 }
- };
- qDebug("Qt: internal: ** HIWindowAvailibility:");
- for (int i = 0; hi_avail && known_avail[i].name; i++) {
- if ((hi_avail & known_avail[i].tag) == known_avail[i].tag) {
- hi_avail ^= known_avail[i].tag;
- qDebug("Qt: internal: * %s", known_avail[i].name);
- }
- }
- if (hi_avail)
- qDebug("Qt: internal: !! Attributes: Unknown (%d)", (int)hi_avail);
- }
#undef ADD_DEBUG_WINDOW_NAME
-#endif
- if (extra && !extra->mask.isEmpty())
- ReshapeCustomWindow(windowRef);
- SetWindowModality(windowRef, kWindowModalityNone, 0);
- if (qt_mac_is_macdrawer(q))
- SetDrawerOffsets(windowRef, 0.0, 25.0);
- data.fstrut_dirty = true; // when we create a toplevel widget, the frame strut should be dirty
- HIViewRef hiview = (HIViewRef)data.winid;
- HIViewRef window_hiview = qt_mac_get_contentview_for(windowRef);
- if(!hiview) {
- hiview = qt_mac_create_widget(q, this, window_hiview);
- setWinId((WId)hiview);
- } else {
- HIViewAddSubview(window_hiview, hiview);
- }
- if (hiview) {
- Rect win_rect;
- GetWindowBounds(qt_mac_window_for (window_hiview), kWindowContentRgn, &win_rect);
- HIRect bounds = CGRectMake(0, 0, win_rect.right-win_rect.left, win_rect.bottom-win_rect.top);
- HIViewSetFrame(hiview, &bounds);
- HIViewSetVisible(hiview, true);
- if (q->testAttribute(Qt::WA_DropSiteRegistered))
- registerDropSite(true);
- transferChildren();
- }
- initWindowPtr();
-
- if (topExtra->posFromMove) {
- updateFrameStrut();
- const QRect &fStrut = frameStrut();
- Rect r;
- SetRect(&r, data.crect.left(), data.crect.top(), data.crect.right() + 1, data.crect.bottom() + 1);
- SetRect(&r, r.left + fStrut.left(), r.top + fStrut.top(),
- (r.left + fStrut.left() + data.crect.width()) - fStrut.right(),
- (r.top + fStrut.top() + data.crect.height()) - fStrut.bottom());
- SetWindowBounds(windowRef, kWindowContentRgn, &r);
- topExtra->posFromMove = false;
- }
-
- if (q->testAttribute(Qt::WA_WState_WindowOpacitySet)){
- q->setWindowOpacity(topExtra->opacity / 255.0f);
- } else if (qt_mac_is_macsheet(q)){
- SetThemeWindowBackground(qt_mac_window_for(q), kThemeBrushSheetBackgroundTransparent, true);
- CGFloat alpha = 0;
- GetWindowAlpha(qt_mac_window_for(q), &alpha);
- if (alpha == 1){
- // For some reason the 'SetThemeWindowBackground' does not seem
- // to work. So we do this little hack until it hopefully starts to
- // work in newer versions of mac OS.
- q->setWindowOpacity(0.95f);
- q->setAttribute(Qt::WA_WState_WindowOpacitySet, false);
- }
- } else{
- // If the window has been recreated after beeing e.g. a sheet,
- // make sure that we don't report a faulty opacity:
- q->setWindowOpacity(1.0f);
- q->setAttribute(Qt::WA_WState_WindowOpacitySet, false);
- }
-
- // Since we only now have a window, sync our state.
- macUpdateHideOnSuspend();
- macUpdateOpaqueSizeGrip();
- macUpdateMetalAttribute();
- macUpdateIgnoreMouseEvents();
- setWindowTitle_helper(extra->topextra->caption);
- setWindowIconText_helper(extra->topextra->iconText);
- setWindowFilePath_helper(extra->topextra->filePath);
- setWindowModified_sys(q->isWindowModified());
- updateFrameStrut();
- qt_mac_update_sizer(q);
- applyMaxAndMinSizeOnWindow();
-}
-#else // QT_MAC_USE_COCOA
void QWidgetPrivate::setWindowLevel()
{
@@ -2398,7 +927,6 @@ void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWin
applyMaxAndMinSizeOnWindow();
}
-#endif // QT_MAC_USE_COCOA
/*
Recreates widget window. Useful if immutable
@@ -2409,18 +937,6 @@ void QWidgetPrivate::recreateMacWindow()
Q_Q(QWidget);
OSViewRef myView = qt_mac_nativeview_for(q);
OSWindowRef oldWindow = qt_mac_window_for(myView);
-#ifndef QT_MAC_USE_COCOA
- HIViewRemoveFromSuperview(myView);
- determineWindowClass();
- createWindow_sys();
-
- if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
- mwl->updateHIToolBarStatus();
- }
-
- if (IsWindowVisible(oldWindow))
- show_sys();
-#else
QMacCocoaAutoReleasePool pool;
[myView removeFromSuperview];
determineWindowClass();
@@ -2436,7 +952,6 @@ void QWidgetPrivate::recreateMacWindow()
[oldWindow orderOut:oldWindow];
show_sys();
}
-#endif // QT_MAC_USE_COCOA
// Release the window after creating the new window, because releasing it early
// may cause the app to quit ("close on last window closed attribute")
@@ -2463,11 +978,7 @@ void QWidgetPrivate::createWindow_sys()
if (windowRef == 0)
qWarning("QWidget: Internal error: %s:%d: If you reach this error please contact Qt Support and include the\n"
" WidgetFlags used in creating the widget.", __FILE__, __LINE__);
-#ifndef QT_MAC_USE_COCOA
- finishCreateWindow_sys_Carbon(windowRef);
-#else
finishCreateWindow_sys_Cocoa(windowRef);
-#endif
}
void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
@@ -2476,9 +987,6 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
QMacCocoaAutoReleasePool pool;
OSViewRef destroyid = 0;
-#ifndef QT_MAC_USE_COCOA
- window_event = 0;
-#endif
Qt::WindowType type = q->windowType();
Qt::WindowFlags flags = data.window_flags;
@@ -2511,15 +1019,11 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
deskn = dsk->screenNumber(parentWidget);
QRect screenGeo = dsk->screenGeometry(deskn);
if (!wasResized) {
-#ifndef QT_MAC_USE_COCOA
- data.crect.setSize(QSize(screenGeo.width()/2, 4*screenGeo.height()/10));
-#else
NSRect newRect = [NSWindow frameRectForContentRect:NSMakeRect(0, 0,
screenGeo.width() / 2.,
4 * screenGeo.height() / 10.)
styleMask:topData()->wattr];
data.crect.setSize(QSize(newRect.size.width, newRect.size.height));
-#endif
// Constrain to minimums and maximums we've set
if (extra->minw > 0)
data.crect.setWidth(qMax(extra->minw, data.crect.width()));
@@ -2545,23 +1049,11 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
if(window) { // override the old window (with a new NSView)
OSViewRef nativeView = OSViewRef(window);
OSViewRef parent = 0;
-#ifndef QT_MAC_USE_COCOA
- CFRetain(nativeView);
-#else
[nativeView retain];
-#endif
if (destroyOldWindow)
destroyid = qt_mac_nativeview_for(q);
bool transfer = false;
setWinId((WId)nativeView);
-#ifndef QT_MAC_USE_COCOA
-#ifndef HIViewInstallEventHandler
- // Macro taken from the CarbonEvents Header on Tiger
-#define HIViewInstallEventHandler( target, handler, numTypes, list, userData, outHandlerRef ) \
- InstallEventHandler( HIObjectGetEventTarget( (HIObjectRef) (target) ), (handler), (numTypes), (list), (userData), (outHandlerRef) )
-#endif
- HIViewInstallEventHandler(nativeView, make_widget_eventUPP(), GetEventTypeCount(widget_events), widget_events, 0, 0);
-#endif
if(topLevel) {
for(int i = 0; i < 2; ++i) {
if(i == 1) {
@@ -2570,19 +1062,11 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
createWindow_sys();
}
if(OSWindowRef windowref = qt_mac_window_for(nativeView)) {
-#ifndef QT_MAC_USE_COCOA
- CFRetain(windowref);
-#else
[windowref retain];
-#endif
if (initializeWindow) {
parent = qt_mac_get_contentview_for(windowref);
} else {
-#ifndef QT_MAC_USE_COCOA
- parent = HIViewGetSuperview(nativeView);
-#else
parent = [nativeView superview];
-#endif
}
break;
}
@@ -2597,83 +1081,45 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
parent = qt_mac_nativeview_for(parentWidget);
}
if(parent != nativeView && parent) {
-#ifndef QT_MAC_USE_COCOA
- HIViewAddSubview(parent, nativeView);
-#else
[parent addSubview:nativeView];
-#endif
}
if(transfer)
transferChildren();
data.fstrut_dirty = true; // we'll re calculate this later
q->setAttribute(Qt::WA_WState_Visible,
-#ifndef QT_MAC_USE_COCOA
- HIViewIsVisible(nativeView)
-#else
![nativeView isHidden]
-#endif
);
if(initializeWindow) {
-#ifndef QT_MAC_USE_COCOA
- HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height());
- HIViewSetFrame(nativeView, &bounds);
- q->setAttribute(Qt::WA_WState_Visible, HIViewIsVisible(nativeView));
-#else
NSRect bounds = NSMakeRect(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height());
[nativeView setFrame:bounds];
q->setAttribute(Qt::WA_WState_Visible, [nativeView isHidden]);
-#endif
}
-#ifndef QT_MAC_USE_COCOA
- initWindowPtr();
-#endif
} else if (desktop) { // desktop widget
if (!qt_root_win)
QWidgetPrivate::qt_create_root_win();
Q_ASSERT(qt_root_win);
WId rootWinID = 0;
-#ifndef QT_MAC_USE_COCOA
- CFRetain(qt_root_win);
- if(HIViewRef rootContentView = HIViewGetRoot(qt_root_win)) {
- rootWinID = (WId)rootContentView;
- CFRetain(rootContentView);
- }
-#else
[qt_root_win retain];
if (OSViewRef rootContentView = [qt_root_win contentView]) {
rootWinID = (WId)rootContentView;
[rootContentView retain];
}
-#endif
setWinId(rootWinID);
} else if (topLevel) {
determineWindowClass();
if(OSViewRef osview = qt_mac_create_widget(q, this, 0)) {
-#ifndef QT_MAC_USE_COCOA
- HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(),
- data.crect.width(), data.crect.height());
- HIViewSetFrame(osview, &bounds);
-#else
NSRect bounds = NSMakeRect(data.crect.x(), flipYCoordinate(data.crect.y()),
data.crect.width(), data.crect.height());
[osview setFrame:bounds];
-#endif
setWinId((WId)osview);
}
} else {
data.fstrut_dirty = false; // non-toplevel widgets don't have a frame, so no need to update the strut
-#ifdef QT_MAC_USE_COCOA
if (q->testAttribute(Qt::WA_NativeWindow) == false || q->internalWinId() != 0) {
// INVARIANT: q is Alien, and we should not create an NSView to back it up.
} else
-#endif
if (OSViewRef osview = qt_mac_create_widget(q, this, qt_mac_nativeview_for(parentWidget))) {
-#ifndef QT_MAC_USE_COCOA
- HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height());
- HIViewSetFrame(osview, &bounds);
- setWinId((WId)osview);
-#else
NSRect bounds = NSMakeRect(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height());
[osview setFrame:bounds];
setWinId((WId)osview);
@@ -2683,7 +1129,6 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
QMacCocoaAutoReleasePool pool;
[osview setHidden:NO];
}
-#endif
}
}
@@ -2710,11 +1155,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
Qt::HANDLE
QWidget::macQDHandle() const
{
-#ifndef QT_MAC_USE_COCOA
- return d_func()->qd_hd;
-#else
return 0;
-#endif
}
/*!
@@ -2773,21 +1214,15 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
if(OSViewRef hiview = qt_mac_nativeview_for(this)) {
OSWindowRef window = 0;
NSDrawer *drawer = nil;
-#ifdef QT_MAC_USE_COCOA
if (qt_mac_is_macdrawer(this)) {
drawer = qt_mac_drawer_for(this);
} else
-#endif
if (isWindow())
window = qt_mac_window_for(hiview);
// Because of how "destruct" works, we have to do just a normal release for the root_win.
if (window && window == qt_root_win) {
-#ifndef QT_MAC_USE_COCOA
- CFRelease(hiview);
-#else
[hiview release];
-#endif
} else {
qt_mac_destructView(hiview);
}
@@ -2821,9 +1256,6 @@ void QWidgetPrivate::transferChildren()
if (!topData()->caption.isEmpty())
setWindowTitle_helper(extra->topextra->caption);
if (w->internalWinId()) {
-#ifndef QT_MAC_USE_COCOA
- HIViewAddSubview(qt_mac_nativeview_for(q), qt_mac_nativeview_for(w));
-#else
// New NSWindows get an extra reference when drops are
// registered (at least in 10.5) which means that we may
// access the window later and get a crash (becasue our
@@ -2836,14 +1268,12 @@ void QWidgetPrivate::transferChildren()
[qt_mac_nativeview_for(q) addSubview:qt_mac_nativeview_for(w)];
[qt_mac_nativeview_for(w) release];
w->setAttribute(Qt::WA_DropSiteRegistered, oldRegistered);
-#endif
}
}
}
}
}
-#ifdef QT_MAC_USE_COCOA
void QWidgetPrivate::setSubWindowStacking(bool set)
{
// After hitting too many unforeseen bugs trying to put Qt on top of the cocoa child
@@ -2918,7 +1348,6 @@ void QWidgetPrivate::setSubWindowStacking(bool set)
}
}
}
-#endif
void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
{
@@ -2926,9 +1355,7 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
QMacCocoaAutoReleasePool pool;
QTLWExtra *topData = maybeTopData();
bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
-#ifdef QT_MAC_USE_COCOA
bool wasWindow = q->isWindow();
-#endif
OSViewRef old_id = 0;
if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
@@ -2949,18 +1376,11 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
}
}
-#ifndef QT_MAC_USE_COCOA
- EventHandlerRef old_window_event = 0;
-#else
bool oldToolbarVisible = false;
NSDrawer *oldDrawer = nil;
NSToolbar *oldToolbar = 0;
-#endif
if (wasCreated && !(q->windowType() == Qt::Desktop)) {
old_id = qt_mac_nativeview_for(q);
-#ifndef QT_MAC_USE_COCOA
- old_window_event = window_event;
-#else
if (qt_mac_is_macdrawer(q)) {
oldDrawer = qt_mac_drawer_for(q);
}
@@ -2973,7 +1393,6 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
[oldWindow setToolbar:nil];
}
}
-#endif
}
QWidget* oldtlw = q->window();
@@ -3006,15 +1425,6 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
if (wasCreated || (nativeWidget && nonWindowWithCreatedParent)) {
createWinId();
if (q->isWindow()) {
-#ifndef QT_MAC_USE_COCOA
- // We do this down below for wasCreated, so avoid doing this twice
- // (only for performance, it gets called a lot anyway).
- if (!wasCreated) {
- if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
- mwl->updateHIToolBarStatus();
- }
- }
-#else
// Simply transfer our toolbar over. Everything should stay put, unlike in Carbon.
if (oldToolbar && !(f & Qt::FramelessWindowHint)) {
OSWindowRef newWindow = qt_mac_window_for(q);
@@ -3022,7 +1432,6 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
[oldToolbar release];
[oldToolbar setVisible:oldToolbarVisible];
}
-#endif
}
}
if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden)
@@ -3031,15 +1440,6 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
if (wasCreated) {
transferChildren();
-#ifndef QT_MAC_USE_COCOA
- // If we were a unified window, We just transfered our toolbars out of the unified toolbar.
- // So redo the status one more time. It apparently is not an issue with Cocoa.
- if (q->isWindow()) {
- if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
- mwl->updateHIToolBarStatus();
- }
- }
-#endif
if (topData &&
(!topData->caption.isEmpty() || !topData->filePath.isEmpty()))
@@ -3052,19 +1452,13 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
q->setAttribute(Qt::WA_DropSiteRegistered, true);
//cleanup
-#ifndef QT_MAC_USE_COCOA
- if (old_window_event)
- RemoveEventHandler(old_window_event);
-#endif
if (old_id) { //don't need old window anymore
OSWindowRef window = (oldtlw == q) ? qt_mac_window_for(old_id) : 0;
qt_mac_destructView(old_id);
-#ifdef QT_MAC_USE_COCOA
if (oldDrawer) {
qt_mac_destructDrawer(oldDrawer);
} else
-#endif
if (window)
qt_mac_destructWindow(window);
}
@@ -3091,14 +1485,6 @@ QPoint QWidget::mapToGlobal(const QPoint &pos) const
QPoint p = pos + data->crect.topLeft();
return isWindow() ? p : parentWidget()->mapToGlobal(p);
}
-#ifndef QT_MAC_USE_COCOA
- QPoint tmp = d->mapToWS(pos);
- HIPoint hi_pos = CGPointMake(tmp.x(), tmp.y());
- HIViewConvertPoint(&hi_pos, qt_mac_nativeview_for(this), 0);
- Rect win_rect;
- GetWindowBounds(qt_mac_window_for(this), kWindowStructureRgn, &win_rect);
- return QPoint((int)hi_pos.x+win_rect.left, (int)hi_pos.y+win_rect.top);
-#else
QPoint tmp = d->mapToWS(pos);
NSPoint hi_pos = NSMakePoint(tmp.x(), tmp.y());
hi_pos = [qt_mac_nativeview_for(this) convertPoint:hi_pos toView:nil];
@@ -3108,7 +1494,6 @@ QPoint QWidget::mapToGlobal(const QPoint &pos) const
// If we aren't the desktop we need to flip, if you flip the desktop on itself, you get the other problem.
return ((window()->windowFlags() & Qt::Desktop) == Qt::Desktop) ? QPointF(hi_pos.x, hi_pos.y).toPoint()
: flipPoint(hi_pos).toPoint();
-#endif
}
QPoint QWidget::mapFromGlobal(const QPoint &pos) const
@@ -3118,13 +1503,6 @@ QPoint QWidget::mapFromGlobal(const QPoint &pos) const
QPoint p = isWindow() ? pos : parentWidget()->mapFromGlobal(pos);
return p - data->crect.topLeft();
}
-#ifndef QT_MAC_USE_COCOA
- Rect win_rect;
- GetWindowBounds(qt_mac_window_for(this), kWindowStructureRgn, &win_rect);
- HIPoint hi_pos = CGPointMake(pos.x()-win_rect.left, pos.y()-win_rect.top);
- HIViewConvertPoint(&hi_pos, 0, qt_mac_nativeview_for(this));
- return d->mapFromWS(QPoint((int)hi_pos.x, (int)hi_pos.y));
-#else
NSRect win_rect = [qt_mac_window_for(this) frame];
// The Window point is in "Cocoa coordinates," but the view is in "Qt coordinates"
// so make sure to keep them in sync.
@@ -3132,7 +1510,6 @@ QPoint QWidget::mapFromGlobal(const QPoint &pos) const
flipYCoordinate(pos.y())-win_rect.origin.y);
hi_pos = [qt_mac_nativeview_for(this) convertPoint:hi_pos fromView:0];
return d->mapFromWS(QPoint(qRound(hi_pos.x), qRound(hi_pos.y)));
-#endif
}
void QWidgetPrivate::updateSystemBackground()
@@ -3153,12 +1530,8 @@ void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
{
Q_Q(QWidget);
if (q->isWindow()) {
-#ifndef QT_MAC_USE_COCOA
- SetWindowTitleWithCFString(qt_mac_window_for(q), QCFString(caption));
-#else
QMacCocoaAutoReleasePool pool;
[qt_mac_window_for(q) setTitle:qt_mac_QStringToNSString(caption)];
-#endif
}
}
@@ -3166,42 +1539,16 @@ void QWidgetPrivate::setWindowModified_sys(bool mod)
{
Q_Q(QWidget);
if (q->isWindow() && q->testAttribute(Qt::WA_WState_Created)) {
-#ifndef QT_MAC_USE_COCOA
- SetWindowModified(qt_mac_window_for(q), mod);
-#else
[qt_mac_window_for(q) setDocumentEdited:mod];
-#endif
}
}
void QWidgetPrivate::setWindowFilePath_sys(const QString &filePath)
{
Q_Q(QWidget);
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
QFileInfo fi(filePath);
[qt_mac_window_for(q) setRepresentedFilename:fi.exists() ? qt_mac_QStringToNSString(filePath) : @""];
-#else
- bool validRef = false;
- FSRef ref;
- bzero(&ref, sizeof(ref));
- OSStatus status;
-
- if (!filePath.isEmpty()) {
- status = FSPathMakeRef(reinterpret_cast<const UInt8 *>(filePath.toUtf8().constData()), &ref, 0);
- validRef = (status == noErr);
- }
- // Set the proxy regardless, since this is our way of clearing it as well, but ignore the
- // return value as well.
- if (validRef) {
- status = HIWindowSetProxyFSRef(qt_mac_window_for(q), &ref);
- } else {
- status = RemoveWindowProxy(qt_mac_window_for(q));
- }
- if (status != noErr)
- qWarning("QWidget::setWindowFilePath: Error setting proxyicon for path (%s):%ld",
- qPrintable(filePath), status);
-#endif
}
void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
@@ -3227,28 +1574,6 @@ void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
}
}
if (q->isWindow()) {
-#ifndef QT_MAC_USE_COCOA
- IconRef previousIcon = 0;
- if (icon.isNull()) {
- RemoveWindowProxy(qt_mac_window_for(q));
- previousIcon = topData->windowIcon;
- topData->windowIcon = 0;
- } else {
- WindowClass wclass;
- GetWindowClass(qt_mac_window_for(q), &wclass);
-
- if (wclass == kDocumentWindowClass) {
- IconRef newIcon = qt_mac_create_iconref(*pm);
- previousIcon = topData->windowIcon;
- topData->windowIcon = newIcon;
- SetWindowProxyIcon(qt_mac_window_for(q), newIcon);
- }
- }
-
- // Release the previous icon if it was set by this function.
- if (previousIcon != 0)
- ReleaseIconRef(previousIcon);
-#else
QMacCocoaAutoReleasePool pool;
if (icon.isNull())
return;
@@ -3267,7 +1592,6 @@ void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
[iconButton setImage:image];
[image release];
}
-#endif
}
}
@@ -3275,12 +1599,8 @@ void QWidgetPrivate::setWindowIconText_sys(const QString &iconText)
{
Q_Q(QWidget);
if(q->isWindow() && !iconText.isEmpty()) {
-#ifndef QT_MAC_USE_COCOA
- SetWindowAlternateTitle(qt_mac_window_for(q), QCFString(iconText));
-#else
QMacCocoaAutoReleasePool pool;
[qt_mac_window_for(q) setMiniwindowTitle:qt_mac_QStringToNSString(iconText)];
-#endif
}
}
@@ -3363,28 +1683,15 @@ void QWidget::activateWindow()
bool windowActive;
OSWindowRef win = qt_mac_window_for(tlw);
-#ifndef QT_MAC_USE_COCOA
- windowActive = IsWindowActive(win);
-#else
QMacCocoaAutoReleasePool pool;
windowActive = [win isKeyWindow];
-#endif
if ((tlw->windowType() == Qt::Popup)
|| (tlw->windowType() == Qt::Tool)
|| qt_mac_is_macdrawer(tlw)
|| windowActive) {
-#ifndef QT_MAC_USE_COCOA
- ActivateWindow(win, true);
- qApp->setActiveWindow(tlw);
-#else
[win makeKeyWindow];
-#endif
} else if(!isMinimized()) {
-#ifndef QT_MAC_USE_COCOA
- SelectWindow(win);
-#else
[win makeKeyAndOrderFront:win];
-#endif
}
}
@@ -3431,47 +1738,22 @@ void QWidgetPrivate::show_sys()
return;
bool realWindow = isRealWindow();
-#ifndef QT_MAC_USE_COCOA
- if (realWindow && !q->testAttribute(Qt::WA_Moved)) {
- if (qt_mac_is_macsheet(q))
- recreateMacWindow();
- q->createWinId();
- if (QWidget *p = q->parentWidget()) {
- p->createWinId();
- RepositionWindow(qt_mac_window_for(q), qt_mac_window_for(p), kWindowCenterOnParentWindow);
- } else {
- RepositionWindow(qt_mac_window_for(q), 0, kWindowCenterOnMainScreen);
- }
- }
-#endif
data.fstrut_dirty = true;
if (realWindow) {
bool isCurrentlyMinimized = (q->windowState() & Qt::WindowMinimized);
setModal_sys();
OSWindowRef window = qt_mac_window_for(q);
-#ifndef QT_MAC_USE_COCOA
- SizeWindow(window, q->width(), q->height(), true);
-#endif
-#ifdef QT_MAC_USE_COCOA
// Make sure that we end up sending a repaint event to
// the widget if the window has been visible one before:
[qt_mac_get_contentview_for(window) setNeedsDisplay:YES];
-#endif
if(qt_mac_is_macsheet(q)) {
qt_event_request_showsheet(q);
} else if(qt_mac_is_macdrawer(q)) {
-#ifndef QT_MAC_USE_COCOA
- OpenDrawer(window, kWindowEdgeDefault, false);
-#else
NSDrawer *drawer = qt_mac_drawer_for(q);
[drawer openOnEdge:[drawer preferredEdge]];
-#endif
} else {
-#ifndef QT_MAC_USE_COCOA
- ShowHide(window, true);
-#else
// sync the opacity value back (in case of a fade).
[window setAlphaValue:q->windowOpacity()];
@@ -3494,7 +1776,6 @@ void QWidgetPrivate::show_sys()
}
setSubWindowStacking(true);
qt_mac_update_cursor();
-#endif
if (q->windowType() == Qt::Popup) {
qt_button_down = 0;
if (q->focusWidget())
@@ -3505,20 +1786,10 @@ void QWidgetPrivate::show_sys()
toggleDrawers(true);
}
if (isCurrentlyMinimized) { //show in collapsed state
-#ifndef QT_MAC_USE_COCOA
- CollapseWindow(window, true);
-#else
[window miniaturize:window];
-#endif
} else if (!q->testAttribute(Qt::WA_ShowWithoutActivating)) {
-#ifndef QT_MAC_USE_COCOA
- qt_event_request_activate(q);
-#endif
}
} else if(topData()->embedded || !q->parentWidget() || q->parentWidget()->isVisible()) {
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), true);
-#else
if (NSView *view = qt_mac_nativeview_for(q)) {
// INVARIANT: q is native. Just show the view:
[view setHidden:NO];
@@ -3526,10 +1797,8 @@ void QWidgetPrivate::show_sys()
// INVARIANT: q is alien. Update q instead:
q->update();
}
-#endif
}
-#ifdef QT_MAC_USE_COCOA
if ([NSApp isActive] && !qt_button_down && !QWidget::mouseGrabber()){
// Update enter/leave immidiatly, don't wait for a move event. But only
// if no grab exists (even if the grab points to this widget, it seems, ref X11)
@@ -3541,7 +1810,6 @@ void QWidgetPrivate::show_sys()
qt_last_native_mouse_receiver = widgetUnderMouse ?
(widgetUnderMouse->internalWinId() ? widgetUnderMouse : widgetUnderMouse->nativeParentWidget()) : 0;
}
-#endif
topLevelAt_cache = 0;
qt_event_request_window_change(q);
@@ -3549,13 +1817,7 @@ void QWidgetPrivate::show_sys()
QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt)
{
-#ifndef QT_MAC_USE_COCOA
- CGPoint nativePoint = CGPointMake(pt.x(), pt.y());
- HIViewConvertPoint(&nativePoint, qt_mac_nativeview_for(child->parentWidget()),
- qt_mac_nativeview_for(child));
-#else
NSPoint nativePoint = [qt_mac_nativeview_for(child) convertPoint:NSMakePoint(pt.x(), pt.y()) fromView:qt_mac_nativeview_for(child->parentWidget())];
-#endif
return QPoint(nativePoint.x, nativePoint.y);
}
@@ -3567,31 +1829,14 @@ void QWidgetPrivate::hide_sys()
return;
QMacCocoaAutoReleasePool pool;
if(q->isWindow()) {
-#ifdef QT_MAC_USE_COCOA
setSubWindowStacking(false);
-#endif
OSWindowRef window = qt_mac_window_for(q);
if(qt_mac_is_macsheet(q)) {
-#ifndef QT_MAC_USE_COCOA
- WindowRef parent = 0;
- if(GetSheetWindowParent(window, &parent) != noErr || !parent)
- ShowHide(window, false);
- else
- HideSheetWindow(window);
-#else
[NSApp endSheet:window];
[window orderOut:window];
-#endif
} else if(qt_mac_is_macdrawer(q)) {
-#ifndef QT_MAC_USE_COCOA
- CloseDrawer(window, false);
-#else
[qt_mac_drawer_for(q) close];
-#endif
} else {
-#ifndef QT_MAC_USE_COCOA
- ShowHide(window, false);
-#else
[window orderOut:window];
// Unfortunately it is not as easy as just hiding the window, we need
// to find out if we were in full screen mode. If we were and this is
@@ -3625,56 +1870,11 @@ void QWidgetPrivate::hide_sys()
if(!keepFullScreen)
qt_mac_set_fullscreen_mode(false);
}
-#endif
toggleDrawers(false);
qt_mac_update_cursor();
-#ifndef QT_MAC_USE_COCOA
- // Clear modality (because it seems something that we've always done).
- if (data.window_modality != Qt::NonModal) {
- SetWindowModality(window, kWindowModalityNone,
- q->parentWidget() ? qt_mac_window_for(q->parentWidget()->window()) : 0);
- }
-#endif
- }
-#ifndef QT_MAC_USE_COCOA
- // If the window we now hide was the active window, we need
- // to find, and activate another window on screen. NB: Cocoa takes care of this
- // logic for us (and distinquishes between main windows and key windows)
- if (q->isActiveWindow() && !(q->windowType() == Qt::Popup)) {
- QWidget *w = 0;
- if(q->parentWidget())
- w = q->parentWidget()->window();
- if(!w || (!w->isVisible() && !w->isMinimized())) {
- for (WindowPtr wp = GetFrontWindowOfClass(kMovableModalWindowClass, true);
- wp; wp = GetNextWindowOfClass(wp, kMovableModalWindowClass, true)) {
- if((w = qt_mac_find_window(wp)))
- break;
- }
- if (!w){
- for (WindowPtr wp = GetFrontWindowOfClass(kDocumentWindowClass, true);
- wp; wp = GetNextWindowOfClass(wp, kDocumentWindowClass, true)) {
- if((w = qt_mac_find_window(wp)))
- break;
- }
- }
- if (!w){
- for(WindowPtr wp = GetFrontWindowOfClass(kSimpleWindowClass, true);
- wp; wp = GetNextWindowOfClass(wp, kSimpleWindowClass, true)) {
- if((w = qt_mac_find_window(wp)))
- break;
- }
- }
- }
- if(w && w->isVisible() && !w->isMinimized()) {
- qt_event_request_activate(w);
- }
}
-#endif
} else {
invalidateBuffer(q->rect());
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), false);
-#else
if (NSView *view = qt_mac_nativeview_for(q)) {
// INVARIANT: q is native. Just hide the view:
[view setHidden:YES];
@@ -3682,10 +1882,8 @@ void QWidgetPrivate::hide_sys()
// INVARIANT: q is alien. Repaint where q is placed instead:
qt_mac_updateParentUnderAlienWidget(q);
}
-#endif
}
-#ifdef QT_MAC_USE_COCOA
if ([NSApp isActive] && !qt_button_down && !QWidget::mouseGrabber()){
// Update enter/leave immidiatly, don't wait for a move event. But only
// if no grab exists (even if the grab points to this widget, it seems, ref X11)
@@ -3697,7 +1895,6 @@ void QWidgetPrivate::hide_sys()
qt_last_native_mouse_receiver = widgetUnderMouse ?
(widgetUnderMouse->internalWinId() ? widgetUnderMouse : widgetUnderMouse->nativeParentWidget()) : 0;
}
-#endif
topLevelAt_cache = 0;
qt_event_request_window_change(q);
@@ -3713,9 +1910,7 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
if (oldstate == newstate)
return;
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
-#endif
bool needSendStateChange = true;
if(isWindow()) {
if((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) {
@@ -3749,17 +1944,9 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
OSWindowRef window = qt_mac_window_for(this);
if((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) {
if (newstate & Qt::WindowMinimized) {
-#ifndef QT_MAC_USE_COCOA
- CollapseWindow(window, true);
-#else
[window miniaturize:window];
-#endif
} else {
-#ifndef QT_MAC_USE_COCOA
- CollapseWindow(window, false);
-#else
[window deminiaturize:window];
-#endif
}
needSendStateChange = oldstate == windowState(); // Collapse didn't change our flags.
}
@@ -3788,45 +1975,6 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
(oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized))) {
if(newstate & Qt::WindowMaximized) {
data->fstrut_dirty = true;
-#ifndef QT_MAC_USE_COCOA
- HIToolbarRef toolbarRef;
- if (GetWindowToolbar(window, &toolbarRef) == noErr && toolbarRef
- && !isVisible() && !IsWindowToolbarVisible(window)) {
- // HIToolbar, needs to be shown so that it's in the structure window
- // Typically this is part of a main window and will get shown
- // during the show, but it's will make the maximize all wrong.
- ShowHideWindowToolbar(window, true, false);
- d->updateFrameStrut(); // In theory the dirty would work, but it's optimized out if the window is not visible :(
- }
- Rect bounds;
- QDesktopWidget *dsk = QApplication::desktop();
- QRect avail = dsk->availableGeometry(dsk->screenNumber(this));
- SetRect(&bounds, avail.x(), avail.y(), avail.x() + avail.width(), avail.y() + avail.height());
- if(QWExtra *extra = d->extraData()) {
- if(bounds.right - bounds.left > extra->maxw)
- bounds.right = bounds.left + extra->maxw;
- if(bounds.bottom - bounds.top > extra->maxh)
- bounds.bottom = bounds.top + extra->maxh;
- }
- if(d->topData()) {
- QRect fs = d->frameStrut();
- bounds.left += fs.left();
- if(bounds.right < avail.x()+avail.width())
- bounds.right = qMin<short>((uint)avail.x()+avail.width(), bounds.right+fs.left());
- if(bounds.bottom < avail.y()+avail.height())
- bounds.bottom = qMin<short>((uint)avail.y()+avail.height(), bounds.bottom+fs.top());
- bounds.top += fs.top();
- bounds.right -= fs.right();
- bounds.bottom -= fs.bottom();
- }
- QRect orect(geometry().x(), geometry().y(), width(), height()),
- nrect(bounds.left, bounds.top, bounds.right - bounds.left,
- bounds.bottom - bounds.top);
- if(orect != nrect) { // the new rect differ from the old
- Point idealSize = { nrect.height(), nrect.width() };
- ZoomWindowIdeal(window, inZoomOut, &idealSize);
- }
-#else
NSToolbar *toolbarRef = [window toolbar];
if (toolbarRef && !isVisible() && ![toolbarRef isVisible]) {
// HIToolbar, needs to be shown so that it's in the structure window
@@ -3839,15 +1987,9 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
}
// Everything should be handled by Cocoa.
[window zoom:window];
-#endif
needSendStateChange = oldstate == windowState(); // Zoom didn't change flags.
} else if(oldstate & Qt::WindowMaximized && !(oldstate & Qt::WindowFullScreen)) {
-#ifndef QT_MAC_USE_COCOA
- Point idealSize;
- ZoomWindowIdeal(window, inZoomIn, &idealSize);
-#else
[window zoom:window];
-#endif
if(QTLWExtra *tlextra = d->topData()) {
setGeometry(tlextra->normalGeometry);
tlextra->normalGeometry.setRect(0, 0, -1, -1);
@@ -3875,13 +2017,9 @@ void QWidgetPrivate::setFocus_sys()
{
Q_Q(QWidget);
if (q->testAttribute(Qt::WA_WState_Created)) {
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
NSView *view = qt_mac_nativeview_for(q);
[[view window] makeFirstResponder:view];
-#else
- SetKeyboardFocus(qt_mac_window_for(q), qt_mac_nativeview_for(q), 1);
-#endif
}
}
@@ -3901,7 +2039,6 @@ void QWidgetPrivate::raise_sys()
if((q->windowType() == Qt::Desktop))
return;
-#if QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
if (isRealWindow()) {
// With the introduction of spaces it is not as simple as just raising the window.
@@ -3947,20 +2084,6 @@ void QWidgetPrivate::raise_sys()
[parentView sortSubviewsUsingFunction:compareViews2Raise context:reinterpret_cast<void *>(view)];
}
topLevelAt_cache = 0;
-#else
- if(q->isWindow()) {
- //raise this window
- BringToFront(qt_mac_window_for(q));
- if(qt_mac_raise_process) { //we get to be the active process now
- ProcessSerialNumber psn;
- GetCurrentProcess(&psn);
- SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly);
- }
- } else if(q->parentWidget()) {
- HIViewSetZOrder(qt_mac_nativeview_for(q), kHIViewZOrderAbove, 0);
- qt_event_request_window_change(q);
- }
-#endif
}
NSComparisonResult compareViews2Lower(id view1, id view2, void *context)
@@ -3978,7 +2101,6 @@ void QWidgetPrivate::lower_sys()
Q_Q(QWidget);
if((q->windowType() == Qt::Desktop))
return;
-#ifdef QT_MAC_USE_COCOA
if (isRealWindow()) {
OSWindowRef window = qt_mac_window_for(q);
[window orderBack:window];
@@ -3988,15 +2110,6 @@ void QWidgetPrivate::lower_sys()
[parentView sortSubviewsUsingFunction:compareViews2Lower context:reinterpret_cast<void *>(view)];
}
topLevelAt_cache = 0;
-#else
- if(q->isWindow()) {
- SendBehind(qt_mac_window_for(q), 0);
- } else if(q->parentWidget()) {
- invalidateBuffer(q->rect());
- HIViewSetZOrder(qt_mac_nativeview_for(q), kHIViewZOrderBelow, 0);
- qt_event_request_window_change(q);
- }
-#endif
}
NSComparisonResult compareViews2StackUnder(id view1, id view2, void *context)
@@ -4015,7 +2128,6 @@ void QWidgetPrivate::stackUnder_sys(QWidget *w)
Q_Q(QWidget);
if(!w || q->isWindow() || (q->windowType() == Qt::Desktop))
return;
-#ifdef QT_MAC_USE_COCOA
// Do the same trick as lower_sys() and put this widget before the widget passed in.
NSView *myView = qt_mac_nativeview_for(q);
NSView *wView = qt_mac_nativeview_for(w);
@@ -4034,117 +2146,8 @@ void QWidgetPrivate::stackUnder_sys(QWidget *w)
viewOrder[myView] = viewOrder[wView] - 1;
[parentView sortSubviewsUsingFunction:compareViews2StackUnder context:reinterpret_cast<void *>(&viewOrder)];
-#else
- QWidget *p = q->parentWidget();
- if(!p || p != w->parentWidget())
- return;
- invalidateBuffer(q->rect());
- HIViewSetZOrder(qt_mac_nativeview_for(q), kHIViewZOrderBelow, qt_mac_nativeview_for(w));
- qt_event_request_window_change(q);
-#endif
}
-#ifndef QT_MAC_USE_COCOA
-/*
- Modifies the bounds for a widgets backing HIView during moves and resizes. Also updates the
- widget, either by scrolling its contents or repainting, depending on the WA_StaticContents
- flag
-*/
-static void qt_mac_update_widget_position(QWidget *q, QRect oldRect, QRect newRect)
-{
- HIRect bounds = CGRectMake(newRect.x(), newRect.y(),
- newRect.width(), newRect.height());
-
- const HIViewRef view = qt_mac_nativeview_for(q);
- const bool isMove = (oldRect.topLeft() != newRect.topLeft());
- const bool isResize = (oldRect.size() != newRect.size());
-
-// qDebug() << oldRect << newRect << isMove << isResize << q->testAttribute(Qt::WA_OpaquePaintEvent) << q->testAttribute(Qt::WA_StaticContents);
- QWidgetPrivate *qd = qt_widget_private(q);
-
- // Perform a normal (complete repaint) update in some cases:
- if (
- // always repaint on move.
- (isMove) ||
-
- // limited update on resize requires WA_StaticContents.
- (isResize && q->testAttribute(Qt::WA_StaticContents) == false) ||
-
- // one of the rects are invalid
- (oldRect.isValid() == false || newRect.isValid() == false) ||
-
- // the position update is a part of a drag-and-drop operation
- QDragManager::self()->object ||
-
- // we are on Panther (no HIViewSetNeedsDisplayInRect)
- QSysInfo::MacintoshVersion < QSysInfo::MV_10_4
- ){
- HIViewSetFrame(view, &bounds);
- return;
- }
-
- const int dx = newRect.x() - oldRect.x();
- const int dy = newRect.y() - oldRect.y();
-
- if (isMove) {
- // HIViewScrollRect silently fails if we try to scroll anything under the grow box.
- // Check if there's one present within the widget rect, and if there is fall back
- // to repainting the entire widget.
- QWidget const * const parentWidget = q->parentWidget();
- const HIViewRef parentView = qt_mac_nativeview_for(parentWidget);
- HIViewRef nativeSizeGrip = 0;
- if (q->testAttribute(Qt::WA_WState_Created))
- HIViewFindByID(HIViewGetRoot(HIViewGetWindow(HIViewRef(q->winId()))), kHIViewWindowGrowBoxID, &nativeSizeGrip);
- if (nativeSizeGrip) {
- QWidget * const window = q->window();
-
- const int sizeGripSize = 20;
- const QRect oldWidgetRect = QRect(q->mapTo(window, QPoint(0, 0)), QSize(oldRect.width(), oldRect.height()));
- const QRect newWidgetRect = QRect(q->mapTo(window, QPoint(0, 0)), QSize(newRect.width(), newRect.height()));
- const QRect sizeGripRect = QRect(window->rect().bottomRight() - QPoint(sizeGripSize, sizeGripSize),
- window->rect().bottomRight());
-
- if (sizeGripRect.intersects(oldWidgetRect) || sizeGripRect.intersects(newWidgetRect)) {
- HIViewSetFrame(view, &bounds);
- return;
- }
- }
-
- // Don't scroll anything outside the parent widget rect.
- const QRect scrollRect = (oldRect | newRect) & parentWidget->rect();
- const HIRect scrollBounds =
- CGRectMake(scrollRect.x(), scrollRect.y(), scrollRect.width(), scrollRect.height());
-
- // We cannot scroll when the widget has a mask as that would
- // scroll the masked out areas too
- if (qd->extra && qd->extra->hasMask) {
- HIViewMoveBy(view, dx, dy);
- return;
- }
-
- OSStatus err = HIViewScrollRect(parentView, &scrollBounds, dx, dy);
- if (err != noErr) {
- HIViewSetNeedsDisplay(view, true);
- qWarning("QWidget: Internal error (%s:%d)", __FILE__, __LINE__);
- }
- }
- // Set the view bounds with drawing disabled to prevent repaints.
- HIViewSetDrawingEnabled(view, false);
- HIViewSetFrame(view, &bounds);
- HIViewSetDrawingEnabled(view, true);
-
- // Update any newly exposed areas due to resizing.
- const int startx = oldRect.width();
- const int stopx = newRect.width();
- const int starty = oldRect.height();
- const int stopy = newRect.height();
-
- const HIRect verticalSlice = CGRectMake(startx, 0, stopx , stopy);
- HIViewSetNeedsDisplayInRect(view, &verticalSlice, true);
- const HIRect horizontalSlice = CGRectMake(0, starty, startx, stopy);
- HIViewSetNeedsDisplayInRect(view, &horizontalSlice, true);
-}
-#endif
/*
Helper function for non-toplevel widgets. Helps to map Qt's 32bit
@@ -4198,26 +2201,15 @@ void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
// Embedded have different meaning on each platform, and on
// Mac, it means that q is a QMacNativeWidget.
bool isEmbeddedWindow = (q->isWindow() && topData()->embedded);
-#ifdef QT_MAC_USE_COCOA
NSView *nsview = qt_mac_nativeview_for(q);
-#endif
if (!isEmbeddedWindow) {
parentWRect = q->parentWidget()->data->wrect;
} else {
// INVARIANT: q's parent view is not owned by Qt. So we need to
// do some extra calls to get the clipped rect of the parent view:
-#ifndef QT_MAC_USE_COCOA
- HIViewRef parentView = HIViewGetSuperview(qt_mac_nativeview_for(q));
-#else
NSView *parentView = [qt_mac_nativeview_for(q) superview];
-#endif
if (parentView) {
-#ifndef QT_MAC_USE_COCOA
- HIRect tmpRect;
- HIViewGetFrame(parentView, &tmpRect);
-#else
NSRect tmpRect = [parentView frame];
-#endif
parentWRect = QRect(tmpRect.origin.x, tmpRect.origin.y,
tmpRect.size.width, tmpRect.size.height);
} else {
@@ -4255,11 +2247,6 @@ void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
if (data.wrect.contains(vrect)) {
wrectInParentCoordSys = data.wrect;
wrectInParentCoordSys.translate(data.crect.topLeft());
-#ifndef QT_MAC_USE_COCOA
- HIRect bounds = CGRectMake(wrectInParentCoordSys.x(), wrectInParentCoordSys.y(),
- wrectInParentCoordSys.width(), wrectInParentCoordSys.height());
- HIViewSetFrame(qt_mac_nativeview_for(q), &bounds);
-#else
if (nsview) {
// INVARIANT: q is native. Set view frame:
NSRect bounds = NSMakeRect(wrectInParentCoordSys.x(), wrectInParentCoordSys.y(),
@@ -4275,43 +2262,18 @@ void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
nativeParent->update(dirtyWRect);
}
-#endif
if (q->testAttribute(Qt::WA_OutsideWSRange)) {
q->setAttribute(Qt::WA_OutsideWSRange, false);
if (!dontShow) {
q->setAttribute(Qt::WA_Mapped);
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), true);
-#else
// If q is Alien, the following call does nothing:
[nsview setHidden:NO];
-#endif
}
}
return;
}
}
-#ifndef QT_MAC_USE_COCOA
- const QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX);
- if (!validRange.contains(wrectInParentCoordSys)) {
- // We're too big, and must clip:
- QPoint screenOffset(0, 0); // offset of the part being on screen
- const QWidget *parentWidget = q->parentWidget();
- while (parentWidget && !parentWidget->isWindow()) {
- screenOffset -= parentWidget->data->crect.topLeft();
- parentWidget = parentWidget->parentWidget();
- }
- QRect cropRect(screenOffset.x() - WRECT_MAX,
- screenOffset.y() - WRECT_MAX,
- 2*WRECT_MAX,
- 2*WRECT_MAX);
-
- wrectInParentCoordSys &=cropRect;
- wrect = wrectInParentCoordSys;
- wrect.translate(-data.crect.topLeft());
- }
-#endif //QT_MAC_USE_COCOA
}
// unmap if we are outside the valid window system coord system
@@ -4320,12 +2282,8 @@ void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
if (q->testAttribute(Qt::WA_OutsideWSRange) != outsideRange) {
q->setAttribute(Qt::WA_OutsideWSRange, outsideRange);
if (outsideRange) {
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), false);
-#else
// If q is Alien, the following call does nothing:
[nsview setHidden:YES];
-#endif
q->setAttribute(Qt::WA_Mapped, false);
} else if (!q->isHidden()) {
mapWindow = true;
@@ -4350,12 +2308,6 @@ void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
}
}
-#ifndef QT_MAC_USE_COCOA
- // Move the actual HIView:
- qt_mac_update_widget_position(q, oldRect, wrectInParentCoordSys);
- if (jump)
- q->update();
-#else
if (nsview) {
// INVARIANT: q is native. Move the actual NSView:
NSRect bounds = NSMakeRect(
@@ -4391,16 +2343,11 @@ void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
nativeParent->update(dirtyOldWRect | dirtyNewWRect);
}
}
-#endif
if (mapWindow && !dontShow) {
q->setAttribute(Qt::WA_Mapped);
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), true);
-#else
// If q is Alien, the following call does nothing:
[nsview setHidden:NO];
-#endif
}
}
@@ -4437,20 +2384,12 @@ void QWidgetPrivate::applyMaxAndMinSizeOnWindow()
QMacCocoaAutoReleasePool pool;
const float max_f(20000);
-#ifndef QT_MAC_USE_COCOA
-#define SF(x) ((x > max_f) ? max_f : x)
- HISize max = CGSizeMake(SF(extra->maxw), SF(extra->maxh));
- HISize min = CGSizeMake(SF(extra->minw), SF(extra->minh));
-#undef SF
- SetWindowResizeLimits(qt_mac_window_for(q), &min, &max);
-#else
#define SF(x) ((x > max_f) ? max_f : x)
NSSize max = NSMakeSize(SF(extra->maxw), SF(extra->maxh));
NSSize min = NSMakeSize(SF(extra->minw), SF(extra->minh));
#undef SF
[qt_mac_window_for(q) setContentMinSize:min];
[qt_mac_window_for(q) setContentMaxSize:max];
-#endif
}
void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
@@ -4466,17 +2405,6 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
if (realWindow && !q->testAttribute(Qt::WA_DontShowOnScreen)){
adjustWithinMaxAndMinSize(w, h);
-#ifndef QT_MAC_USE_COCOA
- if (w != 0 && h != 0) {
- topData()->isSetGeometry = 1;
- topData()->isMove = isMove;
- Rect r; SetRect(&r, x, y, x + w, y + h);
- SetWindowBounds(qt_mac_window_for(q), kWindowContentRgn, &r);
- topData()->isSetGeometry = 0;
- } else {
- setGeometry_sys_helper(x, y, w, h, isMove);
- }
-#else
if (!isMove && !q->testAttribute(Qt::WA_Moved) && !q->isVisible()) {
// INVARIANT: The location of the window has not yet been set. The default will
// instead be to center it on the desktop, or over the parent, if any. Since we now
@@ -4523,7 +2451,6 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
cocoaFrameRect.origin.y -= 1;
[window setFrameOrigin:cocoaFrameRect.origin];
}
-#endif
} else {
setGeometry_sys_helper(x, y, w, h, isMove);
}
@@ -4558,21 +2485,7 @@ void QWidgetPrivate::setGeometry_sys_helper(int x, int y, int w, int h, bool isM
adjustWithinMaxAndMinSize(w, h);
qt_mac_update_sizer(q);
-#ifndef QT_MAC_USE_COCOA
- if (q->windowFlags() & Qt::WindowMaximizeButtonHint) {
- OSWindowRef window = qt_mac_window_for(q);
- if (extra->maxw && extra->maxh && extra->maxw == extra->minw
- && extra->maxh == extra->minh) {
- ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute);
- } else {
- ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes);
- }
- }
- HIRect bounds = CGRectMake(0, 0, w, h);
- HIViewSetFrame(qt_mac_nativeview_for(q), &bounds);
-#else
[qt_mac_nativeview_for(q) setFrame:NSMakeRect(0, 0, w, h)];
-#endif
} else {
const QRect oldRect(oldp, olds);
if (!isResize && QApplicationPrivate::graphicsSystem())
@@ -4618,39 +2531,21 @@ void QWidgetPrivate::updateMaximizeButton_sys()
OSWindowRef window = qt_mac_window_for(q);
QTLWExtra * tlwExtra = topData();
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
NSButton *maximizeButton = [window standardWindowButton:NSWindowZoomButton];
-#endif
if (extra->maxw && extra->maxh
&& extra->maxw == extra->minw
&& extra->maxh == extra->minh) {
// The window has a fixed size, so gray out the maximize button:
if (!tlwExtra->savedWindowAttributesFromMaximized) {
-#ifndef QT_MAC_USE_COCOA
- GetWindowAttributes(window,
- (WindowAttributes*)&extra->topextra->savedWindowAttributesFromMaximized);
-
-#else
tlwExtra->savedWindowAttributesFromMaximized = (![maximizeButton isHidden] && [maximizeButton isEnabled]);
-#endif
}
-#ifndef QT_MAC_USE_COCOA
- ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute);
-#else
[maximizeButton setEnabled:NO];
-#endif
} else {
if (tlwExtra->savedWindowAttributesFromMaximized) {
-#ifndef QT_MAC_USE_COCOA
- ChangeWindowAttributes(window,
- extra->topextra->savedWindowAttributesFromMaximized,
- kWindowNoAttributes);
-#else
[maximizeButton setEnabled:YES];
-#endif
tlwExtra->savedWindowAttributesFromMaximized = 0;
}
}
@@ -4720,15 +2615,7 @@ void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &qscrollRect)
return;
}
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
-#else
- Q_UNUSED(isAlien);
- // We're not sure what the following call is supposed to achive
- // but until we see what it breaks, we don't bring it into the
- // Cocoa port:
- qt_event_request_window_change(q);
-#endif
// First move all native children. Alien children will indirectly be
// moved when the parent is scrolled. All directly or indirectly moved
@@ -4742,27 +2629,12 @@ void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &qscrollRect)
if (QWidget *w = qobject_cast<QWidget*>(obj)) {
if (!w->isWindow()) {
w->data->crect = QRect(w->pos() + scrollDelta, w->size());
-#ifndef QT_MAC_USE_COCOA
- if (w->testAttribute(Qt::WA_WState_Created)) {
- HIRect bounds = CGRectMake(w->data->crect.x(), w->data->crect.y(),
- w->data->crect.width(), w->data->crect.height());
- HIViewRef hiview = qt_mac_nativeview_for(w);
- const bool opaque = q->testAttribute(Qt::WA_OpaquePaintEvent);
-
- if (opaque)
- HIViewSetDrawingEnabled(hiview, false);
- HIViewSetFrame(hiview, &bounds);
- if (opaque)
- HIViewSetDrawingEnabled(hiview, true);
- }
-#else
if (NSView *view = qt_mac_nativeview_for(w)) {
// INVARIANT: w is not alien
[view setFrame:NSMakeRect(
w->data->crect.x(), w->data->crect.y(),
w->data->crect.width(), w->data->crect.height())];
}
-#endif
movedChildren.append(w);
}
}
@@ -4773,18 +2645,6 @@ void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &qscrollRect)
// Scroll q itself according to the qscrollRect, and
// call update on any exposed areas so that they get redrawn:
-#ifndef QT_MAC_USE_COCOA
- OSViewRef view = qt_mac_nativeview_for(q);
- HIRect scrollrect = CGRectMake(qscrollRect.x(), qscrollRect.y(), qscrollRect.width(), qscrollRect.height());
- OSStatus err = _HIViewScrollRectWithOptions(view, qscrollRect.isValid() ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid);
- if (err) {
- // The only parameter that can go wrong, is the rect.
- qWarning("QWidget::scroll: Your rectangle was too big for the widget, clipping rect");
- scrollrect = CGRectMake(qMax(qscrollRect.x(), 0), qMax(qscrollRect.y(), 0),
- qMin(qscrollRect.width(), q->width()), qMin(qscrollRect.height(), q->height()));
- _HIViewScrollRectWithOptions(view, qscrollRect.isValid() ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid);
- }
-#else
QWidget *nativeWidget = isAlien ? q->nativeParentWidget() : q;
if (!nativeWidget)
@@ -4858,7 +2718,6 @@ void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &qscrollRect)
if (dy != 0)
update_sys(deltaYRect);
-#endif // QT_MAC_USE_COCOA
}
for (int i=0; i<movedChildren.size(); i++) {
@@ -4877,18 +2736,10 @@ int QWidget::metric(PaintDeviceMetric m) const
return qRound(metric(PdmWidth) * 25.4 / qreal(metric(PdmDpiX)));
case PdmHeight:
case PdmWidth:
-#ifndef QT_MAC_USE_COCOA
- { HIRect rect;
- HIViewGetFrame(qt_mac_nativeview_for(this), &rect);
- if(m == PdmWidth)
- return (int)rect.size.width;
- return (int)rect.size.height; }
-#else
if (m == PdmWidth)
return data->crect.width();
else
return data->crect.height();
-#endif
case PdmDepth:
return 32;
case PdmNumColors:
@@ -4920,17 +2771,13 @@ int QWidget::metric(PaintDeviceMetric m) const
void QWidgetPrivate::createSysExtra()
{
-#ifdef QT_MAC_USE_COCOA
extra->imageMask = 0;
-#endif
}
void QWidgetPrivate::deleteSysExtra()
{
-#ifdef QT_MAC_USE_COCOA
if (extra->imageMask)
CFRelease(extra->imageMask);
-#endif
}
void QWidgetPrivate::createTLSysExtra()
@@ -4947,16 +2794,6 @@ void QWidgetPrivate::createTLSysExtra()
void QWidgetPrivate::deleteTLSysExtra()
{
-#ifndef QT_MAC_USE_COCOA
- if (extra->topextra->group) {
- qt_mac_release_window_group(extra->topextra->group);
- extra->topextra->group = 0;
- }
- if (extra->topextra->windowIcon) {
- ReleaseIconRef(extra->topextra->windowIcon);
- extra->topextra->windowIcon = 0;
- }
-#endif
}
void QWidgetPrivate::updateFrameStrut()
@@ -4968,7 +2805,6 @@ void QWidgetPrivate::updateFrameStrut()
that->data.fstrut_dirty = false;
QTLWExtra *top = that->topData();
-#if QT_MAC_USE_COCOA
// 1 Get the window frame
OSWindowRef oswnd = qt_mac_window_for(q);
NSRect frameW = [oswnd frame];
@@ -4978,11 +2814,6 @@ void QWidgetPrivate::updateFrameStrut()
(frameW.origin.y + frameW.size.height) - (frameC.origin.y + frameC.size.height),
(frameW.origin.x + frameW.size.width) - (frameC.origin.x + frameC.size.width),
frameC.origin.y - frameW.origin.y);
-#else
- Rect window_r;
- GetWindowStructureWidths(qt_mac_window_for(q), &window_r);
- top->frameStrut.setCoords(window_r.left, window_r.top, window_r.right, window_r.bottom);
-#endif
}
void QWidgetPrivate::registerDropSite(bool on)
@@ -4990,9 +2821,6 @@ void QWidgetPrivate::registerDropSite(bool on)
Q_Q(QWidget);
if (!q->testAttribute(Qt::WA_WState_Created))
return;
-#ifndef QT_MAC_USE_COCOA
- SetControlDragTrackingEnabled(qt_mac_nativeview_for(q), on);
-#else
NSWindow *win = qt_mac_window_for(q);
if (on) {
if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaWindow) class]])
@@ -5000,13 +2828,11 @@ void QWidgetPrivate::registerDropSite(bool on)
else if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaPanel) class]])
[static_cast<QT_MANGLE_NAMESPACE(QCocoaPanel) *>(win) registerDragTypes];
}
-#endif
}
void QWidgetPrivate::registerTouchWindow(bool enable)
{
Q_UNUSED(enable);
-#ifdef QT_MAC_USE_COCOA
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_6)
return;
@@ -5033,7 +2859,6 @@ void QWidgetPrivate::registerTouchWindow(bool enable)
}
}
#endif
-#endif
}
void QWidgetPrivate::setMask_sys(const QRegion &region)
@@ -5041,12 +2866,6 @@ void QWidgetPrivate::setMask_sys(const QRegion &region)
Q_UNUSED(region);
Q_Q(QWidget);
-#ifndef QT_MAC_USE_COCOA
- if (q->isWindow())
- ReshapeCustomWindow(qt_mac_window_for(q));
- else
- HIViewReshapeStructure(qt_mac_nativeview_for(q));
-#else
if (!q->internalWinId())
return;
@@ -5058,7 +2877,6 @@ void QWidgetPrivate::setMask_sys(const QRegion &region)
}
topLevelAt_cache = 0;
-#endif
}
void QWidgetPrivate::setWindowOpacity_sys(qreal level)
@@ -5074,14 +2892,9 @@ void QWidgetPrivate::setWindowOpacity_sys(qreal level)
return;
OSWindowRef oswindow = qt_mac_window_for(q);
-#if QT_MAC_USE_COCOA
[oswindow setAlphaValue:level];
-#else
- SetWindowAlpha(oswindow, level);
-#endif
}
-#ifdef QT_MAC_USE_COCOA
void QWidgetPrivate::syncCocoaMask()
{
Q_Q(QWidget);
@@ -5137,7 +2950,6 @@ void QWidgetPrivate::finishCocoaMaskSetup()
}
macSetNeedsDisplay(QRegion());
}
-#endif
struct QPaintEngineCleanupHandler
{
@@ -5170,7 +2982,6 @@ void QWidgetPrivate::setModal_sys()
const QWidget * const primaryWindow = windowParent ? windowParent->window() : 0;
OSWindowRef windowRef = qt_mac_window_for(q);
-#ifdef QT_MAC_USE_COCOA
QMacCocoaAutoReleasePool pool;
bool alreadySheet = [windowRef styleMask] & NSDocModalWindowMask;
@@ -5208,87 +3019,6 @@ void QWidgetPrivate::setModal_sys()
}
}
-#else
- const bool primaryWindowModal = primaryWindow ? primaryWindow->testAttribute(Qt::WA_ShowModal) : false;
- const bool modal = q->testAttribute(Qt::WA_ShowModal);
-
- WindowClass old_wclass;
- GetWindowClass(windowRef, &old_wclass);
-
- if (modal || primaryWindowModal) {
- if (q->windowModality() == Qt::WindowModal
- || (primaryWindow && primaryWindow->windowModality() == Qt::WindowModal)){
- // Window should be window-modal (which implies a sheet).
- if (old_wclass != kSheetWindowClass){
- // We cannot convert a created window to a sheet.
- // So we recreate the window:
- recreateMacWindow();
- return;
- }
- } else {
- // Window should be application-modal (which implies NOT using a sheet).
- if (old_wclass == kSheetWindowClass){
- // We cannot convert a sheet to a window.
- // So we recreate the window:
- recreateMacWindow();
- return;
- } else if (!(q->data->window_flags & Qt::CustomizeWindowHint)) {
- if (old_wclass == kDocumentWindowClass || old_wclass == kFloatingWindowClass || old_wclass == kUtilityWindowClass){
- // Only change the class to kMovableModalWindowClass if the no explicit jewels
- // are set (kMovableModalWindowClass can't contain them), and the current window class
- // can be converted to modal (according to carbon doc). Mind the order of
- // HIWindowChangeClass and ChangeWindowAttributes.
- WindowGroupRef group = GetWindowGroup(windowRef);
- HIWindowChangeClass(windowRef, kMovableModalWindowClass);
- quint32 tmpWattr = kWindowCloseBoxAttribute | kWindowHorizontalZoomAttribute;
- ChangeWindowAttributes(windowRef, tmpWattr, kWindowNoAttributes);
- ChangeWindowAttributes(windowRef, kWindowNoAttributes, tmpWattr);
- // If the window belongs to a qt-created group, set that group once more:
- if (data.window_flags & Qt::WindowStaysOnTopHint
- || q->windowType() == Qt::Popup
- || q->windowType() == Qt::ToolTip)
- SetWindowGroup(windowRef, group);
- }
- // Popups are usually handled "special" and are never modal.
- Qt::WindowType winType = q->windowType();
- if (winType != Qt::Popup && winType != Qt::ToolTip)
- SetWindowModality(windowRef, kWindowModalityAppModal, 0);
- }
- }
- } else if (windowRef) {
- if (old_wclass == kSheetWindowClass){
- // Converting a sheet to a window is complex. It's easier to recreate:
- recreateMacWindow();
- return;
- }
-
- SetWindowModality(windowRef, kWindowModalityNone, 0);
- if (!(q->data->window_flags & Qt::CustomizeWindowHint)) {
- if (q->window()->d_func()->topData()->wattr |= kWindowCloseBoxAttribute)
- ChangeWindowAttributes(windowRef, kWindowCloseBoxAttribute, kWindowNoAttributes);
- if (q->window()->d_func()->topData()->wattr |= kWindowHorizontalZoomAttribute)
- ChangeWindowAttributes(windowRef, kWindowHorizontalZoomAttribute, kWindowNoAttributes);
- if (q->window()->d_func()->topData()->wattr |= kWindowCollapseBoxAttribute)
- ChangeWindowAttributes(windowRef, kWindowCollapseBoxAttribute, kWindowNoAttributes);
- }
-
- WindowClass newClass = q->window()->d_func()->topData()->wclass;
- if (old_wclass != newClass && newClass != 0){
- WindowGroupRef group = GetWindowGroup(windowRef);
- HIWindowChangeClass(windowRef, newClass);
- // If the window belongs to a qt-created group, set that group once more:
- if (data.window_flags & Qt::WindowStaysOnTopHint
- || q->windowType() == Qt::Popup
- || q->windowType() == Qt::ToolTip)
- SetWindowGroup(windowRef, group);
- }
- }
-
- // Make sure that HIWindowChangeClass didn't remove drag support
- // or reset the opaque size grip setting:
- SetAutomaticControlDragTrackingEnabledForWindow(windowRef, true);
- macUpdateOpaqueSizeGrip();
-#endif
}
void QWidgetPrivate::macUpdateHideOnSuspend()
@@ -5296,17 +3026,10 @@ void QWidgetPrivate::macUpdateHideOnSuspend()
Q_Q(QWidget);
if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow() || q->windowType() != Qt::Tool)
return;
-#ifndef QT_MAC_USE_COCOA
- if(q->testAttribute(Qt::WA_MacAlwaysShowToolWindow))
- ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowHideOnSuspendAttribute);
- else
- ChangeWindowAttributes(qt_mac_window_for(q), kWindowHideOnSuspendAttribute, 0);
-#else
if(q->testAttribute(Qt::WA_MacAlwaysShowToolWindow))
[qt_mac_window_for(q) setHidesOnDeactivate:NO];
else
[qt_mac_window_for(q) setHidesOnDeactivate:YES];
-#endif
}
void QWidgetPrivate::macUpdateOpaqueSizeGrip()
@@ -5316,13 +3039,6 @@ void QWidgetPrivate::macUpdateOpaqueSizeGrip()
if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow())
return;
-#ifndef QT_MAC_USE_COCOA // Growbox is always transparent on Cocoa. Can emulate with setting a QSizeGrip
- HIViewRef growBox;
- HIViewFindByID(HIViewGetRoot(qt_mac_window_for(q)), kHIViewWindowGrowBoxID, &growBox);
- if (!growBox)
- return;
- HIGrowBoxViewSetTransparent(growBox, !q->testAttribute(Qt::WA_MacOpaqueSizeGrip));
-#endif
}
void QWidgetPrivate::macUpdateSizeAttribute()
@@ -5343,29 +3059,6 @@ void QWidgetPrivate::macUpdateSizeAttribute()
void QWidgetPrivate::macUpdateIgnoreMouseEvents()
{
-#ifndef QT_MAC_USE_COCOA // This is handled inside the mouse handler on Cocoa.
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
-
- if(q->isWindow())
- {
- if(q->testAttribute(Qt::WA_TransparentForMouseEvents))
- ChangeWindowAttributes(qt_mac_window_for(q), kWindowIgnoreClicksAttribute, 0);
- else
- ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowIgnoreClicksAttribute);
- ReshapeCustomWindow(qt_mac_window_for(q));
- } else {
-#ifndef kHIViewFeatureIgnoresClicks
-#define kHIViewFeatureIgnoresClicks kHIViewIgnoresClicks
-#endif
- if(q->testAttribute(Qt::WA_TransparentForMouseEvents))
- HIViewChangeFeatures(qt_mac_nativeview_for(q), kHIViewFeatureIgnoresClicks, 0);
- else
- HIViewChangeFeatures(qt_mac_nativeview_for(q), 0, kHIViewFeatureIgnoresClicks);
- HIViewReshapeStructure(qt_mac_nativeview_for(q));
- }
-#endif
}
void QWidgetPrivate::macUpdateMetalAttribute()
@@ -5376,40 +3069,21 @@ void QWidgetPrivate::macUpdateMetalAttribute()
return;
if (realWindow) {
-#if QT_MAC_USE_COCOA
// Cocoa doesn't let us change the style mask once it's been changed
// So, that means we need to recreate the window.
OSWindowRef cocoaWindow = qt_mac_window_for(q);
if ([cocoaWindow styleMask] & NSTexturedBackgroundWindowMask)
return;
recreateMacWindow();
-#else
- QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q));
- if (q->testAttribute(Qt::WA_MacBrushedMetal)) {
- if (layout)
- layout->updateHIToolBarStatus();
- ChangeWindowAttributes(qt_mac_window_for(q), kWindowMetalAttribute, 0);
- ChangeWindowAttributes(qt_mac_window_for(q), kWindowMetalNoContentSeparatorAttribute, 0);
- } else {
- ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalNoContentSeparatorAttribute);
- ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalAttribute);
- if (layout)
- layout->updateHIToolBarStatus();
- }
-#endif
}
}
void QWidgetPrivate::setEnabled_helper_sys(bool enable)
{
-#ifdef QT_MAC_USE_COCOA
Q_Q(QWidget);
NSView *view = qt_mac_nativeview_for(q);
if ([view isKindOfClass:[NSControl class]])
[static_cast<NSControl *>(view) setEnabled:enable];
-#else
- Q_UNUSED(enable);
-#endif
}
QT_END_NAMESPACE