00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <PalmOS.h>
00030 #include <PalmCompatibility.h>
00031 #include "gtalkRsc.h"
00032 #include "gpslib.h"
00033 #include "gtalk.h"
00034 #include "route.h"
00035 #include "gpsutil.h"
00036 #include "log.h"
00037 #include "dbio.h"
00038 #include "map.h"
00039 #include "ExgMgr.h"
00040
00041
00042 static void RouteListDraw (Int16 itemNum, RectanglePtr bounds, CharPtr * itemsText) ROUTE_SECTION;
00043 double LengthOfRoute (int index, Boolean exceptlast) ROUTE_SECTION;
00044
00045 #define LastWptName "TOTAL:"
00046
00047 static Boolean uneditable;
00048
00049
00059 Err
00060 EditRouteRecord (UInt recindex, UInt objindex, Object * objp)
00061 {
00062 VoidHand RouteRecH;
00063 VoidPtr RecP = NULL,
00064 p;
00065 ULong l,
00066 cut,
00067 s;
00068 UInt n;
00069 Err error = 0;
00070
00071
00072 debug_in (GTALKDBG_CALLS, ("->EditRouteRecord(recindex=%d,objindex=%d)", recindex, objindex));
00073
00074 if (recindex >= DmNumRecords (RteDB))
00075 return (dmErrIndexOutOfRange);
00076 if (!(RouteRecH = DmGetRecord (RteDB, recindex)))
00077 return (DmGetLastErr ());
00078 s = MemHandleSize (RouteRecH);
00079 n = ObjectsInRec (RouteRecH);
00080 l = OffsetOfObjectInRec (RouteRecH, objindex);
00081 if ((objp == NULL) && (objindex < n))
00082 {
00083 RecP = MemHandleLock (RouteRecH);
00084 cut = SizeOfObject ((Object *) (RecP + l));
00085 error = DmWrite (RecP, l, RecP + l + cut, s - l - cut);
00086 MemHandleUnlock (RouteRecH);
00087 RouteRecH = DmResizeRecord (RteDB, recindex, s - cut);
00088 }
00089
00090 else if ((objp != NULL) && (objindex <= n))
00091 {
00092 RouteRecH = DmResizeRecord (RteDB, recindex, s + SizeOfObject (objp));
00093 RecP = MemHandleLock (RouteRecH);
00094 p = MemPtrNew (s - l);
00095 if (p)
00096 {
00097 (void) MemMove (p, RecP + l, s - l);
00098 error = DmWrite (RecP, l + SizeOfObject (objp), p, s - l);
00099 MemPtrFree (p);
00100 }
00101 error = DmWrite (RecP, l, objp, SizeOfObject (objp));
00102 MemHandleUnlock (RouteRecH);
00103 }
00104 DmReleaseRecord (RteDB, recindex, true);
00105 debug_out (GTALKDBG_CALLS, ("<-EditRouteRecord returns %d", error));
00106 return (error);
00107 }
00108
00109
00110 #ifndef GRAPHICALROUTEEDIT
00111 static void WptDraw (Int16 itemNum, RectanglePtr bounds, CharPtr * itemsText);
00112
00122 static void
00123 WptDraw (Int16 itemNum, RectanglePtr bounds, CharPtr * itemsText)
00124 {
00125 UInt i;
00126 Custom_Wpt_Type wpt;
00127
00128 i = 0;
00129 DmSeekRecordInCategory (WptDB, &i, itemNum, dmSeekForward, Prefs.wptcategory);
00130 IndexToCustomWpt (i, WptDB, &wpt);
00131 DrawCharsInWidth (wpt.ident, bounds->topLeft.x + 0, bounds->topLeft.y, bounds->extent.x - 5, 0);
00132 }
00133
00134
00143 Boolean
00144 RteEditFormHandleEvent (EventPtr e)
00145 {
00146 Boolean handled = false;
00147 FormPtr frm;
00148 static ListPtr WptLstPtr,
00149 RteLstPtr;
00150 UInt RecordsNumber,
00151 i,
00152 modified;
00153 static UInt RteRecIndex;
00154 static UInt OldToDisplay,
00155 OldCurrentIndex;
00156 static int PrevLstSel,
00157 PrevWptSel;
00158 VoidHand RecH;
00159 static VoidHand RouteRecH;
00160 static Boolean changed;
00161 VoidPtr RecP;
00162 FieldPtr FdPtr;
00163 char buf[16];
00164
00165 static Custom_Rte_Hdr_Type RteHdr;
00166 Object obj;
00167 Raw_D103_Wpt_Type RteWpt;
00168
00169 RectangleType r;
00170 Err error;
00171 char CategoryName[dmCategoryLength];
00172
00173 debug_in (GTALKDBG_CALLS, ("->RteEditFormHandleEvent(event %d)", (int) (e->eType)));
00174 switch (e->eType)
00175 {
00176 case frmOpenEvent:
00177 frm = FrmGetActiveForm ();
00178 handled = true;
00179 OldToDisplay = Prefs.todisplay;
00180 RecordsNumber = DmNumRecordsInCategory (WptDB, Prefs.wptcategory);
00181 WptLstPtr = (ListPtr) (GetObjPtr (RteEditWptLstID));
00182 LstSetListChoices (WptLstPtr, NULL, RecordsNumber);
00183 LstSetDrawFunction (WptLstPtr, &WptDraw);
00184 LstSetSelection (WptLstPtr, -1);
00185 CategoryGetName (WptDB, Prefs.wptcategory, CategoryName);
00186
00187 CategorySetTriggerLabel (GetObjPtr (RtEditWptPopupID), CategoryName);
00188 RteLstPtr = (ListPtr) (GetObjPtr (RteEditRteLstID));
00189
00190 OldCurrentIndex = CurrentRecordIndex;
00191 error=CopyOrCreateRoute(&RteHdr,CurrentRecordIndex,(EditMode == NewWpt));
00192 if (error) {
00193 FrmReturnToForm (0);
00194 break;
00195 }
00196 StrNToField (RteHdr.cmnt, StrLen (RteHdr.cmnt), RtEditCmntID);
00197 StrIToA (buf, RteHdr.nmbr);
00198 StrNToField (buf, StrLen (buf), RtEditNmbrID);
00199 (void) MemMove (RteWpt.ident, LastWptName, sizeof (RteWpt.ident));
00200 MemSet (RteWpt.cmnt, sizeof (RteWpt.cmnt), ' ');
00201 error = put_rte ((GarminObject *) & RteWpt, 0, 1, G103Type, sizeof (RteWpt));
00202 if (error) {
00203 FrmReturnToForm (0);
00204 break;
00205 }
00206 RteRecIndex = DmNumRecords (RteDB) - 1;
00207 CurrentRecordIndex = RteRecIndex;
00208 RouteRecH = DmQueryRecord (RteDB, RteRecIndex);
00209 if (!RouteRecH){
00210 FrmReturnToForm (0);
00211 break;
00212 }
00213 LstSetListChoices (RteLstPtr, NULL, WptsInRteDB (RouteRecH));
00214 LstSetDrawFunction (RteLstPtr, &RouteListDraw);
00215 LstSetSelection (RteLstPtr, -1);
00216 changed = 0;
00217 FrmDrawForm (frm);
00218 break;
00219
00220 case frmCloseEvent:
00221 if (RteLstPtr != NULL)
00222 DmRemoveRecord (RteDB, RteRecIndex);
00223
00224 Prefs.todisplay = OldToDisplay;
00225 break;
00226
00227 case penDownEvent:
00228 frm = FrmGetActiveForm ();
00229 GetObjectBounds (TrashBMID, &r);
00230
00231 if (RctPtInRectangle (e->screenX, e->screenY, &r)
00232 && ((int) LstGetSelection (RteLstPtr) >= 0))
00233 {
00234 WinInvertRectangle (&r, 0);
00235 SndPlaySystemSound (sndInfo);
00236 SysTaskDelay (sysTicksPerSecond / 5);
00237 WinInvertRectangle (&r, 0);
00238 if (LstGetSelection (RteLstPtr) < (WptsInRteDB (RouteRecH) - 1))
00239 {
00240 EditRouteRecord (RteRecIndex, LstGetSelection (RteLstPtr) + 1, NULL);
00241 changed = 1;
00242 }
00243 else
00244 SndPlaySystemSound (sndError);
00245 LstSetListChoices (RteLstPtr, NULL, WptsInRteDB (RouteRecH));
00246 LstSetSelection (RteLstPtr, -1);
00247 LstDrawList (RteLstPtr);
00248 handled = true;
00249 }
00250 break;
00251
00252 case lstSelectEvent:
00253 if (e->data.lstSelect.listID == RteEditRteLstID)
00254 {
00255 if ((int) LstGetSelection (WptLstPtr) >= 0)
00256 {
00257 i = 0;
00258 DmSeekRecordInCategory (WptDB, &i, LstGetSelection (WptLstPtr), dmSeekForward,
00259 Prefs.wptcategory);
00260 RecH = DmQueryRecord (WptDB, i);
00261 if (RecH)
00262 {
00263 Object *objp = MemHandleLock (RecH);
00264 EditRouteRecord (RteRecIndex, LstGetSelection (RteLstPtr) + 1, objp);
00265 changed = 1;
00266 MemHandleUnlock (RecH);
00267 LstSetListChoices (RteLstPtr, NULL, WptsInRteDB (RouteRecH));
00268 LstMakeItemVisible (RteLstPtr, LstGetSelection (RteLstPtr) + 1);
00269 LstDrawList (RteLstPtr);
00270 }
00271 LstSetSelection (WptLstPtr, -1);
00272 LstSetSelection (RteLstPtr, -1);
00273 }
00274 }
00275 else
00276 {
00277 if (LstGetSelection (WptLstPtr) == PrevWptSel)
00278 LstSetSelection (WptLstPtr, -1);
00279 LstSetSelection (RteLstPtr, -1);
00280 }
00281 PrevWptSel = LstGetSelection (WptLstPtr);
00282 PrevLstSel = LstGetSelection (RteLstPtr);
00283 handled = true;
00284 break;
00285
00286 case menuEvent:
00287 MenuEraseStatus (NULL);
00288
00289 switch (e->data.menu.itemID)
00290 {
00291 }
00292
00293 handled = true;
00294 break;
00295
00296 case ctlSelectEvent:
00297 switch (e->data.ctlSelect.controlID)
00298 {
00299 case RtEditWptPopupID:
00300 frm = FrmGetActiveForm ();
00301 CategorySelect (WptDB, frm, RtEditWptPopupID, RtEditWptListID, true,
00302 (WordPtr) & Prefs.wptcategory, CategoryName, 1, 0);
00303 RecordsNumber = DmNumRecordsInCategory (WptDB, Prefs.wptcategory);
00304 LstSetListChoices (WptLstPtr, NULL, RecordsNumber);
00305 LstDrawList (WptLstPtr);
00306 break;
00307
00308 case RteEditBtOKID:
00309 debug (GTALKDBG_INFOS,
00310 ("RteEditFormHandleEvent, OK hit, objects in record=%d",
00311 ObjectsInRec (RouteRecH)));
00312 EditRouteRecord (RteRecIndex, WptsInRteDB (RouteRecH), NULL);
00313 MainListDirty = 1;
00314 modified = 0;
00315 FdPtr = (FieldPtr) (GetObjPtr (RtEditCmntID));
00316 if (FldDirty (FdPtr))
00317 {
00318 i = StrLen (FldGetTextPtr (FdPtr));
00319 StrNCopySafe (RteHdr.cmnt, FldGetTextPtr (FdPtr), sizeof (RteHdr.cmnt));
00320 Canonicalize (RteHdr.cmnt, StrLen (RteHdr.cmnt));
00321 modified = 1;
00322 }
00323 FdPtr = GetObjPtr (RtEditNmbrID);
00324 if (FldDirty (FdPtr))
00325 {
00326 RteHdr.nmbr = StrAToI (FldGetTextPtr (FdPtr));
00327 modified = 1;
00328 }
00329 if (modified)
00330 {
00331 EditRouteRecord (RteRecIndex, 0, NULL);
00332 CustomToRteHdrObj (&RteHdr, &obj, G201Type);
00333 debug (GTALKDBG_INFOS,
00334 ("RteEditFormHandleEvent, put header : nmbr=%d, cmnt=%s", RteHdr.nmbr,
00335 RteHdr.cmnt));
00336
00337 error = EditRouteRecord (RteRecIndex, 0, &obj);
00338 }
00339 debug (GTALKDBG_INFOS, ("RteEditFormHandleEvent, before remove, objects in record=%d",
00340 ObjectsInRec (RouteRecH)));
00341
00342 if (EditMode == EditWpt)
00343 {
00344 DmRemoveRecord (RteDB, OldCurrentIndex);
00345 }
00346 RteLstPtr = NULL;
00347 FrmReturnToForm (0);
00348 break;
00349
00350 case RteEditBtCancelID:
00351 DmRemoveRecord (RteDB, RteRecIndex);
00352 RteLstPtr = NULL;
00353 FrmReturnToForm (0);
00354 break;
00355 }
00356 handled = true;
00357 break;
00358
00359 default:
00360 break;
00361 }
00362 debug_out (GTALKDBG_CALLS, ("<-RteEditFormHandleEvent"));
00363
00364 return handled;
00365 }
00366 #endif
00367
00368
00369 #define XName 0
00370 #define XDist 82
00371 #define XBear 110
00372
00373
00383 static void
00384 RouteListDraw (Int16 itemNum, RectanglePtr bounds, CharPtr * itemsText)
00385 {
00386 VoidHand RecH = NULL;
00387 void *RecP;
00388 static Semicircle_Type last_pt;
00389 double d;
00390 char buf[32];
00391 unsigned int l,
00392 bearing;
00393 Custom_Wpt_Type wpt,
00394 prevp;
00395 LocalFormatID fmt;
00396
00397 debug_in (GTALKDBG_CALLS, ("->RouteListDraw(itemnum=%d)", (int) itemNum));
00398 RecH = DmQueryRecord (RteDB, CurrentRecordIndex);
00399 if (RecH) {
00400 RecP = MemHandleLock (RecH);
00401 fmt = PtrToCustomWpt ((Object *) (RecP + OffsetOfObjectInRec (RecH, itemNum + 1)), &wpt);
00402 if (fmt) {
00403 RectangleType lbounds,origclip;
00404
00405 RctCopyRectangle (bounds,&lbounds );
00406 #if 0
00407 if (lbounds.topLeft.y>=10){
00408 lbounds.topLeft.y-=10;
00409 lbounds.extent.y+=10;
00410 lbounds.extent.x-=8;
00411 }
00412 #endif
00413 WinGetClip(&origclip);
00414 WinSetClip (&lbounds);
00415 WinDrawChars (wpt.ident, StrLen (wpt.ident), bounds->topLeft.x + XName,
00416 bounds->topLeft.y);
00417 if (StrCompare (wpt.ident, LastWptName))
00418 if (itemNum != 0) {
00419 fmt = PtrToCustomWpt ((Object *) (RecP +
00420 OffsetOfObjectInRec (RecH, itemNum)), &prevp);
00421 if (fmt)
00422 {
00423 last_pt.lat = prevp.posn.lat;
00424 last_pt.lon = prevp.posn.lon;
00425 d = Distance (last_pt.lat, last_pt.lon, wpt.posn.lat, wpt.posn.lon,
00426 Prefs.distunit);
00427 bearing =
00428 Bearing (last_pt.lat, last_pt.lon, wpt.posn.lat, wpt.posn.lon);
00429 l = StrPrintF (buf, "%s %s", DToA (d, 0, 2),
00430 DistanceUnitNames[Prefs.distunit]);
00431 WinDrawChars (buf, StrLen (buf),
00432 bounds->topLeft.x + XDist - FntCharsWidth (buf, l),
00433 #if 0
00434 bounds->topLeft.y - bounds->extent.y / 2);
00435 #else
00436 bounds->topLeft.y);
00437 #endif
00438 if (bounds->extent.x > XBear)
00439 {
00440 l = StrPrintF (buf, "%d°", bearing);
00441 WinDrawChars (buf, StrLen (buf),
00442 bounds->topLeft.x + XBear - FntCharsWidth (buf,
00443 l),
00444 #if 0
00445 bounds->topLeft.y - bounds->extent.y / 2);
00446 #else
00447 bounds->topLeft.y);
00448 #endif
00449 }
00450 }
00451 }
00452 else;
00453 else
00454 {
00455 l = StrPrintF (buf, "%s %s",
00456 DToA (LengthOfRoute (CurrentRecordIndex, 1), 0, 2),
00457 DistanceUnitNames[Prefs.distunit]);
00458 WinDrawChars (buf, StrLen (buf),
00459 bounds->topLeft.x + XDist - FntCharsWidth (buf, l),
00460 bounds->topLeft.y);
00461 }
00462 WinSetClip(&origclip);
00463 }
00464 else
00465 {
00466 WinDrawChars ("*", 4, bounds->topLeft.x + XName, bounds->topLeft.y);
00467 uneditable = 1;
00468 }
00469 MemHandleUnlock (RecH);
00470 }
00471 debug_out (GTALKDBG_CALLS, ("<-RouteListDraw"));
00472 }
00473
00474
00482 Boolean
00483 RouteFormHandleEvent (EventPtr e)
00484 {
00485 Boolean Edited,
00486 handled = false;
00487 static FormPtr frm;
00488 static Custom_Rte_Hdr_Type RteHdr;
00489 ListPtr LstPtr;
00490 static VoidHand CurrentRouteRecH;
00491 char buf[48];
00492 UInt category,
00493 l,
00494 attributes;
00495 static UInt MyCategory;
00496 Err error;
00497 char CategoryName[dmCategoryLength];
00498 #ifdef GRAPHICALROUTEEDIT
00499 FieldPtr FdPtr;
00500 Object obj;
00501 Boolean modified;
00502 #endif
00503
00504 switch (e->eType)
00505 {
00506 case frmOpenEvent:
00507 frm = FrmGetActiveForm ();
00508 uneditable = 0;
00509 CurrentRouteRecH = DmQueryRecord (RteDB, CurrentRecordIndex);
00510 if (!CurrentRouteRecH)
00511 {
00512 FrmReturnToForm (0);
00513 handled = true;
00514 break;
00515 }
00516 HandleToCustomRteHdr (CurrentRouteRecH, &RteHdr);
00517
00518
00519 LstPtr = (ListPtr) (GetObjPtr (RouteListID));
00520 LstSetListChoices (LstPtr, NULL, WptsInRteDB (CurrentRouteRecH));
00521 LstSetSelection (LstPtr, -1);
00522 LstSetDrawFunction (LstPtr, &RouteListDraw);
00523
00524 error = DmRecordInfo (RteDB, CurrentRecordIndex, &attributes, NULL, NULL);
00525 MyCategory = attributes & dmRecAttrCategoryMask;
00526 CategoryGetName (RteDB, MyCategory, CategoryName);
00527 CategorySetTriggerLabel (GetObjPtr (RteCatPopupID), CategoryName);
00528 #ifdef GRAPHICALROUTEEDIT
00529 StrIToA (buf, RteHdr.nmbr);
00530 StrNToField (buf, StrLen (buf), RteNumID);
00531 StrNToField (RteHdr.cmnt, StrLen (RteHdr.cmnt), RteCmntID);
00532 #else
00533 HideObject(RteNumID);
00534 HideObject(RteCmntID);
00535 #endif
00536 l = StrPrintF (buf, "%d waypoints, total : %s %s",
00537 (int) (WptsInRteDB (CurrentRouteRecH)),
00538 DToA (LengthOfRoute (CurrentRecordIndex, 0), 0, 2),
00539 DistanceUnitNames[Prefs.distunit]);
00540 StrNToField (buf, l, RteStatFDID);
00541 FrmDrawForm (frm);
00542 handled = true;
00543 break;
00544
00545 case menuEvent:
00546 MenuEraseStatus (NULL);
00547 switch (e->data.menu.itemID)
00548 {
00549 }
00550 handled = true;
00551 break;
00552
00553 case lstSelectEvent:
00554 LstSetSelection (e->data.lstSelect.pList, -1);
00555 #if 0
00556 GetObjectBounds (RouteListID, &DrawRect);
00557
00558 LstEraseList (e->data.lstSelect.pList);
00559 DrawRoute (CurrentRecordIndex, 1, NULL);
00560 #else
00561 MapFlags.DrawRtes = 1;
00562 MapFlags.AllowedOps = MapOpActiveRte;
00563 FrmPopupForm (MapForm);
00564 #endif
00565 handled = true;
00566 break;
00567
00568 case keyDownEvent:
00569
00570 LstPtr = (ListPtr) (GetObjPtr (RouteListID));
00571 if (e->data.keyDown.chr == pageUpChr)
00572 LstScrollList (LstPtr, winUp, LstGetVisibleItems (LstPtr) - 1);
00573 else if (e->data.keyDown.chr == pageDownChr)
00574 LstScrollList (LstPtr, winDown, LstGetVisibleItems (LstPtr) - 1);
00575 break;
00576
00577 case ctlSelectEvent:
00578 switch (e->data.ctlSelect.controlID)
00579 {
00580 case RteBtOKID:
00581 #ifdef GRAPHICALROUTEEDIT
00582 MainListDirty = 1;
00583 modified = 0;
00584 FdPtr = (FieldPtr) (GetObjPtr (RteCmntID));
00585 if (FldDirty (FdPtr))
00586 {
00587
00588 StrNCopySafe (RteHdr.cmnt, FldGetTextPtr (FdPtr), sizeof (RteHdr.cmnt));
00589 Canonicalize (RteHdr.cmnt, StrLen (RteHdr.cmnt));
00590 modified = 1;
00591 }
00592 FdPtr = GetObjPtr (RteNumID);
00593 if (FldDirty (FdPtr))
00594 {
00595 RteHdr.nmbr = StrAToI (FldGetTextPtr (FdPtr));
00596 modified = 1;
00597 }
00598 if (modified)
00599 {
00600 EditRouteRecord (CurrentRecordIndex, 0, NULL);
00601 CustomToRteHdrObj (&RteHdr, &obj, G201Type);
00602 error = EditRouteRecord (CurrentRecordIndex, 0, &obj);
00603 }
00604 #endif
00605
00606 FrmReturnToForm (0);
00607 handled = true;
00608 break;
00609
00610 case RteButEditID:
00611 EditMode = EditWpt;
00612 if (uneditable)
00613 FrmCustomAlert (ErrorID, "Can't edit that kind of route", " ", " ");
00614 else
00615 {
00616 #ifdef GRAPHICALROUTEEDIT
00617 MapFlags.DrawRtes = 1;
00618 MapFlags.AllowedOps = MapOpRteEdit | MapOpWptDisp;
00619 FrmPopupForm (MapForm);
00620 #else
00621 FrmGotoForm (EditRouteForm);
00622 #endif
00623 }
00624 handled = true;
00625 break;
00626
00627 case RteBtDeleteID:
00628 if (FrmCustomAlert (ConfID, "Remove route", " ?", " "))
00629 {
00630 DmRemoveRecord (RteDB, CurrentRecordIndex);
00631
00632 MainListDirty = 1;
00633 FrmReturnToForm (0);
00634 }
00635 handled = true;
00636 break;
00637 #ifdef BEAM
00638 case RteBtBeamID:
00639 {
00640 ExgSocketType sock;
00641 RecordSeparator RecSep;
00642 void *RecP;
00643 ULong len;
00644
00645 if (!CurrentRouteRecH) break;
00646 RecP = MemHandleLock (CurrentRouteRecH);;
00647 MemSet (&sock, sizeof (sock), 0);
00648 sock.target = GPilotSID;
00649 sock.count = 1;
00650 sock.length = MemHandleSize (CurrentRouteRecH);
00651 sock.appData = DispRte;
00652 sock.time = DispRte;
00653 sock.description = "Route";
00654 sock.name = BeamTypes[DispRte];
00655 sock.localMode=1;
00656 RecSep.length = MemHandleSize (CurrentRouteRecH);
00657 RecSep.reserved = 0;
00658
00659 error = ExgPut (&sock);
00660 if (!error)
00661 {
00662 len=ExgSend (&sock, &RecSep, sizeof (RecSep), &error);
00663 len=0;
00664 while (!error && len < MemHandleSize (CurrentRouteRecH)){
00665 len+=ExgSend (&sock, RecP, MemHandleSize (CurrentRouteRecH), &error);
00666 }
00667 error=ExgDisconnect (&sock, error);
00668 }
00669 else SndPlaySystemSound(sndError);
00670 MemHandleUnlock (CurrentRouteRecH);
00671 }
00672 handled = true;
00673 break;
00674 #endif
00675 case RteCatPopupID:
00676
00677 category = MyCategory;
00678 Edited =
00679 CategorySelect (RteDB, frm, RteCatPopupID, RteCatListID, false, &MyCategory,
00680 CtlGetLabel (e->data.ctlSelect.pControl), 1, 0);
00681 if ((MyCategory != category) && (CurrentRecordIndex != dmMaxRecordIndex))
00682 {
00683 error = SetCategory (RteDB, CurrentRecordIndex, MyCategory);
00684 MainListDirty = 1;
00685 }
00686 handled = true;
00687 break;
00688 }
00689 break;
00690
00691 default:
00692 break;
00693 }
00694
00695 return handled;
00696 }
00697
00698
00707 double
00708 LengthOfRoute (int index, Boolean exceptlast)
00709 {
00710 VoidHand RecH = NULL;
00711 void *RecP;
00712 int n,
00713 i;
00714 unsigned long lat,
00715 lon;
00716 double dist = 0.;
00717 Custom_Wpt_Type wpt;
00718
00719 RecH = DmQueryRecord (RteDB, index);
00720 if (RecH)
00721 {
00722 n = (WptsInRteDB (RecH)) - exceptlast;
00723 if (n >= 2)
00724 {
00725 RecP = MemHandleLock (RecH);
00726 PtrToCustomWpt ((Object *) (RecP + SizeOfObject ((Object *) RecP)), &wpt);
00727 lat = wpt.posn.lat;
00728 lon = wpt.posn.lon;
00729 for (i = 1; i < n; i++)
00730 {
00731 PtrToCustomWpt ((Object *) (RecP + OffsetOfObjectInRec (RecH, i + 1)), &wpt);
00732 dist += Distance (lat, lon, wpt.posn.lat, wpt.posn.lon, Prefs.distunit);
00733 lat = wpt.posn.lat;
00734 lon = wpt.posn.lon;
00735 }
00736 MemHandleUnlock (RecH);
00737 }
00738 }
00739 return (dist);
00740 }
00741
00742
00749 UInt
00750 NewRouteNumber ()
00751 {
00752 Boolean found;
00753 UInt i,
00754 j;
00755 VoidHand RecH;
00756 Custom_Rte_Hdr_Type RteHdr;
00757
00758 for (i = 1; i <= 99; i++)
00759 {
00760 found = 1;
00761 j = 0;
00762 while ((RecH = DmQueryNextInCategory (RteDB, &j, Prefs.rtecategory)))
00763 {
00764 HandleToCustomRteHdr (RecH, &RteHdr);
00765 if (RteHdr.nmbr == i)
00766 found = 0;
00767 j++;
00768 }
00769 if (found)
00770 return (i);
00771 }
00772 return (i);
00773 }
00774
00775
00785 Err CopyOrCreateRoute (Custom_Rte_Hdr_Type * RteHdrp, UInt16 index, Boolean new)
00786 {
00787 VoidHand RouteRecH;
00788 Err error=0;
00789
00790 if (new) {
00791 RteHdrp->nmbr = NewRouteNumber ();
00792 RteHdrp->cmnt[0] = 0;
00793 error = put_rte ((GarminObject *) RteHdrp, 0, 1, CustomRteHdr, sizeof (Custom_Rte_Hdr_Type));
00794 }
00795
00796 else {
00797 RouteRecH = DmQueryRecord (RteDB, index);
00798 if (RouteRecH) {
00799 Object *p;
00800 VoidPtr RecP;
00801 RecP = MemHandleLock (RouteRecH);
00802 for (p = RecP; p < (Object *) (RecP + MemHandleSize (RouteRecH));
00803 p = (void *) p + SizeOfObject (p)) {
00804 if (p == RecP) {
00805 if (PtrToCustomRteHdr (RecP, RteHdrp) != Unknown)
00806 error = put_rte ((GarminObject *) RteHdrp, 0, 1, CustomRteHdr, sizeof (Custom_Rte_Hdr_Type));
00807 else error=-1;
00808 }
00809 else error = put_rte (&(p->d.g), 0, 1, p->header.type, p->header.size);
00810 if (error) break;
00811 }
00812 MemHandleUnlock (RouteRecH);
00813 }
00814 else error=-2;
00815 }
00816 return(error);
00817 }
00818
00819 void SearchWptInRoutes(void){
00820 }