Updated programming guide for image-scaling-and-fitting
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / controls / control-wrapper.h
1 #ifndef __DALI_V8PLUGIN_CONTROL_WRAPPER_H__
2 #define __DALI_V8PLUGIN_CONTROL_WRAPPER_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <v8.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali-toolkit/public-api/controls/control.h>
25
26 // INTERNAL INCLUDES
27 #include <actors/actor-wrapper.h>
28
29 namespace Dali
30 {
31
32 namespace V8Plugin
33 {
34
35
36 /**
37  * Wraps a Dali Control.
38  */
39 class ControlWrapper : public ActorWrapper
40 {
41
42 public:
43
44   /**
45    * Control type used an index.
46    * These enums are used to index the ControlApiLookup table in control-wrapper.cpp.
47    * Any changes made must be reflected in the ControlApiLookup otherwise it may segfault when creating a control
48    */
49   enum ControlType
50   {
51     UNKNOWN_CONTROL = -1,
52     CONTROL         = 0,
53     ITEMVIEW        = 1
54   };
55
56   /**
57    * Constructor
58    * @param control DALi control
59    * @param gc garbage collection interface
60    */
61   ControlWrapper( Toolkit::Control control,
62                 GarbageCollectorInterface& gc );
63
64   /**
65    * destructor
66    */
67   virtual ~ControlWrapper();
68
69   /**
70    * @brief Creates a new Control wrapped inside a Javascript Object.
71    * @note: the control type is passed as a parameter e.g. 'ItemView'
72    * @param[in] args v8 function call arguments interpreted
73    */
74   static void NewControl( const v8::FunctionCallbackInfo< v8::Value >& args);
75
76   /**
77    * @brief Wraps a control of a given type
78    */
79   static v8::Handle<v8::Object> WrapControl(v8::Isolate* isolate, Toolkit::Control control, ControlType controlType);
80
81   /**
82    * @brief Wraps a control, the type is looked up from the control
83    */
84   static v8::Handle<v8::Object> WrapControl(v8::Isolate* isolate, Toolkit::Control control );
85
86   // The Control ObjectTemplates.
87   static v8::Persistent<v8::ObjectTemplate> mControlTemplate;
88   static v8::Persistent<v8::ObjectTemplate> mItemViewTemplate;
89   static v8::Persistent<v8::ObjectTemplate> mScrollViewTemplate;
90
91   /**
92    * @return the wrapped control
93    */
94   Toolkit::Control GetControl();
95
96   /**
97    * @return the control type
98    */
99   static ControlWrapper::ControlType GetControlType( const std::string& name );
100
101   /**
102    * @brief Register the garbage to be released when the wrapped control is deleted.
103    */
104   static void RegisterGarbage(void* garbage);
105
106 private:
107
108   /**
109    * Helper to make the control template
110    */
111   static v8::Handle<v8::ObjectTemplate> MakeDaliControlTemplate( v8::Isolate* isolate, ControlType controlType );
112
113   /**
114    * Helper, get a control template given a control type
115    */
116   static v8::Local<v8::ObjectTemplate> GetControlTemplate( v8::Isolate* isolate, ControlType type );
117
118   Toolkit::Control mControl;
119   static Vector< void* > mControlGarbageContainer;
120
121 };
122
123 } // namespace V8Plugin
124
125 } // namespace Dali
126
127 #endif // header