]> saetta.ns0.it Git - reptool/libreptool/commitdiff
Some bugfixes.
authorAndrea Zagli <azagli@libero.it>
Sun, 15 Apr 2007 09:02:02 +0000 (09:02 +0000)
committerAndrea Zagli <azagli@libero.it>
Sun, 15 Apr 2007 09:02:02 +0000 (09:02 +0000)
Added programmatically report creation test.
Static text in text's source attribute must be enclosed into "".
Added text's attributes padding*.
Added page's attributes margin*.
Added RptReport's signal "field-request".

git-svn-id: svn+ssh://saetta.homelinux.org/svn/libreptool/trunk@12 3191ed1d-3fce-41bb-ab4a-0cebc0943b59

23 files changed:
ChangeLog
configure.ac
docs/reference/tmpl/rptobjecttext.sgml
docs/reference/tmpl/rptreport.sgml
src/Makefile.am
src/libreptool.h
src/reptool_marshal.list [new file with mode: 0644]
src/rptcommon.c
src/rptcommon.h
src/rptmarshal.c [new file with mode: 0644]
src/rptmarshal.h [new file with mode: 0644]
src/rptobjectimage.c
src/rptobjectline.c
src/rptobjectrect.c
src/rptobjecttext.c
src/rptprint.c
src/rptreport.c
src/rptreport.h
tests/Makefile.am
tests/test_report.rpt
tests/test_report_db.rpt
tests/test_rptreport.c
tests/test_rptreport_creation.c [new file with mode: 0644]

index 86684b44bc8b1d0d40c445961f50be5e2d2a6cad..31b4c1de34142fd7b0968e8f8956f87b8900dfd3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2007-04-15 Andrea Zagli <azagli@inwind.it>
+
+       * src/rptreport.c:
+       * src/rptprint.c: managed page's margins
+       * src/reptool_marshal.list:
+       * src/rtpmarshal.*: added
+       * src/rptreport.c: added signal "field-request"
+
+2007-04-14 Andrea Zagli <azagli@inwind.it>
+
+       * src/*.c: API documentation
+       * src/rptobjtext.c: added text's attributes padding*
+       * src/rptprint.c: managed text's attributes padding*
+       * src/rptreport.c: static text in text's source attribute must be enclosed
+       into "" (xml entity &quot;);
+       added page's attributes margin*
+
+2007-04-13 Andrea Zagli <azagli@inwind.it>
+
+       * src/Makefile.am: added -no-undefined
+       * tests/test_rptreport_creation.c: added report creation test
+       * src/rptreport.c: changed rpt_report_add_object_to_section()'s prototype
+       * src/rptcommon.c: bugfix on rpt_common_convert_to_str_color
+
 2007-04-08 Andrea Zagli <azagli@inwind.it>
 
        * src/rptreport.h:
index 83c886f65fbe1c9db0cd87c7396704725887eb0c..cfa0c3deb4ce204754f5abe7135d0bca908bc939 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([libreptool], [0.0.3], [azagli@inwind.it])
+AC_INIT([libreptool], [0.0.4], [azagli@inwind.it])
 AC_CONFIG_SRCDIR([src/rptprint.c])
 AC_CONFIG_HEADER([config.h])
 
index 15fc9cdf30545aedffe5e121eb7208e05f2802c6..616a8d624dd22002003ef21caeeee79191ee336b 100644 (file)
@@ -43,6 +43,26 @@ A textual object.
 
 </para>
 
+<!-- ##### ARG RptObjText:padding-bottom ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG RptObjText:padding-left ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG RptObjText:padding-right ##### -->
+<para>
+
+</para>
+
+<!-- ##### ARG RptObjText:padding-top ##### -->
+<para>
+
+</para>
+
 <!-- ##### ARG RptObjText:size ##### -->
 <para>
 
index df3e7fc56cfec264d09e0fd78b78001a3701548c..94045b45bf58001459d842e74bf864bd3cc06e87 100644 (file)
@@ -23,6 +23,17 @@ Manage report definition files and produces the xml report/print's file.
 </para>
 
 
+<!-- ##### SIGNAL RptReport::field-request ##### -->
+<para>
+
+</para>
+
+@rptreport: the object which received the signal.
+@arg1: 
+@arg2: 
+@arg3: 
+@Returns: 
+
 <!-- ##### ENUM RptReportSection ##### -->
 <para>
 
@@ -154,6 +165,7 @@ Manage report definition files and produces the xml report/print's file.
 @rpt_report: 
 @rpt_object: 
 @section: 
+@Returns: 
 
 
 <!-- ##### FUNCTION rpt_report_remove_object ##### -->
index 6854c2f4679083bb1bae7d237edb37cd6a1c5a3f..271533336f9dc927e2490cdd822ab971d0315827 100644 (file)
@@ -4,6 +4,8 @@ AM_CPPFLAGS = $(REPTOOL_CFLAGS)
 
 lib_LTLIBRARIES = libreptool.la
 
+libreptool_la_LDFLAGS = -no-undefined
+
 libreptool_la_SOURCES = \
                         rptobject.c \
                         rptobjecttext.c \
@@ -13,7 +15,8 @@ libreptool_la_SOURCES = \
                         rptobjectimage.c \
                         rptreport.c \
                         rptprint.c \
-                        rptcommon.c
+                        rptcommon.c \
+                        rptmarshal.c
 
 include_HEADERS = \
                   libreptool.h \
@@ -26,3 +29,6 @@ include_HEADERS = \
                   rptreport.h \
                   rptprint.h \
                   rptcommon.h
+
+noinst_HEADERS = \
+                 rptmarshal.h
index 42526d6d94c53d528f0c2bff5d9f790f6cb90572..80fd1e7c16ec2fd0205ca4ecbbb0e260bbc916aa 100644 (file)
 #define __LIBREPTOOL_H__
 
 #include <rptreport.h>
+#include <rptcommon.h>
+#include <rptobject.h>
+#include <rptobjectellipse.h>
+#include <rptobjectimage.h>
+#include <rptobjectline.h>
+#include <rptobjectrect.h>
+#include <rptobjecttext.h>
 #include <rptprint.h>
 
 #endif /* __LIBREPTOOL_H__ */
diff --git a/src/reptool_marshal.list b/src/reptool_marshal.list
new file mode 100644 (file)
index 0000000..2f8088f
--- /dev/null
@@ -0,0 +1 @@
+STRING:STRING,POINTER,INT
index 0ca9437925ea11e37493301e0f00b0a82daa3baa..48676e84fc59e34d617fc02e17949154feca94e8 100644 (file)
@@ -276,49 +276,49 @@ RptBorder
        border->left_color->b = 0.0;
        border->left_color->a = 1.0;
 
-       prop = xmlGetProp (xnode, "border-top-width");
+       prop = (gchar *)xmlGetProp (xnode, "border-top-width");
        if (prop != NULL)
                {
                        border->top_width = strtod (prop, NULL);
                }
 
-       prop = xmlGetProp (xnode, "border-right-width");
+       prop = (gchar *)xmlGetProp (xnode, "border-right-width");
        if (prop != NULL)
                {
                        border->right_width = strtod (prop, NULL);
                }
 
-       prop = xmlGetProp (xnode, "border-bottom-width");
+       prop = (gchar *)xmlGetProp (xnode, "border-bottom-width");
        if (prop != NULL)
                {
                        border->bottom_width = strtod (prop, NULL);
                }
 
