• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
FireChangeEvent(const BaseEventInfo * info)42     void FireChangeEvent(const BaseEventInfo* info) const
43     {
44         if (changeEvent_) {
45             changeEvent_(info);
46         }
47     }
48 
SetDialogChange(DialogEvent && onChange)49     void SetDialogChange(DialogEvent&& onChange)
50     {
51         dialogChangeEvent_ = std::move(onChange);
52     }
53 
FireDialogChangeEvent(const std::string & info)54     void FireDialogChangeEvent(const std::string& info) const
55     {
56         if (dialogChangeEvent_) {
57             dialogChangeEvent_(info);
58         }
59     }
60 
SetDialogAcceptEvent(DialogEvent && onChange)61     void SetDialogAcceptEvent(DialogEvent&& onChange)
62     {
63         dialogAcceptEvent_ = std::move(onChange);
64     }
65 
FireDialogAcceptEvent(const std::string & info)66     void FireDialogAcceptEvent(const std::string& info) const
67     {
68         if (dialogAcceptEvent_) {
69             dialogAcceptEvent_(info);
70         }
71     }
72 
73 private:
74     DateChangeEvent changeEvent_;
75     DialogEvent dialogChangeEvent_;
76     DialogEvent dialogAcceptEvent_;
77 
78     ACE_DISALLOW_COPY_AND_MOVE(DatePickerEventHub);
79 };
80 
81 } // namespace OHOS::Ace::NG
82 
83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS__DATE_PICKER_DATE_PICKER_EVENT_HUB_H