Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

SetTimeDialog Class Reference

Collaboration diagram for SetTimeDialog:

Collaboration graph
List of all members.

Public Member Functions

LRESULT command (WPARAM wParam, LPARAM lParam)
double getTime () const
void init (HWND _hDlg)
LRESULT notify (int id, const NMHDR &nmhdr)
void setTime (const double _jd)
 SetTimeDialog (CelestiaCore *)
void updateControls ()
 ~SetTimeDialog ()

Private Member Functions

void getLocalTimeZoneInfo ()

Private Attributes

CelestiaCoreappCore
HWND hDlg
double jd
char localTimeZoneAbbrev [64]
int localTimeZoneBiasInSeconds
char localTimeZoneName [64]
bool useLocalTime

Constructor & Destructor Documentation

SetTimeDialog::SetTimeDialog CelestiaCore  ) 
 

Definition at line 49 of file wintime.cpp.

References localTimeZoneAbbrev, and localTimeZoneName.

00049                                                    :
00050     hDlg(0),
00051     appCore(_appCore),
00052     jd(astro::J2000),
00053     useLocalTime(false),
00054     localTimeZoneBiasInSeconds(0)
00055 {
00056     localTimeZoneAbbrev[0] = '\0';
00057     localTimeZoneName[0] = '\0';
00058 }

SetTimeDialog::~SetTimeDialog  ) 
 

Definition at line 61 of file wintime.cpp.

00062 {
00063 }


Member Function Documentation

LRESULT SetTimeDialog::command WPARAM  wParam,
LPARAM  lParam
 

Definition at line 198 of file wintime.cpp.

References appCore, CelestiaCore::getSimulation(), hDlg, IDC_COMBOBOX_TIMEZONE, IDC_SETCURRENTTIME, jd, setTime(), Simulation::setTime(), CelestiaCore::setTimeZoneBias(), CelestiaCore::tick(), updateControls(), and useLocalTime.

Referenced by SetTimeProc().

00199 {
00200     switch (LOWORD(wParam))
00201     {
00202         case IDOK:
00203             appCore->tick();
00204             appCore->getSimulation()->setTime(jd);
00205             appCore->setTimeZoneBias(useLocalTime ? 1 : 0);
00206             EndDialog(hDlg, 0);
00207             return TRUE;
00208             
00209         case IDCANCEL:
00210             EndDialog(hDlg, 0);
00211             return TRUE;
00212     
00213         case IDC_SETCURRENTTIME:
00214             // Set time to the current system time
00215             setTime((double) time(NULL) / 86400.0 + (double) astro::Date(1970, 1, 1));
00216             updateControls();
00217             return TRUE;
00218             
00219         case IDC_COMBOBOX_TIMEZONE:
00220             if (HIWORD(wParam) == CBN_SELCHANGE)
00221             {
00222                 LRESULT selection = SendMessage((HWND) lParam, CB_GETCURSEL, 0, 0);
00223                 useLocalTime = (selection == 1);
00224                 updateControls();
00225             }
00226             return TRUE;          
00227             
00228         default:
00229             return FALSE;
00230     }
00231 }

void SetTimeDialog::getLocalTimeZoneInfo  )  [private]
 

Definition at line 102 of file wintime.cpp.

References acronymify(), localTimeZoneAbbrev, localTimeZoneBiasInSeconds, and localTimeZoneName.

Referenced by init().