-       prop = xmlGetProp (xnode, "border-left-width");
+       prop = (gchar *)xmlGetProp (xnode, "border-left-width");
        if (prop != NULL)
                {
                        border->left_width = strtod (prop, NULL);
                }
 
-       prop = xmlGetProp (xnode, "border-top-color");
+       prop = (gchar *)xmlGetProp (xnode, "border-top-color");
        if (prop != NULL)
                {
                        border->top_color = rpt_common_parse_color (prop);
                }
 
-       prop = xmlGetProp (xnode, "border-right-color");
+       prop = (gchar *)xmlGetProp (xnode, "border-right-color");
        if (prop != NULL)
                {
                        border->right_color = rpt_common_parse_color (prop);
                }
 
-       prop = xmlGetProp (xnode, "border-bottom-color");
+       prop = (gchar *)xmlGetProp (xnode, "border-bottom-color");
        if (prop != NULL)
                {
                        border->bottom_color = rpt_common_parse_color (prop);
                }
 
-       prop = xmlGetProp (xnode, "border-left-color");
+       prop = (gchar *)xmlGetProp (xnode, "border-left-color");
        if (prop != NULL)
                {
                        border->left_color = rpt_common_parse_color (prop);
@@ -510,8 +510,9 @@ rpt_common_set_stroke (xmlNode *xnode, const RptStroke *stroke)
 
 /**
  * rpt_common_parse_color:
- * @str_color:
+ * @str_color: a color string.
  *
+ * Returns: an #RptColor.
  */
 RptColor
 *rpt_common_parse_color (const gchar *str_color)
@@ -557,7 +558,7 @@ RptColor
                                                {
                                                        color->b = strtol (g_strndup (&c[5], 2), NULL, 16) / 255.0;
                                                }
-                                       if (strlen (c) == 9)
+                                       if (strlen (c) == 9 && isxdigit (c[7]) && isxdigit (c[8]))
                                                {
                                                        color->a = strtol (g_strndup (&c[7], 2), NULL, 16) / 255.0;
                                                }
@@ -569,8 +570,9 @@ RptColor
 
 /**
  * rpt_common_convert_to_str_color:
- * @color:
+ * @color: an #RptColor value.
  *
+ * Returns: the color string correspondent to @color.
  */
 gchar
 *rpt_common_convert_to_str_color (const RptColor *color)
@@ -581,10 +583,10 @@ gchar
                {
                        ret = g_strdup  ("#");
 
-                       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)color->r * 255), NULL);
-                       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)color->g * 255), NULL);
-                       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)color->b * 255), NULL);
-                       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)color->a * 255), NULL);
+                       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)(color->r * 255)), NULL);
+                       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)(color->g * 255)), NULL);
+                       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)(color->b * 255)), NULL);
+                       ret = g_strconcat (ret, g_strdup_printf ("%.2X", (gint)(color->a * 255)), NULL);
                }
 
        return ret;
index 60571302caef4145af298f95e739b4ff12361ac4..71ad03f074f0f30259dbcd55bc0574037d1c740b 100644 (file)
@@ -30,10 +30,10 @@ G_BEGIN_DECLS
 
 /**
  * RptColor:
- * @r: the red channel
- * @g: the green channel
- * @b: the blue channel
- * @a: the alpha channel
+ * @r: the red channel.
+ * @g: the green channel.
+ * @b: the blue channel.
+ * @a: the alpha channel.
  */
 struct _RptColor
 {
diff --git a/src/rptmarshal.c b/src/rptmarshal.c
new file mode 100644 (file)
index 0000000..3664552
--- /dev/null
@@ -0,0 +1,92 @@
+
+#include       <glib-object.h>
+
+
+#ifdef G_ENABLE_DEBUG
+#define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
+#define g_marshal_value_peek_char(v)     g_value_get_char (v)
+#define g_marshal_value_peek_uchar(v)    g_value_get_uchar (v)
+#define g_marshal_value_peek_int(v)      g_value_get_int (v)
+#define g_marshal_value_peek_uint(v)     g_value_get_uint (v)
+#define g_marshal_value_peek_long(v)     g_value_get_long (v)
+#define g_marshal_value_peek_ulong(v)    g_value_get_ulong (v)
+#define g_marshal_value_peek_int64(v)    g_value_get_int64 (v)
+#define g_marshal_value_peek_uint64(v)   g_value_get_uint64 (v)
+#define g_marshal_value_peek_enum(v)     g_value_get_enum (v)
+#define g_marshal_value_peek_flags(v)    g_value_get_flags (v)
+#define g_marshal_value_peek_float(v)    g_value_get_float (v)
+#define g_marshal_value_peek_double(v)   g_value_get_double (v)
+#define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
+#define g_marshal_value_peek_param(v)    g_value_get_param (v)
+#define g_marshal_value_peek_boxed(v)    g_value_get_boxed (v)
+#define g_marshal_value_peek_pointer(v)  g_value_get_pointer (v)
+#define g_marshal_value_peek_object(v)   g_value_get_object (v)
+#else /* !G_ENABLE_DEBUG */
+/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
+ *          Do not access GValues directly in your code. Instead, use the
+ *          g_value_get_*() functions
+ */
+#define g_marshal_value_peek_boolean(v)  (v)->data[0].v_int
+#define g_marshal_value_peek_char(v)     (v)->data[0].v_int
+#define g_marshal_value_peek_uchar(v)    (v)->data[0].v_uint
+#define g_marshal_value_peek_int(v)      (v)->data[0].v_int
+#define g_marshal_value_peek_uint(v)     (v)->data[0].v_uint
+#define g_marshal_value_peek_long(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_ulong(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_int64(v)    (v)->data[0].v_int64
+#define g_marshal_value_peek_uint64(v)   (v)->data[0].v_uint64
+#define g_marshal_value_peek_enum(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_flags(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_float(v)    (v)->data[0].v_float
+#define g_marshal_value_peek_double(v)   (v)->data[0].v_double
+#define g_marshal_value_peek_string(v)   (v)->data[0].v_pointer
+#define g_marshal_value_peek_param(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_boxed(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_pointer(v)  (v)->data[0].v_pointer
+#define g_marshal_value_peek_object(v)   (v)->data[0].v_pointer
+#endif /* !G_ENABLE_DEBUG */
+
+
+/* STRING:STRING,POINTER,INT (reptool_marshal.list:1) */
+void
+_rpt_marshal_STRING__STRING_POINTER_INT (GClosure     *closure,
+                                         GValue       *return_value,
+                                         guint         n_param_values,
+                                         const GValue *param_values,
+                                         gpointer      invocation_hint,
+                                         gpointer      marshal_data)
+{
+  typedef gchar* (*GMarshalFunc_STRING__STRING_POINTER_INT) (gpointer     data1,
+                                                             gpointer     arg_1,
+                                                             gpointer     arg_2,
+                                                             gint         arg_3,
+                                                             gpointer     data2);
+  register GMarshalFunc_STRING__STRING_POINTER_INT callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+  gchar* v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_STRING__STRING_POINTER_INT) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_string (param_values + 1),
+                       g_marshal_value_peek_pointer (param_values + 2),
+                       g_marshal_value_peek_int (param_values + 3),
+                       data2);
+
+  g_value_take_string (return_value, v_return);
+}
+
diff --git a/src/rptmarshal.h b/src/rptmarshal.h
new file mode 100644 (file)
index 0000000..56bb519
--- /dev/null
@@ -0,0 +1,20 @@
+
+#ifndef ___rpt_marshal_MARSHAL_H__
+#define ___rpt_marshal_MARSHAL_H__
+
+#include       <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* STRING:STRING,POINTER,INT (reptool_marshal.list:1) */
+extern void _rpt_marshal_STRING__STRING_POINTER_INT (GClosure     *closure,
+                                                     GValue       *return_value,
+                                                     guint         n_param_values,
+                                                     const GValue *param_values,
+                                                     gpointer      invocation_hint,
+                                                     gpointer      marshal_data);
+
+G_END_DECLS
+
+#endif /* ___rpt_marshal_MARSHAL_H__ */
+
index 8a81f3d8ec88b27f502794decfc60a054780d84d..96e27dfa1034fe5dd4cbc27bcff58b00a38beb85 100644 (file)
@@ -132,7 +132,9 @@ rpt_obj_image_init (RptObjImage *rpt_obj_image)
 /**
  * rpt_obj_image_new:
  * @name: the #RptObjImage's name.
- * @position:
+ * @position: an #RptPoint.
+ *
+ * Creates a new #RptObjImage object and sets its position to @position.
  *
  * Returns: the newly created #RptObject object.
  */
