diff --git a/rsc/AppResources.xrd b/rsc/AppResources.xrd index 762a6f8..848e467 100644 --- a/rsc/AppResources.xrd +++ b/rsc/AppResources.xrd @@ -111,7 +111,7 @@ 1000 1 - 148 + 17 75 12 @@ -128,32 +128,11 @@ STD_FONT 0 - - 1001 - - 140 - 148 - 18 - 12 - - TRUE - TRUE - TRUE - FALSE - SOLID_UNDERLINE - RIGHT_ALIGN - FALSE - FALSE - TRUE - 3 - STD_FONT - 0 - 1002 123 - 148 + 17 19 12 @@ -164,32 +143,11 @@ 0 FALSE - - 1003 - - 99 - 148 - 18 - 12 - - TRUE - TRUE - TRUE - FALSE - SOLID_UNDERLINE - RIGHT_ALIGN - FALSE - FALSE - TRUE - 3 - STD_FONT - 0 - 1004 82 - 148 + 17 19 12 @@ -204,7 +162,7 @@ 1005 0 - 16 + 34 153 120 @@ -233,7 +191,7 @@ 1006 153 - 16 + 34 7 120 @@ -243,6 +201,34 @@ 0 11 + + 1003 + + 99 + 17 + 19 + 12 + + TRUE + TRUE + FALSE + "999" + STD_FONT + + + 1001 + + 139 + 17 + 19 + 12 + + TRUE + TRUE + FALSE + "999" + STD_FONT + @@ -289,12 +275,12 @@ 1104 - 50 + 46 53 TRUE BOLD_FONT - "Version 1.0" + "Version 1.0.0" 1105 @@ -324,6 +310,255 @@ + + 1200 + + 2 + 33 + 156 + 125 + + TRUE + TRUE + TRUE + 1000 + 0 + 1011 + FALSE + FALSE + + + "Edit Quantity" + + + 1000 + + 4 + 16 + 45 + 18 + + TRUE + TRUE + "1" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1001 + + 55 + 16 + 45 + 18 + + TRUE + TRUE + "2" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1002 + + 106 + 16 + 45 + 18 + + TRUE + TRUE + "3" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1003 + + 4 + 39 + 45 + 18 + + TRUE + TRUE + "4" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1004 + + 55 + 39 + 45 + 18 + + TRUE + TRUE + "5" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1005 + + 106 + 39 + 45 + 18 + + TRUE + TRUE + "6" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1006 + + 4 + 62 + 45 + 18 + + TRUE + TRUE + "7" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1007 + + 55 + 62 + 45 + 18 + + TRUE + TRUE + "8" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1008 + + 106 + 62 + 45 + 18 + + TRUE + TRUE + "9" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1009 + + 4 + 85 + 45 + 18 + + TRUE + TRUE + "0" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1010 + + 55 + 85 + 96 + 18 + + TRUE + TRUE + "OK" + FALSE + LARGE_BOLD_FONT + STANDARD_BUTTON_FRAME + + + 1011 + + 115 + 108 + 36 + 12 + + TRUE + TRUE + "Cancel" + FALSE + STD_FONT + STANDARD_BUTTON_FRAME + + + 1012 + + 73 + 108 + 36 + 12 + + TRUE + TRUE + "Clear" + FALSE + STD_FONT + STANDARD_BUTTON_FRAME + + + 1014 + + 4 + 109 + + TRUE + STD_FONT + "Qty:" + + + 1013 + + 27 + 107 + 30 + 15 + + TRUE + FALSE + FALSE + FALSE + NO_UNDERLINE + RIGHT_ALIGN + FALSE + FALSE + FALSE + 80 + LARGE_BOLD_FONT + 0 + + + + TRUE @@ -354,4 +589,10 @@ + + + "Edit the quantity by pressing the number buttons, then press OK to accept.\n\n(Note that the quantity may not exceed 3 digits.)\n\nPressing Clear will erase the current quantity and allow you to re-enter it.\n\nIf you press Cancel, focus will be returned to the scan field." + + + diff --git a/src/AppMain.c b/src/AppMain.c index 1c32aa2..0ebfeee 100644 --- a/src/AppMain.c +++ b/src/AppMain.c @@ -22,941 +22,1151 @@ /*********************************************************************** * - * Entry Points + * Entry Points * ***********************************************************************/ /*********************************************************************** * - * Internal Constants + * Internal Constants * ***********************************************************************/ -#define appFileCreator 'RTTL' // register your own at http://www.palmos.com/dev/creatorid/ -#define appVersionNum 0x01 -#define appPrefID 0x00 -#define appPrefVersionNum 0x01 -#define appDbRattail "Rattail" -#define appDbRattailScan "Rattail_Scan" +#define appFileCreator 'RTTL' +#define appVersionNum 0x01 +#define appPrefID 0x00 +#define appPrefVersionNum 0x01 +#define appDbRattail "Rattail" +#define appDbRattailScan "Rattail_Scan" -#define COLUMN_BARCODE 0 -#define COLUMN_CASES 1 -#define COLUMN_UNITS 2 +#define COLUMN_BARCODE 0 +#define COLUMN_CASES 1 +#define COLUMN_UNITS 2 /*********************************************************************** * - * Global Variables + * Global Variables * ***********************************************************************/ -UInt16 cardNo = 0; -UInt16 gBcs2RefNum = 0; -Boolean gBabbo = false; -//UInt16 gNumCols = 3; -//UInt16 gNumRows = 11; -//MemHandle gHandles[11][3]; -Int16 gTopVisibleRecord = -1; +UInt16 cardNo = 0; +UInt16 gBcs2RefNum = 0; +Boolean gBabbo = false; +//UInt16 gNumCols = 3; +//UInt16 gNumRows = 11; +//MemHandle gHandles[11][3]; +Int16 gTopVisibleRecord = -1; + +// This stores the resource ID of the selector trigger associated with the +// quantity currently being edited with the Quantity Form. Its value will be +// either MainFormCases or MainFormUnits. +UInt16 gQuantityTriggerID; + +// This tracks whether the quantity form was initiated by the user manually +// selecting a trigger, i.e. versus being auto-initiated by the scanning +// workflow. +Boolean gQuantityManual; + +// These buffers hold the current quantities as text. +Char gCaseQuantity[4]; +Char gUnitQuantity[4]; + +// This pointer refers to the quantity currently being edited. +Char* gQuantity; + +// This tracks whether the quantity shown is the initial/original value, or +// whether it has already been touched in some way. This is used to control +// the behavior of the first number button pressed. +Boolean gQuantityTouched; -/*********************************************************************** +/************************************************************ * * FUNCTION: AppHandleEvent * - * DESCRIPTION: This routine loads form resources and set the event - * handler for the form loaded. - * - * PARAMETERS: event - a pointer to an EventType structure - * - * RETURNED: true if the event has handle and should not be passed - * to a higher level handler. - * - * REVISION HISTORY: - * - * - ***********************************************************************/ -static Boolean AppHandleEvent(EventType* pEvent) + ************************************************************/ + +static Boolean AppHandleEvent(EventPtr event) { - UInt16 formId; - FormType* pForm; - Boolean handled = false; + UInt16 formID; + FormPtr form; + Boolean handled = false; - if (pEvent->eType == frmLoadEvent) { - // Load the form resource. - formId = pEvent->data.frmLoad.formID; - - pForm = FrmInitForm(formId); - FrmSetActiveForm(pForm); + if (event->eType == frmLoadEvent) { - // Set the event handler for the form. The handler of the currently - // active form is called by FrmHandleEvent each time is receives an - // event. - switch (formId) { - case MainForm: - FrmSetEventHandler(pForm, MainFormHandleEvent); - break; - - default: - break; - } - handled = true; - } - - return handled; + // Load the form resource. + formID = event->data.frmLoad.formID; + form = FrmInitForm(formID); + FrmSetActiveForm(form); + + // Set the event handler for the form. + switch (formID) { + case MainForm: + FrmSetEventHandler(form, MainFormHandleEvent); + break; + case QuantityForm: + FrmSetEventHandler(form, QuantityFormHandleEvent); + break; + default: + break; + } + + handled = true; + } + + return handled; } -/*********************************************************************** +/************************************************************ * - * FUNCTION: AppStart + * FUNCTION: AppStart * - * DESCRIPTION: Get the current application's preferences. - * - * PARAMETERS: nothing - * - * RETURNED: Err value errNone if nothing went wrong - * - * REVISION HISTORY: - * - * - ***********************************************************************/ + ************************************************************/ + static Err AppStart(void) { - OpenBCS2Scanner(); - //OpenBabboScanner(); - - FrmGotoForm(MainForm); - return errNone; + OpenBCS2Scanner(); + //OpenBabboScanner(); + + FrmGotoForm(MainForm); + return errNone; } -/*********************************************************************** +/************************************************************ * * FUNCTION: AppStop * - * DESCRIPTION: Save the current state of the application. - * - * PARAMETERS: nothing - * - * RETURNED: nothing - * - ***********************************************************************/ + ************************************************************/ + static void AppStop(void) { - CloseBCS2Scanner(); - //CloseBabboScanner(); + CloseBCS2Scanner(); + //CloseBabboScanner(); - FrmCloseAllForms(); + FrmCloseAllForms(); } -/*********************************************************************** +/************************************************************ * * FUNCTION: AppEventLoop * - * DESCRIPTION: This routine is the event loop for the application. - * - * PARAMETERS: nothing - * - * RETURNED: nothing - * - * REVISION HISTORY: - * - * - ***********************************************************************/ + ************************************************************/ + static void AppEventLoop(void) { - Err error; - EventType event; + Err error; + EventType event; - do { - EvtGetEvent(&event, evtWaitForever); + do { + EvtGetEvent(&event, evtWaitForever); - if (SysHandleEvent(&event)) - continue; - - if (MenuHandleEvent(0, &event, &error)) - continue; - - if (AppHandleEvent(&event)) - continue; - - FrmDispatchEvent(&event); + if (SysHandleEvent(&event)) + continue; + + if (MenuHandleEvent(0, &event, &error)) + continue; + + if (AppHandleEvent(&event)) + continue; + + FrmDispatchEvent(&event); - } while (event.eType != appStopEvent); + } while (event.eType != appStopEvent); } -/*********************************************************************** +/************************************************************ * * FUNCTION: CloseBabboScanner * - ***********************************************************************/ + ************************************************************/ + /* static void CloseBabboScanner() { - if (! gBabbo) - return; - - ScnCmdScanDisable(); - ScnCloseDecoder(); - gBabbo = false; + if (! gBabbo) + return; + + ScnCmdScanDisable(); + ScnCloseDecoder(); + gBabbo = false; } */ -/*********************************************************************** +/************************************************************ * * FUNCTION: CloseBCS2Scanner * - ***********************************************************************/ + ************************************************************/ static void CloseBCS2Scanner() { - LocalID dbId; - - if (! gBcs2RefNum) - return; + LocalID dbId; + + if (! gBcs2RefNum) + return; - dbId = DmFindDatabase(cardNo, appDbRattail); - if (dbId) - SysNotifyUnregister(cardNo, dbId, BCS2BarCodeReadyNotification, - sysNotifyNormalPriority); - BCS2LibClose(gBcs2RefNum); - SysLibRemove(gBcs2RefNum); - gBcs2RefNum = 0; + dbId = DmFindDatabase(cardNo, appDbRattail); + if (dbId) + SysNotifyUnregister(cardNo, dbId, BCS2BarCodeReadyNotification, + sysNotifyNormalPriority); + BCS2LibClose(gBcs2RefNum); + SysLibRemove(gBcs2RefNum); + gBcs2RefNum = 0; } -/*********************************************************************** +/************************************************************ * * FUNCTION: CreateScanDatabase * - ***********************************************************************/ + ************************************************************/ static DmOpenRef CreateScanDatabase() { - Err err; - LocalID dbId; - UInt16 attrs, version; - DmOpenRef db; - - err = DmCreateDatabase(cardNo, appDbRattailScan, appFileCreator, 'SCAN', false); - if (err != errNone) - return NULL; - - dbId = DmFindDatabase(cardNo, appDbRattailScan); - if (dbId == 0) - return NULL; + Err err; + LocalID dbId; + UInt16 attrs, version; + DmOpenRef db; + + err = DmCreateDatabase(cardNo, appDbRattailScan, appFileCreator, 'SCAN', false); + if (err != errNone) + return NULL; + + dbId = DmFindDatabase(cardNo, appDbRattailScan); + if (dbId == 0) + return NULL; - // Set backup flag, version for database. - attrs = dmHdrAttrBackup; - version = 1; - DmSetDatabaseInfo(cardNo, dbId, NULL, &attrs, &version, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL); - - db = DmOpenDatabase(cardNo, dbId, dmModeWrite); - if (db == 0) - return NULL; - - return db; + // Set backup flag, version for database. + attrs = dmHdrAttrBackup; + version = 1; + DmSetDatabaseInfo(cardNo, dbId, NULL, &attrs, &version, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL); + + db = DmOpenDatabase(cardNo, dbId, dmModeWrite); + if (db == 0) + return NULL; + + return db; } -/*********************************************************************** +/************************************************************ * * FUNCTION: DrawCustomTableItem * - ***********************************************************************/ + ************************************************************/ static void DrawCustomTableItem(void* table, Int16 row, Int16 col, RectangleType* bounds) { - Char * text; - UInt16 size; - Coord x; - - text = (Char *) TblGetItemPtr(table, row, col); - if (*text != 0) { - size = StrLen(text); - - if (col == 0) { // barcode - WinDrawChars(text, size, bounds->topLeft.x, bounds->topLeft.y); - - } else { // cases or units - - // Only draw value if nonzero. - if (StrCompareAscii(text, "0") != 0) { - - // Draw value right-aligned. - x = bounds->topLeft.x + bounds->extent.x - FntCharsWidth(text, size); - WinDrawChars(text, size, x, bounds->topLeft.y); - } - } - - } + Char * text; + UInt16 size; + Coord x; + + text = (Char *) TblGetItemPtr(table, row, col); + if (*text != 0) { + size = StrLen(text); + + if (col == 0) { // barcode + WinDrawChars(text, size, bounds->topLeft.x, bounds->topLeft.y); + + } else { // cases or units + + // Only draw value if nonzero. + if (StrCompareAscii(text, "0") != 0) { + + // Draw value right-aligned. + x = bounds->topLeft.x + bounds->extent.x - FntCharsWidth(text, size); + WinDrawChars(text, size, x, bounds->topLeft.y); + } + } + + } } -/*********************************************************************** +/************************************************************ * - * FUNCTION: GetActiveFieldId + * FUNCTION: IsChecked * - ***********************************************************************/ + ************************************************************/ -static UInt16 GetActiveFieldId(FormPtr form) +static Boolean IsChecked(FormPtr form, UInt16 controlID) { - FieldPtr field; - UInt16 index; - - field = FrmGetActiveField(form); - if (field == NULL) { - return NULL; - } - - index = FrmGetObjectIndexFromPtr(form, field); - if (index == frmInvalidObjectId) { - return NULL; - } - - return FrmGetObjectId(form, index); + return (Boolean) CtlGetValue(FrmGetObjectPtr(form, FrmGetObjectIndex(form, controlID))); } -/*********************************************************************** + +/************************************************************ * - * FUNCTION: GetCheckedValue + * FUNCTION: GetObjectPtr * - ***********************************************************************/ + ************************************************************/ + +static void *GetObjectPtr(UInt16 objectID) +{ + FormPtr form; + + form = FrmGetActiveForm(); + return FrmGetObjectPtr(form, FrmGetObjectIndex(form, objectID)); +} -static Int16 GetCheckedValue(UInt16 objId) -{ - FormPtr form; - ControlPtr check; - - form = FrmGetActiveForm(); - check = GetObjectPtrById(form, objId); - if (check == NULL) { - return false; - } - - return CtlGetValue(check); -} -/*********************************************************************** - * - * FUNCTION: GetObjectPtrById - * - ***********************************************************************/ - -static void *GetObjectPtrById(FormPtr form, UInt16 objId) -{ - UInt16 index; - - index = FrmGetObjectIndex(form, objId); - if (index == frmInvalidObjectId) { - return NULL; - } - - return FrmGetObjectPtr(form, index); -} - - -/*********************************************************************** +/************************************************************ * * FUNCTION: MainFormDoCommand * - * DESCRIPTION: This routine performs the menu command specified. - * - * PARAMETERS: command - menu item id - * - * RETURNED: nothing - * - * REVISION HISTORY: - * - * - ***********************************************************************/ + ************************************************************/ + static Boolean MainFormDoCommand(UInt16 command) { - Boolean handled = false; - FormType * pForm; + Boolean handled = false; + FormPtr form; - switch (command) { - case MainOptionsAboutStarterApp: - pForm = FrmInitForm(AboutForm); - FrmDoDialog(pForm); // Display the About Box. - FrmDeleteForm(pForm); - handled = true; - break; + switch (command) { + case MainOptionsAboutStarterApp: + form = FrmInitForm(AboutForm); + FrmDoDialog(form); + FrmDeleteForm(form); + handled = true; + break; - } - - return handled; + } + + return handled; } -/*********************************************************************** +/************************************************************ * * FUNCTION: MainFormHandleEvent * - * DESCRIPTION: This routine is the event handler for the - * "MainForm" of this application. - * - * PARAMETERS: pEvent - a pointer to an EventType structure - * - * RETURNED: true if the event has handle and should not be passed - * to a higher level handler. - * - * REVISION HISTORY: - * - * - ***********************************************************************/ + ************************************************************/ + static Boolean MainFormHandleEvent(EventPtr event) { - Boolean handled = false; - FormPtr form; - TablePtr table; - UInt16 objId; - - switch (event->eType) { - - case frmOpenEvent: - form = FrmGetActiveForm(); - MainFormInit(form); - FrmDrawForm(form); - handled = true; - break; - - case menuEvent: - handled = MainFormDoCommand(event->data.menu.itemID); - break; - - case sclRepeatEvent: - if (event->data.sclRepeat.newValue > event->data.sclRepeat.value) - gTopVisibleRecord += (event->data.sclRepeat.newValue - event->data.sclRepeat.value); - else { - gTopVisibleRecord -= (event->data.sclRepeat.value - event->data.sclRepeat.newValue); - } - form = FrmGetActiveForm(); - table = GetObjectPtrById(form, MainFormScanRecords); - MainFormLoadTable(table, false); - TblRedrawTable(table); - break; - - case keyDownEvent: - form = FrmGetActiveForm(); - - // Pressing the ENTER (line feed) key will either advance focus - // to the next quantity field marked to be stopped upon, or else - // will validate and store the current data as a new scan record. - if (event->data.keyDown.chr == 10) { // line feed (ENTER) - objId = GetActiveFieldId(form); - if (objId == MainFormBarcode) { - ProcessScan(); - } else if (objId == MainFormCases) { - if (GetCheckedValue(MainFormStopOnUnits)) { - SetFieldFocus(MainFormUnits); - } else { - StoreScanData(); - } - } else if (objId == MainFormUnits) { - StoreScanData(); - } - - // Until I have more to go on, I'm assuming that if a handheld has - // a BCS2-capable scanner, then it is an Aceeca Meazura, and that its - // "center" navigational (hardware) key should be used as the scan - // trigger. - } else if (event->data.keyDown.chr == MzVCentreKey) { - if (gBcs2RefNum) { - if (FrmGetFocus(form) == FrmGetObjectIndex(form, MainFormBarcode)) - BCS2LibTriggerOn(gBcs2RefNum); - } + Boolean handled = false; + FormPtr form; + TablePtr table; + //UInt16 objId; + + switch (event->eType) { + + case frmOpenEvent: + form = FrmGetActiveForm(); + MainFormInit(form); + FrmDrawForm(form); + handled = true; + break; + + case menuEvent: + handled = MainFormDoCommand(event->data.menu.itemID); + break; + + case sclRepeatEvent: + if (event->data.sclRepeat.newValue > event->data.sclRepeat.value) + gTopVisibleRecord += (event->data.sclRepeat.newValue - event->data.sclRepeat.value); + else { + gTopVisibleRecord -= (event->data.sclRepeat.value - event->data.sclRepeat.newValue); + } + table = GetObjectPtr(MainFormScanRecords); + MainFormLoadTable(table, false); + TblRedrawTable(table); + break; + + case keyDownEvent: - /* - // Handle Babbo key - } else if ((event->data.keyDown.chr & vchrScanKey && - (event->data.keyDown.keyCode == scanBitHard1)) || - ((event->data.keyDown.chr & vchrScanKey) && - (event->data.keyDown.keyCode == scanBitHard2))) { - if (gBabbo) { - if (ScnCmdStartDecode() != STATUS_OK) { - SysFatalAlert("Start decode failed!"); - } - handled = true; - } - */ - } - break; + if (event->data.keyDown.chr == chrLineFeed) { - /* - // This event is passed by Babbo scanners (Janam handhelds). - case scanDecodeEvent: - if (gBabbo) { // just to be sure? - if (ScnCmdBeep(One_Short_Low) != STATUS_OK) { - SysFatalAlert("Beep failed!"); - } - } - break; - */ - - default: - break; - } - - return handled; + // We only have one field (barcode) on the main form. If it's + // active then we can operate on the ENTER key. + form = FrmGetFormPtr(MainForm); + if (FrmGetActiveField(form)) { + + if (IsChecked(form, MainFormStopOnCases)) { + ShowQuantityForm(MainFormCases, false); + } else if (IsChecked(form, MainFormStopOnUnits)) { + ShowQuantityForm(MainFormUnits, false); + } else { + StoreScanData(); + } + handled = true; + } + } + + /* form = FrmGetActiveForm(); */ + /* // Pressing the ENTER (line feed) key will either advance focus */ + /* // to the next quantity field marked to be stopped upon, or else */ + /* // will validate and store the current data as a new scan record. */ + /* if (event->data.keyDown.chr == chrLineFeed) { */ + /* objId = GetActiveFieldId(form); */ + /* if (objId == MainFormBarcode) { */ + /* ProcessScan(); */ + /* /\* */ + /* } else if (objId == MainFormCases) { */ + /* if (GetCheckedValue(MainFormStopOnUnits)) { */ + /* SetFieldFocus(MainFormUnits); */ + /* } else { */ + /* StoreScanData(); */ + /* } */ + /* *\/ */ + /* } else if (objId == MainFormUnits) { */ + /* StoreScanData(); */ + /* } */ + + /* // Until I have more to go on, I'm assuming that if a handheld has */ + /* // a BCS2-capable scanner, then it is an Aceeca Meazura, and that its */ + /* // "center" navigational (hardware) key should be used as the scan */ + /* // trigger. */ + /* } else if (event->data.keyDown.chr == MzVCentreKey) { */ + /* if (gBcs2RefNum) { */ + /* if (FrmGetFocus(form) == FrmGetObjectIndex(form, MainFormBarcode)) */ + /* BCS2LibTriggerOn(gBcs2RefNum); */ + /* } */ + + /* /\* */ + /* // Handle Babbo key */ + /* } else if ((event->data.keyDown.chr & vchrScanKey && */ + /* (event->data.keyDown.keyCode == scanBitHard1)) || */ + /* ((event->data.keyDown.chr & vchrScanKey) && */ + /* (event->data.keyDown.keyCode == scanBitHard2))) { */ + /* if (gBabbo) { */ + /* if (ScnCmdStartDecode() != STATUS_OK) { */ + /* SysFatalAlert("Start decode failed!"); */ + /* } */ + /* handled = true; */ + /* } */ + /* *\/ */ + /* } */ + + break; + + /* + // This event is passed by Babbo scanners (Janam handhelds). + case scanDecodeEvent: + if (gBabbo) { // just to be sure? + if (ScnCmdBeep(One_Short_Low) != STATUS_OK) { + SysFatalAlert("Beep failed!"); + } + } + break; + */ + + case ctlSelectEvent: + + switch (event->data.ctlSelect.controlID) { + case MainFormCases: + ShowQuantityForm(MainFormCases, true); + handled = true; + break; + case MainFormUnits: + ShowQuantityForm(MainFormUnits, true); + handled = true; + break; + default: + break; + } + + break; + + default: + break; + } + + return handled; } -/*********************************************************************** +/************************************************************ * * FUNCTION: MainFormInit * - ***********************************************************************/ + ************************************************************/ static void MainFormInit(FormPtr form) { - TablePtr table; - Int16 cols, col, rows, row; - UInt16 index; - ControlPtr ctrl; - - table = GetObjectPtrById(form, MainFormScanRecords); - //TblHasScrollBar(table, true); - - cols = TblGetNumberOfColumns(table); - rows = TblGetNumberOfRows(table); - for (col = 0; col < cols; col++) { - TblSetCustomDrawProcedure(table, col, DrawCustomTableItem); - TblSetColumnUsable(table, col, true); - for (row = 0; row < rows; row++) { - TblSetItemStyle(table, row, col, customTableItem); - TblSetRowUsable(table, row, false); - } - } - - MainFormLoadTable(table, true); - TblRedrawTable(table); - - index = FrmGetObjectIndex(form, MainFormCases); - ctrl = FrmGetObjectPtr(form, index); - FldInsert((FieldPtr) ctrl, "0", 1); - - // Unit quantity field is "stoppable" by default, unless the scanner is - // BCS2-capable, in which case I assume the handheld is an Aceeca Meazura - // model. Since this model doesn't have numeric keys, I figure it can't - // really support counting (yet?). - if (! gBcs2RefNum) { - index = FrmGetObjectIndex(form, MainFormStopOnUnits); - ctrl = FrmGetObjectPtr(form, index); - CtlSetValue(ctrl, 1); - } - - index = FrmGetObjectIndex(form, MainFormUnits); - ctrl = FrmGetObjectPtr(form, index); - FldInsert((FieldPtr) ctrl, "1", 1); - - index = FrmGetObjectIndex(form, MainFormBarcode); - FrmSetFocus(form, index); + TablePtr table; + Int16 cols, col, rows, row; + + table = GetObjectPtr(MainFormScanRecords); + //TblHasScrollBar(table, true); + + cols = TblGetNumberOfColumns(table); + rows = TblGetNumberOfRows(table); + for (col = 0; col < cols; col++) { + TblSetCustomDrawProcedure(table, col, DrawCustomTableItem); + TblSetColumnUsable(table, col, true); + for (row = 0; row < rows; row++) { + TblSetItemStyle(table, row, col, customTableItem); + TblSetRowUsable(table, row, false); + } + } + + MainFormLoadTable(table, true); + TblRedrawTable(table); + + // Set initial quantity values. + CtlSetLabel(GetObjectPtr(MainFormCases), "0"); + CtlSetLabel(GetObjectPtr(MainFormUnits), "1"); + + // Only stop on unit quantity by default. + CtlSetValue(GetObjectPtr(MainFormStopOnUnits), 1); + + // Set focus to the barcode field. + FrmSetFocus(form, FrmGetObjectIndex(form, MainFormBarcode)); } -/*********************************************************************** +/************************************************************ * * FUNCTION: MainFormLoadTable * - ***********************************************************************/ + ************************************************************/ static void MainFormLoadTable(TablePtr table, Boolean updateScroll) { - DmOpenRef db; - UInt16 numRecords; - MemHandle recordH; - RatScanDbRecord* recordP; - UInt16 rows, row, rowId; - FormPtr form; - ScrollBarPtr scroll; - - db = OpenScanDatabase(); - if (db == NULL) - return; + DmOpenRef db; + UInt16 numRecords; + MemHandle recordH; + RatScanDbRecord* recordP; + UInt16 rows, row, rowId; + ScrollBarPtr scroll; + + db = OpenScanDatabase(); + if (db == NULL) + return; - numRecords = DmNumRecords(db); - rows = (numRecords < 12) ? numRecords : 12; - if (gTopVisibleRecord < 0) - gTopVisibleRecord = (numRecords > 12) ? (numRecords - 12) : 0; + numRecords = DmNumRecords(db); + rows = (numRecords < 12) ? numRecords : 12; + if (gTopVisibleRecord < 0) + gTopVisibleRecord = (numRecords > 12) ? (numRecords - 12) : 0; - for (row = 0; row < rows; row++) { - rowId = gTopVisibleRecord + row; - recordH = DmGetRecord(db, rowId); - recordP = (MemPtr) MemHandleLock(recordH); - TblSetItemPtr(table, row, 0, &recordP->barcode); - if (StrCompareAscii(recordP->cases, "0") != 0) - TblSetItemPtr(table, row, 1, &recordP->cases); - else - TblSetItemPtr(table, row, 1, ""); - if (StrCompareAscii(recordP->units, "0") != 0) - TblSetItemPtr(table, row, 2, &recordP->units); - else - TblSetItemPtr(table, row, 2, ""); - MemHandleUnlock(recordH); - DmReleaseRecord(db, rowId, false); - TblSetRowID(table, row, rowId); - TblSetRowUsable(table, row, true); - } - - DmCloseDatabase(db); - TblMarkTableInvalid(table); - - if (updateScroll) { - form = FrmGetActiveForm(); - scroll = GetObjectPtrById(form, MainFormScroller); - if (numRecords <= 12) - SclSetScrollBar(scroll, 0, 0, 0, 0); - else - SclSetScrollBar(scroll, gTopVisibleRecord, 0, numRecords - 12, 11); - } + for (row = 0; row < rows; row++) { + rowId = gTopVisibleRecord + row; + recordH = DmGetRecord(db, rowId); + recordP = (MemPtr) MemHandleLock(recordH); + TblSetItemPtr(table, row, 0, &recordP->barcode); + if (StrCompareAscii(recordP->cases, "0") != 0) + TblSetItemPtr(table, row, 1, &recordP->cases); + else + TblSetItemPtr(table, row, 1, ""); + if (StrCompareAscii(recordP->units, "0") != 0) + TblSetItemPtr(table, row, 2, &recordP->units); + else + TblSetItemPtr(table, row, 2, ""); + MemHandleUnlock(recordH); + DmReleaseRecord(db, rowId, false); + TblSetRowID(table, row, rowId); + TblSetRowUsable(table, row, true); + } + + DmCloseDatabase(db); + TblMarkTableInvalid(table); + + if (updateScroll) { + scroll = GetObjectPtr(MainFormScroller); + if (numRecords <= 12) + SclSetScrollBar(scroll, 0, 0, 0, 0); + else + SclSetScrollBar(scroll, gTopVisibleRecord, 0, numRecords - 12, 11); + } } -/*********************************************************************** +/************************************************************ * * FUNCTION: OpenBabboScanner * - ***********************************************************************/ + ************************************************************/ + /* static Boolean OpenBabboScanner() { - Err err; - - if (! ScnIsJanamUnit()) { - SysFatalAlert("Not a Janam unit!"); - return false; - } + Err err; + + if (! ScnIsJanamUnit()) { + SysFatalAlert("Not a Janam unit!"); + return false; + } - err = ScnOpenDecoder(); - if (err) { - SysFatalAlert("Open decoder failed!"); - return false; - } - - if (ScnCmdScanEnable() != STATUS_OK) { - SysFatalAlert("Enable scanner failed!"); - ScnCloseDecoder(); - return false; - } - - gBabbo = true; - return true; + err = ScnOpenDecoder(); + if (err) { + SysFatalAlert("Open decoder failed!"); + return false; + } + + if (ScnCmdScanEnable() != STATUS_OK) { + SysFatalAlert("Enable scanner failed!"); + ScnCloseDecoder(); + return false; + } + + gBabbo = true; + return true; } */ -/*********************************************************************** +/************************************************************ * * FUNCTION: OpenBCS2Scanner * - ***********************************************************************/ + ************************************************************/ static Boolean OpenBCS2Scanner() { - Err err; - LocalID dbId; + Err err; + LocalID dbId; - err = SysLibLoad('libr', 'BcAp', &gBcs2RefNum); - if (err) { - /* - switch (err) { - case sysErrLibNotFound: - SysFatalAlert("BCS2 library not found!"); - break; - case sysErrNoFreeRAM: - SysFatalAlert("Out of memory (RAM)!"); - break; - case sysErrNoFreeLibSlots: - SysFatalAlert("No free library slots!"); - break; - default: - SysFatalAlert("BCS2 library load failed!"); - break; - } - */ - gBcs2RefNum = 0; - return false; - } - - err = BCS2LibOpen(gBcs2RefNum); - if (err) { - /* - switch (err) { - case errBCS2MemoryError: - SysFatalAlert("BCS2 threw memory error"); - break; - default: - SysFatalAlert("BCS2 library open failed!"); - break; - } - */ - SysLibRemove(gBcs2RefNum); - gBcs2RefNum = 0; - return false; - } - - dbId = DmFindDatabase(cardNo, appDbRattail); - if (! dbId) { - /* - SysFatalAlert("Find database failed!"); - */ - SysLibRemove(gBcs2RefNum); - gBcs2RefNum = 0; - return false; - } - - err = SysNotifyRegister(cardNo, dbId, - BCS2BarCodeReadyNotification, NULL, - sysNotifyNormalPriority, NULL); - if (err != errNone) { - /* - SysFatalAlert("Notify registration failed!"); - */ - SysLibRemove(gBcs2RefNum); - gBcs2RefNum = 0; - return false; - } - - return true; + err = SysLibLoad('libr', 'BcAp', &gBcs2RefNum); + if (err) { + /* + switch (err) { + case sysErrLibNotFound: + SysFatalAlert("BCS2 library not found!"); + break; + case sysErrNoFreeRAM: + SysFatalAlert("Out of memory (RAM)!"); + break; + case sysErrNoFreeLibSlots: + SysFatalAlert("No free library slots!"); + break; + default: + SysFatalAlert("BCS2 library load failed!"); + break; + } + */ + gBcs2RefNum = 0; + return false; + } + + err = BCS2LibOpen(gBcs2RefNum); + if (err) { + /* + switch (err) { + case errBCS2MemoryError: + SysFatalAlert("BCS2 threw memory error"); + break; + default: + SysFatalAlert("BCS2 library open failed!"); + break; + } + */ + SysLibRemove(gBcs2RefNum); + gBcs2RefNum = 0; + return false; + } + + dbId = DmFindDatabase(cardNo, appDbRattail); + if (! dbId) { + /* + SysFatalAlert("Find database failed!"); + */ + SysLibRemove(gBcs2RefNum); + gBcs2RefNum = 0; + return false; + } + + err = SysNotifyRegister(cardNo, dbId, + BCS2BarCodeReadyNotification, NULL, + sysNotifyNormalPriority, NULL); + if (err != errNone) { + /* + SysFatalAlert("Notify registration failed!"); + */ + SysLibRemove(gBcs2RefNum); + gBcs2RefNum = 0; + return false; + } + + return true; } -/*********************************************************************** +/************************************************************ * * FUNCTION: OpenScanDatabase * - ***********************************************************************/ + ************************************************************/ static DmOpenRef OpenScanDatabase() { - LocalID dbId; - DmOpenRef db; - - dbId = DmFindDatabase(cardNo, appDbRattailScan); - if (dbId == 0) - return CreateScanDatabase(); - - db = DmOpenDatabase(cardNo, dbId, dmModeWrite); - if (db == 0) - return NULL; - - return db; + LocalID dbId; + DmOpenRef db; + + dbId = DmFindDatabase(cardNo, appDbRattailScan); + if (dbId == 0) + return CreateScanDatabase(); + + db = DmOpenDatabase(cardNo, dbId, dmModeWrite); + if (db == 0) + return NULL; + + return db; } -/*********************************************************************** +/************************************************************ * - * FUNCTION: ProcessScan + * FUNCTION: QuantityFormHandleEvent * - ***********************************************************************/ - -static void ProcessScan() + ************************************************************/ + +static Boolean QuantityFormHandleEvent(EventPtr event) { - if (GetCheckedValue(MainFormStopOnCases)) { - SetFieldFocus(MainFormCases); - } else if (GetCheckedValue(MainFormStopOnUnits)) { - SetFieldFocus(MainFormUnits); - } + Boolean handled = false; + FormPtr form; + + switch (event->eType) { + + case frmOpenEvent: + form = FrmGetActiveForm(); + QuantityFormInit(form); + FrmDrawForm(form); + handled = true; + break; + + case ctlSelectEvent: + switch (event->data.ctlSelect.controlID) { + case QuantityForm1: + AppendQuantityDigit(1); + break; + case QuantityForm2: + AppendQuantityDigit(2); + break; + case QuantityForm3: + AppendQuantityDigit(3); + break; + case QuantityForm4: + AppendQuantityDigit(4); + break; + case QuantityForm5: + AppendQuantityDigit(5); + break; + case QuantityForm6: + AppendQuantityDigit(6); + break; + case QuantityForm7: + AppendQuantityDigit(7); + break; + case QuantityForm8: + AppendQuantityDigit(8); + break; + case QuantityForm9: + AppendQuantityDigit(9); + break; + case QuantityForm0: + AppendQuantityDigit(0); + break; + case QuantityFormClear: + StrCopy(gQuantity, "0"); + UpdateQuantityDisplay(); + break; + case QuantityFormCancel: + FrmReturnToForm(MainForm); + break; + case QuantityFormOK: + QuantityFormAccept(); + break; + default: + break; + } + handled = true; + break; + + case keyDownEvent: + + switch (event->data.keyDown.chr) { + case chrLineFeed: + QuantityFormAccept(); + handled = true; + break; + case chrDigitZero: + AppendQuantityDigit(0); + handled = true; + break; + case chrDigitOne: + AppendQuantityDigit(1); + handled = true; + break; + case chrDigitTwo: + AppendQuantityDigit(2); + handled = true; + break; + case chrDigitThree: + AppendQuantityDigit(3); + handled = true; + break; + case chrDigitFour: + AppendQuantityDigit(4); + handled = true; + break; + case chrDigitFive: + AppendQuantityDigit(5); + handled = true; + break; + case chrDigitSix: + AppendQuantityDigit(6); + handled = true; + break; + case chrDigitSeven: + AppendQuantityDigit(7); + handled = true; + break; + case chrDigitEight: + AppendQuantityDigit(8); + handled = true; + break; + case chrDigitNine: + AppendQuantityDigit(9); + handled = true; + break; + default: + break; + } + + break; + + default: + break; + } + + return handled; } -/*********************************************************************** +/************************************************************ + * + * FUNCTION: QuantityFormAccept + * + ************************************************************/ + +static void QuantityFormAccept() +{ + FormPtr form; + ControlPtr control; + + form = FrmGetFormPtr(MainForm); + + // Close the quantity form and return to the main form. + FrmReturnToForm(MainForm); + + // Update the selector trigger label with the new quantity. + control = FrmGetObjectPtr(form, FrmGetObjectIndex(form, gQuantityTriggerID)); + CtlSetLabel(control, gQuantity); + + // If the form was shown automatically as part of the scanning workflow, + // then we'll keep that workflow going... + if (! gQuantityManual) { + + if (gQuantityTriggerID == MainFormCases) { + if (IsChecked(form, MainFormStopOnUnits)) { + ShowQuantityForm(MainFormUnits, false); + } else { + StoreScanData(); + } + + } else if (gQuantityTriggerID == MainFormUnits) { + StoreScanData(); + } + } +} + + +/************************************************************ + * + * FUNCTION: QuantityFormInit + * + ************************************************************/ + +static void QuantityFormInit(FormPtr form) +{ + // Set form title according to what is being edited. + if (gQuantityTriggerID == MainFormCases) { + FrmSetTitle(form, "Case Quantity"); + } else if (gQuantityTriggerID == MainFormUnits) { + FrmSetTitle(form, "Unit Quantity"); + } + + // Display current quantity value. + FldSetTextPtr(GetObjectPtr(QuantityFormQuantity), gQuantity); +} + + +/************************************************************ * * FUNCTION: SetFieldFocus * - ***********************************************************************/ - + ************************************************************/ + static void SetFieldFocus(UInt16 objId) { - FormPtr form; - UInt16 index; - FieldPtr field; - - form = FrmGetActiveForm(); - if (form == NULL) { - return; - } - - index = FrmGetObjectIndex(form, objId); - if (index == frmInvalidObjectId) { - return; - } - - field = FrmGetObjectPtr(form, index); - FldSetSelection(field, 0, FldGetTextLength(field)); - FrmSetFocus(form, index); + FormPtr form; + FieldPtr field; + UInt16 index; + + form = FrmGetActiveForm(); + index = FrmGetObjectIndex(form, objId); + field = FrmGetObjectPtr(form, index); + FldSetSelection(field, 0, FldGetTextLength(field)); + FrmSetFocus(form, index); } -/*********************************************************************** +/************************************************************ + * + * FUNCTION: ShowQuantityForm + * + ************************************************************/ + +static void ShowQuantityForm(UInt16 triggerID, Boolean manual) +{ + FormPtr form; + ControlPtr ctrl; + + form = FrmGetFormPtr(MainForm); + ctrl = FrmGetObjectPtr(form, FrmGetObjectIndex(form, triggerID)); + + // Track whether the form is being shown due to manaul user initiation, + // versus automatically as part of the scanning workflow. + gQuantityManual = manual; + + // Store quantity trigger so we know which quantity we're editing. + gQuantityTriggerID = triggerID; + + // Update the current quantity buffer from the trigger label. + gQuantity = (triggerID == MainFormCases) ? gCaseQuantity : gUnitQuantity; + StrCopy(gQuantity, CtlGetLabel(ctrl)); + + // The quantity has yet to be touched by the user. + gQuantityTouched = false; + + // Load and display the quantity form. + FrmPopupForm(QuantityForm); +} + + +/************************************************************ + * + * FUNCTION: AppendQuantityDigit + * + ************************************************************/ + +static void AppendQuantityDigit(UInt16 digit) +{ + Char digitText[2]; + + if (StrLen(gQuantity) > 2) { + // If the current quantity already exceeds 2 digits, issue a warning + // beep instead of appending the digit. + SndPlaySystemSound(sndWarning); + + } else if (gQuantityTouched && StrCompare(gQuantity, "0") != 0) { + // Okay, we can append the digit. + StrIToA(digitText, digit); + StrCat(gQuantity, digitText); + UpdateQuantityDisplay(); + + } else { + // Either this is the first time the quantity is being touched, or else + // the quantity is currently zero. Replace it outright instead of + // appending the digit. + StrIToA(gQuantity, digit); + UpdateQuantityDisplay(); + gQuantityTouched = true; + } +} + + +/************************************************************ + * + * FUNCTION: UpdateQuantityDisplay + * + ************************************************************/ + +static void UpdateQuantityDisplay() +{ + FormPtr form; + FieldPtr field; + + form = FrmGetFormPtr(QuantityForm); + field = FrmGetObjectPtr(form, FrmGetObjectIndex(form, QuantityFormQuantity)); + FldSetTextPtr(field, gQuantity); + FldDrawField(field); +} + + +/************************************************************ * * FUNCTION: StoreScanData * - ***********************************************************************/ + ************************************************************/ static Boolean StoreScanData() { - FormPtr form; - FieldPtr barcode, cases, units; - UInt16 fieldIndex; - UInt32 size, offset; - DmOpenRef db; - UInt16 recordIndex; - MemHandle recordH; - MemPtr recordP; - TablePtr table; - UInt16 row; - - // Get form and barcode field pointers. - form = FrmGetActiveForm(); - barcode = GetObjectPtrById(form, MainFormBarcode); - if (barcode == NULL) - return false; + FormPtr form; + FieldPtr barcode; + ControlPtr cases, units; + /* Char* quantity; */ + UInt32 size, offset; + DmOpenRef db; + UInt16 recordIndex; + MemHandle recordH; + MemPtr recordP; + TablePtr table; + UInt16 row; + + // Get form and barcode field pointers. + form = FrmGetFormPtr(MainForm); + barcode = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormBarcode)); - // Set focus to barcode field if empty. - size = FldGetTextLength(barcode); - if (size == 0) { - fieldIndex = FrmGetObjectIndex(form, MainFormBarcode); - if (fieldIndex != frmInvalidObjectId) - FrmSetFocus(form, fieldIndex); - return false; - } - - // Get case and unit field pointers. - cases = GetObjectPtrById(form, MainFormCases); - if (cases == NULL) - return false; - units = GetObjectPtrById(form, MainFormUnits); - if (units == NULL) - return false; - - // Open the database and create a new record. - db = OpenScanDatabase(); - if (db == NULL) - return false; - recordIndex = dmMaxRecordIndex; - recordH = DmNewRecord(db, &recordIndex, sizeof(RatScanDbRecord)); - if (recordH == 0) { - DmCloseDatabase(db); - return false; - } - - // Write scan data to the record... - recordP = MemHandleLock(recordH); - offset = 0; + // Set focus to barcode field if empty. + if (! FldGetTextLength(barcode)) { + FrmSetFocus(form, FrmGetObjectIndex(form, MainFormBarcode)); + return false; + } + + // Get case and unit field pointers. + cases = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormCases)); + units = FrmGetObjectPtr(form, FrmGetObjectIndex(form, MainFormUnits)); + + // Open the database and create a new record. + db = OpenScanDatabase(); + if (db == NULL) + return false; + recordIndex = dmMaxRecordIndex; + recordH = DmNewRecord(db, &recordIndex, sizeof(RatScanDbRecord)); + if (recordH == 0) { + DmCloseDatabase(db); + return false; + } + + // Write scan data to the record... + recordP = MemHandleLock(recordH); + offset = 0; - size = FldGetTextLength(barcode); - DmWrite(recordP, offset, FldGetTextPtr(barcode), size); - offset += size; - - size = 15 - size; - DmSet(recordP, offset, size, 0); - offset += size; - - size = FldGetTextLength(cases); - DmWrite(recordP, offset, FldGetTextPtr(cases), size); - offset += size; + size = FldGetTextLength(barcode); + DmWrite(recordP, offset, FldGetTextPtr(barcode), size); + offset += size; + + size = 15 - size; + DmSet(recordP, offset, size, 0); + offset += size; - size = 4 - size; - DmSet(recordP, offset, size, 0); - offset += size; - - size = FldGetTextLength(units); - DmWrite(recordP, offset, FldGetTextPtr(units), size); - offset += size; - - size = 4 - size; - DmSet(recordP, offset, size, 0); - - // ...then close the record and database. - MemHandleUnlock(recordH); - DmReleaseRecord(db, recordIndex, false); - DmCloseDatabase(db); - - // Redraw the table. - table = GetObjectPtrById(form, MainFormScanRecords); - row = TblGetLastUsableRow(table); - if (row == tblUnusableRow) - gTopVisibleRecord = 0; - else if (row == 11) - gTopVisibleRecord = TblGetRowID(table, 1); - MainFormLoadTable(table, true); - TblRedrawTable(table); + /* + size = FldGetTextLength(cases); + DmWrite(recordP, offset, FldGetTextPtr(cases), size); + offset += size; + */ - SetFieldFocus(MainFormBarcode); - return true; + /* size = 2; */ + /* DmWrite(recordP, offset, "0", 2); */ + /* offset += size; */ + + /* quantity = CtlGetLabel(cases); */ + /* size = StrLen(quantity); */ + /* DmWrite(recordP, offset, quantity, size); */ + /* offset += size; */ + + size = StrLen(CtlGetLabel(cases)); + DmWrite(recordP, offset, CtlGetLabel(cases), size); + offset += size; + + size = 4 - size; + DmSet(recordP, offset, size, 0); + offset += size; + + /* size = FldGetTextLength(units); */ + /* DmWrite(recordP, offset, FldGetTextPtr(units), size); */ + /* offset += size; */ + + size = StrLen(CtlGetLabel(units)); + DmWrite(recordP, offset, CtlGetLabel(units), size); + offset += size; + + size = 4 - size; + DmSet(recordP, offset, size, 0); + + // ...then close the record and database. + MemHandleUnlock(recordH); + DmReleaseRecord(db, recordIndex, false); + DmCloseDatabase(db); + + // Redraw the table. + table = GetObjectPtr(MainFormScanRecords); + row = TblGetLastUsableRow(table); + if (row == tblUnusableRow) + gTopVisibleRecord = 0; + else if (row == 11) + gTopVisibleRecord = TblGetRowID(table, 1); + MainFormLoadTable(table, true); + TblRedrawTable(table); + + SetFieldFocus(MainFormBarcode); + return true; } -/*********************************************************************** +/************************************************************ * * FUNCTION: PilotMain * - * DESCRIPTION: This is the main entry point for the application. - * - * PARAMETERS: cmd - word value specifying the launch code. - * cmdPB - pointer to a structure that is associated with the launch code. - * launchFlags - word value providing extra information about the launch. - * RETURNED: Result of launch - * - * REVISION HISTORY: - * - * - ***********************************************************************/ + ************************************************************/ + UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags) { - Err error = errNone; - SysNotifyParamType* notifyParams = (SysNotifyParamType *) cmdPBP; - FormPtr form; - FieldPtr barcode; - MemHandle barcodeH; - MemPtr barcodeP; - Char * scancode; + Err error = errNone; + /* + SysNotifyParamType* notifyParams = (SysNotifyParamType *) cmdPBP; + FieldPtr barcode; + MemHandle barcodeH; + MemPtr barcodeP; + Char * scancode; + */ - switch (cmd) { - case sysAppLaunchCmdNormalLaunch: - if ((error = AppStart()) == 0) { - AppEventLoop(); - AppStop(); - } - break; - - case sysAppLaunchCmdNotify: - if (notifyParams->notifyType == BCS2BarCodeReadyNotification) { - scancode = (Char *) notifyParams->notifyDetailsP + 1; - if (StrCompareAscii(scancode, "NO READ")) { // (means good read) - form = FrmGetActiveForm(); - barcode = GetObjectPtrById(form, MainFormBarcode); - barcodeH = FldGetTextHandle(barcode); - FldSetTextHandle(barcode, NULL); - if (! barcodeH) - barcodeH = MemHandleNew(15); // ugh - barcodeP = MemHandleLock(barcodeH); - StrCopy((Char *) barcodeP, scancode); - MemHandleUnlock(barcodeH); - FldSetTextHandle(barcode, barcodeH); - FldDrawField(barcode); - if (GetCheckedValue(MainFormStopOnCases)) - SetFieldFocus(MainFormCases); - else if (GetCheckedValue(MainFormStopOnUnits)) - SetFieldFocus(MainFormUnits); - else { - if (StoreScanData()) - SndPlaySystemSound(sndInfo); - } - } - } - break; + switch (cmd) { + case sysAppLaunchCmdNormalLaunch: + if ((error = AppStart()) == 0) { + AppEventLoop(); + AppStop(); + } + break; + + /* + case sysAppLaunchCmdNotify: + if (notifyParams->notifyType == BCS2BarCodeReadyNotification) { + scancode = (Char *) notifyParams->notifyDetailsP + 1; + if (StrCompareAscii(scancode, "NO READ")) { // (means good read) + barcode = GetObjectPtr(MainFormBarcode); + barcodeH = FldGetTextHandle(barcode); + FldSetTextHandle(barcode, NULL); + if (! barcodeH) + barcodeH = MemHandleNew(15); // ugh + barcodeP = MemHandleLock(barcodeH); + StrCopy((Char *) barcodeP, scancode); + MemHandleUnlock(barcodeH); + FldSetTextHandle(barcode, barcodeH); + FldDrawField(barcode); + if (GetCheckedValue(MainFormStopOnCases)) { + //SetFieldFocus(MainFormCases); + } else if (GetCheckedValue(MainFormStopOnUnits)) { + SetFieldFocus(MainFormUnits); + } else { + if (StoreScanData()) + SndPlaySystemSound(sndInfo); + } + } + } + break; + */ - default: - break; - } - - return error; + default: + break; + } + + return error; } - - diff --git a/src/AppMain.h b/src/AppMain.h index 764e5d4..9e62921 100644 --- a/src/AppMain.h +++ b/src/AppMain.h @@ -11,15 +11,22 @@ typedef struct { static void CloseBCS2Scanner(); static DmOpenRef CreateScanDatabase(); static void DrawCustomTableItem(void* table, Int16 row, Int16 col, RectangleType* bounds); -static UInt16 GetActiveFieldId(FormPtr form); -static Int16 GetCheckedValue(UInt16 objId); -static void *GetObjectPtrById(FormPtr form, UInt16 objId); +/* static Int16 GetCheckedValue(UInt16 objId); */ +static Boolean IsChecked(FormPtr form, UInt16 controlID); +static void *GetObjectPtr(UInt16 objId); static Boolean MainFormHandleEvent(EventPtr event); static void MainFormInit(FormPtr form); static void MainFormLoadTable(TablePtr table, Boolean updateScroll); //static Boolean OpenBabboScanner(); static Boolean OpenBCS2Scanner(); static DmOpenRef OpenScanDatabase(); -static void ProcessScan(); static void SetFieldFocus(UInt16 objId); +static void ShowQuantityForm(UInt16 triggerID, Boolean manual); static Boolean StoreScanData(); + +// Quantity Form +static Boolean QuantityFormHandleEvent(EventPtr event); +static void QuantityFormInit(FormPtr form); +static void AppendQuantityDigit(UInt16 digit); +static void UpdateQuantityDisplay(); +static void QuantityFormAccept(); diff --git a/src/AppResources.h b/src/AppResources.h index 3cb43bd..8c70a65 100644 --- a/src/AppResources.h +++ b/src/AppResources.h @@ -24,6 +24,22 @@ #define AboutText1Label 1103 //(Left Origin = 23, Top Origin = 54, Usable = 1, Font = Standard) #define AboutText2Label 1104 //(Left Origin = 50, Top Origin = 104, Usable = 1, Font = Bold) +#define QuantityForm 1200 + +#define QuantityForm1 1000 +#define QuantityForm2 1001 +#define QuantityForm3 1002 +#define QuantityForm4 1003 +#define QuantityForm5 1004 +#define QuantityForm6 1005 +#define QuantityForm7 1006 +#define QuantityForm8 1007 +#define QuantityForm9 1008 +#define QuantityForm0 1009 +#define QuantityFormOK 1010 +#define QuantityFormClear 1012 +#define QuantityFormCancel 1011 +#define QuantityFormQuantity 1013 // Resource: Talt 1001 #define RomIncompatibleAlert 1001