Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / slider / slider-impl.h
index d97da67..707bac8 100755 (executable)
@@ -1,21 +1,22 @@
 #ifndef __DALI_TOOLKIT_INTERNAL_SLIDER_H__
 #define __DALI_TOOLKIT_INTERNAL_SLIDER_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/dali.h>
@@ -41,10 +42,17 @@ typedef Dali::IntrusivePtr< Slider > SliderPtr;
 /**
  * @copydoc Toolkit::Slider
  */
-class Slider : public ControlImpl
+class Slider : public Control
 {
 public:
 
+  // Properties
+  enum
+  {
+    SLIDER_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
+    SLIDER_PROPERTY_END_INDEX = SLIDER_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
+  };
+
   typedef Property::Array MarkList;
 
   /**
@@ -112,7 +120,7 @@ public:
    *
    * @return The hit region
    */
-  Vector2 GetHitRegion() const;
+  const Vector2& GetHitRegion() const;
 
   /**
    * Set backing region
@@ -126,24 +134,17 @@ public:
    *
    * @return The backing region
    */
-  Vector2 GetBackingRegion() const;
+  const Vector2& GetBackingRegion() const;
 
   /**
-   * Get backing scale9 border
+   * @brief Set the disable color.
    *
-   * @return The backing scale9 border
+   * @param[in] color The disable color.
    */
-  Vector4 GetBackingScale9Border() const;
+  void SetDisableColor( const Vector4& color );
 
   /**
-   * Get popup scale9 border
-   *
-   * @return The popup scale9 border
-   */
-  Vector4 GetPopupScale9Border() const;
-
-  /**
-   * Get disable color
+   * @brief Get disable color
    *
    * @return The disable color
    */
@@ -157,6 +158,13 @@ public:
   Vector4 GetPopupTextColor() const;
 
   /**
+   * Set the value precision to be used for numbers in the slider
+   *
+   * @param[in] precision The number of decimal places to use for printing numbers
+   */
+  void SetValuePrecision( int precision );
+
+  /**
    * Get value precision
    *
    * @return The value precision
@@ -168,7 +176,7 @@ public:
    *
    * @param[in] showPopup The show popup flag
    */
-  void ShowPopup( bool showPopup );
+  void SetShowPopup( bool showPopup );
 
   /**
    * Get show value in popup
@@ -182,7 +190,7 @@ public:
    *
    * @param[in] showValue The show value flag
    */
-  void ShowValue( bool showValue );
+  void SetShowValue( bool showValue );
 
   /**
    * Get show value on handle
@@ -206,6 +214,16 @@ public:
   bool IsEnabled() const;
 
   /**
+   * @brief Set the mark tolerance
+   *
+   * The tolerance is the percentage of the slider width for which snapping to
+   * marks occurs
+   *
+   * @param[in] tolerance The percentage of width for which to snap
+   */
+  void SetMarkTolerance( float tolerance );
+
+  /**
    * Return the mark tolerance
    *
    * @return The tolerance set for snapping to marks
@@ -242,6 +260,24 @@ public:
   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
                                FunctorDelegate* functor );
 
+  // 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 propertyIndex );
+
 protected:
 
   /**
@@ -255,7 +291,7 @@ protected:
   virtual ~Slider();
 
   /**
-   * @copydoc Toolkit::ControlImpl::OnControlSizeSet( const Vector3& size )
+   * @copydoc Control::OnControlSizeSet( const Vector3& size )
    */
   virtual void OnControlSizeSet( const Vector3& size );
 
@@ -422,13 +458,6 @@ private:
   void CreateChildren();
 
   /**
-   * Resize the hit area
-   *
-   * @param[in] size The new size of the hit area
-   */
-  void ResizeHitRegion( const Vector2& size );
-
-  /**
    * Create value popup
    */
   void AddPopup();
@@ -490,63 +519,70 @@ private:
    *
    * @param[in] imageName The name of the image to load and set
    */
-  void CreateBackingImage( const std::string& imageName );
+  void SetBackingImageName( const std::string& imageName );
 
   /**
-   * Set the backing image to be a scale-9 image
+   * @brief Return the backing image file name.
    *
-   * @param[in] border The scale-9 border to use
+   * @return The backing image file name.
    */
-  void SetBackingScale9( const Vector4& border );
+  std::string GetBackingImageName();
 
   /**
-   * Resize the backing region
+   * Create the image for the progress bar
    *
-   * @param[in] region The size of the region to set
+   * @param[in] imageName The name of the image to load and set
    */
-  void ResizeBackingRegion( const Vector2& region );
+  void SetProgressImageName( const std::string& imageName );
 
   /**
-   * Size the backing region
+   * @brief Return the progress image name.
    *
-   * @param[in] region The size of the region to set
+   * @return The progress image name if it exists.
    */
-  void SetBackingRegionSize( const Vector2& region );
+  std::string GetProgressImageName();
 
   /**
-   * Create the image for the progress bar
+   * @brief Create the image for the popup
    *
    * @param[in] imageName The name of the image to load and set
    */
-  void CreateProgressImage( const std::string& imageName );
+  void CreatePopupImage( const std::string& imageName );
 
   /**
-   * Create the image for the popup
+   * @brief Set the popup name
    *
-   * @param[in] imageName The name of the image to load and set
+   * @param[in] imageName The name of the image to set
    */
-  void CreatePopupImage( const std::string& imageName );
+  void SetPopupImageName( const std::string& imageName );
 
   /**
-   * Create the image for the popup arrow
+   * @brief Return the popup image name.
    *
-   * @param[in] imageName The name of the image to load and set
+   * @return The name of the popup image if it exists.
    */
-  void CreatePopupArrowImage( const std::string& imageName );
+  std::string GetPopupImageName();
+
+  /**
+   * @brief Set the popup arrow image name
+   *
+   * @param[in] imageName The name of the image to set
+   */
+  void SetPopupArrowImageName( const std::string& imageName );
 
   /**
-   * Set the progress image to be a scale-9 image
+   * @brief Return the popup arrow image name.
    *
-   * @param[in] border The scale-9 border to use
+   * @return The name of the popup image if it exists.
    */
-  void SetProgressScale9( const Vector4& border );
+  std::string GetPopupArrowImageName();
 
   /**
-   * Set the popup image to be a scale-9 image
+   * Create the image for the popup arrow
    *
-   * @param[in] border The scale-9 border to use
+   * @param[in] imageName The name of the image to load and set
    */
-  void SetPopupScale9( const Vector4& border );
+  void CreatePopupArrowImage( const std::string& imageName );
 
   /**
    * Set the size of the progress bar region
@@ -560,7 +596,14 @@ private:
    *
    * @param[in] imageName The name of the image to load and set
    */
-  void CreateHandleImage( const std::string& imageName );
+  void SetHandleImageName( const std::string& imageName );
+
+  /**
+   * @brief Return the handle image name.
+   *
+   * @return The name of the image handle if it exists.
+   */
+  std::string GetHandleImageName();
 
   /**
    * Set the size of the handle region
@@ -584,28 +627,28 @@ private:
    *
    * @param[in] color The new color
    */
-  void UpdatePopupTextColor( const Vector4& color );
+  void SetPopupTextColor( const Vector4& color );
 
   /**
    * Set handle region
    *
    * @param[in] region The handle region
    */
-  void UpdateHandleRegion( const Vector2& region );
+  void SetHandleRegion( const Vector2& region );
 
   /**
    * Get handle region
    *
    * @return The handle region
    */
-  Vector2 GetHandleRegion() const;
+  const Vector2& GetHandleRegion() const;
 
   /**
    * Set the lower bound of the slider's value
    *
    * @param[in] bound The value to set for the lower bound
    */
-  void UpdateLowerBound( float bound );
+  void SetLowerBound( float bound );
 
   /**
    * Get the lower bound of the slider's value
@@ -619,7 +662,7 @@ private:
    *
    * @param[in] bound The value to set for the upper bound
    */
-  void UpdateUpperBound( float bound );
+  void SetUpperBound( float bound );
 
   /**
    * Get the upper bound of the slider's value
@@ -629,14 +672,6 @@ private:
   float GetUpperBound() const;
 
 private:
-  // From ControlImpl
-
-  /**
-   * @copydoc Dali::CustomActorImpl::OnPropertySet()
-   */
-  virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
-
-private:
 
   // Undefined
   Slider( const Slider& );
@@ -671,38 +706,27 @@ private:
 
   MarkList mMarks;                    ///< List of discreet marks
 
-  // Properties
-  Property::Index mPropertyLowerBound;
-  Property::Index mPropertyUpperBound;
-  Property::Index mPropertyValue;
-  Property::Index mPropertyHitRegion;
-  Property::Index mPropertyBackingRegion;
-  Property::Index mPropertyHandleRegion;
-
-  Property::Index mPropertyBackingImageName;
-  Property::Index mPropertyHandleImageName;
-  Property::Index mPropertyProgressImageName;
-  Property::Index mPropertyPopupImageName;
-  Property::Index mPropertyPopupArrowImageName;
-
-  Property::Index mPropertyBackingScale9Border;
-  Property::Index mPropertyProgressScale9Border;
-  Property::Index mPropertyPopupScale9Border;
+  std::string mPopupImageName;      ///< Image name for popup image
+  std::string mPopupArrowImageName; ///< Image name for popup arrow
 
-  Property::Index mPropertyDisableColor;
-  Property::Index mPropertyPopupTextColor;
+  Vector4 mDisableColor;    ///< The color to tint the slider when disabled
+  Vector4 mPopupTextColor;  ///< The color of the popup text
 
-  Property::Index mPropertyValuePrecision;
+  Vector2 mHitRegion;     ///< Size of hit region
+  Vector2 mBackingRegion; ///< Size of backing region
+  Vector2 mHandleRegionSize;  ///< Size of the handle region
 
-  Property::Index mPropertyShowPopup;
-  Property::Index mPropertyShowValue;
+  float mLowerBound;        ///< Lower bound on value
+  float mUpperBound;        ///< Upper bound on value
+  float mValue;             ///< Current value of slider
 
-  Property::Index mPropertyEnabled;
+  float mMarkTolerance;     ///< Tolerance in percentage of slider width for which to snap to marks
 
-  Property::Index mPropertyMarks;
-  Property::Index mPropertySnapToMarks;
-  Property::Index mPropertyMarkTolerance;
+  int mValuePrecision;      ///< The precision to use for outputting the value
 
+  bool mShowPopup   : 1,      ///< Show the popup or not
+       mShowValue   : 1,      ///< Whether to display the value number or not on the handle
+       mSnapToMarks : 1;      ///< Turn on or off snapping to marks
 };
 
 } // namespace Internal