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