forked from tcobbs/ldview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExportOptionsDialog.cpp
243 lines (224 loc) · 6.28 KB
/
ExportOptionsDialog.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
#include "ExportOptionsDialog.h"
#include "OptionsCanvas.h"
#include "OptionsScroller.h"
#include "Resource.h"
#include <TCFoundation/mystring.h>
#include <TCFoundation/TCLocalStrings.h>
#include <CUI/CUIWindowResizer.h>
#if defined(_MSC_VER) && _MSC_VER >= 1400 && defined(_DEBUG)
#define new DEBUG_CLIENTBLOCK
#endif // _DEBUG
ExportOptionsDialog::ExportOptionsDialog(
HINSTANCE hInstance,
LDExporter *exporter):
CUIDialog(hInstance, NULL),
m_exporter(exporter),
m_resizer(NULL),
m_scroller(NULL),
m_canvas(NULL)
{
}
ExportOptionsDialog::~ExportOptionsDialog(void)
{
}
void ExportOptionsDialog::dealloc(void)
{
TCObject::release(m_resizer);
TCObject::release(m_scroller);
TCObject::release(m_canvas);
CUIDialog::dealloc();
}
INT_PTR ExportOptionsDialog::doModal(HWND hWndParent)
{
return CUIDialog::doModal(IDD_EXPORT_OPTIONS, hWndParent);
}
void ExportOptionsDialog::initCanvasOptions(void)
{
LDExporterSettingList &settings = m_exporter->getSettings();
LDExporterSettingList::iterator it;
// All the groupSize stuff here is done to prevent group settings from
// being nested. Nested groups get bool settings.
std::stack<int> groupSizes;
int groupSize = 0;
for (it = settings.begin(); it != settings.end(); it++)
{
// Track whether we were inside a group at the beginning of this
// iteration of the loop.
bool inGroup = groupSize > 0;
if (groupSize > 0)
{
groupSize--;
if (groupSize == 0)
{
// We just got to the end of a group, so pop the previous
// groupSize value off the groupSizes stack.
groupSize = groupSizes.top();
groupSizes.pop();
}
}
if (it->getGroupSize() > 0)
{
// This item is the start of a group.
if (inGroup)
{
// At the beginning of this iteration we were in a group, so
// use a bool setting instead of a group setting.
m_canvas->addBoolSetting(*it);
}
else
{
// Top level group; use a group setting.
m_canvas->addGroup(*it);
}
// We're now in a new group, so push the current groupSize onto
// the groupSizes stack.
groupSizes.push(groupSize);
// Update groupSize based on the new group's size.
groupSize = it->getGroupSize();
}
else
{
// This setting isn't the start of a group; add the appropriate type
// of option UI to the canvas.
switch (it->getType())
{
case LDExporterSetting::TBool:
m_canvas->addBoolSetting(*it);
break;
case LDExporterSetting::TFloat:
m_canvas->addFloatSetting(*it);
break;
case LDExporterSetting::TLong:
m_canvas->addLongSetting(*it);
break;
case LDExporterSetting::TString:
m_canvas->addStringSetting(*it);
break;
case LDExporterSetting::TEnum:
m_canvas->addEnumSetting(*it);
break;
default:
throw "not implemented";
}
}
}
}
void ExportOptionsDialog::initCanvas(void)
{
HWND hCanvasLoc = GetDlgItem(hWindow, IDC_OPTIONS_CANVAS);
HWND hScroller;
RECT canvasRect;
GetWindowRect(hCanvasLoc, &canvasRect);
DestroyWindow(hCanvasLoc);
screenToClient(hWindow, &canvasRect);
m_scroller = new OptionsScroller(hInstance);
m_scroller->create(this);
hScroller = m_scroller->getHWindow();
m_canvas = m_scroller->getCanvas();
m_canvas->retain();
initCanvasOptions();
MoveWindow(hScroller, canvasRect.left, canvasRect.top,
canvasRect.right - canvasRect.left, canvasRect.bottom - canvasRect.top,
TRUE);
ShowWindow(hScroller, SW_SHOW);
}
BOOL ExportOptionsDialog::doInitDialog(HWND hKbControl)
{
ucstring titleBase;
std::string extension = m_exporter->getExtension();
ucstring title;
RECT rect;
HWND hScroller;
GetClientRect(hWindow, &rect);
setMinSize(rect.right, rect.bottom, true);
setIcon(IDI_APP_ICON);
CUIWindow::windowGetText(hWindow, titleBase);
convertStringToUpper(&extension[0]);
utf8toucstring(title, extension);
title += _UC(" ");
title += titleBase;
windowSetText(hWindow, title);
initCanvas();
hScroller = m_scroller->getHWindow();
m_resizer = new CUIWindowResizer;
m_resizer->setHWindow(hWindow);
m_resizer->addSubWindow(hScroller, CUISizeHorizontal | CUISizeVertical);
m_resizer->addSubWindow(IDC_RESET, CUIFloatRight | CUIFloatTop);
m_resizer->addSubWindow(IDOK, CUIFloatLeft | CUIFloatTop);
m_resizer->addSubWindow(IDCANCEL, CUIFloatLeft | CUIFloatTop);
m_resizer->addResizeGrip();
initialized = TRUE;
// Keep a different autosave setting for each export file type.
setAutosaveName((extension + "ExportOptions").c_str());
return CUIDialog::doInitDialog(hKbControl);
}
void ExportOptionsDialog::doOK(void)
{
// If there is a validation error, commitSettings will show the error to the
// user and return false.
if (m_canvas->commitSettings())
{
CUIDialog::doOK();
}
}
LRESULT ExportOptionsDialog::doSize(WPARAM sizeType, int newWidth, int newHeight)
{
if (sizeType != SIZE_MINIMIZED)
{
m_resizer->resize(newWidth, newHeight);
}
return CUIDialog::doSize(sizeType, newWidth, newHeight);
}
LRESULT ExportOptionsDialog::doMouseWheel(
short keyFlags,
short zDelta,
int xPos,
int yPos)
{
RECT rect;
POINT point = { xPos, yPos };
GetWindowRect(m_scroller->getHWindow(), &rect);
if (PtInRect(&rect, point))
{
// I don't know WHY we get the mouse wheel event istead of the scroller
// window (which is set up to handle it), but we do. It's probably
// related to the dialog event forwarding for keyboard navigation.
m_scroller->doMouseWheel(keyFlags, zDelta, xPos, yPos);
}
return 0;
}
LRESULT ExportOptionsDialog::doCommand(
int notifyCode,
int commandId,
HWND control)
{
if (notifyCode == BN_SETFOCUS)
{
UCCHAR className[128];
GetClassName(control, className, COUNT_OF(className));
if (ucstrcmp(className, WC_BUTTON) == 0)
{
// For some reason, when the focus changes betwen the OK and Cancel
// buttons, the group box borders in the canvas get redrawn without
// redrawing the labels or check boxes that are over the top of
// them. This causes there to be a line through their titles. I
// don't have any idea why this happens, but redrawing the canvas
// and all its children fixes the problem.
RedrawWindow(m_canvas->getHWindow(), NULL, NULL,
RDW_INVALIDATE | RDW_ALLCHILDREN);
}
}
else if (notifyCode == BN_CLICKED)
{
if (commandId == IDC_RESET)
{
return doReset();
}
}
return CUIDialog::doCommand(notifyCode, commandId, control);
}
LRESULT ExportOptionsDialog::doReset(void)
{
m_canvas->resetSettings();
return 0;
}