Beispiel #1
0
static void
SaveButtonClick (void)
{
  DmOpenRef openRef;
  UInt16 recIndex;
  MemHandle recH;
  Err err;

  if (EditorMidi.dbID == 0) {

    debugPrintf("dbID==0, create a new record in Palmano DB\n");
    /* create new record in palmano DB */
 
    err = getPalmanoDatabase(&openRef, dmModeReadWrite | dmModeExclusive);
    if (err != 0) {
      ErrAlert(err);
      return;
    }

    /* allocate new record in DB */
    recIndex = dmMaxRecordIndex;
    recH = DmNewRecord(openRef, &recIndex, 5); /* initial size is 5 bytes */
    ErrFatalDisplayIf(!recH, "SaveButtonClick(): can't get new record by index!");
  }
  else {
    /* replace old song in-place */

    openRef = DmOpenDatabase (EditorMidi.cardNo, EditorMidi.dbID,
			      dmModeReadWrite | dmModeExclusive);

    ErrFatalDisplayIf(!openRef, "SaveButtonClick(): "
		      "Can't open old song database for record");

    err = DmFindRecordByID(openRef, EditorMidi.uniqueRecID, &recIndex);

    ErrFatalDisplayIf(err, "Can't find record by ID");

    recH = DmGetRecord(openRef, recIndex);

    ErrFatalDisplayIf(!recH, "SaveButtonClick(): "
		      "Can't get old song record for writing");
  }

  // save midi to recH
  GetFieldTextToStr(EditorMidi.name, ID_EditorNameField, sndMidiNameLength);

  debugPrintf("SaveButtonClick(): smfutils_save(recH=%lx, name=%s\n",
	      recH, EditorMidi.name);
  smfutils_save(recH, EditorMidi.name, &notelist);
  debugPrintf("SaveButtonClick(): return from smfutils_save()\n");

  DmReleaseRecord (openRef, recIndex, 1);
  DmCloseDatabase (openRef);
  
  FrmGotoForm(ID_MainForm);
}
Beispiel #2
0
Err ZDicFontClose(UInt16 refNum, UInt32 clientContext)
{
	ZDicFontGlobalsType * gP;
	Int16 openCount;
	Int16 contextCount;
	Err err = errNone;

	gP = PrvLockGlobals(refNum);

	/* If not open, return */
	if (!gP)
	{
		/* MUST return zero here to get around a bug in system v1.x that
		 * would cause SysLibRemove to fail. */
		return errNone;
	}

	/* Destroy the client context (we ignore the return code in this implementation) */
	PrvDestroyClientContext(gP, clientContext);

	/* Decrement our library open count */
	gP->openCount--;

	/* Error check for open count underflow */
	ErrFatalDisplayIf(gP->openCount < 0, "ZDicFont open count underflow");

	/* Save the new open count and the context count */
	openCount = gP->openCount;
	contextCount = gP->contextCount;

	PrvUnlockGlobals(gP);

	/* If open count reached zero, free our library globals */
	if ( openCount <= 0 )
	{
		/* Error check to make sure that all client contexts were destroyed */
		ErrFatalDisplayIf(contextCount != 0, "not all client contexts were destroyed");

		/* Free our library globals */
		PrvFreeGlobals(refNum);
	}
	else
	{
		/* return this error code to inform the caller
		 * that others are still using this library */
		err = ZDicFontErrStillOpen;
	}

	return err;
}
Err sbuReceiveResponse( SyncBmrResponse_t **respP ) {

   UInt    cardNo;
   LocalID dbID;
   DWord   result;
   Err     error;

   SyncBmrData_t *dataP;

   sbuFindSyncBmr( &cardNo, &dbID );  // find SyncBmr

   // Allocate memory for SyncBmr comm block
   dataP = (SyncBmrData_t *)MEM_ALLOC( sizeof( SyncBmrData_t ) );
   ErrFatalDisplayIf( !dataP, "memory allocation" );

   MemPtrSetOwner( dataP, 0 );        // set owner of storage to system

   dataP->waitForResponse = true;     // indicate a response is expected
   dataP->requestP        = NULL;     // indicate no document to send
   dataP->responseP       = NULL;     // indicate no document received yet

   // Cause SyncBmr to be programmatically launched
   error = SysAppLaunch( cardNo, dbID,
                         sysAppLaunchFlagNewGlobals,
                         sysAppLaunchSyncBmrReceive,
                         (void *)dataP, &result );

   *respP = (SyncBmrResponse_t *)dataP->responseP;  // return received document

   MEM_FREE( dataP );                               // free SyncBmr comm block

   return 0;

} // sbuSendResponse()
Beispiel #4
0
/* Get current selected note and fill out note properties elements.
   If selected == -1, clear and disable this fields. */
static void
UpdateNoteProperties()
{
  FormPtr frm = FrmGetActiveForm ();

  if (notelist.selected == -1) {
    FrmHideObject(frm, FrmGetObjectIndex(frm, ID_EditorDuration));
    FrmHideObject(frm, FrmGetObjectIndex(frm, ID_EditorVelocity));
    FrmHideObject(frm, FrmGetObjectIndex(frm, ID_EditorPause));
  }
  else {
    NotePtr notes = MemHandleLock(notelist.bufH);
    NotePtr note = notes + notelist.selected;

    ErrFatalDisplayIf(notelist.selected > notelist.num, "Invalid note index!");

    SetFieldTextFromNumber(ID_EditorDuration, note->dur);
    SetFieldTextFromNumber(ID_EditorVelocity, note->vel);
    SetFieldTextFromNumber(ID_EditorPause, note->pause);

    FrmShowObject(frm, FrmGetObjectIndex(frm, ID_EditorDuration));
    FrmShowObject(frm, FrmGetObjectIndex(frm, ID_EditorVelocity));
    FrmShowObject(frm, FrmGetObjectIndex(frm, ID_EditorPause));

    MemPtrUnlock(notes);
  }
}
/*
 * The following functions provide malloc/free support to Metrowerks
 * Standard Library (MSL). This feature requires the MSL library be
 * built with _MSL_OS_DIRECT_MALLOC enabled.
 */
