[glom] Added missing files



commit c12cd70da3c45ed4e74d2840b4ae1690deff7dc7
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Oct 4 12:08:06 2011 +0200

    Added missing files

 glom/print_layout/printoperation_printlayout.cc |  100 +++++++++++++++++++++++
 glom/print_layout/printoperation_printlayout.h  |   52 ++++++++++++
 2 files changed, 152 insertions(+), 0 deletions(-)
---
diff --git a/glom/print_layout/printoperation_printlayout.cc b/glom/print_layout/printoperation_printlayout.cc
new file mode 100644
index 0000000..4c8e446
--- /dev/null
+++ b/glom/print_layout/printoperation_printlayout.cc
@@ -0,0 +1,100 @@
+/* gtkmm example Copyright (C) 2006 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <glom/print_layout/printoperation_printlayout.h>
+#include <iostream>
+
+namespace Glom
+{
+
+PrintOperationPrintLayout::PrintOperationPrintLayout()
+: m_canvas(0)
+{
+  set_unit(Gtk::UNIT_MM);
+  set_use_full_page(true); //Because we show the margins on our canvas.
+
+  set_n_pages(1); //There is always at least one page.
+}
+
+PrintOperationPrintLayout::~PrintOperationPrintLayout()
+{
+}
+
+Glib::RefPtr<PrintOperationPrintLayout> PrintOperationPrintLayout::create()
+{
+  return Glib::RefPtr<PrintOperationPrintLayout>(new PrintOperationPrintLayout());
+}
+
+void PrintOperationPrintLayout::on_begin_print(
+        const Glib::RefPtr<Gtk::PrintContext>& print_context)
+{
+  //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;
+
+  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);
+
+  return true; //Pagination has finished. Don't call this again.
+}
+
+
+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;
+
+  //Get a Cairo Context, which is used as a drawing board:
+  m_canvas->hide_page_bounds();
+  Cairo::RefPtr<Cairo::Context> cairo_context = print_context->get_cairo_context();
+
+  //Render the canvas onto the 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);
+}
+
+void PrintOperationPrintLayout::set_canvas(Canvas_PrintLayout* canvas)
+{
+  m_canvas = canvas;
+}
+
+} //namespace Glom
+
diff --git a/glom/print_layout/printoperation_printlayout.h b/glom/print_layout/printoperation_printlayout.h
new file mode 100644
index 0000000..9e281b9
--- /dev/null
+++ b/glom/print_layout/printoperation_printlayout.h
@@ -0,0 +1,52 @@
+/* gtkmm example Copyright (C) 2006 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef GLOM_PRINT_OPERATION_PRINT_LAYOUT_H
+#define GLOM_PRINT_OPERATION_PRINT_LAYOUT_H
+
+#include <glom/print_layout/canvas_print_layout.h>
+#include <gtkmm/printoperation.h>
+#include <vector>
+
+namespace Glom
+{
+
+//We derive our own class from PrintOperation,
+//so we can put the actual print implementation here.
+class PrintOperationPrintLayout : public Gtk::PrintOperation
+{
+public:
+  static Glib::RefPtr<PrintOperationPrintLayout> create();
+  virtual ~PrintOperationPrintLayout();
+
+  void set_canvas(Canvas_PrintLayout* canvas);
+
+private:
+  PrintOperationPrintLayout();
+
+  //PrintOperation default signal handler overrides:
+  virtual bool on_paginate(const Glib::RefPtr<Gtk::PrintContext>& context); //Comment this out if GTK+ bug #345345 has not been fixed yet.
+  virtual void on_begin_print(const Glib::RefPtr<Gtk::PrintContext>& context);
+  virtual void on_draw_page(const Glib::RefPtr<Gtk::PrintContext>& context, int page_nr);
+
+  //Not owned by this instance:
+  Canvas_PrintLayout* m_canvas;
+};
+
+} //namespace Glom
+
+
+#endif // GLOM_PRINT_OPERATION_PRINT_LAYOUT_H



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