📄 memomain.c
字号:
*
* DESCRIPTION: Register with the Exchange Manager to receive .txt and
* text/plain.
*
* PARAMETERS: none
*
* RETURNED: nothing
*
* HISTORY:
* 7/28/00 dje Initial Revision.
*
***********************************************************************/
static void RegisterData(void)
{
MemHandle resH;
void *desc;
resH = DmGetResource(strRsc, ExgDescriptionStr);
desc = MemHandleLock(resH);
ExgRegisterDatatype(sysFileCMemo, exgRegExtensionID, memoExtension, desc, 0);
ExgRegisterDatatype(sysFileCMemo, exgRegTypeID, memoMIMEType, desc, 0);
MemHandleUnlock(resH);
DmReleaseResource(resH);
}
/***********************************************************************
*
* FUNCTION: MemoLoadPrefs
*
* DESCRIPTION: Load the preferences and do any fixups needed for backwards
* and forwards compatibility
*
* PARAMETERS: currentRecordID <- returned record id from preferences.
*
* RETURNED: nothing
*
* HISTORY:
* 01/13/98 BGT Initial Revision.
* 08/04/99 kwk Cleaned up setting EditFont/ListFont from prefs.
*
***********************************************************************/
void MemoLoadPrefs(UInt32* currentRecordID)
{
MemoPreferenceType prefs;
UInt16 prefsSize;
Int16 prefsVersion;
Boolean needFontInfo = false;
// Read the preferences / saved-state information.
prefsSize = sizeof (MemoPreferenceType);
prefsVersion = PrefGetAppPreferences (sysFileCMemo, memoPrefID, &prefs, &prefsSize, true);
if (prefsVersion > memoPrefsVersionNum) {
prefsVersion = noPreferenceFound;
}
if (prefsVersion > noPreferenceFound)
{
// Try to carry forward the version 2 preferences for the font
if (prefsVersion < 2)
{
// No font data in original prefs
needFontInfo = true;
}
else if (prefsVersion == 2)
{
prefs.editFont = prefs.v20editFont;
prefs.listFont = prefs.v20listFont;
// Use the 'better' large font if we've got it, since version 2
// prefs would have been created on an older version of the OS
// which didn't have the largeBoldFont available.
if (prefs.editFont == largeFont)
prefs.editFont = largeBoldFont;
if (prefs.listFont == largeFont)
prefs.listFont = largeBoldFont;
}
TopVisibleRecord = prefs.topVisibleRecord;
CurrentRecord = prefs.currentRecord;
CurrentView = prefs.currentView;
CurrentCategory = prefs.currentCategory;
EditScrollPosition = prefs.editScrollPosition;
ShowAllCategories = prefs.showAllCategories;
SaveBackup = prefs.saveBackup;
*currentRecordID = prefs.currentRecordID;
}
else
{
needFontInfo = true;
}
// If the prefs didn't supply us with font info, we'll need to get it ourselves.
if (needFontInfo)
{
UInt32 defaultFont;
FtrGet(sysFtrCreator, sysFtrDefaultFont, &defaultFont);
EditFont = (FontID)defaultFont;
ListFont = (FontID)defaultFont;
}
else
{
EditFont = prefs.editFont;
ListFont = prefs.listFont;
}
// The first time this app starts register to handle .txt and text/plain.
if (prefsVersion != memoPrefsVersionNum)
RegisterData();
}
/***********************************************************************
*
* FUNCTION: MemoSavePrefs
*
* DESCRIPTION: Save the preferences and do any fixups needed for backwards
* and forwards compatibility
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* BGT 1/13/98 Initial Revision
*
***********************************************************************/
void MemoSavePrefs(UInt16 scrollPosition)
{
MemoPreferenceType prefs;
UInt32 uniqueID;
// Write the preferences / saved-state information.
prefs.topVisibleRecord = TopVisibleRecord;
prefs.currentRecord = CurrentRecord;
prefs.currentView = CurrentView;
prefs.currentCategory = CurrentCategory;
prefs.showAllCategories = ShowAllCategories;
prefs.editScrollPosition = scrollPosition;
prefs.saveBackup = SaveBackup;
prefs.editFont = EditFont;
prefs.listFont = ListFont;
prefs.v20editFont = stdFont;
prefs.v20listFont = stdFont;
// Clear reserved fields so prefs don't look "different" just from stack garbage!
prefs.reserved1 = 0;
prefs.reserved2 = 0;
// Get the current record's unique id and save it with the state
// information.
if ( DmQueryRecord (MemoDB, CurrentRecord) != 0)
{
DmRecordInfo (MemoDB, CurrentRecord, NULL, &uniqueID, NULL);
prefs.currentRecordID = uniqueID;
}
else
prefs.currentRecordID = noRecordSelectedID;
// Write the state information.
PrefSetAppPreferences (sysFileCMemo, memoPrefID, memoPrefsVersionNum, &prefs,
sizeof (MemoPreferenceType), true);
}
/***********************************************************************
*
* 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: GetFocusObjectPtr
*
* DESCRIPTION: This routine returns a pointer to the field object, in
* the current form, that has the focus.
*
* PARAMETERS: nothing
*
* RETURNED: pointer to a field object or NULL of there is no fucus
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 2/21/95 Initial Revision
*
***********************************************************************/
static FieldPtr GetFocusObjectPtr (void)
{
FormPtr frm;
UInt16 focus;
frm = FrmGetActiveForm ();
focus = FrmGetFocus (frm);
if (focus == noFocus)
return (NULL);
return (FrmGetObjectPtr (frm, focus));
}
/***********************************************************************
*
* FUNCTION: SeekRecord
*
* DESCRIPTION: Given the index of a 'to do' record, this routine scans
* forwards or backwards for displayable 'to do' records.
*
* PARAMETERS: indexP - pointer to the index of a record to start from;
* the index of the record sought is returned in
* this parameter.
*
* offset - number of records to skip:
* 0 - mean seek from the current record to the
* next display record, if the current record is
* a displayable record, its index is retuned.
* 1 - mean seek foreward, skipping one displayable
* record
* -1 - menas seek backwards, skipping one
* displayable record
*
*
* RETURNED: false is return if a displayable record was not found.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/5/95 Initial Revision
*
***********************************************************************/
static Boolean SeekRecord (UInt16 * indexP, Int16 offset, Int16 direction)
{
DmSeekRecordInCategory (MemoDB, indexP, offset, direction, CurrentCategory);
if (DmGetLastErr()) return (false);
return (true);
}
/***********************************************************************
*
* FUNCTION: ChangeCategory
*
* DESCRIPTION: This routine updates the global varibles 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)
{
if (ShowAllCategories)
MemosInCategory = DmNumRecordsInCategory (MemoDB, dmAllCategories);
else
MemosInCategory = DmNumRecordsInCategory (MemoDB, category);
CurrentCategory = category;
TopVisibleRecord = 0;
}
/***********************************************************************
*
* FUNCTION: DrawMemoTitle
*
* DESCRIPTION: This routine draws the title of the specified memo.
*
* PARAMETERS: memo - pointer to a memo
* x - draw position
* y - draw position
* width - maximum width to draw.
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 04/18/95 Initial Revision
* roger 07/27/95 Combined both cases
* kwk 05/15/99 Use Int'l code for truncation of title.
*
***********************************************************************/
static void DrawMemoTitle (Char * memo, Int16 x, Int16 y, Int16 width)
{
Char * ptr = StrChr (memo, linefeedChr);
UInt16 titleLen = (ptr == NULL ? StrLen (memo) : (UInt16) (ptr - memo));
if (FntWidthToOffset (memo, titleLen, width, NULL, NULL) == titleLen)
{
WinDrawChars (memo, titleLen, x, y);
}
else
{
Int16 titleWidth;
titleLen = FntWidthToOffset (memo, titleLen, width - FntCharWidth (chrEllipsis), NULL, &titleWidth);
WinDrawChars (memo, titleLen, x, y);
WinDrawChar (chrEllipsis, x + titleWidth, y);
}
}
/***********************************************************************
*
* FUNCTION: ReplaceTwoColors
*
* DESCRIPTION: This routine does a selection or deselection effect by
* replacing foreground and background colors with a new pair
* of colors. In order to reverse the process, you must pass
* the colors in the opposite order, so that the current
* and new colors are known to this routine. This routine
* correctly handling the cases when two or more of these
* four colors are the same, but it requires that the
* affected area of the screen contains neither of the
* given NEW colors, unless these colors are the same as
* one of the old colors.
*
* PARAMETERS: rP - pointer to a rectangle to 'invert'
* cornerDiam - corner diameter
* oldForeground - UI color currently used for foreground
* oldBackground - UI color currently used for background
* newForeground - UI color that you want for foreground
* newBackground - UI color that you want for background
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* peter 05/19/00 Initial Revision
*
***********************************************************************/
static void ReplaceTwoColors (const RectangleType *rP, UInt16 cornerDiam,
UIColorTableEntries oldForeground, UIColorTableEntries oldBackground,
UIColorTableEntries newForeground, UIColorTableEntries newBackground)
{
UInt8 oldForegroundIndex = UIColorGetTableEntryIndex(oldForeground);
UInt8 oldBackgroundIndex = UIColorGetTableEntryIndex(oldBackground);
UInt8 newForegroundIndex = UIColorGetTableEntryIndex(newForeground);
UInt8 newBackgroundIndex = UIColorGetTableEntryIndex(newBackground);
WinPushDrawState();
WinSetDrawMode(winSwap);
WinSetPatternType (blackPattern);
if (newBackgroundIndex == oldForegroundIndex)
if (newForegroundIndex == oldBackgroundIndex)
{
// Handle the case when foreground and background colors change places,
// such as on black and white systems, with a single swap.
WinSetBackColor(oldBackgroundIndex);
WinSetForeColor(oldForegroundIndex);
WinPaintRectangle(rP, cornerDiam);
}
else
{
// Handle the case when the old foreground and the new background
// are the same, using two swaps.
WinSetBackColor(oldForegroundIndex);
WinSetForeColor(oldBackgroundIndex);
WinPaintRectangle(rP, cornerDiam);
WinSetBackColor(oldBackgroundIndex);
WinSetForeColor(newForegroundIndex);
WinPaintRectangle(rP, cornerDiam);
}
else if (oldBackgroundIndex == newForegroundIndex)
{
// Handle the case when the old background and the new foreground
// are the same, using two swaps.
WinSetBackColor(newForegroundIndex);
WinSetForeColor(oldForegroundIndex);
WinPaintRectangle(rP, cornerDiam);
WinSetBackColor(newBackgroundIndex);
WinSetForeColor(oldForegroundIndex);
WinPaintRectangle(rP, cornerDiam);
}
else
{
// Handle the case when no two colors are the same, as is typically the case
// on color systems, using two swaps.
WinSetBackColor(oldBackgroundIndex);
WinSetForeColor(newBackgroundIndex);
WinPaintRectangle(rP, cornerDiam);
WinSetBackColor(oldForegroundIndex);
WinSetForeColor(newForegroundIndex);
WinPaintRectangle(rP, cornerDiam);
}
WinPopDrawState();
}
/***********************************************************************
*
* FUNCTION: Search
*
* DESCRIPTION: This routine searchs the memo database for records
* containing the string passed.
*
* PARAMETERS: findParams - text search parameter block
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 04/18/95 Initial Revision
* roger 07/26/95 converted to modern search mechanism
* kwk 05/15/99 Use TxtFindString, save match length in custom param.
* jmp 10/01/99 Changed call to DmOpenDatabaseByTypeCreator() to
* MemoGetDatabase().
* jmp 10/21/99 Previous change caused bug #22965, but previous code
* caused yet another problem. Fixed #22965 by using
* everyone else's way: Call DmGetNextDatabaseByTypeCreator()
* first, then call DmOpenDatabase() if all is well.
*
***********************************************************************/
static void Search (FindParamsPtr findParams)
{
UInt16 pos;
Char * header;
UInt16 recordNum;
MemHandle recordH;
MemHandle headerStringH;
RectangleType r;
Boolean done;
Boolean match;
DmOpenRef dbP;
DmSearchStateType searchState;
Err err;
UInt16 cardNo = 0;
LocalID dbID;
MemoDBRecordPtr memoRecP;
UInt32 longPos;
UInt16 matchLength;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -