📄 sugarmemoedit.c
字号:
attr &= ~dmRecAttrCategoryMask;
attr |= ((CurrentCategory == dmAllCategories) ? dmUnfiledCategory :
CurrentCategory) | dmRecAttrDirty;
DmSetRecordInfo (CurrentDB, CurrentRecord, &attr, NULL);
IncrementRawWordCount();
// Set the global variable that determines which field is the top visible
// field in the edit view. Also done when New is pressed.
TopVisibleFieldIndex = 0;
CurrentFieldIndex = 0;
EditRowIDWhichHadFocus = 0;
EditFieldPosition = 0;
FrmGotoForm(EditForm);
}
void EditFormScroll (WinDirectionType direction)
{
UInt16 row;
UInt16 height;
UInt16 fieldIndex;
UInt16 columnWidth;
UInt16 tableHeight;
TablePtr table;
//FontID curFont;
RectangleType r;
WordRecordType record;
MemHandle recordH;
FormType* frmP;
// Before processing the scroll, be sure that the command bar has been closed.
MenuEraseStatus (0);
frmP = FrmGetActiveForm();
FntSetFont (stdFont);
table = GetObjectPtr(EditEditTable);
TblReleaseFocus (table);
// Get the height of the table and the width of the description
// column.
TblGetBounds (table, &r);
tableHeight = r.extent.y;
height = 0;
columnWidth = TblGetColumnWidth (table, dataColumn);
// Scroll the table down.
if (direction == winDown)
{
// Get the index of the last visible field, this will become
// the index of the top visible field, unless it occupies the
// whole screeen, in which case the next field will be the
// top filed.
row = TblGetLastUsableRow (table);
fieldIndex = TblGetRowID (table, row);
// If the last visible field is also the first visible field
// then it occupies the whole screeen.
if (row == 0)
fieldIndex = min (MaxFieldIndex, fieldIndex+1);
}
// Scroll the table up.
else
{
// Scan the fields before the first visible field to determine
// how many fields we need to scroll. Since the heights of the
// fields vary, we sum the height of the records until we get
// a screen full.
fieldIndex = TblGetRowID (table, 0);
ErrFatalDisplayIf(fieldIndex > MaxFieldIndex, "Invalid field Index");
if (fieldIndex == 0)
goto exit;
// Get the current record
GetWordRecord (CurrentDB, CurrentRecord, &record, &recordH);
height = TblGetRowHeight (table, 0);
if (height >= tableHeight)
height = 0;
while (height < tableHeight && fieldIndex > 0)
{
height += FldCalcFieldHeight (record.field[FieldMap[fieldIndex-1]],
columnWidth) * FntLineHeight ();
if ((height <= tableHeight) || (fieldIndex == TblGetRowID (table, 0)))
fieldIndex--;
}
MemHandleUnlock(recordH);
}
TblMarkTableInvalid (table);
CurrentFieldIndex = noFieldIndex;
TopVisibleFieldIndex = fieldIndex;
EditRowIDWhichHadFocus = FirstFieldIndex;
EditFieldPosition = 0;
TblUnhighlightSelection (table); // remove the highlight before reloading the table to avoid
// having an out of bounds selection information in case
// the newly loaded data doesn't have as many rows as the old
// data. This fixes the bug
// "File: Table.c, Line: 2599, currentRow violated constraint!"
// (fix suggested by Art) vmk 2/20/98
EditFormLoadTable(frmP);
//TblUnhighlightSelection (table); // moved call before PrvEditLoadTable vmk 2/20/98
TblRedrawTable (table);
exit:
FntSetFont (stdFont);
}
void EditFormResizeField (EventType * event)
{
UInt16 pos;
Int16 row;
Int16 column;
Int16 lastRow;
UInt16 fieldIndex;
UInt16 lastFieldIndex;
UInt16 topFieldIndex;
FieldPtr fld;
TablePtr table;
Boolean restoreFocus = false;
Boolean lastItemClipped;
RectangleType itemR;
RectangleType tableR;
RectangleType fieldR;
FormType* frmP;
frmP = FrmGetActiveForm();
// Get the current height of the field;
fld = event->data.fldHeightChanged.pField;
FldGetBounds (fld, &fieldR);
// Have the table object resize the field and move the items below
// the field up or down.
table = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, EditEditTable));
TblHandleEvent (table, event);
// If the field's height has expanded , we're done.
if (event->data.fldHeightChanged.newHeight >= fieldR.extent.y)
{
topFieldIndex = TblGetRowID (table, 0);
if (topFieldIndex != TopVisibleFieldIndex)
TopVisibleFieldIndex = topFieldIndex;
else
{
// Since the table has expanded we may be able to scroll
// when before we might not have.
lastRow = TblGetLastUsableRow (table);
TblGetBounds (table, &tableR);
TblGetItemBounds (table, lastRow, dataColumn, &itemR);
lastItemClipped = (itemR.topLeft.y + itemR.extent.y >
tableR.topLeft.y + tableR.extent.y);
lastFieldIndex = TblGetRowID (table, lastRow);
EditUpdateScrollers(frmP, lastFieldIndex, lastItemClipped);
return;
}
}
// If the field's height has contracted and the field edit field
// is not visible then the table may be scrolled. Release the
// focus, which will force the saving of the field we are editing.
else if (TblGetRowID (table, 0) != FirstFieldIndex)
{
TblGetSelection (table, &row, &column);
fieldIndex = TblGetRowID (table, row);
fld = TblGetCurrentField (table);
pos = FldGetInsPtPosition (fld);
TblReleaseFocus (table);
restoreFocus = true;
}
// Add items to the table to fill in the space made available by the
// shorting the field.
EditFormLoadTable(frmP);
TblRedrawTable (table);
// Restore the insertion point position.
if (restoreFocus)
{
TblFindRowID (table, fieldIndex, &row);
TblGrabFocus (table, row, column);
FldSetInsPtPosition (fld, pos);
FldGrabFocus (fld);
}
}
UInt16 EditCategorySelection (void)
{
UInt16 attr;
FormType* frmP;
UInt16 category;
Boolean categoryEdited;
// Process the category popup list.
DmRecordInfo (CurrentDB, CurrentRecord, &attr, NULL, NULL);
category = attr & dmRecAttrCategoryMask;
frmP = FrmGetActiveForm();
categoryEdited = CategorySelect (CurrentDB, frmP, EditCategoryPopTrigger, EditWordCategoryList,
false, &category, EditCategoryName, 1, categoryDefaultEditCategoryString);
if (categoryEdited || (category != (attr & dmRecAttrCategoryMask)))
{
// Change the category of the record.
DmRecordInfo (CurrentDB, CurrentRecord, &attr, NULL, NULL);
attr &= ~dmRecAttrCategoryMask;
attr |= category | dmRecAttrDirty;
DmSetRecordInfo (CurrentDB, CurrentRecord, &attr, NULL);
//ToolsChangeCategory (category);
}
return (category);
}
void FieldSelection(Int16 row){
FormType * frmP;
TableType * tableP;
frmP = FrmGetActiveForm();
tableP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, EditEditTable));
CurrentFieldIndex = TblGetRowID(tableP, row);
if (FieldMap[TblGetRowID(tableP, row)] == WordFieldPhonetic){
TblUnhighlightSelection(tableP);
FrmPopupForm(PhoneticForm);
}
}
void EditDrawRecordField (void * table, Int16 row, Int16 column, RectanglePtr bounds){
WordRecordType record;
MemHandle recordH;
UInt16 fieldIndex;
FontID currFont;
fieldIndex = TblGetRowID(table, row);
if (FieldMap[fieldIndex] == WordFieldPhonetic){
GetWordRecord(CurrentDB, CurrentRecord, &record, &recordH);
if (record.field[WordFieldPhonetic]!=NULL){
currFont = FntSetFont(PhoneticSmallFont);
WinDrawChars(record.field[WordFieldPhonetic], StrLen(record.field[WordFieldPhonetic]),
bounds->topLeft.x, bounds->topLeft.y);
FntSetFont(currFont);
}
MemHandleUnlock(recordH);
return;
}
}
static void PhoneticInit(FormType * frmP);
static void DrawVowel (void * table, Int16 row, Int16 column, RectanglePtr bounds);
static void DrawConsonant (void * table, Int16 row, Int16 column, RectanglePtr bounds);
static void SavePhonetic();
Boolean PhoneticFormHandleEvent(EventType * event){
FormType* frmP = FrmGetActiveForm();
FieldType* fldP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, PhoneticInputField));
Char buffer[5];
Char* p;
Boolean handled = false;
switch (event->eType){
case frmOpenEvent:
PhoneticInit (frmP);
FrmDrawForm (frmP);
handled = true;
break;
case ctlSelectEvent:
switch(event->data.ctlSelect.controlID){
case PhoneticOKButton:
SavePhonetic();
FrmReturnToForm(EditForm);
FrmUpdateForm(EditForm, frmRedrawUpdateCode);
handled = true;
break;
case PhoneticCancelButton:
FrmReturnToForm(EditForm);
FrmUpdateForm(EditForm, frmRedrawUpdateCode);
handled = true;
break;
default:
break;
}
break;
case tblSelectEvent:
switch(event->data.tblSelect.tableID){
case PhoneticVowelTable:
TblUnhighlightSelection(event->data.tblSelect.pTable);
p = SysStringByIndex(VowelsStringList,
event->data.tblSelect.row * ColumnsInVowelTable
+ event->data.tblSelect.column, buffer, 4);
FldInsert(fldP, p, StrLen(p));
break;
case PhoneticConsonantTable:
TblUnhighlightSelection(event->data.tblSelect.pTable);
p = SysStringByIndex(ConsonantsStringList,
event->data.tblSelect.row * ColumnsInConsonantTable
+ event->data.tblSelect.column, buffer, 4);
FldInsert(fldP, p, StrLen(p));
break;
}
FrmSetFocus(frmP, FrmGetObjectIndex(frmP, PhoneticInputField));
FldGrabFocus(fldP);
handled = true;
break;
default:
break;
}
return handled;
}
void PhoneticInit(FormType * frmP){
TableType * table;
UInt16 row, column;
UInt16 rowsInTable;
WordRecordType record;
MemHandle recordH;
MemHandle textH, oldTextH;
Char* p;
UInt16 textAllocSize;
FieldType* fld;
table = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP,PhoneticVowelTable));
rowsInTable = TblGetNumberOfRows (table);
for (row = 0; row < rowsInTable; row++)
{
for (column = 0; column < ColumnsInVowelTable; column ++)
TblSetItemStyle (table, row, column, customTableItem);
TblSetRowUsable (table, row, true);
}
for (column = 0; column < ColumnsInVowelTable; column ++){
TblSetColumnUsable (table, column, true);
TblSetCustomDrawProcedure (table, column, DrawVowel);
}
table = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP,PhoneticConsonantTable));
rowsInTable = TblGetNumberOfRows (table);
for (row = 0; row < rowsInTable; row++)
{
for (column = 0; column < ColumnsInVowelTable; column ++)
TblSetItemStyle (table, row, column, customTableItem);
TblSetRowUsable (table, row, true);
}
for (column = 0; column < ColumnsInConsonantTable; column ++){
TblSetColumnUsable (table, column, true);
TblSetCustomDrawProcedure (table, column, DrawConsonant);
}
//Get the record
GetWordRecord(CurrentDB, CurrentRecord, &record, &recordH); //recordH locked
//Calculate mem handle size
if (record.field[WordFieldPhonetic] != NULL)
textAllocSize = StrLen(record.field[WordFieldPhonetic]) + 1; //for null terminator
else
textAllocSize = 1;
//Allocate textH
textH = MemHandleNew(textAllocSize);
p = MemHandleLock(textH); //textH locked
//clear it
MemSet(p, textAllocSize, 0);
//copy
MemMove(p, record.field[WordFieldPhonetic], textAllocSize - 1);
//unlock
MemHandleUnlock(recordH);
MemHandleUnlock(textH);
fld = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, PhoneticInputField));
oldTextH = FldGetTextHandle(fld);
FldSetTextHandle(fld, textH);
if (oldTextH) MemHandleFree(oldTextH);
//set font
FldSetFont(fld, PhoneticSmallFont);
}
void DrawVowel (void * table, Int16 row, Int16 column, RectanglePtr bounds){
Char buffer[5];
Char* p;
FontID currFont;
UInt16 width, height;
currFont = FntSetFont(PhoneticSmallFont);
p = SysStringByIndex(VowelsStringList, row * ColumnsInVowelTable + column, buffer, 4);
if (p!=NULL){
width = FntCharsWidth(p, StrLen(p));
height = FntLineHeight();
WinDrawChars(p, StrLen(p), bounds->topLeft.x + (bounds->extent.x - width)/2,
bounds->topLeft.y + (bounds->extent.y - height)/2);
}
FntSetFont(currFont);
}
void DrawConsonant (void * table, Int16 row, Int16 column, RectanglePtr bounds){
Char buffer[5];
Char* p;
FontID currFont;
UInt16 width, height;
currFont = FntSetFont(PhoneticSmallFont);
p = SysStringByIndex(ConsonantsStringList, row * ColumnsInConsonantTable + column, buffer, 4);
if (p!=NULL){
width = FntCharsWidth(p, StrLen(p));
height = FntLineHeight();
WinDrawChars(p, StrLen(p), bounds->topLeft.x + (bounds->extent.x - width)/2,
bounds->topLeft.y + (bounds->extent.y - height)/2);
}
FntSetFont(currFont);
}
void SavePhonetic(){
FormType* frmP;
FieldType * fld;
MemHandle textH;
Char* textP;
WordRecordType record;
MemHandle recordH;
WordFieldFlags flag;
Err err;
//get field
frmP = FrmGetActiveForm();
fld = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, PhoneticInputField));
//if no change, directly return
if (!FldDirty(fld)) return;
//get text handle
textH = FldGetTextHandle(fld);
//remove selection
FldSetSelection(fld, 0, 0);
//set pointer
if (textH == 0)
textP = NULL;
else {
textP = MemHandleLock(textH); //lock once
if (textP[0] == '\0') textP = NULL;
}
//get record
GetWordRecord(CurrentDB, CurrentRecord, &record, &recordH);
//change field
record.field[WordFieldPhonetic] = textP;
//set change flag
flag.allBits = BitAtPosition(WordFieldPhonetic);
//save changes
err = ChangeWordRecord(CurrentDB, &CurrentRecord, &record, flag);
//seems different from that of .... palm code
if (textH != 0) MemHandleUnlock(textH);
//deal with err
if (err){
ErrNonFatalDisplay("Out of Memory");
MemHandleUnlock(recordH);
return;
}
ToolsDirtyRecord(CurrentRecord);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -