gui_virtual_keyboard.c

来自「The font library converting tool MCT mai」· C语言 代码 · 共 1,129 行 · 第 1/3 页

C
1,129
字号
	}

	if (s->matrix_index >= 0)
	{
		MMI_DBG_ASSERT(s->matrix_column >= 0 && s->matrix_row >= 0);
		*evt = GUI_VKBD_PEN_CHAR_I;
		*ch = lang->matrix_string[s->matrix_row][s->matrix_column];
	} 
	else
	{
		*evt = lang->custom_key_type[s->custom_key_index];
		*ch = lang->custom_string[s->custom_key_index];
	}

	MMI_DBG_ASSERT(!*ch || *evt == GUI_VKBD_PEN_CHAR_I);
	return MMI_TRUE;
}


static void pixtel_UI_virtual_keyboard_translate_dead_key(virtual_keyboard *v, UI_character_type *ch, mmi_gui_virtual_keyboard_pen_enum *evt)
{
	const gui_keyboard_language_struct	*lang;

	lang = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_language;

	if (lang->enable_dead_key)
	{
		if (*evt == GUI_VKBD_PEN_CHAR_I)
		{
			if (pixtel_UI_virtual_keyboard_check_dead_key(*ch))
			{
				v->dead_key_input[0] = *ch;
				*ch = 0;
				*evt = GUI_VKBD_PEN_DEAD_KEY;
			}
			else if (v->dead_key_input[0])
			{
				/* Only two key combination is currently supported */
				UI_character_type ret;
				v->dead_key_input[1] = *ch;
				if ((ret = pixtel_UI_get_dead_key_symbol(v->lang_type, v->dead_key_input, 2)) != 0)
				{
					*ch = ret;
				}
				/* Otherwise, use the original key */

				v->dead_key_input[0] = 0;
			}
		}
		else
		{
			v->dead_key_input[0] = 0;
		}
	}
}

static void pixtel_UI_virtual_keyboard_clear_dead_key(virtual_keyboard *v)
{
	v->dead_key_input[0] = 0;
}

static void pixtel_UI_virtual_keyboard_cache_and_show_selected_key(virtual_keyboard *v)
{
	S32 x1, x2, y1, y2;
	S32 glyph_width, glyph_height;
	virtual_keyboard_selection_struct *s;
	const gui_keyboard_language_struct *lang;
	UI_character_type ch = 0;
	UI_image_type img = NULL;
	
	lang = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_language;
	s = &v->selected_key;

	MMI_DBG_ASSERT(s->custom_key_index >= 0 || s->matrix_index >= 0);
	
	if (s->custom_key_index >= 0 && lang->custom_key_type[s->custom_key_index] == GUI_VKBD_PEN_DISPLAY_AREA)
	{
		/* We do not select Display Area. Furthermore, it costs too much memory to cache the area */
		return;
	}

	x1 = s->key_x;
	y1 = s->key_y;
	x2 = x1 + s->key_width - 1;
	y2 = y1 + s->key_height - 1;

	/* Use a fixed size to avoid running out of certain control buffer bucket size */
	MMI_DBG_ASSERT((((S32) s->key_width * s->key_height * gdi_layer_get_bit_per_pixel() + 7) >> 3) <= MMI_virtual_keyboard_bitmap_cache_size);
	v->selected_key_cached = 1;
#if 1
	{
		/* Workaround. We might not be able allocate large control buffer */
		static char bitmap_buffer[2500];
		MMI_ASSERT(MMI_virtual_keyboard_bitmap_cache_size < 2500);
		v->selected_key_bitmap.buf_ptr = (U8*)bitmap_buffer;
	}
#else
/* under construction !*/
#endif

	pixtel_UI_lock_double_buffer();

	gdi_layer_push_clip();
	
	gdi_layer_set_clip(x1,y1,x2,y2);
	gdi_image_cache_bmp_get(x1, y1, x2, y2, &v->selected_key_bitmap);

	pixtel_UI_draw_filled_area(x1+1, y1+1, x2-1, y2-1, v->keyboard_theme->key_down_filler);

	if (s->matrix_index >= 0)
	{		
		ch = lang->matrix_string[s->matrix_row][s->matrix_column];
	}
	else if (s->custom_key_index >= 0 && lang->custom_string[s->custom_key_index])
	{
		ch = lang->custom_string[s->custom_key_index];
	}
	else
	{
		img = get_image(lang->custom_key_image[s->custom_key_index]);
	}

	if (ch)
	{
		pixtel_UI_set_font(v->keyboard_theme->text_font);
		pixtel_UI_set_text_color(v->keyboard_theme->key_down_text_color);

		pixtel_UI_virtual_keyboard_show_char_center_align(ch, s->key_x, s->key_y, s->key_width, s->key_height, &glyph_width, &glyph_height);
	}
	
	if (img)
	{
		pixtel_UI_measure_image(img, &glyph_width, &glyph_height);
		pixtel_UI_show_image(s->key_x + VKBD_DIFF_HALF(s->key_width, glyph_width), 
								s->key_y + VKBD_DIFF_HALF(s->key_height, glyph_height), img);
	}
	
	gdi_layer_pop_clip();

	pixtel_UI_unlock_double_buffer();
	pixtel_UI_BLT_double_buffer(x1, y1, x2, y2);
}


