6d430c9bb8b3b9aafedcc6ed912594c0f948e90d
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / builder / builder-control.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // EXTERNAL INCLUDES
19 #include <string>
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/builder/builder-get-is.inl.h>
23 #include <dali-toolkit/public-api/controls/control.h>
24 #include <dali-toolkit/public-api/controls/alignment/alignment.h>
25 #include <dali/public-api/scripting/scripting.h>
26
27 namespace // unnamed namespace
28 {
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32 using namespace Dali::Scripting; // SetIfEqual
33
34 Control::SizePolicy GetSizePolicy( const std::string& value )
35 {
36   Control::SizePolicy v(Control::Flexible);
37
38   bool set = \
39     SetIfEqual(value, "FIXED",    v, Control::Fixed    ) || \
40     SetIfEqual(value, "MINIMUM",  v, Control::Minimum  ) || \
41     SetIfEqual(value, "MAXIMUM",  v, Control::Maximum  ) || \
42     SetIfEqual(value, "RANGE",    v, Control::Range    ) || \
43     SetIfEqual(value, "FLEXIBLE", v, Control::Flexible );
44
45   if( !set )
46   {
47     DALI_ASSERT_ALWAYS( !"Unknown Color mode" );
48   }
49
50   return v;
51 }
52
53 } // anon namespace
54
55
56 namespace Dali
57 {
58
59 namespace Toolkit
60 {
61
62 namespace Internal
63 {
64
65 /*
66  * Handles special case control configuration (anything thats not already a property)
67  *
68  */
69 Dali::Toolkit::Control SetupControl( const TreeNode& child, Dali::Toolkit::Control& control )
70 {
71   DALI_ASSERT_ALWAYS( control && "Empty actor handle" );
72
73   Control::SizePolicy widthPolicy(Control::Flexible);
74   Control::SizePolicy heightPolicy(Control::Flexible);
75
76   if( OptionalString v = IsString(child, "width-policy") )
77   {
78     widthPolicy = GetSizePolicy(*v);
79     control.SetSizePolicy( widthPolicy, heightPolicy );
80   }
81
82   if( OptionalString v = IsString(child, "height-policy") )
83   {
84     heightPolicy = GetSizePolicy(*v);
85     control.SetSizePolicy( widthPolicy, heightPolicy );
86   }
87
88   if( OptionalVector3 v = IsVector3(child, "minimum-size") )
89   {
90     control.SetMinimumSize( *v );
91   }
92
93   if( OptionalVector3 v = IsVector3(child, "maximum-size") )
94   {
95     control.SetMaximumSize( *v );
96   }
97
98   if( OptionalBoolean v = IsBoolean(child, "key-input-focus") )
99   {
100     if( *v )
101     {
102       control.SetKeyInputFocus();
103     }
104   }
105
106   return control;
107 }
108
109 } // namespace Internal
110
111 } // namespace Toolkit
112
113 } // namespace Dali