1 /* 2 * Copyright (c) 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 #ifndef OHOS_ACE_FRAMEWORK_CJ_CUSTOMDIALOG_CONTROLLER_FFI_H 16 #define OHOS_ACE_FRAMEWORK_CJ_CUSTOMDIALOG_CONTROLLER_FFI_H 17 18 #include <cinttypes> 19 #include <optional> 20 #include <string> 21 22 #include "bridge/cj_frontend/cppview/native_view.h" 23 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_common_ffi.h" 24 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_macro.h" 25 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_view_abstract_ffi.h" 26 #include "core/components/dialog/dialog_component.h" 27 #include "core/components_ng/pattern/dialog/custom_dialog_controller_model.h" 28 #include "ffi_remote_data.h" 29 #include "cj_animate_param_ffi.h" 30 31 extern "C" { 32 struct NativeCustomDialogControllerOptions { 33 void(*cancel)(); 34 bool autoCancel; 35 int32_t alignment; 36 NativeOffset offset; 37 bool customStyle; 38 NativeOptionInt32 gridCount; 39 uint32_t maskColor; 40 NativeRectangle maskRect; 41 NativeOptionAnimateParam openAnimation; 42 NativeOptionAnimateParam closeAnimation; 43 bool showInSubWindow; 44 NativeOptionUInt32 backgroundColor; 45 NativeLength cornerRadius; 46 }; 47 48 CJ_EXPORT int64_t FfiOHOSAceFrameworkCustomDialogControllerCtor(NativeCustomDialogControllerOptions options); 49 CJ_EXPORT void FfiOHOSAceFrameworkCustomDialogControllerBindView(int64_t controllerId, int64_t nativeViewId); 50 CJ_EXPORT void FfiOHOSAceFrameworkCustomDialogControllerSetBuilder(int64_t controllerId, void(*builder)()); 51 CJ_EXPORT void FfiOHOSAceFrameworkCustomDialogControllerOpen(int64_t id); 52 CJ_EXPORT void FfiOHOSAceFrameworkCustomDialogControllerClose(int64_t id); 53 } 54 55 namespace OHOS::Ace::Framework { 56 57 class ACE_EXPORT NativeCustomDialogController : public OHOS::FFI::FFIData, public virtual AceType { 58 DECLARE_ACE_TYPE(NativeCustomDialogController, AceType) 59 public: 60 NativeCustomDialogController(NativeCustomDialogControllerOptions options); 61 SetView(NativeView * view)62 void SetView(NativeView* view) 63 { 64 ownerView_ = view; 65 }; 66 67 void OpenDialog(); 68 69 void CloseDialog(); 70 SetBuilder(std::function<void ()> builderFunc)71 void SetBuilder(std::function<void()> builderFunc) 72 { 73 builderFunction_ = builderFunc; 74 }; 75 76 private: 77 78 NativeView* ownerView_ = nullptr; 79 bool isShown_ = false; 80 bool pending_ = false; 81 // NG 82 std::vector<WeakPtr<AceType>> dialogs_; 83 84 DialogProperties dialogProperties_; 85 std::function<void()> builderFunction_; 86 std::function<void()> cancelFunction_; 87 RefPtr<AceType> customDialog_; 88 RefPtr<AceType> dialogComponent_; 89 RefPtr<AceType> refself_; 90 std::list<DialogOperation> dialogOperation_; 91 }; 92 } // namespace OHOS::Ace::Framework 93 94 #endif // OHOS_ACE_FRAMEWORK_CJ_CUSTOMDIALOG__CONTROLLER_FFI_H