index c07f60898001ba6f066c115b99e41da62e1c8b1c..6df40b4e1e67c99675095b9c55f01da1de1a3eb1 100644 (file)
@@ -116,7 +116,9 @@ rpt_obj_line_init (RptObjLine *rpt_obj_line)
 /**
  * rpt_obj_line_new:
  * @name: the #RptObjLine's name.
- * @position:
+ * @position: an #RptPoint.
+ *
+ * Creates a new #RptObjLine object and sets its position to @position.
  *
  * Returns: the newly created #RptObject object.
  */
index 947d3db6dfc6f6701bfd4c76b633cc97293d15d2..ae4609ae5c5eeb23a0145b94d1ca7acce08a1489 100644 (file)
@@ -105,7 +105,9 @@ rpt_obj_rect_init (RptObjRect *rpt_obj_rect)
 /**
  * rpt_obj_rect_new:
  * @name: the #RptObjRect's name.
- * @position:
+ * @position: an #RptPoint.
+ *
+ * Creates a new #RptObjRect object and sets its position to @position.
  *
  * Returns: the newly created #RptObject object.
  */
index a1c17fc9b9ab2335fd4bca43d9df8c6d204de4f9..a8abc7bc78e8e7b788e24a6725884b56a4ef9c42 100644 (file)
@@ -27,7 +27,11 @@ enum
        PROP_FONT,
        PROP_ALIGN,
        PROP_SOURCE,
-       PROP_BACKGROUND_COLOR
+       PROP_BACKGROUND_COLOR,
+       PROP_PADDING_TOP,
+       PROP_PADDING_RIGHT,
+       PROP_PADDING_BOTTOM,
+       PROP_PADDING_LEFT
 };
 
 static void rpt_obj_text_class_init (RptObjTextClass *klass);
@@ -54,6 +58,10 @@ struct _RptObjTextPrivate
                RptAlign *align;
                gchar *source;
                RptColor *background_color;
+               gdouble padding_top;
+               gdouble padding_right;
+               gdouble padding_bottom;
+               gdouble padding_left;
        };
 
 GType
@@ -128,6 +136,30 @@ rpt_obj_text_class_init (RptObjTextClass *klass)
                                                               "Background Color",
                                                               "The text's background color.",
                                                               G_PARAM_READWRITE));
+       g_object_class_install_property (object_class, PROP_PADDING_TOP,
+                                        g_param_spec_double ("padding-top",
+                                                             "Padding Top",
+                                                             "Padding Top",
+                                                             0, G_MAXDOUBLE, 0,
+                                                             G_PARAM_READWRITE));
+       g_object_class_install_property (object_class, PROP_PADDING_RIGHT,
+                                        g_param_spec_double ("padding-right",
+                                                             "Padding Right",
+                                                             "Padding Right",
+                                                             0, G_MAXDOUBLE, 0,
+                                                             G_PARAM_READWRITE));
+       g_object_class_install_property (object_class, PROP_PADDING_BOTTOM,
+                                        g_param_spec_double ("padding-bottom",
+                                                             "Padding Bottom",
+                                                             "Padding Bottom",
+                                                             0, G_MAXDOUBLE, 0,
+                                                             G_PARAM_READWRITE));
+       g_object_class_install_property (object_class, PROP_PADDING_LEFT,
+                                        g_param_spec_double ("padding-left",
+                                                             "Padding Left",
+                                                             "Padding Left",
+                                                             0, G_MAXDOUBLE, 0,
+                                                             G_PARAM_READWRITE));
 }
 
 static void
@@ -148,7 +180,9 @@ rpt_obj_text_init (RptObjText *rpt_obj_text)
 /**
  * rpt_obj_text_new:
  * @name: the #RptObjText's name.
- * @position:
+ * @position: an #RptPoint.
+ *
+ * Creates a new #RptObjText object and sets its position to @position.
  *
  * Returns: the newly created #RptObject object.
  */
@@ -174,7 +208,7 @@ RptObject
 
 /**
  * rpt_obj_text_new_from_xml:
- * @xnode:
+ * @xnode: an #xmlNode.
  *
  * Returns: the newly created #RptObject object.
  */
@@ -215,6 +249,27 @@ RptObject
                                                        color = rpt_common_parse_color (g_strstrip (prop));
                                                        g_object_set (rpt_obj_text, "background-color", color, NULL);
                                                }
+
+                                       prop = (gchar *)xmlGetProp (xnode, "padding-top");
+                                       if (prop != NULL)
+                                               {
+                                                       g_object_set (rpt_obj_text, "padding-top", strtod (prop, NULL), NULL);
+                                               }
+                                       prop = (gchar *)xmlGetProp (xnode, "padding-right");
+                                       if (prop != NULL)
+                                               {
+                                                       g_object_set (rpt_obj_text, "padding-right", strtod (prop, NULL), NULL);
+                                               }
+                                       prop = (gchar *)xmlGetProp (xnode, "padding-bottom");
+                                       if (prop != NULL)
+                                               {
+                                                       g_object_set (rpt_obj_text, "padding-bottom", strtod (prop, NULL), NULL);
+                                               }
+                                       prop = (gchar *)xmlGetProp (xnode, "padding-left");
+                                       if (prop != NULL)
+                                               {
+                                                       g_object_set (rpt_obj_text, "padding-left", strtod (prop, NULL), NULL);
+                                               }
                                }
                }
 
@@ -223,8 +278,8 @@ RptObject
 
 /**
  * rpt_obj_text_get_xml:
- * @rpt_objtext:
- * @xnode:
+ * @rpt_objtext: an #RptObjText object.
+ * @xnode: an #xmlNode.
  *
  */
 void
@@ -245,6 +300,23 @@ rpt_obj_text_get_xml (RptObject *rpt_objtext, xmlNode *xnode)
                {
                        xmlSetProp (xnode, "background-color", rpt_common_convert_to_str_color (priv->background_color));
                }
+
+       if (priv->padding_top != 0.0)
+               {
+                       xmlSetProp (xnode, "padding-top", g_strdup_printf ("%f", priv->padding_top));
+               }
+       if (priv->padding_right != 0.0)
+               {
+                       xmlSetProp (xnode, "padding-right", g_strdup_printf ("%f", priv->padding_right));
+               }
+       if (priv->padding_bottom != 0.0)
+               {
+                       xmlSetProp (xnode, "padding-bottom", g_strdup_printf ("%f", priv->padding_bottom));
+               }
+       if (priv->padding_left != 0.0)
+               {
+                       xmlSetProp (xnode, "padding-left", g_strdup_printf ("%f", priv->padding_left));
+               }
 }
 
 static void
