⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addredit.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
	FldSetInsPtPosition (fld, event->data.fldHeightChanged.currentPos);
	
	// Turn the insertion point back on.
	InsPtEnable (insPtState);
	
	fld = TblGetCurrentField (table);
	if (fld != NULL)
	{
		FldDrawField (fld);
	}
#else /* not ADDR_FOCUS_FIX */
	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 = ToolsGetFrmObjectPtr(frmP, EditTable);
	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, editDataColumn, &itemR);
			lastItemClipped = (itemR.topLeft.y + itemR.extent.y >
							   tableR.topLeft.y + tableR.extent.y);
			lastFieldIndex = TblGetRowID (table, lastRow);

			PrvEditUpdateScrollers(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) != editFirstFieldIndex)
	{
		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.
	PrvEditLoadTable(frmP);
	TblRedrawTable (table);

	// Restore the insertion point position.
	if (restoreFocus)
	{
		TblFindRowID (table, fieldIndex, &row);
		TblGrabFocus (table, row, column);
		FldSetInsPtPosition (fld, pos);
		FldGrabFocus (fld);
	}
#endif /* not ADDR_FOCUS_FIX */
}


/***********************************************************************
 *
 * FUNCTION:    PrvEditScroll
 *
 * DESCRIPTION: This routine scrolls the list of editable fields
 *              in the direction specified.
 *
 * PARAMETERS:  direction - up or dowm
 *              oneLine   - if true the list is scroll by a single line,
 *                          if false the list is scroll by a full screen.
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         art   06/26/95	Initial Revision
 *         vmk   02/20/98	Move TblUnhighlightSelection before PrvEditLoadTable
 *         gap   10/12/99	Close command bar before processing scroll
 *
 ***********************************************************************/
void PrvEditScroll (WinDirectionType direction)
{
	UInt16				row;
	UInt16				height;
	UInt16				fieldIndex;
	UInt16				columnWidth;
	UInt16				tableHeight;
	TablePtr				table;
	FontID				curFont;
	RectangleType		r;
	AddrDBRecordType	record;
	MemHandle			recordH;
	FormType*			frmP;
#ifdef ADDR_FOCUS_FIX
	UInt16 				firstRow;
#else /* not ADDR_FOCUS_FIX */
#endif /* not ADDR_FOCUS_FIX */


	// Before processing the scroll, be sure that the command bar has been closed.
	MenuEraseStatus (0);
	frmP = FrmGetActiveForm();

	curFont = FntSetFont (stdFont);

	table = ToolsGetFrmObjectPtr(frmP, EditTable);
	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, editDataColumn);

	// 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.
#ifdef ADDR_FOCUS_FIX
      if (row == PrvEditTblGetFirstUsableRow (table))
         fieldIndex = min (editLastFieldIndex, fieldIndex+1);
#else /* not ADDR_FOCUS_FIX */
		if (row == 0)
			fieldIndex = min (editLastFieldIndex, fieldIndex+1);
#endif /* not ADDR_FOCUS_FIX */
	}

	// 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.

#ifdef ADDR_FOCUS_FIX
      firstRow = PrvEditTblGetFirstUsableRow (table);
      fieldIndex = TblGetRowID (table, firstRow);
#else /* not ADDR_FOCUS_FIX */
		fieldIndex = TblGetRowID (table, 0);
#endif /* not ADDR_FOCUS_FIX */
		ErrFatalDisplayIf(fieldIndex > editLastFieldIndex, "Invalid field Index");
		if (fieldIndex == 0)
			goto exit;

		// Get the current record
		AddrDBGetRecord (AddrDB, CurrentRecord, &record, &recordH);

#ifdef ADDR_FOCUS_FIX
      height = TblGetRowHeight (table, firstRow);
#else /* not ADDR_FOCUS_FIX */
		height = TblGetRowHeight (table, 0);
#endif /* not ADDR_FOCUS_FIX */
		if (height >= tableHeight)
			height = 0;

		while (height < tableHeight && fieldIndex > 0)
		{
#ifdef ADDR_FOCUS_FIX
			/* support non stdFont */
			Char* text = record.fields[FieldMap[fieldIndex-1]];
			
			if (text == NULL || text[0] == '\0')
			{
				FntSetFont (addrEditBlankFont);
				height += FntLineHeight ();
			}
			else
			{
				FntSetFont (AddrEditFont);
				height += FntLineHeight () * FldCalcFieldHeight (text, columnWidth);
			}
         	if ((height <= tableHeight) || (fieldIndex == TblGetRowID (table, PrvEditTblGetFirstUsableRow (table))))
           		fieldIndex--;
#else /* not ADDR_FOCUS_FIX */
			height += FldCalcFieldHeight (record.fields[FieldMap[fieldIndex-1]],
										  columnWidth) * FntLineHeight ();
			if ((height <= tableHeight) || (fieldIndex == TblGetRowID (table, 0)))
				fieldIndex--;
#endif /* not ADDR_FOCUS_FIX */
		}
		MemHandleUnlock(recordH);
	}

	TblMarkTableInvalid (table);
	CurrentFieldIndex = noFieldIndex;
	TopVisibleFieldIndex = fieldIndex;
	EditRowIDWhichHadFocus = editFirstFieldIndex;
	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
