1 /*
2  * Copyright (c) 2022-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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GRID_GRID_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GRID_GRID_MODEL_NG_H
18 
19 #include <string>
20 
21 #include "base/geometry/dimension.h"
22 #include "base/utils/macros.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components/common/properties/scroll_bar.h"
25 #include "core/components_ng/pattern/grid/grid_event_hub.h"
26 #include "core/components_ng/pattern/grid/grid_model.h"
27 
28 namespace OHOS::Ace::NG {
29 
30 class ACE_EXPORT GridModelNG : public OHOS::Ace::GridModel {
31 public:
32     void Create(
33         const RefPtr<ScrollControllerBase>& positionController, const RefPtr<ScrollProxy>& scrollProxy) override;
34     void Pop() override;
35     void SetLayoutOptions(GridLayoutOptions options) override;
36     void SetColumnsTemplate(const std::string& value) override;
37     void SetRowsTemplate(const std::string& value) override;
38     void SetColumnsGap(const Dimension& value) override;
39     void SetRowsGap(const Dimension& value) override;
40     void SetGridHeight(const Dimension& value) override;
41     void SetScrollBarMode(DisplayMode value) override;
42     void SetScrollBarColor(const std::string& value) override;
43     void SetScrollBarWidth(const std::string& value) override;
44     void SetCachedCount(int32_t value, bool show = false) override;
45     void SetIsRTL(TextDirection direction) override;
46     void SetLayoutDirection(FlexDirection value) override;
47     void SetMaxCount(int32_t value) override;
48     void SetMinCount(int32_t value) override;
49     void SetCellLength(int32_t value) override;
50     void SetEditable(bool value) override;
51     void SetMultiSelectable(bool value) override;
52     void SetSupportAnimation(bool value) override;
53     void SetSupportDragAnimation(bool value) override;
54     void SetEdgeEffect(EdgeEffect edgeEffect, bool alwaysEnabled) override;
55     void SetNestedScroll(const NestedScrollOptions& nestedOpt) override;
56     void SetScrollEnabled(bool scrollEnabled) override;
57     void SetFriction(double friction) override;
58     void SetAlignItems(GridItemAlignment itemAlign) override;
59     void SetOnScrollToIndex(ScrollToIndexFunc&& value) override;
60     void SetOnScrollBarUpdate(ScrollBarUpdateFunc&& value) override;
61     void SetOnItemDragStart(std::function<void(const ItemDragInfo&, int32_t)>&& value) override;
62     void SetOnItemDragEnter(ItemDragEnterFunc&& value) override;
63     void SetOnItemDragMove(ItemDragMoveFunc&& value) override;
64     void SetOnItemDragLeave(ItemDragLeaveFunc&& value) override;
65     void SetOnItemDrop(ItemDropFunc&& value) override;
66     void SetOnScroll(OnScrollEvent&& onScroll) override;
67     void SetOnScrollFrameBegin(OnScrollFrameBeginEvent&& onScrollFrameBegin) override;
68     void SetOnScrollStart(OnScrollStartEvent&& onScrollStart) override;
69     void SetOnScrollStop(OnScrollStopEvent&& onScrollStop) override;
70     void SetOnScrollIndex(ScrollIndexFunc&& onScrollIndex) override;
71     void SetOnReachStart(OnReachEvent&& onReachStart) override;
72     void SetOnReachEnd(OnReachEvent&& onReachEnd) override;
73     RefPtr<ScrollControllerBase> CreatePositionController() override;
74     RefPtr<ScrollProxy> CreateScrollBarProxy() override;
75 
76     DisplayMode GetDisplayMode() const override;
77 
78     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId);
79     static RefPtr<ScrollControllerBase> GetOrCreateController(FrameNode* frameNode);
80     static void SetOnScrollIndex(FrameNode* frameNode, ScrollIndexFunc&& onScrollIndex);
81     static void SetColumnsTemplate(FrameNode* frameNode, const std::string& columnsTemplate);
82     static void SetRowsTemplate(FrameNode* frameNode, const std::string& rowsTemplate);
83     static void SetColumnsGap(FrameNode* frameNode, const Dimension& columnsGap);
84     static void SetRowsGap(FrameNode* frameNode, const Dimension& rowsGap);
85     static void SetScrollBarMode(FrameNode* frameNode, DisplayMode scrollBarMode);
86     static void SetScrollBarWidth(FrameNode* frameNode, const Dimension& scrollBarWidth);
87     static void SetScrollBarColor(FrameNode* frameNode, const Color& scrollBarColor);
88     static void SetCachedCount(FrameNode* frameNode, int32_t cachedCount);
89     static void SetShowCached(FrameNode* frameNode, bool show);
90     static void SetLayoutDirection(FrameNode* frameNode, FlexDirection layoutDirection);
91     static void SetMaxCount(FrameNode* frameNode, int32_t maxCount);
92     static void SetMinCount(FrameNode* frameNode, int32_t minCount);
93     static void SetCellLength(FrameNode* frameNode, int32_t cellLength);
94     static void SetEditable(FrameNode* frameNode, bool editMode);
95     static void SetMultiSelectable(FrameNode* frameNode, bool multiSelectable);
96     static void SetSupportAnimation(FrameNode* frameNode, bool supportAnimation);
97 
98     static void SetEdgeEffect(FrameNode* frameNode, EdgeEffect edgeEffect, bool alwaysEnabled);
99     static void SetNestedScroll(FrameNode* frameNode, const NestedScrollOptions& nestedOpt);
100     static void SetScrollEnabled(FrameNode* frameNode, bool scrollEnabled);
101     static void SetFriction(FrameNode* frameNode, double friction);
102     static void SetAlignItems(FrameNode* frameNode, GridItemAlignment itemAlign);
103     static std::string GetColumnsTemplate(FrameNode* frameNode);
104     static std::string GetRowsTemplate(FrameNode* frameNode);
105     static float GetColumnsGap(FrameNode* frameNode);
106     static float GetRowsGap(FrameNode* frameNode);
107     static int32_t GetCachedCount(FrameNode* frameNode);
108     static bool GetShowCached(FrameNode* frameNode);
109     static void InitScroller(FrameNode* frameNode, const RefPtr<ScrollControllerBase>& positionController,
110         const RefPtr<ScrollProxy>& scrollProxy);
111     static void SetLayoutOptions(FrameNode* frameNode, GridLayoutOptions& options);
112 
113 private:
114     void AddDragFrameNodeToManager() const;
115 };
116 
117 } // namespace OHOS::Ace::NG
118 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GRID_GRID_MODEL_NG_H
119