change global variable position
[framework/uifw/cbhm.git] / src / cbhm_main.c
1 /*
2  * SLP2
3  * Copyright (c) 2009 Samsung Electronics, Inc.
4  * All rights reserved.
5  *
6  * This software is a confidential and proprietary information
7  * of Samsung Electronics, Inc. ("Confidential Information").  You
8  * shall not disclose such Confidential Information and shall use
9  * it only in accordance with the terms of the license agreement
10  * you entered into with Samsung Electronics.
11  */
12
13 #include "common.h"
14 #include "cbhm_main.h"
15 #include "xcnphandler.h"
16 #include "clipdrawer.h"
17 #include "scrcapture.h"
18
19 // FIXME: how to remove g_main_ad? 
20 static struct appdata *g_main_ad = NULL;
21
22 static Evas_Object* create_win(void *data, const char *name);
23 static Evas_Object* load_edj(Evas_Object *parent, const char *file, const char *group);
24
25 static void win_del_cb(void *data, Evas_Object *obj, void *event)
26 {
27         struct appdata *ad = (struct appdata *) data;
28         clipdrawer_lower_view(ad);
29 //  NOTE : cbhm doesn't want to exit by home key.
30 //      elm_exit();
31 }
32
33 static void main_quit_cb(void *data, Evas_Object* obj, void* event_info)
34 {
35         elm_exit();
36 }
37
38 void* g_get_main_appdata()
39 {
40         return (void*)g_main_ad;
41 }
42
43 int init_appview(void *data)
44 {
45         struct appdata *ad = (struct appdata *) data;
46         Evas_Object *win, *ly;
47
48         win = create_win(ad, APPNAME);
49         if(win == NULL)
50                 return -1;
51         ad->evas = evas_object_evas_get(win);
52         ad->win_main = win;
53
54 //  avoid focus but it can't be used. because grap keys
55 //      Ecore_X_Window xwin = (Ecore_X_Window)ecore_evas_window_get(ecore_evas_ecore_evas_get(ad->evas));
56 //      ecore_x_icccm_hints_set(xwin, 0, 0, 0, 0, 0, 0, 0);
57
58         ly = load_edj(win, APP_EDJ_FILE, GRP_MAIN);
59         if (ly == NULL)
60                 return -1; 
61         elm_win_resize_object_add(win, ly);
62         ad->ly_main = ly;
63
64         evas_object_show(ly);
65
66         clipdrawer_create_view(ad);
67
68         evas_object_smart_callback_add(ad->win_main, "delete,request", win_del_cb, ad);
69         edje_object_signal_callback_add(elm_layout_edje_get(ly), "EXIT", "*", main_quit_cb, NULL);
70
71 // NOTE: do not show before win_main window resizing
72 //      evas_object_show(win);
73
74         return 0;
75 }
76
77 void disable_focus_for_app_window (Evas_Object *win)
78 {
79     Eina_Bool accepts_focus;
80     Ecore_X_Window_State_Hint initial_state;
81     Ecore_X_Pixmap icon_pixmap;
82     Ecore_X_Pixmap icon_mask;
83     Ecore_X_Window icon_window;
84     Ecore_X_Window window_group;
85     Eina_Bool is_urgent;
86
87     ecore_x_icccm_hints_get (elm_win_xwindow_get (win),
88                              &accepts_focus, &initial_state, &icon_pixmap, &icon_mask, &icon_window, &window_group, &is_urgent);
89     ecore_x_icccm_hints_set (elm_win_xwindow_get (win),
90                              0, initial_state, icon_pixmap, icon_mask, icon_window, window_group, is_urgent);
91 }
92
93 static Evas_Object* create_win(void *data, const char *name)
94 {
95         struct appdata *ad = (struct appdata *) data;
96         Evas_Object *eo;
97         int w, h;
98         Ecore_X_Display *dpy;
99         dpy = ecore_x_display_get();
100
101         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
102         if (eo)
103     {
104                 elm_win_title_set(eo, name);
105                 elm_win_borderless_set(eo, EINA_TRUE);
106                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
107                 ad->root_w = w; ad->root_h = h;
108                 evas_object_resize(eo, w, h);
109                 if (dpy)
110                 {   //disable window effect
111                         utilx_set_window_effect_state(dpy, elm_win_xwindow_get(eo), 0);
112                         ecore_x_icccm_name_class_set(elm_win_xwindow_get(eo), "NORMAL_WINDOW", "NORMAL_WINDOW");
113 //                      elm_win_keyboard_win_set (eo, EINA_TRUE);
114 //                      ecore_x_icccm_name_class_set(elm_win_xwindow_get(eo), "Virtual Keyboard", "ISF");
115 //                      disable_focus_for_app_window(eo);
116                 }
117         }
118
119         return eo;
120 }
121
122 static Evas_Object* load_edj(Evas_Object *parent, const char *file, const char *group)
123 {       
124         Evas_Object *eo;
125         int ret;
126
127         eo = elm_layout_add(parent);
128         if (eo) 
129         {
130                 ret = elm_layout_file_set(eo, file, group);
131                 if (!ret) 
132                 {
133                         evas_object_del(eo);
134                         return NULL;
135                 }
136
137                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
138                 elm_win_resize_object_add(parent, eo);
139         }
140
141         return eo;
142 }
143
144 static int init(struct appdata *ad)
145 {
146         /* FIXME : add checking multiple instance */
147         xcnp_init(ad);
148         init_appview(ad);
149         init_scrcapture(ad);
150
151         return 0;
152 }
153
154 static void fini(struct appdata *ad)
155 {
156         close_scrcapture(ad);
157
158         if (ad->ly_main)
159                 evas_object_del(ad->ly_main);
160
161         if (ad->win_main)
162                 evas_object_del(ad->win_main);
163 }
164
165 static void init_ad(struct appdata *ad)
166 {
167         memset(ad, 0x0, sizeof(struct appdata));
168         g_main_ad = ad;
169 }
170
171 EAPI int elm_main(int argc, char **argv)
172 {
173         struct appdata ad;
174
175         init_ad(&ad);
176
177         if(!init(&ad))
178                 elm_run();
179
180         fini(&ad);
181
182         elm_shutdown();
183
184         return EXIT_SUCCESS;
185 }
186
187 int main( int argc, char *argv[] )
188 {
189         elm_init(argc, argv);
190
191         return elm_main(argc, argv);
192 }