4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "ComboList.hpp"
26 #include "Util/NumberParser.hpp"
27 #include "Util/Macros.hpp"
31 static TCHAR buffer
[16];
34 AngleDataField::Import(int value
)
36 assert(value
>= -int(MAX
));
40 return Import(unsigned(value
));
44 AngleDataField::ModifyValue(unsigned _value
)
46 unsigned value2
= Import(_value
);
55 AngleDataField::ModifyValue(int _value
)
57 unsigned value2
= Import(_value
);
66 AngleDataField::ModifyValue(Angle _value
)
68 unsigned value2
= Import(_value
);
77 AngleDataField::GetAsInteger() const
79 return GetIntegerValue();
83 AngleDataField::GetAsString() const
85 _stprintf(buffer
, _T("%u"), GetIntegerValue());
90 AngleDataField::GetAsDisplayString() const
92 _stprintf(buffer
, _T("%u°"), GetIntegerValue());
97 AngleDataField::SetAsInteger(int _value
)
103 AngleDataField::SetAsString(const TCHAR
*_value
)
105 ModifyValue(Angle::Degrees(ParseDouble(_value
, nullptr)));
109 AngleDataField::Inc()
111 ModifyValue(value
+ step
);
115 AngleDataField::Dec()
117 ModifyValue(MAX
+ value
- step
);
121 AngleDataField::SetFromCombo(int i
, TCHAR
*s
)
124 assert(unsigned(i
) < MAX
);
126 ModifyValue(unsigned(i
));
130 AppendComboValue(ComboList
&combo_list
, unsigned value
)
132 TCHAR buffer1
[ARRAY_SIZE(buffer
)], buffer2
[ARRAY_SIZE(buffer
)];
133 _stprintf(buffer1
, _T("%u"), value
);
134 _stprintf(buffer2
, _T("%u°"), value
);
135 combo_list
.Append(value
, buffer1
, buffer2
);
139 AngleDataField::CreateComboList() const
141 ComboList
*combo_list
= new ComboList();
143 const unsigned fine_step
= std::max(1u, step
/ 10u);
144 const unsigned fine_start_value
= (value
>= step
) ? value
- step
: 0;
145 const unsigned fine_stop_value
= value
+ step
;
147 bool found_current
= false;
148 bool in_fine_step
= false;
149 unsigned current_step
= step
;
153 if (!found_current
&& value
<= i
) {
154 combo_list
->ComboPopupItemSavedIndex
= combo_list
->size();
157 /* the current value is not listed - insert it here */
158 AppendComboValue(*combo_list
, value
);
160 found_current
= true;
163 AppendComboValue(*combo_list
, i
);
166 if (i
+ current_step
> fine_stop_value
) {
168 in_fine_step
= false;
170 i
= ((i
+ step
) / step
) * step
;
173 } else if (i
+ current_step
> fine_start_value
) {
176 current_step
= fine_step
;
177 i
= fine_start_value
+ fine_step
;
186 if (!found_current
) {
187 /* the current value out of range - append it here */
188 combo_list
->ComboPopupItemSavedIndex
= combo_list
->size();
189 AppendComboValue(*combo_list
, value
);