void*
__sys_alloc(size_t size)
{
    void * ptr = MemPtrNew(size);
    ErrFatalDisplayIf(ptr == NULL, "out of memory");
    return ptr;
}
Beispiel #6
0
/***********************************************************************
 *
 * FUNCTION:    PrvCreateTimeZoneArray
 *
 * DESCRIPTION: Create the array of time zone entries from our string
 *		list, gtm offset list, and country list resources. Sort based on
 *		time zone name.
 *
 *	DOLATER kwk - we could save the time zone array we're creating here
 *		in memory, to avoid the performance hit of creating the array.
 *		On the other hand, then the list of names would need to stay
 *		locked down, unless we also copy those into the memory buffer,
 *		which means another 700+ bytes.
 *
 * PARAMETERS:
 *		timeZoneNames	<->	Ptr to returned handle to list of names.
 *		numTimeZones	<->	Ptr to count of number of time zones.
 *
 * RETURNED:
 *		Ptr to allocated array of time zone entry records.
 *
 * HISTORY:
 *		07/31/00	kwk	Created by Ken Krugler.
 *		08/23/00	kwk	Fixed bug where release ROMs caused ErrNonFatalDisplayIf
 *							to become a no-op, and thus the country and time zone
 *							offset list ptrs weren't skipping the count word.
 *
 ***********************************************************************/
static TimeZoneEntryType* PrvCreateTimeZoneArray(MemHandle* timeZoneNames, UInt16* numTimeZones)
{
	const Char* tzNamesP;
	TimeZoneEntryType* tzEntries;
	MemHandle offsetsH;
	MemHandle countriesH;
	UInt16* resP;
	Int16* gmtOffsetsP;
	UInt16* countriesP;
	UInt16 i;
	
	// Specify the number of items in the list, based on total # of items
	// in our time zone name list resource.
	*timeZoneNames = DmGetResource(strListRscType, TimeZoneNamesStringList);
	ErrNonFatalDisplayIf(*timeZoneNames == NULL, "No time zone names");
	tzNamesP = (const Char*)MemHandleLock(*timeZoneNames);
	
	// Skip over prefix string, then get the entry count.
	tzNamesP += StrLen(tzNamesP) + 1;
	*numTimeZones = *tzNamesP++;
	*numTimeZones = (*numTimeZones << 8) +  *tzNamesP++;
	
	// Allocate the array of time zone records.
	tzEntries = (TimeZoneEntryType*)MemPtrNew(*numTimeZones * sizeof(TimeZoneEntryType));
	ErrFatalDisplayIf(tzEntries == NULL, "Out of memory");
	
	// Find and lock down the gtm offset and country integer lists.
	offsetsH = DmGetResource(wrdListRscType, TimeZoneGMTOffsetsList);
	ErrNonFatalDisplayIf(offsetsH == NULL, "No time zone offsets");
	resP = (UInt16*)MemHandleLock(offsetsH);
	ErrNonFatalDisplayIf(*resP != *numTimeZones, "GMT offset count != name count");
	
	// Skip count at start of list.
	gmtOffsetsP = (Int16*)resP + 1;
	
	countriesH = DmGetResource(wrdListRscType, TimeZoneCountriesList);
	ErrNonFatalDisplayIf(countriesH == NULL, "No time zone countries");
	resP = (UInt16*)MemHandleLock(countriesH);
	ErrNonFatalDisplayIf(*resP != *numTimeZones, "Time zone country count != name count");
	
	// Skip count at start of list.
	countriesP = resP + 1;
	
	// Now loop to fill in all of the records.
	for (i = 0; i < *numTimeZones; i++)
	{
		tzEntries[i].tzName = tzNamesP;
		tzNamesP += StrLen(tzNamesP) + 1;
		tzEntries[i].tzOffset = gmtOffsetsP[i];
		tzEntries[i].tzCountry = (CountryType)countriesP[i];
	}
	
	MemHandleUnlock(offsetsH);
	MemHandleUnlock(countriesH);
	
	// Now sort the list, based on the time zone name.
	SysQSort(tzEntries, *numTimeZones, sizeof(TimeZoneEntryType), PrvCompareTimeZoneEntries, 0);
	
	return(tzEntries);
} // PrvCreateTimeZoneArray
Beispiel #7
0
static ZDicFontClientContextType * PrvLockContext(UInt32 context)
{
	ZDicFontClientContextType *	contextP = NULL;

	/* Error-check our parameters */
	ErrFatalDisplayIf(context == 0, "null client context");

	/* Lock the client context */
	contextP = (ZDicFontClientContextType *)MemHandleLock((MemHandle)context);
	ErrFatalDisplayIf(contextP == NULL, "failed to lock client context");

	/* Validate the client context */
	ErrFatalDisplayIf(contextP->libSignature != (void *)&ZDicFontOpen,
		"invalid client context");

	return( contextP );
}
Beispiel #8
0
static ZDicFontGlobalsType * PrvMakeGlobals(UInt16 refNum)
{
	ZDicFontGlobalsType * gP = NULL;
	MemHandle gH;
	SysLibTblEntryType * libEntryP;

	/* Get library globals */
	libEntryP = SysLibTblEntry(refNum);
	ErrFatalDisplayIf(libEntryP == NULL, "invalid ZDicFont refNum");

	/* Error check to make sure the globals don't already exist */
	ErrFatalDisplayIf(libEntryP->globalsP, "ZDicFont globals already exist");

	/* Allocate and initialize our library globals. */
	gH = MemHandleNew(sizeof(ZDicFontGlobalsType));
	if ( !gH )
		return( NULL );

	/* Save the handle of our library globals in the system library table  */
	/* entry so we can later retrieve it using SysLibTblEntry(). */
	libEntryP->globalsP = (void*)gH;

	/* Lock our globals (should not fail) */
	gP = PrvLockGlobals(refNum);
	ErrFatalDisplayIf(gP == NULL, "failed to lock ZDicFont globals");

	/* Set the owner of our globals memory chunk to "system" (zero), so it won't get
	 * freed automatically by Memory Manager when the first application to call
	 * ZDicFontOpen exits.  This is important if the library is going to stay open
	 * between apps. */
	MemPtrSetOwner(gP, 0);

	/* Initialize our library globals */
	MemSet(gP, sizeof(ZDicFontGlobalsType), 0);

	/* for convenience and debugging, save ref in globals structure */
	gP->thisLibRefNum = refNum;

	/* initial open count */
	gP->openCount = 0;

	/* return a pointer to our *locked* globals */
	return( gP );
}
Beispiel #9
0
FlickrGlobals* PrvLockGlobals(UInt16 refNum)
{
    SysLibTblEntryType* libEntry = SysLibTblEntry(refNum);
    ErrFatalDisplayIf(libEntry == NULL, "invalid InfoMan Flickr Uploader refNum");

    MemHandle handle = (MemHandle)libEntry->globalsP;
    if (NULL == handle)
        return NULL;

    return (FlickrGlobals*)MemHandleLock(handle);
}
Beispiel #10
0
static Err PrvCreateClientContext(ZDicFontGlobalsType * gP, UInt32 * clientContextP)
{
	Err err = errNone;
	MemHandle contextH;
	ZDicFontClientContextType * contextP;

	/* Error-check our parameters */
	ErrFatalDisplayIf(gP == NULL, "null globals pointer");
	ErrFatalDisplayIf(clientContextP == NULL, "null context variable pointer");

	/* Initialize return variable */
	*clientContextP = 0;

	/* Allocate a new client context structure */
	contextH = MemHandleNew(sizeof(ZDicFontClientContextType));
	if ( !contextH )
	{
		err = memErrNotEnoughSpace;
	}
	else
	{
		/* save context chunk handle in return variable */
		*clientContextP = (UInt32)contextH;

		/* Initialize the context chunk */
		contextP = (ZDicFontClientContextType *)MemHandleLock(contextH);

		/* save address of open routine as signature to validate context */
		contextP->libSignature = (void *)&ZDicFontOpen;

		/* TODO: Insert code to initialize context members */

		PrvUnlockContext(contextP);

		/* increment context count (for debugging) */
		gP->contextCount++;
		ErrFatalDisplayIf(gP->contextCount == 0, "context count overflow");
	}

	return( err );
}
Beispiel #11
0
static Err PrvDestroyClientContext(ZDicFontGlobalsType * gP, UInt32 clientContext)
{
	ZDicFontClientContextType *	contextP;

	/* Error-check our parameters */
	ErrFatalDisplayIf(gP == NULL, "null globals pointer");

	/* Validate the client context by locking it */
	contextP = PrvLockContext(clientContext);

	if ( contextP )
	{
		/* freeing a locked chunk is permitted by the system */
		MemPtrFree(contextP);

		/* decrement context count (for debugging) */
		gP->contextCount--;
		ErrFatalDisplayIf(gP->contextCount < 0, "context count underflow");
	}

	return errNone;
}
Beispiel #12
0
/************************************************************
 *
 *  FUNCTION: StrCopy
 *
 *  DESCRIPTION: Copies 1 string to another
 *
 *  PARAMETERS: 2 string pointers
 *
 *  RETURNS: pointer to dest string
 *
 *  CREATED: 11/09/94 
 *
 *  BY: Ron Marianetti
 *
 *************************************************************/
