Release 4.0.0-preview1-00286
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.AttachPanel / Tizen.Applications.AttachPanel / AttachPanel.cs
1 using ElmSharp;
2 using System;
3
4 namespace Tizen.Applications.AttachPanel
5 {
6     /// <summary>
7     /// Represents immutable class for attach panel.
8     /// </summary>
9     public partial class AttachPanel
10     {
11         /// <summary>
12         /// Represents immutable class for attach panel.
13         /// </summary>
14         /// <since_tizen> 3 </since_tizen>
15         /// <param name="conformant">The caller's conformant</param>
16         /// <exception cref="OutOfMemoryException">Thrown when an attempt to allocate memory fails.</exception>
17         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is already exist or the <paramref name="conformant"/> is not a conformant object</exception>
18         public AttachPanel(EvasObject conformant)
19         {
20             if (conformant == IntPtr.Zero)
21             {
22                 throw new ArgumentNullException("Use the value property, not null value");
23             }
24
25             IntPtr candidateAttachPanel = new IntPtr();
26             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.CreateAttachPanel(conformant, ref candidateAttachPanel);
27             CheckException(err);
28
29             Tizen.Log.Debug("AttachPanelSharp", "Success to create an AttachPanel Instance");
30             isCreationSucceed = true;
31             _attachPanel = candidateAttachPanel;
32
33             if (_eventEventHandler == null)
34             {
35                 StateEventListenStart();
36             }
37
38             if (_resultEventHandler == null)
39             {
40                 ResultEventListenStart();
41             }
42         }
43
44         /// <summary>
45         /// Represents immutable class for attach panel.
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         /// <param name="conformant">The caller's conformant</param>
49         /// <exception cref="OutOfMemoryException">Thrown when an attempt to allocate memory fails.</exception>
50         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is already exist or the <paramref name="conformant"/> is not a conformant object</exception>
51         public AttachPanel(Conformant conformant)
52         {
53             if (conformant == IntPtr.Zero)
54             {
55                 throw new ArgumentNullException("Use the value property, not null value");
56             }
57
58             IntPtr candidateAttachPanel = new IntPtr();
59             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.CreateAttachPanel(conformant, ref candidateAttachPanel);
60             CheckException(err);
61
62             Tizen.Log.Debug("AttachPanelSharp", "Success to create an AttachPanel Instance");
63             isCreationSucceed = true;
64             _attachPanel = candidateAttachPanel;
65
66             if (_eventEventHandler == null)
67             {
68                 StateEventListenStart();
69             }
70
71             if (_resultEventHandler == null)
72             {
73                 ResultEventListenStart();
74             }
75         }
76
77         /// <summary>
78         /// A destructor which deallocates attach panel resources.
79         /// </summary>
80         ~AttachPanel()
81         {
82             if (isCreationSucceed &&
83                 _attachPanel != IntPtr.Zero)
84             {
85                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.DestroyAttachPanel(_attachPanel);
86                 CheckException(err);
87                 _attachPanel = IntPtr.Zero;
88             }
89         }
90
91         /// <summary>
92         /// Gets the state of the AttachPanel.
93         /// </summary>
94         /// <value>The AttachPanel window state</value>
95         public StateType State
96         {
97             get
98             {
99                 int interopState;
100                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetState(_attachPanel, out interopState);
101                 CheckException(err);
102                 StateType state = (StateType)Enum.ToObject(typeof(StateType), interopState);
103                 return state;
104             }
105         }
106
107         /// <summary>
108         /// Gets the value that indicates whether the AttachPanel is visible.
109         /// </summary>
110         /// <value>visible value of AttachPanel state</value>
111         public bool Visible
112         {
113             get
114             {
115                 int visible;
116                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetVisibility(_attachPanel, out visible);
117                 CheckException(err);
118                 return (visible == 1);
119             }
120         }
121
122         /// <summary>
123         /// Add a content category in the AttachPanel.
124         /// </summary>
125         /// <param name="category">The ContentCategory to be added in the AttachPanel</param>
126         /// <param name="extraData">The AttachPanel send some information using Bundle</param>
127         /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
128         /// <privilege>http://tizen.org/privilege/camera</privilege>
129         /// <privilege>http://tizen.org/privilege/recorder</privilege>
130         /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
131         /// <feature>http://tizen.org/feature/camera</feature>
132         /// <feature>http://tizen.org/feature/microphone</feature>
133         /// <remarks>
134         /// The caller app has to check the return value of this function.
135         /// Content categories will be shown as the sequence of using AddCategory
136         /// Some contents need time to load it all.
137         /// So, it is needed to use this before the mainloop of Show
138         /// Privileges,
139         /// http://tizen.org/privilege/mediastorage, for using Image or Camera
140         /// http://tizen.org/privilege/camera, for using Camera or TakePicture
141         /// http://tizen.org/privilege/recorder, for using Voice
142         /// http://tizen.org/privilege/appmanager.launch, for adding content categories on the More tab
143         /// http://tizen.org/feature/camera, for using Camera or TakePicture
144         /// http://tizen.org/feature/microphone, for using Voice
145         /// Deliver more information to the callee with a bundle if you need.
146         /// http://tizen.org/appcontrol/data/total_count
147         /// http://tizen.org/appcontrol/data/total_size
148         /// </remarks>
149         /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="category"/> is not a valid category</exception>
150         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have privilege to access this method</exception>
151         /// <exception cref="NotSupportedException">Thrown when the device does not supported the <paramref name="category"/> feature </exception>
152         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is not created yet or already destroyed</exception>
153         public void AddCategory(ContentCategory category, Bundle extraData)
154         {
155             IntPtr bundle = IntPtr.Zero;
156             if (extraData != null)
157             {
158                 bundle = extraData.SafeBundleHandle.DangerousGetHandle();
159             }
160
161             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.AddCategory(_attachPanel, (int)category, bundle);
162             CheckException(err);
163         }
164
165         /// <summary>
166         /// Removes the ContentCategory from the AttachPanel
167         /// </summary>
168         /// <param name="category">The ContentCategory adding in the AttachPanel</param>
169         ///  <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="category"/> is not a valid category</exception>
170         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is not created yet or already destroyed</exception>
171         public void RemoveCategory(ContentCategory category)
172         {
173             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.RemoveCategory(_attachPanel, (int)category);
174             CheckException(err);
175         }
176
177         /// <summary>
178         /// Sets extraData to send to the ContentCategory using a Bundle
179         /// </summary>
180         /// <param name="category">The ContentCategory that some information to be set in the AttachPanel.</param>
181         /// <param name="extraData">The AttachPanel send some information using Bundle</param>
182         /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="category"/> is not a valid category</exception>
183         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
184         /// <exception cref="OutOfMemoryException">Thrown when an attempt to allocate memory fails.</exception>
185         public void SetExtraData(ContentCategory category, Bundle extraData)
186         {
187             if (extraData == null)
188             {
189                 CheckException(Interop.AttachPanel.ErrorCode.InvalidParameter);
190             }
191
192             IntPtr bundle = IntPtr.Zero;
193             if (extraData != null)
194             {
195                 bundle = extraData.SafeBundleHandle.DangerousGetHandle();
196             }
197
198             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.SetExtraData(_attachPanel, (int)category, bundle);
199             CheckException(err);
200         }
201
202         /// <summary>
203         /// Shows the attach panel with animations
204         /// </summary>
205         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
206         public void Show()
207         {
208             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Show(_attachPanel);
209             CheckException(err);
210         }
211
212         /// <summary>
213         /// Shows the attach panel and selects whether or not to animate
214         /// </summary>
215         /// <param name="animation">A flag which turn on or turn off the animation while attach panel showing.</param>
216         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
217         public void Show(bool animation)
218         {
219             if (animation)
220             {
221                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Show(_attachPanel);
222                 CheckException(err);
223             }
224             else
225             {
226                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.ShowWithoutAnimation(_attachPanel);
227                 CheckException(err);
228             }
229         }
230
231         /// <summary>
232         /// Hides the attach panel with animations
233         /// </summary>
234         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
235         public void Hide()
236         {
237             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Hide(_attachPanel);
238             CheckException(err);
239         }
240
241         /// <summary>
242         /// Hides the attach panel and selects whether or not to animate
243         /// </summary>
244         /// <param name="animation">A flag which turn on or turn off the animation while attach panel hiding.</param>
245         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
246         public void Hide(bool animation)
247         {
248             if (animation)
249             {
250                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Hide(_attachPanel);
251                 CheckException(err);
252             }
253             else
254             {
255                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.HideWithoutAnimation(_attachPanel);
256                 CheckException(err);
257             }
258         }
259
260         /// <summary>
261         /// Occurs when reserved events are published from the panel-side.
262         /// </summary>
263         public event EventHandler<StateEventArgs> EventChanged
264         {
265             add
266             {
267                 if (_eventEventHandler == null)
268                 {
269                     StateEventListenStart();
270                 }
271
272                 _eventEventHandler += value;
273             }
274
275             remove
276             {
277                 _eventEventHandler -= value;
278                 if (_eventEventHandler == null)
279                 {
280                     StateEventListenStop();
281                 }
282             }
283         }
284
285         /// <summary>
286         /// Occurs when an user selects and confirms something to attach in the AttachPanel
287         /// </summary>
288         public event EventHandler<ResultEventArgs> ResultCallback
289         {
290             add
291             {
292                 if (_resultEventHandler == null)
293                 {
294                     ResultEventListenStart();
295                 }
296
297                 _resultEventHandler += value;
298             }
299
300             remove
301             {
302                 _resultEventHandler -= value;
303                 if (_resultEventHandler == null)
304                 {
305                     ResultEventListenStop();
306                 }
307             }
308         }
309     }
310 }