Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkmm/ChangeLog,v
retrieving revision 1.554
diff -u -p -r1.554 ChangeLog
--- ChangeLog	2 Aug 2006 02:18:24 -0000	1.554
+++ ChangeLog	2 Aug 2006 12:51:01 -0000
@@ -1,3 +1,21 @@
+2006-08-02  Marko Anastasov  <marko@marko.anastasov.name>
+
+	* examples/book/printing/advanced/previewdialog.cc:
+	* examples/book/printing/advanced/previewdialog.h:
+	* examples/book/printing/advanced/printformoperation.cc:
+	* examples/book/printing/advanced/printformoperation.h:
+	Further efforts to fix #347857. See comment #14.
+	* gtk/src/pagesetup.hg:
+	Removed some commented conversions for PaperSize which haven't been
+	used ever since convert_gtk.m4 contains the necessary.
+	* gtk/src/printoperationpreview.hg:
+	Fixed the conversion for PrintContext which takes a reference and fixes
+	some of the problems in the bug. Uncommented ready and got_page_size
+	signals.
+	* tools/m4/convert_gtk.m4:
+	Made both conversions for PaperSize (C to Cpp) take a reference.
+	Removed two unnecessary conversions for PrintContext.
+
 2006-08-01  Jonathon Jongsma  <jonathon.jongsma@gmail.com>
 
 	* docs/tutorial/figures/Makefile.am:
Index: examples/book/printing/advanced/previewdialog.cc
===================================================================
RCS file: /cvs/gnome/gtkmm/examples/book/printing/advanced/previewdialog.cc,v
retrieving revision 1.4
diff -u -p -r1.4 previewdialog.cc
--- examples/book/printing/advanced/previewdialog.cc	20 Jul 2006 18:58:09 -0000	1.4
+++ examples/book/printing/advanced/previewdialog.cc	2 Aug 2006 12:51:02 -0000
@@ -15,38 +15,45 @@
  */
 
 #include "previewdialog.h"
+#include "printformoperation.h"
 
 #include <math.h>
 
 PreviewDialog::PreviewDialog(
+               PrintFormOperation* pfo,
                const Glib::RefPtr<Gtk::PrintOperationPreview>& preview,
                int page_count,
                const Glib::RefPtr<Gtk::PrintContext>& print_ctx,
-               const Glib::RefPtr<Pango::Layout>& layout,
                Gtk::Window& parent)
   :
+  m_pOperation(pfo),
   m_refPreview(preview),
-  m_refLayout(layout),
   m_PageSpin(1, 0),
   m_CloseButton(Gtk::Stock::CLOSE),
   m_Page(1),
   m_PageCount(page_count)
 {
-  g_debug("parent title: %s", parent.get_title().c_str());
   set_transient_for(parent);
   set_title("Preview");
   set_border_width(2);
 
-  Gtk::VBox* vbox = get_vbox();
+  add(m_VBox);
 
-  vbox->pack_start(m_HBox);
   m_HBox.pack_start(m_PageSpin);
   m_HBox.pack_start(m_CloseButton);
+  m_VBox.pack_start(m_HBox);
 
   m_DrawingArea.set_size_request(200, 300);
-  vbox->pack_start(m_DrawingArea);
+  m_VBox.pack_start(m_DrawingArea);
   m_DrawingArea.set_double_buffered(false);
 
+
+  m_refPreview->signal_ready().connect(
+    sigc::mem_fun(*this, &PreviewDialog::on_ready));
+
+  m_refPreview->signal_got_page_size().connect(
+    sigc::mem_fun(*this, &PreviewDialog::on_got_page_size));
+
   m_DrawingArea.signal_realize().connect(
     sigc::bind(sigc::mem_fun(*this, &PreviewDialog::on_drawing_area_realized),
 	       print_ctx));
@@ -54,7 +61,7 @@ PreviewDialog::PreviewDialog(
   m_CloseButton.signal_clicked().connect(
     sigc::mem_fun(*this, &PreviewDialog::on_close_clicked));
 
-  show_all_children();
+  show_all();
 }
 
 PreviewDialog::~PreviewDialog()
@@ -62,8 +69,7 @@ PreviewDialog::~PreviewDialog()
   g_debug("pw dtor");
 }
 
-void PreviewDialog::on_drawing_area_realized(
-                       const Glib::RefPtr<Gtk::PrintContext>& print_ctx)
+void PreviewDialog::on_drawing_area_realized(const Glib::RefPtr<Gtk::PrintContext>& print_ctx)
 {
   Glib::RefPtr<Gdk::Window> gdk_window = m_DrawingArea.get_window();
   Cairo::RefPtr<Cairo::Context> cairo_ctx = gdk_window->create_cairo_context();
@@ -80,8 +86,10 @@ void PreviewDialog::on_page_number_chang
   m_DrawingArea.queue_draw();
 }
 