@@ -280,6 +352,22 @@ rpt_obj_text_set_property (GObject *object, guint property_id, const GValue *val
                                priv->background_color = g_memdup (g_value_get_pointer (value), sizeof (RptColor));
                                break;
 
+                       case PROP_PADDING_TOP:
+                               priv->padding_top = g_value_get_double (value);
+                               break;
+
+                       case PROP_PADDING_RIGHT:
+                               priv->padding_right = g_value_get_double (value);
+                               break;
+
+                       case PROP_PADDING_BOTTOM:
+                               priv->padding_bottom = g_value_get_double (value);
+                               break;
+
+                       case PROP_PADDING_LEFT:
+                               priv->padding_left = g_value_get_double (value);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
@@ -319,6 +407,22 @@ rpt_obj_text_get_property (GObject *object, guint property_id, GValue *value, GP
                                g_value_set_pointer (value, g_memdup (priv->background_color, sizeof (RptColor)));
                                break;
 
+                       case PROP_PADDING_TOP:
+                               g_value_set_double (value, priv->padding_top);
+                               break;
+
+                       case PROP_PADDING_RIGHT:
+                               g_value_set_double (value, priv->padding_right);
+                               break;
+
+                       case PROP_PADDING_BOTTOM:
+                               g_value_set_double (value, priv->padding_bottom);
+                               break;
+
+                       case PROP_PADDING_LEFT:
+                               g_value_set_double (value, priv->padding_left);
+                               break;
+
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
                                break;
index 35abb3e0c4f0de0809830472cb7ac4637454cb52..696ebe05825544b0d9af125fad30b5d3a26c8009 100644 (file)
@@ -74,8 +74,13 @@ static void rpt_print_border (RptPrint *rpt_print,
 typedef struct _RptPrintPrivate RptPrintPrivate;
 struct _RptPrintPrivate
        {
-               gint width;
-               gint height;
+               gdouble width;
+               gdouble height;
+               gdouble margin_top;
+               gdouble margin_right;
+               gdouble margin_bottom;
+               gdouble margin_left;
+
                cairo_surface_t *surface;
                cairo_t *cr;
        };
@@ -130,11 +135,14 @@ rpt_print_init (RptPrint *rpt_print)
  * @output_type:
  * @out_filename:
  *
+ * Creates a new #RptPrint object.
+ *
  * Returns: the newly created #RptPrint object.
  */
 RptPrint
 *rpt_print_new_from_xml (xmlDoc *xdoc, RptPrintOutputType output_type, const gchar *out_filename)
 {
+       gchar *prop;
        RptPrint *rpt_print = NULL;
 
        xmlNode *cur = xmlDocGetRootElement (xdoc);
@@ -168,8 +176,36 @@ RptPrint
                                                                {
                                                                        npage++;
 
-                                                                       priv->width = atol (xmlGetProp (cur, (const xmlChar *)"width"));
-                                                                       priv->height = atol (xmlGetProp (cur, (const xmlChar *)"height"));
+                                                                       prop = xmlGetProp (cur, (const xmlChar *)"width");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       priv->width = strtod (prop, NULL);
+                                                                               }
+                                                                       prop = xmlGetProp (cur, (const xmlChar *)"height");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       priv->height = strtod (prop, NULL);
+                                                                               }
+                                                                       prop = xmlGetProp (cur, (const xmlChar *)"margin-top");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       priv->margin_top = strtod (prop, NULL);
+                                                                               }
+                                                                       prop = xmlGetProp (cur, (const xmlChar *)"margin-right");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       priv->margin_right = strtod (prop, NULL);
+                                                                               }
+                                                                       prop = xmlGetProp (cur, (const xmlChar *)"margin-bottom");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       priv->margin_bottom = strtod (prop, NULL);
+                                                                               }
+                                                                       prop = xmlGetProp (cur, (const xmlChar *)"margin-left");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       priv->margin_left = strtod (prop, NULL);
+                                                                               }
 
                                                                        if (priv->width != 0 && priv->height != 0)
                                                                                {
@@ -178,19 +214,19 @@ RptPrint
                                                                                                        switch (output_type)
                                                                                                                {
                                                                                                                        case RPTP_OUTPUT_PNG:
-                                                                                                                               priv->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, priv->width, priv->height);
+                                                                                                                               priv->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int)priv->width, (int)priv->height);
                                                                                                                                break;
                                                                                                                
                                                                                                                        case RPTP_OUTPUT_PDF:
-                                                                                                                               priv->surface = cairo_pdf_surface_create (out_filename, (double)priv->width, (double)priv->height);
+                                                                                                                               priv->surface = cairo_pdf_surface_create (out_filename, priv->width, priv->height);
                                                                                                                                break;
                
                                                                                                                        case RPTP_OUTPUT_PS:
-                                                                                                                               priv->surface = cairo_ps_surface_create (out_filename, (double)priv->width, (double)priv->height);
+                                                                                                                               priv->surface = cairo_ps_surface_create (out_filename, priv->width, priv->height);
                                                                                                                                break;
                
                                                                                                                        case RPTP_OUTPUT_SVG:
-                                                                                                                               priv->surface = cairo_svg_surface_create (out_filename, (double)priv->width, (double)priv->height);
+                                                                                                                               priv->surface = cairo_svg_surface_create (out_filename, priv->width, priv->height);
                                                                                                                                break;
                                                                                                                }
                                                                                                }
@@ -273,6 +309,8 @@ RptPrint
  * @output_type:
  * @out_filename:
  *
+ * Creates a new #RptPrint object.
+ *
  * Returns: the newly created #RptPrint object.
  */
 RptPrint
@@ -326,6 +364,14 @@ rpt_print_page (RptPrint *rpt_print, xmlNode *xnode)
 
        xmlNode *cur = xnode->children;
 