Char* StrCopy(Char* dst, const Char* src)
{
	Char*	tmp = dst;

	ErrFatalDisplayIf((dst == NULL) || (src == NULL), "NULL string passed");
	
	while (*src)
	{
		*tmp++ = *src++;
	}
	
	*tmp = 0;
	return(dst);
}
Beispiel #13
0
/*!
 * \brief the hold switch has been flipped
 * \param npp the notification
 * \return ErrNone if it's all OK
 */
static Err
PrvHoldNotificationHandler(SysNotifyParamType *npp)
{
	UInt32 held;

	if (npp->broadcaster != sonySysNotifyBroadcasterCode)
		return (errNone);
	held = ((SonySysNotifyHoldStatusChangeDetailsP)
	    (npp->notifyDetailsP))->holdOn;
	ErrFatalDisplayIf(holdCB == NULL,
	    "Received hold call without valid handler");
	if (holdCB != NULL)
		holdCB(held);
	return (errNone);
}
Beispiel #14
0
/*
 * FUNCTION: PrvMakeGlobals
 *
 * DESCRIPTION: Create our library globals.
 *
 * PARAMETERS:
 *
 * refNum
 *		Library reference number returned by SysLibLoad() or SysLibFind().
 *
 * CALLED BY: internal
 *
 * RETURNS:
 *
 *		pointer to our *locked* library globals
 *		NULL if our globals	could not be created.
 */
