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_INDEXER_INDEXER_EVENT_HUB_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_INDEXER_INDEXER_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 #include "core/components_v2/indexer/indexer_event_info.h"
23 
24 namespace OHOS::Ace::NG {
25 
26 using OnSelectedEvent = std::function<void(int32_t)>;
27 using OnRequestPopupDataEvent = std::function<std::vector<std::string>(int32_t)>;
28 using OnPopupSelectedEvent = std::function<void(int32_t)>;
29 
30 class IndexerEventHub : public EventHub {
31     DECLARE_ACE_TYPE(IndexerEventHub, EventHub)
32 
33 public:
34     IndexerEventHub() = default;
35     ~IndexerEventHub() override = default;
36 
SetOnSelected(OnSelectedEvent && onSelected)37     void SetOnSelected(OnSelectedEvent&& onSelected)
38     {
39         onSelectedEvent_ = std::move(onSelected);
40     }
41 
GetOnSelected()42     const OnSelectedEvent& GetOnSelected() const
43     {
44         return onSelectedEvent_;
45     }
46 
SetOnRequestPopupData(OnRequestPopupDataEvent && onRequestPopupData)47     void SetOnRequestPopupData(OnRequestPopupDataEvent&& onRequestPopupData)
48     {
49         onRequestPopupDataEvent_ = std::move(onRequestPopupData);
50     }
51 
GetOnRequestPopupData()52     const OnRequestPopupDataEvent& GetOnRequestPopupData() const
53     {
54         return onRequestPopupDataEvent_;
55     }
56 
SetOnPopupSelected(OnPopupSelectedEvent && onPopupSelected)57     void SetOnPopupSelected(OnPopupSelectedEvent&& onPopupSelected)
58     {
59         onPopupSelectedEvent_ = std::move(onPopupSelected);
60     }
61 
GetOnPopupSelected()62     const OnPopupSelectedEvent& GetOnPopupSelected() const
63     {
64         return onPopupSelectedEvent_;
65     }
66 
SetChangeEvent(OnSelectedEvent && changeEvent)67     void SetChangeEvent(OnSelectedEvent&& changeEvent)
68     {
69         selectedChangeEvent_ = std::move(changeEvent);
70     }
71 
GetChangeEvent()72     const OnSelectedEvent& GetChangeEvent() const
73     {
74         return selectedChangeEvent_;
75     }
SetCreatChangeEvent(OnSelectedEvent && changeEvent)76     void SetCreatChangeEvent(OnSelectedEvent&& changeEvent)
77     {
78         creatChangeEvent_ = std::move(changeEvent);
79     }
80 
GetCreatChangeEvent()81     const OnSelectedEvent& GetCreatChangeEvent() const
82     {
83         return creatChangeEvent_;
84     }
85 
86 private:
87     OnSelectedEvent onSelectedEvent_;
88     OnRequestPopupDataEvent onRequestPopupDataEvent_;
89     OnPopupSelectedEvent onPopupSelectedEvent_;
90     OnSelectedEvent selectedChangeEvent_;
91     OnSelectedEvent creatChangeEvent_;
92 };
93 
94 } // namespace OHOS::Ace::NG
95 
96 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_EVENT_HUB_H
97