c7c70a0c29e818eb8d3da4af0003be29ae56aeea
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Visuals / VisualFactory.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// The VisualFactory is a singleton object that provides and shares visuals between views.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class VisualFactory : BaseHandle
28     {
29         /// <summary>
30         /// Instance of the VisualFactory singleton.
31         /// </summary>
32         private static VisualFactory instance;
33
34         internal VisualFactory(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
35         {
36         }
37
38         internal VisualFactory() : this(Interop.VisualFactory.NewVisualFactory(), true)
39         {
40             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41         }
42
43         /// <summary>
44         /// Retrieves the VisualFactory singleton.
45         /// </summary>
46         /// <since_tizen> 3 </since_tizen>
47         public static VisualFactory Instance
48         {
49             get
50             {
51                 if (!instance)
52                 {
53                     instance = new VisualFactory(Interop.VisualFactory.Get(), true);
54                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
55                 }
56
57                 return instance;
58             }
59         }
60
61         /// <summary>
62         /// Please do not use! this will be deprecated, please use VisualFactory.Instance instead.
63         /// </summary>
64         /// <since_tizen> 3 </since_tizen>
65         [Obsolete("Please do not use! This will be deprecated! Please use VisualFactory.Instance instead! " +
66             "Like: " +
67             "VisualFactory visualFactory = VisualFactory.Instance; " +
68             "visualFactory.CreateVisual(visualMap);")]
69         [EditorBrowsable(EditorBrowsableState.Never)]
70         public static VisualFactory Get()
71         {
72             return VisualFactory.Instance;
73         }
74
75         /// <summary>
76         /// Request the visual.
77         /// </summary>
78         /// <param name="propertyMap">The map contains the properties required by the visual. The content of the map determines the type of visual that will be returned.</param>
79         /// <returns>The handle to the created visual.</returns>
80         /// <since_tizen> 3 </since_tizen>
81         public VisualBase CreateVisual(PropertyMap propertyMap)
82         {
83             VisualBase ret = new VisualBase(Interop.VisualFactory.CreateVisual(SwigCPtr, PropertyMap.getCPtr(propertyMap)), true);
84             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85             return ret;
86         }
87     }
88 }