Commit d2b3e24f authored by twanvl's avatar twanvl

Multiple choice choices can be drawn as radio buttons instead of check boxes

parent fa29cfb3
...@@ -49,11 +49,11 @@ IMPLEMENT_REFLECTION(ChoiceField) { ...@@ -49,11 +49,11 @@ IMPLEMENT_REFLECTION(ChoiceField) {
ChoiceField::Choice::Choice() ChoiceField::Choice::Choice()
: first_id(0) : first_id(0)
, line_below(false), enabled(true) , line_below(false), enabled(true), type(CHOICE_TYPE_CHECK)
{} {}
ChoiceField::Choice::Choice(const String& name) ChoiceField::Choice::Choice(const String& name)
: name(name), first_id(0) : name(name), first_id(0)
, line_below(false), enabled(true) , line_below(false), enabled(true), type(CHOICE_TYPE_CHECK)
{} {}
...@@ -139,6 +139,11 @@ String ChoiceField::Choice::choiceNameNice(int id) const { ...@@ -139,6 +139,11 @@ String ChoiceField::Choice::choiceNameNice(int id) const {
} }
IMPLEMENT_REFLECTION_ENUM(ChoiceChoiceType) {
VALUE_N("check", CHOICE_TYPE_CHECK);
VALUE_N("radio", CHOICE_TYPE_RADIO);
}
IMPLEMENT_REFLECTION_NO_GET_MEMBER(ChoiceField::Choice) { IMPLEMENT_REFLECTION_NO_GET_MEMBER(ChoiceField::Choice) {
if (isGroup() || line_below || enabled.isScripted() || (tag.reading() && tag.isComplex())) { if (isGroup() || line_below || enabled.isScripted() || (tag.reading() && tag.isComplex())) {
// complex values are groups // complex values are groups
...@@ -147,6 +152,7 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(ChoiceField::Choice) { ...@@ -147,6 +152,7 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(ChoiceField::Choice) {
REFLECT(choices); REFLECT(choices);
REFLECT(line_below); REFLECT(line_below);
REFLECT(enabled); REFLECT(enabled);
REFLECT(type);
} else { } else {
REFLECT_NAMELESS(name); REFLECT_NAMELESS(name);
} }
......
...@@ -46,6 +46,12 @@ class ChoiceField : public Field { ...@@ -46,6 +46,12 @@ class ChoiceField : public Field {
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
enum ChoiceChoiceType {
CHOICE_TYPE_CHECK,
CHOICE_TYPE_RADIO
};
/// An item that can be chosen for this field /// An item that can be chosen for this field
class ChoiceField::Choice : public IntrusivePtrBase<ChoiceField::Choice> { class ChoiceField::Choice : public IntrusivePtrBase<ChoiceField::Choice> {
public: public:
...@@ -57,6 +63,7 @@ class ChoiceField::Choice : public IntrusivePtrBase<ChoiceField::Choice> { ...@@ -57,6 +63,7 @@ class ChoiceField::Choice : public IntrusivePtrBase<ChoiceField::Choice> {
vector<ChoiceP> choices; ///< Choices and sub groups in this group vector<ChoiceP> choices; ///< Choices and sub groups in this group
bool line_below; ///< Show a line after this item? bool line_below; ///< Show a line after this item?
Scriptable<bool> enabled; ///< Is this item enabled? Scriptable<bool> enabled; ///< Is this item enabled?
ChoiceChoiceType type; ///< How should this item be shown, only for multiple choice fields
/// First item-id in this group (can be the default item) /// First item-id in this group (can be the default item)
/** Item-ids are consecutive integers, a group uses all ids [first_id..lastId()). /** Item-ids are consecutive integers, a group uses all ids [first_id..lastId()).
* The top level group has first_id 0. * The top level group has first_id 0.
......
...@@ -214,3 +214,24 @@ void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked, bool e ...@@ -214,3 +214,24 @@ void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked, bool e
dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
} }
void draw_radiobox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled) {
#if wxUSE_UXTHEME && defined(__WXMSW__)
// TODO: Windows version?
#endif
// portable version
#if 1
// circle drawing on windows looks absolutely horrible
// so use rounded rectangles instead
dc.SetPen(wxSystemSettings::GetColour(enabled ? wxSYS_COLOUR_WINDOWTEXT: wxSYS_COLOUR_GRAYTEXT));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
//dc.DrawEllipse(rect.x, rect.y, rect.width, rect.height);
dc.DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, rect.width*0.5-1);
if (checked) {
dc.SetBrush(wxSystemSettings::GetColour(enabled ? wxSYS_COLOUR_WINDOWTEXT: wxSYS_COLOUR_GRAYTEXT));
dc.SetPen(*wxTRANSPARENT_PEN);
//dc.DrawEllipse(rect.x+2,rect.y+2,rect.width-4,rect.height-4);
dc.DrawRoundedRectangle(rect.x+3, rect.y+3, rect.width-6, rect.height-6, rect.width*0.5-4);
}
#endif
}
...@@ -63,5 +63,8 @@ void draw_drop_down_arrow(Window* win, DC& dc, const wxRect& rect, bool active); ...@@ -63,5 +63,8 @@ void draw_drop_down_arrow(Window* win, DC& dc, const wxRect& rect, bool active);
/// Draws a check box /// Draws a check box
void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled = true); void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled = true);
/// Draws a radio button
void draw_radiobox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled = true);
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -45,9 +45,11 @@ void DropDownMultipleChoiceList::select(size_t item) { ...@@ -45,9 +45,11 @@ void DropDownMultipleChoiceList::select(size_t item) {
void DropDownMultipleChoiceList::drawIcon(DC& dc, int x, int y, size_t item, bool selected) const { void DropDownMultipleChoiceList::drawIcon(DC& dc, int x, int y, size_t item, bool selected) const {
// is this item active/checked? // is this item active/checked?
bool active = false; bool active = false;
bool radio = false;
if (!isFieldDefault(item)) { if (!isFieldDefault(item)) {
ChoiceField::ChoiceP choice = getChoice(item); ChoiceField::ChoiceP choice = getChoice(item);
active = dynamic_cast<MultipleChoiceValueEditor&>(cve).active[choice->first_id]; active = dynamic_cast<MultipleChoiceValueEditor&>(cve).active[choice->first_id];
radio = choice->type == CHOICE_TYPE_RADIO;
} else { } else {
active = dynamic_cast<MultipleChoiceValueEditor&>(cve).value().value.isDefault(); active = dynamic_cast<MultipleChoiceValueEditor&>(cve).value().value.isDefault();
} }
...@@ -56,7 +58,11 @@ void DropDownMultipleChoiceList::drawIcon(DC& dc, int x, int y, size_t item, boo ...@@ -56,7 +58,11 @@ void DropDownMultipleChoiceList::drawIcon(DC& dc, int x, int y, size_t item, boo
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
dc.DrawRectangle(x,y,16,16); dc.DrawRectangle(x,y,16,16);
wxRect rect = RealRect(x+2,y+2,12,12); wxRect rect = RealRect(x+2,y+2,12,12);
draw_checkbox(nullptr, dc, rect, active, itemEnabled(item)); if (radio) {
draw_radiobox(nullptr, dc, rect, active, itemEnabled(item));
} else {
draw_checkbox(nullptr, dc, rect, active, itemEnabled(item));
}
// draw icon // draw icon
DropDownChoiceListBase::drawIcon(dc, x + 16, y, item, selected); DropDownChoiceListBase::drawIcon(dc, x + 16, y, item, selected);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment