Tizen 2.1 base
[framework/osp/uifw.git] / inc / FUiCtrlRadioGroup.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUiCtrlRadioGroup.h
19  * @brief       This is the header file for the %RadioGroup class.
20  *
21  * This header file contains the declarations of the %RadioGroup class and its helper classes.
22  */
23
24 #ifndef _FUI_CTRL_RADIO_GROUP_H_
25 #define _FUI_CTRL_RADIO_GROUP_H_
26
27 #include <FBaseObject.h>
28 #include <FBaseTypes.h>
29 #include <FUiControl.h>
30 #include <FUiContainer.h>
31 #include <FUiCtrlCheckButton.h>
32
33 namespace Tizen { namespace Ui { namespace Controls
34 {
35 /**
36  * @class       RadioGroup
37  * @brief       This class is an implementation of a %RadioGroup control.
38  *
39  * @since       2.0
40  *
41  * The %RadioGroup class displays a set of CheckButtons with radio style together in a group, allowing the user to select only
42  * one of the predefined set of buttons.
43  * @n
44  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/implementing_button.htm">Buttons</a>.
45  *
46  * The following example demonstrates how to use the %RadioGroup class.
47  *
48  * @code
49 // Sample code for RadioGroupSample.h
50 #include <FUi.h>
51
52 class RadioGroupSample
53         : public Tizen::Ui::Controls::Form
54         , public Tizen::Ui::IActionEventListener
55 {
56 public:
57         RadioGroupSample(void)
58         : __pRadioGroup(null){}
59
60         bool Initialize(void);
61         virtual result OnInitializing(void);
62         virtual result OnTerminating(void);
63         virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
64
65 private:
66         static const int ID_BUTTON1_CHECKED = 101;
67         static const int ID_BUTTON1_UNCHECKED = 102;
68         static const int ID_BUTTON2_CHECKED = 103;
69         static const int ID_BUTTON2_UNCHECKED = 104;
70
71         Tizen::Ui::Controls::RadioGroup* __pRadioGroup;
72 };
73  *      @endcode
74  *
75  *      @code
76 // Sample code for RadioGroupSample.cpp
77 #include <FGraphics.h>
78
79 #include "RadioGroupSample.h"
80
81 using namespace Tizen::Graphics;
82 using namespace Tizen::Ui::Controls;
83
84 bool
85 RadioGroupSample::Initialize(void)
86 {
87         Construct(FORM_STYLE_NORMAL);
88         return true;
89 }
90
91 result
92 RadioGroupSample::OnInitializing(void)
93 {
94         result r = E_SUCCESS;
95
96         // Creates instances of CheckButton
97         CheckButton *pCheckButton1 = new CheckButton();
98         pCheckButton1->Construct(Rectangle(50, 50, GetClientAreaBounds().width - 100, 100),
99                         CHECK_BUTTON_STYLE_RADIO, BACKGROUND_STYLE_DEFAULT, false, L"Radio1");
100         pCheckButton1->SetActionId(ID_BUTTON1_CHECKED, ID_BUTTON1_UNCHECKED);
101         pCheckButton1->AddActionEventListener(*this);
102
103         CheckButton *pCheckButton2 = new CheckButton();
104         pCheckButton2->Construct(Rectangle(50, 160, GetClientAreaBounds().width - 100, 100),
105                         CHECK_BUTTON_STYLE_RADIO,BACKGROUND_STYLE_DEFAULT, false, L"Radio2");
106         pCheckButton2->SetActionId(ID_BUTTON2_CHECKED, ID_BUTTON2_UNCHECKED);
107         pCheckButton2->AddActionEventListener(*this);
108
109         // Adds check buttons to the form
110         AddControl(*pCheckButton1);
111         AddControl(*pCheckButton2);
112
113         // Creates an instance of RadioGroup
114         __pRadioGroup = new RadioGroup();
115         __pRadioGroup->Construct();
116
117         // Adds the check buttons to the radio group
118         __pRadioGroup->Add(*pCheckButton1);
119         __pRadioGroup->Add(*pCheckButton2);
120
121         return r;
122 }
123
124 result
125 RadioGroupSample::OnTerminating(void)
126 {
127         result r = E_SUCCESS;
128
129         // Deallocates the __pRadioGroup
130         delete __pRadioGroup;
131
132         return r;
133 }
134
135 // IActionEventListener implementation
136 void
137 RadioGroupSample::OnActionPerformed(const Control& source, int actionId)
138 {
139         switch (actionId)
140         {
141         case ID_BUTTON1_CHECKED:
142                 {
143                         // ....
144                 }
145                 break;
146         case ID_BUTTON1_UNCHECKED:
147                 {
148                         // ....
149                 }
150                 break;
151         case ID_BUTTON2_CHECKED:
152                 {
153                         // ....
154                 }
155                 break;
156         case ID_BUTTON2_UNCHECKED:
157                 {
158                         // ....
159                 }
160                 break;
161         default:
162                 break;
163         }
164 }
165  * @endcode
166  *
167  */
168 class _OSP_EXPORT_ RadioGroup
169         : public Tizen::Ui::Control
170 {
171 public:
172         /**
173          * This is the default constructor for this class.
174          *
175          * @since       2.0
176          */
177         RadioGroup(void);
178
179         /**
180          * This is the destructor for this class.
181          *
182          * @since       2.0
183          */
184         virtual ~RadioGroup(void);
185
186
187         /**
188          * Initializes this instance of %RadioGroup.
189          *
190          * @since                       2.0
191          *
192          * @return      An error code
193          * @exception   E_SUCCESS           The method is successful.
194          * @exception   E_SYSTEM            A system error has occurred.
195          */
196         result Construct(void);
197
198 public:
199         /**
200          * Adds the check button to the radio group.
201          *
202          * @since               2.0
203          *
204          * @return              An error code
205          * @param[in]   checkButton             The %CheckButton instance to be added
206          * @exception   E_SUCCESS       The method is successful.
207          * @exception   E_INVALID_ARG   The specified input parameter is invalid.
208          * @exception   E_SYSTEM                A system error has occurred.
209          * @remarks             Only CheckButtons whose style is CHECK_BUTTON_STYLE_RADIO or CHECK_BUTTON_STYLE_RADIO_WITH_DIVIDER can be added to %RadioGroup.
210          */
211         result Add(const CheckButton& checkButton);
212
213         /**
214          * Removes the check button from the radio group.
215          *
216          * @since               2.0
217          *
218          * @return              An error code
219          * @param[in]   checkButton                     The %CheckButton instance to be removed
220          * @exception   E_SUCCESS           The method is successful.
221          * @exception   E_OBJ_NOT_FOUND         The object is not found.
222          * @exception   E_SYSTEM                        A system error has occurred.
223          * @remarks             Before removing %CheckButton from its parent container, it must be removed from %RadioGroup.
224          */
225         result Remove(const CheckButton& checkButton);
226
227 public:
228         /**
229          * Gets the number of check buttons in the radio group.
230          *
231          * @since       2.0
232          *
233          * @return      The number of check buttons in the radio group
234          */
235         int GetItemCount(void) const;
236
237         /**
238          * Selects the specified check button in the radio group.
239          *
240          * @since                       2.0
241          *
242          * @param[in]           checkButton             The check button to be selected
243          */
244         void SetSelectedItem(const CheckButton& checkButton);
245
246         /**
247          * Gets the selected check button in the radio group.
248          *
249          * @since                       2.0
250          *
251          * @return      The pointer to the selected check button, @n
252          *                      else  @c null if an error occurs or no check button in the radio group is selected
253          *
254          */
255         const CheckButton* GetSelectedItem(void) const;
256
257         //
258         // This method is for internal use only.
259         // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
260         //
261         // This method is prohibited. If this method is used
262         // in an application, the application can get rejected during the certification
263         // process.
264         //
265         // (Blocked) Draws the control.
266         //
267         // @since               2.0
268         //
269         // @return              An error code
270         // @exception   E_UNSUPPORTED_OPERATION         This operation is not supported.
271         //
272         virtual result Draw(void);
273
274         //
275         // This method is for internal use only.
276         // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
277         //
278         // This method is prohibited. If this method is used
279         // in an application, the application can get rejected during the certification
280         // process.
281         //
282         // (Blocked) Shows this control.
283         //
284         // @since               2.0
285         //
286         // @return              An error code
287         // @exception   E_UNSUPPORTED_OPERATION         This operation is not supported.
288         //
289         virtual result Show(void);
290
291         //
292         // This method is for internal use only.
293         // Using this method can cause behavioral, security-related, and consistency-related issues in the application.
294         //
295         // This method is prohibited. If this method is used
296         // in an application, the application can get rejected during the certification
297         // process.
298         //
299         // (Blocked) Gives the input focus to the control. @n
300         // One must call this method if the control needs to listen to the user input events such as key pressed.
301         //
302         // @since               2.0
303         //
304         // @return              An error code
305         // @exception   E_UNSUPPORTED_OPERATION         This operation is not supported.
306         //
307         virtual result SetFocus(void);
308
309 protected:
310         friend class _RadioGroupImpl;
311
312 private:
313         //
314         // This is the copy constructor for the %RadioGroup class.
315         //
316         RadioGroup(const RadioGroup& rhs);
317
318         //
319         // Assigns the value of the specified instance to the current instance of %RadioGroup.
320         //
321         RadioGroup& operator =(const RadioGroup& rhs);
322
323 }; // RadioGroup
324
325 }}} //Tizen::Ui::Controls
326
327 #endif // _FUI_CTRL_RADIO_GROUP_H_