📄 addrnote.c
字号:
Boolean name1HasPriority;
IndexedColorType curForeColor;
IndexedColorType curBackColor;
IndexedColorType curTextColor;
AddrDBRecordType record;
MemHandle recordH;
UInt8 * lockedWinP;
Err error;
// "Lock" the screen so that all drawing occurs offscreen to avoid
// the anamolies associated with drawing the Form's title then drawing
// the NoteView title. We REALLY need to make a variant for doing
// this in a more official way!
//
lockedWinP = WinScreenLock (winLockCopy);
FrmDrawForm (frm);
// Peform initial set up.
//
FrmGetFormBounds (frm, &r);
formWidth = r.extent.x;
x = 2;
y = 1;
nameExtent = formWidth - 4;
// Save/Set window colors and font. Do this after FrmDrawForm() is called
// because FrmDrawForm() leaves the fore/back colors in a state that we
// don't want here.
//
curForeColor = WinSetForeColor (UIColorGetTableEntryIndex(UIFormFrame));
curBackColor = WinSetBackColor (UIColorGetTableEntryIndex(UIFormFill));
curTextColor = WinSetTextColor (UIColorGetTableEntryIndex(UIFormFrame));
curFont = FntSetFont (boldFont);
RctSetRectangle (&eraseRect, 0, 0, formWidth, FntLineHeight()+4);
RctSetRectangle (&drawRect, 0, 0, formWidth, FntLineHeight()+2);
// Erase the Form's title area and draw the NoteView's.
//
WinEraseRectangle (&eraseRect, 0);
WinDrawRectangle (&drawRect, 3);
error = AddrDBGetRecord(AddrDB, CurrentRecord, &record, &recordH);
ErrNonFatalDisplayIf(error, "Record not found");
name1HasPriority = ToolsDetermineRecordName(&record, &shortenedFieldWidth, &fieldSeparatorWidth, SortByCompany, &name1, &name1Length, &name1Width, &name2, &name2Length, &name2Width, &UnnamedRecordStringPtr, &UnnamedRecordStringH, nameExtent);
ToolsDrawRecordName(name1, name1Length, name1Width, name2, name2Length, name2Width,
nameExtent, &x, y, shortenedFieldWidth, fieldSeparatorWidth, true,
name1HasPriority || !SortByCompany, true);
// Now that we've drawn everything, blast it all back on the screen at once.
//
if (lockedWinP)
WinScreenUnlock ();
// Unlock the record that AddrGetRecord() implicitly locked.
//
MemHandleUnlock (recordH);
// Restore window colors and font.
//
WinSetForeColor (curForeColor);
WinSetBackColor (curBackColor);
WinSetTextColor (curTextColor);
FntSetFont (curFont);
}
/***********************************************************************
*
* FUNCTION: PrvNoteViewUpdateScrollBar
*
* DESCRIPTION: This routine update the scroll bar.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 07/01/96 Initial Revision
* gap 11/02/96 Fix case where field and scroll bars get out of sync
*
***********************************************************************/
void PrvNoteViewUpdateScrollBar (void)
{
UInt16 scrollPos;
UInt16 textHeight;
UInt16 fieldHeight;
Int16 maxValue;
FieldPtr fld;
ScrollBarPtr bar;
fld = ToolsGetObjectPtr (NoteField);
bar = ToolsGetObjectPtr (NoteScrollBar);
FldGetScrollValues (fld, &scrollPos, &textHeight, &fieldHeight);
if (textHeight > fieldHeight)
{
// On occasion, such as after deleting a multi-line selection of text,
// the display might be the last few lines of a field followed by some
// blank lines. To keep the current position in place and allow the user
// to "gracefully" scroll out of the blank area, the number of blank lines
// visible needs to be added to max value. Otherwise the scroll position
// may be greater than maxValue, get pinned to maxvalue in SclSetScrollBar
// resulting in the scroll bar and the display being out of sync.
maxValue = (textHeight - fieldHeight) + FldGetNumberOfBlankLines (fld);
}
else if (scrollPos)
maxValue = scrollPos;
else
maxValue = 0;
SclSetScrollBar (bar, scrollPos, 0, maxValue, fieldHeight-1);
}
/***********************************************************************
*
* FUNCTION: PrvNoteViewLoadRecord
*
* DESCRIPTION: Load the record's note field into the field object
* for editing in place. The note field is too big (4K) to edit in
* the heap.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 6/21/95 Initial Revision
* roger 8/25/95 Changed to edit in place
* jmp 10/11/99 Replaced private MemDeref() call with MemHandleLock() so
* that the SDK build will work.
*
***********************************************************************/
void PrvNoteViewLoadRecord (void)
{
UInt16 offset;
FieldPtr fld;
MemHandle recordH;
Char * ptr;
AddrDBRecordType record;
// Get a pointer to the memo field.
fld = ToolsGetObjectPtr (NoteField);
// Set the font used in the memo field.
FldSetFont (fld, NoteFont);
AddrDBGetRecord (AddrDB, CurrentRecord, &record, &recordH);
// CreateNote will have been called before the NoteView was switched
// to. It will have insured that a note field exists.
// Find out where the note field is to edit it
ptr = MemHandleLock (recordH);
offset = record.fields[note] - ptr;
FldSetText (fld, recordH, offset, StrLen(record.fields[note])+1);
// Unlock recordH twice because AddrGetRecord() locks it, and we had to lock
// it to deref it. Whacky.
MemHandleUnlock(recordH);
MemHandleUnlock(recordH);
}
/***********************************************************************
*
* FUNCTION: PrvNoteViewSave
*
* DESCRIPTION: This routine
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/5/95 Initial Revision
* roger 8/25/95 Changed to edit in place
*
***********************************************************************/
void PrvNoteViewSave (void)
{
FieldPtr fld;
int textLength;
fld = ToolsGetObjectPtr (NoteField);
// If the field wasn't modified then don't do anything
if (FldDirty (fld))
{
// Release any free space in the note field.
FldCompactText (fld);
ToolsDirtyRecord (CurrentRecord);
}
textLength = FldGetTextLength(fld);
// Clear the handle value in the field, otherwise the handle
// will be freed when the form is disposed of, this call also unlocks
// the handle that contains the note string.
FldSetTextHandle (fld, 0);
// Empty fields are not allowed because they cause problems
if (textLength == 0)
NoteViewDelete();
}
/***********************************************************************
*
* FUNCTION: PrvNoteViewDeleteNote
*
* DESCRIPTION: This routine deletes a the note field from a to do record.
*
* PARAMETERS: nothing
*
* RETURNED: true if the note was deleted.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/5/95 Initial Revision
*
***********************************************************************/
Boolean PrvNoteViewDeleteNote (void)
{
FieldPtr fld;
TraceOutput(TL(appErrorClass, "PrvNoteViewDeleteNote() - UnnamedRecordStringH = %hu - Before FrmAlert()", UnnamedRecordStringH));
// CodeWarrior in Debug creates a problem... FrmAlert() sets UnnamedRecordStringH to 0 -> memory leak
if (FrmAlert(DeleteNoteAlert) != DeleteNoteYes)
return (false);
TraceOutput(TL(appErrorClass, "PrvNoteViewDeleteNote() - UnnamedRecordStringH = %hu - After FrmAlert()", UnnamedRecordStringH));
// Unlock the handle that contains the text of the memo.
fld = ToolsGetObjectPtr (NoteField);
ErrFatalDisplayIf ((! fld), "Bad field");
// Clear the handle value in the field, otherwise the handle
// will be freed when the form is disposed of. this call also
// unlocks the handle the contains the note string.
FldCompactText (fld);
FldSetTextHandle (fld, 0);
NoteViewDelete();
return (true);
}
/***********************************************************************
*
* FUNCTION: PrvNoteViewDoCommand
*
* DESCRIPTION: This routine performs the menu command specified.
*
* PARAMETERS: command - menu item id
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/5/95 Initial Revision
* jmp 9/8/99 Moved the noteFontCmd case to where it is in this
* routine in all the other NoteView implementations.
* jmp 9/17/99 Eliminate the goto top/bottom of page menu items
* as NewNoteView no longer supports them.
*
***********************************************************************/
Boolean PrvNoteViewDoCommand (UInt16 command)
{
FieldPtr fld;
Boolean handled = true;
switch (command)
{
case newNoteFontCmd:
NoteFont = ToolsSelectFont (NoteFont);
break;
case newNotePhoneLookupCmd:
fld = ToolsGetObjectPtr (NoteField);
PhoneNumberLookup (fld);
break;
default:
handled = false;
}
return (handled);
}
/***********************************************************************
*
* FUNCTION: PrvNoteViewScroll
*
* DESCRIPTION: This routine scrolls the Note View by the specified
* number of lines.
*
* PARAMETERS: linesToScroll - the number of lines to scroll,
* positive for down,
* negative for up
* updateScrollbar - force a scrollbar update?
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/1/96 Initial Revision
* grant 2/2/99 Use PrvNoteViewUpdateScrollBar()
*
***********************************************************************/
void PrvNoteViewScroll (Int16 linesToScroll, Boolean updateScrollbar)
{
UInt16 blankLines;
FieldPtr fld;
fld = ToolsGetObjectPtr (NoteField);
blankLines = FldGetNumberOfBlankLines (fld);
if (linesToScroll < 0)
FldScrollField (fld, -linesToScroll, winUp);
else if (linesToScroll > 0)
FldScrollField (fld, linesToScroll, winDown);
// If there were blank lines visible at the end of the field
// then we need to update the scroll bar.
if (blankLines && linesToScroll < 0 || updateScrollbar)
{
PrvNoteViewUpdateScrollBar();
}
}
/***********************************************************************
*
* FUNCTION: PrvNoteViewPageScroll
*
* DESCRIPTION: This routine scrolls the message a page up or down.
*
* PARAMETERS: direction up or down
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/1/96 Initial Revision
* grant 2/2/99 Use PrvNoteViewScroll() to do actual scrolling
*
***********************************************************************/
void PrvNoteViewPageScroll (WinDirectionType direction)
{
Int16 linesToScroll;
FieldPtr fld;
fld = ToolsGetObjectPtr (NoteField);
if (FldScrollable (fld, direction))
{
linesToScroll = FldGetVisibleLines (fld) - 1;
if (direction == winUp)
linesToScroll = -linesToScroll;
PrvNoteViewScroll(linesToScroll, true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -