New size negotiation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-view / text-view-impl.h
index 7493fcc..270d32b 100644 (file)
@@ -1,30 +1,35 @@
 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_H__
 #define __DALI_TOOLKIT_INTERNAL_TEXT_VIEW_H__
 
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
-// INTERNAL INCLUDES
-#include <dali/public-api/common/dali-vector.h>
+// EXTERNAL INCLUDES
+#include <dali/public-api/actors/camera-actor.h>
+#include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/actors/layer.h>
+#include <dali/public-api/images/glyph-image.h>
+#include <dali/public-api/render-tasks/render-task.h>
 
-#include <dali/public-api/actors/text-actor.h>
+// INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
-#include "text-actor-cache.h"
-#include "text-view-processor-types.h"
+#include <dali-toolkit/internal/controls/text-view/text-actor-cache.h>
+#include <dali-toolkit/internal/controls/text-view/text-view-processor-types.h>
 
 namespace Dali
 {
@@ -38,7 +43,7 @@ namespace Internal
 /**
  * TextView is a custom control for text aligning and multiline support
  */
-class TextView : public ControlImpl
+class TextView : public Control
 {
 public:
 
@@ -53,6 +58,7 @@ public:
     SplitOriginal,        ///< Split if it exceeds the width but no action if it exceeds the height.
     SplitFade,            ///< Split if it exceeds the width and faded if it exceeds the height.
     SplitShrink,          ///< Split if it exceeds the width and shrunk if it exceeds the height.
+    SplitEllipsizeEnd,    ///< Split if it exceeds the width and ellipsize if it exceeds the height.
     Fade,                 ///< Faded if it exceeds any boundary.
     FadeOriginal,         ///< Faded if it exceeds the width but no action if it exceeds the height.
     ShrinkOriginal,       ///< Shrunk if it exceeds the width but no action if it exceeds the height.
@@ -62,8 +68,8 @@ public:
     EllipsizeEnd          ///< Ellipsized by the end if it exceeds the width and/or the height.
   };
 
-  // Between two OnRelaidOut methods, several calls to InsertTextAt, RemoveTextFrom or SetText can happen.
-  // TextViewProcessorMetadata stores the type of operation. A vector stores all operations between two OnRelaidOut calls.
+  // Between two OnRelayout methods, several calls to InsertTextAt, RemoveTextFrom or SetText can happen.
+  // TextViewProcessorMetadata stores the type of operation. A vector stores all operations between two OnRelayout calls.
 
   enum TextViewProcessorMetadataType
   {
@@ -76,7 +82,7 @@ public:
   };
 
   /**
-   * Stores info about which data structures need to be modified when the OnRelaidOut() method is called
+   * Stores info about which data structures need to be modified when the OnRelayout() method is called
    */
   struct TextViewProcessorMetadata
   {
@@ -84,7 +90,7 @@ public:
 
     TextViewProcessorMetadataType    mType;               ///< Stores the type of operation.
     std::size_t                      mPosition;           ///< Character position within the text.
-    std::size_t                      mNumberOfCharacters; ///< Number of characters to be removed/ replaced.
+    std::size_t                      mNumberOfCharacters; ///< Number of characters to be removed/replaced.
     MarkupProcessor::StyledTextArray mText;               ///< The new text.
     TextStyle::Mask                  mStyleMask;          ///< The style mask.
   };
@@ -102,7 +108,6 @@ public:
     RELAYOUT_INITIALIZE_TEXT_ACTORS = 0x10,    ///< Initialize text-actors (create handles).
     RELAYOUT_TEXT_ACTOR_UPDATE = 0x20,         ///< Updates text-actors (set size, position, style, ...)
     RELAYOUT_INSERT_TO_TEXT_VIEW = 0x40,       ///< Adds the text-actors to the text-view.
-    RELAYOUT_INSERT_TO_TEXT_ACTOR_LIST = 0x80, ///< Inserts the text-actors to the text-actor list.
     RELAYOUT_ALL = 0xFF                        ///< Does all operations.
   };
 
@@ -155,11 +160,6 @@ public:
   std::string GetText() const;
 
   /**
-   * @copydoc SetFont( const Font newFont )
-   */
-  void SetFont( const Font newFont );
-
-  /**
    * @copydoc SetLineHeightOffset()
    */
   void SetLineHeightOffset( PointSize offset );
@@ -245,6 +245,11 @@ public:
   void SetEllipsizeText( const MarkupProcessor::StyledTextArray& ellipsizeText );
 
   /**
+   * @copydoc SetEllipsizeText()
+   */
+  void SetEllipsizeText( const Text& ellipsizeText, const Vector<TextStyle*>& ellipsizeStyles );
+
+  /**
    * @copydoc GetEllipsizeText()
    */
   std::string GetEllipsizeText() const;
@@ -320,7 +325,7 @@ public:
   /**
    * @copydoc ScrolledSignal()
    */
-  Toolkit::TextView::ScrolledSignalV2& ScrolledSignal();
+  Toolkit::TextView::ScrolledSignalType& ScrolledSignal();
 
   /**
    * Connects a callback function with the object's signals.
@@ -333,7 +338,26 @@ public:
    */
   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
 
-private: // From ControlImpl
+  // Properties
+
+  /**
+   * Called when a property of an object of this type is set.
+   * @param[in] object The object whose property is set.
+   * @param[in] index The property index.
+   * @param[in] value The new property value.
+   */
+  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
+
+  /**
+   * Called to retrieve a property of an object of this type.
+   * @param[in] object The object whose property is to be retrieved.
+   * @param[in] index The property index.
+   * @return The current value of the property.
+   */
+  static Property::Value GetProperty( BaseObject* object, Property::Index index );
+
+
+private: // From Control
 
   /**
    * @copydoc Toolkit::Control::OnInitialize()
@@ -341,9 +365,9 @@ private: // From ControlImpl
   virtual void OnInitialize();
 
   /**
-   * @copydoc Toolkit::Control::OnStyleChange()
+   * @copydoc Toolkit::Control::OnFontChange( )
    */
-  virtual void OnStyleChange( StyleChange change );
+  virtual void OnFontChange( bool defaultFontChange, bool defaultFontSizeChange );
 
   /**
    * @copydoc Toolkit::Control::OnControlSizeSet()
@@ -351,11 +375,9 @@ private: // From ControlImpl
   virtual void OnControlSizeSet( const Vector3& size );
 
   /**
-   * @copydoc Toolkit::Control::OnRelaidOut()
-   *
-   * Removes text-actor and calls DoRelayOut()..
+   * @copydoc Toolkit::Control::OnRelayout()
    */
-  virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
+  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
 
   /**
    * Retrieves the text-view's natural size.
@@ -382,11 +404,6 @@ private: // From ControlImpl
    */
   virtual float GetWidthForHeight( float height );
 
-  /**
-   * @copydoc Dali::CustomActorImpl::OnPropertySet()
-   */
-  virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
-
 protected:
 
   /**
@@ -408,8 +425,7 @@ private:
   TextView& operator=( const TextView& rhs );
 
   /**
-   * Executes synchronously relayout operations such as set, insert, remove or replace text, or
-   * split groups of characters, etc.
+   * Executes synchronously relayout operations such as set, insert, remove or replace text, etc.
    */
   void PerformTextViewProcessorOperations();
 
@@ -431,7 +447,7 @@ private:
   /**
    * Process Snapshot. It refresh the render-task in order to generate a new snapshot image.
    *
-   * ProcessSnapshot is called from OnRelaidOut() only if text has been relaid out.
+   * ProcessSnapshot is called from OnRelayout() only if text has been relaid out.
    * It creates a new image buffer only if the size of the text has changed.
    *
    * @param[in] textViewSize The new text-view's size.
@@ -472,7 +488,7 @@ private:
    * @param[in] actor Handle of the text-view.
    * @param[in] gesture Data structure with the parameters of the gesture.
    */
-  void OnTextPan( Actor actor, PanGesture gesture );
+  void OnTextPan( Actor actor, const PanGesture& gesture );
 
   /**
    * Ensures the text-view's boundaries are fully covered of text.
@@ -511,43 +527,65 @@ private:
   Actor GetRootActor() const;
 
   /**
+   * Creates the ellipsize text layout.
+   */
+  void CreateEllipsizeLayout();
+
+  /**
+   * Handle SetProperty for markup processing.
+   * @param[in] propertyValue The new property value.
+   */
+  void OnMarkupEnabledPeopertySet( Property::Value propertyValue );
+
+  /**
    * Handles SetProperty for multiline policy.
    * @param[in] propertyValue The new property value.
-  */
+   */
   void OnMultilinePolicyPropertySet( Property::Value propertyValue );
 
   /**
    * Handles SetProperty for width exceed policy.
    * @param[in] propertyValue The new property value.
-  */
+   */
   void OnWidthExceedPolicyPropertySet( Property::Value propertyValue );
 
   /**
    * Handles SetProperty for height exceed policy.
    * @param[in] propertyValue The new property value.
-  */
+   */
   void OnHeightExceedPolicyPropertySet( Property::Value propertyValue );
 
   /**
    * Handles SetProperty for line justification.
    * @param[in] propertyValue The new property value.
-  */
+   */
   void OnLineJustificationPropertySet( Property::Value propertyValue );
 
   /**
    * Handles SetProperty for fade boundary.
-   * @param[in] propertyIndex The property index.
    * @param[in] propertyValue The new property value.
-  */
-  void OnFadeBoundaryPropertySet( Property::Index propertyIndex, Property::Value propertyValue );
+   */
+  void OnFadeBoundaryPropertySet( Property::Value propertyValue );
 
   /**
    * Handles SetProperty for alignment property.
    * @param[in] propertyIndex The property index.
    * @param[in] propertyValue The new property value.
-  */
+   */
   void OnAlignmentPropertySet( Property::Index propertyIndex, Property::Value propertyValue );
 
+  /**
+   * Handles GetProperty for horizontal alignment property.
+   * @return The property value of horizontal alignment.
+   */
+  std::string OnHorizontalAlignmentPropertyGet();
+
+  /**
+   * Handles GetProperty for vertical alignment property.
+   * @return The property value of vertical alignment.
+   */
+  std::string OnVerticalAlignmentPropertyGet();
+
 public:
 
   /**
@@ -561,6 +599,11 @@ public:
     LayoutParameters();
 
     /**
+     * Default destructor.
+     */
+    ~LayoutParameters();
+
+    /**
      * Constructor
      */
     LayoutParameters( Toolkit::TextView::MultilinePolicy     multilinePolicy,
@@ -569,8 +612,7 @@ public:
                       Toolkit::Alignment::Type               alignment,
                       Toolkit::TextView::LineJustification   lineJustification,
                       float                                  lineHeightOffset,
-                      const std::string&                     ellipsizeText,
-                      const bool                             markUpEnabled );
+                      bool                                   markUpEnabled );
 
     /**
      * Copy constructor
@@ -583,15 +625,14 @@ public:
     LayoutParameters& operator=( const LayoutParameters& layoutParameters );
 
     Toolkit::TextView::MultilinePolicy   mMultilinePolicy;     ///< Stores the multiline policy.
-    TextView::ExceedPolicy               mExceedPolicy;        ///< Stores a combination of both policies;
+    TextView::ExceedPolicy               mExceedPolicy;        ///< Stores a combination of both policies.
     Toolkit::TextView::ExceedPolicy      mWidthExceedPolicy;   ///< Stores the text width exceed policy.
     Toolkit::TextView::ExceedPolicy      mHeightExceedPolicy;  ///< Stores the text height exceed policy.
     Toolkit::Alignment::Type             mHorizontalAlignment; ///< Stores the horizontal alignment for the whole text.
     Toolkit::Alignment::Type             mVerticalAlignment;   ///< Stores the vertical alignment for the whole text.
     Toolkit::TextView::LineJustification mLineJustification;   ///< Stores the line justification.
     float                                mLineHeightOffset;    ///< Line height offset to be addded to the font line height (measured in PointSize).
-    MarkupProcessor::StyledTextArray     mEllipsizeText;       ///< Stores the ellipsize text
-    bool                                 mMarkUpEnabled:1;     ///< Is markup string scanning enabled
+    bool                                 mMarkUpEnabled:1;     ///< Is markup string scanning enabled.
   };
 
   /**
@@ -623,15 +664,6 @@ public:
   };
 
   /**
-   * Temporary data used to calculate line justification.
-   */
-  struct LineJustificationInfo
-  {
-    TextViewProcessor::TextInfoIndices mIndices;    ///< Indices to the first character of the new line.
-    float                              mLineLength; ///< Length of the line (or portion of line).
-  };
-
-  /**
    * The results of the relayout process.
    */
   struct RelayoutData
