[glom] Print Layout: Allow multiple pages.



commit 76c7317815bef2d86554e8447ae0289500ab8974
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Sep 30 11:25:56 2011 +0200

    Print Layout: Allow multiple pages.
    
    * glom/libglom/data_structure/print_layout.[h|cc]: Add get/set_page_count().
    * glom/libglom/document/document.cc: load_after(), save_before():
    Store the page count in the document.
    * glom/glom_document.dtd: Mention the new attribute.
    
    * glom/print_layout/canvas_print_layout.[h|cc]: Add get/set_page_count()
    and get_page_bounds().
    update_page_bounds(): Move the margin creation into here, and create
    margins for all pages.
    * glom/utility_widgets/canvas/canvas_group_grid.[h|cc]:
      Added update_grid_for_new_size().
    * glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]: Add
    Add Page and Delete Page menu items, though we need to rearrange the menus
    more sensibly.
    
    * glom/printoperation_printlayout.cc: on_begin_print(), on_paginate():
      Set the number of pages.
      on_draw(): Render only the specified page's bounds from the GooCanvas.
      However, this is not working for any page but the first one.
      Some cairo transformation might be necessary.

 ChangeLog                                          |   25 ++++
 glom/glom_document.dtd                             |    3 +-
 glom/libglom/data_structure/print_layout.cc        |   17 +++-
 glom/libglom/data_structure/print_layout.h         |    4 +
 glom/libglom/document/document.cc                  |    8 ++
 .../print_layouts/window_print_layout_edit.cc      |   33 ++++++
 .../print_layouts/window_print_layout_edit.h       |    4 +-
 glom/print_layout/canvas_print_layout.cc           |  116 ++++++++++++++++---
 glom/print_layout/canvas_print_layout.h            |   15 +++-
 glom/printoperation_printlayout.cc                 |   24 +++-
 glom/utility_widgets/canvas/canvas_group_grid.cc   |    5 +
 glom/utility_widgets/canvas/canvas_group_grid.h    |    5 +
 12 files changed, 230 insertions(+), 29 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 81294b1..e1f6d6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2011-09-30  Murray Cumming  <murrayc murrayc com>
+
+	Print Layout: Allow multiple pages.
+
+	* glom/libglom/data_structure/print_layout.[h|cc]: Add get/set_page_count().
+	* glom/libglom/document/document.cc: load_after(), save_before():
+	Store the page count in the document.
+	* glom/glom_document.dtd: Mention the new attribute.
+	
+	* glom/print_layout/canvas_print_layout.[h|cc]: Add get/set_page_count()
+	and get_page_bounds().
+	update_page_bounds(): Move the margin creation into here, and create 
+	margins for all pages.
+	* glom/utility_widgets/canvas/canvas_group_grid.[h|cc]:
+  Added update_grid_for_new_size().
+	* glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]: Add 
+	Add Page and Delete Page menu items, though we need to rearrange the menus
+	more sensibly.
+
+	* glom/printoperation_printlayout.cc: on_begin_print(), on_paginate():
+  Set the number of pages.
+  on_draw(): Render only the specified page's bounds from the GooCanvas.
+  However, this is not working for any page but the first one.
+  Some cairo transformation might be necessary.
+
 2011-09-30  Murray Cumming  <murrayc murrayc com>>
 
 	Instantiation test: warn if the widget is too big for small screens.
diff --git a/glom/glom_document.dtd b/glom/glom_document.dtd
index c2c8d3d..0578faa 100644
--- a/glom/glom_document.dtd
+++ b/glom/glom_document.dtd
@@ -411,7 +411,8 @@ TODO: Add 'title_singular' element.
         show_table_title (true|false) "false"
         show_grid (true|false) "false"
         show_rules (true|false) "false"
-        show_outlines (true|false) "false">
+        show_outlines (true|false) "false"
+        page_count CDATA 1>
 
     <!ELEMENT print_layout_groups (print_layout_group*)>
     <!ATTLIST print_layout_groups>
diff --git a/glom/libglom/data_structure/print_layout.cc b/glom/libglom/data_structure/print_layout.cc
index 2625060..84caa51 100644
--- a/glom/libglom/data_structure/print_layout.cc
+++ b/glom/libglom/data_structure/print_layout.cc
@@ -27,7 +27,8 @@ PrintLayout::PrintLayout()
 : m_show_table_title(true),
   m_show_grid(true),
   m_show_rules(true),
-  m_show_outlines(true)
+  m_show_outlines(true),
+  m_page_count(1) //A sensible default
 {
   m_translatable_item_type = TRANSLATABLE_TYPE_PRINT_LAYOUT;
   m_layout_group = sharedptr<LayoutGroup>::create();
@@ -39,7 +40,8 @@ PrintLayout::PrintLayout(const PrintLayout& src)
   m_show_table_title(src.m_show_table_title),
   m_show_grid(src.m_show_grid),
   m_show_rules(src.m_show_rules),
-  m_show_outlines(src.m_show_outlines)
+  m_show_outlines(src.m_show_outlines),
+  m_page_count(src.m_page_count)
 {
   m_page_setup = src.m_page_setup;
   m_horizontal_rules = src.m_horizontal_rules;
@@ -56,6 +58,7 @@ PrintLayout& PrintLayout::operator=(const PrintLayout& src)
   m_show_rules = src.m_show_rules;
   m_show_outlines = src.m_show_outlines;
   m_page_setup = src.m_page_setup;
+  m_page_count = src.m_page_count;
   m_horizontal_rules = src.m_horizontal_rules;
   m_vertical_rules = src.m_vertical_rules;
   
@@ -82,6 +85,16 @@ std::string PrintLayout::get_page_setup() const
   return m_page_setup;
 }
 
+void PrintLayout::set_page_count(guint count)
+{
+  m_page_count = count;
+}
+
+guint PrintLayout::get_page_count() const
+{
+  return m_page_count;
+}
+
 bool PrintLayout::get_show_grid() const
 {
   return m_show_grid;
diff --git a/glom/libglom/data_structure/print_layout.h b/glom/libglom/data_structure/print_layout.h
index 9c9a725..58da376 100644
--- a/glom/libglom/data_structure/print_layout.h
+++ b/glom/libglom/data_structure/print_layout.h
@@ -47,6 +47,9 @@ public:
   /** Returns the Page Setup as it would be created by a Gtk::PageSetup.   
    */
   std::string get_page_setup() const;
+  
+  void set_page_count(guint count);
+  guint get_page_count() const;
 
   bool get_show_grid() const;
   void set_show_grid(bool show_grid = true);
@@ -77,6 +80,7 @@ private:
   bool m_show_outlines;
 
   std::string m_page_setup;
+  guint m_page_count;
 
   type_vec_doubles m_horizontal_rules;
   type_vec_doubles m_vertical_rules;
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 96abf41..c8f5fa3 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -180,6 +180,7 @@ static const char GLOM_NODE_PRINT_LAYOUT[] = "print_layout";
 static const char GLOM_ATTRIBUTE_PRINT_LAYOUT_SHOW_GRID[] = "show_grid";
 static const char GLOM_ATTRIBUTE_PRINT_LAYOUT_SHOW_RULES[] = "show_rules";
 static const char GLOM_ATTRIBUTE_PRINT_LAYOUT_SHOW_OUTLINES[] = "show_outlines";
+static const char GLOM_ATTRIBUTE_PRINT_LAYOUT_PAGE_COUNT[] = "page_count";
 static const char GLOM_NODE_HORIZONTAL_RULE[] = "horizonal_rule";
 static const char GLOM_NODE_VERTICAL_RULE[] = "vertical_rule";
 static const char GLOM_ATTRIBUTE_RULE_POSITION[] = "position";
@@ -2969,6 +2970,10 @@ bool Document::load_after(int& failure_code)
                 //Page Setup:
                 const Glib::ustring key_file_text = get_child_text_node(node, GLOM_NODE_PAGE_SETUP);
                 print_layout->set_page_setup(key_file_text);
+                
+                print_layout->set_page_count(
+                  get_node_attribute_value_as_decimal(node, GLOM_ATTRIBUTE_PRINT_LAYOUT_PAGE_COUNT, 1));
+                 
 
                 //Layout Groups:
                 const xmlpp::Element* nodeGroups = get_node_child_named(node, GLOM_NODE_DATA_LAYOUT_GROUPS);
@@ -3818,6 +3823,9 @@ bool Document::save_before()
             xmlpp::Element* child = nodePrintLayout->add_child(GLOM_NODE_PAGE_SETUP);
             child->add_child_text( Utils::string_clean_for_xml(page_setup) );
           }
+          
+          set_node_attribute_value_as_decimal(nodePrintLayout, GLOM_ATTRIBUTE_PRINT_LAYOUT_PAGE_COUNT, 
+            print_layout->get_page_count(), 1);
 
           xmlpp::Element* nodeGroups = nodePrintLayout->add_child(GLOM_NODE_DATA_LAYOUT_GROUPS);
           if(print_layout->m_layout_group)
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 3e6de6f..b8eedf3 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -240,6 +240,10 @@ void Window_PrintLayout_Edit::init_menu()
                         sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_insert_line_vertical) );
   m_action_group->add(Gtk::Action::create("Action_Menu_Insert_CreateStandard", _("_Create Standard Layout")),
                         sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_insert_create_standard) );
+  m_action_group->add(Gtk::Action::create("Action_Menu_Insert_AddPage", _("_Add Page")),
+                        sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_insert_add_page) );
+  m_action_group->add(Gtk::Action::create("Action_Menu_Insert_DeletePage", _("_Delete Page")),
+                        sigc::mem_fun(*this, &Window_PrintLayout_Edit::on_menu_insert_delete_page) );
 
 
   m_action_group->add(Gtk::Action::create("Menu_Align", _("_Align")));
@@ -317,6 +321,9 @@ void Window_PrintLayout_Edit::init_menu()
     "        <menuitem action='Action_Menu_Insert_LineVertical' />"
     "        <separator />"
     "        <menuitem action='Action_Menu_Insert_CreateStandard' />"
+    "        <separator />"
+    "        <menuitem action='Action_Menu_Insert_AddPage' />"
+    "        <menuitem action='Action_Menu_Insert_DeletePage' />"
     "      </menu>"
     "      <menu action='Menu_Align'>"
     "        <menuitem action='Action_Menu_Align_Top' />"
@@ -1061,6 +1068,32 @@ void Window_PrintLayout_Edit::create_standard(const sharedptr<const LayoutGroup>
     }
   }
 }
+
+void Window_PrintLayout_Edit::on_menu_insert_add_page()
+{
+  m_canvas.set_page_count(
+    m_canvas.get_page_count() + 1);
+}
+
+//TODO: Disable this menu item when there is only one page:
+void Window_PrintLayout_Edit::on_menu_insert_delete_page()
+{
+  const guint page_count = m_canvas.get_page_count();
+  if(page_count <= 1)
+    return;
+
+  //Ask the user to confirm:
+  Gtk::MessageDialog dialog(Utils::bold_message(_("Remove page")), true, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE);
+  dialog.set_secondary_text(_("Are you sure that you wish to remove the last page and any items on that page?"));
+  dialog.set_transient_for(*this);
+  dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+  dialog.add_button(_("Remove Page"), Gtk::RESPONSE_OK);
+  if(dialog.run() != Gtk::RESPONSE_OK)
+    return;
+      
+  m_canvas.set_page_count(page_count - 1);
+}
+
 void Window_PrintLayout_Edit::on_button_close()
 {
   hide();
diff --git a/glom/mode_design/print_layouts/window_print_layout_edit.h b/glom/mode_design/print_layouts/window_print_layout_edit.h
index b4b634b..3b5bb36 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.h
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.h
@@ -71,7 +71,9 @@ private:
   void on_menu_insert_line_horizontal();
   void on_menu_insert_line_vertical();
   void on_menu_insert_create_standard();
-
+  void on_menu_insert_add_page();
+  void on_menu_insert_delete_page();
+  
   void on_menu_view_show_grid();
   void on_menu_view_show_rules();
   void on_menu_view_show_outlines();
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index 0e64bea..58c4f47 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -43,7 +43,8 @@ namespace Glom
 Canvas_PrintLayout::Canvas_PrintLayout()
 : m_modified(false),
   m_dialog_format(0),
-  m_outline_visibility(false)
+  m_outline_visibility(false),
+  m_page_count(1) //Sensible default
 {
   #ifndef GLOM_ENABLE_CLIENT_ONLY
   setup_context_menu();
@@ -68,7 +69,6 @@ Canvas_PrintLayout::~Canvas_PrintLayout()
 {
 }
 
-
 void Canvas_PrintLayout::set_print_layout(const Glib::ustring& table_name, const sharedptr<const PrintLayout>& print_layout)
 {
   m_table_name = table_name;
@@ -91,6 +91,7 @@ void Canvas_PrintLayout::set_print_layout(const Glib::ustring& table_name, const
     set_page_setup(page_setup);
   }
 
+  set_page_count(print_layout->get_page_count());
 
   //Add the rule lines:
   remove_rules();
@@ -131,6 +132,7 @@ sharedptr<PrintLayout> Canvas_PrintLayout::get_print_layout()
   data = key_file.to_data();
 
   result->set_page_setup(data);
+  result->set_page_count(get_page_count());
 
   result->set_horizontal_rules( get_horizontal_rules() );
   result->set_vertical_rules( get_horizontal_rules() );
@@ -576,12 +578,8 @@ Glib::RefPtr<Goocanvas::Polyline> Canvas_PrintLayout::create_margin_line(double
   return line;
 }
 
-void Canvas_PrintLayout::set_page_setup(const Glib::RefPtr<Gtk::PageSetup>& page_setup)
+void Canvas_PrintLayout::update_page_bounds()
 {
-  m_page_setup = page_setup;
-  if(!m_page_setup)
-    return;
-
   //Change the scroll extents to match the page size:
   const Gtk::PaperSize paper_size = m_page_setup->get_paper_size();
   Goocanvas::Bounds bounds;
@@ -592,19 +590,21 @@ void Canvas_PrintLayout::set_page_setup(const Glib::RefPtr<Gtk::PageSetup>& page
 
   //std::cout << "debug: " << G_STRFUNC << ": width=" << paper_size.get_width(units) << ", height=" paper_size.get_height(units) << std::endl;
 
+  double page_width = 0;
+  double page_height = 0;
   if(m_page_setup->get_orientation() == Gtk::PAGE_ORIENTATION_PORTRAIT) //TODO: Handle the reverse orientations too?
   {
-    bounds.set_x2( paper_size.get_width(units) );
-    bounds.set_y2( paper_size.get_height(units) );
+    page_width = paper_size.get_width(units);
+    page_height = paper_size.get_height(units);
   }
   else
   {
-    bounds.set_y2( paper_size.get_width(units) );
-    bounds.set_x2( paper_size.get_height(units) );
+    page_width = paper_size.get_height(units);
+    page_height = paper_size.get_width(units);
   }
-
-  //std::cout << "debug: " << G_STRFUNC << ": portrait page width=" << paper_size.get_width(units) << std::endl;
-
+  
+  bounds.set_x2( page_width );
+  bounds.set_y2( page_height * m_page_count );
   set_bounds(bounds);
 
   //Show the bounds with a rectangle, because the scrolled window might contain extra empty space.
@@ -632,11 +632,26 @@ void Canvas_PrintLayout::set_page_setup(const Glib::RefPtr<Gtk::PageSetup>& page
   if(m_grid)
     m_grid->lower();
 
-  m_margin_left = create_margin_line(page_setup->get_left_margin(units), bounds.get_y1(), page_setup->get_left_margin(units), bounds.get_y2());
-  m_margin_right = create_margin_line(bounds.get_x2() - page_setup->get_right_margin(units), bounds.get_y1(), bounds.get_x2() - page_setup->get_right_margin(units), bounds.get_y2());
-  m_margin_top = create_margin_line(bounds.get_x1(), page_setup->get_top_margin(units), bounds.get_x2(), page_setup->get_top_margin(units));
-  m_margin_bottom = create_margin_line(bounds.get_x1(), bounds.get_y2() - page_setup->get_bottom_margin(units), bounds.get_x2(), bounds.get_y2() - page_setup->get_bottom_margin(units));
-
+  m_margin_left = create_margin_line(m_page_setup->get_left_margin(units), bounds.get_y1(), m_page_setup->get_left_margin(units), bounds.get_y2());
+  m_margin_right = create_margin_line(bounds.get_x2() - m_page_setup->get_right_margin(units), bounds.get_y1(), bounds.get_x2() - m_page_setup->get_right_margin(units), bounds.get_y2());
+ 
+  m_vec_margin_tops.clear();  
+  m_vec_margin_bottoms.clear();
+  for(guint page = 0; page < m_page_count; ++page)
+  {
+    const double top_y = paper_size.get_height(units) * page + m_page_setup->get_top_margin(units);
+    Glib::RefPtr<Goocanvas::Polyline> margin_top = 
+      create_margin_line(
+        bounds.get_x1(), top_y, bounds.get_x2(), top_y);
+    m_vec_margin_tops.push_back(margin_top);
+      
+    const double bottom_y = paper_size.get_height(units) * (page + 1) - m_page_setup->get_bottom_margin(units);
+    Glib::RefPtr<Goocanvas::Polyline> margin_bottom = 
+      create_margin_line(
+        bounds.get_x1(), bottom_y, bounds.get_x2(), bottom_y);
+    m_vec_margin_bottoms.push_back(margin_bottom);
+  }
+  
   m_bounds_group->lower();
 
   //Try to show the whole thing, by (indirectly) making the parent window big enough:
@@ -647,6 +662,19 @@ void Canvas_PrintLayout::set_page_setup(const Glib::RefPtr<Gtk::PageSetup>& page
   std::cout << "DEBUG: width_pixels=" << width_pixels << ", height_pixels=" << height_pixels << std::endl;
   set_size_request(width_pixels, height_pixels);
   */
+  
+  //Update the grid lines:
+  m_grid->update_grid_for_new_size();
+}
+
+void Canvas_PrintLayout::set_page_setup(const Glib::RefPtr<Gtk::PageSetup>& page_setup)
+{
+  m_page_setup = page_setup;
+  if(!m_page_setup)
+    return;
+
+  update_page_bounds();
+  m_modified = true;
 }
 
 Glib::RefPtr<Gtk::PageSetup> Canvas_PrintLayout::get_page_setup()
@@ -654,6 +682,25 @@ Glib::RefPtr<Gtk::PageSetup> Canvas_PrintLayout::get_page_setup()
   return m_page_setup;
 }
 
+void Canvas_PrintLayout::set_page_count(guint count)
+{
+  if(count < 1)
+  {
+    std::cerr << G_STRFUNC << ": count was less than 1" << std::endl;
+    return;
+  }
+
+  m_page_count = count;
+  
+  update_page_bounds();
+  m_modified = true;
+}
+
+guint Canvas_PrintLayout::get_page_count() const
+{
+  return m_page_count;
+}
+
 void Canvas_PrintLayout::fill_with_data(const FoundSet& found_set)
 {
   fill_with_data(m_items_group, found_set);
@@ -1112,5 +1159,36 @@ void Canvas_PrintLayout::select_all(bool selected)
   signal_selection_changed().emit();
 }
 
+Goocanvas::Bounds Canvas_PrintLayout::get_page_bounds(guint page_num) const
+{
+  Goocanvas::Bounds bounds;
+  
+   //Change the scroll extents to match the page size:
+  const Gtk::PaperSize paper_size = m_page_setup->get_paper_size();
+  const Gtk::Unit units = property_units();
+
+  //std::cout << "debug: " << G_STRFUNC << ": width=" << paper_size.get_width(units) << ", height=" paper_size.get_height(units) << std::endl;
+
+  double page_width = 0;
+  double page_height = 0;
+  if(m_page_setup->get_orientation() == Gtk::PAGE_ORIENTATION_PORTRAIT) //TODO: Handle the reverse orientations too?
+  {
+    page_width = paper_size.get_width(units);
+    page_height = paper_size.get_height(units);
+  }
+  else
+  {
+    page_width = paper_size.get_height(units);
+    page_height = paper_size.get_width(units);
+  }
+  
+  bounds.set_x1(0);
+  bounds.set_y1( page_height * page_num);
+  bounds.set_x2( page_width );
+  bounds.set_y2( page_height * (page_num + 1) );
+
+  return bounds;
+}
+
 
 } //namespace Glom
diff --git a/glom/print_layout/canvas_print_layout.h b/glom/print_layout/canvas_print_layout.h
index 19ab6ab..c3bb427 100644
--- a/glom/print_layout/canvas_print_layout.h
+++ b/glom/print_layout/canvas_print_layout.h
@@ -50,6 +50,9 @@ public:
 
   void set_page_setup(const Glib::RefPtr<Gtk::PageSetup>& page_setup);
   Glib::RefPtr<Gtk::PageSetup> get_page_setup();
+  
+  void set_page_count(guint count);
+  guint get_page_count() const;
 
   void set_zoom_percent(guint percent);
  
@@ -83,6 +86,9 @@ public:
    */
   void select_all(bool selected = true);
   
+  
+  Goocanvas::Bounds get_page_bounds(guint page_num) const;
+  
 private:
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
@@ -116,6 +122,8 @@ private:
   void on_dialog_format_hide();
 #endif
 
+  void update_page_bounds();
+  
   Glib::RefPtr<Goocanvas::Polyline> create_margin_line(double x1, double y1, double x2, double y2);
 
   Glib::ustring m_table_name;
@@ -127,7 +135,11 @@ private:
   //A rectangle to show the bounds:
   Glib::RefPtr<Goocanvas::Group> m_bounds_group; //the page and its margins.
   Glib::RefPtr<Goocanvas::Rect> m_bounds_rect;
-  Glib::RefPtr<Goocanvas::Polyline> m_margin_left, m_margin_right, m_margin_top, m_margin_bottom;
+  Glib::RefPtr<Goocanvas::Polyline> m_margin_left, m_margin_right;
+  
+  typedef std::vector< Glib::RefPtr<Goocanvas::Polyline> > type_vec_margins;
+  type_vec_margins m_vec_margin_tops;
+  type_vec_margins m_vec_margin_bottoms;
 
   //Context menu for existing items:
   Gtk::Menu* m_context_menu;
@@ -142,6 +154,7 @@ private:
   Dialog_TextFormatting* m_dialog_format;
 
   bool m_outline_visibility;
+  guint m_page_count;
 };
 
 } //namespace Glom
diff --git a/glom/printoperation_printlayout.cc b/glom/printoperation_printlayout.cc
index 7e97885..9e1fb9d 100644
--- a/glom/printoperation_printlayout.cc
+++ b/glom/printoperation_printlayout.cc
@@ -43,13 +43,21 @@ void PrintOperationPrintLayout::on_begin_print(
 {
   //Call base class:
   Gtk::PrintOperation::on_begin_print(print_context);
+  
+  set_n_pages( m_canvas->get_page_count() );
+  //std::cout << G_STRFUNC << ": n pages =" <<  m_canvas->get_page_count() << std::endl;
 }
 
 bool PrintOperationPrintLayout::on_paginate(const Glib::RefPtr<Gtk::PrintContext>& print_context)
 {
-  std::cout << "PrintOperationPrintLayout::on_paginate" << std::endl;
+  //std::cout << "PrintOperationPrintLayout::on_paginate" << std::endl;
 
-  set_n_pages(1); //on_draw_page() will be called for any new pages.
+  if(!m_canvas)
+    return false;
+
+  //on_draw_page() will be called for any new pages.
+  set_n_pages( m_canvas->get_page_count() );
+  //std::cout << G_STRFUNC << ": n pages =" <<  m_canvas->get_page_count() << std::endl;
 
   //Call base class:
   Gtk::PrintOperation::on_paginate(print_context);
@@ -61,6 +69,8 @@ bool PrintOperationPrintLayout::on_paginate(const Glib::RefPtr<Gtk::PrintContext
 void PrintOperationPrintLayout::on_draw_page(
         const Glib::RefPtr<Gtk::PrintContext>& print_context, int page_nr)
 {
+  //Note that page_nr is 0-based, so the first page is page 0.
+
   if(!m_canvas)
     return;
 
@@ -68,10 +78,14 @@ void PrintOperationPrintLayout::on_draw_page(
   m_canvas->hide_page_bounds();
   Cairo::RefPtr<Cairo::Context> cairo_context = print_context->get_cairo_context();
 
-
   //Render the canvas onto the cairo context:
-  if(m_canvas)
-    m_canvas->render(cairo_context);
+  const Goocanvas::Bounds bounds = m_canvas->get_page_bounds(page_nr);
+  //std::cout << G_STRFUNC << ": page_nr=" << page_nr << ", bounds: x1=" << bounds.get_x1() << ", y1=" << bounds.get_y1() << ", x2=" << bounds.get_x2() << ", y2=" << bounds.get_y2() << std::endl;
+  m_canvas->render(cairo_context, bounds);
+  
+  //This doesn't seem to help:
+  //Shift the renderer context up into the page:
+  //cairo_context->translate(0, - bounds.get_y1());
 
   //Call base class:
   Gtk::PrintOperation::on_draw_page(print_context, page_nr);
diff --git a/glom/utility_widgets/canvas/canvas_group_grid.cc b/glom/utility_widgets/canvas/canvas_group_grid.cc
index a915a1a..685a6e9 100644
--- a/glom/utility_widgets/canvas/canvas_group_grid.cc
+++ b/glom/utility_widgets/canvas/canvas_group_grid.cc
@@ -280,6 +280,11 @@ void CanvasGroupGrid::set_grid_gap(double gap)
   create_grid_lines();
 }
 
+void CanvasGroupGrid::update_grid_for_new_size()
+{
+  create_grid_lines();
+}
+
 void CanvasGroupGrid::remove_grid()
 {
   m_grid_gap = 0.0;
diff --git a/glom/utility_widgets/canvas/canvas_group_grid.h b/glom/utility_widgets/canvas/canvas_group_grid.h
index c99f3d5..767d97a 100644
--- a/glom/utility_widgets/canvas/canvas_group_grid.h
+++ b/glom/utility_widgets/canvas/canvas_group_grid.h
@@ -50,6 +50,11 @@ public:
    * used to snap to the grid lines when moving or resizing items.
    */
   void set_grid_gap(double gap);
+  
+  /** Recreate the grid lines if this item has changed size.
+   * TODO: Just do this in response to some property change?
+   */
+  void update_grid_for_new_size();
 
   /** Remove grid lines.
    * See also remove_rules().



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