Set the window name
[platform/framework/native/uifw.git] / src / ui / FUi_EcoreEvas.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 /**
19  * @file                FUi_EcoreEvas.cpp
20  * @brief               This is the implementation file for the _EcoreEvas class.
21  */
22
23 #include <app.h>
24 #include <appcore-common.h>
25 #include <runtime_info.h>
26 #include <X11/Xlib.h>
27 #include <X11/Xatom.h>
28 #include <Ecore_X.h>
29 #include <Elementary.h>
30 #include <FGrpRectangle.h>
31 #include <FGrpFloatRectangle.h>
32 #include <FBaseInteger.h>
33 #include <FBaseErrors.h>
34 #include <FBaseSysLog.h>
35 #include <FBaseRtThread.h>
36 #include <FApp_IActiveWindowEventListener.h>
37 #include <FBase_StringConverter.h>
38 #include <FGrp_CanvasImpl.h>
39 #include "FUi_CoordinateSystemUtils.h"
40 #include "FUi_EcoreEvas.h"
41 #include "FUi_EcoreEvasMgr.h"
42 #include "FUi_Control.h"
43 #include <utilX.h>
44 #include "FUi_UiNotificationEvent.h"
45 #include "FUi_UiEventManager.h"
46 #include "FUi_Window.h"
47 #include "FUiAnim_EflLayer.h"
48 #include "FUiAnim_EflNode.h"
49 #include "FUiAnim_VisualElement.h"
50 #include "FUi_AccessibilityGesture.h"
51 #include "FUi_AccessibilitySystemSettingLoader.h"
52 #include "FUiAnim_RootVisualElement.h"
53 #include "FUiAnim_DisplayManager.h"
54 #include "FUiCtrl_Frame.h"
55 #include "FUiCtrl_FrameImpl.h"
56 #include "FUiCtrl_FormImpl.h"
57 #include "FUi_Clipboard.h"
58 #include "FUi_TouchManager.h"
59 #include "FUi_ControlManager.h"
60 #include "FUi_ActiveWindowEvent.h"
61 #include "FUi_ControlImplManager.h"
62 #include "FUiCtrl_Popup.h"
63 #include "FUiCtrl_ContextMenu.h"
64
65 using namespace Tizen::Base;
66 using namespace Tizen::Base::Runtime;
67 using namespace Tizen::App;
68 using namespace Tizen::Graphics;
69 using namespace Tizen::Ui;
70 using namespace Tizen::Ui::Animations;
71 using namespace Tizen::Ui::Controls;
72
73 #define ATOM_CBHM_WINDOW_NAME "CBHM_XWIN"
74 #define ATOM_CBHM_MSG "CBHM_MSG"
75 #define ATOM_CBHM_COUNT_GET "CBHM_cCOUNT"
76 #define ATOM_CBHM_SERIAL_NUMBER "CBHM_SERIAL_NUMBER"
77 #define ATOM_CBHM_ERROR "CBHM_ERROR"
78 #define ATOM_CBHM_ITEM "CBHM_ITEM"
79 #define ATOM_CBHM_SET_ITEM "SET_ITEM"
80 #define ATOM_CBHM_CLIPBOARD_SHOW_ALL "show1"
81 #define ATOM_CBHM_CLIPBOARD_SHOW "show0"
82 #define ATOM_CBHM_CLIPBOARD_HIDE "cbhm_hide"
83 #define ATOM_CBHM_SELECTED_ITEM "CBHM_SELECTED_ITEM"
84 #define ATOM_ROTATE_AUTO "_E_WINDOW_ROTATION_SUPPORTED"
85
86 namespace Tizen { namespace Ui
87 {
88 static _EcoreEvas* _pEvas = null;
89 }} // Tizen::Ui
90
91 namespace
92 {
93
94 Ecore_X_Atom __atomRotateRootAngle = 0;
95 Ecore_X_Atom __atomAccessibility = 0;
96
97 int __clipboardHeight = 0;
98
99 void
100 OnWindowStateChanged(Ecore_Evas* pEcoreEvas)
101 {
102         _ControlManager* pControlManager = _ControlManager::GetInstance();
103         if (!pControlManager)
104         {
105                 return;
106         }
107
108         Ecore_X_Window targetWin = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
109
110         SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] OnWindowStateChanged is called.", targetWin);
111
112         int winCount = pControlManager->GetWindowCount();
113         for (int i = 0; i < winCount; i++)
114         {
115                 _Window* pWindow = pControlManager->GetWindow(i);
116                 if (!pWindow)
117                 {
118                         continue;
119                 }
120
121                 Ecore_X_Window win = (Ecore_X_Window)pWindow->GetNativeHandle();
122
123                 if (win == targetWin)
124                 {
125                         pWindow->OnWindowStateChanged();
126
127                         return;
128                 }
129         }
130 }
131
132 Eina_Bool
133 OnWindowPropertyChanged(void* pData, int type, void* pEvent)
134 {
135         Ecore_X_Event_Window_Property* pEv = (Ecore_X_Event_Window_Property*)pEvent;
136         if (!pEv)
137         {
138                 return ECORE_CALLBACK_PASS_ON;
139         }
140
141         Ecore_X_Window targetWin = pEv->win;
142         if (targetWin == 0)
143         {
144                 return ECORE_CALLBACK_PASS_ON;
145         }
146
147         if (pEv->atom == ECORE_X_ATOM_E_ILLUME_CLIPBOARD_STATE)
148         {
149                 Ecore_X_Window zone = ecore_x_e_illume_zone_get(targetWin);
150                 Ecore_X_Illume_Clipboard_State clipboardState = ecore_x_e_illume_clipboard_state_get(zone);
151
152                 if (clipboardState == ECORE_X_ILLUME_CLIPBOARD_STATE_ON)
153                 {
154                         int x = 0;
155                         int y = 0;
156                         int w = 0;
157                         int h = 0;
158                         ecore_x_e_illume_clipboard_geometry_get(zone, &x, &y, &w, &h);
159
160                         Dimension clipboardDim = _CoordinateSystemUtils::InverseTransform(Dimension(w, h));
161
162                         if (__clipboardHeight == 0)
163                         {
164                                 SysLog(NID_UI, "[Clipboard] Clipboard is opened. -> w = %d, h = %d", clipboardDim.width, clipboardDim.height);
165                                 _Clipboard::GetInstance()->FirePopupEvent(_CLIPBOARD_POPUP_STATE_OPENED, clipboardDim.width, clipboardDim.height);
166                                 __clipboardHeight = clipboardDim.height;
167                         }
168 //                      else
169 //                      {
170 //                              SysLog(NID_UI, "[Clipboard] The bounds of Clipboard is changed. -> w = %d, h = %d", clipboardDim.width, clipboardDim.height);
171 //                              _Clipboard::GetInstance()->FirePopupEvent(_CLIPBOARD_POPUP_STATE_BOUNDS_CHANGED, clipboardDim.width, clipboardDim.height);
172 //                      }
173                 }
174                 else if (clipboardState == ECORE_X_ILLUME_CLIPBOARD_STATE_OFF)
175                 {
176                         SysLog(NID_UI, "[Clipboard] Clipboard is closed.");
177                         _Clipboard::GetInstance()->FirePopupEvent(_CLIPBOARD_POPUP_STATE_CLOSED, 0, 0);
178                         __clipboardHeight = 0;
179                         _Clipboard::GetInstance()->HidePopup();
180                 }
181         }
182         else if (pEv->atom == ECORE_X_ATOM_E_ILLUME_CLIPBOARD_GEOMETRY)
183         {
184                 // Only after opening Clipboard
185                 if (__clipboardHeight != 0)
186                 {
187                         Ecore_X_Window zone = ecore_x_e_illume_zone_get(targetWin);
188
189                         int x = 0;
190                         int y = 0;
191                         int w = 0;
192                         int h = 0;
193                         ecore_x_e_illume_clipboard_geometry_get(zone, &x, &y, &w, &h);
194
195                         Dimension clipboardDim = _CoordinateSystemUtils::InverseTransform(Dimension(w, h));
196
197                         if (clipboardDim.height != 0)
198                         {
199                                 SysLog(NID_UI, "[Clipboard] The bounds of Clipboard is changed. -> w = %d, h = %d", clipboardDim.width, clipboardDim.height);
200                                 _Clipboard::GetInstance()->FirePopupEvent(_CLIPBOARD_POPUP_STATE_BOUNDS_CHANGED, clipboardDim.width, clipboardDim.height);
201                         }
202                 }
203         }
204         else if (pEv->atom == ECORE_X_ATOM_WM_STATE)
205         {
206                 _ControlManager* pControlManager = _ControlManager::GetInstance();
207                 if (!pControlManager)
208                 {
209                         return ECORE_CALLBACK_PASS_ON;
210                 }
211
212                 int winCount = pControlManager->GetWindowCount();
213
214                 for (int i = 0; i < winCount; i++)
215                 {
216                         _Window* pWindow = pControlManager->GetWindow(i);
217                         if (!pWindow)
218                         {
219                                 continue;
220                         }
221
222                         Ecore_X_Window win = (Ecore_X_Window)pWindow->GetNativeHandle();
223                         if (win != targetWin)
224                         {
225                                 continue;
226                         }
227
228                         if (pWindow->IsOrientationRoot() == true)
229                         {
230                                 _Frame* pFrame = static_cast<_Frame*>(pWindow);
231
232                                 Ecore_X_Window_State_Hint state = ecore_x_icccm_state_get(targetWin);
233                                 switch (state)
234                                 {
235                                 case ECORE_X_WINDOW_STATE_HINT_WITHDRAWN:
236                                         // Frame was hidden.
237                                         break;
238                                 case ECORE_X_WINDOW_STATE_HINT_ICONIC:
239                                         pFrame->OnFrameMinimized();
240                                         break;
241                                 case ECORE_X_WINDOW_STATE_HINT_NORMAL:
242                                         pFrame->OnFrameRestored();
243                                         break;
244                                 default:
245                                         break;
246                                 }
247
248                                 break;
249                         }
250                 }
251         }
252
253         return ECORE_CALLBACK_PASS_ON;
254 }
255
256 Eina_Bool
257 OnWindowVisibilityChanged(void* pData, int type, void* pEvent)
258 {
259         SysTryReturn(NID_UI, pData, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
260         SysTryReturn(NID_UI, pEvent, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
261
262         Ecore_X_Event_Window_Visibility_Change* pE = (Ecore_X_Event_Window_Visibility_Change*) pEvent;
263         _ControlManager* pControlManager = _ControlManager::GetInstance();
264
265         int count = pControlManager->GetWindowCount();
266
267         _Window* pWindow = null;
268         bool found = false;
269
270         for (int i = 0; i < count; i++)
271         {
272                 pWindow = pControlManager->GetWindow(i);
273                 if (pWindow)
274                 {
275                         NativeWindowHandle handle = pWindow->GetNativeHandle();
276                         if (handle == pE->win)
277                         {
278                                 found = true;
279                                 break;
280                         }
281                 }
282         }
283
284         Tizen::Base::Collection::ArrayList* pArgs = null;
285         String* pType = null;
286         Integer* pObscured = null;
287
288         if (found == true)
289         {
290                 const _Control* pDestination = pWindow;
291
292                 pArgs = new (std::nothrow) Tizen::Base::Collection::ArrayList;
293                 SysTryReturn(NID_UI, pArgs, EINA_FALSE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
294
295                 result r = pArgs->Construct();
296                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
297
298                 pType = new (std::nothrow) String(L"VisibilityEvent");
299                 r = pArgs->Add(*pType);
300                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
301
302                 pObscured = new (std::nothrow) Integer(pE->fully_obscured);
303                 r = pArgs->Add(*pObscured);
304                 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
305
306                 _UiNotificationEvent event(pDestination->GetHandle(), pArgs);
307
308                 r = _UiEventManager::GetInstance()->SendEvent(event);
309         }
310
311         return ECORE_CALLBACK_RENEW;
312
313 CATCH:
314         pArgs->RemoveAll(true);
315         delete pArgs;
316
317         if (pType)
318         {
319                 delete pType;
320         }
321
322         if (pObscured)
323         {
324                 delete pObscured;
325         }
326
327         return EINA_FALSE;
328 }
329
330 Eina_Bool
331 OnWindowShown(void* pData, int type, void* pEvent)
332 {
333         return ECORE_CALLBACK_PASS_ON;
334 }
335
336 Eina_Bool
337 OnAccessibilitySettingMessageReceived(void* pData, int type, void* pEvent)
338 {
339         Ecore_X_Event_Client_Message* pClientEvent = static_cast<Ecore_X_Event_Client_Message*>(pEvent);
340         if (pClientEvent->message_type == __atomAccessibility)
341         {
342                 if ((Eina_Bool)pClientEvent->data.l[0])
343                 {
344                         _AccessibilitySystemSettingLoader::SetSystemSetting(L"AccessibilityActivationStatus", true);
345                         _AccessibilitySystemSettingLoader::SetSystemSetting(L"AccessibilityActivationStatus", true);
346                         SysLog(NID_UI, "Accessibility Screen reader is activated.");
347
348                 }
349                 else
350                 {
351                         _AccessibilitySystemSettingLoader::SetSystemSetting(L"AccessibilityActivationStatus", false);
352                         _AccessibilitySystemSettingLoader::SetSystemSetting(L"AccessibilityActivationStatus", false);
353                         SysLog(NID_UI, "Accessibility Screen reader is deactivated.");
354                 }
355         }
356         return ECORE_CALLBACK_PASS_ON;
357 }
358
359 Eina_Bool
360 OnClientMessageReceived(void* pData, int type, void* pEvent)
361 {
362         Ecore_X_Event_Client_Message* pClientEvent = static_cast<Ecore_X_Event_Client_Message*>(pEvent);
363         SysTryReturn(NID_UI, pClientEvent, ECORE_CALLBACK_RENEW, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
364
365         _ControlManager* pControlManager = _ControlManager::GetInstance();
366         if (!pControlManager)
367         {
368                 return ECORE_CALLBACK_RENEW;
369         }
370
371         if (pClientEvent->message_type == __atomRotateRootAngle)
372         {
373                 int angle = pClientEvent->data.l[0];
374
375                 SysTryReturn(NID_UI, pControlManager, ECORE_CALLBACK_RENEW, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
376
377                 pControlManager->OnWindowRotated(angle);
378         }
379
380         if (pClientEvent->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
381         {
382                 bool bFind = false;
383                 int winCount = pControlManager->GetWindowCount();
384                 for (int i = 0; i < winCount; i++)
385                 {
386                         _Window* pWindow = pControlManager->GetWindow(i);
387                         if (!pWindow)
388                         {
389                                 continue;
390                         }
391
392                         Ecore_X_Window win = (Ecore_X_Window)pWindow->GetNativeHandle();
393
394                         if (win == (Ecore_X_Window)pClientEvent->data.l[0])
395                         {
396                                 bFind = true;
397                                 break;
398                         }
399                 }
400
401                 if (!bFind)
402                 {
403                         return ECORE_CALLBACK_RENEW;
404                 }
405
406                 int x = 0;
407                 int y = 0;
408                 if ((unsigned int)pClientEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
409                 {
410                         SysLog(NID_UI, "Accessibility action : Move next");
411                         _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_FLICK_DOWN);
412                 }
413                 else if ((unsigned int)pClientEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
414                 {
415                         SysLog(NID_UI, "Accessibility action : Move next");
416                         _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_FLICK_RIGHT);
417                 }
418                 else if ((unsigned int)pClientEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
419                 {
420                         SysLog(NID_UI, "Accessibility action : Move previous");
421                         _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_FLICK_LEFT);
422                 }
423                 else if ((unsigned int)pClientEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
424                 {
425                         SysLog(NID_UI, "Accessibility action : Move previous");
426                         _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_FLICK_UP);
427                 }
428                 else if ((unsigned int)pClientEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
429                 {
430                         SysLog(NID_UI, "Accessibility action : Activate");
431                         _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_ONE_FINGER_DOUBLE_TAP);
432                 }
433                 else if ((unsigned int)pClientEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
434                 {
435                         x = (Evas_Coord)pClientEvent->data.l[2];
436                         y = (Evas_Coord)pClientEvent->data.l[3];
437                         SysLog(NID_UI, "Accessibility action : Read");
438                         _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_ONE_FINGER_ONE_TAP, x, y);
439                 }
440                 else if ((unsigned int)pClientEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
441                 {
442                         SysLog(NID_UI, "Accessibility action : value increased");
443                         _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_VALUE_INCREASED);
444                 }
445                 else if ((unsigned int)pClientEvent->data.l[1] == ecore_x_atom_get("_E_MOD_SCREEN_READER_ACTION_SCROLL_"))
446                 {
447                         SysLog(NID_UI, "Accessibility action : scroll %d, %d, %d", pClientEvent->data.l[2], pClientEvent->data.l[3], pClientEvent->data.l[4]);
448                         x = (Evas_Coord)pClientEvent->data.l[3];
449                         y = (Evas_Coord)pClientEvent->data.l[4];
450                         if (pClientEvent->data.l[2] == 0)
451                         {
452                                 _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_TWO_FINGER_PANNING_STARTED, x, y);
453                         }
454                         else if (pClientEvent->data.l[2] == 1)
455                         {
456                                 _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_TWO_FINGER_PANNING_CHANGED, x, y);
457                         }
458                         else if (pClientEvent->data.l[2] == 2)
459                         {
460                                 _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_TWO_FINGER_PANNING_FINISHED, x, y);
461                         }
462                 }
463                 else if ((unsigned int)pClientEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
464                 {
465                         SysLog(NID_UI, "Accessibility action : value decreased");
466                         _AccessibilityGesture::ProcessGesture(_ACCESSIBILITY_GESTURE_TYPE_VALUE_DECREASED);
467                 }
468         }
469
470         if (pClientEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST)
471         {
472                 SysLog(NID_UI, "[Ime Rotation]");
473
474                 _Window* pWindow = pControlManager->GetCurrentFrame();
475                 if (pWindow)
476                 {
477                         NativeWindowHandle handle = pWindow->GetNativeHandle();
478
479                         if (pClientEvent->win == handle)
480                         {
481                                 int angle = pClientEvent->data.l[1];
482                                 SysLog(NID_UI, "[Ime Rotation] Receive the client message(xid = 0x%x, angle = %d)", handle, angle);
483
484                                 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
485
486                                 if (pFrame)
487                                 {
488                                         _FrameImpl* pFrameImpl = static_cast<Controls::_FrameImpl*>(pFrame->GetUserData());
489                                         if (pFrameImpl)
490                                         {
491                                                 _FormImpl* pCurrentFormImpl = pFrameImpl->GetCurrentForm();
492
493                                                 if (pCurrentFormImpl)
494                                                 {
495                                                         pCurrentFormImpl->UpdateOrientation(angle);
496                                                 }
497                                                 else
498                                                 {
499                                                         pFrameImpl->UpdateOrientation(angle);
500                                                 }
501                                         }
502                                 }
503                         }
504                 }
505         }
506
507         return ECORE_CALLBACK_RENEW;
508 }
509
510 } // Anonymous
511
512 // For Clipboard
513 namespace
514 {
515 #define __UNUSED__
516
517 enum _ClipType
518 {
519         _CLIP_TYPE_PRIMARY,
520         _CLIP_TYPE_SECONDARY,
521         _CLIP_TYPE_CLIPBOARD,
522         _CLIP_TYPE_XDND,
523         _CLIP_TYPE_MAX,
524 };
525
526 struct _Clip
527 {
528         Ecore_X_Selection selection;
529         Eina_Bool (* set)(Ecore_X_Window window, const void* pData, int size);
530         Eina_Bool (* clear)(void);
531         void (* request)(Ecore_X_Window window, const char* pTarget);
532
533         bool active;
534         _ClipFormat format;
535         char* pBuffer;
536
537         _ClipFormat requestedFormat;
538         char* pRetrievedBuffer;
539         int bufferLength;
540         bool completed;
541 };
542
543 typedef Eina_Bool (*ClipConverter)(char* pTarget, void* pData, int size, void** outData, int* outSize, Ecore_X_Atom* pType, int* pTypeSize);
544 typedef int (*ClipResponseHandler)(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify);
545 typedef int (*ClipNotifyHandler)(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify);
546
547 enum
548 {
549         _ATOM_TARGETS = 0,
550         _ATOM_ATOM,
551         _ATOM_LISTING_ATOMS = _ATOM_ATOM,
552         _ATOM_TEXT_URI,
553         _ATOM_TEXT_URILIST,
554         _ATOM_TEXT_X_VCARD,
555         _ATOM_IMAGE_PNG,
556         _ATOM_IMAGE_JPEG,
557         _ATOM_IMAGE_BMP,
558         _ATOM_IMAGE_GIF,
559         _ATOM_IMAGE_TIFF,
560         _ATOM_IMAGE_SVG,
561         _ATOM_IMAGE_XPM,
562         _ATOM_IMAGE_TGA,
563         _ATOM_IMAGE_PPM,
564         _ATOM_XELM,
565         _ATOM_TEXT_HTML_UTF8,
566         _ATOM_TEXT_HTML,
567         _ATOM_STRING_UTF8,
568         _ATOM_STRING,
569         _ATOM_TEXT,
570         _ATOM_TEXT_PLAIN_UTF8,
571         _ATOM_TEXT_PLAIN,
572         _ATOM_MAX,
573 };
574
575 struct _Atom
576 {
577         const char* pName;
578         _ClipFormat formats;
579         ClipConverter convert;
580         ClipResponseHandler response;
581         ClipNotifyHandler notify;
582         Ecore_X_Atom atom;
583 };
584
585 Eina_Bool ClearClip(void* pData __UNUSED__, int type, void* pEvent);
586 Eina_Bool NotifyClip(void* pData __UNUSED__, int type, void* pEvent);
587
588 Eina_Bool ConvertClipIntoTarget(char* pTarget, void* pData, int size, void** outData, int* outSize, Ecore_X_Atom* pType, int* pTypeSize);
589 Eina_Bool ConvertClipIntoText(char* pTarget, void* pData, int size, void** outData, int* outSize, Ecore_X_Atom* pType, int* pTypeSize);
590 Eina_Bool ConvertClipIntoHtml(char* pTarget, void* pData, int size, void** outData, int* outSize, Ecore_X_Atom* pType, int* pTypeSize);
591 Eina_Bool ConvertClipIntoEdje(char* pTarget, void* pData, int size, void** outData, int* outSize, Ecore_X_Atom* pType, int* pTypeSize);
592 Eina_Bool ConvertClipIntoUri(char* pTarget, void* pData, int size, void** outData, int* outSize, Ecore_X_Atom* pType, int* pTypeSize);
593 Eina_Bool ConvertClipIntoImage(char* pTarget, void* pData, int size, void** outData, int* outSize, Ecore_X_Atom* pType, int* pTypeSize);
594 Eina_Bool ConvertClipIntoVCard(char* pTarget, void* pData, int size, void** outData, int* outSize, Ecore_X_Atom* pType, int* pTypeSize);
595
596 int NotifyTarget(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify);
597 int NotifyText(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify);
598 int NotifyImage(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify);
599 int NotifyUri(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify);
600 int NotifyEdje(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify);
601 int NotifyHtml(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify);
602
603 int RequestClip(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify);
604
605 _Atom __atomList[_ATOM_MAX];
606 _Clip __clipList[_CLIP_TYPE_MAX];
607
608 Eina_Bool
609 ClearClip(void* pData __UNUSED__, int type __UNUSED__, void* pEvent)
610 {
611         SysTryReturn(NID_UI, pEvent, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
612
613         Ecore_X_Event_Selection_Clear* pE = (Ecore_X_Event_Selection_Clear*) pEvent;
614         Ecore_X_Window window = pE->win;
615
616         _ClipType clipType = _CLIP_TYPE_SECONDARY;
617         __clipList[clipType].requestedFormat = (_ClipFormat)(_CLIP_FORMAT_TEXT|_CLIP_FORMAT_IMAGE);
618
619         ecore_x_selection_secondary_request(window, ECORE_X_SELECTION_TARGET_TARGETS);
620
621         return ECORE_CALLBACK_PASS_ON;
622 }
623
624 Eina_Bool
625 ConvertClipIntoTarget(char* pTarget __UNUSED__, void* pData, int size__UNUSED__, void** outData, int* outSize, Ecore_X_Atom* pType, int* pTypeSize)
626 {
627         return EINA_TRUE;
628
629         /*
630         SysTryReturn(NID_UI, outData, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
631         SysTryReturn(NID_UI, outSize, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
632         SysTryReturn(NID_UI, pData, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
633         SysTryReturn(NID_UI, pType, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
634         SysTryReturn(NID_UI, pTypeSize, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
635
636         int index = *((int*) pData);
637         SysTryReturn(NID_UI, index < _CLIP_TYPE_MAX, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
638
639         int count = 0;
640         for (int i = 0; i < _ATOM_MAX; i++)
641         {
642                 if (__clipList[index].format & __atomList[i].formats)
643                         count++;
644         }
645
646         // Make the atom list to be possible to return data.
647         Ecore_X_Atom* pAtoms = null;
648         if (count > 0)
649         {
650                 pAtoms = (Ecore_X_Atom*) malloc(sizeof(Ecore_X_Atom) * count);
651                 SysTryReturn(NID_UI, pAtoms, EINA_FALSE, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
652
653                 for (int i = 0, count = 0; i < _ATOM_MAX; i++)
654                 {
655                         if (__clipList[index].format & __atomList[i].formats)
656                                 pAtoms[count++] = __atomList[i].atom;
657                 }
658         }
659
660         *outData = pAtoms;
661         *outSize = count;
662         *pTypeSize = 32;
663         *pType = ECORE_X_ATOM_ATOM;
664
665         return EINA_TRUE;
666         */
667 }
668
669 Eina_Bool
670 ConvertClipIntoText(char* pTarget __UNUSED__, void* pData, int size __UNUSED__, void** outData, int* outSize, Ecore_X_Atom* pType __UNUSED__, int* pTypeSize __UNUSED__)
671 {
672         SysTryReturn(NID_UI, outData, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
673         SysTryReturn(NID_UI, outSize, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
674         SysTryReturn(NID_UI, pData, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
675
676         int index = *((int*) pData);
677         SysTryReturn(NID_UI, index < _CLIP_TYPE_MAX, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
678         SysTryReturn(NID_UI, __clipList[index].active, EINA_FALSE, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
679
680         if (__clipList[index].format & _CLIP_FORMAT_TEXT)
681         {
682                 *outData = strdup(__clipList[index].pBuffer);
683                 *outSize = strlen(__clipList[index].pBuffer);
684         }
685
686         return EINA_TRUE;
687 }
688
689 Eina_Bool
690 ConvertClipIntoHtml(char* pTarget __UNUSED__, void* pData, int size __UNUSED__, void** outData, int* outSize, Ecore_X_Atom* pType __UNUSED__, int* pTypeSize __UNUSED__)
691 {
692         SysTryReturn(NID_UI, outData, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
693         SysTryReturn(NID_UI, outSize, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
694         SysTryReturn(NID_UI, pData, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
695
696         int index = *((int*) pData);
697         SysTryReturn(NID_UI, index < _CLIP_TYPE_MAX, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
698         SysTryReturn(NID_UI, __clipList[index].active, EINA_FALSE, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
699
700         if (__clipList[index].format & _CLIP_FORMAT_HTML)
701         {
702                 *outData = strdup(__clipList[index].pBuffer);
703                 *outSize = strlen(__clipList[index].pBuffer);
704         }
705
706         return EINA_TRUE;
707 }
708
709 Eina_Bool
710 ConvertClipIntoEdje(char* pTarget __UNUSED__, void* pData, int size __UNUSED__, void** outData, int* outSize, Ecore_X_Atom* pType __UNUSED__, int* pTypeSize __UNUSED__)
711 {
712         return EINA_TRUE;
713 }
714
715 Eina_Bool
716 ConvertClipIntoUri(char* pTarget __UNUSED__, void* pData, int size __UNUSED__, void** outData, int* outSize, Ecore_X_Atom* pType __UNUSED__, int* pTypeSize __UNUSED__)
717 {
718         SysTryReturn(NID_UI, outData, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
719         SysTryReturn(NID_UI, outSize, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
720         SysTryReturn(NID_UI, pData, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
721
722         int index = *((int*) pData);
723         SysTryReturn(NID_UI, index < _CLIP_TYPE_MAX, EINA_FALSE, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
724         SysTryReturn(NID_UI, __clipList[index].active, EINA_FALSE, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
725
726         if (__clipList[index].format & _CLIP_FORMAT_IMAGE)
727         {
728                 *outData = strdup(__clipList[index].pBuffer);
729                 *outSize = strlen(__clipList[index].pBuffer);
730         }
731
732         return EINA_TRUE;
733 }
734
735 Eina_Bool
736 ConvertClipIntoImage(char* pTarget __UNUSED__, void* pData, int size __UNUSED__, void** outData __UNUSED__, int* outSize __UNUSED__, Ecore_X_Atom* pType __UNUSED__, int* pTypeSize __UNUSED__)
737 {
738         return EINA_TRUE;
739 }
740
741 Eina_Bool
742 ConvertClipIntoVCard(char* pTarget __UNUSED__, void* pData, int size __UNUSED__, void** outData __UNUSED__, int* outSize __UNUSED__, Ecore_X_Atom* pType __UNUSED__, int* pTypeSize __UNUSED__)
743 {
744         return EINA_TRUE;
745 }
746
747 int
748 RequestClip(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify)
749 {
750         return 0;
751 }
752
753 Eina_Bool
754 OnClipboardClosed(void* pData __UNUSED__, int type, void* pEvent)
755 {
756         SysTryReturn(NID_UI, pEvent, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
757
758         _Clipboard* pClipboard = _Clipboard::GetInstance();
759         if (pClipboard)
760         {
761                 bool visible = pClipboard->IsPopupVisible();
762
763                 if (visible == true)
764                 {
765                         pClipboard->FireEvent(0, null);
766                 }
767         }
768
769         return ECORE_CALLBACK_PASS_ON;
770 }
771
772 Eina_Bool
773 NotifyClip(void* pData __UNUSED__, int type, void* pEvent)
774 {
775         SysTryReturn(NID_UI, pEvent, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
776
777         Ecore_X_Event_Selection_Notify* pE = (Ecore_X_Event_Selection_Notify*) pEvent;
778
779         int i = 0;
780         for (i = 0; i < _CLIP_TYPE_MAX; i++)
781         {
782                 if (__clipList[i].selection == pE->selection)
783                 {
784                         break;
785                 }
786         }
787
788         SysTryReturn(NID_UI, i < _CLIP_TYPE_MAX, ECORE_CALLBACK_PASS_ON, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
789
790         _Clip* pClip = __clipList + i;
791         for (i = 0; i < _ATOM_MAX; i++)
792         {
793                 if (!strcmp(pE->target, __atomList[i].pName))
794                 {
795                         if (__atomList[i].notify)
796                         {
797                                 __atomList[i].notify(pClip, pE);
798                         }
799                 }
800         }
801
802         return ECORE_CALLBACK_PASS_ON;
803 }
804
805 int
806 NotifyTarget(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify)
807 {
808         SysTryReturn(NID_UI, pClip, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
809         SysTryReturn(NID_UI, pNotify, ECORE_CALLBACK_PASS_ON, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
810
811         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
812         SysTryReturn(NID_UI, pEcoreEvas, ECORE_CALLBACK_PASS_ON, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
813
814         _ControlManager* pControlManager = _ControlManager::GetInstance();
815         SysTryReturn(NID_UI, pControlManager, ECORE_CALLBACK_PASS_ON, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
816
817         _Window* pWindow = pControlManager->GetClipboardOwner();
818         SysTryReturn(NID_UI, pWindow, ECORE_CALLBACK_PASS_ON, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
819
820         _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
821         SysTryReturn(NID_UI, pRootVE, ECORE_CALLBACK_PASS_ON, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
822
823         _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
824         SysTryReturn(NID_UI, pLayer, ECORE_CALLBACK_PASS_ON, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
825
826         Ecore_Evas* pEE = pLayer->GetEcoreEvas();
827         Ecore_X_Window window = (Ecore_X_Window) ecore_evas_window_get(pEE);
828
829         Ecore_X_Atom dataType = 0;
830         char* pBuffer = null;
831         if (pEcoreEvas->GetSelectedCbhmItem(&dataType, &pBuffer))
832         {
833                 free(pBuffer);
834
835                 const char* pHtmlAtomName = "text/html;charset=utf-8";
836                 Ecore_X_Atom htmlType = ecore_x_atom_get(pHtmlAtomName);
837
838                 if (dataType == htmlType)
839                 {
840                         pClip->request(window, pHtmlAtomName);
841                         return ECORE_CALLBACK_PASS_ON;
842                 }
843         }
844
845         Ecore_X_Selection_Data_Targets* pTargets = (Ecore_X_Selection_Data_Targets*) (pNotify->data);
846         Ecore_X_Atom* pAtomList = (Ecore_X_Atom*) (pTargets->data.data);
847
848         int i, j = 0;
849         for (j = (_ATOM_LISTING_ATOMS+1); j < _ATOM_MAX; j++)
850         {
851                 SysLog(NID_UI, "[Clipboard] __atomList[%d].atom = %d", j, __atomList[j].atom);
852
853                 if (!(__atomList[j].formats & pClip->requestedFormat))
854                 {
855                         continue;
856                 }
857
858                 for (i = 0; i < pTargets->data.length; i++)
859                 {
860                         SysLog(NID_UI, "[Clipboard] pAtomList[%d] = %d", i, pAtomList[i]);
861
862                         if ((__atomList[j].atom == pAtomList[i]) && (__atomList[j].notify))
863                         {
864                                 if ((j == _ATOM_XELM) && (!(pClip->requestedFormat & _CLIP_FORMAT_MARKUP)))
865                                 {
866                                         continue;
867                                 }
868
869                                 SysLog(NID_UI, "[Clipboard] go to __atomList[%d].atom = %d", j, __atomList[j].atom);
870                                 goto FOUND;
871                         }
872                 }
873         }
874
875         return ECORE_CALLBACK_PASS_ON;
876
877 FOUND:
878         pClip->request(window, __atomList[j].pName);
879         return ECORE_CALLBACK_PASS_ON;
880 }
881
882 int
883 NotifyText(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify)
884 {
885         SysTryReturn(NID_UI, pClip, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
886         SysTryReturn(NID_UI, pNotify, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
887
888         Ecore_X_Selection_Data* pData = (Ecore_X_Selection_Data*) pNotify->data;
889         SysTryReturn(NID_UI, pData->data, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
890
891         pClip->bufferLength = (int) pData->length;
892
893         char* pStr = (char*)malloc(sizeof(char) * (pClip->bufferLength + 1));
894         if (pStr)
895         {
896                 strncpy(pStr, (char*)pData->data, pClip->bufferLength);
897                 pStr[pClip->bufferLength] = '\0';
898         }
899         else
900         {
901                 SysLog(NID_UI, "[Clipboard] pStr is null.");
902                 return 0;
903         }
904
905         pClip->pRetrievedBuffer = pStr;
906
907         _Clipboard::GetInstance()->FireEvent(_CLIP_FORMAT_TEXT, pClip->pRetrievedBuffer);
908
909         return 0;
910 }
911
912 int
913 NotifyImage(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify)
914 {
915         SysTryReturn(NID_UI, pClip, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
916         SysTryReturn(NID_UI, pNotify, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
917
918         Ecore_X_Selection_Data* pData = (Ecore_X_Selection_Data*) pNotify->data;
919         SysTryReturn(NID_UI, pData->data, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
920
921         pClip->bufferLength = (int) pData->length;
922
923         char* pStr = (char*)malloc(sizeof(char) * (pClip->bufferLength + 1));
924         if (pStr)
925         {
926                 strncpy(pStr, (char*)pData->data, pClip->bufferLength);
927                 pStr[pClip->bufferLength] = '\0';
928         }
929         else
930         {
931                 SysLog(NID_UI, "[Clipboard] pStr is null.");
932                 return 0;
933         }
934
935         pClip->pRetrievedBuffer = pStr;
936
937         _Clipboard::GetInstance()->FireEvent(_CLIP_FORMAT_IMAGE, pClip->pRetrievedBuffer);
938
939         return 0;
940 }
941
942 int
943 NotifyUri(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify)
944 {
945         SysTryReturn(NID_UI, pClip, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
946         SysTryReturn(NID_UI, pNotify, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
947
948         Ecore_X_Selection_Data* pData = (Ecore_X_Selection_Data*) pNotify->data;
949         SysTryReturn(NID_UI, pData->data, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
950
951         pClip->bufferLength = (int) pData->length;
952
953         char* pStr = (char*)malloc(sizeof(char) * (pClip->bufferLength + 1));
954         if (pStr)
955         {
956                 strncpy(pStr, (char*)pData->data, pClip->bufferLength);
957                 pStr[pClip->bufferLength] = '\0';
958         }
959         else
960         {
961                 SysLog(NID_UI, "[Clipboard] pStr is null.");
962                 return 0;
963         }
964
965         pClip->pRetrievedBuffer = pStr;
966
967         _Clipboard::GetInstance()->FireEvent(_CLIP_FORMAT_IMAGE, pClip->pRetrievedBuffer);
968
969         return 0;
970 }
971
972 int
973 NotifyEdje(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify)
974 {
975         SysTryReturn(NID_UI, pClip, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
976         SysTryReturn(NID_UI, pNotify, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
977
978         Ecore_X_Selection_Data* pData = (Ecore_X_Selection_Data*) pNotify->data;
979         SysTryReturn(NID_UI, pData->data, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
980
981         pClip->bufferLength = (int) pData->length;
982
983         char* pStr = (char*)malloc(sizeof(char) * (pClip->bufferLength + 1));
984         if (pStr)
985         {
986                 strncpy(pStr, (char*)pData->data, pClip->bufferLength);
987                 pStr[pClip->bufferLength] = '\0';
988         }
989         else
990         {
991                 SysLog(NID_UI, "[Clipboard] pStr is null.");
992                 return 0;
993         }
994
995         pClip->pRetrievedBuffer = pStr;
996
997         _Clipboard::GetInstance()->FireEvent(_CLIP_FORMAT_TEXT, pClip->pRetrievedBuffer);
998
999         return 0;
1000 }
1001
1002 int
1003 NotifyHtml(_Clip* pClip, Ecore_X_Event_Selection_Notify* pNotify)
1004 {
1005         SysTryReturn(NID_UI, pClip, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
1006         SysTryReturn(NID_UI, pNotify, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
1007
1008         Ecore_X_Selection_Data* pData = (Ecore_X_Selection_Data*) pNotify->data;
1009         SysTryReturn(NID_UI, pData->data, 0, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
1010
1011         pClip->bufferLength = (int) pData->length;
1012
1013         char* pStr = (char*)malloc(sizeof(char) * (pClip->bufferLength + 1));
1014         if (pStr)
1015         {
1016                 strncpy(pStr, (char*)pData->data, pClip->bufferLength);
1017                 pStr[pClip->bufferLength] = '\0';
1018         }
1019         else
1020         {
1021                 SysLog(NID_UI, "[Clipboard] pStr is null.");
1022                 return 0;
1023         }
1024
1025         pClip->pRetrievedBuffer = pStr;
1026
1027         _Clipboard::GetInstance()->FireEvent(_CLIP_FORMAT_HTML, pClip->pRetrievedBuffer);
1028
1029         return 0;
1030 }
1031 } // Anonymous
1032
1033 namespace Tizen { namespace Ui
1034 {
1035
1036 _EcoreEvas*
1037 _EcoreEvas::CreateInstanceN(void)
1038 {
1039         _EcoreEvas* pEcoreEvas = new (std::nothrow) _EcoreEvas;
1040         SysTryReturn(NID_UI, pEcoreEvas, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1041
1042         result r = GetLastResult();
1043         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1044
1045         SetLastResult(E_SUCCESS);
1046
1047         return pEcoreEvas;
1048
1049 CATCH:
1050         delete pEcoreEvas;
1051         return null;
1052 }
1053
1054 _EcoreEvas::_EcoreEvas(void)
1055         : __pWindowVisibilityChanged(null)
1056         , __pWindowPropertyChanged(null)
1057         , __pWindowShown(null)
1058         , __pClientMessageReceived(null)
1059         , __pClearClip(null)
1060         , __pNotifyClip(null)
1061         , __pClipboardClosed(null)
1062         , __pEvas(null)
1063         , __pForegroundWindow(null)
1064         , __pFrame(null)
1065         , __changeBounds(true)
1066         , __openClipboard(false)
1067 {
1068         int ret = appcore_unset_rotation_cb();
1069         SysLog(NID_UI, "[Window Manager Rotation] appcore_unset_rotation_cb = %d", ret);
1070
1071         __pWindowVisibilityChanged = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE, OnWindowVisibilityChanged, (void*) this);
1072         SysTryReturnVoidResult(NID_UI, __pWindowVisibilityChanged, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1073
1074         __pClientMessageReceived = ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, OnClientMessageReceived, NULL);
1075
1076         ecore_x_event_mask_set(ecore_x_window_root_first_get(), ECORE_X_EVENT_MASK_WINDOW_CONFIGURE);
1077         ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, OnAccessibilitySettingMessageReceived, NULL);
1078         ecore_x_event_mask_set(ecore_x_window_root_first_get(), ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
1079
1080         _pEvas = this;
1081
1082         GetEcoreEvasMgr()->SetEcoreEvas(*this);
1083
1084         //int ret = 0;
1085         //ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_ROTATION_LOCK_ENABLED, OnAutoRotationChanged, NULL);
1086         //SysTryCatch(NID_UI, ret == 0, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1087
1088         result r = InitializeAtomList();
1089         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1090
1091         __pWindowShown = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW, OnWindowShown, (void*) this);
1092         SysTryCatch(NID_UI, __pWindowShown, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1093
1094         __pWindowPropertyChanged = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, OnWindowPropertyChanged, NULL);
1095         SysTryCatch(NID_UI, __pWindowPropertyChanged, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1096
1097         SetLastResult(E_SUCCESS);
1098
1099         return;
1100
1101 CATCH:
1102         if (__pWindowVisibilityChanged)
1103         {
1104                 ecore_event_handler_del(__pWindowVisibilityChanged);
1105                 __pWindowVisibilityChanged = null;
1106         }
1107
1108         if (__pWindowShown)
1109         {
1110                 ecore_event_handler_del(__pWindowShown);
1111                 __pWindowShown = null;
1112         }
1113 }
1114
1115 _EcoreEvas::~_EcoreEvas(void)
1116 {
1117         if (__pWindowVisibilityChanged)
1118         {
1119                 ecore_event_handler_del(__pWindowVisibilityChanged);
1120                 __pWindowVisibilityChanged = null;
1121         }
1122
1123         if (__pWindowShown)
1124         {
1125                 ecore_event_handler_del(__pWindowShown);
1126                 __pWindowShown = null;
1127         }
1128
1129         if (__pClientMessageReceived)
1130         {
1131                 ecore_event_handler_del(__pClientMessageReceived);
1132                 __pClientMessageReceived = null;
1133         }
1134
1135         for (int i = 0; i < _ATOM_MAX; i++)
1136         {
1137                 if (__atomList[i].atom)
1138                 {
1139                         ecore_x_selection_converter_atom_del(__atomList[i].atom);
1140                 }
1141         }
1142
1143         if (__pClearClip)
1144         {
1145                 ecore_event_handler_del(__pClearClip);
1146                 __pClearClip = null;
1147         }
1148
1149         if (__pNotifyClip)
1150         {
1151                 ecore_event_handler_del(__pNotifyClip);
1152                 __pNotifyClip = null;
1153         }
1154
1155         if (__pClipboardClosed)
1156         {
1157                 ecore_event_handler_del(__pClipboardClosed);
1158                 __pClipboardClosed = null;
1159         }
1160
1161         if (__pWindowPropertyChanged)
1162         {
1163                 ecore_event_handler_del(__pWindowPropertyChanged);
1164                 __pWindowPropertyChanged = null;
1165         }
1166
1167         //runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_ROTATION_LOCK_ENABLED);
1168 }
1169
1170 void
1171 _EcoreEvas::RotateWindow(const _Window& window, int orientation, bool rotateEvas)
1172 {
1173         // Set window bounds according to the rotation
1174         // Rotate Evas
1175
1176         _EflLayer* pLayer = GetEflLayer(window);
1177         if (!pLayer)
1178         {
1179                 return;
1180         }
1181
1182         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1183
1184         /*
1185         int curOrientation = ecore_evas_rotation_get(pEcoreEvas);
1186         if (curOrientation == orientation)
1187         {
1188                 return;
1189         }
1190         */
1191
1192         bool rotatePartial = true;
1193
1194         _Frame* pFrame = dynamic_cast<_Frame*>(const_cast<_Window*>(&window));
1195         if (pFrame)
1196         {
1197                 FrameShowMode showMode = pFrame->GetShowMode(false);
1198                 if (showMode == FRAME_SHOW_MODE_FULL_SCREEN)
1199                 {
1200                         rotatePartial = false;
1201                 }
1202         }
1203
1204         _Window* pWindow = const_cast<_Window*>(&window);
1205         if (pWindow->IsLayoutChangable() == true)
1206         {
1207                 rotatePartial = false;
1208         }
1209
1210         Evas_Object* pWinObj = pLayer->GetElmWin();
1211         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1212
1213         int rootW = 0;
1214         int rootH = 0;
1215         ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
1216
1217         if (rotatePartial == false)
1218         {
1219                 if (rotateEvas == true)
1220                 {
1221                         ecore_evas_rotation_with_resize_set(pEcoreEvas, orientation);
1222                 }
1223
1224                 evas_object_move(pWinObj, 0, 0);
1225
1226                 if ((orientation == 0) || (orientation == 180))
1227                 {
1228                         evas_object_resize(pWinObj, rootW, rootH);
1229                 }
1230                 else
1231                 {
1232                         evas_object_resize(pWinObj, rootH, rootW);
1233                 }
1234
1235                 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, FULL SCREEN] Rotate bounds(rot = %d).", win, orientation);
1236         }
1237         else
1238         {
1239                 if (rotateEvas == true)
1240                 {
1241                         ecore_evas_rotation_set(pEcoreEvas, orientation);
1242                 }
1243
1244                 Rectangle winBounds = _CoordinateSystemUtils::Transform(window.GetBounds());
1245                 int rotate = ecore_evas_rotation_get(pEcoreEvas);
1246
1247
1248                 int winX = winBounds.x;
1249                 int winY = winBounds.y;
1250
1251                 switch (rotate)
1252                 {
1253                 case 270:
1254                         winX = rootW - winBounds.y - winBounds.height;
1255                         winY = winBounds.x;
1256                         break;
1257                 case 90:
1258                         winX = winBounds.y;
1259                         winY = rootH - winBounds.x - winBounds.width;
1260                         break;
1261                 case 180:
1262                         winX = rootW - winBounds.x - winBounds.width;
1263                         winY = rootH - winBounds.y - winBounds.height;
1264                         break;
1265                 default:
1266                         break;
1267                 }
1268
1269                 int x = 0;
1270                 int y = 0;
1271                 int w = 0;
1272                 int h = 0;
1273                 Eina_Bool ret = ecore_x_e_window_rotation_geometry_get(win, rotate, &x, &y, &w, &h);
1274
1275                 evas_object_move(pWinObj, winX, winY);
1276
1277                 if (ret == EINA_FALSE)
1278                 {
1279                         evas_object_resize(pWinObj, winBounds.width, winBounds.height);
1280                         SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, PARTIAL SCREEN] Rotate bounds(rot = %d, %d, %d, %d, %d).", win, orientation, winX, winY, winBounds.width, winBounds.height);
1281                 }
1282                 else
1283                 {
1284                         SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, PARTIAL SCREEN] Rotate bounds(rot = %d, %d, %d) ONLY MOVE.", win, orientation, winX, winY);
1285                 }
1286         }
1287 }
1288
1289 _EflLayer*
1290 _EcoreEvas::GetEflLayer(const _Window& window) const
1291 {
1292         _RootVisualElement* pRootVisualElement = null;
1293
1294         pRootVisualElement = window.GetRootVisualElement();
1295         if (!pRootVisualElement)
1296         {
1297                 SysLog(NID_UI, "The root visual element is null.");
1298                 return null;
1299         }
1300
1301         _EflLayer* pEflLayer = static_cast<_EflLayer*>(pRootVisualElement->GetNativeLayer());
1302         if (!pEflLayer)
1303         {
1304                 SysLog(NID_UI, "The efl layer is null.");
1305                 return null;
1306         }
1307
1308         return pEflLayer;
1309 }
1310
1311 bool
1312 _EcoreEvas::GetFloatingMode(void) const
1313 {
1314         SysTryReturn(NID_UI, __pForegroundWindow, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1315
1316         Eina_Bool ret = elm_win_floating_mode_get(__pForegroundWindow);
1317
1318         SetLastResult(E_SUCCESS);
1319
1320         return (ret ? true : false);
1321 }
1322
1323 // [ToDo] Remove API
1324 bool
1325 _EcoreEvas::GetFloatingMode(const _Window& window) const
1326 {
1327         _EflLayer* pLayer = GetEflLayer(window);
1328         SysTryReturn(NID_UI, pLayer, false, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1329
1330         Evas_Object* pWinObj = pLayer->GetElmWin();
1331         SysTryReturn(NID_UI, pWinObj, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1332
1333         Eina_Bool ret = elm_win_floating_mode_get(pWinObj);
1334
1335         SetLastResult(E_SUCCESS);
1336
1337         return (ret ? true : false);
1338 }
1339
1340 // [ToDo] Remove API
1341 void
1342 _EcoreEvas::AddActiveWindowEventListener(const _IActiveWindowEventListener& listener)
1343 {
1344 }
1345
1346 // [ToDo] Remove API
1347 void
1348 _EcoreEvas::RemoveActiveWindowEventListener(const _IActiveWindowEventListener& listener)
1349 {
1350 }
1351
1352 unsigned int
1353 _EcoreEvas::GetActiveWindow(void)
1354 {
1355         Ecore_X_Window* pRoots = null;
1356         Ecore_X_Window activeWin = 0;
1357         int num = 0;
1358
1359         pRoots = ecore_x_window_root_list(&num);
1360         if (pRoots)
1361         {
1362                 Ecore_X_Atom activeAtom = ecore_x_atom_get("_NET_ACTIVE_WINDOW");
1363                 int ret = ecore_x_window_prop_window_get(pRoots[0], activeAtom, &activeWin, 1);
1364
1365                 free(pRoots);
1366
1367                 if (ret < 0)
1368                 {
1369                         return 0;
1370                 }
1371         }
1372
1373         return activeWin;
1374 }
1375
1376 int
1377 _EcoreEvas::GetProcessId(unsigned int window)
1378 {
1379         int pid = 0;
1380         Eina_Bool ret = ecore_x_netwm_pid_get(window, &pid);
1381
1382         if (ret != EINA_TRUE)
1383         {
1384                 return 0;
1385         }
1386
1387         return pid;
1388 }
1389
1390 void
1391 _EcoreEvas::SetOwner(NativeWindowHandle ownee, NativeWindowHandle owner)
1392 {
1393         ecore_x_icccm_transient_for_unset(ownee);
1394         ecore_x_icccm_transient_for_set(ownee, owner);
1395
1396         SysLog(NID_UI, "[Window Order Group][Window : 0x%x] transient_for_set -> 0x%x", ownee, owner);
1397 }
1398
1399 void
1400 _EcoreEvas::ActivateWindow(const _Window& window)
1401 {
1402         _EflLayer* pLayer = GetEflLayer(window);
1403         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1404
1405         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1406         SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1407
1408         ecore_evas_activate(pEcoreEvas);
1409
1410         NativeWindowHandle currentWindow = window.GetNativeHandle();
1411         unsigned int activeWindow = GetActiveWindow();
1412         int pid = GetProcessId(activeWindow);
1413         SysLog(NID_UI, "currentWindow = 0x%x, activeWindow = 0x%x, pid = %d", currentWindow, activeWindow, pid);
1414
1415         SetLastResult(E_SUCCESS);
1416 }
1417
1418 void
1419 _EcoreEvas::MinimizeWindow(_Window& window)
1420 {
1421         _EflLayer* pLayer = GetEflLayer(window);
1422         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1423
1424         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1425         SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1426
1427         //ecore_evas_lower(pEcoreEvas);
1428         ecore_evas_iconified_set(pEcoreEvas, EINA_TRUE);
1429
1430         SetLastResult(E_SUCCESS);
1431 }
1432
1433 void
1434 _EcoreEvas::SetRenderBackend(_RenderBackend backend)
1435 {
1436         switch (backend)
1437         {
1438         case _RENDER_BACKEND_SW:
1439                 elm_config_preferred_engine_set("software_x11");
1440                 break;
1441         case _RENDER_BACKEND_GL:
1442                 elm_config_preferred_engine_set("opengl_x11");
1443                 break;
1444         case _RENDER_BACKEND_DEFAULT:
1445                 // fall through
1446         default:
1447                 elm_config_preferred_engine_set(NULL);
1448                 break;
1449         }
1450 }
1451
1452 _RenderBackend
1453 _EcoreEvas::GetRenderBackend(void)
1454 {
1455         _RenderBackend backend = _RENDER_BACKEND_DEFAULT;
1456
1457         const char* pEngine = elm_config_preferred_engine_get();
1458
1459         if (pEngine == NULL)
1460         {
1461                 backend = _RENDER_BACKEND_DEFAULT;
1462         }
1463         else if (strcmp(pEngine, "software_x11") == 0)
1464         {
1465                 backend = _RENDER_BACKEND_SW;
1466         }
1467         else if (strcmp(pEngine, "opengl_x11") == 0)
1468         {
1469                 backend = _RENDER_BACKEND_GL;
1470         }
1471
1472         return backend;
1473 }
1474
1475 result
1476 _EcoreEvas::CopyClip(_ClipFormat format, const char* pChar)
1477 {
1478         SysTryReturn(NID_UI, IsValidClipFormat(format), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The data type is invalid.");
1479         SysTryReturn(NID_UI, pChar, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The data is invalid.");
1480
1481         Ecore_X_Atom dataType = 0;
1482
1483         switch (format)
1484         {
1485         case _CLIP_FORMAT_TEXT:
1486                 dataType = ecore_x_atom_get("UTF8_STRING");
1487                 break;
1488         case _CLIP_FORMAT_IMAGE:
1489                 dataType = ecore_x_atom_get("text/uri");
1490                 break;
1491         case _CLIP_FORMAT_HTML:
1492                 dataType = ecore_x_atom_get("text/html;charset=utf-8");
1493                 break;
1494         default:
1495                 break;
1496         }
1497
1498         _ControlManager* pControlManager = _ControlManager::GetInstance();
1499
1500         _Window* pWindow = pControlManager->GetClipboardOwner();
1501         if (!pWindow)
1502         {
1503                 return E_SUCCESS;
1504         }
1505
1506         _EflLayer* pLayer = GetEflLayer(*pWindow);
1507         if (!pLayer)
1508         {
1509                 return E_SUCCESS;
1510         }
1511
1512         Ecore_X_Window window = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
1513         SysAssert(window);
1514
1515         SetCbhmItem(window, dataType, (char*)pChar);
1516
1517         return E_SUCCESS;
1518 }
1519
1520 bool
1521 _EcoreEvas::RetrieveClipN(int index, int* format, char** pData)
1522 {
1523         Ecore_X_Atom dataType = 0;
1524
1525         _ControlManager* pControlManager = _ControlManager::GetInstance();
1526
1527         _Window* pWindow = pControlManager->GetClipboardOwner();
1528         if (!pWindow)
1529         {
1530                 return false;
1531         }
1532
1533         _EflLayer* pLayer = GetEflLayer(*pWindow);
1534         if (!pLayer)
1535         {
1536                 return false;
1537         }
1538
1539         GetCbhmItem(index, &dataType, pData);
1540
1541         if ((dataType == ecore_x_atom_get("UTF8_STRING"))
1542                 ||(dataType == ecore_x_atom_get("application/x-elementary-markup")))
1543         {
1544                 *format = _CLIP_FORMAT_TEXT;
1545         }
1546         else if (dataType == ecore_x_atom_get("text/uri"))
1547         {
1548                 *format = _CLIP_FORMAT_IMAGE;
1549         }
1550         else if (dataType == ecore_x_atom_get("text/html;charset=utf-8"))
1551         {
1552                 *format = _CLIP_FORMAT_HTML;
1553         }
1554
1555         if (*pData == null)
1556         {
1557                 return false;
1558         }
1559
1560         // Convert markup to utf8.
1561         if (dataType == ecore_x_atom_get("application/x-elementary-markup"))
1562         {
1563                 char* pTempChar = evas_textblock_text_markup_to_utf8(NULL, *pData);
1564                 SysLog(NID_UI, "[Clipboard] markup[%s] -> utf8[%s]", *pData, pTempChar);
1565                 free(*pData);
1566
1567                 *pData = pTempChar;
1568         }
1569
1570         return true;
1571 }
1572
1573 int
1574 _EcoreEvas::GetClipCount(void) const
1575 {
1576         _ControlManager* pControlManager = _ControlManager::GetInstance();
1577
1578         _Window* pWindow = pControlManager->GetClipboardOwner();
1579         if (!pWindow)
1580         {
1581                 return 0;
1582         }
1583
1584         _EflLayer* pLayer = GetEflLayer(*pWindow);
1585         if (!pLayer)
1586         {
1587                 return 0;
1588         }
1589
1590         int count = GetCbhmItemCount();
1591
1592         return count;
1593 }
1594
1595 void
1596 _EcoreEvas::OpenClipboard(unsigned long clipFormats)
1597 {
1598         _ControlManager* pControlManager = _ControlManager::GetInstance();
1599
1600         _Window* pWindow = pControlManager->GetClipboardOwner();
1601         if (!pWindow)
1602         {
1603                 return;
1604         }
1605
1606         _EflLayer* pLayer = GetEflLayer(*pWindow);
1607         if (!pLayer)
1608         {
1609                 return;
1610         }
1611
1612         Ecore_X_Window window = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
1613         SysAssert(window);
1614
1615         ecore_x_selection_secondary_set(window, "", 1);
1616
1617         if (_CLIP_FORMAT_IMAGE & clipFormats)
1618         {
1619                 SendCbhmMessage(window, ATOM_CBHM_CLIPBOARD_SHOW_ALL);
1620         }
1621         else
1622         {
1623                 SendCbhmMessage(window, ATOM_CBHM_CLIPBOARD_SHOW);
1624         }
1625
1626         __openClipboard = true;
1627 }
1628
1629 void
1630 _EcoreEvas::CloseClipboard(void)
1631 {
1632         _ControlManager* pControlManager = _ControlManager::GetInstance();
1633
1634         _Window* pWindow = pControlManager->GetClipboardOwner();
1635         if (!pWindow)
1636         {
1637                 return;
1638         }
1639
1640         _EflLayer* pLayer = GetEflLayer(*pWindow);
1641         if (!pLayer)
1642         {
1643                 return;
1644         }
1645
1646         Ecore_X_Window window = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
1647         SysAssert(window);
1648
1649         __openClipboard = false;
1650         SendCbhmMessage(window, ATOM_CBHM_CLIPBOARD_HIDE);
1651 }
1652
1653 bool
1654 _EcoreEvas::IsClipboardOpened(void)
1655 {
1656         return __openClipboard;
1657 }
1658
1659 result
1660 _EcoreEvas::SetEventPropagation(const _Control& control, bool enable)
1661 {
1662         _EflNode* pEflNode = dynamic_cast<_EflNode*>(control.GetVisualElement()->GetNativeNode());
1663         SysTryReturn(NID_UI, pEflNode, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1664
1665         Evas_Object* pEvasObject = (Evas_Object*) pEflNode->GetGroupContainer();
1666         SysTryReturn(NID_UI, pEvasObject, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1667
1668         evas_object_propagate_events_set(pEvasObject, (enable ? EINA_TRUE : EINA_FALSE));
1669
1670         return E_SUCCESS;
1671 }
1672
1673 result
1674 _EcoreEvas::SetFocus(const _Control& control, bool focus)
1675 {
1676         _EflNode* pEflNode = dynamic_cast<_EflNode*>(control.GetVisualElement()->GetNativeNode());
1677         SysTryReturn(NID_UI, pEflNode, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1678
1679         Evas_Object* pEvasObject = (Evas_Object*) pEflNode->GetGroupContainer();
1680         SysTryReturn(NID_UI, pEvasObject, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1681
1682         evas_object_focus_set(pEvasObject, (focus ? EINA_TRUE : EINA_FALSE));
1683
1684         return E_SUCCESS;
1685 }
1686
1687 result
1688 _EcoreEvas::SetIndicatorShowState(const _Window& window, bool showState)
1689 {
1690         _EflLayer* pLayer = GetEflLayer(window);
1691         SysTryReturn(NID_UI, pLayer, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1692
1693         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1694         SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1695
1696         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1697
1698         if (showState)
1699         {
1700                 ecore_x_e_illume_indicator_state_set(win, ECORE_X_ILLUME_INDICATOR_STATE_ON);
1701         }
1702         else
1703         {
1704                 ecore_x_e_illume_indicator_state_set(win, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
1705         }
1706
1707         return E_SUCCESS;
1708 }
1709
1710 bool
1711 _EcoreEvas::GetIndicatorShowState(const _Window& window) const
1712 {
1713         _EflLayer* pLayer = GetEflLayer(window);
1714         SysTryReturn(NID_UI, pLayer, false, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1715
1716         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1717         SysTryReturn(NID_UI, pEcoreEvas, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1718
1719         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1720         Ecore_X_Illume_Indicator_State state = ecore_x_e_illume_indicator_state_get(win);
1721
1722         bool showState = true;
1723         if (state == ECORE_X_ILLUME_INDICATOR_STATE_ON)
1724         {
1725                 showState = true;
1726         }
1727         else if (state == ECORE_X_ILLUME_INDICATOR_STATE_OFF)
1728         {
1729                 showState = false;
1730         }
1731
1732         return showState;
1733 }
1734
1735 // [ToDo] Remove API
1736 Rectangle
1737 _EcoreEvas::GetIndicatorBounds(const _Window& window) const
1738 {
1739         _EflLayer* pLayer = GetEflLayer(window);
1740         SysTryReturn(NID_UI, pLayer, Rectangle(0, 0, 0, 0), E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1741
1742         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1743         SysTryReturn(NID_UI, pEcoreEvas, Rectangle(0, 0, 0, 0), E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1744
1745         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1746         Ecore_X_Window rootWin = (Ecore_X_Window) ecore_x_window_root_get(win);
1747
1748         int x = 0;
1749         int y = 0;
1750         int width = 0;
1751         int height = 0;
1752
1753         bool ret = false;
1754         ret = ecore_x_e_illume_indicator_geometry_get(rootWin, &x, &y, &width, &height);
1755         SysTryReturn(NID_UI, ret == true, Rectangle(0, 0, 0, 0), E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1756
1757         SetLastResult(E_SUCCESS);
1758
1759         return Rectangle(x, y, width, height);
1760 }
1761
1762 // [ToDo] Remove API
1763 result
1764 _EcoreEvas::SetIndicatorOpacity(const _Window& window, _IndicatorOpacity opacity)
1765 {
1766         _EflLayer* pLayer = GetEflLayer(window);
1767         SysTryReturn(NID_UI, pLayer, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1768
1769         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1770         SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1771
1772         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1773
1774         Ecore_X_Illume_Indicator_Opacity_Mode mode = ECORE_X_ILLUME_INDICATOR_OPACITY_UNKNOWN;
1775         switch (opacity)
1776         {
1777         case _INDICATOR_OPACITY_UNKNOWN:
1778                 mode = ECORE_X_ILLUME_INDICATOR_OPACITY_UNKNOWN;
1779                 break;
1780         case _INDICATOR_OPACITY_OPAQUE:
1781                 mode = ECORE_X_ILLUME_INDICATOR_OPAQUE;
1782                 break;
1783         case _INDICATOR_OPACITY_TRANSLUCENT:
1784                 mode = ECORE_X_ILLUME_INDICATOR_TRANSLUCENT;
1785                 break;
1786         case _INDICATOR_OPACITY_TRANSPARENT:
1787                 mode = ECORE_X_ILLUME_INDICATOR_TRANSPARENT;
1788                 break;
1789         default:
1790                 SysLogException(NID_UI, E_INVALID_ARG, "[E_INVALID_ARG] The specified data is not valid.");
1791                 return E_INVALID_ARG;
1792         }
1793
1794         ecore_x_e_illume_indicator_opacity_set(win, mode);
1795
1796         return E_SUCCESS;
1797 }
1798
1799 // [ToDo] Remove API
1800 _IndicatorOpacity
1801 _EcoreEvas::GetIndicatorOpacity(const _Window& window) const
1802 {
1803         _EflLayer* pLayer = GetEflLayer(window);
1804         SysTryReturn(NID_UI, pLayer, _INDICATOR_OPACITY_UNKNOWN, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1805
1806         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1807         SysTryReturn(NID_UI, pEcoreEvas, _INDICATOR_OPACITY_UNKNOWN, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1808
1809         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1810         Ecore_X_Illume_Indicator_Opacity_Mode mode = ecore_x_e_illume_indicator_opacity_get(win);
1811
1812         _IndicatorOpacity opacity = _INDICATOR_OPACITY_UNKNOWN;
1813         switch (mode)
1814         {
1815         case ECORE_X_ILLUME_INDICATOR_OPACITY_UNKNOWN:
1816                 opacity = _INDICATOR_OPACITY_UNKNOWN;
1817                 break;
1818         case ECORE_X_ILLUME_INDICATOR_OPAQUE:
1819                 opacity = _INDICATOR_OPACITY_OPAQUE;
1820                 break;
1821         case ECORE_X_ILLUME_INDICATOR_TRANSLUCENT:
1822                 opacity = _INDICATOR_OPACITY_TRANSLUCENT;
1823                 break;
1824         case ECORE_X_ILLUME_INDICATOR_TRANSPARENT:
1825                 opacity = _INDICATOR_OPACITY_TRANSPARENT;
1826                 break;
1827         default:
1828                 SysLogException(NID_UI, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1829                 return _INDICATOR_OPACITY_UNKNOWN;
1830         }
1831
1832         SetLastResult(E_SUCCESS);
1833
1834         return opacity;
1835 }
1836
1837 void
1838 _EcoreEvas::SetWindowActivationEnabled(const _Window& window, bool enable)
1839 {
1840         _EflLayer* pLayer = GetEflLayer(window);
1841         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1842
1843         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1844         SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1845
1846         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1847
1848         Eina_Bool acceptsFocus;
1849         Ecore_X_Window_State_Hint initialState;
1850         Ecore_X_Pixmap iconPixmap;
1851         Ecore_X_Pixmap iconMask;
1852         Ecore_X_Window iconWindow;
1853         Ecore_X_Window windowGroup;
1854         Eina_Bool isUrgent;
1855
1856         ecore_x_icccm_hints_get(win, &acceptsFocus, &initialState, &iconPixmap, &iconMask, &iconWindow, &windowGroup, &isUrgent);
1857         ecore_x_icccm_hints_set(win, (enable ? EINA_TRUE : EINA_FALSE), initialState, iconPixmap, iconMask, iconWindow, windowGroup, isUrgent);
1858 }
1859
1860 bool
1861 _EcoreEvas::IsWindowActivationEnabled(const _Window& window)
1862 {
1863         _EflLayer* pLayer = GetEflLayer(window);
1864         SysTryReturn(NID_UI, pLayer, true, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1865
1866         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1867         SysTryReturn(NID_UI, pEcoreEvas, true, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1868
1869         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1870
1871         Eina_Bool acceptsFocus;
1872         Ecore_X_Window_State_Hint initialState;
1873         Ecore_X_Pixmap iconPixmap;
1874         Ecore_X_Pixmap iconMask;
1875         Ecore_X_Window iconWindow;
1876         Ecore_X_Window windowGroup;
1877         Eina_Bool isUrgent;
1878
1879         ecore_x_icccm_hints_get(win, &acceptsFocus, &initialState, &iconPixmap, &iconMask, &iconWindow, &windowGroup, &isUrgent);
1880
1881         return (acceptsFocus ? true : false);
1882 }
1883
1884 void
1885 _EcoreEvas::SetWindowName(const _Window& window, const Tizen::Base::String& name)
1886 {
1887         _EflLayer* pLayer = GetEflLayer(window);
1888         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1889
1890         Evas_Object* pWinObj = pLayer->GetElmWin();
1891         SysTryReturnVoidResult(NID_UI, pWinObj, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1892
1893         const char* windowName = _StringConverter::CopyToCharArrayN(name);
1894         if (windowName)
1895         {
1896                 elm_win_title_set(pWinObj, windowName);
1897
1898                 delete[] windowName;
1899         }
1900 }
1901
1902 void
1903 _EcoreEvas::SetWindowType(const _Window& window, int winType)
1904 {
1905         _EflLayer* pLayer = GetEflLayer(window);
1906         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1907
1908         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1909         SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1910
1911         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1912
1913         if (winType == _WINDOW_TYPE_SUB)
1914         {
1915                 ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_UTILITY);
1916         }
1917 }
1918
1919 result
1920 _EcoreEvas::SetFloatingMode(const _Window& window, bool enable)
1921 {
1922         _EflLayer* pLayer = GetEflLayer(window);
1923         SysTryReturn(NID_UI, pLayer, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
1924
1925         Evas_Object* pWinObj = pLayer->GetElmWin();
1926         SysTryReturn(NID_UI, pWinObj, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1927
1928         elm_win_floating_mode_set(pWinObj, (enable ? EINA_TRUE : EINA_FALSE));
1929
1930         return E_SUCCESS;
1931 }
1932
1933 // [ToDo] Remove API
1934 Evas*
1935 _EcoreEvas::GetEvas(void) const
1936 {
1937         SysLog(NID_UI, "Do not use.");
1938         _Window* pWindow = _ControlManager::GetInstance()->GetCurrentFrame();
1939         if (!pWindow)
1940         {
1941                 return null;
1942         }
1943
1944         _EflLayer* pLayer = GetEflLayer(*pWindow);
1945         if (!pLayer)
1946         {
1947                 return null;
1948         }
1949
1950         return pLayer->GetEvas();
1951 }
1952
1953 // [ToDo] Remove API
1954 Ecore_Evas*
1955 _EcoreEvas::GetEcoreEvas(void) const
1956 {
1957         SysLog(NID_UI, "Do not use.");
1958         _Window* pWindow = _ControlManager::GetInstance()->GetCurrentFrame();
1959         if (!pWindow)
1960         {
1961                 return null;
1962         }
1963
1964         _EflLayer* pLayer = GetEflLayer(*pWindow);
1965         if (!pLayer)
1966         {
1967                 return null;
1968         }
1969
1970         return pLayer->GetEcoreEvas();
1971 }
1972
1973 // [ToDo] Remove API
1974 Evas_Object*
1975 _EcoreEvas::GetWindowObject(void) const
1976 {
1977         SysLog(NID_UI, "Do not use.");
1978         _Window* pWindow = _ControlManager::GetInstance()->GetCurrentFrame();
1979         if (!pWindow)
1980         {
1981                 return null;
1982         }
1983
1984         _EflLayer* pLayer = GetEflLayer(*pWindow);
1985         if (!pLayer)
1986         {
1987                 return null;
1988         }
1989
1990         return pLayer->GetElmWin();
1991 }
1992
1993 // [ToDo] Remove API
1994 Ecore_X_Window
1995 _EcoreEvas::GetXWindow(void) const
1996 {
1997         SysLog(NID_UI, "Do not use.");
1998         _Window* pWindow = _ControlManager::GetInstance()->GetCurrentFrame();
1999         if (!pWindow)
2000         {
2001                 return 0;
2002         }
2003
2004         _EflLayer* pLayer = GetEflLayer(*pWindow);
2005         if (!pLayer)
2006         {
2007                 return 0;
2008         }
2009
2010         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
2011
2012         return win;
2013 }
2014
2015 void
2016 _EcoreEvas::AllowSetWindowBounds(bool allow)
2017 {
2018         __changeBounds = allow;
2019 }
2020
2021 bool
2022 _EcoreEvas::IsWindowVisible(const _Window& window)
2023 {
2024         _EflLayer* pLayer = GetEflLayer(window);
2025         SysTryReturn(NID_UI, pLayer, false, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
2026
2027         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
2028         SysTryReturn(NID_UI, pEcoreEvas, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2029
2030         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
2031
2032         int ret = ecore_x_window_visible_get(win);
2033         if (ret == 1)
2034         {
2035                 return true;
2036         }
2037         else
2038         {
2039                 return false;
2040         }
2041 }
2042
2043 // [ToDo] Remove API
2044 void
2045 _EcoreEvas::SetQuickPanelScrollEnabled(const _Window& window, bool enable)
2046 {
2047         /*
2048         _EflLayer* pLayer = GetEflLayer(window);
2049         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
2050
2051         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
2052         SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2053
2054         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
2055         Ecore_X_Atom atomPanelScrollable = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
2056
2057         unsigned int val[3];
2058         ecore_x_window_prop_card32_get(win, atomPanelScrollable, val, 3);
2059
2060         if (enable)
2061         {
2062                 val[1] = 1;
2063         }
2064         else
2065         {
2066                 val[1] = 0;
2067         }
2068
2069         ecore_x_window_prop_card32_set(win, atomPanelScrollable, val, 3);
2070         */
2071 }
2072
2073 // [ToDo] Remove API
2074 bool
2075 _EcoreEvas::IsQuickPanelScrollEnabled(const _Window& window)
2076 {
2077         /*
2078         _EflLayer* pLayer = GetEflLayer(window);
2079         SysTryReturn(NID_UI, pLayer, false, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
2080
2081         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
2082         SysTryReturn(NID_UI, pEcoreEvas, false, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2083
2084         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
2085         Ecore_X_Atom atomPanelScrollable = ecore_x_atom_get("_E_MOVE_PANEL_SCROLLABLE_STATE");
2086
2087         unsigned int val[3];
2088         ecore_x_window_prop_card32_get(win, atomPanelScrollable, val, 3);
2089
2090         if (val[1] == 0)
2091         {
2092                 return false;
2093         }
2094         else
2095         {
2096                 return true;
2097         }
2098         */
2099
2100         return true;
2101 }
2102
2103 void
2104 _EcoreEvas::SetWindowLevel(const _Window& window, _WindowLevel level)
2105 {
2106         _EflLayer* pLayer = GetEflLayer(window);
2107         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
2108
2109         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
2110         SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2111
2112         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
2113         ecore_x_icccm_transient_for_unset(win);
2114
2115         if (level == _WINDOW_LEVEL_NORMAL)
2116         {
2117                 ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_NORMAL);
2118         }
2119         else if (level == _WINDOW_LEVEL_NOTIFICATION_HIGH)
2120         {
2121                 ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_NOTIFICATION);
2122                 utilx_set_system_notification_level((Display*)ecore_x_display_get(), win, UTILX_NOTIFICATION_LEVEL_HIGH);
2123         }
2124         else if (level == _WINDOW_LEVEL_NOTIFICATION_MIDDLE)
2125         {
2126                 ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_NOTIFICATION);
2127                 utilx_set_system_notification_level((Display*)ecore_x_display_get(), win, UTILX_NOTIFICATION_LEVEL_NORMAL);
2128         }
2129
2130         SetLastResult(E_SUCCESS);
2131 }
2132
2133 _WindowLevel
2134 _EcoreEvas::GetWindowLevel(const _Window& window) const
2135 {
2136         _EflLayer* pLayer = GetEflLayer(window);
2137         SysTryReturn(NID_UI, pLayer, _WINDOW_LEVEL_UNKNOWN, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
2138
2139         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
2140         SysTryReturn(NID_UI, pEcoreEvas, _WINDOW_LEVEL_UNKNOWN, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2141
2142         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
2143
2144         Ecore_X_Window_Type type = ECORE_X_WINDOW_TYPE_UNKNOWN;
2145         ecore_x_netwm_window_type_get(win, &type);
2146
2147         _WindowLevel winLevel = _WINDOW_LEVEL_UNKNOWN;
2148         if (type == ECORE_X_WINDOW_TYPE_NORMAL)
2149         {
2150                 winLevel = _WINDOW_LEVEL_NORMAL;
2151         }
2152         else if (type == ECORE_X_WINDOW_TYPE_NOTIFICATION)
2153         {
2154                 Utilx_Notification_Level notificationLevel = utilx_get_system_notification_level((Display*)ecore_x_display_get(), win);
2155
2156                 if (notificationLevel == UTILX_NOTIFICATION_LEVEL_HIGH)
2157                 {
2158                         winLevel = _WINDOW_LEVEL_NOTIFICATION_HIGH;
2159                 }
2160                 else if (notificationLevel == UTILX_NOTIFICATION_LEVEL_NORMAL)
2161                 {
2162                         winLevel = _WINDOW_LEVEL_NOTIFICATION_MIDDLE;
2163                 }
2164         }
2165
2166         SetLastResult(E_SUCCESS);
2167
2168         return winLevel;
2169 }
2170
2171 void
2172 _EcoreEvas::SetWindowBounds(const _Window& window, const Rectangle& bounds)
2173 {
2174         if (__changeBounds == false)
2175         {
2176                 return;
2177         }
2178
2179         _EflLayer* pLayer = GetEflLayer(window);
2180         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
2181
2182         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
2183         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
2184
2185         Evas_Object* pWinObject = pLayer->GetElmWin();
2186         SysTryReturnVoidResult(NID_UI, pWinObject, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2187
2188         Rectangle winBounds = _CoordinateSystemUtils::Transform(bounds);
2189
2190         int rotate = ecore_evas_rotation_get(pEcoreEvas);
2191
2192         _Window* pWindow = const_cast<_Window*>(&window);
2193
2194         _ContextMenu* pContextMenu = dynamic_cast<_ContextMenu*>(pWindow);
2195         if (pContextMenu)
2196         {
2197                 // [Exception]
2198                 // ContextMenu
2199                 // Skip
2200
2201                 _ControlManager* pControlManager = _ControlManager::GetInstance();
2202                 if (pControlManager)
2203                 {
2204                         _Window* pCurFrame = pControlManager->GetCurrentFrame();
2205                         if (pCurFrame)
2206                         {
2207                                 int ownerRotate = GetWindowRotation(*pCurFrame);
2208                                 if (ownerRotate != rotate)
2209                                 {
2210                                         return;
2211                                 }
2212                         }
2213                 }
2214         }
2215
2216         int winX = winBounds.x;
2217         int winY = winBounds.y;
2218
2219         int rootW = 0;
2220         int rootH = 0;
2221         ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
2222
2223         switch (rotate)
2224         {
2225         case 270:
2226                 winX = rootW - winBounds.y - winBounds.height;
2227                 winY = winBounds.x;
2228                 break;
2229         case 90:
2230                 winX = winBounds.y;
2231                 winY = rootH - winBounds.x - winBounds.width;
2232                 break;
2233         case 180:
2234                 winX = rootW - winBounds.x - winBounds.width;
2235                 winY = rootH - winBounds.y - winBounds.height;
2236                 break;
2237         default:
2238                 break;
2239         }
2240
2241         int x = 0;
2242         int y = 0;
2243         int w = 0;
2244         int h = 0;
2245         Eina_Bool ret = ecore_x_e_window_rotation_geometry_get(win, rotate, &x, &y, &w, &h);
2246
2247         evas_object_move(pWinObject, winX, winY);
2248
2249         if (ret == EINA_FALSE)
2250         {
2251                 evas_object_resize(pWinObject, winBounds.width, winBounds.height);
2252                 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] Set bounds(rot = %d, %d, %d, %d, %d).", win, rotate, winX, winY, winBounds.width, winBounds.height);
2253         }
2254         else
2255         {
2256                 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] Set bounds(rot = %d, %d, %d) ONLY MOVE.", win, rotate, winX, winY);
2257         }
2258
2259         SetLastResult(E_SUCCESS);
2260 }
2261
2262 void
2263 _EcoreEvas::SetWindowBounds(const _Window& window, const FloatRectangle& bounds)
2264 {
2265         if (__changeBounds == false)
2266         {
2267                 return;
2268         }
2269
2270         _EflLayer* pLayer = GetEflLayer(window);
2271         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
2272
2273         Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
2274         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
2275
2276         Evas_Object* pWinObject = pLayer->GetElmWin();
2277         SysTryReturnVoidResult(NID_UI, pWinObject, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2278
2279         FloatRectangle winBoundsF = _CoordinateSystemUtils::Transform(bounds);
2280         Rectangle winBounds = _CoordinateSystemUtils::ConvertToInteger(winBoundsF);
2281
2282         int rotate = ecore_evas_rotation_get(pEcoreEvas);
2283
2284         _Window* pWindow = const_cast<_Window*>(&window);
2285
2286         _ContextMenu* pContextMenu = dynamic_cast<_ContextMenu*>(pWindow);
2287         if (pContextMenu)
2288         {
2289                 // [Exception]
2290                 // ContextMenu
2291                 // Skip
2292
2293                 _ControlManager* pControlManager = _ControlManager::GetInstance();
2294                 if (pControlManager)
2295                 {
2296                         _Window* pCurFrame = pControlManager->GetCurrentFrame();
2297                         if (pCurFrame)
2298                         {
2299                                 int ownerRotate = GetWindowRotation(*pCurFrame);
2300                                 if (ownerRotate != rotate)
2301                                 {
2302                                         return;
2303                                 }
2304                         }
2305                 }
2306         }
2307
2308         int winX = winBounds.x;
2309         int winY = winBounds.y;
2310
2311         int rootW = 0;
2312         int rootH = 0;
2313         ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
2314
2315         switch (rotate)
2316         {
2317         case 270:
2318                 winX = rootW - winBounds.y - winBounds.height;
2319                 winY = winBounds.x;
2320                 break;
2321         case 90:
2322                 winX = winBounds.y;
2323                 winY = rootH - winBounds.x - winBounds.width;
2324                 break;
2325         case 180:
2326                 winX = rootW - winBounds.x - winBounds.width;
2327                 winY = rootH - winBounds.y - winBounds.height;
2328                 break;
2329         default:
2330                 break;
2331         }
2332
2333         int x = 0;
2334         int y = 0;
2335         int w = 0;
2336         int h = 0;
2337         Eina_Bool ret = ecore_x_e_window_rotation_geometry_get(win, rotate, &x, &y, &w, &h);
2338
2339         evas_object_move(pWinObject, winX, winY);
2340
2341         if (ret == EINA_FALSE)
2342         {
2343                 evas_object_resize(pWinObject, winBounds.width, winBounds.height);
2344                 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] Set bounds(rot = %d, %d, %d, %d, %d).", win, rotate, winX, winY, winBounds.width, winBounds.height);
2345         }
2346         else
2347         {
2348                 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] Set bounds(rot = %d, %d, %d) ONLY MOVE.", win, rotate, winX, winY);
2349         }
2350
2351         SetLastResult(E_SUCCESS);
2352 }
2353
2354 void
2355 _EcoreEvas::SetWindowVisibleState(const _Window& window, bool visibleState)
2356 {
2357         _EflLayer* pLayer = GetEflLayer(window);
2358         SysTryReturnVoidResult(NID_UI, pLayer, E_INVALID_ARG, "[E_INVALID_ARG] The window doesn't have a elf layer.");
2359
2360         Evas_Object* pWinObj = pLayer->GetElmWin();
2361         SysTryReturnVoidResult(NID_UI, pWinObj, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2362
2363         pLayer->SetShowState(visibleState);
2364
2365         SetLastResult(E_SUCCESS);
2366 }
2367
2368 void
2369 _EcoreEvas::SetOwner(const _Window& ownee, const _Control& owner)
2370 {
2371         _Window* pOwnerWindow = owner.GetRootWindow();
2372         SysTryReturnVoidResult(NID_UI, pOwnerWindow, E_INVALID_ARG, "[E_INVALID_ARG] The owner doesn't have a root window.");
2373
2374         _EflLayer* pOwnerLayer = GetEflLayer(*pOwnerWindow);
2375         SysTryReturnVoidResult(NID_UI, pOwnerLayer, E_INVALID_ARG, "[E_INVALID_ARG] The owner doesn't have a elf layer.");
2376
2377         _EflLayer* pOwneeLayer = GetEflLayer(ownee);
2378         SysTryReturnVoidResult(NID_UI, pOwneeLayer, E_INVALID_ARG, "[E_INVALID_ARG] The ownee doesn't have a elf layer.");
2379
2380         Ecore_X_Window ownerWin = (Ecore_X_Window) ecore_evas_window_get(pOwnerLayer->GetEcoreEvas());
2381         Ecore_X_Window owneeWin = (Ecore_X_Window) ecore_evas_window_get(pOwneeLayer->GetEcoreEvas());
2382
2383         Ecore_X_Window_Type type;
2384         ecore_x_netwm_window_type_get(owneeWin, &type);
2385         if ((type == ECORE_X_WINDOW_TYPE_NORMAL) || (type == ECORE_X_WINDOW_TYPE_UTILITY))
2386         {
2387                 ecore_x_icccm_transient_for_unset(owneeWin);
2388                 ecore_x_icccm_transient_for_set(owneeWin, ownerWin);
2389                 SysLog(NID_UI, "[Window Order Group][Window : 0x%x] transient_for_set -> 0x%x", owneeWin, ownerWin);
2390         }
2391         else
2392         {
2393                 SysLog(NID_UI, "[Window Order Group][Window : 0x%x] Skip to transient_for_set", owneeWin);
2394         }
2395
2396         // Ownee window
2397         // 1. IsLayoutChangable : true
2398         // 2. IsRotationSynchronized : true
2399         // -> available_set
2400
2401         if ((ownee.IsLayoutChangable() == true) || (ownee.IsRotationSynchronized() == true))
2402         {
2403                 int* rotations = null;
2404                 unsigned int count = 0;
2405                 Eina_Bool ret = ecore_evas_wm_rotation_available_rotations_get(pOwnerLayer->GetEcoreEvas(), &rotations, &count);
2406
2407                 if (ret)
2408                 {
2409                         if (rotations)
2410                         {
2411                                 SetWindowAvailabledRotation(ownee, rotations, count);
2412                                 free(rotations);
2413                         }
2414                 }
2415
2416                 bool preferredRoation = pOwnerWindow->GetPreferredRotation();
2417                 if (preferredRoation == true)
2418                 {
2419                         int preferredRotation = ecore_evas_wm_rotation_preferred_rotation_get(pOwnerLayer->GetEcoreEvas());
2420                         SetWindowPreferredRotation(ownee, preferredRotation);
2421                 }
2422                 else
2423                 {
2424                         SetWindowPreferredRotation(ownee, -1);
2425                 }
2426         }
2427         else
2428         {
2429                 int ownerRotation = GetWindowRotation(*pOwnerWindow);
2430                 SetWindowPreferredRotation(ownee, ownerRotation);
2431         }
2432
2433         SetLastResult(E_SUCCESS);
2434 }
2435
2436 int
2437 _EcoreEvas::GetWindowRotation(const _Window& window)
2438 {
2439         _EflLayer* pLayer = GetEflLayer(window);
2440         if (!pLayer)
2441         {
2442                 return 0;
2443         }
2444
2445         int rotation = ecore_evas_rotation_get(pLayer->GetEcoreEvas());
2446         return rotation;
2447 }
2448
2449 void
2450 _EcoreEvas::SetWindowPreferredRotation(const _Window& window, int rotation)
2451 {
2452         _EflLayer* pLayer = GetEflLayer(window);
2453         if (!pLayer)
2454         {
2455                 return;
2456         }
2457
2458         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
2459         SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] Set window preferred rotation(%d).", win, rotation);
2460         ecore_evas_wm_rotation_preferred_rotation_set(pLayer->GetEcoreEvas(), rotation);
2461
2462         _Window* pWindow = const_cast<_Window*>(&window);
2463         if (pWindow)
2464         {
2465                 if (rotation == -1)
2466                 {
2467                         pWindow->SetPreferredRotation(false);
2468                 }
2469                 else
2470                 {
2471                         pWindow->SetPreferredRotation(true);
2472                 }
2473         }
2474 }
2475
2476 void
2477 _EcoreEvas::SetWindowAvailabledRotation(const _Window& window, int* rotations, unsigned int count)
2478 {
2479         _EflLayer* pLayer = GetEflLayer(window);
2480         if (!pLayer)
2481         {
2482                 return;
2483         }
2484
2485         // Skip available_set if there is not change
2486
2487         int* prevRotations = null;
2488         unsigned int prevCount = 0;
2489         Eina_Bool ret = ecore_evas_wm_rotation_available_rotations_get(pLayer->GetEcoreEvas(), &prevRotations, &prevCount);
2490         free(prevRotations);
2491
2492         if (ret)
2493         {
2494                 if (prevCount == count)
2495                 {
2496                         return;
2497                 }
2498         }
2499
2500         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
2501         SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] Set window available rotation(%d).", win, count);
2502         ecore_evas_wm_rotation_available_rotations_set(pLayer->GetEcoreEvas(), rotations, count);
2503 }
2504
2505 void
2506 _EcoreEvas::RegisterWindowStateCallback(const _Window& window)
2507 {
2508         _EflLayer* pLayer = GetEflLayer(window);
2509         if (!pLayer)
2510         {
2511                 return;
2512         }
2513
2514         ecore_evas_callback_state_change_set(pLayer->GetEcoreEvas(), OnWindowStateChanged);
2515 }
2516
2517 void
2518 _EcoreEvas::SetWindowRotationBounds(const _Window& window, int rotation, const Tizen::Graphics::Rectangle& bounds)
2519 {
2520         _EflLayer* pLayer = GetEflLayer(window);
2521         if (!pLayer)
2522         {
2523                 return;
2524         }
2525
2526         Rectangle winBounds = _CoordinateSystemUtils::Transform(bounds);
2527
2528         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
2529         SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] Set rotation bounds(rot = %d, %d, %d, %d, %d).", win, rotation, winBounds.x, winBounds.y, winBounds.width, winBounds.height);
2530         ecore_x_e_window_rotation_geometry_set(win, rotation, winBounds.x, winBounds.y, winBounds.width, winBounds.height);
2531 }
2532
2533 void
2534 _EcoreEvas::SetWindowRotationBounds(const _Window& window, int rotation, const Tizen::Graphics::FloatRectangle& bounds)
2535 {
2536         _EflLayer* pLayer = GetEflLayer(window);
2537         if (!pLayer)
2538         {
2539                 return;
2540         }
2541
2542         FloatRectangle winBoundsF = _CoordinateSystemUtils::Transform(bounds);
2543         Rectangle winBounds = _CoordinateSystemUtils::ConvertToInteger(winBoundsF);
2544
2545         Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
2546         SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] Set rotation bounds(rot = %d, %d, %d, %d, %d).", win, rotation, winBounds.x, winBounds.y, winBounds.width, winBounds.height);
2547         ecore_x_e_window_rotation_geometry_set(win, rotation, winBounds.x, winBounds.y, winBounds.width, winBounds.height);
2548 }
2549
2550 // [ToDo] Remove API
2551 const _Control*
2552 _EcoreEvas::GetFrame(void) const
2553 {
2554         SysLog(NID_UI, "Do not use.");
2555         return __pFrame;
2556 }
2557
2558 // [ToDo] Remove API
2559 _RootVisualElement*
2560 _EcoreEvas::GetRootVisualElement(void)const
2561 {
2562         SysLog(NID_UI, "Do not use.");
2563         return null;
2564 }
2565
2566 // [ToDo] Remove API
2567 void
2568 _EcoreEvas::SetFrame(const _Control& control)
2569 {
2570         SysLog(NID_UI, "Do not use.");
2571         __pFrame = const_cast<_Control*>(&control);
2572 }
2573
2574 bool
2575 _EcoreEvas::GetSelectedCbhmItem(Ecore_X_Atom* pDataType, char** pBuffer) const
2576 {
2577         Ecore_X_Window cbhmWin = GetCbhmWindow();
2578         Ecore_X_Atom atomCbhmItem = ecore_x_atom_get(ATOM_CBHM_SELECTED_ITEM);
2579         Ecore_X_Atom atomItemType = 0;
2580
2581         char* pRet = (char*)GetCbhmReply(cbhmWin, atomCbhmItem, &atomItemType, NULL);
2582         if (pRet)
2583         {
2584                 Ecore_X_Atom x_atom_cbhm_error = ecore_x_atom_get(ATOM_CBHM_ERROR);
2585                 if (atomItemType == x_atom_cbhm_error)
2586                 {
2587                         free(pRet);
2588                         return false;
2589                 }
2590
2591                 if (pBuffer)
2592                 {
2593                         *pBuffer = pRet;
2594                 }
2595                 else
2596                 {
2597                         free(pRet);
2598                 }
2599
2600                 if (pDataType)
2601                 {
2602                         *pDataType = atomItemType;
2603                 }
2604
2605                 return true;
2606         }
2607
2608         return false;
2609 }
2610
2611 bool
2612 _EcoreEvas::IsAccessibilityScreenReaderActivated(void)
2613 {
2614         Eina_Bool acc = elm_config_access_get();
2615         return acc;
2616 }
2617
2618 void* _GetEcoreEvasHandle(void)
2619 {
2620         _EcoreEvasMgr* pEcoreEvasMgr = GetEcoreEvasMgr();
2621         if (pEcoreEvasMgr == null)
2622         {
2623                 return null;
2624         }
2625
2626         _EcoreEvas* pUiEcoreEvas = pEcoreEvasMgr->GetEcoreEvas();
2627         if (pUiEcoreEvas == null)
2628         {
2629                 return null;
2630         }
2631
2632         return (void*)pUiEcoreEvas->GetEcoreEvas();
2633 }
2634
2635 void* _GetEvasHandle(void)
2636 {
2637         _EcoreEvasMgr* pEcoreEvasMgr = GetEcoreEvasMgr();
2638         if (pEcoreEvasMgr == null)
2639         {
2640                 return null;
2641         }
2642
2643         _EcoreEvas* pUiEcoreEvas = pEcoreEvasMgr->GetEcoreEvas();
2644         if (pUiEcoreEvas == null)
2645         {
2646                 return null;
2647         }
2648
2649         return (void*)pUiEcoreEvas->GetEvas();
2650 }
2651
2652 result
2653 _EcoreEvas::InitializeAtomList(void)
2654 {
2655         __atomList[_ATOM_TARGETS].pName = "TARGETS";
2656         __atomList[_ATOM_TARGETS].formats = _CLIP_FORMAT_TARGETS;
2657         __atomList[_ATOM_TARGETS].convert = ConvertClipIntoTarget;
2658         __atomList[_ATOM_TARGETS].response = RequestClip;
2659         __atomList[_ATOM_TARGETS].notify = NotifyTarget;
2660         __atomList[_ATOM_TARGETS].atom = 0;
2661
2662         __atomList[_ATOM_ATOM].pName = "ATOM";
2663         __atomList[_ATOM_ATOM].formats = _CLIP_FORMAT_TARGETS;
2664         __atomList[_ATOM_ATOM].convert = ConvertClipIntoTarget;
2665         __atomList[_ATOM_ATOM].response = RequestClip;
2666         __atomList[_ATOM_ATOM].notify = NotifyTarget;
2667         __atomList[_ATOM_ATOM].atom = 0;
2668
2669         __atomList[_ATOM_XELM].pName = "application/x-elementary-markup";
2670         __atomList[_ATOM_XELM].formats = _CLIP_FORMAT_MARKUP;
2671         __atomList[_ATOM_XELM].convert = ConvertClipIntoEdje;
2672         __atomList[_ATOM_XELM].response = null;
2673         __atomList[_ATOM_XELM].notify = NotifyEdje;
2674         __atomList[_ATOM_XELM].atom = 0;
2675
2676         __atomList[_ATOM_TEXT_URI].pName = "text/uri";
2677         __atomList[_ATOM_TEXT_URI].formats = _CLIP_FORMAT_IMAGE;
2678         __atomList[_ATOM_TEXT_URI].convert = ConvertClipIntoUri;
2679         __atomList[_ATOM_TEXT_URI].response = null;
2680         __atomList[_ATOM_TEXT_URI].notify = NotifyUri;
2681         __atomList[_ATOM_TEXT_URI].atom = 0;
2682
2683         __atomList[_ATOM_TEXT_URILIST].pName = "text/uri-list";
2684         __atomList[_ATOM_TEXT_URILIST].formats = _CLIP_FORMAT_IMAGE;
2685         __atomList[_ATOM_TEXT_URILIST].convert = ConvertClipIntoUri;
2686         __atomList[_ATOM_TEXT_URILIST].response = null;
2687         __atomList[_ATOM_TEXT_URILIST].notify = NotifyUri;
2688         __atomList[_ATOM_TEXT_URILIST].atom = 0;
2689
2690         __atomList[_ATOM_TEXT_X_VCARD].pName = "text/x-vcard";
2691         __atomList[_ATOM_TEXT_X_VCARD].formats = _CLIP_FORMAT_VCARD;
2692         __atomList[_ATOM_TEXT_X_VCARD].convert = null;
2693         __atomList[_ATOM_TEXT_X_VCARD].response = null;
2694         __atomList[_ATOM_TEXT_X_VCARD].notify = null;
2695         __atomList[_ATOM_TEXT_X_VCARD].atom = 0;
2696
2697         __atomList[_ATOM_IMAGE_PNG].pName = "image/png";
2698         __atomList[_ATOM_IMAGE_PNG].formats = _CLIP_FORMAT_IMAGE;
2699         __atomList[_ATOM_IMAGE_PNG].convert = ConvertClipIntoImage;
2700         __atomList[_ATOM_IMAGE_PNG].response = null;
2701         __atomList[_ATOM_IMAGE_PNG].notify = NotifyImage;
2702         __atomList[_ATOM_IMAGE_PNG].atom = 0;
2703
2704         __atomList[_ATOM_IMAGE_JPEG].pName = "image/jpeg";
2705         __atomList[_ATOM_IMAGE_JPEG].formats = _CLIP_FORMAT_IMAGE;
2706         __atomList[_ATOM_IMAGE_JPEG].convert = ConvertClipIntoImage;
2707         __atomList[_ATOM_IMAGE_JPEG].response = null;
2708         __atomList[_ATOM_IMAGE_JPEG].notify = NotifyImage;
2709         __atomList[_ATOM_IMAGE_JPEG].atom = 0;
2710
2711         __atomList[_ATOM_IMAGE_BMP].pName = "image/x-ms-bmp";
2712         __atomList[_ATOM_IMAGE_BMP].formats = _CLIP_FORMAT_IMAGE;
2713         __atomList[_ATOM_IMAGE_BMP].convert = ConvertClipIntoImage;
2714         __atomList[_ATOM_IMAGE_BMP].response = null;
2715         __atomList[_ATOM_IMAGE_BMP].notify = NotifyImage;
2716         __atomList[_ATOM_IMAGE_BMP].atom = 0;
2717
2718         __atomList[_ATOM_IMAGE_GIF].pName = "image/gif";
2719         __atomList[_ATOM_IMAGE_GIF].formats = _CLIP_FORMAT_IMAGE;
2720         __atomList[_ATOM_IMAGE_GIF].convert = ConvertClipIntoImage;
2721         __atomList[_ATOM_IMAGE_GIF].response = null;
2722         __atomList[_ATOM_IMAGE_GIF].notify = NotifyImage;
2723         __atomList[_ATOM_IMAGE_GIF].atom = 0;
2724
2725         __atomList[_ATOM_IMAGE_TIFF].pName = "image/tiff";
2726         __atomList[_ATOM_IMAGE_TIFF].formats = _CLIP_FORMAT_IMAGE;
2727         __atomList[_ATOM_IMAGE_TIFF].convert = ConvertClipIntoImage;
2728         __atomList[_ATOM_IMAGE_TIFF].response = null;
2729         __atomList[_ATOM_IMAGE_TIFF].notify = NotifyImage;
2730         __atomList[_ATOM_IMAGE_TIFF].atom = 0;
2731
2732         __atomList[_ATOM_IMAGE_SVG].pName = "image/svg+xml";
2733         __atomList[_ATOM_IMAGE_SVG].formats = _CLIP_FORMAT_IMAGE;
2734         __atomList[_ATOM_IMAGE_SVG].convert = ConvertClipIntoImage;
2735         __atomList[_ATOM_IMAGE_SVG].response = null;
2736         __atomList[_ATOM_IMAGE_SVG].notify = NotifyImage;
2737         __atomList[_ATOM_IMAGE_SVG].atom = 0;
2738
2739         __atomList[_ATOM_IMAGE_XPM].pName = "image/x-xpixmap";
2740         __atomList[_ATOM_IMAGE_XPM].formats = _CLIP_FORMAT_IMAGE;
2741         __atomList[_ATOM_IMAGE_XPM].convert = ConvertClipIntoImage;
2742         __atomList[_ATOM_IMAGE_XPM].response = null;
2743         __atomList[_ATOM_IMAGE_XPM].notify = NotifyImage;
2744         __atomList[_ATOM_IMAGE_XPM].atom = 0;
2745
2746         __atomList[_ATOM_IMAGE_TGA].pName = "image/x-tga";
2747         __atomList[_ATOM_IMAGE_TGA].formats = _CLIP_FORMAT_IMAGE;
2748         __atomList[_ATOM_IMAGE_TGA].convert = ConvertClipIntoImage;
2749         __atomList[_ATOM_IMAGE_TGA].response = null;
2750         __atomList[_ATOM_IMAGE_TGA].notify = NotifyImage;
2751         __atomList[_ATOM_IMAGE_TGA].atom = 0;
2752
2753         __atomList[_ATOM_IMAGE_PPM].pName = "image/x-portable-pixmap";
2754         __atomList[_ATOM_IMAGE_PPM].formats = _CLIP_FORMAT_IMAGE;
2755         __atomList[_ATOM_IMAGE_PPM].convert = ConvertClipIntoImage;
2756         __atomList[_ATOM_IMAGE_PPM].response = null;
2757         __atomList[_ATOM_IMAGE_PPM].notify = NotifyImage;
2758         __atomList[_ATOM_IMAGE_PPM].atom = 0;
2759
2760         __atomList[_ATOM_TEXT_HTML_UTF8].pName = "text/html;charset=utf-8";
2761         __atomList[_ATOM_TEXT_HTML_UTF8].formats = _CLIP_FORMAT_HTML;
2762         __atomList[_ATOM_TEXT_HTML_UTF8].convert = ConvertClipIntoHtml;
2763         __atomList[_ATOM_TEXT_HTML_UTF8].response = null;
2764         __atomList[_ATOM_TEXT_HTML_UTF8].notify = NotifyHtml;
2765         __atomList[_ATOM_TEXT_HTML_UTF8].atom = 0;
2766
2767         __atomList[_ATOM_TEXT_HTML].pName = "text/html";
2768         __atomList[_ATOM_TEXT_HTML].formats = _CLIP_FORMAT_HTML;
2769         __atomList[_ATOM_TEXT_HTML].convert = ConvertClipIntoHtml;
2770         __atomList[_ATOM_TEXT_HTML].response = null;
2771         __atomList[_ATOM_TEXT_HTML].notify = NotifyHtml;
2772         __atomList[_ATOM_TEXT_HTML].atom = 0;
2773
2774         __atomList[_ATOM_STRING_UTF8].pName = "UTF8_STRING";
2775         __atomList[_ATOM_STRING_UTF8].formats = (_ClipFormat) (_CLIP_FORMAT_TEXT | _CLIP_FORMAT_MARKUP | _CLIP_FORMAT_HTML);
2776         __atomList[_ATOM_STRING_UTF8].convert = ConvertClipIntoText;
2777         __atomList[_ATOM_STRING_UTF8].response = null;
2778         __atomList[_ATOM_STRING_UTF8].notify = NotifyText;
2779         __atomList[_ATOM_STRING_UTF8].atom = 0;
2780
2781         __atomList[_ATOM_STRING].pName = "STRING";
2782         __atomList[_ATOM_STRING].formats = (_ClipFormat) (_CLIP_FORMAT_TEXT | _CLIP_FORMAT_MARKUP | _CLIP_FORMAT_HTML);
2783         __atomList[_ATOM_STRING].convert = ConvertClipIntoText;
2784         __atomList[_ATOM_STRING].response = null;
2785         __atomList[_ATOM_STRING].notify = NotifyText;
2786         __atomList[_ATOM_STRING].atom = 0;
2787
2788         __atomList[_ATOM_TEXT].pName = "TEXT";
2789         __atomList[_ATOM_TEXT].formats = (_ClipFormat) (_CLIP_FORMAT_TEXT | _CLIP_FORMAT_MARKUP | _CLIP_FORMAT_HTML);
2790         __atomList[_ATOM_TEXT].convert = ConvertClipIntoText;
2791         __atomList[_ATOM_TEXT].response = null;
2792         __atomList[_ATOM_TEXT].notify = null;
2793         __atomList[_ATOM_TEXT].atom = 0;
2794
2795         __atomList[_ATOM_TEXT_PLAIN_UTF8].pName = "text/plain;charset=utf-8";
2796         __atomList[_ATOM_TEXT_PLAIN_UTF8].formats = (_ClipFormat) (_CLIP_FORMAT_TEXT | _CLIP_FORMAT_MARKUP | _CLIP_FORMAT_HTML);
2797         __atomList[_ATOM_TEXT_PLAIN_UTF8].convert = ConvertClipIntoText;
2798         __atomList[_ATOM_TEXT_PLAIN_UTF8].response = null;
2799         __atomList[_ATOM_TEXT_PLAIN_UTF8].notify = null;
2800         __atomList[_ATOM_TEXT_PLAIN_UTF8].atom = 0;
2801
2802         __atomList[_ATOM_TEXT_PLAIN].pName = "text/plain";
2803         __atomList[_ATOM_TEXT_PLAIN].formats = (_ClipFormat) (_CLIP_FORMAT_TEXT | _CLIP_FORMAT_MARKUP | _CLIP_FORMAT_HTML);
2804         __atomList[_ATOM_TEXT_PLAIN].convert = ConvertClipIntoText;
2805         __atomList[_ATOM_TEXT_PLAIN].response = null;
2806         __atomList[_ATOM_TEXT_PLAIN].notify = null;
2807         __atomList[_ATOM_TEXT_PLAIN].atom = 0;
2808
2809         __clipList[_CLIP_TYPE_PRIMARY].selection = ECORE_X_SELECTION_PRIMARY;
2810         __clipList[_CLIP_TYPE_PRIMARY].set = ecore_x_selection_primary_set;
2811         __clipList[_CLIP_TYPE_PRIMARY].clear = ecore_x_selection_primary_clear;
2812         __clipList[_CLIP_TYPE_PRIMARY].request = ecore_x_selection_primary_request;
2813         __clipList[_CLIP_TYPE_PRIMARY].active = false;
2814         __clipList[_CLIP_TYPE_PRIMARY].pBuffer = null;
2815         __clipList[_CLIP_TYPE_PRIMARY].pRetrievedBuffer = null;
2816         __clipList[_CLIP_TYPE_PRIMARY].bufferLength = 0;
2817         __clipList[_CLIP_TYPE_PRIMARY].completed = false;
2818
2819         __clipList[_CLIP_TYPE_SECONDARY].selection = ECORE_X_SELECTION_SECONDARY;
2820         __clipList[_CLIP_TYPE_SECONDARY].set = ecore_x_selection_secondary_set;
2821         __clipList[_CLIP_TYPE_SECONDARY].clear = ecore_x_selection_secondary_clear;
2822         __clipList[_CLIP_TYPE_SECONDARY].request = ecore_x_selection_secondary_request;
2823         __clipList[_CLIP_TYPE_SECONDARY].active = false;
2824         __clipList[_CLIP_TYPE_SECONDARY].pBuffer = null;
2825         __clipList[_CLIP_TYPE_SECONDARY].pRetrievedBuffer = null;
2826         __clipList[_CLIP_TYPE_SECONDARY].bufferLength = 0;
2827         __clipList[_CLIP_TYPE_SECONDARY].completed = false;
2828
2829         __clipList[_CLIP_TYPE_CLIPBOARD].selection = ECORE_X_SELECTION_CLIPBOARD;
2830         __clipList[_CLIP_TYPE_CLIPBOARD].set = ecore_x_selection_clipboard_set;
2831         __clipList[_CLIP_TYPE_CLIPBOARD].clear = ecore_x_selection_clipboard_clear;
2832         __clipList[_CLIP_TYPE_CLIPBOARD].request = ecore_x_selection_clipboard_request;
2833         __clipList[_CLIP_TYPE_CLIPBOARD].active = false;
2834         __clipList[_CLIP_TYPE_CLIPBOARD].pBuffer = null;
2835         __clipList[_CLIP_TYPE_CLIPBOARD].pRetrievedBuffer = null;
2836         __clipList[_CLIP_TYPE_CLIPBOARD].bufferLength = 0;
2837         __clipList[_CLIP_TYPE_CLIPBOARD].completed = false;
2838
2839         __clipList[_CLIP_TYPE_XDND].selection = ECORE_X_SELECTION_XDND;
2840         __clipList[_CLIP_TYPE_XDND].request = ecore_x_selection_xdnd_request;
2841         __clipList[_CLIP_TYPE_XDND].active = false;
2842         __clipList[_CLIP_TYPE_XDND].pBuffer = null;
2843         __clipList[_CLIP_TYPE_XDND].pRetrievedBuffer = null;
2844         __clipList[_CLIP_TYPE_XDND].bufferLength = 0;
2845         __clipList[_CLIP_TYPE_XDND].completed = false;
2846
2847         for (int i = 0; i < _ATOM_MAX; i++)
2848         {
2849                 __atomList[i].atom = ecore_x_atom_get(__atomList[i].pName);
2850                 //ecore_x_selection_converter_atom_add(__atomList[i].atom, __atomList[i].convert);
2851
2852                 SysLog(NID_UI, "[Clipboard] __atomList[%d] : pName = %s, atom = %d", i, __atomList[i].pName, __atomList[i].atom);
2853         }
2854
2855         result r = E_SUCCESS;
2856
2857         __pClearClip = ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR, ClearClip, NULL);
2858         SysTryCatch(NID_UI, __pClearClip, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2859
2860         __pNotifyClip = ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, NotifyClip, NULL);
2861         SysTryCatch(NID_UI, __pNotifyClip, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2862
2863         __pClipboardClosed = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_FOCUS_IN, OnClipboardClosed, null);
2864         SysTryCatch(NID_UI, __pClipboardClosed, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
2865
2866         __atomRotateRootAngle = ecore_x_atom_get("_E_ILLUME_ROTATE_ROOT_ANGLE");
2867         __atomAccessibility = ecore_x_atom_get("_E_MOD_ACC_SCR_READER_");
2868
2869         return r;
2870
2871 CATCH:
2872         for (int i = 0; i < _ATOM_MAX; i++)
2873         {
2874                 if (__atomList[i].atom)
2875                 {
2876                         ecore_x_selection_converter_atom_del(__atomList[i].atom);
2877                 }
2878         }
2879
2880         if (__pClearClip)
2881         {
2882                 ecore_event_handler_del(__pClearClip);
2883                 __pClearClip = null;
2884         }
2885
2886         if (__pNotifyClip)
2887         {
2888                 ecore_event_handler_del(__pNotifyClip);
2889                 __pNotifyClip = null;
2890         }
2891
2892         if (__pClipboardClosed)
2893         {
2894                 ecore_event_handler_del(__pClipboardClosed);
2895                 __pClipboardClosed = null;
2896         }
2897
2898         return r;
2899 }
2900
2901 bool
2902 _EcoreEvas::IsValidClipFormat(_ClipFormat clipFormat)
2903 {
2904         return ((_CLIP_FORMAT_TEXT & clipFormat) ||
2905                 (_CLIP_FORMAT_MARKUP & clipFormat) ||
2906                 (_CLIP_FORMAT_IMAGE & clipFormat) ||
2907                 (_CLIP_FORMAT_VCARD & clipFormat) ||
2908                 (_CLIP_FORMAT_HTML & clipFormat));
2909 }
2910
2911 Ecore_X_Window
2912 _EcoreEvas::GetCbhmWindow(void) const
2913 {
2914         Ecore_X_Atom atomCbhm = ecore_x_atom_get(ATOM_CBHM_WINDOW_NAME);
2915         Ecore_X_Window cbhmWin = 0;
2916
2917         unsigned char* pBuf = NULL;
2918         int num = 0;
2919         int ret = ecore_x_window_prop_property_get(0, atomCbhm, XA_WINDOW, 0, &pBuf, &num);
2920
2921         if (ret && num)
2922         {
2923                 memcpy(&cbhmWin, pBuf, sizeof(Ecore_X_Window));
2924         }
2925
2926         if (pBuf)
2927         {
2928                 free(pBuf);
2929         }
2930
2931         return cbhmWin;
2932 }
2933
2934 bool
2935 _EcoreEvas::SendCbhmMessage(Ecore_X_Window xwin, const char* pMsg)
2936 {
2937         Ecore_X_Window cbhmWin = GetCbhmWindow();
2938         Ecore_X_Atom atomCbhmMsg = ecore_x_atom_get(ATOM_CBHM_MSG);
2939
2940         if (!cbhmWin || !atomCbhmMsg)
2941         {
2942                 return false;
2943         }
2944
2945         XClientMessageEvent m;
2946         memset(&m, 0, sizeof(m));
2947         m.type = ClientMessage;
2948         m.display = (Display*)ecore_x_display_get();
2949         m.window = xwin;
2950         m.message_type = atomCbhmMsg;
2951         m.format = 8;
2952         snprintf(m.data.b, 20, "%s", pMsg);
2953
2954         XSendEvent((Display*)ecore_x_display_get(), cbhmWin, False, NoEventMask, (XEvent*)&m);
2955
2956         ecore_x_sync();
2957
2958         // [SLP]
2959         Thread::Sleep(100);
2960
2961         return true;
2962 }
2963
2964 bool
2965 _EcoreEvas::SetCbhmItem(Ecore_X_Window xwin, Ecore_X_Atom dataType, char* pItemData)
2966 {
2967         Ecore_X_Window cbhmWin = GetCbhmWindow();
2968         Ecore_X_Atom atomCbhmItem = ecore_x_atom_get(ATOM_CBHM_ITEM);
2969
2970         ecore_x_sync();
2971         ecore_x_window_prop_property_set(cbhmWin, atomCbhmItem, dataType, 8, pItemData, strlen(pItemData) + 1);
2972         ecore_x_sync();
2973
2974         if (SendCbhmMessage(xwin, ATOM_CBHM_SET_ITEM))
2975         {
2976                 return true;
2977         }
2978
2979         return false;
2980 }
2981
2982 void*
2983 _EcoreEvas::GetCbhmReply(Ecore_X_Window xwin, Ecore_X_Atom property, Ecore_X_Atom* pDataType, int* pNum) const
2984 {
2985         unsigned char* pData = null;
2986
2987         if (pDataType)
2988         {
2989                 *pDataType = 0;
2990         }
2991
2992         if (!property)
2993         {
2994                 return null;
2995         }
2996
2997         ecore_x_sync();
2998
2999         if (pNum)
3000         {
3001                 *pNum = 0;
3002         }
3003
3004         long unsigned int numRet = 0;
3005         long unsigned int bytes = 0;
3006         int ret = 0;
3007         int sizeRet = 0;
3008         unsigned int i = 0;
3009         unsigned char* pPropRet = null;
3010         Ecore_X_Atom typeRet;
3011
3012         ret = XGetWindowProperty((Display*)ecore_x_display_get(), xwin, property, 0, LONG_MAX, False,
3013                                                         ecore_x_window_prop_any_type(), (Atom*)&typeRet, &sizeRet, &numRet, &bytes, &pPropRet);
3014         if (ret != Success)
3015         {
3016                 return null;
3017         }
3018
3019         if (!numRet)
3020         {
3021                 XFree(pPropRet);
3022                 return null;
3023         }
3024
3025         if (!(pData = (unsigned char*)malloc(numRet * sizeRet / 8)))
3026         {
3027                 XFree(pPropRet);
3028                 return null;
3029         }
3030
3031         switch (sizeRet)
3032         {
3033         case 8:
3034                 for (i = 0; i < numRet; i++)
3035                 (pData)[i] = pPropRet[i];
3036                 break;
3037         case 16:
3038                 for (i = 0; i < numRet; i++)
3039                 ((unsigned short *)pData)[i] = ((unsigned short *)pPropRet)[i];
3040                 break;
3041         case 32:
3042                 for (i = 0; i < numRet; i++)
3043                 ((unsigned int *)pData)[i] = ((unsigned long *)pPropRet)[i];
3044                 break;
3045         }
3046
3047         XFree(pPropRet);
3048
3049         // [SLP]
3050         Thread::Sleep(100);
3051
3052         if (pNum)
3053         {
3054                 *pNum = numRet;
3055         }
3056
3057         if (pDataType)
3058         {
3059                 *pDataType = typeRet;
3060         }
3061
3062         return pData;
3063 }
3064
3065 int
3066 _EcoreEvas::GetCbhmItemCount(void) const
3067 {
3068         char* pRet = null;
3069         int count = null;
3070
3071         Ecore_X_Atom atomCbhmCountGet = ecore_x_atom_get(ATOM_CBHM_COUNT_GET);
3072         Ecore_X_Window cbhmWin = GetCbhmWindow();
3073
3074         pRet = (char*)GetCbhmReply(cbhmWin, atomCbhmCountGet, null, null);
3075         if (pRet)
3076         {
3077                 count = atoi(pRet);
3078                 free(pRet);
3079                 return count;
3080         }
3081
3082         return -1;
3083 }
3084
3085 bool
3086 _EcoreEvas::GetCbhmItem(int index, Ecore_X_Atom* pDataType, char** pBuffer) const
3087 {
3088         if (pBuffer)
3089         {
3090                 *pBuffer = null;
3091         }
3092
3093         if (pDataType)
3094         {
3095                 *(int*)pDataType = 0;
3096         }
3097
3098         Ecore_X_Window cbhmWin = GetCbhmWindow();
3099         char sendBuf[20];
3100         char* pRet;
3101
3102         snprintf(sendBuf, 20, "CBHM_ITEM%d", index);
3103         Ecore_X_Atom atomCbhmItem = ecore_x_atom_get(sendBuf);
3104         Ecore_X_Atom atomItemType = 0;
3105
3106         pRet = (char*)GetCbhmReply(cbhmWin, atomCbhmItem, &atomItemType, NULL);
3107         if (pRet)
3108         {
3109                 if (pBuffer)
3110                 {
3111                         *pBuffer = pRet;
3112                 }
3113                 else
3114                 {
3115                         free(pRet);
3116                 }
3117
3118                 if (pDataType)
3119                 {
3120                         *pDataType = atomItemType;
3121                 }
3122
3123                 Ecore_X_Atom x_atom_cbhm_error = ecore_x_atom_get(ATOM_CBHM_ERROR);
3124                 if (atomItemType == x_atom_cbhm_error)
3125                 {
3126                         return false;
3127                 }
3128
3129                 return true;
3130         }
3131
3132         return false;
3133 }
3134
3135 }} // Tizen::Ui
3136
3137 #ifdef __cplusplus
3138 extern "C"
3139 {
3140 #endif
3141
3142 // [ToDo] Remove API
3143 _OSP_EXPORT_ void
3144 _AddActiveWindowEventListener(const _IActiveWindowEventListener& listener)
3145 {
3146         GetEcoreEvasMgr()->GetEcoreEvas()->AddActiveWindowEventListener(listener);
3147 }
3148
3149 // [ToDo] Remove API
3150 _OSP_EXPORT_ void
3151 _RemoveActiveWindowEventListener(const _IActiveWindowEventListener& listener)
3152 {
3153         GetEcoreEvasMgr()->GetEcoreEvas()->RemoveActiveWindowEventListener(listener);
3154 }
3155
3156 // [ToDo] Remove API
3157 _OSP_EXPORT_ unsigned int
3158 _GetActiveWindow(void)
3159 {
3160         return GetEcoreEvasMgr()->GetEcoreEvas()->GetActiveWindow();
3161 }
3162
3163 // [ToDo] Remove API
3164 _OSP_EXPORT_ int
3165 _GetProcessId(unsigned int window)
3166 {
3167         return GetEcoreEvasMgr()->GetEcoreEvas()->GetProcessId(window);
3168 }
3169
3170 #ifdef __cplusplus
3171 }
3172 #endif
3173