📄 widget_ctk.c
字号:
*****************************************************************************/
ctk_screen_handle widget_ctk_screen_create(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
ctk_screen_create_struct scr_create;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
CTK_INIT_STRUCT(scr_create);
scr_create.scr_on_enter_fp = widget_ctk_on_enter;
scr_create.scr_on_exit_fp = widget_ctk_on_exit;
scr_create.scr_on_pre_paint_fp = widget_ctk_on_pre_paint;
/* scr_on_post_close_fp is set by different types of window individually */
return ctk_screen_create(HDIa_widgetCtkGetApp(), &scr_create);
}
/*****************************************************************************
* FUNCTION
* HDIa_widgetCtkSetFlag
* DESCRIPTION
*
* PARAMETERS
* ctk [IN] MsfWindow containing the CTK screen
* flags [IN] Flags to add
* RETURNS
* void
*****************************************************************************/
void HDIa_widgetCtkSetFlag(MsfWindowHandle ctk, widget_ctk_flag_t flags)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!IS_CTK_TYPE(ctk))
{
WAP_DBG_ASSERT(0);
return;
}
_CTK(ctk)->ctk_flag |= flags;
}
/*****************************************************************************
* FUNCTION
* HDIa_widgetCtkUnsetFlag
* DESCRIPTION
*
* PARAMETERS
* ctk [IN] MsfWindow containing the CTK screen
* flags [IN] Flags to remove
* RETURNS
* void
*****************************************************************************/
void HDIa_widgetCtkUnsetFlag(MsfWindowHandle ctk, widget_ctk_flag_t flags)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!IS_CTK_TYPE(ctk))
{
WAP_DBG_ASSERT(0);
return;
}
_CTK(ctk)->ctk_flag &= ~flags;
}
/*************************************************************************
*
* Predefined window types that are implemented with CTK
* -------------------------------------------
*
* Note: We use MSF_MEM_ALLOC instead of ctk_mem_alloc because the allocation size
* is not deterministic, and it is difficult to find out the boundary value of memory requirement.
*
* Note: We do not support busy icon on CTK window as in widget screen.
*
*************************************************************************/
/*************************************************************************
* Helper functions
*************************************************************************/
/*****************************************************************************
* FUNCTION
* widget_ctk_free_string_pack
* DESCRIPTION
*
* PARAMETERS
* modId [IN]
* pack [IN]
* RETURNS
* void
*****************************************************************************/
static void widget_ctk_free_string_pack(MSF_UINT8 modId, widget_string_pack_struct *pack)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (pack->type == WIDGET_STRING_PACK_UCS2 && pack->_u.ucs2)
{
MSF_MEM_FREE(modId, pack->_u.ucs2);
pack->_u.ucs2 = NULL;
}
else if (pack->type == WIDGET_STRING_PACK_UTF8 && pack->_u.utf8)
{
MSF_MEM_FREE(modId, pack->_u.utf8);
pack->_u.utf8 = NULL;
}
}
/* Note: Typically we do not store UTF-8 string internally */
/*****************************************************************************
* FUNCTION
* widget_ctk_copy_string_pack
* DESCRIPTION
*
* PARAMETERS
* modId [IN]
* dst [OUT]
* src [IN]
* RETURNS
* void
*****************************************************************************/
static void widget_ctk_copy_string_pack(
MSF_UINT8 modId,
widget_string_pack_struct *dst,
widget_string_pack_struct *src)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
memset(dst, 0, sizeof(widget_string_pack_struct));
if (src->type == WIDGET_STRING_PACK_ID)
{
dst->type = WIDGET_STRING_PACK_ID;
dst->_u.id = src->_u.id;
}
else if (src->type == WIDGET_STRING_PACK_UCS2)
{
dst->type = WIDGET_STRING_PACK_UCS2;
dst->_u.ucs2 = widget_ucs2_strdup(modId, src->_u.ucs2);
}
else
{
dst->type = WIDGET_STRING_PACK_UCS2;
dst->_u.ucs2 = widget_ucs2_strdup_from_utf8(modId, (const kal_uint8*)src->_u.utf8);
}
}
/*****************************************************************************
* FUNCTION
* widget_ctk_string_pack_get_data
* DESCRIPTION
*
* PARAMETERS
* pack [OUT]
* RETURNS
*
*****************************************************************************/
static const kal_uint8 *widget_ctk_string_pack_get_data(widget_string_pack_struct *pack)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (pack->type == WIDGET_STRING_PACK_ID)
{
return (const kal_uint8*)GetString(pack->_u.id);
}
else
{
WAP_DBG_ASSERT(pack->type == WIDGET_STRING_PACK_UCS2);
return pack->_u.ucs2;
}
}
/*************************************************************************
* TextView
*************************************************************************/
/* static void widget_ctk_text_view_key_wrapper(ctk_screen_handle scrid); */
static void widget_ctk_show_text_view(ctk_layout_handle layoutid);
#define WIDGET_CTK_TEXT_VIEW_DRAW_SEPARATOR 0x01
typedef struct
{
MSF_UINT8 modId;
ctk_string_id str_title;
ctk_image_id img_title;
kal_uint32 flags;
kal_uint8 *text;
} widget_ctk_text_view_struct;
/* Callback function of displaying Category74 */
/*****************************************************************************
* FUNCTION
* widget_ctk_show_text_view
* DESCRIPTION
*
* PARAMETERS
* layoutid [IN]
* RETURNS
* void
*****************************************************************************/
static void widget_ctk_show_text_view(ctk_layout_handle layoutid)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
ctk_screen_handle scrid = ctk_layout_get_parent_screen(layoutid);
widget_ctk_text_view_struct *context = (widget_ctk_text_view_struct*) ctk_screen_get_local_data(scrid);
ctk_string_id str1, str2;
ctk_image_id img1, img2;
U8 *guiBuffer;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
guiBuffer = ctk_pcategory_get_gui_buffer(layoutid);
/* MMI categories typically require setting the softkey label before SetLeftSoftkeyFunction */
ctk_screen_get_LSK_label(scrid, &str1, &img1);
ctk_screen_get_RSK_label(scrid, &str2, &img2);
if (context->flags & WIDGET_CTK_TEXT_VIEW_DRAW_SEPARATOR)
{
ShowCategory76Screen(
context->str_title,
widget_get_title_icon(context->img_title),
str1,
img1,
str2,
img2,
context->text,
widget_ucs2_length(context->text),
guiBuffer);
}
else
{
ShowCategory74Screen(
context->str_title,
widget_get_title_icon(context->img_title),
str1,
img1,
str2,
img2,
context->text,
widget_ucs2_length(context->text),
guiBuffer);
}
}
/*****************************************************************************
* FUNCTION
* widget_ctk_text_view_on_post_close
* DESCRIPTION
*
* PARAMETERS
* scrid [IN]
* RETURNS
* void
*****************************************************************************/
static void widget_ctk_text_view_on_post_close(ctk_screen_handle scrid)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
widget_ctk_text_view_struct *context = (widget_ctk_text_view_struct*) ctk_screen_get_local_data(scrid);
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
MSF_MEM_FREE(context->modId, context->text);
MSF_MEM_FREE(context->modId, context);
}
/*****************************************************************************
* FUNCTION
* HDIa_widgetExtCreateTextView
* DESCRIPTION
*
* PARAMETERS
* modId [IN]
* text [IN] UCS2, it will be duplicated. (Do we really need to duplicate it?)
* str_title [IN]
* img_title [IN]
* RETURNS
* handle of the created MsfWindow
*****************************************************************************/
MsfWindowHandle HDIa_widgetExtCreateTextView(
MSF_UINT8 modId,
const kal_uint8 *text,
ctk_string_id str_title,
ctk_image_id img_title)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
ctk_screen_handle scrid;
ctk_layout_handle layoutid;
ctk_pcategory_create_struct layout_create;
widget_ctk_text_view_struct *context;
MsfWindowHandle ctk;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
WAP_DBG_ASSERT(widget_ctk_appid);
/* Create CTK screen */
scrid = widget_ctk_screen_create();
ctk_screen_set_on_post_close_handler(scrid, widget_ctk_text_view_on_post_close);
/* Set context */
context = MSF_MEM_ALLOC(modId, sizeof(widget_ctk_text_view_struct));
context->modId = modId;
context->str_title = str_title;
context->img_title = img_title;
context->text = widget_ucs2_strdup(modId, text);
context->flags = 0;
ctk_screen_set_local_data(scrid, context);
/* Create Layout */
CTK_INIT_STRUCT(layout_create);
layout_create.pcat_show_fp = widget_ctk_show_text_view;
layoutid = ctk_pcategory_create(widget_ctk_appid, &layout_create);
ctk_screen_attach_layout(scrid, layoutid);
/* create MsfWindow */
ctk = HDIa_widgetCtkCreate(modId, scrid);
_CTK(ctk)->ctk_predefined_type = WIDGET_CTK_PREDEFINED_TEXT_VIEW;
return ctk;
}
/*****************************************************************************
* FUNCTION
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -