1 /*
2 * Copyright (c) 2024 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 #include "core/interfaces/native/node/node_folder_stack_modifier.h"
16
17 #include "core/components_ng/pattern/folder_stack/folder_stack_model_ng.h"
18
19 namespace OHOS::Ace::NG {
20 namespace {
SetEnableAnimation(ArkUINodeHandle node,ArkUI_Bool value)21 void SetEnableAnimation(ArkUINodeHandle node, ArkUI_Bool value)
22 {
23 auto* frameNode = reinterpret_cast<FrameNode*>(node);
24 CHECK_NULL_VOID(frameNode);
25 FolderStackModelNG::SetEnableAnimation(frameNode, static_cast<bool>(value));
26 }
27
ResetEnableAnimation(ArkUINodeHandle node)28 void ResetEnableAnimation(ArkUINodeHandle node)
29 {
30 auto* frameNode = reinterpret_cast<FrameNode*>(node);
31 CHECK_NULL_VOID(frameNode);
32 FolderStackModelNG::SetEnableAnimation(frameNode, true);
33 }
34
SetAutoHalfFold(ArkUINodeHandle node,ArkUI_Bool value)35 void SetAutoHalfFold(ArkUINodeHandle node, ArkUI_Bool value)
36 {
37 auto* frameNode = reinterpret_cast<FrameNode*>(node);
38 CHECK_NULL_VOID(frameNode);
39 FolderStackModelNG::SetAutoHalfFold(frameNode, static_cast<bool>(value));
40 }
41
ResetAutoHalfFold(ArkUINodeHandle node)42 void ResetAutoHalfFold(ArkUINodeHandle node)
43 {
44 auto* frameNode = reinterpret_cast<FrameNode*>(node);
45 CHECK_NULL_VOID(frameNode);
46 FolderStackModelNG::SetAutoHalfFold(frameNode, true);
47 }
48
SetOnFolderStateChange(ArkUINodeHandle node,void * callback)49 void SetOnFolderStateChange(ArkUINodeHandle node, void* callback)
50 {
51 auto* frameNode = reinterpret_cast<FrameNode*>(node);
52 CHECK_NULL_VOID(frameNode);
53 if (callback) {
54 auto onFolderStateChange = reinterpret_cast<std::function<void(const NG::FolderEventInfo&)>*>(callback);
55 FolderStackModelNG::SetOnFolderStateChange(frameNode, std::move(*onFolderStateChange));
56 } else {
57 FolderStackModelNG::SetOnFolderStateChange(frameNode, nullptr);
58 }
59 }
60
ResetOnFolderStateChange(ArkUINodeHandle node)61 void ResetOnFolderStateChange(ArkUINodeHandle node)
62 {
63 auto* frameNode = reinterpret_cast<FrameNode*>(node);
64 CHECK_NULL_VOID(frameNode);
65 FolderStackModelNG::SetOnFolderStateChange(frameNode, nullptr);
66 }
67
SetOnHoverStatusChange(ArkUINodeHandle node,void * callback)68 void SetOnHoverStatusChange(ArkUINodeHandle node, void* callback)
69 {
70 auto* frameNode = reinterpret_cast<FrameNode*>(node);
71 CHECK_NULL_VOID(frameNode);
72 if (callback) {
73 auto onHoverStatusChange = reinterpret_cast<std::function<void(const NG::FolderEventInfo&)>*>(callback);
74 FolderStackModelNG::SetOnHoverStatusChange(frameNode, std::move(*onHoverStatusChange));
75 } else {
76 FolderStackModelNG::SetOnHoverStatusChange(frameNode, nullptr);
77 }
78 }
79
ResetOnHoverStatusChange(ArkUINodeHandle node)80 void ResetOnHoverStatusChange(ArkUINodeHandle node)
81 {
82 auto* frameNode = reinterpret_cast<FrameNode*>(node);
83 CHECK_NULL_VOID(frameNode);
84 FolderStackModelNG::SetOnHoverStatusChange(frameNode, nullptr);
85 }
86 } // namespace
87 namespace NodeModifier {
GetFolderStackModifier()88 const ArkUIFolderStackModifier* GetFolderStackModifier()
89 {
90 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
91 static const ArkUIFolderStackModifier modifier = {
92 .setEnableAnimation = SetEnableAnimation,
93 .resetEnableAnimation = ResetEnableAnimation,
94 .setAutoHalfFold = SetAutoHalfFold,
95 .resetAutoHalfFold = ResetAutoHalfFold,
96 .setOnFolderStateChange = SetOnFolderStateChange,
97 .resetOnFolderStateChange = ResetOnFolderStateChange,
98 .setOnHoverStatusChange = SetOnHoverStatusChange,
99 .resetOnHoverStatusChange = ResetOnHoverStatusChange,
100 };
101 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
102 return &modifier;
103 }
104
GetCJUIFolderStackModifier()105 const CJUIFolderStackModifier* GetCJUIFolderStackModifier()
106 {
107 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
108 static const CJUIFolderStackModifier modifier = {
109 .setEnableAnimation = SetEnableAnimation,
110 .resetEnableAnimation = ResetEnableAnimation,
111 .setAutoHalfFold = SetAutoHalfFold,
112 .resetAutoHalfFold = ResetAutoHalfFold,
113 };
114 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
115 return &modifier;
116 }
117 }
118 }
119