1 /*
2  * Copyright (c) 2021 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_CALENDAR_CALENDAR_CONTROLLER_V2_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_CALENDAR_CONTROLLER_V2_H
18 
19 #include "core/components/calendar/calendar_component.h"
20 
21 namespace OHOS::Ace {
22 
23 class ACE_EXPORT CalendarControllerV2 : public AceType {
24     DECLARE_ACE_TYPE(CalendarControllerV2, AceType);
25 
26 public:
27     CalendarControllerV2() = default;
28     ~CalendarControllerV2() override = default;
29 
SetCalendarController(const RefPtr<CalendarController> & controller)30     void SetCalendarController(const RefPtr<CalendarController>& controller)
31     {
32         controller_ = controller;
33     }
34 
BackToToday()35     void BackToToday()
36     {
37         if (controller_) {
38             auto today = controller_->GetToday();
39             controller_->SetFirstSetToday(true);
40             controller_->SetHasMoved(true);
41             controller_->GoTo(today.month.year, today.month.month, today.day);
42         }
43     }
44 
GoTo(int32_t year,int32_t month,int32_t day)45     void GoTo(int32_t year, int32_t month, int32_t day)
46     {
47         if (controller_) {
48             CalendarDay calendarDay;
49             calendarDay.month.month = month;
50             calendarDay.month.year = year;
51             controller_->SetCrossMonth(true);
52             controller_->SetCrossMonthDay(calendarDay);
53             controller_->SetHasMoved(true);
54             controller_->GoTo(year, month, day);
55         }
56     }
57 
58 private:
59     RefPtr<CalendarController> controller_;
60 };
61 
62 } // namespace OHOS::Ace
63 
64 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CALENDAR_CALENDAR_CONTROLLER_V2_H
65