glom r1691 - in trunk: . glom/mode_design/print_layouts
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1691 - in trunk: . glom/mode_design/print_layouts
- Date: Tue, 30 Sep 2008 10:40:10 +0000 (UTC)
Author: murrayc
Date: Tue Sep 30 10:40:10 2008
New Revision: 1691
URL: http://svn.gnome.org/viewvc/glom?rev=1691&view=rev
Log:
2008-09-30 Murray Cumming <murrayc murrayc com>
* glom/mode_design/print_layouts/canvas_layout_item.cc:
* glom/mode_design/print_layouts/canvas_layout_item.h: set_layout_item():
Moved some code into a create_canvas_item_for_layout_item() function so
we can use it to create table cell items, without putting them inside
groups (resizables), because goocanvas cannot handle that.
Modified:
trunk/ChangeLog
trunk/glom/mode_design/print_layouts/canvas_layout_item.cc
trunk/glom/mode_design/print_layouts/canvas_layout_item.h
Modified: trunk/glom/mode_design/print_layouts/canvas_layout_item.cc
==============================================================================
--- trunk/glom/mode_design/print_layouts/canvas_layout_item.cc (original)
+++ trunk/glom/mode_design/print_layouts/canvas_layout_item.cc Tue Sep 30 10:40:10 2008
@@ -35,6 +35,7 @@
#include <glom/libglom/data_structure/glomconversions.h>
#include <glibmm/i18n.h>
#include <math.h>
+#include <algorithm> //For std::max().
namespace Glom
{
@@ -96,7 +97,7 @@
const Glib::ustring bg = formatting.get_text_format_color_background();
if(!bg.empty())
- canvas_item->property_fill_color() = bg;
+ canvas_item->property_fill_color() = bg;
}
void CanvasLayoutItem::on_resized()
@@ -106,19 +107,51 @@
canvas_image->scale_to_size();
}
-void CanvasLayoutItem::set_layout_item(const sharedptr<LayoutItem>& item)
+void CanvasLayoutItem::set_layout_item(const sharedptr<LayoutItem>& layout_item)
{
//Add the new child:
- m_layout_item = item;
+ m_layout_item = layout_item;
if(!m_layout_item)
std::cerr << "CanvasLayoutItem::set_layout_item(): item was NULL." << std::endl;
+ Glib::RefPtr<CanvasItemMovable> child_item = create_canvas_item_for_layout_item(m_layout_item);
+
+ if(child_item)
+ {
+ //child_item->property_pointer_events() =
+ // (Goocanvas::PointerEvents)(Goocanvas::CANVAS_EVENTS_VISIBLE_FILL & GOO_CANVAS_EVENTS_VISIBLE_STROKE);
+
+ //Set the position and dimensions of this group to match the child:
+ double x = 0;
+ double y = 0;
+ double width = 0;
+ double height = 0;
+ m_layout_item->get_print_layout_position(x, y, width, height);
+
+ set_xy(x, y);
+ set_width_height(width, height);
+ //std::cout << "CanvasLayoutItem::set_layout_item(): item x=" << x << std::endl;
+
+ set_child(child_item);
+ }
+
+ //Scale images.
+ //This can only be done after setting the size:
+ Glib::RefPtr<CanvasImageMovable> canvas_image = Glib::RefPtr<CanvasImageMovable>::cast_dynamic(child_item);
+ if(canvas_image)
+ {
+ canvas_image->scale_to_size();
+ }
+}
+
+Glib::RefPtr<CanvasItemMovable> CanvasLayoutItem::create_canvas_item_for_layout_item(const sharedptr<LayoutItem>& layout_item)
+{
sharedptr<LayoutItem_Line> line;
Glib::RefPtr<CanvasItemMovable> child;
Glib::RefPtr<Goocanvas::Item> child_item;
- sharedptr<LayoutItem_Text> text = sharedptr<LayoutItem_Text>::cast_dynamic(m_layout_item);
+ sharedptr<LayoutItem_Text> text = sharedptr<LayoutItem_Text>::cast_dynamic(layout_item);
if(text)
{
Glib::RefPtr<CanvasTextMovable> canvas_item = CanvasTextMovable::create();
@@ -133,7 +166,7 @@
}
else
{
- sharedptr<LayoutItem_Image> image = sharedptr<LayoutItem_Image>::cast_dynamic(m_layout_item);
+ sharedptr<LayoutItem_Image> image = sharedptr<LayoutItem_Image>::cast_dynamic(layout_item);
if(image)
{
Glib::RefPtr<CanvasImageMovable> canvas_item = CanvasImageMovable::create();
@@ -149,7 +182,7 @@
}
else
{
- sharedptr<LayoutItem_Line> line = sharedptr<LayoutItem_Line>::cast_dynamic(m_layout_item);
+ sharedptr<LayoutItem_Line> line = sharedptr<LayoutItem_Line>::cast_dynamic(layout_item);
if(line)
{
double start_x = 0;
@@ -171,7 +204,7 @@
}
else
{
- sharedptr<LayoutItem_Field> field = sharedptr<LayoutItem_Field>::cast_dynamic(m_layout_item);
+ sharedptr<LayoutItem_Field> field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
if(field)
{
//Create an appropriate canvas item for the field type:
@@ -203,7 +236,7 @@
}
else
{
- sharedptr<LayoutItem_Portal> portal = sharedptr<LayoutItem_Portal>::cast_dynamic(m_layout_item);
+ sharedptr<LayoutItem_Portal> portal = sharedptr<LayoutItem_Portal>::cast_dynamic(layout_item);
if(portal)
{
Glib::RefPtr<CanvasTableMovable> canvas_item = CanvasTableMovable::create();
@@ -212,8 +245,7 @@
canvas_item->property_stroke_color() = "black";
//Show as many rows as can fit in the height.
- //TODO: use std::max():
- const double row_height = MAX(portal->get_print_layout_row_height(), 1); //Avoid 0, because that makes the whole thing zero sized.
+ const double row_height = std::max(portal->get_print_layout_row_height(), (double)1); //Avoid 0, because that makes the whole thing zero sized.
double ignore_x = 0;
double ignore_y = 0;
double total_width = 0;
@@ -233,19 +265,30 @@
{
sharedptr<LayoutItem> layout_item = *iter;
- Glib::RefPtr<CanvasRectMovable> rect = CanvasRectMovable::create();
- rect->property_fill_color() = "white"; //This makes the whole area clickable, not just the outline stroke.
- rect->property_line_width() = 1;
- rect->property_stroke_color() = "black";
-
- //TODO: Use std::max():
- guint width = 0;
- layout_item->get_display_width(width);
- width = MAX(width, 10);
- rect->set_width_height(width, row_height);
+ //We use create_canvas_item_for_layout_item() instead of just
+ //creating another CanvasLayoutItem, because that would be a group,
+ //but goocanvas cannot yet support Groups inside Tables. murrayc.
+ //TODO: Bug number.
+ Glib::RefPtr<CanvasItemMovable> cell = create_canvas_item_for_layout_item(layout_item);
+ if(cell)
+ {
+ //Make sure that the width is sensible:
+ guint width = 0;
+ layout_item->get_display_width(width);
+ width = std::max(width, (guint)10);
+ cell->set_width_height(width, row_height);
+
+ //TODO: Add/Remove rows when resizing, instead of resizing the rows:
+ Glib::RefPtr<Goocanvas::Item> cell_as_item = CanvasItemMovable::cast_to_item(cell);
+ if(cell_as_item)
+ {
+ canvas_item->attach(cell_as_item,
+ col /* left_attach */, col+1 /* right_attach */,
+ row /* top_attach */, row + 1 /* right_attach */,
+ Gtk::SHRINK, (Gtk::AttachOptions)Gtk::FILL | Gtk::EXPAND);
+ }
+ }
- //TODO: Add/Remove rows when resizing, instead of resizing the rows:
- canvas_item->attach(rect, col /* left_attach */, col+1 /* right_attach */, row /* top_attach */, row + 1 /* right_attach */, Gtk::SHRINK, (Gtk::AttachOptions)Gtk::FILL | Gtk::EXPAND, 0.0, 0.0, 0.0, 0.0);
++col;
}
}
@@ -253,9 +296,9 @@
child = canvas_item;
child_item = canvas_item;
}
- else if(m_layout_item)
+ else if(layout_item)
{
- std::cerr << "CanvasLayoutItem::set_layout_item(): Unhandled LayoutItem type. part type=" << m_layout_item->get_part_type_name() << std::endl;
+ std::cerr << "CanvasLayoutItem::set_layout_item(): Unhandled LayoutItem type. part type=" << layout_item->get_part_type_name() << std::endl;
}
else
{
@@ -266,6 +309,8 @@
}
}
+ return child;
+
if(child && child_item)
{
//child_item->property_pointer_events() =
@@ -276,14 +321,9 @@
double y = 0;
double width = 0;
double height = 0;
- item->get_print_layout_position(x, y, width, height);
-
- set_xy(x, y);
- set_width_height(width, height);
+ layout_item->get_print_layout_position(x, y, width, height);
+ child->set_width_height(width, height);
//std::cout << "CanvasLayoutItem::set_layout_item(): item x=" << x << std::endl;
-
- //Set the child (this removes the previous child):
- set_child(child);
}
//Scale images.
@@ -295,6 +335,8 @@
//It will also be rescaled when this canvas item is resized - see on_resized().
}
+
+ return child;
}
void CanvasLayoutItem::set_db_data(const Gnome::Gda::Value& value)
Modified: trunk/glom/mode_design/print_layouts/canvas_layout_item.h
==============================================================================
--- trunk/glom/mode_design/print_layouts/canvas_layout_item.h (original)
+++ trunk/glom/mode_design/print_layouts/canvas_layout_item.h Tue Sep 30 10:40:10 2008
@@ -41,6 +41,7 @@
virtual ~CanvasLayoutItem();
public:
+
static Glib::RefPtr<CanvasLayoutItem> create();
//Creates a new canvas item, with an appropriate child canvas item,
@@ -51,7 +52,7 @@
//Create an appropriate child canvas item,
//and sets the position and size of this canvas item to the position in the LayoutItem.
- void set_layout_item(const sharedptr<LayoutItem>& item);
+ void set_layout_item(const sharedptr<LayoutItem>& layout_item);
/// Make the canvas item show actual data instead of, for instance, a field name.
void set_db_data(const Gnome::Gda::Value& value);
@@ -60,7 +61,10 @@
void remove_empty_indicators();
protected:
- void check_and_apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, FieldFormatting& formatting);
+ /// Create the appropriate inner canvas item to represent the layout item.
+ static Glib::RefPtr<CanvasItemMovable> create_canvas_item_for_layout_item(const sharedptr<LayoutItem>& layout_item);
+
+ static void check_and_apply_formatting(const Glib::RefPtr<CanvasTextMovable>& canvas_item, FieldFormatting& formatting);
void on_resized();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]