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