-bool PreviewDialog::on_expose_event(GdkEventExpose* /* event */)
+bool PreviewDialog::on_drawing_area_expose_event(GdkEventExpose* /* event */)
 {
+  g_debug("on_expose_event");
+
   Glib::RefPtr<Gdk::Window> window = m_DrawingArea.get_window();
   if(window)
     window->clear();
@@ -92,12 +100,12 @@ bool PreviewDialog::on_expose_event(GdkE
   return true;
 }
 
-void PreviewDialog::on_ready(const Glib::RefPtr<Gtk::PrintContext>& /* print_ctx */)
+void PreviewDialog::on_ready(const Glib::RefPtr<Gtk::PrintContext>& /* print_ctx */ )
 {
   m_PageSpin.set_range(1.0, m_PageCount);
 
   m_DrawingArea.signal_expose_event().connect(
-    sigc::mem_fun(*this, &PreviewDialog::on_expose_event));
+    sigc::mem_fun(*this, &PreviewDialog::on_drawing_area_expose_event));
 
   m_DrawingArea.queue_draw();
 }
@@ -106,6 +114,8 @@ void PreviewDialog::on_got_page_size(
                        const Glib::RefPtr<Gtk::PrintContext>& print_ctx,
                        const Glib::RefPtr<Gtk::PageSetup>& page_setup)
 {
+  g_debug("on_got_page_size");
+
   Gtk::PaperSize paper_size = page_setup->get_paper_size();
 
   double width = paper_size.get_width(Gtk::UNIT_INCH);
@@ -125,7 +135,7 @@ void PreviewDialog::on_got_page_size(
     m_DpiY = dpi_y;
   }
 
-  m_refLayout->update_from_cairo_context(cairo_ctx);
+  m_pOperation->get_pango_layout()->update_from_cairo_context(cairo_ctx);
 }
 
 void PreviewDialog::on_close_clicked()
Index: examples/book/printing/advanced/previewdialog.h
===================================================================
RCS file: /cvs/gnome/gtkmm/examples/book/printing/advanced/previewdialog.h,v
retrieving revision 1.3
diff -u -p -r1.3 previewdialog.h
--- examples/book/printing/advanced/previewdialog.h	19 Jul 2006 02:55:21 -0000	1.3
+++ examples/book/printing/advanced/previewdialog.h	2 Aug 2006 12:51:02 -0000
@@ -19,14 +19,16 @@
 
 #include <gtkmm.h>
 
-class PreviewDialog : public Gtk::Dialog
+class PrintFormOperation;
+
+class PreviewDialog : public Gtk::Window
 {
  public:
   explicit PreviewDialog(
+                  PrintFormOperation* pfo,
                   const Glib::RefPtr<Gtk::PrintOperationPreview>& preview,
                   int page_count,
                   const Glib::RefPtr<Gtk::PrintContext>& context,
-                  const Glib::RefPtr<Pango::Layout>& layout,
                   Gtk::Window& parent);
   ~PreviewDialog();
 
@@ -37,15 +39,18 @@ class PreviewDialog : public Gtk::Dialog
   virtual void on_page_number_changed();
   virtual void on_close_clicked();
 
-  virtual bool on_expose_event(GdkEventExpose* event);
+  virtual bool on_drawing_area_expose_event(GdkEventExpose* event);
 
   //PrintOperationPreview overrides:
   virtual void on_ready(const Glib::RefPtr<Gtk::PrintContext>& print_ctx);
-  virtual void on_got_page_size(const Glib::RefPtr<Gtk::PrintContext>& context,
-                               const Glib::RefPtr<Gtk::PageSetup>& page_setup);
+  virtual void on_got_page_size(const Glib::RefPtr<Gtk::PrintContext>& context, const Glib::RefPtr<Gtk::PageSetup>& page_setup);
+
+  PrintFormOperation* m_pOperation;
 
   Glib::RefPtr<Gtk::PrintOperationPreview> m_refPreview;
   Glib::RefPtr<Pango::Layout> m_refLayout;
+
+  Gtk::VBox m_VBox;
 
   Gtk::HBox m_HBox;
   Gtk::SpinButton m_PageSpin;
Index: examples/book/printing/advanced/printformoperation.cc
===================================================================
RCS file: /cvs/gnome/gtkmm/examples/book/printing/advanced/printformoperation.cc,v
retrieving revision 1.4
diff -u -p -r1.4 printformoperation.cc
--- examples/book/printing/advanced/printformoperation.cc	25 Jul 2006 17:49:06 -0000	1.4
+++ examples/book/printing/advanced/printformoperation.cc	2 Aug 2006 12:51:03 -0000
@@ -193,27 +193,24 @@ bool PrintFormOperation::on_preview(
     return false;
   }
 
-  if(!m_refLayout)
-  {
-    std::cerr << "PrintFormOperation::on_preview(): m_refLayout was null." << std::endl;
-    return false;
-  }
-
-  g_debug("pfo::on_preview 1");
-
   //Use our custom preview dialog:
-  PreviewDialog dialog(preview, property_n_pages(), context, m_refLayout, *parent);
-  g_debug("pfo::on_preview 2");
-  dialog.run();
+  m_pDialog = new PreviewDialog(this, preview, property_n_pages(), context, *parent);
+  m_pDialog->signal_delete_event().connect(
+    sigc::mem_fun(*this, &PrintFormOperation::on_preview_window_delete_event));
 
-  g_debug("pfo::on_preview 3: emitting preview_done");
+  return true;
+}
 