FlickrGlobals* PrvMakeGlobals(UInt16 refNum)
{
    SysLibTblEntryType* libEntry = SysLibTblEntry(refNum);
    ErrFatalDisplayIf(libEntry == NULL, "invalid InfoMan Flickr Uploader refNum");

    /* Error check to make sure the globals don't already exist */
    ErrFatalDisplayIf(libEntry->globalsP != NULL, "InfoMan Flickr Uploader globals already exist");

    /* Allocate and initialize our library globals. */
    MemHandle handle = MemHandleNew(sizeof(FlickrGlobals));
    if (NULL == handle)
        return NULL;

    FlickrGlobals* globals = (FlickrGlobals*)MemHandleLock(handle);
    if (NULL == globals)
    {
        MemHandleFree(handle);
        return NULL;
    }

    Err err = globals->Init(refNum);
    if (errNone != err)
    {
        MemPtrUnlock(globals);
        MemHandleFree(handle);
        return NULL;
    }

    /* Set the owner of our globals memory chunk to "system" (zero), so it won't get
     * freed automatically by Memory Manager when the first application to call
     * FlickrOpen exits.  This is important if the library is going to stay open
     * between apps. */
    MemPtrSetOwner(globals, 0);
    libEntry->globalsP = (MemPtr)handle;
    return globals;
}
Err sbuFindSyncBmr( UInt *theCardNum, LocalID *theDbID ) {

   UInt              cardNo;
   LocalID           dbID;
   DmSearchStateType searchState;

   DmGetNextDatabaseByTypeCreator( true, &searchState, sysFileTApplication,
                                   SYNC_BMR_ID, true, &cardNo, &dbID );

   ErrFatalDisplayIf( !dbID, "required component missing" );

   *theCardNum = cardNo;  // return the card number
   *theDbID    = dbID;    // return the database id

   return 0;

} // sbuFindSyncBmr()
Beispiel #16
0
TDataMgr::TDataMgr(const char* dbName, UInt32 creator) :
    m_db(NULL)
{
    LocalID dbId = DmFindDatabase(0, dbName);
    if (dbId == 0) {
        Err err = DmCreateDatabase(0, dbName, creator, 'DATA', false);
        if (err == errNone) {
            dbId = DmFindDatabase(0, dbName);
        }
    }

    if (dbId != 0) {
        m_db = DmOpenDatabase(0, dbId, dmModeReadWrite);
    }

    ErrFatalDisplayIf(m_db == NULL, "cannot open db");
}
Beispiel #17
0
void PrvFreeGlobals(UInt16 refNum)
{
    SysLibTblEntryType* libEntry = SysLibTblEntry(refNum);
    ErrFatalDisplayIf(libEntry == NULL, "invalid InfoMan Flickr Uploader refNum");
    MemHandle handle = (MemHandle)libEntry->globalsP;
    if (NULL != handle)
    {
        FlickrGlobals* globals = (FlickrGlobals*)MemHandleLock(handle);
        if (NULL != globals)
        {
            globals->Dispose();
            MemPtrUnlock(globals);
        }
        libEntry->globalsP = NULL;
        MemHandleFree(handle);
    }
}
Beispiel #18
0
Err ZDicFontOpen(UInt16 refNum, UInt32 *clientContextP)
{
	ZDicFontGlobalsType *gP;
	Err err = errNone;
	Int16 originalOpenCount = 0;

	/* Error-check our parameters */
	ErrFatalDisplayIf(
		clientContextP == NULL, 
		"null context variable pointer");

	/* Initialize return variable */
	*clientContextP = 0;

	/* Get library globals */
	gP = PrvLockGlobals(refNum);

	/* Check if already open */
	if (!gP)
	{
		/* Allocate and initialize our library globals. */
		gP = PrvMakeGlobals(refNum);
		if ( !gP )
			err = memErrNotEnoughSpace;
	}

	/* If we have globals, create a client context, increment open
	 * count, and unlock our globals */
	if ( gP )
	{
		originalOpenCount = gP->openCount;

		err = PrvCreateClientContext(gP, clientContextP);
		if ( !err )
			gP->openCount++;

		PrvUnlockGlobals(gP);

		/* If there was an error creating a client context and there  */
		/* are no other clients, free our globals */
		if ( err && (originalOpenCount == 0) )
			PrvFreeGlobals(refNum);
	}

	return( err );
}
Beispiel #19
0
Err FlickrClose(UInt16 refNum)
{
    FlickrGlobals * gP;
    Int16 openCount;
    Err err = errNone;

    DMSG("FlickrClose() enter\n");
    gP = PrvLockGlobals(refNum);

    /* If not open, return */
    if (!gP)
    {
    	/* MUST return zero here to get around a bug in system v1.x that
    	 * would cause SysLibRemove to fail. */
    	return errNone;
    }

    /* Decrement our library open count */
    gP->openCount--;

    /* Error check for open count underflow */
    ErrFatalDisplayIf(gP->openCount < 0, "InfoMan Flickr Uploader open count underflow");

    /* Save the new open count and the context count */
    openCount = gP->openCount;

    PrvUnlockGlobals(gP);

    /* If open count reached zero, free our library globals */
    if ( openCount <= 0 )
    {
    	/* Free our library globals */
    	PrvFreeGlobals(refNum);
    }
    else
    {
    	/* return this error code to inform the caller
    	 * that others are still using this library */
    	err = flickrErrStillOpen;
    }

    DMSG("FlickrClose() exit\n");
    return err;
}
Beispiel #20
0
/***********************************************************************
 *
 * FUNCTION:    ThumbnailViewScroll
 *
 * DESCRIPTION: This routine scrolls the list of of memo titles
 *              in the direction specified.
 *
 * PARAMETERS:  linesToScroll - the number of lines to scroll
 *                              positve: down, negative: up
 *
 * RETURNED:    nothing
 *
 ***********************************************************************/
static void ThumbnailViewScroll(Int16 linesToScroll) {
  UInt16 newTopVisibleRecord = d.top_visible_record;
  FormType* frm = FrmGetActiveForm();

  p.dbI = noRecordSelected;

  /* Scroll down. */
  if (linesToScroll > 0)
    SeekRecord (&newTopVisibleRecord, linesToScroll * recordsPerRow, dmSeekForward);

  /* Scroll up. */
  else if (linesToScroll < 0)
    SeekRecord (&newTopVisibleRecord, -linesToScroll * recordsPerRow, dmSeekBackward);

  ErrFatalDisplayIf (d.top_visible_record == newTopVisibleRecord, "Invalid scroll value");

  SetTopVisibleRecord(newTopVisibleRecord);

  ThumbnailViewLoadGadgets(frm);
}
Beispiel #21
0
/************************************************************
 *
 *  FUNCTION: ApptGetRecord
 *
 *  DESCRIPTION: Get a record from a Appointment Database
 *
 *  PARAMETERS: database pointer
 *                  database index
 *                  database record
 *
 *  RETURNS: ##0 if successful, errorcode if not
 *
 *  CREATED: 1/25/95 
 *
 *  BY: Roger Flores
 *
 *************************************************************/
