📄 memomain.c
字号:
// Find the application's data file.
err = DmGetNextDatabaseByTypeCreator (true, &searchState, memoDBType,
sysFileCMemo, true, &cardNo, &dbID);
if (err)
{
findParams->more = false;
return;
}
// Open the Memo database.
dbP = DmOpenDatabase(cardNo, dbID, findParams->dbAccesMode);
if (!dbP)
{
findParams->more = false;
return;
}
// Display the heading line.
headerStringH = DmGetResource(strRsc, FindMemoHeaderStr);
header = MemHandleLock(headerStringH);
done = FindDrawHeader(findParams, header);
MemHandleUnlock(headerStringH);
DmReleaseResource(headerStringH);
if (done)
goto Exit;
// Search the memos for the "find" string.
recordNum = findParams->recordNum;
while (true)
{
// Because applications can take a long time to finish a find when
// the result may be on the screen or for other reasons, users like
// to be able to stop the find. Stop the find if an event is pending.
// This stops if the user does something with the device. Because
// this call slows winDown the search we perform it every so many
// records instead of every record. The response time should still
// be Int16 without introducing much extra work to the search.
// Note that in the implementation below, if the next 16th record is
// secret the check doesn't happen. Generally this shouldn't be a
// problem since if most of the records are secret then the search
// won't take long anyways!
if ((recordNum & 0x000f) == 0 && // every 16th record
EvtSysEventAvail(true))
{
// Stop the search process.
findParams->more = true;
break;
}
recordH = DmQueryNextInCategory (dbP, &recordNum, dmAllCategories);
// Have we run out of records?
if (! recordH)
{
findParams->more = false;
break;
}
memoRecP = MemHandleLock (recordH);
// Search for the string passed, if it's found display the title
// of the memo.
match = TxtFindString (&(memoRecP->note), findParams->strToFind, &longPos, &matchLength);
pos = longPos;
if (match)
{
// Add the match to the find paramter block, if there is no room to
// display the match the following function will return true.
done = FindSaveMatch (findParams, recordNum, pos, 0, matchLength, cardNo, dbID);
if (!done)
{
// Get the bounds of the region where we will draw the results.
FindGetLineBounds (findParams, &r);
// Display the title of the description.
DrawMemoTitle (&(memoRecP->note), r.topLeft.x+1, r.topLeft.y,
r.extent.x-2);
findParams->lineNumber++;
}
}
MemHandleUnlock(recordH);
if (done) break;
recordNum++;
}
Exit:
DmCloseDatabase (dbP);
}
/***********************************************************************
*
* FUNCTION: GoToItem
*
* DESCRIPTION: This routine is an entry point of the memo application.
* It is generally called as the result of hitting a
* "Go to" button in the text search dialog. The record
* identifies by the parameter block passed will be display,
* with the character range specified highlighted.
*
* PARAMETERS: goToParams - parameter block that identifies the record to
* display.
* launchingApp - true if the application is being launched.
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 06/06/95 Initial Revision
* roger 07/26/95 converted to modern search mechanism
* kwk 05/15/99 Use saved match length in matchCustom field, so
* that it works with Japanese.
*
***********************************************************************/
static void GoToItem (GoToParamsPtr goToParams, Boolean launchingApp)
{
UInt16 recordNum;
UInt16 attr;
UInt32 uniqueID;
EventType event;
recordNum = goToParams->recordNum;
if (!DmQueryRecord(MemoDB, recordNum))
{
// Record isn't accessible. This can happen when receiving a beam while in the
// Memo New form. This prevents a fatal alert, but doesn't fix the off-by-one
// error. (See DOLATER in sysAppLaunchCmdExgReceiveData case.)
if (!SeekRecord(&recordNum, 0, dmSeekBackward))
if (!SeekRecord(&recordNum, 0, dmSeekForward))
{
FrmAlert(secGotoInvalidRecordAlert);
FrmGotoForm(ListView);
return;
}
}
DmRecordInfo(MemoDB, recordNum, &attr, &uniqueID, NULL);
if ((attr & dmRecAttrSecret) && PrivateRecordVisualStatus == maskPrivateRecords)
{
FrmAlert(secGotoInvalidRecordAlert);
FrmGotoForm(ListView);
return;
}
// Make the item the first item displayed.
TopVisibleRecord = recordNum;
// Change the current category if necessary.
if (CurrentCategory != dmAllCategories)
{
ChangeCategory (attr & dmRecAttrCategoryMask);
}
// If the application is already running, close all open forms. This
// may cause in the database record to be reordered, so we'll find the
// records index by its unique id.
if (! launchingApp)
{
FrmCloseAllForms ();
DmFindRecordByID (MemoDB, uniqueID, &recordNum);
}
// Send an event to goto a form and select the matching text.
MemSet (&event, sizeof(EventType), 0);
event.eType = frmLoadEvent;
event.data.frmLoad.formID = EditView;
EvtAddEventToQueue (&event);
event.eType = frmGotoEvent;
event.data.frmGoto.recordNum = recordNum;
event.data.frmGoto.matchPos = goToParams->matchPos;
event.data.frmGoto.matchLen = goToParams->matchCustom;
event.data.frmGoto.matchFieldNum = goToParams->matchFieldNum;
event.data.frmGoto.formID = EditView;
EvtAddEventToQueue (&event);
CurrentView = EditView;
}
/***********************************************************************
*
* FUNCTION: CreateRecord
*
* DESCRIPTION: This routine creates a new memo record.
*
* PARAMETERS: none
*
* RETURNED: true if the record was sucessfully created.
*
* HISTORY:
* 10/03/95 art Created by Art Lamb.
* 10/11/95 kcr Set initial graffiti upshift.
* 09/25/99 kwk No longer take initial character parameter.
* 10/29/99 jmp Eliminate compiler's "has no side-effect" warning.
*
***********************************************************************/
static Boolean CreateRecord (void)
{
MemPtr p;
Char zero = 0;
UInt32 offset = 0;
UInt16 attr = dmUnfiledCategory;
UInt16 index;
MemHandle memoRec;
// Add a new record at the end of the database.
index = DmNumRecords (MemoDB);
memoRec = DmNewRecord (MemoDB, &index, newMemoSize);
// If the allocate failed, display a warning.
if (! memoRec)
{
FrmAlert (DeviceFullAlert);
return (false);
}
p = MemHandleLock (memoRec);
// Null terminate the new memo string.
DmWrite (p, offset, &zero, sizeof(Char));
MemPtrUnlock (p);
// Set the category of the new record to the current category.
DmRecordInfo (MemoDB, index, &attr, NULL, NULL);
attr &= ~dmRecAttrCategoryMask;
if (CurrentCategory != dmAllCategories)
attr |= CurrentCategory;
DmSetRecordInfo (MemoDB, index, &attr, NULL);
CurrentRecord = index;
MemosInCategory++;
DmReleaseRecord (MemoDB, index, true);
// Set the graffiti state for an initial upshift of the
// first character of a new memo.
//GrfSetState (false, false, true);
return (true);
}
/***********************************************************************
*
* FUNCTION: DeleteRecord
*
* DESCRIPTION: This routine deletes the specified memo
*
* PARAMETERS: index - index of record to delete
*
* RETURNED: true if the record was sucessfully deleted.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 9/30/95 Initial Revision
*
***********************************************************************/
static Boolean DeleteRecord (UInt16 index)
{
UInt16 ctlIndex;
UInt16 buttonHit;
FormPtr alert;
Boolean saveBackup;
// Display an alert to confirm the delete operation.
alert = FrmInitForm (DeleteMemoDialog);
ctlIndex = FrmGetObjectIndex (alert, DeleteMemoSaveBackup);
FrmSetControlValue (alert, ctlIndex, SaveBackup);
buttonHit = FrmDoDialog (alert);
saveBackup = FrmGetControlValue (alert, ctlIndex);;
FrmDeleteForm (alert);
if (buttonHit != DeleteMemoOk)
return (false);
SaveBackup = saveBackup;
// Delete or archive the record.
if (SaveBackup)
DmArchiveRecord (MemoDB, index);
else
DmDeleteRecord (MemoDB, index);
DmMoveRecord (MemoDB, index, DmNumRecords (MemoDB));
return (true);
}
/***********************************************************************
*
* FUNCTION: SelectFont
*
* DESCRIPTION: This routine handles selection of a font in the List
* View.
*
* PARAMETERS: currFontID - id of current font
*
* RETURNED: id of new font
*
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 9/10/97 Initial Revision
*
***********************************************************************/
static FontID SelectFont (FontID currFontID)
{
UInt16 formID;
FontID fontID;
formID = (FrmGetFormId (FrmGetActiveForm ()));
// Call the OS font selector to get the id of a font.
fontID = FontSelect (currFontID);
if (fontID != currFontID)
FrmUpdateForm (formID, updateFontChanged);
return (fontID);
}
#pragma mark ----
/***********************************************************************
*
* FUNCTION: PreferencesApply
*
* DESCRIPTION: This routine applies the changes made in the Preferences
* Dialog
*
* PARAMETERS: nothing
*
* RETURNED: update code
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/18/95 Initial Revision
*
***********************************************************************/
static UInt16 PreferencesApply (void)
{
UInt8 sortOrder;
UInt16 updateCode = 0;
// Update the sort order. Reset the To Do list to the top.
sortOrder = LstGetSelection (GetObjectPtr (PreferencesSortByList));
if (MemoGetSortOrder (MemoDB) != sortOrder)
{
if (sortOrder == soAlphabetic)
{
if (FrmAlert (alphabeticSortAlert) == alphabeticSortNo)
return (0);
}
MemoChangeSortOrder (MemoDB, sortOrder);
updateCode = updateDisplayOptsChanged;
}
return (updateCode);
}
/***********************************************************************
*
* FUNCTION: PreferencesInit
*
* DESCRIPTION: This routine initializes the Preferences Dialog.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/18/95 Initial Revision
*
***********************************************************************/
static void PreferencesInit (void)
{
UInt16 sortOrder;
Char * label;
ListPtr lst;
ControlPtr ctl;
// Set the trigger and popup list that indicates the sort order.
sortOrder = MemoGetSortOrder (MemoDB);
lst = GetObjectPtr (PreferencesSortByList);
label = LstGetSelectionText (lst, sortOrder);
ctl = GetObjectPtr (PreferencesSortByTrigger);
CtlSetLabel (ctl, label);
LstSetSelection (lst, sortOrder);
}
/***********************************************************************
*
* FUNCTION: PreferencesHandleEvent
*
* DESCRIPTION: This routine is the event handler for the "Preferences
* Dialog Box" of the Memo application.
*
* PARAMETERS: event - a pointer to an EventType structure
*
* RETURNED: true if the event was handled and should not be passed
* to a higher level handler.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/18/95 Initial Revision
*
***********************************************************************/
static Boolean PreferencesHandleEvent (EventType * event)
{
UInt16 updateCode;
Boolean handled = false;
FormPtr frm;
if (event->eType == ctlSelectEvent)
{
switch (event->data.ctlSelect.controlID)
{
case PreferencesOkButton:
updateCode = PreferencesApply ();
FrmReturnToForm (ListView);
if (updateCode)
FrmUpdateForm (ListView, updateCode);
handled = true;
break;
case PreferencesCancelButton:
FrmReturnToForm (ListView);
handled = true;
break;
}
}
else if (event->eType == frmOpenEvent)
{
frm = FrmGetActiveForm ();
PreferencesInit ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -