예제 #1
0
static FtkWidget* ftk_file_browser_input_dialog(FtkWidget* thiz, const char* text)
{
	int dialog_width = 0;
	FtkWidget* win = thiz;
	FtkWidget* entry = NULL;
	FtkWidget* button = NULL;
	FtkWidget* dialog = NULL;

	dialog = ftk_dialog_create(0, 0, ftk_widget_width(win) - 20, 150);
	dialog_width = ftk_widget_width(dialog);
	entry = ftk_entry_create(dialog, 10, 20, dialog_width - 20, 20);
	ftk_widget_set_id(entry, ID_ENTRY);
	
	button = ftk_button_create(dialog, dialog_width/2-70, 60, 80, 50);
	ftk_widget_set_text(button, _("OK"));
	ftk_widget_set_id(button, ID_OK);
	ftk_button_set_clicked_listener(button, ftk_file_browser_input_dialog_button_clicked, NULL);

	button = ftk_button_create(dialog, dialog_width/2+10, 60, 80, 50);
	ftk_widget_set_text(button, _("Cancel"));
	ftk_widget_set_id(button, ID_CANCEL);
	ftk_button_set_clicked_listener(button, ftk_file_browser_input_dialog_button_clicked, NULL);
	
	ftk_window_set_focus(dialog, entry);
	ftk_widget_set_text(dialog, text);
	ftk_widget_show_all(dialog, 1);

	return dialog;
}
예제 #2
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;
}
예제 #3
0
static Ret ftk_status_panel_relayout(FtkWidget* thiz)
{
	int x = 0;
	int y = 0;
	int w = 0;
	int h = 0;
	int left = 0;
	int right = 0;
	size_t i = 0;
	
	DECL_PRIV1(thiz, priv);

	y = FTK_PANEL_V_MARGIN;
	h = ftk_widget_height(thiz) - 2 * FTK_PANEL_V_MARGIN;
	right = ftk_widget_width(thiz);

	for(i = 0; i < priv->first_nr; i++)
	{
		w = ftk_widget_width(priv->first[i]);
		if((x + w) > right)
		{
			return RET_OK;
		}
		ftk_widget_move_resize(priv->first[i], x, y, w, h);
		x += w;
	}

	left = x;
	x = right;
	for(i = 0; i < priv->last_nr; i++)
	{
		w = ftk_widget_width(priv->last[i]);
		if((x - w) < left)
		{
			return RET_OK;
		}
		x -= w;
		ftk_widget_move_resize(priv->last[i], x, y, w, h);
	}

	right = x;
	x = left;
	for(i = 0; i < priv->mid_nr; i++)
	{
		w = ftk_widget_width(priv->mid[i]);
		if((x + w) > right)
		{
			return RET_OK;
		}
		ftk_widget_move_resize(priv->mid[i], x, y, w, h);
		x += w;
	}

	return RET_OK;
}
예제 #4
0
FtkWidget* ftk_file_browser_create(FtkFileBrowserType type)
{
	FtkListModel* model = NULL;
	FtkListRender* render = NULL;	
	FtkPrepareOptionsMenu option_menu = NULL;
	FtkWidget* win  = ftk_app_window_create();
	PrivInfo* priv  = FTK_NEW(PrivInfo);
	FtkWidget* list = ftk_list_view_create(win, 0, 0, ftk_widget_width(win), ftk_widget_height(win));

	if(type == FTK_FILE_BROWER_APP)
	{
		option_menu = ftk_file_browser_on_prepare_options_menu;
	}
	else
	{
		option_menu = ftk_file_browser_on_prepare_options_menu_for_choose;
	}
	ftk_app_window_set_on_prepare_options_menu(win, option_menu, win);

	model = ftk_list_model_default_create(10);
	render = ftk_list_render_default_create();

	priv->type = type;
	priv->model = model;
	priv->list_view = list;
	ftk_list_view_init(list, model, render, 40);
	ftk_widget_set_text(win, _("File Browser"));
	ftk_widget_set_user_data(win, priv_info_destroy, priv);
	ftk_list_view_set_clicked_listener(list, ftk_file_browser_on_item_clicked, win);
	ftk_list_render_default_set_marquee_attr(render, 
		FTK_MARQUEE_AUTO | FTK_MARQUEE_RIGHT2LEFT | FTK_MARQUEE_FOREVER);
	ftk_list_model_unref(model);

	return win;
}
예제 #5
0
파일: demo_dialog.c 프로젝트: maxliaops/ftk
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
	int width = 0;
	int height = 0;
	FtkWidget* win = NULL;
	FtkWidget* button = NULL;
	
	FTK_INIT(argc, argv);

	win = ftk_app_window_create();
	ftk_window_set_animation_hint(win, "app_main_window");
	width = ftk_widget_width(win);
	height = ftk_widget_height(win);

	button = ftk_button_create(win, 0, height/6, width/3, 50);
	ftk_widget_set_text(button, "Normal");
	ftk_button_set_clicked_listener(button, button_dialog_clicked, NULL);

	button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
	ftk_widget_set_text(button, "Modal");
	ftk_button_set_clicked_listener(button, button_dialog_clicked, (void*)1);

	button = ftk_button_create(win, width/4, height/2, width/2, 60);
	ftk_widget_set_text(button, "quit");
	ftk_button_set_clicked_listener(button, button_close_clicked, win);

	ftk_widget_set_text(win, "demo dialog");
	ftk_widget_show_all(win, 1);
	FTK_QUIT_WHEN_WIDGET_CLOSE(win);

	FTK_RUN();

	return 0;
}
예제 #6
0
static void create_app_window(void)
{
	char title[32] = {0};
	int width = 0;
	int height = 0;
	FtkWidget* win = ftk_app_window_create();
	FtkWidget* label = NULL;
	FtkWidget* button = NULL;
	
	width = ftk_widget_width(win);
	height = ftk_widget_height(win);

	button = ftk_button_create(win, 0, height/6, width/3, 50);
	ftk_widget_set_text(button, "创建窗口");
	ftk_button_set_clicked_listener(button, button_open_clicked, win);

	button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
	ftk_widget_set_text(button, "关闭窗口");
	ftk_button_set_clicked_listener(button, button_close_clicked, win);

	ftk_snprintf(title, sizeof(title), "window%02d", g_index++);
	label = ftk_label_create(win, width/4, height/2, width/2, 30);
	ftk_widget_set_text(label, title);
	
	ftk_widget_set_text(win, title);
	ftk_widget_show_all(win, 1);
	ftk_widget_set_user_data(win, on_window_close, win);

	return;
}
예제 #7
0
static FtkWidget* ftk_wnd_manager_find_target(FtkWndManager* thiz, int x, int y)
{
	int i = 0;
	int top = 0;
	int left = 0;
	int w = 0;
	int h = 0;
	DECL_PRIV(thiz, priv);
	return_val_if_fail(thiz != NULL && priv->top > 0, NULL);	

	i = priv->top;
	for(; i > 0; i--)
	{
		FtkWidget* win = priv->windows[i-1];
		if(!ftk_widget_is_visible(win) || !ftk_window_is_mapped(win))
		{
			continue;
		}
	
		top = ftk_widget_top_abs(win);
		left = ftk_widget_left_abs(win);
		w = ftk_widget_width(win);
		h = ftk_widget_height(win);

		if(x >= left && y >= top && x < (left  + w)	&& y < (top + h))
		{
			return win;
		}
	}

	return NULL;
}
예제 #8
0
파일: ftk_widget.c 프로젝트: xianjimli/misc
FtkWidget* ftk_widget_find_target(FtkWidget* thiz, int x, int y)
{
	FtkWidget* target = NULL;
	int left = ftk_widget_left_abs(thiz);
	int top  = ftk_widget_top_abs(thiz);
	int w    = ftk_widget_width(thiz);
	int h    = ftk_widget_height(thiz);

	if(x < left || y < top || (x > (left + w)) || (y > (top + h)))
	{
		return NULL;
	} 

	if(thiz->children != NULL)
	{
		FtkWidget* iter = thiz->children;
		while(iter != NULL)
		{
			if((target = ftk_widget_find_target(iter, x, y)) != NULL)
			{
				return target;
			}

			iter = ftk_widget_next(iter);
		}
	}

	return thiz;
}
예제 #9
0
static Ret ftk_key_board_on_event(FtkWidget* thiz, FtkEvent* event)
{
	Ret ret = RET_OK;
	DECL_PRIV0(thiz, priv);

	switch(event->type)
	{
		case FTK_EVT_MOUSE_MOVE:
		case FTK_EVT_MOUSE_DOWN:
		case FTK_EVT_MOUSE_UP:
		{
			size_t x = event->u.mouse.x;
			size_t y = event->u.mouse.y;

			ret = ftk_key_board_on_mouse_event(thiz, event->type, x, y);

			break;
		}
		case FTK_EVT_RESIZE:
		case FTK_EVT_MOVE_RESIZE:
		{
			ftk_key_board_desc_layout(priv->desc, ftk_widget_width(thiz), ftk_widget_height(thiz));
			break;
		}
		default:break;
	}

	return ret;
}
예제 #10
0
static Ret designer_on_duplicate(void* ctx, void* item)
{
	FtkWidget* widget = NULL;
	FtkWidget* win = (FtkWidget*)ctx;
	const WidgetInfo* widget_info = NULL; 
	Info* info = (Info*)ftk_widget_user_data(win);
	
	if(!designer_has_selected_widget(win))
	{
		return RET_OK;
	}

	widget_info = widgets_info_find_by_type(ftk_widget_type(info->selected_widget));
	return_val_if_fail(widget_info != NULL, RET_FAIL);

	if(widget_info->is_leaf_widget)
	{
		widget = widget_info->create(
			ftk_widget_parent(info->selected_widget),
			ftk_widget_left(info->selected_widget),
			ftk_widget_top(info->selected_widget) + ftk_widget_height(info->selected_widget),
			ftk_widget_width(info->selected_widget),
			ftk_widget_height(info->selected_widget));
		ftk_widget_set_text(widget, ftk_widget_get_text(info->selected_widget));
		ftk_widget_show(widget, 1);
		ftk_widget_ref(widget);
		/*TODO: duplicate listview/combobox/iconview*/
	}

	return RET_OK;
}
예제 #11
0
#include "ftk.h"
#include <assert.h>

