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