diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index ad5b8033f..c780ab3b8 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -54,7 +54,7 @@ class ApiWrap : private MTP::Sender, private base::Subscriber { void start(); void applyUpdates(const MTPUpdates &updates, quint64 sentMessageRandomId = 0); - using RequestMessageDataCallback = base::lambda; + using RequestMessageDataCallback = Fn; void requestMessageData(ChannelData *channel, MsgId msgId, RequestMessageDataCallback callback); void requestFullPeer(PeerData *peer); diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 97a0d71d5..7dcd361fa 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -207,7 +207,7 @@ bool loggedOut() { void logOut() { if (auto mtproto = Messenger::Instance().mtp()) { - mtproto->logout(rpcDone(&loggedOut), rpcFail(&loggedOut)); + mtproto->logout(rpcDone([] { return loggedOut(); }), rpcFail([] { return loggedOut(); })); } else { // We log out because we've forgotten passcode. // So we just start mtproto from scratch. @@ -1582,7 +1582,7 @@ PeerData *peer(const PeerId &id, PeerData::LoadedStatus restriction) { return i.value(); } -void enumerateUsers(base::lambda action) { +void enumerateUsers(Fn action) { for_const (auto peer, peersData) { if (auto user = peer->asUser()) { action(user); diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index c45307e4b..41470f319 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -142,7 +142,7 @@ inline ChatData *chatLoaded(ChatId chatId) { inline ChannelData *channelLoaded(ChannelId channelId) { return channel(channelId, PeerData::FullLoaded); } -void enumerateUsers(base::lambda action); +void enumerateUsers(Fn action); UserData *self(); PeerData *peerByName(const QString &username); diff --git a/Telegram/SourceFiles/base/lambda.h b/Telegram/SourceFiles/base/lambda.h index 016039352..bb9b5338c 100644 --- a/Telegram/SourceFiles/base/lambda.h +++ b/Telegram/SourceFiles/base/lambda.h @@ -23,6 +23,25 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include // std::max_align_t #include +#ifndef CUSTOM_LAMBDA_WRAP + +#include "base/unique_function.h" +#include + +namespace base { + +namespace lambda_internal { + +template struct lambda_call_type { using type = decltype(&Lambda::operator()); }; + +} // namespace lambda_internal + +template using lambda_call_type_t = typename lambda_internal::lambda_call_type::type; + +} // namespace base + +#else // CUSTOM_LAMBDA_WRAP + #ifndef Assert #define LambdaAssertDefined #define Assert(v) ((v) ? ((void)0) : std::abort()) @@ -63,9 +82,6 @@ template struct type_helper { template using lambda_type = typename lambda_internal::type_helper>::type; -template -constexpr bool lambda_is_mutable = lambda_internal::type_helper>::is_mutable; - namespace lambda_internal { constexpr auto kFullStorageSize = 32U; @@ -416,3 +432,5 @@ template class lambda final #ifdef LambdaUnexpectedDefined #undef Unexpected #endif // LambdaUnexpectedDefined + +#endif // CUSTOM_LAMBDA_WRAP diff --git a/Telegram/SourceFiles/base/lambda_guard.h b/Telegram/SourceFiles/base/lambda_guard.h index 7b38d3d9a..785139330 100644 --- a/Telegram/SourceFiles/base/lambda_guard.h +++ b/Telegram/SourceFiles/base/lambda_guard.h @@ -21,131 +21,76 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "base/lambda.h" +#include "base/weak_unique_ptr.h" #include -namespace base { - -// Guard lambda call by one or many QObject* weak pointers. +// Guard lambda call by QObject* or enable_weak_from_this* pointers. +namespace base { namespace lambda_internal { -template class guard_data { +template class guard_with_QObject { public: - using return_type = typename lambda_type::return_type; - - template - inline guard_data(PointersAndLambda &&... qobjectsAndLambda) - : _lambda(init(_pointers, std::forward(qobjectsAndLambda)...)) {} - - inline guard_data(const guard_data &other) - : _lambda(other._lambda) { - for (auto i = 0; i != N; ++i) { - _pointers[i] = other._pointers[i]; - } - } - - template inline return_type operator()(Args &&... args) { - for (int i = 0; i != N; ++i) { - if (!_pointers[i]) { - return return_type(); - } - } - return _lambda(std::forward(args)...); + template + guard_with_QObject(const QObject *object, OtherLambda &&other) + : _guard(object) + , _callable(std::forward(other)) {} + + template ()(std::declval()...))> + Return operator()(OtherArgs &&... args) { + return _guard ? _callable(std::forward(args)...) : Return(); } - template inline return_type operator()(Args &&... args) const { - for (int i = 0; i != N; ++i) { - if (!_pointers[i]) { - return return_type(); - } - } - return _lambda(std::forward(args)...); + template ()(std::declval()...))> + Return operator()(OtherArgs &&... args) const { + return _guard ? _callable(std::forward(args)...) : Return(); } private: - template - Lambda init(QPointer *pointers, QObject *qobject, PointersAndLambda &&... qobjectsAndLambda) { - *pointers = qobject; - return init(++pointers, std::forward(qobjectsAndLambda)...); - } - Lambda init(QPointer *pointers, Lambda &&lambda) { - return std::move(lambda); - } - - QPointer _pointers[N]; - Lambda _lambda; + QPointer _guard; + Lambda _callable; }; -template class guard { +template class guard_with_weak { public: - using return_type = typename lambda_type::return_type; - - template - inline guard(Pointer &&qobject, Other &&other, PointersAndLambda &&... qobjectsAndLambda) - : _data(std::make_unique>(std::forward(qobject), std::forward(other), - std::forward(qobjectsAndLambda)...)) { - static_assert(1 + 1 + sizeof...(PointersAndLambda) == N + 1, "Wrong argument count!"); - } - - inline guard(const guard &other) - : _data(std::make_unique>(static_cast &>(*other._data))) {} - - inline guard(guard &&other) - : _data(std::move(other._data)) {} - - inline guard &operator=(const guard &&other) { - _data = std::move(other._data); - return *this; - } - - inline guard &operator=(guard &&other) { - _data = std::move(other._data); - return *this; - } - - template inline return_type operator()(Args &&... args) { - return (*_data)(std::forward(args)...); - } - - template inline return_type operator()(Args &&... args) const { - return (*_data)(std::forward(args)...); + template + guard_with_weak(const base::enable_weak_from_this *object, OtherLambda &&other) + : _guard(base::make_weak_unique(object)) + , _callable(std::forward(other)) {} + + template ()(std::declval()...))> + Return operator()(OtherArgs &&... args) { + return _guard ? _callable(std::forward(args)...) : Return{}; } - bool isNull() const { - return !_data; + template ()(std::declval()...))> + Return operator()(OtherArgs &&... args) const { + return _guard ? _callable(std::forward(args)...) : Return{}; } private: - mutable std::unique_ptr> _data; + base::weak_unique_ptr _guard; + Lambda _callable; }; -template struct guard_type; - -template -struct guard_type { - using type = typename guard_type::type; +template struct lambda_call_type> { + using type = lambda_call_type_t; }; -template struct guard_type { using type = guard; }; - -template struct guard_type_helper { - static constexpr int N = sizeof...(PointersAndLambda); - using type = typename guard_type::type; -}; - -template using guard_t = typename guard_type_helper::type; - -template struct type_helper> { - using type = typename type_helper::type; - static constexpr auto is_mutable = type_helper::is_mutable; +template struct lambda_call_type> { + using type = lambda_call_type_t; }; } // namespace lambda_internal -template -inline lambda_internal::guard_t lambda_guarded(PointersAndLambda &&... qobjectsAndLambda) { - static_assert(sizeof...(PointersAndLambda) > 0, "Lambda should be passed here."); - return lambda_internal::guard_t(std::forward(qobjectsAndLambda)...); +template inline auto lambda_guarded(const QObject *object, Lambda &&lambda) { + using Guarded = lambda_internal::guard_with_QObject>; + return Guarded(object, std::forward(lambda)); +} + +template inline auto lambda_guarded(const base::enable_weak_from_this *object, Lambda &&lambda) { + using Guarded = lambda_internal::guard_with_weak>; + return Guarded(object, std::forward(lambda)); } } // namespace base diff --git a/Telegram/SourceFiles/base/observer.h b/Telegram/SourceFiles/base/observer.h index 52ddd4204..41cdbeb39 100644 --- a/Telegram/SourceFiles/base/observer.h +++ b/Telegram/SourceFiles/base/observer.h @@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "base/assertion.h" -#include "base/lambda.h" #include "base/type_traits.h" #include "core/utils.h" #include @@ -31,16 +30,14 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace base { namespace internal { -using ObservableCallHandlers = base::lambda; +using ObservableCallHandlers = Fn; void RegisterPendingObservable(ObservableCallHandlers *handlers); void UnregisterActiveObservable(ObservableCallHandlers *handlers); void UnregisterObservable(ObservableCallHandlers *handlers); -template struct SubscriptionHandlerHelper { - using type = base::lambda)>; -}; +template struct SubscriptionHandlerHelper { using type = Fn)>; }; -template <> struct SubscriptionHandlerHelper { using type = base::lambda; }; +template <> struct SubscriptionHandlerHelper { using type = Fn; }; template using SubscriptionHandler = typename SubscriptionHandlerHelper::type; diff --git a/Telegram/SourceFiles/base/task_queue.h b/Telegram/SourceFiles/base/task_queue.h index 7699fee99..4d7e86c7f 100644 --- a/Telegram/SourceFiles/base/task_queue.h +++ b/Telegram/SourceFiles/base/task_queue.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "base/timer.h" #include #include @@ -28,7 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace base { -using Task = lambda_once; +using Task = FnMut; // An attempt to create/use a TaskQueue or one of the default queues // after the main() has returned leads to an undefined behaviour. diff --git a/Telegram/SourceFiles/base/timer.cpp b/Telegram/SourceFiles/base/timer.cpp index 7798a93d1..328520c62 100644 --- a/Telegram/SourceFiles/base/timer.cpp +++ b/Telegram/SourceFiles/base/timer.cpp @@ -31,7 +31,7 @@ QObject *TimersAdjuster() { } // namespace -Timer::Timer(base::lambda callback) +Timer::Timer(Fn callback) : QObject(nullptr) , _callback(std::move(callback)) , _type(Qt::PreciseTimer) @@ -108,7 +108,7 @@ void Timer::timerEvent(QTimerEvent *e) { } } -int DelayedCallTimer::call(TimeMs timeout, lambda_once callback, Qt::TimerType type) { +int DelayedCallTimer::call(TimeMs timeout, FnMut callback, Qt::TimerType type) { Expects(timeout >= 0); if (!callback) { return 0; diff --git a/Telegram/SourceFiles/base/timer.h b/Telegram/SourceFiles/base/timer.h index 489f045f6..302b61e8c 100644 --- a/Telegram/SourceFiles/base/timer.h +++ b/Telegram/SourceFiles/base/timer.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "base/observer.h" using TimeMs = qint64; @@ -29,14 +28,14 @@ namespace base { class Timer final : private QObject { public: - Timer(base::lambda callback = base::lambda()); + Timer(Fn callback = Fn()); static Qt::TimerType DefaultType(TimeMs timeout) { constexpr auto kThreshold = TimeMs(1000); return (timeout > kThreshold) ? Qt::CoarseTimer : Qt::PreciseTimer; } - void setCallback(base::lambda callback) { + void setCallback(Fn callback) { _callback = std::move(callback); } @@ -86,7 +85,7 @@ class Timer final : private QObject { return static_cast(_repeat); } - base::lambda _callback; + Fn _callback; TimeMs _next = 0; int _timeout = 0; int _timerId = 0; @@ -98,18 +97,18 @@ class Timer final : private QObject { class DelayedCallTimer final : private QObject { public: - int call(TimeMs timeout, lambda_once callback) { + int call(TimeMs timeout, FnMut callback) { return call(timeout, std::move(callback), Timer::DefaultType(timeout)); } - int call(TimeMs timeout, lambda_once callback, Qt::TimerType type); + int call(TimeMs timeout, FnMut callback, Qt::TimerType type); void cancel(int callId); protected: void timerEvent(QTimerEvent *e) override; private: - std::map> _callbacks; // Better to use flatmap. + std::map> _callbacks; // Better to use flatmap. }; } // namespace base diff --git a/Telegram/SourceFiles/base/unique_function.h b/Telegram/SourceFiles/base/unique_function.h new file mode 100644 index 000000000..d008a280a --- /dev/null +++ b/Telegram/SourceFiles/base/unique_function.h @@ -0,0 +1,148 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +*/ +#pragma once + +#include + +#ifndef Unexpected +#define Unexpected(message) std::abort() +#define UniqueFunctionUnexpected +#endif // Unexpected + +namespace base { +namespace details { + +template class moveable_callable_wrap { +public: + static_assert(std::is_move_constructible_v, "Should be at least moveable."); + + moveable_callable_wrap(Callable &&other) + : _value(std::move(other)) {} + moveable_callable_wrap &operator=(Callable &&other) { + _value = std::move(other); + return *this; + } + moveable_callable_wrap(moveable_callable_wrap &&other) + : _value(std::move(other._value)) {} + moveable_callable_wrap(const moveable_callable_wrap &other) + : _value(fail_construct()) {} + moveable_callable_wrap &operator=(moveable_callable_wrap &&other) { + _value = std::move(other._value); + return *this; + } + moveable_callable_wrap &operator=(const moveable_callable_wrap &other) { + return fail_assign(); + } + + template decltype(auto) operator()(Args &&... args) const { + return _value(std::forward(args)...); + } + +private: + [[noreturn]] Callable fail_construct() { + Unexpected("Attempt to copy-construct a move-only type."); + }[[noreturn]] moveable_callable_wrap &fail_assign() { + Unexpected("Attempt to copy-assign a move-only type."); + } + + mutable Callable _value; +}; + +} // namespace details + +template class unique_function; + +template class unique_function final { +public: + unique_function(std::nullptr_t = nullptr) noexcept {} + unique_function(const unique_function &other) = delete; + unique_function &operator=(const unique_function &other) = delete; + + // Move construct / assign from the same type. + unique_function(unique_function &&other) + : _impl(std::move(other._impl)) {} + unique_function &operator=(unique_function &&other) { + _impl = std::move(other._impl); + return *this; + } + + template ()(std::declval()...)), Return>>> + unique_function(Callable &&other) + : unique_function(std::forward(other), std::is_copy_constructible>{}) {} + + template ()(std::declval()...)), Return>>> + unique_function &operator=(Callable &&other) { + using Decayed = std::decay_t; + if constexpr (std::is_copy_constructible_v) { + _impl = std::forward(other); + } else if constexpr (std::is_move_constructible_v) { + _impl = details::moveable_callable_wrap(std::forward(other)); + } else { + static_assert(false_t(other), "Should be moveable."); + } + return *this; + } + + void swap(unique_function &other) { + _impl.swap(other._impl); + } + + template Return operator()(OtherArgs &&... args) { + return _impl(std::forward(args)...); + } + + explicit operator bool() const { + return _impl.operator bool(); + } + + friend inline bool operator==(const unique_function &value, std::nullptr_t) noexcept { + return value._impl == nullptr; + } + friend inline bool operator==(std::nullptr_t, const unique_function &value) noexcept { + return value._impl == nullptr; + } + friend inline bool operator!=(const unique_function &value, std::nullptr_t) noexcept { + return value._impl != nullptr; + } + friend inline bool operator!=(std::nullptr_t, const unique_function &value) noexcept { + return value._impl != nullptr; + } + +private: + template + unique_function(Callable &&other, std::true_type) + : _impl(std::forward(other)) {} + + template + unique_function(Callable &&other, std::false_type) + : _impl(details::moveable_callable_wrap>(std::forward(other))) {} + + std::function _impl; +}; + +} // namespace base + +#ifdef UniqueFunctionUnexpected +#undef UniqueFunctionUnexpected +#undef Unexpected +#endif // UniqueFunctionUnexpectedb diff --git a/Telegram/SourceFiles/base/weak_unique_ptr.h b/Telegram/SourceFiles/base/weak_unique_ptr.h index 5347d95ab..140fbf3fd 100644 --- a/Telegram/SourceFiles/base/weak_unique_ptr.h +++ b/Telegram/SourceFiles/base/weak_unique_ptr.h @@ -46,14 +46,15 @@ class enable_weak_from_this { private: template friend class weak_unique_ptr; - std::shared_ptr getGuarded() { + std::shared_ptr getGuarded() const { if (!_guarded) { - _guarded = std::make_shared(static_cast(this)); + _guarded = std::make_shared( + const_cast(static_cast(this))); } return _guarded; } - std::shared_ptr _guarded; + mutable std::shared_ptr _guarded; }; template class weak_unique_ptr { diff --git a/Telegram/SourceFiles/boxes/abstract_box.cpp b/Telegram/SourceFiles/boxes/abstract_box.cpp index e368e5497..e0ac4687c 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.cpp +++ b/Telegram/SourceFiles/boxes/abstract_box.cpp @@ -32,13 +32,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/labels.h" #include "ui/widgets/scroll_area.h" -QPointer BoxContent::addButton(base::lambda textFactory, - base::lambda clickCallback) { +QPointer BoxContent::addButton(Fn textFactory, Fn clickCallback) { return addButton(std::move(textFactory), std::move(clickCallback), st::defaultBoxButton); } -QPointer BoxContent::addLeftButton(base::lambda textFactory, - base::lambda clickCallback) { +QPointer BoxContent::addLeftButton(Fn textFactory, Fn clickCallback) { return getDelegate()->addLeftButton(std::move(textFactory), std::move(clickCallback), st::defaultBoxButton); } @@ -279,7 +277,7 @@ void AbstractBox::parentResized() { update(); } -void AbstractBox::setTitle(base::lambda titleFactory) { +void AbstractBox::setTitle(Fn titleFactory) { _titleFactory = std::move(titleFactory); refreshTitle(); } @@ -300,7 +298,7 @@ void AbstractBox::refreshTitle() { } } -void AbstractBox::setAdditionalTitle(base::lambda additionalFactory) { +void AbstractBox::setAdditionalTitle(Fn additionalFactory) { _additionalTitleFactory = std::move(additionalFactory); refreshAdditionalTitle(); } @@ -355,8 +353,8 @@ void AbstractBox::clearButtons() { _leftButton.destroy(); } -QPointer AbstractBox::addButton(base::lambda textFactory, - base::lambda clickCallback, const style::RoundButton &st) { +QPointer AbstractBox::addButton(Fn textFactory, Fn clickCallback, + const style::RoundButton &st) { _buttons.push_back(object_ptr(this, std::move(textFactory), st)); auto result = QPointer(_buttons.back()); result->setClickedCallback(std::move(clickCallback)); @@ -365,8 +363,8 @@ QPointer AbstractBox::addButton(base::lambda textFac return result; } -QPointer AbstractBox::addLeftButton(base::lambda textFactory, - base::lambda clickCallback, const style::RoundButton &st) { +QPointer AbstractBox::addLeftButton(Fn textFactory, Fn clickCallback, + const style::RoundButton &st) { _leftButton = object_ptr(this, std::move(textFactory), st); auto result = QPointer(_leftButton); result->setClickedCallback(std::move(clickCallback)); diff --git a/Telegram/SourceFiles/boxes/abstract_box.h b/Telegram/SourceFiles/boxes/abstract_box.h index e2ff7e808..393fe7250 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.h +++ b/Telegram/SourceFiles/boxes/abstract_box.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "base/observer.h" #include "layerwidget.h" #include "ui/text/text_entity.h" @@ -46,14 +45,13 @@ class BoxContentDelegate { virtual Window::Controller *controller() const = 0; virtual void setLayerType(bool layerType) = 0; - virtual void setTitle(base::lambda titleFactory) = 0; - virtual void setAdditionalTitle(base::lambda additionalFactory) = 0; + virtual void setTitle(Fn titleFactory) = 0; + virtual void setAdditionalTitle(Fn additionalFactory) = 0; virtual void clearButtons() = 0; - virtual QPointer addButton(base::lambda textFactory, base::lambda clickCallback, + virtual QPointer addButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) = 0; - virtual QPointer addLeftButton(base::lambda textFactory, - base::lambda clickCallback, + virtual QPointer addLeftButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) = 0; virtual void updateButtonsPositions() = 0; @@ -78,26 +76,26 @@ class BoxContent : public TWidget, protected base::Subscriber { getDelegate()->closeBox(); } - void setTitle(base::lambda titleFactory) { + void setTitle(Fn titleFactory) { if (titleFactory) { getDelegate()->setTitle([titleFactory] { return TextWithEntities{titleFactory(), EntitiesInText()}; }); } else { - getDelegate()->setTitle(base::lambda()); + getDelegate()->setTitle(Fn()); } } - void setTitle(base::lambda titleFactory) { + void setTitle(Fn titleFactory) { getDelegate()->setTitle(std::move(titleFactory)); } - void setAdditionalTitle(base::lambda additional) { + void setAdditionalTitle(Fn additional) { getDelegate()->setAdditionalTitle(std::move(additional)); } void clearButtons() { getDelegate()->clearButtons(); } - QPointer addButton(base::lambda textFactory, base::lambda clickCallback); - QPointer addLeftButton(base::lambda textFactory, base::lambda clickCallback); - QPointer addButton(base::lambda textFactory, base::lambda clickCallback, + QPointer addButton(Fn textFactory, Fn clickCallback); + QPointer addLeftButton(Fn textFactory, Fn clickCallback); + QPointer addButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) { return getDelegate()->addButton(std::move(textFactory), std::move(clickCallback), st); } @@ -214,13 +212,13 @@ class AbstractBox : public LayerWidget, public BoxContentDelegate, protected bas void parentResized() override; void setLayerType(bool layerType) override; - void setTitle(base::lambda titleFactory) override; - void setAdditionalTitle(base::lambda additionalFactory) override; + void setTitle(Fn titleFactory) override; + void setAdditionalTitle(Fn additionalFactory) override; void clearButtons() override; - QPointer addButton(base::lambda textFactory, base::lambda clickCallback, + QPointer addButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) override; - QPointer addLeftButton(base::lambda textFactory, base::lambda clickCallback, + QPointer addLeftButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) override; void updateButtonsPositions() override; @@ -276,9 +274,9 @@ class AbstractBox : public LayerWidget, public BoxContentDelegate, protected bas object_ptr _content; object_ptr _title = {nullptr}; - base::lambda _titleFactory; + Fn _titleFactory; QString _additionalTitle; - base::lambda _additionalTitleFactory; + Fn _additionalTitleFactory; int _titleLeft = 0; int _titleTop = 0; bool _layerType = false; diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 00caade87..c62644a31 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -68,7 +68,7 @@ QString PeerFloodErrorText(PeerFloodType type) { class RevokePublicLinkBox::Inner : public TWidget, private MTP::Sender { public: - Inner(QWidget *parent, base::lambda revokeCallback); + Inner(QWidget *parent, Fn revokeCallback); protected: void mouseMoveEvent(QMouseEvent *e) override; @@ -96,7 +96,7 @@ class RevokePublicLinkBox::Inner : public TWidget, private MTP::Sender { int _rowHeight = 0; int _revokeWidth = 0; - base::lambda _revokeCallback; + Fn _revokeCallback; mtpRequestId _revokeRequestId = 0; QPointer _weakRevokeConfirmBox; }; @@ -600,7 +600,7 @@ SetupChannelBox::SetupChannelBox(QWidget *, ChannelData *channel, bool existing) , _aboutPrivate(st::defaultTextStyle, lang(channel->isMegagroup() ? lng_create_private_group_about : lng_create_private_channel_about), _defaultOptions, _aboutPublicWidth) - , _link(this, st::setupChannelLink, base::lambda(), channel->username, true) {} + , _link(this, st::setupChannelLink, Fn(), channel->username, true) {} void SetupChannelBox::prepare() { _aboutPublicHeight = _aboutPublic.countHeight(_aboutPublicWidth); @@ -1479,7 +1479,7 @@ void EditChannelBox::onSaveInvitesDone(const MTPUpdates &result) { closeBox(); } -RevokePublicLinkBox::Inner::Inner(QWidget *parent, base::lambda revokeCallback) +RevokePublicLinkBox::Inner::Inner(QWidget *parent, Fn revokeCallback) : TWidget(parent) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) , _revokeWidth(st::normalFont->width(lang(lng_channels_too_much_public_revoke))) @@ -1513,7 +1513,7 @@ RevokePublicLinkBox::Inner::Inner(QWidget *parent, base::lambda revokeCa .send(); } -RevokePublicLinkBox::RevokePublicLinkBox(QWidget *, base::lambda revokeCallback) +RevokePublicLinkBox::RevokePublicLinkBox(QWidget *, Fn revokeCallback) : _aboutRevoke(this, lang(lng_channels_too_much_public_about), Ui::FlatLabel::InitType::Simple, st::aboutRevokePublicLabel) , _revokeCallback(std::move(revokeCallback)) {} diff --git a/Telegram/SourceFiles/boxes/add_contact_box.h b/Telegram/SourceFiles/boxes/add_contact_box.h index 72dd67f1c..9ad557bd7 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.h +++ b/Telegram/SourceFiles/boxes/add_contact_box.h @@ -321,7 +321,7 @@ private slots: class RevokePublicLinkBox : public BoxContent, public RPCSender { public: - RevokePublicLinkBox(QWidget *, base::lambda revokeCallback); + RevokePublicLinkBox(QWidget *, Fn revokeCallback); protected: void prepare() override; @@ -335,5 +335,5 @@ class RevokePublicLinkBox : public BoxContent, public RPCSender { QPointer _inner; int _innerTop = 0; - base::lambda _revokeCallback; + Fn _revokeCallback; }; diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index e6da96216..9eddc760c 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -33,7 +33,7 @@ class BackgroundBox::Inner : public TWidget, public RPCSender, private base::Sub public: Inner(QWidget *parent); - void setBackgroundChosenCallback(base::lambda callback) { + void setBackgroundChosenCallback(Fn callback) { _backgroundChosenCallback = std::move(callback); } @@ -49,7 +49,7 @@ class BackgroundBox::Inner : public TWidget, public RPCSender, private base::Sub void gotWallpapers(const MTPVector &result); void updateWallpapers(); - base::lambda _backgroundChosenCallback; + Fn _backgroundChosenCallback; int _bgCount = 0; int _rows = 0; diff --git a/Telegram/SourceFiles/boxes/calendar_box.cpp b/Telegram/SourceFiles/boxes/calendar_box.cpp index e0349db9f..aadd83912 100644 --- a/Telegram/SourceFiles/boxes/calendar_box.cpp +++ b/Telegram/SourceFiles/boxes/calendar_box.cpp @@ -204,7 +204,7 @@ class CalendarBox::Inner : public TWidget, public RPCSender, private base::Subsc return st::calendarPadding.top() + innerHeight + st::calendarPadding.bottom(); } - void setDateChosenCallback(base::lambda callback) { + void setDateChosenCallback(Fn callback) { _dateChosenCallback = std::move(callback); } @@ -230,7 +230,7 @@ class CalendarBox::Inner : public TWidget, public RPCSender, private base::Subsc std::map> _ripples; - base::lambda _dateChosenCallback; + Fn _dateChosenCallback; static constexpr auto kEmptySelection = -kDaysInWeek; int _selected = kEmptySelection; @@ -438,7 +438,7 @@ void CalendarBox::Title::paintEvent(QPaintEvent *e) { _textWidth); } -CalendarBox::CalendarBox(QWidget *, QDate month, QDate highlighted, base::lambda callback) +CalendarBox::CalendarBox(QWidget *, QDate month, QDate highlighted, Fn callback) : _context(std::make_unique(month, highlighted)) , _inner(this, _context.get()) , _title(this, _context.get()) diff --git a/Telegram/SourceFiles/boxes/calendar_box.h b/Telegram/SourceFiles/boxes/calendar_box.h index 841df6092..7be69fb56 100644 --- a/Telegram/SourceFiles/boxes/calendar_box.h +++ b/Telegram/SourceFiles/boxes/calendar_box.h @@ -28,7 +28,7 @@ class IconButton; class CalendarBox : public BoxContent { public: - CalendarBox(QWidget *, QDate month, QDate highlighted, base::lambda callback); + CalendarBox(QWidget *, QDate month, QDate highlighted, Fn callback); void setMinDate(QDate date); void setMaxDate(QDate date); @@ -57,5 +57,5 @@ class CalendarBox : public BoxContent { object_ptr _previous; object_ptr _next; - base::lambda _callback; + Fn _callback; }; diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index eb2243bb0..461090a2c 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -42,8 +42,7 @@ TextParseOptions _confirmBoxTextOptions = { Qt::LayoutDirectionAuto, // dir }; -ConfirmBox::ConfirmBox(QWidget *, const QString &text, base::lambda_once confirmedCallback, - base::lambda_once cancelledCallback) +ConfirmBox::ConfirmBox(QWidget *, const QString &text, FnMut confirmedCallback, FnMut cancelledCallback) : _confirmText(lang(lng_box_ok)) , _cancelText(lang(lng_cancel)) , _confirmStyle(st::defaultBoxButton) @@ -53,8 +52,8 @@ ConfirmBox::ConfirmBox(QWidget *, const QString &text, base::lambda_once init(text); } -ConfirmBox::ConfirmBox(QWidget *, const QString &text, const QString &confirmText, - base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) +ConfirmBox::ConfirmBox(QWidget *, const QString &text, const QString &confirmText, FnMut confirmedCallback, + FnMut cancelledCallback) : _confirmText(confirmText) , _cancelText(lang(lng_cancel)) , _confirmStyle(st::defaultBoxButton) @@ -65,8 +64,8 @@ ConfirmBox::ConfirmBox(QWidget *, const QString &text, const QString &confirmTex } ConfirmBox::ConfirmBox(QWidget *, const QString &text, const QString &confirmText, - const style::RoundButton &confirmStyle, base::lambda_once confirmedCallback, - base::lambda_once cancelledCallback) + const style::RoundButton &confirmStyle, FnMut confirmedCallback, + FnMut cancelledCallback) : _confirmText(confirmText) , _cancelText(lang(lng_cancel)) , _confirmStyle(confirmStyle) @@ -77,7 +76,7 @@ ConfirmBox::ConfirmBox(QWidget *, const QString &text, const QString &confirmTex } ConfirmBox::ConfirmBox(QWidget *, const QString &text, const QString &confirmText, const QString &cancelText, - base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) + FnMut confirmedCallback, FnMut cancelledCallback) : _confirmText(confirmText) , _cancelText(cancelText) , _confirmStyle(st::defaultBoxButton) @@ -89,7 +88,7 @@ ConfirmBox::ConfirmBox(QWidget *, const QString &text, const QString &confirmTex ConfirmBox::ConfirmBox(QWidget *, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, - base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) + FnMut confirmedCallback, FnMut cancelledCallback) : _confirmText(confirmText) , _cancelText(cancelText) , _confirmStyle(st::defaultBoxButton) @@ -99,8 +98,7 @@ ConfirmBox::ConfirmBox(QWidget *, const QString &text, const QString &confirmTex init(text); } -ConfirmBox::ConfirmBox(const InformBoxTag &, const QString &text, const QString &doneText, - base::lambda closedCallback) +ConfirmBox::ConfirmBox(const InformBoxTag &, const QString &text, const QString &doneText, Fn closedCallback) : _confirmText(doneText) , _confirmStyle(st::defaultBoxButton) , _informative(true) @@ -110,7 +108,7 @@ ConfirmBox::ConfirmBox(const InformBoxTag &, const QString &text, const QString init(text); } -base::lambda_once ConfirmBox::generateInformCallback(base::lambda closedCallback) { +FnMut ConfirmBox::generateInformCallback(Fn closedCallback) { return base::lambda_guarded(this, [this, closedCallback] { closeBox(); if (closedCallback) { @@ -222,10 +220,10 @@ void ConfirmBox::paintEvent(QPaintEvent *e) { _text.drawLeftElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, width(), 16, style::al_left); } -InformBox::InformBox(QWidget *, const QString &text, base::lambda closedCallback) +InformBox::InformBox(QWidget *, const QString &text, Fn closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, lang(lng_box_ok), std::move(closedCallback)) {} -InformBox::InformBox(QWidget *, const QString &text, const QString &doneText, base::lambda closedCallback) +InformBox::InformBox(QWidget *, const QString &text, const QString &doneText, Fn closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, doneText, std::move(closedCallback)) {} MaxInviteBox::MaxInviteBox(QWidget *, not_null channel) diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index bf9fd888f..4d49334a7 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -31,21 +31,17 @@ class FlatLabel; class InformBox; class ConfirmBox : public BoxContent, public ClickHandlerHost { public: - ConfirmBox(QWidget *, const QString &text, - base::lambda_once confirmedCallback = base::lambda_once(), - base::lambda_once cancelledCallback = base::lambda_once()); + ConfirmBox(QWidget *, const QString &text, FnMut confirmedCallback = FnMut(), + FnMut cancelledCallback = FnMut()); ConfirmBox(QWidget *, const QString &text, const QString &confirmText, - base::lambda_once confirmedCallback = base::lambda_once(), - base::lambda_once cancelledCallback = base::lambda_once()); + FnMut confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); ConfirmBox(QWidget *, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, - base::lambda_once confirmedCallback = base::lambda_once(), - base::lambda_once cancelledCallback = base::lambda_once()); + FnMut confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); ConfirmBox(QWidget *, const QString &text, const QString &confirmText, const QString &cancelText, - base::lambda_once confirmedCallback = base::lambda_once(), - base::lambda_once cancelledCallback = base::lambda_once()); + FnMut confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); ConfirmBox(QWidget *, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, - const QString &cancelText, base::lambda_once confirmedCallback = base::lambda_once(), - base::lambda_once cancelledCallback = base::lambda_once()); + const QString &cancelText, FnMut confirmedCallback = FnMut(), + FnMut cancelledCallback = FnMut()); void updateLink(); @@ -70,8 +66,8 @@ class ConfirmBox : public BoxContent, public ClickHandlerHost { private: struct InformBoxTag {}; - ConfirmBox(const InformBoxTag &, const QString &text, const QString &doneText, base::lambda closedCallback); - base::lambda_once generateInformCallback(base::lambda closedCallback); + ConfirmBox(const InformBoxTag &, const QString &text, const QString &doneText, Fn closedCallback); + FnMut generateInformCallback(Fn closedCallback); friend class InformBox; void confirmed(); @@ -94,15 +90,14 @@ class ConfirmBox : public BoxContent, public ClickHandlerHost { bool _confirmed = false; bool _cancelled = false; bool _strictCancel = false; - base::lambda_once _confirmedCallback; - base::lambda_once _cancelledCallback; + FnMut _confirmedCallback; + FnMut _cancelledCallback; }; class InformBox : public ConfirmBox { public: - InformBox(QWidget *, const QString &text, base::lambda closedCallback = base::lambda()); - InformBox(QWidget *, const QString &text, const QString &doneText, - base::lambda closedCallback = base::lambda()); + InformBox(QWidget *, const QString &text, Fn closedCallback = Fn()); + InformBox(QWidget *, const QString &text, const QString &doneText, Fn closedCallback = Fn()); }; class MaxInviteBox : public BoxContent { diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp index d72ddb527..1f921eaca 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp @@ -89,7 +89,7 @@ void SentCodeField::fix() { } } -SentCodeCall::SentCodeCall(QObject *parent, base::lambda_once callCallback, base::lambda updateCallback) +SentCodeCall::SentCodeCall(QObject *parent, FnMut callCallback, Fn updateCallback) : _timer(parent) , _call(std::move(callCallback)) , _update(std::move(updateCallback)) { diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.h b/Telegram/SourceFiles/boxes/confirm_phone_box.h index b72a34c21..8dedd6a13 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.h +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.h @@ -30,18 +30,17 @@ class FlatLabel; class SentCodeField : public Ui::InputField { public: - SentCodeField(QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory = base::lambda(), + SentCodeField(QWidget *parent, const style::InputField &st, Fn placeholderFactory = Fn(), const QString &val = QString()) : Ui::InputField(parent, st, std::move(placeholderFactory), val) { connect(this, &Ui::InputField::changed, [this] { fix(); }); } - void setAutoSubmit(int length, base::lambda submitCallback) { + void setAutoSubmit(int length, Fn submitCallback) { _autoSubmitLength = length; _submitCallback = std::move(submitCallback); } - void setChangedCallback(base::lambda changedCallback) { + void setChangedCallback(Fn changedCallback) { _changedCallback = std::move(changedCallback); } @@ -52,13 +51,13 @@ class SentCodeField : public Ui::InputField { bool _fixing = false; int _autoSubmitLength = 0; - base::lambda _submitCallback; - base::lambda _changedCallback; + Fn _submitCallback; + Fn _changedCallback; }; class SentCodeCall { public: - SentCodeCall(QObject *parent, base::lambda_once callCallback, base::lambda updateCallback); + SentCodeCall(QObject *parent, FnMut callCallback, Fn updateCallback); enum class State { Waiting, @@ -91,8 +90,8 @@ class SentCodeCall { private: Status _status; object_ptr _timer; - base::lambda_once _call; - base::lambda _update; + FnMut _call; + Fn _update; }; class ConfirmPhoneBox : public BoxContent, public RPCSender { diff --git a/Telegram/SourceFiles/boxes/edit_color_box.cpp b/Telegram/SourceFiles/boxes/edit_color_box.cpp index 4451fde63..3948d61d2 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_color_box.cpp @@ -731,7 +731,7 @@ void EditColorBox::onFieldSubmitted() { } void EditColorBox::saveColor() { - _cancelCallback = base::lambda(); + _cancelCallback = Fn(); if (_saveCallback) { _saveCallback(_new.toRgb()); } diff --git a/Telegram/SourceFiles/boxes/edit_color_box.h b/Telegram/SourceFiles/boxes/edit_color_box.h index 26740b5ab..650cdb25b 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.h +++ b/Telegram/SourceFiles/boxes/edit_color_box.h @@ -28,11 +28,11 @@ class EditColorBox : public BoxContent { public: EditColorBox(QWidget *, const QString &title, QColor current = QColor(255, 255, 255)); - void setSaveCallback(base::lambda callback) { + void setSaveCallback(Fn callback) { _saveCallback = std::move(callback); } - void setCancelCallback(base::lambda callback) { + void setCancelCallback(Fn callback) { _cancelCallback = std::move(callback); } @@ -103,6 +103,6 @@ private slots: QRect _currentRect; QRect _newRect; - base::lambda _saveCallback; - base::lambda _cancelCallback; + Fn _saveCallback; + Fn _cancelCallback; }; diff --git a/Telegram/SourceFiles/boxes/edit_participant_box.h b/Telegram/SourceFiles/boxes/edit_participant_box.h index 91107e84c..929f9bcf0 100644 --- a/Telegram/SourceFiles/boxes/edit_participant_box.h +++ b/Telegram/SourceFiles/boxes/edit_participant_box.h @@ -70,7 +70,7 @@ class EditAdminBox : public EditParticipantBox { EditAdminBox(QWidget *, not_null channel, not_null user, const MTPChannelAdminRights &rights); - void setSaveCallback(base::lambda callback) { + void setSaveCallback(Fn callback) { _saveCallback = std::move(callback); } @@ -91,7 +91,7 @@ class EditAdminBox : public EditParticipantBox { const MTPChannelAdminRights _oldRights; std::vector> _dependencies; - base::lambda _saveCallback; + Fn _saveCallback; std::map> _checkboxes; QPointer _aboutAddAdmins; @@ -105,7 +105,7 @@ class EditRestrictedBox : public EditParticipantBox { EditRestrictedBox(QWidget *, not_null channel, not_null user, bool hasAdminRights, const MTPChannelBannedRights &rights); - void setSaveCallback(base::lambda callback) { + void setSaveCallback(Fn callback) { _saveCallback = std::move(callback); } @@ -135,7 +135,7 @@ class EditRestrictedBox : public EditParticipantBox { const MTPChannelBannedRights _oldRights; TimeId _until = 0; std::vector> _dependencies; - base::lambda _saveCallback; + Fn _saveCallback; std::map> _checkboxes; diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index 292768a89..ba90b37d8 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -36,8 +36,7 @@ namespace { class PrivacyExceptionsBoxController : public ChatsListBoxController { public: - PrivacyExceptionsBoxController(base::lambda titleFactory, - const std::vector> &selected); + PrivacyExceptionsBoxController(Fn titleFactory, const std::vector> &selected); void rowClicked(not_null row) override; std::vector> getResult() const; @@ -47,11 +46,11 @@ class PrivacyExceptionsBoxController : public ChatsListBoxController { std::unique_ptr createRow(not_null history) override; private: - base::lambda _titleFactory; + Fn _titleFactory; std::vector> _selected; }; -PrivacyExceptionsBoxController::PrivacyExceptionsBoxController(base::lambda titleFactory, +PrivacyExceptionsBoxController::PrivacyExceptionsBoxController(Fn titleFactory, const std::vector> &selected) : _titleFactory(std::move(titleFactory)) , _selected(selected) {} diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.h b/Telegram/SourceFiles/boxes/edit_privacy_box.h index a6d4d8b7d..0b2a62c52 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.h +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.h @@ -59,7 +59,7 @@ class EditPrivacyBox : public BoxContent, private MTP::Sender { virtual QString exceptionBoxTitle(Exception exception) = 0; virtual QString exceptionsDescription() = 0; - virtual void confirmSave(bool someAreDisallowed, base::lambda_once saveCallback) { + virtual void confirmSave(bool someAreDisallowed, FnMut saveCallback) { saveCallback(); } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 8f980db97..16d208ea5 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -36,7 +36,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "window/themes/window_theme.h" PeerListBox::PeerListBox(QWidget *, std::unique_ptr controller, - base::lambda)> init) + Fn)> init) : _controller(std::move(controller)) , _init(std::move(init)) { Expects(_controller != nullptr); @@ -247,13 +247,13 @@ void PeerListBox::peerListSetSearchMode(PeerListSearchMode mode) { } } -void PeerListBox::peerListSortRows(base::lambda compare) { +void PeerListBox::peerListSortRows(Fn compare) { _inner->reorderRows([compare = std::move(compare)](auto &&begin, auto &&end) { std::sort(begin, end, [compare](auto &&a, auto &&b) { return compare(*a, *b); }); }); } -void PeerListBox::peerListPartitionRows(base::lambda border) { +void PeerListBox::peerListPartitionRows(Fn border) { _inner->reorderRows([border = std::move(border)](auto &&begin, auto &&end) { std::stable_partition(begin, end, [border](auto &¤t) { return border(*current); }); }); @@ -507,7 +507,7 @@ void PeerListRow::lazyInitialize() { refreshStatus(); } -void PeerListRow::createCheckbox(base::lambda updateCallback) { +void PeerListRow::createCheckbox(Fn updateCallback) { _checkbox = std::make_unique(st::contactsPhotoCheckbox, std::move(updateCallback), PaintUserpicCallback(_peer)); } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index d2664bf70..67304f375 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -85,7 +85,7 @@ class PeerListRow { virtual QMargins actionMargins() const { return QMargins(); } - virtual void addActionRipple(QPoint point, base::lambda updateCallback) {} + virtual void addActionRipple(QPoint point, Fn updateCallback) {} virtual void stopLastActionRipple() {} virtual void paintAction(Painter &p, TimeMs ms, int x, int y, int outerWidth, bool actionSelected) {} @@ -151,7 +151,7 @@ class PeerListRow { } private: - void createCheckbox(base::lambda updateCallback); + void createCheckbox(Fn updateCallback); void setCheckedInternal(bool checked, SetStyle style); void paintDisabledCheckUserpic(Painter &p, int x, int y, int outerWidth) const; void setStatusText(const QString &text); @@ -177,8 +177,8 @@ enum class PeerListSearchMode { class PeerListDelegate { public: - virtual void peerListSetTitle(base::lambda title) = 0; - virtual void peerListSetAdditionalTitle(base::lambda title) = 0; + virtual void peerListSetTitle(Fn title) = 0; + virtual void peerListSetAdditionalTitle(Fn title) = 0; virtual void peerListSetDescription(object_ptr description) = 0; virtual void peerListSetSearchLoading(object_ptr loading) = 0; virtual void peerListSetSearchNoResults(object_ptr noResults) = 0; @@ -199,8 +199,8 @@ class PeerListDelegate { virtual void peerListScrollToTop() = 0; virtual int peerListFullRowsCount() = 0; virtual PeerListRow *peerListFindRow(PeerListRowId id) = 0; - virtual void peerListSortRows(base::lambda compare) = 0; - virtual void peerListPartitionRows(base::lambda border) = 0; + virtual void peerListSortRows(Fn compare) = 0; + virtual void peerListPartitionRows(Fn border) = 0; template void peerListAddSelectedRows(PeerDataRange &&range) { for (auto peer : range) { @@ -310,13 +310,12 @@ class PeerListController : public PeerListSearchDelegate { class PeerListBox : public BoxContent, public PeerListDelegate { public: - PeerListBox(QWidget *, std::unique_ptr controller, - base::lambda)> init); + PeerListBox(QWidget *, std::unique_ptr controller, Fn)> init); - void peerListSetTitle(base::lambda title) override { + void peerListSetTitle(Fn title) override { setTitle(std::move(title)); } - void peerListSetAdditionalTitle(base::lambda title) override { + void peerListSetAdditionalTitle(Fn title) override { setAdditionalTitle(std::move(title)); } void peerListSetDescription(object_ptr description) override; @@ -341,8 +340,8 @@ class PeerListBox : public BoxContent, public PeerListDelegate { void peerListScrollToTop() override; int peerListFullRowsCount() override; PeerListRow *peerListFindRow(PeerListRowId id) override; - void peerListSortRows(base::lambda compare) override; - void peerListPartitionRows(base::lambda border) override; + void peerListSortRows(Fn compare) override; + void peerListPartitionRows(Fn border) override; protected: void prepare() override; @@ -370,7 +369,7 @@ class PeerListBox : public BoxContent, public PeerListDelegate { QPointer _inner; std::unique_ptr _controller; - base::lambda _init; + Fn _init; bool _scrollBottomFixed = true; }; diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 6c77dd5c2..01c9ab62e 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -269,7 +269,7 @@ void SendFilesBox::prepare() { updateBoxSize(); } -base::lambda SendFilesBox::getSendButtonText() const { +Fn SendFilesBox::getSendButtonText() const { if (!_contactPhone.isEmpty()) { return langFactory(lng_send_button); } else if (_compressed && _compressed->checked()) { diff --git a/Telegram/SourceFiles/boxes/send_files_box.h b/Telegram/SourceFiles/boxes/send_files_box.h index 9905764d3..e8bff8ee3 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.h +++ b/Telegram/SourceFiles/boxes/send_files_box.h @@ -38,13 +38,13 @@ class SendFilesBox : public BoxContent { SendFilesBox(QWidget *, const QStringList &files, CompressConfirm compressed); SendFilesBox(QWidget *, const QString &phone, const QString &firstname, const QString &lastname); - void setConfirmedCallback(base::lambda information, - bool compressed, const QString &caption, bool ctrlShiftEnter)> + void setConfirmedCallback(Fn information, bool compressed, + const QString &caption, bool ctrlShiftEnter)> callback) { _confirmedCallback = std::move(callback); } - void setCancelledCallback(base::lambda callback) { + void setCancelledCallback(Fn callback) { _cancelledCallback = std::move(callback); } @@ -74,7 +74,7 @@ private slots: void updateTitleText(); void updateBoxSize(); void updateControlsGeometry(); - base::lambda getSendButtonText() const; + Fn getSendButtonText() const; QString _titleText; QStringList _files; @@ -102,11 +102,10 @@ private slots: QString _contactLastName; EmptyUserpic _contactPhotoEmpty; - base::lambda information, bool compressed, - const QString &caption, bool ctrlShiftEnter)> + Fn information, + bool compressed, const QString &caption, bool ctrlShiftEnter)> _confirmedCallback; - base::lambda _cancelledCallback; + Fn _cancelledCallback; bool _confirmed = false; object_ptr _caption = {nullptr}; diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 0b1f3cccc..771496e32 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -513,7 +513,7 @@ void ShareBox::Inner::paintChat(Painter &p, TimeMs ms, Chat *chat, int index) { chat->name.drawLeftElided(p, x + nameLeft, y + nameTop, nameWidth, outerWidth, 2, style::al_top, 0, -1, 0, true); } -ShareBox::Inner::Chat::Chat(PeerData *peer, base::lambda updateCallback) +ShareBox::Inner::Chat::Chat(PeerData *peer, Fn updateCallback) : peer(peer) , checkbox(st::sharePhotoCheckbox, updateCallback, PaintUserpicCallback(peer)) , name(st::sharePhotoCheckbox.imageRadius * 2) {} @@ -649,7 +649,7 @@ void ShareBox::Inner::peerUnselected(PeerData *peer) { changePeerCheckState(chat, false, ChangeStateWay::SkipCallback); } -void ShareBox::Inner::setPeerSelectedChangedCallback(base::lambda callback) { +void ShareBox::Inner::setPeerSelectedChangedCallback(Fn callback) { _peerSelectedChangedCallback = std::move(callback); } diff --git a/Telegram/SourceFiles/boxes/share_box.h b/Telegram/SourceFiles/boxes/share_box.h index 5a82afaac..7e8e54353 100644 --- a/Telegram/SourceFiles/boxes/share_box.h +++ b/Telegram/SourceFiles/boxes/share_box.h @@ -44,9 +44,9 @@ class ShareBox : public BoxContent, public RPCSender { Q_OBJECT public: - using CopyCallback = base::lambda; - using SubmitCallback = base::lambda &)>; - using FilterCallback = base::lambda; + using CopyCallback = Fn; + using SubmitCallback = Fn &)>; + using FilterCallback = Fn; ShareBox(QWidget *, CopyCallback &©Callback, SubmitCallback &&submitCallback, FilterCallback &&filterCallback); protected: @@ -113,7 +113,7 @@ class ShareBox::Inner : public TWidget, public RPCSender, private base::Subscrib public: Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallback); - void setPeerSelectedChangedCallback(base::lambda callback); + void setPeerSelectedChangedCallback(Fn callback); void peerUnselected(PeerData *peer); QVector selected() const; @@ -152,7 +152,7 @@ public slots: int displayedChatsCount() const; struct Chat { - Chat(PeerData *peer, base::lambda updateCallback); + Chat(PeerData *peer, Fn updateCallback); PeerData *peer; Ui::RoundImageCheckbox checkbox; @@ -202,7 +202,7 @@ public slots: using SelectedChats = std::set; SelectedChats _selected; - base::lambda _peerSelectedChangedCallback; + Fn _peerSelectedChangedCallback; ChatData *data(Dialogs::Row *row); diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 3d9177718..f20a17ccc 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -440,7 +440,7 @@ bool StickerSetBox::Inner::official() const { return _loaded && _setShortName.isEmpty(); } -base::lambda StickerSetBox::Inner::title() const { +Fn StickerSetBox::Inner::title() const { auto text = TextWithEntities{_setTitle}; if (_loaded) { if (_pack.isEmpty()) { diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.h b/Telegram/SourceFiles/boxes/sticker_set_box.h index f7675cc66..6adcc7709 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.h +++ b/Telegram/SourceFiles/boxes/sticker_set_box.h @@ -69,7 +69,7 @@ class StickerSetBox::Inner : public TWidget, public RPCSender, private base::Sub bool loaded() const; qint32 notInstalled() const; bool official() const; - base::lambda title() const; + Fn title() const; QString shortName() const; void setVisibleTopBottom(int visibleTop, int visibleBottom) override; diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index 695e62196..fa44157c2 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -163,10 +163,10 @@ class StickersBox::Inner : public TWidget, private base::Subscriber, private MTP void setFullOrder(const Stickers::Order &order); void setRemovedSets(const Stickers::Order &removed); - void setInstallSetCallback(base::lambda callback) { + void setInstallSetCallback(Fn callback) { _installSetCallback = std::move(callback); } - void setLoadMoreCallback(base::lambda callback) { + void setLoadMoreCallback(Fn callback) { _loadMoreCallback = std::move(callback); } @@ -265,8 +265,8 @@ public slots: anim::value _aboveShadowFadeOpacity; BasicAnimation _a_shifting; - base::lambda _installSetCallback; - base::lambda _loadMoreCallback; + Fn _installSetCallback; + Fn _loadMoreCallback; int _visibleTop = 0; int _visibleBottom = 0; diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index 34d272ad7..b96669705 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -77,7 +77,7 @@ class BoxController::Row : public PeerListRow { } void paintStatusText(Painter &p, int x, int y, int availableWidth, int outerWidth, bool selected) override; - void addActionRipple(QPoint point, base::lambda updateCallback) override; + void addActionRipple(QPoint point, Fn updateCallback) override; void stopLastActionRipple() override; bool needsVerifiedIcon() const override { @@ -172,7 +172,7 @@ BoxController::Row::Type BoxController::Row::ComputeType(HistoryItem *item) { return Type::In; } -void BoxController::Row::addActionRipple(QPoint point, base::lambda updateCallback) { +void BoxController::Row::addActionRipple(QPoint point, Fn updateCallback) { if (!_actionRipple) { auto mask = Ui::RippleAnimation::ellipseMask(QSize(st::callReDial.rippleAreaSize, st::callReDial.rippleAreaSize)); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index e94e25dc9..d0cab7428 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -114,7 +114,7 @@ std::unique_ptr MimeDataFromTextWithEntities(const TextWithEntities & } MessageField::MessageField(QWidget *parent, not_null controller, const style::FlatTextarea &st, - base::lambda placeholderFactory, const QString &val) + Fn placeholderFactory, const QString &val) : Ui::FlatTextarea(parent, st, std::move(placeholderFactory), val) , _controller(controller) { setMinHeight(st::historySendSize.height() - 2 * st::historySendPadding); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index 593c12730..dcb52278a 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -38,12 +38,11 @@ class MessageField final : public Ui::FlatTextarea { public: MessageField(QWidget *parent, not_null controller, const style::FlatTextarea &st, - base::lambda placeholderFactory = base::lambda(), - const QString &val = QString()); + Fn placeholderFactory = Fn(), const QString &val = QString()); bool hasSendText() const; - void setInsertFromMimeDataHook(base::lambda hook) { + void setInsertFromMimeDataHook(Fn hook) { _insertFromMimeDataHook = std::move(hook); } @@ -61,5 +60,5 @@ public slots: private: not_null _controller; - base::lambda _insertFromMimeDataHook; + Fn _insertFromMimeDataHook; }; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp index cfd4f4637..e3af5bccf 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp @@ -44,8 +44,8 @@ TabbedSection::TabbedSection(QWidget *parent, not_null con _cancelledCallback(); } }); - _selector->setAfterShownCallback(base::lambda()); - _selector->setBeforeHidingCallback(base::lambda()); + _selector->setAfterShownCallback(Fn()); + _selector->setBeforeHidingCallback(Fn()); setAttribute(Qt::WA_OpaquePaintEvent, true); } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_section.h b/Telegram/SourceFiles/chat_helpers/tabbed_section.h index fb05aef32..024822abe 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_section.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_section.h @@ -33,7 +33,7 @@ class TabbedSection : public Window::AbstractSectionWidget { void beforeHiding(); void afterShown(); - void setCancelledCallback(base::lambda callback) { + void setCancelledCallback(Fn callback) { _cancelledCallback = std::move(callback); } @@ -51,7 +51,7 @@ class TabbedSection : public Window::AbstractSectionWidget { private: object_ptr _selector; - base::lambda _cancelledCallback; + Fn _cancelledCallback; }; } // namespace ChatHelpers diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 2db88e458..4bd82a049 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -77,10 +77,10 @@ class TabbedSelector : public TWidget, private base::Subscriber { return _a_slide.animating(); } - void setAfterShownCallback(base::lambda callback) { + void setAfterShownCallback(Fn callback) { _afterShownCallback = std::move(callback); } - void setBeforeHidingCallback(base::lambda callback) { + void setBeforeHidingCallback(Fn callback) { _beforeHidingCallback = std::move(callback); } @@ -195,8 +195,8 @@ private slots: std::array _tabs; SelectorTab _currentTabType = SelectorTab::Emoji; - base::lambda _afterShownCallback; - base::lambda _beforeHidingCallback; + Fn _afterShownCallback; + Fn _beforeHidingCallback; }; class TabbedSelector::Inner : public TWidget { diff --git a/Telegram/SourceFiles/core/basic_types.h b/Telegram/SourceFiles/core/basic_types.h index 58cef3778..fe0777fd5 100644 --- a/Telegram/SourceFiles/core/basic_types.h +++ b/Telegram/SourceFiles/core/basic_types.h @@ -21,16 +21,25 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "base/build_config.h" +#include "base/functors.h" +#include "base/unique_function.h" #include #include #include #include #include +#include #include #include #include -template using not_null = gsl::not_null; +namespace func = base::functors; + +using gsl::not_null; + +template using Fn = std::function; + +template using FnMut = base::unique_function; #define qsl(s) QStringLiteral(s) -#define qstr(s) QLatin1String(s, static_cast(sizeof(s) - 1)) +#define qstr(s) QLatin1String((s), static_cast(sizeof(s) - 1)) diff --git a/Telegram/SourceFiles/core/click_handler.h b/Telegram/SourceFiles/core/click_handler.h index a1c20bb57..9431d619e 100644 --- a/Telegram/SourceFiles/core/click_handler.h +++ b/Telegram/SourceFiles/core/click_handler.h @@ -22,7 +22,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include -#include "base/lambda.h" #include "core/utils.h" #include "ui/text/text_entity.h" @@ -180,7 +179,7 @@ class LeftButtonClickHandler : public ClickHandler { class LambdaClickHandler : public ClickHandler { public: - LambdaClickHandler(base::lambda handler) + LambdaClickHandler(Fn handler) : _handler(std::move(handler)) {} void onClick(Qt::MouseButton button) const override final { if (button == Qt::LeftButton && _handler) { @@ -189,5 +188,5 @@ class LambdaClickHandler : public ClickHandler { } private: - base::lambda _handler; + Fn _handler; }; diff --git a/Telegram/SourceFiles/core/file_utilities.cpp b/Telegram/SourceFiles/core/file_utilities.cpp index 41240123a..d195efb38 100644 --- a/Telegram/SourceFiles/core/file_utilities.cpp +++ b/Telegram/SourceFiles/core/file_utilities.cpp @@ -135,8 +135,8 @@ void UnsafeLaunchDefault(const QString &filepath) { namespace FileDialog { -void GetOpenPath(const QString &caption, const QString &filter, base::lambda callback, - base::lambda failed) { +void GetOpenPath(const QString &caption, const QString &filter, Fn callback, + Fn failed) { base::TaskQueue::Main().Put([caption, filter, callback = std::move(callback), failed = std::move(failed)] { auto files = QStringList(); auto remoteContent = QByteArray(); @@ -156,8 +156,8 @@ void GetOpenPath(const QString &caption, const QString &filter, base::lambda callback, - base::lambda failed) { +void GetOpenPaths(const QString &caption, const QString &filter, Fn callback, + Fn failed) { base::TaskQueue::Main().Put([caption, filter, callback = std::move(callback), failed = std::move(failed)] { auto files = QStringList(); auto remoteContent = QByteArray(); @@ -176,7 +176,7 @@ void GetOpenPaths(const QString &caption, const QString &filter, base::lambda callback, base::lambda failed) { + Fn callback, Fn failed) { base::TaskQueue::Main().Put( [caption, filter, initialPath, callback = std::move(callback), failed = std::move(failed)] { auto file = QString(); @@ -190,8 +190,8 @@ void GetWritePath(const QString &caption, const QString &filter, const QString & }); } -void GetFolder(const QString &caption, const QString &initialPath, base::lambda callback, - base::lambda failed) { +void GetFolder(const QString &caption, const QString &initialPath, Fn callback, + Fn failed) { base::TaskQueue::Main().Put([caption, initialPath, callback = std::move(callback), failed = std::move(failed)] { auto files = QStringList(); auto remoteContent = QByteArray(); diff --git a/Telegram/SourceFiles/core/file_utilities.h b/Telegram/SourceFiles/core/file_utilities.h index 2ddc3a228..459abb1d4 100644 --- a/Telegram/SourceFiles/core/file_utilities.h +++ b/Telegram/SourceFiles/core/file_utilities.h @@ -60,15 +60,14 @@ struct OpenResult { QStringList paths; QByteArray remoteContent; }; -void GetOpenPath(const QString &caption, const QString &filter, base::lambda callback, - base::lambda failed = base::lambda()); -void GetOpenPaths(const QString &caption, const QString &filter, base::lambda callback, - base::lambda failed = base::lambda()); +void GetOpenPath(const QString &caption, const QString &filter, Fn callback, + Fn failed = Fn()); +void GetOpenPaths(const QString &caption, const QString &filter, Fn callback, + Fn failed = Fn()); void GetWritePath(const QString &caption, const QString &filter, const QString &initialPath, - base::lambda callback, - base::lambda failed = base::lambda()); -void GetFolder(const QString &caption, const QString &initialPath, base::lambda callback, - base::lambda failed = base::lambda()); + Fn callback, Fn failed = Fn()); +void GetFolder(const QString &caption, const QString &initialPath, Fn callback, + Fn failed = Fn()); QString AllFilesFilter(); diff --git a/Telegram/SourceFiles/core/single_timer.cpp b/Telegram/SourceFiles/core/single_timer.cpp index 9898ba82b..46de21014 100644 --- a/Telegram/SourceFiles/core/single_timer.cpp +++ b/Telegram/SourceFiles/core/single_timer.cpp @@ -28,7 +28,7 @@ SingleTimer::SingleTimer(QObject *parent) Sandbox::connect(SIGNAL(adjustSingleTimers()), this, SLOT(adjust())); } -void SingleTimer::setTimeoutHandler(base::lambda handler) { +void SingleTimer::setTimeoutHandler(Fn handler) { if (_handler && !handler) { disconnect(this, SIGNAL(timeout()), this, SLOT(onTimeout())); } else if (handler && !_handler) { diff --git a/Telegram/SourceFiles/core/single_timer.h b/Telegram/SourceFiles/core/single_timer.h index 3f39d0ac7..ce4970bc7 100644 --- a/Telegram/SourceFiles/core/single_timer.h +++ b/Telegram/SourceFiles/core/single_timer.h @@ -35,7 +35,7 @@ class SingleTimer : public QTimer { // single shot timer with check void setSingleShot(bool); // is not available void start(); // is not available - void setTimeoutHandler(base::lambda handler); + void setTimeoutHandler(Fn handler); public slots: void start(int msec); @@ -47,5 +47,5 @@ private slots: private: TimeMs _finishing = 0; - base::lambda _handler; + Fn _handler; }; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 8237d4dde..f9497320b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -1285,11 +1285,9 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) { } _menu = new Ui::PopupMenu(nullptr); - App::main()->fillPeerMenu(_menuPeer, - [this](const QString &text, base::lambda callback) { - return _menu->addAction(text, std::move(callback)); - }, - true); + App::main()->fillPeerMenu( + _menuPeer, + [this](const QString &text, Fn callback) { return _menu->addAction(text, std::move(callback)); }, true); connect(_menu, SIGNAL(destroyed(QObject *)), this, SLOT(onMenuDestroyed(QObject *))); _menu->popup(e->globalPos()); e->accept(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index f403c1ce6..968e5f7db 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -105,7 +105,7 @@ class DialogsInner : public Ui::SplittedWidget, public RPCSender, private base:: PeerData *updateFromParentDrag(QPoint globalPos); - void setLoadMoreCallback(base::lambda callback) { + void setLoadMoreCallback(Fn callback) { _loadMoreCallback = std::move(callback); } void setVisibleTopBottom(int visibleTop, int visibleBottom) override; @@ -301,5 +301,5 @@ public slots: Ui::PopupMenu *_menu = nullptr; - base::lambda _loadMoreCallback; + Fn _loadMoreCallback; }; diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.cpp b/Telegram/SourceFiles/dialogs/dialogs_row.cpp index c0f1e9c4e..400093d65 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_row.cpp @@ -29,7 +29,7 @@ namespace Dialogs { RippleRow::RippleRow() = default; RippleRow::~RippleRow() = default; -void RippleRow::addRipple(QPoint origin, QSize size, base::lambda updateCallback) { +void RippleRow::addRipple(QPoint origin, QSize size, Fn updateCallback) { if (!_ripple) { auto mask = Ui::RippleAnimation::rectMask(size); _ripple = std::make_unique(st::dialogsRipple, std::move(mask), std::move(updateCallback)); diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.h b/Telegram/SourceFiles/dialogs/dialogs_row.h index f0fd8731d..d41d404fb 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.h +++ b/Telegram/SourceFiles/dialogs/dialogs_row.h @@ -39,7 +39,7 @@ class RippleRow { RippleRow(); ~RippleRow(); - void addRipple(QPoint origin, QSize size, base::lambda updateCallback); + void addRipple(QPoint origin, QSize size, Fn updateCallback); void stopLastRipple(); void paintRipple(Painter &p, int x, int y, int outerWidth, TimeMs ms, const QColor *colorOverride = nullptr) const; diff --git a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp index 97a403eeb..0b2c92010 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp @@ -28,8 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Dialogs { -void ShowSearchFromBox(PeerData *peer, base::lambda)> callback, - base::lambda closedCallback) { +void ShowSearchFromBox(PeerData *peer, Fn)> callback, Fn closedCallback) { auto createController = [peer, callback = std::move(callback)]() -> std::unique_ptr { if (peer) { if (auto chat = peer->asChat()) { @@ -52,8 +51,7 @@ void ShowSearchFromBox(PeerData *peer, base::lambda)> } } -ChatSearchFromController::ChatSearchFromController(not_null chat, - base::lambda)> callback) +ChatSearchFromController::ChatSearchFromController(not_null chat, Fn)> callback) : PeerListController() , _chat(chat) , _callback(std::move(callback)) {} @@ -120,7 +118,7 @@ void ChatSearchFromController::appendRow(not_null user) { } ChannelSearchFromController::ChannelSearchFromController(not_null channel, - base::lambda)> callback) + Fn)> callback) : ParticipantsBoxController(channel, ParticipantsBoxController::Role::Members) , _callback(std::move(callback)) {} diff --git a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h index 8ca25fdaf..d822f3c95 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h +++ b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h @@ -25,12 +25,11 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Dialogs { -void ShowSearchFromBox(PeerData *peer, base::lambda)> callback, - base::lambda closedCallback); +void ShowSearchFromBox(PeerData *peer, Fn)> callback, Fn closedCallback); class ChatSearchFromController : public PeerListController, protected base::Subscriber { public: - ChatSearchFromController(not_null chat, base::lambda)> callback); + ChatSearchFromController(not_null chat, Fn)> callback); void prepare() override; void rowClicked(not_null row) override; @@ -41,12 +40,12 @@ class ChatSearchFromController : public PeerListController, protected base::Subs void appendRow(not_null user); not_null _chat; - base::lambda)> _callback; + Fn)> _callback; }; class ChannelSearchFromController : public Profile::ParticipantsBoxController { public: - ChannelSearchFromController(not_null channel, base::lambda)> callback); + ChannelSearchFromController(not_null channel, Fn)> callback); void prepare() override; void rowClicked(not_null row) override; @@ -55,7 +54,7 @@ class ChannelSearchFromController : public Profile::ParticipantsBoxController { std::unique_ptr createRow(not_null user) const override; private: - base::lambda)> _callback; + Fn)> _callback; }; } // namespace Dialogs diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 8d2568c92..8d33e8ea5 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -42,7 +42,7 @@ Q_DECLARE_METATYPE(Ui::ShowWay); namespace App { namespace internal { -void CallDelayed(int duration, base::lambda_once &&lambda) { +void CallDelayed(int duration, FnMut &&lambda) { Messenger::Instance().callDelayed(duration, std::move(lambda)); } diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 33948bf3b..7236cbf29 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -40,36 +40,57 @@ class ItemBase; namespace App { namespace internal { -void CallDelayed(int duration, base::lambda_once &&lambda); +void CallDelayed(int duration, FnMut &&lambda); } // namespace internal -template -inline void CallDelayed(int duration, base::lambda_internal::guard &&guarded) { - return internal::CallDelayed(duration, [guarded = std::move(guarded)] { guarded(); }); +template +inline void CallDelayed(int duration, base::lambda_internal::guard_with_QObject &&guarded) { + return internal::CallDelayed(duration, std::move(guarded)); } -template -inline void CallDelayed(int duration, Pointer &&qobject, PointersAndLambda &&... qobjectsAndLambda) { - auto guarded = - base::lambda_guarded(std::forward(qobject), std::forward(qobjectsAndLambda)...); - return CallDelayed(duration, std::move(guarded)); +template +inline void CallDelayed(int duration, base::lambda_internal::guard_with_weak &&guarded) { + return internal::CallDelayed(duration, std::move(guarded)); } -template -inline base::lambda LambdaDelayed(int duration, PointersAndLambda &&... qobjectsAndLambda) { - auto guarded = base::lambda_guarded(std::forward(qobjectsAndLambda)...); - return [guarded = std::move(guarded), duration] { internal::CallDelayed(duration, [guarded] { guarded(); }); }; +template inline void CallDelayed(int duration, const QObject *object, Lambda &&lambda) { + return internal::CallDelayed(duration, base::lambda_guarded(object, std::forward(lambda))); } -template -inline base::lambda_once LambdaDelayedOnce(int duration, PointersAndLambda &&... qobjectsAndLambda) { - auto guarded = base::lambda_guarded(std::forward(qobjectsAndLambda)...); - return [guarded = std::move(guarded), duration]() mutable { - internal::CallDelayed(duration, [guarded = std::move(guarded)] { guarded(); }); +template +inline void CallDelayed(int duration, const base::enable_weak_from_this *object, Lambda &&lambda) { + return internal::CallDelayed(duration, base::lambda_guarded(object, std::forward(lambda))); +} + +template inline auto LambdaDelayed(int duration, const QObject *object, Lambda &&lambda) { + auto guarded = base::lambda_guarded(object, std::forward(lambda)); + return [saved = std::move(guarded), duration] { + auto copy = saved; + internal::CallDelayed(duration, std::move(copy)); + }; +} + +template +inline auto LambdaDelayed(int duration, const base::enable_weak_from_this *object, Lambda &&lambda) { + auto guarded = base::lambda_guarded(object, std::forward(lambda)); + return [saved = std::move(guarded), duration] { + auto copy = saved; + internal::CallDelayed(duration, std::move(copy)); }; } +template inline auto LambdaDelayedOnce(int duration, const QObject *object, Lambda &&lambda) { + auto guarded = base::lambda_guarded(object, std::forward(lambda)); + return [saved = std::move(guarded), duration]() mutable { internal::CallDelayed(duration, std::move(saved)); }; +} + +template +inline auto LambdaDelayedOnce(int duration, const base::enable_weak_from_this *object, Lambda &&lambda) { + auto guarded = base::lambda_guarded(object, std::forward(lambda)); + return [saved = std::move(guarded), duration]() mutable { internal::CallDelayed(duration, std::move(saved)); }; +} + void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo = 0); bool insertBotCommand(const QString &cmd); void activateBotCommand(const HistoryItem *msg, int row, int col); diff --git a/Telegram/SourceFiles/history/history_admin_log_filter.cpp b/Telegram/SourceFiles/history/history_admin_log_filter.cpp index 4ba77a24a..28f2b6bdd 100644 --- a/Telegram/SourceFiles/history/history_admin_log_filter.cpp +++ b/Telegram/SourceFiles/history/history_admin_log_filter.cpp @@ -150,7 +150,7 @@ QPoint UserCheckbox::prepareRippleStartPosition() const { class FilterBox::Inner : public TWidget, private base::Subscriber { public: Inner(QWidget *parent, not_null channel, const std::vector> &admins, - const FilterValue &filter, base::lambda changedCallback); + const FilterValue &filter, Fn changedCallback); template QPointer addRow(object_ptr widget, int marginTop) { widget->setParent(this); @@ -191,12 +191,12 @@ class FilterBox::Inner : public TWidget, private base::Subscriber { }; std::vector _rows; - base::lambda _changedCallback; + Fn _changedCallback; }; FilterBox::Inner::Inner(QWidget *parent, not_null channel, const std::vector> &admins, const FilterValue &filter, - base::lambda changedCallback) + Fn changedCallback) : TWidget(parent) , _channel(channel) , _changedCallback(std::move(changedCallback)) { @@ -365,7 +365,7 @@ void FilterBox::Inner::resizeEvent(QResizeEvent *e) { } FilterBox::FilterBox(QWidget *, not_null channel, const std::vector> &admins, - const FilterValue &filter, base::lambda saveCallback) + const FilterValue &filter, Fn saveCallback) : BoxContent() , _channel(channel) , _admins(admins) diff --git a/Telegram/SourceFiles/history/history_admin_log_filter.h b/Telegram/SourceFiles/history/history_admin_log_filter.h index 24ba5e256..26ae2d9d5 100644 --- a/Telegram/SourceFiles/history/history_admin_log_filter.h +++ b/Telegram/SourceFiles/history/history_admin_log_filter.h @@ -28,7 +28,7 @@ namespace AdminLog { class FilterBox : public BoxContent { public: FilterBox(QWidget *, not_null channel, const std::vector> &admins, - const FilterValue &filter, base::lambda saveCallback); + const FilterValue &filter, Fn saveCallback); protected: void prepare() override; @@ -40,7 +40,7 @@ class FilterBox : public BoxContent { not_null _channel; std::vector> _admins; FilterValue _initialFilter; - base::lambda _saveCallback; + Fn _saveCallback; class Inner; QPointer _inner; diff --git a/Telegram/SourceFiles/history/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/history_admin_log_inner.cpp index b9f4233f5..0282a360e 100644 --- a/Telegram/SourceFiles/history/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/history_admin_log_inner.cpp @@ -375,7 +375,7 @@ void InnerWidget::requestAdmins() { .send(); } -void InnerWidget::showFilter(base::lambda callback) { +void InnerWidget::showFilter(Fn callback) { if (_admins.empty()) { _showFilterCallback = std::move(callback); } else { diff --git a/Telegram/SourceFiles/history/history_admin_log_inner.h b/Telegram/SourceFiles/history/history_admin_log_inner.h index ca59d86df..7602f254e 100644 --- a/Telegram/SourceFiles/history/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/history_admin_log_inner.h @@ -72,7 +72,7 @@ class InnerWidget final : public TWidget, // Empty "flags" means all events. void applyFilter(FilterValue &&value); void applySearch(const QString &query); - void showFilter(base::lambda callback); + void showFilter(Fn callback); // AbstractTooltipShower interface QString tooltipText() const override; @@ -240,7 +240,7 @@ class InnerWidget final : public TWidget, QString _searchQuery; std::vector> _admins; std::vector> _adminsCanEdit; - base::lambda _showFilterCallback; + Fn _showFilterCallback; }; } // namespace AdminLog diff --git a/Telegram/SourceFiles/history/history_admin_log_item.cpp b/Telegram/SourceFiles/history/history_admin_log_item.cpp index 70ab81129..d7dab38eb 100644 --- a/Telegram/SourceFiles/history/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/history_admin_log_item.cpp @@ -271,7 +271,7 @@ TextWithEntities GenerateParticipantChangeText(not_null channel, } // namespace void GenerateItems(not_null history, LocalIdManager &idManager, const MTPDchannelAdminLogEvent &event, - base::lambda callback) { + Fn callback) { Expects(history->peer->isChannel()); auto id = event.vid.v; diff --git a/Telegram/SourceFiles/history/history_admin_log_item.h b/Telegram/SourceFiles/history/history_admin_log_item.h index 333b8d218..619519451 100644 --- a/Telegram/SourceFiles/history/history_admin_log_item.h +++ b/Telegram/SourceFiles/history/history_admin_log_item.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "core/basic_types.h" #include "core/utils.h" #include "history/history_item.h" @@ -33,7 +32,7 @@ class HistoryItemOwned; class LocalIdManager; void GenerateItems(not_null history, LocalIdManager &idManager, const MTPDchannelAdminLogEvent &event, - base::lambda callback); + Fn callback); // Smart pointer wrapper for HistoryItem* that destroys the owned item. class HistoryItemOwned { diff --git a/Telegram/SourceFiles/history/history_drag_area.h b/Telegram/SourceFiles/history/history_drag_area.h index 3fb084167..dfa139fa0 100644 --- a/Telegram/SourceFiles/history/history_drag_area.h +++ b/Telegram/SourceFiles/history/history_drag_area.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "ui/animation.h" #include "ui/twidget.h" #include @@ -40,7 +39,7 @@ class DragArea : public TWidget { void hideFast(); - void setDroppedCallback(base::lambda callback) { + void setDroppedCallback(Fn callback) { _droppedCallback = std::move(callback); } @@ -70,7 +69,7 @@ public slots: bool _hiding = false; bool _in = false; QPixmap _cache; - base::lambda _droppedCallback; + Fn _droppedCallback; Animation _a_opacity; Animation _a_in; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index ecbd9a130..48e6c1ea6 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -266,7 +266,7 @@ void FastShareMessage(not_null item) { } return false; }; - auto copyLinkCallback = canCopyLink ? base::lambda(std::move(copyCallback)) : base::lambda(); + auto copyLinkCallback = canCopyLink ? Fn(std::move(copyCallback)) : Fn(); Ui::show(Box(std::move(copyLinkCallback), std::move(submitCallback), std::move(filterCallback))); } @@ -274,7 +274,7 @@ void HistoryInitMessages() { initTextOptions(); } -base::lambda HistoryDependentItemCallback(const FullMsgId &msgId) { +Fn HistoryDependentItemCallback(const FullMsgId &msgId) { return [dependent = msgId](ChannelData *channel, MsgId msgId) { if (auto item = App::histItemById(dependent)) { item->updateDependencyItem(); diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index ff805b280..76489690e 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "core/basic_types.h" #include "history/history.h" #include "history/history_item.h" @@ -28,7 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "structs.h" void HistoryInitMessages(); -base::lambda HistoryDependentItemCallback(const FullMsgId &msgId); +Fn HistoryDependentItemCallback(const FullMsgId &msgId); MTPDmessage::Flags NewMessageFlags(not_null peer); QString GetErrorTextForForward(not_null peer, const SelectedItemSet &items); void FastShareMessage(not_null item); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index 2db3f1703..2ea5810b1 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -427,7 +427,7 @@ void Inner::refreshSwitchPmButton(const CacheEntry *entry) { _switchPmStartToken.clear(); } else { if (!_switchPmButton) { - _switchPmButton.create(this, base::lambda(), st::switchPmButton); + _switchPmButton.create(this, Fn(), st::switchPmButton); _switchPmButton->show(); _switchPmButton->setTextTransform(Ui::RoundButton::TextTransform::NoTransform); connect(_switchPmButton, SIGNAL(clicked()), this, SLOT(onSwitchPm())); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.h b/Telegram/SourceFiles/inline_bots/inline_results_widget.h index 10e996fcf..ba56d3039 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.h @@ -83,7 +83,7 @@ class Inner : public TWidget, public Context, private base::Subscriber { int countHeight(); - void setResultSelectedCallback(base::lambda callback) { + void setResultSelectedCallback(Fn callback) { _resultSelectedCallback = std::move(callback); } @@ -160,7 +160,7 @@ private slots: QTimer _previewTimer; bool _previewShown = false; - base::lambda _resultSelectedCallback; + Fn _resultSelectedCallback; }; } // namespace internal @@ -186,7 +186,7 @@ class Widget : public TWidget, private MTP::Sender { void showAnimated(); void hideAnimated(); - void setResultSelectedCallback(base::lambda callback) { + void setResultSelectedCallback(Fn callback) { _inner->setResultSelectedCallback(std::move(callback)); } diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index b12a3133e..6f6089853 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -31,7 +31,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Intro { -CodeInput::CodeInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory) +CodeInput::CodeInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory) : Ui::MaskedInputField(parent, st, std::move(placeholderFactory)) {} void CodeInput::setDigitsCountMax(int digitsCount) { @@ -163,7 +163,7 @@ void CodeWidget::updateControlsGeometry() { _callLabel->moveToLeft(contentLeft() + st::buttonRadius, linkTop); } -void CodeWidget::showCodeError(base::lambda textFactory) { +void CodeWidget::showCodeError(Fn textFactory) { if (textFactory) _code->showError(); showError(std::move(textFactory)); } diff --git a/Telegram/SourceFiles/intro/introcode.h b/Telegram/SourceFiles/intro/introcode.h index db6205e1d..ae5f3ce88 100644 --- a/Telegram/SourceFiles/intro/introcode.h +++ b/Telegram/SourceFiles/intro/introcode.h @@ -35,7 +35,7 @@ class CodeInput final : public Ui::MaskedInputField { Q_OBJECT public: - CodeInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory); + CodeInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory); void setDigitsCountMax(int digitsCount); @@ -83,7 +83,7 @@ private slots: void codeSubmitDone(const MTPauth_Authorization &result); bool codeSubmitFail(const RPCError &error); - void showCodeError(base::lambda textFactory); + void showCodeError(Fn textFactory); void callDone(const MTPauth_SentCode &v); void gotPassword(const MTPaccount_Password &result); diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index b3ee53758..932a5e1ce 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -78,7 +78,7 @@ void PhoneWidget::updateSignupGeometry() { } } -void PhoneWidget::showPhoneError(base::lambda textFactory) { +void PhoneWidget::showPhoneError(Fn textFactory) { _phone->showError(); showError(std::move(textFactory)); } diff --git a/Telegram/SourceFiles/intro/introphone.h b/Telegram/SourceFiles/intro/introphone.h index 891250e5c..00f1b5aa9 100644 --- a/Telegram/SourceFiles/intro/introphone.h +++ b/Telegram/SourceFiles/intro/introphone.h @@ -70,7 +70,7 @@ private slots: QString fullNumber() const; void stopCheck(); - void showPhoneError(base::lambda textFactory); + void showPhoneError(Fn textFactory); void hidePhoneError(); void showSignup(); diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index 2bc0f83d4..74e50a88b 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -59,7 +59,7 @@ Widget::Widget(QWidget *parent) , _back(this, object_ptr(this, st::introBackButton), st::introSlideDuration) , _settings(this, object_ptr(this, langFactory(lng_menu_settings), st::defaultBoxButton), st::introCoverDuration) - , _next(this, base::lambda(), st::introNextButton) { + , _next(this, Fn(), st::introNextButton) { auto country = Platform::SystemCountry(); if (country.isEmpty()) { country = str_const_toString(kDefaultCountry); @@ -484,7 +484,7 @@ void Widget::Step::updateLabelsPosition() { } } -void Widget::Step::setTitleText(base::lambda richTitleTextFactory) { +void Widget::Step::setTitleText(Fn richTitleTextFactory) { _titleTextFactory = std::move(richTitleTextFactory); refreshTitle(); updateLabelsPosition(); @@ -494,7 +494,7 @@ void Widget::Step::refreshTitle() { _title->setRichText(_titleTextFactory()); } -void Widget::Step::setDescriptionText(base::lambda richDescriptionTextFactory) { +void Widget::Step::setDescriptionText(Fn richDescriptionTextFactory) { _descriptionTextFactory = std::move(richDescriptionTextFactory); refreshDescription(); updateLabelsPosition(); @@ -689,7 +689,7 @@ void Widget::Step::setErrorBelowLink(bool below) { } } -void Widget::Step::showError(base::lambda textFactory) { +void Widget::Step::showError(Fn textFactory) { _errorTextFactory = std::move(textFactory); refreshError(); updateLabelsPosition(); @@ -778,11 +778,11 @@ void Widget::Step::showAnimated(Direction direction) { } } -void Widget::Step::setGoCallback(base::lambda callback) { +void Widget::Step::setGoCallback(Fn callback) { _goCallback = std::move(callback); } -void Widget::Step::setShowResetCallback(base::lambda callback) { +void Widget::Step::setShowResetCallback(Fn callback) { _showResetCallback = std::move(callback); } diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index de5ae02ab..38dba19ae 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -95,8 +95,8 @@ class Widget : public TWidget, private MTP::Sender, private base::Subscriber { setFocus(); } - void setGoCallback(base::lambda callback); - void setShowResetCallback(base::lambda callback); + void setGoCallback(Fn callback); + void setShowResetCallback(Fn callback); void prepareShowAnimated(Step *after); void showAnimated(Direction direction); @@ -117,9 +117,9 @@ class Widget : public TWidget, private MTP::Sender, private base::Subscriber { void setErrorCentered(bool centered); void setErrorBelowLink(bool below); - void showError(base::lambda textFactory); + void showError(Fn textFactory); void hideError() { - showError(base::lambda()); + showError(Fn()); } ~Step(); @@ -128,8 +128,8 @@ class Widget : public TWidget, private MTP::Sender, private base::Subscriber { void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; - void setTitleText(base::lambda richTitleTextFactory); - void setDescriptionText(base::lambda richDescriptionTextFactory); + void setTitleText(Fn richTitleTextFactory); + void setDescriptionText(Fn richDescriptionTextFactory); bool paintAnimated(Painter &p, QRect clip); void fillSentCodeData(const MTPauth_SentCodeType &type); @@ -186,17 +186,17 @@ class Widget : public TWidget, private MTP::Sender, private base::Subscriber { Data *_data = nullptr; bool _hasCover = false; - base::lambda _goCallback; - base::lambda _showResetCallback; + Fn _goCallback; + Fn _showResetCallback; object_ptr _title; - base::lambda _titleTextFactory; + Fn _titleTextFactory; object_ptr> _description; - base::lambda _descriptionTextFactory; + Fn _descriptionTextFactory; bool _errorCentered = false; bool _errorBelowLink = false; - base::lambda _errorTextFactory; + Fn _errorTextFactory; object_ptr> _error = {nullptr}; Animation _a_show; diff --git a/Telegram/SourceFiles/lang/lang_file_parser.cpp b/Telegram/SourceFiles/lang/lang_file_parser.cpp index 3f1d6cb9d..775e0810f 100644 --- a/Telegram/SourceFiles/lang/lang_file_parser.cpp +++ b/Telegram/SourceFiles/lang/lang_file_parser.cpp @@ -35,8 +35,7 @@ FileParser::FileParser(const QString &file, const std::set &request) parse(); } -FileParser::FileParser(const QByteArray &content, - base::lambda callback) +FileParser::FileParser(const QByteArray &content, Fn callback) : _content(base::parse::stripComments(content)) , _callback(std::move(callback)) { parse(); diff --git a/Telegram/SourceFiles/lang/lang_file_parser.h b/Telegram/SourceFiles/lang/lang_file_parser.h index b69841d61..96b8315e4 100644 --- a/Telegram/SourceFiles/lang/lang_file_parser.h +++ b/Telegram/SourceFiles/lang/lang_file_parser.h @@ -29,7 +29,7 @@ class FileParser { using Result = QMap; FileParser(const QString &file, const std::set &request); - FileParser(const QByteArray &content, base::lambda callback); + FileParser(const QByteArray &content, Fn callback); static QByteArray ReadFile(const QString &absolutePath, const QString &relativePath); @@ -57,7 +57,7 @@ class FileParser { const QByteArray _content; const std::set _request; - const base::lambda _callback; + const Fn _callback; Result _result; }; diff --git a/Telegram/SourceFiles/lang/lang_keys.h b/Telegram/SourceFiles/lang/lang_keys.h index 0171722a9..4c33b8352 100644 --- a/Telegram/SourceFiles/lang/lang_keys.h +++ b/Telegram/SourceFiles/lang/lang_keys.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "lang/lang_instance.h" #include @@ -28,7 +27,7 @@ inline QString lang(LangKey key) { return Lang::Current().getValue(key); } -inline base::lambda langFactory(LangKey key) { +inline Fn langFactory(LangKey key) { return [key] { return Lang::Current().getValue(key); }; } diff --git a/Telegram/SourceFiles/layerwidget.cpp b/Telegram/SourceFiles/layerwidget.cpp index 7949e2970..54be68c61 100644 --- a/Telegram/SourceFiles/layerwidget.cpp +++ b/Telegram/SourceFiles/layerwidget.cpp @@ -47,7 +47,7 @@ class LayerStackWidget::BackgroundWidget : public TWidget { BackgroundWidget(QWidget *parent) : TWidget(parent) {} - void setDoneCallback(base::lambda callback) { + void setDoneCallback(Fn callback) { _doneCallback = std::move(callback); } @@ -81,7 +81,7 @@ class LayerStackWidget::BackgroundWidget : public TWidget { QPixmap _specialLayerCache; QPixmap _layerCache; - base::lambda _doneCallback; + Fn _doneCallback; bool _wasAnimating = false; bool _inPaintEvent = false; diff --git a/Telegram/SourceFiles/layerwidget.h b/Telegram/SourceFiles/layerwidget.h index ffb9eb92d..4623d06ca 100644 --- a/Telegram/SourceFiles/layerwidget.h +++ b/Telegram/SourceFiles/layerwidget.h @@ -22,7 +22,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include -#include "base/lambda.h" #include "structs.h" #include "ui/animation.h" #include "ui/twidget.h" @@ -54,10 +53,10 @@ class LayerWidget : public TWidget { bool overlaps(const QRect &globalRect); - void setClosedCallback(base::lambda callback) { + void setClosedCallback(Fn callback) { _closedCallback = std::move(callback); } - void setResizedCallback(base::lambda callback) { + void setResizedCallback(Fn callback) { _resizedCallback = std::move(callback); } @@ -82,8 +81,8 @@ class LayerWidget : public TWidget { private: bool _closing = false; - base::lambda _closedCallback; - base::lambda _resizedCallback; + Fn _closedCallback; + Fn _resizedCallback; }; class LayerStackWidget : public TWidget { diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index a00fda0e1..1cf256502 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2265,8 +2265,7 @@ void MainWidget::scheduleViewIncrement(HistoryItem *item) { j.value().insert(item->id, true); } -void MainWidget::fillPeerMenu(PeerData *peer, - base::lambda handler)> callback, +void MainWidget::fillPeerMenu(PeerData *peer, Fn handler)> callback, bool pinToggle) { if (pinToggle) { auto isPinned = false; diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index d6b928b5c..300461690 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -368,9 +368,7 @@ class MainWidget : public TWidget, public RPCSender, private base::Subscriber { void scheduleViewIncrement(HistoryItem *item); - void fillPeerMenu(PeerData *peer, - base::lambda handler)> callback, - bool pinToggle); + void fillPeerMenu(PeerData *peer, Fn handler)> callback, bool pinToggle); void gotRangeDifference(ChannelData *channel, const MTPupdates_ChannelDifference &diff); void onSelfParticipantUpdated(ChannelData *channel); diff --git a/Telegram/SourceFiles/media/media_clip_reader.h b/Telegram/SourceFiles/media/media_clip_reader.h index 776e124ba..38072cae2 100644 --- a/Telegram/SourceFiles/media/media_clip_reader.h +++ b/Telegram/SourceFiles/media/media_clip_reader.h @@ -58,7 +58,7 @@ enum ReaderSteps { class ReaderPrivate; class Reader { public: - using Callback = base::lambda; + using Callback = Fn; enum class Mode { Gif, Video, diff --git a/Telegram/SourceFiles/media/player/media_player_button.cpp b/Telegram/SourceFiles/media/player/media_player_button.cpp index de1708447..962d2e221 100644 --- a/Telegram/SourceFiles/media/player/media_player_button.cpp +++ b/Telegram/SourceFiles/media/player/media_player_button.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Media { namespace Player { -PlayButtonLayout::PlayButtonLayout(const style::MediaPlayerButton &st, base::lambda callback) +PlayButtonLayout::PlayButtonLayout(const style::MediaPlayerButton &st, Fn callback) : _st(st) , _callback(std::move(callback)) {} diff --git a/Telegram/SourceFiles/media/player/media_player_button.h b/Telegram/SourceFiles/media/player/media_player_button.h index 1f9c14172..28b43f140 100644 --- a/Telegram/SourceFiles/media/player/media_player_button.h +++ b/Telegram/SourceFiles/media/player/media_player_button.h @@ -34,7 +34,7 @@ class PlayButtonLayout { Pause, Cancel, }; - PlayButtonLayout(const style::MediaPlayerButton &st, base::lambda callback); + PlayButtonLayout(const style::MediaPlayerButton &st, Fn callback); void setState(State state); void finishTransform(); @@ -57,7 +57,7 @@ class PlayButtonLayout { Animation _transformProgress; bool _transformBackward = false; - base::lambda _callback; + Fn _callback; }; } // namespace Player diff --git a/Telegram/SourceFiles/media/player/media_player_cover.h b/Telegram/SourceFiles/media/player/media_player_cover.h index 5acbb79bc..b8fd2bb46 100644 --- a/Telegram/SourceFiles/media/player/media_player_cover.h +++ b/Telegram/SourceFiles/media/player/media_player_cover.h @@ -46,7 +46,7 @@ class CoverWidget : public TWidget, private base::Subscriber { public: CoverWidget(QWidget *parent); - using ButtonCallback = base::lambda; + using ButtonCallback = Fn; void setPinCallback(ButtonCallback &&callback); void setCloseCallback(ButtonCallback &&callback); diff --git a/Telegram/SourceFiles/media/player/media_player_float.cpp b/Telegram/SourceFiles/media/player/media_player_float.cpp index 69bb59210..28bf5f638 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.cpp +++ b/Telegram/SourceFiles/media/player/media_player_float.cpp @@ -33,8 +33,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Media { namespace Player { -Float::Float(QWidget *parent, HistoryItem *item, base::lambda toggleCallback, - base::lambda draggedCallback) +Float::Float(QWidget *parent, HistoryItem *item, Fn toggleCallback, + Fn draggedCallback) : TWidget(parent) , _item(item) , _toggleCallback(std::move(toggleCallback)) diff --git a/Telegram/SourceFiles/media/player/media_player_float.h b/Telegram/SourceFiles/media/player/media_player_float.h index fda1e2f8a..8888c75c6 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.h +++ b/Telegram/SourceFiles/media/player/media_player_float.h @@ -35,8 +35,8 @@ namespace Player { class Float : public TWidget, private base::Subscriber { public: - Float(QWidget *parent, HistoryItem *item, base::lambda toggleCallback, - base::lambda draggedCallback); + Float(QWidget *parent, HistoryItem *item, Fn toggleCallback, + Fn draggedCallback); HistoryItem *item() const { return _item; @@ -91,7 +91,7 @@ class Float : public TWidget, private base::Subscriber { void finishDrag(bool closed); HistoryItem *_item = nullptr; - base::lambda _toggleCallback; + Fn _toggleCallback; double _opacity = 1.; @@ -102,7 +102,7 @@ class Float : public TWidget, private base::Subscriber { bool _drag = false; QPoint _dragLocalPoint; - base::lambda _draggedCallback; + Fn _draggedCallback; std::unique_ptr _roundPlayback; }; diff --git a/Telegram/SourceFiles/media/player/media_player_panel.h b/Telegram/SourceFiles/media/player/media_player_panel.h index 20622cc1a..3d4fe775c 100644 --- a/Telegram/SourceFiles/media/player/media_player_panel.h +++ b/Telegram/SourceFiles/media/player/media_player_panel.h @@ -50,7 +50,7 @@ class Panel : public TWidget { void showFromOther(); void hideFromOther(); - using ButtonCallback = base::lambda; + using ButtonCallback = Fn; void setPinCallback(ButtonCallback &&callback); void setCloseCallback(ButtonCallback &&callback); diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index 6f078f3d3..fcc4af657 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -180,7 +180,7 @@ void Widget::updateVolumeToggleIcon() { _volumeToggle->setIconOverride(icon()); } -void Widget::setCloseCallback(base::lambda callback) { +void Widget::setCloseCallback(Fn callback) { _closeCallback = std::move(callback); _close->setClickedCallback([this] { stopAndClose(); }); } diff --git a/Telegram/SourceFiles/media/player/media_player_widget.h b/Telegram/SourceFiles/media/player/media_player_widget.h index 2ce060ef7..21aaea3f6 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.h +++ b/Telegram/SourceFiles/media/player/media_player_widget.h @@ -47,7 +47,7 @@ class Widget : public TWidget, private base::Subscriber { public: Widget(QWidget *parent); - void setCloseCallback(base::lambda callback); + void setCloseCallback(Fn callback); void stopAndClose(); void setShadowGeometryToLeft(int x, int y, int w, int h); void showShadow(); @@ -103,7 +103,7 @@ class Widget : public TWidget, private base::Subscriber { // We change _voiceIsActive to false only manually or from tracksFinished(). AudioMsgId::Type _type = AudioMsgId::Type::Unknown; bool _voiceIsActive = false; - base::lambda _closeCallback; + Fn _closeCallback; bool _labelsOver = false; bool _labelsDown = false; diff --git a/Telegram/SourceFiles/media/view/media_clip_playback.h b/Telegram/SourceFiles/media/view/media_clip_playback.h index 909f621b6..d1044c095 100644 --- a/Telegram/SourceFiles/media/view/media_clip_playback.h +++ b/Telegram/SourceFiles/media/view/media_clip_playback.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "ui/animation.h" #include "ui/widgets/continuous_sliders.h" @@ -35,10 +34,10 @@ class Playback { public: Playback(); - void setValueChangedCallback(base::lambda callback) { + void setValueChangedCallback(Fn callback) { _valueChanged = std::move(callback); } - void setInLoadingStateChangedCallback(base::lambda callback) { + void setInLoadingStateChangedCallback(Fn callback) { _inLoadingStateChanged = std::move(callback); } void setValue(double value, bool animated); @@ -55,10 +54,10 @@ class Playback { // so it should be a BasicAnimation, not an Animation. anim::value a_value; BasicAnimation _a_value; - base::lambda _valueChanged; + Fn _valueChanged; bool _inLoadingState = false; - base::lambda _inLoadingStateChanged; + Fn _inLoadingStateChanged; qint64 _position = 0; qint64 _length = 0; diff --git a/Telegram/SourceFiles/messenger.h b/Telegram/SourceFiles/messenger.h index 4dca790f8..4194143b8 100644 --- a/Telegram/SourceFiles/messenger.h +++ b/Telegram/SourceFiles/messenger.h @@ -200,7 +200,7 @@ class Messenger final : public QObject, public RPCSender, private base::Subscrib void call_handleDelayedPeerUpdates(); void call_handleObservables(); - void callDelayed(int duration, base::lambda_once &&lambda) { + void callDelayed(int duration, FnMut &&lambda) { _callDelayedTimer.call(duration, std::move(lambda)); } diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index 834975542..0b3f9d984 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -97,8 +97,8 @@ class Instance::Private : private Sender { void setUpdatesHandler(RPCDoneHandlerPtr onDone); void setGlobalFailHandler(RPCFailHandlerPtr onFail); - void setStateChangedHandler(base::lambda handler); - void setSessionResetHandler(base::lambda handler); + void setStateChangedHandler(Fn handler); + void setSessionResetHandler(Fn handler); void clearGlobalHandlers(); internal::Session *getSession(ShiftedDcId shiftedDcId); @@ -185,8 +185,8 @@ class Instance::Private : private Sender { RPCCallbackClears _toClear; RPCResponseHandler _globalHandler; - base::lambda _stateChangedHandler; - base::lambda _sessionResetHandler; + Fn _stateChangedHandler; + Fn _sessionResetHandler; base::Timer _checkDelayedTimer; @@ -1277,19 +1277,19 @@ void Instance::Private::setGlobalFailHandler(RPCFailHandlerPtr onFail) { _globalHandler.onFail = onFail; } -void Instance::Private::setStateChangedHandler(base::lambda handler) { +void Instance::Private::setStateChangedHandler(Fn handler) { _stateChangedHandler = std::move(handler); } -void Instance::Private::setSessionResetHandler(base::lambda handler) { +void Instance::Private::setSessionResetHandler(Fn handler) { _sessionResetHandler = std::move(handler); } void Instance::Private::clearGlobalHandlers() { setUpdatesHandler(RPCDoneHandlerPtr()); setGlobalFailHandler(RPCFailHandlerPtr()); - setStateChangedHandler(base::lambda()); - setSessionResetHandler(base::lambda()); + setStateChangedHandler(Fn()); + setSessionResetHandler(Fn()); } void Instance::Private::prepareToDestroy() { @@ -1424,11 +1424,11 @@ void Instance::setGlobalFailHandler(RPCFailHandlerPtr onFail) { _private->setGlobalFailHandler(onFail); } -void Instance::setStateChangedHandler(base::lambda handler) { +void Instance::setStateChangedHandler(Fn handler) { _private->setStateChangedHandler(std::move(handler)); } -void Instance::setSessionResetHandler(base::lambda handler) { +void Instance::setSessionResetHandler(Fn handler) { _private->setSessionResetHandler(std::move(handler)); } diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.h b/Telegram/SourceFiles/mtproto/mtp_instance.h index 0db340277..8e7cb8005 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.h +++ b/Telegram/SourceFiles/mtproto/mtp_instance.h @@ -118,8 +118,8 @@ class Instance : public QObject { void setUpdatesHandler(RPCDoneHandlerPtr onDone); void setGlobalFailHandler(RPCFailHandlerPtr onFail); - void setStateChangedHandler(base::lambda handler); - void setSessionResetHandler(base::lambda handler); + void setStateChangedHandler(Fn handler); + void setSessionResetHandler(Fn handler); void clearGlobalHandlers(); void onStateChange(ShiftedDcId dcWithShift, qint32 state); diff --git a/Telegram/SourceFiles/mtproto/rpc_sender.h b/Telegram/SourceFiles/mtproto/rpc_sender.h index 29ca6e3a6..b1bc739e0 100644 --- a/Telegram/SourceFiles/mtproto/rpc_sender.h +++ b/Telegram/SourceFiles/mtproto/rpc_sender.h @@ -854,7 +854,7 @@ using MTPSessionResetHandler = void (*)(qint32 dcId); template class RPCHandlerImplementation : public Base { protected: - using Lambda = base::lambda_once; + using Lambda = FnMut; using Parent = RPCHandlerImplementation; public: @@ -920,7 +920,9 @@ template class RPCDoneHandlerImplementationNo : public RPCDoneHandl public: using RPCDoneHandlerImplementation::Parent::Parent; void operator()(mtpRequestId requestId, const mtpPrime *from, const mtpPrime *end) override { - return this->_handler ? this->_handler() : void(0); + if (this->_handler) { + this->_handler(); + } } }; @@ -929,41 +931,81 @@ class RPCDoneHandlerImplementationNoReq : public RPCDoneHandlerImplementation::Parent::Parent; void operator()(mtpRequestId requestId, const mtpPrime *from, const mtpPrime *end) override { - return this->_handler ? this->_handler(requestId) : void(0); + if (this->_handler) { + this->_handler(requestId); + } } }; -template -inline RPCDoneHandlerPtr rpcDone_lambda_wrap_helper(base::lambda_once lambda) { - return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationBare(std::move(lambda))); -} +template +constexpr bool rpcDone_canCallBare_v = std::is_invocable_v; -template -inline RPCDoneHandlerPtr -rpcDone_lambda_wrap_helper(base::lambda_once lambda) { - return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationBareReq(std::move(lambda))); -} +template +constexpr bool rpcDone_canCallBareReq_v = std::is_invocable_v; -template -inline RPCDoneHandlerPtr rpcDone_lambda_wrap_helper(base::lambda_once lambda) { - return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationPlain(std::move(lambda))); -} +template constexpr bool rpcDone_canCallNo_v = std::is_invocable_v; -template -inline RPCDoneHandlerPtr rpcDone_lambda_wrap_helper(base::lambda_once lambda) { - return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationReq(std::move(lambda))); -} +template constexpr bool rpcDone_canCallNoReq_v = std::is_invocable_v; -template inline RPCDoneHandlerPtr rpcDone_lambda_wrap_helper(base::lambda_once lambda) { - return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationNo(std::move(lambda))); -} +template struct rpcDone_canCallPlain : std::false_type {}; -template inline RPCDoneHandlerPtr rpcDone_lambda_wrap_helper(base::lambda_once lambda) { - return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationNoReq(std::move(lambda))); -} +template +struct rpcDone_canCallPlain : std::true_type { + using Arg = T; +}; + +template +struct rpcDone_canCallPlain : rpcDone_canCallPlain { +}; + +template constexpr bool rpcDone_canCallPlain_v = rpcDone_canCallPlain::value; -template RPCDoneHandlerPtr rpcDone(Lambda lambda) { - return rpcDone_lambda_wrap_helper(base::lambda_type(std::move(lambda))); +template struct rpcDone_canCallReq : std::false_type {}; + +template +struct rpcDone_canCallReq : std::true_type { + using Arg = T; +}; + +template +struct rpcDone_canCallReq + : rpcDone_canCallReq {}; + +template constexpr bool rpcDone_canCallReq_v = rpcDone_canCallReq::value; + +template struct rpcDone_returnType; + +template struct rpcDone_returnType { + using type = Return; +}; + +template +struct rpcDone_returnType { + using type = Return; +}; + +template using rpcDone_returnType_t = typename rpcDone_returnType::type; + +template > +RPCDoneHandlerPtr rpcDone(Lambda lambda) { + using R = rpcDone_returnType_t; + if constexpr (rpcDone_canCallBare_v) { + return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationBare(std::move(lambda))); + } else if constexpr (rpcDone_canCallBareReq_v) { + return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationBareReq(std::move(lambda))); + } else if constexpr (rpcDone_canCallNo_v) { + return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationNo(std::move(lambda))); + } else if constexpr (rpcDone_canCallNoReq_v) { + return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationNoReq(std::move(lambda))); + } else if constexpr (rpcDone_canCallPlain_v) { + using T = typename rpcDone_canCallPlain::Arg; + return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationPlain(std::move(lambda))); + } else if constexpr (rpcDone_canCallReq_v) { + using T = typename rpcDone_canCallReq::Arg; + return RPCDoneHandlerPtr(new RPCDoneHandlerImplementationReq(std::move(lambda))); + } else { + static_assert(std::is_same::value, "Unknown method."); + } } template @@ -1002,22 +1044,26 @@ class RPCFailHandlerImplementationNoReq : public RPCFailHandlerImplementation lambda) { - return RPCFailHandlerPtr(new RPCFailHandlerImplementationPlain(std::move(lambda))); -} +template constexpr bool rpcFail_canCallNo_v = std::is_invocable_v; -inline RPCFailHandlerPtr rpcFail_lambda_wrap_helper(base::lambda_once lambda) { - return RPCFailHandlerPtr(new RPCFailHandlerImplementationReq(std::move(lambda))); -} +template constexpr bool rpcFail_canCallNoReq_v = std::is_invocable_v; -inline RPCFailHandlerPtr rpcFail_lambda_wrap_helper(base::lambda_once lambda) { - return RPCFailHandlerPtr(new RPCFailHandlerImplementationNo(std::move(lambda))); -} +template constexpr bool rpcFail_canCallPlain_v = std::is_invocable_v; -inline RPCFailHandlerPtr rpcFail_lambda_wrap_helper(base::lambda_once lambda) { - return RPCFailHandlerPtr(new RPCFailHandlerImplementationNoReq(std::move(lambda))); -} +template +constexpr bool rpcFail_canCallReq_v = std::is_invocable_v; -template RPCFailHandlerPtr rpcFail(Lambda lambda) { - return rpcFail_lambda_wrap_helper(base::lambda_type(std::move(lambda))); +template > +RPCFailHandlerPtr rpcFail(Lambda lambda) { + if constexpr (rpcFail_canCallNo_v) { + return RPCFailHandlerPtr(new RPCFailHandlerImplementationNo(std::move(lambda))); + } else if constexpr (rpcFail_canCallNoReq_v) { + return RPCFailHandlerPtr(new RPCFailHandlerImplementationNoReq(std::move(lambda))); + } else if constexpr (rpcFail_canCallPlain_v) { + return RPCFailHandlerPtr(new RPCFailHandlerImplementationPlain(std::move(lambda))); + } else if constexpr (rpcFail_canCallReq_v) { + return RPCFailHandlerPtr(new RPCFailHandlerImplementationReq(std::move(lambda))); + } else { + static_assert(std::is_same::value, "Unknown method."); + } } diff --git a/Telegram/SourceFiles/mtproto/sender.h b/Telegram/SourceFiles/mtproto/sender.h index 7f3189450..1bb2c8c21 100644 --- a/Telegram/SourceFiles/mtproto/sender.h +++ b/Telegram/SourceFiles/mtproto/sender.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "base/variant.h" #include "facades.h" #include "mtproto/rpc_sender.h" @@ -38,21 +37,21 @@ class Sender { RequestBuilder &operator=(RequestBuilder &&other) = delete; protected: - using FailPlainHandler = base::lambda_once; - using FailRequestIdHandler = base::lambda_once; + using FailPlainHandler = FnMut; + using FailRequestIdHandler = FnMut; enum class FailSkipPolicy { Simple, HandleFlood, HandleAll, }; template struct DonePlainPolicy { - using Callback = base::lambda_once; + using Callback = FnMut; static void handle(Callback &&handler, mtpRequestId requestId, Response &&result) { handler(result); } }; template struct DoneRequestIdPolicy { - using Callback = base::lambda_once; + using Callback = FnMut; static void handle(Callback &&handler, mtpRequestId requestId, Response &&result) { handler(result, requestId); } @@ -84,13 +83,13 @@ class Sender { }; struct FailPlainPolicy { - using Callback = base::lambda_once; + using Callback = FnMut; static void handle(Callback &&handler, mtpRequestId requestId, const RPCError &error) { handler(error); } }; struct FailRequestIdPolicy { - using Callback = base::lambda_once; + using Callback = FnMut; static void handle(Callback &&handler, mtpRequestId requestId, const RPCError &error) { handler(error, requestId); } @@ -215,25 +214,24 @@ class Sender { return *this; } SpecificRequestBuilder & - done(base::lambda_once callback) WARN_UNUSED_RESULT { + done(FnMut callback) WARN_UNUSED_RESULT { setDoneHandler(MakeShared>( sender(), std::move(callback))); return *this; } SpecificRequestBuilder & - done(base::lambda_once callback) + done(FnMut callback) WARN_UNUSED_RESULT { setDoneHandler(MakeShared>( sender(), std::move(callback))); return *this; } - SpecificRequestBuilder & - fail(base::lambda_once callback) noexcept WARN_UNUSED_RESULT { + SpecificRequestBuilder &fail(FnMut callback) noexcept WARN_UNUSED_RESULT { setFailHandler(std::move(callback)); return *this; } - SpecificRequestBuilder &fail(base::lambda_once - callback) noexcept WARN_UNUSED_RESULT { + SpecificRequestBuilder & + fail(FnMut callback) noexcept WARN_UNUSED_RESULT { setFailHandler(std::move(callback)); return *this; } diff --git a/Telegram/SourceFiles/mtproto/special_config_request.cpp b/Telegram/SourceFiles/mtproto/special_config_request.cpp index 4598d633b..23ea0efbe 100644 --- a/Telegram/SourceFiles/mtproto/special_config_request.cpp +++ b/Telegram/SourceFiles/mtproto/special_config_request.cpp @@ -48,7 +48,7 @@ Y1hZCxdv6cs5UnW9+PWvS+WIbkh+GaWYxwIDAQAB\n\ } // namespace -SpecialConfigRequest::SpecialConfigRequest(base::lambda callback) +SpecialConfigRequest::SpecialConfigRequest(Fn callback) : _callback(std::move(callback)) { App::setProxySettings(_manager); diff --git a/Telegram/SourceFiles/mtproto/special_config_request.h b/Telegram/SourceFiles/mtproto/special_config_request.h index 2f7d55270..f7f765603 100644 --- a/Telegram/SourceFiles/mtproto/special_config_request.h +++ b/Telegram/SourceFiles/mtproto/special_config_request.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "mtproto/mtp_instance.h" #include @@ -30,7 +29,7 @@ namespace MTP { class SpecialConfigRequest : public QObject { public: - SpecialConfigRequest(base::lambda callback); + SpecialConfigRequest(Fn callback); ~SpecialConfigRequest(); @@ -42,7 +41,7 @@ class SpecialConfigRequest : public QObject { void handleResponse(const QByteArray &bytes); bool decryptSimpleConfig(const QByteArray &bytes); - base::lambda _callback; + Fn _callback; MTPhelp_ConfigSimple _simpleConfig; QNetworkAccessManager _manager; diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h index 463ef78f4..a911bb984 100644 --- a/Telegram/SourceFiles/observer_peer.h +++ b/Telegram/SourceFiles/observer_peer.h @@ -122,7 +122,7 @@ class PeerUpdatedHandler { private: PeerUpdate::Flags _events; - base::lambda _handler; + Fn _handler; }; base::Observable &PeerUpdated(); diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index f2483e175..8b9bad531 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -177,7 +177,7 @@ class PhotoVideoCheckbox { private: void startAnimation(); - base::lambda _updateCallback; + Fn _updateCallback; Ui::RoundCheckbox _check; Animation _pression; diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index eb8e65bc2..22ab2fb05 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -219,7 +219,7 @@ class ToastEventHandler : public Implements task) { + void performOnMainQueue(FnMut task) { base::TaskQueue::Main().Put([weak = _weak, task = std::move(task)]() mutable { if (auto strong = weak.lock()) { task(*strong); diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.h b/Telegram/SourceFiles/profile/profile_block_peer_list.h index 9b6e36328..1f9bc2fe5 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.h +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.h @@ -87,16 +87,16 @@ class PeerListWidget : public BlockWidget { qSort(_items.begin(), _items.end(), std::move(predicate)); } - void setPreloadMoreCallback(base::lambda callback) { + void setPreloadMoreCallback(Fn callback) { _preloadMoreCallback = std::move(callback); } - void setSelectedCallback(base::lambda callback) { + void setSelectedCallback(Fn callback) { _selectedCallback = std::move(callback); } - void setRemovedCallback(base::lambda callback) { + void setRemovedCallback(Fn callback) { _removedCallback = std::move(callback); } - void setUpdateItemCallback(base::lambda callback) { + void setUpdateItemCallback(Fn callback) { _updateItemCallback = std::move(callback); } @@ -139,10 +139,10 @@ class PeerListWidget : public BlockWidget { const style::ProfilePeerListItem &_st; - base::lambda _preloadMoreCallback; - base::lambda _selectedCallback; - base::lambda _removedCallback; - base::lambda _updateItemCallback; + Fn _preloadMoreCallback; + Fn _selectedCallback; + Fn _removedCallback; + Fn _updateItemCallback; QList _items; diff --git a/Telegram/SourceFiles/profile/profile_channel_controllers.h b/Telegram/SourceFiles/profile/profile_channel_controllers.h index b20bda1cb..b33ce83aa 100644 --- a/Telegram/SourceFiles/profile/profile_channel_controllers.h +++ b/Telegram/SourceFiles/profile/profile_channel_controllers.h @@ -147,9 +147,8 @@ class AddParticipantBoxController : public PeerListController, using Role = ParticipantsBoxController::Role; using Additional = ParticipantsBoxController::Additional; - using AdminDoneCallback = base::lambda user, const MTPChannelAdminRights &adminRights)>; - using BannedDoneCallback = - base::lambda user, const MTPChannelBannedRights &bannedRights)>; + using AdminDoneCallback = Fn user, const MTPChannelAdminRights &adminRights)>; + using BannedDoneCallback = Fn user, const MTPChannelBannedRights &bannedRights)>; AddParticipantBoxController(not_null channel, Role role, AdminDoneCallback adminDoneCallback, BannedDoneCallback bannedDoneCallback); diff --git a/Telegram/SourceFiles/profile/profile_cover.cpp b/Telegram/SourceFiles/profile/profile_cover.cpp index b7ce34196..49a65598f 100644 --- a/Telegram/SourceFiles/profile/profile_cover.cpp +++ b/Telegram/SourceFiles/profile/profile_cover.cpp @@ -473,15 +473,13 @@ void CoverWidget::clearButtons() { } } -void CoverWidget::addButton(base::lambda textFactory, const char *slot, - const style::RoundButton *replacementStyle) { +void CoverWidget::addButton(Fn textFactory, const char *slot, const style::RoundButton *replacementStyle) { auto &buttonStyle = _buttons.isEmpty() ? st::profilePrimaryButton : st::profileSecondaryButton; auto button = new Ui::RoundButton(this, std::move(textFactory), buttonStyle); connect(button, SIGNAL(clicked()), this, slot); button->show(); - auto replacement = - replacementStyle ? new Ui::RoundButton(this, base::lambda(), *replacementStyle) : nullptr; + auto replacement = replacementStyle ? new Ui::RoundButton(this, Fn(), *replacementStyle) : nullptr; if (replacement) { connect(replacement, SIGNAL(clicked()), this, slot); replacement->hide(); diff --git a/Telegram/SourceFiles/profile/profile_cover.h b/Telegram/SourceFiles/profile/profile_cover.h index e898290a5..0ada508b5 100644 --- a/Telegram/SourceFiles/profile/profile_cover.h +++ b/Telegram/SourceFiles/profile/profile_cover.h @@ -120,8 +120,7 @@ private slots: void setChannelButtons(); void clearButtons(); - void addButton(base::lambda textFactory, const char *slot, - const style::RoundButton *replacementStyle = nullptr); + void addButton(Fn textFactory, const char *slot, const style::RoundButton *replacementStyle = nullptr); void paintDivider(Painter &p); diff --git a/Telegram/SourceFiles/profile/profile_cover_drop_area.h b/Telegram/SourceFiles/profile/profile_cover_drop_area.h index ede9d4a70..dd47305cf 100644 --- a/Telegram/SourceFiles/profile/profile_cover_drop_area.h +++ b/Telegram/SourceFiles/profile/profile_cover_drop_area.h @@ -33,7 +33,7 @@ class CoverDropArea : public TWidget { void showAnimated(); - using HideFinishCallback = base::lambda; + using HideFinishCallback = Fn; void hideAnimated(HideFinishCallback &&callback); bool hiding() const { diff --git a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp index 59652b071..792958fd3 100644 --- a/Telegram/SourceFiles/profile/profile_fixed_bar.cpp +++ b/Telegram/SourceFiles/profile/profile_fixed_bar.cpp @@ -130,7 +130,7 @@ void FixedBar::setChannelActions() { } } -void FixedBar::addRightAction(RightActionType type, base::lambda textFactory, const char *slot) { +void FixedBar::addRightAction(RightActionType type, Fn textFactory, const char *slot) { if (_rightActions.size() > _currentAction) { if (_rightActions.at(_currentAction).type == type) { ++_currentAction; diff --git a/Telegram/SourceFiles/profile/profile_fixed_bar.h b/Telegram/SourceFiles/profile/profile_fixed_bar.h index a049cc51c..d6583afca 100644 --- a/Telegram/SourceFiles/profile/profile_fixed_bar.h +++ b/Telegram/SourceFiles/profile/profile_fixed_bar.h @@ -94,7 +94,7 @@ private slots: ShareContact, }; - void addRightAction(RightActionType type, base::lambda textFactory, const char *slot); + void addRightAction(RightActionType type, Fn textFactory, const char *slot); void applyHideShareContactButton(); PeerData *_peer; diff --git a/Telegram/SourceFiles/settings/settings_block_widget.cpp b/Telegram/SourceFiles/settings/settings_block_widget.cpp index 514472bf2..67e294bac 100644 --- a/Telegram/SourceFiles/settings/settings_block_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_block_widget.cpp @@ -86,7 +86,7 @@ void BlockWidget::rowHeightUpdated() { } void BlockWidget::createChildRow(object_ptr &child, style::margins &margin, const QString &text, - base::lambda callback, bool checked) { + Fn callback, bool checked) { child.create(this, text, checked, st::defaultBoxCheckbox); subscribe(child->checkedChanged, std::move(callback)); } diff --git a/Telegram/SourceFiles/settings/settings_block_widget.h b/Telegram/SourceFiles/settings/settings_block_widget.h index 5199eee02..da2a1fd96 100644 --- a/Telegram/SourceFiles/settings/settings_block_widget.h +++ b/Telegram/SourceFiles/settings/settings_block_widget.h @@ -93,7 +93,7 @@ class BlockWidget : public TWidget, protected base::Subscriber { margin.setBottom(margin.bottom() - padding.bottom()); } void createChildRow(object_ptr &child, style::margins &margin, const QString &text, - base::lambda callback, bool checked); + Fn callback, bool checked); void createChildRow(object_ptr &child, style::margins &margin, const QString &text, const char *slot, const style::LinkButton &st = st::boxLinkButton); diff --git a/Telegram/SourceFiles/settings/settings_layer.cpp b/Telegram/SourceFiles/settings/settings_layer.cpp index 88ba36f83..3821ac617 100644 --- a/Telegram/SourceFiles/settings/settings_layer.cpp +++ b/Telegram/SourceFiles/settings/settings_layer.cpp @@ -53,7 +53,7 @@ Layer::Layer() connect(_scroll, SIGNAL(scrolled()), this, SLOT(onScroll())); } -void Layer::setCloseClickHandler(base::lambda callback) { +void Layer::setCloseClickHandler(Fn callback) { _fixedBarClose->setClickedCallback(std::move(callback)); } diff --git a/Telegram/SourceFiles/settings/settings_layer.h b/Telegram/SourceFiles/settings/settings_layer.h index d6afe7585..f4817871b 100644 --- a/Telegram/SourceFiles/settings/settings_layer.h +++ b/Telegram/SourceFiles/settings/settings_layer.h @@ -49,7 +49,7 @@ class Layer : public LayerWidget { public: Layer(); - void setCloseClickHandler(base::lambda callback); + void setCloseClickHandler(Fn callback); void resizeToWidth(int newWidth, int newContentLeft); protected: diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 47a718708..93744fb79 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -38,7 +38,7 @@ class BlockUserBoxController : public ChatsListBoxController { public: void rowClicked(not_null row) override; - void setBlockUserCallback(base::lambda user)> callback) { + void setBlockUserCallback(Fn user)> callback) { _blockUserCallback = std::move(callback); } @@ -53,7 +53,7 @@ class BlockUserBoxController : public ChatsListBoxController { private: void updateIsBlocked(not_null row, UserData *user) const; - base::lambda user)> _blockUserCallback; + Fn user)> _blockUserCallback; }; void BlockUserBoxController::prepareViewHook() { @@ -271,7 +271,7 @@ QString LastSeenPrivacyController::exceptionsDescription() { return lang(lng_edit_privacy_lastseen_exceptions); } -void LastSeenPrivacyController::confirmSave(bool someAreDisallowed, base::lambda_once saveCallback) { +void LastSeenPrivacyController::confirmSave(bool someAreDisallowed, FnMut saveCallback) { if (someAreDisallowed && !Auth().data().lastSeenWarningSeen()) { auto weakBox = std::make_shared>(); auto callback = [weakBox, saveCallback = std::move(saveCallback)]() mutable { diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index 312e0e7d2..6f6e9ab17 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -62,7 +62,7 @@ class LastSeenPrivacyController : public EditPrivacyBox::Controller, private bas QString exceptionBoxTitle(Exception exception) override; QString exceptionsDescription() override; - void confirmSave(bool someAreDisallowed, base::lambda_once saveCallback) override; + void confirmSave(bool someAreDisallowed, FnMut saveCallback) override; }; class GroupsInvitePrivacyController : public EditPrivacyBox::Controller, private base::Subscriber { diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index 1f0c912a3..29e788d01 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -46,7 +46,7 @@ namespace Settings { namespace { QString SecretText; -QMap> Codes; +QMap> Codes; void fillCodes() { Codes.insert(qsl("debugmode"), [] { diff --git a/Telegram/SourceFiles/ui/abstract_button.h b/Telegram/SourceFiles/ui/abstract_button.h index da551dd90..82628a6aa 100644 --- a/Telegram/SourceFiles/ui/abstract_button.h +++ b/Telegram/SourceFiles/ui/abstract_button.h @@ -54,7 +54,7 @@ class AbstractButton : public TWidget { void setAcceptBoth(bool acceptBoth = true); - void setClickedCallback(base::lambda callback) { + void setClickedCallback(Fn callback) { _clickedCallback = std::move(callback); } @@ -107,7 +107,7 @@ class AbstractButton : public TWidget { Qt::KeyboardModifiers _modifiers; bool _enablePointerCursor = true; - base::lambda _clickedCallback; + Fn _clickedCallback; }; } // namespace Ui diff --git a/Telegram/SourceFiles/ui/animation.h b/Telegram/SourceFiles/ui/animation.h index ee136f5f2..2b9562b5c 100644 --- a/Telegram/SourceFiles/ui/animation.h +++ b/Telegram/SourceFiles/ui/animation.h @@ -30,7 +30,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include #include -#include "base/lambda.h" #include "core/basic_types.h" #include "core/utils.h" #include "mtproto/facade.h" @@ -103,7 +102,7 @@ enum Notification { namespace anim { -using transition = base::lambda; +using transition = Fn; extern transition linear; extern transition sineInOut; @@ -687,7 +686,7 @@ class Animation { anim::value value; BasicAnimation a_animation; - base::lambda updateCallback; + Fn updateCallback; double duration = 0.; anim::transition transition = anim::linear; MTP::PauseHolder pause; diff --git a/Telegram/SourceFiles/ui/effects/ripple_animation.cpp b/Telegram/SourceFiles/ui/effects/ripple_animation.cpp index 6bb459dee..42c2aa197 100644 --- a/Telegram/SourceFiles/ui/effects/ripple_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/ripple_animation.cpp @@ -199,7 +199,7 @@ void RippleAnimation::paint(QPainter &p, int x, int y, int outerWidth, TimeMs ms clearFinished(); } -QImage RippleAnimation::maskByDrawer(QSize size, bool filled, base::lambda drawer) { +QImage RippleAnimation::maskByDrawer(QSize size, bool filled, Fn drawer) { auto result = QImage(size * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor()); result.fill(filled ? QColor(255, 255, 255) : Qt::transparent); @@ -215,7 +215,7 @@ QImage RippleAnimation::maskByDrawer(QSize size, bool filled, base::lambda()); + return maskByDrawer(size, true, Fn()); } QImage RippleAnimation::roundRectMask(QSize size, int radius) { diff --git a/Telegram/SourceFiles/ui/effects/ripple_animation.h b/Telegram/SourceFiles/ui/effects/ripple_animation.h index aeec827b2..7cda19ab4 100644 --- a/Telegram/SourceFiles/ui/effects/ripple_animation.h +++ b/Telegram/SourceFiles/ui/effects/ripple_animation.h @@ -20,14 +20,13 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "styles/style_widgets.h" namespace Ui { class RippleAnimation { public: - using UpdateCallback = base::lambda; + using UpdateCallback = Fn; // White upon transparent mask, like colorizeImage(black-white-mask, white). RippleAnimation(const style::RippleAnimation &st, QImage mask, const UpdateCallback &update); @@ -44,7 +43,7 @@ class RippleAnimation { return _ripples.isEmpty(); } - static QImage maskByDrawer(QSize size, bool filled, base::lambda drawer); + static QImage maskByDrawer(QSize size, bool filled, Fn drawer); static QImage rectMask(QSize size); static QImage roundRectMask(QSize size, int radius); static QImage ellipseMask(QSize size); diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp index 6b04e2f03..65f5e66f8 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp @@ -65,7 +65,7 @@ void prepareCheckCaches(const style::RoundCheckbox *st, bool displayInactive, QP } // namespace -RoundCheckbox::RoundCheckbox(const style::RoundCheckbox &st, base::lambda updateCallback) +RoundCheckbox::RoundCheckbox(const style::RoundCheckbox &st, Fn updateCallback) : _st(st) , _updateCallback(updateCallback) {} @@ -245,7 +245,7 @@ void RoundCheckbox::prepareInactiveCache() { _inactiveCacheFg = App::pixmapFromImageInPlace(std::move(cacheFg)); } -RoundImageCheckbox::RoundImageCheckbox(const style::RoundImageCheckbox &st, base::lambda updateCallback, +RoundImageCheckbox::RoundImageCheckbox(const style::RoundImageCheckbox &st, Fn updateCallback, PaintRoundImage &&paintRoundImage) : _st(st) , _updateCallback(updateCallback) diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.h b/Telegram/SourceFiles/ui/effects/round_checkbox.h index 296e1ba47..0850a2daa 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.h +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "styles/style_widgets.h" #include "ui/animation.h" @@ -32,7 +31,7 @@ namespace Ui { class RoundCheckbox { public: - RoundCheckbox(const style::RoundCheckbox &st, base::lambda updateCallback); + RoundCheckbox(const style::RoundCheckbox &st, Fn updateCallback); void paint(Painter &p, TimeMs ms, int x, int y, int outerWidth, double masterScale = 1.); @@ -60,7 +59,7 @@ class RoundCheckbox { QRect cacheDestRect(int x, int y, double scale) const; const style::RoundCheckbox &_st; - base::lambda _updateCallback; + Fn _updateCallback; bool _checked = false; std::vector _icons; @@ -74,8 +73,8 @@ class RoundCheckbox { class RoundImageCheckbox { public: - using PaintRoundImage = base::lambda; - RoundImageCheckbox(const style::RoundImageCheckbox &st, base::lambda updateCallback, + using PaintRoundImage = Fn; + RoundImageCheckbox(const style::RoundImageCheckbox &st, Fn updateCallback, PaintRoundImage &&paintRoundImage); void paint(Painter &p, TimeMs ms, int x, int y, int outerWidth); @@ -95,7 +94,7 @@ class RoundImageCheckbox { void prepareWideCache(); const style::RoundImageCheckbox &_st; - base::lambda _updateCallback; + Fn _updateCallback; PaintRoundImage _paintRoundImage; QPixmap _wideCache; diff --git a/Telegram/SourceFiles/ui/effects/widget_fade_wrap.cpp b/Telegram/SourceFiles/ui/effects/widget_fade_wrap.cpp index 6a4648451..156fbfb7e 100644 --- a/Telegram/SourceFiles/ui/effects/widget_fade_wrap.cpp +++ b/Telegram/SourceFiles/ui/effects/widget_fade_wrap.cpp @@ -159,7 +159,7 @@ void FadeAnimation::updateCallback() { } WidgetFadeWrap::WidgetFadeWrap(QWidget *parent, object_ptr entity, int duration, - base::lambda updateCallback, bool scaled) + Fn updateCallback, bool scaled) : TWidget(parent) , _entity(std::move(entity)) , _duration(duration) @@ -178,8 +178,8 @@ void WidgetFadeWrap::installCallbacks() { _animation.setFinishedCallback([this] { _updateCallback(); }); _animation.setUpdatedCallback([this](double opacity) { _updateCallback(); }); } else { - _animation.setFinishedCallback(base::lambda()); - _animation.setUpdatedCallback(base::lambda()); + _animation.setFinishedCallback(Fn()); + _animation.setUpdatedCallback(Fn()); } } diff --git a/Telegram/SourceFiles/ui/effects/widget_fade_wrap.h b/Telegram/SourceFiles/ui/effects/widget_fade_wrap.h index 461296016..7786b2598 100644 --- a/Telegram/SourceFiles/ui/effects/widget_fade_wrap.h +++ b/Telegram/SourceFiles/ui/effects/widget_fade_wrap.h @@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once -#include "base/lambda.h" #include "base/object_ptr.h" #include "styles/style_widgets.h" #include "ui/animation.h" @@ -42,10 +41,10 @@ class FadeAnimation { bool paint(Painter &p); void refreshCache(); - using FinishedCallback = base::lambda; + using FinishedCallback = Fn; void setFinishedCallback(FinishedCallback &&callback); - using UpdatedCallback = base::lambda; + using UpdatedCallback = Fn; void setUpdatedCallback(UpdatedCallback &&callback); void show(); @@ -89,7 +88,7 @@ template class WidgetFadeWrap; template <> class WidgetFadeWrap : public TWidget { public: WidgetFadeWrap(QWidget *parent, object_ptr entity, int duration = st::widgetFadeDuration, - base::lambda updateCallback = base::lambda(), bool scaled = false); + Fn updateCallback = Fn(), bool scaled = false); void showAnimated() { toggleAnimated(true); @@ -146,7 +145,7 @@ template <> class WidgetFadeWrap : public TWidget { bool animating() const { return _animation.animating(); } - void setUpdateCallback(base::lambda callback) { + void setUpdateCallback(Fn callback) { _updateCallback = std::move(callback); installCallbacks(); } @@ -160,7 +159,7 @@ template <> class WidgetFadeWrap : public TWidget { object_ptr _entity; int _duration; - base::lambda _updateCallback; + Fn _updateCallback; FadeAnimation _animation; }; @@ -168,7 +167,7 @@ template <> class WidgetFadeWrap : public TWidget { template class WidgetFadeWrap : public WidgetFadeWrap { public: WidgetFadeWrap(QWidget *parent, object_ptr entity, int duration = st::widgetFadeDuration, - base::lambda updateCallback = base::lambda(), bool scaled = false) + Fn updateCallback = Fn(), bool scaled = false) : WidgetFadeWrap(parent, std::move(entity), duration, std::move(updateCallback), scaled) {} Widget *entity() { return static_cast(WidgetFadeWrap::entity()); @@ -181,7 +180,7 @@ template class WidgetFadeWrap : public WidgetFadeWrap template class WidgetScaledFadeWrap : public WidgetFadeWrap { public: WidgetScaledFadeWrap(QWidget *parent, object_ptr entity, int duration = st::widgetFadeDuration, - base::lambda updateCallback = base::lambda()) + Fn updateCallback = Fn()) : WidgetFadeWrap(parent, std::move(entity), duration, std::move(updateCallback), true) {} }; diff --git a/Telegram/SourceFiles/ui/effects/widget_slide_wrap.cpp b/Telegram/SourceFiles/ui/effects/widget_slide_wrap.cpp index dc7516af8..978070112 100644 --- a/Telegram/SourceFiles/ui/effects/widget_slide_wrap.cpp +++ b/Telegram/SourceFiles/ui/effects/widget_slide_wrap.cpp @@ -23,7 +23,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Ui { WidgetSlideWrap::WidgetSlideWrap(QWidget *parent, object_ptr entity, style::margins entityPadding, - base::lambda updateCallback, int duration) + Fn updateCallback, int duration) : TWidget(parent) , _entity(std::move(entity)) , _padding(entityPadding) diff --git a/Telegram/SourceFiles/ui/effects/widget_slide_wrap.h b/Telegram/SourceFiles/ui/effects/widget_slide_wrap.h index 437875354..94a777736 100644 --- a/Telegram/SourceFiles/ui/effects/widget_slide_wrap.h +++ b/Telegram/SourceFiles/ui/effects/widget_slide_wrap.h @@ -31,7 +31,7 @@ template class WidgetSlideWrap; template <> class WidgetSlideWrap : public TWidget { public: WidgetSlideWrap(QWidget *parent, object_ptr entity, style::margins entityPadding, - base::lambda updateCallback, int duration = st::widgetSlideDuration); + Fn updateCallback, int duration = st::widgetSlideDuration); void showAnimated(); void hideAnimated(); @@ -85,7 +85,7 @@ template <> class WidgetSlideWrap : public TWidget { bool _inResizeToWidth = false; style::margins _padding; int _duration; - base::lambda _updateCallback; + Fn _updateCallback; style::size _realSize; int _forceHeight = -1; @@ -95,8 +95,8 @@ template <> class WidgetSlideWrap : public TWidget { template class WidgetSlideWrap : public WidgetSlideWrap { public: - WidgetSlideWrap(QWidget *parent, object_ptr entity, style::margins entityPadding, - base::lambda updateCallback, int duration = st::widgetSlideDuration) + WidgetSlideWrap(QWidget *parent, object_ptr entity, style::margins entityPadding, Fn updateCallback, + int duration = st::widgetSlideDuration) : WidgetSlideWrap(parent, std::move(entity), entityPadding, std::move(updateCallback), duration) {} Widget *entity() { return static_cast(WidgetSlideWrap::entity()); diff --git a/Telegram/SourceFiles/ui/special_buttons.h b/Telegram/SourceFiles/ui/special_buttons.h index 82afe5235..06c822171 100644 --- a/Telegram/SourceFiles/ui/special_buttons.h +++ b/Telegram/SourceFiles/ui/special_buttons.h @@ -99,16 +99,16 @@ class SendButton : public RippleButton { void setRecordActive(bool recordActive); void finishAnimation(); - void setRecordStartCallback(base::lambda callback) { + void setRecordStartCallback(Fn callback) { _recordStartCallback = std::move(callback); } - void setRecordUpdateCallback(base::lambda callback) { + void setRecordUpdateCallback(Fn callback) { _recordUpdateCallback = std::move(callback); } - void setRecordStopCallback(base::lambda callback) { + void setRecordStopCallback(Fn callback) { _recordStopCallback = std::move(callback); } - void setRecordAnimationCallback(base::lambda callback) { + void setRecordAnimationCallback(Fn callback) { _recordAnimationCallback = std::move(callback); } @@ -136,10 +136,10 @@ class SendButton : public RippleButton { Animation _a_recordActive; bool _recording = false; - base::lambda _recordStartCallback; - base::lambda _recordStopCallback; - base::lambda _recordUpdateCallback; - base::lambda _recordAnimationCallback; + Fn _recordStartCallback; + Fn _recordStopCallback; + Fn _recordUpdateCallback; + Fn _recordAnimationCallback; }; class PeerAvatarButton : public AbstractButton { diff --git a/Telegram/SourceFiles/ui/twidget.h b/Telegram/SourceFiles/ui/twidget.h index c5476b729..ff1fc3995 100644 --- a/Telegram/SourceFiles/ui/twidget.h +++ b/Telegram/SourceFiles/ui/twidget.h @@ -21,7 +21,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "base/flags.h" -#include "base/lambda.h" #include "base/object_ptr.h" #include "styles/palette.h" #include "styles/style_basic.h" @@ -395,7 +394,7 @@ QImage myGrabImage(TWidget *target, QRect rect = QRect(), QColor bg = QColor(255 class SingleQueuedInvokation : public QObject { public: - SingleQueuedInvokation(base::lambda callback) + SingleQueuedInvokation(Fn callback) : _callback(callback) {} void call() { if (_pending.testAndSetAcquire(0, 1)) { @@ -408,7 +407,7 @@ class SingleQueuedInvokation : public QObject { } private: - base::lambda _callback; + Fn _callback; QAtomicInt _pending = {0}; }; diff --git a/Telegram/SourceFiles/ui/widgets/buttons.cpp b/Telegram/SourceFiles/ui/widgets/buttons.cpp index 789b81e3e..67caf0b89 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.cpp +++ b/Telegram/SourceFiles/ui/widgets/buttons.cpp @@ -195,9 +195,9 @@ void FlatButton::paintEvent(QPaintEvent *e) { class RoundButton::Numbers { public: - Numbers(const style::RoundButton &st, base::lambda animationCallback); + Numbers(const style::RoundButton &st, Fn animationCallback); - void setWidthChangedCallback(base::lambda callback) { + void setWidthChangedCallback(Fn callback) { _widthChangedCallback = std::move(callback); } void setText(const QString &text, int value); @@ -233,11 +233,11 @@ class RoundButton::Numbers { int _value = 0; bool _growing = false; - base::lambda _animationCallback; - base::lambda _widthChangedCallback; + Fn _animationCallback; + Fn _widthChangedCallback; }; -RoundButton::Numbers::Numbers(const style::RoundButton &st, base::lambda animationCallback) +RoundButton::Numbers::Numbers(const style::RoundButton &st, Fn animationCallback) : _st(st) , _animationCallback(std::move(animationCallback)) { for (auto ch = '0'; ch != '9'; ++ch) { @@ -354,7 +354,7 @@ void RoundButton::Numbers::paint(Painter &p, int x, int y, int outerWidth) { p.setOpacity(1.); } -RoundButton::RoundButton(QWidget *parent, base::lambda textFactory, const style::RoundButton &st) +RoundButton::RoundButton(QWidget *parent, Fn textFactory, const style::RoundButton &st) : RippleButton(parent, st.ripple) , _textFactory(std::move(textFactory)) , _st(st) { @@ -367,7 +367,7 @@ void RoundButton::setTextTransform(TextTransform transform) { refreshText(); } -void RoundButton::setText(base::lambda textFactory) { +void RoundButton::setText(Fn textFactory) { _textFactory = std::move(textFactory); refreshText(); } @@ -384,7 +384,7 @@ void RoundButton::setNumbersText(const QString &numbersText, int numbers) { refreshText(); } -void RoundButton::setWidthChangedCallback(base::lambda callback) { +void RoundButton::setWidthChangedCallback(Fn callback) { if (!_numbers) { _numbers = std::make_unique(_st, [this] { numbersAnimationCallback(); }); } diff --git a/Telegram/SourceFiles/ui/widgets/buttons.h b/Telegram/SourceFiles/ui/widgets/buttons.h index 74efbd3a4..dbec7a14b 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.h +++ b/Telegram/SourceFiles/ui/widgets/buttons.h @@ -109,9 +109,9 @@ class FlatButton : public RippleButton { class RoundButton : public RippleButton, private base::Subscriber { public: - RoundButton(QWidget *parent, base::lambda textFactory, const style::RoundButton &st); + RoundButton(QWidget *parent, Fn textFactory, const style::RoundButton &st); - void setText(base::lambda textFactory); + void setText(Fn textFactory); void setNumbersText(const QString &numbersText) { setNumbersText(numbersText, numbersText.toInt()); @@ -119,7 +119,7 @@ class RoundButton : public RippleButton, private base::Subscriber { void setNumbersText(int numbers) { setNumbersText(QString::number(numbers), numbers); } - void setWidthChangedCallback(base::lambda callback); + void setWidthChangedCallback(Fn callback); void stepNumbersAnimation(TimeMs ms); void finishNumbersAnimation(); @@ -149,7 +149,7 @@ class RoundButton : public RippleButton, private base::Subscriber { void resizeToText(); QString _text; - base::lambda _textFactory; + Fn _textFactory; int _textWidth; class Numbers; diff --git a/Telegram/SourceFiles/ui/widgets/checkbox.cpp b/Telegram/SourceFiles/ui/widgets/checkbox.cpp index 5d3b683df..6d8b5e2b9 100644 --- a/Telegram/SourceFiles/ui/widgets/checkbox.cpp +++ b/Telegram/SourceFiles/ui/widgets/checkbox.cpp @@ -39,7 +39,7 @@ TextParseOptions _checkboxOptions = { } // namespace -AbstractCheckView::AbstractCheckView(int duration, bool checked, base::lambda updateCallback) +AbstractCheckView::AbstractCheckView(int duration, bool checked, Fn updateCallback) : _duration(duration) , _checked(checked) , _updateCallback(std::move(updateCallback)) {} @@ -52,7 +52,7 @@ void AbstractCheckView::setCheckedFast(bool checked) { } } -void AbstractCheckView::setUpdateCallback(base::lambda updateCallback) { +void AbstractCheckView::setUpdateCallback(Fn updateCallback) { _updateCallback = std::move(updateCallback); if (_toggleAnimation.animating()) { _toggleAnimation.setUpdateCallback(_updateCallback); @@ -74,7 +74,7 @@ double AbstractCheckView::currentAnimationValue(TimeMs ms) { return ms ? _toggleAnimation.current(ms, _checked ? 1. : 0.) : _toggleAnimation.current(_checked ? 1. : 0.); } -ToggleView::ToggleView(const style::Toggle &st, bool checked, base::lambda updateCallback) +ToggleView::ToggleView(const style::Toggle &st, bool checked, Fn updateCallback) : AbstractCheckView(st.duration, checked, std::move(updateCallback)) , _st(&st) {} @@ -210,7 +210,7 @@ bool ToggleView::checkRippleStartPosition(QPoint position) const { return QRect(QPoint(0, 0), rippleSize()).contains(position); } -CheckView::CheckView(const style::Check &st, bool checked, base::lambda updateCallback) +CheckView::CheckView(const style::Check &st, bool checked, Fn updateCallback) : AbstractCheckView(st.duration, checked, std::move(updateCallback)) , _st(&st) {} @@ -255,7 +255,7 @@ bool CheckView::checkRippleStartPosition(QPoint position) const { return QRect(QPoint(0, 0), rippleSize()).contains(position); } -RadioView::RadioView(const style::Radio &st, bool checked, base::lambda updateCallback) +RadioView::RadioView(const style::Radio &st, bool checked, Fn updateCallback) : AbstractCheckView(st.duration, checked, std::move(updateCallback)) , _st(&st) {} diff --git a/Telegram/SourceFiles/ui/widgets/checkbox.h b/Telegram/SourceFiles/ui/widgets/checkbox.h index 60aea1ee6..c563c969a 100644 --- a/Telegram/SourceFiles/ui/widgets/checkbox.h +++ b/Telegram/SourceFiles/ui/widgets/checkbox.h @@ -28,12 +28,12 @@ namespace Ui { class AbstractCheckView { public: - AbstractCheckView(int duration, bool checked, base::lambda updateCallback); + AbstractCheckView(int duration, bool checked, Fn updateCallback); void setCheckedFast(bool checked); void setCheckedAnimated(bool checked); void finishAnimation(); - void setUpdateCallback(base::lambda updateCallback); + void setUpdateCallback(Fn updateCallback); bool checked() const { return _checked; } @@ -57,13 +57,13 @@ class AbstractCheckView { private: int _duration = 0; bool _checked = false; - base::lambda _updateCallback; + Fn _updateCallback; Animation _toggleAnimation; }; class CheckView : public AbstractCheckView { public: - CheckView(const style::Check &st, bool checked, base::lambda updateCallback); + CheckView(const style::Check &st, bool checked, Fn updateCallback); void setStyle(const style::Check &st); @@ -80,7 +80,7 @@ class CheckView : public AbstractCheckView { class RadioView : public AbstractCheckView { public: - RadioView(const style::Radio &st, bool checked, base::lambda updateCallback); + RadioView(const style::Radio &st, bool checked, Fn updateCallback); void setStyle(const style::Radio &st); @@ -97,7 +97,7 @@ class RadioView : public AbstractCheckView { class ToggleView : public AbstractCheckView { public: - ToggleView(const style::Toggle &st, bool checked, base::lambda updateCallback); + ToggleView(const style::Toggle &st, bool checked, Fn updateCallback); void setStyle(const style::Toggle &st); @@ -174,7 +174,7 @@ class RadiobuttonGroup { : _value(value) , _hasValue(true) {} - void setChangedCallback(base::lambda callback) { + void setChangedCallback(Fn callback) { _changedCallback = std::move(callback); } @@ -199,7 +199,7 @@ class RadiobuttonGroup { int _value = 0; bool _hasValue = false; - base::lambda _changedCallback; + Fn _changedCallback; std::vector _buttons; }; diff --git a/Telegram/SourceFiles/ui/widgets/continuous_sliders.h b/Telegram/SourceFiles/ui/widgets/continuous_sliders.h index 523c6cf09..d3ea5ae80 100644 --- a/Telegram/SourceFiles/ui/widgets/continuous_sliders.h +++ b/Telegram/SourceFiles/ui/widgets/continuous_sliders.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "core/single_timer.h" #include "styles/style_widgets.h" #include "ui/animation.h" @@ -48,7 +47,7 @@ class ContinuousSlider : public TWidget { return _disabled; } - using Callback = base::lambda; + using Callback = Fn; void setChangeProgressCallback(Callback &&callback) { _changeProgressCallback = std::move(callback); } diff --git a/Telegram/SourceFiles/ui/widgets/discrete_sliders.h b/Telegram/SourceFiles/ui/widgets/discrete_sliders.h index ea70e9564..9410b80ff 100644 --- a/Telegram/SourceFiles/ui/widgets/discrete_sliders.h +++ b/Telegram/SourceFiles/ui/widgets/discrete_sliders.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "styles/style_widgets.h" #include "ui/animation.h" #include "ui/twidget.h" @@ -44,7 +43,7 @@ class DiscreteSlider : public TWidget { void setActiveSection(int index); void setActiveSectionFast(int index); - using SectionActivatedCallback = base::lambda; + using SectionActivatedCallback = Fn; void setSectionActivatedCallback(SectionActivatedCallback &&callback); protected: diff --git a/Telegram/SourceFiles/ui/widgets/dropdown_menu.cpp b/Telegram/SourceFiles/ui/widgets/dropdown_menu.cpp index 9bf3465d7..10f7baee9 100644 --- a/Telegram/SourceFiles/ui/widgets/dropdown_menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/dropdown_menu.cpp @@ -64,7 +64,7 @@ QAction *DropdownMenu::addAction(const QString &text, const QObject *receiver, c return _menu->addAction(text, receiver, member, icon, iconOver); } -QAction *DropdownMenu::addAction(const QString &text, base::lambda callback, const style::icon *icon, +QAction *DropdownMenu::addAction(const QString &text, Fn callback, const style::icon *icon, const style::icon *iconOver) { return _menu->addAction(text, std::move(callback), icon, iconOver); } diff --git a/Telegram/SourceFiles/ui/widgets/dropdown_menu.h b/Telegram/SourceFiles/ui/widgets/dropdown_menu.h index 2f4cf7731..757645f19 100644 --- a/Telegram/SourceFiles/ui/widgets/dropdown_menu.h +++ b/Telegram/SourceFiles/ui/widgets/dropdown_menu.h @@ -34,12 +34,12 @@ class DropdownMenu : public InnerDropdown { QAction *addAction(const QString &text, const QObject *receiver, const char *member, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); - QAction *addAction(const QString &text, base::lambda callback, const style::icon *icon = nullptr, + QAction *addAction(const QString &text, Fn callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); QAction *addSeparator(); void clearActions(); - void setHiddenCallback(base::lambda callback) { + void setHiddenCallback(Fn callback) { _hiddenCallback = std::move(callback); } @@ -103,7 +103,7 @@ private slots: void showMenu(const QPoint &p, DropdownMenu *parent, TriggeredSource source); const style::DropdownMenu &_st; - base::lambda _hiddenCallback; + Fn _hiddenCallback; QPointer _menu; diff --git a/Telegram/SourceFiles/ui/widgets/inner_dropdown.h b/Telegram/SourceFiles/ui/widgets/inner_dropdown.h index bb9baa369..5f7b0ca05 100644 --- a/Telegram/SourceFiles/ui/widgets/inner_dropdown.h +++ b/Telegram/SourceFiles/ui/widgets/inner_dropdown.h @@ -57,13 +57,13 @@ class InnerDropdown : public TWidget { void otherEnter(); void otherLeave(); - void setShowStartCallback(base::lambda callback) { + void setShowStartCallback(Fn callback) { _showStartCallback = std::move(callback); } - void setHideStartCallback(base::lambda callback) { + void setHideStartCallback(Fn callback) { _hideStartCallback = std::move(callback); } - void setHiddenCallback(base::lambda callback) { + void setHiddenCallback(Fn callback) { _hiddenCallback = std::move(callback); } @@ -131,9 +131,9 @@ private slots: QTimer _hideTimer; bool _ignoreShowEvents = false; - base::lambda _showStartCallback; - base::lambda _hideStartCallback; - base::lambda _hiddenCallback; + Fn _showStartCallback; + Fn _hideStartCallback; + Fn _hiddenCallback; object_ptr _scroll; diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index f376ef91c..ff5137d8f 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -131,7 +131,7 @@ QString FlatTextarea::tagsMimeType() { return qsl("application/x-td-field-tags"); } -FlatTextarea::FlatTextarea(QWidget *parent, const style::FlatTextarea &st, base::lambda placeholderFactory, +FlatTextarea::FlatTextarea(QWidget *parent, const style::FlatTextarea &st, Fn placeholderFactory, const QString &v, const TagList &tags) : TWidgetHelper(parent) , _placeholderFactory(std::move(placeholderFactory)) @@ -1328,7 +1328,7 @@ void FlatTextarea::onRedoAvailable(bool avail) { if (App::wnd()) App::wnd()->updateGlobalMenu(); } -void FlatTextarea::setPlaceholder(base::lambda placeholderFactory, int afterSymbols) { +void FlatTextarea::setPlaceholder(Fn placeholderFactory, int afterSymbols) { _placeholderFactory = std::move(placeholderFactory); if (_placeholderAfterSymbols != afterSymbols) { _placeholderAfterSymbols = afterSymbols; @@ -1482,8 +1482,7 @@ void FlatTextarea::contextMenuEvent(QContextMenuEvent *e) { } } -FlatInput::FlatInput(QWidget *parent, const style::FlatInput &st, base::lambda placeholderFactory, - const QString &v) +FlatInput::FlatInput(QWidget *parent, const style::FlatInput &st, Fn placeholderFactory, const QString &v) : TWidgetHelper(v, parent) , _oldtext(v) , _placeholderFactory(std::move(placeholderFactory)) @@ -1658,7 +1657,7 @@ void FlatInput::resizeEvent(QResizeEvent *e) { return QLineEdit::resizeEvent(e); } -void FlatInput::setPlaceholder(base::lambda placeholderFactory) { +void FlatInput::setPlaceholder(Fn placeholderFactory) { _placeholderFactory = std::move(placeholderFactory); refreshPlaceholder(); } @@ -1772,8 +1771,7 @@ void FlatInput::onTextChange(const QString &text) { if (App::wnd()) App::wnd()->updateGlobalMenu(); } -InputArea::InputArea(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, - const QString &val) +InputArea::InputArea(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val) : TWidget(parent) , _st(st) , _inner(this) @@ -2522,7 +2520,7 @@ void InputArea::refreshPlaceholder() { update(); } -void InputArea::setPlaceholder(base::lambda placeholderFactory) { +void InputArea::setPlaceholder(Fn placeholderFactory) { _placeholderFactory = std::move(placeholderFactory); refreshPlaceholder(); } @@ -2542,7 +2540,7 @@ void InputArea::setErrorShown(bool error) { } } -InputField::InputField(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, +InputField::InputField(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val) : TWidget(parent) , _st(st) @@ -3306,7 +3304,7 @@ void InputField::refreshPlaceholder() { update(); } -void InputField::setPlaceholder(base::lambda placeholderFactory) { +void InputField::setPlaceholder(Fn placeholderFactory) { _placeholderFactory = std::move(placeholderFactory); refreshPlaceholder(); } @@ -3326,8 +3324,8 @@ void InputField::setErrorShown(bool error) { } } -MaskedInputField::MaskedInputField(QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory, const QString &val) +MaskedInputField::MaskedInputField(QWidget *parent, const style::InputField &st, Fn placeholderFactory, + const QString &val) : TWidgetHelper(val, parent) , _st(st) , _oldtext(val) @@ -3603,7 +3601,7 @@ void MaskedInputField::refreshPlaceholder() { update(); } -void MaskedInputField::setPlaceholder(base::lambda placeholderFactory) { +void MaskedInputField::setPlaceholder(Fn placeholderFactory) { _placeholderFactory = std::move(placeholderFactory); refreshPlaceholder(); } @@ -3926,14 +3924,13 @@ void PhonePartInput::onChooseCode(const QString &code) { startPlaceholderAnimation(); } -PasswordInput::PasswordInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, +PasswordInput::PasswordInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { setEchoMode(QLineEdit::Password); } -PortInput::PortInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, - const QString &val) +PortInput::PortInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { if (!val.toInt() || val.toInt() > 65535) { setText(QString()); @@ -3961,7 +3958,7 @@ void PortInput::correctValue(const QString &was, qint32 wasCursor, QString &now, setCorrectedText(now, nowCursor, newText, newPos); } -UsernameInput::UsernameInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, +UsernameInput::UsernameInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val, bool isLink) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { setLinkPlaceholder(isLink ? Messenger::Instance().createInternalLink(QString()) : QString()); @@ -4007,7 +4004,7 @@ void UsernameInput::correctValue(const QString &was, qint32 wasCursor, QString & setCorrectedText(now, nowCursor, now.mid(from, len), newPos); } -PhoneInput::PhoneInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, +PhoneInput::PhoneInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { QString phone(val); diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.h b/Telegram/SourceFiles/ui/widgets/input_fields.h index 73c8ab1b6..d81919ca9 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.h +++ b/Telegram/SourceFiles/ui/widgets/input_fields.h @@ -25,7 +25,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include #include -#include "base/lambda.h" #include "history/history.h" #include "styles/style_widgets.h" #include "ui/twidget.h" @@ -45,15 +44,14 @@ class FlatTextarea : public TWidgetHelper, private base::Subscriber { static TagList deserializeTagsList(QByteArray data, int textLength); static QString tagsMimeType(); - FlatTextarea(QWidget *parent, const style::FlatTextarea &st, - base::lambda placeholderFactory = base::lambda(), const QString &val = QString(), - const TagList &tags = TagList()); + FlatTextarea(QWidget *parent, const style::FlatTextarea &st, Fn placeholderFactory = Fn(), + const QString &val = QString(), const TagList &tags = TagList()); void setMaxLength(int maxLength); void setMinHeight(int minHeight); void setMaxHeight(int maxHeight); - void setPlaceholder(base::lambda placeholderFactory, int afterSymbols = 0); + void setPlaceholder(Fn placeholderFactory, int afterSymbols = 0); void updatePlaceholder(); void finishPlaceholder(); @@ -182,7 +180,7 @@ public slots: SubmitSettings _submitSettings = SubmitSettings::Enter; QString _placeholder; - base::lambda _placeholderFactory; + Fn _placeholderFactory; int _placeholderAfterSymbols = 0; bool _focused = false; bool _placeholderVisible = true; @@ -240,11 +238,11 @@ class FlatInput : public TWidgetHelper, private base::Subscriber { Q_OBJECT public: - FlatInput(QWidget *parent, const style::FlatInput &st, - base::lambda placeholderFactory = base::lambda(), const QString &val = QString()); + FlatInput(QWidget *parent, const style::FlatInput &st, Fn placeholderFactory = Fn(), + const QString &val = QString()); void updatePlaceholder(); - void setPlaceholder(base::lambda placeholderFactory); + void setPlaceholder(Fn placeholderFactory); QRect placeholderRect() const; void setTextMrg(const QMargins &textMrg); @@ -296,7 +294,7 @@ public slots: QString _oldtext; QString _placeholder; - base::lambda _placeholderFactory; + Fn _placeholderFactory; bool _customUpDown = false; @@ -324,8 +322,8 @@ class InputArea : public TWidget, private base::Subscriber { Q_OBJECT public: - InputArea(QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory = base::lambda(), const QString &val = QString()); + InputArea(QWidget *parent, const style::InputField &st, Fn placeholderFactory = Fn(), + const QString &val = QString()); void showError(); @@ -336,7 +334,7 @@ class InputArea : public TWidget, private base::Subscriber { const QString &getLastText() const { return _oldtext; } - void setPlaceholder(base::lambda placeholderFactory); + void setPlaceholder(Fn placeholderFactory); void setDisplayFocused(bool focused); void finishAnimations(); void setFocusFast() { @@ -473,7 +471,7 @@ private slots: bool _customUpDown = false; QString _placeholder; - base::lambda _placeholderFactory; + Fn _placeholderFactory; Animation _a_placeholderShifted; bool _placeholderShifted = false; QPainterPath _placeholderPath; @@ -502,8 +500,8 @@ class InputField : public TWidget, private base::Subscriber { Q_OBJECT public: - InputField(QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory = base::lambda(), const QString &val = QString()); + InputField(QWidget *parent, const style::InputField &st, Fn placeholderFactory = Fn(), + const QString &val = QString()); void setMaxLength(int maxLength) { _maxLength = maxLength; @@ -514,7 +512,7 @@ class InputField : public TWidget, private base::Subscriber { const QString &getLastText() const { return _oldtext; } - void setPlaceholder(base::lambda placeholderFactory); + void setPlaceholder(Fn placeholderFactory); void setPlaceholderHidden(bool forcePlaceholderHidden); void setDisplayFocused(bool focused); void finishAnimations(); @@ -657,7 +655,7 @@ private slots: bool _customUpDown = true; QString _placeholder; - base::lambda _placeholderFactory; + Fn _placeholderFactory; Animation _a_placeholderShifted; bool _placeholderShifted = false; QPainterPath _placeholderPath; @@ -686,8 +684,7 @@ class MaskedInputField : public TWidgetHelper, private base::Subscrib Q_OBJECT public: - MaskedInputField(QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory = base::lambda(), + MaskedInputField(QWidget *parent, const style::InputField &st, Fn placeholderFactory = Fn(), const QString &val = QString()); void showError(); @@ -701,7 +698,7 @@ class MaskedInputField : public TWidgetHelper, private base::Subscrib const QString &getLastText() const { return _oldtext; } - void setPlaceholder(base::lambda placeholderFactory); + void setPlaceholder(Fn placeholderFactory); void setPlaceholderHidden(bool forcePlaceholderHidden); void setDisplayFocused(bool focused); void finishAnimations(); @@ -790,7 +787,7 @@ public slots: bool _customUpDown = false; QString _placeholder; - base::lambda _placeholderFactory; + Fn _placeholderFactory; Animation _a_placeholderShifted; bool _placeholderShifted = false; QPainterPath _placeholderPath; @@ -862,15 +859,13 @@ public slots: class PasswordInput : public MaskedInputField { public: - PasswordInput(QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory = base::lambda(), + PasswordInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory = Fn(), const QString &val = QString()); }; class PortInput : public MaskedInputField { public: - PortInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, - const QString &val); + PortInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val); protected: void correctValue(const QString &was, int wasCursor, QString &now, int &nowCursor) override; @@ -878,8 +873,8 @@ class PortInput : public MaskedInputField { class UsernameInput : public MaskedInputField { public: - UsernameInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, - const QString &val, bool isLink); + UsernameInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val, + bool isLink); void setLinkPlaceholder(const QString &placeholder); @@ -893,8 +888,7 @@ class UsernameInput : public MaskedInputField { class PhoneInput : public MaskedInputField { public: - PhoneInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, - const QString &val); + PhoneInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val); void clearText(); diff --git a/Telegram/SourceFiles/ui/widgets/labels.h b/Telegram/SourceFiles/ui/widgets/labels.h index facb1b13b..7e42d137f 100644 --- a/Telegram/SourceFiles/ui/widgets/labels.h +++ b/Telegram/SourceFiles/ui/widgets/labels.h @@ -112,7 +112,7 @@ class FlatLabel : public TWidget, public ClickHandlerHost { void setLink(quint16 lnkIndex, const ClickHandlerPtr &lnk); - using ClickHandlerHook = base::lambda; + using ClickHandlerHook = Fn; void setClickHandlerHook(ClickHandlerHook &&hook); // ClickHandlerHost interface diff --git a/Telegram/SourceFiles/ui/widgets/menu.cpp b/Telegram/SourceFiles/ui/widgets/menu.cpp index 9c8d2eded..01c6c80e2 100644 --- a/Telegram/SourceFiles/ui/widgets/menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/menu.cpp @@ -65,7 +65,7 @@ QAction *Menu::addAction(const QString &text, const QObject *receiver, const cha return action; } -QAction *Menu::addAction(const QString &text, base::lambda callback, const style::icon *icon, +QAction *Menu::addAction(const QString &text, Fn callback, const style::icon *icon, const style::icon *iconOver) { auto action = addAction(new QAction(text, this), icon, iconOver); connect(action, &QAction::triggered, action, std::move(callback), Qt::QueuedConnection); diff --git a/Telegram/SourceFiles/ui/widgets/menu.h b/Telegram/SourceFiles/ui/widgets/menu.h index df1bfec4b..3565dc428 100644 --- a/Telegram/SourceFiles/ui/widgets/menu.h +++ b/Telegram/SourceFiles/ui/widgets/menu.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "styles/style_widgets.h" #include "ui/twidget.h" @@ -42,7 +41,7 @@ class Menu : public TWidget { QAction *addAction(const QString &text, const QObject *receiver, const char *member, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); - QAction *addAction(const QString &text, base::lambda callback, const style::icon *icon = nullptr, + QAction *addAction(const QString &text, Fn callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); QAction *addSeparator(); void clearActions(); @@ -63,33 +62,33 @@ class Menu : public TWidget { using Actions = QList; Actions &actions(); - void setResizedCallback(base::lambda callback) { + void setResizedCallback(Fn callback) { _resizedCallback = std::move(callback); } - void setActivatedCallback(base::lambda callback) { + void setActivatedCallback(Fn callback) { _activatedCallback = std::move(callback); } - void setTriggeredCallback(base::lambda callback) { + void setTriggeredCallback(Fn callback) { _triggeredCallback = std::move(callback); } - void setKeyPressDelegate(base::lambda delegate) { + void setKeyPressDelegate(Fn delegate) { _keyPressDelegate = std::move(delegate); } void handleKeyPress(int key); - void setMouseMoveDelegate(base::lambda delegate) { + void setMouseMoveDelegate(Fn delegate) { _mouseMoveDelegate = std::move(delegate); } void handleMouseMove(QPoint globalPosition); - void setMousePressDelegate(base::lambda delegate) { + void setMousePressDelegate(Fn delegate) { _mousePressDelegate = std::move(delegate); } void handleMousePress(QPoint globalPosition); - void setMouseReleaseDelegate(base::lambda delegate) { + void setMouseReleaseDelegate(Fn delegate) { _mouseReleaseDelegate = std::move(delegate); } void handleMouseRelease(QPoint globalPosition); @@ -143,13 +142,13 @@ private slots: const style::Menu &_st; - base::lambda _resizedCallback; - base::lambda _activatedCallback; - base::lambda _triggeredCallback; - base::lambda _keyPressDelegate; - base::lambda _mouseMoveDelegate; - base::lambda _mousePressDelegate; - base::lambda _mouseReleaseDelegate; + Fn _resizedCallback; + Fn _activatedCallback; + Fn _triggeredCallback; + Fn _keyPressDelegate; + Fn _mouseMoveDelegate; + Fn _mousePressDelegate; + Fn _mouseReleaseDelegate; QMenu *_wappedMenu = nullptr; Actions _actions; diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.cpp b/Telegram/SourceFiles/ui/widgets/multi_select.cpp index 44a6750aa..11586c429 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.cpp +++ b/Telegram/SourceFiles/ui/widgets/multi_select.cpp @@ -248,7 +248,7 @@ void MultiSelect::Item::setOver(bool over) { } } -MultiSelect::MultiSelect(QWidget *parent, const style::MultiSelect &st, base::lambda placeholderFactory) +MultiSelect::MultiSelect(QWidget *parent, const style::MultiSelect &st, Fn placeholderFactory) : TWidget(parent) , _st(st) , _scroll(this, _st.scroll) { @@ -299,15 +299,15 @@ void MultiSelect::scrollTo(int activeTop, int activeBottom) { } } -void MultiSelect::setQueryChangedCallback(base::lambda callback) { +void MultiSelect::setQueryChangedCallback(Fn callback) { _queryChangedCallback = std::move(callback); } -void MultiSelect::setSubmittedCallback(base::lambda callback) { +void MultiSelect::setSubmittedCallback(Fn callback) { _inner->setSubmittedCallback(std::move(callback)); } -void MultiSelect::setResizedCallback(base::lambda callback) { +void MultiSelect::setResizedCallback(Fn callback) { _resizedCallback = std::move(callback); } @@ -340,7 +340,7 @@ void MultiSelect::finishItemsBunch() { _inner->finishItemsBunch(AddItemWay::SkipAnimation); } -void MultiSelect::setItemRemovedCallback(base::lambda callback) { +void MultiSelect::setItemRemovedCallback(Fn callback) { _inner->setItemRemovedCallback(std::move(callback)); } @@ -369,7 +369,7 @@ int MultiSelect::resizeGetHeight(int newWidth) { return newHeight; } -MultiSelect::Inner::Inner(QWidget *parent, const style::MultiSelect &st, base::lambda placeholder, +MultiSelect::Inner::Inner(QWidget *parent, const style::MultiSelect &st, Fn placeholder, ScrollCallback callback) : TWidget(parent) , _st(st) @@ -418,11 +418,11 @@ void MultiSelect::Inner::clearQuery() { _field->setText(QString()); } -void MultiSelect::Inner::setQueryChangedCallback(base::lambda callback) { +void MultiSelect::Inner::setQueryChangedCallback(Fn callback) { _queryChangedCallback = std::move(callback); } -void MultiSelect::Inner::setSubmittedCallback(base::lambda callback) { +void MultiSelect::Inner::setSubmittedCallback(Fn callback) { _submittedCallback = std::move(callback); } @@ -725,11 +725,11 @@ void MultiSelect::Inner::setItemText(quint64 itemId, const QString &text) { } } -void MultiSelect::Inner::setItemRemovedCallback(base::lambda callback) { +void MultiSelect::Inner::setItemRemovedCallback(Fn callback) { _itemRemovedCallback = std::move(callback); } -void MultiSelect::Inner::setResizedCallback(base::lambda callback) { +void MultiSelect::Inner::setResizedCallback(Fn callback) { _resizedCallback = std::move(callback); } diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.h b/Telegram/SourceFiles/ui/widgets/multi_select.h index 2e95b6856..dd04c08c6 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.h +++ b/Telegram/SourceFiles/ui/widgets/multi_select.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "base/object_ptr.h" #include "styles/style_widgets.h" #include "ui/twidget.h" @@ -41,29 +40,28 @@ class ScrollArea; class MultiSelect : public TWidget { public: - MultiSelect(QWidget *parent, const style::MultiSelect &st, - base::lambda placeholderFactory = base::lambda()); + MultiSelect(QWidget *parent, const style::MultiSelect &st, Fn placeholderFactory = Fn()); QString getQuery() const; void setInnerFocus(); void clearQuery(); - void setQueryChangedCallback(base::lambda callback); - void setSubmittedCallback(base::lambda callback); - void setResizedCallback(base::lambda callback); + void setQueryChangedCallback(Fn callback); + void setSubmittedCallback(Fn callback); + void setResizedCallback(Fn callback); enum class AddItemWay { Default, SkipAnimation, }; - using PaintRoundImage = base::lambda; + using PaintRoundImage = Fn; void addItem(quint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage, AddItemWay way = AddItemWay::Default); void addItemInBunch(quint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage); void finishItemsBunch(); void setItemText(quint64 itemId, const QString &text); - void setItemRemovedCallback(base::lambda callback); + void setItemRemovedCallback(Fn callback); void removeItem(quint64 itemId); int getItemsCount() const; @@ -86,8 +84,8 @@ class MultiSelect : public TWidget { class Inner; QPointer _inner; - base::lambda _resizedCallback; - base::lambda _queryChangedCallback; + Fn _resizedCallback; + Fn _queryChangedCallback; }; // This class is hold in header because it requires Qt preprocessing. @@ -95,29 +93,28 @@ class MultiSelect::Inner : public TWidget { Q_OBJECT public: - using ScrollCallback = base::lambda; - Inner(QWidget *parent, const style::MultiSelect &st, base::lambda placeholderFactory, - ScrollCallback callback); + using ScrollCallback = Fn; + Inner(QWidget *parent, const style::MultiSelect &st, Fn placeholderFactory, ScrollCallback callback); QString getQuery() const; bool setInnerFocus(); void clearQuery(); - void setQueryChangedCallback(base::lambda callback); - void setSubmittedCallback(base::lambda callback); + void setQueryChangedCallback(Fn callback); + void setSubmittedCallback(Fn callback); void addItemInBunch(std::unique_ptr item); void finishItemsBunch(AddItemWay way); void setItemText(quint64 itemId, const QString &text); - void setItemRemovedCallback(base::lambda callback); + void setItemRemovedCallback(Fn callback); void removeItem(quint64 itemId); int getItemsCount() const; QVector getItems() const; bool hasItem(quint64 itemId) const; - void setResizedCallback(base::lambda callback); + void setResizedCallback(Fn callback); ~Inner(); @@ -183,10 +180,10 @@ private slots: int _newHeight = 0; Animation _height; - base::lambda _queryChangedCallback; - base::lambda _submittedCallback; - base::lambda _itemRemovedCallback; - base::lambda _resizedCallback; + Fn _queryChangedCallback; + Fn _submittedCallback; + Fn _itemRemovedCallback; + Fn _resizedCallback; }; @@ -213,7 +210,7 @@ class MultiSelect::Item { void setPosition(int x, int y, int outerWidth, int maxVisiblePadding); QRect paintArea(int outerWidth) const; - void setUpdateCallback(base::lambda updateCallback) { + void setUpdateCallback(Fn updateCallback) { _updateCallback = updateCallback; } void setText(const QString &text); @@ -245,7 +242,7 @@ class MultiSelect::Item { quint64 _id; struct SlideAnimation { - SlideAnimation(base::lambda updateCallback, int fromX, int toX, int y, double duration) + SlideAnimation(Fn updateCallback, int fromX, int toX, int y, double duration) : fromX(fromX) , toX(toX) , y(y) { @@ -268,7 +265,7 @@ class MultiSelect::Item { bool _overDelete = false; bool _active = false; PaintRoundImage _paintRoundImage; - base::lambda _updateCallback; + Fn _updateCallback; bool _hiding = false; }; diff --git a/Telegram/SourceFiles/ui/widgets/popup_menu.cpp b/Telegram/SourceFiles/ui/widgets/popup_menu.cpp index 2ebf7f069..f92ab4e4e 100644 --- a/Telegram/SourceFiles/ui/widgets/popup_menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/popup_menu.cpp @@ -94,7 +94,7 @@ QAction *PopupMenu::addAction(const QString &text, const QObject *receiver, cons return _menu->addAction(text, receiver, member, icon, iconOver); } -QAction *PopupMenu::addAction(const QString &text, base::lambda callback, const style::icon *icon, +QAction *PopupMenu::addAction(const QString &text, Fn callback, const style::icon *icon, const style::icon *iconOver) { return _menu->addAction(text, std::move(callback), icon, iconOver); } diff --git a/Telegram/SourceFiles/ui/widgets/popup_menu.h b/Telegram/SourceFiles/ui/widgets/popup_menu.h index c17e645c8..af2bf1f32 100644 --- a/Telegram/SourceFiles/ui/widgets/popup_menu.h +++ b/Telegram/SourceFiles/ui/widgets/popup_menu.h @@ -17,7 +17,6 @@ */ #pragma once -#include "base/lambda.h" #include "qevent.h" #include "styles/style_widgets.h" #include "ui/animation.h" @@ -33,7 +32,7 @@ class PopupMenu : public TWidget { QAction *addAction(const QString &text, const QObject *receiver, const char *member, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); - QAction *addAction(const QString &text, base::lambda callback, const style::icon *icon = nullptr, + QAction *addAction(const QString &text, Fn callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); QAction *addSeparator(); void clearActions(); @@ -45,7 +44,7 @@ class PopupMenu : public TWidget { void popup(const QPoint &p); void hideMenu(bool fast = false); - void setDestroyedCallback(base::lambda callback) { + void setDestroyedCallback(Fn callback) { _destroyedCallback = std::move(callback); } @@ -139,7 +138,7 @@ class PopupMenu : public TWidget { bool _triggering = false; bool _deleteLater = false; - base::lambda _destroyedCallback; + Fn _destroyedCallback; }; } // namespace Ui diff --git a/Telegram/SourceFiles/ui/widgets/tooltip.h b/Telegram/SourceFiles/ui/widgets/tooltip.h index b0b2324ff..bbf5e1a90 100644 --- a/Telegram/SourceFiles/ui/widgets/tooltip.h +++ b/Telegram/SourceFiles/ui/widgets/tooltip.h @@ -86,7 +86,7 @@ class ImportantTooltip : public TWidget { void toggleFast(bool visible); void hideAfter(TimeMs timeout); - void setHiddenCallback(base::lambda callback) { + void setHiddenCallback(Fn callback) { _hiddenCallback = std::move(callback); } @@ -112,7 +112,7 @@ class ImportantTooltip : public TWidget { Animation _visibleAnimation; bool _visible = false; - base::lambda _hiddenCallback; + Fn _hiddenCallback; bool _useTransparency = true; QPixmap _cache; }; diff --git a/Telegram/SourceFiles/window/player_wrap_widget.cpp b/Telegram/SourceFiles/window/player_wrap_widget.cpp index d50db6d00..2e2e03d78 100644 --- a/Telegram/SourceFiles/window/player_wrap_widget.cpp +++ b/Telegram/SourceFiles/window/player_wrap_widget.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace Window { -PlayerWrapWidget::PlayerWrapWidget(QWidget *parent, base::lambda updateCallback) +PlayerWrapWidget::PlayerWrapWidget(QWidget *parent, Fn updateCallback) : Parent(parent, object_ptr(parent), style::margins(0, 0, 0, 0), std::move(updateCallback)) { } diff --git a/Telegram/SourceFiles/window/player_wrap_widget.h b/Telegram/SourceFiles/window/player_wrap_widget.h index b47954e77..1a0c8a0ec 100644 --- a/Telegram/SourceFiles/window/player_wrap_widget.h +++ b/Telegram/SourceFiles/window/player_wrap_widget.h @@ -13,7 +13,7 @@ class PlayerWrapWidget : public Ui::WidgetSlideWrap { using Parent = Ui::WidgetSlideWrap; public: - PlayerWrapWidget(QWidget *parent, base::lambda updateCallback); + PlayerWrapWidget(QWidget *parent, Fn updateCallback); void updateAdaptiveLayout() { updateShadowGeometry(); diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 9158ba88b..3b4d507a2 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -859,8 +859,7 @@ bool CopyColorsToPalette(const QString &path, const QByteArray &themeContent) { return true; } -bool ReadPaletteValues(const QByteArray &content, - base::lambda callback) { +bool ReadPaletteValues(const QByteArray &content, Fn callback) { if (content.size() > kThemeSchemeSizeLimit) { LOG(("Theme Error: color scheme file too large (should be less than 1 MB, got %2)").arg(content.size())); return false; diff --git a/Telegram/SourceFiles/window/themes/window_theme.h b/Telegram/SourceFiles/window/themes/window_theme.h index c01cf97e6..8ec8867a5 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -152,7 +152,7 @@ void ComputeBackgroundRects(QRect wholeFill, QSize imageSize, QRect &to, QRect & bool CopyColorsToPalette(const QString &path, const QByteArray &themeContent); -bool ReadPaletteValues(const QByteArray &content, base::lambda callback); +bool ReadPaletteValues(const QByteArray &content, Fn callback); } // namespace Theme } // namespace Window diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index 6cac4d86b..501b2178b 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -213,19 +213,19 @@ class Editor::Inner : public TWidget, private base::Subscriber { public: Inner(QWidget *parent, const QString &path); - void setErrorCallback(base::lambda callback) { + void setErrorCallback(Fn callback) { _errorCallback = std::move(callback); } - void setFocusCallback(base::lambda callback) { + void setFocusCallback(Fn callback) { _focusCallback = std::move(callback); } - void setScrollCallback(base::lambda callback) { + void setScrollCallback(Fn callback) { _scrollCallback = std::move(callback); } void prepare(); - base::lambda exportCallback(); + Fn exportCallback(); void filterRows(const QString &query); void chooseRow(); @@ -257,9 +257,9 @@ class Editor::Inner : public TWidget, private base::Subscriber { QString _path; QByteArray _paletteContent; - base::lambda _errorCallback; - base::lambda _focusCallback; - base::lambda _scrollCallback; + Fn _errorCallback; + Fn _focusCallback; + Fn _scrollCallback; object_ptr _existingRows; object_ptr _newRows; @@ -334,7 +334,7 @@ void Editor::Inner::prepare() { } } -base::lambda Editor::Inner::exportCallback() { +Fn Editor::Inner::exportCallback() { return App::LambdaDelayed(st::defaultRippleAnimation.hideDuration, this, [this] { auto background = Background()->pixmap().toImage(); auto backgroundContent = QByteArray(); diff --git a/Telegram/SourceFiles/window/themes/window_theme_warning.h b/Telegram/SourceFiles/window/themes/window_theme_warning.h index c85ebed87..aa2844e53 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_warning.h +++ b/Telegram/SourceFiles/window/themes/window_theme_warning.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "base/object_ptr.h" #include "core/single_timer.h" #include "ui/twidget.h" @@ -39,7 +38,7 @@ class WarningWidget : public TWidget { public: WarningWidget(QWidget *parent); - void setHiddenCallback(base::lambda callback) { + void setHiddenCallback(Fn callback) { _hiddenCallback = std::move(callback); } @@ -72,7 +71,7 @@ class WarningWidget : public TWidget { object_ptr _keepChanges; object_ptr _revert; - base::lambda _hiddenCallback; + Fn _hiddenCallback; }; } // namespace Theme diff --git a/Telegram/SourceFiles/window/top_bar_widget.cpp b/Telegram/SourceFiles/window/top_bar_widget.cpp index 105f771df..df9fd2892 100644 --- a/Telegram/SourceFiles/window/top_bar_widget.cpp +++ b/Telegram/SourceFiles/window/top_bar_widget.cpp @@ -157,7 +157,7 @@ void TopBarWidget::showMenu() { })); _menuToggle->installEventFilter(_menu); App::main()->fillPeerMenu(peer, - [this](const QString &text, base::lambda callback) { + [this](const QString &text, Fn callback) { return _menu->addAction(text, std::move(callback)); }, false); diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index 9da08fc4c..0f7757a3e 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "base/timer.h" #include "ui/twidget.h" diff --git a/Telegram/SourceFiles/window/window_slide_animation.h b/Telegram/SourceFiles/window/window_slide_animation.h index 96e9a829f..ad25f937f 100644 --- a/Telegram/SourceFiles/window/window_slide_animation.h +++ b/Telegram/SourceFiles/window/window_slide_animation.h @@ -20,7 +20,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once -#include "base/lambda.h" #include "ui/animation.h" #include "ui/twidget.h" #include @@ -40,10 +39,10 @@ class SlideAnimation { void setPixmaps(const QPixmap &oldContentCache, const QPixmap &newContentCache); void setTopBarShadow(bool enabled); - using RepaintCallback = base::lambda; + using RepaintCallback = Fn; void setRepaintCallback(RepaintCallback &&callback); - using FinishedCallback = base::lambda; + using FinishedCallback = Fn; void setFinishedCallback(FinishedCallback &&callback); void start();