-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathICFSaveDialog.cpp
282 lines (247 loc) · 11.6 KB
/
ICFSaveDialog.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
/* ######################################################################### */
/* ## ## */
/* ## (Iometer) / ICFSaveDialog.cpp ## */
/* ## ## */
/* ## ------------------------------------------------------------------- ## */
/* ## ## */
/* ## Job .......: Implementation of the CICFSaveDialog class, which ## */
/* ## extends the standard CFileDialog class with ## */
/* ## additional functionality for saving Iometer's .ICF ## */
/* ## (Iometer Configuration File) files. ## */
/* ## ## */
/* ## ------------------------------------------------------------------- ## */
/* ## ## */
/* ## Intel Open Source License ## */
/* ## ## */
/* ## Copyright (c) 2001 Intel Corporation ## */
/* ## All rights reserved. ## */
/* ## Redistribution and use in source and binary forms, with or ## */
/* ## without modification, are permitted provided that the following ## */
/* ## conditions are met: ## */
/* ## ## */
/* ## Redistributions of source code must retain the above copyright ## */
/* ## notice, this list of conditions and the following disclaimer. ## */
/* ## ## */
/* ## Redistributions in binary form must reproduce the above copyright ## */
/* ## notice, this list of conditions and the following disclaimer in ## */
/* ## the documentation and/or other materials provided with the ## */
/* ## distribution. ## */
/* ## ## */
/* ## Neither the name of the Intel Corporation nor the names of its ## */
/* ## contributors may be used to endorse or promote products derived ## */
/* ## from this software without specific prior written permission. ## */
/* ## ## */
/* ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND ## */
/* ## CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, ## */
/* ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ## */
/* ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ## */
/* ## DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS CONTRIBUTORS BE ## */
/* ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ## */
/* ## OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ## */
/* ## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ## */
/* ## OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ## */
/* ## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR ## */
/* ## TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ## */
/* ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY ## */
/* ## OF SUCH DAMAGE. ## */
/* ## ## */
/* ## ------------------------------------------------------------------- ## */
/* ## ## */
/* ## Remarks ...: <none> ## */
/* ## ## */
/* ## ------------------------------------------------------------------- ## */
/* ## ## */
/* ## Changes ...: 2003-10-17 ([email protected]) ## */
/* ## - Moved to the use of the IOMTR_[OSFAMILY|OS|CPU]_* ## */
/* ## global defines. ## */
/* ## - Integrated the License Statement into this header. ## */
/* ## 2003-04-25 ([email protected]) ## */
/* ## - Updated the global debug flag (_DEBUG) handling ## */
/* ## of the source file (check for platform etc.). ## */
/* ## - Added new header holding the changelog. ## */
/* ## ## */
/* ######################################################################### */
#include "stdafx.h"
#include "GalileoApp.h"
#include "ICFSaveDialog.h"
// Needed for MFC Library support for assisting in finding memory leaks
//
// NOTE: Based on the documentation[1] I found, it should be enough to have
// a "#define new DEBUG_NEW" statement for the case, that we are
// running Windows. There should be no need for checking the _DEBUG
// flag and no need for redefiniting the THIS_FILE string. Maybe there
// will be a MFC hacker who could advice here.
// [1] = http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_debug_new.asp
//
#if defined(IOMTR_OS_WIN32) || defined(IOMTR_OS_WIN64)
#ifdef IOMTR_SETTING_MFC_MEMALLOC_DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#endif
IMPLEMENT_DYNAMIC(CICFSaveDialog, CFileDialog)
/////////////////////////////////////////////////////////////////////////////
// CICFSaveDialog dialog
CICFSaveDialog::CICFSaveDialog()
: CFileDialog(FALSE, "icf", "iometer", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Iometer Configuration Files (*.icf)|*.icf|" "Text Files (*.txt)|*.txt|All Files (*.*)|*.*||",
NULL, 0UL, FALSE)
{
CString title;
char *buf;
VERIFY(title.LoadString(IDS_SAVE_DIALOG_TITLE)); // get frame title from resource file
buf = new char[title.GetLength() + 1];
strcpy(buf, title);
m_ofn.lpstrTitle = buf;
m_ofn.Flags |= OFN_ENABLETEMPLATE | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FILESAVE_OPTS);
//{{AFX_DATA_INIT(CICFSaveDialog)
isCkTestSetup = TRUE;
isCkResultsDisplay = TRUE;
isCkGlobalAccessSpec = TRUE;
isCkManagerWorker = TRUE;
isCkAssignAccessSpec = TRUE;
isCkAssignTargets = TRUE;
//}}AFX_DATA_INIT
wasCkAssignAccessSpec = TRUE;
wasCkAssignTargets = TRUE;
}
CICFSaveDialog::~CICFSaveDialog()
{
if (m_ofn.lpstrTitle)
delete (void*)m_ofn.lpstrTitle;
}
void CICFSaveDialog::DoDataExchange(CDataExchange * pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CICFSaveDialog)
DDX_Control(pDX, CkTestSetup, m_CkTestSetup);
DDX_Control(pDX, CkResultsDisplay, m_CkResultsDisplay);
DDX_Control(pDX, CkGlobalAccessSpec, m_CkGlobalAccessSpec);
DDX_Control(pDX, CkManagerWorker, m_CkManagerWorker);
DDX_Control(pDX, CkAssignAccessSpec, m_CkAssignAccessSpec);
DDX_Control(pDX, CkAssignTargets, m_CkAssignTargets);
DDX_Check(pDX, CkTestSetup, isCkTestSetup);
DDX_Check(pDX, CkResultsDisplay, isCkResultsDisplay);
DDX_Check(pDX, CkGlobalAccessSpec, isCkGlobalAccessSpec);
DDX_Check(pDX, CkManagerWorker, isCkManagerWorker);
DDX_Check(pDX, CkAssignAccessSpec, isCkAssignAccessSpec);
DDX_Check(pDX, CkAssignTargets, isCkAssignTargets);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CICFSaveDialog, CDialog)
//{{AFX_MSG_MAP(CICFSaveDialog)
ON_BN_CLICKED(CkManagerWorker, OnCkManagerWorker)
ON_BN_CLICKED(CkTestSetup, OnAnyCheck)
ON_WM_HELPINFO()
ON_BN_CLICKED(CkResultsDisplay, OnAnyCheck)
ON_BN_CLICKED(CkGlobalAccessSpec, OnAnyCheck)
ON_BN_CLICKED(CkAssignAccessSpec, OnAnyCheck)
ON_BN_CLICKED(CkAssignTargets, OnAnyCheck)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CICFSaveDialog message handlers
void CICFSaveDialog::OnCkManagerWorker()
{
UpdateData(TRUE); // copy the GUI state to the variables
if (isCkManagerWorker) {
// The box was checked
m_CkAssignAccessSpec.EnableWindow(TRUE);
isCkAssignAccessSpec = wasCkAssignAccessSpec;
m_CkAssignTargets.EnableWindow(TRUE);
isCkAssignTargets = wasCkAssignTargets;
} else {
// The box was unchecked
if (m_CkAssignAccessSpec.IsWindowEnabled()) {
m_CkAssignAccessSpec.EnableWindow(FALSE);
wasCkAssignAccessSpec = isCkAssignAccessSpec;
isCkAssignAccessSpec = FALSE;
}
if (m_CkAssignTargets.IsWindowEnabled()) {
m_CkAssignTargets.EnableWindow(FALSE);
wasCkAssignTargets = isCkAssignTargets;
isCkAssignTargets = FALSE;
}
}
UpdateData(FALSE); // copy the variable states to the GUI
OnAnyCheck();
}
void CICFSaveDialog::OnAnyCheck()
{
UpdateData(TRUE); // copy the GUI state to the variables
// Disable OK button if no boxes are checked
if (isCkTestSetup || isCkResultsDisplay
|| isCkGlobalAccessSpec || isCkManagerWorker || isCkAssignAccessSpec || isCkAssignTargets)
CWnd::GetOwner()->GetDlgItem(IDOK)->EnableWindow(TRUE);
else
CWnd::GetOwner()->GetDlgItem(IDOK)->EnableWindow(FALSE);
}
BOOL CICFSaveDialog::OnInitDialog()
{
CDialog::OnInitDialog();
UpdateData(FALSE); // copy the variable states to the GUI
if (!isCkManagerWorker) {
m_CkAssignAccessSpec.EnableWindow(FALSE);
m_CkAssignTargets.EnableWindow(FALSE);
}
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CICFSaveDialog::OnHelpInfo(HELPINFO * pHelpInfo)
{
switch (pHelpInfo->iCtrlId) {
// When we figure out the help, put it here...
case CkTestSetup:
break;
case CkResultsDisplay:
break;
case CkGlobalAccessSpec:
break;
case CkManagerWorker:
break;
case CkAssignAccessSpec:
break;
case CkAssignTargets:
break;
}
return CDialog::OnHelpInfo(pHelpInfo);
}
//
// Draw the lines that show the relation between the Manager/Worker
// checkbox and the access spec and target assignment checkboxes.
// There is no need to call CFileDialog::OnPaint. That is a separate
// message, since this is an extension to the file open/save common
// dialog.
//
void CICFSaveDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect MgrWkr;
CRect AsgnAspec;
CRect AsgnTargets;
int centerer;
int x1, x2, y1, y2, y3;
// Get the screen coordinates of the controls.
m_CkManagerWorker.GetWindowRect(MgrWkr);
m_CkAssignAccessSpec.GetWindowRect(AsgnAspec);
m_CkAssignTargets.GetWindowRect(AsgnTargets);
// Convert screen coords to window (client-area) coords.
ScreenToClient(MgrWkr);
ScreenToClient(AsgnAspec);
ScreenToClient(AsgnTargets);
// The distance from the corner of a checkbox square to the center of one of its sides.
centerer = (MgrWkr.bottom - MgrWkr.top) / 2 - 1;
x1 = MgrWkr.left + centerer - 1;
x2 = AsgnAspec.left;
y1 = MgrWkr.bottom;
y2 = AsgnAspec.top + centerer;
y3 = AsgnTargets.top + centerer;
dc.MoveTo(x1, y1);
dc.LineTo(x1, y3); // Vertical line (from MgrWkr checkbox, straight down)
dc.MoveTo(x1, y2);
dc.LineTo(x2, y2); // Horiz line from the first line to the AsgnAspec checkbox
dc.MoveTo(x1, y3);
dc.LineTo(x2, y3); // Horiz line from the first line to the AsgnTargets checkbox
}