00103 {
00104     TIME_ZONE_INFORMATION tzi;
00105     DWORD dst = GetTimeZoneInformation(&tzi);
00106     if (dst != TIME_ZONE_ID_INVALID)
00107     {
00108         WCHAR* tzName = NULL;
00109         LONG dstBias = 0;
00110 
00111         if (dst == TIME_ZONE_ID_STANDARD)
00112         {
00113             dstBias = tzi.StandardBias;
00114             tzName = tzi.StandardName;
00115         }
00116         else if (dst == TIME_ZONE_ID_DAYLIGHT)
00117         {
00118             dstBias = tzi.DaylightBias;
00119             tzName = tzi.DaylightName;
00120         }
00121 
00122         localTimeZoneBiasInSeconds = (tzi.Bias + dstBias) * -60;
00123         
00124         // Convert from wide chars to a normal C string
00125         WideCharToMultiByte(CP_ACP, 0,
00126                             tzName, -1,
00127                             localTimeZoneName, sizeof(localTimeZoneName),
00128                             NULL, NULL);
00129         strcpy(localTimeZoneAbbrev, localTimeZoneName);
00130 
00131         // Not sure what GetTimeZoneInformation can return for the
00132         // time zone name.  On my XP system, it returns the string
00133         // "Pacific Standard Time", when we want PST . . .  So, we
00134         // call acronymify to do the conversion.  If the time zone
00135         // name doesn't contain any spaces, we assume that it's
00136         // already in acronym form.
00137         if (strchr(localTimeZoneAbbrev, ' ') != NULL)
00138             acronymify(localTimeZoneAbbrev, strlen(localTimeZoneAbbrev));
00139     }
00140 }

double SetTimeDialog::getTime  )  const
 

Definition at line 144 of file wintime.cpp.

References jd.

00145 {
00146     return jd;
00147 }

void SetTimeDialog::init HWND  _hDlg  ) 
 

Definition at line 82 of file wintime.cpp.

References appCore, getLocalTimeZoneInfo(), CelestiaCore::getSimulation(), Simulation::getTime(), CelestiaCore::getTimeZoneBias(), hDlg, IDC_COMBOBOX_TIMEZONE, jd, localTimeZoneName, updateControls(), and useLocalTime.

Referenced by SetTimeProc().

00083 {
00084     hDlg = _hDlg;
00085     
00086     SetWindowLong(hDlg, DWL_USER, reinterpret_cast<LPARAM>(this));
00087     getLocalTimeZoneInfo();
00088     
00089     jd = appCore->getSimulation()->getTime();
00090     useLocalTime = appCore->getTimeZoneBias() != 0;
00091 
00092     SendDlgItemMessage(hDlg, IDC_COMBOBOX_TIMEZONE, CB_ADDSTRING, 0, (LPARAM) "Universal Time");
00093     SendDlgItemMessage(hDlg, IDC_COMBOBOX_TIMEZONE, CB_ADDSTRING, 0, (LPARAM) localTimeZoneName);
00094     
00095     SendDlgItemMessage(hDlg, IDC_COMBOBOX_TIMEZONE, CB_SETCURSEL, useLocalTime ? 1 : 0, 0);
00096     
00097     updateControls();
00098 }

LRESULT SetTimeDialog::notify int  id,
const NMHDR &  nmhdr
 

Definition at line 235 of file wintime.cpp.

References astro::Date::day, hDlg, astro::Date::hour, IDC_DATEPICKER, IDC_TIMEPICKER, jd, localTimeZoneBiasInSeconds, astro::Date::minute, astro::Date::month, newTime, astro::Date::seconds, useLocalTime, and astro::Date::year.

Referenced by SetTimeProc().

00236 {
00237     astro::Date newTime(jd);
00238     
00239     if (hdr.code == DTN_DATETIMECHANGE)
00240     {
00241         LPNMDATETIMECHANGE change = (LPNMDATETIMECHANGE) &hdr;
00242         if (change->dwFlags == GDT_VALID)
00243         {
00244             if (id == IDC_DATEPICKER || id == IDC_TIMEPICKER)
00245             {
00246                 SYSTEMTIME sysTime;
00247                 SYSTEMTIME sysDate;
00248                 DateTime_GetSystemtime(GetDlgItem(hDlg, IDC_TIMEPICKER), &sysTime);
00249                 DateTime_GetSystemtime(GetDlgItem(hDlg, IDC_DATEPICKER), &sysDate);
00250                 newTime.year = (int16) sysDate.wYear;
00251                 newTime.month = sysDate.wMonth;
00252                 newTime.day = sysDate.wDay;
00253                 newTime.hour = sysTime.wHour;
00254                 newTime.minute = sysTime.wMinute;
00255                 newTime.seconds = sysTime.wSecond + (double) sysTime.wMilliseconds / 1000.0;
00256                 
00257                 jd = (double) newTime;
00258                 if (useLocalTime)
00259                     jd -= localTimeZoneBiasInSeconds / 86400.0;                
00260             }
00261         }
00262     }
00263         
00264     return TRUE;
00265 }

void SetTimeDialog::setTime const double  _jd  ) 
 

Definition at line 151 of file wintime.cpp.

References jd.

Referenced by command().

00152 {
00153     jd = _jd;
00154 }

void SetTimeDialog::updateControls  ) 
 

Definition at line 158 of file wintime.cpp.

References astro::Date::day, hDlg, astro::Date::hour, IDC_DATEPICKER, IDC_TIMEPICKER, jd, localTimeZoneAbbrev, localTimeZoneBiasInSeconds, astro::Date::minute, astro::Date::month, newTime, astro::Date::seconds, useLocalTime, and astro::Date::year.

Referenced by command(), and init().

00159 {
00160     HWND timeItem = NULL;
00161     HWND dateItem = NULL;
00162     SYSTEMTIME sysTime;
00163     double tzjd = jd;
00164 
00165     if (useLocalTime)
00166         tzjd += localTimeZoneBiasInSeconds / 86400.0;
00167         
00168     astro::Date newTime(tzjd);
00169     
00170     sysTime.wYear = newTime.year;
00171     sysTime.wMonth = newTime.month;
00172     sysTime.wDay = newTime.day;
00173     sysTime.wDayOfWeek = ((int) ((double) newTime + 0.5) + 1) % 7;
00174     sysTime.wHour = newTime.hour;
00175     sysTime.wMinute = newTime.minute;
00176     sysTime.wSecond = (int) newTime.seconds;
00177     sysTime.wMilliseconds = 0;
00178 
00179     dateItem = GetDlgItem(hDlg, IDC_DATEPICKER);
00180     if (dateItem != NULL)
00181     {
00182         DateTime_SetFormat(dateItem, "dd' 'MMM' 'yyy");
00183         DateTime_SetSystemtime(dateItem, GDT_VALID, &sysTime);
00184     }
00185     timeItem = GetDlgItem(hDlg, IDC_TIMEPICKER);
00186     if (timeItem != NULL)
00187     {
00188         char dateFormat[256];
00189         char* timeZoneName = useLocalTime ? localTimeZoneAbbrev : "UTC";
00190         sprintf(dateFormat, "HH':'mm':'ss' %s'", timeZoneName);
00191         DateTime_SetFormat(timeItem, dateFormat);
00192         DateTime_SetSystemtime(timeItem, GDT_VALID, &sysTime);
00193     }
00194 }


Member Data Documentation

CelestiaCore* SetTimeDialog::appCore [private]
 

Definition at line 38 of file wintime.cpp.

Referenced by command(), and init().

HWND SetTimeDialog::hDlg [private]
 

Definition at line 37 of file wintime.cpp.

Referenced by command(), init(), notify(), and updateControls().

double SetTimeDialog::jd [private]
 

Definition at line 39 of file wintime.cpp.

Referenced by command(), getTime(), init(), notify(), setTime(), and updateControls().

char SetTimeDialog::localTimeZoneAbbrev[64] [private]
 

Definition at line 41 of file wintime.cpp.

Referenced by getLocalTimeZoneInfo(), SetTimeDialog(), and updateControls().

int SetTimeDialog::localTimeZoneBiasInSeconds [private]
 

Definition at line 43 of file wintime.cpp.

Referenced by getLocalTimeZoneInfo(), notify(), and updateControls().

char SetTimeDialog::localTimeZoneName[64] [private]
 

Definition at line 42 of file wintime.cpp.

Referenced by getLocalTimeZoneInfo(), init(), and SetTimeDialog().

bool SetTimeDialog::useLocalTime [private]
 

Definition at line 40 of file wintime.cpp.

Referenced by command(), init(), notify(), and updateControls().


The documentation for this class was generated from the following file:
Generated on Sat Jan 14 22:33:35 2006 for Celestia by  doxygen 1.4.1