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/control-depth-index-ranges.h>
23 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/public-api/math/vector2.h>
28 #include <dali/public-api/math/vector4.h>
29 #include <dali/devel-api/object/type-registry-helper.h>
43 const Dali::Vector2 DEFAULT_MAX_SIZE( 400.0f, 65.0f ); ///< The maximum size of the Toolbar.
47 return Toolkit::TextSelectionToolbar::New();
50 // Setup properties, signals and actions using the type-registry.
52 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextSelectionToolbar, Toolkit::Control, Create );
54 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionToolbar, "max-size", VECTOR2, MAX_SIZE )
55 DALI_PROPERTY_REGISTRATION( Toolkit, TextSelectionToolbar, "enable-overshoot", BOOLEAN, ENABLE_OVERSHOOT )
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 >() );
91 case Toolkit::TextSelectionToolbar::Property::ENABLE_OVERSHOOT:
93 impl.mScrollView.SetOvershootEnabled( value.Get< bool >() );
97 } // TextSelectionToolbar
100 Property::Value TextSelectionToolbar::GetProperty( BaseObject* object, Property::Index index )
102 Property::Value value;
104 Toolkit::TextSelectionToolbar selectionPopup = Toolkit::TextSelectionToolbar::DownCast( Dali::BaseHandle( object ) );
108 TextSelectionToolbar& impl( GetImpl( selectionPopup ) );
112 case Toolkit::TextSelectionToolbar::Property::MAX_SIZE:
114 value = impl.GetPopupMaxSize();
117 case Toolkit::TextSelectionToolbar::Property::ENABLE_OVERSHOOT:
119 value = impl.mScrollView.IsOvershootEnabled();
127 void TextSelectionToolbar::OnInitialize()
132 void TextSelectionToolbar::OnRelayout( const Vector2& size, RelayoutContainer& container )
134 float width = std::max ( mTableOfButtons.GetNaturalSize().width, size.width );
135 mRulerX->SetDomain( RulerDomain( 0.0, width, true ) );
136 mScrollView.SetRulerX( mRulerX );
139 void TextSelectionToolbar::OnStageConnection( int depth )
141 // Call the Control::OnStageConnection() to set the depth of the background.
142 Control::OnStageConnection( depth );
144 // Traverse the dividers and set the depth.
145 for( unsigned int i = 0; i < mDividerIndexes.Count(); ++i )
147 Actor divider = mTableOfButtons.GetChildAt( Toolkit::TableView::CellPosition( 0, mDividerIndexes[ i ] ) );
149 ImageActor dividerImageActor = ImageActor::DownCast( divider );
150 if( dividerImageActor )
152 dividerImageActor.SetSortModifier( DECORATION_DEPTH_INDEX + depth );
156 // TODO at the moment divider are image actors.
160 // Texts are controls, they have their own OnStageConnection() implementation.
161 // Icons are inside a TableView. It has it's own OnStageConnection() implementation.
164 void TextSelectionToolbar::SetPopupMaxSize( const Size& maxSize )
167 if (mScrollView && mStencilLayer )
169 mScrollView.SetMaximumSize( mMaxSize );
170 mStencilLayer.SetMaximumSize( mMaxSize );
174 const Dali::Vector2& TextSelectionToolbar::GetPopupMaxSize() const
179 void TextSelectionToolbar::SetUpScrollView()
181 mScrollView.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
182 mScrollView.SetParentOrigin( ParentOrigin::CENTER_LEFT );
183 mScrollView.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
185 mScrollView.SetScrollingDirection( PanGestureDetector::DIRECTION_HORIZONTAL, Degree( 40.0f ) );
186 mScrollView.SetAxisAutoLock( true );
187 mScrollView.ScrollStartedSignal().Connect( this, &TextSelectionToolbar::OnScrollStarted );
188 mScrollView.ScrollCompletedSignal().Connect( this, &TextSelectionToolbar::OnScrollCompleted );
190 mRulerX = new DefaultRuler(); // IntrusivePtr which is unreferenced when ScrollView is destroyed.
192 RulerPtr rulerY = new DefaultRuler(); // IntrusivePtr which is unreferenced when ScrollView is destroyed.
194 mScrollView.SetRulerY( rulerY );
196 mScrollView.SetOvershootEnabled( true );
199 void TextSelectionToolbar::SetUp()
202 self.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
204 // Create Layer and Stencil. Layer enable's clipping when content exceed maximum defined width.
205 mStencilLayer = Layer::New();
206 mStencilLayer.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
207 mStencilLayer.SetParentOrigin( ParentOrigin::CENTER );
209 ImageActor stencil = CreateSolidColorActor( Color::RED );
210 stencil.SetDrawMode( DrawMode::STENCIL );
211 stencil.SetVisible( true );
212 stencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
213 stencil.SetParentOrigin( ParentOrigin::CENTER );
215 mScrollView = Toolkit::ScrollView::New();
218 // Toolbar must start with at least one option, adding further options with increase it's size
219 mTableOfButtons = Dali::Toolkit::TableView::New( 1, 1 );
220 mTableOfButtons.SetFitHeight( 0 );
221 mTableOfButtons.SetParentOrigin( ParentOrigin::CENTER_LEFT );
222 mTableOfButtons.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
225 mStencilLayer.Add( stencil );
226 mStencilLayer.Add( mScrollView );
227 mScrollView.Add( mTableOfButtons );
228 self.Add( mStencilLayer );
231 void TextSelectionToolbar::OnScrollStarted( const Vector2& position )
233 mTableOfButtons.SetSensitive( false );
236 void TextSelectionToolbar::OnScrollCompleted( const Vector2& position )
238 mTableOfButtons.SetSensitive( true );
241 void TextSelectionToolbar::AddOption( Actor& option )
243 mTableOfButtons.AddChild( option, Toolkit::TableView::CellPosition( 0, mIndexInTable ) );
244 mTableOfButtons.SetFitWidth( mIndexInTable );
248 void TextSelectionToolbar::AddDivider( Actor& divider )
250 AddOption( divider );
251 mDividerIndexes.PushBack( mIndexInTable - 1u );
254 void TextSelectionToolbar::ResizeDividers( Size& size )
256 for( unsigned int i = 0; i < mDividerIndexes.Count(); ++i )
258 Actor divider = mTableOfButtons.GetChildAt( Toolkit::TableView::CellPosition( 0, mDividerIndexes[ i ] ) );
259 divider.SetSize( size );
264 void TextSelectionToolbar::RaiseAbove( Layer target )
266 mStencilLayer.RaiseAbove( target );
269 TextSelectionToolbar::TextSelectionToolbar()
270 : Control( ControlBehaviour( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ) ),
277 TextSelectionToolbar::~TextSelectionToolbar()
282 } // namespace Internal
284 } // namespace Toolkit