Err ApptGetRecord (DmOpenRef dbP, UInt16 index, ApptDBRecordPtr r,
                   MemHandle * handleP) {
    MemHandle handle;
    ApptPackedDBRecordPtr src;

    handle = DmQueryRecord(dbP, index);
    ErrFatalDisplayIf(DmGetLastErr(), "Error Querying record");

    src = (ApptPackedDBRecordPtr) MemHandleLock (handle);

    if (DmGetLastErr()) {
        *handleP = 0;
        return DmGetLastErr();
    }

    ApptUnpack(src, r);

    *handleP = handle;
    return 0;
}
Beispiel #22
0
static void PrvFreeGlobals(UInt16 refNum)
{
	MemHandle gH;
	SysLibTblEntryType * libEntryP;

	/* Get our library globals handle */
	libEntryP = SysLibTblEntry(refNum);
	ErrFatalDisplayIf(libEntryP == NULL, "invalid ZDicFont refNum");

	gH = (MemHandle)(libEntryP->globalsP);

	/* Free our library globals */
	if ( gH )
	{
		/* clear our globals reference */
		libEntryP->globalsP = NULL;

		/* free our globals */
		MemHandleFree(gH);
	}
}
Beispiel #23
0
Err
loadHiRes(void)
{
	SonySysFtrSysInfoP sonySysFtrSysInfoP;
	Err error = 0;
	UInt16 refNum;

	if (highDensityFeatureSet() != 0)
		return (errNone);
	if ((error = FtrGet(sonySysFtrCreator,
		sonySysFtrNumSysInfoP, (UInt32*)&sonySysFtrSysInfoP))) {
		/* Not CLIE: maybe not available */
	} else {
		if (sonySysFtrSysInfoP->libr & sonySysFtrSysInfoLibrHR) {
			/* HR available */
			if ((error = SysLibFind(sonySysLibNameHR, &refNum))) {
				if (error == sysErrLibNotFound) {
				/* couldn't find lib */
				error = SysLibLoad('libr', sonySysFileCHRLib,
				    &refNum);
				}
				if (!error) didl = 1;
			}
			if (!error) {
				hires = refNum;
				/* Now we can use HR lib */
				HROpen(hires);
			}
			ErrFatalDisplayIf(error, "could not load hires lib");
		}
	}
	if (!error)
		error = goHires();

	return (error);
}
Beispiel #24
0
static void SetField(UInt16 formID, UInt16 fieldID, const char *str)
{
    FormPtr frm;
    FieldPtr fld;
    UInt16 obj;
    CharPtr p;
    VoidHand h;
	
    frm = FrmGetFormPtr(formID);
    obj = FrmGetObjectIndex(frm, fieldID);
    fld = (FieldPtr)FrmGetObjectPtr(frm, obj);
    h = (VoidHand)FldGetTextHandle(fld);
    if (h == NULL)
    {
	h = MemHandleNew (FldGetMaxChars(fld)+1);
	ErrFatalDisplayIf(!h, "No Memory");
    }
	
    p = (CharPtr)MemHandleLock(h);
    StrCopy(p, str);
    MemHandleUnlock(h);
	
    FldSetTextHandle(fld, (Handle)h);
}
Beispiel #25
0
/***********************************************************************
 *
 * FUNCTION:    ApptGetAppointments
 *
 * DESCRIPTION: This routine returns a list of appointments that are on 
 *              the date specified
 *
 * PARAMETERS:  dbP    - pointer to the database
 *              date   - date to search for
 *              countP - number of appointments on the specified 
 *                       day (returned value)
 *
 * RETURNED:    handle of the appointment list (ApptInfoType)
 *
 * REVISION HISTORY:
 *          Name    Date        Description
 *          ----    ----        -----------
 *          art     6/15/95     Initial Revision
 *
 ***********************************************************************/