#ifdef ADDR_FOCUS_FIX
	PrvEditLoadTable (frmP, true);   
#else /* not ifdef ADDR_FOCUS_FIX */
	PrvEditLoadTable(frmP);
#endif /* not ifdef ADDR_FOCUS_FIX */

	//TblUnhighlightSelection (table);	// moved call before PrvEditLoadTable vmk 2/20/98
	TblRedrawTable (table);

	exit:
		FntSetFont (curFont);
}


/***********************************************************************
 *
 * FUNCTION:    PrvEditNextField
 *
 * DESCRIPTION: If a field is being edited, advance the focus to the
 * edit view table's next field.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         roger   7/27/95   Initial Revision
 *
 ***********************************************************************/
void PrvEditNextField (WinDirectionType direction)
{
	TablePtr tableP;
	Int16 row;
	Int16 column;
	UInt16 nextFieldNumIndex;
	FormType* frmP;

	frmP = FrmGetActiveForm();
	tableP = ToolsGetFrmObjectPtr(frmP, EditTable);

	if (!TblEditing(tableP))
		return;

	// Find out which field is being edited.
	TblGetSelection (tableP, &row, &column);
	nextFieldNumIndex = TblGetRowID (tableP, row);
	if (direction == winDown)
	{
		if (nextFieldNumIndex >= editLastFieldIndex)
			nextFieldNumIndex = 0;
		else
			nextFieldNumIndex++;
	}
	else
	{
		if (nextFieldNumIndex == 0)
			nextFieldNumIndex = editLastFieldIndex;
		else
			nextFieldNumIndex--;
	}
	TblReleaseFocus (tableP);

	CurrentFieldIndex = nextFieldNumIndex;

	// If the new field isn't visible move the edit view and then
	// find the row where the next field is.
	while (!TblFindRowID(tableP, nextFieldNumIndex, &row))
	{
		// Scroll the view down placing the item
		// on the top row
		TopVisibleFieldIndex = nextFieldNumIndex;
#ifdef ADDR_FOCUS_FIX
		PrvEditLoadTable(frmP, true);
#else /* not ifdef ADDR_FOCUS_FIX */
		PrvEditLoadTable(frmP);
#endif /* not ifdef ADDR_FOCUS_FIX */
		TblRedrawTable(tableP);
	}

	PrvEditHandleSelectField(row, editDataColumn);
}




/***********************************************************************
 *
 * FUNCTION:    PrvEditUpdateCustomFieldLabels
 *
 * DESCRIPTION: Update the custom field labels by reloading those rows
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event was handled and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *			Name	Date      Description
 *			----	----      -----------
 *			art		6/5/95      Initial Revision
 *			aro		9/26/00		Adding frmP as an argument for the updateEvent
 *
 ***********************************************************************/
void PrvEditUpdateCustomFieldLabels( FormType* frmP)
{
	UInt16 row;
	UInt16 rowsInTable;
	TablePtr table;
	AddrAppInfoPtr appInfoPtr;
	UInt16 fieldIndex;
	UInt16 fieldNum;
	AddrDBRecordType record;
	MemHandle recordH;
	Boolean redraw = false;


	appInfoPtr = (AddrAppInfoPtr)AddrDBAppInfoGetPtr(AddrDB);
	table = ToolsGetFrmObjectPtr(frmP, EditTable);

	if (TblGetColumnWidth(table, editLabelColumn) != EditLabelColumnWidth)
	{
		PrvEditInit (frmP, false);
		redraw = true;
	}
	else
	{


		// Get the current record
		AddrDBGetRecord (AddrDB, CurrentRecord, &record, &recordH);


		rowsInTable = TblGetNumberOfRows(table);

		// Reload any renameable fields
		for (row = 0; row < rowsInTable; row++)
		{
			if (TblRowUsable (table, row))
			{
				fieldIndex = TblGetRowID (table, row);
				fieldNum = FieldMap[fieldIndex];
				if (fieldNum >= firstRenameableLabel &&
					fieldNum <= lastRenameableLabel)
				{
					PrvEditInitTableRow(frmP, table, row, fieldIndex,
										TblGetRowHeight (table, row),
										TblGetItemFont (table, row, editDataColumn),
										&record, appInfoPtr);
					redraw = true;

					// Mark the row invalid so that it will draw when we call the
					// draw routine.
					TblMarkRowInvalid (table, row);
				}
			}
		}


		MemHandleUnlock(recordH);
	}


	if (redraw)
		TblRedrawTable(table);


	MemPtrUnlock(appInfoPtr);
}


/***********************************************************************
 *
 * FUNCTION:    PrvEditUpdateDisplay
 *
 * DESCRIPTION: This routine update the display of the edit view
 *
 * PARAMETERS:  updateCode - a code that indicated what changes  been
 *                           have made to the view.
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	9/12/97	Initial Revision
 *			jmp	11/02/99	Fixed problem on frmRedrawUpdateCode events when
 *								we're still in the edit state

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -