📄 memomain.c
字号:
FrmDrawForm (frm);
handled = true;
}
return (handled);
}
#pragma mark ----
/***********************************************************************
*
* FUNCTION: DetailsSelectCategory
*
* DESCRIPTION: This routine handles selection, creation and deletion of
* categories form the Details Dialog.
*
* PARAMETERS: nothing
*
* RETURNED: index of the selected category.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 03/10/95 Initial Revision
* gap 08/13/99 Update to use new constant categoryDefaultEditCategoryString.
*
***********************************************************************/
static UInt16 DetailsSelectCategory (UInt16* category)
{
Char* name;
Boolean categoryEdited;
name = (Char *)CtlGetLabel (GetObjectPtr (DetailsCategoryTrigger));
categoryEdited = CategorySelect (MemoDB, FrmGetActiveForm (),
DetailsCategoryTrigger, DetailsCategoryList,
false, category, name, 1, categoryDefaultEditCategoryString);
return (categoryEdited);
}
/***********************************************************************
*
* FUNCTION: DetailsApply
*
* DESCRIPTION: This routine applies the changes made in the Details Dialog.
*
* PARAMETERS: category - new catagory
*
* RETURNED: code which indicates how the memo was changed, this
* code is sent as the update code, in the frmUpdate event.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 3/10/95 Initial Revision
* kcr 10/9/95 added 'private records' alert.
*
***********************************************************************/
static UInt16 DetailsApply (UInt16 category, Boolean categoryEdited)
{
UInt16 attr;
UInt16 updateCode = 0;
Boolean dirty = false;
Boolean secret;
// Get the category and secret attribute of the current record.
DmRecordInfo (MemoDB, CurrentRecord, &attr, NULL, NULL);
// Get the current setting of the secret checkbox.
secret = (CtlGetValue (GetObjectPtr (DetailsSecretCheckbox)) != 0);
// Has the secret attribute was been changed?
if (((attr & dmRecAttrSecret) == dmRecAttrSecret) != secret)
{
if (secret)
{
attr |= dmRecAttrSecret;
if (PrivateRecordVisualStatus == showPrivateRecords)
FrmAlert (privateRecordInfoAlert);
}
else
attr &= ~dmRecAttrSecret;
dirty = true;
}
// Has the category been changed?
if (CurrentCategory != category)
{
attr &= ~dmRecAttrCategoryMask;
attr |= category;
dirty = true;
updateCode = updateCategoryChanged;
}
// If the current category was deleted, renamed, or merged with
// another category, then the list view needs to be redrawn.
if (categoryEdited)
{
CurrentCategory = category;
updateCode |= updateCategoryChanged;
}
if (dirty)
{
attr |= dmRecAttrDirty;
DmSetRecordInfo (MemoDB, CurrentRecord, &attr, NULL);
}
return (updateCode);
}
/***********************************************************************
*
* FUNCTION: DetailsInit
*
* DESCRIPTION: This routine initializes the Details Dialog.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 3/10/95 Initial Revision
*
***********************************************************************/
static void DetailsInit (void)
{
UInt16 attr;
UInt16 category;
Char* name;
Boolean secret;
ControlPtr ctl;
// Get the category and secret attribute of the current record.
DmRecordInfo (MemoDB, CurrentRecord, &attr, NULL, NULL);
category = attr & dmRecAttrCategoryMask;
secret = attr & dmRecAttrSecret;
// If the record is marked secret, turn on the secret checkbox.
ctl = GetObjectPtr (DetailsSecretCheckbox);
if (secret)
CtlSetValue (ctl, true);
else
CtlSetValue (ctl, false);
// Set the label of the category trigger.
ctl = GetObjectPtr (DetailsCategoryTrigger);
name = (Char *)CtlGetLabel (ctl);
CategoryGetName (MemoDB, category, name);
CategorySetTriggerLabel (ctl, name);
}
/***********************************************************************
*
* FUNCTION: DetailsHandleEvent
*
* DESCRIPTION: This routine is the event handler for the "Details
* Dialog Box".
*
* PARAMETERS: event - a pointer to an EventType structure
*
* RETURNED: true if the event has handle and should not be passed
* to a higher level handler.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 2/21/95 Initial Revision
*
***********************************************************************/
static Boolean DetailsHandleEvent (EventType * event)
{
static UInt16 category;
static Boolean categoryEdited;
UInt16 updateCode;
FormPtr frm;
Boolean handled = false;
if (event->eType == ctlSelectEvent)
{
switch (event->data.ctlSelect.controlID)
{
case DetailsOkButton:
updateCode = DetailsApply (category, categoryEdited);
FrmReturnToForm (EditView);
if (updateCode)
FrmUpdateForm (EditView, updateCode);
handled = true;
break;
case DetailsCancelButton:
if (categoryEdited)
FrmUpdateForm (EditView, updateCategoryChanged);
FrmReturnToForm (EditView);
handled = true;
break;
case DetailsDeleteButton:
if ( EditViewDeleteRecord ())
{
frm = FrmGetActiveForm();
FrmEraseForm (frm);
FrmDeleteForm (frm);
FrmCloseAllForms ();
FrmGotoForm (ListView);
}
handled = true;
break;
case DetailsCategoryTrigger:
categoryEdited = DetailsSelectCategory (&category) || categoryEdited;
handled = true;
break;
}
}
else if (event->eType == frmOpenEvent)
{
frm = FrmGetActiveForm ();
DetailsInit ();
FrmDrawForm (frm);
category = CurrentCategory;
categoryEdited = false;
handled = true;
}
return (handled);
}
#pragma mark ----
/***********************************************************************
*
* FUNCTION: EditViewSetTitle
*
* DESCRIPTION: This routine formats and sets the title of the Edit View.
* If the Edit View is visible, the new title is drawn.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* HISTORY:
* 02/21/95 art Created by Art Labm.
* 08/31/00 kwk Re-wrote to use TxtParamString, versus hard-coding
* order of elements using '#' in template string.
* 11/22/00 FPa Added DmReleaseResource()
* 11/28/00 CS Use FrmSetTitle instead of FrmCopyTitle and leave it
* allocated until EditViewExit. This removes the
* dependency that the form title in the resource has to
* be wide enough to accomodate the longest possible title.
* 11/30/00 FPa Fixed bug #46014
*
***********************************************************************/
static void EditViewSetTitle (void)
{
MemHandle titleTemplateH;
Char * titleTemplateP;
Char * title;
Char * oldTitle;
Char posStr[maxStrIToALen + 1];
Char totalStr[maxStrIToALen + 1];
UInt16 pos;
FormType* formP;
formP = FrmGetFormPtr(EditView);
// If there's an old title, we must free it; nevertheless FrmSetTitle() uses the old title -> we need to free it *after* having called FrmSetTitle()
oldTitle = (Char*)FrmGetTitle(formP);
// Format as strings, the memo's postion within its category, and
// the total number of memos in the category.
pos = DmPositionInCategory( MemoDB,CurrentRecord, ShowAllCategories ? dmAllCategories : CurrentCategory);
StrIToA(posStr, pos+1);
StrIToA(totalStr, MemosInCategory);
titleTemplateH = DmGetResource(strRsc, EditTitleString);
titleTemplateP = MemHandleLock(titleTemplateH);
title = TxtParamString(titleTemplateP, posStr, totalStr, NULL, NULL); // title needs to be freed
FrmSetTitle(formP, title);
if (oldTitle != 0)
MemPtrFree(oldTitle);
MemHandleUnlock(titleTemplateH);
DmReleaseResource(titleTemplateH);
}
/***********************************************************************
*
* FUNCTION: EditViewSelectCategory
*
* DESCRIPTION: This routine recategorizes a memo in the "Edit View".
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* The following global variables are modified:
* CurrentCategory
* CategoryName
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 10/03/95 Initial Revision
* grant 86/29/99 Adjust MemosInCategory when the record is private
* gap 08/13/99 Update to use new constant categoryDefaultEditCategoryString.
*
***********************************************************************/
static void EditViewSelectCategory (void)
{
UInt16 attr;
FormPtr frm;
UInt16 category;
Boolean categorySelected;
Boolean categoryEdited;
// Get the current category.
DmRecordInfo (MemoDB, CurrentRecord, &attr, NULL, NULL);
category = attr & dmRecAttrCategoryMask;
// Process the category popup list.
frm = FrmGetActiveForm();
categoryEdited = CategorySelect (MemoDB, frm, EditCategoryTrigger,
EditCategoryList, false, &category, CategoryName, 1, categoryDefaultEditCategoryString);
categorySelected = category != (attr & dmRecAttrCategoryMask);
// If a different category was selected, set the category field
// in the new record.
if (categorySelected)
{
// Change the category of the record.
DmRecordInfo (MemoDB, CurrentRecord, &attr, NULL, NULL);
attr &= ~dmRecAttrCategoryMask;
attr |= category | dmRecAttrDirty;
DmSetRecordInfo (MemoDB, CurrentRecord, &attr, NULL);
}
// If the current category was changed or the name of the category
// was edited, draw the title.
if (categoryEdited || categorySelected)
{
ChangeCategory (category);
// If the record is secret and secret records are hidden, then the record isn't
// accounted for by MemosInCategory. Adjust it, and EditViewSaveRecord will
// adjust when done with the record.
if ((PrivateRecordVisualStatus == hidePrivateRecords) && (attr & dmRecAttrSecret))
MemosInCategory++;
EditViewSetTitle ();
}
}
/***********************************************************************
*
* FUNCTION: EditViewUpdateScrollBar
*
* 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
*
***********************************************************************/
static void EditViewUpdateScrollBar ()
{
UInt16 scrollPos;
UInt16 textHeight;
UInt16 fieldHeight;
Int16 maxValue;
FieldPtr fld;
ScrollBarPtr bar;
fld = GetObjectPtr (EditMemoField);
bar = GetObjectPtr (EditMemoScrollBar);
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: EditViewLoadRecord
*
* DESCRIPTION: This routine loads a memo record into the Edit View form.
*
* PARAMETERS: frm - pointer to the Edit View form
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 2/21/95 Initial Revision
* roger 6/24/99 Fixup MemosInCategory when the record is private
* peter 4/25/00 Add support for un-masking just the selected record.
*
***********************************************************************/
static void EditViewLoadRecord (FormPtr frm)
{
UInt16 attr;
FieldPtr fld;
ControlPtr ctl;
MemHandle memoRec;
Boolean capsLock, numLock, autoShifted;
UInt16 tempShift;
if ((GrfGetState(&capsLock, &numLock, &tempShift, &autoShifted) == 0)
&& (autoShifted))
{
GrfSetState(capsLock, numLock, false);
}
// Get a pointer to the memo field.
fld = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, EditMemoField));
DmRecordInfo (MemoDB, CurrentRecord, &attr, NULL, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -