From: Nathan K. <na...@va...> - 2000-11-03 09:09:03
|
Here's my first try at navigation between fields in the edit view. It basically works, although it is not well tested. I'll test tomorrow. I ended up changing more than I planned to. This is not necessarily a good thing. I could probably minimize the changes if desired. The patch is against the test version of 0.3.1. Stylistic corrections appreciated -- I'm still familiarizing myself with Palm programming. ---------------------------------------------------------------------- *** edit.c Fri Oct 20 01:51:08 2000 --- edit.nate.c Fri Nov 3 02:13:28 2000 *************** *** 26,31 **** --- 26,34 ---- #define GetObjectPtr(f,i) FrmGetObjectPtr((f),FrmGetObjectIndex((f),(i))) #define noFieldIndex 32 + #define labelColumn 0 + #define fieldColumn 1 + typedef struct { MemHandle h; Boolean b; *************** *** 54,69 **** static void EditViewLoadTable(TablePtr table) EDITSECT; static void EditViewInitTable(TablePtr table) EDITSECT; static void EditViewResizeDescription(EventPtr event) EDITSECT; ! #if 0 ! static void EditViewHandleSelectField(UInt16 row, const UInt8 column) EDITSECT ; ! #endif static void EditViewScroll(WinDirectionType direction) EDITSECT; static Boolean ValidateData(void) EDITSECT; static void SaveRecord(void) EDITSECT; static void SetupRecordData(void) EDITSECT; - static Err EditViewLoadRecord(void * table, Int16 row, Int16 column, Boolean editing, MemHandle * textH, Int16 * textOffset, --- 57,70 ---- static void EditViewLoadTable(TablePtr table) EDITSECT; static void EditViewInitTable(TablePtr table) EDITSECT; static void EditViewResizeDescription(EventPtr event) EDITSECT; ! static void EditViewNextField(WinDirectionType direction) EDITSECT; ! static void EditViewSelectField(TablePtr table, UInt16 fieldIndex) EDITSECT; static void EditViewScroll(WinDirectionType direction) EDITSECT; static Boolean ValidateData(void) EDITSECT; static void SaveRecord(void) EDITSECT; static void SetupRecordData(void) EDITSECT; static Err EditViewLoadRecord(void * table, Int16 row, Int16 column, Boolean editing, MemHandle * textH, Int16 * textOffset, *************** *** 389,396 **** } /* Enable the label and data columns. */ ! TblSetColumnUsable(table, 0, true); ! TblSetColumnUsable(table, 1, true); /* Figure out the width of the label column. */ labelWidth = FntCharsWidth(CurrentSource->schema.fields[0].name, --- 390,397 ---- } /* Enable the label and data columns. */ ! TblSetColumnUsable(table, labelColumn, true); ! TblSetColumnUsable(table, fieldColumn, true); /* Figure out the width of the label column. */ labelWidth = FntCharsWidth(CurrentSource->schema.fields[0].name, *************** *** 412,417 **** --- 413,421 ---- TblSetSaveDataProcedure(table, 1, EditViewSaveRecord); EditViewLoadTable(table); + + /* set focus to the first field */ + EditViewSelectField(table, 0); } static void *************** *** 492,529 **** } } - #if 0 static void ! EditViewHandleSelectField(UInt16 row, const UInt8 column) { ! TablePtr table; ! FieldPtr fld; ! UInt16 fieldNum; ! Char buf[16]; ! StrIToA(buf, column); ! FrmCustomAlert(alertID_Debug, "row = ", buf, " "); ! table = GetObjectPtr(FrmGetActiveForm(), ctlID_EditView_Table); ! fieldNum = TblGetRowID(table, row); ! if (fieldNum != CurrentField) { ! if (TblGetCurrentField(table)) { ! TblReleaseFocus(table); ! FrmCustomAlert(alertID_Debug, "focus released", " ", " "); ! } ! TblUnhighlightSelection(table); ! TblGrabFocus(table, row, 1); ! fld = TblGetCurrentField(table); ! if (fld) { ! FldGrabFocus(fld); ! FldMakeFullyVisible(fld); ! } ! FrmCustomAlert(alertID_Debug, "focus grabbed", " ", " "); ! CurrentField = fieldNum; } } - #endif static void EditViewScroll(WinDirectionType direction) --- 496,600 ---- } } static void ! EditViewSelectField(TablePtr table, UInt16 fieldIndex) { ! UInt16 fieldRow; ! FieldPtr fld; ! UInt16 tableIndex; ! FormPtr form; ! ! /* NOTE: must unhighlite selection first */ ! TblUnhighlightSelection(table); ! ! /* remove the old focus before setting the new */ ! /* FUTURE: is there a more efficient yet safe way of doing this? */ ! form = FrmGetActiveForm(); ! FrmSetFocus(form, noFocus); ! tableIndex = FrmGetObjectIndex(form, ctlID_EditView_Table); ! FrmSetFocus(form, tableIndex); ! ! /* scroll in case nextRow is not already visible on the screen */ ! if (! TblFindRowID(table, fieldIndex, &fieldRow)) { ! /* NOTE: only the rows shown on the screen are present in the table */ ! CurrentField = fieldIndex; ! EditViewLoadTable(table); ! TblRedrawTable(table); ! /* find the next row within the scrolled version of the table */ ! ErrFatalDisplayIf(! TblFindRowID(table, fieldIndex, &fieldRow), ! "could not find specified row"); ! } ! ! /* set the focus according to the field type */ ! switch (CurrentSource->schema.fields[fieldIndex].type) ! { ! case FIELD_TYPE_STRING: ! case FIELD_TYPE_INTEGER: ! TblSelectItem(table, fieldRow, fieldColumn); ! TblGrabFocus(table, fieldRow, fieldColumn); ! fld = TblGetCurrentField(table); ! FldGrabFocus(fld); ! FldMakeFullyVisible(fld); ! break; ! case FIELD_TYPE_BOOLEAN: ! /* no focus allowed for boolean so select the label instead */ ! TblSelectItem(table, fieldRow, labelColumn); ! break; ! default: ! ErrDisplay("field type not supported"); ! break; ! } ! return; ! } ! ! ! static void ! EditViewNextField(WinDirectionType direction) ! { ! FormPtr form; ! TablePtr table; ! Int16 currentRow; ! Int16 currentColumn; ! UInt16 currentFieldIndex; ! UInt16 lastFieldIndex; ! UInt16 nextFieldIndex; ! ! form = FrmGetActiveForm(); ! table = GetObjectPtr(form, ctlID_EditView_Table); ! if (! table) return; ! /* NOTE: TblEditing() would return false if a label was selected */ ! ! /* FUTURE: check that something indeed is selected */ ! /* NOTE: TblGetSelection() is false after initial automatic selection? */ ! TblGetSelection(table, ¤tRow, ¤tColumn); ! ! currentFieldIndex = TblGetRowID(table, currentRow); ! lastFieldIndex = CurrentSource->schema.numFields - 1; ! ! if (direction == winDown) ! { ! if (currentFieldIndex < lastFieldIndex) ! nextFieldIndex = currentFieldIndex + 1; ! else ! /* last field cycles forward to first field */ ! nextFieldIndex = 0; ! } ! else /* winUp */ ! { ! if (currentFieldIndex > 0) ! nextFieldIndex = currentFieldIndex - 1; ! else ! /* first field cycles back to last field */ ! nextFieldIndex = lastFieldIndex; } + + EditViewSelectField(table, nextFieldIndex); + + return; } static void EditViewScroll(WinDirectionType direction) *************** *** 819,825 **** FormPtr form; TablePtr table; UInt16 fieldNum; - FieldPtr fld; switch (event->eType) { case frmOpenEvent: --- 890,895 ---- *************** *** 873,915 **** case tblSelectEvent: table = event->data.tblSelect.pTable; fieldNum = TblGetRowID(table, event->data.tblSelect.row); ! if (event->data.tblSelect.column == 0) { ! switch (CurrentSource->schema.fields[fieldNum].type) { ! case FIELD_TYPE_STRING: ! case FIELD_TYPE_INTEGER: ! /* A tap on the label edits the field. */ ! if (TblGetCurrentField(event->data.tblSelect.pTable)) { ! TblReleaseFocus(event->data.tblSelect.pTable); ! } ! TblUnhighlightSelection(event->data.tblSelect.pTable); ! TblGrabFocus(event->data.tblSelect.pTable, ! event->data.tblSelect.row, 1); ! fld = TblGetCurrentField(event->data.tblSelect.pTable); ! if (fld) { ! FldGrabFocus(fld); ! FldMakeFullyVisible(fld); ! } ! return true; ! default: ! break; ! } ! } else if (event->data.tblSelect.column == 1) { ! switch (CurrentSource->schema.fields[fieldNum].type) { case FIELD_TYPE_BOOLEAN: ! if (TblGetItemInt(table, ! event->data.tblSelect.row, ! event->data.tblSelect.column)) ! fields[fieldNum].b = true; ! else ! fields[fieldNum].b = false; ! IsDirty = true; ! break; - default: - break; - } - } return false; case ctlSelectEvent: --- 943,966 ---- case tblSelectEvent: table = event->data.tblSelect.pTable; fieldNum = TblGetRowID(table, event->data.tblSelect.row); ! EditViewSelectField(table, fieldNum); ! if (event->data.tblSelect.column == 1) { ! switch (CurrentSource->schema.fields[fieldNum].type) { case FIELD_TYPE_BOOLEAN: ! if (TblGetItemInt(table, event->data.tblSelect.row, ! event->data.tblSelect.column)) ! fields[fieldNum].b = true; ! else ! fields[fieldNum].b = false; ! IsDirty = true; ! break; ! ! default: ! break; ! } ! } return false; case ctlSelectEvent: *************** *** 977,992 **** } } break; ! default: return HandleCommonMenuEvent(event->data.menu.itemID); } break; - default: - break; ! } return false; } --- 1028,1071 ---- } } break; ! default: return HandleCommonMenuEvent(event->data.menu.itemID); } break; ! case keyDownEvent: ! if (EvtKeydownIsVirtual(event)) ! { ! switch (event->data.keyDown.chr) ! { ! case vchrPageUp: ! EditViewScroll (winUp); ! return true; ! ! case vchrPageDown: ! EditViewScroll (winDown); ! return true; ! ! case vchrNextField: ! EditViewNextField (winDown); ! return true;; ! ! case vchrPrevField: ! EditViewNextField (winUp); ! break; ! } ! } ! else /* key is not virtual */ ! { ! /* FUTURE: allow checkboxes to be toggled using keyboard */ ! } + default: + break; + + } + return false; } ---------------------------------------------------------------------------- Goodnight! --nate |