GPS4Palm

Source Code Documentation


RouteForm.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * $RCSfile: RouteForm_8c-source.html,v $
00004  *
00005  * GPS4Palm Routes Form
00006  *
00007  *
00008  * This program is Copyright (C) 12/2002 Matthias Prinke
00009  * <matthias.prinke@surfeu.de> and covered by GNU's GPL.
00010  * In particular, this program is free software and comes WITHOUT
00011  * ANY WARRANTY.
00012  *
00013  * $Author: mp $
00014  *
00015  * $Date: 2007-10-08 20:40:34 $
00016  *
00017  * $Revision: 1.7.2.1 $
00018  *
00019  * $Log: RouteForm_8c-source.html,v $
00019  * Revision 1.7.2.1  2007-10-08 20:40:34  mp
00019  * updated for gps4palm V0.9.5 beta
00019  *
00020  * Revision 1.19  2005-05-06 13:40:07  mp
00021  * added workaround for Bluetooth-Open Bug
00022  *
00023  * Revision 1.18  2005/01/30 21:22:13  mp
00024  * added PortsMenu event handling
00025  *
00026  * Revision 1.17  2005/01/23 10:01:32  mp
00027  * changed re-opening of GPS serial port after data transfer
00028  *
00029  * Revision 1.16  2004/12/18 16:11:53  mp
00030  * fixed serial port re-opening for PDAs with New Serial Manager
00031  *
00032  * Revision 1.15  2004/12/07 17:13:52  mp
00033  * Modified selection of Active Route: route must contain at least two
00034  * waypoints.
00035  *
00036  * Revision 1.14  2004/12/06 21:10:00  mp
00037  * changed display of Active Route to bold font
00038  *
00039  * Revision 1.13  2004/11/30 20:43:08  mp
00040  * added TransferTrkReqEvent and TrackMenu event handling, added GarminGetTrks()
00041  *
00042  * Revision 1.12  2004/11/26 20:07:02  mp
00043  * added string truncation to fit table cell in TableDrawCommentCell()
00044  *
00045  * Revision 1.11  2004/11/24 21:22:35  mp
00046  * moved static function declarations from header to implementation file,
00047  * added AboutForm menu event handling
00048  *
00049  * Revision 1.10  2004/11/23 17:47:52  mp
00050  * removed unused variables
00051  *
00052  * Revision 1.9  2004/11/20 15:45:11  mp
00053  * added UpdateActWpt() function call
00054  *
00055  * Revision 1.8  2004/11/19 18:36:16  mp
00056  * added setting of active waypoint from start of active route
00057  *
00058  * Revision 1.7  2004/11/15 19:52:38  mp
00059  * code cleanup
00060  *
00061  * Revision 1.6  2004/11/13 18:53:47  mp
00062  * fixed table selection, fixed status update after route download
00063  *
00064  * Revision 1.5  2004/11/13 15:59:24  mp
00065  * added route new/edit functions, fixed bugs
00066  *
00067  * Revision 1.4  2004/11/11 21:43:09  mp
00068  * Modified table handling (custom drawing function for comments),
00069  * added Active Route selection, added route deletion.
00070  *
00071  * Revision 1.3  2004/11/11 18:41:03  mp
00072  * modified table handling, still problems with memory manager
00073  *
00074  * Revision 1.2  2004/06/23 18:36:09  mp
00075  * added debug output
00076  *
00077  * Revision 1.1  2004/04/29 19:25:58  mp
00078  * initial version
00079  *
00080  *
00081  ****************************************************************************/
00082 
00083 #define DO_NOT_ALLOW_ACCESS_TO_INTERNALS_OF_STRUCTS
00084 #include <BuildDefines.h>
00085 #ifdef DEBUG_BUILD
00086 #define ERROR_CHECK_LEVEL ERROR_CHECK_FULL
00087 #endif
00088 #include <PalmOS.h>
00089 #include <SerialMgrOld.h>
00090 #include "ResourceDefines.h"
00091 #include "gpslib.h"
00092 #include "RouteForm.h"
00093 #include "Data.h"
00094 #include "DataExchange.h"
00095 #include "Utils.h"
00096 #include "Serial.h"
00097 #include "utm.h"
00098 #include "geo.h"
00099 #include "fp.h"
00100 #include "common.h"
00101 
00102 /* Global Variables */
00103 extern PrefsType        gPrefs;                 /* application preferences */
00104 extern UInt32           gSerialPort;            /* serial port name/no. */
00105 
00106 ActRouteType            gSelRoute;              /**< selected route */
00107 
00108 /* Local Variables */
00109 static Int32            gRouteTopRow;           /* top table row */
00110 static UInt16           gRouteSel;              /* selected route (table) */
00111 static UInt16           nr_waypoints;           /* number of waypoints */
00112 static UInt16           nr_routes;              /* number of routes */
00113 
00114 
00115 /* Static Functions */
00116 static void RouteFormInit(FormPtr frmP)                 ROUTE_SECTION;
00117 static void RouteFormDeinit(FormPtr frmP)               ROUTE_SECTION;
00118 static void ChangePorts(void)                           ROUTE_SECTION;
00119 
00120 
00121 /*****************************************************************************
00122  * FUNCTION:    RouteFormInit
00123  *
00124  * DESCRIPTION: Route Form Init Function
00125  *
00126  ****************************************************************************/
00127 static void RouteFormInit(FormPtr frmP)
00128 {
00129 #pragma unused(frmP)
00130   // warning-- don't do any drawing in this routine.
00131   // Also, don't call FrmSetFocus from here (it must be called *after*
00132   // FrmDrawForm)
00133   
00134 }
00135 
00136 
00137 /*****************************************************************************
00138  * FUNCTION:    RouteFormDeinit
00139  *
00140  * DESCRIPTION: Route Form De-Init Function
00141  *
00142  ****************************************************************************/
00143 static void RouteFormDeinit(FormPtr frmP)
00144 {
00145 #pragma unused(frmP)
00146 
00147 }
00148 
00149 
00150 /*****************************************************************************
00151  * FUNCTION:    TableDrawCommentCell
00152  *
00153  * DESCRIPTION: Custom table cell drawing function for Route Number
00154  *              (max. 3 digits) and Route Comment (string, max. 20
00155  *              characters). The DB record number is retrieved via
00156  *              TblGetRowData().
00157  *
00158  * GLOBALS:     gRouteDB        -- route DB reference
00159  *
00160  * PARAMETERS:  Note: The function's prototype is defined by PalmOS
00161  *                    (TableDrawItemFuncType).
00162  *
00163  * RETURNED:    -
00164  ****************************************************************************/
00165 static void TableDrawCommentCell(void *tblP, Int16 row, Int16 column,
00166                    RectangleType *bounds)
00167 {
00168   Char                  str[21];                /* string buffer */
00169   MemHandle             routeDBEntry;           /* record handle */
00170   UInt16                rec;                    /* record index */
00171   route_t               *route;                 /* route */
00172   UInt32                routeID;                /* route ID (unique) */
00173   Int16                 cell_width;             /* table cell width in pixels */
00174   Boolean               fits;                   /* string fits in table cell */
00175   Int16                 length;                 /* string length */
00176   
00177   /* get record index from row data */
00178   rec = (UInt16)TblGetRowData(tblP, row);
00179   
00180   if (column == 0) {
00181     WinEraseRectangle(bounds, 0);
00182     
00183     /*
00184      * Set font to bold, because route items column (which is numeric, too)
00185      * uses it due to ItemStyle numericTableItem.
00186      */
00187     FntSetFont(boldFont);
00188 
00189     if (TblRowUsable(tblP, row)) {
00190       routeDBEntry = DmQueryRecord(gRouteDB, rec);
00191       route = (route_t *)MemHandleLock(routeDBEntry);
00192       MemSet((Char *)str, 21, 0);
00193       StrPrintF(str, "%3d", route->nmbr);
00194       MemHandleUnlock(routeDBEntry);
00195 
00196       WinDrawChars(str, StrLen(str), bounds->topLeft.x + 1, bounds->topLeft.y);
00197     }
00198     
00199   } else if (column == 1) {
00200     WinEraseRectangle(bounds, 0);
00201     
00202     if (TblRowUsable(tblP, row)) {
00203       routeDBEntry = DmQueryRecord(gRouteDB, rec);
00204 
00205       /* get unique Route ID */
00206       DmRecordInfo(gRouteDB, rec, NULL /* *attrP */,
00207         &routeID /* *uniqueIDP */, NULL /* *chunkIDP */);
00208 
00209       if (gPrefs.act_rte.valid && (routeID == gPrefs.act_rte.routeID)) {
00210         FntSetFont(boldFont);
00211       } else {
00212         FntSetFont(stdFont);
00213       }
00214 
00215       route = (route_t *)MemHandleLock(routeDBEntry);
00216       MemSet((Char *)str, 21, 0);
00217       StrNCopy(str, (Char *)route->cmnt, 20);
00218       MemHandleUnlock(routeDBEntry);
00219       
00220       /* truncate string to fit in table cell */
00221       length = StrLen(str);
00222       cell_width = bounds->extent.x;
00223       FntCharsInWidth(str, &cell_width, &length, &fits);
00224      
00225       WinDrawChars(str, length, bounds->topLeft.x + 1, bounds->topLeft.y);
00226     }
00227   }
00228 }
00229 
00230 
00231 /****************************************************************************/
00232 /**
00233  * \brief       Routes table drawing function
00234  *
00235  *****************************************************************************/
00236 void routeDrawTable(void)
00237 {
00238   TablePtr              tblP;                   /* table ptr */
00239   FormPtr               frmP;                   /* form ptr */
00240   ScrollBarPtr          sclP;                   /* scrollbar ptr */
00241   UInt16                top;                    /* table row counter */
00242   UInt16                row;                    /* table row counter */
00243   UInt16                rec;                    /* record nr */
00244   UInt16                max_rows;               /* total nr. of routes */
00245   UInt16                numRows;                /* number of visible rows */
00246   MemHandle             routeDBEntry;           /* record handle */
00247   route_t               *route;                 /* route */
00248   Err                   err;                    /* error code */
00249   
00250   frmP = FrmGetActiveForm();
00251   tblP = (TablePtr)GetObjectFromForm(frmP, RouteTable);
00252   top = gRouteTopRow;
00253   
00254   /* total number of routes */
00255   max_rows = DmNumRecordsInCategory(gRouteDB, dmAllCategories);
00256   
00257   /* number of visible rows */
00258   numRows = TblGetNumberOfRows(tblP);
00259 
00260   /* set columns usable */
00261   TblSetColumnUsable(tblP, 0, true);
00262   TblSetColumnUsable(tblP, 1, true);
00263   TblSetColumnUsable(tblP, 2, true);
00264       
00265   /* set row data to Route DB entries (record index) */
00266   for (row = 0; row < numRows; row++) {
00267 
00268     /* default: mark row as not usable (empty or no valid record) */
00269     TblSetRowUsable(tblP, row, true);
00270 
00271     if (row + top < max_rows) {
00272       /* seek from beginning of database */
00273       rec = 0;
00274       
00275       /* get next record */
00276       err = DmSeekRecordInCategory(gRouteDB, &rec /* index */,
00277         top + row /* offset */, dmSeekForward, dmAllCategories);
00278       
00279       if (err == errNone) {
00280         /* query record */
00281         routeDBEntry = DmQueryRecord(gRouteDB, rec);
00282 
00283         if (routeDBEntry) {
00284           /*
00285            * Record is valid, set row data to index and
00286            * mark table row as usable.
00287            */
00288           TblSetRowData(tblP, row, rec);
00289           TblSetRowUsable(tblP, row, true);
00290         }
00291       }
00292     } /*  if (row + top < max_rows) */
00293   } /* for (row = 0; row < numRows; row++) */  
00294   
00295   /* initialize table */
00296   for (row = 0; row < numRows; row++) {
00297     
00298     if (row + top < max_rows) {
00299       /* set all rows selectable */
00300       TblSetRowSelectable(tblP, row, true);
00301 
00302       /* get record index from row data */
00303       rec = TblGetRowData(tblP, row);
00304 
00305       /* get record */
00306       routeDBEntry = DmQueryRecord(gRouteDB, rec);
00307       
00308       /* lock record */
00309       route = (route_t *)MemHandleLock(routeDBEntry);
00310       
00311       /* set columns to custom style, set drawing functions */
00312       /*
00313        * route number
00314        *
00315        * Note:  ItemStyle customTableItem is used instead of
00316        *        numericTableItem, because otherwise
00317        *        TblSelectItem() does not work properly.
00318        */
00319       TblSetItemStyle(tblP, row, 0, customTableItem);    
00320       TblSetCustomDrawProcedure(tblP, 0, TableDrawCommentCell);
00321       
00322       /* route comment */
00323       TblSetItemStyle(tblP, row, 1, customTableItem);    
00324       TblSetCustomDrawProcedure(tblP, 1, TableDrawCommentCell);
00325 
00326       /* number of waypoints */
00327       TblSetItemStyle(tblP, row, 2, numericTableItem);    
00328       TblSetItemInt(tblP, row, 2, route->items);
00329       
00330       /* unlock record */
00331       MemHandleUnlock(routeDBEntry);
00332       
00333       /* mark row as usable */
00334       TblSetRowUsable(tblP, row, true);
00335       
00336       /* mark all rows as invalid to trigger table update by FrmDrawForm() */
00337       TblMarkRowInvalid(tblP, row);
00338     } else {
00339       /* rows empty, mark as not usable */
00340       TblSetRowUsable(tblP, row, false);
00341     }
00342   }
00343 
00344   sclP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, RouteScrl));
00345 
00346   /* set scrollbar: value, min, max, pagesize */
00347   if (max_rows <= numRows) {
00348     SclSetScrollBar(sclP, 0, 0, 0, numRows);
00349   } else {
00350     SclSetScrollBar(sclP, gRouteTopRow, 0, max_rows - numRows, numRows);
00351   }
00352   
00353   /*
00354    * Selected route scolled below visible table rows,
00355    *   selection is switched to last visible entry.
00356    */
00357   if ( gRouteSel > (gRouteTopRow + numRows - 1) ) {
00358     gRouteSel = gRouteTopRow + numRows - 1;
00359   }
00360 
00361   /*
00362    * Selected route scolled above visible table rows,
00363    *   selection is switched to first visible entry.
00364    */  
00365   if (gRouteSel < gRouteTopRow) {
00366     gRouteSel = gRouteTopRow;
00367   }
00368   
00369   for (row = 0; row < numRows; row++, top++) {
00370     if ((top < max_rows) && (top == gRouteSel)) {
00371       TblSelectItem(tblP, row, 0);
00372       break;
00373     }
00374   }
00375   
00376   FrmDrawForm(frmP);
00377 }
00378 
00379 
00380 /****************************************************************************/
00381 /**
00382  * \brief       Terminate Garmin mode, close host port and open GPS port.
00383  *
00384  * \note        This function could actually be called
00385  *              from RouteFormHandleEvent() upon reception of a
00386  *              frmCloseEvent. Unfortunately, when a Bluetooth GPS device
00387  *              is used and SrmOpen/SrmExtOpen opens the connection progress
00388  *              window, the frmOpenEvent queued by calling FrmGotoForm()
00389  *              previously seems to have been lost.
00390  *              As a (rather awkward) workaround, we have to call
00391  *              ChangePorts() _before_ FrmGotoForm() (scattered throughout
00392  *              RouteFormHandleEvent()).
00393  *
00394  ****************************************************************************/
00395 static void ChangePorts(void)
00396 {
00397   Err           err;            /* error code */
00398 
00399   /* Terminate Garmin mode and close serial port */
00400   GPSEndOfOperation();
00401 
00402   /*
00403    * open GPS port
00404    *
00405    * Note:      At this stage we have to cut corners. Even if the
00406    *            NewSerialManager is installed, we do not open the
00407    *            PortForm again to let the user select the connection
00408    *            profile. The error checking is also slightly simplified
00409    *          (because we have already checked that the serial port
00410    *          is available).
00411    */
00412   if (gNewSerialManager) {
00413 
00414     if (gSerialPort == sysFileCVirtRfComm) {
00415       /*
00416        * Bluetooth Virtual Serial Port --
00417        * Connect to known device (address)
00418        */
00419       err = BluetoothOpen(gSerialPort, gPrefs.serprefs.gps_baud,
00420         gPrefs.serprefs.gps_btaddr, &gPortID);
00421 
00422     } else {
00423       /* open non-BT serial port */
00424       err = SrmOpen(gSerialPort, gPrefs.serprefs.gps_baud, &gPortID);
00425     }
00426   } else {
00427     err = SerOpen(gPortID, 0, kBaudRate);
00428   }
00429 
00430   if (err) {
00431     EventType           event;                  /* event to queue */
00432 
00433     FrmAlert(CantOpenSerialAlert);
00434     event.eType = appStopEvent;
00435     EvtAddEventToQueue(&event);
00436   }
00437 }
00438 
00439 
00440 /****************************************************************************/
00441 /**
00442  * \brief       Route Form event handler
00443  *
00444  * \param       eventP          pointer to event structure
00445  *
00446  * \return      Status flag: event handled
00447  ****************************************************************************/
00448 Boolean RouteFormHandleEvent(EventPtr eventP)
00449 {
00450   Boolean               handled = false;        /* event handled flag */
00451   Err                   err;                    /* error */
00452   FormPtr               frmP;                   /* form ptr */
00453   FieldPtr              fldP;                   /* field ptr */
00454   TablePtr              tblP;                   /* table ptr */
00455   UInt16                rec;                    /* record index */
00456   MemHandle             routeDBEntry;           /* route record handle */
00457   route_t               *route;
00458 
00459   frmP = FrmGetActiveForm();
00460   tblP = (TablePtr)GetObjectFromForm(frmP, RouteTable);
00461         
00462   /* Number of Waypoints/Routes (could have been modified by download) */
00463   nr_waypoints = DmNumRecordsInCategory(gWaypointDB, dmAllCategories);
00464   nr_routes = DmNumRecordsInCategory(gRouteDB, dmAllCategories);
00465   
00466   switch (eventP->eType) {
00467   case frmOpenEvent:
00468     fldP = (FieldPtr)GetObjectFromActiveForm(RouteGpslibField);
00469     
00470     /* close serial port - Garmin uses 9600 baud */
00471     DoClose(gPortID);
00472     
00473     /* configure GPS4Palm to emulate Garmin III */
00474     GarminSetHostMode(fldP, GIII /* EmulatedGPS */);
00475     
00476     /* receive waypoints from host */
00477     GarminGetWpts(store_wpt, fldP);
00478     
00479     /* receive routes from host */
00480     GarminGetRtes(store_rte, fldP);
00481 
00482     /* receive tracks from host */
00483     GarminGetTrks(store_trk, fldP);
00484     
00485     frmP = FrmGetActiveForm();
00486     RouteFormInit(frmP);
00487     FrmDrawForm(frmP);
00488         
00489     /* draw the table */
00490     routeDrawTable();
00491 
00492     handled = true;
00493     break;
00494 
00495   case nilEvent:
00496     GpslibTicks();
00497     handled = true;
00498     break;
00499 
00500   case TransferWptReqEvent:
00501     /* gpslib - request to transfer waypoints to host*/
00502     fldP = (FieldPtr)GetObjectFromActiveForm(RouteGpslibField);
00503     GarminPutWpts(get_next_wpt, fldP, nr_waypoints);
00504     handled = true;
00505     break;
00506   
00507   case TransferRteReqEvent:
00508     /* gpslib - request to transfer routes to host */
00509     fldP = (FieldPtr)GetObjectFromActiveForm(RouteGpslibField);
00510     GarminPutRtes(get_next_rte, fldP, NumRtePackets());
00511     handled = true;
00512     break;
00513     
00514   case TransferTrkReqEvent:
00515     /* gpslib - request to transfer tracks */
00516     fldP = (FieldPtr)GetObjectFromActiveForm(WaypointGpslibField);
00517     GarminPutTrks(get_next_trk, fldP, NumTrkPackets());
00518     handled = true;
00519     break;
00520 
00521   case menuEvent:
00522     switch (eventP->data.menu.itemID) {
00523 
00524       case PositionMenu:
00525         ChangePorts();
00526         FrmGotoForm(GPSMainForm);
00527         handled = true;
00528         break;
00529 
00530       case SkyviewMenu:
00531         ChangePorts();
00532         FrmGotoForm(SkyviewForm);
00533         handled = true;
00534         break;
00535 
00536       case NavigationMenu:
00537         ChangePorts();
00538         FrmGotoForm(NavigationForm);
00539         handled = true;
00540         break;
00541 
00542       case MapMenu:
00543         ChangePorts();
00544         FrmGotoForm(MapForm);
00545         handled = true;
00546         break;
00547 
00548       case MiscOptsMenu:
00549         ChangePorts();
00550         FrmGotoForm(MiscOptsForm);
00551         handled = true;
00552         break;
00553 
00554       case MapOptsMenu:
00555         ChangePorts();
00556         FrmGotoForm(MapOptsForm);
00557         handled = true;
00558         break;
00559 
00560       case PortsMenu:
00561         if (gNewSerialManager) {
00562           ChangePorts();
00563           FrmGotoForm(GPSPortForm);
00564         }
00565         handled = true;
00566         break;
00567 
00568       case WaypointMenu:
00569         ChangePorts();
00570         FrmGotoForm(WaypointForm);
00571         handled = true;
00572         break;
00573 
00574       case TrackMenu:
00575         ChangePorts();
00576         FrmGotoForm(TrackForm);
00577         handled = true;
00578         break;
00579 
00580       case AboutMenu:
00581         ChangePorts();
00582         FrmGotoForm(AboutForm);
00583         handled = true;
00584         break;
00585 
00586     }
00587     break;  
00588 
00589   case tblSelectEvent:
00590     /* update table selection */
00591     gRouteSel = eventP->data.tblSelect.row + gRouteTopRow;
00592     
00593     /* always select column 0 */
00594     if (eventP->data.tblSelect.column != 0) {
00595       TblSelectItem(tblP, eventP->data.tblSelect.row, 0);
00596     }           
00597     handled = true;
00598     break;
00599   
00600   case sclRepeatEvent:
00601     /* handle scrollbar */
00602     Doscroll(RouteTable, RouteScrl, nr_routes, &gRouteTopRow);
00603     routeDrawTable();
00604     /* Note: scrollbar needs to handle the event, too */
00605     handled = false;
00606     break;
00607   
00608   case keyDownEvent:
00609     switch (eventP->data.keyDown.chr) {
00610     
00611     case pageUpChr:
00612     case pageDownChr:
00613       Dopage(RouteTable, (eventP->data.keyDown.chr == pageDownChr), nr_routes,
00614         &gRouteTopRow);
00615       routeDrawTable();
00616       /* Note: scrollbar needs to handle the event, too */
00617       handled = false;
00618       break;
00619     }
00620     break;
00621   
00622   case ctlSelectEvent:
00623     switch (eventP->data.ctlSelect.controlID) {
00624 
00625       case RouteDeleteButton:
00626         if (nr_routes == 0)
00627           break;
00628 
00629         if ( FrmAlert(RouteDelAlert) == 0 ) {     
00630           /* get record index from row data */
00631           rec = (UInt16)TblGetRowData(tblP, gRouteSel - gRouteTopRow);
00632           
00633           /*
00634            * Only data base backup, no synchronizing available.
00635            * This means a record can simply be deleted.
00636            */
00637           DmRemoveRecord(gRouteDB, rec);
00638 
00639           /* update number of records */
00640           nr_routes = DmNumRecordsInCategory(gRouteDB, dmAllCategories);
00641           
00642           /* redraw the table */
00643           gRouteTopRow = 0;
00644           gRouteSel = 0;
00645           routeDrawTable();
00646         }
00647         handled = true;
00648         break;
00649     
00650       case RouteNewButton:
00651         /* create new route */
00652         ChangePorts();
00653         FrmGotoForm(RouteEditForm);
00654         gSelRoute.valid = false;
00655         handled = true;
00656         break;
00657 
00658       case RouteEditButton:
00659         /* modify route */
00660         if (nr_routes == 0)
00661           break;
00662 
00663         /* get record index from row data */
00664         rec = (UInt16)TblGetRowData(tblP, gRouteSel - gRouteTopRow);
00665         
00666         /* get unique route ID */
00667         err = DmRecordInfo(gRouteDB, rec, NULL /* *attrP */,
00668           &gSelRoute.routeID /* *uniqueIDP */, NULL /* *chunkIDP */);
00669         
00670         /* mark selected waypoint as valid/invalid */
00671         gSelRoute.valid = (err == errNone) ? true : false;
00672 
00673         ChangePorts();
00674         FrmGotoForm(RouteEditForm);
00675         handled = true;
00676         break;
00677       
00678       case RouteSelectButton:
00679         if (nr_routes == 0)
00680           break;
00681         
00682 
00683         /* get record index from row data */
00684         rec = (UInt16)TblGetRowData(tblP, gRouteSel - gRouteTopRow);
00685         
00686         /* get unique Route ID */
00687         err = DmRecordInfo(gRouteDB, rec, NULL /* *attrP */,
00688           &gPrefs.act_rte.routeID /* *uniqueIDP */, NULL /* *chunkIDP */);
00689         
00690         /* mark active route as valid/invalid */
00691         gPrefs.act_rte.valid = (err == errNone) ? true : false;
00692         
00693         /* start with first waypoint on route */
00694         gPrefs.act_rte.wpt_index = 0;
00695                     /* get active route */
00696         
00697         err = DmFindRecordByID(gRouteDB, gPrefs.act_rte.routeID,
00698           &rec);
00699 
00700         if (!err) {
00701           /* active route found */
00702           routeDBEntry = DmQueryRecord(gRouteDB, rec);
00703 
00704           /* lock record */
00705           route = (route_t *)MemHandleLock(routeDBEntry);
00706 
00707           /* an active route must contain at least two waypoints */
00708           if (route->items > 1) {
00709             gPrefs.act_wpt.waypointID = 
00710               route->wpt_rec_id[gPrefs.act_rte.wpt_index];
00711             gPrefs.act_wpt.valid = true;
00712           
00713           } else {
00714             gPrefs.act_rte.valid = false;
00715             gPrefs.act_wpt.valid = false;
00716           }
00717           
00718           /* unlock route record */
00719           MemHandleUnlock(routeDBEntry);
00720           
00721           /* initialize auto waypoint selection */
00722           UpdateActWpt(0.0 /* dummy */, 0.0 /* dummy */, true /* init */);
00723                   
00724           /* mark row as invalid to trigger table update by FrmDrawForm() */
00725           TblMarkRowInvalid(tblP, gRouteSel - gRouteTopRow );
00726           FrmDrawForm(frmP);
00727         
00728         } else {
00729           gPrefs.act_wpt.valid = false;
00730         }
00731 
00732         handled = true;
00733         break;
00734     }
00735     break;
00736 
00737   case frmCloseEvent:
00738     if (gPrefs.act_rte.valid) {
00739       /* check if active route still exists, mark as invalid if not */
00740       err = DmFindRecordByID(gRouteDB, gPrefs.act_rte.routeID, &rec);
00741       gPrefs.act_rte.valid = (err) ? false : true;
00742     }
00743 
00744     SetFieldText(RouteGpslibField, NULL, false, true);
00745 
00746     RouteFormDeinit(FrmGetActiveForm());
00747     handled = false;
00748     break;
00749 
00750   default:
00751     break;
00752   }
00753   
00754   return handled;
00755 }

Created: Mon, 08 Oct 2007 22:33:16 +0200
Copyright ©2004 M. Prinke