static void pixtel_UI_virtual_keyboard_show_unselect_key_from_cache(virtual_keyboard *v)
{
	S16	x1,x2,y1,y2;

	if (!v->selected_key_cached )
	{
		return;
	}
	
	x1 = v->selected_key.key_x;
	y1 = v->selected_key.key_y;
	x2 = x1 + v->selected_key.key_width - 1;
	y2 = y1 + v->selected_key.key_height - 1;

	pixtel_UI_lock_double_buffer();
	gdi_layer_push_clip();
	gdi_layer_set_clip(x1, y1, x2, y2);
	gdi_image_cache_bmp_draw(x1, y1, &v->selected_key_bitmap);
	gdi_layer_pop_clip();
	pixtel_UI_unlock_double_buffer();
	pixtel_UI_BLT_double_buffer(x1, y1, x2, y2);
	
	// pixtel_UI_free(v->selected_key_bitmap.buf_ptr);
	v->selected_key_bitmap.buf_ptr = NULL;
	v->selected_key_cached = 0;
}


static BOOL pixtel_UI_virtual_keyboard_translate_pen_position(virtual_keyboard *v, S16 x, S16 y, virtual_keyboard_selection_struct *s)
{
	const gui_keyboard_layout_struct		*layout;
	S32	i;

	layout = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_layout;

	pixtel_UI_virtual_keyboard_clear_selected_key(s);
	
	for (i = 0; i < layout->n_matrix_key_layout; i++)
	{
		const gui_matrix_key_layout_struct	*matrix;
		S32 matrix_x, matrix_y;

		matrix = &layout->matrix_layout[i];
		matrix_x = v->x + matrix->x;
		matrix_y = v->y + matrix->y;
		if (PEN_CHECK_BOUND(x, y, matrix_x, matrix_y, matrix->width, matrix->height))
		{
			s->matrix_index = i;
			
			s->matrix_column = (x - matrix_x) / (matrix->key_width+matrix->horizontal_key_gap);
			if (s->matrix_column >= matrix->n_columns)
				s->matrix_column = matrix->n_columns - 1;
				
			s->matrix_row = (y - matrix_y) / (matrix->key_height+matrix->vertical_key_gap);
			if (s->matrix_row >= matrix->n_rows)
				s->matrix_row = matrix->n_rows - 1;
				
			s->key_width = matrix->key_width;
			s->key_height = matrix->key_height;
			s->key_x = matrix_x + s->matrix_column * (matrix->key_width+matrix->horizontal_key_gap);
			s->key_y = matrix_y + s->matrix_row * (matrix->key_height+matrix->vertical_key_gap);
			return MMI_TRUE;
		}
	}

	for (i = 0; i < layout->n_custom_keys; i++)
	{
		const gui_custom_key_layout_struct	*custom_key;
		S32 custom_key_x, custom_key_y;

		custom_key = &layout->custom_keys[i];
		custom_key_x = v->x + custom_key->x;
		custom_key_y = v->y + custom_key->y;

		if (PEN_CHECK_BOUND(x, y, custom_key_x, custom_key_y, custom_key->key_width, custom_key->key_height))
		{
			s->custom_key_index = i;
			
			s->key_width = custom_key->key_width;
			s->key_height = custom_key->key_height;
			s->key_x = custom_key_x;
			s->key_y = custom_key_y;
			return MMI_TRUE;
		}
	}

	return MMI_FALSE;
}

#endif /* __MMI_TOUCH_SCREEN__ */

/***************************************************************************** 
* Global Variable
*****************************************************************************/
UI_virtual_keyboard_theme 	*current_virtual_keyboard_theme=NULL;

/***************************************************************************** 
* Global Function
*****************************************************************************/

/*----------------------------------------------------------------------------
Function:			pixtel_UI_set_virtual_keyboard_current_theme
Description:		Applies the current theme for virtual keyboard.
Input Parameters:	v	is the virtual keyboard pointer
Output Parameters:	none
Returns:			void
----------------------------------------------------------------------------*/
void pixtel_UI_set_virtual_keyboard_current_theme(virtual_keyboard *v)
{
	MMI_DBG_ASSERT(current_virtual_keyboard_theme);
   v->keyboard_theme = current_virtual_keyboard_theme;
   v->keyboard_theme->flags|=current_virtual_keyboard_theme->flags;
}

