[glom] Print Layout: Print Standard: Avoid page break spaces in the middle of pages.



commit 0cb0e9113428bbabe610978072194d22adafe844
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Oct 17 11:23:11 2011 +0200

    Print Layout: Print Standard: Avoid page break spaces in the middle of pages.
    
    	* glom/print_layout/canvas_print_layout.[h|cc]: fill_with_data():
      Add an avoid_page_margins parameter, so we can choose to always move items
      past the margins on to the next page while setting their data.
    	* glom/print_layout/print_layout_utils.[h|cc]: create_standard():
    	Add an avoid_page_margins parameter, so we can choose to do this later instead
    	when setting the data, to avoid big gaps that are later moved down into the
    	middle of the page.
    	do_print_layout(): Add an avoid_page_margins parameter here too, passing
    	it to fill_with_data().
    	* glom/mode_data/box_data_details.cc: print_layout(): Do not avoid page
    	margins when creating, because that will happen when expanding items.
    	Avoid the page margins when setting the details.
    	* glom/mode_design/print_layouts/window_print_layout_edit.cc:
    	on_menu_insert_create_standard(): Avoid page margins when creating.
    	However, those gaps could be left in the middle of the page when printing,
    	because some items may be expanded. We need a way to squash that space
    	later when it is unecessary.

 ChangeLog                                          |   22 ++++++++++++++
 glom/frame_glom.cc                                 |    4 ++-
 glom/mode_data/box_data_details.cc                 |   11 +++++--
 .../print_layouts/window_print_layout_edit.cc      |    2 +-
 glom/print_layout/canvas_print_layout.cc           |   30 +++++++++++++++++--
 glom/print_layout/canvas_print_layout.h            |    4 +-
 glom/print_layout/print_layout_utils.cc            |   29 ++++++++++++------
 glom/print_layout/print_layout_utils.h             |    7 +++-
 8 files changed, 86 insertions(+), 23 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a20620f..31f2d3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2011-10-17  Murray Cumming  <murrayc murrayc com>
+
+	Print Layout: Print Standard: Avoid page break spaces in the middle of pages.
+
+	* glom/print_layout/canvas_print_layout.[h|cc]: fill_with_data():
+  Add an avoid_page_margins parameter, so we can choose to always move items
+  past the margins on to the next page while setting their data.
+	* glom/print_layout/print_layout_utils.[h|cc]: create_standard():
+	Add an avoid_page_margins parameter, so we can choose to do this later instead
+	when setting the data, to avoid big gaps that are later moved down into the 
+	middle of the page.
+	do_print_layout(): Add an avoid_page_margins parameter here too, passing 
+	it to fill_with_data().
+	* glom/mode_data/box_data_details.cc: print_layout(): Do not avoid page 
+	margins when creating, because that will happen when expanding items.
+	Avoid the page margins when setting the details.
+	* glom/mode_design/print_layouts/window_print_layout_edit.cc:
+	on_menu_insert_create_standard(): Avoid page margins when creating.
+	However, those gaps could be left in the middle of the page when printing,
+	because some items may be expanded. We need a way to squash that space
+	later when it is unecessary.
+
 2011-10-15  Jasper Lievisse Adriaanse <jasperla gnome org>
 
 	Remove glibc-specific function call.
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 76748b2..546aff6 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -2340,9 +2340,11 @@ void Frame_Glom::do_print_layout(const Glib::ustring& print_layout_name, bool pr
     return;
   }
   
+  //TODO: When expandingt items, avoid the page gaps that the print layout's designed
+  //has added.  
   const FoundSet found_set = m_Notebook_Data.get_found_set_details();
   PrintLayoutUtils::do_print_layout(print_layout, found_set, 
-    preview, document, transient_for);
+    preview, document, false /* do not avoid print margins */, transient_for);
 }
  
 #endif // !GLOM_ENABLE_CLIENT_ONLY
diff --git a/glom/mode_data/box_data_details.cc b/glom/mode_data/box_data_details.cc
index 2b01c9e..6a174dd 100644
--- a/glom/mode_data/box_data_details.cc
+++ b/glom/mode_data/box_data_details.cc
@@ -929,14 +929,19 @@ void Box_Data_Details::print_layout()
     std::cerr << G_STRFUNC << ": page_setup was null" << std::endl;
     return;
   }
-  
+
+  //Note that we initially create the page layout without spaces for page 
+  //breaks because those spaces would be empty space on the page after
+  //we have moved items down when expanding:
+  //TODO: Squash that space when expanding custom layouts.
   sharedptr<PrintLayout> print_layout = 
-    PrintLayoutUtils::create_standard(page_setup, m_table_name, document);
+    PrintLayoutUtils::create_standard(page_setup, m_table_name, document,
+      false /* do not avoid page margins */);
   
   //Show the print preview window:
   Application* app = Application::get_application();
   PrintLayoutUtils::do_print_layout(print_layout, m_found_set,
-    false /* not preview */, document, app);  
+    false /* not preview */, document, true /* avoid page margins */, app);
 }
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
diff --git a/glom/mode_design/print_layouts/window_print_layout_edit.cc b/glom/mode_design/print_layouts/window_print_layout_edit.cc
index 6056b07..391bd82 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -938,7 +938,7 @@ void Window_PrintLayout_Edit::on_menu_insert_create_standard()
     return;
   }
   
-  m_print_layout = PrintLayoutUtils::create_standard(page_setup, m_table_name, document);
+  m_print_layout = PrintLayoutUtils::create_standard(page_setup, m_table_name, document, true /* avoid page margins */);
   
   m_canvas.set_print_layout(m_table_name, m_print_layout);
 }
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index ad6118f..8233104 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -707,9 +707,9 @@ guint Canvas_PrintLayout::get_page_count() const
   return m_page_count;
 }
 
-void Canvas_PrintLayout::fill_with_data(const FoundSet& found_set)
+void Canvas_PrintLayout::fill_with_data(const FoundSet& found_set, bool avoid_page_margins)
 {
-  fill_with_data(m_items_group, found_set);
+  fill_with_data(m_items_group, found_set, avoid_page_margins);
 }
 
 void Canvas_PrintLayout::fill_with_data_system_preferences(const Glib::RefPtr<CanvasLayoutItem>& canvas_item, Document* document)
@@ -744,12 +744,15 @@ void Canvas_PrintLayout::fill_with_data_system_preferences(const Glib::RefPtr<Ca
     const Gnome::Gda::Value value = get_field_value_in_database(
      field_in_record, 0 /* TODO: parent window */);
     if(!Glom::Conversions::value_is_empty(value))
+    {
       canvas_item->set_db_data(value);
+      //TODO: canvas_item->expand_text_vertically();
+    }
   }
 }
  
 
