提交 8457439d 编写于 作者: B bernard.xiong

use new object type implementation.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1402 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 169c31fc
......@@ -58,6 +58,7 @@ widgets/textbox.c
widgets/listbox.c
widgets/title.c
widgets/toplevel.c
widgets/notebook.c
widgets/view.c
widgets/list_view.c
widgets/about_view.c
......
......@@ -18,6 +18,7 @@
#include <rtgui/image_xpm.h>
#include <rtgui/rtgui_system.h>
#ifdef RTGUI_IMAGE_XPM
#define XPM_MAGIC_LEN 9
static rt_bool_t rtgui_image_xpm_check(struct rtgui_filerw * file);
......@@ -607,4 +608,4 @@ static void rtgui_image_xpm_blit(struct rtgui_image* image, struct rtgui_dc* dc,
}
}
}
#endif
......@@ -28,90 +28,36 @@ static void _rtgui_object_destructor(rtgui_object_t *object)
/* nothing */
}
rtgui_type_t *rtgui_type_create(const char *type_name, rtgui_type_t *parent_type,
int type_size, rtgui_constructor_t constructor,
rtgui_destructor_t destructor)
{
rtgui_type_t *new_type;
if (!type_name)
return RT_NULL;
new_type = rtgui_malloc(sizeof(rtgui_type_t));
new_type->name = rt_strdup(type_name);
new_type->size = type_size;
new_type->constructor = constructor;
new_type->destructor = destructor;
if (!parent_type)
{
new_type->hierarchy_depth = 0;
new_type->hierarchy = RT_NULL;
}
else
{
/* Build the type hierarchy */
new_type->hierarchy_depth = parent_type->hierarchy_depth + 1;
new_type->hierarchy = rtgui_malloc(sizeof(rtgui_type_t *) * new_type->hierarchy_depth);
new_type->hierarchy[0] = parent_type;
rt_memcpy(new_type->hierarchy + 1, parent_type->hierarchy,
parent_type->hierarchy_depth * sizeof(rtgui_type_t *));
}
return new_type;
}
void rtgui_type_destroy(rtgui_type_t *type)
{
if (!type) return;
if (type->hierarchy) rtgui_free(type->hierarchy);
rtgui_free(type->name);
rtgui_free(type);
}
DEFINE_CLASS_TYPE(type, "object",
RT_NULL,
_rtgui_object_constructor,
_rtgui_object_destructor,
sizeof(struct rtgui_object));
void rtgui_type_object_construct(rtgui_type_t *type, rtgui_object_t *object)
{
int i;
/* first call parent's type */
if (type->parent != RT_NULL)
rtgui_type_object_construct(type->parent, object);
if (!type || !object) return;
/* Call the constructors */
for (i = type->hierarchy_depth - 1; i >= 0; i--)
{
if (type->hierarchy[i]->constructor)
type->hierarchy[i]->constructor(object);
}
if (type->constructor) type->constructor(object);
}
void rtgui_type_destructors_call(rtgui_type_t *type, rtgui_object_t *object)
{
int i;
if (!type || !object) return;
if (type->destructor) type->destructor(object);
for (i = 0; i < type->hierarchy_depth; i++)
while (type)
{
if (type->hierarchy[i]->destructor)
type->hierarchy[i]->destructor(object);
if (type->destructor) type->destructor(object);
type = type->parent;
}
}
rt_bool_t rtgui_type_inherits_from(rtgui_type_t *type, rtgui_type_t *parent)
{
int i;
if (!type || !parent) return RT_FALSE;
if (type == parent) return RT_TRUE;
for (i = 0; i < type->hierarchy_depth; i++)
while (type)
{
if (type->hierarchy[i] == parent) return RT_TRUE;
if (type == parent) return RT_TRUE;
type = type->parent;
}
return RT_FALSE;
......@@ -119,9 +65,7 @@ rt_bool_t rtgui_type_inherits_from(rtgui_type_t *type, rtgui_type_t *parent)
rtgui_type_t *rtgui_type_parent_type_get(rtgui_type_t *type)
{
if (!type || !type->hierarchy) return RT_NULL;
return type->hierarchy[0];
return type->parent;
}
const char *rtgui_type_name_get(rtgui_type_t *type)
......@@ -131,6 +75,7 @@ const char *rtgui_type_name_get(rtgui_type_t *type)
return type->name;
}
#ifdef RTGUI_OBJECT_TRACE
struct rtgui_object_information
{
rt_uint32_t objs_number;
......@@ -138,6 +83,7 @@ struct rtgui_object_information
rt_uint32_t max_allocated;
};
struct rtgui_object_information obj_info = {0, 0, 0};
#endif
/**
* @brief Creates a new object: it calls the corresponding constructors (from the constructor of the base class to the
......@@ -155,10 +101,12 @@ rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type)
new_object = rtgui_malloc(object_type->size);
if (new_object == RT_NULL) return RT_NULL;
#ifdef RTGUI_OBJECT_TRACE
obj_info.objs_number ++;
obj_info.allocated_size += object_type->size;
if (obj_info.allocated_size > obj_info.max_allocated)
obj_info.max_allocated = obj_info.allocated_size;
#endif
new_object->type = object_type;
new_object->is_static = RT_FALSE;
......@@ -179,8 +127,10 @@ void rtgui_object_destroy(rtgui_object_t *object)
{
if (!object || object->is_static == RT_TRUE) return;
#ifdef RTGUI_OBJECT_TRACE
obj_info.objs_number --;
obj_info.allocated_size -= object->type->size;
#endif
/* call destructor */
RT_ASSERT(object->type != RT_NULL);
......@@ -190,25 +140,6 @@ void rtgui_object_destroy(rtgui_object_t *object)
rtgui_free(object);
}
/**
* @internal
* @brief Gets the type of a rtgui_object
* @return Returns the type of a rtgui_object
*/
rtgui_type_t *rtgui_object_type_get(void)
{
static rtgui_type_t *object_type = RT_NULL;
if (!object_type)
{
object_type = rtgui_type_create("object", RT_NULL,
sizeof(rtgui_object_t), RTGUI_CONSTRUCTOR(_rtgui_object_constructor),
RTGUI_DESTRUCTOR(_rtgui_object_destructor));
}
return object_type;
}
/**
* @brief Checks if @a object can be cast to @a type.
* If @a object doesn't inherit from @a type, a warning is displayed in the console but the object is returned anyway.
......@@ -217,16 +148,16 @@ rtgui_type_t *rtgui_object_type_get(void)
* @return Returns the object
* @note You usually do not need to call this function, use specific macros instead (ETK_IS_WIDGET() for example)
*/
rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *object, rtgui_type_t *type)
rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *obj, rtgui_type_t *obj_type)
{
if (!object) return RT_NULL;
if (!obj) return RT_NULL;
if (!rtgui_type_inherits_from(object->type, type))
if (!rtgui_type_inherits_from(obj->type, obj_type))
{
rt_kprintf("Invalid cast from \"%s\" to \"%s\"\n", rtgui_type_name_get(object->type), rtgui_type_name_get(type));
rt_kprintf("Invalid cast from \"%s\" to \"%s\"\n", rtgui_type_name_get(obj->type), rtgui_type_name_get(obj_type));
}
return object;
return obj;
}
/**
......@@ -240,3 +171,4 @@ rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object)
return object->type;
}
......@@ -35,7 +35,6 @@ void rtgui_system_server_init()
rtgui_font_system_init();
/* init rtgui server */
rtgui_panel_init();
rtgui_topwin_init();
rtgui_server_init();
......@@ -236,11 +235,6 @@ static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event)
struct rtgui_event_monitor *monitor = (struct rtgui_event_monitor*)event;
if (monitor->panel != RT_NULL)
{
#if 0
rt_kprintf("panel: %s, the rect is:(%d, %d) - (%d, %d)", monitor->panel->name,
monitor->rect.x1, monitor->rect.y1,
monitor->rect.x2, monitor->rect.y2);
#endif
rt_kprintf("the rect is:(%d, %d) - (%d, %d)",
monitor->rect.x1, monitor->rect.y1,
monitor->rect.x2, monitor->rect.y2);
......
......@@ -275,6 +275,7 @@ struct rtgui_event_paint
struct rtgui_event parent;
rtgui_win_t* wid; /* destination window */
rtgui_rect_t rect; /* rect to be updated */
};
struct rtgui_timer;
......
......@@ -42,9 +42,8 @@ struct rtgui_type
/* type name */
char* name;
/* hierarchy and depth */
struct rtgui_type **hierarchy;
int hierarchy_depth;
/* parent type link */
struct rtgui_type *parent;
/* constructor and destructor */
rtgui_constructor_t constructor;
......@@ -54,11 +53,16 @@ struct rtgui_type
int size;
};
typedef struct rtgui_type rtgui_type_t;
#define RTGUI_TYPE(type) (struct rtgui_type*)&(_rtgui_##type)
rtgui_type_t *rtgui_type_create(const char *type_name, rtgui_type_t *parent_type,
int type_size, rtgui_constructor_t constructor,
rtgui_destructor_t destructor);
void rtgui_type_destroy(rtgui_type_t *type);
#define DECLARE_CLASS_TYPE(type) extern const struct rtgui_type _rtgui_##type
#define DEFINE_CLASS_TYPE(type, name, parent, constructor, destructor, size) \
const struct rtgui_type _rtgui_##type = { \
name, \
parent, \
constructor, \
destructor, \
size }
void rtgui_type_object_construct(rtgui_type_t *type, rtgui_object_t *object);
void rtgui_type_destructors_call(rtgui_type_t *type, rtgui_object_t *object);
......@@ -68,17 +72,18 @@ const char *rtgui_type_name_get(rtgui_type_t *type);
rtgui_type_t *rtgui_type_get_from_name(const char *name);
#ifdef RTGUI_USING_CAST_CHECK
#define RTGUI_OBJECT_CAST(obj, rtgui_type_t, c_type) \
((c_type *)rtgui_object_check_cast((rtgui_object_t *)(obj), (rtgui_type_t)))
#define RTGUI_OBJECT_CAST(obj, obj_type, c_type) \
((c_type *)rtgui_object_check_cast((rtgui_object_t *)(obj), (obj_type)))
#else
#define RTGUI_OBJECT_CAST(obj, rtgui_type_t, c_type) ((c_type *)(obj))
#define RTGUI_OBJECT_CAST(obj, obj_type, c_type) ((c_type *)(obj))
#endif
#define RTGUI_OBJECT_CHECK_TYPE(_obj, _type) \
(rtgui_type_inherits_from(((rtgui_object_t *)(_obj))->type, (_type)))
DECLARE_CLASS_TYPE(type);
/** Gets the type of an object */
#define RTGUI_OBJECT_TYPE (rtgui_object_type_get())
#define RTGUI_OBJECT_TYPE RTGUI_TYPE(type)
/** Casts the object to an rtgui_object_t */
#define RTGUI_OBJECT(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_OBJECT_TYPE, rtgui_object_t))
/** Checks if the object is an rtgui_Object */
......@@ -88,7 +93,7 @@ rtgui_type_t *rtgui_type_get_from_name(const char *name);
struct rtgui_object
{
/* object type */
rtgui_type_t* type;
const rtgui_type_t* type;
rt_bool_t is_static;
};
......
......@@ -63,7 +63,6 @@ typedef struct rtgui_topwin rtgui_topwin_t;
/* top win manager init */
void rtgui_topwin_init(void);
void rtgui_panel_init (void);
void rtgui_server_init(void);
/* post an event to server */
......
......@@ -20,8 +20,9 @@
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
DECLARE_CLASS_TYPE(aboutview);
/** Gets the type of a about view */
#define RTGUI_ABOUT_VIEW_TYPE (rtgui_about_view_type_get())
#define RTGUI_ABOUT_VIEW_TYPE (RTGUI_TYPE(aboutview))
/** Casts the object to a about view */
#define RTGUI_ABOUT_VIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_ABOUT_VIEW_TYPE, rtgui_about_view_t))
/** Checks if the object is a about view */
......
......@@ -22,8 +22,10 @@
extern "C" {
#endif
DECLARE_CLASS_TYPE(box);
/** Gets the type of a box */
#define RTGUI_BOX_TYPE (rtgui_box_type_get())
#define RTGUI_BOX_TYPE (RTGUI_TYPE(box))
/** Casts the object to an rtgui_box */
#define RTGUI_BOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_BOX_TYPE, rtgui_box_t))
/** Checks if the object is an rtgui_box */
......@@ -38,8 +40,6 @@ struct rtgui_box
};
typedef struct rtgui_box rtgui_box_t;
rtgui_type_t *rtgui_box_type_get(void);
struct rtgui_box* rtgui_box_create(int orientation, rtgui_rect_t* rect);
void rtgui_box_destroy(struct rtgui_box* box);
......
......@@ -27,8 +27,10 @@ extern "C" {
* @{
*/
DECLARE_CLASS_TYPE(button);
/** Gets the type of a button */
#define RTGUI_BUTTON_TYPE (rtgui_button_type_get())
#define RTGUI_BUTTON_TYPE (RTGUI_TYPE(button))
/** Casts the object to an rtgui_button */
#define RTGUI_BUTTON(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_BUTTON_TYPE, rtgui_button_t))
/** Checks if the object is an rtgui_button */
......@@ -59,8 +61,6 @@ struct rtgui_button
};
typedef struct rtgui_button rtgui_button_t;
rtgui_type_t *rtgui_button_type_get(void);
rtgui_button_t* rtgui_button_create(const char* text);
rtgui_button_t* rtgui_pushbutton_create(const char* text);
void rtgui_button_destroy(rtgui_button_t* btn);
......
......@@ -5,8 +5,10 @@
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/label.h>
/** Gets the type of a button */
#define RTGUI_CHECKBOX_TYPE (rtgui_checkbox_type_get())
DECLARE_CLASS_TYPE(checkbox);
/** Gets the type of a checkbox */
#define RTGUI_CHECKBOX_TYPE (RTGUI_TYPE(checkbox))
/** Casts the object to an rtgui_button */
#define RTGUI_CHECKBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_CHECKBOX_TYPE, rtgui_checkbox))
/** Checks if the object is an rtgui_button */
......@@ -28,8 +30,6 @@ struct rtgui_checkbox
};
typedef struct rtgui_checkbox rtgui_checkbox_t;
rtgui_type_t *rtgui_checkbox_type_get(void);
rtgui_checkbox_t* rtgui_checkbox_create(const char* text, rt_bool_t checked);
void rtgui_checkbox_destroy(rtgui_checkbox_t* checkbox);
......
......@@ -6,8 +6,9 @@
#include <rtgui/widgets/window.h>
#include <rtgui/widgets/listbox.h>
DECLARE_CLASS_TYPE(combobox);
/** Gets the type of a combobox */
#define RTGUI_COMBOBOX_TYPE (rtgui_combobox_type_get())
#define RTGUI_COMBOBOX_TYPE (RTGUI_TYPE(combobox))
/** Casts the object to a rtgui_combobox */
#define RTGUI_COMBOBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_COMBOBOX_TYPE, rtgui_combobox_t))
/** Checks if the object is a rtgui_combobox */
......@@ -37,7 +38,6 @@ struct rtgui_combobox
};
typedef struct rtgui_combobox rtgui_combobox_t;
rtgui_type_t *rtgui_combobox_type_get(void);
rtgui_combobox_t *rtgui_combobox_create(struct rtgui_listbox_item* items, rt_uint16_t counter, struct rtgui_rect* rect);
void rtgui_combobox_destroy(rtgui_combobox_t* box);
......
......@@ -16,8 +16,9 @@
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(container);
/** Gets the type of a container */
#define RTGUI_CONTAINER_TYPE (rtgui_container_type_get())
#define RTGUI_CONTAINER_TYPE (RTGUI_TYPE(container))
/** Casts the object to a rtgui_container */
#define RTGUI_CONTAINER(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_CONTAINER_TYPE, rtgui_container_t))
/** Checks if the object is a rtgui_container */
......@@ -33,8 +34,6 @@ struct rtgui_container
};
typedef struct rtgui_container rtgui_container_t;
rtgui_type_t *rtgui_container_type_get(void);
void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t* child);
void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t* child);
void rtgui_container_destroy_children(rtgui_container_t *container);
......
......@@ -14,8 +14,9 @@ struct rtgui_file_item
rt_uint32_t size;
};
DECLARE_CLASS_TYPE(filelist);
/** Gets the type of a filelist view */
#define RTGUI_FILELIST_VIEW_TYPE (rtgui_filelist_view_type_get())
#define RTGUI_FILELIST_VIEW_TYPE (RTGUI_TYPE(filelist))
/** Casts the object to a filelist */
#define RTGUI_FILELIST_VIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_FILELIST_VIEW_TYPE, rtgui_filelist_view_t))
/** Checks if the object is a filelist view */
......@@ -43,8 +44,6 @@ struct rtgui_filelist_view
};
typedef struct rtgui_filelist_view rtgui_filelist_view_t;
rtgui_type_t *rtgui_filelist_view_type_get(void);
rtgui_filelist_view_t* rtgui_filelist_view_create(rtgui_workbench_t* workbench,
const char* directory, const char* pattern, const rtgui_rect_t* rect);
void rtgui_filelist_view_destroy(rtgui_filelist_view_t* view);
......
......@@ -18,8 +18,9 @@
#include <rtgui/image.h>
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(iconbox);
/** Gets the type of a iconbox */
#define RTGUI_ICONBOX_TYPE (rtgui_iconbox_type_get())
#define RTGUI_ICONBOX_TYPE (RTGUI_TYPE(iconbox))
/** Casts the object to a rtgui_iconbox */
#define RTGUI_ICONBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_ICONBOX_TYPE, rtgui_iconbox_t))
/** Checks if the object is a rtgui_iconbox */
......@@ -44,8 +45,6 @@ struct rtgui_iconbox
};
typedef struct rtgui_iconbox rtgui_iconbox_t;
rtgui_type_t *rtgui_iconbox_type_get(void);
struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, const char* text, int position);
void rtgui_iconbox_destroy(struct rtgui_iconbox* iconbox);
......
......@@ -17,8 +17,10 @@
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(label);
/** Gets the type of a button */
#define RTGUI_LABEL_TYPE (rtgui_label_type_get())
#define RTGUI_LABEL_TYPE (RTGUI_TYPE(label))
/** Casts the object to an rtgui_button */
#define RTGUI_LABEL(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LABEL_TYPE, rtgui_label_t))
/** Checks if the object is an rtgui_button */
......@@ -36,8 +38,6 @@ struct rtgui_label
};
typedef struct rtgui_label rtgui_label_t;
rtgui_type_t *rtgui_label_type_get(void);
rtgui_label_t* rtgui_label_create(const char* text);
void rtgui_label_destroy(rtgui_label_t* label);
......
......@@ -31,8 +31,9 @@ struct rtgui_list_item
void *parameter;
};
DECLARE_CLASS_TYPE(listview);
/** Gets the type of a list view */
#define RTGUI_LIST_VIEW_TYPE (rtgui_list_view_type_get())
#define RTGUI_LIST_VIEW_TYPE (RTGUI_TYPE(listview))
/** Casts the object to a filelist */
#define RTGUI_LIST_VIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LIST_VIEW_TYPE, rtgui_list_view_t))
/** Checks if the object is a filelist view */
......
......@@ -26,8 +26,9 @@ struct rtgui_listbox_item
rtgui_image_t *image;
};
DECLARE_CLASS_TYPE(listbox);
/** Gets the type of a list box */
#define RTGUI_LISTBOX_TYPE (rtgui_listbox_type_get())
#define RTGUI_LISTBOX_TYPE (RTGUI_TYPE(listbox))
/** Casts the object to a filelist */
#define RTGUI_LISTBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LISTBOX_TYPE, rtgui_listbox_t))
/** Checks if the object is a filelist box */
......@@ -54,8 +55,6 @@ struct rtgui_listbox
typedef struct rtgui_listbox rtgui_listbox_t;
typedef void (*rtgui_onitem_func_t)(struct rtgui_widget* widget, rtgui_event_t *event);
rtgui_type_t *rtgui_listbox_type_get(void);
rtgui_listbox_t* rtgui_listbox_create(const struct rtgui_listbox_item* items, rt_uint16_t count,
rtgui_rect_t *rect);
void rtgui_listbox_destroy(rtgui_listbox_t* box);
......
......@@ -20,8 +20,9 @@
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(listctrl);
/** Gets the type of a listctrl */
#define RTGUI_LISTCTRL_TYPE (rtgui_listctrl_type_get())
#define RTGUI_LISTCTRL_TYPE (RTGUI_TYPE(listctrl))
/** Casts the object to a listctrl */
#define RTGUI_LISTCTRL(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LISTCTRL_TYPE, rtgui_listctrl_t))
/** Checks if the object is a listctrl */
......
......@@ -33,8 +33,9 @@ struct rtgui_menu_item
};
typedef struct rtgui_menu_item rtgui_menu_item_t;
DECLARE_CLASS_TYPE(menu);
/** Gets the type of a menu */
#define RTGUI_MENU_TYPE (rtgui_menu_type_get())
#define RTGUI_MENU_TYPE (RTGUI_TYPE(menu))
/** Casts the object to an rtgui_menu */
#define RTGUI_MENU(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MENU_TYPE, rtgui_menu_t))
/** Checks if the object is an rtgui_menu */
......
......@@ -4,8 +4,9 @@
#include <rtgui/rtgui.h>
#include <rtgui/widgets/container.h>
DECLARE_CLASS_TYPE(notebook);
/** Gets the type of a notebook */
#define RTGUI_NOTEBOOK_TYPE (rtgui_notebook_type_get())
#define RTGUI_NOTEBOOK_TYPE (RTGUI_TYPE(notebook))
/** Casts the object to a notebook control */
#define RTGUI_NOTEBOOK(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_NOTEBOOK_TYPE, rtgui_notebook_t))
/** Checks if the object is a notebook control */
......
......@@ -4,8 +4,9 @@
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(progressbar);
/** Gets the type of a progressbar */
#define RTGUI_PROGRESSBAR_TYPE (rtgui_progressbar_type_get())
#define RTGUI_PROGRESSBAR_TYPE (RTGUI_TYPE(progressbar))
/** Casts the object to a rtgui_progressbar */
#define RTGUI_PROGRESSBAR(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_PROGRESSBAR_TYPE, rtgui_progressbar_t))
/** Checks if the object is a rtgui_progressbar */
......@@ -25,8 +26,6 @@ struct rtgui_progressbar
};
typedef struct rtgui_progressbar rtgui_progressbar_t;
rtgui_type_t *rtgui_progressbar_type_get(void);
struct rtgui_progressbar* rtgui_progressbar_create(int orientation, int range, rtgui_rect_t* r);
void rtgui_progressbar_destroy(struct rtgui_progressbar* p_bar);
......
......@@ -4,8 +4,9 @@
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(radiobox);
/** Gets the type of a radiobox */
#define RTGUI_RADIOBOX_TYPE (rtgui_radiobox_type_get())
#define RTGUI_RADIOBOX_TYPE (RTGUI_TYPE(radiobox))
/** Casts the object to an rtgui_radiobox */
#define RTGUI_RADIOBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_RADIOBOX_TYPE, rtgui_radiobox_t))
/** Checks if the object is an rtgui_radiobox */
......@@ -30,8 +31,6 @@ struct rtgui_radiobox
};
typedef struct rtgui_radiobox rtgui_radiobox_t;
rtgui_type_t *rtgui_radiobox_type_get(void);
struct rtgui_radiobox* rtgui_radiobox_create(const char* label, int orient, char** radio_items, int number);
void rtgui_radiobox_destroy(struct rtgui_radiobox* radiobox);
......
......@@ -21,8 +21,9 @@
extern "C" {
#endif
DECLARE_CLASS_TYPE(scrollbar);
/** Gets the type of a scrollbar */
#define RTGUI_SCROLLBAR_TYPE (rtgui_scrollbar_type_get())
#define RTGUI_SCROLLBAR_TYPE (RTGUI_TYPE(scrollbar))
/** Casts the object to an rtgui_scrollbar */
#define RTGUI_SCROLLBAR(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_SCROLLBAR_TYPE, rtgui_scrollbar_t))
/** Checks if the object is an rtgui_scrollbar */
......@@ -65,8 +66,6 @@ struct rtgui_scrollbar
};
typedef struct rtgui_scrollbar rtgui_scrollbar_t;
rtgui_type_t *rtgui_scrollbar_type_get(void);
struct rtgui_scrollbar* rtgui_scrollbar_create(int orient, rtgui_rect_t* r);
void rtgui_scrollbar_destroy(struct rtgui_scrollbar* bar);
......
......@@ -17,8 +17,9 @@
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(slider);
/** Gets the type of a slider */
#define RTGUI_SLIDER_TYPE (rtgui_slider_type_get())
#define RTGUI_SLIDER_TYPE (RTGUI_TYPE(slider))
/** Casts the object to an rtgui_slider */
#define RTGUI_SLIDER(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_SLIDER_TYPE, rtgui_slider_t))
/** Checks if the object is an rtgui_slider */
......@@ -38,8 +39,6 @@ struct rtgui_slider
};
typedef struct rtgui_slider rtgui_slider_t;
rtgui_type_t *rtgui_slider_type_get(void);
struct rtgui_slider* rtgui_slider_create(rt_size_t min, rt_size_t max, int orient);
void rtgui_slider_destroy(struct rtgui_slider* slider);
......
......@@ -8,8 +8,9 @@
* the static line widget
*/
DECLARE_CLASS_TYPE(staticline);
/** Gets the type of a staticline */
#define RTGUI_STATICLINE_TYPE (rtgui_staticline_type_get())
#define RTGUI_STATICLINE_TYPE (RTGUI_TYPE(staticline))
/** Casts the object to an rtgui_staticline */
#define RTGUI_STATICLINE(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_STATICLINE_TYPE, rtgui_staticline_t))
/** Checks if the object is an rtgui_staticline */
......
......@@ -17,8 +17,9 @@
#include <rtgui/rtgui.h>
#include <rtgui/widgets/widget.h>
DECLARE_CLASS_TYPE(textbox);
/** Gets the type of a textbox */
#define RTGUI_TEXTBOX_TYPE (rtgui_textbox_type_get())
#define RTGUI_TEXTBOX_TYPE (RTGUI_TYPE(textbox))
/** Casts the object to a rtgui_textbox */
#define RTGUI_TEXTBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_TEXTBOX_TYPE, rtgui_textbox_t))
/** Checks if the object is a rtgui_textbox */
......@@ -61,8 +62,6 @@ struct rtgui_textbox
};
typedef struct rtgui_textbox rtgui_textbox_t;
rtgui_type_t *rtgui_textbox_type_get(void);
struct rtgui_textbox* rtgui_textbox_create(const char* text, rt_uint8_t flag);
void rtgui_textbox_destroy(struct rtgui_textbox* box);
......
......@@ -16,8 +16,9 @@
#include <rtgui/widgets/toplevel.h>
/** Gets the type of a top win */
#define RTGUI_WINTITLE_TYPE (rtgui_wintitle_type_get())
DECLARE_CLASS_TYPE(wintitle);
/** Gets the type of a title */
#define RTGUI_WINTITLE_TYPE (RTGUI_TYPE(wintitle))
/** Casts the object to an rtgui_wintitle */
#define RTGUI_WINTITLE(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WINTITLE_TYPE, rtgui_wintitle_t))
/** Checks if the object is an rtgui_wintitle */
......@@ -32,8 +33,6 @@ struct rtgui_wintitle
};
typedef struct rtgui_wintitle rtgui_wintitle_t;
rtgui_type_t* rtgui_wintitle_type_get(void);
rtgui_wintitle_t* rtgui_wintitle_create(const char* title);
void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle);
......
......@@ -16,8 +16,9 @@
#include <rtgui/widgets/container.h>
DECLARE_CLASS_TYPE(toplevel);
/** Gets the type of a toplevel */
#define RTGUI_TOPLEVEL_TYPE (rtgui_toplevel_type_get())
#define RTGUI_TOPLEVEL_TYPE (RTGUI_TYPE(toplevel))
/** Casts the object to an rtgui_toplevel */
#define RTGUI_TOPLEVEL(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_TOPLEVEL_TYPE, rtgui_toplevel_t))
/** Checks if the object is an rtgui_toplevel */
......@@ -40,10 +41,7 @@ struct rtgui_toplevel
};
typedef struct rtgui_toplevel rtgui_toplevel_t;
rtgui_type_t *rtgui_toplevel_type_get(void);
rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* event);
void rtgui_toplevel_update_clip(rtgui_toplevel_t* top);
#endif
......@@ -21,8 +21,9 @@
extern "C" {
#endif
DECLARE_CLASS_TYPE(view);
/** Gets the type of a view */
#define RTGUI_VIEW_TYPE (rtgui_view_type_get())
#define RTGUI_VIEW_TYPE (RTGUI_TYPE(view))
/** Casts the object to an rtgui_view */
#define RTGUI_VIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_VIEW_TYPE, rtgui_view_t))
/** Checks if the object is an rtgui_view */
......@@ -42,8 +43,6 @@ struct rtgui_view
};
typedef struct rtgui_view rtgui_view_t;
rtgui_type_t *rtgui_view_type_get(void);
rtgui_view_t* rtgui_view_create(const char* title);
void rtgui_view_destroy(rtgui_view_t* view);
......
......@@ -59,8 +59,10 @@ extern "C" {
#define RTGUI_WIDGET_FONT(w) ((w)->gc.font)
#define RTGUI_WIDGET_FLAG(w) ((w)->flag)
DECLARE_CLASS_TYPE(widget);
/** Gets the type of a widget */
#define RTGUI_WIDGET_TYPE (rtgui_widget_type_get())
#define RTGUI_WIDGET_TYPE (RTGUI_TYPE(widget))
/** Casts the object to a rtgui_widget */
#define RTGUI_WIDGET(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WIDGET_TYPE, rtgui_widget_t))
/** Check if the object is a rtgui_widget */
......
......@@ -21,8 +21,9 @@
#include <rtgui/widgets/toplevel.h>
#include <rtgui/widgets/box.h>
DECLARE_CLASS_TYPE(win);
/** Gets the type of a win */
#define RTGUI_WIN_TYPE (rtgui_win_type_get())
#define RTGUI_WIN_TYPE (RTGUI_TYPE(win))
/** Casts the object to an rtgui_win */
#define RTGUI_WIN(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WIN_TYPE, rtgui_win_t))
/** Checks if the object is an rtgui_win */
......@@ -72,8 +73,6 @@ struct rtgui_win
rt_uint32_t user_data;
};
rtgui_type_t *rtgui_win_type_get(void);
rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title,
rtgui_rect_t *rect, rt_uint8_t flag);
void rtgui_win_destroy(rtgui_win_t* win);
......
......@@ -35,8 +35,10 @@
#define RTGUI_WORKBENCH_IS_MODAL_MODE(w) ((w)->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
DECLARE_CLASS_TYPE(workbench);
/** Gets the type of a workbench */
#define RTGUI_WORKBENCH_TYPE (rtgui_workbench_type_get())
#define RTGUI_WORKBENCH_TYPE (RTGUI_TYPE(workbench))
/** Casts the object to an rtgui_workbench */
#define RTGUI_WORKBENCH(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WORKBENCH_TYPE, rtgui_workbench_t))
/** Checks if the object is an rtgui_workbench */
......@@ -64,7 +66,7 @@ rtgui_type_t* rtgui_workbench_type_get(void);
rtgui_workbench_t *rtgui_workbench_create(const char* panel_name, const unsigned char* title);
void rtgui_workbench_destroy(rtgui_workbench_t* workbench);
void rtgui_workbench_close(rtgui_workbench_t* workbench);
void rtgui_workbench_close(rtgui_workbench_t* workbench);
rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* event);
......
......@@ -18,12 +18,7 @@
#include <rtgui/rtgui_system.h>
/* the global parameter */
struct rtgui_list_node _rtgui_panel_list;
void rtgui_panel_init()
{
rtgui_list_init(&_rtgui_panel_list);
}
struct rtgui_list_node _rtgui_panel_list = {RT_NULL};
void rtgui_panel_register(char* name, rtgui_rect_t* extent)
{
......
......@@ -268,154 +268,66 @@ void rtgui_topwin_deactivate_win(struct rtgui_topwin* win)
}
/* raise window to front */
#ifdef RTGUI_USING_SMALL_SIZE
void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender)
{
struct rtgui_topwin* topwin;
struct rtgui_list_node* node;
struct rtgui_event_clip_info eclip;
/* find the topwin node */
topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list);
if (topwin)
{
rt_int32_t count;
struct rtgui_list_node* node;
struct rtgui_event_clip_info eclip;
RTGUI_EVENT_CLIP_INFO_INIT(&eclip);
eclip.wid = RT_NULL;
/* the window is already placed in front */
if (&(topwin->list) == _rtgui_topwin_show_list.next)
{
rtgui_server_focus_topwin = RT_NULL;
rtgui_topwin_activate_win(topwin);
return ;
}
/* remove node from list */
rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list));
/* add to front */
rtgui_list_insert(&_rtgui_topwin_show_list, &(topwin->list));
/* send clip info event */
count = 0;
for (node = _rtgui_topwin_show_list.next; node != RT_NULL; node = node->next)
{
struct rtgui_topwin* wnd = rtgui_list_entry(node, struct rtgui_topwin, list);
eclip.num_rect = count;
eclip.wid = wnd->wid;
count ++;
/* send to destination window */
rtgui_thread_send(wnd->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info));
/* reset clip info in title */
if (wnd->title != RT_NULL)
{
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title));
rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip),
&(RTGUI_WIDGET(wnd->title)->clip),
&(wnd->extent));
}
}
RTGUI_EVENT_CLIP_INFO_INIT(&eclip);
eclip.wid = RT_NULL;
/* the window is already placed in front */
if (&(topwin->list) == _rtgui_topwin_show_list.next)
{
rtgui_server_focus_topwin = RT_NULL;
rtgui_topwin_activate_win(topwin);
return ;
}
}
#else
void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender)
{
struct rtgui_topwin* topwin;
// rt_sem_take(&_rtgui_topwin_lock, RT_WAITING_FOREVER);
/* find the topwin node */
topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list);
if (topwin)
for (node = _rtgui_topwin_show_list.next; node->next != RT_NULL; node = node->next)
{
rt_int32_t count;
struct rtgui_list_node* node;
struct rtgui_event_clip_info* eclip;
struct rtgui_rect* rect;
/* the window is already placed in front */
if (&(topwin->list) == _rtgui_topwin_show_list.next)
{
rtgui_server_focus_topwin = RT_NULL;
rtgui_topwin_activate_win(topwin);
return ;
}
/* update clip info */
count = 0;
node = _rtgui_topwin_show_list.next;
while (node != &(topwin->list))
{
count ++;
node = node->next;
}
eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info)
+ (count + 1)* sizeof(struct rtgui_rect));
/* reset clip info to top window */
RTGUI_EVENT_CLIP_INFO_INIT(eclip);
eclip->num_rect = 0;
eclip->wid = topwin->wid;
/* send to destination window */
rtgui_thread_send(topwin->tid, &(eclip->parent), sizeof(struct rtgui_event_clip_info));
/* reset clip info in title */
if (topwin->title != RT_NULL)
{
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title));
rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip),
&(RTGUI_WIDGET(topwin->title)->clip),
&(topwin->extent));
}
rect = RTGUI_EVENT_GET_RECT(eclip, 0);
*rect = (topwin->title != RT_NULL)? RTGUI_WIDGET(topwin->title)->extent : topwin->extent;
count = 1;
for (node = _rtgui_topwin_show_list.next;
node != &(topwin->list);
node = node->next)
topwin = rtgui_list_entry(node->next, struct rtgui_topwin, list);
if (topwin->wid == wid)
{
struct rtgui_topwin* wnd;
wnd = rtgui_list_entry(node, struct rtgui_topwin, list);
eclip->num_rect = count;
eclip->wid = wnd->wid;
/* send to destination window */
rtgui_thread_send(wnd->tid, &(eclip->parent),
sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect));
/* reset clip info in title */
if (wnd->title != RT_NULL)
/* found target */
struct rtgui_list_node* n;
n = node->next;
/* remove node */
node->next = node->next->next;
/* insert node to the header */
n->next = _rtgui_topwin_show_list.next;
_rtgui_topwin_show_list.next = n;
/* send clip update to each upper window */
for (n = _rtgui_topwin_show_list.next; n != node->next; n = n->next)
{
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title));
rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip),
&(RTGUI_WIDGET(wnd->title)->clip),
&(wnd->extent));
struct rtgui_topwin* wnd = rtgui_list_entry(n, struct rtgui_topwin, list);
eclip.wid = wnd->wid;
/* send to destination window */
rtgui_thread_send(wnd->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info));
/* reset clip info in title */
if (wnd->title != RT_NULL)
{
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title));
rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip),
&(RTGUI_WIDGET(wnd->title)->clip),
&(wnd->extent));
}
}
rect = RTGUI_EVENT_GET_RECT(eclip, count++);
*rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent;
/* active window */
rtgui_topwin_activate_win(topwin);
break;
}
/* release clip info event */
rtgui_free(eclip);
/* remove node from list */
rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list));
/* add to front */
rtgui_list_insert(&_rtgui_topwin_show_list, &(topwin->list));
rtgui_topwin_activate_win(topwin);
}
// rt_sem_release(&_rtgui_topwin_lock);
}
#endif
/* show a window */
void rtgui_topwin_show(struct rtgui_event_win* event)
......
......@@ -32,18 +32,11 @@ static void _rtgui_about_view_constructor(struct rtgui_about_view *view)
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
}
rtgui_type_t *rtgui_about_view_type_get(void)
{
static rtgui_type_t *list_view_type = RT_NULL;
if (!list_view_type)
{
list_view_type = rtgui_type_create("aboutview", RTGUI_VIEW_TYPE,
sizeof(rtgui_about_view_t), RTGUI_CONSTRUCTOR(_rtgui_about_view_constructor), RT_NULL);
}
return list_view_type;
}
DEFINE_CLASS_TYPE(aboutview, "aboutview",
RTGUI_VIEW_TYPE,
_rtgui_about_view_constructor,
RT_NULL,
sizeof(struct rtgui_about_view));
void rtgui_about_view_ondraw(struct rtgui_about_view* view)
{
......
......@@ -28,18 +28,11 @@ static void _rtgui_box_constructor(rtgui_box_t *box)
box->border_size = RTGUI_BORDER_DEFAULT_WIDTH;
}
rtgui_type_t *rtgui_box_type_get(void)
{
static rtgui_type_t *box_type = RT_NULL;
if (!box_type)
{
box_type = rtgui_type_create("box", RTGUI_CONTAINER_TYPE,
sizeof(rtgui_box_t), RTGUI_CONSTRUCTOR(_rtgui_box_constructor), RT_NULL);
}
return box_type;
}
DEFINE_CLASS_TYPE(box, "box",
RTGUI_CONTAINER_TYPE,
_rtgui_box_constructor,
RT_NULL,
sizeof(struct rtgui_box));
rt_bool_t rtgui_box_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
{
......
......@@ -50,20 +50,11 @@ static void _rtgui_button_destructor(rtgui_button_t *button)
}
}
rtgui_type_t *rtgui_button_type_get(void)
{
static rtgui_type_t *button_type = RT_NULL;
if (!button_type)
{
button_type = rtgui_type_create("button", RTGUI_LABEL_TYPE,
sizeof(rtgui_button_t),
RTGUI_CONSTRUCTOR(_rtgui_button_constructor),
RTGUI_DESTRUCTOR(_rtgui_button_destructor));
}
return button_type;
}
DEFINE_CLASS_TYPE(button, "button",
RTGUI_LABEL_TYPE,
_rtgui_button_constructor,
_rtgui_button_destructor,
sizeof(struct rtgui_button));
rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
......
......@@ -16,18 +16,11 @@ static void _rtgui_checkbox_constructor(rtgui_checkbox_t *box)
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
}
rtgui_type_t *rtgui_checkbox_type_get(void)
{
static rtgui_type_t *checkbox_type = RT_NULL;
if (!checkbox_type)
{
checkbox_type = rtgui_type_create("checkbox", RTGUI_LABEL_TYPE,
sizeof(rtgui_checkbox_t), RTGUI_CONSTRUCTOR(_rtgui_checkbox_constructor), RT_NULL);
}
return checkbox_type;
}
DEFINE_CLASS_TYPE(checkbox, "checkbox",
RTGUI_LABEL_TYPE,
_rtgui_checkbox_constructor,
RT_NULL,
sizeof(struct rtgui_checkbox));
void rtgui_checkbox_set_onbutton(rtgui_checkbox_t* checkbox, rtgui_onbutton_func_t func)
{
......
......@@ -56,20 +56,11 @@ rt_bool_t rtgui_combobox_pdwin_ondeactive(struct rtgui_widget* widget, struct rt
return RT_TRUE;
}
rtgui_type_t *rtgui_combobox_type_get(void)
{
static rtgui_type_t *combobox_type = RT_NULL;
if (!combobox_type)
{
combobox_type = rtgui_type_create("combobox", RTGUI_WIDGET_TYPE,
sizeof(rtgui_combobox_t),
RTGUI_CONSTRUCTOR(_rtgui_combobox_constructor),
RTGUI_DESTRUCTOR(_rtgui_combobox_destructor));
}
return combobox_type;
}
DEFINE_CLASS_TYPE(combobox, "combobox",
RTGUI_WIDGET_TYPE,
_rtgui_combobox_constructor,
_rtgui_combobox_destructor,
sizeof(struct rtgui_combobox));
rtgui_combobox_t *rtgui_combobox_create(struct rtgui_listbox_item* items, rt_uint16_t count, struct rtgui_rect* rect)
{
......
......@@ -49,20 +49,11 @@ static void _rtgui_container_update_toplevel(rtgui_container_t* container)
}
}
rtgui_type_t *rtgui_container_type_get(void)
{
static rtgui_type_t *container_type = RT_NULL;
if (!container_type)
{
container_type = rtgui_type_create("container", RTGUI_WIDGET_TYPE,
sizeof(rtgui_container_t),
RTGUI_CONSTRUCTOR(_rtgui_container_constructor),
RTGUI_DESTRUCTOR(_rtgui_container_destructor));
}
return container_type;
}
DEFINE_CLASS_TYPE(container, "container",
RTGUI_WIDGET_TYPE,
_rtgui_container_constructor,
_rtgui_container_destructor,
sizeof(struct rtgui_container));
rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t* event)
{
......
......@@ -356,20 +356,11 @@ static void _rtgui_filelist_view_destructor(struct rtgui_filelist_view *view)
rtgui_image_destroy(folder_image);
}
rtgui_type_t *rtgui_filelist_view_type_get(void)
{
static rtgui_type_t *filelist_view_type = RT_NULL;
if (!filelist_view_type)
{
filelist_view_type = rtgui_type_create("flview", RTGUI_VIEW_TYPE,
sizeof(rtgui_filelist_view_t),
RTGUI_CONSTRUCTOR(_rtgui_filelist_view_constructor),
RTGUI_DESTRUCTOR(_rtgui_filelist_view_destructor));
}
return filelist_view_type;
}
DEFINE_CLASS_TYPE(filelist, "filelist",
RTGUI_VIEW_TYPE,
_rtgui_filelist_view_constructor,
_rtgui_filelist_view_destructor,
sizeof(struct rtgui_filelist_view));
void rtgui_filelist_view_ondraw(struct rtgui_filelist_view* view)
{
......
......@@ -40,19 +40,11 @@ static void _rtgui_iconbox_destructor(rtgui_iconbox_t *iconbox)
iconbox->text = RT_NULL;
}
rtgui_type_t *rtgui_iconbox_type_get(void)
{
static rtgui_type_t *iconbox_type = RT_NULL;
if (!iconbox_type)
{
iconbox_type = rtgui_type_create("iconbox", RTGUI_WIDGET_TYPE,
sizeof(rtgui_iconbox_t), RTGUI_CONSTRUCTOR(_rtgui_iconbox_constructor),
RTGUI_DESTRUCTOR(_rtgui_iconbox_destructor));
}
return iconbox_type;
}
DEFINE_CLASS_TYPE(iconbox, "iconbox",
RTGUI_WIDGET_TYPE,
_rtgui_iconbox_constructor,
_rtgui_iconbox_destructor,
sizeof(struct rtgui_iconbox));
rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
......
......@@ -32,20 +32,11 @@ static void _rtgui_label_destructor(rtgui_label_t *label)
label->text = RT_NULL;
}
rtgui_type_t *rtgui_label_type_get(void)
{
static rtgui_type_t *label_type = RT_NULL;
if (!label_type)
{
label_type = rtgui_type_create("label", RTGUI_WIDGET_TYPE,
sizeof(rtgui_label_t),
RTGUI_CONSTRUCTOR(_rtgui_label_constructor),
RTGUI_DESTRUCTOR(_rtgui_label_destructor));
}
return label_type;
}
DEFINE_CLASS_TYPE(label, "label",
RTGUI_WIDGET_TYPE,
_rtgui_label_constructor,
_rtgui_label_destructor,
sizeof(struct rtgui_label));
rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
......
......@@ -37,18 +37,11 @@ static void _rtgui_list_view_constructor(struct rtgui_list_view *view)
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
}
rtgui_type_t *rtgui_list_view_type_get(void)
{
static rtgui_type_t *list_view_type = RT_NULL;
if (!list_view_type)
{
list_view_type = rtgui_type_create("listview", RTGUI_VIEW_TYPE,
sizeof(rtgui_list_view_t), RTGUI_CONSTRUCTOR(_rtgui_list_view_constructor), RT_NULL);
}
return list_view_type;
}
DEFINE_CLASS_TYPE(listview, "listview",
RTGUI_VIEW_TYPE,
_rtgui_list_view_constructor,
RT_NULL,
sizeof(struct rtgui_list_view));
static void rtgui_list_view_onicondraw(struct rtgui_list_view* view, struct rtgui_dc *dc)
{
......
......@@ -33,18 +33,11 @@ static void _rtgui_listbox_constructor(struct rtgui_listbox *box)
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_CENTER_VERTICAL;
}
rtgui_type_t *rtgui_listbox_type_get(void)
{
static rtgui_type_t *listbox_type = RT_NULL;
if (!listbox_type)
{
listbox_type = rtgui_type_create("listbox", RTGUI_WIDGET_TYPE,
sizeof(rtgui_listbox_t), RTGUI_CONSTRUCTOR(_rtgui_listbox_constructor), RT_NULL);
}
return listbox_type;
}
DEFINE_CLASS_TYPE(listbox, "listbox",
RTGUI_WIDGET_TYPE,
_rtgui_listbox_constructor,
RT_NULL,
sizeof(struct rtgui_listbox));
void rtgui_listbox_ondraw(struct rtgui_listbox* box)
{
......
......@@ -34,18 +34,11 @@ static void _rtgui_listctrl_constructor(struct rtgui_listctrl *ctrl)
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(ctrl)) = RTGUI_ALIGN_CENTER_VERTICAL;
}
rtgui_type_t *rtgui_listctrl_type_get(void)
{
static rtgui_type_t *listctrl_type = RT_NULL;
if (!listctrl_type)
{
listctrl_type = rtgui_type_create("listctrl", RTGUI_WIDGET_TYPE,
sizeof(rtgui_listctrl_t), RTGUI_CONSTRUCTOR(_rtgui_listctrl_constructor), RT_NULL);
}
return listctrl_type;
}
DEFINE_CLASS_TYPE(listctrl, "listctrl",
RTGUI_WIDGET_TYPE,
_rtgui_listctrl_constructor,
RT_NULL,
sizeof(struct rtgui_listctrl));
static void _rtgui_listctrl_get_rect(struct rtgui_listctrl* ctrl, rtgui_rect_t* rect)
{
......
......@@ -141,20 +141,11 @@ static void _rtgui_menu_item_onmouse()
{
}
rtgui_type_t *rtgui_menu_type_get(void)
{
static rtgui_type_t *menu_type = RT_NULL;
if (!menu_type)
{
menu_type = rtgui_type_create("menu", RTGUI_WIN_TYPE,
sizeof(rtgui_menu_t),
RTGUI_CONSTRUCTOR(_rtgui_menu_constructor),
RTGUI_DESTRUCTOR (_rtgui_menu_destructor));
}
return menu_type;
}
DEFINE_CLASS_TYPE(menu, "menu",
RTGUI_WIDGET_TYPE,
_rtgui_menu_constructor,
_rtgui_menu_destructor,
sizeof(struct rtgui_menu));
static rt_bool_t rtgui_menu_on_deactivate(rtgui_widget_t* widget, rtgui_event_t* event)
{
......
......@@ -147,20 +147,11 @@ static void _rtgui_notebook_get_bar_rect(rtgui_notebook_t *notebook, struct rtgu
rect->y1 = rect->y2 - 25;
}
rtgui_type_t *rtgui_notebook_type_get(void)
{
static rtgui_type_t *noteboot_type = RT_NULL;
if (!noteboot_type)
{
noteboot_type = rtgui_type_create("notebook", RTGUI_CONTAINER_TYPE,
sizeof(rtgui_notebook_t),
RTGUI_CONSTRUCTOR(_rtgui_notebook_constructor),
RTGUI_DESTRUCTOR(_rtgui_notebook_destructor));
}
return noteboot_type;
}
DEFINE_CLASS_TYPE(notebook, "notebook",
RTGUI_CONTAINER_TYPE,
_rtgui_notebook_constructor,
_rtgui_notebook_destructor,
sizeof(struct rtgui_notebook));
rtgui_notebook_tab_t *tabs;
struct rtgui_notebook *_notebook;
......
......@@ -19,18 +19,11 @@ static void _rtgui_progressbar_constructor(rtgui_progressbar_t *bar)
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(bar)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
}
rtgui_type_t *rtgui_progressbar_type_get(void)
{
static rtgui_type_t *progressbar_type = RT_NULL;
if (!progressbar_type)
{
progressbar_type = rtgui_type_create("progressbar", RTGUI_WIDGET_TYPE,
sizeof(rtgui_progressbar_t), RTGUI_CONSTRUCTOR(_rtgui_progressbar_constructor), RT_NULL);
}
return progressbar_type;
}
DEFINE_CLASS_TYPE(progressbar, "progressbar",
RTGUI_WIDGET_TYPE,
_rtgui_progressbar_constructor,
RT_NULL,
sizeof(struct rtgui_progressbar));
rt_bool_t rtgui_progressbar_event_handler(struct rtgui_widget* widget,
struct rtgui_event* event)
......
......@@ -11,7 +11,7 @@ static void _rtgui_radiobox_constructor(rtgui_radiobox_t *radiobox)
/* init widget and set event handler */
RTGUI_WIDGET(radiobox)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(radiobox)) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(radiobox)) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
rtgui_widget_set_event_handler(RTGUI_WIDGET(radiobox), rtgui_radiobox_event_handler);
......@@ -22,18 +22,11 @@ static void _rtgui_radiobox_constructor(rtgui_radiobox_t *radiobox)
radiobox->orient = RTGUI_HORIZONTAL;
}
rtgui_type_t *rtgui_radiobox_type_get(void)
{
static rtgui_type_t *radiobox_type = RT_NULL;
if (!radiobox_type)
{
radiobox_type = rtgui_type_create("radiobox", RTGUI_WIDGET_TYPE,
sizeof(rtgui_radiobox_t), RTGUI_CONSTRUCTOR(_rtgui_radiobox_constructor), RT_NULL);
}
return radiobox_type;
}
DEFINE_CLASS_TYPE(radiobox, "radiobox",
RTGUI_WIDGET_TYPE,
_rtgui_radiobox_constructor,
RT_NULL,
sizeof(struct rtgui_radiobox));
static void rtgui_radiobox_onmouse(struct rtgui_radiobox* radiobox, struct rtgui_event_mouse* event)
{
......
......@@ -89,18 +89,11 @@ void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *rect)
}
}
rtgui_type_t *rtgui_scrollbar_type_get(void)
{
static rtgui_type_t *scrollbar_type = RT_NULL;
if (!scrollbar_type)
{
scrollbar_type = rtgui_type_create("scrollbar", RTGUI_WIDGET_TYPE,
sizeof(rtgui_scrollbar_t), RTGUI_CONSTRUCTOR(_rtgui_scrollbar_constructor), RT_NULL);
}
return scrollbar_type;
}
DEFINE_CLASS_TYPE(scrollbar, "scrollbar",
RTGUI_WIDGET_TYPE,
_rtgui_scrollbar_constructor,
RT_NULL,
sizeof(struct rtgui_scrollbar));
static void _rtgui_scrollbar_on_mouseclick(struct rtgui_widget * widget, struct rtgui_event * event)
{
......
......@@ -41,18 +41,11 @@ static void _rtgui_slider_constructor(rtgui_slider_t *slider)
slider->on_changed = RT_NULL;
}
rtgui_type_t *rtgui_slider_type_get(void)
{
static rtgui_type_t *slider_type = RT_NULL;
if (!slider_type)
{
slider_type = rtgui_type_create("slider", RTGUI_WIDGET_TYPE,
sizeof(rtgui_slider_t), RTGUI_CONSTRUCTOR(_rtgui_slider_constructor), RT_NULL);
}
return slider_type;
}
DEFINE_CLASS_TYPE(slider, "slider",
RTGUI_WIDGET_TYPE,
_rtgui_slider_constructor,
RT_NULL,
sizeof(struct rtgui_slider));
static void rtgui_slider_onmouse(struct rtgui_slider* slider, struct rtgui_event_mouse* event)
{
......
......@@ -13,18 +13,12 @@ static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
rtgui_widget_set_event_handler(RTGUI_WIDGET(staticline), rtgui_staticline_event_handler);
}
rtgui_type_t *rtgui_staticline_type_get(void)
{
static rtgui_type_t *staticline_type = RT_NULL;
if (!staticline_type)
{
staticline_type = rtgui_type_create("staticline", RTGUI_WIDGET_TYPE,
sizeof(rtgui_staticline_t), RTGUI_CONSTRUCTOR(_rtgui_staticline_constructor), RT_NULL);
}
return staticline_type;
}
DEFINE_CLASS_TYPE(staticline, "staticline",
RTGUI_WIDGET_TYPE,
_rtgui_staticline_constructor,
RT_NULL,
sizeof(struct rtgui_staticline));
rt_bool_t rtgui_staticline_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
......
......@@ -84,20 +84,11 @@ static void _rtgui_textbox_deconstructor(rtgui_textbox_t *box)
box->caret_timer = RT_NULL;
}
rtgui_type_t *rtgui_textbox_type_get(void)
{
static rtgui_type_t *textbox_type = RT_NULL;
if (!textbox_type)
{
textbox_type = rtgui_type_create("textbox", RTGUI_WIDGET_TYPE,
sizeof(rtgui_textbox_t),
RTGUI_CONSTRUCTOR(_rtgui_textbox_constructor),
RTGUI_DESTRUCTOR(_rtgui_textbox_deconstructor));
}
return textbox_type;
}
DEFINE_CLASS_TYPE(textbox, "textbox",
RTGUI_WIDGET_TYPE,
_rtgui_textbox_constructor,
_rtgui_textbox_deconstructor,
sizeof(struct rtgui_textbox));
static void rtgui_textbox_onmouse(struct rtgui_textbox* box, struct rtgui_event_mouse* event)
{
......
......@@ -28,20 +28,11 @@ static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t* wintitle)
wintitle->title = RT_NULL;
}
rtgui_type_t* rtgui_wintitle_type_get()
{
static rtgui_type_t *wintitle_type = RT_NULL;
if (!wintitle_type)
{
wintitle_type = rtgui_type_create("wintitle", RTGUI_TOPLEVEL_TYPE,
sizeof(rtgui_wintitle_t),
RTGUI_CONSTRUCTOR(_rtgui_wintitle_constructor),
RTGUI_DESTRUCTOR(_rtgui_wintitle_deconstructor));
}
return wintitle_type;
}
DEFINE_CLASS_TYPE(wintitle, "wintitle",
RTGUI_TOPLEVEL_TYPE,
_rtgui_wintitle_constructor,
_rtgui_wintitle_deconstructor,
sizeof(struct rtgui_wintitle));
rtgui_wintitle_t* rtgui_wintitle_create(const char* title)
{
......
......@@ -38,20 +38,11 @@ static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel)
toplevel->drawing = 0;
}
rtgui_type_t *rtgui_toplevel_type_get(void)
{
static rtgui_type_t *toplevel_type = RT_NULL;
if (!toplevel_type)
{
toplevel_type = rtgui_type_create("toplevel", RTGUI_CONTAINER_TYPE,
sizeof(rtgui_toplevel_t),
RTGUI_CONSTRUCTOR(_rtgui_toplevel_constructor),
RTGUI_DESTRUCTOR(_rtgui_toplevel_destructor));
}
return toplevel_type;
}
DEFINE_CLASS_TYPE(toplevel, "toplevel",
RTGUI_CONTAINER_TYPE,
_rtgui_toplevel_constructor,
_rtgui_toplevel_destructor,
sizeof(struct rtgui_toplevel));
rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
{
......
......@@ -48,20 +48,11 @@ static void _rtgui_view_destructor(rtgui_view_t *view)
}
}
rtgui_type_t *rtgui_view_type_get(void)
{
static rtgui_type_t *view_type = RT_NULL;
if (!view_type)
{
view_type = rtgui_type_create("view", RTGUI_CONTAINER_TYPE,
sizeof(rtgui_view_t),
RTGUI_CONSTRUCTOR(_rtgui_view_constructor),
RTGUI_DESTRUCTOR(_rtgui_view_destructor));
}
return view_type;
}
DEFINE_CLASS_TYPE(view, "view",
RTGUI_CONTAINER_TYPE,
_rtgui_view_constructor,
_rtgui_view_destructor,
sizeof(struct rtgui_view));
rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
......
......@@ -84,19 +84,11 @@ static void _rtgui_widget_destructor(rtgui_widget_t *widget)
rtgui_region_fini(&(widget->clip));
}
rtgui_type_t *rtgui_widget_type_get(void)
{
static rtgui_type_t *widget_type = RT_NULL;
if (!widget_type)
{
widget_type = rtgui_type_create("rtgui_widget", RTGUI_OBJECT_TYPE,
sizeof(rtgui_widget_t), RTGUI_CONSTRUCTOR(_rtgui_widget_constructor),
RTGUI_DESTRUCTOR(_rtgui_widget_destructor));
}
return widget_type;
}
DEFINE_CLASS_TYPE(widget, "widget",
RTGUI_OBJECT_TYPE,
_rtgui_widget_constructor,
_rtgui_widget_destructor,
sizeof(struct rtgui_widget));
rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type)
{
......
......@@ -100,20 +100,11 @@ static rt_bool_t _rtgui_win_create_in_server(rtgui_win_t* win)
return RT_TRUE;
}
rtgui_type_t *rtgui_win_type_get(void)
{
static rtgui_type_t *win_type = RT_NULL;
if (!win_type)
{
win_type = rtgui_type_create("win", RTGUI_TOPLEVEL_TYPE,
sizeof(rtgui_win_t),
RTGUI_CONSTRUCTOR(_rtgui_win_constructor),
RTGUI_DESTRUCTOR(_rtgui_win_destructor));
}
return win_type;
}
DEFINE_CLASS_TYPE(win, "win",
RTGUI_TOPLEVEL_TYPE,
_rtgui_win_constructor,
_rtgui_win_destructor,
sizeof(struct rtgui_win));
rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title, rtgui_rect_t *rect, rt_uint8_t style)
{
......
......@@ -55,20 +55,11 @@ static void _rtgui_workbench_destructor(rtgui_workbench_t *workbench)
workbench->title = RT_NULL;
}
rtgui_type_t *rtgui_workbench_type_get(void)
{
static rtgui_type_t *workbench_type = RT_NULL;
if (!workbench_type)
{
workbench_type = rtgui_type_create("workbench", RTGUI_TOPLEVEL_TYPE,
sizeof(rtgui_workbench_t),
RTGUI_CONSTRUCTOR(_rtgui_workbench_constructor),
RTGUI_DESTRUCTOR(_rtgui_workbench_destructor));
}
return workbench_type;
}
DEFINE_CLASS_TYPE(workbench, "workbench",
RTGUI_TOPLEVEL_TYPE,
_rtgui_workbench_constructor,
_rtgui_workbench_destructor,
sizeof(struct rtgui_workbench));
rtgui_workbench_t *rtgui_workbench_create(const char* panel_name, const unsigned char* title)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册