2016-04-09 18:45:55 +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.
|
2016-04-09 18:45:55 +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
|
2016-04-09 18:45:55 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "dialogs/dialogs_row.h"
|
|
|
|
|
|
|
|
class PeerData;
|
|
|
|
namespace Dialogs {
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
enum class SortMode;
|
|
|
|
|
2019-04-22 14:22:39 +00:00
|
|
|
class List final {
|
2016-04-09 18:45:55 +00:00
|
|
|
public:
|
2020-03-17 13:04:30 +00:00
|
|
|
List(SortMode sortMode, FilterId filterId = 0);
|
2016-04-09 18:45:55 +00:00
|
|
|
List(const List &other) = delete;
|
|
|
|
List &operator=(const List &other) = delete;
|
2019-04-16 14:05:56 +00:00
|
|
|
List(List &&other) = default;
|
|
|
|
List &operator=(List &&other) = default;
|
|
|
|
~List() = default;
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2023-02-12 10:39:06 +00:00
|
|
|
void clear() {
|
|
|
|
_rows.clear();
|
|
|
|
_rowByKey.clear();
|
|
|
|
}
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] int size() const {
|
2019-04-16 11:37:50 +00:00
|
|
|
return _rows.size();
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] bool empty() const {
|
2019-04-16 11:37:50 +00:00
|
|
|
return _rows.empty();
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] int height() const {
|
|
|
|
return _rows.empty()
|
|
|
|
? 0
|
|
|
|
: (_rows.back()->top() + _rows.back()->height());
|
|
|
|
}
|
|
|
|
[[nodiscard]] bool contains(Key key) const {
|
2018-01-04 17:15:04 +00:00
|
|
|
return _rowByKey.find(key) != _rowByKey.end();
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] Row *getRow(Key key) const {
|
2018-01-04 17:15:04 +00:00
|
|
|
const auto i = _rowByKey.find(key);
|
2019-04-16 11:37:50 +00:00
|
|
|
return (i != _rowByKey.end()) ? i->second.get() : nullptr;
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] Row *rowAtY(int y) const;
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2019-04-16 11:37:50 +00:00
|
|
|
not_null<Row*> addToEnd(Key key);
|
2018-01-04 17:15:04 +00:00
|
|
|
Row *adjustByName(Key key);
|
2019-04-16 11:37:50 +00:00
|
|
|
not_null<Row*> addByName(Key key);
|
2018-01-04 17:15:04 +00:00
|
|
|
bool moveToTop(Key key);
|
2019-04-16 11:37:50 +00:00
|
|
|
void adjustByDate(not_null<Row*> row);
|
2022-12-01 17:36:26 +00:00
|
|
|
bool updateHeight(Key key, float64 narrowRatio);
|
|
|
|
bool updateHeights(float64 narrowRatio);
|
2022-11-11 06:23:23 +00:00
|
|
|
bool remove(Key key, Row *replacedBy = nullptr);
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2019-04-16 11:37:50 +00:00
|
|
|
using const_iterator = std::vector<not_null<Row*>>::const_iterator;
|
2016-04-09 18:45:55 +00:00
|
|
|
using iterator = const_iterator;
|
|
|
|
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] const_iterator cbegin() const { return _rows.cbegin(); }
|
|
|
|
[[nodiscard]] const_iterator cend() const { return _rows.cend(); }
|
|
|
|
[[nodiscard]] const_iterator begin() const { return cbegin(); }
|
|
|
|
[[nodiscard]] const_iterator end() const { return cend(); }
|
|
|
|
[[nodiscard]] iterator begin() { return cbegin(); }
|
|
|
|
[[nodiscard]] iterator end() { return cend(); }
|
|
|
|
[[nodiscard]] const_iterator cfind(Row *value) const;
|
|
|
|
[[nodiscard]] const_iterator find(Row *value) const {
|
|
|
|
return cfind(value);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] iterator find(Row *value) { return cfind(value); }
|
2022-11-11 18:58:51 +00:00
|
|
|
[[nodiscard]] iterator findByY(int y) const;
|
2016-04-09 18:45:55 +00:00
|
|
|
|
|
|
|
private:
|
2019-04-16 11:37:50 +00:00
|
|
|
void adjustByName(not_null<Row*> row);
|
|
|
|
void rotate(
|
|
|
|
std::vector<not_null<Row*>>::iterator first,
|
|
|
|
std::vector<not_null<Row*>>::iterator middle,
|
|
|
|
std::vector<not_null<Row*>>::iterator last);
|
|
|
|
|
|
|
|
SortMode _sortMode = SortMode();
|
2020-03-17 13:04:30 +00:00
|
|
|
FilterId _filterId = 0;
|
2022-12-01 17:36:26 +00:00
|
|
|
float64 _narrowRatio = 0.;
|
2019-04-16 11:37:50 +00:00
|
|
|
std::vector<not_null<Row*>> _rows;
|
|
|
|
std::map<Key, std::unique_ptr<Row>> _rowByKey;
|
2018-01-04 17:15:04 +00:00
|
|
|
|
2016-04-09 18:45:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Dialogs
|