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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_ITEM_GROUP_MENU_ITEM_GROUP_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_ITEM_GROUP_MENU_ITEM_GROUP_PATTERN_H
18 
19 #include "base/memory/referenced.h"
20 #include "base/utils/noncopyable.h"
21 #include "base/utils/utils.h"
22 #include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_accessibility_property.h"
23 #include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_layout_algorithm.h"
24 #include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_paint_method.h"
25 #include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_paint_property.h"
26 #include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_view.h"
27 #include "core/components_ng/pattern/pattern.h"
28 
29 namespace OHOS::Ace::NG {
30 class ACE_EXPORT MenuItemGroupPattern : public Pattern {
31     DECLARE_ACE_TYPE(MenuItemGroupPattern, Pattern);
32 
33 public:
34     explicit MenuItemGroupPattern() = default;
35     ~MenuItemGroupPattern() override = default;
36 
IsAtomicNode()37     bool IsAtomicNode() const override
38     {
39         return false;
40     }
41 
CreateAccessibilityProperty()42     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
43     {
44         return MakeRefPtr<MenuItemGroupAccessibilityProperty>();
45     }
46 
CreateLayoutAlgorithm()47     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
48     {
49         return MakeRefPtr<MenuItemGroupLayoutAlgorithm>(headerIndex_, footerIndex_, itemStartIndex_);
50     }
51 
CreateNodePaintMethod()52     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
53     {
54         return MakeRefPtr<MenuItemGroupPaintMethod>();
55     }
56 
CreatePaintProperty()57     RefPtr<PaintProperty> CreatePaintProperty() override
58     {
59         return MakeRefPtr<MenuItemGroupPaintProperty>();
60     }
61 
62     void AddHeader(const RefPtr<NG::UINode>& header);
63     void AddFooter(const RefPtr<NG::UINode>& footer);
64 
AddHeaderContent(const RefPtr<NG::FrameNode> & headerContent)65     void AddHeaderContent(const RefPtr<NG::FrameNode>& headerContent)
66     {
67         headerContent_ = headerContent;
68     }
69 
AddFooterContent(const RefPtr<NG::FrameNode> & footerContent)70     void AddFooterContent(const RefPtr<NG::FrameNode>& footerContent)
71     {
72         footerContent_ = footerContent;
73     }
74 
75     RefPtr<FrameNode> GetMenu();
76 
77     std::string GetHeaderContent();
78 
HasSelectIcon()79     bool HasSelectIcon() const
80     {
81         return hasSelectIcon_;
82     }
83 
HasStartIcon()84     bool HasStartIcon() const
85     {
86         return hasStartIcon_;
87     }
88 
89     // Travel children to update items icon info
90     void UpdateMenuItemIconInfo();
91     void OnExtItemPressed(bool press, bool beforeGroup);
92     void OnIntItemPressed(int32_t index, bool press);
93     void ModifyDivider();
94 
95 protected:
96     void OnMountToParentDone() override;
97 
98 private:
99     void ModifyFontSize();
100 
101     int32_t headerIndex_ = -1;
102     int32_t footerIndex_ = -1;
103     int32_t itemStartIndex_ = 0;
104 
105     // True: one of menu items in group has select icon;
106     // False: none of menu items in group has select icon.
107     bool hasSelectIcon_ = false;
108     // True: one of menu items in group has start icon;
109     // False: none of menu items in group has start icon.
110     bool hasStartIcon_ = false;
111 
112     RefPtr<FrameNode> headerContent_;
113     RefPtr<FrameNode> footerContent_;
114 
115     ACE_DISALLOW_COPY_AND_MOVE(MenuItemGroupPattern);
116 };
117 } // namespace OHOS::Ace::NG
118 
119 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_ITEM_GROUP_MENU_ITEM_GROUP_PATTERN_H
120