+ State mState; ///< Selection mode, edit mode etc.
+
+ CharacterIndex mPrimaryCursorPosition; ///< Index into logical model for primary cursor
+ CharacterIndex mSecondaryCursorPosition; ///< Index into logical model for secondary cursor
+
+ /**
+ * 0,0 means that the top-left corner of the layout matches the top-left corner of the UI control.
+ * Typically this will have a negative value with scrolling occurs.
+ */
+ Vector2 mScrollPosition; ///< The text is offset by this position when scrolling.
+
+ bool mDecoratorUpdated : 1; ///< True if the decorator was updated during event processing
+ bool mCursorBlinkEnabled : 1; ///< True if cursor should blink when active
+ bool mGrabHandleEnabled : 1; ///< True if grab handle is enabled
+ bool mGrabHandlePopupEnabled : 1; ///< True if the grab handle popu-up should be shown
+ bool mSelectionEnabled : 1; ///< True if selection handles, highlight etc. are enabled
+ bool mHorizontalScrollingEnabled : 1; ///< True if horizontal scrolling is enabled
+ bool mVerticalScrollingEnabled : 1; ///< True if vertical scrolling is enabled
+ bool mUpdateCursorPosition : 1; ///< True if the visual position of the cursor must be recalculated
+};
+
+struct Controller::Impl
+{
+ Impl( ControlInterface& controlInterface )
+ : mControlInterface( controlInterface ),
+ mLogicalModel(),
+ mVisualModel(),
+ mFontDefaults( NULL ),
+ mTextInput( NULL ),
+ mFontClient(),
+ mView(),
+ mLayoutEngine(),
+ mModifyEvents(),
+ mControlSize(),
+ mAlignmentOffset(),
+ mOperationsPending( NO_OPERATION ),
+ mRecalculateNaturalSize( true )
+ {
+ mLogicalModel = LogicalModel::New();
+ mVisualModel = VisualModel::New();
+
+ mFontClient = TextAbstraction::FontClient::Get();
+
+ mView.SetVisualModel( mVisualModel );
+
+ // Set the text properties to default
+ mVisualModel->SetTextColor( Color::WHITE );
+ mVisualModel->SetShadowOffset( Vector2::ZERO );
+ mVisualModel->SetShadowColor( Vector4::ZERO );
+ mVisualModel->SetUnderlineEnabled( false );
+ }
+
+ ~Impl()
+ {
+ delete mTextInput;
+ }
+
+ ControlInterface& mControlInterface; ///< Reference to the text controller.
+ LogicalModelPtr mLogicalModel; ///< Pointer to the logical model.
+ VisualModelPtr mVisualModel; ///< Pointer to the visual model.
+ FontDefaults* mFontDefaults; ///< Avoid allocating this when the user does not specify a font.
+ Controller::TextInput* mTextInput; ///< Avoid allocating everything for text input until EnableTextInput().
+ TextAbstraction::FontClient mFontClient; ///< Handle to the font client.
+ View mView; ///< The view interface to the rendering back-end.
+ LayoutEngine mLayoutEngine; ///< The layout engine.
+ std::vector<ModifyEvent> mModifyEvents; ///< Temporary stores the text set until the next relayout.
+ Size mControlSize; ///< The size of the control.
+ Vector2 mAlignmentOffset; ///< Vertical and horizontal offset of the whole text inside the control due to alignment.
+ OperationsMask mOperationsPending; ///< Operations pending to be done to layout the text.
+ bool mRecalculateNaturalSize:1; ///< Whether the natural size needs to be recalculated.
+};
+
+ControllerPtr Controller::New( ControlInterface& controlInterface )
+{
+ return ControllerPtr( new Controller( controlInterface ) );
+}
+
+void Controller::SetText( const std::string& text )
+{
+ // Cancel previously queued inserts etc.
+ mImpl->mModifyEvents.clear();
+
+ // Keep until size negotiation
+ ModifyEvent event;
+ event.type = REPLACE_TEXT;
+ event.text = text;
+ mImpl->mModifyEvents.push_back( event );
+
+ if( mImpl->mTextInput )
+ {
+ // Cancel previously queued events
+ mImpl->mTextInput->mEventQueue.clear();
+
+ // TODO - Hide selection decorations
+ }
+}
+
+void Controller::GetText( std::string& text ) const
+{
+ if( !mImpl->mModifyEvents.empty() &&
+ REPLACE_TEXT == mImpl->mModifyEvents[0].type )
+ {
+ text = mImpl->mModifyEvents[0].text;
+ }
+ else
+ {
+ // TODO - Convert from UTF-32
+ }
+}
+
+void Controller::SetPlaceholderText( const std::string& text )
+{
+ if( !mImpl->mTextInput )
+ {
+ mImpl->mTextInput->mPlaceholderText = text;
+ }
+}
+
+void Controller::GetPlaceholderText( std::string& text ) const
+{
+ if( !mImpl->mTextInput )
+ {
+ text = mImpl->mTextInput->mPlaceholderText;
+ }
+}
+
+void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily )
+{
+ if( !mImpl->mFontDefaults )
+ {
+ mImpl->mFontDefaults = new Controller::FontDefaults();
+ }
+
+ mImpl->mFontDefaults->mDefaultFontFamily = defaultFontFamily;
+ mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+ mImpl->mRecalculateNaturalSize = true;
+
+ // Clear the font-specific data
+ mImpl->mLogicalModel->mFontRuns.Clear();
+ mImpl->mVisualModel->mGlyphs.Clear();
+ mImpl->mVisualModel->mGlyphsToCharacters.Clear();
+ mImpl->mVisualModel->mCharactersToGlyph.Clear();
+ mImpl->mVisualModel->mCharactersPerGlyph.Clear();
+ mImpl->mVisualModel->mGlyphsPerCharacter.Clear();
+ mImpl->mVisualModel->mGlyphPositions.Clear();
+ mImpl->mVisualModel->mLines.Clear();
+ mImpl->mVisualModel->ClearCaches();
+
+ RequestRelayout();
+}
+
+const std::string& Controller::GetDefaultFontFamily() const
+{
+ if( mImpl->mFontDefaults )
+ {
+ return mImpl->mFontDefaults->mDefaultFontFamily;
+ }
+
+ return String::EMPTY;;
+}
+
+void Controller::SetDefaultFontStyle( const std::string& defaultFontStyle )
+{
+ if( !mImpl->mFontDefaults )
+ {
+ mImpl->mFontDefaults = new Controller::FontDefaults();
+ }
+
+ mImpl->mFontDefaults->mDefaultFontStyle = defaultFontStyle;
+ mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+ mImpl->mRecalculateNaturalSize = true;
+
+ // Clear the font-specific data
+ mImpl->mLogicalModel->mFontRuns.Clear();
+ mImpl->mVisualModel->mGlyphs.Clear();
+ mImpl->mVisualModel->mGlyphsToCharacters.Clear();
+ mImpl->mVisualModel->mCharactersToGlyph.Clear();
+ mImpl->mVisualModel->mCharactersPerGlyph.Clear();
+ mImpl->mVisualModel->mGlyphsPerCharacter.Clear();
+ mImpl->mVisualModel->mGlyphPositions.Clear();
+ mImpl->mVisualModel->mLines.Clear();
+ mImpl->mVisualModel->ClearCaches();
+
+ RequestRelayout();
+}
+
+const std::string& Controller::GetDefaultFontStyle() const
+{
+ if( mImpl->mFontDefaults )
+ {
+ return mImpl->mFontDefaults->mDefaultFontStyle;
+ }
+
+ return String::EMPTY;
+}