1 /* 2 This file is part of Telegram Desktop, 3 the official desktop application for the Telegram messaging service. 4 5 For license and copyright information please follow this link: 6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL 7 */ 8 #pragma once 9 10 #include "ui/widgets/tooltip.h" 11 #include "chat_helpers/bot_command.h" 12 13 class ReplyKeyboard; 14 15 namespace style { 16 struct BotKeyboardButton; 17 } // namespace style 18 19 namespace Window { 20 class SessionController; 21 } // namespace Window 22 23 class BotKeyboard 24 : public TWidget 25 , public Ui::AbstractTooltipShower 26 , public ClickHandlerHost { 27 public: 28 BotKeyboard( 29 not_null<Window::SessionController*> controller, 30 QWidget *parent); 31 32 bool moderateKeyActivate(int index); 33 34 // With force=true the markup is updated even if it is 35 // already shown for the passed history item. 36 bool updateMarkup(HistoryItem *last, bool force = false); 37 [[nodiscard]] bool hasMarkup() const; 38 [[nodiscard]] bool forceReply() const; 39 placeholder()40 [[nodiscard]] QString placeholder() const { 41 return _placeholder; 42 } 43 44 void step_selected(crl::time ms, bool timer); resizeToWidth(int newWidth,int maxOuterHeight)45 void resizeToWidth(int newWidth, int maxOuterHeight) { 46 _maxOuterHeight = maxOuterHeight; 47 return TWidget::resizeToWidth(newWidth); 48 } 49 50 [[nodiscard]] bool maximizeSize() const; 51 [[nodiscard]] bool singleUse() const; 52 forMsgId()53 [[nodiscard]] FullMsgId forMsgId() const { 54 return _wasForMsgId; 55 } 56 57 // AbstractTooltipShower interface 58 QString tooltipText() const override; 59 QPoint tooltipPos() const override; 60 bool tooltipWindowActive() const override; 61 62 // ClickHandlerHost interface 63 void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; 64 void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; 65 66 rpl::producer<Bot::SendCommandRequest> sendCommandRequests() const; 67 68 ~BotKeyboard(); 69 70 protected: 71 int resizeGetHeight(int newWidth) override; 72 73 void paintEvent(QPaintEvent *e) override; 74 void mousePressEvent(QMouseEvent *e) override; 75 void mouseMoveEvent(QMouseEvent *e) override; 76 void mouseReleaseEvent(QMouseEvent *e) override; 77 void enterEventHook(QEnterEvent *e) override; 78 void leaveEventHook(QEvent *e) override; 79 80 private: 81 void updateSelected(); 82 83 void updateStyle(int newWidth); 84 void clearSelection(); 85 86 const not_null<Window::SessionController*> _controller; 87 FullMsgId _wasForMsgId; 88 QString _placeholder; 89 int _height = 0; 90 int _maxOuterHeight = 0; 91 bool _maximizeSize = false; 92 bool _singleUse = false; 93 bool _forceReply = false; 94 95 QPoint _lastMousePos; 96 std::unique_ptr<ReplyKeyboard> _impl; 97 98 rpl::event_stream<Bot::SendCommandRequest> _sendCommandRequests; 99 100 const style::BotKeyboardButton *_st = nullptr; 101 102 }; 103