#include <dali-toolkit/public-api/text/logical-model.h>
#include <dali-toolkit/public-api/text/multi-language-support.h>
#include <dali-toolkit/public-api/text/script-run.h>
+#include <dali-toolkit/public-api/text/segmentation.h>
#include <dali-toolkit/public-api/text/shaper.h>
#include <dali-toolkit/public-api/text/text-view.h>
#include <dali-toolkit/public-api/text/visual-model.h>
namespace Text
{
+struct Controller::TextInput
+{
+ // Used to queue input events until DoRelayout()
+ enum EventType
+ {
+ KEYBOARD_FOCUS_GAIN_EVENT,
+ KEYBOARD_FOCUS_LOST_EVENT,
+ TAP_EVENT,
+ GRAB_HANDLE_EVENT
+ };
+
+ union Param
+ {
+ int mInt;
+ float mFloat;
+ };
+
+ struct Event
+ {
+ Event( EventType eventType )
+ : type( eventType )
+ {
+ p1.mInt = 0;
+ p2.mInt = 0;
+ }
+
+ EventType type;
+ Param p1;
+ Param p2;
+ };
+
+ TextInput( DecoratorPtr decorator )
+ : mDecorator( decorator )
+ {
+ }
+
+ DecoratorPtr mDecorator;
+
+ std::vector<Event> mEventQueue;
+};
+
struct Controller::Impl
{
- Impl()
- : mNewText(),
- mOperations( NO_OPERATION )
+ Impl( ControlInterface& controlInterface )
+ : mControlInterface( controlInterface ),
+ mNewText(),
+ mOperations( NO_OPERATION ),
+ mControlSize(),
+ mTextInput( NULL )
{
mLogicalModel = LogicalModel::New();
mVisualModel = VisualModel::New();
mFontClient = TextAbstraction::FontClient::Get();
}
+ ~Impl()
+ {
+ delete mTextInput;
+ }
+
+ ControlInterface& mControlInterface;
+
std::string mNewText;
LogicalModelPtr mLogicalModel;
TextAbstraction::FontClient mFontClient;
OperationsMask mOperations;
+
+ Size mControlSize;
+
+ // Avoid allocating everything for text input until EnableTextInput()
+ Controller::TextInput* mTextInput;
};
-ControllerPtr Controller::New()
+ControllerPtr Controller::New( ControlInterface& controlInterface )
{
- return ControllerPtr( new Controller() );
+ return ControllerPtr( new Controller( controlInterface ) );
}
void Controller::SetText( const std::string& text )
// Keep until size negotiation
mImpl->mNewText = text;
mImpl->mOperations = ALL_OPERATIONS;
+
+ if( mImpl->mTextInput )
+ {
+ // Cancel previously queued events
+ mImpl->mTextInput->mEventQueue.clear();
+
+ // TODO - Hide selection decorations
+ }
+}
+
+void Controller::EnableTextInput( DecoratorPtr decorator )
+{
+ if( !mImpl->mTextInput )
+ {
+ mImpl->mTextInput = new TextInput( decorator );
+ }
}
bool Controller::Relayout( const Vector2& size )
bool viewUpdated = false;
- if( size != mControlSize )
+ if( size != mImpl->mControlSize )
{
viewUpdated = DoRelayout( size, mImpl->mOperations );
// Do not re-do any operation until something changes.
mImpl->mOperations = NO_OPERATION;
- mControlSize = size;
+ mImpl->mControlSize = size;
}
return viewUpdated;
text.clear();
}
+ Vector<LineBreakInfo> lineBreakInfo;
+ if( GET_LINE_BREAKS & operations )
+ {
+ // Retrieves the line break info. The line break info is used to split the text in 'paragraphs' to
+ // calculate the bidirectional info for each 'paragraph'.
+ // It's also used to layout the text (where it should be a new line) or to shape the text (text in different lines
+ // is not shaped together).
+ lineBreakInfo.Resize( characterCount, TextAbstraction::LINE_NO_BREAK );
+
+ SetLineBreakInfo( utf32Characters,
+ lineBreakInfo );
+
+ mImpl->mLogicalModel->SetLineBreakInfo( lineBreakInfo.Begin(), characterCount );
+ }
+
const bool getScripts = GET_SCRIPTS & operations;
const bool validateFonts = VALIDATE_FONTS & operations;
{
// Retrieves the scripts used in the text.
multilanguageSupport.SetScripts( utf32Characters,
+ lineBreakInfo,
scripts );
// Sets the scripts into the model.
}
}
- Vector<LineBreakInfo> lineBreakInfo;
- if( GET_LINE_BREAKS & operations )
- {
- // Retrieves the line break info. The line break info is used to split the text in 'paragraphs' to
- // calculate the bidirectional info for each 'paragraph'.
- // It's also used to layout the text (where it should be a new line) or to shape the text (text in different lines
- // is not shaped together).
- lineBreakInfo.Resize( characterCount, TextAbstraction::LINE_NO_BREAK );
- mImpl->mLogicalModel->SetLineBreakInfo( lineBreakInfo.Begin(), characterCount );
- }
-
Vector<GlyphInfo> glyphs;
Vector<CharacterIndex> characterIndices;
Vector<Length> charactersPerGlyph;
mImpl->mVisualModel->GetGlyphs( glyphs.Begin(),
0u,
numberOfGlyphs );
-
+
mImpl->mVisualModel->GetGlyphToCharacterMap( characterIndices.Begin(),
0u,
numberOfGlyphs );
viewUpdated = true;
}
+ // TODO - process input events to move grab handle
+
return viewUpdated;
}
return mImpl->mLayoutEngine;
}
+void Controller::RequestRelayout()
+{
+ mImpl->mControlInterface.RequestTextRelayout();
+}
+
+void Controller::KeyboardFocusGainEvent()
+{
+ DALI_ASSERT_DEBUG( mImpl->mTextInput && "Unexpected KeyboardFocusGainEvent" );
+
+ if( mImpl->mTextInput )
+ {
+ TextInput::Event event( TextInput::KEYBOARD_FOCUS_GAIN_EVENT );
+ mImpl->mTextInput->mEventQueue.push_back( event );
+
+ RequestRelayout();
+ }
+}
+
+void Controller::KeyboardFocusLostEvent()
+{
+ DALI_ASSERT_DEBUG( mImpl->mTextInput && "Unexpected KeyboardFocusLostEvent" );
+
+ if( mImpl->mTextInput )
+ {
+ TextInput::Event event( TextInput::KEYBOARD_FOCUS_LOST_EVENT );
+ mImpl->mTextInput->mEventQueue.push_back( event );
+
+ RequestRelayout();
+ }
+}
+
+void Controller::TapEvent( float x, float y)
+{
+ DALI_ASSERT_DEBUG( mImpl->mTextInput && "Unexpected TapEvent" );
+
+ if( mImpl->mTextInput )
+ {
+ TextInput::Event event( TextInput::TAP_EVENT );
+ event.p1.mFloat = x;
+ event.p2.mFloat = y;
+
+ RequestRelayout();
+ }
+}
+
+void Controller::GrabHandleEvent( GrabHandleState state, float x )
+{
+ DALI_ASSERT_DEBUG( mImpl->mTextInput && "Unexpected GrabHandleEvent" );
+
+ if( mImpl->mTextInput )
+ {
+ TextInput::Event event( TextInput::GRAB_HANDLE_EVENT );
+ event.p1.mInt = state;
+ event.p2.mFloat = x;
+
+ RequestRelayout();
+ }
+}
+
Controller::~Controller()
{
delete mImpl;
}
-Controller::Controller()
-: mImpl( NULL ),
- mControlSize()
+Controller::Controller( ControlInterface& controlInterface )
+: mImpl( NULL )
{
- mImpl = new Controller::Impl();
+ mImpl = new Controller::Impl( controlInterface );
}
} // namespace Text