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