Working MultipleChoiceValueEditor for checklist style

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@228 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-03-22 15:36:07 +00:00
parent 21781a559a
commit f5de36057c
7 changed files with 67 additions and 17 deletions
+40 -1
View File
@@ -7,6 +7,7 @@
// ----------------------------------------------------------------------------- : Includes
#include <gui/value/multiple_choice.hpp>
#include <data/action/value.hpp>
// ----------------------------------------------------------------------------- : MultipleChoiceValueEditor
@@ -14,7 +15,45 @@ IMPLEMENT_VALUE_EDITOR(MultipleChoice) {}
void MultipleChoiceValueEditor::determineSize(bool force_fit) {
if (!nativeLook()) return;
// item height
item_height = 16;
// height depends on number of items and item height
int item_count = field().choices->lastId();
style().height = item_count * 20;
style().height = item_count * item_height;
}
bool MultipleChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
// find item under cursor
if (style().render_style && RENDER_CHECKLIST) {
int id = (pos.y - style().top) / item_height;
int end = field().choices->lastId();
if (id >= 0 && id < end) {
toggle(id);
return true;
}
} else {
// TODO
}
return false;
}
void MultipleChoiceValueEditor::toggle(int id) {
String new_value;
// old selection
vector<String> selected;
value().get(selected);
vector<String>::iterator select_it = selected.begin();
// copy selected choices to new value
int end = field().choices->lastId();
for (int i = 0 ; i < end ; ++i) {
String choice = field().choices->choiceName(i);
bool active = select_it != selected.end() && *select_it == choice;
if (active) select_it++;
if (active != (i == id)) {
if (!new_value.empty()) new_value += _(", ");
new_value += choice;
}
}
// store value
getSet().actions.add(value_action(valueP(), new_value));
}