• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/components/menu/menu_component.h"
17 
18 #include "core/components/menu/menu_element.h"
19 
20 namespace OHOS::Ace {
21 
22 
CreateElement()23 RefPtr<Element> MenuComponent::CreateElement()
24 {
25     return AceType::MakeRefPtr<MenuElement>(GetId());
26 }
27 
GetPopup() const28 const RefPtr<SelectPopupComponent>& MenuComponent::GetPopup() const
29 {
30     return popup_;
31 }
32 
RemoveOption(const RefPtr<OptionComponent> & option)33 void MenuComponent::RemoveOption(const RefPtr<OptionComponent>& option)
34 {
35     if (!popup_ || !option) {
36         LOGE("popup or option is null.");
37         return;
38     }
39     option->SetSelectable(false);
40     popup_->RemoveSelectOption(option);
41 }
42 
AppendOption(const RefPtr<OptionComponent> & option)43 void MenuComponent::AppendOption(const RefPtr<OptionComponent>& option)
44 {
45     if (!popup_ || !option) {
46         LOGE("popup or option is null.");
47         return;
48     }
49     option->SetSelectable(false);
50     popup_->AppendSelectOption(option);
51 }
52 
InsertOption(const RefPtr<OptionComponent> & option,uint32_t index)53 void MenuComponent::InsertOption(const RefPtr<OptionComponent>& option, uint32_t index)
54 {
55     if (!popup_ || !option) {
56         return;
57     }
58     option->SetSelectable(false);
59     popup_->InsertSelectOption(option, index);
60 }
61 
ClearOptions()62 void MenuComponent::ClearOptions()
63 {
64     if (!popup_) {
65         LOGE("popup is null.");
66         return;
67     }
68     popup_->ClearAllOptions();
69 }
70 
GetOptionCount() const71 std::size_t MenuComponent::GetOptionCount() const
72 {
73     if (!popup_) {
74         LOGE("popup is null.");
75         return 0;
76     }
77     return popup_->GetSelectOptionCount();
78 }
79 
GetOption(std::size_t index) const80 RefPtr<OptionComponent> MenuComponent::GetOption(std::size_t index) const
81 {
82     if (!popup_) {
83         LOGE("popup is null.");
84         return nullptr;
85     }
86     return popup_->GetSelectOption(index);
87 }
88 
GetOptions() const89 std::vector<RefPtr<OptionComponent>> MenuComponent::GetOptions() const
90 {
91     if (!popup_) {
92         LOGE("popup is null.");
93         return std::vector<RefPtr<OptionComponent>>();
94     }
95     return popup_->GetSelectOptions();
96 }
97 
GetTitle() const98 std::string MenuComponent::GetTitle() const
99 {
100     if (!popup_) {
101         LOGE("popup is null.");
102         return "";
103     }
104     return popup_->GetTitle();
105 }
106 
SetTitle(const std::string & value)107 void MenuComponent::SetTitle(const std::string& value)
108 {
109     if (!popup_) {
110         LOGE("popup is null.");
111         return;
112     }
113     popup_->SetTitle(value);
114 }
115 
GetTitleStyle() const116 const TextStyle& MenuComponent::GetTitleStyle() const
117 {
118     if (!popup_) {
119         LOGE("popup is null.");
120         return textStyle_;
121     }
122     return popup_->GetTitleStyle();
123 }
124 
SetTitleStyle(const TextStyle & value)125 void MenuComponent::SetTitleStyle(const TextStyle& value)
126 {
127     if (!popup_) {
128         LOGE("popup is null.");
129         return;
130     }
131     return popup_->SetTitleStyle(value);
132 }
133 
134 } // namespace OHOS::Ace
135