2 Copyright 2004-2005 Chris Tallon
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
21 #include "wselectlist.h"
\r
26 WSelectList::WSelectList():
\r
27 backgroundColour(DrawStyle::VIEWBACKGROUND)
\r
31 numOptionsDisplayable = 0;
\r
35 showseloption = true;
\r
36 darkseloption = false;
\r
40 WSelectList::~WSelectList()
\r
45 void WSelectList::clear()
\r
47 int vsize = options.size();
\r
48 for (int i = 0; i < vsize; i++)
\r
50 delete[] options[i].text;
\r
56 numOptionsDisplayable = 0;
\r
60 void WSelectList::setNoLoop()
\r
65 void WSelectList::setBackgroundColour(const DrawStyle& colour)
\r
67 backgroundColour = colour;
\r
70 void WSelectList::hintSetCurrent(int idx)
\r
72 selectedOption = idx;
\r
73 if (selectedOption >= options.size()) selectedOption = options.size() - 1;
\r
76 void WSelectList::hintSetTop(int idx)
\r
81 int WSelectList::addOption(const char* text, ULONG data, int selected)
\r
83 int thisNewOption = options.size();
\r
86 wslo.text = new char[strlen(text) + 1];
\r
87 strcpy(wslo.text, text);
\r
89 options.push_back(wslo);
\r
90 if (selected) selectedOption = thisNewOption;
\r
91 return thisNewOption;
\r
94 void WSelectList::draw()
\r
96 int fontHeight = getFontHeight();
\r
97 int ySeperation = fontHeight + gap;
\r
99 numOptionsDisplayable = (area.h - 5) / ySeperation;
\r
101 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
\r
102 if (selectedOption == ((UINT)topOption - 1)) topOption--;
\r
103 // if still not visible...
\r
104 if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
\r
106 topOption = selectedOption - (numOptionsDisplayable / 2);
\r
109 if (topOption < 0) topOption = 0;
\r
112 fillColour(backgroundColour);
\r
115 for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++)
\r
117 if (i == options.size()) return;
\r
118 if ((ypos + ySeperation) > area.h) break;
\r
120 if (i == selectedOption && showseloption)
\r
123 rectangle(0, ypos, area.w, fontHeight, darkseloption ? DrawStyle::SELECTDARKHIGHLIGHT: DrawStyle::SELECTHIGHLIGHT);
\r
125 drawOptionLine(options[i].text, 5, ypos, area.w - 5, DrawStyle::DARKTEXT);
\r
130 drawOptionLine(options[i].text, 5, ypos, area.w - 5, DrawStyle::LIGHTTEXT);
\r
132 ypos += ySeperation;
\r
137 void WSelectList::addColumn(int x)
\r
139 if (numColumns == 10) return;
\r
140 columns[numColumns++] = x;
\r
143 void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, const DrawStyle& colour)
\r
148 drawText(text, xpos, ypos, width, colour);
\r
153 strncpy(buffer, text, 199);
\r
154 int currentColumn = 0;
\r
157 pointer = strtok(buffer, "\t");
\r
161 drawText(pointer, xpos + columns[currentColumn], ypos, width - columns[currentColumn], colour);
\r
164 if (currentColumn == 10) return;
\r
165 pointer = strtok(NULL, "\t");
\r
170 void WSelectList::up()
\r
172 if (selectedOption > 0)
\r
178 if (!noLoop) selectedOption = options.size() - 1;
\r
182 void WSelectList::down()
\r
184 if (selectedOption < options.size() - 1)
\r
190 if (!noLoop) selectedOption = 0;
\r
194 void WSelectList::pageUp()
\r
196 topOption -= numOptionsDisplayable;
\r
197 if (topOption < 0) topOption = 0;
\r
199 selectedOption = topOption;
\r
202 void WSelectList::pageDown()
\r
204 if ((topOption + numOptionsDisplayable) >= options.size())
\r
206 selectedOption = options.size() - 1;
\r
210 topOption += numOptionsDisplayable;
\r
211 selectedOption = topOption;
\r
215 int WSelectList::getTopOption()
\r
220 int WSelectList::getNumOptions()
\r
222 return options.size();
\r
225 int WSelectList::getBottomOption()
\r
227 UINT retval = topOption + numOptionsDisplayable;
\r
228 if (retval > options.size()) return options.size();
\r
229 else return retval;
\r
232 int WSelectList::getCurrentOption()
\r
234 return selectedOption;
\r
237 ULONG WSelectList::getCurrentOptionData()
\r
239 if (!options.size()) return 0;
\r
240 return options[selectedOption].data;
\r
243 bool WSelectList::mouseAndroidScroll(int x, int y,int sx, int sy)
\r
245 /* int fontHeight = getFontHeight();
\r
246 int movelines= sy/fontHeight;
\r
248 int seloption=selectedOption+movelines;
\r
249 if (seloption<0) seloption=0;
\r
250 else if (seloption>options.size()-1) seloption=options.size()-1;
\r
251 selectedOption=seloption;*/
\r
255 bool WSelectList::mouseMove(int x, int y)
\r
257 int ml = getMouseLine(x-getRootBoxOffsetX(), y-getRootBoxOffsetY());
\r
258 if (ml>=0 && ml!=(int)selectedOption)
\r
260 selectedOption = ml;
\r
266 bool WSelectList::mouseLBDOWN(int x, int y)
\r
268 int ml = getMouseLine(x-getRootBoxOffsetX(), y-getRootBoxOffsetY());
\r
269 if (ml == (int)selectedOption)
\r
271 /* caller should generate a OK message*/
\r
277 int WSelectList::getMouseLine(int x,int y)
\r
279 int fontHeight = getFontHeight();
\r
280 int ySeperation = fontHeight + gap;
\r
282 if (y<0) return -1;
\r
283 if (x<0 || x>(int)area.w) return -1;
\r
284 if (y>(int)(10+numOptionsDisplayable*ySeperation)) return -1;
\r
288 int selected=cy/ySeperation;
\r
289 if (y<5) selected=-1;
\r
290 if (selected> ((int)numOptionsDisplayable)) return -1;
\r
291 /* Important: should be the same algorithm used in draw! */
\r
292 if (selectedOption == (topOption + numOptionsDisplayable)) topOption++;
\r
293 if (selectedOption == ((UINT)topOption - 1)) topOption--;
\r
294 // if still not visible...
\r
295 if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
\r
297 topOption = selectedOption - (numOptionsDisplayable / 2);
\r
300 if (topOption < 0) topOption = 0;
\r
302 if ((selected+topOption >= (int) options.size()) ||
\r
303 (selected + topOption < 0)) return -1;
\r
305 return selected + topOption;
\r