From 0a1f6ed7721619e33c434166000706ebfb1808d0 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Fri, 19 Aug 2005 18:35:50 +0000 Subject: [PATCH] Got rid of 500 entry limit by converting options to a vector --- wselectlist.cc | 29 ++++++++++++++--------------- wselectlist.h | 15 ++++++++++----- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/wselectlist.cc b/wselectlist.cc index 101658c..a0734f9 100644 --- a/wselectlist.cc +++ b/wselectlist.cc @@ -22,7 +22,6 @@ WSelectList::WSelectList() { - numOptions = 0; selectedOption = 0; topOption = 0; numOptionsDisplayable = 0; @@ -36,12 +35,13 @@ WSelectList::~WSelectList() void WSelectList::clear() { - for (int i = 0; i < numOptions; i++) + int vsize = options.size(); + for (int i = 0; i < vsize; i++) { delete[] options[i]; } + options.clear(); - numOptions = 0; selectedOption = 0; topOption = 0; numOptionsDisplayable = 0; @@ -51,7 +51,7 @@ void WSelectList::clear() void WSelectList::hintSetCurrent(int index) { selectedOption = index; - if (selectedOption >= numOptions) selectedOption = numOptions - 1; + if (selectedOption >= options.size()) selectedOption = options.size() - 1; } void WSelectList::hintSetTop(int index) @@ -61,12 +61,11 @@ void WSelectList::hintSetTop(int index) int WSelectList::addOption(char* text, int selected) { - int thisNewOption = numOptions; + int thisNewOption = options.size(); int length = strlen(text); - options[thisNewOption] = new char[length + 1]; + options.push_back(new char[length + 1]); strcpy(options[thisNewOption], text); if (selected) selectedOption = thisNewOption; - numOptions++; return thisNewOption; } @@ -92,9 +91,9 @@ void WSelectList::draw() fillColour(Colour::VIEWBACKGROUND); int ypos = 5; - for (int i = topOption; i < (topOption + numOptionsDisplayable); i++) + for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++) { - if (i == numOptions) return; + if (i == options.size()) return; if ((ypos + ySeperation) > height) break; if (i == selectedOption) @@ -149,13 +148,13 @@ void WSelectList::up() } else { - selectedOption = numOptions - 1; + selectedOption = options.size() - 1; } } void WSelectList::down() { - if (selectedOption < numOptions - 1) + if (selectedOption < options.size() - 1) { selectedOption++; } @@ -175,7 +174,7 @@ void WSelectList::pageUp() void WSelectList::pageDown() { - if ((topOption + numOptionsDisplayable) >= numOptions) return; + if ((topOption + numOptionsDisplayable) >= options.size()) return; topOption += numOptionsDisplayable; selectedOption = topOption; @@ -188,13 +187,13 @@ int WSelectList::getTopOption() int WSelectList::getNumOptions() { - return numOptions; + return options.size(); } int WSelectList::getBottomOption() { - int retval = topOption + numOptionsDisplayable; - if (retval > numOptions) return numOptions; + UINT retval = topOption + numOptionsDisplayable; + if (retval > options.size()) return options.size(); else return retval; } diff --git a/wselectlist.h b/wselectlist.h index 23c6cae..7c48e6a 100644 --- a/wselectlist.h +++ b/wselectlist.h @@ -24,9 +24,14 @@ #include #include +#include + +#include "defines.h" #include "box.h" #include "colour.h" +using namespace std; + class WSelectList : public Box { public: @@ -54,13 +59,13 @@ class WSelectList : public Box private: void drawOptionLine(char* text, int xpos, int ypos, Colour& colour); - char* options[500]; - int numOptions; - int selectedOption; - int topOption; - int numOptionsDisplayable; + vector options; + UINT selectedOption; + UINT topOption; + UINT numOptionsDisplayable; int columns[10]; int numColumns; + }; #endif -- 2.39.5