2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/text-controls/text-selection-toolbar-impl.h>
22 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/math/vector4.h>
28 #include <dali/devel-api/object/type-registry-helper.h>
44 const Dali::Vector2 DEFAULT_MAX_SIZE( 400.0f, 65.0f ); ///< The maximum size of the Toolbar.
48 return Toolkit::TextSelectionToolbar::New();
51 // Setup properties, signals and actions using the type-registry.
53 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionToolbar, Toolkit::Control, Create );
55 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionToolbar, "max-size", VECTOR2, MAX_SIZE )
57 DALI_TYPE_REGISTRATION_END()
61 Dali::Toolkit::TextSelectionToolbar TextSelectionToolbar::New()
63 // Create the implementation, temporarily owned by this handle on stack
64 IntrusivePtr< TextSelectionToolbar > impl = new TextSelectionToolbar();
66 // Pass ownership to CustomActor handle
67 Dali::Toolkit::TextSelectionToolbar handle( *impl );
69 // Second-phase init of the implementation
70 // This can only be done after the CustomActor connection has been made...
76 void TextSelectionToolbar::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
78 Toolkit::TextSelectionToolbar selectionPopup = Toolkit::TextSelectionToolbar::DownCast( Dali::BaseHandle( object ) );
82 TextSelectionToolbar& impl( GetImpl( selectionPopup ) );
86 case Toolkit::TextSelectionToolbar::Property::MAX_SIZE:
88 impl.SetPopupMaxSize( value.Get< Vector2 >() );
93 } // TextSelectionToolbar
96 Property::Value TextSelectionToolbar::GetProperty( BaseObject* object, Property::Index index )
98 Property::Value value;
100 Toolkit::TextSelectionToolbar selectionPopup = Toolkit::TextSelectionToolbar::DownCast( Dali::BaseHandle( object ) );
104 TextSelectionToolbar& impl( GetImpl( selectionPopup ) );
108 case Toolkit::TextSelectionToolbar::Property::MAX_SIZE:
110 value = impl.GetPopupMaxSize();
118 void TextSelectionToolbar::OnInitialize()
123 void TextSelectionToolbar::SetPopupMaxSize( const Size& maxSize )
128 const Dali::Vector2& TextSelectionToolbar::GetPopupMaxSize() const
133 void TextSelectionToolbar::SetUp()
136 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
138 // Create Layer and Stencil.
139 mStencilLayer = Layer::New();
140 mStencilLayer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
141 mStencilLayer.SetParentOrigin( ParentOrigin::CENTER );
142 mStencilLayer.SetMaximumSize( mMaxSize );
144 ImageActor stencil = CreateSolidColorActor( Color::RED );
145 stencil.SetDrawMode( DrawMode::STENCIL );
146 stencil.SetVisible( true );
147 stencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
148 stencil.SetParentOrigin( ParentOrigin::CENTER );
150 Actor scrollview = Actor::New(); //todo make a scrollview
151 scrollview.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
152 scrollview.SetParentOrigin( ParentOrigin::CENTER );
154 // Toolbar needs at least one option, adding further options with increase it's size
155 mTableOfButtons = Dali::Toolkit::TableView::New( 1, 1 );
156 mTableOfButtons.SetFitHeight( 0 );
157 mTableOfButtons.SetParentOrigin( ParentOrigin::CENTER );
159 mStencilLayer.Add( stencil );
160 mStencilLayer.Add( scrollview );
161 scrollview.Add( mTableOfButtons );
162 self.Add( mStencilLayer );
164 mStencilLayer.RaiseToTop();
167 void TextSelectionToolbar::AddOption( Actor& option )
169 mTableOfButtons.AddChild( option, Toolkit::TableView::CellPosition( 0, mIndexInTable ) );
170 mTableOfButtons.SetFitWidth( mIndexInTable );
174 void TextSelectionToolbar::AddDivider( Actor& divider )
176 AddOption( divider );
177 mDividerIndexes.PushBack( mIndexInTable );
180 void TextSelectionToolbar::ResizeDividers( Size& size )
182 for( unsigned int i = 0; i < mDividerIndexes.Count(); ++i )
184 Actor divider = mTableOfButtons.GetChildAt( Toolkit::TableView::CellPosition( 0, mDividerIndexes[ i ] ) );
185 divider.SetSize( size );
190 TextSelectionToolbar::TextSelectionToolbar()
191 : Control( ControlBehaviour( ControlBehaviour( ACTOR_BEHAVIOUR_NONE ) ) ),
192 mMaxSize ( DEFAULT_MAX_SIZE ),
198 TextSelectionToolbar::~TextSelectionToolbar()
203 } // namespace Internal
205 } // namespace Toolkit