src/gui/kernel/qwidget.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
   203 #elif defined(Q_WS_WIN)
   203 #elif defined(Q_WS_WIN)
   204       , noPaintOnScreen(0)
   204       , noPaintOnScreen(0)
   205       , nativeGesturePanEnabled(0)
   205       , nativeGesturePanEnabled(0)
   206 #elif defined(Q_WS_MAC)
   206 #elif defined(Q_WS_MAC)
   207       , needWindowChange(0)
   207       , needWindowChange(0)
       
   208       , hasAlienChildren(0)
   208       , window_event(0)
   209       , window_event(0)
   209       , qd_hd(0)
   210       , qd_hd(0)
   210 #endif
   211 #endif
   211 {
   212 {
   212     if (!qApp) {
   213     if (!qApp) {
   217     if (version != QObjectPrivateVersion)
   218     if (version != QObjectPrivateVersion)
   218         qFatal("Cannot mix incompatible Qt libraries");
   219         qFatal("Cannot mix incompatible Qt libraries");
   219 
   220 
   220     isWidget = true;
   221     isWidget = true;
   221     memset(high_attributes, 0, sizeof(high_attributes));
   222     memset(high_attributes, 0, sizeof(high_attributes));
       
   223 #if QT_MAC_USE_COCOA
       
   224     drawRectOriginalAdded = false;
       
   225     originalDrawMethod = true;
       
   226     changeMethods = false;
       
   227 #endif // QT_MAC_USE_COCOA
   222 #ifdef QWIDGET_EXTRA_DEBUG
   228 #ifdef QWIDGET_EXTRA_DEBUG
   223     static int count = 0;
   229     static int count = 0;
   224     qDebug() << "widgets" << ++count;
   230     qDebug() << "widgets" << ++count;
   225 #endif
   231 #endif
   226 }
   232 }
  1119     Q_Q(QWidget);
  1125     Q_Q(QWidget);
  1120     if (QApplication::type() == QApplication::Tty)
  1126     if (QApplication::type() == QApplication::Tty)
  1121         qFatal("QWidget: Cannot create a QWidget when no GUI is being used");
  1127         qFatal("QWidget: Cannot create a QWidget when no GUI is being used");
  1122 
  1128 
  1123     Q_ASSERT(allWidgets);
  1129     Q_ASSERT(allWidgets);
  1124     allWidgets->insert(q);
  1130     if (allWidgets)
       
  1131         allWidgets->insert(q);
  1125 
  1132 
  1126     QWidget *desktopWidget = 0;
  1133     QWidget *desktopWidget = 0;
  1127     if (parentWidget && parentWidget->windowType() == Qt::Desktop) {
  1134     if (parentWidget && parentWidget->windowType() == Qt::Desktop) {
  1128         desktopWidget = parentWidget;
  1135         desktopWidget = parentWidget;
  1129         parentWidget = 0;
  1136         parentWidget = 0;
  1165     data.in_destructor = false;
  1172     data.in_destructor = false;
  1166 
  1173 
  1167     // Widgets with Qt::MSWindowsOwnDC (typically QGLWidget) must have a window handle.
  1174     // Widgets with Qt::MSWindowsOwnDC (typically QGLWidget) must have a window handle.
  1168     if (f & Qt::MSWindowsOwnDC)
  1175     if (f & Qt::MSWindowsOwnDC)
  1169         q->setAttribute(Qt::WA_NativeWindow);
  1176         q->setAttribute(Qt::WA_NativeWindow);
       
  1177 
       
  1178 #ifdef Q_WS_MAC
       
  1179     q->setAttribute(Qt::WA_NativeWindow);
       
  1180 #endif
  1170 
  1181 
  1171     q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute()
  1182     q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute()
  1172     adjustQuitOnCloseAttribute();
  1183     adjustQuitOnCloseAttribute();
  1173 
  1184 
  1174     q->setAttribute(Qt::WA_WState_Hidden);
  1185     q->setAttribute(Qt::WA_WState_Hidden);
  1261         type = Qt::Window;
  1272         type = Qt::Window;
  1262         flags |= Qt::Window;
  1273         flags |= Qt::Window;
  1263     }
  1274     }
  1264 
  1275 
  1265     if (QWidget *parent = parentWidget()) {
  1276     if (QWidget *parent = parentWidget()) {
       
  1277 #ifdef Q_WS_MAC
       
  1278         if (testAttribute(Qt::WA_NativeWindow) == false)
       
  1279             parent->d_func()->hasAlienChildren = true;
       
  1280 #endif
  1266         if (type & Qt::Window) {
  1281         if (type & Qt::Window) {
  1267             if (!parent->testAttribute(Qt::WA_WState_Created))
  1282             if (!parent->testAttribute(Qt::WA_WState_Created))
  1268                 parent->createWinId();
  1283                 parent->createWinId();
  1269         } else if (testAttribute(Qt::WA_NativeWindow) && !parent->internalWinId()
  1284         } else if (testAttribute(Qt::WA_NativeWindow) && !parent->internalWinId()
  1270                    && !testAttribute(Qt::WA_DontCreateNativeAncestors)) {
  1285                    && !testAttribute(Qt::WA_DontCreateNativeAncestors)) {
  1371 #if defined (QT_CHECK_STATE)
  1386 #if defined (QT_CHECK_STATE)
  1372     if (paintingActive())
  1387     if (paintingActive())
  1373         qWarning("QWidget: %s (%s) deleted while being painted", className(), name());
  1388         qWarning("QWidget: %s (%s) deleted while being painted", className(), name());
  1374 #endif
  1389 #endif
  1375 
  1390 
       
  1391     foreach (Qt::GestureType type, d->gestureContext.keys())
       
  1392         ungrabGesture(type);
       
  1393 
  1376     // force acceptDrops false before winId is destroyed.
  1394     // force acceptDrops false before winId is destroyed.
  1377     d->registerDropSite(false);
  1395     d->registerDropSite(false);
  1378 
  1396 
  1379 #ifndef QT_NO_ACTION
  1397 #ifndef QT_NO_ACTION
  1380     // remove all actions from this widget
  1398     // remove all actions from this widget
  1431                 // and if that also doesn't work, then give up
  1449                 // and if that also doesn't work, then give up
  1432             }
  1450             }
  1433         }
  1451         }
  1434     }
  1452     }
  1435 
  1453 
  1436 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS)
  1454 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_MAC)
  1437     else if (!internalWinId() && isVisible()) {
  1455     else if (!internalWinId() && isVisible()) {
  1438         qApp->d_func()->sendSyntheticEnterLeave(this);
  1456         qApp->d_func()->sendSyntheticEnterLeave(this);
  1439 #ifdef Q_WS_QWS
  1457 #ifdef Q_WS_QWS
  1440     } else if (isVisible()) {
  1458     } else if (isVisible()) {
  1441         qApp->d_func()->sendSyntheticEnterLeave(this);
  1459         qApp->d_func()->sendSyntheticEnterLeave(this);
  1466 
  1484 
  1467     // set all QPointers for this object to zero
  1485     // set all QPointers for this object to zero
  1468     QObjectPrivate::clearGuards(this);
  1486     QObjectPrivate::clearGuards(this);
  1469 
  1487 
  1470     if (d->declarativeData) {
  1488     if (d->declarativeData) {
  1471         d->declarativeData->destroyed(this);
  1489         QAbstractDeclarativeData::destroyed(d->declarativeData, this);
  1472         d->declarativeData = 0;                 // don't activate again in ~QObject
  1490         d->declarativeData = 0;                 // don't activate again in ~QObject
  1473     }
  1491     }
       
  1492 
       
  1493 #ifdef QT_MAC_USE_COCOA
       
  1494     // QCocoaView holds a pointer back to this widget. Clear it now
       
  1495     // to make sure it's not followed later on. The lifetime of the
       
  1496     // QCocoaView might exceed the lifetime of this widget in cases
       
  1497     // where Cocoa itself holds references to it.
       
  1498     extern void qt_mac_clearCocoaViewQWidgetPointers(QWidget *);
       
  1499     qt_mac_clearCocoaViewQWidgetPointers(this);
       
  1500 #endif
  1474 
  1501 
  1475     if (!d->children.isEmpty())
  1502     if (!d->children.isEmpty())
  1476         d->deleteChildren();
  1503         d->deleteChildren();
  1477 
  1504 
  1478     QApplication::removePostedEvents(this);
  1505     QApplication::removePostedEvents(this);
  1552         x->posFromMove = false;
  1579         x->posFromMove = false;
  1553         x->sizeAdjusted = false;
  1580         x->sizeAdjusted = false;
  1554         x->inTopLevelResize = false;
  1581         x->inTopLevelResize = false;
  1555         x->inRepaint = false;
  1582         x->inRepaint = false;
  1556         x->embedded = 0;
  1583         x->embedded = 0;
       
  1584 #ifdef Q_WS_MAC
       
  1585 #ifdef QT_MAC_USE_COCOA
       
  1586         x->wasMaximized = false;
       
  1587 #endif // QT_MAC_USE_COCOA
       
  1588 #endif // Q_WS_MAC
  1557         createTLSysExtra();
  1589         createTLSysExtra();
  1558 #ifdef QWIDGET_EXTRA_DEBUG
  1590 #ifdef QWIDGET_EXTRA_DEBUG
  1559         static int count = 0;
  1591         static int count = 0;
  1560         qDebug() << "tlextra" << ++count;
  1592         qDebug() << "tlextra" << ++count;
  1561 #endif
  1593 #endif
  2299     \sa find()
  2331     \sa find()
  2300 */
  2332 */
  2301 WId QWidget::winId() const
  2333 WId QWidget::winId() const
  2302 {
  2334 {
  2303     if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
  2335     if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
       
  2336 #ifdef ALIEN_DEBUG
       
  2337         qDebug() << "QWidget::winId: creating native window for" << this;
       
  2338 #endif
  2304         QWidget *that = const_cast<QWidget*>(this);
  2339         QWidget *that = const_cast<QWidget*>(this);
  2305         that->setAttribute(Qt::WA_NativeWindow);
  2340         that->setAttribute(Qt::WA_NativeWindow);
  2306         that->d_func()->createWinId();
  2341         that->d_func()->createWinId();
  2307         return that->data->winid;
  2342         return that->data->winid;
  2308     }
  2343     }
  2311 
  2346 
  2312 
  2347 
  2313 void QWidgetPrivate::createWinId(WId winid)
  2348 void QWidgetPrivate::createWinId(WId winid)
  2314 {
  2349 {
  2315     Q_Q(QWidget);
  2350     Q_Q(QWidget);
       
  2351 
       
  2352 #ifdef ALIEN_DEBUG
       
  2353     qDebug() << "QWidgetPrivate::createWinId for" << q << winid;
       
  2354 #endif
  2316     const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
  2355     const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
  2317     if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
  2356     if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
  2318         if (!q->isWindow()) {
  2357         if (!q->isWindow()) {
  2319             QWidget *parent = q->parentWidget();
  2358             QWidget *parent = q->parentWidget();
  2320             QWidgetPrivate *pd = parent->d_func();
  2359             QWidgetPrivate *pd = parent->d_func();
  2353 */
  2392 */
  2354 
  2393 
  2355 void QWidget::createWinId()
  2394 void QWidget::createWinId()
  2356 {
  2395 {
  2357     Q_D(QWidget);
  2396     Q_D(QWidget);
       
  2397 #ifdef ALIEN_DEBUG
       
  2398     qDebug()  << "QWidget::createWinId" << this;
       
  2399 #endif
  2358 //    qWarning("QWidget::createWinId is obsolete, please fix your code.");
  2400 //    qWarning("QWidget::createWinId is obsolete, please fix your code.");
  2359     d->createWinId();
  2401     d->createWinId();
  2360 }
  2402 }
  2361 
  2403 
  2362 /*!
  2404 /*!
  2499         )
  2541         )
  2500 {
  2542 {
  2501     Q_Q(QWidget);
  2543     Q_Q(QWidget);
  2502     QStyle *oldStyle  = q->style();
  2544     QStyle *oldStyle  = q->style();
  2503 #ifndef QT_NO_STYLE_STYLESHEET
  2545 #ifndef QT_NO_STYLE_STYLESHEET
  2504     QStyle *origStyle = 0;
  2546     QWeakPointer<QStyle> origStyle;
  2505 #endif
  2547 #endif
  2506 
  2548 
  2507 #ifdef Q_WS_MAC
  2549 #ifdef Q_WS_MAC
  2508     // the metalhack boolean allows Qt/Mac to do a proper re-polish depending
  2550     // the metalhack boolean allows Qt/Mac to do a proper re-polish depending
  2509     // on how the Qt::WA_MacBrushedMetal attribute is set. It is only ever
  2551     // on how the Qt::WA_MacBrushedMetal attribute is set. It is only ever
  2513 #endif
  2555 #endif
  2514     {
  2556     {
  2515         createExtra();
  2557         createExtra();
  2516 
  2558 
  2517 #ifndef QT_NO_STYLE_STYLESHEET
  2559 #ifndef QT_NO_STYLE_STYLESHEET
  2518         origStyle = extra->style;
  2560         origStyle = extra->style.data();
  2519 #endif
  2561 #endif
  2520         extra->style = newStyle;
  2562         extra->style = newStyle;
  2521     }
  2563     }
  2522 
  2564 
  2523     // repolish
  2565     // repolish
  2542             if (c)
  2584             if (c)
  2543                 c->d_func()->inheritStyle();
  2585                 c->d_func()->inheritStyle();
  2544         }
  2586         }
  2545     }
  2587     }
  2546 
  2588 
       
  2589 #ifndef QT_NO_STYLE_STYLESHEET
       
  2590     if (!qobject_cast<QStyleSheetStyle*>(newStyle)) {
       
  2591         if (const QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(origStyle.data())) {
       
  2592             cssStyle->clearWidgetFont(q);
       
  2593         }
       
  2594     }
       
  2595 #endif
       
  2596 
  2547     QEvent e(QEvent::StyleChange);
  2597     QEvent e(QEvent::StyleChange);
  2548     QApplication::sendEvent(q, &e);
  2598     QApplication::sendEvent(q, &e);
  2549 #ifdef QT3_SUPPORT
  2599 #ifdef QT3_SUPPORT
  2550     q->styleChange(*oldStyle);
  2600     q->styleChange(*oldStyle);
  2551 #endif
  2601 #endif
  2552 
  2602 
  2553 #ifndef QT_NO_STYLE_STYLESHEET
  2603 #ifndef QT_NO_STYLE_STYLESHEET
  2554     if (!qobject_cast<QStyleSheetStyle*>(newStyle)) {
       
  2555         if (const QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(origStyle)) {
       
  2556             cssStyle->clearWidgetFont(q);
       
  2557         }
       
  2558     }
       
  2559 #endif
       
  2560 
       
  2561 #ifndef QT_NO_STYLE_STYLESHEET
       
  2562     // dereference the old stylesheet style
  2604     // dereference the old stylesheet style
  2563     if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(origStyle))
  2605     if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(origStyle.data()))
  2564         proxy->deref();
  2606         proxy->deref();
  2565 #endif
  2607 #endif
  2566 }
  2608 }
  2567 
  2609 
  2568 // Inherits style from the current parent and propagates it as necessary
  2610 // Inherits style from the current parent and propagates it as necessary
  4882     or QGLWidget::renderPixmap() instead.
  4924     or QGLWidget::renderPixmap() instead.
  4883 */
  4925 */
  4884 void QWidget::render(QPaintDevice *target, const QPoint &targetOffset,
  4926 void QWidget::render(QPaintDevice *target, const QPoint &targetOffset,
  4885                      const QRegion &sourceRegion, RenderFlags renderFlags)
  4927                      const QRegion &sourceRegion, RenderFlags renderFlags)
  4886 {
  4928 {
  4887     Q_D(QWidget);
  4929     d_func()->render(target, targetOffset, sourceRegion, renderFlags, false);
  4888     if (!target) {
       
  4889         qWarning("QWidget::render: null pointer to paint device");
       
  4890         return;
       
  4891     }
       
  4892 
       
  4893     const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter;
       
  4894     QRegion paintRegion = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags)
       
  4895                                                : sourceRegion;
       
  4896     if (paintRegion.isEmpty())
       
  4897         return;
       
  4898 
       
  4899 #ifndef Q_WS_MAC
       
  4900     QPainter *oldSharedPainter = inRenderWithPainter ? d->sharedPainter() : 0;
       
  4901 
       
  4902     // Use the target's shared painter if set (typically set when doing
       
  4903     // "other->render(widget);" in the widget's paintEvent.
       
  4904     if (target->devType() == QInternal::Widget) {
       
  4905         QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func();
       
  4906         if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) {
       
  4907             QPainter *targetPainter = targetPrivate->sharedPainter();
       
  4908             if (targetPainter && targetPainter->isActive())
       
  4909                 d->setSharedPainter(targetPainter);
       
  4910         }
       
  4911     }
       
  4912 #endif
       
  4913 
       
  4914     // Use the target's redirected device if set and adjust offset and paint
       
  4915     // region accordingly. This is typically the case when people call render
       
  4916     // from the paintEvent.
       
  4917     QPoint offset = targetOffset;
       
  4918     offset -= paintRegion.boundingRect().topLeft();
       
  4919     QPoint redirectionOffset;
       
  4920     QPaintDevice *redirected = 0;
       
  4921 
       
  4922     if (target->devType() == QInternal::Widget)
       
  4923         redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset);
       
  4924     if (!redirected)
       
  4925         redirected = QPainter::redirected(target, &redirectionOffset);
       
  4926 
       
  4927     if (redirected) {
       
  4928         target = redirected;
       
  4929         offset -= redirectionOffset;
       
  4930     }
       
  4931 
       
  4932     if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp).
       
  4933         if (QPaintEngine *targetEngine = target->paintEngine()) {
       
  4934             const QRegion targetSystemClip = targetEngine->systemClip();
       
  4935             if (!targetSystemClip.isEmpty())
       
  4936                 paintRegion &= targetSystemClip.translated(-offset);
       
  4937         }
       
  4938     }
       
  4939 
       
  4940     // Set backingstore flags.
       
  4941     int flags = QWidgetPrivate::DrawPaintOnScreen | QWidgetPrivate::DrawInvisible;
       
  4942     if (renderFlags & DrawWindowBackground)
       
  4943         flags |= QWidgetPrivate::DrawAsRoot;
       
  4944 
       
  4945     if (renderFlags & DrawChildren)
       
  4946         flags |= QWidgetPrivate::DrawRecursive;
       
  4947     else
       
  4948         flags |= QWidgetPrivate::DontSubtractOpaqueChildren;
       
  4949 
       
  4950 #ifdef Q_WS_QWS
       
  4951     flags |= QWidgetPrivate::DontSetCompositionMode;
       
  4952 #endif
       
  4953 
       
  4954     if (target->devType() == QInternal::Printer) {
       
  4955         QPainter p(target);
       
  4956         d->render_helper(&p, targetOffset, paintRegion, renderFlags);
       
  4957         return;
       
  4958     }
       
  4959 
       
  4960 #ifndef Q_WS_MAC
       
  4961     // Render via backingstore.
       
  4962     d->drawWidget(target, paintRegion, offset, flags, d->sharedPainter());
       
  4963 
       
  4964     // Restore shared painter.
       
  4965     if (oldSharedPainter)
       
  4966         d->setSharedPainter(oldSharedPainter);
       
  4967 #else
       
  4968     // Render via backingstore (no shared painter).
       
  4969     d->drawWidget(target, paintRegion, offset, flags, 0);
       
  4970 #endif
       
  4971 }
  4930 }
  4972 
  4931 
  4973 /*!
  4932 /*!
  4974     \overload
  4933     \overload
  4975 
  4934 
  5325             bool flushed = QWidgetBackingStore::flushPaint(q, toBePainted);
  5284             bool flushed = QWidgetBackingStore::flushPaint(q, toBePainted);
  5326 #endif
  5285 #endif
  5327             QPaintEngine *paintEngine = pdev->paintEngine();
  5286             QPaintEngine *paintEngine = pdev->paintEngine();
  5328             if (paintEngine) {
  5287             if (paintEngine) {
  5329                 setRedirected(pdev, -offset);
  5288                 setRedirected(pdev, -offset);
  5330 
  5289 #ifdef Q_WS_MAC
       
  5290                 // (Alien support) Special case for Mac when redirecting: If the paint device
       
  5291                 // is of the Widget type we need to set WA_WState_InPaintEvent since painting
       
  5292                 // outside the paint event is not supported on QWidgets. The attributeis
       
  5293                 // restored further down.
       
  5294                 if (pdev->devType() == QInternal::Widget)
       
  5295                     static_cast<QWidget *>(pdev)->setAttribute(Qt::WA_WState_InPaintEvent);
       
  5296 
       
  5297 #endif
  5331                 if (sharedPainter)
  5298                 if (sharedPainter)
  5332                     paintEngine->d_func()->systemClip = toBePainted;
  5299                     paintEngine->d_func()->systemClip = toBePainted;
  5333                 else
  5300                 else
  5334                     paintEngine->d_func()->systemRect = q->data->crect;
  5301                     paintEngine->d_func()->systemRect = q->data->crect;
  5335 
  5302 
  5366                 backingStore->markDirtyOnScreen(toBePainted, q, offset);
  5333                 backingStore->markDirtyOnScreen(toBePainted, q, offset);
  5367 #endif
  5334 #endif
  5368 
  5335 
  5369             //restore
  5336             //restore
  5370             if (paintEngine) {
  5337             if (paintEngine) {
       
  5338 #ifdef Q_WS_MAC
       
  5339                 if (pdev->devType() == QInternal::Widget)
       
  5340                     static_cast<QWidget *>(pdev)->setAttribute(Qt::WA_WState_InPaintEvent, false);
       
  5341 #endif
  5371                 restoreRedirected();
  5342                 restoreRedirected();
  5372                 if (!sharedPainter)
  5343                 if (!sharedPainter)
  5373                     paintEngine->d_func()->systemRect = QRect();
  5344                     paintEngine->d_func()->systemRect = QRect();
  5374                 else
  5345                 else
  5375                     paintEngine->d_func()->currentClipWidget = 0;
  5346                     paintEngine->d_func()->currentClipWidget = 0;
  5409 #ifdef Q_BACKINGSTORE_SUBSURFACES
  5380 #ifdef Q_BACKINGSTORE_SUBSURFACES
  5410                                 , q->windowSurface()
  5381                                 , q->windowSurface()
  5411 #endif
  5382 #endif
  5412                                 , sharedPainter, backingStore);
  5383                                 , sharedPainter, backingStore);
  5413     }
  5384     }
       
  5385 }
       
  5386 
       
  5387 void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset,
       
  5388                             const QRegion &sourceRegion, QWidget::RenderFlags renderFlags,
       
  5389                             bool readyToRender)
       
  5390 {
       
  5391     if (!target) {
       
  5392         qWarning("QWidget::render: null pointer to paint device");
       
  5393         return;
       
  5394     }
       
  5395 
       
  5396     const bool inRenderWithPainter = extra && extra->inRenderWithPainter;
       
  5397     QRegion paintRegion = !inRenderWithPainter && !readyToRender
       
  5398                           ? prepareToRender(sourceRegion, renderFlags)
       
  5399                           : sourceRegion;
       
  5400     if (paintRegion.isEmpty())
       
  5401         return;
       
  5402 
       
  5403 #ifndef Q_WS_MAC
       
  5404     QPainter *oldSharedPainter = inRenderWithPainter ? sharedPainter() : 0;
       
  5405 
       
  5406     // Use the target's shared painter if set (typically set when doing
       
  5407     // "other->render(widget);" in the widget's paintEvent.
       
  5408     if (target->devType() == QInternal::Widget) {
       
  5409         QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func();
       
  5410         if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) {
       
  5411             QPainter *targetPainter = targetPrivate->sharedPainter();
       
  5412             if (targetPainter && targetPainter->isActive())
       
  5413                 setSharedPainter(targetPainter);
       
  5414         }
       
  5415     }
       
  5416 #endif
       
  5417 
       
  5418     // Use the target's redirected device if set and adjust offset and paint
       
  5419     // region accordingly. This is typically the case when people call render
       
  5420     // from the paintEvent.
       
  5421     QPoint offset = targetOffset;
       
  5422     offset -= paintRegion.boundingRect().topLeft();
       
  5423     QPoint redirectionOffset;
       
  5424     QPaintDevice *redirected = 0;
       
  5425 
       
  5426     if (target->devType() == QInternal::Widget)
       
  5427         redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset);
       
  5428     if (!redirected)
       
  5429         redirected = QPainter::redirected(target, &redirectionOffset);
       
  5430 
       
  5431     if (redirected) {
       
  5432         target = redirected;
       
  5433         offset -= redirectionOffset;
       
  5434     }
       
  5435 
       
  5436     if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp).
       
  5437         if (QPaintEngine *targetEngine = target->paintEngine()) {
       
  5438             const QRegion targetSystemClip = targetEngine->systemClip();
       
  5439             if (!targetSystemClip.isEmpty())
       
  5440                 paintRegion &= targetSystemClip.translated(-offset);
       
  5441         }
       
  5442     }
       
  5443 
       
  5444     // Set backingstore flags.
       
  5445     int flags = DrawPaintOnScreen | DrawInvisible;
       
  5446     if (renderFlags & QWidget::DrawWindowBackground)
       
  5447         flags |= DrawAsRoot;
       
  5448 
       
  5449     if (renderFlags & QWidget::DrawChildren)
       
  5450         flags |= DrawRecursive;
       
  5451     else
       
  5452         flags |= DontSubtractOpaqueChildren;
       
  5453 
       
  5454 #ifdef Q_WS_QWS
       
  5455     flags |= DontSetCompositionMode;
       
  5456 #endif
       
  5457 
       
  5458     if (target->devType() == QInternal::Printer) {
       
  5459         QPainter p(target);
       
  5460         render_helper(&p, targetOffset, paintRegion, renderFlags);
       
  5461         return;
       
  5462     }
       
  5463 
       
  5464 #ifndef Q_WS_MAC
       
  5465     // Render via backingstore.
       
  5466     drawWidget(target, paintRegion, offset, flags, sharedPainter());
       
  5467 
       
  5468     // Restore shared painter.
       
  5469     if (oldSharedPainter)
       
  5470         setSharedPainter(oldSharedPainter);
       
  5471 #else
       
  5472     // Render via backingstore (no shared painter).
       
  5473     drawWidget(target, paintRegion, offset, flags, 0);
       
  5474 #endif
  5414 }
  5475 }
  5415 
  5476 
  5416 void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn,
  5477 void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn,
  5417                                             const QPoint &offset, int flags
  5478                                             const QPoint &offset, int flags
  5418 #ifdef Q_BACKINGSTORE_SUBSURFACES
  5479 #ifdef Q_BACKINGSTORE_SUBSURFACES
  5528         const QTransform &painterTransform = context->painter->worldTransform();
  5589         const QTransform &painterTransform = context->painter->worldTransform();
  5529         sourceRect = painterTransform.mapRect(sourceRect);
  5590         sourceRect = painterTransform.mapRect(sourceRect);
  5530         pixmapOffset = painterTransform.map(pixmapOffset);
  5591         pixmapOffset = painterTransform.map(pixmapOffset);
  5531     }
  5592     }
  5532 
  5593 
  5533 
       
  5534     QRect effectRect;
  5594     QRect effectRect;
  5535 
  5595 
  5536     if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) {
  5596     if (mode == QGraphicsEffect::PadToEffectiveBoundingRect)
  5537         effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect();
  5597         effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect();
  5538 
  5598     else if (mode == QGraphicsEffect::PadToTransparentBorder)
  5539     } else if (mode == QGraphicsEffect::PadToTransparentBorder) {
       
  5540         effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect();
  5599         effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect();
  5541 
  5600     else
  5542     } else {
       
  5543         effectRect = sourceRect.toAlignedRect();
  5601         effectRect = sourceRect.toAlignedRect();
  5544 
       
  5545     }
       
  5546 
  5602 
  5547     if (offset)
  5603     if (offset)
  5548         *offset = effectRect.topLeft();
  5604         *offset = effectRect.topLeft();
  5549 
  5605 
  5550     if (deviceCoordinates) {
       
  5551         // Clip to device rect.
       
  5552         int left, top, right, bottom;
       
  5553         effectRect.getCoords(&left, &top, &right, &bottom);
       
  5554         if (left < 0) {
       
  5555             if (offset)
       
  5556                 offset->rx() += -left;
       
  5557             effectRect.setX(0);
       
  5558         }
       
  5559         if (top < 0) {
       
  5560             if (offset)
       
  5561                 offset->ry() += -top;
       
  5562             effectRect.setY(0);
       
  5563         }
       
  5564         // NB! We use +-1 for historical reasons (see QRect documentation).
       
  5565         QPaintDevice *device = context->painter->device();
       
  5566         const int deviceWidth = device->width();
       
  5567         const int deviceHeight = device->height();
       
  5568         if (right + 1 > deviceWidth)
       
  5569             effectRect.setRight(deviceWidth - 1);
       
  5570         if (bottom + 1 > deviceHeight)
       
  5571             effectRect.setBottom(deviceHeight -1);
       
  5572     }
       
  5573 
       
  5574     pixmapOffset -= effectRect.topLeft();
  5606     pixmapOffset -= effectRect.topLeft();
  5575 
  5607 
  5576     QPixmap pixmap(effectRect.size());
  5608     QPixmap pixmap(effectRect.size());
  5577     pixmap.fill(Qt::transparent);
  5609     pixmap.fill(Qt::transparent);
  5578     m_widget->render(&pixmap, pixmapOffset);
  5610     m_widget->render(&pixmap, pixmapOffset, QRegion(), QWidget::DrawChildren);
  5579     return pixmap;
  5611     return pixmap;
  5580 }
  5612 }
  5581 #endif //QT_NO_GRAPHICSEFFECT
  5613 #endif //QT_NO_GRAPHICSEFFECT
  5582 
  5614 
  5583 #ifndef QT_NO_GRAPHICSVIEW
  5615 #ifndef QT_NO_GRAPHICSVIEW
  6177                     QApplication::sendEvent(previousProxyFocus, &event);
  6209                     QApplication::sendEvent(previousProxyFocus, &event);
  6178                     if (that)
  6210                     if (that)
  6179                         QApplication::sendEvent(that->style(), &event);
  6211                         QApplication::sendEvent(that->style(), &event);
  6180                 }
  6212                 }
  6181                 if (!isHidden()) {
  6213                 if (!isHidden()) {
       
  6214 #ifndef QT_NO_GRAPHICSVIEW
       
  6215                     // Update proxy state
       
  6216                     if (QWExtra *topData = window()->d_func()->extra)
       
  6217                         if (topData->proxyWidget && topData->proxyWidget->hasFocus())
       
  6218                             topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget();
       
  6219 #endif
  6182                     // Send event to self
  6220                     // Send event to self
  6183                     QFocusEvent event(QEvent::FocusIn, reason);
  6221                     QFocusEvent event(QEvent::FocusIn, reason);
  6184                     QPointer<QWidget> that = f;
  6222                     QPointer<QWidget> that = f;
  6185                     QApplication::sendEvent(f, &event);
  6223                     QApplication::sendEvent(f, &event);
  6186                     if (that)
  6224                     if (that)
  6456         second = sp;
  6494         second = sp;
  6457 
  6495 
  6458 //    QWidget *fp = first->d_func()->focus_prev;
  6496 //    QWidget *fp = first->d_func()->focus_prev;
  6459     QWidget *fn = first->d_func()->focus_next;
  6497     QWidget *fn = first->d_func()->focus_next;
  6460 
  6498 
  6461     if (fn == second)
  6499     if (fn == second || first == second)
  6462         return;
  6500         return;
  6463 
  6501 
  6464     QWidget *sp = second->d_func()->focus_prev;
  6502     QWidget *sp = second->d_func()->focus_prev;
  6465     QWidget *sn = second->d_func()->focus_next;
  6503     QWidget *sn = second->d_func()->focus_next;
  6466 
  6504 
  6685 
  6723 
  6686     \sa restoreGeometry(), QMainWindow::saveState(), QMainWindow::restoreState()
  6724     \sa restoreGeometry(), QMainWindow::saveState(), QMainWindow::restoreState()
  6687 */
  6725 */
  6688 QByteArray QWidget::saveGeometry() const
  6726 QByteArray QWidget::saveGeometry() const
  6689 {
  6727 {
       
  6728 #ifdef QT_MAC_USE_COCOA
       
  6729     // We check if the window was maximized during this invocation. If so, we need to record the
       
  6730     // starting position as 0,0.
       
  6731     Q_D(const QWidget);
       
  6732     QRect newFramePosition = frameGeometry();
       
  6733     QRect newNormalPosition = normalGeometry();
       
  6734     if(d->topData()->wasMaximized && !(windowState() & Qt::WindowMaximized)) {
       
  6735         // Change the starting position
       
  6736         newFramePosition.moveTo(0, 0);
       
  6737         newNormalPosition.moveTo(0, 0);
       
  6738     }
       
  6739 #endif // QT_MAC_USE_COCOA
  6690     QByteArray array;
  6740     QByteArray array;
  6691     QDataStream stream(&array, QIODevice::WriteOnly);
  6741     QDataStream stream(&array, QIODevice::WriteOnly);
  6692     stream.setVersion(QDataStream::Qt_4_0);
  6742     stream.setVersion(QDataStream::Qt_4_0);
  6693     const quint32 magicNumber = 0x1D9D0CB;
  6743     const quint32 magicNumber = 0x1D9D0CB;
  6694     quint16 majorVersion = 1;
  6744     quint16 majorVersion = 1;
  6695     quint16 minorVersion = 0;
  6745     quint16 minorVersion = 0;
  6696     stream << magicNumber
  6746     stream << magicNumber
  6697            << majorVersion
  6747            << majorVersion
  6698            << minorVersion
  6748            << minorVersion
       
  6749 #ifdef QT_MAC_USE_COCOA
       
  6750            << newFramePosition
       
  6751            << newNormalPosition
       
  6752 #else
  6699            << frameGeometry()
  6753            << frameGeometry()
  6700            << normalGeometry()
  6754            << normalGeometry()
       
  6755 #endif // QT_MAC_USE_COCOA
  6701            << qint32(QApplication::desktop()->screenNumber(this))
  6756            << qint32(QApplication::desktop()->screenNumber(this))
  6702            << quint8(windowState() & Qt::WindowMaximized)
  6757            << quint8(windowState() & Qt::WindowMaximized)
  6703            << quint8(windowState() & Qt::WindowFullScreen);
  6758            << quint8(windowState() & Qt::WindowFullScreen);
  6704     return array;
  6759     return array;
  6705 }
  6760 }
  7272 {
  7327 {
  7273     Q_Q(QWidget);
  7328     Q_Q(QWidget);
  7274 
  7329 
  7275     bool isEmbedded = false;
  7330     bool isEmbedded = false;
  7276 #if !defined QT_NO_GRAPHICSVIEW
  7331 #if !defined QT_NO_GRAPHICSVIEW
  7277     isEmbedded = q->isWindow() && nearestGraphicsProxyWidget(q->parentWidget()) != 0;
  7332     isEmbedded = q->isWindow() && !bypassGraphicsProxyWidget(q) && nearestGraphicsProxyWidget(q->parentWidget()) != 0;
  7278 #else
  7333 #else
  7279     Q_UNUSED(isEmbedded);
  7334     Q_UNUSED(isEmbedded);
  7280 #endif
  7335 #endif
  7281 
  7336 
  7282     if (!isEmbedded && (q->windowType() == Qt::Popup))
  7337     if (!isEmbedded && (q->windowType() == Qt::Popup))
  7309     hideChildren(false);
  7364     hideChildren(false);
  7310 
  7365 
  7311     // next bit tries to move the focus if the focus widget is now
  7366     // next bit tries to move the focus if the focus widget is now
  7312     // hidden.
  7367     // hidden.
  7313     if (wasVisible) {
  7368     if (wasVisible) {
  7314 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS)
  7369 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_MAC)
  7315         qApp->d_func()->sendSyntheticEnterLeave(q);
  7370         qApp->d_func()->sendSyntheticEnterLeave(q);
  7316 #endif
  7371 #endif
  7317 
  7372 
  7318         QWidget *fw = QApplication::focusWidget();
  7373         QWidget *fw = QApplication::focusWidget();
  7319         while (fw &&  !fw->isWindow()) {
  7374         while (fw &&  !fw->isWindow()) {
  7441             // remove posted quit events when showing a new window
  7496             // remove posted quit events when showing a new window
  7442             QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
  7497             QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
  7443 
  7498 
  7444             d->show_helper();
  7499             d->show_helper();
  7445 
  7500 
  7446 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS)
  7501 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_MAC)
  7447             qApp->d_func()->sendSyntheticEnterLeave(this);
  7502             qApp->d_func()->sendSyntheticEnterLeave(this);
  7448 #endif
  7503 #endif
  7449         }
  7504         }
  7450 
  7505 
  7451         QEvent showToParentEvent(QEvent::ShowToParent);
  7506         QEvent showToParentEvent(QEvent::ShowToParent);
  7573                 // hide_sys() on an ancestor won't have any affect on this
  7628                 // hide_sys() on an ancestor won't have any affect on this
  7574                 // widget, so it needs an explicit hide_sys() of its own
  7629                 // widget, so it needs an explicit hide_sys() of its own
  7575                 widget->d_func()->hide_sys();
  7630                 widget->d_func()->hide_sys();
  7576             }
  7631             }
  7577         }
  7632         }
  7578 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS)
  7633 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_MAC)
  7579         qApp->d_func()->sendSyntheticEnterLeave(widget);
  7634         qApp->d_func()->sendSyntheticEnterLeave(widget);
  7580 #endif
  7635 #endif
  7581 #ifndef QT_NO_ACCESSIBILITY
  7636 #ifndef QT_NO_ACCESSIBILITY
  7582         if (!spontaneous)
  7637         if (!spontaneous)
  7583             QAccessible::updateAccessibility(widget, 0, QAccessible::ObjectHide);
  7638             QAccessible::updateAccessibility(widget, 0, QAccessible::ObjectHide);
  7617 
  7672 
  7618 #ifdef QT3_SUPPORT
  7673 #ifdef QT3_SUPPORT
  7619     if (isMain)
  7674     if (isMain)
  7620         QApplication::quit();
  7675         QApplication::quit();
  7621 #endif
  7676 #endif
  7622     // Attempt to close the application only if this widget has the
  7677     // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent
  7623     // WA_QuitOnClose flag set set and has a non-visible parent
  7678     quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible());
  7624     quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible() || parentWidget->testAttribute(Qt::WA_DontShowOnScreen));
       
  7625 
  7679 
  7626     if (quitOnClose) {
  7680     if (quitOnClose) {
  7627         // If there is no non-withdrawn primary window left (except
  7681         /* if there is no non-withdrawn primary window left (except
  7628         // the ones without QuitOnClose or with WA_DontShowOnScreen),
  7682            the ones without QuitOnClose), we emit the lastWindowClosed
  7629         // we emit the lastWindowClosed signal
  7683            signal */
  7630         QWidgetList list = QApplication::topLevelWidgets();
  7684         QWidgetList list = QApplication::topLevelWidgets();
  7631         bool lastWindowClosed = true;
  7685         bool lastWindowClosed = true;
  7632         for (int i = 0; i < list.size(); ++i) {
  7686         for (int i = 0; i < list.size(); ++i) {
  7633             QWidget *w = list.at(i);
  7687             QWidget *w = list.at(i);
  7634             if ((w->isVisible() && !w->testAttribute(Qt::WA_DontShowOnScreen))
  7688             if (!w->isVisible() || w->parentWidget() || !w->testAttribute(Qt::WA_QuitOnClose))
  7635                     && !w->parentWidget() && w->testAttribute(Qt::WA_QuitOnClose)) {
  7689                 continue;
  7636                 lastWindowClosed = false;
  7690             lastWindowClosed = false;
  7637                 break;
  7691             break;
  7638             }
       
  7639         }
  7692         }
  7640         if (lastWindowClosed)
  7693         if (lastWindowClosed)
  7641             QApplicationPrivate::emitLastWindowClosed();
  7694             QApplicationPrivate::emitLastWindowClosed();
  7642     }
  7695     }
  7643 
  7696 
  9796     QWidget *desktopWidget = 0;
  9849     QWidget *desktopWidget = 0;
  9797     if (parent && parent->windowType() == Qt::Desktop)
  9850     if (parent && parent->windowType() == Qt::Desktop)
  9798         desktopWidget = parent;
  9851         desktopWidget = parent;
  9799     bool newParent = (parent != parentWidget()) || !wasCreated || desktopWidget;
  9852     bool newParent = (parent != parentWidget()) || !wasCreated || desktopWidget;
  9800 
  9853 
  9801 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
  9854 #if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_MAC)
  9802     if (newParent && parent && !desktopWidget) {
  9855     if (newParent && parent && !desktopWidget) {
  9803         if (testAttribute(Qt::WA_NativeWindow) && !qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings))
  9856         if (testAttribute(Qt::WA_NativeWindow) && !qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings))
  9804             parent->d_func()->enforceNativeChildren();
  9857             parent->d_func()->enforceNativeChildren();
  9805         else if (parent->d_func()->nativeChildrenForced() || parent->testAttribute(Qt::WA_PaintOnScreen))
  9858         else if (parent->d_func()->nativeChildrenForced() || parent->testAttribute(Qt::WA_PaintOnScreen))
  9806             setAttribute(Qt::WA_NativeWindow);
  9859             setAttribute(Qt::WA_NativeWindow);
 10271     return (d->extra && d->extra->topextra) ? d->extra->topextra->iconPixmap : 0;
 10324     return (d->extra && d->extra->topextra) ? d->extra->topextra->iconPixmap : 0;
 10272 }
 10325 }
 10273 
 10326 
 10274 #endif // QT3_SUPPORT
 10327 #endif // QT3_SUPPORT
 10275 
 10328 
 10276 /*!
 10329  /*!
 10277     Sets the attribute \a attribute on this widget if \a on is true;
 10330   \internal
 10278     otherwise clears the attribute.
 10331 
 10279 
 10332   This just sets the corresponding attribute bit to 1 or 0
 10280     \sa testAttribute()
 10333  */
 10281 */
 10334 static void setAttribute_internal(Qt::WidgetAttribute attribute, bool on, QWidgetData *data,
 10282 void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
 10335                                   QWidgetPrivate *d)
 10283 {
 10336 {
 10284     if (testAttribute(attribute) == on)
       
 10285         return;
       
 10286 
       
 10287     Q_D(QWidget);
       
 10288     Q_ASSERT_X(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8),
       
 10289                "QWidget::setAttribute(WidgetAttribute, bool)",
       
 10290                "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
       
 10291 
       
 10292 #ifdef Q_WS_WIN
       
 10293     // ### Don't use PaintOnScreen+paintEngine() to do native painting in 5.0
       
 10294     if (attribute == Qt::WA_PaintOnScreen && on && !inherits("QGLWidget")) {
       
 10295         // see qwidget_win.cpp, ::paintEngine for details
       
 10296         paintEngine();
       
 10297         if (d->noPaintOnScreen)
       
 10298             return;
       
 10299     }
       
 10300 #endif
       
 10301 
       
 10302     if (attribute < int(8*sizeof(uint))) {
 10337     if (attribute < int(8*sizeof(uint))) {
 10303         if (on)
 10338         if (on)
 10304             data->widget_attributes |= (1<<attribute);
 10339             data->widget_attributes |= (1<<attribute);
 10305         else
 10340         else
 10306             data->widget_attributes &= ~(1<<attribute);
 10341             data->widget_attributes &= ~(1<<attribute);
 10310         if (on)
 10345         if (on)
 10311             d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
 10346             d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
 10312         else
 10347         else
 10313             d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
 10348             d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
 10314     }
 10349     }
       
 10350 }
       
 10351 
       
 10352 /*!
       
 10353     Sets the attribute \a attribute on this widget if \a on is true;
       
 10354     otherwise clears the attribute.
       
 10355 
       
 10356     \sa testAttribute()
       
 10357 */
       
 10358 void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
       
 10359 {
       
 10360     if (testAttribute(attribute) == on)
       
 10361         return;
       
 10362 
       
 10363     Q_D(QWidget);
       
 10364     Q_ASSERT_X(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8),
       
 10365                "QWidget::setAttribute(WidgetAttribute, bool)",
       
 10366                "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
       
 10367 
       
 10368 #ifdef Q_WS_WIN
       
 10369     // ### Don't use PaintOnScreen+paintEngine() to do native painting in 5.0
       
 10370     if (attribute == Qt::WA_PaintOnScreen && on && !inherits("QGLWidget")) {
       
 10371         // see qwidget_win.cpp, ::paintEngine for details
       
 10372         paintEngine();
       
 10373         if (d->noPaintOnScreen)
       
 10374             return;
       
 10375     }
       
 10376 #endif
       
 10377 
       
 10378     setAttribute_internal(attribute, on, data, d);
 10315 
 10379 
 10316     switch (attribute) {
 10380     switch (attribute) {
 10317 
 10381 
 10318 #ifndef QT_NO_DRAGANDDROP
 10382 #ifndef QT_NO_DRAGANDDROP
 10319     case Qt::WA_AcceptDrops:  {
 10383     case Qt::WA_AcceptDrops:  {
 10368     case Qt::WA_MacSmallSize:
 10432     case Qt::WA_MacSmallSize:
 10369     case Qt::WA_MacMiniSize:
 10433     case Qt::WA_MacMiniSize:
 10370 #ifdef Q_WS_MAC
 10434 #ifdef Q_WS_MAC
 10371         {
 10435         {
 10372             // We can only have one of these set at a time
 10436             // We can only have one of these set at a time
 10373             static const int MacSizes[] = { Qt::WA_MacNormalSize, Qt::WA_MacSmallSize,
 10437             const Qt::WidgetAttribute MacSizes[] = { Qt::WA_MacNormalSize, Qt::WA_MacSmallSize,
 10374                                             Qt::WA_MacMiniSize, 0 };
 10438                                                      Qt::WA_MacMiniSize };
 10375             for (int i = 0; MacSizes[i] != 0; ++i) {
 10439             for (int i = 0; i < 3; ++i) {
 10376                 if (MacSizes[i] == attribute)
 10440                 if (MacSizes[i] != attribute)
 10377                     continue;
 10441                     setAttribute_internal(MacSizes[i], false, data, d);
 10378                 int macsize_x = MacSizes[i] - 8*sizeof(uint);
       
 10379                 int macsize_int_off = macsize_x / (8*sizeof(uint));
       
 10380                 d->high_attributes[macsize_int_off] &= ~(1<<(macsize_x-(macsize_int_off*8*sizeof(uint))));
       
 10381             }
 10442             }
 10382             d->macUpdateSizeAttribute();
 10443             d->macUpdateSizeAttribute();
 10383         }
 10444         }
 10384 #endif
 10445 #endif
 10385         break;
 10446         break;
 10442 #endif //QT_NO_IM
 10503 #endif //QT_NO_IM
 10443         break;
 10504         break;
 10444     }
 10505     }
 10445     case Qt::WA_PaintOnScreen:
 10506     case Qt::WA_PaintOnScreen:
 10446         d->updateIsOpaque();
 10507         d->updateIsOpaque();
 10447 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
 10508 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_MAC)
 10448         // Recreate the widget if it's already created as an alien widget and
 10509         // Recreate the widget if it's already created as an alien widget and
 10449         // WA_PaintOnScreen is enabled. Paint on screen widgets must have win id.
 10510         // WA_PaintOnScreen is enabled. Paint on screen widgets must have win id.
 10450         // So must their children.
 10511         // So must their children.
 10451         if (on) {
 10512         if (on) {
 10452             setAttribute(Qt::WA_NativeWindow);
 10513             setAttribute(Qt::WA_NativeWindow);
 10497             d->createExtra();
 10558             d->createExtra();
 10498         d->extra->compress_events = on;
 10559         d->extra->compress_events = on;
 10499         break;
 10560         break;
 10500     case Qt::WA_X11OpenGLOverlay:
 10561     case Qt::WA_X11OpenGLOverlay:
 10501         d->updateIsOpaque();
 10562         d->updateIsOpaque();
       
 10563         break;
       
 10564     case Qt::WA_X11DoNotAcceptFocus:
       
 10565         if (testAttribute(Qt::WA_WState_Created))
       
 10566             d->updateX11AcceptFocus();
 10502         break;
 10567         break;
 10503 #endif
 10568 #endif
 10504     case Qt::WA_DontShowOnScreen: {
 10569     case Qt::WA_DontShowOnScreen: {
 10505         if (on && isVisible()) {
 10570         if (on && isVisible()) {
 10506             // Make sure we keep the current state and only hide the widget
 10571             // Make sure we keep the current state and only hide the widget
 12232 {
 12297 {
 12233     delete winId;
 12298     delete winId;
 12234 }
 12299 }
 12235 #endif
 12300 #endif
 12236 
 12301 
       
 12302 #if QT_MAC_USE_COCOA
       
 12303 void QWidgetPrivate::syncUnifiedMode() {
       
 12304     // The whole purpose of this method is to keep the unifiedToolbar in sync.
       
 12305     // That means making sure we either exchange the drawing methods or we let
       
 12306     // the toolbar know that it does not require to draw the baseline.
       
 12307     Q_Q(QWidget);
       
 12308     // This function makes sense only if this is a top level
       
 12309     if(!q->isWindow())
       
 12310         return;
       
 12311     OSWindowRef window = qt_mac_window_for(q);
       
 12312     if(changeMethods) {
       
 12313         // Ok, we are in documentMode.
       
 12314         if(originalDrawMethod)
       
 12315             qt_mac_replaceDrawRect(window, this);
       
 12316     } else {
       
 12317         if(!originalDrawMethod)
       
 12318             qt_mac_replaceDrawRectOriginal(window, this);
       
 12319     }
       
 12320 }
       
 12321 
       
 12322 #endif // QT_MAC_USE_COCOA
       
 12323 
 12237 QT_END_NAMESPACE
 12324 QT_END_NAMESPACE
 12238 
 12325 
 12239 #include "moc_qwidget.cpp"
 12326 #include "moc_qwidget.cpp"
 12240 
 12327