MorePalmOS
A development library for developing Palm OS applications

MoreWindow.c

Go to the documentation of this file.
00001 /******************************************************************************
00002  * MorePalmOS
00003  * Copyright (c) 2004 Steven Fisher
00004  *
00005  * Distributed under the Boost Software License, Version 1.0. See accompanying
00006  * license file License.txt or <http://www.boost.org/LICENSE_1_0.txt>.
00007  *
00008  * http://morepalmos.sourceforge.net
00009  *
00010  *   MorePalmOS is the humble begining of an attempt to provide a library for
00011  *   Palm OS development which works around system bugs, illustrate how to
00012  *   use system calls, and provide "glue code" for programming Palm OS
00013  *   applications in a more straightforward way while minimally impacting
00014  *   code size.
00015  *****************************************************************************/
00016 
00017 #include "MorePrefix.h"
00018 #include "MoreWindow.h"
00019 #include "MoreStringMgr.h"
00020 #include "MorePrivate.h"
00021 
00022 #include <PalmTypes.h>
00023 #include <SystemMgr.h>
00024 #include <Window.h>
00025 
00026 //-----------------------------------------------------------------------------
00027 
00028 Err MWinScreenToDefault( MOREPALMOS_NOPARAMS )
00029 {
00030         return WinScreenMode( winScreenModeSetToDefaults,
00031                         NULL, NULL, NULL, NULL );
00032 }
00033 
00034 //-----------------------------------------------------------------------------
00035 
00036 Err MWinScreenToDepth( UInt8 depth )
00037 {
00038         Err err;
00039         UInt32 supportedDepths;
00040         UInt32 requiredDepth;
00041         // Get supported bit depths. 
00042         err = WinScreenMode( winScreenModeGetSupportedDepths, NULL, NULL,
00043                         &supportedDepths, NULL );
00044         _reject( err, fail )
00045         // Is the appropriate bit set? 
00046         _require_action( ( supportedDepths & ( 1 << ( depth - 1 ) ) ), fail,
00047                         err = sysErrParamErr; );
00048         // If so, try to set to that depth. 
00049         requiredDepth = depth;
00050         err = WinScreenMode( winScreenModeSet, NULL, NULL, &requiredDepth, NULL );
00051         _reject( err, fail ); // dispatch notification in debug mode
00052         // err is errNone, so falling thru leads to right result
00053 fail:
00054         return err;
00055 }
00056 
00057 //-----------------------------------------------------------------------------
00058 
00059 Coord MWinDrawAlignStr( const char *str, Coord x, Coord y, Alignment align )
00060 {
00061         return MWinDrawAlignChars( str, MStrLen( str ), x, y, align );
00062 }
00063 
00064 Coord MWinDrawAlignChars( const char *str, UInt32 len, Coord x, Coord y,
00065                 Alignment align )
00066 {
00067         Coord strWidth;
00068         _require( str, noString );
00069         _require( len, noString );
00070         strWidth = FntCharsWidth( str, len );
00071         if ( align != Left )
00072         {
00073             x -= ( align == Center ) ? ( strWidth >> 1 ) : strWidth;
00074         }
00075         WinPaintChars( str, len, x, y );
00076         x += strWidth; // return x+strWidth; generates larger code
00077         // fall thru
00078 noString:
00079         return x;
00080 }
00081 
00082 //-----------------------------------------------------------------------------
00083 
00084 Coord MWinDrawAlignStrTrunc( const char *str, Coord x, Coord y,
00085                 Coord availWidth, Alignment align )
00086 {
00087         return MWinDrawAlignCharsTrunc( str, MStrLen( str ), x, y, availWidth,
00088                         align );
00089 }
00090 
00091 Coord MWinDrawAlignCharsTrunc( const char *str, UInt32 len, Coord x, Coord y,
00092                 Coord availWidth, Alignment align )
00093 {
00094         Coord strWidth;
00095         _require( str, noString );
00096         _require( len, noString );
00097         strWidth = FntCharsWidth( str, len );
00098         if ( strWidth > availWidth )
00099                 strWidth = availWidth;
00100         if ( align != Left )
00101         {
00102                 x -= ( align == Center ) ? ( strWidth >> 1 ) : strWidth;
00103         }
00104         WinDrawTruncChars( str, len, x, y, availWidth );
00105         x += strWidth; // return x+strWidth; generates larger code
00106         // fall thru
00107 noString:
00108         return x;
00109 }

SourceForge.net Logo