@@ -661,14 +693,13 @@ public:
     Toolkit::TextView::CharacterLayoutInfoContainer mCharacterLayoutInfoTable;    ///< Stores layout info per character sorted by the character's visual index.
     Toolkit::TextView::LineLayoutInfoContainer      mLines;                       ///< Stores an index to the first character of each line.
     Size                                            mTextSizeForRelayoutOption;   ///< Stores the text size after relayout.
-    std::vector<LineJustificationInfo>              mLineJustificationInfo;       ///< Stores justification info per line.
     TextActorCache                                  mTextActorCache;              ///< Stores previously created text-actors to be reused.
   };
 
 private:
 
   MarkupProcessor::StyledTextArray       mCurrentStyledText;           ///< text currently displayed by the view
-  std::vector<TextViewProcessorMetadata> mTextViewProcessorOperations; ///< Stores all relayout operations which arrive between two consecutive OnRelaidOut() calls.
+  std::vector<TextViewProcessorMetadata> mTextViewProcessorOperations; ///< Stores all relayout operations which arrive between two consecutive OnRelayout() calls.
 
   LayoutParameters                       mLayoutParameters;            ///< Stores some layout parameters in a struct. To be passed in layout functions.
   VisualParameters                       mVisualParameters;            ///< Some parameters which afects text-view visualization.
@@ -707,20 +738,7 @@ private:
   bool                                            mPreviousSnapshotModeEnabled:1; ///< Stores the previous snapshot mode value.
   bool                                            mMarkUpEnabled:1;               ///< enable to scan for mark-up
 
-  Toolkit::TextView::ScrolledSignalV2             mScrolledSignalV2;              ///< Signal emitted when text is scrolled.
-
-  Property::Index                                 mPropertyText;                  ///< Property index for text.
-  Property::Index                                 mPropertyMultilinePolicy;       ///< Property index for multiline policy.
-  Property::Index                                 mPropertyWidthExceedPolicy;     ///< Property index for width exceed policy.
-  Property::Index                                 mPropertyHeightExceedPolicy;    ///< Property index for height exceed policy.
-  Property::Index                                 mPropertyLineJustification;     ///< Property index for line justification policy.
-  Property::Index                                 mPropertyFadeBoundaryLeft;      ///< Property index for Left fade boundary.
-  Property::Index                                 mPropertyFadeBoundaryRight;     ///< Property index for Right fade boundary.
-  Property::Index                                 mPropertyFadeBoundaryTop;       ///< Property index for Top fade boundary.
-  Property::Index                                 mPropertyFadeBoundaryBottom;    ///< Property index for Bottom fade boundary.
-  Property::Index                                 mPropertyLineHeightOffset;      ///< Property index for Line height offset.
-  Property::Index                                 mPropertyHorizontalAlignment;   ///< Property index for Horizontal alignment.
-  Property::Index                                 mPropertyVerticalAlignment;     ///< Property index for Vertical alignment.
+  Toolkit::TextView::ScrolledSignalType             mScrolledSignal;              ///< Signal emitted when text is scrolled.
 };
 
 } // namespace Internal