diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 1696225f43..d6c64d7927 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -370,10 +370,7 @@ HistoryInner::HistoryInner( [=] { mouseActionUpdate(QCursor::pos()); setCursor(_cursor); }, [=] { return window()->isActiveWindow(); }) , _scrollDateCheck([this] { scrollDateCheck(); }) -, _scrollDateHideTimer([this] { scrollDateHideByTimer(); }) -, _overlayHost(std::make_unique( - this, - [=](not_null view) { return itemTop(view); })) { +, _scrollDateHideTimer([this] { scrollDateHideByTimer(); }) { _history->delegateMixin()->setCurrent(this); if (_migrated) { _migrated->delegateMixin()->setCurrent(this); @@ -498,7 +495,9 @@ HistoryInner::HistoryInner( controller->adaptive().chatWideValue( ) | rpl::on_next([=](bool wide) { _isChatWide = wide; - _overlayHost->hide(); + if (_overlayHost) { + _overlayHost->hide(); + } }, lifetime()); _selectScroll.scrolls( @@ -699,7 +698,9 @@ void HistoryInner::setupSwipeReplyAndBack() { if (!canReply) { return true; } - _overlayHost->hide(); + if (_overlayHost) { + _overlayHost->hide(); + } result.msgBareId = item->fullId().msg.bare; result.callback = [=, itemId = item->fullId()] { const auto still = show->session().data().message(itemId); @@ -1892,7 +1893,9 @@ void HistoryInner::mousePressEvent(QMouseEvent *e) { e->accept(); return; // ignore mouse press, that was hiding context menu } - _overlayHost->handleClickOutside(e->pos()); + if (_overlayHost) { + _overlayHost->handleClickOutside(e->pos()); + } if (_middleClickAutoscroll.active()) { _middleClickAutoscroll.stop(); e->accept(); @@ -2203,7 +2206,9 @@ void HistoryInner::itemRemoved(not_null item) { } void HistoryInner::viewRemoved(not_null view) { - _overlayHost->viewGone(view); + if (_overlayHost) { + _overlayHost->viewGone(view); + } const auto refresh = [&](auto &saved) { if (saved == view) { const auto now = viewByItem(view->data()); @@ -3667,7 +3672,7 @@ void HistoryInner::copyContextText(FullMsgId itemId) { } void HistoryInner::resizeEvent(QResizeEvent *e) { - if (e->oldSize().width() != e->size().width()) { + if (e->oldSize().width() != e->size().width() && _overlayHost) { _overlayHost->hide(); } mouseActionUpdate(); @@ -3984,7 +3989,9 @@ void HistoryInner::visibleAreaUpdated(int top, int bottom) { _visibleAreaTop, _visibleAreaBottom); - _overlayHost->updatePosition(); + if (_overlayHost) { + _overlayHost->updatePosition(); + } } bool HistoryInner::displayScrollDate() const { @@ -4142,7 +4149,9 @@ void HistoryInner::leaveEventHook(QEvent *e) { } HistoryInner::~HistoryInner() { - _overlayHost->hide(); + if (_overlayHost) { + _overlayHost->hide(); + } _aboutView = nullptr; for (const auto &item : _animatedStickersPlayed) { if (const auto view = item->mainView()) { @@ -4265,7 +4274,7 @@ HistoryView::SelectionModeResult HistoryInner::inSelectionMode() const { const auto now = inSelectionMode; if (_lastInSelectionMode != now) { _lastInSelectionMode = now; - if (now) { + if (now && _overlayHost) { _overlayHost->hide(); } if (_inSelectionModeAnimation.animating()) { @@ -4317,13 +4326,24 @@ void HistoryInner::elementShowPollResults( _controller->showPollResults(poll, context); } +HistoryView::ElementOverlayHost &HistoryInner::ensureOverlayHost() { + if (!_overlayHost) { + _overlayHost = std::make_unique( + this, + [=](not_null view) { + return itemTop(view); + }); + } + return *_overlayHost; +} + void HistoryInner::elementShowAddPollOption( not_null view, not_null poll, FullMsgId context, QRect optionRect) { HistoryView::ShowAddPollOptionOverlay( - *_overlayHost, + ensureOverlayHost(), this, view, poll, @@ -4333,7 +4353,9 @@ void HistoryInner::elementShowAddPollOption( } void HistoryInner::elementSubmitAddPollOption(FullMsgId context) { - _overlayHost->triggerSubmit(context); + if (_overlayHost) { + _overlayHost->triggerSubmit(context); + } } void HistoryInner::elementOpenPhoto( diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 7254dc6345..0ae55744af 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -603,6 +603,7 @@ private: ClickHandlerPtr _scrollDateLink; ClickHandlerPtr _forumThreadBarLink; + [[nodiscard]] HistoryView::ElementOverlayHost &ensureOverlayHost(); std::unique_ptr _overlayHost; }; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index f4de077de1..cadee423b3 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -440,15 +440,9 @@ ListWidget::ListWidget( [=](int d) { _delegate->listScrollTo(_visibleTop + d, false); }, [=](const QCursor &cursor) { setCursor(cursor); }, [=] { mouseActionUpdate(QCursor::pos()); setCursor(_cursor); }, - [=] { return window()->isActiveWindow(); }) -, _overlayHost(std::make_unique( - this, - [=](not_null view) { return itemTop(view); })) { + [=] { return window()->isActiveWindow(); }) { setAttribute(Qt::WA_AcceptTouchEvents); setMouseTracking(true); - _overlayHost->setHiddenCallback([=] { - _delegate->listWindowSetInnerFocus(); - }); if (_readMetricsTracker) { Core::App().inAppKeyPressed( ) | rpl::on_next([=] { @@ -572,7 +566,9 @@ ListWidget::ListWidget( _delegate->listChatWideValue( ) | rpl::on_next([=](bool wide) { _isChatWide = wide; - _overlayHost->hide(); + if (_overlayHost) { + _overlayHost->hide(); + } }, lifetime()); _selectScroll.scrolls( @@ -1184,7 +1180,9 @@ void ListWidget::visibleTopBottomUpdated( _applyUpdatedScrollState.call(); _emojiInteractions->visibleAreaUpdated(_visibleTop, _visibleBottom); - _overlayHost->updatePosition(); + if (_overlayHost) { + _overlayHost->updatePosition(); + } } void ListWidget::applyUpdatedScrollState() { @@ -1318,7 +1316,7 @@ SelectionModeResult ListWidget::inSelectionMode() const { || (_mouseAction == MouseAction::Selecting && _lastInSelectionMode); if (_lastInSelectionMode != now) { _lastInSelectionMode = now; - if (now) { + if (now && _overlayHost) { _overlayHost->hide(); } if (_inSelectionModeAnimation.animating()) { @@ -1903,13 +1901,27 @@ void ListWidget::elementShowPollResults( _delegate->listShowPollResults(poll, context); } +ElementOverlayHost &ListWidget::ensureOverlayHost() { + if (!_overlayHost) { + _overlayHost = std::make_unique( + this, + [=](not_null view) { + return itemTop(view); + }); + _overlayHost->setHiddenCallback([=] { + _delegate->listWindowSetInnerFocus(); + }); + } + return *_overlayHost; +} + void ListWidget::elementShowAddPollOption( not_null view, not_null poll, FullMsgId context, QRect optionRect) { ShowAddPollOptionOverlay( - *_overlayHost, + ensureOverlayHost(), this, view, poll, @@ -1919,11 +1931,15 @@ void ListWidget::elementShowAddPollOption( } void ListWidget::elementSubmitAddPollOption(FullMsgId context) { - _overlayHost->triggerSubmit(context); + if (_overlayHost) { + _overlayHost->triggerSubmit(context); + } } void ListWidget::hideElementOverlay() { - _overlayHost->hide(); + if (_overlayHost) { + _overlayHost->hide(); + } } void ListWidget::elementOpenPhoto( @@ -2069,7 +2085,7 @@ void ListWidget::updateSize() { } void ListWidget::resizeToWidth(int newWidth, int minHeight) { - if (width() != newWidth) { + if (width() != newWidth && _overlayHost) { _overlayHost->hide(); } _minHeight = minHeight; @@ -3109,7 +3125,9 @@ void ListWidget::mousePressEvent(QMouseEvent *e) { e->accept(); return; // ignore mouse press, that was hiding context menu } - _overlayHost->handleClickOutside(e->pos()); + if (_overlayHost) { + _overlayHost->handleClickOutside(e->pos()); + } if (_middleClickAutoscroll.active()) { _middleClickAutoscroll.stop(); e->accept(); @@ -4398,7 +4416,9 @@ void ListWidget::showItemHighlight(not_null item) { } void ListWidget::viewReplaced(not_null was, Element *now) { - _overlayHost->viewGone(was); + if (_overlayHost) { + _overlayHost->viewGone(was); + } if (_visibleTopItem == was) _visibleTopItem = now; if (_scrollDateLastItem == was) _scrollDateLastItem = now; if (_overElement == was) _overElement = now; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 69d9a9da2e..e577b46630 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -901,6 +901,7 @@ private: rpl::event_stream _requestedToShowMessage; rpl::event_stream> _scrollKeyEvents; + [[nodiscard]] ElementOverlayHost &ensureOverlayHost(); std::unique_ptr _overlayHost; rpl::lifetime _viewerLifetime;