1
|
#include "stdafx.h"
|
2
|
#include "graph\eg_powerobjects.h"
|
3
|
#include "graph\eg_util.h"
|
4
|
#include "graph\eg_global.h"
|
5
|
#include <math.h>
|
6
|
STRUCT_GRPCOLINFO ClockColInfo[]=
|
7
|
{
|
8
|
{"??ʾ????",1,0,1},{"??ʾ????",1,1,1},{"??ʾʱ??",1,2,1},
|
9
|
{"??ʾ??",1,3,1},{"ʱ??????",1,4,1},{"??ʾ????????",1,5,1},{"ˮƽ??ʾ",1,6,1}
|
10
|
|
11
|
};
|
12
|
const ClockColNum=sizeof(ClockColInfo)/sizeof(STRUCT_GRPCOLINFO);
|
13
|
STRUCT_FILECOLINFO *CClockObj::m_FileColInfo=NULL;
|
14
|
STRUCT_FILECOLBASEINFO CClockObj::m_FileColBaseInfo={0,0};
|
15
|
|
16
|
BOOL CClockObj::RWPicFile(FILE *fp,unsigned char writeflag)
|
17
|
{
|
18
|
CRectObj::RWPicFile(fp,writeflag);
|
19
|
STRUCT_FILECOLBASEINFO nowbaseinfo;
|
20
|
nowbaseinfo.colnum=ClockColNum;
|
21
|
nowbaseinfo.rcdlen=sizeof(m_ClockInfo);
|
22
|
if(writeflag==0)
|
23
|
InitClockInfo();
|
24
|
return Base_RWPicFile(fp,writeflag,nowbaseinfo,ClockColInfo,
|
25
|
m_FileColBaseInfo,m_FileColInfo,&m_ClockInfo);
|
26
|
}
|
27
|
BOOL CClockObj::RWPicColInfo(FILE *fp,unsigned char writeflag)
|
28
|
{
|
29
|
STRUCT_FILECOLBASEINFO baseinfo;
|
30
|
baseinfo.colnum=ClockColNum;
|
31
|
baseinfo.rcdlen=sizeof(STRUCT_CLOCKINFO);
|
32
|
return RWGrpClassColInfo(fp,writeflag,baseinfo,ClockColInfo,m_FileColBaseInfo,&m_FileColInfo);
|
33
|
}
|
34
|
BOOL CClockObj::FreeColInfo()
|
35
|
{
|
36
|
m_FileColBaseInfo.colnum=0;
|
37
|
m_FileColBaseInfo.rcdlen=0;
|
38
|
if(m_FileColInfo)
|
39
|
free(m_FileColInfo);
|
40
|
m_FileColInfo=NULL;
|
41
|
return TRUE;
|
42
|
}
|
43
|
|
44
|
CClockObj::CClockObj()
|
45
|
: CRectObj()
|
46
|
{
|
47
|
m_shape = OS_CLOCK;
|
48
|
InitClockInfo();
|
49
|
}
|
50
|
|
51
|
CClockObj::CClockObj(const CFRect& rcpos)
|
52
|
: CRectObj(rcpos)
|
53
|
{
|
54
|
m_shape = OS_CLOCK;
|
55
|
InitClockInfo();
|
56
|
}
|
57
|
|
58
|
CClockObj::~CClockObj()
|
59
|
{
|
60
|
}
|
61
|
|
62
|
static char *WeekDayStr[]={"??????","????һ","???ڶ?","??????","??????","??????","??????"};
|
63
|
void CClockObj::Draw(CDC* pdc, CTransDriver *trans)
|
64
|
{
|
65
|
|
66
|
if (!CanDrawNow())
|
67
|
return;
|
68
|
BOOL printflag=0;
|
69
|
if(pdc->IsPrinting()) printflag=1;
|
70
|
char datestr[256],weekstr[256],timestr[256];
|
71
|
CTime curtime=CTime::GetCurrentTime();
|
72
|
int rownum=0;
|
73
|
strcpy(datestr,"");
|
74
|
strcpy(weekstr,"");
|
75
|
strcpy(timestr,"");
|
76
|
if(m_ClockInfo.DateFlag)
|
77
|
{
|
78
|
rownum++;
|
79
|
if(m_ClockInfo.YearFlag)//WYF 20180703 ?? ?? ?ո?ʽ?ij?2018/7/3
|
80
|
if(m_ClockInfo.Text3DFlag)
|
81
|
// sprintf(datestr,"%04d??%02d??%02d??",curtime.GetYear(),curtime.GetMonth(),curtime.GetDay());
|
82
|
sprintf(datestr,"%04d-%02d-%02d",curtime.GetYear(),curtime.GetMonth(),curtime.GetDay());
|
83
|
else
|
84
|
sprintf(datestr,"%04d/%02d/%02d",curtime.GetYear(),curtime.GetMonth(),curtime.GetDay());
|
85
|
else
|
86
|
sprintf(datestr,"%02d??%02d??",
|
87
|
curtime.GetMonth(),curtime.GetDay());
|
88
|
}
|
89
|
else
|
90
|
{
|
91
|
if(m_ClockInfo.YearFlag)
|
92
|
{
|
93
|
rownum++;
|
94
|
sprintf(datestr,"%04d??",curtime.GetYear());
|
95
|
}
|
96
|
}
|
97
|
if(m_ClockInfo.WeekFlag)
|
98
|
{
|
99
|
rownum++;
|
100
|
int weezxay=curtime.GetDayOfWeek();
|
101
|
if(weezxay>0&&weezxay<8)
|
102
|
strcpy(weekstr,WeekDayStr[weezxay-1]);
|
103
|
}
|
104
|
if(m_ClockInfo.TimeFlag)
|
105
|
{
|
106
|
rownum++;
|
107
|
if(m_ClockInfo.TimeType==0)
|
108
|
sprintf(timestr,"%02d:%02d:%02d",curtime.GetHour(),curtime.GetMinute(),
|
109
|
curtime.GetSecond());
|
110
|
else
|
111
|
sprintf(timestr,"%02dʱ%02d??%02d??",curtime.GetHour(),curtime.GetMinute(),
|
112
|
curtime.GetSecond());
|
113
|
}
|
114
|
|
115
|
unsigned int maxlen;
|
116
|
if(m_ClockInfo.IsHorizental)
|
117
|
{
|
118
|
maxlen=strlen(datestr)+1+strlen(weekstr)+1+strlen(timestr);
|
119
|
rownum=1;
|
120
|
}
|
121
|
else
|
122
|
{
|
123
|
maxlen=max(strlen(datestr),strlen(weekstr));
|
124
|
maxlen=max(maxlen,strlen(timestr));
|
125
|
}
|
126
|
if(maxlen<=0)
|
127
|
{
|
128
|
DrawHandle(pdc, trans);
|
129
|
return;
|
130
|
}
|
131
|
if(rownum<=0)
|
132
|
{
|
133
|
DrawHandle(pdc, trans);
|
134
|
return;
|
135
|
}
|
136
|
|
137
|
CFRect drawrect=m_BaseObjInfo.rectpos;
|
138
|
//LPtoDP(&drawrect);
|
139
|
trans->MapToClient(&drawrect);
|
140
|
|
141
|
int texthigh=int(1.5*double(drawrect.Width())/double(maxlen));
|
142
|
int rowhigh=(int)(drawrect.Height()/rownum);
|
143
|
if(texthigh>rowhigh)
|
144
|
texthigh=rowhigh;
|
145
|
|
146
|
CLineStyle drawLineStyle = m_lineStyle;
|
147
|
if (m_status == ST_SELECT && !CGlobal::m_IsPaintFlag)
|
148
|
{
|
149
|
drawLineStyle.penColor = CGlobal::slctLineStyle.penColor;
|
150
|
}
|
151
|
CBrushStyle drawBrushStyle = m_brushStyle;
|
152
|
if (m_status == ST_SELECT && !CGlobal::m_IsPaintFlag)
|
153
|
{
|
154
|
drawBrushStyle.BackColor = CGlobal::slctBrushStyle.BackColor;
|
155
|
}
|
156
|
//end
|
157
|
|
158
|
LOGFONT lf;
|
159
|
CRect textrect;
|
160
|
|
161
|
memset(&lf,0,sizeof(lf));
|
162
|
lf.lfHeight =-texthigh;
|
163
|
lf.lfCharSet =GB2312_CHARSET; //????GB2312????
|
164
|
strcpy(lf.lfFaceName, "????");
|
165
|
COLORREF fore=drawLineStyle.penColor;
|
166
|
COLORREF back=drawBrushStyle.BackColor;
|
167
|
if(printflag)
|
168
|
{
|
169
|
fore=GetPrintColor(pdc,fore,CGlobal::m_GrpBackColor);
|
170
|
back=GetPrintColor(pdc,back,CGlobal::m_GrpBackColor);
|
171
|
}
|
172
|
// Create new font
|
173
|
CFont m_font;
|
174
|
m_font.CreateFontIndirect(&lf);
|
175
|
CFont *oldfont=pdc->SelectObject(&m_font);
|
176
|
COLORREF oldcolor=pdc->SetTextColor(fore);
|
177
|
int oldmode = pdc->SetBkMode(TRANSPARENT);
|
178
|
rownum=0;
|
179
|
|
180
|
char tmpstr[256];
|
181
|
strcpy(tmpstr,"");
|
182
|
if(m_ClockInfo.DateFlag || m_ClockInfo.YearFlag)
|
183
|
{
|
184
|
strcat(tmpstr,datestr);
|
185
|
strcat(tmpstr," ");
|
186
|
}
|
187
|
if(m_ClockInfo.WeekFlag)
|
188
|
{
|
189
|
strcat(tmpstr,weekstr);
|
190
|
strcat(tmpstr," ");
|
191
|
}
|
192
|
if(m_ClockInfo.TimeFlag)
|
193
|
strcat(tmpstr,timestr);
|
194
|
|
195
|
if(m_ClockInfo.Text3DFlag)
|
196
|
{
|
197
|
textrect.left=(long)(drawrect.left+1);
|
198
|
textrect.right=(long)drawrect.right+1;
|
199
|
pdc->SetTextColor(back);
|
200
|
if(m_ClockInfo.IsHorizental)
|
201
|
{
|
202
|
textrect.top=(long)(drawrect.top+1);
|
203
|
textrect.bottom=(long)(drawrect.bottom+1);
|
204
|
pdc->DrawText(tmpstr,strlen(tmpstr),textrect,DT_CENTER);//|DT_BOTTOM|DT_SINGLELINE);
|
205
|
}
|
206
|
else
|
207
|
{
|
208
|
if(m_ClockInfo.DateFlag || m_ClockInfo.YearFlag)
|
209
|
{
|
210
|
textrect.top=(long)drawrect.top+rownum*rowhigh+1;
|
211
|
textrect.bottom=(long)drawrect.top+(rownum+1)*rowhigh+1;
|
212
|
pdc->DrawText(datestr,strlen(datestr),textrect,DT_CENTER);//|DT_BOTTOM|DT_SINGLELINE);
|
213
|
rownum++;
|
214
|
}
|
215
|
if(m_ClockInfo.WeekFlag)
|
216
|
{
|
217
|
textrect.top=(long)drawrect.top+rownum*rowhigh+1;
|
218
|
textrect.bottom=(long)drawrect.top+(rownum+1)*rowhigh+1;
|
219
|
pdc->DrawText(weekstr,strlen(weekstr),textrect,DT_CENTER);//|DT_VCENTER|DT_SINGLELINE);
|
220
|
rownum++;
|
221
|
}
|
222
|
if(m_ClockInfo.TimeFlag)
|
223
|
{
|
224
|
textrect.top=(long)drawrect.top+rownum*rowhigh+1;
|
225
|
textrect.bottom=(long)drawrect.top+(rownum+1)*rowhigh+1;
|
226
|
pdc->DrawText(timestr,strlen(timestr),textrect,DT_CENTER);//|DT_TOP|DT_SINGLELINE);
|
227
|
rownum++;
|
228
|
}
|
229
|
}
|
230
|
}
|
231
|
textrect=CRect((long)drawrect.left,(long)drawrect.top,(long)drawrect.right,(long)drawrect.bottom);
|
232
|
rownum=0;
|
233
|
pdc->SetTextColor(fore);
|
234
|
if(m_ClockInfo.IsHorizental)
|
235
|
pdc->DrawText(tmpstr,strlen(tmpstr),textrect,DT_CENTER);//|DT_BOTTOM|DT_SINGLELINE);
|
236
|
else
|
237
|
{
|
238
|
if(m_ClockInfo.DateFlag || m_ClockInfo.YearFlag)
|
239
|
{
|
240
|
textrect.top=(long)drawrect.top+rownum*rowhigh;
|
241
|
textrect.bottom=(long)drawrect.top+(rownum+1)*rowhigh;
|
242
|
pdc->DrawText(datestr,strlen(datestr),textrect,DT_CENTER);//|DT_BOTTOM|DT_SINGLELINE);
|
243
|
rownum++;
|
244
|
}
|
245
|
if(m_ClockInfo.WeekFlag)
|
246
|
{
|
247
|
textrect.top=(long)drawrect.top+rownum*rowhigh;
|
248
|
textrect.bottom=(long)drawrect.top+(rownum+1)*rowhigh;
|
249
|
pdc->DrawText(weekstr,strlen(weekstr),textrect,DT_CENTER);//|DT_VCENTER|DT_SINGLELINE);
|
250
|
rownum++;
|
251
|
}
|
252
|
if(m_ClockInfo.TimeFlag)
|
253
|
{
|
254
|
textrect.top=(long)drawrect.top+rownum*rowhigh;
|
255
|
textrect.bottom=(long)drawrect.top+(rownum+1)*rowhigh;
|
256
|
pdc->DrawText(timestr,strlen(timestr),textrect,DT_CENTER);//|DT_TOP|DT_SINGLELINE);
|
257
|
rownum++;
|
258
|
}
|
259
|
}
|
260
|
pdc->SetTextColor(oldcolor);
|
261
|
pdc->SelectObject(oldfont);
|
262
|
pdc->SetBkMode(oldmode);
|
263
|
m_font.DeleteObject();
|
264
|
|
265
|
DrawHandle(pdc, trans);
|
266
|
}
|
267
|
UINT CClockObj::GetHandleCount()
|
268
|
{
|
269
|
return 4;
|
270
|
}
|
271
|
|
272
|
CBaseObj* CClockObj::Clone()
|
273
|
{
|
274
|
|
275
|
CClockObj* pObj = new CClockObj(m_BaseObjInfo.rectpos);
|
276
|
if (pObj == NULL)
|
277
|
return NULL;
|
278
|
|
279
|
RectClone(pObj);
|
280
|
|
281
|
pObj->m_ClockInfo = m_ClockInfo;
|
282
|
|
283
|
return pObj;
|
284
|
}
|
285
|
|
286
|
//??????
|
287
|
BOOL CClockObj::SetObjectProp(CBaseObj* pFromObj)
|
288
|
{
|
289
|
if(CRectObj::SetObjectProp(pFromObj) == FALSE)
|
290
|
return FALSE;
|
291
|
|
292
|
m_ClockInfo = ((CClockObj *)pFromObj)->m_ClockInfo;
|
293
|
|
294
|
return TRUE;
|
295
|
}
|
296
|
|
297
|
void CClockObj::InitClockInfo()
|
298
|
{
|
299
|
m_ClockInfo.DateFlag=1;
|
300
|
m_ClockInfo.WeekFlag=1;
|
301
|
m_ClockInfo.TimeFlag=1;
|
302
|
m_ClockInfo.TimeType=0;
|
303
|
m_ClockInfo.YearFlag=1;
|
304
|
m_ClockInfo.Text3DFlag=1;
|
305
|
m_ClockInfo.IsHorizental=0;
|
306
|
}
|
307
|
int CClockObj::GetObjLength()
|
308
|
{
|
309
|
int len=CRectObj::GetObjLength();
|
310
|
len+=sizeof(m_ClockInfo);
|
311
|
return len;
|
312
|
}
|
313
|
|
314
|
BOOL CClockObj::SetObjectData(char *buffer, int &buflen)
|
315
|
{
|
316
|
int len = 0;
|
317
|
char *buf = buffer;
|
318
|
|
319
|
CRectObj::SetObjectData(buf, len);
|
320
|
buf = buf + len;
|
321
|
|
322
|
memcpy(&m_ClockInfo, buf, sizeof(STRUCT_CLOCKINFO));
|
323
|
len += sizeof(STRUCT_CLOCKINFO);
|
324
|
|
325
|
buflen = len;
|
326
|
return TRUE;
|
327
|
}
|
328
|
|
329
|
BOOL CClockObj::GetObjectData(char **objdata)
|
330
|
{
|
331
|
char *buf = *objdata;
|
332
|
|
333
|
CRectObj::GetObjectData(&buf);
|
334
|
buf = buf + CRectObj::GetObjLength();
|
335
|
|
336
|
memcpy(buf, &m_ClockInfo, sizeof(STRUCT_CLOCKINFO));
|
337
|
|
338
|
return TRUE;
|
339
|
}
|