summaryrefslogtreecommitdiff
path: root/components/rtgui/widgets
diff options
context:
space:
mode:
authorGrissiom <[email protected]>2013-02-01 10:27:10 +0800
committerGrissiom <[email protected]>2013-02-01 10:27:10 +0800
commitf06c70feed0941b5bceedcecf89e9aa22034aca8 (patch)
tree89fd3a989b4d88fc72b39eaad6567de3a3d23874 /components/rtgui/widgets
parent4f02e67bef7eacee5102d7730356663d9c889e15 (diff)
sync with rtgui-0.6
Diffstat (limited to 'components/rtgui/widgets')
-rw-r--r--components/rtgui/widgets/box.c12
-rw-r--r--components/rtgui/widgets/button.c14
-rw-r--r--components/rtgui/widgets/combobox.c8
-rw-r--r--components/rtgui/widgets/digfont.c309
-rw-r--r--components/rtgui/widgets/digtube.c174
-rw-r--r--components/rtgui/widgets/filelist_view.c2
-rw-r--r--components/rtgui/widgets/menu.c14
-rw-r--r--components/rtgui/widgets/notebook.c3
-rw-r--r--components/rtgui/widgets/radiobox.c8
-rw-r--r--components/rtgui/widgets/slider.c8
-rw-r--r--components/rtgui/widgets/staticline.c8
-rw-r--r--components/rtgui/widgets/textbox.c46
-rw-r--r--components/rtgui/widgets/widget.c26
-rw-r--r--components/rtgui/widgets/window.c50
14 files changed, 597 insertions, 85 deletions
diff --git a/components/rtgui/widgets/box.c b/components/rtgui/widgets/box.c
index 47c704b7c9..448f47ea36 100644
--- a/components/rtgui/widgets/box.c
+++ b/components/rtgui/widgets/box.c
@@ -73,7 +73,7 @@ static void rtgui_box_layout_vertical(struct rtgui_box *box, struct rtgui_rect *
{
rtgui_widget_t *widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++;
- else total_height += widget->mini_height;
+ else total_height += widget->min_height;
}
/* calculate the height for each spaces */
@@ -98,8 +98,8 @@ static void rtgui_box_layout_vertical(struct rtgui_box *box, struct rtgui_rect *
/* reset rect */
rtgui_rect_moveto(rect, -rect->x1, -rect->y1);
- rect->x2 = widget->mini_width;
- rect->y2 = widget->mini_height;
+ rect->x2 = widget->min_width;
+ rect->y2 = widget->min_height;
/* left in default */
rtgui_rect_moveto(rect, next_x, next_y);
@@ -166,7 +166,7 @@ static void rtgui_box_layout_horizontal(struct rtgui_box *box, struct rtgui_rect
{
rtgui_widget_t *widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++;
- else total_width += widget->mini_width;
+ else total_width += widget->min_width;
}
if (space_count != 0)
@@ -191,8 +191,8 @@ static void rtgui_box_layout_horizontal(struct rtgui_box *box, struct rtgui_rect
/* reset rect */
rtgui_rect_moveto(rect, -rect->x1, -rect->y1);
- rect->x2 = widget->mini_width;
- rect->y2 = widget->mini_height;
+ rect->x2 = widget->min_width;
+ rect->y2 = widget->min_height;
/* top in default */
rtgui_rect_moveto(rect, next_x, next_y);
diff --git a/components/rtgui/widgets/button.c b/components/rtgui/widgets/button.c
index ca15acb89a..ceca58f008 100644
--- a/components/rtgui/widgets/button.c
+++ b/components/rtgui/widgets/button.c
@@ -104,7 +104,8 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_e
break;
case RTGUI_EVENT_MOUSE_BUTTON:
- if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
+ if (RTGUI_WIDGET_IS_HIDE(widget))
+ return RT_FALSE;
{
struct rtgui_event_mouse *emouse = (struct rtgui_event_mouse *)event;
@@ -159,9 +160,6 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_e
/* need callback */
rt_bool_t need_cb = RT_FALSE;
- win = RTGUI_WIN(RTGUI_WIDGET(btn)->toplevel);
- win->last_mevent_widget = RTGUI_WIDGET(btn);
-
/* we need to decide whether the callback will be invoked
* before the flag has changed. Moreover, we cannot invoke
* it directly here, because the button might be destroyed
@@ -174,14 +172,20 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_e
need_cb = RT_TRUE;
}
- /* it's a normal button */
+ /* if the button will handle the mouse up event here, it
+ * should not be the last_mevent_widget. Take care that
+ * don't overwrite other widgets. */
+ win = RTGUI_WIN(RTGUI_WIDGET(btn)->toplevel);
if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
{
btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
+ win->last_mevent_widget = RTGUI_WIDGET(btn);
}
else
{
btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
+ if (win->last_mevent_widget == RTGUI_WIDGET(btn))
+ win->last_mevent_widget = RT_NULL;
}
/* draw button */
diff --git a/components/rtgui/widgets/combobox.c b/components/rtgui/widgets/combobox.c
index 50cac173b1..ece6cb2e1b 100644
--- a/components/rtgui/widgets/combobox.c
+++ b/components/rtgui/widgets/combobox.c
@@ -48,7 +48,7 @@ rt_bool_t rtgui_combobox_pdwin_onitem(struct rtgui_object *object, struct rtgui_
if (combo->on_selected != RT_NULL)
combo->on_selected(RTGUI_OBJECT(combo), RT_NULL);
- rtgui_win_hiden(pd_win);
+ rtgui_win_hide(pd_win);
rtgui_widget_update(RTGUI_WIDGET(combo));
return RT_FALSE;
@@ -56,7 +56,7 @@ rt_bool_t rtgui_combobox_pdwin_onitem(struct rtgui_object *object, struct rtgui_
rt_bool_t rtgui_combobox_pdwin_ondeactive(struct rtgui_object *object, struct rtgui_event *event)
{
- rtgui_win_hiden(RTGUI_WIN(object));
+ rtgui_win_hide(RTGUI_WIN(object));
return RT_TRUE;
}
@@ -226,7 +226,7 @@ rt_bool_t rtgui_combobox_event_handler(struct rtgui_object *object, struct rtgui
if (focused->widget != RT_NULL)
{
/* hide pull down window */
- rtgui_win_hiden(RTGUI_WIN(box->pd_win));
+ rtgui_win_hide(RTGUI_WIN(box->pd_win));
rtgui_combobox_ondraw(box);
}
}
@@ -255,7 +255,7 @@ static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_object *object, struc
if (box == RT_NULL) return RT_TRUE;
/* hide pull down window */
- rtgui_win_hiden(RTGUI_WIN(box->pd_win));
+ rtgui_win_hide(RTGUI_WIN(box->pd_win));
/* clear pull down button state */
box->pd_pressed = RT_FALSE;
diff --git a/components/rtgui/widgets/digfont.c b/components/rtgui/widgets/digfont.c
new file mode 100644
index 0000000000..0d081f94ad
--- /dev/null
+++ b/components/rtgui/widgets/digfont.c
@@ -0,0 +1,309 @@
+/*
+ * File : digfont.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2012, 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
+ * 2012-12-21 pife first version
+ */
+
+#include <rtthread.h>
+#include <rtgui/rtgui.h>
+#include <rtgui/dc.h>
+#include <rtgui/widgets/digfont.h>
+
+#define DIGFONT_V 1
+#define DIGFONT_H 0
+
+int rtgui_digitfont_create(struct rtgui_digitfont * font)
+{
+ int i;
+ int half;
+ int space;
+ int seg35_y;
+ int hight;
+ struct rtgui_digitfont_data * data, *databuf;
+ struct rtgui_digitfont_data temp, temp2;;
+
+ data= rt_malloc(sizeof(struct rtgui_digitfont_data) * 7 * font->seg1_nr);
+ if (data== RT_NULL)
+ {
+ rt_kprintf("out of memory.\n");
+ goto __err;
+ }
+ databuf = font->data = data;
+
+ data = &temp;
+ half = font->seg1_nr >> 1;
+ space = font->seg1_hspace;
+ seg35_y = font->seg1_vspace + font->seg2_len + (half<<1) - font->seg1_vspace;
+ hight = (font->seg1_vspace << 1) + font->seg2_len + font->seg3_len + (half << 1) - 1;
+
+ //seg 1
+ data->type = DIGFONT_H;
+ data->x = font->seg1_hspace;
+ data->y = 0;
+ data->len = font->seg1_len;
+
+ *databuf++ = *data;
+ for(i=1; i<font->seg1_nr; i++)
+ {
+ data->len -= 2;
+ data->x ++;
+ data->y ++;
+ *databuf++ = *data;
+ }
+
+ //seg 2
+ data->type = DIGFONT_V;
+ data->x = (font->seg1_hspace << 1) + font->seg1_len -1;
+ data->y = font->seg1_vspace ;
+ data->len = font->seg2_len;
+ *databuf++ = *data;
+ for(i=1; i<font->seg1_nr; i++)
+ {
+ if (i >= half)
+ {
+ data->len -= 2;
+ }
+ data->x --;
+ data->y ++;
+ *databuf++ = *data;
+ }
+
+ //seg 3
+ data->type = DIGFONT_V;
+ data->x = (font->seg1_hspace << 1) + font->seg1_len -1;
+ data->y = seg35_y;
+ data->len = font->seg3_len;
+ *databuf++ = *data;
+ temp2 = *data;
+ for(i=1; i<font->seg1_nr; i++)
+ {
+ if (i < half)
+ data->y --;
+ else
+ {
+ data->len -= 2;
+ data->y ++;
+ }
+
+ data->x --;
+ *databuf++ = *data;
+ }
+
+ // seg4
+ data->type = DIGFONT_H;
+ data->x = font->seg1_hspace;
+ data->y = hight -1;
+ data->len = font->seg1_len;
+ *databuf++ = *data;
+ for(i=1; i<font->seg1_nr; i++)
+ {
+ data->len -= 2;
+ data->x ++;
+ data->y --;
+ *databuf++ = *data;
+ }
+
+ //seg5
+ data->type = DIGFONT_V;
+ data->x = 0;
+ data->y = seg35_y;
+ data->len = font->seg3_len;
+ *databuf++ = *data;
+
+ for(i=1; i<font->seg1_nr; i++)
+ {
+ if (i < half)
+ data->y --;
+ else
+ {
+ data->len -= 2;
+ data->y ++;
+ }
+
+ data->x ++;
+ *databuf++ = *data;
+ }
+
+ //seg 6
+ data->type = DIGFONT_V;
+ data->x = 0;
+ data->y = font->seg1_vspace ;
+ data->len = font->seg2_len;
+ *databuf++ = *data;
+ for(i=1; i<font->seg1_nr; i++)
+ {
+ if (i >= half)
+ {
+ data->len -= 2;
+ }
+ data->x ++;
+ data->y ++;
+ *databuf++ = *data;
+ }
+
+ //seg7
+ data->type = DIGFONT_H;
+ data->x = font->seg1_hspace + half - 1;
+ data->y = font->seg1_vspace + font->seg2_len + half -1;
+ data->len = (font->seg1_hspace << 1) + font->seg1_len - \
+ ((font->seg1_hspace + half -1) << 1);
+ *databuf++ = *data;
+ temp2 = *data;
+ for(i=0; i<half; i++)
+ {
+ data->x ++;
+ data->y --;
+ data->len -= 2;
+ *databuf++ = *data;
+ }
+
+ *data = temp2;
+ for (i=0; i<half; i++)
+ {
+ data->x ++;
+ data->y ++;
+ data->len -= 2;
+ *databuf++ = *data;
+ }
+
+ return 0;
+
+__err:
+ return -1;
+}
+
+int rtgui_dc_draw_digitfont(struct rtgui_dc *dc, struct rtgui_digitfont * font, rtgui_rect_t * rect)
+{
+ int i, size;
+ struct rtgui_digitfont_data * data;
+
+ size = font->seg1_nr * 7;
+ data = font->data;
+
+ for(i=0; i<size; i++)
+ {
+ if (data->type == DIGFONT_H)
+ rtgui_dc_draw_hline(dc, rect->x1 + data->x, \
+ rect->x1 + data->x + data->len, rect->y1 + data->y);
+ else
+ rtgui_dc_draw_vline(dc, rect->x1 + data->x, rect->y1 + data->y, \
+ rect->y1 + data->y + data->len);
+
+ data++;
+ }
+}
+
+const char digtube_code_table[] =
+{ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,};
+
+int rtgui_dc_draw_digitfont_code(struct rtgui_dc *dc, struct rtgui_digitfont * font, rtgui_rect_t * rect, char code)
+{
+ int i,j;
+ struct rtgui_digitfont_data * data;
+ rtgui_color_t color;
+
+ data = font->data;
+
+ color = RTGUI_DC_FC(dc);
+ for(i=0; i<7; i++)
+ {
+ if (code & (1 << i))
+ RTGUI_DC_FC(dc) = color;
+ else
+ RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
+
+ for (j=0; j<font->seg1_nr; j++)
+ {
+ if (data->type == DIGFONT_H)
+ rtgui_dc_draw_hline(dc, rect->x1 + data->x, \
+ rect->x1 + data->x + data->len, rect->y1 + data->y);
+ else
+ rtgui_dc_draw_vline(dc, rect->x1 + data->x, rect->y1 + data->y, \
+ rect->y1 + data->y + data->len);
+
+ data++;
+ }
+ }
+ RTGUI_DC_FC(dc) = color;
+
+ return 0;
+}
+
+int rtgui_get_digfont_metrics(struct rtgui_digitfont * font, rtgui_rect_t * rect)
+{
+ int half = font->seg1_nr >> 1;
+ rect->x1 = 0;
+ rect->y1 = 0;
+ rect->x2 = (font->seg1_hspace << 1) + font->seg1_len;
+ rect->y2 = (font->seg1_vspace << 1) + font->seg2_len + font->seg3_len + (half << 1) - 1;
+ return 0;
+}
+
+/* debug */
+struct rtgui_digitfont digitfont_40 =
+{
+ 34, //int seg1_len;
+ 3, //int seg1_hspace;
+ 1, //int seg1_vpace;
+ 9, //int seg1_nr; //9
+ 30, //int seg2_len;
+ 30, //int seg3_len;
+ RT_NULL,
+};
+
+#ifdef _WIN32
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+static char fontbuf[80];
+int digfont_file(char * name, struct rtgui_digitfont * font)
+{
+ int i;
+ int size;
+ FILE * file;
+ struct rtgui_digitfont_data * data;
+
+ if (font->data == RT_NULL)
+ rtgui_digitfont_create(font);
+
+ /* create a file to store data */
+ file = fopen(name, "wb + ");
+ if (file == RT_NULL)
+ {
+ rt_kprintf("open < % s > failed.\n", name);
+ return -1;
+ }
+ data = font->data;
+ size = font->seg1_nr * 7;
+
+ for( i=0; i<size; i++)
+ {
+ if ((i % (font->seg1_nr)) == 0)
+ {
+ sprintf(fontbuf, "\n/* seg <%d> */\n", i/font->seg1_nr + 1);
+ fwrite(fontbuf, strlen(fontbuf), 1, file);
+ }
+
+ sprintf(fontbuf, " { % 2d, % 2d, % 2d, % 2d}, \n", data->x, data->y, data->len, data->type);
+ fwrite(fontbuf, strlen(fontbuf), 1, file);
+ data ++;
+ }
+ fclose(file);
+
+ return 0;
+}
+#if defined(RT_USING_FINSH)
+#include <finsh.h>
+FINSH_FUNCTION_EXPORT(digfont_file, create the font file of digit font)
+#endif
+
+#endif \ No newline at end of file
diff --git a/components/rtgui/widgets/digtube.c b/components/rtgui/widgets/digtube.c
new file mode 100644
index 0000000000..e5ce5484ea
--- /dev/null
+++ b/components/rtgui/widgets/digtube.c
@@ -0,0 +1,174 @@
+/*
+ * File : digfont.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2012, 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
+ * 2012-12-21 pife first version
+ */
+
+#include <rtgui/dc.h>
+#include <rtgui/widgets/digtube.h>
+
+static void _rtgui_digtube_constructor(struct rtgui_digtube * digtube)
+{
+ RTGUI_WIDGET_TEXTALIGN(digtube) = RTGUI_ALIGN_CENTER;
+
+ /* init widget and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(digtube), rtgui_digtube_event_handler);
+}
+
+static void _rtgui_digtube_destructor(struct rtgui_digtube *digtube)
+{
+#ifndef RTGUI_DIGTUBE_USE_CONST_FONT
+ /* release font memory */
+ rt_free(digtube->digitfont.data);
+ digtube->digitfont.data = RT_NULL;
+#endif
+}
+
+DEFINE_CLASS_TYPE(digtube, "digtube",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_digtube_constructor,
+ _rtgui_digtube_destructor,
+ sizeof(struct rtgui_digtube));
+
+rt_bool_t rtgui_digtube_event_handler(struct rtgui_object *object, struct rtgui_event *event)
+{
+ struct rtgui_digtube *digtube;
+ struct rtgui_dc *dc;
+ rtgui_rect_t rect;
+ rtgui_rect_t text_rect;
+ rtgui_color_t color;
+ char * disbuf;
+ char tempbuf[8];
+ int i;
+
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+
+ digtube = RTGUI_DIGTUBE(object);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
+ if (dc == RT_NULL)
+ break;
+ rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
+ rtgui_dc_fill_rect(dc, &rect);
+
+ if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
+ {
+ color = RTGUI_DC_BC(dc);
+ RTGUI_DC_BC(dc) = digtube->digit_bc;
+ }
+
+ if (digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISCODES)
+ disbuf = (char *) (digtube->value);
+ else
+ {
+ const char * format =
+ digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISHEXNUM ?
+ "%7x" : "%7d";
+
+ disbuf = &tempbuf[0];
+ rt_snprintf(disbuf, 8, format, digtube->value);
+
+ /* */
+ for (i=0; i<7; i++)
+ {
+ if (disbuf[i] == ' ')
+ disbuf[i] = 0;
+ else
+ {
+ disbuf[i] = (disbuf[i] >= '0' && disbuf[i] <= '9') ? disbuf[i] - '0':
+ disbuf[i] - 'a' + 10;
+
+ disbuf[i] = digtube_code_table[disbuf[i]];
+ }
+ }
+
+ disbuf = tempbuf + 7 - digtube->tube_count;
+ }
+
+ text_rect.x1 = 0;
+ text_rect.y1 = 0;
+ text_rect.x2 = (digtube->digit_width + digtube->digit_space) * digtube->tube_count
+ -digtube->digit_space;
+ text_rect.y2 = digtube->digit_hight;
+
+ rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_DC_TEXTALIGN(dc));
+ for (i=0; i<digtube->tube_count; i++)
+ {
+ rtgui_dc_draw_digitfont_code(dc, &digtube->digitfont, &text_rect, disbuf[i]);
+ text_rect.x1 += digtube->digit_width + digtube->digit_space;
+ }
+
+ if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
+ RTGUI_DC_BC(dc) = color;
+ rtgui_dc_end_drawing(dc);
+ break;
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
+
+ return RT_FALSE;
+}
+
+rtgui_digtube_t *rtgui_digtube_create(
+ struct rtgui_digitfont * digitfont,
+ int count,
+ void * value,
+ int style)
+{
+ struct rtgui_digtube *digtube;
+ rtgui_rect_t rect;
+
+ RT_ASSERT(count <= 7 && count > 0)
+
+ digtube = (struct rtgui_digtube *) rtgui_widget_create(RTGUI_DIGTUBE_TYPE);
+ if (digtube == RT_NULL)
+ return RT_NULL;
+
+ /* set field */
+ if (digitfont == RT_NULL)
+ digitfont = &digitfont_40;
+
+ rt_memcpy(& digtube->digitfont, digitfont, sizeof(struct rtgui_digitfont));
+
+#ifndef RTGUI_DIGTUBE_USE_CONST_FONT
+ if (digtube->digitfont.data == RT_NULL)
+ rtgui_digitfont_create(& digtube->digitfont);
+#endif
+
+ /* set default rect */
+ rtgui_get_digfont_metrics(&digtube->digitfont, &rect);
+ digtube->digit_width = rect.x2;
+ digtube->digit_hight = rect.y2;
+ digtube->tube_count = count;
+ digtube->digit_space = RTGUI_DIGTUBE_DEFAULT_SPACE;
+
+ rect.x2 = (rect.x2 + digtube->digit_space) * count - digtube->digit_space;
+ rect.y2 = rect.y2;
+
+ RTGUI_WIDGET_BACKGROUND(digtube) = rtgui_theme_default_bc();
+ RTGUI_WIDGET_FOREGROUND(digtube) = RTGUI_DIGTUBE_DEFAULT_FC;
+ rtgui_widget_set_rect(RTGUI_WIDGET(digtube), &rect);
+
+ /* set display value */
+ digtube->digit_bc = RTGUI_DIGTUBE_DEFAULT_DIGIT_BC;
+ digtube->value = value;
+ digtube->tube_style = style;
+
+ return digtube;
+}
+
+void rtgui_digtube_destroy(rtgui_digtube_t *digtube)
+{
+ rtgui_widget_destroy(RTGUI_WIDGET(digtube));
+} \ No newline at end of file
diff --git a/components/rtgui/widgets/filelist_view.c b/components/rtgui/widgets/filelist_view.c
index effb42c251..78d05c68d0 100644
--- a/components/rtgui/widgets/filelist_view.c
+++ b/components/rtgui/widgets/filelist_view.c
@@ -250,7 +250,7 @@ static rt_bool_t rtgui_filelist_view_on_folder_item(rtgui_object_t *object, stru
view = RTGUI_FILELIST_VIEW(menu->user_data);
/* hide window */
- rtgui_win_hiden(menu);
+ rtgui_win_hide(menu);
switch (listbox->current_item)
{
diff --git a/components/rtgui/widgets/menu.c b/components/rtgui/widgets/menu.c
index 07a3a4dd15..ce6f719120 100644
--- a/components/rtgui/widgets/menu.c
+++ b/components/rtgui/widgets/menu.c
@@ -61,7 +61,7 @@ static rt_bool_t _rtgui_menu_onitem(struct rtgui_object *object, struct rtgui_ev
if (!RTGUI_WIDGET_IS_HIDE(menu->sub_menu))
{
/* hide this sub menu */
- rtgui_win_hiden(RTGUI_WIN(menu->sub_menu));
+ rtgui_win_hide(RTGUI_WIN(menu->sub_menu));
return RT_FALSE;
}
@@ -91,9 +91,9 @@ static rt_bool_t _rtgui_menu_onitem(struct rtgui_object *object, struct rtgui_ev
/* hide sub-menu */
if (menu->sub_menu != RT_NULL)
{
- rtgui_menu_hiden(menu->sub_menu);
+ rtgui_menu_hide(menu->sub_menu);
}
- rtgui_menu_hiden(menu);
+ rtgui_menu_hide(menu);
}
return RT_FALSE;
}
@@ -183,7 +183,7 @@ static rt_bool_t rtgui_menu_on_deactivate(struct rtgui_object *object, rtgui_eve
return RT_TRUE;
}
- rtgui_win_hiden(RTGUI_WIN(menu));
+ rtgui_win_hide(RTGUI_WIN(menu));
if (menu->on_menuhide != RT_NULL)
{
menu->on_menuhide(RTGUI_OBJECT(menu), RT_NULL);
@@ -282,13 +282,13 @@ void rtgui_menu_pop(struct rtgui_menu *menu, int x, int y)
rtgui_win_show(RTGUI_WIN(menu), RT_FALSE);
}
-void rtgui_menu_hiden(struct rtgui_menu *menu)
+void rtgui_menu_hide(struct rtgui_menu *menu)
{
- rtgui_win_hiden(RTGUI_WIN(menu));
+ rtgui_win_hide(RTGUI_WIN(menu));
/* un-select item */
menu->items_list->current_item = -1;
if (menu->parent_menu != RT_NULL)
- rtgui_menu_hiden(menu->parent_menu);
+ rtgui_menu_hide(menu->parent_menu);
}
diff --git a/components/rtgui/widgets/notebook.c b/components/rtgui/widgets/notebook.c
index b0d1846e65..f3a6da232c 100644
--- a/components/rtgui/widgets/notebook.c
+++ b/components/rtgui/widgets/notebook.c
@@ -539,7 +539,8 @@ void rtgui_notebook_set_current_by_index(struct rtgui_notebook *notebook, rt_uin
widget = notebook->childs[notebook->current].widget;
rtgui_widget_show(widget);
rtgui_widget_update_clip(widget);
- rtgui_widget_update(widget);
+ /* the whole notebook need an update */
+ rtgui_widget_update(RTGUI_WIDGET(notebook));
rtgui_widget_focus(widget);
}
}
diff --git a/components/rtgui/widgets/radiobox.c b/components/rtgui/widgets/radiobox.c
index 47dc92e9db..4eeb620221 100644
--- a/components/rtgui/widgets/radiobox.c
+++ b/components/rtgui/widgets/radiobox.c
@@ -228,14 +228,14 @@ void rtgui_radiobox_set_orientation(struct rtgui_radiobox *radiobox, int orienta
if (radiobox->orient == RTGUI_HORIZONTAL)
{
/* HORIZONTAL */
- rtgui_widget_set_miniheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
+ rtgui_widget_set_minheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
+ rtgui_widget_set_minwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
}
else
{
/* VERTICAL */
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
- rtgui_widget_set_miniheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
+ rtgui_widget_set_minwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
+ rtgui_widget_set_minheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
}
#endif
}
diff --git a/components/rtgui/widgets/slider.c b/components/rtgui/widgets/slider.c
index e592183f07..01ef2a340b 100644
--- a/components/rtgui/widgets/slider.c
+++ b/components/rtgui/widgets/slider.c
@@ -255,14 +255,14 @@ void rtgui_slider_set_orientation(struct rtgui_slider *slider, int orientation)
if (slider->orient == RTGUI_HORIZONTAL)
{
/* HORIZONTAL */
- rtgui_widget_set_miniheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
+ rtgui_widget_set_minheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
+ rtgui_widget_set_minwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
}
else
{
/* VERTICAL */
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
- rtgui_widget_set_miniheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
+ rtgui_widget_set_minwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
+ rtgui_widget_set_minheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
}
#endif
}
diff --git a/components/rtgui/widgets/staticline.c b/components/rtgui/widgets/staticline.c
index 2187f0131c..b3ee043f0d 100644
--- a/components/rtgui/widgets/staticline.c
+++ b/components/rtgui/widgets/staticline.c
@@ -73,14 +73,14 @@ void rtgui_staticline_set_orientation(rtgui_staticline_t *staticline, int orient
if (orientation == RTGUI_HORIZONTAL)
{
/* HORIZONTAL */
- rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 2);
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 100);
+ rtgui_widget_set_minheight(RTGUI_WIDGET(staticline), 2);
+ rtgui_widget_set_minwidth(RTGUI_WIDGET(staticline), 100);
}
else
{
/* VERTICAL */
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 2);
- rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 100);
+ rtgui_widget_set_minwidth(RTGUI_WIDGET(staticline), 2);
+ rtgui_widget_set_minheight(RTGUI_WIDGET(staticline), 100);
}
#endif
}
diff --git a/components/rtgui/widgets/textbox.c b/components/rtgui/widgets/textbox.c
index 53642aeed3..6cc46e05f4 100644
--- a/components/rtgui/widgets/textbox.c
+++ b/components/rtgui/widgets/textbox.c
@@ -54,6 +54,14 @@ static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
rtgui_textbox_set_mask_char(box, '*');
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(box), "H", &rect);
+ rtgui_widget_set_minheight(RTGUI_WIDGET(box),
+ rtgui_rect_height(rect) + RTGUI_TEXTBOX_BORDER_WIDTH * 2);
+ /* at least, we want to display one char. */
+ rtgui_widget_set_minwidth(RTGUI_WIDGET(box),
+ rtgui_rect_width(rect) + RTGUI_TEXTBOX_BORDER_WIDTH * 2 \
+ + RTGUI_WIDGET_DEFAULT_MARGIN /* there is a margin in the beginning
+ of the text. */
+ );
box->font_width = rtgui_rect_width(rect);
box->on_enter = RT_NULL;
box->dis_length = 0;
@@ -531,13 +539,13 @@ void rtgui_textbox_ondraw(rtgui_textbox_t *box)
rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
fc = RTGUI_WIDGET_FOREGROUND(box);
- rtgui_rect_inflate(&rect, -1);
+ rtgui_rect_inflate(&rect, -RTGUI_TEXTBOX_BORDER_WIDTH);
/* fill widget rect with white color */
RTGUI_WIDGET_BACKGROUND(box) = white;
rtgui_dc_fill_rect(dc, &rect);
- rtgui_rect_inflate(&rect, 1);
+ rtgui_rect_inflate(&rect, RTGUI_TEXTBOX_BORDER_WIDTH);
/* draw border */
RTGUI_WIDGET_FOREGROUND(box) = RTGUI_RGB(123, 158, 189);
rtgui_dc_draw_rect(dc, &rect);
@@ -610,29 +618,27 @@ char rtgui_textbox_get_mask_char(rtgui_textbox_t *box)
return box->mask_char;
}
-void rtgui_textbox_set_line_length(rtgui_textbox_t *box, rt_size_t length)
+rt_err_t rtgui_textbox_set_line_length(rtgui_textbox_t *box, rt_size_t length)
{
- rt_uint8_t *new_line;
+ char *new_line;
- RT_ASSERT(box != RT_NULL);
+ RT_ASSERT(box != RT_NULL);
- /* invalid length */
- if (length <= 0)
- return;
+ /* invalid length */
+ if (length <= 0)
+ return -RT_ERROR;
- new_line = rtgui_malloc(length);
- if (length < box->line_length)
- {
- rt_memcpy(new_line, box->text, length - 1);
- new_line[length] = '\0';
- }
- else
- {
- rt_memcpy(new_line, (const char *)box->text, rt_strlen((const char *)box->text));
- }
+ new_line = rtgui_realloc(box->text, length+1);
+ if (new_line == RT_NULL)
+ return -RT_ENOMEM;
+
+ if (length < box->line_length)
+ new_line[length] = '\0';
+
+ box->line_length = length;
+ box->text = new_line;
- /* set line length */
- box->line_length = length;
+ return RT_EOK;
}
/* get textbox text area */
diff --git a/components/rtgui/widgets/widget.c b/components/rtgui/widgets/widget.c
index 83c87ba1b9..9340a5394a 100644
--- a/components/rtgui/widgets/widget.c
+++ b/components/rtgui/widgets/widget.c
@@ -135,9 +135,9 @@ void rtgui_widget_set_rect(rtgui_widget_t *widget, const rtgui_rect_t *rect)
rtgui_container_layout(RTGUI_CONTAINER(widget));
}
- /* reset mini width and height */
- widget->mini_width = rtgui_rect_width(widget->extent);
- widget->mini_height = rtgui_rect_height(widget->extent);
+ /* reset min width and height */
+ widget->min_width = rtgui_rect_width(widget->extent);
+ widget->min_height = rtgui_rect_height(widget->extent);
/* it's not empty, fini it */
if (rtgui_region_not_empty(&(widget->clip)))
@@ -184,21 +184,29 @@ void rtgui_widget_get_extent(rtgui_widget_t *widget, rtgui_rect_t *rect)
}
RTM_EXPORT(rtgui_widget_get_extent);
-void rtgui_widget_set_miniwidth(rtgui_widget_t *widget, int width)
+void rtgui_widget_set_minsize(rtgui_widget_t *widget, int width, int height)
+{
+ RT_ASSERT(widget != RT_NULL);
+ widget->min_width = width;
+ widget->min_height = height;
+}
+RTM_EXPORT(rtgui_widget_set_minsize);
+
+void rtgui_widget_set_minwidth(rtgui_widget_t *widget, int width)
{
RT_ASSERT(widget != RT_NULL);
- widget->mini_width = width;
+ widget->min_width = width;
}
-RTM_EXPORT(rtgui_widget_set_miniwidth);
+RTM_EXPORT(rtgui_widget_set_minwidth);
-void rtgui_widget_set_miniheight(rtgui_widget_t *widget, int height)
+void rtgui_widget_set_minheight(rtgui_widget_t *widget, int height)
{
RT_ASSERT(widget != RT_NULL);
- widget->mini_height = height;
+ widget->min_height = height;
}
-RTM_EXPORT(rtgui_widget_set_miniheight);
+RTM_EXPORT(rtgui_widget_set_minheight);
/*
* This function moves widget and its children to a logic point
diff --git a/components/rtgui/widgets/window.c b/components/rtgui/widgets/window.c
index cb93ee9e92..78971a4649 100644
--- a/components/rtgui/widgets/window.c
+++ b/components/rtgui/widgets/window.c
@@ -178,7 +178,7 @@ static rt_bool_t _rtgui_win_deal_close(struct rtgui_win *win,
return RT_FALSE;
}
- rtgui_win_hiden(win);
+ rtgui_win_hide(win);
win->flag |= RTGUI_WIN_FLAG_CLOSED;
@@ -280,7 +280,7 @@ rt_base_t rtgui_win_show(struct rtgui_win *win, rt_bool_t is_modal)
/* set main window */
if (app->main_object == RT_NULL)
- rtgui_app_set_main_win(win);
+ rtgui_app_set_main_win(app, win);
if (is_modal == RT_TRUE)
{
@@ -328,7 +328,7 @@ void rtgui_win_end_modal(struct rtgui_win *win, rtgui_modal_code_t modal_code)
}
RTM_EXPORT(rtgui_win_end_modal);
-void rtgui_win_hiden(struct rtgui_win *win)
+void rtgui_win_hide(struct rtgui_win *win)
{
RT_ASSERT(win != RT_NULL);
@@ -351,7 +351,7 @@ void rtgui_win_hiden(struct rtgui_win *win)
win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
}
}
-RTM_EXPORT(rtgui_win_hiden);
+RTM_EXPORT(rtgui_win_hide);
rt_err_t rtgui_win_activate(struct rtgui_win *win)
{
@@ -469,7 +469,7 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object *object, struct rtgui_even
break;
case RTGUI_EVENT_WIN_HIDE:
- rtgui_win_hiden(win);
+ rtgui_win_hide(win);
break;
case RTGUI_EVENT_WIN_CLOSE:
@@ -538,27 +538,37 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object *object, struct rtgui_even
break;
case RTGUI_EVENT_MOUSE_BUTTON:
- /* check whether has widget which handled mouse event before */
- if (win->last_mevent_widget != RT_NULL)
- {
- RTGUI_OBJECT(win->last_mevent_widget)->event_handler(
- RTGUI_OBJECT(win->last_mevent_widget),
- event);
-
- /* clean last mouse event handled widget */
- win->last_mevent_widget = RT_NULL;
- }
- else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
- (struct rtgui_event_mouse *)event) == RT_FALSE)
{
+ rt_bool_t res = rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
+ (struct rtgui_event_mouse *)event);
#ifndef RTGUI_USING_SMALL_SIZE
if (RTGUI_WIDGET(object)->on_mouseclick != RT_NULL)
{
- return RTGUI_WIDGET(object)->on_mouseclick(object, event);
+ RTGUI_WIDGET(object)->on_mouseclick(object, event);
}
#endif
+ /* check whether has widget which handled mouse event before.
+ *
+ * Note #1: that the widget should have already received mouse down
+ * event and we should only feed the mouse up event to it here.
+ *
+ * Note #2: the widget is responsible to clean up
+ * last_mevent_widget on mouse up event(but not overwrite other
+ * widgets). If not, it will receive two mouse up events.
+ */
+ if (((struct rtgui_event_mouse *)event)->button & RTGUI_MOUSE_BUTTON_UP
+ && win->last_mevent_widget != RT_NULL)
+ {
+ RTGUI_OBJECT(win->last_mevent_widget)->event_handler(
+ RTGUI_OBJECT(win->last_mevent_widget),
+ event);
+
+ /* clean last mouse event handled widget */
+ win->last_mevent_widget = RT_NULL;
+ }
+
+ return res;
}
- break;
case RTGUI_EVENT_MOUSE_MOTION:
#if 0
@@ -623,7 +633,7 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object *object, struct rtgui_even
return RT_TRUE;
break;
- default :
+ default:
return rtgui_container_event_handler(object, event);
}