Пример #1
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;
}
Пример #2
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);
	}
}