1 /*
2 * Copyright (c) 2025 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 "ui/view/components/menu_view.h"
17
18 #include "core/components_ng/pattern/menu/menu_view.h"
19 #include "interfaces/inner_api/ace_kit/src/view/frame_node_impl.h"
20
21 namespace OHOS::Ace::Kit {
22
Create(std::vector<OptionParam> && params,MenuType type,const MenuParam & menuParam)23 RefPtr<FrameNode> MenuView::Create(std::vector<OptionParam>&& params, MenuType type, const MenuParam& menuParam)
24 {
25 std::vector<NG::OptionParam> aceParams;
26 for (const OptionParam& optionParam : params) {
27 NG::OptionParam aceOptionParam;
28 aceOptionParam.value = optionParam.value;
29 aceOptionParam.icon = optionParam.icon;
30 aceOptionParam.enabled = optionParam.enabled;
31 aceOptionParam.action = optionParam.action;
32 if (optionParam.symbol) {
33 aceOptionParam.symbol = [symbol = optionParam.symbol](WeakPtr<NG::FrameNode> weakAceFrameNode) {
34 RefPtr<NG::FrameNode> aceFrameNode = weakAceFrameNode.Upgrade();
35 CHECK_NULL_VOID(aceFrameNode);
36 symbol(reinterpret_cast<void*>(AceType::RawPtr(aceFrameNode)));
37 };
38 }
39 aceOptionParam.symbolUserDefinedIdealFontSize = optionParam.symbolUserDefinedIdealFontSize;
40 aceOptionParam.disableSystemClick = optionParam.disableSystemClick;
41 aceOptionParam.isPasteOption = optionParam.isPasteOption;
42 aceParams.push_back(aceOptionParam);
43 }
44
45 NG::MenuParam aceMenuParam;
46 aceMenuParam.isShowInSubWindow = menuParam.isShowInSubWindow;
47 aceMenuParam.placement = static_cast<Placement>(menuParam.placement);
48 RefPtr<NG::FrameNode> aceNode = OHOS::Ace::NG::MenuView::Create(std::move(aceParams), menuParam.targetId,
49 menuParam.targetTag, static_cast<NG::MenuType>(type), aceMenuParam);
50 RefPtr<FrameNode> node = AceType::MakeRefPtr<FrameNodeImpl>(aceNode);
51 aceNode->SetKitNode(node);
52 return node;
53 }
54 } // OHOS::Ace::Kit