1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_EVENT_HUB_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_EVENT_HUB_H 18 19 #include "base/memory/ace_type.h" 20 #include "core/components_ng/event/event_hub.h" 21 22 namespace OHOS::Ace::NG { 23 24 using TextChangeEvent = std::function<void(const std::string&, double)>; 25 using DialogTextEvent = std::function<void(const std::string&)>; 26 using DialogCancelEvent = std::function<void()>; 27 using DialogGestureEvent = std::function<void(const GestureEvent& info)>; 28 29 class TextPickerEventHub : public EventHub { 30 DECLARE_ACE_TYPE(TextPickerEventHub, EventHub) 31 32 public: 33 TextPickerEventHub() = default; 34 ~TextPickerEventHub() override = default; 35 SetOnChange(TextChangeEvent && TextChangeEvent)36 void SetOnChange(TextChangeEvent&& TextChangeEvent) 37 { 38 TextChangeEvent_ = std::move(TextChangeEvent); 39 } 40 FireChangeEvent(const std::string & value,double index)41 void FireChangeEvent(const std::string& value, double index) const 42 { 43 if (TextChangeEvent_) { 44 TextChangeEvent_(value, index); 45 } 46 } 47 SetDialogChange(DialogTextEvent && onChange)48 void SetDialogChange(DialogTextEvent&& onChange) 49 { 50 DialogChangeEvent_ = std::move(onChange); 51 } 52 FireDialogChangeEvent(const std::string & info)53 void FireDialogChangeEvent(const std::string& info) const 54 { 55 if (DialogChangeEvent_) { 56 DialogChangeEvent_(info); 57 } 58 } 59 SetDialogAcceptEvent(DialogTextEvent && onChange)60 void SetDialogAcceptEvent(DialogTextEvent&& onChange) 61 { 62 DialogAcceptEvent_ = std::move(onChange); 63 } 64 FireDialogAcceptEvent(const std::string & info)65 void FireDialogAcceptEvent(const std::string& info) const 66 { 67 if (DialogAcceptEvent_) { 68 DialogAcceptEvent_(info); 69 } 70 } 71 private: 72 TextChangeEvent TextChangeEvent_; 73 DialogTextEvent DialogChangeEvent_; 74 DialogTextEvent DialogAcceptEvent_; 75 76 ACE_DISALLOW_COPY_AND_MOVE(TextPickerEventHub); 77 }; 78 79 } // namespace OHOS::Ace::NG 80 81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_EVENT_HUB_H