Change tabs to two spaces.

This commit is contained in:
Lymia Aluysia
2017-01-18 08:43:21 -06:00
parent d7f5f0dc3b
commit d2c635f739
329 changed files with 41307 additions and 41496 deletions
+15 -15
View File
@@ -12,38 +12,38 @@
// ----------------------------------------------------------------------------- : BooleanField
BooleanField::BooleanField() {
choices->choices.push_back(intrusive(new Choice(_("yes"))));
choices->choices.push_back(intrusive(new Choice(_("no"))));
choices->initIds();
choices->choices.push_back(intrusive(new Choice(_("yes"))));
choices->choices.push_back(intrusive(new Choice(_("no"))));
choices->initIds();
}
IMPLEMENT_FIELD_TYPE(Boolean, "boolean");
IMPLEMENT_REFLECTION(BooleanField) {
REFLECT_BASE(Field); // NOTE: don't reflect as a ChoiceField
REFLECT(script);
REFLECT_N("default", default_script);
REFLECT(initial);
REFLECT_BASE(Field); // NOTE: don't reflect as a ChoiceField
REFLECT(script);
REFLECT_N("default", default_script);
REFLECT(initial);
}
// ----------------------------------------------------------------------------- : BooleanStyle
BooleanStyle::BooleanStyle(const ChoiceFieldP& field)
: ChoiceStyle(field)
: ChoiceStyle(field)
{
render_style = RENDER_BOTH;
//choice_images[_("yes")] = ScriptableImage(_("buildin_image(\"bool_yes\")"));
//choice_images[_("no")] = ScriptableImage(_("buildin_image(\"bool_no\")"));
choice_images[_("yes")] = ScriptableImage(intrusive(new BuiltInImage(_("bool_yes"))));
choice_images[_("no")] = ScriptableImage(intrusive(new BuiltInImage(_("bool_no"))));
render_style = RENDER_BOTH;
//choice_images[_("yes")] = ScriptableImage(_("buildin_image(\"bool_yes\")"));
//choice_images[_("no")] = ScriptableImage(_("buildin_image(\"bool_no\")"));
choice_images[_("yes")] = ScriptableImage(intrusive(new BuiltInImage(_("bool_yes"))));
choice_images[_("no")] = ScriptableImage(intrusive(new BuiltInImage(_("bool_no"))));
}
IMPLEMENT_REFLECTION(BooleanStyle) {
REFLECT_BASE(ChoiceStyle);
REFLECT_BASE(ChoiceStyle);
}
// ----------------------------------------------------------------------------- : BooleanValue
IMPLEMENT_REFLECTION_NAMELESS(BooleanValue) {
REFLECT_BASE(ChoiceValue);
REFLECT_BASE(ChoiceValue);
}
+18 -18
View File
@@ -21,10 +21,10 @@ DECLARE_POINTER_TYPE(BooleanValue);
/// A field whos value is either true or false
class BooleanField : public ChoiceField {
public:
BooleanField();
DECLARE_FIELD_TYPE(Boolean);
// no extra data
BooleanField();
DECLARE_FIELD_TYPE(Boolean);
// no extra data
};
// ----------------------------------------------------------------------------- : BooleanStyle
@@ -32,14 +32,14 @@ class BooleanField : public ChoiceField {
/// The Style for a BooleanField
class BooleanStyle : public ChoiceStyle {
public:
BooleanStyle(const ChoiceFieldP& field);
DECLARE_HAS_FIELD(Boolean); // not DECLARE_STYLE_TYPE, because we use a normal ChoiceValueViewer/Editor
virtual StyleP clone() const;
// no extra data
BooleanStyle(const ChoiceFieldP& field);
DECLARE_HAS_FIELD(Boolean); // not DECLARE_STYLE_TYPE, because we use a normal ChoiceValueViewer/Editor
virtual StyleP clone() const;
// no extra data
private:
DECLARE_REFLECTION();
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : BooleanValue
@@ -47,14 +47,14 @@ class BooleanStyle : public ChoiceStyle {
/// The Value in a BooleanField
class BooleanValue : public ChoiceValue {
public:
inline BooleanValue(const ChoiceFieldP& field) : ChoiceValue(field) {}
DECLARE_HAS_FIELD(Boolean);
virtual ValueP clone() const;
// no extra data
inline BooleanValue(const ChoiceFieldP& field) : ChoiceValue(field) {}
DECLARE_HAS_FIELD(Boolean);
virtual ValueP clone() const;
// no extra data
private:
DECLARE_REFLECTION();
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : EOF
+194 -194
View File
@@ -18,292 +18,292 @@ DECLARE_TYPEOF(map<String COMMA ScriptableImage>);
// ----------------------------------------------------------------------------- : ChoiceField
ChoiceField::ChoiceField()
: choices((Choice*)new Choice)
, default_name(_("Default"))
: choices((Choice*)new Choice)
, default_name(_("Default"))
{}
IMPLEMENT_FIELD_TYPE(Choice, "choice");
void ChoiceField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
script .initDependencies(ctx, dep);
default_script.initDependencies(ctx, dep);
Field ::initDependencies(ctx, dep);
script .initDependencies(ctx, dep);
default_script.initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(ChoiceField) {
REFLECT_BASE(Field);
REFLECT_N("choices", choices->choices);
REFLECT(script);
REFLECT_N("default", default_script);
REFLECT(initial);
REFLECT(default_name);
REFLECT_IF_READING {
choices->initIds();
}
REFLECT(choice_colors);
REFLECT(choice_colors_cardlist);
REFLECT_BASE(Field);
REFLECT_N("choices", choices->choices);
REFLECT(script);
REFLECT_N("default", default_script);
REFLECT(initial);
REFLECT(default_name);
REFLECT_IF_READING {
choices->initIds();
}
REFLECT(choice_colors);
REFLECT(choice_colors_cardlist);
}
// ----------------------------------------------------------------------------- : ChoiceField::Choice
ChoiceField::Choice::Choice()
: line_below(false), enabled(true), type(CHOICE_TYPE_CHECK)
, first_id(0)
: line_below(false), enabled(true), type(CHOICE_TYPE_CHECK)
, first_id(0)
{}
ChoiceField::Choice::Choice(const String& name)
: name(name)
, line_below(false), enabled(true), type(CHOICE_TYPE_CHECK)
, first_id(0)
: name(name)
, line_below(false), enabled(true), type(CHOICE_TYPE_CHECK)
, first_id(0)
{}
bool ChoiceField::Choice::isGroup() const {
return !choices.empty();
return !choices.empty();
}
bool ChoiceField::Choice::hasDefault() const {
return !isGroup() || !default_name.empty();
return !isGroup() || !default_name.empty();
}
int ChoiceField::Choice::initIds() {
int id = first_id + (hasDefault() ? 1 : 0);
FOR_EACH(c, choices) {
c->first_id = id;
id = c->initIds();
}
return id;
int id = first_id + (hasDefault() ? 1 : 0);
FOR_EACH(c, choices) {
c->first_id = id;
id = c->initIds();
}
return id;
}
int ChoiceField::Choice::choiceCount() const {
return lastId() - first_id;
return lastId() - first_id;
}
int ChoiceField::Choice::lastId() const {
if (isGroup()) {
// last id of last choice
return choices.back()->lastId();
} else {
return first_id + 1;
}
if (isGroup()) {
// last id of last choice
return choices.back()->lastId();
} else {
return first_id + 1;
}
}
int ChoiceField::Choice::choiceId(const String& search_name) const {
if (hasDefault() && search_name == name) {
return first_id;
} else if (name.empty()) { // no name for this group, forward to all children
FOR_EACH_CONST(c, choices) {
int sub_id = c->choiceId(search_name);
if (sub_id != -1) return sub_id;
}
} else if (isGroup() && starts_with(search_name, name + _(" "))) {
String sub_name = search_name.substr(name.size() + 1);
FOR_EACH_CONST(c, choices) {
int sub_id = c->choiceId(sub_name);
if (sub_id != -1) return sub_id;
}
}
return -1;
if (hasDefault() && search_name == name) {
return first_id;
} else if (name.empty()) { // no name for this group, forward to all children
FOR_EACH_CONST(c, choices) {
int sub_id = c->choiceId(search_name);
if (sub_id != -1) return sub_id;
}
} else if (isGroup() && starts_with(search_name, name + _(" "))) {
String sub_name = search_name.substr(name.size() + 1);
FOR_EACH_CONST(c, choices) {
int sub_id = c->choiceId(sub_name);
if (sub_id != -1) return sub_id;
}
}
return -1;
}
String ChoiceField::Choice::choiceName(int id) const {
if (hasDefault() && id == first_id) {
return name;
} else {
FOR_EACH_CONST_REVERSE(c, choices) { // take the last one that still contains id
if (id >= c->first_id) {
if (name.empty()) {
return c->choiceName(id);
} else {
return name + _(" ") + c->choiceName(id);
}
}
}
}
return _("");
if (hasDefault() && id == first_id) {
return name;
} else {
FOR_EACH_CONST_REVERSE(c, choices) { // take the last one that still contains id
if (id >= c->first_id) {
if (name.empty()) {
return c->choiceName(id);
} else {
return name + _(" ") + c->choiceName(id);
}
}
}
}
return _("");
}
String ChoiceField::Choice::choiceNameNice(int id) const {
if (!isGroup() && id == first_id) {
return name;
} else if (hasDefault() && id == first_id) {
return default_name;
} else {
FOR_EACH_CONST_REVERSE(c, choices) {
if (id == c->first_id) {
return c->name; // we don't want "<group> default"
} else if (id > c->first_id) {
return c->choiceNameNice(id);
}
}
}
return _("");
if (!isGroup() && id == first_id) {
return name;
} else if (hasDefault() && id == first_id) {
return default_name;
} else {
FOR_EACH_CONST_REVERSE(c, choices) {
if (id == c->first_id) {
return c->name; // we don't want "<group> default"
} else if (id > c->first_id) {
return c->choiceNameNice(id);
}
}
}
return _("");
}
IMPLEMENT_REFLECTION_ENUM(ChoiceChoiceType) {
VALUE_N("check", CHOICE_TYPE_CHECK);
VALUE_N("radio", CHOICE_TYPE_RADIO);
VALUE_N("check", CHOICE_TYPE_CHECK);
VALUE_N("radio", CHOICE_TYPE_RADIO);
}
IMPLEMENT_REFLECTION(ChoiceField::Choice) {
if (isGroup() || line_below || enabled.isScripted() || tag.isComplex()) {
// complex values are groups
REFLECT(name);
REFLECT_N("group_choice", default_name);
REFLECT(choices);
REFLECT(line_below);
REFLECT(enabled);
REFLECT(type);
} else {
REFLECT_NAMELESS(name);
}
if (isGroup() || line_below || enabled.isScripted() || tag.isComplex()) {
// complex values are groups
REFLECT(name);
REFLECT_N("group_choice", default_name);
REFLECT(choices);
REFLECT(line_below);
REFLECT(enabled);
REFLECT(type);
} else {
REFLECT_NAMELESS(name);
}
}
// ----------------------------------------------------------------------------- : ChoiceStyle
ChoiceStyle::ChoiceStyle(const ChoiceFieldP& field)
: Style(field)
, popup_style(POPUP_DROPDOWN)
, render_style(RENDER_TEXT)
, choice_images_initialized(false)
, combine(COMBINE_NORMAL)
, alignment(ALIGN_STRETCH)
, thumbnails(nullptr)
, content_width(0.0), content_height(0.0)
: Style(field)
, popup_style(POPUP_DROPDOWN)
, render_style(RENDER_TEXT)
, choice_images_initialized(false)
, combine(COMBINE_NORMAL)
, alignment(ALIGN_STRETCH)
, thumbnails(nullptr)
, content_width(0.0), content_height(0.0)
{}
ChoiceStyle::~ChoiceStyle() {
delete thumbnails;
delete thumbnails;
}
void ChoiceStyle::initImage() {
if (image.isSet() || choice_images.empty()) return;
// for, for example:
// choice images:
// a: {uvw}
// b: {xyz}
// generate the script:
// [a: {uvw}, b: {xyz}][input]() or else nil
// or in bytecode
// PUSH_CONST [a: {uvw}, b: {xyz}]
// GET_VAR input
// MEMBER
// CALL 0
// PUSH_CONST nil
// OR_ELSE
ScriptCustomCollectionP lookup(new ScriptCustomCollection());
FOR_EACH(ci, choice_images) {
lookup->key_value[ci.first] = ci.second.getValidScriptP();
}
Script& script = image.getMutableScript();
script.addInstruction(I_PUSH_CONST, lookup);
script.addInstruction(I_GET_VAR, SCRIPT_VAR_input);
script.addInstruction(I_BINARY, I_MEMBER);
script.addInstruction(I_CALL, 0);
script.addInstruction(I_PUSH_CONST, script_nil);
script.addInstruction(I_BINARY, I_OR_ELSE);
if (image.isSet() || choice_images.empty()) return;
// for, for example:
// choice images:
// a: {uvw}
// b: {xyz}
// generate the script:
// [a: {uvw}, b: {xyz}][input]() or else nil
// or in bytecode
// PUSH_CONST [a: {uvw}, b: {xyz}]
// GET_VAR input
// MEMBER
// CALL 0
// PUSH_CONST nil
// OR_ELSE
ScriptCustomCollectionP lookup(new ScriptCustomCollection());
FOR_EACH(ci, choice_images) {
lookup->key_value[ci.first] = ci.second.getValidScriptP();
}
Script& script = image.getMutableScript();
script.addInstruction(I_PUSH_CONST, lookup);
script.addInstruction(I_GET_VAR, SCRIPT_VAR_input);
script.addInstruction(I_BINARY, I_MEMBER);
script.addInstruction(I_CALL, 0);
script.addInstruction(I_PUSH_CONST, script_nil);
script.addInstruction(I_BINARY, I_OR_ELSE);
}
int ChoiceStyle::update(Context& ctx) {
// Don't update the choice images, leave that to invalidate()
int change = Style::update(ctx)
| font .update(ctx) * CHANGE_OTHER;
if (!choice_images_initialized) {
// we only want to do this once because it is rather slow, other updates are handled by dependencies
choice_images_initialized = true;
FOR_EACH(ci, choice_images) {
if (ci.second.update(ctx)) {
change |= CHANGE_OTHER;
// TODO : remove this thumbnail
}
}
}
return change;
// Don't update the choice images, leave that to invalidate()
int change = Style::update(ctx)
| font .update(ctx) * CHANGE_OTHER;
if (!choice_images_initialized) {
// we only want to do this once because it is rather slow, other updates are handled by dependencies
choice_images_initialized = true;
FOR_EACH(ci, choice_images) {
if (ci.second.update(ctx)) {
change |= CHANGE_OTHER;
// TODO : remove this thumbnail
}
}
}
return change;
}
void ChoiceStyle::initDependencies(Context& ctx, const Dependency& dep) const {
Style::initDependencies(ctx, dep);
FOR_EACH_CONST(ci, choice_images) {
ci.second.initDependencies(ctx, dep);
}
Style::initDependencies(ctx, dep);
FOR_EACH_CONST(ci, choice_images) {
ci.second.initDependencies(ctx, dep);
}
}
void ChoiceStyle::checkContentDependencies(Context& ctx, const Dependency& dep) const {
Style::checkContentDependencies(ctx, dep);
image.initDependencies(ctx, dep);
FOR_EACH_CONST(ci, choice_images) {
ci.second.initDependencies(ctx, dep);
}
Style::checkContentDependencies(ctx, dep);
image.initDependencies(ctx, dep);
FOR_EACH_CONST(ci, choice_images) {
ci.second.initDependencies(ctx, dep);
}
}
void ChoiceStyle::invalidate() {
// TODO : this is also done in update(), once should be enough
// Update choice images and thumbnails
int end = field().choices->lastId();
thumbnails_status.resize(end, THUMB_NOT_MADE);
for (int i = 0 ; i < end ; ++i) {
if (thumbnails_status[i] == THUMB_OK) thumbnails_status[i] = THUMB_CHANGED;
}
tellListeners(CHANGE_OTHER);
// TODO : this is also done in update(), once should be enough
// Update choice images and thumbnails
int end = field().choices->lastId();
thumbnails_status.resize(end, THUMB_NOT_MADE);
for (int i = 0 ; i < end ; ++i) {
if (thumbnails_status[i] == THUMB_OK) thumbnails_status[i] = THUMB_CHANGED;
}
tellListeners(CHANGE_OTHER);
}
IMPLEMENT_REFLECTION_ENUM(ChoicePopupStyle) {
VALUE_N("dropdown", POPUP_DROPDOWN);
VALUE_N("menu", POPUP_MENU);
VALUE_N("in place", POPUP_DROPDOWN_IN_PLACE);
VALUE_N("dropdown", POPUP_DROPDOWN);
VALUE_N("menu", POPUP_MENU);
VALUE_N("in place", POPUP_DROPDOWN_IN_PLACE);
}
IMPLEMENT_REFLECTION_ENUM(ChoiceRenderStyle) {
VALUE_N("text", RENDER_TEXT);
VALUE_N("image", RENDER_IMAGE);
VALUE_N("both", RENDER_BOTH);
VALUE_N("hidden", RENDER_HIDDEN);
VALUE_N("image hidden", RENDER_HIDDEN_IMAGE);
VALUE_N("checklist", RENDER_TEXT_CHECKLIST);
VALUE_N("image checklist", RENDER_IMAGE_CHECKLIST);
VALUE_N("both checklist", RENDER_BOTH_CHECKLIST);
VALUE_N("text list", RENDER_TEXT_LIST);
VALUE_N("image list", RENDER_IMAGE_LIST);
VALUE_N("both list", RENDER_BOTH_LIST);
VALUE_N("text", RENDER_TEXT);
VALUE_N("image", RENDER_IMAGE);
VALUE_N("both", RENDER_BOTH);
VALUE_N("hidden", RENDER_HIDDEN);
VALUE_N("image hidden", RENDER_HIDDEN_IMAGE);
VALUE_N("checklist", RENDER_TEXT_CHECKLIST);
VALUE_N("image checklist", RENDER_IMAGE_CHECKLIST);
VALUE_N("both checklist", RENDER_BOTH_CHECKLIST);
VALUE_N("text list", RENDER_TEXT_LIST);
VALUE_N("image list", RENDER_IMAGE_LIST);
VALUE_N("both list", RENDER_BOTH_LIST);
}
template <typename T> void reflect_content(T& tag, const ChoiceStyle& cs) {}
template <> void reflect_content(GetMember& tag, const ChoiceStyle& cs) {
REFLECT_N("content_width", cs.content_width);
REFLECT_N("content_height", cs.content_height);
REFLECT_N("content_width", cs.content_width);
REFLECT_N("content_height", cs.content_height);
}
IMPLEMENT_REFLECTION(ChoiceStyle) {
REFLECT_ALIAS(300, "card list colors", "colors card list");
REFLECT_BASE(Style);
REFLECT(popup_style);
REFLECT(render_style);
REFLECT(combine);
REFLECT(alignment);
REFLECT(font);
REFLECT(image);
REFLECT(choice_images);
reflect_content(tag, *this);
REFLECT_ALIAS(300, "card list colors", "colors card list");
REFLECT_BASE(Style);
REFLECT(popup_style);
REFLECT(render_style);
REFLECT(combine);
REFLECT(alignment);
REFLECT(font);
REFLECT(image);
REFLECT(choice_images);
reflect_content(tag, *this);
}
// ----------------------------------------------------------------------------- : ChoiceValue
ChoiceValue::ChoiceValue(const ChoiceFieldP& field, bool initial_first_choice)
: Value(field)
, value( !field->initial.empty() ? field->initial
: initial_first_choice ? field->choices->choiceName(0)
: _("")
, true)
: Value(field)
, value( !field->initial.empty() ? field->initial
: initial_first_choice ? field->choices->choiceName(0)
: _("")
, true)
{}
String ChoiceValue::toString() const {
return value();
return value();
}
bool ChoiceValue::update(Context& ctx) {
bool change = field().default_script.invokeOnDefault(ctx, value)
| field(). script.invokeOn(ctx, value);
Value::update(ctx);
return change;
bool change = field().default_script.invokeOnDefault(ctx, value)
| field(). script.invokeOn(ctx, value);
Value::update(ctx);
return change;
}
IMPLEMENT_REFLECTION_NAMELESS(ChoiceValue) {
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(value);
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(value);
}
INSTANTIATE_REFLECTION_NAMELESS(ChoiceValue)
+117 -117
View File
@@ -27,139 +27,139 @@ DECLARE_POINTER_TYPE(ChoiceValue);
/// A field that contains a list of choices
class ChoiceField : public Field {
public:
ChoiceField();
DECLARE_FIELD_TYPE(Choice);
class Choice;
typedef intrusive_ptr<Choice> ChoiceP;
ChoiceP choices; ///< A choice group of possible choices
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
String initial; ///< Initial choice of a new value, or ""
String default_name; ///< Name of "default" value
map<String,Color> choice_colors; ///< Colors for the various choices (when color_cardlist)
map<String,Color> choice_colors_cardlist; ///< Colors for the various choices, for in the card list
virtual void initDependencies(Context&, const Dependency&) const;
ChoiceField();
DECLARE_FIELD_TYPE(Choice);
class Choice;
typedef intrusive_ptr<Choice> ChoiceP;
ChoiceP choices; ///< A choice group of possible choices
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
String initial; ///< Initial choice of a new value, or ""
String default_name; ///< Name of "default" value
map<String,Color> choice_colors; ///< Colors for the various choices (when color_cardlist)
map<String,Color> choice_colors_cardlist; ///< Colors for the various choices, for in the card list
virtual void initDependencies(Context&, const Dependency&) const;
};
enum ChoiceChoiceType {
CHOICE_TYPE_CHECK,
CHOICE_TYPE_RADIO
CHOICE_TYPE_CHECK,
CHOICE_TYPE_RADIO
};
/// An item that can be chosen for this field
class ChoiceField::Choice : public IntrusivePtrBase<ChoiceField::Choice> {
public:
Choice();
Choice(const String& name);
String name; ///< Name/value of the item
String default_name; ///< A default item, if this is a group and default_name.empty() there is no default
vector<ChoiceP> choices; ///< Choices and sub groups in this group
bool line_below; ///< Show a line after this item?
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)
/** Item-ids are consecutive integers, a group uses all ids [first_id..lastId()).
* The top level group has first_id 0.
*/
int first_id;
/// Is this a group?
bool isGroup() const;
/// Can this Choice itself be chosen?
/** For a single choice this is always true, for a group only if it has a default choice */
bool hasDefault() const;
/// Initialize the first_id of children
/** @pre first_id is set
* Returns lastId()
*/
int initIds();
/// Number of choices in this group (and subgroups), 1 if it is not a group
/** The default choice also counts */
int choiceCount() const;
/// item-id just beyond the end of this group
int lastId() const;
/// item-id of a choice, given the internal name
/** If the id is not in this group, returns -1 */
int choiceId(const String& name) const;
/// Internal name of a choice
/** The internal name is formed by concatenating the names of all parents, separated by spaces.
* Returns "" if id is not in this group
*/
String choiceName(int id) const;
/// Formated name of a choice.
/** Intended for use in menu structures, so it doesn't include the group name for children.
* Returns "" if id is not in this group.
*/
String choiceNameNice(int id) const;
DECLARE_REFLECTION();
Choice();
Choice(const String& name);
String name; ///< Name/value of the item
String default_name; ///< A default item, if this is a group and default_name.empty() there is no default
vector<ChoiceP> choices; ///< Choices and sub groups in this group
bool line_below; ///< Show a line after this item?
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)
/** Item-ids are consecutive integers, a group uses all ids [first_id..lastId()).
* The top level group has first_id 0.
*/
int first_id;
/// Is this a group?
bool isGroup() const;
/// Can this Choice itself be chosen?
/** For a single choice this is always true, for a group only if it has a default choice */
bool hasDefault() const;
/// Initialize the first_id of children
/** @pre first_id is set
* Returns lastId()
*/
int initIds();
/// Number of choices in this group (and subgroups), 1 if it is not a group
/** The default choice also counts */
int choiceCount() const;
/// item-id just beyond the end of this group
int lastId() const;
/// item-id of a choice, given the internal name
/** If the id is not in this group, returns -1 */
int choiceId(const String& name) const;
/// Internal name of a choice
/** The internal name is formed by concatenating the names of all parents, separated by spaces.
* Returns "" if id is not in this group
*/
String choiceName(int id) const;
/// Formated name of a choice.
/** Intended for use in menu structures, so it doesn't include the group name for children.
* Returns "" if id is not in this group.
*/
String choiceNameNice(int id) const;
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : ChoiceStyle
// How should the menu for a choice look?
enum ChoicePopupStyle
{ POPUP_MENU
, POPUP_DROPDOWN
, POPUP_DROPDOWN_IN_PLACE
{ POPUP_MENU
, POPUP_DROPDOWN
, POPUP_DROPDOWN_IN_PLACE
};
// How should a choice value be rendered?
enum ChoiceRenderStyle
{ RENDER_TEXT = 0x01 // render the name as text
, RENDER_IMAGE = 0x10 // render an image
, RENDER_HIDDEN = 0x20 // don't render anything, only have a menu
, RENDER_CHECKLIST = 0x100 // render as a checklist, intended for multiple choice
, RENDER_LIST = 0x200 // render as a list of images/text, intended for multiple choice
, RENDER_BOTH = RENDER_TEXT | RENDER_IMAGE
, RENDER_HIDDEN_IMAGE = RENDER_HIDDEN | RENDER_IMAGE
, RENDER_TEXT_CHECKLIST = RENDER_CHECKLIST | RENDER_TEXT
, RENDER_IMAGE_CHECKLIST = RENDER_CHECKLIST | RENDER_IMAGE
, RENDER_BOTH_CHECKLIST = RENDER_CHECKLIST | RENDER_BOTH
, RENDER_TEXT_LIST = RENDER_LIST | RENDER_TEXT
, RENDER_IMAGE_LIST = RENDER_LIST | RENDER_IMAGE
, RENDER_BOTH_LIST = RENDER_LIST | RENDER_BOTH
{ RENDER_TEXT = 0x01 // render the name as text
, RENDER_IMAGE = 0x10 // render an image
, RENDER_HIDDEN = 0x20 // don't render anything, only have a menu
, RENDER_CHECKLIST = 0x100 // render as a checklist, intended for multiple choice
, RENDER_LIST = 0x200 // render as a list of images/text, intended for multiple choice
, RENDER_BOTH = RENDER_TEXT | RENDER_IMAGE
, RENDER_HIDDEN_IMAGE = RENDER_HIDDEN | RENDER_IMAGE
, RENDER_TEXT_CHECKLIST = RENDER_CHECKLIST | RENDER_TEXT
, RENDER_IMAGE_CHECKLIST = RENDER_CHECKLIST | RENDER_IMAGE
, RENDER_BOTH_CHECKLIST = RENDER_CHECKLIST | RENDER_BOTH
, RENDER_TEXT_LIST = RENDER_LIST | RENDER_TEXT
, RENDER_IMAGE_LIST = RENDER_LIST | RENDER_IMAGE
, RENDER_BOTH_LIST = RENDER_LIST | RENDER_BOTH
};
enum ThumbnailStatus
{ THUMB_NOT_MADE // there is no image
, THUMB_OK // image is ok
, THUMB_CHANGED // there is an image, but it may need to be updated
{ THUMB_NOT_MADE // there is no image
, THUMB_OK // image is ok
, THUMB_CHANGED // there is an image, but it may need to be updated
};
/// The Style for a ChoiceField
class ChoiceStyle : public Style {
public:
ChoiceStyle(const ChoiceFieldP& field);
DECLARE_STYLE_TYPE(Choice);
~ChoiceStyle();
ChoicePopupStyle popup_style; ///< Style of popups/menus
ChoiceRenderStyle render_style; ///< Style of rendering
Font font; ///< Font for drawing text (when RENDER_TEXT)
CachedScriptableImage image; ///< Image to draw (when RENDER_IMAGE)
map<String,ScriptableImage> choice_images; ///< Images for the various choices (when RENDER_IMAGE)
bool choice_images_initialized;
ImageCombine combine; ///< Combining mode for drawing the images
Alignment alignment; ///< Alignment of images
wxImageList* thumbnails; ///< Thumbnails for the choices
vector<ThumbnailStatus> thumbnails_status; ///< Which thumbnails are up to date?
// information from image rendering
double content_width, content_height; ///< Size of the rendered image/text
/// Initialize image from choice_images
void initImage();
virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
virtual void checkContentDependencies(Context&, const Dependency&) const;
virtual void invalidate();
ChoiceStyle(const ChoiceFieldP& field);
DECLARE_STYLE_TYPE(Choice);
~ChoiceStyle();
ChoicePopupStyle popup_style; ///< Style of popups/menus
ChoiceRenderStyle render_style; ///< Style of rendering
Font font; ///< Font for drawing text (when RENDER_TEXT)
CachedScriptableImage image; ///< Image to draw (when RENDER_IMAGE)
map<String,ScriptableImage> choice_images; ///< Images for the various choices (when RENDER_IMAGE)
bool choice_images_initialized;
ImageCombine combine; ///< Combining mode for drawing the images
Alignment alignment; ///< Alignment of images
wxImageList* thumbnails; ///< Thumbnails for the choices
vector<ThumbnailStatus> thumbnails_status; ///< Which thumbnails are up to date?
// information from image rendering
double content_width, content_height; ///< Size of the rendered image/text
/// Initialize image from choice_images
void initImage();
virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
virtual void checkContentDependencies(Context&, const Dependency&) const;
virtual void invalidate();
};
// ----------------------------------------------------------------------------- : ChoiceValue
@@ -167,16 +167,16 @@ class ChoiceStyle : public Style {
/// The Value in a ChoiceField
class ChoiceValue : public Value {
public:
/// Create a value for the given field
/** If initial_first_choice then the first choice should be used in the absence of
an explicit initial value
*/
ChoiceValue(const ChoiceFieldP& field, bool initial_first_choice = true);
DECLARE_VALUE_TYPE(Choice, Defaultable<String>);
ValueType value; /// The name of the selected choice
virtual bool update(Context&);
/// Create a value for the given field
/** If initial_first_choice then the first choice should be used in the absence of
an explicit initial value
*/
ChoiceValue(const ChoiceFieldP& field, bool initial_first_choice = true);
DECLARE_VALUE_TYPE(Choice, Defaultable<String>);
ValueType value; /// The name of the selected choice
virtual bool update(Context&);
};
// ----------------------------------------------------------------------------- : EOF
+49 -49
View File
@@ -15,90 +15,90 @@ DECLARE_TYPEOF_COLLECTION(ColorField::ChoiceP);
// ----------------------------------------------------------------------------- : ColorField
ColorField::ColorField()
: allow_custom(true)
, default_name(_("Default"))
: allow_custom(true)
, default_name(_("Default"))
{}
IMPLEMENT_FIELD_TYPE(Color, "color");
void ColorField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
script .initDependencies(ctx, dep);
default_script.initDependencies(ctx, dep);
Field ::initDependencies(ctx, dep);
script .initDependencies(ctx, dep);
default_script.initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(ColorField) {
REFLECT_BASE(Field);
REFLECT(script);
REFLECT_N("default", default_script);
REFLECT(initial);
REFLECT(default_name);
REFLECT(allow_custom);
REFLECT(choices);
REFLECT_BASE(Field);
REFLECT(script);
REFLECT_N("default", default_script);
REFLECT(initial);
REFLECT(default_name);
REFLECT(allow_custom);
REFLECT(choices);
}
// ----------------------------------------------------------------------------- : ColorField::Choice
IMPLEMENT_REFLECTION(ColorField::Choice) {
if (tag.reading() && !tag.isComplex()) {
REFLECT_NAMELESS(name);
color = parse_color(name);
} else {
REFLECT(name);
REFLECT(color);
}
if (tag.reading() && !tag.isComplex()) {
REFLECT_NAMELESS(name);
color = parse_color(name);
} else {
REFLECT(name);
REFLECT(color);
}
}
// ----------------------------------------------------------------------------- : ColorStyle
ColorStyle::ColorStyle(const ColorFieldP& field)
: Style(field)
, radius(0)
, left_width(100000), right_width (100000)
, top_width (100000), bottom_width(100000)
, combine(COMBINE_NORMAL)
: Style(field)
, radius(0)
, left_width(100000), right_width (100000)
, top_width (100000), bottom_width(100000)
, combine(COMBINE_NORMAL)
{}
IMPLEMENT_REFLECTION(ColorStyle) {
REFLECT_BASE(Style);
REFLECT(radius);
REFLECT(left_width);
REFLECT(right_width);
REFLECT(top_width);
REFLECT(bottom_width);
REFLECT(combine);
REFLECT_BASE(Style);
REFLECT(radius);
REFLECT(left_width);
REFLECT(right_width);
REFLECT(top_width);
REFLECT(bottom_width);
REFLECT(combine);
}
int ColorStyle::update(Context& ctx) {
return Style::update(ctx);
return Style::update(ctx);
}
// ----------------------------------------------------------------------------- : ColorValue
ColorValue::ColorValue(const ColorFieldP& field)
: Value(field)
, value( !field->initial.isDefault() ? field->initial()
: !field->choices.empty() ? field->choices[0]->color
: *wxBLACK
, true)
: Value(field)
, value( !field->initial.isDefault() ? field->initial()
: !field->choices.empty() ? field->choices[0]->color
: *wxBLACK
, true)
{}
String ColorValue::toString() const {
if (value.isDefault()) return field().default_name;
// is this a named color?
FOR_EACH(c, field().choices) {
if (value() == c->color) return c->name;
}
return _("<color>");
if (value.isDefault()) return field().default_name;
// is this a named color?
FOR_EACH(c, field().choices) {
if (value() == c->color) return c->name;
}
return _("<color>");
}
bool ColorValue::update(Context& ctx) {
bool change = field().default_script.invokeOnDefault(ctx, value)
| field(). script.invokeOn(ctx, value);
Value::update(ctx);
return change;
bool change = field().default_script.invokeOnDefault(ctx, value)
| field(). script.invokeOn(ctx, value);
Value::update(ctx);
return change;
}
IMPLEMENT_REFLECTION_NAMELESS(ColorValue) {
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(value);
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(value);
}
+35 -35
View File
@@ -24,29 +24,29 @@ DECLARE_POINTER_TYPE(ColorValue);
/// A field for color values, it contains a list of choices for colors
class ColorField : public Field {
public:
ColorField();
DECLARE_FIELD_TYPE(Color);
class Choice;
typedef intrusive_ptr<Choice> ChoiceP;
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
vector<ChoiceP> choices; ///< Color choices available
bool allow_custom; ///< Are colors not in the list of choices allowed?
Defaultable<Color> initial; ///< Initial choice of a new value, if not set the first choice is used
String default_name; ///< Name of "default" value
virtual void initDependencies(Context&, const Dependency&) const;
ColorField();
DECLARE_FIELD_TYPE(Color);
class Choice;
typedef intrusive_ptr<Choice> ChoiceP;
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
vector<ChoiceP> choices; ///< Color choices available
bool allow_custom; ///< Are colors not in the list of choices allowed?
Defaultable<Color> initial; ///< Initial choice of a new value, if not set the first choice is used
String default_name; ///< Name of "default" value
virtual void initDependencies(Context&, const Dependency&) const;
};
/// A color that can be chosen for this field
class ColorField::Choice : public IntrusivePtrBase<ColorField::Choice> {
public:
String name; ///< Name of the color
Color color; ///< The actual color
DECLARE_REFLECTION();
String name; ///< Name of the color
Color color; ///< The actual color
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : ColorStyle
@@ -54,17 +54,17 @@ class ColorField::Choice : public IntrusivePtrBase<ColorField::Choice> {
/// The Style for a ColorField
class ColorStyle : public Style {
public:
ColorStyle(const ColorFieldP& field);
DECLARE_STYLE_TYPE(Color);
double radius; ///< Radius of round corners
double left_width; ///< Width of the colored region on the left side
double right_width; ///< Width of the colored region on the right side
double top_width; ///< Width of the colored region on the top side
double bottom_width; ///< Width of the colored region on the bottom side
ImageCombine combine; ///< How to combine image with the background
virtual int update(Context&);
ColorStyle(const ColorFieldP& field);
DECLARE_STYLE_TYPE(Color);
double radius; ///< Radius of round corners
double left_width; ///< Width of the colored region on the left side
double right_width; ///< Width of the colored region on the right side
double top_width; ///< Width of the colored region on the top side
double bottom_width; ///< Width of the colored region on the bottom side
ImageCombine combine; ///< How to combine image with the background
virtual int update(Context&);
};
// ----------------------------------------------------------------------------- : ColorValue
@@ -72,12 +72,12 @@ class ColorStyle : public Style {
/// The Value in a ColorField
class ColorValue : public Value {
public:
ColorValue(const ColorFieldP& field);
DECLARE_VALUE_TYPE(Color, Defaultable<Color>);
ValueType value; ///< The value
virtual bool update(Context&);
ColorValue(const ColorFieldP& field);
DECLARE_VALUE_TYPE(Color, Defaultable<Color>);
ValueType value; ///< The value
virtual bool update(Context&);
};
+10 -10
View File
@@ -15,38 +15,38 @@
IMPLEMENT_FIELD_TYPE(Image, "image");
IMPLEMENT_REFLECTION(ImageField) {
REFLECT_BASE(Field);
REFLECT_BASE(Field);
}
// ----------------------------------------------------------------------------- : ImageStyle
IMPLEMENT_REFLECTION(ImageStyle) {
REFLECT_BASE(Style);
REFLECT_N("default", default_image);
REFLECT_BASE(Style);
REFLECT_N("default", default_image);
}
int ImageStyle::update(Context& ctx) {
return Style ::update(ctx)
| default_image.update(ctx) * CHANGE_DEFAULT;
return Style ::update(ctx)
| default_image.update(ctx) * CHANGE_DEFAULT;
}
// ----------------------------------------------------------------------------- : ImageValue
String ImageValue::toString() const {
return filename.empty() ? wxEmptyString : _("<image>");
return filename.empty() ? wxEmptyString : _("<image>");
}
// custom reflection: convert to ScriptImageP for scripting
void ImageValue::reflect(Reader& tag) {
tag.handle(filename);
tag.handle(filename);
}
void ImageValue::reflect(Writer& tag) {
if (fieldP->save_value) tag.handle(filename);
if (fieldP->save_value) tag.handle(filename);
}
void ImageValue::reflect(GetMember& tag) {}
void ImageValue::reflect(GetDefaultMember& tag) {
// convert to ScriptImageP for scripting
tag.handle( (ScriptValueP)intrusive(new ImageValueToImage(filename, last_update)) );
// convert to ScriptImageP for scripting
tag.handle( (ScriptValueP)intrusive(new ImageValueToImage(filename, last_update)) );
}
+13 -13
View File
@@ -23,8 +23,8 @@ DECLARE_POINTER_TYPE(ImageValue);
/// A field for image values
class ImageField : public Field {
public:
// no extra data
DECLARE_FIELD_TYPE(Image);
// no extra data
DECLARE_FIELD_TYPE(Image);
};
// ----------------------------------------------------------------------------- : ImageStyle
@@ -32,12 +32,12 @@ class ImageField : public Field {
/// The Style for a ImageField
class ImageStyle : public Style {
public:
inline ImageStyle(const ImageFieldP& field) : Style(field) {}
DECLARE_STYLE_TYPE(Image);
ScriptableImage default_image; ///< Placeholder
virtual int update(Context&);
inline ImageStyle(const ImageFieldP& field) : Style(field) {}
DECLARE_STYLE_TYPE(Image);
ScriptableImage default_image; ///< Placeholder
virtual int update(Context&);
};
// ----------------------------------------------------------------------------- : ImageValue
@@ -45,11 +45,11 @@ class ImageStyle : public Style {
/// The Value in a ImageField, i.e. an image
class ImageValue : public Value {
public:
inline ImageValue(const ImageFieldP& field) : Value(field) {}
DECLARE_VALUE_TYPE(Image, FileName);
ValueType filename; ///< Filename of the image (in the current package), or ""
Age last_update; ///< When was the image last changed?
inline ImageValue(const ImageFieldP& field) : Value(field) {}
DECLARE_VALUE_TYPE(Image, FileName);
ValueType filename; ///< Filename of the image (in the current package), or ""
Age last_update; ///< When was the image last changed?
};
// ----------------------------------------------------------------------------- : EOF
+29 -29
View File
@@ -15,60 +15,60 @@
IMPLEMENT_FIELD_TYPE(Info, "info");
void InfoField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
script. initDependencies(ctx, dep);
Field ::initDependencies(ctx, dep);
script. initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(InfoField) {
REFLECT_BASE(Field);
REFLECT(script);
REFLECT_BASE(Field);
REFLECT(script);
}
// ----------------------------------------------------------------------------- : InfoStyle
InfoStyle::InfoStyle(const InfoFieldP& field)
: Style(field)
, alignment(ALIGN_TOP_LEFT)
, padding_left (2)
, padding_right (2)
, padding_top (2)
, padding_bottom(2)
, background_color(255,255,255)
: Style(field)
, alignment(ALIGN_TOP_LEFT)
, padding_left (2)
, padding_right (2)
, padding_top (2)
, padding_bottom(2)
, background_color(255,255,255)
{}
int InfoStyle::update(Context& ctx) {
return Style ::update(ctx)
| font .update(ctx) * CHANGE_OTHER;
return Style ::update(ctx)
| font .update(ctx) * CHANGE_OTHER;
}
void InfoStyle::initDependencies(Context& ctx, const Dependency& dep) const {
Style ::initDependencies(ctx, dep);
// font .initDependencies(ctx, dep);
Style ::initDependencies(ctx, dep);
// font .initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(InfoStyle) {
REFLECT_BASE(Style);
REFLECT(font);
REFLECT(alignment);
REFLECT(padding_left);
REFLECT(padding_right);
REFLECT(padding_top);
REFLECT(padding_bottom);
REFLECT(background_color);
REFLECT_BASE(Style);
REFLECT(font);
REFLECT(alignment);
REFLECT(padding_left);
REFLECT(padding_right);
REFLECT(padding_top);
REFLECT(padding_bottom);
REFLECT(background_color);
}
// ----------------------------------------------------------------------------- : InfoValue
String InfoValue::toString() const {
return value;
return value;
}
bool InfoValue::update(Context& ctx) {
if (value.empty()) value = field().name;
bool change = field().script.invokeOn(ctx, value);
Value::update(ctx);
return change;
if (value.empty()) value = field().name;
bool change = field().script.invokeOn(ctx, value);
Value::update(ctx);
return change;
}
IMPLEMENT_REFLECTION_NAMELESS(InfoValue) {
// never save
// never save
}
+23 -23
View File
@@ -26,12 +26,12 @@ DECLARE_POINTER_TYPE(InfoValue);
*/
class InfoField : public Field {
public:
InfoField() { editable = false; }
DECLARE_FIELD_TYPE(Text);
OptionalScript script; ///< Script to apply to all values
virtual void initDependencies(Context&, const Dependency&) const;
InfoField() { editable = false; }
DECLARE_FIELD_TYPE(Text);
OptionalScript script; ///< Script to apply to all values
virtual void initDependencies(Context&, const Dependency&) const;
};
// ----------------------------------------------------------------------------- : InfoStyle
@@ -39,17 +39,17 @@ class InfoField : public Field {
/// The Style for a InfoField
class InfoStyle : public Style {
public:
InfoStyle(const InfoFieldP&);
DECLARE_STYLE_TYPE(Info);
Font font; ///< Font to use for the text
Alignment alignment; ///< Alignment inside the box
double padding_left, padding_right; ///< Padding
double padding_top, padding_bottom;
Color background_color;
virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
InfoStyle(const InfoFieldP&);
DECLARE_STYLE_TYPE(Info);
Font font; ///< Font to use for the text
Alignment alignment; ///< Alignment inside the box
double padding_left, padding_right; ///< Padding
double padding_top, padding_bottom;
Color background_color;
virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
};
// ----------------------------------------------------------------------------- : InfoValue
@@ -57,12 +57,12 @@ class InfoStyle : public Style {
/// The Value in a InfoField
class InfoValue : public Value {
public:
inline InfoValue(const InfoFieldP& field) : Value(field) {}
DECLARE_VALUE_TYPE(Info, String);
ValueType value;
virtual bool update(Context&);
inline InfoValue(const InfoFieldP& field) : Value(field) {}
DECLARE_VALUE_TYPE(Info, String);
ValueType value;
virtual bool update(Context&);
};
// ----------------------------------------------------------------------------- : EOF
+69 -69
View File
@@ -12,103 +12,103 @@
// ----------------------------------------------------------------------------- : MultipleChoiceField
MultipleChoiceField::MultipleChoiceField()
: minimum_selection(0)
, maximum_selection(1000000)
: minimum_selection(0)
, maximum_selection(1000000)
{}
IMPLEMENT_FIELD_TYPE(MultipleChoice, "multiple choice");
IMPLEMENT_REFLECTION(MultipleChoiceField) {
REFLECT_BASE(ChoiceField);
REFLECT(minimum_selection);
REFLECT(maximum_selection);
REFLECT(empty_choice);
REFLECT_BASE(ChoiceField);
REFLECT(minimum_selection);
REFLECT(maximum_selection);
REFLECT(empty_choice);
}
// ----------------------------------------------------------------------------- : MultipleChoiceStyle
MultipleChoiceStyle::MultipleChoiceStyle(const MultipleChoiceFieldP& field)
: ChoiceStyle(field)
, direction(LEFT_TO_RIGHT)
, spacing(0)
: ChoiceStyle(field)
, direction(LEFT_TO_RIGHT)
, spacing(0)
{}
IMPLEMENT_REFLECTION(MultipleChoiceStyle) {
REFLECT_BASE(ChoiceStyle);
REFLECT(direction);
REFLECT(spacing);
REFLECT_BASE(ChoiceStyle);
REFLECT(direction);
REFLECT(spacing);
}
int MultipleChoiceStyle::update(Context& ctx) {
return ChoiceStyle::update(ctx)
| direction.update(ctx) * CHANGE_OTHER
| spacing.update(ctx) * CHANGE_OTHER;
return ChoiceStyle::update(ctx)
| direction.update(ctx) * CHANGE_OTHER
| spacing.update(ctx) * CHANGE_OTHER;
}
// ----------------------------------------------------------------------------- : MultipleChoiceValue
IMPLEMENT_REFLECTION_NAMELESS(MultipleChoiceValue) {
REFLECT_BASE(ChoiceValue);
REFLECT_BASE(ChoiceValue);
}
bool MultipleChoiceValue::update(Context& ctx) {
String old_value = value();
ctx.setVariable(_("last change"), to_script(last_change));
ChoiceValue::update(ctx);
normalForm();
return value() != old_value;
String old_value = value();
ctx.setVariable(_("last change"), to_script(last_change));
ChoiceValue::update(ctx);
normalForm();
return value() != old_value;
}
void MultipleChoiceValue::get(vector<String>& out) const {
// split the value
out.clear();
bool is_new = true;
FOR_EACH_CONST(c, value()) {
if (c == _(',')) {
is_new = true;
} else if (is_new) {
if (c != _(' ')) { // ignore whitespace after ,
is_new = false;
out.push_back(String(1, c));
}
} else {
assert(!out.empty());
out.back() += c;
}
}
// split the value
out.clear();
bool is_new = true;
FOR_EACH_CONST(c, value()) {
if (c == _(',')) {
is_new = true;
} else if (is_new) {
if (c != _(' ')) { // ignore whitespace after ,
is_new = false;
out.push_back(String(1, c));
}
} else {
assert(!out.empty());
out.back() += c;
}
}
}
void MultipleChoiceValue::normalForm() {
String& val = value.mutateDontChangeDefault();
// which choices are active?
vector<bool> seen(field().choices->lastId());
for (size_t pos = 0 ; pos < val.size() ; ) {
if (val.GetChar(pos) == _(' ')) {
++pos; // ingore whitespace
} else {
// does this choice match the one asked about?
size_t end = val.find_first_of(_(','), pos);
if (end == String::npos) end = val.size();
// find this choice
for (size_t i = 0 ; i < seen.size() ; ++i) {
if (is_substr(val, pos, field().choices->choiceName((int)i))) {
seen[i] = true;
break;
}
}
pos = end + 1;
}
}
// now put them back in the right order
val.clear();
for (size_t i = 0 ; i < seen.size() ; ++i) {
if (seen[i]) {
if (!val.empty()) val += _(", ");
val += field().choices->choiceName((int)i);
}
}
// empty choice name
if (val.empty()) {
val = field().empty_choice;
}
String& val = value.mutateDontChangeDefault();
// which choices are active?
vector<bool> seen(field().choices->lastId());
for (size_t pos = 0 ; pos < val.size() ; ) {
if (val.GetChar(pos) == _(' ')) {
++pos; // ingore whitespace
} else {
// does this choice match the one asked about?
size_t end = val.find_first_of(_(','), pos);
if (end == String::npos) end = val.size();
// find this choice
for (size_t i = 0 ; i < seen.size() ; ++i) {
if (is_substr(val, pos, field().choices->choiceName((int)i))) {
seen[i] = true;
break;
}
}
pos = end + 1;
}
}
// now put them back in the right order
val.clear();
for (size_t i = 0 ; i < seen.size() ; ++i) {
if (seen[i]) {
if (!val.empty()) val += _(", ");
val += field().choices->choiceName((int)i);
}
}
// empty choice name
if (val.empty()) {
val = field().empty_choice;
}
}
+33 -33
View File
@@ -21,11 +21,11 @@ DECLARE_POINTER_TYPE(MultipleChoiceValue);
/// A ChoiceField where multiple choices can be selected simultaniously
class MultipleChoiceField : public ChoiceField {
public:
MultipleChoiceField();
DECLARE_FIELD_TYPE(MultipleChoiceField);
UInt minimum_selection, maximum_selection; ///< How many choices can be selected simultaniously?
String empty_choice; ///< Name to use when nothing is selected
MultipleChoiceField();
DECLARE_FIELD_TYPE(MultipleChoiceField);
UInt minimum_selection, maximum_selection; ///< How many choices can be selected simultaniously?
String empty_choice; ///< Name to use when nothing is selected
};
// ----------------------------------------------------------------------------- : MultipleChoiceStyle
@@ -33,13 +33,13 @@ class MultipleChoiceField : public ChoiceField {
/// The Style for a MultipleChoiceField
class MultipleChoiceStyle : public ChoiceStyle {
public:
MultipleChoiceStyle(const MultipleChoiceFieldP& field);
DECLARE_STYLE_TYPE(MultipleChoice);
Scriptable<Direction> direction; ///< In what direction are choices layed out?
Scriptable<double> spacing; ///< Spacing between choices (images) in pixels
virtual int update(Context&);
MultipleChoiceStyle(const MultipleChoiceFieldP& field);
DECLARE_STYLE_TYPE(MultipleChoice);
Scriptable<Direction> direction; ///< In what direction are choices layed out?
Scriptable<double> spacing; ///< Spacing between choices (images) in pixels
virtual int update(Context&);
};
// ----------------------------------------------------------------------------- : MultipleChoiceValue
@@ -50,28 +50,28 @@ class MultipleChoiceStyle : public ChoiceStyle {
*/
class MultipleChoiceValue : public ChoiceValue {
public:
inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field, false) {}
DECLARE_HAS_FIELD(MultipleChoice);
virtual ValueP clone() const;
String last_change; ///< Which of the choices was selected/deselected last?
// for SimpleValueAction
struct ValueType {
ChoiceValue::ValueType value;
String last_change;
};
/// Splits the value, stores the selected choices in the out parameter
void get(vector<String>& out) const;
virtual bool update(Context&);
inline MultipleChoiceValue(const MultipleChoiceFieldP& field) : ChoiceValue(field, false) {}
DECLARE_HAS_FIELD(MultipleChoice);
virtual ValueP clone() const;
String last_change; ///< Which of the choices was selected/deselected last?
// for SimpleValueAction
struct ValueType {
ChoiceValue::ValueType value;
String last_change;
};
/// Splits the value, stores the selected choices in the out parameter
void get(vector<String>& out) const;
virtual bool update(Context&);
private:
DECLARE_REFLECTION();
/// Put the value in normal form (all choices ordered, empty_name
void normalForm();
DECLARE_REFLECTION();
/// Put the value in normal form (all choices ordered, empty_name
void normalForm();
};
// ----------------------------------------------------------------------------- : Utilities
+34 -34
View File
@@ -15,73 +15,73 @@
IMPLEMENT_FIELD_TYPE(PackageChoice, "package choice");
void PackageChoiceField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
script. initDependencies(ctx, dep);
Field ::initDependencies(ctx, dep);
script. initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(PackageChoiceField) {
REFLECT_BASE(Field);
REFLECT(script);
REFLECT(match);
REFLECT(initial);
REFLECT(required);
REFLECT(empty_name);
REFLECT_BASE(Field);
REFLECT(script);
REFLECT(match);
REFLECT(initial);
REFLECT(required);
REFLECT(empty_name);
}
// ----------------------------------------------------------------------------- : PackageChoiceStyle
PackageChoiceStyle::PackageChoiceStyle(const PackageChoiceFieldP& field)
: Style(field)
: Style(field)
{}
int PackageChoiceStyle::update(Context& ctx) {
return Style ::update(ctx)
| font .update(ctx) * CHANGE_OTHER;
return Style ::update(ctx)
| font .update(ctx) * CHANGE_OTHER;
}
/*void PackageChoiceStyle::initDependencies(Context& ctx, const Dependency& dep) const {
Style ::initDependencies(ctx, dep);
// font .initDependencies(ctx, dep);
Style ::initDependencies(ctx, dep);
// font .initDependencies(ctx, dep);
}*/
IMPLEMENT_REFLECTION(PackageChoiceStyle) {
REFLECT_BASE(Style);
REFLECT(font);
REFLECT_BASE(Style);
REFLECT(font);
}
// ----------------------------------------------------------------------------- : PackageChoiceValue
String PackageChoiceValue::toString() const {
PackagedP pack = getPackage();
if (pack.get()) return pack->short_name;
else return _("");
PackagedP pack = getPackage();
if (pack.get()) return pack->short_name;
else return _("");
}
PackagedP PackageChoiceValue::getPackage() const {
if (package_name.empty()) return nullptr;
else return package_manager.openAny(package_name, true);
if (package_name.empty()) return nullptr;
else return package_manager.openAny(package_name, true);
}
bool PackageChoiceValue::update(Context& ctx) {
bool change = field().script.invokeOn(ctx, package_name);
Value::update(ctx);
return change;
bool change = field().script.invokeOn(ctx, package_name);
Value::update(ctx);
return change;
}
void PackageChoiceValue::reflect(Reader& tag) {
REFLECT_NAMELESS(package_name);
REFLECT_NAMELESS(package_name);
}
void PackageChoiceValue::reflect(Writer& tag) {
REFLECT_NAMELESS(package_name);
REFLECT_NAMELESS(package_name);
}
void PackageChoiceValue::reflect(GetDefaultMember& tag) {
if (package_name.empty()) {
REFLECT_NAMELESS(package_name);
} else if(package_name != field().initial) {
// add a space to the name, to indicate the dependency doesn't have to be marked
// see also PackageManager::openFileFromPackage and SymbolFontRef::loadFont
REFLECT_NAMELESS(_("/:NO-WARN-DEP:") + package_name);
} else {
REFLECT_NAMELESS(_("/") + package_name);
}
if (package_name.empty()) {
REFLECT_NAMELESS(package_name);
} else if(package_name != field().initial) {
// add a space to the name, to indicate the dependency doesn't have to be marked
// see also PackageManager::openFileFromPackage and SymbolFontRef::loadFont
REFLECT_NAMELESS(_("/:NO-WARN-DEP:") + package_name);
} else {
REFLECT_NAMELESS(_("/") + package_name);
}
}
void PackageChoiceValue::reflect(GetMember& tag) {}
+25 -25
View File
@@ -25,16 +25,16 @@ DECLARE_POINTER_TYPE(PackageChoiceValue);
/// A field for PackageChoice values, it contains a list of choices for PackageChoices
class PackageChoiceField : public Field {
public:
PackageChoiceField() : required(true), empty_name(_("none")) {}
DECLARE_FIELD_TYPE(PackageChoice);
OptionalScript script; ///< Script to apply to all values
String match; ///< Package filenames to match
String initial; ///< Initial value
bool required; ///< Is selecting a package required?
String empty_name; ///< Displayed name for the empty value (if !required)
virtual void initDependencies(Context&, const Dependency&) const;
PackageChoiceField() : required(true), empty_name(_("none")) {}
DECLARE_FIELD_TYPE(PackageChoice);
OptionalScript script; ///< Script to apply to all values
String match; ///< Package filenames to match
String initial; ///< Initial value
bool required; ///< Is selecting a package required?
String empty_name; ///< Displayed name for the empty value (if !required)
virtual void initDependencies(Context&, const Dependency&) const;
};
// ----------------------------------------------------------------------------- : PackageChoiceStyle
@@ -42,12 +42,12 @@ class PackageChoiceField : public Field {
/// The Style for a PackageChoiceField
class PackageChoiceStyle : public Style {
public:
PackageChoiceStyle(const PackageChoiceFieldP& field);
DECLARE_STYLE_TYPE(PackageChoice);
Font font; ///< Font to use for the text
virtual int update(Context&);
PackageChoiceStyle(const PackageChoiceFieldP& field);
DECLARE_STYLE_TYPE(PackageChoice);
Font font; ///< Font to use for the text
virtual int update(Context&);
};
// ----------------------------------------------------------------------------- : PackageChoiceValue
@@ -55,15 +55,15 @@ class PackageChoiceStyle : public Style {
/// The Value in a PackageChoiceField
class PackageChoiceValue : public Value {
public:
PackageChoiceValue(const PackageChoiceFieldP& field) : Value(field), package_name(field->initial) {}
DECLARE_VALUE_TYPE(PackageChoice, String);
ValueType package_name; ///< The selected package
/// Get the package (if it is set)
PackagedP getPackage() const;
virtual bool update(Context&);
PackageChoiceValue(const PackageChoiceFieldP& field) : Value(field), package_name(field->initial) {}
DECLARE_VALUE_TYPE(PackageChoice, String);
ValueType package_name; ///< The selected package
/// Get the package (if it is set)
PackagedP getPackage() const;
virtual bool update(Context&);
};
// ----------------------------------------------------------------------------- : EOF
+14 -14
View File
@@ -15,42 +15,42 @@
IMPLEMENT_FIELD_TYPE(Symbol, "symbol");
IMPLEMENT_REFLECTION(SymbolField) {
REFLECT_BASE(Field);
REFLECT_BASE(Field);
}
// ----------------------------------------------------------------------------- : SymbolStyle
IMPLEMENT_REFLECTION(SymbolStyle) {
REFLECT_BASE(Style);
REFLECT(min_aspect_ratio);
REFLECT(max_aspect_ratio);
REFLECT(variations);
REFLECT_BASE(Style);
REFLECT(min_aspect_ratio);
REFLECT(max_aspect_ratio);
REFLECT(variations);
}
SymbolVariation::SymbolVariation()
: border_radius(0.05)
: border_radius(0.05)
{}
SymbolVariation::~SymbolVariation() {}
bool SymbolVariation::operator == (const SymbolVariation& that) const {
return name == that.name
&& border_radius == that.border_radius
&& *filter == *that.filter;
return name == that.name
&& border_radius == that.border_radius
&& *filter == *that.filter;
}
IMPLEMENT_REFLECTION_NO_SCRIPT(SymbolVariation) {
REFLECT(name);
REFLECT(border_radius);
REFLECT_NAMELESS(filter);
REFLECT(name);
REFLECT(border_radius);
REFLECT_NAMELESS(filter);
}
// ----------------------------------------------------------------------------- : SymbolValue
String SymbolValue::toString() const {
return filename.empty() ? wxEmptyString : _("<symbol>");
return filename.empty() ? wxEmptyString : _("<symbol>");
}
IMPLEMENT_REFLECTION_NAMELESS(SymbolValue) {
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(filename);
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(filename);
}
+26 -26
View File
@@ -25,9 +25,9 @@ DECLARE_POINTER_TYPE(SymbolValue);
/// A field for image values
class SymbolField : public Field {
public:
DECLARE_FIELD_TYPE(Symbol);
// no extra data
DECLARE_FIELD_TYPE(Symbol);
// no extra data
};
// ----------------------------------------------------------------------------- : SymbolStyle
@@ -35,29 +35,29 @@ class SymbolField : public Field {
/// The Style for a SymbolField
class SymbolStyle : public Style {
public:
inline SymbolStyle(const SymbolFieldP& field)
: Style(field)
, min_aspect_ratio(1), max_aspect_ratio(1)
{}
DECLARE_STYLE_TYPE(Symbol);
double min_aspect_ratio;
double max_aspect_ratio; ///< Bounds for the symbol's aspect ratio
vector<SymbolVariationP> variations; ///< Different variantions of the same symbol
inline SymbolStyle(const SymbolFieldP& field)
: Style(field)
, min_aspect_ratio(1), max_aspect_ratio(1)
{}
DECLARE_STYLE_TYPE(Symbol);
double min_aspect_ratio;
double max_aspect_ratio; ///< Bounds for the symbol's aspect ratio
vector<SymbolVariationP> variations; ///< Different variantions of the same symbol
};
/// Styling for a symbol variation, defines color, border, etc.
class SymbolVariation : public IntrusivePtrBase<SymbolVariation> {
public:
SymbolVariation();
~SymbolVariation();
String name; ///< Name of this variation
SymbolFilterP filter; ///< Filter to color the symbol
double border_radius; ///< Border radius for the symbol
bool operator == (const SymbolVariation&) const;
DECLARE_REFLECTION();
SymbolVariation();
~SymbolVariation();
String name; ///< Name of this variation
SymbolFilterP filter; ///< Filter to color the symbol
double border_radius; ///< Border radius for the symbol
bool operator == (const SymbolVariation&) const;
DECLARE_REFLECTION();
};
// ----------------------------------------------------------------------------- : SymbolValue
@@ -65,11 +65,11 @@ class SymbolVariation : public IntrusivePtrBase<SymbolVariation> {
/// The Value in a SymbolField, i.e. a symbol
class SymbolValue : public Value {
public:
inline SymbolValue(const SymbolFieldP& field) : Value(field) {}
DECLARE_VALUE_TYPE(Symbol, FileName);
ValueType filename; ///< Filename of the symbol (in the current package)
Age last_update; ///< When was the symbol last changed?
inline SymbolValue(const SymbolFieldP& field) : Value(field) {}
DECLARE_VALUE_TYPE(Symbol, FileName);
ValueType filename; ///< Filename of the symbol (in the current package)
Age last_update; ///< When was the symbol last changed?
};
// ----------------------------------------------------------------------------- : EOF
+115 -115
View File
@@ -14,176 +14,176 @@
// ----------------------------------------------------------------------------- : TextField
TextField::TextField()
: multi_line(false)
, default_name(_("Default"))
: multi_line(false)
, default_name(_("Default"))
{}
IMPLEMENT_FIELD_TYPE(Text, "text");
void TextField::initDependencies(Context& ctx, const Dependency& dep) const {
Field ::initDependencies(ctx, dep);
script .initDependencies(ctx, dep);
default_script.initDependencies(ctx, dep);
Field ::initDependencies(ctx, dep);
script .initDependencies(ctx, dep);
default_script.initDependencies(ctx, dep);
}
IMPLEMENT_REFLECTION(TextField) {
REFLECT_BASE(Field);
REFLECT(multi_line);
REFLECT(script);
REFLECT_N("default", default_script);
REFLECT(default_name);
REFLECT_BASE(Field);
REFLECT(multi_line);
REFLECT(script);
REFLECT_N("default", default_script);
REFLECT(default_name);
}
// ----------------------------------------------------------------------------- : TextStyle
TextStyle::TextStyle(const TextFieldP& field)
: Style(field)
, always_symbol(false), allow_formating(true)
, alignment(ALIGN_TOP_LEFT)
, padding_left (0), padding_left_min (10000)
, padding_right (0), padding_right_min (10000)
, padding_top (0), padding_top_min (10000)
, padding_bottom(0), padding_bottom_min(10000)
, line_height_soft(1.0)
, line_height_hard(1.0)
, line_height_line(1.0)
, line_height_soft_max(0.0)
, line_height_hard_max(0.0)
, line_height_line_max(0.0)
, paragraph_height(-1)
, direction(LEFT_TO_RIGHT)
, content_width(0), content_height(0), content_lines(0)
: Style(field)
, always_symbol(false), allow_formating(true)
, alignment(ALIGN_TOP_LEFT)
, padding_left (0), padding_left_min (10000)
, padding_right (0), padding_right_min (10000)
, padding_top (0), padding_top_min (10000)
, padding_bottom(0), padding_bottom_min(10000)
, line_height_soft(1.0)
, line_height_hard(1.0)
, line_height_line(1.0)
, line_height_soft_max(0.0)
, line_height_hard_max(0.0)
, line_height_line_max(0.0)
, paragraph_height(-1)
, direction(LEFT_TO_RIGHT)
, content_width(0), content_height(0), content_lines(0)
{}
double TextStyle::getStretch() const {
if (content_width > 0 && (alignment() & ALIGN_STRETCH)) {
double factor = (width - padding_left - padding_right) / content_width;
if (!(alignment() & ALIGN_IF_OVERFLOW) || factor < 1.0) {
return factor;
}
}
return 1.0;
if (content_width > 0 && (alignment() & ALIGN_STRETCH)) {
double factor = (width - padding_left - padding_right) / content_width;
if (!(alignment() & ALIGN_IF_OVERFLOW) || factor < 1.0) {
return factor;
}
}
return 1.0;
}
int TextStyle::update(Context& ctx) {
return Style ::update(ctx)
| font .update(ctx) * CHANGE_OTHER
| symbol_font.update(ctx) * CHANGE_OTHER
| alignment .update(ctx) * CHANGE_OTHER
| ( padding_left .update(ctx)
| padding_left_min .update(ctx)
| padding_right .update(ctx)
| padding_right_min .update(ctx)
| padding_top .update(ctx)
| padding_top_min .update(ctx)
| padding_bottom .update(ctx)
| padding_bottom_min .update(ctx)
| line_height_soft .update(ctx)
| line_height_hard .update(ctx)
| line_height_line .update(ctx)
| line_height_soft_max.update(ctx)
| line_height_hard_max.update(ctx)
| line_height_line_max.update(ctx)
) * CHANGE_OTHER;
return Style ::update(ctx)
| font .update(ctx) * CHANGE_OTHER
| symbol_font.update(ctx) * CHANGE_OTHER
| alignment .update(ctx) * CHANGE_OTHER
| ( padding_left .update(ctx)
| padding_left_min .update(ctx)
| padding_right .update(ctx)
| padding_right_min .update(ctx)
| padding_top .update(ctx)
| padding_top_min .update(ctx)
| padding_bottom .update(ctx)
| padding_bottom_min .update(ctx)
| line_height_soft .update(ctx)
| line_height_hard .update(ctx)
| line_height_line .update(ctx)
| line_height_soft_max.update(ctx)
| line_height_hard_max.update(ctx)
| line_height_line_max.update(ctx)
) * CHANGE_OTHER;
}
void TextStyle::initDependencies(Context& ctx, const Dependency& dep) const {
Style ::initDependencies(ctx, dep);
// font .initDependencies(ctx, dep);
// symbol_font.initDependencies(ctx, dep);
Style ::initDependencies(ctx, dep);
// font .initDependencies(ctx, dep);
// symbol_font.initDependencies(ctx, dep);
}
void TextStyle::checkContentDependencies(Context& ctx, const Dependency& dep) const {
Style ::checkContentDependencies(ctx, dep);
alignment.initDependencies(ctx, dep);
Style ::checkContentDependencies(ctx, dep);
alignment.initDependencies(ctx, dep);
}
template <typename T> void reflect_content(T& tag, const TextStyle& ts) {}
template <> void reflect_content(GetMember& tag, const TextStyle& ts) {
REFLECT_N("content_width", ts.content_width);
REFLECT_N("content_height", ts.content_height);
REFLECT_N("content_lines", ts.content_lines);
REFLECT_N("content_width", ts.content_width);
REFLECT_N("content_height", ts.content_height);
REFLECT_N("content_lines", ts.content_lines);
}
IMPLEMENT_REFLECTION(TextStyle) {
REFLECT_BASE(Style);
REFLECT(font);
REFLECT(symbol_font);
REFLECT(always_symbol);
REFLECT(allow_formating);
REFLECT(alignment);
REFLECT(padding_left);
REFLECT(padding_right);
REFLECT(padding_top);
REFLECT(padding_bottom);
REFLECT(padding_left_min);
REFLECT(padding_right_min);
REFLECT(padding_top_min);
REFLECT(padding_bottom_min);
REFLECT(line_height_soft);
REFLECT(line_height_hard);
REFLECT(line_height_line);
REFLECT(line_height_soft_max);
REFLECT(line_height_hard_max);
REFLECT(line_height_line_max);
REFLECT(paragraph_height);
REFLECT(direction);
reflect_content(tag, *this);
REFLECT_BASE(Style);
REFLECT(font);
REFLECT(symbol_font);
REFLECT(always_symbol);
REFLECT(allow_formating);
REFLECT(alignment);
REFLECT(padding_left);
REFLECT(padding_right);
REFLECT(padding_top);
REFLECT(padding_bottom);
REFLECT(padding_left_min);
REFLECT(padding_right_min);
REFLECT(padding_top_min);
REFLECT(padding_bottom_min);
REFLECT(line_height_soft);
REFLECT(line_height_hard);
REFLECT(line_height_line);
REFLECT(line_height_soft_max);
REFLECT(line_height_hard_max);
REFLECT(line_height_line_max);
REFLECT(paragraph_height);
REFLECT(direction);
reflect_content(tag, *this);
}
// ----------------------------------------------------------------------------- : TextValue
String TextValue::toString() const {
return untag_hide_sep(value());
return untag_hide_sep(value());
}
bool TextValue::update(Context& ctx) {
updateAge();
WITH_DYNAMIC_ARG(last_update_age, last_update.get());
WITH_DYNAMIC_ARG(value_being_updated, this);
bool change = field().default_script.invokeOnDefault(ctx, value)
| field(). script.invokeOn(ctx, value);
if (change) last_update.update();
updateSortValue(ctx);
return change;
updateAge();
WITH_DYNAMIC_ARG(last_update_age, last_update.get());
WITH_DYNAMIC_ARG(value_being_updated, this);
bool change = field().default_script.invokeOnDefault(ctx, value)
| field(). script.invokeOn(ctx, value);
if (change) last_update.update();
updateSortValue(ctx);
return change;
}
IMPLEMENT_REFLECTION_NAMELESS(TextValue) {
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(value);
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(value);
}
// ----------------------------------------------------------------------------- : FakeTextValue
FakeTextValue::FakeTextValue(const TextFieldP& field, String* underlying, bool editable, bool untagged)
: TextValue(field), underlying(underlying)
, editable(editable), untagged(untagged)
: TextValue(field), underlying(underlying)
, editable(editable), untagged(untagged)
{}
void FakeTextValue::store() {
if (underlying) {
if (editable) {
*underlying = untagged ? untag(value) : value();
} else {
retrieve();
}
}
if (underlying) {
if (editable) {
*underlying = untagged ? untag(value) : value();
} else {
retrieve();
}
}
}
void FakeTextValue::retrieve() {
if (underlying) {
value.assign(untagged ? escape(*underlying) : *underlying);
} else {
value.assign(wxEmptyString);
}
if (underlying) {
value.assign(untagged ? escape(*underlying) : *underlying);
} else {
value.assign(wxEmptyString);
}
}
void FakeTextValue::onAction(Action& a, bool undone) {
store();
store();
}
bool FakeTextValue::equals(const Value* that) {
if (this == that) return true;
if (!underlying) return false;
const FakeTextValue* thatT = dynamic_cast<const FakeTextValue*>(that);
if (!thatT || underlying != thatT->underlying) return false;
// update the value
retrieve();
return true;
if (this == that) return true;
if (!underlying) return false;
const FakeTextValue* thatT = dynamic_cast<const FakeTextValue*>(that);
if (!thatT || underlying != thatT->underlying) return false;
// update the value
retrieve();
return true;
}
+68 -68
View File
@@ -30,17 +30,17 @@ DECLARE_POINTER_TYPE(TextBackground);
/// A field for values containing tagged text
class TextField : public Field {
public:
TextField();
DECLARE_FIELD_TYPE(Text);
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
//%OptionalScript view_script; ///< Script to apply before viewing
//%OptionalScript unview_script; ///< Script to apply after changes to the view
bool multi_line; ///< Are newlines allowed in the text?
String default_name; ///< Name of "default" value
virtual void initDependencies(Context&, const Dependency&) const;
TextField();
DECLARE_FIELD_TYPE(Text);
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
//%OptionalScript view_script; ///< Script to apply before viewing
//%OptionalScript unview_script; ///< Script to apply after changes to the view
bool multi_line; ///< Are newlines allowed in the text?
String default_name; ///< Name of "default" value
virtual void initDependencies(Context&, const Dependency&) const;
};
// ----------------------------------------------------------------------------- : TextStyle
@@ -48,37 +48,37 @@ class TextField : public Field {
/// The Style for a TextField
class TextStyle : public Style {
public:
TextStyle(const TextFieldP&);
DECLARE_STYLE_TYPE(Text);
Font font; ///< Font to use for the text
SymbolFontRef symbol_font; ///< Symbol font for symbols in the text
bool always_symbol; ///< Should everything be drawn as symbols?
bool allow_formating; ///< Is formating (bold/italic/..) allowed?
Scriptable<Alignment> alignment; ///< Alignment inside the box
Scriptable<double>
padding_left, padding_left_min, ///< Padding
padding_right, padding_right_min, ///< Padding
padding_top, padding_top_min, ///< Padding
padding_bottom, padding_bottom_min, ///< Padding
line_height_soft, ///< Line height for soft linebreaks
line_height_hard, ///< Line height for hard linebreaks
line_height_line, ///< Line height for <line> tags
line_height_soft_max, ///< Maximum line height
line_height_hard_max, ///< Maximum line height
line_height_line_max, ///< Maximum line height
paragraph_height; ///< Fixed height of paragraphs
Direction direction; ///< In what direction is text layed out?
// information from text rendering
double content_width, content_height; ///< Size of the rendered text
int content_lines; ///< Number of rendered lines
virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
virtual void checkContentDependencies(Context&, const Dependency&) const;
/// Stretch factor to use
double getStretch() const;
TextStyle(const TextFieldP&);
DECLARE_STYLE_TYPE(Text);
Font font; ///< Font to use for the text
SymbolFontRef symbol_font; ///< Symbol font for symbols in the text
bool always_symbol; ///< Should everything be drawn as symbols?
bool allow_formating; ///< Is formating (bold/italic/..) allowed?
Scriptable<Alignment> alignment; ///< Alignment inside the box
Scriptable<double>
padding_left, padding_left_min, ///< Padding
padding_right, padding_right_min, ///< Padding
padding_top, padding_top_min, ///< Padding
padding_bottom, padding_bottom_min, ///< Padding
line_height_soft, ///< Line height for soft linebreaks
line_height_hard, ///< Line height for hard linebreaks
line_height_line, ///< Line height for <line> tags
line_height_soft_max, ///< Maximum line height
line_height_hard_max, ///< Maximum line height
line_height_line_max, ///< Maximum line height
paragraph_height; ///< Fixed height of paragraphs
Direction direction; ///< In what direction is text layed out?
// information from text rendering
double content_width, content_height; ///< Size of the rendered text
int content_lines; ///< Number of rendered lines
virtual int update(Context&);
virtual void initDependencies(Context&, const Dependency&) const;
virtual void checkContentDependencies(Context&, const Dependency&) const;
/// Stretch factor to use
double getStretch() const;
};
// ----------------------------------------------------------------------------- : TextValue
@@ -86,13 +86,13 @@ class TextStyle : public Style {
/// The Value in a TextField
class TextValue : public Value {
public:
inline TextValue(const TextFieldP& field) : Value(field), last_update(1) {}
DECLARE_VALUE_TYPE(Text, Defaultable<String>);
ValueType value; ///< The text of this value
Age last_update; ///< When was the text last changed?
virtual bool update(Context&);
inline TextValue(const TextFieldP& field) : Value(field), last_update(1) {}
DECLARE_VALUE_TYPE(Text, Defaultable<String>);
ValueType value; ///< The text of this value
Age last_update; ///< When was the text last changed?
virtual bool update(Context&);
};
// ----------------------------------------------------------------------------- : TextValue
@@ -101,25 +101,25 @@ class TextValue : public Value {
/** Used by TextCtrl */
class FakeTextValue : public TextValue {
public:
/// Initialize the fake text value
/** underlying can be nullptr, in that case there is no underlying value */
FakeTextValue(const TextFieldP& field, String* underlying, bool editable, bool untagged);
String* const underlying; ///< The underlying actual value, can be null
bool const editable; ///< The underlying value can be edited
bool const untagged; ///< The underlying value is untagged
/// Store the value in the underlying value.
/** May be overloaded to do some transformation */
virtual void store();
/// Retrieve the value from the underlying value.
/** May be overloaded to do some transformation */
virtual void retrieve();
/// Update underlying data
virtual void onAction(Action& a, bool undone);
/// Editing the same underlying value?
virtual bool equals(const Value* that);
/// Initialize the fake text value
/** underlying can be nullptr, in that case there is no underlying value */
FakeTextValue(const TextFieldP& field, String* underlying, bool editable, bool untagged);
String* const underlying; ///< The underlying actual value, can be null
bool const editable; ///< The underlying value can be edited
bool const untagged; ///< The underlying value is untagged
/// Store the value in the underlying value.
/** May be overloaded to do some transformation */
virtual void store();
/// Retrieve the value from the underlying value.
/** May be overloaded to do some transformation */
virtual void retrieve();
/// Update underlying data
virtual void onAction(Action& a, bool undone);
/// Editing the same underlying value?
virtual bool equals(const Value* that);
};
// ----------------------------------------------------------------------------- : EOF