📄 datebook.c
字号:
/******************************************************************************
*
* Copyright (c) 1995-2003 PalmSource, Inc. All rights reserved.
*
* File: Datebook.c
*
* Release: Palm OS 5 SDK (68K) R3.
*
* Description:
* This is the Datebook application's main module. This module
* starts the application, dispatches events, and stops
* the application.
*
*****************************************************************************/
#include <PalmOS.h>
#include <PalmUtils.h>
#include "DateLunar.h" // For DateSupportsLunarCalendar(), etc. (will be in Time Mgr 6.0)
#include "Datebook.h"
extern ECApptDBValidate (DmOpenRef dbP);
/***********************************************************************
*
* Global variables, declarded in DateGlobals.c. Because of a bug in
* the Metrowerks compiler, we must compile the globals separately with
* PC-relative strings turned off.
*
***********************************************************************/
extern UInt16 TopVisibleAppt;
extern privateRecordViewEnum CurrentRecordVisualStatus; // applies to current record
extern privateRecordViewEnum PrivateRecordVisualStatus; // applies to all other records
// The following global variables are used to keep track of the edit
// state of the application.
extern UInt16 CurrentRecord; // record being edited
extern Boolean ItemSelected; // true if a day view item is selected
extern UInt16 DayEditPosition; // position of the insertion point in the desc field
extern UInt16 DayEditSelectionLength; // length of the current selection.
extern Boolean RecordDirty; // true if a record has been modified
extern MemHandle pArabicNumeralFontH; // used by Lunar View
extern MemHandle pChineseNumeralFontH; // used by Lunar View
/***********************************************************************
*
* Internal Functions
*
***********************************************************************/
static void EventLoop (void);
/***********************************************************************
*
* Test Code
*
***********************************************************************/
// Useful structure field offset and size macros
#define prvFieldOffset(type, field) ((UInt32)(&((type*)0)->field))
#define prvFieldSize(type, field) (sizeof(((type*)0)->field))
/***********************************************************************
*
* FUNCTION: SetDBBackupBit
*
* DESCRIPTION: This routine sets the backup bit on the given database.
* This is to aid syncs with non Palm software.
* If no DB is given, open the app's default database and set
* the backup bit on it.
*
* PARAMETERS: dbP - the database to set backup bit,
* can be NULL to indicate app's default database
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* grant 4/1/99 Initial Revision
*
***********************************************************************/
static void SetDBBackupBit(DmOpenRef dbP)
{
DmOpenRef localDBP;
LocalID dbID;
UInt16 cardNo;
UInt16 attributes;
// Open database if necessary. If it doesn't exist, simply exit (don't create it).
if (dbP == NULL)
{
localDBP = DmOpenDatabaseByTypeCreator (datebookDBType, sysFileCDatebook, dmModeReadWrite);
if (localDBP == NULL) return;
}
else
{
localDBP = dbP;
}
// now set the backup bit on localDBP
DmOpenDatabaseInfo(localDBP, &dbID, NULL, NULL, &cardNo, NULL);
DmDatabaseInfo(cardNo, dbID, NULL, &attributes, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL);
attributes |= dmHdrAttrBackup;
DmSetDatabaseInfo(cardNo, dbID, NULL, &attributes, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL);
// close database if necessary
if (dbP == NULL)
{
DmCloseDatabase(localDBP);
}
}
/***********************************************************************
*
* FUNCTION: RegisterData
*
* DESCRIPTION: Register with the Exchange Manager to receive .vcs and
* text/x-vCalendar.
*
* PARAMETERS: none
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* dje 7/28/00 Initial Revision
*
***********************************************************************/
static void RegisterData(void)
{
MemHandle resH = DmGetResource(strRsc, exgDescriptionStrID);
void *desc = MemHandleLock(resH);
ExgRegisterDatatype(sysFileCDatebook, exgRegExtensionID, dateExtension, (Char *)desc, 0);
ExgRegisterDatatype(sysFileCDatebook, exgRegTypeID, dateMIMEType, (Char *)desc, 0);
MemHandleUnlock(resH);
DmReleaseResource(resH);
}
/***********************************************************************
*
* FUNCTION: DateGetDatabase
*
* DESCRIPTION: Get the application's database. Open the database if it
* exists, create it if neccessary.
*
* PARAMETERS: *dbPP - pointer to a database ref (DmOpenRef) to be set
* mode - how to open the database (dmModeReadWrite)
*
* RETURNED: Err - zero if no error, else the error
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 12/3/97 Initial Revision
*
***********************************************************************/
static Err DateGetDatabase (DmOpenRef *dbPP, UInt16 mode)
{
Err error = 0;
DmOpenRef dbP;
UInt16 cardNo;
LocalID dbID;
*dbPP = 0;
dbP = DmOpenDatabaseByTypeCreator(datebookDBType, sysFileCDatebook, mode);
if (! dbP)
{
error = DmCreateDatabase (0, datebookDBName, sysFileCDatebook,
datebookDBType, false);
if (error) return error;
dbP = DmOpenDatabaseByTypeCreator(datebookDBType, sysFileCDatebook, mode);
if (! dbP) return ~0;
// Set the backup bit. This is to aid syncs with non Palm software.
SetDBBackupBit(dbP);
error = ApptAppInfoInit (dbP);
if (error)
{
DmOpenDatabaseInfo(dbP, &dbID, NULL, NULL, &cardNo, NULL);
DmCloseDatabase(dbP);
DmDeleteDatabase(cardNo, dbID);
return error;
}
}
*dbPP = dbP;
return 0;
}
/***********************************************************************
*
* FUNCTION: LoadLunarViewFonts
*
* DESCRIPTION: Load the special Arabic and Chinese numeral fonts
* needed for the Lunar View.
*
* PARAMETERS: None
*
* RETURNED: Nothing
*
* REVISION HISTORY:
* 2002-10-22 CS New today to support Lunar View.
* 2002-11-04 CS Use fontExtRscType, since we now have multi-density
* font families.
*
***********************************************************************/
static void LoadLunarViewFonts(void)
{
FontType *fontP = NULL;
pArabicNumeralFontH = NULL;
pChineseNumeralFontH = NULL;
if (DateSupportsLunarCalendar())
{
pArabicNumeralFontH = DmGetResource(fontExtRscType, arabicNumeralFontID);
ErrNonFatalDisplayIf(!pArabicNumeralFontH,
"Can't load Arabic Numeral Font");
if (pArabicNumeralFontH)
{
fontP = (FontType *)MemHandleLock(pArabicNumeralFontH);
FntDefineFont((FontID)arabicNumeralFontID, fontP);
}
pChineseNumeralFontH = DmGetResource(fontExtRscType, chineseNumeralFontID);
ErrNonFatalDisplayIf(!pChineseNumeralFontH,
"Can't load Chinese Numeral Font");
if (pChineseNumeralFontH)
{
fontP = (FontType *)MemHandleLock(pChineseNumeralFontH);
FntDefineFont((FontID)chineseNumeralFontID, fontP);
}
}
} // LoadLunarViewFonts
/***********************************************************************
*
* FUNCTION: ReleaseLunarViewFonts
*
* DESCRIPTION: Release the special Arabic and Chinese numeral fonts
* needed for the Lunar View.
*
* PARAMETERS: None
*
* RETURNED: Nothing
*
* REVISION HISTORY:
* 2002-10-22 CS New today to support Lunar View.
*
***********************************************************************/
static void ReleaseLunarViewFonts(void)
{
if (pArabicNumeralFontH)
{
MemHandleUnlock(pArabicNumeralFontH);
DmReleaseResource(pArabicNumeralFontH);
}
pArabicNumeralFontH = NULL;
if (pChineseNumeralFontH)
{
MemHandleUnlock(pChineseNumeralFontH);
DmReleaseResource(pChineseNumeralFontH);
}
pChineseNumeralFontH = NULL;
} // ReleaseLunarViewFonts
/***********************************************************************
*
* FUNCTION: StartApplication
*
* DESCRIPTION: This routine opens the application's database, loads the
* saved-state information and initializes global variables.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/12/95 Initial Revision
* trm 8/5/97 adds variable alarm sound settings
* frigino 9/9/97 Add AlarmSoundUniqueRecID initialization
* vmk 12/9/97 Call DatebookLoadPrefs() to load and fixup prefs
* rbb 6/20/99 Removed multi-segment workaround
* 2002-10-23 CS Load fonts needed for Lunar View.
*
***********************************************************************/
static UInt16 StartApplication (void)
{
Err err = 0;
UInt16 mode;
DateTimeType dateTime;
DatebookPreferenceType prefs;
Int16 prefsVersion;
// Determime if secret record should be shown.
PrivateRecordVisualStatus = CurrentRecordVisualStatus =
(privateRecordViewEnum)PrefGetPreference(prefShowPrivateRecords);
mode = (PrivateRecordVisualStatus == hidePrivateRecords) ?
dmModeReadWrite : (dmModeReadWrite | dmModeShowSecret);
// Get the time formats from the system preferences.
TimeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat);
// Get the date formats from the system preferences.
LongDateFormat = (DateFormatType)PrefGetPreference(prefLongDateFormat);
ShortDateFormat = (DateFormatType)PrefGetPreference(prefDateFormat);
// Get the starting day of the week from the system preferences.
StartDayOfWeek = PrefGetPreference(prefWeekStartDay);
// Get today's date.
TimSecondsToDateTime (TimGetSeconds (), &dateTime);
Date.year = dateTime.year - firstYear;
Date.month = dateTime.month;
Date.day = dateTime.day;
// Find the application's data file. If it don't exist create it.
err = DateGetDatabase (&ApptDB, mode);
if (err) return err;
// Read the preferences / saved-state information (will fix up incompatible versions).
prefsVersion = DatebookLoadPrefs (&prefs);
DayStartHour = prefs.dayStartHour;
DayEndHour = prefs.dayEndHour;
AlarmPreset = prefs.alarmPreset;
NoteFont = prefs.noteFont;
SaveBackup = prefs.saveBackup;
ShowTimeBars = prefs.showTimeBars;
CompressDayView = prefs.compressDayView;
ShowTimedAppts = prefs.showTimedAppts;
ShowUntimedAppts = prefs.showUntimedAppts;
ShowDailyRepeatingAppts = prefs.showDailyRepeatingAppts;
AlarmSoundRepeatCount = prefs.alarmSoundRepeatCount;
AlarmSoundRepeatInterval = prefs.alarmSoundRepeatInterval;
AlarmSoundUniqueRecID = prefs.alarmSoundUniqueRecID;
ApptDescFont = prefs.apptDescFont;
AlarmSnooze = prefs.alarmSnooze;
// Load any fonts needed for the Lunar View
LoadLunarViewFonts();
// The first time this app starts register to handle vCard data.
if (prefsVersion != datebookPrefsVersionNum)
RegisterData();
TopVisibleAppt = 0;
CurrentRecord = noRecordSelected;
return 0;
}
/***********************************************************************
*
* FUNCTION: StopApplication
*
* DESCRIPTION: This routine closes the application's database
* and saves the current state of the application.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/12/95 Initial Revision
* trm 8/5/97 adds variable alarm sound settings
* frigino 9/9/97 Add saving of AlarmSoundUniqueRecID
* vmk 12/9/97 Call DatebookSavePrefs() to write out the prefs
* rbb 6/20/99 Removed multi-segment workaround
* 2002-09-13 CS Call TerminateDateLunar for now, but this will be
* handled by Time Mgr 6.0 termination sequence.
* 2002-10-23 CS Release fonts needed for Lunar View.
*
***********************************************************************/
static void StopApplication (void)
{
// DOLATER CS - Remove this when it becomes part of Time Mgr 6.0
TerminateDateLunar();
DatebookSavePrefs();
// Send a frmSave event to all the open forms.
FrmSaveAllForms ();
// Close all the open forms.
FrmCloseAllForms ();
// Close the application's data file.
DmCloseDatabase (ApptDB);
// Rekease any fonts needed for the Lunar View
ReleaseLunarViewFonts();
}
/***********************************************************************
*
* FUNCTION: DatebookLoadPrefs
*
* DESCRIPTION: Loads app's preferences and fixes them up if they didn't exist
* or were of the wrong version.
*
* PARAMETERS: prefsP -- ptr to preferences structure to fill in
*
* RETURNED: the version of preferences from which values were read
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* vmk 12/9/97 Initial version
* vmk 12/11/97 Fix up note font
* rbb 4/23/99 Added alarmSnooze
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -