more tweaks (savepoint)

This commit is contained in:
Lance Edgar 2013-01-13 09:54:23 -08:00
parent 8f10956bae
commit f2a63e2235

View file

@ -109,7 +109,7 @@ Boolean gBabbo = false;
//UInt16 gNumCols = 3; //UInt16 gNumCols = 3;
//UInt16 gNumRows = 11; //UInt16 gNumRows = 11;
//MemHandle gHandles[11][3]; //MemHandle gHandles[11][3];
Int16 gTopVisibleRecord = -1; Int16 firstRecordIndex = -1;
Boolean scanRecordsSelected[12]; Boolean scanRecordsSelected[12];
Int16 eventEnteredRow = -1; Int16 eventEnteredRow = -1;
@ -506,19 +506,21 @@ static Boolean MainFormHandleEvent(EventPtr event)
break; break;
case penMoveEvent: case penMoveEvent:
table = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormScanRecords)); if (eventEnteredRow >= 0) {
if (TableHitTest(table, event->screenX, event->screenY)) { table = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormScanRecords));
if (TableHitTest(table, event->screenX, event->screenY)) {
row = TableRowHitTest(table, event->screenX, event->screenY); row = TableRowHitTest(table, event->screenX, event->screenY);
if (row >= 0) { if (row >= 0) {
if (! scanRecordsSelected[row]) { if (! scanRecordsSelected[row]) {
scanRecordsSelected[row] = true; scanRecordsSelected[row] = true;
TblMarkRowInvalid(table, row); TblMarkRowInvalid(table, row);
TblRedrawTable(table); TblRedrawTable(table);
}
} }
}
handled = true; handled = true;
}
} }
break; break;
@ -538,7 +540,8 @@ static Boolean MainFormHandleEvent(EventPtr event)
handled = true; handled = true;
} }
} eventEnteredRow = -1;
}
break; break;
case sclEnterEvent: case sclEnterEvent:
@ -547,9 +550,9 @@ static Boolean MainFormHandleEvent(EventPtr event)
case sclRepeatEvent: case sclRepeatEvent:
if (event->data.sclRepeat.newValue > event->data.sclRepeat.value) if (event->data.sclRepeat.newValue > event->data.sclRepeat.value)
gTopVisibleRecord += (event->data.sclRepeat.newValue - event->data.sclRepeat.value); firstRecordIndex += (event->data.sclRepeat.newValue - event->data.sclRepeat.value);
else { else {
gTopVisibleRecord -= (event->data.sclRepeat.value - event->data.sclRepeat.newValue); firstRecordIndex -= (event->data.sclRepeat.value - event->data.sclRepeat.newValue);
} }
table = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormScanRecords)); table = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormScanRecords));
@ -721,20 +724,18 @@ static Boolean MainFormDoCommand(UInt16 command)
FormPtr form; FormPtr form;
TablePtr table; TablePtr table;
DmOpenRef db; DmOpenRef db;
UInt16 row, offset, records; UInt16 row, offset, records, selected;
Int16 rowIndex; Int16 rowIndex;
Boolean selected;
handled = false; handled = false;
switch (command) { switch (command) {
case MainEditDeleteSelected: case MainEditDeleteSelected:
selected = false; selected = 0;
for (row = 0; row < 12; row++) { for (row = 0; row < 12; row++) {
if (scanRecordsSelected[row]) { if (scanRecordsSelected[row]) {
selected = true; selected++;
break;
} }
} }
if (selected) { if (selected) {
@ -750,6 +751,9 @@ static Boolean MainFormDoCommand(UInt16 command)
} }
} }
DmCloseDatabase(db); DmCloseDatabase(db);
if (firstRecordIndex > 0) {
firstRecordIndex -= selected;
}
MainFormLoadTable(table, true); MainFormLoadTable(table, true);
ClearScanRecordSelection(); ClearScanRecordSelection();
TblRedrawTable(table); TblRedrawTable(table);
@ -960,15 +964,19 @@ static void MainFormLoadTable(TablePtr table, Boolean updateScroll)
ScrollBarPtr scroll; ScrollBarPtr scroll;
db = OpenScanDatabase(); db = OpenScanDatabase();
records = DmNumRecords(db);
if (gTopVisibleRecord < 0) { records = DmNumRecords(db);
gTopVisibleRecord = (records > 12) ? (records - 12) : 0; if (records) {
if (firstRecordIndex < 0) {
firstRecordIndex = (records > 12) ? (records - 12) : 0;
}
} else {
firstRecordIndex = -1;
} }
rows = (records < 12) ? records : 12; rows = (records < 12) ? records : 12;
for (row = 0; row < rows; row++) { for (row = 0; row < rows; row++) {
recordIndex = gTopVisibleRecord + row; recordIndex = firstRecordIndex + row;
recordH = DmGetRecord(db, recordIndex); recordH = DmGetRecord(db, recordIndex);
recordP = MemHandleLock(recordH); recordP = MemHandleLock(recordH);
@ -999,7 +1007,7 @@ static void MainFormLoadTable(TablePtr table, Boolean updateScroll)
if (records <= 12) { if (records <= 12) {
SclSetScrollBar(scroll, 0, 0, 0, 0); SclSetScrollBar(scroll, 0, 0, 0, 0);
} else { } else {
SclSetScrollBar(scroll, gTopVisibleRecord, 0, records - 12, 11); SclSetScrollBar(scroll, firstRecordIndex, 0, records - 12, 11);
} }
} }
} }
@ -1021,11 +1029,11 @@ static void MainFormLoadTable(TablePtr table, Boolean updateScroll)
/* numRecords = DmNumRecords(db); */ /* numRecords = DmNumRecords(db); */
/* rows = (numRecords < 12) ? numRecords : 12; */ /* rows = (numRecords < 12) ? numRecords : 12; */
/* if (gTopVisibleRecord < 0) */ /* if (firstRecordIndex < 0) */
/* gTopVisibleRecord = (numRecords > 12) ? (numRecords - 12) : 0; */ /* firstRecordIndex = (numRecords > 12) ? (numRecords - 12) : 0; */
/* for (row = 0; row < rows; row++) { */ /* for (row = 0; row < rows; row++) { */
/* rowId = gTopVisibleRecord + row; */ /* rowId = firstRecordIndex + row; */
/* recordH = DmGetRecord(db, rowId); */ /* recordH = DmGetRecord(db, rowId); */
/* recordP = (MemPtr) MemHandleLock(recordH); */ /* recordP = (MemPtr) MemHandleLock(recordH); */
/* TblSetItemPtr(table, row, 0, &recordP->barcode); */ /* TblSetItemPtr(table, row, 0, &recordP->barcode); */
@ -1054,7 +1062,7 @@ static void MainFormLoadTable(TablePtr table, Boolean updateScroll)
/* if (numRecords <= 12) { */ /* if (numRecords <= 12) { */
/* SclSetScrollBar(scroll, 0, 0, 0, 0); */ /* SclSetScrollBar(scroll, 0, 0, 0, 0); */
/* } else { */ /* } else { */
/* SclSetScrollBar(scroll, gTopVisibleRecord, 0, numRecords - 12, 11); */ /* SclSetScrollBar(scroll, firstRecordIndex, 0, numRecords - 12, 11); */
/* } */ /* } */
/* } */ /* } */
/* } */ /* } */
@ -1346,7 +1354,6 @@ static void StoreScanData()
MemHandle recordH; MemHandle recordH;
MemPtr recordP; MemPtr recordP;
TablePtr table; TablePtr table;
UInt16 row;
form = FrmGetFormPtr(MainForm); form = FrmGetFormPtr(MainForm);
@ -1369,12 +1376,7 @@ static void StoreScanData()
DmCloseDatabase(db); DmCloseDatabase(db);
table = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormScanRecords)); table = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormScanRecords));
row = TblGetLastUsableRow(table); firstRecordIndex = (recordIndex > 11) ? (recordIndex - 11) : 0;
if (row == tblUnusableRow) {
gTopVisibleRecord = 0;
} else if (row == 11) {
gTopVisibleRecord = TblGetRowID(table, 1);
}
MainFormLoadTable(table, true); MainFormLoadTable(table, true);
TblRedrawTable(table); TblRedrawTable(table);
@ -1480,9 +1482,9 @@ static void StoreScanData()
/* table = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormScanRecords)); */ /* table = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormScanRecords)); */
/* row = TblGetLastUsableRow(table); */ /* row = TblGetLastUsableRow(table); */
/* if (row == tblUnusableRow) { */ /* if (row == tblUnusableRow) { */
/* gTopVisibleRecord = 0; */ /* firstRecordIndex = 0; */
/* } else if (row == 11) { */ /* } else if (row == 11) { */
/* gTopVisibleRecord = TblGetRowID(table, 1); */ /* firstRecordIndex = TblGetRowID(table, 1); */
/* } */ /* } */
/* MainFormLoadTable(table, true); */ /* MainFormLoadTable(table, true); */
/* TblRedrawTable(table); */ /* TblRedrawTable(table); */