-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathagecolorpage.cpp
More file actions
185 lines (160 loc) · 4.38 KB
/
Copy pathagecolorpage.cpp
File metadata and controls
185 lines (160 loc) · 4.38 KB
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
// agecolors.cpp : implementation file
//
#include "stdafx.h"
#include "onstation.h"
#include "agecolorpage.h"
#include "settings.h"
#include "colortool.h"
#include "onstationview.h"
#include "onstationdoc.h"
#include "mainfrm.h"
#include "agecolorhelper.h"
#include "colortool.h"
#include "colorsheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CGlobalColorManager Colors_G;
extern CSettings * pSettings_G;
/////////////////////////////////////////////////////////////////////////////
// CAgeColorPage dialog
CAgeColorPage::CAgeColorPage(CColorSheet * pColorSheet)
: CPropertyPage(CAgeColorPage::IDD),m_ColorWidget(FALSE,3,5)
{
//{{AFX_DATA_INIT(CAgeColorPage)
//}}AFX_DATA_INIT
m_bDirty=FALSE;
m_pColorSheet=pColorSheet;
}
BOOL CAgeColorPage::IsDirty()
{
return m_bDirty;
}
void CAgeColorPage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAgeColorPage)
DDX_Control(pDX, IDC_AGELIST, m_AgeList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAgeColorPage, CPropertyPage)
//{{AFX_MSG_MAP(CAgeColorPage)
ON_BN_CLICKED(IDC_BUTTONDEFAULTS, OnButtondefaults)
ON_WM_DRAWITEM()
ON_MESSAGE(WM_COLORCHANGE,OnColorChange)
ON_BN_CLICKED(IDC_WIZARD, OnWizard)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAgeColorPage message handlers
BOOL CAgeColorPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
RECT rect;
GetDlgItem(IDC_COLORSLOT)->GetWindowRect(&rect);
ScreenToClient(&rect);
m_ColorWidget.Create(this,rect,IDC_NEWCOLORSLOT);
InitializeAll();
m_pColorSheet->m_iRecommendedColorSchemeIndex=COLORSCHEME_AGE;
m_AgeList.SetFocus();
return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAgeColorPage::InitializeAll()
{
m_AgeList.ResetContent();
for (int i=0;i<pSettings_G->m_iNumAgeColors;i++)
{
char szTemp[20];
CString szString;
DWORD dwAge=pSettings_G->m_dwAgeDates[i];
DWordToDate(dwAge,szTemp);
if (i==0)
{
szString.Format(IDS_BEFORE,szTemp);
}
else if (i==pSettings_G->m_iNumAgeColors-1)
{
DWordToDate(pSettings_G->m_dwAgeDates[i-1],szTemp);
szString.Format(IDS_ANDLATER,szTemp);
}
else
{
char szTemp1[20];
DWordToDate(pSettings_G->m_dwAgeDates[i-1],szTemp1);
szString.Format(IDS_STOS,szTemp1,szTemp);
}
m_AgeList.AddString(szString);
}
}
void CAgeColorPage::OnButtondefaults()
{
pSettings_G->SetDefaultAgeColors();
m_bDirty=TRUE;
InitializeAll();
}
void CAgeColorPage::OnOK()
{
CPropertyPage::OnOK();
}
LONG CAgeColorPage::OnColorChange(UINT ,LONG lParam)
{
m_bDirty=TRUE;
int iIndex=m_AgeList.GetCurSel();
if (iIndex==LB_ERR)
{
return 0l;
}
else
{
CancelToClose();
pSettings_G->m_crAgeColors[iIndex]=(COLORREF)lParam;
m_AgeList.InvalidateRect(NULL,TRUE);
}
return 0l;
}
void CAgeColorPage::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (lpDrawItemStruct->itemID!=LB_ERR)
{
DWORD dwColor=pSettings_G->m_crAgeColors[lpDrawItemStruct->itemID];
if (dwColor==RGB(255,255,255))
{
dwColor=RGB(0,0,0); //white on white is hard to see, so display it as black
}
SetTextColor(lpDrawItemStruct->hDC,dwColor);
if (lpDrawItemStruct->itemState&ODS_FOCUS)
{
SetBkMode(lpDrawItemStruct->hDC,OPAQUE);
SetBkColor(lpDrawItemStruct->hDC,RGB(0,0,255));
}
char szTemp[128];
m_AgeList.GetText(lpDrawItemStruct->itemID,szTemp);
TabbedTextOut(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,szTemp,lstrlen(szTemp),0,NULL,0);
}
else
{
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
}
void CAgeColorPage::OnWizard()
{
WORD wYearDiff=GetYear(pSettings_G->m_dwAgeDates[1])-
GetYear(pSettings_G->m_dwAgeDates[0]);
if (wYearDiff==0)
wYearDiff=1;
if (wYearDiff>50)
wYearDiff=50;
CAgeColorHelper ACH(pSettings_G->m_dwAgeDates[0],pSettings_G->m_iNumAgeColors,wYearDiff);
if (ACH.DoModal()==IDOK)
{
m_bDirty=TRUE;
CancelToClose();
int iYear=GetYear(ACH.m_dwStartDate);
int iDay=GetDay(ACH.m_dwStartDate);
pSettings_G->SetAgeColors(ACH.m_dwStartDate,ACH.m_iNumIntervals,ACH.m_iYears);
InitializeAll(); //reset the list box
}
}