Add code to create main window

Signed-off-by: Chris Michael <devilhorns@comcast.net>
This commit is contained in:
Chris Michael 2013-12-24 16:33:19 +00:00
parent ab6c8bfe0c
commit 66f728e17e
1 changed files with 133 additions and 3 deletions

View File

@ -1,7 +1,137 @@
#include "private.h"
int
main(int argc, char **argv)
/* internal structures */
struct _Window
{
return 0;
Evas *evas;
Evas_Object *o_win;
Evas_Object *o_bg;
};
/* local prototypes */
static void _main_window_free(Window *win);
/* external variables */
int _log_dom = -1;
/* local functions */
static void
_main_window_cb_del(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
{
Window *win;
if (!(win = data)) return;
win->o_win = NULL;
_main_window_free(win);
}
static void
_main_window_free(Window *win)
{
/* delete the background */
if (win->o_bg) evas_object_del(win->o_bg);
if (win->o_win)
{
/* destroy the window if it exists */
evas_object_event_callback_del_full(win->o_win, EVAS_CALLBACK_DEL,
_main_window_cb_del, win);
evas_object_del(win->o_win);
}
/* free allocated structure */
free(win);
}
static Window *
_main_window_new(void)
{
Window *win;
/* try to allocate space for new window structure */
if (!(win = calloc(1, sizeof(Window))))
return NULL;
/* create elm window */
win->o_win = _window_new();
/* store the canvas into our window structure for easy reuse */
win->evas = evas_object_evas_get(win->o_win);
/* add a callback to know when this window gets deleted */
evas_object_event_callback_add(win->o_win, EVAS_CALLBACK_DEL,
_main_window_cb_del, win);
/* add a background to the window */
win->o_bg = evas_object_rectangle_add(win->evas);
evas_object_color_set(win->o_bg, 0, 0, 0, 255);
evas_object_size_hint_weight_set(win->o_bg,
EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_fill_set(win->o_bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_win_resize_object_add(win->o_win, win->o_bg);
evas_object_show(win->o_bg);
return win;
}
/* public functions */
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Window *win;
/* create logging domain */
_log_dom = eina_log_domain_register("express", NULL);
if (_log_dom < 0)
{
EINA_LOG_CRIT("Could not create logging domain");
elm_shutdown();
return EXIT_FAILURE;
}
/* set elm policy */
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
/* set elm app directories */
elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
/* set elm app info */
elm_app_info_set(elm_main, "express", "themes/default.edj");
/* TODO: set elm theme overlay */
/* create main window */
if (!(win = _main_window_new()))
goto win_new_err;
evas_object_resize(win->o_win, 200, 200);
evas_object_show(win->o_win);
/* start main loop */
elm_run();
/* destroy main window */
_main_window_free(win);
/* unregister our logging domain */
eina_log_domain_unregister(_log_dom);
_log_dom = -1;
/* shutdown elementary */
elm_shutdown();
return EXIT_SUCCESS;
win_new_err:
/* unregister our logging domain */
eina_log_domain_unregister(_log_dom);
_log_dom = -1;
/* shutdown elementary */
elm_shutdown();
return EXIT_FAILURE;
}
ELM_MAIN()