|
@@ -105,16 +105,18 @@ static void _rtgui_listctrl_scrollbar_onmouse(struct rtgui_listctrl *ctrl, struc
|
|
|
if (mouse->y < rect.y1)
|
|
|
{
|
|
|
if (ctrl->current_item - ctrl->page_items >= 0)
|
|
|
- ctrl->current_item -= ctrl->page_items;
|
|
|
- rtgui_listctrl_update_current(ctrl, old_item);
|
|
|
+ rtgui_listctrl_set_current_item(ctrl, ctrl->current_item - ctrl->page_items);
|
|
|
+ else
|
|
|
+ rtgui_listctrl_update_current(ctrl, old_item);
|
|
|
}
|
|
|
else if (mouse->y > rect.y2)
|
|
|
{
|
|
|
+ rt_uint16_t new_item;
|
|
|
if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
|
|
|
- ctrl->current_item += ctrl->page_items;
|
|
|
+ new_item = ctrl->current_item + ctrl->page_items;
|
|
|
else
|
|
|
- ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
|
|
|
- rtgui_listctrl_update_current(ctrl, old_item);
|
|
|
+ new_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
|
|
|
+ rtgui_listctrl_set_current_item(ctrl, new_item);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -166,7 +168,7 @@ static void _rtgui_listctrl_ondraw(struct rtgui_listctrl *ctrl)
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
}
|
|
|
|
|
|
-void rtgui_listctrl_update_current(struct rtgui_listctrl *ctrl, rt_uint16_t old_item)
|
|
|
+static void rtgui_listctrl_update_current(struct rtgui_listctrl *ctrl, rt_uint16_t old_item)
|
|
|
{
|
|
|
struct rtgui_dc *dc;
|
|
|
rtgui_rect_t rect, item_rect;
|
|
@@ -214,7 +216,6 @@ void rtgui_listctrl_update_current(struct rtgui_listctrl *ctrl, rt_uint16_t old_
|
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
}
|
|
|
-RTM_EXPORT(rtgui_listctrl_update_current);
|
|
|
|
|
|
rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object *object, struct rtgui_event *event)
|
|
|
{
|
|
@@ -288,24 +289,10 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object *object, struct rtgui
|
|
|
if ((index < ctrl->page_items) &&
|
|
|
(ctrl->current_item / ctrl->page_items)* ctrl->page_items + index < ctrl->items_count)
|
|
|
{
|
|
|
- rt_uint16_t old_item;
|
|
|
-
|
|
|
- old_item = ctrl->current_item;
|
|
|
-
|
|
|
- /* set selected item */
|
|
|
- ctrl->current_item = (ctrl->current_item / ctrl->page_items) * ctrl->page_items + index;
|
|
|
if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
|
|
|
{
|
|
|
- /* down event */
|
|
|
- rtgui_listctrl_update_current(ctrl, old_item);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- /* up event */
|
|
|
- if (ctrl->on_item != RT_NULL)
|
|
|
- {
|
|
|
- ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
|
|
|
- }
|
|
|
+ rtgui_listctrl_set_current_item(ctrl,
|
|
|
+ (ctrl->current_item / ctrl->page_items) * ctrl->page_items + index);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -318,38 +305,36 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object *object, struct rtgui
|
|
|
struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
|
|
|
if ((ekbd->type == RTGUI_KEYDOWN) && (ctrl->items_count > 0))
|
|
|
{
|
|
|
- rt_uint16_t old_item;
|
|
|
-
|
|
|
- old_item = ctrl->current_item;
|
|
|
switch (ekbd->key)
|
|
|
{
|
|
|
case RTGUIK_LEFT:
|
|
|
if (ctrl->current_item - ctrl->page_items >= 0)
|
|
|
- ctrl->current_item -= ctrl->page_items;
|
|
|
- rtgui_listctrl_update_current(ctrl, old_item);
|
|
|
+ rtgui_listctrl_set_current_item(ctrl, ctrl->current_item - ctrl->page_items);
|
|
|
return RT_TRUE;
|
|
|
|
|
|
case RTGUIK_UP:
|
|
|
if (ctrl->current_item > 0)
|
|
|
- ctrl->current_item --;
|
|
|
- rtgui_listctrl_update_current(ctrl, old_item);
|
|
|
+ rtgui_listctrl_set_current_item(ctrl, ctrl->current_item-1);
|
|
|
return RT_TRUE;
|
|
|
|
|
|
case RTGUIK_RIGHT:
|
|
|
- if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
|
|
|
- ctrl->current_item += ctrl->page_items;
|
|
|
- else
|
|
|
{
|
|
|
- if ((((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items) < ctrl->items_count - 1)
|
|
|
- ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
|
|
|
+ rt_uint16_t new_item = ctrl->items_count;
|
|
|
+ if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
|
|
|
+ new_item = ctrl->current_item + ctrl->page_items;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if ((((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items)
|
|
|
+ < ctrl->items_count - 1)
|
|
|
+ new_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
|
|
|
+ }
|
|
|
+ rtgui_listctrl_set_current_item(ctrl, new_item);
|
|
|
}
|
|
|
- rtgui_listctrl_update_current(ctrl, old_item);
|
|
|
return RT_TRUE;
|
|
|
|
|
|
case RTGUIK_DOWN:
|
|
|
if (ctrl->current_item < ctrl->items_count - 1)
|
|
|
- ctrl->current_item ++;
|
|
|
- rtgui_listctrl_update_current(ctrl, old_item);
|
|
|
+ rtgui_listctrl_set_current_item(ctrl, ctrl->current_item+1);
|
|
|
return RT_TRUE;
|
|
|
|
|
|
case RTGUIK_RETURN:
|