-void Canvas_PrintLayout::fill_with_data(const Glib::RefPtr<Goocanvas::Group>& canvas_group, const FoundSet& found_set)
+void Canvas_PrintLayout::fill_with_data(const Glib::RefPtr<Goocanvas::Group>& canvas_group, const FoundSet& found_set, bool avoid_page_margins)
 {
   //A map of the text representation (e.g. field_name or relationship::field_name) to the index:
   typedef std::map<Glib::ustring, guint> type_map_layout_fields_index;
@@ -803,7 +806,7 @@ void Canvas_PrintLayout::fill_with_data(const Glib::RefPtr<Goocanvas::Group>& ca
   if(fieldsToGet.empty())
     return;
 
-  Glib::RefPtr<Gnome::Gda::SqlBuilder> sql_query = Utils::build_sql_select_with_where_clause(found_set.m_table_name,
+  const Glib::RefPtr<const Gnome::Gda::SqlBuilder> sql_query = Utils::build_sql_select_with_where_clause(found_set.m_table_name,
     fieldsToGet,
     found_set.m_where_clause, sharedptr<const Relationship>() /* extra_join */, found_set.m_sort_clause,
     1);
@@ -865,6 +868,25 @@ void Canvas_PrintLayout::fill_with_data(const Glib::RefPtr<Goocanvas::Group>& ca
       //Clear the no-image pixbuf from images:
       canvas_item->remove_empty_indicators();
     }
+    
+    if(avoid_page_margins)
+    {
+      const Glib::RefPtr<Gtk::PageSetup> page_setup = get_page_setup();
+      const Gtk::Unit units = property_units();
+      const bool needs_moving = PrintLayoutUtils::needs_move_fully_to_page(page_setup, units, canvas_item);
+      if(needs_moving)
+      {
+        double x = 0;
+        double y = 0;
+        canvas_item->get_xy(x, y);
+        double width = 0;
+        double height = 0;
+        canvas_item->get_width_height(width, height);
+               
+        const double offset = PrintLayoutUtils::get_offset_to_move_fully_to_next_page(page_setup, units, y, height);
+        move_items_down(y, offset);
+      }
+    }
   }
 }
 
diff --git a/glom/print_layout/canvas_print_layout.h b/glom/print_layout/canvas_print_layout.h
index c5efb4b..20302be 100644
--- a/glom/print_layout/canvas_print_layout.h
+++ b/glom/print_layout/canvas_print_layout.h
@@ -72,7 +72,7 @@ public:
    */
   void fill_with_data_system_preferences(const Glib::RefPtr<CanvasLayoutItem>& canvas_item, Document* document);
 
-  void fill_with_data(const FoundSet& found_set);
+  void fill_with_data(const FoundSet& found_set, bool avoid_page_margins);
 
   virtual void set_grid_gap(double gap = 20.0);
 
@@ -108,7 +108,7 @@ private:
   void fill_layout_group(const sharedptr<LayoutGroup>& group);
 
   //These are not static, because they need access to the document:
-  void fill_with_data(const Glib::RefPtr<Goocanvas::Group>& canvas_group, const FoundSet& found_set);
+  void fill_with_data(const Glib::RefPtr<Goocanvas::Group>& canvas_group, const FoundSet& found_set, bool avoid_page_margins);
   void fill_with_data_portal(const Glib::RefPtr<CanvasLayoutItem>& canvas_item, const Gnome::Gda::Value& foreign_key_value);
   static void set_canvas_item_field_value(const Glib::RefPtr<Goocanvas::Item>& canvas_item, const sharedptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
   
diff --git a/glom/print_layout/print_layout_utils.cc b/glom/print_layout/print_layout_utils.cc
index a2a6d80..869e8b7 100644
--- a/glom/print_layout/print_layout_utils.cc
+++ b/glom/print_layout/print_layout_utils.cc
@@ -167,7 +167,7 @@ static double move_fully_to_page(const Glib::RefPtr<const Gtk::PageSetup>& page_
 }
 */
 
-static void create_standard(const sharedptr<const LayoutGroup>& layout_group, const sharedptr<LayoutGroup>& print_layout_group, const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units, double x, double& y)
+static void create_standard(const sharedptr<const LayoutGroup>& layout_group, const sharedptr<LayoutGroup>& print_layout_group, const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units, double x, double& y, bool avoid_page_margins)
 {
   if(!layout_group || !print_layout_group)
   {
@@ -190,7 +190,9 @@ static void create_standard(const sharedptr<const LayoutGroup>& layout_group, co
     text->set_text(title);
     text->m_formatting.set_text_format_font("Sans Bold 10");
 
-    y = move_fully_to_page(page_setup, units, y, field_height);
+    if(avoid_page_margins)
+      y = move_fully_to_page(page_setup, units, y, field_height);
+
     text->set_print_layout_position(x, y, item_width, field_height); //TODO: Enough and no more.
     y += field_height + gap; //padding.
 
@@ -211,7 +213,9 @@ static void create_standard(const sharedptr<const LayoutGroup>& layout_group, co
 
     //Set an initial default height, though this will be changed
     //when we fill it with data:
-    y = move_fully_to_page(page_setup, units, y, field_height);
+    if(avoid_page_margins)
+      y = move_fully_to_page(page_setup, units, y, field_height);
+    
     portal_clone->set_print_layout_position(x, y, item_width, field_height);
     y += field_height + gap; //padding.
 
@@ -232,7 +236,7 @@ static void create_standard(const sharedptr<const LayoutGroup>& layout_group, co
     if(group && !portal)
     {
       //Recurse:
-      create_standard(group, print_layout_group, page_setup, units, x, y);
+      create_standard(group, print_layout_group, page_setup, units, x, y, avoid_page_margins);
     }
     else
     {
@@ -244,7 +248,10 @@ static void create_standard(const sharedptr<const LayoutGroup>& layout_group, co
       {
         text_title = sharedptr<LayoutItem_Text>::create();
         text_title->set_text(field->get_title_or_name() + ":");
-        y = move_fully_to_page(page_setup, units, y, field_height);
+        
+        if(avoid_page_margins)
+          y = move_fully_to_page(page_setup, units, y, field_height);
+
         text_title->set_print_layout_position(x, y, title_width, field_height); //TODO: Enough and no more.
         text_title->m_formatting.set_text_format_font("Sans 10");
 
@@ -274,7 +281,9 @@ static void create_standard(const sharedptr<const LayoutGroup>& layout_group, co
         }
       }
 
-      y = move_fully_to_page(page_setup, units, y, this_field_height); //TODO: Move the title down too, if this was moved.
+      if(avoid_page_margins)
+        y = move_fully_to_page(page_setup, units, y, this_field_height); //TODO: Move the title down too, if this was moved.
+        
       clone->set_print_layout_position(item_x, y, field_width, this_field_height); //TODO: Enough and no more.
       
       //Make sure that the title is still aligned, even if this was moved by move_fully_to_page().
@@ -300,7 +309,7 @@ guint get_page_for_y(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::
   return pages_integral;
 }
 
-sharedptr<PrintLayout> create_standard(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, const Glib::ustring& table_name, const Document* document)
+sharedptr<PrintLayout> create_standard(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, const Glib::ustring& table_name, const Document* document, bool avoid_page_margins)
 {
   const Gtk::Unit units = Gtk::UNIT_MM;
   sharedptr<PrintLayout> print_layout = sharedptr<PrintLayout>::create();  
@@ -342,7 +351,7 @@ sharedptr<PrintLayout> create_standard(const Glib::RefPtr<const Gtk::PageSetup>&
     if(!group)
       continue;
 
-    create_standard(group, print_layout->m_layout_group, page_setup, units, x, y);
+    create_standard(group, print_layout->m_layout_group, page_setup, units, x, y, avoid_page_margins);
   }
 
   //Add extra pages if necessary:
@@ -358,7 +367,7 @@ sharedptr<PrintLayout> create_standard(const Glib::RefPtr<const Gtk::PageSetup>&
   return print_layout;
 }
 
-void do_print_layout(const sharedptr<const PrintLayout>& print_layout, const FoundSet& found_set, bool preview, const Document* document, Gtk::Window* transient_for)
+void do_print_layout(const sharedptr<const PrintLayout>& print_layout, const FoundSet& found_set, bool preview, const Document* document, bool avoid_page_margins, Gtk::Window* transient_for)
 {
   if(!print_layout)
   {
@@ -412,7 +421,7 @@ void do_print_layout(const sharedptr<const PrintLayout>& print_layout, const Fou
   //print->signal_done().connect(sigc::bind(sigc::mem_fun(*this,
   //                &ExampleWindow::on_printoperation_done), print));
 
-  canvas.fill_with_data(found_set);
+  canvas.fill_with_data(found_set, avoid_page_margins);
 
   try
   {
diff --git a/glom/print_layout/print_layout_utils.h b/glom/print_layout/print_layout_utils.h
index e9ea15b..a823c70 100644
--- a/glom/print_layout/print_layout_utils.h
+++ b/glom/print_layout/print_layout_utils.h
@@ -42,9 +42,12 @@ const double ITEM_WIDTH_WIDE = GRID_GAP * 10;
 
 //TODO: Move this into libglom, by replacing Gtk::PageSetup with a custom class.
 //However, this also uses goocanvas, which would need to have its GTK+ widget split away too.
-sharedptr<PrintLayout> create_standard(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, const Glib::ustring& table_name, const Document* document);
+/** Create a print layout based on the on-screen details layout.
+ * @param avoid_page_margins If true then do skip page margins.
+ */
+sharedptr<PrintLayout> create_standard(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, const Glib::ustring& table_name, const Document* document, bool avoid_page_margins);
 
-void do_print_layout(const sharedptr<const PrintLayout>& print_layout, const FoundSet& found_set, bool preview, const Document* document, Gtk::Window* transient_for);
+void do_print_layout(const sharedptr<const PrintLayout>& print_layout, const FoundSet& found_set, bool preview, const Document* document, bool avoid_page_margins, Gtk::Window* transient_for);
 
 double get_page_height(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units);
 double get_page_height(const Glib::RefPtr<const Gtk::PageSetup>& page_setup, Gtk::Unit units, double& margin_top, double& margin_bottom);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]