FtkWidget* text_view1  = NULL;

static Ret button_quit_clicked(void* ctx, void* obj)
{
	ftk_widget_unref(ctx);

	return RET_OK;
}

static Ret scroll_bar_on_scroll(void* ctx, void* scroll_bar)
{
	static int old_at_line = 0;

	int total_lines = ftk_text_view_get_total_lines(text_view1);
	int per = ftk_scroll_bar_get_value(scroll_bar);
	int at_line = total_lines * per / 100;

	if (0 == old_at_line) old_at_line = total_lines;

	int offset = at_line - old_at_line;

	ftk_text_view_v_move_caret(text_view1, offset);

	printf("%s: value=%d, totals = %d, offset = %d\n", __func__, per, total_lines, offset);

	old_at_line = at_line;
	return RET_OK;
}

#define XX_STR  "hahah\n4\n5\n latst"

#define TEXT_STR "libpng is the official PNG reference library. It supports almost all PNG features, is extensible, and has been extensively tested for over 15 years. The home site for development versions (i.e., may be buggy or subject to change or include experimental features) is http://libpng.sourceforge.net/, and the place to go for questions about the library is the png-mng-implement mailing list.\n\nlibpng is available as ANSI C (C89) source code and requires zlib 1.0.4 or later (1.2.3 or later recommended for performance and security reasons). The current public release, libpng 1.4.3, contains fixes for two potential security issues: "

#define TEXT1_STR "Several versions of libpng through 1.4.2 (and through 1.2.43 in the older series) contain a bug whereby progressive applications such as web browsers (or the rpng2 demo app included in libpng) could receive an extra row of image data beyond the height reported in the header, potentially leading to an out-of-bounds write to memory (depending on how the application is written) and the possibility of execution of an attacker's code with the privileges of the libpng user (including remote compromise in the case of a libpng-based browser visiting a hostile web site). This vulnerability has been assigned ID CVE-2010-1205 (via Mozilla). \n\n4\n5\n6\n7\n8\nlast line"

