Corresponding to TizenIVI3.0 M14.3,
[profile/ivi/ico-uxf-homescreen.git] / src / homescreen / CicoHSWindow.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   Window class
11  *
12  * @date    Aug-08-2013
13  */
14 #include "CicoHSWindow.h"
15
16 //==========================================================================
17 //  static variables
18 //==========================================================================
19 struct created_window_name   *CicoHSWindow::created_window_title = NULL;
20
21 /*============================================================================*/
22 /* functions                                                                  */
23 /*============================================================================*/
24 /*--------------------------------------------------------------------------*/
25 /**
26  * @brief   CicoHSWindow::CicoHSWindow
27  *          Constractor
28  *
29  * @param[in]   none
30  * @return      none
31  */
32 /*--------------------------------------------------------------------------*/
33 CicoHSWindow::CicoHSWindow(void)
34 {
35     window = NULL;
36 }
37
38 /*--------------------------------------------------------------------------*/
39 /**
40  * @brief   CicoHSWindow::~CicoHSWindow
41  *          Destractor
42  *
43  * @param[in]   none
44  * @return      none
45  */
46 /*--------------------------------------------------------------------------*/
47 CicoHSWindow::~CicoHSWindow(void)
48 {
49     /* Do not somthing to do */
50     if(window != NULL){
51         FreeWindow();
52     }
53 }
54
55 /*--------------------------------------------------------------------------*/
56 /**
57  * @brief   CicoHSWindow::CreateWindow
58  *          create new window(ecore evas)
59  *
60  * @param[in]   none
61  * @return      none
62  */
63 /*--------------------------------------------------------------------------*/
64 int
65 CicoHSWindow::CreateWindow(const char *title, int pos_x, int pos_y,
66                            int width, int height, int alpha)
67 {
68     struct created_window_name  *winname;
69     struct created_window_name  *tp;
70
71     ICO_DBG("CicoHSWindow::CreateWindow: Enter(%s,x/y=%d/%d,w/h=%d/%d,a=%d)",
72             title, pos_x, pos_y, width, height, alpha);
73
74     this->pos_x = pos_x;
75     this->pos_y = pos_y;
76     this->width = width;
77     this->height = height;
78
79     /* Make a new ecore_evas    */
80     window = ecore_evas_new(NULL, pos_x, pos_y, width, height, "frame=0");
81     /* if do not creted new, enlightenment return NULL */
82     if (!window) {
83         ICO_ERR("CicoHSWindow::CreateWindow: could not create new_window.");
84         ICO_DBG("CicoHSWindow::CreateWindow: Leave(Error)");
85         return ICO_ERROR;
86     }
87     strncpy(this->title, title, ICO_MAX_TITLE_NAME_LEN);
88     ecore_evas_title_set(window, this->title);
89
90     /* alpha channel is enable  */
91     ecore_evas_alpha_set(window, alpha);
92
93     /* save window name(title)  */
94     winname = (struct created_window_name *)malloc(sizeof(struct created_window_name));
95     if (! winname)  {
96         ICO_ERR("CicoHSWindow::CreateWindow: out of memory");
97         ICO_DBG("CicoHSWindow::CreateWindow: Leave(Error)");
98         return ICO_ERROR;
99     }
100     else    {
101         memset(winname, 0, sizeof(struct created_window_name));
102         strncpy(winname->winname, title, ICO_MAX_TITLE_NAME_LEN-1);
103         if (created_window_title)   {
104             tp = created_window_title;
105             while (tp->next)    tp = tp->next;
106             tp->next = winname;
107         }
108         else    {
109             created_window_title = winname;
110         }
111     }
112     ICO_DBG("CicoHSWindow::CreateWindow: Leave");
113     return ICO_OK;
114 }
115
116 /*--------------------------------------------------------------------------*/
117 /**
118  * @brief   CicoHSWindow::getWindowName
119  *          get window title by window index
120  *
121  * @param[in]   index
122  * @return      window title
123  */
124 /*--------------------------------------------------------------------------*/
125 const char *
126 CicoHSWindow::getWindowName(const int index)
127 {
128     int     i = index;
129     struct created_window_name  *tp = created_window_title;
130
131     for (i = 0; i < index; i++) {
132         if (! tp)   break;
133         tp = tp->next;
134     }
135
136     if (tp) {
137         return tp->winname;
138     }
139     else    {
140         return "\0";
141     }
142 }
143
144 /*--------------------------------------------------------------------------*/
145 /**
146  * @brief   CicoHSWindow::FreeWindow
147  *          Free the window(ecore evas)
148  *
149  * @param[in]   none
150  * @return      none
151  */
152 /*--------------------------------------------------------------------------*/
153 void
154 CicoHSWindow::FreeWindow(void)
155 {
156     ecore_evas_free(window);
157 }
158
159 /*--------------------------------------------------------------------------*/
160 /**
161  * @brief   CicoHSWindow::WindowSetting
162  *          setting to window(ecore evas)
163  *
164  * @param[in]   none
165  * @return      none
166  */
167 /*--------------------------------------------------------------------------*/
168 void
169 CicoHSWindow::WindowSetting(int pos_x,int pos_y,int width,int height,int alpha)
170 {
171     this->pos_x = pos_x;
172     this->pos_y = pos_y;
173     this->width = width;
174     this->height = height;
175
176     /* move     */
177     ecore_evas_move(window,pos_x,pos_y);
178     /* resize   */
179     ecore_evas_resize(window, width, height);
180     /* alpha channel is enable  */
181     ecore_evas_alpha_set(window, alpha);
182 }
183
184 /*--------------------------------------------------------------------------*/
185 /**
186  * @brief   CicoHSWindow::ShowWindow
187  *          showing window(ecore evas)
188  *
189  * @param[in]   none
190  * @return      none
191  */
192 /*--------------------------------------------------------------------------*/
193 void
194 CicoHSWindow::ShowWindow(void)
195 {
196     /* showing  */
197     ecore_evas_show(window);
198 }
199
200 /*--------------------------------------------------------------------------*/
201 /**
202  * @brief   CicoHSWindow::HideWindow
203  *          hiding window(ecore evas)
204  *
205  * @param[in]   none
206  * @return      none
207  */
208 /*--------------------------------------------------------------------------*/
209 void
210 CicoHSWindow::HideWindow(void)
211 {
212     /* hiding   */
213     ecore_evas_hide(window);
214 }
215 // vim:set expandtab ts=4 sw=4: