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_PATTERN_SELECT_SELECT_EVENT_HUB_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_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 SelectEvent = std::function<void(int32_t, const std::string&)>; 26 using SelectChangeEvent = std::function<void(int32_t)>; 27 using ValueChangeEvent = std::function<void(const std::string&)>; 28 29 class SelectEventHub : public EventHub { 30 DECLARE_ACE_TYPE(SelectEventHub, EventHub) 31 public: 32 SelectEventHub() = default; 33 34 ~SelectEventHub() override = default; 35 SetSelectEvent(SelectEvent && onSelect)36 void SetSelectEvent(SelectEvent&& onSelect) 37 { 38 onSelect_ = std::move(onSelect); 39 } 40 GetSelectEvent()41 const SelectEvent& GetSelectEvent() 42 { 43 return onSelect_; 44 } 45 SetSelectChangeEvent(SelectChangeEvent && selectChangeEvent)46 void SetSelectChangeEvent(SelectChangeEvent&& selectChangeEvent) 47 { 48 selectChangeEvent_ = std::move(selectChangeEvent); 49 } 50 GetSelectChangeEvent()51 const SelectChangeEvent& GetSelectChangeEvent() 52 { 53 return selectChangeEvent_; 54 } 55 SetValueChangeEvent(ValueChangeEvent && valueChangeEvent)56 void SetValueChangeEvent(ValueChangeEvent&& valueChangeEvent) 57 { 58 valueChangeEvent_ = std::move(valueChangeEvent); 59 } 60 GetValueChangeEvent()61 const ValueChangeEvent& GetValueChangeEvent() 62 { 63 return valueChangeEvent_; 64 } 65 66 private: 67 SelectEvent onSelect_; 68 SelectChangeEvent selectChangeEvent_; 69 ValueChangeEvent valueChangeEvent_; 70 71 ACE_DISALLOW_COPY_AND_MOVE(SelectEventHub); 72 }; 73 74 } // namespace OHOS::Ace::NG 75 76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_EVENT_HUB_H 77 78