Inwin basic example

SVN revision: 61853
This commit is contained in:
Iván Briano 2011-07-28 12:11:26 +00:00
parent ddb13f269b
commit 49761b1c02
4 changed files with 241 additions and 2 deletions

View File

@ -4763,6 +4763,82 @@
* @example photocam_example_01.c
*/
/**
* @page inwin_example_01 Inwin - General overview
*
* Inwin is a very simple widget to show, so this example will be a very simple
* one, just using all of the available API.
*
* The program is nothing but a window with a lonely button, as shown here.
*
* @image html screenshots/inwin_example.png
* @image latex screenshots/inwin_example.eps width=\textwidth
*
* And pressing the button makes an inwin appear.
*
* @image html screenshots/inwin_example_a.png
* @image latex screenshots/inwin_example_a.eps width=\textwidth
*
* And the code is just as simple. We being with some global variables to keep
* track of our Inwin.
* @dontinclude inwin_example.c
* @skip static
* @until current_style
*
* And two callbacks used by the buttons the above screenshot showed. In these,
* we check if @c inwin exists and execute the proper action on it. If it's not
* there anymore, then we were abandoned to our luck, so we disabled ourselves.
* @until _inwin_destroy
* @until }
* @until }
*
* The lonely button from the beginning, when clicked, will call the following
* function, which begins by checking if an inwin exists, and if it's there,
* we bring it back to the front and exit from our function without any further
* ado.
* @until }
*
* But if no inwin is there to show, we need to create one. First we need the
* top-most window for the program, as no inwin can be created using other
* objects as parents. Then we create our popup, set the next style in the list
* and show it.
* @until current_style =
*
* As for the content of our inwin, it's just a box with a label and some
* buttons inside.
* @until _inwin_destroy
* @until }
*
* Now, all the code above shows how every object must always be set as content
* for some other object, be it by setting the full content, packing it in a
* box or table or working as icon for some other widget. But we didn't do
* anything like that for the inwin, this one is just created and shown and
* everything works. Other widgets can be used this way, but they would need
* to be placed and resized manually or nothing would be shown correctly. The
* inwin, however, sets itself as a children of the top-level window and will
* be resized as the parent window changes too.
*
* Another characteristic of Inwin is that when it's shown above everyone else,
* it will work kind of like a modal window, blocking any other widget from
* receiving events until the window is manually dismissed by pressing some
* button to close it or having blocking task signalling its completion so
* normal operations can be resumed. This is unlike the @ref Hover widget,
* that would show its content on top of the designated target, but clicking
* anywhere else would dismiss it automatically.
*
* To illustrate that last point, when we close the main window and an inwin
* is still there, we'll take out the content from the inwin and place it in
* a hover.
* @until }
* @until }
*
* And the rest of the program doesn't have anything else related to inwin,
* so it won't be shown here, but you can find it in
* @ref inwin_example.c "inwin_example.c".
*
* @example inwin_example.c
*/
/**
* @page bg_example_01_c bg_example_01.c
* @include bg_example_01.c

View File

@ -96,7 +96,8 @@ SRCS = \
slideshow_example.c \
progressbar_example.c \
notify_example_01.c \
photocam_example_01.c
photocam_example_01.c \
inwin_example.c
pkglib_PROGRAMS =
@ -182,7 +183,8 @@ pkglib_PROGRAMS += \
slideshow_example \
progressbar_example \
notify_example_01 \
photocam_example_01
photocam_example_01 \
inwin_example
# This variable will hold the list of screenshots that will be made
# by "make screenshots". Each item in the list is of the form:
@ -242,6 +244,8 @@ SCREENSHOTS = \
notify_example_01:notify_example_01_a.png:6.0 \
slideshow_example:slideshow_example.png:1.0 \
photocam_example_01:photocam_example_01.png:3
inwin_example:inwin_example.png:0.0 \
inwin_example:inwin_example_a.png:0.2
HTML_SS_DIR=$(top_builddir)/doc/html/screenshots
LATEX_SS_DIR=$(top_builddir)/doc/latex/screenshots

View File

@ -0,0 +1,156 @@
/*
* gcc -o inwin_example inwin_example.c `pkg-config --cflags --libs elementary`
*/
#include <Elementary.h>
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#else
# define __UNUSED__
#endif
static Evas_Object *inwin = NULL;
static const char *styles[] = {
"default",
"minimal",
"minimal_vertical"
};
static int current_style = 0;
static void
_inwin_hide(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
{
if (inwin)
{
evas_object_hide(inwin);
return;
}
elm_object_text_set(obj, "No inwin!");
elm_object_disabled_set(obj, EINA_TRUE);
}
static void
_inwin_destroy(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
{
if (inwin)
{
evas_object_del(inwin);
inwin = NULL;
return;
}
elm_object_text_set(obj, "No inwin!");
elm_object_disabled_set(obj, EINA_TRUE);
}
static void
_btn_click_cb(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
{
Evas_Object *o, *parent;
if (inwin)
{
elm_win_inwin_activate(inwin);
return;
}
parent = elm_object_top_widget_get(obj);
inwin = elm_win_inwin_add(parent);
elm_object_style_set(inwin, styles[current_style]);
evas_object_show(inwin);
current_style = (current_style + 1) % 3;
o = elm_box_add(parent);
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_win_inwin_content_set(inwin, o);
evas_object_show(o);
o = elm_label_add(parent);
elm_object_text_set(o, "Click on the first button to hide the Inwin.<ps>"
"Second to destroy it<ps>");
evas_object_show(o);
elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
o = elm_button_add(parent);
elm_object_text_set(o, "Hide");
evas_object_show(o);
evas_object_smart_callback_add(o, "clicked", _inwin_hide, NULL);
elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
o = elm_button_add(parent);
elm_object_text_set(o, "Destroy");
evas_object_show(o);
evas_object_smart_callback_add(o, "clicked", _inwin_destroy, NULL);
elm_box_pack_end(elm_win_inwin_content_get(inwin), o);
}
static void
_win_del_cb(void *data __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
{
if (inwin)
{
Evas_Object *hover, *o = elm_win_inwin_content_unset(inwin);
evas_object_del(inwin);
inwin = NULL;
hover = elm_hover_add(obj);
elm_hover_target_set(hover, obj);
elm_hover_content_set(hover, "middle", o);
evas_object_show(hover);
return;
}
evas_object_del(obj);
}
static Eina_Bool
_screenshot_hack_cb(void *data)
{
_btn_click_cb(NULL, data, NULL);
return EINA_FALSE;
}
int
elm_main(int argc __UNUSED__, char *argv[] __UNUSED__)
{
Evas_Object *win, *bg, *box, *o;
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
win = elm_win_add(NULL, "inwin-example", ELM_WIN_BASIC);
elm_win_title_set(win, "Inwin Example");
evas_object_resize(win, 400, 400);
evas_object_show(win);
evas_object_smart_callback_add(win, "delete,request", _win_del_cb, NULL);
bg = elm_bg_add(win);
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, bg);
evas_object_show(bg);
box = elm_box_add(win);
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, box);
evas_object_show(box);
o = elm_button_add(win);
elm_object_text_set(o, "Inwin!");
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(o, 0.0, 0.0);
elm_box_pack_end(box, o);
evas_object_show(o);
evas_object_smart_callback_add(o, "clicked", _btn_click_cb, NULL);
if (!strncmp(elm_engine_current_get(), "shot", 4))
ecore_timer_add(0.1, _screenshot_hack_cb, o);
elm_run();
return 0;
}
ELM_MAIN();

View File

@ -1743,6 +1743,9 @@ extern "C" {
* possible, but it's sized vertically the most it needs to fit its\
* contents.
*
* Some examples of Inwin can be found in the following:
* @li @ref inwin_example_01
*
* @{
*/
/**