+       /* clipping region for page's margins */
+       cairo_rectangle (priv->cr,
+                        priv->margin_left,
+                                        priv->margin_top,
+                                        priv->width - priv->margin_left - priv->margin_right,
+                                        priv->height - priv->margin_top - priv->margin_bottom);
+       cairo_clip (priv->cr);
+
        while (cur != NULL)
                {
                        cairo_save (priv->cr);
@@ -376,10 +422,10 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
        gchar *prop;
        gchar *str_font;
 
-       gdouble pad_top;
-       gdouble pad_right;
-       gdouble pad_bottom;
-       gdouble pad_left;
+       gdouble padding_top = 0.0;
+       gdouble padding_right = 0.0;
+       gdouble padding_bottom = 0.0;
+       gdouble padding_left = 0.0;
 
        position = rpt_common_get_position (xnode);
        size = rpt_common_get_size (xnode);
@@ -391,29 +437,29 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
        prop = xmlGetProp (xnode, (const xmlChar *)"padding-top");
        if (prop != NULL)
                {
-                       pad_top = atof (prop);
+                       padding_top = atof (prop);
                }
        prop = xmlGetProp (xnode, (const xmlChar *)"padding-right");
        if (prop != NULL)
                {
-                       pad_right= atof (prop);
+                       padding_right= atof (prop);
                }
        prop = xmlGetProp (xnode, (const xmlChar *)"padding-bottom");
        if (prop != NULL)
                {
-                       pad_bottom= atof (prop);
+                       padding_bottom= atof (prop);
                }
        prop = xmlGetProp (xnode, (const xmlChar *)"padding-left");
        if (prop != NULL)
                {
-                       pad_left= atof (prop);
+                       padding_left= atof (prop);
                }
 
        /* creating pango layout */
        playout = pango_cairo_create_layout (priv->cr);
        if (size != NULL)
                {
-                       pango_layout_set_width (playout, size->width * PANGO_SCALE);
+                       pango_layout_set_width (playout, (size->width - padding_left - padding_right) * PANGO_SCALE);
                }
 
        str_font = g_strdup (font->name);
@@ -522,7 +568,11 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
        /* setting clipping region */
        if (position != NULL && size != NULL)
                {
-                       cairo_rectangle (priv->cr, position->x, position->y, size->width, size->height);
+                       cairo_rectangle (priv->cr,
+                                        position->x + padding_left,
+                                        position->y + padding_top,
+                                        size->width - padding_left - padding_right,
+                                        size->height - padding_top - padding_bottom);
                        cairo_clip (priv->cr);
                }
 
@@ -540,7 +590,7 @@ rpt_print_text_xml (RptPrint *rpt_print, xmlNode *xnode)
                }
        if (position != NULL)
                {
-                       cairo_move_to (priv->cr, position->x, position->y);
+                       cairo_move_to (priv->cr, position->x + padding_left, position->y + padding_top);
                }
        pango_layout_set_text (playout, text, -1);
        pango_cairo_show_layout (priv->cr, playout);
index 075ca6ccb41fcc71c21a75256a7609ede9a8ca81..e68f0a098ac97f76f5ecef9335c1a8efc5a6d8ef 100644 (file)
@@ -20,7 +20,6 @@
 #include <string.h>
 #include <time.h>
 
-#include <libgda/libgda.h>
 #include <libxml/xpath.h>
 
 #ifdef HAVE_CONFIG_H
@@ -35,6 +34,8 @@
 #include "rptobjectellipse.h"
 #include "rptobjectimage.h"
 
+#include "rptmarshal.h"
+
 typedef struct
 {
        gchar *provider_id;
@@ -49,6 +50,10 @@ typedef struct
 typedef struct
 {
        RptSize *size;
+       gdouble margin_top;
+       gdouble margin_right;
+       gdouble margin_bottom;
+       gdouble margin_left;
 } Page;
 
 typedef struct
@@ -181,6 +186,29 @@ rpt_report_class_init (RptReportClass *klass)
 
        object_class->set_property = rpt_report_set_property;
        object_class->get_property = rpt_report_get_property;
+
+       /**
+        * RptReport::field-request:
+        * @rpt_report: an #RptReport object that recieved the signal.
+        * @field_name: the name of the field requested.
+        * @data_model: a #GdaDataModel; or NULL if there's no database source.
+        * @row: the current @data_model's row; -1 if @data_model is NULL.
+        *
+        * The signal is emitted each time there's into text's source
+        * attribute a field that doesn't exists.
+        */
+       klass->field_request_signal_id = g_signal_new ("field-request",
+                                                      G_TYPE_FROM_CLASS (object_class),
+                                                      G_SIGNAL_RUN_LAST,
+                                                      0,
+                                                      NULL,
+                                                      NULL,
+                                                      _rpt_marshal_STRING__STRING_POINTER_INT,
+                                                      G_TYPE_STRING,
+                                                      3,
+                                                      G_TYPE_STRING,
+                                                      G_TYPE_POINTER,
+                                                      G_TYPE_INT);
 }
 
 static void
@@ -209,6 +237,8 @@ rpt_report_init (RptReport *rpt_report)
 /**
  * rpt_report_new:
  *
+ * Creates a new #RptReport object.
+ *
  * Returns: the newly created #RptReport object.
  */
 RptReport