-  //Inform the application that the print preview dialog has closed:
+bool
+PrintFormOperation::on_preview_window_delete_event(GdkEventAny*)
+{
+  //Pass the main window the most recent settings user applied.
   //TODO: Why do we need to do this?
   //Glib::RefPtr<Gtk::PrintSettings> settings = get_print_settings();
   //signal_preview_done.emit(settings);
 
-   g_debug("pfo::on_preview 4");
+  m_pDialog->hide();
+  delete m_pDialog;
 
   return true;
 }
Index: examples/book/printing/advanced/printformoperation.h
===================================================================
RCS file: /cvs/gnome/gtkmm/examples/book/printing/advanced/printformoperation.h,v
retrieving revision 1.5
diff -u -p -r1.5 printformoperation.h
--- examples/book/printing/advanced/printformoperation.h	25 Jul 2006 17:49:06 -0000	1.5
+++ examples/book/printing/advanced/printformoperation.h	2 Aug 2006 12:51:03 -0000
@@ -21,6 +21,8 @@
 #include <gtkmm.h>
 #include <vector>
 
+class PreviewDialog;
+
 //We derive our own class from PrintOperation,
 //so we can put the actual print implementation here.
 class PrintFormOperation : public Gtk::PrintOperation
@@ -29,6 +31,8 @@ class PrintFormOperation : public Gtk::P
   static Glib::RefPtr<PrintFormOperation> create();
   virtual ~PrintFormOperation();
 
+  Glib::RefPtr<Pango::Layout> get_pango_layout() { return m_refLayout; }
+
   void set_name(const Glib::ustring& name) { m_Name = name; }
   void set_comments(const Glib::ustring& comments) { m_Comments = comments; }
 
@@ -50,6 +54,9 @@ class PrintFormOperation : public Gtk::P
                   const Glib::RefPtr<Gtk::PrintContext>& context,
                   Gtk::Window* parent);
 
+  virtual bool on_preview_window_delete_event(GdkEventAny*);
+
+  PreviewDialog* m_pDialog;
 
   Glib::ustring m_Name;
   Glib::ustring m_Comments;
Index: gtk/src/pagesetup.hg
===================================================================
RCS file: /cvs/gnome/gtkmm/gtk/src/pagesetup.hg,v
retrieving revision 1.2
diff -u -p -r1.2 pagesetup.hg
--- gtk/src/pagesetup.hg	7 Jul 2006 12:53:16 -0000	1.2
+++ gtk/src/pagesetup.hg	2 Aug 2006 12:51:04 -0000
@@ -54,11 +54,6 @@ public:
   _WRAP_METHOD(PageOrientation get_orientation() const, gtk_page_setup_get_orientation)
   _WRAP_METHOD(void set_orientation(PageOrientation orientation), gtk_page_setup_set_orientation)
 
-//_CONVERSION(`PaperSize&',`GtkPaperSize*',__FR2P)
-//_CONVERSION(`const PaperSize&',`GtkPaperSize*',__FCR2P)
-//_CONVERSION(`GtkPaperSize*',`Glib::RefPtr<PaperSize>',`Glib::wrap($3)')
-//_CONVERSION(`const Glib::RefPtr<PaperSize>&',`GtkPaperSize*',__CONVERT_REFPTR_TO_P($3))
-
   _WRAP_METHOD(PaperSize get_paper_size(), gtk_page_setup_get_paper_size)
   _WRAP_METHOD(const PaperSize get_paper_size() const, gtk_page_setup_get_paper_size, constversion)
   _WRAP_METHOD(void set_paper_size(const PaperSize& paper_size), gtk_page_setup_set_paper_size)
Index: gtk/src/printoperationpreview.hg
===================================================================
RCS file: /cvs/gnome/gtkmm/gtk/src/printoperationpreview.hg,v
retrieving revision 1.5
diff -u -p -r1.5 printoperationpreview.hg
--- gtk/src/printoperationpreview.hg	24 Jul 2006 19:43:12 -0000	1.5
+++ gtk/src/printoperationpreview.hg	2 Aug 2006 12:51:04 -0000
@@ -49,12 +49,12 @@ public:
   #m4 _CONVERSION(`GtkPageSetup*',`const Glib::RefPtr<PageSetup>&',`Glib::wrap($3, true)')
   #m4 _CONVERSION(`const Glib::RefPtr<PageSetup>&',`GtkPageSetup*',__CONVERT_REFPTR_TO_P($3))
 
-  #m4 _CONVERSION(`PrintContext*',`const Glib::RefPtr<PrintContext>&',`Glib::wrap($3, true)')
+  #m4 _CONVERSION(`GtkPrintContext*',`const Glib::RefPtr<PrintContext>&',`Glib::wrap($3, true)')
 
   //TODO: Wrapping either of these signals causes a crash when showing a preview,
   //though the reference counting seems to be correct (take a reference because the signal does not give us a reference).
-  //_WRAP_SIGNAL(void ready(const Glib::RefPtr<PrintContext>& context), "ready")
-  //_WRAP_SIGNAL(void got_page_size(const Glib::RefPtr<PrintContext>& context, const Glib::RefPtr<PageSetup>& page_setup), "got_page_size")
+  _WRAP_SIGNAL(void ready(const Glib::RefPtr<PrintContext>& context), "ready")
+  _WRAP_SIGNAL(void got_page_size(const Glib::RefPtr<PrintContext>& context, const Glib::RefPtr<PageSetup>& page_setup), "got_page_size")
 };
 
 } // namespace Gtk
Index: tools/m4/convert_gtk.m4
===================================================================
RCS file: /cvs/gnome/gtkmm/tools/m4/convert_gtk.m4,v
retrieving revision 1.46
diff -u -p -r1.46 convert_gtk.m4
--- tools/m4/convert_gtk.m4	30 Jul 2006 20:49:57 -0000	1.46
+++ tools/m4/convert_gtk.m4	2 Aug 2006 12:51:08 -0000
@@ -536,8 +536,8 @@ _CONVERSION(`Glib::RefPtr<RecentManager>
 _CONVERSION(`Glib::RefPtr<const RecentManager>', `GtkRecentManager*', __CONVERT_CONST_REFPTR_TO_P_SUN(Gtk::RecentManager))
 
 #PaperSize
-_CONVERSION(`GtkPaperSize*',`PaperSize',`Glib::wrap($3)')
-_CONVERSION(`GtkPaperSize*',`const PaperSize',`Glib::wrap($3)')
+_CONVERSION(`GtkPaperSize*',`PaperSize',`Glib::wrap($3, true)')
+_CONVERSION(`GtkPaperSize*',`const PaperSize',`Glib::wrap($3, true)')
 _CONVERSION(`const PaperSize&',`GtkPaperSize*',__FCR2P)
 
 #PageSetup
@@ -562,8 +562,6 @@ _CONVERSION(`GtkPrintSettings*',`Glib::R
 _CONVERSION(`const Glib::RefPtr<PrintSettings>&',`GtkPrintSettings*',__CONVERT_REFPTR_TO_P)
 
 #PrintContext
-_CONVERSION(`GtkPrintContext*',`Glib::RefPtr<PrintContext>',`Glib::wrap($3)')
-_CONVERSION(`GtkPrintContext*',`const Glib::RefPtr<PrintContext>',`Glib::wrap($3)')
 _CONVERSION(`GtkPrintContext*',`const Glib::RefPtr<PrintContext>&',`Glib::wrap($3)')
 _CONVERSION(`const Glib::RefPtr<PrintContext>',`GtkPrintContext*',__CONVERT_REFPTR_TO_P($3))
 _CONVERSION(`const Glib::RefPtr<PrintContext>&',`GtkPrintContext*',__CONVERT_REFPTR_TO_P($3))
