From dd81f5d59fa6ca40e26c1b3862bf6f8a5b5206f5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 4 Jun 2018 18:35:11 +0300 Subject: [PATCH] Replace base::lambda with shorter term. base::lambda -> Fn (type alias for std::function). base::lambda_once -> FnMut (type alias for base::unique_function). base::lambda_guarded -> crl::guard. base::lambda_call_type_t -> crl::deduced_call_type. --- Telegram/SourceFiles/apiwrap.cpp | 20 +- Telegram/SourceFiles/apiwrap.h | 24 +- Telegram/SourceFiles/app.cpp | 4 +- Telegram/SourceFiles/app.h | 4 +- Telegram/SourceFiles/base/lambda.h | 487 ------------------ Telegram/SourceFiles/base/lambda_guard.h | 114 ---- Telegram/SourceFiles/base/observer.h | 6 +- Telegram/SourceFiles/base/timer.cpp | 6 +- Telegram/SourceFiles/base/timer.h | 15 +- Telegram/SourceFiles/base/unique_function.h | 6 +- Telegram/SourceFiles/boxes/abstract_box.cpp | 16 +- Telegram/SourceFiles/boxes/abstract_box.h | 34 +- .../SourceFiles/boxes/add_contact_box.cpp | 14 +- Telegram/SourceFiles/boxes/add_contact_box.h | 4 +- Telegram/SourceFiles/boxes/background_box.cpp | 4 +- Telegram/SourceFiles/boxes/calendar_box.cpp | 6 +- Telegram/SourceFiles/boxes/calendar_box.h | 4 +- .../SourceFiles/boxes/change_phone_box.cpp | 8 +- Telegram/SourceFiles/boxes/confirm_box.cpp | 26 +- Telegram/SourceFiles/boxes/confirm_box.h | 32 +- .../SourceFiles/boxes/confirm_phone_box.cpp | 2 +- .../SourceFiles/boxes/confirm_phone_box.h | 18 +- Telegram/SourceFiles/boxes/connection_box.cpp | 14 +- .../SourceFiles/boxes/download_path_box.cpp | 2 +- Telegram/SourceFiles/boxes/edit_color_box.cpp | 2 +- Telegram/SourceFiles/boxes/edit_color_box.h | 8 +- .../SourceFiles/boxes/edit_participant_box.h | 8 +- .../SourceFiles/boxes/edit_privacy_box.cpp | 12 +- Telegram/SourceFiles/boxes/edit_privacy_box.h | 2 +- Telegram/SourceFiles/boxes/passcode_box.cpp | 4 +- Telegram/SourceFiles/boxes/peer_list_box.cpp | 6 +- Telegram/SourceFiles/boxes/peer_list_box.h | 26 +- .../boxes/peer_list_controllers.cpp | 2 +- .../SourceFiles/boxes/peer_list_controllers.h | 4 +- .../boxes/peers/edit_peer_info_box.cpp | 20 +- .../boxes/peers/manage_peer_box.cpp | 2 +- Telegram/SourceFiles/boxes/send_files_box.cpp | 6 +- Telegram/SourceFiles/boxes/send_files_box.h | 8 +- Telegram/SourceFiles/boxes/sessions_box.cpp | 4 +- Telegram/SourceFiles/boxes/share_box.cpp | 4 +- Telegram/SourceFiles/boxes/share_box.h | 12 +- .../SourceFiles/boxes/sticker_set_box.cpp | 2 +- Telegram/SourceFiles/boxes/sticker_set_box.h | 2 +- Telegram/SourceFiles/boxes/stickers_box.h | 8 +- .../calls/calls_box_controller.cpp | 4 +- Telegram/SourceFiles/calls/calls_panel.cpp | 2 +- Telegram/SourceFiles/calls/calls_panel.h | 4 +- .../chat_helpers/emoji_suggestions_widget.cpp | 2 +- .../chat_helpers/emoji_suggestions_widget.h | 4 +- .../chat_helpers/message_field.cpp | 10 +- .../SourceFiles/chat_helpers/message_field.h | 2 +- .../chat_helpers/stickers_list_widget.cpp | 8 +- .../chat_helpers/tabbed_section.cpp | 10 +- .../SourceFiles/chat_helpers/tabbed_section.h | 12 +- .../chat_helpers/tabbed_selector.h | 8 +- Telegram/SourceFiles/core/basic_types.h | 14 +- Telegram/SourceFiles/core/changelogs.cpp | 2 +- Telegram/SourceFiles/core/click_handler.h | 4 +- Telegram/SourceFiles/core/event_filter.cpp | 4 +- Telegram/SourceFiles/core/event_filter.h | 6 +- Telegram/SourceFiles/core/file_utilities.cpp | 16 +- Telegram/SourceFiles/core/file_utilities.h | 16 +- Telegram/SourceFiles/core/single_timer.cpp | 2 +- Telegram/SourceFiles/core/single_timer.h | 4 +- Telegram/SourceFiles/core/update_checker.cpp | 29 +- Telegram/SourceFiles/data/data_sparse_ids.cpp | 2 +- Telegram/SourceFiles/data/data_sparse_ids.h | 2 +- .../dialogs/dialogs_inner_widget.cpp | 4 +- .../dialogs/dialogs_inner_widget.h | 4 +- Telegram/SourceFiles/dialogs/dialogs_row.cpp | 2 +- Telegram/SourceFiles/dialogs/dialogs_row.h | 2 +- .../dialogs_search_from_controllers.cpp | 8 +- .../dialogs/dialogs_search_from_controllers.h | 12 +- .../SourceFiles/dialogs/dialogs_widget.cpp | 4 +- Telegram/SourceFiles/facades.cpp | 2 +- Telegram/SourceFiles/facades.h | 89 +--- .../admin_log/history_admin_log_filter.cpp | 8 +- .../admin_log/history_admin_log_filter.h | 4 +- .../admin_log/history_admin_log_inner.cpp | 4 +- .../admin_log/history_admin_log_inner.h | 4 +- .../admin_log/history_admin_log_item.cpp | 2 +- .../admin_log/history_admin_log_item.h | 2 +- .../SourceFiles/history/history_drag_area.h | 4 +- .../history/history_inner_widget.cpp | 2 +- .../SourceFiles/history/history_message.cpp | 6 +- .../SourceFiles/history/history_message.h | 2 +- .../SourceFiles/history/history_widget.cpp | 16 +- .../view/history_view_context_menu.cpp | 4 +- .../view/history_view_top_bar_widget.cpp | 6 +- .../info_common_groups_inner_widget.cpp | 4 +- .../info_common_groups_inner_widget.h | 4 +- .../info/feed/info_feed_channels.cpp | 4 +- .../info/feed/info_feed_channels.h | 4 +- .../feed/info_feed_channels_controllers.cpp | 2 +- Telegram/SourceFiles/info/info_top_bar.h | 2 +- .../SourceFiles/info/info_wrap_widget.cpp | 2 +- .../info/media/info_media_list_widget.cpp | 14 +- .../info/profile/info_profile_cover.cpp | 4 +- .../info/profile/info_profile_members.cpp | 4 +- .../info/profile/info_profile_members.h | 4 +- .../inline_bots/inline_results_widget.cpp | 2 +- .../inline_bots/inline_results_widget.h | 6 +- Telegram/SourceFiles/intro/introcode.cpp | 4 +- Telegram/SourceFiles/intro/introcode.h | 4 +- Telegram/SourceFiles/intro/introphone.cpp | 2 +- Telegram/SourceFiles/intro/introphone.h | 2 +- Telegram/SourceFiles/intro/intropwdcheck.cpp | 2 +- Telegram/SourceFiles/intro/introsignup.cpp | 2 +- Telegram/SourceFiles/intro/introwidget.cpp | 36 +- Telegram/SourceFiles/intro/introwidget.h | 38 +- .../SourceFiles/lang/lang_file_parser.cpp | 2 +- Telegram/SourceFiles/lang/lang_file_parser.h | 4 +- Telegram/SourceFiles/lang/lang_keys.h | 2 +- Telegram/SourceFiles/mainwidget.cpp | 14 +- .../SourceFiles/media/media_clip_reader.h | 2 +- .../media/player/media_player_button.cpp | 2 +- .../media/player/media_player_button.h | 4 +- .../media/player/media_player_cover.h | 2 +- .../media/player/media_player_float.cpp | 4 +- .../media/player/media_player_float.h | 8 +- .../media/player/media_player_panel.h | 2 +- .../media/player/media_player_widget.cpp | 2 +- .../media/player/media_player_widget.h | 4 +- .../media/view/media_clip_playback.h | 8 +- .../media/view/media_view_group_thumbs.cpp | 4 +- Telegram/SourceFiles/mediaview.cpp | 4 +- Telegram/SourceFiles/messenger.h | 2 +- Telegram/SourceFiles/mtproto/mtp_instance.cpp | 20 +- Telegram/SourceFiles/mtproto/mtp_instance.h | 4 +- Telegram/SourceFiles/mtproto/rpc_sender.h | 6 +- Telegram/SourceFiles/mtproto/sender.h | 20 +- .../mtproto/special_config_request.cpp | 10 +- .../mtproto/special_config_request.h | 8 +- Telegram/SourceFiles/observer_peer.h | 2 +- .../SourceFiles/overview/overview_layout.cpp | 2 +- .../passport/passport_form_controller.cpp | 2 +- .../passport/passport_form_controller.h | 4 +- .../passport/passport_form_view_controller.h | 2 +- .../passport/passport_panel_controller.cpp | 6 +- .../passport/passport_panel_controller.h | 8 +- .../passport/passport_panel_details_row.cpp | 4 +- .../passport/passport_panel_edit_contact.cpp | 14 +- .../passport/passport_panel_edit_contact.h | 12 +- .../passport/passport_panel_edit_document.cpp | 26 +- .../passport/passport_panel_edit_document.h | 10 +- .../passport/passport_panel_edit_scans.cpp | 8 +- .../passport/passport_panel_edit_scans.h | 4 +- .../linux/notifications_manager_linux.cpp | 2 +- .../platform/mac/main_window_mac.mm | 4 +- .../win/notifications_manager_win.cpp | 2 +- .../profile/profile_block_group_members.cpp | 8 +- .../profile/profile_block_peer_list.cpp | 2 +- .../profile/profile_block_peer_list.h | 16 +- .../profile/profile_channel_controllers.cpp | 8 +- .../profile/profile_channel_controllers.h | 10 +- .../profile/profile_cover_drop_area.h | 2 +- Telegram/SourceFiles/rpl/lifetime.h | 4 +- Telegram/SourceFiles/rpl/operators_tests.cpp | 6 +- Telegram/SourceFiles/rpl/producer.h | 6 +- Telegram/SourceFiles/rpl/producer_tests.cpp | 6 +- .../settings/settings_advanced_widget.cpp | 4 +- .../settings/settings_background_widget.cpp | 2 +- .../settings/settings_block_widget.cpp | 2 +- .../settings/settings_block_widget.h | 2 +- .../settings_chat_settings_widget.cpp | 2 +- .../SourceFiles/settings/settings_cover.cpp | 2 +- .../settings/settings_inner_widget.h | 2 +- .../SourceFiles/settings/settings_layer.cpp | 2 +- .../SourceFiles/settings/settings_layer.h | 2 +- .../settings/settings_privacy_controllers.cpp | 6 +- .../settings/settings_privacy_controllers.h | 2 +- .../settings/settings_scale_widget.cpp | 4 +- .../SourceFiles/settings/settings_widget.cpp | 2 +- Telegram/SourceFiles/stdafx.h | 7 +- Telegram/SourceFiles/ui/abstract_button.h | 4 +- Telegram/SourceFiles/ui/animation.h | 4 +- .../SourceFiles/ui/effects/fade_animation.h | 4 +- .../ui/effects/numbers_animation.cpp | 2 +- .../ui/effects/numbers_animation.h | 8 +- .../ui/effects/ripple_animation.cpp | 4 +- .../SourceFiles/ui/effects/ripple_animation.h | 4 +- .../SourceFiles/ui/effects/round_checkbox.cpp | 4 +- .../SourceFiles/ui/effects/round_checkbox.h | 10 +- Telegram/SourceFiles/ui/special_buttons.cpp | 4 +- Telegram/SourceFiles/ui/special_buttons.h | 16 +- Telegram/SourceFiles/ui/twidget.h | 4 +- Telegram/SourceFiles/ui/widgets/buttons.cpp | 6 +- Telegram/SourceFiles/ui/widgets/buttons.h | 8 +- Telegram/SourceFiles/ui/widgets/checkbox.cpp | 10 +- Telegram/SourceFiles/ui/widgets/checkbox.h | 16 +- .../ui/widgets/continuous_sliders.h | 2 +- .../SourceFiles/ui/widgets/dropdown_menu.cpp | 2 +- .../SourceFiles/ui/widgets/dropdown_menu.h | 6 +- .../SourceFiles/ui/widgets/inner_dropdown.h | 12 +- .../SourceFiles/ui/widgets/input_fields.cpp | 28 +- .../SourceFiles/ui/widgets/input_fields.h | 38 +- Telegram/SourceFiles/ui/widgets/labels.h | 2 +- Telegram/SourceFiles/ui/widgets/menu.cpp | 2 +- Telegram/SourceFiles/ui/widgets/menu.h | 30 +- .../SourceFiles/ui/widgets/multi_select.cpp | 20 +- .../SourceFiles/ui/widgets/multi_select.h | 42 +- .../SourceFiles/ui/widgets/popup_menu.cpp | 2 +- Telegram/SourceFiles/ui/widgets/popup_menu.h | 6 +- Telegram/SourceFiles/ui/widgets/tooltip.h | 4 +- Telegram/SourceFiles/window/layer_widget.cpp | 4 +- Telegram/SourceFiles/window/layer_widget.h | 8 +- .../window/themes/window_theme.cpp | 2 +- .../SourceFiles/window/themes/window_theme.h | 2 +- .../window/themes/window_theme_editor.cpp | 20 +- .../themes/window_theme_editor_block.cpp | 4 +- .../window/themes/window_theme_warning.h | 4 +- .../SourceFiles/window/window_peer_menu.cpp | 6 +- .../SourceFiles/window/window_peer_menu.h | 10 +- .../window/window_slide_animation.h | 4 +- Telegram/ThirdParty/crl | 2 +- Telegram/gyp/telegram_sources.txt | 2 - 216 files changed, 792 insertions(+), 1455 deletions(-) delete mode 100644 Telegram/SourceFiles/base/lambda.h delete mode 100644 Telegram/SourceFiles/base/lambda_guard.h diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index cb78db9d1d..6608f80aae 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -149,7 +149,7 @@ ApiWrap::ApiWrap(not_null session) void ApiWrap::requestChangelog( const QString &sinceVersion, - base::lambda callback) { + Fn callback) { request(MTPhelp_GetAppChangelog( MTP_string(sinceVersion) )).done( @@ -235,7 +235,7 @@ void ApiWrap::proxyPromotionDone(const MTPhelp_ProxyData &proxy) { void ApiWrap::requestDeepLinkInfo( const QString &path, - base::lambda callback) { + Fn callback) { request(_deepLinkInfoRequestId).cancel(); _deepLinkInfoRequestId = request(MTPhelp_GetDeepLinkInfo( MTP_string(path) @@ -276,7 +276,7 @@ void ApiWrap::savePinnedOrder() { //void ApiWrap::toggleChannelGrouping( // not_null channel, // bool group, -// base::lambda callback) { +// Fn callback) { // if (const auto already = _channelGroupingRequests.take(channel)) { // request(already->first).cancel(); // } @@ -1419,7 +1419,7 @@ void ApiWrap::deleteAllFromUserSend( void ApiWrap::requestChannelMembersForAdd( not_null channel, - base::lambda callback) { + Fn callback) { _channelMembersForAddCallback = std::move(callback); if (_channelMembersForAdd == channel) { return; @@ -2617,10 +2617,10 @@ void ApiWrap::readFeaturedSets() { void ApiWrap::parseChannelParticipants( not_null channel, const MTPchannels_ChannelParticipants &result, - base::lambda &list)> callbackList, - base::lambda callbackNotModified) { + Fn callbackNotModified) { TLHelp::VisitChannelParticipants(result, base::overload([&]( const MTPDchannels_channelParticipants &data) { App::feedUsers(data.vusers); @@ -2654,10 +2654,10 @@ void ApiWrap::refreshChannelAdmins( void ApiWrap::parseRecentChannelParticipants( not_null channel, const MTPchannels_ChannelParticipants &result, - base::lambda &list)> callbackList, - base::lambda callbackNotModified) { + Fn callbackNotModified) { parseChannelParticipants(channel, result, [&]( int availableCount, const QVector &list) { @@ -3536,12 +3536,12 @@ void ApiWrap::sendAction(const SendOptions &options) { void ApiWrap::forwardMessages( HistoryItemsList &&items, const SendOptions &options, - base::lambda_once &&successCallback) { + FnMut &&successCallback) { Expects(!items.empty()); struct SharedCallback { int requestsLeft = 0; - base::lambda_once callback; + FnMut callback; }; const auto shared = successCallback ? std::make_shared() diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index a68b8b5482..01d4f0e435 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -63,10 +63,10 @@ public: //void toggleChannelGrouping( // #feed // not_null channel, // bool group, - // base::lambda callback); + // Fn callback); //void ungroupAllFromFeed(not_null feed); - using RequestMessageDataCallback = base::lambda; + using RequestMessageDataCallback = Fn; void requestMessageData( ChannelData *channel, MsgId msgId, @@ -92,15 +92,15 @@ public: void requestChangelog( const QString &sinceVersion, - base::lambda callback); + Fn callback); void refreshProxyPromotion(); void requestDeepLinkInfo( const QString &path, - base::lambda callback); + Fn callback); void requestChannelMembersForAdd( not_null channel, - base::lambda callback); + Fn callback); void processFullPeer(PeerData *peer, const MTPmessages_ChatFull &result); void processFullPeer(UserData *user, const MTPUserFull &result); @@ -206,17 +206,17 @@ public: void parseChannelParticipants( not_null channel, const MTPchannels_ChannelParticipants &result, - base::lambda &list)> callbackList, - base::lambda callbackNotModified = nullptr); + Fn callbackNotModified = nullptr); void parseRecentChannelParticipants( not_null channel, const MTPchannels_ChannelParticipants &result, - base::lambda &list)> callbackList, - base::lambda callbackNotModified = nullptr); + Fn callbackNotModified = nullptr); struct SendOptions { SendOptions(not_null history) : history(history) { @@ -235,7 +235,7 @@ public: void forwardMessages( HistoryItemsList &&items, const SendOptions &options, - base::lambda_once &&successCallback = nullptr); + FnMut &&successCallback = nullptr); void shareContact( const QString &phone, const QString &firstName, @@ -462,11 +462,11 @@ private: ChannelData *_channelMembersForAdd = nullptr; mtpRequestId _channelMembersForAddRequestId = 0; - base::lambda _channelMembersForAddCallback; base::flat_map< not_null, - std::pair>> _channelGroupingRequests; + std::pair>> _channelGroupingRequests; using KickRequest = std::pair< not_null, diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 4d6ab462d3..ffebdf65be 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -1150,7 +1150,7 @@ namespace { return i.value(); } - void enumerateUsers(base::lambda)> action) { + void enumerateUsers(Fn)> action) { for_const (const auto peer, peersData) { if (const auto user = peer->asUser()) { action(user); @@ -1159,7 +1159,7 @@ namespace { } void enumerateChatsChannels( - base::lambda)> action) { + Fn)> action) { for_const (const auto peer, peersData) { if (!peer->isUser()) { action(peer); diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index aba1e31a7e..3680a2f4d1 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -135,9 +135,9 @@ namespace App { inline ChannelData *channelLoaded(ChannelId channelId) { return channel(channelId, PeerData::FullLoaded); } - void enumerateUsers(base::lambda)> action); + void enumerateUsers(Fn)> action); void enumerateChatsChannels( - base::lambda)> action); + Fn)> action); UserData *self(); PeerData *peerByName(const QString &username); diff --git a/Telegram/SourceFiles/base/lambda.h b/Telegram/SourceFiles/base/lambda.h deleted file mode 100644 index 9f9d67d540..0000000000 --- a/Telegram/SourceFiles/base/lambda.h +++ /dev/null @@ -1,487 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include - -#ifndef CUSTOM_LAMBDA_WRAP - -#include -#include "base/unique_function.h" - -namespace base { - -template -using lambda = std::function; - -template -using lambda_once = unique_function; - -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()) -#endif // Assert - -#ifndef Unexpected -#define LambdaUnexpectedDefined -#define Unexpected(v) std::abort() -#endif // Unexpected - -namespace base { - -template class lambda_once; -template class lambda; - -// Get lambda type from a lambda template parameter. - -namespace lambda_internal { - -template -struct type_resolver; - -template -struct type_resolver { - using type = lambda; - static constexpr auto is_mutable = false; -}; - -template -struct type_resolver { - using type = lambda_once; - static constexpr auto is_mutable = true; -}; - -template -struct type_helper { - using type = typename type_resolver::type; - static constexpr auto is_mutable = type_resolver::is_mutable; -}; - -} // namespace lambda_internal - -template -using lambda_type = typename lambda_internal::type_helper>::type; - -namespace lambda_internal { - -constexpr auto kFullStorageSize = 32U; -static_assert(kFullStorageSize % sizeof(void*) == 0, "Invalid pointer size!"); - -constexpr auto kStorageSize = kFullStorageSize - sizeof(void*); -using alignment = std::max_align_t; - -template -constexpr bool is_large = (sizeof(std::decay_t) > kStorageSize); - -[[noreturn]] inline void bad_construct_copy(void *lambda, const void *source) { - Unexpected("base::lambda bad_construct_copy() called!"); -} - -template -[[noreturn]] Return bad_const_call(const void *lambda, Args...) { - Unexpected("base::lambda bad_const_call() called!"); -} - -template -struct vtable_base { - using construct_copy_other_type = void(*)(void *, const void *); // dst, src - using construct_move_other_type = void(*)(void *, void *); // dst, src - using const_call_type = Return(*)(const void *, Args...); - using call_type = Return(*)(void *, Args...); - using destruct_type = void(*)(const void *); - - vtable_base() = delete; - vtable_base(const vtable_base &other) = delete; - vtable_base &operator=(const vtable_base &other) = delete; - - vtable_base( - construct_copy_other_type construct_copy_other, - construct_move_other_type construct_move_other, - const_call_type const_call, - call_type call, - destruct_type destruct) - : construct_copy_other(construct_copy_other) - , construct_move_other(construct_move_other) - , const_call(const_call) - , call(call) - , destruct(destruct) { - } - - const construct_copy_other_type construct_copy_other; - const construct_move_other_type construct_move_other; - const const_call_type const_call; - const call_type call; - const destruct_type destruct; - -}; - -template struct vtable_once_impl; - -template -struct vtable_once_impl : public vtable_base { - using JustLambda = std::decay_t; - using LambdaPtr = std::unique_ptr; - using Parent = vtable_base; - static void construct_move_other_method(void *storage, void *source) { - auto source_lambda_ptr = static_cast(source); - new (storage) LambdaPtr(std::move(*source_lambda_ptr)); - } - static Return call_method(void *storage, Args... args) { - return (**static_cast(storage))(std::forward(args)...); - } - static void destruct_method(const void *storage) { - static_cast(storage)->~LambdaPtr(); - } - vtable_once_impl() : Parent( - &bad_construct_copy, - &vtable_once_impl::construct_move_other_method, - &bad_const_call, - &vtable_once_impl::call_method, - &vtable_once_impl::destruct_method) { - } - - // Used directly. - static void construct_move_lambda_method(void *storage, void *source) { - auto source_lambda = static_cast(source); - new (storage) LambdaPtr(std::make_unique(static_cast(*source_lambda))); - } - -protected: - vtable_once_impl( - typename Parent::construct_copy_other_type construct_copy_other, - typename Parent::const_call_type const_call - ) : Parent( - construct_copy_other, - &vtable_once_impl::construct_move_other_method, - const_call, - &vtable_once_impl::call_method, - &vtable_once_impl::destruct_method) { - } - -}; - -template -struct vtable_once_impl : public vtable_base { - using JustLambda = std::decay_t; - using Parent = vtable_base; - static void construct_move_other_method(void *storage, void *source) { - auto source_lambda = static_cast(source); - new (storage) JustLambda(static_cast(*source_lambda)); - } - static Return call_method(void *storage, Args... args) { - return (*static_cast(storage))(std::forward(args)...); - } - static void destruct_method(const void *storage) { - static_cast(storage)->~JustLambda(); - } - vtable_once_impl() : Parent( - &bad_construct_copy, - &vtable_once_impl::construct_move_other_method, - &bad_const_call, - &vtable_once_impl::call_method, - &vtable_once_impl::destruct_method) { - } - - // Used directly. - static void construct_move_lambda_method(void *storage, void *source) { - auto source_lambda = static_cast(source); - new (storage) JustLambda(static_cast(*source_lambda)); - } - -protected: - vtable_once_impl( - typename Parent::construct_copy_other_type construct_copy_other, - typename Parent::const_call_type const_call - ) : Parent( - construct_copy_other, - &vtable_once_impl::construct_move_other_method, - const_call, - &vtable_once_impl::call_method, - &vtable_once_impl::destruct_method) { - } - -}; - -template -struct vtable_once : public vtable_once_impl, Return, Args...> { - static const vtable_once instance; -}; - -template -const vtable_once vtable_once::instance = {}; - -template struct vtable_impl; - -template -struct vtable_impl : public vtable_once_impl { - using JustLambda = std::decay_t; - using LambdaPtr = std::unique_ptr; - using Parent = vtable_once_impl; - static void construct_copy_other_method(void *storage, const void *source) { - auto source_lambda = static_cast(source); - new (storage) LambdaPtr(std::make_unique(*source_lambda->get())); - } - static Return const_call_method(const void *storage, Args... args) { - auto lambda_ptr = static_cast(storage)->get(); - return (*static_cast(lambda_ptr))(std::forward(args)...); - } - vtable_impl() : Parent( - &vtable_impl::construct_copy_other_method, - &vtable_impl::const_call_method - ) { - } - -}; - -template -struct vtable_impl : public vtable_once_impl { - using JustLambda = std::decay_t; - using Parent = vtable_once_impl; - static void construct_copy_other_method(void *storage, const void *source) { - auto source_lambda = static_cast(source); - new (storage) JustLambda(static_cast(*source_lambda)); - } - static Return const_call_method(const void *storage, Args... args) { - return (*static_cast(storage))(std::forward(args)...); - } - vtable_impl() : Parent( - &vtable_impl::construct_copy_other_method, - &vtable_impl::const_call_method - ) { - } - -}; - -template -struct vtable : public vtable_impl, Return, Args...> { - static const vtable instance; -}; - -template -const vtable vtable::instance = {}; - -} // namespace lambda_internal - -template -class lambda_once { - using VTable = lambda_internal::vtable_base; - -public: - using return_type = Return; - - lambda_once() { - data_.vtable = nullptr; - } - lambda_once(const lambda_once &other) = delete; - lambda_once &operator=(const lambda_once &other) = delete; - - // Move construct / assign from the same type. - lambda_once(lambda_once &&other) { - if ((data_.vtable = other.data_.vtable)) { - data_.vtable->construct_move_other(data_.storage, other.data_.storage); - } - } - lambda_once &operator=(lambda_once &&other) { - if (this != &other) { - if (data_.vtable) { - data_.vtable->destruct(data_.storage); - } - if ((data_.vtable = other.data_.vtable)) { - data_.vtable->construct_move_other(data_.storage, other.data_.storage); - data_.vtable->destruct(other.data_.storage); - other.data_.vtable = nullptr; - } - } - return *this; - } - - // Move construct / assign from a derived type. - lambda_once(lambda &&other) { - if ((data_.vtable = other.data_.vtable)) { - data_.vtable->construct_move_other(data_.storage, other.data_.storage); - data_.vtable->destruct(other.data_.storage); - other.data_.vtable = nullptr; - } - } - lambda_once &operator=(lambda &&other) { - if (this != &other) { - if (data_.vtable) { - data_.vtable->destruct(data_.storage); - } - if ((data_.vtable = other.data_.vtable)) { - data_.vtable->construct_move_other(data_.storage, other.data_.storage); - data_.vtable->destruct(other.data_.storage); - other.data_.vtable = nullptr; - } - } - return *this; - } - - // Copy construct / assign from a derived type. - lambda_once(const lambda &other) { - if ((data_.vtable = other.data_.vtable)) { - data_.vtable->construct_copy_other(data_.storage, other.data_.storage); - } - } - lambda_once &operator=(const lambda &other) { - if (this != &other) { - if (data_.vtable) { - data_.vtable->destruct(data_.storage); - } - if ((data_.vtable = other.data_.vtable)) { - data_.vtable->construct_copy_other(data_.storage, other.data_.storage); - } - } - return *this; - } - - // Copy / move construct / assign from an arbitrary type. - template ()(std::declval()...)),Return>::value>> - lambda_once(Lambda other) { - data_.vtable = &lambda_internal::vtable_once::instance; - lambda_internal::vtable_once::construct_move_lambda_method(data_.storage, &other); - } - template ()(std::declval()...)),Return>::value>> - lambda_once &operator=(Lambda other) { - if (data_.vtable) { - data_.vtable->destruct(data_.storage); - } - data_.vtable = &lambda_internal::vtable_once::instance; - lambda_internal::vtable_once::construct_move_lambda_method(data_.storage, &other); - return *this; - } - - void swap(lambda_once &other) { - if (this != &other) { - std::swap(*this, other); - } - } - - template < - typename ...OtherArgs, - typename = std::enable_if_t<(sizeof...(Args) == sizeof...(OtherArgs))>> - inline Return operator()(OtherArgs&&... args) { - Assert(data_.vtable != nullptr); - return data_.vtable->call( - data_.storage, - std::forward(args)...); - } - - explicit operator bool() const { - return (data_.vtable != nullptr); - } - - ~lambda_once() { - if (data_.vtable) { - data_.vtable->destruct(data_.storage); - } - } - -protected: - struct Private { - }; - lambda_once(const VTable *vtable, const Private &) { - data_.vtable = vtable; - } - - struct Data { - char storage[lambda_internal::kStorageSize]; - const VTable *vtable; - }; - union { - lambda_internal::alignment alignment_; - char raw_[lambda_internal::kFullStorageSize]; - Data data_; - }; - -}; - -template -class lambda final : public lambda_once { - using Parent = lambda_once; - -public: - lambda() = default; - - // Move construct / assign from the same type. - lambda(lambda &&other) : Parent(std::move(other)) { - } - lambda &operator=(lambda &&other) { - Parent::operator=(std::move(other)); - return *this; - } - - // Copy construct / assign from the same type. - lambda(const lambda &other) : Parent(other) { - } - lambda &operator=(const lambda &other) { - Parent::operator=(other); - return *this; - } - - // Copy / move construct / assign from an arbitrary type. - template ()(std::declval()...)),Return>::value>> - lambda(Lambda other) : Parent(&lambda_internal::vtable::instance, typename Parent::Private()) { - lambda_internal::vtable::construct_move_lambda_method(this->data_.storage, &other); - } - template ()(std::declval()...)),Return>::value>> - lambda &operator=(Lambda other) { - if (this->data_.vtable) { - this->data_.vtable->destruct(this->data_.storage); - } - this->data_.vtable = &lambda_internal::vtable::instance; - lambda_internal::vtable::construct_move_lambda_method(this->data_.storage, &other); - return *this; - } - - template < - typename ...OtherArgs, - typename = std::enable_if_t<(sizeof...(Args) == sizeof...(OtherArgs))>> - inline Return operator()(OtherArgs&&... args) const { - Assert(this->data_.vtable != nullptr); - return this->data_.vtable->const_call( - this->data_.storage, - std::forward(args)...); - } - - void swap(lambda &other) { - if (this != &other) { - std::swap(*this, other); - } - } - -}; - -} // namespace base - -#ifdef LambdaAssertDefined -#undef Assert -#endif // LambdaAssertDefined - -#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 deleted file mode 100644 index 8c1413d88a..0000000000 --- a/Telegram/SourceFiles/base/lambda_guard.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include -#include "base/weak_ptr.h" - -// Guard lambda call by QObject* or has_weak_ptr* pointers. - -namespace base { -namespace lambda_internal { - -template -class guard_with_QObject { -public: - template - guard_with_QObject(const QObject *object, OtherLambda &&other) - : _guard(object) - , _callable(std::forward(other)) { - } - - template < - typename ...OtherArgs, - typename Return = decltype(std::declval()(std::declval()...))> - Return operator()(OtherArgs &&...args) { - return _guard - ? _callable(std::forward(args)...) - : Return(); - } - - template < - typename ...OtherArgs, - typename Return = decltype(std::declval()(std::declval()...))> - Return operator()(OtherArgs &&...args) const { - return _guard - ? _callable(std::forward(args)...) - : Return(); - } - -private: - QPointer _guard; - Lambda _callable; - -}; - -template -class guard_with_weak { -public: - template - guard_with_weak( - const base::has_weak_ptr *object, - OtherLambda &&other) - : _guard(base::make_weak(object)) - , _callable(std::forward(other)) { - } - - template < - typename ...OtherArgs, - typename Return = decltype(std::declval()(std::declval()...))> - Return operator()(OtherArgs &&...args) { - return _guard - ? _callable(std::forward(args)...) - : Return(); - } - - template < - typename ...OtherArgs, - typename Return = decltype(std::declval()(std::declval()...))> - Return operator()(OtherArgs &&...args) const { - return _guard - ? _callable(std::forward(args)...) - : Return(); - } - -private: - base::weak_ptr _guard; - Lambda _callable; - -}; - -template -struct lambda_call_type> { - using type = lambda_call_type_t; -}; - -template -struct lambda_call_type> { - using type = lambda_call_type_t; -}; - -} // namespace lambda_internal - -template -inline auto lambda_guarded(const QObject *object, Lambda &&lambda) { - using Guarded = lambda_internal::guard_with_QObject< - std::decay_t>; - return Guarded(object, std::forward(lambda)); -} - -template -inline auto lambda_guarded( - const base::has_weak_ptr *object, - Lambda &&lambda) { - using Guarded = lambda_internal::guard_with_weak< - std::decay_t>; - return Guarded(object, std::forward(lambda)); -} - -} // namespace base diff --git a/Telegram/SourceFiles/base/observer.h b/Telegram/SourceFiles/base/observer.h index a7dbc8af41..f523df39d7 100644 --- a/Telegram/SourceFiles/base/observer.h +++ b/Telegram/SourceFiles/base/observer.h @@ -15,19 +15,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL 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)>; + using type = Fn)>; }; template <> struct SubscriptionHandlerHelper { - using type = base::lambda; + using type = Fn; }; template diff --git a/Telegram/SourceFiles/base/timer.cpp b/Telegram/SourceFiles/base/timer.cpp index a5f8b81691..c752a9b731 100644 --- a/Telegram/SourceFiles/base/timer.cpp +++ b/Telegram/SourceFiles/base/timer.cpp @@ -19,13 +19,13 @@ QObject *TimersAdjuster() { Timer::Timer( not_null thread, - base::lambda callback) + Fn callback) : Timer(std::move(callback)) { moveToThread(thread); } -Timer::Timer(base::lambda callback) +Timer::Timer(Fn callback) : QObject(nullptr) , _callback(std::move(callback)) , _type(Qt::PreciseTimer) @@ -114,7 +114,7 @@ void Timer::timerEvent(QTimerEvent *e) { int DelayedCallTimer::call( TimeMs timeout, - lambda_once callback, + FnMut callback, Qt::TimerType type) { Expects(timeout >= 0); diff --git a/Telegram/SourceFiles/base/timer.h b/Telegram/SourceFiles/base/timer.h index cc04b4f0f4..f6b83280ff 100644 --- a/Telegram/SourceFiles/base/timer.h +++ b/Telegram/SourceFiles/base/timer.h @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "base/lambda.h" #include "base/observer.h" namespace base { @@ -16,15 +15,15 @@ class Timer final : private QObject { public: explicit Timer( not_null thread, - base::lambda callback = nullptr); - explicit Timer(base::lambda callback = nullptr); + Fn callback = nullptr); + explicit Timer(Fn callback = nullptr); 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); } @@ -74,7 +73,7 @@ private: return static_cast(_repeat); } - base::lambda _callback; + Fn _callback; TimeMs _next = 0; int _timeout = 0; int _timerId = 0; @@ -87,7 +86,7 @@ private: 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), @@ -96,7 +95,7 @@ public: int call( TimeMs timeout, - lambda_once callback, + FnMut callback, Qt::TimerType type); void cancel(int callId); @@ -104,7 +103,7 @@ protected: void timerEvent(QTimerEvent *e) override; private: - base::flat_map> _callbacks; + base::flat_map> _callbacks; }; diff --git a/Telegram/SourceFiles/base/unique_function.h b/Telegram/SourceFiles/base/unique_function.h index 1ba676972e..46c6867265 100644 --- a/Telegram/SourceFiles/base/unique_function.h +++ b/Telegram/SourceFiles/base/unique_function.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include + #ifndef Unexpected #define Unexpected(message) std::abort() #define UniqueFunctionUnexpected @@ -47,7 +49,7 @@ public: } template - decltype(auto) operator()(Args &&...args) const { + decltype(auto) operator()(Args &&...args) { return _value(std::forward(args)...); } @@ -59,7 +61,7 @@ private: Unexpected("Attempt to copy-assign a move-only type."); } - mutable Callable _value; + Callable _value; }; diff --git a/Telegram/SourceFiles/boxes/abstract_box.cpp b/Telegram/SourceFiles/boxes/abstract_box.cpp index 9b1687580b..52c1a13006 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.cpp +++ b/Telegram/SourceFiles/boxes/abstract_box.cpp @@ -20,8 +20,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" QPointer BoxContent::addButton( - base::lambda textFactory, - base::lambda clickCallback) { + Fn textFactory, + Fn clickCallback) { return addButton( std::move(textFactory), std::move(clickCallback), @@ -29,8 +29,8 @@ QPointer BoxContent::addButton( } QPointer BoxContent::addLeftButton( - base::lambda textFactory, - base::lambda clickCallback) { + Fn textFactory, + Fn clickCallback) { return getDelegate()->addLeftButton( std::move(textFactory), std::move(clickCallback), @@ -290,7 +290,7 @@ void AbstractBox::parentResized() { update(); } -void AbstractBox::setTitle(base::lambda titleFactory) { +void AbstractBox::setTitle(Fn titleFactory) { _titleFactory = std::move(titleFactory); refreshTitle(); } @@ -311,7 +311,7 @@ void AbstractBox::refreshTitle() { } } -void AbstractBox::setAdditionalTitle(base::lambda additionalFactory) { +void AbstractBox::setAdditionalTitle(Fn additionalFactory) { _additionalTitleFactory = std::move(additionalFactory); refreshAdditionalTitle(); } @@ -373,7 +373,7 @@ 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)); @@ -382,7 +382,7 @@ 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 84f4f6ea2a..2c61e172d3 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.h +++ b/Telegram/SourceFiles/boxes/abstract_box.h @@ -28,12 +28,12 @@ class BoxContent; class BoxContentDelegate { public: 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, const style::RoundButton &st) = 0; - virtual QPointer addLeftButton(base::lambda textFactory, base::lambda clickCallback, const style::RoundButton &st) = 0; + virtual QPointer addButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) = 0; + virtual QPointer addLeftButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) = 0; virtual void updateButtonsPositions() = 0; virtual void showBox( @@ -72,17 +72,17 @@ public: 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)); } @@ -91,9 +91,9 @@ public: 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, const style::RoundButton &st) { + 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); } void updateButtonsGeometry() { @@ -228,16 +228,16 @@ public: 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 showBox( object_ptr box, LayerOptions options, anim::type animated) override; void clearButtons() override; - QPointer addButton(base::lambda textFactory, base::lambda clickCallback, const style::RoundButton &st) override; - QPointer addLeftButton(base::lambda textFactory, base::lambda clickCallback, const style::RoundButton &st) override; + QPointer addButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) override; + QPointer addLeftButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) override; void updateButtonsPositions() override; void setDimensions(int newWidth, int maxHeight) override; @@ -292,9 +292,9 @@ private: 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 a295b613c6..87bd819e96 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -57,7 +57,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; @@ -85,7 +85,7 @@ private: int _rowHeight = 0; int _revokeWidth = 0; - base::lambda _revokeCallback; + Fn _revokeCallback; mtpRequestId _revokeRequestId = 0; QPointer _weakRevokeConfirmBox; @@ -592,7 +592,7 @@ SetupChannelBox::SetupChannelBox(QWidget*, ChannelData *channel, bool existing) , _aboutPublicWidth(st::boxWideWidth - st::boxPadding.left() - st::boxButtonPadding.right() - st::newGroupPadding.left() - st::defaultRadio.diameter - st::defaultBoxCheckbox.textPosition.x()) , _aboutPublic(st::defaultTextStyle, lang(channel->isMegagroup() ? lng_create_public_group_about : lng_create_public_channel_about), _defaultOptions, _aboutPublicWidth) , _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() { @@ -819,7 +819,7 @@ void SetupChannelBox::privacyChanged(Privacy value) { if (value == Privacy::Public) { if (_tooMuchUsernames) { _privacyGroup->setValue(Privacy::Private); - Ui::show(Box(base::lambda_guarded(this, [this] { + Ui::show(Box(crl::guard(this, [this] { _tooMuchUsernames = false; _privacyGroup->setValue(Privacy::Public); check(); @@ -1389,7 +1389,7 @@ void EditChannelBox::onSaveInvitesDone(const MTPUpdates &result) { closeBox(); } -RevokePublicLinkBox::Inner::Inner(QWidget *parent, base::lambda revokeCallback) : TWidget(parent) +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))) , _revokeCallback(std::move(revokeCallback)) { @@ -1425,7 +1425,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)) { } @@ -1484,7 +1484,7 @@ void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) { auto text_method = pressed->isMegagroup() ? lng_channels_too_much_public_revoke_confirm_group : lng_channels_too_much_public_revoke_confirm_channel; auto text = text_method(lt_link, Messenger::Instance().createInternalLink(pressed->userName()), lt_group, pressed->name); auto confirmText = lang(lng_channels_too_much_public_revoke); - _weakRevokeConfirmBox = Ui::show(Box(text, confirmText, base::lambda_guarded(this, [this, pressed]() { + _weakRevokeConfirmBox = Ui::show(Box(text, confirmText, crl::guard(this, [this, pressed]() { if (_revokeRequestId) return; _revokeRequestId = request(MTPchannels_UpdateUsername(pressed->asChannel()->inputChannel, MTP_string(""))).done([this](const MTPBool &result) { if (_weakRevokeConfirmBox) { diff --git a/Telegram/SourceFiles/boxes/add_contact_box.h b/Telegram/SourceFiles/boxes/add_contact_box.h index b35fe4a0eb..582fb2004d 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.h +++ b/Telegram/SourceFiles/boxes/add_contact_box.h @@ -281,7 +281,7 @@ private: class RevokePublicLinkBox : public BoxContent, public RPCSender { public: - RevokePublicLinkBox(QWidget*, base::lambda revokeCallback); + RevokePublicLinkBox(QWidget*, Fn revokeCallback); protected: void prepare() override; @@ -295,6 +295,6 @@ private: 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 b413ce693f..8e59f57058 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -20,7 +20,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); } @@ -36,7 +36,7 @@ private: 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 5746f46fc6..1cdc46deee 100644 --- a/Telegram/SourceFiles/boxes/calendar_box.cpp +++ b/Telegram/SourceFiles/boxes/calendar_box.cpp @@ -192,7 +192,7 @@ public: return st::calendarPadding.top() + innerHeight + st::calendarPadding.bottom(); } - void setDateChosenCallback(base::lambda callback) { + void setDateChosenCallback(Fn callback) { _dateChosenCallback = std::move(callback); } @@ -219,7 +219,7 @@ private: std::map> _ripples; - base::lambda _dateChosenCallback; + Fn _dateChosenCallback; static constexpr auto kEmptySelection = -kDaysInWeek; int _selected = kEmptySelection; @@ -440,7 +440,7 @@ void CalendarBox::Title::paintEvent(QPaintEvent *e) { p.drawTextLeft((width() - _textWidth) / 2, (height() - st::calendarTitleFont->height) / 2, width(), _text, _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 faf9ec5e98..867fb76779 100644 --- a/Telegram/SourceFiles/boxes/calendar_box.h +++ b/Telegram/SourceFiles/boxes/calendar_box.h @@ -15,7 +15,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); @@ -44,6 +44,6 @@ private: object_ptr _previous; object_ptr _next; - base::lambda _callback; + Fn _callback; }; diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index 87a114be23..a68a1780c4 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -144,9 +144,9 @@ void ChangePhoneBox::EnterPhone::submit() { hideError(); auto phoneNumber = _phone->getLastText().trimmed(); - _requestId = MTP::send(MTPaccount_SendChangePhoneCode(MTP_flags(0), MTP_string(phoneNumber), MTP_bool(false)), rpcDone(base::lambda_guarded(this, [this, phoneNumber](const MTPauth_SentCode &result) { + _requestId = MTP::send(MTPaccount_SendChangePhoneCode(MTP_flags(0), MTP_string(phoneNumber), MTP_bool(false)), rpcDone(crl::guard(this, [this, phoneNumber](const MTPauth_SentCode &result) { return sendPhoneDone(phoneNumber, result); - })), rpcFail(base::lambda_guarded(this, [this, phoneNumber](const RPCError &error) { + })), rpcFail(crl::guard(this, [this, phoneNumber](const RPCError &error) { return sendPhoneFail(phoneNumber, error); }))); } @@ -265,13 +265,13 @@ void ChangePhoneBox::EnterCode::submit() { Ui::hideLayer(); } Ui::Toast::Show(lang(lng_change_phone_success)); - }), rpcFail(base::lambda_guarded(this, [this](const RPCError &error) { + }), rpcFail(crl::guard(this, [this](const RPCError &error) { return sendCodeFail(error); }))); } void ChangePhoneBox::EnterCode::sendCall() { - MTP::send(MTPauth_ResendCode(MTP_string(_phone), MTP_string(_hash)), rpcDone(base::lambda_guarded(this, [this] { + MTP::send(MTPauth_ResendCode(MTP_string(_phone), MTP_string(_hash)), rpcDone(crl::guard(this, [this] { _call.callDone(); }))); } diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 9770f20fb2..93175cdfc3 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -33,7 +33,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) @@ -43,7 +43,7 @@ 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) @@ -53,7 +53,7 @@ ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText init(text); } -ConfirmBox::ConfirmBox(QWidget*, const TextWithEntities &text, const QString &confirmText, base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) +ConfirmBox::ConfirmBox(QWidget*, const TextWithEntities &text, const QString &confirmText, FnMut confirmedCallback, FnMut cancelledCallback) : _confirmText(confirmText) , _cancelText(lang(lng_cancel)) , _confirmStyle(st::defaultBoxButton) @@ -63,7 +63,7 @@ ConfirmBox::ConfirmBox(QWidget*, const TextWithEntities &text, const QString &co init(text); } -ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) +ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, FnMut confirmedCallback, FnMut cancelledCallback) : _confirmText(confirmText) , _cancelText(lang(lng_cancel)) , _confirmStyle(confirmStyle) @@ -73,7 +73,7 @@ ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText init(text); } -ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) +ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, FnMut confirmedCallback, FnMut cancelledCallback) : _confirmText(confirmText) , _cancelText(cancelText) , _confirmStyle(st::defaultBoxButton) @@ -83,7 +83,7 @@ ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText init(text); } -ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) +ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, FnMut confirmedCallback, FnMut cancelledCallback) : _confirmText(confirmText) , _cancelText(cancelText) , _confirmStyle(st::defaultBoxButton) @@ -93,7 +93,7 @@ ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText 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) @@ -103,7 +103,7 @@ ConfirmBox::ConfirmBox(const InformBoxTag &, const QString &text, const QString init(text); } -ConfirmBox::ConfirmBox(const InformBoxTag &, const TextWithEntities &text, const QString &doneText, base::lambda closedCallback) +ConfirmBox::ConfirmBox(const InformBoxTag &, const TextWithEntities &text, const QString &doneText, Fn closedCallback) : _confirmText(doneText) , _confirmStyle(st::defaultBoxButton) , _informative(true) @@ -113,8 +113,8 @@ ConfirmBox::ConfirmBox(const InformBoxTag &, const TextWithEntities &text, const init(text); } -base::lambda_once ConfirmBox::generateInformCallback(base::lambda closedCallback) { - return base::lambda_guarded(this, [this, closedCallback] { +FnMut ConfirmBox::generateInformCallback(Fn closedCallback) { + return crl::guard(this, [this, closedCallback] { closeBox(); if (closedCallback) { closedCallback(); @@ -241,13 +241,13 @@ void ConfirmBox::paintEvent(QPaintEvent *e) { } } -InformBox::InformBox(QWidget*, const QString &text, base::lambda closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, lang(lng_box_ok), std::move(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) : ConfirmBox(ConfirmBox::InformBoxTag(), text, doneText, std::move(closedCallback)) { +InformBox::InformBox(QWidget*, const QString &text, const QString &doneText, Fn closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, doneText, std::move(closedCallback)) { } -InformBox::InformBox(QWidget*, const TextWithEntities &text, base::lambda closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, lang(lng_box_ok), std::move(closedCallback)) { +InformBox::InformBox(QWidget*, const TextWithEntities &text, Fn closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, lang(lng_box_ok), std::move(closedCallback)) { } MaxInviteBox::MaxInviteBox(QWidget*, not_null channel) : BoxContent() diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index ec366c3ae1..9c2ee6caa1 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -18,12 +18,12 @@ class EmptyUserpic; 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, const QString &confirmText, base::lambda_once confirmedCallback = base::lambda_once(), base::lambda_once cancelledCallback = base::lambda_once()); - 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()); - 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()); - 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()); - ConfirmBox(QWidget*, const TextWithEntities &text, const QString &confirmText, base::lambda_once confirmedCallback = nullptr, base::lambda_once cancelledCallback = nullptr); + ConfirmBox(QWidget*, const QString &text, FnMut confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); + ConfirmBox(QWidget*, const QString &text, const QString &confirmText, FnMut confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); + ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, FnMut confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); + ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, FnMut confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); + ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, FnMut confirmedCallback = FnMut(), FnMut cancelledCallback = FnMut()); + ConfirmBox(QWidget*, const TextWithEntities &text, const QString &confirmText, FnMut confirmedCallback = nullptr, FnMut cancelledCallback = nullptr); void updateLink(); @@ -51,9 +51,9 @@ protected: private: struct InformBoxTag { }; - ConfirmBox(const InformBoxTag &, const QString &text, const QString &doneText, base::lambda closedCallback); - ConfirmBox(const InformBoxTag &, const TextWithEntities &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); + ConfirmBox(const InformBoxTag &, const TextWithEntities &text, const QString &doneText, Fn closedCallback); + FnMut generateInformCallback(Fn closedCallback); friend class InformBox; void confirmed(); @@ -77,16 +77,16 @@ private: 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 = nullptr); - InformBox(QWidget*, const QString &text, const QString &doneText, base::lambda closedCallback = nullptr); - InformBox(QWidget*, const TextWithEntities &text, base::lambda closedCallback = nullptr); + InformBox(QWidget*, const QString &text, Fn closedCallback = nullptr); + InformBox(QWidget*, const QString &text, const QString &doneText, Fn closedCallback = nullptr); + InformBox(QWidget*, const TextWithEntities &text, Fn closedCallback = nullptr); }; @@ -172,7 +172,7 @@ public: bool suggestModerateActions); DeleteMessagesBox(QWidget*, MessageIdsList &&selected); - void setDeleteConfirmedCallback(base::lambda callback) { + void setDeleteConfirmedCallback(Fn callback) { _deleteConfirmedCallback = std::move(callback); } @@ -198,7 +198,7 @@ private: object_ptr _reportSpam = { nullptr }; object_ptr _deleteAll = { nullptr }; - base::lambda _deleteConfirmedCallback; + Fn _deleteConfirmedCallback; }; diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp index f001e4124f..a04a5dc257 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp @@ -76,7 +76,7 @@ void SentCodeField::fix() { } } -SentCodeCall::SentCodeCall(base::lambda_once callCallback, base::lambda updateCallback) +SentCodeCall::SentCodeCall(FnMut callCallback, Fn updateCallback) : _call(std::move(callCallback)) , _update(std::move(updateCallback)) { _timer.setCallback([=] { diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.h b/Telegram/SourceFiles/boxes/confirm_phone_box.h index bde65d12c4..36084bbf02 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.h +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.h @@ -18,15 +18,15 @@ class FlatLabel; class SentCodeField : public Ui::InputField { public: - SentCodeField(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory = base::lambda(), const QString &val = QString()) : Ui::InputField(parent, st, std::move(placeholderFactory), val) { + 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); } @@ -37,16 +37,16 @@ private: bool _fixing = false; int _autoSubmitLength = 0; - base::lambda _submitCallback; - base::lambda _changedCallback; + Fn _submitCallback; + Fn _changedCallback; }; class SentCodeCall { public: SentCodeCall( - base::lambda_once callCallback, - base::lambda updateCallback); + FnMut callCallback, + Fn updateCallback); enum class State { Waiting, @@ -79,8 +79,8 @@ public: private: Status _status; base::Timer _timer; - base::lambda_once _call; - base::lambda _update; + FnMut _call; + Fn _update; }; diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index eabc26a1d2..b00003bb60 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -125,8 +125,8 @@ public: ProxyBox( QWidget*, const ProxyData &data, - base::lambda callback, - base::lambda shareCallback); + Fn callback, + Fn shareCallback); protected: void prepare() override; @@ -148,8 +148,8 @@ private: not_null parent, const QString &text) const; - base::lambda _callback; - base::lambda _shareCallback; + Fn _callback; + Fn _shareCallback; object_ptr _content; @@ -415,7 +415,7 @@ void ProxyRow::showMenu() { _menuToggle->installEventFilter(_menu); const auto addAction = [&]( const QString &text, - base::lambda callback) { + Fn callback) { return _menu->addAction(text, std::move(callback)); }; addAction(lang(lng_proxy_menu_edit), [=] { @@ -677,8 +677,8 @@ void ProxiesBox::setupButtons(int id, not_null button) { ProxyBox::ProxyBox( QWidget*, const ProxyData &data, - base::lambda callback, - base::lambda shareCallback) + Fn callback, + Fn shareCallback) : _callback(std::move(callback)) , _shareCallback(std::move(shareCallback)) , _content(this) { diff --git a/Telegram/SourceFiles/boxes/download_path_box.cpp b/Telegram/SourceFiles/boxes/download_path_box.cpp index 0332b3dd1b..96eb358642 100644 --- a/Telegram/SourceFiles/boxes/download_path_box.cpp +++ b/Telegram/SourceFiles/boxes/download_path_box.cpp @@ -101,7 +101,7 @@ void DownloadPathBox::onEditPath() { this, lang(lng_download_path_choose), initialPath, - base::lambda_guarded(this, handleFolder)); + crl::guard(this, handleFolder)); } void DownloadPathBox::save() { diff --git a/Telegram/SourceFiles/boxes/edit_color_box.cpp b/Telegram/SourceFiles/boxes/edit_color_box.cpp index 4cc85aba6c..21d754d7f9 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_color_box.cpp @@ -720,7 +720,7 @@ void EditColorBox::fieldSubmitted() { } 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 0a83ba08cc..1ca903a152 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.h +++ b/Telegram/SourceFiles/boxes/edit_color_box.h @@ -13,11 +13,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); } @@ -86,7 +86,7 @@ private: 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 a266c62744..f4fd325ffc 100644 --- a/Telegram/SourceFiles/boxes/edit_participant_box.h +++ b/Telegram/SourceFiles/boxes/edit_participant_box.h @@ -58,7 +58,7 @@ class EditAdminBox : public EditParticipantBox { public: EditAdminBox(QWidget*, not_null channel, not_null user, const MTPChannelAdminRights &rights); - void setSaveCallback(base::lambda callback) { + void setSaveCallback(Fn callback) { _saveCallback = std::move(callback); } @@ -79,7 +79,7 @@ private: const MTPChannelAdminRights _oldRights; std::vector> _dependencies; - base::lambda _saveCallback; + Fn _saveCallback; std::map> _checkboxes; QPointer _aboutAddAdmins; @@ -93,7 +93,7 @@ class EditRestrictedBox : public EditParticipantBox { public: 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); } @@ -123,7 +123,7 @@ private: 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 26319c9b5b..7fcfac3cba 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -22,7 +22,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; @@ -32,12 +32,12 @@ protected: std::unique_ptr createRow(not_null history) override; private: - base::lambda _titleFactory; + Fn _titleFactory; std::vector> _selected; }; -PrivacyExceptionsBoxController::PrivacyExceptionsBoxController(base::lambda titleFactory, const std::vector> &selected) +PrivacyExceptionsBoxController::PrivacyExceptionsBoxController(Fn titleFactory, const std::vector> &selected) : _titleFactory(std::move(titleFactory)) , _selected(selected) { } @@ -163,11 +163,11 @@ int EditPrivacyBox::countDefaultHeight(int newWidth) { } void EditPrivacyBox::editExceptionUsers(Exception exception) { - auto controller = std::make_unique(base::lambda_guarded(this, [this, exception] { + auto controller = std::make_unique(crl::guard(this, [this, exception] { return _controller->exceptionBoxTitle(exception); }), exceptionUsers(exception)); auto initBox = [this, exception, controller = controller.get()](not_null box) { - box->addButton(langFactory(lng_settings_save), base::lambda_guarded(this, [this, box, exception, controller] { + box->addButton(langFactory(lng_settings_save), crl::guard(this, [this, box, exception, controller] { exceptionUsers(exception) = controller->getResult(); exceptionLink(exception)->entity()->setText(exceptionLinkText(exception)); auto removeFrom = ([exception] { @@ -295,7 +295,7 @@ void EditPrivacyBox::createWidgets() { clearButtons(); addButton(langFactory(lng_settings_save), [this] { auto someAreDisallowed = (_option != Option::Everyone) || !_neverUsers.empty(); - _controller->confirmSave(someAreDisallowed, base::lambda_guarded(this, [this] { + _controller->confirmSave(someAreDisallowed, crl::guard(this, [this] { Auth().api().savePrivacy(_controller->key(), collectResult()); closeBox(); })); diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.h b/Telegram/SourceFiles/boxes/edit_privacy_box.h index 748a9d79c8..264425561e 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.h +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.h @@ -49,7 +49,7 @@ public: 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/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index 6ad516f82c..8963c545df 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -320,7 +320,7 @@ void PasscodeBox::save(bool force) { } if (!_recoverEmail->isHidden() && email.isEmpty() && !force) { _skipEmailWarning = true; - _replacedBy = getDelegate()->show(Box(lang(lng_cloud_password_about_recover), lang(lng_cloud_password_skip_email), st::attentionBoxButton, base::lambda_guarded(this, [this] { + _replacedBy = getDelegate()->show(Box(lang(lng_cloud_password_about_recover), lang(lng_cloud_password_skip_email), st::attentionBoxButton, crl::guard(this, [this] { save(true); }))); } else if (_newPasscode->isHidden()) { @@ -679,7 +679,7 @@ void RecoverBox::submit() { return; } - const auto send = base::lambda_guarded(this, [=] { + const auto send = crl::guard(this, [=] { _submitRequest = MTP::send( MTPauth_RecoverPassword(MTP_string(code)), rpcDone(&RecoverBox::codeSubmitDone, true), diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 3d89e7caac..bdc3ff8351 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -31,7 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL PeerListBox::PeerListBox( QWidget*, std::unique_ptr controller, - base::lambda)> init) + Fn)> init) : _controller(std::move(controller)) , _init(std::move(init)) { Expects(_controller != nullptr); @@ -525,7 +525,7 @@ void PeerListRow::lazyInitialize(const style::PeerListItem &st) { refreshStatus(); } -void PeerListRow::createCheckbox(base::lambda updateCallback) { +void PeerListRow::createCheckbox(Fn updateCallback) { _checkbox = std::make_unique( st::contactsPhotoCheckbox, std::move(updateCallback), @@ -1022,7 +1022,7 @@ void PeerListContent::contextMenuEvent(QContextMenuEvent *e) { if (const auto row = getRow(_contexted.index)) { _contextMenu = _controller->rowContextMenu(row); if (_contextMenu) { - _contextMenu->setDestroyedCallback(base::lambda_guarded( + _contextMenu->setDestroyedCallback(crl::guard( this, [this] { setContexted(Selected()); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index 5a50a5d416..889a15cbce 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -37,7 +37,7 @@ struct PeerUpdate; inline auto PaintUserpicCallback( not_null peer, bool respectSavedMessagesChat) -->base::lambda { +->Fn { if (respectSavedMessagesChat && peer->isSelf()) { return [](Painter &p, int x, int y, int outerWidth, int size) { Ui::EmptyUserpic::PaintSavedMessages(p, x, y, outerWidth, size); @@ -95,7 +95,7 @@ public: virtual QMargins actionMargins() const { return QMargins(); } - virtual void addActionRipple(QPoint point, base::lambda updateCallback) { + virtual void addActionRipple(QPoint point, Fn updateCallback) { } virtual void stopLastActionRipple() { } @@ -200,7 +200,7 @@ protected: } private: - void createCheckbox(base::lambda updateCallback); + void createCheckbox(Fn updateCallback); void setCheckedInternal(bool checked, SetStyle style); void paintDisabledCheckUserpic( Painter &p, @@ -236,8 +236,8 @@ struct PeerListState; 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; @@ -258,8 +258,8 @@ public: virtual void peerListScrollToTop() = 0; virtual int peerListFullRowsCount() = 0; virtual PeerListRow *peerListFindRow(PeerListRowId id) = 0; - virtual void peerListSortRows(base::lambda compare) = 0; - virtual int peerListPartitionRows(base::lambda border) = 0; + virtual void peerListSortRows(Fn compare) = 0; + virtual int peerListPartitionRows(Fn border) = 0; template void peerListAddSelectedRows(PeerDataRange &&range) { @@ -701,7 +701,7 @@ public: _content->setSearchMode(mode); } void peerListSortRows( - base::lambda compare) override { + Fn compare) override { _content->reorderRows([&]( auto &&begin, auto &&end) { @@ -711,7 +711,7 @@ public: }); } int peerListPartitionRows( - base::lambda border) override { + Fn border) override { auto result = 0; _content->reorderRows([&]( auto &&begin, @@ -749,13 +749,13 @@ public: PeerListBox( QWidget*, std::unique_ptr controller, - base::lambda)> init); + Fn)> init); - void peerListSetTitle(base::lambda title) override { + void peerListSetTitle(Fn title) override { setTitle(std::move(title)); } void peerListSetAdditionalTitle( - base::lambda title) override { + Fn title) override { setAdditionalTitle(std::move(title)); } void peerListSetSearchMode(PeerListSearchMode mode) override; @@ -793,7 +793,7 @@ private: object_ptr> _select = { nullptr }; std::unique_ptr _controller; - base::lambda _init; + Fn _init; bool _scrollBottomFixed = false; }; diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index 80bfbd3fc6..f87db01679 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -901,7 +901,7 @@ void AddBotToGroupBoxController::prepareViewHook() { } ChooseRecipientBoxController::ChooseRecipientBoxController( - base::lambda_once)> callback) + FnMut)> callback) : _callback(std::move(callback)) { } diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.h b/Telegram/SourceFiles/boxes/peer_list_controllers.h index de241040dc..4c8227204e 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.h +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.h @@ -230,7 +230,7 @@ private: class ChooseRecipientBoxController : public ChatsListBoxController { public: ChooseRecipientBoxController( - base::lambda_once)> callback); + FnMut)> callback); void rowClicked(not_null row) override; @@ -244,6 +244,6 @@ protected: not_null history) override; private: - base::lambda_once)> _callback; + FnMut)> _callback; }; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index a1c6c02e8a..29f74a2982 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -42,8 +42,8 @@ constexpr auto kMaxGroupChannelTitle = 255; // See also add_contact_box. constexpr auto kMaxChannelDescription = 255; // See also add_contact_box. class Controller - : private MTP::Sender - , private base::has_weak_ptr { + : public base::has_weak_ptr + , private MTP::Sender { public: Controller( not_null box, @@ -101,7 +101,7 @@ private: base::optional everyoneInvites; }; - base::lambda computeTitle() const; + Fn computeTitle() const; object_ptr createPhotoAndTitleEdit(); object_ptr createTitleEdit(); object_ptr createPhotoEdit(); @@ -159,7 +159,7 @@ private: void saveInvites(); void saveSignatures(); void savePhoto(); - void pushSaveStage(base::lambda_once &&lambda); + void pushSaveStage(FnMut &&lambda); void continueSave(); void cancelSave(); @@ -174,7 +174,7 @@ private: UsernameState _usernameState = UsernameState::Normal; rpl::event_stream> _usernameResultTexts; - std::deque> _saveStagesQueue; + std::deque> _saveStagesQueue; Saving _savingData; }; @@ -195,7 +195,7 @@ Controller::Controller( }); } -base::lambda Controller::computeTitle() const { +Fn Controller::computeTitle() const { return langFactory(_isGroup ? lng_edit_group : lng_edit_channel_title); @@ -434,7 +434,7 @@ object_ptr Controller::createUsernameEdit() { object_ptr( container, st::setupChannelLink, - base::lambda(), + Fn(), channel->username, true)); _controls.username->heightValue( @@ -565,7 +565,7 @@ void Controller::checkUsernameAvailability() { void Controller::askUsernameRevoke() { _controls.privacy->setValue(Privacy::Private); - auto revokeCallback = base::lambda_guarded(this, [this] { + auto revokeCallback = crl::guard(this, [this] { _usernameState = UsernameState::Normal; _controls.privacy->setValue(Privacy::Public); checkUsernameAvailability(); @@ -644,7 +644,7 @@ void Controller::revokeInviteLink() { void Controller::exportInviteLink(const QString &confirmation) { auto boxPointer = std::make_shared>(); - auto callback = base::lambda_guarded(this, [=] { + auto callback = crl::guard(this, [=] { if (auto strong = *boxPointer) { strong->closeBox(); } @@ -1185,7 +1185,7 @@ void Controller::save() { } } -void Controller::pushSaveStage(base::lambda_once &&lambda) { +void Controller::pushSaveStage(FnMut &&lambda) { _saveStagesQueue.push_back(std::move(lambda)); } diff --git a/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp b/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp index 12abb1dc29..1cfdd2f9b6 100644 --- a/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp @@ -24,7 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { -base::lambda ManagePeerTitle( +Fn ManagePeerTitle( not_null channel) { return langFactory(channel->isMegagroup() ? lng_manage_group_title diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 95220f9b3d..0314bc5841 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -125,7 +125,7 @@ public: bool isPointAfter(QPoint position) const; void moveInAlbum(QPoint to); QPoint center() const; - void suggestMove(float64 delta, base::lambda callback); + void suggestMove(float64 delta, Fn callback); void finishAnimations(); private: @@ -520,7 +520,7 @@ QPoint AlbumThumb::center() const { return realGeometry.center(); } -void AlbumThumb::suggestMove(float64 delta, base::lambda callback) { +void AlbumThumb::suggestMove(float64 delta, Fn callback) { if (_suggestedMove != delta) { _suggestedMoveAnimation.start( std::move(callback), @@ -889,7 +889,7 @@ rpl::producer SingleFilePreview::desiredHeightValue() const { return rpl::single(st::boxPhotoPadding.top() + h + st::msgShadow); } -base::lambda FieldPlaceholder(const Storage::PreparedList &list) { +Fn FieldPlaceholder(const Storage::PreparedList &list) { return langFactory(list.files.size() > 1 ? lng_photos_comment : lng_photo_caption); diff --git a/Telegram/SourceFiles/boxes/send_files_box.h b/Telegram/SourceFiles/boxes/send_files_box.h index e9ff281ce8..4839692973 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.h +++ b/Telegram/SourceFiles/boxes/send_files_box.h @@ -46,14 +46,14 @@ public: CompressConfirm compressed); void setConfirmedCallback( - base::lambda callback) { _confirmedCallback = std::move(callback); } - void setCancelledCallback(base::lambda callback) { + void setCancelledCallback(Fn callback) { _cancelledCallback = std::move(callback); } @@ -107,12 +107,12 @@ private: CompressConfirm _compressConfirmInitial = CompressConfirm::None; CompressConfirm _compressConfirm = CompressConfirm::None; - base::lambda _confirmedCallback; - base::lambda _cancelledCallback; + Fn _cancelledCallback; bool _confirmed = false; object_ptr _caption = { nullptr }; diff --git a/Telegram/SourceFiles/boxes/sessions_box.cpp b/Telegram/SourceFiles/boxes/sessions_box.cpp index a2fc235e5d..25adc3ed28 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.cpp +++ b/Telegram/SourceFiles/boxes/sessions_box.cpp @@ -297,7 +297,7 @@ void SessionsBox::Inner::onTerminate() { for (auto i = _terminateButtons.begin(), e = _terminateButtons.end(); i != e; ++i) { if (i.value()->isOver()) { if (_terminateBox) _terminateBox->deleteLater(); - _terminateBox = Ui::show(Box(lang(lng_settings_reset_one_sure), lang(lng_settings_reset_button), st::attentionBoxButton, base::lambda_guarded(this, [this, terminating = i.key()] { + _terminateBox = Ui::show(Box(lang(lng_settings_reset_one_sure), lang(lng_settings_reset_button), st::attentionBoxButton, crl::guard(this, [this, terminating = i.key()] { if (_terminateBox) { _terminateBox->closeBox(); _terminateBox = nullptr; @@ -315,7 +315,7 @@ void SessionsBox::Inner::onTerminate() { void SessionsBox::Inner::onTerminateAll() { if (_terminateBox) _terminateBox->deleteLater(); - _terminateBox = Ui::show(Box(lang(lng_settings_reset_sure), lang(lng_settings_reset_button), st::attentionBoxButton, base::lambda_guarded(this, [this] { + _terminateBox = Ui::show(Box(lang(lng_settings_reset_sure), lang(lng_settings_reset_button), st::attentionBoxButton, crl::guard(this, [this] { if (_terminateBox) { _terminateBox->closeBox(); _terminateBox = nullptr; diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 0a3962d803..920107bfdd 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -551,7 +551,7 @@ void ShareBox::Inner::paintChat( 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, true)) , name(st::sharePhotoCheckbox.imageRadius * 2) { @@ -699,7 +699,7 @@ void ShareBox::Inner::peerUnselected(not_null peer) { } } -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 1cc9259f8e..ce3136a7cd 100644 --- a/Telegram/SourceFiles/boxes/share_box.h +++ b/Telegram/SourceFiles/boxes/share_box.h @@ -31,9 +31,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: @@ -103,7 +103,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(not_null peer); QVector selected() const; @@ -148,7 +148,7 @@ private: int displayedChatsCount() const; struct Chat { - Chat(PeerData *peer, base::lambda updateCallback); + Chat(PeerData *peer, Fn updateCallback); PeerData *peer; Ui::RoundImageCheckbox checkbox; @@ -201,7 +201,7 @@ private: using SelectedChats = OrderedSet; 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 fd1aa8d789..a6990514ac 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -431,7 +431,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 2917cbe6b3..ffab649c1a 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.h +++ b/Telegram/SourceFiles/boxes/sticker_set_box.h @@ -52,7 +52,7 @@ public: bool loaded() const; bool notInstalled() const; bool official() const; - base::lambda title() const; + Fn title() const; QString shortName() const; void install(); diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index d0f3bffafe..b5a3301ff9 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -154,10 +154,10 @@ public: 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); } @@ -280,8 +280,8 @@ private: 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 58b44134fe..e22dccd87e 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -78,7 +78,7 @@ public: 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; int nameIconWidth() const override { @@ -191,7 +191,7 @@ BoxController::Row::Type BoxController::Row::ComputeType( 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)); _actionRipple = std::make_unique(st::callReDial.ripple, std::move(mask), std::move(updateCallback)); diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index 4c1d421305..65b97134e9 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -71,7 +71,7 @@ SignalBars::SignalBars( QWidget *parent, not_null call, const style::CallSignalBars &st, - base::lambda displayedChangedCallback) + Fn displayedChangedCallback) : RpWidget(parent) , _st(st) , _displayedChangedCallback(std::move(displayedChangedCallback)) { diff --git a/Telegram/SourceFiles/calls/calls_panel.h b/Telegram/SourceFiles/calls/calls_panel.h index b8309596ee..df00ac55aa 100644 --- a/Telegram/SourceFiles/calls/calls_panel.h +++ b/Telegram/SourceFiles/calls/calls_panel.h @@ -32,7 +32,7 @@ public: QWidget *parent, not_null call, const style::CallSignalBars &st, - base::lambda displayedChangedCallback = nullptr); + Fn displayedChangedCallback = nullptr); bool isDisplayed() const; @@ -44,7 +44,7 @@ private: const style::CallSignalBars &_st; int _count = Call::kSignalBarStarting; - base::lambda _displayedChangedCallback; + Fn _displayedChangedCallback; }; diff --git a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp index beb1a8b175..46a58b9466 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp @@ -367,7 +367,7 @@ SuggestionsController::SuggestionsController(QWidget *parent, not_null callback) { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.h b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.h index abc89727ad..5ca31faaec 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.h @@ -68,7 +68,7 @@ public: SuggestionsController(QWidget *parent, not_null field); void raise(); - void setReplaceCallback(base::lambda callback); @@ -91,7 +91,7 @@ private: bool _ignoreCursorPositionChange = false; bool _textChangeAfterKeyPress = false; QPointer _field; - base::lambda _replaceCallback; diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 2941f4de7a..4da871d3f1 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -57,7 +57,7 @@ public: QWidget*, const QString &text, const QString &link, - base::lambda callback); + Fn callback); void setInnerFocus() override; @@ -67,8 +67,8 @@ protected: private: QString _startText; QString _startLink; - base::lambda _callback; - base::lambda _setInnerFocus; + Fn _callback; + Fn _setInnerFocus; }; @@ -120,7 +120,7 @@ EditLinkBox::EditLinkBox( QWidget*, const QString &text, const QString &link, - base::lambda callback) + Fn callback) : _startText(text) , _startLink(link) , _callback(std::move(callback)) { @@ -307,7 +307,7 @@ void SetClipboardWithEntities( } } -base::lambda(lang(lng_stickers_remove_group_set), base::lambda_guarded(this, [this, group = _megagroupSet] { + Ui::show(Box(lang(lng_stickers_remove_group_set), crl::guard(this, [this, group = _megagroupSet] { Expects(group->mgInfo != nullptr); if (group->mgInfo->stickerSet.type() != mtpc_inputStickerSetEmpty) { Auth().api().setGroupStickerSet(group, MTP_inputStickerSetEmpty()); @@ -2351,7 +2351,7 @@ void StickersListWidget::removeMegagroupSet(bool locally) { Ui::hideLayer(); _removingSetId = 0; emit checkForHide(); - }), base::lambda_guarded(this, [this] { + }), crl::guard(this, [this] { _removingSetId = 0; emit checkForHide(); }))); @@ -2363,7 +2363,7 @@ void StickersListWidget::removeSet(uint64 setId) { if (it != sets.cend()) { _removingSetId = it->id; auto text = lng_stickers_remove_pack(lt_sticker_pack, it->title); - Ui::show(Box(text, lang(lng_stickers_remove_pack_confirm), base::lambda_guarded(this, [this] { + Ui::show(Box(text, lang(lng_stickers_remove_pack_confirm), crl::guard(this, [this] { Ui::hideLayer(); auto &sets = Auth().data().stickerSetsRef(); auto it = sets.find(_removingSetId); @@ -2400,7 +2400,7 @@ void StickersListWidget::removeSet(uint64 setId) { } _removingSetId = 0; emit checkForHide(); - }), base::lambda_guarded(this, [this] { + }), crl::guard(this, [this] { _removingSetId = 0; emit checkForHide(); }))); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp index 495c8e232b..04f93ebed0 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_section.cpp @@ -14,7 +14,7 @@ namespace ChatHelpers { TabbedMemento::TabbedMemento( object_ptr selector, - base::lambda)> returnMethod) + Fn)> returnMethod) : _selector(std::move(selector)) , _returnMethod(std::move(returnMethod)) { } @@ -46,14 +46,14 @@ TabbedSection::TabbedSection( parent, controller, object_ptr(this, controller), - base::lambda)>()) { + Fn)>()) { } TabbedSection::TabbedSection( QWidget *parent, not_null controller, object_ptr selector, - base::lambda)> returnMethod) + Fn)> returnMethod) : Window::SectionWidget(parent, controller) , _selector(std::move(selector)) , _returnMethod(std::move(returnMethod)) { @@ -67,8 +67,8 @@ TabbedSection::TabbedSection( _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 51176a0399..5829dc6a3d 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_section.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_section.h @@ -18,7 +18,7 @@ class TabbedMemento : public Window::SectionMemento { public: TabbedMemento( object_ptr selector, - base::lambda)> returnMethod); + Fn)> returnMethod); TabbedMemento(TabbedMemento &&other) = default; TabbedMemento &operator=(TabbedMemento &&other) = default; @@ -32,7 +32,7 @@ public: private: object_ptr _selector; - base::lambda)> _returnMethod; + Fn)> _returnMethod; }; @@ -45,11 +45,11 @@ public: QWidget *parent, not_null controller, object_ptr selector, - base::lambda)> returnMethod); + Fn)> returnMethod); void beforeHiding(); void afterShown(); - void setCancelledCallback(base::lambda callback) { + void setCancelledCallback(Fn callback) { _cancelledCallback = std::move(callback); } @@ -77,8 +77,8 @@ protected: private: object_ptr _selector; - base::lambda _cancelledCallback; - base::lambda)> _returnMethod; + Fn _cancelledCallback; + Fn)> _returnMethod; }; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index b9e21b225d..2ab9d84571 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -63,10 +63,10 @@ public: 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); } @@ -187,8 +187,8 @@ private: std::array _tabs; SelectorTab _currentTabType = SelectorTab::Emoji; - base::lambda _afterShownCallback; - base::lambda _beforeHidingCallback; + Fn _afterShownCallback; + Fn _beforeHidingCallback; rpl::event_stream<> _showRequests; diff --git a/Telegram/SourceFiles/core/basic_types.h b/Telegram/SourceFiles/core/basic_types.h index 275ada1382..bf2ed209da 100644 --- a/Telegram/SourceFiles/core/basic_types.h +++ b/Telegram/SourceFiles/core/basic_types.h @@ -11,12 +11,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include +#include +#include #include "base/build_config.h" #include "base/ordered_set.h" +#include "base/unique_function.h" +#include "base/functors.h" + +namespace func = base::functors; using gsl::not_null; +template +using Fn = std::function; + +template +using FnMut = base::unique_function; + //using uchar = unsigned char; // Qt has uchar using int16 = qint16; using uint16 = quint16; @@ -28,4 +40,4 @@ using float32 = float; using float64 = double; #define qsl(s) QStringLiteral(s) -#define qstr(s) QLatin1String(s, sizeof(s) - 1) +#define qstr(s) QLatin1String((s), sizeof(s) - 1) diff --git a/Telegram/SourceFiles/core/changelogs.cpp b/Telegram/SourceFiles/core/changelogs.cpp index f4a09d4a1c..6931a6b201 100644 --- a/Telegram/SourceFiles/core/changelogs.cpp +++ b/Telegram/SourceFiles/core/changelogs.cpp @@ -177,7 +177,7 @@ void Changelogs::requestCloudLogs() { }; _session->api().requestChangelog( FormatVersionPrecise(_oldVersion), - base::lambda_guarded(this, callback)); + crl::guard(this, callback)); } void Changelogs::addLocalLogs() { diff --git a/Telegram/SourceFiles/core/click_handler.h b/Telegram/SourceFiles/core/click_handler.h index 996429e4d7..32c02a4a87 100644 --- a/Telegram/SourceFiles/core/click_handler.h +++ b/Telegram/SourceFiles/core/click_handler.h @@ -171,7 +171,7 @@ protected: class LambdaClickHandler : public ClickHandler { public: - LambdaClickHandler(base::lambda handler) : _handler(std::move(handler)) { + LambdaClickHandler(Fn handler) : _handler(std::move(handler)) { } void onClick(Qt::MouseButton button) const override final { if (button == Qt::LeftButton && _handler) { @@ -180,6 +180,6 @@ public: } private: - base::lambda _handler; + Fn _handler; }; diff --git a/Telegram/SourceFiles/core/event_filter.cpp b/Telegram/SourceFiles/core/event_filter.cpp index eb5d6890c4..9d97ba30a1 100644 --- a/Telegram/SourceFiles/core/event_filter.cpp +++ b/Telegram/SourceFiles/core/event_filter.cpp @@ -11,7 +11,7 @@ namespace Core { EventFilter::EventFilter( not_null parent, - base::lambda)> filter) + Fn)> filter) : QObject(parent) , _filter(std::move(filter)) { parent->installEventFilter(this); @@ -23,7 +23,7 @@ bool EventFilter::eventFilter(QObject *watched, QEvent *event) { not_null InstallEventFilter( not_null object, - base::lambda)> filter) { + Fn)> filter) { return new EventFilter(object, std::move(filter)); } diff --git a/Telegram/SourceFiles/core/event_filter.h b/Telegram/SourceFiles/core/event_filter.h index 3fbf71252f..f11d686f09 100644 --- a/Telegram/SourceFiles/core/event_filter.h +++ b/Telegram/SourceFiles/core/event_filter.h @@ -13,18 +13,18 @@ class EventFilter : public QObject { public: EventFilter( not_null parent, - base::lambda)> filter); + Fn)> filter); protected: bool eventFilter(QObject *watched, QEvent *event); private: - base::lambda)> _filter; + Fn)> _filter; }; not_null InstallEventFilter( not_null object, - base::lambda)> filter); + Fn)> filter); } // namespace Core diff --git a/Telegram/SourceFiles/core/file_utilities.cpp b/Telegram/SourceFiles/core/file_utilities.cpp index 1ee269c738..5c8e197260 100644 --- a/Telegram/SourceFiles/core/file_utilities.cpp +++ b/Telegram/SourceFiles/core/file_utilities.cpp @@ -154,8 +154,8 @@ void GetOpenPath( QPointer parent, const QString &caption, const QString &filter, - base::lambda callback, - base::lambda failed) { + Fn callback, + Fn failed) { InvokeQueued(QApplication::instance(), [=] { auto files = QStringList(); auto remoteContent = QByteArray(); @@ -187,8 +187,8 @@ void GetOpenPaths( QPointer parent, const QString &caption, const QString &filter, - base::lambda callback, - base::lambda failed) { + Fn callback, + Fn failed) { InvokeQueued(QApplication::instance(), [=] { auto files = QStringList(); auto remoteContent = QByteArray(); @@ -217,8 +217,8 @@ void GetWritePath( const QString &caption, const QString &filter, const QString &initialPath, - base::lambda callback, - base::lambda failed) { + Fn callback, + Fn failed) { InvokeQueued(QApplication::instance(), [=] { auto file = QString(); if (filedialogGetSaveFile(parent, file, caption, filter, initialPath)) { @@ -235,8 +235,8 @@ void GetFolder( QPointer parent, const QString &caption, const QString &initialPath, - base::lambda callback, - base::lambda failed) { + Fn callback, + Fn failed) { InvokeQueued(QApplication::instance(), [=] { auto files = QStringList(); auto remoteContent = QByteArray(); diff --git a/Telegram/SourceFiles/core/file_utilities.h b/Telegram/SourceFiles/core/file_utilities.h index d9ab99d4ef..d7a186a786 100644 --- a/Telegram/SourceFiles/core/file_utilities.h +++ b/Telegram/SourceFiles/core/file_utilities.h @@ -57,27 +57,27 @@ void GetOpenPath( QPointer parent, const QString &caption, const QString &filter, - base::lambda callback, - base::lambda failed = base::lambda()); + Fn callback, + Fn failed = Fn()); void GetOpenPaths( QPointer parent, const QString &caption, const QString &filter, - base::lambda callback, - base::lambda failed = base::lambda()); + Fn callback, + Fn failed = Fn()); void GetWritePath( QPointer parent, const QString &caption, const QString &filter, const QString &initialPath, - base::lambda callback, - base::lambda failed = base::lambda()); + Fn callback, + Fn failed = Fn()); void GetFolder( QPointer parent, const QString &caption, const QString &initialPath, - base::lambda callback, - base::lambda failed = base::lambda()); + Fn callback, + Fn failed = Fn()); QString AllFilesFilter(); diff --git a/Telegram/SourceFiles/core/single_timer.cpp b/Telegram/SourceFiles/core/single_timer.cpp index 38778ec789..81eeaad175 100644 --- a/Telegram/SourceFiles/core/single_timer.cpp +++ b/Telegram/SourceFiles/core/single_timer.cpp @@ -14,7 +14,7 @@ SingleTimer::SingleTimer(QObject *parent) : QTimer(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 ef8de8e5e2..c031b170d7 100644 --- a/Telegram/SourceFiles/core/single_timer.h +++ b/Telegram/SourceFiles/core/single_timer.h @@ -18,7 +18,7 @@ public: 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); @@ -30,6 +30,6 @@ private slots: private: TimeMs _finishing = 0; - base::lambda _handler; + Fn _handler; }; diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 108367a9c4..27a5a14866 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -211,8 +211,8 @@ public: template void send( const T &request, - base::lambda done, - base::lambda fail, + Fn done, + Fn fail, MTP::ShiftedDcId dcId = 0); bool valid() const; @@ -225,7 +225,7 @@ private: bool removeRequest(mtpRequestId requestId); QPointer _instance; - std::map> _requests; + std::map> _requests; }; @@ -248,11 +248,11 @@ private: }; using Checker::fail; - base::lambda failHandler(); + Fn failHandler(); void resolveChannel( const QString &username, - base::lambda callback); + Fn callback); void gotMessage(const MTPmessages_Messages &result); base::optional parseMessage( const MTPmessages_Messages &result) const; @@ -285,7 +285,7 @@ private: void startLoading() override; void sendRequest(); void gotPart(int offset, const MTPupload_File &result); - base::lambda failHandler(); + Fn failHandler(); static constexpr auto kRequestsCount = 2; static constexpr auto kNextRequestDelay = TimeMs(20); @@ -891,8 +891,7 @@ HttpChecker::HttpChecker(bool testing) : Checker(testing) { void HttpChecker::start() { auto url = QUrl(Local::readAutoupdatePrefix() + qstr("/current")); - DEBUG_LOG(("Update Info: requesting update state from '%1'" - ).arg(url.toDisplayString())); + DEBUG_LOG(("Update Info: requesting update state")); const auto request = QNetworkRequest(url); _manager = std::make_unique(); _reply = _manager->get(request); @@ -1193,8 +1192,8 @@ void MtpWeak::die() { template void MtpWeak::send( const T &request, - base::lambda done, - base::lambda fail, + Fn done, + Fn fail, MTP::ShiftedDcId dcId) { using Response = typename T::ResponseType; if (!valid()) { @@ -1203,14 +1202,14 @@ void MtpWeak::send( }); return; } - const auto onDone = base::lambda_guarded(this, [=]( + const auto onDone = crl::guard((QObject*)this, [=]( const Response &result, mtpRequestId requestId) { if (removeRequest(requestId)) { done(result); } }); - const auto onFail = base::lambda_guarded(this, [=]( + const auto onFail = crl::guard((QObject*)this, [=]( const RPCError &error, mtpRequestId requestId) { if (MTP::isDefaultHandledError(error)) { @@ -1277,7 +1276,7 @@ void MtpChecker::start() { void MtpChecker::resolveChannel( const QString &username, - base::lambda callback) { + Fn callback) { const auto failed = [&] { LOG(("Update Error: MTP channel '%1' resolve failed." ).arg(username)); @@ -1467,7 +1466,7 @@ auto MtpChecker::parseFile(const MTPmessages_Messages &result) const return ParsedFile { name, size, fields.vdc_id.v, location }; } -base::lambda MtpChecker::failHandler() { +Fn MtpChecker::failHandler() { return [=](const RPCError &error) { LOG(("Update Error: MTP check failed with '%1'" ).arg(QString::number(error.code()) + ':' + error.type())); @@ -1549,7 +1548,7 @@ void MtpLoader::gotPart(int offset, const MTPupload_File &result) { sendRequest(); } -base::lambda MtpLoader::failHandler() { +Fn MtpLoader::failHandler() { return [=](const RPCError &error) { LOG(("Update Error: MTP load failed with '%1'" ).arg(QString::number(error.code()) + ':' + error.type())); diff --git a/Telegram/SourceFiles/data/data_sparse_ids.cpp b/Telegram/SourceFiles/data/data_sparse_ids.cpp index bf55cb4cb1..e75aa4ca14 100644 --- a/Telegram/SourceFiles/data/data_sparse_ids.cpp +++ b/Telegram/SourceFiles/data/data_sparse_ids.cpp @@ -399,7 +399,7 @@ rpl::producer SparseIdsMergedSlice::CreateViewer( SparseIdsMergedSlice::Key key, int limitBefore, int limitAfter, - base::lambda simpleViewer) { + Fn simpleViewer) { Expects(IsServerMsgId(key.universalId) || (key.universalId == 0) || (IsServerMsgId(ServerMaxMsgId + key.universalId) && key.migratedPeerId != 0)); diff --git a/Telegram/SourceFiles/data/data_sparse_ids.h b/Telegram/SourceFiles/data/data_sparse_ids.h index 487fb6fca5..3198d4748c 100644 --- a/Telegram/SourceFiles/data/data_sparse_ids.h +++ b/Telegram/SourceFiles/data/data_sparse_ids.h @@ -96,7 +96,7 @@ public: SparseIdsMergedSlice::Key key, int limitBefore, int limitAfter, - base::lambda simpleViewer); + Fn simpleViewer); private: static SparseIdsSlice::Key PartKey(const Key &key) { diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 37bb04ef4c..8606cd9911 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -1519,7 +1519,7 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) { Window::FillPeerMenu( _controller, history->peer, - [&](const QString &text, base::lambda callback) { + [&](const QString &text, Fn callback) { return _menu->addAction(text, std::move(callback)); }, Window::PeerMenuSource::ChatsList); @@ -1527,7 +1527,7 @@ void DialogsInner::contextMenuEvent(QContextMenuEvent *e) { Window::FillFeedMenu( _controller, feed, - [&](const QString &text, base::lambda callback) { + [&](const QString &text, Fn callback) { return _menu->addAction(text, std::move(callback)); }, Window::PeerMenuSource::ChatsList); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index 9f6f033a03..ee62a035b5 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -102,7 +102,7 @@ public: PeerData *updateFromParentDrag(QPoint globalPos); - void setLoadMoreCallback(base::lambda callback) { + void setLoadMoreCallback(Fn callback) { _loadMoreCallback = std::move(callback); } @@ -357,7 +357,7 @@ private: Text _searchFromUserText; Dialogs::Key _menuKey; - base::lambda _loadMoreCallback; + Fn _loadMoreCallback; base::unique_qptr _menu; diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.cpp b/Telegram/SourceFiles/dialogs/dialogs_row.cpp index 0a9abc77a7..8aa4cb0a3b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_row.cpp @@ -17,7 +17,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 92e098b2fa..756cc88d3c 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.h +++ b/Telegram/SourceFiles/dialogs/dialogs_row.h @@ -27,7 +27,7 @@ public: 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 b4f9267c16..fca5ef2359 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp @@ -18,8 +18,8 @@ namespace Dialogs { void ShowSearchFromBox( not_null navigation, not_null peer, - base::lambda)> callback, - base::lambda closedCallback) { + Fn)> callback, + Fn closedCallback) { auto createController = [ navigation, peer, @@ -54,7 +54,7 @@ void ShowSearchFromBox( ChatSearchFromController::ChatSearchFromController( not_null navigation, not_null chat, - base::lambda)> callback) + Fn)> callback) : PeerListController() , _chat(chat) , _callback(std::move(callback)) { @@ -128,7 +128,7 @@ void ChatSearchFromController::appendRow(not_null user) { ChannelSearchFromController::ChannelSearchFromController( not_null navigation, not_null channel, - base::lambda)> callback) + Fn)> callback) : ParticipantsBoxController( navigation, channel, diff --git a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h index 25c133f923..2198375f2f 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h +++ b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.h @@ -15,15 +15,15 @@ namespace Dialogs { void ShowSearchFromBox( not_null navigation, not_null peer, - base::lambda)> callback, - base::lambda closedCallback); + Fn)> callback, + Fn closedCallback); class ChatSearchFromController : public PeerListController, protected base::Subscriber { public: ChatSearchFromController( not_null navigation, not_null chat, - base::lambda)> callback); + Fn)> callback); void prepare() override; void rowClicked(not_null row) override; @@ -34,7 +34,7 @@ private: void appendRow(not_null user); not_null _chat; - base::lambda)> _callback; + Fn)> _callback; }; @@ -43,7 +43,7 @@ public: ChannelSearchFromController( not_null navigation, not_null channel, - base::lambda)> callback); + Fn)> callback); void prepare() override; void rowClicked(not_null row) override; @@ -52,7 +52,7 @@ protected: std::unique_ptr createRow(not_null user) const override; private: - base::lambda)> _callback; + Fn)> _callback; }; diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 6972b8f1cf..4e888f7ce8 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -1078,13 +1078,13 @@ void DialogsWidget::showSearchFrom() { Dialogs::ShowSearchFromBox( controller(), peer, - base::lambda_guarded(this, [=]( + crl::guard(this, [=]( not_null user) { Ui::hideLayer(); setSearchInChat(chat, user); onFilterUpdate(true); }), - base::lambda_guarded(this, [this] { _filter->setFocus(); })); + crl::guard(this, [this] { _filter->setFocus(); })); } } diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index f4a9520b4a..7deb2a4d47 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -31,7 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL 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 0df55026fd..8e90cffa14 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -25,55 +25,30 @@ class ItemBase; namespace App { namespace internal { -void CallDelayed(int duration, base::lambda_once &&lambda); +void CallDelayed(int duration, FnMut &&lambda); } // namespace internal -template +template inline void CallDelayed( int duration, - base::lambda_internal::guard_with_QObject &&guarded) { + crl::guarded_wrap &&guarded) { return internal::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 void CallDelayed(int duration, Guard &&object, Lambda &&lambda) { + return internal::CallDelayed(duration, crl::guard( + std::forward(object), + std::forward(lambda))); } -template -inline void CallDelayed( - int duration, - const QObject *object, - Lambda &&lambda) { - return internal::CallDelayed( - duration, - base::lambda_guarded(object, std::forward(lambda))); -} - -template -inline void CallDelayed( - int duration, - const base::has_weak_ptr *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, +template +inline auto LambdaDelayed(int duration, Guard &&object, Lambda &&lambda) { + auto guarded = crl::guard( + std::forward(object), std::forward(lambda)); return [saved = std::move(guarded), duration] { auto copy = saved; @@ -81,46 +56,6 @@ inline auto LambdaDelayed( }; } -template -inline auto LambdaDelayed( - int duration, - const base::has_weak_ptr *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::has_weak_ptr *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, diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp index b8f5799ed5..ae7cb41e69 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp @@ -134,7 +134,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); + Inner(QWidget *parent, not_null channel, const std::vector> &admins, const FilterValue &filter, Fn changedCallback); template QPointer addRow(object_ptr widget, int marginTop) { @@ -176,11 +176,11 @@ private: }; 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) : TWidget(parent) +FilterBox::Inner::Inner(QWidget *parent, not_null channel, const std::vector> &admins, const FilterValue &filter, Fn changedCallback) : TWidget(parent) , _channel(channel) , _changedCallback(std::move(changedCallback)) { createControls(admins, filter); @@ -344,7 +344,7 @@ void FilterBox::Inner::resizeEvent(QResizeEvent *e) { } } -FilterBox::FilterBox(QWidget*, not_null channel, const std::vector> &admins, const FilterValue &filter, base::lambda saveCallback) : BoxContent() +FilterBox::FilterBox(QWidget*, not_null channel, const std::vector> &admins, const FilterValue &filter, Fn saveCallback) : BoxContent() , _channel(channel) , _admins(admins) , _initialFilter(filter) diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.h index 7cabcfd8c6..0d21cc7558 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.h @@ -14,7 +14,7 @@ namespace AdminLog { class FilterBox : public BoxContent { public: - FilterBox(QWidget*, not_null channel, const std::vector> &admins, const FilterValue &filter, base::lambda saveCallback); + FilterBox(QWidget*, not_null channel, const std::vector> &admins, const FilterValue &filter, Fn saveCallback); protected: void prepare() override; @@ -26,7 +26,7 @@ private: not_null _channel; std::vector> _admins; FilterValue _initialFilter; - base::lambda _saveCallback; + Fn _saveCallback; class Inner; QPointer _inner; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index b68847cfd8..bdea6dbe41 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -419,7 +419,7 @@ void InnerWidget::requestAdmins() { }).send(); } -void InnerWidget::showFilter(base::lambda callback) { +void InnerWidget::showFilter(Fn callback) { if (_admins.empty()) { _showFilterCallback = std::move(callback); } else { @@ -1089,7 +1089,7 @@ void InnerWidget::savePhotoToFile(PhotoData *photo) { lang(lng_save_photo), filter, filedialogDefaultName(qsl("photo"), qsl(".jpg")), - base::lambda_guarded(this, [=](const QString &result) { + crl::guard(this, [=](const QString &result) { if (!result.isEmpty()) { photo->full->pix().toImage().save(result, "JPG"); } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index f79ae176f3..2835e659e9 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -69,7 +69,7 @@ public: // Empty "flags" means all events. void applyFilter(FilterValue &&value); void applySearch(const QString &query); - void showFilter(base::lambda callback); + void showFilter(Fn callback); // Ui::AbstractTooltipShower interface. QString tooltipText() const override; @@ -260,7 +260,7 @@ private: QString _searchQuery; std::vector> _admins; std::vector> _adminsCanEdit; - base::lambda _showFilterCallback; + Fn _showFilterCallback; std::shared_ptr _idManager; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index c45c08394a..5fcd21144a 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -327,7 +327,7 @@ void GenerateItems( not_null history, not_null idManager, const MTPDchannelAdminLogEvent &event, - base::lambda callback) { + Fn callback) { Expects(history->peer->isChannel()); auto id = event.vid.v; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.h index 05cc07132b..b29ea016b9 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.h @@ -22,7 +22,7 @@ void GenerateItems( not_null history, not_null idManager, const MTPDchannelAdminLogEvent &event, - base::lambda callback); + Fn callback); // Smart pointer wrapper for HistoryItem* that destroys the owned item. class OwnedItem { diff --git a/Telegram/SourceFiles/history/history_drag_area.h b/Telegram/SourceFiles/history/history_drag_area.h index b3556d5db4..a17e3d4f45 100644 --- a/Telegram/SourceFiles/history/history_drag_area.h +++ b/Telegram/SourceFiles/history/history_drag_area.h @@ -24,7 +24,7 @@ public: void hideFast(); - void setDroppedCallback(base::lambda callback) { + void setDroppedCallback(Fn callback) { _droppedCallback = std::move(callback); } @@ -57,7 +57,7 @@ private: 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_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index c01dc71b8a..1aeef5607d 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1744,7 +1744,7 @@ void HistoryInner::savePhotoToFile(not_null photo) { filedialogDefaultName( qsl("photo"), qsl(".jpg")), - base::lambda_guarded(this, [=](const QString &result) { + crl::guard(this, [=](const QString &result) { if (!result.isEmpty()) { photo->full->pix().toImage().save(result, "JPG"); } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 9d3794bb57..0354ed9cab 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -209,15 +209,15 @@ void FastShareMessage(not_null item) { return false; }; auto copyLinkCallback = canCopyLink - ? base::lambda(std::move(copyCallback)) - : base::lambda(); + ? Fn(std::move(copyCallback)) + : Fn(); Ui::show(Box( std::move(copyLinkCallback), std::move(submitCallback), std::move(filterCallback))); } -base::lambda HistoryDependentItemCallback( +Fn HistoryDependentItemCallback( const FullMsgId &msgId) { return [dependent = msgId](ChannelData *channel, MsgId msgId) { if (auto item = App::histItemById(dependent)) { diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 2bb07e49ac..e0280d94d7 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -15,7 +15,7 @@ class Message; struct HistoryMessageEdited; -base::lambda HistoryDependentItemCallback( +Fn HistoryDependentItemCallback( const FullMsgId &msgId); MTPDmessage::Flags NewMessageFlags(not_null peer); QString GetErrorTextForForward( diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 698b9b4062..12658c91b9 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -3221,7 +3221,7 @@ void HistoryWidget::chooseAttach() { auto filter = FileDialog::AllFilesFilter() + qsl(";;Image files (*") + cImgExtensions().join(qsl(" *")) + qsl(")"); - FileDialog::GetOpenPaths(this, lang(lng_choose_files), filter, base::lambda_guarded(this, [this](FileDialog::OpenResult &&result) { + FileDialog::GetOpenPaths(this, lang(lng_choose_files), filter, crl::guard(this, [this](FileDialog::OpenResult &&result) { if (result.paths.isEmpty() && result.remoteContent.isEmpty()) { return; } @@ -3891,7 +3891,7 @@ void HistoryWidget::pushTabbedSelectorToThirdSection( auto destroyingPanel = std::move(_tabbedPanel); auto memento = ChatHelpers::TabbedMemento( destroyingPanel->takeSelector(), - base::lambda_guarded(this, [this]( + crl::guard(this, [this]( object_ptr selector) { returnTabbedSelector(std::move(selector)); })); @@ -4179,7 +4179,7 @@ bool HistoryWidget::confirmSendingFiles( text, boxCompressConfirm); _field->setTextWithTags({}); - box->setConfirmedCallback(base::lambda_guarded(this, [=]( + box->setConfirmedCallback(crl::guard(this, [=]( Storage::PreparedList &&list, SendFilesWay way, TextWithTags &&caption, @@ -4200,7 +4200,7 @@ bool HistoryWidget::confirmSendingFiles( replyToId(), album); })); - box->setCancelledCallback(base::lambda_guarded(this, [=] { + box->setCancelledCallback(crl::guard(this, [=] { _field->setTextWithTags(text); auto cursor = _field->textCursor(); cursor.setPosition(anchor); @@ -4611,7 +4611,7 @@ void HistoryWidget::documentFailed(const FullMsgId &newId) { void HistoryWidget::onReportSpamClicked() { auto text = lang(_peer->isUser() ? lng_report_spam_sure : ((_peer->isChat() || _peer->isMegagroup()) ? lng_report_spam_sure_group : lng_report_spam_sure_channel)); - Ui::show(Box(text, lang(lng_report_spam_ok), st::attentionBoxButton, base::lambda_guarded(this, [this, peer = _peer] { + Ui::show(Box(text, lang(lng_report_spam_ok), st::attentionBoxButton, crl::guard(this, [this, peer = _peer] { if (_reportSpamRequest) return; Ui::hideLayer(); @@ -5840,7 +5840,7 @@ void HistoryWidget::replyToMessage(not_null item) { Ui::show(Box(lang(lng_reply_cant))); } else { const auto itemId = item->fullId(); - Ui::show(Box(lang(lng_reply_cant_forward), lang(lng_selected_forward), base::lambda_guarded(this, [=] { + Ui::show(Box(lang(lng_reply_cant_forward), lang(lng_selected_forward), crl::guard(this, [=] { App::main()->setForwardDraft( _peer->id, { 1, itemId }); @@ -5965,7 +5965,7 @@ void HistoryWidget::unpinMessage(FullMsgId itemId) { return; } - Ui::show(Box(lang(lng_pinned_unpin_sure), lang(lng_pinned_unpin), base::lambda_guarded(this, [=] { + Ui::show(Box(lang(lng_pinned_unpin_sure), lang(lng_pinned_unpin), crl::guard(this, [=] { channel->clearPinnedMessage(); Ui::hideLayer(); @@ -6318,7 +6318,7 @@ void HistoryWidget::onCancel() { lang(lng_cancel_edit_post_sure), lang(lng_cancel_edit_post_yes), lang(lng_cancel_edit_post_no), - base::lambda_guarded(this, [this] { + crl::guard(this, [this] { if (_editMsgId) { cancelEdit(); Ui::hideLayer(); diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 585052b9ae..cc71185e86 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -53,7 +53,7 @@ void SavePhotoToFile(not_null photo) { lang(lng_save_photo), qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter(), filedialogDefaultName(qsl("photo"), qsl(".jpg")), - base::lambda_guarded(&Auth(), [=](const QString &result) { + crl::guard(&Auth(), [=](const QString &result) { if (!result.isEmpty()) { photo->full->pix().toImage().save(result, "JPG"); } @@ -474,7 +474,7 @@ base::unique_qptr FillContextMenu( && (list->delegate()->listContext() == Context::Feed)) { Window::PeerMenuAddMuteAction(peer, [&]( const QString &text, - base::lambda handler) { + Fn handler) { return result->addAction(text, handler); }); AddToggleGroupingAction(result, linkPeer->peer()); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 3b5233c25b..013255c076 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -187,12 +187,12 @@ void TopBarWidget::showMenu() { weak->_menuToggle->setForceRippled(false); } }); - _menu->setShowStartCallback(base::lambda_guarded(this, [this, menu = _menu.data()] { + _menu->setShowStartCallback(crl::guard(this, [this, menu = _menu.data()] { if (_menu == menu) { _menuToggle->setForceRippled(true); } })); - _menu->setHideStartCallback(base::lambda_guarded(this, [this, menu = _menu.data()] { + _menu->setHideStartCallback(crl::guard(this, [this, menu = _menu.data()] { if (_menu == menu) { _menuToggle->setForceRippled(false); } @@ -200,7 +200,7 @@ void TopBarWidget::showMenu() { _menuToggle->installEventFilter(_menu); const auto addAction = [&]( const QString &text, - base::lambda callback) { + Fn callback) { return _menu->addAction(text, std::move(callback)); }; if (const auto peer = _activeChat.peer()) { diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp index da22554953..c8f2645ac4 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp @@ -238,11 +238,11 @@ object_ptr InnerWidget::setupList( return result; } -void InnerWidget::peerListSetTitle(base::lambda title) { +void InnerWidget::peerListSetTitle(Fn title) { } void InnerWidget::peerListSetAdditionalTitle( - base::lambda title) { + Fn title) { } bool InnerWidget::peerListIsRowSelected(not_null peer) { diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h index 3df6115bba..68b08951c6 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h @@ -48,9 +48,9 @@ private: using ListWidget = PeerListContent; // PeerListContentDelegate interface. - void peerListSetTitle(base::lambda title) override; + void peerListSetTitle(Fn title) override; void peerListSetAdditionalTitle( - base::lambda title) override; + Fn title) override; bool peerListIsRowSelected(not_null peer) override; int peerListSelectedRowsCount() override; std::vector> peerListCollectSelectedRows() override; diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels.cpp b/Telegram/SourceFiles/info/feed/info_feed_channels.cpp index 9650f1a8bb..124c885637 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels.cpp +++ b/Telegram/SourceFiles/info/feed/info_feed_channels.cpp @@ -289,11 +289,11 @@ void Channels::visibleTopBottomUpdated( setChildVisibleTopBottom(_list, visibleTop, visibleBottom); } -void Channels::peerListSetTitle(base::lambda title) { +void Channels::peerListSetTitle(Fn title) { } void Channels::peerListSetAdditionalTitle( - base::lambda title) { + Fn title) { } bool Channels::peerListIsRowSelected(not_null peer) { diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels.h b/Telegram/SourceFiles/info/feed/info_feed_channels.h index 013df7cedb..fd14462174 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels.h +++ b/Telegram/SourceFiles/info/feed/info_feed_channels.h @@ -61,9 +61,9 @@ private: using ListWidget = PeerListContent; // PeerListContentDelegate interface. - void peerListSetTitle(base::lambda title) override; + void peerListSetTitle(Fn title) override; void peerListSetAdditionalTitle( - base::lambda title) override; + Fn title) override; bool peerListIsRowSelected(not_null peer) override; int peerListSelectedRowsCount() override; std::vector> peerListCollectSelectedRows() override; diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp index 42592d8e6b..b7b7548a4d 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp +++ b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp @@ -195,7 +195,7 @@ base::unique_qptr ChannelsController::rowContextMenu( auto result = base::make_unique_q(nullptr); Window::PeerMenuAddMuteAction(channel, [&]( const QString &text, - base::lambda handler) { + Fn handler) { return result->addAction(text, handler); }); //result->addAction( // #feed diff --git a/Telegram/SourceFiles/info/info_top_bar.h b/Telegram/SourceFiles/info/info_top_bar.h index edb91452c5..3b28dcf5cb 100644 --- a/Telegram/SourceFiles/info/info_top_bar.h +++ b/Telegram/SourceFiles/info/info_top_bar.h @@ -134,7 +134,7 @@ private: QPointer> _delete; rpl::event_stream<> _cancelSelectionClicks; - using UpdateCallback = base::lambda; + using UpdateCallback = Fn; std::map _updateControlCallbacks; }; diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 72b1527c23..51a05ba052 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -497,7 +497,7 @@ void WrapWidget::showProfileMenu() { const auto addAction = [=]( const QString &text, - base::lambda callback) { + Fn callback) { return _topBarMenu->addAction(text, std::move(callback)); }; if (const auto peer = key().peer()) { diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 266534fc31..c9774cd36a 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1297,20 +1297,20 @@ void ListWidget::showContextMenu( if (canForwardAll()) { _contextMenu->addAction( lang(lng_context_forward_selected), - base::lambda_guarded(this, [this] { + crl::guard(this, [this] { forwardSelected(); })); } if (canDeleteAll()) { _contextMenu->addAction( lang(lng_context_delete_selected), - base::lambda_guarded(this, [this] { + crl::guard(this, [this] { deleteSelected(); })); } _contextMenu->addAction( lang(lng_context_clear_selection), - base::lambda_guarded(this, [this] { + crl::guard(this, [this] { clearSelected(); })); } else { @@ -1318,21 +1318,21 @@ void ListWidget::showContextMenu( if (item->allowsForward()) { _contextMenu->addAction( lang(lng_context_forward_msg), - base::lambda_guarded(this, [this, universalId] { + crl::guard(this, [this, universalId] { forwardItem(universalId); })); } if (item->canDelete()) { _contextMenu->addAction( lang(lng_context_delete_msg), - base::lambda_guarded(this, [this, universalId] { + crl::guard(this, [this, universalId] { deleteItem(universalId); })); } } _contextMenu->addAction( lang(lng_context_select_msg), - base::lambda_guarded(this, [this, universalId] { + crl::guard(this, [this, universalId] { if (hasSelectedText()) { clearSelected(); } else if (_selected.size() == MaxSelectedItems) { @@ -1344,7 +1344,7 @@ void ListWidget::showContextMenu( })); } - _contextMenu->setDestroyedCallback(base::lambda_guarded( + _contextMenu->setDestroyedCallback(crl::guard( this, [this, universalId] { _contextMenu = nullptr; diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index 798a5b3e0d..4b3b0ede62 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -34,7 +34,7 @@ public: SectionToggle( const style::InfoToggle &st, bool checked, - base::lambda updateCallback); + Fn updateCallback); QSize getSize() const override; void paint( @@ -56,7 +56,7 @@ private: SectionToggle::SectionToggle( const style::InfoToggle &st, bool checked, - base::lambda updateCallback) + Fn updateCallback) : AbstractCheckView(st.duration, checked, std::move(updateCallback)) , _st(st) { } diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.cpp b/Telegram/SourceFiles/info/profile/info_profile_members.cpp index aa41986e4a..175526386c 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members.cpp @@ -409,11 +409,11 @@ void Members::visibleTopBottomUpdated( setChildVisibleTopBottom(_list, visibleTop, visibleBottom); } -void Members::peerListSetTitle(base::lambda title) { +void Members::peerListSetTitle(Fn title) { } void Members::peerListSetAdditionalTitle( - base::lambda title) { + Fn title) { } bool Members::peerListIsRowSelected(not_null peer) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.h b/Telegram/SourceFiles/info/profile/info_profile_members.h index 8e3aed0bae..5fcf81b726 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.h +++ b/Telegram/SourceFiles/info/profile/info_profile_members.h @@ -63,9 +63,9 @@ private: using ListWidget = PeerListContent; // PeerListContentDelegate interface. - void peerListSetTitle(base::lambda title) override; + void peerListSetTitle(Fn title) override; void peerListSetAdditionalTitle( - base::lambda title) override; + Fn title) override; bool peerListIsRowSelected(not_null peer) override; int peerListSelectedRowsCount() override; std::vector> peerListCollectSelectedRows() override; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index d021cd37fd..b78dcea8dc 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -422,7 +422,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 b7aae64f4d..9d682bc0e0 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.h @@ -69,7 +69,7 @@ public: int countHeight(); - void setResultSelectedCallback(base::lambda callback) { + void setResultSelectedCallback(Fn callback) { _resultSelectedCallback = std::move(callback); } @@ -150,7 +150,7 @@ private: QTimer _previewTimer; bool _previewShown = false; - base::lambda _resultSelectedCallback; + Fn _resultSelectedCallback; }; @@ -177,7 +177,7 @@ public: 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 f1d6d33766..d8f23f501e 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -17,7 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Intro { -CodeInput::CodeInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory) : Ui::MaskedInputField(parent, st, std::move(placeholderFactory)) { +CodeInput::CodeInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory) : Ui::MaskedInputField(parent, st, std::move(placeholderFactory)) { } void CodeInput::setDigitsCountMax(int digitsCount) { @@ -145,7 +145,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 37c510a0ee..27cd2b3711 100644 --- a/Telegram/SourceFiles/intro/introcode.h +++ b/Telegram/SourceFiles/intro/introcode.h @@ -22,7 +22,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); @@ -71,7 +71,7 @@ private: 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 0b33ec9149..46363d1d70 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -93,7 +93,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 975d9b0a48..be12eb4f1b 100644 --- a/Telegram/SourceFiles/intro/introphone.h +++ b/Telegram/SourceFiles/intro/introphone.h @@ -57,7 +57,7 @@ private: QString fullNumber() const; void stopCheck(); - void showPhoneError(base::lambda textFactory); + void showPhoneError(Fn textFactory); void hidePhoneError(); //void showSignup(); diff --git a/Telegram/SourceFiles/intro/intropwdcheck.cpp b/Telegram/SourceFiles/intro/intropwdcheck.cpp index b4bcb64338..008ca21629 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.cpp +++ b/Telegram/SourceFiles/intro/intropwdcheck.cpp @@ -277,7 +277,7 @@ void PwdCheckWidget::submit() { _codeField->showError(); return; } - const auto send = base::lambda_guarded(this, [=] { + const auto send = crl::guard(this, [=] { _sentRequest = MTP::send( MTPauth_RecoverPassword(MTP_string(code)), rpcDone(&PwdCheckWidget::pwdSubmitDone, true), diff --git a/Telegram/SourceFiles/intro/introsignup.cpp b/Telegram/SourceFiles/intro/introsignup.cpp index 299221ca45..97b0cb61fd 100644 --- a/Telegram/SourceFiles/intro/introsignup.cpp +++ b/Telegram/SourceFiles/intro/introsignup.cpp @@ -221,7 +221,7 @@ void SignupWidget::submit() { || !getData()->termsPopup) { send(); } else { - acceptTerms(base::lambda_guarded(this, [=] { + acceptTerms(crl::guard(this, [=] { _termsAccepted = true; send(); })); diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index aaacdbe944..17287a0bb1 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -48,8 +48,8 @@ public: TermsBox( QWidget*, const TextWithEntities &text, - base::lambda agree, - base::lambda cancel, + Fn agree, + Fn cancel, int age = 0); rpl::producer<> agreeClicks() const; @@ -62,8 +62,8 @@ protected: private: TextWithEntities _text; - base::lambda _agree; - base::lambda _cancel; + Fn _agree; + Fn _cancel; int _age = 0; rpl::event_stream<> _agreeClicks; rpl::event_stream<> _cancelClicks; @@ -73,8 +73,8 @@ private: TermsBox::TermsBox( QWidget*, const TextWithEntities &text, - base::lambda agree, - base::lambda cancel, + Fn agree, + Fn cancel, int age) : _text(text) , _agree(agree) @@ -161,7 +161,7 @@ Widget::Widget(QWidget *parent) : RpWidget(parent) this, langFactory(lng_menu_settings), st::defaultBoxButton)) -, _next(this, base::lambda(), st::introNextButton) { +, _next(this, Fn(), st::introNextButton) { auto country = Platform::SystemCountry(); if (country.isEmpty()) { country = str_const_toString(kDefaultCountry); @@ -392,7 +392,7 @@ void Widget::appendStep(Step *step) { step->setShowTermsCallback([=]() { showTerms(); }); - step->setAcceptTermsCallback([=](base::lambda callback) { + step->setAcceptTermsCallback([=](Fn callback) { acceptTerms(callback); }); } @@ -438,14 +438,14 @@ void Widget::showTerms() { } } -void Widget::acceptTerms(base::lambda callback) { +void Widget::acceptTerms(Fn callback) { showTerms(callback); } void Widget::resetAccount() { if (_resetRequest) return; - Ui::show(Box(lang(lng_signin_sure_reset), lang(lng_signin_reset), st::attentionBoxButton, base::lambda_guarded(this, [this] { + Ui::show(Box(lang(lng_signin_sure_reset), lang(lng_signin_reset), st::attentionBoxButton, crl::guard(this, [this] { if (_resetRequest) return; _resetRequest = request(MTPaccount_DeleteAccount(MTP_string("Forgot password"))).done([this](const MTPBool &result) { _resetRequest = 0; @@ -497,7 +497,7 @@ void Widget::getNearestDC() { }).send(); } -void Widget::showTerms(base::lambda callback) { +void Widget::showTerms(Fn callback) { if (getData()->termsText.text.isEmpty()) { return; } @@ -755,7 +755,7 @@ void Widget::Step::updateLabelsPosition() { } } -void Widget::Step::setTitleText(base::lambda richTitleTextFactory) { +void Widget::Step::setTitleText(Fn richTitleTextFactory) { _titleTextFactory = std::move(richTitleTextFactory); refreshTitle(); updateLabelsPosition(); @@ -765,7 +765,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(); @@ -967,7 +967,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(); @@ -1074,20 +1074,20 @@ 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); } -void Widget::Step::setShowTermsCallback(base::lambda callback) { +void Widget::Step::setShowTermsCallback(Fn callback) { _showTermsCallback = std::move(callback); } void Widget::Step::setAcceptTermsCallback( - base::lambda callback)> callback) { + Fn callback)> callback) { _acceptTermsCallback = std::move(callback); } diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index cec682ee16..9de0d94437 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -102,12 +102,12 @@ public: } void setGoCallback( - base::lambda callback); - void setShowResetCallback(base::lambda callback); + Fn callback); + void setShowResetCallback(Fn callback); void setShowTermsCallback( - base::lambda callback); + Fn callback); void setAcceptTermsCallback( - base::lambda callback)> callback); + Fn callback)> callback); void prepareShowAnimated(Step *after); void showAnimated(Direction direction); @@ -128,9 +128,9 @@ public: 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(); @@ -139,8 +139,8 @@ public: 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 MTPDauth_sentCode &type); @@ -168,7 +168,7 @@ public: void showTerms() { if (_showTermsCallback) _showTermsCallback(); } - void acceptTerms(base::lambda callback) { + void acceptTerms(Fn callback) { if (_acceptTermsCallback) { _acceptTermsCallback(callback); } @@ -205,20 +205,20 @@ public: Data *_data = nullptr; bool _hasCover = false; - base::lambda _goCallback; - base::lambda _showResetCallback; - base::lambda _showTermsCallback; - base::lambda callback)> _acceptTermsCallback; + Fn _goCallback; + Fn _showResetCallback; + Fn _showTermsCallback; + Fn callback)> _acceptTermsCallback; 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; @@ -248,7 +248,7 @@ private: void resetAccount(); void showTerms(); - void acceptTerms(base::lambda callback); + void acceptTerms(Fn callback); void hideAndDestroy(object_ptr> widget); Step *getStep(int skip = 0) { @@ -260,7 +260,7 @@ private: void appendStep(Step *step); void getNearestDC(); - void showTerms(base::lambda callback); + void showTerms(Fn callback); Animation _a_show; bool _showBack = false; diff --git a/Telegram/SourceFiles/lang/lang_file_parser.cpp b/Telegram/SourceFiles/lang/lang_file_parser.cpp index 065e134bdd..27253eb111 100644 --- a/Telegram/SourceFiles/lang/lang_file_parser.cpp +++ b/Telegram/SourceFiles/lang/lang_file_parser.cpp @@ -22,7 +22,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 7c44682b02..cf0dcd4de5 100644 --- a/Telegram/SourceFiles/lang/lang_file_parser.h +++ b/Telegram/SourceFiles/lang/lang_file_parser.h @@ -16,7 +16,7 @@ public: 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); @@ -44,7 +44,7 @@ private: 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 2b41130d6d..3dc6d6090a 100644 --- a/Telegram/SourceFiles/lang/lang_keys.h +++ b/Telegram/SourceFiles/lang/lang_keys.h @@ -14,7 +14,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/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 4154fa961a..a9940bdd58 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -910,7 +910,7 @@ void MainWidget::cancelUploadLayer(not_null item) { void MainWidget::deletePhotoLayer(PhotoData *photo) { if (!photo) return; - Ui::show(Box(lang(lng_delete_photo_sure), lang(lng_box_delete), base::lambda_guarded(this, [=] { + Ui::show(Box(lang(lng_delete_photo_sure), lang(lng_box_delete), crl::guard(this, [=] { Ui::hideLayer(); auto me = App::self(); @@ -950,11 +950,11 @@ bool MainWidget::selectingPeerForInlineSwitch() { void MainWidget::offerPeer(PeerId peer) { Ui::hideLayer(); if (_hider->offerPeer(peer) && Adaptive::OneColumn()) { - _forwardConfirm = Ui::show(Box(_hider->offeredText(), lang(lng_forward_send), base::lambda_guarded(this, [this] { + _forwardConfirm = Ui::show(Box(_hider->offeredText(), lang(lng_forward_send), crl::guard(this, [this] { _hider->forward(); if (_forwardConfirm) _forwardConfirm->closeBox(); if (_hider) _hider->offerPeer(0); - }), base::lambda_guarded(this, [this] { + }), crl::guard(this, [this] { if (_hider && _forwardConfirm) _hider->offerPeer(0); }))); } @@ -1670,12 +1670,12 @@ void MainWidget::documentLoadFailed(FileLoader *loader, bool started) { auto document = Auth().data().document(documentId); if (started) { auto failedFileName = loader->fileName(); - Ui::show(Box(lang(lng_download_finish_failed), base::lambda_guarded(this, [=] { + Ui::show(Box(lang(lng_download_finish_failed), crl::guard(this, [=] { Ui::hideLayer(); if (document) document->save(failedFileName); }))); } else { - Ui::show(Box(lang(lng_download_path_failed), lang(lng_download_path_settings), base::lambda_guarded(this, [=] { + Ui::show(Box(lang(lng_download_path_failed), lang(lng_download_path_settings), crl::guard(this, [=] { Global::SetDownloadPath(QString()); Global::SetDownloadPathBookmark(QByteArray()); Ui::show(Box()); @@ -2771,11 +2771,11 @@ void MainWidget::showAll() { if (_hider) { _hider->hide(); if (!_forwardConfirm && _hider->wasOffered()) { - _forwardConfirm = Ui::show(Box(_hider->offeredText(), lang(lng_forward_send), base::lambda_guarded(this, [this] { + _forwardConfirm = Ui::show(Box(_hider->offeredText(), lang(lng_forward_send), crl::guard(this, [this] { _hider->forward(); if (_forwardConfirm) _forwardConfirm->closeBox(); if (_hider) _hider->offerPeer(0); - }), base::lambda_guarded(this, [this] { + }), crl::guard(this, [this] { if (_hider && _forwardConfirm) _hider->offerPeer(0); })), LayerOption::CloseOther, anim::type::instant); } diff --git a/Telegram/SourceFiles/media/media_clip_reader.h b/Telegram/SourceFiles/media/media_clip_reader.h index 62bf8b2956..7f40f29977 100644 --- a/Telegram/SourceFiles/media/media_clip_reader.h +++ b/Telegram/SourceFiles/media/media_clip_reader.h @@ -42,7 +42,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 bd7c962b49..7ec148fe49 100644 --- a/Telegram/SourceFiles/media/player/media_player_button.cpp +++ b/Telegram/SourceFiles/media/player/media_player_button.cpp @@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL 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 76a2296fb9..7c33af2d7b 100644 --- a/Telegram/SourceFiles/media/player/media_player_button.h +++ b/Telegram/SourceFiles/media/player/media_player_button.h @@ -20,7 +20,7 @@ public: Pause, Cancel, }; - PlayButtonLayout(const style::MediaPlayerButton &st, base::lambda callback); + PlayButtonLayout(const style::MediaPlayerButton &st, Fn callback); void setState(State state); void finishTransform(); @@ -43,7 +43,7 @@ private: Animation _transformProgress; bool _transformBackward = false; - base::lambda _callback; + Fn _callback; }; diff --git a/Telegram/SourceFiles/media/player/media_player_cover.h b/Telegram/SourceFiles/media/player/media_player_cover.h index 8f2a2a47a5..fff86109e7 100644 --- a/Telegram/SourceFiles/media/player/media_player_cover.h +++ b/Telegram/SourceFiles/media/player/media_player_cover.h @@ -32,7 +32,7 @@ class CoverWidget : public Ui::RpWidget, 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 dd5f1ba8b2..7a1de62273 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.cpp +++ b/Telegram/SourceFiles/media/player/media_player_float.cpp @@ -30,8 +30,8 @@ Float::Float( QWidget *parent, not_null controller, not_null item, - base::lambda toggleCallback, - base::lambda draggedCallback) + Fn toggleCallback, + Fn draggedCallback) : RpWidget(parent) , _controller(controller) , _item(item) diff --git a/Telegram/SourceFiles/media/player/media_player_float.h b/Telegram/SourceFiles/media/player/media_player_float.h index ec5cc19978..79da429984 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.h +++ b/Telegram/SourceFiles/media/player/media_player_float.h @@ -26,8 +26,8 @@ public: QWidget *parent, not_null controller, not_null item, - base::lambda toggleCallback, - base::lambda draggedCallback); + Fn toggleCallback, + Fn draggedCallback); HistoryItem *item() const { return _item; @@ -78,7 +78,7 @@ private: not_null _controller; HistoryItem *_item = nullptr; - base::lambda _toggleCallback; + Fn _toggleCallback; float64 _opacity = 1.; @@ -89,7 +89,7 @@ private: bool _drag = false; QPoint _dragLocalPoint; - base::lambda _draggedCallback; + Fn _draggedCallback; }; diff --git a/Telegram/SourceFiles/media/player/media_player_panel.h b/Telegram/SourceFiles/media/player/media_player_panel.h index 9ee2783422..7dc6162839 100644 --- a/Telegram/SourceFiles/media/player/media_player_panel.h +++ b/Telegram/SourceFiles/media/player/media_player_panel.h @@ -43,7 +43,7 @@ public: 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 ee5f356b7b..f91d24095d 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -171,7 +171,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 481df4e7c2..a715a61a19 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.h +++ b/Telegram/SourceFiles/media/player/media_player_widget.h @@ -34,7 +34,7 @@ class Widget : public Ui::RpWidget, 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(); @@ -90,7 +90,7 @@ private: // 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 1e2c84e6c4..5ad06ec5fa 100644 --- a/Telegram/SourceFiles/media/view/media_clip_playback.h +++ b/Telegram/SourceFiles/media/view/media_clip_playback.h @@ -20,10 +20,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(float64 value, bool animated); @@ -40,10 +40,10 @@ private: // 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; int64 _position = 0; int64 _length = 0; diff --git a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp index 15dd1864c2..ed1ef2ce46 100644 --- a/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp +++ b/Telegram/SourceFiles/media/view/media_view_group_thumbs.cpp @@ -96,7 +96,7 @@ public: Dying, }; - Thumb(Key key, ImagePtr image, base::lambda handler); + Thumb(Key key, ImagePtr image, Fn handler); int leftToUpdate() const; int rightToUpdate() const; @@ -137,7 +137,7 @@ private: GroupThumbs::Thumb::Thumb( Key key, ImagePtr image, - base::lambda handler) + Fn handler) : _key(key) , _image(image) { _link = std::make_shared(std::move(handler)); diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 9531833fe9..06be4b2b5a 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -860,12 +860,12 @@ void MediaView::onSaveAs() { QString(), false, _photo->date), - base::lambda_guarded(this, [this, photo = _photo](const QString &result) { + crl::guard(this, [this, photo = _photo](const QString &result) { if (!result.isEmpty() && _photo == photo && photo->loaded()) { photo->full->pix().toImage().save(result, "JPG"); } psShowOverAll(this); - }), base::lambda_guarded(this, [this] { + }), crl::guard(this, [this] { psShowOverAll(this); })); } diff --git a/Telegram/SourceFiles/messenger.h b/Telegram/SourceFiles/messenger.h index 3aef2707d8..895ae8a814 100644 --- a/Telegram/SourceFiles/messenger.h +++ b/Telegram/SourceFiles/messenger.h @@ -185,7 +185,7 @@ public: 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 2a9065efb0..0e4fe9a825 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -98,8 +98,8 @@ public: 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); @@ -202,8 +202,8 @@ private: std::map> _authWaiters; RPCResponseHandler _globalHandler; - base::lambda _stateChangedHandler; - base::lambda _sessionResetHandler; + Fn _stateChangedHandler; + Fn _sessionResetHandler; base::Timer _checkDelayedTimer; @@ -1420,19 +1420,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() { @@ -1588,11 +1588,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 5a67b1f8b0..f0629606b2 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.h +++ b/Telegram/SourceFiles/mtproto/mtp_instance.h @@ -112,8 +112,8 @@ public: 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, int32 state); diff --git a/Telegram/SourceFiles/mtproto/rpc_sender.h b/Telegram/SourceFiles/mtproto/rpc_sender.h index 50217b6062..7985716b8d 100644 --- a/Telegram/SourceFiles/mtproto/rpc_sender.h +++ b/Telegram/SourceFiles/mtproto/rpc_sender.h @@ -839,7 +839,7 @@ using MTPSessionResetHandler = void (*)(int32 dcId); template class RPCHandlerImplementation : public Base { protected: - using Lambda = base::lambda_once; + using Lambda = FnMut; using Parent = RPCHandlerImplementation; public: @@ -994,7 +994,7 @@ using rpcDone_returnType_t = typename rpcDone_returnType::type; template < typename Lambda, - typename Function = base::lambda_call_type_t> + typename Function = crl::deduced_call_type> RPCDoneHandlerPtr rpcDone(Lambda lambda) { using R = rpcDone_returnType_t; if constexpr (rpcDone_canCallBare_v) { @@ -1073,7 +1073,7 @@ constexpr bool rpcFail_canCallReq_v = rpl::details::is_callable_plain_v< template < typename Lambda, - typename Function = base::lambda_call_type_t> + typename Function = crl::deduced_call_type> RPCFailHandlerPtr rpcFail(Lambda lambda) { if constexpr (rpcFail_canCallNo_v) { return RPCFailHandlerPtr(new RPCFailHandlerImplementationNo(std::move(lambda))); diff --git a/Telegram/SourceFiles/mtproto/sender.h b/Telegram/SourceFiles/mtproto/sender.h index ff9788fea8..06acdd8490 100644 --- a/Telegram/SourceFiles/mtproto/sender.h +++ b/Telegram/SourceFiles/mtproto/sender.h @@ -22,8 +22,8 @@ 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, @@ -31,7 +31,7 @@ class Sender { }; template struct DonePlainPolicy { - using Callback = base::lambda_once; + using Callback = FnMut; static void handle(Callback &&handler, mtpRequestId requestId, Response &&result) { handler(result); } @@ -39,7 +39,7 @@ class Sender { }; template struct DoneRequestIdPolicy { - using Callback = base::lambda_once; + using Callback = FnMut; static void handle(Callback &&handler, mtpRequestId requestId, Response &&result) { handler(result, requestId); } @@ -72,14 +72,14 @@ 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); } @@ -209,19 +209,19 @@ public: setCanWait(ms); return *this; } - [[nodiscard]] SpecificRequestBuilder &done(base::lambda_once callback) { + [[nodiscard]] SpecificRequestBuilder &done(FnMut callback) { setDoneHandler(std::make_shared>(sender(), std::move(callback))); return *this; } - [[nodiscard]] SpecificRequestBuilder &done(base::lambda_once callback) { + [[nodiscard]] SpecificRequestBuilder &done(FnMut callback) { setDoneHandler(std::make_shared>(sender(), std::move(callback))); return *this; } - [[nodiscard]] SpecificRequestBuilder &fail(base::lambda_once callback) noexcept { + [[nodiscard]] SpecificRequestBuilder &fail(FnMut callback) noexcept { setFailHandler(std::move(callback)); return *this; } - [[nodiscard]] SpecificRequestBuilder &fail(base::lambda_once callback) noexcept { + [[nodiscard]] SpecificRequestBuilder &fail(FnMut callback) noexcept { 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 9eaead5f13..d60d9b72c2 100644 --- a/Telegram/SourceFiles/mtproto/special_config_request.cpp +++ b/Telegram/SourceFiles/mtproto/special_config_request.cpp @@ -157,7 +157,7 @@ ServiceWebRequest::~ServiceWebRequest() { } SpecialConfigRequest::SpecialConfigRequest( - base::lambda reply) { if (reply->error() != QNetworkReply::NoError) { - LOG(("Config Error: Failed to get response from %1, error: %2 (%3)" - ).arg(reply->request().url().toDisplayString() + LOG(("Config Error: Failed to get response, error: %2 (%3)" ).arg(reply->errorString() ).arg(reply->error())); } @@ -373,7 +372,7 @@ void SpecialConfigRequest::handleResponse(const QByteArray &bytes) { } } -DomainResolver::DomainResolver(base::lambda callback) @@ -492,8 +491,7 @@ QByteArray DomainResolver::finalizeRequest( const AttemptKey &key, not_null reply) { if (reply->error() != QNetworkReply::NoError) { - LOG(("Resolve Error: Failed to get response from %1, error: %2 (%3)" - ).arg(reply->request().url().toDisplayString() + LOG(("Resolve Error: Failed to get response, error: %2 (%3)" ).arg(reply->errorString() ).arg(reply->error())); } diff --git a/Telegram/SourceFiles/mtproto/special_config_request.h b/Telegram/SourceFiles/mtproto/special_config_request.h index d56744ae5a..c63292b380 100644 --- a/Telegram/SourceFiles/mtproto/special_config_request.h +++ b/Telegram/SourceFiles/mtproto/special_config_request.h @@ -26,7 +26,7 @@ struct ServiceWebRequest { class SpecialConfigRequest : public QObject { public: SpecialConfigRequest( - base::lambda callback); @@ -104,7 +104,7 @@ private: const AttemptKey &key, not_null reply); - base::lambda _callback; diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h index c6ea649e2f..bae314db67 100644 --- a/Telegram/SourceFiles/observer_peer.h +++ b/Telegram/SourceFiles/observer_peer.h @@ -97,7 +97,7 @@ public: 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 169a771819..2d8b1d77c0 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -83,7 +83,7 @@ public: private: void startAnimation(); - base::lambda _updateCallback; + Fn _updateCallback; Ui::RoundCheckbox _check; Animation _pression; diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index da2502153b..ba673fc945 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -841,7 +841,7 @@ void FormController::prepareFile( void FormController::encryptFile( EditFile &file, QByteArray &&content, - base::lambda callback) { + Fn callback) { prepareFile(file, content); const auto weak = std::weak_ptr(file.guard); diff --git a/Telegram/SourceFiles/passport/passport_form_controller.h b/Telegram/SourceFiles/passport/passport_form_controller.h index b470dc353c..573bd3a5ff 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.h +++ b/Telegram/SourceFiles/passport/passport_form_controller.h @@ -356,7 +356,7 @@ private: void encryptFile( EditFile &file, QByteArray &&content, - base::lambda callback); + Fn callback); void prepareFile( EditFile &file, const QByteArray &content); @@ -425,7 +425,7 @@ private: bytes::vector _secret; uint64 _secretId = 0; - std::vector> _secretCallbacks; + std::vector> _secretCallbacks; mtpRequestId _saveSecretRequestId = 0; rpl::event_stream<> _secretReady; rpl::event_stream _passwordError; diff --git a/Telegram/SourceFiles/passport/passport_form_view_controller.h b/Telegram/SourceFiles/passport/passport_form_view_controller.h index 4a46b4e19f..c06165e3da 100644 --- a/Telegram/SourceFiles/passport/passport_form_view_controller.h +++ b/Telegram/SourceFiles/passport/passport_form_view_controller.h @@ -50,7 +50,7 @@ public: LayerOptions options, anim::type animated) = 0; virtual void showToast(const QString &text) = 0; - virtual void suggestReset(base::lambda callback) = 0; + virtual void suggestReset(Fn callback) = 0; virtual int closeGetDuration() = 0; diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index badea4c312..eca4523333 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -390,7 +390,7 @@ QString PanelController::privacyPolicyUrl() const { } void PanelController::fillRows( - base::lambda callback) { +void PanelController::suggestReset(Fn callback) { _resetBox = BoxPointer(show(Box( Lang::Hard::PassportCorrupted(), Lang::Hard::PassportCorruptedReset(), @@ -750,7 +750,7 @@ void PanelController::suggestReset(base::lambda callback) { [=] { cancelReset(); })).data()); } -void PanelController::resetPassport(base::lambda callback) { +void PanelController::resetPassport(Fn callback) { const auto box = show(Box( Lang::Hard::PassportCorruptedResetSure(), Lang::Hard::PassportCorruptedReset(), diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.h b/Telegram/SourceFiles/passport/passport_panel_controller.h index 05cc68e6e3..a3007d9c10 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.h +++ b/Telegram/SourceFiles/passport/passport_panel_controller.h @@ -99,7 +99,7 @@ public: void showCriticalError(const QString &error) override; void fillRows( - base::lambda callback) override; + void suggestReset(Fn callback) override; int closeGetDuration() override; @@ -151,7 +151,7 @@ private: QString getDefaultContactValue(Scope::Type type) const; void deleteValueSure(bool withDetails); - void resetPassport(base::lambda callback); + void resetPassport(Fn callback); void cancelReset(); not_null _form; @@ -161,7 +161,7 @@ private: rpl::event_stream _saveErrors; std::unique_ptr _panel; - base::lambda _panelHasUnsavedChanges; + Fn _panelHasUnsavedChanges; QPointer _confirmForgetChangesBox; std::vector _editScopeBoxes; Scope *_editScope = nullptr; diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp index 9a34854620..e5ec229f3c 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp @@ -27,7 +27,7 @@ public: PostcodeInput( QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory, + Fn placeholderFactory, const QString &val); protected: @@ -42,7 +42,7 @@ protected: PostcodeInput::PostcodeInput( QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory, + Fn placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { if (!QRegularExpression("^[a-zA-Z0-9\\-]+$").match(val).hasMatch()) { diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp index a0d0003825..cb0ab55d4d 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp @@ -34,7 +34,7 @@ public: const QString &title, const QString &text, int codeLength, - base::lambda submit, + Fn submit, rpl::producer call, rpl::producer error); @@ -47,12 +47,12 @@ private: void setupControls( const QString &text, int codeLength, - base::lambda submit, + Fn submit, rpl::producer call, rpl::producer error); QString _title; - base::lambda _submit; + Fn _submit; QPointer _code; int _height = 0; @@ -63,7 +63,7 @@ VerifyBox::VerifyBox( const QString &title, const QString &text, int codeLength, - base::lambda submit, + Fn submit, rpl::producer call, rpl::producer error) : _title(title) { @@ -78,7 +78,7 @@ VerifyBox::VerifyBox( void VerifyBox::setupControls( const QString &text, int codeLength, - base::lambda submit, + Fn submit, rpl::producer call, rpl::producer error) { const auto description = Ui::CreateChild( @@ -355,7 +355,7 @@ void PanelEditContact::save(const QString &value) { object_ptr VerifyPhoneBox( const QString &phone, int codeLength, - base::lambda submit, + Fn submit, rpl::producer call, rpl::producer error) { return Box( @@ -370,7 +370,7 @@ object_ptr VerifyPhoneBox( object_ptr VerifyEmailBox( const QString &email, int codeLength, - base::lambda submit, + Fn submit, rpl::producer error) { return Box( lang(lng_passport_email_title), diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_contact.h b/Telegram/SourceFiles/passport/passport_panel_edit_contact.h index 3d9f8bd8b7..e5658b4ec0 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_contact.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_contact.h @@ -31,11 +31,11 @@ struct EditContactScheme { QString aboutExisting; QString newHeader; - base::lambda newPlaceholder; + Fn newPlaceholder; QString aboutNew; - base::lambda validate; - base::lambda format; - base::lambda postprocess; + Fn validate; + Fn format; + Fn postprocess; }; @@ -76,13 +76,13 @@ private: object_ptr VerifyPhoneBox( const QString &phone, int codeLength, - base::lambda submit, + Fn submit, rpl::producer call, rpl::producer error); object_ptr VerifyEmailBox( const QString &email, int codeLength, - base::lambda submit, + Fn submit, rpl::producer error); } // namespace Passport diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp index bde31bcbfc..785411756d 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp @@ -37,7 +37,7 @@ public: const QString &title, const QString &about, std::vector labels, - base::lambda submit); + Fn submit); protected: void prepare() override; @@ -46,10 +46,10 @@ private: void setupControls( const QString &about, std::vector labels, - base::lambda submit); + Fn submit); QString _title; - base::lambda _submit; + Fn _submit; int _height = 0; }; @@ -60,7 +60,7 @@ public: QWidget*, const QString &text, const QString &detailsCheckbox, - base::lambda submit); + Fn submit); protected: void prepare() override; @@ -69,9 +69,9 @@ private: void setupControls( const QString &text, const QString &detailsCheckbox, - base::lambda submit); + Fn submit); - base::lambda _submit; + Fn _submit; int _height = 0; }; @@ -81,7 +81,7 @@ RequestTypeBox::RequestTypeBox( const QString &title, const QString &about, std::vector labels, - base::lambda submit) + Fn submit) : _title(title) { setupControls(about, std::move(labels), submit); } @@ -96,7 +96,7 @@ void RequestTypeBox::prepare() { void RequestTypeBox::setupControls( const QString &about, std::vector labels, - base::lambda submit) { + Fn submit) { const auto header = Ui::CreateChild( this, lang(lng_passport_document_type), @@ -150,7 +150,7 @@ DeleteDocumentBox::DeleteDocumentBox( QWidget*, const QString &text, const QString &detailsCheckbox, - base::lambda submit) { + Fn submit) { setupControls(text, detailsCheckbox, submit); } @@ -164,7 +164,7 @@ void DeleteDocumentBox::prepare() { void DeleteDocumentBox::setupControls( const QString &text, const QString &detailsCheckbox, - base::lambda submit) { + Fn submit) { const auto label = Ui::CreateChild( this, text, @@ -452,7 +452,7 @@ void PanelEditDocument::save() { } object_ptr RequestIdentityType( - base::lambda submit, + Fn submit, std::vector labels) { return Box( lang(lng_passport_identity_title), @@ -462,7 +462,7 @@ object_ptr RequestIdentityType( } object_ptr RequestAddressType( - base::lambda submit, + Fn submit, std::vector labels) { return Box( lang(lng_passport_address_title), @@ -472,7 +472,7 @@ object_ptr RequestAddressType( } object_ptr ConfirmDeleteDocument( - base::lambda submit, + Fn submit, const QString &text, const QString &detailsCheckbox) { return Box(text, detailsCheckbox, submit); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.h b/Telegram/SourceFiles/passport/passport_panel_edit_document.h index cfd3c1fd52..3edbd28127 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.h @@ -43,8 +43,8 @@ struct EditDocumentScheme { PanelDetailsType inputType = PanelDetailsType(); QString key; QString label; - base::lambda(const QString &value)> error; - base::lambda format; + Fn(const QString &value)> error; + Fn format; int lengthLimit = 0; }; std::vector rows; @@ -115,14 +115,14 @@ private: }; object_ptr RequestIdentityType( - base::lambda submit, + Fn submit, std::vector labels); object_ptr RequestAddressType( - base::lambda submit, + Fn submit, std::vector labels); object_ptr ConfirmDeleteDocument( - base::lambda submit, + Fn submit, const QString &text, const QString &detailsCheckbox = QString()); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp index 60b9907573..3d783fa63c 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp @@ -645,16 +645,16 @@ void EditScans::chooseSpecialScan(SpecialFile type) { void EditScans::ChooseScan( QPointer parent, - base::lambda doneCallback, - base::lambda errorCallback) { + Fn doneCallback, + Fn errorCallback) { Expects(parent != nullptr); const auto filter = FileDialog::AllFilesFilter() + qsl(";;Image files (*") + cImgExtensions().join(qsl(" *")) + qsl(")"); - const auto guardedCallback = base::lambda_guarded(parent, doneCallback); - const auto guardedError = base::lambda_guarded(parent, errorCallback); + const auto guardedCallback = crl::guard(parent, doneCallback); + const auto guardedError = crl::guard(parent, errorCallback); const auto onMainCallback = [=](QByteArray content) { crl::on_main([=, bytes = std::move(content)]() mutable { guardedCallback(std::move(bytes)); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.h b/Telegram/SourceFiles/passport/passport_panel_edit_scans.h index e50df6aa55..7437732c15 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.h @@ -55,8 +55,8 @@ public: static void ChooseScan( QPointer parent, - base::lambda doneCallback, - base::lambda errorCallback); + Fn doneCallback, + Fn errorCallback); ~EditScans(); diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index f756c6ed59..18c07d32a9 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -189,7 +189,7 @@ private: PeerId peerId = 0; MsgId msgId = 0; }; - static void performOnMainQueue(NotificationDataStruct *data, base::lambda_once task) { + static void performOnMainQueue(NotificationDataStruct *data, FnMut task) { const auto weak = data->weak; crl::on_main(weak, [=, task = std::move(task)]() mutable { task(*weak.lock()); diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 52ffdae798..ea895dd1c0 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -65,7 +65,7 @@ id FindClassInSubviews(NSView *parent, NSString *className) { class LayerCreationChecker : public QObject { public: - LayerCreationChecker(NSView * __weak view, base::lambda callback) + LayerCreationChecker(NSView * __weak view, Fn callback) : _weakView(view) , _callback(std::move(callback)) { QCoreApplication::instance()->installEventFilter(this); @@ -81,7 +81,7 @@ protected: private: NSView * __weak _weakView = nil; - base::lambda _callback; + Fn _callback; }; diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index 9e994f539c..ed6bec3759 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -212,7 +212,7 @@ public: } ~ToastEventHandler() = default; - void performOnMainQueue(base::lambda_once task) { + void performOnMainQueue(FnMut task) { const auto weak = _weak; crl::on_main(weak, [=, task = std::move(task)]() mutable { task(*weak.lock()); diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.cpp b/Telegram/SourceFiles/profile/profile_block_group_members.cpp index 84e192906f..271b59f7ac 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.cpp +++ b/Telegram/SourceFiles/profile/profile_block_group_members.cpp @@ -244,20 +244,20 @@ Ui::PopupMenu *GroupMembersWidget::fillPeerMenu(PeerData *selectedPeer) { if (channel) { if (channel->canEditAdmin(user)) { auto label = lang((item->adminState != Item::AdminState::None) ? lng_context_edit_permissions : lng_context_promote_admin); - result->addAction(label, base::lambda_guarded(this, [this, user] { + result->addAction(label, crl::guard(this, [this, user] { editAdmin(user); })); } if (channel->canRestrictUser(user)) { - result->addAction(lang(lng_context_restrict_user), base::lambda_guarded(this, [this, user] { + result->addAction(lang(lng_context_restrict_user), crl::guard(this, [this, user] { restrictUser(user); })); - result->addAction(lang(lng_context_remove_from_group), base::lambda_guarded(this, [this, selectedPeer] { + result->addAction(lang(lng_context_remove_from_group), crl::guard(this, [this, selectedPeer] { removePeer(selectedPeer); })); } } else if (item->hasRemoveLink) { - result->addAction(lang(lng_context_remove_from_group), base::lambda_guarded(this, [this, selectedPeer] { + result->addAction(lang(lng_context_remove_from_group), crl::guard(this, [this, selectedPeer] { removePeer(selectedPeer); })); } diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index 007e7cca6c..4e0465dd36 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -207,7 +207,7 @@ void PeerListWidget::contextMenuEvent(QContextMenuEvent *e) { _menu = fillPeerMenu(_items[_selected]->peer); if (_menu) { - _menu->setDestroyedCallback(base::lambda_guarded(this, [this, menu = _menu] { + _menu->setDestroyedCallback(crl::guard(this, [this, menu = _menu] { if (_menu == menu) { _menu = nullptr; } diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.h b/Telegram/SourceFiles/profile/profile_block_peer_list.h index 3cc3641a39..cf0062eadd 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.h +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.h @@ -71,16 +71,16 @@ public: 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); } @@ -125,10 +125,10 @@ private: const style::PeerListItem &_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.cpp b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp index c559d54d8b..165e3ae17e 100644 --- a/Telegram/SourceFiles/profile/profile_channel_controllers.cpp +++ b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp @@ -36,7 +36,7 @@ void RemoveAdmin( not_null channel, not_null user, const MTPChannelAdminRights &oldRights, - base::lambda onDone) { + Fn onDone) { const auto newRights = MTP_channelAdminRights(MTP_flags(0)); auto done = [=](const MTPUpdates &result) { Auth().api().applyUpdates(result); @@ -53,13 +53,13 @@ void RemoveAdmin( } // namespace -base::lambda SaveAdminCallback( not_null channel, not_null user, - base::lambda onDone, - base::lambda onFail) { + Fn onDone, + Fn onFail) { return [=]( const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) { diff --git a/Telegram/SourceFiles/profile/profile_channel_controllers.h b/Telegram/SourceFiles/profile/profile_channel_controllers.h index 9aee0f44d3..d7a9756911 100644 --- a/Telegram/SourceFiles/profile/profile_channel_controllers.h +++ b/Telegram/SourceFiles/profile/profile_channel_controllers.h @@ -20,13 +20,13 @@ class Navigation; namespace Profile { -base::lambda SaveAdminCallback( not_null channel, not_null user, - base::lambda onDone, - base::lambda onFail); + Fn onDone, + Fn onFail); // Viewing admins, banned or restricted users list with search. class ParticipantsBoxController @@ -218,8 +218,8 @@ public: 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); void prepare() override; diff --git a/Telegram/SourceFiles/profile/profile_cover_drop_area.h b/Telegram/SourceFiles/profile/profile_cover_drop_area.h index 8e5edf076a..c6b0fef70d 100644 --- a/Telegram/SourceFiles/profile/profile_cover_drop_area.h +++ b/Telegram/SourceFiles/profile/profile_cover_drop_area.h @@ -15,7 +15,7 @@ public: void showAnimated(); - using HideFinishCallback = base::lambda; + using HideFinishCallback = Fn; void hideAnimated(HideFinishCallback &&callback); bool hiding() const { diff --git a/Telegram/SourceFiles/rpl/lifetime.h b/Telegram/SourceFiles/rpl/lifetime.h index a163c38898..8c21184a5d 100644 --- a/Telegram/SourceFiles/rpl/lifetime.h +++ b/Telegram/SourceFiles/rpl/lifetime.h @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "base/lambda.h" +#include "base/unique_function.h" #include namespace rpl { @@ -49,7 +49,7 @@ public: ~lifetime() { destroy(); } private: - std::deque> _callbacks; + std::deque> _callbacks; }; diff --git a/Telegram/SourceFiles/rpl/operators_tests.cpp b/Telegram/SourceFiles/rpl/operators_tests.cpp index f7d141a2c3..bd3b739622 100644 --- a/Telegram/SourceFiles/rpl/operators_tests.cpp +++ b/Telegram/SourceFiles/rpl/operators_tests.cpp @@ -14,8 +14,8 @@ using namespace rpl; class OnDestructor { public: - OnDestructor(base::lambda_once callback) - : _callback(std::move(callback)) { + OnDestructor(std::function callback) + : _callback(std::move(callback)) { } ~OnDestructor() { if (_callback) { @@ -24,7 +24,7 @@ public: } private: - base::lambda_once _callback; + std::function _callback; }; diff --git a/Telegram/SourceFiles/rpl/producer.h b/Telegram/SourceFiles/rpl/producer.h index 88850e38b9..fb130e3d4e 100644 --- a/Telegram/SourceFiles/rpl/producer.h +++ b/Telegram/SourceFiles/rpl/producer.h @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "base/lambda.h" +#include #include #include #include @@ -47,7 +47,7 @@ private: }; -// Type-erased copyable mutable lambda using base::lambda. +// Type-erased copyable mutable function using std::function. template class type_erased_generator final { public: @@ -100,7 +100,7 @@ public: } private: - base::lambda> &)> _implementation; + std::function> &)> _implementation; }; diff --git a/Telegram/SourceFiles/rpl/producer_tests.cpp b/Telegram/SourceFiles/rpl/producer_tests.cpp index 42fc603831..0267f92aa8 100644 --- a/Telegram/SourceFiles/rpl/producer_tests.cpp +++ b/Telegram/SourceFiles/rpl/producer_tests.cpp @@ -14,8 +14,8 @@ using namespace rpl; class OnDestructor { public: - OnDestructor(base::lambda_once callback) - : _callback(std::move(callback)) { + OnDestructor(std::function callback) + : _callback(std::move(callback)) { } ~OnDestructor() { if (_callback) { @@ -24,7 +24,7 @@ public: } private: - base::lambda_once _callback; + std::function _callback; }; diff --git a/Telegram/SourceFiles/settings/settings_advanced_widget.cpp b/Telegram/SourceFiles/settings/settings_advanced_widget.cpp index 3e50cc3ca2..3a3a76c11b 100644 --- a/Telegram/SourceFiles/settings/settings_advanced_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced_widget.cpp @@ -124,9 +124,9 @@ void AdvancedWidget::onToggleNightTheme() { } void AdvancedWidget::onAskQuestion() { - auto box = Box(lang(lng_settings_ask_sure), lang(lng_settings_ask_ok), lang(lng_settings_faq_button), base::lambda_guarded(this, [this] { + auto box = Box(lang(lng_settings_ask_sure), lang(lng_settings_ask_ok), lang(lng_settings_faq_button), crl::guard(this, [this] { onAskQuestionSure(); - }), base::lambda_guarded(this, [this] { + }), crl::guard(this, [this] { onTelegramFAQ(); })); box->setStrictCancel(true); diff --git a/Telegram/SourceFiles/settings/settings_background_widget.cpp b/Telegram/SourceFiles/settings/settings_background_widget.cpp index 1975b93611..896eac833e 100644 --- a/Telegram/SourceFiles/settings/settings_background_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_background_widget.cpp @@ -268,7 +268,7 @@ void BackgroundWidget::onChooseFromFile() { this, lang(lng_choose_image), filters.join(qsl(";;")), - base::lambda_guarded(this, callback)); + crl::guard(this, callback)); } void BackgroundWidget::onEditTheme() { diff --git a/Telegram/SourceFiles/settings/settings_block_widget.cpp b/Telegram/SourceFiles/settings/settings_block_widget.cpp index d562c8f13f..b13f6ed8cf 100644 --- a/Telegram/SourceFiles/settings/settings_block_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_block_widget.cpp @@ -89,7 +89,7 @@ void BlockWidget::createChildWidget( object_ptr &child, style::margins &margin, const QString &text, - base::lambda callback, + 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 7cc62804fa..6680a27b00 100644 --- a/Telegram/SourceFiles/settings/settings_block_widget.h +++ b/Telegram/SourceFiles/settings/settings_block_widget.h @@ -87,7 +87,7 @@ private: void createChildWidget( object_ptr &child, style::margins &margin, - const QString &text, base::lambda callback, bool checked); + const QString &text, Fn callback, bool checked); void createChildWidget( object_ptr &child, style::margins &margin, diff --git a/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp b/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp index 028cfb3f51..9e13113b27 100644 --- a/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp @@ -107,7 +107,7 @@ void DownloadPathState::onDownloadPath() { } void DownloadPathState::onClear() { - Ui::show(Box(lang(lng_sure_clear_downloads), base::lambda_guarded(this, [this] { + Ui::show(Box(lang(lng_sure_clear_downloads), crl::guard(this, [this] { Ui::hideLayer(); App::wnd()->tempDirDelete(Local::ClearManagerDownloads); _state = State::Clearing; diff --git a/Telegram/SourceFiles/settings/settings_cover.cpp b/Telegram/SourceFiles/settings/settings_cover.cpp index 40ce533197..d825365fff 100644 --- a/Telegram/SourceFiles/settings/settings_cover.cpp +++ b/Telegram/SourceFiles/settings/settings_cover.cpp @@ -361,7 +361,7 @@ void CoverWidget::chooseNewPhoto() { this, lang(lng_choose_image), filter, - base::lambda_guarded(this, callback)); + crl::guard(this, callback)); } void CoverWidget::editName() { diff --git a/Telegram/SourceFiles/settings/settings_inner_widget.h b/Telegram/SourceFiles/settings/settings_inner_widget.h index 3094e9e4be..99f8b05538 100644 --- a/Telegram/SourceFiles/settings/settings_inner_widget.h +++ b/Telegram/SourceFiles/settings/settings_inner_widget.h @@ -43,7 +43,7 @@ private: UserData *_self = nullptr; int _contentLeft = 0; - base::lambda _getUpdateTop; + Fn _getUpdateTop; }; diff --git a/Telegram/SourceFiles/settings/settings_layer.cpp b/Telegram/SourceFiles/settings/settings_layer.cpp index 92786629d3..7e28deb9e0 100644 --- a/Telegram/SourceFiles/settings/settings_layer.cpp +++ b/Telegram/SourceFiles/settings/settings_layer.cpp @@ -44,7 +44,7 @@ Layer::Layer() | rpl::map(_1 > 0)); } -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 df4a4e8474..23dab677f4 100644 --- a/Telegram/SourceFiles/settings/settings_layer.h +++ b/Telegram/SourceFiles/settings/settings_layer.h @@ -34,7 +34,7 @@ class Layer : public Window::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 99decaad19..4e664c2262 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -26,7 +26,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); } @@ -41,7 +41,7 @@ protected: private: void updateIsBlocked(not_null row, UserData *user) const; - base::lambda user)> _blockUserCallback; + Fn user)> _blockUserCallback; }; @@ -256,7 +256,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().settings().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 ec68deeb8d..1269c5434a 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -50,7 +50,7 @@ public: QString exceptionBoxTitle(Exception exception) override; QString exceptionsDescription() override; - void confirmSave(bool someAreDisallowed, base::lambda_once saveCallback) override; + void confirmSave(bool someAreDisallowed, FnMut saveCallback) override; }; diff --git a/Telegram/SourceFiles/settings/settings_scale_widget.cpp b/Telegram/SourceFiles/settings/settings_scale_widget.cpp index b888cf7218..78d5c6b276 100644 --- a/Telegram/SourceFiles/settings/settings_scale_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_scale_widget.cpp @@ -88,11 +88,11 @@ void ScaleWidget::setScale(DBIScale newScale) { } if (cEvalScale(newScale) != cEvalScale(cRealScale())) { - Ui::show(Box(lang(lng_settings_need_restart), lang(lng_settings_restart_now), base::lambda_guarded(this, [this] { + Ui::show(Box(lang(lng_settings_need_restart), lang(lng_settings_restart_now), crl::guard(this, [this] { cSetConfigScale(_newScale); Local::writeSettings(); App::restart(); - }), base::lambda_guarded(this, [this] { + }), crl::guard(this, [this] { App::CallDelayed(st::boxDuration, this, [this] { setScale(cRealScale()); }); diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index 37d638ceec..b9e70eebad 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -35,7 +35,7 @@ namespace Settings { namespace { QString SecretText; -QMap> Codes; +QMap> Codes; void fillCodes() { Codes.insert(qsl("debugmode"), [] { diff --git a/Telegram/SourceFiles/stdafx.h b/Telegram/SourceFiles/stdafx.h index f751893b4c..f118305b3e 100644 --- a/Telegram/SourceFiles/stdafx.h +++ b/Telegram/SourceFiles/stdafx.h @@ -76,18 +76,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/variant.h" #include "base/optional.h" #include "base/algorithm.h" -#include "base/functors.h" - -namespace func = base::functors; - #include "base/flat_set.h" #include "base/flat_map.h" +#include "base/weak_ptr.h" #include "core/basic_types.h" #include "logs.h" #include "core/utils.h" -#include "base/lambda.h" -#include "base/lambda_guard.h" #include "config.h" #include "mtproto/facade.h" diff --git a/Telegram/SourceFiles/ui/abstract_button.h b/Telegram/SourceFiles/ui/abstract_button.h index a16f5aa86e..fe613578cb 100644 --- a/Telegram/SourceFiles/ui/abstract_button.h +++ b/Telegram/SourceFiles/ui/abstract_button.h @@ -39,7 +39,7 @@ public: void setAcceptBoth(bool acceptBoth = true); - void setClickedCallback(base::lambda callback) { + void setClickedCallback(Fn callback) { _clickedCallback = std::move(callback); } @@ -98,7 +98,7 @@ private: Qt::KeyboardModifiers _modifiers; bool _enablePointerCursor = true; - base::lambda _clickedCallback; + Fn _clickedCallback; rpl::event_stream<> _clicks; diff --git a/Telegram/SourceFiles/ui/animation.h b/Telegram/SourceFiles/ui/animation.h index a6000ce121..778bee47ac 100644 --- a/Telegram/SourceFiles/ui/animation.h +++ b/Telegram/SourceFiles/ui/animation.h @@ -90,7 +90,7 @@ enum class activation { background, }; -using transition = base::lambda; +using transition = Fn; extern transition linear; extern transition sineInOut; @@ -681,7 +681,7 @@ private: anim::value value; BasicAnimation a_animation; - base::lambda updateCallback; + Fn updateCallback; float64 duration = 0.; anim::transition transition = anim::linear; MTP::PauseHolder pause; diff --git a/Telegram/SourceFiles/ui/effects/fade_animation.h b/Telegram/SourceFiles/ui/effects/fade_animation.h index c068c7dd3b..3e815d13ff 100644 --- a/Telegram/SourceFiles/ui/effects/fade_animation.h +++ b/Telegram/SourceFiles/ui/effects/fade_animation.h @@ -19,10 +19,10 @@ public: 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(); diff --git a/Telegram/SourceFiles/ui/effects/numbers_animation.cpp b/Telegram/SourceFiles/ui/effects/numbers_animation.cpp index d2758904ef..beca4ebdcd 100644 --- a/Telegram/SourceFiles/ui/effects/numbers_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/numbers_animation.cpp @@ -14,7 +14,7 @@ namespace Ui { NumbersAnimation::NumbersAnimation( const style::font &font, - base::lambda animationCallback) + Fn animationCallback) : _font(font) , _animationCallback(std::move(animationCallback)) { for (auto ch = '0'; ch != '9'; ++ch) { diff --git a/Telegram/SourceFiles/ui/effects/numbers_animation.h b/Telegram/SourceFiles/ui/effects/numbers_animation.h index cfd15d979b..8ed9c12818 100644 --- a/Telegram/SourceFiles/ui/effects/numbers_animation.h +++ b/Telegram/SourceFiles/ui/effects/numbers_animation.h @@ -19,9 +19,9 @@ class NumbersAnimation { public: NumbersAnimation( const style::font &font, - base::lambda animationCallback); + Fn animationCallback); - void setWidthChangedCallback(base::lambda callback) { + void setWidthChangedCallback(Fn callback) { _widthChangedCallback = std::move(callback); } void setText(const QString &text, int value); @@ -58,8 +58,8 @@ private: int _value = 0; bool _growing = false; - base::lambda _animationCallback; - base::lambda _widthChangedCallback; + Fn _animationCallback; + Fn _widthChangedCallback; }; diff --git a/Telegram/SourceFiles/ui/effects/ripple_animation.cpp b/Telegram/SourceFiles/ui/effects/ripple_animation.cpp index a633174317..c44170cefe 100644 --- a/Telegram/SourceFiles/ui/effects/ripple_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/ripple_animation.cpp @@ -181,7 +181,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); @@ -197,7 +197,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 2acfc91dee..9e01f88639 100644 --- a/Telegram/SourceFiles/ui/effects/ripple_animation.h +++ b/Telegram/SourceFiles/ui/effects/ripple_animation.h @@ -13,7 +13,7 @@ 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); @@ -30,7 +30,7 @@ public: 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 b22a1c8d95..fc856bb061 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp @@ -278,7 +278,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) { } @@ -374,7 +374,7 @@ void RoundCheckbox::prepareInactiveCache() { _inactiveCacheFg = App::pixmapFromImageInPlace(std::move(cacheFg)); } -RoundImageCheckbox::RoundImageCheckbox(const style::RoundImageCheckbox &st, base::lambda updateCallback, PaintRoundImage &&paintRoundImage) +RoundImageCheckbox::RoundImageCheckbox(const style::RoundImageCheckbox &st, Fn updateCallback, PaintRoundImage &&paintRoundImage) : _st(st) , _updateCallback(updateCallback) , _paintRoundImage(std::move(paintRoundImage)) diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.h b/Telegram/SourceFiles/ui/effects/round_checkbox.h index c5a0963f8f..4d24b519ce 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.h +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.h @@ -13,7 +13,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, float64 masterScale = 1.); @@ -33,7 +33,7 @@ private: void prepareInactiveCache(); const style::RoundCheckbox &_st; - base::lambda _updateCallback; + Fn _updateCallback; bool _checked = false; Animation _checkedProgress; @@ -45,8 +45,8 @@ private: class RoundImageCheckbox { public: - using PaintRoundImage = base::lambda; - RoundImageCheckbox(const style::RoundImageCheckbox &st, base::lambda updateCallback, PaintRoundImage &&paintRoundImage); + using PaintRoundImage = Fn; + RoundImageCheckbox(const style::RoundImageCheckbox &st, Fn updateCallback, PaintRoundImage &&paintRoundImage); void paint(Painter &p, TimeMs ms, int x, int y, int outerWidth); float64 checkedAnimationRatio() const; @@ -65,7 +65,7 @@ private: void prepareWideCache(); const style::RoundImageCheckbox &_st; - base::lambda _updateCallback; + Fn _updateCallback; PaintRoundImage _paintRoundImage; QPixmap _wideCache; diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index c60db0bad6..23337cb883 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -471,14 +471,14 @@ void UserpicButton::setClickHandlerByRole() { } void UserpicButton::changePhotoLazy() { - auto callback = base::lambda_guarded( + auto callback = crl::guard( this, [this](QImage &&image) { setImage(std::move(image)); }); ShowChoosePhotoBox(this, _peerForCrop, std::move(callback)); } void UserpicButton::uploadNewPeerPhoto() { - auto callback = base::lambda_guarded( + auto callback = crl::guard( this, [this](QImage &&image) { Messenger::Instance().uploadProfilePhoto( diff --git a/Telegram/SourceFiles/ui/special_buttons.h b/Telegram/SourceFiles/ui/special_buttons.h index a373d84672..5d02454b78 100644 --- a/Telegram/SourceFiles/ui/special_buttons.h +++ b/Telegram/SourceFiles/ui/special_buttons.h @@ -98,16 +98,16 @@ public: void setRecordActive(bool recordActive); void finishAnimating(); - 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); } @@ -135,10 +135,10 @@ private: 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; }; diff --git a/Telegram/SourceFiles/ui/twidget.h b/Telegram/SourceFiles/ui/twidget.h index 43f11bda9e..22083be4d5 100644 --- a/Telegram/SourceFiles/ui/twidget.h +++ b/Telegram/SourceFiles/ui/twidget.h @@ -450,7 +450,7 @@ QPointer make_weak(not_null object) { class SingleQueuedInvokation : public QObject { public: - SingleQueuedInvokation(base::lambda callback) : _callback(callback) { + SingleQueuedInvokation(Fn callback) : _callback(callback) { } void call() { if (_pending.testAndSetAcquire(0, 1)) { @@ -463,7 +463,7 @@ public: } 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 6ba7886492..358330c465 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.cpp +++ b/Telegram/SourceFiles/ui/widgets/buttons.cpp @@ -204,7 +204,7 @@ void FlatButton::paintEvent(QPaintEvent *e) { p.drawText(r, _text, style::al_top); } -RoundButton::RoundButton(QWidget *parent, base::lambda textFactory, const style::RoundButton &st) : RippleButton(parent, st.ripple) +RoundButton::RoundButton(QWidget *parent, Fn textFactory, const style::RoundButton &st) : RippleButton(parent, st.ripple) , _textFactory(std::move(textFactory)) , _st(st) { subscribe(Lang::Current().updated(), [this] { refreshText(); }); @@ -216,7 +216,7 @@ void RoundButton::setTextTransform(TextTransform transform) { refreshText(); } -void RoundButton::setText(base::lambda textFactory) { +void RoundButton::setText(Fn textFactory) { _textFactory = std::move(textFactory); refreshText(); } @@ -235,7 +235,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.font, [this] { numbersAnimationCallback(); diff --git a/Telegram/SourceFiles/ui/widgets/buttons.h b/Telegram/SourceFiles/ui/widgets/buttons.h index 72a87b0fcb..28c331e7dd 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.h +++ b/Telegram/SourceFiles/ui/widgets/buttons.h @@ -100,9 +100,9 @@ private: 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()); @@ -110,7 +110,7 @@ public: void setNumbersText(int numbers) { setNumbersText(QString::number(numbers), numbers); } - void setWidthChangedCallback(base::lambda callback); + void setWidthChangedCallback(Fn callback); void stepNumbersAnimation(TimeMs ms); void finishNumbersAnimation(); @@ -140,7 +140,7 @@ private: void resizeToText(); QString _text; - base::lambda _textFactory; + Fn _textFactory; int _textWidth; std::unique_ptr _numbers; diff --git a/Telegram/SourceFiles/ui/widgets/checkbox.cpp b/Telegram/SourceFiles/ui/widgets/checkbox.cpp index d1fc354d6a..6b46f007e0 100644 --- a/Telegram/SourceFiles/ui/widgets/checkbox.cpp +++ b/Telegram/SourceFiles/ui/widgets/checkbox.cpp @@ -22,7 +22,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)) { @@ -36,7 +36,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); @@ -67,7 +67,7 @@ float64 AbstractCheckView::currentAnimationValue(TimeMs ms) { ToggleView::ToggleView( const style::Toggle &st, bool checked, - base::lambda updateCallback) + Fn updateCallback) : AbstractCheckView(st.duration, checked, std::move(updateCallback)) , _st(&st) { } @@ -204,7 +204,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) : AbstractCheckView(st.duration, checked, std::move(updateCallback)) +CheckView::CheckView(const style::Check &st, bool checked, Fn updateCallback) : AbstractCheckView(st.duration, checked, std::move(updateCallback)) , _st(&st) { } @@ -261,7 +261,7 @@ void CheckView::setUntoggledOverride( RadioView::RadioView( const style::Radio &st, bool checked, - base::lambda updateCallback) + 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 c5fc35cfb3..6567563927 100644 --- a/Telegram/SourceFiles/ui/widgets/checkbox.h +++ b/Telegram/SourceFiles/ui/widgets/checkbox.h @@ -15,12 +15,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 finishAnimating(); - void setUpdateCallback(base::lambda updateCallback); + void setUpdateCallback(Fn updateCallback); bool checked() const { return _checked; } @@ -49,7 +49,7 @@ public: private: int _duration = 0; bool _checked = false; - base::lambda _updateCallback; + Fn _updateCallback; Animation _toggleAnimation; rpl::event_stream _checks; @@ -61,7 +61,7 @@ public: CheckView( const style::Check &st, bool checked, - base::lambda updateCallback = nullptr); + Fn updateCallback = nullptr); void setStyle(const style::Check &st); @@ -86,7 +86,7 @@ public: RadioView( const style::Radio &st, bool checked, - base::lambda updateCallback = nullptr); + Fn updateCallback = nullptr); void setStyle(const style::Radio &st); @@ -110,7 +110,7 @@ public: ToggleView( const style::Toggle &st, bool checked, - base::lambda updateCallback = nullptr); + Fn updateCallback = nullptr); void setStyle(const style::Toggle &st); @@ -202,7 +202,7 @@ public: RadiobuttonGroup(int value) : _value(value), _hasValue(true) { } - void setChangedCallback(base::lambda callback) { + void setChangedCallback(Fn callback) { _changedCallback = std::move(callback); } @@ -227,7 +227,7 @@ private: 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 11b69d567a..847ab226f1 100644 --- a/Telegram/SourceFiles/ui/widgets/continuous_sliders.h +++ b/Telegram/SourceFiles/ui/widgets/continuous_sliders.h @@ -32,7 +32,7 @@ public: return _disabled; } - using Callback = base::lambda; + using Callback = Fn; void setChangeProgressCallback(Callback &&callback) { _changeProgressCallback = std::move(callback); } diff --git a/Telegram/SourceFiles/ui/widgets/dropdown_menu.cpp b/Telegram/SourceFiles/ui/widgets/dropdown_menu.cpp index e1ea73b362..a309dd0796 100644 --- a/Telegram/SourceFiles/ui/widgets/dropdown_menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/dropdown_menu.cpp @@ -56,7 +56,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, const style::icon *iconOver) { +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 9d73839907..a9ab80ccaf 100644 --- a/Telegram/SourceFiles/ui/widgets/dropdown_menu.h +++ b/Telegram/SourceFiles/ui/widgets/dropdown_menu.h @@ -20,11 +20,11 @@ public: DropdownMenu(QWidget *parent, const style::DropdownMenu &st = st::defaultDropdownMenu); 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, const style::icon *iconOver = 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); } @@ -88,7 +88,7 @@ private: 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 721494ec45..1575f344eb 100644 --- a/Telegram/SourceFiles/ui/widgets/inner_dropdown.h +++ b/Telegram/SourceFiles/ui/widgets/inner_dropdown.h @@ -41,13 +41,13 @@ public: 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); } @@ -115,9 +115,9 @@ private: 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 87b0ef9c45..952cdf378a 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -789,7 +789,7 @@ const InstantReplaces &InstantReplaces::Default() { return result; } -FlatInput::FlatInput(QWidget *parent, const style::FlatInput &st, base::lambda placeholderFactory, const QString &v) : TWidgetHelper(v, parent) +FlatInput::FlatInput(QWidget *parent, const style::FlatInput &st, Fn placeholderFactory, const QString &v) : TWidgetHelper(v, parent) , _oldtext(v) , _placeholderFactory(std::move(placeholderFactory)) , _placeholderVisible(!v.length()) @@ -962,7 +962,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(); } @@ -1078,7 +1078,7 @@ void FlatInput::onTextChange(const QString &text) { InputField::InputField( QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory, + Fn placeholderFactory, const QString &value) : InputField( parent, @@ -1092,7 +1092,7 @@ InputField::InputField( QWidget *parent, const style::InputField &st, Mode mode, - base::lambda placeholderFactory, + Fn placeholderFactory, const QString &value) : InputField( parent, @@ -1106,7 +1106,7 @@ InputField::InputField( QWidget *parent, const style::InputField &st, Mode mode, - base::lambda placeholderFactory, + Fn placeholderFactory, const TextWithTags &value) : RpWidget(parent) , _st(st) @@ -3276,7 +3276,7 @@ void InputField::refreshPlaceholder() { } void InputField::setPlaceholder( - base::lambda placeholderFactory, + Fn placeholderFactory, int afterSymbols) { _placeholderFactory = std::move(placeholderFactory); if (_placeholderAfterSymbols != afterSymbols) { @@ -3287,7 +3287,7 @@ void InputField::setPlaceholder( } void InputField::setEditLinkCallback( - base::lambda placeholderFactory, + Fn placeholderFactory, const QString &val) : Parent(val, parent) , _st(st) @@ -3597,7 +3597,7 @@ void MaskedInputField::refreshPlaceholder() { update(); } -void MaskedInputField::setPlaceholder(base::lambda placeholderFactory) { +void MaskedInputField::setPlaceholder(Fn placeholderFactory) { _placeholderFactory = std::move(placeholderFactory); refreshPlaceholder(); } @@ -3926,11 +3926,11 @@ void PhonePartInput::onChooseCode(const QString &code) { startPlaceholderAnimation(); } -PasswordInput::PasswordInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { +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) : MaskedInputField(parent, st, std::move(placeholderFactory), 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 +3961,7 @@ void PortInput::correctValue( setCorrectedText(now, nowCursor, newText, newPos); } -HexInput::HexInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { +HexInput::HexInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { if (!QRegularExpression("^[a-fA-F0-9]+$").match(val).hasMatch()) { setText(QString()); } @@ -3988,7 +3988,7 @@ void HexInput::correctValue( setCorrectedText(now, nowCursor, newText, newPos); } -UsernameInput::UsernameInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, const QString &val, bool isLink) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { +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()); } @@ -4035,7 +4035,7 @@ void UsernameInput::correctValue( setCorrectedText(now, nowCursor, now.mid(from, len), newPos); } -PhoneInput::PhoneInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { +PhoneInput::PhoneInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val) : MaskedInputField(parent, st, std::move(placeholderFactory), val) { QString phone(val); if (phone.isEmpty()) { clearText(); diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.h b/Telegram/SourceFiles/ui/widgets/input_fields.h index 22187247f0..15eabca557 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.h +++ b/Telegram/SourceFiles/ui/widgets/input_fields.h @@ -40,11 +40,11 @@ public: FlatInput( QWidget *parent, const style::FlatInput &st, - base::lambda placeholderFactory = nullptr, + Fn placeholderFactory = nullptr, const QString &val = QString()); void updatePlaceholder(); - void setPlaceholder(base::lambda placeholderFactory); + void setPlaceholder(Fn placeholderFactory); QRect placeholderRect() const; void setTextMrg(const QMargins &textMrg); @@ -96,7 +96,7 @@ private: QString _oldtext; QString _placeholder; - base::lambda _placeholderFactory; + Fn _placeholderFactory; bool _customUpDown = false; @@ -138,19 +138,19 @@ public: InputField( QWidget *parent, const style::InputField &st, - base::lambda placeholderFactory, + Fn placeholderFactory, const QString &value = QString()); InputField( QWidget *parent, const style::InputField &st, Mode mode, - base::lambda placeholderFactory, + Fn placeholderFactory, const QString &value); InputField( QWidget *parent, const style::InputField &st, Mode mode = Mode::SingleLine, - base::lambda placeholderFactory = nullptr, + Fn placeholderFactory = nullptr, const TextWithTags &value = TextWithTags()); void showError(); @@ -200,7 +200,7 @@ public: Edit, }; void setEditLinkCallback( - base::lambda placeholderFactory, + Fn placeholderFactory, int afterSymbols = 0); void setPlaceholderHidden(bool forcePlaceholderHidden); void setDisplayFocused(bool focused); @@ -280,7 +280,7 @@ public: Check, Insert, }; - using MimeDataHook = base::lambda data, MimeAction action)>; void setMimeDataHook(MimeDataHook hook) { @@ -412,7 +412,7 @@ private: TextWithTags _lastTextWithTags; std::vector _lastMarkdownTags; QString _lastPreEditText; - base::lambda _placeholderFactory; + Fn _placeholderFactory; int _placeholderAfterSymbols = 0; Animation _a_placeholderShifted; bool _placeholderShifted = false; @@ -484,7 +484,7 @@ class MaskedInputField using Parent = RpWidgetWrap; public: - MaskedInputField(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory = base::lambda(), const QString &val = QString()); + MaskedInputField(QWidget *parent, const style::InputField &st, Fn placeholderFactory = Fn(), const QString &val = QString()); void showError(); @@ -499,7 +499,7 @@ public: const QString &getLastText() const { return _oldtext; } - void setPlaceholder(base::lambda placeholderFactory); + void setPlaceholder(Fn placeholderFactory); void setPlaceholderHidden(bool forcePlaceholderHidden); void setDisplayFocused(bool focused); void finishAnimating(); @@ -594,7 +594,7 @@ private: bool _customUpDown = false; QString _placeholder; - base::lambda _placeholderFactory; + Fn _placeholderFactory; Animation _a_placeholderShifted; bool _placeholderShifted = false; QPainterPath _placeholderPath; @@ -676,13 +676,13 @@ private: class PasswordInput : public MaskedInputField { public: - PasswordInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory = base::lambda(), const QString &val = QString()); + 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( @@ -695,7 +695,7 @@ protected: class HexInput : public MaskedInputField { public: - HexInput(QWidget *parent, const style::InputField &st, base::lambda placeholderFactory, const QString &val); + HexInput(QWidget *parent, const style::InputField &st, Fn placeholderFactory, const QString &val); protected: void correctValue( @@ -708,7 +708,7 @@ protected: 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); @@ -727,7 +727,7 @@ private: 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 45f0c1a6e9..7419c43d74 100644 --- a/Telegram/SourceFiles/ui/widgets/labels.h +++ b/Telegram/SourceFiles/ui/widgets/labels.h @@ -109,7 +109,7 @@ public: void setLink(uint16 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 d79fd2df48..c0897fb156 100644 --- a/Telegram/SourceFiles/ui/widgets/menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/menu.cpp @@ -49,7 +49,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, const style::icon *iconOver) { +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); return action; diff --git a/Telegram/SourceFiles/ui/widgets/menu.h b/Telegram/SourceFiles/ui/widgets/menu.h index fbf243d08e..3a995b7a80 100644 --- a/Telegram/SourceFiles/ui/widgets/menu.h +++ b/Telegram/SourceFiles/ui/widgets/menu.h @@ -22,7 +22,7 @@ public: Menu(QWidget *parent, QMenu *menu, const style::Menu &st = st::defaultMenu); 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, const style::icon *iconOver = nullptr); + QAction *addAction(const QString &text, Fn callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); QAction *addSeparator(); void clearActions(); void finishAnimating(); @@ -42,33 +42,33 @@ public: 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); @@ -122,13 +122,13 @@ private: 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 57749affbb..bcf7722bdc 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.cpp +++ b/Telegram/SourceFiles/ui/widgets/multi_select.cpp @@ -234,7 +234,7 @@ void MultiSelect::Item::setOver(bool over) { MultiSelect::MultiSelect( QWidget *parent, const style::MultiSelect &st, - base::lambda placeholderFactory) + Fn placeholderFactory) : RpWidget(parent) , _st(st) , _scroll(this, _st.scroll) { @@ -285,15 +285,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); } @@ -324,7 +324,7 @@ void MultiSelect::finishItemsBunch() { _inner->finishItemsBunch(AddItemWay::SkipAnimation); } -void MultiSelect::setItemRemovedCallback(base::lambda callback) { +void MultiSelect::setItemRemovedCallback(Fn callback) { _inner->setItemRemovedCallback(std::move(callback)); } @@ -353,7 +353,7 @@ int MultiSelect::resizeGetHeight(int newWidth) { return newHeight; } -MultiSelect::Inner::Inner(QWidget *parent, const style::MultiSelect &st, base::lambda placeholder, ScrollCallback callback) : TWidget(parent) +MultiSelect::Inner::Inner(QWidget *parent, const style::MultiSelect &st, Fn placeholder, ScrollCallback callback) : TWidget(parent) , _st(st) , _scrollCallback(std::move(callback)) , _field(this, _st.field, std::move(placeholder)) @@ -396,12 +396,12 @@ 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) { + Fn callback) { _submittedCallback = std::move(callback); } @@ -709,11 +709,11 @@ void MultiSelect::Inner::setItemText(uint64 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 8127fac02e..dd69488104 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.h +++ b/Telegram/SourceFiles/ui/widgets/multi_select.h @@ -18,27 +18,27 @@ class ScrollArea; class MultiSelect : public RpWidget { 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(uint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage, AddItemWay way = AddItemWay::Default); void addItemInBunch(uint64 itemId, const QString &text, style::color color, PaintRoundImage paintRoundImage); void finishItemsBunch(); void setItemText(uint64 itemId, const QString &text); - void setItemRemovedCallback(base::lambda callback); + void setItemRemovedCallback(Fn callback); void removeItem(uint64 itemId); int getItemsCount() const; @@ -61,8 +61,8 @@ private: class Inner; QPointer _inner; - base::lambda _resizedCallback; - base::lambda _queryChangedCallback; + Fn _resizedCallback; + Fn _queryChangedCallback; }; @@ -71,28 +71,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(uint64 itemId, const QString &text); - void setItemRemovedCallback(base::lambda callback); + void setItemRemovedCallback(Fn callback); void removeItem(uint64 itemId); int getItemsCount() const; QVector getItems() const; bool hasItem(uint64 itemId) const; - void setResizedCallback(base::lambda callback); + void setResizedCallback(Fn callback); ~Inner(); @@ -152,10 +152,10 @@ private: 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; }; @@ -182,7 +182,7 @@ public: 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); @@ -214,7 +214,7 @@ private: uint64 _id; struct SlideAnimation { - SlideAnimation(base::lambda updateCallback, int fromX, int toX, int y, float64 duration) + SlideAnimation(Fn updateCallback, int fromX, int toX, int y, float64 duration) : fromX(fromX) , toX(toX) , y(y) { @@ -237,7 +237,7 @@ private: 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 891ee8313e..18ea6ec4e1 100644 --- a/Telegram/SourceFiles/ui/widgets/popup_menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/popup_menu.cpp @@ -82,7 +82,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, const style::icon *iconOver) { +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 7a7ebc3778..0b9a6c7652 100644 --- a/Telegram/SourceFiles/ui/widgets/popup_menu.h +++ b/Telegram/SourceFiles/ui/widgets/popup_menu.h @@ -19,7 +19,7 @@ public: PopupMenu(QWidget*, QMenu *menu, const style::PopupMenu &st = st::defaultPopupMenu); 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, const style::icon *iconOver = nullptr); + QAction *addAction(const QString &text, Fn callback, const style::icon *icon = nullptr, const style::icon *iconOver = nullptr); QAction *addSeparator(); void clearActions(); @@ -30,7 +30,7 @@ public: void popup(const QPoint &p); void hideMenu(bool fast = false); - void setDestroyedCallback(base::lambda callback) { + void setDestroyedCallback(Fn callback) { _destroyedCallback = std::move(callback); } @@ -124,7 +124,7 @@ private: bool _triggering = false; bool _deleteLater = false; - base::lambda _destroyedCallback; + Fn _destroyedCallback; }; diff --git a/Telegram/SourceFiles/ui/widgets/tooltip.h b/Telegram/SourceFiles/ui/widgets/tooltip.h index 6f02f302da..667dfcf0a9 100644 --- a/Telegram/SourceFiles/ui/widgets/tooltip.h +++ b/Telegram/SourceFiles/ui/widgets/tooltip.h @@ -75,7 +75,7 @@ public: void toggleFast(bool visible); void hideAfter(TimeMs timeout); - void setHiddenCallback(base::lambda callback) { + void setHiddenCallback(Fn callback) { _hiddenCallback = std::move(callback); } @@ -101,7 +101,7 @@ private: Animation _visibleAnimation; bool _visible = false; - base::lambda _hiddenCallback; + Fn _hiddenCallback; bool _useTransparency = true; QPixmap _cache; diff --git a/Telegram/SourceFiles/window/layer_widget.cpp b/Telegram/SourceFiles/window/layer_widget.cpp index 36d5fdce02..d28a249088 100644 --- a/Telegram/SourceFiles/window/layer_widget.cpp +++ b/Telegram/SourceFiles/window/layer_widget.cpp @@ -38,7 +38,7 @@ public: BackgroundWidget(QWidget *parent) : TWidget(parent) { } - void setDoneCallback(base::lambda callback) { + void setDoneCallback(Fn callback) { _doneCallback = std::move(callback); } @@ -72,7 +72,7 @@ private: QPixmap _specialLayerCache; QPixmap _layerCache; - base::lambda _doneCallback; + Fn _doneCallback; bool _wasAnimating = false; bool _inPaintEvent = false; diff --git a/Telegram/SourceFiles/window/layer_widget.h b/Telegram/SourceFiles/window/layer_widget.h index 9a25a6facd..b54aa1fcf5 100644 --- a/Telegram/SourceFiles/window/layer_widget.h +++ b/Telegram/SourceFiles/window/layer_widget.h @@ -35,10 +35,10 @@ public: 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); } virtual bool takeToThirdSection() { @@ -72,8 +72,8 @@ protected: private: bool _closing = false; - base::lambda _closedCallback; - base::lambda _resizedCallback; + Fn _closedCallback; + Fn _resizedCallback; }; diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 9d6a8b96b8..5b2c1362a1 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -827,7 +827,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 802e6e527a..166d609915 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -135,7 +135,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 cfb4afaca7..0eac8acbef 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -194,19 +194,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(); @@ -238,9 +238,9 @@ private: 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; @@ -318,7 +318,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(); @@ -621,7 +621,7 @@ void ThemeExportBox::updateThumbnail() { } void ThemeExportBox::chooseBackgroundFromFile() { - FileDialog::GetOpenPath(this, lang(lng_theme_editor_choose_image), "Image files (*.jpeg *.jpg *.png)", base::lambda_guarded(this, [this](const FileDialog::OpenResult &result) { + FileDialog::GetOpenPath(this, lang(lng_theme_editor_choose_image), "Image files (*.jpeg *.jpg *.png)", crl::guard(this, [this](const FileDialog::OpenResult &result) { auto content = result.remoteContent; if (!result.paths.isEmpty()) { QFile f(result.paths.front()); @@ -651,7 +651,7 @@ void ThemeExportBox::exportTheme() { auto caption = lang(lng_theme_editor_choose_name); auto filter = "Themes (*.tdesktop-theme)"; auto name = "awesome.tdesktop-theme"; - FileDialog::GetWritePath(this, caption, filter, name, base::lambda_guarded(this, [this](const QString &path) { + FileDialog::GetWritePath(this, caption, filter, name, crl::guard(this, [this](const QString &path) { zlib::FileToWrite zip; zip_fileinfo zfi = { { 0, 0, 0, 0, 0, 0 }, 0, 0, 0 }; diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp index d2a901b8e8..dbd43e9a32 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp @@ -294,10 +294,10 @@ void EditorBlock::activateRow(const Row &row) { } else { _editing = findRowIndex(&row); if (auto box = Ui::show(Box(row.name(), row.value()))) { - box->setSaveCallback(base::lambda_guarded(this, [this](QColor value) { + box->setSaveCallback(crl::guard(this, [this](QColor value) { saveEditing(value); })); - box->setCancelCallback(base::lambda_guarded(this, [this] { + box->setCancelCallback(crl::guard(this, [this] { cancelEditing(); })); _context->box = box; diff --git a/Telegram/SourceFiles/window/themes/window_theme_warning.h b/Telegram/SourceFiles/window/themes/window_theme_warning.h index 39159d052d..328460e0b9 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_warning.h +++ b/Telegram/SourceFiles/window/themes/window_theme_warning.h @@ -18,7 +18,7 @@ class WarningWidget : public TWidget { public: WarningWidget(QWidget *parent); - void setHiddenCallback(base::lambda callback) { + void setHiddenCallback(Fn callback) { _hiddenCallback = std::move(callback); } @@ -51,7 +51,7 @@ private: object_ptr _keepChanges; object_ptr _revert; - base::lambda _hiddenCallback; + Fn _hiddenCallback; }; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 3d038503ed..9c4da44ea1 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -565,7 +565,7 @@ void PeerMenuShareContactBox(not_null user) { QPointer ShowForwardMessagesBox( MessageIdsList &&items, - base::lambda_once &&successCallback) { + FnMut &&successCallback) { const auto weak = std::make_shared>(); auto callback = [ ids = std::move(items), @@ -684,7 +684,7 @@ void PeerMenuAddMuteAction( // callback); //} -base::lambda ClearHistoryHandler(not_null peer) { +Fn ClearHistoryHandler(not_null peer) { return [peer] { const auto weak = std::make_shared>(); const auto text = peer->isSelf() @@ -708,7 +708,7 @@ base::lambda ClearHistoryHandler(not_null peer) { }; } -base::lambda DeleteAndLeaveHandler(not_null peer) { +Fn DeleteAndLeaveHandler(not_null peer) { return [peer] { const auto warningText = peer->isSelf() ? lang(lng_sure_delete_saved_messages) diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index 2b11ab99e5..8baca1921d 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -25,9 +25,9 @@ enum class PeerMenuSource { Profile, }; -using PeerMenuCallback = base::lambda handler)>; + Fn handler)>; void FillPeerMenu( not_null controller, @@ -51,11 +51,11 @@ void PeerMenuAddChannelMembers(not_null channel); //void PeerMenuUngroupFeed(not_null feed); // #feed //void ToggleChannelGrouping(not_null channel, bool group); // #feed -base::lambda ClearHistoryHandler(not_null peer); -base::lambda DeleteAndLeaveHandler(not_null peer); +Fn ClearHistoryHandler(not_null peer); +Fn DeleteAndLeaveHandler(not_null peer); QPointer ShowForwardMessagesBox( MessageIdsList &&items, - base::lambda_once &&successCallback = nullptr); + FnMut &&successCallback = nullptr); } // namespace Window diff --git a/Telegram/SourceFiles/window/window_slide_animation.h b/Telegram/SourceFiles/window/window_slide_animation.h index 8cdbd7818f..206e50fedb 100644 --- a/Telegram/SourceFiles/window/window_slide_animation.h +++ b/Telegram/SourceFiles/window/window_slide_animation.h @@ -23,10 +23,10 @@ public: void setTopBarShadow(bool enabled); void setWithFade(bool withFade); - using RepaintCallback = base::lambda; + using RepaintCallback = Fn; void setRepaintCallback(RepaintCallback &&callback); - using FinishedCallback = base::lambda; + using FinishedCallback = Fn; void setFinishedCallback(FinishedCallback &&callback); void start(); diff --git a/Telegram/ThirdParty/crl b/Telegram/ThirdParty/crl index 344cbde9ae..f893c36427 160000 --- a/Telegram/ThirdParty/crl +++ b/Telegram/ThirdParty/crl @@ -1 +1 @@ -Subproject commit 344cbde9ae8d89a6530408d3176d2754ae0ff0e2 +Subproject commit f893c36427993e22181c8b3ec382dedb5563dc08 diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index 04b1ca0418..e21be3b601 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -7,8 +7,6 @@ <(src_loc)/base/flat_map.h <(src_loc)/base/flat_set.h <(src_loc)/base/functors.h -<(src_loc)/base/lambda.h -<(src_loc)/base/lambda_guard.h <(src_loc)/base/index_based_iterator.h <(src_loc)/base/observer.cpp <(src_loc)/base/observer.h