1 /* 2 * Copyright (c) 2021-2022 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_POPUP_POPUP_COMPONENT_V2_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POPUP_POPUP_COMPONENT_V2_H 18 19 #include "core/components/box/box_component.h" 20 #include "core/components/popup/popup_component.h" 21 #include "core/components/popup/popup_theme.h" 22 23 namespace OHOS::Ace { 24 25 class ACE_EXPORT PopupComponentV2 : public PopupComponent { 26 DECLARE_ACE_TYPE(PopupComponentV2, PopupComponent); 27 28 public: PopupComponentV2(const ComposeId & id,const std::string & name,const RefPtr<Component> & child)29 PopupComponentV2(const ComposeId& id, const std::string& name, const RefPtr<Component>& child) 30 : PopupComponent(id, name, child) {} PopupComponentV2(const ComposeId & id,const std::string & name)31 PopupComponentV2(const ComposeId& id, const std::string& name) : PopupComponent(id, name) {} 32 ~PopupComponentV2() override = default; 33 34 RefPtr<Element> CreateElement() override; 35 SetMessage(const std::string & message)36 void SetMessage(const std::string& message) 37 { 38 message_ = message; 39 } 40 GetMessage()41 std::string GetMessage() const 42 { 43 return message_; 44 } 45 GetOnStateChange()46 const EventMarker& GetOnStateChange() const 47 { 48 return onStateChange_; 49 } 50 SetOnStateChange(const EventMarker & onStateChange)51 void SetOnStateChange(const EventMarker& onStateChange) 52 { 53 onStateChange_ = onStateChange; 54 } 55 GetChangeEvent()56 const EventMarker& GetChangeEvent() const 57 { 58 return changeEvent_; 59 } 60 SetChangeEvent(const EventMarker & changeEvent)61 void SetChangeEvent(const EventMarker& changeEvent) 62 { 63 changeEvent_ = changeEvent; 64 } 65 66 void Initialization( 67 const RefPtr<ThemeManager>& themeManager, const WeakPtr<PipelineContext>& context); 68 SetPrimaryButtonProperties(const ButtonProperties & properties)69 void SetPrimaryButtonProperties(const ButtonProperties& properties) 70 { 71 primaryButtonProperties_ = properties; 72 } 73 GetPrimaryButtonValue()74 std::string GetPrimaryButtonValue() const 75 { 76 return primaryButtonProperties_.value; 77 } 78 SetSecondaryButtonProperties(const ButtonProperties & properties)79 void SetSecondaryButtonProperties(const ButtonProperties& properties) 80 { 81 secondaryButtonProperties_ = properties; 82 } 83 GetSecondaryButtonValue()84 std::string GetSecondaryButtonValue() const 85 { 86 return secondaryButtonProperties_.value; 87 } 88 SetPlacementOnTop(bool placementOnTop)89 void SetPlacementOnTop(bool placementOnTop) 90 { 91 placementOnTop_ = placementOnTop; 92 } 93 GetPlacementOnTop()94 bool GetPlacementOnTop() const 95 { 96 return placementOnTop_; 97 } 98 SetCustomComponent(const RefPtr<Component> & customComponent)99 void SetCustomComponent(const RefPtr<Component>& customComponent) 100 { 101 customComponent_ = customComponent; 102 } 103 GetCustomComponent()104 const RefPtr<Component>& GetCustomComponent() const 105 { 106 return customComponent_; 107 } 108 109 private: 110 const RefPtr<Component> CreateChild(); 111 const RefPtr<Component> CreateMessage(); 112 const RefPtr<Component> CreateButtons(); 113 const RefPtr<Component> CreateButton(const ButtonProperties& buttonProperties); 114 const RefPtr<Component> SetPadding(const RefPtr<Component>& component, const Edge& edge); 115 const RefPtr<BoxComponent> CreateBox(const RefPtr<PopupTheme>& popupTheme); 116 117 std::string message_; 118 bool hasInitialization_ = false; 119 bool placementOnTop_ = false; 120 EventMarker onStateChange_; 121 EventMarker changeEvent_; 122 RefPtr<PopupParam> popupParam_; 123 RefPtr<PopupController> popupController_; 124 RefPtr<ThemeManager> themeManager_; 125 RefPtr<Component> customComponent_; 126 WeakPtr<PipelineContext> context_; 127 128 ButtonProperties primaryButtonProperties_; // first button. 129 ButtonProperties secondaryButtonProperties_; // second button. 130 }; 131 132 } // namespace OHOS::Ace 133 134 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POPUP_POPUP_COMPONENT_V2_H 135