MemHandle ApptGetAppointments (DmOpenRef dbP, DateType date, UInt16 * countP) {
    Err error;
    Int16 result;
    Int16 count = 0;
    UInt16    recordNum;
    Boolean repeats;
    MemHandle recordH;
    MemHandle apptListH;
    ApptInfoPtr apptList;
    ApptDBRecordType apptRec;
    ApptPackedDBRecordPtr r;

    // Allocated a block to hold the appointment list.
    apptListH = MemHandleNew (sizeof (ApptInfoType) * apptMaxPerDay);
    ErrFatalDisplayIf(!apptListH, "Out of memory");
    if (! apptListH) return (0);

    apptList = MemHandleLock (apptListH);

    // Find the first non-repeating appointment of the day.
    if (ApptFindFirst (dbP, date, &recordNum)) {
        while (count < apptMaxPerDay) {
            // Check if the appointment is on the date passed, if it is
            // add it to the appointment list.
            recordH = DmQueryRecord (dbP, recordNum);
            r = MemHandleLock (recordH);
            result = DateCompare (r->when.date, date);

            if (result == 0) {
                // Add the record to the appoitment list.
                apptList[count].startTime = r->when.startTime;
                apptList[count].endTime = r->when.endTime;
                apptList[count].recordNum = recordNum;
                count++;
            }
            MemHandleUnlock (recordH);
            if (result != 0) break;

            // Get the next record.
            error = DmSeekRecordInCategory (dbP, &recordNum, 1,
                                            dmSeekForward,
                                            dmAllCategories);
            if (error == dmErrSeekFailed) break;
        }
    }

    // Add the repeating appointments to the list.  Repeating appointments
    // are stored at the beginning of the database.
    recordNum = 0;
    while (count < apptMaxPerDay) {
        recordH = DmQueryNextInCategory (dbP, &recordNum, dmAllCategories);
        if (! recordH) break;
        
        r = (ApptPackedDBRecordPtr) MemHandleLock (recordH);
        
        repeats = (r->flags.repeat != 0);
        if (repeats) {
            ApptUnpack (r, &apptRec);
            if (ApptRepeatsOnDate (&apptRec, date)) {
                // Add the record to the appoitment list.
                apptList[count].startTime = r->when.startTime;              
                apptList[count].endTime = r->when.endTime;              
                apptList[count].recordNum = recordNum;  
                count++;
            }
        }
        MemHandleUnlock (recordH);

        // If the record has no repeating info we've reached the end of the 
        // repeating appointments.
        if (! repeats) break;
        
        recordNum++;
    }

    // Sort the list by start time.
    // SysInsertionSort (apptList, count, sizeof (ApptInfoType),
    //          ApptListCompare, 0L);

    // If there are no appointments on the specified day, free the appointment
    // list.
    if (count == 0) {
        MemPtrFree (apptList);
        apptListH = 0;
    }
    // Resize the appointment list block to release any unused space.
    else {
        MemHandleUnlock (apptListH);
        MemHandleResize (apptListH, count * sizeof (ApptInfoType));
    }

    *countP = count;
    return (apptListH);
}
Beispiel #26
0
Boolean CBiddingForm::OnNilEvent(EventPtr pEvent, Boolean& bHandled) {

	if ( gManager->Status() == GetHandBids ) {

		HighlightActiveBidder();

		FormPtr frmP = FrmGetActiveForm();

		Int16 player_index = (*gManager->tbl->current_bidder)->playerIndex;


		//
		// if this is a human player, we need to render the screen widgets for their bid
		//
		if ( player_index == gManager->humanIndex && player_has_bid == false ) {

			player_hand.Render(true);

			Int16 current_bid = 0;

			if ( (*gManager->tbl->dealer)->playerIndex != gManager->humanIndex || ! gManager->dealer_take_bid ) {
				current_bid = gManager->tbl->high_bid;
			}
			else {
				current_bid = gManager->tbl->high_bid - 1;
			}
			
			if ( (*gManager->tbl->dealer)->playerIndex == gManager->humanIndex && gManager->tbl->high_bid < 2 ) {
				CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false);	
				CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-");
				CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false);
				CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-");
				CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), false);
				CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), "-Pass-");
			}
			else {
				switch (current_bid) {
					case 5:
						CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), false);	
						CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), "-S-");
					case 4:
						CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false);	
						CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-");
					case 3:
						CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false);
						CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-");
					case 2:
						CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), false);
						CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), "-2-");
				}
			}

		} // if if ( player_index == 3 && player_has_bid == false )


		//
		// handle processing actual bids here - get one automatically if this player isn't
		// a human, or if the human has already bid
		//
		if ( player_index != gManager->humanIndex || player_has_bid == true ) {

			Boolean player_did_bid = gManager->GetNextBid(gManager->trk, false );
			Int16 tmp_bid = (*gManager->tbl->current_bidder)->Bid();

			if ( player_did_bid && 
					gManager->tbl->current_bidder == gManager->tbl->winning_bidder &&
					(tmp_bid >= 2) ) {

				char x[10];
				StrPrintF(x, "bids %d", tmp_bid );
				bidstr = x;
			}
			else {
				bidstr = "passes";
			}
				
			bids[(*gManager->tbl->current_bidder)->playerIndex].Replace(bidstr);


			//
			// if we just got the dealer's bid, then we are all done
			//
			if ( gManager->tbl->current_bidder == gManager->tbl->dealer ) {

				//
				// at this point we need to set trump...
				//	
				gManager->Status(SetHandTrump);


				if ( (*gManager->tbl->winning_bidder)->playerIndex == gManager->humanIndex ) {
					CPlayerTrumpForm frmPlayerTrump;
					frmPlayerTrump.DoModal();
				}

				FrmDrawForm(frmP);

				//
				// ... and display the final results
				//

				Card::suit_t foo = (*gManager->tbl->winning_bidder)->Trump();
				gManager->tbl->trump = foo;
				gManager->trk->no_trump_first_trick = (*gManager->tbl->winning_bidder)->NoTrumpFirstTrickP();

				MemHandle hRsc;
				BitmapType* bitmapP;

				switch ( gManager->tbl->trump ) {

					case Card::heart:
						hRsc = DmGetResource(bitmapRsc, HeartBitmapFamily );
						break;
					case Card::diamond:
						hRsc = DmGetResource(bitmapRsc, DiamondBitmapFamily );
						break;
					case Card::club:
						hRsc = DmGetResource(bitmapRsc, ClubBitmapFamily );
						break;
					case Card::spade:
						hRsc = DmGetResource(bitmapRsc, SpadeBitmapFamily );
						break;
				}

				if ( gManager->trk->no_trump_first_trick ) {
					FrmCustomAlert(NoTrumpFirstTrickAlert, (*gManager->tbl->winning_bidder)->name, "", "");
				}


				RectangleType bounds;

				UInt16 gadgetIndex = FrmGetObjectIndex(frmP, BiddingTrumpGadget);
				FrmGetObjectBounds(frmP, gadgetIndex, &bounds);
				WinPaintChars("Trump Is: ", StrLen("Trump Is: "), bounds.topLeft.x, bounds.topLeft.y );

				ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource");
				bitmapP = (BitmapType*) MemHandleLock(hRsc);
				WinDrawBitmap (bitmapP, bounds.topLeft.x + 40, bounds.topLeft.y);
				MemHandleUnlock(hRsc);
				DmReleaseResource(hRsc);

				UInt32 hsStatusVersion;
				
				if (FtrGet (hsFtrCreator, hsFtrIDNavigationSupported, &hsStatusVersion) == 0) {
					FrmGlueNavObjectTakeFocus(FrmGetActiveForm(), BiddingOKButton );
				}

			
			} // if ( dealer bid )

			else {

				// move along to the next player
				gManager->tbl->current_bidder = gManager->getNextPlayerIter(gManager->tbl->current_bidder);

				EventType event;
				event.eType = nilEvent;
				EvtAddEventToQueue (&event);

				// pause here
//				SysTaskDelay(SysTicksPerSecond());
				gManager->ShortDelay();
			
			}


		} // if ( player_index != 3 || player_has_bid == true )


	} // if GetHandBids

	bHandled = false;
	return true;
}
Beispiel #27
0
void DialogOK ( Word frmname, Short p1, Short p2 ) {
    FormPtr prevForm, frm;
    Word hitButton;
    Char msg[(MaxName * 2) + 128];
    Word fieldname = 0;

    switch ( frmname ) {
    case frmNextPlayer:
        fieldname = fldNextPlayer;
        if( (stor.numplayers + stor.numcomputers) > 1 ) {
            StrPrintF( msg, NextPlayerString,
                       stor.player[p1].name,
                       stor.player[p2].name,
                       NULL);
        } else {
            StrPrintF( msg, "%s", NextSoloPlayerString, NULL );
        }
        break;

    case frmSuspend:
        if( (stor.numplayers + stor.numcomputers) == 1 ) {
            return;
        }
        fieldname = fldSuspend;
        StrPrintF( msg, SuspendString,
                   stor.player[p1].name,
                   stor.player[p2].name,
                   NULL);
        break;


    case frmLost:
        fieldname = fldLost;
        StrPrintF( msg, LostString, stor.player[p1].name, NULL );
        break;

    case frmLeader:
        fieldname = fldLeader;
        StrPrintF( msg, LeaderString, stor.player[p1].name, NULL );
        break;

    case frmWinner:
        fieldname = fldWinner;
        StrPrintF( msg, WinnerString, stor.player[p1].name, NULL );
        break;

    case frmNobodyWon:
        fieldname = fldNobodyWon;
        StrPrintF( msg, NobodyWonString, NULL );
        break;

    case frmBump:
        fieldname = fldBump;
        StrPrintF( msg, BumpString,
                   stor.player[p2].name,
                   stor.player[p1].name,
                   stor.player[p2].score,
                   stor.player[p1].score,
                   NULL );
        break;

    case frmSampler:
        fieldname = fldSampler;
        StrPrintF( msg, SamplerString, stor.player[p1].name, NULL );
        break;


    case frmTrainWreck:
        fieldname = fldTrainWreck;
        StrPrintF( msg, TrainWreckString,
                   stor.player[p1].name,
                   stor.player[p1].TWcount,
                   stor.nTrainWrecks,
                   NULL );
        break;

    default:
        ErrDisplay( "DialogOK: fall through: Programmer sucks." );
        return;
    }

    // Save previous form
    prevForm = FrmGetActiveForm();
    // Init new form
    frm = FrmInitForm( frmname );

    // Set it
    FrmSetActiveForm(frm);
    FrmDrawForm(frm);


    // Fill it...
    ErrFatalDisplayIf( fieldname == 0,
                       "DialogOK: ZeroField: Programmer sucks." );
    SetFieldTextFromStr( fieldname, msg );

    // Set the handler
    // FrmSetEventHandler(frm, DialogNewGameHandleEvent);

    hitButton = FrmDoDialog(frm);

    // Delete the form, we're not using it
    FrmDeleteForm(frm);

    // Restore previous form.
    if (prevForm) {
        FrmSetActiveForm(prevForm);
    }

    // We don't care about which button, there is only one.
}
Beispiel #28
0
/************************************************************
 *
 * FUNCTION:	StrNCopy
 *
 * DESCRIPTION: Copies up to N characters from srcP string to
 *		dstP string. It does NOT null terminate if N characters
 *		were copied, see history comment.
 *
 * PARAMETERS:
 *		dstP - destination string
 *		srcP - source string
 *		n   - max # of bytes to copy from srcP string
 *
 * RETURNS: pointer to dest string
 *
 *	HISTORY:
 *		05/06/96	ron	Created by Ron Marianetti.
 *		10/24/96	rsf	Fill all of dest
 *		12/18/96	vmk	Removed ec code -- it was trashing data during
 *							"copy in place" operations
 *		08/12/97	ADH	Modified test for null termination to comply with
 *							ANSI specifications.
 *		05/13/00	kwk	Made it work for all char encodings, not just Latin.
 *		11/02/00	kwk	Cast src to unsigned before comparing to kTxtMaxNeverMultiByte.
 *		01/02/01	rsf	Fix bug reading from srcP when n is 0.  Found by Scott Maxwell.
 *
 *************************************************************/
