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__DATE_PICKER_DATE_PICKER_EVENT_HUB_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS__DATE_PICKER_DATE_PICKER_EVENT_HUB_H 18 19 #include "base/memory/ace_type.h" 20 #include "core/components_ng/event/event_hub.h" 21 #include "core/components_ng/event/gesture_event_hub.h" 22 23 namespace OHOS::Ace::NG { 24 25 using DateChangeEvent = std::function<void(const BaseEventInfo* info)>; 26 using DialogEvent = std::function<void(const std::string&)>; 27 using DialogCancelEvent = std::function<void()>; 28 using DialogGestureEvent = std::function<void(const GestureEvent& info)>; 29 30 class DatePickerEventHub : public EventHub { 31 DECLARE_ACE_TYPE(DatePickerEventHub, EventHub) 32 33 public: 34 DatePickerEventHub() = default; 35 ~DatePickerEventHub() override = default; 36 SetOnChange(DateChangeEvent && onChange)37 void SetOnChange(DateChangeEvent&& onChange) 38 { 39 changeEvent_ = std::move(onChange); 40 } 41 SetOnDateChange(DateChangeEvent && onChange)42 void SetOnDateChange(DateChangeEvent&& onChange) 43 { 44 dateChangeEvent_ = std::move(onChange); 45 } 46 FireChangeEvent(const BaseEventInfo * info)47 void FireChangeEvent(const BaseEventInfo* info) const 48 { 49 if (selectedChangeEvent_) { 50 selectedChangeEvent_(info); 51 } 52 if (changeEvent_) { 53 changeEvent_(info); 54 } 55 if (dateChangeEvent_) { 56 dateChangeEvent_(info); 57 } 58 } 59 SetDialogChange(DialogEvent && onChange)60 void SetDialogChange(DialogEvent&& onChange) 61 { 62 dialogChangeEvent_ = std::move(onChange); 63 } 64 FireDialogChangeEvent(const std::string & info)65 void FireDialogChangeEvent(const std::string& info) const 66 { 67 if (dialogChangeEvent_) { 68 dialogChangeEvent_(info); 69 } 70 if (dialogDateChangeEvent_) { 71 dialogDateChangeEvent_(info); 72 } 73 } 74 SetDialogAcceptEvent(DialogEvent && onChange)75 void SetDialogAcceptEvent(DialogEvent&& onChange) 76 { 77 dialogAcceptEvent_ = std::move(onChange); 78 } 79 FireDialogAcceptEvent(const std::string & info)80 void FireDialogAcceptEvent(const std::string& info) const 81 { 82 if (dialogAcceptEvent_) { 83 dialogAcceptEvent_(info); 84 } 85 if (dialogDateAcceptEvent_) { 86 dialogDateAcceptEvent_(info); 87 } 88 } 89 SetDialogDateChange(DialogEvent && onChange)90 void SetDialogDateChange(DialogEvent&& onChange) 91 { 92 dialogDateChangeEvent_ = std::move(onChange); 93 } 94 SetDialogDateAcceptEvent(DialogEvent && onChange)95 void SetDialogDateAcceptEvent(DialogEvent&& onChange) 96 { 97 dialogDateAcceptEvent_ = std::move(onChange); 98 } 99 SetChangeEvent(DateChangeEvent && onChange)100 void SetChangeEvent(DateChangeEvent&& onChange) 101 { 102 selectedChangeEvent_ = std::move(onChange); 103 } 104 105 private: 106 DateChangeEvent changeEvent_; 107 DateChangeEvent dateChangeEvent_; 108 DialogEvent dialogChangeEvent_; 109 DialogEvent dialogAcceptEvent_; 110 DialogEvent dialogDateChangeEvent_; 111 DialogEvent dialogDateAcceptEvent_; 112 DateChangeEvent selectedChangeEvent_; 113 114 ACE_DISALLOW_COPY_AND_MOVE(DatePickerEventHub); 115 }; 116 117 } // namespace OHOS::Ace::NG 118 119 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS__DATE_PICKER_DATE_PICKER_EVENT_HUB_H 120