• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_TEXT_PICKER_TEXT_PICKER_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_MODEL_NG_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "core/components/picker/picker_base_component.h"
21 #include "core/components_ng/pattern/text_picker/textpicker_event_hub.h"
22 #include "core/components_ng/pattern/text_picker/textpicker_model.h"
23 
24 namespace OHOS::Ace::NG {
25 class ACE_EXPORT TextPickerModelNG : public TextPickerModel {
26 public:
27     void Create(RefPtr<PickerTheme> pickerTheme, uint32_t columnKind) override;
28     void SetSelected(uint32_t value) override;
29     void SetRange(const std::vector<NG::RangeContent>& value) override;
30     void SetValue(const std::string& value) override;
31     void SetDefaultPickerItemHeight(const Dimension& value) override;
32     void SetCanLoop(const bool value) override;
33     void SetDefaultAttributes(const RefPtr<PickerTheme>& pickerTheme) override;
34     void SetDisappearTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value) override;
35     void SetNormalTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value) override;
36     void SetSelectedTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value) override;
37     void MultiInit(const RefPtr<PickerTheme> pickerTheme) override;
38     void SetColumns(const std::vector<NG::TextCascadePickerOptions>& options) override;
39     void SetIsCascade(bool isCascade) override;
40     void SetOnCascadeChange(TextCascadeChangeEvent&& onChange) override;
41     void SetValues(const std::vector<std::string>& values) override;
42     void SetSelecteds(const std::vector<uint32_t>& values) override;
43     void SetBackgroundColor(const Color& color) override;
44     bool IsSingle() override;
45     bool GetSingleRange(std::vector<NG::RangeContent>& rangeValue) override;
IsCascade()46     bool IsCascade() override
47     {
48         return isCascade_;
49     }
50 
SetMaxCount(uint32_t maxCount)51     void SetMaxCount(uint32_t maxCount) override
52     {
53         maxCount_ = maxCount;
54     }
55 
GetMaxCount()56     uint32_t GetMaxCount() override
57     {
58         return maxCount_;
59     }
60 
SetSingleRange(bool isSingleRange)61     void SetSingleRange(bool isSingleRange) override
62     {
63         isSingleRange_ = isSingleRange;
64     }
65 
GetSingleRange()66     bool GetSingleRange() override
67     {
68         return isSingleRange_;
69     }
70 
71     void SetHasSelectAttr(bool value) override;
72     bool GetMultiOptions(std::vector<NG::TextCascadePickerOptions>& options) override;
73     void SetOnValueChangeEvent(TextCascadeValueChangeEvent&& onChange) override;
74     void SetOnSelectedChangeEvent(TextCascadeSelectedChangeEvent&& onChange) override;
75 
76     static void SetCanLoop(FrameNode* frameNode, const bool value);
77     static void SetSelected(FrameNode* frameNode, uint32_t value);
78     static void SetSelecteds(FrameNode* frameNode, const std::vector<uint32_t>& values);
79     static void SetHasSelectAttr(FrameNode* frameNode, bool value);
80     static void SetNormalTextStyle(
81         FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value);
82     static void SetSelectedTextStyle(
83         FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value);
84     static void SetDisappearTextStyle(
85         FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value);
86     static void SetDefaultPickerItemHeight(FrameNode* frameNode, const Dimension& value);
87     static void SetBackgroundColor(FrameNode* frameNode, const Color& color);
88 
89 private:
90     static RefPtr<FrameNode> CreateStackNode();
91     static RefPtr<FrameNode> CreateButtonNode();
92     RefPtr<FrameNode> CreateColumnNode(uint32_t columnKind, uint32_t showCount);
93     void SetUnCascadeColumns(const std::vector<NG::TextCascadePickerOptions>& options);
94     void SetCascadeColumns(const std::vector<NG::TextCascadePickerOptions>& options);
95 
96     uint32_t showCount_ = 0;
97     std::vector<uint32_t> kinds_;
98     bool isCascade_ = false;
99     std::vector<NG::RangeContent> rangeValue_;
100     std::vector<NG::TextCascadePickerOptions> options_;
101     uint32_t maxCount_ = 0;
102     bool isSingleRange_ = true;
103 };
104 
105 class ACE_EXPORT TextPickerDialogModelNG : public TextPickerDialogModel {
106 public:
107     RefPtr<AceType> CreateObject() override;
108     void SetTextPickerDialogShow(RefPtr<AceType>& PickerText, NG::TextPickerSettingData& settingData,
109         std::function<void()>&& onCancel, std::function<void(const std::string&)>&& onAccept,
110         std::function<void(const std::string&)>&& onChange, TextPickerDialog& textPickerDialog) override;
111 };
112 } // namespace OHOS::Ace::NG
113 
114 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_PICKER_TEXT_PICKER_MODEL_NG_H
115