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 } |
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 |
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); |
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 |
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) |
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 } |
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; |
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 |