@@ -319,10 +349,37 @@ RptReport
                                                        xnodeset = xpresult->nodesetval;
                                                        if (xnodeset->nodeNr == 1)
                                                                {
+                                                                       gchar *prop;
+                                                                       gdouble margin_top = 0.0;
+                                                                       gdouble margin_right = 0.0;
+                                                                       gdouble margin_bottom = 0.0;
+                                                                       gdouble margin_left = 0.0;
                                                                        RptSize *size;
 
                                                                        size = rpt_common_get_size (xnodeset->nodeTab[0]);
                                                                        rpt_report_set_page_size (rpt_report, *size);
+
+                                                                       prop = xmlGetProp (xnodeset->nodeTab[0], "margin-top");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       margin_top = strtod (prop, NULL);
+                                                                               }
+                                                                       prop = xmlGetProp (xnodeset->nodeTab[0], "margin-right");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       margin_right = strtod (prop, NULL);
+                                                                               }
+                                                                       prop = xmlGetProp (xnodeset->nodeTab[0], "margin-bottom");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       margin_bottom = strtod (prop, NULL);
+                                                                               }
+                                                                       prop = xmlGetProp (xnodeset->nodeTab[0], "margin-left");
+                                                                       if (prop != NULL)
+                                                                               {
+                                                                                       margin_left = strtod (prop, NULL);
+                                                                               }
+                                                                       rpt_report_set_page_margins (rpt_report, margin_top, margin_right, margin_bottom, margin_left);
                                                                }
                                                        else
                                                                {
@@ -456,6 +513,7 @@ rpt_report_set_database (RptReport *rpt_report,
  * @rpt_report: an #RptReport object.
  * @size: an #RptSize.
  *
+ * Sets page's size.
  */
 void
 rpt_report_set_page_size (RptReport *rpt_report,
@@ -467,12 +525,38 @@ rpt_report_set_page_size (RptReport *rpt_report,
        priv->page->size->height = size.height;
 }
 
+/**
+ * rpt_report_set_page_margins:
+ * @rpt_report:
+ * @top:
+ * @right:
+ * @bottom:
+ * @left:
+ *
+ * Sets page's margins.
+ */
+void
+rpt_report_set_page_margins (RptReport *rpt_report,
+                             gdouble top,
+                             gdouble right,
+                             gdouble bottom,
+                             gdouble left)
+{
+       RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
+
+       priv->page->margin_top = top;
+       priv->page->margin_right = right;
+       priv->page->margin_bottom = bottom;
+       priv->page->margin_left = left;
+}
+
 /**
  * rpt_report_set_section_height: 
  * @rpt_report: an #RptReport object.
  * @section:
  * @height: the section's height.
  *
+ * Sets @section's height.
  */
 void
 rpt_report_set_section_height (RptReport *rpt_report,
@@ -619,6 +703,22 @@ xmlDoc
 
        xnode = xmlNewNode (NULL, "page");
        rpt_common_set_size (xnode, priv->page->size);
+       if (priv->page->margin_top != 0.0)
+               {
+                       xmlSetProp (xnode, "margin-top", g_strdup_printf ("%f", priv->page->margin_top));
+               }
+       if (priv->page->margin_right != 0.0)
+               {
+                       xmlSetProp (xnode, "margin-right", g_strdup_printf ("%f", priv->page->margin_right));
+               }
+       if (priv->page->margin_bottom != 0.0)
+               {
+                       xmlSetProp (xnode, "margin-bottom", g_strdup_printf ("%f", priv->page->margin_bottom));
+               }
+       if (priv->page->margin_left != 0.0)
+               {
+                       xmlSetProp (xnode, "margin-left", g_strdup_printf ("%f", priv->page->margin_left));
+               }
        xmlAddChild (xroot, xnode);
 
        xreport = xmlNewNode (NULL, "report");
@@ -700,6 +800,8 @@ xmlDoc
                                        priv->db->gda_datamodel = gda_connection_execute_single_command (priv->db->gda_conn, command, NULL);
                                        if (priv->db->gda_datamodel == NULL)
                                                {
+                                                       /* TO DO */
+                                                       g_warning ("Unable to create the datamodel.");
                                                        return NULL;
                                                }
 
@@ -712,20 +814,20 @@ xmlDoc
                                {
                                        if (row == 0 ||
                                            priv->body->new_page_after ||
-                                           (priv->page_footer != NULL && (cur_y + priv->body->height > priv->page->size->height - (priv->page_footer != NULL ? priv->page_footer->height: 0.0))) ||
-                                           cur_y > priv->page->size->height)
+                                           (priv->page_footer != NULL && (cur_y + priv->body->height > priv->page->size->height - priv->page->margin_top - priv->page->margin_bottom - (priv->page_footer != NULL ? priv->page_footer->height: 0.0))) ||
+                                           cur_y > (priv->page->size->height - priv->page->margin_top - priv->page->margin_bottom))
                                                {
                                                        if (priv->cur_page > 0 && priv->page_footer != NULL)
                                                                {
                                                                        if ((priv->cur_page == 1 && priv->page_footer->first_page) ||
                                                                            priv->cur_page > 1)
                                                                                {
-                                                                                       cur_y = priv->page->size->height - priv->page_footer->height;
+                                                                                       cur_y = priv->page->size->height - priv->page->margin_top - priv->page->margin_bottom - priv->page_footer->height;
                                                                                        rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1);
                                                                                }
                                                                }
 
-                                                       cur_y = 0.0;
+                                                       cur_y = priv->page->margin_top;
                                                        xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
 
                                                        if (priv->cur_page == 1 && priv->report_header != NULL)
@@ -752,16 +854,16 @@ xmlDoc
 
                        if (priv->cur_page > 0 && priv->report_footer != NULL)
                                {
-                                       if ((cur_y + priv->report_footer->height > priv->page->size->height - (priv->page_footer != NULL ? priv->page_footer->height : 0.0)) ||
+                                       if ((cur_y + priv->report_footer->height > priv->page->size->height - priv->page->margin_top - priv->page->margin_bottom - (priv->page_footer != NULL ? priv->page_footer->height : 0.0)) ||
                                            priv->report_footer->new_page_before)
                                                {
                                                        if (priv->cur_page > 0 && priv->page_footer != NULL)
                                                                {
-                                                                       cur_y = priv->page->size->height - priv->page_footer->height;
+                                                                       cur_y = priv->page->size->height - priv->page->margin_top - priv->page->margin_bottom - priv->page_footer->height;
                                                                        rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1);
                                                                }
 
-                                                       cur_y = 0.0;
+                                                       cur_y = priv->page->margin_top;
                                                        xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
 
                                                        if (priv->page_header != NULL)
@@ -773,13 +875,14 @@ xmlDoc
                                }
                        if (priv->cur_page > 0 && priv->page_footer != NULL && priv->page_footer->last_page)
                                {
-                                       cur_y = priv->page->size->height - priv->page_footer->height;
+                                       cur_y = priv->page->size->height - priv->page->margin_top - priv->page->margin_bottom - priv->page_footer->height;
                                        rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, row - 1);
                                }
                }
        else
                {
                        priv->cur_page++;
+                       cur_y = priv->page->margin_top;
                        xpage = rpt_report_rptprint_new_page (rpt_report, xroot);
 
                        if (priv->report_header != NULL)
@@ -799,7 +902,7 @@ xmlDoc
                                }
                        if (priv->page_footer != NULL)
                                {
-                                       cur_y = priv->page->size->height - priv->page_footer->height;
+                                       cur_y = priv->page->size->height - priv->page->margin_top - priv->page->margin_bottom - priv->page_footer->height;
                                        rpt_report_rptprint_section (rpt_report, xpage, &cur_y, RPTREPORT_SECTION_PAGE_FOOTER, -1);
                                }
                }
@@ -813,34 +916,52 @@ xmlDoc
  * @rpt_object: an #RptObject object.
  * @section:
  *
+ * Returns: FALSE if already exists an #RptObject with the same @rpt_object's
+ * name; TRUE otherwise.
  */
-void
+gboolean
 rpt_report_add_object_to_section (RptReport *rpt_report, RptObject *rpt_object, RptReportSection section)
 {
+       gboolean ret = FALSE;
+       gchar *objname;
+
        RptReportPrivate *priv = RPT_REPORT_GET_PRIVATE (rpt_report);
 
-       switch (section)
+       g_object_get (rpt_object, "name", &objname, NULL);
+       if (rpt_report_get_object_from_name (rpt_report, objname) == NULL)
                {
-                       case RPTREPORT_SECTION_REPORT_HEADER:
-                               priv->report_header->objects = g_list_append (priv->report_header->objects, rpt_object);;
-                               break;
+                       switch (section)
+                               {
+                                       case RPTREPORT_SECTION_REPORT_HEADER:
+                                               priv->report_header->objects = g_list_append (priv->report_header->objects, rpt_object);;
+                                               break;
 
-                       case RPTREPORT_SECTION_REPORT_FOOTER:
-                               priv->report_footer->objects = g_list_append (priv->report_footer->objects, rpt_object);;
-                               break;
+                                       case RPTREPORT_SECTION_REPORT_FOOTER:
+                                               priv->report_footer->objects = g_list_append (priv->report_footer->objects, rpt_object);;
+                                               break;
 
-                       case RPTREPORT_SECTION_PAGE_HEADER:
-                               priv->page_header->objects = g_list_append (priv->page_header->objects, rpt_object);;
-                               break;
+                                       case RPTREPORT_SECTION_PAGE_HEADER:
+                                               priv->page_header->objects = g_list_append (priv->page_header->objects, rpt_object);;
+                                               break;
 
-                       case RPTREPORT_SECTION_PAGE_FOOTER:
-                               priv->page_footer->objects = g_list_append (priv->page_footer->objects, rpt_object);;
-                               break;
+                                       case RPTREPORT_SECTION_PAGE_FOOTER:
+                                               priv->page_footer->objects = g_list_append (priv->page_footer->objects, rpt_object);;
+                                               break;
 
-                       case RPTREPORT_SECTION_BODY:
-                               priv->body->objects = g_list_append (priv->body->objects, rpt_object);;
-                               break;
+                                       case RPTREPORT_SECTION_BODY:
+                                               priv->body->objects = g_list_append (priv->body->objects, rpt_object);;
+                                               break;
+                               }
+
+                       ret = TRUE;
                }
+       else
+               {
+                       /* TO DO */
+                       g_warning ("An object with name \"%s\" already exists.", objname);
+               }
+
+       return ret;
 }
 
 /**
@@ -1208,17 +1329,7 @@ rpt_report_xml_parse_section (RptReport *rpt_report, xmlNode *xnode, RptReportSe
 
                        if (rptobj != NULL)
                                {
-                                       g_object_get (rptobj, "name", &objname, NULL);
-
-                                       if (rpt_report_get_object_from_name (rpt_report, objname) == NULL)
-                                               {
-                                                       rpt_report_add_object_to_section (rpt_report, rptobj, section);
-                                               }
-                                       else
-                                               {
-                                                       /* TO DO */
-                                                       g_warning ("An object with name \"%s\" already exists.", objname);
-                                               }
+                                       rpt_report_add_object_to_section (rpt_report, rptobj, section);
                                }
 
                        cur = cur->next;
@@ -1320,6 +1431,22 @@ static xmlNode
        xmlAddChild (xroot, xnode);
 
        rpt_common_set_size (xnode, priv->page->size);
+       if (priv->page->margin_top != 0.0)
+               {
+                       xmlSetProp (xnode, "margin-top", g_strdup_printf ("%f", priv->page->margin_top));
+               }
+       if (priv->page->margin_right != 0.0)
+               {
+                       xmlSetProp (xnode, "margin-right", g_strdup_printf ("%f", priv->page->margin_right));
+               }
+       if (priv->page->margin_bottom != 0.0)
+               {
+                       xmlSetProp (xnode, "margin-bottom", g_strdup_printf ("%f", priv->page->margin_bottom));
+               }
+       if (priv->page->margin_left != 0.0)
+               {
+                       xmlSetProp (xnode, "margin-left", g_strdup_printf ("%f", priv->page->margin_left));
+               }
 
        priv->cur_page++;
 
@@ -1373,6 +1500,16 @@ rpt_report_rptprint_section (RptReport *rpt_report, xmlNode *xpage, gdouble *cur
                                        xmlRemoveProp (attr);
                                }
 
+                       if (priv->page->margin_left != 0.0)
+                               {
+                                       prop = (gchar *)xmlGetProp (xnode, "x");
+                                       if (prop == NULL)
+                                               {
+                                                       prop = g_strdup ("0.0");
+                                               }
+                                       xmlSetProp (xnode, "x", g_strdup_printf ("%f", strtod (prop, NULL) + priv->page->margin_left));
+                               }
+                       
                        prop = (gchar *)xmlGetProp (xnode, "y");
                        if (prop == NULL)
                                {
@@ -1448,14 +1585,40 @@ rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj,
                                }
                        else
                                {
-                                       /* TO DO */
                                        /* ask value */
+                                       gchar *ret;
+                                       RptReportClass *klass = RPT_REPORT_GET_CLASS (rpt_report);
+
+                                       g_signal_emit (rpt_report, klass->field_request_signal_id,
+                                                      0, field, priv->db->gda_datamodel, row, &ret);
+                                       if (ret != NULL)
+                                               {
+                                                       source = g_strdup (ret);
+                                               }
+                                       else
+                                               {
+                                                       source = g_strdup ("");
+                                               }
                                }
                }
        else if (source[0] == '[' && source[strlen (source) - 1] == ']')
                {
-                       /* TO DO */
                        /* ask value */
+                       gchar *ret;
+                       gchar *field;
+                       RptReportClass *klass = RPT_REPORT_GET_CLASS (rpt_report);
+
+                       field = g_strstrip (g_strndup (source + 1, strlen (source) - 2));
+                       g_signal_emit (rpt_report, klass->field_request_signal_id,
+                                      0, field, NULL, row, &ret);
+                       if (ret != NULL)
+                               {
+                                       source = g_strdup (ret);
+                               }
+                       else
+                               {
+                                       source = g_strdup ("");
+                               }
                }
        else if (source[0] == '@')
                {
@@ -1483,6 +1646,14 @@ rpt_report_rptprint_parse_text_source (RptReport *rpt_report, RptObject *rptobj,
                                        source = g_strdup_printf ("%s", &date);
                                }
                }
+       else if (source[0] = '"' && source[strlen (source) - 1] == '"')
+               {
+                       source = g_strndup (source + 1, strlen (source) - 2);
+               }
+       else
+               {
+                       source = g_strdup ("");
+               }
 
        xmlNodeSetContent (xnode, source);
 }
index 04d88437d6afc4640105f200aa169749968dd5b7..5be4f23b29159cf9070b0f5dc6ed92d1f0aaa826 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <glib.h>
 #include <glib-object.h>
+#include <libgda/libgda.h>
 #include <libxml/tree.h>
 
 #include "rptobject.h"
@@ -48,6 +49,8 @@ struct _RptReport
 struct _RptReportClass
        {
                GObjectClass parent_class;
+
+               guint field_request_signal_id;
        };
 
 GType rpt_report_get_type (void) G_GNUC_CONST;
@@ -74,6 +77,11 @@ void rpt_report_set_database (RptReport *rpt_report,
 
 void rpt_report_set_page_size (RptReport *rpt_report,
                                RptSize size);
+void rpt_report_set_page_margins (RptReport *rpt_report,
+                                  gdouble top,
+                                  gdouble right,
+                                  gdouble bottom,
+                                  gdouble left);
 
 void rpt_report_set_section_height (RptReport *rpt_report,
                                     RptReportSection section,
@@ -95,9 +103,9 @@ xmlDoc *rpt_report_get_xml (RptReport *rpt_report);
 
 xmlDoc *rpt_report_get_xml_rptprint (RptReport *rpt_report);
 
-void rpt_report_add_object_to_section (RptReport *rpt_report,
-                                       RptObject *rpt_object,
-                                       RptReportSection section);
+gboolean rpt_report_add_object_to_section (RptReport *rpt_report,
+                                           RptObject *rpt_object,
+                                           RptReportSection section);
 void rpt_report_remove_object (RptReport *rpt_report,
                                RptObject *rpt_object);
 
index ccd4a53c0e563571d909b790b48de47200a065e0..b491e5ae8688539b9e8afd0e5357de63f00414d9 100644 (file)
@@ -5,8 +5,10 @@ AM_CPPFLAGS = $(REPTOOL_CFLAGS) \
 
 libreptool = $(top_builddir)/src/libreptool.la
 
-noinst_PROGRAMS = test_rptprint \
-                  test_rptreport
+noinst_PROGRAMS = \
+                  test_rptreport \
+                  test_rptprint \
+                  test_rptreport_creation
 
 LDADD = $(libreptool)
 
index 41299a22f1e275d081d28c0b7d67ca4587c65f39..b95fc60ad63e1c622c6e129813d45645a0c113a7 100644 (file)
@@ -1,12 +1,19 @@
 <?xml version="1.0" ?>
 <reptool>
-       <page width="595" height="842" />
+       <page width="595" height="842" margin-top="50" margin-left="100" margin-right="10" />
 
        <report>
-               <body height="300">
-                       <text name="text1" x="100" y="50" width="500" height="150" source="the text's content" />
+               <body height="500">
+                       <text name="text4" x="-50" y="10" width="500" height="150" source="&quot;text outside from left&quot;" />
+                       <text name="text1" x="100" y="50" width="500" height="150" source="&quot;the text's content&quot;" />
                        <text name="date" x="100" y="150" width="500" height="150" source="@Date" />
                        <text name="time" x="100" y="250" width="500" height="150" source="@Time" />
+                       <text name="text2" x="100" y="350" width="200" height="100"
+                               border-top-width="1.0" border-right-width="1.0" border-bottom-width="1.0" border-left-width="1.0"
+                               padding-top="20" padding-right="20" padding-bottom="20" padding-left="10"
+                               source="&quot;text very very long to try padding and border&quot;" />
+                       <text name="text3" x="400" y="350" width="200" height="50" source="&quot;another long text to test page margins&quot;" />
+                       <text name="text5" x="50" y="460" width="200" height="50" source="[field_to_request]" />
                </body>
        </report>
 </reptool>
index 1709557d1d23114a7ba51093308a154a34a8aa9d..40b759424b3f894f2983b2a3f79762ec7582a1f8 100644 (file)
 
        <report>
                <report-header height="80">
-                       <text name="rephead" x="10" y="10" width="300" height="70" font-name="Verdana" font-size="16" font-bold="y" font-underline="y" font-color="#0000FF" source="the report's header" />
+                       <text name="rephead" x="10" y="10" width="300" height="70" font-name="Verdana" font-size="16" font-bold="y" font-underline="y" font-color="#0000FF" source="&quot;the report's header&quot;" />
                </report-header>
                <page-header height="80" first-page="y">
-                       <text name="title" x="10" y="10" width="300" height="50" font-name="Courier New" font-size="10" font-bold="y" source="the page's title" />
+                       <text name="title" x="10" y="10" width="300" height="50" font-name="Courier New" font-size="10" font-bold="y" source="&quot;the page's title&quot;" />
                        <line name="line1" x="10" y="65" width="500" height="0" />
                </page-header>
                <body height="200">
                        <text name="txt_id" x="50" y="50" width="100" height="50" border-top-width="1.0" border-top-color="#FF0000" source="[id]" />
                        <text name="txt_name" x="200" y="50" width="100" height="50" source="[name]" />
+                       <text name="txt_req" x="50" y="100" width="100" height="50" source="[nonexistent]" />
                        <rect name="rect1" x="400" y="10" width="20" height="20" fill-color="#00FF00" />
                        <image name="img1" x="450" y="10" width="60" height="60" source="tests/gnome-globe.png" />
                </body>
                <report-footer height="50">
                        <line name="line3" x="10" y="10" width="500" height="0" stroke-color="#FFFF00" />
-                       <text name="txt_report_footer" x="10" y="20" width="500" height="30" horizontal-align="center" source="the report's footer" />
+                       <text name="txt_report_footer" x="10" y="20" width="500" height="30" horizontal-align="center" source="&quot;the report's footer&quot;" />
                        <line name="line4" x="10" y="50" width="500" height="0" stroke-color="#FFFF00" />
                </report-footer>
                <page-footer height="80" first-page="y" last-page="y">
                        <line name="line2" x="10" y="10" width="500" height="0" />
-                       <text name="footer" x="10" y="20" width="300" height="50" source="the page's footer" />
+                       <text name="footer" x="10" y="20" width="300" height="50" source="&quot;the page's footer&quot;" />
                        <ellipse name="ellipse1" x="400" y="50" width="20" height="10" stroke-color="#FF0000" fill-color="#00FF00" />
                        <text name="page_n" x="500" y="20" width="30" height="50" source="@Page" />
                </page-footer>
index 1b27f0735209e21fd2053ee209d629d1a064d758..f5e9d71ca0c9c22a0a2080bf53a9b4646df014c9 100644 (file)
 #include <rptreport.h>
 #include <rptprint.h>
 
+gchar
+*field_request (RptReport *rpt_report,
+                gchar *field_name,
+                GdaDataModel *data_model,
+                gint row,
+                gpointer user_data)
+{
+       gchar *ret = NULL;
+
+       if (strcmp (field_name, "field_to_request") == 0)
+               {
+                       ret = g_strdup ("the field requested");
+               }
+       else if (strcmp (field_name, "nonexistent") == 0 &&
+                data_model != NULL &&
+                row > -1)
+               {
+                       ret = g_strdup_printf ("%s - %s",
+                                              gda_value_stringify ((GdaValue *)gda_data_model_get_value_at (data_model, 0, row)),
+                                              gda_value_stringify ((GdaValue *)gda_data_model_get_value_at (data_model, 1, row)));
+               }
+
+       return ret;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -29,6 +54,8 @@ main (int argc, char **argv)
 
        rptr = rpt_report_new_from_file (argv[1]);
 
+       g_signal_connect (rptr, "field-request", G_CALLBACK (field_request), NULL);
+
        if (rptr != NULL)
                {
                        xmlDoc *report = rpt_report_get_xml (rptr);
diff --git a/tests/test_rptreport_creation.c b/tests/test_rptreport_creation.c
new file mode 100644 (file)
index 0000000..0e0652c
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
+ */
+
+#include <libreptool.h>
+
+int
+main (int argc, char **argv)
+{
+       RptReport *rptr;
+       RptObject *obj;
+       RptPoint point;
+       RptSize size;
+       RptStroke stroke;
+       RptColor *color;
+
+       g_type_init ();
+
+       rptr = rpt_report_new ();
+
+       if (rptr != NULL)
+               {
+                       size.width = 500;
+                       size.height = 500;
+                       rpt_report_set_page_size (rptr, size);
+
+                       point.x = 10;
+                       point.y = 10;
+                       obj = rpt_obj_text_new ("text1", point);
+                       size.width = 480;
+                       size.height = 50;
+                       g_object_set (obj,
+                                     "source", "The first object inserted.",
+                                     "size", &size,
+                                     NULL);
+                       rpt_report_add_object_to_section (rptr, obj, RPTREPORT_SECTION_BODY);
+
+                       point.x = 10;
+                       point.y = 60;
+                       obj = rpt_obj_line_new ("line1", point);
+                       size.width = 480;
+                       size.height = 0;
+                       stroke.color = rpt_common_parse_color ("#FF0000");
+                       g_object_set (obj,
+                                     "size", &size,
+                                                 "stroke", &stroke,
+                                     NULL);
+                       rpt_report_add_object_to_section (rptr, obj, RPTREPORT_SECTION_BODY);
+
+                       point.x = 0;
+                       point.y = 0;
+                       obj = rpt_obj_line_new ("line2", point);
+                       size.width = 500;
+                       size.height = 500;
+                       stroke.color = rpt_common_parse_color ("#000000AA");
+                       g_object_set (obj,
+                                     "size", &size,
+                                                 "stroke", &stroke,
+                                     NULL);
+                       rpt_report_add_object_to_section (rptr, obj, RPTREPORT_SECTION_BODY);
+
+                       point.x = 500;
+                       point.y = 0;
+                       obj = rpt_obj_line_new ("line3", point);
+                       size.width = -500;
+                       size.height = 500;
+                       stroke.color = rpt_common_parse_color ("#000000AA");
+                       g_object_set (obj,
+                                     "size", &size,
+                                                 "stroke", &stroke,
+                                     NULL);
+                       rpt_report_add_object_to_section (rptr, obj, RPTREPORT_SECTION_BODY);
+
+                       point.x = 250;
+                       point.y = 250;
+                       obj = rpt_obj_ellipse_new ("circle1", point);
+                       size.width = 100;
+                       size.height = 100;
+                       color = rpt_common_parse_color ("#00FF0099");
+                       stroke.color = rpt_common_parse_color ("#00FF00AA");
+                       g_object_set (obj,
+                                     "size", &size,
+                                                 "stroke", &stroke,
+                                                 "fill-color", color,
+                                     NULL);
+                       rpt_report_add_object_to_section (rptr, obj, RPTREPORT_SECTION_BODY);
+
+                       xmlDoc *report = rpt_report_get_xml (rptr);
+                       xmlSaveFormatFile ("test_report.rpt", report, 2);
+
+                       xmlDoc *rptprint = rpt_report_get_xml_rptprint (rptr);
+                       xmlSaveFormatFile ("test_report.rptr", rptprint, 2);
+               
+                       rpt_print_new_from_xml (rptprint, RPTP_OUTPUT_PDF, "test.pdf");
+               }
+
+       return 0;
+}