forked from gopa810/gcal-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrameBase.cpp
454 lines (365 loc) · 11 KB
/
FrameBase.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
// FrameBase.cpp : implementation file
//
#include "stdafx.h"
#include "vcal5beta.h"
#include "FrameBase.h"
#include "LocationRef.h"
#include "enums.h"
#include "GCStrings.h"
#include "GCAyanamsha.h"
#include "GCDisplaySettings.h"
#include "GCGlobal.h"
#include "GCTextParser.h"
/////////////////////////////////////////////////////////////////////////////
// CFrameBase
//IMPLEMENT_DYNCREATE(CFrameBase, CFrameWnd)
CFrameBase::CFrameBase()
{
m_rectPrintMargins.SetRect(15,15,15,15);
m_bClosed = FALSE;
}
CFrameBase::~CFrameBase()
{
}
BEGIN_MESSAGE_MAP(CFrameBase, CFrameWnd)
ON_WM_INITMENU()
//{{AFX_MSG_MAP(CFrameBase)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_MOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFrameBase message handlers
void CFrameBase::InitBaseAttributes()
{
m_fontList.CreateFont(14,0,0,0,0,0,0,0,0,0,0,0,0, "Lucida Console");
m_fontInfo.CreateFont(32,0,0,0,0,0,0,0,0,0,0,0,0, "Tahoma");
}
int CFrameBase::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
InitBaseAttributes();
return 0;
}
int CFrameBase::AfxPrintCalendarText(CDC &dc, TResultCalendar &daybuff, CLocationRef & earth, VCTIME date
, int nDaysCount, CRect & rcPrint)
{
int k;
CString str, str2, str3, dayText;
VAISNAVADAY * pvd, * prevd, *nextd;
int lastmasa = -1;
int lastmonth = -1;
bool bStart = true;
bool bStarted = false;
CPoint midPoint;
int yCurr = rcPrint.top;
int nWidth;
int yLine = 0;
CString strLine, strPage, strHdr;
TString strt, strt2;
int nPage = 0, nLineCount = 0;
int nColumn[7];
yCurr = rcPrint.top;
midPoint = rcPrint.CenterPoint();
CSize sz;
double xRes = dc.GetDeviceCaps(LOGPIXELSX);
nColumn[0] = 0;
nColumn[1] = int(xRes * 1.5);
nColumn[2] = int(xRes * 4.85);
nColumn[3] = int(xRes * 5);
nColumn[4] = int(xRes * 6);
nColumn[5] = int(xRes * 7);
sz = dc.GetTextExtent("M", 1);
nColumn[6] = sz.cx;
for (k = 0; k < nDaysCount; k++)
{
date.shour = 0.0;
date.tzone = earth.m_fTimezone;
prevd = daybuff.GetDay(k - 1);
pvd = daybuff.GetDay(k);
nextd = daybuff.GetDay(k + 1);
if (pvd)
{
// zistuje kolko riadkov zaberie nasledujuci den
nLineCount = pvd->GetTextLineCount();
if ((yLine * nLineCount + yCurr) > rcPrint.bottom)
bStart = true;
if ((GCDisplaySettings::getValue(18) == 1) && (pvd->astrodata.nMasa != lastmasa))
{
strHdr.Format("%s %s, Gaurabda %d", GCStrings::GetMasaName(pvd->astrodata.nMasa), GCStrings::getString(22).c_str(), pvd->astrodata.nGaurabdaYear);
// if ((pvd->astrodata.nMasa == ADHIKA_MASA) && ((lastmasa >= SRIDHARA_MASA) && (lastmasa <= DAMODARA_MASA)))
{
// GCStringBuilder::AppendTwoColumnText(m_text, GCStrings::getString(128]);
}
lastmasa = pvd->astrodata.nMasa;
bStart = true;
}
if ((GCDisplaySettings::getValue(19) == 1) && (pvd->date.month != lastmonth))
{
strHdr.Format("%s %d", GCStrings::getString(759 + pvd->date.month).c_str(), pvd->date.year);
//m_text += " DATE TITHI PAKSA YOGA NAKSATRA FAST\r\n";
lastmonth = pvd->date.month;
bStart = true;
}
if (bStart)
{
if (bStarted == true)
dc.EndPage();
dc.StartPage();
yCurr = rcPrint.top;
bStarted = true;
dc.SelectObject(&m_fontPrintHdr);
// tlaci hlavicku
sz = dc.GetTextExtent(strHdr);
dc.TextOut(midPoint.x - sz.cx / 2, yCurr, strHdr);
yCurr += sz.cy + 8;
dc.SelectObject(&m_fontPrintText);
// location
str = this->earth.m_strName.c_str();
sz = dc.GetTextExtent(str);
dc.TextOut(midPoint.x - sz.cx / 2, yCurr + 10, str);
// version
sz = dc.GetTextExtent(GCStrings::getString(130).c_str(), GCStrings::getString(130).GetLength());
dc.TextOut(rcPrint.right - sz.cx, yCurr - sz.cy - 10, GCStrings::getString(130).c_str(), GCStrings::getString(130).GetLength());
// page
str.Format("%s %d", GCStrings::getString(162).c_str(), nPage);
nPage++;
sz = dc.GetTextExtent(str);
dc.TextOut(rcPrint.right - sz.cx, yCurr + 10, str);
// line
dc.MoveTo(rcPrint.left, yCurr - 4);
dc.LineTo(rcPrint.right, yCurr - 4);
yLine = sz.cy * 6 / 5;
yCurr += 3 * sz.cy;
str = GCStrings::getString(157);
dc.TextOut(rcPrint.left + nColumn[0] + 3*nColumn[6], yCurr, str);//DATE
str = GCStrings::getString(13);
str.MakeUpper();
dc.TextOut(rcPrint.left + nColumn[1], yCurr, str);//TITHI
str = GCStrings::getString(163);
sz = dc.GetTextExtent(str);
dc.TextOut(rcPrint.left + nColumn[2] - sz.cx, yCurr, str);
str = GCStrings::getString(104);
str.MakeUpper();
dc.TextOut(rcPrint.left + nColumn[3], yCurr, str);
str = GCStrings::getString(15);
str.MakeUpper();
dc.TextOut(rcPrint.left + nColumn[4], yCurr, str);
dc.TextOut(rcPrint.left + nColumn[5] - 2*nColumn[6], yCurr, "FAST", 4);
yCurr += yLine + 8;
dc.MoveTo(rcPrint.left, yCurr);
dc.LineTo(rcPrint.right, yCurr);
yCurr += 8;
bStart = false;
}
if (pvd->astrodata.sun.longitude_deg < 0.0)
{
continue;
}
str.Format("%d %s %d", pvd->date.day, GCStrings::GetMonthAbreviation(pvd->date.month), pvd->date.year);
sz = dc.GetTextExtent(str);
dc.TextOut(rcPrint.left + nColumn[0] + 11*nColumn[6] - nColumn[6]/2 - sz.cx, yCurr, str);
dc.TextOut(rcPrint.left + nColumn[0] + 11*nColumn[6] + nColumn[6]/2
, yCurr, LPCTSTR(GCStrings::getString(pvd->date.dayOfWeek)), 2);
str = pvd->GetFullTithiName().c_str();
dc.TextOut(rcPrint.left + nColumn[1], yCurr, str);
dc.TextOut(rcPrint.left + nColumn[2] - nColumn[6], yCurr, GCStrings::GetPaksaName(pvd->astrodata.nPaksa), 1);
str = GCStrings::GetYogaName(pvd->astrodata.nYoga);
dc.TextOut(rcPrint.left + nColumn[3], yCurr, str);
str = GCStrings::GetNaksatraName(pvd->astrodata.nNaksatra);
dc.TextOut(rcPrint.left + nColumn[4], yCurr, str);
if (pvd->nFastType >= EV_NULL)
dc.TextOut(rcPrint.left + nColumn[5], yCurr, "*", 1);
yCurr += yLine;
for(int i = 0; i < pvd->dayEvents.Count(); i++)
{
GCMutableDictionary * ed = pvd->dayEvents.ObjectAtIndex(i);
int disp = ed->intForKey("disp");
str = ed->stringForKey("text");
if (!ed->containsKey("disp") || disp == -1 || GCDisplaySettings::getValue(disp))
{
if (ed->containsKey("spec"))
{
sz = dc.GetTextExtent(str);
nWidth = sz.cx / 2;
dc.TextOut(midPoint.x - nWidth, yCurr, str);
dc.MoveTo(rcPrint.left, yCurr + sz.cy / 2);
dc.LineTo(midPoint.x - nWidth, yCurr + sz.cy / 2);
dc.MoveTo(midPoint.x + nWidth, yCurr + sz.cy / 2);
dc.LineTo(rcPrint.right, yCurr + sz.cy / 2);
}
else
{
dc.TextOut(rcPrint.left + nColumn[1], yCurr, str);
}
yCurr += yLine;
}
}
}
date.shour = 0;
date.NextDay();
}
dc.EndPage();
return 1;
}
int CFrameBase::PrintBlockText(CDC &pdc, TString &strTitle, TString &strText, int &nPage, CRect & rcPrint)
{
CPoint midPoint;
int yCurr = rcPrint.top;
int xOffset = 0;
int nPos = 0, nPrevPos = 0;
int nMaxWidth = 0;
TString strLine, strPage;
BOOL bStart = TRUE;
CString str;
yCurr = rcPrint.top;
midPoint = rcPrint.CenterPoint();
CSize sz;
// location text
// m_viewCond.m_edits[0].GetWindowText(strLocation);
// measure dimension of text
pdc.SelectObject(&m_fontPrintText);
str = strText.c_str();
sz = pdc.GetTextExtent(str);
GCTextParser parser;
parser.SetTarget(&strText);
while(parser.GetNextLine(strLine))
{
str = strLine.c_str();
sz = pdc.GetTextExtent(str);
if (sz.cx > nMaxWidth)
nMaxWidth = sz.cx;
}
xOffset = (rcPrint.Width() - nMaxWidth) / 2;
parser.SetTarget(&strText);
while(parser.GetNextLine(strLine))
{
if (strLine.IsEmpty())
strLine = " ";
if (bStart)
{
pdc.StartPage();
pdc.SelectObject(&m_fontPrintHdr);
// titul
str = strTitle.c_str();
sz = pdc.GetTextExtent(str);
pdc.TextOut( midPoint.x - sz.cx / 2, yCurr, str);
yCurr += sz.cy;
pdc.SelectObject(&m_fontPrintText);
// pozn o programe verzii
str = GCStrings::getString(130).c_str();
sz = pdc.GetTextExtent(str);
pdc.TextOut(rcPrint.right - sz.cx, yCurr - sz.cy - 5, str);
// cislo strany
strPage.Format("%s %d", GCStrings::getString(162).c_str(), nPage);
nPage++;
str = strPage.c_str();
sz = pdc.GetTextExtent(str);
pdc.TextOut(rcPrint.right - sz.cx, yCurr + 10, str);
// ciara
pdc.MoveTo( rcPrint.left, yCurr);
pdc.LineTo( rcPrint.right, yCurr);
yCurr += 10;
// lokacia
str = this->earth.m_strName.c_str();
sz = pdc.GetTextExtent(str);
pdc.TextOut( midPoint.x - sz.cx / 2, yCurr, str);
yCurr += 3 * sz.cy;
bStart = FALSE;
}
str = strLine.c_str();
sz = pdc.GetTextExtent(str);
if (sz.cy + yCurr > rcPrint.bottom)
{
nPos = nPrevPos;
bStart = TRUE;
pdc.EndPage();
yCurr = rcPrint.top;
}
else
{
pdc.TextOut(xOffset, yCurr, str);
yCurr += sz.cy;
}
nPrevPos = nPos;
}
pdc.EndPage();
return 0;
}
void CFrameBase::OnDestroy()
{
CFrameWnd::OnDestroy();
m_bClosed = TRUE;
}
void CFrameBase::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
GetWindowRect(m_rectWindow);
}
void CFrameBase::OnMove(int x, int y)
{
CFrameWnd::OnMove(x, y);
GetWindowRect(m_rectWindow);
}
void CFrameBase::OnInitMenu(CMenu* pMenu)
{
CFrameWnd::OnInitMenu(pMenu);
// CG: This block added by 'Tip of the Day' component.
{
// TODO: This code adds the "Tip of the Day" menu item
// on the fly. It may be removed after adding the menu
// item to all applicable menu items using the resource
// editor.
// Add Tip of the Day menu item on the fly!
static CMenu* pSubMenu = NULL;
CString strHelp; strHelp.LoadString(CG_IDS_TIPOFTHEDAYHELP);
CString strMenu;
int nMenuCount = pMenu->GetMenuItemCount();
BOOL bFound = FALSE;
for (int i=0; i < nMenuCount; i++)
{
pMenu->GetMenuString(i, strMenu, MF_BYPOSITION);
if (strMenu == strHelp)
{
pSubMenu = pMenu->GetSubMenu(i);
bFound = TRUE;
ASSERT(pSubMenu != NULL);
}
}
CString strTipMenu;
strTipMenu.LoadString(CG_IDS_TIPOFTHEDAYMENU);
if (!bFound)
{
// Help menu is not available. Please add it!
if (pSubMenu == NULL)
{
// The same pop-up menu is shared between mainfrm and frame
// with the doc.
static CMenu popUpMenu;
pSubMenu = &popUpMenu;
pSubMenu->CreatePopupMenu();
pSubMenu->InsertMenu(0, MF_STRING|MF_BYPOSITION,
CG_IDS_TIPOFTHEDAY, strTipMenu);
}
pMenu->AppendMenu(MF_STRING|MF_BYPOSITION|MF_ENABLED|MF_POPUP,
(UINT)pSubMenu->m_hMenu, strHelp);
DrawMenuBar();
}
else
{
// Check to see if the Tip of the Day menu has already been added.
pSubMenu->GetMenuString(0, strMenu, MF_BYPOSITION);
if (strMenu != strTipMenu)
{
// Tip of the Day submenu has not been added to the
// first position, so add it.
pSubMenu->InsertMenu(0, MF_BYPOSITION); // Separator
pSubMenu->InsertMenu(0, MF_STRING|MF_BYPOSITION,
CG_IDS_TIPOFTHEDAY, strTipMenu);
}
}
}
}