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