Example #1
0
static Ret desktop_on_button_open_applist_clicked(void* ctx, void* obj)
{
	size_t i = 0;
	size_t n = 0;
	size_t item_size = 100;
	FtkWidget* win = NULL;
	AppInfo* app_info = NULL;
	FtkWidget* button = NULL;
	FtkIconViewItem item;
	FtkWidget* icon_view = NULL;

	ftk_source_ref(g_timer);
	ftk_main_loop_remove_source(ftk_default_main_loop(), g_timer);

	if(g_desktop.applist_win != NULL)
	{
		ftk_widget_show_all(g_desktop.applist_win, 1);

		return RET_OK;
	}

	win = desktop_load_xul(g_desktop.is_horizonal ? "xul/appview-h.xul" : "xul/appview-v.xul"); 
	
	button = ftk_widget_lookup(win, 100);
	ftk_button_set_clicked_listener(button, desktop_on_button_close_applist_clicked, win);

	icon_view = ftk_widget_lookup(win, 99);

	item_size = 6 * ftk_widget_get_font_size(icon_view);
	if(ftk_widget_width(icon_view) < 2 * item_size)
	{
		item_size = (ftk_widget_width(icon_view) - 10) / 2;
	}

	ftk_icon_view_set_item_size(icon_view, item_size);
	ftk_icon_view_set_clicked_listener(icon_view, applist_on_item_clicked, win);
	n = app_info_manager_get_count(g_desktop.app_manager);
	
	for(i = 0; i < n; i++)
	{
		app_info_manager_get(g_desktop.app_manager, i, &app_info);
		
		item.icon = ftk_app_get_icon(app_info->app);
		item.user_data = app_info;
		item.text = (char*)ftk_app_get_name(app_info->app);
		if(item.text == NULL)
		{
			item.text = app_info->name;
		}
		ftk_icon_view_add(icon_view, &item);
	}

	g_desktop.applist_win = win;

	return RET_OK;
}
Example #2
0
Ret ftk_wait_box_start_waiting(FtkWidget* thiz)
{
	DECL_PRIV0(thiz, priv);
	return_val_if_fail(priv != NULL, RET_FAIL);
	return_val_if_fail(!priv->waiting, RET_FAIL);

	priv->offset = 0;
	priv->waiting = 1;
	ftk_source_ref(priv->timer);

	return ftk_main_loop_add_source(ftk_default_main_loop(), priv->timer);
}
Example #3
0
static Ret  ftk_wnd_manager_default_dispatch_event(FtkWndManager* thiz, FtkEvent* event)
{
	DECL_PRIV(thiz, priv);
	FtkWidget* target = NULL;
	return_val_if_fail(thiz != NULL && event != NULL, RET_FAIL);

	if(priv->dieing)
	{
		return RET_OK;
	}

	if(event->type == FTK_EVT_KEY_DOWN || event->type == FTK_EVT_KEY_UP)
	{
		ftk_wnd_manager_default_key_translate(thiz, event);
	}

	if(ftk_wnd_manager_dispatch_globals(thiz, event) != RET_OK)
	{
		return RET_REMOVE;
	}

	switch(event->type)
	{
		case FTK_EVT_WND_DESTROY:
		{
			if(priv->top_window == event->widget)
			{
				priv->top_window = NULL;
			}

			priv->disable_anim++;
			ftk_wnd_manager_default_remove(thiz, (FtkWidget*)event->widget);	
			priv->disable_anim--;
			return RET_OK;
		}
		case FTK_EVT_HIDE:
		{
			priv->disable_anim++;
			ftk_wnd_manager_default_emit_top_wnd_changed(thiz);
			priv->disable_anim--;
			ftk_wnd_manager_default_do_animation(thiz, event);
			ftk_wnd_manager_update(thiz);
			return RET_OK;
		}
		case FTK_EVT_SHOW:
		{
			priv->disable_anim++;
			ftk_wnd_manager_default_emit_top_wnd_changed(thiz);
			priv->disable_anim--;
			ftk_wnd_manager_default_do_animation(thiz, event);
			if(ftk_widget_type((FtkWidget*)event->widget) == FTK_WINDOW 
				&& ftk_wnd_manager_default_map_panels(thiz, !ftk_wnd_manager_default_has_fullscreen_win(thiz)) == RET_OK)
			{
				ftk_wnd_manager_update(thiz);
			}
			return RET_OK;
		}
		case FTK_EVT_RELAYOUT_WND:
		{
			ftk_wnd_manager_default_relayout(thiz);
			break;
		}
		default:break;
	}

	if(event->type == FTK_EVT_MOUSE_DOWN || event->type == FTK_EVT_KEY_DOWN)
	{
		priv->pressed_event = *event;
		ftk_source_ref(priv->long_press_timer);
		ftk_source_timer_reset(priv->long_press_timer);
		ftk_main_loop_add_source(ftk_default_main_loop(), priv->long_press_timer);
	}
	
	if(event->type == FTK_EVT_MOUSE_UP|| event->type == FTK_EVT_KEY_UP)
	{
		ftk_main_loop_remove_source(ftk_default_main_loop(), priv->long_press_timer);
	}

	if((event->type == FTK_EVT_MOUSE_DOWN 
		|| event->type == FTK_EVT_MOUSE_UP
		|| event->type == FTK_EVT_MOUSE_MOVE) && priv->grab_widget == NULL)
	{
		int x = event->u.mouse.x;
		int y = event->u.mouse.y;
		
		target = ftk_wnd_manager_find_target(thiz, x, y);
		if(event->type == FTK_EVT_MOUSE_DOWN && !ftk_widget_has_attr(target, FTK_ATTR_NO_FOCUS))
		{
			priv->focus_widget = target;
		}
	}
	else if(event->widget != NULL)
	{
		target = (FtkWidget*)event->widget;
	}
	else if(priv->grab_widget != NULL)
	{
		target = priv->grab_widget;
	}
	else if(priv->focus_widget != NULL)
	{
		target = priv->focus_widget;
	}
	else if(priv->top > 0)
	{
		target = priv->windows[priv->top - 1];
	}

	if(target != NULL && !ftk_widget_is_insensitive(target))
	{
		ftk_widget_ref(target);
		ftk_widget_event(target, event);
		ftk_widget_unref(target);
	}

	return RET_OK;
}
Example #4
0
static Ret  ftk_input_method_hw_handle_event(FtkInputMethod* thiz, FtkEvent* event)
{
	Ret ret = RET_OK;
	DECL_PRIV(thiz, priv);
	return_val_if_fail(priv != NULL && event != NULL, RET_FAIL);
	
	switch(event->type)
	{
		case FTK_EVT_MOUSE_DOWN:
		{
			if(priv->hand_write_state == FTK_HW_NONE)
			{
				priv->hand_write_state = FTK_HW_FIRST;
				ftk_stroke_painter_begin(priv->painter);
			}
			else if(priv->hand_write_state == FTK_HW_FIRST)
			{
				priv->hand_write_state = FTK_HW_WRITING;
			}

			priv->pen_down = 1;
			priv->points_nr = 0;
			
			ftk_source_disable(priv->commit_timer);
			ftk_main_loop_remove_source(ftk_default_main_loop(), priv->commit_timer);
			ret = ftk_input_method_hw_add_point(thiz, event->u.mouse.x, event->u.mouse.y);

			if(priv->hand_write_state == FTK_HW_FIRST)
			{
				ftk_source_timer_reset(priv->click_timer);
				ftk_main_loop_remove_source(ftk_default_main_loop(), priv->click_timer);
				if(ftk_main_loop_add_source(ftk_default_main_loop(), priv->click_timer) == RET_OK)
				{
					ftk_source_ref(priv->click_timer);
				}
			}

			ftk_logd("FTK_EVT_MOUSE_DOWN: %d\n", priv->points_nr);
			break;
		}
		case FTK_EVT_MOUSE_MOVE:
		{
			if(priv->pen_down && priv->hand_write_state != FTK_HW_NONE)
			{
				ret = ftk_input_method_hw_add_point(thiz, event->u.mouse.x, event->u.mouse.y);
			}

			break;
		}
		case FTK_EVT_MOUSE_UP:
		{
			priv->pen_down = 0;
			if(priv->hand_write_state != FTK_HW_NONE)
			{
				ret = ftk_input_method_hw_add_point(thiz, event->u.mouse.x, event->u.mouse.y);

				ftk_source_enable(priv->commit_timer);
				ftk_source_timer_reset(priv->commit_timer);
				if(ftk_main_loop_add_source(ftk_default_main_loop(), priv->commit_timer) == RET_OK)
				{
					ftk_source_ref(priv->commit_timer);
				}
	
				if(priv->points_nr < 5)
				{
					ret = RET_OK;
					break;
				}
				else
				{
					ftk_hand_write_engine_add_stroke(priv->engine, priv->points, priv->points_nr);
				}
			}
			ftk_logd("FTK_EVT_MOUSE_UP: %d\n", priv->points_nr);

			break;
		}
		case FTK_EVT_IM_ACT_COMMIT:
		{
			ftk_input_method_hw_end(thiz);
			ftk_input_method_hw_reset(thiz);

			break;
		}
		default:break;
	}

	return ret;
}