Main Page | File List | Globals | Related Pages

editwpt.c

Go to the documentation of this file.
00001 
00008 // $Id: editwpt.c,v 1.27 2004/01/02 20:38:23 clavelei Exp clavelei $ 
00009 
00010 
00011 #ifndef SKIPEDIT
00012 
00013 #include <PalmOS.h>
00014 #include <PalmCompatibility.h>
00015 #include <Graffiti.h>
00016 #include <string.h>
00017 #include "gtalkRsc.h"
00018 #include "latlong.h"
00019 #include "MathLib.h"
00020 #include <stdio.h>
00021 #include "gpslib.h"
00022 #include "gtalk.h"
00023 #include "gpsutil.h"
00024 #include "dbio.h"
00025 
00026 
00027 static char LatButtonsValues[12][2];   /* contenu des bouton statiques de latitude */
00028 static char LonButtonsValues[13][2];   /* contenu des bouton statiques de longitude */
00029 static const char *ListChoices[] =
00030     { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "N", "S", "W", "E" };
00031 static char LatMask[3][13] = {         /* masque d'utilisation des boutons (attention à la cohérence) */
00032     "00°60.000'N",                     /* DMM */
00033     "00°60'60.0\"N",                   /* DMS */
00034     "00.00000°N"                       /* DDD */
00035 };
00036 static char LonMask[3][14] = {
00037     "200°60.000'W",                    /* DMM */
00038     "200°60'60.0\"W",                  /* DMS */
00039     "200.00000°W"                      /* DDD */
00040 };
00041 static const char * LocalId2String []={"Unkn", "D100","D101", "D102", "D103", "D104", "D105", "D106", "D107", "D108", "", "", "", "", "", "", "", "", "", "", "D109"};
00042 
00043 static void EditListDraw (Int16 itemNum, RectanglePtr bounds, CharPtr * itemsText) EDIT_SECTION;
00044 static void updateLatButtons (double latitude) EDIT_SECTION;
00045 static void updateLonButtons (double longitude) EDIT_SECTION;
00046 static void DegreToButtons (double latitude, double longitude) EDIT_SECTION;
00047 static double ReadLon (void) EDIT_SECTION;
00048 static double ReadLat (void) EDIT_SECTION;
00049 static void SetButtons (int firstbutton, char *maskp, char *datas, char label[][2]) EDIT_SECTION;
00050 static Err CustomToDBWpt (Custom_Wpt_Type * pcust, LocalFormatID format, long index, Boolean merge) EDIT_SECTION;
00051 
00052 static Boolean changed = 0,
00053   ReducedSymbolsSet;
00054 
00055 
00062 static double
00063 ReadLon ()
00064 {
00065     int butind,
00066       i;
00067     char lon[14];
00068     Boolean b;
00069     ControlPtr butptr;
00070 
00071     for (i = 0, butind = EditCoordButLon0; butind <= EditCoordButLonEW; butind++, i++)
00072     {
00073         butptr = (ControlPtr) GetObjPtr (butind);
00074         lon[i] = CtlGetLabel (butptr)[0];
00075     }
00076     lon[i] = 0;
00077     return (ReadCoord (lon, &b));
00078 }
00079 
00080 
00087 static double
00088 ReadLat ()
00089 {
00090     int butind,
00091       i;
00092     char lat[13];
00093     Boolean b;
00094     ControlPtr butptr;
00095 
00096     for (i = 0, butind = EditCoordButLat0; butind <= EditCoordButLatNS; butind++, i++)
00097     {
00098         butptr = (ControlPtr) GetObjPtr (butind);
00099         lat[i] = CtlGetLabel (butptr)[0];
00100     }
00101     lat[i] = 0;
00102     return (ReadCoord (lat, &b));
00103 }
00104 
00105 
00116 static void
00117 SetButtons (int firstbutton, char *maskp, char *datas, char label[][2])
00118 {
00119     int butind,
00120       j;
00121     ControlPtr butptr;
00122     ListPtr LstPtr;
00123 
00124     for (butind = firstbutton; *maskp; butind++, maskp++, datas++)
00125     {
00126         butptr = (ControlPtr) GetObjPtr (butind);
00127         LstPtr = (ListPtr) GetObjPtr (butind + EditListOffset);
00128         if (*maskp == 'N')
00129         {
00130             LstSetListChoices (LstPtr, (char **)&ListChoices[10], 2);
00131             LstSetSelection (LstPtr, *datas == 'N' ? 0 : 1);
00132             LstSetHeight (LstPtr, 2);
00133             CtlSetLabel (butptr, LstGetSelectionText (LstPtr, LstGetSelection (LstPtr)));
00134             CtlSetEnabled (butptr, 1);
00135         }
00136         else if (*maskp == 'W')
00137         {
00138             LstSetListChoices (LstPtr, (char **)&ListChoices[12], 2);
00139             LstSetSelection (LstPtr, *datas == 'W' ? 0 : 1);
00140             LstSetHeight (LstPtr, 2);
00141             CtlSetLabel (butptr, LstGetSelectionText (LstPtr, LstGetSelection (LstPtr)));
00142             CtlSetEnabled (butptr, 1);
00143         }
00144         else if ((*maskp >= '0') && (*maskp <= '9'))
00145         {
00146             LstSetListChoices (LstPtr, (char **)&ListChoices[0], *maskp == '0' ? 10 : *maskp - '0');
00147             LstSetHeight (LstPtr, *maskp == '0' ? 10 : *maskp - '0');
00148             LstSetSelection (LstPtr, *datas - '0');
00149             CtlSetLabel (butptr, LstGetSelectionText (LstPtr, LstGetSelection (LstPtr)));
00150             CtlSetEnabled (butptr, 1);
00151         }
00152         else
00153         {
00154             j = butind - firstbutton;
00155             label[j][0] = *maskp;
00156             label[j][1] = 0;
00157             CtlSetLabel (butptr, label[j]);
00158             CtlSetEnabled (butptr, 0);
00159         }
00160     }                                                      /* for */
00161 }                                                          /* SetButtons */
00162 
00163 
00171 static void
00172 updateLatButtons (double latitude)
00173 {
00174     char *p,
00175      *maskp = LatMask[Prefs.displaymode];
00176 
00177     p = DegreToChars (latitude, 0, Prefs.displaymode);
00178     SetButtons (EditCoordButLat0, maskp, p, LatButtonsValues);
00179 }
00180 
00181 
00189 static void
00190 updateLonButtons (double longitude)
00191 {
00192     char *p,
00193      *maskp = LonMask[Prefs.displaymode];
00194 
00195     p = DegreToChars (longitude, 1, Prefs.displaymode);
00196     SetButtons (EditCoordButLon0, maskp, p, LonButtonsValues);
00197 }
00198 
00199 
00208 static void
00209 DegreToButtons (double latitude, double longitude)
00210 {
00211     updateLatButtons (latitude);
00212     updateLonButtons (longitude);
00213     return;
00214 }
00215 
00228 static Err
00229 CustomToDBWpt (Custom_Wpt_Type * pcust, LocalFormatID format, long index, Boolean merge)
00230 {
00231     Object o;
00232     ObjectPtr newp = &o,
00233       destob;
00234     VoidHand RecH = NULL;
00235     Err error;
00236 
00237     InitObject(newp);
00238     if (index >= 0)
00239     {                                                      /* replace existing record */
00240         RecH = DmGetRecord (WptDB, index);
00241         if (!RecH)
00242             return (DmGetLastErr ());
00243         if (merge)
00244         {
00245             destob = MemHandleLock (RecH);
00246             MemMove (&(newp->d), &(destob->d),
00247                      min (sizeof (o.d), MemHandleSize (RecH) - sizeof (destob->header)));
00248             MemHandleUnlock (RecH);
00249         }
00250     }
00251 
00252     CustomToAnyWpt (pcust, format, newp, merge);
00253 
00254     if (index < 0)
00255         error = put_wpt (&(newp->d.g), 0, 0, newp->header.type, newp->header.size);
00256     else
00257         error = SetRecord (RecH, newp, SizeOfObject (newp), WptDB, index, Prefs.wptcategory);   // 
00258     return (error);
00259 }                                                          /* CustomToDBWpt */
00260 
00261 #if 0
00262 
00271 static void
00272 EditListDatumDraw (Int16 itemNum, RectanglePtr bounds, CharPtr * itemsText)
00273 {
00274 
00275         WinDrawChars (gDatum[itemNum].name, StrLen (gDatum[itemNum].name), bounds->topLeft.x,
00276                       bounds->topLeft.y);
00277 }
00278 #endif
00279 
00280 
00290 static void
00291 EditListDraw (Int16 itemNum, RectanglePtr bounds, CharPtr * itemsText)
00292 {
00293     VoidHand RecH = NULL;
00294     BitmapPtr *RecP;
00295 
00296         if (ReducedSymbolsSet)
00297     {
00298         RecH = DmGetResource ('Tbmp', itemNum + DotBMID);
00299         if (RecH)
00300         {
00301             RecP = MemHandleLock (RecH);
00302             WinDrawBitmap ((BitmapPtr) RecP, bounds->topLeft.x, bounds->topLeft.y);
00303             MemHandleUnlock (RecH);
00304             DmReleaseResource (RecH);
00305         }
00306     }
00307     else
00308         DrawSymbol (itemNum, bounds->topLeft.x + 8, bounds->topLeft.y + 7);
00309 }                                                          /* EditListDraw */
00310 
00311 
00312 
00320 Boolean
00321 EditFormHandleEvent (EventPtr e)
00322 {
00323     Boolean Edited,
00324       handled = false;
00325     FormPtr frm;
00326     ListPtr LstPtr;
00327     static ListPtr ColorLstPtr,
00328       SymbolLstPtr;
00329     FieldPtr fdPtr;
00330     ControlPtr PopupPtr,
00331       butPtr;
00332     static Custom_Wpt_Type wp;
00333     char date[dateStringLength];
00334     char time[timeStringLength];
00335     static LocalFormatID wptformat,
00336       curformat;
00337     static double latitude,
00338       longitude,
00339       latfrombut,                      /* buttons latitude */
00340 
00341       lonfrombut;                      /* buttons longitude */
00342     double nlatitude,
00343       nlongitude;
00344     static UInt MyCategory;
00345     static int butID;
00346     DateTimeType dtp;
00347     char name[8],
00348       CategoryName[dmCategoryLength],
00349      *cp;
00350     UInt i,
00351       j,
00352       category,
00353       attributes;
00354     Err error = 0;
00355     short choice;
00356     RectangleType r;
00357     int focus;
00358 
00359         switch (e->eType)
00360     {
00361     case frmOpenEvent:
00362         frm = FrmGetActiveForm ();
00363         wptformat = Prefs.emulatedgps == G12CX ? G107Type :
00364             Prefs.emulatedgps == GII ? G100Type :
00365             Prefs.emulatedgps == MAP175 ? G102Type :
00366             Prefs.emulatedgps == GIII ? G104Type :
00367             Prefs.emulatedgps == eTrex ? G108Type : Prefs.emulatedgps ==
00368             GPS76 ? G109Type : G103Type;
00369         if (EditMode >= NewWpt)
00370         {
00371             /* creation nouveau waypoint  */
00372             MemSet (&wp, sizeof (wp), 0);
00373             wp.posn.lat = CurrentWGS84Pos.lat;
00374             wp.posn.lon = CurrentWGS84Pos.lon;
00375             wp.dst = 1e25;
00376             wp.alt = 1e25;
00377             //      if((wptformat != G103Type) && (wptformat != Garmin107Type))wp.smbl = sym_wpt_dot;
00378             TimSecondsToDateTime (TimGetSeconds () - Prefs.utcoffset * 3600, &dtp);     /* cmnt par defaut a base de date */
00379             DateToAscii (dtp.month, dtp.day, dtp.year, dfDMYWithDashes, date);
00380             TimeToAscii (dtp.hour, dtp.minute, tfColon24h, time);
00381             StrPrintF (wp.cmnt, "%s %s", date, time);
00382             if (EditMode == MarkWpt)
00383             {                                              /* Mark point ? */
00384                 for (i = 1; i < 100; i++)
00385                 {
00386                     StrCopy (name, "MARK");
00387                     StrIToA (&name[4], i);
00388                     if (SearchWptByName (name, 1, 1) < 0)
00389                         break;
00390                 }
00391                 StrNCopySafe (wp.ident, name, sizeof (wp.ident));
00392                 changed = 1;
00393             }
00394             if (EditMode == FromRefWpt)
00395             {                                              /* nouveau wpt dérivé de référence ? */
00396                 //              FrmCopyLabel (frm, EditRefNameID, ReferencePtName); /* nom de la reference */
00397                 StrNToField (ReferencePtName, StrLen (ReferencePtName), EditRefNameID); /* nom de la reference */
00398                 FrmCopyLabel (frm, EditunitLabelID, DistanceUnitNames[Prefs.distunit]);
00399             }
00400             HideObject (EditBtRefID);                      /* effacement bouton Ref */
00401         }
00402         else
00403           {                                                /* edition waypoint existant */
00404             curformat = IndexToCustomWpt (CurrentRecordIndex, WptDB, &wp);
00405             if (wptformat != curformat)
00406               if (!FrmAlert (ConvWptID))
00407                 wptformat = curformat;
00408             if (wptformat<=G109Type) StrNToField (LocalId2String[wptformat], StrLen (LocalId2String[wptformat]), EditTypeFieldID);
00409             CurrentWGS84Pos.lat = wp.posn.lat;
00410             CurrentWGS84Pos.lon = wp.posn.lon;
00411             HideObject (EditBtNextID);
00412           }
00413 
00414         /* symboles */
00415         SymbolLstPtr = (ListPtr) GetObjPtr (EditSymbolListID);
00416         LstSetDrawFunction (SymbolLstPtr, &EditListDraw);
00417         if ((wptformat == G103Type) || (wptformat == Garmin107Type))
00418         {
00419             ReducedSymbolsSet = 1;
00420             LstSetListChoices (SymbolLstPtr, NULL, 16);
00421             wp.smbl = SymbolTypeTosmbl (wp.smbl);
00422             //      LstSetSelection (SymbolLstPtr, wp.smbl);
00423         }
00424         else
00425         {
00426             //        HideObject (EditSymbolPopupID);
00427             ReducedSymbolsSet = 0;
00428             LstSetListChoices (SymbolLstPtr, NULL, 2400 / 16);
00429             wp.smbl = symb_gid2lid (wp.smbl);
00430         }
00431         LstSetSelection (SymbolLstPtr, wp.smbl);
00432         LstMakeItemVisible (SymbolLstPtr, LstGetSelection (SymbolLstPtr));
00433 
00434         /* nom */
00435         StrNToField (wp.ident, StrLen (wp.ident), EditFdNameID);
00436         if (EditMode >= NewWpt)
00437         {
00438             fdPtr = (FieldPtr) GetObjPtr (EditFdNameID);
00439             FldSetSelection (fdPtr, 0, FldGetTextLength (fdPtr));
00440             FrmSetFocus (frm, FrmGetObjectIndex (frm, EditFdNameID));
00441             /* FldGrabFocus(fdPtr); // ne marche pas */
00442         }
00443 
00444         /* commentaire */
00445         StrNToField (wp.cmnt, StrLen (wp.cmnt), EditFdCommentID);
00446 
00447         /* coordonnees */
00448         if (EditMode != FromRefWpt)
00449         {
00450             SemiToDegre (&wp.posn, &latitude, &longitude); /* traduction */
00451             nlatitude = latitude;
00452             nlongitude = longitude;
00453             translate (FromWGS84, &nlatitude, &nlongitude, Prefs.datum);        /* conversion */
00454             DegreToButtons (nlatitude, nlongitude);        /* et affichage */
00455             latfrombut = ReadLat ();
00456             lonfrombut = ReadLon ();
00457         }
00458 
00459         /* display mode */
00460         if ((wptformat == G103Type) || (wptformat == G104Type) || (wptformat == G107Type)
00461             || (wptformat == G108Type) || (wptformat == G109Type))
00462         {                                                  // optimisable, a voir pour 109 $$
00463             LstPtr = (ListPtr) GetObjPtr (EditDispListID);
00464             LstSetSelection (LstPtr, wp.dspl);
00465             PopupPtr = (ControlPtr) GetObjPtr (EditDispPopupID);
00466             CtlSetLabel (PopupPtr, LstGetSelectionText (LstPtr, wp.dspl));
00467         }
00468         else
00469         {
00470             HideObject (EditPDispLabelID);
00471             HideObject (EditDispPopupID);
00472         }
00473         //#if 0
00474         /* proximity distance */
00475         if ((wptformat == G102Type) || (wptformat == G104Type) || (wptformat == G107Type) || 
00476             (wptformat == G108Type) || (wptformat == G109Type))
00477           if (wp.dst < 1.0e9) {
00478             cp = DToA (wp.dst, 0, 0);  // suspect principal $$
00479             StrNToField (cp, StrLen (cp), EditPDistFieldID);
00480           }
00481           else;
00482         else
00483         {
00484             //FldSetUsable (fdPtr, 0);
00485             HideObject (EditPDistFieldID);
00486             HideObject (EditPDistLabelID);
00487         }
00488         /* altitude */
00489         if ((wptformat == G108Type) || (wptformat == G109Type))
00490           {
00491             if (wp.alt < 1.0e9) {
00492               cp = DToA (wp.alt, 0, 0);
00493               StrNToField (cp, StrLen (cp), EditAltFieldID);
00494             }
00495             ShowObject (EditAltLabelID);
00496             ShowObject (EditAltFieldID);
00497           }
00498 
00499         /* color */
00500         ColorLstPtr = NULL;
00501         PopupPtr = NULL;
00502         if (wptformat == G107Type)
00503         {
00504             ColorLstPtr = (ListPtr) GetObjPtr (EditColorListID);
00505             LstSetSelection (ColorLstPtr, wp.color < 4 ? wp.color : 0);
00506             PopupPtr = (ControlPtr) GetObjPtr (EditColorPopupID);
00507             ShowObject (EditColorPopupID);
00508         }
00509         else if ((wptformat == G108Type) || (wptformat == G109Type))
00510         {
00511             ColorLstPtr = (ListPtr) GetObjPtr (EditColor2ListID);
00512             LstSetSelection (ColorLstPtr, wp.color < 16 ? wp.color : 0);
00513             PopupPtr = (ControlPtr) GetObjPtr (EditColor2PopupID);
00514             ShowObject (EditColor2PopupID);
00515         }
00516         if (ColorLstPtr)
00517             CtlSetLabel (PopupPtr,
00518                          LstGetSelectionText (ColorLstPtr, LstGetSelection (ColorLstPtr)));
00519 
00520         /* catégorie */
00521         if (EditMode >= NewWpt)
00522         {
00523             MyCategory = Prefs.wptcategory;
00524             if (MyCategory == dmAllCategories)
00525                 MyCategory = dmUnfiledCategory;
00526         }
00527         else
00528         {
00529             error = DmRecordInfo (WptDB, CurrentRecordIndex, &attributes, NULL, NULL);
00530             MyCategory = attributes & dmRecAttrCategoryMask;
00531         }
00532         CategoryGetName (WptDB, MyCategory, CategoryName);
00533         CategorySetTriggerLabel (GetObjPtr (EditCatPopupID), CategoryName);
00534 
00535         /* datum */
00536 #if 0
00537         LstPtr = (ListPtr) GetObjPtr (EditDatumListID);
00538         LstSetListChoices (LstPtr, NULL, nDatums);
00539         LstSetDrawFunction (LstPtr, &EditListDatumDraw);
00540         LstSetSelection (LstPtr, Prefs.datum);
00541         LstMakeItemVisible (LstPtr, Prefs.datum);
00542         PopupPtr = (ControlPtr) GetObjPtr (EditDatumPopupID);
00543         CtlSetLabel (PopupPtr, gDatum[Prefs.datum].name);
00544 #else
00545         FldSetTextPtr (GetObjPtr (EditDatumFieldID), gDatum[Prefs.datum].name);
00546 #endif
00547 
00548         FrmDrawForm (frm);
00549 
00550         //      PopupPtr = (ControlPtr) GetObjPtr (EditSymbolPopupID);
00551         GetObjectBounds (EditSymbolPopupID, &r);
00552         EditListDraw (LstGetSelection (SymbolLstPtr), &r, NULL);
00553         GrfSetState (1, 0, 0);
00554         //      butID = EditCoordButLat0; ??
00555         handled = true;
00556         break;
00557 
00558     case frmCloseEvent:
00559         if (EditMode >= NewWpt)
00560             //        SelectionAvailable = 0;
00561             break;
00562 
00563 /*      case menuEvent: */
00564 /*      MenuEraseStatus (NULL); */
00565 /*      switch (e->data.menu.itemID) */
00566 /*      { */
00567 /*      } */
00568 /*      handled = true; */
00569 /*      break; */
00570 
00571     case lstSelectEvent:
00572         switch (e->data.lstSelect.listID)
00573         {
00574         }
00575         //      handled = true;
00576         break;
00577 
00578     case popSelectEvent:
00579 #if 0
00580         if (e->data.popSelect.controlID == EditDatumPopupID)
00581         {
00582             CtlSetLabel (e->data.popSelect.controlP, gDatum[e->data.popSelect.selection].name);
00583             nlongitude = ReadLon ();
00584             nlatitude = ReadLat ();
00585             if ((nlongitude == lonfrombut) && (nlatitude == latfrombut))        /* contenu boutons modifie ? */
00586             {
00587                 nlatitude = latitude;
00588                 nlongitude = longitude;
00589             }
00590             else
00591                 translate (ToWGS84, &nlatitude, &nlongitude, Prefs.datum);      /* conversion depuis datum courant */
00592             Prefs.datum = e->data.popSelect.selection;
00593             translate (FromWGS84, &nlatitude, &nlongitude, Prefs.datum);        /* conversion vers nouveau datum */
00594             DegreToButtons (nlatitude, nlongitude);
00595             latfrombut = ReadLat ();
00596             lonfrombut = ReadLon ();                       /* et affichage */
00597             handled = true;
00598         }
00599 #endif
00600         break;
00601 
00602     case keyDownEvent:
00603         frm = FrmGetActiveForm ();
00604         focus = FrmGetFocus (frm);
00605         if (focus >= 0)
00606             i = FrmGetObjectId (frm, focus);
00607         else
00608             i = 0;
00609         switch (e->data.keyDown.chr)
00610         {
00611         case nextFieldChr:
00612             switch (i)
00613             {
00614             case EditFdNameID:
00615                 j = EditFdCommentID;
00616                 break;
00617             default:
00618                 j = EditFdNameID;
00619             }                                              /* switch (i) */
00620             FrmSetFocus (frm, FrmGetObjectIndex (frm, j));
00621             handled = true;
00622             break;
00623 
00624         case prevFieldChr:
00625             break;
00626         }                                                  /* switch (e->data.keyDown.chr) */
00627         break;                                             /* pb avec focus des fields */
00628 #if 0
00629         butPtr = (ControlPtr) GetObjPtr (butID);
00630         if (butPtr)
00631         {
00632             p = CtlGetLabel (butPtr);
00633             name[0] = *p;
00634             *p = e->data.keyDown.chr;
00635             CtlSetLabel (butPtr, p);
00636             if ((LonFieldToDegree () < -180) || (LonFieldToDegree () > 180)
00637                 || (LatFieldToDegree () < -90) || (LatFieldToDegree () > 90))
00638             {
00639                 SndPlaySystemSound (sndError);
00640                 *p = name[0];
00641                 CtlSetLabel (butPtr, p);
00642             }
00643         }
00644         handled = true;
00645         break;
00646 #endif
00647     case ctlSelectEvent:
00648         switch (e->data.ctlSelect.controlID)
00649         {
00650         case EditBtNextID:
00651         case EditBtOKID:
00652             //                frm = FrmGetActiveForm ();
00653             LstPtr = (ListPtr) GetObjPtr (EditDispListID);
00654             if (LstGetSelection (LstPtr) != wp.dspl)       /* display mode changé ? */
00655             {
00656                 wp.dspl = LstGetSelection (LstPtr);
00657                 changed = 1;
00658             }
00659 
00660             fdPtr = (FieldPtr) GetObjPtr (EditFdNameID);
00661             if (FldDirty (fdPtr))
00662             {                                              /* nom changé ? */
00663                 StrNCopySafe (wp.ident, FldGetTextPtr (fdPtr), sizeof (wp.ident));
00664                 Canonicalize (wp.ident, /*  sizeof */ StrLen (wp.ident));
00665                 changed = 1;
00666             }
00667 
00668             fdPtr = (FieldPtr) GetObjPtr (EditFdCommentID);
00669             if (FldDirty (fdPtr))
00670             {                                              /* commentaire changé ? */
00671                 StrNCopySafe (wp.cmnt, FldGetTextPtr (fdPtr), sizeof (wp.cmnt));
00672                 Canonicalize (wp.cmnt, /*  sizeof */ StrLen (wp.cmnt));
00673                 changed = 1;
00674             }
00675 
00676             fdPtr = (FieldPtr) GetObjPtr (EditPDistFieldID);
00677             if (FldDirty (fdPtr))
00678             {                                              /* distance changée ? */
00679                 wp.dst = StrToD (FldGetTextPtr (fdPtr), NULL);
00680                 if(wp.dst < 0.0)wp.dst=-wp.dst;
00681                 changed = 1;
00682             }
00683 
00684             fdPtr = (FieldPtr) GetObjPtr (EditAltFieldID);
00685             if (FldDirty (fdPtr))
00686             {                                              /* altitude changée ? */
00687                 wp.alt = StrToD (FldGetTextPtr (fdPtr), NULL);
00688                 changed = 1;
00689             }
00690 
00691             //      LstPtr = (ListPtr) GetObjPtr (EditColorListID);
00692             if (ColorLstPtr && (LstGetSelection (ColorLstPtr) != wp.color))     /* couleur changée ? */
00693             {
00694                 wp.color = LstGetSelection (ColorLstPtr);
00695                 changed = 1;
00696             }
00697             if (ReducedSymbolsSet)
00698                 wp.smbl = smblToSymbolType (wp.smbl);      /* symbole */
00699             else
00700                 wp.smbl = symb_lid2gid (wp.smbl);
00701             if (EditMode == FromRefWpt)
00702             {                                              /* cas du wpt dérivé d'une référence */
00703                 double distance = 0;
00704                 unsigned int bearing = 0;
00705                 fdPtr = (FieldPtr) GetObjPtr (EditDistFieldID);
00706 
00707                 if (FldDirty (fdPtr))
00708                     distance = StrToD (FldGetTextPtr (fdPtr), NULL);
00709 
00710                 if (Prefs.distunit == metric)
00711                     distance /= 1.852;
00712                 else if (Prefs.distunit == statute)
00713                     distance /= 1.15078;
00714                 fdPtr = (FieldPtr) GetObjPtr (EditBearFieldID);
00715                 if (FldDirty (fdPtr))
00716                     bearing = StrAToI (FldGetTextPtr (fdPtr));
00717                 wp.posn.lat = ReferencePt.lat;
00718                 wp.posn.lon = ReferencePt.lon;
00719                 DistBearToSemi (distance, bearing, &wp.posn);
00720                 changed = 1;
00721             }
00722             else
00723             {
00724                 nlongitude = ReadLon ();
00725                 nlatitude = ReadLat ();
00726                 if ((nlatitude > 90.) || (nlatitude < -90.) || (nlongitude > 180.)
00727                     || (nlongitude < -180.))
00728                 {
00729                     FrmCustomAlert (CoordErrorID, "", "", "");
00730                     changed = 0;
00731                     handled = true;
00732                     break;
00733                 }
00734                 if ((nlongitude != lonfrombut) || (nlatitude != latfrombut))
00735                 {                                          /* coord. modifiées ? */
00736                     translate (ToWGS84, &nlatitude, &nlongitude, Prefs.datum);
00737                     DegreToSemi (nlatitude, nlongitude, &wp.posn);
00738                     changed = 1;
00739                 }
00740             }
00741             if (changed)
00742             {
00743                 WptSortCritType oldsortcrit = Prefs.wptsortcrit;
00744                 Prefs.wptcategory = MyCategory;
00745                 if (EditMode >= NewWpt)
00746                 {                                          /* creation nouveau waypoint ? */
00747                     error = CustomToDBWpt (&wp, wptformat, -1, 0);
00748                     CurrentRecordIndex = 0;
00749                 }
00750                 else
00751                 {                                          /* modification de waypoint */
00752                     error = CustomToDBWpt (&wp, wptformat, CurrentRecordIndex, 1);
00753                 }
00754                 SortWpts (oldsortcrit);                    /* remise en ordre */
00755                 MainListDirty = 1;
00756             }                                              /* EditBtOKID */
00757             if (e->data.ctlSelect.controlID == EditBtNextID)
00758             {                                              /* on enchaine sur un autre */
00759                 wp.ident[0] = 0;
00760                 StrNToField (wp.ident, StrLen (wp.ident), EditFdNameID);
00761                 break;
00762             }
00763 
00764         case EditBtCancelID:
00765             FrmReturnToForm (0);
00766             handled = true;
00767             break;
00768 
00769         case EditBtRefID:
00770             if (SetReferencePt (CurrentRecordIndex, 1))
00771             {
00772                 if ((Prefs.wptsortcrit == Dist)||(Prefs.wptsortcrit == Bear))
00773                     SortWpts (Current);
00774                 FrmReturnToForm (0);
00775             }
00776             handled = true;
00777             break;
00778 
00779         case EditBtDeleteID:                               /* suppression du waypoint */
00780             if (EditMode >= NewWpt)
00781             {                                              /* si nouveau wpt abandon */
00782                 //                SelectionAvailable = 0;
00783                 FrmReturnToForm (0);
00784             }
00785             else if (FrmCustomAlert (RmvWptID, wp.ident, NULL, NULL))
00786             {
00787                 error = DmRemoveRecord (WptDB, CurrentRecordIndex);
00788                 CurrentRecordIndex = CurrentRecordIndex == 0 ? 0 : CurrentRecordIndex - 1;
00789                 MainListDirty = 1;
00790                 FrmReturnToForm (0);
00791             }
00792 
00793             handled = true;
00794             break;
00795 
00796         case EditCatPopupID:                               /* categorie */
00797             frm = FrmGetActiveForm ();
00798             category = MyCategory;
00799             Edited =
00800                 CategorySelect (WptDB, frm, EditCatPopupID, EditCatListID, false, &MyCategory,
00801                                 CtlGetLabel (e->data.ctlSelect.pControl), 1, 0);
00802             if (Edited)
00803                 Prefs.wptcategory = dmAllCategories;
00804             if ((MyCategory != category) && (EditMode == EditWpt))
00805                 changed = 1;
00806             handled = true;
00807             break;
00808 
00809         case EditSymbolPopupID:                    /* symbole */
00810             //        LstPtr = (ListPtr) GetObjPtr (EditSymbolListID);
00811             choice = LstPopupList (SymbolLstPtr);
00812             if ((choice != -1) && (choice != wp.smbl))
00813             {
00814                 changed = 1;
00815                 wp.smbl = choice;
00816             }
00817             //      PopupPtr = (ControlPtr) GetObjPtr (EditSymbolPopupID);
00818             GetObjectBounds (EditSymbolPopupID, &r);
00819             EditListDraw (choice, &r, NULL);
00820             handled = true;
00821             break;
00822 
00823         case EditCoordButLat0:
00824         case EditCoordButLat0 + 1:
00825         case EditCoordButLat0 + 2:
00826         case EditCoordButLat0 + 3:
00827         case EditCoordButLat0 + 4:
00828         case EditCoordButLat0 + 5:
00829         case EditCoordButLat0 + 6:
00830         case EditCoordButLat0 + 7:
00831         case EditCoordButLat0 + 8:
00832         case EditCoordButLat0 + 9:
00833         case EditCoordButLat0 + 10:
00834         case EditCoordButLat0 + 11:
00835         case EditCoordButLon0:
00836         case EditCoordButLon0 + 1:
00837         case EditCoordButLon0 + 2:
00838         case EditCoordButLon0 + 3:
00839         case EditCoordButLon0 + 4:
00840         case EditCoordButLon0 + 5:
00841         case EditCoordButLon0 + 6:
00842         case EditCoordButLon0 + 7:
00843         case EditCoordButLon0 + 8:
00844         case EditCoordButLon0 + 9:
00845         case EditCoordButLon0 + 10:
00846         case EditCoordButLon0 + 11:
00847         case EditCoordButLon0 + 12:
00848             butID = e->data.ctlSelect.controlID;
00849             butPtr = e->data.ctlSelect.pControl;
00850             LstPtr = (ListPtr) GetObjPtr (butID + EditListOffset);
00851             i = LstPopupList (LstPtr);
00852             CtlSetLabel (butPtr, LstGetSelectionText (LstPtr, LstGetSelection (LstPtr)));
00853             break;
00854         }
00855         break;
00856 
00857     default:
00858         break;
00859     }
00860 
00861         return handled;
00862 }                                                          /* EditFormHandleEvent */
00863 
00864 #endif

Generated on Sun Aug 29 11:00:40 2004 for GPilotS by doxygen 1.3.4