2017-10-04 12:39:59 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-10-04 12:39:59 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-10-04 12:39:59 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/rp_widget.h"
|
|
|
|
#include "info/media/info_media_widget.h"
|
2017-11-06 07:31:18 +00:00
|
|
|
#include "data/data_shared_media.h"
|
2020-05-21 12:27:04 +00:00
|
|
|
#include "overview/overview_layout_delegate.h"
|
2017-10-04 17:15:08 +00:00
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
class DeleteMessagesBox;
|
2019-07-24 11:45:24 +00:00
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
2018-01-26 15:40:11 +00:00
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
namespace HistoryView {
|
|
|
|
struct TextState;
|
|
|
|
struct StateRequest;
|
|
|
|
enum class CursorState : char;
|
|
|
|
enum class PointState : char;
|
|
|
|
} // namespace HistoryView
|
|
|
|
|
2017-10-09 21:55:30 +00:00
|
|
|
namespace Ui {
|
|
|
|
class PopupMenu;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2017-10-04 17:15:08 +00:00
|
|
|
namespace Overview {
|
|
|
|
namespace Layout {
|
|
|
|
class ItemBase;
|
|
|
|
} // namespace Layout
|
|
|
|
} // namespace Overview
|
2017-10-04 12:39:59 +00:00
|
|
|
|
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2017-10-04 12:39:59 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
|
|
|
namespace Info {
|
2017-10-31 18:25:22 +00:00
|
|
|
|
2017-12-09 15:13:06 +00:00
|
|
|
class AbstractController;
|
2017-10-31 18:25:22 +00:00
|
|
|
|
2017-10-04 12:39:59 +00:00
|
|
|
namespace Media {
|
|
|
|
|
2017-10-09 21:55:30 +00:00
|
|
|
using BaseLayout = Overview::Layout::ItemBase;
|
|
|
|
using UniversalMsgId = int32;
|
|
|
|
|
2020-05-21 12:27:04 +00:00
|
|
|
class ListWidget final
|
|
|
|
: public Ui::RpWidget
|
|
|
|
, public Overview::Layout::Delegate {
|
2017-10-04 12:39:59 +00:00
|
|
|
public:
|
|
|
|
ListWidget(
|
|
|
|
QWidget *parent,
|
2017-12-09 15:13:06 +00:00
|
|
|
not_null<AbstractController*> controller);
|
2020-05-21 12:27:04 +00:00
|
|
|
~ListWidget();
|
2017-10-04 12:39:59 +00:00
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Main::Session &session() const;
|
2019-07-24 11:13:51 +00:00
|
|
|
|
2017-10-30 19:24:20 +00:00
|
|
|
void restart();
|
|
|
|
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<int> scrollToRequests() const;
|
|
|
|
rpl::producer<SelectedItems> selectedListValue() const;
|
2017-10-20 16:19:42 +00:00
|
|
|
void cancelSelection() {
|
|
|
|
clearSelected();
|
2017-10-13 19:07:04 +00:00
|
|
|
}
|
2017-10-05 17:32:34 +00:00
|
|
|
|
2017-12-09 15:13:06 +00:00
|
|
|
QRect getCurrentSongGeometry();
|
|
|
|
rpl::producer<> checkForHide() const {
|
|
|
|
return _checkForHide.events();
|
|
|
|
}
|
2018-07-19 14:27:09 +00:00
|
|
|
bool preventAutoHide() const;
|
2017-12-09 15:13:06 +00:00
|
|
|
|
2017-10-27 17:41:38 +00:00
|
|
|
void saveState(not_null<Memento*> memento);
|
|
|
|
void restoreState(not_null<Memento*> memento);
|
|
|
|
|
2020-05-21 13:13:29 +00:00
|
|
|
void registerHeavyItem(not_null<const BaseLayout*> item) override;
|
|
|
|
void unregisterHeavyItem(not_null<const BaseLayout*> item) override;
|
2017-10-04 17:15:08 +00:00
|
|
|
|
2017-10-04 12:39:59 +00:00
|
|
|
private:
|
2018-01-27 13:59:24 +00:00
|
|
|
struct Context;
|
|
|
|
class Section;
|
|
|
|
using CursorState = HistoryView::CursorState;
|
|
|
|
using TextState = HistoryView::TextState;
|
|
|
|
using StateRequest = HistoryView::StateRequest;
|
2017-10-09 21:55:30 +00:00
|
|
|
enum class MouseAction {
|
|
|
|
None,
|
|
|
|
PrepareDrag,
|
|
|
|
Dragging,
|
|
|
|
PrepareSelect,
|
|
|
|
Selecting,
|
|
|
|
};
|
2017-10-05 15:35:52 +00:00
|
|
|
struct CachedItem {
|
2017-10-09 21:55:30 +00:00
|
|
|
CachedItem(std::unique_ptr<BaseLayout> item);
|
2020-05-21 12:27:04 +00:00
|
|
|
CachedItem(CachedItem &&other);
|
|
|
|
CachedItem &operator=(CachedItem &&other);
|
2017-10-05 15:35:52 +00:00
|
|
|
~CachedItem();
|
|
|
|
|
2017-10-09 21:55:30 +00:00
|
|
|
std::unique_ptr<BaseLayout> item;
|
2017-10-05 15:35:52 +00:00
|
|
|
bool stale = false;
|
|
|
|
};
|
2017-10-05 17:32:34 +00:00
|
|
|
struct FoundItem {
|
2017-10-09 21:55:30 +00:00
|
|
|
not_null<BaseLayout*> layout;
|
2017-10-05 17:32:34 +00:00
|
|
|
QRect geometry;
|
|
|
|
bool exact = false;
|
|
|
|
};
|
2017-10-13 19:07:04 +00:00
|
|
|
struct SelectionData {
|
|
|
|
explicit SelectionData(TextSelection text) : text(text) {
|
|
|
|
}
|
|
|
|
|
|
|
|
TextSelection text;
|
|
|
|
bool canDelete = false;
|
|
|
|
bool canForward = false;
|
|
|
|
};
|
|
|
|
using SelectedMap = base::flat_map<
|
|
|
|
UniversalMsgId,
|
|
|
|
SelectionData,
|
|
|
|
std::less<>>;
|
|
|
|
enum class DragSelectAction {
|
|
|
|
None,
|
|
|
|
Selecting,
|
|
|
|
Deselecting,
|
|
|
|
};
|
2018-01-27 13:59:24 +00:00
|
|
|
struct MouseState {
|
2017-10-13 19:07:04 +00:00
|
|
|
UniversalMsgId itemId = 0;
|
|
|
|
QSize size;
|
|
|
|
QPoint cursor;
|
|
|
|
bool inside = false;
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
inline bool operator==(const MouseState &other) const {
|
2017-10-13 19:07:04 +00:00
|
|
|
return (itemId == other.itemId)
|
|
|
|
&& (cursor == other.cursor);
|
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
inline bool operator!=(const MouseState &other) const {
|
2017-10-13 19:07:04 +00:00
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2017-10-25 16:32:22 +00:00
|
|
|
enum class ContextMenuSource {
|
|
|
|
Mouse,
|
|
|
|
Touch,
|
|
|
|
Other,
|
|
|
|
};
|
2017-10-27 17:41:38 +00:00
|
|
|
struct ScrollTopState {
|
|
|
|
UniversalMsgId item = 0;
|
|
|
|
int shift = 0;
|
|
|
|
};
|
2017-10-04 17:15:08 +00:00
|
|
|
|
2020-05-21 12:27:04 +00:00
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
|
|
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
void start();
|
2017-10-04 17:15:08 +00:00
|
|
|
int recountHeight();
|
2017-10-05 15:35:52 +00:00
|
|
|
void refreshHeight();
|
|
|
|
|
|
|
|
QMargins padding() const;
|
2017-10-09 21:55:30 +00:00
|
|
|
bool isMyItem(not_null<const HistoryItem*> item) const;
|
|
|
|
bool isItemLayout(
|
|
|
|
not_null<const HistoryItem*> item,
|
|
|
|
BaseLayout *layout) const;
|
2017-10-27 17:41:38 +00:00
|
|
|
bool isPossiblyMyId(FullMsgId fullId) const;
|
2017-10-09 21:55:30 +00:00
|
|
|
void repaintItem(const HistoryItem *item);
|
2017-10-05 15:35:52 +00:00
|
|
|
void repaintItem(UniversalMsgId msgId);
|
2017-10-09 21:55:30 +00:00
|
|
|
void repaintItem(const BaseLayout *item);
|
2017-10-13 19:07:04 +00:00
|
|
|
void repaintItem(QRect itemGeometry);
|
2017-10-05 15:35:52 +00:00
|
|
|
void itemRemoved(not_null<const HistoryItem*> item);
|
2017-10-09 21:55:30 +00:00
|
|
|
void itemLayoutChanged(not_null<const HistoryItem*> item);
|
2017-10-04 17:15:08 +00:00
|
|
|
|
|
|
|
void refreshViewer();
|
|
|
|
void invalidatePaletteCache();
|
|
|
|
void refreshRows();
|
2017-10-29 15:32:01 +00:00
|
|
|
SparseIdsMergedSlice::Key sliceKey(
|
2017-10-05 17:32:34 +00:00
|
|
|
UniversalMsgId universalId) const;
|
2017-10-13 19:07:04 +00:00
|
|
|
BaseLayout *getLayout(UniversalMsgId universalId);
|
|
|
|
BaseLayout *getExistingLayout(UniversalMsgId universalId) const;
|
2017-10-09 21:55:30 +00:00
|
|
|
std::unique_ptr<BaseLayout> createLayout(
|
2017-10-13 19:07:04 +00:00
|
|
|
UniversalMsgId universalId,
|
2017-10-04 17:15:08 +00:00
|
|
|
Type type);
|
|
|
|
|
2017-10-13 19:07:04 +00:00
|
|
|
SelectedItems collectSelectedItems() const;
|
2017-12-06 10:13:38 +00:00
|
|
|
MessageIdsList collectSelectedIds() const;
|
2017-10-13 19:07:04 +00:00
|
|
|
void pushSelectedItems();
|
|
|
|
FullMsgId computeFullId(UniversalMsgId universalId) const;
|
|
|
|
bool hasSelected() const;
|
|
|
|
bool isSelectedItem(
|
|
|
|
const SelectedMap::const_iterator &i) const;
|
|
|
|
void removeItemSelection(
|
|
|
|
const SelectedMap::const_iterator &i);
|
|
|
|
bool hasSelectedText() const;
|
|
|
|
bool hasSelectedItems() const;
|
|
|
|
void clearSelected();
|
2017-10-25 16:32:22 +00:00
|
|
|
void forwardSelected();
|
|
|
|
void forwardItem(UniversalMsgId universalId);
|
2017-12-06 10:13:38 +00:00
|
|
|
void forwardItems(MessageIdsList &&items);
|
2017-10-25 16:32:22 +00:00
|
|
|
void deleteSelected();
|
|
|
|
void deleteItem(UniversalMsgId universalId);
|
2018-01-26 15:40:11 +00:00
|
|
|
DeleteMessagesBox *deleteItems(MessageIdsList &&items);
|
2017-10-13 19:07:04 +00:00
|
|
|
void applyItemSelection(
|
|
|
|
UniversalMsgId universalId,
|
|
|
|
TextSelection selection);
|
|
|
|
void toggleItemSelection(
|
|
|
|
UniversalMsgId universalId);
|
|
|
|
SelectedMap::iterator itemUnderPressSelection();
|
|
|
|
SelectedMap::const_iterator itemUnderPressSelection() const;
|
|
|
|
bool isItemUnderPressSelected() const;
|
|
|
|
bool requiredToStartDragging(not_null<BaseLayout*> layout) const;
|
2018-01-27 13:59:24 +00:00
|
|
|
bool isPressInSelectedText(TextState state) const;
|
2017-10-13 19:07:04 +00:00
|
|
|
void applyDragSelection();
|
|
|
|
void applyDragSelection(SelectedMap &applyTo) const;
|
|
|
|
bool changeItemSelection(
|
|
|
|
SelectedMap &selected,
|
|
|
|
UniversalMsgId universalId,
|
|
|
|
TextSelection selection) const;
|
|
|
|
|
|
|
|
static bool IsAfter(
|
2018-01-27 13:59:24 +00:00
|
|
|
const MouseState &a,
|
|
|
|
const MouseState &b);
|
|
|
|
static bool SkipSelectFromItem(const MouseState &state);
|
|
|
|
static bool SkipSelectTillItem(const MouseState &state);
|
2017-10-13 19:07:04 +00:00
|
|
|
|
2017-10-04 17:15:08 +00:00
|
|
|
void markLayoutsStale();
|
|
|
|
void clearStaleLayouts();
|
2017-10-05 15:35:52 +00:00
|
|
|
std::vector<Section>::iterator findSectionByItem(
|
|
|
|
UniversalMsgId universalId);
|
|
|
|
std::vector<Section>::iterator findSectionAfterTop(int top);
|
|
|
|
std::vector<Section>::const_iterator findSectionAfterTop(
|
|
|
|
int top) const;
|
|
|
|
std::vector<Section>::const_iterator findSectionAfterBottom(
|
|
|
|
std::vector<Section>::const_iterator from,
|
|
|
|
int bottom) const;
|
2017-10-27 17:41:38 +00:00
|
|
|
FoundItem findItemByPoint(QPoint point) const;
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<FoundItem> findItemById(UniversalMsgId universalId);
|
2020-05-21 12:27:04 +00:00
|
|
|
FoundItem findItemDetails(not_null<BaseLayout*> item);
|
2017-10-05 17:32:34 +00:00
|
|
|
FoundItem foundItemInSection(
|
|
|
|
const FoundItem &item,
|
2017-10-27 17:41:38 +00:00
|
|
|
const Section §ion) const;
|
2017-10-05 17:32:34 +00:00
|
|
|
|
2017-10-27 17:41:38 +00:00
|
|
|
ScrollTopState countScrollState() const;
|
2017-10-05 17:32:34 +00:00
|
|
|
void saveScrollState();
|
|
|
|
void restoreScrollState();
|
2017-10-04 17:15:08 +00:00
|
|
|
|
2017-10-09 21:55:30 +00:00
|
|
|
QPoint clampMousePosition(QPoint position) const;
|
|
|
|
void mouseActionStart(
|
2018-01-26 15:40:11 +00:00
|
|
|
const QPoint &globalPosition,
|
2017-10-09 21:55:30 +00:00
|
|
|
Qt::MouseButton button);
|
2018-01-26 15:40:11 +00:00
|
|
|
void mouseActionUpdate(const QPoint &globalPosition);
|
2017-10-13 19:07:04 +00:00
|
|
|
void mouseActionUpdate();
|
2017-10-09 21:55:30 +00:00
|
|
|
void mouseActionFinish(
|
2018-01-26 15:40:11 +00:00
|
|
|
const QPoint &globalPosition,
|
2017-10-09 21:55:30 +00:00
|
|
|
Qt::MouseButton button);
|
|
|
|
void mouseActionCancel();
|
|
|
|
void performDrag();
|
2017-10-13 19:07:04 +00:00
|
|
|
style::cursor computeMouseCursor() const;
|
2017-10-25 16:32:22 +00:00
|
|
|
void showContextMenu(
|
|
|
|
QContextMenuEvent *e,
|
|
|
|
ContextMenuSource source);
|
2017-10-13 19:07:04 +00:00
|
|
|
|
|
|
|
void updateDragSelection();
|
|
|
|
void clearDragSelection();
|
|
|
|
|
|
|
|
void trySwitchToWordSelection();
|
|
|
|
void switchToWordSelection();
|
|
|
|
void validateTrippleClickStartTime();
|
|
|
|
void checkMoveToOtherViewer();
|
2020-05-21 12:27:04 +00:00
|
|
|
void clearHeavyItems();
|
2017-10-09 21:55:30 +00:00
|
|
|
|
2017-12-09 15:13:06 +00:00
|
|
|
void setActionBoxWeak(QPointer<Ui::RpWidget> box);
|
|
|
|
|
|
|
|
const not_null<AbstractController*> _controller;
|
2017-10-31 18:25:22 +00:00
|
|
|
const not_null<PeerData*> _peer;
|
|
|
|
PeerData * const _migrated = nullptr;
|
2017-10-04 12:39:59 +00:00
|
|
|
Type _type = Type::Photo;
|
|
|
|
|
2017-10-05 17:32:34 +00:00
|
|
|
static constexpr auto kMinimalIdsLimit = 16;
|
2017-10-27 17:41:38 +00:00
|
|
|
static constexpr auto kDefaultAroundId = (ServerMaxMsgId - 1);
|
|
|
|
UniversalMsgId _universalAroundId = kDefaultAroundId;
|
2017-10-05 17:32:34 +00:00
|
|
|
int _idsLimit = kMinimalIdsLimit;
|
2017-10-29 15:32:01 +00:00
|
|
|
SparseIdsMergedSlice _slice;
|
2017-10-04 17:15:08 +00:00
|
|
|
|
2020-05-21 13:13:29 +00:00
|
|
|
std::unordered_map<UniversalMsgId, CachedItem> _layouts;
|
|
|
|
base::flat_set<not_null<const BaseLayout*>> _heavyLayouts;
|
|
|
|
bool _heavyLayoutsInvalidated = false;
|
2017-10-04 17:15:08 +00:00
|
|
|
std::vector<Section> _sections;
|
|
|
|
|
2017-10-05 17:32:34 +00:00
|
|
|
int _visibleTop = 0;
|
2017-10-09 21:55:30 +00:00
|
|
|
int _visibleBottom = 0;
|
2017-10-27 17:41:38 +00:00
|
|
|
ScrollTopState _scrollTopState;
|
2017-10-05 17:32:34 +00:00
|
|
|
rpl::event_stream<int> _scrollToRequests;
|
|
|
|
|
2017-10-09 21:55:30 +00:00
|
|
|
MouseAction _mouseAction = MouseAction::None;
|
|
|
|
TextSelectType _mouseSelectType = TextSelectType::Letters;
|
|
|
|
QPoint _mousePosition;
|
2018-01-27 13:59:24 +00:00
|
|
|
MouseState _overState;
|
|
|
|
MouseState _pressState;
|
2017-10-13 19:07:04 +00:00
|
|
|
BaseLayout *_overLayout = nullptr;
|
2017-10-25 16:32:22 +00:00
|
|
|
UniversalMsgId _contextUniversalId = 0;
|
2018-01-27 13:59:24 +00:00
|
|
|
CursorState _mouseCursorState = CursorState();
|
2017-10-13 19:07:04 +00:00
|
|
|
uint16 _mouseTextSymbol = 0;
|
2017-10-09 21:55:30 +00:00
|
|
|
bool _pressWasInactive = false;
|
2017-10-13 19:07:04 +00:00
|
|
|
SelectedMap _selected;
|
|
|
|
SelectedMap _dragSelected;
|
2017-10-20 16:19:42 +00:00
|
|
|
rpl::event_stream<SelectedItems> _selectedListStream;
|
2017-10-09 21:55:30 +00:00
|
|
|
style::cursor _cursor = style::cur_default;
|
2017-10-13 19:07:04 +00:00
|
|
|
DragSelectAction _dragSelectAction = DragSelectAction::None;
|
2017-10-09 21:55:30 +00:00
|
|
|
bool _wasSelectedText = false; // was some text selected in current drag action
|
2017-12-09 15:13:06 +00:00
|
|
|
|
2018-07-19 14:27:09 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> _contextMenu;
|
2017-12-09 15:13:06 +00:00
|
|
|
rpl::event_stream<> _checkForHide;
|
|
|
|
QPointer<Ui::RpWidget> _actionBoxWeak;
|
|
|
|
rpl::lifetime _actionBoxWeakLifetime;
|
2017-10-09 21:55:30 +00:00
|
|
|
|
|
|
|
QPoint _trippleClickPoint;
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time _trippleClickStartTime = 0;
|
2017-10-09 21:55:30 +00:00
|
|
|
|
2017-10-04 17:15:08 +00:00
|
|
|
rpl::lifetime _viewerLifetime;
|
|
|
|
|
2017-10-04 12:39:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Media
|
|
|
|
} // namespace Info
|