-
Notifications
You must be signed in to change notification settings - Fork 16
/
JpegOptionsDialog.cpp
188 lines (173 loc) · 3.92 KB
/
JpegOptionsDialog.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
#include "JpegOptionsDialog.h"
#include "Resource.h"
#include <TCFoundation/TCJpegOptions.h>
#include <TCFoundation/mystring.h>
#include <TCFoundation/TCLocalStrings.h>
#if defined(_MSC_VER) && _MSC_VER >= 1400 && defined(_DEBUG)
#define new DEBUG_CLIENTBLOCK
#endif // _DEBUG
JpegOptionsDialog::JpegOptionsDialog(HINSTANCE hInstance, HWND hParentWindow)
: CUIDialog(hInstance, hParentWindow)
, options(new TCJpegOptions)
, hQualityField(NULL)
, hQualitySpin(NULL)
, hQualitySlider(NULL)
, quality(87)
{
}
JpegOptionsDialog::~JpegOptionsDialog(void)
{
}
void JpegOptionsDialog::dealloc(void)
{
TCObject::release(options);
CUIDialog::dealloc();
}
INT_PTR JpegOptionsDialog::doModal(HWND hWndParent)
{
return CUIDialog::doModal(IDD_JPEG_OPTIONS, hWndParent);
}
void JpegOptionsDialog::setQuality(int value)
{
quality = value;
trackBarSetPos(IDC_JPEG_QUAL_SLIDER, quality);
upDownSetPos(IDC_JPEG_QUAL_SPIN, quality);
windowSetValue(IDC_JPEG_QUAL_FIELD, (long)quality);
}
BOOL JpegOptionsDialog::doInitDialog(HWND /*hKbControl*/)
{
int index;
int i;
quality = options->getQuality();
hQualityField = GetDlgItem(hWindow, IDC_JPEG_QUAL_FIELD);
hQualitySpin = GetDlgItem(hWindow, IDC_JPEG_QUAL_SPIN);
hQualitySlider = GetDlgItem(hWindow, IDC_JPEG_QUAL_SLIDER);
trackBarSetup(IDC_JPEG_QUAL_SLIDER, 1, 100, 10, quality);
for (i = 10; i < 100; i += 10)
{
trackBarSetTic(IDC_JPEG_QUAL_SLIDER, i);
}
textFieldSetLimitText(IDC_JPEG_QUAL_FIELD, 3);
upDownSetup(IDC_JPEG_QUAL_SPIN, 1, 100, quality);
setQuality(quality);
comboAddString(IDC_JPEG_SUBSAMPLING_COMBO,
ls(_UC("Jpeg444ss")));
comboAddString(IDC_JPEG_SUBSAMPLING_COMBO,
ls(_UC("Jpeg422ss")));
comboAddString(IDC_JPEG_SUBSAMPLING_COMBO,
ls(_UC("Jpeg420ss")));
switch (options->getSubSampling())
{
case TCJpegOptions::SS422:
index = 1;
break;
case TCJpegOptions::SS420:
index = 2;
break;
default: // TCJpegOptions::SS444
index = 0;
break;
}
comboSetCurSel(IDC_JPEG_SUBSAMPLING_COMBO, index);
checkSet(IDC_JPEG_PROGRESSIVE_CHECK, options->getProgressive());
return TRUE;
}
LRESULT JpegOptionsDialog::doVScroll(
int scrollCode,
int position,
HWND hScrollBar)
{
if (scrollCode == SB_THUMBPOSITION && hScrollBar == hQualitySpin)
{
setQuality(position);
return 0;
}
return CUIDialog::doVScroll(scrollCode, position, hScrollBar);
}
LRESULT JpegOptionsDialog::doHScroll(
int scrollCode,
int position,
HWND hScrollBar)
{
if (hScrollBar == hQualitySlider)
{
if (scrollCode != SB_ENDSCROLL)
{
switch (scrollCode)
{
case SB_PAGEUP:
position = quality - 10;
break;
case SB_PAGEDOWN:
position = quality + 10;
break;
}
if (position < 1)
{
position = 1;
}
if (position > 100)
{
position = 100;
}
setQuality(position);
return 0;
}
}
return CUIDialog::doHScroll(scrollCode, position, hScrollBar);
}
LRESULT JpegOptionsDialog::doTextFieldChange(int controlId, HWND control)
{
if (controlId == IDC_JPEG_QUAL_FIELD)
{
long value;
if (windowGetValue(controlId, value))
{
int start, end;
textFieldGetSelection(controlId, start, end);
if (value > 100)
{
while (value > 100)
{
value /= 10;
}
}
setQuality(value);
if (start > 2)
{
if (value == 100)
{
start = 3;
}
else
{
start = 2;
}
}
textFieldSetSelection(controlId, start, start);
}
return 0;
}
return CUIDialog::doTextFieldChange(controlId, control);
}
void JpegOptionsDialog::doOK(void)
{
TCJpegOptions::SubSampling subSampling = TCJpegOptions::SS444;
switch (comboGetCurSel(IDC_JPEG_SUBSAMPLING_COMBO))
{
case 0:
subSampling = TCJpegOptions::SS444;
break;
case 1:
subSampling = TCJpegOptions::SS422;
break;
case 2:
subSampling = TCJpegOptions::SS420;
break;
}
options->setQuality(trackBarGetPos(IDC_JPEG_QUAL_SLIDER));
options->setSubSampling(subSampling);
options->setProgressive(checkGet(IDC_JPEG_PROGRESSIVE_CHECK));
options->save();
CUIDialog::doOK();
}