2009-11-24 07:34:58 +08:00
|
|
|
/*
|
|
|
|
* File : toplevel.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
|
|
|
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* The license and distribution terms for this file may be
|
|
|
|
* found in the file LICENSE in this distribution or at
|
|
|
|
* http://www.rt-thread.org/license/LICENSE
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2009-10-16 Bernard first version
|
|
|
|
*/
|
|
|
|
#include <rtgui/rtgui_system.h>
|
|
|
|
#include <rtgui/widgets/toplevel.h>
|
2012-04-18 23:06:12 +08:00
|
|
|
#include <rtgui/widgets/window.h>
|
|
|
|
#include <rtgui/widgets/title.h>
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
static void _rtgui_toplevel_constructor(rtgui_toplevel_t *toplevel)
|
|
|
|
{
|
|
|
|
/* set event handler */
|
2012-04-18 23:06:12 +08:00
|
|
|
rtgui_object_set_event_handler(RTGUI_OBJECT(toplevel), rtgui_toplevel_event_handler);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* set toplevel to self */
|
2012-04-18 23:06:12 +08:00
|
|
|
if (RTGUI_IS_WINTITLE(toplevel))
|
|
|
|
RTGUI_WIDGET(toplevel)->toplevel = (struct rtgui_win*)toplevel;
|
|
|
|
else
|
|
|
|
RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIN(toplevel);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* init toplevel property */
|
|
|
|
toplevel->drawing = 0;
|
|
|
|
|
|
|
|
/* hide toplevel default */
|
|
|
|
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(toplevel));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel)
|
|
|
|
{
|
|
|
|
/* release external clip info */
|
|
|
|
toplevel->drawing = 0;
|
|
|
|
}
|
|
|
|
|
2012-04-18 23:06:12 +08:00
|
|
|
DEFINE_CLASS_TYPE(toplevel, "toplevel",
|
2011-05-13 18:53:51 +08:00
|
|
|
RTGUI_CONTAINER_TYPE,
|
|
|
|
_rtgui_toplevel_constructor,
|
|
|
|
_rtgui_toplevel_destructor,
|
|
|
|
sizeof(struct rtgui_toplevel));
|
2009-11-24 07:34:58 +08:00
|
|
|
|
2012-04-18 23:06:12 +08:00
|
|
|
rt_bool_t rtgui_toplevel_event_handler(struct rtgui_object* object, rtgui_event_t* event)
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2012-04-18 23:06:12 +08:00
|
|
|
struct rtgui_toplevel* toplevel;
|
|
|
|
|
|
|
|
RT_ASSERT(object != RT_NULL);
|
|
|
|
RT_ASSERT(event != RT_NULL);
|
|
|
|
|
|
|
|
toplevel = RTGUI_TOPLEVEL(object);
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
{
|
|
|
|
case RTGUI_EVENT_CLIP_INFO:
|
|
|
|
/* update toplevel clip */
|
|
|
|
rtgui_toplevel_update_clip(toplevel);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTGUI_EVENT_COMMAND:
|
2012-04-18 23:06:12 +08:00
|
|
|
if (rtgui_container_dispatch_event(RTGUI_CONTAINER(object), event) != RT_TRUE)
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2010-01-04 08:05:01 +08:00
|
|
|
#ifndef RTGUI_USING_SMALL_SIZE
|
2012-04-18 23:06:12 +08:00
|
|
|
if (RTGUI_WIDGET(object)->on_command != RT_NULL)
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
2012-04-18 23:06:12 +08:00
|
|
|
RTGUI_WIDGET(object)->on_command(object, event);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
2010-01-04 08:05:01 +08:00
|
|
|
#endif
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
else return RT_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
2012-04-18 23:06:12 +08:00
|
|
|
return rtgui_container_event_handler(object, event);
|
2009-11-24 07:34:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return RT_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtgui_toplevel_update_clip(rtgui_toplevel_t* top)
|
|
|
|
{
|
2012-04-18 23:06:12 +08:00
|
|
|
rtgui_container_t* view;
|
2009-11-24 07:34:58 +08:00
|
|
|
struct rtgui_list_node* node;
|
|
|
|
|
2012-04-18 23:06:12 +08:00
|
|
|
if (top == RT_NULL)
|
|
|
|
return;
|
2009-11-24 07:34:58 +08:00
|
|
|
|
|
|
|
/* update the clip info of each child */
|
2012-04-18 23:06:12 +08:00
|
|
|
view = RTGUI_CONTAINER(top);
|
|
|
|
rtgui_list_foreach(node, &(view->children))
|
2009-11-24 07:34:58 +08:00
|
|
|
{
|
|
|
|
rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
|
|
|
|
|
|
|
|
rtgui_widget_update_clip(child);
|
|
|
|
}
|
|
|
|
}
|