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 #include "bridge/declarative_frontend/jsview/models/stepper_model_impl.h"
17
18 #include "bridge/declarative_frontend/jsview/js_view_abstract.h"
19 #include "bridge/declarative_frontend/view_stack_processor.h"
20 #include "core/components/box/box_component.h"
21 #include "core/components/navigator/navigator_component.h"
22 #include "frameworks/core/components/stepper/stepper_component.h"
23 #include "frameworks/core/components/stepper/stepper_theme.h"
24
25 namespace OHOS::Ace::Framework {
26
Create(uint32_t index)27 void StepperModelImpl::Create(uint32_t index)
28 {
29 std::list<RefPtr<OHOS::Ace::Component>> componentChildren;
30 auto stepperComponent = AceType::MakeRefPtr<OHOS::Ace::StepperComponent>(componentChildren);
31 stepperComponent->SetIndex(static_cast<int32_t>(index));
32 RefPtr<StepperTheme> theme = JSViewAbstract::GetTheme<StepperTheme>();
33 if (theme) {
34 stepperComponent->SetDefaultPaddingStart(theme->GetDefaultPaddingStart());
35 stepperComponent->SetDefaultPaddingEnd(theme->GetDefaultPaddingEnd());
36 stepperComponent->SetProgressColor(theme->GetProgressColor());
37 stepperComponent->SetProgressDiameter(theme->GetProgressDiameter());
38 stepperComponent->SetArrowWidth(theme->GetArrowWidth());
39 stepperComponent->SetArrowHeight(theme->GetArrowHeight());
40 stepperComponent->SetArrowColor(theme->GetArrowColor());
41 stepperComponent->SetDisabledColor(theme->GetDisabledColor());
42 stepperComponent->SetRadius(theme->GetRadius());
43 stepperComponent->SetButtonPressedColor(theme->GetButtonPressedColor());
44 stepperComponent->SetButtonPressedHeight(theme->GetButtonPressedHeight());
45 stepperComponent->SetControlHeight(theme->GetControlHeight());
46 stepperComponent->SetControlMargin(theme->GetControlMargin());
47 stepperComponent->SetControlPadding(theme->GetControlPadding());
48 stepperComponent->SetFocusColor(theme->GetFocusColor());
49 stepperComponent->SetFocusBorderWidth(theme->GetFocusBorderWidth());
50 stepperComponent->SetMouseHoverColor(theme->GetMouseHoverColor());
51 stepperComponent->SetDisabledAlpha(theme->GetDisabledAlpha());
52 }
53 ViewStackProcessor::GetInstance()->ClaimElementId(stepperComponent);
54 ViewStackProcessor::GetInstance()->Push(stepperComponent);
55 }
SetOnFinish(RoutineCallbackEvent && eventOnFinish)56 void StepperModelImpl::SetOnFinish(RoutineCallbackEvent&& eventOnFinish)
57 {
58 auto component = AceType::DynamicCast<StepperComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
59 if (!component) {
60 LOGW("Failed to get '%{public}s' in view stack", AceType::TypeName<StepperComponent>());
61 return;
62 }
63 component->SetOnFinish(std::move(eventOnFinish));
64 }
65
SetOnSkip(RoutineCallbackEvent && eventOnSkip)66 void StepperModelImpl::SetOnSkip(RoutineCallbackEvent&& eventOnSkip)
67 {
68 auto component = AceType::DynamicCast<StepperComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
69 if (!component) {
70 LOGW("Failed to get '%{public}s' in view stack", AceType::TypeName<StepperComponent>());
71 return;
72 }
73 component->SetOnSkip(std::move(eventOnSkip));
74 }
75
SetOnChange(IndexCallbackEvent && eventOnChange)76 void StepperModelImpl::SetOnChange(IndexCallbackEvent&& eventOnChange)
77 {
78 auto component = AceType::DynamicCast<StepperComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
79 if (!component) {
80 LOGW("Failed to get '%{public}s' in view stack", AceType::TypeName<StepperComponent>());
81 return;
82 }
83 component->SetOnChange(std::move(eventOnChange));
84 }
85
SetOnNext(IndexCallbackEvent && eventOnNext)86 void StepperModelImpl::SetOnNext(IndexCallbackEvent&& eventOnNext)
87 {
88 auto component = AceType::DynamicCast<StepperComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
89 if (!component) {
90 LOGW("Failed to get '%{public}s' in view stack", AceType::TypeName<StepperComponent>());
91 return;
92 }
93 component->SetOnNext(std::move(eventOnNext));
94 }
95
SetOnPrevious(IndexCallbackEvent && eventOnPrevious)96 void StepperModelImpl::SetOnPrevious(IndexCallbackEvent&& eventOnPrevious)
97 {
98 auto component = AceType::DynamicCast<StepperComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
99 if (!component) {
100 LOGW("Failed to get '%{public}s' in view stack", AceType::TypeName<StepperComponent>());
101 return;
102 }
103 component->SetOnPrevious(std::move(eventOnPrevious));
104 }
105
106 } // namespace OHOS::Ace::Framework