[Attach panel] Initial implement C# attach-panel API
[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     public partial class AttachPanel
6     {
7         private const string LogTag = "Tizen.Applications.AttachPanel";
8
9         private static IntPtr _attachPanel;
10
11         private static event EventHandler<StateEventArgs> _eventEventHandler;
12         private static event EventHandler<ResultEventArgs> _resultEventHandler;
13
14         private static Interop.AttachPanel.AttachPanelEventCallback SetEventListener;
15         private static Interop.AttachPanel.AttachPanelResultCallback SetResultListener;
16
17         public AttachPanel(IntPtr conformant)
18         {
19             _attachPanel = new IntPtr();
20             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.CreateAttachPanel(conformant, ref _attachPanel);
21             checkException(err);
22
23             if (_eventEventHandler == null)
24             {
25                 StateEventListenStart();
26             }
27
28             if (_resultEventHandler == null)
29             {
30                 ResultEventListenStart();
31             }
32         }
33
34         ~AttachPanel()
35         {
36             if (_attachPanel != IntPtr.Zero)
37             {
38                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.DestroyAttachPanel(_attachPanel);
39                 checkException(err);
40                 _attachPanel = IntPtr.Zero;
41             }
42         }
43
44         public int State
45         {
46             get
47             {
48                 int state;
49                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetState(_attachPanel, out state);
50                 checkException(err);
51                 return state;
52             }
53         }
54         public int Visible
55         {
56             get
57             {
58                 int visible;
59                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.GetVisibility(_attachPanel, out visible);
60                 checkException(err);
61                 return visible;
62             }
63         }
64
65         public void AddCategory(ContentCategory category, Bundle extraData)
66         {
67             IntPtr bundle = IntPtr.Zero;
68             if (extraData != null)
69             {
70                 bundle = extraData.SafeBundleHandle.DangerousGetHandle();
71             }
72             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.AddCategory(_attachPanel, (int)category, bundle);
73             checkException(err);
74         }
75
76         public void RemoveCategory(ContentCategory category)
77         {
78             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.RemoveCategory(_attachPanel, (int)category);
79             checkException(err);
80         }
81
82         public void SetExtraData(ContentCategory category, Bundle extraData)
83         {
84             IntPtr bundle = IntPtr.Zero;
85             if (extraData != null)
86             {
87                 bundle = extraData.SafeBundleHandle.DangerousGetHandle();
88             }
89             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.SetExtraData(_attachPanel, (int)category, bundle);
90             checkException(err);
91         }
92
93         public void Show()
94         {
95             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Show(_attachPanel);
96             checkException(err);
97         }
98
99         public void Show(bool animation)
100         {
101             if (animation)
102             {
103                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Show(_attachPanel);
104                 checkException(err);
105             }
106             else
107             {
108                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.ShowWithoutAnimation(_attachPanel);
109                 checkException(err);
110             }
111         }
112
113         public void Hide()
114         {
115             Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Hide(_attachPanel);
116             checkException(err);
117         }
118
119         public void Hide(bool animation)
120         {
121             if (animation)
122             {
123                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.Hide(_attachPanel);
124                 checkException(err);
125             }
126             else
127             {
128                 Interop.AttachPanel.ErrorCode err = Interop.AttachPanel.HideWithoutAnimation(_attachPanel);
129                 checkException(err);
130             }
131         }
132
133         public event EventHandler<StateEventArgs> EventChanged
134         {
135             add
136             {
137                 if (_eventEventHandler == null)
138                 {
139                     StateEventListenStart();
140                 }
141                 _eventEventHandler += value;
142             }
143             remove
144             {
145                 _eventEventHandler -= value;
146                 if (_eventEventHandler == null)
147                 {
148                     StateEventListenStop();
149                 }
150             }
151         }
152
153         public event EventHandler<ResultEventArgs> ResultCallback
154         {
155             add
156             {
157                 if (_resultEventHandler == null)
158                 {
159                     ResultEventListenStart();
160                 }
161                 _resultEventHandler += value;
162             }
163             remove
164             {
165                 _resultEventHandler -= value;
166                 if (_resultEventHandler == null)
167                 {
168                     ResultEventListenStop();
169                 }
170             }
171         }
172     }
173 }