e827a97cd89a9110a84ab2649633ecf9be444979
[profile/ivi/ico-uxf-homescreen.git] / src / homescreen / CicoHSSwipeInputWindow.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9 /**
10  * @brief   swipe input window
11  *
12  * @date    Sep-20-2013
13  */
14 #include "CicoHSSwipeInputWindow.h"
15 #include "CicoHSSwipeTouch.h"
16 #include "CicoHomeScreen.h"
17 #include "CicoHSSystemState.h"
18
19 /*============================================================================*/
20 /* functions                                                                  */
21 /*============================================================================*/
22 /*--------------------------------------------------------------------------*/
23 /**
24  * @brief   CicoHSSwipeInputWindow::CicoHSSwipeInputWindow
25  *          Constractor
26  *
27  * @param[in]   none
28  * @return      none
29  */
30 /*--------------------------------------------------------------------------*/
31 CicoHSSwipeInputWindow::CicoHSSwipeInputWindow(void)
32 {
33     ICO_DBG("CicoHSSwipeInputWindow::CicoHSSwipeInputWindow: constractor");
34     evas = NULL;
35     background = NULL;
36     setuped = false;
37 }
38
39 /*--------------------------------------------------------------------------*/
40 /**
41  * @brief   CicoHSSwipeInputWindow::~CicoHSSwipeInputWindow
42  *          Destractor
43  *
44  * @param[in]   none
45  * @return      none
46  */
47 /*--------------------------------------------------------------------------*/
48 CicoHSSwipeInputWindow::~CicoHSSwipeInputWindow(void)
49 {
50     ICO_DBG("CicoHSSwipeInputWindow::CicoHSSwipeInputWindow: destractor");
51     /* not somthing to do */
52 }
53
54 /*--------------------------------------------------------------------------*/
55 /**
56  * @brief   CicoHSSwipeInputWindow::CreateSwipeInputWindow
57  *          crate window (swipe input window)
58  *
59  * @param[in]   pos_x    position x
60  * @param[in]   pos_y    position y
61  * @param[in]   width    width
62  * @param[in]   height   height
63  * @param[in]   subname  swipe input window sub name
64  * @return      OK or ERRROR
65  */
66 /*--------------------------------------------------------------------------*/
67 int
68 CicoHSSwipeInputWindow::CreateSwipeInputWindow(int pos_x, int pos_y,
69                                                int width, int height, const char *subname)
70 {
71     int ret;
72
73     ICO_DBG("CreateSwipeInputWindow: start(%s,x/y=%d/%d,w/h=%d/%d)",
74             subname ? subname : "(null)", pos_x, pos_y, width, height);
75
76     /*create window*/
77     if (subname)    {
78         snprintf(winname, sizeof(winname), "%s_%s",
79                  ICO_HS_SWIPE_INPUT_WINDOW_TITLE, subname);
80     }
81     else    {
82         strncpy(winname, ICO_HS_SWIPE_INPUT_WINDOW_TITLE, ICO_SYC_MAX_WINNAME_LEN);
83     }
84     winname[ICO_SYC_MAX_WINNAME_LEN-1] = 0;
85     ICO_DBG("CreateSwipeInputWindow: winname=%s", winname);
86     ret = CreateWindow(winname, pos_x, pos_y, width, height, EINA_TRUE);
87     if(ret != ICO_OK){
88         ICO_CRI("CicoHSSwipeInputWindow::CreateSwipeInputWindow: can not create window");
89         return ret;
90     }
91
92     /* get evas */
93     evas = ecore_evas_get(window);
94     if (!evas) {
95         ICO_CRI("CicoHSSwipeInputWindow::CreateSwipeInputWindow: could not get evas.");
96         return ICO_ERROR;
97     }
98
99     /* background object(transparent)    */
100     background = evas_object_image_filled_add(evas);
101
102     /* set mouse/touch callback */
103     evas_object_event_callback_add(background, EVAS_CALLBACK_MOUSE_DOWN,
104                                        CicoHSSwipeTouch::TouchDownSwipe, this);
105     evas_object_event_callback_add(background, EVAS_CALLBACK_MOUSE_UP,
106                                        CicoHSSwipeTouch::TouchUpSwipe, this);
107     evas_object_event_callback_add(background, EVAS_CALLBACK_MOUSE_MOVE,
108                                        CicoHSSwipeTouch::TouchMoveSwipe, this);
109     /* move and show window     */
110     evas_object_move(background, 0, 0);
111     evas_object_resize(background, width, height);
112     evas_object_show(background);
113
114     ICO_DBG("CreateSwipeInputWindow: end");
115     return ICO_OK;
116 }
117
118 /*--------------------------------------------------------------------------*/
119 /**
120  * @brief   CicoHSSwipeInputWindow::FreeSwipeInputWindow
121  *          free window (swipe input window)
122  *
123  * @param[in]   none
124  * @return      none
125  */
126 /*--------------------------------------------------------------------------*/
127 void
128 CicoHSSwipeInputWindow::FreeSwipeInputWindow(void)
129 {
130     evas_object_del(background);
131     FreeWindow();
132 }
133
134 /*--------------------------------------------------------------------------*/
135 /**
136  * @brief   CicoHSSwipeInputWindow::SetupSwipeWindow
137  *          initiale setup swipe input window
138  *
139  * @param       none
140  * @return      none
141  */
142 /*--------------------------------------------------------------------------*/
143 void
144 CicoHSSwipeInputWindow::SetupSwipeWindow(void)
145 {
146     ico_syc_win_move_t move;
147     ico_syc_animation_t show;
148
149     if (! setuped)  {
150         ICO_DBG("SetupSwipeWindow: start");
151         setuped = true;
152         move.zone = NULL;
153         move.pos_x = pos_x;
154         move.pos_y = pos_y;
155         move.width = width;
156         move.height = height;
157         memset(&show, 0, sizeof(show));
158         show.name = (char *)"none";
159
160         /* move swipe input window to TouchLayer    */
161         ico_syc_change_layer(appid, surface, HS_LAYER_TOUCHPANEL);
162         /* move window position and size            */
163         ico_syc_move(appid, surface, &move, NULL);
164         /* show and raise window                    */
165         show.time = ICO_SYC_WIN_SURF_RAISE;
166         ico_syc_show(appid, surface, &show);
167
168         /* show touch layer                         */
169         ico_syc_show_layer(HS_LAYER_TOUCHPANEL);
170
171         ICO_DBG("SetupSwipeWindow: end");
172     }
173 }
174
175 /*--------------------------------------------------------------------------*/
176 /**
177  * @brief   CicoHSSwipeInputWindow::Show
178  *          show my window
179  *
180  * @param       none
181  * @return      none
182  */
183 /*--------------------------------------------------------------------------*/
184 void
185 CicoHSSwipeInputWindow::Show(void)
186 {
187     ICO_DBG("CicoHSSwipeInputWindow::Show: %08x.%s", surface, this->winname);
188     ico_syc_show(appid, surface, NULL);
189 }
190
191 /*--------------------------------------------------------------------------*/
192 /**
193  * @brief   CicoHSSwipeInputWindow::Hide
194  *          hide my window
195  *
196  * @param       none
197  * @return      none
198  */
199 /*--------------------------------------------------------------------------*/
200 void
201 CicoHSSwipeInputWindow::Hide(void)
202 {
203     ICO_DBG("CicoHSSwipeInputWindow::Hide: %08x.%s", surface, this->winname);
204     ico_syc_hide(appid, surface, NULL);
205 }
206
207 /*--------------------------------------------------------------------------*/
208 /**
209  * @brief   CicoHSSwipeInputWindow::isMyWindowName
210  *          check window name
211  *
212  * @param[in]   winname     target window name
213  * @return      check result
214  * @retval      true        my window name is winname
215  * @retval      false       my window name is NOT winname
216  */
217 /*--------------------------------------------------------------------------*/
218 bool
219 CicoHSSwipeInputWindow::isMyWindowName(const char *winname)
220 {
221     bool    ret;
222
223     ret = (strcmp(winname, this->winname)) ? false : true;
224     ICO_DBG("isMyWindowName: %s is %s", winname, ret ? "TRUE" : "FALSE");
225     return ret;
226 }
227
228 int
229 CicoHSSwipeInputWindow::GetPosX(void)
230 {
231     return pos_x;
232 }
233
234 int
235 CicoHSSwipeInputWindow::GetPosY(void)
236 {
237     return pos_y;
238 }
239
240 int
241 CicoHSSwipeInputWindow::GetWidth(void)
242 {
243     return width;
244 }
245
246 int
247 CicoHSSwipeInputWindow::GetHeight(void)
248 {
249     return height;
250 }
251
252 /*--------------------------------------------------------------------------*/
253 /**
254  * @brief   CicoHSSwipeInputWindow::SetWindowID
255  *          set appid and surface
256  *
257  * @param[in]   none
258  * @return      none
259  */
260 /*--------------------------------------------------------------------------*/
261 void
262 CicoHSSwipeInputWindow::SetWindowID(const char *appid, int surface)
263 {
264     ICO_DBG("SetWindowID: appid=%s surface=%08x", appid, surface);
265     strncpy(this->appid, appid, ICO_HS_MAX_PROCESS_NAME);
266     this->surface = surface;
267 }
268 // vim: set expandtab ts=4 sw=4: