Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / FUi_AccessibilityElement.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <FBaseString.h>
19 #include <FUiAccessibilityTypes.h>
20 #include <FUiIAccessibilityListener.h>
21 #include <FBaseSysLog.h>
22 #include "FUi_AccessibilityContainer.h"
23 #include "FUi_AccessibilityElementImpl.h"
24 #include "FUi_AccessibilityElement.h"
25 #include "FUi_AccessibilityManager.h"
26 #include "FUi_Control.h"
27 #include "FUi_ResourceManager.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31
32 namespace Tizen { namespace Ui {
33
34 const wchar_t* _traitString[] =
35 {
36         L"",//ACCESSIBILITY_TRAITS_NONE,
37         L"TITLE",//ACCESSIBILITY_TRAITS_TITLE,
38         L"OPTION HEADER",//ACCESSIBILITY_TRAITS_OPTION_HEADER,
39         L"PICTURE",//ACCESSIBILITY_TRAITS_PICTURE,
40         L"STATUS BAR",//ACCESSIBILITY_TRAITS_STATUS_BAR,
41         L"TEXT FIELD",//ACCESSIBILITY_TRAITS_TEXT_FIELD,
42         L"RATING",//ACCESSIBILITY_TRAITS_RATING,
43         L"ACTION BAR",//ACCESSIBILITY_TRAITS_ACTION_BAR,
44         L"ACTION BAR MENU",//ACCESSIBILITY_TRAITS_ACTION_BAR_MENU,
45         L"BACK BUTTON",//ACCESSIBILITY_TRAITS_BUTTON,
46         L"BUTTON",//ACCESSIBILITY_TRAITS_BUTTON,
47         L"LABEL",//ACCESSIBILITY_TRAITS_LABEL,
48         L"LIST",//ACCESSIBILITY_TRAITS_LIST,
49         L"SELECTOR",//ACCESSIBILITY_TRAITS_DATA_SELECTOR,
50         L"SCROLL",//ACCESSIBILITY_TRAITS_DRAG_SCROLL,
51         L"EXPAND BUTTON",//ACCESSIBILITY_TRAITS_EXPAND_BUTTON,
52         L"FUNCTION PANEL",//ACCESSIBILITY_TRAITS_FUNCTION_PANEL,
53         L"IN DEPTH BUTTON",//ACCESSIBILITY_TRAITS_IN_DEPTH_BUTTON,
54         L"INDEX SCROLL",//ACCESSIBILITY_TRAITS_INDEX_SCROLL,
55         L"IMAGE",//ACCESSIBILITY_TRAITS_IMAGE
56         L"INDICATOR",//ACCESSIBILITY_TRAITS_INDICATOR,
57         L"NOTIFICATION",//ACCESSIBILITY_TRAITS_NOTIFICATION,
58         L"RADIO BUTTON",//ACCESSIBILITY_TRAITS_RADIO_BUTTON,
59         L"SCROLL BAR",//ACCESSIBILITY_TRAITS_SCROLL_BAR,
60         L"SEARCH FIELD",//ACCESSIBILITY_TRAITS_SEARCH_FIELD,
61         L"SEGMENT",//ACCESSIBILITY_TRAITS_SEGMENT,
62         L"SLIDER",//ACCESSIBILITY_TRAITS_SLIDER,
63         L"SOFT KEY",//ACCESSIBILITY_TRAITS_SOFT_KEY,
64         L"SUB MENU TITLE",//ACCESSIBILITY_TRAITS_SUB_MENU_TITLE,
65         L"TAB",//ACCESSIBILITY_TRAITS_TAB,
66         L"TICK BOX",//ACCESSIBILITY_TRAITS_TICKBOX,
67         L"TIME SELECTOR",//ACCESSIBILITY_TRAITS_TIME_SELECTOR,
68         L"VOLUME SLIDER",//ACCESSIBILITY_TRAITS_VOLUME_SLIDER,
69         L"HOUR",//ACCESSIBILITY_TRAITS_HOUR,
70         L"MINUTE",//ACCESSIBILITY_TRAITS_MINUTE,
71         L"SECOND",//ACCESSIBILITY_TRAITS_SECOND,
72         L"YEAR",//ACCESSIBILITY_TRAITS_YEAR,
73         L"MONTH",//ACCESSIBILITY_TRAITS_MONTH,
74         L"DAY",//ACCESSIBILITY_TRAITS_DAY,
75         L"END",//ACCESSIBILITY_TRAITS_END = 0xff
76 };
77
78
79 _AccessibilityElement::_AccessibilityElement(bool systemElement)
80         : __name(L"")
81         , __bounds(0,0,0,0)
82         , __absBounds(0,0,0,0)
83         , __label(L"")
84         , __hint(L"")
85         , __status(L"")
86         , __traitString(L"")
87         , __trait(ACCESSIBILITY_TRAITS_NONE)
88         , __value(L"")
89         , __pParent(null)
90         , __pLabelId(null)
91         , __pTraitId(null)
92         , __pHintId(null)
93         , __pStatusId(null)
94         , __pValueId(null)
95         , __pUserData(null)
96         , __systemElement(systemElement)
97         , __activated(true)
98         , __supportOperatingGesture(true)
99         , __setHintByUser(false)
100         , __disabledHint(false)
101         , __updateContents(false)
102 {
103 }
104 _AccessibilityElement::~_AccessibilityElement(void)
105 {
106         if (__pUserData)
107         {
108                 static_cast<_AccessibilityElementImpl*>(__pUserData)->SetCore(null);
109                 __pUserData = null;
110         }
111         delete [] __pLabelId;
112         __pLabelId = null;
113         delete [] __pTraitId;
114         __pTraitId = null;
115         delete [] __pHintId;
116         __pHintId = null;
117         delete [] __pStatusId;
118         __pStatusId = null;
119         delete [] __pValueId;
120         __pValueId = null;
121         if (__pParent && this == __pParent->GetCurrentFocusedElement())
122         {
123                 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
124         }
125 }
126 result
127 _AccessibilityElement::Construct(const String& name, const FloatRectangle& bounds)
128 {
129         __name = name;
130         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
131         return E_SUCCESS;
132 }
133 result
134 _AccessibilityElement::Construct(const String& name, const Rectangle& bounds)
135 {
136         __name = name;
137         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
138         return E_SUCCESS;
139 }
140 void
141 _AccessibilityElement::SetName(const String& name)
142 {
143         __name = name;
144 }
145 void
146 _AccessibilityElement::SetLabel(const String& label)
147 {
148         __label = label;
149         __updateContents = true;
150         if(__pLabelId)
151         {
152                 delete [] __pLabelId;
153                 __pLabelId = null;
154         }
155 }
156 void
157 _AccessibilityElement::SetHint(const String& hint, bool setHintByUser)
158 {
159         if(__setHintByUser && !setHintByUser)
160         {
161                 return;
162         }
163         __hint = hint;
164         __setHintByUser = setHintByUser;
165         __updateContents = true;
166         if(__pHintId)
167         {
168                 delete [] __pHintId;
169                 __pHintId = null;
170         }
171 }
172 void
173 _AccessibilityElement::SetStatus(const String& status)
174 {
175         __status = status;
176         __updateContents = true;
177         if(__pStatusId)
178         {
179                 delete [] __pStatusId;
180                 __pStatusId = null;
181         }
182 }
183 void
184 _AccessibilityElement::SetTrait(const Tizen::Base::String& trait)
185 {
186         __traitString = trait;
187         __updateContents = true;
188         if(__pTraitId)
189         {
190                 delete [] __pTraitId;
191                 __pTraitId = null;
192         }
193 }
194 void
195 _AccessibilityElement::SetParent(const _AccessibilityContainer& parent)
196 {
197         __pParent = &const_cast<_AccessibilityContainer&>(parent);
198 }
199 void
200 _AccessibilityElement::SetValue(const String& value)
201 {
202         __value = value;
203         __updateContents = true;
204         if(__pValueId)
205         {
206                 delete [] __pValueId;
207                 __pValueId = null;
208         }
209 }
210 _AccessibilityContainer*
211 _AccessibilityElement::GetParent(void) const
212 {
213         return __pParent;
214 }
215 String
216 _AccessibilityElement::GetName(void) const
217 {
218         return __name;
219 }
220 FloatRectangle
221 _AccessibilityElement::GetBounds(void) const
222 {
223         return __bounds;
224 }
225 String
226 _AccessibilityElement::GetLabel(void) const
227 {
228         String out;
229         if (__pLabelId)
230         {
231                 Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pLabelId, out);
232                 return out;
233         }
234
235         return __label;
236 }
237 String
238 _AccessibilityElement::GetHint(void) const
239 {
240         String out;
241         if (__pHintId)
242         {
243                 Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pHintId, out);
244                 return out;
245         }
246         return __hint;
247 }
248 String
249 _AccessibilityElement::GetStatus(void) const
250 {
251         String out;
252         if (__pStatusId)
253         {
254                 Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pStatusId, out);
255                 return out;
256         }
257         return __status;
258 }
259 String
260 _AccessibilityElement::GetTraitString(void) const
261 {
262         String out;
263         if (__pTraitId)
264         {
265                 Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pTraitId, out);
266                 return out;
267         }
268         return __traitString;
269 }
270 String
271 _AccessibilityElement::GetValue(void) const
272 {
273         String out;
274         if (__pValueId)
275         {
276                 Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pValueId, out);
277                 return out;
278         }
279         return __value;
280 }
281 void
282 _AccessibilityElement::SetHintDisabled(bool enable)
283 {
284         __disabledHint = enable;
285 }
286 void
287 _AccessibilityElement::Activate(bool enable)
288 {
289         __activated = enable;
290         _AccessibilityManager::GetInstance()->NeedRefreshItem();
291 }
292 bool
293 _AccessibilityElement::IsActivated(void) const
294 {
295         return __activated;
296 }
297 String
298 _AccessibilityElement::GetReadingContents(void) const
299 {
300         String out = L"";
301         if (__pLabelId != null)
302         {
303                 String string;
304                 Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pLabelId, string);
305                 out = string;
306         }
307         else if(__label.GetLength() > 0)
308         {
309                 out += __label;
310         }
311
312         if (__pTraitId != null)
313         {
314                 String string;
315                 Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pTraitId, string);
316                 out += L", ";
317                 out += string;
318         }
319         else if(__traitString.GetLength() > 0)
320         {
321                 out += L", ";
322                 out += __traitString;
323         }
324
325         if (__pValueId != null)
326         {
327                 String string;
328                 Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pValueId, string);
329                 out += L", ";
330                 out += string;
331         }
332         else if(__value.GetLength() > 0)
333         {
334                 out += L", ";
335                 out += __value;
336         }
337
338         if (__pStatusId != null)
339         {
340                 String string;
341                 Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pStatusId, string);
342                 out += L", ";
343                 out += string;
344         }
345         else if(__status.GetLength() > 0)
346         {
347                 out += L", ";
348                 out += __status;
349         }
350         if(__pParent->GetEnableState() == false)
351         {
352                 out += L", ";
353                 out += L"disable"; //ScrLocalization
354         }
355         if (!__disabledHint && __pParent->GetEnableState())
356         {
357                 if (__pHintId != null)
358                 {
359                         String string;
360                         Tizen::Ui::_ResourceManager::GetInstance()->GetString(__pHintId, string);
361                         out += L"\n ";
362                         out += string;
363                 }
364                 else if(__hint.GetLength() > 0)
365                 {
366                         out += L"\n ";
367                         out += __hint;
368                 }
369         }
370         const_cast<_AccessibilityElement*>(this)->__updateContents = false;
371         return out;
372 }
373 void
374 _AccessibilityElement::SetBounds(const FloatRectangle& bounds)
375 {
376         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
377         if(__pParent && this == __pParent->GetCurrentFocusedElement())
378         {
379                 _AccessibilityManager::GetInstance()->RequestToDrawFocusUi();
380         }
381         _AccessibilityManager::GetInstance()->NeedRefreshItem();
382 }
383
384 void
385 _AccessibilityElement::SetBounds(const Tizen::Graphics::Rectangle& bounds)
386 {
387         __bounds.SetBounds(bounds.x,bounds.y,bounds.width,bounds.height);
388         if(__pParent && this == __pParent->GetCurrentFocusedElement())
389         {
390                 _AccessibilityManager::GetInstance()->RequestToDrawFocusUi();
391         }
392         _AccessibilityManager::GetInstance()->NeedRefreshItem();
393 }
394
395 FloatRectangle
396 _AccessibilityElement::GetAbsoluteBounds(void) const
397 {
398         FloatRectangle controlAbsBounds = GetParent()->GetOwner().GetAbsoluteBoundsF();
399         FloatRectangle rect(controlAbsBounds.x+__bounds.x, controlAbsBounds.y+__bounds.y, __bounds.width, __bounds.height);
400         const_cast<FloatRectangle&>(__absBounds).SetBounds(controlAbsBounds.x+__bounds.x, controlAbsBounds.y+__bounds.y, __bounds.width, __bounds.height);
401         return rect;
402 }
403 void
404 _AccessibilityElement::SetSupportOperatingGesture(bool set)
405 {
406         __supportOperatingGesture = set;
407 }
408 bool
409 _AccessibilityElement::GetSupportOperatingGesture(void)
410 {
411         return __supportOperatingGesture;
412 }
413 void*
414 _AccessibilityElement::GetUserData(void) const
415 {
416         return __pUserData;
417 }
418
419 void
420 _AccessibilityElement::SetUserData(void* pUserData)
421 {
422         __pUserData = pUserData;
423 }
424 bool
425 _AccessibilityElement::IsSystemElement(void)
426 {
427         return __systemElement;
428 }
429 bool
430 _AccessibilityElement::IsUpdated(void)
431 {
432         return __updateContents;
433 }
434
435 void
436 _AccessibilityElement::SetLabelWithStringId(const char* id)
437 {
438         if(__pLabelId)
439         {
440                 delete [] __pLabelId;
441         __pLabelId = null;
442         }
443         int length = strlen(id);
444         if(length == 0)
445         {
446                 return;
447         }
448         __pLabelId = new char[length+1];
449         strcpy(__pLabelId, id);
450         __pLabelId[length] = '\0';
451 }
452 void
453 _AccessibilityElement::SetTraitWithStringId(const char* id)
454 {
455         if(__pTraitId)
456         {
457                 delete [] __pTraitId;
458         __pTraitId = null;
459         }
460         int length = strlen(id);
461         if(length == 0)
462         {
463                 return;
464         }
465         __pTraitId = new char[length+1];
466         strcpy(__pTraitId, id);
467         __pTraitId[length] = '\0';
468 }
469 void
470 _AccessibilityElement::SetHintWithStringId(const char* id)
471 {
472         if(__pHintId)
473         {
474                 delete [] __pHintId;
475         __pHintId = null;
476         }
477
478         int length = strlen(id);
479         if(length == 0)
480         {
481                 return;
482         }
483         __pHintId = new char[length+1];
484         strcpy(__pHintId, id);
485         __pHintId[length] = '\0';
486 }
487 void
488 _AccessibilityElement::SetStatusWithStringId(const char* id)
489 {
490         if(__pStatusId)
491         {
492                 delete [] __pStatusId;
493         __pStatusId = null;
494         }
495         int length = strlen(id);
496         if(length == 0)
497         {
498                 return;
499         }
500         __pStatusId = new char[length+1];
501         strcpy(__pStatusId, id);
502         __pStatusId[length] = '\0';
503 }
504 void
505 _AccessibilityElement::SetValueWithStringId(const char* id)
506 {
507         if(__pValueId)
508         {
509                 delete [] __pValueId;
510         __pValueId = null;
511         }
512         int length = strlen(id);
513         if(length == 0)
514         {
515                 return;
516         }
517         __pValueId = new char[length+1];
518         strcpy(__pValueId, id);
519         __pValueId[length] = '\0';
520 }
521
522 }}