/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "overview/overview_layout.h" namespace Storage { enum class SharedMediaType : signed char; } // namespace Storage namespace Info::Media { using Type = Storage::SharedMediaType; using BaseLayout = Overview::Layout::ItemBase; class Memento; class ListSection; inline constexpr auto kPreloadIfLessThanScreens = 2; struct ListItemSelectionData { explicit ListItemSelectionData(TextSelection text) : text(text) { } TextSelection text; bool canDelete = false; bool canForward = false; }; inline bool operator==( ListItemSelectionData a, ListItemSelectionData b) { return (a.text == b.text) && (a.canDelete == b.canDelete) && (a.canForward == b.canForward); } using ListSelectedMap = base::flat_map< not_null, ListItemSelectionData, std::less<>>; enum class ListDragSelectAction { None, Selecting, Deselecting, }; struct ListContext { Overview::Layout::PaintContext layoutContext; not_null selected; not_null dragSelected; ListDragSelectAction dragSelectAction = ListDragSelectAction::None; }; struct ListScrollTopState { int64 position = 0; // ListProvider-specific. HistoryItem *item = nullptr; int shift = 0; }; struct ListFoundItem { not_null layout; QRect geometry; bool exact = false; }; struct CachedItem { CachedItem(std::unique_ptr item) : item(std::move(item)) { }; CachedItem(CachedItem &&other) = default; CachedItem &operator=(CachedItem &&other) = default; ~CachedItem() = default; std::unique_ptr item; bool stale = false; }; using UniversalMsgId = MsgId; [[nodiscard]] UniversalMsgId GetUniversalId(FullMsgId itemId); [[nodiscard]] UniversalMsgId GetUniversalId( not_null item); [[nodiscard]] UniversalMsgId GetUniversalId( not_null layout); bool ChangeItemSelection( ListSelectedMap &selected, not_null item, ListItemSelectionData selectionData); class ListSectionDelegate { public: [[nodiscard]] virtual bool sectionHasFloatingHeader() = 0; [[nodiscard]] virtual QString sectionTitle( not_null item) = 0; [[nodiscard]] virtual bool sectionItemBelongsHere( not_null item, not_null previous) = 0; [[nodiscard]] not_null sectionDelegate() { return this; } }; class ListProvider { public: [[nodiscard]] virtual Type type() = 0; [[nodiscard]] virtual bool hasSelectRestriction() = 0; [[nodiscard]] virtual auto hasSelectRestrictionChanges() ->rpl::producer = 0; [[nodiscard]] virtual bool isPossiblyMyItem( not_null item) = 0; [[nodiscard]] virtual std::optional fullCount() = 0; virtual void restart() = 0; virtual void checkPreload( QSize viewport, not_null topLayout, not_null bottomLayout, bool preloadTop, bool preloadBottom) = 0; virtual void refreshViewer() = 0; [[nodiscard]] virtual rpl::producer<> refreshed() = 0; [[nodiscard]] virtual std::vector fillSections( not_null delegate) = 0; [[nodiscard]] virtual auto layoutRemoved() -> rpl::producer> = 0; [[nodiscard]] virtual BaseLayout *lookupLayout( const HistoryItem *item) = 0; [[nodiscard]] virtual bool isMyItem( not_null item) = 0; [[nodiscard]] virtual bool isAfter( not_null a, not_null b) = 0; [[nodiscard]] virtual ListItemSelectionData computeSelectionData( not_null item, TextSelection selection) = 0; virtual void applyDragSelection( ListSelectedMap &selected, not_null fromItem, bool skipFrom, not_null tillItem, bool skipTill) = 0; [[nodiscard]] virtual bool allowSaveFileAs( not_null item, not_null document) = 0; [[nodiscard]] virtual QString showInFolderPath( not_null item, not_null document) = 0; virtual void setSearchQuery(QString query) = 0; [[nodiscard]] virtual int64 scrollTopStatePosition( not_null item) = 0; [[nodiscard]] virtual HistoryItem *scrollTopStateItem( ListScrollTopState state) = 0; virtual void saveState( not_null memento, ListScrollTopState scrollState) = 0; virtual void restoreState( not_null memento, Fn restoreScrollState) = 0; virtual ~ListProvider() = default; }; } // namespace Info::Media