Merge "Fix for multi-language support." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / feedback / feedback-style.h
1 #ifndef __DALI_INTERNAL_FEEDBACK_STYLE_H__
2 #define __DALI_INTERNAL_FEEDBACK_STYLE_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 <map>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/devel-api/adaptor-framework/feedback-player.h>
25 #include <dali/public-api/signals/connection-tracker.h>
26 #include <dali/public-api/adaptor-framework/style-change.h>
27 #include <dali/public-api/signals/slot-delegate.h>
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/internal/feedback/feedback-ids.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 struct FeedbackStyleInfo;
42 struct SignalFeedbackInfo;
43
44 /**
45  * Plays feedback effects for Dali-Toolkit UI Controls.
46  *
47  * This functionality relies on an adaptor plugin.
48  * (And will have no effect if this is not loaded)
49  *
50  */
51 class FeedbackStyle : public ConnectionTracker
52 {
53 public:
54
55   /**
56    * Constructor.
57    */
58   FeedbackStyle();
59
60   /**
61    * The destructor
62    */
63   ~FeedbackStyle();
64
65   /**
66    * Called to start playing feedback effects.
67    */
68   void Start();
69
70   /**
71    * Called to stop playing feedback effects.
72    */
73   void Stop();
74
75   /**
76    * Callback function to play a feedback effect when a signal is emitted for an object
77    * Plays feedback effect.
78    * @param [in] type The Object type
79    * @param [in] signalName The name of the signal
80    */
81   void PlayFeedback(const std::string& type, const std::string& signalName);
82
83   /**
84    * Connects feedback to signals for the newly created object
85    * @param [in] object Handle to the newly created object
86    */
87   void ObjectCreated( BaseHandle object );
88
89   /**
90    * Style changed so reload the theme file
91    * @param [in] userDefinedThemePath Theme filename path
92    * @param [in] styleChange The type of style change
93    */
94   void StyleChanged(const std::string& userDefinedThemePath, StyleChange::Type styleChange);
95
96 private:
97
98   /**
99    * Helper to retrieve styleInfo from mStyleInfoLut
100    * @param type A string described a type of object
101    * @return The style information for the given object
102    */
103   const FeedbackStyleInfo& GetStyleInfo( const std::string& type) const;
104
105   /**
106    * Callback function for Dali::Toolkit::PushButton::SignalPressed signal
107    * Plays feedback effect.
108    * @param [in] effect The feedback effect to play
109    */
110   bool LoadTheme(const std::string& data);
111
112   /**
113    * Loads a string representation the theme.
114    * @param [in] data A string represenation of the theme.
115    * @param [in] format The string representation format ie JSON.
116    */
117   void LoadFromString( const std::string& data );
118
119   /**
120    * Helper to store signal information.
121    * @param [in] styleInfo The information will be stored here.
122    * @param [in] signalInfo The information to add.
123    */
124   void AddSignalInfo( FeedbackStyleInfo& styleInfo, SignalFeedbackInfo signalInfo );
125
126   /**
127    * Map a pattern string to feedback pattern ID.
128    * @param [in] pattern The pattern string.
129    * @return A feedback pattern ID.
130    */
131   FeedbackPattern GetFeedbackPattern( const std::string& pattern );
132
133   /**
134    * Plays a feedback effect
135    * @param [in] type The feedback type haptic or sound
136    * @param [in] effect The feedback effect to play
137    */
138   void PlayEffect(FeedbackType type, FeedbackPattern effect);
139
140   /**
141    * Plays a haptic or sound effect file
142    * @param [in] type The feedback type haptic or sound
143    * @param [in] file The path to the file containing the effect
144    */
145   void PlayFile(FeedbackType type, const std::string& file);
146
147 private:
148   Dali::FeedbackPlayer mFeedback;
149
150   std::map<const std::string, FeedbackPattern>   mFeedbackPatternLut; ///< Used to convert feedback pattern strings into enumerated values
151   std::map<const std::string, FeedbackStyleInfo> mStyleInfoLut;       ///< Converts key strings into style information
152 };
153
154 } // namespace Toolkit
155
156 } // namespace Internal
157
158 } // namespace Dali
159
160 #endif // __DALI_INTERNAL_FEEDBACK_STYLE_H__