[dali_1.0.2] Merge branch 'tizen'
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / public-api / controls / scrollable / item-view / item-view.h
1 #ifndef __DALI_TOOLKIT_ITEM_VIEW_H__
2 #define __DALI_TOOLKIT_ITEM_VIEW_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/dali.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
26 #include <dali-toolkit/public-api/controls/scrollable/item-view/item-view-declarations.h>
27
28 namespace Dali DALI_IMPORT_API
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36 class ItemView;
37 }
38
39 class ScrollConnector;
40 class ItemFactory;
41 class ItemLayout;
42 struct ItemRange;
43
44 typedef IntrusivePtr<ItemLayout> ItemLayoutPtr;
45
46 /**
47  * @brief ItemView is a scrollable layout container.
48  *
49  * Multiple ItemLayouts may be provided, to determine the logical position of each item a layout.
50  * Actors are provided from an external ItemFactory, to display the currently visible items.
51  */
52 class ItemView : public Scrollable
53 {
54 public:
55
56   /**
57    * @brief Create an uninitialized ItemView; this can be initialized with ItemView::New().
58    *
59    * Calling member functions with an uninitialized Dali::Object is not allowed.
60    */
61   ItemView();
62
63   /**
64    * @brief Copy constructor.
65    */
66   ItemView( const ItemView& itemView );
67
68   /**
69    * @brief Assignment operator.
70    */
71   ItemView& operator=( const ItemView& itemView );
72
73   /**
74    * @brief Destructor
75    *
76    * This is non-virtual since derived Handle types must not contain data or virtual methods.
77    */
78   ~ItemView();
79
80   /**
81    * @brief Create an initialized ItemView.
82    *
83    * @param[in] factory The factory which provides ItemView with items.
84    * @return A handle to a newly allocated Dali resource.
85    */
86   static ItemView New(ItemFactory& factory);
87
88   /**
89    * @brief Downcast an Object handle to ItemView.
90    *
91    * If handle points to a ItemView the downcast produces valid
92    * handle. If not the returned handle is left uninitialized.
93    *
94    * @param[in] handle Handle to an object
95    * @return handle to a ItemView or an uninitialized handle
96    */
97   static ItemView DownCast( BaseHandle handle );
98
99   /**
100    * @brief Retrieve a scroll-connector; this can be used to connect scroll components e.g. scroll bars.
101    *
102    * @return The connector.
103    */
104   ScrollConnector GetScrollConnector() const;
105
106   /**
107    * @brief Query the number of layouts.
108    *
109    * @return The number of layouts.
110    */
111   unsigned int GetLayoutCount() const;
112
113   /**
114    * @brief Add a layout.
115    *
116    * @param[in] layout The layout.
117    */
118   void AddLayout(ItemLayout& layout);
119
120   /**
121    * @brief Remove a layout.
122    *
123    * @pre layoutIndex is less than GetLayoutCount().
124    * @param[in] layoutIndex The index of one of the ItemView layouts.
125    */
126   void RemoveLayout(unsigned int layoutIndex);
127
128   /**
129    * @brief Retrieve a layout.
130    *
131    * @pre layoutIndex is less than GetLayoutCount().
132    * @param[in] layoutIndex The index of the layout to retrieve.
133    * @return The layout
134    */
135   ItemLayoutPtr GetLayout(unsigned int layoutIndex) const;
136
137   /**
138    * @brief Retrieve the currently active layout, if any.
139    *
140    * @return The layout, or an uninitialized pointer if no layout is active.
141    */
142   ItemLayoutPtr GetActiveLayout() const;
143
144   /**
145    * @brief Retrieve the current layout-position of an item in the ItemView.
146    *
147    * @param[in] itemId The item identifier.
148    * @return The current layout-position.
149    */
150   float GetCurrentLayoutPosition(ItemId itemId) const;
151
152   /**
153    * @brief Activate one of the layouts; this will resize the ItemView
154    * & relayout actors within the ItemView.
155    *
156    * This is done by applying constraints from the new layout, and
157    * removing constraints from the previous layout.
158    *
159    * @pre layoutIndex is less than GetLayoutCount().
160    * @pre durationSeconds is greater or equal to zero.
161    * @param[in] layoutIndex The index of one of the ItemView layouts.
162    * @param[in] targetSize The target ItemView & layout size.
163    * @param[in] durationSeconds The time taken to relayout in seconds (zero for immediate).
164    */
165   void ActivateLayout(unsigned int layoutIndex, Vector3 targetSize, float durationSeconds);
166
167   /**
168    * @brief Deactivate the current layout, if any.
169    *
170    * The constraints applied by the layout will be removed.
171    */
172   void DeactivateCurrentLayout();
173
174   /**
175    * @brief Set default the alpha function used when applying constraints e.g. during ActivateLayout().
176    *
177    * @deprecated Use SetAlphaFunction() in the layout
178    * @param[in] func The default alpha function to use.
179    */
180   void SetDefaultAlphaFunction(AlphaFunction func);
181
182   /**
183    * @brief Retrieve the default alpha function used when applying constraints
184    *
185    * @deprecated Use GetAlphaFunction() in the layout
186    * @return The default alpha function.
187    */
188   AlphaFunction GetDefaultAlphaFunction() const;
189
190   /**
191    * @brief Set the minimum swipe speed in pixels per second; A pan
192    * gesture must exceed this to trigger a swipe.
193    *
194    * @param[in] speed The minimum swipe speed
195    */
196   void SetMinimumSwipeSpeed(float speed);
197
198   /**
199    * @brief Get the minimum swipe speed in pixels per second.
200    *
201    * @return The minimum swipe speed
202    */
203   float GetMinimumSwipeSpeed() const;
204
205   /**
206    * @brief Set the minimum swipe distance in actor coordinates; A pan
207    * gesture must exceed this to trigger a swipe.
208    *
209    * @param[in] distance The minimum swipe distance.
210    */
211   void SetMinimumSwipeDistance(float distance);
212
213   /**
214    * @brief Get the minimum swipe distance in actor coordinates.
215    *
216    * @return The minimum swipe distance
217    */
218   float GetMinimumSwipeDistance() const;
219
220   /**
221    * @brief Set the step of scroll distance in actor coordinates for each mouse wheel event received.
222    *
223    * @param[in] step The step of scroll distance(pixel).
224    */
225   void SetMouseWheelScrollDistanceStep(float step);
226
227   /**
228    * @brief Get the step of scroll distance in actor coordinates for each mouse wheel event received.
229    *
230    * @return The step of scroll distance(pixel)
231    */
232   float GetMouseWheelScrollDistanceStep() const;
233
234   /**
235    * @brief Set whether to enable the animation for the layout to
236    * scroll to its anchor position after dragging or swiping.
237    *
238    * The anchor position is the position where all the items in the layout
239    * are aligned to their closest rounded layout positions in integer.
240    *
241    * @param[in] enabled Whether the anchor animation is enabled or not.
242    */
243   void SetAnchoring(bool enabled);
244
245   /**
246    * @brief Get whether the anchor animation is enabled or not.
247    *
248    * @return Whether the anchor animation is enabled or not.
249    */
250   bool GetAnchoring() const;
251
252   /**
253    * @brief Set the duration of the anchor animation in seconds.
254    *
255    * This is the time taken to reach the nearest anchor position after
256    * a drag or swipe gesture ends.
257    *
258    * @pre durationSeconds must be greater than zero.
259    * @param[in] durationSeconds The duration of the anchor animation in seconds.
260    */
261   void SetAnchoringDuration(float durationSeconds);
262
263   /**
264    * @brief Get the duration of the anchor animation in seconds.
265    *
266    * @return The duration of the anchor animation
267    */
268   float GetAnchoringDuration() const;
269
270   /**
271    * @brief Scroll the current layout to a particular item.
272    *
273    * @pre durationSeconds must be zero or greater; zero means the layout should scroll to the particular item instantly.
274    * If calling this with zero second of duration immediately after calling ActivateLayout, it might not work unless
275    * the duration of relayout animation for ActivateLayout is also set to be zero.
276    * @param[in] itemId The ID of an item in the layout.
277    * @param[in] durationSeconds How long the scrolling takes in seconds.
278    */
279   void ScrollToItem(ItemId itemId, float durationSeconds);
280
281   /**
282    * @brief Set the interval between refreshes. When the layout-position of items is changed by this interval,
283    * new items are requested from ItemFactory.
284    *
285    * @param[in] intervalLayoutPositions The refresh interval in layout position.
286    */
287   void SetRefreshInterval(float intervalLayoutPositions);
288
289   /**
290    * @brief Get the interval between refreshes in layout position.
291    *
292    * @return  The refresh interval
293    */
294   float GetRefreshInterval() const;
295
296   /**
297    * @brief Given the Item ID, this returns the accompanying actor.
298    *
299    * @param[in] itemId The Item ID of the actor required.
300    * @return The Actor corresponding to the Item ID.
301    */
302   Actor GetItem(ItemId itemId) const;
303
304   /**
305    * @brief Returns the Item ID of the specified actor.
306    *
307    * @param[in] actor The actor whose Item ID is required.
308    * @return The Item ID of the item.
309    * @pre The actor should be an item of ItemView.
310    */
311   ItemId GetItemId(Actor actor) const;
312
313   /**
314    * @brief Insert an item.
315    *
316    * A relayout will occur for the existing actors; for example if InsertItem(Item(2, ActorZ), 0) is called,
317    * the items with ID 2 or greater will be moved:
318    *   Initial actors:     After insert:
319    *     ID 1 - ActorA       ID 1 - ActorA
320    *     ID 2 - ActorB       ID 2 - ActorZ !
321    *     ID 3 - ActorC       ID 3 - ActorB
322    *                         ID 4 - ActorC
323    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
324    * @param[in] newItem The item to insert.
325    * @param[in] durationSeconds How long the relayout takes in seconds.
326    */
327   void InsertItem(Item newItem, float durationSeconds);
328
329   /**
330    * @brief Insert a set of items; this is more efficient than calling InsertItem() repeatedly.
331    *
332    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
333    * @param[in] newItems The items to insert.
334    * @param[in] durationSeconds How long the relayout takes in seconds.
335    */
336   void InsertItems(const ItemContainer& newItems, float durationSeconds);
337
338   /**
339    * @brief Removes an item with the given ID.
340    *
341    * A relayout will occur for the remaining actors; for example if RemoveItem(Item(2, ActorZ), 0) is called,
342    * the items with ID 3 or greater will be moved:
343    *   Initial actors:     After remove:
344    *     ID 1 - ActorA       ID 1 - ActorA
345    *     ID 2 - ActorB       ID 2 - ActorC (previously ID 3)
346    *     ID 3 - ActorC       ID 3 - ActorB (previously ID 4)
347    *     ID 4 - ActorD
348    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
349    * @param[in] itemId The Item ID of the item to remove.
350    * @param[in] durationSeconds How long the relayout takes in seconds.
351    */
352   void RemoveItem(ItemId itemId, float durationSeconds);
353
354   /**
355    * @brief Remove a set of items; this is more efficient than calling RemoveItem() repeatedly.
356    *
357    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
358    * @param[in] itemIds The IDs of the items to remove.
359    * @param[in] durationSeconds How long the relayout takes in seconds.
360    */
361   void RemoveItems(const ItemIdContainer& itemIds, float durationSeconds);
362
363   /**
364    * @brief Replace an item.
365    *
366    * A relayout will occur for the replacement item only.
367    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
368    * @param[in] replacementItem The replacement for an existing item.
369    * @param[in] durationSeconds How long the relayout takes in seconds.
370    */
371   void ReplaceItem(Item replacementItem, float durationSeconds);
372
373   /**
374    * @brief Replace a set of items.
375    *
376    * A relayout will occur for the replacement items only.
377    * @pre durationSeconds must be zero or greater; zero means the relayout occurs instantly.
378    * @param[in] replacementItems The replacements for a set of existing items.
379    * @param[in] durationSeconds How long the relayout takes in seconds.
380    */
381   void ReplaceItems(const ItemContainer& replacementItems, float durationSeconds);
382
383   /**
384    * @brief Set the parent origin of the items
385    *
386    * A relayout will occur for all the items if the parent origin is different than the current one.
387    * @param[in] parentOrigin New parent origin position vector
388    */
389   void SetItemsParentOrigin( const Vector3& parentOrigin );
390
391   /**
392    * @brief Get the parent origin of the items
393    *
394    * @return The current parent origin of the items
395    */
396   Vector3 GetItemsParentOrigin() const;
397
398   /**
399    * @brief Set the anchor point of the items
400    *
401    * A relayout will occur for all the items if the anchor point is different than the current one.
402    * @param[in] anchorPoint New anchor point position vector
403    */
404   void SetItemsAnchorPoint( const Vector3& anchorPoint );
405
406   /**
407    * @brief Get the anchor point of the items
408    *
409    * @return The current anchor point of the items
410    */
411   Vector3 GetItemsAnchorPoint() const;
412
413   /**
414    * @brief Get the range of items that are currently in ItemView.
415    *
416    * @param[out] range The range of items.
417    */
418   void GetItemsRange(ItemRange& range);
419
420 public: // Not intended for application developers
421
422   /**
423    * @brief Creates a handle using the Toolkit::Internal implementation.
424    *
425    * @param[in]  implementation  The Control implementation.
426    */
427   ItemView(Internal::ItemView& implementation);
428
429   /**
430    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
431    *
432    * @param[in]  internal  A pointer to the internal CustomActor.
433    */
434   ItemView( Dali::Internal::CustomActor* internal );
435 };
436
437 } // namespace Toolkit
438
439 } // namespace Dali
440
441 #endif // __DALI_TOOLKIT_ITEM_VIEW_H__