📄 todo.c
字号:
ErrNonFatalDisplayIf((err != errNone) && (err != sysNotifyErrDuplicateEntry), "can't register");
#endif
}
return;
}
/***********************************************************************
*
* FUNCTION: SearchDraw
*
* DESCRIPTION: This routine draws the description of a ToDo item found
* by the text search routine
*
* PARAMETERS: desc - pointer to a description field
* x - draw position
* y - draw position
* width - maximum width to draw.
*
* RETURNED: nothing
*
* HISTORY:
* 04/18/95 art Created by Art Lamb.
* 12/10/00 kwk Use WinDrawTruncChars, versus byte-by-byte processing
* of text that doesn't work with Japanese.
*
***********************************************************************/
static void SearchDraw (Char* desc, Int16 x, Int16 y, Int16 width)
{
UInt16 textLen;
const Char* lineFeedP;
lineFeedP = StrChr(desc, chrLineFeed);
if (lineFeedP != NULL)
{
textLen = lineFeedP - desc;
}
else
{
textLen = StrLen(desc);
}
WinDrawTruncChars(desc, textLen, x, y, width);
}
/***********************************************************************
*
* FUNCTION: Search
*
* DESCRIPTION: This routine searchs the ToDo database for records
* that contain the findParams string.
*
* PARAMETERS: findParams - text search parameter block
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 4/18/95 Initial Revision
* jmp 10/21/99 Changed params to findParams to match other routines
* like this one.
*
***********************************************************************/
static void Search (FindParamsPtr findParams)
{
Err err;
UInt16 pos;
UInt16 fieldNum;
Char* desc;
Char* note;
Char* header;
UInt16 recordNum;
MemHandle recordH;
MemHandle headerH;
RectangleType r;
Boolean done;
Boolean match;
LocalID dbID;
DmOpenRef dbP;
ToDoDBRecordPtr toDoRec;
UInt16 cardNo = 0;
DmSearchStateType searchState;
UInt32 longPos;
UInt16 matchLength;
// Find the application's data file.
err = DmGetNextDatabaseByTypeCreator (true, &searchState, toDoDBType,
sysFileCToDo, true, &cardNo, &dbID);
if (err)
{
findParams->more = false;
return;
}
// Open the ToDo database.
dbP = DmOpenDatabase(cardNo, dbID, findParams->dbAccesMode);
if (!dbP)
{
findParams->more = false;
return;
}
// Display the heading line.
headerH = DmGetResource (strRsc, FindToDoHeaderStr);
header = MemHandleLock (headerH);
done = FindDrawHeader (findParams, header);
MemHandleUnlock(headerH);
if (done)
goto Exit;
// Search the description and note fields 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 if most of the records are secret then the search
// won't take long.
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;
}
toDoRec = MemHandleLock (recordH);
// Search the description field, if a match is not found search the
// note field.
fieldNum = descSeacrchFieldNum;
desc = &toDoRec->description;
match = TxtFindString (desc, findParams->strToFind, &longPos, &matchLength);
pos = longPos;
if (! match)
{
note = desc + StrLen (desc) + 1;
if (*note)
{
fieldNum = noteSeacrchFieldNum;
match = TxtFindString (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, fieldNum, matchLength, cardNo, dbID);
if (done)
{
MemHandleUnlock (recordH);
break;
}
// Get the bounds of the region where we will draw the results.
FindGetLineBounds (findParams, &r);
// Display the description.
SearchDraw (desc, r.topLeft.x+1, r.topLeft.y, r.extent.x-2);
findParams->lineNumber++;
}
MemHandleUnlock (recordH);
recordNum++;
}
Exit:
DmCloseDatabase (dbP);
}
/***********************************************************************
*
* FUNCTION: GoToItem
*
* DESCRIPTION: This routine is called when the "Go to" button
* in the text search dialog is pressed.
*
* PARAMETERS: goToParams - where to go to
* launchingApp - true is the application is being launched
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 06/06/95 Initial Revision
* kwk 12/03/98 Fixed param order in call to MemSet.
* jmp 09/17/99 Use NewNoteView instead of NoteView.
*
***********************************************************************/
static void GoToItem (GoToParamsPtr goToParams, Boolean launchingApp)
{
UInt16 formID;
UInt16 recordNum;
UInt16 attr;
Int32 dateL;
Int32 todayL;
UInt32 uniqueID;
MemHandle recordH;
EventType event;
DateTimeType today;
ToDoDBRecordPtr toDoRec;
recordNum = goToParams->recordNum;
if (!DmQueryRecord(ToDoDB, recordNum))
{
// Record isn't accessible. This can happen when receiving a beam while in an
// empty record. 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;
}
}
// If the application is already running, close all the open forms. If
// the current record is blank, then it will be deleted, so we'll get
// the unique id of the record and use it to find the record index
// after all the forms are closed.
if (! launchingApp)
{
DmRecordInfo (ToDoDB, recordNum, NULL, &uniqueID, NULL);
FrmCloseAllForms ();
ClearEditState ();
DmFindRecordByID (ToDoDB, uniqueID, &recordNum);
}
// Make the item the first item displayed.
TopVisibleRecord = recordNum;
// Change the current category if necessary.
if (CurrentCategory != dmAllCategories)
{
DmRecordInfo (ToDoDB, recordNum, &attr, NULL, NULL);
if (CurrentCategory != (attr & dmRecAttrCategoryMask))
{
CurrentCategory = dmAllCategories;
ShowAllCategories = true;
}
}
// If the item is not displayable given the current display options,
// change the display options so that it will be.
recordH = DmQueryRecord (ToDoDB, recordNum);
toDoRec = (ToDoDBRecordPtr) MemHandleLock (recordH);
// If only completed items are not being displayed, and the item is complete,
// change the "show completed" option setting.
if ((! ShowCompletedItems) && (toDoRec->priority & completeFlag))
ShowCompletedItems = true;
// If only due items are being show, and the item is not due,
// change the "show only due items" option.
if (ShowOnlyDueItems)
if (DateToInt (toDoRec->dueDate) != toDoNoDueDate)
{
// Check if the item is due.
TimSecondsToDateTime (TimGetSeconds(), &today);
todayL = ( ((Int32) today.year) << 16) +
( ((Int32) today.month) << 8) +
((Int32) today.day);
dateL = ( ((Int32) toDoRec->dueDate.year + firstYear) << 16) +
( ((Int32) toDoRec->dueDate.month) << 8) +
((Int32) toDoRec->dueDate.day);
if (dateL > todayL)
ShowOnlyDueItems = false;
}
MemHandleUnlock (recordH);
if (goToParams->matchFieldNum == noteSeacrchFieldNum)
formID = NewNoteView;
else
formID = ListView;
// Send an event to goto a form and select the matching text.
MemSet (&event, sizeof(EventType), 0);
event.eType = frmLoadEvent;
event.data.frmLoad.formID = formID;
EvtAddEventToQueue (&event);
event.eType = frmGotoEvent;
event.data.frmGoto.formID = formID;
event.data.frmGoto.recordNum = recordNum;
event.data.frmGoto.matchPos = goToParams->matchPos;
event.data.frmGoto.matchLen = goToParams->matchCustom;
event.data.frmGoto.matchFieldNum = goToParams->matchFieldNum;
EvtAddEventToQueue (&event);
}
/***********************************************************************
*
* FUNCTION: GetObjectPtr
*
* DESCRIPTION: This routine returns a pointer to an object in the current
* form.
*
* PARAMETERS: formId - id of the form to display
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 2/21/95 Initial Revision
*
***********************************************************************/
static void* GetObjectPtr (UInt16 objectID)
{
FormPtr frm;
frm = FrmGetActiveForm ();
return (FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, objectID)));
}
/***********************************************************************
*
* FUNCTION: SetObjectValue
*
* DESCRIPTION: Assign a value to the object with the given ID
*
* PARAMETERS: objectID - id of the object to change
* value - new value of the object
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* rbb 4/14/99 Initial Revision
*
***********************************************************************/
static void SetObjectValue (UInt16 objectID, Int16 value)
{
ControlPtr ctl;
ctl = GetObjectPtr (objectID);
CtlSetValue (ctl, value);
}
/***********************************************************************
*
* FUNCTION: GetObjectValue
*
* DESCRIPTION: Return the value of the object with the given ID
*
* PARAMETERS: objectID - id of the object to change
*
* RETURNED: value of the object
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* rbb 4/14/99 Initial Revision
*
***********************************************************************/
static Int16 GetObjectValue (UInt16 objectID)
{
ControlPtr ctl;
ctl = GetObjectPtr (objectID);
return CtlGetValue (ctl);
}
/***********************************************************************
*
* FUNCTION: ChangeCategory
*
* DESCRIPTION: This routine updates the global variables that keep track
* of category information.
*
* PARAMETERS: category - new category (index)
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 3/10/95 Initial Revision
*
***********************************************************************/
static void ChangeCategory (UInt16 category)
{
CurrentCategory = category;
TopVisibleRecord = 0;
}
/***********************************************************************
*
* 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -