Example #1
0
static rt_bool_t app_list_view_onmouse(struct app_list_view *view,
                                       struct rtgui_event_mouse *emouse)
{
    if (rtgui_rect_contains_point(&view->view_rect,
                                  emouse->x, emouse->y) == RT_EOK)
    {
        rt_uint16_t index;
        rt_uint16_t old_item;

        /* get old item */
        old_item = view->current_item;

        {
            rt_uint16_t x, y;
            rt_uint16_t item_height, item_width;


            item_width = (rtgui_rect_width(view->view_rect) - 2 * LIST_MARGIN) /
                         view->col_items;
            item_height = (rtgui_rect_height(view->view_rect) - 4) / view->row_items;
            x = emouse->x - view->view_rect.x1;
            y = emouse->y - view->view_rect.y1;

            index = (y / item_height * view->col_items) + x / item_width;

            if ((index + (view->current_page * view->page_items) <
                    view->items_count))
            {

                if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
                {
                    view->current_item = index + (view->current_page *
                                                  view->page_items);
                    /* down event */
                    // rtgui_list_view_update_icon(view, old_item);
                }
                else
                {
                    if (view->current_item == index + (view->current_page *
                                                       view->page_items))
                    {
                        rt_kprintf("mouse up,current item:%d\n", view->current_item);
                        /* up event */
                        if (view->on_select != RT_NULL)
                        {
                            view->on_select(&view->items[view->current_item]);
                        }
                    }
                }

            }
        }


        return RT_TRUE;
    }

