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