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
+7 -5
View File
@@ -200,12 +200,14 @@ void draw_drop_down_arrow(Window* win, DC& dc, const wxRect& rect, bool active)
}
void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked) {
// TODO: Windows version?
// portable
#if wxUSE_UXTHEME && defined(__WXMSW__)
// TODO: Windows version?
#endif
// portable version
if (checked) {
dc.DrawCheckMark(wxRect(rect.x-1,rect.y-1,rect.width+2,rect.height+2));
}
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
if (checked) {
dc.DrawCheckMark(rect);
}
}
+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));
}
+4
View File
@@ -21,6 +21,10 @@ class MultipleChoiceValueEditor : public MultipleChoiceValueViewer, public Value
DECLARE_VALUE_EDITOR(MultipleChoice);
virtual void determineSize(bool force_fit);
virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent& ev);
private:
/// Toggle a choice or on or off
void toggle(int id);
};
// ----------------------------------------------------------------------------- : EOF