-
Notifications
You must be signed in to change notification settings - Fork 0
/
PAGESET.cpp
126 lines (109 loc) · 3.56 KB
/
PAGESET.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
// pageset.cpp : implementation of the CPadView class
#include "stdafx.h"
#include "psx.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPageSetupDlg dialog
IMPLEMENT_DYNAMIC(CPageSetupDlg, CDialog)
CPageSetupDlg::CPageSetupDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPageSetupDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPageSetupDlg)
m_iFooterTime = -1;
m_iHeaderTime = -1;
//}}AFX_DATA_INIT
}
void CPageSetupDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPageSetupDlg)
DDX_Text(pDX, IDC_FOOTER, m_strFooter);
DDX_Text(pDX, IDC_HEADER, m_strHeader);
DDX_Radio(pDX, IDC_FOOTER_FILE, m_iFooterTime);
DDX_Radio(pDX, IDC_HEADER_FILE, m_iHeaderTime);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPageSetupDlg, CDialog)
//{{AFX_MSG_MAP(CPageSetupDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPageSetup member functions
static void Replace(CString& strModify, const char* pszWhat, const char* pszWith)
// replace pszWhat with pwzWith in string strModify
{
int i;
if ((i = strModify.Find(pszWhat)) >= 0)
strModify = strModify.Left(i) + pszWith + strModify.Mid(i+strlen(pszWhat));
}
void CPageSetupDlg::FormatFilePage(CString& strFormat,
const char* pszFileName, UINT nPage)
{
char sz[32];
wsprintf(sz, "%d", nPage);
::Replace(strFormat, "&p", sz);
if (pszFileName == NULL)
{
pszFileName = sz;
sz[0] = 0;
}
::Replace(strFormat, "&f", pszFileName);
}
void CPageSetupDlg::FormatHeader(CString& strHeader, CTime& time,
const char* pszFileName, UINT nPage)
{
CString strFormat = m_strHeader;
FormatFilePage(strFormat, pszFileName, nPage);
#ifndef _AFXDLL
strHeader = time.Format(strFormat);
#else
// formatted time option not supported
(void)&time; // not used
strHeader = strFormat;
#endif
}
void CPageSetupDlg::FormatFooter(CString& strFooter, CTime& time,
const char* pszFileName, UINT nPage)
{
CString strFormat = m_strFooter;
FormatFilePage(strFormat, pszFileName, nPage);
#ifndef _AFXDLL
strFooter = time.Format(strFormat);
#else
// formatted time option not supported
(void)&time; // not used
strFooter = strFormat;
#endif
}
static char BASED_CODE szPageSetup[] = "PageSetup";
static char BASED_CODE szHeader[] = "Header";
static char BASED_CODE szFooter[] = "Footer";
static char BASED_CODE szHeaderTime[] = "HeaderTime";
static char BASED_CODE szFooterTime[] = "FooterTime";
void CPageSetupDlg::Initialize()
{
m_strHeader = AfxGetApp()->GetProfileString(szPageSetup, szHeader, "File: &f");
m_strFooter = AfxGetApp()->GetProfileString(szPageSetup, szFooter, "Page: &p");
m_iHeaderTime = AfxGetApp()->GetProfileInt(szPageSetup, szHeaderTime, 0);
m_iFooterTime = AfxGetApp()->GetProfileInt(szPageSetup, szFooterTime, 0);
m_strHeaderOld = m_strHeader;
m_strFooterOld = m_strFooter;
m_iHeaderTimeOld = m_iHeaderTime;
m_iFooterTimeOld = m_iFooterTime;
}
void CPageSetupDlg::Terminate()
{
if (m_strHeader != m_strHeaderOld)
AfxGetApp()->WriteProfileString(szPageSetup, szHeader, m_strHeader);
if (m_strFooter != m_strFooterOld)
AfxGetApp()->WriteProfileString(szPageSetup, szFooter, m_strFooter);
if (m_iHeaderTime != m_iHeaderTimeOld)
AfxGetApp()->WriteProfileInt(szPageSetup, szHeaderTime, m_iHeaderTime);
if (m_iFooterTime != m_iFooterTimeOld)
AfxGetApp()->WriteProfileInt(szPageSetup, szFooterTime, m_iFooterTime);
}
/////////////////////////////////////////////////////////////////////////////
// CPageSetupDlg message handlers