c7184895f6eab6a99481249ba498ab6ac08fc4bf
[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> 4 </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> 4 </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         /// <since_tizen> 4 </since_tizen>
96         public StateType State
97         {
98             get
99             {
100                 int interopState;
101                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetState(_attachPanel, out interopState);
102                 CheckException(err);
103                 StateType state = (StateType)Enum.ToObject(typeof(StateType), interopState);
104                 return state;
105             }
106         }
107
108         /// <summary>
109         /// Gets the value that indicates whether the AttachPanel is visible.
110         /// </summary>
111         /// <value>visible value of AttachPanel state</value>
112         /// <since_tizen> 4 </since_tizen>
113         public bool Visible
114         {
115             get
116             {
117                 int visible;
118                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetVisibility(_attachPanel, out visible);
119                 CheckException(err);
120                 return (visible == 1);
121             }
122         }
123
124         /// <summary>
125         /// Add a content category in the AttachPanel.
126         /// </summary>
127         /// <param name="category">The ContentCategory to be added in the AttachPanel</param>
128         /// <param name="extraData">The AttachPanel send some information using Bundle</param>
129         /// <privilege>http://tizen.org/privilege/mediastorage</privilege>
130         /// <privilege>http://tizen.org/privilege/camera</privilege>
131         /// <privilege>http://tizen.org/privilege/recorder</privilege>
132         /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
133         /// <feature>http://tizen.org/feature/camera</feature>
134         /// <feature>http://tizen.org/feature/microphone</feature>
135         /// <remarks>
136         /// The caller app has to check the return value of this function.
137         /// Content categories will be shown as the sequence of using AddCategory
138         /// Some contents need time to load it all.
139         /// So, it is needed to use this before the mainloop of Show
140         /// Privileges,
141         /// http://tizen.org/privilege/mediastorage, for using Image or Camera
142         /// http://tizen.org/privilege/camera, for using Camera or TakePicture
143         /// http://tizen.org/privilege/recorder, for using Voice
144         /// http://tizen.org/privilege/appmanager.launch, for adding content categories on the More tab
145         /// http://tizen.org/feature/camera, for using Camera or TakePicture
146         /// http://tizen.org/feature/microphone, for using Voice
147         /// Deliver more information to the callee with a bundle if you need.
148         /// http://tizen.org/appcontrol/data/total_count
149         /// http://tizen.org/appcontrol/data/total_size
150         /// </remarks>
151         /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="category"/> is not a valid category</exception>
152         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have privilege to access this method</exception>
153         /// <exception cref="NotSupportedException">Thrown when the device does not supported the <paramref name="category"/> feature </exception>
154         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is not created yet or already destroyed</exception>
155         /// <since_tizen> 4 </since_tizen>
156         public void AddCategory(ContentCategory category, Bundle extraData)
157         {
158             IntPtr bundle = IntPtr.Zero;
159             if (extraData != null)
160             {
161                 bundle = extraData.SafeBundleHandle.DangerousGetHandle();
162             }
163
164             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.AddCategory(_attachPanel, (int)category, bundle);
165             CheckException(err);
166         }
167
168         /// <summary>
169         /// Removes the ContentCategory from the AttachPanel
170         /// </summary>
171         /// <param name="category">The ContentCategory adding in the AttachPanel</param>
172         ///  <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="category"/> is not a valid category</exception>
173         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is not created yet or already destroyed</exception>
174         /// <since_tizen> 4 </since_tizen>
175         public void RemoveCategory(ContentCategory category)
176         {
177             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.RemoveCategory(_attachPanel, (int)category);
178             CheckException(err);
179         }
180
181         /// <summary>
182         /// Sets extraData to send to the ContentCategory using a Bundle
183         /// </summary>
184         /// <param name="category">The ContentCategory that some information to be set in the AttachPanel.</param>
185         /// <param name="extraData">The AttachPanel send some information using Bundle</param>
186         /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="category"/> is not a valid category</exception>
187         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
188         /// <exception cref="OutOfMemoryException">Thrown when an attempt to allocate memory fails.</exception>
189         /// <since_tizen> 4 </since_tizen>
190         public void SetExtraData(ContentCategory category, Bundle extraData)
191         {
192             if (extraData == null)
193             {
194                 CheckException(Interop.AttachPanel.ErrorCode.InvalidParameter);
195             }
196
197             IntPtr bundle = IntPtr.Zero;
198             if (extraData != null)
199             {
200                 bundle = extraData.SafeBundleHandle.DangerousGetHandle();
201             }
202
203             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.SetExtraData(_attachPanel, (int)category, bundle);
204             CheckException(err);
205         }
206
207         /// <summary>
208         /// Shows the attach panel with animations
209         /// </summary>
210         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
211         /// <since_tizen> 4 </since_tizen>
212         public void Show()
213         {
214             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Show(_attachPanel);
215             CheckException(err);
216         }
217
218         /// <summary>
219         /// Shows the attach panel and selects whether or not to animate
220         /// </summary>
221         /// <param name="animation">A flag which turn on or turn off the animation while attach panel showing.</param>
222         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
223         /// <since_tizen> 4 </since_tizen>
224         public void Show(bool animation)
225         {
226             if (animation)
227             {
228                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Show(_attachPanel);
229                 CheckException(err);
230             }
231             else
232             {
233                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.ShowWithoutAnimation(_attachPanel);
234                 CheckException(err);
235             }
236         }
237
238         /// <summary>
239         /// Hides the attach panel with animations
240         /// </summary>
241         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
242         /// <since_tizen> 4 </since_tizen>
243         public void Hide()
244         {
245             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Hide(_attachPanel);
246             CheckException(err);
247         }
248
249         /// <summary>
250         /// Hides the attach panel and selects whether or not to animate
251         /// </summary>
252         /// <param name="animation">A flag which turn on or turn off the animation while attach panel hiding.</param>
253         /// <exception cref="InvalidOperationException">Thrown when the AttachPanel is destroyed</exception>
254         /// <since_tizen> 4 </since_tizen>
255         public void Hide(bool animation)
256         {
257             if (animation)
258             {
259                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Hide(_attachPanel);
260                 CheckException(err);
261             }
262             else
263             {
264                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.HideWithoutAnimation(_attachPanel);
265                 CheckException(err);
266             }
267         }
268
269         /// <summary>
270         /// Occurs when reserved events are published from the panel-side.
271         /// </summary>
272         /// <since_tizen> 4 </since_tizen>
273         public event EventHandler<StateEventArgs> EventChanged
274         {
275             add
276             {
277                 if (_eventEventHandler == null)
278                 {
279                     StateEventListenStart();
280                 }
281
282                 _eventEventHandler += value;
283             }
284
285             remove
286             {
287                 _eventEventHandler -= value;
288                 if (_eventEventHandler == null)
289                 {
290                     StateEventListenStop();
291                 }
292             }
293         }
294
295         /// <summary>
296         /// Occurs when an user selects and confirms something to attach in the AttachPanel
297         /// </summary>
298         /// <since_tizen> 4 </since_tizen>
299         public event EventHandler<ResultEventArgs> ResultCallback
300         {
301             add
302             {
303                 if (_resultEventHandler == null)
304                 {
305                     ResultEventListenStart();
306                 }
307
308                 _resultEventHandler += value;
309             }
310
311             remove
312             {
313                 _resultEventHandler -= value;
314                 if (_resultEventHandler == null)
315                 {
316                     ResultEventListenStop();
317                 }
318             }
319         }
320     }
321 }