July 30, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Windows Programming for Palm OS

  • February 2, 2005
  • By Alex Gusev
  • Send Email »
  • More Articles »

Now, consider a couple other helpful functions:

WinHandle WinSaveBits (const RectangleType *source, UInt16 *error)
void WinRestoreBits (WinHandle winHandle, Coord destX, Coord destY)

The first one creates an offscreen window and copies a given region into it. The second one puts the contents of the passed window into the current draw window and then removes the given window. When will it be required? Suppose you want to display a "Please wait" message while processing some lengthly operation. There is no need to use any resource for such a lightweight task. All you need to do is to draw an appropriate string and frame:

...
   Err error;
   FontID font = stdFont;
   FrameType frame = rectangleFrame;
   const Char* pszLine = "Please wait";
   RectangleType rcLocation;
   UInt32 nScreenX, nScreenY;
   Coord nMessageWidth = 0;
   Int16 wLineLength;

   error = WinScreenMode(winScreenModeGet,&nScreenX, &nScreenY,
                         NULL, NULL);

   rcLocation.topLeft.x = 0;
   rcLocation.topLeft.y = 0;
   rcLocation.extent.x  = (Coord)nScreenX;
   rcLocation.extent.y  = (Coord)nScreenY;

   wLineLength = (Int16)StrLen(pszLine);
   nMessageWidth = FntCharsWidth(pszLine, wLineLength);

     Coord nLineHeight = FntLineHeight();
   nMessageWidth += nLineHeight * 2;

   RectangleType rcMessageBounds;
   rcMessageBounds.topLeft.x = rcLocation.topLeft.x
                             + (rcLocation.extent.x - nMessageWidth) / 2;
   rcMessageBounds.topLeft.y = rcLocation.topLeft.y
                             + (rcLocation.extent.y - nLineHeight) / 2;
   rcMessageBounds.extent.x = nMessageWidth;
   rcMessageBounds.extent.y = nLineHeight;

   RectangleType rcSavedBounds;
   WinGetFramesRectangle(frame, &rcMessageBounds, &rcSavedBounds);

   // First, save the display area
      WinHandle hwndSavedBits = WinSaveBits(&rcSavedBounds, &error);
   if (hwndSavedBits != NULL)
   {
      FontID fntOld = FntSetFont(font);

      WinEraseRectangle(&rcMessageBounds, 0);
      WinDrawRectangleFrame(frame, &rcMessageBounds);

      Coord nTopPos = rcMessageBounds.topLeft.y + nLineHeight / 2;
      Coord nLeftPos = rcMessageBounds.topLeft.x
                     + (nMessageWidth - nLineWidth) / 2;
      WinDrawChars(pszLine, wLineLength, nLeftPos, nTopPos);

      FntSetFont(fntOld);
   ................................................

      // and finally, restore the screen
      WinRestoreBits(hwndSavedBits, rcSavedBounds.topLeft.x,
                     rcSavedBounds.topLeft.y);
   }

As a result, a framed "Please wait" message is displayed on the screen.

Let me mention several points in the above code snippet. First, take a look at how message bounds are calculated. The sample code takes the screen boundaries as default values. Then, after a call to FntCharsWidth, the snippet gets the actual string width in pixels, based on the currently selected font. And finally, the application requests a frame to be temporarily stored (WinGetFramesRectangle). A pair of WinSave/RestoreBits completes the game.

I'm leaving quite a lot of various functions to manage shapes, rectangles, bitmaps, and colors untouched. The Window.h header file will guide you through all the rich APIs that Palm OS offers.

Finally, I'd like to say a few words regarding font management. Palm OS has about two dozen functions to manage fonts. They all are declared in the Font.h file. You definitely won't use them all, but several helpful ones are listed below:

FontID FntGetFont (void)
FontID FntSetFont (FontID font)
Int16 FntCharHeight (void)
Int16 FntLineHeight (void)
Int16 FntCharsWidth (Char const *chars, Int16 len)
void FntCharsInWidth (Char const *string,
                      Int16 *stringWidthP, Int16 *stringLengthP,
                      Boolean *fitWithinWidth)
Int16 FntLineWidth (Char const *pChars, UInt16 length)
UInt16 FntWordWrap (Char const *chars, UInt16 maxWidth)
void FntWordWrapReverseNLines (Char const *const chars,
                               UInt16 maxWidth, UInt16 *linesToScrollP,
                               UInt16 *scrollPosP)

These functions allow you to get or set the current font, retrieve information about font height, determine boundaries of given text, and so forth. Some examples of their usage were presented above. Actually, there is nothing much to duscuss here; just refer to the SDK documentation.

Conclusion

I hope this article gave you an initial picture of Palm OS Window Management. It's not as complicated as it might seem, but does require some effort from you to develop all the functionality you want to be implemented. In other words, it is worth your verification.

About the Author

Alex Gusev started to play with mainframes at the end of the 1980s, using Pascal and REXX, but soon switched to C/C++ and Java on different platforms. When mobile PDAs seriously rose their heads in the IT market, Alex did it too. Now, he works at an international retail software company as a team leader of the Mobile R department, making programmers' lives in the mobile jungles a little bit simpler.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel