📄 addressdb.c
字号:
/******************************************************************************
*
* Copyright (c) 1995-1999 Palm Computing, Inc. or its subsidiaries.
* All rights reserved.
*
* File: AddressDB.c
*
* Description:
* Address Manager routines
*
* History:
* 1/9/95 rsf - Created
* 7/22/96 rsf - Added the Address Lookup routines. These calls
* perform the data searching needed by the app to
* support the lookup launch notification.
* 10/01/99 jmp - Added AddrGetDataBase() routine.
*
*****************************************************************************/
// Set this to get to private database defines
#define __ADDRMGR_PRIVATE__
#include <PalmOS.h>
#include "Address.h"
#include "AddressDB.h"
#include "progect.h"
#include "progectRsc.h"
//#include "AddressRsc.h"
// Max length of a field name found in the FieldNamesStrList string list.
#define maxFieldName 31
// Indexes into FieldNamesStrList string list.
enum {
fieldNameStrListCity = 0,
fieldNameStrListState,
fieldNameStrListZip
};
// Extract the bit at position index from bitfield. 0 is the high bit.
#define BitAtPosition(pos) ((UInt32)1 << (pos))
#define GetBitMacro(bitfield, index) ((bitfield) & BitAtPosition(index))
#define SetBitMacro(bitfield, index) ((bitfield) |= BitAtPosition(index))
#define RemoveBitMacro(bitfield, index) ((bitfield) &= ~BitAtPosition(index))
#define sortKeyFieldBits (BitAtPosition(name) | BitAtPosition(firstName) | BitAtPosition(company))
//0x70000 // Update this if the sort fields
// change positions
// The following structure doesn't really exist. The first field
// varies depending on the data present. However, it is convient
// (and less error prone) to use when accessing the other information.
typedef struct {
AddrOptionsType options; // Display by company or by name
AddrDBRecordFlags flags;
UInt8 companyFieldOffset; // Offset from firstField
char firstField;
} AddrPackedDBRecord;
/************************************************************
* Private routines used only in this module
*************************************************************/
Boolean PrvSeekVisibleRecordInCategory (DmOpenRef dbR, UInt16 * indexP, UInt16 offset,
Int16 direction, UInt16 category, Boolean masked);
/************************************************************
*
* FUNCTION: AddrAppInfoGetPtr
*
* DESCRIPTION: Return a locked pointer to the AddrAppInfo or NULL
*
* PARAMETERS: dbP - open database pointer
*
* RETURNS: locked ptr to the AddrAppInfo or NULL
*
* CREATED: 6/13/95
*
* BY: Roger Flores
*
*************************************************************/
//AddrAppInfoPtr AddrAppInfoGetPtr(DmOpenRef dbP)
//{
// UInt16 cardNo;
// LocalID dbID;
// LocalID appInfoID;
//
// if (DmOpenDatabaseInfo(dbP, &dbID, NULL, NULL, &cardNo, NULL))
// return NULL;
// if (DmDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &appInfoID, NULL, NULL, NULL))
// return NULL;
//
// if (appInfoID == NULL)
// return NULL;
// else
// return MemLocalIDToLockedPtr(appInfoID, cardNo);
//
//}
/************************************************************
*
* FUNCTION: AddrChangeCountry
*
* DESCRIPTION: Set the field labels to those appropriate
* to the current country (based on system preferences).
*
* PARAMETERS: application info ptr
*
* RETURNS: nothing
*
* HISTORY:
* 07/24/95 rsf Created by Roger Flores
* 07/29/99 kwk Load field names from string list resource.
*
*************************************************************/
//void AddrChangeCountry(AddrAppInfoPtr appInfoP)
//{
// CountryType countryCurrent;
// AddrAppInfoPtr nilP = NULL;
// MemHandle textH;
// UInt16 strListID;
// Char fieldName[maxFieldName + sizeOf7BitChar(chrNull)];
//
// // Localize the field labels to the current country
// countryCurrent = (CountryType) PrefGetPreference(prefCountry);
// strListID = (UInt16)countryCurrent + FieldNamesStrList;
//
// textH = DmGetResource(strListRscType, strListID);
// if (textH != NULL)
// {
// AddrDBRecordFlags dirtyFieldLabels;
//
// DmStrCopy(appInfoP, (Int32) nilP->fieldLabels[city],
// SysStringByIndex(strListID, fieldNameStrListCity, fieldName, maxFieldName));
// DmStrCopy(appInfoP, (Int32) nilP->fieldLabels[state],
// SysStringByIndex(strListID, fieldNameStrListState, fieldName, maxFieldName));
// DmStrCopy(appInfoP, (Int32) nilP->fieldLabels[zipCode],
// SysStringByIndex(strListID, fieldNameStrListZip, fieldName, maxFieldName));
//
// dirtyFieldLabels.allBits = (appInfoP->dirtyFieldLabels.allBits) |
// BitAtPosition(city) | BitAtPosition(state) | BitAtPosition(zipCode);
//
// DmWrite(appInfoP, (Int32) &nilP->dirtyFieldLabels, &dirtyFieldLabels, sizeof dirtyFieldLabels);
// }
//
// // Record the country.
// DmWrite(appInfoP, (Int32) &nilP->country, &countryCurrent, sizeof(countryCurrent));
//}
/************************************************************
*
* FUNCTION: AddrLocalizeAppInfo
*
* DESCRIPTION: Look for localize app info strings and copy
* them into the app info block.
*
* PARAMETERS: application info ptr
*
* RETURNS: nothing
*
* CREATED: 12/13/95
*
* BY: Roger Flores
*
* MODIFICATIONS:
* 10/22/96 roger Set flags when field modified
*************************************************************/
//static void AddrLocalizeAppInfo(AddrAppInfoPtr appInfoP)
//{
// MemHandle localizedAppInfoH;
// Char * localizedAppInfoP;
// AddrAppInfoPtr nilP = 0;
// MemHandle stringsH;
// Char * *stringsP;
// int i;
// UInt16 localRenamedCategories;
// UInt32 localDirtyFieldLabels;
//
//
// localizedAppInfoH = DmGetResource(appInfoStringsRsc, LocalizedAppInfoStr);
// if (!localizedAppInfoH)
// return;
// localizedAppInfoP = MemHandleLock(localizedAppInfoH);
// stringsH = SysFormPointerArrayToStrings(localizedAppInfoP,
// dmRecNumCategories + addrNumFields + numPhoneLabelsStoredSecond);
// stringsP = MemHandleLock(stringsH);
//
//
// // Copy each category
// localRenamedCategories = appInfoP->renamedCategories;
// for (i = 0; i < dmRecNumCategories; i++)
// {
// if (stringsP[i][0] != '\0')
// {
// DmStrCopy(appInfoP, (Int32) nilP->categoryLabels[i], stringsP[i]);
// SetBitMacro(localRenamedCategories, i);
// }
// }
// DmWrite(appInfoP, (Int32) &nilP->renamedCategories, &localRenamedCategories,
// sizeof(localRenamedCategories));
//
//
// // Copy each field label
// localDirtyFieldLabels = appInfoP->dirtyFieldLabels.allBits;
// for (i = 0; i < (addrNumFields + numPhoneLabelsStoredSecond); i++)
// {
// if (stringsP[i + dmRecNumCategories][0] != '\0')
// {
// DmStrCopy(appInfoP, (Int32) nilP->fieldLabels[i],
// stringsP[i + dmRecNumCategories]);
// SetBitMacro(localDirtyFieldLabels, i);
// }
// }
// DmWrite(appInfoP, (Int32) &nilP->dirtyFieldLabels.allBits, &localDirtyFieldLabels,
// sizeof(localDirtyFieldLabels));
//
//
// MemPtrFree(stringsP);
// MemPtrUnlock(localizedAppInfoP);
// DmReleaseResource(localizedAppInfoH);
//}
/************************************************************
*
* FUNCTION: AddrAppInfoInit
*
* DESCRIPTION: Create an app info chunk if missing. Set
* the strings to a default.
*
* PARAMETERS: dbP - open database pointer
*
* RETURNS: 0 if successful, errorcode if not
*
* CREATED: 1/3/95
*
* BY: Roger Flores
*
* MODIFICATIONS:
* 10/22/96 roger Change to init data via code and resources to
* remove global var use which wasn't always available.
*************************************************************/
//Err AddrAppInfoInit(DmOpenRef dbP)
//{
// UInt16 cardNo;
// LocalID dbID;
// LocalID appInfoID;
// MemHandle h;
// AddrAppInfoPtr appInfoP;
// AddrAppInfoPtr defaultAddrApplicationInfoP;
// UInt8 i;
//
//
// appInfoP = AddrAppInfoGetPtr(dbP);
//
// // If there isn't an AddrApplicationInfo make space for one
// if (appInfoP == NULL)
// {
// if (DmOpenDatabaseInfo(dbP, &dbID, NULL, NULL, &cardNo, NULL))
// return dmErrInvalidParam;
// if (DmDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &appInfoID, NULL, NULL, NULL))
// return dmErrInvalidParam;
//
// h = DmNewHandle(dbP, sizeof(AddrAppInfoType));
// if (!h) return dmErrMemError;
//
// appInfoID = MemHandleToLocalID( h);
// DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &appInfoID, NULL, NULL, NULL);
//
// appInfoP = MemHandleLock(h);
// }
//
//
// // Allocate & Clear the app info
// defaultAddrApplicationInfoP = MemPtrNew(sizeof(AddrAppInfoType));
// if (defaultAddrApplicationInfoP == NULL)
// {
// ErrDisplay("Unable to init AddressDB");
// return 1;
// }
//
// MemSet(defaultAddrApplicationInfoP, sizeof(AddrAppInfoType), 0);
//
// // Init the categories
// for (i = 0; i < dmRecNumCategories; i++)
// {
// defaultAddrApplicationInfoP->categoryUniqIDs[i] = i;
// }
// defaultAddrApplicationInfoP->lastUniqID = dmRecNumCategories - 1;
//
// // Set to sort by name
// defaultAddrApplicationInfoP->misc.sortByCompany = false;
//
//
// // copy in the defaults and free the default app info
// DmWrite(appInfoP, 0, defaultAddrApplicationInfoP, sizeof(AddrAppInfoType));
// MemPtrFree(defaultAddrApplicationInfoP);
//
//
// // Try to use localized app info block strings.
// AddrLocalizeAppInfo(appInfoP);
//
// // Localize the field labels to the current country
// AddrChangeCountry(appInfoP);
//
//
// // Unlock
// MemPtrUnlock(appInfoP);
//
// return 0;
//}
/************************************************************
*
* FUNCTION: AddrSetFieldLabel
*
* DESCRIPTION: Set a field's label and mark it dirty.
*
* PARAMETERS: dbP - open database pointer
* fieldNum - field label to change
* fieldLabel - new field label to use
*
* RETURNS: 0 if successful, errorcode if not
*
* CREATED: 6/28/95
*
* BY: Roger Flores
*
*************************************************************/
//void AddrSetFieldLabel(DmOpenRef dbP, UInt16 fieldNum, Char * fieldLabel)
//{
// AddrAppInfoPtr appInfoP;
// AddrAppInfoType copy;
//
//
// ErrFatalDisplayIf(fieldNum >= lastLabel,
// "fieldNum out of range");
//
// // Get a copy of the app info
// appInfoP = AddrAppInfoGetPtr(dbP);
// ErrFatalDisplayIf(appInfoP == NULL,
// "Bad database (invalid or no app info block)");
// MemMove(©, appInfoP, sizeof(copy));
//
// // Make the changes
// StrCopy(copy.fieldLabels[fieldNum], fieldLabel); //lint !e661
// SetBitMacro(copy.dirtyFieldLabels.allBits, fieldNum);
//
// // Write changes to record
// DmWrite(appInfoP, 0, ©, sizeof(copy));
//
// // Unlock app info
// MemPtrUnlock(appInfoP);
//}
/************************************************************
*
* FUNCTION: AddrFindKey
*
* DESCRIPTION: Return the next valid key
*
* PARAMETERS: database packed record
* <-> key to use (ptr to string or NULL for uniq ID)
* <-> which key (incremented for use again, starts at 1)
* -> sortByCompany
*
* RETURNS:
*
* CREATED: 1/16/95
*
* BY: Roger Flores
*
* COMMENTS: Returns the key which is asked for if possible and
* advances whichKey. If the key is not available the key advances
* to the next one. The order of keys is:
*
* if sortByCompany:
* companyKey, nameKey, firstNameKey, uniq ID
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -