diff --git a/src/data/action/value.cpp b/src/data/action/value.cpp index 22fefcca..379f15e8 100644 --- a/src/data/action/value.cpp +++ b/src/data/action/value.cpp @@ -52,10 +52,11 @@ class SimpleValueAction : public ValueAction { typename T::ValueType new_value; }; -ValueAction* value_action(const ChoiceValueP& value, const Defaultable& new_value) { return new SimpleValueAction (value, new_value); } -ValueAction* value_action(const ColorValueP& value, const Defaultable& new_value) { return new SimpleValueAction (value, new_value); } -ValueAction* value_action(const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction(value, new_value); } -ValueAction* value_action(const SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction(value, new_value); } +ValueAction* value_action(const ChoiceValueP& value, const Defaultable& new_value) { return new SimpleValueAction (value, new_value); } +ValueAction* value_action(const MultipleChoiceValueP& value, const Defaultable& new_value) { return new SimpleValueAction(value, new_value); } +ValueAction* value_action(const ColorValueP& value, const Defaultable& new_value) { return new SimpleValueAction (value, new_value); } +ValueAction* value_action(const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction(value, new_value); } +ValueAction* value_action(const SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction(value, new_value); } // ----------------------------------------------------------------------------- : Text diff --git a/src/data/action/value.hpp b/src/data/action/value.hpp index 5e0e9843..c3fab93b 100644 --- a/src/data/action/value.hpp +++ b/src/data/action/value.hpp @@ -24,6 +24,7 @@ DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(Style); DECLARE_POINTER_TYPE(TextValue); DECLARE_POINTER_TYPE(ChoiceValue); +DECLARE_POINTER_TYPE(MultipleChoiceValue); DECLARE_POINTER_TYPE(ColorValue); DECLARE_POINTER_TYPE(ImageValue); DECLARE_POINTER_TYPE(SymbolValue); @@ -43,10 +44,11 @@ class ValueAction : public Action { // ----------------------------------------------------------------------------- : Simple /// Action that updates a Value to a new value -ValueAction* value_action(const ChoiceValueP& value, const Defaultable& new_value); -ValueAction* value_action(const ColorValueP& value, const Defaultable& new_value); -ValueAction* value_action(const ImageValueP& value, const FileName& new_value); -ValueAction* value_action(const SymbolValueP& value, const FileName& new_value); +ValueAction* value_action(const ChoiceValueP& value, const Defaultable& new_value); +ValueAction* value_action(const MultipleChoiceValueP& value, const Defaultable& new_value); +ValueAction* value_action(const ColorValueP& value, const Defaultable& new_value); +ValueAction* value_action(const ImageValueP& value, const FileName& new_value); +ValueAction* value_action(const SymbolValueP& value, const FileName& new_value); // ----------------------------------------------------------------------------- : Text diff --git a/src/gui/util.cpp b/src/gui/util.cpp index 390782da..a7e810f9 100644 --- a/src/gui/util.cpp +++ b/src/gui/util.cpp @@ -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); - } } diff --git a/src/gui/value/multiple_choice.cpp b/src/gui/value/multiple_choice.cpp index 8420950a..e10c100b 100644 --- a/src/gui/value/multiple_choice.cpp +++ b/src/gui/value/multiple_choice.cpp @@ -7,6 +7,7 @@ // ----------------------------------------------------------------------------- : Includes #include +#include // ----------------------------------------------------------------------------- : 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 selected; + value().get(selected); + vector::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)); } diff --git a/src/gui/value/multiple_choice.hpp b/src/gui/value/multiple_choice.hpp index ae8b38a4..eec111fe 100644 --- a/src/gui/value/multiple_choice.hpp +++ b/src/gui/value/multiple_choice.hpp @@ -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 diff --git a/src/render/value/multiple_choice.cpp b/src/render/value/multiple_choice.cpp index 3f6de5bd..7abb4833 100644 --- a/src/render/value/multiple_choice.cpp +++ b/src/render/value/multiple_choice.cpp @@ -41,7 +41,7 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) { } void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active) { - RealSize size; + RealSize size; size.height = item_height; if (nativeLook() && (style().render_style & RENDER_CHECKLIST)) { wxRect rect = dc.tr(RealRect(pos + RealSize(1,1), RealSize(12,12))); draw_checkbox(nullptr, dc.getDC(), rect, active); // TODO @@ -60,7 +60,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const } if (style().render_style & RENDER_TEXT) { // draw text - String text = tr(*viewer.stylesheet, choice, capitalize(choice)); + String text = tr(*viewer.stylesheet, choice, capitalize_sentence(choice)); RealSize text_size = dc.GetTextExtent(text); dc.DrawText(text, align_in_rect(ALIGN_MIDDLE_LEFT, text_size, RealRect(pos + RealSize(size.width + 1, 0), RealSize(0,size.height)))); diff --git a/src/render/value/multiple_choice.hpp b/src/render/value/multiple_choice.hpp index 8de59a49..d57ffc87 100644 --- a/src/render/value/multiple_choice.hpp +++ b/src/render/value/multiple_choice.hpp @@ -18,9 +18,11 @@ /// Viewer that displays a multiple choice value class MultipleChoiceValueViewer : public ValueViewer { public: - DECLARE_VALUE_VIEWER(MultipleChoice) : ValueViewer(parent,style) {} + DECLARE_VALUE_VIEWER(MultipleChoice) : ValueViewer(parent,style), item_height(0) {} virtual void draw(RotatedDC& dc); + protected: + double item_height; ///< Height of a single item, or 0 if non uniform private: void drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active = true); };