GPS4Palm

Source Code Documentation


MainForm.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * $RCSfile: MainForm_8c-source.html,v $
00004  *
00005  * GPS4Palm Main Form (Position Form)
00006  *
00007  * This program is Copyright (C) 03/2003 Matthias Prinke
00008  * <matthias.prinke@surfeu.de> and covered by GNU's GPL.
00009  * In particular, this program is free software and comes WITHOUT
00010  * ANY WARRANTY.
00011  *
00012  * $Author: mp $
00013  *
00014  * $Date: 2007-10-08 20:40:33 $
00015  *
00016  * $Revision: 1.7.2.1 $
00017  *
00018  * $Log: MainForm_8c-source.html,v $
00018  * Revision 1.7.2.1  2007-10-08 20:40:33  mp
00018  * updated for gps4palm V0.9.5 beta
00018  *
00019  * Revision 1.20  2005-04-02 10:09:43  mp
00020  * modified Position2Clipboard() and Position2Geodb() to return 'handled'
00021  *
00022  * Revision 1.19  2005/04/02 07:26:59  mp
00023  * added PosgeodbMenu event handling
00024  *
00025  * Revision 1.18  2005/03/25 13:44:41  mp
00026  * added PosclipMenu event handling
00027  *
00028  * Revision 1.17  2005/01/23 18:40:43  mp
00029  * added PortsMenu event handling
00030  *
00031  * Revision 1.16  2004/12/09 17:31:11  mp
00032  * removed debug specific code
00033  *
00034  * Revision 1.15  2004/12/08 21:02:43  mp
00035  * added track logging, modified nilEvent handling
00036  *
00037  * Revision 1.14  2004/11/30 20:43:48  mp
00038  * added TrackMenu event handling
00039  *
00040  * Revision 1.13  2004/11/25 20:14:20  mp
00041  * fixed typo
00042  *
00043  * Revision 1.12  2004/11/25 20:07:49  mp
00044  * added NotifyApproach()
00045  *
00046  * Revision 1.11  2004/11/25 16:58:06  mp
00047  * added function call UpdateActWpt()
00048  *
00049  * Revision 1.10  2004/11/24 21:12:40  mp
00050  * moved static function declarations from header to implementation file,
00051  * added AboutForm menu event handling
00052  *
00053  * Revision 1.9  2004/04/29 20:10:26  mp
00054  * modified comments for doxygen
00055  *
00056  * Revision 1.8  2004/02/28 13:24:56  mp
00057  * added WaypointMenu
00058  *
00059  * Revision 1.7  2004/01/18 19:01:53  mp
00060  * added FrmHideObject/FrmShowObject calls for switching between Latitude/Longitude
00061  * and UTM position display mode
00062  *
00063  * Revision 1.6  2003/12/31 15:05:35  mp
00064  * added comments, cleaned up code
00065  *
00066  * Revision 1.5  2003/11/20 20:44:29  mp
00067  * added status redraw on frmOpenEvent
00068  *
00069  * Revision 1.4  2003/11/18 20:52:56  mp
00070  * Added Auto Power-Off disable, moved serial port setup to GPS.c,
00071  * added current form to Application Preferences, modified Fields.
00072  *
00073  * Revision 1.3  2003/10/20 17:23:38  mp
00074  * added field deallocation on frmCloseEvent
00075  *
00076  * Revision 1.2  2003/10/15 19:12:33  mp
00077  * modified event loop, added menu item Debug
00078  *
00079  * Revision 1.1.1.1  2003/07/14 18:59:29  mp
00080  * Imported GPS4Palm to CVS revision control.
00081  *
00082  *
00083  ****************************************************************************/
00084 #include <PalmOS.h>                     
00085 #include "ResourceDefines.h"
00086 #include "Serial.h"
00087 #include "Utils.h"
00088 #include "MainForm.h"
00089 #include "GPS.h"
00090 #include "HandleMessage.h"
00091 #include "Utils.h"
00092 #include "Data.h"               /* UpdateActWpt(), NotifyApproach() */
00093 #include "Clip.h"
00094 #include "common.h"
00095 
00096 /* Preferences data structure */
00097 extern PrefsType gPrefs;
00098 
00099 /* Auto Power-Off */
00100 extern UInt16   gAutoPwrOff;
00101 
00102 /* GPS Data */
00103 extern GPSType          gGPSData;
00104 
00105 /* Static Functions */
00106 static void MainFormInit(void);
00107 
00108 
00109 static 
00110 void MainFormInit(void)
00111 {
00112         gFormOpened = true;
00113 }
00114 
00115 /****************************************************************************/
00116 /**
00117  * \brief       Position Form event handler
00118  *
00119  * \param       event           pointer to event structure
00120  *
00121  * \return      event handled flag
00122  ****************************************************************************/
00123 Boolean MainFormHandleEvent(EventPtr event)
00124 {
00125         Boolean         handled = false;
00126         Boolean         updatedDisplay;
00127         FormPtr         frmP;           /* form ptr */
00128 
00129         switch (event->eType) {
00130         
00131         case menuEvent:
00132           switch (event->data.menu.itemID) {
00133       
00134             case SkyviewMenu:
00135               FrmGotoForm(SkyviewForm);
00136               handled = true;
00137               break;
00138             
00139             case NavigationMenu:
00140               FrmGotoForm(NavigationForm);
00141               handled = true;
00142               break;
00143 
00144             case MapMenu:
00145               FrmGotoForm(MapForm);
00146               handled = true;
00147               break;
00148 
00149             case MiscOptsMenu:
00150               FrmGotoForm(MiscOptsForm);
00151               handled = true;
00152               break;
00153                
00154             case MapOptsMenu:
00155               FrmGotoForm(MapOptsForm);
00156               handled = true;
00157               break;
00158             
00159             case PortsMenu:
00160               if (gNewSerialManager) {
00161                 FrmGotoForm(GPSPortForm);
00162               }
00163               handled = true;
00164               break;
00165             
00166             case WaypointMenu:
00167               FrmGotoForm(WaypointForm);
00168               handled = true;
00169               break;
00170 
00171             case RouteMenu:
00172               FrmGotoForm(RouteForm);
00173               handled = true;
00174               break;
00175                
00176             case TrackMenu:
00177               FrmGotoForm(TrackForm);
00178               handled = true;
00179               break;
00180             
00181             case PosclipMenu:
00182               handled = Position2Clipboard(gGPSData, gPrefs.units);
00183               break;
00184               
00185             case PosgeodbMenu:
00186               handled = Position2Geodb(gGPSData);
00187               break;
00188               
00189             case AboutMenu:
00190               FrmGotoForm(AboutForm);
00191               handled = true;
00192               break;
00193                
00194 #ifdef DEBUG_FORM
00195             case DebugMenu:
00196               FrmGotoForm(DebugForm);
00197               handled = true;
00198               break;
00199 #endif
00200           }
00201           break;
00202           
00203         case nilEvent:
00204                 handled = true;
00205                 /* throw away anything in the buffer -- we want fresh data */
00206                 DoReceiveFlush(gPortID, 1);
00207                 
00208                 /* read data from GPS */
00209                 updatedDisplay = ReadFromGPS();
00210                 
00211                 if (gGPSData.valid && gPrefs.act_rte.valid && gPrefs.auto_wpt) {
00212                   /* update active waypoint */
00213                   UpdateActWpt(gGPSData.lat, gGPSData.lon, false /* init */);
00214                 }
00215                                 
00216                 /* Active Waypoint approach detection and display */
00217                 NotifyApproach();
00218                 
00219                 /* Track Logging */
00220                 if (gPrefs.act_trk.log_state) {
00221                   Boolean new_trk;
00222                                   
00223                   if (TrackIntervalCheck(false /* init */, &new_trk)) {
00224                     TrackWriteLog(new_trk);
00225                   }
00226                 }               
00227                 break;
00228                 
00229         case frmOpenEvent:
00230                 frmP = FrmGetActiveForm();
00231                 gPrefs.form = GPSMainForm;
00232                 MainFormInit();
00233                 
00234                 if (gPrefs.units.pos_unit == POS_UTM) { 
00235                   FrmHideObject(frmP, FrmGetObjectIndex(frmP, LatLabel));
00236                   FrmHideObject(frmP, FrmGetObjectIndex(frmP, LonLabel));
00237                   FrmShowObject(frmP, FrmGetObjectIndex(frmP, EastLabel));
00238                   FrmShowObject(frmP, FrmGetObjectIndex(frmP, NorthLabel));
00239                 } else {
00240                   FrmHideObject(frmP, FrmGetObjectIndex(frmP, EastLabel));
00241                   FrmHideObject(frmP, FrmGetObjectIndex(frmP, NorthLabel));
00242                   FrmShowObject(frmP, FrmGetObjectIndex(frmP, LatLabel));
00243                   FrmShowObject(frmP, FrmGetObjectIndex(frmP, LonLabel));
00244                 }   
00245 
00246                 FrmDrawForm(frmP);
00247                 UpdateStatus(STAT_REDRAW);
00248                 handled = true;
00249                 break;
00250                 
00251         case frmCloseEvent:
00252                 /* Deallocate Fields' Text Memory */
00253                 SetFieldText(PositionStatusField, NULL, false, true);
00254                 SetFieldText(TimeField, NULL, false, true);
00255                 SetFieldText(LatitudeField, NULL, false, true);
00256                 SetFieldText(LongitudeField, NULL, false, true);
00257                 SetFieldText(SpeedField, NULL, false, true);
00258                 SetFieldText(AltField, NULL, false, true);
00259                 SetFieldText(CMGField, NULL, false, true);
00260                 SetFieldText(MagField, NULL, false, true);
00261                 handled = true;
00262                 break;
00263         }
00264         return(handled);
00265 } /* MainFormHandleEvent() */

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