| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | /******************************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2007, ACCESS Systems Americas, Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * File: AppMain.c | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <PalmOS.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #ifdef SCANLIB_BCS2
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | #include "BCS2ScannerLib.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #ifdef SCANLIB_JANAM
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | #include "JanamScnCompatible.h"
 | 
					
						
							|  |  |  | #include "ScanMgr.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef SCANLIB_SYMBOL
 | 
					
						
							|  |  |  | #include "Symbol/ScanMgrDef.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Rattail App
 | 
					
						
							|  |  |  | #include "AppResources.h"
 | 
					
						
							|  |  |  | #include "AppMain.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /***********************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  *    Entry Points | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  ***********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /***********************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  *    Internal Constants | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  ***********************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | #define appFileCreator            'RTTL'
 | 
					
						
							|  |  |  | #define appVersionNum            0x01
 | 
					
						
							|  |  |  | #define appPrefID                0x00
 | 
					
						
							|  |  |  | #define appPrefVersionNum        0x01
 | 
					
						
							|  |  |  | #define appDbRattail            "Rattail"
 | 
					
						
							|  |  |  | #define appDbRattailScan        "Rattail_Scan"
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | #define COLUMN_BARCODE            0
 | 
					
						
							|  |  |  | #define COLUMN_CASES            1
 | 
					
						
							|  |  |  | #define COLUMN_UNITS            2
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /***********************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  *    Global Variables | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  ***********************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | UInt16          cardNo = 0; | 
					
						
							|  |  |  | //UInt16        gNumCols = 3;
 | 
					
						
							|  |  |  | //UInt16        gNumRows = 11;
 | 
					
						
							|  |  |  | //MemHandle     gHandles[11][3];
 | 
					
						
							|  |  |  | Int16           gTopVisibleRecord = -1; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #ifdef SCANLIB_BCS2
 | 
					
						
							|  |  |  | UInt16          gBcs2RefNum = 0; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef SCANLIB_JANAM
 | 
					
						
							|  |  |  | Boolean         gBabbo = false; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | // 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; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | // 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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    AppHandleEvent | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | static Boolean AppHandleEvent(EventPtr event) | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     UInt16      formID; | 
					
						
							|  |  |  |     FormPtr     form; | 
					
						
							|  |  |  |     Boolean     handled = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (event->eType == frmLoadEvent) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // 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; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  * FUNCTION:    AppStart | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | static Err AppStart(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #ifdef SCANLIB_BCS2
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     OpenBCS2Scanner(); | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef SCANLIB_JANAM
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     //OpenBabboScanner();
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |      | 
					
						
							|  |  |  |     FrmGotoForm(MainForm); | 
					
						
							|  |  |  |     return errNone; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    AppStop | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | static void AppStop(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #ifdef SCANLIB_BCS2
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     CloseBCS2Scanner(); | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef SCANLIB_JANAM
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     //CloseBabboScanner();
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     FrmCloseAllForms(); | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    AppEventLoop | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | static void AppEventLoop(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     Err         error; | 
					
						
							|  |  |  |     EventType   event; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     do { | 
					
						
							|  |  |  |         EvtGetEvent(&event, evtWaitForever); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (SysHandleEvent(&event)) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |         if (MenuHandleEvent(0, &event, &error)) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |         if (AppHandleEvent(&event)) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |         FrmDispatchEvent(&event); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } while (event.eType != appStopEvent); | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #ifdef SCANLIB_JANAM
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    CloseBabboScanner | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | /*
 | 
					
						
							|  |  |  | static void CloseBabboScanner() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     if (! gBabbo) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     ScnCmdScanDisable(); | 
					
						
							|  |  |  |     ScnCloseDecoder();     | 
					
						
							|  |  |  |     gBabbo = false; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #ifdef SCANLIB_BCS2
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    CloseBCS2Scanner | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void CloseBCS2Scanner() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     LocalID     dbId; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     if (! gBcs2RefNum) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dbId = DmFindDatabase(cardNo, appDbRattail); | 
					
						
							|  |  |  |     if (dbId) | 
					
						
							|  |  |  |         SysNotifyUnregister(cardNo, dbId, BCS2BarCodeReadyNotification,  | 
					
						
							|  |  |  |                             sysNotifyNormalPriority); | 
					
						
							|  |  |  |     BCS2LibClose(gBcs2RefNum); | 
					
						
							|  |  |  |     SysLibRemove(gBcs2RefNum); | 
					
						
							|  |  |  |     gBcs2RefNum = 0; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    CreateScanDatabase | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static DmOpenRef CreateScanDatabase() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    DrawCustomTableItem | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void DrawCustomTableItem(void* table, Int16 row, Int16 col, RectangleType* bounds) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  * FUNCTION:    IsChecked | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | static Boolean IsChecked(FormPtr form, UInt16 controlID) | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     return (Boolean) CtlGetValue(FrmGetObjectPtr(form, FrmGetObjectIndex(form, controlID))); | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  * FUNCTION:    GetObjectPtr | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | static void *GetObjectPtr(UInt16 objectID) | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     FormPtr     form; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     form = FrmGetActiveForm(); | 
					
						
							|  |  |  |     return FrmGetObjectPtr(form, FrmGetObjectIndex(form, objectID)); | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    MainFormDoCommand | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | static Boolean MainFormDoCommand(UInt16 command) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     Boolean     handled = false; | 
					
						
							|  |  |  |     FormPtr     form; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (command) { | 
					
						
							|  |  |  |     case MainOptionsAboutStarterApp: | 
					
						
							|  |  |  |         form = FrmInitForm(AboutForm); | 
					
						
							|  |  |  |         FrmDoDialog(form); | 
					
						
							|  |  |  |         FrmDeleteForm(form); | 
					
						
							|  |  |  |         handled = true; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     return handled; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    MainFormHandleEvent | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | static Boolean MainFormHandleEvent(EventPtr event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (event->data.keyDown.chr == chrLineFeed) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // 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; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    MainFormInit | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void MainFormInit(FormPtr form) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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)); | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    MainFormLoadTable | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void MainFormLoadTable(TablePtr table, Boolean updateScroll) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #ifdef SCANLIB_JANAM
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    OpenBabboScanner | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | /*
 | 
					
						
							|  |  |  | static Boolean OpenBabboScanner() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #ifdef SCANLIB_BCS2
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    OpenBCS2Scanner | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static Boolean OpenBCS2Scanner() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-12-04 11:55:58 -08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    OpenScanDatabase | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | static DmOpenRef OpenScanDatabase() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  * FUNCTION:    QuantityFormHandleEvent | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static Boolean QuantityFormHandleEvent(EventPtr event) | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    SetFieldFocus | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | static void SetFieldFocus(UInt16 objId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     FormPtr     form; | 
					
						
							|  |  |  |     FieldPtr    field; | 
					
						
							|  |  |  |     UInt16      index; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     form = FrmGetActiveForm(); | 
					
						
							|  |  |  |     index = FrmGetObjectIndex(form, objId); | 
					
						
							|  |  |  |     field = FrmGetObjectPtr(form, index); | 
					
						
							|  |  |  |     FldSetSelection(field, 0, FldGetTextLength(field));     | 
					
						
							|  |  |  |     FrmSetFocus(form, index); | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  * FUNCTION:    ShowQuantityForm | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | static void ShowQuantityForm(UInt16 triggerID, Boolean manual) | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     FormPtr     form; | 
					
						
							|  |  |  |     ControlPtr  ctrl; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     form = FrmGetFormPtr(MainForm); | 
					
						
							|  |  |  |     ctrl = FrmGetObjectPtr(form, FrmGetObjectIndex(form, triggerID)); | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     // 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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  * FUNCTION:    AppendQuantityDigit | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void AppendQuantityDigit(UInt16 digit) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Char        digitText[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:27:22 -08:00
										 |  |  |     if (! gQuantityTouched) { | 
					
						
							|  |  |  |         // This is the first time the quantity is being touched; replace it
 | 
					
						
							|  |  |  |         // outright instead of appending the digit.
 | 
					
						
							|  |  |  |         StrIToA(gQuantity, digit); | 
					
						
							|  |  |  |         UpdateQuantityDisplay(); | 
					
						
							|  |  |  |         gQuantityTouched = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } else if (StrLen(gQuantity) > 2) { | 
					
						
							|  |  |  |         // The current quantity already exceeds 2 digits; issue a warning beep
 | 
					
						
							|  |  |  |         // instead of appending the digit.
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |         SndPlaySystemSound(sndWarning); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:27:22 -08:00
										 |  |  |     } else if (StrCompare(gQuantity, "0") == 0) { | 
					
						
							|  |  |  |         // The current quantity is zero; replace it outright instead of
 | 
					
						
							|  |  |  |         // appending the digit.
 | 
					
						
							|  |  |  |         StrIToA(gQuantity, digit); | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |         UpdateQuantityDisplay(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:27:22 -08:00
										 |  |  |         // Okay, we can append the digit.
 | 
					
						
							|  |  |  |         StrIToA(digitText, digit); | 
					
						
							|  |  |  |         StrCat(gQuantity, digitText); | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |         UpdateQuantityDisplay(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  * FUNCTION:    UpdateQuantityDisplay | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void UpdateQuantityDisplay() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     FormPtr     form; | 
					
						
							|  |  |  |     FieldPtr    field; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     form = FrmGetFormPtr(QuantityForm); | 
					
						
							|  |  |  |     field = FrmGetObjectPtr(form, FrmGetObjectIndex(form, QuantityFormQuantity)); | 
					
						
							|  |  |  |     FldSetTextPtr(field, gQuantity); | 
					
						
							|  |  |  |     FldDrawField(field); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  * FUNCTION:    StoreScanData | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |  ************************************************************/ | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | static Boolean StoreScanData() | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  |     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.
 | 
					
						
							|  |  |  |     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 = 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; | 
					
						
							| 
									
										
										
										
											2012-02-15 19:34:31 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 11:18:18 -08:00
										 |  |  | /************************************************************
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * FUNCTION:    PilotMain | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  ************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     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)
 | 
					
						
							|  |  |  |           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; | 
					
						
							|  |  |  | } |