00001 /***************************************************************************** 00002 * 00003 * $RCSfile: MiscOptsForm_8c-source.html,v $ 00004 * 00005 * GPS4Palm Misc Options 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: MiscOptsForm_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.13 2005-05-13 18:32:05 mp 00020 * removed variable gAutoPwrOff 00021 * 00022 * Revision 1.12 2005/01/30 21:22:13 mp 00023 * added PortsMenu event handling 00024 * 00025 * Revision 1.11 2004/12/01 17:44:58 mp 00026 * added TrkModePopup, TrkInt(Time|DST)Popup, and TrkFullPopup 00027 * 00028 * Revision 1.10 2004/11/30 20:44:48 mp 00029 * added TrackMenu event handling 00030 * 00031 * Revision 1.9 2004/11/25 17:01:40 mp 00032 * added ApproachAlertCheckbox and ApproachSoundCheckbox handling 00033 * 00034 * Revision 1.8 2004/11/24 21:18:17 mp 00035 * moved static function declarations from header to implementation file 00036 * 00037 * Revision 1.7 2004/11/23 17:48:52 mp 00038 * removed unused variables 00039 * 00040 * Revision 1.6 2004/11/19 17:57:11 mp 00041 * added AutoWaypointCheckbox and modified AutoPwrOffCheckbox 00042 * 00043 * Revision 1.5 2004/04/29 18:47:16 mp 00044 * added RouteForm, modified for doxygen 00045 * 00046 * Revision 1.4 2004/02/28 17:21:43 mp 00047 * added menuEvent WaypointMenu 00048 * 00049 * Revision 1.3 2004/01/18 11:46:04 mp 00050 * added position display option UTM 00051 * 00052 * Revision 1.2 2003/11/20 20:50:06 mp 00053 * Added setting of Controls from Preferences at frmOpenEvent and 00054 * setting of Prefernces on ctlSelectEvent. 00055 * Removed nilEvent and obsolete Controls (Sermux and Backlight). 00056 * 00057 * Revision 1.1 2003/11/16 17:45:02 mp 00058 * initial version 00059 * 00060 ****************************************************************************/ 00061 #include <PalmOS.h> 00062 #include "ResourceDefines.h" 00063 #include "Serial.h" 00064 #include "Sinetab.h" 00065 #include "MiscOptsForm.h" 00066 #include "GPS.h" 00067 #include "Utils.h" 00068 #include "common.h" 00069 00070 extern Boolean gFormOpened; 00071 extern PrefsType gPrefs; 00072 00073 /* Static Functions */ 00074 static void MiscOptsFormInit(void); 00075 00076 static 00077 void MiscOptsFormInit(void) 00078 { 00079 00080 gFormOpened = true; 00081 } 00082 00083 00084 /****************************************************************************/ 00085 /** 00086 * \brief Misc Options Form event handler 00087 * 00088 * \param eventP pointer to event structure 00089 * 00090 * \return event handled flag 00091 ****************************************************************************/ 00092 Boolean MiscOptsFormHandleEvent(EventPtr eventP) 00093 { 00094 FormPtr frmP = FrmGetActiveForm(); /* Form Ptr */ 00095 ListPtr lstP; /* List Ptr */ 00096 UInt16 n; /* no. of items */ 00097 Boolean handled; /* event handled flag */ 00098 00099 handled = false; 00100 switch (eventP->eType) { 00101 00102 case frmOpenEvent: 00103 MiscOptsFormInit(); 00104 FrmDrawForm(FrmGetActiveForm()); 00105 00106 /* Set Auto Power-Off Check Box from Preferences */ 00107 FrmSetControlValue(frmP, 00108 FrmGetObjectIndex(frmP, AutoPwrOffCheckbox), gPrefs.pwroff); 00109 00110 /* Set Auto Waypoint Check Box from Preferences */ 00111 FrmSetControlValue(frmP, 00112 FrmGetObjectIndex(frmP, AutoWaypointCheckbox), 00113 (gPrefs.auto_wpt) ? 1 : 0); 00114 00115 /* Set Approach Alert Check Box from Preferences */ 00116 FrmSetControlValue(frmP, 00117 FrmGetObjectIndex(frmP, ApproachAlertCheckbox), 00118 (gPrefs.approach_alert) ? 1 : 0); 00119 00120 /* Set Approach Sound Check Box from Preferences */ 00121 FrmSetControlValue(frmP, 00122 FrmGetObjectIndex(frmP, ApproachSoundCheckbox), 00123 (gPrefs.approach_sound) ? 1 : 0); 00124 00125 /* Set Track Log Mode Popup from Preferences */ 00126 lstP = GetObjectFromActiveForm(TrkModeList); 00127 LstSetSelection(lstP, gPrefs.trk_log.mode); 00128 CtlSetLabel(GetObjectFromActiveForm(TrkModePopup), 00129 LstGetSelectionText(lstP, gPrefs.trk_log.mode)); 00130 00131 /* Show Track Log Interval Popup from Preferences */ 00132 switch (gPrefs.trk_log.mode) { 00133 case 0: 00134 FrmHideObject(frmP, FrmGetObjectIndex(frmP, TrkIntTimePopup)); 00135 FrmShowObject(frmP, FrmGetObjectIndex(frmP, TrkIntDstPopup)); 00136 lstP = GetObjectFromActiveForm(TrkIntDstList); 00137 LstSetSelection(lstP, gPrefs.trk_log.ival); 00138 CtlSetLabel(GetObjectFromActiveForm(TrkIntDstPopup), 00139 LstGetSelectionText(lstP, gPrefs.trk_log.ival)); 00140 break; 00141 00142 case 1: 00143 FrmHideObject(frmP, FrmGetObjectIndex(frmP, TrkIntDstPopup)); 00144 FrmShowObject(frmP, FrmGetObjectIndex(frmP, TrkIntTimePopup)); 00145 lstP = GetObjectFromActiveForm(TrkIntTimeList); 00146 LstSetSelection(lstP, gPrefs.trk_log.ival); 00147 CtlSetLabel(GetObjectFromActiveForm(TrkIntTimePopup), 00148 LstGetSelectionText(lstP, gPrefs.trk_log.ival)); 00149 break; 00150 } 00151 00152 /* Set Track Full Popup from Preferences */ 00153 lstP = GetObjectFromActiveForm(TrkFullList); 00154 LstSetSelection(lstP, gPrefs.trk_log.wrap); 00155 CtlSetLabel(GetObjectFromActiveForm(TrkFullPopup), 00156 LstGetSelectionText(lstP, gPrefs.trk_log.wrap)); 00157 00158 /* Set Position Unit Push Buttons from Preferences */ 00159 switch (gPrefs.units.pos_unit) { 00160 case POS_D: 00161 SetControlValueFromId(PosDPushb, 1); 00162 break; 00163 00164 case POS_DM: 00165 SetControlValueFromId(PosDMPushb, 1); 00166 break; 00167 00168 case POS_DMS: 00169 SetControlValueFromId(PosDMSPushb, 1); 00170 break; 00171 00172 case POS_UTM: 00173 SetControlValueFromId(PosUTMPushb, 1); 00174 break; 00175 } 00176 00177 /* Set Distance Unit Push Buttons from Preferences */ 00178 switch (gPrefs.units.dst_unit) { 00179 case DST_KM: 00180 SetControlValueFromId(DstKmPushb, 1); 00181 break; 00182 00183 case DST_MI: 00184 SetControlValueFromId(DstMiPushb, 1); 00185 break; 00186 00187 case DST_NM: 00188 SetControlValueFromId(DstNmPushb, 1); 00189 break; 00190 } 00191 00192 /* Set Altitude Unit Push Buttons from Preferences */ 00193 switch (gPrefs.units.alt_unit) { 00194 case ALT_M: 00195 SetControlValueFromId(AltMPushb, 1); 00196 break; 00197 00198 case ALT_FT: 00199 SetControlValueFromId(AltFtPushb, 1); 00200 break; 00201 } 00202 00203 /* Set Speed Unit Push Buttons from Preferences */ 00204 switch (gPrefs.units.spd_unit) { 00205 case SPD_KMH: 00206 SetControlValueFromId(SpdKmhPushb, 1); 00207 break; 00208 00209 case SPD_MS: 00210 SetControlValueFromId(SpdMsPushb, 1); 00211 break; 00212 00213 case SPD_MIH: 00214 SetControlValueFromId(SpdMihPushb, 1); 00215 break; 00216 00217 case SPD_KTS: 00218 SetControlValueFromId(SpdKtsPushb, 1); 00219 break; 00220 } 00221 00222 handled = true; 00223 break; 00224 00225 case menuEvent: 00226 switch (eventP->data.menu.itemID) { 00227 00228 case PositionMenu: 00229 FrmGotoForm(GPSMainForm); 00230 handled = true; 00231 break; 00232 00233 case SkyviewMenu: 00234 FrmGotoForm(SkyviewForm); 00235 handled = true; 00236 break; 00237 00238 case NavigationMenu: 00239 FrmGotoForm(NavigationForm); 00240 handled = true; 00241 break; 00242 00243 case MapMenu: 00244 FrmGotoForm(MapForm); 00245 handled = true; 00246 break; 00247 00248 case MapOptsMenu: 00249 FrmGotoForm(MapOptsForm); 00250 handled = true; 00251 break; 00252 00253 case PortsMenu: 00254 if (gNewSerialManager) { 00255 FrmGotoForm(GPSPortForm); 00256 } 00257 handled = true; 00258 break; 00259 00260 case WaypointMenu: 00261 FrmGotoForm(WaypointForm); 00262 handled = true; 00263 break; 00264 00265 case RouteMenu: 00266 FrmGotoForm(RouteForm); 00267 handled = true; 00268 break; 00269 00270 case TrackMenu: 00271 FrmGotoForm(TrackForm); 00272 handled = true; 00273 break; 00274 00275 case AboutMenu: 00276 FrmGotoForm(AboutForm); 00277 handled = true; 00278 break; 00279 } 00280 break; 00281 00282 case popSelectEvent: 00283 /* Popup List */ 00284 00285 /* Track Log Mode */ 00286 if (eventP->data.popSelect.controlID == TrkModePopup) { 00287 gPrefs.trk_log.mode = eventP->data.popSelect.selection; 00288 00289 /* Change Track Log Interval Popup */ 00290 switch (gPrefs.trk_log.mode) { 00291 case 0: 00292 /* Distance */ 00293 FrmHideObject(frmP, FrmGetObjectIndex(frmP, TrkIntTimePopup)); 00294 FrmShowObject(frmP, FrmGetObjectIndex(frmP, TrkIntDstPopup)); 00295 00296 lstP = GetObjectFromActiveForm(TrkIntDstList); 00297 n = LstGetNumberOfItems(lstP); 00298 00299 if (gPrefs.trk_log.ival > n-1) { 00300 /* set to last index */ 00301 gPrefs.trk_log.ival = n-1; 00302 } 00303 00304 /* Show Track Log Interval */ 00305 LstSetSelection(lstP, gPrefs.trk_log.ival); 00306 CtlSetLabel(GetObjectFromActiveForm(TrkIntDstPopup), 00307 LstGetSelectionText(lstP, gPrefs.trk_log.ival)); 00308 break; 00309 00310 case 1: 00311 /* Time */ 00312 FrmHideObject(frmP, FrmGetObjectIndex(frmP, TrkIntDstPopup)); 00313 FrmShowObject(frmP, FrmGetObjectIndex(frmP, TrkIntTimePopup)); 00314 00315 lstP = GetObjectFromActiveForm(TrkIntTimeList); 00316 n = LstGetNumberOfItems(lstP); 00317 00318 if (gPrefs.trk_log.ival > n-1) { 00319 /* set to last index */ 00320 gPrefs.trk_log.ival = n-1; 00321 } 00322 00323 /* Show Track Log Interval */ 00324 LstSetSelection(lstP, gPrefs.trk_log.ival); 00325 CtlSetLabel(GetObjectFromActiveForm(TrkIntTimePopup), 00326 LstGetSelectionText(lstP, gPrefs.trk_log.ival)); 00327 break; 00328 } 00329 } 00330 00331 /* Track Log Interval */ 00332 if (eventP->data.popSelect.controlID == TrkIntTimePopup || 00333 eventP->data.popSelect.controlID == TrkIntDstPopup) { 00334 gPrefs.trk_log.ival = eventP->data.popSelect.selection; 00335 } 00336 00337 /* Track Log Full Option */ 00338 if (eventP->data.popSelect.controlID == TrkFullPopup) { 00339 gPrefs.trk_log.wrap = eventP->data.popSelect.selection; 00340 } 00341 00342 /* Note: popup needs to handle the event, too */ 00343 break; 00344 00345 case ctlSelectEvent: 00346 switch (eventP->data.ctlSelect.controlID) { 00347 /* Auto Power-Off Check Box */ 00348 case AutoPwrOffCheckbox: 00349 gPrefs.pwroff = GetControlValueFromId(AutoPwrOffCheckbox); 00350 break; 00351 00352 case AutoWaypointCheckbox: 00353 gPrefs.auto_wpt = GetControlValueFromId(AutoWaypointCheckbox); 00354 break; 00355 00356 case ApproachAlertCheckbox: 00357 gPrefs.approach_alert = GetControlValueFromId(ApproachAlertCheckbox); 00358 break; 00359 00360 case ApproachSoundCheckbox: 00361 gPrefs.approach_sound = GetControlValueFromId(ApproachSoundCheckbox); 00362 break; 00363 00364 /* Position Unit Push Buttons */ 00365 case PosDPushb: 00366 gPrefs.units.pos_unit = POS_D; 00367 break; 00368 00369 case PosDMPushb: 00370 gPrefs.units.pos_unit = POS_DM; 00371 break; 00372 00373 case PosDMSPushb: 00374 gPrefs.units.pos_unit = POS_DMS; 00375 break; 00376 00377 case PosUTMPushb: 00378 gPrefs.units.pos_unit = POS_UTM; 00379 break; 00380 } 00381 00382 /* Distance Unit Push Buttons */ 00383 switch (eventP->data.ctlSelect.controlID) { 00384 case DstKmPushb: 00385 gPrefs.units.dst_unit = DST_KM; 00386 break; 00387 00388 case DstMiPushb: 00389 gPrefs.units.dst_unit = DST_MI; 00390 break; 00391 00392 case DstNmPushb: 00393 gPrefs.units.dst_unit = DST_NM; 00394 break; 00395 } 00396 00397 /* Altitude Unit Push Buttons */ 00398 switch (eventP->data.ctlSelect.controlID) { 00399 case AltMPushb: 00400 gPrefs.units.alt_unit = ALT_M; 00401 break; 00402 00403 case AltFtPushb: 00404 gPrefs.units.alt_unit = ALT_FT; 00405 break; 00406 00407 } 00408 00409 /* Speed Unit Push Buttons */ 00410 switch (eventP->data.ctlSelect.controlID) { 00411 case SpdKmhPushb: 00412 gPrefs.units.spd_unit = SPD_KMH; 00413 break; 00414 00415 case SpdMsPushb: 00416 gPrefs.units.spd_unit = SPD_MS; 00417 break; 00418 00419 case SpdMihPushb: 00420 gPrefs.units.spd_unit = SPD_MIH; 00421 break; 00422 00423 case SpdKtsPushb: 00424 gPrefs.units.spd_unit = SPD_KTS; 00425 break; 00426 } 00427 00428 break; 00429 00430 case frmCloseEvent: 00431 break; 00432 00433 } 00434 return(handled); 00435 } /* MiscOptsFormHandleEvent() */