    return RT_FALSE;
}
Example #2
0
static rt_bool_t rtgui_combobox_onmouse_button(struct rtgui_combobox* box, struct rtgui_event_mouse* event)
{
	struct rtgui_rect rect;

	/* get widget rect */
	rect = RTGUI_WIDGET(box)->extent;

	/* move to the pull down button */
	rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH;
	if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK)
	{
		/* handle mouse button on pull down button */
		if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
			event->button & RTGUI_MOUSE_BUTTON_DOWN)
		{
			box->pd_pressed = RT_TRUE;
			rtgui_widget_update(RTGUI_WIDGET(box));
		}
		else if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
			event->button & RTGUI_MOUSE_BUTTON_UP)
		{
			box->pd_pressed = RT_FALSE;
			rtgui_widget_update(RTGUI_WIDGET(box));

			/* pop pull down window */
			if (box->pd_win == RT_NULL)
			{
				rtgui_listbox_t  *list;

				/* create pull down window */
				rect = RTGUI_WIDGET(box)->extent;
				rect.y1 = rect.y2;
				rect.y2 = rect.y1 + 5 * (2 + rtgui_theme_get_selected_height());
				box->pd_win = rtgui_win_create(RT_NULL, "combo", &rect, RTGUI_WIN_STYLE_NO_TITLE);
				rtgui_win_set_ondeactivate(RTGUI_WIN(box->pd_win), rtgui_combobox_pulldown_hide);
				/* set user data to parent combobox */
				box->pd_win->user_data = (rt_uint32_t)box;

				/* create list box */
				rtgui_rect_inflate(&rect, -1);
				list = rtgui_listbox_create(box->items, box->items_count, &rect);
				rtgui_container_add_child(RTGUI_CONTAINER(box->pd_win), RTGUI_WIDGET(list));
				rtgui_widget_focus(RTGUI_WIDGET(list));

				rtgui_listbox_set_onitem(list, rtgui_combobox_pdwin_onitem);
				rtgui_win_set_ondeactivate(box->pd_win, rtgui_combobox_pdwin_ondeactive);
			}

			/* show combo box pull down window */
			rtgui_win_show(RTGUI_WIN(box->pd_win), RT_FALSE);
		}

		return RT_TRUE;
	}

	return RT_FALSE;
}
Example #3
0
static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	if (event->type == RTGUI_EVENT_PAINT)
	{
		struct rtgui_dc* dc;
		struct rtgui_rect rect;
		rtgui_image_t *image;

		dc = rtgui_dc_begin_drawing(widget);
		if (dc == RT_NULL) return RT_FALSE;
		rtgui_widget_get_rect(widget, &rect);

		rtgui_dc_fill_rect(dc, &rect);
		rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2 - 1);

		/* draw RT-Thread logo */
		image = rtgui_image_create_from_file("hdc",
			"/resource/RTT.hdc", RT_FALSE);
		if (image != RT_NULL)
		{
			rtgui_image_blit(image, dc, &rect);
			rtgui_image_destroy(image);
			
			image = RT_NULL;
		}

        if (network_image != RT_NULL)
        {
            rect.x1 = rect.x2 - (network_image->w + 2);
            rtgui_image_blit(network_image, dc, &rect);
        }

		rtgui_dc_end_drawing(dc);

		return RT_FALSE;
	}
	else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
	{
		struct rtgui_rect rect;
		struct rtgui_event_mouse* emouse; 

		emouse = (struct rtgui_event_mouse*) event;
		rtgui_widget_get_rect(widget, &rect);

		rect.y2 = rect.y1 + 100;
		if (emouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP) &&
			(rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK))
		{
			/* enter function view */
			player_notfiy_functionview();
		}
	}

	return rtgui_view_event_handler(widget, event);
}
Example #4
0
static void _rtgui_notebook_onmouse(struct rtgui_notebook *notebook, struct rtgui_event_mouse* emouse)
{
	rtgui_rect_t rect;

	/* handle notebook bar */
	_rtgui_notebook_get_bar_rect(notebook, &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
	if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
	{
		int index;
		struct rtgui_dc* dc;

		if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM || notebook->flag == RTGUI_NOTEBOOK_TOP)
		{
			index = (emouse->x - rect.x1) / notebook->tab_w;
			if (index < notebook->count && index != notebook->current)
			{
				/* update tab bar */
				dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
				if (dc == RT_NULL) return;

				rtgui_notebook_set_current_by_index(notebook, index);

				_rtgui_notebook_draw_bar(notebook, dc);

				rtgui_dc_end_drawing(dc);
			}
		}
		else
		{
			index = (emouse->y - rect.y1) / notebook->tab_h;
			if (index < notebook->count && index != notebook->current)
			{
				/* update tab bar */
				dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
				if (dc == RT_NULL) return;

				rtgui_notebook_set_current_by_index(notebook, index);
				_rtgui_notebook_draw_bar(notebook, dc);
				
				rtgui_dc_end_drawing(dc);
			}
		}
	}
	else
	{
		/* handle on page */
		if (RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler != RT_NULL)
			RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler(
					RTGUI_OBJECT(notebook->childs[notebook->current].widget),
					&(emouse->parent));
	}
}
Example #5
0
static void rtgui_radiobox_onmouse(struct rtgui_radiobox *radiobox, struct rtgui_event_mouse *event)
{
    RT_ASSERT(radiobox != RT_NULL);
    RT_ASSERT(event  != RT_NULL);

    /* widget is hide, return */
    if (RTGUI_WIDGET_IS_HIDE(radiobox) ||
            !RTGUI_WIDGET_IS_ENABLE(radiobox)) return;

    if (event->button & RTGUI_MOUSE_BUTTON_DOWN &&
            event->button & RTGUI_MOUSE_BUTTON_LEFT)
    {
        int bord_size;
        struct rtgui_rect rect;

        /* focus widgets */
        rtgui_widget_focus(RTGUI_WIDGET(radiobox));

        /* get widget physical rect */
        rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
        rtgui_widget_rect_to_device(RTGUI_WIDGET(radiobox), &rect);

        /* get board size */
        if (radiobox->orient == RTGUI_VERTICAL)
            bord_size = radiobox->item_size;
        else
        {
            struct rtgui_rect bord_rect;

            rtgui_font_get_metrics(RTGUI_WIDGET_FONT(radiobox), "H", &bord_rect);
            bord_size = rtgui_rect_height(bord_rect);
        }
        rtgui_rect_inflate(&rect, - bord_size);
        if (rtgui_rect_contains_point(&rect, event->x, event->y) != RT_EOK) return;

        if (radiobox->orient == RTGUI_VERTICAL)
        {
            int delta_y = event->y - rect.y1;
            rtgui_radiobox_set_selection(radiobox, delta_y / radiobox->item_size);
        }
        else
        {
            int delta_x = event->x - rect.x1;
            rtgui_radiobox_set_selection(radiobox, delta_x / radiobox->item_size);
        }
    }
}
Example #6
0
static rt_bool_t apps_listctrl_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{
	struct rtgui_listctrl* ctrl;

	ctrl = RTGUI_LISTCTRL(object);
	if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
	{
		struct rtgui_rect rect, close_rect;
		struct rtgui_event_mouse* emouse;

		emouse = (struct rtgui_event_mouse*)event;
		if (emouse->button & RTGUI_MOUSE_BUTTON_UP)
		{
			/* get physical extent information */
			rtgui_widget_get_extent(RTGUI_WIDGET(ctrl), &rect);
			close_rect = rect;
			close_rect.x1 = close_rect.x2 - 50;

			if ((rtgui_rect_contains_point(&close_rect, emouse->x, emouse->y) == RT_EOK) &&
					(ctrl->items_count > 0))
			{
				rt_uint16_t index;
				index = (emouse->y - rect.y1) / (2 + ctrl->item_height);

				if ((index < ctrl->page_items) &&
					(ctrl->current_item/ctrl->page_items)* ctrl->page_items + index < ctrl->items_count)
				{
					rt_uint16_t cur_item;

					/* get current item */
					cur_item = (ctrl->current_item/ctrl->page_items) * ctrl->page_items + index;
					if (cur_item == ctrl->current_item)
					{
						rt_kprintf("close app\n");
						rtgui_app_close(app_items[ctrl->current_item].app);
						return RT_TRUE;
					}
				}
			}
		}
	}

	return rtgui_listctrl_event_handler(object, event);
}
Example #7
0
File: server.c Project: eyeye/RTGUI
void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event)
{
    struct rtgui_topwin *wnd;

    /* re-init to server thread */
    RTGUI_EVENT_MOUSE_BUTTON_INIT(event);

	/* set cursor position */
	rtgui_mouse_set_position(event->x, event->y);

#ifdef RTGUI_USING_WINMOVE
    if (rtgui_winrect_is_moved() &&
            event->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP))
    {
        struct rtgui_topwin *topwin;
        rtgui_rect_t rect;

        if (rtgui_winrect_moved_done(&rect, &topwin) == RT_TRUE)
        {
            struct rtgui_event_win_move ewin;

            /* move window */
            RTGUI_EVENT_WIN_MOVE_INIT(&ewin);
            ewin.wid = topwin->wid;
            if (topwin->title != RT_NULL)
            {
                if (topwin->flag & WINTITLE_BORDER)
                {
                    ewin.x = rect.x1 + WINTITLE_BORDER_SIZE;
                    ewin.y = rect.y1 + WINTITLE_BORDER_SIZE;
                }
                if (!(topwin->flag & WINTITLE_NO)) ewin.y += WINTITLE_HEIGHT;
            }
            else
            {
                ewin.x = rect.x1;
                ewin.y = rect.y1;
            }

            /* send to client thread */
            rtgui_send(topwin->tid, &(ewin.parent), sizeof(ewin));

            return;
        }
    }
#endif

    /* get the wnd which contains the mouse */
    wnd = rtgui_topwin_get_wnd_no_modaled(event->x, event->y);
    if (wnd != RT_NULL)
    {
        event->wid = wnd->wid;

        if (rtgui_topwin_get_focus() != wnd)
        {
            /* raise this window */
            rtgui_topwin_activate_topwin(wnd);
        }

        if (wnd->title != RT_NULL &&
                rtgui_rect_contains_point(&(RTGUI_WIDGET(wnd->title)->extent), event->x, event->y) == RT_EOK)
        {
            rtgui_topwin_title_onmouse(wnd, event);
        }
        else
        {
            /* send mouse event to thread */
            rtgui_send(wnd->tid, (struct rtgui_event *)event, sizeof(struct rtgui_event_mouse));
        }
        return ;
    }
}
Example #8
0
rt_bool_t rtgui_combo_event_handler(pvoid wdt, rtgui_event_t* event)
{
	rtgui_widget_t *widget = RTGUI_WIDGET(wdt);
	rtgui_combo_t* cbo = RTGUI_COMBO(wdt);


	RT_ASSERT(widget != RT_NULL);

	switch(event->type)
	{
	case RTGUI_EVENT_PAINT:
		if(widget->on_draw != RT_NULL)
			widget->on_draw(widget, event);
		else
			rtgui_combo_ondraw(cbo);
		break;

	case RTGUI_EVENT_KBD:
		if(widget->on_key != RT_NULL)
			widget->on_key(widget, event);

		return RT_TRUE;

	case RTGUI_EVENT_MOUSE_BUTTON:
	{
		rtgui_rect_t rect;
		struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
		rt_bool_t inclip=RT_EOK;

		if(!RTGUI_WIDGET_IS_ENABLE(cbo)) break;

		if(cbo->tbox->isedit == RT_TRUE)
		{
			/* only detect textbox area */
			inclip = rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect);
		}
		else
		{
			/* detect all area */
			inclip = (rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect) &&
			          rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo->tbox),emouse->x,emouse->y,&rect));
		}

		if(inclip == RT_EOK)
		{
			rtgui_combo_get_downarrow_rect(cbo,&rect);
			if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
			{
				if(rtgui_rect_contains_point(&rect,emouse->x,emouse->y) == RT_EOK)
				{
					/* on pull-down button */
					cbo->style = RTGUI_COMBO_STYLE_DOWNARROW_DOWN;
					rtgui_combo_draw_downarrow(cbo);
				}

				if(cbo->lbox != RT_NULL)
				{
					if(RTGUI_WIDGET_IS_HIDE(cbo->lbox))
					{
						/* display pupup listbox */
						RTGUI_WIDGET_SHOW(cbo->lbox);
						rtgui_widget_focus(cbo->lbox);
						rtgui_widget_update_clip_pirate(RTGUI_WIDGET_PARENT(cbo->lbox),cbo->lbox);
						/* set listbox location is 0 */
						cbo->lbox->first_item=0;
						cbo->lbox->now_item = 0;
						if(cbo->lbox->scroll != RT_NULL)
						{
							if(!RTGUI_WIDGET_IS_HIDE(cbo->lbox->scroll))
							{
								rtgui_scrollbar_set_value(cbo->lbox->scroll,cbo->lbox->first_item);
							}
						}
						rtgui_widget_update(RTGUI_WIDGET_PARENT(cbo->lbox));
					}
					else
					{
						/* hide it */
						rtgui_widget_hide(cbo->lbox);
					}
				}
			}
			else if(emouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				if(rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect) == RT_EOK)
				{
					/* on upriver button */
					cbo->style = RTGUI_COMBO_STYLE_DOWNARROW_UP;
					rtgui_combo_draw_downarrow(cbo);
				}
			}
		}
		else
			rtgui_view_event_handler(widget,event);

		return RT_TRUE;
	}

	default:
		return rtgui_view_event_handler(widget,event);
	}

	return RT_FALSE;
}
Example #9
0
rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_button* btn;

	RT_ASSERT(widget != RT_NULL);

	btn = (struct rtgui_button*) widget;
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_theme_draw_button(btn);
		break;

	case RTGUI_EVENT_KBD:
		{
			struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*) event;

			if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
			if ((ekbd->key == RTGUIK_RETURN) || (ekbd->key == RTGUIK_SPACE))
			{
				if (RTGUI_KBD_IS_DOWN(ekbd))
				{
					btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
				}
				else
				{
					btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
				}

				/* draw button */
				rtgui_theme_draw_button(btn);

				if ((btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
				{
					/* call on button handler */
					btn->on_button(widget, event);
				}
			}
		}
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
		{
			struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;

			/* it's not this widget event, clean status */
			if (rtgui_rect_contains_point(&(RTGUI_WIDGET(btn)->extent), 
				emouse->x, emouse->y) != RT_EOK)
			{
				btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
				/* draw button */
				rtgui_theme_draw_button(btn);

				break;
			}

			if (btn->flag & RTGUI_BUTTON_TYPE_PUSH)
			{
				/* it's a push button */
				if (emouse->button & RTGUI_MOUSE_BUTTON_UP)
				{
					if (btn->flag & RTGUI_BUTTON_FLAG_PRESS)
					{
						btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
					}
					else
					{
						btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
					}

					/* draw button */
					rtgui_theme_draw_button(btn);

					if (btn->on_button != RT_NULL)
					{
						/* call on button handler */
						btn->on_button(widget, event);
					}

#ifndef RTGUI_USING_SMALL_SIZE
					/* invokes call back */
					if (widget->on_mouseclick != RT_NULL &&
						emouse->button & RTGUI_MOUSE_BUTTON_UP)
						return widget->on_mouseclick(widget, event);
#endif
				}
			}
			else
			{
				if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT)
				{
					/* set the last mouse event handled widget */
					rtgui_toplevel_t* toplevel;

					toplevel = RTGUI_TOPLEVEL(RTGUI_WIDGET(btn)->toplevel);
					toplevel->last_mevent_widget = RTGUI_WIDGET(btn);

					/* it's a normal button */
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
					}
					else
					{
						btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
					}

					/* draw button */
					rtgui_theme_draw_button(btn);

#ifndef RTGUI_USING_SMALL_SIZE
					/* invokes call back */
					if (widget->on_mouseclick != RT_NULL &&
						emouse->button & RTGUI_MOUSE_BUTTON_UP)
						return widget->on_mouseclick(widget, event);
#endif

					if (!(btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
					{
						/* call on button handler */
						btn->on_button(widget, event);
					}
				}

			}

			return RT_TRUE;
		}
	}

	return RT_FALSE;
}
Example #10
0
rt_bool_t rtgui_fileview_event_handler(pvoid wdt, rtgui_event_t* event)
{
	rtgui_widget_t *widget = RTGUI_WIDGET(wdt);
	rtgui_fileview_t* fview = RTGUI_FILEVIEW(wdt);

	switch(event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_fileview_ondraw(fview);
		return RT_FALSE;

	case RTGUI_EVENT_MOUSE_BUTTON:
	{
		rtgui_rect_t rect;
		struct rtgui_event_mouse* emouse;

		emouse = (struct rtgui_event_mouse*)event;

		rtgui_widget_focus(fview);
		/* get physical extent information */
		rtgui_widget_get_rect(fview, &rect);
		rtgui_widget_rect_to_device(fview, &rect);

		if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
			rect.x2 -= RC_W(fview->sbar->parent.extent);

		if((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) && fview->item_count>0)
		{
			rt_uint16_t i;

			/* set focus */
			rtgui_widget_focus(fview);

			i = (emouse->y - rect.y1) / (2 + RTGUI_SEL_H);

			if((i < fview->item_count) && (i < fview->item_per_page))
			{
				if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
				{
					fview->old_item = fview->now_item;
					fview->now_item = fview->first_item + i;
					rtgui_fileview_update_current(fview);
				}
				else if(emouse->button & RTGUI_MOUSE_BUTTON_UP)
				{
					if(fview->now_item==fview->old_item) return RT_FALSE;

					rtgui_fileview_update_current(fview);
				}
				if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
				{
					if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
						rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
				}
			}
		}
		rtgui_container_dispatch_mouse_event(fview, emouse);
		return RT_TRUE;
	}

	case RTGUI_EVENT_KBD:
	{
		struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*)event;
		if(RTGUI_KBD_IS_DOWN(ekbd))
		{
			switch(ekbd->key)
			{
			case RTGUIK_UP:
				if(fview->now_item > 0)
				{
					fview->old_item = fview->now_item;
					fview->now_item --;

					if(fview->now_item < fview->first_item)
					{
						/* turn up page */
						fview->first_item = fview->now_item;
						rtgui_fileview_ondraw(fview);
					}
					else
					{
						/* current page */
						rtgui_fileview_update_current(fview);
					}

					if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
					{
						if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
							rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
					}
				}
				return RT_TRUE;

			case RTGUIK_DOWN:
				if(fview->now_item < fview->item_count-1)
				{
					fview->old_item = fview->now_item;
					fview->now_item ++;

					if(fview->now_item >= fview->first_item+fview->item_per_page)
					{
						/* turn down page */
						fview->first_item++;
						rtgui_fileview_ondraw(fview);
					}
					else
					{
						/* in current page */
						rtgui_fileview_update_current(fview);
					}
					if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
					{
						if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
							rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
					}
				}
				return RT_TRUE;

			case RTGUIK_LEFT:
				if(fview->item_count==0)return RT_FALSE;
				fview->old_item = fview->now_item;
				fview->now_item -= fview->item_per_page;

				if(fview->now_item < 0)
					fview->now_item = 0;

				if(fview->now_item < fview->first_item)
				{
					fview->first_item = fview->now_item;
					rtgui_fileview_ondraw(fview);
				}
				else
				{
					rtgui_fileview_update_current(fview);
				}
				if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
				{
					if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
						rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
				}
				return RT_TRUE;

			case RTGUIK_RIGHT:
				if(fview->item_count==0)return RT_FALSE;
				fview->old_item = fview->now_item;
				fview->now_item += fview->item_per_page;

				if(fview->now_item > fview->item_count-1)
					fview->now_item = fview->item_count-1;

				if(fview->now_item >= fview->first_item+fview->item_per_page)
				{
					fview->first_item += fview->item_per_page;
					if(fview->first_item >fview->item_count-fview->item_per_page)
					{
						fview->first_item = fview->item_count-fview->item_per_page;
						fview->now_item = fview->first_item;
					}
					rtgui_fileview_ondraw(fview);
				}
				else
				{
					rtgui_fileview_update_current(fview);
				}
				if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
				{
					if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
						rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
				}
				return RT_TRUE;

			case RTGUIK_RETURN:
				rtgui_fileview_on_enter(fview, event);
				return RT_TRUE;
			case RTGUIK_BACKSPACE:
				rtgui_fileview_goto_topfolder(fview);
				return RT_TRUE;
			default:
				break;
			}
		}
	}
	return RT_FALSE;
	default:
		return rtgui_container_event_handler(widget, event);
	}
}
Example #11
0
rt_bool_t rtgui_listctrl_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_listctrl* ctrl = RT_NULL;

	ctrl = RTGUI_LISTCTRL(widget);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		_rtgui_listctrl_ondraw(ctrl);
		return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
        {
			struct rtgui_event_resize* resize;

			resize = (struct rtgui_event_resize*)event;

            /* recalculate page items */
			ctrl->page_items = resize->h  / (2 + rtgui_theme_get_selected_height());
        }
        break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			rtgui_rect_t rect;
			struct rtgui_event_mouse* emouse;

			emouse = (struct rtgui_event_mouse*)event;

			/* get scrollbar rect */
			_rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
			rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);
			if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
			{
				_rtgui_listctrl_scrollbar_onmouse(ctrl, emouse);
				return RT_TRUE;
			}

			/* calculate selected item */

			/* get physical extent information */
			_rtgui_listctrl_get_rect(ctrl, &rect);
			rtgui_widget_rect_to_device(widget, &rect);

			if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) &&
					(ctrl->items_count > 0))
			{
				rt_uint16_t index;
				index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

				/* set focus */
				rtgui_widget_focus(widget);
				{
					struct rtgui_rect rect;
					struct rtgui_dc* dc;

					dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
					if (dc != RT_NULL)
					{
						/* get widget rect */
						rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
						/* update focus border */
						rect.x2 -= 1; rect.y2 -= 1;
						rtgui_dc_end_drawing(dc);
					}
				}

				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_WIDGET(ctrl), RT_NULL);
						}
					}
				}
			}

			return RT_TRUE;
		}

    case RTGUI_EVENT_KBD:
        {
            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);
					return RT_FALSE;

                case RTGUIK_UP:
					if (ctrl->current_item > 0)
						ctrl->current_item --;
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

				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;
					}
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

                case RTGUIK_DOWN:
					if (ctrl->current_item < ctrl->items_count - 1)
						ctrl->current_item ++;
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

				case RTGUIK_RETURN:
                    if (ctrl->on_item != RT_NULL)
					{
						ctrl->on_item(RTGUI_WIDGET(ctrl), RT_NULL);
					}
					return RT_FALSE;

                default:
                    break;
                }
            }
        }
		return RT_FALSE;
	}

    /* use ctrl event handler */
    return rtgui_widget_event_handler(widget, event);
}
Example #12
0
static void _rtgui_scrollbar_on_mouseclick(rtgui_scrollbar_t *bar, rtgui_event_t * event)
{
	rtgui_rect_t btn_rect, bar_rect,rect;
	rt_uint32_t pos;
	struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;

	RT_ASSERT(bar != RT_NULL);

	/* get value */
	pos = get_scrollbar_pos(bar);

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&rect);

	if(bar->orient == RTGUI_VERTICAL)
	{
		/* arrange vertical */
		/* get up arrow button rect */
		btn_rect.x1 = rect.x1;
		btn_rect.x2 = rect.x2;
		btn_rect.y1 = rect.y1;
		btn_rect.y2 = rect.y1 + rtgui_rect_width(rect);

		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_UPARROW;
				if(bar->value==0)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value -= bar->line_step;
				if(bar->value < 0) bar->value = 0;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				bar->status = 0;
			}
			goto __exit;
		}
		/* click on the thumb chunk, be going to dragging */
		rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
		if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
		{
			/* on thumb */
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				/* changed status into drag */
				bar->status |= SBS_VERTTHUMB;
				sbar_mouse_move_size.x = mouse->x;
				sbar_mouse_move_size.y = mouse->y;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				bar->status = 0;
			}
			goto __exit;
		}
		else
		{
			/* click on space without thumb */
			/* get bar rect */
			bar_rect.y1 = rect.y1 + rtgui_rect_width(rect);
			bar_rect.y2 = rect.y2 - rtgui_rect_width(rect);
			if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
			{
				if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
				{
					/* page step */
					if(mouse->y < bar_rect.y1 + pos)
					{
						bar->status |= SBS_UPSPACE;
						bar->value -= bar->page_step;
						if(bar->value < 0) bar->value = 0;
					}
					else if(mouse->y > pos + bar->thumb_len)
					{
						bar->status |= SBS_DOWNSPACE;
						bar->value += bar->page_step;
						if(bar->value > bar->count) bar->value = bar->count;
					}
				}
				goto __exit;
			}
		}
		/* likewise foregoing */
		/* get down arrow button rect */
		bar_rect.x1 = rect.x1;
		bar_rect.x2 = rect.x2;
		btn_rect.y1 = rect.y2 - rtgui_rect_width(rect);
		btn_rect.y2 = rect.y2;
		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_DOWNARROW;
				if(bar->value==bar->count)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value += bar->line_step;
				if(bar->value > bar->count) bar->value = bar->count;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				bar->status = 0;
			goto __exit;
		}
	}
	else
	{
		/* get left arrow button rect */
		btn_rect.x1 = rect.x1;
		btn_rect.x2 = rect.x1 + rtgui_rect_height(rect);
		btn_rect.y1 = rect.y1;
		btn_rect.y2 = rect.y2;
		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_LEFTARROW;
				if(bar->value==0)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value -= bar->line_step;
				if(bar->value < 0) bar->value = 0;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				bar->status = 0;
			goto __exit;
		}

		rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
		if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
		{
			/* on the thumb */
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_HORZTHUMB;
				sbar_mouse_move_size.x = mouse->x;
				sbar_mouse_move_size.y = mouse->y;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				bar->status = 0;
			}
			goto __exit;
		}
		else
		{
			/* get bar rect */
			bar_rect.x1 = rect.x1 + rtgui_rect_height(rect);
			bar_rect.x2 = rect.x2 - rtgui_rect_height(rect);
			bar_rect.y1 = rect.y1;
			bar_rect.y2 = rect.y2;
			if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
			{
				if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
				{
					/* page step */
					if(mouse->x <  bar_rect.x1 + pos)
					{
						bar->status |= SBS_LEFTSPACE;
						bar->value -= bar->page_step;
						if(bar->value < 0) bar->value = 0;
					}
					else if(mouse->x > pos + bar->thumb_len)
					{
						bar->status |= SBS_RIGHTSPACE;
						bar->value += bar->page_step;
						if(bar->value > bar->count) bar->value = bar->count;
					}
				}
				else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				{
					bar->status = 0;
				}
				goto __exit;
			}
		}
		/* get right arrow button rect */
		btn_rect.x1 = rect.x2 - rtgui_rect_height(rect);
		btn_rect.x2 = rect.x2;
		bar_rect.y1 = rect.y1;
		bar_rect.y2 = rect.y2;
		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_RIGHTARROW;
				if(bar->value==bar->count)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value += bar->line_step;
				if(bar->value > bar->count) bar->value = bar->count;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				bar->status = 0;
			goto __exit;
		}
	}

