2017-04-08 13:27:53 +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-04-08 13:27:53 +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-04-08 13:27:53 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-08-31 11:21:24 +00:00
|
|
|
#include "ui/widgets/fields/input_field.h"
|
2018-05-21 21:31:46 +00:00
|
|
|
#include "base/timer.h"
|
2023-05-17 11:51:04 +00:00
|
|
|
#include "chat_helpers/compose/compose_features.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2019-11-05 11:27:21 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_SPELLCHECK
|
2020-02-21 09:48:24 +00:00
|
|
|
#include "boxes/dictionaries_manager.h"
|
2019-11-05 11:27:21 +00:00
|
|
|
#include "spellcheck/spelling_highlighter.h"
|
|
|
|
#endif // TDESKTOP_DISABLE_SPELLCHECK
|
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
2019-08-02 10:40:35 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
2023-05-02 09:33:19 +00:00
|
|
|
class SessionShow;
|
2019-08-02 10:40:35 +00:00
|
|
|
} // namespace Main
|
2019-06-06 10:21:40 +00:00
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2017-04-08 13:27:53 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2023-05-02 09:33:19 +00:00
|
|
|
namespace ChatHelpers {
|
|
|
|
enum class PauseReason;
|
|
|
|
class Show;
|
|
|
|
} // namespace ChatHelpers
|
|
|
|
|
2020-07-24 08:23:08 +00:00
|
|
|
namespace Ui {
|
|
|
|
class PopupMenu;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2023-08-21 09:00:38 +00:00
|
|
|
[[nodiscard]] QString PrepareMentionTag(not_null<UserData*> user);
|
|
|
|
[[nodiscard]] TextWithTags PrepareEditText(not_null<HistoryItem*> item);
|
|
|
|
[[nodiscard]] bool EditTextChanged(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
const TextWithTags &updated);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<bool(
|
2018-05-26 14:58:21 +00:00
|
|
|
Ui::InputField::EditLinkSelection selection,
|
|
|
|
QString text,
|
|
|
|
QString link,
|
|
|
|
Ui::InputField::EditLinkAction action)> DefaultEditLinkCallback(
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<Main::SessionShow> show,
|
2022-03-06 13:02:15 +00:00
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
const style::InputField *fieldStyle = nullptr);
|
2022-07-01 13:36:58 +00:00
|
|
|
void InitMessageFieldHandlers(
|
|
|
|
not_null<Main::Session*> session,
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<Main::SessionShow> show, // may be null
|
2022-07-01 13:36:58 +00:00
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
Fn<bool()> customEmojiPaused,
|
2022-08-01 13:24:51 +00:00
|
|
|
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji = nullptr,
|
2022-07-01 13:36:58 +00:00
|
|
|
const style::InputField *fieldStyle = nullptr);
|
2022-07-01 13:01:39 +00:00
|
|
|
void InitMessageFieldHandlers(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::InputField*> field,
|
2023-05-02 09:33:19 +00:00
|
|
|
ChatHelpers::PauseReason pauseReasonLevel,
|
2022-08-01 13:24:51 +00:00
|
|
|
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji = nullptr);
|
2023-05-02 09:33:19 +00:00
|
|
|
void InitMessageField(
|
|
|
|
std::shared_ptr<ChatHelpers::Show> show,
|
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji);
|
2018-05-26 14:58:21 +00:00
|
|
|
void InitMessageField(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2022-07-15 14:52:36 +00:00
|
|
|
not_null<Ui::InputField*> field,
|
2022-08-01 13:24:51 +00:00
|
|
|
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji);
|
2019-11-05 11:27:21 +00:00
|
|
|
|
2022-03-03 08:51:43 +00:00
|
|
|
void InitSpellchecker(
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<Main::SessionShow> show,
|
2022-03-06 12:52:01 +00:00
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
bool skipDictionariesManager = false);
|
2019-11-05 11:27:21 +00:00
|
|
|
|
2018-05-21 21:31:46 +00:00
|
|
|
bool HasSendText(not_null<const Ui::InputField*> field);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-05-21 21:31:46 +00:00
|
|
|
struct InlineBotQuery {
|
|
|
|
QString query;
|
|
|
|
QString username;
|
|
|
|
UserData *bot = nullptr;
|
|
|
|
bool lookingUpBot = false;
|
|
|
|
};
|
2020-06-08 09:06:50 +00:00
|
|
|
InlineBotQuery ParseInlineBotQuery(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
not_null<const Ui::InputField*> field);
|
2018-05-21 21:31:46 +00:00
|
|
|
|
|
|
|
struct AutocompleteQuery {
|
|
|
|
QString query;
|
|
|
|
bool fromStart = false;
|
|
|
|
};
|
|
|
|
AutocompleteQuery ParseMentionHashtagBotCommandQuery(
|
2023-05-17 11:51:04 +00:00
|
|
|
not_null<const Ui::InputField*> field,
|
|
|
|
ChatHelpers::ComposeFeatures features);
|
2018-05-21 21:31:46 +00:00
|
|
|
|
|
|
|
class MessageLinksParser : private QObject {
|
|
|
|
public:
|
|
|
|
MessageLinksParser(not_null<Ui::InputField*> field);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2021-01-29 11:27:17 +00:00
|
|
|
void parseNow();
|
2023-08-21 09:00:38 +00:00
|
|
|
void setDisabled(bool disabled);
|
2021-01-29 11:27:17 +00:00
|
|
|
|
|
|
|
[[nodiscard]] const rpl::variable<QStringList> &list() const;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
protected:
|
2018-05-21 21:31:46 +00:00
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
private:
|
2018-05-21 21:31:46 +00:00
|
|
|
struct LinkRange {
|
|
|
|
int start;
|
|
|
|
int length;
|
2018-05-26 14:58:21 +00:00
|
|
|
QString custom;
|
2018-05-21 21:31:46 +00:00
|
|
|
};
|
|
|
|
friend inline bool operator==(const LinkRange &a, const LinkRange &b) {
|
2018-05-26 14:58:21 +00:00
|
|
|
return (a.start == b.start)
|
|
|
|
&& (a.length == b.length)
|
|
|
|
&& (a.custom == b.custom);
|
2018-05-21 21:31:46 +00:00
|
|
|
}
|
|
|
|
friend inline bool operator!=(const LinkRange &a, const LinkRange &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-05-21 21:31:46 +00:00
|
|
|
void parse();
|
|
|
|
void apply(const QString &text, const QVector<LinkRange> &ranges);
|
|
|
|
|
|
|
|
not_null<Ui::InputField*> _field;
|
|
|
|
rpl::variable<QStringList> _list;
|
|
|
|
int _lastLength = 0;
|
2023-08-21 09:00:38 +00:00
|
|
|
bool _disabled = false;
|
2018-05-21 21:31:46 +00:00
|
|
|
base::Timer _timer;
|
2023-08-31 11:21:24 +00:00
|
|
|
rpl::lifetime _lifetime;
|
2018-05-21 21:31:46 +00:00
|
|
|
|
2019-07-26 16:06:22 +00:00
|
|
|
};
|
2023-01-31 17:21:47 +00:00
|
|
|
|
|
|
|
[[nodiscard]] base::unique_qptr<Ui::RpWidget> CreateDisabledFieldView(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<PeerData*> peer);
|