Char* StrNCopy(Char* dstP, const Char* srcP, Int16 n)
{
	Char*	tmp = dstP;
	const Char* src = srcP;
#if (ERROR_CHECK_LEVEL == ERROR_CHECK_FULL)
	Char*	endDestP = dstP + n;
#endif		
	
	// Check for err
	ErrFatalDisplayIf((dstP == NULL) || (srcP == NULL), "NULL string passed");
	
	// Copy N characters from src string
	while (n > 0 && *src)
	{
		*tmp++ = *src++;
		--n;
	}
	
	// Terminate dest string if there's space.
	if (n > 0) 
	{
		*tmp = '\0';
	}
	else if (*(UInt8*)src > kTxtMaxNeverMultiByte)
	{
		// We stopped copying because we had moved N bytes, but we
		// haven't yet hit the end of the source string. This means
		// that the last character copied might be a partial character,
		// if the first uncopied byte could be part of a mult-byte char.
		// We need to find the bounds of the last character in the
		// source string.
		UInt32 offset = src - srcP;
		UInt32 charStart, charEnd;
		TxtCharBounds(srcP, offset, &charStart, &charEnd);
		
		// If we were in the middle of a character, we want to null-
		// terminate the destination string just in case the caller
		// jams a null at dstP[n] in an attempt to terminate the
		// string, as otherwise we would still wind up with an invalid
		// (partial) character at the end. This also sets up properly
		// for the subsequent error check buffer-filling code.
		if (charStart < offset)
		{
			tmp = dstP + charStart;
			*tmp = '\0';
		}
	}
	
	// Fill up the unused dest buffer with bytes to reveal errors.
	// Only copy over the remaining unused bytes.  This works correctly when
	// the src and dest overlap.
#if (ERROR_CHECK_LEVEL == ERROR_CHECK_FULL)
	tmp++; // Advance past null
	if (tmp < endDestP)
	{
		// In debug ROMs MemSet will complain if the unused dest buffer was cleared before.
		// This is common when copying many strings.  Add some extra code to work around it.
		tmp[0] = 0;
		
		// Fill up the destination as much as allowed with a value to reveal errors.
		MemSet(tmp, endDestP - tmp, 0xfe);
	}
#endif
	
	return(dstP);
} // StrNCopy
Beispiel #29
0
void CGameForm::OnDraw() {

	played_cards.Render(true);
	player_hand.Render(true);

	char bid_trump_str[2];
	StrPrintF(bid_trump_str, "%d", gManager->tbl->bid  );

	FormPtr frmP = FrmGetActiveForm();
/*
	RectangleType bounds;
	UInt16 gadgetIndex = FrmGetObjectIndex( frmP, MainBidTrumpGadget );
	FrmGetObjectBounds(frmP, gadgetIndex, &bounds);

	// draw the bid
	char bidval = bid_trump_str[0];
	WinPaintChar( bidval, bounds.topLeft.x, bounds.topLeft.y );

	Card foo(gManager->trk->getTrump(), (Card::face_t)1 );

	// now, draw the suit
	MemHandle hRsc = DmGetResource(bitmapRsc, foo.SuitBitmap(false) );
	ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource");
	BitmapType* bitmapP = (BitmapType*) MemHandleLock(hRsc);

	WinPaintBitmap (bitmapP, bounds.topLeft.x + 6, bounds.topLeft.y);

	MemHandleUnlock(hRsc);
	DmReleaseResource(hRsc);
*/
	// handle MainBidTrumpGadget here also
	MemHandle hRsc;
	BitmapType* bitmapP;

	switch ( gManager->tbl->trump ) {

		case Card::heart:
			hRsc = DmGetResource(bitmapRsc, HeartBitmapFamily );
			break;
		case Card::diamond:
			hRsc = DmGetResource(bitmapRsc, DiamondBitmapFamily );
			break;
		case Card::club:
			hRsc = DmGetResource(bitmapRsc, ClubBitmapFamily );
			break;
		case Card::spade:
			hRsc = DmGetResource(bitmapRsc, SpadeBitmapFamily );
			break;
	}

	RectangleType bounds;

//	FormPtr frmP = FrmGetActiveForm();
	UInt16 gadgetIndex = FrmGetObjectIndex(frmP, MainBidTrumpGadget);
	FrmGetObjectBounds(frmP, gadgetIndex, &bounds);
	char bidstr[4];
	StrPrintF(bidstr, "%d", gManager->tbl->bid);
	WinPaintChar(bidstr[0], bounds.topLeft.x, bounds.topLeft.y );

	ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource");
	bitmapP = (BitmapType*) MemHandleLock(hRsc);
	WinDrawBitmap (bitmapP, bounds.topLeft.x + FntCharWidth(bidstr[0]) + 1, bounds.topLeft.y);
	MemHandleUnlock(hRsc);
	DmReleaseResource(hRsc);

}
Beispiel #30
0
/************************************************************
 *
 * FUNCTION: StrNCat
 *
 * DESCRIPTION: Concatenates 1 string to another clipping the
 *		destination string to a max of N characters (including null
 *		at end).
 *
 * PARAMETERS:
 *		dstP	<-> String to receive catenated result.
 *		srcP	 -> String to catenate to the end of dstP.
 *		n		 -> Max length of resulting string, including null byte.
 *
 * RETURNS:	pointer to dest string
 *
 * HISTORY:
 *		11/09/94	ron	Created by Ron Marianetti
 *		10/24/96	rsf	Added ec code
 *		12/18/96	vmk	Removed ec code -- it was trashing data during
 *							"copy in place" operations
 *		05/13/00	kwk	Made it work for all char encodings, not just Latin.
 *		11/02/00	kwk	Cast src to unsigned before comparing to kTxtMaxNeverMultiByte.
 *		01/02/01	rsf	Fix bug reading from srcP when n is 0.
 *
 *************************************************************/
