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