/*----------------------------------------------------------------------------
Function:			pixtel_UI_set_virtual_keyboard_current_theme
Description:		Applies the current theme for virtual keyboard.
Input Parameters:	v	is the virtual keyboard pointer
Output Parameters:	none
Returns:			void
----------------------------------------------------------------------------*/
void pixtel_UI_set_virtual_keyboard_theme(virtual_keyboard *v, UI_virtual_keyboard_theme *t)
{
	MMI_DBG_ASSERT(t);
   v->keyboard_theme = t;
   v->keyboard_theme->flags|=t->flags;
}

/*----------------------------------------------------------------------------
Function:			pixtel_UI_create_virtual_keyboard
Description:		Create virtual keyboard object
Input Parameters:	v		is the virtual keyboard object
					(x,y)	is the left-top cornerd
					lang_type		is language type to be used for the keyboard
Output Parameters:	none
Returns:			void
----------------------------------------------------------------------------*/
void pixtel_UI_create_virtual_keyboard(virtual_keyboard *v, S16 x, S16 y, mmi_gui_virtual_keyboard_language_enum lang_type)
{
	v->x = x;
	v->y = y;
	v->width = MMI_virtual_keyboard_language_map[lang_type].virtual_keyboard_layout->width;
	v->height = MMI_virtual_keyboard_language_map[lang_type].virtual_keyboard_layout->height;
	v->lang_type = lang_type;
	v->flags = 0;
	v->allowed_characters = NULL;
	v->disp_area_text[0] = (UI_character_type) '\0';
	v->disabled_chars[0] = (UI_character_type) '\0';
	v->disabled_symbols[0] = GUI_VKBD_PEN_NONE;
	pixtel_UI_set_virtual_keyboard_current_theme(v);

	memset(v->dead_key_input, 0, sizeof(v->dead_key_input));
	
	pixtel_UI_virtual_keyboard_clear_selected_key(&v->selected_key);
	v->selected_key_bitmap.buf_ptr = NULL;
	v->selected_key_cached = 0;
}


/*----------------------------------------------------------------------------
Function:			pixtel_UI_move_virtual_keyboard
Description:		Move the virtual keyboard 
Input Parameters:	v		is the virtual keyboard object
					(x,y)	is the left-top cornerd
Output Parameters:	none
Returns:			void
----------------------------------------------------------------------------*/
void pixtel_UI_move_virtual_keyboard(virtual_keyboard *v, S16 x, S16 y)
{
	v->x = x;
	v->y = y;
}


/*----------------------------------------------------------------------------
Function:				pixtel_UI_show_virtual_keyboard
Description:			Show the virtual keyboard 
Input Parameters:		v	is the virtual keyboard object
Output Parameters:	none
Returns:					void
----------------------------------------------------------------------------*/

void pixtel_UI_show_virtual_keyboard(virtual_keyboard *v)
{
	S16	x1, y1, x2, y2;
	S32	glyph_width, glyph_height;
	UI_character_type	key_char;
	S16	key_width, key_height;
	S16	key_x, key_y;
	const gui_keyboard_layout_struct		*layout;
	const gui_keyboard_language_struct	*lang;
	S16	i, j, k;
	BOOL	enable_dead_key;
	
	x1=v->x;
	y1=v->y;
	x2=v->x+v->width-1;
	y2=v->y+v->height-1;
	
	layout = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_layout;
	lang = MMI_virtual_keyboard_language_map[v->lang_type].virtual_keyboard_language;

	enable_dead_key = lang->enable_dead_key;

	pixtel_UI_push_clip();
	pixtel_UI_push_text_clip();
	pixtel_UI_set_clip(x1, y1, x2, y2);
	pixtel_UI_set_text_clip(x1, y1, x2, y2);

	pixtel_UI_show_image(x1, y1, (UI_image_type) get_image(layout->ImageId)); 
	
	for (k=0; k<layout->n_matrix_key_layout; k++)
	{
		S16	horizontal_text_gap, vertical_text_gap;
		S16	n_matrix_column, n_matrix_row;
		const gui_matrix_key_layout_struct	*matrix;
		const UI_character_type	*matrix_string;

		matrix = &layout->matrix_layout[k];		
		horizontal_text_gap = matrix->horizontal_key_gap;
		vertical_text_gap = matrix->vertical_key_gap;
		
		n_matrix_column = matrix->n_columns;
		n_matrix_row = matrix->n_rows;

		key_x = v->x + matrix->x;
		key_y = v->y + matrix->y;
		key_width = matrix->key_width;
		key_height = matrix->key_height;
		
		pixtel_UI_set_font( v->keyboard_theme->text_font);
		pixtel_UI_set_text_color(v->keyboard_theme->key_up_text_color);
		

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?