Char* StrNCat(Char* dstP, const Char* srcP, Int16 n)
{
	Char*			tmp;
	const Char*	savedSrcP;
	Int16			len;
#if (ERROR_CHECK_LEVEL == ERROR_CHECK_FULL)
	Char*			endDstP;
#endif		
	
	
	// Check for err
	ErrFatalDisplayIf((dstP == NULL) || (srcP == NULL), "NULL string passed");
	ErrNonFatalDisplayIf(dstP == srcP, "dest and source can't be the same");
	
	// If we already are full, we can quickly return. This means that
	// following code knows there's enough space to copy at least one
	// byte of data plus a terminating null.
	len = StrLen(dstP);
	if (len >= n - 1) {
		return(dstP);
	}
	
	// Do the cat. Note that we leave space for the terminating null, thus
	// N is total size limit of the dst string, including the null.
	tmp = dstP + len;
	savedSrcP = srcP;
	while ((len < (n - 1)) && *srcP)
	{
		*tmp++ = *srcP++;
		len++;
	}
	
	// Null terminate the string if there's room
	if (len < n)
	{
		*tmp = '\0';
	}
	
	// Make sure we didn't wind up copying over a partial byte. If we
	// still have source data then we must have been limited by n, and
	// thus need to check the bounds of the last character copied in the
	// source string. Though this check only needs to be made if the
	// first byte of the remaining source _could_ be part of a multi-
	// byte character.
	
	if (*(UInt8*)srcP > kTxtMaxNeverMultiByte)
	{
		UInt32 charStart, charEnd;
		UInt32 offset = srcP - savedSrcP;
		TxtCharBounds(savedSrcP, offset, &charStart, &charEnd);
		
		if (charStart < offset)
		{
			tmp -= (offset - charStart);
			*tmp = '\0';
		}
	}

	// Fill up the unused dest buffer with bytes to reveal errors.
	// Only copy over the remaining unused bytes.  This works correctly when
	// the src and dest overlap.
#if (ERROR_CHECK_LEVEL == ERROR_CHECK_FULL)
	tmp++;	// skip terminating null
	endDstP = dstP + n;
	if (tmp < endDstP)
	{
		// Make sure that the MemSet call changes at least one value or it can 
		// complain that it didn't change anything and thus didn't need to be called.
		// This is basically extra debug code to help out other debug code.
		tmp[0] = 0;
		
		// Fill up the destination as much as allowed with a value to reveal errors.
		MemSet(tmp, endDstP - tmp, 0xfe);
	}
#endif
	
	return(dstP);
} // StrNCat