[glom] Allow custom text formatting of Buttons as well as text items and fields.
- From: Murray Cumming <murrayc src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glom] Allow custom text formatting of Buttons as well as text items and fields.
- Date: Fri, 22 Jan 2010 15:49:14 +0000 (UTC)
commit 51a0a70fd23f821114e358d9d44acb8efda80809
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Jan 22 16:49:09 2010 +0100
Allow custom text formatting of Buttons as well as text items and fields.
* glom/libglom/data_structure/layout/layoutitem_button.[h|cc]:
Derive from LayoutItem_WithFormatting.
* glom/libglom/document/document.[h|cc]: Make loading/saving of
formatting generic so we get it for free whenever a new class
derives from LayoutItem_WithFormatting.
* glom/mode_data/flowtablewithfields.cc:
on_dnd_add_layout_item_button(): Try to apply the formatting to
the button's label, though it doesn't seem to work.
ChangeLog | 13 ++++
.../data_structure/layout/layoutitem_button.cc | 6 +-
.../data_structure/layout/layoutitem_button.h | 4 +-
glom/libglom/document/document.cc | 75 +++++++++++++++-----
glom/libglom/document/document.h | 2 +
glom/mode_data/flowtablewithfields.cc | 7 ++-
6 files changed, 82 insertions(+), 25 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fd0b4af..fda6fe5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2010-01-22 Murray Cumming <murrayc murrayc com>>
+ Allow custom text formatting of Buttons as well as text items and fields.
+
+ * glom/libglom/data_structure/layout/layoutitem_button.[h|cc]:
+ Derive from LayoutItem_WithFormatting.
+ * glom/libglom/document/document.[h|cc]: Make loading/saving of
+ formatting generic so we get it for free whenever a new class
+ derives from LayoutItem_WithFormatting.
+ * glom/mode_data/flowtablewithfields.cc:
+ on_dnd_add_layout_item_button(): Try to apply the formatting to
+ the button's label, though it doesn't seem to work.
+
+2010-01-22 Murray Cumming <murrayc murrayc com>>
+
Allow editing of formatting for static text items.
* glom/mode_design/layout/layout_item_dialogs/dialog_formatting.[h|cc]:
diff --git a/glom/libglom/data_structure/layout/layoutitem_button.cc b/glom/libglom/data_structure/layout/layoutitem_button.cc
index 4b31d9b..f2d7ce7 100644
--- a/glom/libglom/data_structure/layout/layoutitem_button.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_button.cc
@@ -30,7 +30,7 @@ LayoutItem_Button::LayoutItem_Button()
}
LayoutItem_Button::LayoutItem_Button(const LayoutItem_Button& src)
-: LayoutItem(src),
+: LayoutItem_WithFormatting(src),
m_script(src.m_script)
{
}
@@ -46,7 +46,7 @@ LayoutItem* LayoutItem_Button::clone() const
bool LayoutItem_Button::operator==(const LayoutItem_Button& src) const
{
- bool result = LayoutItem::operator==(src) &&
+ bool result = LayoutItem_WithFormatting::operator==(src) &&
(m_script == src.m_script);
return result;
@@ -55,7 +55,7 @@ bool LayoutItem_Button::operator==(const LayoutItem_Button& src) const
//Avoid using this, for performance:
LayoutItem_Button& LayoutItem_Button::operator=(const LayoutItem_Button& src)
{
- LayoutItem::operator=(src);
+ LayoutItem_WithFormatting::operator=(src);
m_script = src.m_script;
diff --git a/glom/libglom/data_structure/layout/layoutitem_button.h b/glom/libglom/data_structure/layout/layoutitem_button.h
index 81227b3..443af0c 100644
--- a/glom/libglom/data_structure/layout/layoutitem_button.h
+++ b/glom/libglom/data_structure/layout/layoutitem_button.h
@@ -21,13 +21,13 @@
#ifndef GLOM_DATASTRUCTURE_LAYOUTITEM_BUTTON_H
#define GLOM_DATASTRUCTURE_LAYOUTITEM_BUTTON_H
-#include "layoutitem.h"
+#include "layoutitem_withformatting.h"
namespace Glom
{
class LayoutItem_Button
- : public LayoutItem
+ : public LayoutItem_WithFormatting
{
public:
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index d349bf9..7377ae7 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -1881,6 +1881,26 @@ void Document::set_modified(bool value)
//}
}
+void Document::load_after_layout_item_formatting(const xmlpp::Element* element, const sharedptr<LayoutItem_WithFormatting>& layout_item, const Glib::ustring& table_name)
+{
+ if(!layout_item)
+ return;
+
+ FieldFormatting& format = layout_item->m_formatting;
+
+ sharedptr<LayoutItem_Field> field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
+
+ Field::glom_field_type field_type = Field::TYPE_INVALID;
+ if(field)
+ field_type = field->get_glom_type();
+
+ Glib::ustring field_name;
+ if(field)
+ field_name = field->get_name();
+
+ load_after_layout_item_formatting(element, format, field_type, table_name, field_name);
+}
+
void Document::load_after_layout_item_formatting(const xmlpp::Element* element, FieldFormatting& format, Field::glom_field_type field_type, const Glib::ustring& table_name, const Glib::ustring& field_name)
{
//Numeric formatting:
@@ -2009,13 +2029,6 @@ void Document::load_after_layout_item_field(const xmlpp::Element* element, const
item->set_editable( get_node_attribute_value_as_bool(element, GLOM_ATTRIBUTE_EDITABLE) );
- const xmlpp::Element* elementFormatting = get_node_child_named(element, GLOM_NODE_FORMAT);
- if(elementFormatting)
- {
- //TODO: Provide the name of the relationship's table if there is a relationship:
- load_after_layout_item_formatting(elementFormatting, item->m_formatting, item->get_glom_type(), table_name, name);
- }
-
item->set_formatting_use_default( get_node_attribute_value_as_bool(element, GLOM_ATTRIBUTE_DATA_LAYOUT_ITEM_FIELD_USE_DEFAULT_FORMATTING) );
@@ -2109,10 +2122,6 @@ void Document::load_after_layout_group(const xmlpp::Element* node, const Glib::u
sharedptr<LayoutItem_Text> item = sharedptr<LayoutItem_Text>::create();
load_after_translations(element, *item);
- const xmlpp::Element* elementFormatting = get_node_child_named(element, GLOM_NODE_FORMAT);
- if(elementFormatting)
- load_after_layout_item_formatting(elementFormatting, item->m_formatting);
-
//The text can be translated too, so it has its own node:
const xmlpp::Element* element_text = get_node_child_named(element, GLOM_NODE_DATA_LAYOUT_TEXTOBJECT_TEXT);
if(element_text)
@@ -2298,6 +2307,18 @@ void Document::load_after_layout_group(const xmlpp::Element* node, const Glib::u
}
}
+ //Load formatting for any layout type that uses it:
+ sharedptr<LayoutItem_WithFormatting> withformatting = sharedptr<LayoutItem_WithFormatting>::cast_dynamic(item_added);
+ if(withformatting)
+ {
+ const xmlpp::Element* elementFormatting = get_node_child_named(element, GLOM_NODE_FORMAT);
+ if(elementFormatting)
+ {
+ //TODO: Provide the name of the relationship's table if there is a relationship:
+ load_after_layout_item_formatting(elementFormatting, withformatting, table_name);
+ }
+ }
+
//Add the new layout item to the group:
if(item_added)
{
@@ -2882,10 +2903,26 @@ bool Document::load_after(int& failure_code)
return result;
}
+void Document::save_before_layout_item_formatting(xmlpp::Element* nodeItem, const sharedptr<const LayoutItem_WithFormatting>& layout_item)
+{
+ if(!layout_item)
+ return;
+
+ const FieldFormatting& format = layout_item->m_formatting;
+
+ sharedptr<const LayoutItem_Field> field = sharedptr<const LayoutItem_Field>::cast_dynamic(layout_item);
+
+ Field::glom_field_type field_type = Field::TYPE_INVALID;
+ if(field)
+ field_type = field->get_glom_type();
+
+ save_before_layout_item_formatting(nodeItem, format, field_type);
+}
+
void Document::save_before_layout_item_formatting(xmlpp::Element* nodeItem, const FieldFormatting& format, Field::glom_field_type field_type)
{
//Numeric format:
- if(field_type != Field::TYPE_INVALID) //These options are only for fields:
+ if(field_type != Field::TYPE_INVALID) //These options are only for fields:
{
set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_THOUSANDS_SEPARATOR, format.m_numeric_format.m_use_thousands_separator);
set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_DECIMAL_PLACES_RESTRICTED, format.m_numeric_format.m_decimal_places_restricted);
@@ -2963,9 +3000,6 @@ void Document::save_before_layout_item_field(xmlpp::Element* nodeItem, const sha
save_before_layout_item_usesrelationship(nodeItem, field);
set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_EDITABLE, field->get_editable());
- xmlpp::Element* elementFormat = nodeItem->add_child(GLOM_NODE_FORMAT);
- save_before_layout_item_formatting(elementFormat, field->m_formatting, field->get_glom_type());
-
set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_DATA_LAYOUT_ITEM_FIELD_USE_DEFAULT_FORMATTING, field->get_formatting_use_default());
sharedptr<const CustomTitle> custom_title = field->get_title_custom();
@@ -3191,9 +3225,6 @@ void Document::save_before_layout_group(xmlpp::Element* node, const sharedptr<co
nodeItem = child->add_child(GLOM_NODE_DATA_LAYOUT_TEXTOBJECT);
save_before_translations(nodeItem, *textobject);
- xmlpp::Element* elementFormat = nodeItem->add_child(GLOM_NODE_FORMAT);
- save_before_layout_item_formatting(elementFormat, textobject->m_formatting);
-
//The text is translatable too, so we use a node for it:
xmlpp::Element* element_text = nodeItem->add_child(GLOM_NODE_DATA_LAYOUT_TEXTOBJECT_TEXT);
save_before_translations(element_text, *(textobject->m_text));
@@ -3231,6 +3262,14 @@ void Document::save_before_layout_group(xmlpp::Element* node, const sharedptr<co
}
}
}
+
+ //Save formatting for any layout items that use it:
+ sharedptr<const LayoutItem_WithFormatting> withformatting = sharedptr<const LayoutItem_WithFormatting>::cast_dynamic(item);
+ if(withformatting)
+ {
+ xmlpp::Element* elementFormat = nodeItem->add_child(GLOM_NODE_FORMAT);
+ save_before_layout_item_formatting(elementFormat, withformatting);
+ }
}
if(nodeItem)
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index 5e5769d..0cfd574 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -453,6 +453,7 @@ private:
void save_before_layout_item_usesrelationship(xmlpp::Element* nodeItem, const sharedptr<const UsesRelationship>& item);
void save_before_layout_item_field(xmlpp::Element* nodeItem, const sharedptr<const LayoutItem_Field>& item);
void save_before_layout_item_formatting(xmlpp::Element* nodeItem, const FieldFormatting& format, Field::glom_field_type field_type = Field::TYPE_INVALID);
+ void save_before_layout_item_formatting(xmlpp::Element* nodeItem, const sharedptr<const LayoutItem_WithFormatting>& layout_item);
void save_before_translations(xmlpp::Element* nodeItem, const TranslatableItem& item);
void save_before_print_layout_position(xmlpp::Element* nodeItem, const sharedptr<const LayoutItem>& item);
@@ -465,6 +466,7 @@ private:
void load_after_layout_item_usesrelationship(const xmlpp::Element* element, const Glib::ustring& table_name, const sharedptr<UsesRelationship>& item);
void load_after_layout_item_field(const xmlpp::Element* element, const Glib::ustring& table_name, const sharedptr<LayoutItem_Field>& item);
void load_after_layout_item_formatting(const xmlpp::Element* element, FieldFormatting& format, Field::glom_field_type field_type = Field::TYPE_INVALID, const Glib::ustring& table_name = Glib::ustring(), const Glib::ustring& field_name = Glib::ustring());
+ void load_after_layout_item_formatting(const xmlpp::Element* element, const sharedptr<LayoutItem_WithFormatting>& layout_item, const Glib::ustring& table_name = Glib::ustring());
void load_after_translations(const xmlpp::Element* element, TranslatableItem& item);
void load_after_print_layout_position(const xmlpp::Element* nodeItem, const sharedptr<LayoutItem>& item);
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index 02bf365..234f3fa 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -600,6 +600,10 @@ void FlowTableWithFields::add_button_at_position(const sharedptr<LayoutItem_Butt
insert_before (*button, *widget, false /* expand */);
else
add(*button, false /* expand */);
+
+ //TODO: This doesn't seem to work.
+ Gtk::Widget* label = button->get_child();
+ apply_formatting(*label, layoutitem_button);
}
void FlowTableWithFields::add_textobject_at_position(const sharedptr<LayoutItem_Text>& layoutitem_text, const Glib::ustring& table_name , const type_list_layoutwidgets::iterator& add_before)
@@ -1325,9 +1329,8 @@ void FlowTableWithFields::on_dnd_add_layout_item_button(LayoutWidgetBase* above)
sharedptr<LayoutItem_Button> layout_item_button = sharedptr<LayoutItem_Button>::create();
layout_item_button->set_title(_("New Button")); //Give the button a default title, so it is big enough, and so people see that they should change it.
layout_item_button->set_name("new_button");
- sharedptr<LayoutItem> layout_item = sharedptr<LayoutItem>::cast_dynamic(layout_item_button);
- dnd_add_to_layout_group(layout_item, above);
+ dnd_add_to_layout_group(layout_item_button, above);
//Tell the parent to tell the document to save the layout:
signal_layout_changed().emit();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]