forked from gopa810/gcal-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDlgGetLocation.cpp
498 lines (410 loc) · 13.7 KB
/
DlgGetLocation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
// DlgGetLocation.cpp : implementation file
//
#include "stdafx.h"
#include "vcal5beta.h"
#include "DlgGetLocation.h"
#include "DlgGetLocationEx.h"
#include "GCMath.h"
#include "TTimeZone.h"
#include "GCStrings.h"
#include "GCGlobal.h"
#include "GCUserInterface.h"
#include "Location.h"
/////////////////////////////////////////////////////////////////////////////
// DlgGetLocation dialog
DlgGetLocation::DlgGetLocation(LPCTSTR szTitle, CWnd* pParent /*=NULL*/)
: CDialog(DlgGetLocation::IDD, pParent)
{
// m_pfont = pFont;
m_bMyLocation = FALSE;
m_nNextStep = 0;
//{{AFX_DATA_INIT(DlgGetLocation)
//}}AFX_DATA_INIT
m_strTitle = szTitle;
m_bFinal = FALSE;
m_latiSign = 1.0;
m_longSign = 1.0;
b_upd = true;
m_nLastDst = 0;
wrongCoordinates = FALSE;
errorText = "";
}
void DlgGetLocation::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgGetLocation)
DDX_Control(pDX, IDC_BTN_LONG, cLongSw);
DDX_Control(pDX, IDC_BTN_LATI, cLatiSw);
DDX_Control(pDX, IDC_LONG_DEG, cLongDeg);
DDX_Control(pDX, IDC_LONG_ARC, cLongArc);
DDX_Control(pDX, IDC_LATI_DEG, cLatiDeg);
DDX_Control(pDX, IDC_LATI_ARC, cLatiArc);
DDX_Control(pDX, IDC_COMBO_DST, cDst);
DDX_Control(pDX, IDC_EDIT5, cLocName);
DDX_Control(pDX, IDC_DST_INFO, cDstInfo);
DDX_Control(pDX, IDC_STATIC1, m_hdr);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgGetLocation, CDialog)
//{{AFX_MSG_MAP(DlgGetLocation)
ON_BN_CLICKED(IDC_BUTTON1, OnSelectLocation)
ON_BN_CLICKED(ID_BUTTON_BACK, OnButtonBack)
ON_BN_CLICKED(ID_BUTTON_NEXT, OnButtonNext)
ON_CBN_SELENDOK(IDC_COMBO_DST, OnSelendokComboDst)
ON_CBN_DROPDOWN(IDC_COMBO_DST, OnDropdownComboDst)
ON_BN_CLICKED(IDC_BTN_LONG, OnBtnLong)
ON_BN_CLICKED(IDC_BTN_LATI, OnBtnLati)
ON_EN_CHANGE(IDC_LATI_ARC, OnChangeLatiArc)
ON_EN_CHANGE(IDC_LATI_DEG, OnChangeLatiDeg)
ON_EN_CHANGE(IDC_LONG_ARC, OnChangeLongArc)
ON_EN_CHANGE(IDC_LONG_DEG, OnChangeLongDeg)
ON_EN_CHANGE(IDC_EDIT5, OnChangeLocation)
//}}AFX_MSG_MAP
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
int DlgGetLocation::LocGetDeg(double d)
{
return int(floor(fabs(d)));
}
int DlgGetLocation::LocGetArc(double d)
{
double a = fabs(d);
return int((a - floor(a))* 60.0 + 0.5);
}
/////////////////////////////////////////////////////////////////////////////
// DlgGetLocation message handlers
void DlgGetLocation::OnSelectLocation()
{
// TODO: Add your control notification handler code here
//CDlgSelectLocation d;
DlgGetLocationEx d;
if (d.DoModal() == IDOK)
{
// this is part: DIALOG.RESULT TO LOCATION
m_location.m_fLongitude = d.m_lc->m_fLongitude;
m_location.m_fLatitude = d.m_lc->m_fLatitude;
m_location.m_fTimezone = d.m_lc->m_fTimezone;
m_location.m_strName = d.m_lc->m_strCity;
m_location.m_strName += " [";
m_location.m_strName += d.m_lc->m_strCountry;
m_location.m_strName += "]";
m_location.m_nDST = d.m_lc->m_nTimezoneId;
// this is part: LOCATION TO DIALOG
cLocName.SetWindowText(m_location.m_strName);
b_upd = false;
SetDlgItemInt(IDC_LATI_DEG, LocGetDeg(d.m_lc->m_fLatitude));
SetDlgItemInt(IDC_LATI_ARC, LocGetArc(d.m_lc->m_fLatitude));
SetDlgItemInt(IDC_LONG_DEG, LocGetDeg(d.m_lc->m_fLongitude));
SetDlgItemInt(IDC_LONG_ARC, LocGetArc(d.m_lc->m_fLongitude));
cLatiSw.SetWindowText(GCStrings::getLatitudeDirectionName(d.m_lc->m_fLatitude));
cLongSw.SetWindowText(GCStrings::getLongitudeDirectionName(d.m_lc->m_fLongitude));
m_latiSign = GCMath::getSign(d.m_lc->m_fLatitude);
m_longSign = GCMath::getSign(d.m_lc->m_fLongitude);
b_upd = true;
//UpdateDstByTimezone(m_location.m_fTimezone);
//cLat.SetWindowText(EARTHDATA::GetTextLatitude());
//cLong.SetWindowText(EARTHDATA::GetTextLongitude());
//cTimezone.SetCurSel(AvcGetNearestTimeZone(d.m_lc->m_fTimezone));
SetCurSelDST(d.m_lc->m_nTimezoneId);
}
}
//============================================================================
//
//============================================================================
void DlgGetLocation::OnButtonBack()
{
// TODO: Add your control notification handler code here
m_nNextStep = -1;
CDialog::OnCancel();
}
//============================================================================
//
//============================================================================
void DlgGetLocation::OnButtonNext()
{
CString str;
m_location.m_nDST = cDst.GetItemData(cDst.GetCurSel());
cLocName.GetWindowText(str);
m_location.m_strName = str;
m_location.m_fTimezone = TTimeZone::GetTimeZoneOffset(m_location.m_nDST);
m_location.m_strLatitude = EARTHDATA::GetTextLatitude(m_location.m_fLatitude);
m_location.m_strLongitude = EARTHDATA::GetTextLongitude(m_location.m_fLongitude);
m_location.m_strTimeZone = TTimeZone::GetTimeZoneOffsetText(m_location.m_fTimezone);
m_location.m_strFullName.Format("%s (%s %s, %s)",
m_location.m_strName.c_str(),
m_location.m_strLatitude.c_str(),
m_location.m_strLongitude.c_str(),
m_location.m_strTimeZone.c_str());
// TODO: Add your control notification handler code here
if (m_bMyLocation)
{
GCGlobal::myLocation.Set(m_location);
}
GCGlobal::lastLocation.Set(m_location);
m_nNextStep = 1;
CDialog::OnOK();
}
//============================================================================
//
//============================================================================
BOOL DlgGetLocation::OnInitDialog()
{
int n, m, c;
if (m_bFinal == TRUE)
{
GetDlgItem(ID_BUTTON_NEXT)->SetWindowText("Set");
}
if (m_bMyLocation)
{
m_location.Set(GCGlobal::myLocation);
}
else
{
m_location.Set(GCGlobal::lastLocation);
}
CDialog::OnInitDialog();
m_hdr.InitMyFont();
m_hdr.SetWindowText(m_strTitle);
m = TTimeZone::GetTimeZoneCount();
cDst.ResetContent();
for(n = 0; n < m; n++)
{
c = cDst.AddString(TTimeZone::gzone[n].name);
cDst.SetItemData(c, TTimeZone::gzone[n].idx);
}
cLocName.SetWindowText(m_location.m_strName);
LocationToDialog();
m_nNextStep = 0;
CheckDlgButton(IDC_CHECK1, 0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//============================================================================
//
//============================================================================
void DlgGetLocation::LocationToDialog()
{
b_upd = false;
SetDlgItemInt(IDC_LATI_DEG, LocGetDeg(m_location.m_fLatitude));
SetDlgItemInt(IDC_LATI_ARC, LocGetArc(m_location.m_fLatitude));
SetDlgItemInt(IDC_LONG_DEG, LocGetDeg(m_location.m_fLongitude));
SetDlgItemInt(IDC_LONG_ARC, LocGetArc(m_location.m_fLongitude));
cLatiSw.SetWindowText(GCStrings::getLatitudeDirectionName(m_location.m_fLatitude));
cLongSw.SetWindowText(GCStrings::getLongitudeDirectionName(m_location.m_fLongitude));
b_upd = true;
SetCurSelDST(m_location.m_nDST);
}
//============================================================================
//
//============================================================================
void DlgGetLocation::GetEarthData(EARTHDATA &earth)
{
earth.latitude_deg = m_location.m_fLatitude;
earth.longitude_deg = m_location.m_fLongitude;
earth.tzone = m_location.m_fTimezone;
earth.dst = m_location.m_nDST;
}
//============================================================================
//
//============================================================================
void DlgGetLocation::OnSelendokComboDst()
{
UpdateDSTInfo();
CheckDlgButton(IDC_CHECK1, 0);
}
//============================================================================
//
//============================================================================
void DlgGetLocation::UpdateDSTInfo()
{
TString str, ret;
if (wrongCoordinates)
{
cDstInfo.SetWindowTextA(errorText);
return;
}
int i = cDst.GetItemData( cDst.GetCurSel() );
if (i < 0 || i >= TTimeZone::GetTimeZoneCount())
return;
DWORD dw = TTimeZone::gzone[TTimeZone::ID2INDEX(i)].val;
// cTimezone.SetCurSel( AvcGetNearestTimeZone( TTimeZone::gzone[i].tzone));
int a[8];
if (dw == 0)
{
ret = GCStrings::getString(807);
}
else
{
TTimeZone::ExpandVal(dw, a);
ret = GCStrings::getString(808);
// pre datumovy den
if (a[1] == 1)
{
str.Format("since %s %s ", GCStrings::getString(a[2] + 810).c_str(), GCStrings::getString(a[0] + 794).c_str());
//SetDlgItemText(IDC_STATIC_DST_INFO1, str);
}
else
{
// pre tyzdenny den
str.Format("since %s %s %s ", GCStrings::getString(a[2] + 781).c_str(), GCStrings::getString(a[3] + 787).c_str(), GCStrings::getString(a[0] + 794).c_str());
//SetDlgItemText(IDC_STATIC_DST_INFO1, str);
}
ret += str;
if (a[5] == 1)
{
str.Format("to %s %s", GCStrings::getString(810 + a[6]).c_str(), GCStrings::getString(a[4] + 794).c_str());
//SetDlgItemText(IDC_STATIC_DST_INFO2, str);
}
else
{
// pre tyzdenny den
str.Format("to %s %s %s", GCStrings::getString(a[6] + 781).c_str(), GCStrings::getString(a[7] + 787).c_str(), GCStrings::getString(a[4] + 794).c_str());
//SetDlgItemText(IDC_STATIC_DST_INFO2, str);
}
ret += str;
}
cDstInfo.SetWindowText(ret);
}
//============================================================================
//
//============================================================================
int DlgGetLocation::UpdateDstByTimezone(double tzone)
{
int n, m = TTimeZone::GetTimeZoneCount();
int found = 0;
if (IsDlgButtonChecked(IDC_CHECK1)==0)
return 0;
// return 1;
double lon = (fabs(m_location.m_fLongitude)+7.5)/15.0;
if (m_location.m_fLongitude<0.0)
lon = -lon;
for(n = 0; n < m; n++)
{
if (TTimeZone::gzone[n].offset >= int(lon)*60)
{
cDst.SetCurSel(n);
break;
}
}
UpdateDSTInfo();
return 1;
}
//============================================================================
//
//============================================================================
void DlgGetLocation::OnDropdownComboDst()
{
//m_location.m_fTimezone = AvcGetTimeZone(cTimezone.GetCurSel());
//UpdateDstByTimezone(m_location.m_fTimezone);
}
void DlgGetLocation::OnBtnLong()
{
m_longSign = -m_longSign;
if (GCUserInterface::dstSelectionMethod == 2 && b_upd == true)
{
m_location.m_fLongitude = m_longSign * (double(GetDlgItemInt(IDC_LONG_DEG)) + double(GetDlgItemInt(IDC_LONG_ARC))/60.0);
UpdateDstByTimezone(m_location.m_fTimezone);
}
SetDlgItemText(IDC_BTN_LONG, GCStrings::getLongitudeDirectionName(m_longSign));
}
void DlgGetLocation::OnBtnLati()
{
m_latiSign = -m_latiSign;
if (GCUserInterface::dstSelectionMethod == 2 && b_upd == true)
{
m_location.m_fLatitude = m_latiSign * (double(GetDlgItemInt(IDC_LATI_DEG)) + double(GetDlgItemInt(IDC_LATI_ARC))/60.0);
UpdateDstByTimezone(m_location.m_fTimezone);
}
SetDlgItemText(IDC_BTN_LATI, GCStrings::getLatitudeDirectionName(m_latiSign));
}
void DlgGetLocation::OnChangeLatiArc()
{
if (GCUserInterface::dstSelectionMethod == 2 && b_upd == true)
{
m_location.m_fLatitude = m_latiSign * (double(GetDlgItemInt(IDC_LATI_DEG)) + double(GetDlgItemInt(IDC_LATI_ARC))/60.0);
UpdateDstByTimezone(m_location.m_fTimezone);
}
}
void DlgGetLocation::OnChangeLatiDeg()
{
if (GCUserInterface::dstSelectionMethod == 2 && b_upd == true)
{
m_location.m_fLatitude = m_latiSign * (double(GetDlgItemInt(IDC_LATI_DEG)) + double(GetDlgItemInt(IDC_LATI_ARC))/60.0);
UpdateDstByTimezone(m_location.m_fTimezone);
}
}
void DlgGetLocation::OnChangeLongArc()
{
if (GCUserInterface::dstSelectionMethod == 2 && b_upd == true)
{
m_location.m_fLongitude = m_longSign * (double(GetDlgItemInt(IDC_LONG_DEG)) + double(GetDlgItemInt(IDC_LONG_ARC))/60.0);
UpdateDstByTimezone(m_location.m_fTimezone);
}
}
void DlgGetLocation::OnChangeLongDeg()
{
if (GCUserInterface::dstSelectionMethod == 2 && b_upd == true)
{
m_location.m_fLongitude = m_longSign * (double(GetDlgItemInt(IDC_LONG_DEG)) + double(GetDlgItemInt(IDC_LONG_ARC))/60.0);
UpdateDstByTimezone(m_location.m_fTimezone);
}
}
int DlgGetLocation::SetCurSelDST(int nID)
{
int i, m = cDst.GetCount();
m_nLastDst = nID;
for(i = 0; i< m; i++)
{
if (cDst.GetItemData(i) == nID)
{
cDst.SetCurSel(i);
UpdateDSTInfo();
return 1;
}
}
m_nLastDst = 0;
cDst.SetCurSel(0);
UpdateDSTInfo();
return 0;
}
void DlgGetLocation::OnChangeLocation()
{
CheckDlgButton(IDC_CHECK1, 1);
}
HBRUSH DlgGetLocation::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
COLORREF redColor = RGB(255,0,0);
COLORREF blackColor = RGB(0,0,0);
// TODO: Change any attributes of the DC here
if (nCtlColor == CTLCOLOR_EDIT)
{
BOOL wrongLongDeg = GetDlgItemInt(IDC_LONG_DEG) > 180;
BOOL wrongLongArc = GetDlgItemInt(IDC_LONG_ARC) > 59;
BOOL wrongLatiDeg = GetDlgItemInt(IDC_LATI_DEG) > 90;
BOOL wrongLatiArc = GetDlgItemInt(IDC_LATI_ARC) > 59;
wrongCoordinates = wrongLatiArc | wrongLatiDeg | wrongLongArc | wrongLongDeg;
if (pWnd->GetDlgCtrlID() == IDC_LONG_ARC) {
pDC->SetTextColor(wrongLongArc ? redColor : blackColor);
if (wrongLongArc) cDstInfo.SetWindowTextA("Longitude Minutes must be from range 0 - 59");
} else if (pWnd->GetDlgCtrlID() == IDC_LONG_DEG) {
pDC->SetTextColor(wrongLongDeg ? redColor : blackColor);
if (wrongLongDeg) cDstInfo.SetWindowTextA("Longitude Degrees must be from range 0 - 180");
} else if (pWnd->GetDlgCtrlID() == IDC_LATI_ARC) {
pDC->SetTextColor(wrongLatiArc ? redColor : blackColor);
if (wrongLatiArc) cDstInfo.SetWindowTextA("Latitude Minutes must be from range 0 - 59");
} else if (pWnd->GetDlgCtrlID() == IDC_LATI_DEG) {
pDC->SetTextColor(wrongLatiDeg ? redColor : blackColor);
if (wrongLatiDeg) cDstInfo.SetWindowTextA("Latitude Degrees must be from range 0 - 90");
}
if (!wrongCoordinates) UpdateDSTInfo();
}
if (nCtlColor == CTLCOLOR_STATIC)
{
if (pWnd->GetDlgCtrlID() == IDC_DST_INFO){
pDC->SetTextColor(wrongCoordinates ? redColor : blackColor);
}
}
// TODO: Return a different brush if the default is not desired
return hbr;
}