1 /*
2  * Copyright (c) 2023 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/alphabet_indexer_modifier.h"
16 
17 #include "core/components/common/properties/text_style.h"
18 #include "core/components_ng/base/frame_node.h"
19 #include "core/components_ng/pattern/indexer/indexer_model_ng.h"
20 #include "core/pipeline/base/element_register.h"
21 #include "frameworks/bridge/common/utils/utils.h"
22 #include "core/components/indexer/indexer_theme.h"
23 
24 namespace OHOS::Ace::NG {
25 namespace {
26 constexpr int FONT_SIZE_INDEX = 0;
27 constexpr int FONT_WEIGHT_INDEX = 1;
28 constexpr int FONT_FAMILY_INDEX = 2;
29 const std::vector<Ace::FontStyle> FONT_STYLES = { Ace::FontStyle::NORMAL, Ace::FontStyle::ITALIC };
30 constexpr bool DEFAULT_USINGPOPUP = false;
31 constexpr int32_t DEFAULT_SELECTED = 0;
32 constexpr Dimension DEFAULT_POPUPHORIZONTALSPACE = -1.0_vp;
33 constexpr int32_t DEFAULT_ALIGN_STYLE = static_cast<int32_t>(NG::AlignStyle::RIGHT);
34 constexpr double DEFAULT_ITEM_SIZE = 16.0;
35 constexpr double DEFAULT_POPUP_POSITION_X = 60.0;
36 constexpr double DEFAULT_POPUP_POSITION_Y = 48.0;
37 constexpr double POPUP_ITEM_DEFAULT_RADIUS = 24.0;
38 constexpr double ITEM_DEFAULT_RADIUS = 8.0;
39 constexpr double RADIUS_OFFSET = 4.0;
40 } // namespace
41 
SetPopupItemFont(ArkUINodeHandle node,ArkUI_Float32 size,int unit,const char * weight)42 void SetPopupItemFont(ArkUINodeHandle node, ArkUI_Float32 size, int unit, const char* weight)
43 {
44     auto* frameNode = reinterpret_cast<FrameNode*>(node);
45     CHECK_NULL_VOID(frameNode);
46     Dimension fontSize = Dimension(size, static_cast<OHOS::Ace::DimensionUnit>(unit));
47     IndexerModelNG::SetFontSize(frameNode, fontSize);
48     IndexerModelNG::SetFontWeight(frameNode, StringUtils::StringToFontWeight(std::string(weight), FontWeight::MEDIUM));
49 }
50 
ResetPopupItemFont(ArkUINodeHandle node)51 void ResetPopupItemFont(ArkUINodeHandle node)
52 {
53     auto* frameNode = reinterpret_cast<FrameNode*>(node);
54     CHECK_NULL_VOID(frameNode);
55     auto pipeline = PipelineBase::GetCurrentContext();
56     CHECK_NULL_VOID(pipeline);
57     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
58     CHECK_NULL_VOID(indexerTheme);
59     auto fontSize = indexerTheme->GetPopupTextSize();
60     IndexerModelNG::SetFontSize(frameNode, fontSize);
61     auto fontWeight = indexerTheme->GetPopupTextStyle().GetFontWeight();
62     IndexerModelNG::SetFontWeight(frameNode, fontWeight);
63 }
64 
SetSelectedFont(ArkUINodeHandle node,const char * fontInfo,int32_t style)65 void SetSelectedFont(ArkUINodeHandle node, const char* fontInfo, int32_t style)
66 {
67     auto* frameNode = reinterpret_cast<FrameNode*>(node);
68     CHECK_NULL_VOID(frameNode);
69     std::vector<std::string> res;
70     std::string fontValues = std::string(fontInfo);
71     StringUtils::StringSplitter(fontValues, '|', res);
72     std::optional<Dimension> fontSize =
73         StringUtils::StringToCalcDimension(res[FONT_SIZE_INDEX], false, DimensionUnit::FP);
74     std::optional<FontWeight> fontWeight = StringUtils::StringToFontWeight(res[FONT_WEIGHT_INDEX]);
75     std::optional<std::vector<std::string>> fontFamily = Framework::ConvertStrToFontFamilies(res[FONT_FAMILY_INDEX]);
76     std::optional<Ace::FontStyle> fontStyle = FONT_STYLES[0];
77     if (style >= 0 && style < static_cast<int32_t>(FONT_STYLES.size())) {
78         fontStyle = FONT_STYLES[style];
79     };
80     IndexerModelNG::SetSelectedFont(frameNode, fontSize, fontWeight, fontFamily, fontStyle);
81 }
82 
ResetSelectedFont(ArkUINodeHandle node)83 void ResetSelectedFont(ArkUINodeHandle node)
84 {
85     auto* frameNode = reinterpret_cast<FrameNode*>(node);
86     CHECK_NULL_VOID(frameNode);
87     auto pipeline = PipelineBase::GetCurrentContext();
88     CHECK_NULL_VOID(pipeline);
89     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
90     CHECK_NULL_VOID(indexerTheme);
91     TextStyle selectTextStyle = indexerTheme->GetSelectTextStyle();
92     std::optional<Dimension> fontSize = selectTextStyle.GetFontSize();
93     std::optional<FontWeight> fontWeight = selectTextStyle.GetFontWeight();
94     std::optional<std::vector<std::string>> fontFamily = selectTextStyle.GetFontFamilies();
95     std::optional<Ace::FontStyle> fontStyle = selectTextStyle.GetFontStyle();
96     IndexerModelNG::SetSelectedFont(frameNode, fontSize, fontWeight, fontFamily, fontStyle);
97 }
98 
SetPopupFont(ArkUINodeHandle node,const char * fontInfo,int32_t style)99 void SetPopupFont(ArkUINodeHandle node, const char* fontInfo, int32_t style)
100 {
101     auto* frameNode = reinterpret_cast<FrameNode*>(node);
102     CHECK_NULL_VOID(frameNode);
103     std::vector<std::string> res;
104     std::string fontValues = std::string(fontInfo);
105     StringUtils::StringSplitter(fontValues, '|', res);
106     std::optional<Dimension> fontSize =
107         StringUtils::StringToCalcDimension(res[FONT_SIZE_INDEX], false, DimensionUnit::FP);
108     std::optional<FontWeight> fontWeight = StringUtils::StringToFontWeight(res[FONT_WEIGHT_INDEX]);
109     std::optional<std::vector<std::string>> fontFamily = Framework::ConvertStrToFontFamilies(res[FONT_FAMILY_INDEX]);
110     std::optional<Ace::FontStyle> fontStyle = FONT_STYLES[0];
111     if (style >= 0 && style < static_cast<int32_t>(FONT_STYLES.size())) {
112         fontStyle = FONT_STYLES[style];
113     };
114     IndexerModelNG::SetPopupFont(frameNode, fontSize, fontWeight, fontFamily, fontStyle);
115 }
116 
ResetPopupFont(ArkUINodeHandle node)117 void ResetPopupFont(ArkUINodeHandle node)
118 {
119     auto* frameNode = reinterpret_cast<FrameNode*>(node);
120     CHECK_NULL_VOID(frameNode);
121     auto pipeline = PipelineBase::GetCurrentContext();
122     CHECK_NULL_VOID(pipeline);
123     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
124     CHECK_NULL_VOID(indexerTheme);
125     TextStyle popupTextStyle = indexerTheme->GetPopupTextStyle();
126     std::optional<Dimension> fontSize = popupTextStyle.GetFontSize();
127     std::optional<FontWeight> fontWeight = popupTextStyle.GetFontWeight();
128     std::optional<std::vector<std::string>> fontFamily = popupTextStyle.GetFontFamilies();
129     std::optional<Ace::FontStyle> fontStyle = popupTextStyle.GetFontStyle();
130     IndexerModelNG::SetPopupFont(frameNode, fontSize, fontWeight, fontFamily, fontStyle);
131 }
132 
SetAlphabetIndexerFont(ArkUINodeHandle node,const char * fontInfo,int32_t style)133 void SetAlphabetIndexerFont(ArkUINodeHandle node, const char* fontInfo, int32_t style)
134 {
135     auto* frameNode = reinterpret_cast<FrameNode*>(node);
136     CHECK_NULL_VOID(frameNode);
137     std::vector<std::string> res;
138     std::string fontValues = std::string(fontInfo);
139     StringUtils::StringSplitter(fontValues, '|', res);
140     std::optional<Dimension> fontSize =
141         StringUtils::StringToCalcDimension(res[FONT_SIZE_INDEX], false, DimensionUnit::FP);
142     std::optional<FontWeight> fontWeight = StringUtils::StringToFontWeight(res[FONT_WEIGHT_INDEX]);
143     std::optional<std::vector<std::string>> fontFamily = Framework::ConvertStrToFontFamilies(res[FONT_FAMILY_INDEX]);
144     std::optional<Ace::FontStyle> fontStyle = FONT_STYLES[0];
145     if (style >= 0 && style < static_cast<int32_t>(FONT_STYLES.size())) {
146         fontStyle = FONT_STYLES[style];
147     };
148     IndexerModelNG::SetFont(frameNode, fontSize, fontWeight, fontFamily, fontStyle);
149 }
150 
ResetAlphabetIndexerFont(ArkUINodeHandle node)151 void ResetAlphabetIndexerFont(ArkUINodeHandle node)
152 {
153     auto* frameNode = reinterpret_cast<FrameNode*>(node);
154     CHECK_NULL_VOID(frameNode);
155     auto pipeline = PipelineBase::GetCurrentContext();
156     CHECK_NULL_VOID(pipeline);
157     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
158     CHECK_NULL_VOID(indexerTheme);
159     TextStyle defaultTextStyle = indexerTheme->GetDefaultTextStyle();
160     std::optional<Dimension> fontSize = defaultTextStyle.GetFontSize();
161     std::optional<FontWeight> fontWeight = defaultTextStyle.GetFontWeight();
162     std::optional<std::vector<std::string>> fontFamily = defaultTextStyle.GetFontFamilies();
163     std::optional<Ace::FontStyle> fontStyle = defaultTextStyle.GetFontStyle();
164     IndexerModelNG::SetFont(frameNode, fontSize, fontWeight, fontFamily, fontStyle);
165 }
166 
SetPopupItemBackgroundColor(ArkUINodeHandle node,uint32_t color)167 void SetPopupItemBackgroundColor(ArkUINodeHandle node, uint32_t color)
168 {
169     auto* frameNode = reinterpret_cast<FrameNode*>(node);
170     CHECK_NULL_VOID(frameNode);
171     IndexerModelNG::SetPopupItemBackground(frameNode, Color(color));
172 }
173 
ResetPopupItemBackgroundColor(ArkUINodeHandle node)174 void ResetPopupItemBackgroundColor(ArkUINodeHandle node)
175 {
176     auto* frameNode = reinterpret_cast<FrameNode*>(node);
177     CHECK_NULL_VOID(frameNode);
178     auto pipeline = PipelineBase::GetCurrentContext();
179     CHECK_NULL_VOID(pipeline);
180     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
181     CHECK_NULL_VOID(indexerTheme);
182     Color color = Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)
183                         ? indexerTheme->GetPopupUnclickedBgAreaColor()
184                         : indexerTheme->GetPopupBackgroundColor();
185     IndexerModelNG::SetPopupItemBackground(frameNode, color);
186 }
187 
SetAlphabetIndexerColor(ArkUINodeHandle node,uint32_t color)188 void SetAlphabetIndexerColor(ArkUINodeHandle node, uint32_t color)
189 {
190     auto* frameNode = reinterpret_cast<FrameNode*>(node);
191     CHECK_NULL_VOID(frameNode);
192     IndexerModelNG::SetColor(frameNode, Color(color));
193 }
194 
ResetAlphabetIndexerColor(ArkUINodeHandle node)195 void ResetAlphabetIndexerColor(ArkUINodeHandle node)
196 {
197     auto* frameNode = reinterpret_cast<FrameNode*>(node);
198     CHECK_NULL_VOID(frameNode);
199     auto pipeline = PipelineBase::GetCurrentContext();
200     CHECK_NULL_VOID(pipeline);
201     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
202     CHECK_NULL_VOID(indexerTheme);
203     Color color = indexerTheme->GetDefaultTextColor();
204     IndexerModelNG::SetColor(frameNode, color);
205 }
206 
SetPopupColor(ArkUINodeHandle node,uint32_t color)207 void SetPopupColor(ArkUINodeHandle node, uint32_t color)
208 {
209     auto* frameNode = reinterpret_cast<FrameNode*>(node);
210     CHECK_NULL_VOID(frameNode);
211     IndexerModelNG::SetPopupColor(frameNode, Color(color));
212 }
213 
ResetPopupColor(ArkUINodeHandle node)214 void ResetPopupColor(ArkUINodeHandle node)
215 {
216     auto* frameNode = reinterpret_cast<FrameNode*>(node);
217     CHECK_NULL_VOID(frameNode);
218     auto pipeline = PipelineBase::GetCurrentContext();
219     CHECK_NULL_VOID(pipeline);
220     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
221     CHECK_NULL_VOID(indexerTheme);
222     Color color = indexerTheme->GetPopupTextColor();
223     IndexerModelNG::SetPopupColor(frameNode, color);
224 }
225 
SetAlphabetIndexerSelectedColor(ArkUINodeHandle node,uint32_t color)226 void SetAlphabetIndexerSelectedColor(ArkUINodeHandle node, uint32_t color)
227 {
228     auto* frameNode = reinterpret_cast<FrameNode*>(node);
229     CHECK_NULL_VOID(frameNode);
230     IndexerModelNG::SetSelectedColor(frameNode, Color(color));
231 }
232 
ResetAlphabetIndexerSelectedColor(ArkUINodeHandle node)233 void ResetAlphabetIndexerSelectedColor(ArkUINodeHandle node)
234 {
235     auto* frameNode = reinterpret_cast<FrameNode*>(node);
236     CHECK_NULL_VOID(frameNode);
237     auto pipeline = PipelineBase::GetCurrentContext();
238     CHECK_NULL_VOID(pipeline);
239     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
240     CHECK_NULL_VOID(indexerTheme);
241     Color color = indexerTheme->GetSelectedTextColor();
242     IndexerModelNG::SetSelectedColor(frameNode, color);
243 }
244 
SetPopupBackground(ArkUINodeHandle node,uint32_t color)245 void SetPopupBackground(ArkUINodeHandle node, uint32_t color)
246 {
247     auto* frameNode = reinterpret_cast<FrameNode*>(node);
248     CHECK_NULL_VOID(frameNode);
249     IndexerModelNG::SetPopupBackground(frameNode, Color(color));
250 }
251 
ResetPopupBackground(ArkUINodeHandle node)252 void ResetPopupBackground(ArkUINodeHandle node)
253 {
254     auto* frameNode = reinterpret_cast<FrameNode*>(node);
255     CHECK_NULL_VOID(frameNode);
256     auto pipeline = PipelineBase::GetCurrentContext();
257     CHECK_NULL_VOID(pipeline);
258     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
259     CHECK_NULL_VOID(indexerTheme);
260     Color color = indexerTheme->GetPopupBackgroundColor();
261     IndexerModelNG::SetPopupBackground(frameNode, color);
262 }
263 
SetSelectedBackgroundColor(ArkUINodeHandle node,uint32_t color)264 void SetSelectedBackgroundColor(ArkUINodeHandle node, uint32_t color)
265 {
266     auto* frameNode = reinterpret_cast<FrameNode*>(node);
267     CHECK_NULL_VOID(frameNode);
268     IndexerModelNG::SetSelectedBackgroundColor(frameNode, Color(color));
269 }
270 
ResetSelectedBackgroundColor(ArkUINodeHandle node)271 void ResetSelectedBackgroundColor(ArkUINodeHandle node)
272 {
273     auto* frameNode = reinterpret_cast<FrameNode*>(node);
274     CHECK_NULL_VOID(frameNode);
275     auto pipeline = PipelineBase::GetCurrentContext();
276     CHECK_NULL_VOID(pipeline);
277     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
278     CHECK_NULL_VOID(indexerTheme);
279     Color color = indexerTheme->GetSeclectedBackgroundColor();
280     IndexerModelNG::SetSelectedBackgroundColor(frameNode, color);
281 }
282 
SetPopupUnselectedColor(ArkUINodeHandle node,uint32_t color)283 void SetPopupUnselectedColor(ArkUINodeHandle node, uint32_t color)
284 {
285     auto* frameNode = reinterpret_cast<FrameNode*>(node);
286     CHECK_NULL_VOID(frameNode);
287     IndexerModelNG::SetPopupUnselectedColor(frameNode, Color(color));
288 }
289 
ResetPopupUnselectedColor(ArkUINodeHandle node)290 void ResetPopupUnselectedColor(ArkUINodeHandle node)
291 {
292     auto* frameNode = reinterpret_cast<FrameNode*>(node);
293     CHECK_NULL_VOID(frameNode);
294     auto pipeline = PipelineBase::GetCurrentContext();
295     CHECK_NULL_VOID(pipeline);
296     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
297     CHECK_NULL_VOID(indexerTheme);
298     Color color = indexerTheme->GetPopupUnselectedTextColor();
299     IndexerModelNG::SetPopupUnselectedColor(frameNode, color);
300 }
301 
SetAlignStyle(ArkUINodeHandle node,int32_t value)302 void SetAlignStyle(ArkUINodeHandle node, int32_t value)
303 {
304     auto* frameNode = reinterpret_cast<FrameNode*>(node);
305     CHECK_NULL_VOID(frameNode);
306     IndexerModelNG::SetAlignStyle(frameNode, value);
307 }
308 
ResetAlignStyle(ArkUINodeHandle node)309 void ResetAlignStyle(ArkUINodeHandle node)
310 {
311     auto* frameNode = reinterpret_cast<FrameNode*>(node);
312     CHECK_NULL_VOID(frameNode);
313     IndexerModelNG::SetAlignStyle(frameNode, DEFAULT_ALIGN_STYLE);
314 }
315 
SetPopupHorizontalSpace(ArkUINodeHandle node,ArkUI_Float32 value,int unit)316 void SetPopupHorizontalSpace(ArkUINodeHandle node, ArkUI_Float32 value, int unit)
317 {
318     auto* frameNode = reinterpret_cast<FrameNode*>(node);
319     CHECK_NULL_VOID(frameNode);
320     IndexerModelNG::SetPopupHorizontalSpace(frameNode, Dimension(value, static_cast<OHOS::Ace::DimensionUnit>(unit)));
321 }
322 
ResetPopupHorizontalSpace(ArkUINodeHandle node)323 void ResetPopupHorizontalSpace(ArkUINodeHandle node)
324 {
325     auto* frameNode = reinterpret_cast<FrameNode*>(node);
326     CHECK_NULL_VOID(frameNode);
327     IndexerModelNG::SetPopupHorizontalSpace(frameNode, DEFAULT_POPUPHORIZONTALSPACE);
328 }
329 
SetUsingPopup(ArkUINodeHandle node,ArkUI_Bool value)330 void SetUsingPopup(ArkUINodeHandle node, ArkUI_Bool value)
331 {
332     auto* frameNode = reinterpret_cast<FrameNode*>(node);
333     CHECK_NULL_VOID(frameNode);
334     IndexerModelNG::SetUsingPopup(frameNode, value);
335 }
336 
ResetUsingPopup(ArkUINodeHandle node)337 void ResetUsingPopup(ArkUINodeHandle node)
338 {
339     auto* frameNode = reinterpret_cast<FrameNode*>(node);
340     CHECK_NULL_VOID(frameNode);
341     IndexerModelNG::SetUsingPopup(frameNode, DEFAULT_USINGPOPUP);
342 }
343 
SetAlphabetIndexerSelected(ArkUINodeHandle node,int32_t value)344 void SetAlphabetIndexerSelected(ArkUINodeHandle node, int32_t value)
345 {
346     auto* frameNode = reinterpret_cast<FrameNode*>(node);
347     CHECK_NULL_VOID(frameNode);
348     IndexerModelNG::SetSelected(frameNode, value);
349 }
350 
ResetAlphabetIndexerSelected(ArkUINodeHandle node)351 void ResetAlphabetIndexerSelected(ArkUINodeHandle node)
352 {
353     auto* frameNode = reinterpret_cast<FrameNode*>(node);
354     CHECK_NULL_VOID(frameNode);
355     IndexerModelNG::SetSelected(frameNode, DEFAULT_SELECTED);
356 }
357 
SetPopupSelectedColor(ArkUINodeHandle node,uint32_t color)358 void SetPopupSelectedColor(ArkUINodeHandle node, uint32_t color)
359 {
360     auto* frameNode = reinterpret_cast<FrameNode*>(node);
361     CHECK_NULL_VOID(frameNode);
362     IndexerModelNG::SetPopupSelectedColor(frameNode, Color(color));
363 }
ResetPopupSelectedColor(ArkUINodeHandle node)364 void ResetPopupSelectedColor(ArkUINodeHandle node)
365 {
366     auto* frameNode = reinterpret_cast<FrameNode*>(node);
367     CHECK_NULL_VOID(frameNode);
368     auto pipeline = PipelineBase::GetCurrentContext();
369     CHECK_NULL_VOID(pipeline);
370     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
371     CHECK_NULL_VOID(indexerTheme);
372     Color color = indexerTheme->GetPopupSelectedTextColor();
373     IndexerModelNG::SetPopupSelectedColor(frameNode, color);
374 }
375 
SetItemSize(ArkUINodeHandle node,ArkUI_Float32 value,int unit)376 void SetItemSize(ArkUINodeHandle node, ArkUI_Float32 value, int unit)
377 {
378     auto* frameNode = reinterpret_cast<FrameNode*>(node);
379     CHECK_NULL_VOID(frameNode);
380     IndexerModelNG::SetItemSize(frameNode, Dimension(value, static_cast<OHOS::Ace::DimensionUnit>(unit)));
381 }
382 
ResetItemSize(ArkUINodeHandle node)383 void ResetItemSize(ArkUINodeHandle node)
384 {
385     auto* frameNode = reinterpret_cast<FrameNode*>(node);
386     CHECK_NULL_VOID(frameNode);
387     IndexerModelNG::SetItemSize(frameNode, Dimension(DEFAULT_ITEM_SIZE, DimensionUnit::VP));
388 }
389 
SetPopupPosition(ArkUINodeHandle node,ArkUI_Float32 xValue,int xUnit,ArkUI_Float32 yValue,int yUnit)390 void SetPopupPosition(ArkUINodeHandle node, ArkUI_Float32 xValue, int xUnit, ArkUI_Float32 yValue, int yUnit)
391 {
392     auto* frameNode = reinterpret_cast<FrameNode*>(node);
393     CHECK_NULL_VOID(frameNode);
394     IndexerModelNG::SetPopupPositionX(frameNode, Dimension(xValue, static_cast<OHOS::Ace::DimensionUnit>(xUnit)));
395     IndexerModelNG::SetPopupPositionY(frameNode, Dimension(yValue, static_cast<OHOS::Ace::DimensionUnit>(yUnit)));
396 }
397 
ResetPopupPosition(ArkUINodeHandle node)398 void ResetPopupPosition(ArkUINodeHandle node)
399 {
400     auto* frameNode = reinterpret_cast<FrameNode*>(node);
401     CHECK_NULL_VOID(frameNode);
402     IndexerModelNG::SetPopupPositionX(frameNode, Dimension(DEFAULT_POPUP_POSITION_X, DimensionUnit::VP));
403     IndexerModelNG::SetPopupPositionY(frameNode, Dimension(DEFAULT_POPUP_POSITION_Y, DimensionUnit::VP));
404 }
405 
SetPopupItemBorderRadius(ArkUINodeHandle node,ArkUI_Float32 radiusValue,ArkUI_Int32 radiusUnit,ArkUI_Float32 popupValue,ArkUI_Int32 popupUnit)406 void SetPopupItemBorderRadius(ArkUINodeHandle node, ArkUI_Float32 radiusValue, ArkUI_Int32 radiusUnit,
407     ArkUI_Float32 popupValue, ArkUI_Int32 popupUnit)
408 {
409     auto* frameNode = reinterpret_cast<FrameNode*>(node);
410     CHECK_NULL_VOID(frameNode);
411     IndexerModelNG::SetPopupItemBorderRadius(
412         frameNode, Dimension(radiusValue, static_cast<OHOS::Ace::DimensionUnit>(radiusUnit)));
413     IndexerModelNG::SetPopupBorderRadius(
414         frameNode, Dimension(popupValue, static_cast<OHOS::Ace::DimensionUnit>(popupUnit)));
415 }
ResetPopupItemBorderRadius(ArkUINodeHandle node)416 void ResetPopupItemBorderRadius(ArkUINodeHandle node)
417 {
418     auto* frameNode = reinterpret_cast<FrameNode*>(node);
419     CHECK_NULL_VOID(frameNode);
420     auto radius = Dimension(ZERO_RADIUS, DimensionUnit::VP);
421     auto popupRadius = Dimension(ZERO_RADIUS, DimensionUnit::VP);
422     radius.SetValue(POPUP_ITEM_DEFAULT_RADIUS);
423     radius.SetUnit(DimensionUnit::VP);
424     popupRadius.SetValue(radius.Value() + RADIUS_OFFSET);
425     popupRadius.SetUnit(DimensionUnit::VP);
426     IndexerModelNG::SetPopupItemBorderRadius(frameNode, radius);
427     IndexerModelNG::SetPopupBorderRadius(frameNode, popupRadius);
428 }
SetItemBorderRadius(ArkUINodeHandle node,ArkUI_Float32 radiusValue,ArkUI_Int32 radiusUnit,ArkUI_Float32 indexerValue,ArkUI_Int32 indexerUnit)429 void SetItemBorderRadius(ArkUINodeHandle node, ArkUI_Float32 radiusValue, ArkUI_Int32 radiusUnit,
430     ArkUI_Float32 indexerValue, ArkUI_Int32 indexerUnit)
431 {
432     auto* frameNode = reinterpret_cast<FrameNode*>(node);
433     CHECK_NULL_VOID(frameNode);
434     IndexerModelNG::SetItemBorderRadius(
435         frameNode, Dimension(radiusValue, static_cast<OHOS::Ace::DimensionUnit>(radiusUnit)));
436     IndexerModelNG::SetIndexerBorderRadius(
437         frameNode, Dimension(indexerValue, static_cast<OHOS::Ace::DimensionUnit>(indexerUnit)));
438 }
ResetItemBorderRadius(ArkUINodeHandle node)439 void ResetItemBorderRadius(ArkUINodeHandle node)
440 {
441     auto* frameNode = reinterpret_cast<FrameNode*>(node);
442     CHECK_NULL_VOID(frameNode);
443     auto radius = Dimension(ZERO_RADIUS, DimensionUnit::VP);
444     auto indexerRadius = Dimension(ZERO_RADIUS, DimensionUnit::VP);
445     radius.SetValue(ITEM_DEFAULT_RADIUS);
446     radius.SetUnit(DimensionUnit::VP);
447     indexerRadius.SetValue(radius.Value() + RADIUS_OFFSET);
448     indexerRadius.SetUnit(DimensionUnit::VP);
449     IndexerModelNG::SetIndexerBorderRadius(frameNode, indexerRadius);
450     IndexerModelNG::SetItemBorderRadius(frameNode, radius);
451 }
SetPopupBackgroundBlurStyle(ArkUINodeHandle node,ArkUI_Uint32 value)452 void SetPopupBackgroundBlurStyle(ArkUINodeHandle node, ArkUI_Uint32 value)
453 {
454     auto* frameNode = reinterpret_cast<FrameNode*>(node);
455     CHECK_NULL_VOID(frameNode);
456     BlurStyleOption styleOption;
457     if (value >= static_cast<ArkUI_Uint32>(BlurStyle::NO_MATERIAL) &&
458         value <= static_cast<ArkUI_Uint32>(BlurStyle::COMPONENT_ULTRA_THICK)) {
459         styleOption.blurStyle = static_cast<BlurStyle>(value);
460     }
461     IndexerModelNG::SetPopupBackgroundBlurStyle(frameNode, styleOption);
462 }
ResetPopupBackgroundBlurStyle(ArkUINodeHandle node)463 void ResetPopupBackgroundBlurStyle(ArkUINodeHandle node)
464 {
465     auto* frameNode = reinterpret_cast<FrameNode*>(node);
466     CHECK_NULL_VOID(frameNode);
467     BlurStyleOption styleOption;
468     styleOption.blurStyle = BlurStyle::COMPONENT_REGULAR;
469     IndexerModelNG::SetPopupBackgroundBlurStyle(frameNode, styleOption);
470 }
SetPopupTitleBackground(ArkUINodeHandle node,ArkUI_Uint32 color)471 void SetPopupTitleBackground(ArkUINodeHandle node, ArkUI_Uint32 color)
472 {
473     auto* frameNode = reinterpret_cast<FrameNode*>(node);
474     CHECK_NULL_VOID(frameNode);
475     IndexerModelNG::SetPopupTitleBackground(frameNode, Color(color));
476 }
ResetPopupTitleBackground(ArkUINodeHandle node)477 void ResetPopupTitleBackground(ArkUINodeHandle node)
478 {
479     auto* frameNode = reinterpret_cast<FrameNode*>(node);
480     CHECK_NULL_VOID(frameNode);
481     auto pipeline = PipelineBase::GetCurrentContext();
482     CHECK_NULL_VOID(pipeline);
483     auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
484     CHECK_NULL_VOID(indexerTheme);
485     Color color = indexerTheme->GetPopupTitleBackground();
486     IndexerModelNG::SetPopupTitleBackground(frameNode, color);
487 }
488 
SetAdaptiveWidth(ArkUINodeHandle node)489 void SetAdaptiveWidth(ArkUINodeHandle node)
490 {
491     auto* frameNode = reinterpret_cast<FrameNode*>(node);
492     CHECK_NULL_VOID(frameNode);
493     IndexerModelNG::SetAdaptiveWidth(frameNode, true);
494 }
495 
ResetAdaptiveWidth(ArkUINodeHandle node)496 void ResetAdaptiveWidth(ArkUINodeHandle node)
497 {
498     auto* frameNode = reinterpret_cast<FrameNode*>(node);
499     CHECK_NULL_VOID(frameNode);
500     IndexerModelNG::SetAdaptiveWidth(frameNode, false);
501 }
502 
SetArrayValue(ArkUINodeHandle node,ArkUI_CharPtr * value,ArkUI_Uint32 length)503 void SetArrayValue(ArkUINodeHandle node, ArkUI_CharPtr* value, ArkUI_Uint32 length)
504 {
505     auto* frameNode = reinterpret_cast<FrameNode*>(node);
506     CHECK_NULL_VOID(frameNode);
507     CHECK_NULL_VOID(value);
508     std::vector<std::string> valueVector;
509     for (uint32_t i = 0; i < length; i++) {
510         valueVector.emplace_back(value[i]);
511     }
512     IndexerModelNG::SetArrayValue(frameNode, valueVector);
513 }
514 
ResetArrayValue(ArkUINodeHandle node)515 void ResetArrayValue(ArkUINodeHandle node)
516 {
517     auto* frameNode = reinterpret_cast<FrameNode*>(node);
518     CHECK_NULL_VOID(frameNode);
519     std::vector<std::string> valueVector;
520     IndexerModelNG::SetArrayValue(frameNode, valueVector);
521 }
522 
SetAutoCollapse(ArkUINodeHandle node,ArkUI_Bool value)523 void SetAutoCollapse(ArkUINodeHandle node, ArkUI_Bool value)
524 {
525     auto* frameNode = reinterpret_cast<FrameNode*>(node);
526     CHECK_NULL_VOID(frameNode);
527     IndexerModelNG::SetAutoCollapse(frameNode, value);
528 }
529 
ResetAutoCollapse(ArkUINodeHandle node)530 void ResetAutoCollapse(ArkUINodeHandle node)
531 {
532     auto* frameNode = reinterpret_cast<FrameNode*>(node);
533     CHECK_NULL_VOID(frameNode);
534     IndexerModelNG::SetAutoCollapse(frameNode, true);
535 }
536 
SetEnableHapticFeedback(ArkUINodeHandle node,ArkUI_Bool value)537 void SetEnableHapticFeedback(ArkUINodeHandle node, ArkUI_Bool value)
538 {
539     auto* frameNode = reinterpret_cast<FrameNode*>(node);
540     CHECK_NULL_VOID(frameNode);
541     IndexerModelNG::SetEnableHapticFeedback(frameNode, value);
542 }
543 
ResetEnableHapticFeedback(ArkUINodeHandle node)544 void ResetEnableHapticFeedback(ArkUINodeHandle node)
545 {
546     auto* frameNode = reinterpret_cast<FrameNode*>(node);
547     CHECK_NULL_VOID(frameNode);
548     IndexerModelNG::SetEnableHapticFeedback(frameNode, true);
549 }
550 
551 namespace NodeModifier {
GetAlphabetIndexerModifier()552 const ArkUIAlphabetIndexerModifier* GetAlphabetIndexerModifier()
553 {
554     static const ArkUIAlphabetIndexerModifier modifier = { SetPopupItemFont, ResetPopupItemFont, SetSelectedFont,
555         ResetSelectedFont, SetPopupFont, ResetPopupFont, SetAlphabetIndexerFont, ResetAlphabetIndexerFont,
556         SetPopupItemBackgroundColor, ResetPopupItemBackgroundColor, SetAlphabetIndexerColor, ResetAlphabetIndexerColor,
557         SetPopupColor, ResetPopupColor, SetAlphabetIndexerSelectedColor, ResetAlphabetIndexerSelectedColor,
558         SetPopupBackground, ResetPopupBackground, SetSelectedBackgroundColor, ResetSelectedBackgroundColor,
559         SetPopupUnselectedColor, ResetPopupUnselectedColor, SetAlignStyle, ResetAlignStyle, SetUsingPopup,
560         ResetUsingPopup, SetAlphabetIndexerSelected, ResetAlphabetIndexerSelected, SetPopupHorizontalSpace,
561         ResetPopupHorizontalSpace, SetPopupSelectedColor, ResetPopupSelectedColor, SetItemSize, ResetItemSize,
562         SetPopupPosition, ResetPopupPosition, SetPopupItemBorderRadius, ResetPopupItemBorderRadius, SetItemBorderRadius,
563         ResetItemBorderRadius, SetPopupBackgroundBlurStyle, ResetPopupBackgroundBlurStyle, SetPopupTitleBackground,
564         ResetPopupTitleBackground, SetAdaptiveWidth, ResetAdaptiveWidth, SetArrayValue, ResetArrayValue,
565         SetAutoCollapse, ResetAutoCollapse, SetEnableHapticFeedback, ResetEnableHapticFeedback };
566 
567     return &modifier;
568 }
569 
GetCJUIAlphabetIndexerModifier()570 const CJUIAlphabetIndexerModifier* GetCJUIAlphabetIndexerModifier()
571 {
572     static const CJUIAlphabetIndexerModifier modifier = { SetPopupItemFont, ResetPopupItemFont, SetSelectedFont,
573         ResetSelectedFont, SetPopupFont, ResetPopupFont, SetAlphabetIndexerFont, ResetAlphabetIndexerFont,
574         SetPopupItemBackgroundColor, ResetPopupItemBackgroundColor, SetAlphabetIndexerColor, ResetAlphabetIndexerColor,
575         SetPopupColor, ResetPopupColor, SetAlphabetIndexerSelectedColor, ResetAlphabetIndexerSelectedColor,
576         SetPopupBackground, ResetPopupBackground, SetSelectedBackgroundColor, ResetSelectedBackgroundColor,
577         SetPopupUnselectedColor, ResetPopupUnselectedColor, SetAlignStyle, ResetAlignStyle, SetUsingPopup,
578         ResetUsingPopup, SetAlphabetIndexerSelected, ResetAlphabetIndexerSelected, SetPopupHorizontalSpace,
579         ResetPopupHorizontalSpace, SetPopupSelectedColor, ResetPopupSelectedColor, SetItemSize, ResetItemSize,
580         SetPopupPosition, ResetPopupPosition, SetPopupItemBorderRadius, ResetPopupItemBorderRadius, SetItemBorderRadius,
581         ResetItemBorderRadius, SetPopupBackgroundBlurStyle, ResetPopupBackgroundBlurStyle, SetPopupTitleBackground,
582         ResetPopupTitleBackground, SetAdaptiveWidth, ResetAdaptiveWidth, SetAutoCollapse, ResetAutoCollapse,
583         SetEnableHapticFeedback, ResetEnableHapticFeedback, SetArrayValue, ResetArrayValue };
584 
585     return &modifier;
586 }
587 
SetOnIndexerSelected(ArkUINodeHandle node,void * extraParam)588 void SetOnIndexerSelected(ArkUINodeHandle node, void* extraParam)
589 {
590     auto* frameNode = reinterpret_cast<FrameNode*>(node);
591     CHECK_NULL_VOID(frameNode);
592     auto onEvent = [node, extraParam](const int32_t selected) {
593         ArkUINodeEvent event;
594         event.kind = COMPONENT_ASYNC_EVENT;
595         event.extraParam = reinterpret_cast<intptr_t>(extraParam);
596         event.componentAsyncEvent.subKind = ON_ALPHABET_INDEXER_SELECTED;
597         event.componentAsyncEvent.data[0].i32 = selected;
598         SendArkUIAsyncEvent(&event);
599     };
600     IndexerModelNG::SetOnSelected(frameNode, std::move(onEvent));
601 }
602 
SetOnIndexerRequestPopupData(ArkUINodeHandle node,void * extraParam)603 void SetOnIndexerRequestPopupData(ArkUINodeHandle node, void* extraParam)
604 {
605     auto* frameNode = reinterpret_cast<FrameNode*>(node);
606     CHECK_NULL_VOID(frameNode);
607     auto onEvent = [node, extraParam](const int32_t selected) {
608         ArkUINodeEvent event;
609         event.kind = COMPONENT_ASYNC_EVENT;
610         event.extraParam = reinterpret_cast<intptr_t>(extraParam);
611         event.componentAsyncEvent.subKind = ON_ALPHABET_INDEXER_REQUEST_POPUP_DATA;
612         event.componentAsyncEvent.data[0].i32 = selected;
613         SendArkUIAsyncEvent(&event);
614         char** valueArray = reinterpret_cast<char**>(event.textArrayEvent.nativeStringArrayPtr);
615         ArkUI_Int32 length = event.textArrayEvent.length;
616         std::vector<std::string> valueVector;
617         if (length != 0 && valueArray != nullptr) {
618             for (ArkUI_Int32 i = 0; i < length; i++) {
619                 valueVector.emplace_back(valueArray[i]);
620                 free(valueArray[i]);
621             }
622             free(valueArray);
623         }
624         return valueVector;
625     };
626     IndexerModelNG::SetOnRequestPopupData(frameNode, std::move(onEvent));
627 }
628 
SetOnIndexerPopupSelected(ArkUINodeHandle node,void * extraParam)629 void SetOnIndexerPopupSelected(ArkUINodeHandle node, void* extraParam)
630 {
631     auto* frameNode = reinterpret_cast<FrameNode*>(node);
632     CHECK_NULL_VOID(frameNode);
633     auto onEvent = [node, extraParam](const int32_t selected) {
634         ArkUINodeEvent event;
635         event.kind = COMPONENT_ASYNC_EVENT;
636         event.extraParam = reinterpret_cast<intptr_t>(extraParam);
637         event.componentAsyncEvent.subKind = ON_ALPHABET_INDEXER_POPUP_SELECTED;
638         event.componentAsyncEvent.data[0].i32 = selected;
639         SendArkUIAsyncEvent(&event);
640     };
641     IndexerModelNG::SetOnPopupSelected(frameNode, std::move(onEvent));
642 }
643 
SetIndexerChangeEvent(ArkUINodeHandle node,void * extraParam)644 void SetIndexerChangeEvent(ArkUINodeHandle node, void* extraParam)
645 {
646     auto* frameNode = reinterpret_cast<FrameNode*>(node);
647     CHECK_NULL_VOID(frameNode);
648     auto onEvent = [node, extraParam](const int32_t selected) {
649         ArkUINodeEvent event;
650         event.kind = COMPONENT_ASYNC_EVENT;
651         event.extraParam = reinterpret_cast<intptr_t>(extraParam);
652         event.componentAsyncEvent.subKind = ON_ALPHABET_INDEXER_CHANGE_EVENT;
653         event.componentAsyncEvent.data[0].i32 = selected;
654         SendArkUIAsyncEvent(&event);
655     };
656     IndexerModelNG::SetChangeEvent(frameNode, std::move(onEvent));
657 }
658 
SetIndexerCreatChangeEvent(ArkUINodeHandle node,void * extraParam)659 void SetIndexerCreatChangeEvent(ArkUINodeHandle node, void* extraParam)
660 {
661     auto* frameNode = reinterpret_cast<FrameNode*>(node);
662     CHECK_NULL_VOID(frameNode);
663     auto onEvent = [node, extraParam](const int32_t selected) {
664         ArkUINodeEvent event;
665         event.kind = COMPONENT_ASYNC_EVENT;
666         event.extraParam = reinterpret_cast<intptr_t>(extraParam);
667         event.componentAsyncEvent.subKind = ON_ALPHABET_INDEXER_CREAT_CHANGE_EVENT;
668         event.componentAsyncEvent.data[0].i32 = selected;
669         SendArkUIAsyncEvent(&event);
670     };
671     IndexerModelNG::SetCreatChangeEvent(frameNode, std::move(onEvent));
672 }
673 }
674 } // namespace OHOS::Ace::NG