#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_text_view_create()
{
	return ftk_app_demo_create(_("text_view"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
	int width = 0;
	int height = 0;
	FtkWidget* win = NULL;
	FtkWidget* button = NULL;
	FtkWidget* text_view  = NULL;
	FtkWidget* scroll_bar = NULL;

	FTK_INIT(argc, argv);

	win = ftk_app_window_create();
	width = ftk_widget_width(win);
	height = ftk_widget_height(win);
	
	text_view1 = ftk_text_view_create(win, 10, 10, ftk_widget_width(win) - 40, height/3);
	ftk_widget_set_text(text_view1, XX_STR);
	ftk_text_view_set_readonly(text_view1, 1);


	scroll_bar = ftk_scroll_bar_create(win, width-30, 10, 20, height/3);
	ftk_scroll_bar_set_param(scroll_bar, 0, 120, 20);	
	ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
	ftk_scroll_bar_set_value(scroll_bar, 100);


	text_view = ftk_text_view_create(win, 10, 15 + height/3, ftk_widget_width(win) - 20, height/3);
	ftk_widget_set_text(text_view, TEXT_STR);
	assert(strcmp(TEXT_STR, ftk_widget_get_text(text_view)) == 0);
	ftk_text_view_set_readonly(text_view, 1);

	button = ftk_button_create(win, width/4, 3*height/4, width/2, 60);
	ftk_widget_set_text(button, "quit");
	ftk_button_set_clicked_listener(button, button_quit_clicked, win);
	ftk_window_set_focus(win, button);

	ftk_widget_set_text(win, "text_view demo");
	ftk_widget_show_all(win, 1);
	FTK_QUIT_WHEN_WIDGET_CLOSE(win);

	FTK_RUN();

	return 0;
}
예제 #12
0
파일: ftk.c 프로젝트: bbw2008good/ftk
static void ftk_init_panel(void)
{
	FtkGc gc;
	FtkWidget* item = NULL;	
	FtkWidget* panel = ftk_status_panel_create(FTK_STATUS_PANEL_HEIGHT);
	size_t width = ftk_widget_width(panel);

	ftk_set_status_panel(panel);
	quit_if_fail(ftk_default_status_panel(), "Init status panel failed.\n");

	memset(&gc, 0x00, sizeof(gc));
	gc.mask   = FTK_GC_BITMAP;
	gc.bitmap = ftk_theme_load_image(ftk_default_theme(), "status-bg"FTK_STOCK_IMG_SUFFIX);
	ftk_widget_set_gc(panel, FTK_WIDGET_NORMAL, &gc);
	ftk_widget_set_gc(panel, FTK_WIDGET_ACTIVE, &gc);
	ftk_widget_set_gc(panel, FTK_WIDGET_FOCUSED, &gc);
	ftk_gc_reset(&gc);
	
	item = ftk_status_item_create(panel, -100, 32);
	ftk_widget_set_id(item, IDC_CLOSE_ITEM);
	gc.bitmap = ftk_theme_load_image(ftk_default_theme(), "close-32"FTK_STOCK_IMG_SUFFIX);
	if(gc.bitmap != NULL)
	{
		gc.mask = FTK_GC_BITMAP;
		ftk_widget_set_gc(item, FTK_WIDGET_NORMAL, &gc);
		ftk_widget_set_gc(item, FTK_WIDGET_FOCUSED, &gc);
		ftk_gc_reset(&gc);
		gc.mask = FTK_GC_BITMAP;
		gc.bitmap = ftk_theme_load_image(ftk_default_theme(), "close-pressed-32"FTK_STOCK_IMG_SUFFIX);
		ftk_widget_set_gc(item, FTK_WIDGET_ACTIVE, &gc);
		ftk_gc_reset(&gc);
	}
	ftk_status_item_set_clicked_listener(item, button_close_top_clicked, NULL);

	gc.bitmap = ftk_theme_load_image(ftk_default_theme(), "flag-32"FTK_STOCK_IMG_SUFFIX);
	item = ftk_status_item_create(panel, 1, gc.bitmap ? min(ftk_bitmap_width(gc.bitmap), 100) : 32);
	ftk_widget_set_id(item, IDC_ICON_ITEM);
	if(gc.bitmap != NULL)
	{
		gc.mask = FTK_GC_BITMAP;
		ftk_widget_set_gc(item, FTK_WIDGET_NORMAL, &gc);
		ftk_widget_set_gc(item, FTK_WIDGET_ACTIVE, &gc);
		ftk_widget_set_gc(item, FTK_WIDGET_FOCUSED, &gc);
		ftk_gc_reset(&gc);
	}
	ftk_widget_show(item, 1);

	item = ftk_status_item_create(panel, 2, width/2);
	ftk_widget_set_id(item, IDC_TITLE_ITEM);
	ftk_widget_show(item, 1);

	ftk_wnd_manager_add_global_listener(ftk_default_wnd_manager(), on_wnd_manager_global_event, NULL);
	ftk_widget_show(panel, 1);
	
	return;
}
예제 #13
0
Ret designer_select_file(const char* title, const char* init_path, FtkListener on_select, void* ctx)
{
	int width = 0;
	int height = 0;
	int y_offset = 0;
	
	Info* info = NULL;
	FtkWidget* win = NULL;
	FtkWidget* label = NULL;
	FtkWidget* entry = NULL;	
	FtkWidget* button = NULL;
	
	info = info_create();
	return_val_if_fail(info != NULL, RET_FAIL);

	win = ftk_app_window_create();
	ftk_widget_set_user_data(win, info_destroy, info);
	ftk_widget_set_text(win, title);
	
	width = ftk_widget_width(win);
	height = ftk_widget_height(win);

	info->on_select = on_select;
	info->on_select_ctx = ctx;
	info->init_path = ftk_strdup(init_path);

	y_offset = height/3 - 30;
	label = ftk_label_create(win, 0, y_offset, width/5, 30);
	ftk_widget_set_text(label, _("FileName:"));
	
	y_offset = height/3;
	info->widget_file_name = entry = ftk_entry_create(win, 5, y_offset, width*4/5-2, 30);
	if(s_last_file[0] == '\0')
	{
		ftk_fs_get_cwd(s_last_file);
	}
	ftk_widget_set_text(entry, s_last_file);
	
	button = ftk_button_create(win, width*4/5, y_offset-5, width/5, 40);
	ftk_widget_set_text(button, _("..."));
	ftk_button_set_clicked_listener(button, button_browse_clicked, win);

	button = ftk_button_create(win, width/5, height-60, width/5, 50);
	ftk_widget_set_text(button, _("OK"));
	ftk_button_set_clicked_listener(button, button_ok_clicked, win);

	button = ftk_button_create(win, width*3/5, height-60, width/5, 50);
	ftk_widget_set_text(button, _("Cancel"));
	ftk_button_set_clicked_listener(button, button_cancel_clicked, win);
	
	ftk_widget_show_all(win, 1);

	return RET_OK;
}
예제 #14
0
파일: demo_dialog.c 프로젝트: maxliaops/ftk
static Ret button_dialog_clicked(void* ctx, void* obj)
{
	int id = 0;
	int width = 0;
	int height = 0;
//	FtkWidget* label = NULL;
	FtkWidget* button = NULL;
	FtkWidget* dialog = NULL;
	FtkBitmap* icon = NULL;
	FtkWidget* combo_box = NULL;
	int modal = (int)ctx;
	
	ftk_logi("%s:%d begin\n", __func__, __LINE__);
	dialog = ftk_dialog_create(0, 40, 320, 240);
	
	icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX);
	ftk_dialog_set_icon(dialog, icon);

	width = ftk_widget_width(dialog);
	height = ftk_widget_height(dialog);
//	label = ftk_label_create(dialog, width/6, height/4, 5*width/6, 20);
//	ftk_widget_set_text(label, "Are you sure to quit?");
	
	combo_box = ftk_combo_box_create(dialog, width/6, height/4, 2*width/3, 30);
	ftk_combo_box_set_text(combo_box, "1 second");
	ftk_combo_box_append(combo_box, NULL, "1 second");
	ftk_combo_box_append(combo_box, NULL, "2 seconds");
	ftk_combo_box_append(combo_box, NULL, "3 seconds");
	ftk_entry_set_readonly(ftk_combo_box_get_entry(combo_box), modal);

	button = ftk_button_create(dialog, width/6, height/2, width/3, 50);
	ftk_widget_set_text(button, "yes");
	ftk_button_set_clicked_listener(button, button_quit_clicked, modal ? &id : NULL);
	
	button = ftk_button_create(dialog, width/2, height/2, width/3, 50);
	ftk_widget_set_text(button, "no");
	ftk_button_set_clicked_listener(button, button_quit_clicked, modal ? &id : NULL);
	ftk_window_set_focus(dialog, button);

	ftk_widget_set_text(dialog, modal ? "model dialog" : "normal dialog");

	if(modal)
	{
		assert(ftk_dialog_run(dialog) == id);
		ftk_widget_unref(dialog);
	}
	else
	{
		ftk_widget_show_all(dialog, 1);
	}
	ftk_logi("%s:%d end\n", __func__, __LINE__);

	return RET_OK;
}
예제 #15
0
파일: demo_image.c 프로젝트: htbegin/pyftk
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
	FtkWidget* image = NULL;
	FtkWidget* win = NULL;
	char filename[FTK_MAX_PATH+1] = {0};
	FTK_INIT(argc, argv);
	
	win = ftk_app_window_create();
	ftk_window_set_animation_hint(win, "app_main_window");

	ftk_snprintf(filename, FTK_MAX_PATH, "%s/earth.png", 
		ftk_config_get_test_data_dir(ftk_default_config()));

	image = ftk_image_create(win, 0, 0, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
	ftk_image_set_image(image, 
		ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
	
	ftk_snprintf(filename, FTK_MAX_PATH, "%s/png_RGB_tRNS.png", 
		ftk_config_get_test_data_dir(ftk_default_config()));
	image = ftk_image_create(win, 0, 0, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
	ftk_image_set_image(image, 
		ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
	ftk_widget_set_attr(image, FTK_ATTR_TRANSPARENT);

	ftk_snprintf(filename, FTK_MAX_PATH, "%s/Calculator.png", 
		ftk_config_get_test_data_dir(ftk_default_config()));
	image = ftk_image_create(win, ftk_widget_width(win)/2, 0, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
	ftk_image_set_image(image, 
		ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
	ftk_widget_set_attr(image, FTK_ATTR_BG_TILE);

	ftk_snprintf(filename, FTK_MAX_PATH, "%s/t8.bmp", 
		ftk_config_get_test_data_dir(ftk_default_config()));
	image = ftk_image_create(win, 0, ftk_widget_height(win)/2, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
	ftk_image_set_image(image, 
		ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
	ftk_widget_set_attr(image, FTK_ATTR_BG_CENTER);
	
	ftk_snprintf(filename, FTK_MAX_PATH,  "%s/jpeg1.jpg", 
		ftk_config_get_test_data_dir(ftk_default_config()));
	image = ftk_image_create(win, ftk_widget_width(win)/2, ftk_widget_height(win)/2, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
	ftk_image_set_image(image, 
		ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
	ftk_widget_set_attr(image, FTK_ATTR_BG_TILE);

	ftk_widget_set_text(win, "image demo");
	ftk_widget_show_all(win, 1);
	
	FTK_QUIT_WHEN_WIDGET_CLOSE(win);

	FTK_RUN();

	return 0;
}
예제 #16
0
static Ret button_fullscreen_clicked(void* ctx, void* obj)
{
	if(ftk_window_is_fullscreen(ctx))
	{
		ftk_infomation("Infomation", "Windows is fullscreen.", buttons);
	}
	else
	{
		ftk_window_set_fullscreen(ctx, 1);
	}

	ftk_logd("%s: width=%d height=%d\n", __func__, ftk_widget_width(ctx), ftk_widget_height(ctx));
	return RET_OK;
}
예제 #17
0
Ret ftk_key_board_load(FtkWidget* thiz, const char* filename)
{
	DECL_PRIV0(thiz, priv);
	
	return_val_if_fail(thiz != NULL && filename != NULL && priv->desc == NULL, RET_FAIL);
	
	priv->desc = ftk_key_board_desc_create(filename);
	return_val_if_fail(priv->desc != NULL, RET_FAIL);

	priv->desc->current_view = 0;
	ftk_key_board_desc_layout(priv->desc, ftk_widget_width(thiz), ftk_widget_height(thiz));
	ftk_widget_invalidate(thiz);

	return RET_OK;
}
예제 #18
0
파일: demo_bidi.c 프로젝트: bbw2008good/ftk
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
	int width = 0;
	int height = 0;
	FtkGc gc = {.mask = FTK_GC_BG};
	TimerInfo* info = NULL;

	FTK_INIT(argc, argv);
	info = (TimerInfo*)FTK_ZALLOC(sizeof(TimerInfo));
	info->times = 100;
		
	FtkSource* timer = ftk_source_timer_create(1000, timeout, info);
	FtkWidget* win = ftk_app_window_create();
	ftk_window_set_animation_hint(win, "app_main_window");

	width = ftk_widget_width(win);
	height = ftk_widget_height(win);

	FtkWidget* label = ftk_label_create(win, 10, 10, width - 20, 20);
	ftk_widget_set_text(label, "arabic bidi demo");
	
	label = ftk_label_create(win, 10, 40, width - 20, 20);
	ftk_widget_set_text(label, "English Text");
	assert(strcmp(ftk_widget_get_text(label), "English Text") == 0);
	
	gc.bg.a = 0xff;
	gc.bg.r = 0xF0;
	gc.bg.g = 0xF0;
	gc.bg.b = 0x80;
	label = ftk_label_create(win, 10, height/2, width - 20, 120);
	ftk_widget_set_gc(label, FTK_WIDGET_INSENSITIVE, &gc);
	ftk_widget_unset_attr(label, FTK_ATTR_TRANSPARENT);
	ftk_widget_set_text(label, "ان منح حياتك للمسيح تعد خطوة ايمان يمكنك القيام بها عن طريق الصلاة");
	
	label = ftk_label_create(win, 50, height/2-30, width, 20);
	info->label = label;
	
	ftk_widget_set_text(win, "label demo");
	ftk_widget_show_all(win, 1);

	ftk_widget_set_attr(win, FTK_ATTR_IGNORE_CLOSE);
	ftk_main_loop_add_source(ftk_default_main_loop(), timer);

	FTK_RUN();

	return 0;
}
예제 #19
0
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
	int width = 0;
	int height = 0;
	FtkWidget* win = NULL;
	FtkWidget* button = NULL;
	FtkWidget* icon_view = NULL;
	FtkIconViewItem item;
	FTK_INIT(argc, argv);
	
	win = ftk_app_window_create();
	ftk_window_set_animation_hint(win, "app_main_window");
	width = ftk_widget_width(win);
	height = ftk_widget_height(win);

	button = ftk_button_create(win, 10, 0, width/3-10, 60);
	ftk_widget_set_text(button, "more");
	ftk_button_set_clicked_listener(button, button_more_clicked, win);
	ftk_window_set_focus(win, button);
	
	button = ftk_button_create(win, 2*width/3, 0, width/3-10, 60);
	ftk_widget_set_text(button, "quit");
	ftk_button_set_clicked_listener(button, button_quit_clicked, win);
	ftk_window_set_focus(win, button);

	item.icon = ftk_theme_load_image(ftk_default_theme(), "flag-32.png");
	icon_view = ftk_icon_view_create(win, 5, 70, width-10, height-80);
	ftk_widget_set_id(icon_view, 100);
	ftk_icon_view_set_clicked_listener(icon_view, item_clicked, win);
	for(; i < 4; i++)
	{
		char text[100] = {0};
		ftk_snprintf(text, sizeof(text), "%d", i);
		item.text = text;
		item.user_data = (void*)i;
		ftk_icon_view_add(icon_view, &item);
	}
	
	ftk_bitmap_unref(item.icon);
	ftk_widget_set_text(win, "icon view demo");
	ftk_widget_show_all(win, 1);
	FTK_QUIT_WHEN_WIDGET_CLOSE(win);

	FTK_RUN();

	return 0;
}
예제 #20
0
static Ret designer_move_widget(FtkWidget* widget, int x, int y, int w, int h)
{
	int parent_w = ftk_widget_width(ftk_widget_parent(widget));
	int parent_h = ftk_widget_height(ftk_widget_parent(widget));
	const WidgetInfo* widget_info = widgets_info_find_by_type(ftk_widget_type(widget));

	return_val_if_fail(widget_info != NULL, RET_OK);

	x = x >= 0 ? x : 0;
	y = y >= 0 ? y : 0;

	w = FTK_MAX(w, widget_info->min_width);
	h = FTK_MAX(h, widget_info->min_height);

	if((x + w) < parent_w && (y + h) < parent_h)
	{
		ftk_widget_move_resize(widget, x, y, w, h);
	}

	return RET_OK;
}
예제 #21
0
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
	int width = 0;
	int height = 0;
	FtkWidget* win = NULL;
	FtkWidget* button = NULL;

	FTK_INIT(argc, argv);
	
	win = ftk_app_window_create();
	ftk_window_set_animation_hint(win, "app_main_window");
	width = ftk_widget_width(win);
	height = ftk_widget_height(win);
	
	width = width/2 - 10;
	button = ftk_button_create(win, 0, height/4, width, 50);
	ftk_widget_set_text(button, "Single Choose");
	ftk_button_set_clicked_listener(button, button_single_choose_clicked, win);

	button = ftk_button_create(win, width + 10, height/4, width, 50);
	ftk_widget_set_text(button, "Browser");
	ftk_button_set_clicked_listener(button, button_browser_clicked, win);
	
	button = ftk_button_create(win, 0, height/2, width, 50);
	ftk_widget_set_text(button, "Multi Choose");
	ftk_button_set_clicked_listener(button, button_multi_choose_clicked, win);

	button = ftk_button_create(win, width + 10, height/2, width, 50);
	ftk_widget_set_text(button, "Quit");
	ftk_button_set_clicked_listener(button, button_quit_clicked, win);
	ftk_window_set_focus(win, button);

	ftk_widget_set_text(win, "FileBrowser");
	ftk_widget_show_all(win, 1);
	FTK_QUIT_WHEN_WIDGET_CLOSE(win);

	FTK_RUN();

	return 0;
}
예제 #22
0
static Ret designer_on_mouse_event(FtkWidget* win, int press, int x, int y)
{
	Info* info = (Info*)ftk_widget_user_data(win);

	if(press == 1)
	{
		info->last_x = x;
		info->last_y = y;
		info->mouse_down = 1;
		info->selected_widget = ftk_widget_find_target(win, info->last_x, info->last_y, 0);
	}
	else if(press == 0)
	{
		info->mouse_down = 0;
	}
	else
	{
		int w = 0;
		int h = 0;
		int x_offset = x - info->last_x;
		int y_offset = y - info->last_y;
		
		if(!designer_has_selected_widget(win) || !info->mouse_down)
		{
			return RET_OK;
		}
	
		info->last_x = x;
		info->last_y = y;
		x = ftk_widget_left(info->selected_widget) + x_offset;
		y = ftk_widget_top(info->selected_widget) + y_offset;
		w = ftk_widget_width(info->selected_widget);
		h = ftk_widget_height(info->selected_widget);

		designer_move_widget(info->selected_widget, x, y, w, h);
	}

	return RET_OK;
}
예제 #23
0
파일: demo_wait_box.c 프로젝트: caicha/ftk
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
    int width = 0;
    int height = 0;
    FtkWidget* win = NULL;
    FtkWidget* button = NULL;
    FtkWidget* wait_box = NULL;

    FTK_INIT(argc, argv);

    win = ftk_app_window_create();
    width = ftk_widget_width(win);
    height = ftk_widget_height(win);

    wait_box = ftk_wait_box_create(win, width/2 - 16, height/4, 0, 0);

    button = ftk_button_create(win, 0, height/2, width/3, 50);
    ftk_widget_set_text(button, "start");
    ftk_button_set_clicked_listener(button, button_start_clicked, wait_box);

    button = ftk_button_create(win, 2*width/3, height/2, width/3, 50);
    ftk_widget_set_text(button, "stop");
    ftk_button_set_clicked_listener(button, button_stop_clicked, wait_box);

    button = ftk_button_create(win, width/4, 3*height/4, width/2, 60);
    ftk_widget_set_text(button, "quit");
    ftk_button_set_clicked_listener(button, button_quit_clicked, win);
    ftk_window_set_focus(win, button);

    ftk_widget_set_text(win, "wait_box demo");
    ftk_widget_show_all(win, 1);
    FTK_QUIT_WHEN_WIDGET_CLOSE(win);

    FTK_RUN();

    return 0;
}
예제 #24
0
#include "ftk.h"

static Ret on_prepare_options_menu(void* ctx, FtkWidget* menu_panel)
{
	int i = 0;
	for(i = 0; i < 3; i++)
	{
		char text[32] = {0};
		FtkWidget* item = ftk_menu_item_create(menu_panel);
		ftk_snprintf(text, sizeof(text), "Menu%02d", i);
		ftk_widget_set_text(item, text);
		ftk_widget_show(item, 1);
	}

	return i > 0 ? RET_OK : RET_FAIL;
}
#define IDC_TEST_BUTTON 1000
static Ret button_quit_clicked(void* ctx, void* obj)
{
	ftk_widget_unref(ctx);

	return RET_OK;
}

static const char* buttons[] = {"OK", NULL};
static Ret button_unfullscreen_clicked(void* ctx, void* obj)
{
	if(!ftk_window_is_fullscreen(ctx))
	{
		ftk_infomation("Infomation", "Windows is not fullscreen.", buttons);
	}
	else
	{
		ftk_window_set_fullscreen(ctx, 0);
	}
	ftk_logd("%s: width=%d height=%d\n", __func__, ftk_widget_width(ctx), ftk_widget_height(ctx));

	return RET_OK;
}

static Ret button_fullscreen_clicked(void* ctx, void* obj)
{
	if(ftk_window_is_fullscreen(ctx))
	{
		ftk_infomation("Infomation", "Windows is fullscreen.", buttons);
	}
	else
	{
		ftk_window_set_fullscreen(ctx, 1);
	}

	ftk_logd("%s: width=%d height=%d\n", __func__, ftk_widget_width(ctx), ftk_widget_height(ctx));
	return RET_OK;
}

#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_fullscreen_create()
{
	return ftk_app_demo_create(_("fullscreen"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
	int width = 0;
	int height = 0;
	FtkWidget* win = NULL;
	FtkWidget* button = NULL;

	FTK_INIT(argc, argv);
	
	win = ftk_app_window_create();
	ftk_window_set_animation_hint(win, "app_main_window");
	width = ftk_widget_width(win);
	height = ftk_widget_height(win);
	
	width = width/2 - 10;
	button = ftk_button_create(win, 0, height/4, width, 50);
	ftk_widget_set_text(button, "Fullscreen");
	ftk_button_set_clicked_listener(button, button_fullscreen_clicked, win);

	button = ftk_button_create(win, width + 10, height/4, width, 50);
	ftk_widget_set_text(button, "Unfullscreen");
	ftk_button_set_clicked_listener(button, button_unfullscreen_clicked, win);
	
	button = ftk_button_create(win, width/2, height/2, width, 60);
	ftk_widget_set_text(button, "quit");
	ftk_button_set_clicked_listener(button, button_quit_clicked, win);
	ftk_window_set_focus(win, button);

	ftk_widget_set_text(win, "fullscreen");
	ftk_widget_show_all(win, 1);
	FTK_QUIT_WHEN_WIDGET_CLOSE(win);
	ftk_app_window_set_on_prepare_options_menu(win, on_prepare_options_menu, win);

	FTK_RUN();

	return 0;
}
예제 #25
0
static Ret ftk_scroll_bar_on_event(FtkWidget* thiz, FtkEvent* event)
{
	int x = 0;
	int y = 0;
	Ret ret = RET_OK;
	DECL_PRIV0(thiz, priv);

	if(priv->page_delta == priv->max_value)
	{
		/*one page, no scroll*/
		return RET_OK;
	}

	switch(event->type)
	{
		case FTK_EVT_KEY_DOWN:
		{
			if(event->u.key.code == FTK_KEY_DOWN)
			{
				ftk_scroll_bar_inc(thiz);
				ret = RET_REMOVE;
			}
			else if(event->u.key.code == FTK_KEY_UP)
			{
				ftk_scroll_bar_dec(thiz);
				ret = RET_REMOVE;
			}
			else if(event->u.key.code == FTK_KEY_PAGEDOWN)
			{
				ftk_scroll_bar_pagedown(thiz);
			}
			else if(event->u.key.code == FTK_KEY_PAGEUP)
			{
				ftk_scroll_bar_pageup(thiz);
			}
			break;
		}
		case FTK_EVT_MOUSE_DOWN:
		{
			int pos = 0;
			int value = 0;

			x = event->u.mouse.x;
			y = event->u.mouse.y;

			priv->mouse_pressed = 1;
			ftk_window_grab(ftk_widget_toplevel(thiz), thiz);

			pos = priv->vertical ? y : x;
			priv->drag_enabled = pos >= priv->tracker_pos && pos < (priv->tracker_pos + priv->tracker_size);

			if(!priv->drag_enabled)
			{
				value = pos < priv->tracker_pos ? priv->value - priv->page_delta : priv->value + priv->page_delta;
				ftk_scroll_bar_set_value(thiz, value);
			}
		
			priv->last_mouse_pos = pos;

			break;
		}
		case FTK_EVT_MOUSE_MOVE:
		{
			int pos = 0;
			int delta =0;
			int value = 0;
			int width = 0;
			int height = 0;
			
			if(!priv->drag_enabled) break;
			
			x = event->u.mouse.x;
			y = event->u.mouse.y;
			pos = priv->vertical ? y : x;
			delta = pos - priv->last_mouse_pos;

			width = ftk_widget_width(thiz);
			height = ftk_widget_height(thiz);

			value = priv->vertical ? priv->max_value * delta/height : priv->max_value * delta/width;

			if(value != 0)
			{
				value += priv->value;
				priv->last_mouse_pos = pos;
				ftk_scroll_bar_set_value(thiz, value);
			}

			break;
		}
		case FTK_EVT_MOUSE_UP:
		{
			priv->drag_enabled = 0;
			priv->mouse_pressed = 0;
			ftk_window_ungrab(ftk_widget_toplevel(thiz), thiz);

			break;
		}
		default:break;
	}

	return ret;
}
예제 #26
0
int ftk_message_box(FtkBitmap* icon, const char* title, const char* text, const char* buttons[FTK_MSGBOX_MAX_BUTTONS])
{
	int i = 0;
	int w = 0;
	int h = 0;
	int id = 0;
	int ret = 0;
	int width = 0;
	int height = 0;
	int xoffset = 0;
	int yoffset = 0;
	int h_margin = 0;
	int has_title = icon != NULL || title != NULL;
	int buttons_nr = ftk_count_strings(buttons);

	FtkWidget* label = NULL;
	FtkWidget* button = NULL;
	FtkWidget* dialog = NULL;
	
	return_val_if_fail(text != NULL, -1);

	ftk_message_box_size(has_title, buttons_nr, text, &width, &height);
	dialog = ftk_dialog_create(0, 0, width, height);
	ftk_window_set_animation_hint(dialog, "msgbox");
	if(has_title) 
	{
		ftk_dialog_set_icon(dialog, icon);
		ftk_widget_set_text(dialog, title);
	}
	else
	{
		ftk_dialog_hide_title(dialog);
		ftk_widget_set_attr(dialog, FTK_ATTR_POPUP);
	}

	width  = ftk_widget_width(dialog);
	height = ftk_widget_height(dialog);

	/*create label.*/
	xoffset = FTK_H_MARGIN;
	yoffset = FTK_V_MARGIN;
	w = width - 2 * (FTK_DIALOG_BORDER + FTK_H_MARGIN);
	h = height - FTK_DIALOG_BORDER - 4 * FTK_V_MARGIN;
	h -= has_title ? ftk_dialog_get_title_height() : 0;
	h -= buttons_nr > 0 ? FTK_BUTTON_DEFAULT_HEIGHT : 0;

	label = ftk_label_create(dialog, xoffset, yoffset, w, h);
	ftk_widget_set_text(label, text);

	/*create buttons*/

	if(buttons_nr > 0)
	{
		xoffset = 0;
		w = FTK_BUTTON_DEFAULT_WIDTH;
		h = FTK_BUTTON_DEFAULT_HEIGHT;
		w = ((buttons_nr + 1) * w) < width ? w : (width / (buttons_nr + 1));
		yoffset = height - h - FTK_V_MARGIN - (has_title ? ftk_dialog_get_title_height() : 0);
		h_margin = (width - buttons_nr * w) / (buttons_nr + 1);

		for(i = 0; i < buttons_nr; i++)
		{
			xoffset += h_margin;
			button = ftk_button_create(dialog, xoffset, yoffset, w, h);
			ftk_widget_set_id(button, i + 1);
			ftk_widget_set_text(button, buttons[i]);
			ftk_button_set_clicked_listener(button, message_box_on_button_clicked, &id);
			xoffset += w;
		}
	}
	else
	{
		/*if no buttons, quit when timeout.*/
		ftk_dialog_quit_after(dialog, 3000);
	}

	ftk_widget_show_all(dialog, 1);
	ret = ftk_dialog_run(dialog);
	ftk_widget_unref(dialog);
	
	if(icon != NULL)
	{
		ftk_bitmap_unref(icon);
	}

	return ret;
}
예제 #27
0
파일: demo_label.c 프로젝트: htbegin/pyftk
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
	int width = 0;
	int height = 0;
	FtkGc gc = {0};
	TimerInfo* info = NULL;
	FtkSource* timer = NULL;
	FtkWidget* win = NULL;
	FtkWidget* label = NULL;

	gc.mask = FTK_GC_BG;

	FTK_INIT(argc, argv);
	info = (TimerInfo*)FTK_ZALLOC(sizeof(TimerInfo));
	info->times = 5;
		
	timer = ftk_source_timer_create(1000, timeout, info);
	win = ftk_app_window_create();
	ftk_window_set_animation_hint(win, "app_main_window");

	width = ftk_widget_width(win);
	height = ftk_widget_height(win);

#ifdef WIN32	
	label = ftk_label_create(win, 10, 10, width - 20, 20);
	ftk_widget_set_text(label, "中文文本");
#else
#endif
	label = ftk_label_create(win, 10, 40, width - 20, 20);
	ftk_widget_set_text(label, "English Text(center)");
	ftk_label_set_alignment(label, FTK_ALIGN_CENTER);
	assert(strcmp(ftk_widget_get_text(label), "English Text(center)") == 0);
	
	label = ftk_label_create(win, 10, 70, width - 20, 20);
	ftk_widget_set_text(label, "English Text(right)");
	ftk_label_set_alignment(label, FTK_ALIGN_RIGHT);

	gc.bg.a = 0xff;
	gc.bg.r = 0xF0;
	gc.bg.g = 0xF0;
	gc.bg.b = 0x80;
	label = ftk_label_create(win, 10, height/2, width - 20, 120);
	ftk_widget_set_gc(label, FTK_WIDGET_INSENSITIVE, &gc);
	ftk_widget_unset_attr(label, FTK_ATTR_TRANSPARENT);
#ifdef WIN32	
	ftk_widget_set_text(label, "The linux mobile development(with background color)");
#else
	ftk_widget_set_text(label, "中英文混合多行文本显示:the linux mobile development.带有背景颜色。");
#endif
	label = ftk_label_create(win, 50, height/2-30, width, 20);
	info->label = label;
	
	ftk_widget_set_text(win, "label demo");
	ftk_widget_show_all(win, 1);

	ftk_widget_set_attr(win, FTK_ATTR_IGNORE_CLOSE);
	ftk_main_loop_add_source(ftk_default_main_loop(), timer);

	FTK_RUN();

	return 0;
}
예제 #28
0
static  Ret designer_handle_direction_key(FtkWidget* win, int press, int code)
{
	int x = 0;
	int y = 0;
	int w = 0;
	int h = 0;
	Ret ret = RET_OK;
	Info* info = (Info*)ftk_widget_user_data(win);

	x = ftk_widget_left(info->selected_widget);
	y = ftk_widget_top(info->selected_widget);
	w = ftk_widget_width(info->selected_widget);
	h = ftk_widget_height(info->selected_widget);
	
	switch(code)
	{
		case FTK_KEY_UP:
		{
			if(info->ctrl_down)
			{
				y--;
			}

			if(info->alt_down)
			{
				h--;
			}

			break;
		}
		case FTK_KEY_DOWN:
		{
			if(info->ctrl_down)
			{
				y++;
			}

			if(info->alt_down)
			{
				h++;
			}

			break;
		}
		case FTK_KEY_LEFT:
		{
			if(info->ctrl_down)
			{
				x--;
			}

			if(info->alt_down)
			{
				w--;
			}

			break;
		}
		case FTK_KEY_RIGHT:
		{
			if(info->ctrl_down)
			{
				x++;
			}

			if(info->alt_down)
			{
				w++;
			}

			break;
		}
		default:break; 
	}

	if(info->ctrl_down || info->alt_down)
	{
		designer_move_widget(info->selected_widget, x, y, w, h);
		ret = RET_REMOVE;
	}

	return ret;
}
예제 #29
0
static Ret  ftk_wnd_manager_default_relayout_one(FtkWndManager* thiz, FtkWidget* window)
{
	int x = 0;
	int y = 0;
	int w = 0;
	int h = 0;
	int work_area_h = 0;
	FtkEvent event;
	return_val_if_fail(thiz != NULL && window != NULL, RET_FAIL);

	work_area_h = ftk_display_height(ftk_default_display()) - ftk_wnd_manager_get_status_bar_height(thiz);
	/*XXX: we assume panel is added as first window*/
	switch(ftk_widget_type(window))
	{
		case FTK_WINDOW:
		{
			w = ftk_display_width(ftk_default_display());
			h = ftk_display_height(ftk_default_display());

			if(!ftk_window_is_fullscreen(window))
			{
				h -= ftk_wnd_manager_get_status_bar_height(thiz);
				y = ftk_wnd_manager_get_status_bar_height(thiz);
			}

			break;
		}
		case FTK_DIALOG:
		{
			if(ftk_widget_has_attr(window, FTK_ATTR_AUTO_LAYOUT))
			{
				x = FTK_DIALOG_MARGIN;
				w = ftk_display_width(ftk_default_display()) - FTK_DIALOG_MARGIN * 2; 
				h = work_area_h < ftk_widget_height(window) ? work_area_h : ftk_widget_height(window);
				y = (work_area_h - h) / 2;
				
				if(!ftk_wnd_manager_default_has_fullscreen_win(thiz))
				{
					y += ftk_wnd_manager_get_status_bar_height(thiz);
				}
			}
			else
			{
				x = ftk_widget_left_abs(window);
				y = ftk_widget_top_abs(window);
				w = ftk_widget_width(window);
				h = ftk_widget_height(window);
			}
			break;
		}
		case FTK_STATUS_PANEL:
		{
			ftk_event_init(&event, FTK_EVT_MAP);
			event.widget = window;
			ftk_wnd_manager_dispatch_event(thiz, &event);
			w = ftk_display_width(ftk_default_display());
			h = FTK_STATUS_PANEL_HEIGHT;

			break;
		}
		case FTK_MENU_PANEL:
		{
			ftk_event_init(&event, FTK_EVT_MAP);
			event.widget = window;
			ftk_wnd_manager_dispatch_event(thiz, &event);
			w = ftk_display_width(ftk_default_display());
			h = ftk_widget_height(window);
			x = 0;
			y = ftk_display_height(ftk_default_display()) - h;

			break;
		}
		default:
		{
			x = ftk_widget_left_abs(window);
			y = ftk_widget_top_abs(window);
			w = ftk_widget_width(window);
			h = ftk_widget_height(window);

			break;
		}
	}
	
	ftk_widget_move_resize(window, x, y, w, h);
	ftk_logd("type=%d %d %d %d %d\n", ftk_widget_type(window), x, y, w, h);

	return RET_OK;
}
예제 #30
0
static Ret ftk_progress_bar_on_event_interactive(FtkWidget* thiz, FtkEvent* event)
{
	DECL_PRIV0(thiz, priv);
	int percent = priv->percent;
	return_val_if_fail(thiz != NULL && event != NULL, RET_FAIL);
	
	if(event->type == FTK_EVT_KEY_UP)
	{
		switch(event->u.key.code)
		{
			case FTK_KEY_HOME:
			{
				percent  = 0;
				break;
			}
			case FTK_KEY_END:
			{
				percent  = 100;
				break;
			}
			case FTK_KEY_PAGEUP:
			{
				percent += 10;
				break;
			}
			case FTK_KEY_PAGEDOWN:
			{
				percent -= 10;
				break;
			}
			case FTK_KEY_LEFT:
			case FTK_KEY_DOWN:
			{
				percent--;
				break;
			}
			case FTK_KEY_UP:
			case FTK_KEY_RIGHT:
			{
				percent++;
				break;
			}
			default:break;
		}
	}
	else if(event->type == FTK_EVT_MOUSE_DOWN)
	{
		priv->mouse_pressed = 1;
		ftk_window_grab(ftk_widget_toplevel(thiz), thiz);
	}
	else if(event->type == FTK_EVT_MOUSE_MOVE && priv->mouse_pressed)
	{
		int width = ftk_widget_width(thiz);
		int offset = event->u.mouse.x - ftk_widget_left_abs(thiz);
		
		percent = 100 * offset / width;
	}
	else if(event->type == FTK_EVT_MOUSE_UP)
	{
		int width = ftk_widget_width(thiz);
		int offset = event->u.mouse.x - ftk_widget_left_abs(thiz);
		
		priv->mouse_pressed = 0;
		percent = 100 * offset / width;
		ftk_window_ungrab(ftk_widget_toplevel(thiz), thiz);
	}
	else
	{
		return RET_OK;
	}

	ftk_progress_bar_set_percent(thiz, percent);

	return RET_OK;
}