Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Utilities.c
/* |
File: Utilities.c |
Contains: General utility routines |
Written by: Chris White |
Copyright: Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/10/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#pragma segment Core |
// System Includes |
#ifndef __TYPES__ |
#include <Types.h> |
#endif |
#ifndef __TEXTUTILS__ |
#include <TextUtils.h> |
#endif |
#ifndef __DIALOGS__ |
#include <Dialogs.h> |
#endif |
#ifndef __CODEFRAGMENTS__ |
#include <CodeFragments.h> |
#endif |
// Application Includes |
#ifndef __BAREBONES__ |
#include "BareBones.h" |
#endif |
#ifndef __PROTOTYPES__ |
#include "Prototypes.h" |
#endif |
StringPtr CopyPStr ( Str255 inSourceStr, StringPtr outDestStr, SInt16 inDestSize ) |
{ |
SInt8 dataLen = inSourceStr[0] + 1; |
if ( dataLen > inDestSize ) |
dataLen = inDestSize; |
BlockMoveData ( inSourceStr, outDestStr, dataLen ); |
outDestStr[0] = dataLen - 1; |
return outDestStr; |
} |
StringPtr ConcatPStr ( Str255 ioFirstStr, Str255 inSecondStr, SInt16 inDestSize ) |
{ |
SInt8 charsToCopy = inSecondStr[0]; |
if ( ioFirstStr[0] + charsToCopy > inDestSize - 1 ) |
charsToCopy = inDestSize - 1 - ioFirstStr[0]; |
BlockMoveData ( inSecondStr + 1, ioFirstStr + ioFirstStr[0] + 1, charsToCopy ); |
ioFirstStr[0] += charsToCopy; |
return ioFirstStr; |
} |
void OSTypeToPStr ( OSType inOSType, StringPtr outString ) |
{ |
BlockMoveData ( &inOSType, outString + 1, sizeof ( OSType ) ); |
outString[0] = sizeof ( OSType ); |
return; |
} |
void PStrToOSType ( StringPtr inString, OSType* outOSType ) |
{ |
BlockMoveData ( inString + 1, outOSType, sizeof ( OSType ) ); |
return; |
} |
// |
// Tell the user that something went wrong |
// |
void AlertUser ( short messageCode, short errorNum, StringPtr theString ) |
{ |
Str255 messageString; |
Str255 numberString; |
if ( messageCode > 0 ) |
GetIndString ( messageString, kErrorStrings, messageCode ); |
else |
messageString[0] = '\0'; |
if ( errorNum != 0 ) |
NumToString ( errorNum, numberString ); |
else |
numberString[0] = '\0'; |
ParamText ( messageString, numberString, theString, (StringPtr) "\p" ); |
StopAlert ( kErrorDialog, nil ); |
// We need to clear the param text so it isn't used by mistake |
ParamText ( (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p" ); |
return; |
} |
void LocalToGlobalRect ( Rect* theRect ) |
{ |
LocalToGlobal ( (Point*) &theRect->top ); |
LocalToGlobal ( (Point*) &theRect->bottom ); |
return; |
} |
Boolean IsMovableModal ( WindowRef theWindow ) |
{ |
return (GetWVariant ( theWindow ) == movableDBoxProc); |
} |
#if DEBUGGING |
void DebugStrNum ( Str255 str, SInt32 num ) |
{ |
Str255 debug_str, tmp_str; |
BlockMoveData ( &str[0], &debug_str[0], str[0] + 1 ); |
NumToString ( num , &tmp_str[0] ); |
debug_str[debug_str[0] + 1] = ' '; |
BlockMoveData ( &tmp_str[1], &debug_str[debug_str[0] + 2], tmp_str[0] ); |
debug_str[0] = debug_str[0] + tmp_str[0] + 1; |
DebugStr ( debug_str ); |
return; |
} |
#endif |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-30