__exit:
	rtgui_scrollbar_ondraw(bar);
	if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
	{
		if(bar->widget_link != RT_NULL && bar->on_scroll != RT_NULL)
		{
			rtgui_widget_focus(bar->widget_link);
			bar->on_scroll(RTGUI_OBJECT(bar->widget_link), event);
		}
	}
}
Example #13
0
rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
    struct rtgui_widget *widget;
    struct rtgui_filelist_view *view = RT_NULL;

    widget = RTGUI_WIDGET(object);
    view = RTGUI_FILELIST_VIEW(widget);
    switch (event->type)
    {
    case RTGUI_EVENT_PAINT:
        rtgui_filelist_view_ondraw(view);
        return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
    {
        struct rtgui_event_resize *resize;

        resize = (struct rtgui_event_resize *)event;

        /* recalculate page items */
        if (file_image != RT_NULL)
            view->page_items = resize->h  / (1 + rtgui_theme_get_selected_height());
        else
            view->page_items = resize->h / (2 + 14);
        if (view->page_items == 0)
            view->page_items = 1;
    }
    break;

    case RTGUI_EVENT_MOUSE_BUTTON:
    {
        rtgui_rect_t rect;
        struct rtgui_event_mouse *emouse;

        emouse = (struct rtgui_event_mouse *)event;

        /* calculate selected item */

        /* get physical extent information */
        rtgui_widget_get_rect(widget, &rect);
        rtgui_widget_rect_to_device(widget, &rect);

        if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
        {
            rt_uint16_t index;
            rt_uint16_t current_page;
            rt_uint16_t old_item;

            index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

            /* get current page */
            current_page = view->current_item / view->page_items;
            old_item = view->current_item;

            if (index + current_page * view->page_items < view->items_count)
            {
                /* set selected item */
                view->current_item = index + current_page * view->page_items;
                if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
                {
                    rtgui_filelist_view_update_current(view, old_item);
                }
                else
                {
                    /* up event */
                    rtgui_filelist_view_onenturn(view);
                }
            }

            return RT_TRUE;
        }
    }
    break;

    case RTGUI_EVENT_KBD:
    {
        struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
        if (ekbd->type == RTGUI_KEYDOWN)
        {
            rt_uint16_t old_item;

            old_item = view->current_item;
            switch (ekbd->key)
            {
            case RTGUIK_UP:
                if (view->current_item > 0)
                    view->current_item --;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_DOWN:
                if (view->current_item < view->items_count - 1)
                    view->current_item ++;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_LEFT:
                if (view->current_item - view->page_items >= 0)
                    view->current_item -= view->page_items;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_RIGHT:
                if (view->current_item + view->page_items < view->items_count - 1)
                    view->current_item += view->page_items;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_RETURN:
                rtgui_filelist_view_onenturn(view);
                return RT_TRUE;

            default:
                break;
            }
        }
    }
    return RT_FALSE;
    }

    /* use view event handler */
    return rtgui_container_event_handler(object, event);
}
rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_listbox* box = RT_NULL;

	box = RTGUI_LISTBOX(widget);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_listbox_ondraw(box);
		return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
        {
			struct rtgui_event_resize* resize;

			resize = (struct rtgui_event_resize*)event;

            /* recalculate page items */
			box->page_items = resize->h  / (2 + rtgui_theme_get_selected_height());
        }
        break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			rtgui_rect_t rect;
			struct rtgui_event_mouse* emouse;

			emouse = (struct rtgui_event_mouse*)event;

			/* calculate selected item */

			/* get physical extent information */
			rtgui_widget_get_rect(widget, &rect);
			rtgui_widget_rect_to_device(widget, &rect);

			if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) && (box->items_count > 0))
			{
				rt_uint16_t index;
				index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

				/* set focus */
				rtgui_widget_focus(widget);
				{
					struct rtgui_rect rect;
					struct rtgui_dc* dc;

					dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
					if (dc != RT_NULL)
					{
						/* get widget rect */
						rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
						/* update focus border */
						rect.x2 -= 1; rect.y2 -= 1;
						/* draw focused border */
						if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(box)))
							rtgui_dc_draw_focus_rect(dc, &rect);
						rtgui_dc_end_drawing(dc);
					}
				}

				if ((index < box->items_count) && (index < box->page_items))
				{
					rt_uint16_t old_item;

					old_item = box->current_item;

					/* set selected item */
					box->current_item = (box->current_item/box->page_items) * box->page_items + index;
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						/* down event */
						rtgui_listbox_update_current(box, old_item);
					}
					else
					{
						/* up event */
						if (box->on_item != RT_NULL)
						{
							box->on_item(RTGUI_WIDGET(box), RT_NULL);
						}
					}
				}
			}

			return RT_TRUE;
		}

    case RTGUI_EVENT_KBD:
        {
            struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
            if ((ekbd->type == RTGUI_KEYDOWN) && (box->items_count > 0))
            {
				rt_uint16_t old_item;

				old_item = box->current_item;
                switch (ekbd->key)
                {
				case RTGUIK_LEFT:
					if (box->current_item - box->page_items >= 0)
						box->current_item -= box->page_items;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

                case RTGUIK_UP:
					if (box->current_item > 0)
						box->current_item --;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

				case RTGUIK_RIGHT:
					if (box->current_item + box->page_items < box->items_count - 1)
						box->current_item += box->page_items;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

                case RTGUIK_DOWN:
					if (box->current_item < box->items_count - 1)
						box->current_item ++;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

				case RTGUIK_RETURN:
                    if (box->on_item != RT_NULL)
					{
						box->on_item(RTGUI_WIDGET(box), RT_NULL);
					}
					return RT_FALSE;

                default:
                    break;
                }
            }
        }
		return RT_FALSE;
	}

    /* use box event handler */
    return rtgui_widget_event_handler(widget, event);
}
Example #15
0
static void _rtgui_scrollbar_on_mouseclick(struct rtgui_widget * widget, struct rtgui_event * event)
{
	rtgui_rect_t btn_rect, bar_rect;
	rt_uint32_t thumb_size, thumb_position;
    struct rtgui_scrollbar* bar = (struct rtgui_scrollbar*)widget;
    struct rtgui_event_mouse* mouse = (struct rtgui_event_mouse*)event;

	/* get the thumb size and position */
	thumb_size = bar->thumb_size * (bar->max_position - bar->min_position) / _rtgui_scrollbar_get_length(bar);
	thumb_position = _rtgui_scrollbar_get_thumb_position(bar);

    if (bar->orient == RTGUI_VERTICAL)
    {
		/* get up arrow button rect */
		btn_rect.x1 = widget->extent.x1;
		btn_rect.x2 = widget->extent.x2;
		btn_rect.y1 = widget->extent.y1;
		btn_rect.y2 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
        if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
                bar->status |= SBS_UPARROW;

				/* line step */
				bar->thumb_position -= bar->line_step;
				if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
            }
            else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
                bar->status = 0;
			}
			goto __exit;
        }

		/* get bar rect */
		bar_rect.x1 = widget->extent.x1;
		bar_rect.x2 = widget->extent.x2;
		bar_rect.y1 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
		bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
        if (rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
        {
			if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
				/* page step */
				if (mouse->y < bar_rect.y1 + thumb_position)
				{
					bar->thumb_position -= bar->page_step;
					if (bar->thumb_position < bar->min_position)					
						bar->thumb_position = bar->min_position;
				}
				else if (mouse->y > thumb_position + bar->thumb_size)
				{
					bar->thumb_position += bar->page_step;
					if (bar->thumb_position > bar->max_position - thumb_size)
						bar->thumb_position = bar->max_position - thumb_size;
				}
            }
			goto __exit;
        }

		/* get down arrow button rect */
        btn_rect.y1 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
        btn_rect.y2 = widget->extent.y2;
        bar_rect.y1 = widget->extent.y1 + ((widget->extent.y2 - widget->extent.y1)/2);
        bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
        if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
                bar->status |= SBS_DOWNARROW;

				/* line step */
				bar->thumb_position += bar->line_step;
				if (bar->thumb_position > bar->max_position - thumb_size)
					bar->thumb_position = bar->max_position - thumb_size;
            }
            else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
                bar->status = 0;
        }
    }
    else
    {
		/* get left arrow button rect */
		btn_rect.x1 = widget->extent.x1;
		btn_rect.x2 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
		btn_rect.y1 = widget->extent.y1;
		btn_rect.y2 = widget->extent.y2;
        if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
                bar->status |= SBS_LEFTARROW;

				/* line step */
				bar->thumb_position -= bar->line_step;
				if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
            }
             else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
                bar->status = 0;
			goto __exit;
       }

		/* get bar rect */
		bar_rect.x1 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
		bar_rect.x2 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
		bar_rect.y1 = widget->extent.y1;
		bar_rect.y2 = widget->extent.y2;
        if (rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
				/* page step */
				if (mouse->x <  bar_rect.x1 + thumb_position)
				{
					bar->thumb_position -= bar->page_step;
					if (bar->thumb_position < bar->min_position)					
						bar->thumb_position = bar->min_position;
				}
				else if (mouse->x > thumb_position + bar->thumb_size)
				{
					bar->thumb_position += bar->page_step;
					if (bar->thumb_position > bar->max_position - thumb_size)
						bar->thumb_position = bar->max_position - thumb_size;
				}
            }
			goto __exit;
        }

		/* get right arrow button rect */
        btn_rect.x1 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
        btn_rect.x2 = widget->extent.x2;
        bar_rect.x1 = widget->extent.x1 + ((widget->extent.x2 - widget->extent.x1)/2);
        bar_rect.x2 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
        if (rtgui_rect_contains_point(&btn_rect,
                            mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
                bar->status |= SBS_RIGHTARROW;

				/* line step */
				bar->thumb_position += bar->line_step;
				if (bar->thumb_position > bar->max_position - bar->line_step)
					bar->thumb_position = bar->max_position - bar->line_step;
            }
             else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
                bar->status = 0;
        }
    }

__exit:
    rtgui_theme_draw_scrollbar(bar);
	if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
		(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
	{
		if (bar->on_scroll != RT_NULL) bar->on_scroll(widget, RT_NULL);
	}
}
Example #16
0
static rt_bool_t rtgui_list_view_onmouse(struct rtgui_list_view* view, struct rtgui_event_mouse* emouse)
{
	rtgui_rect_t rect;

	/* calculate selected item */

	/* get physical extent information */
	rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);

	if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
	{
		rt_uint16_t index;
		rt_uint16_t old_item;

		/* get old item */
		old_item = view->current_item;

		switch (view->flag)
		{
		case RTGUI_LIST_VIEW_LIST:
			index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

			if ((index < view->items_count) && (index < view->page_items))
			{
				/* set selected item */
				view->current_item = (view->current_item/view->page_items) * view->page_items + index;
				if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
				{
					/* down event */
					rtgui_list_view_update_list(view, old_item);
				}
				else
				{
					/* up event */
					if (view->items[view->current_item].action != RT_NULL)
					{
						view->items[view->current_item].action(view->items[view->current_item].parameter);
					}
				}
			}
			break;

		case RTGUI_LIST_VIEW_ICON:
			{
				rt_uint16_t x, y;
				rt_uint16_t item_height, item_width;
				rt_ubase_t current_page;

				item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN)/view->col_items;
				item_height = (rtgui_rect_height(rect) - 4)/view->row_items;
				x = emouse->x - rect.x1;
				y = emouse->y - rect.y1;

				index = (y / item_height * view->col_items) + x / item_width;
				current_page = view->current_item / view->page_items;

				if ((index + (current_page * view->page_items) < view->items_count))
				{
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						view->current_item = index + (current_page * view->page_items);

						/* down event */
						rtgui_list_view_update_icon(view, old_item);
					}
					else
					{
						/* up event */
						if (view->items[view->current_item].action != RT_NULL)
						{
							view->items[view->current_item].action(view->items[view->current_item].parameter);
						}
					}
				}
			}
			break;

		case RTGUI_LIST_VIEW_REPORT:
			break;
		}

		return RT_TRUE;
	}

	return RT_FALSE;
}
Example #17
0
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
    if (event->type == RTGUI_EVENT_PAINT)
    {
        struct rtgui_dc* dc;
        struct rtgui_rect rect;
        rtgui_image_t *background;

		/* draw child */
		rtgui_view_event_handler(widget, event);

        dc = rtgui_dc_begin_drawing(widget);
        if (dc == RT_NULL) return RT_FALSE;
        rtgui_widget_get_rect(widget, &rect);

        /* draw background */
        background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE);
        if (background != RT_NULL)
        {
            rtgui_image_blit(background, dc, &rect);
            rtgui_image_destroy(background);
        }
        else
        {
            rtgui_dc_fill_rect(dc, &rect);
        }

        /* draw playing information */
		player_update_tag_info();

        rtgui_dc_end_drawing(dc);

        return RT_FALSE;
    }
    else if (event->type == RTGUI_EVENT_KBD)
    {
        struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
        if (ekbd->type == RTGUI_KEYDOWN)
        {
        	if ((ekbd->key == RTGUIK_LEFT) || (ekbd->key == RTGUIK_RIGHT))
        	{
        		if (player_mode == PLAYER_STOP)
        		{
                    rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE);
        		}
        		else
        		{
        			rt_device_t dev = rt_device_find("snd");
        			if (ekbd->key == RTGUIK_LEFT && radio_setup.default_volume > 0)
        			{
        				radio_setup.default_volume--;
        				rt_device_control(dev, CODEC_CMD_VOLUME, &radio_setup.default_volume);
        			}
        			else if (ekbd->key == RTGUIK_RIGHT && radio_setup.default_volume < CODEC_VOLUME_MAX)
        			{
        				radio_setup.default_volume++;
        				rt_device_control(dev, CODEC_CMD_VOLUME, &radio_setup.default_volume);
        			}
        		}
        	}
			else
			{
				return RTGUI_WIDGET(music_listbox)->event_handler(RTGUI_WIDGET(music_listbox), event);
			}
        }
        return RT_FALSE;
    }
	else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
	{
		struct rtgui_event_mouse* emouse;

		emouse = (struct rtgui_event_mouse*)event;
		if (emouse->button & RTGUI_MOUSE_BUTTON_UP)
		{
			if (rtgui_rect_contains_point(&next_btn_rect, emouse->x, emouse->y) == RT_EOK)
				player_onbutton(NEXT_BUTTON);
			else if (rtgui_rect_contains_point(&prev_btn_rect, emouse->x, emouse->y) == RT_EOK)
				player_onbutton(PREV_BUTTON);
			else if (rtgui_rect_contains_point(&playing_btn_rect, emouse->x, emouse->y) == RT_EOK)
				player_onbutton(PLAYING_BUTTON);
		}
	}
    else if (event->type == RTGUI_EVENT_COMMAND)
    {
        struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;

        switch (ecmd->command_id)
        {
        case PLAYER_REQUEST_PLAY_SINGLE_FILE:
        case PLAYER_REQUEST_PLAY_LIST:
            rtgui_timer_start(info_timer);
			return RT_TRUE;

        case PLAYER_REQUEST_STOP:
        {
			struct play_item *item = RT_NULL;

			/* if it's radio mode, set next mode to stop */
			if (player_mode == PLAYER_PLAY_RADIO)
				next_step = PLAYER_STEP_STOP;

			/* set player mode */
			player_mode = PLAYER_STOP;

			switch (next_step)
			{
			case PLAYER_STEP_NEXT:
				/* play next */
				item = play_list_next(play_list_get_mode());
				break;
			case PLAYER_STEP_PREV:
				/* play prev */
				item = play_list_prev(play_list_get_mode());
				break;
			case PLAYER_STEP_SEEK:
				/* play current item */
				item = play_list_current();
			}

			if (item != RT_NULL)
				player_play_item(item);
			else
			{
				player_mode = PLAYER_STOP;
				rtgui_timer_stop(info_timer);
			}

			/* update tag information */
			player_update_tag_info();
        }
		return RT_TRUE;

        case PLAYER_REQUEST_FREEZE:
        {
            /* stop play */
            if (player_is_playing() == RT_TRUE)
            {
                player_stop();
            }

            /* delay some tick */
            rt_thread_delay(50);

            /* show a modal view */
            {
                rtgui_view_t *view;
                rtgui_label_t *label;
                rtgui_rect_t rect = {0, 0, 150, 150}, container_rect;

                rtgui_graphic_driver_get_default_rect(&container_rect);
                /* set centre */
                rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
                view = rtgui_view_create("USB");
                rtgui_workbench_add_view(workbench, view);

                /* set container to window rect */
                container_rect = rect;

                rect.x1 = 0;
                rect.y1 = 0;
                rect.x2 = 120;
                rect.y2 = 20;
                label = rtgui_label_create("USB 联机中...");
                rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
                rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
                rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));

                rtgui_view_show(view, RT_TRUE);
                /* never reach hear */
            }
        }

		case PLAYER_REQUEST_UPDATE_INFO:
			/* update status information */
			player_update_tag_info();
			return RT_TRUE;

        default:
            break;
        }

        return RT_FALSE;
    }

    return rtgui_view_event_handler(widget, event);
}