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