📄 wap_gle.c
字号:
*******************************************************************************/
VOID GLEa_playSoundClick(VOID)
{
T_WAP_MMI_CONTROL_IND parameter;
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_playSoundClick");
#endif
parameter.object_id = 0;
parameter.status_code = 0;
parameter.error_code = 0;
parameter.play_standard_click = TRUE;
W_WAP_MMI_CONTROL_IND(¶meter);
return;
}
/*******************************************************************************
$Function: GLEa_strcpyGle2Wchar
$Description: Converts a GLE_STRING to a Unicode string.
$Returns: the Unicode string
$Arguments: dst - the null terminated destination string
src - the null terminated source string
*******************************************************************************/
WCHAR* GLEa_strcpyGle2Wchar(WCHAR* dst, const GLE_STRING src)
{
UINT16 index;
USHORT *srcUnicode = (USHORT *)src;
USHORT *dstUnicode = (USHORT *)dst;
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_strcpyGle2Wchar");
#endif
for (index=0; srcUnicode[index] != 0; index++)
{
dstUnicode[index] = srcUnicode[index];
}
dstUnicode[index] = 0;
return dst;
}
/*******************************************************************************
$Function: GLEa_strcpyWchar2Gle
$Description: Converts a Unicode string to a GLE_STRING string.
$Returns: the GLE_STRING string
$Arguments: dst - the null terminated destination string
src - the null terminated source string
*******************************************************************************/
GLE_STRING GLEa_strcpyWchar2Gle(GLE_STRING dst, const WCHAR* src)
{
UINT16 index;
USHORT *dstUnicode = (USHORT *)dst;
USHORT *srcUnicode = (USHORT *)src;
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_strcpyWchar2Gle");
#endif
for (index=0; src[index] != '\0'; index++)
{
dstUnicode[index] = srcUnicode[index];
}
dstUnicode[index] = 0;
return dst;
}
/*******************************************************************************
$Function: GLEa_strcpyGle2Gle
$Description: Copies a GLE_STRING string to another GLE_STRING string.
$Returns: the copy
$Arguments: dst - the null terminated destination string
src - the null terminated source string
*******************************************************************************/
GLE_STRING GLEa_strcpyGle2Gle(GLE_STRING dst, const GLE_STRING src)
{
UINT16 index;
USHORT *srcUnicode = (USHORT *)src;
USHORT *dstUnicode = (USHORT *)dst;
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_strcpyGle2Gle");
#endif
for (index=0; srcUnicode[index] != 0; index++)
{
dstUnicode[index] = srcUnicode[index];
}
dstUnicode[index] = 0;
return dst;
}
/*******************************************************************************
$Function: GLEa_strlen
$Description: Computes the number of characters in the GLE_STRING string.
$Returns: the number of characters, not including the null character
$Arguments: str - the null terminated source string
*******************************************************************************/
INT16 GLEa_strlen(const GLE_STRING str)
{
INT16 index = 0;
USHORT *strUnicode = (USHORT *)str;
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_strlen");
#endif
while ( strUnicode[index] >= 0x20 )
index++;
#ifdef TRACE_WAP_GLE
WAP_trace_ushort_string(strUnicode, index);
#endif
return index;
}
/*******************************************************************************
$Function: GLEa_sizeofString
$Description: Computes the number of bytes needed to store the GLE_STRING string.
$Returns: the number of bytes that need to be allocated to convert the Unicode
array pointed to text to a null-terminated GLE_STRING string. Space
for the null character is also counted.
$Arguments: text - the null terminated source string
*******************************************************************************/
UINT16 GLEa_sizeofString(const WCHAR* str)
{
UINT16 index = 0;
USHORT *strUnicode = (USHORT *)str;
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_sizeofString");
WAP_trace_ushort_string(strUnicode, 40);
#endif
while (str[index] != '\0')
index++;
#ifdef TRACE_WAP_GLE
TRACE_EVENT_P1("Returned: %d", index*sizeof(USHORT));
#endif
return index*sizeof(USHORT); /* Includes terminating NULL */
}
/*******************************************************************************
$Function: GLEa_strNbrCharsWithoutEndingSpaces
$Description: Calculates the number of the first len characters in the passed string.
$Returns: the number of the len first characters in the str string, except for
ending space characters.
$Arguments: str - the source string
len - the number of characters to read
*******************************************************************************/
INT16 GLEa_strNbrCharsWithoutEndingSpaces(const GLE_STRING str, UINT16 len)
{
INT16 stringlength = GLEa_strlen(str);
USHORT *strUnicode = (USHORT *)str;
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_strNbrCharsWithoutEndingSpaces");
WAP_trace_ushort_string((USHORT *)strUnicode, len);
#endif
if (len > stringlength) /* start at len characters, */
len = stringlength; /* or the end of the string if smaller. */
while (strUnicode[len-1] == 0x0020 && len > 0) /* if the character is a space, */
len--; /* look at the previous character */
#ifdef TRACE_WAP_GLE
TRACE_EVENT_P1("Returned: %d", len);
#endif
return (INT16) len; /* now we have the number of non-space characters */
}
/*******************************************************************************
$Function: GLEa_sizeofNchars
$Description: Computes how many bytes are needed to hold the first len characters
in the str string, except for ending space characters.
$Returns: the number of bytes that are needed to hold the first len characters of
the string.
$Arguments: str - the source string
len - the number of bytes to read
*******************************************************************************/
UINT16 GLEa_sizeofNchars(const GLE_STRING str, UINT16 len)
{
UINT16 sizeNoEndSpaces = GLEa_strNbrCharsWithoutEndingSpaces(str, len);
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_sizeofNchars");
WAP_trace_ushort_string((USHORT *)str,sizeNoEndSpaces);
TRACE_EVENT_P1("Returned: %d", (sizeNoEndSpaces*sizeof(USHORT)));
#endif
return (UINT16) (sizeNoEndSpaces*sizeof(USHORT));
}
/*******************************************************************************
$Function: GLEa_textFontAscent
$Description: The rendering algorithm of the GLE uses this function to get a text's
ascent.
$Returns: the ascent in pixels of the corresponding font.
$Arguments: format - the format of the text
isLink - TRUE if the text is a link
*******************************************************************************/
UINT16 GLEa_textFontAscent(INT8 format, BOOL isLink)
{
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_textFontAscent");
#endif
return font_height;
}
/*******************************************************************************
$Function: GLEa_textFontHeight
$Description: The rendering algorithm of the GLE uses this function to get a text's
height.
$Returns: the height in pixels of the corresponding font. This height includes
eventual space to the following line.
$Arguments: format - the format of the text
isLink - TRUE if the text is a link
*******************************************************************************/
UINT16 GLEa_textFontLineHeight(INT8 format, BOOL isLink)
{
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_textFontLineHeight");
TRACE_EVENT_P1("Returning: %d", font_height);
#endif
return font_height;
}
/*******************************************************************************
$Function: GLEa_textFontWidth
$Description: The rendering algorithm of the GLE uses this function to get a text's
width.
$Returns: the width in pixels of the first len characters in the GLE_STRING text,
calculated with the corresponding font.
$Arguments: text - the text whose width is to be returned
len - number of characters to be considered
format - the format of the text
isLink - TRUE if the text is a link
*******************************************************************************/
UINT16 GLEa_textFontWidth(const GLE_STRING text, const UINT16 len, INT8 format, BOOL isLink)
{
UINT16 width;
INT16 stringlength = GLEa_strlen(text);
USHORT *strUnicode = (USHORT *)text;
UINT16 index;
#ifdef TRACE_WAP_GLE
TRACE_FUNCTION("GLEa_textFontWidth");
#endif
width = 0;
for (index=0; index<len && index<stringlength; index++)
{
if (strUnicode[index]<256)
width += font_width[strUnicode[index]];
else
width += unicode_width;
}
#ifdef TRACE_WAP_GLE
TRACE_EVENT_P1("Returned: %d", width);
#endif
return width;
}
/*******************************************************************************
$Function: GLEa_textFontWordWrap
$Description: Given the null terminated GLE_STRING text, this function returns the
number of characters of the whole words that can be displayed within
wrapWidth pixels, calculated with the corresponding font. Ending space
characters shall be counted as they fit. If not even one word fits
within the wrapWidth, then the function returns the number of characters
of the first word that fits within wrapWidth.
$Returns: the number of characters of the whole words that can be displayed.
$Arguments: text - the text to wrap
wrapWidth - maximum width in pixels
format - the format of the text
isLink - TRUE if the text is a link
*******************************************************************************/
UINT16 GLEa_textFontWordWrap(const GLE_STRING text, const UINT16 wrapWidth, INT8 format, BOOL isLink)
{
UINT16 index;
UINT16 foundspace = 0;
BOOL foundnonbreaking = FALSE; /* Nonbreaking space character (A0) means cannot wrap until space found */
UINT16 totalWidth = 0;
USHORT *textUnicode = (USHORT *)text;
#ifdef TRACE_WAP_GLE
USHORT *dump = (USHORT *)text;
USHORT dumpIndex;
TRACE_EVENT("GLEa_textFontWordWrap");
TRACE_EVENT_P3("wrapWidth, format, isLink: %d, %d, %d", wrapWidth, format, isLink);
for (dumpIndex = 0; dumpIndex < 10; dumpIndex++)
{
TRACE_EVENT_P3("%X: %c, %d", dump+dumpIndex, *(dump+dumpIndex), *(dump+dumpIndex));
}
#endif
for(index = 0; textUnicode[index]>=0x20; index++)
{
if (totalWidth>=wrapWidth && !foundnonbreaking)
break;
totalWidth += GLEa_textFontWidth((GLE_STRING)(textUnicode+index), 1, format, isLink); /* Width of single character */
if (textUnicode[index]==0x20)
{
foundspace = index;
foundnonbreaking = FALSE;
}
if (textUnicode[index]==0xA0)
{
foundnonbreaking = TRUE;
}
}
if (totalWidth>wrapWidth)
index--;
/* If we haven't found a space, hard-wrap the text */
if (foundspace==0)
{
return index;
}
/* Otherwise, soft-wrap it */
if (textUnicode[index]==0x20) /* Space is found */
{
return index+1;
}
if (textUnicode[index]<0x20) /* End of string is found */
{
return index;
}
return foundspace+1;
}
/*******************************************************************************
$Function: GLEa_textDraw
$Description: This function draws a number of characters of a text in the corresponding
font.
$Returns: None.
$Arguments: text - the text to draw
len - draws the len first characters of the text
invert - if TRUE, text should be drawn marked, otherwise not
textBounds - the position of the upper left corner and the allowed
width and height.
deltaY - distance from the upper left corner to the top of the
text
format - the format of the text
isLink - true if the text is a link
*******************************************************************************/
VOID GLEa_textDraw(UINT8 viewId, const GLE_STRING text, const UINT16 len, BOOL invert, GleRectangleType *textBounds, UINT16 deltaY, INT8 format, BOOL isLink)
{
T_WAP_MMI_SEND_TEXT_IND parameter;
/* USHORT textIndex; */
#ifdef TRACE_WAP_GLE
TRACE_EVENT("GLEa_textDraw");
WAP_trace_ushort_string((USHORT *)text,len);
#endif
/* If our text element is off the edge of the screen, don't send the event */
if (textBounds->topLeft.x > view_width || textBounds->topLeft.y > (view_height-font_height)
|| (textBounds->topLeft.x+textBounds->extent.x)<0 || textBounds->topLeft.y<0)
return;
/* Otherwise, send the event */
parameter.object_id = viewId;
parameter.type = WAP_TEXT_NORM;
parameter.text_length = len;
parameter.Text = (USHORT*)text;
/* Skip out leading space of string */
if (parameter.Text[0] == 0x20 || parameter.Text[0] == 0xA0)
{
parameter.Text++;
parameter.text_length--;
}
parameter.invert = invert;
parameter.pX = textBounds->topLeft.x;
parameter.pY = textBounds->topLeft.y;
parameter.pWidth = textBounds->extent.x;
parameter.pHeight = textBounds->extent.y;
parameter.format = format;
parameter.selected = invert;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -