Fix for klockwork minor issues.
[platform/framework/native/uifw.git] / inc / FUiRelativeLayout.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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 /**
19  * @file                FUiRelativeLayout.h
20  * @brief               This is the header file for the %RelativeLayout class.
21  *
22  * This header file contains the declarations of the %RelativeLayout class.
23  */
24
25 #ifndef _FUI_RELATIVE_LAYOUT_H_
26 #define _FUI_RELATIVE_LAYOUT_H_
27
28 #include <FUiLayout.h>
29
30 namespace Tizen { namespace Ui
31 {
32 class Control;
33 }}
34
35 namespace Tizen { namespace Ui
36 {
37
38 /**
39  * @class       RelativeLayout
40  * @brief       This class positions the children of a container in a manner that is relative to other children or its parent container.
41  *
42  * @since       2.0
43  *
44  * The %RelativeLayout class defines the relative layout for a Container. The layout positions the children of the %Container relative to the
45  * %Container or its other children. @n
46  *
47  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/relative_layout.htm">Relative Layout</a>.
48  *
49  * The following examples demonstrate how to use the %RelativeLayout class.
50  * @code
51 // Sample code for RelativeLayoutSample.h
52 #include <FUi.h>
53
54 class RelativeLayoutSample
55         : public Tizen::Ui::Controls::Form
56 {
57 public:
58         bool Initialize(void);
59         virtual result OnInitializing(void);
60 };
61  *      @endcode
62  *
63  *      @code
64 // Sample code for RelativeLayoutSample.cpp
65 #include <FGraphics.h>
66
67 #include "RelativeLayoutSample.h"
68
69 using namespace Tizen::Graphics;
70 using namespace Tizen::Ui;
71 using namespace Tizen::Ui::Controls;
72
73 bool
74 RelativeLayoutSample::Initialize(void)
75 {
76         // Creates an instance of RelativeLayout
77         RelativeLayout relativeFormLayout;
78         relativeFormLayout.Construct();
79
80         // Applies the relative layout to the form
81         Construct(relativeFormLayout, FORM_STYLE_NORMAL);
82         return true;
83 }
84
85 result
86 RelativeLayoutSample::OnInitializing(void)
87 {
88         result r = E_SUCCESS;
89
90         // Creates an instance of RelativeLayout for the top panel
91         RelativeLayout topPanelLayout;
92         topPanelLayout.Construct();
93
94         // Creates an instance of Panel and applies it to the relative layout
95         Panel* pTopRelativePanel = new Panel();
96         pTopRelativePanel->Construct(topPanelLayout, Rectangle(0, 0, 300, 300));
97         {
98                 // Creates instances of Button
99                 Button* pUpButton = new Button();
100                 pUpButton->Construct(Rectangle(0,0,200,100), "UP");
101                 pTopRelativePanel->AddControl(pUpButton);
102
103                 Button* pMiddleButton = new Button();
104                 pMiddleButton->Construct(Rectangle(0,0,200,100), "CENTER");
105                 pTopRelativePanel->AddControl(pMiddleButton);
106
107                 Button* pDownButton = new Button();
108                 pDownButton->Construct(Rectangle(0,0,200,100), "DOWN");
109                 pTopRelativePanel->AddControl(pDownButton);
110
111                 // Sets relations between the pUpButton and pMiddleButton
112                 topPanelLayout.SetRelation(*pUpButton, pMiddleButton, RECT_EDGE_RELATION_LEFT_TO_LEFT);
113                 topPanelLayout.SetRelation(*pUpButton, pMiddleButton, RECT_EDGE_RELATION_BOTTOM_TO_TOP);
114                 topPanelLayout.SetMargin(*pUpButton, 0, 0, 0, 10);
115
116                 // Sets the middle button
117                 topPanelLayout.SetCenterAligned(*pMiddleButton, CENTER_ALIGN_HORIZONTAL);
118                 topPanelLayout.SetCenterAligned(*pMiddleButton, CENTER_ALIGN_VERTICAL);
119                 topPanelLayout.SetMargin(*pMiddleButton, 10, 10, 10, 10);
120
121                 // Sets relations between the pDownButton and the pMiddleButton
122                 topPanelLayout.SetRelation(*pDownButton, pMiddleButton, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
123                 topPanelLayout.SetRelation(*pDownButton, pMiddleButton, RECT_EDGE_RELATION_TOP_TO_BOTTOM);
124                 topPanelLayout.SetMargin(*pDownButton, 0, 0, 10, 0);
125         }
126
127         // Adds the top panel to the form
128         AddControl(pTopRelativePanel);
129
130         // Creates an instance of RelativeLayout for the bottom panel
131         RelativeLayout bottomPanelLayout;
132         bottomPanelLayout.Construct();
133
134         // Creates an instance of Panel and applies it to the relative layout
135         Panel* pBottomRelativePanel = new Panel();
136         pBottomRelativePanel->Construct(bottomPanelLayout, Rectangle(0, 0, 300, 300));
137         {
138                 // Creates instances of Label
139                 Label* pFixedLabel = new Label();
140                 pFixedLabel->Construct(Rectangle(0, 0, 150, 80), L"FIXED");
141                 pFixedLabel->SetBackgroundColor(Color::GetColor(COLOR_ID_YELLOW));
142                 pFixedLabel->SetTextColor(Color::GetColor(COLOR_ID_BLACK));
143                 pBottomRelativePanel->AddControl(pFixedLabel);
144
145                 Label* pScalableLabel = new Label();
146                 pScalableLabel->Construct(Rectangle(0, 0, 150, 80), L"SCALABLE <=>");
147                 pScalableLabel->SetBackgroundColor(Color::GetColor(COLOR_ID_BLUE));
148                 pScalableLabel->SetTextColor(Color::GetColor(COLOR_ID_BLACK));
149                 pBottomRelativePanel->AddControl(pScalableLabel);
150
151                 // Sets relations between the fixed label and the panel
152                 bottomPanelLayout.SetCenterAligned(*pFixedLabel, CENTER_ALIGN_VERTICAL);
153                 bottomPanelLayout.SetRelation(*pFixedLabel, pBottomRelativePanel, RECT_EDGE_RELATION_LEFT_TO_LEFT);
154                 bottomPanelLayout.SetRelation(*pFixedLabel, pBottomRelativePanel, RECT_EDGE_RELATION_TOP_TO_TOP);
155                 bottomPanelLayout.SetMargin(*pFixedLabel, 30, 30, 30, 30);
156
157                 // Sets relations between the scalable label and the panel
158                 bottomPanelLayout.SetCenterAligned(*pScalableLabel, CENTER_ALIGN_VERTICAL);
159                 bottomPanelLayout.SetRelation(*pScalableLabel, pFixedLabel, RECT_EDGE_RELATION_LEFT_TO_RIGHT);
160                 bottomPanelLayout.SetRelation(*pScalableLabel, pFixedLabel, RECT_EDGE_RELATION_LEFT_TO_RIGHT);
161                 bottomPanelLayout.SetRelation(*pScalableLabel, pBottomRelativePanel, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
162                 bottomPanelLayout.SetRelation(*pScalableLabel, pBottomRelativePanel, RECT_EDGE_RELATION_TOP_TO_TOP);
163                 bottomPanelLayout.SetMargin(*pScalableLabel, 30, 30, 30, 30);
164         }
165
166         // Adds the bottom panel to the form
167         AddControl(pBottomRelativePanel);
168
169         //Gets the layout of the form
170         RelativeLayout* pFormLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
171
172         // Sets relations of the top relative panel
173         pFormLayout->SetRelation(*pTopRelativePanel, this, RECT_EDGE_RELATION_LEFT_TO_LEFT);
174         pFormLayout->SetRelation(*pTopRelativePanel, this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
175         pFormLayout->SetRelation(*pTopRelativePanel, this, RECT_EDGE_RELATION_TOP_TO_TOP);
176
177         // Sets relations of the bottom relative panel
178         pFormLayout->SetRelation(*pBottomRelativePanel, this, RECT_EDGE_RELATION_LEFT_TO_LEFT);
179         pFormLayout->SetRelation(*pBottomRelativePanel, this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
180         pFormLayout->SetRelation(*pBottomRelativePanel, this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
181
182         // Sets relations between the top relative panel and the bottom relative panel
183         pFormLayout->SetHorizontalFitPolicy(*pTopRelativePanel, FIT_POLICY_PARENT);
184         pFormLayout->SetHorizontalFitPolicy(*pBottomRelativePanel, FIT_POLICY_PARENT);
185         pFormLayout->SetVerticalFitPolicy(*pBottomRelativePanel, FIT_POLICY_FIXED);
186         pFormLayout->SetRelation(*pTopRelativePanel, pBottomRelativePanel, RECT_EDGE_RELATION_BOTTOM_TO_TOP);
187
188         return r;
189 }
190  * @endcode
191  *
192  */
193 class _OSP_EXPORT_ RelativeLayout
194         : public Layout
195 {
196 public:
197         /**
198          * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
199          *
200          * @since               2.0
201          *
202          * @remarks             After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
203          */
204         RelativeLayout(void);
205
206         /**
207          * This destructor overrides Tizen::Base::Object::~Object().
208          *
209          * @since               2.0
210          */
211         virtual ~RelativeLayout(void);
212
213         /**
214          * Initializes this instance of %RelativeLayout.
215          *
216          * @since               2.0
217          *
218          * @return              An error code
219          * @exception   E_SUCCESS                       The method is successful.
220          * @exception   E_SYSTEM                        A system error has occurred.
221          */
222         result Construct(void);
223
224         /**
225          * Gets the type of the layout.
226          *
227          * @since               2.0
228          *
229          * @return      The layout type
230          */
231         virtual LayoutType GetLayoutType(void) const;
232
233         /**
234          * Sets the relation of the specified child control for the edge with other control.
235          *
236          * @brief       <i> [Deprecated] </i>
237          * @deprecated  This method is deprecated.
238          * @since               2.0
239          *
240          * @return              An error code
241          * @param[in]   childControl    The control for which the relation is set
242          * @param[in]   targetControl   The target control @n
243          *                                                              It must be a parent or sibling.
244          * @param[in]   edgeRelation    The edge of the specified control to align with the edge of the target control
245          * @exception   E_SUCCESS               The method is successful.
246          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
247          *                                                              Either the specified @c childControl or the specified @c targetControl is not a child of the container that owns the layout.
248          * @exception   E_SYSTEM                A system error has occurred.
249          */
250         result SetRelation(Control& childControl, const Control& targetControl, RectangleEdgeRelation edgeRelation);
251
252         /**
253          * Sets the relation of a specified child control for the edge with other control.
254          *
255          * @since               2.1
256          *
257          * @return              An error code
258          * @param[in]   childControl    The control for which the relation is set
259          * @param[in]   pTargetControl  The target control @n
260          *                                                              It must be a parent or sibling.
261          * @param[in]   edgeRelation    The edge of the specified control to align with the edge of the target control
262          * @exception   E_SUCCESS               The method is successful.
263          * @exception   E_INVALID_ARG   A specified input parameter is invalid. @n
264          *                                                              Either the specified @c childControl or the specified @c pTargetControl is not a child of the container that owns the layout.
265          * @exception   E_SYSTEM                A system error has occurred.
266          */
267         result SetRelation(Control& childControl, Control *pTargetControl, RectangleEdgeRelation edgeRelation);
268
269         /**
270          * Resets the relation of the specified control for the vertical edge.
271          *
272          * @since               2.0
273          *
274          * @return              An error code
275          * @param[in]   childControl    The control for which the relation is reset
276          * @param[in]   edgeType                The edge type of the specified control
277          * @exception   E_SUCCESS               The method is successful.
278          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
279          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
280          * @exception   E_SYSTEM                A system error has occurred.
281          */
282         result ResetRelation(Control& childControl, RectangleEdgeType edgeType);
283
284         /**
285          * Sets the specified control at the center of the parent control.
286          *
287          * @since               2.0
288          *
289          * @return              An error code
290          * @param[in]   childControl    The control to center aligned
291          * @param[in]   alignment               The center alignment for a control either vertically or horizontally
292          * @exception   E_SUCCESS               The method is successful.
293          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
294          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
295          * @exception   E_SYSTEM                A system error has occurred.
296          * @remarks             The relation value that is set to a child control is ignored when the center-alignment is applied to the control.
297          */
298         result SetCenterAligned(Control& childControl, CenterAlignmentType alignment);
299
300         /**
301          * Resets the center position of the specified control.
302          *
303          * @since               2.0
304          *
305          * @return              An error code
306          * @param[in]   childControl    The control to center aligned
307          * @param[in]   alignment               The center alignment for a control either vertically or horizontally
308          * @exception   E_SUCCESS               The method is successful.
309          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
310          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
311          * @exception   E_SYSTEM                A system error has occurred.
312          */
313         result ResetCenterAligned(Control& childControl, CenterAlignmentType alignment);
314
315         /**
316          * Sets the margins of the specified control.
317          *
318          * @since               2.0
319          *
320          * @return              An error code
321          * @param[in]   childControl    The control for which the margins are set
322          * @param[in]   left                    The left margin
323          * @param[in]   right                   The right margin
324          * @param[in]   top                             The top margin
325          * @param[in]   bottom                  The bottom margin
326          * @exception   E_SUCCESS               The method is successful.
327          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
328          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
329          * @exception   E_SYSTEM                A system error has occurred.
330          * @remarks             By default, the margins are set to @c 0.
331          */
332         result SetMargin(Control& childControl, int left, int right, int top, int bottom);
333
334         /**
335          * Sets the margins of a specified control.
336          *
337          * @since               2.1
338          *
339          * @return              An error code
340          * @param[in]   childControl    The control for which the margins are set
341          * @param[in]   left                    The left margin
342          * @param[in]   right                   The right margin
343          * @param[in]   top                             The top margin
344          * @param[in]   bottom                  The bottom margin
345          * @exception   E_SUCCESS               The method is successful.
346          * @exception   E_INVALID_ARG   A specified input parameter is invalid. @n
347          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
348          * @exception   E_SYSTEM                A system error has occurred.
349          * @remarks             By default, the margins are set to @c 0.
350          */
351         result SetMargin(Control& childControl, float left, float right, float top, float bottom);
352
353         /**
354          * Sets the width of the specified control to the fixed size.
355          *
356          * @since               2.0
357          *
358          * @return              An error code
359          * @param[in]   childControl    The control for which the width is set
360          * @param[in]   width                   The value of the width
361          * @exception   E_SUCCESS               The method is successful.
362          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
363          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
364          * @exception   E_SYSTEM                A system error has occurred.
365          */
366         result SetWidth(Control& childControl, int width);
367
368         /**
369          * Sets the width of a specified control to the fixed size.
370          *
371          * @since               2.1
372          *
373          * @return              An error code
374          * @param[in]   childControl    The control for which the width is set
375          * @param[in]   width                   The value of the width
376          * @exception   E_SUCCESS               The method is successful.
377          * @exception   E_INVALID_ARG   A specified input parameter is invalid. @n
378          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
379          * @exception   E_SYSTEM                A system error has occurred.
380          */
381         result SetWidth(Control& childControl, float width);
382
383         /**
384          * Sets the width of the specified control as per the fitting policy.
385          *
386          * @since               2.0
387          *
388          * @return              An error code
389          * @param[in]   childControl    The control for which the width is set
390          * @param[in]   policy                  The fitting policy for the width
391          * @exception   E_SUCCESS               The method is successful.
392          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
393          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
394          * @exception   E_SYSTEM                A system error has occurred.
395          */
396         result SetHorizontalFitPolicy(Control& childControl, FitPolicy policy);
397
398         /**
399          * Sets the height of the specified control to the fixed size.
400          *
401          * @since               2.0
402          *
403          * @return              An error code
404          * @param[in]   childControl    The control for which the height is set
405          * @param[in]   height                  The value of the height
406          * @exception   E_SUCCESS               The method is successful.
407          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
408          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
409          * @exception   E_SYSTEM                A system error has occurred.
410          */
411         result SetHeight(Control& childControl, int height);
412
413         /**
414          * Sets the height of a specified control to the fixed size.
415          *
416          * @since               2.1
417          *
418          * @return              An error code
419          * @param[in]   childControl    The control for which the height is set
420          * @param[in]   height                  The value of the height
421          * @exception   E_SUCCESS               The method is successful.
422          * @exception   E_INVALID_ARG   A specified input parameter is invalid. @n
423          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
424          * @exception   E_SYSTEM                A system error has occurred.
425          */
426         result SetHeight(Control& childControl, float height);
427
428         /**
429          * Sets the height of the specified control as per the fitting policy.
430          *
431          * @since               2.0
432          *
433          * @return              An error code
434          * @param[in]   childControl    The control for which the height is set
435          * @param[in]   policy                  The fitting policy for the height
436          * @exception   E_SUCCESS               The method is successful.
437          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
438          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
439          * @exception   E_SYSTEM                A system error has occurred.
440          */
441         result SetVerticalFitPolicy(Control& childControl, FitPolicy policy);
442
443 private:
444         //
445         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
446         //
447         RelativeLayout(const RelativeLayout& rhs);
448
449         //
450         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
451         //
452         RelativeLayout& operator =(const RelativeLayout& rhs);
453
454 }; // RelativeLayout
455
456 }} // Tizen::Ui
457
458 #endif // _FUI_RELATIVE_LAYOUT_H_