appclasses.cpp
资源名称:cppapp.zip [点击查看]
上传用户:smh666999
上传日期:2007-01-14
资源大小:553k
文件大小:9k
源码类别:
BREW编程
开发平台:
Visual C++
- #include "appclasses.h"
- #include "AEEStdLib.h"
- //--------------------------------------------------------------------------
- // Writer class constructor
- //--------------------------------------------------------------------------
- Writer::Writer(IShell* pIShell)
- {
- int charHeight, pnAscent, pnDescent;
- ISHELL_CreateInstance(pIShell, AEECLSID_DISPLAY, (void **)&m_pIDisplay);
- // Determine the amount of available screen space
- ISHELL_GetDeviceInfo(pIShell,&m_di);
- // Determine the height of a line of text
- charHeight = IDISPLAY_GetFontMetrics (m_pIDisplay, AEE_FONT_NORMAL,
- &pnAscent, &pnDescent);
- // Number of available lines equals the available screen
- // space divided by the height of a line, minus 3 for the
- // lines we always print at the top and bottom of the screen
- m_cMaxLine = (m_di.cyScreen / charHeight) - 3;
- m_cLineNum = 1;
- IDISPLAY_EraseRgn(m_pIDisplay, 0, 0, m_di.cxScreen, m_di.cyScreen);
- // WriteLine("Writer Constructor");
- }
- //--------------------------------------------------------------------------
- // Writer class desctuctor
- //--------------------------------------------------------------------------
- Writer::~Writer()
- {
- // WriteLine("Writer Destructor");
- IDISPLAY_Release(m_pIDisplay);
- }
- /*===========================================================================
- FUNCTION: Writer::WriteLine
- DESCRIPTION
- This function displays lines of text on the screen, taking into account
- the number of text lines printed so far and the number of lines available
- for output.
- If all available lines are exhausted, this function returns without doing
- anything.
- If the last available line of the screen is reached, this function prints
- "..." to indicate that some lines may not have been printed due to lack
- of space.
- Otherwise, this function prints the line on the screen by calling DisplayOutput,
- and updates the count of lines printed based on how many lines DisplayOutput
- used to print the text.
- PROTOTYPE:
- static void WriteLine(char *pszStr)
- PARAMETERS:
- pszStr: [in]: The character string to be displayed on the screen.
- DEPENDENCIES
- Assumes the m_cLineNum gets initialized to the starting line for text display
- on the screen, and that m_cMaxLine contains the last available line for
- output on the screen.
- RETURN VALUE
- None.
- SIDE EFFECTS
- None
- ===========================================================================*/
- void Writer::WriteLine(const char *pszStr)
- {
- char ellipsis[4];
- STRCPY(ellipsis, "...");
- // If all available lines used, return
- if (m_cLineNum > m_cMaxLine)
- return;
- // If we've reached last available line, print an
- // ellipsis indicator
- if (m_cLineNum == m_cMaxLine)
- {
- DisplayOutput(m_cLineNum++, ellipsis);
- return;
- }
- // There are lines available for printing. Print the string passed as
- // input and update the count of lines available
- m_cLineNum += DisplayOutput(m_cLineNum, pszStr);
- IDISPLAY_UpdateEx(m_pIDisplay, TRUE);
- return;
- } // End of WriteLine
- void Writer::WriteLine(int i)
- {
- char ch[12];
- SPRINTF(ch, "%ld", i);
- WriteLine(ch);
- } //
- //--------------------------------------------------------------------------
- // Writer class operator <<
- //--------------------------------------------------------------------------
- //--------------------------------------------------------------------------
- // Writer class operator new
- //--------------------------------------------------------------------------
- /*===========================================================================
- FUNCTION: Writer::DisplayOutput
- DESCRIPTION
- This function displays an output string at a given line number on the
- screen. If the nline parameter is a negative value (-1) the string
- is displayed in the middle of the screen. If the "nline" value is larger
- than or equal to zero the "nline" value is multiplied by 15 and the
- resulting value in pixels is set to the y-coordinate of the start of
- the string display on the screen. If the string does not fit on one line
- the string wraps around to the next line (spaced rougly 10-15 pixels apart).
- By default 5 is used as the starting the x-coordinate of a displayed
- string.
- How many characters that fit on one line is calculated for each line
- that is wrapped around to the next line.
- Note: depending on the phone screen size and the fonts used for characters
- the output might differ on different handsets (devices). Where some
- handsets will have a smaller screen and large default fonts which will
- cause partial overlapping of lines. This function does not try to address
- these issues (this is meant as a simple display function).
- PROTOTYPE:
- int DisplayOutput(int nline, char *pszStr)
- PARAMETERS:
- nline: [in]: Contains the line number to start displaying the text. The line
- numbers are by default spaced 15 pixels apart along the y-axis.
- pszStr: [in]: The character string to be displayed on the screen.
- DEPENDENCIES
- None
- RETURN VALUE
- Number of lines written to the screen.
- SIDE EFFECTS
- None
- ===========================================================================*/
- int Writer::DisplayOutput(int nline, const char *pszStr)
- {
- AECHAR * szBuf; // a buffer that supports 200 char string
- AECHAR * psz = NULL;
- int charHeight = 0; // Stores the char height in pixels for given font
- int pnAscent = 0; // Stores the ascent in number of pixels
- int pnDescent = 0; // Stores the descent in number of pixels
- int pixelWidth;
- AEEFont font = AEE_FONT_NORMAL;
- int pnFits = 0, dy;
- int totalCh = 0;
- int numLinesPrinted = 0;
- // Make sure the pointers we'll be using are valid
- if (m_pIDisplay == NULL)
- return 0;
- if ((szBuf = (AECHAR *) MALLOC(TEXT_BUFFER_SIZE)) == NULL)
- return 0;
- // Get the font metrics info
- charHeight = IDISPLAY_GetFontMetrics (m_pIDisplay, AEE_FONT_NORMAL,
- &pnAscent, &pnDescent);
- // Convert to wide string (unicode)
- STR_TO_WSTR ((char *)pszStr, szBuf, TEXT_BUFFER_SIZE);
- // If nlines is zero then print this string starting around the middle of
- // the screen. Or else multiply nlines by charheight to decide the y coordinate of
- // the start of the string.
- if (nline < 0) {
- dy = m_di.cyScreen*2/5;
- }
- else{
- dy = nline * charHeight + 5;
- }
- // psz keeps track of the point from which to write from the string buffer
- // in case the string does not fit one line and needs to wrap around in the
- // next line.
- psz = szBuf;
- // Need to calculate the lotal string length to decide if any wrapping
- // around is needed.
- totalCh = STRLEN ((char *)pszStr);
- // Keep displaying text string on multiple lines if the string can't be displayed
- // on one single line. Lines are spaced 15 pixels apart.
- while ((totalCh > 0) && (*psz != NULL))
- {
- // Get information on how many characters will fit in a line.
- // Give the pointer to the buffer to be displayed, and the number of
- // pixels along the x axis you want to display the string in (max number)
- // pnFits will have the max number of chars that will fit in the maxWidth
- // number of pixels (given string can't fit in one line), or the number of
- // chars in the string (if it does fit in one line). pnWidth gives the
- // number of pixels that will be used to display pnFits number of chars.
- pixelWidth = IDISPLAY_MeasureTextEx(m_pIDisplay,
- font,
- (AECHAR *) psz, // Start of the buffer to display,
- -1,
- m_di.cxScreen - 5, // maxWidth
- &pnFits); // Number of chars that will fit a line
- // If pnFits is zero there is something wrong in the input to above function.
- // Normally this scenario should not occur. But, have the check anyway.
- if (pnFits == 0)
- {
- FREE(szBuf);
- return 0;
- }
- IDISPLAY_DrawText(m_pIDisplay, AEE_FONT_NORMAL, psz, pnFits, 5 /*start dx*/,
- dy, 0 /* use default rectangle coordinates */, 0);
- psz += pnFits; // move pointer to the next segment to be displayed
- totalCh -= pnFits; // reduce the total number of characters to still display
- dy += charHeight; // Place next line charHeight pixels below the
- // previous line.
- ++numLinesPrinted;
- IDISPLAY_Update(m_pIDisplay); //, TRUE);
- if (totalCh < pnFits)
- pnFits = totalCh; // if total number is less than pnFits, adjust pnFits
- }
- FREE(szBuf);
- return numLinesPrinted;
- } // End of DisplayOutput